summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format18
-rw-r--r--.clang-tidy26
-rw-r--r--Auxiliary/bash-completion/cmake5
-rw-r--r--Auxiliary/cmake-mode.el4
-rw-r--r--Auxiliary/cmake.m42
-rw-r--r--Auxiliary/vim/cmake.vim.in59
-rwxr-xr-xAuxiliary/vim/extract-upper-case.pl65
-rw-r--r--Auxiliary/vim/indent/cmake.vim20
-rw-r--r--Auxiliary/vim/syntax/cmake.vim3103
-rw-r--r--CMakeCPack.cmake21
-rw-r--r--CMakeCPackOptions.cmake.in16
-rw-r--r--CMakeLists.txt254
-rw-r--r--CONTRIBUTING.rst32
-rw-r--r--CTestCustom.cmake.in19
-rw-r--r--CompileFlags.cmake74
-rw-r--r--Copyright.txt10
-rw-r--r--Help/command/FIND_XXX.txt39
-rw-r--r--Help/command/add_compile_options.rst45
-rw-r--r--Help/command/add_custom_command.rst40
-rw-r--r--Help/command/add_custom_target.rst13
-rw-r--r--Help/command/add_definitions.rst18
-rw-r--r--Help/command/add_dependencies.rst4
-rw-r--r--Help/command/add_executable.rst24
-rw-r--r--Help/command/add_library.rst59
-rw-r--r--Help/command/add_subdirectory.rst9
-rw-r--r--Help/command/add_test.rst13
-rw-r--r--Help/command/aux_source_directory.rst6
-rw-r--r--Help/command/break.rst4
-rw-r--r--Help/command/build_command.rst2
-rw-r--r--Help/command/build_name.rst2
-rw-r--r--Help/command/cmake_host_system_information.rst45
-rw-r--r--Help/command/cmake_minimum_required.rst50
-rw-r--r--Help/command/cmake_parse_arguments.rst69
-rw-r--r--Help/command/cmake_policy.rst40
-rw-r--r--Help/command/configure_file.rst32
-rw-r--r--Help/command/continue.rst6
-rw-r--r--Help/command/create_test_sourcelist.rst2
-rw-r--r--Help/command/ctest_build.rst4
-rw-r--r--Help/command/ctest_start.rst89
-rw-r--r--Help/command/ctest_submit.rst35
-rw-r--r--Help/command/ctest_update.rst12
-rw-r--r--Help/command/define_property.rst26
-rw-r--r--Help/command/else.rst4
-rw-r--r--Help/command/elseif.rst9
-rw-r--r--Help/command/enable_language.rst14
-rw-r--r--Help/command/enable_testing.rst17
-rw-r--r--Help/command/endforeach.rst8
-rw-r--r--Help/command/endfunction.rst8
-rw-r--r--Help/command/endif.rst8
-rw-r--r--Help/command/endmacro.rst8
-rw-r--r--Help/command/endwhile.rst8
-rw-r--r--Help/command/exec_program.rst4
-rw-r--r--Help/command/execute_process.rst35
-rw-r--r--Help/command/export.rst36
-rw-r--r--Help/command/export_library_dependencies.rst2
-rw-r--r--Help/command/file.rst450
-rw-r--r--Help/command/find_file.rst3
-rw-r--r--Help/command/find_library.rst3
-rw-r--r--Help/command/find_package.rst266
-rw-r--r--Help/command/find_path.rst3
-rw-r--r--Help/command/find_program.rst2
-rw-r--r--Help/command/fltk_wrap_ui.rst2
-rw-r--r--Help/command/foreach.rst99
-rw-r--r--Help/command/function.rst88
-rw-r--r--Help/command/get_cmake_property.rst12
-rw-r--r--Help/command/get_directory_property.rst19
-rw-r--r--Help/command/get_filename_component.rst39
-rw-r--r--Help/command/get_property.rst25
-rw-r--r--Help/command/get_source_file_property.rst18
-rw-r--r--Help/command/get_target_property.rst15
-rw-r--r--Help/command/get_test_property.rst14
-rw-r--r--Help/command/if.rst148
-rw-r--r--Help/command/include.rst10
-rw-r--r--Help/command/include_directories.rst8
-rw-r--r--Help/command/include_external_msproject.rst6
-rw-r--r--Help/command/include_regular_expression.rst4
-rw-r--r--Help/command/install.rst501
-rw-r--r--Help/command/install_files.rst6
-rw-r--r--Help/command/install_programs.rst4
-rw-r--r--Help/command/install_targets.rst4
-rw-r--r--Help/command/link_directories.rst52
-rw-r--r--Help/command/link_libraries.rst2
-rw-r--r--Help/command/list.rst343
-rw-r--r--Help/command/load_cache.rst11
-rw-r--r--Help/command/load_command.rst2
-rw-r--r--Help/command/macro.rst138
-rw-r--r--Help/command/make_directory.rst4
-rw-r--r--Help/command/mark_as_advanced.rst27
-rw-r--r--Help/command/math.rst36
-rw-r--r--Help/command/message.rst70
-rw-r--r--Help/command/option.rst13
-rw-r--r--Help/command/output_required_files.rst8
-rw-r--r--Help/command/project.rst154
-rw-r--r--Help/command/qt_wrap_cpp.rst21
-rw-r--r--Help/command/qt_wrap_ui.rst18
-rw-r--r--Help/command/remove.rst4
-rw-r--r--Help/command/remove_definitions.rst4
-rw-r--r--Help/command/return.rst7
-rw-r--r--Help/command/separate_arguments.rst46
-rw-r--r--Help/command/set.rst29
-rw-r--r--Help/command/set_directory_properties.rst15
-rw-r--r--Help/command/set_property.rst56
-rw-r--r--Help/command/set_source_files_properties.rst12
-rw-r--r--Help/command/set_target_properties.rst8
-rw-r--r--Help/command/set_tests_properties.rst11
-rw-r--r--Help/command/site_name.rst2
-rw-r--r--Help/command/source_group.rst2
-rw-r--r--Help/command/string.rst215
-rw-r--r--Help/command/subdir_depends.rst2
-rw-r--r--Help/command/subdirs.rst4
-rw-r--r--Help/command/target_compile_definitions.rst21
-rw-r--r--Help/command/target_compile_features.rst13
-rw-r--r--Help/command/target_compile_options.rst41
-rw-r--r--Help/command/target_include_directories.rst12
-rw-r--r--Help/command/target_link_libraries.rst127
-rw-r--r--Help/command/target_sources.rst16
-rw-r--r--Help/command/try_compile.rst61
-rw-r--r--Help/command/try_run.rst23
-rw-r--r--Help/command/unset.rst34
-rw-r--r--Help/command/use_mangled_mesa.rst4
-rw-r--r--Help/command/utility_source.rst2
-rw-r--r--Help/command/variable_requires.rst4
-rw-r--r--Help/command/variable_watch.rst14
-rw-r--r--Help/command/while.rst24
-rw-r--r--Help/command/write_file.rst4
-rw-r--r--Help/dev/README.rst2
-rw-r--r--Help/dev/maint.rst90
-rw-r--r--Help/dev/review.rst176
-rw-r--r--Help/dev/source.rst75
-rw-r--r--Help/dev/testing.rst5
-rw-r--r--Help/generator/CodeBlocks.rst12
-rw-r--r--Help/generator/CodeLite.rst6
-rw-r--r--Help/generator/Eclipse CDT4.rst2
-rw-r--r--Help/generator/Green Hills MULTI.rst57
-rw-r--r--Help/generator/Kate.rst8
-rw-r--r--Help/generator/MSYS Makefiles.rst3
-rw-r--r--Help/generator/MinGW Makefiles.rst3
-rw-r--r--Help/generator/Ninja.rst4
-rw-r--r--Help/generator/Sublime Text 2.rst10
-rw-r--r--Help/generator/Unix Makefiles.rst2
-rw-r--r--Help/generator/VS_TOOLSET_HOST_ARCH.txt9
-rw-r--r--Help/generator/Visual Studio 10 2010.rst29
-rw-r--r--Help/generator/Visual Studio 11 2012.rst31
-rw-r--r--Help/generator/Visual Studio 12 2013.rst32
-rw-r--r--Help/generator/Visual Studio 14 2015.rst26
-rw-r--r--Help/generator/Visual Studio 15 2017.rst55
-rw-r--r--Help/generator/Visual Studio 8 2005.rst23
-rw-r--r--Help/generator/Visual Studio 9 2008.rst19
-rw-r--r--Help/generator/Xcode.rst2
-rw-r--r--Help/index.rst5
-rw-r--r--Help/manual/LINKS.txt12
-rw-r--r--Help/manual/OPTIONS_BUILD.txt51
-rw-r--r--Help/manual/ccmake.1.rst6
-rw-r--r--Help/manual/cmake-buildsystem.7.rst86
-rw-r--r--Help/manual/cmake-commands.7.rst19
-rw-r--r--Help/manual/cmake-compile-features.7.rst13
-rw-r--r--Help/manual/cmake-developer.7.rst682
-rw-r--r--Help/manual/cmake-generator-expressions.7.rst602
-rw-r--r--Help/manual/cmake-generators.7.rst6
-rw-r--r--Help/manual/cmake-gui.1.rst15
-rw-r--r--Help/manual/cmake-language.7.rst111
-rw-r--r--Help/manual/cmake-modules.7.rst148
-rw-r--r--Help/manual/cmake-packages.7.rst69
-rw-r--r--Help/manual/cmake-policies.7.rst68
-rw-r--r--Help/manual/cmake-properties.7.rst77
-rw-r--r--Help/manual/cmake-qt.7.rst52
-rw-r--r--Help/manual/cmake-server.7.rst86
-rw-r--r--Help/manual/cmake-toolchains.7.rst145
-rw-r--r--Help/manual/cmake-variables.7.rst141
-rw-r--r--Help/manual/cmake.1.rst466
-rw-r--r--Help/manual/cpack.1.rst138
-rw-r--r--Help/manual/ctest.1.rst540
-rw-r--r--Help/module/CPackArchive.rst5
-rw-r--r--Help/module/CPackBundle.rst5
-rw-r--r--Help/module/CPackCygwin.rst5
-rw-r--r--Help/module/CPackDMG.rst5
-rw-r--r--Help/module/CPackDeb.rst5
-rw-r--r--Help/module/CPackNSIS.rst5
-rw-r--r--Help/module/CPackPackageMaker.rst5
-rw-r--r--Help/module/CPackProductBuild.rst5
-rw-r--r--Help/module/CPackRPM.rst5
-rw-r--r--Help/module/CPackWIX.rst6
-rw-r--r--Help/policy/CMP0000.rst24
-rw-r--r--Help/policy/CMP0001.rst16
-rw-r--r--Help/policy/CMP0002.rst12
-rw-r--r--Help/policy/CMP0003.rst10
-rw-r--r--Help/policy/CMP0004.rst11
-rw-r--r--Help/policy/CMP0005.rst10
-rw-r--r--Help/policy/CMP0006.rst26
-rw-r--r--Help/policy/CMP0007.rst10
-rw-r--r--Help/policy/CMP0008.rst19
-rw-r--r--Help/policy/CMP0009.rst16
-rw-r--r--Help/policy/CMP0010.rst10
-rw-r--r--Help/policy/CMP0011.rst31
-rw-r--r--Help/policy/CMP0012.rst27
-rw-r--r--Help/policy/CMP0013.rst6
-rw-r--r--Help/policy/CMP0014.rst16
-rw-r--r--Help/policy/CMP0015.rst20
-rw-r--r--Help/policy/CMP0016.rst9
-rw-r--r--Help/policy/CMP0017.rst16
-rw-r--r--Help/policy/CMP0018.rst35
-rw-r--r--Help/policy/CMP0019.rst8
-rw-r--r--Help/policy/CMP0020.rst22
-rw-r--r--Help/policy/CMP0021.rst19
-rw-r--r--Help/policy/CMP0022.rst30
-rw-r--r--Help/policy/CMP0023.rst22
-rw-r--r--Help/policy/CMP0024.rst19
-rw-r--r--Help/policy/CMP0025.rst10
-rw-r--r--Help/policy/CMP0026.rst23
-rw-r--r--Help/policy/CMP0027.rst28
-rw-r--r--Help/policy/CMP0028.rst26
-rw-r--r--Help/policy/CMP0037.rst20
-rw-r--r--Help/policy/CMP0038.rst8
-rw-r--r--Help/policy/CMP0039.rst8
-rw-r--r--Help/policy/CMP0040.rst2
-rw-r--r--Help/policy/CMP0041.rst8
-rw-r--r--Help/policy/CMP0042.rst4
-rw-r--r--Help/policy/CMP0043.rst8
-rw-r--r--Help/policy/CMP0044.rst8
-rw-r--r--Help/policy/CMP0045.rst8
-rw-r--r--Help/policy/CMP0046.rst8
-rw-r--r--Help/policy/CMP0047.rst10
-rw-r--r--Help/policy/CMP0048.rst14
-rw-r--r--Help/policy/CMP0049.rst16
-rw-r--r--Help/policy/CMP0050.rst8
-rw-r--r--Help/policy/CMP0052.rst7
-rw-r--r--Help/policy/CMP0053.rst4
-rw-r--r--Help/policy/CMP0055.rst8
-rw-r--r--Help/policy/CMP0056.rst6
-rw-r--r--Help/policy/CMP0060.rst6
-rw-r--r--Help/policy/CMP0061.rst2
-rw-r--r--Help/policy/CMP0062.rst2
-rw-r--r--Help/policy/CMP0065.rst2
-rw-r--r--Help/policy/CMP0066.rst2
-rw-r--r--Help/policy/CMP0067.rst2
-rw-r--r--Help/policy/DISALLOWED_COMMAND.txt8
-rw-r--r--Help/prop_cache/ADVANCED.rst2
-rw-r--r--Help/prop_cache/STRINGS.rst4
-rw-r--r--Help/prop_cache/TYPE.rst6
-rw-r--r--Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst16
-rw-r--r--Help/prop_dir/BUILDSYSTEM_TARGETS.rst2
-rw-r--r--Help/prop_dir/COMPILE_DEFINITIONS.rst2
-rw-r--r--Help/prop_dir/COMPILE_OPTIONS.rst2
-rw-r--r--Help/prop_dir/EXCLUDE_FROM_ALL.rst14
-rw-r--r--Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst10
-rw-r--r--Help/prop_dir/INCLUDE_DIRECTORIES.rst12
-rw-r--r--Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst2
-rw-r--r--Help/prop_dir/LINK_DIRECTORIES.rst15
-rw-r--r--Help/prop_dir/MACROS.rst2
-rw-r--r--Help/prop_dir/SUBDIRECTORIES.rst2
-rw-r--r--Help/prop_dir/TEST_INCLUDE_FILE.rst4
-rw-r--r--Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst14
-rw-r--r--Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst6
-rw-r--r--Help/prop_dir/VS_STARTUP_PROJECT.rst2
-rw-r--r--Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst16
-rw-r--r--Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst3
-rw-r--r--Help/prop_gbl/DEBUG_CONFIGURATIONS.rst7
-rw-r--r--Help/prop_gbl/DISABLED_FEATURES.rst6
-rw-r--r--Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst2
-rw-r--r--Help/prop_gbl/ENABLED_FEATURES.rst6
-rw-r--r--Help/prop_gbl/JOB_POOLS.rst8
-rw-r--r--Help/prop_gbl/RULE_MESSAGES.rst2
-rw-r--r--Help/prop_gbl/USE_FOLDERS.rst4
-rw-r--r--Help/prop_gbl/XCODE_EMIT_EFFECTIVE_PLATFORM_NAME.rst7
-rw-r--r--Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst4
-rw-r--r--Help/prop_inst/CPACK_NEVER_OVERWRITE.rst2
-rw-r--r--Help/prop_inst/CPACK_PERMANENT.rst2
-rw-r--r--Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst4
-rw-r--r--Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst4
-rw-r--r--Help/prop_inst/CPACK_WIX_ACL.rst2
-rw-r--r--Help/prop_sf/AUTORCC_OPTIONS.rst13
-rw-r--r--Help/prop_sf/AUTOUIC_OPTIONS.rst19
-rw-r--r--Help/prop_sf/COMPILE_DEFINITIONS.rst18
-rw-r--r--Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst6
-rw-r--r--Help/prop_sf/COMPILE_FLAGS.rst8
-rw-r--r--Help/prop_sf/EXTERNAL_OBJECT.rst2
-rw-r--r--Help/prop_sf/Fortran_FORMAT.rst7
-rw-r--r--Help/prop_sf/GENERATED.rst23
-rw-r--r--Help/prop_sf/KEEP_EXTENSION.rst2
-rw-r--r--Help/prop_sf/LABELS.rst2
-rw-r--r--Help/prop_sf/LANGUAGE.rst3
-rw-r--r--Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst14
-rw-r--r--Help/prop_sf/OBJECT_DEPENDS.rst2
-rw-r--r--Help/prop_sf/OBJECT_OUTPUTS.rst6
-rw-r--r--Help/prop_sf/SKIP_AUTOGEN.rst13
-rw-r--r--Help/prop_sf/SKIP_AUTOMOC.rst11
-rw-r--r--Help/prop_sf/SKIP_AUTORCC.rst11
-rw-r--r--Help/prop_sf/SKIP_AUTOUIC.rst16
-rw-r--r--Help/prop_sf/SYMBOLIC.rst2
-rw-r--r--Help/prop_sf/VS_CSHARP_tagname.rst5
-rw-r--r--Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst3
-rw-r--r--Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst3
-rw-r--r--Help/prop_sf/VS_INCLUDE_IN_VSIX.rst6
-rw-r--r--Help/prop_sf/VS_SHADER_FLAGS.rst2
-rw-r--r--Help/prop_sf/VS_SHADER_TYPE.rst2
-rw-r--r--Help/prop_sf/VS_XAML_TYPE.rst7
-rw-r--r--Help/prop_sf/WRAP_EXCLUDE.rst9
-rw-r--r--Help/prop_sf/XCODE_EXPLICIT_FILE_TYPE.rst2
-rw-r--r--Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst4
-rw-r--r--Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst4
-rw-r--r--Help/prop_test/COST.rst13
-rw-r--r--Help/prop_test/DISABLED.rst14
-rw-r--r--Help/prop_test/ENVIRONMENT.rst2
-rw-r--r--Help/prop_test/FIXTURES_CLEANUP.rst3
-rw-r--r--Help/prop_test/FIXTURES_REQUIRED.rst6
-rw-r--r--Help/prop_test/FIXTURES_SETUP.rst5
-rw-r--r--Help/prop_test/MEASUREMENT.rst8
-rw-r--r--Help/prop_test/PROCESSORS.rst12
-rw-r--r--Help/prop_test/RUN_SERIAL.rst2
-rw-r--r--Help/prop_test/SKIP_RETURN_CODE.rst2
-rw-r--r--Help/prop_test/WORKING_DIRECTORY.rst6
-rw-r--r--Help/prop_tgt/ANDROID_NATIVE_LIB_DIRECTORIES.rst4
-rw-r--r--Help/prop_tgt/AUTOGEN_BUILD_DIR.rst2
-rw-r--r--Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst37
-rw-r--r--Help/prop_tgt/AUTOMOC.rst273
-rw-r--r--Help/prop_tgt/AUTOMOC_DEPEND_FILTERS.rst95
-rw-r--r--Help/prop_tgt/AUTORCC.rst55
-rw-r--r--Help/prop_tgt/AUTORCC_OPTIONS.rst9
-rw-r--r--Help/prop_tgt/AUTOUIC.rst86
-rw-r--r--Help/prop_tgt/AUTOUIC_OPTIONS.rst9
-rw-r--r--Help/prop_tgt/BUILD_RPATH.rst2
-rw-r--r--Help/prop_tgt/BUNDLE.rst2
-rw-r--r--Help/prop_tgt/BUNDLE_EXTENSION.rst2
-rw-r--r--Help/prop_tgt/COMPILE_FLAGS.rst2
-rw-r--r--Help/prop_tgt/COMPILE_OPTIONS.rst2
-rw-r--r--Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst2
-rw-r--r--Help/prop_tgt/CROSSCOMPILING_EMULATOR.rst4
-rw-r--r--Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst12
-rw-r--r--Help/prop_tgt/CUDA_SEPARABLE_COMPILATION.rst4
-rw-r--r--Help/prop_tgt/CUDA_STANDARD.rst2
-rw-r--r--Help/prop_tgt/CXX_STANDARD.rst5
-rw-r--r--Help/prop_tgt/C_STANDARD.rst3
-rw-r--r--Help/prop_tgt/DEBUG_POSTFIX.rst6
-rw-r--r--Help/prop_tgt/DEFINE_SYMBOL.rst4
-rw-r--r--Help/prop_tgt/DEPLOYMENT_REMOTE_DIRECTORY.rst4
-rw-r--r--Help/prop_tgt/ENABLE_EXPORTS.rst2
-rw-r--r--Help/prop_tgt/EXCLUDE_FROM_ALL.rst23
-rw-r--r--Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst6
-rw-r--r--Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG.rst7
-rw-r--r--Help/prop_tgt/EXPORT_NAME.rst6
-rw-r--r--Help/prop_tgt/EchoString.rst4
-rw-r--r--Help/prop_tgt/FOLDER.rst9
-rw-r--r--Help/prop_tgt/FRAMEWORK.rst10
-rw-r--r--Help/prop_tgt/FRAMEWORK_VERSION.rst2
-rw-r--r--Help/prop_tgt/Fortran_FORMAT.rst6
-rw-r--r--Help/prop_tgt/Fortran_MODULE_DIRECTORY.rst4
-rw-r--r--Help/prop_tgt/GENERATOR_FILE_NAME.rst2
-rw-r--r--Help/prop_tgt/GNUtoMS.rst16
-rw-r--r--Help/prop_tgt/HAS_CXX.rst4
-rw-r--r--Help/prop_tgt/IMPORTED.rst4
-rw-r--r--Help/prop_tgt/IMPORTED_IMPLIB.rst4
-rw-r--r--Help/prop_tgt/IMPORTED_IMPLIB_CONFIG.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst6
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst12
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG.rst6
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst4
-rw-r--r--Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_LOCATION.rst29
-rw-r--r--Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_NO_SONAME.rst6
-rw-r--r--Help/prop_tgt/IMPORTED_NO_SONAME_CONFIG.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_OBJECTS.rst2
-rw-r--r--Help/prop_tgt/IMPORTED_SONAME.rst4
-rw-r--r--Help/prop_tgt/IMPORTED_SONAME_CONFIG.rst2
-rw-r--r--Help/prop_tgt/IMPORT_PREFIX.rst6
-rw-r--r--Help/prop_tgt/IMPORT_SUFFIX.rst8
-rw-r--r--Help/prop_tgt/INCLUDE_DIRECTORIES.rst2
-rw-r--r--Help/prop_tgt/INSTALL_NAME_DIR.rst10
-rw-r--r--Help/prop_tgt/INSTALL_RPATH.rst4
-rw-r--r--Help/prop_tgt/INSTALL_RPATH_USE_LINK_PATH.rst6
-rw-r--r--Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst2
-rw-r--r--Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst6
-rw-r--r--Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.rst4
-rw-r--r--Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst2
-rw-r--r--Help/prop_tgt/LANG_CLANG_TIDY.rst2
-rw-r--r--Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst5
-rw-r--r--Help/prop_tgt/LANG_CPPLINT.rst2
-rw-r--r--Help/prop_tgt/LANG_INCLUDE_WHAT_YOU_USE.rst2
-rw-r--r--Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst3
-rw-r--r--Help/prop_tgt/LINKER_LANGUAGE.rst2
-rw-r--r--Help/prop_tgt/LINK_DEPENDS.rst10
-rw-r--r--Help/prop_tgt/LINK_FLAGS.rst16
-rw-r--r--Help/prop_tgt/LINK_FLAGS_CONFIG.rst9
-rw-r--r--Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst4
-rw-r--r--Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst4
-rw-r--r--Help/prop_tgt/LINK_LIBRARIES.rst2
-rw-r--r--Help/prop_tgt/LINK_SEARCH_END_STATIC.rst11
-rw-r--r--Help/prop_tgt/LINK_SEARCH_START_STATIC.rst15
-rw-r--r--Help/prop_tgt/LOCATION.rst19
-rw-r--r--Help/prop_tgt/LOCATION_CONFIG.rst14
-rw-r--r--Help/prop_tgt/MACOSX_BUNDLE.rst6
-rw-r--r--Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst4
-rw-r--r--Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst4
-rw-r--r--Help/prop_tgt/MACOSX_RPATH.rst2
-rw-r--r--Help/prop_tgt/NO_SONAME.rst6
-rw-r--r--Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst18
-rw-r--r--Help/prop_tgt/OSX_ARCHITECTURES.rst4
-rw-r--r--Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst2
-rw-r--r--Help/prop_tgt/OUTPUT_NAME.rst3
-rw-r--r--Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst10
-rw-r--r--Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst6
-rw-r--r--Help/prop_tgt/POSITION_INDEPENDENT_CODE.rst5
-rw-r--r--Help/prop_tgt/POST_INSTALL_SCRIPT.rst8
-rw-r--r--Help/prop_tgt/PREFIX.rst2
-rw-r--r--Help/prop_tgt/PRE_INSTALL_SCRIPT.rst8
-rw-r--r--Help/prop_tgt/PRIVATE_HEADER.rst4
-rw-r--r--Help/prop_tgt/PUBLIC_HEADER.rst4
-rw-r--r--Help/prop_tgt/RESOURCE.rst19
-rw-r--r--Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst3
-rw-r--r--Help/prop_tgt/SKIP_BUILD_RPATH.rst4
-rw-r--r--Help/prop_tgt/SOVERSION.rst2
-rw-r--r--Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst15
-rw-r--r--Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst10
-rw-r--r--Help/prop_tgt/SUFFIX.rst2
-rw-r--r--Help/prop_tgt/TYPE.rst6
-rw-r--r--Help/prop_tgt/VERSION.rst2
-rw-r--r--Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst5
-rw-r--r--Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst3
-rw-r--r--Help/prop_tgt/VS_SDK_REFERENCES.rst2
-rw-r--r--Help/prop_tgt/WIN32_EXECUTABLE.rst11
-rw-r--r--Help/prop_tgt/XCODE_ATTRIBUTE_an-attribute.rst4
-rw-r--r--Help/release/3.0.rst2
-rw-r--r--Help/release/3.1.rst6
-rw-r--r--Help/release/3.2.rst10
-rw-r--r--Help/release/3.3.rst14
-rw-r--r--Help/release/3.4.rst12
-rw-r--r--Help/release/3.5.rst22
-rw-r--r--Help/release/3.6.rst64
-rw-r--r--Help/release/3.7.rst23
-rw-r--r--Help/release/3.8.rst22
-rw-r--r--Help/release/3.9.rst23
-rw-r--r--Help/release/index.rst6
-rw-r--r--Help/variable/APPLE.rst5
-rw-r--r--Help/variable/CMAKE_ANDROID_STL_TYPE.rst3
-rw-r--r--Help/variable/CMAKE_APPBUNDLE_PATH.rst4
-rw-r--r--Help/variable/CMAKE_ARGC.rst6
-rw-r--r--Help/variable/CMAKE_ARGV0.rst4
-rw-r--r--Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst2
-rw-r--r--Help/variable/CMAKE_AUTORCC_OPTIONS.rst11
-rw-r--r--Help/variable/CMAKE_AUTOUIC_OPTIONS.rst11
-rw-r--r--Help/variable/CMAKE_BUILD_RPATH.rst2
-rw-r--r--Help/variable/CMAKE_BUILD_TYPE.rst4
-rw-r--r--Help/variable/CMAKE_CFG_INTDIR.rst2
-rw-r--r--Help/variable/CMAKE_CROSSCOMPILING.rst27
-rw-r--r--Help/variable/CMAKE_CROSSCOMPILING_EMULATOR.rst6
-rw-r--r--Help/variable/CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.rst2
-rw-r--r--Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst23
-rw-r--r--Help/variable/CMAKE_ENABLE_EXPORTS.rst2
-rw-r--r--Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst9
-rw-r--r--Help/variable/CMAKE_EXTRA_GENERATOR.rst2
-rw-r--r--Help/variable/CMAKE_FIND_APPBUNDLE.rst4
-rw-r--r--Help/variable/CMAKE_FIND_FRAMEWORK.rst4
-rw-r--r--Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst24
-rw-r--r--Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst3
-rw-r--r--Help/variable/CMAKE_FIND_ROOT_PATH.rst2
-rw-r--r--Help/variable/CMAKE_FRAMEWORK_PATH.rst4
-rw-r--r--Help/variable/CMAKE_GENERATOR.rst5
-rw-r--r--Help/variable/CMAKE_GENERATOR_PLATFORM.rst5
-rw-r--r--Help/variable/CMAKE_GENERATOR_TOOLSET.rst13
-rw-r--r--Help/variable/CMAKE_HOME_DIRECTORY.rst7
-rw-r--r--Help/variable/CMAKE_HOST_APPLE.rst4
-rw-r--r--Help/variable/CMAKE_HOST_SYSTEM.rst2
-rw-r--r--Help/variable/CMAKE_HOST_SYSTEM_NAME.rst2
-rw-r--r--Help/variable/CMAKE_IGNORE_PATH.rst2
-rw-r--r--Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst2
-rw-r--r--Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst2
-rw-r--r--Help/variable/CMAKE_INCLUDE_PATH.rst2
-rw-r--r--Help/variable/CMAKE_INSTALL_NAME_DIR.rst2
-rw-r--r--Help/variable/CMAKE_INSTALL_PREFIX.rst16
-rw-r--r--Help/variable/CMAKE_JOB_POOL_LINK.rst2
-rw-r--r--Help/variable/CMAKE_LANG_CLANG_TIDY.rst11
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst2
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_ID.rst6
-rw-r--r--Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst3
-rw-r--r--Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst3
-rw-r--r--Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst3
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS.rst11
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst5
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_DEBUG_INIT.rst9
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_INIT.rst8
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst6
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL_INIT.rst9
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst5
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_RELEASE_INIT.rst9
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst6
-rw-r--r--Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT.rst9
-rw-r--r--Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst7
-rw-r--r--Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst15
-rw-r--r--Help/variable/CMAKE_LIBRARY_PATH.rst2
-rw-r--r--Help/variable/CMAKE_MACOSX_BUNDLE.rst3
-rw-r--r--Help/variable/CMAKE_MACOSX_RPATH.rst2
-rw-r--r--Help/variable/CMAKE_MAKE_PROGRAM.rst17
-rw-r--r--Help/variable/CMAKE_MFC_FLAG.rst15
-rw-r--r--Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst6
-rw-r--r--Help/variable/CMAKE_MODULE_PATH.rst4
-rw-r--r--Help/variable/CMAKE_OSX_ARCHITECTURES.rst4
-rw-r--r--Help/variable/CMAKE_OSX_DEPLOYMENT_TARGET.rst10
-rw-r--r--Help/variable/CMAKE_OSX_SYSROOT.rst2
-rw-r--r--Help/variable/CMAKE_OSX_VARIABLE.txt7
-rw-r--r--Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst4
-rw-r--r--Help/variable/CMAKE_PREFIX_PATH.rst2
-rw-r--r--Help/variable/CMAKE_PROGRAM_PATH.rst2
-rw-r--r--Help/variable/CMAKE_PROJECT_DESCRIPTION.rst34
-rw-r--r--Help/variable/CMAKE_PROJECT_NAME.rst34
-rw-r--r--Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst10
-rw-r--r--Help/variable/CMAKE_SKIP_INSTALL_RULES.rst2
-rw-r--r--Help/variable/CMAKE_SOURCE_DIR.rst2
-rw-r--r--Help/variable/CMAKE_STAGING_PREFIX.rst10
-rw-r--r--Help/variable/CMAKE_SYSROOT.rst4
-rw-r--r--Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst2
-rw-r--r--Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst2
-rw-r--r--Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst2
-rw-r--r--Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst2
-rw-r--r--Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst2
-rw-r--r--Help/variable/CMAKE_SYSTEM_NAME.rst3
-rw-r--r--Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst9
-rw-r--r--Help/variable/CMAKE_SYSTEM_PROCESSOR.rst2
-rw-r--r--Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst2
-rw-r--r--Help/variable/CMAKE_Swift_LANGUAGE_VERSION.rst8
-rw-r--r--Help/variable/CMAKE_VS_DEVENV_COMMAND.rst2
-rw-r--r--Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst2
-rw-r--r--Help/variable/CMAKE_VS_PLATFORM_NAME.rst4
-rw-r--r--Help/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE.rst10
-rw-r--r--Help/variable/CMAKE_XCODE_GENERATE_SCHEME.rst9
-rw-r--r--Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst2
-rw-r--r--Help/variable/CTEST_CUSTOM_WARNING_EXCEPTION.rst2
-rw-r--r--Help/variable/CTEST_CUSTOM_WARNING_MATCH.rst2
-rw-r--r--Help/variable/CTEST_SCP_COMMAND.rst3
-rw-r--r--Help/variable/CTEST_TRIGGER_SITE.rst3
-rw-r--r--Help/variable/CTEST_UPDATE_VERSION_ONLY.rst2
-rw-r--r--Help/variable/ENV.rst11
-rw-r--r--Help/variable/GHS-MULTI.rst2
-rw-r--r--Help/variable/LIBRARY_OUTPUT_PATH.rst2
-rw-r--r--Help/variable/MSVC.rst6
-rw-r--r--Help/variable/MSVC_VERSION.rst27
-rw-r--r--Help/variable/PROJECT_DESCRIPTION.rst5
-rw-r--r--Help/variable/PROJECT_NAME.rst4
-rw-r--r--Help/variable/UNIX.rst8
-rw-r--r--Help/variable/WIN32.rst4
-rw-r--r--Help/variable/XCODE_VERSION.rst4
-rw-r--r--Modules/AddFileDependencies.cmake33
-rw-r--r--Modules/AndroidTestUtilities.cmake2
-rw-r--r--Modules/AndroidTestUtilities/PushToAndroidDevice.cmake2
-rw-r--r--Modules/BasicConfigVersion-AnyNewerVersion.cmake.in14
-rw-r--r--Modules/BasicConfigVersion-ExactVersion.cmake.in7
-rw-r--r--Modules/BasicConfigVersion-SameMajorVersion.cmake.in7
-rw-r--r--Modules/BundleUtilities.cmake474
-rw-r--r--Modules/CMakeASMCompiler.cmake.in4
-rw-r--r--Modules/CMakeASMInformation.cmake41
-rw-r--r--Modules/CMakeASM_NASMInformation.cmake4
-rw-r--r--Modules/CMakeAddFortranSubdirectory.cmake81
-rw-r--r--Modules/CMakeAddNewLanguage.txt22
-rw-r--r--Modules/CMakeBackwardCompatibilityC.cmake4
-rw-r--r--Modules/CMakeBackwardCompatibilityCXX.cmake32
-rw-r--r--Modules/CMakeCCompiler.cmake.in7
-rw-r--r--Modules/CMakeCCompilerABI.c4
-rw-r--r--Modules/CMakeCCompilerId.c.in6
-rw-r--r--Modules/CMakeCInformation.cmake40
-rw-r--r--Modules/CMakeCSharpCompiler.cmake.in1
-rw-r--r--Modules/CMakeCSharpInformation.cmake60
-rw-r--r--Modules/CMakeCUDACompiler.cmake.in5
-rw-r--r--Modules/CMakeCUDACompilerABI.cu2
-rw-r--r--Modules/CMakeCUDACompilerId.cu.in4
-rw-r--r--Modules/CMakeCUDAInformation.cmake50
-rw-r--r--Modules/CMakeCXXCompiler.cmake.in8
-rw-r--r--Modules/CMakeCXXCompilerABI.cpp2
-rw-r--r--Modules/CMakeCXXCompilerId.cpp.in17
-rw-r--r--Modules/CMakeCXXInformation.cmake44
-rw-r--r--Modules/CMakeCheckCompilerFlagCommonPatterns.cmake49
-rw-r--r--Modules/CMakeCommonLanguageInclude.cmake114
-rw-r--r--Modules/CMakeCompilerABI.h21
-rw-r--r--Modules/CMakeCompilerIdDetection.cmake12
-rw-r--r--Modules/CMakeDependentOption.cmake43
-rw-r--r--Modules/CMakeDetermineASMCompiler.cmake106
-rw-r--r--Modules/CMakeDetermineASM_MASMCompiler.cmake6
-rw-r--r--Modules/CMakeDetermineCCompiler.cmake44
-rw-r--r--Modules/CMakeDetermineCSharpCompiler.cmake6
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake41
-rw-r--r--Modules/CMakeDetermineCXXCompiler.cmake47
-rw-r--r--Modules/CMakeDetermineCompileFeatures.cmake6
-rw-r--r--Modules/CMakeDetermineCompilerABI.cmake47
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake276
-rw-r--r--Modules/CMakeDetermineFortranCompiler.cmake33
-rw-r--r--Modules/CMakeDetermineSwiftCompiler.cmake51
-rw-r--r--Modules/CMakeDetermineSystem.cmake3
-rw-r--r--Modules/CMakeDetermineVSServicePack.cmake116
-rw-r--r--Modules/CMakeExpandImportedTargets.cmake260
-rw-r--r--Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake7
-rw-r--r--Modules/CMakeFindBinUtils.cmake90
-rw-r--r--Modules/CMakeFindCodeBlocks.cmake5
-rw-r--r--Modules/CMakeFindDependencyMacro.cmake102
-rw-r--r--Modules/CMakeFindFrameworks.cmake19
-rw-r--r--Modules/CMakeFindPackageMode.cmake57
-rw-r--r--Modules/CMakeForceCompiler.cmake132
-rw-r--r--Modules/CMakeFortranCompiler.cmake.in4
-rw-r--r--Modules/CMakeFortranCompilerABI.F8
-rw-r--r--Modules/CMakeFortranCompilerId.F.in71
-rw-r--r--Modules/CMakeFortranInformation.cmake45
-rw-r--r--Modules/CMakeGenericSystem.cmake8
-rw-r--r--Modules/CMakeGraphVizOptions.cmake236
-rw-r--r--Modules/CMakeIOSInstallCombined.cmake9
-rw-r--r--Modules/CMakeJavaInformation.cmake6
-rw-r--r--Modules/CMakeLanguageInformation.cmake4
-rw-r--r--Modules/CMakeNinjaFindMake.cmake2
-rw-r--r--Modules/CMakePackageConfigHelpers.cmake416
-rw-r--r--Modules/CMakeParseArguments.cmake17
-rw-r--r--Modules/CMakeParseImplicitLinkInfo.cmake7
-rw-r--r--Modules/CMakePlatformId.h.in68
-rw-r--r--Modules/CMakePrintHelpers.cmake98
-rw-r--r--Modules/CMakePrintSystemInformation.cmake17
-rw-r--r--Modules/CMakePushCheckState.cmake129
-rw-r--r--Modules/CMakeRCInformation.cmake27
-rw-r--r--Modules/CMakeSwiftCompiler.cmake.in9
-rw-r--r--Modules/CMakeSwiftInformation.cmake90
-rw-r--r--Modules/CMakeSystemSpecificInformation.cmake3
-rw-r--r--Modules/CMakeSystemSpecificInitialize.cmake13
-rw-r--r--Modules/CMakeTestCCompiler.cmake15
-rw-r--r--Modules/CMakeTestCSharpCompiler.cmake7
-rw-r--r--Modules/CMakeTestCUDACompiler.cmake7
-rw-r--r--Modules/CMakeTestCXXCompiler.cmake17
-rw-r--r--Modules/CMakeTestCompilerCommon.cmake20
-rw-r--r--Modules/CMakeTestFortranCompiler.cmake7
-rw-r--r--Modules/CMakeTestJavaCompiler.cmake2
-rw-r--r--Modules/CMakeTestRCCompiler.cmake2
-rw-r--r--Modules/CMakeTestSwiftCompiler.cmake14
-rw-r--r--Modules/CMakeVerifyManifest.cmake33
-rwxr-xr-xModules/CPack.STGZ_Header.sh.in2
-rw-r--r--Modules/CPack.background.png.inbin47076 -> 44108 bytes
-rw-r--r--Modules/CPack.cmake712
-rw-r--r--Modules/CPackComponent.cmake605
-rw-r--r--Modules/CPackIFW.cmake971
-rw-r--r--Modules/CPackIFWConfigureFile.cmake53
-rw-r--r--Modules/CSharpUtilities.cmake5
-rw-r--r--Modules/CTest.cmake26
-rw-r--r--Modules/CTestCoverageCollectGCOV.cmake165
-rw-r--r--Modules/CTestScriptMode.cmake15
-rw-r--r--Modules/CTestTargets.cmake5
-rw-r--r--Modules/CTestUseLaunchers.cmake53
-rw-r--r--Modules/CheckCCompilerFlag.cmake93
-rw-r--r--Modules/CheckCSourceCompiles.cmake98
-rw-r--r--Modules/CheckCSourceRuns.cmake108
-rw-r--r--Modules/CheckCXXCompilerFlag.cmake97
-rw-r--r--Modules/CheckCXXSourceCompiles.cmake98
-rw-r--r--Modules/CheckCXXSourceRuns.cmake104
-rw-r--r--Modules/CheckCXXSymbolExists.cmake76
-rw-r--r--Modules/CheckForPthreads.c40
-rw-r--r--Modules/CheckFortranCompilerFlag.cmake52
-rw-r--r--Modules/CheckFortranFunctionExists.cmake63
-rw-r--r--Modules/CheckFortranSourceCompiles.cmake120
-rw-r--r--Modules/CheckFunctionExists.c12
-rw-r--r--Modules/CheckFunctionExists.cmake93
-rw-r--r--Modules/CheckIPOSupported.cmake21
-rw-r--r--Modules/CheckIncludeFile.cmake105
-rw-r--r--Modules/CheckIncludeFileCXX.cmake103
-rw-r--r--Modules/CheckIncludeFiles.cmake139
-rw-r--r--Modules/CheckLanguage.cmake92
-rw-r--r--Modules/CheckLibraryExists.cmake68
-rw-r--r--Modules/CheckPrototypeDefinition.cmake91
-rw-r--r--Modules/CheckStructHasMember.cmake126
-rw-r--r--Modules/CheckSymbolExists.cmake36
-rw-r--r--Modules/CheckTypeSize.c.in8
-rw-r--r--Modules/CheckTypeSize.cmake143
-rw-r--r--Modules/CheckVariableExists.c8
-rw-r--r--Modules/CheckVariableExists.cmake72
-rw-r--r--Modules/Compiler/ARMCC-ASM.cmake2
-rw-r--r--Modules/Compiler/ARMCC-DetermineCompiler.cmake2
-rw-r--r--Modules/Compiler/ARMCC.cmake2
-rw-r--r--Modules/Compiler/Absoft-Fortran.cmake1
-rw-r--r--Modules/Compiler/AppleClang-C.cmake3
-rw-r--r--Modules/Compiler/AppleClang-CXX.cmake12
-rw-r--r--Modules/Compiler/Bruce-C.cmake2
-rw-r--r--Modules/Compiler/CMakeCommonCompilerMacros.cmake57
-rw-r--r--Modules/Compiler/Clang-C.cmake38
-rw-r--r--Modules/Compiler/Clang-CXX.cmake139
-rw-r--r--Modules/Compiler/Clang.cmake25
-rw-r--r--Modules/Compiler/Cray-C.cmake6
-rw-r--r--Modules/Compiler/Cray-CXX.cmake10
-rw-r--r--Modules/Compiler/Cray-Fortran.cmake9
-rw-r--r--Modules/Compiler/Cray.cmake7
-rw-r--r--Modules/Compiler/CrayPrgEnv-C.cmake6
-rw-r--r--Modules/Compiler/CrayPrgEnv-CXX.cmake6
-rw-r--r--Modules/Compiler/CrayPrgEnv-Fortran.cmake6
-rw-r--r--Modules/Compiler/CrayPrgEnv.cmake167
-rw-r--r--Modules/Compiler/G95-Fortran.cmake2
-rw-r--r--Modules/Compiler/GHS-C.cmake20
-rw-r--r--Modules/Compiler/GHS-CXX.cmake24
-rw-r--r--Modules/Compiler/GHS-DetermineCompiler.cmake11
-rw-r--r--Modules/Compiler/GHS.cmake6
-rw-r--r--Modules/Compiler/GNU-C.cmake3
-rw-r--r--Modules/Compiler/GNU-CXX.cmake19
-rw-r--r--Modules/Compiler/GNU-FindBinUtils.cmake4
-rw-r--r--Modules/Compiler/GNU-Fortran.cmake5
-rw-r--r--Modules/Compiler/GNU.cmake24
-rw-r--r--Modules/Compiler/HP-C.cmake3
-rw-r--r--Modules/Compiler/HP-CXX.cmake3
-rw-r--r--Modules/Compiler/HP-Fortran.cmake3
-rw-r--r--Modules/Compiler/IAR-ASM.cmake36
-rw-r--r--Modules/Compiler/IAR-C.cmake74
-rw-r--r--Modules/Compiler/IAR-CXX.cmake80
-rw-r--r--Modules/Compiler/IAR-DetermineCompiler.cmake41
-rw-r--r--Modules/Compiler/IAR.cmake123
-rw-r--r--Modules/Compiler/Intel-C.cmake6
-rw-r--r--Modules/Compiler/Intel-CXX-FeatureTests.cmake6
-rw-r--r--Modules/Compiler/Intel-CXX.cmake32
-rw-r--r--Modules/Compiler/Intel-DetermineCompiler.cmake14
-rw-r--r--Modules/Compiler/Intel-Fortran.cmake3
-rw-r--r--Modules/Compiler/Intel.cmake8
-rw-r--r--Modules/Compiler/MSVC-CXX-FeatureTests.cmake34
-rw-r--r--Modules/Compiler/MSVC-CXX.cmake53
-rw-r--r--Modules/Compiler/NAG-Fortran.cmake1
-rw-r--r--Modules/Compiler/NVIDIA-CUDA.cmake14
-rw-r--r--Modules/Compiler/NVIDIA-DetermineCompiler.cmake8
-rw-r--r--Modules/Compiler/PGI-C.cmake3
-rw-r--r--Modules/Compiler/PGI-CXX.cmake4
-rw-r--r--Modules/Compiler/PGI-Fortran.cmake4
-rw-r--r--Modules/Compiler/PGI.cmake15
-rw-r--r--Modules/Compiler/QCC-C.cmake3
-rw-r--r--Modules/Compiler/QCC-CXX.cmake3
-rw-r--r--Modules/Compiler/QCC.cmake13
-rw-r--r--Modules/Compiler/SCO.cmake3
-rw-r--r--Modules/Compiler/SunPro-C.cmake12
-rw-r--r--Modules/Compiler/SunPro-CXX-FeatureTests.cmake14
-rw-r--r--Modules/Compiler/SunPro-CXX.cmake15
-rw-r--r--Modules/Compiler/SunPro-Fortran.cmake7
-rw-r--r--Modules/Compiler/TI-C.cmake8
-rw-r--r--Modules/Compiler/TI-CXX.cmake2
-rw-r--r--Modules/Compiler/TinyCC-C.cmake3
-rw-r--r--Modules/Compiler/XL-C.cmake40
-rw-r--r--Modules/Compiler/XL-CXX.cmake46
-rw-r--r--Modules/Compiler/XL-Fortran.cmake3
-rw-r--r--Modules/Compiler/XL.cmake28
-rw-r--r--Modules/CompilerId/VS-10.vcxproj.in1
-rw-r--r--Modules/CompilerId/Xcode-3.pbxproj.in4
-rw-r--r--Modules/Dart.cmake43
-rw-r--r--Modules/DartConfiguration.tcl.in15
-rw-r--r--Modules/DeployQt4.cmake728
-rw-r--r--Modules/Documentation.cmake17
-rw-r--r--Modules/ExternalData.cmake2
-rw-r--r--Modules/ExternalProject-download.cmake.in2
-rw-r--r--Modules/ExternalProject.cmake1597
-rw-r--r--Modules/FeatureSummary.cmake4
-rw-r--r--Modules/FindALSA.cmake66
-rw-r--r--Modules/FindASPELL.cmake31
-rw-r--r--Modules/FindAVIFile.cmake45
-rw-r--r--Modules/FindArmadillo.cmake58
-rw-r--r--Modules/FindBISON.cmake224
-rw-r--r--Modules/FindBLAS.cmake1284
-rw-r--r--Modules/FindBZip2.cmake125
-rw-r--r--Modules/FindBacktrace.cmake71
-rw-r--r--Modules/FindBoost.cmake1671
-rw-r--r--Modules/FindBullet.cmake79
-rw-r--r--Modules/FindCABLE.cmake43
-rw-r--r--Modules/FindCUDA.cmake852
-rw-r--r--Modules/FindCUDA/make2cmake.cmake2
-rw-r--r--Modules/FindCUDA/run_nvcc.cmake17
-rw-r--r--Modules/FindCUDA/select_compute_arch.cmake101
-rw-r--r--Modules/FindCURL.cmake182
-rw-r--r--Modules/FindCVS.cmake43
-rw-r--r--Modules/FindCoin3D.cmake33
-rw-r--r--Modules/FindCups.cmake63
-rw-r--r--Modules/FindCurses.cmake187
-rw-r--r--Modules/FindCxxTest.cmake345
-rw-r--r--Modules/FindCygwin.cmake22
-rw-r--r--Modules/FindDCMTK.cmake168
-rw-r--r--Modules/FindDart.cmake17
-rw-r--r--Modules/FindDevIL.cmake61
-rw-r--r--Modules/FindDoxygen.cmake112
-rw-r--r--Modules/FindEXPAT.cmake51
-rw-r--r--Modules/FindFLEX.cmake191
-rw-r--r--Modules/FindFLTK.cmake433
-rw-r--r--Modules/FindFLTK2.cmake77
-rw-r--r--Modules/FindFreetype.cmake99
-rw-r--r--Modules/FindGCCXML.cmake27
-rw-r--r--Modules/FindGDAL.cmake150
-rw-r--r--Modules/FindGIF.cmake91
-rw-r--r--Modules/FindGLEW.cmake369
-rw-r--r--Modules/FindGLU.cmake1
-rw-r--r--Modules/FindGLUT.cmake107
-rw-r--r--Modules/FindGSL.cmake109
-rw-r--r--Modules/FindGTK.cmake35
-rw-r--r--Modules/FindGTK2.cmake211
-rw-r--r--Modules/FindGTest.cmake284
-rw-r--r--Modules/FindGettext.cmake351
-rw-r--r--Modules/FindGit.cmake55
-rw-r--r--Modules/FindGnuTLS.cmake71
-rw-r--r--Modules/FindGnuplot.cmake39
-rw-r--r--Modules/FindHDF5.cmake419
-rw-r--r--Modules/FindHSPELL.cmake45
-rw-r--r--Modules/FindHTMLHelp.cmake55
-rw-r--r--Modules/FindHg.cmake79
-rw-r--r--Modules/FindICU.cmake292
-rw-r--r--Modules/FindIce.cmake565
-rw-r--r--Modules/FindIcotool.cmake29
-rw-r--r--Modules/FindImageMagick.cmake179
-rw-r--r--Modules/FindIntl.cmake55
-rw-r--r--Modules/FindJNI.cmake251
-rw-r--r--Modules/FindJPEG.cmake150
-rw-r--r--Modules/FindJasper.cmake31
-rw-r--r--Modules/FindJava.cmake291
-rw-r--r--Modules/FindKDE3.cmake485
-rw-r--r--Modules/FindKDE4.cmake105
-rw-r--r--Modules/FindLAPACK.cmake376
-rw-r--r--Modules/FindLATEX.cmake103
-rw-r--r--Modules/FindLTTngUST.cmake64
-rw-r--r--Modules/FindLibArchive.cmake30
-rw-r--r--Modules/FindLibLZMA.cmake89
-rw-r--r--Modules/FindLibXml2.cmake80
-rw-r--r--Modules/FindLibXslt.cmake48
-rw-r--r--Modules/FindLua.cmake302
-rw-r--r--Modules/FindLua50.cmake76
-rw-r--r--Modules/FindLua51.cmake71
-rw-r--r--Modules/FindMFC.cmake40
-rw-r--r--Modules/FindMPEG.cmake67
-rw-r--r--Modules/FindMPEG2.cmake61
-rw-r--r--Modules/FindMPI.cmake2141
-rw-r--r--Modules/FindMatlab.cmake1584
-rw-r--r--Modules/FindMotif.cmake27
-rw-r--r--Modules/FindOpenAL.cmake39
-rw-r--r--Modules/FindOpenCL.cmake92
-rw-r--r--Modules/FindOpenGL.cmake480
-rw-r--r--Modules/FindOpenMP.cmake304
-rw-r--r--Modules/FindOpenSSL.cmake148
-rw-r--r--Modules/FindOpenSceneGraph.cmake195
-rw-r--r--Modules/FindOpenThreads.cmake79
-rw-r--r--Modules/FindPHP4.cmake29
-rw-r--r--Modules/FindPNG.cmake96
-rw-r--r--Modules/FindPackageHandleStandardArgs.cmake63
-rw-r--r--Modules/FindPackageMessage.cmake59
-rw-r--r--Modules/FindPerl.cmake28
-rw-r--r--Modules/FindPerlLibs.cmake277
-rw-r--r--Modules/FindPhysFS.cmake35
-rw-r--r--Modules/FindPike.cmake38
-rw-r--r--Modules/FindPkgConfig.cmake591
-rw-r--r--Modules/FindPostgreSQL.cmake159
-rw-r--r--Modules/FindProducer.cmake71
-rw-r--r--Modules/FindProtobuf.cmake504
-rw-r--r--Modules/FindPythonInterp.cmake92
-rw-r--r--Modules/FindPythonLibs.cmake134
-rw-r--r--Modules/FindQt.cmake83
-rw-r--r--Modules/FindQt3.cmake96
-rw-r--r--Modules/FindQt4.cmake668
-rw-r--r--Modules/FindQuickTime.cmake29
-rw-r--r--Modules/FindRTI.cmake63
-rw-r--r--Modules/FindRuby.cmake364
-rw-r--r--Modules/FindSDL.cmake142
-rw-r--r--Modules/FindSDL_image.cmake69
-rw-r--r--Modules/FindSDL_mixer.cmake69
-rw-r--r--Modules/FindSDL_net.cmake67
-rw-r--r--Modules/FindSDL_sound.cmake568
-rw-r--r--Modules/FindSDL_ttf.cmake67
-rw-r--r--Modules/FindSWIG.cmake51
-rw-r--r--Modules/FindSelfPackers.cmake35
-rw-r--r--Modules/FindSquish.cmake238
-rw-r--r--Modules/FindSubversion.cmake138
-rw-r--r--Modules/FindTCL.cmake142
-rw-r--r--Modules/FindTIFF.cmake75
-rw-r--r--Modules/FindTclStub.cmake87
-rw-r--r--Modules/FindTclsh.cmake46
-rw-r--r--Modules/FindThreads.cmake202
-rw-r--r--Modules/FindUnixCommands.cmake42
-rw-r--r--Modules/FindVulkan.cmake56
-rw-r--r--Modules/FindWget.cmake25
-rw-r--r--Modules/FindWish.cmake35
-rw-r--r--Modules/FindX11.cmake513
-rw-r--r--Modules/FindXCTest.cmake23
-rw-r--r--Modules/FindXMLRPC.cmake102
-rw-r--r--Modules/FindXalanC.cmake81
-rw-r--r--Modules/FindXercesC.cmake92
-rw-r--r--Modules/FindZLIB.cmake111
-rw-r--r--Modules/Findosg.cmake71
-rw-r--r--Modules/FindosgAnimation.cmake61
-rw-r--r--Modules/FindosgDB.cmake69
-rw-r--r--Modules/FindosgFX.cmake61
-rw-r--r--Modules/FindosgGA.cmake61
-rw-r--r--Modules/FindosgIntrospection.cmake63
-rw-r--r--Modules/FindosgManipulator.cmake63
-rw-r--r--Modules/FindosgParticle.cmake61
-rw-r--r--Modules/FindosgPresentation.cmake65
-rw-r--r--Modules/FindosgProducer.cmake61
-rw-r--r--Modules/FindosgQt.cmake61
-rw-r--r--Modules/FindosgShadow.cmake61
-rw-r--r--Modules/FindosgSim.cmake61
-rw-r--r--Modules/FindosgTerrain.cmake61
-rw-r--r--Modules/FindosgText.cmake61
-rw-r--r--Modules/FindosgUtil.cmake61
-rw-r--r--Modules/FindosgViewer.cmake61
-rw-r--r--Modules/FindosgVolume.cmake61
-rw-r--r--Modules/FindosgWidget.cmake63
-rw-r--r--Modules/Findosg_functions.cmake147
-rw-r--r--Modules/FindwxWidgets.cmake344
-rw-r--r--Modules/FindwxWindows.cmake166
-rw-r--r--Modules/FortranCInterface/CMakeLists.txt5
-rw-r--r--Modules/GNUInstallDirs.cmake260
-rw-r--r--Modules/GenerateExportHeader.cmake421
-rw-r--r--Modules/GetPrerequisites.cmake398
-rw-r--r--Modules/GoogleTest.cmake271
-rw-r--r--Modules/ITKCompatibility.cmake2
-rw-r--r--Modules/InstallRequiredSystemLibraries.cmake434
-rw-r--r--Modules/Internal/FeatureTesting.cmake29
-rw-r--r--Modules/KDE3Macros.cmake453
-rw-r--r--Modules/MacroAddFileDependencies.cmake41
-rw-r--r--Modules/MatlabTestsRedirect.cmake5
-rw-r--r--Modules/NSIS.template.in4
-rw-r--r--Modules/Platform/AIX-GNU.cmake4
-rw-r--r--Modules/Platform/AIX-XL.cmake22
-rw-r--r--Modules/Platform/Android-Clang-CXX.cmake7
-rw-r--r--Modules/Platform/Android-Clang.cmake1
-rw-r--r--Modules/Platform/Android-Common.cmake4
-rw-r--r--Modules/Platform/Android-Determine.cmake40
-rw-r--r--Modules/Platform/Android-GNU-CXX.cmake3
-rw-r--r--Modules/Platform/Android.cmake8
-rw-r--r--Modules/Platform/Android/Determine-Compiler-NDK.cmake13
-rw-r--r--Modules/Platform/Android/abi-common.cmake20
-rw-r--r--Modules/Platform/Android/ndk-stl-c++.cmake1
-rw-r--r--Modules/Platform/Android/ndk-stl-gabi++.cmake1
-rw-r--r--Modules/Platform/Android/ndk-stl-gnustl.cmake1
-rw-r--r--Modules/Platform/Android/ndk-stl-none.cmake1
-rw-r--r--Modules/Platform/Android/ndk-stl-stlport.cmake1
-rw-r--r--Modules/Platform/Android/ndk-stl-system.cmake1
-rw-r--r--Modules/Platform/CYGWIN-GNU.cmake3
-rw-r--r--Modules/Platform/CrayLinuxEnvironment.cmake72
-rw-r--r--Modules/Platform/Darwin-Initialize.cmake12
-rw-r--r--Modules/Platform/Darwin.cmake19
-rw-r--r--Modules/Platform/DragonFly.cmake4
-rw-r--r--Modules/Platform/FreeBSD.cmake3
-rw-r--r--Modules/Platform/Fuchsia.cmake3
-rw-r--r--Modules/Platform/GNU.cmake27
-rw-r--r--Modules/Platform/GNUtoMS_lib.bat.in1
-rw-r--r--Modules/Platform/Generic-ADSP-C.cmake4
-rw-r--r--Modules/Platform/Generic-ADSP-CXX.cmake4
-rw-r--r--Modules/Platform/Generic-SDCC-C.cmake5
-rw-r--r--Modules/Platform/Haiku.cmake1
-rw-r--r--Modules/Platform/Linux-GNU.cmake1
-rw-r--r--Modules/Platform/Linux-Intel.cmake9
-rw-r--r--Modules/Platform/Linux-PGI.cmake3
-rw-r--r--Modules/Platform/Linux.cmake1
-rw-r--r--Modules/Platform/NetBSD.cmake2
-rw-r--r--Modules/Platform/OpenBSD.cmake4
-rw-r--r--Modules/Platform/SINIX.cmake3
-rw-r--r--Modules/Platform/SunOS-GNU.cmake1
-rw-r--r--Modules/Platform/SunOS.cmake12
-rw-r--r--Modules/Platform/UNIX_SV.cmake3
-rw-r--r--Modules/Platform/UnixPaths.cmake24
-rw-r--r--Modules/Platform/UnixWare.cmake3
-rw-r--r--Modules/Platform/Windows-Clang-CXX.cmake1
-rw-r--r--Modules/Platform/Windows-Clang.cmake116
-rw-r--r--Modules/Platform/Windows-Embarcadero.cmake2
-rw-r--r--Modules/Platform/Windows-GNU.cmake3
-rw-r--r--Modules/Platform/Windows-Intel-C.cmake2
-rw-r--r--Modules/Platform/Windows-Intel-CXX.cmake2
-rw-r--r--Modules/Platform/Windows-Intel-Fortran.cmake37
-rw-r--r--Modules/Platform/Windows-Intel.cmake2
-rw-r--r--Modules/Platform/Windows-MSVC.cmake152
-rw-r--r--Modules/Platform/Windows-NVIDIA-CUDA.cmake63
-rw-r--r--Modules/Platform/Windows-df.cmake3
-rw-r--r--Modules/ProcessorCount.cmake107
-rw-r--r--Modules/Qt4ConfigDependentSettings.cmake16
-rw-r--r--Modules/Qt4Macros.cmake144
-rw-r--r--Modules/SelectLibraryConfigurations.cmake68
-rwxr-xr-xModules/Squish4RunTestCase.bat48
-rw-r--r--Modules/SquishTestScript.cmake33
-rw-r--r--Modules/TestBigEndian.cmake29
-rw-r--r--Modules/TestCXXAcceptsFlag.cmake35
-rw-r--r--Modules/TestForANSIForScope.cmake25
-rw-r--r--Modules/TestForANSIStreamHeaders.cmake25
-rw-r--r--Modules/TestForSSTREAM.cmake23
-rw-r--r--Modules/TestForSTDNamespace.cmake23
-rw-r--r--Modules/UseEcos.cmake267
-rw-r--r--Modules/UseJava.cmake1119
-rw-r--r--Modules/UseJavaClassFilelist.cmake23
-rw-r--r--Modules/UseJavaSymlinks.cmake19
-rw-r--r--Modules/UsePkgConfig.cmake37
-rw-r--r--Modules/UseQt4.cmake20
-rw-r--r--Modules/UseSWIG.cmake859
-rw-r--r--Modules/Use_wxWindows.cmake61
-rw-r--r--Modules/UsewxWidgets.cmake71
-rw-r--r--Modules/WriteBasicConfigVersionFile.cmake37
-rw-r--r--Modules/WriteCompilerDetectionHeader.cmake539
-rw-r--r--Modules/ecos_clean.cmake12
-rw-r--r--Modules/exportheader.cmake.in2
-rw-r--r--Modules/readme.txt2
-rw-r--r--README.rst49
-rw-r--r--Source/CMakeInstallDestinations.cmake7
-rw-r--r--Source/CMakeLists.txt237
-rw-r--r--Source/CMakeVersion.cmake4
-rw-r--r--Source/CMakeVersionCompute.cmake15
-rw-r--r--Source/CPack/IFW/cmCPackIFWCommon.cxx4
-rw-r--r--Source/CPack/IFW/cmCPackIFWGenerator.cxx148
-rw-r--r--Source/CPack/IFW/cmCPackIFWGenerator.h34
-rw-r--r--Source/CPack/IFW/cmCPackIFWInstaller.cxx66
-rw-r--r--Source/CPack/IFW/cmCPackIFWInstaller.h7
-rw-r--r--Source/CPack/IFW/cmCPackIFWPackage.cxx160
-rw-r--r--Source/CPack/IFW/cmCPackIFWPackage.h6
-rw-r--r--Source/CPack/IFW/cmCPackIFWRepository.cxx31
-rw-r--r--Source/CPack/OSXScriptLauncher.cxx13
-rw-r--r--Source/CPack/WiX/cmCPackWIXGenerator.cxx149
-rw-r--r--Source/CPack/WiX/cmCPackWIXGenerator.h21
-rw-r--r--Source/CPack/WiX/cmWIXAccessControlList.cxx13
-rw-r--r--Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx12
-rw-r--r--Source/CPack/WiX/cmWIXFilesSourceWriter.cxx4
-rw-r--r--Source/CPack/WiX/cmWIXPatch.cxx28
-rw-r--r--Source/CPack/WiX/cmWIXPatchParser.cxx8
-rw-r--r--Source/CPack/WiX/cmWIXRichTextFormatWriter.h2
-rw-r--r--Source/CPack/WiX/cmWIXShortcut.cxx16
-rw-r--r--Source/CPack/WiX/cmWIXSourceWriter.cxx10
-rw-r--r--Source/CPack/cmCPack7zGenerator.cxx4
-rw-r--r--Source/CPack/cmCPack7zGenerator.h6
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.cxx124
-rw-r--r--Source/CPack/cmCPackArchiveGenerator.h12
-rw-r--r--Source/CPack/cmCPackBundleGenerator.cxx37
-rw-r--r--Source/CPack/cmCPackBundleGenerator.h12
-rw-r--r--Source/CPack/cmCPackComponentGroup.cxx6
-rw-r--r--Source/CPack/cmCPackComponentGroup.h31
-rw-r--r--Source/CPack/cmCPackCygwinBinaryGenerator.cxx5
-rw-r--r--Source/CPack/cmCPackCygwinBinaryGenerator.h2
-rw-r--r--Source/CPack/cmCPackCygwinSourceGenerator.cxx16
-rw-r--r--Source/CPack/cmCPackCygwinSourceGenerator.h2
-rw-r--r--Source/CPack/cmCPackDebGenerator.cxx1222
-rw-r--r--Source/CPack/cmCPackDebGenerator.h16
-rw-r--r--Source/CPack/cmCPackDragNDropGenerator.cxx158
-rw-r--r--Source/CPack/cmCPackDragNDropGenerator.h20
-rw-r--r--Source/CPack/cmCPackGenerator.cxx972
-rw-r--r--Source/CPack/cmCPackGenerator.h44
-rw-r--r--Source/CPack/cmCPackGeneratorFactory.cxx56
-rw-r--r--Source/CPack/cmCPackGeneratorFactory.h3
-rw-r--r--Source/CPack/cmCPackLog.cxx9
-rw-r--r--Source/CPack/cmCPackLog.h5
-rw-r--r--Source/CPack/cmCPackNSISGenerator.cxx330
-rw-r--r--Source/CPack/cmCPackNSISGenerator.h20
-rw-r--r--Source/CPack/cmCPackOSXX11Generator.cxx60
-rw-r--r--Source/CPack/cmCPackOSXX11Generator.h12
-rw-r--r--Source/CPack/cmCPackPKGGenerator.cxx108
-rw-r--r--Source/CPack/cmCPackPKGGenerator.h10
-rw-r--r--Source/CPack/cmCPackPackageMakerGenerator.cxx87
-rw-r--r--Source/CPack/cmCPackPackageMakerGenerator.h12
-rw-r--r--Source/CPack/cmCPackProductBuildGenerator.cxx38
-rw-r--r--Source/CPack/cmCPackProductBuildGenerator.h10
-rw-r--r--Source/CPack/cmCPackRPMGenerator.cxx56
-rw-r--r--Source/CPack/cmCPackRPMGenerator.h14
-rw-r--r--Source/CPack/cmCPackSTGZGenerator.cxx19
-rw-r--r--Source/CPack/cmCPackSTGZGenerator.h12
-rw-r--r--Source/CPack/cmCPackTGZGenerator.cxx4
-rw-r--r--Source/CPack/cmCPackTGZGenerator.h6
-rw-r--r--Source/CPack/cmCPackTXZGenerator.cxx4
-rw-r--r--Source/CPack/cmCPackTXZGenerator.h6
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.cxx4
-rw-r--r--Source/CPack/cmCPackTarBZip2Generator.h6
-rw-r--r--Source/CPack/cmCPackTarCompressGenerator.cxx4
-rw-r--r--Source/CPack/cmCPackTarCompressGenerator.h6
-rw-r--r--Source/CPack/cmCPackZIPGenerator.cxx4
-rw-r--r--Source/CPack/cmCPackZIPGenerator.h6
-rw-r--r--Source/CPack/cpack.cxx182
-rw-r--r--Source/CTest/cmCTestBZR.cxx70
-rw-r--r--Source/CTest/cmCTestBZR.h14
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.cxx181
-rw-r--r--Source/CTest/cmCTestBuildAndTestHandler.h17
-rw-r--r--Source/CTest/cmCTestBuildCommand.cxx50
-rw-r--r--Source/CTest/cmCTestBuildCommand.h12
-rw-r--r--Source/CTest/cmCTestBuildHandler.cxx341
-rw-r--r--Source/CTest/cmCTestBuildHandler.h18
-rw-r--r--Source/CTest/cmCTestCVS.cxx47
-rw-r--r--Source/CTest/cmCTestCVS.h8
-rw-r--r--Source/CTest/cmCTestCommand.h4
-rw-r--r--Source/CTest/cmCTestConfigureCommand.cxx38
-rw-r--r--Source/CTest/cmCTestConfigureCommand.h8
-rw-r--r--Source/CTest/cmCTestConfigureHandler.cxx33
-rw-r--r--Source/CTest/cmCTestConfigureHandler.h6
-rw-r--r--Source/CTest/cmCTestCoverageCommand.cxx8
-rw-r--r--Source/CTest/cmCTestCoverageCommand.h12
-rw-r--r--Source/CTest/cmCTestCoverageHandler.cxx519
-rw-r--r--Source/CTest/cmCTestCoverageHandler.h12
-rw-r--r--Source/CTest/cmCTestCurl.cxx66
-rw-r--r--Source/CTest/cmCTestCurl.h4
-rw-r--r--Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h6
-rw-r--r--Source/CTest/cmCTestGIT.cxx123
-rw-r--r--Source/CTest/cmCTestGIT.h14
-rw-r--r--Source/CTest/cmCTestGenericHandler.cxx20
-rw-r--r--Source/CTest/cmCTestGenericHandler.h2
-rw-r--r--Source/CTest/cmCTestGlobalVC.cxx28
-rw-r--r--Source/CTest/cmCTestGlobalVC.h8
-rw-r--r--Source/CTest/cmCTestHG.cxx83
-rw-r--r--Source/CTest/cmCTestHG.h14
-rw-r--r--Source/CTest/cmCTestHandlerCommand.cxx68
-rw-r--r--Source/CTest/cmCTestHandlerCommand.h4
-rw-r--r--Source/CTest/cmCTestLaunch.cxx177
-rw-r--r--Source/CTest/cmCTestLaunch.h15
-rw-r--r--Source/CTest/cmCTestMemCheckCommand.cxx7
-rw-r--r--Source/CTest/cmCTestMemCheckCommand.h8
-rw-r--r--Source/CTest/cmCTestMemCheckHandler.cxx234
-rw-r--r--Source/CTest/cmCTestMemCheckHandler.h23
-rw-r--r--Source/CTest/cmCTestMultiProcessHandler.cxx820
-rw-r--r--Source/CTest/cmCTestMultiProcessHandler.h26
-rw-r--r--Source/CTest/cmCTestP4.cxx81
-rw-r--r--Source/CTest/cmCTestP4.h14
-rw-r--r--Source/CTest/cmCTestReadCustomFilesCommand.cxx5
-rw-r--r--Source/CTest/cmCTestReadCustomFilesCommand.h6
-rw-r--r--Source/CTest/cmCTestRunScriptCommand.cxx3
-rw-r--r--Source/CTest/cmCTestRunScriptCommand.h6
-rw-r--r--Source/CTest/cmCTestRunTest.cxx675
-rw-r--r--Source/CTest/cmCTestRunTest.h67
-rw-r--r--Source/CTest/cmCTestSVN.cxx98
-rw-r--r--Source/CTest/cmCTestSVN.h24
-rw-r--r--Source/CTest/cmCTestScriptHandler.cxx283
-rw-r--r--Source/CTest/cmCTestScriptHandler.h26
-rw-r--r--Source/CTest/cmCTestSleepCommand.h6
-rw-r--r--Source/CTest/cmCTestStartCommand.cxx83
-rw-r--r--Source/CTest/cmCTestStartCommand.h6
-rw-r--r--Source/CTest/cmCTestSubmitCommand.cxx160
-rw-r--r--Source/CTest/cmCTestSubmitCommand.h44
-rw-r--r--Source/CTest/cmCTestSubmitHandler.cxx1145
-rw-r--r--Source/CTest/cmCTestSubmitHandler.h39
-rw-r--r--Source/CTest/cmCTestTestCommand.cxx31
-rw-r--r--Source/CTest/cmCTestTestCommand.h8
-rw-r--r--Source/CTest/cmCTestTestHandler.cxx862
-rw-r--r--Source/CTest/cmCTestTestHandler.h62
-rw-r--r--Source/CTest/cmCTestUpdateCommand.cxx15
-rw-r--r--Source/CTest/cmCTestUpdateCommand.h8
-rw-r--r--Source/CTest/cmCTestUpdateHandler.cxx85
-rw-r--r--Source/CTest/cmCTestUpdateHandler.h6
-rw-r--r--Source/CTest/cmCTestUploadCommand.cxx18
-rw-r--r--Source/CTest/cmCTestUploadCommand.h18
-rw-r--r--Source/CTest/cmCTestUploadHandler.cxx22
-rw-r--r--Source/CTest/cmCTestUploadHandler.h15
-rw-r--r--Source/CTest/cmCTestVC.cxx40
-rw-r--r--Source/CTest/cmCTestVC.h11
-rw-r--r--Source/CTest/cmParseBlanketJSCoverage.cxx10
-rw-r--r--Source/CTest/cmParseCacheCoverage.cxx31
-rw-r--r--Source/CTest/cmParseCacheCoverage.h4
-rw-r--r--Source/CTest/cmParseCoberturaCoverage.cxx40
-rw-r--r--Source/CTest/cmParseDelphiCoverage.cxx12
-rw-r--r--Source/CTest/cmParseGTMCoverage.cxx39
-rw-r--r--Source/CTest/cmParseGTMCoverage.h4
-rw-r--r--Source/CTest/cmParseJacocoCoverage.cxx26
-rw-r--r--Source/CTest/cmParseMumpsCoverage.cxx21
-rw-r--r--Source/CTest/cmParsePHPCoverage.cxx7
-rw-r--r--Source/CTest/cmProcess.cxx742
-rw-r--r--Source/CTest/cmProcess.h104
-rw-r--r--Source/Checks/cm_cxx_features.cmake27
-rw-r--r--Source/CursesDialog/CMakeLists.txt30
-rw-r--r--Source/CursesDialog/ccmake.cxx55
-rw-r--r--Source/CursesDialog/cmCursesBoolWidget.h9
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.cxx13
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.h9
-rw-r--r--Source/CursesDialog/cmCursesDummyWidget.h9
-rw-r--r--Source/CursesDialog/cmCursesFilePathWidget.h7
-rw-r--r--Source/CursesDialog/cmCursesForm.cxx4
-rw-r--r--Source/CursesDialog/cmCursesForm.h11
-rw-r--r--Source/CursesDialog/cmCursesLabelWidget.cxx4
-rw-r--r--Source/CursesDialog/cmCursesLabelWidget.h11
-rw-r--r--Source/CursesDialog/cmCursesLongMessageForm.cxx15
-rw-r--r--Source/CursesDialog/cmCursesLongMessageForm.h15
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx278
-rw-r--r--Source/CursesDialog/cmCursesMainForm.h24
-rw-r--r--Source/CursesDialog/cmCursesOptionsWidget.cxx8
-rw-r--r--Source/CursesDialog/cmCursesOptionsWidget.h9
-rw-r--r--Source/CursesDialog/cmCursesPathWidget.h13
-rw-r--r--Source/CursesDialog/cmCursesStandardIncludes.h19
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.cxx6
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.h13
-rw-r--r--Source/CursesDialog/cmCursesWidget.cxx2
-rw-r--r--Source/CursesDialog/cmCursesWidget.h7
-rw-r--r--Source/CursesDialog/form/CMakeLists.txt17
-rw-r--r--Source/CursesDialog/form/frm_post.c2
-rw-r--r--Source/LexerParser/cmCommandArgumentLexer.cxx698
-rw-r--r--Source/LexerParser/cmCommandArgumentLexer.h441
-rw-r--r--Source/LexerParser/cmCommandArgumentLexer.in.l38
-rw-r--r--Source/LexerParser/cmCommandArgumentParser.cxx111
-rw-r--r--Source/LexerParser/cmCommandArgumentParser.y3
-rw-r--r--Source/LexerParser/cmDependsJavaLexer.cxx773
-rw-r--r--Source/LexerParser/cmDependsJavaLexer.h441
-rw-r--r--Source/LexerParser/cmDependsJavaLexer.in.l19
-rw-r--r--Source/LexerParser/cmDependsJavaParser.cxx1437
-rw-r--r--Source/LexerParser/cmDependsJavaParser.y5
-rw-r--r--Source/LexerParser/cmExprLexer.cxx790
-rw-r--r--Source/LexerParser/cmExprLexer.h441
-rw-r--r--Source/LexerParser/cmExprLexer.in.l26
-rw-r--r--Source/LexerParser/cmExprParser.cxx109
-rw-r--r--Source/LexerParser/cmExprParser.y7
-rw-r--r--Source/LexerParser/cmFortranLexer.cxx973
-rw-r--r--Source/LexerParser/cmFortranLexer.h441
-rw-r--r--Source/LexerParser/cmFortranLexer.in.l19
-rw-r--r--Source/LexerParser/cmFortranParser.cxx125
-rw-r--r--Source/LexerParser/cmFortranParser.y7
-rw-r--r--Source/LexerParser/cmFortranParserTokens.h2
-rw-r--r--Source/LexerParser/cmListFileLexer.c887
-rw-r--r--Source/LexerParser/cmListFileLexer.in.l36
-rw-r--r--Source/Modules/FindLibUV.cmake2
-rw-r--r--Source/QtDialog/AddCacheEntry.cxx16
-rw-r--r--Source/QtDialog/AddCacheEntry.h4
-rw-r--r--Source/QtDialog/CMakeLists.txt28
-rw-r--r--Source/QtDialog/CMakeSetup.cxx114
-rw-r--r--Source/QtDialog/CMakeSetup.icnsbin138205 -> 195235 bytes
-rw-r--r--Source/QtDialog/CMakeSetup.icobin24542 -> 159613 bytes
-rw-r--r--Source/QtDialog/CMakeSetup128.pngbin13269 -> 7981 bytes
-rw-r--r--Source/QtDialog/CMakeSetup32.pngbin358 -> 1632 bytes
-rw-r--r--Source/QtDialog/CMakeSetup64.pngbin7213 -> 3566 bytes
-rw-r--r--Source/QtDialog/CMakeSetupDialog.cxx77
-rw-r--r--Source/QtDialog/CMakeSetupDialog.h15
-rw-r--r--Source/QtDialog/CMakeSetupDialog.ui3
-rw-r--r--Source/QtDialog/Compilers.h8
-rw-r--r--Source/QtDialog/Delete16.pngbin731 -> 538 bytes
-rw-r--r--Source/QtDialog/FirstConfigure.cxx107
-rw-r--r--Source/QtDialog/FirstConfigure.h17
-rw-r--r--Source/QtDialog/Plus16.pngbin358 -> 207 bytes
-rw-r--r--Source/QtDialog/QCMake.cxx150
-rw-r--r--Source/QtDialog/QCMake.h33
-rw-r--r--Source/QtDialog/QCMakeCacheView.cxx18
-rw-r--r--Source/QtDialog/QCMakeWidgets.cxx11
-rw-r--r--Source/QtDialog/QCMakeWidgets.h9
-rw-r--r--Source/QtDialog/RegexExplorer.cxx6
-rw-r--r--Source/QtDialog/RegexExplorer.h4
-rw-r--r--Source/QtDialog/WarningMessagesDialog.h4
-rw-r--r--Source/bindexplib.cxx184
-rw-r--r--Source/bindexplib.h2
-rw-r--r--Source/cmAddCompileOptionsCommand.cxx5
-rw-r--r--Source/cmAddCompileOptionsCommand.h6
-rw-r--r--Source/cmAddCustomCommandCommand.cxx203
-rw-r--r--Source/cmAddCustomCommandCommand.h6
-rw-r--r--Source/cmAddCustomTargetCommand.cxx74
-rw-r--r--Source/cmAddCustomTargetCommand.h6
-rw-r--r--Source/cmAddDefinitionsCommand.cxx5
-rw-r--r--Source/cmAddDefinitionsCommand.h6
-rw-r--r--Source/cmAddDependenciesCommand.cxx15
-rw-r--r--Source/cmAddDependenciesCommand.h6
-rw-r--r--Source/cmAddExecutableCommand.cxx57
-rw-r--r--Source/cmAddExecutableCommand.h6
-rw-r--r--Source/cmAddLibraryCommand.cxx67
-rw-r--r--Source/cmAddLibraryCommand.h6
-rw-r--r--Source/cmAddSubDirectoryCommand.cxx29
-rw-r--r--Source/cmAddSubDirectoryCommand.h6
-rw-r--r--Source/cmAddTestCommand.cxx3
-rw-r--r--Source/cmAddTestCommand.h6
-rw-r--r--Source/cmAlgorithms.h259
-rw-r--r--Source/cmArchiveWrite.cxx58
-rw-r--r--Source/cmArchiveWrite.h18
-rw-r--r--Source/cmAuxSourceDirectoryCommand.cxx11
-rw-r--r--Source/cmAuxSourceDirectoryCommand.h6
-rw-r--r--Source/cmBase32.cxx8
-rw-r--r--Source/cmBreakCommand.cxx14
-rw-r--r--Source/cmBreakCommand.h6
-rw-r--r--Source/cmBuildCommand.cxx4
-rw-r--r--Source/cmBuildCommand.h6
-rw-r--r--Source/cmBuildNameCommand.cxx6
-rw-r--r--Source/cmBuildNameCommand.h6
-rw-r--r--Source/cmCLocaleEnvironmentScope.cxx5
-rw-r--r--Source/cmCLocaleEnvironmentScope.h8
-rw-r--r--Source/cmCMakeHostSystemInformationCommand.cxx87
-rw-r--r--Source/cmCMakeHostSystemInformationCommand.h8
-rw-r--r--Source/cmCMakeMinimumRequired.cxx88
-rw-r--r--Source/cmCMakeMinimumRequired.h8
-rw-r--r--Source/cmCMakePolicyCommand.cxx65
-rw-r--r--Source/cmCMakePolicyCommand.h7
-rw-r--r--Source/cmCPackPropertiesGenerator.cxx15
-rw-r--r--Source/cmCPackPropertiesGenerator.h10
-rw-r--r--Source/cmCPluginAPI.cxx153
-rw-r--r--Source/cmCPluginAPI.h8
-rw-r--r--Source/cmCTest.cxx1945
-rw-r--r--Source/cmCTest.h353
-rw-r--r--Source/cmCacheManager.cxx215
-rw-r--r--Source/cmCacheManager.h60
-rw-r--r--Source/cmCallVisualStudioMacro.cxx100
-rw-r--r--Source/cmCallVisualStudioMacro.h14
-rw-r--r--Source/cmCommand.h16
-rw-r--r--Source/cmCommandArgumentParserHelper.cxx86
-rw-r--r--Source/cmCommandArgumentParserHelper.h29
-rw-r--r--Source/cmCommands.cxx138
-rw-r--r--Source/cmCommonTargetGenerator.cxx56
-rw-r--r--Source/cmCommonTargetGenerator.h4
-rw-r--r--Source/cmComputeComponentGraph.cxx18
-rw-r--r--Source/cmComputeLinkDepends.cxx167
-rw-r--r--Source/cmComputeLinkDepends.h32
-rw-r--r--Source/cmComputeLinkInformation.cxx297
-rw-r--r--Source/cmComputeLinkInformation.h48
-rw-r--r--Source/cmComputeTargetDepends.cxx208
-rw-r--r--Source/cmComputeTargetDepends.h7
-rw-r--r--Source/cmConditionEvaluator.cxx75
-rw-r--r--Source/cmConditionEvaluator.h21
-rw-r--r--Source/cmConfigure.cmake.h.in44
-rw-r--r--Source/cmConfigureFileCommand.cxx26
-rw-r--r--Source/cmConfigureFileCommand.h12
-rw-r--r--Source/cmContinueCommand.cxx6
-rw-r--r--Source/cmContinueCommand.h6
-rw-r--r--Source/cmConvertMSBuildXMLToJSON.py21
-rw-r--r--Source/cmCoreTryCompile.cxx307
-rw-r--r--Source/cmCoreTryCompile.h4
-rw-r--r--Source/cmCreateTestSourceList.cxx3
-rw-r--r--Source/cmCreateTestSourceList.h6
-rw-r--r--Source/cmCryptoHash.cxx34
-rw-r--r--Source/cmCryptoHash.h12
-rw-r--r--Source/cmCurl.cxx70
-rw-r--r--Source/cmCurl.h6
-rw-r--r--Source/cmCustomCommand.cxx55
-rw-r--r--Source/cmCustomCommand.h29
-rw-r--r--Source/cmCustomCommandGenerator.cxx160
-rw-r--r--Source/cmCustomCommandGenerator.h16
-rw-r--r--Source/cmDefinePropertyCommand.h6
-rw-r--r--Source/cmDefinitions.cxx34
-rw-r--r--Source/cmDefinitions.h21
-rw-r--r--Source/cmDepends.cxx230
-rw-r--r--Source/cmDepends.h51
-rw-r--r--Source/cmDependsC.cxx185
-rw-r--r--Source/cmDependsC.h26
-rw-r--r--Source/cmDependsFortran.cxx290
-rw-r--r--Source/cmDependsFortran.h36
-rw-r--r--Source/cmDependsJava.cxx12
-rw-r--r--Source/cmDependsJava.h18
-rw-r--r--Source/cmDependsJavaParserHelper.cxx78
-rw-r--r--Source/cmDependsJavaParserHelper.h4
-rw-r--r--Source/cmDisallowedCommand.cxx6
-rw-r--r--Source/cmDisallowedCommand.h15
-rw-r--r--Source/cmDocumentation.cxx189
-rw-r--r--Source/cmDocumentation.h21
-rw-r--r--Source/cmDocumentationEntry.h3
-rw-r--r--Source/cmDocumentationFormatter.cxx28
-rw-r--r--Source/cmDocumentationFormatter.h4
-rw-r--r--Source/cmDocumentationSection.cxx6
-rw-r--r--Source/cmDocumentationSection.h5
-rw-r--r--Source/cmDynamicLoader.cxx14
-rw-r--r--Source/cmDynamicLoader.h8
-rw-r--r--Source/cmELF.cxx108
-rw-r--r--Source/cmELF.h11
-rw-r--r--Source/cmEnableLanguageCommand.cxx7
-rw-r--r--Source/cmEnableLanguageCommand.h6
-rw-r--r--Source/cmEnableTestingCommand.h6
-rw-r--r--Source/cmExecProgramCommand.cxx66
-rw-r--r--Source/cmExecProgramCommand.h11
-rw-r--r--Source/cmExecuteProcessCommand.cxx378
-rw-r--r--Source/cmExecuteProcessCommand.h6
-rw-r--r--Source/cmExecutionStatus.h16
-rw-r--r--Source/cmExpandedCommandArgument.cxx16
-rw-r--r--Source/cmExpandedCommandArgument.h5
-rw-r--r--Source/cmExportBuildAndroidMKGenerator.cxx82
-rw-r--r--Source/cmExportBuildAndroidMKGenerator.h31
-rw-r--r--Source/cmExportBuildFileGenerator.cxx102
-rw-r--r--Source/cmExportBuildFileGenerator.h16
-rw-r--r--Source/cmExportCommand.cxx204
-rw-r--r--Source/cmExportCommand.h30
-rw-r--r--Source/cmExportFileGenerator.cxx324
-rw-r--r--Source/cmExportFileGenerator.h18
-rw-r--r--Source/cmExportInstallAndroidMKGenerator.cxx8
-rw-r--r--Source/cmExportInstallAndroidMKGenerator.h47
-rw-r--r--Source/cmExportInstallFileGenerator.cxx125
-rw-r--r--Source/cmExportInstallFileGenerator.h18
-rw-r--r--Source/cmExportLibraryDependenciesCommand.cxx60
-rw-r--r--Source/cmExportLibraryDependenciesCommand.h12
-rw-r--r--Source/cmExportSet.cxx5
-rw-r--r--Source/cmExportSet.h8
-rw-r--r--Source/cmExportSetMap.cxx2
-rw-r--r--Source/cmExportSetMap.h5
-rw-r--r--Source/cmExportTryCompileFileGenerator.cxx52
-rw-r--r--Source/cmExportTryCompileFileGenerator.h16
-rw-r--r--Source/cmExprParserHelper.cxx62
-rw-r--r--Source/cmExprParserHelper.h17
-rw-r--r--Source/cmExternalMakefileProjectGenerator.cxx18
-rw-r--r--Source/cmExternalMakefileProjectGenerator.h24
-rw-r--r--Source/cmExtraCodeBlocksGenerator.cxx291
-rw-r--r--Source/cmExtraCodeBlocksGenerator.h11
-rw-r--r--Source/cmExtraCodeLiteGenerator.cxx178
-rw-r--r--Source/cmExtraCodeLiteGenerator.h6
-rw-r--r--Source/cmExtraEclipseCDT4Generator.cxx328
-rw-r--r--Source/cmExtraEclipseCDT4Generator.h8
-rw-r--r--Source/cmExtraKateGenerator.cxx95
-rw-r--r--Source/cmExtraKateGenerator.h7
-rw-r--r--Source/cmExtraSublimeTextGenerator.cxx180
-rw-r--r--Source/cmExtraSublimeTextGenerator.h12
-rw-r--r--Source/cmFLTKWrapUICommand.cxx18
-rw-r--r--Source/cmFLTKWrapUICommand.h10
-rw-r--r--Source/cmFileCommand.cxx2038
-rw-r--r--Source/cmFileCommand.h10
-rw-r--r--Source/cmFileLock.cxx6
-rw-r--r--Source/cmFileLock.h42
-rw-r--r--Source/cmFileLockPool.cxx36
-rw-r--r--Source/cmFileLockPool.h30
-rw-r--r--Source/cmFileLockResult.cxx19
-rw-r--r--Source/cmFileLockResult.h32
-rw-r--r--Source/cmFileLockUnix.cxx5
-rw-r--r--Source/cmFileLockWin32.cxx1
-rw-r--r--Source/cmFileMonitor.cxx46
-rw-r--r--Source/cmFileMonitor.h6
-rw-r--r--Source/cmFilePathChecksum.cxx55
-rw-r--r--Source/cmFilePathChecksum.h29
-rw-r--r--Source/cmFindBase.cxx46
-rw-r--r--Source/cmFindCommon.cxx76
-rw-r--r--Source/cmFindCommon.h9
-rw-r--r--Source/cmFindFileCommand.h4
-rw-r--r--Source/cmFindLibraryCommand.cxx91
-rw-r--r--Source/cmFindLibraryCommand.h6
-rw-r--r--Source/cmFindPackageCommand.cxx591
-rw-r--r--Source/cmFindPackageCommand.h55
-rw-r--r--Source/cmFindPathCommand.cxx28
-rw-r--r--Source/cmFindPathCommand.h6
-rw-r--r--Source/cmFindProgramCommand.cxx80
-rw-r--r--Source/cmFindProgramCommand.h6
-rw-r--r--Source/cmForEachCommand.cxx39
-rw-r--r--Source/cmForEachCommand.h12
-rw-r--r--Source/cmFortranParser.h65
-rw-r--r--Source/cmFortranParserImpl.cxx117
-rw-r--r--Source/cmFunctionBlocker.h2
-rw-r--r--Source/cmFunctionCommand.cxx25
-rw-r--r--Source/cmFunctionCommand.h14
-rw-r--r--Source/cmGeneratedFileStream.cxx59
-rw-r--r--Source/cmGeneratedFileStream.h36
-rw-r--r--Source/cmGeneratorExpression.cxx88
-rw-r--r--Source/cmGeneratorExpression.h98
-rw-r--r--Source/cmGeneratorExpressionContext.cxx14
-rw-r--r--Source/cmGeneratorExpressionContext.h8
-rw-r--r--Source/cmGeneratorExpressionDAGChecker.cxx54
-rw-r--r--Source/cmGeneratorExpressionDAGChecker.h28
-rw-r--r--Source/cmGeneratorExpressionEvaluationFile.cxx138
-rw-r--r--Source/cmGeneratorExpressionEvaluationFile.h23
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx70
-rw-r--r--Source/cmGeneratorExpressionEvaluator.h40
-rw-r--r--Source/cmGeneratorExpressionLexer.cxx28
-rw-r--r--Source/cmGeneratorExpressionLexer.h4
-rw-r--r--Source/cmGeneratorExpressionNode.cxx1911
-rw-r--r--Source/cmGeneratorExpressionNode.h6
-rw-r--r--Source/cmGeneratorExpressionParser.cxx30
-rw-r--r--Source/cmGeneratorExpressionParser.h3
-rw-r--r--Source/cmGeneratorTarget.cxx2449
-rw-r--r--Source/cmGeneratorTarget.h207
-rw-r--r--Source/cmGetCMakePropertyCommand.cxx2
-rw-r--r--Source/cmGetCMakePropertyCommand.h6
-rw-r--r--Source/cmGetDirectoryPropertyCommand.cxx10
-rw-r--r--Source/cmGetDirectoryPropertyCommand.h6
-rw-r--r--Source/cmGetFilenameComponentCommand.cxx39
-rw-r--r--Source/cmGetFilenameComponentCommand.h6
-rw-r--r--Source/cmGetPropertyCommand.cxx13
-rw-r--r--Source/cmGetPropertyCommand.h6
-rw-r--r--Source/cmGetSourceFilePropertyCommand.cxx2
-rw-r--r--Source/cmGetSourceFilePropertyCommand.h6
-rw-r--r--Source/cmGetTargetPropertyCommand.cxx10
-rw-r--r--Source/cmGetTargetPropertyCommand.h6
-rw-r--r--Source/cmGetTestPropertyCommand.cxx2
-rw-r--r--Source/cmGetTestPropertyCommand.h6
-rw-r--r--Source/cmGhsMultiGpj.cxx35
-rw-r--r--Source/cmGhsMultiGpj.h13
-rw-r--r--Source/cmGhsMultiTargetGenerator.cxx1086
-rw-r--r--Source/cmGhsMultiTargetGenerator.h124
-rw-r--r--Source/cmGlobalBorlandMakefileGenerator.cxx33
-rw-r--r--Source/cmGlobalBorlandMakefileGenerator.h28
-rw-r--r--Source/cmGlobalCommonGenerator.cxx4
-rw-r--r--Source/cmGlobalCommonGenerator.h4
-rw-r--r--Source/cmGlobalGenerator.cxx1461
-rw-r--r--Source/cmGlobalGenerator.h215
-rw-r--r--Source/cmGlobalGeneratorFactory.h40
-rw-r--r--Source/cmGlobalGhsMultiGenerator.cxx970
-rw-r--r--Source/cmGlobalGhsMultiGenerator.h191
-rw-r--r--Source/cmGlobalJOMMakefileGenerator.cxx27
-rw-r--r--Source/cmGlobalJOMMakefileGenerator.h20
-rw-r--r--Source/cmGlobalMSYSMakefileGenerator.cxx10
-rw-r--r--Source/cmGlobalMSYSMakefileGenerator.h2
-rw-r--r--Source/cmGlobalMinGWMakefileGenerator.cxx4
-rw-r--r--Source/cmGlobalMinGWMakefileGenerator.h2
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.cxx38
-rw-r--r--Source/cmGlobalNMakeMakefileGenerator.h24
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx1510
-rw-r--r--Source/cmGlobalNinjaGenerator.h194
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.cxx489
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.h80
-rw-r--r--Source/cmGlobalVisualStudio10Generator.cxx784
-rw-r--r--Source/cmGlobalVisualStudio10Generator.h95
-rw-r--r--Source/cmGlobalVisualStudio11Generator.cxx101
-rw-r--r--Source/cmGlobalVisualStudio11Generator.h26
-rw-r--r--Source/cmGlobalVisualStudio12Generator.cxx80
-rw-r--r--Source/cmGlobalVisualStudio12Generator.h30
-rw-r--r--Source/cmGlobalVisualStudio14Generator.cxx153
-rw-r--r--Source/cmGlobalVisualStudio14Generator.h29
-rw-r--r--Source/cmGlobalVisualStudio71Generator.cxx50
-rw-r--r--Source/cmGlobalVisualStudio71Generator.h28
-rw-r--r--Source/cmGlobalVisualStudio7Generator.cxx260
-rw-r--r--Source/cmGlobalVisualStudio7Generator.h68
-rw-r--r--Source/cmGlobalVisualStudio8Generator.cxx290
-rw-r--r--Source/cmGlobalVisualStudio8Generator.h80
-rw-r--r--Source/cmGlobalVisualStudio9Generator.cxx55
-rw-r--r--Source/cmGlobalVisualStudio9Generator.h16
-rw-r--r--Source/cmGlobalVisualStudioGenerator.cxx378
-rw-r--r--Source/cmGlobalVisualStudioGenerator.h60
-rw-r--r--Source/cmGlobalWatcomWMakeGenerator.cxx32
-rw-r--r--Source/cmGlobalWatcomWMakeGenerator.h23
-rw-r--r--Source/cmGlobalXCodeGenerator.cxx1817
-rw-r--r--Source/cmGlobalXCodeGenerator.h110
-rw-r--r--Source/cmGraphAdjacencyList.h10
-rw-r--r--Source/cmGraphVizWriter.cxx306
-rw-r--r--Source/cmGraphVizWriter.h15
-rw-r--r--Source/cmHexFileConverter.cxx29
-rw-r--r--Source/cmHexFileConverter.h8
-rw-r--r--Source/cmIDEFlagTable.h13
-rw-r--r--Source/cmIDEOptions.cxx97
-rw-r--r--Source/cmIDEOptions.h45
-rw-r--r--Source/cmIfCommand.cxx69
-rw-r--r--Source/cmIfCommand.h25
-rw-r--r--Source/cmIncludeCommand.cxx26
-rw-r--r--Source/cmIncludeCommand.h6
-rw-r--r--Source/cmIncludeDirectoryCommand.cxx28
-rw-r--r--Source/cmIncludeDirectoryCommand.h6
-rw-r--r--Source/cmIncludeExternalMSProjectCommand.cxx23
-rw-r--r--Source/cmIncludeExternalMSProjectCommand.h9
-rw-r--r--Source/cmIncludeRegularExpressionCommand.h9
-rw-r--r--Source/cmInstallCommand.cxx812
-rw-r--r--Source/cmInstallCommand.h28
-rw-r--r--Source/cmInstallCommandArguments.cxx135
-rw-r--r--Source/cmInstallCommandArguments.h39
-rw-r--r--Source/cmInstallDirectoryGenerator.cxx38
-rw-r--r--Source/cmInstallDirectoryGenerator.h10
-rw-r--r--Source/cmInstallExportAndroidMKGenerator.cxx29
-rw-r--r--Source/cmInstallExportAndroidMKGenerator.h2
-rw-r--r--Source/cmInstallExportGenerator.cxx46
-rw-r--r--Source/cmInstallExportGenerator.h12
-rw-r--r--Source/cmInstallFilesCommand.cxx15
-rw-r--r--Source/cmInstallFilesCommand.h12
-rw-r--r--Source/cmInstallFilesGenerator.cxx33
-rw-r--r--Source/cmInstallFilesGenerator.h10
-rw-r--r--Source/cmInstallGenerator.cxx35
-rw-r--r--Source/cmInstallGenerator.h23
-rw-r--r--Source/cmInstallProgramsCommand.cxx7
-rw-r--r--Source/cmInstallProgramsCommand.h10
-rw-r--r--Source/cmInstallScriptGenerator.cxx76
-rw-r--r--Source/cmInstallScriptGenerator.h18
-rw-r--r--Source/cmInstallTargetGenerator.cxx261
-rw-r--r--Source/cmInstallTargetGenerator.h24
-rw-r--r--Source/cmInstallTargetsCommand.cxx10
-rw-r--r--Source/cmInstallTargetsCommand.h6
-rw-r--r--Source/cmInstalledFile.cxx22
-rw-r--r--Source/cmInstalledFile.h12
-rw-r--r--Source/cmLinkDirectoriesCommand.cxx37
-rw-r--r--Source/cmLinkDirectoriesCommand.h9
-rw-r--r--Source/cmLinkItem.h85
-rw-r--r--Source/cmLinkLibrariesCommand.cxx2
-rw-r--r--Source/cmLinkLibrariesCommand.h6
-rw-r--r--Source/cmLinkLineComputer.cxx68
-rw-r--r--Source/cmLinkLineComputer.h7
-rw-r--r--Source/cmLinkLineDeviceComputer.cxx186
-rw-r--r--Source/cmLinkLineDeviceComputer.h36
-rw-r--r--Source/cmLinkedTree.h13
-rw-r--r--Source/cmListCommand.cxx1049
-rw-r--r--Source/cmListCommand.h12
-rw-r--r--Source/cmListFileCache.cxx234
-rw-r--r--Source/cmListFileCache.h103
-rw-r--r--Source/cmListFileLexer.h3
-rw-r--r--Source/cmLoadCacheCommand.cxx27
-rw-r--r--Source/cmLoadCacheCommand.h6
-rw-r--r--Source/cmLoadCommandCommand.cxx44
-rw-r--r--Source/cmLoadCommandCommand.h6
-rw-r--r--Source/cmLocalCommonGenerator.cxx36
-rw-r--r--Source/cmLocalCommonGenerator.h14
-rw-r--r--Source/cmLocalGenerator.cxx1365
-rw-r--r--Source/cmLocalGenerator.h172
-rw-r--r--Source/cmLocalGhsMultiGenerator.cxx90
-rw-r--r--Source/cmLocalGhsMultiGenerator.h24
-rw-r--r--Source/cmLocalNinjaGenerator.cxx278
-rw-r--r--Source/cmLocalNinjaGenerator.h32
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.cxx686
-rw-r--r--Source/cmLocalUnixMakefileGenerator3.h105
-rw-r--r--Source/cmLocalVisualStudio10Generator.cxx63
-rw-r--r--Source/cmLocalVisualStudio10Generator.h23
-rw-r--r--Source/cmLocalVisualStudio7Generator.cxx690
-rw-r--r--Source/cmLocalVisualStudio7Generator.h35
-rw-r--r--Source/cmLocalVisualStudioGenerator.cxx38
-rw-r--r--Source/cmLocalVisualStudioGenerator.h16
-rw-r--r--Source/cmLocalXCodeGenerator.cxx30
-rw-r--r--Source/cmLocalXCodeGenerator.h18
-rw-r--r--Source/cmLocale.h10
-rw-r--r--Source/cmMSVC60LinkLineComputer.cxx2
-rw-r--r--Source/cmMSVC60LinkLineComputer.h11
-rw-r--r--Source/cmMachO.cxx25
-rw-r--r--Source/cmMachO.h6
-rw-r--r--Source/cmMacroCommand.cxx47
-rw-r--r--Source/cmMacroCommand.h14
-rw-r--r--Source/cmMakeDirectoryCommand.cxx4
-rw-r--r--Source/cmMakeDirectoryCommand.h6
-rw-r--r--Source/cmMakefile.cxx1642
-rw-r--r--Source/cmMakefile.h381
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx175
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.h6
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx305
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.h9
-rw-r--r--Source/cmMakefileTargetGenerator.cxx660
-rw-r--r--Source/cmMakefileTargetGenerator.h34
-rw-r--r--Source/cmMakefileUtilityTargetGenerator.cxx22
-rw-r--r--Source/cmMakefileUtilityTargetGenerator.h6
-rw-r--r--Source/cmMarkAsAdvancedCommand.cxx2
-rw-r--r--Source/cmMarkAsAdvancedCommand.h6
-rw-r--r--Source/cmMathCommand.cxx75
-rw-r--r--Source/cmMathCommand.h6
-rw-r--r--Source/cmMessageCommand.cxx75
-rw-r--r--Source/cmMessageCommand.h6
-rw-r--r--Source/cmMessenger.cxx108
-rw-r--r--Source/cmMessenger.h50
-rw-r--r--Source/cmNewLineStyle.cxx5
-rw-r--r--Source/cmNewLineStyle.h2
-rw-r--r--Source/cmNinjaLinkLineComputer.h10
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx780
-rw-r--r--Source/cmNinjaNormalTargetGenerator.h15
-rw-r--r--Source/cmNinjaTargetGenerator.cxx1067
-rw-r--r--Source/cmNinjaTargetGenerator.h38
-rw-r--r--Source/cmNinjaTypes.h43
-rw-r--r--Source/cmNinjaUtilityTargetGenerator.cxx149
-rw-r--r--Source/cmNinjaUtilityTargetGenerator.h6
-rw-r--r--Source/cmOSXBundleGenerator.cxx38
-rw-r--r--Source/cmOSXBundleGenerator.h5
-rw-r--r--Source/cmOptionCommand.cxx78
-rw-r--r--Source/cmOptionCommand.h6
-rw-r--r--Source/cmOrderDirectories.cxx80
-rw-r--r--Source/cmOrderDirectories.h6
-rw-r--r--Source/cmOutputConverter.cxx193
-rw-r--r--Source/cmOutputConverter.h29
-rw-r--r--Source/cmOutputRequiredFilesCommand.cxx129
-rw-r--r--Source/cmOutputRequiredFilesCommand.h6
-rw-r--r--Source/cmParseArgumentsCommand.cxx237
-rw-r--r--Source/cmParseArgumentsCommand.h6
-rw-r--r--Source/cmPathLabel.cxx10
-rw-r--r--Source/cmPathLabel.h2
-rw-r--r--Source/cmPolicies.cxx175
-rw-r--r--Source/cmPolicies.h110
-rw-r--r--Source/cmProcessOutput.cxx8
-rw-r--r--Source/cmProcessOutput.h8
-rw-r--r--Source/cmProcessTools.cxx21
-rw-r--r--Source/cmProcessTools.h19
-rw-r--r--Source/cmProjectCommand.cxx235
-rw-r--r--Source/cmProjectCommand.h10
-rw-r--r--Source/cmProperty.cxx4
-rw-r--r--Source/cmPropertyMap.cxx8
-rw-r--r--Source/cmQTWrapCPPCommand.cxx25
-rw-r--r--Source/cmQTWrapCPPCommand.h6
-rw-r--r--Source/cmQTWrapUICommand.cxx33
-rw-r--r--Source/cmQTWrapUICommand.h6
-rw-r--r--Source/cmRST.cxx111
-rw-r--r--Source/cmRST.h4
-rw-r--r--Source/cmRemoveCommand.cxx18
-rw-r--r--Source/cmRemoveCommand.h6
-rw-r--r--Source/cmRemoveDefinitionsCommand.cxx5
-rw-r--r--Source/cmRemoveDefinitionsCommand.h6
-rw-r--r--Source/cmReturnCommand.h6
-rw-r--r--Source/cmRulePlaceholderExpander.cxx43
-rw-r--r--Source/cmRulePlaceholderExpander.h13
-rw-r--r--Source/cmScriptGenerator.cxx43
-rw-r--r--Source/cmScriptGenerator.h18
-rw-r--r--Source/cmSearchPath.cxx74
-rw-r--r--Source/cmSearchPath.h10
-rw-r--r--Source/cmSeparateArgumentsCommand.cxx24
-rw-r--r--Source/cmSeparateArgumentsCommand.h6
-rw-r--r--Source/cmServer.cxx312
-rw-r--r--Source/cmServer.h139
-rw-r--r--Source/cmServerConnection.cxx416
-rw-r--r--Source/cmServerConnection.h106
-rw-r--r--Source/cmServerDictionary.h31
-rw-r--r--Source/cmServerProtocol.cxx678
-rw-r--r--Source/cmServerProtocol.h26
-rw-r--r--Source/cmSetCommand.cxx48
-rw-r--r--Source/cmSetCommand.h6
-rw-r--r--Source/cmSetDirectoryPropertiesCommand.h9
-rw-r--r--Source/cmSetPropertyCommand.cxx90
-rw-r--r--Source/cmSetPropertyCommand.h6
-rw-r--r--Source/cmSetSourceFilesPropertiesCommand.cxx18
-rw-r--r--Source/cmSetSourceFilesPropertiesCommand.h9
-rw-r--r--Source/cmSetTargetPropertiesCommand.cxx3
-rw-r--r--Source/cmSetTargetPropertiesCommand.h6
-rw-r--r--Source/cmSetTestsPropertiesCommand.cxx3
-rw-r--r--Source/cmSetTestsPropertiesCommand.h6
-rw-r--r--Source/cmSiteNameCommand.cxx19
-rw-r--r--Source/cmSiteNameCommand.h6
-rw-r--r--Source/cmSourceFile.cxx178
-rw-r--r--Source/cmSourceFile.h37
-rw-r--r--Source/cmSourceFileLocation.cxx81
-rw-r--r--Source/cmSourceFileLocation.h25
-rw-r--r--Source/cmSourceGroup.cxx67
-rw-r--r--Source/cmSourceGroup.h20
-rw-r--r--Source/cmSourceGroupCommand.cxx308
-rw-r--r--Source/cmSourceGroupCommand.h29
-rw-r--r--Source/cmStandardLexer.h48
-rw-r--r--Source/cmState.cxx213
-rw-r--r--Source/cmState.h71
-rw-r--r--Source/cmStateDirectory.cxx209
-rw-r--r--Source/cmStateDirectory.h31
-rw-r--r--Source/cmStatePrivate.h11
-rw-r--r--Source/cmStateSnapshot.cxx71
-rw-r--r--Source/cmStateSnapshot.h8
-rw-r--r--Source/cmStringCommand.cxx233
-rw-r--r--Source/cmStringCommand.h34
-rw-r--r--Source/cmSubdirCommand.cxx22
-rw-r--r--Source/cmSubdirCommand.h6
-rw-r--r--Source/cmSubdirDependsCommand.h6
-rw-r--r--Source/cmSystemTools.cxx1260
-rw-r--r--Source/cmSystemTools.h264
-rw-r--r--Source/cmTarget.cxx1367
-rw-r--r--Source/cmTarget.h271
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.cxx24
-rw-r--r--Source/cmTargetCompileDefinitionsCommand.h16
-rw-r--r--Source/cmTargetCompileFeaturesCommand.cxx22
-rw-r--r--Source/cmTargetCompileFeaturesCommand.h13
-rw-r--r--Source/cmTargetCompileOptionsCommand.cxx17
-rw-r--r--Source/cmTargetCompileOptionsCommand.h13
-rw-r--r--Source/cmTargetDepend.h8
-rw-r--r--Source/cmTargetIncludeDirectoriesCommand.cxx46
-rw-r--r--Source/cmTargetIncludeDirectoriesCommand.h18
-rw-r--r--Source/cmTargetLinkLibrariesCommand.cxx322
-rw-r--r--Source/cmTargetLinkLibrariesCommand.h13
-rw-r--r--Source/cmTargetPropCommandBase.cxx30
-rw-r--r--Source/cmTargetPropCommandBase.h3
-rw-r--r--Source/cmTargetPropertyComputer.cxx37
-rw-r--r--Source/cmTargetPropertyComputer.h14
-rw-r--r--Source/cmTargetSourcesCommand.cxx93
-rw-r--r--Source/cmTargetSourcesCommand.h22
-rw-r--r--Source/cmTest.cxx4
-rw-r--r--Source/cmTest.h4
-rw-r--r--Source/cmTestGenerator.cxx102
-rw-r--r--Source/cmTestGenerator.h27
-rw-r--r--Source/cmTimestamp.cxx30
-rw-r--r--Source/cmTimestamp.h8
-rw-r--r--Source/cmTryCompileCommand.cxx5
-rw-r--r--Source/cmTryCompileCommand.h8
-rw-r--r--Source/cmTryRunCommand.cxx78
-rw-r--r--Source/cmTryRunCommand.h8
-rw-r--r--Source/cmUnexpectedCommand.h11
-rw-r--r--Source/cmUnsetCommand.cxx15
-rw-r--r--Source/cmUnsetCommand.h6
-rw-r--r--Source/cmUseMangledMesaCommand.cxx41
-rw-r--r--Source/cmUseMangledMesaCommand.h9
-rw-r--r--Source/cmUtilitySourceCommand.cxx22
-rw-r--r--Source/cmUtilitySourceCommand.h6
-rw-r--r--Source/cmUtils.hxx2
-rw-r--r--Source/cmUuid.cxx18
-rw-r--r--Source/cmUuid.h4
-rw-r--r--Source/cmVSSetupHelper.cxx169
-rw-r--r--Source/cmVSSetupHelper.h32
-rw-r--r--Source/cmVariableRequiresCommand.cxx2
-rw-r--r--Source/cmVariableRequiresCommand.h6
-rw-r--r--Source/cmVariableWatch.cxx48
-rw-r--r--Source/cmVariableWatch.h23
-rw-r--r--Source/cmVariableWatchCommand.cxx33
-rw-r--r--Source/cmVariableWatchCommand.h10
-rw-r--r--Source/cmVersionMacros.h2
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx4088
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h212
-rw-r--r--Source/cmVisualStudio10ToolsetOptions.cxx127
-rw-r--r--Source/cmVisualStudio10ToolsetOptions.h30
-rw-r--r--Source/cmVisualStudioGeneratorOptions.cxx318
-rw-r--r--Source/cmVisualStudioGeneratorOptions.h33
-rw-r--r--Source/cmVisualStudioSlnData.h2
-rw-r--r--Source/cmVisualStudioSlnParser.cxx8
-rw-r--r--Source/cmVisualStudioSlnParser.h2
-rw-r--r--Source/cmVisualStudioWCEPlatformParser.cxx8
-rw-r--r--Source/cmVisualStudioWCEPlatformParser.h2
-rw-r--r--Source/cmWhileCommand.cxx33
-rw-r--r--Source/cmWhileCommand.h14
-rw-r--r--Source/cmWorkingDirectory.cxx16
-rw-r--r--Source/cmWorkingDirectory.h20
-rw-r--r--Source/cmWriteFileCommand.cxx18
-rw-r--r--Source/cmWriteFileCommand.h6
-rw-r--r--Source/cmXCode21Object.cxx8
-rw-r--r--Source/cmXCode21Object.h2
-rw-r--r--Source/cmXCodeObject.cxx47
-rw-r--r--Source/cmXCodeObject.h14
-rw-r--r--Source/cmXCodeScheme.cxx246
-rw-r--r--Source/cmXCodeScheme.h35
-rw-r--r--Source/cmXMLParser.cxx18
-rw-r--r--Source/cmXMLWriter.cxx31
-rw-r--r--Source/cmXMLWriter.h94
-rw-r--r--Source/cm_codecvt.cxx22
-rw-r--r--Source/cm_codecvt.hxx18
-rw-r--r--Source/cm_sys_stat.h5
-rw-r--r--Source/cm_utf8.c29
-rw-r--r--Source/cm_utf8.h4
-rw-r--r--Source/cmake.cxx1245
-rw-r--r--Source/cmake.h308
-rw-r--r--Source/cmakemain.cxx504
-rw-r--r--Source/cmcldeps.cxx4
-rw-r--r--Source/cmcmd.cxx1154
-rw-r--r--Source/cmcmd.h16
-rw-r--r--Source/ctest.cxx124
-rw-r--r--Source/kwsys/Base64.c2
-rw-r--r--Source/kwsys/Base64.h.in40
-rw-r--r--Source/kwsys/CMakeLists.txt378
-rw-r--r--Source/kwsys/CONTRIBUTING.rst2
-rw-r--r--Source/kwsys/CommandLineArguments.cxx63
-rw-r--r--Source/kwsys/CommandLineArguments.hxx.in3
-rw-r--r--Source/kwsys/Configure.h.in134
-rw-r--r--Source/kwsys/Configure.hxx.in53
-rw-r--r--Source/kwsys/ConsoleBuf.hxx.in16
-rw-r--r--Source/kwsys/Directory.cxx82
-rw-r--r--Source/kwsys/DynamicLoader.cxx181
-rw-r--r--Source/kwsys/DynamicLoader.hxx.in39
-rw-r--r--Source/kwsys/Encoding.h.in32
-rw-r--r--Source/kwsys/Encoding.hxx.in10
-rw-r--r--Source/kwsys/EncodingC.c4
-rw-r--r--Source/kwsys/EncodingCXX.cxx46
-rw-r--r--Source/kwsys/FStream.cxx2
-rw-r--r--Source/kwsys/FStream.hxx.in60
-rw-r--r--Source/kwsys/Glob.cxx33
-rw-r--r--Source/kwsys/Glob.hxx.in14
-rw-r--r--Source/kwsys/IOStream.cxx38
-rw-r--r--Source/kwsys/IOStream.hxx.in76
-rw-r--r--Source/kwsys/MD5.c20
-rw-r--r--Source/kwsys/MD5.h.in48
-rw-r--r--Source/kwsys/Process.h.in338
-rw-r--r--Source/kwsys/ProcessUNIX.c122
-rw-r--r--Source/kwsys/ProcessWin32.c109
-rw-r--r--Source/kwsys/RegularExpression.cxx353
-rw-r--r--Source/kwsys/RegularExpression.hxx.in246
-rw-r--r--Source/kwsys/SharedForward.h.in453
-rw-r--r--Source/kwsys/String.c42
-rw-r--r--Source/kwsys/String.h.in20
-rw-r--r--Source/kwsys/System.c2
-rw-r--r--Source/kwsys/System.h.in17
-rw-r--r--Source/kwsys/SystemInformation.cxx781
-rw-r--r--Source/kwsys/SystemInformation.hxx.in11
-rw-r--r--Source/kwsys/SystemTools.cxx1592
-rw-r--r--Source/kwsys/SystemTools.hxx.in124
-rw-r--r--Source/kwsys/Terminal.c80
-rw-r--r--Source/kwsys/Terminal.h.in158
-rw-r--r--Source/kwsys/hash_map.hxx.in18
-rw-r--r--Source/kwsys/hash_set.hxx.in18
-rw-r--r--Source/kwsys/hashtable.hxx.in93
-rw-r--r--Source/kwsys/kwsysPlatformTests.cmake5
-rw-r--r--Source/kwsys/kwsysPlatformTestsC.c65
-rw-r--r--Source/kwsys/kwsysPlatformTestsCXX.cxx142
-rw-r--r--Source/kwsys/kwsysPrivate.h16
-rw-r--r--Source/kwsys/testCommandLineArguments.cxx45
-rw-r--r--Source/kwsys/testCommandLineArguments1.cxx8
-rw-r--r--Source/kwsys/testConsoleBuf.cxx73
-rw-r--r--Source/kwsys/testConsoleBufChild.cxx4
-rw-r--r--Source/kwsys/testDynamicLoader.cxx32
-rw-r--r--Source/kwsys/testDynload.c4
-rw-r--r--Source/kwsys/testEncode.c2
-rw-r--r--Source/kwsys/testEncoding.cxx15
-rw-r--r--Source/kwsys/testFStream.cxx6
-rw-r--r--Source/kwsys/testHashSTL.cxx9
-rw-r--r--Source/kwsys/testProcess.c63
-rw-r--r--Source/kwsys/testSharedForward.c.in10
-rw-r--r--Source/kwsys/testSystemInformation.cxx26
-rw-r--r--Source/kwsys/testSystemTools.cxx296
-rw-r--r--Source/kwsys/testTerminal.c2
-rw-r--r--Templates/MSBuild/nasm.xml6
-rw-r--r--Templates/TestDriver.cxx.in10
-rw-r--r--Templates/Windows/ApplicationIcon.pngbin3392 -> 2335 bytes
-rw-r--r--Templates/Windows/Logo.pngbin801 -> 488 bytes
-rw-r--r--Templates/Windows/SmallLogo.pngbin329 -> 167 bytes
-rw-r--r--Templates/Windows/SmallLogo44x44.pngbin554 -> 265 bytes
-rw-r--r--Templates/Windows/SplashScreen.pngbin2146 -> 909 bytes
-rw-r--r--Templates/Windows/StoreLogo.pngbin429 -> 227 bytes
-rw-r--r--Tests/AliasTarget/CMakeLists.txt7
-rw-r--r--Tests/AliasTarget/bat.cpp8
-rw-r--r--Tests/BuildDepends/CMakeLists.txt13
-rw-r--r--Tests/BuildDepends/Project/CMakeLists.txt41
-rw-r--r--Tests/BundleTest/BundleLib.cxx2
-rw-r--r--Tests/BundleTest/BundleSubDir/CMakeLists.txt7
-rw-r--r--Tests/BundleUtilities/framework.h12
-rw-r--r--Tests/BundleUtilities/shared.h12
-rw-r--r--Tests/BundleUtilities/shared2.h12
-rw-r--r--Tests/BundleUtilities/testbundleutils1.cpp4
-rw-r--r--Tests/BundleUtilities/testbundleutils2.cpp4
-rw-r--r--Tests/BundleUtilities/testbundleutils3.cpp4
-rw-r--r--Tests/CFBundleTest/np_macmain.cpp2
-rw-r--r--Tests/CMakeBuildTest.cmake.in9
-rw-r--r--Tests/CMakeCommands/add_compile_options/main.cpp6
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt23
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/consumer.c46
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/consumer.cpp18
-rw-r--r--Tests/CMakeCommands/target_compile_definitions/main.cpp6
-rw-r--r--Tests/CMakeCommands/target_compile_features/CMakeLists.txt6
-rw-r--r--Tests/CMakeCommands/target_compile_options/CMakeLists.txt41
-rw-r--r--Tests/CMakeCommands/target_compile_options/consumer.c44
-rw-r--r--Tests/CMakeCommands/target_compile_options/consumer.cpp50
-rw-r--r--Tests/CMakeCommands/target_compile_options/main.cpp36
-rw-r--r--Tests/CMakeCommands/target_include_directories/CMakeLists.txt20
-rw-r--r--Tests/CMakeCommands/target_include_directories/consumer.c18
-rw-r--r--Tests/CMakeCommands/target_include_directories/consumer.cpp20
-rw-r--r--Tests/CMakeCommands/target_include_directories/main.cpp8
-rw-r--r--Tests/CMakeCommands/target_link_libraries/CMakeLists.txt16
-rw-r--r--Tests/CMakeCommands/target_link_libraries/libgenex.h2
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetC.cpp2
-rw-r--r--Tests/CMakeInstall.cmake13
-rw-r--r--Tests/CMakeLib/CMakeLists.txt37
-rw-r--r--Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in6
-rw-r--r--Tests/CMakeLib/run_compile_commands.cxx14
-rw-r--r--Tests/CMakeLib/testEncoding.cxx4
-rw-r--r--Tests/CMakeLib/testRST.expect11
-rw-r--r--Tests/CMakeLib/testRST.rst11
-rw-r--r--Tests/CMakeLib/testSystemTools.cxx31
-rw-r--r--Tests/CMakeLib/testUTF8.cxx109
-rw-r--r--Tests/CMakeLib/testVisualStudioSlnParser.cxx60
-rw-r--r--Tests/CMakeLib/testXMLSafe.cxx4
-rw-r--r--Tests/CMakeLists.txt938
-rw-r--r--Tests/CMakeOnly/AllFindModules/CMakeLists.txt2
-rw-r--r--Tests/CMakeOnly/CMakeLists.txt16
-rw-r--r--Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt2
-rw-r--r--Tests/CMakeOnly/CheckLanguage/CMakeLists.txt3
-rw-r--r--Tests/CMakeOnly/ProjectInclude/CMakeLists.txt2
-rw-r--r--Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt5
-rw-r--r--Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in19
-rw-r--r--Tests/CMakeTests/CheckSourceTreeTest.cmake.in4
-rw-r--r--Tests/CMakeTests/FileDownloadInput.pngbin358 -> 194 bytes
-rw-r--r--Tests/CMakeTests/FileDownloadTest.cmake.in16
-rw-r--r--Tests/CMakeTests/FileUploadTest.cmake.in4
-rw-r--r--Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in100
-rw-r--r--Tests/CMakeTests/ListTest.cmake.in4
-rw-r--r--Tests/CMakeTests/PushCheckStateTest.cmake.in22
-rw-r--r--Tests/CMakeTests/String-TIMESTAMP-UnixTime.cmake6
-rw-r--r--Tests/CMakeTests/StringTest.cmake.in4
-rw-r--r--Tests/CMakeTests/StringTestScript.cmake25
-rw-r--r--Tests/COnly/CMakeLists.txt2
-rw-r--r--Tests/COnly/libc2.h12
-rw-r--r--Tests/COnly/testCModule.c4
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend1.cmake2
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend2.cmake2
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake2
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake2
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake4
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-components-shlibdeps1.cmake2
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake2
-rw-r--r--Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake4
-rw-r--r--Tests/CPackComponentsForAll/CMakeLists.txt12
-rw-r--r--Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in4
-rw-r--r--Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in4
-rw-r--r--Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in4
-rw-r--r--Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake62
-rw-r--r--Tests/CSharpLinkToCxx/CMakeLists.txt6
-rw-r--r--Tests/CSharpOnly/CMakeLists.txt3
-rw-r--r--Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in1
-rw-r--r--Tests/CTestConfig/CMakeLists.txt35
-rw-r--r--Tests/CTestConfig/dashboard.cmake.in4
-rw-r--r--Tests/CTestConfig/script.cmake.in1
-rw-r--r--Tests/CTestCoverageCollectGCOV/fakegcov.cmake21
-rw-r--r--Tests/CTestCoverageCollectGCOV/test.cmake.in1
-rw-r--r--Tests/CTestTest/test.cmake.in2
-rw-r--r--Tests/CTestTest2/test.cmake.in1
-rw-r--r--Tests/CTestTestBadExe/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestBadGenerator/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestCostSerial/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestCostSerial/sleep.c4
-rw-r--r--Tests/CTestTestCrash/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestCycle/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestDepends/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestFailure/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestFdSetSize/sleep.c4
-rw-r--r--Tests/CTestTestLaunchers/launcher_compiler_test_project/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestLaunchers/launcher_custom_command_test_project/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestLaunchers/launcher_linker_test_project/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestParallel/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestResourceLock/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestScheduler/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestScheduler/sleep.c4
-rw-r--r--Tests/CTestTestSkipReturnCode/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestStopTime/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestStopTime/GetDate.cmake2
-rw-r--r--Tests/CTestTestStopTime/sleep.c4
-rw-r--r--Tests/CTestTestSubdir/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestTimeout/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestTimeout/sleep.c4
-rw-r--r--Tests/CTestTestTimeout/timeout.cmake2
-rw-r--r--Tests/CTestTestUpload/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestUpload/sleep.c4
-rw-r--r--Tests/CTestTestVerboseOutput/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestZeroTimeout/CTestConfig.cmake3
-rw-r--r--Tests/CTestTestZeroTimeout/sleep.c4
-rw-r--r--Tests/CTestUpdateCommon.cmake1
-rw-r--r--Tests/CheckFortran.cmake7
-rw-r--r--Tests/CompatibleInterface/main.cpp12
-rw-r--r--Tests/CompileCommandOutput/relative.h12
-rw-r--r--Tests/CompileDefinitions/compiletest.c10
-rw-r--r--Tests/CompileDefinitions/compiletest.cpp102
-rw-r--r--Tests/CompileDefinitions/compiletest_mixed_c.c10
-rw-r--r--Tests/CompileDefinitions/compiletest_mixed_cxx.cpp10
-rw-r--r--Tests/CompileDefinitions/runtest.c2
-rw-r--r--Tests/CompileDefinitions/target_prop/usetgt.c6
-rw-r--r--Tests/CompileFeatures/CMakeLists.txt247
-rw-r--r--Tests/CompileFeatures/cxx_attribute_deprecated.cpp5
-rw-r--r--Tests/CompileFeatures/cxx_contextual_conversions.cpp1
-rw-r--r--Tests/CompileFeatures/cxx_digit_separators.cpp3
-rw-r--r--Tests/CompileFeatures/cxx_generalized_initializers.cpp8
-rw-r--r--Tests/CompileFeatures/cxx_lambda_init_captures.cpp3
-rw-r--r--Tests/CompileFeatures/cxx_raw_string_literals.cpp2
-rw-r--r--Tests/CompileFeatures/cxx_relaxed_constexpr.cpp3
-rw-r--r--Tests/CompileFeatures/cxx_variadic_templates.cpp20
-rw-r--r--Tests/CompileFeatures/default_dialect.c26
-rw-r--r--Tests/CompileFeatures/default_dialect.cpp42
-rw-r--r--Tests/CompileFeatures/genex_test.c44
-rw-r--r--Tests/CompileFeatures/genex_test.cpp81
-rw-r--r--Tests/CompileOptions/CMakeLists.txt32
-rw-r--r--Tests/CompileOptions/main.cpp51
-rw-r--r--Tests/Complex/CMakeLists.txt9
-rw-r--r--Tests/Complex/Cache/CMakeCache.txt2
-rw-r--r--Tests/Complex/Executable/complex.cxx74
-rw-r--r--Tests/Complex/Executable/complex.file.cxx2
-rw-r--r--Tests/Complex/Executable/notInAllExe.cxx2
-rw-r--r--Tests/Complex/Library/CMakeLists.txt2
-rw-r--r--Tests/Complex/Library/notInAllLib.cxx2
-rw-r--r--Tests/Complex/Library/sharedFile.h12
-rw-r--r--Tests/Complex/Library/testConly.h12
-rw-r--r--Tests/Complex/VarTests.cmake2
-rw-r--r--Tests/Complex/cmTestConfigure.h.in4
-rw-r--r--Tests/ComplexOneConfig/CMakeLists.txt9
-rw-r--r--Tests/ComplexOneConfig/Cache/CMakeCache.txt2
-rw-r--r--Tests/ComplexOneConfig/Executable/complex.cxx74
-rw-r--r--Tests/ComplexOneConfig/Executable/complex.file.cxx2
-rw-r--r--Tests/ComplexOneConfig/Executable/notInAllExe.cxx2
-rw-r--r--Tests/ComplexOneConfig/Library/CMakeLists.txt2
-rw-r--r--Tests/ComplexOneConfig/Library/notInAllLib.cxx2
-rw-r--r--Tests/ComplexOneConfig/Library/sharedFile.h12
-rw-r--r--Tests/ComplexOneConfig/Library/testConly.h12
-rw-r--r--Tests/ComplexOneConfig/VarTests.cmake2
-rw-r--r--Tests/ComplexOneConfig/cmTestConfigure.h.in4
-rw-r--r--Tests/Contracts/Trilinos/CMakeLists.txt19
-rw-r--r--Tests/Contracts/VTK/CMakeLists.txt19
-rw-r--r--Tests/Cuda/CMakeLists.txt3
-rw-r--r--Tests/Cuda/Complex/CMakeLists.txt9
-rw-r--r--Tests/Cuda/Complex/dynamic.cpp4
-rw-r--r--Tests/Cuda/Complex/dynamic.cu4
-rw-r--r--Tests/Cuda/Complex/main.cpp4
-rw-r--r--Tests/Cuda/Complex/mixed.cpp8
-rw-r--r--Tests/Cuda/Complex/mixed.cu8
-rw-r--r--Tests/Cuda/ConsumeCompileFeatures/CMakeLists.txt2
-rw-r--r--Tests/Cuda/ObjectLibrary/CMakeLists.txt19
-rw-r--r--Tests/Cuda/ObjectLibrary/main.cpp20
-rw-r--r--Tests/Cuda/ObjectLibrary/static.cpp4
-rw-r--r--Tests/Cuda/ObjectLibrary/static.cu6
-rw-r--r--Tests/Cuda/WithC/CMakeLists.txt7
-rw-r--r--Tests/Cuda/WithC/main.c2
-rw-r--r--Tests/CudaOnly/CMakeLists.txt19
-rw-r--r--Tests/CudaOnly/EnableStandard/CMakeLists.txt2
-rw-r--r--Tests/CudaOnly/EnableStandard/main.cu4
-rw-r--r--Tests/CudaOnly/EnableStandard/shared.cu4
-rw-r--r--Tests/CudaOnly/ExportPTX/CMakeLists.txt7
-rw-r--r--Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt23
-rw-r--r--Tests/CudaOnly/ResolveDeviceSymbols/main.cu11
-rw-r--r--Tests/CudaOnly/SeparateCompilation/CMakeLists.txt18
-rw-r--r--Tests/CudaOnly/WithDefs/CMakeLists.txt36
-rw-r--r--Tests/CudaOnly/WithDefs/main.notcu51
-rw-r--r--Tests/CustComDepend/bar.h12
-rw-r--r--Tests/CustomCommand/wrapper.cxx7
-rw-r--r--Tests/CustomCommandByproducts/CMakeLists.txt8
-rw-r--r--Tests/CustomCommandWorkingDirectory/CMakeLists.txt28
-rw-r--r--Tests/CxxOnly/libcxx2.h12
-rw-r--r--Tests/CxxOnly/testCxxModule.cxx4
-rw-r--r--Tests/EnforceConfig.cmake.in13
-rw-r--r--Tests/ExportImport/CMakeLists.txt5
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt88
-rw-r--r--Tests/ExportImport/Export/Interface/CMakeLists.txt2
-rw-r--r--Tests/ExportImport/Export/Interface/source_target.cpp4
-rw-r--r--Tests/ExportImport/Export/Interface/source_target_for_install.cpp4
-rw-r--r--Tests/ExportImport/Export/systemlib.h4
-rw-r--r--Tests/ExportImport/Export/testExe2.c4
-rw-r--r--Tests/ExportImport/Export/testExe2lib.c8
-rw-r--r--Tests/ExportImport/Export/testExe2libImp.c4
-rw-r--r--Tests/ExportImport/Export/testLib3.c8
-rw-r--r--Tests/ExportImport/Export/testLib3Imp.c8
-rw-r--r--Tests/ExportImport/Export/testLib3ImpDep.c4
-rw-r--r--Tests/ExportImport/Export/testLib4.c4
-rw-r--r--Tests/ExportImport/Export/testLib5.c4
-rw-r--r--Tests/ExportImport/Export/testLibDepends.c6
-rw-r--r--Tests/ExportImport/Export/testLibNoSONAME.c4
-rw-r--r--Tests/ExportImport/Import/A/CMakeLists.txt82
-rw-r--r--Tests/ExportImport/Import/A/cmp0022NEW_test.cpp4
-rw-r--r--Tests/ExportImport/Import/A/cmp0022OLD_test.cpp4
-rw-r--r--Tests/ExportImport/Import/A/deps_iface.c6
-rw-r--r--Tests/ExportImport/Import/A/deps_shared_iface.cpp22
-rw-r--r--Tests/ExportImport/Import/A/framework_interface/framework_test.cpp2
-rw-r--r--Tests/ExportImport/Import/A/iface_test.cpp2
-rw-r--r--Tests/ExportImport/Import/A/imp_mod1.c4
-rw-r--r--Tests/ExportImport/Import/A/imp_testExe1.c4
-rw-r--r--Tests/ExportImport/Import/A/imp_testExeAbs1.c4
-rw-r--r--Tests/ExportImport/Import/Interface/CMakeLists.txt8
-rw-r--r--Tests/ExportImport/Import/Interface/headeronlytest.cpp4
-rw-r--r--Tests/ExportImport/Import/Interface/interfacetest.cpp6
-rw-r--r--Tests/ExternalOBJ/CMakeLists.txt2
-rw-r--r--Tests/ExternalProject/CMakeLists.txt18
-rw-r--r--Tests/ExternalProjectLocal/CMakeLists.txt130
-rw-r--r--Tests/FindBoost/CMakeLists.txt28
-rw-r--r--Tests/FindBoost/Test/CMakeLists.txt15
-rw-r--r--Tests/FindBoost/Test/main.cxx17
-rw-r--r--Tests/FindDoxygen/CMakeLists.txt20
-rw-r--r--Tests/FindGTK2/cairomm/main.cpp2
-rw-r--r--Tests/FindGTest/Test/main.cxx2
-rw-r--r--Tests/FindLTTngUST/Test/main.c4
-rw-r--r--Tests/FindMPI/Test/CMakeLists.txt5
-rw-r--r--Tests/FindMatlab/basic_checks/CMakeLists.txt80
-rw-r--r--Tests/FindMatlab/components_checks/CMakeLists.txt12
-rw-r--r--Tests/FindMatlab/versions_checks/CMakeLists.txt7
-rw-r--r--Tests/FindOpenCL/Test/main.c4
-rw-r--r--Tests/FindOpenGL/CMakeLists.txt7
-rw-r--r--Tests/FindOpenGL/Test/CMakeLists.txt59
-rw-r--r--Tests/FindOpenGL/Test/main.c6
-rw-r--r--Tests/FindOpenMP/Test/scaltest.c4
-rw-r--r--Tests/FindOpenSSL/rand/main.cc2
-rw-r--r--Tests/FindPackageModeMakefileTest/foo.cpp2
-rw-r--r--Tests/FindPackageModeMakefileTest/foo.h8
-rw-r--r--Tests/FindPackageTest/CMakeLists.txt300
-rw-r--r--Tests/FindProtobuf/Test/CMakeLists.txt20
-rw-r--r--Tests/FindThreads/C-only/CMakeLists.txt1
-rw-r--r--Tests/FindThreads/CXX-only/CMakeLists.txt1
-rw-r--r--Tests/ForceInclude/foo.c4
-rw-r--r--Tests/Fortran/CMakeLists.txt9
-rw-r--r--Tests/FortranModules/CMakeLists.txt5
-rw-r--r--Tests/FortranModules/Submodules/CMakeLists.txt24
-rw-r--r--Tests/FortranModules/Submodules/main.f902
-rw-r--r--Tests/FortranModules/test_preprocess.F902
-rw-r--r--Tests/FortranModules/test_preprocess_module.F902
-rw-r--r--Tests/FortranOnly/CMakeLists.txt23
-rw-r--r--Tests/Framework/foo.cxx4
-rw-r--r--Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp20
-rw-r--r--Tests/GeneratorExpression/CMakeLists.txt129
-rw-r--r--Tests/GeneratorExpression/check-part1.cmake5
-rw-r--r--Tests/GeneratorExpression/check-part3.cmake5
-rw-r--r--Tests/GeneratorExpression/check-part4.cmake15
-rw-r--r--Tests/GeneratorExpression/echo.c3
-rw-r--r--Tests/GeneratorExpression/pwd.c8
-rw-r--r--Tests/GoogleTest/Test/CMakeLists.txt7
-rw-r--r--Tests/IncludeDirectories/CMP0021/main.cpp2
-rw-r--r--Tests/IncludeDirectories/CMakeLists.txt6
-rw-r--r--Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt4
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt16
-rw-r--r--Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp3
-rw-r--r--Tests/InterfaceLibrary/CMakeLists.txt3
-rw-r--r--Tests/InterfaceLibrary/definetestexe.cpp6
-rw-r--r--Tests/InterfaceLibrary/map_config.cpp12
-rw-r--r--Tests/InterfaceLibrary/sharedlibtestexe.cpp6
-rw-r--r--Tests/InterfaceLinkLibraries/bang.cpp4
-rw-r--r--Tests/InterfaceLinkLibraries/bar.cpp16
-rw-r--r--Tests/InterfaceLinkLibraries/foo.cpp4
-rw-r--r--Tests/InterfaceLinkLibraries/main.cpp8
-rw-r--r--Tests/Java/CMakeLists.txt3
-rw-r--r--Tests/JavaExportImport/CMakeLists.txt5
-rw-r--r--Tests/Jump/Executable/jumpExecutable.cxx4
-rw-r--r--Tests/Jump/Library/Shared/jumpShared.cxx4
-rw-r--r--Tests/LinkDirectory/External/CMakeLists.txt14
-rw-r--r--Tests/LinkFlags/LinkFlagsExe.c2
-rw-r--r--Tests/LinkFlags/LinkFlagsLib.c2
-rw-r--r--Tests/LoadCommand/CMakeLists.txt7
-rw-r--r--Tests/LoadCommandOneConfig/CMakeLists.txt7
-rw-r--r--Tests/MFC/CMakeLists.txt.in5
-rw-r--r--Tests/MFC/mfc1/ChildFrm.cpp2
-rw-r--r--Tests/MFC/mfc1/MainFrm.cpp13
-rw-r--r--Tests/MFC/mfc1/Resource.h12
-rw-r--r--Tests/MFC/mfc1/mfc1.cpp2
-rw-r--r--Tests/MFC/mfc1/mfc1.h2
-rw-r--r--Tests/MFC/mfc1/mfc1Doc.cpp2
-rw-r--r--Tests/MFC/mfc1/mfc1View.cpp2
-rw-r--r--Tests/MFC/mfc1/stdafx.h52
-rw-r--r--Tests/MacRuntimePath/A/framework.h12
-rw-r--r--Tests/MacRuntimePath/A/framework2.h12
-rw-r--r--Tests/MacRuntimePath/A/shared.h12
-rw-r--r--Tests/MacRuntimePath/CMakeLists.txt5
-rw-r--r--Tests/MakeClean/ToClean/CMakeLists.txt140
-rw-r--r--Tests/MakeClean/check_clean.c.in2
-rw-r--r--Tests/MathTest/CMakeLists.txt33
-rw-r--r--Tests/MathTest/MathTestExec.cxx40
-rw-r--r--Tests/MissingInstall/CMakeLists.txt8
-rw-r--r--Tests/Module/CheckIPOSupported-C/CMakeLists.txt5
-rw-r--r--Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt5
-rw-r--r--Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt5
-rw-r--r--Tests/Module/CheckTypeSize/CheckTypeSize.c30
-rw-r--r--Tests/Module/CheckTypeSize/CheckTypeSize.cxx34
-rw-r--r--Tests/Module/ExternalData/Data5/CMakeLists.txt6
-rw-r--r--Tests/Module/FindDependency/CMakeLists.txt4
-rw-r--r--Tests/Module/FindDependency/main.cpp24
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt34
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/compile_tests.h10
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/main.c18
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/main.cpp2
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/main_multi.c18
-rw-r--r--Tests/Module/WriteCompilerDetectionHeader/multi_files.cpp2
-rw-r--r--Tests/ModuleDefinition/example_mod_1.c4
-rw-r--r--Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m3
-rw-r--r--Tests/MumpsCoverage/ZZCOVTST.cmcov63
-rw-r--r--Tests/MumpsCoverage/ZZCOVTST.mcov3
-rw-r--r--Tests/NewlineArgs/libcxx1.cxx4
-rw-r--r--Tests/NewlineArgs/libcxx1.h4
-rw-r--r--Tests/ObjectLibrary/A/a.h4
-rw-r--r--Tests/ObjectLibrary/B/b.h12
-rw-r--r--Tests/ObjectLibrary/CMakeLists.txt10
-rw-r--r--Tests/ObjectLibrary/c.c4
-rw-r--r--Tests/ObjectLibrary/main.c4
-rw-r--r--Tests/OutDir/CMakeLists.txt5
-rw-r--r--Tests/OutOfSource/CMakeLists.txt2
-rw-r--r--Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt4
-rw-r--r--Tests/OutOfSource/OutOfSourceSubdir/testlib.h12
-rw-r--r--Tests/PDBDirectoryAndName/CMakeLists.txt10
-rw-r--r--Tests/PerConfig/pcShared.h12
-rw-r--r--Tests/Plugin/CMakeLists.txt8
-rw-r--r--Tests/Plugin/include/example.h12
-rw-r--r--Tests/Plugin/src/example_exe.cxx4
-rw-r--r--Tests/Plugin/src/example_mod_1.c8
-rw-r--r--Tests/PolicyScope/CMakeLists.txt8
-rw-r--r--Tests/PrecompiledHeader/CMakeLists.txt5
-rw-r--r--Tests/PrecompiledHeader/foo1.c2
-rw-r--r--Tests/PrecompiledHeader/foo2.c4
-rw-r--r--Tests/Preprocess/CMakeLists.txt14
-rw-r--r--Tests/Preprocess/preprocess.c83
-rw-r--r--Tests/Preprocess/preprocess.cxx80
-rw-r--r--Tests/Properties/CMakeLists.txt2
-rw-r--r--Tests/Properties/subdirtest.cxx2
-rw-r--r--Tests/Qt4Deploy/CMakeLists.txt7
-rw-r--r--Tests/Qt4Targets/CMakeLists.txt10
-rw-r--r--Tests/Qt4Targets/activeqtexe.cpp2
-rw-r--r--Tests/Qt4Targets/main.cpp4
-rw-r--r--Tests/Qt4Targets/main_gen_test.cpp4
-rw-r--r--Tests/Qt4Targets/mywrapobject.h4
-rw-r--r--Tests/RunCMake/Android/RunCMakeTest.cmake25
-rw-r--r--Tests/RunCMake/Android/android.cxx38
-rw-r--r--Tests/RunCMake/Android/android.h120
-rw-r--r--Tests/RunCMake/Android/android_sysinc.c2
-rw-r--r--Tests/RunCMake/Android/android_sysinc.cxx2
-rw-r--r--Tests/RunCMake/Android/common.cmake24
-rw-r--r--Tests/RunCMake/Android/ndk-badvernum-stderr.txt2
-rw-r--r--Tests/RunCMake/AndroidMK/AndroidMK.cmake8
-rw-r--r--Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt8
-rw-r--r--Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt8
-rw-r--r--Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/AutoExportDll/foo.c4
-rw-r--r--Tests/RunCMake/AutoExportDll/hello.h12
-rw-r--r--Tests/RunCMake/AutoExportDll/say.cxx4
-rw-r--r--Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/C-Exe.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/Custom-Always.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake2
-rw-r--r--Tests/RunCMake/BuildDepends/RunCMakeTest.cmake21
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-OLD-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0026/LOCATION-and-TARGET_OBJECTS-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0026/clear-cached-information-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake2
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake2
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake2
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake2
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake2
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake2
-rw-r--r--Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake2
-rw-r--r--Tests/RunCMake/CMP0037/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/CMP0037/RunCMakeTest.cmake17
-rw-r--r--Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt6
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt13
-rw-r--r--Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt13
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt55
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt11
-rw-r--r--Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt55
-rw-r--r--Tests/RunCMake/CMP0060/CMP0060-Common.cmake3
-rw-r--r--Tests/RunCMake/CMP0060/CMP0060-WARN-ON-stderr.txt2
-rw-r--r--Tests/RunCMake/CMP0060/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/CMP0069/CMP0069-NEW-cmake-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0069/CMP0069-NEW-compiler-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0069/CMP0069-NEW-generator-stderr.txt4
-rw-r--r--Tests/RunCMake/CMP0069/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/CMakeLists.txt260
-rw-r--r--Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake17
-rw-r--r--Tests/RunCMake/CPack/CMakeLists.txt4
-rw-r--r--Tests/RunCMake/CPack/CPackTestHelpers.cmake90
-rw-r--r--Tests/RunCMake/CPack/DEB/Helpers.cmake21
-rw-r--r--Tests/RunCMake/CPack/README.txt28
-rw-r--r--Tests/RunCMake/CPack/RPM/Helpers.cmake26
-rw-r--r--Tests/RunCMake/CPack/RPM/default_expected_stderr.txt2
-rw-r--r--Tests/RunCMake/CPack/RunCMakeTest.cmake53
-rw-r--r--Tests/RunCMake/CPack/STGZ/Helpers.cmake29
-rw-r--r--Tests/RunCMake/CPack/VerifyResult.cmake14
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake4
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt2
-rw-r--r--Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake45
-rw-r--r--Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake8
-rw-r--r--Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake10
-rw-r--r--Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake5
-rw-r--r--Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake5
-rw-r--r--Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake4
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake4
-rw-r--r--Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake5
-rw-r--r--Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake6
-rw-r--r--Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake14
-rw-r--r--Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake7
-rw-r--r--Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake16
-rw-r--r--Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake1
-rw-r--r--Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt2
-rw-r--r--Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake2
-rw-r--r--Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake11
-rw-r--r--Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake2
-rw-r--r--Tests/RunCMake/CPackConfig/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake2
-rw-r--r--Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake2
-rw-r--r--Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake2
-rw-r--r--Tests/RunCMake/CTest/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/CTestCommandLine/LabelCount-stdout.txt4
-rw-r--r--Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake77
-rw-r--r--Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/CheckModules/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/CommandLine/C-no-file-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/E_capabilities-stdout.txt2
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake14
-rw-r--r--Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake8
-rw-r--r--Tests/RunCMake/CommandLine/NoArgs-stdout.txt1
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake310
-rw-r--r--Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/Wdev-stderr.txt4
-rw-r--r--Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/Werror_dev-stderr.txt4
-rw-r--r--Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt4
-rw-r--r--Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake34
-rw-r--r--Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt2
-rw-r--r--Tests/RunCMake/CommandLineTar/gnutar-gz.cmake4
-rw-r--r--Tests/RunCMake/CommandLineTar/pax.cmake4
-rw-r--r--Tests/RunCMake/CommandLineTar/roundtrip.cmake14
-rw-r--r--Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake18
-rw-r--r--Tests/RunCMake/Cpplint/C-error-Build-result.txt2
-rw-r--r--Tests/RunCMake/Cpplint/C-error-launch-Build-result.txt2
-rw-r--r--Tests/RunCMake/Cpplint/CXX-error-Build-result.txt2
-rw-r--r--Tests/RunCMake/Cpplint/CXX-error-launch-Build-result.txt2
-rw-r--r--Tests/RunCMake/CrosscompilingEmulator/AddCustomCommand.cmake3
-rw-r--r--Tests/RunCMake/CrosscompilingEmulator/CrosscompilingEmulatorProperty.cmake6
-rw-r--r--Tests/RunCMake/CrosscompilingEmulator/RunCMakeTest.cmake9
-rw-r--r--Tests/RunCMake/ExternalData/BadAlgoMap1-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadAlgoMap2-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadOption1-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadOption2-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadRecurse1-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadRecurse2-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadRecurse3-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries1-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries2-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/BadSeries3-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/Directory1-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/Directory2-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/Directory3-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/Directory4-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/Directory5-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/MissingData-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake18
-rw-r--r--Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake7
-rw-r--r--Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake18
-rw-r--r--Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake7
-rw-r--r--Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake3
-rw-r--r--Tests/RunCMake/ExternalProject/NoOptions-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalProject/RunCMakeTest.cmake40
-rw-r--r--Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt4
-rw-r--r--Tests/RunCMake/ExternalProject/UsesTerminal.cmake3
-rw-r--r--Tests/RunCMake/FPHSA/RunCMakeTest.cmake13
-rw-r--r--Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake10
-rw-r--r--Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt3
-rw-r--r--Tests/RunCMake/File_Generate/OutputNameMatchesObjects.cmake7
-rw-r--r--Tests/RunCMake/File_Generate/ReRunCMake.cmake2
-rw-r--r--Tests/RunCMake/File_Generate/RunCMakeTest.cmake22
-rw-r--r--Tests/RunCMake/File_Generate/WriteIfDifferent.cmake2
-rw-r--r--Tests/RunCMake/FindMatlab/MatlabTest1.cmake3
-rw-r--r--Tests/RunCMake/FindMatlab/MatlabTest2.cmake4
-rw-r--r--Tests/RunCMake/FindMatlab/RunCMakeTest.cmake11
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake108
-rw-r--r--Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake2
-rw-r--r--Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake3
-rwxr-xr-xTests/RunCMake/FindPkgConfig/dummy-pkg-config.bat54
-rw-r--r--Tests/RunCMake/Framework/FrameworkLayout.cmake7
-rw-r--r--Tests/RunCMake/Framework/FrameworkTypeSTATIC-build-stdout.txt4
-rw-r--r--Tests/RunCMake/Framework/RunCMakeTest.cmake20
-rw-r--r--Tests/RunCMake/Framework/ios.cmake12
-rw-r--r--Tests/RunCMake/GNUInstallDirs/RunCMakeTest.cmake12
-rw-r--r--Tests/RunCMake/GenerateExportHeader/GEH.cmake19
-rw-r--r--Tests/RunCMake/GenerateExportHeader/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/libshared/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/libstatic/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/Empty/libshared_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/Empty/libstatic_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/MinGW/libshared_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/MinGW/libstatic_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/UNIX/libshared_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/UNIX/libstatic_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libshared_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libstatic_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/Win32/libshared_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/Win32/libstatic_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libshared_export.h2
-rw-r--r--Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libstatic_export.h2
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadSHELL_PATH-stderr.txt9
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadSHELL_PATH.cmake1
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt6
-rw-r--r--Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake3
-rw-r--r--Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake2
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt6
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake8
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt6
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake5
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt6
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake3
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt6
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake3
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt4
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt6
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake5
-rw-r--r--Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-unknown-lang.cmake2
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt2
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake6
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt2
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake6
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt2
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake10
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt2
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake10
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt2
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake6
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt2
-rw-r--r--Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake6
-rw-r--r--Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion-stderr.txt8
-rw-r--r--Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion.cmake3
-rw-r--r--Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake63
-rw-r--r--Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES-check.cmake3
-rw-r--r--Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES.cmake4
-rw-r--r--Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake3
-rw-r--r--Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake1
-rw-r--r--Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt1
-rw-r--r--Tests/RunCMake/GeneratorToolset/BadToolsetHostArchTwice-stderr.txt2
-rw-r--r--Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake26
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone-stdout.txt2
-rw-r--r--Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone.cmake13
-rw-r--r--Tests/RunCMake/Languages/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/LinkStatic/RunCMakeTest.cmake27
-rw-r--r--Tests/RunCMake/Make/RunCMakeTest.cmake18
-rw-r--r--Tests/RunCMake/Ninja/RunCMakeTest.cmake49
-rw-r--r--Tests/RunCMake/Ninja/greeting.c1
-rw-r--r--Tests/RunCMake/Ninja/greeting2.c1
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt5
-rw-r--r--Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake2
-rw-r--r--Tests/RunCMake/ObjectLibrary/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/ObjectLibrary/InstallNotSupported-stderr.txt4
-rw-r--r--Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt4
-rw-r--r--Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake45
-rw-r--r--Tests/RunCMake/ObjectLibrary/a.c8
-rw-r--r--Tests/RunCMake/ObjectLibrary/b.c14
-rw-r--r--Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake64
-rw-r--r--Tests/RunCMake/README.rst15
-rw-r--r--Tests/RunCMake/RunCMake.cmake62
-rw-r--r--Tests/RunCMake/RunCTest.cmake8
-rw-r--r--Tests/RunCMake/RuntimePath/RunCMakeTest.cmake16
-rw-r--r--Tests/RunCMake/RuntimePath/main.c4
-rw-r--r--Tests/RunCMake/Swift/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt13
-rw-r--r--Tests/RunCMake/Syntax/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt2
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall1.cmake3
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt2
-rw-r--r--Tests/RunCMake/Syntax/UnterminatedCall2.cmake3
-rw-r--r--Tests/RunCMake/TargetObjects/NoTarget.cmake4
-rw-r--r--Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt9
-rw-r--r--Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake4
-rw-r--r--Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt5
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt4
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt2
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt2
-rw-r--r--Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake16
-rw-r--r--Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt2
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebug-stderr.txt8
-rw-r--r--Tests/RunCMake/TargetSources/RelativePathInInterface.cmake4
-rw-r--r--Tests/RunCMake/TargetSources/RunCMakeTest.cmake10
-rw-r--r--Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/VS10Project/RunCMakeTest.cmake26
-rw-r--r--Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake31
-rw-r--r--Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake25
-rw-r--r--Tests/RunCMake/VS10Project/VsDebuggerWorkingDir-check.cmake36
-rw-r--r--Tests/RunCMake/VS10Project/VsDebuggerWorkingDir.cmake5
-rw-r--r--Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt2
-rw-r--r--Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt1
-rw-r--r--Tests/RunCMake/XcodeProject/PerConfigPerSourceFlags-stderr.txt4
-rw-r--r--Tests/RunCMake/XcodeProject/RunCMakeTest.cmake113
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeBundles.cmake20
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake9
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake5
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedSingleArch.cmake5
-rw-r--r--Tests/RunCMake/XcodeProject/XcodeInstallIOS.cmake3
-rw-r--r--Tests/RunCMake/add_custom_command/RunCMakeTest.cmake11
-rw-r--r--Tests/RunCMake/add_custom_target/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/add_subdirectory/CMakeLists.txt7
-rw-r--r--Tests/RunCMake/add_subdirectory/DoesNotExist-stderr.txt2
-rw-r--r--Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake8
-rw-r--r--Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt9
-rw-r--r--Tests/RunCMake/add_subdirectory/Missing-stderr.txt2
-rw-r--r--Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake57
-rw-r--r--Tests/RunCMake/alias_targets/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/alias_targets/imported-target-stderr.txt18
-rw-r--r--Tests/RunCMake/alias_targets/imported-target.cmake44
-rw-r--r--Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt13
-rw-r--r--Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt13
-rw-r--r--Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/configure_file/DirInput-stderr.txt2
-rw-r--r--Tests/RunCMake/ctest_build/BuildQuiet-stdout.txt1
-rw-r--r--Tests/RunCMake/ctest_configure/ConfigureQuiet-stdout.txt1
-rw-r--r--Tests/RunCMake/ctest_fixtures/CMakeLists.txt.in6
-rw-r--r--Tests/RunCMake/ctest_memcheck/CTestConfig.cmake.in3
-rwxr-xr-xTests/RunCMake/ctest_skipped_test/skip.bat2
-rw-r--r--Tests/RunCMake/ctest_start/ConfigInBuild-stdout.txt1
-rw-r--r--Tests/RunCMake/ctest_start/ConfigInSource-stdout.txt1
-rw-r--r--Tests/RunCMake/ctest_start/RunCMakeTest.cmake36
-rw-r--r--Tests/RunCMake/ctest_start/test.cmake.in22
-rw-r--r--Tests/RunCMake/ctest_submit/CDashSubmitHeaders-stderr.txt2
-rw-r--r--Tests/RunCMake/ctest_submit/CTestConfig.cmake.in1
-rw-r--r--Tests/RunCMake/ctest_submit/FailDrop-http-stdout.txt5
-rw-r--r--Tests/RunCMake/ctest_submit/FailDrop-https-stdout.txt5
-rw-r--r--Tests/RunCMake/ctest_submit/RunCMakeTest.cmake20
-rw-r--r--Tests/RunCMake/ctest_submit/test.cmake.in1
-rw-r--r--Tests/RunCMake/ctest_test/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/execute_process/RunCMakeTest.cmake13
-rw-r--r--Tests/RunCMake/export/AppendExport-stderr.txt2
-rw-r--r--Tests/RunCMake/export/OldIface-stderr.txt3
-rw-r--r--Tests/RunCMake/export/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/file/FileOpenFailRead-stderr.txt2
-rw-r--r--Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt12
-rw-r--r--Tests/RunCMake/file/RunCMakeTest.cmake97
-rw-r--r--Tests/RunCMake/find_package/PackageRoot.cmake2
-rw-r--r--Tests/RunCMake/find_package/PackageRootNestedConfig.cmake2
-rw-r--r--Tests/RunCMake/find_package/PackageRootNestedModule.cmake2
-rw-r--r--Tests/RunCMake/find_package/RunCMakeTest.cmake8
-rw-r--r--Tests/RunCMake/find_path/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/find_program/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/get_filename_component/KnownComponents.cmake15
-rw-r--r--Tests/RunCMake/get_property/BadArgument-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/BadDirectory-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/BadScope-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/BadTarget-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/BadTest-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/GlobalName-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/MissingArgument-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/NoCache-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/NoProperty-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/NoSource-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/NoTarget-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/NoTest-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/get_property/VariableName-stderr.txt2
-rw-r--r--Tests/RunCMake/get_property/directory_properties-stderr.txt10
-rw-r--r--Tests/RunCMake/get_property/directory_properties.cmake9
-rw-r--r--Tests/RunCMake/get_property/directory_properties/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/get_property/source_properties-stderr.txt8
-rw-r--r--Tests/RunCMake/get_property/source_properties.cmake10
-rw-r--r--Tests/RunCMake/get_property/target_properties-stderr.txt8
-rw-r--r--Tests/RunCMake/get_property/target_properties.cmake7
-rw-r--r--Tests/RunCMake/include_external_msproject/check_utils.cmake2
-rw-r--r--Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt2
-rw-r--r--Tests/RunCMake/install/RunCMakeTest.cmake77
-rw-r--r--Tests/RunCMake/install/obj1.c5
-rw-r--r--Tests/RunCMake/interface_library/global-interface-stderr.txt4
-rw-r--r--Tests/RunCMake/interface_library/target_commands-stderr.txt16
-rw-r--r--Tests/RunCMake/interface_library/whitelist.cmake19
-rw-r--r--Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt2
-rw-r--r--Tests/RunCMake/list/FILTER-NotList.cmake4
-rw-r--r--Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt2
-rw-r--r--Tests/RunCMake/list/INSERT-InvalidIndex.cmake2
-rw-r--r--Tests/RunCMake/list/REMOVE_AT-NotList-stderr.txt2
-rw-r--r--Tests/RunCMake/list/REMOVE_AT-NotList.cmake4
-rw-r--r--Tests/RunCMake/list/REMOVE_DUPLICATES-NotList.cmake4
-rw-r--r--Tests/RunCMake/list/REMOVE_ITEM-NotList.cmake4
-rw-r--r--Tests/RunCMake/list/REVERSE-NotList.cmake4
-rw-r--r--Tests/RunCMake/list/RunCMakeTest.cmake83
-rw-r--r--Tests/RunCMake/list/SORT-NotList.cmake4
-rw-r--r--Tests/RunCMake/message/RunCMakeTest.cmake44
-rw-r--r--Tests/RunCMake/project/ProjectDescription2-stderr.txt2
-rw-r--r--Tests/RunCMake/project/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/project/VersionMissingLanguages-stderr.txt3
-rw-r--r--Tests/RunCMake/set/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/set_property/RunCMakeTest.cmake4
-rw-r--r--Tests/RunCMake/string/AppendNoArgs-stderr.txt2
-rw-r--r--Tests/RunCMake/string/ConcatNoArgs-stderr.txt2
-rw-r--r--Tests/RunCMake/string/RunCMakeTest.cmake12
-rw-r--r--Tests/RunCMake/string/Timestamp-stderr.txt2
-rw-r--r--Tests/RunCMake/string/Timestamp.cmake2
-rw-r--r--Tests/RunCMake/string/UuidBadNamespace-stderr.txt2
-rw-r--r--Tests/RunCMake/string/UuidBadType-stderr.txt2
-rw-r--r--Tests/RunCMake/string/UuidMissingNameValue-stderr.txt2
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespace-stderr.txt2
-rw-r--r--Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt2
-rw-r--r--Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/target_compile_features/alias_target-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/imported_target-stderr.txt7
-rw-r--r--Tests/RunCMake/target_compile_features/imported_target.cmake10
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt4
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_c_feature-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/no_target-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_c_feature-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt2
-rw-r--r--Tests/RunCMake/target_compile_features/utility_target-stderr.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt6
-rw-r--r--Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake12
-rw-r--r--Tests/RunCMake/try_compile/CMP0056-stderr.txt13
-rw-r--r--Tests/RunCMake/try_compile/CMP0066-stderr.txt13
-rw-r--r--Tests/RunCMake/try_compile/CStandardGNU.c4
-rw-r--r--Tests/RunCMake/try_compile/CxxStandardGNU.cxx4
-rw-r--r--Tests/RunCMake/try_compile/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/try_compile/src.c2
-rw-r--r--Tests/RunCMake/try_run/RunCMakeTest.cmake7
-rw-r--r--Tests/RunCMake/variable_watch/RunCMakeTest.cmake2
-rw-r--r--Tests/Server/CMakeLists.txt17
-rw-r--r--Tests/Server/cmakelib.py231
-rw-r--r--Tests/Server/server-test.py177
-rw-r--r--Tests/Server/tc_handshake.json4
-rw-r--r--Tests/SourceGroups/CMakeLists.txt18
-rw-r--r--Tests/SourceGroups/main.c7
-rw-r--r--Tests/StagingPrefix/CMakeLists.txt16
-rw-r--r--Tests/SubDir/Executable/test.cxx8
-rw-r--r--Tests/SubDirSpaces/CMakeLists.txt2
-rw-r--r--Tests/SubDirSpaces/Executable Sources/test.cxx8
-rw-r--r--Tests/SubDirSpaces/Executable/test.cxx8
-rw-r--r--Tests/SwiftMix/CMain.c6
-rw-r--r--Tests/SwiftMix/CMakeLists.txt1
-rw-r--r--Tests/SwiftMix/ObjCMain.m2
-rw-r--r--Tests/SwiftMix/SwiftMain.swift2
-rw-r--r--Tests/SwiftOnly/CMakeLists.txt7
-rw-r--r--Tests/TestsWorkingDirectory/main.c23
-rw-r--r--Tests/TryCompile/CMakeLists.txt33
-rw-r--r--Tests/TryCompile/testdef.c2
-rw-r--r--Tests/Tutorial/Step1/CMakeLists.txt19
-rw-r--r--Tests/Tutorial/Step1/tutorial.cxx17
-rw-r--r--Tests/Tutorial/Step2/CMakeLists.txt34
-rw-r--r--Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx13
-rw-r--r--Tests/Tutorial/Step2/TutorialConfig.h.in1
-rw-r--r--Tests/Tutorial/Step2/tutorial.cxx32
-rw-r--r--Tests/Tutorial/Step3/CMakeLists.txt74
-rw-r--r--Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt3
-rw-r--r--Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx13
-rw-r--r--Tests/Tutorial/Step3/tutorial.cxx27
-rw-r--r--Tests/Tutorial/Step4/CMakeLists.txt72
-rw-r--r--Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt7
-rw-r--r--Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx23
-rw-r--r--Tests/Tutorial/Step4/TutorialConfig.h.in4
-rw-r--r--Tests/Tutorial/Step4/tutorial.cxx27
-rw-r--r--Tests/Tutorial/Step5/CMakeLists.txt86
-rw-r--r--Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt23
-rw-r--r--Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx35
-rw-r--r--Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx27
-rw-r--r--Tests/Tutorial/Step5/TutorialConfig.h.in4
-rw-r--r--Tests/Tutorial/Step5/tutorial.cxx27
-rw-r--r--Tests/Tutorial/Step6/CMakeLists.txt94
-rw-r--r--Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt32
-rw-r--r--Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx35
-rw-r--r--Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx31
-rw-r--r--Tests/Tutorial/Step6/tutorial.cxx27
-rw-r--r--Tests/Tutorial/Step7/CMakeLists.txt98
-rw-r--r--Tests/Tutorial/Step7/License.txt2
-rw-r--r--Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt33
-rw-r--r--Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx35
-rw-r--r--Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx18
-rw-r--r--Tests/Tutorial/Step7/tutorial.cxx27
-rw-r--r--Tests/Unset/CMakeLists.txt9
-rw-r--r--Tests/VSExternalInclude/CMakeLists.txt4
-rw-r--r--Tests/VSGNUFortran/CMakeLists.txt5
-rw-r--r--Tests/VSGNUFortran/runtest.cmake.in2
-rw-r--r--Tests/VSNASM/CMakeLists.txt12
-rw-r--r--Tests/VSNASM/include/foo-proc.asm2
-rw-r--r--Tests/VSNASM/main.c3
-rw-r--r--Tests/VSResource/CMakeLists.txt7
-rw-r--r--Tests/VSWinStorePhone/CMakeLists.txt17
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.pngbin3392 -> 2335 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Logo.pngbin801 -> 488 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo.pngbin329 -> 167 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo44x44.pngbin554 -> 265 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.pngbin2146 -> 909 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/StoreLogo.pngbin429 -> 227 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.pngbin9930 -> 2953 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.pngbin9070 -> 2767 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.pngbin3674 -> 1397 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.pngbin4937 -> 893 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileSmall.pngbin3724 -> 516 bytes
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp4
-rw-r--r--Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp6
-rw-r--r--Tests/VSXaml/Assets/Logo.scale-100.pngbin801 -> 488 bytes
-rw-r--r--Tests/VSXaml/Assets/SmallLogo.scale-100.pngbin329 -> 167 bytes
-rw-r--r--Tests/VSXaml/Assets/SplashScreen.scale-100.pngbin2146 -> 909 bytes
-rw-r--r--Tests/VSXaml/Assets/StoreLogo.scale-100.pngbin429 -> 227 bytes
-rw-r--r--Tests/WarnUnusedCliUnused/CMakeLists.txt8
-rw-r--r--Tests/Wrapping/fakefluid.cxx7
-rw-r--r--Tests/Wrapping/qtwrappingmain.cxx4
-rw-r--r--Tests/X11/HelloWorldX11.cxx12
-rw-r--r--Tests/X11/X11.c4
-rw-r--r--Tests/XCTest/CMakeLists.txt2
-rw-r--r--Tests/bootstrap.bat.in4
-rw-r--r--Utilities/Doxygen/CMakeLists.txt2
-rwxr-xr-xUtilities/GitSetup/setup-hooks4
-rwxr-xr-xUtilities/GitSetup/tips4
-rw-r--r--Utilities/IWYU/mapping.imp51
-rw-r--r--Utilities/KWIML/Copyright.txt2
-rw-r--r--Utilities/KWIML/include/kwiml/abi.h19
-rw-r--r--Utilities/KWIML/include/kwiml/int.h15
-rw-r--r--Utilities/KWIML/src/version.h.in2
-rw-r--r--Utilities/KWIML/test/test_int_format.h9
-rw-r--r--Utilities/Release/CMakeLogo.icobin24542 -> 17542 bytes
-rw-r--r--Utilities/Release/WiX/WIX.template.in2
-rw-r--r--Utilities/Release/create-cmake-release.cmake2
-rw-r--r--Utilities/Release/linux64_release.cmake19
-rw-r--r--Utilities/Release/osx_release.cmake3
-rwxr-xr-xUtilities/Release/release_cmake.sh.in2
-rw-r--r--Utilities/Release/win32_release.cmake42
-rw-r--r--Utilities/Release/win64_release.cmake39
-rw-r--r--Utilities/Scripts/BoostScanDeps.cmake41
-rwxr-xr-xUtilities/Scripts/clang-format.bash17
-rwxr-xr-xUtilities/Scripts/update-curl.bash12
-rwxr-xr-xUtilities/Scripts/update-expat.bash2
-rwxr-xr-xUtilities/Scripts/update-gitsetup.bash7
-rwxr-xr-xUtilities/Scripts/update-libarchive.bash2
-rwxr-xr-xUtilities/Scripts/update-liblzma.bash8
-rwxr-xr-xUtilities/Scripts/update-libuv.bash2
-rw-r--r--Utilities/Scripts/update-third-party.bash24
-rw-r--r--Utilities/Sphinx/CMakeLists.txt31
-rw-r--r--Utilities/Sphinx/cmake.py65
-rw-r--r--Utilities/Sphinx/conf.py.in2
-rwxr-xr-xUtilities/Sphinx/create_identifiers.py3
-rw-r--r--Utilities/Sphinx/static/cmake-favicon.icobin1150 -> 1150 bytes
-rw-r--r--Utilities/Sphinx/static/cmake-logo-16.pngbin761 -> 692 bytes
-rw-r--r--Utilities/Sphinx/static/cmake.css10
-rw-r--r--Utilities/cmThirdParty.h.in2
-rw-r--r--Utilities/cm_bzlib.h4
-rw-r--r--Utilities/cm_curl.h4
-rw-r--r--Utilities/cm_expat.h4
-rw-r--r--Utilities/cm_jsoncpp_reader.h4
-rw-r--r--Utilities/cm_jsoncpp_value.h4
-rw-r--r--Utilities/cm_jsoncpp_writer.h4
-rw-r--r--Utilities/cm_kwiml.h8
-rw-r--r--Utilities/cm_libarchive.h8
-rw-r--r--Utilities/cm_lzma.h4
-rw-r--r--Utilities/cm_rhash.h4
-rw-r--r--Utilities/cm_uv.h4
-rw-r--r--Utilities/cm_zlib.h4
-rw-r--r--Utilities/cmcurl/CMake/CMakeConfigurableFile.in1
-rw-r--r--Utilities/cmcurl/CMake/CurlSymbolHiding.cmake92
-rw-r--r--Utilities/cmcurl/CMake/CurlTests.c94
-rw-r--r--Utilities/cmcurl/CMake/FindCARES.cmake38
-rw-r--r--Utilities/cmcurl/CMake/FindGSS.cmake410
-rw-r--r--Utilities/cmcurl/CMake/FindLibSSH2.cmake14
-rw-r--r--Utilities/cmcurl/CMake/FindNGHTTP2.cmake2
-rw-r--r--Utilities/cmcurl/CMake/Macros.cmake83
-rw-r--r--Utilities/cmcurl/CMake/OtherTests.cmake136
-rw-r--r--Utilities/cmcurl/CMake/Platforms/WindowsCache.cmake7
-rw-r--r--Utilities/cmcurl/CMake/Utilities.cmake41
-rw-r--r--Utilities/cmcurl/CMakeLists.txt606
-rw-r--r--Utilities/cmcurl/COPYING2
-rw-r--r--Utilities/cmcurl/curltest.c184
-rw-r--r--Utilities/cmcurl/include/curl/curl.h400
-rw-r--r--Utilities/cmcurl/include/curl/curlver.h14
-rw-r--r--Utilities/cmcurl/include/curl/easy.h10
-rw-r--r--Utilities/cmcurl/include/curl/multi.h8
-rw-r--r--Utilities/cmcurl/include/curl/system.h639
-rw-r--r--Utilities/cmcurl/include/curl/typecheck-gcc.h54
-rw-r--r--Utilities/cmcurl/lib/CMakeLists.txt47
-rw-r--r--Utilities/cmcurl/lib/Makefile.inc28
-rw-r--r--Utilities/cmcurl/lib/amigaos.c32
-rw-r--r--Utilities/cmcurl/lib/amigaos.h9
-rw-r--r--Utilities/cmcurl/lib/arpa_telnet.h6
-rw-r--r--Utilities/cmcurl/lib/asyn-ares.c222
-rw-r--r--Utilities/cmcurl/lib/asyn-thread.c197
-rw-r--r--Utilities/cmcurl/lib/asyn.h36
-rw-r--r--Utilities/cmcurl/lib/base64.c36
-rw-r--r--Utilities/cmcurl/lib/conncache.c363
-rw-r--r--Utilities/cmcurl/lib/conncache.h40
-rw-r--r--Utilities/cmcurl/lib/connect.c316
-rw-r--r--Utilities/cmcurl/lib/connect.h13
-rw-r--r--Utilities/cmcurl/lib/content_encoding.c857
-rw-r--r--Utilities/cmcurl/lib/content_encoding.h45
-rw-r--r--Utilities/cmcurl/lib/cookie.c658
-rw-r--r--Utilities/cmcurl/lib/cookie.h34
-rw-r--r--Utilities/cmcurl/lib/curl_addrinfo.c52
-rw-r--r--Utilities/cmcurl/lib/curl_addrinfo.h13
-rw-r--r--Utilities/cmcurl/lib/curl_config.h.cmake44
-rw-r--r--Utilities/cmcurl/lib/curl_endian.c10
-rw-r--r--Utilities/cmcurl/lib/curl_fnmatch.c373
-rw-r--r--Utilities/cmcurl/lib/curl_gssapi.c13
-rw-r--r--Utilities/cmcurl/lib/curl_gssapi.h16
-rw-r--r--Utilities/cmcurl/lib/curl_ldap.h1
-rw-r--r--Utilities/cmcurl/lib/curl_md4.h4
-rw-r--r--Utilities/cmcurl/lib/curl_md5.h10
-rw-r--r--Utilities/cmcurl/lib/curl_memory.h4
-rw-r--r--Utilities/cmcurl/lib/curl_memrchr.c19
-rw-r--r--Utilities/cmcurl/lib/curl_multibyte.c12
-rw-r--r--Utilities/cmcurl/lib/curl_ntlm_core.c176
-rw-r--r--Utilities/cmcurl/lib/curl_ntlm_core.h18
-rw-r--r--Utilities/cmcurl/lib/curl_ntlm_wb.c114
-rw-r--r--Utilities/cmcurl/lib/curl_ntlm_wb.h11
-rw-r--r--Utilities/cmcurl/lib/curl_printf.h16
-rw-r--r--Utilities/cmcurl/lib/curl_rtmp.c21
-rw-r--r--Utilities/cmcurl/lib/curl_sasl.c77
-rw-r--r--Utilities/cmcurl/lib/curl_setup.h146
-rw-r--r--Utilities/cmcurl/lib/curl_setup_once.h38
-rw-r--r--Utilities/cmcurl/lib/curl_sspi.c7
-rw-r--r--Utilities/cmcurl/lib/curl_threads.c24
-rw-r--r--Utilities/cmcurl/lib/curl_threads.h3
-rw-r--r--Utilities/cmcurl/lib/curlx.h22
-rw-r--r--Utilities/cmcurl/lib/dict.c32
-rw-r--r--Utilities/cmcurl/lib/dotdot.c32
-rw-r--r--Utilities/cmcurl/lib/dotdot.h2
-rw-r--r--Utilities/cmcurl/lib/easy.c326
-rw-r--r--Utilities/cmcurl/lib/easyif.h1
-rw-r--r--Utilities/cmcurl/lib/escape.c50
-rw-r--r--Utilities/cmcurl/lib/escape.h4
-rw-r--r--Utilities/cmcurl/lib/file.c142
-rw-r--r--Utilities/cmcurl/lib/file.h1
-rw-r--r--Utilities/cmcurl/lib/fileinfo.c10
-rw-r--r--Utilities/cmcurl/lib/fileinfo.h5
-rw-r--r--Utilities/cmcurl/lib/formdata.c967
-rw-r--r--Utilities/cmcurl/lib/formdata.h57
-rw-r--r--Utilities/cmcurl/lib/ftp.c631
-rw-r--r--Utilities/cmcurl/lib/ftp.h9
-rw-r--r--Utilities/cmcurl/lib/ftplistparser.c249
-rw-r--r--Utilities/cmcurl/lib/getinfo.c126
-rw-r--r--Utilities/cmcurl/lib/gopher.c46
-rw-r--r--Utilities/cmcurl/lib/hash.c21
-rw-r--r--Utilities/cmcurl/lib/hmac.c4
-rw-r--r--Utilities/cmcurl/lib/hostasyn.c43
-rw-r--r--Utilities/cmcurl/lib/hostcheck.c28
-rw-r--r--Utilities/cmcurl/lib/hostcheck.h1
-rw-r--r--Utilities/cmcurl/lib/hostip.c464
-rw-r--r--Utilities/cmcurl/lib/hostip.h23
-rw-r--r--Utilities/cmcurl/lib/hostip4.c15
-rw-r--r--Utilities/cmcurl/lib/hostip6.c59
-rw-r--r--Utilities/cmcurl/lib/hostsyn.c10
-rw-r--r--Utilities/cmcurl/lib/http.c1575
-rw-r--r--Utilities/cmcurl/lib/http.h56
-rw-r--r--Utilities/cmcurl/lib/http2.c723
-rw-r--r--Utilities/cmcurl/lib/http2.h15
-rw-r--r--Utilities/cmcurl/lib/http_chunks.c86
-rw-r--r--Utilities/cmcurl/lib/http_chunks.h1
-rw-r--r--Utilities/cmcurl/lib/http_digest.c5
-rw-r--r--Utilities/cmcurl/lib/http_digest.h12
-rw-r--r--Utilities/cmcurl/lib/http_negotiate.c134
-rw-r--r--Utilities/cmcurl/lib/http_negotiate.h8
-rw-r--r--Utilities/cmcurl/lib/http_ntlm.c63
-rw-r--r--Utilities/cmcurl/lib/http_ntlm.h10
-rw-r--r--Utilities/cmcurl/lib/http_proxy.c321
-rw-r--r--Utilities/cmcurl/lib/http_proxy.h10
-rw-r--r--Utilities/cmcurl/lib/if2ip.c69
-rw-r--r--Utilities/cmcurl/lib/if2ip.h9
-rw-r--r--Utilities/cmcurl/lib/imap.c394
-rw-r--r--Utilities/cmcurl/lib/imap.h4
-rw-r--r--Utilities/cmcurl/lib/inet_ntop.c28
-rw-r--r--Utilities/cmcurl/lib/inet_ntop.h1
-rw-r--r--Utilities/cmcurl/lib/inet_pton.c9
-rw-r--r--Utilities/cmcurl/lib/inet_pton.h6
-rw-r--r--Utilities/cmcurl/lib/krb5.c17
-rw-r--r--Utilities/cmcurl/lib/ldap.c56
-rw-r--r--Utilities/cmcurl/lib/libcurl.rc12
-rw-r--r--Utilities/cmcurl/lib/llist.c6
-rw-r--r--Utilities/cmcurl/lib/llist.h1
-rw-r--r--Utilities/cmcurl/lib/md4.c116
-rw-r--r--Utilities/cmcurl/lib/md5.c211
-rw-r--r--Utilities/cmcurl/lib/memdebug.c185
-rw-r--r--Utilities/cmcurl/lib/memdebug.h121
-rw-r--r--Utilities/cmcurl/lib/mprintf.c40
-rw-r--r--Utilities/cmcurl/lib/multi.c1547
-rw-r--r--Utilities/cmcurl/lib/multihandle.h61
-rw-r--r--Utilities/cmcurl/lib/multiif.h38
-rw-r--r--Utilities/cmcurl/lib/netrc.c108
-rw-r--r--Utilities/cmcurl/lib/netrc.h11
-rw-r--r--Utilities/cmcurl/lib/non-ascii.c124
-rw-r--r--Utilities/cmcurl/lib/non-ascii.h4
-rw-r--r--Utilities/cmcurl/lib/nonblock.c3
-rw-r--r--Utilities/cmcurl/lib/nonblock.h1
-rw-r--r--Utilities/cmcurl/lib/nwlib.c11
-rw-r--r--Utilities/cmcurl/lib/openldap.c117
-rw-r--r--Utilities/cmcurl/lib/parsedate.c214
-rw-r--r--Utilities/cmcurl/lib/parsedate.h1
-rw-r--r--Utilities/cmcurl/lib/pingpong.c73
-rw-r--r--Utilities/cmcurl/lib/pingpong.h11
-rw-r--r--Utilities/cmcurl/lib/pop3.c155
-rw-r--r--Utilities/cmcurl/lib/progress.c406
-rw-r--r--Utilities/cmcurl/lib/progress.h29
-rw-r--r--Utilities/cmcurl/lib/rand.c12
-rw-r--r--Utilities/cmcurl/lib/rand.h7
-rw-r--r--Utilities/cmcurl/lib/rtsp.c132
-rw-r--r--Utilities/cmcurl/lib/rtsp.h3
-rw-r--r--Utilities/cmcurl/lib/security.c35
-rw-r--r--Utilities/cmcurl/lib/select.c30
-rw-r--r--Utilities/cmcurl/lib/select.h6
-rw-r--r--Utilities/cmcurl/lib/sendf.c230
-rw-r--r--Utilities/cmcurl/lib/sendf.h11
-rw-r--r--Utilities/cmcurl/lib/share.c15
-rw-r--r--Utilities/cmcurl/lib/share.h9
-rw-r--r--Utilities/cmcurl/lib/sigpipe.h5
-rw-r--r--Utilities/cmcurl/lib/slist.c1
-rw-r--r--Utilities/cmcurl/lib/slist.h1
-rw-r--r--Utilities/cmcurl/lib/smb.c160
-rw-r--r--Utilities/cmcurl/lib/smb.h34
-rw-r--r--Utilities/cmcurl/lib/smtp.c209
-rw-r--r--Utilities/cmcurl/lib/sockaddr.h1
-rw-r--r--Utilities/cmcurl/lib/socks.c127
-rw-r--r--Utilities/cmcurl/lib/socks.h1
-rw-r--r--Utilities/cmcurl/lib/socks_gssapi.c61
-rw-r--r--Utilities/cmcurl/lib/socks_sspi.c31
-rw-r--r--Utilities/cmcurl/lib/speedcheck.c6
-rw-r--r--Utilities/cmcurl/lib/speedcheck.h4
-rw-r--r--Utilities/cmcurl/lib/splay.c32
-rw-r--r--Utilities/cmcurl/lib/splay.h17
-rw-r--r--Utilities/cmcurl/lib/ssh.c494
-rw-r--r--Utilities/cmcurl/lib/ssh.h73
-rw-r--r--Utilities/cmcurl/lib/strcase.c11
-rw-r--r--Utilities/cmcurl/lib/strcase.h1
-rw-r--r--Utilities/cmcurl/lib/strdup.c8
-rw-r--r--Utilities/cmcurl/lib/strerror.c114
-rw-r--r--Utilities/cmcurl/lib/strerror.h11
-rw-r--r--Utilities/cmcurl/lib/strtoofft.c68
-rw-r--r--Utilities/cmcurl/lib/strtoofft.h39
-rw-r--r--Utilities/cmcurl/lib/system_win32.c97
-rw-r--r--Utilities/cmcurl/lib/system_win32.h6
-rw-r--r--Utilities/cmcurl/lib/telnet.c151
-rw-r--r--Utilities/cmcurl/lib/telnet.h1
-rw-r--r--Utilities/cmcurl/lib/tftp.c146
-rw-r--r--Utilities/cmcurl/lib/tftp.h1
-rw-r--r--Utilities/cmcurl/lib/timeval.c174
-rw-r--r--Utilities/cmcurl/lib/timeval.h38
-rw-r--r--Utilities/cmcurl/lib/transfer.c906
-rw-r--r--Utilities/cmcurl/lib/transfer.h29
-rw-r--r--Utilities/cmcurl/lib/url.c4870
-rw-r--r--Utilities/cmcurl/lib/url.h52
-rw-r--r--Utilities/cmcurl/lib/urldata.h1065
-rw-r--r--Utilities/cmcurl/lib/vauth/cleartext.c48
-rw-r--r--Utilities/cmcurl/lib/vauth/cram.c2
-rw-r--r--Utilities/cmcurl/lib/vauth/digest.c217
-rw-r--r--Utilities/cmcurl/lib/vauth/digest.h6
-rw-r--r--Utilities/cmcurl/lib/vauth/digest_sspi.c53
-rw-r--r--Utilities/cmcurl/lib/vauth/krb5_gssapi.c8
-rw-r--r--Utilities/cmcurl/lib/vauth/krb5_sspi.c18
-rw-r--r--Utilities/cmcurl/lib/vauth/ntlm.c295
-rw-r--r--Utilities/cmcurl/lib/vauth/ntlm.h8
-rw-r--r--Utilities/cmcurl/lib/vauth/ntlm_sspi.c82
-rw-r--r--Utilities/cmcurl/lib/vauth/oauth2.c56
-rw-r--r--Utilities/cmcurl/lib/vauth/spnego_gssapi.c20
-rw-r--r--Utilities/cmcurl/lib/vauth/spnego_sspi.c70
-rw-r--r--Utilities/cmcurl/lib/vauth/vauth.c44
-rw-r--r--Utilities/cmcurl/lib/vauth/vauth.h25
-rw-r--r--Utilities/cmcurl/lib/version.c114
-rw-r--r--Utilities/cmcurl/lib/vtls/cyassl.c274
-rw-r--r--Utilities/cmcurl/lib/vtls/cyassl.h63
-rw-r--r--Utilities/cmcurl/lib/vtls/gskit.c244
-rw-r--r--Utilities/cmcurl/lib/vtls/gskit.h38
-rw-r--r--Utilities/cmcurl/lib/vtls/gtls.c403
-rw-r--r--Utilities/cmcurl/lib/vtls/gtls.h64
-rw-r--r--Utilities/cmcurl/lib/vtls/mbedtls.c286
-rw-r--r--Utilities/cmcurl/lib/vtls/mbedtls.h52
-rw-r--r--Utilities/cmcurl/lib/vtls/nss.c368
-rw-r--r--Utilities/cmcurl/lib/vtls/nssg.h71
-rw-r--r--Utilities/cmcurl/lib/vtls/openssl.c1270
-rw-r--r--Utilities/cmcurl/lib/vtls/openssl.h91
-rw-r--r--Utilities/cmcurl/lib/vtls/polarssl.c212
-rw-r--r--Utilities/cmcurl/lib/vtls/polarssl.h52
-rw-r--r--Utilities/cmcurl/lib/vtls/polarssl_threadlock.c63
-rw-r--r--Utilities/cmcurl/lib/vtls/polarssl_threadlock.h9
-rw-r--r--Utilities/cmcurl/lib/vtls/schannel.c1474
-rw-r--r--Utilities/cmcurl/lib/vtls/schannel.h145
-rw-r--r--Utilities/cmcurl/lib/vtls/vtls.c564
-rw-r--r--Utilities/cmcurl/lib/vtls/vtls.h92
-rw-r--r--Utilities/cmcurl/lib/warnless.c70
-rw-r--r--Utilities/cmcurl/lib/warnless.h9
-rw-r--r--Utilities/cmcurl/lib/wildcard.c24
-rw-r--r--Utilities/cmcurl/lib/wildcard.h16
-rw-r--r--Utilities/cmcurl/lib/x509asn1.c515
-rw-r--r--Utilities/cmexpat/CMakeLists.txt2
-rw-r--r--Utilities/cmexpat/ConfigureChecks.cmake35
-rw-r--r--Utilities/cmexpat/README.md55
-rw-r--r--Utilities/cmexpat/expat_config.h.cmake30
-rw-r--r--Utilities/cmexpat/lib/ascii.h32
-rw-r--r--Utilities/cmexpat/lib/asciitab.h32
-rw-r--r--Utilities/cmexpat/lib/expat.h36
-rw-r--r--Utilities/cmexpat/lib/expat_external.h92
-rw-r--r--Utilities/cmexpat/lib/iasciitab.h32
-rw-r--r--Utilities/cmexpat/lib/internal.h36
-rw-r--r--Utilities/cmexpat/lib/latin1tab.h32
-rw-r--r--Utilities/cmexpat/lib/loadlibrary.c4
-rw-r--r--Utilities/cmexpat/lib/nametab.h32
-rw-r--r--Utilities/cmexpat/lib/siphash.h17
-rw-r--r--Utilities/cmexpat/lib/utf8tab.h33
-rw-r--r--Utilities/cmexpat/lib/winconfig.h41
-rw-r--r--Utilities/cmexpat/lib/xmlparse.c2715
-rw-r--r--Utilities/cmexpat/lib/xmlrole.c32
-rw-r--r--Utilities/cmexpat/lib/xmlrole.h32
-rw-r--r--Utilities/cmexpat/lib/xmltok.c90
-rw-r--r--Utilities/cmexpat/lib/xmltok.h37
-rw-r--r--Utilities/cmexpat/lib/xmltok_impl.c115
-rw-r--r--Utilities/cmexpat/lib/xmltok_impl.h31
-rw-r--r--Utilities/cmexpat/lib/xmltok_ns.c33
-rw-r--r--Utilities/cmjsoncpp/CMakeLists.txt4
-rw-r--r--Utilities/cmjsoncpp/LICENSE8
-rw-r--r--Utilities/cmjsoncpp/include/json/assertions.h41
-rw-r--r--Utilities/cmjsoncpp/include/json/config.h135
-rw-r--r--Utilities/cmjsoncpp/include/json/features.h10
-rw-r--r--Utilities/cmjsoncpp/include/json/forwards.h8
-rw-r--r--Utilities/cmjsoncpp/include/json/json.h2
-rw-r--r--Utilities/cmjsoncpp/include/json/reader.h181
-rw-r--r--Utilities/cmjsoncpp/include/json/value.h723
-rw-r--r--Utilities/cmjsoncpp/include/json/version.h16
-rw-r--r--Utilities/cmjsoncpp/include/json/writer.h205
-rw-r--r--Utilities/cmjsoncpp/src/lib_json/json_reader.cpp1436
-rw-r--r--Utilities/cmjsoncpp/src/lib_json/json_tool.h44
-rw-r--r--Utilities/cmjsoncpp/src/lib_json/json_value.cpp892
-rw-r--r--Utilities/cmjsoncpp/src/lib_json/json_valueiterator.inl138
-rw-r--r--Utilities/cmjsoncpp/src/lib_json/json_writer.cpp823
-rw-r--r--Utilities/cmlibarchive/CMakeLists.txt458
-rw-r--r--Utilities/cmlibarchive/build/cmake/config.h.in102
-rw-r--r--Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in1
-rw-r--r--Utilities/cmlibarchive/build/version2
-rw-r--r--Utilities/cmlibarchive/libarchive/CMakeLists.txt17
-rw-r--r--Utilities/cmlibarchive/libarchive/archive.h8
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_acl.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_check_magic.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_cmdline.c6
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_cryptor.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_cryptor_private.h2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry.32
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry.c35
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry.h3
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_acl.310
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_paths.312
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_perms.34
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_entry_sparse.c4
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_getdate.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_match.c4
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h3
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_pack_dev.c5
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_platform.h43
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_ppmd7.c10
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h4
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_ppmd_private.h7
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_random.c3
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read.c15
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_append_filter.c4
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk.372
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c1285
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c8
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_private.h9
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c19
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_filter.36
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_format.36
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_open.34
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c6
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c21
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c156
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c9
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c34
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c8
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c289
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c32
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c28
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c9
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c32
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c71
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_string.c6
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_string_sprintf.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_util.c92
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_virtual.c11
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write.32
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter.c3
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c10
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c3
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c7
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_data.324
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk.3185
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c308
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_private.h6
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c19
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_filter.36
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_finish_entry.35
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_format.31
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c17
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c17
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c17
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c2
-rw-r--r--Utilities/cmlibarchive/libarchive/config_freebsd.h351
-rw-r--r--Utilities/cmlibarchive/libarchive/libarchive_changes.31
-rw-r--r--Utilities/cmlibarchive/libarchive/mtree.52
-rw-r--r--Utilities/cmlibarchive/libarchive/xxhash.c12
-rw-r--r--Utilities/cmliblzma/CMakeLists.txt20
-rw-r--r--Utilities/cmliblzma/COPYING2
-rw-r--r--Utilities/cmliblzma/common/common_w32res.rc2
-rw-r--r--Utilities/cmliblzma/common/sysdefs.h15
-rw-r--r--Utilities/cmliblzma/common/tuklib_integer.h35
-rw-r--r--Utilities/cmliblzma/config.h.in28
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma.h26
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/base.h88
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/block.h74
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/container.h222
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/filter.h13
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/hardware.h14
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/index.h34
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/index_hash.h4
-rw-r--r--Utilities/cmliblzma/liblzma/api/lzma/version.h4
-rw-r--r--Utilities/cmliblzma/liblzma/check/check.c12
-rw-r--r--Utilities/cmliblzma/liblzma/check/check.h93
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc32_fast.c8
-rw-r--r--Utilities/cmliblzma/liblzma/check/crc64_fast.c4
-rw-r--r--Utilities/cmliblzma/liblzma/check/sha256.c68
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_decoder.c73
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_decoder.h2
-rw-r--r--Utilities/cmliblzma/liblzma/common/alone_encoder.c68
-rw-r--r--Utilities/cmliblzma/liblzma/common/auto_decoder.c51
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c10
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c134
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_decoder.c67
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_decoder.h2
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_encoder.c52
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_encoder.h2
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_header_decoder.c37
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_header_encoder.c19
-rw-r--r--Utilities/cmliblzma/liblzma/common/block_util.c13
-rw-r--r--Utilities/cmliblzma/liblzma/common/common.c103
-rw-r--r--Utilities/cmliblzma/liblzma/common/common.h138
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_buffer_encoder.c4
-rw-r--r--Utilities/cmliblzma/liblzma/common/easy_encoder.c1
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c15
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c18
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_common.c129
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_common.h2
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_decoder.c87
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_decoder.h2
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_encoder.c163
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_encoder.h6
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c8
-rw-r--r--Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c3
-rw-r--r--Utilities/cmliblzma/liblzma/common/index.c166
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_decoder.c63
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_encoder.c35
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_encoder.h2
-rw-r--r--Utilities/cmliblzma/liblzma/common/index_hash.c16
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c8
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c25
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_decoder.c102
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_decoder.h5
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_encoder.c108
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c8
-rw-r--r--Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c8
-rw-r--r--Utilities/cmliblzma/liblzma/common/vli_decoder.c4
-rw-r--r--Utilities/cmliblzma/liblzma/common/vli_encoder.c2
-rw-r--r--Utilities/cmliblzma/liblzma/common/vli_size.c3
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_common.c31
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_decoder.c29
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_decoder.h5
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_encoder.c31
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_encoder.h3
-rw-r--r--Utilities/cmliblzma/liblzma/delta/delta_private.h6
-rw-r--r--Utilities/cmliblzma/liblzma/liblzma.pc.in2
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_decoder.c97
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_decoder.h52
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder.c224
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder.h21
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h21
-rw-r--r--Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c230
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/fastpos.h57
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c49
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h5
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c85
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h4
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_common.h54
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c253
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h7
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c150
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h16
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c49
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_normal.c340
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c8
-rw-r--r--Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h28
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/range_common.h7
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h16
-rw-r--r--Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h3
-rw-r--r--Utilities/cmliblzma/liblzma/simple/arm.c12
-rw-r--r--Utilities/cmliblzma/liblzma/simple/armthumb.c12
-rw-r--r--Utilities/cmliblzma/liblzma/simple/ia64.c32
-rw-r--r--Utilities/cmliblzma/liblzma/simple/powerpc.c10
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_coder.c91
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_coder.h36
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_decoder.c7
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_decoder.h2
-rw-r--r--Utilities/cmliblzma/liblzma/simple/simple_private.h15
-rw-r--r--Utilities/cmliblzma/liblzma/simple/sparc.c13
-rw-r--r--Utilities/cmliblzma/liblzma/simple/x86.c44
-rw-r--r--Utilities/cmlibrhash/CMakeLists.txt2
-rw-r--r--Utilities/cmlibrhash/librhash/rhash.c2
-rw-r--r--Utilities/cmlibuv/CMakeLists.txt60
-rw-r--r--Utilities/cmlibuv/LICENSE4
-rw-r--r--Utilities/cmlibuv/include/uv.h182
-rw-r--r--Utilities/cmlibuv/src/fs-poll.c4
-rw-r--r--Utilities/cmlibuv/src/inet.c13
-rw-r--r--Utilities/cmlibuv/src/threadpool.c114
-rw-r--r--Utilities/cmlibuv/src/unix/aix.c349
-rw-r--r--Utilities/cmlibuv/src/unix/android-ifaddrs.c51
-rw-r--r--Utilities/cmlibuv/src/unix/async.c8
-rw-r--r--Utilities/cmlibuv/src/unix/atomic-ops.h9
-rw-r--r--Utilities/cmlibuv/src/unix/bsd-ifaddrs.c42
-rw-r--r--Utilities/cmlibuv/src/unix/core.c314
-rw-r--r--Utilities/cmlibuv/src/unix/cygwin.c4
-rw-r--r--Utilities/cmlibuv/src/unix/darwin-proctitle.c150
-rw-r--r--Utilities/cmlibuv/src/unix/darwin.c24
-rw-r--r--Utilities/cmlibuv/src/unix/freebsd.c134
-rw-r--r--Utilities/cmlibuv/src/unix/fs.c580
-rw-r--r--Utilities/cmlibuv/src/unix/fsevents.c92
-rw-r--r--Utilities/cmlibuv/src/unix/getaddrinfo.c59
-rw-r--r--Utilities/cmlibuv/src/unix/getnameinfo.c3
-rw-r--r--Utilities/cmlibuv/src/unix/internal.h87
-rw-r--r--Utilities/cmlibuv/src/unix/kqueue.c127
-rw-r--r--Utilities/cmlibuv/src/unix/linux-core.c161
-rw-r--r--Utilities/cmlibuv/src/unix/linux-inotify.c18
-rw-r--r--Utilities/cmlibuv/src/unix/linux-syscalls.c133
-rw-r--r--Utilities/cmlibuv/src/unix/linux-syscalls.h34
-rw-r--r--Utilities/cmlibuv/src/unix/loop-watcher.c2
-rw-r--r--Utilities/cmlibuv/src/unix/loop.c11
-rw-r--r--Utilities/cmlibuv/src/unix/netbsd.c88
-rw-r--r--Utilities/cmlibuv/src/unix/no-fsevents.c6
-rw-r--r--Utilities/cmlibuv/src/unix/no-proctitle.c2
-rw-r--r--Utilities/cmlibuv/src/unix/openbsd.c66
-rw-r--r--Utilities/cmlibuv/src/unix/os390-syscalls.c246
-rw-r--r--Utilities/cmlibuv/src/unix/os390-syscalls.h7
-rw-r--r--Utilities/cmlibuv/src/unix/os390.c235
-rw-r--r--Utilities/cmlibuv/src/unix/pipe.c113
-rw-r--r--Utilities/cmlibuv/src/unix/poll.c32
-rw-r--r--Utilities/cmlibuv/src/unix/posix-hrtime.c25
-rw-r--r--Utilities/cmlibuv/src/unix/posix-poll.c18
-rw-r--r--Utilities/cmlibuv/src/unix/process.c152
-rw-r--r--Utilities/cmlibuv/src/unix/procfs-exepath.c4
-rw-r--r--Utilities/cmlibuv/src/unix/proctitle.c43
-rw-r--r--Utilities/cmlibuv/src/unix/signal.c70
-rw-r--r--Utilities/cmlibuv/src/unix/stream.c379
-rw-r--r--Utilities/cmlibuv/src/unix/sunos.c61
-rw-r--r--Utilities/cmlibuv/src/unix/tcp.c166
-rw-r--r--Utilities/cmlibuv/src/unix/thread.c465
-rw-r--r--Utilities/cmlibuv/src/unix/tty.c95
-rw-r--r--Utilities/cmlibuv/src/unix/udp.c107
-rw-r--r--Utilities/cmlibuv/src/uv-common.c48
-rw-r--r--Utilities/cmlibuv/src/uv-common.h139
-rw-r--r--Utilities/cmlibuv/src/win/async.c10
-rw-r--r--Utilities/cmlibuv/src/win/atomicops-inl.h8
-rw-r--r--Utilities/cmlibuv/src/win/core.c68
-rw-r--r--Utilities/cmlibuv/src/win/dl.c64
-rw-r--r--Utilities/cmlibuv/src/win/error.c6
-rw-r--r--Utilities/cmlibuv/src/win/fs-event.c46
-rw-r--r--Utilities/cmlibuv/src/win/fs.c752
-rw-r--r--Utilities/cmlibuv/src/win/getaddrinfo.c101
-rw-r--r--Utilities/cmlibuv/src/win/getnameinfo.c50
-rw-r--r--Utilities/cmlibuv/src/win/handle-inl.h25
-rw-r--r--Utilities/cmlibuv/src/win/handle.c17
-rw-r--r--Utilities/cmlibuv/src/win/internal.h125
-rw-r--r--Utilities/cmlibuv/src/win/loop-watcher.c2
-rw-r--r--Utilities/cmlibuv/src/win/pipe.c1197
-rw-r--r--Utilities/cmlibuv/src/win/poll.c55
-rw-r--r--Utilities/cmlibuv/src/win/process-stdio.c59
-rw-r--r--Utilities/cmlibuv/src/win/process.c160
-rw-r--r--Utilities/cmlibuv/src/win/signal.c52
-rw-r--r--Utilities/cmlibuv/src/win/stream-inl.h11
-rw-r--r--Utilities/cmlibuv/src/win/stream.c36
-rw-r--r--Utilities/cmlibuv/src/win/tcp.c258
-rw-r--r--Utilities/cmlibuv/src/win/thread.c252
-rw-r--r--Utilities/cmlibuv/src/win/tty.c306
-rw-r--r--Utilities/cmlibuv/src/win/udp.c146
-rw-r--r--Utilities/cmlibuv/src/win/util.c408
-rw-r--r--Utilities/cmlibuv/src/win/winapi.c59
-rw-r--r--Utilities/cmlibuv/src/win/winapi.h91
-rw-r--r--Utilities/cmlibuv/src/win/winsock.c38
-rw-r--r--Utilities/cmlibuv/src/win/winsock.h3
-rw-r--r--Utilities/cmzlib/CMakeLists.txt2
-rwxr-xr-xbootstrap440
3309 files changed, 133204 insertions, 95383 deletions
diff --git a/.clang-format b/.clang-format
index a8bde417d..162c56d76 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,9 +1,21 @@
---
-# This configuration requires clang-format 3.8 or higher.
+# This configuration requires clang-format version 6.0 exactly.
BasedOnStyle: Mozilla
AlignOperands: false
-AlwaysBreakAfterReturnType: None
+AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterClass: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterStruct: true
+ AfterUnion: true
+BreakBeforeBraces: Custom
ColumnLimit: 79
-Standard: Cpp03
+IndentPPDirectives: AfterHash
+SortUsingDeclarations: false
+SpaceAfterTemplateKeyword: true
...
diff --git a/.clang-tidy b/.clang-tidy
index a9d121aa0..bfcb67ca7 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,30 +1,36 @@
---
Checks: "-*,\
+bugprone-*,\
+-bugprone-macro-parentheses,\
+-bugprone-misplaced-widening-cast,\
+google-readability-casting,\
misc-*,\
-misc-incorrect-roundings,\
-misc-macro-parentheses,\
-misc-misplaced-widening-cast,\
-misc-static-assert,\
-modernize-make-shared,\
-modernize-make-unique,\
-modernize-redundant-void-arg,\
-modernize-use-bool-literals,\
-modernize-use-nullptr,\
-modernize-use-override,\
+modernize-*,\
+-modernize-deprecated-headers,\
+-modernize-return-braced-init-list,\
+-modernize-use-auto,\
+-modernize-use-noexcept,\
+-modernize-use-transparent-functors,\
+-modernize-use-using,\
performance-*,\
-performance-inefficient-string-concatenation,\
readability-*,\
-readability-function-size,\
-readability-identifier-naming,\
-readability-implicit-bool-cast,\
+-readability-implicit-bool-conversion,\
-readability-inconsistent-declaration-parameter-name,\
-readability-named-parameter,\
-readability-redundant-declaration,\
--readability-redundant-member-init,\
--readability-simplify-boolean-expr,\
"
HeaderFilterRegex: 'Source/cm[^/]*\.(h|hxx|cxx)$'
CheckOptions:
- - key: modernize-use-nullptr.NullMacros
- value: 'CM_NULLPTR'
+ - key: modernize-use-default-member-init.UseAssignment
+ value: '1'
+ - key: modernize-use-equals-default.IgnoreMacros
+ value: '0'
...
diff --git a/Auxiliary/bash-completion/cmake b/Auxiliary/bash-completion/cmake
index 0a862fa07..638b1c442 100644
--- a/Auxiliary/bash-completion/cmake
+++ b/Auxiliary/bash-completion/cmake
@@ -96,7 +96,7 @@ _cmake()
_filedir
return
;;
- --build)
+ --build|--install|--open)
_filedir -d
return
;;
@@ -116,6 +116,9 @@ _cmake()
2>/dev/null )' -- "$quoted" ) )
return
;;
+ --loglevel)
+ COMPREPLY=( $(compgen -W 'error warning notice status verbose debug trace' -- $cur ) )
+ ;;
--help-command)
COMPREPLY=( $( compgen -W '$( cmake --help-command-list 2>/dev/null|
grep -v "^cmake version " )' -- "$cur" ) )
diff --git a/Auxiliary/cmake-mode.el b/Auxiliary/cmake-mode.el
index a1b43c5b6..e4fa6c175 100644
--- a/Auxiliary/cmake-mode.el
+++ b/Auxiliary/cmake-mode.el
@@ -55,7 +55,7 @@ set the path with these commands:
(* (or (not (any space "()#\\\n")) (and ?\\ nonl)))))
(defconst cmake-regex-token
(rx-to-string `(group (or (regexp ,cmake-regex-comment)
- ?( ?)
+ ?\( ?\)
(regexp ,cmake-regex-argument-unquoted)
(regexp ,cmake-regex-argument-quoted)))))
(defconst cmake-regex-indented
@@ -352,7 +352,7 @@ and store the result as a list in LISTVAR."
;;;###autoload
(defun cmake-help ()
- "Queries for any of the four available help topics and prints out the approriate page."
+ "Queries for any of the four available help topics and prints out the appropriate page."
(interactive)
(let* ((default-entry (cmake-symbol-at-point))
(command-list (cmake-get-list "command"))
diff --git a/Auxiliary/cmake.m4 b/Auxiliary/cmake.m4
index 7beff41a8..a40c0ae97 100644
--- a/Auxiliary/cmake.m4
+++ b/Auxiliary/cmake.m4
@@ -13,7 +13,7 @@ fi
# $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
+# PathScale, Cray, SCO, 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], [
diff --git a/Auxiliary/vim/cmake.vim.in b/Auxiliary/vim/cmake.vim.in
index 389d9e46e..3471b5455 100644
--- a/Auxiliary/vim/cmake.vim.in
+++ b/Auxiliary/vim/cmake.vim.in
@@ -1,10 +1,13 @@
-" vim: set nowrap:
" Vim syntax file
+" Program: CMake - Cross-Platform Makefile Generator
+" Version: @VERSION@
" Language: CMake
-" Author: Andy Cedilnik <andy.cedilnik@kitware.com>, Nicholas Hutchinson <nshutchinson@gmail.com>, Patrick Boettcher <patrick.boettcher@posteo.de>
-" Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
-" Last Change: $Date$
-" Version: $Revision$
+" Author: Andy Cedilnik <andy.cedilnik@kitware.com>,
+" Nicholas Hutchinson <nshutchinson@gmail.com>,
+" Patrick Boettcher <patrick.boettcher@posteo.de>
+" Maintainer: Dimitri Merejkowsky <d.merej@gmail.com>
+" Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
+" Last Change: @DATE@
"
" Licence: The CMake license applies to this file. See
" https://cmake.org/licensing
@@ -13,27 +16,31 @@
if exists("b:current_syntax")
finish
endif
+let s:keepcpo= &cpo
+set cpo&vim
+
+syn region cmakeBracketArgument start="\[\z(=\?\|=[0-9]*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell
syn region cmakeComment start="#" end="$" contains=cmakeTodo,@Spell
-syn region cmakeLuaComment start="\[\z(=*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell
+syn region cmakeBracketComment start="#\[\z(=\?\|=[0-9]*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell
syn match cmakeEscaped /\(\\\\\|\\"\|\\n\|\\t\)/ contained
syn region cmakeRegistry start="\[" end="]" contained oneline contains=cmakeTodo,cmakeEscaped
syn region cmakeGeneratorExpression start="$<" end=">" contained oneline contains=cmakeVariableValue,cmakeProperty,cmakeGeneratorExpressions,cmakeTodo
-syn region cmakeString start='"' end='"' contained contains=cmakeTodo,cmakeVariableValue
+syn region cmakeString start='"' end='"' contained contains=cmakeTodo,cmakeVariableValue,cmakeEscaped
-syn region cmakeVariableValue start="${" end="}" contained oneline contains=cmakeVariable,cmakeTodo
+syn region cmakeVariableValue start="${" end="}" contained oneline contains=cmakeVariable,cmakeTodo,cmakeVariableValue
syn region cmakeEnvironment start="$ENV{" end="}" contained oneline contains=cmakeTodo
-syn region cmakeArguments start="(" end=")" contains=ALLBUT,cmakeArguments,cmakeTodo
+syn region cmakeArguments start="(" end=")" contains=ALLBUT,cmakeGeneratorExpressions,cmakeCommand,cmakeCommandConditional,cmakeCommandRepeat,cmakeCommandDeprecated,cmakeCommandManuallyAdded,cmakeArguments,cmakeTodo
syn case match
syn keyword cmakeProperty contained
- \ ABSTRACT ADDITIONAL_MAKE_CLEAN_FILES ADVANCED ALIASED_TARGET ALLOW_DUPLICATE_CUSTOM_TARGETS ANDROID_ANT_ADDITIONAL_OPTIONS ANDROID_API ANDROID_API_MIN ANDROID_ARCH ANDROID_ASSETS_DIRECTORIES ANDROID_GUI ANDROID_JAR_DEPENDENCIES ANDROID_JAR_DIRECTORIES ANDROID_JAVA_SOURCE_DIR ANDROID_NATIVE_LIB_DEPENDENCIES ANDROID_NATIVE_LIB_DIRECTORIES ANDROID_PROCESS_MAX ANDROID_PROGUARD ANDROID_PROGUARD_CONFIG_PATH ANDROID_SECURE_PROPS_PATH ANDROID_SKIP_ANT_STEP ANDROID_STL_TYPE ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_DEBUG ARCHIVE_OUTPUT_DIRECTORY_RELEASE ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_DEBUG ARCHIVE_OUTPUT_NAME_RELEASE ATTACHED_FILES ATTACHED_FILES_ON_FAIL AUTOGEN_TARGETS_FOLDER AUTOGEN_TARGET_DEPENDS AUTOMOC AUTOMOC_MOC_OPTIONS AUTOMOC_TARGETS_FOLDER AUTORCC AUTORCC_OPTIONS AUTOUIC AUTOUIC_OPTIONS BINARY_DIR BUILD_WITH_INSTALL_RPATH BUNDLE BUNDLE_EXTENSION CACHE_VARIABLES CLEAN_NO_CUSTOM CMAKE_CONFIGURE_DEPENDS CMAKE_CXX_KNOWN_FEATURES CMAKE_C_KNOWN_FEATURES COMPATIBLE_INTERFACE_BOOL COMPATIBLE_INTERFACE_NUMBER_MAX COMPATIBLE_INTERFACE_NUMBER_MIN COMPATIBLE_INTERFACE_STRING COMPILE_DEFINITIONS COMPILE_DEFINITIONS_DEBUG COMPILE_DEFINITIONS_RELEASE COMPILE_FEATURES COMPILE_FLAGS COMPILE_OPTIONS COMPILE_PDB_NAME COMPILE_PDB_NAME_DEBUG COMPILE_PDB_NAME_RELEASE COMPILE_PDB_OUTPUT_DIRECTORY COMPILE_PDB_OUTPUT_DIRECTORY_DEBUG COMPILE_PDB_OUTPUT_DIRECTORY_RELEASE COST CPACK_DESKTOP_SHORTCUTS CPACK_NEVER_OVERWRITE CPACK_PERMANENT CPACK_STARTUP_SHORTCUTS CPACK_START_MENU_SHORTCUTS CPACK_WIX_ACL CROSSCOMPILING_EMULATOR CXX_EXTENSIONS CXX_STANDARD CXX_STANDARD_REQUIRED C_EXTENSIONS C_STANDARD C_STANDARD_REQUIRED DEBUG_CONFIGURATIONS DEBUG_POSTFIX DEFINE_SYMBOL DEFINITIONS DEPENDS DISABLED_FEATURES ECLIPSE_EXTRA_NATURES ENABLED_FEATURES ENABLED_LANGUAGES ENABLE_EXPORTS ENVIRONMENT EXCLUDE_FROM_ALL EXCLUDE_FROM_DEFAULT_BUILD EXCLUDE_FROM_DEFAULT_BUILD_DEBUG EXCLUDE_FROM_DEFAULT_BUILD_RELEASE EXPORT_NAME EXTERNAL_OBJECT EchoString FAIL_REGULAR_EXPRESSION FIND_LIBRARY_USE_LIB64_PATHS FIND_LIBRARY_USE_OPENBSD_VERSIONING FOLDER FRAMEWORK FRAMEWORK_VERSION Fortran_FORMAT Fortran_MODULE_DIRECTORY GENERATED GENERATOR_FILE_NAME GLOBAL_DEPENDS_DEBUG_MODE GLOBAL_DEPENDS_NO_CYCLES GNUtoMS HAS_CXX HEADER_FILE_ONLY HELPSTRING IMPLICIT_DEPENDS_INCLUDE_TRANSFORM IMPORTED IMPORTED_CONFIGURATIONS IMPORTED_IMPLIB IMPORTED_IMPLIB_DEBUG IMPORTED_IMPLIB_RELEASE IMPORTED_LINK_DEPENDENT_LIBRARIES IMPORTED_LINK_DEPENDENT_LIBRARIES_DEBUG IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_LANGUAGES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE IMPORTED_LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_MULTIPLICITY IMPORTED_LINK_INTERFACE_MULTIPLICITY_DEBUG IMPORTED_LINK_INTERFACE_MULTIPLICITY_RELEASE IMPORTED_LOCATION IMPORTED_LOCATION_DEBUG IMPORTED_LOCATION_RELEASE IMPORTED_NO_SONAME IMPORTED_NO_SONAME_DEBUG IMPORTED_NO_SONAME_RELEASE IMPORTED_SONAME IMPORTED_SONAME_DEBUG IMPORTED_SONAME_RELEASE IMPORT_PREFIX IMPORT_SUFFIX INCLUDE_DIRECTORIES INCLUDE_REGULAR_EXPRESSION INSTALL_NAME_DIR INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH INTERFACE_AUTOUIC_OPTIONS INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_FEATURES INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES INTERFACE_POSITION_INDEPENDENT_CODE INTERFACE_SOURCES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_DEBUG INTERPROCEDURAL_OPTIMIZATION_RELEASE IN_TRY_COMPILE JOB_POOLS JOB_POOL_COMPILE JOB_POOL_LINK KEEP_EXTENSION LABELS LANGUAGE LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_DEBUG LIBRARY_OUTPUT_DIRECTORY_RELEASE LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_DEBUG LIBRARY_OUTPUT_NAME_RELEASE LINKER_LANGUAGE LINK_DEPENDS LINK_DEPENDS_NO_SHARED LINK_DIRECTORIES LINK_FLAGS LINK_FLAGS_DEBUG LINK_FLAGS_RELEASE LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_DEBUG LINK_INTERFACE_LIBRARIES_RELEASE LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_DEBUG LINK_INTERFACE_MULTIPLICITY_RELEASE LINK_LIBRARIES LINK_SEARCH_END_STATIC LINK_SEARCH_START_STATIC LISTFILE_STACK LOCATION LOCATION_DEBUG LOCATION_RELEASE MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST MACOSX_PACKAGE_LOCATION MACOSX_RPATH MACROS MAP_IMPORTED_CONFIG_DEBUG MAP_IMPORTED_CONFIG_RELEASE MEASUREMENT MODIFIED NAME NO_SONAME NO_SYSTEM_FROM_IMPORTED OBJECT_DEPENDS OBJECT_OUTPUTS OSX_ARCHITECTURES OSX_ARCHITECTURES_DEBUG OSX_ARCHITECTURES_RELEASE OUTPUT_NAME OUTPUT_NAME_DEBUG OUTPUT_NAME_RELEASE PACKAGES_FOUND PACKAGES_NOT_FOUND PARENT_DIRECTORY PASS_REGULAR_EXPRESSION PDB_NAME PDB_NAME_DEBUG PDB_NAME_RELEASE PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_DEBUG PDB_OUTPUT_DIRECTORY_RELEASE POSITION_INDEPENDENT_CODE POST_INSTALL_SCRIPT PREDEFINED_TARGETS_FOLDER PREFIX PRE_INSTALL_SCRIPT PRIVATE_HEADER PROCESSORS PROJECT_LABEL PUBLIC_HEADER REPORT_UNDEFINED_PROPERTIES REQUIRED_FILES RESOURCE RESOURCE_LOCK RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK RULE_MESSAGES RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_DEBUG RUNTIME_OUTPUT_DIRECTORY_RELEASE RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_DEBUG RUNTIME_OUTPUT_NAME_RELEASE RUN_SERIAL SKIP_BUILD_RPATH SKIP_RETURN_CODE SOURCES SOURCE_DIR SOVERSION STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_DEBUG STATIC_LIBRARY_FLAGS_RELEASE STRINGS SUFFIX SYMBOLIC TARGET_ARCHIVES_MAY_BE_SHARED_LIBS TARGET_MESSAGES TARGET_SUPPORTS_SHARED_LIBS TEST_INCLUDE_FILE TIMEOUT TYPE USE_FOLDERS VALUE VARIABLES VERSION VISIBILITY_INLINES_HIDDEN VS_DEPLOYMENT_CONTENT VS_DEPLOYMENT_LOCATION VS_DESKTOP_EXTENSIONS_VERSION VS_DOTNET_REFERENCES VS_DOTNET_TARGET_FRAMEWORK_VERSION VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_GLOBAL_ROOTNAMESPACE VS_IOT_EXTENSIONS_VERSION VS_IOT_STARTUP_TASK VS_KEYWORD VS_MOBILE_EXTENSIONS_VERSION VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER VS_SHADER_ENTRYPOINT VS_SHADER_FLAGS VS_SHADER_MODEL VS_SHADER_TYPE VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION VS_WINRT_COMPONENT VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES VS_XAML_TYPE WILL_FAIL WIN32_EXECUTABLE WINDOWS_EXPORT_ALL_SYMBOLS WORKING_DIRECTORY WRAP_EXCLUDE XCODE_EXPLICIT_FILE_TYPE XCODE_LAST_KNOWN_FILE_TYPE XCTEST
+@PROPERTIES@
syn keyword cmakeVariable contained
@VARIABLE_LIST@
@@ -70,6 +77,8 @@ syn keyword cmakeTodo
\ TODO FIXME XXX
\ contained
+hi def link cmakeBracketArgument String
+hi def link cmakeBracketComment Comment
hi def link cmakeCommand Function
hi def link cmakeCommandConditional Conditional
hi def link cmakeCommandDeprecated WarningMsg
@@ -79,7 +88,6 @@ hi def link cmakeEnvironment Special
hi def link cmakeEscaped Special
hi def link cmakeGeneratorExpression WarningMsg
hi def link cmakeGeneratorExpressions Constant
-hi def link cmakeLuaComment Comment
hi def link cmakeModule Include
hi def link cmakeProperty Constant
hi def link cmakeRegistry Underlined
@@ -90,4 +98,33 @@ hi def link cmakeVariable Identifier
@KEYWORDS_HIGHLIGHT@
+" Manually added - difficult to parse out of documentation
+syn case ignore
+
+syn keyword cmakeCommandManuallyAdded
+ \ configure_package_config_file write_basic_package_version_file
+ \ nextgroup=cmakeArguments
+
+syn case match
+
+syn keyword cmakeKWconfigure_package_config_file contained
+ \ INSTALL_DESTINATION PATH_VARS NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO INSTALL_PREFIX
+
+syn keyword cmakeKWconfigure_package_config_file_constants contained
+ \ AnyNewerVersion SameMajorVersion SameMinorVersion ExactVersion
+
+syn keyword cmakeKWwrite_basic_package_version_file contained
+ \ VERSION COMPATIBILITY
+
+hi def link cmakeCommandManuallyAdded Function
+
+hi def link cmakeKWconfigure_package_config_file ModeMsg
+hi def link cmakeKWwrite_basic_package_version_file ModeMsg
+hi def link cmakeKWconfigure_package_config_file_constants Constant
+
let b:current_syntax = "cmake"
+
+let &cpo = s:keepcpo
+unlet s:keepcpo
+
+" vim: set nowrap:
diff --git a/Auxiliary/vim/extract-upper-case.pl b/Auxiliary/vim/extract-upper-case.pl
index ea77cbb5c..204b49662 100755
--- a/Auxiliary/vim/extract-upper-case.pl
+++ b/Auxiliary/vim/extract-upper-case.pl
@@ -2,6 +2,7 @@
use strict;
use warnings;
+use POSIX qw(strftime);
#my $cmake = "/home/pboettch/devel/upstream/cmake/build/bin/cmake";
my $cmake = "cmake";
@@ -12,6 +13,9 @@ my @properties;
my @modules;
my %keywords; # command => keyword-list
+# find cmake/Modules/ | sed -rn 's/.*CMakeDetermine(.+)Compiler.cmake/\1/p' | sort
+my @languages = qw(ASM ASM_MASM ASM_NASM C CSharp CUDA CXX Fortran Java RC Swift);
+
# unwanted upper-cases
my %unwanted = map { $_ => 1 } qw(VS CXX IDE NOTFOUND NO_ DFOO DBAR NEW);
# cannot remove ALL - exists for add_custom_command
@@ -30,7 +34,20 @@ push @modules, "ExternalProject";
open(CMAKE, "$cmake --help-variable-list|") or die "could not run cmake";
while (<CMAKE>) {
chomp;
- next if /\</; # skip VARIABLES which contained <>-"templates"
+
+ if (/<(.*?)>/) {
+ if ($1 eq 'LANG') {
+ foreach my $lang (@languages) {
+ (my $V = $_) =~ s/<.*>/$lang/;
+ push @variables, $V;
+ }
+
+ next
+ } else {
+ next; # skip if containing < or >
+ }
+ }
+
push @variables, $_;
}
close(CMAKE);
@@ -70,11 +87,24 @@ my @generator_expr = extract_upper("$cmake --help-manual cmake-generator-express
# properties
open(CMAKE, "$cmake --help-property-list|");
while (<CMAKE>) {
+ next if /\</; # skip if containing < or >
chomp;
push @properties, $_;
}
close(CMAKE);
+# transform all properties in a hash
+my %properties = map { $_ => 1 } @properties;
+
+# version
+open(CMAKE, "$cmake --version|");
+my $version = 'unknown';
+while (<CMAKE>) {
+ chomp;
+ $version = $_ if /cmake version/;
+}
+close(CMAKE);
+
# generate cmake.vim
open(IN, "<cmake.vim.in") or die "could not read cmake.vim.in";
open(OUT, ">syntax/cmake.vim") or die "could not write to syntax/cmake.vim";
@@ -89,28 +119,37 @@ while(<IN>)
my @tmp = grep { ! exists $conditional{$_} and
! exists $loop{$_} and
! exists $deprecated{$_} } @commands;
- print OUT " " x 12 , "\\ ", join(" ", @tmp), "\n";
+ print_list(\*OUT, @tmp);
} elsif ($1 eq "VARIABLE_LIST") {
- print OUT " " x 12 , "\\ ", join(" ", sort keys %variables), "\n";
+ print_list(\*OUT, keys %variables);
} elsif ($1 eq "MODULES") {
- print OUT " " x 12 , "\\ ", join("\n", @modules), "\n";
+ print_list(\*OUT, @modules);
} elsif ($1 eq "GENERATOR_EXPRESSIONS") {
- print OUT " " x 12 , "\\ ", join(" ", @generator_expr), "\n";
+ print_list(\*OUT, @generator_expr);
} elsif ($1 eq "CONDITIONALS") {
- print OUT " " x 12 , "\\ ", join(" ", sort keys %conditional), "\n";
+ print_list(\*OUT, keys %conditional);
} elsif ($1 eq "LOOPS") {
- print OUT " " x 12 , "\\ ", join(" ", sort keys %loop), "\n";
+ print_list(\*OUT, keys %loop);
} elsif ($1 eq "DEPRECATED") {
- print OUT " " x 12 , "\\ ", join(" ", sort keys %deprecated), "\n";
+ print_list(\*OUT, keys %deprecated);
+ } elsif ($1 eq "PROPERTIES") {
+ print_list(\*OUT, keys %properties);
} elsif ($1 eq "KEYWORDS") {
foreach my $k (sort keys %keywords) {
print OUT "syn keyword cmakeKW$k contained\n";
- print OUT " " x 12, "\\ ", join(" ", @{$keywords{$k}}), "\n";
+ print_list(\*OUT, @{$keywords{$k}});
print OUT "\n";
push @keyword_hi, "hi def link cmakeKW$k ModeMsg";
}
} elsif ($1 eq "KEYWORDS_HIGHLIGHT") {
print OUT join("\n", @keyword_hi), "\n";
+ } elsif ($1 eq "VERSION") {
+ $_ =~ s/\@VERSION\@/$version/;
+ print OUT $_;
+ } elsif ($1 eq "DATE") {
+ my $date = strftime "%Y %b %d", localtime;
+ $_ =~ s/\@DATE\@/$date/;
+ print OUT $_;
} else {
print "ERROR do not know how to replace $1\n";
}
@@ -128,7 +167,6 @@ sub extract_upper
open(KW, $input);
while (<KW>) {
-
foreach my $w (m/\b([A-Z_]{2,})\b/g) {
next
if exists $variables{$w} or # skip if it is a variable
@@ -142,3 +180,10 @@ sub extract_upper
return @word;
}
+
+sub print_list
+{
+ my $O = shift;
+ my $indent = " " x 12 . "\\ ";
+ print $O $indent, join("\n" . $indent, sort @_), "\n";
+}
diff --git a/Auxiliary/vim/indent/cmake.vim b/Auxiliary/vim/indent/cmake.vim
index 76aff64a6..33e583d62 100644
--- a/Auxiliary/vim/indent/cmake.vim
+++ b/Auxiliary/vim/indent/cmake.vim
@@ -1,9 +1,9 @@
" 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$
+" Maintainer: Dimitri Merejkowsky <d.merej@gmail.com>
+" Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
+" Last Change: 2017 Aug 30
"
" Licence: The CMake license applies to this file. See
" https://cmake.org/licensing
@@ -14,6 +14,9 @@ if exists("b:did_indent")
endif
let b:did_indent = 1
+let s:keepcpo= &cpo
+set cpo&vim
+
setlocal indentexpr=CMakeGetIndent(v:lnum)
setlocal indentkeys+==ENDIF(,ENDFOREACH(,ENDMACRO(,ELSE(,ELSEIF(,ENDWHILE(
@@ -64,20 +67,23 @@ fun! CMakeGetIndent(lnum)
let ind = ind
else
if previous_line =~? cmake_indent_begin_regex
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
if previous_line =~? cmake_indent_open_regex
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
endif
" Subtract
if this_line =~? cmake_indent_end_regex
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
if previous_line =~? cmake_indent_close_regex
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
endfun
+
+let &cpo = s:keepcpo
+unlet s:keepcpo
diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim
index a191c1872..cd8385b67 100644
--- a/Auxiliary/vim/syntax/cmake.vim
+++ b/Auxiliary/vim/syntax/cmake.vim
@@ -1,10 +1,13 @@
-" vim: set nowrap:
" Vim syntax file
+" Program: CMake - Cross-Platform Makefile Generator
+" Version: cmake version 3.14.20190529-g067a4f
" Language: CMake
-" Author: Andy Cedilnik <andy.cedilnik@kitware.com>, Nicholas Hutchinson <nshutchinson@gmail.com>, Patrick Boettcher <patrick.boettcher@posteo.de>
-" Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
-" Last Change: $Date$
-" Version: $Revision$
+" Author: Andy Cedilnik <andy.cedilnik@kitware.com>,
+" Nicholas Hutchinson <nshutchinson@gmail.com>,
+" Patrick Boettcher <patrick.boettcher@posteo.de>
+" Maintainer: Dimitri Merejkowsky <d.merej@gmail.com>
+" Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com>
+" Last Change: 2019 May 29
"
" Licence: The CMake license applies to this file. See
" https://cmake.org/licensing
@@ -13,333 +16,3185 @@
if exists("b:current_syntax")
finish
endif
+let s:keepcpo= &cpo
+set cpo&vim
+
+syn region cmakeBracketArgument start="\[\z(=\?\|=[0-9]*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell
syn region cmakeComment start="#" end="$" contains=cmakeTodo,@Spell
-syn region cmakeLuaComment start="\[\z(=*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell
+syn region cmakeBracketComment start="#\[\z(=\?\|=[0-9]*\)\[" end="\]\z1\]" contains=cmakeTodo,@Spell
syn match cmakeEscaped /\(\\\\\|\\"\|\\n\|\\t\)/ contained
syn region cmakeRegistry start="\[" end="]" contained oneline contains=cmakeTodo,cmakeEscaped
syn region cmakeGeneratorExpression start="$<" end=">" contained oneline contains=cmakeVariableValue,cmakeProperty,cmakeGeneratorExpressions,cmakeTodo
-syn region cmakeString start='"' end='"' contained contains=cmakeTodo,cmakeVariableValue
+syn region cmakeString start='"' end='"' contained contains=cmakeTodo,cmakeVariableValue,cmakeEscaped
-syn region cmakeVariableValue start="${" end="}" contained oneline contains=cmakeVariable,cmakeTodo
+syn region cmakeVariableValue start="${" end="}" contained oneline contains=cmakeVariable,cmakeTodo,cmakeVariableValue
syn region cmakeEnvironment start="$ENV{" end="}" contained oneline contains=cmakeTodo
-syn region cmakeArguments start="(" end=")" contains=ALLBUT,cmakeArguments,cmakeTodo
+syn region cmakeArguments start="(" end=")" contains=ALLBUT,cmakeGeneratorExpressions,cmakeCommand,cmakeCommandConditional,cmakeCommandRepeat,cmakeCommandDeprecated,cmakeCommandManuallyAdded,cmakeArguments,cmakeTodo
syn case match
syn keyword cmakeProperty contained
- \ ABSTRACT ADDITIONAL_MAKE_CLEAN_FILES ADVANCED ALIASED_TARGET ALLOW_DUPLICATE_CUSTOM_TARGETS ANDROID_ANT_ADDITIONAL_OPTIONS ANDROID_API ANDROID_API_MIN ANDROID_ARCH ANDROID_ASSETS_DIRECTORIES ANDROID_GUI ANDROID_JAR_DEPENDENCIES ANDROID_JAR_DIRECTORIES ANDROID_JAVA_SOURCE_DIR ANDROID_NATIVE_LIB_DEPENDENCIES ANDROID_NATIVE_LIB_DIRECTORIES ANDROID_PROCESS_MAX ANDROID_PROGUARD ANDROID_PROGUARD_CONFIG_PATH ANDROID_SECURE_PROPS_PATH ANDROID_SKIP_ANT_STEP ANDROID_STL_TYPE ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_DEBUG ARCHIVE_OUTPUT_DIRECTORY_RELEASE ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_DEBUG ARCHIVE_OUTPUT_NAME_RELEASE ATTACHED_FILES ATTACHED_FILES_ON_FAIL AUTOGEN_TARGETS_FOLDER AUTOGEN_TARGET_DEPENDS AUTOMOC AUTOMOC_MOC_OPTIONS AUTOMOC_TARGETS_FOLDER AUTORCC AUTORCC_OPTIONS AUTOUIC AUTOUIC_OPTIONS BINARY_DIR BUILD_WITH_INSTALL_RPATH BUNDLE BUNDLE_EXTENSION CACHE_VARIABLES CLEAN_NO_CUSTOM CMAKE_CONFIGURE_DEPENDS CMAKE_CXX_KNOWN_FEATURES CMAKE_C_KNOWN_FEATURES COMPATIBLE_INTERFACE_BOOL COMPATIBLE_INTERFACE_NUMBER_MAX COMPATIBLE_INTERFACE_NUMBER_MIN COMPATIBLE_INTERFACE_STRING COMPILE_DEFINITIONS COMPILE_DEFINITIONS_DEBUG COMPILE_DEFINITIONS_RELEASE COMPILE_FEATURES COMPILE_FLAGS COMPILE_OPTIONS COMPILE_PDB_NAME COMPILE_PDB_NAME_DEBUG COMPILE_PDB_NAME_RELEASE COMPILE_PDB_OUTPUT_DIRECTORY COMPILE_PDB_OUTPUT_DIRECTORY_DEBUG COMPILE_PDB_OUTPUT_DIRECTORY_RELEASE COST CPACK_DESKTOP_SHORTCUTS CPACK_NEVER_OVERWRITE CPACK_PERMANENT CPACK_STARTUP_SHORTCUTS CPACK_START_MENU_SHORTCUTS CPACK_WIX_ACL CROSSCOMPILING_EMULATOR CXX_EXTENSIONS CXX_STANDARD CXX_STANDARD_REQUIRED C_EXTENSIONS C_STANDARD C_STANDARD_REQUIRED DEBUG_CONFIGURATIONS DEBUG_POSTFIX DEFINE_SYMBOL DEFINITIONS DEPENDS DISABLED_FEATURES ECLIPSE_EXTRA_NATURES ENABLED_FEATURES ENABLED_LANGUAGES ENABLE_EXPORTS ENVIRONMENT EXCLUDE_FROM_ALL EXCLUDE_FROM_DEFAULT_BUILD EXCLUDE_FROM_DEFAULT_BUILD_DEBUG EXCLUDE_FROM_DEFAULT_BUILD_RELEASE EXPORT_NAME EXTERNAL_OBJECT EchoString FAIL_REGULAR_EXPRESSION FIND_LIBRARY_USE_LIB64_PATHS FIND_LIBRARY_USE_OPENBSD_VERSIONING FOLDER FRAMEWORK FRAMEWORK_VERSION Fortran_FORMAT Fortran_MODULE_DIRECTORY GENERATED GENERATOR_FILE_NAME GLOBAL_DEPENDS_DEBUG_MODE GLOBAL_DEPENDS_NO_CYCLES GNUtoMS HAS_CXX HEADER_FILE_ONLY HELPSTRING IMPLICIT_DEPENDS_INCLUDE_TRANSFORM IMPORTED IMPORTED_CONFIGURATIONS IMPORTED_IMPLIB IMPORTED_IMPLIB_DEBUG IMPORTED_IMPLIB_RELEASE IMPORTED_LINK_DEPENDENT_LIBRARIES IMPORTED_LINK_DEPENDENT_LIBRARIES_DEBUG IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_LANGUAGES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE IMPORTED_LINK_INTERFACE_LIBRARIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE IMPORTED_LINK_INTERFACE_MULTIPLICITY IMPORTED_LINK_INTERFACE_MULTIPLICITY_DEBUG IMPORTED_LINK_INTERFACE_MULTIPLICITY_RELEASE IMPORTED_LOCATION IMPORTED_LOCATION_DEBUG IMPORTED_LOCATION_RELEASE IMPORTED_NO_SONAME IMPORTED_NO_SONAME_DEBUG IMPORTED_NO_SONAME_RELEASE IMPORTED_SONAME IMPORTED_SONAME_DEBUG IMPORTED_SONAME_RELEASE IMPORT_PREFIX IMPORT_SUFFIX INCLUDE_DIRECTORIES INCLUDE_REGULAR_EXPRESSION INSTALL_NAME_DIR INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH INTERFACE_AUTOUIC_OPTIONS INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_FEATURES INTERFACE_COMPILE_OPTIONS INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES INTERFACE_POSITION_INDEPENDENT_CODE INTERFACE_SOURCES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_DEBUG INTERPROCEDURAL_OPTIMIZATION_RELEASE IN_TRY_COMPILE JOB_POOLS JOB_POOL_COMPILE JOB_POOL_LINK KEEP_EXTENSION LABELS LANGUAGE LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_DEBUG LIBRARY_OUTPUT_DIRECTORY_RELEASE LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_DEBUG LIBRARY_OUTPUT_NAME_RELEASE LINKER_LANGUAGE LINK_DEPENDS LINK_DEPENDS_NO_SHARED LINK_DIRECTORIES LINK_FLAGS LINK_FLAGS_DEBUG LINK_FLAGS_RELEASE LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_DEBUG LINK_INTERFACE_LIBRARIES_RELEASE LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_DEBUG LINK_INTERFACE_MULTIPLICITY_RELEASE LINK_LIBRARIES LINK_SEARCH_END_STATIC LINK_SEARCH_START_STATIC LISTFILE_STACK LOCATION LOCATION_DEBUG LOCATION_RELEASE MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST MACOSX_PACKAGE_LOCATION MACOSX_RPATH MACROS MAP_IMPORTED_CONFIG_DEBUG MAP_IMPORTED_CONFIG_RELEASE MEASUREMENT MODIFIED NAME NO_SONAME NO_SYSTEM_FROM_IMPORTED OBJECT_DEPENDS OBJECT_OUTPUTS OSX_ARCHITECTURES OSX_ARCHITECTURES_DEBUG OSX_ARCHITECTURES_RELEASE OUTPUT_NAME OUTPUT_NAME_DEBUG OUTPUT_NAME_RELEASE PACKAGES_FOUND PACKAGES_NOT_FOUND PARENT_DIRECTORY PASS_REGULAR_EXPRESSION PDB_NAME PDB_NAME_DEBUG PDB_NAME_RELEASE PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_DEBUG PDB_OUTPUT_DIRECTORY_RELEASE POSITION_INDEPENDENT_CODE POST_INSTALL_SCRIPT PREDEFINED_TARGETS_FOLDER PREFIX PRE_INSTALL_SCRIPT PRIVATE_HEADER PROCESSORS PROJECT_LABEL PUBLIC_HEADER REPORT_UNDEFINED_PROPERTIES REQUIRED_FILES RESOURCE RESOURCE_LOCK RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK RULE_MESSAGES RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_DEBUG RUNTIME_OUTPUT_DIRECTORY_RELEASE RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_DEBUG RUNTIME_OUTPUT_NAME_RELEASE RUN_SERIAL SKIP_BUILD_RPATH SKIP_RETURN_CODE SOURCES SOURCE_DIR SOVERSION STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_DEBUG STATIC_LIBRARY_FLAGS_RELEASE STRINGS SUFFIX SYMBOLIC TARGET_ARCHIVES_MAY_BE_SHARED_LIBS TARGET_MESSAGES TARGET_SUPPORTS_SHARED_LIBS TEST_INCLUDE_FILE TIMEOUT TYPE USE_FOLDERS VALUE VARIABLES VERSION VISIBILITY_INLINES_HIDDEN VS_DEPLOYMENT_CONTENT VS_DEPLOYMENT_LOCATION VS_DESKTOP_EXTENSIONS_VERSION VS_DOTNET_REFERENCES VS_DOTNET_TARGET_FRAMEWORK_VERSION VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_GLOBAL_ROOTNAMESPACE VS_IOT_EXTENSIONS_VERSION VS_IOT_STARTUP_TASK VS_KEYWORD VS_MOBILE_EXTENSIONS_VERSION VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER VS_SHADER_ENTRYPOINT VS_SHADER_FLAGS VS_SHADER_MODEL VS_SHADER_TYPE VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION VS_WINRT_COMPONENT VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES VS_XAML_TYPE WILL_FAIL WIN32_EXECUTABLE WINDOWS_EXPORT_ALL_SYMBOLS WORKING_DIRECTORY WRAP_EXCLUDE XCODE_EXPLICIT_FILE_TYPE XCODE_LAST_KNOWN_FILE_TYPE XCTEST
+ \ ABSTRACT
+ \ ADDITIONAL_CLEAN_FILES
+ \ ADDITIONAL_MAKE_CLEAN_FILES
+ \ ADVANCED
+ \ ALIASED_TARGET
+ \ ALLOW_DUPLICATE_CUSTOM_TARGETS
+ \ ANDROID_ANT_ADDITIONAL_OPTIONS
+ \ ANDROID_API
+ \ ANDROID_API_MIN
+ \ ANDROID_ARCH
+ \ ANDROID_ASSETS_DIRECTORIES
+ \ ANDROID_GUI
+ \ ANDROID_JAR_DEPENDENCIES
+ \ ANDROID_JAR_DIRECTORIES
+ \ ANDROID_JAVA_SOURCE_DIR
+ \ ANDROID_NATIVE_LIB_DEPENDENCIES
+ \ ANDROID_NATIVE_LIB_DIRECTORIES
+ \ ANDROID_PROCESS_MAX
+ \ ANDROID_PROGUARD
+ \ ANDROID_PROGUARD_CONFIG_PATH
+ \ ANDROID_SECURE_PROPS_PATH
+ \ ANDROID_SKIP_ANT_STEP
+ \ ANDROID_STL_TYPE
+ \ ARCHIVE_OUTPUT_DIRECTORY
+ \ ARCHIVE_OUTPUT_NAME
+ \ ATTACHED_FILES
+ \ ATTACHED_FILES_ON_FAIL
+ \ AUTOGEN_BUILD_DIR
+ \ AUTOGEN_ORIGIN_DEPENDS
+ \ AUTOGEN_PARALLEL
+ \ AUTOGEN_SOURCE_GROUP
+ \ AUTOGEN_TARGETS_FOLDER
+ \ AUTOGEN_TARGET_DEPENDS
+ \ AUTOMOC
+ \ AUTOMOC_COMPILER_PREDEFINES
+ \ AUTOMOC_DEPEND_FILTERS
+ \ AUTOMOC_EXECUTABLE
+ \ AUTOMOC_MACRO_NAMES
+ \ AUTOMOC_MOC_OPTIONS
+ \ AUTOMOC_SOURCE_GROUP
+ \ AUTOMOC_TARGETS_FOLDER
+ \ AUTORCC
+ \ AUTORCC_EXECUTABLE
+ \ AUTORCC_OPTIONS
+ \ AUTORCC_SOURCE_GROUP
+ \ AUTOUIC
+ \ AUTOUIC_EXECUTABLE
+ \ AUTOUIC_OPTIONS
+ \ AUTOUIC_SEARCH_PATHS
+ \ BINARY_DIR
+ \ BUILDSYSTEM_TARGETS
+ \ BUILD_RPATH
+ \ BUILD_RPATH_USE_ORIGIN
+ \ BUILD_WITH_INSTALL_NAME_DIR
+ \ BUILD_WITH_INSTALL_RPATH
+ \ BUNDLE
+ \ BUNDLE_EXTENSION
+ \ CACHE_VARIABLES
+ \ CLEAN_NO_CUSTOM
+ \ CMAKE_CONFIGURE_DEPENDS
+ \ CMAKE_CXX_KNOWN_FEATURES
+ \ CMAKE_C_KNOWN_FEATURES
+ \ CMAKE_ROLE
+ \ COMMON_LANGUAGE_RUNTIME
+ \ COMPATIBLE_INTERFACE_BOOL
+ \ COMPATIBLE_INTERFACE_NUMBER_MAX
+ \ COMPATIBLE_INTERFACE_NUMBER_MIN
+ \ COMPATIBLE_INTERFACE_STRING
+ \ COMPILE_DEFINITIONS
+ \ COMPILE_FEATURES
+ \ COMPILE_FLAGS
+ \ COMPILE_OPTIONS
+ \ COMPILE_PDB_NAME
+ \ COMPILE_PDB_OUTPUT_DIRECTORY
+ \ COST
+ \ CPACK_DESKTOP_SHORTCUTS
+ \ CPACK_NEVER_OVERWRITE
+ \ CPACK_PERMANENT
+ \ CPACK_STARTUP_SHORTCUTS
+ \ CPACK_START_MENU_SHORTCUTS
+ \ CPACK_WIX_ACL
+ \ CROSSCOMPILING_EMULATOR
+ \ CUDA_EXTENSIONS
+ \ CUDA_PTX_COMPILATION
+ \ CUDA_RESOLVE_DEVICE_SYMBOLS
+ \ CUDA_SEPARABLE_COMPILATION
+ \ CUDA_STANDARD
+ \ CUDA_STANDARD_REQUIRED
+ \ CXX_EXTENSIONS
+ \ CXX_STANDARD
+ \ CXX_STANDARD_REQUIRED
+ \ C_EXTENSIONS
+ \ C_STANDARD
+ \ C_STANDARD_REQUIRED
+ \ DEBUG_CONFIGURATIONS
+ \ DEBUG_POSTFIX
+ \ DEFINE_SYMBOL
+ \ DEFINITIONS
+ \ DEPENDS
+ \ DEPLOYMENT_ADDITIONAL_FILES
+ \ DEPLOYMENT_REMOTE_DIRECTORY
+ \ DISABLED
+ \ DISABLED_FEATURES
+ \ DOTNET_TARGET_FRAMEWORK_VERSION
+ \ ECLIPSE_EXTRA_CPROJECT_CONTENTS
+ \ ECLIPSE_EXTRA_NATURES
+ \ ENABLED_FEATURES
+ \ ENABLED_LANGUAGES
+ \ ENABLE_EXPORTS
+ \ ENVIRONMENT
+ \ EXCLUDE_FROM_ALL
+ \ EXCLUDE_FROM_DEFAULT_BUILD
+ \ EXPORT_NAME
+ \ EXPORT_PROPERTIES
+ \ EXTERNAL_OBJECT
+ \ EchoString
+ \ FAIL_REGULAR_EXPRESSION
+ \ FIND_LIBRARY_USE_LIB32_PATHS
+ \ FIND_LIBRARY_USE_LIB64_PATHS
+ \ FIND_LIBRARY_USE_LIBX32_PATHS
+ \ FIND_LIBRARY_USE_OPENBSD_VERSIONING
+ \ FIXTURES_CLEANUP
+ \ FIXTURES_REQUIRED
+ \ FIXTURES_SETUP
+ \ FOLDER
+ \ FRAMEWORK
+ \ FRAMEWORK_VERSION
+ \ Fortran_FORMAT
+ \ Fortran_MODULE_DIRECTORY
+ \ GENERATED
+ \ GENERATOR_FILE_NAME
+ \ GENERATOR_IS_MULTI_CONFIG
+ \ GHS_INTEGRITY_APP
+ \ GHS_NO_SOURCE_GROUP_FILE
+ \ GLOBAL_DEPENDS_DEBUG_MODE
+ \ GLOBAL_DEPENDS_NO_CYCLES
+ \ GNUtoMS
+ \ HAS_CXX
+ \ HEADER_FILE_ONLY
+ \ HELPSTRING
+ \ IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+ \ IMPORTED
+ \ IMPORTED_COMMON_LANGUAGE_RUNTIME
+ \ IMPORTED_CONFIGURATIONS
+ \ IMPORTED_GLOBAL
+ \ IMPORTED_IMPLIB
+ \ IMPORTED_LIBNAME
+ \ IMPORTED_LINK_DEPENDENT_LIBRARIES
+ \ IMPORTED_LINK_INTERFACE_LANGUAGES
+ \ IMPORTED_LINK_INTERFACE_LIBRARIES
+ \ IMPORTED_LINK_INTERFACE_MULTIPLICITY
+ \ IMPORTED_LOCATION
+ \ IMPORTED_NO_SONAME
+ \ IMPORTED_OBJECTS
+ \ IMPORTED_SONAME
+ \ IMPORT_PREFIX
+ \ IMPORT_SUFFIX
+ \ INCLUDE_DIRECTORIES
+ \ INCLUDE_REGULAR_EXPRESSION
+ \ INSTALL_NAME_DIR
+ \ INSTALL_RPATH
+ \ INSTALL_RPATH_USE_LINK_PATH
+ \ INTERFACE_AUTOUIC_OPTIONS
+ \ INTERFACE_COMPILE_DEFINITIONS
+ \ INTERFACE_COMPILE_FEATURES
+ \ INTERFACE_COMPILE_OPTIONS
+ \ INTERFACE_INCLUDE_DIRECTORIES
+ \ INTERFACE_LINK_DEPENDS
+ \ INTERFACE_LINK_DIRECTORIES
+ \ INTERFACE_LINK_LIBRARIES
+ \ INTERFACE_LINK_OPTIONS
+ \ INTERFACE_POSITION_INDEPENDENT_CODE
+ \ INTERFACE_SOURCES
+ \ INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
+ \ INTERPROCEDURAL_OPTIMIZATION
+ \ IN_TRY_COMPILE
+ \ IOS_INSTALL_COMBINED
+ \ JOB_POOLS
+ \ JOB_POOL_COMPILE
+ \ JOB_POOL_LINK
+ \ KEEP_EXTENSION
+ \ LABELS
+ \ LANGUAGE
+ \ LIBRARY_OUTPUT_DIRECTORY
+ \ LIBRARY_OUTPUT_NAME
+ \ LINKER_LANGUAGE
+ \ LINK_DEPENDS
+ \ LINK_DEPENDS_NO_SHARED
+ \ LINK_DIRECTORIES
+ \ LINK_FLAGS
+ \ LINK_INTERFACE_LIBRARIES
+ \ LINK_INTERFACE_MULTIPLICITY
+ \ LINK_LIBRARIES
+ \ LINK_OPTIONS
+ \ LINK_SEARCH_END_STATIC
+ \ LINK_SEARCH_START_STATIC
+ \ LINK_WHAT_YOU_USE
+ \ LISTFILE_STACK
+ \ LOCATION
+ \ MACOSX_BUNDLE
+ \ MACOSX_BUNDLE_INFO_PLIST
+ \ MACOSX_FRAMEWORK_INFO_PLIST
+ \ MACOSX_PACKAGE_LOCATION
+ \ MACOSX_RPATH
+ \ MACROS
+ \ MANUALLY_ADDED_DEPENDENCIES
+ \ MEASUREMENT
+ \ MODIFIED
+ \ MSVC_RUNTIME_LIBRARY
+ \ NAME
+ \ NO_SONAME
+ \ NO_SYSTEM_FROM_IMPORTED
+ \ OBJECT_DEPENDS
+ \ OBJECT_OUTPUTS
+ \ OSX_ARCHITECTURES
+ \ OUTPUT_NAME
+ \ PACKAGES_FOUND
+ \ PACKAGES_NOT_FOUND
+ \ PARENT_DIRECTORY
+ \ PASS_REGULAR_EXPRESSION
+ \ PDB_NAME
+ \ PDB_OUTPUT_DIRECTORY
+ \ POSITION_INDEPENDENT_CODE
+ \ POST_INSTALL_SCRIPT
+ \ PREDEFINED_TARGETS_FOLDER
+ \ PREFIX
+ \ PRE_INSTALL_SCRIPT
+ \ PRIVATE_HEADER
+ \ PROCESSORS
+ \ PROCESSOR_AFFINITY
+ \ PROJECT_LABEL
+ \ PUBLIC_HEADER
+ \ REPORT_UNDEFINED_PROPERTIES
+ \ REQUIRED_FILES
+ \ RESOURCE
+ \ RESOURCE_LOCK
+ \ RULE_LAUNCH_COMPILE
+ \ RULE_LAUNCH_CUSTOM
+ \ RULE_LAUNCH_LINK
+ \ RULE_MESSAGES
+ \ RUNTIME_OUTPUT_DIRECTORY
+ \ RUNTIME_OUTPUT_NAME
+ \ RUN_SERIAL
+ \ SKIP_AUTOGEN
+ \ SKIP_AUTOMOC
+ \ SKIP_AUTORCC
+ \ SKIP_AUTOUIC
+ \ SKIP_BUILD_RPATH
+ \ SKIP_RETURN_CODE
+ \ SOURCES
+ \ SOURCE_DIR
+ \ SOVERSION
+ \ STATIC_LIBRARY_FLAGS
+ \ STATIC_LIBRARY_OPTIONS
+ \ STRINGS
+ \ SUBDIRECTORIES
+ \ SUFFIX
+ \ SYMBOLIC
+ \ Swift_DEPENDENCIES_FILE
+ \ Swift_DIAGNOSTICS_FILE
+ \ Swift_MODULE_DIRECTORY
+ \ Swift_MODULE_NAME
+ \ TARGET_ARCHIVES_MAY_BE_SHARED_LIBS
+ \ TARGET_MESSAGES
+ \ TARGET_SUPPORTS_SHARED_LIBS
+ \ TESTS
+ \ TEST_INCLUDE_FILE
+ \ TEST_INCLUDE_FILES
+ \ TIMEOUT
+ \ TIMEOUT_AFTER_MATCH
+ \ TYPE
+ \ USE_FOLDERS
+ \ VALUE
+ \ VARIABLES
+ \ VERSION
+ \ VISIBILITY_INLINES_HIDDEN
+ \ VS_CONFIGURATION_TYPE
+ \ VS_COPY_TO_OUT_DIR
+ \ VS_DEBUGGER_COMMAND
+ \ VS_DEBUGGER_COMMAND_ARGUMENTS
+ \ VS_DEBUGGER_ENVIRONMENT
+ \ VS_DEBUGGER_WORKING_DIRECTORY
+ \ VS_DEPLOYMENT_CONTENT
+ \ VS_DEPLOYMENT_LOCATION
+ \ VS_DESKTOP_EXTENSIONS_VERSION
+ \ VS_DOTNET_REFERENCES
+ \ VS_DOTNET_REFERENCES_COPY_LOCAL
+ \ VS_DOTNET_TARGET_FRAMEWORK_VERSION
+ \ VS_GLOBAL_KEYWORD
+ \ VS_GLOBAL_PROJECT_TYPES
+ \ VS_GLOBAL_ROOTNAMESPACE
+ \ VS_INCLUDE_IN_VSIX
+ \ VS_IOT_EXTENSIONS_VERSION
+ \ VS_IOT_STARTUP_TASK
+ \ VS_JUST_MY_CODE_DEBUGGING
+ \ VS_KEYWORD
+ \ VS_MOBILE_EXTENSIONS_VERSION
+ \ VS_NO_SOLUTION_DEPLOY
+ \ VS_PROJECT_IMPORT
+ \ VS_RESOURCE_GENERATOR
+ \ VS_SCC_AUXPATH
+ \ VS_SCC_LOCALPATH
+ \ VS_SCC_PROJECTNAME
+ \ VS_SCC_PROVIDER
+ \ VS_SDK_REFERENCES
+ \ VS_SHADER_DISABLE_OPTIMIZATIONS
+ \ VS_SHADER_ENABLE_DEBUG
+ \ VS_SHADER_ENTRYPOINT
+ \ VS_SHADER_FLAGS
+ \ VS_SHADER_MODEL
+ \ VS_SHADER_OBJECT_FILE_NAME
+ \ VS_SHADER_OUTPUT_HEADER_FILE
+ \ VS_SHADER_TYPE
+ \ VS_SHADER_VARIABLE_NAME
+ \ VS_STARTUP_PROJECT
+ \ VS_TOOL_OVERRIDE
+ \ VS_USER_PROPS
+ \ VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION
+ \ VS_WINRT_COMPONENT
+ \ VS_WINRT_EXTENSIONS
+ \ VS_WINRT_REFERENCES
+ \ VS_XAML_TYPE
+ \ WILL_FAIL
+ \ WIN32_EXECUTABLE
+ \ WINDOWS_EXPORT_ALL_SYMBOLS
+ \ WORKING_DIRECTORY
+ \ WRAP_EXCLUDE
+ \ XCODE_EMIT_EFFECTIVE_PLATFORM_NAME
+ \ XCODE_EXPLICIT_FILE_TYPE
+ \ XCODE_FILE_ATTRIBUTES
+ \ XCODE_GENERATE_SCHEME
+ \ XCODE_LAST_KNOWN_FILE_TYPE
+ \ XCODE_PRODUCT_TYPE
+ \ XCODE_SCHEME_ADDRESS_SANITIZER
+ \ XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN
+ \ XCODE_SCHEME_ARGUMENTS
+ \ XCODE_SCHEME_DEBUG_AS_ROOT
+ \ XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER
+ \ XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS
+ \ XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE
+ \ XCODE_SCHEME_ENVIRONMENT
+ \ XCODE_SCHEME_EXECUTABLE
+ \ XCODE_SCHEME_GUARD_MALLOC
+ \ XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP
+ \ XCODE_SCHEME_MALLOC_GUARD_EDGES
+ \ XCODE_SCHEME_MALLOC_SCRIBBLE
+ \ XCODE_SCHEME_MALLOC_STACK
+ \ XCODE_SCHEME_THREAD_SANITIZER
+ \ XCODE_SCHEME_THREAD_SANITIZER_STOP
+ \ XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER
+ \ XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP
+ \ XCODE_SCHEME_ZOMBIE_OBJECTS
+ \ XCTEST
syn keyword cmakeVariable contained
- \ ANDROID APPLE BORLAND BUILD_SHARED_LIBS CMAKE_ABSOLUTE_DESTINATION_FILES CMAKE_ANDROID_ANT_ADDITIONAL_OPTIONS CMAKE_ANDROID_API CMAKE_ANDROID_API_MIN CMAKE_ANDROID_ARCH CMAKE_ANDROID_ARCH_ABI CMAKE_ANDROID_ARM_MODE CMAKE_ANDROID_ARM_NEON CMAKE_ANDROID_ASSETS_DIRECTORIES CMAKE_ANDROID_GUI CMAKE_ANDROID_JAR_DEPENDENCIES CMAKE_ANDROID_JAR_DIRECTORIES CMAKE_ANDROID_JAVA_SOURCE_DIR CMAKE_ANDROID_NATIVE_LIB_DEPENDENCIES CMAKE_ANDROID_NATIVE_LIB_DIRECTORIES CMAKE_ANDROID_NDK CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION CMAKE_ANDROID_PROCESS_MAX CMAKE_ANDROID_PROGUARD CMAKE_ANDROID_PROGUARD_CONFIG_PATH CMAKE_ANDROID_SECURE_PROPS_PATH CMAKE_ANDROID_SKIP_ANT_STEP CMAKE_ANDROID_STANDALONE_TOOLCHAIN CMAKE_ANDROID_STL_TYPE CMAKE_APPBUNDLE_PATH CMAKE_AR CMAKE_ARCHIVE_OUTPUT_DIRECTORY CMAKE_ARGC CMAKE_ARGV0 CMAKE_AUTOMOC CMAKE_AUTOMOC_DEPEND_FILTERS CMAKE_AUTOMOC_MOC_OPTIONS CMAKE_AUTOMOC_RELAXED_MODE CMAKE_AUTORCC CMAKE_AUTORCC_OPTIONS CMAKE_AUTOUIC CMAKE_AUTOUIC_OPTIONS CMAKE_AUTOUIC_SEARCH_PATHS CMAKE_BACKWARDS_COMPATIBILITY CMAKE_BINARY_DIR CMAKE_BUILD_RPATH CMAKE_BUILD_TOOL CMAKE_BUILD_TYPE CMAKE_BUILD_WITH_INSTALL_NAME_DIR CMAKE_BUILD_WITH_INSTALL_RPATH CMAKE_CACHEFILE_DIR CMAKE_CACHE_MAJOR_VERSION CMAKE_CACHE_MINOR_VERSION CMAKE_CACHE_PATCH_VERSION CMAKE_CFG_INTDIR CMAKE_CL_64 CMAKE_CODELITE_USE_TARGETS CMAKE_COLOR_MAKEFILE CMAKE_COMMAND CMAKE_COMPILER_2005 CMAKE_COMPILER_IS_GNUCC CMAKE_COMPILER_IS_GNUCXX CMAKE_COMPILER_IS_GNUG77 CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY CMAKE_CONFIGURATION_TYPES CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR CMAKE_CTEST_COMMAND CMAKE_CUDA_EXTENSIONS CMAKE_CUDA_STANDARD CMAKE_CUDA_STANDARD_REQUIRED CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES CMAKE_CURRENT_BINARY_DIR CMAKE_CURRENT_LIST_DIR CMAKE_CURRENT_LIST_FILE CMAKE_CURRENT_LIST_LINE CMAKE_CURRENT_SOURCE_DIR CMAKE_CXX_COMPILE_FEATURES CMAKE_CXX_EXTENSIONS CMAKE_CXX_STANDARD CMAKE_CXX_STANDARD_REQUIRED CMAKE_C_COMPILE_FEATURES CMAKE_C_EXTENSIONS CMAKE_C_STANDARD CMAKE_C_STANDARD_REQUIRED CMAKE_DEBUG_POSTFIX CMAKE_DEBUG_TARGET_PROPERTIES CMAKE_DEPENDS_IN_PROJECT_ONLY CMAKE_DL_LIBS CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT CMAKE_ECLIPSE_MAKE_ARGUMENTS CMAKE_ECLIPSE_VERSION CMAKE_EDIT_COMMAND CMAKE_ENABLE_EXPORTS CMAKE_ERROR_DEPRECATED CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION CMAKE_EXECUTABLE_SUFFIX CMAKE_EXE_LINKER_FLAGS CMAKE_EXE_LINKER_FLAGS_INIT CMAKE_EXPORT_COMPILE_COMMANDS CMAKE_EXPORT_NO_PACKAGE_REGISTRY CMAKE_EXTRA_GENERATOR CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES CMAKE_FIND_APPBUNDLE CMAKE_FIND_FRAMEWORK CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX CMAKE_FIND_LIBRARY_PREFIXES CMAKE_FIND_LIBRARY_SUFFIXES CMAKE_FIND_NO_INSTALL_PREFIX CMAKE_FIND_PACKAGE_NAME CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY CMAKE_FIND_PACKAGE_SORT_DIRECTION CMAKE_FIND_PACKAGE_SORT_ORDER CMAKE_FIND_PACKAGE_WARN_NO_MODULE CMAKE_FIND_ROOT_PATH CMAKE_FIND_ROOT_PATH_MODE_INCLUDE CMAKE_FIND_ROOT_PATH_MODE_LIBRARY CMAKE_FIND_ROOT_PATH_MODE_PACKAGE CMAKE_FIND_ROOT_PATH_MODE_PROGRAM CMAKE_FRAMEWORK_PATH CMAKE_Fortran_FORMAT CMAKE_Fortran_MODDIR_DEFAULT CMAKE_Fortran_MODDIR_FLAG CMAKE_Fortran_MODOUT_FLAG CMAKE_Fortran_MODULE_DIRECTORY CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM CMAKE_GENERATOR_TOOLSET CMAKE_GNUtoMS CMAKE_HOME_DIRECTORY CMAKE_HOST_APPLE CMAKE_HOST_SOLARIS CMAKE_HOST_SYSTEM CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_UNIX CMAKE_HOST_WIN32 CMAKE_IGNORE_PATH CMAKE_IMPORT_LIBRARY_PREFIX CMAKE_IMPORT_LIBRARY_SUFFIX CMAKE_INCLUDE_CURRENT_DIR CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE CMAKE_INCLUDE_DIRECTORIES_BEFORE CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE CMAKE_INCLUDE_PATH CMAKE_INSTALL_DEFAULT_COMPONENT_NAME CMAKE_INSTALL_MESSAGE CMAKE_INSTALL_NAME_DIR CMAKE_INSTALL_PREFIX CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT CMAKE_INSTALL_RPATH CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_INTERNAL_PLATFORM_ABI CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_IOS_INSTALL_COMBINED CMAKE_JOB_POOL_COMPILE CMAKE_JOB_POOL_LINK CMAKE_LIBRARY_ARCHITECTURE CMAKE_LIBRARY_ARCHITECTURE_REGEX CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_LIBRARY_PATH CMAKE_LIBRARY_PATH_FLAG CMAKE_LINK_DEF_FILE_FLAG CMAKE_LINK_DEPENDS_NO_SHARED CMAKE_LINK_INTERFACE_LIBRARIES CMAKE_LINK_LIBRARY_FILE_FLAG CMAKE_LINK_LIBRARY_FLAG CMAKE_LINK_LIBRARY_SUFFIX CMAKE_LINK_SEARCH_END_STATIC CMAKE_LINK_SEARCH_START_STATIC CMAKE_LINK_WHAT_YOU_USE CMAKE_MACOSX_BUNDLE CMAKE_MACOSX_RPATH CMAKE_MAJOR_VERSION CMAKE_MAKE_PROGRAM CMAKE_MATCH_COUNT CMAKE_MFC_FLAG CMAKE_MINIMUM_REQUIRED_VERSION CMAKE_MINOR_VERSION CMAKE_MODULE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS_INIT CMAKE_MODULE_PATH CMAKE_NINJA_OUTPUT_PATH_PREFIX CMAKE_NOT_USING_CONFIG_FLAGS CMAKE_NO_BUILTIN_CHRPATH CMAKE_NO_SYSTEM_FROM_IMPORTED CMAKE_OBJECT_PATH_MAX CMAKE_OSX_ARCHITECTURES CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT CMAKE_PARENT_LIST_FILE CMAKE_PATCH_VERSION CMAKE_PDB_OUTPUT_DIRECTORY CMAKE_POSITION_INDEPENDENT_CODE CMAKE_PREFIX_PATH CMAKE_PROGRAM_PATH CMAKE_PROJECT_DESCRIPTION CMAKE_PROJECT_NAME CMAKE_RANLIB CMAKE_ROOT CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_SCRIPT_MODE_FILE CMAKE_SHARED_LIBRARY_PREFIX CMAKE_SHARED_LIBRARY_SUFFIX CMAKE_SHARED_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS_INIT CMAKE_SHARED_MODULE_PREFIX CMAKE_SHARED_MODULE_SUFFIX CMAKE_SIZEOF_VOID_P CMAKE_SKIP_BUILD_RPATH CMAKE_SKIP_INSTALL_ALL_DEPENDENCY CMAKE_SKIP_INSTALL_RPATH CMAKE_SKIP_INSTALL_RULES CMAKE_SKIP_RPATH CMAKE_SOURCE_DIR CMAKE_STAGING_PREFIX CMAKE_STATIC_LIBRARY_PREFIX CMAKE_STATIC_LIBRARY_SUFFIX CMAKE_STATIC_LINKER_FLAGS CMAKE_STATIC_LINKER_FLAGS_INIT CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE CMAKE_SYSROOT CMAKE_SYSTEM CMAKE_SYSTEM_APPBUNDLE_PATH CMAKE_SYSTEM_FRAMEWORK_PATH CMAKE_SYSTEM_IGNORE_PATH CMAKE_SYSTEM_INCLUDE_PATH CMAKE_SYSTEM_LIBRARY_PATH CMAKE_SYSTEM_NAME CMAKE_SYSTEM_PREFIX_PATH CMAKE_SYSTEM_PROCESSOR CMAKE_SYSTEM_PROGRAM_PATH CMAKE_SYSTEM_VERSION CMAKE_Swift_LANGUAGE_VERSION CMAKE_TOOLCHAIN_FILE CMAKE_TRY_COMPILE_CONFIGURATION CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_TRY_COMPILE_TARGET_TYPE CMAKE_TWEAK_VERSION CMAKE_USER_MAKE_RULES_OVERRIDE CMAKE_USE_RELATIVE_PATHS CMAKE_VERBOSE_MAKEFILE CMAKE_VERSION CMAKE_VISIBILITY_INLINES_HIDDEN CMAKE_VS_DEVENV_COMMAND CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD CMAKE_VS_INTEL_Fortran_PROJECT_VERSION CMAKE_VS_MSBUILD_COMMAND CMAKE_VS_NsightTegra_VERSION CMAKE_VS_PLATFORM_NAME CMAKE_VS_PLATFORM_TOOLSET CMAKE_VS_PLATFORM_TOOLSET_CUDA CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION CMAKE_WARN_DEPRECATED CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION CMAKE_WIN32_EXECUTABLE CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS CMAKE_XCODE_GENERATE_SCHEME CMAKE_XCODE_PLATFORM_TOOLSET CPACK_ABSOLUTE_DESTINATION_FILES CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION CPACK_INCLUDE_TOPLEVEL_DIRECTORY CPACK_INSTALL_SCRIPT CPACK_PACKAGING_INSTALL_PREFIX CPACK_SET_DESTDIR CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION CTEST_BINARY_DIRECTORY CTEST_BUILD_COMMAND CTEST_BUILD_NAME CTEST_BZR_COMMAND CTEST_BZR_UPDATE_OPTIONS CTEST_CHANGE_ID CTEST_CHECKOUT_COMMAND CTEST_CONFIGURATION_TYPE CTEST_CONFIGURE_COMMAND CTEST_COVERAGE_COMMAND CTEST_COVERAGE_EXTRA_FLAGS CTEST_CURL_OPTIONS CTEST_CUSTOM_COVERAGE_EXCLUDE CTEST_CUSTOM_ERROR_EXCEPTION CTEST_CUSTOM_ERROR_MATCH CTEST_CUSTOM_ERROR_POST_CONTEXT CTEST_CUSTOM_ERROR_PRE_CONTEXT CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE CTEST_CUSTOM_MEMCHECK_IGNORE CTEST_CUSTOM_POST_MEMCHECK CTEST_CUSTOM_POST_TEST CTEST_CUSTOM_PRE_MEMCHECK CTEST_CUSTOM_PRE_TEST CTEST_CUSTOM_TEST_IGNORE CTEST_CUSTOM_WARNING_EXCEPTION CTEST_CUSTOM_WARNING_MATCH CTEST_CVS_CHECKOUT CTEST_CVS_COMMAND CTEST_CVS_UPDATE_OPTIONS CTEST_DROP_LOCATION CTEST_DROP_METHOD CTEST_DROP_SITE CTEST_DROP_SITE_CDASH CTEST_DROP_SITE_PASSWORD CTEST_DROP_SITE_USER CTEST_EXTRA_COVERAGE_GLOB CTEST_GIT_COMMAND CTEST_GIT_INIT_SUBMODULES CTEST_GIT_UPDATE_CUSTOM CTEST_GIT_UPDATE_OPTIONS CTEST_HG_COMMAND CTEST_HG_UPDATE_OPTIONS CTEST_MEMORYCHECK_COMMAND CTEST_MEMORYCHECK_COMMAND_OPTIONS CTEST_MEMORYCHECK_SANITIZER_OPTIONS CTEST_MEMORYCHECK_SUPPRESSIONS_FILE CTEST_MEMORYCHECK_TYPE CTEST_NIGHTLY_START_TIME CTEST_P4_CLIENT CTEST_P4_COMMAND CTEST_P4_OPTIONS CTEST_P4_UPDATE_OPTIONS CTEST_SCP_COMMAND CTEST_SITE CTEST_SOURCE_DIRECTORY CTEST_SVN_COMMAND CTEST_SVN_OPTIONS CTEST_SVN_UPDATE_OPTIONS CTEST_TEST_LOAD CTEST_TEST_TIMEOUT CTEST_TRIGGER_SITE CTEST_UPDATE_COMMAND CTEST_UPDATE_OPTIONS CTEST_UPDATE_VERSION_ONLY CTEST_USE_LAUNCHERS CYGWIN ENV EXECUTABLE_OUTPUT_PATH GHS-MULTI LIBRARY_OUTPUT_PATH MINGW MSVC MSVC10 MSVC11 MSVC12 MSVC14 MSVC60 MSVC70 MSVC71 MSVC80 MSVC90 MSVC_IDE MSVC_VERSION PROJECT_BINARY_DIR PROJECT_DESCRIPTION PROJECT_NAME PROJECT_SOURCE_DIR PROJECT_VERSION PROJECT_VERSION_MAJOR PROJECT_VERSION_MINOR PROJECT_VERSION_PATCH PROJECT_VERSION_TWEAK UNIX WIN32 WINCE WINDOWS_PHONE WINDOWS_STORE XCODE XCODE_VERSION
+ \ ANDROID
+ \ APPLE
+ \ BORLAND
+ \ BUILD_SHARED_LIBS
+ \ CACHE
+ \ CMAKE_ABSOLUTE_DESTINATION_FILES
+ \ CMAKE_ANDROID_ANT_ADDITIONAL_OPTIONS
+ \ CMAKE_ANDROID_API
+ \ CMAKE_ANDROID_API_MIN
+ \ CMAKE_ANDROID_ARCH
+ \ CMAKE_ANDROID_ARCH_ABI
+ \ CMAKE_ANDROID_ARM_MODE
+ \ CMAKE_ANDROID_ARM_NEON
+ \ CMAKE_ANDROID_ASSETS_DIRECTORIES
+ \ CMAKE_ANDROID_GUI
+ \ CMAKE_ANDROID_JAR_DEPENDENCIES
+ \ CMAKE_ANDROID_JAR_DIRECTORIES
+ \ CMAKE_ANDROID_JAVA_SOURCE_DIR
+ \ CMAKE_ANDROID_NATIVE_LIB_DEPENDENCIES
+ \ CMAKE_ANDROID_NATIVE_LIB_DIRECTORIES
+ \ CMAKE_ANDROID_NDK
+ \ CMAKE_ANDROID_NDK_DEPRECATED_HEADERS
+ \ CMAKE_ANDROID_NDK_TOOLCHAIN_HOST_TAG
+ \ CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION
+ \ CMAKE_ANDROID_PROCESS_MAX
+ \ CMAKE_ANDROID_PROGUARD
+ \ CMAKE_ANDROID_PROGUARD_CONFIG_PATH
+ \ CMAKE_ANDROID_SECURE_PROPS_PATH
+ \ CMAKE_ANDROID_SKIP_ANT_STEP
+ \ CMAKE_ANDROID_STANDALONE_TOOLCHAIN
+ \ CMAKE_ANDROID_STL_TYPE
+ \ CMAKE_APPBUNDLE_PATH
+ \ CMAKE_AR
+ \ CMAKE_ARCHIVE_OUTPUT_DIRECTORY
+ \ CMAKE_ARGC
+ \ CMAKE_ARGV0
+ \ CMAKE_ASM
+ \ CMAKE_ASM_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_ASM_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_ASM_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_ASM_ARCHIVE_APPEND
+ \ CMAKE_ASM_ARCHIVE_CREATE
+ \ CMAKE_ASM_ARCHIVE_FINISH
+ \ CMAKE_ASM_CLANG_TIDY
+ \ CMAKE_ASM_COMPILER
+ \ CMAKE_ASM_COMPILER_ABI
+ \ CMAKE_ASM_COMPILER_AR
+ \ CMAKE_ASM_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_ASM_COMPILER_ID
+ \ CMAKE_ASM_COMPILER_LAUNCHER
+ \ CMAKE_ASM_COMPILER_LOADED
+ \ CMAKE_ASM_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_ASM_COMPILER_RANLIB
+ \ CMAKE_ASM_COMPILER_TARGET
+ \ CMAKE_ASM_COMPILER_VERSION
+ \ CMAKE_ASM_COMPILER_VERSION_INTERNAL
+ \ CMAKE_ASM_COMPILE_OBJECT
+ \ CMAKE_ASM_CPPCHECK
+ \ CMAKE_ASM_CPPLINT
+ \ CMAKE_ASM_CREATE_SHARED_LIBRARY
+ \ CMAKE_ASM_CREATE_SHARED_MODULE
+ \ CMAKE_ASM_CREATE_STATIC_LIBRARY
+ \ CMAKE_ASM_FLAGS
+ \ CMAKE_ASM_FLAGS_DEBUG
+ \ CMAKE_ASM_FLAGS_DEBUG_INIT
+ \ CMAKE_ASM_FLAGS_INIT
+ \ CMAKE_ASM_FLAGS_MINSIZEREL
+ \ CMAKE_ASM_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_ASM_FLAGS_RELEASE
+ \ CMAKE_ASM_FLAGS_RELEASE_INIT
+ \ CMAKE_ASM_FLAGS_RELWITHDEBINFO
+ \ CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_ASM_IGNORE_EXTENSIONS
+ \ CMAKE_ASM_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_ASM_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_ASM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_ASM_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_ASM_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_ASM_INIT
+ \ CMAKE_ASM_LIBRARY_ARCHITECTURE
+ \ CMAKE_ASM_LINKER_PREFERENCE
+ \ CMAKE_ASM_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_ASM_LINKER_WRAPPER_FLAG
+ \ CMAKE_ASM_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_ASM_LINK_EXECUTABLE
+ \ CMAKE_ASM_MASM
+ \ CMAKE_ASM_MASM_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_ASM_MASM_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_ASM_MASM_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_ASM_MASM_ARCHIVE_APPEND
+ \ CMAKE_ASM_MASM_ARCHIVE_CREATE
+ \ CMAKE_ASM_MASM_ARCHIVE_FINISH
+ \ CMAKE_ASM_MASM_CLANG_TIDY
+ \ CMAKE_ASM_MASM_COMPILER
+ \ CMAKE_ASM_MASM_COMPILER_ABI
+ \ CMAKE_ASM_MASM_COMPILER_AR
+ \ CMAKE_ASM_MASM_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_ASM_MASM_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_ASM_MASM_COMPILER_ID
+ \ CMAKE_ASM_MASM_COMPILER_LAUNCHER
+ \ CMAKE_ASM_MASM_COMPILER_LOADED
+ \ CMAKE_ASM_MASM_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_ASM_MASM_COMPILER_RANLIB
+ \ CMAKE_ASM_MASM_COMPILER_TARGET
+ \ CMAKE_ASM_MASM_COMPILER_VERSION
+ \ CMAKE_ASM_MASM_COMPILER_VERSION_INTERNAL
+ \ CMAKE_ASM_MASM_COMPILE_OBJECT
+ \ CMAKE_ASM_MASM_CPPCHECK
+ \ CMAKE_ASM_MASM_CPPLINT
+ \ CMAKE_ASM_MASM_CREATE_SHARED_LIBRARY
+ \ CMAKE_ASM_MASM_CREATE_SHARED_MODULE
+ \ CMAKE_ASM_MASM_CREATE_STATIC_LIBRARY
+ \ CMAKE_ASM_MASM_FLAGS
+ \ CMAKE_ASM_MASM_FLAGS_DEBUG
+ \ CMAKE_ASM_MASM_FLAGS_DEBUG_INIT
+ \ CMAKE_ASM_MASM_FLAGS_INIT
+ \ CMAKE_ASM_MASM_FLAGS_MINSIZEREL
+ \ CMAKE_ASM_MASM_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_ASM_MASM_FLAGS_RELEASE
+ \ CMAKE_ASM_MASM_FLAGS_RELEASE_INIT
+ \ CMAKE_ASM_MASM_FLAGS_RELWITHDEBINFO
+ \ CMAKE_ASM_MASM_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_ASM_MASM_IGNORE_EXTENSIONS
+ \ CMAKE_ASM_MASM_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_ASM_MASM_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_ASM_MASM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_ASM_MASM_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_ASM_MASM_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_ASM_MASM_INIT
+ \ CMAKE_ASM_MASM_LIBRARY_ARCHITECTURE
+ \ CMAKE_ASM_MASM_LINKER_PREFERENCE
+ \ CMAKE_ASM_MASM_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_ASM_MASM_LINKER_WRAPPER_FLAG
+ \ CMAKE_ASM_MASM_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_ASM_MASM_LINK_EXECUTABLE
+ \ CMAKE_ASM_MASM_OUTPUT_EXTENSION
+ \ CMAKE_ASM_MASM_PLATFORM_ID
+ \ CMAKE_ASM_MASM_SIMULATE_ID
+ \ CMAKE_ASM_MASM_SIMULATE_VERSION
+ \ CMAKE_ASM_MASM_SIZEOF_DATA_PTR
+ \ CMAKE_ASM_MASM_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_ASM_MASM_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_ASM_MASM_STANDARD_LIBRARIES
+ \ CMAKE_ASM_MASM_VISIBILITY_PRESET
+ \ CMAKE_ASM_NASM
+ \ CMAKE_ASM_NASM_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_ASM_NASM_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_ASM_NASM_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_ASM_NASM_ARCHIVE_APPEND
+ \ CMAKE_ASM_NASM_ARCHIVE_CREATE
+ \ CMAKE_ASM_NASM_ARCHIVE_FINISH
+ \ CMAKE_ASM_NASM_CLANG_TIDY
+ \ CMAKE_ASM_NASM_COMPILER
+ \ CMAKE_ASM_NASM_COMPILER_ABI
+ \ CMAKE_ASM_NASM_COMPILER_AR
+ \ CMAKE_ASM_NASM_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_ASM_NASM_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_ASM_NASM_COMPILER_ID
+ \ CMAKE_ASM_NASM_COMPILER_LAUNCHER
+ \ CMAKE_ASM_NASM_COMPILER_LOADED
+ \ CMAKE_ASM_NASM_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_ASM_NASM_COMPILER_RANLIB
+ \ CMAKE_ASM_NASM_COMPILER_TARGET
+ \ CMAKE_ASM_NASM_COMPILER_VERSION
+ \ CMAKE_ASM_NASM_COMPILER_VERSION_INTERNAL
+ \ CMAKE_ASM_NASM_COMPILE_OBJECT
+ \ CMAKE_ASM_NASM_CPPCHECK
+ \ CMAKE_ASM_NASM_CPPLINT
+ \ CMAKE_ASM_NASM_CREATE_SHARED_LIBRARY
+ \ CMAKE_ASM_NASM_CREATE_SHARED_MODULE
+ \ CMAKE_ASM_NASM_CREATE_STATIC_LIBRARY
+ \ CMAKE_ASM_NASM_FLAGS
+ \ CMAKE_ASM_NASM_FLAGS_DEBUG
+ \ CMAKE_ASM_NASM_FLAGS_DEBUG_INIT
+ \ CMAKE_ASM_NASM_FLAGS_INIT
+ \ CMAKE_ASM_NASM_FLAGS_MINSIZEREL
+ \ CMAKE_ASM_NASM_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_ASM_NASM_FLAGS_RELEASE
+ \ CMAKE_ASM_NASM_FLAGS_RELEASE_INIT
+ \ CMAKE_ASM_NASM_FLAGS_RELWITHDEBINFO
+ \ CMAKE_ASM_NASM_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_ASM_NASM_IGNORE_EXTENSIONS
+ \ CMAKE_ASM_NASM_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_ASM_NASM_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_ASM_NASM_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_ASM_NASM_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_ASM_NASM_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_ASM_NASM_INIT
+ \ CMAKE_ASM_NASM_LIBRARY_ARCHITECTURE
+ \ CMAKE_ASM_NASM_LINKER_PREFERENCE
+ \ CMAKE_ASM_NASM_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_ASM_NASM_LINKER_WRAPPER_FLAG
+ \ CMAKE_ASM_NASM_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_ASM_NASM_LINK_EXECUTABLE
+ \ CMAKE_ASM_NASM_OUTPUT_EXTENSION
+ \ CMAKE_ASM_NASM_PLATFORM_ID
+ \ CMAKE_ASM_NASM_SIMULATE_ID
+ \ CMAKE_ASM_NASM_SIMULATE_VERSION
+ \ CMAKE_ASM_NASM_SIZEOF_DATA_PTR
+ \ CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_ASM_NASM_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_ASM_NASM_STANDARD_LIBRARIES
+ \ CMAKE_ASM_NASM_VISIBILITY_PRESET
+ \ CMAKE_ASM_OUTPUT_EXTENSION
+ \ CMAKE_ASM_PLATFORM_ID
+ \ CMAKE_ASM_SIMULATE_ID
+ \ CMAKE_ASM_SIMULATE_VERSION
+ \ CMAKE_ASM_SIZEOF_DATA_PTR
+ \ CMAKE_ASM_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_ASM_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_ASM_STANDARD_LIBRARIES
+ \ CMAKE_ASM_VISIBILITY_PRESET
+ \ CMAKE_AUTOGEN_ORIGIN_DEPENDS
+ \ CMAKE_AUTOGEN_PARALLEL
+ \ CMAKE_AUTOGEN_VERBOSE
+ \ CMAKE_AUTOMOC
+ \ CMAKE_AUTOMOC_COMPILER_PREDEFINES
+ \ CMAKE_AUTOMOC_DEPEND_FILTERS
+ \ CMAKE_AUTOMOC_MACRO_NAMES
+ \ CMAKE_AUTOMOC_MOC_OPTIONS
+ \ CMAKE_AUTOMOC_RELAXED_MODE
+ \ CMAKE_AUTORCC
+ \ CMAKE_AUTORCC_OPTIONS
+ \ CMAKE_AUTOUIC
+ \ CMAKE_AUTOUIC_OPTIONS
+ \ CMAKE_AUTOUIC_SEARCH_PATHS
+ \ CMAKE_BACKWARDS_COMPATIBILITY
+ \ CMAKE_BINARY_DIR
+ \ CMAKE_BUILD_RPATH
+ \ CMAKE_BUILD_RPATH_USE_ORIGIN
+ \ CMAKE_BUILD_TOOL
+ \ CMAKE_BUILD_TYPE
+ \ CMAKE_BUILD_WITH_INSTALL_NAME_DIR
+ \ CMAKE_BUILD_WITH_INSTALL_RPATH
+ \ CMAKE_C
+ \ CMAKE_CACHEFILE_DIR
+ \ CMAKE_CACHE_MAJOR_VERSION
+ \ CMAKE_CACHE_MINOR_VERSION
+ \ CMAKE_CACHE_PATCH_VERSION
+ \ CMAKE_CFG_INTDIR
+ \ CMAKE_CL_64
+ \ CMAKE_CODEBLOCKS_COMPILER_ID
+ \ CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES
+ \ CMAKE_CODELITE_USE_TARGETS
+ \ CMAKE_COLOR_MAKEFILE
+ \ CMAKE_COMMAND
+ \ CMAKE_COMPILER_2005
+ \ CMAKE_COMPILER_IS_GNUCC
+ \ CMAKE_COMPILER_IS_GNUCXX
+ \ CMAKE_COMPILER_IS_GNUG77
+ \ CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY
+ \ CMAKE_CONFIGURATION_TYPES
+ \ CMAKE_CPACK_COMMAND
+ \ CMAKE_CROSSCOMPILING
+ \ CMAKE_CROSSCOMPILING_EMULATOR
+ \ CMAKE_CSharp
+ \ CMAKE_CSharp_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_CSharp_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_CSharp_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_CSharp_ARCHIVE_APPEND
+ \ CMAKE_CSharp_ARCHIVE_CREATE
+ \ CMAKE_CSharp_ARCHIVE_FINISH
+ \ CMAKE_CSharp_CLANG_TIDY
+ \ CMAKE_CSharp_COMPILER
+ \ CMAKE_CSharp_COMPILER_ABI
+ \ CMAKE_CSharp_COMPILER_AR
+ \ CMAKE_CSharp_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_CSharp_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_CSharp_COMPILER_ID
+ \ CMAKE_CSharp_COMPILER_LAUNCHER
+ \ CMAKE_CSharp_COMPILER_LOADED
+ \ CMAKE_CSharp_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_CSharp_COMPILER_RANLIB
+ \ CMAKE_CSharp_COMPILER_TARGET
+ \ CMAKE_CSharp_COMPILER_VERSION
+ \ CMAKE_CSharp_COMPILER_VERSION_INTERNAL
+ \ CMAKE_CSharp_COMPILE_OBJECT
+ \ CMAKE_CSharp_CPPCHECK
+ \ CMAKE_CSharp_CPPLINT
+ \ CMAKE_CSharp_CREATE_SHARED_LIBRARY
+ \ CMAKE_CSharp_CREATE_SHARED_MODULE
+ \ CMAKE_CSharp_CREATE_STATIC_LIBRARY
+ \ CMAKE_CSharp_FLAGS
+ \ CMAKE_CSharp_FLAGS_DEBUG
+ \ CMAKE_CSharp_FLAGS_DEBUG_INIT
+ \ CMAKE_CSharp_FLAGS_INIT
+ \ CMAKE_CSharp_FLAGS_MINSIZEREL
+ \ CMAKE_CSharp_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_CSharp_FLAGS_RELEASE
+ \ CMAKE_CSharp_FLAGS_RELEASE_INIT
+ \ CMAKE_CSharp_FLAGS_RELWITHDEBINFO
+ \ CMAKE_CSharp_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_CSharp_IGNORE_EXTENSIONS
+ \ CMAKE_CSharp_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_CSharp_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_CSharp_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_CSharp_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_CSharp_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_CSharp_INIT
+ \ CMAKE_CSharp_LIBRARY_ARCHITECTURE
+ \ CMAKE_CSharp_LINKER_PREFERENCE
+ \ CMAKE_CSharp_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_CSharp_LINKER_WRAPPER_FLAG
+ \ CMAKE_CSharp_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_CSharp_LINK_EXECUTABLE
+ \ CMAKE_CSharp_OUTPUT_EXTENSION
+ \ CMAKE_CSharp_PLATFORM_ID
+ \ CMAKE_CSharp_SIMULATE_ID
+ \ CMAKE_CSharp_SIMULATE_VERSION
+ \ CMAKE_CSharp_SIZEOF_DATA_PTR
+ \ CMAKE_CSharp_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_CSharp_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_CSharp_STANDARD_LIBRARIES
+ \ CMAKE_CSharp_VISIBILITY_PRESET
+ \ CMAKE_CTEST_COMMAND
+ \ CMAKE_CUDA
+ \ CMAKE_CUDA_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_CUDA_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_CUDA_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_CUDA_ARCHIVE_APPEND
+ \ CMAKE_CUDA_ARCHIVE_CREATE
+ \ CMAKE_CUDA_ARCHIVE_FINISH
+ \ CMAKE_CUDA_CLANG_TIDY
+ \ CMAKE_CUDA_COMPILER
+ \ CMAKE_CUDA_COMPILER_ABI
+ \ CMAKE_CUDA_COMPILER_AR
+ \ CMAKE_CUDA_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_CUDA_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_CUDA_COMPILER_ID
+ \ CMAKE_CUDA_COMPILER_LAUNCHER
+ \ CMAKE_CUDA_COMPILER_LOADED
+ \ CMAKE_CUDA_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_CUDA_COMPILER_RANLIB
+ \ CMAKE_CUDA_COMPILER_TARGET
+ \ CMAKE_CUDA_COMPILER_VERSION
+ \ CMAKE_CUDA_COMPILER_VERSION_INTERNAL
+ \ CMAKE_CUDA_COMPILE_OBJECT
+ \ CMAKE_CUDA_CPPCHECK
+ \ CMAKE_CUDA_CPPLINT
+ \ CMAKE_CUDA_CREATE_SHARED_LIBRARY
+ \ CMAKE_CUDA_CREATE_SHARED_MODULE
+ \ CMAKE_CUDA_CREATE_STATIC_LIBRARY
+ \ CMAKE_CUDA_EXTENSIONS
+ \ CMAKE_CUDA_FLAGS
+ \ CMAKE_CUDA_FLAGS_DEBUG
+ \ CMAKE_CUDA_FLAGS_DEBUG_INIT
+ \ CMAKE_CUDA_FLAGS_INIT
+ \ CMAKE_CUDA_FLAGS_MINSIZEREL
+ \ CMAKE_CUDA_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_CUDA_FLAGS_RELEASE
+ \ CMAKE_CUDA_FLAGS_RELEASE_INIT
+ \ CMAKE_CUDA_FLAGS_RELWITHDEBINFO
+ \ CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_CUDA_HOST_COMPILER
+ \ CMAKE_CUDA_IGNORE_EXTENSIONS
+ \ CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_CUDA_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_CUDA_INIT
+ \ CMAKE_CUDA_LIBRARY_ARCHITECTURE
+ \ CMAKE_CUDA_LINKER_PREFERENCE
+ \ CMAKE_CUDA_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_CUDA_LINKER_WRAPPER_FLAG
+ \ CMAKE_CUDA_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_CUDA_LINK_EXECUTABLE
+ \ CMAKE_CUDA_OUTPUT_EXTENSION
+ \ CMAKE_CUDA_PLATFORM_ID
+ \ CMAKE_CUDA_SEPARABLE_COMPILATION
+ \ CMAKE_CUDA_SIMULATE_ID
+ \ CMAKE_CUDA_SIMULATE_VERSION
+ \ CMAKE_CUDA_SIZEOF_DATA_PTR
+ \ CMAKE_CUDA_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_CUDA_STANDARD
+ \ CMAKE_CUDA_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_CUDA_STANDARD_LIBRARIES
+ \ CMAKE_CUDA_STANDARD_REQUIRED
+ \ CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES
+ \ CMAKE_CUDA_VISIBILITY_PRESET
+ \ CMAKE_CURRENT_BINARY_DIR
+ \ CMAKE_CURRENT_LIST_DIR
+ \ CMAKE_CURRENT_LIST_FILE
+ \ CMAKE_CURRENT_LIST_LINE
+ \ CMAKE_CURRENT_SOURCE_DIR
+ \ CMAKE_CXX
+ \ CMAKE_CXX_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_CXX_ARCHIVE_APPEND
+ \ CMAKE_CXX_ARCHIVE_CREATE
+ \ CMAKE_CXX_ARCHIVE_FINISH
+ \ CMAKE_CXX_CLANG_TIDY
+ \ CMAKE_CXX_COMPILER
+ \ CMAKE_CXX_COMPILER_ABI
+ \ CMAKE_CXX_COMPILER_AR
+ \ CMAKE_CXX_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_CXX_COMPILER_ID
+ \ CMAKE_CXX_COMPILER_LAUNCHER
+ \ CMAKE_CXX_COMPILER_LOADED
+ \ CMAKE_CXX_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_CXX_COMPILER_RANLIB
+ \ CMAKE_CXX_COMPILER_TARGET
+ \ CMAKE_CXX_COMPILER_VERSION
+ \ CMAKE_CXX_COMPILER_VERSION_INTERNAL
+ \ CMAKE_CXX_COMPILE_FEATURES
+ \ CMAKE_CXX_COMPILE_OBJECT
+ \ CMAKE_CXX_CPPCHECK
+ \ CMAKE_CXX_CPPLINT
+ \ CMAKE_CXX_CREATE_SHARED_LIBRARY
+ \ CMAKE_CXX_CREATE_SHARED_MODULE
+ \ CMAKE_CXX_CREATE_STATIC_LIBRARY
+ \ CMAKE_CXX_EXTENSIONS
+ \ CMAKE_CXX_FLAGS
+ \ CMAKE_CXX_FLAGS_DEBUG
+ \ CMAKE_CXX_FLAGS_DEBUG_INIT
+ \ CMAKE_CXX_FLAGS_INIT
+ \ CMAKE_CXX_FLAGS_MINSIZEREL
+ \ CMAKE_CXX_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_CXX_FLAGS_RELEASE
+ \ CMAKE_CXX_FLAGS_RELEASE_INIT
+ \ CMAKE_CXX_FLAGS_RELWITHDEBINFO
+ \ CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_CXX_IGNORE_EXTENSIONS
+ \ CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_CXX_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_CXX_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_CXX_INIT
+ \ CMAKE_CXX_LIBRARY_ARCHITECTURE
+ \ CMAKE_CXX_LINKER_PREFERENCE
+ \ CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_CXX_LINKER_WRAPPER_FLAG
+ \ CMAKE_CXX_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_CXX_LINK_EXECUTABLE
+ \ CMAKE_CXX_OUTPUT_EXTENSION
+ \ CMAKE_CXX_PLATFORM_ID
+ \ CMAKE_CXX_SIMULATE_ID
+ \ CMAKE_CXX_SIMULATE_VERSION
+ \ CMAKE_CXX_SIZEOF_DATA_PTR
+ \ CMAKE_CXX_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_CXX_STANDARD
+ \ CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_CXX_STANDARD_LIBRARIES
+ \ CMAKE_CXX_STANDARD_REQUIRED
+ \ CMAKE_CXX_VISIBILITY_PRESET
+ \ CMAKE_C_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_C_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_C_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_C_ARCHIVE_APPEND
+ \ CMAKE_C_ARCHIVE_CREATE
+ \ CMAKE_C_ARCHIVE_FINISH
+ \ CMAKE_C_CLANG_TIDY
+ \ CMAKE_C_COMPILER
+ \ CMAKE_C_COMPILER_ABI
+ \ CMAKE_C_COMPILER_AR
+ \ CMAKE_C_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_C_COMPILER_ID
+ \ CMAKE_C_COMPILER_LAUNCHER
+ \ CMAKE_C_COMPILER_LOADED
+ \ CMAKE_C_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_C_COMPILER_RANLIB
+ \ CMAKE_C_COMPILER_TARGET
+ \ CMAKE_C_COMPILER_VERSION
+ \ CMAKE_C_COMPILER_VERSION_INTERNAL
+ \ CMAKE_C_COMPILE_FEATURES
+ \ CMAKE_C_COMPILE_OBJECT
+ \ CMAKE_C_CPPCHECK
+ \ CMAKE_C_CPPLINT
+ \ CMAKE_C_CREATE_SHARED_LIBRARY
+ \ CMAKE_C_CREATE_SHARED_MODULE
+ \ CMAKE_C_CREATE_STATIC_LIBRARY
+ \ CMAKE_C_EXTENSIONS
+ \ CMAKE_C_FLAGS
+ \ CMAKE_C_FLAGS_DEBUG
+ \ CMAKE_C_FLAGS_DEBUG_INIT
+ \ CMAKE_C_FLAGS_INIT
+ \ CMAKE_C_FLAGS_MINSIZEREL
+ \ CMAKE_C_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_C_FLAGS_RELEASE
+ \ CMAKE_C_FLAGS_RELEASE_INIT
+ \ CMAKE_C_FLAGS_RELWITHDEBINFO
+ \ CMAKE_C_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_C_IGNORE_EXTENSIONS
+ \ CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_C_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_C_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_C_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_C_INIT
+ \ CMAKE_C_LIBRARY_ARCHITECTURE
+ \ CMAKE_C_LINKER_PREFERENCE
+ \ CMAKE_C_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_C_LINKER_WRAPPER_FLAG
+ \ CMAKE_C_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_C_LINK_EXECUTABLE
+ \ CMAKE_C_OUTPUT_EXTENSION
+ \ CMAKE_C_PLATFORM_ID
+ \ CMAKE_C_SIMULATE_ID
+ \ CMAKE_C_SIMULATE_VERSION
+ \ CMAKE_C_SIZEOF_DATA_PTR
+ \ CMAKE_C_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_C_STANDARD
+ \ CMAKE_C_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_C_STANDARD_LIBRARIES
+ \ CMAKE_C_STANDARD_REQUIRED
+ \ CMAKE_C_VISIBILITY_PRESET
+ \ CMAKE_DEBUG_POSTFIX
+ \ CMAKE_DEBUG_TARGET_PROPERTIES
+ \ CMAKE_DEPENDS_IN_PROJECT_ONLY
+ \ CMAKE_DIRECTORY_LABELS
+ \ CMAKE_DL_LIBS
+ \ CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION
+ \ CMAKE_ECLIPSE_GENERATE_LINKED_RESOURCES
+ \ CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT
+ \ CMAKE_ECLIPSE_MAKE_ARGUMENTS
+ \ CMAKE_ECLIPSE_VERSION
+ \ CMAKE_EDIT_COMMAND
+ \ CMAKE_ENABLE_EXPORTS
+ \ CMAKE_ERROR_DEPRECATED
+ \ CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+ \ CMAKE_EXECUTABLE_SUFFIX
+ \ CMAKE_EXECUTE_PROCESS_COMMAND_ECHO
+ \ CMAKE_EXE_LINKER_FLAGS
+ \ CMAKE_EXE_LINKER_FLAGS_INIT
+ \ CMAKE_EXPORT_COMPILE_COMMANDS
+ \ CMAKE_EXPORT_NO_PACKAGE_REGISTRY
+ \ CMAKE_EXPORT_PACKAGE_REGISTRY
+ \ CMAKE_EXTRA_GENERATOR
+ \ CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES
+ \ CMAKE_FIND_APPBUNDLE
+ \ CMAKE_FIND_FRAMEWORK
+ \ CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX
+ \ CMAKE_FIND_LIBRARY_PREFIXES
+ \ CMAKE_FIND_LIBRARY_SUFFIXES
+ \ CMAKE_FIND_NO_INSTALL_PREFIX
+ \ CMAKE_FIND_PACKAGE_NAME
+ \ CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY
+ \ CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY
+ \ CMAKE_FIND_PACKAGE_PREFER_CONFIG
+ \ CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS
+ \ CMAKE_FIND_PACKAGE_SORT_DIRECTION
+ \ CMAKE_FIND_PACKAGE_SORT_ORDER
+ \ CMAKE_FIND_PACKAGE_WARN_NO_MODULE
+ \ CMAKE_FIND_ROOT_PATH
+ \ CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
+ \ CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
+ \ CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
+ \ CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
+ \ CMAKE_FOLDER
+ \ CMAKE_FRAMEWORK
+ \ CMAKE_FRAMEWORK_PATH
+ \ CMAKE_Fortran
+ \ CMAKE_Fortran_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_Fortran_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_Fortran_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_Fortran_ARCHIVE_APPEND
+ \ CMAKE_Fortran_ARCHIVE_CREATE
+ \ CMAKE_Fortran_ARCHIVE_FINISH
+ \ CMAKE_Fortran_CLANG_TIDY
+ \ CMAKE_Fortran_COMPILER
+ \ CMAKE_Fortran_COMPILER_ABI
+ \ CMAKE_Fortran_COMPILER_AR
+ \ CMAKE_Fortran_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_Fortran_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_Fortran_COMPILER_ID
+ \ CMAKE_Fortran_COMPILER_LAUNCHER
+ \ CMAKE_Fortran_COMPILER_LOADED
+ \ CMAKE_Fortran_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_Fortran_COMPILER_RANLIB
+ \ CMAKE_Fortran_COMPILER_TARGET
+ \ CMAKE_Fortran_COMPILER_VERSION
+ \ CMAKE_Fortran_COMPILER_VERSION_INTERNAL
+ \ CMAKE_Fortran_COMPILE_OBJECT
+ \ CMAKE_Fortran_CPPCHECK
+ \ CMAKE_Fortran_CPPLINT
+ \ CMAKE_Fortran_CREATE_SHARED_LIBRARY
+ \ CMAKE_Fortran_CREATE_SHARED_MODULE
+ \ CMAKE_Fortran_CREATE_STATIC_LIBRARY
+ \ CMAKE_Fortran_FLAGS
+ \ CMAKE_Fortran_FLAGS_DEBUG
+ \ CMAKE_Fortran_FLAGS_DEBUG_INIT
+ \ CMAKE_Fortran_FLAGS_INIT
+ \ CMAKE_Fortran_FLAGS_MINSIZEREL
+ \ CMAKE_Fortran_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_Fortran_FLAGS_RELEASE
+ \ CMAKE_Fortran_FLAGS_RELEASE_INIT
+ \ CMAKE_Fortran_FLAGS_RELWITHDEBINFO
+ \ CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_Fortran_FORMAT
+ \ CMAKE_Fortran_IGNORE_EXTENSIONS
+ \ CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_Fortran_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_Fortran_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_Fortran_INIT
+ \ CMAKE_Fortran_LIBRARY_ARCHITECTURE
+ \ CMAKE_Fortran_LINKER_PREFERENCE
+ \ CMAKE_Fortran_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_Fortran_LINKER_WRAPPER_FLAG
+ \ CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_Fortran_LINK_EXECUTABLE
+ \ CMAKE_Fortran_MODDIR_DEFAULT
+ \ CMAKE_Fortran_MODDIR_FLAG
+ \ CMAKE_Fortran_MODOUT_FLAG
+ \ CMAKE_Fortran_MODULE_DIRECTORY
+ \ CMAKE_Fortran_OUTPUT_EXTENSION
+ \ CMAKE_Fortran_PLATFORM_ID
+ \ CMAKE_Fortran_SIMULATE_ID
+ \ CMAKE_Fortran_SIMULATE_VERSION
+ \ CMAKE_Fortran_SIZEOF_DATA_PTR
+ \ CMAKE_Fortran_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_Fortran_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_Fortran_STANDARD_LIBRARIES
+ \ CMAKE_Fortran_VISIBILITY_PRESET
+ \ CMAKE_GENERATOR
+ \ CMAKE_GENERATOR_INSTANCE
+ \ CMAKE_GENERATOR_PLATFORM
+ \ CMAKE_GENERATOR_TOOLSET
+ \ CMAKE_GHS_NO_SOURCE_GROUP_FILE
+ \ CMAKE_GLOBAL_AUTOGEN_TARGET
+ \ CMAKE_GLOBAL_AUTOGEN_TARGET_NAME
+ \ CMAKE_GLOBAL_AUTORCC_TARGET
+ \ CMAKE_GLOBAL_AUTORCC_TARGET_NAME
+ \ CMAKE_GNUtoMS
+ \ CMAKE_HOME_DIRECTORY
+ \ CMAKE_HOST_APPLE
+ \ CMAKE_HOST_SOLARIS
+ \ CMAKE_HOST_SYSTEM
+ \ CMAKE_HOST_SYSTEM_NAME
+ \ CMAKE_HOST_SYSTEM_PROCESSOR
+ \ CMAKE_HOST_SYSTEM_VERSION
+ \ CMAKE_HOST_UNIX
+ \ CMAKE_HOST_WIN32
+ \ CMAKE_IGNORE_PATH
+ \ CMAKE_IMPORT_LIBRARY_PREFIX
+ \ CMAKE_IMPORT_LIBRARY_SUFFIX
+ \ CMAKE_INCLUDE_CURRENT_DIR
+ \ CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE
+ \ CMAKE_INCLUDE_DIRECTORIES_BEFORE
+ \ CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE
+ \ CMAKE_INCLUDE_PATH
+ \ CMAKE_INSTALL_DEFAULT_COMPONENT_NAME
+ \ CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
+ \ CMAKE_INSTALL_MESSAGE
+ \ CMAKE_INSTALL_NAME_DIR
+ \ CMAKE_INSTALL_PREFIX
+ \ CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
+ \ CMAKE_INSTALL_RPATH
+ \ CMAKE_INSTALL_RPATH_USE_LINK_PATH
+ \ CMAKE_INTERNAL_PLATFORM_ABI
+ \ CMAKE_INTERPROCEDURAL_OPTIMIZATION
+ \ CMAKE_IOS_INSTALL_COMBINED
+ \ CMAKE_JOB_POOLS
+ \ CMAKE_JOB_POOL_COMPILE
+ \ CMAKE_JOB_POOL_LINK
+ \ CMAKE_Java
+ \ CMAKE_Java_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_Java_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_Java_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_Java_ARCHIVE_APPEND
+ \ CMAKE_Java_ARCHIVE_CREATE
+ \ CMAKE_Java_ARCHIVE_FINISH
+ \ CMAKE_Java_CLANG_TIDY
+ \ CMAKE_Java_COMPILER
+ \ CMAKE_Java_COMPILER_ABI
+ \ CMAKE_Java_COMPILER_AR
+ \ CMAKE_Java_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_Java_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_Java_COMPILER_ID
+ \ CMAKE_Java_COMPILER_LAUNCHER
+ \ CMAKE_Java_COMPILER_LOADED
+ \ CMAKE_Java_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_Java_COMPILER_RANLIB
+ \ CMAKE_Java_COMPILER_TARGET
+ \ CMAKE_Java_COMPILER_VERSION
+ \ CMAKE_Java_COMPILER_VERSION_INTERNAL
+ \ CMAKE_Java_COMPILE_OBJECT
+ \ CMAKE_Java_CPPCHECK
+ \ CMAKE_Java_CPPLINT
+ \ CMAKE_Java_CREATE_SHARED_LIBRARY
+ \ CMAKE_Java_CREATE_SHARED_MODULE
+ \ CMAKE_Java_CREATE_STATIC_LIBRARY
+ \ CMAKE_Java_FLAGS
+ \ CMAKE_Java_FLAGS_DEBUG
+ \ CMAKE_Java_FLAGS_DEBUG_INIT
+ \ CMAKE_Java_FLAGS_INIT
+ \ CMAKE_Java_FLAGS_MINSIZEREL
+ \ CMAKE_Java_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_Java_FLAGS_RELEASE
+ \ CMAKE_Java_FLAGS_RELEASE_INIT
+ \ CMAKE_Java_FLAGS_RELWITHDEBINFO
+ \ CMAKE_Java_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_Java_IGNORE_EXTENSIONS
+ \ CMAKE_Java_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_Java_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_Java_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_Java_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_Java_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_Java_INIT
+ \ CMAKE_Java_LIBRARY_ARCHITECTURE
+ \ CMAKE_Java_LINKER_PREFERENCE
+ \ CMAKE_Java_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_Java_LINKER_WRAPPER_FLAG
+ \ CMAKE_Java_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_Java_LINK_EXECUTABLE
+ \ CMAKE_Java_OUTPUT_EXTENSION
+ \ CMAKE_Java_PLATFORM_ID
+ \ CMAKE_Java_SIMULATE_ID
+ \ CMAKE_Java_SIMULATE_VERSION
+ \ CMAKE_Java_SIZEOF_DATA_PTR
+ \ CMAKE_Java_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_Java_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_Java_STANDARD_LIBRARIES
+ \ CMAKE_Java_VISIBILITY_PRESET
+ \ CMAKE_LIBRARY_ARCHITECTURE
+ \ CMAKE_LIBRARY_ARCHITECTURE_REGEX
+ \ CMAKE_LIBRARY_OUTPUT_DIRECTORY
+ \ CMAKE_LIBRARY_PATH
+ \ CMAKE_LIBRARY_PATH_FLAG
+ \ CMAKE_LINK_DEF_FILE_FLAG
+ \ CMAKE_LINK_DEPENDS_NO_SHARED
+ \ CMAKE_LINK_DIRECTORIES_BEFORE
+ \ CMAKE_LINK_INTERFACE_LIBRARIES
+ \ CMAKE_LINK_LIBRARY_FILE_FLAG
+ \ CMAKE_LINK_LIBRARY_FLAG
+ \ CMAKE_LINK_LIBRARY_SUFFIX
+ \ CMAKE_LINK_SEARCH_END_STATIC
+ \ CMAKE_LINK_SEARCH_START_STATIC
+ \ CMAKE_LINK_WHAT_YOU_USE
+ \ CMAKE_MACOSX_BUNDLE
+ \ CMAKE_MACOSX_RPATH
+ \ CMAKE_MAJOR_VERSION
+ \ CMAKE_MAKE_PROGRAM
+ \ CMAKE_MATCH_COUNT
+ \ CMAKE_MAXIMUM_RECURSION_DEPTH
+ \ CMAKE_MFC_FLAG
+ \ CMAKE_MINIMUM_REQUIRED_VERSION
+ \ CMAKE_MINOR_VERSION
+ \ CMAKE_MODULE_LINKER_FLAGS
+ \ CMAKE_MODULE_LINKER_FLAGS_INIT
+ \ CMAKE_MODULE_PATH
+ \ CMAKE_MSVCIDE_RUN_PATH
+ \ CMAKE_MSVC_RUNTIME_LIBRARY
+ \ CMAKE_NETRC
+ \ CMAKE_NETRC_FILE
+ \ CMAKE_NINJA_OUTPUT_PATH_PREFIX
+ \ CMAKE_NOT_USING_CONFIG_FLAGS
+ \ CMAKE_NO_BUILTIN_CHRPATH
+ \ CMAKE_NO_SYSTEM_FROM_IMPORTED
+ \ CMAKE_OBJECT_PATH_MAX
+ \ CMAKE_OSX_ARCHITECTURES
+ \ CMAKE_OSX_DEPLOYMENT_TARGET
+ \ CMAKE_OSX_SYSROOT
+ \ CMAKE_PARENT_LIST_FILE
+ \ CMAKE_PATCH_VERSION
+ \ CMAKE_PDB_OUTPUT_DIRECTORY
+ \ CMAKE_POSITION_INDEPENDENT_CODE
+ \ CMAKE_PREFIX_PATH
+ \ CMAKE_PROGRAM_PATH
+ \ CMAKE_PROJECT_DESCRIPTION
+ \ CMAKE_PROJECT_HOMEPAGE_URL
+ \ CMAKE_PROJECT_INCLUDE
+ \ CMAKE_PROJECT_INCLUDE_BEFORE
+ \ CMAKE_PROJECT_NAME
+ \ CMAKE_PROJECT_VERSION
+ \ CMAKE_PROJECT_VERSION_MAJOR
+ \ CMAKE_PROJECT_VERSION_MINOR
+ \ CMAKE_PROJECT_VERSION_PATCH
+ \ CMAKE_PROJECT_VERSION_TWEAK
+ \ CMAKE_RANLIB
+ \ CMAKE_RC
+ \ CMAKE_RC_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_RC_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_RC_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_RC_ARCHIVE_APPEND
+ \ CMAKE_RC_ARCHIVE_CREATE
+ \ CMAKE_RC_ARCHIVE_FINISH
+ \ CMAKE_RC_CLANG_TIDY
+ \ CMAKE_RC_COMPILER
+ \ CMAKE_RC_COMPILER_ABI
+ \ CMAKE_RC_COMPILER_AR
+ \ CMAKE_RC_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_RC_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_RC_COMPILER_ID
+ \ CMAKE_RC_COMPILER_LAUNCHER
+ \ CMAKE_RC_COMPILER_LOADED
+ \ CMAKE_RC_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_RC_COMPILER_RANLIB
+ \ CMAKE_RC_COMPILER_TARGET
+ \ CMAKE_RC_COMPILER_VERSION
+ \ CMAKE_RC_COMPILER_VERSION_INTERNAL
+ \ CMAKE_RC_COMPILE_OBJECT
+ \ CMAKE_RC_CPPCHECK
+ \ CMAKE_RC_CPPLINT
+ \ CMAKE_RC_CREATE_SHARED_LIBRARY
+ \ CMAKE_RC_CREATE_SHARED_MODULE
+ \ CMAKE_RC_CREATE_STATIC_LIBRARY
+ \ CMAKE_RC_FLAGS
+ \ CMAKE_RC_FLAGS_DEBUG
+ \ CMAKE_RC_FLAGS_DEBUG_INIT
+ \ CMAKE_RC_FLAGS_INIT
+ \ CMAKE_RC_FLAGS_MINSIZEREL
+ \ CMAKE_RC_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_RC_FLAGS_RELEASE
+ \ CMAKE_RC_FLAGS_RELEASE_INIT
+ \ CMAKE_RC_FLAGS_RELWITHDEBINFO
+ \ CMAKE_RC_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_RC_IGNORE_EXTENSIONS
+ \ CMAKE_RC_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_RC_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_RC_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_RC_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_RC_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_RC_INIT
+ \ CMAKE_RC_LIBRARY_ARCHITECTURE
+ \ CMAKE_RC_LINKER_PREFERENCE
+ \ CMAKE_RC_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_RC_LINKER_WRAPPER_FLAG
+ \ CMAKE_RC_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_RC_LINK_EXECUTABLE
+ \ CMAKE_RC_OUTPUT_EXTENSION
+ \ CMAKE_RC_PLATFORM_ID
+ \ CMAKE_RC_SIMULATE_ID
+ \ CMAKE_RC_SIMULATE_VERSION
+ \ CMAKE_RC_SIZEOF_DATA_PTR
+ \ CMAKE_RC_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_RC_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_RC_STANDARD_LIBRARIES
+ \ CMAKE_RC_VISIBILITY_PRESET
+ \ CMAKE_ROOT
+ \ CMAKE_RULE_MESSAGES
+ \ CMAKE_RUNTIME_OUTPUT_DIRECTORY
+ \ CMAKE_SCRIPT_MODE_FILE
+ \ CMAKE_SHARED_LIBRARY_PREFIX
+ \ CMAKE_SHARED_LIBRARY_SUFFIX
+ \ CMAKE_SHARED_LINKER_FLAGS
+ \ CMAKE_SHARED_LINKER_FLAGS_INIT
+ \ CMAKE_SHARED_MODULE_PREFIX
+ \ CMAKE_SHARED_MODULE_SUFFIX
+ \ CMAKE_SIZEOF_VOID_P
+ \ CMAKE_SKIP_BUILD_RPATH
+ \ CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
+ \ CMAKE_SKIP_INSTALL_RPATH
+ \ CMAKE_SKIP_INSTALL_RULES
+ \ CMAKE_SKIP_RPATH
+ \ CMAKE_SOURCE_DIR
+ \ CMAKE_STAGING_PREFIX
+ \ CMAKE_STATIC_LIBRARY_PREFIX
+ \ CMAKE_STATIC_LIBRARY_SUFFIX
+ \ CMAKE_STATIC_LINKER_FLAGS
+ \ CMAKE_STATIC_LINKER_FLAGS_INIT
+ \ CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
+ \ CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE
+ \ CMAKE_SUPPRESS_REGENERATION
+ \ CMAKE_SYSROOT
+ \ CMAKE_SYSROOT_COMPILE
+ \ CMAKE_SYSROOT_LINK
+ \ CMAKE_SYSTEM
+ \ CMAKE_SYSTEM_APPBUNDLE_PATH
+ \ CMAKE_SYSTEM_FRAMEWORK_PATH
+ \ CMAKE_SYSTEM_IGNORE_PATH
+ \ CMAKE_SYSTEM_INCLUDE_PATH
+ \ CMAKE_SYSTEM_LIBRARY_PATH
+ \ CMAKE_SYSTEM_NAME
+ \ CMAKE_SYSTEM_PREFIX_PATH
+ \ CMAKE_SYSTEM_PROCESSOR
+ \ CMAKE_SYSTEM_PROGRAM_PATH
+ \ CMAKE_SYSTEM_VERSION
+ \ CMAKE_Swift
+ \ CMAKE_Swift_ANDROID_TOOLCHAIN_MACHINE
+ \ CMAKE_Swift_ANDROID_TOOLCHAIN_PREFIX
+ \ CMAKE_Swift_ANDROID_TOOLCHAIN_SUFFIX
+ \ CMAKE_Swift_ARCHIVE_APPEND
+ \ CMAKE_Swift_ARCHIVE_CREATE
+ \ CMAKE_Swift_ARCHIVE_FINISH
+ \ CMAKE_Swift_CLANG_TIDY
+ \ CMAKE_Swift_COMPILER
+ \ CMAKE_Swift_COMPILER_ABI
+ \ CMAKE_Swift_COMPILER_AR
+ \ CMAKE_Swift_COMPILER_ARCHITECTURE_ID
+ \ CMAKE_Swift_COMPILER_EXTERNAL_TOOLCHAIN
+ \ CMAKE_Swift_COMPILER_ID
+ \ CMAKE_Swift_COMPILER_LAUNCHER
+ \ CMAKE_Swift_COMPILER_LOADED
+ \ CMAKE_Swift_COMPILER_PREDEFINES_COMMAND
+ \ CMAKE_Swift_COMPILER_RANLIB
+ \ CMAKE_Swift_COMPILER_TARGET
+ \ CMAKE_Swift_COMPILER_VERSION
+ \ CMAKE_Swift_COMPILER_VERSION_INTERNAL
+ \ CMAKE_Swift_COMPILE_OBJECT
+ \ CMAKE_Swift_CPPCHECK
+ \ CMAKE_Swift_CPPLINT
+ \ CMAKE_Swift_CREATE_SHARED_LIBRARY
+ \ CMAKE_Swift_CREATE_SHARED_MODULE
+ \ CMAKE_Swift_CREATE_STATIC_LIBRARY
+ \ CMAKE_Swift_FLAGS
+ \ CMAKE_Swift_FLAGS_DEBUG
+ \ CMAKE_Swift_FLAGS_DEBUG_INIT
+ \ CMAKE_Swift_FLAGS_INIT
+ \ CMAKE_Swift_FLAGS_MINSIZEREL
+ \ CMAKE_Swift_FLAGS_MINSIZEREL_INIT
+ \ CMAKE_Swift_FLAGS_RELEASE
+ \ CMAKE_Swift_FLAGS_RELEASE_INIT
+ \ CMAKE_Swift_FLAGS_RELWITHDEBINFO
+ \ CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT
+ \ CMAKE_Swift_IGNORE_EXTENSIONS
+ \ CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES
+ \ CMAKE_Swift_IMPLICIT_LINK_DIRECTORIES
+ \ CMAKE_Swift_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES
+ \ CMAKE_Swift_IMPLICIT_LINK_LIBRARIES
+ \ CMAKE_Swift_INCLUDE_WHAT_YOU_USE
+ \ CMAKE_Swift_INIT
+ \ CMAKE_Swift_LANGUAGE_VERSION
+ \ CMAKE_Swift_LIBRARY_ARCHITECTURE
+ \ CMAKE_Swift_LINKER_PREFERENCE
+ \ CMAKE_Swift_LINKER_PREFERENCE_PROPAGATES
+ \ CMAKE_Swift_LINKER_WRAPPER_FLAG
+ \ CMAKE_Swift_LINKER_WRAPPER_FLAG_SEP
+ \ CMAKE_Swift_LINK_EXECUTABLE
+ \ CMAKE_Swift_MODULE_DIRECTORY
+ \ CMAKE_Swift_OUTPUT_EXTENSION
+ \ CMAKE_Swift_PLATFORM_ID
+ \ CMAKE_Swift_SIMULATE_ID
+ \ CMAKE_Swift_SIMULATE_VERSION
+ \ CMAKE_Swift_SIZEOF_DATA_PTR
+ \ CMAKE_Swift_SOURCE_FILE_EXTENSIONS
+ \ CMAKE_Swift_STANDARD_INCLUDE_DIRECTORIES
+ \ CMAKE_Swift_STANDARD_LIBRARIES
+ \ CMAKE_Swift_VISIBILITY_PRESET
+ \ CMAKE_TOOLCHAIN_FILE
+ \ CMAKE_TRY_COMPILE_CONFIGURATION
+ \ CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
+ \ CMAKE_TRY_COMPILE_TARGET_TYPE
+ \ CMAKE_TWEAK_VERSION
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_ASM
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_ASM_MASM
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_ASM_NASM
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_C
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_CSharp
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_CUDA
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_CXX
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_Java
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_RC
+ \ CMAKE_USER_MAKE_RULES_OVERRIDE_Swift
+ \ CMAKE_USE_RELATIVE_PATHS
+ \ CMAKE_VERBOSE_MAKEFILE
+ \ CMAKE_VERSION
+ \ CMAKE_VISIBILITY_INLINES_HIDDEN
+ \ CMAKE_VS_DEVENV_COMMAND
+ \ CMAKE_VS_GLOBALS
+ \ CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD
+ \ CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD
+ \ CMAKE_VS_INTEL_Fortran_PROJECT_VERSION
+ \ CMAKE_VS_JUST_MY_CODE_DEBUGGING
+ \ CMAKE_VS_MSBUILD_COMMAND
+ \ CMAKE_VS_NsightTegra_VERSION
+ \ CMAKE_VS_PLATFORM_NAME
+ \ CMAKE_VS_PLATFORM_NAME_DEFAULT
+ \ CMAKE_VS_PLATFORM_TOOLSET
+ \ CMAKE_VS_PLATFORM_TOOLSET_CUDA
+ \ CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE
+ \ CMAKE_VS_PLATFORM_TOOLSET_VERSION
+ \ CMAKE_VS_SDK_EXCLUDE_DIRECTORIES
+ \ CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES
+ \ CMAKE_VS_SDK_INCLUDE_DIRECTORIES
+ \ CMAKE_VS_SDK_LIBRARY_DIRECTORIES
+ \ CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES
+ \ CMAKE_VS_SDK_REFERENCE_DIRECTORIES
+ \ CMAKE_VS_SDK_SOURCE_DIRECTORIES
+ \ CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
+ \ CMAKE_VS_WINRT_BY_DEFAULT
+ \ CMAKE_WARN_DEPRECATED
+ \ CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
+ \ CMAKE_WIN32_EXECUTABLE
+ \ CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
+ \ CMAKE_XCODE_GENERATE_SCHEME
+ \ CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY
+ \ CMAKE_XCODE_PLATFORM_TOOLSET
+ \ CMAKE_XCODE_SCHEME_ADDRESS_SANITIZER
+ \ CMAKE_XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN
+ \ CMAKE_XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER
+ \ CMAKE_XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS
+ \ CMAKE_XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE
+ \ CMAKE_XCODE_SCHEME_GUARD_MALLOC
+ \ CMAKE_XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP
+ \ CMAKE_XCODE_SCHEME_MALLOC_GUARD_EDGES
+ \ CMAKE_XCODE_SCHEME_MALLOC_SCRIBBLE
+ \ CMAKE_XCODE_SCHEME_MALLOC_STACK
+ \ CMAKE_XCODE_SCHEME_THREAD_SANITIZER
+ \ CMAKE_XCODE_SCHEME_THREAD_SANITIZER_STOP
+ \ CMAKE_XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER
+ \ CMAKE_XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP
+ \ CMAKE_XCODE_SCHEME_ZOMBIE_OBJECTS
+ \ CPACK_ABSOLUTE_DESTINATION_FILES
+ \ CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY
+ \ CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+ \ CPACK_INCLUDE_TOPLEVEL_DIRECTORY
+ \ CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
+ \ CPACK_INSTALL_SCRIPT
+ \ CPACK_PACKAGING_INSTALL_PREFIX
+ \ CPACK_SET_DESTDIR
+ \ CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
+ \ CTEST_BINARY_DIRECTORY
+ \ CTEST_BUILD_COMMAND
+ \ CTEST_BUILD_NAME
+ \ CTEST_BZR_COMMAND
+ \ CTEST_BZR_UPDATE_OPTIONS
+ \ CTEST_CHANGE_ID
+ \ CTEST_CHECKOUT_COMMAND
+ \ CTEST_CONFIGURATION_TYPE
+ \ CTEST_CONFIGURE_COMMAND
+ \ CTEST_COVERAGE_COMMAND
+ \ CTEST_COVERAGE_EXTRA_FLAGS
+ \ CTEST_CURL_OPTIONS
+ \ CTEST_CUSTOM_COVERAGE_EXCLUDE
+ \ CTEST_CUSTOM_ERROR_EXCEPTION
+ \ CTEST_CUSTOM_ERROR_MATCH
+ \ CTEST_CUSTOM_ERROR_POST_CONTEXT
+ \ CTEST_CUSTOM_ERROR_PRE_CONTEXT
+ \ CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE
+ \ CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS
+ \ CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS
+ \ CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE
+ \ CTEST_CUSTOM_MEMCHECK_IGNORE
+ \ CTEST_CUSTOM_POST_MEMCHECK
+ \ CTEST_CUSTOM_POST_TEST
+ \ CTEST_CUSTOM_PRE_MEMCHECK
+ \ CTEST_CUSTOM_PRE_TEST
+ \ CTEST_CUSTOM_TESTS_IGNORE
+ \ CTEST_CUSTOM_WARNING_EXCEPTION
+ \ CTEST_CUSTOM_WARNING_MATCH
+ \ CTEST_CVS_CHECKOUT
+ \ CTEST_CVS_COMMAND
+ \ CTEST_CVS_UPDATE_OPTIONS
+ \ CTEST_DROP_LOCATION
+ \ CTEST_DROP_METHOD
+ \ CTEST_DROP_SITE
+ \ CTEST_DROP_SITE_CDASH
+ \ CTEST_DROP_SITE_PASSWORD
+ \ CTEST_DROP_SITE_USER
+ \ CTEST_EXTRA_COVERAGE_GLOB
+ \ CTEST_GIT_COMMAND
+ \ CTEST_GIT_INIT_SUBMODULES
+ \ CTEST_GIT_UPDATE_CUSTOM
+ \ CTEST_GIT_UPDATE_OPTIONS
+ \ CTEST_HG_COMMAND
+ \ CTEST_HG_UPDATE_OPTIONS
+ \ CTEST_LABELS_FOR_SUBPROJECTS
+ \ CTEST_MEMORYCHECK_COMMAND
+ \ CTEST_MEMORYCHECK_COMMAND_OPTIONS
+ \ CTEST_MEMORYCHECK_SANITIZER_OPTIONS
+ \ CTEST_MEMORYCHECK_SUPPRESSIONS_FILE
+ \ CTEST_MEMORYCHECK_TYPE
+ \ CTEST_NIGHTLY_START_TIME
+ \ CTEST_P4_CLIENT
+ \ CTEST_P4_COMMAND
+ \ CTEST_P4_OPTIONS
+ \ CTEST_P4_UPDATE_OPTIONS
+ \ CTEST_RUN_CURRENT_SCRIPT
+ \ CTEST_SCP_COMMAND
+ \ CTEST_SITE
+ \ CTEST_SOURCE_DIRECTORY
+ \ CTEST_SUBMIT_URL
+ \ CTEST_SVN_COMMAND
+ \ CTEST_SVN_OPTIONS
+ \ CTEST_SVN_UPDATE_OPTIONS
+ \ CTEST_TEST_LOAD
+ \ CTEST_TEST_TIMEOUT
+ \ CTEST_TRIGGER_SITE
+ \ CTEST_UPDATE_COMMAND
+ \ CTEST_UPDATE_OPTIONS
+ \ CTEST_UPDATE_VERSION_ONLY
+ \ CTEST_UPDATE_VERSION_OVERRIDE
+ \ CTEST_USE_LAUNCHERS
+ \ CYGWIN
+ \ ENV
+ \ EXECUTABLE_OUTPUT_PATH
+ \ GHS-MULTI
+ \ IOS
+ \ LIBRARY_OUTPUT_PATH
+ \ MINGW
+ \ MSVC
+ \ MSVC10
+ \ MSVC11
+ \ MSVC12
+ \ MSVC14
+ \ MSVC60
+ \ MSVC70
+ \ MSVC71
+ \ MSVC80
+ \ MSVC90
+ \ MSVC_IDE
+ \ MSVC_TOOLSET_VERSION
+ \ MSVC_VERSION
+ \ MSYS
+ \ PROJECT_BINARY_DIR
+ \ PROJECT_DESCRIPTION
+ \ PROJECT_HOMEPAGE_URL
+ \ PROJECT_NAME
+ \ PROJECT_SOURCE_DIR
+ \ PROJECT_VERSION
+ \ PROJECT_VERSION_MAJOR
+ \ PROJECT_VERSION_MINOR
+ \ PROJECT_VERSION_PATCH
+ \ PROJECT_VERSION_TWEAK
+ \ UNIX
+ \ WIN32
+ \ WINCE
+ \ WINDOWS_PHONE
+ \ WINDOWS_STORE
+ \ XCODE
+ \ XCODE_VERSION
syn keyword cmakeModule contained
\ ExternalProject
syn keyword cmakeKWExternalProject contained
- \ ALGO BINARY_DIR BUILD_ALWAYS BUILD_BYPRODUCTS BUILD_COMMAND BUILD_IN_SOURCE CMAKE_ARGS CMAKE_CACHE_ARGS CMAKE_CACHE_DEFAULT_ARGS COMMENT CONFIGURE_COMMAND CVSROOT CVS_MODULE CVS_REPOSITORY CVS_TAG DEPENDEES DEPENDERS DEPENDS DOWNLOADED_FILE DOWNLOAD_COMMAND DOWNLOAD_DIR DOWNLOAD_NAME DOWNLOAD_NO_EXTRACT DOWNLOAD_NO_PROGRESS EP_BASE EP_INDEPENDENT_STEP_TARGETS EP_PREFIX EP_STEP_TARGETS EP_UPDATE_DISCONNECTED EXCLUDE_FROM_ALL FORCE GIT_CONFIG GIT_PROGRESS GIT_REMOTE_NAME GIT_REPOSITORY GIT_SHALLOW GIT_SUBMODULES GIT_TAG HG_REPOSITORY HG_TAG HTTP_HEADER HTTP_PASSWORD HTTP_USERNAME INDEPENDENT_STEP_TARGETS INSTALL_COMMAND INSTALL_DIR JOB_POOLS LIST_SEPARATOR LOG_BUILD LOG_CONFIGURE LOG_DOWNLOAD LOG_INSTALL LOG_TEST LOG_UPDATE NO_DEPENDS PATCH_COMMAND PREFIX PROPERTY SOURCE_DIR SOURCE_SUBDIR STAMP_DIR STEP_TARGETS SVN_PASSWORD SVN_REPOSITORY SVN_REVISION SVN_TRUST_CERT SVN_USERNAME TEST_AFTER_INSTALL TEST_BEFORE_INSTALL TEST_COMMAND TEST_EXCLUDE_FROM_MAIN TIMEOUT TLS_CAINFO TLS_VERIFY TMP_DIR UPDATE_COMMAND UPDATE_DISCONNECTED URL URL_HASH USES_TERMINAL_BUILD USES_TERMINAL_CONFIGURE USES_TERMINAL_DOWNLOAD USES_TERMINAL_INSTALL USES_TERMINAL_TEST USES_TERMINAL_UPDATE WORKING_DIRECTORY
+ \ AWS
+ \ BINARY_DIR
+ \ BUILD_ALWAYS
+ \ BUILD_BYPRODUCTS
+ \ BUILD_COMMAND
+ \ BUILD_IN_SOURCE
+ \ CMAKE_ARGS
+ \ CMAKE_CACHE_ARGS
+ \ CMAKE_CACHE_DEFAULT_ARGS
+ \ CMAKE_TLS_CAINFO
+ \ CMAKE_TLS_VERIFY
+ \ COMMENT
+ \ CONFIGURE_COMMAND
+ \ CVS
+ \ CVSROOT
+ \ CVS_MODULE
+ \ CVS_REPOSITORY
+ \ CVS_TAG
+ \ DEPENDEES
+ \ DEPENDERS
+ \ DEPENDS
+ \ DOWNLOADED_FILE
+ \ DOWNLOAD_COMMAND
+ \ DOWNLOAD_DIR
+ \ DOWNLOAD_NAME
+ \ DOWNLOAD_NO_EXTRACT
+ \ DOWNLOAD_NO_PROGRESS
+ \ EP_BASE
+ \ EP_INDEPENDENT_STEP_TARGETS
+ \ EP_PREFIX
+ \ EP_STEP_TARGETS
+ \ EP_UPDATE_DISCONNECTED
+ \ EXCLUDE_FROM_ALL
+ \ FORCE
+ \ GHS
+ \ GIT_CONFIG
+ \ GIT_PROGRESS
+ \ GIT_REMOTE_NAME
+ \ GIT_REPOSITORY
+ \ GIT_SHALLOW
+ \ GIT_SUBMODULES
+ \ GIT_TAG
+ \ HG_REPOSITORY
+ \ HG_TAG
+ \ HTTP_HEADER
+ \ HTTP_PASSWORD
+ \ HTTP_USERNAME
+ \ IGNORED
+ \ INDEPENDENT_STEP_TARGETS
+ \ INSTALL_COMMAND
+ \ INSTALL_DIR
+ \ JOB_POOLS
+ \ LIST_SEPARATOR
+ \ LOG_BUILD
+ \ LOG_CONFIGURE
+ \ LOG_DIR
+ \ LOG_DOWNLOAD
+ \ LOG_INSTALL
+ \ LOG_MERGED_STDOUTERR
+ \ LOG_OUTPUT_ON_FAILURE
+ \ LOG_PATCH
+ \ LOG_TEST
+ \ LOG_UPDATE
+ \ MAKE_EXE
+ \ MULTI
+ \ NAMES
+ \ NETRC
+ \ NETRC_FILE
+ \ NOTE
+ \ NO_DEPENDS
+ \ OPTIONAL
+ \ PATCH_COMMAND
+ \ PREFIX
+ \ PROPERTY
+ \ REQUIRED
+ \ SOURCE_DIR
+ \ SOURCE_SUBDIR
+ \ STAMP_DIR
+ \ STEP_TARGETS
+ \ STRING
+ \ SVN_PASSWORD
+ \ SVN_REPOSITORY
+ \ SVN_REVISION
+ \ SVN_TRUST_CERT
+ \ SVN_USERNAME
+ \ TEST_AFTER_INSTALL
+ \ TEST_BEFORE_INSTALL
+ \ TEST_COMMAND
+ \ TEST_EXCLUDE_FROM_MAIN
+ \ TIMEOUT
+ \ TLS_CAINFO
+ \ TLS_VERIFY
+ \ TMP_DIR
+ \ TRUE
+ \ UPDATE_COMMAND
+ \ UPDATE_DISCONNECTED
+ \ URL
+ \ URL_HASH
+ \ USES_TERMINAL_BUILD
+ \ USES_TERMINAL_CONFIGURE
+ \ USES_TERMINAL_DOWNLOAD
+ \ USES_TERMINAL_INSTALL
+ \ USES_TERMINAL_TEST
+ \ USES_TERMINAL_UPDATE
+ \ WORKING_DIRECTORY
+
+syn keyword cmakeKWadd_compile_definitions contained
+ \ COMPILE_DEFINITIONS
+ \ VAR
syn keyword cmakeKWadd_compile_options contained
\ COMPILE_OPTIONS
+ \ SHELL
+ \ UNIX_COMMAND
+ \ WX
syn keyword cmakeKWadd_custom_command contained
- \ APPEND ARGS BYPRODUCTS CC COMMAND COMMAND_EXPAND_LISTS COMMENT CROSSCOMPILING_EMULATOR DEPENDS DEPFILE GENERATED IMPLICIT_DEPENDS INCLUDE_DIRECTORIES JOIN MAIN_DEPENDENCY NOT OUTPUT POST_BUILD PRE_BUILD PRE_LINK SYMBOLIC TARGET_FILE TARGET_PROPERTY USES_TERMINAL VERBATIM WORKING_DIRECTORY
+ \ APPEND
+ \ ARGS
+ \ BYPRODUCTS
+ \ CC
+ \ COMMAND
+ \ COMMAND_EXPAND_LISTS
+ \ COMMENT
+ \ CROSSCOMPILING_EMULATOR
+ \ DEPENDS
+ \ DEPFILE
+ \ GENERATED
+ \ IMPLICIT_DEPENDS
+ \ INCLUDE_DIRECTORIES
+ \ JOB_POOL
+ \ JOB_POOLS
+ \ JOIN
+ \ MAIN_DEPENDENCY
+ \ NOT
+ \ OUTPUT
+ \ POST_BUILD
+ \ PRE_BUILD
+ \ PRE_LINK
+ \ SYMBOLIC
+ \ TARGET_FILE
+ \ TARGET_PROPERTY
+ \ USES_TERMINAL
+ \ VERBATIM
+ \ WORKING_DIRECTORY
syn keyword cmakeKWadd_custom_target contained
- \ ALL BYPRODUCTS CC COMMAND COMMAND_EXPAND_LISTS COMMENT CROSSCOMPILING_EMULATOR DEPENDS GENERATED INCLUDE_DIRECTORIES JOIN SOURCES TARGET_PROPERTY USES_TERMINAL VERBATIM WORKING_DIRECTORY
+ \ ALL
+ \ BYPRODUCTS
+ \ CC
+ \ COMMAND
+ \ COMMAND_EXPAND_LISTS
+ \ COMMENT
+ \ CROSSCOMPILING_EMULATOR
+ \ DEPENDS
+ \ GENERATED
+ \ INCLUDE_DIRECTORIES
+ \ JOB_POOL
+ \ JOB_POOLS
+ \ JOIN
+ \ SOURCES
+ \ TARGET_PROPERTY
+ \ USES_TERMINAL
+ \ VERBATIM
+ \ WORKING_DIRECTORY
syn keyword cmakeKWadd_definitions contained
\ COMPILE_DEFINITIONS
syn keyword cmakeKWadd_dependencies contained
- \ DEPENDS OBJECT_DEPENDS
+ \ DEPENDS
+ \ OBJECT_DEPENDS
syn keyword cmakeKWadd_executable contained
- \ ALIAS CONFIG EXCLUDE_FROM_ALL GLOBAL IMPORTED IMPORTED_ IMPORTED_LOCATION IMPORTED_LOCATION_ MACOSX_BUNDLE OUTPUT_NAME RUNTIME_OUTPUT_DIRECTORY TARGET
+ \ ALIAS
+ \ CONFIG
+ \ EXCLUDE_FROM_ALL
+ \ GLOBAL
+ \ HEADER_FILE_ONLY
+ \ IMPORTED
+ \ IMPORTED_
+ \ IMPORTED_LOCATION
+ \ IMPORTED_LOCATION_
+ \ MACOSX_BUNDLE
+ \ OUTPUT_NAME
+ \ RUNTIME_OUTPUT_DIRECTORY
+ \ TARGET
syn keyword cmakeKWadd_library contained
- \ ALIAS ARCHIVE_OUTPUT_DIRECTORY CLI CONFIG DLL EXCLUDE_FROM_ALL FRAMEWORK GLOBAL IMPORTED IMPORTED_ IMPORTED_LOCATION IMPORTED_LOCATION_ INTERFACE_ LIBRARY_OUTPUT_DIRECTORY MODULE OBJECT ON OUTPUT_NAME POSITION_INDEPENDENT_CODE POST_BUILD PRE_BUILD PRE_LINK RUNTIME_OUTPUT_DIRECTORY SHARED STATIC TARGET_OBJECTS UNKNOWN
+ \ ALIAS
+ \ ARCHIVE_OUTPUT_DIRECTORY
+ \ CLI
+ \ CONFIG
+ \ DLL
+ \ EXCLUDE_FROM_ALL
+ \ FRAMEWORK
+ \ GLOBAL
+ \ HEADER_FILE_ONLY
+ \ IMPORTED
+ \ IMPORTED_
+ \ IMPORTED_LOCATION
+ \ IMPORTED_LOCATION_
+ \ IMPORTED_OBJECTS
+ \ IMPORTED_OBJECTS_
+ \ INTERFACE_
+ \ LIBRARY_OUTPUT_DIRECTORY
+ \ MODULE
+ \ OBJECT
+ \ ON
+ \ OUTPUT_NAME
+ \ POSITION_INDEPENDENT_CODE
+ \ POST_BUILD
+ \ PRE_BUILD
+ \ PRE_LINK
+ \ PUBLIC_HEADER
+ \ RUNTIME_OUTPUT_DIRECTORY
+ \ SHARED
+ \ STATIC
+ \ TARGET_OBJECTS
+ \ UNKNOWN
+
+syn keyword cmakeKWadd_link_options contained
+ \ CMAKE_
+ \ GCC
+ \ GNU
+ \ LANG
+ \ LINKER
+ \ LINK_OPTIONS
+ \ SHELL
+ \ STATIC_LIBRARY_OPTIONS
+ \ UNIX_COMMAND
+ \ _LINKER_WRAPPER_FLAG
+ \ _LINKER_WRAPPER_FLAG_SEP
syn keyword cmakeKWadd_subdirectory contained
\ EXCLUDE_FROM_ALL
syn keyword cmakeKWadd_test contained
- \ BUILD_TESTING COMMAND CONFIGURATIONS FAIL_REGULAR_EXPRESSION NAME PASS_REGULAR_EXPRESSION TARGET_FILE WILL_FAIL WORKING_DIRECTORY
+ \ BUILD_TESTING
+ \ COMMAND
+ \ CONFIGURATIONS
+ \ FAIL_REGULAR_EXPRESSION
+ \ NAME
+ \ OFF
+ \ PASS_REGULAR_EXPRESSION
+ \ TARGET_FILE
+ \ WILL_FAIL
+ \ WORKING_DIRECTORY
syn keyword cmakeKWbuild_command contained
- \ CONFIGURATION TARGET
-
-syn keyword cmakeKWbuild_name contained
- \ CMAKE_CXX_COMPILER
+ \ CONFIGURATION
+ \ TARGET
syn keyword cmakeKWcmake_host_system_information contained
- \ AVAILABLE_PHYSICAL_MEMORY AVAILABLE_VIRTUAL_MEMORY FQDN HOSTNAME NUMBER_OF_LOGICAL_CORES NUMBER_OF_PHYSICAL_CORES QUERY RESULT TOTAL_PHYSICAL_MEMORY TOTAL_VIRTUAL_MEMORY
+ \ AVAILABLE_PHYSICAL_MEMORY
+ \ AVAILABLE_VIRTUAL_MEMORY
+ \ FQDN
+ \ HAS_FPU
+ \ HAS_MMX
+ \ HAS_MMX_PLUS
+ \ HAS_SERIAL_NUMBER
+ \ HAS_SSE
+ \ HAS_SSE_FP
+ \ HAS_SSE_MMX
+ \ HOSTNAME
+ \ ID
+ \ NUMBER_OF_LOGICAL_CORES
+ \ NUMBER_OF_PHYSICAL_CORES
+ \ OS_NAME
+ \ OS_PLATFORM
+ \ OS_RELEASE
+ \ OS_VERSION
+ \ PROCESSOR_DESCRIPTION
+ \ PROCESSOR_NAME
+ \ PROCESSOR_SERIAL_NUMBER
+ \ QUERY
+ \ RESULT
+ \ TOTAL_PHYSICAL_MEMORY
+ \ TOTAL_VIRTUAL_MEMORY
syn keyword cmakeKWcmake_minimum_required contained
- \ FATAL_ERROR VERSION
+ \ FATAL_ERROR
+ \ VERSION
syn keyword cmakeKWcmake_parse_arguments contained
- \ ARGN CONFIGURATIONS DESTINATION FALSE FAST FILES MY_INSTALL MY_INSTALL_CONFIGURATIONS MY_INSTALL_DESTINATION MY_INSTALL_FAST MY_INSTALL_OPTIONAL MY_INSTALL_RENAME MY_INSTALL_TARGETS MY_INSTALL_UNPARSED_ARGUMENTS OPTIONAL PARSE_ARGV RENAME TARGETS TRUE _UNPARSED_ARGUMENTS
+ \ ARGN
+ \ CONFIGURATIONS
+ \ DESTINATION
+ \ FALSE
+ \ FAST
+ \ FILES
+ \ MY_INSTALL
+ \ MY_INSTALL_CONFIGURATIONS
+ \ MY_INSTALL_DESTINATION
+ \ MY_INSTALL_FAST
+ \ MY_INSTALL_KEYWORDS_MISSING_VALUES
+ \ MY_INSTALL_OPTIONAL
+ \ MY_INSTALL_RENAME
+ \ MY_INSTALL_TARGETS
+ \ MY_INSTALL_UNPARSED_ARGUMENTS
+ \ OPTIONAL
+ \ PARSE_ARGV
+ \ RENAME
+ \ TARGETS
+ \ TRUE
+ \ UNDEFINED
+ \ _KEYWORDS_MISSING_VALUES
+ \ _UNPARSED_ARGUMENTS
syn keyword cmakeKWcmake_policy contained
- \ CMAKE_POLICY_DEFAULT_CMP CMP GET NNNN NO_POLICY_SCOPE OLD POP PUSH SET VERSION
+ \ CMAKE_POLICY_DEFAULT_CMP
+ \ CMP
+ \ GET
+ \ NNNN
+ \ NO_POLICY_SCOPE
+ \ OLD
+ \ POP
+ \ PUSH
+ \ SET
+ \ VERSION
syn keyword cmakeKWconfigure_file contained
- \ COPYONLY CRLF DOS ESCAPE_QUOTES FOO_ENABLE FOO_STRING LF NEWLINE_STYLE VAR
+ \ COPYONLY
+ \ CRLF
+ \ DOS
+ \ ESCAPE_QUOTES
+ \ FOO_ENABLE
+ \ FOO_STRING
+ \ LF
+ \ NEWLINE_STYLE
+ \ VAR
syn keyword cmakeKWcreate_test_sourcelist contained
- \ CMAKE_TESTDRIVER_AFTER_TESTMAIN CMAKE_TESTDRIVER_BEFORE_TESTMAIN EXTRA_INCLUDE FUNCTION
+ \ CMAKE_TESTDRIVER_AFTER_TESTMAIN
+ \ CMAKE_TESTDRIVER_BEFORE_TESTMAIN
+ \ EXTRA_INCLUDE
+ \ FUNCTION
syn keyword cmakeKWctest_build contained
- \ ALL_BUILD APPEND BUILD CAPTURE_CMAKE_ERROR CONFIGURATION CTEST_BUILD_CONFIGURATION CTEST_BUILD_FLAGS CTEST_BUILD_TARGET CTEST_PROJECT_NAME FLAGS NUMBER_ERRORS NUMBER_WARNINGS QUIET RETURN_VALUE TARGET
+ \ ALL_BUILD
+ \ APPEND
+ \ BUILD
+ \ CAPTURE_CMAKE_ERROR
+ \ CONFIGURATION
+ \ CTEST_BUILD_CONFIGURATION
+ \ CTEST_BUILD_FLAGS
+ \ CTEST_BUILD_TARGET
+ \ FLAGS
+ \ NUMBER_ERRORS
+ \ NUMBER_WARNINGS
+ \ QUIET
+ \ RETURN_VALUE
+ \ TARGET
syn keyword cmakeKWctest_configure contained
- \ APPEND BUILD CAPTURE_CMAKE_ERROR OPTIONS QUIET RETURN_VALUE SOURCE
+ \ APPEND
+ \ BUILD
+ \ CAPTURE_CMAKE_ERROR
+ \ OPTIONS
+ \ QUIET
+ \ RETURN_VALUE
+ \ SOURCE
syn keyword cmakeKWctest_coverage contained
- \ APPEND BUILD CAPTURE_CMAKE_ERROR LABELS QUIET RETURN_VALUE
+ \ APPEND
+ \ BUILD
+ \ CAPTURE_CMAKE_ERROR
+ \ LABELS
+ \ QUIET
+ \ RETURN_VALUE
syn keyword cmakeKWctest_memcheck contained
- \ APPEND BUILD DEFECT_COUNT EXCLUDE EXCLUDE_LABEL INCLUDE INCLUDE_LABEL OFF ON PARALLEL_LEVEL QUIET RETURN_VALUE SCHEDULE_RANDOM START STOP_TIME STRIDE TEST_LOAD
+ \ APPEND
+ \ BUILD
+ \ DEFECT_COUNT
+ \ EXCLUDE
+ \ EXCLUDE_FIXTURE
+ \ EXCLUDE_FIXTURE_CLEANUP
+ \ EXCLUDE_FIXTURE_SETUP
+ \ EXCLUDE_LABEL
+ \ INCLUDE
+ \ INCLUDE_LABEL
+ \ OFF
+ \ ON
+ \ PARALLEL_LEVEL
+ \ QUIET
+ \ RETURN_VALUE
+ \ SCHEDULE_RANDOM
+ \ START
+ \ STOP_TIME
+ \ STRIDE
+ \ TEST_LOAD
syn keyword cmakeKWctest_run_script contained
- \ NEW_PROCESS RETURN_VALUE
+ \ NEW_PROCESS
+ \ RETURN_VALUE
syn keyword cmakeKWctest_start contained
- \ APPEND QUIET TAG TRACK
+ \ APPEND
+ \ QUIET
+ \ TAG
+ \ TRACK
syn keyword cmakeKWctest_submit contained
- \ API CDASH_UPLOAD CDASH_UPLOAD_TYPE CTEST_EXTRA_SUBMIT_FILES CTEST_NOTES_FILES FILES PARTS QUIET RETRY_COUNT RETRY_DELAY RETURN_VALUE
+ \ API
+ \ BUILD_ID
+ \ CAPTURE_CMAKE_ERROR
+ \ CDASH_UPLOAD
+ \ CDASH_UPLOAD_TYPE
+ \ CTEST_EXTRA_SUBMIT_FILES
+ \ CTEST_NOTES_FILES
+ \ FILES
+ \ HTTPHEADER
+ \ PARTS
+ \ QUIET
+ \ RETRY_COUNT
+ \ RETRY_DELAY
+ \ RETURN_VALUE
+ \ SUBMIT_URL
syn keyword cmakeKWctest_test contained
- \ APPEND BUILD CAPTURE_CMAKE_ERROR CPU EXCLUDE EXCLUDE_LABEL INCLUDE INCLUDE_LABEL OFF ON PARALLEL_LEVEL QUIET RETURN_VALUE SCHEDULE_RANDOM START STOP_TIME STRIDE TEST_LOAD
+ \ APPEND
+ \ BUILD
+ \ CAPTURE_CMAKE_ERROR
+ \ CPU
+ \ EXCLUDE
+ \ EXCLUDE_FIXTURE
+ \ EXCLUDE_FIXTURE_CLEANUP
+ \ EXCLUDE_FIXTURE_SETUP
+ \ EXCLUDE_LABEL
+ \ INCLUDE
+ \ INCLUDE_LABEL
+ \ OFF
+ \ ON
+ \ PARALLEL_LEVEL
+ \ QUIET
+ \ RETURN_VALUE
+ \ SCHEDULE_RANDOM
+ \ START
+ \ STOP_TIME
+ \ STRIDE
+ \ TEST_LOAD
syn keyword cmakeKWctest_update contained
- \ QUIET RETURN_VALUE SOURCE
+ \ CAPTURE_CMAKE_ERROR
+ \ QUIET
+ \ RETURN_VALUE
+ \ SOURCE
syn keyword cmakeKWctest_upload contained
- \ CAPTURE_CMAKE_ERROR FILES QUIET
+ \ CAPTURE_CMAKE_ERROR
+ \ FILES
+ \ QUIET
syn keyword cmakeKWdefine_property contained
- \ BRIEF_DOCS CACHED_VARIABLE DIRECTORY FULL_DOCS GLOBAL INHERITED PROPERTY SOURCE TARGET TEST VARIABLE
+ \ APPEND
+ \ APPEND_STRING
+ \ BRIEF_DOCS
+ \ CACHED_VARIABLE
+ \ DIRECTORY
+ \ FULL_DOCS
+ \ GLOBAL
+ \ INHERITED
+ \ PROPERTY
+ \ SOURCE
+ \ TARGET
+ \ TEST
+ \ VARIABLE
syn keyword cmakeKWenable_language contained
+ \ ASM
+ \ CUDA
\ OPTIONAL
+syn keyword cmakeKWenable_testing contained
+ \ BUILD_TESTING
+
syn keyword cmakeKWexec_program contained
- \ ARGS OUTPUT_VARIABLE RETURN_VALUE
+ \ ARGS
+ \ OUTPUT_VARIABLE
+ \ RETURN_VALUE
syn keyword cmakeKWexecute_process contained
- \ ANSI AUTO COMMAND ENCODING ERROR_FILE ERROR_QUIET ERROR_STRIP_TRAILING_WHITESPACE ERROR_VARIABLE INPUT_FILE NONE OEM OUTPUT_FILE OUTPUT_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE RESULT_VARIABLE TIMEOUT UTF VERBATIM WORKING_DIRECTORY
+ \ ANSI
+ \ AUTO
+ \ COMMAND
+ \ COMMAND_ECHO
+ \ ENCODING
+ \ ERROR_FILE
+ \ ERROR_QUIET
+ \ ERROR_STRIP_TRAILING_WHITESPACE
+ \ ERROR_VARIABLE
+ \ INPUT_FILE
+ \ NONE
+ \ OEM
+ \ OUTPUT_FILE
+ \ OUTPUT_QUIET
+ \ OUTPUT_STRIP_TRAILING_WHITESPACE
+ \ OUTPUT_VARIABLE
+ \ RESULTS_VARIABLE
+ \ RESULT_VARIABLE
+ \ RFC
+ \ STDERR
+ \ STDOUT
+ \ TIMEOUT
+ \ UTF
+ \ VERBATIM
+ \ WORKING_DIRECTORY
syn keyword cmakeKWexport contained
- \ ANDROID_MK APPEND CONFIG EXPORT EXPORT_LINK_INTERFACE_LIBRARIES FILE IMPORTED IMPORTED_ NAMESPACE NDK OLD PACKAGE TARGETS
+ \ ANDROID_MK
+ \ APPEND
+ \ CONFIG
+ \ EXPORT
+ \ EXPORT_LINK_INTERFACE_LIBRARIES
+ \ FILE
+ \ IMPORTED
+ \ IMPORTED_
+ \ NAMESPACE
+ \ NDK
+ \ OLD
+ \ PACKAGE
+ \ TARGETS
syn keyword cmakeKWexport_library_dependencies contained
- \ APPEND EXPORT INCLUDE LINK_INTERFACE_LIBRARIES SET
+ \ APPEND
+ \ EXPORT
+ \ INCLUDE
+ \ LINK_INTERFACE_LIBRARIES
+ \ SET
syn keyword cmakeKWfile contained
- \ ALGO APPEND ASCII CMAKE_TLS_CAINFO CMAKE_TLS_VERIFY CONDITION CONFIG CONTENT COPY CR DESTINATION DIRECTORY_PERMISSIONS DOWNLOAD ENCODING EXCLUDE EXPECTED_HASH FILES_MATCHING FILE_PERMISSIONS FOLLOW_SYMLINKS FUNCTION GENERATE GLOB GLOB_RECURSE GUARD HASH HEX HTTPHEADER INACTIVITY_TIMEOUT INSTALL LENGTH_MAXIMUM LENGTH_MINIMUM LF LIMIT LIMIT_COUNT LIMIT_INPUT LIMIT_OUTPUT LIST_DIRECTORIES LOCK LOG MAKE_DIRECTORY NEWLINE_CONSUME NO_HEX_CONVERSION NO_SOURCE_PERMISSIONS OFFSET OLD PATTERN PROCESS READ REGEX RELATIVE RELATIVE_PATH RELEASE REMOVE REMOVE_RECURSE RENAME RESULT_VARIABLE SHOW_PROGRESS SORT SSL STATUS STRINGS TIMESTAMP TLS_CAINFO TLS_VERIFY TO_CMAKE_PATH TO_NATIVE_PATH UPLOAD USERPWD USE_SOURCE_PERMISSIONS UTC UTF WRITE
+ \ ALGO
+ \ APPEND
+ \ ASCII
+ \ CMAKE_TLS_CAINFO
+ \ CMAKE_TLS_VERIFY
+ \ CONDITION
+ \ CONFIG
+ \ CONFIGURE_DEPENDS
+ \ CONTENT
+ \ COPY
+ \ COPY_ON_ERROR
+ \ CREATE_LINK
+ \ DESTINATION
+ \ DIRECTORY_PERMISSIONS
+ \ DOWNLOAD
+ \ ENCODING
+ \ EXCLUDE
+ \ EXPECTED_HASH
+ \ FILES_MATCHING
+ \ FILE_PERMISSIONS
+ \ FOLLOW_SYMLINKS
+ \ FOLLOW_SYMLINK_CHAIN
+ \ FUNCTION
+ \ GENERATE
+ \ GLOB
+ \ GLOB_RECURSE
+ \ GUARD
+ \ HASH
+ \ HEX
+ \ HTTPHEADER
+ \ IGNORED
+ \ INACTIVITY_TIMEOUT
+ \ INSTALL
+ \ IS_ABSOLUTE
+ \ LENGTH_MAXIMUM
+ \ LENGTH_MINIMUM
+ \ LF
+ \ LIMIT
+ \ LIMIT_COUNT
+ \ LIMIT_INPUT
+ \ LIMIT_OUTPUT
+ \ LIST_DIRECTORIES
+ \ LOCK
+ \ LOG
+ \ MAKE_DIRECTORY
+ \ NETRC
+ \ NETRC_FILE
+ \ NEWLINE_CONSUME
+ \ NOT
+ \ NO_HEX_CONVERSION
+ \ NO_SOURCE_PERMISSIONS
+ \ OFFSET
+ \ OLD
+ \ OPTIONAL
+ \ OUTPUT
+ \ PATTERN
+ \ PROCESS
+ \ READ
+ \ READ_SYMLINK
+ \ REGEX
+ \ RELATIVE_PATH
+ \ RELEASE
+ \ REMOVE
+ \ REMOVE_RECURSE
+ \ RENAME
+ \ REQUIRED
+ \ RESULT
+ \ RESULT_VARIABLE
+ \ SHOW_PROGRESS
+ \ SIZE
+ \ SSL
+ \ STATUS
+ \ STRINGS
+ \ SYMBOLIC
+ \ TIMESTAMP
+ \ TLS_CAINFO
+ \ TLS_VERIFY
+ \ TOUCH
+ \ TOUCH_NOCREATE
+ \ TO_CMAKE_PATH
+ \ TO_NATIVE_PATH
+ \ UPLOAD
+ \ URL
+ \ USERPWD
+ \ USE_SOURCE_PERMISSIONS
+ \ UTC
+ \ UTF
+ \ WRITE
syn keyword cmakeKWfind_file contained
- \ CMAKE_FIND_ROOT_PATH_BOTH DOC DVAR HINTS INCLUDE NAMES NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH ONLY_CMAKE_FIND_ROOT_PATH OS PATHS PATH_SUFFIXES VAR
+ \ CMAKE_FIND_ROOT_PATH_BOTH
+ \ DOC
+ \ DVAR
+ \ HINTS
+ \ INCLUDE
+ \ NAMES
+ \ NO_CMAKE_ENVIRONMENT_PATH
+ \ NO_CMAKE_FIND_ROOT_PATH
+ \ NO_CMAKE_PATH
+ \ NO_CMAKE_SYSTEM_PATH
+ \ NO_DEFAULT_PATH
+ \ NO_PACKAGE_ROOT_PATH
+ \ NO_SYSTEM_ENVIRONMENT_PATH
+ \ ONLY_CMAKE_FIND_ROOT_PATH
+ \ PATHS
+ \ PATH_SUFFIXES
+ \ VAR
syn keyword cmakeKWfind_library contained
- \ CMAKE_FIND_ROOT_PATH_BOTH DOC DVAR HINTS LIB NAMES NAMES_PER_DIR NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH ONLY_CMAKE_FIND_ROOT_PATH OS PATHS PATH_SUFFIXES VAR
+ \ CMAKE_FIND_ROOT_PATH_BOTH
+ \ DOC
+ \ DVAR
+ \ HINTS
+ \ LIB
+ \ NAMES
+ \ NAMES_PER_DIR
+ \ NO_CMAKE_ENVIRONMENT_PATH
+ \ NO_CMAKE_FIND_ROOT_PATH
+ \ NO_CMAKE_PATH
+ \ NO_CMAKE_SYSTEM_PATH
+ \ NO_DEFAULT_PATH
+ \ NO_PACKAGE_ROOT_PATH
+ \ NO_SYSTEM_ENVIRONMENT_PATH
+ \ ONLY_CMAKE_FIND_ROOT_PATH
+ \ PATHS
+ \ PATH_SUFFIXES
+ \ VAR
syn keyword cmakeKWfind_package contained
- \ CMAKE_DISABLE_FIND_PACKAGE_ CMAKE_FIND_ROOT_PATH_BOTH COMPONENTS CONFIG CONFIGS DEC DVAR EXACT HINTS MODULE NAMES NATURAL NO_CMAKE_BUILDS_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_PATH NO_CMAKE_SYSTEM_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH NO_MODULE NO_POLICY_SCOPE NO_SYSTEM_ENVIRONMENT_PATH ONLY_CMAKE_FIND_ROOT_PATH OPTIONAL_COMPONENTS OS PACKAGE_FIND_NAME PACKAGE_FIND_VERSION PACKAGE_FIND_VERSION_COUNT PACKAGE_FIND_VERSION_MAJOR PACKAGE_FIND_VERSION_MINOR PACKAGE_FIND_VERSION_PATCH PACKAGE_FIND_VERSION_TWEAK PACKAGE_VERSION PACKAGE_VERSION_COMPATIBLE PACKAGE_VERSION_EXACT PACKAGE_VERSION_UNSUITABLE PATHS PATH_SUFFIXES QUIET REQUIRED SET TRUE _CONFIG _CONSIDERED_CONFIGS _CONSIDERED_VERSIONS _DIR _FIND_COMPONENTS _FIND_QUIETLY _FIND_REQUIRED _FIND_REQUIRED_ _FIND_VERSION_EXACT _FOUND
+ \ ABI
+ \ BUNDLE
+ \ CMAKE_DISABLE_FIND_PACKAGE_
+ \ CMAKE_FIND_ROOT_PATH_BOTH
+ \ COMPONENTS
+ \ CONFIG
+ \ CONFIGS
+ \ DEC
+ \ DVAR
+ \ EXACT
+ \ FRAMEWORK
+ \ HINTS
+ \ MODULE
+ \ NAMES
+ \ NATURAL
+ \ NO_CMAKE_BUILDS_PATH
+ \ NO_CMAKE_ENVIRONMENT_PATH
+ \ NO_CMAKE_FIND_ROOT_PATH
+ \ NO_CMAKE_PACKAGE_REGISTRY
+ \ NO_CMAKE_PATH
+ \ NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
+ \ NO_CMAKE_SYSTEM_PATH
+ \ NO_DEFAULT_PATH
+ \ NO_MODULE
+ \ NO_PACKAGE_ROOT_PATH
+ \ NO_POLICY_SCOPE
+ \ NO_SYSTEM_ENVIRONMENT_PATH
+ \ ONLY_CMAKE_FIND_ROOT_PATH
+ \ OPTIONAL_COMPONENTS
+ \ PACKAGE_FIND_NAME
+ \ PACKAGE_FIND_VERSION
+ \ PACKAGE_FIND_VERSION_COUNT
+ \ PACKAGE_FIND_VERSION_MAJOR
+ \ PACKAGE_FIND_VERSION_MINOR
+ \ PACKAGE_FIND_VERSION_PATCH
+ \ PACKAGE_FIND_VERSION_TWEAK
+ \ PACKAGE_VERSION
+ \ PACKAGE_VERSION_COMPATIBLE
+ \ PACKAGE_VERSION_EXACT
+ \ PACKAGE_VERSION_UNSUITABLE
+ \ PATHS
+ \ PATH_SUFFIXES
+ \ QUIET
+ \ REQUIRED
+ \ SET
+ \ TRUE
+ \ _CONFIG
+ \ _CONSIDERED_CONFIGS
+ \ _CONSIDERED_VERSIONS
+ \ _DIR
+ \ _FIND_COMPONENTS
+ \ _FIND_QUIETLY
+ \ _FIND_REQUIRED
+ \ _FIND_REQUIRED_
+ \ _FIND_VERSION_EXACT
+ \ _FOUND
syn keyword cmakeKWfind_path contained
- \ CMAKE_FIND_ROOT_PATH_BOTH DOC DVAR HINTS INCLUDE NAMES NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH ONLY_CMAKE_FIND_ROOT_PATH OS PATHS PATH_SUFFIXES VAR
+ \ CMAKE_FIND_ROOT_PATH_BOTH
+ \ DOC
+ \ DVAR
+ \ HINTS
+ \ INCLUDE
+ \ NAMES
+ \ NO_CMAKE_ENVIRONMENT_PATH
+ \ NO_CMAKE_FIND_ROOT_PATH
+ \ NO_CMAKE_PATH
+ \ NO_CMAKE_SYSTEM_PATH
+ \ NO_DEFAULT_PATH
+ \ NO_PACKAGE_ROOT_PATH
+ \ NO_SYSTEM_ENVIRONMENT_PATH
+ \ ONLY_CMAKE_FIND_ROOT_PATH
+ \ PATHS
+ \ PATH_SUFFIXES
+ \ VAR
syn keyword cmakeKWfind_program contained
- \ CMAKE_FIND_ROOT_PATH_BOTH DOC DVAR HINTS NAMES NAMES_PER_DIR NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_FIND_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_SYSTEM_PATH NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH ONLY_CMAKE_FIND_ROOT_PATH OS PATHS PATH_SUFFIXES VAR
+ \ CMAKE_FIND_ROOT_PATH_BOTH
+ \ DOC
+ \ DVAR
+ \ HINTS
+ \ NAMES
+ \ NAMES_PER_DIR
+ \ NO_CMAKE_ENVIRONMENT_PATH
+ \ NO_CMAKE_FIND_ROOT_PATH
+ \ NO_CMAKE_PATH
+ \ NO_CMAKE_SYSTEM_PATH
+ \ NO_DEFAULT_PATH
+ \ NO_PACKAGE_ROOT_PATH
+ \ NO_SYSTEM_ENVIRONMENT_PATH
+ \ ONLY_CMAKE_FIND_ROOT_PATH
+ \ PATHS
+ \ PATH_SUFFIXES
+ \ VAR
syn keyword cmakeKWfltk_wrap_ui contained
\ FLTK
syn keyword cmakeKWforeach contained
- \ ARGS IN ITEMS LISTS RANGE
+ \ IN
+ \ ITEMS
+ \ LISTS
+ \ RANGE
+ \ STATUS
syn keyword cmakeKWfunction contained
- \ ARGC ARGN ARGS ARGV PARENT_SCOPE
+ \ ARGC
+ \ ARGN
+ \ ARGV
+ \ FOO
+ \ PARENT_SCOPE
syn keyword cmakeKWget_cmake_property contained
- \ COMPONENTS GLOBAL MACROS VAR VARIABLES
+ \ COMPONENTS
+ \ GLOBAL
+ \ MACROS
+ \ VARIABLES
syn keyword cmakeKWget_directory_property contained
- \ DEFINITION DIRECTORY
+ \ DEFINITION
+ \ DIRECTORY
+ \ INHERITED
syn keyword cmakeKWget_filename_component contained
- \ ABSOLUTE ARG_VAR BASE_DIR CACHE COMP DIRECTORY EXT NAME NAME_WE PATH PROGRAM PROGRAM_ARGS REALPATH VAR
+ \ ABSOLUTE
+ \ BASE_DIR
+ \ DIRECTORY
+ \ EXT
+ \ LAST_EXT
+ \ NAME
+ \ NAME_WE
+ \ NAME_WLE
+ \ PATH
+ \ PROGRAM
+ \ PROGRAM_ARGS
+ \ REALPATH
syn keyword cmakeKWget_property contained
- \ BRIEF_DOCS CACHE DEFINED DIRECTORY FULL_DOCS GLOBAL INSTALL PROPERTY SET SOURCE TARGET TEST VARIABLE
+ \ BRIEF_DOCS
+ \ DEFINED
+ \ DIRECTORY
+ \ FULL_DOCS
+ \ GLOBAL
+ \ INSTALL
+ \ PROPERTY
+ \ SET
+ \ SOURCE
+ \ TARGET
+ \ TEST
+ \ VARIABLE
syn keyword cmakeKWget_source_file_property contained
- \ LOCATION VAR
+ \ INHERITED
+ \ LOCATION
+ \ VAR
syn keyword cmakeKWget_target_property contained
+ \ INHERITED
\ VAR
syn keyword cmakeKWget_test_property contained
+ \ INHERITED
\ VAR
syn keyword cmakeKWif contained
- \ ARGS CMAKE_MATCH_ CMP COMMAND DEFINED EQUAL EXISTS FALSE GREATER GREATER_EQUAL IGNORE IN_LIST IS_ABSOLUTE IS_DIRECTORY IS_NEWER_THAN IS_SYMLINK LESS LESS_EQUAL MATCHES NNNN NOT OFF OR POLICY STREQUAL STRGREATER STRGREATER_EQUAL STRLESS STRLESS_EQUAL TARGET TEST THEN TRUE VERSION_EQUAL VERSION_GREATER VERSION_GREATER_EQUAL VERSION_LESS VERSION_LESS_EQUAL YES
+ \ CMAKE_MATCH_
+ \ CMP
+ \ COMMAND
+ \ DEFINED
+ \ EQUAL
+ \ EXISTS
+ \ FALSE
+ \ GREATER
+ \ GREATER_EQUAL
+ \ IGNORE
+ \ IN_LIST
+ \ IS_ABSOLUTE
+ \ IS_DIRECTORY
+ \ IS_NEWER_THAN
+ \ IS_SYMLINK
+ \ LESS
+ \ LESS_EQUAL
+ \ MATCHES
+ \ NNNN
+ \ NOT
+ \ OFF
+ \ OR
+ \ POLICY
+ \ STREQUAL
+ \ STRGREATER
+ \ STRGREATER_EQUAL
+ \ STRLESS
+ \ STRLESS_EQUAL
+ \ TARGET
+ \ TEST
+ \ TRUE
+ \ VERSION_EQUAL
+ \ VERSION_GREATER
+ \ VERSION_GREATER_EQUAL
+ \ VERSION_LESS
+ \ VERSION_LESS_EQUAL
+ \ YES
syn keyword cmakeKWinclude contained
- \ NO_POLICY_SCOPE OPTIONAL RESULT_VARIABLE
+ \ NO_POLICY_SCOPE
+ \ OPTIONAL
+ \ RESULT_VARIABLE
syn keyword cmakeKWinclude_directories contained
- \ AFTER BEFORE INCLUDE_DIRECTORIES ON SYSTEM
+ \ AFTER
+ \ BEFORE
+ \ INCLUDE_DIRECTORIES
+ \ ON
+ \ SYSTEM
syn keyword cmakeKWinclude_external_msproject contained
- \ GUID MAP_IMPORTED_CONFIG_ PLATFORM TYPE WIX
+ \ GUID
+ \ MAP_IMPORTED_CONFIG_
+ \ PLATFORM
+ \ TYPE
+ \ WIX
+
+syn keyword cmakeKWinclude_guard contained
+ \ DIRECTORY
+ \ GLOBAL
+ \ TRUE
+ \ __CURRENT_FILE_VAR__
syn keyword cmakeKWinstall contained
- \ ARCHIVE BUNDLE CODE COMPONENT CONFIGURATIONS CVS DESTDIR DESTINATION DIRECTORY DIRECTORY_PERMISSIONS DLL EXCLUDE_FROM_ALL EXPORT EXPORT_ANDROID_MK EXPORT_LINK_INTERFACE_LIBRARIES FILES FILES_MATCHING FILE_PERMISSIONS FRAMEWORK GROUP_EXECUTE GROUP_READ GROUP_WRITE IMPORTED_ INCLUDES INSTALL_PREFIX INTERFACE_INCLUDE_DIRECTORIES LIBRARY MACOSX_BUNDLE MESSAGE_NEVER NAMELINK_ONLY NAMELINK_SKIP NAMESPACE NDK OBJECTS OPTIONAL OWNER_EXECUTE OWNER_READ OWNER_WRITE PATTERN PERMISSIONS POST_INSTALL_SCRIPT PRE_INSTALL_SCRIPT PRIVATE_HEADER PROGRAMS PUBLIC_HEADER REGEX RENAME RESOURCE RUNTIME SCRIPT SETGID SETUID SOVERSION TARGETS TRUE USE_SOURCE_PERMISSIONS VERSION WORLD_EXECUTE WORLD_READ WORLD_WRITE
+ \ AFTER
+ \ APT
+ \ ARCHIVE
+ \ BEFORE
+ \ BUILD_TYPE
+ \ BUNDLE
+ \ CMAKE_INSTALL_BINDIR
+ \ CMAKE_INSTALL_DATADIR
+ \ CMAKE_INSTALL_DATAROOTDIR
+ \ CMAKE_INSTALL_DOCDIR
+ \ CMAKE_INSTALL_INCLUDEDIR
+ \ CMAKE_INSTALL_INFODIR
+ \ CMAKE_INSTALL_LIBDIR
+ \ CMAKE_INSTALL_LOCALEDIR
+ \ CMAKE_INSTALL_LOCALSTATEDIR
+ \ CMAKE_INSTALL_MANDIR
+ \ CMAKE_INSTALL_RUNSTATEDIR
+ \ CMAKE_INSTALL_SBINDIR
+ \ CMAKE_INSTALL_SHARESTATEDIR
+ \ CMAKE_INSTALL_SYSCONFDIR
+ \ CODE
+ \ COMPONENT
+ \ CONFIGURATIONS
+ \ CVS
+ \ DATA
+ \ DATAROOT
+ \ DBUILD_TYPE
+ \ DCOMPONENT
+ \ DESTDIR
+ \ DESTINATION
+ \ DIRECTORY
+ \ DIRECTORY_PERMISSIONS
+ \ DLL
+ \ DOC
+ \ EXCLUDE_FROM_ALL
+ \ EXPORT
+ \ EXPORT_ANDROID_MK
+ \ EXPORT_LINK_INTERFACE_LIBRARIES
+ \ EXPORT_NAME
+ \ FILES
+ \ FILES_MATCHING
+ \ FILE_PERMISSIONS
+ \ FRAMEWORK
+ \ GROUP_EXECUTE
+ \ GROUP_READ
+ \ GROUP_WRITE
+ \ IMPORTED_
+ \ INCLUDES
+ \ INFO
+ \ INSTALL_PREFIX
+ \ INTERFACE_INCLUDE_DIRECTORIES
+ \ LIBRARY
+ \ LOCALE
+ \ LOCALSTATE
+ \ MACOSX_BUNDLE
+ \ MAN
+ \ MESSAGE_NEVER
+ \ NAMELINK_COMPONENT
+ \ NAMELINK_ONLY
+ \ NAMELINK_SKIP
+ \ NAMESPACE
+ \ NDK
+ \ OBJECTS
+ \ OPTIONAL
+ \ OWNER_EXECUTE
+ \ OWNER_READ
+ \ OWNER_WRITE
+ \ PATTERN
+ \ PERMISSIONS
+ \ POST_INSTALL_SCRIPT
+ \ PRE_INSTALL_SCRIPT
+ \ PRIVATE_HEADER
+ \ PROGRAMS
+ \ PROPERTIES
+ \ PUBLIC_HEADER
+ \ REGEX
+ \ RENAME
+ \ RESOURCE
+ \ RPM
+ \ RUNSTATE
+ \ RUNTIME
+ \ SBIN
+ \ SCRIPT
+ \ SETGID
+ \ SETUID
+ \ SHAREDSTATE
+ \ SOVERSION
+ \ STATIC
+ \ SYSCONF
+ \ TARGETS
+ \ TRUE
+ \ TYPE
+ \ USE_SOURCE_PERMISSIONS
+ \ VERSION
+ \ WORLD_EXECUTE
+ \ WORLD_READ
+ \ WORLD_WRITE
syn keyword cmakeKWinstall_files contained
- \ FILES GLOB
+ \ FILES
+ \ GLOB
syn keyword cmakeKWinstall_programs contained
- \ FILES GLOB PROGRAMS TARGETS
+ \ FILES
+ \ GLOB
+ \ PROGRAMS
+ \ TARGETS
syn keyword cmakeKWinstall_targets contained
- \ DLL RUNTIME_DIRECTORY TARGETS
+ \ DLL
+ \ RUNTIME_DIRECTORY
+
+syn keyword cmakeKWlink_directories contained
+ \ AFTER
+ \ BEFORE
+ \ LINK_DIRECTORIES
+ \ ON
+ \ ORIGIN
+ \ RPATH
syn keyword cmakeKWlist contained
- \ APPEND CACHE EXCLUDE FILTER FIND GET INCLUDE INSERT INTERNAL LENGTH LIST NOTES PARENT_SCOPE REGEX REMOVE_AT REMOVE_DUPLICATES REMOVE_ITEM REVERSE SORT
+ \ ACTION
+ \ APPEND
+ \ ASCENDING
+ \ CASE
+ \ COMPARE
+ \ DESCENDING
+ \ EXCLUDE
+ \ FILE_BASENAME
+ \ FILTER
+ \ FIND
+ \ GENEX_STRIP
+ \ GET
+ \ INCLUDE
+ \ INSENSITIVE
+ \ INSERT
+ \ INTERNAL
+ \ JOIN
+ \ LENGTH
+ \ ORDER
+ \ OUTPUT_VARIABLE
+ \ PARENT_SCOPE
+ \ POP_BACK
+ \ POP_FRONT
+ \ PREPEND
+ \ REGEX
+ \ REMOVE_AT
+ \ REMOVE_DUPLICATES
+ \ REMOVE_ITEM
+ \ REPLACE
+ \ REVERSE
+ \ SELECTOR
+ \ SENSITIVE
+ \ SORT
+ \ STRING
+ \ STRIP
+ \ SUBLIST
+ \ TOLOWER
+ \ TOUPPER
+ \ TRANSFORM
syn keyword cmakeKWload_cache contained
- \ EXCLUDE INCLUDE_INTERNALS READ_WITH_PREFIX
+ \ EXCLUDE
+ \ INCLUDE_INTERNALS
+ \ READ_WITH_PREFIX
syn keyword cmakeKWload_command contained
- \ CMAKE_LOADED_COMMAND_ COMMAND_NAME
+ \ CMAKE_LOADED_COMMAND_
+ \ COMMAND_NAME
syn keyword cmakeKWmacro contained
- \ ARGC ARGN ARGS ARGV DEFINED GREATER LISTS NOT _BAR _FOO
-
-syn keyword cmakeKWmake_directory contained
- \ MAKE_DIRECTORY
+ \ ARGC
+ \ ARGN
+ \ ARGV
+ \ DEFINED
+ \ FOO
+ \ GREATER
+ \ LISTS
+ \ NOT
syn keyword cmakeKWmark_as_advanced contained
- \ CLEAR FORCE VAR
+ \ CLEAR
+ \ FORCE
syn keyword cmakeKWmath contained
\ EXPR
+ \ HEXADECIMAL
+ \ OUTPUT_FORMAT
syn keyword cmakeKWmessage contained
- \ AUTHOR_WARNING DEPRECATION FATAL_ERROR GUI SEND_ERROR STATUS WARNING
+ \ AUTHOR_WARNING
+ \ DEBUG
+ \ DEPRECATION
+ \ FATAL_ERROR
+ \ GUI
+ \ NOTICE
+ \ SEND_ERROR
+ \ STATUS
+ \ TRACE
+ \ VERBOSE
+ \ WARNING
syn keyword cmakeKWoption contained
- \ OFF ON
+ \ OFF
+ \ ON
syn keyword cmakeKWproject contained
- \ CMAKE_PROJECT_ DESCRIPTION LANGUAGES NAME NONE PROJECT VERSION _BINARY_DIR _INCLUDE _SOURCE_DIR _VERSION _VERSION_MAJOR _VERSION_MINOR _VERSION_PATCH _VERSION_TWEAK
+ \ ASM
+ \ CMAKE_PROJECT_
+ \ CUDA
+ \ DESCRIPTION
+ \ HOMEPAGE_URL
+ \ LANGUAGES
+ \ NAME
+ \ NONE
+ \ PROJECT
+ \ VERSION
+ \ _BINARY_DIR
+ \ _DESCRIPTION
+ \ _HOMEPAGE_URL
+ \ _INCLUDE
+ \ _SOURCE_DIR
+ \ _VERSION
+ \ _VERSION_MAJOR
+ \ _VERSION_MINOR
+ \ _VERSION_PATCH
+ \ _VERSION_TWEAK
+
+syn keyword cmakeKWqt_wrap_cpp contained
+ \ AUTOMOC
+
+syn keyword cmakeKWqt_wrap_ui contained
+ \ AUTOUIC
syn keyword cmakeKWremove contained
- \ REMOVE_ITEM VALUE VAR
+ \ VALUE
+ \ VAR
syn keyword cmakeKWseparate_arguments contained
- \ MSDN NATIVE NATIVE_COMMAND UNIX_COMMAND WINDOWS WINDOWS_COMMAND _COMMAND
+ \ MSDN
+ \ NATIVE_COMMAND
+ \ UNIX_COMMAND
+ \ WINDOWS_COMMAND
syn keyword cmakeKWset contained
- \ BOOL CACHE FILEPATH FORCE INTERNAL OFF ON PARENT_SCOPE STRING STRINGS
+ \ BOOL
+ \ FILEPATH
+ \ FORCE
+ \ INTERNAL
+ \ OFF
+ \ ON
+ \ PARENT_SCOPE
+ \ STRING
+ \ STRINGS
syn keyword cmakeKWset_directory_properties contained
+ \ DIRECTORY
\ PROPERTIES
syn keyword cmakeKWset_property contained
- \ APPEND APPEND_STRING CACHE DIRECTORY GLOBAL INSTALL PROPERTY SOURCE TARGET TEST WIX
+ \ APPEND
+ \ APPEND_STRING
+ \ DIRECTORY
+ \ GLOBAL
+ \ INHERITED
+ \ INSTALL
+ \ PROPERTY
+ \ SOURCE
+ \ TARGET
+ \ TEST
+ \ WIX
syn keyword cmakeKWset_source_files_properties contained
\ PROPERTIES
+ \ SOURCE
syn keyword cmakeKWset_target_properties contained
\ PROPERTIES
+ \ TARGET
syn keyword cmakeKWset_tests_properties contained
\ PROPERTIES
+ \ TEST
syn keyword cmakeKWsource_group contained
- \ FILES PREFIX REGULAR_EXPRESSION TREE
+ \ FILES
+ \ PREFIX
+ \ REGULAR_EXPRESSION
+ \ TREE
syn keyword cmakeKWstring contained
- \ ALPHABET APPEND ASCII CMAKE_MATCH_ COMPARE CONCAT CONFIGURE EQUAL ESCAPE_QUOTES FIND GENEX_STRIP GREATER GREATER_EQUAL GUID HASH LENGTH LESS LESS_EQUAL MAKE_C_IDENTIFIER MATCH MATCHALL MATCHES NAMESPACE NOTEQUAL ONLY RANDOM RANDOM_SEED REGEX REPLACE REVERSE RFC SHA SOURCE_DATE_EPOCH STRIP SUBSTRING SZ TIMESTAMP TOLOWER TOUPPER TYPE US UTC UUID
+ \ ALPHABET
+ \ APPEND
+ \ ASCII
+ \ CMAKE_MATCH_
+ \ COMPARE
+ \ CONCAT
+ \ CONFIGURE
+ \ EQUAL
+ \ ESCAPE_QUOTES
+ \ FIND
+ \ GENEX_STRIP
+ \ GREATER
+ \ GREATER_EQUAL
+ \ GUID
+ \ HASH
+ \ JOIN
+ \ LENGTH
+ \ LESS
+ \ LESS_EQUAL
+ \ MAKE_C_IDENTIFIER
+ \ MATCH
+ \ MATCHALL
+ \ MATCHES
+ \ NAMESPACE
+ \ NOTEQUAL
+ \ ONLY
+ \ PREPEND
+ \ RANDOM
+ \ RANDOM_SEED
+ \ REGEX
+ \ REPEAT
+ \ REPLACE
+ \ REVERSE
+ \ RFC
+ \ SHA
+ \ SOURCE_DATE_EPOCH
+ \ STRIP
+ \ SUBSTRING
+ \ SZ
+ \ TIMESTAMP
+ \ TOLOWER
+ \ TOUPPER
+ \ TYPE
+ \ US
+ \ UTC
+ \ UUID
syn keyword cmakeKWsubdirs contained
- \ EXCLUDE_FROM_ALL PREORDER
+ \ EXCLUDE_FROM_ALL
+ \ PREORDER
syn keyword cmakeKWtarget_compile_definitions contained
- \ COMPILE_DEFINITIONS INTERFACE INTERFACE_COMPILE_DEFINITIONS PRIVATE PUBLIC
+ \ ALIAS
+ \ COMPILE_DEFINITIONS
+ \ FOO
+ \ IMPORTED
+ \ INTERFACE
+ \ INTERFACE_COMPILE_DEFINITIONS
+ \ PRIVATE
+ \ PUBLIC
syn keyword cmakeKWtarget_compile_features contained
- \ COMPILE_FEATURES IMPORTED INTERFACE INTERFACE_COMPILE_FEATURES PRIVATE PUBLIC
+ \ ALIAS
+ \ COMPILE_FEATURES
+ \ IMPORTED
+ \ INTERFACE
+ \ INTERFACE_COMPILE_FEATURES
+ \ PRIVATE
+ \ PUBLIC
syn keyword cmakeKWtarget_compile_options contained
- \ BEFORE COMPILE_OPTIONS IMPORTED INTERFACE INTERFACE_COMPILE_OPTIONS PRIVATE PUBLIC
+ \ ALIAS
+ \ BEFORE
+ \ COMPILE_OPTIONS
+ \ IMPORTED
+ \ INTERFACE
+ \ INTERFACE_COMPILE_OPTIONS
+ \ PRIVATE
+ \ PUBLIC
+ \ SHELL
+ \ UNIX_COMMAND
syn keyword cmakeKWtarget_include_directories contained
- \ BEFORE BUILD_INTERFACE IMPORTED INCLUDE_DIRECTORIES INSTALL_INTERFACE INTERFACE INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES PRIVATE PUBLIC SYSTEM
+ \ ALIAS
+ \ BEFORE
+ \ BUILD_INTERFACE
+ \ IMPORTED
+ \ INCLUDE_DIRECTORIES
+ \ INSTALL_INTERFACE
+ \ INTERFACE
+ \ INTERFACE_INCLUDE_DIRECTORIES
+ \ INTERFACE_LINK_LIBRARIES
+ \ INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
+ \ PRIVATE
+ \ PUBLIC
+ \ SYSTEM
+
+syn keyword cmakeKWtarget_link_directories contained
+ \ ALIAS
+ \ BEFORE
+ \ IMPORTED
+ \ INTERFACE
+ \ INTERFACE_LINK_DIRECTORIES
+ \ LINK_DIRECTORIES
+ \ ORIGIN
+ \ PRIVATE
+ \ PUBLIC
+ \ RPATH
syn keyword cmakeKWtarget_link_libraries contained
- \ ALIAS DAG DEBUG_CONFIGURATIONS IMPORTED IMPORTED_NO_SONAME INTERFACE INTERFACE_LINK_LIBRARIES LINK_FLAGS LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_DEBUG LINK_INTERFACE_MULTIPLICITY LINK_PRIVATE LINK_PUBLIC OLD OSX PRIVATE PUBLIC STATIC
+ \ ALIAS
+ \ DA
+ \ DAG
+ \ DEBUG_CONFIGURATIONS
+ \ DOBJ
+ \ IMPORTED
+ \ IMPORTED_NO_SONAME
+ \ INTERFACE
+ \ INTERFACE_LINK_LIBRARIES
+ \ LINK_INTERFACE_LIBRARIES
+ \ LINK_INTERFACE_LIBRARIES_DEBUG
+ \ LINK_INTERFACE_MULTIPLICITY
+ \ LINK_OPTIONS
+ \ LINK_PRIVATE
+ \ LINK_PUBLIC
+ \ OBJECT
+ \ OLD
+ \ PRIVATE
+ \ PUBLIC
+ \ SHARED
+ \ STATIC
+
+syn keyword cmakeKWtarget_link_options contained
+ \ ALIAS
+ \ BEFORE
+ \ CMAKE_
+ \ GCC
+ \ GNU
+ \ IMPORTED
+ \ INTERFACE
+ \ INTERFACE_LINK_OPTIONS
+ \ LANG
+ \ LINKER
+ \ LINK_OPTIONS
+ \ PRIVATE
+ \ PUBLIC
+ \ SHELL
+ \ STATIC_LIBRARY_OPTIONS
+ \ UNIX_COMMAND
+ \ _LINKER_WRAPPER_FLAG
+ \ _LINKER_WRAPPER_FLAG_SEP
syn keyword cmakeKWtarget_sources contained
- \ IMPORTED INTERFACE INTERFACE_SOURCES PRIVATE PUBLIC SOURCES
+ \ ALIAS
+ \ IMPORTED
+ \ INTERFACE
+ \ INTERFACE_SOURCES
+ \ PRIVATE
+ \ PUBLIC
+ \ SOURCES
syn keyword cmakeKWtry_compile contained
- \ ALL_BUILD CMAKE_FLAGS COMPILE_DEFINITIONS COPY_FILE COPY_FILE_ERROR CUDA_EXTENSIONS CUDA_STANDARD CUDA_STANDARD_REQUIRED CXX_EXTENSIONS CXX_STANDARD CXX_STANDARD_REQUIRED C_EXTENSIONS C_STANDARD C_STANDARD_REQUIRED DEFINED DLINK_LIBRARIES DVAR FALSE INCLUDE_DIRECTORIES LANG LINK_DIRECTORIES LINK_LIBRARIES NOT OUTPUT_VARIABLE RESULT_VAR SOURCES TRUE TYPE VALUE _EXTENSIONS _STANDARD _STANDARD_REQUIRED
+ \ ALL_BUILD
+ \ CMAKE_FLAGS
+ \ COMPILE_DEFINITIONS
+ \ COPY_FILE
+ \ COPY_FILE_ERROR
+ \ CUDA_EXTENSIONS
+ \ CUDA_STANDARD
+ \ CUDA_STANDARD_REQUIRED
+ \ CXX_EXTENSIONS
+ \ CXX_STANDARD
+ \ CXX_STANDARD_REQUIRED
+ \ C_EXTENSIONS
+ \ C_STANDARD
+ \ C_STANDARD_REQUIRED
+ \ DEFINED
+ \ DLINK_LIBRARIES
+ \ DVAR
+ \ EXECUTABLE
+ \ FALSE
+ \ GHS
+ \ INCLUDE_DIRECTORIES
+ \ LANG
+ \ LINK_DIRECTORIES
+ \ LINK_LIBRARIES
+ \ LINK_OPTIONS
+ \ MULTI
+ \ NOT
+ \ OUTPUT_VARIABLE
+ \ PRIVATE
+ \ SOURCES
+ \ STATIC_LIBRARY
+ \ STATIC_LIBRARY_OPTIONS
+ \ TRUE
+ \ TYPE
+ \ VALUE
+ \ _EXTENSIONS
+ \ _STANDARD
+ \ _STANDARD_REQUIRED
syn keyword cmakeKWtry_run contained
- \ ARGS CMAKE_FLAGS COMPILE_DEFINITIONS COMPILE_OUTPUT_VARIABLE COMPILE_RESULT_VAR DLINK_LIBRARIES DVAR FAILED_TO_RUN FALSE INCLUDE_DIRECTORIES LINK_DIRECTORIES LINK_LIBRARIES RUN_OUTPUT_VARIABLE RUN_RESULT_VAR TRUE TYPE VALUE __TRYRUN_OUTPUT
+ \ ARGS
+ \ CMAKE_FLAGS
+ \ COMPILE_DEFINITIONS
+ \ COMPILE_OUTPUT_VARIABLE
+ \ DLINK_LIBRARIES
+ \ DVAR
+ \ FAILED_TO_RUN
+ \ FALSE
+ \ INCLUDE_DIRECTORIES
+ \ LINK_DIRECTORIES
+ \ LINK_LIBRARIES
+ \ LINK_OPTIONS
+ \ RUN_OUTPUT_VARIABLE
+ \ TRUE
+ \ TYPE
+ \ VALUE
+ \ __TRYRUN_OUTPUT
syn keyword cmakeKWunset contained
- \ CACHE LD_LIBRARY_PATH PARENT_SCOPE
+ \ PARENT_SCOPE
+ \ VAR
syn keyword cmakeKWuse_mangled_mesa contained
- \ GL OUTPUT_DIRECTORY PATH_TO_MESA
+ \ GL
+ \ OUTPUT_DIRECTORY
+ \ PATH_TO_MESA
syn keyword cmakeKWvariable_requires contained
- \ RESULT_VARIABLE TEST_VARIABLE
+ \ RESULT_VARIABLE
+ \ TEST_VARIABLE
syn keyword cmakeKWvariable_watch contained
\ COMMAND
-syn keyword cmakeKWwhile contained
- \ ARGS
-
syn keyword cmakeKWwrite_file contained
- \ APPEND CONFIGURE_FILE NOTE WRITE
+ \ APPEND
+ \ CONFIGURE_FILE
+ \ NOTE
+ \ WRITE
syn keyword cmakeGeneratorExpressions contained
- \ LINK_LIBRARIES INCLUDE_DIRECTORIES COMPILE_DEFINITIONS CONFIG DEBUG_MODE BOOL AND NOT IF STREQUAL MAP_IMPORTED_CONFIG_ PLATFORM_ID C_COMPILER_ID CXX_COMPILER_ID VERSION_LESS VERSION_GREATER VERSION_EQUAL VERSION_LESS_EQUAL VERSION_GREATER_EQUAL C_COMPILER_VERSION CXX_COMPILER_VERSION TARGET_POLICY COMPILE_FEATURES C_STANDARD CXX_STANDARD COMPILE_LANGUAGE PRIVATE PUBLIC COMPILING_CXX GNU OLD_COMPILER CMAKE_CXX_COMPILER_VERSION CONFIGURATION TARGET_FILE TARGET_FILE_NAME TARGET_FILE_DIR TARGET_LINKER_FILE TARGET_LINKER_FILE_NAME TARGET_LINKER_FILE_DIR TARGET_SONAME_FILE TARGET_SONAME_FILE_NAME TARGET_SONAME_FILE_DIR TARGET_PDB_FILE PDB_NAME PDB_OUTPUT_DIRECTORY PDB_NAME_ PDB_OUTPUT_DIRECTORY_ TARGET_PDB_FILE_NAME TARGET_PDB_FILE_DIR TARGET_BUNDLE_DIR TARGET_BUNDLE_CONTENT_DIR SDK TARGET_PROPERTY INSTALL_PREFIX EXPORT JOIN ANGLE COMMA SEMICOLON TARGET_NAME LINK_ONLY INTERFACE_LINK_LIBRARIES INSTALL_INTERFACE BUILD_INTERFACE LOWER_CASE UPPER_CASE MAKE_C_IDENTIFIER TARGET_OBJECTS OBJECT_LIBRARY SHELL_PATH MSYS
+ \ AND
+ \ ANGLE
+ \ ARCHIVE_OUTPUT_NAME
+ \ ARCHIVE_OUTPUT_NAME_
+ \ BAR
+ \ BOOL
+ \ BUILD_INTERFACE
+ \ CMAKE_
+ \ COMMA
+ \ COMMAND
+ \ COMPILE_DEFINITIONS
+ \ COMPILE_FEATURES
+ \ COMPILE_LANGUAGE
+ \ COMPILE_LANG_AND_ID
+ \ COMPILING_CUDA
+ \ COMPILING_CXX_WITH_CLANG
+ \ COMPILING_CXX_WITH_INTEL
+ \ COMPILING_C_WITH_CLANG
+ \ CONFIG
+ \ CONFIGURATION
+ \ CUDA_COMPILER_ID
+ \ CUDA_COMPILER_VERSION
+ \ CUSTOM_KEYS
+ \ CXX_COMPILER_ID
+ \ CXX_COMPILER_VERSION
+ \ CXX_STANDARD
+ \ C_COMPILER_ID
+ \ C_COMPILER_VERSION
+ \ C_STANDARD
+ \ DEBUG_MODE
+ \ DEBUG_POSTFIX
+ \ EXCLUDE
+ \ EXPORT
+ \ FALSE
+ \ FILTER
+ \ FOO_EXTRA_THINGS
+ \ Fortran_COMPILER_ID
+ \ Fortran_COMPILER_VERSION
+ \ GENERATE
+ \ GENEX_EVAL
+ \ GNU
+ \ IF
+ \ IGNORE
+ \ IMPORT_PREFIX
+ \ IMPORT_SUFFIX
+ \ INCLUDE_DIRECTORIES
+ \ INSTALL_INTERFACE
+ \ INSTALL_PREFIX
+ \ INTERFACE_LINK_LIBRARIES
+ \ IN_LIST
+ \ JOIN
+ \ LANG
+ \ LANG_COMPILER_ID
+ \ LIBRARY_OUTPUT_NAME
+ \ LIBRARY_OUTPUT_NAME_
+ \ LINK_LIBRARIES
+ \ LINK_ONLY
+ \ LOWER_CASE
+ \ MAKE_C_IDENTIFIER
+ \ MAP_IMPORTED_CONFIG_
+ \ NO
+ \ NOT
+ \ OFF
+ \ OLD_COMPILER
+ \ OUTPUT_NAME
+ \ OUTPUT_NAME_
+ \ PDB_NAME
+ \ PDB_NAME_
+ \ PDB_OUTPUT_DIRECTORY
+ \ PDB_OUTPUT_DIRECTORY_
+ \ PLATFORM_ID
+ \ POSIX
+ \ PRIVATE
+ \ PUBLIC
+ \ REMOVE_DUPLICATES
+ \ RUNTIME_OUTPUT_NAME
+ \ RUNTIME_OUTPUT_NAME_
+ \ SDK
+ \ SEMICOLON
+ \ SHELL_PATH
+ \ STREQUAL
+ \ TARGET_BUNDLE_CONTENT_DIR
+ \ TARGET_BUNDLE_DIR
+ \ TARGET_EXISTS
+ \ TARGET_FILE
+ \ TARGET_FILE_BASE_NAME
+ \ TARGET_FILE_DIR
+ \ TARGET_FILE_NAME
+ \ TARGET_FILE_PREFIX
+ \ TARGET_FILE_SUFFIX
+ \ TARGET_GENEX_EVAL
+ \ TARGET_LINKER_FILE
+ \ TARGET_LINKER_FILE_BASE_NAME
+ \ TARGET_LINKER_FILE_DIR
+ \ TARGET_LINKER_FILE_NAME
+ \ TARGET_LINKER_FILE_PREFIX
+ \ TARGET_LINKER_FILE_SUFFIX
+ \ TARGET_NAME_IF_EXISTS
+ \ TARGET_OBJECTS
+ \ TARGET_PDB_FILE
+ \ TARGET_PDB_FILE_BASE_NAME
+ \ TARGET_PDB_FILE_DIR
+ \ TARGET_PDB_FILE_NAME
+ \ TARGET_POLICY
+ \ TARGET_PROPERTY
+ \ TARGET_SONAME_FILE
+ \ TARGET_SONAME_FILE_DIR
+ \ TARGET_SONAME_FILE_NAME
+ \ UPPER_CASE
+ \ VERSION_EQUAL
+ \ VERSION_GREATER
+ \ VERSION_GREATER_EQUAL
+ \ VERSION_LESS
+ \ VERSION_LESS_EQUAL
+ \ _POSTFIX
syn case ignore
syn keyword cmakeCommand
- \ 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 cmake_host_system_information cmake_minimum_required cmake_parse_arguments cmake_policy configure_file continue 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 enable_language enable_testing endfunction endmacro execute_process export file find_file find_library find_package find_path find_program fltk_wrap_ui function get_cmake_property get_directory_property get_filename_component get_property get_source_file_property get_target_property get_test_property include include_directories include_external_msproject include_regular_expression install link_directories list load_cache load_command macro mark_as_advanced math message option project qt_wrap_cpp qt_wrap_ui 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 target_compile_definitions target_compile_features target_compile_options target_include_directories target_link_libraries target_sources try_compile try_run unset variable_watch
+ \ add_compile_definitions
+ \ add_compile_options
+ \ add_custom_command
+ \ add_custom_target
+ \ add_definitions
+ \ add_dependencies
+ \ add_executable
+ \ add_library
+ \ add_link_options
+ \ add_subdirectory
+ \ add_test
+ \ aux_source_directory
+ \ break
+ \ build_command
+ \ cmake_host_system_information
+ \ cmake_minimum_required
+ \ cmake_parse_arguments
+ \ cmake_policy
+ \ configure_file
+ \ continue
+ \ 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
+ \ enable_language
+ \ enable_testing
+ \ endfunction
+ \ endmacro
+ \ execute_process
+ \ export
+ \ file
+ \ find_file
+ \ find_library
+ \ find_package
+ \ find_path
+ \ find_program
+ \ fltk_wrap_ui
+ \ function
+ \ get_cmake_property
+ \ get_directory_property
+ \ get_filename_component
+ \ get_property
+ \ get_source_file_property
+ \ get_target_property
+ \ get_test_property
+ \ include
+ \ include_directories
+ \ include_external_msproject
+ \ include_guard
+ \ include_regular_expression
+ \ install
+ \ link_directories
+ \ list
+ \ load_cache
+ \ load_command
+ \ macro
+ \ mark_as_advanced
+ \ math
+ \ message
+ \ option
+ \ project
+ \ qt_wrap_cpp
+ \ qt_wrap_ui
+ \ 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
+ \ target_compile_definitions
+ \ target_compile_features
+ \ target_compile_options
+ \ target_include_directories
+ \ target_link_directories
+ \ target_link_libraries
+ \ target_link_options
+ \ target_sources
+ \ try_compile
+ \ try_run
+ \ unset
+ \ variable_watch
\ nextgroup=cmakeArguments
syn keyword cmakeCommandConditional
- \ else elseif endif if
+ \ else
+ \ elseif
+ \ endif
+ \ if
\ nextgroup=cmakeArguments
syn keyword cmakeCommandRepeat
- \ endforeach endwhile foreach while
+ \ endforeach
+ \ endwhile
+ \ foreach
+ \ while
\ nextgroup=cmakeArguments
syn keyword cmakeCommandDeprecated
- \ build_name exec_program export_library_dependencies install_files install_programs install_targets link_libraries make_directory output_required_files remove subdir_depends subdirs use_mangled_mesa utility_source variable_requires write_file
+ \ build_name
+ \ exec_program
+ \ export_library_dependencies
+ \ install_files
+ \ install_programs
+ \ install_targets
+ \ link_libraries
+ \ make_directory
+ \ output_required_files
+ \ remove
+ \ subdir_depends
+ \ subdirs
+ \ use_mangled_mesa
+ \ utility_source
+ \ variable_requires
+ \ write_file
\ nextgroup=cmakeArguments
syn case match
@@ -348,6 +3203,8 @@ syn keyword cmakeTodo
\ TODO FIXME XXX
\ contained
+hi def link cmakeBracketArgument String
+hi def link cmakeBracketComment Comment
hi def link cmakeCommand Function
hi def link cmakeCommandConditional Conditional
hi def link cmakeCommandDeprecated WarningMsg
@@ -357,7 +3214,6 @@ hi def link cmakeEnvironment Special
hi def link cmakeEscaped Special
hi def link cmakeGeneratorExpression WarningMsg
hi def link cmakeGeneratorExpressions Constant
-hi def link cmakeLuaComment Comment
hi def link cmakeModule Include
hi def link cmakeProperty Constant
hi def link cmakeRegistry Underlined
@@ -367,6 +3223,7 @@ hi def link cmakeVariableValue Type
hi def link cmakeVariable Identifier
hi def link cmakeKWExternalProject ModeMsg
+hi def link cmakeKWadd_compile_definitions ModeMsg
hi def link cmakeKWadd_compile_options ModeMsg
hi def link cmakeKWadd_custom_command ModeMsg
hi def link cmakeKWadd_custom_target ModeMsg
@@ -374,10 +3231,10 @@ hi def link cmakeKWadd_definitions ModeMsg
hi def link cmakeKWadd_dependencies ModeMsg
hi def link cmakeKWadd_executable ModeMsg
hi def link cmakeKWadd_library ModeMsg
+hi def link cmakeKWadd_link_options ModeMsg
hi def link cmakeKWadd_subdirectory ModeMsg
hi def link cmakeKWadd_test ModeMsg
hi def link cmakeKWbuild_command ModeMsg
-hi def link cmakeKWbuild_name ModeMsg
hi def link cmakeKWcmake_host_system_information ModeMsg
hi def link cmakeKWcmake_minimum_required ModeMsg
hi def link cmakeKWcmake_parse_arguments ModeMsg
@@ -396,6 +3253,7 @@ hi def link cmakeKWctest_update ModeMsg
hi def link cmakeKWctest_upload ModeMsg
hi def link cmakeKWdefine_property ModeMsg
hi def link cmakeKWenable_language ModeMsg
+hi def link cmakeKWenable_testing ModeMsg
hi def link cmakeKWexec_program ModeMsg
hi def link cmakeKWexecute_process ModeMsg
hi def link cmakeKWexport ModeMsg
@@ -420,20 +3278,23 @@ hi def link cmakeKWif ModeMsg
hi def link cmakeKWinclude ModeMsg
hi def link cmakeKWinclude_directories ModeMsg
hi def link cmakeKWinclude_external_msproject ModeMsg
+hi def link cmakeKWinclude_guard ModeMsg
hi def link cmakeKWinstall ModeMsg
hi def link cmakeKWinstall_files ModeMsg
hi def link cmakeKWinstall_programs ModeMsg
hi def link cmakeKWinstall_targets ModeMsg
+hi def link cmakeKWlink_directories ModeMsg
hi def link cmakeKWlist ModeMsg
hi def link cmakeKWload_cache ModeMsg
hi def link cmakeKWload_command ModeMsg
hi def link cmakeKWmacro ModeMsg
-hi def link cmakeKWmake_directory ModeMsg
hi def link cmakeKWmark_as_advanced ModeMsg
hi def link cmakeKWmath ModeMsg
hi def link cmakeKWmessage ModeMsg
hi def link cmakeKWoption ModeMsg
hi def link cmakeKWproject ModeMsg
+hi def link cmakeKWqt_wrap_cpp ModeMsg
+hi def link cmakeKWqt_wrap_ui ModeMsg
hi def link cmakeKWremove ModeMsg
hi def link cmakeKWseparate_arguments ModeMsg
hi def link cmakeKWset ModeMsg
@@ -449,7 +3310,9 @@ hi def link cmakeKWtarget_compile_definitions ModeMsg
hi def link cmakeKWtarget_compile_features ModeMsg
hi def link cmakeKWtarget_compile_options ModeMsg
hi def link cmakeKWtarget_include_directories ModeMsg
+hi def link cmakeKWtarget_link_directories ModeMsg
hi def link cmakeKWtarget_link_libraries ModeMsg
+hi def link cmakeKWtarget_link_options ModeMsg
hi def link cmakeKWtarget_sources ModeMsg
hi def link cmakeKWtry_compile ModeMsg
hi def link cmakeKWtry_run ModeMsg
@@ -457,7 +3320,35 @@ hi def link cmakeKWunset ModeMsg
hi def link cmakeKWuse_mangled_mesa ModeMsg
hi def link cmakeKWvariable_requires ModeMsg
hi def link cmakeKWvariable_watch ModeMsg
-hi def link cmakeKWwhile ModeMsg
hi def link cmakeKWwrite_file ModeMsg
+" Manually added - difficult to parse out of documentation
+syn case ignore
+
+syn keyword cmakeCommandManuallyAdded
+ \ configure_package_config_file write_basic_package_version_file
+ \ nextgroup=cmakeArguments
+
+syn case match
+
+syn keyword cmakeKWconfigure_package_config_file contained
+ \ INSTALL_DESTINATION PATH_VARS NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO INSTALL_PREFIX
+
+syn keyword cmakeKWconfigure_package_config_file_constants contained
+ \ AnyNewerVersion SameMajorVersion SameMinorVersion ExactVersion
+
+syn keyword cmakeKWwrite_basic_package_version_file contained
+ \ VERSION COMPATIBILITY
+
+hi def link cmakeCommandManuallyAdded Function
+
+hi def link cmakeKWconfigure_package_config_file ModeMsg
+hi def link cmakeKWwrite_basic_package_version_file ModeMsg
+hi def link cmakeKWconfigure_package_config_file_constants Constant
+
let b:current_syntax = "cmake"
+
+let &cpo = s:keepcpo
+unlet s:keepcpo
+
+" vim: set nowrap:
diff --git a/CMakeCPack.cmake b/CMakeCPack.cmake
index a0aacb465..78e22cc85 100644
--- a/CMakeCPack.cmake
+++ b/CMakeCPack.cmake
@@ -102,9 +102,6 @@ if(CMake_INSTALL_COMPONENTS)
if(WIN32 AND NOT CYGWIN)
list(APPEND _CPACK_IFW_COMPONENTS_ALL cmcldeps)
endif()
- if(APPLE)
- list(APPEND _CPACK_IFW_COMPONENTS_ALL cmakexbuild)
- endif()
if(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME)
set(_CPACK_IFW_COMPONENT_UNSPECIFIED_NAME
${CMAKE_INSTALL_DEFAULT_COMPONENT_NAME})
@@ -245,5 +242,23 @@ configure_file("${CMake_SOURCE_DIR}/CMakeCPackOptions.cmake.in"
"${CMake_BINARY_DIR}/CMakeCPackOptions.cmake" @ONLY)
set(CPACK_PROJECT_CONFIG_FILE "${CMake_BINARY_DIR}/CMakeCPackOptions.cmake")
+set(CPACK_SOURCE_IGNORE_FILES
+ # Files specific to version control.
+ "/\\\\.git/"
+ "/\\\\.gitattributes$"
+ "/\\\\.github/"
+ "/\\\\.gitignore$"
+ "/\\\\.hooks-config$"
+
+ # Cygwin package build.
+ "/\\\\.build/"
+
+ # Temporary files.
+ "\\\\.swp$"
+ "\\\\.#"
+ "/#"
+ "~$"
+ )
+
# include CPack model once all variables are set
include(CPack)
diff --git a/CMakeCPackOptions.cmake.in b/CMakeCPackOptions.cmake.in
index ad0c24586..2a4bcc589 100644
--- a/CMakeCPackOptions.cmake.in
+++ b/CMakeCPackOptions.cmake.in
@@ -109,16 +109,6 @@ if(CPACK_GENERATOR MATCHES "IFW")
set(CPACK_IFW_COMPONENT_CMCLDEPS_VERSION
"@CMake_IFW_ROOT_COMPONENT_VERSION@")
- set(CPACK_COMPONENT_CMAKEXBUILD_DISPLAY_NAME "cmakexbuild")
- set(CPACK_COMPONENT_CMAKEXBUILD_DESCRIPTION
- "The \"cmakexbuild\" executable is a wrapper program for \"xcodebuild\"")
- set(CPACK_COMPONENT_CMAKEXBUILD_REQUIRED TRUE)
- set(CPACK_COMPONENT_CMAKEXBUILD_GROUP Tools)
- set(CPACK_IFW_COMPONENT_CMAKEXBUILD_NAME "CMakeXBuild")
- set(CPACK_IFW_COMPONENT_CMAKEXBUILD_PRIORITY 85)
- set(CPACK_IFW_COMPONENT_CMAKEXBUILD_VERSION
- "@CMake_IFW_ROOT_COMPONENT_VERSION@")
-
# Dialogs
set(CPACK_COMPONENT_GROUP_DIALOGS_DISPLAY_NAME "Interactive Dialogs")
set(CPACK_COMPONENT_GROUP_DIALOGS_DESCRIPTION
@@ -208,12 +198,6 @@ if(CPACK_GENERATOR MATCHES "IFW")
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")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ed924eb4e..e60b6c568 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,14 +1,12 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR)
-if(POLICY CMP0025)
- cmake_policy(SET CMP0025 NEW)
-endif()
-if(POLICY CMP0053)
- cmake_policy(SET CMP0053 NEW)
-endif()
+cmake_minimum_required(VERSION 3.1...3.14 FATAL_ERROR)
+set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideC.cmake)
+set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideCXX.cmake)
project(CMake)
+unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX)
+unset(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
# Make sure we can find internal find_package modules only used for
# building CMake and not for shipping externally
@@ -21,6 +19,14 @@ if(CMAKE_BOOTSTRAP)
endif()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+ message(FATAL_ERROR
+ "CMake no longer compiles on HP-UX. See\n"
+ " https://gitlab.kitware.com/cmake/cmake/issues/17137\n"
+ "Use CMake 3.9 or lower instead."
+ )
+ endif()
+
set(CMake_BIN_DIR ${CMake_BINARY_DIR}/bin)
endif()
@@ -58,11 +64,20 @@ if(NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMake_NO_CXX_STANDARD)
if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
set(CMAKE_CXX_STANDARD 98)
else()
- include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_cstdio.cmake)
- if(NOT CMake_CXX14_CSTDIO_BROKEN)
- set(CMAKE_CXX_STANDARD 14)
+ if(NOT CMAKE_VERSION VERSION_LESS 3.8)
+ include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx17_check.cmake)
else()
- set(CMAKE_CXX_STANDARD 11)
+ set(CMake_CXX17_BROKEN 1)
+ endif()
+ if(NOT CMake_CXX17_BROKEN)
+ set(CMAKE_CXX_STANDARD 17)
+ else()
+ include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx14_check.cmake)
+ if(NOT CMake_CXX14_BROKEN)
+ set(CMAKE_CXX_STANDARD 14)
+ else()
+ set(CMAKE_CXX_STANDARD 11)
+ endif()
endif()
endif()
endif()
@@ -72,6 +87,10 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
# check for available C++ features
include(${CMake_SOURCE_DIR}/Source/Checks/cm_cxx_features.cmake)
+
+ if(NOT CMake_HAVE_CXX_UNIQUE_PTR)
+ message(FATAL_ERROR "The C++ compiler does not support C++11 (e.g. std::unique_ptr).")
+ endif()
endif()
# set the internal encoding of CMake to UTF-8
@@ -98,6 +117,18 @@ option(CMake_BUILD_DEVELOPER_REFERENCE
"Build CMake Developer Reference" OFF)
mark_as_advanced(CMake_BUILD_DEVELOPER_REFERENCE)
+# option to build using interprocedural optimizations (IPO/LTO)
+if (NOT CMAKE_VERSION VERSION_LESS 3.12.2)
+ option(CMake_BUILD_LTO "Compile CMake with link-time optimization if supported" OFF)
+ if(CMake_BUILD_LTO)
+ include(CheckIPOSupported)
+ check_ipo_supported(RESULT HAVE_IPO)
+ if(HAVE_IPO)
+ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+ endif()
+ endif()
+endif()
+
#-----------------------------------------------------------------------
# a macro to deal with system libraries, implemented as a macro
# simply to improve readability of the main script
@@ -106,13 +137,9 @@ 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 FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB)
+ set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBRHASH LIBUV ZLIB ZSTD)
foreach(util ${UTILITIES})
if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
@@ -140,14 +167,14 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
# 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)
+ option(CMAKE_USE_SYSTEM_CURL "Use system-installed curl" "${CMAKE_USE_SYSTEM_LIBRARY_CURL}")
+ option(CMAKE_USE_SYSTEM_EXPAT "Use system-installed expat" "${CMAKE_USE_SYSTEM_LIBRARY_EXPAT}")
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_ZSTD "Use system-installed zstd"
+ "${CMAKE_USE_SYSTEM_LIBRARY_ZSTD}" "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)
option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
@@ -181,7 +208,7 @@ endmacro()
macro(CMAKE_SETUP_TESTING)
if(BUILD_TESTING)
set(CMAKE_TEST_SYSTEM_LIBRARIES 0)
- foreach(util CURL EXPAT XMLRPC ZLIB)
+ foreach(util CURL EXPAT ZLIB)
if(CMAKE_USE_SYSTEM_${util})
set(CMAKE_TEST_SYSTEM_LIBRARIES 1)
endif()
@@ -244,6 +271,17 @@ if(CMake_RUN_CLANG_TIDY)
message(FATAL_ERROR "CMake_RUN_CLANG_TIDY is ON but clang-tidy is not found!")
endif()
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_COMMAND}")
+
+ # Create a preprocessor definition that depends on .clang-tidy content so
+ # the compile command will change when .clang-tidy changes. This ensures
+ # that a subsequent build re-runs clang-tidy on all sources even if they
+ # do not otherwise need to be recompiled. Nothing actually uses this
+ # definition. We add it to targets on which we run clang-tidy just to
+ # get the build dependency on the .clang-tidy file.
+ file(SHA1 ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy clang_tidy_sha1)
+ set(CLANG_TIDY_DEFINITIONS "CLANG_TIDY_SHA1=${clang_tidy_sha1}")
+ unset(clang_tidy_sha1)
+
endif()
configure_file(.clang-tidy .clang-tidy COPYONLY)
@@ -255,7 +293,8 @@ if(CMake_RUN_IWYU)
message(FATAL_ERROR "CMake_RUN_IWYU is ON but include-what-you-use is not found!")
endif()
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
- "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp")
+ "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMake_SOURCE_DIR}/Utilities/IWYU/mapping.imp;-w")
+ list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${CMake_IWYU_OPTIONS})
endif()
@@ -280,6 +319,8 @@ endmacro()
# Simply to improve readability of the main script.
#-----------------------------------------------------------------------
macro (CMAKE_BUILD_UTILITIES)
+ find_package(Threads)
+
#---------------------------------------------------------------------
# Create the kwsys library for CMake.
set(KWSYS_NAMESPACE cmsys)
@@ -293,6 +334,9 @@ macro (CMAKE_BUILD_UTILITIES)
set(KWSYS_USE_ConsoleBuf 1)
set(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
set(KWSYS_INSTALL_DOC_DIR "${CMAKE_DOC_DIR}")
+ if(CMake_NO_CXX_STANDARD)
+ set(KWSYS_CXX_STANDARD "")
+ endif()
add_subdirectory(Source/kwsys)
set(kwsys_folder "Utilities/KWSys")
CMAKE_SET_TARGET_FOLDER(${KWSYS_NAMESPACE} "${kwsys_folder}")
@@ -333,11 +377,7 @@ macro (CMAKE_BUILD_UTILITIES)
endif()
if(CMAKE_USE_SYSTEM_LIBRHASH)
- if(NOT CMAKE_VERSION VERSION_LESS 3.0)
- find_package(LibRHash)
- else()
- message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBRHASH requires CMake >= 3.0")
- endif()
+ find_package(LibRHash)
if(NOT LibRHash_FOUND)
message(FATAL_ERROR
"CMAKE_USE_SYSTEM_LIBRHASH is ON but LibRHash is not found!")
@@ -381,7 +421,6 @@ macro (CMAKE_BUILD_UTILITIES)
set(CURL_SPECIAL_ZLIB_H ${CMAKE_ZLIB_HEADER})
set(CURL_SPECIAL_LIBZ_INCLUDES ${CMAKE_ZLIB_INCLUDES})
set(CURL_SPECIAL_LIBZ ${CMAKE_ZLIB_LIBRARIES})
- add_definitions(-DCURL_STATICLIB)
set(CMAKE_CURL_INCLUDES)
set(CMAKE_CURL_LIBRARIES cmcurl)
if(CMAKE_TESTS_CDASH_SERVER)
@@ -408,14 +447,6 @@ macro (CMAKE_BUILD_UTILITIES)
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")
-
- #---------------------------------------------------------------------
# Build expat library for CMake, CTest, and libarchive.
if(CMAKE_USE_SYSTEM_EXPAT)
find_package(EXPAT)
@@ -447,6 +478,17 @@ macro (CMAKE_BUILD_UTILITIES)
endif()
#---------------------------------------------------------------------
+ # Build or use system zstd for libarchive.
+ if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
+ if(NOT CMAKE_USE_SYSTEM_ZSTD)
+ set(ZSTD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Utilities/cmzstd")
+ set(ZSTD_LIBRARY cmzstd)
+ add_subdirectory(Utilities/cmzstd)
+ CMAKE_SET_TARGET_FOLDER(cmzstd "Utilities/3rdParty")
+ endif()
+ endif()
+
+ #---------------------------------------------------------------------
# Build or use system liblzma for libarchive.
if(NOT CMAKE_USE_SYSTEM_LIBARCHIVE)
if(CMAKE_USE_SYSTEM_LIBLZMA)
@@ -469,7 +511,7 @@ macro (CMAKE_BUILD_UTILITIES)
#---------------------------------------------------------------------
# Build or use system libarchive for CMake and CTest.
if(CMAKE_USE_SYSTEM_LIBARCHIVE)
- find_package(LibArchive 3.0.0)
+ find_package(LibArchive 3.3.3)
if(NOT LibArchive_FOUND)
message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBARCHIVE is ON but LibArchive is not found!")
endif()
@@ -484,6 +526,7 @@ macro (CMAKE_BUILD_UTILITIES)
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 LZMA library if found")
+ set(ENABLE_LZ4 OFF CACHE INTERNAL "Enable the use of the system LZ4 library if found")
set(ENABLE_LZO OFF CACHE INTERNAL "Enable the use of the system LZO library if found")
set(ENABLE_ZLIB ON CACHE INTERNAL "Enable the use of the system ZLIB library if found")
set(ENABLE_BZip2 ON CACHE INTERNAL "Enable the use of the system BZip2 library if found")
@@ -503,15 +546,15 @@ macro (CMAKE_BUILD_UTILITIES)
#---------------------------------------------------------------------
# Build jsoncpp library.
if(CMAKE_USE_SYSTEM_JSONCPP)
- if(NOT CMAKE_VERSION VERSION_LESS 3.0)
- find_package(JsonCpp)
- else()
- message(FATAL_ERROR "CMAKE_USE_SYSTEM_JSONCPP requires CMake >= 3.0")
- endif()
+ find_package(JsonCpp 1.4.1)
if(NOT JsonCpp_FOUND)
message(FATAL_ERROR
"CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
endif()
+ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+ set_property(TARGET JsonCpp::JsonCpp APPEND PROPERTY
+ INTERFACE_COMPILE_OPTIONS -Wno-deprecated-declarations)
+ endif()
set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
else()
set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
@@ -521,79 +564,41 @@ macro (CMAKE_BUILD_UTILITIES)
#---------------------------------------------------------------------
# Build libuv library.
- if(NOT DEFINED CMAKE_USE_LIBUV)
- set(CMAKE_USE_LIBUV 1)
- if(APPLE)
- include(CheckCSourceCompiles)
- check_c_source_compiles("
-#include <CoreServices/CoreServices.h>
-#include <AvailabilityMacros.h>
-#ifndef MAC_OS_X_VERSION_10_5
-#error \"MAC_OS_X_VERSION_10_5 is not defined\"
-#endif
-int main(void) { return 0; }
-" HAVE_CoreServices_OS_X_10_5)
- if(NOT HAVE_CoreServices_OS_X_10_5)
- set(CMAKE_USE_LIBUV 0)
- endif()
- elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
- # Disable until it can be ported.
- set(CMAKE_USE_LIBUV 0)
- endif()
- endif()
- if(CMAKE_USE_LIBUV)
- if(CMAKE_USE_SYSTEM_LIBUV)
- if(NOT CMAKE_VERSION VERSION_LESS 3.0)
- find_package(LibUV 1.0.0)
- else()
- message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBUV requires CMake >= 3.0")
- endif()
- if(NOT LIBUV_FOUND)
- message(FATAL_ERROR
- "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
- endif()
- set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
- else()
- set(CMAKE_LIBUV_LIBRARIES cmlibuv)
- add_subdirectory(Utilities/cmlibuv)
- CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
- endif()
- else()
- set(CMAKE_LIBUV_LIBRARIES)
- endif()
-
- #---------------------------------------------------------------------
- # Build XMLRPC library for CMake and CTest.
- if(CTEST_USE_XMLRPC)
- find_package(XMLRPC QUIET REQUIRED libwww-client)
- if(NOT XMLRPC_FOUND)
+ if(CMAKE_USE_SYSTEM_LIBUV)
+ find_package(LibUV 1.10.0)
+ if(NOT LIBUV_FOUND)
message(FATAL_ERROR
- "CTEST_USE_XMLRPC is ON but xmlrpc is not found!")
+ "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!")
endif()
- set(CMAKE_XMLRPC_INCLUDES ${XMLRPC_INCLUDE_DIRS})
- set(CMAKE_XMLRPC_LIBRARIES ${XMLRPC_LIBRARIES})
+ set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV)
+ else()
+ set(CMAKE_LIBUV_LIBRARIES cmlibuv)
+ add_subdirectory(Utilities/cmlibuv)
+ CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
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)
+ if(NOT DEFINED BUILD_CursesDialog)
+ include(${CMake_SOURCE_DIR}/Source/Checks/Curses.cmake)
+ option(BUILD_CursesDialog "Build the CMake Curses Dialog ccmake" "${CMakeCheckCurses_COMPILED}")
endif()
else ()
set(BUILD_CursesDialog 0)
endif ()
if(BUILD_CursesDialog)
+ set(CURSES_NEED_NCURSES TRUE)
+ find_package(Curses)
+ if(NOT CURSES_FOUND)
+ message(WARNING
+ "'ccmake' will not be built because Curses was not found.\n"
+ "Turn off BUILD_CursesDialog to suppress this message."
+ )
+ set(BUILD_CursesDialog 0)
+ endif()
+ endif()
+ if(BUILD_CursesDialog)
if(NOT CMAKE_USE_SYSTEM_FORM)
add_subdirectory(Source/CursesDialog/form)
elseif(NOT CURSES_FORM_LIBRARY)
@@ -725,7 +730,7 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
# 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)
+ OR CMAKE_USE_SYSTEM_EXPAT 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)
@@ -748,31 +753,6 @@ endif()
# setup some Testing support (a macro defined in this file)
CMAKE_SETUP_TESTING()
-# Check whether to build server mode or not:
-if(NOT CMake_TEST_EXTERNAL_CMAKE)
- if(NOT DEFINED CMake_ENABLE_SERVER_MODE)
- list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_auto_type CMake_HAVE_CXX_AUTO_TYPE)
- list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_range_for CMake_HAVE_CXX_RANGE_FOR)
- if(CMAKE_USE_LIBUV
- AND CMake_HAVE_CXX_AUTO_TYPE
- AND CMake_HAVE_CXX_MAKE_UNIQUE
- AND CMake_HAVE_CXX_RANGE_FOR
- )
- set(CMake_ENABLE_SERVER_MODE 1)
- else()
- set(CMake_ENABLE_SERVER_MODE 0)
- endif()
- endif()
- if(CMake_ENABLE_SERVER_MODE AND NOT CMAKE_USE_LIBUV)
- message(FATAL_ERROR "The server mode requires libuv!")
- endif()
-else()
- set(CMake_ENABLE_SERVER_MODE 0)
-endif()
-if(NOT DEFINED CMake_TEST_SERVER_MODE)
- set(CMake_TEST_SERVER_MODE ${CMake_ENABLE_SERVER_MODE})
-endif()
-
if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(NOT CMake_VERSION_IS_RELEASE)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
@@ -808,15 +788,19 @@ add_subdirectory(Tests)
if(NOT CMake_TEST_EXTERNAL_CMAKE)
if(BUILD_TESTING)
CMAKE_SET_TARGET_FOLDER(CMakeLibTests "Tests")
+ IF(TARGET CMakeServerLibTests)
+ CMAKE_SET_TARGET_FOLDER(CMakeServerLibTests "Tests")
+ ENDIF()
endif()
if(TARGET documentation)
CMAKE_SET_TARGET_FOLDER(documentation "Documentation")
endif()
endif()
-# add a test
-add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
- --system-information -G "${CMAKE_GENERATOR}" )
+if(BUILD_TESTING)
+ add_test(SystemInformationNew "${CMAKE_CMAKE_COMMAND}"
+ --system-information -G "${CMAKE_GENERATOR}" )
+endif()
if(NOT CMake_TEST_EXTERNAL_CMAKE)
# Install license file as it requires.
@@ -838,4 +822,10 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
# Install auxiliary files integrating with other tools.
add_subdirectory(Auxiliary)
+
+ # Optionally sign installed binaries.
+ if(CMake_INSTALL_SIGNTOOL)
+ configure_file(Source/CMakeInstallSignTool.cmake.in Source/CMakeInstallSignTool.cmake @ONLY)
+ install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/Source/CMakeInstallSignTool.cmake)
+ endif()
endif()
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index e2197632a..7e7111164 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -24,21 +24,47 @@ CMake uses `Kitware's GitLab Instance`_ to manage development and code review.
To contribute patches:
#. Fork the upstream `CMake Repository`_ into a personal account.
-#. Run `Utilities/SetupForDevelopment.sh`_ for local configuration.
+#. Run `Utilities/SetupForDevelopment.sh`_ for local git configuration.
+#. See `Building CMake`_ for building CMake locally.
#. See the `CMake Source Code Guide`_ for coding guidelines.
#. Base all new work on the upstream ``master`` branch.
-#. Create commits making incremental, distinct, logically complete changes.
+ Base work on the upstream ``release`` branch only if it fixes a
+ regression or bug in a feature new to that release.
+ If in doubt, prefer ``master``. Reviewers may simply ask for
+ a rebase if deemed appropriate in particular cases.
+#. Create commits making incremental, distinct, logically complete changes
+ with appropriate `commit messages`_.
#. Push a topic branch to a personal repository fork on GitLab.
-#. Create a GitLab Merge Request targeting the upstream ``master`` branch.
+#. Create a GitLab Merge Request targeting the upstream ``master`` branch
+ (even if the change is intended for merge to the ``release`` branch).
+ Check the box labelled "Allow commits from members who can merge to the
+ target branch". This will allow maintainers to make minor edits on your
+ behalf.
The merge request will enter the `CMake Review Process`_ for consideration.
.. _`Kitware's GitLab Instance`: https://gitlab.kitware.com
.. _`CMake Repository`: https://gitlab.kitware.com/cmake/cmake
.. _`Utilities/SetupForDevelopment.sh`: Utilities/SetupForDevelopment.sh
+.. _`Building CMake`: README.rst#building-cmake
.. _`CMake Source Code Guide`: Help/dev/source.rst
+.. _`commit messages`: Help/dev/review.rst#commit-messages
.. _`CMake Review Process`: Help/dev/review.rst
+CMake Dashboard Client
+======================
+
+The *integration testing* step of the `CMake Review Process`_ uses a set of
+testing machines that follow an integration branch on their own schedule to
+drive testing and submit results to the `CMake CDash Page`_. Anyone is
+welcome to provide testing machines in order to help keep support for their
+platforms working.
+
+See documentation on `CMake Testing Process`_ for more information.
+
+.. _`CMake CDash Page`: https://open.cdash.org/index.php?project=CMake
+.. _`CMake Testing Process`: Help/dev/testing.rst
+
License
=======
diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in
index fa2fbe35c..823ee3cb7 100644
--- a/CTestCustom.cmake.in
+++ b/CTestCustom.cmake.in
@@ -2,6 +2,7 @@ list(APPEND CTEST_CUSTOM_ERROR_MATCH
"ERROR:")
list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
+ "warning: cast from 'char\\*' to 'cmCursesWidget\\*' increases required alignment of target type" # Occurs when using Solaris's system libform
"xtree.[0-9]+. : warning C4702: unreachable code"
"warning LNK4221"
"warning LNK4204" # Occurs by race condition with objects in small libs
@@ -44,11 +45,14 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
"Warning: LINN32: Last line.*is less.*"
"Warning: Olimit was exceeded on function.*"
"Warning: To override Olimit for all functions in file.*"
+ "Warning: Function .* can throw only the exceptions thrown by the function .* it overrides\\."
+ "WarningMessagesDialog\\.cxx"
"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)"
"(Lexer|Parser).*warning.*variable.*was set but never used"
+ "LexerParser.*warning.*empty expression statement has no effect; remove unnecessary"
"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.*"
@@ -68,11 +72,11 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
"cm(StringCommand|CTestTestHandler)\\.cxx.*warning.*srand.*seed choices are.*poor" # we do not do crypto
"IPA warning: function.*multiply defined in"
- # Ignore clang's summary warning, assuming prior text has matched some
+ # Ignore compiler summary warning, assuming prior text has matched some
# other warning expression:
- "[0-9,]+ warnings? generated."
- # similarly for PGI
- "compilation completed with warnings"
+ "[0-9,]+ warnings? generated." # Clang
+ "compilation completed with warnings" # PGI
+ "[0-9]+ Warning\\(s\\) detected" # SunPro
# scanbuild exceptions
"char_traits.h:.*: warning: Null pointer argument in call to string length function"
@@ -90,6 +94,7 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
"cmFortranLexer.cxx:[0-9]+:[0-9]+: warning: Call to 'realloc' has an allocation size of 0 bytes"
"testProcess.*warning: Dereference of null pointer .loaded from variable .invalidAddress.."
"liblzma/simple/x86.c:[0-9]+:[0-9]+: warning: The result of the '<<' expression is undefined"
+ "liblzma/common/index_encoder.c:[0-9]+:[0-9]+: warning: Value stored to .* during its initialization is never read"
"libuv/src/.*:[0-9]+:[0-9]+: warning: Dereference of null pointer"
"libuv/src/.*:[0-9]+:[0-9]+: warning: The left operand of '==' is a garbage value"
)
@@ -100,12 +105,6 @@ if(NOT "@CMAKE_GENERATOR@" MATCHES "Xcode")
)
endif ()
-if(NOT "@CMAKE_GENERATOR@" MATCHES "KDevelop")
- list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE
- "Kdevelop"
- )
-endif ()
-
list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE
# Exclude kwsys files from coverage results. They are reported
# (with better coverage results) on kwsys dashboards...
diff --git a/CompileFlags.cmake b/CompileFlags.cmake
index 7a9d4cdf3..053259f47 100644
--- a/CompileFlags.cmake
+++ b/CompileFlags.cmake
@@ -8,15 +8,28 @@ if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Intel")
set(_INTEL_WINDOWS 1)
endif()
+if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Clang"
+ AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ set(_CLANG_MSVC_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)
+if(MSVC OR _INTEL_WINDOWS OR _CLANG_MSVC_WINDOWS)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
else()
endif()
+if(MSVC)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stack:10000000")
+endif()
+
+if(_CLANG_MSVC_WINDOWS AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000")
+endif()
+
#silence duplicate symbol warnings on AIX
if(CMAKE_SYSTEM_NAME MATCHES "AIX")
if(NOT CMAKE_COMPILER_IS_GNUCXX)
@@ -24,31 +37,12 @@ if(CMAKE_SYSTEM_NAME MATCHES "AIX")
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()
-
# Workaround for short jump tables on PA-RISC
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc")
if(CMAKE_COMPILER_IS_GNUCC)
@@ -59,6 +53,23 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc")
endif()
endif()
+# Workaround for TOC Overflow on ppc64
+set(bigTocFlag "")
+if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND
+ CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc")
+ set(bigTocFlag "-Wl,-bbigtoc")
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
+ CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
+ set(bigTocFlag "-Wl,--no-multi-toc")
+endif()
+if(bigTocFlag)
+ include(CheckCXXLinkerFlag)
+ check_cxx_linker_flag(${bigTocFlag} BIG_TOC_FLAG_SUPPORTED)
+ if(BIG_TOC_FLAG_SUPPORTED)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${bigTocFlag}")
+ endif()
+endif()
+
if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND
NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
@@ -90,3 +101,26 @@ endif ()
if (CMAKE_ANSI_CFLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
endif ()
+
+# Allow per-translation-unit parallel builds when using MSVC
+if(CMAKE_GENERATOR MATCHES "Visual Studio" AND
+ (CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR
+ CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Intel"))
+
+ set(CMake_MSVC_PARALLEL ON CACHE STRING "\
+Enables /MP flag for parallel builds using MSVC. Specify an \
+integer value to control the number of threads used (Only \
+works on some older versions of Visual Studio). Setting to \
+ON lets the toolchain decide how many threads to use. Set to \
+OFF to disable /MP completely." )
+
+ if(CMake_MSVC_PARALLEL)
+ if(CMake_MSVC_PARALLEL GREATER 0)
+ string(APPEND CMAKE_C_FLAGS " /MP${CMake_MSVC_PARALLEL}")
+ string(APPEND CMAKE_CXX_FLAGS " /MP${CMake_MSVC_PARALLEL}")
+ else()
+ string(APPEND CMAKE_C_FLAGS " /MP")
+ string(APPEND CMAKE_CXX_FLAGS " /MP")
+ endif()
+ endif()
+endif()
diff --git a/Copyright.txt b/Copyright.txt
index 33201080d..f2362144a 100644
--- a/Copyright.txt
+++ b/Copyright.txt
@@ -1,5 +1,5 @@
CMake - Cross Platform Makefile Generator
-Copyright 2000-2017 Kitware, Inc. and Contributors
+Copyright 2000-2019 Kitware, Inc. and Contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -34,10 +34,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The following individuals and institutions are among the Contributors:
* Aaron C. Meadows <cmake@shadowguarddev.com>
+* Adriaan de Groot <groot@kde.org>
* Aleksey Avdeev <solo@altlinux.ru>
* Alexander Neundorf <neundorf@kde.org>
* Alexander Smorkalov <alexander.smorkalov@itseez.com>
* Alexey Sokolov <sokolov@google.com>
+* Alex Merry <alex.merry@kde.org>
* Alex Turbov <i.zaufi@gmail.com>
* Andreas Pakulat <apaku@gmx.de>
* Andreas Schneider <asn@cryptomilk.org>
@@ -61,13 +63,17 @@ The following individuals and institutions are among the Contributors:
* Ilya Lavrenov <ilya.lavrenov@itseez.com>
* Insight Software Consortium <insightsoftwareconsortium.org>
* Jan Woetzel
+* Julien Schueller
* Kelly Thompson <kgt@lanl.gov>
+* Laurent Montel <montel@kde.org>
* Konstantin Podsvirov <konstantin@podsvirov.pro>
* Mario Bensi <mbensi@ipsquad.net>
+* Martin Gräßlin <mgraesslin@kde.org>
* Mathieu Malaterre <mathieu.malaterre@gmail.com>
* Matthaeus G. Chajdas
* Matthias Kretz <kretz@kde.org>
* Matthias Maennich <matthias@maennich.net>
+* Michael Hirsch, Ph.D. <www.scivision.co>
* Michael Stürmer
* Miguel A. Figueroa-Villanueva
* Mike Jackson
@@ -75,7 +81,9 @@ The following individuals and institutions are among the Contributors:
* Nicolas Bock <nicolasbock@gmail.com>
* Nicolas Despres <nicolas.despres@gmail.com>
* Nikita Krupen'ko <krnekit@gmail.com>
+* NVIDIA Corporation <www.nvidia.com>
* OpenGamma Ltd. <opengamma.com>
+* Patrick Stotko <stotko@cs.uni-bonn.de>
* Per Øyvind Karlsen <peroyvind@mandriva.org>
* Peter Collingbourne <peter@pcc.me.uk>
* Petr Gotthard <gotthard@honeywell.com>
diff --git a/Help/command/FIND_XXX.txt b/Help/command/FIND_XXX.txt
index 7db221cb8..dde4dbbbc 100644
--- a/Help/command/FIND_XXX.txt
+++ b/Help/command/FIND_XXX.txt
@@ -16,6 +16,7 @@ The general signature is:
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[DOC "cache documentation string"]
[NO_DEFAULT_PATH]
+ [NO_PACKAGE_ROOT_PATH]
[NO_CMAKE_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
@@ -60,6 +61,13 @@ 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:
+.. |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX_SUBDIR| replace::
+ |prefix_XXX_SUBDIR| for each ``<prefix>`` in the
+ :variable:`<PackageName>_ROOT` CMake variable and the
+ :envvar:`<PackageName>_ROOT` environment variable if
+ called from within a find module loaded by
+ :command:`find_package(<PackageName>)`
+
.. |CMAKE_PREFIX_PATH_XXX_SUBDIR| replace::
|prefix_XXX_SUBDIR| for each ``<prefix>`` in :variable:`CMAKE_PREFIX_PATH`
@@ -71,16 +79,31 @@ If ``NO_DEFAULT_PATH`` is not specified, the search process is as follows:
|prefix_XXX_SUBDIR| for each ``<prefix>`` in
:variable:`CMAKE_SYSTEM_PREFIX_PATH`
-1. Search paths specified in cmake-specific cache variables.
+1. If called from within a find module loaded by
+ :command:`find_package(<PackageName>)`, search prefixes unique to the
+ current package being found. Specifically look in the
+ :variable:`<PackageName>_ROOT` CMake variable and the
+ :envvar:`<PackageName>_ROOT` environment variable.
+ The package root variables are maintained as a stack so if called from
+ nested find modules, root paths from the parent's find module will be
+ searched after paths from the current module,
+ i.e. ``<CurrentPackage>_ROOT``, ``ENV{<CurrentPackage>_ROOT}``,
+ ``<ParentPackage>_ROOT``, ``ENV{<ParentPackage>_ROOT}``, etc.
+ This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed.
+ See policy :policy:`CMP0074`.
+
+ * |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX|
+
+2. Search paths specified in cmake-specific cache variables.
These are intended to be used on the command line with a ``-DVAR=value``.
- The values are interpreted as :ref:`;-lists <CMake Language Lists>`.
+ The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
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.
+3. Search paths specified in cmake-specific environment variables.
These are intended to be set in the user's shell configuration,
and therefore use the host's native path separator
(``;`` on Windows and ``:`` on UNIX).
@@ -90,17 +113,17 @@ If ``NO_DEFAULT_PATH`` is not specified, the search process is as follows:
* |CMAKE_XXX_PATH|
* |CMAKE_XXX_MAC_PATH|
-3. Search the paths specified by the ``HINTS`` option.
+4. 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.
+5. 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
+6. Search cmake variables defined in the Platform files
for the current system. This can be skipped if ``NO_CMAKE_SYSTEM_PATH``
is passed.
@@ -108,13 +131,13 @@ If ``NO_DEFAULT_PATH`` is not specified, the search process is as follows:
* |CMAKE_SYSTEM_XXX_PATH|
* |CMAKE_SYSTEM_XXX_MAC_PATH|
-6. Search the paths specified by the PATHS option
+7. 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
-On OS X the :variable:`CMAKE_FIND_FRAMEWORK` and
+On macOS the :variable:`CMAKE_FIND_FRAMEWORK` and
:variable:`CMAKE_FIND_APPBUNDLE` variables determine the order of
preference between Apple-style and unix-style package components.
diff --git a/Help/command/add_compile_options.rst b/Help/command/add_compile_options.rst
index 3fe2a3330..43805c3a9 100644
--- a/Help/command/add_compile_options.rst
+++ b/Help/command/add_compile_options.rst
@@ -1,23 +1,48 @@
add_compile_options
-------------------
-Adds options to the compilation of source files.
+Add options to the compilation of source files.
-::
+.. code-block:: cmake
add_compile_options(<option> ...)
-Adds options to the compiler command line for targets in the current
-directory and below that are added after this command is invoked.
-See documentation of the :prop_dir:`directory <COMPILE_OPTIONS>` and
-:prop_tgt:`target <COMPILE_OPTIONS>` ``COMPILE_OPTIONS`` properties.
+Adds options to the :prop_dir:`COMPILE_OPTIONS` directory property.
+These options are used when compiling targets from 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`).
+Arguments
+^^^^^^^^^
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.
+
+.. include:: OPTIONS_SHELL.txt
+
+Example
+^^^^^^^
+
+Since different compilers support different options, a typical use of
+this command is in a compiler-specific conditional clause:
+
+.. code-block:: cmake
+
+ if (MSVC)
+ # warning level 4 and all warnings as errors
+ add_compile_options(/W4 /WX)
+ else()
+ # lots of warnings and all warnings as errors
+ add_compile_options(-Wall -Wextra -pedantic -Werror)
+ endif()
+
+See Also
+^^^^^^^^
+
+This command can be used to add any options. However, for
+adding preprocessor definitions and include directories it is recommended
+to use the more specific commands :command:`add_compile_definitions`
+and :command:`include_directories`.
+
+The command :command:`target_compile_options` adds target-specific options.
diff --git a/Help/command/add_custom_command.rst b/Help/command/add_custom_command.rst
index d03840633..ed321fcef 100644
--- a/Help/command/add_custom_command.rst
+++ b/Help/command/add_custom_command.rst
@@ -8,7 +8,9 @@ There are two main signatures for ``add_custom_command``.
Generating Files
^^^^^^^^^^^^^^^^
-The first signature is for adding a custom command to produce an output::
+The first signature is for adding a custom command to produce an output:
+
+.. code-block:: cmake
add_custom_command(OUTPUT output1 [output2 ...]
COMMAND command1 [ARGS] [args1...]
@@ -21,6 +23,7 @@ The first signature is for adding a custom command to produce an output::
[WORKING_DIRECTORY dir]
[COMMENT comment]
[DEPFILE depfile]
+ [JOB_POOL job_pool]
[VERBATIM] [APPEND] [USES_TERMINAL]
[COMMAND_EXPAND_LISTS])
@@ -142,12 +145,21 @@ The options are:
Note that the ``IMPLICIT_DEPENDS`` option is currently supported
only for Makefile generators and will be ignored by other generators.
+``JOB_POOL``
+ Specify a :prop_gbl:`pool <JOB_POOLS>` for the :generator:`Ninja`
+ generator. Incompatible with ``USES_TERMINAL``, which implies
+ the ``console`` pool.
+ Using a pool that is not defined by :prop_gbl:`JOB_POOLS` causes
+ an error by ninja at build time.
+
``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. At most one custom command may specify a
- given source file as its main dependency.
+ the custom command. Each source file may have at most one command
+ specifying it as its main dependency. A compile command (i.e. for a
+ library or an executable) counts as an implicit main dependency which
+ gets silently overwritten by a custom command specification.
``OUTPUT``
Specify the output files the command is expected to produce.
@@ -180,6 +192,9 @@ The options are:
If it is a relative path it will be interpreted relative to the
build tree directory corresponding to the current source directory.
+ Arguments to ``WORKING_DIRECTORY`` may use
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
``DEPFILE``
Specify a ``.d`` depfile for the :generator:`Ninja` generator.
A ``.d`` file holds dependencies usually emitted by the custom
@@ -195,7 +210,7 @@ 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.
-::
+.. code-block:: cmake
add_custom_command(TARGET <target>
PRE_BUILD | PRE_LINK | POST_BUILD
@@ -214,10 +229,9 @@ 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 8 or later.
- For all other generators ``PRE_BUILD`` will be treated as
- ``PRE_LINK``.
+ On :ref:`Visual Studio Generators`, run before any other rules are
+ executed within the target.
+ On other generators, run just before ``PRE_LINK`` commands.
``PRE_LINK``
Run after sources have been compiled but before linking the binary
or running the librarian or archiver tool of a static library.
@@ -225,3 +239,13 @@ of the following is specified:
:command:`add_custom_target` command.
``POST_BUILD``
Run after all other rules within the target have been executed.
+
+.. note::
+ Because generator expressions can be used in custom commands,
+ it is possible to define ``COMMAND`` lines or whole custom commands
+ which evaluate to empty strings for certain configurations.
+ For **Visual Studio 2010 (and newer)** generators these command
+ lines or custom commands will be omitted for the specific
+ configuration and no "empty-string-command" will be added.
+
+ This allows to add individual build events for every configuration.
diff --git a/Help/command/add_custom_target.rst b/Help/command/add_custom_target.rst
index bd61c8b96..08b95168b 100644
--- a/Help/command/add_custom_target.rst
+++ b/Help/command/add_custom_target.rst
@@ -3,7 +3,7 @@ add_custom_target
Add a target with no output so it will always be built.
-::
+.. code-block:: cmake
add_custom_target(Name [ALL] [command1 [args1...]]
[COMMAND command2 [args2...] ...]
@@ -11,6 +11,7 @@ Add a target with no output so it will always be built.
[BYPRODUCTS [files...]]
[WORKING_DIRECTORY dir]
[COMMENT comment]
+ [JOB_POOL job_pool]
[VERBATIM] [USES_TERMINAL]
[COMMAND_EXPAND_LISTS]
[SOURCES src1 [src2...]])
@@ -97,6 +98,13 @@ The options are:
``${CC} "-I$<JOIN:$<TARGET_PROPERTY:foo,INCLUDE_DIRECTORIES>,;-I>" foo.cc``
to be properly expanded.
+``JOB_POOL``
+ Specify a :prop_gbl:`pool <JOB_POOLS>` for the :generator:`Ninja`
+ generator. Incompatible with ``USES_TERMINAL``, which implies
+ the ``console`` pool.
+ Using a pool that is not defined by :prop_gbl:`JOB_POOLS` causes
+ an error by ninja at build time.
+
``SOURCES``
Specify additional source files to be included in the custom target.
Specified source files will be added to IDE project files for
@@ -121,3 +129,6 @@ The options are:
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.
+
+ Arguments to ``WORKING_DIRECTORY`` may use
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
diff --git a/Help/command/add_definitions.rst b/Help/command/add_definitions.rst
index a04faf591..d06b01c9a 100644
--- a/Help/command/add_definitions.rst
+++ b/Help/command/add_definitions.rst
@@ -1,18 +1,26 @@
add_definitions
---------------
-Adds -D define flags to the compilation of source files.
+Add -D define flags to the compilation of source files.
-::
+.. code-block:: cmake
add_definitions(-DFOO -DBAR ...)
Adds definitions to the compiler command line for targets in the current
directory and below (whether added before or after this command is invoked).
This command can be used to add any flags, but it is intended to add
-preprocessor definitions (see the :command:`add_compile_options` command
-to add other flags).
-Flags beginning in -D or /D that look like preprocessor definitions are
+preprocessor definitions.
+
+.. note::
+
+ This command has been superseded by alternatives:
+
+ * Use :command:`add_compile_definitions` to add preprocessor definitions.
+ * Use :command:`include_directories` to add include directories.
+ * Use :command:`add_compile_options` to add other options.
+
+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
diff --git a/Help/command/add_dependencies.rst b/Help/command/add_dependencies.rst
index 7a6614328..de219a508 100644
--- a/Help/command/add_dependencies.rst
+++ b/Help/command/add_dependencies.rst
@@ -3,11 +3,11 @@ add_dependencies
Add a dependency between top-level targets.
-::
+.. code-block:: cmake
add_dependencies(<target> [<target-dependency>]...)
-Make a top-level ``<target>`` depend on other top-level targets to
+Makes 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 one of the :command:`add_executable`,
:command:`add_library`, or :command:`add_custom_target` commands
diff --git a/Help/command/add_executable.rst b/Help/command/add_executable.rst
index c088796e4..0a7d7e151 100644
--- a/Help/command/add_executable.rst
+++ b/Help/command/add_executable.rst
@@ -3,18 +3,19 @@ add_executable
Add an executable to the project using the specified source files.
-::
+.. code-block:: cmake
add_executable(<name> [WIN32] [MACOSX_BUNDLE]
[EXCLUDE_FROM_ALL]
- source1 [source2 ...])
+ [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>``).
+files listed in the command invocation. (The source files can be omitted
+here if they are added later using :command:`target_sources`.) 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
@@ -46,7 +47,7 @@ within IDE.
--------------------------------------------------------------------------
-::
+.. code-block:: cmake
add_executable(<name> IMPORTED [GLOBAL])
@@ -66,15 +67,16 @@ properties for more information.
--------------------------------------------------------------------------
-::
+.. code-block:: cmake
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
+``<target>`` may not be a non-``GLOBAL``
+: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 existence with the regular :command:`if(TARGET)` subcommand.
The ``<name>`` may not be used to modify properties of ``<target>``, that
diff --git a/Help/command/add_library.rst b/Help/command/add_library.rst
index de5335eff..7274e4474 100644
--- a/Help/command/add_library.rst
+++ b/Help/command/add_library.rst
@@ -10,17 +10,18 @@ Add a library to the project using the specified source files.
Normal Libraries
^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
add_library(<name> [STATIC | SHARED | MODULE]
[EXCLUDE_FROM_ALL]
- source1 [source2 ...])
+ [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
+listed in the command invocation. (The source files can be omitted here
+if they are added later using :command:`target_sources`.) 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
@@ -34,7 +35,7 @@ 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.
A ``SHARED`` or ``STATIC`` library may be marked with the :prop_tgt:`FRAMEWORK`
-target property to create an OS X Framework.
+target property to create an macOS Framework.
If a library does not export any symbols, it must not be declared as a
``SHARED`` library. For example, a Windows resource DLL or a managed C++/CLI
@@ -66,7 +67,7 @@ within IDE.
Imported Libraries
^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
add_library(<name> <SHARED|STATIC|MODULE|OBJECT|UNKNOWN> IMPORTED
[GLOBAL])
@@ -79,16 +80,30 @@ 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.
+begin in ``IMPORTED_`` and ``INTERFACE_``.
+
+The most important properties are:
+
+* :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.
+* :prop_tgt:`IMPORTED_OBJECTS` (and :prop_tgt:`IMPORTED_OBJECTS_<CONFIG>`)
+ for object libraries, specifies the locations of object files on disk.
+* :prop_tgt:`PUBLIC_HEADER` files to be installed during :command:`install` invocation
+
+See documentation of the ``IMPORTED_*`` and ``INTERFACE_*`` properties
+for more information.
+
+An ``UNKNOWN`` library type is typically only used in the implementation of
+:ref:`Find Modules`. It allows the path to an imported library (often found
+using the :command:`find_library` command) to be used without having to know
+what type of library it is. This is especially useful on Windows where a
+static library and a DLL's import library both have the same file extension.
Object Libraries
^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
add_library(<name> OBJECT <src>...)
@@ -109,22 +124,23 @@ 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 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>``.
+``PRE_BUILD``, ``PRE_LINK``, or ``POST_BUILD`` commands. Some native build
+systems (such as Xcode) 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
^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
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 generated buildsystem as a make target. The ``<target>``
-may not be an :ref:`Imported Target <Imported Targets>` or an ``ALIAS``.
+may not be a non-``GLOBAL`` :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 existence with the
regular :command:`if(TARGET)` subcommand. The ``<name>`` may not be used
@@ -136,7 +152,7 @@ installed or exported.
Interface Libraries
^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
add_library(<name> INTERFACE [IMPORTED [GLOBAL]])
@@ -148,6 +164,7 @@ the interface target using the commands:
* :command:`set_property`,
* :command:`target_link_libraries(INTERFACE)`,
+* :command:`target_link_options(INTERFACE)`,
* :command:`target_include_directories(INTERFACE)`,
* :command:`target_compile_options(INTERFACE)`,
* :command:`target_compile_definitions(INTERFACE)`, and
diff --git a/Help/command/add_subdirectory.rst b/Help/command/add_subdirectory.rst
index e97925302..8dba986ba 100644
--- a/Help/command/add_subdirectory.rst
+++ b/Help/command/add_subdirectory.rst
@@ -3,12 +3,11 @@ add_subdirectory
Add a subdirectory to the build.
-::
+.. code-block:: cmake
- add_subdirectory(source_dir [binary_dir]
- [EXCLUDE_FROM_ALL])
+ add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL])
-Add a subdirectory to the build. The source_dir specifies the
+Adds 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
@@ -30,7 +29,7 @@ project that is useful but not necessary, such as a set of examples.
Typically the subdirectory should contain its own :command:`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
+dependencies supersede 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
index d8a96e9b9..46b9b63c5 100644
--- a/Help/command/add_test.rst
+++ b/Help/command/add_test.rst
@@ -3,13 +3,13 @@ add_test
Add a test to the project to be run by :manual:`ctest(1)`.
-::
+.. code-block:: cmake
add_test(NAME <name> COMMAND <command> [<arg>...]
[CONFIGURATIONS <config>...]
[WORKING_DIRECTORY <dir>])
-Add a test called ``<name>``. The test name may not contain spaces,
+Adds a test called ``<name>``. The test name may not contain spaces,
quotes, or other characters special in CMake syntax. The options are:
``COMMAND``
@@ -39,7 +39,9 @@ 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::
+Example usage:
+
+.. code-block:: cmake
add_test(NAME mytest
COMMAND testDriver --config $<CONFIGURATION>
@@ -53,11 +55,12 @@ file produced by target ``myexe``.
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``.
+ command automatically unless the ``BUILD_TESTING`` option is turned
+ ``OFF``.
---------------------------------------------------------------------
-::
+.. code-block:: cmake
add_test(<name> <command> [<arg>...])
diff --git a/Help/command/aux_source_directory.rst b/Help/command/aux_source_directory.rst
index dcd1cdfc3..9619f357f 100644
--- a/Help/command/aux_source_directory.rst
+++ b/Help/command/aux_source_directory.rst
@@ -3,7 +3,7 @@ aux_source_directory
Find all source files in a directory.
-::
+.. code-block:: cmake
aux_source_directory(<dir> <variable>)
@@ -11,14 +11,14 @@ 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
+``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
+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
index fc2cd3c7b..4875a2bf2 100644
--- a/Help/command/break.rst
+++ b/Help/command/break.rst
@@ -3,10 +3,10 @@ break
Break from an enclosing foreach or while loop.
-::
+.. code-block:: cmake
break()
-Breaks from an enclosing foreach loop or while loop
+Breaks from an enclosing :command:`foreach` or :command:`while` loop.
See also the :command:`continue` command.
diff --git a/Help/command/build_command.rst b/Help/command/build_command.rst
index b83edaf57..6659005be 100644
--- a/Help/command/build_command.rst
+++ b/Help/command/build_command.rst
@@ -14,7 +14,7 @@ This is mainly intended for internal use by the :module:`CTest` module.
Sets the given ``<variable>`` to a command-line string of the form::
- <cmake> --build . [--config <config>] [--target <target>] [-- -i]
+ <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
diff --git a/Help/command/build_name.rst b/Help/command/build_name.rst
index f717db1dd..2a1fbae62 100644
--- a/Help/command/build_name.rst
+++ b/Help/command/build_name.rst
@@ -1,7 +1,7 @@
build_name
----------
-Disallowed. See CMake Policy :policy:`CMP0036`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0036`.
Use ``${CMAKE_SYSTEM}`` and ``${CMAKE_CXX_COMPILER}`` instead.
diff --git a/Help/command/cmake_host_system_information.rst b/Help/command/cmake_host_system_information.rst
index 9402d57e9..2e9563aab 100644
--- a/Help/command/cmake_host_system_information.rst
+++ b/Help/command/cmake_host_system_information.rst
@@ -3,7 +3,7 @@ cmake_host_system_information
Query host system specific information.
-::
+.. code-block:: cmake
cmake_host_system_information(RESULT <variable> QUERY <key> ...)
@@ -13,13 +13,38 @@ queried. The list of queried values is stored in ``<variable>``.
``<key>`` can be one of the following values:
-::
+============================= ================================================
+Key Description
+============================= ================================================
+``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 MiB [#mebibytes]_
+``AVAILABLE_VIRTUAL_MEMORY`` Available virtual memory in MiB [#mebibytes]_
+``TOTAL_PHYSICAL_MEMORY`` Total physical memory in MiB [#mebibytes]_
+``AVAILABLE_PHYSICAL_MEMORY`` Available physical memory in MiB [#mebibytes]_
+``IS_64BIT`` One if processor is 64Bit
+``HAS_FPU`` One if processor has floating point unit
+``HAS_MMX`` One if processor supports MMX instructions
+``HAS_MMX_PLUS`` One if processor supports Ext. MMX instructions
+``HAS_SSE`` One if processor supports SSE instructions
+``HAS_SSE2`` One if processor supports SSE2 instructions
+``HAS_SSE_FP`` One if processor supports SSE FP instructions
+``HAS_SSE_MMX`` One if processor supports SSE MMX instructions
+``HAS_AMD_3DNOW`` One if processor supports 3DNow instructions
+``HAS_AMD_3DNOW_PLUS`` One if processor supports 3DNow+ instructions
+``HAS_IA64`` One if IA64 processor emulating x86
+``HAS_SERIAL_NUMBER`` One if processor has serial number
+``PROCESSOR_SERIAL_NUMBER`` Processor serial number
+``PROCESSOR_NAME`` Human readable processor name
+``PROCESSOR_DESCRIPTION`` Human readable full processor description
+``OS_NAME`` See :variable:`CMAKE_HOST_SYSTEM_NAME`
+``OS_RELEASE`` The OS sub-type e.g. on Windows ``Professional``
+``OS_VERSION`` The OS build ID
+``OS_PLATFORM`` See :variable:`CMAKE_HOST_SYSTEM_PROCESSOR`
+============================= ================================================
- 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.
+.. rubric:: Footnotes
+
+.. [#mebibytes] One MiB (mebibyte) is equal to 1024x1024 bytes.
diff --git a/Help/command/cmake_minimum_required.rst b/Help/command/cmake_minimum_required.rst
index 9535bf34f..e6ebcf0db 100644
--- a/Help/command/cmake_minimum_required.rst
+++ b/Help/command/cmake_minimum_required.rst
@@ -1,14 +1,26 @@
cmake_minimum_required
----------------------
-Set the minimum required version of cmake for a project and
-update `Policy Settings`_ to match the version given::
+Require a minimum version of cmake.
- cmake_minimum_required(VERSION major.minor[.patch[.tweak]]
- [FATAL_ERROR])
+.. code-block:: cmake
-If the current version of CMake is lower than that required it will
-stop processing the project and report an error.
+ cmake_minimum_required(VERSION <min>[...<max>] [FATAL_ERROR])
+
+Sets the minimum required version of cmake for a project.
+Also updates the policy settings as explained below.
+
+``<min>`` and the optional ``<max>`` are each CMake versions of the form
+``major.minor[.patch[.tweak]]``, and the ``...`` is literal.
+
+If the running version of CMake is lower than the ``<min>`` required
+version it will stop processing the project and report an error.
+The optional ``<max>`` version, if specified, must be at least the
+``<min>`` version and affects policy settings as described below.
+If the running version of CMake is older than 3.12, the extra ``...``
+dots will be seen as version component separators, resulting in the
+``...<max>`` part being ignored and preserving the pre-3.12 behavior
+of basing policies on ``<min>``.
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
@@ -30,21 +42,27 @@ Policy Settings
The ``cmake_minimum_required(VERSION)`` command implicitly invokes the
:command:`cmake_policy(VERSION)` command to specify that the current
-project 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. This effectively requests behavior preferred
+project code is written for the given range of CMake versions.
+All policies known to the running version of CMake and introduced
+in the ``<min>`` (or ``<max>``, if specified) version or earlier will
+be set to use ``NEW`` behavior. All policies introduced in later
+versions will be unset. This effectively requests behavior preferred
as of a given CMake version and tells newer CMake versions to warn
about their new policies.
-When a version higher than 2.4 is specified the command implicitly
-invokes::
+When a ``<min>`` version higher than 2.4 is specified the command
+implicitly invokes
+
+.. code-block:: cmake
+
+ cmake_policy(VERSION <min>[...<max>])
- cmake_policy(VERSION major[.minor[.patch[.tweak]]])
+which sets CMake policies based on the range of versions specified.
+When a ``<min>`` version 2.4 or lower is given the command implicitly
+invokes
-which sets the cmake policy version level to the version specified.
-When version 2.4 or lower is given the command implicitly invokes::
+.. code-block:: cmake
- cmake_policy(VERSION 2.4)
+ cmake_policy(VERSION 2.4[...<max>])
which enables compatibility features for CMake 2.4 and lower.
diff --git a/Help/command/cmake_parse_arguments.rst b/Help/command/cmake_parse_arguments.rst
index ec4ffed3a..fcd36d0a3 100644
--- a/Help/command/cmake_parse_arguments.rst
+++ b/Help/command/cmake_parse_arguments.rst
@@ -1,26 +1,28 @@
cmake_parse_arguments
---------------------
-``cmake_parse_arguments`` is intended to be used in macros or functions for
-parsing the arguments given to that macro or function. It processes the
-arguments and defines a set of variables which hold the values of the
-respective options.
+Parse function or macro arguments.
-::
+.. code-block:: cmake
cmake_parse_arguments(<prefix> <options> <one_value_keywords>
- <multi_value_keywords> args...)
+ <multi_value_keywords> <args>...)
- cmake_parse_arguments(PARSE_ARGV N <prefix> <options> <one_value_keywords>
- <multi_value_keywords>)
+ cmake_parse_arguments(PARSE_ARGV <N> <prefix> <options>
+ <one_value_keywords> <multi_value_keywords>)
-The first signature reads processes arguments passed in the ``args...``.
+This command is for use in macros or functions.
+It processes the arguments given to that macro or function,
+and defines a set of variables which hold the values of the
+respective options.
+
+The first signature reads processes arguments passed in the ``<args>...``.
This may be used in either a :command:`macro` or a :command:`function`.
The ``PARSE_ARGV`` signature is only for use in a :command:`function`
body. In this case the arguments that are parsed come from the
``ARGV#`` variables of the calling function. The parsing starts with
-the Nth argument, where ``N`` is an unsigned integer. This allows for
+the ``<N>``-th argument, where ``<N>`` is an unsigned integer. This allows for
the values to have special characters like ``;`` in them.
The ``<options>`` argument contains all options for the respective macro,
@@ -43,23 +45,31 @@ macro which can be followed by more than one value, like e.g. the
``<multi_value_keywords>``. A warning will be emitted if uniqueness is
violated.
-When done, ``cmake_parse_arguments`` will have defined for each of the
+When done, ``cmake_parse_arguments`` will consider 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``.
+variables will then hold the respective value from the argument list
+or be undefined if the associated option could not be found.
+For the ``<options>`` keywords, these will always be defined,
+to ``TRUE`` or ``FALSE``, whether the option is in the argument list or not.
All remaining arguments are collected in a variable
-``<prefix>_UNPARSED_ARGUMENTS``, this can be checked afterwards to see
+``<prefix>_UNPARSED_ARGUMENTS`` that will be undefined if all arguments
+were recognized. This can be checked afterwards to see
whether your macro was called with unrecognized parameters.
-As an example here a ``my_install()`` macro, which takes similar arguments
-as the real :command:`install` command:
+``<one_value_keywords>`` and ``<multi_value_keywords>`` that were given no
+values at all are collected in a variable ``<prefix>_KEYWORDS_MISSING_VALUES``
+that will be undefined if all keywords received values. This can be checked
+to see if there were keywords without any values given.
+
+Consider the following example macro, ``my_install()``, which takes similar
+arguments to the real :command:`install` command:
.. code-block:: cmake
- function(MY_INSTALL)
+ macro(my_install)
set(options OPTIONAL FAST)
set(oneValueArgs DESTINATION RENAME)
set(multiValueArgs TARGETS CONFIGURATIONS)
@@ -72,25 +82,28 @@ Assume ``my_install()`` has been called like this:
.. code-block:: cmake
- my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub)
+ my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub CONFIGURATIONS)
-After the ``cmake_parse_arguments`` call the macro will have set the
-following variables::
+After the ``cmake_parse_arguments`` call the macro will have set or undefined
+the following variables::
MY_INSTALL_OPTIONAL = TRUE
- MY_INSTALL_FAST = FALSE (was not used in call to my_install)
+ MY_INSTALL_FAST = FALSE # was not used in call to my_install
MY_INSTALL_DESTINATION = "bin"
- MY_INSTALL_RENAME = "" (was not used)
+ MY_INSTALL_RENAME <UNDEFINED> # was not used
MY_INSTALL_TARGETS = "foo;bar"
- MY_INSTALL_CONFIGURATIONS = "" (was not used)
- MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (nothing expected after "OPTIONAL")
+ MY_INSTALL_CONFIGURATIONS <UNDEFINED> # was not used
+ MY_INSTALL_UNPARSED_ARGUMENTS = "blub" # nothing expected after "OPTIONAL"
+ MY_INSTALL_KEYWORDS_MISSING_VALUES = "CONFIGURATIONS"
+ # No value for "CONFIGURATIONS" given
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
+Keywords terminate lists of values, e.g. if directly after a
+``one_value_keyword`` another recognized keyword follows, this is
interpreted as the beginning of the new option. E.g.
``my_install(TARGETS foo DESTINATION OPTIONAL)`` would result in
``MY_INSTALL_DESTINATION`` set to ``"OPTIONAL"``, but as ``OPTIONAL``
-is a keyword itself ``MY_INSTALL_DESTINATION`` will be empty and
-``MY_INSTALL_OPTIONAL`` will therefore be set to ``TRUE``.
+is a keyword itself ``MY_INSTALL_DESTINATION`` will be empty (but added
+to ``MY_INSTALL_KEYWORDS_MISSING_VALUES``) and ``MY_INSTALL_OPTIONAL`` will
+therefore be set to ``TRUE``.
diff --git a/Help/command/cmake_policy.rst b/Help/command/cmake_policy.rst
index b51b9512c..4bc7807bb 100644
--- a/Help/command/cmake_policy.rst
+++ b/Help/command/cmake_policy.rst
@@ -22,19 +22,29 @@ 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
+encourage projects to set policies based on CMake versions:
+
+.. code-block:: cmake
+
+ cmake_policy(VERSION <min>[...<max>])
+
+``<min>`` and the optional ``<max>`` are each CMake versions of the form
+``major.minor[.patch[.tweak]]``, and the ``...`` is literal. The ``<min>``
+version must be at least ``2.4`` and at most the running version of CMake.
+The ``<max>`` version, if specified, must be at least the ``<min>`` version
+but may exceed the running version of CMake. If the running version of
+CMake is older than 3.12, the extra ``...`` dots will be seen as version
+component separators, resulting in the ``...<max>`` part being ignored and
+preserving the pre-3.12 behavior of basing policies on ``<min>``.
+
+This specifies that the current CMake code is written for the given
+range of CMake versions. All policies known to the running version of CMake
+and introduced in the ``<min>`` (or ``<max>``, if specified) version
+or earlier will be set to use ``NEW`` behavior. All policies
+introduced in later versions 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.
@@ -42,7 +52,7 @@ command implicitly calls ``cmake_policy(VERSION)`` too.
Setting Policies Explicitly
^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
cmake_policy(SET CMP<NNNN> NEW)
cmake_policy(SET CMP<NNNN> OLD)
@@ -58,7 +68,7 @@ policy state to ``NEW``.
Checking Policy Settings
^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
cmake_policy(GET CMP<NNNN> <variable>)
@@ -70,14 +80,16 @@ 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
+``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::
+entries on the policy stack:
+
+.. code-block:: cmake
cmake_policy(PUSH)
cmake_policy(POP)
diff --git a/Help/command/configure_file.rst b/Help/command/configure_file.rst
index 4304f095b..29e85bd16 100644
--- a/Help/command/configure_file.rst
+++ b/Help/command/configure_file.rst
@@ -3,7 +3,7 @@ configure_file
Copy a file to another location and modify its contents.
-::
+.. code-block:: cmake
configure_file(<input> <output>
[COPYONLY] [ESCAPE_QUOTES] [@ONLY]
@@ -13,15 +13,21 @@ Copies an ``<input>`` file to an ``<output>`` file and substitutes
variable values referenced as ``@VAR@`` or ``${VAR}`` in the input
file content. Each variable reference will be replaced with the
current value of the variable, or the empty string if the variable
-is not defined. Furthermore, input lines of the form::
+is not defined. Furthermore, input lines of the form
+
+.. code-block:: c
#cmakedefine VAR ...
-will be replaced with either::
+will be replaced with either
+
+.. code-block:: c
#define VAR ...
-or::
+or
+
+.. code-block:: c
/* #undef VAR */
@@ -30,9 +36,27 @@ a false constant by the :command:`if` command. The "..." content on the
line after the variable name, 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.
+The result lines (with the exception of the ``#undef`` comments) can be
+indented using spaces and/or tabs between the ``#`` character
+and the ``cmakedefine`` or ``cmakedefine01`` words. This whitespace
+indentation will be preserved in the output lines:
+
+.. code-block:: c
+
+ # cmakedefine VAR
+ # cmakedefine01 VAR
+
+will be replaced, if ``VAR`` is defined, with
+
+.. code-block:: c
+
+ # define VAR
+ # define VAR 1
If the input file is modified the build system will re-run CMake to
re-configure the file and generate the build system again.
+The generated file is modified and its timestamp updated on subsequent
+cmake runs only if its content is changed.
The arguments are:
diff --git a/Help/command/continue.rst b/Help/command/continue.rst
index 1c7d6730c..31c7089a1 100644
--- a/Help/command/continue.rst
+++ b/Help/command/continue.rst
@@ -3,10 +3,12 @@ continue
Continue to the top of enclosing foreach or while loop.
-::
+.. code-block:: cmake
continue()
The ``continue`` command allows a cmake script to abort the rest of a block
in a :command:`foreach` or :command:`while` loop, and start at the top of
-the next iteration. See also the :command:`break` command.
+the next iteration.
+
+See also the :command:`break` command.
diff --git a/Help/command/create_test_sourcelist.rst b/Help/command/create_test_sourcelist.rst
index dde6812e1..77e37c50f 100644
--- a/Help/command/create_test_sourcelist.rst
+++ b/Help/command/create_test_sourcelist.rst
@@ -3,7 +3,7 @@ create_test_sourcelist
Create a test driver and source list for building test programs.
-::
+.. code-block:: cmake
create_test_sourcelist(sourceListName driverName
test1 test2 test3
diff --git a/Help/command/ctest_build.rst b/Help/command/ctest_build.rst
index 55bb4a317..66e1844e9 100644
--- a/Help/command/ctest_build.rst
+++ b/Help/command/ctest_build.rst
@@ -50,9 +50,7 @@ The options are:
for an example.
``PROJECT_NAME <project-name>``
- Set the name of the project to build. This should correspond
- to the top-level call to the :command:`project` command.
- If not specified the ``CTEST_PROJECT_NAME`` variable will be checked.
+ Ignored. This was once used but is no longer needed.
``TARGET <target-name>``
Specify the name of a target to build. If not specified the
diff --git a/Help/command/ctest_start.rst b/Help/command/ctest_start.rst
index 63db32f4e..6db9a485a 100644
--- a/Help/command/ctest_start.rst
+++ b/Help/command/ctest_start.rst
@@ -5,21 +5,78 @@ Starts the testing for a given model
::
- ctest_start(Model [TRACK <track>] [APPEND] [source [binary]] [QUIET])
+ ctest_start(<model> [<source> [<binary>]] [TRACK <track>] [QUIET])
+
+ ctest_start([<model> [<source> [<binary>]]] [TRACK <track>] APPEND [QUIET])
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 ``QUIET`` is used, CTest will suppress any
-non-error messages that it otherwise would have printed to the console.
-
-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.
+after the binary directory is initialized.
+
+The parameters are as follows:
+
+``<model>``
+ Set the dashboard model. Must be one of ``Experimental``, ``Continuous``, or
+ ``Nightly``. This parameter is required unless ``APPEND`` is specified.
+
+``<source>``
+ Set the source directory. If not specified, the value of
+ :variable:`CTEST_SOURCE_DIRECTORY` is used instead.
+
+``<binary>``
+ Set the binary directory. If not specified, the value of
+ :variable:`CTEST_BINARY_DIRECTORY` is used instead.
+
+``TRACK <track>``
+ If ``TRACK`` is used, the submissions will go to the specified track on the
+ CDash server. If no ``TRACK`` is specified, the name of the model is used by
+ default.
+
+``APPEND``
+ If ``APPEND`` is used, the existing ``TAG`` is used rather than creating a new
+ one based on the current time stamp. If you use ``APPEND``, you can omit the
+ ``<model>`` and ``TRACK <track>`` parameters, because they will be read from
+ the generated ``TAG`` file. For example:
+
+ .. code-block:: cmake
+
+ ctest_start(Experimental TRACK TrackExperimental)
+
+ Later, in another ``ctest -S`` script:
+
+ .. code-block:: cmake
+
+ ctest_start(APPEND)
+
+ When the second script runs ``ctest_start(APPEND)``, it will read the
+ ``Experimental`` model and ``TrackExperimental`` track from the ``TAG`` file
+ generated by the first ``ctest_start()`` command. Please note that if you
+ call ``ctest_start(APPEND)`` and specify a different model or track than
+ in the first ``ctest_start()`` command, a warning will be issued, and the
+ new model and track will be used.
+
+``QUIET``
+ If ``QUIET`` is used, CTest will suppress any non-error messages that it
+ otherwise would have printed to the console.
+
+The parameters for ``ctest_start()`` can be issued in any order, with the
+exception that ``<model>``, ``<source>``, and ``<binary>`` have to appear
+in that order with respect to each other. The following are all valid and
+equivalent:
+
+.. code-block:: cmake
+
+ ctest_start(Experimental path/to/source path/to/binary TRACK SomeTrack QUIET APPEND)
+
+ ctest_start(TRACK SomeTrack Experimental QUIET path/to/source APPEND path/to/binary)
+
+ ctest_start(APPEND QUIET Experimental path/to/source TRACK SomeTrack path/to/binary)
+
+However, for the sake of readability, it is recommended that you order your
+parameters in the order listed at the top of this page.
+
+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
index 6b49da392..983fc20ce 100644
--- a/Help/command/ctest_submit.rst
+++ b/Help/command/ctest_submit.rst
@@ -6,10 +6,13 @@ Perform the :ref:`CTest Submit Step` as a :ref:`Dashboard Client`.
::
ctest_submit([PARTS <part>...] [FILES <file>...]
+ [SUBMIT_URL <url>]
+ [BUILD_ID <result-var>]
[HTTPHEADER <header>]
[RETRY_COUNT <count>]
[RETRY_DELAY <delay>]
[RETURN_VALUE <result-var>]
+ [CAPTURE_CMAKE_ERROR <result-var>]
[QUIET]
)
@@ -32,14 +35,31 @@ The options are:
ExtraFiles = Files listed by CTEST_EXTRA_SUBMIT_FILES
Upload = Files prepared for upload by ctest_upload(), in Upload.xml
Submit = nothing
+ Done = Build is complete, in Done.xml
``FILES <file>...``
Specify an explicit list of specific files to be submitted.
Each individual file must exist at the time of the call.
+``SUBMIT_URL <url>``
+ The ``http`` or ``https`` URL of the dashboard server to send the submission
+ to. If not given, the :variable:`CTEST_SUBMIT_URL` variable is used.
+
+``BUILD_ID <result-var>``
+ Store in the ``<result-var>`` variable the ID assigned to this build by
+ CDash.
+
``HTTPHEADER <HTTP-header>``
Specify HTTP header to be included in the request to CDash during submission.
- This suboption can be repeated several times.
+ For example, CDash can be configured to only accept submissions from
+ authenticated clients. In this case, you should provide a bearer token in your
+ header:
+
+ .. code-block:: cmake
+
+ ctest_submit(HTTPHEADER "Authorization: Bearer <auth-token>")
+
+ This suboption can be repeated several times for multiple headers.
``RETRY_COUNT <count>``
Specify how many times to retry a timed-out submission.
@@ -52,6 +72,10 @@ The options are:
Store in the ``<result-var>`` variable ``0`` for success and
non-zero on failure.
+``CAPTURE_CMAKE_ERROR <result-var>``
+ Store in the ``<result-var>`` variable -1 if there are any errors running
+ the command and prevent ctest from returning non-zero if an error occurs.
+
``QUIET``
Suppress all non-error messages that would have otherwise been
printed to the console.
@@ -62,16 +86,19 @@ Submit to CDash Upload API
::
ctest_submit(CDASH_UPLOAD <file> [CDASH_UPLOAD_TYPE <type>]
+ [SUBMIT_URL <url>]
[HTTPHEADER <header>]
[RETRY_COUNT <count>]
[RETRY_DELAY <delay>]
+ [RETURN_VALUE <result-var>]
[QUIET])
This second signature is used to upload files to CDash via the CDash
-file upload API. The api first sends a request to upload to CDash along
+file upload API. The API first sends a request to upload to CDash along
with a content hash of the file. If CDash does not already have the file,
then it is uploaded. Along with the file, a CDash type string is specified
to tell CDash which handler to use to process the data.
-This signature accepts the ``HTTPHEADER``, ``RETRY_COUNT``, ``RETRY_DELAY``, and
-``QUIET`` options as described above.
+This signature accepts the ``SUBMIT_URL``, ``BUILD_ID``, ``HTTPHEADER``,
+``RETRY_COUNT``, ``RETRY_DELAY``, ``RETURN_VALUE`` and ``QUIET`` options
+as described above.
diff --git a/Help/command/ctest_update.rst b/Help/command/ctest_update.rst
index b205bca93..96a11c913 100644
--- a/Help/command/ctest_update.rst
+++ b/Help/command/ctest_update.rst
@@ -5,7 +5,10 @@ Perform the :ref:`CTest Update Step` as a :ref:`Dashboard Client`.
::
- ctest_update([SOURCE <source-dir>] [RETURN_VALUE <result-var>] [QUIET])
+ ctest_update([SOURCE <source-dir>]
+ [RETURN_VALUE <result-var>]
+ [CAPTURE_CMAKE_ERROR <result-var>]
+ [QUIET])
Update the source tree from version control and record results in
``Update.xml`` for submission with the :command:`ctest_submit` command.
@@ -20,6 +23,10 @@ The options are:
Store in the ``<result-var>`` variable the number of files
updated or ``-1`` on error.
+``CAPTURE_CMAKE_ERROR <result-var>``
+ Store in the ``<result-var>`` variable -1 if there are any errors running
+ the command and prevent ctest from returning non-zero if an error occurs.
+
``QUIET``
Tell CTest to suppress most non-error messages that it would
have otherwise printed to the console. CTest will still report
@@ -28,4 +35,5 @@ The options are:
The update always follows the version control branch currently checked
out in the source directory. See the :ref:`CTest Update Step`
-documentation for more information.
+documentation for information about variables that change the behavior
+of ``ctest_update()``.
diff --git a/Help/command/define_property.rst b/Help/command/define_property.rst
index 873c6cabb..8f7439bbe 100644
--- a/Help/command/define_property.rst
+++ b/Help/command/define_property.rst
@@ -3,7 +3,7 @@ define_property
Define and document custom properties.
-::
+.. code-block:: cmake
define_property(<GLOBAL | DIRECTORY | TARGET | SOURCE |
TEST | VARIABLE | CACHED_VARIABLE>
@@ -11,7 +11,7 @@ Define and document custom properties.
BRIEF_DOCS <brief-doc> [docs...]
FULL_DOCS <full-doc> [docs...])
-Define one property in a scope for use with the :command:`set_property` and
+Defines one property in a scope for use with the :command:`set_property` and
:command:`get_property` commands. This is primarily useful to associate
documentation with property names that may be retrieved with the
:command:`get_property` command. The first argument determines the kind of
@@ -34,10 +34,24 @@ 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 :command:`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``.
+If the ``INHERITED`` option is given, then the :command:`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 its parent directory's scope, continuing the
+ walk up parent directories until a directory has the property set or there
+ are no more parents. If still not found at the top level directory, it
+ chains to the ``GLOBAL`` scope.
+* ``TARGET``, ``SOURCE`` and ``TEST`` properties chain to ``DIRECTORY`` scope,
+ including further chaining up the directories, etc. as needed.
+
+Note that this scope chaining behavior only applies to calls to
+:command:`get_property`, :command:`get_directory_property`,
+:command:`get_target_property`, :command:`get_source_file_property` and
+:command:`get_test_property`. There is no inheriting behavior when *setting*
+properties, so using ``APPEND`` or ``APPEND_STRING`` with the
+:command:`set_property` command will not consider inherited values when working
+out the contents to append to.
The ``BRIEF_DOCS`` and ``FULL_DOCS`` options are followed by strings to be
associated with the property as its brief and full documentation.
diff --git a/Help/command/else.rst b/Help/command/else.rst
index 0e5a19810..a98fcd88e 100644
--- a/Help/command/else.rst
+++ b/Help/command/else.rst
@@ -3,8 +3,8 @@ else
Starts the else portion of an if block.
-::
+.. code-block:: cmake
- else(expression)
+ else([<condition>])
See the :command:`if` command.
diff --git a/Help/command/elseif.rst b/Help/command/elseif.rst
index 9a8dfed1d..6bf8646fb 100644
--- a/Help/command/elseif.rst
+++ b/Help/command/elseif.rst
@@ -1,10 +1,11 @@
elseif
------
-Starts the elseif portion of an if block.
+Starts an elseif portion of an if block.
-::
+.. code-block:: cmake
- elseif(expression)
+ elseif(<condition>)
-See the :command:`if` command.
+See the :command:`if` command, especially for the syntax and logic
+of the ``<condition>``.
diff --git a/Help/command/enable_language.rst b/Help/command/enable_language.rst
index 444556151..fb49b4432 100644
--- a/Help/command/enable_language.rst
+++ b/Help/command/enable_language.rst
@@ -3,14 +3,17 @@ enable_language
Enable a language (CXX/C/Fortran/etc)
-::
+.. code-block:: cmake
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
+Enables support for the named language in CMake. This is
+the same as the :command:`project` command but does not create any of the extra
variables that are created by the project command. Example languages
-are CXX, C, Fortran.
+are ``CXX``, ``C``, ``CUDA``, ``Fortran``, and ``ASM``.
+
+If enabling ``ASM``, enable it last so that CMake can check whether
+compilers for other languages like ``C`` work for assembly too.
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
@@ -19,4 +22,5 @@ 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.
+does not currently work. Instead you can use the :module:`CheckLanguage`
+module to verify support before enabling.
diff --git a/Help/command/enable_testing.rst b/Help/command/enable_testing.rst
index 1e3e2799c..3ac1a198a 100644
--- a/Help/command/enable_testing.rst
+++ b/Help/command/enable_testing.rst
@@ -3,11 +3,18 @@ enable_testing
Enable testing for current directory and below.
-::
+.. code-block:: cmake
enable_testing()
-Enables testing for this directory and below. See also the
-:command:`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.
+Enables testing for this directory and below.
+
+This command should be in the source directory root
+because ctest expects to find a test file in the build
+directory root.
+
+This command is automatically invoked when the :module:`CTest`
+module is included, except if the ``BUILD_TESTING`` option is
+turned off.
+
+See also the :command:`add_test` command.
diff --git a/Help/command/endforeach.rst b/Help/command/endforeach.rst
index 9af972bee..fd923d56a 100644
--- a/Help/command/endforeach.rst
+++ b/Help/command/endforeach.rst
@@ -3,8 +3,12 @@ endforeach
Ends a list of commands in a foreach block.
-::
+.. code-block:: cmake
- endforeach(expression)
+ endforeach([<loop_var>])
See the :command:`foreach` command.
+
+The optional ``<loop_var>`` argument is supported for backward compatibility
+only. If used it must be a verbatim repeat of the ``<loop_var>`` argument of
+the opening ``foreach`` clause.
diff --git a/Help/command/endfunction.rst b/Help/command/endfunction.rst
index 6cc196cde..e27129d8a 100644
--- a/Help/command/endfunction.rst
+++ b/Help/command/endfunction.rst
@@ -3,8 +3,12 @@ endfunction
Ends a list of commands in a function block.
-::
+.. code-block:: cmake
- endfunction(expression)
+ endfunction([<name>])
See the :command:`function` command.
+
+The optional ``<name>`` argument is supported for backward compatibility
+only. If used it must be a verbatim repeat of the ``<name>`` argument
+of the opening ``function`` command.
diff --git a/Help/command/endif.rst b/Help/command/endif.rst
index a0163bf33..fc4f03822 100644
--- a/Help/command/endif.rst
+++ b/Help/command/endif.rst
@@ -3,8 +3,12 @@ endif
Ends a list of commands in an if block.
-::
+.. code-block:: cmake
- endif(expression)
+ endif([<condition>])
See the :command:`if` command.
+
+The optional ``<condition>`` argument is supported for backward compatibility
+only. If used it must be a verbatim repeat of the argument of the opening
+``if`` clause.
diff --git a/Help/command/endmacro.rst b/Help/command/endmacro.rst
index 47327a783..4290ba748 100644
--- a/Help/command/endmacro.rst
+++ b/Help/command/endmacro.rst
@@ -3,8 +3,12 @@ endmacro
Ends a list of commands in a macro block.
-::
+.. code-block:: cmake
- endmacro(expression)
+ endmacro([<name>])
See the :command:`macro` command.
+
+The optional ``<name>`` argument is supported for backward compatibility
+only. If used it must be a verbatim repeat of the ``<name>`` argument
+of the opening ``macro`` command.
diff --git a/Help/command/endwhile.rst b/Help/command/endwhile.rst
index 798c20e71..5ef585bdc 100644
--- a/Help/command/endwhile.rst
+++ b/Help/command/endwhile.rst
@@ -3,8 +3,12 @@ endwhile
Ends a list of commands in a while block.
-::
+.. code-block:: cmake
- endwhile(expression)
+ endwhile([<condition>])
See the :command:`while` command.
+
+The optional ``<condition>`` argument is supported for backward compatibility
+only. If used it must be a verbatim repeat of the argument of the opening
+``while`` clause.
diff --git a/Help/command/exec_program.rst b/Help/command/exec_program.rst
index 6dfdad394..bc9b06916 100644
--- a/Help/command/exec_program.rst
+++ b/Help/command/exec_program.rst
@@ -1,7 +1,9 @@
exec_program
------------
-Deprecated. Use the :command:`execute_process` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`execute_process` command instead.
Run an executable program during the processing of the CMakeList.txt
file.
diff --git a/Help/command/execute_process.rst b/Help/command/execute_process.rst
index d617243d1..14f879d03 100644
--- a/Help/command/execute_process.rst
+++ b/Help/command/execute_process.rst
@@ -5,11 +5,12 @@ Execute one or more child processes.
.. code-block:: cmake
- execute_process(COMMAND <cmd1> [args1...]]
- [COMMAND <cmd2> [args2...] [...]]
+ execute_process(COMMAND <cmd1> [<arguments>]
+ [COMMAND <cmd2> [<arguments>]]...
[WORKING_DIRECTORY <directory>]
[TIMEOUT <seconds>]
[RESULT_VARIABLE <variable>]
+ [RESULTS_VARIABLE <variable>]
[OUTPUT_VARIABLE <variable>]
[ERROR_VARIABLE <variable>]
[INPUT_FILE <file>]
@@ -17,11 +18,14 @@ Execute one or more child processes.
[ERROR_FILE <file>]
[OUTPUT_QUIET]
[ERROR_QUIET]
+ [COMMAND_ECHO <where>]
[OUTPUT_STRIP_TRAILING_WHITESPACE]
[ERROR_STRIP_TRAILING_WHITESPACE]
[ENCODING <name>])
-Runs the given sequence of one or more commands in parallel with the standard
+Runs the given sequence of one or more commands.
+
+Commands are executed concurrently as a pipeline, 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.
@@ -45,14 +49,21 @@ Options:
the child processes.
``TIMEOUT``
- The child processes will be terminated if they do not finish in the
- specified number of seconds (fractions are allowed).
+ After the specified number of seconds (fractions allowed), all unfinished
+ child processes will be terminated, and the ``RESULT_VARIABLE`` will be
+ set to a string mentioning the "timeout".
``RESULT_VARIABLE``
- The variable will be set to contain the result of running the processes.
+ The variable will be set to contain the result of last child process.
This will be an integer return code from the last child or a string
describing an error condition.
+``RESULTS_VARIABLE <variable>``
+ The variable will be set to contain the result of all processes as a
+ :ref:`semicolon-separated list <CMake Language Lists>`, in order of the
+ given ``COMMAND`` arguments. Each entry will be an integer return code
+ from the corresponding 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
@@ -67,6 +78,12 @@ Options:
``OUTPUT_QUIET``, ``ERROR_QUIET``
The standard output or standard error results will be quietly ignored.
+``COMMAND_ECHO <where>``
+ The command being run will be echo'ed to ``<where>`` with ``<where>``
+ being set to one of ``STDERR``, ``STDOUT`` or ``NONE``.
+ See the :variable:`CMAKE_EXECUTE_PROCESS_COMMAND_ECHO` variable for a way
+ to control the default behavior when this option is not present.
+
``ENCODING <name>``
On Windows, the encoding that is used to decode output from the process.
Ignored on other platforms.
@@ -83,8 +100,10 @@ Options:
Use the ANSI codepage.
``OEM``
Use the original equipment manufacturer (OEM) code page.
- ``UTF8``
- Use the UTF-8 codepage.
+ ``UTF8`` or ``UTF-8``
+ Use the UTF-8 codepage. Prior to CMake 3.11.0, only ``UTF8`` was accepted
+ for this encoding. In CMake 3.11.0, ``UTF-8`` was added for consistency with
+ the `UTF-8 RFC <https://www.ietf.org/rfc/rfc3629>`_ naming convention.
If more than one ``OUTPUT_*`` or ``ERROR_*`` option is given for the
same pipe the precedence is not specified.
diff --git a/Help/command/export.rst b/Help/command/export.rst
index 53675a756..2ca705616 100644
--- a/Help/command/export.rst
+++ b/Help/command/export.rst
@@ -3,11 +3,11 @@ export
Export targets from the build tree for use by outside projects.
-::
+.. code-block:: cmake
export(EXPORT <export-name> [NAMESPACE <namespace>] [FILE <filename>])
-Create a file ``<filename>`` that may be included by outside projects to
+Creates 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
@@ -25,7 +25,7 @@ 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.
-::
+.. code-block:: cmake
export(TARGETS [target1 [target2 [...]]] [NAMESPACE <namespace>]
[APPEND] FILE <filename> [EXPORT_LINK_INTERFACE_LIBRARIES])
@@ -40,23 +40,37 @@ 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.
-::
+.. note::
- export(PACKAGE <name>)
+ :ref:`Object Libraries` under :generator:`Xcode` have special handling if
+ multiple architectures are listed in :variable:`CMAKE_OSX_ARCHITECTURES`.
+ In this case they will be exported as :ref:`Interface Libraries` with
+ no object files available to clients. This is sufficient to satisfy
+ transitive usage requirements of other targets that link to the
+ object libraries in their implementation.
+
+.. code-block:: cmake
+
+ export(PACKAGE <PackageName>)
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
+for package ``<PackageName>``. The :command:`find_package` command may consider the
+directory while searching for package ``<PackageName>``. 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
+package configuration file (``<PackageName>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.
+registry.
+
+By default the ``export(PACKAGE)`` command does nothing (see policy
+:policy:`CMP0090`) because populating the user package registry has effects
+outside the source and build trees. Set the
+:variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable to add build directories to
+the CMake user package registry.
-::
+.. code-block:: cmake
export(TARGETS [target1 [target2 [...]]] [ANDROID_MK <filename>])
diff --git a/Help/command/export_library_dependencies.rst b/Help/command/export_library_dependencies.rst
index 2cb437e77..9753abf54 100644
--- a/Help/command/export_library_dependencies.rst
+++ b/Help/command/export_library_dependencies.rst
@@ -1,7 +1,7 @@
export_library_dependencies
---------------------------
-Disallowed. See CMake Policy :policy:`CMP0033`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0033`.
Use :command:`install(EXPORT)` or :command:`export` command.
diff --git a/Help/command/file.rst b/Help/command/file.rst
index b2e4eea44..f99021ef6 100644
--- a/Help/command/file.rst
+++ b/Help/command/file.rst
@@ -3,22 +3,49 @@ file
File manipulation command.
-------------------------------------------------------------------------------
+Synopsis
+^^^^^^^^
-::
+.. parsed-literal::
- file(WRITE <filename> <content>...)
- file(APPEND <filename> <content>...)
+ `Reading`_
+ file(`READ`_ <filename> <out-var> [...])
+ file(`STRINGS`_ <filename> <out-var> [...])
+ file(`\<HASH\> <HASH_>`_ <filename> <out-var>)
+ file(`TIMESTAMP`_ <filename> <out-var> [...])
-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.)
+ `Writing`_
+ file({`WRITE`_ | `APPEND`_} <filename> <content>...)
+ file({`TOUCH`_ | `TOUCH_NOCREATE`_} [<file>...])
+ file(`GENERATE`_ OUTPUT <output-file> [...])
+
+ `Filesystem`_
+ file({`GLOB`_ | `GLOB_RECURSE`_} <out-var> [...] [<globbing-expr>...])
+ file(`RENAME`_ <oldname> <newname>)
+ file({`REMOVE`_ | `REMOVE_RECURSE`_ } [<files>...])
+ file(`MAKE_DIRECTORY`_ [<dir>...])
+ file({`COPY`_ | `INSTALL`_} <file>... DESTINATION <dir> [...])
+ file(`SIZE`_ <filename> <out-var>)
+ file(`READ_SYMLINK`_ <linkname> <out-var>)
+ file(`CREATE_LINK`_ <original> <linkname> [...])
+
+ `Path Conversion`_
+ file(`RELATIVE_PATH`_ <out-var> <directory> <file>)
+ file({`TO_CMAKE_PATH`_ | `TO_NATIVE_PATH`_} <path> <out-var>)
+
+ `Transfer`_
+ file(`DOWNLOAD`_ <url> <file> [...])
+ file(`UPLOAD`_ <file> <url> [...])
-------------------------------------------------------------------------------
+ `Locking`_
+ file(`LOCK`_ <path> [...])
-::
+Reading
+^^^^^^^
+
+.. _READ:
+
+.. code-block:: cmake
file(READ <filename> <variable>
[OFFSET <offset>] [LIMIT <max-in>] [HEX])
@@ -28,9 +55,9 @@ Read content from a file called ``<filename>`` and store it in a
read at most ``<max-in>`` bytes. The ``HEX`` option causes data to
be converted to a hexadecimal representation (useful for binary data).
-------------------------------------------------------------------------------
+.. _STRINGS:
-::
+.. code-block:: cmake
file(STRINGS <filename> <variable> [<options>...])
@@ -79,9 +106,9 @@ For example, the code
stores a list in the variable ``myfile`` in which each item is a line
from the input file.
-------------------------------------------------------------------------------
+.. _HASH:
-::
+.. code-block:: cmake
file(<HASH> <filename> <variable>)
@@ -90,26 +117,130 @@ store it in a ``<variable>``. The supported ``<HASH>`` algorithm names
are those listed by the :ref:`string(\<HASH\>) <Supported Hash Algorithms>`
command.
-------------------------------------------------------------------------------
+.. _TIMESTAMP:
+
+.. code-block:: cmake
+
+ 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.
+
+Writing
+^^^^^^^
+
+.. _WRITE:
+.. _APPEND:
+
+.. code-block:: cmake
+
+ 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.
+Any directories in the path specified by ``<filename>`` that do not
+exist will be created.
+
+If the file is a build input, use the :command:`configure_file` command
+to update the file only when its content changes.
+
+.. _TOUCH:
+.. _TOUCH_NOCREATE:
+
+.. code-block:: cmake
+
+ file(TOUCH [<files>...])
+ file(TOUCH_NOCREATE [<files>...])
+
+Create a file with no content if it does not yet exist. If the file already
+exists, its access and/or modification will be updated to the time when the
+function call is executed.
+
+Use TOUCH_NOCREATE to touch a file if it exists but not create it. If a file
+does not exist it will be silently ignored.
+
+With TOUCH and TOUCH_NOCREATE the contents of an existing file will not be
+modified.
+
+.. _GENERATE:
+
+.. code-block:: cmake
+
+ file(GENERATE OUTPUT output-file
+ <INPUT input-file|CONTENT content>
+ [CONDITION expression])
+
+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.
+ A relative path is treated with respect to the value of
+ :variable:`CMAKE_CURRENT_SOURCE_DIR`. See policy :policy:`CMP0070`.
+
+``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.
+ A relative path (after evaluating generator expressions) is treated
+ with respect to the value of :variable:`CMAKE_CURRENT_BINARY_DIR`.
+ See policy :policy:`CMP0070`.
+
+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 and their timestamp updated on subsequent cmake
+runs only if their content is changed.
+
+Note also that ``file(GENERATE)`` does not create the output file until the
+generation phase. The output file will not yet have been written when the
+``file(GENERATE)`` command returns, it is written only after processing all
+of a project's ``CMakeLists.txt`` files.
+
+Filesystem
+^^^^^^^^^^
+
+.. _GLOB:
+.. _GLOB_RECURSE:
+
+.. code-block:: cmake
file(GLOB <variable>
- [LIST_DIRECTORIES true|false] [RELATIVE <path>]
+ [LIST_DIRECTORIES true|false] [RELATIVE <path>] [CONFIGURE_DEPENDS]
[<globbing-expressions>...])
file(GLOB_RECURSE <variable> [FOLLOW_SYMLINKS]
- [LIST_DIRECTORIES true|false] [RELATIVE <path>]
+ [LIST_DIRECTORIES true|false] [RELATIVE <path>] [CONFIGURE_DEPENDS]
[<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. No specific order of results is defined other than that it is
-deterministic. If order is important then sort the list explicitly
-(e.g. using the :command:`list(SORT)` command).
+path. The results will be ordered lexicographically.
-By default ``GLOB`` lists directories - directories are omited in result if
+If the ``CONFIGURE_DEPENDS`` flag is specified, CMake will add logic
+to the main build system check target to rerun the flagged ``GLOB`` commands
+at build time. If any of the outputs change, CMake will regenerate the build
+system.
+
+By default ``GLOB`` lists directories - directories are omitted in result if
``LIST_DIRECTORIES`` is set to false.
.. note::
@@ -117,6 +248,10 @@ By default ``GLOB`` lists directories - directories are omited in result if
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.
+ The ``CONFIGURE_DEPENDS`` flag may not work reliably on all generators, or if
+ a new generator is added in the future that cannot support it, projects using
+ it will be stuck. Even if ``CONFIGURE_DEPENDS`` works reliably, there is
+ still a cost to perform the check on every rebuild.
Examples of globbing expressions include::
@@ -138,46 +273,168 @@ Examples of recursive globbing include::
/dir/*.py - match all python files in /dir and subdirectories
-------------------------------------------------------------------------------
+.. _RENAME:
-::
+.. code-block:: cmake
file(RENAME <oldname> <newname>)
Move a file or directory within a filesystem from ``<oldname>`` to
``<newname>``, replacing the destination atomically.
-------------------------------------------------------------------------------
+.. _REMOVE:
+.. _REMOVE_RECURSE:
-::
+.. code-block:: cmake
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. No error is emitted if a
-given file does not exist.
+given file does not exist. Relative input paths are evaluated with respect
+to the current source directory. Empty input paths are ignored with a warning.
-------------------------------------------------------------------------------
+.. _MAKE_DIRECTORY:
-::
+.. code-block:: cmake
file(MAKE_DIRECTORY [<directories>...])
Create the given directories and their parents as needed.
-------------------------------------------------------------------------------
+.. _COPY:
+.. _INSTALL:
-::
+.. code-block:: cmake
+
+ file(<COPY|INSTALL> <files>... DESTINATION <dir>
+ [FILE_PERMISSIONS <permissions>...]
+ [DIRECTORY_PERMISSIONS <permissions>...]
+ [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]
+ [FOLLOW_SYMLINK_CHAIN]
+ [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``).
+
+If ``FOLLOW_SYMLINK_CHAIN`` is specified, ``COPY`` will recursively resolve
+the symlinks at the paths given until a real file is found, and install
+a corresponding symlink in the destination for each symlink encountered. For
+each symlink that is installed, the resolution is stripped of the directory,
+leaving only the filename, meaning that the new symlink points to a file in
+the same directory as the symlink. This feature is useful on some Unix systems,
+where libraries are installed as a chain of symlinks with version numbers, with
+less specific versions pointing to more specific versions.
+``FOLLOW_SYMLINK_CHAIN`` will install all of these symlinks and the library
+itself into the destination directory. For example, if you have the following
+directory structure:
+
+* ``/opt/foo/lib/libfoo.so.1.2.3``
+* ``/opt/foo/lib/libfoo.so.1.2 -> libfoo.so.1.2.3``
+* ``/opt/foo/lib/libfoo.so.1 -> libfoo.so.1.2``
+* ``/opt/foo/lib/libfoo.so -> libfoo.so.1``
+
+and you do:
+
+.. code-block:: cmake
+
+ file(COPY /opt/foo/lib/libfoo.so DESTINATION lib FOLLOW_SYMLINK_CHAIN)
+
+This will install all of the symlinks and ``libfoo.so.1.2.3`` itself into
+``lib``.
+
+See the :command:`install(DIRECTORY)` command for documentation of
+permissions, ``FILES_MATCHING``, ``PATTERN``, ``REGEX``, and
+``EXCLUDE`` options. Copying directories preserves the structure
+of their content even if options are used to select a subset of
+files.
+
+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).
+
+.. _SIZE:
+
+.. code-block:: cmake
+
+ file(SIZE <filename> <variable>)
+
+Determine the file size of the ``<filename>`` and put the result in
+``<variable>`` variable. Requires that ``<filename>`` is a valid path
+pointing to a file and is readable.
+
+.. _READ_SYMLINK:
+
+.. code-block:: cmake
+
+ file(READ_SYMLINK <linkname> <variable>)
+
+This subcommand queries the symlink ``<linkname>`` and stores the path it
+points to in the result ``<variable>``. If ``<linkname>`` does not exist or
+is not a symlink, CMake issues a fatal error.
+
+Note that this command returns the raw symlink path and does not resolve
+a relative path. The following is an example of how to ensure that an
+absolute path is obtained:
+
+.. code-block:: cmake
+
+ set(linkname "/path/to/foo.sym")
+ file(READ_SYMLINK "${linkname}" result)
+ if(NOT IS_ABSOLUTE "${result}")
+ get_filename_component(dir "${linkname}" DIRECTORY)
+ set(result "${dir}/${result}")
+ endif()
+
+.. _CREATE_LINK:
+
+.. code-block:: cmake
+
+ file(CREATE_LINK <original> <linkname>
+ [RESULT <result>] [COPY_ON_ERROR] [SYMBOLIC])
+
+Create a link ``<linkname>`` that points to ``<original>``.
+It will be a hard link by default, but providing the ``SYMBOLIC`` option
+results in a symbolic link instead. Hard links require that ``original``
+exists and is a file, not a directory. If ``<linkname>`` already exists,
+it will be overwritten.
+
+The ``<result>`` variable, if specified, receives the status of the operation.
+It is set to ``0`` upon success or an error message otherwise. If ``RESULT``
+is not specified and the operation fails, a fatal error is emitted.
+
+Specifying ``COPY_ON_ERROR`` enables copying the file as a fallback if
+creating the link fails. It can be useful for handling situations such as
+``<original>`` and ``<linkname>`` being on different drives or mount points,
+which would make them unable to support a hard link.
+
+Path Conversion
+^^^^^^^^^^^^^^^
+
+.. _RELATIVE_PATH:
+
+.. code-block:: cmake
file(RELATIVE_PATH <variable> <directory> <file>)
Compute the relative path from a ``<directory>`` to a ``<file>`` and
store it in the ``<variable>``.
-------------------------------------------------------------------------------
+.. _TO_CMAKE_PATH:
+.. _TO_NATIVE_PATH:
-::
+.. code-block:: cmake
file(TO_CMAKE_PATH "<path>" <variable>)
file(TO_NATIVE_PATH "<path>" <variable>)
@@ -193,9 +450,13 @@ 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.
-------------------------------------------------------------------------------
+Transfer
+^^^^^^^^
-::
+.. _DOWNLOAD:
+.. _UPLOAD:
+
+.. code-block:: cmake
file(DOWNLOAD <url> <file> [<options>...])
file(UPLOAD <file> <url> [<options>...])
@@ -231,6 +492,31 @@ Options to both ``DOWNLOAD`` and ``UPLOAD`` are:
``HTTPHEADER <HTTP-header>``
HTTP header for operation. Suboption can be repeated several times.
+``NETRC <level>``
+ Specify whether the .netrc file is to be used for operation. If this
+ option is not specified, the value of the ``CMAKE_NETRC`` variable
+ will be used instead.
+ Valid levels are:
+
+ ``IGNORED``
+ The .netrc file is ignored.
+ This is the default.
+ ``OPTIONAL``
+ The .netrc file is optional, and information in the URL is preferred.
+ The file will be scanned to find which ever information is not specified
+ in the URL.
+ ``REQUIRED``
+ The .netrc file is required, and information in the URL is ignored.
+
+``NETRC_FILE <file>``
+ Specify an alternative .netrc file to the one in your home directory,
+ if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option
+ is not specified, the value of the ``CMAKE_NETRC_FILE`` variable will
+ be used instead.
+
+If neither ``NETRC`` option is given CMake will check variables
+``CMAKE_NETRC`` and ``CMAKE_NETRC_FILE``, respectively.
+
Additional options to ``DOWNLOAD`` are:
``EXPECTED_HASH ALGO=<value>``
@@ -255,96 +541,12 @@ 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.
-------------------------------------------------------------------------------
+Locking
+^^^^^^^
-::
+.. _LOCK:
- 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 OUTPUT output-file
- <INPUT input-file|CONTENT content>
- [CONDITION expression])
-
-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.
-
-Note also that ``file(GENERATE)`` does not create the output file until the
-generation phase. The output file will not yet have been written when the
-``file(GENERATE)`` command returns, it is written only after processing all
-of a project's ``CMakeLists.txt`` files.
-
-------------------------------------------------------------------------------
-
-::
-
- 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, ``FILES_MATCHING``, ``PATTERN``, ``REGEX``, and
-``EXCLUDE`` options. Copying directories preserves the structure
-of their content even if options are used to select a subset of
-files.
-
-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).
-
-------------------------------------------------------------------------------
-
-::
+.. code-block:: cmake
file(LOCK <path> [DIRECTORY] [RELEASE]
[GUARD <FUNCTION|FILE|PROCESS>]
diff --git a/Help/command/find_file.rst b/Help/command/find_file.rst
index e56097bea..2a14ad72f 100644
--- a/Help/command/find_file.rst
+++ b/Help/command/find_file.rst
@@ -8,6 +8,9 @@ find_file
.. |prefix_XXX_SUBDIR| replace:: ``<prefix>/include``
.. |entry_XXX_SUBDIR| replace:: ``<entry>/include``
+.. |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX| replace::
+ ``<prefix>/include/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE`
+ is set, and |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX_SUBDIR|
.. |CMAKE_PREFIX_PATH_XXX| replace::
``<prefix>/include/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE`
is set, and |CMAKE_PREFIX_PATH_XXX_SUBDIR|
diff --git a/Help/command/find_library.rst b/Help/command/find_library.rst
index f774f17ec..0861d6789 100644
--- a/Help/command/find_library.rst
+++ b/Help/command/find_library.rst
@@ -8,6 +8,9 @@ find_library
.. |prefix_XXX_SUBDIR| replace:: ``<prefix>/lib``
.. |entry_XXX_SUBDIR| replace:: ``<entry>/lib``
+.. |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX| replace::
+ ``<prefix>/lib/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE` is set,
+ and |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX_SUBDIR|
.. |CMAKE_PREFIX_PATH_XXX| replace::
``<prefix>/lib/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE` is set,
and |CMAKE_PREFIX_PATH_XXX_SUBDIR|
diff --git a/Help/command/find_package.rst b/Help/command/find_package.rst
index 83f471619..e5e5b2cf6 100644
--- a/Help/command/find_package.rst
+++ b/Help/command/find_package.rst
@@ -1,23 +1,31 @@
find_package
------------
-Load settings for an external project.
+.. only:: html
-::
+ .. contents::
- find_package(<package> [version] [EXACT] [QUIET] [MODULE]
+Find an external project, and load its settings.
+
+.. _`basic signature`:
+
+Basic Signature and Module Mode
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: cmake
+
+ find_package(<PackageName> [version] [EXACT] [QUIET] [MODULE]
[REQUIRED] [[COMPONENTS] [components...]]
[OPTIONAL_COMPONENTS components...]
[NO_POLICY_SCOPE])
-Finds and loads settings from an external project. ``<package>_FOUND``
+Finds and loads settings from an external project. ``<PackageName>_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.
+``QUIET`` option disables informational messages, including those indicating
+that the package cannot be found if it is not ``REQUIRED``. 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).
@@ -33,28 +41,45 @@ should be compatible (format is ``major[.minor[.patch[.tweak]]]``). The
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).
+package-by-package basis (see the `Version Selection`_ section below).
+
+See the :command:`cmake_policy` command documentation for discussion
+of the ``NO_POLICY_SCOPE`` option.
-User code should generally look for packages using the above simple
-signature. The remainder of this command documentation specifies the
+The command has two modes by which it searches for packages: "Module"
+mode and "Config" mode. The above signature selects Module mode.
+If no module is found the command falls back to Config mode, described
+below. This fall back is disabled if the ``MODULE`` option is given.
+
+In Module mode, CMake searches for a file called ``Find<PackageName>.cmake``.
+The file is first searched in the :variable:`CMAKE_MODULE_PATH`,
+then among the :ref:`Find Modules` provided 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. Some find-modules provide limited or no support for versioning;
+check the module documentation.
+
+If the ``MODULE`` option is not specfied in the above signature,
+CMake first searches for the package using Module mode. Then, if the
+package is not found, it searches again using Config mode. A user
+may set the variable :variable:`CMAKE_FIND_PACKAGE_PREFER_CONFIG` to
+``TRUE`` to direct CMake first search using Config mode before falling
+back to Module mode.
+
+Full Signature and Config Mode
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+User code should generally look for packages using the above `basic
+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]
+The complete Config mode command signature is
+
+.. code-block:: cmake
+
+ find_package(<PackageName> [version] [EXACT] [QUIET]
[REQUIRED] [[COMPONENTS] [components...]]
[CONFIG|NO_MODULE]
[NO_POLICY_SCOPE]
@@ -64,6 +89,7 @@ The complete Config mode command signature is::
[PATHS path1 [path2 ... ]]
[PATH_SUFFIXES suffix1 [suffix2 ...]]
[NO_DEFAULT_PATH]
+ [NO_PACKAGE_ROOT_PATH]
[NO_CMAKE_PATH]
[NO_CMAKE_ENVIRONMENT_PATH]
[NO_SYSTEM_ENVIRONMENT_PATH]
@@ -75,37 +101,44 @@ The complete Config mode command signature is::
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.
+The ``CONFIG`` option, the synonymous ``NO_MODULE`` option, or the use
+of options not specified in the `basic signature`_ all enforce pure Config
+mode. In pure Config mode, the command skips Module mode search and
+proceeds at once with Config mode search.
-Config mode attempts to locate a configuration file provided by the
-package to be found. A cache entry called ``<package>_DIR`` is created to
+Config mode search attempts to locate a configuration file provided by the
+package to be found. A cache entry called ``<PackageName>_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
+searches for a package with the name ``<PackageName>``. If the ``NAMES`` option
+is given the names following it are used instead of ``<PackageName>``.
+The command searches for a file called ``<PackageName>Config.cmake`` or
+``<lower-case-package-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``.
+is stored in the cmake variable ``<PackageName>_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``.
+version are stored in the cmake variable ``<PackageName>_CONSIDERED_CONFIGS``,
+the associated versions in ``<PackageName>_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
+``<PackageName>_DIR`` has been set to a directory not containing a
configuration file CMake will ignore it and search from scratch.
+Package maintainers providing CMake package configuration files are
+encouraged to name and install them such that the `Search Procedure`_
+outlined below will find them without requiring use of additional options.
+
+Version Selection
+^^^^^^^^^^^^^^^^^
+
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``
@@ -126,7 +159,7 @@ version file is loaded in a nested scope in which the following
variables have been defined:
``PACKAGE_FIND_NAME``
- the ``<package>`` name
+ the ``<PackageName>``
``PACKAGE_FIND_VERSION``
full requested version string
``PACKAGE_FIND_VERSION_MAJOR``
@@ -154,20 +187,20 @@ sets these variables:
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
+are not available after the ``find_package`` call returns. If the version
is acceptable the following variables are set:
-``<package>_VERSION``
+``<PackageName>_VERSION``
full provided version string
-``<package>_VERSION_MAJOR``
+``<PackageName>_VERSION_MAJOR``
major version if provided, else 0
-``<package>_VERSION_MINOR``
+``<PackageName>_VERSION_MINOR``
minor version if provided, else 0
-``<package>_VERSION_PATCH``
+``<PackageName>_VERSION_PATCH``
patch version if provided, else 0
-``<package>_VERSION_TWEAK``
+``<PackageName>_VERSION_TWEAK``
tweak version if provided, else 0
-``<package>_VERSION_COUNT``
+``<PackageName>_VERSION_COUNT``
number of version components, 0 to 4
and the corresponding package configuration file is loaded.
@@ -176,47 +209,40 @@ claim compatibility with the version requested it is unspecified which
one is chosen: unless the variable :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER`
is set no attempt is made to choose a highest or closest version number.
-To control the order in which ``find_package`` checks for compatibiliy use
+To control the order in which ``find_package`` checks for compatibility use
the two variables :variable:`CMAKE_FIND_PACKAGE_SORT_ORDER` and
:variable:`CMAKE_FIND_PACKAGE_SORT_DIRECTION`.
-For instance in order to select the highest version one can set::
+For instance in order to select the highest version one can set
+
+.. code-block:: cmake
SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
before calling ``find_package``.
-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.
+Search Procedure
+^^^^^^^^^^^^^^^^
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::
+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)
- <prefix>/<name>*/(lib/<arch>|lib|share)/cmake/<name>*/ (W/U)
- <prefix>/<name>*/(lib/<arch>|lib|share)/<name>*/ (W/U)
- <prefix>/<name>*/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/ (W/U)
-
-On systems supporting OS X Frameworks and Application Bundles the
-following directories are searched for frameworks or bundles
+ <prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/ (U)
+ <prefix>/(lib/<arch>|lib*|share)/<name>*/ (U)
+ <prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (U)
+ <prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/ (W/U)
+ <prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/ (W/U)
+ <prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (W/U)
+
+On systems supporting macOS :prop_tgt:`FRAMEWORK` and :prop_tgt:`BUNDLE`, the
+following directories are searched for Frameworks or Application Bundles
containing a configuration file::
<prefix>/<name>.framework/Resources/ (A)
@@ -227,20 +253,32 @@ containing a configuration file::
<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``).
+to any of the names specified (``<PackageName>`` 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.
+:variable:`CMAKE_LIBRARY_ARCHITECTURE` variable is set. ``lib*`` includes one
+or more of the values ``lib64``, ``lib32``, ``libx32`` or ``lib`` (searched in
+that order).
+
+* Paths with ``lib64`` are searched on 64 bit platforms if the
+ :prop_gbl:`FIND_LIBRARY_USE_LIB64_PATHS` property is set to ``TRUE``.
+* Paths with ``lib32`` are searched on 32 bit platforms if the
+ :prop_gbl:`FIND_LIBRARY_USE_LIB32_PATHS` property is set to ``TRUE``.
+* Paths with ``libx32`` are searched on platforms using the x32 ABI
+ if the :prop_gbl:`FIND_LIBRARY_USE_LIBX32_PATHS` property is set to ``TRUE``.
+* The ``lib`` path is always searched.
+
+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
+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
+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
+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
:variable:`CMAKE_FIND_FRAMEWORK` and :variable:`CMAKE_FIND_APPBUNDLE`
variables determine the order of preference.
@@ -249,46 +287,55 @@ 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
+1. Search paths specified in the :variable:`<PackageName>_ROOT` CMake
+ variable and the :envvar:`<PackageName>_ROOT` environment variable,
+ where ``<PackageName>`` is the package to be found.
+ The package root variables are maintained as a stack so if
+ called from within a find module, root paths from the parent's find
+ module will also be searched after paths for the current package.
+ This can be skipped if ``NO_PACKAGE_ROOT_PATH`` is passed.
+ See policy :policy:`CMP0074`.
+
+2. Search paths specified in cmake-specific cache variables. These
are intended to be used on the command line with a ``-DVAR=value``.
- The values are interpreted as :ref:`;-lists <CMake Language Lists>`.
+ The values are interpreted as :ref:`semicolon-separated lists <CMake Language Lists>`.
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.
+3. Search paths specified in cmake-specific environment variables.
These are intended to be set in the user's shell configuration,
and therefore use the host's native path separator
(``;`` on Windows and ``:`` on UNIX).
This can be skipped if ``NO_CMAKE_ENVIRONMENT_PATH`` is passed::
- <package>_DIR
+ <PackageName>_DIR
CMAKE_PREFIX_PATH
CMAKE_FRAMEWORK_PATH
CMAKE_APPBUNDLE_PATH
-3. Search paths specified by the ``HINTS`` option. These should be paths
+4. 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
+5. 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 paths stored in the CMake :ref:`User Package Registry`.
+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.
-6. Search cmake variables defined in the Platform files for the
+7. Search cmake variables defined in the Platform files for the
current system. This can be skipped if ``NO_CMAKE_SYSTEM_PATH`` is
passed::
@@ -296,54 +343,62 @@ enabled.
CMAKE_SYSTEM_FRAMEWORK_PATH
CMAKE_SYSTEM_APPBUNDLE_PATH
-7. Search paths stored in the CMake :ref:`System Package Registry`.
+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.
-8. Search paths specified by the ``PATHS`` option. These are typically
+9. Search paths specified by the ``PATHS`` option. These are typically
hard-coded guesses.
.. |FIND_XXX| replace:: find_package
-.. |FIND_ARGS_XXX| replace:: <package>
+.. |FIND_ARGS_XXX| replace:: <PackageName>
.. |CMAKE_FIND_ROOT_PATH_MODE_XXX| replace::
:variable:`CMAKE_FIND_ROOT_PATH_MODE_PACKAGE`
.. include:: FIND_XXX_ROOT.txt
.. include:: FIND_XXX_ORDER.txt
+By default the value stored in the result variable will be the path at
+which the file is found. The :variable:`CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS`
+variable may be set to ``TRUE`` before calling ``find_package`` in order
+to resolve symbolic links and store the real path to the file.
+
Every non-REQUIRED ``find_package`` call can be disabled by setting the
:variable:`CMAKE_DISABLE_FIND_PACKAGE_<PackageName>` variable to ``TRUE``.
+Package File Interface Variables
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
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):
``CMAKE_FIND_PACKAGE_NAME``
- the ``<package>`` name which is searched for
-``<package>_FIND_REQUIRED``
+ the ``<PackageName>`` which is searched for
+``<PackageName>_FIND_REQUIRED``
true if ``REQUIRED`` option was given
-``<package>_FIND_QUIETLY``
+``<PackageName>_FIND_QUIETLY``
true if ``QUIET`` option was given
-``<package>_FIND_VERSION``
+``<PackageName>_FIND_VERSION``
full requested version string
-``<package>_FIND_VERSION_MAJOR``
+``<PackageName>_FIND_VERSION_MAJOR``
major version if requested, else 0
-``<package>_FIND_VERSION_MINOR``
+``<PackageName>_FIND_VERSION_MINOR``
minor version if requested, else 0
-``<package>_FIND_VERSION_PATCH``
+``<PackageName>_FIND_VERSION_PATCH``
patch version if requested, else 0
-``<package>_FIND_VERSION_TWEAK``
+``<PackageName>_FIND_VERSION_TWEAK``
tweak version if requested, else 0
-``<package>_FIND_VERSION_COUNT``
+``<PackageName>_FIND_VERSION_COUNT``
number of version components, 0 to 4
-``<package>_FIND_VERSION_EXACT``
+``<PackageName>_FIND_VERSION_EXACT``
true if ``EXACT`` option was given
-``<package>_FIND_COMPONENTS``
+``<PackageName>_FIND_COMPONENTS``
list of requested components
-``<package>_FIND_REQUIRED_<c>``
+``<PackageName>_FIND_REQUIRED_<c>``
true if component ``<c>`` is required,
false if component ``<c>`` is optional
@@ -353,8 +408,5 @@ 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
+``<PackageName>_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
index 76342d020..988a3fae4 100644
--- a/Help/command/find_path.rst
+++ b/Help/command/find_path.rst
@@ -8,6 +8,9 @@ find_path
.. |prefix_XXX_SUBDIR| replace:: ``<prefix>/include``
.. |entry_XXX_SUBDIR| replace:: ``<entry>/include``
+.. |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX| replace::
+ ``<prefix>/include/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE`
+ is set, and |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX_SUBDIR|
.. |CMAKE_PREFIX_PATH_XXX| replace::
``<prefix>/include/<arch>`` if :variable:`CMAKE_LIBRARY_ARCHITECTURE`
is set, and |CMAKE_PREFIX_PATH_XXX_SUBDIR|
diff --git a/Help/command/find_program.rst b/Help/command/find_program.rst
index d3430c054..4f00773b3 100644
--- a/Help/command/find_program.rst
+++ b/Help/command/find_program.rst
@@ -8,6 +8,8 @@ find_program
.. |prefix_XXX_SUBDIR| replace:: ``<prefix>/[s]bin``
.. |entry_XXX_SUBDIR| replace:: ``<entry>/[s]bin``
+.. |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX| replace::
+ |FIND_PACKAGE_ROOT_PREFIX_PATH_XXX_SUBDIR|
.. |CMAKE_PREFIX_PATH_XXX| replace::
|CMAKE_PREFIX_PATH_XXX_SUBDIR|
.. |CMAKE_XXX_PATH| replace:: :variable:`CMAKE_PROGRAM_PATH`
diff --git a/Help/command/fltk_wrap_ui.rst b/Help/command/fltk_wrap_ui.rst
index 041e5a7e3..66752729d 100644
--- a/Help/command/fltk_wrap_ui.rst
+++ b/Help/command/fltk_wrap_ui.rst
@@ -3,7 +3,7 @@ fltk_wrap_ui
Create FLTK user interfaces Wrappers.
-::
+.. code-block:: cmake
fltk_wrap_ui(resultingLibraryName source1
source2 ... sourceN )
diff --git a/Help/command/foreach.rst b/Help/command/foreach.rst
index c0f3679d9..ae2afb290 100644
--- a/Help/command/foreach.rst
+++ b/Help/command/foreach.rst
@@ -3,45 +3,82 @@ foreach
Evaluate a group of commands for each value in a list.
-::
+.. code-block:: cmake
- foreach(loop_var arg1 arg2 ...)
- COMMAND1(ARGS ...)
- COMMAND2(ARGS ...)
- ...
- endforeach(loop_var)
+ foreach(<loop_var> <items>)
+ <commands>
+ endforeach()
-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.
+where ``<items>`` is a list of items that are separated by
+semicolon or whitespace.
+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 item in ``<items>``.
+At the beginning of each iteration the variable ``loop_var`` will be set
+to the value of the current item.
-::
+The commands :command:`break` and :command:`continue` provide means to
+escape from the normal control flow.
- foreach(loop_var RANGE total)
- foreach(loop_var RANGE start stop [step])
+Per legacy, the :command:`endforeach` command admits
+an optional ``<loop_var>`` argument.
+If used, it must be a verbatim
+repeat of the argument of the opening
+``foreach`` command.
-Foreach can also iterate over a generated range of numbers. There are
-three types of this iteration:
+.. code-block:: cmake
-* When specifying single number, the range will have elements 0 to
- "total".
+ foreach(<loop_var> RANGE <stop>)
-* When specifying two numbers, the range will have elements from the
- first number to the second number.
+In this variant, ``foreach`` iterates over the numbers
+0, 1, ... up to (and including) the nonnegative integer ``<stop>``.
-* The third optional number is the increment used to iterate from the
- first number to the second number.
+.. code-block:: cmake
-::
+ foreach(<loop_var> RANGE <start> <stop> [<step>])
+
+In this variant, ``foreach`` iterates over the numbers from
+``<start>`` up to at most ``<stop>`` in steps of ``<step>``.
+If ``<step>`` is not specified, then the step size is 1.
+The three arguments ``<start>`` ``<stop>`` ``<step>`` must
+all be nonnegative integers, and ``<stop>`` must not be
+smaller than ``<start>``; otherwise you enter the danger zone
+of undocumented behavior that may change in future releases.
+
+.. code-block:: cmake
+
+ foreach(loop_var IN [LISTS [<lists>]] [ITEMS [<items>]])
- foreach(loop_var IN [LISTS [list1 [...]]]
- [ITEMS [item1 [...]]])
+In this variant, ``<lists>`` is a whitespace or semicolon
+separated list of list-valued variables. The ``foreach``
+command iterates over each item in each given list.
+The ``<items>`` following the ``ITEMS`` keyword are processed
+as in the first variant of the ``foreach`` command.
+The forms ``LISTS A`` and ``ITEMS ${A}`` are
+equivalent.
+
+The following example shows how the ``LISTS`` option is
+processed:
+
+.. code-block:: cmake
+
+ set(A 0;1)
+ set(B 2 3)
+ set(C "4 5")
+ set(D 6;7 8)
+ set(E "")
+ foreach(X IN LISTS A B C D E)
+ message(STATUS "X=${X}")
+ endforeach()
+
+yields
+::
-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.
+ -- X=0
+ -- X=1
+ -- X=2
+ -- X=3
+ -- X=4 5
+ -- X=6
+ -- X=7
+ -- X=8
diff --git a/Help/command/function.rst b/Help/command/function.rst
index 7ffdfee65..53ba75481 100644
--- a/Help/command/function.rst
+++ b/Help/command/function.rst
@@ -1,36 +1,70 @@
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
-:command:`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
-``ARGC`` variable 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.
-Referencing to ``ARGV#`` arguments beyond ``ARGC`` have undefined
-behavior. Checking that ``ARGC`` is greater than ``#`` is the only way
-to ensure that ``ARGV#`` was passed to the function as an extra
-argument.
+Start recording a function for later invocation as a command.
+
+.. code-block:: cmake
+
+ function(<name> [<arg1> ...])
+ <commands>
+ endfunction()
+
+Defines a function named ``<name>`` that takes arguments named
+``<arg1>``, ... The ``<commands>`` in the function definition
+are recorded; they are not executed until the function is invoked.
+
+Per legacy, the :command:`endfunction` command admits an optional
+``<name>`` argument. If used, it must be a verbatim repeat of the
+argument of the opening ``function`` command.
A function opens a new scope: see :command:`set(var PARENT_SCOPE)` for
details.
See the :command:`cmake_policy()` command documentation for the behavior
of policies inside functions.
+
+See the :command:`macro()` command documentation for differences
+between CMake functions and macros.
+
+Invocation
+^^^^^^^^^^
+
+The function invocation is case-insensitive. A function defined as
+
+.. code-block:: cmake
+
+ function(foo)
+ <commands>
+ endfunction()
+
+can be invoked through any of
+
+.. code-block:: cmake
+
+ foo()
+ Foo()
+ FOO()
+
+and so on. However, it is strongly recommended to stay with the
+case chosen in the function definition. Typically functions use
+all-lowercase names.
+
+Arguments
+^^^^^^^^^
+
+When the function is invoked, the recorded ``<commands>`` 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
+``ARGC`` variable 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.
+
+Furthermore, ``ARGV`` holds the list of all arguments given to the
+function and ``ARGN`` holds the list of arguments past the last expected
+argument. Referencing to ``ARGV#`` arguments beyond ``ARGC`` have
+undefined behavior. Checking that ``ARGC`` is greater than ``#`` is
+the only way to ensure that ``ARGV#`` was passed to the function as an
+extra argument.
diff --git a/Help/command/get_cmake_property.rst b/Help/command/get_cmake_property.rst
index 497ab4eeb..96764a3b9 100644
--- a/Help/command/get_cmake_property.rst
+++ b/Help/command/get_cmake_property.rst
@@ -3,14 +3,14 @@ get_cmake_property
Get a global property of the CMake instance.
-::
+.. code-block:: cmake
- get_cmake_property(VAR property)
+ get_cmake_property(<var> <property>)
-Get a global 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". See the :manual:`cmake-properties(7)` manual
-for available properties.
+Gets a global 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``.
+See the :manual:`cmake-properties(7)` manual for available properties.
See also the :command:`get_property` command ``GLOBAL`` option.
diff --git a/Help/command/get_directory_property.rst b/Help/command/get_directory_property.rst
index e50abe0e9..218efa9d3 100644
--- a/Help/command/get_directory_property.rst
+++ b/Help/command/get_directory_property.rst
@@ -3,17 +3,22 @@ get_directory_property
Get a property of ``DIRECTORY`` scope.
-::
+.. code-block:: cmake
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.
+Stores a property of directory scope in the named ``<variable>``.
+The ``DIRECTORY`` argument specifies another directory from which
+to retrieve the property value instead of the current directory.
+The specified directory must have already been traversed by CMake.
-::
+If the property is not defined for the nominated directory scope,
+an empty string is returned. In the case of ``INHERITED`` properties,
+if the property is not found for the nominated directory scope,
+the search will chain to a parent scope as described for the
+:command:`define_property` command.
+
+.. code-block:: cmake
get_directory_property(<variable> [DIRECTORY <dir>]
DEFINITION <var-name>)
diff --git a/Help/command/get_filename_component.rst b/Help/command/get_filename_component.rst
index 14c8cf279..9bbf87714 100644
--- a/Help/command/get_filename_component.rst
+++ b/Help/command/get_filename_component.rst
@@ -3,13 +3,11 @@ get_filename_component
Get a specific component of a full filename.
-------------------------------------------------------------------------------
+.. code-block:: cmake
-::
-
- get_filename_component(<VAR> <FileName> <COMP> [CACHE])
+ get_filename_component(<var> <FileName> <mode> [CACHE])
-Set ``<VAR>`` to a component of ``<FileName>``, where ``<COMP>`` is one of:
+Sets ``<var>`` to a component of ``<FileName>``, where ``<mode>`` is one of:
::
@@ -17,22 +15,19 @@ Set ``<VAR>`` to a component of ``<FileName>``, where ``<COMP>`` is one of:
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
+ LAST_EXT = File name last extension (.c from d/a.b.c)
+ NAME_WLE = File name without directory or last extension
PATH = Legacy alias for DIRECTORY (use for CMake <= 2.8.11)
Paths are returned with forward slashes and have no trailing slashes.
-The longest file extension is always considered. If the optional
-``CACHE`` argument is specified, the result variable is added to the
-cache.
+If the optional ``CACHE`` argument is specified, the result variable is
+added to the cache.
-------------------------------------------------------------------------------
+.. code-block:: cmake
-::
+ get_filename_component(<var> <FileName> <mode> [BASE_DIR <dir>] [CACHE])
- get_filename_component(<VAR> <FileName>
- <COMP> [BASE_DIR <BASE_DIR>]
- [CACHE])
-
-Set ``<VAR>`` to the absolute path of ``<FileName>``, where ``<COMP>`` is one
+Sets ``<var>`` to the absolute path of ``<FileName>``, where ``<mode>`` is one
of:
::
@@ -41,24 +36,20 @@ of:
REALPATH = Full path to existing file with symlinks resolved
If the provided ``<FileName>`` is a relative path, it is evaluated relative
-to the given base directory ``<BASE_DIR>``. If no base directory is
+to the given base directory ``<dir>``. If no base directory is
provided, the default base directory will be
:variable:`CMAKE_CURRENT_SOURCE_DIR`.
-Paths are returned with forward slashes and have no trailing slahes. If the
+Paths are returned with forward slashes and have no trailing slashes. If the
optional ``CACHE`` argument is specified, the result variable is added to the
cache.
-------------------------------------------------------------------------------
-
-::
+.. code-block:: cmake
- get_filename_component(<VAR> <FileName>
- PROGRAM [PROGRAM_ARGS <ARG_VAR>]
- [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
+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
index 632ece65c..c0f9b460a 100644
--- a/Help/command/get_property.rst
+++ b/Help/command/get_property.rst
@@ -3,32 +3,33 @@ get_property
Get a property.
-::
+.. code-block:: cmake
get_property(<variable>
<GLOBAL |
- DIRECTORY [dir] |
+ DIRECTORY [<dir>] |
TARGET <target> |
SOURCE <source> |
INSTALL <file> |
TEST <test> |
CACHE <entry> |
- VARIABLE>
+ 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:
+Gets 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.
+ directory (already processed by CMake) may be named by the
+ full or relative path ``<dir>``.
``TARGET``
Scope must name one existing target.
@@ -50,11 +51,15 @@ be one of the following:
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
+returned, although some properties support inheriting from a parent scope
+if defined to behave that way (see :command:`define_property`).
+
+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 the
:command:`define_property` command.
+
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
diff --git a/Help/command/get_source_file_property.rst b/Help/command/get_source_file_property.rst
index 3e975c2f9..decec1916 100644
--- a/Help/command/get_source_file_property.rst
+++ b/Help/command/get_source_file_property.rst
@@ -3,14 +3,20 @@ get_source_file_property
Get a property for a source file.
-::
+.. code-block:: cmake
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 :command:`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 :prop_sf:`LOCATION`
+Gets a property from a source file. The value of the property is
+stored in the variable ``VAR``. If the source property is not found, the
+behavior depends on whether it has been defined to be an ``INHERITED`` property
+or not (see :command:`define_property`). Non-inherited properties will set
+``VAR`` to "NOTFOUND", whereas inherited properties will search the relevant
+parent scope as described for the :command:`define_property` command and
+if still unable to find the property, ``VAR`` will be set to an empty string.
+
+Use :command:`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 :prop_sf:`LOCATION`.
See also the more general :command:`get_property` command.
diff --git a/Help/command/get_target_property.rst b/Help/command/get_target_property.rst
index 2a72c3af7..11e07eabe 100644
--- a/Help/command/get_target_property.rst
+++ b/Help/command/get_target_property.rst
@@ -3,16 +3,25 @@ get_target_property
Get a property from a target.
-::
+.. code-block:: cmake
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 :command:`set_target_properties` to set property values.
+the variable ``VAR``. If the target property is not found, the behavior
+depends on whether it has been defined to be an ``INHERITED`` property
+or not (see :command:`define_property`). Non-inherited properties will
+set ``VAR`` to ``NOTFOUND``, whereas inherited properties will search the
+relevant parent scope as described for the :command:`define_property`
+command and if still unable to find the property, ``VAR`` will be set to
+an empty string.
+
+Use :command:`set_target_properties` to set target 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 :command:`get_property` command.
+
+See :ref:`Target Properties` for the list of properties known to CMake.
diff --git a/Help/command/get_test_property.rst b/Help/command/get_test_property.rst
index e359f4b3d..e02b9bc77 100644
--- a/Help/command/get_test_property.rst
+++ b/Help/command/get_test_property.rst
@@ -3,13 +3,19 @@ get_test_property
Get a property of the test.
-::
+.. code-block:: cmake
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 test or property is not found, ``VAR`` will
-be set to "NOTFOUND". For a list of standard properties you can type
-``cmake --help-property-list``.
+the variable ``VAR``. If the test property is not found, the behavior
+depends on whether it has been defined to be an ``INHERITED`` property
+or not (see :command:`define_property`). Non-inherited properties will
+set ``VAR`` to "NOTFOUND", whereas inherited properties will search the
+relevant parent scope as described for the :command:`define_property`
+command and if still unable to find the property, ``VAR`` will be set to
+an empty string.
+
+For a list of standard properties you can type ``cmake --help-property-list``.
See also the more general :command:`get_property` command.
diff --git a/Help/command/if.rst b/Help/command/if.rst
index edd343de2..d8e3a45da 100644
--- a/Help/command/if.rst
+++ b/Help/command/if.rst
@@ -3,41 +3,49 @@ if
Conditionally execute a group of commands.
+Synopsis
+^^^^^^^^
+
.. 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``, ``LESS_EQUAL, ``GREATER``, ``GREATER_EQUAL``,
+ if(<condition>)
+ <commands>
+ elseif(<condition>) # optional block, can be repeated
+ <commands>
+ else() # optional block
+ <commands>
+ endif()
+
+Evaluates the ``condition`` argument of the ``if`` clause according to the
+`Condition syntax`_ described below. If the result is true, then the
+``commands`` in the ``if`` block are executed.
+Otherwise, optional ``elseif`` blocks are processed in the same way.
+Finally, if no ``condition`` is true, ``commands`` in the optional ``else``
+block are executed.
+
+Per legacy, the :command:`else` and :command:`endif` commands admit
+an optional ``<condition>`` argument.
+If used, it must be a verbatim
+repeat of the argument of the opening
+``if`` command.
+
+Condition Syntax
+^^^^^^^^^^^^^^^^
+
+The following syntax applies to the ``condition`` argument of
+the ``if``, ``elseif`` and :command:`while` clauses.
+
+Compound conditions are evaluated in the following order of precedence:
+Innermost parentheses are evaluated first. Next come unary tests such
+as ``EXISTS``, ``COMMAND``, and ``DEFINED``. Then binary tests such as
+``EQUAL``, ``LESS``, ``LESS_EQUAL``, ``GREATER``, ``GREATER_EQUAL``,
``STREQUAL``, ``STRLESS``, ``STRLESS_EQUAL``, ``STRGREATER``,
``STRGREATER_EQUAL``, ``VERSION_EQUAL``, ``VERSION_LESS``,
``VERSION_LESS_EQUAL``, ``VERSION_GREATER``, ``VERSION_GREATER_EQUAL``,
-and ``MATCHES`` will be evaluated. Then boolean ``NOT`` operators and
-finally boolean ``AND`` and then ``OR`` operators will be evaluated.
+and ``MATCHES``. Then the boolean operators in the order ``NOT``, ``AND``,
+and finally ``OR``.
-Possible expressions are:
+Possible conditions are:
``if(<constant>)``
True if the constant is ``1``, ``ON``, ``YES``, ``TRUE``, ``Y``,
@@ -52,14 +60,14 @@ Possible expressions are:
True if given a variable that 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(NOT <condition>)``
+ True if the condition is not true.
-``if(<expr1> AND <expr2>)``
- True if both expressions would be considered true individually.
+``if(<cond1> AND <cond2>)``
+ True if both conditions would be considered true individually.
-``if(<expr1> OR <expr2>)``
- True if either expression would be considered true individually.
+``if(<cond1> OR <cond2>)``
+ True if either condition would be considered true individually.
``if(COMMAND command-name)``
True if the given name is a command, macro or function that can be
@@ -80,7 +88,9 @@ Possible expressions are:
``if(EXISTS path-to-file-or-directory)``
True if the named file or directory exists. Behavior is well-defined
- only for full paths.
+ only for full paths. Resolves symbolic links, i.e. if the named file or
+ directory is a symbolic link, returns true if the target of the
+ symbolic link exists.
``if(file1 IS_NEWER_THAN file2)``
True if ``file1`` is newer than ``file2`` or if one of the two files doesn't
@@ -103,7 +113,7 @@ Possible expressions are:
``if(<variable|string> MATCHES regex)``
True if the given string or variable's value matches the given regular
- expression. See :ref:`Regex Specification` for regex format.
+ condition. See :ref:`Regex Specification` for regex format.
``()`` groups are captured in :variable:`CMAKE_MATCH_<n>` variables.
``if(<variable|string> LESS <variable|string>)``
@@ -148,63 +158,82 @@ Possible expressions are:
``if(<variable|string> VERSION_LESS <variable|string>)``
Component-wise integer version number comparison (version format is
- ``major[.minor[.patch[.tweak]]]``).
+ ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero).
+ Any non-integer version component or non-integer trailing part of a version
+ component effectively truncates the string at that point.
``if(<variable|string> VERSION_GREATER <variable|string>)``
Component-wise integer version number comparison (version format is
- ``major[.minor[.patch[.tweak]]]``).
+ ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero).
+ Any non-integer version component or non-integer trailing part of a version
+ component effectively truncates the string at that point.
``if(<variable|string> VERSION_EQUAL <variable|string>)``
Component-wise integer version number comparison (version format is
- ``major[.minor[.patch[.tweak]]]``).
+ ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero).
+ Any non-integer version component or non-integer trailing part of a version
+ component effectively truncates the string at that point.
``if(<variable|string> VERSION_LESS_EQUAL <variable|string>)``
Component-wise integer version number comparison (version format is
- ``major[.minor[.patch[.tweak]]]``).
+ ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero).
+ Any non-integer version component or non-integer trailing part of a version
+ component effectively truncates the string at that point.
``if(<variable|string> VERSION_GREATER_EQUAL <variable|string>)``
Component-wise integer version number comparison (version format is
- ``major[.minor[.patch[.tweak]]]``).
+ ``major[.minor[.patch[.tweak]]]``, omitted components are treated as zero).
+ Any non-integer version component or non-integer trailing part of a version
+ component effectively truncates the string at that point.
``if(<variable|string> IN_LIST <variable>)``
True if the given element is contained in the named list variable.
-``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(DEFINED <name>|CACHE{<name>}|ENV{<name>})``
+ True if a variable, cache variable or environment variable
+ with given ``<name>`` is defined. The value of the variable
+ does not matter. Note that 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.
+``if((condition) AND (condition OR (condition)))``
+ The conditions inside the parenthesis are evaluated first and then
+ the remaining condition 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.
+ of evaluating the condition that contains them.
+
+Variable Expansion
+^^^^^^^^^^^^^^^^^^
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::
+command even receives the arguments. Therefore code like
+
+.. code-block:: cmake
set(var1 OFF)
set(var2 "var1")
if(${var2})
-appears to the if command as::
+appears to the if command as
- if(var1)
+.. code-block:: cmake
+
+ 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::
+``${}`` from the example then the command sees
- if(var2)
+.. code-block:: cmake
-which is true because ``var2`` is defined to "var1" which is not a false
+ 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>``:
+above-documented condition syntax 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
@@ -242,3 +271,8 @@ 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`.
+
+There is no automatic evaluation for environment or cache
+:ref:`Variable References`. Their values must be referenced as
+``$ENV{<name>}`` or ``$CACHE{<name>}`` wherever the above-documented
+condition syntax accepts ``<variable|string>``.
diff --git a/Help/command/include.rst b/Help/command/include.rst
index eeca4c6e3..80968da7b 100644
--- a/Help/command/include.rst
+++ b/Help/command/include.rst
@@ -3,16 +3,16 @@ include
Load and run CMake code from a file or module.
-::
+.. code-block:: cmake
- include(<file|module> [OPTIONAL] [RESULT_VARIABLE <VAR>]
+ include(<file|module> [OPTIONAL] [RESULT_VARIABLE <var>]
[NO_POLICY_SCOPE])
-Load and run CMake code from the file given. Variable reads and
+Loads and runs 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.
+``RESULT_VARIABLE`` is given the variable ``<var>`` 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 :variable:`CMAKE_MODULE_PATH`,
diff --git a/Help/command/include_directories.rst b/Help/command/include_directories.rst
index f69493460..fe281c3c8 100644
--- a/Help/command/include_directories.rst
+++ b/Help/command/include_directories.rst
@@ -3,7 +3,7 @@ include_directories
Add include directories to the build.
-::
+.. code-block:: cmake
include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])
@@ -33,3 +33,9 @@ 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.
+
+.. note::
+
+ Prefer the :command:`target_include_directories` command to add include
+ directories to individual targets and optionally propagate/export them
+ to dependents.
diff --git a/Help/command/include_external_msproject.rst b/Help/command/include_external_msproject.rst
index 335282a30..540a13af8 100644
--- a/Help/command/include_external_msproject.rst
+++ b/Help/command/include_external_msproject.rst
@@ -3,7 +3,7 @@ include_external_msproject
Include an external Microsoft project file in a workspace.
-::
+.. code-block:: cmake
include_external_msproject(projectname location
[TYPE projectTypeGUID]
@@ -13,11 +13,11 @@ Include an external Microsoft project file in a workspace.
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 :command:`add_dependencies`
+named ``[projectname]``. This can be used in the :command:`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
+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).
diff --git a/Help/command/include_regular_expression.rst b/Help/command/include_regular_expression.rst
index ab5a56325..dde837892 100644
--- a/Help/command/include_regular_expression.rst
+++ b/Help/command/include_regular_expression.rst
@@ -3,11 +3,11 @@ include_regular_expression
Set the regular expression used for dependency checking.
-::
+.. code-block:: cmake
include_regular_expression(regex_match [regex_complain])
-Set the regular expressions used in dependency checking. Only files
+Sets 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:
diff --git a/Help/command/install.rst b/Help/command/install.rst
index 58438b763..ab6fef664 100644
--- a/Help/command/install.rst
+++ b/Help/command/install.rst
@@ -1,11 +1,19 @@
install
-------
-.. only:: html
+Specify rules to run at install time.
- .. contents::
+Synopsis
+^^^^^^^^
-Specify rules to run at install time.
+.. parsed-literal::
+
+ install(`TARGETS`_ <target>... [...])
+ install({`FILES`_ | `PROGRAMS`_} <file>... [...])
+ install(`DIRECTORY`_ <dir>... [...])
+ install(`SCRIPT`_ <file> [...])
+ install(`CODE`_ <code> [...])
+ install(`EXPORT`_ <export-name> [...])
Introduction
^^^^^^^^^^^^
@@ -38,7 +46,21 @@ signatures that specify them. The common options are:
``CONFIGURATIONS``
Specify a list of build configurations for which the install rule
- applies (Debug, Release, etc.).
+ applies (Debug, Release, etc.). Note that the values specified for
+ this option only apply to options listed AFTER the ``CONFIGURATIONS``
+ option. For example, to set separate install paths for the Debug and
+ Release configurations, do the following:
+
+ .. code-block:: cmake
+
+ install(TARGETS target
+ CONFIGURATIONS Debug
+ RUNTIME DESTINATION Debug/bin)
+ install(TARGETS target
+ CONFIGURATIONS Release
+ RUNTIME DESTINATION Release/bin)
+
+ Note that ``CONFIGURATIONS`` appears BEFORE ``RUNTIME DESTINATION``.
``COMPONENT``
Specify an installation component name with which the install rule
@@ -67,10 +89,20 @@ Command signatures that install files may print messages during
installation. Use the :variable:`CMAKE_INSTALL_MESSAGE` variable
to control which messages are printed.
+Many of the ``install()`` variants implicitly create the directories
+containing the installed files. If
+:variable:`CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS` is set, these
+directories will be created with the permissions specified. Otherwise,
+they will be created according to the uname rules on Unix-like platforms.
+Windows platforms are unaffected.
+
Installing Targets
^^^^^^^^^^^^^^^^^^
-::
+.. _`install(TARGETS)`:
+.. _TARGETS:
+
+.. code-block:: cmake
install(TARGETS targets... [EXPORT <export-name>]
[[ARCHIVE|LIBRARY|RUNTIME|OBJECTS|FRAMEWORK|BUNDLE|
@@ -79,6 +111,7 @@ Installing Targets
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>]
+ [NAMELINK_COMPONENT <component>]
[OPTIONAL] [EXCLUDE_FROM_ALL]
[NAMELINK_ONLY|NAMELINK_SKIP]
] [...]
@@ -86,63 +119,192 @@ Installing Targets
)
The ``TARGETS`` form specifies rules for installing targets from a
-project. There are six kinds of target files that may be installed:
-``ARCHIVE``, ``LIBRARY``, ``RUNTIME``, ``OBJECTS``, ``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 treated as ``ARCHIVE`` targets,
-except that those marked with the ``FRAMEWORK`` property are treated
-as ``FRAMEWORK`` targets on OS X.
-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. Object
-libraries are always treated as ``OBJECTS`` targets.
-The ``ARCHIVE``, ``LIBRARY``, ``RUNTIME``, ``OBJECTS``, 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 ``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.
-
-The ``INCLUDES DESTINATION`` specifies a list of directories
-which will be added to the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
-target property of the ``<targets>`` when exported by the
-:command:`install(EXPORT)` command. If a relative path is
-specified, it is treated as relative to the ``$<INSTALL_PREFIX>``.
-This is independent of the rest of the argument groups and does
-not actually install anything.
+project. There are several kinds of target files that may be installed:
+
+``ARCHIVE``
+ Static libraries are treated as ``ARCHIVE`` targets, except those
+ marked with the ``FRAMEWORK`` property on macOS (see ``FRAMEWORK``
+ below.) For DLL platforms (all Windows-based systems including
+ Cygwin), the DLL import library is treated as an ``ARCHIVE`` target.
+
+``LIBRARY``
+ Module libraries are always treated as ``LIBRARY`` targets. For non-
+ DLL platforms shared libraries are treated as ``LIBRARY`` targets,
+ except those marked with the ``FRAMEWORK`` property on macOS (see
+ ``FRAMEWORK`` below.)
+
+``RUNTIME``
+ Executables are treated as ``RUNTIME`` objects, except those marked
+ with the ``MACOSX_BUNDLE`` property on macOS (see ``BUNDLE`` below.)
+ For DLL platforms (all Windows-based systems including Cygwin), the
+ DLL part of a shared library is treated as a ``RUNTIME`` target.
+
+``OBJECTS``
+ Object libraries (a simple group of object files) are always treated
+ as ``OBJECTS`` targets.
+
+``FRAMEWORK``
+ Both static and shared libraries marked with the ``FRAMEWORK``
+ property are treated as ``FRAMEWORK`` targets on macOS.
+
+``BUNDLE``
+ Executables marked with the :prop_tgt:`MACOSX_BUNDLE` property are treated as
+ ``BUNDLE`` targets on macOS.
+
+``PUBLIC_HEADER``
+ Any :prop_tgt:`PUBLIC_HEADER` files associated with a library are installed in
+ the destination specified by the ``PUBLIC_HEADER`` argument on non-Apple
+ platforms. Rules defined by this argument are ignored for :prop_tgt:`FRAMEWORK`
+ libraries on Apple platforms because the associated files are installed
+ into the appropriate locations inside the framework folder. See
+ :prop_tgt:`PUBLIC_HEADER` for details.
+
+``PRIVATE_HEADER``
+ Similar to ``PUBLIC_HEADER``, but for ``PRIVATE_HEADER`` files. See
+ :prop_tgt:`PRIVATE_HEADER` for details.
+
+``RESOURCE``
+ Similar to ``PUBLIC_HEADER`` and ``PRIVATE_HEADER``, but for
+ ``RESOURCE`` files. See :prop_tgt:`RESOURCE` for details.
+
+For each of these arguments given, the arguments following them only apply
+to the target or file type specified in the argument. 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.)
+
+For regular executables, static libraries and shared libraries, the
+``DESTINATION`` argument is not required. For these target types, when
+``DESTINATION`` is omitted, a default destination will be taken from the
+appropriate variable from :module:`GNUInstallDirs`, or set to a built-in
+default value if that variable is not defined. The same is true for the
+public and private headers associated with the installed targets through the
+:prop_tgt:`PUBLIC_HEADER` and :prop_tgt:`PRIVATE_HEADER` target properties.
+A destination must always be provided for module libraries, Apple bundles and
+frameworks. A destination can be omitted for interface and object libraries,
+but they are handled differently (see the discussion of this topic toward the
+end of this section).
+
+The following table shows the target types with their associated variables and
+built-in defaults that apply when no destination is given:
+
+================== =============================== ======================
+ Target Type GNUInstallDirs Variable Built-In Default
+================== =============================== ======================
+``RUNTIME`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
+``LIBRARY`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
+``ARCHIVE`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
+``PRIVATE_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
+``PUBLIC_HEADER`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
+================== =============================== ======================
+
+Projects wishing to follow the common practice of installing headers into a
+project-specific subdirectory will need to provide a destination rather than
+rely on the above.
+
+To make packages compliant with distribution filesystem layout policies, if
+projects must specify a ``DESTINATION``, it is recommended that they use a
+path that begins with the appropriate :module:`GNUInstallDirs` variable.
+This allows package maintainers to control the install destination by setting
+the appropriate cache variables. The following example shows a static library
+being installed to the default destination provided by
+:module:`GNUInstallDirs`, but with its headers installed to a project-specific
+subdirectory that follows the above recommendation:
+
+.. code-block:: cmake
+
+ add_library(mylib STATIC ...)
+ set_target_properties(mylib PROPERTIES PUBLIC_HEADER mylib.h)
+ include(GNUInstallDirs)
+ install(TARGETS mylib
+ PUBLIC_HEADER
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/myproj
+ )
+
+In addition to the common options listed above, each target can accept
+the following additional arguments:
+
+``NAMELINK_COMPONENT``
+ 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_COMPONENT`` option is similar to the
+ ``COMPONENT`` option, but it changes the installation component of a shared
+ library namelink if one is generated. If not specified, this defaults to the
+ value of ``COMPONENT``. It is an error to use this parameter outside of a
+ ``LIBRARY`` block.
+
+ Consider the following example:
+
+ .. code-block:: cmake
+
+ install(TARGETS mylib
+ LIBRARY
+ COMPONENT Libraries
+ NAMELINK_COMPONENT Development
+ PUBLIC_HEADER
+ COMPONENT Development
+ )
+
+ In this scenario, if you choose to install only the ``Development``
+ component, both the headers and namelink will be installed without the
+ library. (If you don't also install the ``Libraries`` component, the
+ namelink will be a dangling symlink, and projects that link to the library
+ will have build errors.) If you install only the ``Libraries`` component,
+ only the library will be installed, without the headers and namelink.
+
+ This option is typically used for package managers that have separate
+ runtime and development packages. For example, on Debian systems, the
+ library is expected to be in the runtime package, and the headers and
+ namelink are expected to be in the development package.
+
+ See the :prop_tgt:`VERSION` and :prop_tgt:`SOVERSION` target properties for
+ details on creating versioned shared libraries.
+
+``NAMELINK_ONLY``
+ This option causes the installation of only the namelink when a library
+ target is installed. On platforms where versioned shared libraries do not
+ have namelinks or when a library is not versioned, the ``NAMELINK_ONLY``
+ option installs nothing. It is an error to use this parameter outside of a
+ ``LIBRARY`` block.
+
+ When ``NAMELINK_ONLY`` is given, either ``NAMELINK_COMPONENT`` or
+ ``COMPONENT`` may be used to specify the installation component of the
+ namelink, but ``COMPONENT`` should generally be preferred.
+
+``NAMELINK_SKIP``
+ Similar to ``NAMELINK_ONLY``, but it has the opposite effect: it causes the
+ installation of library files other than the namelink when a library target
+ is installed. When neither ``NAMELINK_ONLY`` or ``NAMELINK_SKIP`` are given,
+ both portions are installed. On platforms where versioned shared libraries
+ do not have symlinks or when a library is not versioned, ``NAMELINK_SKIP``
+ installs the library. It is an error to use this parameter outside of a
+ ``LIBRARY`` block.
+
+ If ``NAMELINK_SKIP`` is specified, ``NAMELINK_COMPONENT`` has no effect. It
+ is not recommended to use ``NAMELINK_SKIP`` in conjunction with
+ ``NAMELINK_COMPONENT``.
+
+The `install(TARGETS)`_ command can also accept the following options at the
+top level:
+
+``EXPORT``
+ This option associates the installed target files with an export called
+ ``<export-name>``. It must appear before any target options. To actually
+ install the export file itself, call `install(EXPORT)`_, documented below.
+ See documentation of the :prop_tgt:`EXPORT_NAME` target property to change
+ the name of the exported target.
+
+``INCLUDES DESTINATION``
+ This option 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 `install(EXPORT)`_ command. If a
+ relative path is specified, it is treated as relative to the
+ ``$<INSTALL_PREFIX>``.
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
@@ -164,24 +326,40 @@ 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``, ``ARCHIVE``, or ``OBJECTS`` options. To actually install the
-export file itself, call ``install(EXPORT)``, documented below.
+:ref:`Interface Libraries` may be listed among the targets to install.
+They install no artifacts but will be included in an associated ``EXPORT``.
+If :ref:`Object Libraries` are listed but given no destination for their
+object files, they will be exported as :ref:`Interface Libraries`.
+This is sufficient to satisfy transitive usage requirements of other
+targets that link to the object libraries in their implementation.
Installing a target with the :prop_tgt:`EXCLUDE_FROM_ALL` target property
set to ``TRUE`` has undefined behavior.
-The install destination given to the target install ``DESTINATION`` may
+`install(TARGETS)`_ can install targets that were created in
+other directories. When using such cross-directory install rules, running
+``make install`` (or similar) from a subdirectory will not guarantee that
+targets from other directories are up-to-date. You can use
+:command:`target_link_libraries` or :command:`add_dependencies`
+to ensure that such out-of-directory targets are built before the
+subdirectory-specific install rules are run.
+
+An install destination given as a ``DESTINATION`` argument may
use "generator expressions" with the syntax ``$<...>``. See the
:manual:`cmake-generator-expressions(7)` manual for available expressions.
Installing Files
^^^^^^^^^^^^^^^^
-::
+.. _`install(FILES)`:
+.. _`install(PROGRAMS)`:
+.. _FILES:
+.. _PROGRAMS:
+
+.. code-block:: cmake
- install(<FILES|PROGRAMS> files... DESTINATION <dir>
+ install(<FILES|PROGRAMS> files...
+ TYPE <type> | DESTINATION <dir>
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[COMPONENT <component>]
@@ -205,16 +383,71 @@ The list of ``files...`` given to ``FILES`` or ``PROGRAMS`` may use
However, if any item begins in a generator expression it must evaluate
to a full path.
-The install destination given to the files install ``DESTINATION`` may
+Either a ``TYPE`` or a ``DESTINATION`` must be provided, but not both.
+A ``TYPE`` argument specifies the generic file type of the files being
+installed. A destination will then be set automatically by taking the
+corresponding variable from :module:`GNUInstallDirs`, or by using a
+built-in default if that variable is not defined. See the table below for
+the supported file types and their corresponding variables and built-in
+defaults. Projects can provide a ``DESTINATION`` argument instead of a
+file type if they wish to explicitly define the install destination.
+
+======================= ================================== =========================
+ ``TYPE`` Argument GNUInstallDirs Variable Built-In Default
+======================= ================================== =========================
+``BIN`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
+``SBIN`` ``${CMAKE_INSTALL_SBINDIR}`` ``sbin``
+``LIB`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
+``INCLUDE`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
+``SYSCONF`` ``${CMAKE_INSTALL_SYSCONFDIR}`` ``etc``
+``SHAREDSTATE`` ``${CMAKE_INSTALL_SHARESTATEDIR}`` ``com``
+``LOCALSTATE`` ``${CMAKE_INSTALL_LOCALSTATEDIR}`` ``var``
+``RUNSTATE`` ``${CMAKE_INSTALL_RUNSTATEDIR}`` ``<LOCALSTATE dir>/run``
+``DATA`` ``${CMAKE_INSTALL_DATADIR}`` ``<DATAROOT dir>``
+``INFO`` ``${CMAKE_INSTALL_INFODIR}`` ``<DATAROOT dir>/info``
+``LOCALE`` ``${CMAKE_INSTALL_LOCALEDIR}`` ``<DATAROOT dir>/locale``
+``MAN`` ``${CMAKE_INSTALL_MANDIR}`` ``<DATAROOT dir>/man``
+``DOC`` ``${CMAKE_INSTALL_DOCDIR}`` ``<DATAROOT dir>/doc``
+======================= ================================== =========================
+
+Projects wishing to follow the common practice of installing headers into a
+project-specific subdirectory will need to provide a destination rather than
+rely on the above.
+
+Note that some of the types' built-in defaults use the ``DATAROOT`` directory as
+a prefix. The ``DATAROOT`` prefix is calculated similarly to the types, with
+``CMAKE_INSTALL_DATAROOTDIR`` as the variable and ``share`` as the built-in
+default. You cannot use ``DATAROOT`` as a ``TYPE`` parameter; please use
+``DATA`` instead.
+
+To make packages compliant with distribution filesystem layout policies, if
+projects must specify a ``DESTINATION``, it is recommended that they use a
+path that begins with the appropriate :module:`GNUInstallDirs` variable.
+This allows package maintainers to control the install destination by setting
+the appropriate cache variables. The following example shows how to follow
+this advice while installing headers to a project-specific subdirectory:
+
+.. code-block:: cmake
+
+ include(GNUInstallDirs)
+ install(FILES mylib.h
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/myproj
+ )
+
+An install destination given as a ``DESTINATION`` argument may
use "generator expressions" with the syntax ``$<...>``. See the
:manual:`cmake-generator-expressions(7)` manual for available expressions.
Installing Directories
^^^^^^^^^^^^^^^^^^^^^^
-::
+.. _`install(DIRECTORY)`:
+.. _DIRECTORY:
+
+.. code-block:: cmake
- install(DIRECTORY dirs... DESTINATION <dir>
+ install(DIRECTORY dirs...
+ TYPE <type> | DESTINATION <dir>
[FILE_PERMISSIONS permissions...]
[DIRECTORY_PERMISSIONS permissions...]
[USE_SOURCE_PERMISSIONS] [OPTIONAL] [MESSAGE_NEVER]
@@ -285,15 +518,60 @@ will install the ``icons`` directory to ``share/myproj/icons`` and the
file permissions, the scripts will be given specific permissions, and any
``CVS`` directories will be excluded.
-The list of ``dirs...`` given to ``DIRECTORY`` and the install destination
-given to the directory install ``DESTINATION`` may use "generator expressions"
+Either a ``TYPE`` or a ``DESTINATION`` must be provided, but not both.
+A ``TYPE`` argument specifies the generic file type of the files within the
+listed directories being installed. A destination will then be set
+automatically by taking the corresponding variable from
+:module:`GNUInstallDirs`, or by using a built-in default if that variable
+is not defined. See the table below for the supported file types and their
+corresponding variables and built-in defaults. Projects can provide a
+``DESTINATION`` argument instead of a file type if they wish to explicitly
+define the install destination.
+
+======================= ================================== =========================
+ ``TYPE`` Argument GNUInstallDirs Variable Built-In Default
+======================= ================================== =========================
+``BIN`` ``${CMAKE_INSTALL_BINDIR}`` ``bin``
+``SBIN`` ``${CMAKE_INSTALL_SBINDIR}`` ``sbin``
+``LIB`` ``${CMAKE_INSTALL_LIBDIR}`` ``lib``
+``INCLUDE`` ``${CMAKE_INSTALL_INCLUDEDIR}`` ``include``
+``SYSCONF`` ``${CMAKE_INSTALL_SYSCONFDIR}`` ``etc``
+``SHAREDSTATE`` ``${CMAKE_INSTALL_SHARESTATEDIR}`` ``com``
+``LOCALSTATE`` ``${CMAKE_INSTALL_LOCALSTATEDIR}`` ``var``
+``RUNSTATE`` ``${CMAKE_INSTALL_RUNSTATEDIR}`` ``<LOCALSTATE dir>/run``
+``DATA`` ``${CMAKE_INSTALL_DATADIR}`` ``<DATAROOT dir>``
+``INFO`` ``${CMAKE_INSTALL_INFODIR}`` ``<DATAROOT dir>/info``
+``LOCALE`` ``${CMAKE_INSTALL_LOCALEDIR}`` ``<DATAROOT dir>/locale``
+``MAN`` ``${CMAKE_INSTALL_MANDIR}`` ``<DATAROOT dir>/man``
+``DOC`` ``${CMAKE_INSTALL_DOCDIR}`` ``<DATAROOT dir>/doc``
+======================= ================================== =========================
+
+Note that some of the types' built-in defaults use the ``DATAROOT`` directory as
+a prefix. The ``DATAROOT`` prefix is calculated similarly to the types, with
+``CMAKE_INSTALL_DATAROOTDIR`` as the variable and ``share`` as the built-in
+default. You cannot use ``DATAROOT`` as a ``TYPE`` parameter; please use
+``DATA`` instead.
+
+To make packages compliant with distribution filesystem layout policies, if
+projects must specify a ``DESTINATION``, it is recommended that they use a
+path that begins with the appropriate :module:`GNUInstallDirs` variable.
+This allows package maintainers to control the install destination by setting
+the appropriate cache variables.
+
+The list of ``dirs...`` given to ``DIRECTORY`` and an install destination
+given as a ``DESTINATION`` argument may use "generator expressions"
with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
manual for available expressions.
Custom Installation Logic
^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. _`install(CODE)`:
+.. _`install(SCRIPT)`:
+.. _CODE:
+.. _SCRIPT:
+
+.. code-block:: cmake
install([[SCRIPT <file>] [CODE <code>]]
[COMPONENT <component>] [EXCLUDE_FROM_ALL] [...])
@@ -311,24 +589,32 @@ example, the code
will print a message during installation.
+``<file>`` or ``<code>`` may use "generator expressions" with the syntax
+``$<...>`` (in the case of ``<file>``, this refers to their use in the file
+name, not the file's contents). See the
+:manual:`cmake-generator-expressions(7)` manual for available expressions.
+
Installing Exports
^^^^^^^^^^^^^^^^^^
-::
+.. _`install(EXPORT)`:
+.. _EXPORT:
+
+.. code-block:: cmake
install(EXPORT <export-name> DESTINATION <dir>
[NAMESPACE <namespace>] [[FILE <name>.cmake]|
- [EXPORT_ANDROID_MK <name>.mk]]
[PERMISSIONS permissions...]
[CONFIGURATIONS [Debug|Release|...]]
[EXPORT_LINK_INTERFACE_LIBRARIES]
[COMPONENT <component>]
[EXCLUDE_FROM_ALL])
+ install(EXPORT_ANDROID_MK <export-name> DESTINATION <dir> [...])
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
+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``
@@ -340,14 +626,28 @@ 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.
-
-In additon to cmake language files, the ``EXPORT_ANDROID_MK`` option maybe
-used to specifiy an export to the android ndk build system. The Android
+policy :policy:`CMP0022` is ``NEW``.
+
+When a ``COMPONENT`` option is given, the listed ``<component>`` implicitly
+depends on all components mentioned in the export set. The exported
+``<name>.cmake`` file will require each of the exported components to be
+present in order for dependent projects to build properly. For example, a
+project may define components ``Runtime`` and ``Development``, with shared
+libraries going into the ``Runtime`` component and static libraries and
+headers going into the ``Development`` component. The export set would also
+typically be part of the ``Development`` component, but it would export
+targets from both the ``Runtime`` and ``Development`` components. Therefore,
+the ``Runtime`` component would need to be installed if the ``Development``
+component was installed, but not vice versa. If the ``Development`` component
+was installed without the ``Runtime`` component, dependent projects that try
+to link against it would have build errors. Package managers, such as APT and
+RPM, typically handle this by listing the ``Runtime`` component as a dependency
+of the ``Development`` component in the package metadata, ensuring that the
+library is always installed if the headers and CMake export file are present.
+
+In addition to cmake language files, the ``EXPORT_ANDROID_MK`` mode maybe
+used to specify an export to the android ndk build system. This mode
+accepts the same options as the normal export mode. The Android
NDK supports the use of prebuilt libraries, both static and shared. This
allows cmake to build the libraries of a project and make them available
to an ndk build system complete with transitive dependencies, include flags
@@ -360,11 +660,11 @@ and installed by the current project. For example, the code
install(TARGETS myexe EXPORT myproj DESTINATION bin)
install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)
- install(EXPORT_ANDROID_MK myexp DESTINATION share/ndk-modules)
+ install(EXPORT_ANDROID_MK myproj DESTINATION share/ndk-modules)
-will install the executable myexe to ``<prefix>/bin`` and code to import
+will install the executable ``myexe`` to ``<prefix>/bin`` and code to import
it in the file ``<prefix>/lib/myproj/myproj.cmake`` and
-``<prefix>/lib/share/ndk-modules/Android.mk``. An outside project
+``<prefix>/share/ndk-modules/Android.mk``. 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.
@@ -378,3 +678,26 @@ executable from the installation tree using the imported target name
those generated by :command:`install_targets`,
:command:`install_files`, and :command:`install_programs` commands
is not defined.
+
+Generated Installation Script
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The ``install()`` command generates a file, ``cmake_install.cmake``, inside
+the build directory, which is used internally by the generated install target
+and by CPack. You can also invoke this script manually with ``cmake -P``. This
+script accepts several variables:
+
+``COMPONENT``
+ Set this variable to install only a single CPack component as opposed to all
+ of them. For example, if you only want to install the ``Development``
+ component, run ``cmake -DCOMPONENT=Development -P cmake_install.cmake``.
+
+``BUILD_TYPE``
+ Set this variable to change the build type if you are using a multi-config
+ generator. For example, to install with the ``Debug`` configuration, run
+ ``cmake -DBUILD_TYPE=Debug -P cmake_install.cmake``.
+
+``DESTDIR``
+ This is an environment variable rather than a CMake variable. It allows you
+ to change the installation prefix on UNIX systems. See :envvar:`DESTDIR` for
+ details.
diff --git a/Help/command/install_files.rst b/Help/command/install_files.rst
index 1850be6e1..ff074a8a7 100644
--- a/Help/command/install_files.rst
+++ b/Help/command/install_files.rst
@@ -1,7 +1,9 @@
install_files
-------------
-Deprecated. Use the :command:`install(FILES)` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`install(FILES)` command instead.
This command has been superceded by the :command:`install` command. It is
provided for compatibility with older CMake code. The ``FILES`` form is
@@ -19,7 +21,7 @@ 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'.
+A typical extension is ``.h``.
::
diff --git a/Help/command/install_programs.rst b/Help/command/install_programs.rst
index 79aa486a3..fab64820d 100644
--- a/Help/command/install_programs.rst
+++ b/Help/command/install_programs.rst
@@ -1,7 +1,9 @@
install_programs
----------------
-Deprecated. Use the :command:`install(PROGRAMS)` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`install(PROGRAMS)` command instead.
This command has been superceded by the :command:`install` command. It is
provided for compatibility with older CMake code. The ``FILES`` form is
diff --git a/Help/command/install_targets.rst b/Help/command/install_targets.rst
index 49ca69694..c9efdce67 100644
--- a/Help/command/install_targets.rst
+++ b/Help/command/install_targets.rst
@@ -1,7 +1,9 @@
install_targets
---------------
-Deprecated. Use the :command:`install(TARGETS)` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`install(TARGETS)` command instead.
This command has been superceded by the :command:`install` command. It is
provided for compatibility with older CMake code.
diff --git a/Help/command/link_directories.rst b/Help/command/link_directories.rst
index 5c64bc609..9cb8faa74 100644
--- a/Help/command/link_directories.rst
+++ b/Help/command/link_directories.rst
@@ -1,19 +1,51 @@
link_directories
----------------
-Specify directories in which the linker will look for libraries.
+Add directories in which the linker will look for libraries.
-::
+.. code-block:: cmake
- link_directories(directory1 directory2 ...)
+ link_directories([AFTER|BEFORE] 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.
+Adds the paths in which the linker should search for libraries.
Relative paths given to this command are interpreted as relative to
the current source directory, see :policy:`CMP0015`.
-Note that this command is rarely necessary. Library locations
-returned by :command:`find_package` and :command:`find_library` are
-absolute paths. Pass these absolute library file paths directly to the
-:command:`target_link_libraries` command. CMake will ensure the linker finds
-them.
+The directories are added to the :prop_dir:`LINK_DIRECTORIES` directory
+property for the current ``CMakeLists.txt`` file, converting relative
+paths to absolute as needed.
+The command will apply only to targets created after it is called.
+
+By default the directories specified are appended onto the current list of
+directories. This default behavior can be changed by setting
+:variable:`CMAKE_LINK_DIRECTORIES_BEFORE` to ``ON``. By using
+``AFTER`` or ``BEFORE`` explicitly, you can select between appending and
+prepending, independent of the default.
+
+Arguments to ``link_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.
+
+.. note::
+
+ This command is rarely necessary and should be avoided where there are
+ other choices. Prefer to pass full absolute paths to libraries where
+ possible, since this ensures the correct library will always be linked.
+ The :command:`find_library` command provides the full path, which can
+ generally be used directly in calls to :command:`target_link_libraries`.
+ Situations where a library search path may be needed include:
+
+ - Project generators like Xcode where the user can switch target
+ architecture at build time, but a full path to a library cannot
+ be used because it only provides one architecture (i.e. it is not
+ a universal binary).
+ - Libraries may themselves have other private library dependencies
+ that expect to be found via ``RPATH`` mechanisms, but some linkers
+ are not able to fully decode those paths (e.g. due to the presence
+ of things like ``$ORIGIN``).
+
+ If a library search path must be provided, prefer to localize the effect
+ where possible by using the :command:`target_link_directories` command
+ rather than ``link_directories()``. The target-specific command can also
+ control how the search directories propagate to other dependent targets.
diff --git a/Help/command/link_libraries.rst b/Help/command/link_libraries.rst
index fd5dc3723..8665cb789 100644
--- a/Help/command/link_libraries.rst
+++ b/Help/command/link_libraries.rst
@@ -3,7 +3,7 @@ link_libraries
Link libraries to all targets added later.
-::
+.. code-block:: cmake
link_libraries([item1 [item2 [...]]]
[[debug|optimized|general] <item>] ...)
diff --git a/Help/command/list.rst b/Help/command/list.rst
index f6b75bc19..39e7e2a69 100644
--- a/Help/command/list.rst
+++ b/Help/command/list.rst
@@ -3,66 +3,323 @@ list
List operations.
-::
+Synopsis
+^^^^^^^^
+
+.. parsed-literal::
+
+ `Reading`_
+ list(`LENGTH`_ <list> <out-var>)
+ list(`GET`_ <list> <element index> [<index> ...] <out-var>)
+ list(`JOIN`_ <list> <glue> <out-var>)
+ list(`SUBLIST`_ <list> <begin> <length> <out-var>)
+
+ `Search`_
+ list(`FIND`_ <list> <value> <out-var>)
+
+ `Modification`_
+ list(`APPEND`_ <list> [<element>...])
+ list(`FILTER`_ <list> {INCLUDE | EXCLUDE} REGEX <regex>)
+ list(`INSERT`_ <list> <index> [<element>...])
+ list(`POP_BACK`_ <list> [<out-var>...])
+ list(`POP_FRONT`_ <list> [<out-var>...])
+ list(`PREPEND`_ <list> [<element>...])
+ list(`REMOVE_ITEM`_ <list> <value>...)
+ list(`REMOVE_AT`_ <list> <index>...)
+ list(`REMOVE_DUPLICATES`_ <list>)
+ list(`TRANSFORM`_ <list> <ACTION> [...])
+
+ `Ordering`_
+ list(`REVERSE`_ <list>)
+ list(`SORT`_ <list> [...])
+
+Introduction
+^^^^^^^^^^^^
+
+The list subcommands ``APPEND``, ``INSERT``, ``FILTER``, ``PREPEND``,
+``POP_BACK``, ``POP_FRONT``, ``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 :command:`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
+:command:`set` with ``PARENT_SCOPE``, :command:`set` with
+``CACHE INTERNAL``, or some other means of value propagation.
+
+.. note::
+
+ 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.)
+
+.. note::
+
+ 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.
+
+Reading
+^^^^^^^
+
+.. _LENGTH:
+
+.. code-block:: cmake
list(LENGTH <list> <output variable>)
- list(GET <list> <element index> [<element index> ...]
- <output variable>)
+
+Returns the list's length.
+
+.. _GET:
+
+.. code-block:: cmake
+
+ list(GET <list> <element index> [<element index> ...] <output variable>)
+
+Returns the list of elements specified by indices from the list.
+
+.. _JOIN:
+
+.. code-block:: cmake
+
+ list(JOIN <list> <glue> <output variable>)
+
+Returns a string joining all list's elements using the glue string.
+To join multiple strings, which are not part of a list, use ``JOIN`` operator
+from :command:`string` command.
+
+.. _SUBLIST:
+
+.. code-block:: cmake
+
+ list(SUBLIST <list> <begin> <length> <output variable>)
+
+Returns a sublist of the given list.
+If ``<length>`` is 0, an empty list will be returned.
+If ``<length>`` is -1 or the list is smaller than ``<begin>+<length>`` then
+the remaining elements of the list starting at ``<begin>`` will be returned.
+
+Search
+^^^^^^
+
+.. _FIND:
+
+.. code-block:: cmake
+
+ list(FIND <list> <value> <output variable>)
+
+Returns the index of the element specified in the list or -1
+if it wasn't found.
+
+Modification
+^^^^^^^^^^^^
+
+.. _APPEND:
+
+.. code-block:: cmake
+
list(APPEND <list> [<element> ...])
+
+Appends elements to the list.
+
+.. _FILTER:
+
+.. code-block:: cmake
+
list(FILTER <list> <INCLUDE|EXCLUDE> REGEX <regular_expression>)
- list(FIND <list> <value> <output variable>)
+
+Includes or removes items from the list that match the mode's pattern.
+In ``REGEX`` mode, items will be matched against the given regular expression.
+
+For more information on regular expressions see also the
+:command:`string` command.
+
+.. _INSERT:
+
+.. code-block:: cmake
+
list(INSERT <list> <element_index> <element> [<element> ...])
+
+Inserts elements to the list to the specified location.
+
+.. _POP_BACK:
+
+.. code-block:: cmake
+
+ list(POP_BACK <list> [<out-var>...])
+
+If no variable name is given, removes exactly one element. Otherwise,
+assign the last element's value to the given variable and removes it,
+up to the last variable name given.
+
+.. _POP_FRONT:
+
+.. code-block:: cmake
+
+ list(POP_FRONT <list> [<out-var>...])
+
+If no variable name is given, removes exactly one element. Otherwise,
+assign the first element's value to the given variable and removes it,
+up to the last variable name given.
+
+.. _PREPEND:
+
+.. code-block:: cmake
+
+ list(PREPEND <list> [<element> ...])
+
+Insert elements to the 0th position in the list.
+
+.. _REMOVE_ITEM:
+
+.. code-block:: cmake
+
list(REMOVE_ITEM <list> <value> [<value> ...])
+
+Removes the given items from the list.
+
+.. _REMOVE_AT:
+
+.. code-block:: cmake
+
list(REMOVE_AT <list> <index> [<index> ...])
+
+Removes items at given indices from the list.
+
+.. _REMOVE_DUPLICATES:
+
+.. code-block:: cmake
+
list(REMOVE_DUPLICATES <list>)
- list(REVERSE <list>)
- list(SORT <list>)
-``LENGTH`` will return a given list's length.
+Removes duplicated items in the list. The relative order of items is preserved,
+but if duplicates are encountered, only the first instance is preserved.
-``GET`` will return list of elements specified by indices from the list.
+.. _TRANSFORM:
-``APPEND`` will append elements to the list.
+.. code-block:: cmake
-``FILTER`` will include or remove items from the list that match the
-mode's pattern.
-In ``REGEX`` mode, items will be matched against the given regular expression.
-For more information on regular expressions see also the :command:`string`
-command.
+ list(TRANSFORM <list> <ACTION> [<SELECTOR>]
+ [OUTPUT_VARIABLE <output variable>])
-``FIND`` will return the index of the element specified in the list or -1
-if it wasn't found.
+Transforms the list by applying an action to all or, by specifying a
+``<SELECTOR>``, to the selected elements of the list, storing the result
+in-place or in the specified output variable.
-``INSERT`` will insert elements to the list to the specified location.
+.. note::
-``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.
+ The ``TRANSFORM`` sub-command does not change the number of elements in the
+ list. If a ``<SELECTOR>`` is specified, only some elements will be changed,
+ the other ones will remain the same as before the transformation.
-``REMOVE_DUPLICATES`` will remove duplicated items in the list.
+``<ACTION>`` specifies the action to apply to the elements of the list.
+The actions have exactly the same semantics as sub-commands of the
+:command:`string` command. ``<ACTION>`` must be one of the following:
-``REVERSE`` reverses the contents of the list in-place.
+``APPEND``, ``PREPEND``: Append, prepend specified value to each element of
+the list.
-``SORT`` sorts the list in-place alphabetically.
+ .. code-block:: cmake
-The list subcommands ``APPEND``, ``INSERT``, ``FILTER``, ``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
-:command:`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
-:command:`set` with ``PARENT_SCOPE``, :command:`set` with
-``CACHE INTERNAL``, or some other means of value propagation.
+ list(TRANSFORM <list> <APPEND|PREPEND> <value> ...)
+
+``TOUPPER``, ``TOLOWER``: Convert each element of the list to upper, lower
+characters.
+
+ .. code-block:: cmake
+
+ list(TRANSFORM <list> <TOLOWER|TOUPPER> ...)
+
+``STRIP``: Remove leading and trailing spaces from each element of the
+list.
+
+ .. code-block:: cmake
+
+ list(TRANSFORM <list> STRIP ...)
+
+``GENEX_STRIP``: Strip any
+:manual:`generator expressions <cmake-generator-expressions(7)>` from each
+element of the list.
+
+ .. code-block:: cmake
+
+ list(TRANSFORM <list> GENEX_STRIP ...)
+
+``REPLACE``: Match the regular expression as many times as possible and
+substitute the replacement expression for the match for each element
+of the list
+(Same semantic as ``REGEX REPLACE`` from :command:`string` command).
+
+ .. code-block:: cmake
+
+ list(TRANSFORM <list> REPLACE <regular_expression>
+ <replace_expression> ...)
+
+``<SELECTOR>`` determines which elements of the list will be transformed.
+Only one type of selector can be specified at a time. When given,
+``<SELECTOR>`` must be one of the following:
+
+``AT``: Specify a list of indexes.
+
+ .. code-block:: cmake
+
+ list(TRANSFORM <list> <ACTION> AT <index> [<index> ...] ...)
+
+``FOR``: Specify a range with, optionally, an increment used to iterate over
+the range.
+
+ .. code-block:: cmake
+
+ list(TRANSFORM <list> <ACTION> FOR <start> <stop> [<step>] ...)
+
+``REGEX``: Specify a regular expression. Only elements matching the regular
+expression will be transformed.
+
+ .. code-block:: cmake
+
+ list(TRANSFORM <list> <ACTION> REGEX <regular_expression> ...)
+
+
+Ordering
+^^^^^^^^
+
+.. _REVERSE:
+
+.. code-block:: cmake
+
+ list(REVERSE <list>)
+
+Reverses the contents of the list in-place.
+
+.. _SORT:
+
+.. code-block:: cmake
+
+ list(SORT <list> [COMPARE <compare>] [CASE <case>] [ORDER <order>])
+
+Sorts the list in-place alphabetically.
+Use the ``COMPARE`` keyword to select the comparison method for sorting.
+The ``<compare>`` option should be one of:
+
+* ``STRING``: Sorts a list of strings alphabetically. This is the
+ default behavior if the ``COMPARE`` option is not given.
+* ``FILE_BASENAME``: Sorts a list of pathnames of files by their basenames.
+
+Use the ``CASE`` keyword to select a case sensitive or case insensitive
+sort mode. The ``<case>`` option should be one of:
+
+* ``SENSITIVE``: List items are sorted in a case-sensitive manner. This is
+ the default behavior if the ``CASE`` option is not given.
+* ``INSENSITIVE``: List items are sorted case insensitively. The order of
+ items which differ only by upper/lowercase is not specified.
+
+To control the sort order, the ``ORDER`` keyword can be given.
+The ``<order>`` option should be one of:
-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.
+* ``ASCENDING``: Sorts the list in ascending order. This is the default
+ behavior when the ``ORDER`` option is not given.
+* ``DESCENDING``: Sorts the list in descending order.
diff --git a/Help/command/load_cache.rst b/Help/command/load_cache.rst
index f1134472d..33625c463 100644
--- a/Help/command/load_cache.rst
+++ b/Help/command/load_cache.rst
@@ -3,21 +3,20 @@ load_cache
Load in the values from another project's CMake cache.
-::
+.. code-block:: cmake
- load_cache(pathToCacheFile READ_WITH_PREFIX
- prefix entry1...)
+ load_cache(pathToCacheFile READ_WITH_PREFIX prefix entry1...)
-Read the cache and store the requested entries in variables with their
+Reads 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.
-::
+.. code-block:: cmake
load_cache(pathToCacheFile [EXCLUDE entry1...]
[INCLUDE_INTERNALS entry1...])
-Load in the values from another cache and store them in the local
+Loads 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.
diff --git a/Help/command/load_command.rst b/Help/command/load_command.rst
index a1576e8b5..dc235994c 100644
--- a/Help/command/load_command.rst
+++ b/Help/command/load_command.rst
@@ -1,7 +1,7 @@
load_command
------------
-Disallowed. See CMake Policy :policy:`CMP0031`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0031`.
Load a command into a running CMake.
diff --git a/Help/command/macro.rst b/Help/command/macro.rst
index 6bee69c73..05e5d79ac 100644
--- a/Help/command/macro.rst
+++ b/Help/command/macro.rst
@@ -1,27 +1,66 @@
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
-:command:`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.
+Start recording a macro for later invocation as a command
+
+.. code-block:: cmake
+
+ macro(<name> [<arg1> ...])
+ <commands>
+ endmacro()
+
+Defines a macro named ``<name>`` that takes arguments named
+``<arg1>``, ... Commands listed after macro, but before the
+matching :command:`endmacro()`, are not executed until the macro
+is invoked.
+
+Per legacy, the :command:`endmacro` command admits an optional
+``<name>`` argument. If used, it must be a verbatim repeat of the
+argument of the opening ``macro`` command.
+
+See the :command:`cmake_policy()` command documentation for the behavior
+of policies inside macros.
+
+See the :ref:`Macro vs Function` section below for differences
+between CMake macros and :command:`functions <function>`.
+
+Invocation
+^^^^^^^^^^
+
+The macro invocation is case-insensitive. A macro defined as
+
+.. code-block:: cmake
+
+ macro(foo)
+ <commands>
+ endmacro()
+
+can be invoked through any of
+
+.. code-block:: cmake
+
+ foo()
+ Foo()
+ FOO()
+
+and so on. However, it is strongly recommended to stay with the
+case chosen in the macro definition. Typically macros use
+all-lowercase names.
+
+Arguments
+^^^^^^^^^
+
+When a macro 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
+
+Furthermore, ``${ARGV}`` holds the list of all arguments given to the
macro and ``${ARGN}`` holds the list of arguments past the last expected
argument.
Referencing to ``${ARGV#}`` arguments beyond ``${ARGC}`` have undefined
@@ -29,48 +68,73 @@ behavior. Checking that ``${ARGC}`` is greater than ``#`` is the only
way to ensure that ``${ARGV#}`` was passed to the function as an extra
argument.
-See the :command:`cmake_policy()` command documentation for the behavior
-of policies inside macros.
+.. _`Macro vs Function`:
+
+Macro vs Function
+^^^^^^^^^^^^^^^^^
-Macro Argument Caveats
-^^^^^^^^^^^^^^^^^^^^^^
+The ``macro`` command is very similar to the :command:`function` command.
+Nonetheless, there are a few important differences.
-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::
+In a function, ``ARGN``, ``ARGC``, ``ARGV`` and ``ARGV0``, ``ARGV1``, ...
+are true variables in the usual CMake sense. In a macro, they are not,
+they are string replacements much like the C preprocessor would do
+with a macro. This has a number of consequences, as explained in
+the :ref:`Argument Caveats` section below.
+
+Another difference between macros and functions is the control flow.
+A function is executed by transferring control from the calling
+statement to the function body. A macro is executed as if the macro
+body were pasted in place of the calling statement. This has the
+consequence that a :command:`return()` in a macro body does not
+just terminate execution of the macro; rather, control is returned
+from the scope of the macro call. To avoid confusion, it is recommended
+to avoid :command:`return()` in macros altogether.
+
+.. _`Argument Caveats`:
+
+Argument Caveats
+^^^^^^^^^^^^^^^^
+
+Since ``ARGN``, ``ARGC``, ``ARGV``, ``ARGV0`` etc. are not variables,
+you will NOT be able to use commands like
+
+.. code-block:: cmake
if(ARGV1) # ARGV1 is not a variable
if(DEFINED ARGV2) # ARGV2 is not a variable
if(ARGC GREATER 2) # ARGC 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 and third case, the proper way to check if an optional
-variable was passed to the macro is to use ``if(${ARGC} GREATER 2)``.
-In the last case, you can use ``foreach(loop_var ${ARGN})`` but this
-will skip empty arguments.
-If you need to include them, you can use::
+In the first case, you can use ``if(${ARGV1})``. In the second and
+third case, the proper way to check if an optional variable was
+passed to the macro is to use ``if(${ARGC} GREATER 2)``. In the
+last case, you can use ``foreach(loop_var ${ARGN})`` but this will
+skip empty arguments. If you need to include them, you can use
+
+.. code-block:: cmake
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::
+existing variable instead of the arguments. For example:
+
+.. code-block:: cmake
- macro(_BAR)
+ macro(bar)
foreach(arg IN LISTS ARGN)
- [...]
+ <commands>
endforeach()
endmacro()
- function(_FOO)
- _bar(x y z)
+ function(foo)
+ bar(x y z)
endfunction()
- _foo(a b c)
+ foo(a b c)
-Will loop over ``a;b;c`` and not over ``x;y;z`` as one might be expecting.
+Will loop over ``a;b;c`` and not over ``x;y;z`` as one might have expected.
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
index 27ecf5194..8469b0a96 100644
--- a/Help/command/make_directory.rst
+++ b/Help/command/make_directory.rst
@@ -1,7 +1,9 @@
make_directory
--------------
-Deprecated. Use the :command:`file(MAKE_DIRECTORY)` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`file(MAKE_DIRECTORY)` command instead.
::
diff --git a/Help/command/mark_as_advanced.rst b/Help/command/mark_as_advanced.rst
index c3f94fc48..5712fb420 100644
--- a/Help/command/mark_as_advanced.rst
+++ b/Help/command/mark_as_advanced.rst
@@ -3,17 +3,22 @@ mark_as_advanced
Mark cmake cached variables as advanced.
-::
+.. code-block:: cmake
- mark_as_advanced([CLEAR|FORCE] VAR [VAR2 ...])
+ mark_as_advanced([CLEAR|FORCE] <var1> ...)
-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.
+Sets the advanced/non-advanced state of the named
+cached variables.
-It does nothing in script mode.
+An advanced variable will not be displayed in any
+of the cmake GUIs unless the ``show advanced`` option is on.
+In script mode, the advanced/non-advanced state has no effect.
+
+If the keyword ``CLEAR`` is given
+then advanced variables are changed back to unadvanced.
+If the keyword ``FORCE`` is given
+then the variables are made advanced.
+If neither ``FORCE`` nor ``CLEAR`` is specified,
+new values will be marked as advanced, but if a
+variable already has an advanced/non-advanced state,
+it will not be changed.
diff --git a/Help/command/math.rst b/Help/command/math.rst
index f99dc3db3..3cbe719e5 100644
--- a/Help/command/math.rst
+++ b/Help/command/math.rst
@@ -1,14 +1,36 @@
math
----
-Mathematical expressions.
+Evaluate a mathematical expression.
-::
+.. code-block:: cmake
- math(EXPR <output-variable> <math-expression>)
+ math(EXPR <variable> "<expression>" [OUTPUT_FORMAT <format>])
-``EXPR`` evaluates mathematical expression and returns result in the
-output variable. Example mathematical expression is ``5 * (10 + 13)``.
+Evaluates a mathematical ``<expression>`` and sets ``<variable>`` to the
+resulting value.
+
+The mathematical expression must be given as a string (i.e. enclosed in
+double quotation marks). An example is ``"5 * (10 + 13)"``.
Supported operators are ``+``, ``-``, ``*``, ``/``, ``%``, ``|``, ``&``,
-``^``, ``~``, ``<<``, ``>>``, and ``(...)``. They have the same meaning
-as they do in C code.
+``^``, ``~``, ``<<``, ``>>``, and ``(...)``; they have the same meaning
+as in C code.
+
+Hexadecimal numbers are recognized when prefixed with ``0x``, as in C code.
+
+The result is formatted according to the option ``OUTPUT_FORMAT``,
+where ``<format>`` is one of
+
+``HEXADECIMAL``
+ Hexadecimal notation as in C code, i. e. starting with "0x".
+``DECIMAL``
+ Decimal notation. Which is also used if no ``OUTPUT_FORMAT`` option
+ is specified.
+
+
+For example
+
+.. code-block:: cmake
+
+ math(EXPR value "100 * 0xA" OUTPUT_FORMAT DECIMAL) # value is set to "1000"
+ math(EXPR value "100 * 0xA" OUTPUT_FORMAT HEXADECIMAL) # value is set to "0x3e8"
diff --git a/Help/command/message.rst b/Help/command/message.rst
index 04c62fdff..5dca6b417 100644
--- a/Help/command/message.rst
+++ b/Help/command/message.rst
@@ -3,30 +3,62 @@ message
Display a message to the user.
-::
+.. code-block:: cmake
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.
+``FATAL_ERROR``
+ CMake Error, stop processing and generation.
+
+``SEND_ERROR``
+ CMake Error, continue processing, but skip generation.
+
+``WARNING``
+ CMake Warning, continue processing.
+
+``AUTHOR_WARNING``
+ CMake Warning (dev), continue processing.
+
+``DEPRECATION``
+ CMake Deprecation Error or Warning if variable
+ :variable:`CMAKE_ERROR_DEPRECATED` or :variable:`CMAKE_WARN_DEPRECATED`
+ is enabled, respectively, else no message.
+
+(none) or ``NOTICE``
+ Important message printed to stderr to attract user's attention.
+
+``STATUS``
+ The main interesting messages that project users might be interested in.
+ Ideally these should be concise, no more than a single line, but still
+ informative.
+
+``VERBOSE``
+ Detailed informational messages intended for project users. These messages
+ should provide additional details that won't be of interest in most cases,
+ but which may be useful to those building the project when they want deeper
+ insight into what's happening.
+
+``DEBUG``
+ Detailed informational messages intended for developers working on the
+ project itself as opposed to users who just want to build it. These messages
+ will not typically be of interest to other users building the project and
+ will often be closely related to internal implementation details.
+
+``TRACE``
+ Fine-grained messages with very low-level implementation details. Messages
+ using this log level would normally only be temporary and would expect to be
+ removed before releasing the project, packaging up the files, etc.
+
+The CMake command-line tool displays ``STATUS`` to ``TRACE`` messages on stdout
+with the message preceded by two hyphens and a space. All other message types
+are sent to stderr and are not prefixed with hyphens. The
+:manual:`CMake GUI <cmake-gui(1)>` displays all messages in its log area.
+The :manual:`curses interface <ccmake(1)>` shows ``STATUS`` to ``TRACE``
+messages one at a time on a status line and other messages in an
+interactive pop-up box. The ``--loglevel`` command-line option to each of
+these tools can be used to control which messages will be shown.
CMake Warning and Error message text displays using a simple markup
language. Non-indented text is formatted in line-wrapped paragraphs
diff --git a/Help/command/option.rst b/Help/command/option.rst
index 91cd0a778..8956307c5 100644
--- a/Help/command/option.rst
+++ b/Help/command/option.rst
@@ -1,15 +1,16 @@
option
------
-Provides an option that the user can optionally select.
+Provide an option that the user can optionally select.
-::
+.. code-block:: cmake
- option(<option_variable> "help string describing option"
- [initial value])
+ option(<variable> "<help_text>" [value])
-Provide an option for the user to select as ``ON`` or ``OFF``. If no
-initial value is provided, ``OFF`` is used.
+Provides an option for the user to select as ``ON`` or ``OFF``.
+If no initial ``<value>`` is provided, ``OFF`` is used.
+If ``<variable>`` is already set as a normal variable
+then the command does nothing (see policy :policy:`CMP0077`).
If you have options that depend on the values of other options, see
the module help for :module:`CMakeDependentOption`.
diff --git a/Help/command/output_required_files.rst b/Help/command/output_required_files.rst
index 5e1355763..b3a6e8653 100644
--- a/Help/command/output_required_files.rst
+++ b/Help/command/output_required_files.rst
@@ -1,7 +1,7 @@
output_required_files
---------------------
-Disallowed. See CMake Policy :policy:`CMP0032`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0032`.
Approximate C preprocessor dependency scanning.
@@ -14,6 +14,6 @@ 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.
+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
index 139f69c9b..baf18be64 100644
--- a/Help/command/project.rst
+++ b/Help/command/project.rst
@@ -1,69 +1,129 @@
project
-------
-Set a name, version, and enable languages for the entire project.
+Set the name of the project.
+
+Synopsis
+^^^^^^^^
.. code-block:: cmake
- project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
+ project(<PROJECT-NAME> [<language-name>...])
project(<PROJECT-NAME>
[VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
[DESCRIPTION <project-description-string>]
+ [HOMEPAGE_URL <url-string>]
[LANGUAGES <language-name>...])
-Sets the name of the project and stores the name in the
-:variable:`PROJECT_NAME` variable. Additionally this sets variables
+Sets the name of the project, and stores it in the variable
+:variable:`PROJECT_NAME`. When called from the top-level
+``CMakeLists.txt`` also stores the project name in the
+variable :variable:`CMAKE_PROJECT_NAME`.
+
+Also sets the 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``).
-
-If optional ``DESCRIPTION`` is given, then additional :variable:`PROJECT_DESCRIPTION`
-variable will be set to its argument. The argument must be a string with short
-description of the project (only a few words).
-
-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.
+Further variables are set by the optional arguments described in the following.
+If any of these arguments is not used, then the corresponding variables are
+set to the empty string.
+
+Options
+^^^^^^^
+
+The options are:
+
+``VERSION <version>``
+ Optional; may not be used unless policy :policy:`CMP0048` is
+ set to ``NEW``.
+
+ Takes a ``<version>`` argument composed of non-negative integer components,
+ i.e. ``<major>[.<minor>[.<patch>[.<tweak>]]]``,
+ and sets the 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`.
+
+ When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
+ then the version is also stored in the variable :variable:`CMAKE_PROJECT_VERSION`.
+
+``DESCRIPTION <project-description-string>``
+ Optional.
+ Sets the variables
+
+ * :variable:`PROJECT_DESCRIPTION`, :variable:`<PROJECT-NAME>_DESCRIPTION`
+
+ to ``<project-description-string>``.
+ It is recommended that this description is a relatively short string,
+ usually no more than a few words.
+
+ When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
+ then the description is also stored in the variable :variable:`CMAKE_PROJECT_DESCRIPTION`.
+
+``HOMEPAGE_URL <url-string>``
+ Optional.
+ Sets the variables
+
+ * :variable:`PROJECT_HOMEPAGE_URL`, :variable:`<PROJECT-NAME>_HOMEPAGE_URL`
+
+ to ``<url-string>``, which should be the canonical home URL for the project.
+
+ When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
+ then the URL also is stored in the variable :variable:`CMAKE_PROJECT_HOMEPAGE_URL`.
+
+``LANGUAGES <language-name>...``
+ Optional.
+ Can also be specified without ``LANGUAGES`` keyword per the first, short signature.
+
+ Selects which programming languages are needed to build the project.
+ Supported languages include ``C``, ``CXX`` (i.e. C++), ``CUDA``, ``Fortran``, and ``ASM``.
+ 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 enabling ``ASM``, list it last so that CMake can check whether
+ compilers for other languages like ``C`` work for assembly too.
+
+The variables set through the ``VERSION``, ``DESCRIPTION`` and ``HOMEPAGE_URL``
+options are intended for use as default values in package metadata and documentation.
+
+Code Injection
+^^^^^^^^^^^^^^
+
+If the :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variable is set, the file
+pointed to by that variable will be included as the first step of the
+``project()`` command.
+
+If the :variable:`CMAKE_PROJECT_INCLUDE` or
+:variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` variables are set, the files
+they point to will be included as the last step of the ``project()`` command.
+If both are set, then :variable:`CMAKE_PROJECT_INCLUDE` will be included before
+:variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`.
+
+Usage
+^^^^^
The top-level ``CMakeLists.txt`` file for a project must contain a
-literal, direct call to the :command:`project` command; loading one
+literal, direct call to the ``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``).
+call exists, CMake will issue a warning and pretend there is a
+``project(Project)`` at the top to enable the default languages
+(``C`` and ``CXX``).
.. note::
- Call the :command:`cmake_minimum_required` command at the beginning
- of the top-level ``CMakeLists.txt`` file even before calling the
- ``project()`` command. It is important to establish version and
- policy settings before invoking other commands whose behavior they
- may affect. See also policy :policy:`CMP0000`.
+ Call the ``project()`` command near the top of the top-level
+ ``CMakeLists.txt``, but *after* calling :command:`cmake_minimum_required`.
+ It is important to establish version and policy settings before invoking
+ other commands whose behavior they may affect.
+ See also policy :policy:`CMP0000`.
diff --git a/Help/command/qt_wrap_cpp.rst b/Help/command/qt_wrap_cpp.rst
index 3843bf5e9..ce11c2d09 100644
--- a/Help/command/qt_wrap_cpp.rst
+++ b/Help/command/qt_wrap_cpp.rst
@@ -1,12 +1,23 @@
qt_wrap_cpp
-----------
-Create Qt Wrappers.
+.. deprecated:: 3.14
-::
+ This command was originally added to support Qt 3 before the
+ :command:`add_custom_command()` command was sufficiently mature. The
+ :module:`FindQt4` module provides the ``qt4_wrap_cpp()`` macro, which
+ should be used instead for Qt 4 projects. For projects using Qt 5 or
+ later, use the equivalent macro provided by Qt itself (e.g. Qt 5 provides
+ ``qt5_wrap_cpp()``).
- qt_wrap_cpp(resultingLibraryName DestName
- SourceLists ...)
+Manually create Qt Wrappers.
-Produce moc files for all the .h files listed in the SourceLists. The
+.. code-block:: cmake
+
+ qt_wrap_cpp(resultingLibraryName DestName SourceLists ...)
+
+Produces 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.
+
+Consider updating the project to use the :prop_tgt:`AUTOMOC` target property
+instead for a more automated way of invoking the ``moc`` tool.
diff --git a/Help/command/qt_wrap_ui.rst b/Help/command/qt_wrap_ui.rst
index f731ed9a8..efbbc5472 100644
--- a/Help/command/qt_wrap_ui.rst
+++ b/Help/command/qt_wrap_ui.rst
@@ -1,14 +1,26 @@
qt_wrap_ui
----------
-Create Qt user interfaces Wrappers.
+.. deprecated:: 3.14
-::
+ This command was originally added to support Qt 3 before the
+ :command:`add_custom_command()` command was sufficiently mature. The
+ :module:`FindQt4` module provides the ``qt4_wrap_ui()`` macro, which
+ should be used instead for Qt 4 projects. For projects using Qt 5 or
+ later, use the equivalent macro provided by Qt itself (e.g. Qt 5 provides
+ ``qt5_wrap_ui()``).
+
+Manually create Qt user interfaces Wrappers.
+
+.. code-block:: cmake
qt_wrap_ui(resultingLibraryName HeadersDestName
SourcesDestName SourceLists ...)
-Produce .h and .cxx files for all the .ui files listed in the
+Produces .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.
+
+Consider updating the project to use the :prop_tgt:`AUTOUIC` target property
+instead for a more automated way of invoking the ``uic`` tool.
diff --git a/Help/command/remove.rst b/Help/command/remove.rst
index 462827796..543d01671 100644
--- a/Help/command/remove.rst
+++ b/Help/command/remove.rst
@@ -1,7 +1,9 @@
remove
------
-Deprecated. Use the :command:`list(REMOVE_ITEM)` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`list(REMOVE_ITEM)` command instead.
::
diff --git a/Help/command/remove_definitions.rst b/Help/command/remove_definitions.rst
index ea189181c..faad16dcb 100644
--- a/Help/command/remove_definitions.rst
+++ b/Help/command/remove_definitions.rst
@@ -1,9 +1,9 @@
remove_definitions
------------------
-Removes -D define flags added by :command:`add_definitions`.
+Remove -D define flags added by :command:`add_definitions`.
-::
+.. code-block:: cmake
remove_definitions(-DFOO -DBAR ...)
diff --git a/Help/command/return.rst b/Help/command/return.rst
index e49fb3c8d..830992c25 100644
--- a/Help/command/return.rst
+++ b/Help/command/return.rst
@@ -3,7 +3,7 @@ return
Return from a file, directory or function.
-::
+.. code-block:: cmake
return()
@@ -14,5 +14,6 @@ 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.
+
+Note that a :command:`macro <macro>`, unlike a :command:`function <function>`,
+is expanded in place and therefore cannot handle ``return()``.
diff --git a/Help/command/separate_arguments.rst b/Help/command/separate_arguments.rst
index 47982a503..fbca859f2 100644
--- a/Help/command/separate_arguments.rst
+++ b/Help/command/separate_arguments.rst
@@ -1,33 +1,43 @@
separate_arguments
------------------
-Parse space-separated arguments into a semicolon-separated list.
+Parse command-line arguments into a semicolon-separated list.
-::
+.. code-block:: cmake
- separate_arguments(<var> <NATIVE|UNIX|WINDOWS>_COMMAND "<args>")
+ separate_arguments(<variable> <mode> <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.
+Parses a space-separated string ``<args>`` into a list of items,
+and stores this list in semicolon-separated standard form in ``<variable>``.
-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``).
+This function is intended for parsing command-line arguments.
+The entire command line must be passed as one string in the
+argument ``<args>``.
-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.
+The exact parsing rules depend on the operating system.
+They are specified by the ``<mode>`` argument which must
+be one of the following keywords:
-The ``NATIVE_COMMAND`` mode parses a Windows command-line if the host
-system is Windows, and a UNIX command-line otherwise.
+``UNIX_COMMAND``
+ Arguments are separated by by unquoted whitespace.
+ Both single-quote and double-quote pairs are respected.
+ A backslash escapes the next literal character (``\"`` is ``"``);
+ there are no special escapes (``\n`` is just ``n``).
+
+``WINDOWS_COMMAND``
+ A Windows command-line is parsed 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.
+
+``NATIVE_COMMAND``
+ Proceeds as in ``WINDOWS_COMMAND`` mode if the host system is Windows.
+ Otherwise proceeds as in ``UNIX_COMMAND`` mode.
.. _`Parsing C Command-Line Arguments`: https://msdn.microsoft.com/library/a1y7w461.aspx
-::
+.. code-block:: cmake
separate_arguments(<var>)
diff --git a/Help/command/set.rst b/Help/command/set.rst
index b24ebefeb..c0e02e246 100644
--- a/Help/command/set.rst
+++ b/Help/command/set.rst
@@ -8,18 +8,18 @@ and cache entries.
Signatures of this command that specify a ``<value>...`` placeholder
expect zero or more arguments. Multiple arguments will be joined as
-a :ref:`;-list <CMake Language Lists>` to form the actual variable
+a :ref:`semicolon-separated list <CMake Language Lists>` to form the actual variable
value to be set. Zero arguments will cause normal variables to be
unset. See the :command:`unset` command to unset variables explicitly.
Set Normal Variable
^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
set(<variable> <value>... [PARENT_SCOPE])
-Set the given ``<variable>`` in the current function or directory scope.
+Sets the given ``<variable>`` in the current function or directory scope.
If the ``PARENT_SCOPE`` option is given the variable will be set in
the scope above the current scope. Each new directory or function
@@ -32,11 +32,11 @@ undefined and if it had a value, it is still that value).
Set Cache Entry
^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
set(<variable> <value>... CACHE <type> <docstring> [FORCE])
-Set the given cache ``<variable>`` (cache entry). Since cache entries
+Sets the given cache ``<variable>`` (cache entry). Since cache entries
are meant to provide user-settable values this does not overwrite
existing cache entries by default. Use the ``FORCE`` option to
overwrite existing entries.
@@ -84,8 +84,21 @@ current working directory and convert it to an absolute path.
Set Environment Variable
^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
- set(ENV{<variable>} <value>...)
+ set(ENV{<variable>} [<value>])
-Set the current process environment ``<variable>`` to the given value.
+Sets an :manual:`Environment Variable <cmake-env-variables(7)>`
+to the given value.
+Subsequent calls of ``$ENV{<variable>}`` will return this new value.
+
+This command affects only the current CMake process, not the process
+from which CMake was called, nor the system environment at large,
+nor the environment of subsequent build or test processes.
+
+If no argument is given after ``ENV{<variable>}`` or if ``<value>`` is
+an empty string, then this command will clear any existing value of the
+environment variable.
+
+Arguments after ``<value>`` are ignored. If extra arguments are found,
+then an author warning is issued.
diff --git a/Help/command/set_directory_properties.rst b/Help/command/set_directory_properties.rst
index e485fce0a..f02a8e6c7 100644
--- a/Help/command/set_directory_properties.rst
+++ b/Help/command/set_directory_properties.rst
@@ -1,12 +1,15 @@
set_directory_properties
------------------------
-Set a property of the directory.
+Set properties of the current directory and subdirectories.
-::
+.. code-block:: cmake
- set_directory_properties(PROPERTIES prop1 value1 prop2 value2)
+ set_directory_properties(PROPERTIES prop1 value1 [prop2 value2] ...)
-Set a property for the current directory and subdirectories. See
-:ref:`Directory Properties` for the list of properties known
-to CMake.
+Sets properties of the current directory and its subdirectories in key-value pairs.
+
+See also the :command:`set_property(DIRECTORY)` command.
+
+See :ref:`Directory Properties` for the list of properties known to CMake
+and their individual documentation for the behavior of each property.
diff --git a/Help/command/set_property.rst b/Help/command/set_property.rst
index 5ed788e4a..ec08c8f99 100644
--- a/Help/command/set_property.rst
+++ b/Help/command/set_property.rst
@@ -3,37 +3,40 @@ set_property
Set a named property in a given scope.
-::
-
- set_property(<GLOBAL |
- DIRECTORY [dir] |
- TARGET [target1 [target2 ...]] |
- SOURCE [src1 [src2 ...]] |
- INSTALL [file1 [file2 ...]] |
- TEST [test1 [test2 ...]] |
- CACHE [entry1 [entry2 ...]]>
+.. code-block:: cmake
+
+ set_property(<GLOBAL |
+ DIRECTORY [<dir>] |
+ TARGET [<target1> ...] |
+ SOURCE [<src1> ...] |
+ INSTALL [<file1> ...] |
+ TEST [<test1> ...] |
+ CACHE [<entry1> ...] >
[APPEND] [APPEND_STRING]
- PROPERTY <name> [value1 [value2 ...]])
+ PROPERTY <name> [value1 ...])
-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:
+Sets 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.
+ Scope defaults to the current directory but another directory
+ (already processed by CMake) may be named by full or relative path.
+ See also the :command:`set_directory_properties` command.
``TARGET``
Scope may name zero or more existing targets.
+ See also the :command:`set_target_properties` command.
``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).
+ directory (``CMakeLists.txt``).
+ See also the :command:`set_source_files_properties` command.
``INSTALL``
Scope may name zero or more installed file paths.
@@ -45,7 +48,7 @@ be one of the following:
Path components have to be separated by forward slashes,
must be normalized and are case sensitive.
- To reference the installation prefix itself with a relative path use ".".
+ To reference the installation prefix itself with a relative path use ``.``.
Currently installed file properties are only defined for
the WIX generator where the given paths are relative
@@ -53,17 +56,24 @@ be one of the following:
``TEST``
Scope may name zero or more existing tests.
+ See also the :command:`set_tests_properties` command.
``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.
+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
+appended to any existing property value as string, i.e. it results in a
+longer string and not a list of strings. When using ``APPEND`` or
+``APPEND_STRING`` with a property defined to support ``INHERITED``
+behavior (see :command:`define_property`), no inheriting occurs when
+finding the initial value to append to. If the property is not already
+directly set in the nominated scope, the command will behave as though
+``APPEND`` or ``APPEND_STRING`` had not been given.
See the :manual:`cmake-properties(7)` manual for a list of properties
in each scope.
diff --git a/Help/command/set_source_files_properties.rst b/Help/command/set_source_files_properties.rst
index b4904e8d0..ab95d7094 100644
--- a/Help/command/set_source_files_properties.rst
+++ b/Help/command/set_source_files_properties.rst
@@ -3,13 +3,17 @@ set_source_files_properties
Source files can have properties that affect how they are built.
-::
+.. code-block:: cmake
set_source_files_properties([file1 [file2 [...]]]
PROPERTIES prop1 value1
[prop2 value2 [...]])
-Set properties associated with source files using a key/value paired
-list. See :ref:`Source File Properties` for the list of properties known
+Sets properties associated with source files using a key/value paired
+list.
+
+See also the :command:`set_property(SOURCE)` command.
+
+See :ref:`Source File Properties` for the list of properties known
to CMake. Source file properties are visible only to targets added
-in the same directory (CMakeLists.txt).
+in the same directory (``CMakeLists.txt``).
diff --git a/Help/command/set_target_properties.rst b/Help/command/set_target_properties.rst
index b894eace3..597be231a 100644
--- a/Help/command/set_target_properties.rst
+++ b/Help/command/set_target_properties.rst
@@ -3,16 +3,18 @@ set_target_properties
Targets can have properties that affect how they are built.
-::
+.. code-block:: cmake
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
+Sets properties on targets. The syntax for the command is to list all
+the targets 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 :command:`get_property` or :command:`get_target_property`
command.
+See also the :command:`set_property(TARGET)` command.
+
See :ref:`Target Properties` for the list of properties known to CMake.
diff --git a/Help/command/set_tests_properties.rst b/Help/command/set_tests_properties.rst
index 3efb1653e..9bc94ae38 100644
--- a/Help/command/set_tests_properties.rst
+++ b/Help/command/set_tests_properties.rst
@@ -3,12 +3,15 @@ set_tests_properties
Set a property of the tests.
-::
+.. code-block:: cmake
set_tests_properties(test1 [test2...] PROPERTIES prop1 value1 prop2 value2)
-Set a property for the tests. If the test is not found, CMake
+Sets a property for the tests. If the test is not found, CMake
will report an error.
:manual:`Generator expressions <cmake-generator-expressions(7)>` will be
-expanded the same as supported by the test's :command:`add_test` call. See
-:ref:`Test Properties` for the list of properties known to CMake.
+expanded the same as supported by the test's :command:`add_test` call.
+
+See also the :command:`set_property(TEST)` command.
+
+See :ref:`Test Properties` for the list of properties known to CMake.
diff --git a/Help/command/site_name.rst b/Help/command/site_name.rst
index e17c1ee68..1bcaeada0 100644
--- a/Help/command/site_name.rst
+++ b/Help/command/site_name.rst
@@ -3,6 +3,6 @@ site_name
Set the given variable to the name of the computer.
-::
+.. code-block:: cmake
site_name(variable)
diff --git a/Help/command/source_group.rst b/Help/command/source_group.rst
index 938ca40f2..6623c9837 100644
--- a/Help/command/source_group.rst
+++ b/Help/command/source_group.rst
@@ -4,7 +4,7 @@ source_group
Define a grouping for source files in IDE project generation.
There are two different signatures to create source groups.
-::
+.. code-block:: cmake
source_group(<name> [FILES <src>...] [REGULAR_EXPRESSION <regex>])
source_group(TREE <root> [PREFIX <prefix>] [FILES <src>...])
diff --git a/Help/command/string.rst b/Help/command/string.rst
index 4f0c45c29..2e89d7b9e 100644
--- a/Help/command/string.rst
+++ b/Help/command/string.rst
@@ -1,19 +1,55 @@
string
------
-.. only:: html
-
- .. contents::
-
String operations.
+Synopsis
+^^^^^^^^
+
+.. parsed-literal::
+
+ `Search and Replace`_
+ string(`FIND`_ <string> <substring> <out-var> [...])
+ string(`REPLACE`_ <match-string> <replace-string> <out-var> <input>...)
+
+ `Regular Expressions`_
+ string(`REGEX MATCH`_ <match-regex> <out-var> <input>...)
+ string(`REGEX MATCHALL`_ <match-regex> <out-var> <input>...)
+ string(`REGEX REPLACE`_ <match-regex> <replace-expr> <out-var> <input>...)
+
+ `Manipulation`_
+ string(`APPEND`_ <string-var> [<input>...])
+ string(`PREPEND`_ <string-var> [<input>...])
+ string(`CONCAT`_ <out-var> [<input>...])
+ string(`JOIN`_ <glue> <out-var> [<input>...])
+ string(`TOLOWER`_ <string1> <out-var>)
+ string(`TOUPPER`_ <string1> <out-var>)
+ string(`LENGTH`_ <string> <out-var>)
+ string(`SUBSTRING`_ <string> <begin> <length> <out-var>)
+ string(`STRIP`_ <string> <out-var>)
+ string(`GENEX_STRIP`_ <string> <out-var>)
+ string(`REPEAT`_ <string> <count> <out-var>)
+
+ `Comparison`_
+ string(`COMPARE`_ <op> <string1> <string2> <out-var>)
+
+ `Hashing`_
+ string(`\<HASH\> <HASH_>`_ <out-var> <input>)
+
+ `Generation`_
+ string(`ASCII`_ <number>... <out-var>)
+ string(`CONFIGURE`_ <string1> <out-var> [...])
+ string(`MAKE_C_IDENTIFIER`_ <string> <out-var>)
+ string(`RANDOM`_ [<option>...] <out-var>)
+ string(`TIMESTAMP`_ <out-var> [<format string>] [UTC])
+ string(`UUID`_ <out-var> ...)
+
Search and Replace
^^^^^^^^^^^^^^^^^^
-FIND
-""""
+.. _FIND:
-::
+.. code-block:: cmake
string(FIND <string> <substring> <output variable> [REVERSE])
@@ -22,10 +58,9 @@ the supplied string. If the ``REVERSE`` flag was used, the command will
search for the position of the last occurrence of the specified
substring. If the substring is not found, a position of -1 is returned.
-REPLACE
-"""""""
+.. _REPLACE:
-::
+.. code-block:: cmake
string(REPLACE <match_string>
<replace_string> <output variable>
@@ -37,10 +72,9 @@ with ``replace_string`` and store the result in the output.
Regular Expressions
^^^^^^^^^^^^^^^^^^^
-REGEX MATCH
-"""""""""""
+.. _`REGEX MATCH`:
-::
+.. code-block:: cmake
string(REGEX MATCH <regular_expression>
<output variable> <input> [<input>...])
@@ -48,10 +82,9 @@ REGEX MATCH
Match the regular expression once and store the match in the output variable.
All ``<input>`` arguments are concatenated before matching.
-REGEX MATCHALL
-""""""""""""""
+.. _`REGEX MATCHALL`:
-::
+.. code-block:: cmake
string(REGEX MATCHALL <regular_expression>
<output variable> <input> [<input>...])
@@ -60,10 +93,9 @@ Match the regular expression as many times as possible and store the matches
in the output variable as a list.
All ``<input>`` arguments are concatenated before matching.
-REGEX REPLACE
-"""""""""""""
+.. _`REGEX REPLACE`:
-::
+.. code-block:: cmake
string(REGEX REPLACE <regular_expression>
<replace_expression> <output variable>
@@ -90,6 +122,11 @@ The following characters have special meaning in regular expressions:
Matches at end of input
``.``
Matches any single character
+``\<char>``
+ Matches the single character specified by ``<char>``. Use this to
+ match special regex characters, e.g. ``\.`` for a literal ``.``
+ or ``\\`` for a literal backslash ``\``. Escaping a non-special
+ character is unnecessary but allowed, e.g. ``\a`` matches ``a``.
``[ ]``
Matches any character(s) inside the brackets
``[^ ]``
@@ -120,59 +157,90 @@ 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``.
+CMake language :ref:`Escape Sequences` such as ``\t``, ``\r``, ``\n``,
+and ``\\`` may be used to construct literal tabs, carriage returns,
+newlines, and backslashes (respectively) to pass in a regex. For example:
+
+* The quoted argument ``"[ \t\r\n]"`` specifies a regex that matches
+ any single whitespace character.
+* The quoted argument ``"[/\\]"`` specifies a regex that matches
+ a single forward slash ``/`` or backslash ``\``.
+* The quoted argument ``"[A-Za-z0-9_]"`` specifies a regex that matches
+ any single "word" character in the C locale.
+* The quoted argument ``"\\(\\a\\+b\\)"`` specifies a regex that matches
+ the exact string ``(a+b)``. Each ``\\`` is parsed in a quoted argument
+ as just ``\``, so the regex itself is actually ``\(\a\+\b\)``. This
+ can alternatively be specified in a :ref:`bracket argument` without
+ having to escape the backslashes, e.g. ``[[\(\a\+\b\)]]``.
+
Manipulation
^^^^^^^^^^^^
-APPEND
-""""""
+.. _APPEND:
-::
+.. code-block:: cmake
string(APPEND <string variable> [<input>...])
Append all the input arguments to the string.
-CONCAT
-""""""
+.. _PREPEND:
-::
+.. code-block:: cmake
+
+ string(PREPEND <string variable> [<input>...])
+
+Prepend all the input arguments to the string.
+
+.. _CONCAT:
+
+.. code-block:: cmake
string(CONCAT <output variable> [<input>...])
Concatenate all the input arguments together and store
the result in the named output variable.
-TOLOWER
-"""""""
+.. _JOIN:
-::
+.. code-block:: cmake
+
+ string(JOIN <glue> <output variable> [<input>...])
+
+Join all the input arguments together using the glue
+string and store the result in the named output variable.
+
+To join list's elements, use preferably the ``JOIN`` operator
+from :command:`list` command. This allows for the elements to have
+special characters like ``;`` in them.
+
+.. _TOLOWER:
+
+.. code-block:: cmake
string(TOLOWER <string1> <output variable>)
Convert string to lower characters.
-TOUPPER
-"""""""
+.. _TOUPPER:
-::
+.. code-block:: cmake
string(TOUPPER <string1> <output variable>)
Convert string to upper characters.
-LENGTH
-""""""
+.. _LENGTH:
-::
+.. code-block:: cmake
string(LENGTH <string> <output variable>)
Store in an output variable a given string's length.
-SUBSTRING
-"""""""""
+.. _SUBSTRING:
-::
+.. code-block:: cmake
string(SUBSTRING <string> <begin> <length> <output variable>)
@@ -184,30 +252,38 @@ If string is shorter than length then end of string is used instead.
CMake 3.1 and below reported an error if length pointed past
the end of string.
-STRIP
-"""""
+.. _STRIP:
-::
+.. code-block:: cmake
string(STRIP <string> <output variable>)
Store in an output variable a substring of a given string with leading and
trailing spaces removed.
-GENEX_STRIP
-"""""""""""
+.. _GENEX_STRIP:
-::
+.. code-block:: cmake
string(GENEX_STRIP <input string> <output variable>)
Strip any :manual:`generator expressions <cmake-generator-expressions(7)>`
from the ``input string`` and store the result in the ``output variable``.
+.. _REPEAT:
+
+.. code-block:: cmake
+
+ string(REPEAT <input string> <count> <output variable>)
+
+Produce the output string as repetion of ``input string`` ``count`` times.
+
Comparison
^^^^^^^^^^
-::
+.. _COMPARE:
+
+.. code-block:: cmake
string(COMPARE LESS <string1> <string2> <output variable>)
string(COMPARE GREATER <string1> <string2> <output variable>)
@@ -223,7 +299,9 @@ Compare the strings and store true or false in the output variable.
Hashing
^^^^^^^
-::
+.. _`HASH`:
+
+.. code-block:: cmake
string(<HASH> <output variable> <input>)
@@ -254,29 +332,37 @@ The supported ``<HASH>`` algorithm names are:
Generation
^^^^^^^^^^
-ASCII
-"""""
+.. _ASCII:
-::
+.. code-block:: cmake
string(ASCII <number> [<number> ...] <output variable>)
Convert all numbers into corresponding ASCII characters.
-CONFIGURE
-"""""""""
+.. _CONFIGURE:
-::
+.. code-block:: cmake
string(CONFIGURE <string1> <output variable>
[@ONLY] [ESCAPE_QUOTES])
Transform a string like :command:`configure_file` transforms a file.
-RANDOM
-""""""
+.. _MAKE_C_IDENTIFIER:
-::
+.. code-block:: cmake
+
+ string(MAKE_C_IDENTIFIER <input string> <output variable>)
+
+Convert each non-alphanumeric character in the ``<input string>`` to an
+underscore and store the result in the ``<output variable>``. If the first
+character of the string is a digit, an underscore will also be prepended to
+the result.
+
+.. _RANDOM:
+
+.. code-block:: cmake
string(RANDOM [LENGTH <length>] [ALPHABET <alphabet>]
[RANDOM_SEED <seed>] <output variable>)
@@ -287,10 +373,9 @@ 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.
-TIMESTAMP
-"""""""""
+.. _TIMESTAMP:
-::
+.. code-block:: cmake
string(TIMESTAMP <output variable> [<format string>] [UTC])
@@ -315,6 +400,7 @@ specifiers:
%j The day of the current year (001-366).
%m The month of the current year (01-12).
%b Abbreviated month name (e.g. Oct).
+ %B Full month name (e.g. October).
%M The minute of the current hour (00-59).
%s Seconds since midnight (UTC) 1-Jan-1970 (UNIX time).
%S The second of the current minute.
@@ -322,6 +408,7 @@ specifiers:
%U The week number of the current year (00-53).
%w The day of the current week. 0 is Sunday. (0-6)
%a Abbreviated weekday name (e.g. Fri).
+ %A Full weekday name (e.g. Friday).
%y The last two digits of the current year (00-99)
%Y The current year.
@@ -335,28 +422,20 @@ 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.
-
-::
-
- string(MAKE_C_IDENTIFIER <input string> <output variable>)
-
-Write a string which can be used as an identifier in C.
-
.. note::
If the ``SOURCE_DATE_EPOCH`` environment variable is set,
its value will be used instead of the current time.
See https://reproducible-builds.org/specs/source-date-epoch/ for details.
-UUID
-""""
+.. _UUID:
-::
+.. code-block:: cmake
string(UUID <output variable> NAMESPACE <namespace> NAME <name>
TYPE <MD5|SHA1> [UPPER])
-Create a univerally unique identifier (aka GUID) as per RFC4122
+Create a universally 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
diff --git a/Help/command/subdir_depends.rst b/Help/command/subdir_depends.rst
index 5676c8f40..0c1b3c1ce 100644
--- a/Help/command/subdir_depends.rst
+++ b/Help/command/subdir_depends.rst
@@ -1,7 +1,7 @@
subdir_depends
--------------
-Disallowed. See CMake Policy :policy:`CMP0029`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0029`.
Does nothing.
diff --git a/Help/command/subdirs.rst b/Help/command/subdirs.rst
index 43b87d4d7..530951bd1 100644
--- a/Help/command/subdirs.rst
+++ b/Help/command/subdirs.rst
@@ -1,7 +1,9 @@
subdirs
-------
-Deprecated. Use the :command:`add_subdirectory` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`add_subdirectory` command instead.
Add a list of subdirectories to the build.
diff --git a/Help/command/target_compile_definitions.rst b/Help/command/target_compile_definitions.rst
index 8bd323375..9e9c69093 100644
--- a/Help/command/target_compile_definitions.rst
+++ b/Help/command/target_compile_definitions.rst
@@ -3,26 +3,37 @@ target_compile_definitions
Add compile definitions to a target.
-::
+.. code-block:: cmake
target_compile_definitions(<target>
<INTERFACE|PUBLIC|PRIVATE> [items1...]
[<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
-Specify compile definitions to use when compiling a given ``<target>``. The
+Specifies 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>`.
+:ref:`ALIAS target <Alias 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
+:prop_tgt:`INTERFACE_COMPILE_DEFINITIONS` property of ``<target>``.
+(:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
+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.
+
+Any leading ``-D`` on an item will be removed. Empty items are ignored.
+For example, the following are all equivalent:
+
+.. code-block:: cmake
+
+ target_compile_definitions(foo PUBLIC FOO)
+ target_compile_definitions(foo PUBLIC -DFOO) # -D removed
+ target_compile_definitions(foo PUBLIC "" FOO) # "" ignored
+ target_compile_definitions(foo PUBLIC -D FOO) # -D becomes "", then ignored
diff --git a/Help/command/target_compile_features.rst b/Help/command/target_compile_features.rst
index b66a4ec16..9271cd56c 100644
--- a/Help/command/target_compile_features.rst
+++ b/Help/command/target_compile_features.rst
@@ -3,11 +3,11 @@ target_compile_features
Add expected compiler features to a target.
-::
+.. code-block:: cmake
target_compile_features(<target> <PRIVATE|PUBLIC|INTERFACE> <feature> [...])
-Specify compiler features required when compiling a given target. If the
+Specifies 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
@@ -18,12 +18,13 @@ 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.
+:prop_tgt:`INTERFACE_COMPILE_FEATURES` property of ``<target>``.
+(:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
+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.
+:command:`add_executable` or :command:`add_library` and must not be an
+:ref:`ALIAS target <Alias Targets>`.
Arguments to ``target_compile_features`` may use "generator expressions"
with the syntax ``$<...>``.
diff --git a/Help/command/target_compile_options.rst b/Help/command/target_compile_options.rst
index 73e01e7f8..47e7d86f8 100644
--- a/Help/command/target_compile_options.rst
+++ b/Help/command/target_compile_options.rst
@@ -3,35 +3,46 @@ target_compile_options
Add compile options to a target.
-::
+.. code-block:: cmake
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
-:ref:`IMPORTED Target <Imported Targets>`. If ``BEFORE`` is specified,
-the content will be prepended to the property instead of being appended.
+Adds options to the :prop_tgt:`COMPILE_OPTIONS` or
+:prop_tgt:`INTERFACE_COMPILE_OPTIONS` target properties. These options
+are used when compiling the given ``<target>``, which must have been
+created by a command such as :command:`add_executable` or
+:command:`add_library` and must not be an :ref:`ALIAS target <Alias Targets>`.
-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_dir:`directory <COMPILE_OPTIONS>` and
-:prop_tgt:`target <COMPILE_OPTIONS>` ``COMPILE_OPTIONS`` properties.
+Arguments
+^^^^^^^^^
+
+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:`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
+:prop_tgt:`INTERFACE_COMPILE_OPTIONS` property of ``<target>``.
+(:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
+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.
+
+.. include:: OPTIONS_SHELL.txt
+
+See Also
+^^^^^^^^
+
+This command can be used to add any options. However, for adding
+preprocessor definitions and include directories it is recommended
+to use the more specific commands :command:`target_compile_definitions`
+and :command:`target_include_directories`.
+
+For directory-wide settings, there is the command :command:`add_compile_options`.
diff --git a/Help/command/target_include_directories.rst b/Help/command/target_include_directories.rst
index 30ec2cb27..660e15c9b 100644
--- a/Help/command/target_include_directories.rst
+++ b/Help/command/target_include_directories.rst
@@ -3,16 +3,16 @@ target_include_directories
Add include directories to a target.
-::
+.. code-block:: cmake
target_include_directories(<target> [SYSTEM] [BEFORE]
<INTERFACE|PUBLIC|PRIVATE> [items1...]
[<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
-Specify include directories to use when compiling a given target.
+Specifies include directories 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.
+:ref:`ALIAS target <Alias Targets>`.
If ``BEFORE`` is specified, the content will be prepended to the property
instead of being appended.
@@ -21,9 +21,9 @@ 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.
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` property of ``<target>``.
+(:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
+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
diff --git a/Help/command/target_link_libraries.rst b/Help/command/target_link_libraries.rst
index 30d69f266..c2e7e8ac9 100644
--- a/Help/command/target_link_libraries.rst
+++ b/Help/command/target_link_libraries.rst
@@ -14,13 +14,19 @@ Overview
^^^^^^^^
This command has several signatures as detailed in subsections below.
-All of them have the general form::
+All of them have the general form
+
+.. code-block:: cmake
target_link_libraries(<target> ... <item>... ...)
-The named ``<target>`` must have been created in the current directory by
-a command such as :command:`add_executable` or :command:`add_library`.
-Repeated calls for the same ``<target>`` append items in the order called.
+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:`ALIAS target <Alias Targets>`. If policy :policy:`CMP0079` is not
+set to ``NEW`` then the target must have been created in the current
+directory. Repeated calls for the same ``<target>`` append items in
+the order called.
+
Each ``<item>`` may be:
* **A library target name**: The generated link line will have the
@@ -39,6 +45,9 @@ Each ``<item>`` may be:
the library instead of using the full path
(e.g. ``/usr/lib/libfoo.so`` becomes ``-lfoo``).
+ The full path to the target's artifact will be quoted/escaped for
+ the shell automatically.
+
* **A full path to a library file**: The generated link line will
normally preserve the full path to the file. The buildsystem will
have a dependency to re-link ``<target>`` if the library file changes.
@@ -48,7 +57,7 @@ Each ``<item>`` may be:
as when a shared library is detected to have no ``SONAME`` field.
See policy :policy:`CMP0060` for discussion of another case.
- If the library file is in a Mac OSX framework, the ``Headers`` directory
+ If the library file is in a macOS 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.
@@ -58,9 +67,15 @@ Each ``<item>`` may be:
imported into generated project files. This is not supported by other
generators.
+ The full path to the library file will be quoted/escaped for
+ the shell automatically.
+
* **A plain library name**: The generated link line will ask the linker
to search for the library (e.g. ``foo`` becomes ``-lfoo`` or ``foo.lib``).
+ The library name/flag is treated as a command-line string fragment and
+ will be used with no extra quoting or escaping.
+
* **A link flag**: 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
@@ -69,10 +84,28 @@ Each ``<item>`` may be:
Link flags specified here are inserted into the link command in the same
place as the link libraries. This might not be correct, depending on
- the linker. Use the :prop_tgt:`LINK_FLAGS` target property to add link
+ the linker. Use the :prop_tgt:`LINK_OPTIONS` target property or
+ :command:`target_link_options` command to add link
flags explicitly. The flags will then be placed at the toolchain-defined
flag position in the link command.
+ The link flag is treated as a command-line string fragment and
+ will be used with no extra quoting or escaping.
+
+* **A generator expression**: A ``$<...>`` :manual:`generator expression
+ <cmake-generator-expressions(7)>` may evaluate to any of the above
+ items or to a :ref:`semicolon-separated list <CMake Language Lists>` of them.
+ If the ``...`` contains any ``;`` characters, e.g. after evaluation
+ of a ``${list}`` variable, be sure to use an explicitly quoted
+ argument ``"$<...>"`` so that this command receives it as a
+ single ``<item>``.
+
+ Additionally, a generator expression may be used as a fragment of
+ any of the above items, e.g. ``foo$<1:_d>``.
+
+ Note that generator expressions will not be used in OLD handling of
+ policy :policy:`CMP0003` or policy :policy:`CMP0004`.
+
* A ``debug``, ``optimized``, or ``general`` keyword immediately followed
by another ``<item>``. The item following such a keyword will be used
only for the corresponding build configuration. The ``debug`` keyword
@@ -83,23 +116,21 @@ Each ``<item>`` may be:
optional. Higher granularity may be achieved for per-configuration
rules by creating and linking to
:ref:`IMPORTED library targets <Imported Targets>`.
+ These keywords are interpreted immediately by this command and therefore
+ have no special meaning when produced by a generator expression.
Items containing ``::``, such as ``Foo::Bar``, are assumed to be
:ref:`IMPORTED <Imported Targets>` or :ref:`ALIAS <Alias Targets>` library
target names and will cause an error if no such target exists.
See policy :policy:`CMP0028`.
-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.
+See the :manual:`cmake-buildsystem(7)` manual for more on defining
+buildsystem properties.
Libraries for a Target and/or its Dependents
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
target_link_libraries(<target>
<PRIVATE|PUBLIC|INTERFACE> <item>...
@@ -116,7 +147,7 @@ used for linking ``<target>``.
Libraries for both a Target and its Dependents
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
target_link_libraries(<target> <item>...)
@@ -134,7 +165,7 @@ exclusively by this signature private.
Libraries for a Target and/or its Dependents (Legacy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
target_link_libraries(<target>
<LINK_PRIVATE|LINK_PUBLIC> <lib>...
@@ -156,7 +187,7 @@ made part of the :prop_tgt:`INTERFACE_LINK_LIBRARIES`. If policy
Libraries for Dependents Only (Legacy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
target_link_libraries(<target> LINK_INTERFACE_LIBRARIES <item>...)
@@ -182,6 +213,70 @@ is not ``NEW``, they are also appended to the
``general`` (or without any keyword) are treated as if specified for both
``debug`` and ``optimized``.
+Linking Object Libraries
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+:ref:`Object Libraries` may be used as the ``<target>`` (first) argument
+of ``target_link_libraries`` to specify dependencies of their sources
+on other libraries. For example, the code
+
+.. code-block:: cmake
+
+ add_library(A SHARED a.c)
+ target_compile_definitions(A PUBLIC A)
+
+ add_library(obj OBJECT obj.c)
+ target_compile_definitions(obj PUBLIC OBJ)
+ target_link_libraries(obj PUBLIC A)
+
+compiles ``obj.c`` with ``-DA -DOBJ`` and establishes usage requirements
+for ``obj`` that propagate to its dependents.
+
+Normal libraries and executables may link to :ref:`Object Libraries`
+to get their objects and usage requirements. Continuing the above
+example, the code
+
+.. code-block:: cmake
+
+ add_library(B SHARED b.c)
+ target_link_libraries(B PUBLIC obj)
+
+compiles ``b.c`` with ``-DA -DOBJ``, creates shared library ``B``
+with object files from ``b.c`` and ``obj.c``, and links ``B`` to ``A``.
+Furthermore, the code
+
+.. code-block:: cmake
+
+ add_executable(main main.c)
+ target_link_libraries(main B)
+
+compiles ``main.c`` with ``-DA -DOBJ`` and links executable ``main``
+to ``B`` and ``A``. The object library's usage requirements are
+propagated transitively through ``B``, but its object files are not.
+
+:ref:`Object Libraries` may "link" to other object libraries to get
+usage requirements, but since they do not have a link step nothing
+is done with their object files. Continuing from the above example,
+the code:
+
+.. code-block:: cmake
+
+ add_library(obj2 OBJECT obj2.c)
+ target_link_libraries(obj2 PUBLIC obj)
+
+ add_executable(main2 main2.c)
+ target_link_libraries(main2 obj2)
+
+compiles ``obj2.c`` with ``-DA -DOBJ``, creates executable ``main2``
+with object files from ``main2.c`` and ``obj2.c``, and links ``main2``
+to ``A``.
+
+In other words, when :ref:`Object Libraries` appear in a target's
+:prop_tgt:`INTERFACE_LINK_LIBRARIES` property they will be
+treated as :ref:`Interface Libraries`, but when they appear in
+a target's :prop_tgt:`LINK_LIBRARIES` property their object files
+will be included in the link too.
+
Cyclic Dependencies of Static Libraries
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst
index d6f148d23..27e737bf0 100644
--- a/Help/command/target_sources.rst
+++ b/Help/command/target_sources.rst
@@ -3,26 +3,32 @@ target_sources
Add sources to a target.
-::
+.. code-block:: cmake
target_sources(<target>
<INTERFACE|PUBLIC|PRIVATE> [items1...]
[<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
-Specify sources to use when compiling a given target. The
+Specifies sources to use when compiling a given target. Relative
+source file paths are interpreted as being relative to the current
+source directory (i.e. :variable:`CMAKE_CURRENT_SOURCE_DIR`). 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>`.
+:ref:`ALIAS target <Alias 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:`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
+:prop_tgt:`INTERFACE_SOURCES` property of ``<target>``.
+(:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
+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.
+
+See also the :policy:`CMP0076` policy for older behavior related to the
+handling of relative source file paths.
diff --git a/Help/command/try_compile.rst b/Help/command/try_compile.rst
index 66ea3d7f2..0bc2ca37a 100644
--- a/Help/command/try_compile.rst
+++ b/Help/command/try_compile.rst
@@ -10,14 +10,14 @@ Try building some code.
Try Compiling Whole Projects
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
- try_compile(RESULT_VAR <bindir> <srcdir>
+ try_compile(<resultVar> <bindir> <srcdir>
<projectName> [<targetName>] [CMAKE_FLAGS <flags>...]
[OUTPUT_VARIABLE <var>])
Try building a project. The success or failure of the ``try_compile``,
-i.e. ``TRUE`` or ``FALSE`` respectively, is returned in ``RESULT_VAR``.
+i.e. ``TRUE`` or ``FALSE`` respectively, is returned in ``<resultVar>``.
In this form, ``<srcdir>`` should contain a complete CMake project with a
``CMakeLists.txt`` file and all sources. The ``<bindir>`` and ``<srcdir>``
@@ -28,11 +28,12 @@ below for the meaning of other options.
Try Compiling Source Files
^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
- try_compile(RESULT_VAR <bindir> <srcfile|SOURCES srcfile...>
+ try_compile(<resultVar> <bindir> <srcfile|SOURCES srcfile...>
[CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
+ [LINK_OPTIONS <options>...]
[LINK_LIBRARIES <libs>...]
[OUTPUT_VARIABLE <var>]
[COPY_FILE <fileName> [COPY_FILE_ERROR <var>]]
@@ -41,18 +42,27 @@ Try Compiling Source Files
[<LANG>_EXTENSIONS <bool>]
)
-Try building an executable from one or more source files. The success or
-failure of the ``try_compile``, i.e. ``TRUE`` or ``FALSE`` respectively, is
-returned in ``RESULT_VAR``.
+Try building an executable or static library from one or more source files
+(which one is determined by the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE`
+variable). The success or failure of the ``try_compile``, i.e. ``TRUE`` or
+``FALSE`` respectively, is returned in ``<resultVar>``.
-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 that looks something like this::
+In this form, one or more source files must be provided. If
+:variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is unset or is set to ``EXECUTABLE``,
+the sources must include a definition for ``main`` and CMake will create a
+``CMakeLists.txt`` file to build the source(s) as an executable.
+If :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to ``STATIC_LIBRARY``,
+a static library will be built instead and no definition for ``main`` is
+required. For an executable, the generated ``CMakeLists.txt`` file would
+contain something like the following:
+
+.. code-block:: cmake
add_definitions(<expanded COMPILE_DEFINITIONS from caller>)
include_directories(${INCLUDE_DIRECTORIES})
link_directories(${LINK_DIRECTORIES})
add_executable(cmTryCompileExec <srcfile>...)
+ target_link_options(cmTryCompileExec PRIVATE <LINK_OPTIONS from caller>)
target_link_libraries(cmTryCompileExec ${LINK_LIBRARIES})
The options are:
@@ -65,11 +75,11 @@ The options are:
are used.
``COMPILE_DEFINITIONS <defs>...``
- Specify ``-Ddefinition`` arguments to pass to ``add_definitions``
+ Specify ``-Ddefinition`` arguments to pass to :command:`add_definitions`
in the generated test project.
``COPY_FILE <fileName>``
- Copy the linked executable to the given ``<fileName>``.
+ Copy the built executable or static library to the given ``<fileName>``.
``COPY_FILE_ERROR <var>``
Use after ``COPY_FILE`` to capture into variable ``<var>`` any error
@@ -83,8 +93,13 @@ The options are:
If this option is specified, any ``-DLINK_LIBRARIES=...`` value
given to the ``CMAKE_FLAGS`` option will be ignored.
+``LINK_OPTIONS <options>...``
+ Specify link step options to pass to :command:`target_link_options` or to
+ set the :prop_tgt:`STATIC_LIBRARY_OPTIONS` target property in the generated
+ project, depending on the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable.
+
``OUTPUT_VARIABLE <var>``
- Store the output from the build process the given variable.
+ Store the output from the build process in the given variable.
``<LANG>_STANDARD <std>``
Specify the :prop_tgt:`C_STANDARD`, :prop_tgt:`CXX_STANDARD`,
@@ -105,7 +120,7 @@ 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
+project by ``if(NOT DEFINED <resultVar>)`` 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``.
@@ -120,12 +135,19 @@ default values:
* :variable:`CMAKE_ENABLE_EXPORTS`
* :variable:`CMAKE_LINK_SEARCH_START_STATIC`
* :variable:`CMAKE_LINK_SEARCH_END_STATIC`
+* :variable:`CMAKE_MSVC_RUNTIME_LIBRARY`
* :variable:`CMAKE_POSITION_INDEPENDENT_CODE`
If :policy:`CMP0056` is set to ``NEW``, then
:variable:`CMAKE_EXE_LINKER_FLAGS` is passed in as well.
-The current setting of :policy:`CMP0065` is set in the generated project.
+If :policy:`CMP0083` is set to ``NEW``, then in order to obtain correct
+behavior at link time, the ``check_pie_supported()`` command from the
+:module:`CheckPIESupported` module must be called before using the
+:command:`try_compile` command.
+
+The current settings of :policy:`CMP0065` and :policy:`CMP0083` are propagated
+through to the generated test project.
Set the :variable:`CMAKE_TRY_COMPILE_CONFIGURATION` variable to choose
a build configuration.
@@ -135,7 +157,9 @@ the type of target used for the source file signature.
Set the :variable:`CMAKE_TRY_COMPILE_PLATFORM_VARIABLES` variable to specify
variables that must be propagated into the test project. This variable is
-meant for use only in toolchain files.
+meant for use only in toolchain files and is only honored by the
+``try_compile()`` command for the source files form, not when given a whole
+project.
If :policy:`CMP0067` is set to ``NEW``, or any of the ``<LANG>_STANDARD``,
``<LANG>_STANDARD_REQUIRED``, or ``<LANG>_EXTENSIONS`` options are used,
@@ -153,3 +177,6 @@ then the language standard variables are honored:
Their values are used to set the corresponding target properties in
the generated project (unless overridden by an explicit option).
+
+For the :generator:`Green Hills MULTI` generator the GHS toolset and target
+system customization cache variables are also propagated into the test project.
diff --git a/Help/command/try_run.rst b/Help/command/try_run.rst
index e3bd57d50..d401ebe92 100644
--- a/Help/command/try_run.rst
+++ b/Help/command/try_run.rst
@@ -10,11 +10,12 @@ Try compiling and then running some code.
Try Compiling and Running Source Files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: cmake
- try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
- bindir srcfile [CMAKE_FLAGS <flags>...]
+ try_run(<runResultVar> <compileResultVar>
+ <bindir> <srcfile> [CMAKE_FLAGS <flags>...]
[COMPILE_DEFINITIONS <defs>...]
+ [LINK_OPTIONS <options>...]
[LINK_LIBRARIES <libs>...]
[COMPILE_OUTPUT_VARIABLE <var>]
[RUN_OUTPUT_VARIABLE <var>]
@@ -22,9 +23,9 @@ Try Compiling and Running Source Files
[ARGS <args>...])
Try compiling a ``<srcfile>``. Returns ``TRUE`` or ``FALSE`` for success
-or failure in ``COMPILE_RESULT_VAR``. If the compile succeeded, runs the
-executable and returns its exit code in ``RUN_RESULT_VAR``. If the
-executable was built, but failed to run, then ``RUN_RESULT_VAR`` will be
+or failure in ``<compileResultVar>``. If the compile succeeded, runs the
+executable and returns its exit code in ``<runResultVar>``. If the
+executable was built, but failed to run, then ``<runResultVar>`` will be
set to ``FAILED_TO_RUN``. See the :command:`try_compile` command for
information on how the test project is constructed to build the source file.
@@ -38,7 +39,7 @@ The options are:
are used.
``COMPILE_DEFINITIONS <defs>...``
- Specify ``-Ddefinition`` arguments to pass to ``add_definitions``
+ Specify ``-Ddefinition`` arguments to pass to :command:`add_definitions`
in the generated test project.
``COMPILE_OUTPUT_VARIABLE <var>``
@@ -52,6 +53,10 @@ The options are:
If this option is specified, any ``-DLINK_LIBRARIES=...`` value
given to the ``CMAKE_FLAGS`` option will be ignored.
+``LINK_OPTIONS <options>...``
+ Specify link step options to pass to :command:`target_link_options` in the
+ generated project.
+
``OUTPUT_VARIABLE <var>``
Report the compile build output and the output from running the executable
in the given variable. This option exists for legacy reasons. Prefer
@@ -80,10 +85,10 @@ 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 cache entries are:
-``<RUN_RESULT_VAR>``
+``<runResultVar>``
Exit code if the executable were to be run on the target platform.
-``<RUN_RESULT_VAR>__TRYRUN_OUTPUT``
+``<runResultVar>__TRYRUN_OUTPUT``
Output from stdout and stderr if the executable were to be run on
the target platform. This is created only if the
``RUN_OUTPUT_VARIABLE`` or ``OUTPUT_VARIABLE`` option was used.
diff --git a/Help/command/unset.rst b/Help/command/unset.rst
index a1fc95cc6..75210521e 100644
--- a/Help/command/unset.rst
+++ b/Help/command/unset.rst
@@ -3,23 +3,39 @@ unset
Unset a variable, cache variable, or environment variable.
-::
+Unset Normal Variable or Cache Entry
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: cmake
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.
+Removes a normal variable from the current scope, causing it
+to become undefined. If ``CACHE`` is present, then a cache variable
+is removed instead of a normal variable. Note that when evaluating
+:ref:`Variable References` of the form ``${VAR}``, CMake first searches
+for a normal variable with that name. If no such normal variable exists,
+CMake will then search for a cache entry with that name. Because of this
+unsetting a normal variable can expose a cache variable that was previously
+hidden. To force a variable reference of the form ``${VAR}`` to return an
+empty string, use ``set(<variable> "")``, which clears the normal variable
+but leaves it defined.
If ``PARENT_SCOPE`` is present then the variable is removed from the scope
above the current scope. See the same option in the :command:`set` command
for further details.
-``<variable>`` can be an environment variable such as:
+Unset Environment Variable
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: cmake
-::
+ unset(ENV{<variable>})
- unset(ENV{LD_LIBRARY_PATH})
+Removes ``<variable>`` from the currently available
+:manual:`Environment Variables <cmake-env-variables(7)>`.
+Subsequent calls of ``$ENV{<variable>}`` will return the empty string.
-in which case the variable will be removed from the current
-environment.
+This command affects only the current CMake process, not the process
+from which CMake was called, nor the system environment at large,
+nor the environment of subsequent build or test processes.
diff --git a/Help/command/use_mangled_mesa.rst b/Help/command/use_mangled_mesa.rst
index 6f4d7aca6..5b0e2ee06 100644
--- a/Help/command/use_mangled_mesa.rst
+++ b/Help/command/use_mangled_mesa.rst
@@ -1,7 +1,7 @@
use_mangled_mesa
----------------
-Disallowed. See CMake Policy :policy:`CMP0030`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0030`.
Copy mesa headers for use in combination with system GL.
@@ -9,7 +9,7 @@ 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
+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
index ee34492c3..94d6a4e64 100644
--- a/Help/command/utility_source.rst
+++ b/Help/command/utility_source.rst
@@ -1,7 +1,7 @@
utility_source
--------------
-Disallowed. See CMake Policy :policy:`CMP0034`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0034`.
Specify the source tree of a third-party utility.
diff --git a/Help/command/variable_requires.rst b/Help/command/variable_requires.rst
index 9cf9f3ffd..322b15459 100644
--- a/Help/command/variable_requires.rst
+++ b/Help/command/variable_requires.rst
@@ -1,7 +1,7 @@
variable_requires
-----------------
-Disallowed. See CMake Policy :policy:`CMP0035`.
+Disallowed since version 3.0. See CMake Policy :policy:`CMP0035`.
Use the :command:`if` command instead.
@@ -18,5 +18,5 @@ 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
+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
index a2df058eb..ce69bcfcd 100644
--- a/Help/command/variable_watch.rst
+++ b/Help/command/variable_watch.rst
@@ -3,11 +3,13 @@ variable_watch
Watch the CMake variable for change.
-::
+.. code-block:: cmake
- variable_watch(<variable name> [<command to execute>])
+ variable_watch(<variable> [<command>])
-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>)
+If the specified ``<variable>`` changes, a message will be printed
+to inform about the change.
+
+Additionally, if ``<command>`` is given, this 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
index 7509da309..a4957c1db 100644
--- a/Help/command/while.rst
+++ b/Help/command/while.rst
@@ -3,15 +3,23 @@ while
Evaluate a group of commands while a condition is true
-::
+.. code-block:: cmake
- while(condition)
- COMMAND1(ARGS ...)
- COMMAND2(ARGS ...)
- ...
- endwhile(condition)
+ while(<condition>)
+ <commands>
+ endwhile()
All commands between while and the matching :command:`endwhile` are recorded
without being invoked. Once the :command:`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 :command:`if` command.
+recorded list of commands is invoked as long as the ``<condition>`` is true.
+
+The ``<condition>`` has the same syntax and is evaluated using the same logic
+as described at length for the :command:`if` command.
+
+The commands :command:`break` and :command:`continue` provide means to
+escape from the normal control flow.
+
+Per legacy, the :command:`endwhile` command admits
+an optional ``<condition>`` argument.
+If used, it must be a verbatim repeat of the argument of the opening
+``while`` command.
diff --git a/Help/command/write_file.rst b/Help/command/write_file.rst
index 40e755763..4d476bd5a 100644
--- a/Help/command/write_file.rst
+++ b/Help/command/write_file.rst
@@ -1,7 +1,9 @@
write_file
----------
-Deprecated. Use the :command:`file(WRITE)` command instead.
+.. deprecated:: 3.0
+
+ Use the :command:`file(WRITE)` command instead.
::
diff --git a/Help/dev/README.rst b/Help/dev/README.rst
index ce62abc4b..84da4f1d3 100644
--- a/Help/dev/README.rst
+++ b/Help/dev/README.rst
@@ -36,8 +36,10 @@ Developer Documentation
CMake developer documentation is provided by the following documents:
* The `CMake Source Code Guide`_.
+* The `CMake Documentation Guide`_.
.. _`CMake Source Code Guide`: source.rst
+.. _`CMake Documentation Guide`: documentation.rst
Maintainer Documentation
========================
diff --git a/Help/dev/maint.rst b/Help/dev/maint.rst
index 78c06df65..1153a095f 100644
--- a/Help/dev/maint.rst
+++ b/Help/dev/maint.rst
@@ -8,6 +8,90 @@ See documentation on `CMake Development`_ for more information.
.. contents:: Maintainer Processes:
+Review a Merge Request
+======================
+
+The `CMake Review Process`_ requires a maintainer to issue the ``Do: merge``
+command to integrate a merge request. Please check at least the following:
+
+* If the MR source branch is not named well for the change it makes
+ (e.g. it is just ``master`` or the patch changed during review),
+ add a ``Topic-rename: <topic>`` trailing line to the MR description
+ to provide a better topic name.
+
+* If the MR introduces a new feature or a user-facing behavior change,
+ such as a policy, ensure that a ``Help/release/dev/$topic.rst`` file
+ is added with a release note.
+
+* If a commit changes a specific area, such as a module, its commit
+ message should have an ``area:`` prefix on its first line.
+
+* If a commit fixes a tracked issue, its commit message should have
+ a trailing line such as ``Fixes: #00000``.
+
+* Ensure that the MR adds sufficient documentation and test cases.
+
+* Ensure that the MR has been tested sufficiently. Typically it should
+ be staged for nightly testing with ``Do: stage``. Then manually
+ review the `CMake CDash Page`_ to verify that no regressions were
+ introduced. (Learn to tolerate spurious failures due to idiosyncrasies
+ of various nightly builders.)
+
+* Ensure that the MR targets the ``master`` branch. A MR intended for
+ the ``release`` branch should be based on ``release`` but still merged
+ to ``master`` first (via ``Do: merge``). A maintainer may then merge
+ the MR topic to ``release`` manually.
+
+Maintain Current Release
+========================
+
+The ``release`` branch is used to maintain the current release or release
+candidate. The branch is published with no version number but maintained
+using a local branch named ``release-$ver``, where ``$ver`` is the version
+number of the current release in the form ``$major.$minor``. It is always
+merged into ``master`` before publishing.
+
+Before merging a ``$topic`` branch into ``release``, verify that the
+``$topic`` branch has already been merged to ``master`` via the usual
+``Do: merge`` process. Then, to merge the ``$topic`` branch into
+``release``, start by creating the local branch:
+
+.. code-block:: shell
+
+ git fetch origin
+ git checkout -b release-$ver origin/release
+
+Merge the ``$topic`` branch into the local ``release-$ver`` branch, making
+sure to include a ``Merge-request: !xxxx`` footer in the commit message:
+
+.. code-block:: shell
+
+ git merge --no-ff $topic
+
+Merge the ``release-$ver`` branch to ``master``:
+
+.. code-block:: shell
+
+ git checkout master
+ git pull
+ git merge --no-ff release-$ver
+
+Review new ancestry to ensure nothing unexpected was merged to either branch:
+
+.. code-block:: shell
+
+ git log --graph --boundary origin/master..master
+ git log --graph --boundary origin/release..release-$ver
+
+Publish both ``master`` and ``release`` simultaneously:
+
+.. code-block:: shell
+
+ git push --atomic origin master release-$ver:release
+
+.. _`CMake Review Process`: review.rst
+.. _`CMake CDash Page`: https://open.cdash.org/index.php?project=CMake
+
Branch a New Release
====================
@@ -104,12 +188,6 @@ Update ``Source/CMakeVersion.cmake`` to set the version to
set(CMake_VERSION_PATCH 0)
set(CMake_VERSION_RC 1)
-Update ``Utilities/Release/upload_release.cmake``:
-
-.. code-block:: cmake
-
- set(VERSION $ver)
-
Update uses of ``DEVEL_CMAKE_VERSION`` in the source tree to mention the
actual version number:
diff --git a/Help/dev/review.rst b/Help/dev/review.rst
index 9450bf081..cbde6feea 100644
--- a/Help/dev/review.rst
+++ b/Help/dev/review.rst
@@ -185,6 +185,92 @@ commands to ``@kwrobot`` using the form ``Do: ...``:
See the corresponding sections for details on permissions and options
for each command.
+Commit Messages
+---------------
+
+Part of the human review is to check that each commit message is appropriate.
+The first line of the message should begin with one or two words indicating the
+area the commit applies to, followed by a colon and then a brief summary.
+Committers should aim to keep this first line short. Any subsequent lines
+should be separated from the first by a blank line and provide relevant, useful
+information.
+
+Area Prefix on Commit Messages
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The appropriateness of the initial word describing the area the commit applies
+to is not something the automatic robot review can judge, so it is up to the
+human reviewer to confirm that the area is specified and that it is
+appropriate. Good area words include the module name the commit is primarily
+fixing, the main C++ source file being edited, ``Help`` for generic
+documentation changes or a feature or functionality theme the changes apply to
+(e.g. ``server`` or ``Autogen``). Examples of suitable first lines of a commit
+message include:
+
+* ``Help: Fix example in cmake-buildsystem(7) manual``
+* ``FindBoost: Add support for 1.64``
+* ``Autogen: Extended mocInclude tests``
+* ``cmLocalGenerator: Explain standard flag selection logic in comments``
+
+Referencing Issues in Commit Messages
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If the commit fixes a particular reported issue, this information should
+ideally also be part of the commit message. The recommended way to do this is
+to place a line at the end of the message in the form ``Fixes: #xxxxx`` where
+``xxxxx`` is the GitLab issue number and to separate it from the rest of the
+text by a blank line. For example::
+
+ Help: Fix FooBar example robustness issue
+
+ FooBar supports option X, but the example provided
+ would not work if Y was also specified.
+
+ Fixes: #12345
+
+GitLab will automatically create relevant links to the merge request and will
+close the issue when the commit is merged into master. GitLab understands a few
+other synonyms for ``Fixes`` and allows much more flexible forms than the
+above, but committers should aim for this format for consistency. Note that
+such details can alternatively be specified in the merge request description.
+
+Referencing Commits in Commit Messages
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The preferred form for references to other commits is
+``commit <shorthash> (<subject>, <date>)``, where:
+
+* ``<shorthash>``:
+ The abbreviated hash of the commit.
+
+* ``<subject>``:
+ The first line of the commit message.
+
+* ``<date>``:
+ The author date of the commit, in its original time zone, formatted as
+ ``CCYY-MM-DD``. ``git-log(1)`` shows the original time zone by default.
+
+This may be generated with
+``git show -s --date=short --pretty="format:%h (%s, %ad)" <commit>``.
+
+If the commit is a fix for the mentioned commit, consider using a ``Fixes:``
+trailer in the commit message with the specified format. This trailer should
+not be word-wrapped. Note that if there is also an issue for what is being
+fixed, it is preferrable to link to the issue instead.
+
+If relevant, add the first release tag of CMake containing the commit after
+the ``<date>``, i.e., ``commit <shorthash> (<subject>, <date>, <tag>)``.
+
+Alternatively, the full commit ``<hash>`` may be used.
+
+Revising Commit Messages
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Reviewers are encouraged to ask the committer to amend commit messages to
+follow these guidelines, but prefer to focus on the changes themselves as a
+first priority. Maintainers will also make a check of commit messages before
+merging.
+
Topic Testing
=============
@@ -246,6 +332,14 @@ branch (e.g. ``master``) branch followed by a sequence of merges each
integrating changes from an open MR that has been staged for integration
testing. Each time the target integration branch is updated the stage
is rebuilt automatically by merging the staged MR topics again.
+The branch is stored in the upstream repository by special refs:
+
+* ``refs/stage/master/head``: The current topic stage branch.
+ This is used by continuous builds that report to CDash.
+* ``refs/stage/master/nightly/latest``: Topic stage as of 1am UTC each night.
+ This is used by most nightly builds that report to CDash.
+* ``refs/stage/master/nightly/<yyyy>/<mm>/<dd>``: Topic stage as of 1am UTC
+ on the date specified. This is used for historical reference.
`CMake GitLab Project Developers`_ may stage a MR for integration testing
by adding a comment with a command among the `comment trailing lines`_::
@@ -283,7 +377,15 @@ command is needed to stage it again.
Resolve
=======
-A MR may be resolved in one of the following ways.
+The workflow used by the CMake project supports a number of different
+ways in which a MR can be moved to a resolved state. In addition to
+the conventional practices of merging or closing a MR without merging it,
+a MR can also be moved to a quasi-resolved state pending some action.
+This may involve moving discussion to an issue or it may be the result of
+an extended period of inactivity. These quasi-resolved states are used
+to help manage the relatively large number of MRs the project receives
+and are not an indication of the changes being rejected. The following
+sections explain the different resolutions a MR may be given.
Merge
-----
@@ -324,11 +426,14 @@ The ``Do: merge`` command accepts the following arguments:
branch in the constructed merge commit message.
Additionally, ``Do: merge`` extracts configuration from trailing lines
-in the MR description:
+in the MR description (the following have no effect if used in a MR
+comment instead):
* ``Topic-rename: <topic>``: substitute ``<topic>`` for the name of
the MR topic branch in the constructed merge commit message.
- The ``-t`` option overrides this.
+ It is also used in merge commits constructed by ``Do: stage``.
+ The ``-t`` option to a ``Do: merge`` command overrides any topic
+ rename set in the MR description.
.. _`CMake GitLab Project Masters`: https://gitlab.kitware.com/cmake/cmake/settings/members
@@ -336,15 +441,68 @@ Close
-----
If review has concluded that the MR should not be integrated then it
-may be closed through GitLab.
+may be closed through GitLab. This would normally be a final state
+with no expectation that the MR would be re-opened in the future.
+It is also used when a MR is being superseded by another separate one,
+in which case a reference to the new MR should be added to the MR being
+closed.
Expire
------
If progress on a MR has stalled for a while, it may be closed with a
``workflow:expired`` label and a comment indicating that the MR has
-been closed due to inactivity.
-
-Contributors are welcome to re-open an expired MR when they are ready
-to continue work. Please re-open *before* pushing an update to the
-MR topic branch to ensure GitLab will still act on the association.
+been closed due to inactivity (it may also be done where the MR is blocked
+for an extended period by work in a different MR). This is not an
+indication that there is a problem with the MR's content, it is only a
+practical measure to allow the reviewers to focus attention on MRs that
+are actively being worked on. As a guide, the average period of inactivity
+before transitioning a MR to the expired state would be around 2 weeks,
+but this may decrease to 1 week or less when there is a high number of
+open merge requests.
+
+Reviewers would usually provide a message similar to the following when
+resolving a MR as expired::
+
+ Closing for now. @<MR-author> please re-open when ready to continue work.
+
+This is to make it clear to contributors that they are welcome to re-open
+the expired MR when they are ready to return to working on it and moving
+it forward. In the meantime, the MR will appear as ``Closed`` in GitLab,
+but it can be differentiated from permanently closed MRs by the presence
+of the ``workflow:expired`` label.
+
+**NOTE:** Please re-open *before* pushing an update to the MR topic branch
+to ensure GitLab will still act on the association. If changes are pushed
+before re-opening the MR, the reviewer should initiate a ``Do: check`` to
+force GitLab to act on the updates.
+
+External Discussion
+-------------------
+
+In some situations, a series of comments on a MR may develop into a more
+involved discussion, or it may become apparent that there are broader
+discussions that need to take place before the MR can move forward in an
+agreed direction. Such discussions are better suited to GitLab issues
+rather than in a MR because MRs may be superseded by a different MR, or
+the set of changes may evolve to look quite different to the context in
+which the discussions began. When this occurs, reviewers may ask the
+MR author to open an issue to discuss things there and they will transition
+the MR to a resolved state with the label ``workflow:external-discussion``.
+The MR will appear in GitLab as closed, but it can be differentiated from
+permanently closed MRs by the presence of the ``workflow:external-discussion``
+label. Reviewers should leave a message clearly explaining the action
+so that the MR author understands that the MR closure is temporary and
+it is clear what actions need to happen next. The following is an example
+of such a message, but it will usually be necessary to tailor the message
+to the individual situation::
+
+ The desired behavior here looks to be more involved than first thought.
+ Please open an issue so we can discuss the relevant details there.
+ Once the path forward is clear, we can re-open this MR and continue work.
+
+When the discussion in the associated issue runs its course and the way
+forward is clear, the MR can be re-opened again and the
+``workflow:external-discussion`` label removed. Reviewers should ensure
+that the issue created contains a reference to the MR so that GitLab
+provides a cross-reference to link the two.
diff --git a/Help/dev/source.rst b/Help/dev/source.rst
index 7e4499559..47baff42d 100644
--- a/Help/dev/source.rst
+++ b/Help/dev/source.rst
@@ -9,7 +9,7 @@ See documentation on `CMake Development`_ for more information.
C++ Code Style
==============
-We use `clang-format`_ version **3.8** to define our style for C++ code in
+We use `clang-format`_ version **6.0** to define our style for C++ code in
the CMake source tree. See the `.clang-format`_ configuration file for our
style settings. Use the `Utilities/Scripts/clang-format.bash`_ script to
format source code. It automatically runs ``clang-format`` on the set of
@@ -23,38 +23,57 @@ format only a subset of files, such as those that are locally modified.
C++ Subset Permitted
====================
-CMake supports compiling as C++98 in addition to C++11 and C++14.
-In order to support building on older toolchains some constructs
-need to be handled with care:
+CMake requires compiling as C++11 or above. However, in order to support
+building on older toolchains some constructs need to be handled with care:
-* Use ``CM_AUTO_PTR`` instead of ``std::auto_ptr``.
+* Do not use ``std::auto_ptr``.
- The ``std::auto_ptr`` template is deprecated in C++11. We want to use it
- so we can build on C++98 compilers but we do not want to turn off compiler
- warnings about deprecated interfaces in general. Use the ``CM_AUTO_PTR``
- macro instead.
+ The ``std::auto_ptr`` template is deprecated in C++11. Use ``std::unique_ptr``.
-* Use ``CM_EQ_DELETE;`` instead of ``= delete;``.
+Source Tree Layout
+==================
- Defining functions as *deleted* is not supported in C++98. Using
- ``CM_EQ_DELETE`` will delete the functions if the compiler supports it and
- give them no implementation otherwise. Calling such a function will lead
- to compiler errors if the compiler supports *deleted* functions and linker
- errors otherwise.
+The CMake source tree is organized as follows.
-* Use ``CM_DISABLE_COPY(Class)`` to mark classes as non-copyable.
+* ``Auxiliary/``:
+ Shell and editor integration files.
- The ``CM_DISABLE_COPY`` macro should be used in the private section of a
- class to make sure that attempts to copy or assign an instance of the class
- lead to compiler errors even if the compiler does not support *deleted*
- functions. As a guideline, all polymorphic classes should be made
- non-copyable in order to avoid slicing. Classes that are composed of or
- derived from non-copyable classes must also be made non-copyable explicitly
- with ``CM_DISABLE_COPY``.
+* ``Help/``:
+ Documentation. See the `CMake Documentation Guide`_.
-* Use ``size_t`` instead of ``std::size_t``.
+ * ``Help/dev/``:
+ Developer documentation.
- 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.
+ * ``Help/release/dev/``:
+ Release note snippets for development since last release.
+
+* ``Licenses/``:
+ License files for third-party libraries in binary distributions.
+
+* ``Modules/``:
+ CMake language modules installed with CMake.
+
+* ``Packaging/``:
+ Files used for packaging CMake itself for distribution.
+
+* ``Source/``:
+ Source code of CMake itself.
+
+* ``Templates/``:
+ Files distributed with CMake as implementation details for generators,
+ packagers, etc.
+
+* ``Tests/``:
+ The test suite. See `Tests/README.rst`_.
+
+* ``Utilities/``:
+ Scripts, third-party source code.
+
+ * ``Utilities/Sphinx/``:
+ Sphinx configuration to build CMake user documentation.
+
+ * ``Utilities/Release/``:
+ Scripts used to package CMake itself for distribution on ``cmake.org``.
+
+.. _`CMake Documentation Guide`: documentation.rst
+.. _`Tests/README.rst`: ../../Tests/README.rst
diff --git a/Help/dev/testing.rst b/Help/dev/testing.rst
index 731930c8f..23d0ca3f2 100644
--- a/Help/dev/testing.rst
+++ b/Help/dev/testing.rst
@@ -16,7 +16,7 @@ welcome to provide testing machines in order to help keep support for their
platforms working.
The `CMake Dashboard Scripts Repository`_ provides CTest scripts to drive
-nightly, continous, and experimental testing of CMake. Use the following
+nightly, continuous, and experimental testing of CMake. Use the following
commands to set up a new integration testing client:
.. code-block:: console
@@ -26,13 +26,14 @@ commands to set up a new integration testing client:
$ git clone https://gitlab.kitware.com/cmake/dashboard-scripts.git CMakeScripts
$ cd CMakeScripts
-The ``cmake_common.cmake`` script contains comments at the top with
+The `cmake_common.cmake`_ script contains comments at the top with
instructions to set up a testing client. As it instructs, create a
CTest script with local settings and include ``cmake_common.cmake``.
.. _`CMake Review Process`: review.rst
.. _`CMake CDash Page`: https://open.cdash.org/index.php?project=CMake
.. _`CMake Dashboard Scripts Repository`: https://gitlab.kitware.com/cmake/dashboard-scripts
+.. _`cmake_common.cmake`: https://gitlab.kitware.com/cmake/dashboard-scripts/blob/master/cmake_common.cmake
Nightly Start Time
------------------
diff --git a/Help/generator/CodeBlocks.rst b/Help/generator/CodeBlocks.rst
index d03cb0ce6..d830542eb 100644
--- a/Help/generator/CodeBlocks.rst
+++ b/Help/generator/CodeBlocks.rst
@@ -4,10 +4,14 @@ 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
+in every subdirectory which features a ``CMakeLists.txt`` file containing
+a :command:`project` call. Additionally a hierarchy of makefiles is generated
+into the build tree.
+The :variable:`CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES` variable may
+be set to ``ON`` to exclude any files which are located outside of
+the project root directory.
+The appropriate make program can build the
+project through the default ``all`` target. An ``install`` target is
also provided.
This "extra" generator may be specified as:
diff --git a/Help/generator/CodeLite.rst b/Help/generator/CodeLite.rst
index 3e60aa6d6..46fa5bef7 100644
--- a/Help/generator/CodeLite.rst
+++ b/Help/generator/CodeLite.rst
@@ -7,11 +7,11 @@ Project files for CodeLite will be created in the top directory and
in every subdirectory which features a CMakeLists.txt file containing
a :command:`project` call.
The :variable:`CMAKE_CODELITE_USE_TARGETS` variable may be set to ``ON``
-to change the default behaviour from projects to targets as the basis
+to change the default behavior from projects to targets as the basis
for project files.
The appropriate make program can build the
-project through the default make target. A "make install" target is
-also provided.
+project through the default ``all`` target. An ``install`` target
+is also provided.
This "extra" generator may be specified as:
diff --git a/Help/generator/Eclipse CDT4.rst b/Help/generator/Eclipse CDT4.rst
index eb68bf094..634e2b6dd 100644
--- a/Help/generator/Eclipse CDT4.rst
+++ b/Help/generator/Eclipse CDT4.rst
@@ -7,7 +7,7 @@ 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
+the project through the default ``all`` target. An ``install`` target
is also provided.
This "extra" generator may be specified as:
diff --git a/Help/generator/Green Hills MULTI.rst b/Help/generator/Green Hills MULTI.rst
index 4d3169026..dffc6795d 100644
--- a/Help/generator/Green Hills MULTI.rst
+++ b/Help/generator/Green Hills MULTI.rst
@@ -3,12 +3,65 @@ Green Hills MULTI
Generates Green Hills MULTI project files (experimental, work-in-progress).
-Customizations are available through the following cache variables:
+The buildsystem has predetermined build-configuration settings that can be controlled
+via the :variable:`CMAKE_BUILD_TYPE` variable.
+
+Customizations that are used to pick toolset and target system:
+
+The ``-A <arch>`` can be supplied for setting the target architecture.
+``<arch>`` usually is one of ``arm``, ``ppc``, ``86``, etcetera.
+If the target architecture is not specified then
+the default architecture of ``arm`` will be used.
+
+The ``-T <toolset>`` option can be used to set the directory location of the toolset.
+Both absolute and relative paths are valid. Relative paths use ``GHS_TOOLSET_ROOT``
+as the root. If the toolset is not specified then the latest toolset found in
+``GHS_TOOLSET_ROOT`` will be used.
+
+Cache variables that are used for toolset and target system customization:
+
+* ``GHS_TARGET_PLATFORM``
+
+ | Defaults to ``integrity``.
+ | Usual values are ``integrity``, ``threadx``, ``uvelosity``, ``velosity``,
+ ``vxworks``, ``standalone``.
+
+* ``GHS_PRIMARY_TARGET``
+
+ | Sets ``primaryTarget`` entry in project file.
+ | Defaults to ``<arch>_<GHS_TARGET_PLATFORM>.tgt``.
+
+* ``GHS_TOOLSET_ROOT``
+
+ | Root path for ``toolset`` searches.
+ | Defaults to ``C:/ghs`` in Windows or ``/usr/ghs`` in Linux.
+
+* ``GHS_OS_ROOT``
+
+ | Root path for RTOS searches.
+ | Defaults to ``C:/ghs`` in Windows or ``/usr/ghs`` in Linux.
+
+* ``GHS_OS_DIR`` and ``GHS_OS_DIR_OPTION``
+
+ | Sets ``-os_dir`` entry in project file.
+ | Defaults to latest platform OS installation at ``GHS_OS_ROOT``. Set this value if
+ a specific RTOS is to be used.
+ | ``GHS_OS_DIR_OPTION`` default value is ``-os_dir``.
* ``GHS_BSP_NAME``
+
+ | Sets ``-bsp`` entry in project file.
+ | Defaults to ``sim<arch>`` for ``integrity`` platforms.
+
+Customizations are available through the following cache variables:
+
* ``GHS_CUSTOMIZATION``
* ``GHS_GPJ_MACROS``
-* ``GHS_OS_DIR``
+
+The following properties are available:
+
+* :prop_tgt:`GHS_INTEGRITY_APP`
+* :prop_tgt:`GHS_NO_SOURCE_GROUP_FILE`
.. note::
This generator is deemed experimental as of CMake |release|
diff --git a/Help/generator/Kate.rst b/Help/generator/Kate.rst
index 9b61a93b3..129bf631b 100644
--- a/Help/generator/Kate.rst
+++ b/Help/generator/Kate.rst
@@ -5,10 +5,10 @@ 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
+To use it in Kate, the Project plugin must be enabled.
+The project file is loaded in Kate 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:
diff --git a/Help/generator/MSYS Makefiles.rst b/Help/generator/MSYS Makefiles.rst
index f7cfa4461..75b9fe531 100644
--- a/Help/generator/MSYS Makefiles.rst
+++ b/Help/generator/MSYS Makefiles.rst
@@ -1,7 +1,8 @@
MSYS Makefiles
--------------
-Generates makefiles for use with MSYS ``make`` under the MSYS shell.
+Generates makefiles for use with MSYS (Minimal SYStem)
+``make`` under the MSYS shell.
Use this generator in a MSYS shell prompt and using ``make`` as the build
tool. The generated makefiles use ``/bin/sh`` as the shell to launch build
diff --git a/Help/generator/MinGW Makefiles.rst b/Help/generator/MinGW Makefiles.rst
index 9fe5fe3e5..134ea7094 100644
--- a/Help/generator/MinGW Makefiles.rst
+++ b/Help/generator/MinGW Makefiles.rst
@@ -4,7 +4,8 @@ MinGW Makefiles
Generates makefiles for use with ``mingw32-make`` under a Windows command
prompt.
-Use this generator under a Windows command prompt with MinGW in the ``PATH``
+Use this generator under a Windows command prompt with
+MinGW (Minimalist GNU for Windows) in the ``PATH``
and using ``mingw32-make`` as the build tool. The generated makefiles use
``cmd.exe`` as the shell to launch build rules. They are not compatible with
MSYS or a unix shell.
diff --git a/Help/generator/Ninja.rst b/Help/generator/Ninja.rst
index 3bbd9dcbe..51ef49b01 100644
--- a/Help/generator/Ninja.rst
+++ b/Help/generator/Ninja.rst
@@ -4,8 +4,8 @@ Ninja
Generates build.ninja files.
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.
+of the ninja program can build the project through the ``all`` target.
+An ``install`` target is also provided.
For each subdirectory ``sub/dir`` of the project, additional targets
are generated:
diff --git a/Help/generator/Sublime Text 2.rst b/Help/generator/Sublime Text 2.rst
index 0597a9528..0a07ea983 100644
--- a/Help/generator/Sublime Text 2.rst
+++ b/Help/generator/Sublime Text 2.rst
@@ -4,11 +4,11 @@ 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.
+and in every subdirectory which features a ``CMakeLists.txt`` file
+containing a :command:`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 ``all``
+target. An ``install`` target is also provided.
This "extra" generator may be specified as:
diff --git a/Help/generator/Unix Makefiles.rst b/Help/generator/Unix Makefiles.rst
index 97d74a853..1e65ee133 100644
--- a/Help/generator/Unix Makefiles.rst
+++ b/Help/generator/Unix Makefiles.rst
@@ -5,4 +5,4 @@ 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.
+default ``all`` target. An ``install`` target is also provided.
diff --git a/Help/generator/VS_TOOLSET_HOST_ARCH.txt b/Help/generator/VS_TOOLSET_HOST_ARCH.txt
index 5d13e7741..029363115 100644
--- a/Help/generator/VS_TOOLSET_HOST_ARCH.txt
+++ b/Help/generator/VS_TOOLSET_HOST_ARCH.txt
@@ -1,6 +1,7 @@
For each toolset that comes with this version of Visual Studio, there are
-variants that are themselves compiled for 32-bit (x86) and 64-bit (x64) hosts
-(independent of the architecture they target). By default Visual Studio
-chooses the 32-bit variant even on a 64-bit host. One may request use of the
-64-bit host tools by adding a ``host=x64`` option to the toolset specification.
+variants that are themselves compiled for 32-bit (``x86``) and
+64-bit (``x64``) hosts (independent of the architecture they target).
+|VS_TOOLSET_HOST_ARCH_DEFAULT|
+One may explicitly request use of either the 32-bit or 64-bit host tools
+by adding either ``host=x86`` or ``host=x64`` to the toolset specification.
See the :variable:`CMAKE_GENERATOR_TOOLSET` variable for details.
diff --git a/Help/generator/Visual Studio 10 2010.rst b/Help/generator/Visual Studio 10 2010.rst
index 04eef1039..4bf9a8f15 100644
--- a/Help/generator/Visual Studio 10 2010.rst
+++ b/Help/generator/Visual Studio 10 2010.rst
@@ -3,11 +3,31 @@ 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 (architecture).
+For compatibility with CMake versions prior to 3.0, one may specify this
+generator using the name ``Visual Studio 10`` without the year component.
+
+Project Types
+^^^^^^^^^^^^^
+
+Only Visual C++ and C# projects may be generated. Other types of
+projects (Database, Website, etc.) are not supported.
+
+Platform Selection
+^^^^^^^^^^^^^^^^^^
+
+The default target platform name (architecture) is ``Win32``.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps
+via the :manual:`cmake(1)` ``-A`` option, to specify a target platform
+name (architecture). For example:
+
+* ``cmake -G "Visual Studio 10 2010" -A Win32``
+* ``cmake -G "Visual Studio 10 2010" -A x64``
+* ``cmake -G "Visual Studio 10 2010" -A Itanium``
For compatibility with CMake versions prior to 3.1, one may specify
-a target platform name optionally at the end of this generator name:
+a target platform name optionally at the end of the generator name.
+This is supported only for:
``Visual Studio 10 2010 Win64``
Specify target platform ``x64``.
@@ -15,9 +35,6 @@ a target platform name optionally at the end of this generator name:
``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.
-
Toolset Selection
^^^^^^^^^^^^^^^^^
diff --git a/Help/generator/Visual Studio 11 2012.rst b/Help/generator/Visual Studio 11 2012.rst
index 347a153b9..5d89a6e7c 100644
--- a/Help/generator/Visual Studio 11 2012.rst
+++ b/Help/generator/Visual Studio 11 2012.rst
@@ -3,11 +3,33 @@ 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 (architecture).
+For compatibility with CMake versions prior to 3.0, one may specify this
+generator using the name "Visual Studio 11" without the year component.
+
+Project Types
+^^^^^^^^^^^^^
+
+Only Visual C++ and C# projects may be generated. Other types of
+projects (JavaScript, Database, Website, etc.) are not supported.
+
+Platform Selection
+^^^^^^^^^^^^^^^^^^
+
+The default target platform name (architecture) is ``Win32``.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps
+via the :manual:`cmake(1)` ``-A`` option, to specify a target platform
+name (architecture). For example:
+
+* ``cmake -G "Visual Studio 11 2012" -A Win32``
+* ``cmake -G "Visual Studio 11 2012" -A x64``
+* ``cmake -G "Visual Studio 11 2012" -A ARM``
+* ``cmake -G "Visual Studio 11 2012" -A <WinCE-SDK>``
+ (Specify a target platform matching a Windows CE SDK 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:
+a target platform name optionally at the end of the generator name.
+This is supported only for:
``Visual Studio 11 2012 Win64``
Specify target platform ``x64``.
@@ -18,9 +40,6 @@ a target platform name optionally at the end of this generator name:
``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.
-
Toolset Selection
^^^^^^^^^^^^^^^^^
diff --git a/Help/generator/Visual Studio 12 2013.rst b/Help/generator/Visual Studio 12 2013.rst
index 5071b20ce..fb8e021bc 100644
--- a/Help/generator/Visual Studio 12 2013.rst
+++ b/Help/generator/Visual Studio 12 2013.rst
@@ -3,11 +3,31 @@ 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 (architecture).
+For compatibility with CMake versions prior to 3.0, one may specify this
+generator using the name "Visual Studio 12" without the year component.
+
+Project Types
+^^^^^^^^^^^^^
+
+Only Visual C++ and C# projects may be generated. Other types of
+projects (JavaScript, Powershell, Python, etc.) are not supported.
+
+Platform Selection
+^^^^^^^^^^^^^^^^^^
+
+The default target platform name (architecture) is ``Win32``.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps
+via the :manual:`cmake(1)` ``-A`` option, to specify a target platform
+name (architecture). For example:
+
+* ``cmake -G "Visual Studio 12 2013" -A Win32``
+* ``cmake -G "Visual Studio 12 2013" -A x64``
+* ``cmake -G "Visual Studio 12 2013" -A ARM``
For compatibility with CMake versions prior to 3.1, one may specify
-a target platform name optionally at the end of this generator name:
+a target platform name optionally at the end of the generator name.
+This is supported only for:
``Visual Studio 12 2013 Win64``
Specify target platform ``x64``.
@@ -15,9 +35,6 @@ a target platform name optionally at the end of this generator name:
``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.
-
Toolset Selection
^^^^^^^^^^^^^^^^^
@@ -25,4 +42,7 @@ The ``v120`` toolset that comes with Visual Studio 12 2013 is selected by
default. The :variable:`CMAKE_GENERATOR_TOOLSET` option may be set, perhaps
via the :manual:`cmake(1)` ``-T`` option, to specify another toolset.
+.. |VS_TOOLSET_HOST_ARCH_DEFAULT| replace::
+ By default this generator uses the 32-bit variant even on a 64-bit host.
+
.. include:: VS_TOOLSET_HOST_ARCH.txt
diff --git a/Help/generator/Visual Studio 14 2015.rst b/Help/generator/Visual Studio 14 2015.rst
index 64254b579..7383f7a6f 100644
--- a/Help/generator/Visual Studio 14 2015.rst
+++ b/Help/generator/Visual Studio 14 2015.rst
@@ -3,11 +3,28 @@ Visual Studio 14 2015
Generates Visual Studio 14 (VS 2015) project files.
-The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
-to specify a target platform name (architecture).
+Project Types
+^^^^^^^^^^^^^
+
+Only Visual C++ and C# projects may be generated. Other types of
+projects (JavaScript, Powershell, Python, etc.) are not supported.
+
+Platform Selection
+^^^^^^^^^^^^^^^^^^
+
+The default target platform name (architecture) is ``Win32``.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps
+via the :manual:`cmake(1)` ``-A`` option, to specify a target platform
+name (architecture). For example:
+
+* ``cmake -G "Visual Studio 14 2015" -A Win32``
+* ``cmake -G "Visual Studio 14 2015" -A x64``
+* ``cmake -G "Visual Studio 14 2015" -A ARM``
For compatibility with CMake versions prior to 3.1, one may specify
-a target platform name optionally at the end of this generator name:
+a target platform name optionally at the end of the generator name.
+This is supported only for:
``Visual Studio 14 2015 Win64``
Specify target platform ``x64``.
@@ -22,4 +39,7 @@ The ``v140`` toolset that comes with Visual Studio 14 2015 is selected by
default. The :variable:`CMAKE_GENERATOR_TOOLSET` option may be set, perhaps
via the :manual:`cmake(1)` ``-T`` option, to specify another toolset.
+.. |VS_TOOLSET_HOST_ARCH_DEFAULT| replace::
+ By default this generator uses the 32-bit variant even on a 64-bit host.
+
.. include:: VS_TOOLSET_HOST_ARCH.txt
diff --git a/Help/generator/Visual Studio 15 2017.rst b/Help/generator/Visual Studio 15 2017.rst
index 2ac044968..7e6f0fb20 100644
--- a/Help/generator/Visual Studio 15 2017.rst
+++ b/Help/generator/Visual Studio 15 2017.rst
@@ -3,11 +3,45 @@ Visual Studio 15 2017
Generates Visual Studio 15 (VS 2017) project files.
-The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set
-to specify a target platform name (architecture).
+Project Types
+^^^^^^^^^^^^^
+
+Only Visual C++ and C# projects may be generated. Other types of
+projects (JavaScript, Powershell, Python, etc.) are not supported.
+
+Instance Selection
+^^^^^^^^^^^^^^^^^^
+
+VS 2017 supports multiple installations on the same machine.
+The :variable:`CMAKE_GENERATOR_INSTANCE` variable may be set as a
+cache entry containing the absolute path to a Visual Studio instance.
+If the value is not specified explicitly by the user or a toolchain file,
+CMake queries the Visual Studio Installer to locate VS instances, chooses
+one, and sets the variable as a cache entry to hold the value persistently.
+
+When CMake first chooses an instance, if the ``VS150COMNTOOLS`` environment
+variable is set and points to the ``Common7/Tools`` directory within
+one of the instances, that instance will be used. Otherwise, if more
+than one instance is installed we do not define which one is chosen
+by default.
+
+Platform Selection
+^^^^^^^^^^^^^^^^^^
+
+The default target platform name (architecture) is ``Win32``.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps
+via the :manual:`cmake(1)` ``-A`` option, to specify a target platform
+name (architecture). For example:
+
+* ``cmake -G "Visual Studio 15 2017" -A Win32``
+* ``cmake -G "Visual Studio 15 2017" -A x64``
+* ``cmake -G "Visual Studio 15 2017" -A ARM``
+* ``cmake -G "Visual Studio 15 2017" -A ARM64``
For compatibility with CMake versions prior to 3.1, one may specify
-a target platform name optionally at the end of this generator name:
+a target platform name optionally at the end of the generator name.
+This is supported only for:
``Visual Studio 15 2017 Win64``
Specify target platform ``x64``.
@@ -15,18 +49,6 @@ a target platform name optionally at the end of this generator name:
``Visual Studio 15 2017 ARM``
Specify target platform ``ARM``.
-Instance Selection
-^^^^^^^^^^^^^^^^^^
-
-VS 2017 supports multiple installations on the same machine.
-CMake queries the Visual Studio Installer to locate VS instances.
-If more than one instance is installed we do not define which one
-is chosen by default. If the ``VS150COMNTOOLS`` environment variable
-is set and points to the ``Common7/Tools`` directory within one of
-the instances, that instance will be used. The environment variable
-must remain consistently set whenever CMake is re-run within a given
-build tree.
-
Toolset Selection
^^^^^^^^^^^^^^^^^
@@ -34,4 +56,7 @@ The ``v141`` toolset that comes with Visual Studio 15 2017 is selected by
default. The :variable:`CMAKE_GENERATOR_TOOLSET` option may be set, perhaps
via the :manual:`cmake(1)` ``-T`` option, to specify another toolset.
+.. |VS_TOOLSET_HOST_ARCH_DEFAULT| replace::
+ By default this generator uses the 32-bit variant even on a 64-bit host.
+
.. include:: VS_TOOLSET_HOST_ARCH.txt
diff --git a/Help/generator/Visual Studio 8 2005.rst b/Help/generator/Visual Studio 8 2005.rst
index acbbf01ae..947e7a597 100644
--- a/Help/generator/Visual Studio 8 2005.rst
+++ b/Help/generator/Visual Studio 8 2005.rst
@@ -1,23 +1,6 @@
Visual Studio 8 2005
--------------------
-Deprecated. Generates Visual Studio 8 2005 project files.
-
-.. note::
- This generator is deprecated and will be removed in a future version
- of CMake. It will still be possible to build with VS 8 2005 tools
- using the :generator:`Visual Studio 10 2010` (or above) generator
- with :variable:`CMAKE_GENERATOR_TOOLSET` set to ``v80``, or by
- using the :generator:`NMake Makefiles` generator.
-
-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.
+Removed. This once generated Visual Studio 8 2005 project files, but
+the generator has been removed since CMake 3.12. It is still possible to
+build with VS 2005 tools using the :generator:`NMake Makefiles` generator.
diff --git a/Help/generator/Visual Studio 9 2008.rst b/Help/generator/Visual Studio 9 2008.rst
index 40471b92e..a09d047ae 100644
--- a/Help/generator/Visual Studio 9 2008.rst
+++ b/Help/generator/Visual Studio 9 2008.rst
@@ -3,11 +3,24 @@ 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.
+Platform Selection
+^^^^^^^^^^^^^^^^^^
+
+The default target platform name (architecture) is ``Win32``.
+
+The :variable:`CMAKE_GENERATOR_PLATFORM` variable may be set, perhaps
+via the :manual:`cmake(1)` ``-A`` option, to specify a target platform
+name (architecture). For example:
+
+* ``cmake -G "Visual Studio 9 2008" -A Win32``
+* ``cmake -G "Visual Studio 9 2008" -A x64``
+* ``cmake -G "Visual Studio 9 2008" -A Itanium``
+* ``cmake -G "Visual Studio 9 2008" -A <WinCE-SDK>``
+ (Specify a target platform matching a Windows CE SDK 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:
+a target platform name optionally at the end of the generator name.
+This is supported only for:
``Visual Studio 9 2008 Win64``
Specify target platform ``x64``.
diff --git a/Help/generator/Xcode.rst b/Help/generator/Xcode.rst
index 968c26a70..d893ac504 100644
--- a/Help/generator/Xcode.rst
+++ b/Help/generator/Xcode.rst
@@ -3,7 +3,7 @@ Xcode
Generate Xcode project files.
-This supports Xcode 3.0 and above.
+This supports Xcode 5.0 and above.
Toolset Selection
^^^^^^^^^^^^^^^^^
diff --git a/Help/index.rst b/Help/index.rst
index 97cd1073b..a94893972 100644
--- a/Help/index.rst
+++ b/Help/index.rst
@@ -29,17 +29,20 @@ Reference Manuals
/manual/cmake-commands.7
/manual/cmake-compile-features.7
/manual/cmake-developer.7
+ /manual/cmake-env-variables.7
+ /manual/cmake-file-api.7
/manual/cmake-generator-expressions.7
/manual/cmake-generators.7
/manual/cmake-language.7
- /manual/cmake-server.7
/manual/cmake-modules.7
/manual/cmake-packages.7
/manual/cmake-policies.7
/manual/cmake-properties.7
/manual/cmake-qt.7
+ /manual/cmake-server.7
/manual/cmake-toolchains.7
/manual/cmake-variables.7
+ /manual/cpack-generators.7
.. only:: html or text
diff --git a/Help/manual/LINKS.txt b/Help/manual/LINKS.txt
index 3993ff83d..60a260c10 100644
--- a/Help/manual/LINKS.txt
+++ b/Help/manual/LINKS.txt
@@ -5,20 +5,16 @@ Home Page
The primary starting point for learning about CMake.
-Frequently Asked Questions
- https://cmake.org/Wiki/CMake_FAQ
-
- A Wiki is provided containing answers to frequently asked questions.
-
-Online Documentation
+Online Documentation and Community Resources
https://cmake.org/documentation
- Links to available documentation may be found on this web page.
+ Links to available documentation and community resources may be
+ found on this web page.
Mailing List
https://cmake.org/mailing-lists
- For help and discussion about using cmake, a mailing list is
+ 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 https://cmake.org before posting questions to
diff --git a/Help/manual/OPTIONS_BUILD.txt b/Help/manual/OPTIONS_BUILD.txt
index e8b87c923..810aaa914 100644
--- a/Help/manual/OPTIONS_BUILD.txt
+++ b/Help/manual/OPTIONS_BUILD.txt
@@ -1,23 +1,31 @@
+``-S <path-to-source>``
+ Path to root directory of the CMake project to build.
+
+``-B <path-to-build>``
+ Path to directory which CMake will use as the root of build directory.
+
+ If the directory doesn't already exist CMake will make it.
+
``-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
+ 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
+ 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
+ containing :command:`set` commands that use the ``CACHE`` option, not a
cache-format file.
``-D <var>:<type>=<value>, -D <var>=<value>``
- Create a cmake cache entry.
+ Create or update 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
+ 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.
+ repeated for as many ``CACHE`` entries as desired.
If the ``:<type>`` portion is given it must be one of the types
specified by the :command:`set` command documentation for its
@@ -31,14 +39,14 @@
``-D<var>:<type>=<value>`` or ``-D<var>=<value>``.
``-U <globbing_expr>``
- Remove matching entries from CMake cache.
+ 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
+ ``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.
+ Use with care, you can make your ``CMakeCache.txt`` non-working.
``-G <generator-name>``
Specify a build system generator.
@@ -48,6 +56,9 @@
build system. Possible generator names are specified in the
:manual:`cmake-generators(7)` manual.
+ If not specified, CMake checks the :envvar:`CMAKE_GENERATOR` environment
+ variable and otherwise falls back to a builtin default selection.
+
``-T <toolset-spec>``
Toolset specification for the generator, if supported.
@@ -66,47 +77,47 @@
Suppress developer warnings.
Suppress warnings that are meant for the author of the
- CMakeLists.txt files. By default this will also turn off
+ ``CMakeLists.txt`` files. By default this will also turn off
deprecation warnings.
``-Wdev``
Enable developer warnings.
- Enable warnings that are meant for the author of the CMakeLists.txt
+ Enable warnings that are meant for the author of the ``CMakeLists.txt``
files. By default this will also turn on deprecation warnings.
``-Werror=dev``
Make developer warnings errors.
- Make warnings that are meant for the author of the CMakeLists.txt files
+ Make warnings that are meant for the author of the ``CMakeLists.txt`` files
errors. By default this will also turn on deprecated warnings as errors.
``-Wno-error=dev``
Make developer warnings not errors.
- Make warnings that are meant for the author of the CMakeLists.txt files not
+ Make warnings that are meant for the author of the ``CMakeLists.txt`` files not
errors. By default this will also turn off deprecated warnings as errors.
``-Wdeprecated``
Enable deprecated functionality warnings.
Enable warnings for usage of deprecated functionality, that are meant
- for the author of the CMakeLists.txt files.
+ for the author of the ``CMakeLists.txt`` files.
``-Wno-deprecated``
Suppress deprecated functionality warnings.
Suppress warnings for usage of deprecated functionality, that are meant
- for the author of the CMakeLists.txt files.
+ for the author of the ``CMakeLists.txt`` files.
``-Werror=deprecated``
Make deprecated macro and function warnings errors.
Make warnings for usage of deprecated macros and functions, that are meant
- for the author of the CMakeLists.txt files, errors.
+ for the author of the ``CMakeLists.txt`` files, errors.
``-Wno-error=deprecated``
Make deprecated macro and function warnings not errors.
Make warnings for usage of deprecated macros and functions, that are meant
- for the author of the CMakeLists.txt files, not errors.
+ for the author of the ``CMakeLists.txt`` files, not errors.
diff --git a/Help/manual/ccmake.1.rst b/Help/manual/ccmake.1.rst
index a5fe19168..60d45a35d 100644
--- a/Help/manual/ccmake.1.rst
+++ b/Help/manual/ccmake.1.rst
@@ -8,19 +8,19 @@ Synopsis
.. parsed-literal::
- ccmake [<options>] (<path-to-source> | <path-to-existing-build>)
+ ccmake [<options>] {<path-to-source> | <path-to-existing-build>}
Description
===========
-The "ccmake" executable is the CMake curses interface. Project
+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.
+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.
diff --git a/Help/manual/cmake-buildsystem.7.rst b/Help/manual/cmake-buildsystem.7.rst
index 95f5b8735..8cd6e681f 100644
--- a/Help/manual/cmake-buildsystem.7.rst
+++ b/Help/manual/cmake-buildsystem.7.rst
@@ -21,7 +21,7 @@ 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.
+appropriate :prop_tgt:`PREFIX`, :prop_tgt:`SUFFIX` and extensions for the platform targeted.
Dependencies between binary targets are expressed using the
:command:`target_link_libraries` command:
@@ -31,7 +31,7 @@ Dependencies between binary targets are expressed using the
add_executable(zipapp zipapp.cpp)
target_link_libraries(zipapp archive)
-``archive`` is defined as a static library -- an archive containing objects
+``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
@@ -59,7 +59,7 @@ Binary Library Types
Normal Libraries
^^^^^^^^^^^^^^^^
-By default, the :command:`add_library` command defines a static library,
+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
@@ -95,7 +95,7 @@ Apple Frameworks
""""""""""""""""
A ``SHARED`` library may be marked with the :prop_tgt:`FRAMEWORK`
-target property to create an OS X or iOS Framework Bundle.
+target property to create an macOS or iOS Framework Bundle.
The ``MACOSX_FRAMEWORK_IDENTIFIER`` sets ``CFBundleIdentifier`` key
and it uniquely identifies the bundle.
@@ -113,9 +113,9 @@ and it uniquely identifies the bundle.
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:
+The ``OBJECT`` library type defines a non-archival collection of object files
+resulting from compiling the given source files. The object files collection
+may be used as source inputs to other targets:
.. code-block:: cmake
@@ -125,22 +125,31 @@ The object files collection can be used as source inputs to other targets:
add_executable(test_exe $<TARGET_OBJECTS:archive> test.cpp)
-``OBJECT`` libraries may not be 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. They
-may be installed, and will be exported as an INTERFACE library.
+The link (or archiving) step of those other targets will use the object
+files collection in addition to those from their own sources.
-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>``.
+Alternatively, object libraries may be linked into other targets:
-Although object libraries may not be used as the ``TARGET``
-in a use of the :command:`add_custom_command(TARGET)` command signature,
-the list of objects can be used by :command:`add_custom_command(OUTPUT)` or
-:command:`file(GENERATE)` by using ``$<TARGET_OBJECTS:objlib>``.
+.. code-block:: cmake
+
+ add_library(archive OBJECT archive.cpp zip.cpp lzma.cpp)
+
+ add_library(archiveExtras STATIC extras.cpp)
+ target_link_libraries(archiveExtras PUBLIC archive)
+
+ add_executable(test_exe test.cpp)
+ target_link_libraries(test_exe archive)
+
+The link (or archiving) step of those other targets will use the object
+files from ``OBJECT`` libraries that are *directly* linked. Additionally,
+usage requirements of the ``OBJECT`` libraries will be honored when compiling
+sources in those other targets. Furthermore, those usage requirements
+will propagate transitively to dependents of those other targets.
+Object libraries may not be used as the ``TARGET`` in a use of the
+:command:`add_custom_command(TARGET)` command signature. However,
+the list of objects can be used by :command:`add_custom_command(OUTPUT)`
+or :command:`file(GENERATE)` by using ``$<TARGET_OBJECTS:objlib>``.
Build Specification and Usage Requirements
==========================================
@@ -266,7 +275,7 @@ The :command:`target_link_libraries` command has ``PRIVATE``,
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
+``serialization`` is a ``PRIVATE`` dependency of ``archiveExtras``, the usage
requirements of it are not propagated to ``consumer``.
Generally, a dependency should be specified in a use of
@@ -356,8 +365,8 @@ non-compatible requirements :manual:`cmake(1)` issues a diagnostic:
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
+"compatible" with the :prop_tgt:`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.
@@ -538,10 +547,10 @@ is not known until build-time. Therefore, code such as
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.
+may appear to work for :ref:`Makefile Generators` and :generator:`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
@@ -687,9 +696,10 @@ 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.
+be controlled by setting the :prop_tgt:`NO_SYSTEM_FROM_IMPORTED` target
+property on the *consumers* of imported targets.
-If a binary target is linked transitively to a Mac OX framework, the
+If a binary target is linked transitively to a macOS :prop_tgt:`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.
@@ -774,7 +784,7 @@ A *library* output artifact of a buildsystem target may be:
with the ``MODULE`` option.
* On non-DLL platforms: the shared library file (e.g. ``.so`` or ``.dylib``)
- of a shared shared library target created by the :command:`add_library`
+ of a shared library target created by the :command:`add_library`
command with the ``SHARED`` option.
The :prop_tgt:`LIBRARY_OUTPUT_DIRECTORY` and :prop_tgt:`LIBRARY_OUTPUT_NAME`
@@ -811,7 +821,7 @@ 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`,
+target at a time. The commands :command:`add_compile_definitions`,
:command:`add_compile_options` and :command:`include_directories` have
a similar function, but operate at directory scope instead of target
scope for convenience.
@@ -830,12 +840,11 @@ 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.
+immutable. After declaring an :prop_tgt:`IMPORTED` target one can adjust its
+target properties by using the customary commands such as
+:command:`target_compile_definitions`, :command:`target_include_directories`,
+:command:`target_compile_options` or :command:`target_link_libraries` just like
+with any other regular target.
:prop_tgt:`IMPORTED` targets may have the same usage requirement properties
populated as binary targets, such as
@@ -968,9 +977,10 @@ are:
* Properties matching ``INTERFACE_*``
* Built-in properties matching ``COMPATIBLE_INTERFACE_*``
* ``EXPORT_NAME``
+* ``EXPORT_PROPERTIES``
* ``IMPORTED``
+* ``MANUALLY_ADDED_DEPENDENCIES``
* ``NAME``
-* ``NO_SYSTEM_FROM_IMPORTED``
* Properties matching ``IMPORTED_LIBNAME_*``
* Properties matching ``MAP_IMPORTED_CONFIG_*``
diff --git a/Help/manual/cmake-commands.7.rst b/Help/manual/cmake-commands.7.rst
index 611c989a0..a3bc46519 100644
--- a/Help/manual/cmake-commands.7.rst
+++ b/Help/manual/cmake-commands.7.rst
@@ -22,8 +22,8 @@ These commands are always available.
/command/cmake_policy
/command/configure_file
/command/continue
- /command/elseif
/command/else
+ /command/elseif
/command/endforeach
/command/endfunction
/command/endif
@@ -44,6 +44,7 @@ These commands are always available.
/command/get_property
/command/if
/command/include
+ /command/include_guard
/command/list
/command/macro
/command/mark_as_advanced
@@ -52,9 +53,9 @@ These commands are always available.
/command/option
/command/return
/command/separate_arguments
+ /command/set
/command/set_directory_properties
/command/set_property
- /command/set
/command/site_name
/command/string
/command/unset
@@ -69,6 +70,7 @@ These commands are available only in CMake projects.
.. toctree::
:maxdepth: 1
+ /command/add_compile_definitions
/command/add_compile_options
/command/add_custom_command
/command/add_custom_target
@@ -76,6 +78,7 @@ These commands are available only in CMake projects.
/command/add_dependencies
/command/add_executable
/command/add_library
+ /command/add_link_options
/command/add_subdirectory
/command/add_test
/command/aux_source_directory
@@ -97,8 +100,6 @@ These commands are available only in CMake projects.
/command/link_libraries
/command/load_cache
/command/project
- /command/qt_wrap_cpp
- /command/qt_wrap_ui
/command/remove_definitions
/command/set_source_files_properties
/command/set_target_properties
@@ -108,7 +109,9 @@ These commands are available only in CMake projects.
/command/target_compile_features
/command/target_compile_options
/command/target_include_directories
+ /command/target_link_directories
/command/target_link_libraries
+ /command/target_link_options
/command/target_sources
/command/try_compile
/command/try_run
@@ -140,8 +143,10 @@ These commands are available only in CTest scripts.
Deprecated Commands
===================
-These commands are available only for compatibility with older
-versions of CMake. Do not use them in new code.
+These commands are deprecated and are only made available to maintain
+backward compatibility. The documentation of each command states the
+CMake version in which it was deprecated. Do not use these commands
+in new code.
.. toctree::
:maxdepth: 1
@@ -155,6 +160,8 @@ versions of CMake. Do not use them in new code.
/command/load_command
/command/make_directory
/command/output_required_files
+ /command/qt_wrap_cpp
+ /command/qt_wrap_ui
/command/remove
/command/subdir_depends
/command/subdirs
diff --git a/Help/manual/cmake-compile-features.7.rst b/Help/manual/cmake-compile-features.7.rst
index 012439500..658694a9d 100644
--- a/Help/manual/cmake-compile-features.7.rst
+++ b/Help/manual/cmake-compile-features.7.rst
@@ -331,11 +331,11 @@ and :prop_gbl:`compile features <CMAKE_CXX_KNOWN_FEATURES>` available from
the following :variable:`compiler ids <CMAKE_<LANG>_COMPILER_ID>` as of the
versions specified for each:
-* ``AppleClang``: Apple Clang for Xcode versions 4.4 though 6.2.
-* ``Clang``: Clang compiler versions 2.9 through 3.4.
-* ``GNU``: GNU compiler versions 4.4 through 5.0.
+* ``AppleClang``: Apple Clang for Xcode versions 4.4 though 9.2.
+* ``Clang``: Clang compiler versions 2.9 through 6.0.
+* ``GNU``: GNU compiler versions 4.4 through 8.0.
* ``MSVC``: Microsoft Visual Studio versions 2010 through 2017.
-* ``SunPro``: Oracle SolarisStudio versions 12.4 through 12.5.
+* ``SunPro``: Oracle SolarisStudio versions 12.4 through 12.6.
* ``Intel``: Intel compiler versions 12.1 through 17.0.
CMake is currently aware of the :prop_tgt:`C standards <C_STANDARD>`
@@ -344,7 +344,7 @@ the following :variable:`compiler ids <CMAKE_<LANG>_COMPILER_ID>` as of the
versions specified for each:
* all compilers and versions listed above for C++.
-* ``GNU``: GNU compiler versions 3.4 through 5.0.
+* ``GNU``: GNU compiler versions 3.4 through 8.0.
CMake is currently aware of the :prop_tgt:`C++ standards <CXX_STANDARD>` and
their associated meta-features (e.g. ``cxx_std_11``) available from the
@@ -361,9 +361,10 @@ following :variable:`compiler ids <CMAKE_<LANG>_COMPILER_ID>` as of the
versions specified for each:
* all compilers and versions listed above with only meta-features for C++.
+* ``TI``: Texas Instruments compiler.
CMake is currently aware of the :prop_tgt:`CUDA standards <CUDA_STANDARD>`
from the following :variable:`compiler ids <CMAKE_<LANG>_COMPILER_ID>` as of the
versions specified for each:
-* ``NVIDIA``: NVIDIA nvcc compiler 7.5 though 8.0.
+* ``NVIDIA``: NVIDIA nvcc compiler 7.5 though 9.1.
diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst
index cd509ac20..85ed935e6 100644
--- a/Help/manual/cmake-developer.7.rst
+++ b/Help/manual/cmake-developer.7.rst
@@ -10,580 +10,24 @@ cmake-developer(7)
Introduction
============
-This manual is intended for reference by developers modifying the CMake
-source tree itself, and by those authoring externally-maintained modules.
-
-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. Ensure that the ``CMAKE_<LANG>_STANDARD_DEFAULT`` is set to
-the computed internal variable ``CMAKE_<LANG>_STANDARD_COMPUTED_DEFAULT``
-for compiler versions which should be supported.
-
-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.
+This manual is intended for reference by developers working with
+:manual:`cmake-language(7)` code, whether writing their own modules,
+authoring their own build systems, or working on CMake itself.
-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:``.
-At the top of ``Modules/<module-name>.cmake``, begin with the following
-license notice:
-
-.. code-block:: cmake
-
- # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- # file Copyright.txt or https://cmake.org/licensing for details.
-
-After this notice, add a *BLANK* line. Then, add documentation using
-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:
-
-::
-
- #[[.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:
-
-::
-
- # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- # file Copyright.txt or https://cmake.org/licensing for details.
-
- #.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()
-
-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.
+See https://cmake.org/get-involved/ to get involved in development of
+CMake upstream. It includes links to contribution instructions, which
+in turn link to developer guides for CMake itself.
.. _`Find Modules`:
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>``.
+A "find module" is a ``Find<PackageName>.cmake`` file to be loaded
+by the :command:`find_package` command when invoked for ``<PackageName>``.
The primary task of a find module is to determine whether a package
-exists on the system, set the ``<package>_FOUND`` variable to reflect
+exists on the system, set the ``<PackageName>_FOUND`` variable to reflect
this and provide any variables, macros and imported targets required to
use the package. A find module is useful in cases where an upstream
library does not provide a
@@ -638,14 +82,11 @@ 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.
-
+.. _`CMake Developer Standard Variable Names`:
Standard Variable Names
-^^^^^^^^^^^^^^^^^^^^^^^
+-----------------------
For a ``FindXxx.cmake`` module that takes the approach of setting
variables (either instead of or in addition to creating imported
@@ -752,54 +193,81 @@ 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``.
+We will describe how to create a simple find module for a library ``Foo``.
-The first thing that is needed is a license notice.
+The top of the module should begin with a license notice, followed by
+a blank line, and then followed by a :ref:`Bracket Comment`. The comment
+should begin with ``.rst:`` to indicate that the rest of its content is
+reStructuredText-format documentation. For example:
-.. code-block:: cmake
+::
- # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- # file Copyright.txt or https://cmake.org/licensing for details.
+ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+ # file Copyright.txt or https://cmake.org/licensing for details.
-Next we need module documentation. CMake's documentation system requires you
-to follow the license notice with a blank line and then with a documentation
-marker and the name of the module. You should follow this with a simple
-statement of what the module does.
+ #[=======================================================================[.rst:
+ FindFoo
+ -------
-.. code-block:: cmake
+ Finds the Foo library.
- #.rst:
- # FindFoo
- # -------
- #
- # Finds the Foo library
- #
+ Imported Targets
+ ^^^^^^^^^^^^^^^^
-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
+ This module provides the following imported targets, if found:
-.. code-block:: cmake
+ ``Foo::Foo``
+ The Foo library
+
+ Result Variables
+ ^^^^^^^^^^^^^^^^
+
+ 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.
+ ``Foo_INCLUDE_DIRS``
+ Include directories needed to use Foo.
+ ``Foo_LIBRARIES``
+ Libraries needed to link to Foo.
+
+ Cache Variables
+ ^^^^^^^^^^^^^^^
+
+ The following cache variables may also be set:
+
+ ``Foo_INCLUDE_DIR``
+ The directory containing ``foo.h``.
+ ``Foo_LIBRARY``
+ The path to the Foo library.
+
+ #]=======================================================================]
+
+The module documentation consists of:
+
+* An underlined heading specifying the module name.
+
+* A simple description of what the module finds.
+ More description may be required for some packages. If there are
+ caveats or other details users of the module should be aware of,
+ specify them here.
+
+* A section listing imported targets provided by the module, if any.
+
+* A section listing result variables provided by the module.
- # 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
+* Optionally a section listing cache variables used by the module, if any.
-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.
+If the package provides any macros or functions, they should be listed in
+an additional section, but can be documented by additional ``.rst:``
+comment blocks immediately above where those macros or functions are defined.
+The find module implementation may begin below the documentation block.
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.
@@ -943,7 +411,7 @@ populated:
endif()
The ``RELEASE`` variant should be listed first in the property
-so that that variant is chosen if the user uses a configuration which is
+so that the variant is chosen if the user uses a configuration which is
not an exact match for any listed ``IMPORTED_CONFIGURATIONS``.
Most of the cache variables should be hidden in the ``ccmake`` interface unless
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst
index bddb17477..e970379fa 100644
--- a/Help/manual/cmake-generator-expressions.7.rst
+++ b/Help/manual/cmake-generator-expressions.7.rst
@@ -20,54 +20,74 @@ 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.
+They enable conditional linking, conditional definitions used when compiling,
+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
-===================
+Generator expressions have the form ``$<...>``. To avoid confusion, this page
+deviates from most of the CMake documentation in that it omits angular brackets
+``<...>`` around placeholders like ``condition``, ``string``, ``target``,
+among others.
-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::
+Generator expressions can be nested, as shown in most of the examples below.
- $<$<CONFIG:Debug>:DEBUG_MODE>
+.. _`Boolean Generator Expressions`:
-expands to ``DEBUG_MODE`` when the ``Debug`` configuration is used, and
-otherwise expands to nothing.
-
-Available logical expressions are:
-
-``$<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``
-``$<IF:?,true-value...,false-value...>```
- ``true-value...`` if ``?`` is ``1``, ``false-value...`` if ``?`` is ``0``
-``$<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``.
+Boolean Generator Expressions
+=============================
+
+Boolean expressions evaluate to either ``0`` or ``1``.
+They are typically used to construct the condition in a :ref:`conditional
+generator expression<Conditional Generator Expressions>`.
+
+Available boolean expressions are:
+
+Logical Operators
+-----------------
+
+``$<BOOL:string>``
+ Converts ``string`` to ``0`` or ``1`` according to the rules of the
+ :command:`if()` command. Evaluates to ``0`` if any of the following is true:
+
+ * ``string`` is empty,
+ * ``string`` is a case-insensitive equal of
+ ``0``, ``FALSE``, ``OFF``, ``N``, ``NO``, ``IGNORE``, or ``NOTFOUND``, or
+ * ``string`` ends in the suffix ``-NOTFOUND`` (case-sensitive).
+
+ Otherwise evaluates to ``1``.
+
+``$<AND:conditions>``
+ where ``conditions`` is a comma-separated list of boolean expressions.
+ Evaluates to ``1`` if all conditions are ``1``.
+ Otherwise evaluates to ``0``.
+
+``$<OR:conditions>``
+ where ``conditions`` is a comma-separated list of boolean expressions.
+ Evaluates to ``1`` if at least one of the conditions is ``1``.
+ Otherwise evaluates to ``0``.
+
+``$<NOT:condition>``
+ ``0`` if ``condition`` is ``1``, else ``1``.
+
+String Comparisons
+------------------
+
+``$<STREQUAL:string1,string2>``
+ ``1`` if ``string1`` and ``string2`` are equal, else ``0``.
+ The comparison is case-sensitive. For a case-insensitive comparison,
+ combine with a :ref:`string transforming generator expression
+ <String Transforming Generator Expressions>`,
+
+ .. code-block:: cmake
+
+ $<STREQUAL:$<UPPER_CASE:${foo}>,"BAR"> # "1" if ${foo} is any of "BAR", "Bar", "bar", ...
+
+``$<EQUAL:value1,value2>``
+ ``1`` if ``value1`` and ``value2`` are numerically equal, else ``0``.
+``$<IN_LIST:string,list>``
+ ``1`` if ``string`` is member of the semicolon-separated ``list``, else ``0``.
+ Uses case-sensitive comparisons.
``$<VERSION_LESS:v1,v2>``
``1`` if ``v1`` is a version less than ``v2``, else ``0``.
``$<VERSION_GREATER:v1,v2>``
@@ -78,76 +98,169 @@ Available logical expressions are:
``1`` if ``v1`` is a version less than or equal to ``v2``, else ``0``.
``$<VERSION_GREATER_EQUAL:v1,v2>``
``1`` if ``v1`` is a version greater than or equal to ``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
+
+
+Variable Queries
+----------------
+
+``$<TARGET_EXISTS:target>``
+ ``1`` if ``target`` exists, 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:platform_ids>``
+ where ``platform_ids`` is a comma-separated list.
+ ``1`` if the CMake's platform id matches any one of the entries in
+ ``platform_ids``, otherwise ``0``.
+ See also the :variable:`CMAKE_SYSTEM_NAME` variable.
+``$<C_COMPILER_ID:compiler_ids>``
+ where ``compiler_ids`` is a comma-separated list.
+ ``1`` if the CMake's compiler id of the C compiler matches any one
+ of the entries in ``compiler_ids``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<CXX_COMPILER_ID:compiler_ids>``
+ where ``compiler_ids`` is a comma-separated list.
+ ``1`` if the CMake's compiler id of the CXX compiler matches any one
+ of the entries in ``compiler_ids``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<CUDA_COMPILER_ID:compiler_ids>``
+ where ``compiler_ids`` is a comma-separated list.
+ ``1`` if the CMake's compiler id of the CUDA compiler matches any one
+ of the entries in ``compiler_ids``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<Fortran_COMPILER_ID:compiler_ids>``
+ where ``compiler_ids`` is a comma-separated list.
+ ``1`` if the CMake's compiler id of the Fortran compiler matches any one
+ of the entries in ``compiler_ids``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<C_COMPILER_VERSION:version>``
+ ``1`` if the version of the C compiler matches ``version``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<CXX_COMPILER_VERSION:version>``
+ ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<CUDA_COMPILER_VERSION:version>``
+ ``1`` if the version of the CXX compiler matches ``version``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<Fortran_COMPILER_VERSION:version>``
+ ``1`` if the version of the Fortran compiler matches ``version``, otherwise ``0``.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<TARGET_POLICY:policy>``
+ ``1`` if the ``policy`` 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'
+``$<COMPILE_FEATURES:features>``
+ where ``features`` is a comma-spearated list.
+ Evaluates to ``1`` if all of the ``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 and a list of supported compilers.
-``$<COMPILE_LANGUAGE:lang>``
- ``1`` when the language used for compilation unit matches ``lang``,
- otherwise ``0``. This expression used to specify compile options for
- source files of a particular language in a target. For example, to specify
- the use of the ``-fno-exceptions`` compile option (compiler id checks
- elided):
+
+.. _`Boolean COMPILE_LANGUAGE Generator Expression`:
+
+``$<COMPILE_LANG_AND_ID:language,compiler_ids>``
+ ``1`` when the language used for compilation unit matches ``language`` and
+ the CMake's compiler id of the language compiler matches any one of the
+ entries in ``compiler_ids``, otherwise ``0``. This expression is a short form
+ for the combination of ``$<COMPILE_LANGUAGE:language>`` and
+ ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify
+ compile options, compile definitions, and include directories for source files of a
+ particular language and compiler combination in a target. For example:
.. code-block:: cmake
- add_executable(myapp main.cpp foo.c bar.cpp)
- target_compile_options(myapp
- PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
+ add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
+ target_compile_definitions(myapp
+ PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG>
+ $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL>
+ $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG>
)
- This generator expression has limited use because it is not possible to
- use it with the Visual Studio generators. Portable buildsystems would
- not use this expression, and would create separate libraries for each
- source file language instead:
+ This specifies the use of different compile definitions based on both
+ the compiler id and compilation language. This example will have a
+ ``COMPILING_CXX_WITH_CLANG`` compile definition when Clang is the CXX
+ compiler, and ``COMPILING_CXX_WITH_INTEL`` when Intel is the CXX compiler.
+ Likewise when the C compiler is Clang it will only see the ``COMPILING_C_WITH_CLANG``
+ definition.
+
+ Without the ``COMPILE_LANG_AND_ID`` generator expression the same logic
+ would be expressed as:
.. code-block:: cmake
- add_library(myapp_c foo.c)
- add_library(myapp_cxx bar.cpp)
- target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
- add_executable(myapp main.cpp)
- target_link_libraries(myapp myapp_c myapp_cxx)
+ target_compile_definitions(myapp
+ PRIVATE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:AppleClang,Clang>>:COMPILING_CXX_WITH_CLANG>
+ $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:Intel>>:COMPILING_CXX_WITH_INTEL>
+ $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG>
+ )
- The ``Makefile`` and ``Ninja`` based generators can also use this
- expression to specify compile-language specific compile definitions
- and include directories:
+``$<COMPILE_LANGUAGE:languages>``
+ ``1`` when the language used for compilation unit matches any of the entries
+ in ``languages``, otherwise ``0``. This expression may be used to specify
+ compile options, compile definitions, and include directories for source files of a
+ particular language in a target. For example:
.. code-block:: cmake
- add_executable(myapp main.cpp foo.c bar.cpp)
+ add_executable(myapp main.cpp foo.c bar.cpp zot.cu)
+ target_compile_options(myapp
+ PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
+ )
target_compile_definitions(myapp
PRIVATE $<$<COMPILE_LANGUAGE:CXX>:COMPILING_CXX>
+ $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA>
)
target_include_directories(myapp
- PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/opt/foo/cxx_headers>
+ PRIVATE $<$<COMPILE_LANGUAGE:CXX,CUDA>:/opt/foo/headers>
)
-Informational Expressions
-=========================
+ This specifies the use of the ``-fno-exceptions`` compile option,
+ ``COMPILING_CXX`` compile definition, and ``cxx_headers`` include
+ directory for C++ only (compiler id checks elided). It also specifies
+ a ``COMPILING_CUDA`` compile definition for CUDA.
+
+ Note that with :ref:`Visual Studio Generators` and :generator:`Xcode` there
+ is no way to represent target-wide compile definitions or include directories
+ separately for ``C`` and ``CXX`` languages.
+ Also, with :ref:`Visual Studio Generators` there is no way to represent
+ target-wide flags separately for ``C`` and ``CXX`` languages. Under these
+ generators, expressions for both C and C++ sources will be evaluated
+ using ``CXX`` if there are any C++ sources and otherwise using ``C``.
+ A workaround is to create separate libraries for each source file language
+ instead:
+
+ .. code-block:: cmake
-These expressions expand to some information. The information may be used
-directly, eg::
+ add_library(myapp_c foo.c)
+ add_library(myapp_cxx bar.cpp)
+ target_compile_options(myapp_cxx PUBLIC -fno-exceptions)
+ add_executable(myapp main.cpp)
+ target_link_libraries(myapp myapp_c myapp_cxx)
+
+String-Valued Generator Expressions
+===================================
+
+These expressions expand to some string.
+For example,
+
+.. code-block:: cmake
include_directories(/usr/include/$<CXX_COMPILER_ID>/)
expands to ``/usr/include/GNU/`` or ``/usr/include/Clang/`` etc, depending on
-the Id of the compiler.
+the compiler identifier.
-These expressions may also may be combined with logical expressions::
+String-valued expressions may also be combined with other expressions.
+Here an example for a string-valued expression within a boolean expressions
+within a conditional expression:
+
+.. code-block:: cmake
$<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,4.2.0>:OLD_COMPILER>
@@ -155,20 +268,141 @@ expands to ``OLD_COMPILER`` if the
:variable:`CMAKE_CXX_COMPILER_VERSION <CMAKE_<LANG>_COMPILER_VERSION>` is less
than 4.2.0.
-Available informational expressions are:
+And here two nested string-valued expressions:
+
+.. code-block:: cmake
+
+ -I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>
+
+generates a string of the entries in the :prop_tgt:`INCLUDE_DIRECTORIES` target
+property with each entry preceded by ``-I``.
+
+Expanding on the previous example, if one first wants to check if the
+``INCLUDE_DIRECTORIES`` property is non-empty, then it is advisable to
+introduce a helper variable to keep the code readable:
+
+.. code-block:: cmake
+
+ set(prop "$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>") # helper variable
+ $<$<BOOL:${prop}>:-I$<JOIN:${prop}, -I>>
+
+The following string-valued generator expressions are available:
+
+Escaped Characters
+------------------
+
+String literals to escape the special meaning a character would otherwise have:
+
+``$<ANGLE-R>``
+ A literal ``>``. Used for example to compare strings that contain a ``>``.
+``$<COMMA>``
+ A literal ``,``. Used for example to compare strings which contain a ``,``.
+``$<SEMICOLON>``
+ A literal ``;``. Used to prevent list expansion on an argument with ``;``.
+
+.. _`Conditional Generator Expressions`:
+
+Conditional Expressions
+-----------------------
+
+Conditional generator expressions depend on a boolean condition
+that must be ``0`` or ``1``.
+
+``$<condition:true_string>``
+ Evaluates to ``true_string`` if ``condition`` is ``1``.
+ Otherwise evaluates to the empty string.
+
+``$<IF:condition,true_string,false_string>``
+ Evaluates to ``true_string`` if ``condition`` is ``1``.
+ Otherwise evaluates to ``false_string``.
+
+Typically, the ``condition`` is a :ref:`boolean generator expression
+<Boolean Generator Expressions>`. For instance,
+
+.. code-block:: cmake
+
+ $<$<CONFIG:Debug>:DEBUG_MODE>
+
+expands to ``DEBUG_MODE`` when the ``Debug`` configuration is used, and
+otherwise expands to the empty string.
+
+.. _`String Transforming Generator Expressions`:
+
+String Transformations
+----------------------
+
+``$<JOIN:list,string>``
+ Joins the list with the content of ``string``.
+``$<REMOVE_DUPLICATES:list>``
+ Removes duplicated items in the given ``list``.
+``$<FILTER:list,INCLUDE|EXCLUDE,regex>``
+ Includes or removes items from ``list`` that match the regular expression ``regex``.
+``$<LOWER_CASE:string>``
+ Content of ``string`` converted to lower case.
+``$<UPPER_CASE:string>``
+ Content of ``string`` converted to upper case.
+
+``$<GENEX_EVAL:expr>``
+ Content of ``expr`` evaluated as a generator expression in the current
+ context. This enables consumption of generator expressions whose
+ evaluation results itself in generator expressions.
+``$<TARGET_GENEX_EVAL:tgt,expr>``
+ Content of ``expr`` evaluated as a generator expression in the context of
+ ``tgt`` target. This enables consumption of custom target properties that
+ themselves contain generator expressions.
+
+ Having the capability to evaluate generator expressions is very useful when
+ you want to manage custom properties supporting generator expressions.
+ For example:
+
+ .. code-block:: cmake
+
+ add_library(foo ...)
+
+ set_property(TARGET foo PROPERTY
+ CUSTOM_KEYS $<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>
+ )
+
+ add_custom_target(printFooKeys
+ COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:foo,CUSTOM_KEYS>
+ )
+
+ This naive implementation of the ``printFooKeys`` custom command is wrong
+ because ``CUSTOM_KEYS`` target property is not evaluated and the content
+ is passed as is (i.e. ``$<$<CONFIG:DEBUG>:FOO_EXTRA_THINGS>``).
+
+ To have the expected result (i.e. ``FOO_EXTRA_THINGS`` if config is
+ ``Debug``), it is required to evaluate the output of
+ ``$<TARGET_PROPERTY:foo,CUSTOM_KEYS>``:
+
+ .. code-block:: cmake
+
+ add_custom_target(printFooKeys
+ COMMAND ${CMAKE_COMMAND} -E
+ echo $<TARGET_GENEX_EVAL:foo,$<TARGET_PROPERTY:foo,CUSTOM_KEYS>>
+ )
+
+Variable Queries
+----------------
-``$<CONFIGURATION>``
- Configuration name. Deprecated. Use ``CONFIG`` instead.
``$<CONFIG>``
- Configuration name
+ Configuration name.
+``$<CONFIGURATION>``
+ Configuration name. Deprecated since CMake 3.0. Use ``CONFIG`` instead.
``$<PLATFORM_ID>``
- The CMake-id of the platform.
+ The current system's CMake platform id.
See also the :variable:`CMAKE_SYSTEM_NAME` variable.
``$<C_COMPILER_ID>``
- The CMake-id of the C compiler used.
+ The CMake's compiler 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.
+ The CMake's compiler id of the CXX compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<CUDA_COMPILER_ID>``
+ The CMake's compiler id of the CUDA compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
+``$<Fortran_COMPILER_ID>``
+ The CMake's compiler id of the Fortran compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable.
``$<C_COMPILER_VERSION>``
The version of the C compiler used.
@@ -176,14 +410,105 @@ Available informational expressions are:
``$<CXX_COMPILER_VERSION>``
The version of the CXX compiler used.
See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<CUDA_COMPILER_VERSION>``
+ The version of the CUDA compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<Fortran_COMPILER_VERSION>``
+ The version of the Fortran compiler used.
+ See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` variable.
+``$<COMPILE_LANGUAGE>``
+ The compile language of source files when evaluating compile options.
+ See :ref:`the related boolean expression
+ <Boolean COMPILE_LANGUAGE Generator Expression>`
+ ``$<COMPILE_LANGUAGE:language>``
+ for notes about the portability of this generator expression.
+
+Target-Dependent Queries
+------------------------
+
+``$<TARGET_NAME_IF_EXISTS:tgt>``
+ Expands to the ``tgt`` if the given target exists, an empty string
+ otherwise.
``$<TARGET_FILE:tgt>``
- Full path to main file (.exe, .so.1.2, .a) where ``tgt`` is the name of a target.
+ Full path to main file (.exe, .so.1.2, .a) where ``tgt`` is the name of a
+ target.
+``$<TARGET_FILE_BASE_NAME:tgt>``
+ Base name of main file where ``tgt`` is the name of a target.
+
+ The base name corresponds to the target file name (see
+ ``$<TARGET_FILE_NAME:tgt>``) without prefix and suffix. For example, if
+ target file name is ``libbase.so``, the base name is ``base``.
+
+ See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
+ :prop_tgt:`LIBRARY_OUTPUT_NAME` and :prop_tgt:`RUNTIME_OUTPUT_NAME`
+ target properties and their configuration specific variants
+ :prop_tgt:`OUTPUT_NAME_<CONFIG>`, :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>`,
+ :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>` and
+ :prop_tgt:`RUNTIME_OUTPUT_NAME_<CONFIG>`.
+
+ The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
+ properties can also be considered.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
+``$<TARGET_FILE_PREFIX:tgt>``
+ Prefix of main file where ``tgt`` is the name of a target.
+
+ See also the :prop_tgt:`PREFIX` target property.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
+``$<TARGET_FILE_SUFFIX:tgt>``
+ Suffix of main file where ``tgt`` is the name of a target.
+
+ The suffix corresponds to the file extension (such as ".so" or ".exe").
+
+ See also the :prop_tgt:`SUFFIX` target property.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
``$<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_BASE_NAME:tgt>``
+ Base name of file used to link where ``tgt`` is the name of a target.
+
+ The base name corresponds to the target linker file name (see
+ ``$<TARGET_LINKER_FILE_NAME:tgt>``) without prefix and suffix. For example,
+ if target file name is ``libbase.a``, the base name is ``base``.
+
+ See also the :prop_tgt:`OUTPUT_NAME`, :prop_tgt:`ARCHIVE_OUTPUT_NAME`,
+ and :prop_tgt:`LIBRARY_OUTPUT_NAME` target properties and their configuration
+ specific variants :prop_tgt:`OUTPUT_NAME_<CONFIG>`,
+ :prop_tgt:`ARCHIVE_OUTPUT_NAME_<CONFIG>` and
+ :prop_tgt:`LIBRARY_OUTPUT_NAME_<CONFIG>`.
+
+ The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
+ properties can also be considered.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
+``$<TARGET_LINKER_FILE_PREFIX:tgt>``
+ Prefix of file used to link where ``tgt`` is the name of a target.
+
+ See also the :prop_tgt:`PREFIX` and :prop_tgt:`IMPORT_PREFIX` target
+ properties.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
+``$<TARGET_LINKER_FILE_SUFFIX:tgt>``
+ Suffix of file used to link where ``tgt`` is the name of a target.
+
+ The suffix corresponds to the file extension (such as ".so" or ".lib").
+
+ See also the :prop_tgt:`SUFFIX` and :prop_tgt:`IMPORT_SUFFIX` target
+ properties.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
``$<TARGET_LINKER_FILE_NAME:tgt>``
Name of file used to link (.a, .lib, .so).
``$<TARGET_LINKER_FILE_DIR:tgt>``
@@ -201,6 +526,22 @@ Available informational expressions are:
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_BASE_NAME:tgt>``
+ Base name of the linker generated program database file (.pdb)
+ where ``tgt`` is the name of a target.
+
+ The base name corresponds to the target PDB file name (see
+ ``$<TARGET_PDB_FILE_NAME:tgt>``) without prefix and suffix. For example,
+ if target file name is ``base.pdb``, the base name is ``base``.
+
+ See also the :prop_tgt:`PDB_NAME` target property and its configuration
+ specific variant :prop_tgt:`PDB_NAME_<CONFIG>`.
+
+ The :prop_tgt:`<CONFIG>_POSTFIX` and :prop_tgt:`DEBUG_POSTFIX` target
+ properties can also be considered.
+
+ Note that ``tgt`` is not added as a dependency of the target this
+ expression is evaluated on.
``$<TARGET_PDB_FILE_NAME:tgt>``
Name of the linker generated program database file (.pdb).
``$<TARGET_PDB_FILE_DIR:tgt>``
@@ -221,49 +562,17 @@ Available informational expressions are:
expression is evaluated on.
``$<TARGET_PROPERTY:prop>``
Value of the property ``prop`` on the target on which the generator
- expression is evaluated.
+ expression is evaluated. Note that for generator expressions in
+ :ref:`Target Usage Requirements` this is the value of the property
+ on the consuming target rather than the target specifying the
+ requirement.
``$<INSTALL_PREFIX>``
Content of the install prefix when the target is exported via
:command:`install(EXPORT)` and empty otherwise.
-``$<COMPILE_LANGUAGE>``
- The compile language of source files when evaluating compile options. See
- the unary version for notes about portability of this generator
- expression.
-
-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::
+Output-Related Expressions
+--------------------------
- -I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>
-
-generates a string of the entries in the :prop_tgt:`INCLUDE_DIRECTORIES` target
-property with each entry preceded by ``-I``. Note that a more-complete use
-in this situation would require first checking if the INCLUDE_DIRECTORIES
-property is non-empty::
-
- $<$<BOOL:${prop}>:-I$<JOIN:${prop}, -I>>
-
-where ``${prop}`` refers to a helper variable::
-
- set(prop "$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>")
-
-Available output expressions are:
-
-``$<0:...>``
- Empty string (ignores ``...``)
-``$<1:...>``
- Content of ``...``
-``$<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
@@ -282,16 +591,39 @@ Available output expressions are:
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.
+ Content of ``...`` converted to a C identifier. The conversion follows the
+ same behavior as :command:`string(MAKE_C_IDENTIFIER)`.
``$<TARGET_OBJECTS:objLib>``
- List of objects resulting from build of ``objLib``. ``objLib`` must be an
- object of type ``OBJECT_LIBRARY``.
+ List of objects resulting from build of ``objLib``.
``$<SHELL_PATH:...>``
Content of ``...`` converted to shell path style. For example, slashes are
converted to backslashes in Windows shells and drive letters are converted
to posix paths in MSYS shells. The ``...`` must be an absolute path.
+ The ``...`` may be a :ref:`semicolon-separated list <CMake Language Lists>`
+ of paths, in which case each path is converted individually and a result
+ list is generated using the shell path separator (``:`` on POSIX and
+ ``;`` on Windows). Be sure to enclose the argument containing this genex
+ in double quotes in CMake source code so that ``;`` does not split arguments.
+
+Debugging
+=========
+
+Since generator expressions are evaluated during generation of the buildsystem,
+and not during processing of ``CMakeLists.txt`` files, it is not possible to
+inspect their result with the :command:`message()` command.
+
+One possible way to generate debug messages is to add a custom target,
+
+.. code-block:: cmake
+
+ add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "$<...>")
+
+The shell command ``make genexdebug`` (invoked after execution of ``cmake``)
+would then print the result of ``$<...>``.
+
+Another way is to write debug messages to a file:
+
+.. code-block:: cmake
+
+ file(GENERATE OUTPUT filename CONTENT "$<...>")
diff --git a/Help/manual/cmake-generators.7.rst b/Help/manual/cmake-generators.7.rst
index a37c65b39..41f765220 100644
--- a/Help/manual/cmake-generators.7.rst
+++ b/Help/manual/cmake-generators.7.rst
@@ -27,6 +27,8 @@ when creating a new build tree.
CMake Generators
================
+.. _`Command-Line Build Tool Generators`:
+
Command-Line Build Tool Generators
----------------------------------
@@ -58,6 +60,8 @@ Ninja Generator
/generator/Ninja
+.. _`IDE Build Tool Generators`:
+
IDE Build Tool Generators
-------------------------
@@ -83,6 +87,7 @@ Visual Studio Generators
/generator/Visual Studio 12 2013
/generator/Visual Studio 14 2015
/generator/Visual Studio 15 2017
+ /generator/Visual Studio 16 2019
Other Generators
^^^^^^^^^^^^^^^^
@@ -108,6 +113,5 @@ The following extra generators are known to CMake.
/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
index 032b51fda..ff8311bbe 100644
--- a/Help/manual/cmake-gui.1.rst
+++ b/Help/manual/cmake-gui.1.rst
@@ -9,24 +9,33 @@ Synopsis
.. parsed-literal::
cmake-gui [<options>]
- cmake-gui [<options>] (<path-to-source> | <path-to-existing-build>)
+ cmake-gui [<options>] {<path-to-source> | <path-to-existing-build>}
+ cmake-gui [<options>] -S <path-to-source> -B <path-to-build>
Description
===========
-The "cmake-gui" executable is the CMake GUI. Project configuration
+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.
+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
=======
+``-S <path-to-source>``
+ Path to root directory of the CMake project to build.
+
+``-B <path-to-build>``
+ Path to directory which CMake will use as the root of build directory.
+
+ If the directory doesn't already exist CMake will make it.
+
.. include:: OPTIONS_HELP.txt
See Also
diff --git a/Help/manual/cmake-language.7.rst b/Help/manual/cmake-language.7.rst
index 27b5d30b4..4ca8e3a26 100644
--- a/Help/manual/cmake-language.7.rst
+++ b/Help/manual/cmake-language.7.rst
@@ -183,18 +183,18 @@ 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} ']'
+ bracket_open: '[' '='* '['
+ bracket_content: <any text not containing a `bracket_close` with
+ : the same number of '=' as the `bracket_open`>
+ bracket_close: ']' '='* ']'
.. raw:: latex
\end{small}
-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 ``]``.
+An opening bracket is written ``[`` followed by zero or more ``=`` followed
+by ``[``. The corresponding closing bracket is written ``]`` followed
+by the same number of ``=`` 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.
@@ -206,9 +206,10 @@ 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:
+.. No code-block syntax highlighting in the following example
+ (long string literal not supported by our cmake.py)
-.. code-block:: cmake
+For example::
message([=[
This is the first line in a bracket argument with bracket length 1.
@@ -253,16 +254,22 @@ closing quotes. Both `Escape Sequences`_ and `Variable References`_
are evaluated. A quoted argument is always given to the command
invocation as exactly one argument.
+.. No code-block syntax highlighting in the following example
+ (escape \" not supported by our cmake.py)
+
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.
- ")
+ 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.
+ ")
+
+.. No code-block syntax highlighting in the following example
+ (for conformity with the two above examples)
The final ``\`` on any line ending in an odd number of backslashes
is treated as a line continuation and ignored along with the
@@ -270,11 +277,11 @@ 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.\
- ")
+ 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 ``\``.
@@ -334,6 +341,8 @@ For example:
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.
+ They may instead be written as quoted arguments ``"-Da=\"b c\""``,
+ ``"-Da=$(v)"``, and ``"a\" \"b\"c\"d"``, respectively.
Make-style references are treated literally as part of the content
and do not undergo variable expansion. They are treated as part
@@ -380,7 +389,7 @@ historical considerations.)
Variable References
-------------------
-A *variable reference* has the form ``${variable_name}`` and is
+A *variable reference* has the form ``${<variable>}`` 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.
@@ -389,14 +398,24 @@ 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.)
+may be used to evaluate variables of any name. See also policy
+:policy:`CMP0053` documentation for historical considerations and reasons why
+the ``$`` is also technically permitted but is discouraged.
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.
+An *environment variable reference* has the form ``$ENV{<variable>}``.
+See the `Environment Variables`_ section for more information.
+
+A *cache variable reference* has the form ``$CACHE{<variable>}``.
+See :variable:`CACHE` for more information.
+
+The :command:`if` command has a special condition syntax that
+allows for variable references in the short form ``<variable>``
+instead of ``${<variable>}``.
+However, environment and cache variables always need to be
+referenced as ``$ENV{<variable>}`` or ``$CACHE{<variable>}``.
Comments
--------
@@ -411,7 +430,7 @@ comments: a `Bracket Comment`_ and a `Line Comment`_.
Bracket Comment
^^^^^^^^^^^^^^^
-A ``#`` immediately followed by a `Bracket Argument`_ forms a
+A ``#`` immediately followed by a :token:`bracket_open` forms a
*bracket comment* consisting of the entire bracket enclosure:
.. raw:: latex
@@ -442,7 +461,7 @@ For example:
Line Comment
^^^^^^^^^^^^
-A ``#`` not immediately followed by a `Bracket Argument`_ forms a
+A ``#`` not immediately followed by a :token:`bracket_open` forms a
*line comment* that runs until the end of the line:
.. raw:: latex
@@ -450,7 +469,7 @@ A ``#`` not immediately followed by a `Bracket Argument`_ forms a
\begin{small}
.. productionlist::
- line_comment: '#' <any text not starting in a `bracket_argument`
+ line_comment: '#' <any text not starting in a `bracket_open`
: and not containing a `newline`>
.. raw:: latex
@@ -514,7 +533,7 @@ Function Scope
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.
+ any nested calls within it, but not after the function returns.
Directory Scope
Each of the `Directories`_ in a source tree has its own variable
@@ -541,11 +560,41 @@ to the binding in the current directory scope, if any. If a
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 ``$CACHE{VAR}`` syntax can be used to do direct cache entry
+lookups.
-The :manual:`cmake-variables(7)` manual documents many variables
+The :manual:`cmake-variables(7)` manual documents the many variables
that are provided by CMake or have meaning to CMake when set
by project code.
+.. _`CMake Language Environment Variables`:
+
+Environment Variables
+=====================
+
+Environment Variables are like ordinary `Variables`_, with the
+following differences:
+
+Scope
+ Environment variables have global scope in a CMake process.
+ They are never cached.
+
+References
+ `Variable References`_ have the form ``$ENV{<variable>}``.
+
+Initialization
+ Initial values of the CMake environment variables are those of
+ the calling process.
+ Values can be changed using the :command:`set` and :command:`unset`
+ commands.
+ These commands only affect the running CMake process,
+ not the system environment at large.
+ Changed values are not written back to the calling process,
+ and they are not seen by subsequent build or test processes.
+
+The :manual:`cmake-env-variables(7)` manual documents environment
+variables that have special meaning to CMake.
+
.. _`CMake Language Lists`:
Lists
diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index 4a03b7a80..fc4bfdc7a 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -3,12 +3,14 @@
cmake-modules(7)
****************
-.. only:: html
+The modules listed here are part of the CMake distribution.
+Projects may provide further modules; their location(s)
+can be specified in the :variable:`CMAKE_MODULE_PATH` variable.
- .. contents::
+Utility Modules
+^^^^^^^^^^^^^^^
-All Modules
-===========
+These modules are loaded using the :command:`include` command.
.. toctree::
:maxdepth: 1
@@ -26,6 +28,7 @@ All Modules
/module/CheckFortranCompilerFlag
/module/CheckFortranFunctionExists
/module/CheckFortranSourceCompiles
+ /module/CheckFortranSourceRuns
/module/CheckFunctionExists
/module/CheckIPOSupported
/module/CheckIncludeFileCXX
@@ -33,6 +36,7 @@ All Modules
/module/CheckIncludeFiles
/module/CheckLanguage
/module/CheckLibraryExists
+ /module/CheckPIESupported
/module/CheckPrototypeDefinition
/module/CheckStructHasMember
/module/CheckSymbolExists
@@ -41,33 +45,19 @@ All Modules
/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/CPackArchive
- /module/CPackBundle
/module/CPackComponent
- /module/CPackCygwin
- /module/CPackDeb
- /module/CPackDMG
/module/CPackIFW
/module/CPackIFWConfigureFile
- /module/CPackNSIS
- /module/CPackPackageMaker
- /module/CPackProductBuild
- /module/CPackRPM
/module/CPack
- /module/CPackWIX
/module/CSharpUtilities
/module/CTest
/module/CTestCoverageCollectGCOV
@@ -79,6 +69,40 @@ All Modules
/module/ExternalData
/module/ExternalProject
/module/FeatureSummary
+ /module/FetchContent
+ /module/FindPackageHandleStandardArgs
+ /module/FindPackageMessage
+ /module/FortranCInterface
+ /module/GenerateExportHeader
+ /module/GetPrerequisites
+ /module/GNUInstallDirs
+ /module/GoogleTest
+ /module/InstallRequiredSystemLibraries
+ /module/ProcessorCount
+ /module/SelectLibraryConfigurations
+ /module/SquishTestScript
+ /module/TestBigEndian
+ /module/TestForANSIForScope
+ /module/TestForANSIStreamHeaders
+ /module/TestForSSTREAM
+ /module/TestForSTDNamespace
+ /module/UseEcos
+ /module/UseJavaClassFilelist
+ /module/UseJava
+ /module/UseJavaSymlinks
+ /module/UseSWIG
+ /module/UsewxWidgets
+ /module/WriteCompilerDetectionHeader
+
+Find Modules
+^^^^^^^^^^^^
+
+These modules search for third-party software.
+They are normally called through the :command:`find_package` command.
+
+.. toctree::
+ :maxdepth: 1
+
/module/FindALSA
/module/FindArmadillo
/module/FindASPELL
@@ -91,7 +115,6 @@ All Modules
/module/FindBZip2
/module/FindCABLE
/module/FindCoin3D
- /module/FindCUDA
/module/FindCups
/module/FindCURL
/module/FindCurses
@@ -102,10 +125,12 @@ All Modules
/module/FindDCMTK
/module/FindDevIL
/module/FindDoxygen
+ /module/FindEnvModules
/module/FindEXPAT
/module/FindFLEX
/module/FindFLTK2
/module/FindFLTK
+ /module/FindFontconfig
/module/FindFreetype
/module/FindGCCXML
/module/FindGDAL
@@ -128,6 +153,7 @@ All Modules
/module/FindIcotool
/module/FindICU
/module/FindImageMagick
+ /module/FindIconv
/module/FindIntl
/module/FindITK
/module/FindJasper
@@ -139,6 +165,7 @@ All Modules
/module/FindLAPACK
/module/FindLATEX
/module/FindLibArchive
+ /module/FindLibinput
/module/FindLibLZMA
/module/FindLibXml2
/module/FindLibXslt
@@ -152,6 +179,8 @@ All Modules
/module/FindMPEG2
/module/FindMPEG
/module/FindMPI
+ /module/FindODBC
+ /module/FindOpenACC
/module/FindOpenAL
/module/FindOpenCL
/module/FindOpenGL
@@ -179,8 +208,7 @@ All Modules
/module/FindosgViewer
/module/FindosgVolume
/module/FindosgWidget
- /module/FindPackageHandleStandardArgs
- /module/FindPackageMessage
+ /module/FindPatch
/module/FindPerlLibs
/module/FindPerl
/module/FindPHP4
@@ -191,11 +219,11 @@ All Modules
/module/FindPostgreSQL
/module/FindProducer
/module/FindProtobuf
- /module/FindPythonInterp
- /module/FindPythonLibs
+ /module/FindPython
+ /module/FindPython2
+ /module/FindPython3
/module/FindQt3
/module/FindQt4
- /module/FindQt
/module/FindQuickTime
/module/FindRTI
/module/FindRuby
@@ -207,6 +235,7 @@ All Modules
/module/FindSDL_ttf
/module/FindSelfPackers
/module/FindSquish
+ /module/FindSQLite3
/module/FindSubversion
/module/FindSWIG
/module/FindTCL
@@ -220,36 +249,63 @@ All Modules
/module/FindWget
/module/FindWish
/module/FindwxWidgets
- /module/FindwxWindows
/module/FindXCTest
/module/FindXalanC
/module/FindXercesC
/module/FindX11
/module/FindXMLRPC
/module/FindZLIB
- /module/FortranCInterface
- /module/GenerateExportHeader
- /module/GetPrerequisites
- /module/GNUInstallDirs
- /module/GoogleTest
- /module/InstallRequiredSystemLibraries
+
+Deprecated Modules
+^^^^^^^^^^^^^^^^^^^
+
+Deprecated Utility Modules
+==========================
+
+.. toctree::
+ :maxdepth: 1
+
+ /module/CMakeDetermineVSServicePack
+ /module/CMakeExpandImportedTargets
+ /module/CMakeForceCompiler
+ /module/CMakeParseArguments
/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
+
+Deprecated Find Modules
+=======================
+
+.. toctree::
+ :maxdepth: 1
+
+ /module/FindCUDA
+ /module/FindPythonInterp
+ /module/FindPythonLibs
+ /module/FindQt
+ /module/FindwxWindows
+
+Legacy CPack Modules
+====================
+
+These modules used to be mistakenly exposed to the user, and have been moved
+out of user visibility. They are for CPack internal use, and should never be
+used directly.
+
+.. toctree::
+ :maxdepth: 1
+
+ /module/CPackArchive
+ /module/CPackBundle
+ /module/CPackCygwin
+ /module/CPackDeb
+ /module/CPackDMG
+ /module/CPackFreeBSD
+ /module/CPackNSIS
+ /module/CPackNuGet
+ /module/CPackPackageMaker
+ /module/CPackProductBuild
+ /module/CPackRPM
+ /module/CPackWIX
diff --git a/Help/manual/cmake-packages.7.rst b/Help/manual/cmake-packages.7.rst
index c9442bc19..f5aa42dc7 100644
--- a/Help/manual/cmake-packages.7.rst
+++ b/Help/manual/cmake-packages.7.rst
@@ -12,7 +12,7 @@ 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
+using :command:`find_package` is either a set of :prop_tgt:`IMPORTED` targets, or
a set of variables corresponding to build-relevant information.
Using Packages
@@ -73,7 +73,7 @@ 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
+``TRUE``, the ``<PackageName>`` package will not be searched, and will always
be ``NOTFOUND``.
.. _`Config File Packages`:
@@ -92,9 +92,9 @@ packages, that is, they belong with the header files and any other files
provided to assist downstreams in using the package.
A set of variables which provide package status information are also set
-automatically when using a config-file package. The ``<Package>_FOUND``
+automatically when using a config-file package. The ``<PackageName>_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
+found. The ``<PackageName>_DIR`` cache variable is set to the location of the
package configuration file.
Find-module Packages
@@ -108,10 +108,10 @@ 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``
+of reference identifies the package as being found, so the ``<PackageName>_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,
+the author of the Find-module. Similarly there is no ``<PackageName>_DIR`` variable,
but each of the artifacts such as library locations and header file locations
provide a separate cache variable.
@@ -197,7 +197,7 @@ When the :command:`find_package` command loads a version file it first sets the
following variables:
``PACKAGE_FIND_NAME``
- The <package> name
+ The ``<PackageName>``
``PACKAGE_FIND_VERSION``
Full requested version string
@@ -240,26 +240,26 @@ 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``
+``<PackageName>_VERSION``
Full provided version string
-``<package>_VERSION_MAJOR``
+``<PackageName>_VERSION_MAJOR``
Major version if provided, else 0
-``<package>_VERSION_MINOR``
+``<PackageName>_VERSION_MINOR``
Minor version if provided, else 0
-``<package>_VERSION_PATCH``
+``<PackageName>_VERSION_PATCH``
Patch version if provided, else 0
-``<package>_VERSION_TWEAK``
+``<PackageName>_VERSION_TWEAK``
Tweak version if provided, else 0
-``<package>_VERSION_COUNT``
+``<PackageName>_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
+The ``<PackageName>`` part of their name matches the argument given to the
:command:`find_package` command.
.. _`Creating Packages`:
@@ -347,8 +347,8 @@ 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
+version-specific variables ``<PackageName>_VERSION``, ``<PackageName>_VERSION_MAJOR``,
+``<PackageName>_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`
@@ -432,8 +432,8 @@ 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
+they are listed in the ``<PackageName>_FIND_COMPONENTS`` variable. If a particular
+component is non-optional, then the ``<PackageName>_FIND_REQUIRED_<comp>`` will
be true. This can be tested with logic in the package configuration file:
.. code-block:: cmake
@@ -580,8 +580,8 @@ 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``).
+`Package Configuration File`_ (``<PackageName>Config.cmake``) and optionally a
+`Package Version File`_ (``<PackageName>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
@@ -603,18 +603,18 @@ 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::
+A ``<PackageName>`` may appear under registry key::
- HKEY_CURRENT_USER\Software\Kitware\CMake\Packages\<package>
+ HKEY_CURRENT_USER\Software\Kitware\CMake\Packages\<PackageName>
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
+directory under ``~/.cmake/packages``. A ``<PackageName>`` may appear under
the directory::
- ~/.cmake/packages/<package>
+ ~/.cmake/packages/<PackageName>
as a file, with arbitrary name, whose content specifies the directory
containing the package configuration file.
@@ -629,10 +629,10 @@ 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
+under a key in ``HKEY_LOCAL_MACHINE``. A ``<PackageName>`` may appear under
registry key::
- HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\<package>
+ HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\<PackageName>
as a ``REG_SZ`` value, with arbitrary name, that specifies the directory
containing the package configuration file.
@@ -647,12 +647,17 @@ Disabling the Package Registry
In some cases using the Package Registries is not desirable. CMake
allows one 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.
+* The :command:`export(PACKAGE)` command does not populate the user
+ package registry when :policy:`CMP0090` is set to ``NEW`` unless the
+ :variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable explicitly enables it.
+ When :policy:`CMP0090` is *not* set to ``NEW`` then
+ :command:`export(PACKAGE)` populates the user package registry unless
+ the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable explicitly
+ disables it.
+* :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
------------------------
diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index 7b858176f..1d023cb1a 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -51,6 +51,74 @@ 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.
+Policies Introduced by CMake 3.15
+=================================
+
+.. toctree::
+ :maxdepth: 1
+
+ CMP0094: FindPython3, FindPython2 and FindPython use LOCATION for lookup strategy. </policy/CMP0094>
+ CMP0093: FindBoost reports Boost_VERSION in x.y.z format. </policy/CMP0093>
+ CMP0092: MSVC warning flags are not in CMAKE_{C,CXX}_FLAGS by default. </policy/CMP0092>
+ CMP0091: MSVC runtime library flags are selected by an abstraction. </policy/CMP0091>
+ CMP0090: export(PACKAGE) does not populate package registry by default. </policy/CMP0090>
+ CMP0089: Compiler id for IBM Clang-based XL compilers is now XLClang. </policy/CMP0089>
+
+Policies Introduced by CMake 3.14
+=================================
+
+.. toctree::
+ :maxdepth: 1
+
+ CMP0088: FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing. </policy/CMP0088>
+ CMP0087: install(SCRIPT | CODE) supports generator expressions. </policy/CMP0087>
+ CMP0086: UseSWIG honors SWIG_MODULE_NAME via -module flag. </policy/CMP0086>
+ CMP0085: IN_LIST generator expression handles empty list items. </policy/CMP0085>
+ CMP0084: The FindQt module does not exist for find_package(). </policy/CMP0084>
+ CMP0083: Add PIE options when linking executable. </policy/CMP0083>
+ CMP0082: Install rules from add_subdirectory() are interleaved with those in caller. </policy/CMP0082>
+
+
+Policies Introduced by CMake 3.13
+=================================
+
+.. toctree::
+ :maxdepth: 1
+
+ CMP0081: Relative paths not allowed in LINK_DIRECTORIES target property. </policy/CMP0081>
+ CMP0080: BundleUtilities cannot be included at configure time. </policy/CMP0080>
+ CMP0079: target_link_libraries allows use with targets in other directories. </policy/CMP0079>
+ CMP0078: UseSWIG generates standard target names. </policy/CMP0078>
+ CMP0077: option() honors normal variables. </policy/CMP0077>
+ CMP0076: target_sources() command converts relative paths to absolute. </policy/CMP0076>
+
+Policies Introduced by CMake 3.12
+=================================
+
+.. toctree::
+ :maxdepth: 1
+
+ CMP0075: Include file check macros honor CMAKE_REQUIRED_LIBRARIES. </policy/CMP0075>
+ CMP0074: find_package uses PackageName_ROOT variables. </policy/CMP0074>
+ CMP0073: Do not produce legacy _LIB_DEPENDS cache entries. </policy/CMP0073>
+
+Policies Introduced by CMake 3.11
+=================================
+
+.. toctree::
+ :maxdepth: 1
+
+ CMP0072: FindOpenGL prefers GLVND by default when available. </policy/CMP0072>
+
+Policies Introduced by CMake 3.10
+=================================
+
+.. toctree::
+ :maxdepth: 1
+
+ CMP0071: Let AUTOMOC and AUTOUIC process GENERATED files. </policy/CMP0071>
+ CMP0070: Define file(GENERATE) behavior for relative paths. </policy/CMP0070>
+
Policies Introduced by CMake 3.9
================================
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index ec25596f3..77b1ae8a1 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -23,6 +23,7 @@ Properties of Global Scope
/prop_gbl/AUTORCC_SOURCE_GROUP
/prop_gbl/CMAKE_C_KNOWN_FEATURES
/prop_gbl/CMAKE_CXX_KNOWN_FEATURES
+ /prop_gbl/CMAKE_ROLE
/prop_gbl/DEBUG_CONFIGURATIONS
/prop_gbl/DISABLED_FEATURES
/prop_gbl/ENABLED_FEATURES
@@ -40,6 +41,7 @@ Properties of Global Scope
/prop_gbl/JOB_POOLS
/prop_gbl/PREDEFINED_TARGETS_FOLDER
/prop_gbl/ECLIPSE_EXTRA_NATURES
+ /prop_gbl/ECLIPSE_EXTRA_CPROJECT_CONTENTS
/prop_gbl/REPORT_UNDEFINED_PROPERTIES
/prop_gbl/RULE_LAUNCH_COMPILE
/prop_gbl/RULE_LAUNCH_CUSTOM
@@ -59,7 +61,7 @@ Properties on Directories
.. toctree::
:maxdepth: 1
- /prop_dir/ADDITIONAL_MAKE_CLEAN_FILES
+ /prop_dir/ADDITIONAL_CLEAN_FILES
/prop_dir/BINARY_DIR
/prop_dir/BUILDSYSTEM_TARGETS
/prop_dir/CACHE_VARIABLES
@@ -74,7 +76,9 @@ Properties on Directories
/prop_dir/INCLUDE_REGULAR_EXPRESSION
/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG
/prop_dir/INTERPROCEDURAL_OPTIMIZATION
+ /prop_dir/LABELS
/prop_dir/LINK_DIRECTORIES
+ /prop_dir/LINK_OPTIONS
/prop_dir/LISTFILE_STACK
/prop_dir/MACROS
/prop_dir/PARENT_DIRECTORY
@@ -83,7 +87,8 @@ Properties on Directories
/prop_dir/RULE_LAUNCH_LINK
/prop_dir/SOURCE_DIR
/prop_dir/SUBDIRECTORIES
- /prop_dir/TEST_INCLUDE_FILE
+ /prop_dir/TESTS
+ /prop_dir/TEST_INCLUDE_FILES
/prop_dir/VARIABLES
/prop_dir/VS_GLOBAL_SECTION_POST_section
/prop_dir/VS_GLOBAL_SECTION_PRE_section
@@ -97,6 +102,7 @@ Properties on Targets
.. toctree::
:maxdepth: 1
+ /prop_tgt/ADDITIONAL_CLEAN_FILES
/prop_tgt/ALIASED_TARGET
/prop_tgt/ANDROID_ANT_ADDITIONAL_OPTIONS
/prop_tgt/ANDROID_API
@@ -120,17 +126,25 @@ Properties on Targets
/prop_tgt/ARCHIVE_OUTPUT_NAME_CONFIG
/prop_tgt/ARCHIVE_OUTPUT_NAME
/prop_tgt/AUTOGEN_BUILD_DIR
+ /prop_tgt/AUTOGEN_ORIGIN_DEPENDS
+ /prop_tgt/AUTOGEN_PARALLEL
/prop_tgt/AUTOGEN_TARGET_DEPENDS
+ /prop_tgt/AUTOMOC_COMPILER_PREDEFINES
/prop_tgt/AUTOMOC_DEPEND_FILTERS
+ /prop_tgt/AUTOMOC_EXECUTABLE
+ /prop_tgt/AUTOMOC_MACRO_NAMES
/prop_tgt/AUTOMOC_MOC_OPTIONS
/prop_tgt/AUTOMOC
/prop_tgt/AUTOUIC
+ /prop_tgt/AUTOUIC_EXECUTABLE
/prop_tgt/AUTOUIC_OPTIONS
/prop_tgt/AUTOUIC_SEARCH_PATHS
/prop_tgt/AUTORCC
+ /prop_tgt/AUTORCC_EXECUTABLE
/prop_tgt/AUTORCC_OPTIONS
/prop_tgt/BINARY_DIR
/prop_tgt/BUILD_RPATH
+ /prop_tgt/BUILD_RPATH_USE_ORIGIN
/prop_tgt/BUILD_WITH_INSTALL_NAME_DIR
/prop_tgt/BUILD_WITH_INSTALL_RPATH
/prop_tgt/BUNDLE_EXTENSION
@@ -138,6 +152,7 @@ Properties on Targets
/prop_tgt/C_EXTENSIONS
/prop_tgt/C_STANDARD
/prop_tgt/C_STANDARD_REQUIRED
+ /prop_tgt/COMMON_LANGUAGE_RUNTIME
/prop_tgt/COMPATIBLE_INTERFACE_BOOL
/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MAX
/prop_tgt/COMPATIBLE_INTERFACE_NUMBER_MIN
@@ -165,22 +180,29 @@ Properties on Targets
/prop_tgt/DEBUG_POSTFIX
/prop_tgt/DEFINE_SYMBOL
/prop_tgt/DEPLOYMENT_REMOTE_DIRECTORY
+ /prop_tgt/DEPLOYMENT_ADDITIONAL_FILES
+ /prop_tgt/DOTNET_TARGET_FRAMEWORK_VERSION
/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/EXPORT_PROPERTIES
/prop_tgt/FOLDER
/prop_tgt/Fortran_FORMAT
/prop_tgt/Fortran_MODULE_DIRECTORY
/prop_tgt/FRAMEWORK
/prop_tgt/FRAMEWORK_VERSION
/prop_tgt/GENERATOR_FILE_NAME
+ /prop_tgt/GHS_INTEGRITY_APP
+ /prop_tgt/GHS_NO_SOURCE_GROUP_FILE
/prop_tgt/GNUtoMS
/prop_tgt/HAS_CXX
/prop_tgt/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
+ /prop_tgt/IMPORTED_COMMON_LANGUAGE_RUNTIME
/prop_tgt/IMPORTED_CONFIGURATIONS
+ /prop_tgt/IMPORTED_GLOBAL
/prop_tgt/IMPORTED_IMPLIB_CONFIG
/prop_tgt/IMPORTED_IMPLIB
/prop_tgt/IMPORTED_LIBNAME_CONFIG
@@ -213,7 +235,10 @@ Properties on Targets
/prop_tgt/INTERFACE_COMPILE_FEATURES
/prop_tgt/INTERFACE_COMPILE_OPTIONS
/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES
+ /prop_tgt/INTERFACE_LINK_DEPENDS
+ /prop_tgt/INTERFACE_LINK_DIRECTORIES
/prop_tgt/INTERFACE_LINK_LIBRARIES
+ /prop_tgt/INTERFACE_LINK_OPTIONS
/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE
/prop_tgt/INTERFACE_SOURCES
/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
@@ -225,6 +250,7 @@ Properties on Targets
/prop_tgt/LABELS
/prop_tgt/LANG_CLANG_TIDY
/prop_tgt/LANG_COMPILER_LAUNCHER
+ /prop_tgt/LANG_CPPCHECK
/prop_tgt/LANG_CPPLINT
/prop_tgt/LANG_INCLUDE_WHAT_YOU_USE
/prop_tgt/LANG_VISIBILITY_PRESET
@@ -235,6 +261,7 @@ Properties on Targets
/prop_tgt/LINK_DEPENDS_NO_SHARED
/prop_tgt/LINK_DEPENDS
/prop_tgt/LINKER_LANGUAGE
+ /prop_tgt/LINK_DIRECTORIES
/prop_tgt/LINK_FLAGS_CONFIG
/prop_tgt/LINK_FLAGS
/prop_tgt/LINK_INTERFACE_LIBRARIES_CONFIG
@@ -242,6 +269,7 @@ Properties on Targets
/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG
/prop_tgt/LINK_INTERFACE_MULTIPLICITY
/prop_tgt/LINK_LIBRARIES
+ /prop_tgt/LINK_OPTIONS
/prop_tgt/LINK_SEARCH_END_STATIC
/prop_tgt/LINK_SEARCH_START_STATIC
/prop_tgt/LINK_WHAT_YOU_USE
@@ -253,6 +281,7 @@ Properties on Targets
/prop_tgt/MACOSX_RPATH
/prop_tgt/MANUALLY_ADDED_DEPENDENCIES
/prop_tgt/MAP_IMPORTED_CONFIG_CONFIG
+ /prop_tgt/MSVC_RUNTIME_LIBRARY
/prop_tgt/NAME
/prop_tgt/NO_SONAME
/prop_tgt/NO_SYSTEM_FROM_IMPORTED
@@ -283,14 +312,22 @@ Properties on Targets
/prop_tgt/SOVERSION
/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG
/prop_tgt/STATIC_LIBRARY_FLAGS
+ /prop_tgt/STATIC_LIBRARY_OPTIONS
/prop_tgt/SUFFIX
+ /prop_tgt/Swift_DEPENDENCIES_FILE
+ /prop_tgt/Swift_MODULE_DIRECTORY
+ /prop_tgt/Swift_MODULE_NAME
/prop_tgt/TYPE
/prop_tgt/VERSION
/prop_tgt/VISIBILITY_INLINES_HIDDEN
/prop_tgt/VS_CONFIGURATION_TYPE
+ /prop_tgt/VS_DEBUGGER_COMMAND
+ /prop_tgt/VS_DEBUGGER_COMMAND_ARGUMENTS
+ /prop_tgt/VS_DEBUGGER_ENVIRONMENT
/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY
/prop_tgt/VS_DESKTOP_EXTENSIONS_VERSION
/prop_tgt/VS_DOTNET_REFERENCE_refname
+ /prop_tgt/VS_DOTNET_REFERENCEPROP_refname_TAG_tagname
/prop_tgt/VS_DOTNET_REFERENCES
/prop_tgt/VS_DOTNET_REFERENCES_COPY_LOCAL
/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION
@@ -300,8 +337,12 @@ Properties on Targets
/prop_tgt/VS_GLOBAL_variable
/prop_tgt/VS_IOT_EXTENSIONS_VERSION
/prop_tgt/VS_IOT_STARTUP_TASK
+ /prop_tgt/VS_JUST_MY_CODE_DEBUGGING
/prop_tgt/VS_KEYWORD
/prop_tgt/VS_MOBILE_EXTENSIONS_VERSION
+ /prop_tgt/VS_NO_SOLUTION_DEPLOY
+ /prop_tgt/VS_PACKAGE_REFERENCES
+ /prop_tgt/VS_PROJECT_IMPORT
/prop_tgt/VS_SCC_AUXPATH
/prop_tgt/VS_SCC_LOCALPATH
/prop_tgt/VS_SCC_PROJECTNAME
@@ -316,7 +357,27 @@ Properties on Targets
/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS
/prop_tgt/XCODE_ATTRIBUTE_an-attribute
/prop_tgt/XCODE_EXPLICIT_FILE_TYPE
+ /prop_tgt/XCODE_GENERATE_SCHEME
/prop_tgt/XCODE_PRODUCT_TYPE
+ /prop_tgt/XCODE_SCHEME_ADDRESS_SANITIZER
+ /prop_tgt/XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN
+ /prop_tgt/XCODE_SCHEME_ARGUMENTS
+ /prop_tgt/XCODE_SCHEME_DEBUG_AS_ROOT
+ /prop_tgt/XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER
+ /prop_tgt/XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS
+ /prop_tgt/XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE
+ /prop_tgt/XCODE_SCHEME_ENVIRONMENT
+ /prop_tgt/XCODE_SCHEME_EXECUTABLE
+ /prop_tgt/XCODE_SCHEME_GUARD_MALLOC
+ /prop_tgt/XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP
+ /prop_tgt/XCODE_SCHEME_MALLOC_GUARD_EDGES
+ /prop_tgt/XCODE_SCHEME_MALLOC_SCRIBBLE
+ /prop_tgt/XCODE_SCHEME_MALLOC_STACK
+ /prop_tgt/XCODE_SCHEME_THREAD_SANITIZER
+ /prop_tgt/XCODE_SCHEME_THREAD_SANITIZER_STOP
+ /prop_tgt/XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER
+ /prop_tgt/XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP
+ /prop_tgt/XCODE_SCHEME_ZOMBIE_OBJECTS
/prop_tgt/XCTEST
.. _`Test Properties`:
@@ -340,6 +401,7 @@ Properties on Tests
/prop_test/LABELS
/prop_test/MEASUREMENT
/prop_test/PASS_REGULAR_EXPRESSION
+ /prop_test/PROCESSOR_AFFINITY
/prop_test/PROCESSORS
/prop_test/REQUIRED_FILES
/prop_test/RESOURCE_LOCK
@@ -363,10 +425,12 @@ Properties on Source Files
/prop_sf/AUTORCC_OPTIONS
/prop_sf/COMPILE_DEFINITIONS
/prop_sf/COMPILE_FLAGS
+ /prop_sf/COMPILE_OPTIONS
/prop_sf/EXTERNAL_OBJECT
/prop_sf/Fortran_FORMAT
/prop_sf/GENERATED
/prop_sf/HEADER_FILE_ONLY
+ /prop_sf/INCLUDE_DIRECTORIES
/prop_sf/KEEP_EXTENSION
/prop_sf/LABELS
/prop_sf/LANGUAGE
@@ -378,6 +442,8 @@ Properties on Source Files
/prop_sf/SKIP_AUTOMOC
/prop_sf/SKIP_AUTORCC
/prop_sf/SKIP_AUTOUIC
+ /prop_sf/Swift_DEPENDENCIES_FILE
+ /prop_sf/Swift_DIAGNOSTICS_FILE
/prop_sf/SYMBOLIC
/prop_sf/VS_COPY_TO_OUT_DIR
/prop_sf/VS_CSHARP_tagname
@@ -385,10 +451,15 @@ Properties on Source Files
/prop_sf/VS_DEPLOYMENT_LOCATION
/prop_sf/VS_INCLUDE_IN_VSIX
/prop_sf/VS_RESOURCE_GENERATOR
+ /prop_sf/VS_SHADER_DISABLE_OPTIMIZATIONS
+ /prop_sf/VS_SHADER_ENABLE_DEBUG
/prop_sf/VS_SHADER_ENTRYPOINT
/prop_sf/VS_SHADER_FLAGS
/prop_sf/VS_SHADER_MODEL
+ /prop_sf/VS_SHADER_OBJECT_FILE_NAME
+ /prop_sf/VS_SHADER_OUTPUT_HEADER_FILE
/prop_sf/VS_SHADER_TYPE
+ /prop_sf/VS_SHADER_VARIABLE_NAME
/prop_sf/VS_TOOL_OVERRIDE.rst
/prop_sf/VS_XAML_TYPE
/prop_sf/WRAP_EXCLUDE
@@ -433,7 +504,9 @@ Deprecated Properties on Directories
.. toctree::
:maxdepth: 1
+ /prop_dir/ADDITIONAL_MAKE_CLEAN_FILES
/prop_dir/COMPILE_DEFINITIONS_CONFIG
+ /prop_dir/TEST_INCLUDE_FILE
Deprecated Properties on Targets
diff --git a/Help/manual/cmake-qt.7.rst b/Help/manual/cmake-qt.7.rst
index b7f16b9ea..d8d61729e 100644
--- a/Help/manual/cmake-qt.7.rst
+++ b/Help/manual/cmake-qt.7.rst
@@ -44,14 +44,10 @@ 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
+and ``rcc`` for virtual file system 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
^^^^^^^
@@ -59,9 +55,10 @@ 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
+If a macro from :prop_tgt:`AUTOMOC_MACRO_NAMES` 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 ``<basename>.moc`` must
be included by the user in the C++ implementation file with a preprocessor
@@ -72,6 +69,10 @@ Included ``moc_*.cpp`` and ``*.moc`` files will be generated in the
automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
* This differs from CMake 3.7 and below; see their documentation for details.
+
+* For :prop_gbl:`multi configuration generators <GENERATOR_IS_MULTI_CONFIG>`,
+ the include directory is ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``.
+
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
Not included ``moc_<basename>.cpp`` files will be generated in custom
@@ -91,6 +92,9 @@ following targets by setting the :variable:`CMAKE_AUTOMOC` variable. The
options to pass to ``moc``. The :variable:`CMAKE_AUTOMOC_MOC_OPTIONS`
variable may be populated to pre-set the options for all following targets.
+Additional macro names to search for can be added to
+:prop_tgt:`AUTOMOC_MACRO_NAMES`.
+
Additional ``moc`` dependency file names can be extracted from source code
by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`.
@@ -124,6 +128,10 @@ The generated generated ``ui_*.h`` files are placed in the
automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
* This differs from CMake 3.7 and below; see their documentation for details.
+
+* For :prop_gbl:`multi configuration generators <GENERATOR_IS_MULTI_CONFIG>`,
+ the include directory is ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``.
+
* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
The :prop_tgt:`AUTOUIC` target property may be pre-set for all following
@@ -202,6 +210,34 @@ overrides options from the :prop_tgt:`AUTORCC_OPTIONS` target property.
Source files can be excluded from :prop_tgt:`AUTORCC` processing by
enabling :prop_sf:`SKIP_AUTORCC` or the broader :prop_sf:`SKIP_AUTOGEN`.
+The ``<ORIGIN>_autogen`` target
+===============================
+
+The ``moc`` and ``uic`` tools are executed as part of a synthesized
+``<ORIGIN>_autogen`` :command:`custom target <add_custom_target>` generated by
+CMake. By default that ``<ORIGIN>_autogen`` target inherits the dependencies
+of the ``<ORIGIN>`` target (see :prop_tgt:`AUTOGEN_ORIGIN_DEPENDS`).
+Target dependencies may be added to the ``<ORIGIN>_autogen`` target by adding
+them to the :prop_tgt:`AUTOGEN_TARGET_DEPENDS` target property.
+
+Visual Studio Generators
+========================
+
+When using the :manual:`Visual Studio generators <cmake-generators(7)>`, CMake
+generates a ``PRE_BUILD`` :command:`custom command <add_custom_command>`
+instead of the ``<ORIGIN>_autogen`` :command:`custom target <add_custom_target>`
+(for :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC`).
+This isn't always possible though and
+an ``<ORIGIN>_autogen`` :command:`custom target <add_custom_target>` is used,
+when either
+
+- the ``<ORIGIN>`` target depends on :prop_sf:`GENERATED` files which aren't
+ excluded from :prop_tgt:`AUTOMOC` and :prop_tgt:`AUTOUIC` by
+ :prop_sf:`SKIP_AUTOMOC`, :prop_sf:`SKIP_AUTOUIC`, :prop_sf:`SKIP_AUTOGEN`
+ or :policy:`CMP0071`
+- :prop_tgt:`AUTOGEN_TARGET_DEPENDS` lists a source file
+- :variable:`CMAKE_GLOBAL_AUTOGEN_TARGET` is enabled
+
qtmain.lib on Windows
=====================
diff --git a/Help/manual/cmake-server.7.rst b/Help/manual/cmake-server.7.rst
index 9520cc140..8f10b9f0e 100644
--- a/Help/manual/cmake-server.7.rst
+++ b/Help/manual/cmake-server.7.rst
@@ -7,6 +7,11 @@ cmake-server(7)
.. contents::
+.. deprecated:: 3.15
+
+ This will be removed from a future version of CMake.
+ Clients should use the :manual:`cmake-file-api(7)` instead.
+
Introduction
============
@@ -49,10 +54,12 @@ Operation
Start :manual:`cmake(1)` in the server command mode, supplying the path to
the build directory to process::
- cmake -E server (--debug|--pipe <NAMED_PIPE>)
+ cmake -E server (--debug|--pipe=<NAMED_PIPE>)
The server will communicate using stdin/stdout (with the ``--debug`` parameter)
-or using a named pipe (with the ``--pipe <NAMED_PIPE>`` parameter).
+or using a named pipe (with the ``--pipe=<NAMED_PIPE>`` parameter). Note
+that "named pipe" refers to a local domain socket on Unix and to a named pipe
+on Windows.
When connecting to the server (via named pipe or by starting it in ``--debug``
mode), the server will reply with a hello message::
@@ -162,7 +169,7 @@ When the server is busy for a long time, it is polite to send back replies of
type "progress" to the client. These will contain a "progressMessage" with a
string describing the action currently taking place as well as
"progressMinimum", "progressMaximum" and "progressCurrent" with integer values
-describing the range of progess.
+describing the range of progress.
Messages of type "progress" will be followed by more "progress" messages or with
a message of type "reply" or "error" that complete the request.
@@ -254,6 +261,11 @@ versions supported by the cmake server. These are JSON objects with "major" and
as experimental. These will contain the "isExperimental" key set to true. Enabling
these requires a special command line argument when starting the cmake server mode.
+Within a "major" version all "minor" versions are fully backwards compatible.
+New "minor" versions may introduce functionality in such a way that existing
+clients of the same "major" version will continue to work, provided they
+ignore keys in the output that they do not know about.
+
Example::
[== "CMake Server" ==[
@@ -268,8 +280,9 @@ The first request that the client may send to the server is of type "handshake".
This request needs to pass one of the "supportedProtocolVersions" of the "hello"
type response received earlier back to the server in the "protocolVersion" field.
-
-Each protocol version may request additional attributes to be present.
+Giving the "major" version of the requested protocol version will make the server
+use the latest minor version of that protocol. Use this if you do not explicitly
+need to depend on a specific minor version.
Protocol version 1.0 requires the following attributes to be set:
@@ -280,6 +293,10 @@ Protocol version 1.0 requires the following attributes to be set:
* "platform" with the generator platform (if supported by the generator)
* "toolset" with the generator toolset (if supported by the generator)
+Protocol version 1.2 makes all but the build directory optional, provided
+there is a valid cache in the build directory that contains all the other
+information already.
+
Example::
[== "CMake Server" ==[
@@ -448,6 +465,11 @@ Each project object can have the following keys:
"name"
contains the (sub-)projects name.
+"minimumCMakeVersion"
+ contains the minimum cmake version allowed for this project, null if the
+ project doesn't specify one.
+"hasInstallRule"
+ true if the project contains any install rules, false otherwise.
"sourceDirectory"
contains the current source directory
"buildDirectory"
@@ -471,6 +493,12 @@ Each target object can have the following keys:
contains the current source directory.
"buildDirectory"
contains the current build directory.
+"isGeneratorProvided"
+ true if the target is auto-created by a generator, false otherwise
+"hasInstallRule"
+ true if the target contains any install rules, false otherwise.
+"installPaths"
+ full path to the destination directories defined by target install rules.
"artifacts"
with a list of build artifacts. The list is sorted with the most
important artifacts first (e.g. a .DLL file is listed before a
@@ -572,6 +600,51 @@ CMake will reply::
]== "CMake Server" ==]
+Type "ctestInfo"
+^^^^^^^^^^^^^^^^
+
+The "ctestInfo" request can be used after a project was "compute"d successfully.
+
+It will list the complete project test structure as it is known to cmake.
+
+The reply will contain a key "configurations", which will contain a list of
+configuration objects. Configuration objects are used to destinquish between
+different configurations the build directory might have enabled. While most
+generators only support one configuration, others might support several.
+
+Each configuration object can have the following keys:
+
+"name"
+ contains the name of the configuration. The name may be empty.
+"projects"
+ contains a list of project objects, one for each build project.
+
+Project objects define one (sub-)project defined in the cmake build system.
+
+Each project object can have the following keys:
+
+"name"
+ contains the (sub-)projects name.
+"ctestInfo"
+ contains a list of test objects.
+
+Each test object can have the following keys:
+
+"ctestName"
+ contains the name of the test.
+"ctestCommand"
+ contains the test command.
+"properties"
+ contains a list of test property objects.
+
+Each test property object can have the following keys:
+
+"key"
+ contains the test property key.
+"value"
+ contains the test property value.
+
+
Type "cmakeInputs"
^^^^^^^^^^^^^^^^^^
@@ -616,8 +689,7 @@ and will not survive the build directory getting cleaned out.
Type "cache"
^^^^^^^^^^^^
-The "cache" request can be used once a project is configured and will
-list the cached configuration values.
+The "cache" request will list the cached configuration values.
Example::
diff --git a/Help/manual/cmake-toolchains.7.rst b/Help/manual/cmake-toolchains.7.rst
index 8554e87f9..7435d9a77 100644
--- a/Help/manual/cmake-toolchains.7.rst
+++ b/Help/manual/cmake-toolchains.7.rst
@@ -26,13 +26,13 @@ built-in variables, such as
: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:
+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
+A special value of ``NONE`` can also be used with the :command:`project` command
to enable no languages:
.. code-block:: cmake
@@ -101,6 +101,14 @@ values for the compilers.
The :variable:`CMAKE_CROSSCOMPILING` variable is set to true when CMake is
cross-compiling.
+Note that using the :variable:`CMAKE_SOURCE_DIR` or :variable:`CMAKE_BINARY_DIR`
+variables inside a toolchain file is typically undesirable. The toolchain
+file is used in contexts where these variables have different values when used
+in different places (e.g. as part of a call to :command:`try_compile`). In most
+cases, where there is a need to evaluate paths inside a toolchain file, the more
+appropriate variable to use would be :variable:`CMAKE_CURRENT_LIST_DIR`, since
+it always has an unambiguous, predictable value.
+
Cross Compiling for Linux
-------------------------
@@ -468,10 +476,10 @@ The following variables will be computed and provided automatically:
The Android ABI detected from the standalone toolchain.
:variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_PREFIX`
- The absolute path prefix to the binutils in the standalone toolchain.
+ The absolute path prefix to the ``binutils`` in the standalone toolchain.
:variable:`CMAKE_<LANG>_ANDROID_TOOLCHAIN_SUFFIX`
- The host platform suffix of the binutils in the standalone toolchain.
+ The host platform suffix of the ``binutils`` in the standalone toolchain.
For example, a toolchain file might contain:
@@ -522,3 +530,132 @@ See also target properties:
* :prop_tgt:`ANDROID_SECURE_PROPS_PATH`
* :prop_tgt:`ANDROID_SKIP_ANT_STEP`
* :prop_tgt:`ANDROID_STL_TYPE`
+
+.. _`Cross Compiling for iOS, tvOS, or watchOS`:
+
+Cross Compiling for iOS, tvOS, or watchOS
+-----------------------------------------
+
+For cross-compiling to iOS, tvOS, or watchOS, the :generator:`Xcode`
+generator is recommended. The :generator:`Unix Makefiles` or
+:generator:`Ninja` generators can also be used, but they require the
+project to handle more areas like target CPU selection and code signing.
+
+Any of the three systems can be targeted by setting the
+:variable:`CMAKE_SYSTEM_NAME` variable to a value from the table below.
+By default, the latest Device SDK is chosen. As for all Apple platforms,
+a different SDK (e.g. a simulator) can be selected by setting the
+:variable:`CMAKE_OSX_SYSROOT` variable, although this should rarely be
+necessary (see :ref:`Switching Between Device and Simulator` below).
+A list of available SDKs can be obtained by running ``xcodebuild -showsdks``.
+
+======= ================= ==================== ================
+OS CMAKE_SYSTEM_NAME Device SDK (default) Simulator SDK
+======= ================= ==================== ================
+iOS iOS iphoneos iphonesimulator
+tvOS tvOS appletvos appletvsimulator
+watchOS watchOS watchos watchsimulator
+======= ================= ==================== ================
+
+For example, to create a CMake configuration for iOS, the following
+command is sufficient:
+
+.. code-block:: console
+
+ cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS
+
+Variable :variable:`CMAKE_OSX_ARCHITECTURES` can be used to set architectures
+for both device and simulator. Variable :variable:`CMAKE_OSX_DEPLOYMENT_TARGET`
+can be used to set an iOS/tvOS/watchOS deployment target.
+
+Next configuration will install fat 5 architectures iOS library
+and add the ``-miphoneos-version-min=9.3``/``-mios-simulator-version-min=9.3``
+flags to the compiler:
+
+.. code-block:: console
+
+ $ cmake -S. -B_builds -GXcode \
+ -DCMAKE_SYSTEM_NAME=iOS \
+ "-DCMAKE_OSX_ARCHITECTURES=armv7;armv7s;arm64;i386;x86_64" \
+ -DCMAKE_OSX_DEPLOYMENT_TARGET=9.3 \
+ -DCMAKE_INSTALL_PREFIX=`pwd`/_install \
+ -DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO \
+ -DCMAKE_IOS_INSTALL_COMBINED=YES
+
+Example:
+
+.. code-block:: cmake
+
+ # CMakeLists.txt
+ cmake_minimum_required(VERSION 3.14)
+ project(foo)
+ add_library(foo foo.cpp)
+ install(TARGETS foo DESTINATION lib)
+
+Install:
+
+.. code-block:: console
+
+ $ cmake --build _builds --config Release --target install
+
+Check library:
+
+.. code-block:: console
+
+ $ lipo -info _install/lib/libfoo.a
+ Architectures in the fat file: _install/lib/libfoo.a are: i386 armv7 armv7s x86_64 arm64
+
+.. code-block:: console
+
+ $ otool -l _install/lib/libfoo.a | grep -A2 LC_VERSION_MIN_IPHONEOS
+ cmd LC_VERSION_MIN_IPHONEOS
+ cmdsize 16
+ version 9.3
+
+Code Signing
+^^^^^^^^^^^^
+
+Some build artifacts for the embedded Apple platforms require mandatory
+code signing. If the :generator:`Xcode` generator is being used and
+code signing is required or desired, the development team ID can be
+specified via the ``CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM`` CMake variable.
+This team ID will then be included in the generated Xcode project.
+By default, CMake avoids the need for code signing during the internal
+configuration phase (i.e compiler ID and feature detection).
+
+.. _`Switching Between Device and Simulator`:
+
+Switching Between Device and Simulator
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+When configuring for any of the embedded platforms, one can target either
+real devices or the simulator. Both have their own separate SDK, but CMake
+only supports specifying a single SDK for the configuration phase. This
+means the developer must select one or the other at configuration time.
+When using the :generator:`Xcode` generator, this is less of a limitation
+because Xcode still allows you to build for either a device or a simulator,
+even though configuration was only performed for one of the two. From
+within the Xcode IDE, builds are performed for the selected "destination"
+platform. When building from the command line, the desired sdk can be
+specified directly by passing a ``-sdk`` option to the underlying build
+tool (``xcodebuild``). For example:
+
+.. code-block:: console
+
+ $ cmake --build ... -- -sdk iphonesimulator
+
+Please note that checks made during configuration were performed against
+the configure-time SDK and might not hold true for other SDKs. Commands
+like :command:`find_package`, :command:`find_library`, etc. store and use
+details only for the configured SDK/platform, so they can be problematic
+if wanting to switch between device and simulator builds. You can follow
+the next rules to make device + simulator configuration work:
+
+- Use explicit ``-l`` linker flag,
+ e.g. ``target_link_libraries(foo PUBLIC "-lz")``
+
+- Use explicit ``-framework`` linker flag,
+ e.g. ``target_link_libraries(foo PUBLIC "-framework CoreFoundation")``
+
+- Use :command:`find_package` only for libraries installed with
+ :variable:`CMAKE_IOS_INSTALL_COMBINED` feature
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 1a2726dd3..e3c2f9fc8 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -7,6 +7,14 @@ cmake-variables(7)
.. contents::
+This page documents variables that are provided by CMake
+or have meaning to CMake when set by project code.
+
+For general information on variables, see the
+:ref:`Variables <CMake Language Variables>`
+section in the cmake-language manual.
+
+
Variables that Provide Information
==================================
@@ -24,6 +32,7 @@ Variables that Provide Information
/variable/CMAKE_CACHE_PATCH_VERSION
/variable/CMAKE_CFG_INTDIR
/variable/CMAKE_COMMAND
+ /variable/CMAKE_CPACK_COMMAND
/variable/CMAKE_CROSSCOMPILING
/variable/CMAKE_CROSSCOMPILING_EMULATOR
/variable/CMAKE_CTEST_COMMAND
@@ -32,7 +41,9 @@ Variables that Provide Information
/variable/CMAKE_CURRENT_LIST_FILE
/variable/CMAKE_CURRENT_LIST_LINE
/variable/CMAKE_CURRENT_SOURCE_DIR
+ /variable/CMAKE_DIRECTORY_LABELS
/variable/CMAKE_DL_LIBS
+ /variable/CMAKE_DOTNET_TARGET_FRAMEWORK_VERSION
/variable/CMAKE_EDIT_COMMAND
/variable/CMAKE_EXECUTABLE_SUFFIX
/variable/CMAKE_EXTRA_GENERATOR
@@ -41,13 +52,14 @@ Variables that Provide Information
/variable/CMAKE_FIND_PACKAGE_SORT_DIRECTION
/variable/CMAKE_FIND_PACKAGE_SORT_ORDER
/variable/CMAKE_GENERATOR
+ /variable/CMAKE_GENERATOR_INSTANCE
/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_JOB_POOLS
/variable/CMAKE_LANG_COMPILER_AR
/variable/CMAKE_LANG_COMPILER_RANLIB
/variable/CMAKE_LINK_LIBRARY_SUFFIX
@@ -59,12 +71,21 @@ Variables that Provide Information
/variable/CMAKE_MATCH_n
/variable/CMAKE_MINIMUM_REQUIRED_VERSION
/variable/CMAKE_MINOR_VERSION
+ /variable/CMAKE_NETRC
+ /variable/CMAKE_NETRC_FILE
/variable/CMAKE_PARENT_LIST_FILE
/variable/CMAKE_PATCH_VERSION
/variable/CMAKE_PROJECT_DESCRIPTION
+ /variable/CMAKE_PROJECT_HOMEPAGE_URL
/variable/CMAKE_PROJECT_NAME
+ /variable/CMAKE_PROJECT_VERSION
+ /variable/CMAKE_PROJECT_VERSION_MAJOR
+ /variable/CMAKE_PROJECT_VERSION_MINOR
+ /variable/CMAKE_PROJECT_VERSION_PATCH
+ /variable/CMAKE_PROJECT_VERSION_TWEAK
/variable/CMAKE_RANLIB
/variable/CMAKE_ROOT
+ /variable/CMAKE_RULE_MESSAGES
/variable/CMAKE_SCRIPT_MODE_FILE
/variable/CMAKE_SHARED_LIBRARY_PREFIX
/variable/CMAKE_SHARED_LIBRARY_SUFFIX
@@ -76,22 +97,27 @@ Variables that Provide Information
/variable/CMAKE_SOURCE_DIR
/variable/CMAKE_STATIC_LIBRARY_PREFIX
/variable/CMAKE_STATIC_LIBRARY_SUFFIX
+ /variable/CMAKE_Swift_MODULE_DIRECTORY
+ /variable/CMAKE_Swift_NUM_THREADS
/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_NsightTegra_VERSION
/variable/CMAKE_VS_PLATFORM_NAME
+ /variable/CMAKE_VS_PLATFORM_NAME_DEFAULT
/variable/CMAKE_VS_PLATFORM_TOOLSET
/variable/CMAKE_VS_PLATFORM_TOOLSET_CUDA
/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE
+ /variable/CMAKE_VS_PLATFORM_TOOLSET_VERSION
/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION
/variable/CMAKE_XCODE_GENERATE_SCHEME
/variable/CMAKE_XCODE_PLATFORM_TOOLSET
/variable/PROJECT-NAME_BINARY_DIR
+ /variable/PROJECT-NAME_DESCRIPTION
+ /variable/PROJECT-NAME_HOMEPAGE_URL
/variable/PROJECT-NAME_SOURCE_DIR
/variable/PROJECT-NAME_VERSION
/variable/PROJECT-NAME_VERSION_MAJOR
@@ -100,6 +126,7 @@ Variables that Provide Information
/variable/PROJECT-NAME_VERSION_TWEAK
/variable/PROJECT_BINARY_DIR
/variable/PROJECT_DESCRIPTION
+ /variable/PROJECT_HOMEPAGE_URL
/variable/PROJECT_NAME
/variable/PROJECT_SOURCE_DIR
/variable/PROJECT_VERSION
@@ -120,6 +147,8 @@ Variables that Change Behavior
/variable/CMAKE_AUTOMOC_RELAXED_MODE
/variable/CMAKE_BACKWARDS_COMPATIBILITY
/variable/CMAKE_BUILD_TYPE
+ /variable/CMAKE_CODEBLOCKS_COMPILER_ID
+ /variable/CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES
/variable/CMAKE_CODELITE_USE_TARGETS
/variable/CMAKE_COLOR_MAKEFILE
/variable/CMAKE_CONFIGURATION_TYPES
@@ -132,7 +161,9 @@ Variables that Change Behavior
/variable/CMAKE_ECLIPSE_VERSION
/variable/CMAKE_ERROR_DEPRECATED
/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
+ /variable/CMAKE_EXECUTE_PROCESS_COMMAND_ECHO
/variable/CMAKE_EXPORT_COMPILE_COMMANDS
+ /variable/CMAKE_EXPORT_PACKAGE_REGISTRY
/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY
/variable/CMAKE_FIND_APPBUNDLE
/variable/CMAKE_FIND_FRAMEWORK
@@ -142,6 +173,8 @@ Variables that Change Behavior
/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_PREFER_CONFIG
+ /variable/CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS
/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE
/variable/CMAKE_FIND_ROOT_PATH
/variable/CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
@@ -154,22 +187,27 @@ Variables that Change Behavior
/variable/CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE
/variable/CMAKE_INCLUDE_PATH
/variable/CMAKE_INSTALL_DEFAULT_COMPONENT_NAME
+ /variable/CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
/variable/CMAKE_INSTALL_MESSAGE
/variable/CMAKE_INSTALL_PREFIX
/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
/variable/CMAKE_LIBRARY_PATH
+ /variable/CMAKE_LINK_DIRECTORIES_BEFORE
/variable/CMAKE_MFC_FLAG
+ /variable/CMAKE_MAXIMUM_RECURSION_DEPTH
/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_INCLUDE
+ /variable/CMAKE_PROJECT_INCLUDE_BEFORE
/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE
/variable/CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
/variable/CMAKE_STAGING_PREFIX
/variable/CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS
/variable/CMAKE_SUBLIME_TEXT_2_EXCLUDE_BUILD_TREE
+ /variable/CMAKE_SUPPRESS_REGENERATION
/variable/CMAKE_SYSROOT
/variable/CMAKE_SYSROOT_COMPILE
/variable/CMAKE_SYSROOT_LINK
@@ -183,6 +221,23 @@ Variables that Change Behavior
/variable/CMAKE_USER_MAKE_RULES_OVERRIDE
/variable/CMAKE_WARN_DEPRECATED
/variable/CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
+ /variable/CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY
+ /variable/CMAKE_XCODE_SCHEME_ADDRESS_SANITIZER
+ /variable/CMAKE_XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN
+ /variable/CMAKE_XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER
+ /variable/CMAKE_XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS
+ /variable/CMAKE_XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE
+ /variable/CMAKE_XCODE_SCHEME_GUARD_MALLOC
+ /variable/CMAKE_XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP
+ /variable/CMAKE_XCODE_SCHEME_MALLOC_GUARD_EDGES
+ /variable/CMAKE_XCODE_SCHEME_MALLOC_SCRIBBLE
+ /variable/CMAKE_XCODE_SCHEME_MALLOC_STACK
+ /variable/CMAKE_XCODE_SCHEME_THREAD_SANITIZER
+ /variable/CMAKE_XCODE_SCHEME_THREAD_SANITIZER_STOP
+ /variable/CMAKE_XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER
+ /variable/CMAKE_XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP
+ /variable/CMAKE_XCODE_SCHEME_ZOMBIE_OBJECTS
+ /variable/PackageName_ROOT
Variables that Describe the System
==================================
@@ -211,8 +266,8 @@ Variables that Describe the System
/variable/CMAKE_SYSTEM_PROCESSOR
/variable/CMAKE_SYSTEM_VERSION
/variable/CYGWIN
- /variable/ENV
/variable/GHS-MULTI
+ /variable/IOS
/variable/MINGW
/variable/MSVC
/variable/MSVC10
@@ -225,7 +280,9 @@ Variables that Describe the System
/variable/MSVC80
/variable/MSVC90
/variable/MSVC_IDE
+ /variable/MSVC_TOOLSET_VERSION
/variable/MSVC_VERSION
+ /variable/MSYS
/variable/UNIX
/variable/WIN32
/variable/WINCE
@@ -267,8 +324,13 @@ Variables that Control the Build
/variable/CMAKE_ANDROID_STL_TYPE
/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY
/variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY_CONFIG
+ /variable/CMAKE_AUTOGEN_ORIGIN_DEPENDS
+ /variable/CMAKE_AUTOGEN_PARALLEL
+ /variable/CMAKE_AUTOGEN_VERBOSE
/variable/CMAKE_AUTOMOC
+ /variable/CMAKE_AUTOMOC_COMPILER_PREDEFINES
/variable/CMAKE_AUTOMOC_DEPEND_FILTERS
+ /variable/CMAKE_AUTOMOC_MACRO_NAMES
/variable/CMAKE_AUTOMOC_MOC_OPTIONS
/variable/CMAKE_AUTORCC
/variable/CMAKE_AUTORCC_OPTIONS
@@ -276,19 +338,28 @@ Variables that Control the Build
/variable/CMAKE_AUTOUIC_OPTIONS
/variable/CMAKE_AUTOUIC_SEARCH_PATHS
/variable/CMAKE_BUILD_RPATH
+ /variable/CMAKE_BUILD_RPATH_USE_ORIGIN
/variable/CMAKE_BUILD_WITH_INSTALL_NAME_DIR
/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_CUDA_SEPARABLE_COMPILATION
/variable/CMAKE_DEBUG_POSTFIX
/variable/CMAKE_ENABLE_EXPORTS
/variable/CMAKE_EXE_LINKER_FLAGS
/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG
/variable/CMAKE_EXE_LINKER_FLAGS_CONFIG_INIT
/variable/CMAKE_EXE_LINKER_FLAGS_INIT
+ /variable/CMAKE_FOLDER
+ /variable/CMAKE_FRAMEWORK
/variable/CMAKE_Fortran_FORMAT
/variable/CMAKE_Fortran_MODULE_DIRECTORY
+ /variable/CMAKE_GHS_NO_SOURCE_GROUP_FILE
+ /variable/CMAKE_GLOBAL_AUTOGEN_TARGET
+ /variable/CMAKE_GLOBAL_AUTOGEN_TARGET_NAME
+ /variable/CMAKE_GLOBAL_AUTORCC_TARGET
+ /variable/CMAKE_GLOBAL_AUTORCC_TARGET_NAME
/variable/CMAKE_GNUtoMS
/variable/CMAKE_INCLUDE_CURRENT_DIR
/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE
@@ -300,6 +371,7 @@ Variables that Control the Build
/variable/CMAKE_IOS_INSTALL_COMBINED
/variable/CMAKE_LANG_CLANG_TIDY
/variable/CMAKE_LANG_COMPILER_LAUNCHER
+ /variable/CMAKE_LANG_CPPCHECK
/variable/CMAKE_LANG_CPPLINT
/variable/CMAKE_LANG_INCLUDE_WHAT_YOU_USE
/variable/CMAKE_LANG_VISIBILITY_PRESET
@@ -319,6 +391,8 @@ Variables that Control the Build
/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG
/variable/CMAKE_MODULE_LINKER_FLAGS_CONFIG_INIT
/variable/CMAKE_MODULE_LINKER_FLAGS_INIT
+ /variable/CMAKE_MSVCIDE_RUN_PATH
+ /variable/CMAKE_MSVC_RUNTIME_LIBRARY
/variable/CMAKE_NINJA_OUTPUT_PATH_PREFIX
/variable/CMAKE_NO_BUILTIN_CHRPATH
/variable/CMAKE_NO_SYSTEM_FROM_IMPORTED
@@ -345,8 +419,18 @@ Variables that Control the Build
/variable/CMAKE_TRY_COMPILE_TARGET_TYPE
/variable/CMAKE_USE_RELATIVE_PATHS
/variable/CMAKE_VISIBILITY_INLINES_HIDDEN
+ /variable/CMAKE_VS_GLOBALS
/variable/CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD
/variable/CMAKE_VS_INCLUDE_PACKAGE_TO_DEFAULT_BUILD
+ /variable/CMAKE_VS_JUST_MY_CODE_DEBUGGING
+ /variable/CMAKE_VS_SDK_EXCLUDE_DIRECTORIES
+ /variable/CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES
+ /variable/CMAKE_VS_SDK_INCLUDE_DIRECTORIES
+ /variable/CMAKE_VS_SDK_LIBRARY_DIRECTORIES
+ /variable/CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES
+ /variable/CMAKE_VS_SDK_REFERENCE_DIRECTORIES
+ /variable/CMAKE_VS_SDK_SOURCE_DIRECTORIES
+ /variable/CMAKE_VS_WINRT_BY_DEFAULT
/variable/CMAKE_WIN32_EXECUTABLE
/variable/CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
/variable/CMAKE_XCODE_ATTRIBUTE_an-attribute
@@ -362,6 +446,7 @@ Variables for Languages
/variable/CMAKE_COMPILER_IS_GNUCC
/variable/CMAKE_COMPILER_IS_GNUCXX
/variable/CMAKE_COMPILER_IS_GNUG77
+ /variable/CMAKE_CUDA_HOST_COMPILER
/variable/CMAKE_CUDA_EXTENSIONS
/variable/CMAKE_CUDA_STANDARD
/variable/CMAKE_CUDA_STANDARD_REQUIRED
@@ -377,7 +462,6 @@ Variables for Languages
/variable/CMAKE_Fortran_MODDIR_DEFAULT
/variable/CMAKE_Fortran_MODDIR_FLAG
/variable/CMAKE_Fortran_MODOUT_FLAG
- /variable/CMAKE_INTERNAL_PLATFORM_ABI
/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_MACHINE
/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_PREFIX
/variable/CMAKE_LANG_ANDROID_TOOLCHAIN_SUFFIX
@@ -385,10 +469,10 @@ Variables for Languages
/variable/CMAKE_LANG_ARCHIVE_CREATE
/variable/CMAKE_LANG_ARCHIVE_FINISH
/variable/CMAKE_LANG_COMPILER
- /variable/CMAKE_LANG_COMPILER_ABI
/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN
/variable/CMAKE_LANG_COMPILER_ID
/variable/CMAKE_LANG_COMPILER_LOADED
+ /variable/CMAKE_LANG_COMPILER_PREDEFINES_COMMAND
/variable/CMAKE_LANG_COMPILER_TARGET
/variable/CMAKE_LANG_COMPILER_VERSION
/variable/CMAKE_LANG_COMPILE_OBJECT
@@ -396,6 +480,8 @@ Variables for Languages
/variable/CMAKE_LANG_CREATE_SHARED_MODULE
/variable/CMAKE_LANG_CREATE_STATIC_LIBRARY
/variable/CMAKE_LANG_FLAGS
+ /variable/CMAKE_LANG_FLAGS_CONFIG
+ /variable/CMAKE_LANG_FLAGS_CONFIG_INIT
/variable/CMAKE_LANG_FLAGS_DEBUG
/variable/CMAKE_LANG_FLAGS_DEBUG_INIT
/variable/CMAKE_LANG_FLAGS_INIT
@@ -405,10 +491,6 @@ Variables for Languages
/variable/CMAKE_LANG_FLAGS_RELEASE_INIT
/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO
/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT
- /variable/CMAKE_LANG_GHS_KERNEL_FLAGS_DEBUG
- /variable/CMAKE_LANG_GHS_KERNEL_FLAGS_MINSIZEREL
- /variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELEASE
- /variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELWITHDEBINFO
/variable/CMAKE_LANG_IGNORE_EXTENSIONS
/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES
/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES
@@ -417,9 +499,10 @@ Variables for Languages
/variable/CMAKE_LANG_LIBRARY_ARCHITECTURE
/variable/CMAKE_LANG_LINKER_PREFERENCE
/variable/CMAKE_LANG_LINKER_PREFERENCE_PROPAGATES
+ /variable/CMAKE_LANG_LINKER_WRAPPER_FLAG
+ /variable/CMAKE_LANG_LINKER_WRAPPER_FLAG_SEP
/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
@@ -461,7 +544,7 @@ Variables for CTest
/variable/CTEST_CUSTOM_POST_TEST
/variable/CTEST_CUSTOM_PRE_MEMCHECK
/variable/CTEST_CUSTOM_PRE_TEST
- /variable/CTEST_CUSTOM_TEST_IGNORE
+ /variable/CTEST_CUSTOM_TESTS_IGNORE
/variable/CTEST_CUSTOM_WARNING_EXCEPTION
/variable/CTEST_CUSTOM_WARNING_MATCH
/variable/CTEST_CVS_CHECKOUT
@@ -480,6 +563,7 @@ Variables for CTest
/variable/CTEST_GIT_UPDATE_OPTIONS
/variable/CTEST_HG_COMMAND
/variable/CTEST_HG_UPDATE_OPTIONS
+ /variable/CTEST_LABELS_FOR_SUBPROJECTS
/variable/CTEST_MEMORYCHECK_COMMAND
/variable/CTEST_MEMORYCHECK_COMMAND_OPTIONS
/variable/CTEST_MEMORYCHECK_SANITIZER_OPTIONS
@@ -490,8 +574,10 @@ Variables for CTest
/variable/CTEST_P4_COMMAND
/variable/CTEST_P4_OPTIONS
/variable/CTEST_P4_UPDATE_OPTIONS
+ /variable/CTEST_RUN_CURRENT_SCRIPT
/variable/CTEST_SCP_COMMAND
/variable/CTEST_SITE
+ /variable/CTEST_SUBMIT_URL
/variable/CTEST_SOURCE_DIRECTORY
/variable/CTEST_SVN_COMMAND
/variable/CTEST_SVN_OPTIONS
@@ -502,6 +588,7 @@ Variables for CTest
/variable/CTEST_UPDATE_COMMAND
/variable/CTEST_UPDATE_OPTIONS
/variable/CTEST_UPDATE_VERSION_ONLY
+ /variable/CTEST_UPDATE_VERSION_OVERRIDE
/variable/CTEST_USE_LAUNCHERS
Variables for CPack
@@ -514,7 +601,37 @@ Variables for CPack
/variable/CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY
/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
/variable/CPACK_INCLUDE_TOPLEVEL_DIRECTORY
+ /variable/CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
/variable/CPACK_INSTALL_SCRIPT
/variable/CPACK_PACKAGING_INSTALL_PREFIX
/variable/CPACK_SET_DESTDIR
/variable/CPACK_WARN_ON_ABSOLUTE_INSTALL_DESTINATION
+
+Variable Expansion Operators
+============================
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/CACHE
+ /variable/ENV
+
+Internal Variables
+==================
+
+CMake has many internal variables. Most of them are undocumented.
+Some of them, however, were at some point described as normal
+variables, and therefore may be encountered in legacy code. They
+are subject to change, and not recommended for use in project code.
+
+.. toctree::
+ :maxdepth: 1
+
+ /variable/CMAKE_HOME_DIRECTORY
+ /variable/CMAKE_INTERNAL_PLATFORM_ABI
+ /variable/CMAKE_LANG_COMPILER_ABI
+ /variable/CMAKE_LANG_COMPILER_ARCHITECTURE_ID
+ /variable/CMAKE_LANG_COMPILER_VERSION_INTERNAL
+ /variable/CMAKE_LANG_PLATFORM_ID
+ /variable/CMAKE_NOT_USING_CONFIG_FLAGS
+ /variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst
index ba925e8ec..7b5399d21 100644
--- a/Help/manual/cmake.1.rst
+++ b/Help/manual/cmake.1.rst
@@ -8,72 +8,190 @@ 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>...
+ `Generate a Project Buildsystem`_
+ cmake [<options>] <path-to-source>
+ cmake [<options>] <path-to-existing-build>
+ cmake [<options>] -S <path-to-source> -B <path-to-build>
+
+ `Build a Project`_
+ cmake --build <dir> [<options>] [-- <build-tool-options>]
+
+ `Install a Project`_
+ cmake --install <dir> [<options>]
+
+ `Open a Project`_
+ cmake --open <dir>
+
+ `Run a Script`_
+ cmake [{-D <var>=<value>}...] -P <cmake-script-file>
+
+ `Run a Command-Line Tool`_
+ cmake -E <command> [<options>]
+
+ `Run the Find-Package Tool`_
+ cmake --find-package [<options>]
+
+ `View Help`_
+ cmake --help[-<topic>]
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.
+The **cmake** executable is the command-line interface of the cross-platform
+buildsystem generator CMake. The above `Synopsis`_ lists various actions
+the tool can perform as described in sections below.
+
+To build a software project with CMake, `Generate a Project Buildsystem`_.
+Optionally use **cmake** to `Build a Project`_, `Install a Project`_ or just
+run the corresponding build tool (e.g. ``make``) directly. **cmake** can also
+be used to `View Help`_.
+
+The other actions are meant for use by software developers writing
+scripts in the :manual:`CMake language <cmake-language(7)>` to support
+their builds.
+
+For graphical user interfaces that may be used in place of **cmake**,
+see :manual:`ccmake <ccmake(1)>` and :manual:`cmake-gui <cmake-gui(1)>`.
+For command-line interfaces to the CMake testing and packaging facilities,
+see :manual:`ctest <ctest(1)>` and :manual:`cpack <cpack(1)>`.
+
+For more information on CMake at large, `see also`_ the links at the end
+of this manual.
+
+
+Introduction to CMake Buildsystems
+==================================
+
+A *buildsystem* describes how to build a project's executables and libraries
+from its source code using a *build tool* to automate the process. For
+example, a buildsystem may be a ``Makefile`` for use with a command-line
+``make`` tool or a project file for an Integrated Development Environment
+(IDE). In order to avoid maintaining multiple such buildsystems, a project
+may specify its buildsystem abstractly using files written in the
+:manual:`CMake language <cmake-language(7)>`. From these files CMake
+generates a preferred buildsystem locally for each user through a backend
+called a *generator*.
+
+To generate a buildsystem with CMake, the following must be selected:
+
+Source Tree
+ The top-level directory containing source files provided by the project.
+ The project specifies its buildsystem using files as described in the
+ :manual:`cmake-language(7)` manual, starting with a top-level file named
+ ``CMakeLists.txt``. These files specify build targets and their
+ dependencies as described in the :manual:`cmake-buildsystem(7)` manual.
+
+Build Tree
+ The top-level directory in which buildsystem files and build output
+ artifacts (e.g. executables and libraries) are to be stored.
+ CMake will write a ``CMakeCache.txt`` file to identify the directory
+ as a build tree and store persistent information such as buildsystem
+ configuration options.
+
+ To maintain a pristine source tree, perform an *out-of-source* build
+ by using a separate dedicated build tree. An *in-source* build in
+ which the build tree is placed in the same directory as the source
+ tree is also supported, but discouraged.
+
+Generator
+ This chooses the kind of buildsystem to generate. See the
+ :manual:`cmake-generators(7)` manual for documentation of all generators.
+ Run ``cmake --help`` to see a list of generators available locally.
+ Optionally use the ``-G`` option below to specify a generator, or simply
+ accept the default CMake chooses for the current platform.
+
+ When using one of the :ref:`Command-Line Build Tool Generators`
+ CMake expects that the environment needed by the compiler toolchain
+ is already configured in the shell. When using one of the
+ :ref:`IDE Build Tool Generators`, no particular environment is needed.
+
+
+Generate a Project Buildsystem
+==============================
+
+Run CMake with one of the following command signatures to specify the
+source and build trees and generate a buildsystem:
+
+``cmake [<options>] <path-to-source>``
+ Uses the current working directory as the build tree, and
+ ``<path-to-source>`` as the source tree. The specified path may
+ be absolute or relative to the current working directory.
+ The source tree must contain a ``CMakeLists.txt`` file and must
+ *not* contain a ``CMakeCache.txt`` file because the latter
+ identifies an existing build tree. For example:
+
+ .. code-block:: console
+
+ $ mkdir build ; cd build
+ $ cmake ../src
+
+``cmake [<options>] <path-to-existing-build>``
+ Uses ``<path-to-existing-build>`` as the build tree, and loads the
+ path to the source tree from its ``CMakeCache.txt`` file, which must
+ have already been generated by a previous run of CMake. The specified
+ path may be absolute or relative to the current working directory.
+ For example:
+
+ .. code-block:: console
+
+ $ cd build
+ $ cmake .
+
+``cmake [<options>] -S <path-to-source> -B <path-to-build>``
+ Uses ``<path-to-build>`` as the build tree and ``<path-to-source>``
+ as the source tree. The specified paths may be absolute or relative
+ to the current working directory. The source tree must contain a
+ ``CMakeLists.txt`` file. The build tree will be created automatically
+ if it does not already exist. For example:
-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.
+ .. code-block:: console
+
+ $ cmake -S src -B build
+
+In all cases the ``<options>`` may be zero or more of the `Options`_ below.
+
+After generating a buildsystem one may use the corresponding native
+build tool to build the project. For example, after using the
+:generator:`Unix Makefiles` generator one may run ``make`` directly:
+
+ .. code-block:: console
+
+ $ make
+ $ make install
+
+Alternatively, one may use **cmake** to `Build a Project`_ by
+automatically choosing and invoking the appropriate native build tool.
.. _`CMake Options`:
Options
-=======
+-------
.. include:: OPTIONS_BUILD.txt
-``-E <command> [<options>...]``
- See `Command-Line Tool Mode`_.
-
``-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
+ List ``CACHE`` variables will run CMake and list all the variables from
+ the CMake ``CACHE`` that are not marked as ``INTERNAL`` or :prop_cache:`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>``
- See `Build Tool Mode`_.
-
``-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``
- See `Find-Package Tool Mode`_.
-
``--graphviz=[file]``
- Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for more.
+ Generate graphviz of dependencies, see :module:`CMakeGraphVizOptions` 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.
+ :module:`CMakeGraphVizOptions` for more details.
``--system-information [file]``
Dump information about this system.
@@ -82,10 +200,17 @@ Options
from the top of a binary tree for a CMake project it will dump
additional information such as the cache, log files etc.
+``--loglevel=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>``
+ Set the log level.
+
+ The :command:`message` command will only output messages of the specified
+ log level or higher. The default log level is ``STATUS``.
+
``--debug-trycompile``
- Do not delete the try_compile build tree. Only useful on one try_compile at a time.
+ Do not delete the :command:`try_compile` build tree.
+ Only useful on one :command:`try_compile` at a time.
- Do not delete the files and directories created for try_compile
+ Do not delete the files and directories created for :command:`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
@@ -96,7 +221,7 @@ Options
Put cmake in a debug mode.
Print extra information during the cmake run like stack traces with
- message(send_error ) calls.
+ :command:`message(SEND_ERROR)` calls.
``--trace``
Put cmake in trace mode.
@@ -133,18 +258,20 @@ Options
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.
+ in :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR`.
+ This flag tells CMake to warn about other files as well.
-.. include:: OPTIONS_HELP.txt
+.. _`Build Tool Mode`:
-Build Tool Mode
+Build a Project
===============
CMake provides a command-line signature to build an already-generated
-project binary tree::
+project binary tree:
+
+.. code-block:: shell
- cmake --build <dir> [<options>...] [-- <build-tool-options>...]
+ cmake --build <dir> [<options>] [-- <build-tool-options>]
This abstracts a native build tool's command-line interface with the
following options:
@@ -152,8 +279,19 @@ following options:
``--build <dir>``
Project binary directory to be built. This is required and must be first.
-``--target <tgt>``
- Build ``<tgt>`` instead of default targets. May only be specified once.
+``--parallel [<jobs>], -j [<jobs>]``
+ The maximum number of concurrent processes to use when building.
+ If ``<jobs>`` is omitted the native build tool's default number is used.
+
+ The :envvar:`CMAKE_BUILD_PARALLEL_LEVEL` environment variable, if set,
+ specifies a default parallel level when this option is not given.
+
+ Some native build tools always build in parallel. The use of ``<jobs>``
+ value of ``1`` can be used to limit to a single job.
+
+``--target <tgt>..., -t <tgt>...``
+ Build ``<tgt>`` instead of the default target. Multiple targets may be
+ given, separated by spaces.
``--config <cfg>``
For multi-configuration tools, choose configuration ``<cfg>``.
@@ -165,17 +303,89 @@ following options:
``--use-stderr``
Ignored. Behavior is default in CMake >= 3.0.
+``--verbose, -v``
+ Enable verbose output - if supported - including the build commands to be
+ executed.
+
+ This option can be omitted if :envvar:`VERBOSE` environment variable or
+ :variable:`CMAKE_VERBOSE_MAKEFILE` cached variable is set.
+
+
``--``
Pass remaining options to the native tool.
Run ``cmake --build`` with no options for quick help.
-Command-Line Tool Mode
-======================
+Install a Project
+=================
+
+CMake provides a command-line signature to install an already-generated
+project binary tree:
+
+.. code-block:: shell
+
+ cmake --install <dir> [<options>]
-CMake provides builtin command-line tools through the signature::
+This may be used after building a project to run installation without
+using the generated build system or the native build tool.
+The options are:
+
+``--install <dir>``
+ Project binary directory to install. This is required and must be first.
+
+``--config <cfg>``
+ For multi-configuration generators, choose configuration ``<cfg>``.
- cmake -E <command> [<options>...]
+``--component <comp>``
+ Component-based install. Only install component ``<comp>``.
+
+``--prefix <prefix>``
+ Override the installation prefix, :variable:`CMAKE_INSTALL_PREFIX`.
+
+``--strip``
+ Strip before installing.
+
+``-v, --verbose``
+ Enable verbose output.
+
+ This option can be omitted if :envvar:`VERBOSE` environment variable is set.
+
+Run ``cmake --install`` with no options for quick help.
+
+Open a Project
+==============
+
+.. code-block:: shell
+
+ cmake --open <dir>
+
+Open the generated project in the associated application. This is only
+supported by some generators.
+
+
+.. _`Script Processing Mode`:
+
+Run a Script
+============
+
+.. code-block:: shell
+
+ cmake [{-D <var>=<value>}...] -P <cmake-script-file>
+
+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.
+
+
+Run a Command-Line Tool
+=======================
+
+CMake provides builtin command-line tools through the signature
+
+.. code-block:: shell
+
+ cmake -E <command> [<options>]
Run ``cmake -E`` or ``cmake -E help`` for a summary of commands.
Available commands are:
@@ -214,30 +424,51 @@ Available commands are:
A list of strings with all the extra generators compatible with
the generator.
+ ``fileApi``
+ Optional member that is present when the :manual:`cmake-file-api(7)`
+ is available. The value is a JSON object with one member:
+
+ ``requests``
+ A JSON array containing zero or more supported file-api requests.
+ Each request is a JSON object with members:
+
+ ``kind``
+ Specifies one of the supported :ref:`file-api object kinds`.
+
+ ``version``
+ A JSON array whose elements are each a JSON object containing
+ ``major`` and ``minor`` members specifying non-negative integer
+ version components.
+
``serverMode``
``true`` if cmake supports server-mode and ``false`` otherwise.
``chdir <dir> <cmd> [<arg>...]``
Change the current working directory and run a command.
-``compare_files <file1> <file2>``
+``compare_files [--ignore-eol] <file1> <file2>``
Check if ``<file1>`` is same as ``<file2>``. If files are the same,
- then returns 0, if not it returns 1.
+ then returns ``0``, if not it returns ``1``. The ``--ignore-eol`` option
+ implies line-wise comparison and ignores LF/CRLF differences.
``copy <file>... <destination>``
Copy files to ``<destination>`` (either file or directory).
If multiple files are specified, the ``<destination>`` must be
directory and it must exist. Wildcards are not supported.
+ ``copy`` does follow symlinks. That means it does not copy symlinks,
+ but the files or directories it point to.
``copy_directory <dir>... <destination>``
Copy directories to ``<destination>`` directory.
If ``<destination>`` directory does not exist it will be created.
+ ``copy_directory`` does follow symlinks.
``copy_if_different <file>... <destination>``
Copy files to ``<destination>`` (either file or directory) if
they have changed.
If multiple files are specified, the ``<destination>`` must be
directory and it must exist.
+ ``copy_if_different`` does follow symlinks.
``echo [<string>...]``
Displays arguments as text.
@@ -262,18 +493,51 @@ Available commands are:
351abe79cd3800b38cdfb25d45015a15 file1.txt
052f86c15bbde68af55c7f7b340ab639 file2.txt
+``sha1sum <file>...``
+ Create SHA1 checksum of files in ``sha1sum`` compatible format::
+
+ 4bb7932a29e6f73c97bb9272f2bdc393122f86e0 file1.txt
+ 1df4c8f318665f9a5f2ed38f55adadb7ef9f559c file2.txt
+
+``sha224sum <file>...``
+ Create SHA224 checksum of files in ``sha224sum`` compatible format::
+
+ b9b9346bc8437bbda630b0b7ddfc5ea9ca157546dbbf4c613192f930 file1.txt
+ 6dfbe55f4d2edc5fe5c9197bca51ceaaf824e48eba0cc453088aee24 file2.txt
+
+``sha256sum <file>...``
+ Create SHA256 checksum of files in ``sha256sum`` compatible format::
+
+ 76713b23615d31680afeb0e9efe94d47d3d4229191198bb46d7485f9cb191acc file1.txt
+ 15b682ead6c12dedb1baf91231e1e89cfc7974b3787c1e2e01b986bffadae0ea file2.txt
+
+``sha384sum <file>...``
+ Create SHA384 checksum of files in ``sha384sum`` compatible format::
+
+ acc049fedc091a22f5f2ce39a43b9057fd93c910e9afd76a6411a28a8f2b8a12c73d7129e292f94fc0329c309df49434 file1.txt
+ 668ddeb108710d271ee21c0f3acbd6a7517e2b78f9181c6a2ff3b8943af92b0195dcb7cce48aa3e17893173c0a39e23d file2.txt
+
+``sha512sum <file>...``
+ Create SHA512 checksum of files in ``sha512sum`` compatible format::
+
+ 2a78d7a6c5328cfb1467c63beac8ff21794213901eaadafd48e7800289afbc08e5fb3e86aa31116c945ee3d7bf2a6194489ec6101051083d1108defc8e1dba89 file1.txt
+ 7a0b54896fe5e70cca6dd643ad6f672614b189bf26f8153061c4d219474b05dad08c4e729af9f4b009f1a1a280cb625454bf587c690f4617c27e3aebdf3b7a2d file2.txt
+
``remove [-f] <file>...``
Remove the file(s). If any of the listed files already do not
exist, the command returns a non-zero exit code, but no message
is logged. The ``-f`` option changes the behavior to return a
zero exit code (i.e. success) in such situations instead.
+ ``remove`` does not follow symlinks. That means it remove only symlinks
+ and not files it point to.
-``remove_directory <dir>``
- Remove a directory and its contents. If a directory does
+``remove_directory <dir>...``
+ Remove ``<dir>`` directories and their contents. If a directory does
not exist it will be silently ignored.
``rename <oldname> <newname>``
- Rename a file or directory (on one volume).
+ Rename a file or directory (on one volume). If file with the ``<newname>`` name
+ already exists, then it will be silently replaced.
``server``
Launch :manual:`cmake-server(7)` mode.
@@ -281,39 +545,59 @@ Available commands are:
``sleep <number>...``
Sleep for given number of seconds.
-``tar [cxt][vf][zjJ] file.tar [<options>...] [--] [<file>...]``
+``tar [cxt][vf][zjJ] file.tar [<options>] [--] [<pathname>...]``
Create or extract a tar or zip archive. Options are:
- ``--``
- Stop interpreting options and treat all remaining arguments
- as file names even if they start in ``-``.
+ ``c``
+ Create a new archive containing the specified files.
+ If used, the ``<pathname>...`` argument is mandatory.
+ ``x``
+ Extract to disk from the archive.
+ The ``<pathname>...`` argument could be used to extract only selected files
+ or directories.
+ When extracting selected files or directories, you must provide their exact
+ names including the path, as printed by list (``-t``).
+ ``t``
+ List archive contents.
+ The ``<pathname>...`` argument could be used to list only selected files
+ or directories.
+ ``v``
+ Produce verbose output.
+ ``z``
+ Compress the resulting archive with gzip.
+ ``j``
+ Compress the resulting archive with bzip2.
+ ``J``
+ Compress the resulting archive with XZ.
+ ``--zstd``
+ Compress the resulting archive with Zstandard.
``--files-from=<file>``
Read file names from the given file, one per line.
Blank lines are ignored. Lines may not start in ``-``
except for ``--add-file=<name>`` to add files whose
names start in ``-``.
- ``--mtime=<date>``
- Specify modification time recorded in tarball entries.
``--format=<format>``
Specify the format of the archive to be created.
Supported formats are: ``7zip``, ``gnutar``, ``pax``,
``paxr`` (restricted pax, default), and ``zip``.
+ ``--mtime=<date>``
+ Specify modification time recorded in tarball entries.
+ ``--``
+ Stop interpreting options and treat all remaining arguments
+ as file names, even if they start with ``-``.
+
``time <command> [<args>...]``
- Run command and return elapsed time.
+ Run command and display elapsed time.
-``touch <file>``
- Touch a file.
+``touch <file>...``
+ Creates ``<file>`` if file do not exist.
+ If ``<file>`` exists, it is changing ``<file>`` access and modification times.
-``touch_nocreate <file>``
+``touch_nocreate <file>...``
Touch a file if it exists but do not create it. If a file does
not exist it will be silently ignored.
-UNIX-specific Command-Line Tools
---------------------------------
-
-The following ``cmake -E`` commands are available only on UNIX:
-
``create_symlink <old> <new>``
Create a symbolic link ``<new>`` naming ``<old>``.
@@ -339,24 +623,40 @@ The following ``cmake -E`` commands are available only on Windows:
``write_regv <key> <value>``
Write Windows registry value.
-Find-Package Tool Mode
-======================
-CMake provides a helper for Makefile-based projects with the signature::
+Run the Find-Package Tool
+=========================
+
+CMake provides a pkg-config like helper for Makefile-based projects:
- cmake --find-package <options>...
+.. code-block:: shell
-This runs in a pkg-config like mode.
+ cmake --find-package [<options>]
-Search a package using :command:`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``).
+It searches a package using :command:`find_package()` and prints the
+resulting flags to stdout. This can be used instead of pkg-config
+to find installed libraries in plain Makefile-based projects or in
+autoconf-based projects (via ``share/aclocal/cmake.m4``).
.. note::
This mode is not well-supported due to some technical limitations.
It is kept for compatibility but should not be used in new projects.
+
+View Help
+=========
+
+To print selected pages from the CMake documentation, use
+
+.. code-block:: shell
+
+ cmake --help[-<topic>]
+
+with one of the following options:
+
+.. include:: OPTIONS_HELP.txt
+
+
See Also
========
diff --git a/Help/manual/cpack.1.rst b/Help/manual/cpack.1.rst
index 4f9f28d4e..10f617e68 100644
--- a/Help/manual/cpack.1.rst
+++ b/Help/manual/cpack.1.rst
@@ -8,86 +8,98 @@ Synopsis
.. parsed-literal::
- cpack -G <generator> [<options>]
+ cpack [<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.
+The **cpack** executable is the CMake packaging program. It generates
+installers and source packages in a variety of formats.
-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.
+For each installer or package format, **cpack** has a specific backend,
+called "generator". A generator is responsible for generating the required
+inputs and invoking the specific package creation tools. These installer
+or package generators are not to be confused with the makefile generators
+of the :manual:`cmake <cmake(1)>` command.
+
+All supported generators are specified in the :manual:`cpack-generators
+<cpack-generators(7)>` manual. The command ``cpack --help`` prints a
+list of generators supported for the target platform. Which of them are
+to be used can be selected through the :variable:`CPACK_GENERATOR` variable
+or through the command-line option ``-G``.
+
+The **cpack** program is steered by a configuration file written in the
+:manual:`CMake language <cmake-language(7)>`. Unless chosen differently
+through the command-line option ``--config``, the file ``CPackConfig.cmake``
+in the current directory is used.
+
+In the standard CMake workflow, the file ``CPackConfig.cmake`` is generated
+by the :manual:`cmake <cmake(1)>` executable, provided the :module:`CPack`
+module is included by the project's ``CMakeLists.txt`` file.
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.
+``-G <generators>``
+ ``<generators>`` is a :ref:`semicolon-separated list <CMake Language Lists>`
+ of generator names. ``cpack`` will iterate through this list and produce
+ package(s) in that generator's format according to the details provided in
+ the ``CPackConfig.cmake`` configuration file. If this option is not given,
+ the :variable:`CPACK_GENERATOR` variable determines the default set of
+ generators that will be used.
``-C <Configuration>``
- Specify the project configuration
-
- This option specifies the configuration that the project was build
- with, for example 'Debug', 'Release'.
+ Specify the project configuration to be packaged (e.g. ``Debug``,
+ ``Release``, etc.). When the CMake project uses a multi-configuration
+ generator such as Xcode or Visual Studio, this option is needed to tell
+ ``cpack`` which built executables to include in the package.
``-D <var>=<value>``
- Set a CPack variable.
+ Set a CPack variable. This will override any value set for ``<var>`` in the
+ input file read by ``cpack``.
- Set a variable that can be used by the generator.
+``--config <configFile>``
+ Specify the configuration file read by ``cpack`` to provide the packaging
+ details. By default, ``CPackConfig.cmake`` in the current directory will
+ be used.
-``--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.
+``--verbose, -V``
+ Run ``cpack`` with verbose output. This can be used to show more details
+ from the package generation tools and is suitable for project developers.
``--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 command 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
+ Run ``cpack`` with debug output. This option is intended mainly for the
+ developers of ``cpack`` itself and is not normally needed by project
+ developers.
+
+``--trace``
+ Put the underlying cmake scripts in trace mode.
+
+``--trace-expand``
+ Put the underlying cmake scripts in expanded trace mode.
+
+``-P <packageName>``
+ Override/define the value of the :variable:`CPACK_PACKAGE_NAME` variable used
+ for packaging. Any value set for this variable in the ``CPackConfig.cmake``
+ file will then be ignored.
+
+``-R <packageVersion>``
+ Override/define the value of the :variable:`CPACK_PACKAGE_VERSION`
+ variable used for packaging. It will override a value set in the
+ ``CPackConfig.cmake`` file or one automatically computed from
+ :variable:`CPACK_PACKAGE_VERSION_MAJOR`,
+ :variable:`CPACK_PACKAGE_VERSION_MINOR` and
+ :variable:`CPACK_PACKAGE_VERSION_PATCH`.
+
+``-B <packageDirectory>``
+ Override/define :variable:`CPACK_PACKAGE_DIRECTORY`, which controls the
+ directory where CPack will perform its packaging work. The resultant
+ package(s) will be created at this location by default and a
+ ``_CPack_Packages`` subdirectory will also be created below this directory to
+ use as a working area during package creation.
+
+``--vendor <vendorName>``
+ Override/define :variable:`CPACK_PACKAGE_VENDOR`.
.. include:: OPTIONS_HELP.txt
diff --git a/Help/manual/ctest.1.rst b/Help/manual/ctest.1.rst
index a89c4e9bb..5773176e6 100644
--- a/Help/manual/ctest.1.rst
+++ b/Help/manual/ctest.1.rst
@@ -3,20 +3,27 @@
ctest(1)
********
+.. contents::
+
Synopsis
========
.. parsed-literal::
ctest [<options>]
+ ctest --build-and-test <path-to-source> <path-to-build>
+ --build-generator <generator> [<options>...]
+ [--build-options <opts>...] [--test-command <command> [<args>...]]
+ ctest {-D <dashboard> | -M <model> -T <action> | -S <script> | -SP <script>}
+ [-- <dashboard-options>...]
Description
===========
-The "ctest" executable is the CMake test driver program.
+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.
+:command:`enable_testing` and :command:`add_test` commands have testing support.
+This program will run the tests and report results.
Options
=======
@@ -26,8 +33,21 @@ Options
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".
+ which one should be tested. Example configurations are ``Debug`` and
+ ``Release``.
+
+``--progress``
+ Enable short progress output from tests.
+
+ When the output of **ctest** is being sent directly to a terminal, the
+ progress through the set of tests is reported by updating the same line
+ rather than printing start and end messages for each test on new lines.
+ This can significantly reduce the verbosity of the test output.
+ Test completion messages are still output on their own line for failed
+ tests and the final test summary will also still be logged.
+
+ This option can also be enabled by setting the environment variable
+ :envvar:`CTEST_PROGRESS_OUTPUT`.
``-V,--verbose``
Enable verbose output from tests.
@@ -49,22 +69,26 @@ Options
``--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``.
+ This option can also be enabled by setting the
+ :envvar:`CTEST_OUTPUT_ON_FAILURE` environment variable
``-F``
Enable failover.
- This option allows ctest to resume a test set execution that was
+ 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 the given 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``.
+ This option tells CTest to run the tests in parallel using given
+ number of jobs. This option can also be set by setting the
+ :envvar:`CTEST_PARALLEL_LEVEL` environment variable.
+
+ This option can be used with the :prop_test:`PROCESSORS` test property.
+
+ See `Label and Subproject Summary`_.
``--test-load <level>``
While running tests in parallel (e.g. with ``-j``), try not to start
@@ -74,7 +98,7 @@ Options
``TestLoad`` option of the `CTest Test Step`_.
``-Q,--quiet``
- Make ctest 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
@@ -84,37 +108,47 @@ Options
``-O <file>, --output-log <file>``
Output to log file.
- This option tells ctest to write all its output to a log file.
+ This option tells CTest to write all its output to a ``<file>`` log file.
-``-N,--show-only``
+``-N,--show-only[=<format>]``
Disable actual execution of tests.
- This option tells ctest to list the tests that would be run but not
+ 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.
+ ``<format>`` can be one of the following values.
+
+ ``human``
+ Human-friendly output. This is not guaranteed to be stable.
+ This is the default.
+
+ ``json-v1``
+ Dump the test information in JSON format.
+ See `Show as JSON Object Model`_.
+
``-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
+ 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
+ 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
+ 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
+ This option tells CTest to NOT run the tests whose labels match the
given regular expression.
``-FA <regex>, --fixture-exclude-any <regex>``
@@ -137,10 +171,13 @@ Options
``-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.
+ 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``.
+
+ See `Dashboard Client`_.
``-D <var>:<type>=<value>``
Define a variable for script mode.
@@ -153,35 +190,33 @@ Options
``-M <model>, --test-model <model>``
Sets the model for a dashboard.
- This option tells ctest to act as a CDash client where the ``<model>``
+ This option tells CTest to act as a CDash client where the ``<model>``
can be ``Experimental``, ``Nightly``, and ``Continuous``.
Combining ``-M`` and ``-T`` is similar to ``-D``.
+ See `Dashboard Client`_.
+
``-T <action>, --test-action <action>``
Sets the dashboard action to perform.
- This option tells ctest to act as a CDash client and perform some
+ This option tells CTest to act as a CDash client and perform some
action such as ``start``, ``build``, ``test`` etc. See
`Dashboard Client Steps`_ for the full list of actions.
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.
+ See `Dashboard Client`_.
``-S <script>, --script <script>``
Execute a dashboard for a configuration.
- This option tells ctest to load in a configuration script which sets
+ 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.
+ 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.
+ See `Dashboard Client`_.
+
``-SP <script>, --script-new-process <script>``
Execute a dashboard for a configuration.
@@ -190,19 +225,15 @@ Options
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.
+ See `Dashboard Client`_.
``-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
+ 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``
@@ -214,11 +245,11 @@ Options
``--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
+ 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
+ fail, subsequent calls to CTest with the ``--rerun-failed`` option will run
the set of tests that most recently failed (if any).
``--repeat-until-fail <n>``
@@ -234,41 +265,154 @@ Options
name which can be very annoying.
``--interactive-debug-mode [0|1]``
- Set the interactive mode to 0 or 1.
+ Set the interactive mode to ``0`` or ``1``.
- This option causes ctest to run tests in either an interactive mode
+ 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
+ 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
+ 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 <path-to-source> <path-to-build>``
- Configure, build and run a test.
+ See `Label and Subproject Summary`_.
+
+``--no-subproject-summary``
+ Disable timing summary information for subprojects.
+
+ This option tells CTest not to print summary information for each
+ subproject associated with the tests run. If there are no subprojects on the
+ tests, nothing extra is printed.
+
+ See `Label and Subproject Summary`_.
+
+``--build-and-test``
+See `Build and Test Mode`_.
+
+``--test-output-size-passed <size>``
+ Limit the output for passed tests to ``<size>`` bytes.
+
+``--test-output-size-failed <size>``
+ Limit the output for failed tests to ``<size>`` bytes.
- 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.
- 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`` and ``--build-options``.
+``--overwrite``
+ Overwrite CTest configuration option.
+
+ By default CTest uses configuration options from configuration file.
+ This option will overwrite the configuration option.
+
+``--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 the default test timeout.
+
+ This option effectively sets a timeout on all tests that do not
+ already have a timeout set on them via the :prop_test:`TIMEOUT`
+ property.
+
+``--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.
+
+``--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
+
+.. _`Label and Subproject Summary`:
+
+Label and Subproject Summary
+============================
+
+CTest prints timing summary information for each ``LABEL`` and subproject
+associated with the tests run. The label time summary will not include labels
+that are mapped to subprojects.
+
+When the :prop_test:`PROCESSORS` test property is set, CTest will display a
+weighted test timing result in label and subproject summaries. The time is
+reported with `sec*proc` instead of just `sec`.
+
+The weighted time summary reported for each label or subproject ``j``
+is computed as::
+
+ Weighted Time Summary for Label/Subproject j =
+ sum(raw_test_time[j,i] * num_processors[j,i], i=1...num_tests[j])
+
+ for labels/subprojects j=1...total
+
+where:
+
+* ``raw_test_time[j,i]``: Wall-clock time for the ``i`` test
+ for the ``j`` label or subproject
+* ``num_processors[j,i]``: Value of the CTest :prop_test:`PROCESSORS` property
+ for the ``i`` test for the ``j`` label or subproject
+* ``num_tests[j]``: Number of tests associated with the ``j`` label or subproject
+* ``total``: Total number of labels or subprojects that have at least one test run
+
+Therefore, the weighted time summary for each label or subproject represents
+the amount of time that CTest gave to run the tests for each label or
+subproject and gives a good representation of the total expense of the tests
+for each label or subproject when compared to other labels or subprojects.
+
+For example, if ``SubprojectA`` showed ``100 sec*proc`` and ``SubprojectB`` showed
+``10 sec*proc``, then CTest allocated approximately 10 times the CPU/core time
+to run the tests for ``SubprojectA`` than for ``SubprojectB`` (e.g. so if effort
+is going to be expended to reduce the cost of the test suite for the whole
+project, then reducing the cost of the test suite for ``SubprojectA`` would
+likely have a larger impact than effort to reduce the cost of the test suite
+for ``SubprojectB``).
+
+.. _`Build and Test Mode`:
+
+Build and Test Mode
+===================
+
+CTest provides a command-line signature to configure (i.e. run cmake on),
+build, and/or execute a test::
+
+ ctest --build-and-test <path-to-source> <path-to-build>
+ --build-generator <generator>
+ [<options>...]
+ [--build-options <opts>...]
+ [--test-command <command> [<args>...]]
+
+The configure and test steps are optional. The arguments to this command line
+are the source and binary directories. 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 include:
``--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.
+ If left out the ``all`` target is built.
``--build-nocmake``
Run the build without running cmake first.
@@ -306,84 +450,66 @@ Options
``--build-config-sample``
A sample executable to use to determine the configuration that
- should be used. e.g. Debug/Release/etc.
+ 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``
+ Additional options for configuring the build (i.e. for CMake, not for
+ the build tool). Note that if this is specified, the ``--build-options``
+ keyword and its arguments must be the last option given on the command
+ line, with the possible exception of ``--test-command``.
``--test-command``
- The test to run with the ``--build-and-test`` option.
-
-``--test-output-size-passed <size>``
- Limit the output for passed tests to ``<size>`` bytes.
-
-``--test-output-size-failed <size>``
- Limit the output for failed tests to ``<size>`` bytes.
+ The command to run as the test step with the ``--build-and-test`` option.
+ All arguments following this keyword will be assumed to be part of the
+ test command line, so it must be the last option given.
``--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.
+ The time limit in seconds
-``--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.
+.. _`Dashboard Client`:
- By default ctest uses configuration options from configuration file.
- This option will overwrite the configuration option.
+Dashboard Client
+================
-``--extra-submit <file>[;<file>]``
- Submit extra files to the dashboard.
+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. The command-line signature used to submit to `CDash`_ is::
- This option will submit extra files to the dashboard.
+ ctest (-D <dashboard> | -M <model> -T <action> | -S <script> | -SP <script>)
+ [-- <dashboard-options>...]
-``--force-new-ctest-process``
- Run child CTest instances as new processes.
+Options for Dashboard Client include:
- 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.
+``--track <track>``
+ Specify the track to submit dashboard to
-``--schedule-random``
- Use a random order for scheduling tests.
+ 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.
- This option will run the tests in a random order. It is commonly
- used to detect implicit dependencies in a test suite.
+``-A <file>, --add-notes <file>``
+ Add a notes file with submission.
-``--submit-index``
- Legacy option for old Dart2 dashboard server feature.
- Do not use.
+ This option tells CTest to include a notes file when submitting
+ dashboard.
-``--timeout <seconds>``
- Set a global timeout on all tests.
+``--tomorrow-tag``
+ ``Nightly`` or ``Experimental`` starts with next day tag.
- This option will set a global timeout on all tests that do not
- already have a timeout set on them.
+ This is useful if the build will not finish in one day.
-``--stop-time <time>``
- Set a time at which all tests should stop running.
+``--extra-submit <file>[;<file>]``
+ Submit extra files to the dashboard.
- 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.
+ This option will submit extra files to the dashboard.
``--http1.0``
- Submit using HTTP 1.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.
+ 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.
@@ -392,26 +518,6 @@ Options
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`:
-
-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
----------------------
@@ -606,7 +712,7 @@ Configuration settings to specify the version control tool include:
The source tree is updated by ``git fetch`` followed by
``git reset --hard`` to the ``FETCH_HEAD``. The result is the same
- as ``git pull`` except that any local moficiations are overwritten.
+ as ``git pull`` except that any local modifications are overwritten.
Use ``GITUpdateCustom`` to specify a different approach.
``GITInitSubmodules``
@@ -716,6 +822,8 @@ Configuration settings to specify the version control tool include:
* :module:`CTest` module variable: ``UPDATE_TYPE`` if set,
else ``CTEST_UPDATE_TYPE``
+.. _`UpdateVersionOnly`:
+
``UpdateVersionOnly``
Specify that you want the version control update command to only
discover the current version that is checked out, and not to update
@@ -723,7 +831,18 @@ Configuration settings to specify the version control tool include:
* `CTest Script`_ variable: :variable:`CTEST_UPDATE_VERSION_ONLY`
+.. _`UpdateVersionOverride`:
+``UpdateVersionOverride``
+ Specify the current version of your source tree.
+
+ When this variable is set to a non-empty string, CTest will report the value
+ you specified rather than using the update command to discover the current
+ version that is checked out. Use of this variable supersedes
+ ``UpdateVersionOnly``. Like ``UpdateVersionOnly``, using this variable tells
+ CTest not to update the source tree to a different version.
+
+ * `CTest Script`_ variable: :variable:`CTEST_UPDATE_VERSION_OVERRIDE`
Additional configuration settings include:
@@ -758,6 +877,16 @@ Configuration settings include:
* :module:`CTest` module variable: :variable:`CMAKE_COMMAND`
followed by :variable:`PROJECT_SOURCE_DIR`
+``LabelsForSubprojects``
+ Specify a semicolon-separated list of labels that will be treated as
+ subprojects. This mapping will be passed on to CDash when configure, test or
+ build results are submitted.
+
+ * `CTest Script`_ variable: :variable:`CTEST_LABELS_FOR_SUBPROJECTS`
+ * :module:`CTest` module variable: ``CTEST_LABELS_FOR_SUBPROJECTS``
+
+ See `Label and Subproject Summary`_.
+
.. _`CTest Build Step`:
CTest Build Step
@@ -778,7 +907,17 @@ Configuration settings include:
* `CTest Script`_ variable: :variable:`CTEST_CONFIGURATION_TYPE`
* :module:`CTest` module variable: ``DEFAULT_CTEST_CONFIGURATION_TYPE``,
- initialized by the ``CMAKE_CONFIG_TYPE`` environment variable
+ initialized by the :envvar:`CMAKE_CONFIG_TYPE` environment variable
+
+``LabelsForSubprojects``
+ Specify a semicolon-separated list of labels that will be treated as
+ subprojects. This mapping will be passed on to CDash when configure, test or
+ build results are submitted.
+
+ * `CTest Script`_ variable: :variable:`CTEST_LABELS_FOR_SUBPROJECTS`
+ * :module:`CTest` module variable: ``CTEST_LABELS_FOR_SUBPROJECTS``
+
+ See `Label and Subproject Summary`_.
``MakeCommand``
Command-line to launch the software build process.
@@ -815,6 +954,16 @@ Arguments to the command may specify some of the step settings.
Configuration settings include:
+``LabelsForSubprojects``
+ Specify a semicolon-separated list of labels that will be treated as
+ subprojects. This mapping will be passed on to CDash when configure, test or
+ build results are submitted.
+
+ * `CTest Script`_ variable: :variable:`CTEST_LABELS_FOR_SUBPROJECTS`
+ * :module:`CTest` module variable: ``CTEST_LABELS_FOR_SUBPROJECTS``
+
+ See `Label and Subproject Summary`_.
+
``TestLoad``
While running tests in parallel (e.g. with ``-j``), try not to start
tests when they may cause the CPU load to pass above a given threshold.
@@ -853,6 +1002,8 @@ Configuration settings include:
* `CTest Script`_ variable: :variable:`CTEST_COVERAGE_EXTRA_FLAGS`
* :module:`CTest` module variable: ``COVERAGE_EXTRA_FLAGS``
+ These options are the first arguments passed to ``CoverageCommand``.
+
.. _`CTest MemCheck Step`:
CTest MemCheck Step
@@ -945,7 +1096,7 @@ Configuration settings include:
* :module:`CTest` module variable: ``BUILDNAME``
``CDashVersion``
- Specify the version of `CDash`_ on the server.
+ Legacy option. Not used.
* `CTest Script`_ variable: none, detected from server
* :module:`CTest` module variable: ``CTEST_CDASH_VERSION``
@@ -974,55 +1125,58 @@ Configuration settings include:
* :module:`CTest` module variable: ``CTEST_CURL_OPTIONS``
``DropLocation``
- The path on the dashboard server to send the submission.
+ Legacy option. When ``SubmitURL`` is not set, it is constructed from
+ ``DropMethod``, ``DropSiteUser``, ``DropSitePassword``, ``DropSite``, and
+ ``DropLocation``.
* `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).
+ Legacy option. When ``SubmitURL`` is not set, it is constructed from
+ ``DropMethod``, ``DropSiteUser``, ``DropSitePassword``, ``DropSite``, and
+ ``DropLocation``.
* `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``).
+ Legacy option. When ``SubmitURL`` is not set, it is constructed from
+ ``DropMethod``, ``DropSiteUser``, ``DropSitePassword``, ``DropSite``, and
+ ``DropLocation``.
* `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``).
+ Legacy option. When ``SubmitURL`` is not set, it is constructed from
+ ``DropMethod``, ``DropSiteUser``, ``DropSitePassword``, ``DropSite``, and
+ ``DropLocation``.
* `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``).
+ Legacy option. When ``SubmitURL`` is not set, it is constructed from
+ ``DropMethod``, ``DropSiteUser``, ``DropSitePassword``, ``DropSite``, and
+ ``DropLocation``.
* `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``.
+ Legacy option. Not used.
* `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``.
+ Legacy option. Not used.
* `CTest Script`_ variable: :variable:`CTEST_SCP_COMMAND`
* :module:`CTest` module variable: ``SCPCOMMAND``
@@ -1035,15 +1189,83 @@ Configuration settings include:
* :module:`CTest` module variable: ``SITE``,
initialized by the :command:`site_name` command
+``SubmitURL``
+ The ``http`` or ``https`` URL of the dashboard server to send the submission
+ to.
+
+ * `CTest Script`_ variable: :variable:`CTEST_SUBMIT_URL`
+ * :module:`CTest` module variable: ``SUBMIT_URL`` if set,
+ else ``CTEST_SUBMIT_URL``
+
``TriggerSite``
- Legacy option to support older dashboard server implementations.
- Not used when ``IsCDash`` is true.
+ Legacy option. Not used.
* `CTest Script`_ variable: :variable:`CTEST_TRIGGER_SITE`
* :module:`CTest` module variable: ``TRIGGER_SITE`` if set,
else ``CTEST_TRIGGER_SITE``
+.. _`Show as JSON Object Model`:
+
+Show as JSON Object Model
+=========================
+
+When the ``--show-only=json-v1`` command line option is given, the test
+information is output in JSON format. Version 1.0 of the JSON object
+model is defined as follows:
+
+``kind``
+ The string "ctestInfo".
+
+``version``
+ A JSON object specifying the version components. Its members are
+
+ ``major``
+ A non-negative integer specifying the major version component.
+ ``minor``
+ A non-negative integer specifying the minor version component.
+
+``backtraceGraph``
+ JSON object representing backtrace information with the
+ following members:
+
+ ``commands``
+ List of command names.
+ ``files``
+ List of file names.
+ ``nodes``
+ List of node JSON objects with members:
+
+ ``command``
+ Index into the ``commands`` member of the ``backtraceGraph``.
+ ``file``
+ Index into the ``files`` member of the ``backtraceGraph``.
+ ``line``
+ Line number in the file where the backtrace was added.
+ ``parent``
+ Index into the ``nodes`` member of the ``backtraceGraph``
+ representing the parent in the graph.
+
+``tests``
+ A JSON array listing information about each test. Each entry
+ is a JSON object with members:
+
+ ``name``
+ Test name.
+ ``config``
+ Configuration that the test can run on.
+ Empty string means any config.
+ ``command``
+ List where the first element is the test command and the
+ remaining elements are the command arguments.
+ ``backtrace``
+ Index into the ``nodes`` member of the ``backtraceGraph``.
+ ``properties``
+ Test properties.
+ Can contain keys for each of the supported test properties.
+
See Also
========
.. include:: LINKS.txt
+
+.. _`CDash`: http://cdash.org/
diff --git a/Help/module/CPackArchive.rst b/Help/module/CPackArchive.rst
index eb8d9d244..8616098cb 100644
--- a/Help/module/CPackArchive.rst
+++ b/Help/module/CPackArchive.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackArchive.cmake
+CPackArchive
+------------
+
+The documentation for the CPack Archive generator has moved here: :cpack_gen:`CPack Archive Generator`
diff --git a/Help/module/CPackBundle.rst b/Help/module/CPackBundle.rst
index 651e87426..513488427 100644
--- a/Help/module/CPackBundle.rst
+++ b/Help/module/CPackBundle.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackBundle.cmake
+CPackBundle
+-----------
+
+The documentation for the CPack Bundle generator has moved here: :cpack_gen:`CPack Bundle Generator`
diff --git a/Help/module/CPackCygwin.rst b/Help/module/CPackCygwin.rst
index 21f447348..719dfceb1 100644
--- a/Help/module/CPackCygwin.rst
+++ b/Help/module/CPackCygwin.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackCygwin.cmake
+CPackCygwin
+-----------
+
+The documentation for the CPack Cygwin generator has moved here: :cpack_gen:`CPack Cygwin Generator`
diff --git a/Help/module/CPackDMG.rst b/Help/module/CPackDMG.rst
index 784262c5e..e59dcbb7a 100644
--- a/Help/module/CPackDMG.rst
+++ b/Help/module/CPackDMG.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackDMG.cmake
+CPackDMG
+--------
+
+The documentation for the CPack DragNDrop generator has moved here: :cpack_gen:`CPack DragNDrop Generator`
diff --git a/Help/module/CPackDeb.rst b/Help/module/CPackDeb.rst
index d1526ee49..cd7e5f305 100644
--- a/Help/module/CPackDeb.rst
+++ b/Help/module/CPackDeb.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackDeb.cmake
+CPackDeb
+--------
+
+The documentation for the CPack DEB generator has moved here: :cpack_gen:`CPack DEB Generator`
diff --git a/Help/module/CPackNSIS.rst b/Help/module/CPackNSIS.rst
index bb35ed60a..2cb407a97 100644
--- a/Help/module/CPackNSIS.rst
+++ b/Help/module/CPackNSIS.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackNSIS.cmake
+CPackNSIS
+---------
+
+The documentation for the CPack NSIS generator has moved here: :cpack_gen:`CPack NSIS Generator`
diff --git a/Help/module/CPackPackageMaker.rst b/Help/module/CPackPackageMaker.rst
index de5544869..226b6fd8e 100644
--- a/Help/module/CPackPackageMaker.rst
+++ b/Help/module/CPackPackageMaker.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackPackageMaker.cmake
+CPackPackageMaker
+-----------------
+
+The documentation for the CPack PackageMaker generator has moved here: :cpack_gen:`CPack PackageMaker Generator`
diff --git a/Help/module/CPackProductBuild.rst b/Help/module/CPackProductBuild.rst
index 6081fe48a..8cd9198b4 100644
--- a/Help/module/CPackProductBuild.rst
+++ b/Help/module/CPackProductBuild.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackProductBuild.cmake
+CPackProductBuild
+-----------------
+
+The documentation for the CPack productbuild generator has moved here: :cpack_gen:`CPack productbuild Generator`
diff --git a/Help/module/CPackRPM.rst b/Help/module/CPackRPM.rst
index 28d0e6912..00b7e0ad7 100644
--- a/Help/module/CPackRPM.rst
+++ b/Help/module/CPackRPM.rst
@@ -1 +1,4 @@
-.. cmake-module:: ../../Modules/CPackRPM.cmake
+CPackRPM
+--------
+
+The documentation for the CPack RPM generator has moved here: :cpack_gen:`CPack RPM Generator`
diff --git a/Help/module/CPackWIX.rst b/Help/module/CPackWIX.rst
index 1f5e451e9..fd378b86a 100644
--- a/Help/module/CPackWIX.rst
+++ b/Help/module/CPackWIX.rst
@@ -1 +1,5 @@
-.. cmake-module:: ../../Modules/CPackWIX.cmake
+CPackWIX
+--------
+
+The documentation for the CPack WIX generator has moved here:
+:cpack_gen:`CPack WIX Generator`
diff --git a/Help/policy/CMP0000.rst b/Help/policy/CMP0000.rst
index 97ea633b2..aecfa7187 100644
--- a/Help/policy/CMP0000.rst
+++ b/Help/policy/CMP0000.rst
@@ -7,25 +7,27 @@ 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:
+versions newer than that specified. Use the :command:`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
+where ``<major>.<minor>`` is the version of CMake you want to support
+(such as ``3.14``). 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.
+the project. See documentation of :command:`cmake_minimum_required` for
+details.
-Note that the command invocation must appear in the CMakeLists.txt
+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.
+the :command:`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
index 09ad38702..6fa64d983 100644
--- a/Help/policy/CMP0001.rst
+++ b/Help/policy/CMP0001.rst
@@ -1,21 +1,21 @@
CMP0001
-------
-CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
+``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
+The 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
+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
+and the :command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0002.rst b/Help/policy/CMP0002.rst
index 7cc53efa1..dc68d5180 100644
--- a/Help/policy/CMP0002.rst
+++ b/Help/policy/CMP0002.rst
@@ -3,8 +3,8 @@ 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
+Targets names created with :command:`add_executable`, :command:`add_library`, or
+:command:`add_custom_target` are logical build target names. Logical target
names must be globally unique because:
::
@@ -16,13 +16,13 @@ names must be globally unique because:
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
+:prop_tgt:`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).
+property :prop_gbl:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0003.rst b/Help/policy/CMP0003.rst
index 16b045165..dd90883dc 100644
--- a/Help/policy/CMP0003.rst
+++ b/Help/policy/CMP0003.rst
@@ -37,7 +37,7 @@ 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
+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
@@ -45,9 +45,9 @@ 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
+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
+needed for their own libraries. When this policy is set to ``OLD``, CMake
will produce a link line such as
::
@@ -98,7 +98,7 @@ 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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0004.rst b/Help/policy/CMP0004.rst
index 55da4d293..be6d3079b 100644
--- a/Help/policy/CMP0004.rst
+++ b/Help/policy/CMP0004.rst
@@ -12,14 +12,15 @@ whitespace from libraries linked with code like
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 ``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.
+target is created by an :command:`add_executable` or :command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0005.rst b/Help/policy/CMP0005.rst
index 66d125fb7..59567d56e 100644
--- a/Help/policy/CMP0005.rst
+++ b/Help/policy/CMP0005.rst
@@ -12,15 +12,15 @@ 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
+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
+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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0006.rst b/Help/policy/CMP0006.rst
index d1b9ece7f..181958b39 100644
--- a/Help/policy/CMP0006.rst
+++ b/Help/policy/CMP0006.rst
@@ -1,24 +1,24 @@
CMP0006
-------
-Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
+Installing :prop_tgt:`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
+This policy determines whether the :command:`install(TARGETS)` command must be
+given a ``BUNDLE DESTINATION`` when asked to install a target with the
+:prop_tgt:`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.
+CMake 2.6 provides a ``BUNDLE`` option to the :command:`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.
+:prop_tgt:`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.
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0007.rst b/Help/policy/CMP0007.rst
index 39276457a..1006ed33a 100644
--- a/Help/policy/CMP0007.rst
+++ b/Help/policy/CMP0007.rst
@@ -5,13 +5,13 @@ 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 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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0008.rst b/Help/policy/CMP0008.rst
index f1e2ddde5..18ede821c 100644
--- a/Help/policy/CMP0008.rst
+++ b/Help/policy/CMP0008.rst
@@ -9,26 +9,27 @@ 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
+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
+path cannot be found. For :ref:`Visual Studio Generators` IDE
+and :generator:`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.
+(``-lsomelib`` or ``somelib.lib``). Despite the failure with Makefiles, some
+projects have code like this and build only with Visual Studio 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
+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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0009.rst b/Help/policy/CMP0009.rst
index 44baeb449..27cfde0db 100644
--- a/Help/policy/CMP0009.rst
+++ b/Help/policy/CMP0009.rst
@@ -3,19 +3,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
+In CMake 2.6.1 and below, :command:`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.
+during a :command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0010.rst b/Help/policy/CMP0010.rst
index 344d70475..cfae4982a 100644
--- a/Help/policy/CMP0010.rst
+++ b/Help/policy/CMP0010.rst
@@ -4,17 +4,17 @@ 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
+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
+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.
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0011.rst b/Help/policy/CMP0011.rst
index d281e0ef7..257415c26 100644
--- a/Help/policy/CMP0011.rst
+++ b/Help/policy/CMP0011.rst
@@ -1,24 +1,25 @@
CMP0011
-------
-Included scripts do automatic cmake_policy PUSH and POP.
+Included scripts do automatic :command:`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.
+the :command:`include` and :command:`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, :command:`include` and
+:command:`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 :command:`include` and :command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0012.rst b/Help/policy/CMP0012.rst
index 85d64f4d4..17ec8d33d 100644
--- a/Help/policy/CMP0012.rst
+++ b/Help/policy/CMP0012.rst
@@ -1,27 +1,28 @@
CMP0012
-------
-if() recognizes numbers and boolean constants.
+:command:`if` recognizes numbers and boolean constants.
-In CMake versions 2.6.4 and lower the if() command implicitly
+In CMake versions 2.6.4 and lower the :command:`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
+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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0013.rst b/Help/policy/CMP0013.rst
index 2fabb8920..dbd67a177 100644
--- a/Help/policy/CMP0013.rst
+++ b/Help/policy/CMP0013.rst
@@ -9,13 +9,13 @@ 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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0014.rst b/Help/policy/CMP0014.rst
index f1f7b77b8..331dde5ef 100644
--- a/Help/policy/CMP0014.rst
+++ b/Help/policy/CMP0014.rst
@@ -1,17 +1,17 @@
CMP0014
-------
-Input directories must have CMakeLists.txt.
+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(),
+CMake versions before 2.8 silently ignored missing ``CMakeLists.txt``
+files in directories referenced by :command:`add_subdirectory` or :command:`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.
+:command:`cmake_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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0015.rst b/Help/policy/CMP0015.rst
index 9a48e3dac..90d520334 100644
--- a/Help/policy/CMP0015.rst
+++ b/Help/policy/CMP0015.rst
@@ -1,19 +1,19 @@
CMP0015
-------
-link_directories() treats paths relative to the source dir.
+ :command:`link_directories` treats paths relative to the source dir.
-In CMake 2.8.0 and lower the link_directories() command passed
+In CMake 2.8.0 and lower the :command:`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.
+:command:`link_directories` command prefers to interpret relative paths with
+respect to ``CMAKE_CURRENT_SOURCE_DIR``, which is consistent with
+:command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0016.rst b/Help/policy/CMP0016.rst
index cc898c8ca..026d02a9d 100644
--- a/Help/policy/CMP0016.rst
+++ b/Help/policy/CMP0016.rst
@@ -1,15 +1,16 @@
CMP0016
-------
-target_link_libraries() reports error if its only argument is not a target.
+:command:`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
+In CMake 2.8.2 and lower the :command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0017.rst b/Help/policy/CMP0017.rst
index 9f0f0380f..ca4664eed 100644
--- a/Help/policy/CMP0017.rst
+++ b/Help/policy/CMP0017.rst
@@ -4,18 +4,18 @@ 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
+located in the CMake module directory) calls :command:`include` or
+:command:`find_package`, the files located in the CMake module directory are
+preferred over the files in :variable:`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
+other cases, the files found in :variable:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0018.rst b/Help/policy/CMP0018.rst
index a3a7a12bd..624840678 100644
--- a/Help/policy/CMP0018.rst
+++ b/Help/policy/CMP0018.rst
@@ -1,34 +1,35 @@
CMP0018
-------
-Ignore CMAKE_SHARED_LIBRARY_<Lang>_FLAGS variable.
+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
+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
+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
+prefer instead to use the :prop_tgt:`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.
+``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
+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 ``OLD`` behavior for this policy is to ignore the
+:prop_tgt:`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.
+The ``NEW`` behavior for this policy is to ignore
+``CMAKE_SHARED_LIBRARY_<Lang>_FLAGS`` whether it is modified or not and
+honor the :prop_tgt:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW``
+explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0019.rst b/Help/policy/CMP0019.rst
index 2e3557d32..682dcdf86 100644
--- a/Help/policy/CMP0019.rst
+++ b/Help/policy/CMP0019.rst
@@ -11,12 +11,12 @@ 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 ``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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0020.rst b/Help/policy/CMP0020.rst
index 75ca9deb2..6d27684f2 100644
--- a/Help/policy/CMP0020.rst
+++ b/Help/policy/CMP0020.rst
@@ -1,27 +1,27 @@
CMP0020
-------
-Automatically link Qt executables to qtmain target on Windows.
+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.
+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
+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
+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.
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0021.rst b/Help/policy/CMP0021.rst
index 3a792ca14..937b106eb 100644
--- a/Help/policy/CMP0021.rst
+++ b/Help/policy/CMP0021.rst
@@ -1,20 +1,21 @@
CMP0021
-------
-Fatal error on relative paths in INCLUDE_DIRECTORIES target property.
+Fatal error on relative paths in :prop_tgt:`INCLUDE_DIRECTORIES` target
+property.
-CMake 2.8.10.2 and lower allowed the INCLUDE_DIRECTORIES target
+CMake 2.8.10.2 and lower allowed the :prop_tgt:`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.
+entries is not well defined. CMake 2.8.12 issues a ``FATAL_ERROR`` if the
+:prop_tgt:`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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0022.rst b/Help/policy/CMP0022.rst
index 579d09ac0..be60e375a 100644
--- a/Help/policy/CMP0022.rst
+++ b/Help/policy/CMP0022.rst
@@ -1,39 +1,39 @@
CMP0022
-------
-INTERFACE_LINK_LIBRARIES defines the link interface.
+:prop_tgt:`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
+:prop_tgt:`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
+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
+link interface only if policy ``CMP0022`` is ``NEW``. When exporting a target
+which has this policy set to ``NEW``, only the :prop_tgt:`INTERFACE_LINK_LIBRARIES`
+property will be processed and generated for the ``IMPORTED`` target by
+default. A new option to the :command:`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.
+:command:`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
+The ``OLD`` behavior for this policy is to ignore the
+:prop_tgt:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0023.rst b/Help/policy/CMP0023.rst
index 76a4900b6..3c72c8195 100644
--- a/Help/policy/CMP0023.rst
+++ b/Help/policy/CMP0023.rst
@@ -1,15 +1,15 @@
CMP0023
-------
-Plain and keyword target_link_libraries signatures cannot be mixed.
+Plain and keyword :command:`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
+CMake 2.8.12 introduced the :command:`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:
+:command:`target_link_libraries` signature. For example, consider the code:
::
@@ -20,16 +20,16 @@ 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
+plain and keyword signatures of :command:`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
+The ``OLD`` behavior for this policy is to allow keyword and plain
+:command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0024.rst b/Help/policy/CMP0024.rst
index 272a56c8d..6e24b0454 100644
--- a/Help/policy/CMP0024.rst
+++ b/Help/policy/CMP0024.rst
@@ -3,22 +3,23 @@ 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
+CMake 2.8.12 and lower allowed use of the :command:`include` command with the
+result of the :command:`export` command. This relies on the assumption that
+the :command:`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
+the :command:`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.
+The ``OLD`` behavior for this policy is to allow including the result of
+an :command:`export` command. The ``NEW`` behavior for this policy is not to
+allow including the result of an :command:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW``
+explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0025.rst b/Help/policy/CMP0025.rst
index 62dd50985..ba5e1e948 100644
--- a/Help/policy/CMP0025.rst
+++ b/Help/policy/CMP0025.rst
@@ -15,13 +15,13 @@ language ``<LANG>`` is enabled by the :command:`project` or
:command:`enable_language` command. The policy must be set prior
to the invocation of either command.
-The OLD behavior for this policy is to use compiler id ``Clang``. The
-NEW behavior for this policy is to use compiler id ``AppleClang``.
+The ``OLD`` behavior for this policy is to use compiler id ``Clang``. The
+``NEW`` behavior for this policy is to use compiler id ``AppleClang``.
This policy was introduced in CMake version 3.0. 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.
+: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
index 3fe1374c8..3401d4a9a 100644
--- a/Help/policy/CMP0026.rst
+++ b/Help/policy/CMP0026.rst
@@ -3,26 +3,27 @@ CMP0026
Disallow use of the LOCATION property for build targets.
-CMake 2.8.12 and lower allowed reading the LOCATION target
+CMake 2.8.12 and lower allowed reading the :prop_tgt:`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
+generate-time. At generate time, the ``$<TARGET_FILE>`` generator
+expression can be used to determine the eventual :prop_tgt:`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.
+Code which reads the :prop_tgt:`LOCATION` target property can be ported to
+use the ``$<TARGET_FILE>`` generator expression together with the
+:command:`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.
+The ``OLD`` behavior for this policy is to allow reading the :prop_tgt:`LOCATION`
+properties from build-targets. The ``NEW`` behavior for this policy is to
+not to allow reading the :prop_tgt:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0027.rst b/Help/policy/CMP0027.rst
index 28913cee4..bf7b6a978 100644
--- a/Help/policy/CMP0027.rst
+++ b/Help/policy/CMP0027.rst
@@ -4,24 +4,24 @@ 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
+:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`, and a check at cmake time that the
+entries in the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` of an ``IMPORTED``
+target actually exist. CMake 2.8.11 also introduced generator expression
+support in the :command:`target_link_libraries` command. However, if an
+imported target is linked as a result of a generator expression evaluation, the
+entries in the :prop_tgt:`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 ``OLD`` behavior of this policy is to report a warning if an entry in
+the :prop_tgt:`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.
+The ``NEW`` behavior of this policy is to report an error if an entry in
+the :prop_tgt:`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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0028.rst b/Help/policy/CMP0028.rst
index be57125d4..ab3822993 100644
--- a/Help/policy/CMP0028.rst
+++ b/Help/policy/CMP0028.rst
@@ -1,25 +1,25 @@
CMP0028
-------
-Double colon in target name means ALIAS or IMPORTED target.
+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.
+colons in :command:`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
+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.
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0037.rst b/Help/policy/CMP0037.rst
index 9f8457c62..9895fb0b4 100644
--- a/Help/policy/CMP0037.rst
+++ b/Help/policy/CMP0037.rst
@@ -10,19 +10,25 @@ 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.
+character (``_``), dot(``.``), plus(``+``) and minus(``-``).
+As a special case, ``ALIAS`` and ``IMPORTED`` targets may contain
+two consecutive colons.
Target names reserved by one or more CMake generators are not allowed.
-Among others these include "all", "help" and "test".
+Among others these include ``all``, ``clean``, ``help``, and ``install``.
-The OLD behavior for this policy is to allow creating targets with
+Target names associated with optional features, such as ``test`` and
+``package``, may also be reserved. CMake 3.10 and below always reserve them.
+CMake 3.11 and above reserve them only when the corresponding feature is
+enabled (e.g. by including the :module:`CTest` or :module:`CPack` modules).
+
+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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0038.rst b/Help/policy/CMP0038.rst
index a306d90a9..7fb2209fa 100644
--- a/Help/policy/CMP0038.rst
+++ b/Help/policy/CMP0038.rst
@@ -7,12 +7,12 @@ 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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0039.rst b/Help/policy/CMP0039.rst
index 97d78ae2a..4b14e21ae 100644
--- a/Help/policy/CMP0039.rst
+++ b/Help/policy/CMP0039.rst
@@ -7,13 +7,13 @@ 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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0040.rst b/Help/policy/CMP0040.rst
index d46baf647..0afe5895d 100644
--- a/Help/policy/CMP0040.rst
+++ b/Help/policy/CMP0040.rst
@@ -2,7 +2,7 @@ CMP0040
-------
The target in the ``TARGET`` signature of :command:`add_custom_command`
-must exist and must be defined in current directory.
+must exist and must be defined in the current directory.
CMake 2.8.12 and lower silently ignored a custom command created with
the ``TARGET`` signature of :command:`add_custom_command`
diff --git a/Help/policy/CMP0041.rst b/Help/policy/CMP0041.rst
index f027d5de9..3b4df3601 100644
--- a/Help/policy/CMP0041.rst
+++ b/Help/policy/CMP0041.rst
@@ -15,13 +15,13 @@ As an additional diagnostic, the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` gener
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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0042.rst b/Help/policy/CMP0042.rst
index 31314b2cd..087756450 100644
--- a/Help/policy/CMP0042.rst
+++ b/Help/policy/CMP0042.rst
@@ -15,7 +15,7 @@ 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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0043.rst b/Help/policy/CMP0043.rst
index 9e427c377..05210ac6e 100644
--- a/Help/policy/CMP0043.rst
+++ b/Help/policy/CMP0043.rst
@@ -35,13 +35,13 @@ or via :command:`target_compile_definitions`:
COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DIR_DEBUG_MODE>
)
-The OLD behavior for this policy is to consume the content of the suffixed
+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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0044.rst b/Help/policy/CMP0044.rst
index 02afa9f1a..6a4d040b1 100644
--- a/Help/policy/CMP0044.rst
+++ b/Help/policy/CMP0044.rst
@@ -9,13 +9,13 @@ 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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0045.rst b/Help/policy/CMP0045.rst
index c7e1a90f6..80e217b18 100644
--- a/Help/policy/CMP0045.rst
+++ b/Help/policy/CMP0045.rst
@@ -7,13 +7,13 @@ 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
+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.
+|release| warns when the policy is not set and uses ``OLD`` behavior. Use
+the :command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0046.rst b/Help/policy/CMP0046.rst
index 576d1b1cc..bf785842c 100644
--- a/Help/policy/CMP0046.rst
+++ b/Help/policy/CMP0046.rst
@@ -6,14 +6,14 @@ 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
+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.
+``OLD`` behavior. Use the :command:`cmake_policy` command to set it
+to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0047.rst b/Help/policy/CMP0047.rst
index 882dd7828..9588edd7a 100644
--- a/Help/policy/CMP0047.rst
+++ b/Help/policy/CMP0047.rst
@@ -15,14 +15,14 @@ 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
+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.
+: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
index 0e7e60681..e63ec01a2 100644
--- a/Help/policy/CMP0048.rst
+++ b/Help/policy/CMP0048.rst
@@ -1,24 +1,24 @@
CMP0048
-------
-The :command:`project` command manages VERSION variables.
+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
+: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
+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
+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.
+``OLD`` behavior. Use the :command:`cmake_policy` command to set
+it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0049.rst b/Help/policy/CMP0049.rst
index a3ce4b1fa..49b20be17 100644
--- a/Help/policy/CMP0049.rst
+++ b/Help/policy/CMP0049.rst
@@ -3,23 +3,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
+CMake 2.8.12 and lower performed an extra layer of variable expansion
+when evaluating source file names::
set(a_source foo.c)
add_executable(foo \${a_source})
+.. note: no cmake highlighting since this syntax is deprecated
+
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
+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.
+``OLD`` behavior. Use the :command:`cmake_policy` command to set
+it to ``OLD`` or ``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0050.rst b/Help/policy/CMP0050.rst
index 39e40b698..27e7b1d50 100644
--- a/Help/policy/CMP0050.rst
+++ b/Help/policy/CMP0050.rst
@@ -8,13 +8,13 @@ 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
+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.
+``OLD`` behavior. Use the :command:`cmake_policy` command to set it to ``OLD`` or
+``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0052.rst b/Help/policy/CMP0052.rst
index 0ea5ace77..ee2e6e8de 100644
--- a/Help/policy/CMP0052.rst
+++ b/Help/policy/CMP0052.rst
@@ -1,7 +1,8 @@
CMP0052
-------
-Reject source and build dirs in installed INTERFACE_INCLUDE_DIRECTORIES.
+Reject source and build dirs in installed
+:prop_tgt:`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
@@ -13,9 +14,9 @@ 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
+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
+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.
diff --git a/Help/policy/CMP0053.rst b/Help/policy/CMP0053.rst
index 2620a60e0..032b3e5c6 100644
--- a/Help/policy/CMP0053.rst
+++ b/Help/policy/CMP0053.rst
@@ -16,6 +16,10 @@ cleaned up to simplify the behavior. Specifically:
* Literal ``${VAR}`` reference syntax may contain only
alphanumeric characters (``A-Z``, ``a-z``, ``0-9``) and
the characters ``_``, ``.``, ``/``, ``-``, and ``+``.
+ Note that ``$`` is technically allowed in the ``NEW`` behavior, but is
+ invalid for ``OLD`` behavior. This is due to an oversight during the
+ implementation of :policy:`CMP0053` and its use as a literal variable
+ reference is discouraged for this reason.
Variables with other characters in their name may still
be referenced indirectly, e.g.
diff --git a/Help/policy/CMP0055.rst b/Help/policy/CMP0055.rst
index b3df758fe..bc5ad086b 100644
--- a/Help/policy/CMP0055.rst
+++ b/Help/policy/CMP0055.rst
@@ -7,13 +7,13 @@ CMake 3.1 and lower allowed calls to the :command:`break` command
outside of a loop context and also ignored any given arguments.
This was undefined behavior.
-The OLD behavior for this policy is to allow :command:`break` to be placed
-outside of loop contexts and ignores any arguments. The NEW behavior for this
+The ``OLD`` behavior for this policy is to allow :command:`break` to be placed
+outside of loop contexts and ignores any arguments. The ``NEW`` behavior for this
policy is to issue an error if a misplaced break or any arguments are found.
This policy was introduced in CMake version 3.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.
+``OLD`` behavior. Use the :command:`cmake_policy` command to set it to ``OLD`` or
+``NEW`` explicitly.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0056.rst b/Help/policy/CMP0056.rst
index 3ba89d576..834da844f 100644
--- a/Help/policy/CMP0056.rst
+++ b/Help/policy/CMP0056.rst
@@ -14,9 +14,9 @@ the generated project. CMake 3.2 and above prefer to set it so that
linker flags are honored as well as compiler flags. This policy
provides compatibility with the pre-3.2 behavior.
-The OLD behavior for this policy is to not set the value of the
+The ``OLD`` behavior for this policy is to not set the value of the
:variable:`CMAKE_EXE_LINKER_FLAGS` variable in the generated test
-project. The NEW behavior for this policy is to set the value of
+project. The ``NEW`` behavior for this policy is to set the value of
the :variable:`CMAKE_EXE_LINKER_FLAGS` variable in the test project
to the same as it is in the calling project.
@@ -27,7 +27,7 @@ variable in the cache.
This policy was introduced in CMake version 3.2. 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
+is not set and simply uses ``OLD`` behavior. See documentation of the
:variable:`CMAKE_POLICY_WARNING_CMP0056 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
variable to control the warning.
diff --git a/Help/policy/CMP0060.rst b/Help/policy/CMP0060.rst
index 8611affac..98ac2cf69 100644
--- a/Help/policy/CMP0060.rst
+++ b/Help/policy/CMP0060.rst
@@ -51,14 +51,14 @@ and link libraries by full path even when they are in implicit link
directories. Policy ``CMP0060`` provides compatibility for existing
projects.
-The OLD behavior for this policy is to ask the linker to search for
+The ``OLD`` behavior for this policy is to ask the linker to search for
libraries whose full paths are known to be in implicit link directories.
-The NEW behavior for this policy is to link libraries by full path even
+The ``NEW`` behavior for this policy is to link libraries by full path even
if they are in implicit link directories.
This policy was introduced in CMake version 3.3. 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
+is not set and simply uses ``OLD`` behavior. See documentation of the
:variable:`CMAKE_POLICY_WARNING_CMP0060 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
variable to control the warning.
diff --git a/Help/policy/CMP0061.rst b/Help/policy/CMP0061.rst
index cb2ac2840..57e4161d0 100644
--- a/Help/policy/CMP0061.rst
+++ b/Help/policy/CMP0061.rst
@@ -21,6 +21,6 @@ add ``-i``.
This policy was introduced in CMake version 3.3. Unlike most policies,
CMake version |release| does *not* warn when this policy is not set and
-simply uses OLD behavior.
+simply uses ``OLD`` behavior.
.. include:: DEPRECATED.txt
diff --git a/Help/policy/CMP0062.rst b/Help/policy/CMP0062.rst
index 9047fffbe..0db7aafd0 100644
--- a/Help/policy/CMP0062.rst
+++ b/Help/policy/CMP0062.rst
@@ -1,7 +1,7 @@
CMP0062
-------
-Disallow install() of export() result.
+Disallow :command:`install` of :command:`export` result.
The :command:`export()` command generates a file containing
:ref:`Imported Targets`, which is suitable for use from the build
diff --git a/Help/policy/CMP0065.rst b/Help/policy/CMP0065.rst
index 2ed775dee..b820aad51 100644
--- a/Help/policy/CMP0065.rst
+++ b/Help/policy/CMP0065.rst
@@ -20,7 +20,7 @@ property is set to ``True``.
This policy was introduced in CMake version 3.4. 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
+is not set and simply uses ``OLD`` behavior. See documentation of the
:variable:`CMAKE_POLICY_WARNING_CMP0065 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
variable to control the warning.
diff --git a/Help/policy/CMP0066.rst b/Help/policy/CMP0066.rst
index d1dcb0ec6..e110ae127 100644
--- a/Help/policy/CMP0066.rst
+++ b/Help/policy/CMP0066.rst
@@ -20,7 +20,7 @@ variabldes like :variable:`CMAKE_<LANG>_FLAGS_DEBUG`.
This policy was introduced in CMake version 3.7. 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
+is not set and simply uses ``OLD`` behavior. See documentation of the
:variable:`CMAKE_POLICY_WARNING_CMP0066 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
variable to control the warning.
diff --git a/Help/policy/CMP0067.rst b/Help/policy/CMP0067.rst
index e6dda8018..f802787ff 100644
--- a/Help/policy/CMP0067.rst
+++ b/Help/policy/CMP0067.rst
@@ -30,7 +30,7 @@ setting variables.
This policy was introduced in CMake version 3.8. 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
+is not set and simply uses ``OLD`` behavior. See documentation of the
:variable:`CMAKE_POLICY_WARNING_CMP0067 <CMAKE_POLICY_WARNING_CMP<NNNN>>`
variable to control the warning.
diff --git a/Help/policy/DISALLOWED_COMMAND.txt b/Help/policy/DISALLOWED_COMMAND.txt
index 36280d2b6..6500bb0f3 100644
--- a/Help/policy/DISALLOWED_COMMAND.txt
+++ b/Help/policy/DISALLOWED_COMMAND.txt
@@ -1,9 +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
+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.
+``OLD`` behavior. Use the :command:`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
index a0a4f73bb..ec4de9d85 100644
--- a/Help/prop_cache/ADVANCED.rst
+++ b/Help/prop_cache/ADVANCED.rst
@@ -4,5 +4,5 @@ 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()
+interesting only for advanced configuration. The :command:`mark_as_advanced`
command modifies this property.
diff --git a/Help/prop_cache/STRINGS.rst b/Help/prop_cache/STRINGS.rst
index 2f8e32e3f..0e3c326d2 100644
--- a/Help/prop_cache/STRINGS.rst
+++ b/Help/prop_cache/STRINGS.rst
@@ -1,9 +1,9 @@
STRINGS
-------
-Enumerate possible STRING entry values for GUI selection.
+Enumerate possible ``STRING`` entry values for GUI selection.
-For cache entries with type STRING, this enumerates a set of values.
+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
index eb75c2ab2..7ca859f68 100644
--- a/Help/prop_cache/TYPE.rst
+++ b/Help/prop_cache/TYPE.rst
@@ -5,7 +5,7 @@ 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:
+determine the widget type. Valid ``TYPE`` values are:
::
@@ -17,5 +17,5 @@ determine the widget type. Valid TYPE values are:
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.).
+Generally the ``TYPE`` of a cache entry should be set by the command which
+creates it ( :command:`set`, :command:`option`, :command:`find_library`, etc.).
diff --git a/Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst b/Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst
index e32eed3ed..b6f616099 100644
--- a/Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst
+++ b/Help/prop_dir/ADDITIONAL_MAKE_CLEAN_FILES.rst
@@ -1,7 +1,17 @@
ADDITIONAL_MAKE_CLEAN_FILES
---------------------------
-Additional files to clean during the make clean stage.
+.. deprecated:: 3.15
-A list of files that will be cleaned as a part of the "make clean"
-stage.
+ Use :prop_dir:`ADDITIONAL_CLEAN_FILES` instead.
+
+Additional files to remove during the clean stage.
+
+A :ref:`;-list <CMake Language Lists>` of files that will be removed as a
+part of the ``make clean`` target.
+
+Arguments to :prop_dir:`ADDITIONAL_MAKE_CLEAN_FILES` may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+This property only works for the Makefile generators.
+It is ignored on other generators.
diff --git a/Help/prop_dir/BUILDSYSTEM_TARGETS.rst b/Help/prop_dir/BUILDSYSTEM_TARGETS.rst
index da907cb93..04bb56ec1 100644
--- a/Help/prop_dir/BUILDSYSTEM_TARGETS.rst
+++ b/Help/prop_dir/BUILDSYSTEM_TARGETS.rst
@@ -2,7 +2,7 @@ BUILDSYSTEM_TARGETS
-------------------
This read-only directory property contains a
-:ref:`;-list <CMake Language Lists>` of buildsystem targets added in the
+:ref:`semicolon-separated list <CMake Language Lists>` of buildsystem targets added in the
directory by calls to the :command:`add_library`, :command:`add_executable`,
and :command:`add_custom_target` commands. The list does not include any
:ref:`Imported Targets` or :ref:`Alias Targets`, but does include
diff --git a/Help/prop_dir/COMPILE_DEFINITIONS.rst b/Help/prop_dir/COMPILE_DEFINITIONS.rst
index 85adcb58a..18f4567c5 100644
--- a/Help/prop_dir/COMPILE_DEFINITIONS.rst
+++ b/Help/prop_dir/COMPILE_DEFINITIONS.rst
@@ -4,7 +4,7 @@ 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.
+:command:`add_compile_definitions` (or :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``.
diff --git a/Help/prop_dir/COMPILE_OPTIONS.rst b/Help/prop_dir/COMPILE_OPTIONS.rst
index 877deb000..48e8b9b8d 100644
--- a/Help/prop_dir/COMPILE_OPTIONS.rst
+++ b/Help/prop_dir/COMPILE_OPTIONS.rst
@@ -3,7 +3,7 @@ COMPILE_OPTIONS
List of options to pass to the compiler.
-This property holds a :ref:`;-list <CMake Language Lists>` of options
+This property holds a :ref:`semicolon-separated list <CMake Language Lists>` of options
given so far to the :command:`add_compile_options` command.
This property is used to initialize the :prop_tgt:`COMPILE_OPTIONS` target
diff --git a/Help/prop_dir/EXCLUDE_FROM_ALL.rst b/Help/prop_dir/EXCLUDE_FROM_ALL.rst
index 1aa24e44b..8e3cca0c2 100644
--- a/Help/prop_dir/EXCLUDE_FROM_ALL.rst
+++ b/Help/prop_dir/EXCLUDE_FROM_ALL.rst
@@ -1,9 +1,13 @@
EXCLUDE_FROM_ALL
----------------
-Exclude the directory from the all target of its parent.
+Set this directory property to a true value on a subdirectory to exclude
+its targets from the "all" target of its ancestors. If excluded, running
+e.g. ``make`` in the parent directory will not build targets the
+subdirectory by default. This does not affect the "all" target of the
+subdirectory itself. Running e.g. ``make`` inside the subdirectory will
+still build its targets.
-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.
+If the :prop_tgt:`EXCLUDE_FROM_ALL` target property is set on a target
+then its value determines whether the target is included in the "all"
+target of this directory and its ancestors.
diff --git a/Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst b/Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst
index 993f6200e..f5349763a 100644
--- a/Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst
+++ b/Help/prop_dir/IMPLICIT_DEPENDS_INCLUDE_TRANSFORM.rst
@@ -1,15 +1,15 @@
IMPLICIT_DEPENDS_INCLUDE_TRANSFORM
----------------------------------
-Specify #include line transforms for dependencies in a directory.
+Specify ``#include`` line transforms for dependencies in a directory.
-This property specifies rules to transform macro-like #include lines
+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
+``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
+``%``. For example, the entry
::
diff --git a/Help/prop_dir/INCLUDE_DIRECTORIES.rst b/Help/prop_dir/INCLUDE_DIRECTORIES.rst
index 6789a5644..5d856b80a 100644
--- a/Help/prop_dir/INCLUDE_DIRECTORIES.rst
+++ b/Help/prop_dir/INCLUDE_DIRECTORIES.rst
@@ -11,11 +11,17 @@ 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 initial value of the :prop_tgt:`INCLUDE_DIRECTORIES` target property
+directly on any directory using the :command:`set_property` command, and can be
+set on the current directory using the :command:`set_directory_properties`
+command. A directory gets its initial value from its parent directory if it has
+one. The initial 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.
+Calls to :command:`set_property` or :command:`set_directory_properties`,
+however, will update the directory property value without updating target
+property values. Therefore direct property updates must be made before
+calls to :command:`add_executable` or :command:`add_library` for targets
+they are meant to affect.
The target property values are used by the generators to set the
include paths for the compiler.
diff --git a/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst b/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
index 325208656..840a1dbc7 100644
--- a/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
+++ b/Help/prop_dir/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
@@ -3,6 +3,6 @@ INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
Per-configuration interprocedural optimization for a directory.
-This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION.
+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
index fa375766d..44dc2304e 100644
--- a/Help/prop_dir/LINK_DIRECTORIES.rst
+++ b/Help/prop_dir/LINK_DIRECTORIES.rst
@@ -3,6 +3,15 @@ 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.
+This property holds a :ref:`semicolon-separated list <CMake Language Lists>` of directories
+and is typically populated using the :command:`link_directories` command.
+It gets its initial value from its parent directory, if it has one.
+
+The directory property is used to initialize the :prop_tgt:`LINK_DIRECTORIES`
+target property when a target is created. That target property is used
+by the generators to set the library search directories for the linker.
+
+Contents of ``LINK_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/MACROS.rst b/Help/prop_dir/MACROS.rst
index e4feadaa5..245cc1b91 100644
--- a/Help/prop_dir/MACROS.rst
+++ b/Help/prop_dir/MACROS.rst
@@ -4,5 +4,5 @@ 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
+defined. It is intended for debugging purposes. See the :command:`macro`
command.
diff --git a/Help/prop_dir/SUBDIRECTORIES.rst b/Help/prop_dir/SUBDIRECTORIES.rst
index 2c2ea773e..6a0ac80d8 100644
--- a/Help/prop_dir/SUBDIRECTORIES.rst
+++ b/Help/prop_dir/SUBDIRECTORIES.rst
@@ -2,7 +2,7 @@ SUBDIRECTORIES
--------------
This read-only directory property contains a
-:ref:`;-list <CMake Language Lists>` of subdirectories processed so far by
+:ref:`semicolon-separated list <CMake Language Lists>` of subdirectories processed so far by
the :command:`add_subdirectory` or :command:`subdirs` commands. Each entry is
the absolute path to the source directory (containing the ``CMakeLists.txt``
file). This is suitable to pass to the :command:`get_property` command
diff --git a/Help/prop_dir/TEST_INCLUDE_FILE.rst b/Help/prop_dir/TEST_INCLUDE_FILE.rst
index e47795191..31b23829d 100644
--- a/Help/prop_dir/TEST_INCLUDE_FILE.rst
+++ b/Help/prop_dir/TEST_INCLUDE_FILE.rst
@@ -1,7 +1,9 @@
TEST_INCLUDE_FILE
-----------------
+Deprecated. Use :prop_dir:`TEST_INCLUDE_FILES` instead.
+
A cmake file that will be included when ctest is run.
-If you specify TEST_INCLUDE_FILE, that file will be included and
+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/VS_GLOBAL_SECTION_POST_section.rst b/Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst
index a316abec9..b65db99f3 100644
--- a/Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst
+++ b/Help/prop_dir/VS_GLOBAL_SECTION_POST_section.rst
@@ -12,20 +12,20 @@ in the solution file:
<contents based on property value>
EndGlobalSection
-The property must be set to a semicolon-separated list of key=value
+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 8 and above; it is ignored
+This property only works for Visual Studio 9 and above; it is ignored
on other generators. The property only applies when set on a
-directory whose CMakeLists.txt contains a project() command.
+directory whose ``CMakeLists.txt`` contains a :command:`project` command.
-Note that CMake generates postSolution sections ExtensibilityGlobals
-and ExtensibilityAddIns by default. If you set the corresponding
+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
+``VS_GLOBAL_SECTION_POST_ExtensibilityGlobals`` will override the default
+contents of the ``ExtensibilityGlobals`` section, while keeping
ExtensibilityAddIns on its default. However, CMake will always
add a ``SolutionGuid`` to the ``ExtensibilityGlobals`` section
if it is not specified explicitly.
diff --git a/Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst b/Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst
index 200e8e62f..7f8bf6161 100644
--- a/Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst
+++ b/Help/prop_dir/VS_GLOBAL_SECTION_PRE_section.rst
@@ -12,11 +12,11 @@ in the solution file:
<contents based on property value>
EndGlobalSection
-The property must be set to a semicolon-separated list of key=value
+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 8 and above; it is ignored
+This property only works for Visual Studio 9 and above; it is ignored
on other generators. The property only applies when set on a
-directory whose CMakeLists.txt contains a project() command.
+directory whose ``CMakeLists.txt`` contains a :command:`project` command.
diff --git a/Help/prop_dir/VS_STARTUP_PROJECT.rst b/Help/prop_dir/VS_STARTUP_PROJECT.rst
index 04441b621..2680dfa6c 100644
--- a/Help/prop_dir/VS_STARTUP_PROJECT.rst
+++ b/Help/prop_dir/VS_STARTUP_PROJECT.rst
@@ -7,7 +7,7 @@ The :ref:`Visual Studio Generators` create a ``.sln`` file for each directory
whose ``CMakeLists.txt`` file calls the :command:`project` command. Set this
property in the same directory as a :command:`project` command call (e.g. in
the top-level ``CMakeLists.txt`` file) to specify the default startup project
-for the correpsonding solution file.
+for the corresponding solution file.
The property must be set to the name of an existing target. This
will cause that project to be listed first in the generated solution
diff --git a/Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst b/Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst
index 8fab50345..19775ff2d 100644
--- a/Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst
+++ b/Help/prop_gbl/ALLOW_DUPLICATE_CUSTOM_TARGETS.rst
@@ -4,16 +4,18 @@ 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
+globally unique logical names (see policy :policy:`CMP0002`).
+This is necessary to generate meaningful project file names in
+:generator:`Xcode` and :ref:`Visual Studio Generators` 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
+Makefile generators are capable of supporting duplicate :command:`add_custom_target`
+names. For projects that care only about :ref:`Makefile Generators` and do
+not wish to support :generator:`Xcode` or :ref:`Visual Studio Generators` IDE
+generators, one may set this property to ``True``
+to allow duplicate custom targets. The property
+allows multiple :command:`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/CMAKE_CXX_KNOWN_FEATURES.rst b/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst
index 2ad81574f..262a67c29 100644
--- a/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst
+++ b/Help/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.rst
@@ -26,6 +26,9 @@ The features known to this version of CMake are:
``cxx_std_17``
Compiler mode is aware of C++ 17.
+``cxx_std_20``
+ Compiler mode is aware of C++ 20.
+
``cxx_aggregate_default_initializers``
Aggregate default initializers, as defined in N3605_.
diff --git a/Help/prop_gbl/DEBUG_CONFIGURATIONS.rst b/Help/prop_gbl/DEBUG_CONFIGURATIONS.rst
index 690143f82..fec6fdac8 100644
--- a/Help/prop_gbl/DEBUG_CONFIGURATIONS.rst
+++ b/Help/prop_gbl/DEBUG_CONFIGURATIONS.rst
@@ -4,11 +4,10 @@ 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.
+Currently this property is used only by the :command:`target_link_libraries`
+command. 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 first :command:`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
index 111cdf67e..882bbfacd 100644
--- a/Help/prop_gbl/DISABLED_FEATURES.rst
+++ b/Help/prop_gbl/DISABLED_FEATURES.rst
@@ -5,7 +5,7 @@ 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
+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.
+``FeatureSummary.cmake``.
diff --git a/Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst b/Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst
index 6d1529d3a..a46575ffa 100644
--- a/Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst
+++ b/Help/prop_gbl/ECLIPSE_EXTRA_NATURES.rst
@@ -6,3 +6,5 @@ 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).
+
+Also see the :prop_gbl:`ECLIPSE_EXTRA_CPROJECT_CONTENTS` property.
diff --git a/Help/prop_gbl/ENABLED_FEATURES.rst b/Help/prop_gbl/ENABLED_FEATURES.rst
index b03da5a45..acbb3d018 100644
--- a/Help/prop_gbl/ENABLED_FEATURES.rst
+++ b/Help/prop_gbl/ENABLED_FEATURES.rst
@@ -5,7 +5,7 @@ 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
+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.
+``FeatureSummary.cmake``.
diff --git a/Help/prop_gbl/JOB_POOLS.rst b/Help/prop_gbl/JOB_POOLS.rst
index 2ce74b81c..21da4662d 100644
--- a/Help/prop_gbl/JOB_POOLS.rst
+++ b/Help/prop_gbl/JOB_POOLS.rst
@@ -18,6 +18,14 @@ 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`.
+:command:`Custom commands <add_custom_command>` and
+:command:`custom targets <add_custom_target>` can specify pools using the
+option ``JOB_POOL``.
+Using a pool that is not defined by :prop_gbl:`JOB_POOLS` causes
+an error by ninja at build time.
+
+If not set, this property uses the value of the :variable:`CMAKE_JOB_POOLS`
+variable.
Build targets provided by CMake that are meant for individual interactive
use, such as ``install``, are placed in the ``console`` pool automatically.
diff --git a/Help/prop_gbl/RULE_MESSAGES.rst b/Help/prop_gbl/RULE_MESSAGES.rst
index 87a5ca613..a9734a730 100644
--- a/Help/prop_gbl/RULE_MESSAGES.rst
+++ b/Help/prop_gbl/RULE_MESSAGES.rst
@@ -8,6 +8,6 @@ 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
+of detailed reports. If a :variable:`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/USE_FOLDERS.rst b/Help/prop_gbl/USE_FOLDERS.rst
index a1b4ccb5b..591972327 100644
--- a/Help/prop_gbl/USE_FOLDERS.rst
+++ b/Help/prop_gbl/USE_FOLDERS.rst
@@ -4,7 +4,7 @@ USE_FOLDERS
Use the :prop_tgt:`FOLDER` target property to organize targets into
folders.
-If not set, CMake treats this property as OFF by default. CMake
+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 :prop_tgt:`FOLDER` target property to name those
-folders. See also the documentation for the FOLDER target property.
+folders. See also the documentation for the :prop_tgt:`FOLDER` target property.
diff --git a/Help/prop_gbl/XCODE_EMIT_EFFECTIVE_PLATFORM_NAME.rst b/Help/prop_gbl/XCODE_EMIT_EFFECTIVE_PLATFORM_NAME.rst
index 9a6086ed8..950044301 100644
--- a/Help/prop_gbl/XCODE_EMIT_EFFECTIVE_PLATFORM_NAME.rst
+++ b/Help/prop_gbl/XCODE_EMIT_EFFECTIVE_PLATFORM_NAME.rst
@@ -1,14 +1,15 @@
XCODE_EMIT_EFFECTIVE_PLATFORM_NAME
----------------------------------
-Control emission of ``EFFECTIVE_PLATFORM_NAME`` by the Xcode generator.
+Control emission of ``EFFECTIVE_PLATFORM_NAME`` by the :generator:`Xcode`
+generator.
It is required for building the same target with multiple SDKs. A
common use case is the parallel use of ``iphoneos`` and
``iphonesimulator`` SDKs.
-Three different states possible that control when the Xcode generator
-emits the ``EFFECTIVE_PLATFORM_NAME`` variable:
+Three different states possible that control when the :generator:`Xcode`
+generator emits the ``EFFECTIVE_PLATFORM_NAME`` variable:
- If set to ``ON`` it will always be emitted
- If set to ``OFF`` it will never be emitted
diff --git a/Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst b/Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst
index 11f2c036c..729ab603c 100644
--- a/Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst
+++ b/Help/prop_inst/CPACK_DESKTOP_SHORTCUTS.rst
@@ -1,7 +1,7 @@
CPACK_DESKTOP_SHORTCUTS
-----------------------
-Species a list of shortcut names that should be created on the Desktop
+Species a list of shortcut names that should be created on the `Desktop`
for this file.
-The property is currently only supported by the WIX generator.
+The property is currently only supported by the :cpack_gen:`CPack WIX Generator`.
diff --git a/Help/prop_inst/CPACK_NEVER_OVERWRITE.rst b/Help/prop_inst/CPACK_NEVER_OVERWRITE.rst
index 11f44d0df..4789e253d 100644
--- a/Help/prop_inst/CPACK_NEVER_OVERWRITE.rst
+++ b/Help/prop_inst/CPACK_NEVER_OVERWRITE.rst
@@ -3,4 +3,4 @@ CPACK_NEVER_OVERWRITE
Request that this file not be overwritten on install or reinstall.
-The property is currently only supported by the WIX generator.
+The property is currently only supported by the :cpack_gen:`CPack WIX Generator`.
diff --git a/Help/prop_inst/CPACK_PERMANENT.rst b/Help/prop_inst/CPACK_PERMANENT.rst
index 5e191d08e..985de0da9 100644
--- a/Help/prop_inst/CPACK_PERMANENT.rst
+++ b/Help/prop_inst/CPACK_PERMANENT.rst
@@ -3,4 +3,4 @@ CPACK_PERMANENT
Request that this file not be removed on uninstall.
-The property is currently only supported by the WIX generator.
+The property is currently only supported by the :cpack_gen:`CPack WIX Generator`.
diff --git a/Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst b/Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst
index 8a160223d..d9208b9f9 100644
--- a/Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst
+++ b/Help/prop_inst/CPACK_STARTUP_SHORTCUTS.rst
@@ -1,7 +1,7 @@
CPACK_STARTUP_SHORTCUTS
-----------------------
-Species a list of shortcut names that should be created in the Startup folder
+Species a list of shortcut names that should be created in the `Startup` folder
for this file.
-The property is currently only supported by the WIX generator.
+The property is currently only supported by the :cpack_gen:`CPack WIX Generator`.
diff --git a/Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst b/Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst
index d30ea39fd..092334a5a 100644
--- a/Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst
+++ b/Help/prop_inst/CPACK_START_MENU_SHORTCUTS.rst
@@ -1,7 +1,7 @@
CPACK_START_MENU_SHORTCUTS
--------------------------
-Species a list of shortcut names that should be created in the Start Menu
+Species a list of shortcut names that should be created in the `Start Menu`
for this file.
-The property is currently only supported by the WIX generator.
+The property is currently only supported by the :cpack_gen:`CPack WIX Generator`.
diff --git a/Help/prop_inst/CPACK_WIX_ACL.rst b/Help/prop_inst/CPACK_WIX_ACL.rst
index 4e13ec48c..c88f42675 100644
--- a/Help/prop_inst/CPACK_WIX_ACL.rst
+++ b/Help/prop_inst/CPACK_WIX_ACL.rst
@@ -17,3 +17,5 @@ each of which has to match the following format.
``<permission>`` is any of the YesNoType attributes listed here::
http://wixtoolset.org/documentation/manual/v3/xsd/wix/permission.html
+
+The property is currently only supported by the :cpack_gen:`CPack WIX Generator`.
diff --git a/Help/prop_sf/AUTORCC_OPTIONS.rst b/Help/prop_sf/AUTORCC_OPTIONS.rst
index d9dc4d33e..2bec033e4 100644
--- a/Help/prop_sf/AUTORCC_OPTIONS.rst
+++ b/Help/prop_sf/AUTORCC_OPTIONS.rst
@@ -9,5 +9,14 @@ optional ``OPTIONS`` argument of the :module:`qt4_add_resources() <FindQt4>` mac
By default it is empty.
-The options set on the ``.qrc`` source file may override :prop_tgt:`AUTORCC_OPTIONS` set
-on the target.
+The options set on the ``.qrc`` source file may override
+:prop_tgt:`AUTORCC_OPTIONS` set on the target.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(SOURCE resources.qrc PROPERTY AUTORCC_OPTIONS "--compress;9")
+ # ...
diff --git a/Help/prop_sf/AUTOUIC_OPTIONS.rst b/Help/prop_sf/AUTOUIC_OPTIONS.rst
index bb48da90f..e2f47ecd2 100644
--- a/Help/prop_sf/AUTOUIC_OPTIONS.rst
+++ b/Help/prop_sf/AUTOUIC_OPTIONS.rst
@@ -4,11 +4,20 @@ 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.
+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.
+The options set on the ``.ui`` source file may override
+:prop_tgt:`AUTOUIC_OPTIONS` set on the target.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(SOURCE widget.ui PROPERTY AUTOUIC_OPTIONS "--no-protection")
+ # ...
diff --git a/Help/prop_sf/COMPILE_DEFINITIONS.rst b/Help/prop_sf/COMPILE_DEFINITIONS.rst
index 1626825f1..63176901e 100644
--- a/Help/prop_sf/COMPILE_DEFINITIONS.rst
+++ b/Help/prop_sf/COMPILE_DEFINITIONS.rst
@@ -3,17 +3,27 @@ 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.
+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").
+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. Xcode does not support per-configuration
definitions on source files.
.. include:: /include/COMPILE_DEFINITIONS_DISCLAIMER.txt
+
+Contents of ``COMPILE_DEFINITIONS`` may use :manual:`cmake-generator-expressions(7)`
+with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
+manual for available expressions. However, :generator:`Xcode`
+does not support per-config per-source settings, so expressions
+that depend on the build configuration are not allowed with that
+generator.
+
+Generator expressions should be preferred instead of setting the alternative per-configuration
+property.
diff --git a/Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst b/Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst
index 848707647..ec867b65d 100644
--- a/Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst
+++ b/Help/prop_sf/COMPILE_DEFINITIONS_CONFIG.rst
@@ -5,6 +5,6 @@ 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.
+This is the configuration-specific version of :prop_tgt:`COMPILE_DEFINITIONS`.
+Note that :generator:`Xcode` does not support per-configuration source
+file flags so this property will be ignored by the :generator:`Xcode` generator.
diff --git a/Help/prop_sf/COMPILE_FLAGS.rst b/Help/prop_sf/COMPILE_FLAGS.rst
index 10121644e..c211b89ac 100644
--- a/Help/prop_sf/COMPILE_FLAGS.rst
+++ b/Help/prop_sf/COMPILE_FLAGS.rst
@@ -3,8 +3,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 :prop_sf:`COMPILE_DEFINITIONS` to pass
+The ``COMPILE_FLAGS`` property, managed as a string, sets additional compiler
+flags used to build source files. Use :prop_sf:`COMPILE_DEFINITIONS` to pass
additional preprocessor definitions.
Contents of ``COMPILE_FLAGS`` may use "generator expressions"
@@ -13,3 +13,7 @@ manual for available expressions. However, :generator:`Xcode`
does not support per-config per-source settings, so expressions
that depend on the build configuration are not allowed with that
generator.
+
+.. note::
+
+ This property has been superseded by the :prop_sf:`COMPILE_OPTIONS` property.
diff --git a/Help/prop_sf/EXTERNAL_OBJECT.rst b/Help/prop_sf/EXTERNAL_OBJECT.rst
index efa0e9bea..351c04d51 100644
--- a/Help/prop_sf/EXTERNAL_OBJECT.rst
+++ b/Help/prop_sf/EXTERNAL_OBJECT.rst
@@ -3,6 +3,6 @@ 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
+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
index 69e34aafd..1cbbf4809 100644
--- a/Help/prop_sf/Fortran_FORMAT.rst
+++ b/Help/prop_sf/Fortran_FORMAT.rst
@@ -1,9 +1,10 @@
Fortran_FORMAT
--------------
-Set to FIXED or FREE to indicate the Fortran source layout.
+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.
+flag to the compiler. Consider using the target-wide
+:prop_tgt:`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
index a3aa12747..d430ee264 100644
--- a/Help/prop_sf/GENERATED.rst
+++ b/Help/prop_sf/GENERATED.rst
@@ -1,8 +1,23 @@
GENERATED
---------
-Is this source file generated as part of the build process.
+Is this source file generated as part of the build or CMake 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.
+Tells the internal CMake engine that a source file is generated by an outside
+process such as another build step, or the execution of CMake itself. This
+information is then used to exempt the file from any existence or validity
+checks. Generated files are created by the execution of commands such as
+:command:`add_custom_command` and :command:`file(GENERATE)`.
+
+When a generated file created by an :command:`add_custom_command` command
+is explicitly listed as a source file for any target in the same
+directory scope (which usually means the same ``CMakeLists.txt`` file),
+CMake will automatically create a dependency to make sure the file is
+generated before building that target.
+
+Generated sources may be hidden in some IDE tools, while in others they might
+be shown. For the special case of sources generated by CMake's :prop_tgt:`AUTOMOC`
+or :prop_tgt:`AUTORCC` functionality, the :prop_gbl:`AUTOGEN_SOURCE_GROUP`,
+:prop_gbl:`AUTOMOC_SOURCE_GROUP` and :prop_gbl:`AUTORCC_SOURCE_GROUP` target
+properties may influence where the generated sources are grouped in the project's
+file lists.
diff --git a/Help/prop_sf/KEEP_EXTENSION.rst b/Help/prop_sf/KEEP_EXTENSION.rst
index d6167e5a9..a32f96834 100644
--- a/Help/prop_sf/KEEP_EXTENSION.rst
+++ b/Help/prop_sf/KEEP_EXTENSION.rst
@@ -6,4 +6,4 @@ 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.
+example ``.cxx`` will go to a ``.o`` extension.
diff --git a/Help/prop_sf/LABELS.rst b/Help/prop_sf/LABELS.rst
index e1c10696a..d0d2a0a92 100644
--- a/Help/prop_sf/LABELS.rst
+++ b/Help/prop_sf/LABELS.rst
@@ -4,5 +4,5 @@ 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
+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
index 97bfa20f4..88d438e7b 100644
--- a/Help/prop_sf/LANGUAGE.rst
+++ b/Help/prop_sf/LANGUAGE.rst
@@ -5,6 +5,7 @@ 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
+the file extension. Typical values are ``CXX`` (i.e. C++), ``C``,
+``CSharp``, ``CUDA``, ``Fortran``, and ``ASM``. 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/MACOSX_PACKAGE_LOCATION.rst b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
index a064afa63..d185d9197 100644
--- a/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
+++ b/Help/prop_sf/MACOSX_PACKAGE_LOCATION.rst
@@ -3,19 +3,19 @@ MACOSX_PACKAGE_LOCATION
Place a source file inside a Application Bundle
(:prop_tgt:`MACOSX_BUNDLE`), Core Foundation Bundle (:prop_tgt:`BUNDLE`),
-or Framework Bundle (:prop_tgt:`FRAMEWORK`). It is applicable for OS X
+or Framework Bundle (:prop_tgt:`FRAMEWORK`). It is applicable for macOS
and iOS.
Executable targets with the :prop_tgt:`MACOSX_BUNDLE` property set are
-built as OS X or iOS application bundles on Apple platforms. Shared
+built as macOS or iOS application bundles on Apple platforms. Shared
library targets with the :prop_tgt:`FRAMEWORK` property set are built as
-OS X or iOS frameworks on Apple platforms. Module library targets with
-the :prop_tgt:`BUNDLE` property set are built as OS X ``CFBundle`` bundles
+macOS or iOS frameworks on Apple platforms. Module library targets with
+the :prop_tgt:`BUNDLE` property set are built as macOS ``CFBundle`` bundles
on Apple platforms. Source files listed in the target with this property
set will be copied to a directory inside the bundle or framework content
-folder specified by the property value. For OS X Application Bundles the
-content folder is ``<name>.app/Contents``. For OS X Frameworks the
-content folder is ``<name>.framework/Versions/<version>``. For OS X
+folder specified by the property value. For macOS Application Bundles the
+content folder is ``<name>.app/Contents``. For macOS Frameworks the
+content folder is ``<name>.framework/Versions/<version>``. For macOS
CFBundles the content folder is ``<name>.bundle/Contents`` (unless the
extension is changed). See the :prop_tgt:`PUBLIC_HEADER`,
:prop_tgt:`PRIVATE_HEADER`, and :prop_tgt:`RESOURCE` target properties for
diff --git a/Help/prop_sf/OBJECT_DEPENDS.rst b/Help/prop_sf/OBJECT_DEPENDS.rst
index 1d24960b5..aaff95659 100644
--- a/Help/prop_sf/OBJECT_DEPENDS.rst
+++ b/Help/prop_sf/OBJECT_DEPENDS.rst
@@ -3,7 +3,7 @@ OBJECT_DEPENDS
Additional files on which a compiled object file depends.
-Specifies a :ref:`;-list <CMake Language Lists>` of full-paths to
+Specifies a :ref:`semicolon-separated list <CMake Language Lists>` of full-paths to
files on which any object files compiled from this source file depend.
On :ref:`Makefile Generators` and the :generator:`Ninja` generator an
object file will be recompiled if any of the named files is newer than it.
diff --git a/Help/prop_sf/OBJECT_OUTPUTS.rst b/Help/prop_sf/OBJECT_OUTPUTS.rst
index 6a2855374..e7e880b29 100644
--- a/Help/prop_sf/OBJECT_OUTPUTS.rst
+++ b/Help/prop_sf/OBJECT_OUTPUTS.rst
@@ -1,9 +1,9 @@
OBJECT_OUTPUTS
--------------
-Additional outputs for a Makefile rule.
+Additional outputs for a :generator:`Ninja` or :ref:`Makefile Generators` 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.
+supported only on the :generator:`Ninja` and :ref:`Makefile Generators`
+and will be ignored on other generators.
diff --git a/Help/prop_sf/SKIP_AUTOGEN.rst b/Help/prop_sf/SKIP_AUTOGEN.rst
index 6bf2409b2..f31185a5b 100644
--- a/Help/prop_sf/SKIP_AUTOGEN.rst
+++ b/Help/prop_sf/SKIP_AUTOGEN.rst
@@ -4,5 +4,14 @@ SKIP_AUTOGEN
Exclude the source file from :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTOUIC` and
:prop_tgt:`AUTORCC` processing (for Qt projects).
-For finer control see :prop_sf:`SKIP_AUTOMOC`, :prop_sf:`SKIP_AUTOUIC` and
-:prop_sf:`SKIP_AUTORCC`.
+For finer exclusion control see :prop_sf:`SKIP_AUTOMOC`,
+:prop_sf:`SKIP_AUTOUIC` and :prop_sf:`SKIP_AUTORCC`.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(SOURCE file.h PROPERTY SKIP_AUTOGEN ON)
+ # ...
diff --git a/Help/prop_sf/SKIP_AUTOMOC.rst b/Help/prop_sf/SKIP_AUTOMOC.rst
index 2245ca639..a9294489a 100644
--- a/Help/prop_sf/SKIP_AUTOMOC.rst
+++ b/Help/prop_sf/SKIP_AUTOMOC.rst
@@ -3,4 +3,13 @@ SKIP_AUTOMOC
Exclude the source file from :prop_tgt:`AUTOMOC` processing (for Qt projects).
-For broader control see :prop_sf:`SKIP_AUTOGEN`
+For broader exclusion control see :prop_sf:`SKIP_AUTOGEN`.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(SOURCE file.h PROPERTY SKIP_AUTOMOC ON)
+ # ...
diff --git a/Help/prop_sf/SKIP_AUTORCC.rst b/Help/prop_sf/SKIP_AUTORCC.rst
index 394d8f8cf..bccccfc93 100644
--- a/Help/prop_sf/SKIP_AUTORCC.rst
+++ b/Help/prop_sf/SKIP_AUTORCC.rst
@@ -3,4 +3,13 @@ SKIP_AUTORCC
Exclude the source file from :prop_tgt:`AUTORCC` processing (for Qt projects).
-For broader control see :prop_sf:`SKIP_AUTOGEN`
+For broader exclusion control see :prop_sf:`SKIP_AUTOGEN`.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(SOURCE file.qrc PROPERTY SKIP_AUTORCC ON)
+ # ...
diff --git a/Help/prop_sf/SKIP_AUTOUIC.rst b/Help/prop_sf/SKIP_AUTOUIC.rst
index 50f78ef66..8c962dbfe 100644
--- a/Help/prop_sf/SKIP_AUTOUIC.rst
+++ b/Help/prop_sf/SKIP_AUTOUIC.rst
@@ -3,4 +3,18 @@ SKIP_AUTOUIC
Exclude the source file from :prop_tgt:`AUTOUIC` processing (for Qt projects).
-For broader control see :prop_sf:`SKIP_AUTOGEN`
+:prop_sf:`SKIP_AUTOUIC` can be set on C++ header and source files and on
+``.ui`` files.
+
+For broader exclusion control see :prop_sf:`SKIP_AUTOGEN`.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(SOURCE file.h PROPERTY SKIP_AUTOUIC ON)
+ set_property(SOURCE file.cpp PROPERTY SKIP_AUTOUIC ON)
+ set_property(SOURCE widget.ui PROPERTY SKIP_AUTOUIC ON)
+ # ...
diff --git a/Help/prop_sf/SYMBOLIC.rst b/Help/prop_sf/SYMBOLIC.rst
index c7d0b2603..8bebe30bb 100644
--- a/Help/prop_sf/SYMBOLIC.rst
+++ b/Help/prop_sf/SYMBOLIC.rst
@@ -3,6 +3,6 @@ SYMBOLIC
Is this just a name for a rule.
-If SYMBOLIC (boolean) is set to true the build system will be informed
+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_CSHARP_tagname.rst b/Help/prop_sf/VS_CSHARP_tagname.rst
index d42159f6d..91c4a06c1 100644
--- a/Help/prop_sf/VS_CSHARP_tagname.rst
+++ b/Help/prop_sf/VS_CSHARP_tagname.rst
@@ -3,8 +3,9 @@ VS_CSHARP_<tagname>
Visual Studio and CSharp source-file-specific configuration.
-Tell the Visual Studio generator to set the source file tag
-``<tagname>`` to a given value in the generated Visual Studio CSharp
+Tell the :manual:`Visual Studio generators <cmake-generators(7)>`
+to set the source file tag ``<tagname>``
+to a given value in the generated Visual Studio CSharp
project. Ignored on other generators and languages. This property
can be used to define dependencies between source files or set any
other Visual Studio specific parameters.
diff --git a/Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst b/Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst
index 9fb3ba3d0..6a38478fe 100644
--- a/Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst
+++ b/Help/prop_sf/VS_DEPLOYMENT_CONTENT.rst
@@ -2,7 +2,8 @@ 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.
+Windows Store application when built with a
+:manual:`Visual Studio generators <cmake-generators(7)>`.
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.
diff --git a/Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst b/Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst
index 303db952b..2ce22fced 100644
--- a/Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst
+++ b/Help/prop_sf/VS_DEPLOYMENT_LOCATION.rst
@@ -2,7 +2,8 @@ VS_DEPLOYMENT_LOCATION
----------------------
Specifies the deployment location for a content source file with a Windows
-Phone or Windows Store application when built with a Visual Studio generator.
+Phone or Windows Store application when built
+with a :manual:`Visual Studio generators <cmake-generators(7)>`.
This property is only applicable when using :prop_sf:`VS_DEPLOYMENT_CONTENT`.
The value represent the path relative to the app package and applies to all
configurations.
diff --git a/Help/prop_sf/VS_INCLUDE_IN_VSIX.rst b/Help/prop_sf/VS_INCLUDE_IN_VSIX.rst
index 30f471d30..db470ef00 100644
--- a/Help/prop_sf/VS_INCLUDE_IN_VSIX.rst
+++ b/Help/prop_sf/VS_INCLUDE_IN_VSIX.rst
@@ -1,6 +1,6 @@
VS_INCLUDE_IN_VSIX
------------------
-Boolean property to specify if the file should be included within a VSIX
-extension package. This is needed for development of Visual Studio
-extensions.
+Boolean property to specify if the file should be included within a
+VSIX (Visual Studio Integration Extension) extension package.
+This is needed for development of Visual Studio extensions.
diff --git a/Help/prop_sf/VS_SHADER_FLAGS.rst b/Help/prop_sf/VS_SHADER_FLAGS.rst
index 09011231b..0a53afd1c 100644
--- a/Help/prop_sf/VS_SHADER_FLAGS.rst
+++ b/Help/prop_sf/VS_SHADER_FLAGS.rst
@@ -1,4 +1,4 @@
VS_SHADER_FLAGS
---------------
-Set additional VS shader flags of a ``.hlsl`` source file.
+Set additional Visual Studio shader flags of a ``.hlsl`` source file.
diff --git a/Help/prop_sf/VS_SHADER_TYPE.rst b/Help/prop_sf/VS_SHADER_TYPE.rst
index 688025608..f1048379a 100644
--- a/Help/prop_sf/VS_SHADER_TYPE.rst
+++ b/Help/prop_sf/VS_SHADER_TYPE.rst
@@ -1,4 +1,4 @@
VS_SHADER_TYPE
--------------
-Set the VS shader type of a ``.hlsl`` source file.
+Set the Visual Studio shader type of a ``.hlsl`` source file.
diff --git a/Help/prop_sf/VS_XAML_TYPE.rst b/Help/prop_sf/VS_XAML_TYPE.rst
index e92191dcb..1a274ba4e 100644
--- a/Help/prop_sf/VS_XAML_TYPE.rst
+++ b/Help/prop_sf/VS_XAML_TYPE.rst
@@ -1,6 +1,7 @@
VS_XAML_TYPE
------------
-Mark a XAML source file as a different type than the default ``Page``.
-The most common usage would be to set the default App.xaml file as
-ApplicationDefinition.
+Mark a Extensible Application Markup Language (XAML) source file
+as a different type than the default ``Page``.
+The most common usage would be to set the default ``App.xaml`` file as
+``ApplicationDefinition``.
diff --git a/Help/prop_sf/WRAP_EXCLUDE.rst b/Help/prop_sf/WRAP_EXCLUDE.rst
index 2c79f72a2..638ff0398 100644
--- a/Help/prop_sf/WRAP_EXCLUDE.rst
+++ b/Help/prop_sf/WRAP_EXCLUDE.rst
@@ -4,7 +4,8 @@ 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.
+provide additional functionality.
+
+For example, C++ code can be wrapped into Java or Python, using SWIG.
+If ``WRAP_EXCLUDE`` is set to ``True``, 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
index 1b24701a3..b8cf946ea 100644
--- a/Help/prop_sf/XCODE_EXPLICIT_FILE_TYPE.rst
+++ b/Help/prop_sf/XCODE_EXPLICIT_FILE_TYPE.rst
@@ -1,7 +1,7 @@
XCODE_EXPLICIT_FILE_TYPE
------------------------
-Set the Xcode ``explicitFileType`` attribute on its reference to a
+Set the :generator:`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.
diff --git a/Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst b/Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst
index 39e69665a..4c93f444a 100644
--- a/Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst
+++ b/Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst
@@ -1,9 +1,9 @@
XCODE_FILE_ATTRIBUTES
---------------------
-Add values to the Xcode ``ATTRIBUTES`` setting on its reference to a
+Add values to the :generator:`Xcode` ``ATTRIBUTES`` setting on its reference to a
source file. Among other things, this can be used to set the role on
-a mig file::
+a ``.mig`` file::
set_source_files_properties(defs.mig
PROPERTIES
diff --git a/Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst b/Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst
index 42e37574d..b21891fce 100644
--- a/Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst
+++ b/Help/prop_sf/XCODE_LAST_KNOWN_FILE_TYPE.rst
@@ -1,8 +1,8 @@
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
+Set the :generator:`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
diff --git a/Help/prop_test/COST.rst b/Help/prop_test/COST.rst
index 3236a0295..9300d7b27 100644
--- a/Help/prop_test/COST.rst
+++ b/Help/prop_test/COST.rst
@@ -1,7 +1,14 @@
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. When parallel testing is
+enabled, tests in the test set will be run in descending order of cost.
+Projects can explicitly define the cost of a test by setting this property
+to a floating point value.
-This property describes the cost of a test. You can explicitly set
-this value; tests with higher COST values will run first.
+When the cost of a test is not defined by the project,
+:manual:`ctest <ctest(1)>` will initially use a default cost of ``0``.
+It computes a weighted average of the cost each time a test is run and
+uses that as an improved estimate of the cost for the next run. The more
+a test is re-run in the same build directory, the more representative the
+cost should become.
diff --git a/Help/prop_test/DISABLED.rst b/Help/prop_test/DISABLED.rst
index c18ae7ffa..1d469e80b 100644
--- a/Help/prop_test/DISABLED.rst
+++ b/Help/prop_test/DISABLED.rst
@@ -1,15 +1,15 @@
DISABLED
--------
-If set to true, the test will be skipped and its status will be 'Not Run'. A
-DISABLED test will not be counted in the total number of tests and its
-completion status will be reported to CDash as 'Disabled'.
+If set to ``True``, the test will be skipped and its status will be 'Not Run'. A
+``DISABLED`` test will not be counted in the total number of tests and its
+completion status will be reported to CDash as ``Disabled``.
-A DISABLED test does not participate in test fixture dependency resolution.
-If a DISABLED test has fixture requirements defined in its
+A ``DISABLED`` test does not participate in test fixture dependency resolution.
+If a ``DISABLED`` test has fixture requirements defined in its
:prop_test:`FIXTURES_REQUIRED` property, it will not cause setup or cleanup
tests for those fixtures to be added to the test set.
-If a test with the :prop_test:`FIXTURES_SETUP` property set is DISABLED, the
-fixture behavior will be as though that setup test was passing and any test
+If a test with the :prop_test:`FIXTURES_SETUP` property set is ``DISABLED``,
+the fixture behavior will be as though that setup test was passing and any test
case requiring that fixture will still run.
diff --git a/Help/prop_test/ENVIRONMENT.rst b/Help/prop_test/ENVIRONMENT.rst
index df9bc9e14..102c7922f 100644
--- a/Help/prop_test/ENVIRONMENT.rst
+++ b/Help/prop_test/ENVIRONMENT.rst
@@ -4,6 +4,6 @@ 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
+``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/FIXTURES_CLEANUP.rst b/Help/prop_test/FIXTURES_CLEANUP.rst
index f0a4be0ec..3075b4d48 100644
--- a/Help/prop_test/FIXTURES_CLEANUP.rst
+++ b/Help/prop_test/FIXTURES_CLEANUP.rst
@@ -2,7 +2,8 @@ FIXTURES_CLEANUP
----------------
Specifies a list of fixtures for which the test is to be treated as a cleanup
-test.
+test. These fixture names are distinct from test case names and are not
+required to have any similarity to the names of tests associated with them.
Fixture cleanup tests are ordinary tests with all of the usual test
functionality. Setting the ``FIXTURES_CLEANUP`` property for a test has two
diff --git a/Help/prop_test/FIXTURES_REQUIRED.rst b/Help/prop_test/FIXTURES_REQUIRED.rst
index e37dfb57d..e3f60c426 100644
--- a/Help/prop_test/FIXTURES_REQUIRED.rst
+++ b/Help/prop_test/FIXTURES_REQUIRED.rst
@@ -2,7 +2,7 @@ FIXTURES_REQUIRED
-----------------
Specifies a list of fixtures the test requires. Fixture names are case
-sensitive.
+sensitive and they are not required to have any similarity to test names.
Fixtures are a way to attach setup and cleanup tasks to a set of tests. If a
test requires a given fixture, then all tests marked as setup tasks for that
@@ -19,7 +19,9 @@ some setup tests fail.
When CTest is asked to execute only a subset of tests (e.g. by the use of
regular expressions or when run with the ``--rerun-failed`` command line
option), it will automatically add any setup or cleanup tests for fixtures
-required by any of the tests that are in the execution set.
+required by any of the tests that are in the execution set. This behavior can
+be overridden with the ``-FS``, ``-FC`` and ``-FA`` command line options to
+:manual:`ctest(1)` if desired.
Since setup and cleanup tasks are also tests, they can have an ordering
specified by the :prop_test:`DEPENDS` test property just like any other tests.
diff --git a/Help/prop_test/FIXTURES_SETUP.rst b/Help/prop_test/FIXTURES_SETUP.rst
index a22021592..fdb21cc76 100644
--- a/Help/prop_test/FIXTURES_SETUP.rst
+++ b/Help/prop_test/FIXTURES_SETUP.rst
@@ -2,14 +2,15 @@ FIXTURES_SETUP
--------------
Specifies a list of fixtures for which the test is to be treated as a setup
-test.
+test. These fixture names are distinct from test case names and are not
+required to have any similarity to the names of tests associated with them.
Fixture setup tests are ordinary tests with all of the usual test
functionality. Setting the ``FIXTURES_SETUP`` property for a test has two
primary effects:
- CTest will ensure the test executes before any other test which lists the
- fixture(s) in its :prop_test:`FIXTURES_REQUIRED` property.
+ fixture name(s) in its :prop_test:`FIXTURES_REQUIRED` property.
- If CTest is asked to run only a subset of tests (e.g. using regular
expressions or the ``--rerun-failed`` option) and the setup test is not in
diff --git a/Help/prop_test/MEASUREMENT.rst b/Help/prop_test/MEASUREMENT.rst
index bc4936e97..de459ed4e 100644
--- a/Help/prop_test/MEASUREMENT.rst
+++ b/Help/prop_test/MEASUREMENT.rst
@@ -1,8 +1,8 @@
MEASUREMENT
-----------
-Specify a CDASH measurement and value to be reported for a test.
+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".
+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/PROCESSORS.rst b/Help/prop_test/PROCESSORS.rst
index 763b6d003..a927c1078 100644
--- a/Help/prop_test/PROCESSORS.rst
+++ b/Help/prop_test/PROCESSORS.rst
@@ -1,8 +1,16 @@
PROCESSORS
----------
-How many process slots this test requires
+Set to specify how many process slots this test requires.
+If not set, the default is ``1`` processor.
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.
+the :command:`ctest_test` ``PARALLEL_LEVEL`` option.
+
+This will also be used to display a weighted test timing result in label and
+subproject summaries in the command line output of :manual:`ctest(1)`. The wall
+clock time for the test run will be multiplied by this property to give a
+better idea of how much cpu resource CTest allocated for the test.
+
+See also the :prop_test:`PROCESSOR_AFFINITY` test property.
diff --git a/Help/prop_test/RUN_SERIAL.rst b/Help/prop_test/RUN_SERIAL.rst
index 8f65ae18a..ab4c54233 100644
--- a/Help/prop_test/RUN_SERIAL.rst
+++ b/Help/prop_test/RUN_SERIAL.rst
@@ -3,6 +3,6 @@ RUN_SERIAL
Do not run this test in parallel with any other test.
-Use this option in conjunction with the ctest_test PARALLEL_LEVEL
+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
index c61273c56..a05fbf3b3 100644
--- a/Help/prop_test/SKIP_RETURN_CODE.rst
+++ b/Help/prop_test/SKIP_RETURN_CODE.rst
@@ -6,4 +6,4 @@ 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.
+``Not Run`` if it is encountered.
diff --git a/Help/prop_test/WORKING_DIRECTORY.rst b/Help/prop_test/WORKING_DIRECTORY.rst
index 5222a197b..92a040967 100644
--- a/Help/prop_test/WORKING_DIRECTORY.rst
+++ b/Help/prop_test/WORKING_DIRECTORY.rst
@@ -3,5 +3,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.
+If this is not set, the test will be run with the working directory set to the
+binary directory associated with where the test was created (i.e. the
+:variable:`CMAKE_CURRENT_BINARY_DIR` for where :command:`add_test` was
+called).
diff --git a/Help/prop_tgt/ANDROID_NATIVE_LIB_DIRECTORIES.rst b/Help/prop_tgt/ANDROID_NATIVE_LIB_DIRECTORIES.rst
index bc673804d..d0cd29de8 100644
--- a/Help/prop_tgt/ANDROID_NATIVE_LIB_DIRECTORIES.rst
+++ b/Help/prop_tgt/ANDROID_NATIVE_LIB_DIRECTORIES.rst
@@ -1,8 +1,8 @@
ANDROID_NATIVE_LIB_DIRECTORIES
------------------------------
-Set the Android property that specifies directories to search for the
-.so libraries.
+Set the Android property that specifies directories to search for the ``.so``
+libraries.
This a string property that contains the directory paths separated
by semicolons.
diff --git a/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst b/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst
index 8db6ede91..909b14c34 100644
--- a/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst
+++ b/Help/prop_tgt/AUTOGEN_BUILD_DIR.rst
@@ -5,7 +5,7 @@ Directory where :prop_tgt:`AUTOMOC`, :prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC`
generate files for the target.
The directory is created on demand and automatically added to the
-:prop_dir:`ADDITIONAL_MAKE_CLEAN_FILES`.
+:prop_tgt:`ADDITIONAL_CLEAN_FILES` target property.
When unset or empty the directory ``<dir>/<target-name>_autogen`` is used where
``<dir>`` is :variable:`CMAKE_CURRENT_BINARY_DIR` and ``<target-name>``
diff --git a/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst b/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst
index f522c6bf2..d5c5e147d 100644
--- a/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst
+++ b/Help/prop_tgt/AUTOGEN_TARGET_DEPENDS.rst
@@ -1,17 +1,36 @@
AUTOGEN_TARGET_DEPENDS
----------------------
-Target dependencies of the corresponding ``_autogen`` target.
+Additional target dependencies of the corresponding ``_autogen`` target.
-Targets which have their :prop_tgt:`AUTOMOC` target ``ON`` have a
-corresponding ``_autogen`` target which is used to autogenerate generate moc
-files. As this ``_autogen`` target is created at generate-time, it is not
-possible to define dependencies of it, such as to create inputs for the ``moc``
-executable.
+Targets which have their :prop_tgt:`AUTOMOC` or :prop_tgt:`AUTOUIC` property
+``ON`` have a corresponding ``_autogen`` target which generates
+``moc`` and ``uic`` files. As this ``_autogen`` target is created at
+generate-time, it is not possible to define dependencies of it using
+e.g. :command:`add_dependencies`. Instead the
+:prop_tgt:`AUTOGEN_TARGET_DEPENDS` target property can be set to a
+:ref:`;-list <CMake Language Lists>` of additional dependencies for the
+``_autogen`` target. Dependencies can be target names or file names.
-The ``AUTOGEN_TARGET_DEPENDS`` target property can be set instead to a list of
-dependencies for the ``_autogen`` target. The buildsystem will be generated to
-depend on its contents.
+In total the dependencies of the ``_autogen`` target are composed from
+
+- forwarded origin target dependencies
+ (enabled by default via :prop_tgt:`AUTOGEN_ORIGIN_DEPENDS`)
+- additional user defined dependencies from :prop_tgt:`AUTOGEN_TARGET_DEPENDS`
See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt.
+
+Use cases
+^^^^^^^^^
+
+If :prop_tgt:`AUTOMOC` or :prop_tgt:`AUTOUIC` depends on a file that is either
+
+- a :prop_sf:`GENERATED` non C++ file (e.g. a :prop_sf:`GENERATED` ``.json``
+ or ``.ui`` file) or
+- a :prop_sf:`GENERATED` C++ file that isn't recognized by :prop_tgt:`AUTOMOC`
+ and :prop_tgt:`AUTOUIC` because it's skipped by :prop_sf:`SKIP_AUTOMOC`,
+ :prop_sf:`SKIP_AUTOUIC`, :prop_sf:`SKIP_AUTOGEN` or :policy:`CMP0071` or
+- a file that isn't in the origin target's sources
+
+it must added to :prop_tgt:`AUTOGEN_TARGET_DEPENDS`.
diff --git a/Help/prop_tgt/AUTOMOC.rst b/Help/prop_tgt/AUTOMOC.rst
index 0171d20e7..f6dfabdd3 100644
--- a/Help/prop_tgt/AUTOMOC.rst
+++ b/Help/prop_tgt/AUTOMOC.rst
@@ -1,76 +1,247 @@
AUTOMOC
-------
-Should the target be processed with automoc (for Qt projects).
+Should the target be processed with auto-moc (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.
+:prop_tgt:`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.
+
+This property is initialized by the value of the :variable:`CMAKE_AUTOMOC`
+variable if it is set when a target is created.
When this property is set ``ON``, CMake will scan the header and
-source files at build time and invoke moc accordingly.
+source files at build time and invoke ``moc`` accordingly.
-* If an ``#include`` statement like ``#include "moc_<basename>.cpp"`` is found,
- the ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in an otherwise empty
- line of the ``<basename>.h(xx)`` header file. ``moc`` is run on the header
- file to generate ``moc_<basename>.cpp`` in the
- ``<AUTOGEN_BUILD_DIR>/include`` directory which is automatically added
- to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
- This allows the compiler to find the included ``moc_<basename>.cpp`` file
- regardless of the location the original source.
- * See :prop_tgt:`AUTOGEN_BUILD_DIR`.
+Header file processing
+^^^^^^^^^^^^^^^^^^^^^^
-* If an ``#include`` statement like ``#include "<basename>.moc"`` is found,
- then ``Q_OBJECT`` or ``Q_GADGET`` macros are expected in the current source
- file and ``moc`` is run on the source file itself.
+At configuration time, a list of header files that should be scanned by
+:prop_tgt:`AUTOMOC` is computed from the target's sources.
-* Header files that are not included by an ``#include "moc_<basename>.cpp"``
- statement are nonetheless scanned for ``Q_OBJECT`` or ``Q_GADGET`` macros.
- The resulting ``moc_<basename>.cpp`` files are generated in custom
- directories and automatically included in a generated
- ``<AUTOGEN_BUILD_DIR>/mocs_compilation.cpp`` file,
- which is compiled as part of the target.
+- All header files in the target's sources are added to the scan list.
+- For all C++ source files ``<source_base>.<source_extension>`` in the
+ target's sources, CMake searches for
- * The custom directories with checksum
- based names help to avoid name collisions for moc files with the same
- ``<basename>``.
+ - a regular header with the same base name
+ (``<source_base>.<header_extention>``) and
+ - a private header with the same base name and a ``_p`` suffix
+ (``<source_base>_p.<header_extention>``)
- * See :prop_tgt:`AUTOGEN_BUILD_DIR`.
+ and adds these to the scan list.
-* Additionally, header files with the same base name as a source file,
- (like ``<basename>.h``) or ``_p`` appended to the base name (like
- ``<basename>_p.h``), are parsed for ``Q_OBJECT`` or ``Q_GADGET`` macros,
- and if found, ``moc`` is also executed on those files.
+At build time, CMake scans each unknown or modified header file from the
+list and searches for
-* ``AUTOMOC`` always checks multiple header alternative extensions,
- such as ``hpp``, ``hxx``, etc. when searching for headers.
+- a Qt macro from :prop_tgt:`AUTOMOC_MACRO_NAMES`,
+- additional file dependencies from the ``FILE`` argument of a
+ ``Q_PLUGIN_METADATA`` macro and
+- additional file dependencies detected by filters defined in
+ :prop_tgt:`AUTOMOC_DEPEND_FILTERS`.
-* ``AUTOMOC`` looks for the ``Q_PLUGIN_METADATA`` macro and reruns the
- ``moc`` when the file addressed by the ``FILE`` argument of the macro changes.
+If a Qt macro is found, then the header will be compiled by the ``moc`` to the
+output file ``moc_<base_name>.cpp``. The complete output file path is
+described in the section `Output file location`_.
-This property is initialized by the value of the :variable:`CMAKE_AUTOMOC`
-variable if it is set when a target is created.
+The header will be ``moc`` compiled again if a file from the additional file
+dependencies changes.
+
+Header ``moc`` output files ``moc_<base_name>.cpp`` can be included in source
+files. In the section `Including header moc files in sources`_ there is more
+information on that topic.
+
+
+Source file processing
+^^^^^^^^^^^^^^^^^^^^^^
+
+At build time, CMake scans each unknown or modified C++ source file from the
+target's sources for
+
+- a Qt macro from :prop_tgt:`AUTOMOC_MACRO_NAMES`,
+- includes of header ``moc`` files
+ (see `Including header moc files in sources`_),
+- additional file dependencies from the ``FILE`` argument of a
+ ``Q_PLUGIN_METADATA`` macro and
+- additional file dependencies detected by filters defined in
+ :prop_tgt:`AUTOMOC_DEPEND_FILTERS`.
+
+If a Qt macro is found, then the C++ source file
+``<base>.<source_extension>`` is expected to as well contain an include
+statement
+
+.. code-block:: c++
+
+ #include <<base>.moc> // or
+ #include "<base>.moc"
+
+The source file then will be compiled by the ``moc`` to the output file
+``<base>.moc``. A description of the complete output file path is in section
+`Output file location`_.
+
+The source will be ``moc`` compiled again if a file from the additional file
+dependencies changes.
+
+Including header moc files in sources
+"""""""""""""""""""""""""""""""""""""
+
+A source file can include the ``moc`` output file of a header
+``<header_base>.<header_extension>`` by using an include statement of
+the form
+
+.. code-block:: c++
+
+ #include <moc_<header_base>.cpp> // or
+ #include "moc_<header_base>.cpp"
+
+If the ``moc`` output file of a header is included by a source, it will
+be generated in a different location than if it was not included. This is
+described in the section `Output file location`_.
+
+
+Output file location
+^^^^^^^^^^^^^^^^^^^^
+
+Included moc output files
+"""""""""""""""""""""""""
+
+``moc`` output files that are included by a source file will be generated in
+
+- ``<AUTOGEN_BUILD_DIR>/include``
+ for single configuration generators or in
+- ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>``
+ for :prop_gbl:`multi configuration <GENERATOR_IS_MULTI_CONFIG>` generators.
+
+Where ``<AUTOGEN_BUILD_DIR>`` is the value of the target property
+:prop_tgt:`AUTOGEN_BUILD_DIR`.
+
+The include directory is automatically added to the target's
+:prop_tgt:`INCLUDE_DIRECTORIES`.
+
+Not included moc output files
+"""""""""""""""""""""""""""""
+
+``moc`` output files that are not included in a source file will be generated
+in
+
+- ``<AUTOGEN_BUILD_DIR>/<SOURCE_DIR_CHECKSUM>``
+ for single configuration generators or in,
+- ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>/<SOURCE_DIR_CHECKSUM>``
+ for :prop_gbl:`multi configuration <GENERATOR_IS_MULTI_CONFIG>` generators.
+
+Where ``<SOURCE_DIR_CHECKSUM>`` is a checksum computed from the relative
+parent directory path of the ``moc`` input file. This scheme allows to have
+``moc`` input files with the same name in different directories.
+
+All not included ``moc`` output files will be included automatically by the
+CMake generated file
+
+- ``<AUTOGEN_BUILD_DIR>/mocs_compilation.cpp``,
+
+which is added to the target's sources.
+
+
+Qt version detection
+^^^^^^^^^^^^^^^^^^^^
+
+:prop_tgt:`AUTOMOC` enabled targets need to know the Qt major and minor
+version they're working with. The major version usually is provided by the
+``INTERFACE_QT_MAJOR_VERSION`` property of the ``Qt[45]Core`` library,
+that the target links to. To find the minor version, CMake builds a list of
+available Qt versions from
+
+- ``Qt5Core_VERSION_MAJOR`` and ``Qt5Core_VERSION_MINOR`` variables
+ (usually set by ``find_package(Qt5...)``)
+- ``Qt5Core_VERSION_MAJOR`` and ``Qt5Core_VERSION_MINOR`` directory properties
+- ``QT_VERSION_MAJOR`` and ``QT_VERSION_MINOR`` variables
+ (usually set by ``find_package(Qt4...)``)
+- ``QT_VERSION_MAJOR`` and ``QT_VERSION_MINOR`` directory properties
+
+in the context of the :command:`add_executable` or :command:`add_library` call.
+
+Assumed ``INTERFACE_QT_MAJOR_VERSION`` is a valid number, the first
+entry in the list with a matching major version is taken. If no matching major
+version was found, an error is generated.
+If ``INTERFACE_QT_MAJOR_VERSION`` is not a valid number, the first
+entry in the list is taken.
-Additional command line options for moc can be set via the
-:prop_tgt:`AUTOMOC_MOC_OPTIONS` property.
+A ``find_package(Qt[45]...)`` call sets the ``QT/Qt5Core_VERSION_MAJOR/MINOR``
+variables. If the call is in a different context than the
+:command:`add_executable` or :command:`add_library` call, e.g. in a function,
+then the version variables might not be available to the :prop_tgt:`AUTOMOC`
+enabled target.
+In that case the version variables can be forwarded from the
+`find_package(Qt[45]...)` calling context to the :command:`add_executable`
+or :command:`add_library` calling context as directory properties.
+The following Qt5 example demonstrates the procedure.
-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.
+.. code-block:: cmake
-The global property :prop_gbl:`AUTOGEN_TARGETS_FOLDER` can be used to group the
-automoc targets together in an IDE, e.g. in MSVS.
+ function (add_qt5_client)
+ find_package(Qt5 REQUIRED QUIET COMPONENTS Core Widgets)
+ ...
+ set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ PROPERTY Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}")
+ set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ PROPERTY Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MAJOR}")
+ ...
+ endfunction ()
+ ...
+ add_qt5_client()
+ add_executable(myTarget main.cpp)
+ target_link_libraries(myTarget Qt5::QtWidgets)
+ set_property(TARGET myTarget PROPERTY AUTOMOC ON)
-The global property :prop_gbl:`AUTOGEN_SOURCE_GROUP` can be used to group
-files generated by :prop_tgt:`AUTOMOC` together in an IDE, e.g. in MSVS.
-Additional ``moc`` dependency file names can be extracted from source code
-by using :prop_tgt:`AUTOMOC_DEPEND_FILTERS`.
+Modifiers
+^^^^^^^^^
-Source C++ files can be excluded from :prop_tgt:`AUTOMOC` processing by
-enabling :prop_sf:`SKIP_AUTOMOC` or the broader :prop_sf:`SKIP_AUTOGEN`.
+:prop_tgt:`AUTOMOC_EXECUTABLE`:
+The ``moc`` executable will be detected automatically, but can be forced to
+a certain binary using this target property.
+
+:prop_tgt:`AUTOMOC_MOC_OPTIONS`:
+Additional command line options for ``moc`` can be set in this target property.
+
+:prop_tgt:`AUTOMOC_MACRO_NAMES`:
+This list of Qt macro names can be extended to search for additional macros in
+headers and sources.
+
+:prop_tgt:`AUTOMOC_DEPEND_FILTERS`:
+``moc`` dependency file names can be extracted from headers or sources by
+defining file name filters in this target property.
+
+:prop_tgt:`AUTOMOC_COMPILER_PREDEFINES`:
+Compiler pre definitions for ``moc`` are written to the ``moc_predefs.h`` file.
+The generation of this file can be enabled or disabled in this target property.
+
+:prop_sf:`SKIP_AUTOMOC`:
+Sources and headers can be excluded from :prop_tgt:`AUTOMOC` processing by
+setting this source file property.
+
+:prop_sf:`SKIP_AUTOGEN`:
+Source files can be excluded from :prop_tgt:`AUTOMOC`,
+:prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` processing by
+setting this source file property.
+
+:prop_gbl:`AUTOGEN_SOURCE_GROUP`:
+This global property can be used to group files generated by
+:prop_tgt:`AUTOMOC` or :prop_tgt:`AUTORCC` together in an IDE, e.g. in MSVS.
+
+:prop_gbl:`AUTOGEN_TARGETS_FOLDER`:
+This global property can be used to group :prop_tgt:`AUTOMOC`,
+:prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` targets together in an IDE,
+e.g. in MSVS.
+
+:variable:`CMAKE_GLOBAL_AUTOGEN_TARGET`:
+A global ``autogen`` target, that depends on all :prop_tgt:`AUTOMOC` or
+:prop_tgt:`AUTOUIC` generated ``<ORIGIN>_autogen`` targets in the project,
+will be generated when this variable is ``ON``.
+
+:prop_tgt:`AUTOGEN_PARALLEL`:
+This target property controls the number of ``moc`` or ``uic`` processes to
+start in parallel during builds.
See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt.
diff --git a/Help/prop_tgt/AUTOMOC_DEPEND_FILTERS.rst b/Help/prop_tgt/AUTOMOC_DEPEND_FILTERS.rst
index 810cbf4ae..69957bf18 100644
--- a/Help/prop_tgt/AUTOMOC_DEPEND_FILTERS.rst
+++ b/Help/prop_tgt/AUTOMOC_DEPEND_FILTERS.rst
@@ -1,21 +1,27 @@
AUTOMOC_DEPEND_FILTERS
----------------------
-Filter definitions used by :prop_tgt:`AUTOMOC` to extract file names from
-source code as additional dependencies for the ``moc`` file.
-
-This property is only used if the :prop_tgt:`AUTOMOC` property is ``ON``
-for this target.
+Filter definitions used by :prop_tgt:`AUTOMOC` to extract file names from a
+source file that are registered as additional dependencies for the
+``moc`` file of the source file.
Filters are defined as ``KEYWORD;REGULAR_EXPRESSION`` pairs. First the file
content is searched for ``KEYWORD``. If it is found at least once, then file
names are extracted by successively searching for ``REGULAR_EXPRESSION`` and
taking the first match group.
-Consider a filter extracts the file name ``DEP`` from the content of a file
-``FOO``. If ``DEP`` changes, then the ``moc`` file for ``FOO`` gets rebuilt.
-The file ``DEP`` is searched for first in the vicinity
-of ``FOO`` and afterwards in the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
+The file name found in the first match group is searched for
+
+- first in the vicinity of the source file
+- and afterwards in the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
+
+If any of the extracted files changes, then the ``moc`` file for the source
+file gets rebuilt even when the source file itself doesn't change.
+
+If any of the extracted files is :prop_sf:`GENERATED` or if it is not in the
+target's sources, then it might be necessary to add it to the
+``_autogen`` target dependencies.
+See :prop_tgt:`AUTOGEN_TARGET_DEPENDS` for reference.
By default :prop_tgt:`AUTOMOC_DEPEND_FILTERS` is initialized from
:variable:`CMAKE_AUTOMOC_DEPEND_FILTERS`, which is empty by default.
@@ -24,22 +30,75 @@ See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt.
-Example
--------
+Example 1
+^^^^^^^^^
-Consider a file ``FOO.hpp`` holds a custom macro ``OBJ_JSON_FILE`` and we
-want the ``moc`` file to depend on the macro`s file name argument::
+A header file ``my_class.hpp`` uses a custom macro ``JSON_FILE_MACRO`` which
+is defined in an other header ``macros.hpp``.
+We want the ``moc`` file of ``my_class.hpp`` to depend on the file name
+argument of ``JSON_FILE_MACRO``::
+ // my_class.hpp
class My_Class : public QObject
{
Q_OBJECT
- OBJ_JSON_FILE ( "DEP.json" )
+ JSON_FILE_MACRO ( "info.json" )
+ ...
+ };
+
+In ``CMakeLists.txt`` we add a filter to
+:variable:`CMAKE_AUTOMOC_DEPEND_FILTERS` like this::
+
+ list( APPEND CMAKE_AUTOMOC_DEPEND_FILTERS
+ "JSON_FILE_MACRO"
+ "[\n][ \t]*JSON_FILE_MACRO[ \t]*\\([ \t]*\"([^\"]+)\""
+ )
+
+We assume ``info.json`` is a plain (not :prop_sf:`GENERATED`) file that is
+listed in the target's source. Therefore we do not need to add it to
+:prop_tgt:`AUTOGEN_TARGET_DEPENDS`.
+
+Example 2
+^^^^^^^^^
+
+In the target ``my_target`` a header file ``complex_class.hpp`` uses a
+custom macro ``JSON_BASED_CLASS`` which is defined in an other header
+``macros.hpp``::
+
+ // macros.hpp
...
+ #define JSON_BASED_CLASS(name, json) \
+ class name : public QObject \
+ { \
+ Q_OBJECT \
+ Q_PLUGIN_METADATA(IID "demo" FILE json) \
+ name() {} \
};
+ ...
+
+::
-Then we might use :variable:`CMAKE_AUTOMOC_DEPEND_FILTERS` to
-define a filter like this::
+ // complex_class.hpp
+ #pragma once
+ JSON_BASED_CLASS(Complex_Class, "meta.json")
+ // end of file
- set(CMAKE_AUTOMOC_DEPEND_FILTERS
- "OBJ_JSON_FILE" "[\n][ \t]*OBJ_JSON_FILE[ \t]*\\([ \t]*\"([^\"]+)\""
+Since ``complex_class.hpp`` doesn't contain a ``Q_OBJECT`` macro it would be
+ignored by :prop_tgt:`AUTOMOC`. We change this by adding ``JSON_BASED_CLASS``
+to :variable:`CMAKE_AUTOMOC_MACRO_NAMES`::
+
+ list(APPEND CMAKE_AUTOMOC_MACRO_NAMES "JSON_BASED_CLASS")
+
+We want the ``moc`` file of ``complex_class.hpp`` to depend on
+``meta.json``. So we add a filter to
+:variable:`CMAKE_AUTOMOC_DEPEND_FILTERS`::
+
+ list(APPEND CMAKE_AUTOMOC_DEPEND_FILTERS
+ "JSON_BASED_CLASS"
+ "[\n^][ \t]*JSON_BASED_CLASS[ \t]*\\([^,]*,[ \t]*\"([^\"]+)\""
)
+
+Additionally we assume ``meta.json`` is :prop_sf:`GENERATED` which is
+why we have to add it to :prop_tgt:`AUTOGEN_TARGET_DEPENDS`::
+
+ set_property(TARGET my_target APPEND PROPERTY AUTOGEN_TARGET_DEPENDS "meta.json")
diff --git a/Help/prop_tgt/AUTORCC.rst b/Help/prop_tgt/AUTORCC.rst
index c0f6a26b2..cca3e583f 100644
--- a/Help/prop_tgt/AUTORCC.rst
+++ b/Help/prop_tgt/AUTORCC.rst
@@ -1,9 +1,9 @@
AUTORCC
-------
-Should the target be processed with autorcc (for Qt projects).
+Should the target be processed with auto-rcc (for Qt projects).
-``AUTORCC`` is a boolean specifying whether CMake will handle
+:prop_tgt:`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.
@@ -13,22 +13,49 @@ 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.
-
-The global property :prop_gbl:`AUTOGEN_SOURCE_GROUP` can be used to group
-files generated by :prop_tgt:`AUTORCC` together in an IDE, e.g. in MSVS.
+By default :prop_tgt:`AUTORCC` is processed by a
+:command:`custom command <add_custom_command>`.
+If the ``.qrc`` file is :prop_sf:`GENERATED`, a
+:command:`custom target <add_custom_target>` is used instead.
When there are multiple ``.qrc`` files with the same name, CMake will
-generate unspecified unique names for ``rcc``. Therefore if
-``Q_INIT_RESOURCE()`` or ``Q_CLEANUP_RESOURCE()`` need to be used the
+generate unspecified unique output file names for ``rcc``. Therefore, if
+``Q_INIT_RESOURCE()`` or ``Q_CLEANUP_RESOURCE()`` need to be used, the
``.qrc`` file name must be unique.
-Source files can be excluded from :prop_tgt:`AUTORCC` processing by
-enabling :prop_sf:`SKIP_AUTORCC` or the broader :prop_sf:`SKIP_AUTOGEN`.
+
+Modifiers
+^^^^^^^^^
+
+:prop_tgt:`AUTORCC_EXECUTABLE`:
+The ``rcc`` executable will be detected automatically, but can be forced to
+a certain binary by setting this target property.
+
+:prop_sf:`AUTORCC_OPTIONS`:
+Additional command line options for ``rcc`` can be set via this ``.qrc``
+source file property.
+
+:prop_sf:`SKIP_AUTORCC`:
+``.qrc`` files can be excluded from :prop_tgt:`AUTORCC` processing by
+setting this source file property.
+
+:prop_sf:`SKIP_AUTOGEN`:
+Source files can be excluded from :prop_tgt:`AUTOMOC`,
+:prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` processing by
+setting this source file property.
+
+:prop_gbl:`AUTOGEN_SOURCE_GROUP`:
+This global property can be used to group files generated by
+:prop_tgt:`AUTOMOC` or :prop_tgt:`AUTORCC` together in an IDE, e.g. in MSVS.
+
+:prop_gbl:`AUTOGEN_TARGETS_FOLDER`:
+This global property can be used to group :prop_tgt:`AUTOMOC`,
+:prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` targets together in an IDE,
+e.g. in MSVS.
+
+:variable:`CMAKE_GLOBAL_AUTORCC_TARGET`:
+A global ``autorcc`` target that depends on all :prop_tgt:`AUTORCC` targets
+in the project will be generated when this variable is ``ON``.
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
index 8a0f632c2..d6ade5adb 100644
--- a/Help/prop_tgt/AUTORCC_OPTIONS.rst
+++ b/Help/prop_tgt/AUTORCC_OPTIONS.rst
@@ -19,3 +19,12 @@ set on the ``.qrc`` source file.
See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(TARGET tgt PROPERTY AUTORCC_OPTIONS "--compress;9")
+ # ...
diff --git a/Help/prop_tgt/AUTOUIC.rst b/Help/prop_tgt/AUTOUIC.rst
index 6493bbc78..5cf87552c 100644
--- a/Help/prop_tgt/AUTOUIC.rst
+++ b/Help/prop_tgt/AUTOUIC.rst
@@ -1,34 +1,82 @@
AUTOUIC
-------
-Should the target be processed with autouic (for Qt projects).
+Should the target be processed with auto-uic (for Qt projects).
-``AUTOUIC`` is a boolean specifying whether CMake will handle
+:prop_tgt:`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 ``source.cpp``, a ``foo.ui`` file is
-searched for first in the vicinity of ``source.cpp`` and afterwards in the
-optional :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target.
-``uic`` is run on the ``foo.ui`` file to generate ``ui_foo.h`` in the directory
-``<AUTOGEN_BUILD_DIR>/include``,
-which is automatically added to the target's :prop_tgt:`INCLUDE_DIRECTORIES`.
-
-* See :prop_tgt:`AUTOGEN_BUILD_DIR`.
-
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.
+When this property is ``ON``, CMake will scan the header and source files at
+build time and invoke ``uic`` accordingly.
+
+
+Header and source file processing
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+At build time, CMake scans each header and source file from the
+target's sources for include statements of the form
+
+.. code-block:: c++
+
+ #include "ui_<ui_base>.h"
+
+Once such an include statement is found in a file, CMake searches for the
+``uic`` input file ``<ui_base>.ui``
+
+- in the vicinity of the file and
+- in the :prop_tgt:`AUTOUIC_SEARCH_PATHS` of the target.
+
+If the ``<ui_base>.ui`` file was found, ``uic`` is called on it to generate
+``ui_<ui_base>.h`` in the directory
+
+- ``<AUTOGEN_BUILD_DIR>/include`` for single configuration generators or in
+- ``<AUTOGEN_BUILD_DIR>/include_<CONFIG>`` for
+ :prop_gbl:`multi configuration <GENERATOR_IS_MULTI_CONFIG>` generators.
+
+Where ``<AUTOGEN_BUILD_DIR>`` is the value of the target property
+:prop_tgt:`AUTOGEN_BUILD_DIR`.
+
+The include directory is automatically added to the target's
+:prop_tgt:`INCLUDE_DIRECTORIES`.
+
+
+Modifiers
+^^^^^^^^^
+
+:prop_tgt:`AUTOUIC_EXECUTABLE`:
+The ``uic`` executable will be detected automatically, but can be forced to
+a certain binary using this target property.
+
+:prop_sf:`AUTOUIC_OPTIONS`: Additional command line options for ``uic`` can
+be set via this source file property on a ``<base_name>.ui`` file.
+
+:prop_sf:`SKIP_AUTOUIC`:
+Source files can be excluded from :prop_tgt:`AUTOUIC` processing by setting
+this source file property.
+
+:prop_sf:`SKIP_AUTOGEN`:
+Source files can be excluded from :prop_tgt:`AUTOMOC`,
+:prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` processing by
+setting this source file property.
+
+:prop_gbl:`AUTOGEN_TARGETS_FOLDER`:
+This global property can be used to group :prop_tgt:`AUTOMOC`,
+:prop_tgt:`AUTOUIC` and :prop_tgt:`AUTORCC` targets together in an IDE,
+e.g. in MSVS.
+
+:variable:`CMAKE_GLOBAL_AUTOGEN_TARGET`:
+A global ``autogen`` target, that depends on all :prop_tgt:`AUTOMOC` or
+:prop_tgt:`AUTOUIC` generated ``<ORIGIN>_autogen`` targets in the project,
+will be generated when this variable is ``ON``.
-Source files can be excluded from :prop_tgt:`AUTOUIC` processing by
-enabling :prop_sf:`SKIP_AUTOUIC` or the broader :prop_sf:`SKIP_AUTOGEN`.
+:prop_tgt:`AUTOGEN_PARALLEL`:
+This target property controls the number of ``moc`` or ``uic`` processes to
+start in parallel during builds.
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
index 9fb042ea6..3f613b952 100644
--- a/Help/prop_tgt/AUTOUIC_OPTIONS.rst
+++ b/Help/prop_tgt/AUTOUIC_OPTIONS.rst
@@ -23,3 +23,12 @@ expressions.
See the :manual:`cmake-qt(7)` manual for more information on using CMake
with Qt.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(TARGET tgt PROPERTY AUTOUIC_OPTIONS "--no-protection")
+ # ...
diff --git a/Help/prop_tgt/BUILD_RPATH.rst b/Help/prop_tgt/BUILD_RPATH.rst
index 27393f5d7..13c9c1de8 100644
--- a/Help/prop_tgt/BUILD_RPATH.rst
+++ b/Help/prop_tgt/BUILD_RPATH.rst
@@ -1,7 +1,7 @@
BUILD_RPATH
-----------
-A :ref:`;-list <CMake Language Lists>` specifying runtime path (``RPATH``)
+A :ref:`semicolon-separated list <CMake Language Lists>` specifying runtime path (``RPATH``)
entries to add to binaries linked in the build tree (for platforms that
support it). The entries will *not* be used for binaries in the install
tree. See also the :prop_tgt:`INSTALL_RPATH` target property.
diff --git a/Help/prop_tgt/BUNDLE.rst b/Help/prop_tgt/BUNDLE.rst
index 075f017df..c556ac32c 100644
--- a/Help/prop_tgt/BUNDLE.rst
+++ b/Help/prop_tgt/BUNDLE.rst
@@ -1,7 +1,7 @@
BUNDLE
------
-This target is a ``CFBundle`` on the OS X.
+This target is a ``CFBundle`` on the macOS.
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
diff --git a/Help/prop_tgt/BUNDLE_EXTENSION.rst b/Help/prop_tgt/BUNDLE_EXTENSION.rst
index 6b3d58023..70de11c40 100644
--- a/Help/prop_tgt/BUNDLE_EXTENSION.rst
+++ b/Help/prop_tgt/BUNDLE_EXTENSION.rst
@@ -2,7 +2,7 @@ BUNDLE_EXTENSION
----------------
The file extension used to name a :prop_tgt:`BUNDLE`, a :prop_tgt:`FRAMEWORK`,
-or a :prop_tgt:`MACOSX_BUNDLE` target on the OS X and iOS.
+or a :prop_tgt:`MACOSX_BUNDLE` target on the macOS and iOS.
The default value is ``bundle``, ``framework``, or ``app`` for the respective
target types.
diff --git a/Help/prop_tgt/COMPILE_FLAGS.rst b/Help/prop_tgt/COMPILE_FLAGS.rst
index 1a5389e48..8fe651b4a 100644
--- a/Help/prop_tgt/COMPILE_FLAGS.rst
+++ b/Help/prop_tgt/COMPILE_FLAGS.rst
@@ -8,4 +8,4 @@ build sources within the target. Use :prop_tgt:`COMPILE_DEFINITIONS`
to pass additional preprocessor definitions.
This property is deprecated. Use the :prop_tgt:`COMPILE_OPTIONS`
-property or the command:`target_compile_options` command instead.
+property or the :command:`target_compile_options` command instead.
diff --git a/Help/prop_tgt/COMPILE_OPTIONS.rst b/Help/prop_tgt/COMPILE_OPTIONS.rst
index 892ac23e1..0cd683610 100644
--- a/Help/prop_tgt/COMPILE_OPTIONS.rst
+++ b/Help/prop_tgt/COMPILE_OPTIONS.rst
@@ -3,7 +3,7 @@ COMPILE_OPTIONS
List of options to pass to the compiler.
-This property holds a :ref:`;-list <CMake Language Lists>` of options
+This property holds a :ref:`semicolon-separated list <CMake Language Lists>` of options
specified so far for its target. Use the :command:`target_compile_options`
command to append more options.
diff --git a/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
index 52ef013da..f261756f1 100644
--- a/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
+++ b/Help/prop_tgt/COMPILE_PDB_OUTPUT_DIRECTORY_CONFIG.rst
@@ -6,7 +6,7 @@ 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
+but multi-configuration generators (Visual Studio, 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
diff --git a/Help/prop_tgt/CROSSCOMPILING_EMULATOR.rst b/Help/prop_tgt/CROSSCOMPILING_EMULATOR.rst
index a0811bcaa..87c5978bc 100644
--- a/Help/prop_tgt/CROSSCOMPILING_EMULATOR.rst
+++ b/Help/prop_tgt/CROSSCOMPILING_EMULATOR.rst
@@ -6,6 +6,10 @@ This command will be added as a prefix to :command:`add_test`,
:command:`add_custom_command`, and :command:`add_custom_target` commands
for built target system executables.
+If this property contains a :ref:`semicolon-separated list <CMake Language
+Lists>`, then the first value is the command and remaining values are its
+arguments.
+
This property is initialized by the value of the
:variable:`CMAKE_CROSSCOMPILING_EMULATOR` variable if it is set when a target
is created.
diff --git a/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst b/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst
index 127d79fb3..ef74ae26f 100644
--- a/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst
+++ b/Help/prop_tgt/CUDA_RESOLVE_DEVICE_SYMBOLS.rst
@@ -1,12 +1,18 @@
CUDA_RESOLVE_DEVICE_SYMBOLS
---------------------------
-CUDA only: Enables device linking for the specific static library target
+CUDA only: Enables device linking for the specific library target
-If set this will enable device linking on this static library target. Normally
+If set this will enable device linking on the library target. Normally
device linking is deferred until a shared library or executable is generated,
allowing for multiple static libraries to resolve device symbols at the same
-time.
+time when they are used by a shared library or executable.
+
+By default static library targets have this property is disabled,
+while shared, module, and executable targets have this property enabled.
+
+Note that device linking is not supported for :ref:`Object Libraries`.
+
For instance:
diff --git a/Help/prop_tgt/CUDA_SEPARABLE_COMPILATION.rst b/Help/prop_tgt/CUDA_SEPARABLE_COMPILATION.rst
index 1c7dd8083..d306d7f82 100644
--- a/Help/prop_tgt/CUDA_SEPARABLE_COMPILATION.rst
+++ b/Help/prop_tgt/CUDA_SEPARABLE_COMPILATION.rst
@@ -11,3 +11,7 @@ For instance:
.. code-block:: cmake
set_property(TARGET myexe PROPERTY CUDA_SEPARABLE_COMPILATION ON)
+
+This property is initialized by the value of the
+:variable:`CMAKE_CUDA_SEPARABLE_COMPILATION` variable if it is set when a
+target is created.
diff --git a/Help/prop_tgt/CUDA_STANDARD.rst b/Help/prop_tgt/CUDA_STANDARD.rst
index b26281471..a3a2f5689 100644
--- a/Help/prop_tgt/CUDA_STANDARD.rst
+++ b/Help/prop_tgt/CUDA_STANDARD.rst
@@ -7,7 +7,7 @@ This property specifies the CUDA/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``, ``11``.
+Supported values are ``98``, ``11``, ``14``.
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
diff --git a/Help/prop_tgt/CXX_STANDARD.rst b/Help/prop_tgt/CXX_STANDARD.rst
index 30a612db6..ccc014790 100644
--- a/Help/prop_tgt/CXX_STANDARD.rst
+++ b/Help/prop_tgt/CXX_STANDARD.rst
@@ -6,9 +6,10 @@ 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. For compilers that
-have no notion of a standard level, such as MSVC, this has no effect.
+have no notion of a standard level, such as Microsoft Visual C++ before
+2015 Update 3, this has no effect.
-Supported values are ``98``, ``11``, ``14``, and ``17``.
+Supported values are ``98``, ``11``, ``14``, ``17``, and ``20``.
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
diff --git a/Help/prop_tgt/C_STANDARD.rst b/Help/prop_tgt/C_STANDARD.rst
index 815a68676..e7f7904f2 100644
--- a/Help/prop_tgt/C_STANDARD.rst
+++ b/Help/prop_tgt/C_STANDARD.rst
@@ -6,7 +6,8 @@ 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. For compilers that
-have no notion of a standard level, such as MSVC, this has no effect.
+have no notion of a standard level, such as Microsoft Visual C++ before
+2015 Update 3, this has no effect.
Supported values are ``90``, ``99`` and ``11``.
diff --git a/Help/prop_tgt/DEBUG_POSTFIX.rst b/Help/prop_tgt/DEBUG_POSTFIX.rst
index 1487656d9..04e312e37 100644
--- a/Help/prop_tgt/DEBUG_POSTFIX.rst
+++ b/Help/prop_tgt/DEBUG_POSTFIX.rst
@@ -1,7 +1,7 @@
DEBUG_POSTFIX
-------------
-See target property <CONFIG>_POSTFIX.
+See target property ``<CONFIG>_POSTFIX``.
-This property is a special case of the more-general <CONFIG>_POSTFIX
-property for the DEBUG configuration.
+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
index f47f135ea..eb7f93735 100644
--- a/Help/prop_tgt/DEFINE_SYMBOL.rst
+++ b/Help/prop_tgt/DEFINE_SYMBOL.rst
@@ -3,9 +3,9 @@ DEFINE_SYMBOL
Define a symbol when compiling this target's sources.
-DEFINE_SYMBOL sets the name of the preprocessor symbol defined when
+``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
+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/DEPLOYMENT_REMOTE_DIRECTORY.rst b/Help/prop_tgt/DEPLOYMENT_REMOTE_DIRECTORY.rst
index 1ff5bf01e..368768ae7 100644
--- a/Help/prop_tgt/DEPLOYMENT_REMOTE_DIRECTORY.rst
+++ b/Help/prop_tgt/DEPLOYMENT_REMOTE_DIRECTORY.rst
@@ -3,8 +3,8 @@ DEPLOYMENT_REMOTE_DIRECTORY
Set the WinCE project ``RemoteDirectory`` in ``DeploymentTool`` and
``RemoteExecutable`` in ``DebuggerTool`` in ``.vcproj`` files generated
-by the :generator:`Visual Studio 9 2008` and :generator:`Visual Studio 8 2005`
-generators. This is useful when you want to debug on remote WinCE device.
+by the :generator:`Visual Studio 9 2008` generator.
+This is useful when you want to debug on remote WinCE device.
For example:
.. code-block:: cmake
diff --git a/Help/prop_tgt/ENABLE_EXPORTS.rst b/Help/prop_tgt/ENABLE_EXPORTS.rst
index 9e2230971..581c2b90c 100644
--- a/Help/prop_tgt/ENABLE_EXPORTS.rst
+++ b/Help/prop_tgt/ENABLE_EXPORTS.rst
@@ -12,7 +12,7 @@ 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 OS X, the
+require all symbols to be resolved at link time, such as macOS, 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
diff --git a/Help/prop_tgt/EXCLUDE_FROM_ALL.rst b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst
index caa5741f8..3aa296d3b 100644
--- a/Help/prop_tgt/EXCLUDE_FROM_ALL.rst
+++ b/Help/prop_tgt/EXCLUDE_FROM_ALL.rst
@@ -1,10 +1,21 @@
EXCLUDE_FROM_ALL
----------------
-Exclude the target from the all target.
+Set this target property to a true (or false) value to exclude (or include)
+the target from the "all" target of the containing directory and its
+ancestors. If excluded, running e.g. ``make`` in the containing directory
+or its ancestors will not build the target by default.
-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.
+If this target property is not set then the target will be included in
+the "all" target of the containing directory. Furthermore, it will be
+included in the "all" target of its ancestor directories unless the
+:prop_dir:`EXCLUDE_FROM_ALL` directory property is set.
+
+With ``EXCLUDE_FROM_ALL`` set to false or not set at all, the target
+will be brought up to date as part of doing a ``make install`` or its
+equivalent for the CMake generator being used. If a target has
+``EXCLUDE_FROM_ALL`` set to true, then any attempt to install that
+target has undefined behavior. Note that such a target can still safely
+be listed in an :command:`install(TARGETS)` command as long as the install
+components the target belongs to are not part of the set of components
+that anything tries to install.
diff --git a/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst b/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst
index a14e48c19..664704bfa 100644
--- a/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst
+++ b/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD.rst
@@ -1,8 +1,8 @@
EXCLUDE_FROM_DEFAULT_BUILD
--------------------------
-Exclude target from "Build Solution".
+Exclude target from ``Build Solution``.
This property is only used by Visual Studio generators.
-When set to TRUE, the target will not be built when you press "Build
-Solution".
+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
index 655a9dee0..ad1021aa4 100644
--- a/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG.rst
+++ b/Help/prop_tgt/EXCLUDE_FROM_DEFAULT_BUILD_CONFIG.rst
@@ -1,9 +1,10 @@
EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>
-----------------------------------
-Per-configuration version of target exclusion from "Build Solution".
+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
+:prop_tgt:`EXCLUDE_FROM_DEFAULT_BUILD`. If the generic
+:prop_tgt:`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
index 1b4247cc5..0e021d0db 100644
--- a/Help/prop_tgt/EXPORT_NAME.rst
+++ b/Help/prop_tgt/EXPORT_NAME.rst
@@ -3,6 +3,6 @@ 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.
+This sets the name for the ``IMPORTED`` target generated by the
+:command:`install(EXPORT)` and :command:`export` commands.
+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
index 32ae2aa8f..352d06258 100644
--- a/Help/prop_tgt/EchoString.rst
+++ b/Help/prop_tgt/EchoString.rst
@@ -3,5 +3,5 @@ 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.
+A message to display on some generators (such as :ref:`Makefile Generators`)
+when the target is built.
diff --git a/Help/prop_tgt/FOLDER.rst b/Help/prop_tgt/FOLDER.rst
index bfe4e8e16..f6be9e673 100644
--- a/Help/prop_tgt/FOLDER.rst
+++ b/Help/prop_tgt/FOLDER.rst
@@ -3,8 +3,11 @@ 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
+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
+folders, use ``FOLDER`` values such as 'GUI/Dialogs' with '/' characters
separating folder levels.
+
+This property is initialized by the value of the variable
+:variable:`CMAKE_FOLDER` if it is set when a target is created.
diff --git a/Help/prop_tgt/FRAMEWORK.rst b/Help/prop_tgt/FRAMEWORK.rst
index 495d30e95..3dff1be3c 100644
--- a/Help/prop_tgt/FRAMEWORK.rst
+++ b/Help/prop_tgt/FRAMEWORK.rst
@@ -1,17 +1,19 @@
FRAMEWORK
---------
-Build ``SHARED`` or ``STATIC`` library as Framework Bundle on the OS X and iOS.
+Build ``SHARED`` or ``STATIC`` library as Framework Bundle on the macOS and iOS.
If such a library target has this property set to ``TRUE`` it will be
-built as a framework when built on the OS X and iOS. It will have the
+built as a framework when built on the macOS and iOS. It will have the
directory structure required for a framework and will be suitable to
-be used with the ``-framework`` option
+be used with the ``-framework`` option. This property is initialized by the
+value of the :variable:`CMAKE_FRAMEWORK` variable if it is set when a target is
+created.
To customize ``Info.plist`` file in the framework, use
:prop_tgt:`MACOSX_FRAMEWORK_INFO_PLIST` target property.
-For OS X see also the :prop_tgt:`FRAMEWORK_VERSION` target property.
+For macOS see also the :prop_tgt:`FRAMEWORK_VERSION` target property.
Example of creation ``dynamicFramework``:
diff --git a/Help/prop_tgt/FRAMEWORK_VERSION.rst b/Help/prop_tgt/FRAMEWORK_VERSION.rst
index 6aa30268a..c2ae7b98f 100644
--- a/Help/prop_tgt/FRAMEWORK_VERSION.rst
+++ b/Help/prop_tgt/FRAMEWORK_VERSION.rst
@@ -4,5 +4,5 @@ FRAMEWORK_VERSION
Version of a framework created using the :prop_tgt:`FRAMEWORK` target
property (e.g. ``A``).
-This property only affects OS X, as iOS doesn't have versioned
+This property only affects macOS, as iOS doesn't have versioned
directory structure.
diff --git a/Help/prop_tgt/Fortran_FORMAT.rst b/Help/prop_tgt/Fortran_FORMAT.rst
index 0a11d91ca..8704e5f42 100644
--- a/Help/prop_tgt/Fortran_FORMAT.rst
+++ b/Help/prop_tgt/Fortran_FORMAT.rst
@@ -1,11 +1,11 @@
Fortran_FORMAT
--------------
-Set to FIXED or FREE to indicate the Fortran source layout.
+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
+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
+variable :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
index 9c8643764..e061863b3 100644
--- a/Help/prop_tgt/Fortran_MODULE_DIRECTORY.rst
+++ b/Help/prop_tgt/Fortran_MODULE_DIRECTORY.rst
@@ -8,10 +8,10 @@ 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
+: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.
+:prop_tgt:`INCLUDE_DIRECTORIES` regardless of this property.
diff --git a/Help/prop_tgt/GENERATOR_FILE_NAME.rst b/Help/prop_tgt/GENERATOR_FILE_NAME.rst
index 032b22acf..a48610550 100644
--- a/Help/prop_tgt/GENERATOR_FILE_NAME.rst
+++ b/Help/prop_tgt/GENERATOR_FILE_NAME.rst
@@ -6,4 +6,4 @@ 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().
+:command:`include_external_msproject`.
diff --git a/Help/prop_tgt/GNUtoMS.rst b/Help/prop_tgt/GNUtoMS.rst
index cf34da9c3..a09ebbfae 100644
--- a/Help/prop_tgt/GNUtoMS.rst
+++ b/Help/prop_tgt/GNUtoMS.rst
@@ -1,17 +1,17 @@
GNUtoMS
-------
-Convert GNU import library (.dll.a) to MS format (.lib).
+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.
+the import library (``.dll.a``) from GNU to MS format (``.lib``). Both import
+libraries will be installed by :command:`install(TARGETS)` and exported by
+:command:`install(EXPORT)` and :command:`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
+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
+prior to the first command that enables a language such as :command:`project`
+or :command:`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
index 7790932ae..15199b15b 100644
--- a/Help/prop_tgt/HAS_CXX.rst
+++ b/Help/prop_tgt/HAS_CXX.rst
@@ -3,5 +3,5 @@ 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.
+This is equivalent to setting the :prop_tgt:`LINKER_LANGUAGE`
+property to ``CXX``.
diff --git a/Help/prop_tgt/IMPORTED.rst b/Help/prop_tgt/IMPORTED.rst
index 605c1ce6c..22d28aaf7 100644
--- a/Help/prop_tgt/IMPORTED.rst
+++ b/Help/prop_tgt/IMPORTED.rst
@@ -1,8 +1,8 @@
IMPORTED
--------
-Read-only indication of whether a target is 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`.
+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_IMPLIB.rst b/Help/prop_tgt/IMPORTED_IMPLIB.rst
index acf4b321f..77fb552ea 100644
--- a/Help/prop_tgt/IMPORTED_IMPLIB.rst
+++ b/Help/prop_tgt/IMPORTED_IMPLIB.rst
@@ -1,7 +1,7 @@
IMPORTED_IMPLIB
---------------
-Full path to the import library for an IMPORTED target.
+Full path to the import library for an ``IMPORTED`` target.
-Set this to the location of the ".lib" part of a windows DLL. Ignored
+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
index b4b3f0228..5debabc95 100644
--- a/Help/prop_tgt/IMPORTED_IMPLIB_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_IMPLIB_CONFIG.rst
@@ -1,7 +1,7 @@
IMPORTED_IMPLIB_<CONFIG>
------------------------
-<CONFIG>-specific version of IMPORTED_IMPLIB property.
+<CONFIG>-specific version of :prop_tgt:`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
index 2db2b0e58..f7e216581 100644
--- a/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES.rst
@@ -8,7 +8,7 @@ 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
+interface libraries in the :prop_tgt:`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
index ee243c75d..5b9c51308 100644
--- a/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_DEPENDENT_LIBRARIES_CONFIG.rst
@@ -1,7 +1,7 @@
IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>
------------------------------------------
-<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.
+<CONFIG>-specific version of :prop_tgt:`IMPORTED_LINK_DEPENDENT_LIBRARIES`.
Configuration names correspond to those provided by the project from
which the target is imported. If set, this property completely
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst
index 5ca9c8b6f..4ed4281f3 100644
--- a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES.rst
@@ -1,14 +1,14 @@
IMPORTED_LINK_INTERFACE_LANGUAGES
---------------------------------
-Languages compiled into an IMPORTED static library.
+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
+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 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
index d4a10fbdd..40fcf7fcf 100644
--- a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LANGUAGES_CONFIG.rst
@@ -1,7 +1,7 @@
IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>
------------------------------------------
-<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.
+<CONFIG>-specific version of :prop_tgt:`IMPORTED_LINK_INTERFACE_LANGUAGES`.
Configuration names correspond to those provided by the project from
which the target is imported. If set, this property completely
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst
index 61134a401..527cf2ebe 100644
--- a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.rst
@@ -1,16 +1,16 @@
IMPORTED_LINK_INTERFACE_LIBRARIES
---------------------------------
-Transitive link interface of an IMPORTED target.
+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
+``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
+:prop_tgt:`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.
+:prop_tgt:`INTERFACE_LINK_LIBRARIES` property.
-This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.
+This property is deprecated. Use :prop_tgt:`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
index 13b93ba98..050fb1dff 100644
--- a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES_CONFIG.rst
@@ -1,13 +1,13 @@
IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>
------------------------------------------
-<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.
+<CONFIG>-specific version of :prop_tgt:`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.
+:prop_tgt:`INTERFACE_LINK_LIBRARIES` property.
-This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead.
+This property is deprecated. Use :prop_tgt:`INTERFACE_LINK_LIBRARIES` instead.
diff --git a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst
index 3a86b9985..7a92d96b6 100644
--- a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY.rst
@@ -1,6 +1,6 @@
IMPORTED_LINK_INTERFACE_MULTIPLICITY
------------------------------------
-Repetition count for cycles of IMPORTED static libraries.
+Repetition count for cycles of ``IMPORTED`` static libraries.
-This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.
+This is :prop_tgt:`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
index 33b9b8419..758237bf1 100644
--- a/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
@@ -1,7 +1,7 @@
IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>
---------------------------------------------
-<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.
+<CONFIG>-specific version of :prop_tgt:`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
index 8cfef7343..a9123cdd9 100644
--- a/Help/prop_tgt/IMPORTED_LOCATION.rst
+++ b/Help/prop_tgt/IMPORTED_LOCATION.rst
@@ -1,21 +1,28 @@
IMPORTED_LOCATION
-----------------
-Full path to the main file on disk for an IMPORTED target.
+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
+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
+on macOS 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
+For ``SHARED`` libraries on non-DLL platforms this is the location of the
+shared library. For frameworks on macOS 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
+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.
+The ``IMPORTED_LOCATION`` target property may be overridden for a
+given configuration ``<CONFIG>`` by the configuration-specific
+:prop_tgt:`IMPORTED_LOCATION_<CONFIG>` target property. Furthermore,
+the :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` target property may be
+used to map between a project's configurations and those of an imported
+target. If none of these is set then the name of any other configuration
+listed in the :prop_tgt:`IMPORTED_CONFIGURATIONS` target property may be
+selected and its :prop_tgt:`IMPORTED_LOCATION_<CONFIG>` value used.
+
+To get the location of an imported target read one of the :prop_tgt:`LOCATION`
+or ``LOCATION_<CONFIG>`` properties.
diff --git a/Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst b/Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst
index f85bb19c9..c5f5f048c 100644
--- a/Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_LOCATION_CONFIG.rst
@@ -1,7 +1,7 @@
IMPORTED_LOCATION_<CONFIG>
--------------------------
-<CONFIG>-specific version of IMPORTED_LOCATION property.
+<CONFIG>-specific version of :prop_tgt:`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
index 4a1bb447a..cbb764226 100644
--- a/Help/prop_tgt/IMPORTED_NO_SONAME.rst
+++ b/Help/prop_tgt/IMPORTED_NO_SONAME.rst
@@ -1,9 +1,9 @@
IMPORTED_NO_SONAME
------------------
-Specifies that an IMPORTED shared library target has 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
+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.
+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
index 22d68220c..76fe471f4 100644
--- a/Help/prop_tgt/IMPORTED_NO_SONAME_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_NO_SONAME_CONFIG.rst
@@ -1,7 +1,7 @@
IMPORTED_NO_SONAME_<CONFIG>
---------------------------
-<CONFIG>-specific version of IMPORTED_NO_SONAME property.
+<CONFIG>-specific version of :prop_tgt:`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_OBJECTS.rst b/Help/prop_tgt/IMPORTED_OBJECTS.rst
index 222e6cc02..50a329fb3 100644
--- a/Help/prop_tgt/IMPORTED_OBJECTS.rst
+++ b/Help/prop_tgt/IMPORTED_OBJECTS.rst
@@ -1,7 +1,7 @@
IMPORTED_OBJECTS
----------------
-:ref:`;-list <CMake Language Lists>` of absolute paths to the object
+A :ref:`semicolon-separated list <CMake Language Lists>` of absolute paths to the object
files on disk for an :ref:`imported <Imported targets>`
:ref:`object library <object libraries>`.
diff --git a/Help/prop_tgt/IMPORTED_SONAME.rst b/Help/prop_tgt/IMPORTED_SONAME.rst
index d80907e3e..bf0c3cbc1 100644
--- a/Help/prop_tgt/IMPORTED_SONAME.rst
+++ b/Help/prop_tgt/IMPORTED_SONAME.rst
@@ -1,8 +1,8 @@
IMPORTED_SONAME
---------------
-The "soname" of an IMPORTED target of shared library type.
+The ``soname`` of an ``IMPORTED`` target of shared library type.
-Set this to the "soname" embedded in an imported shared library. This
+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
index 6ec9af3f8..59a9d1a45 100644
--- a/Help/prop_tgt/IMPORTED_SONAME_CONFIG.rst
+++ b/Help/prop_tgt/IMPORTED_SONAME_CONFIG.rst
@@ -1,7 +1,7 @@
IMPORTED_SONAME_<CONFIG>
------------------------
-<CONFIG>-specific version of IMPORTED_SONAME property.
+<CONFIG>-specific version of :prop_tgt:`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
index deede9788..17e381be4 100644
--- a/Help/prop_tgt/IMPORT_PREFIX.rst
+++ b/Help/prop_tgt/IMPORT_PREFIX.rst
@@ -3,7 +3,7 @@ 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")
+Similar to the target property :prop_tgt:`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
index bd0125037..9307115b4 100644
--- a/Help/prop_tgt/IMPORT_SUFFIX.rst
+++ b/Help/prop_tgt/IMPORT_SUFFIX.rst
@@ -3,7 +3,7 @@ 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.
+Similar to the target property :prop_tgt:`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
index 8b40d9c34..b381d1dbd 100644
--- a/Help/prop_tgt/INCLUDE_DIRECTORIES.rst
+++ b/Help/prop_tgt/INCLUDE_DIRECTORIES.rst
@@ -18,7 +18,7 @@ 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
+Contents of ``INCLUDE_DIRECTORIES`` may use :manual:`cmake-generator-expressions(7)` 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
index a67ec1584..2216072ac 100644
--- a/Help/prop_tgt/INSTALL_NAME_DIR.rst
+++ b/Help/prop_tgt/INSTALL_NAME_DIR.rst
@@ -1,8 +1,12 @@
INSTALL_NAME_DIR
----------------
-Mac OSX directory name for installed targets.
+macOS 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
+``INSTALL_NAME_DIR`` is a string specifying the directory portion of the
+"install_name" field of shared libraries on macOS to use in the
installed targets.
+
+This property is initialized by the value of the variable
+:variable:`CMAKE_INSTALL_NAME_DIR` if it is set when a target is
+created.
diff --git a/Help/prop_tgt/INSTALL_RPATH.rst b/Help/prop_tgt/INSTALL_RPATH.rst
index 6206b6889..6403f4c67 100644
--- a/Help/prop_tgt/INSTALL_RPATH.rst
+++ b/Help/prop_tgt/INSTALL_RPATH.rst
@@ -5,5 +5,5 @@ 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.
+by the value of the variable :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
index f0006f85b..d8be9548a 100644
--- a/Help/prop_tgt/INSTALL_RPATH_USE_LINK_PATH.rst
+++ b/Help/prop_tgt/INSTALL_RPATH_USE_LINK_PATH.rst
@@ -3,8 +3,8 @@ 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
+``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
+to the :prop_tgt:`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_LINK_LIBRARIES.rst b/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst
index 832d12bbc..bf7f72f4c 100644
--- a/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst
+++ b/Help/prop_tgt/INTERFACE_LINK_LIBRARIES.rst
@@ -17,6 +17,8 @@ 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:: LINK_LIBRARIES_INDIRECTION.txt
+
Creating Relocatable Packages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst b/Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst
index ea700dfe9..4336d7182 100644
--- a/Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst
+++ b/Help/prop_tgt/INTERFACE_POSITION_INDEPENDENT_CODE.rst
@@ -14,3 +14,9 @@ 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.
+
+Contents of ``INTERFACE_POSITION_INDEPENDENT_CODE`` 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
index 3f68c3128..d3a5e9414 100644
--- a/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.rst
+++ b/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION.rst
@@ -4,7 +4,9 @@ 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.
+known :module:`to be supported <CheckIPOSupported>` by the compiler. Depending
+on value of policy :policy:`CMP0069`, the error will be reported or ignored,
+if interprocedural optimization is enabled but not supported.
This property is initialized by the
:variable:`CMAKE_INTERPROCEDURAL_OPTIMIZATION` variable if it is set when a
diff --git a/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst b/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
index 782b0f0a6..79d46048b 100644
--- a/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
+++ b/Help/prop_tgt/INTERPROCEDURAL_OPTIMIZATION_CONFIG.rst
@@ -3,7 +3,7 @@ INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
Per-configuration interprocedural optimization for a target.
-This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION.
+This is a per-configuration version of :prop_tgt:`INTERPROCEDURAL_OPTIMIZATION`.
If set, this property overrides the generic property for the named
configuration.
diff --git a/Help/prop_tgt/LANG_CLANG_TIDY.rst b/Help/prop_tgt/LANG_CLANG_TIDY.rst
index 2887e235d..2bfef6673 100644
--- a/Help/prop_tgt/LANG_CLANG_TIDY.rst
+++ b/Help/prop_tgt/LANG_CLANG_TIDY.rst
@@ -3,7 +3,7 @@
This property is implemented only when ``<LANG>`` is ``C`` or ``CXX``.
-Specify a :ref:`;-list <CMake Language Lists>` containing a command
+Specify a :ref:`semicolon-separated list <CMake Language Lists>` containing a command
line for the ``clang-tidy`` tool. The :ref:`Makefile Generators`
and the :generator:`Ninja` generator will run this tool along with the
compiler and report a warning if the tool reports any problems.
diff --git a/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst b/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst
index 0fe0b31e5..23af503af 100644
--- a/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst
+++ b/Help/prop_tgt/LANG_COMPILER_LAUNCHER.rst
@@ -1,9 +1,10 @@
<LANG>_COMPILER_LAUNCHER
------------------------
-This property is implemented only when ``<LANG>`` is ``C`` or ``CXX``.
+This property is implemented only when ``<LANG>`` is ``C``, ``CXX``,
+``Fortran``, or ``CUDA``.
-Specify a :ref:`;-list <CMake Language Lists>` containing a command line
+Specify a :ref:`semicolon-separated list <CMake Language Lists>` containing a command line
for a compiler launching tool. The :ref:`Makefile Generators` and the
:generator:`Ninja` generator will run this tool and pass the compiler and
its arguments to the tool. Some example tools are distcc and ccache.
diff --git a/Help/prop_tgt/LANG_CPPLINT.rst b/Help/prop_tgt/LANG_CPPLINT.rst
index 14f47d465..9944c88ba 100644
--- a/Help/prop_tgt/LANG_CPPLINT.rst
+++ b/Help/prop_tgt/LANG_CPPLINT.rst
@@ -3,7 +3,7 @@
This property is supported only when ``<LANG>`` is ``C`` or ``CXX``.
-Specify a :ref:`;-list <CMake Language Lists>` containing a command line
+Specify a :ref:`semicolon-separated list <CMake Language Lists>` containing a command line
for the ``cpplint`` style checker. The :ref:`Makefile Generators` and the
:generator:`Ninja` generator will run ``cpplint`` along with the compiler
and report any problems.
diff --git a/Help/prop_tgt/LANG_INCLUDE_WHAT_YOU_USE.rst b/Help/prop_tgt/LANG_INCLUDE_WHAT_YOU_USE.rst
index 26f6d1671..35220e414 100644
--- a/Help/prop_tgt/LANG_INCLUDE_WHAT_YOU_USE.rst
+++ b/Help/prop_tgt/LANG_INCLUDE_WHAT_YOU_USE.rst
@@ -3,7 +3,7 @@
This property is implemented only when ``<LANG>`` is ``C`` or ``CXX``.
-Specify a :ref:`;-list <CMake Language Lists>` containing a command
+Specify a :ref:`semicolon-separated list <CMake Language Lists>` containing a command
line for the ``include-what-you-use`` tool. The :ref:`Makefile Generators`
and the :generator:`Ninja` generator will run this tool along with the
compiler and report a warning if the tool reports any problems.
diff --git a/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst
index 28dd404df..5cefc38bb 100644
--- a/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst
+++ b/Help/prop_tgt/LIBRARY_OUTPUT_DIRECTORY_CONFIG.rst
@@ -6,7 +6,8 @@ Per-configuration output directory for
This is a per-configuration version of the
:prop_tgt:`LIBRARY_OUTPUT_DIRECTORY` target property, but
-multi-configuration generators (VS, Xcode) do NOT append a
+multi-configuration generators (:ref:`Visual Studio Generators`,
+:generator:`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>` variable if
diff --git a/Help/prop_tgt/LINKER_LANGUAGE.rst b/Help/prop_tgt/LINKER_LANGUAGE.rst
index b1ca86710..b0a572b5c 100644
--- a/Help/prop_tgt/LINKER_LANGUAGE.rst
+++ b/Help/prop_tgt/LINKER_LANGUAGE.rst
@@ -8,7 +8,7 @@ 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.
+documentation of :variable:`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
index 5576b85fa..e59d4c014 100644
--- a/Help/prop_tgt/LINK_DEPENDS.rst
+++ b/Help/prop_tgt/LINK_DEPENDS.rst
@@ -7,6 +7,12 @@ 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
+This property is supported only by :generator:`Ninja` and
+:ref:`Makefile Generators`. It is
+intended to specify dependencies on "linker scripts" for custom Makefile link
rules.
+
+Contents of ``LINK_DEPENDS`` 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_FLAGS.rst b/Help/prop_tgt/LINK_FLAGS.rst
index 409d00a29..92cd3c0a5 100644
--- a/Help/prop_tgt/LINK_FLAGS.rst
+++ b/Help/prop_tgt/LINK_FLAGS.rst
@@ -1,8 +1,16 @@
LINK_FLAGS
----------
-Additional flags to use when linking this target.
+Additional flags to use when linking this target if it is a shared library,
+module library, or an executable. Static libraries need to use
+:prop_tgt:`STATIC_LIBRARY_OPTIONS` or :prop_tgt:`STATIC_LIBRARY_FLAGS`
+properties.
-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.
+The ``LINK_FLAGS`` property, managed as a string, can be used to add extra
+flags to the link step of a target. :prop_tgt:`LINK_FLAGS_<CONFIG>` will add
+to the configuration ``<CONFIG>``, for example, ``DEBUG``, ``RELEASE``,
+``MINSIZEREL``, ``RELWITHDEBINFO``, ...
+
+.. note::
+
+ This property has been superseded by :prop_tgt:`LINK_OPTIONS` property.
diff --git a/Help/prop_tgt/LINK_FLAGS_CONFIG.rst b/Help/prop_tgt/LINK_FLAGS_CONFIG.rst
index ba7adc84f..68c312932 100644
--- a/Help/prop_tgt/LINK_FLAGS_CONFIG.rst
+++ b/Help/prop_tgt/LINK_FLAGS_CONFIG.rst
@@ -1,6 +1,11 @@
LINK_FLAGS_<CONFIG>
-------------------
-Per-configuration linker flags for a target.
+Per-configuration linker flags for a ``SHARED`` library, ``MODULE`` or
+``EXECUTABLE`` target.
-This is the configuration-specific version of LINK_FLAGS.
+This is the configuration-specific version of :prop_tgt:`LINK_FLAGS`.
+
+.. note::
+
+ This property has been superseded by :prop_tgt:`LINK_OPTIONS` property.
diff --git a/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst
index 4e26388a9..b798af954 100644
--- a/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst
+++ b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY.rst
@@ -1,9 +1,9 @@
LINK_INTERFACE_MULTIPLICITY
---------------------------
-Repetition count for STATIC libraries with cyclic dependencies.
+Repetition count for ``STATIC`` libraries with cyclic dependencies.
-When linking to a STATIC library target with cyclic dependencies the
+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
diff --git a/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
index 5ea4a45cf..7c9461fde 100644
--- a/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
+++ b/Help/prop_tgt/LINK_INTERFACE_MULTIPLICITY_CONFIG.rst
@@ -1,8 +1,8 @@
LINK_INTERFACE_MULTIPLICITY_<CONFIG>
------------------------------------
-Per-configuration repetition count for cycles of STATIC libraries.
+Per-configuration repetition count for cycles of ``STATIC`` libraries.
This is the configuration-specific version of
-LINK_INTERFACE_MULTIPLICITY. If set, this property completely
+:prop_tgt:`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
index aa4b9f55f..d88e79881 100644
--- a/Help/prop_tgt/LINK_LIBRARIES.rst
+++ b/Help/prop_tgt/LINK_LIBRARIES.rst
@@ -15,3 +15,5 @@ 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.
+
+.. include:: LINK_LIBRARIES_INDIRECTION.txt
diff --git a/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst b/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
index cf9c87147..fecbb1480 100644
--- a/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
+++ b/Help/prop_tgt/LINK_SEARCH_END_STATIC.rst
@@ -3,16 +3,17 @@ 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.
+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.
+search type to ``-Bstatic`` regardless of how it started.
This property is initialized by the value of the variable
-CMAKE_LINK_SEARCH_END_STATIC if it is set when a target is created.
+:variable:`CMAKE_LINK_SEARCH_END_STATIC` if it is set
+when a target is created.
-See also LINK_SEARCH_START_STATIC.
+See also :prop_tgt:`LINK_SEARCH_START_STATIC`.
diff --git a/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst b/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
index 2e0f9bd33..83cf231c5 100644
--- a/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
+++ b/Help/prop_tgt/LINK_SEARCH_START_STATIC.rst
@@ -3,17 +3,18 @@ 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.
+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
+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).
This property is initialized by the value of the variable
-CMAKE_LINK_SEARCH_START_STATIC if it is set when a target is created.
+ :variable:`CMAKE_LINK_SEARCH_START_STATIC` if it is set
+ when a target is created.
-See also LINK_SEARCH_END_STATIC.
+See also :prop_tgt:`LINK_SEARCH_END_STATIC`.
diff --git a/Help/prop_tgt/LOCATION.rst b/Help/prop_tgt/LOCATION.rst
index 16d5696e5..d058064d6 100644
--- a/Help/prop_tgt/LOCATION.rst
+++ b/Help/prop_tgt/LOCATION.rst
@@ -4,24 +4,25 @@ 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.
+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
+executable target's output file for use in :command:`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.
+``$(ConfigurationName)`` in VS). In CMake 2.6 and above
+:command:`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 :command:`add_custom_command` recognizes
+:manual:`generator expressions <cmake-generator-expressions(7)>`
+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>)?",
+``(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
index ac6bdb786..67de8ed21 100644
--- a/Help/prop_tgt/LOCATION_CONFIG.rst
+++ b/Help/prop_tgt/LOCATION_CONFIG.rst
@@ -4,17 +4,17 @@ 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
+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.
+:prop_tgt:`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.
+``(RUNTIME|LIBRARY|ARCHIVE)_OUTPUT_(NAME|DIRECTORY)(_<CONFIG>)?``,
+``(IMPLIB_)?(PREFIX|SUFFIX)``, or :prop_tgt:`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
index 7cd80462a..92bce53ee 100644
--- a/Help/prop_tgt/MACOSX_BUNDLE.rst
+++ b/Help/prop_tgt/MACOSX_BUNDLE.rst
@@ -1,12 +1,12 @@
MACOSX_BUNDLE
-------------
-Build an executable as an Application Bundle on OS X or iOS.
+Build an executable as an Application Bundle on macOS or iOS.
-When this property is set to ``TRUE`` the executable when built on OS X
+When this property is set to ``TRUE`` the executable when built on macOS
or iOS will be created as an application bundle. This makes it
a GUI executable that can be launched from the Finder. See the
-:prop_tgt:`MACOSX_FRAMEWORK_INFO_PLIST` target property for information about
+:prop_tgt:`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
:variable:`CMAKE_MACOSX_BUNDLE` if it is set when a target is created.
diff --git a/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
index 8515accc2..443a645e4 100644
--- a/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
+++ b/Help/prop_tgt/MACOSX_BUNDLE_INFO_PLIST.rst
@@ -1,10 +1,10 @@
MACOSX_BUNDLE_INFO_PLIST
------------------------
-Specify a custom ``Info.plist`` template for a OS X and iOS Application Bundle.
+Specify a custom ``Info.plist`` template for a macOS and iOS Application Bundle.
An executable target with :prop_tgt:`MACOSX_BUNDLE` enabled will be built as an
-application bundle on OS X. By default its ``Info.plist`` file is created
+application bundle on macOS. By default its ``Info.plist`` file is created
by configuring a template called ``MacOSXBundleInfo.plist.in`` located in the
:variable:`CMAKE_MODULE_PATH`. This property specifies an alternative template
file name which may be a full path.
diff --git a/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
index 58f31d495..82fdcc0fb 100644
--- a/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
+++ b/Help/prop_tgt/MACOSX_FRAMEWORK_INFO_PLIST.rst
@@ -1,10 +1,10 @@
MACOSX_FRAMEWORK_INFO_PLIST
---------------------------
-Specify a custom ``Info.plist`` template for a OS X and iOS Framework.
+Specify a custom ``Info.plist`` template for a macOS and iOS Framework.
A library target with :prop_tgt:`FRAMEWORK` enabled will be built as a
-framework on OS X. By default its ``Info.plist`` file is created by
+framework on macOS. By default its ``Info.plist`` file is created by
configuring a template called ``MacOSXFrameworkInfo.plist.in`` located in the
:variable:`CMAKE_MODULE_PATH`. This property specifies an alternative template
file name which may be a full path.
diff --git a/Help/prop_tgt/MACOSX_RPATH.rst b/Help/prop_tgt/MACOSX_RPATH.rst
index 1f9a036bf..acd5a7aa4 100644
--- a/Help/prop_tgt/MACOSX_RPATH.rst
+++ b/Help/prop_tgt/MACOSX_RPATH.rst
@@ -1,7 +1,7 @@
MACOSX_RPATH
------------
-Whether this target on OS X or iOS is located at runtime using rpaths.
+Whether this target on macOS or iOS is located at runtime using rpaths.
When this property is set to ``TRUE``, the directory portion of
the ``install_name`` field of this shared library will be ``@rpath``
diff --git a/Help/prop_tgt/NO_SONAME.rst b/Help/prop_tgt/NO_SONAME.rst
index ee45ed849..d381a9c3b 100644
--- a/Help/prop_tgt/NO_SONAME.rst
+++ b/Help/prop_tgt/NO_SONAME.rst
@@ -1,10 +1,10 @@
NO_SONAME
---------
-Whether to set "soname" when linking a shared library.
+Whether to set ``soname`` when linking a shared library.
-Enable this boolean property if a generated shared library
-should not have "soname" set. Default is to set "soname" on all
+Enable this boolean property if a generated ``SHARED`` library
+should not have ``soname`` set. Default is to set ``soname`` on all
shared libraries 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
diff --git a/Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst b/Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst
index 070dd3018..880343de4 100644
--- a/Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst
+++ b/Help/prop_tgt/NO_SYSTEM_FROM_IMPORTED.rst
@@ -1,11 +1,15 @@
NO_SYSTEM_FROM_IMPORTED
-----------------------
-Do not treat includes from IMPORTED target interfaces as SYSTEM.
+Do not treat include directories from the interfaces of consumed
+:ref:`imported targets` 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.
+The contents of the :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property
+of imported targets are treated as ``SYSTEM`` includes by default. If this
+property is enabled on a target, compilation of sources in that target will
+not treat the contents of the ``INTERFACE_INCLUDE_DIRECTORIES`` of consumed
+imported targets as system includes.
+
+This property is initialized by the value of the
+:variable:`CMAKE_NO_SYSTEM_FROM_IMPORTED` variable 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
index cefe03f5b..996a4be72 100644
--- a/Help/prop_tgt/OSX_ARCHITECTURES.rst
+++ b/Help/prop_tgt/OSX_ARCHITECTURES.rst
@@ -1,10 +1,10 @@
OSX_ARCHITECTURES
-----------------
-Target specific architectures for OS X.
+Target specific architectures for macOS.
The ``OSX_ARCHITECTURES`` property sets the target binary architecture for
-targets on OS X (``-arch``). This property is initialized by the value of the
+targets on macOS (``-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
diff --git a/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
index fb78177fb..06da4fb09 100644
--- a/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
+++ b/Help/prop_tgt/OSX_ARCHITECTURES_CONFIG.rst
@@ -1,7 +1,7 @@
OSX_ARCHITECTURES_<CONFIG>
--------------------------
-Per-configuration OS X and iOS binary architectures for a target.
+Per-configuration macOS and iOS binary architectures for a target.
This property is the configuration-specific version of
:prop_tgt:`OSX_ARCHITECTURES`.
diff --git a/Help/prop_tgt/OUTPUT_NAME.rst b/Help/prop_tgt/OUTPUT_NAME.rst
index f1bdb7c88..4b33b38e0 100644
--- a/Help/prop_tgt/OUTPUT_NAME.rst
+++ b/Help/prop_tgt/OUTPUT_NAME.rst
@@ -5,7 +5,8 @@ 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.
+default during generation. The value is not set by default during
+configuration.
Contents of ``OUTPUT_NAME`` and the variants listed below may use
:manual:`generator expressions <cmake-generator-expressions(7)>`.
diff --git a/Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst
index 730cf5776..2f667f364 100644
--- a/Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst
+++ b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY.rst
@@ -5,8 +5,14 @@ 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
+will be placed by the linker. The property value may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
+Multi-configuration generators append a per-configuration
+subdirectory to the specified directory unless a generator expression
+is used.
+
+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`
diff --git a/Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst
index 6037fa0c7..6c550831f 100644
--- a/Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst
+++ b/Help/prop_tgt/PDB_OUTPUT_DIRECTORY_CONFIG.rst
@@ -5,11 +5,15 @@ 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
+but multi-configuration generators (:ref:`Visual Studio Generators`,
+:generator:`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.
+Contents of ``PDB_OUTPUT_DIRECTORY_<CONFIG>`` may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
+
.. |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
index 54af8c6de..0aaf66bd0 100644
--- a/Help/prop_tgt/POSITION_INDEPENDENT_CODE.rst
+++ b/Help/prop_tgt/POSITION_INDEPENDENT_CODE.rst
@@ -9,3 +9,8 @@ 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.
+
+.. note::
+
+ For executable targets, the link step is controlled by the :policy:`CMP0083`
+ policy and the :module:`CheckPIESupported` module.
diff --git a/Help/prop_tgt/POST_INSTALL_SCRIPT.rst b/Help/prop_tgt/POST_INSTALL_SCRIPT.rst
index f1adb40b7..23935bcdf 100644
--- a/Help/prop_tgt/POST_INSTALL_SCRIPT.rst
+++ b/Help/prop_tgt/POST_INSTALL_SCRIPT.rst
@@ -3,7 +3,7 @@ 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.
+The :prop_tgt:`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 :command:`install` command instead.
diff --git a/Help/prop_tgt/PREFIX.rst b/Help/prop_tgt/PREFIX.rst
index a16510461..a40129268 100644
--- a/Help/prop_tgt/PREFIX.rst
+++ b/Help/prop_tgt/PREFIX.rst
@@ -4,4 +4,4 @@ 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.
+``lib``) on a library name.
diff --git a/Help/prop_tgt/PRE_INSTALL_SCRIPT.rst b/Help/prop_tgt/PRE_INSTALL_SCRIPT.rst
index 113d7c56a..43432f4d8 100644
--- a/Help/prop_tgt/PRE_INSTALL_SCRIPT.rst
+++ b/Help/prop_tgt/PRE_INSTALL_SCRIPT.rst
@@ -3,7 +3,7 @@ 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.
+The ``PRE_INSTALL_SCRIPT`` and :prop_tgt:`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 :command:`install` command instead.
diff --git a/Help/prop_tgt/PRIVATE_HEADER.rst b/Help/prop_tgt/PRIVATE_HEADER.rst
index c4412ed25..23e1f8e6f 100644
--- a/Help/prop_tgt/PRIVATE_HEADER.rst
+++ b/Help/prop_tgt/PRIVATE_HEADER.rst
@@ -4,8 +4,8 @@ PRIVATE_HEADER
Specify private header files in a :prop_tgt:`FRAMEWORK` shared library target.
Shared library targets marked with the :prop_tgt:`FRAMEWORK` property generate
-frameworks on OS X, iOS and normal shared libraries on other platforms.
+frameworks on macOS, iOS and normal shared libraries on other platforms.
This property may be set to a list of header files to be placed in the
PrivateHeaders directory inside the framework folder. On non-Apple
platforms these headers may be installed using the ``PRIVATE_HEADER``
-option to the ``install(TARGETS)`` command.
+option to the :command:`install(TARGETS)` command.
diff --git a/Help/prop_tgt/PUBLIC_HEADER.rst b/Help/prop_tgt/PUBLIC_HEADER.rst
index d4a636caf..915e39cd2 100644
--- a/Help/prop_tgt/PUBLIC_HEADER.rst
+++ b/Help/prop_tgt/PUBLIC_HEADER.rst
@@ -4,8 +4,8 @@ PUBLIC_HEADER
Specify public header files in a :prop_tgt:`FRAMEWORK` shared library target.
Shared library targets marked with the :prop_tgt:`FRAMEWORK` property generate
-frameworks on OS X, iOS and normal shared libraries on other platforms.
+frameworks on macOS, iOS and normal shared libraries on other platforms.
This property may be set to a list of header files to be placed in the
``Headers`` directory inside the framework folder. On non-Apple platforms
these headers may be installed using the ``PUBLIC_HEADER`` option to the
-``install(TARGETS)`` command.
+:command:`install(TARGETS)` command.
diff --git a/Help/prop_tgt/RESOURCE.rst b/Help/prop_tgt/RESOURCE.rst
index d837f7b33..e5a1cb677 100644
--- a/Help/prop_tgt/RESOURCE.rst
+++ b/Help/prop_tgt/RESOURCE.rst
@@ -4,12 +4,12 @@ RESOURCE
Specify resource files in a :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE`.
Target marked with the :prop_tgt:`FRAMEWORK` or :prop_tgt:`BUNDLE` property
-generate framework or application bundle (both OS X and iOS is supported)
+generate framework or application bundle (both macOS and iOS is supported)
or normal shared libraries on other platforms.
This property may be set to a list of files to be placed in the corresponding
-directory (eg. ``Resources`` directory for OS X) inside the bundle.
+directory (eg. ``Resources`` directory for macOS) inside the bundle.
On non-Apple platforms these files may be installed using the ``RESOURCE``
-option to the ``install(TARGETS)`` command.
+option to the :command:`install(TARGETS)` command.
Following example of Application Bundle:
@@ -18,21 +18,18 @@ Following example of Application Bundle:
add_executable(ExecutableTarget
addDemo.c
resourcefile.txt
- appresourcedir/appres.txt
- )
+ appresourcedir/appres.txt)
target_link_libraries(ExecutableTarget heymath mul)
set(RESOURCE_FILES
resourcefile.txt
- appresourcedir/appres.txt
- )
+ appresourcedir/appres.txt)
set_target_properties(ExecutableTarget PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget
- RESOURCE "${RESOURCE_FILES}"
- )
+ RESOURCE "${RESOURCE_FILES}")
will produce flat structure for iOS systems::
@@ -42,7 +39,7 @@ will produce flat structure for iOS systems::
Info.plist
resourcefile.txt
-For OS X systems it will produce following directory structure::
+For macOS systems it will produce following directory structure::
ExecutableTarget.app/
Contents
@@ -53,7 +50,7 @@ For OS X systems it will produce following directory structure::
appres.txt
resourcefile.txt
-For Linux, such cmake script produce following files::
+For Linux, such CMake script produce following files::
ExecutableTarget
Resources
diff --git a/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst b/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst
index 94fb2776a..67277548e 100644
--- a/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst
+++ b/Help/prop_tgt/RUNTIME_OUTPUT_DIRECTORY_CONFIG.rst
@@ -6,7 +6,8 @@ Per-configuration output directory for
This is a per-configuration version of the
:prop_tgt:`RUNTIME_OUTPUT_DIRECTORY` target property, but
-multi-configuration generators (VS, Xcode) do NOT append a
+multi-configuration generators (:ref:`Visual Studio Generators`,
+:generator:`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>` variable if
diff --git a/Help/prop_tgt/SKIP_BUILD_RPATH.rst b/Help/prop_tgt/SKIP_BUILD_RPATH.rst
index a91fa9ca3..7086b1bc4 100644
--- a/Help/prop_tgt/SKIP_BUILD_RPATH.rst
+++ b/Help/prop_tgt/SKIP_BUILD_RPATH.rst
@@ -3,7 +3,7 @@ SKIP_BUILD_RPATH
Should rpaths be used for the build tree.
-SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic
+``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.
+:variable:`CMAKE_SKIP_BUILD_RPATH` if it is set when a target is created.
diff --git a/Help/prop_tgt/SOVERSION.rst b/Help/prop_tgt/SOVERSION.rst
index 82b6b976a..b07c17cfe 100644
--- a/Help/prop_tgt/SOVERSION.rst
+++ b/Help/prop_tgt/SOVERSION.rst
@@ -20,7 +20,7 @@ These numbers are used as the image version of the binary.
Mach-O Versions
^^^^^^^^^^^^^^^
-For shared libraries and executables on Mach-O systems (e.g. OS X, iOS),
+For shared libraries and executables on Mach-O systems (e.g. macOS, iOS),
the ``SOVERSION`` property corresponds to *compatibility version* and
:prop_tgt:`VERSION` to *current version*. See the :prop_tgt:`FRAMEWORK` target
property for an example. Versions of Mach-O binaries may be checked with the
diff --git a/Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst b/Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst
index d3b2cd478..66e0e8b96 100644
--- a/Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst
+++ b/Help/prop_tgt/STATIC_LIBRARY_FLAGS.rst
@@ -1,6 +1,17 @@
STATIC_LIBRARY_FLAGS
--------------------
-Extra flags to use when linking static libraries.
+Archiver (or MSVC librarian) flags for a static library target.
+Targets that are shared libraries, modules, or executables need to use
+the :prop_tgt:`LINK_OPTIONS` or :prop_tgt:`LINK_FLAGS` target properties.
-Extra flags to use when linking a static library.
+The ``STATIC_LIBRARY_FLAGS`` property, managed as a string, can be used to add
+extra flags to the link step of a static library target.
+:prop_tgt:`STATIC_LIBRARY_FLAGS_<CONFIG>` will add to the configuration
+``<CONFIG>``, for example, ``DEBUG``, ``RELEASE``, ``MINSIZEREL``,
+``RELWITHDEBINFO``, ...
+
+.. note::
+
+ This property has been superseded by :prop_tgt:`STATIC_LIBRARY_OPTIONS`
+ property.
diff --git a/Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst b/Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst
index cca353ddc..5b97941da 100644
--- a/Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst
+++ b/Help/prop_tgt/STATIC_LIBRARY_FLAGS_CONFIG.rst
@@ -1,6 +1,12 @@
STATIC_LIBRARY_FLAGS_<CONFIG>
-----------------------------
-Per-configuration flags for creating a static library.
+Per-configuration archiver (or MSVC librarian) flags for a static library
+target.
-This is the configuration-specific version of STATIC_LIBRARY_FLAGS.
+This is the configuration-specific version of :prop_tgt:`STATIC_LIBRARY_FLAGS`.
+
+.. note::
+
+ This property has been superseded by :prop_tgt:`STATIC_LIBRARY_OPTIONS`
+ property.
diff --git a/Help/prop_tgt/SUFFIX.rst b/Help/prop_tgt/SUFFIX.rst
index 70844be5c..32ec42910 100644
--- a/Help/prop_tgt/SUFFIX.rst
+++ b/Help/prop_tgt/SUFFIX.rst
@@ -4,4 +4,4 @@ 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.
+``.so`` or ``.exe``) on the name of a library, module or executable.
diff --git a/Help/prop_tgt/TYPE.rst b/Help/prop_tgt/TYPE.rst
index 5ac63cc37..3136d119d 100644
--- a/Help/prop_tgt/TYPE.rst
+++ b/Help/prop_tgt/TYPE.rst
@@ -4,6 +4,6 @@ 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, INTERFACE_LIBRARY, EXECUTABLE or one of the internal
-target types.
+target. It will be one of ``STATIC_LIBRARY``, ``MODULE_LIBRARY``,
+``SHARED_LIBRARY``, ``OBJECT_LIBRARY``, ``INTERFACE_LIBRARY``, ``EXECUTABLE``
+or one of the internal target types.
diff --git a/Help/prop_tgt/VERSION.rst b/Help/prop_tgt/VERSION.rst
index 66e7bde71..ff3b3030f 100644
--- a/Help/prop_tgt/VERSION.rst
+++ b/Help/prop_tgt/VERSION.rst
@@ -22,7 +22,7 @@ These numbers are used as the image version of the binary.
Mach-O Versions
^^^^^^^^^^^^^^^
-For shared libraries and executables on Mach-O systems (e.g. OS X, iOS),
+For shared libraries and executables on Mach-O systems (e.g. macOS, iOS),
the :prop_tgt:`SOVERSION` property correspond to *compatibility version* and
``VERSION`` to *current version*. See the :prop_tgt:`FRAMEWORK` target
property for an example. Versions of Mach-O binaries may be checked with the
diff --git a/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst b/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst
index 0af85cbdc..008bbf6e6 100644
--- a/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst
+++ b/Help/prop_tgt/VS_DEBUGGER_WORKING_DIRECTORY.rst
@@ -2,5 +2,10 @@ VS_DEBUGGER_WORKING_DIRECTORY
-----------------------------
Sets the local debugger working directory for Visual Studio C++ targets.
+The property value may use
+:manual:`generator expressions <cmake-generator-expressions(7)>`.
This is defined in ``<LocalDebuggerWorkingDirectory>`` in the Visual Studio
project file.
+
+This property only works for Visual Studio 2010 and above;
+it is ignored on other generators.
diff --git a/Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst b/Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst
index 829d696d5..9f5a313d3 100644
--- a/Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst
+++ b/Help/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION.rst
@@ -5,3 +5,6 @@ Specify the .NET target framework version.
Used to specify the .NET target framework version for C++/CLI. For
example, "v4.5".
+
+This property is deprecated and should not be used anymore. Use
+:prop_tgt:`DOTNET_TARGET_FRAMEWORK_VERSION` instead.
diff --git a/Help/prop_tgt/VS_SDK_REFERENCES.rst b/Help/prop_tgt/VS_SDK_REFERENCES.rst
index 769a0d1d5..99987f561 100644
--- a/Help/prop_tgt/VS_SDK_REFERENCES.rst
+++ b/Help/prop_tgt/VS_SDK_REFERENCES.rst
@@ -2,6 +2,6 @@ VS_SDK_REFERENCES
-----------------
Visual Studio project SDK references.
-Specify a :ref:`;-list <CMake Language Lists>` of SDK references
+Specify a :ref:`semicolon-separated list <CMake Language Lists>` of SDK references
to be added to a generated Visual Studio project, e.g.
``Microsoft.AdMediatorWindows81, Version=1.0``.
diff --git a/Help/prop_tgt/WIN32_EXECUTABLE.rst b/Help/prop_tgt/WIN32_EXECUTABLE.rst
index 336d5f7f3..060d16671 100644
--- a/Help/prop_tgt/WIN32_EXECUTABLE.rst
+++ b/Help/prop_tgt/WIN32_EXECUTABLE.rst
@@ -5,8 +5,9 @@ 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.
+main(). This makes it a GUI executable instead of a console application.
+See the :variable:`CMAKE_MFC_FLAG` variable documentation to
+configure use of the Microsoft Foundation Classes (MFC) for WinMain
+executables. This property is initialized by the value of the
+:variable:`CMAKE_WIN32_EXECUTABLE` variable 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
index 7e00ac430..71858c50e 100644
--- a/Help/prop_tgt/XCODE_ATTRIBUTE_an-attribute.rst
+++ b/Help/prop_tgt/XCODE_ATTRIBUTE_an-attribute.rst
@@ -3,8 +3,8 @@ 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.
+Tell the :generator:`Xcode` generator to set '<an-attribute>' to a given
+value in the generated Xcode project. Ignored on other generators.
See the :variable:`CMAKE_XCODE_ATTRIBUTE_<an-attribute>` variable
to set attributes on all targets in a directory tree.
diff --git a/Help/release/3.0.rst b/Help/release/3.0.rst
index d02f94093..64491e310 100644
--- a/Help/release/3.0.rst
+++ b/Help/release/3.0.rst
@@ -224,7 +224,7 @@ Modules
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
+ for libraries 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.
diff --git a/Help/release/3.1.rst b/Help/release/3.1.rst
index dca42cdcd..8bea28f70 100644
--- a/Help/release/3.1.rst
+++ b/Help/release/3.1.rst
@@ -289,16 +289,16 @@ CPack
-----
* :manual:`cpack(1)` gained an ``IFW`` generator to package using
- Qt Framework Installer tools. See the :module:`CPackIFW` module.
+ Qt Framework Installer tools. See the :cpack_gen:`CPack IFW Generator`.
* :manual:`cpack(1)` gained ``7Z`` and ``TXZ`` generators supporting
lzma-compressed archives.
-* The :module:`CPackDeb` module learned a new
+* The :cpack_gen:`CPack DEB Generator` learned a new
:variable:`CPACK_DEBIAN_COMPRESSION_TYPE` variable to set the
tarball compression type.
-* The :manual:`cpack(1)` ``WiX`` generator learned to support
+* The :cpack_gen:`CPack WIX Generator` learned to support
a :prop_inst:`CPACK_WIX_ACL` installed file property to
specify an Access Control List.
diff --git a/Help/release/3.2.rst b/Help/release/3.2.rst
index 8abb1ca62..992d44b65 100644
--- a/Help/release/3.2.rst
+++ b/Help/release/3.2.rst
@@ -156,27 +156,27 @@ CTest
CPack
-----
-* The :module:`CPackRPM` module learned options to set per-component
+* The :cpack_gen:`CPack RPM Generator` learned options to set per-component
descriptions and summaries. See the
:variable:`CPACK_RPM_<component>_PACKAGE_DESCRIPTION` and
:variable:`CPACK_RPM_<component>_PACKAGE_SUMMARY` variables.
-* The :module:`CPackRPM` module learned options to specify
+* The :cpack_gen:`CPack RPM Generator` learned options to specify
requirements for pre- and post-install scripts. See the
:variable:`CPACK_RPM_PACKAGE_REQUIRES_PRE` and
:variable:`CPACK_RPM_PACKAGE_REQUIRES_POST` variables.
-* The :module:`CPackRPM` module learned options to specify
+* The :cpack_gen:`CPack RPM Generator` learned options to specify
requirements for pre- and post-uninstall scripts. See the
:variable:`CPACK_RPM_PACKAGE_REQUIRES_PREUN` and
:variable:`CPACK_RPM_PACKAGE_REQUIRES_POSTUN` variables.
-* The :module:`CPackRPM` module learned a new
+* The :cpack_gen:`CPack RPM Generator` learned a new
:variable:`CPACK_RPM_<COMPONENT>_PACKAGE_PREFIX` variable to
specify a component-specific value to use instead of
:variable:`CPACK_PACKAGING_INSTALL_PREFIX`.
-* The :module:`CPackRPM` module learned a new
+* The :cpack_gen:`CPack RPM Generator` learned a new
:variable:`CPACK_RPM_RELOCATION_PATHS` variable to
specify multiple relocation prefixes for a single rpm package.
diff --git a/Help/release/3.3.rst b/Help/release/3.3.rst
index 0beb354ac..6657e8df1 100644
--- a/Help/release/3.3.rst
+++ b/Help/release/3.3.rst
@@ -169,26 +169,26 @@ CTest
CPack
-----
-* The :manual:`cpack(1)` ``IFW`` generator and the :module:`CPackIFW`
- module learned to support Qt Framework Installer 2.0 tools.
+* The :cpack_gen:`CPack IFW Generator` learned to support
+ Qt Framework Installer 2.0 tools.
-* The :module:`CPackDeb` module learned a new
+* The :cpack_gen:`CPack DEB Generator` learned a new
:variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_SHLIBDEPS`
variable to specify per-component use of ``dpkg-shlibdeps``.
-* The :module:`CPackDeb` module learned a new
+* The :cpack_gen:`CPack DEB Generator` learned a new
:variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_DEPENDS`
option to specify per-component dependencies.
-* The :module:`CPackRPM` module learned to package symbolic links
+* The :cpack_gen:`CPack RPM Generator` learned to package symbolic links
more cleanly and now supports directory symlinks with recent
``rpmbuild`` versions.
-* The :module:`CPackRPM` module learned a new
+* The :cpack_gen:`CPack RPM Generator` learned a new
:variable:`CPACK_RPM_ADDITIONAL_MAN_DIRS` variable to specify
directories containing man pages for the brp-compress RPM macro.
-* The :module:`CPackRPM` module learned a new
+* The :cpack_gen:`CPack RPM Generator` learned a new
:variable:`CPACK_RPM_<component>_PACKAGE_ARCHITECTURE` variable
to specify a component-specific package architecture.
diff --git a/Help/release/3.4.rst b/Help/release/3.4.rst
index 89c5561d3..943d26716 100644
--- a/Help/release/3.4.rst
+++ b/Help/release/3.4.rst
@@ -66,7 +66,7 @@ Variables
Properties
----------
-* :ref:`Visual Studio Generators` learned to support additonal
+* :ref:`Visual Studio Generators` learned to support additional
target properties to customize projects for NVIDIA Nsight
Tegra Visual Studio Edition:
@@ -197,7 +197,7 @@ CTest
CPack
-----
-* The :module:`CPackDeb` module learned to set package dependencies
+* The :cpack_gen:`CPack DEB Generator` learned to set package dependencies
per component. See variables:
* :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_BREAKS`
@@ -249,11 +249,11 @@ Other Changes
:module:`CheckSymbolExists`, and :module:`FindThreads` modules learned to
work in environments where only CXX is enabled.
-* The :module:`CPackDeb` module now correctly excludes symlinks during package
- checksum calculation.
+* The :cpack_gen:`CPack DEB Generator` now correctly excludes symlinks
+ during package checksum calculation.
-* The :module:`CPackDeb` no longer uses fakeroot and system tar program for
- packaging.
+* The :cpack_gen:`CPack DEB Generator` no longer uses fakeroot and
+ system tar program for packaging.
* The :module:`CPack` module no longer mangles settings with CMake-special
characters when they're used as defaults for other settings. The macro
diff --git a/Help/release/3.5.rst b/Help/release/3.5.rst
index 009eb3c7c..58a5d4eef 100644
--- a/Help/release/3.5.rst
+++ b/Help/release/3.5.rst
@@ -120,31 +120,33 @@ Platforms
CPack
-----
-* The :module:`CPackDMG` module learned new variable to specify AppleScript
- file run to customize appearance of ``DragNDrop`` installer folder,
- including background image setting using supplied PNG or multi-resolution
- TIFF file. See the :variable:`CPACK_DMG_DS_STORE_SETUP_SCRIPT` and
+* The :cpack_gen:`CPack DragNDrop Generator` learned new variable to
+ specify AppleScript file run to customize appearance of ``DragNDrop``
+ installer folder, including background image setting using supplied
+ PNG or multi-resolution TIFF file.
+ See the :variable:`CPACK_DMG_DS_STORE_SETUP_SCRIPT` and
:variable:`CPACK_DMG_BACKGROUND_IMAGE` variables.
-* The :module:`CPackDeb` module learned to set the optional config
+* The :cpack_gen:`CPack DEB Generator` learned to set the optional config
file ``Source`` field using a monolithic or per-component variable.
See :variable:`CPACK_DEBIAN_PACKAGE_SOURCE`.
-* The :module:`CPackDeb` module learned to set Package, Section
+* The :cpack_gen:`CPack DEB Generator` learned to set Package, Section
and Priority control fields per-component.
See variables :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_SECTION` and
:variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_PRIORITY`.
-* The :module:`CPack DragNDrop generator <CPackDMG>` learned to add
+* The :cpack_gen:`CPack DragNDrop Generator` learned to add
multi-lingual SLAs to a DMG which is presented to the user when they try to
mount the DMG. See the :variable:`CPACK_DMG_SLA_LANGUAGES` and
:variable:`CPACK_DMG_SLA_DIR` variables for details.
-* The :module:`CPackNSIS` module learned new variables to add bitmaps to the
- installer. See the :variable:`CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP`
+* The :cpack_gen:`CPack NSIS Generator` learned new variables to
+ add bitmaps to the installer.
+ See the :variable:`CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP`
and :variable:`CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP` variables.
-* The :module:`CPackRPM` module learned to set Name and Group
+* The :cpack_gen:`CPack RPM Generator` learned to set Name and Group
control fields per-component.
See :variable:`CPACK_RPM_<component>_PACKAGE_NAME`
and :variable:`CPACK_RPM_<component>_PACKAGE_GROUP`.
diff --git a/Help/release/3.6.rst b/Help/release/3.6.rst
index 144537de0..f0add07ff 100644
--- a/Help/release/3.6.rst
+++ b/Help/release/3.6.rst
@@ -111,7 +111,7 @@ Modules
* The :module:`ExternalProject` module learned to initialize Git submodules
recursively and also to initialize new submodules on updates. Use the
- ``GIT_SUBMODULES`` option to restrict which submodules are initalized and
+ ``GIT_SUBMODULES`` option to restrict which submodules are initialized and
updated.
* The :module:`ExternalProject` module leared the ``DOWNLOAD_NO_EXTRACT 1``
@@ -165,25 +165,25 @@ CTest
CPack
-----
-* The :module:`CPackDeb` module learned how to handle ``$ORIGIN``
+* The :cpack_gen:`CPack DEB Generator` learned how to handle ``$ORIGIN``
in ``CMAKE_INSTALL_RPATH`` when :variable:`CPACK_DEBIAN_PACKAGE_SHLIBDEPS`
is used for dependency auto detection.
-* The :module:`CPackDeb` module learned how to generate ``DEBIAN/shlibs``
- contorl file when package contains shared libraries.
+* The :cpack_gen:`CPack DEB Generator` learned how to generate
+ ``DEBIAN/shlibs`` contorl file when package contains shared libraries.
-* The :module:`CPackDeb` module learned how to generate ``DEBIAN/postinst`` and
- ``DEBIAN/postrm`` files if the package installs libraries in
- ldconfig-controlled locations (e.g. ``/lib/``, ``/usr/lib/``).
+* The :cpack_gen:`CPack DEB Generator` learned how to generate
+ ``DEBIAN/postinst`` and ``DEBIAN/postrm`` files if the package installs
+ libraries in ldconfig-controlled locations (e.g. ``/lib/``, ``/usr/lib/``).
-* The :module:`CPackDeb` module learned how to generate dependencies between
- Debian packages if multi-component setup is used and
+* The :cpack_gen:`CPack DEB Generator` learned how to generate dependencies
+ between Debian packages if multi-component setup is used and
:variable:`CPACK_COMPONENT_<compName>_DEPENDS` variables are set.
For backward compatibility this feature is disabled by default.
See :variable:`CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS`.
-* The :module:`CPackDeb` module learned how to set custom package file names
- including how to generate properly-named Debian packages::
+* The :cpack_gen:`CPack DEB Generator` learned how to set custom package
+ file names including how to generate properly-named Debian packages::
<PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
@@ -191,42 +191,44 @@ CPack
:variable:`CPACK_DEBIAN_FILE_NAME` and
:variable:`CPACK_DEBIAN_<COMPONENT>_FILE_NAME`.
-* The :module:`CPackDeb` module learned how to set the package release number
- (``DebianRevisionNumber`` in package file name when used in combination with
- ``DEB-DEFAULT`` value set by :variable:`CPACK_DEBIAN_FILE_NAME`). See
- :variable:`CPACK_DEBIAN_PACKAGE_RELEASE`.
+* The :cpack_gen:`CPack DEB Generator` learned how to set the package
+ release number (``DebianRevisionNumber`` in package file name when
+ used in combination with ``DEB-DEFAULT`` value set by
+ :variable:`CPACK_DEBIAN_FILE_NAME`).
+ See :variable:`CPACK_DEBIAN_PACKAGE_RELEASE`.
-* The :module:`CPackDeb` module learned how to set the package architecture
- per-component. See :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_ARCHITECTURE`.
+* The :cpack_gen:`CPack DEB Generator` learned how to set the package
+ architecture per-component.
+ See :variable:`CPACK_DEBIAN_<COMPONENT>_PACKAGE_ARCHITECTURE`.
-* The :module:`CPackDMG` module learned a new option to tell the CPack
- ``DragNDrop`` generaor to skip the ``/Applications`` symlink.
+* The :cpack_gen:`CPack DragNDrop Generator` learned a new option to skip the
+ ``/Applications`` symlink.
See the :variable:`CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK` variable.
* The :module:`CPackIFW` module gained a new
:command:`cpack_ifw_update_repository` command to update a QtIFW-specific
repository from a remote repository.
-* The :module:`CPackRPM` module learned how to set RPM ``dist`` tag as part of
- RPM ``Release:`` tag when enabled (mandatory on some Linux distributions for
- e.g. on Fedora).
+* The :cpack_gen:`CPack RPM Generator` learned how to set RPM ``dist`` tag
+ as part of RPM ``Release:`` tag when enabled (mandatory on some Linux
+ distributions for e.g. on Fedora).
See :variable:`CPACK_RPM_PACKAGE_RELEASE_DIST`.
-* The :module:`CPackRPM` module learned how to set default values for owning
- user/group and file/directory permissions of package content.
+* The :cpack_gen:`CPack RPM Generator` learned how to set default values
+ for owning user/group and file/directory permissions of package content.
See :variable:`CPACK_RPM_DEFAULT_USER`, :variable:`CPACK_RPM_DEFAULT_GROUP`,
:variable:`CPACK_RPM_DEFAULT_FILE_PERMISSIONS`,
:variable:`CPACK_RPM_DEFAULT_DIR_PERMISSIONS` and their per component
counterparts.
-* The :module:`CPackRPM` module learned how to set user defined package file
- names, how to specify that rpmbuild should decide on file name format as
- well as handling of multiple rpm packages generated by a single user defined
- spec file.
+* The :cpack_gen:`CPack RPM Generator` learned how to set user defined
+ package file names, how to specify that rpmbuild should decide on file
+ name format as well as handling of multiple rpm packages generated by a
+ single user defined spec file.
See :variable:`CPACK_RPM_PACKAGE_NAME` and
:variable:`CPACK_RPM_<component>_PACKAGE_NAME`.
-* The :module:`CPackRPM` module learned how to correctly handle symlinks
+* The :cpack_gen:`CPack RPM Generator` learned how to correctly handle symlinks
that are pointing outside generated packages.
Other
@@ -249,7 +251,7 @@ Deprecated and Removed Features
Users that keep some ``<prefix>/bin`` directories in the ``PATH`` just for
their tools do not necessarily want any supporting ``<prefix>/lib``
directories searched. One may set the ``CMAKE_PREFIX_PATH`` environment
- variable with a :ref:`;-list <CMake Language Lists>` of prefixes that are
+ variable with a :ref:`semicolon-separated list <CMake Language Lists>` of prefixes that are
to be searched.
* The :generator:`Visual Studio 7 .NET 2003` generator is now
@@ -296,7 +298,7 @@ Other Changes
Input variables of the old case will be honored if provided, and output
variables of the old case are always provided.
-* The :module:`CPackRPM` module now supports upper cased component
+* The :cpack_gen:`CPack RPM Generator` now supports upper cased component
names in per component CPackRPM specific variables.
E.g. component named ``foo`` now expects component specific
variable to be ``CPACK_RPM_FOO_PACKAGE_NAME`` while before
diff --git a/Help/release/3.7.rst b/Help/release/3.7.rst
index 4c51af43e..345c056df 100644
--- a/Help/release/3.7.rst
+++ b/Help/release/3.7.rst
@@ -221,13 +221,12 @@ CTest
CPack
-----
-* CPack gained a ``productbuild`` generator on OS X, configured by
- the :module:`CPackProductBuild` module.
+* CPack gained a :cpack_gen:`CPack productbuild Generator` on OS X.
* CPack gained a new :variable:`CPACK_PACKAGE_CHECKSUM` variable to
enable generation of a checksum file for each package file.
-* The :module:`CPackDeb` module learned to support long file names
+* The :cpack_gen:`CPack DEB Generator` learned to support long file names
when archive format is set to GNU tar.
See :variable:`CPACK_DEBIAN_ARCHIVE_TYPE`
@@ -237,35 +236,35 @@ CPack
* The :module:`CPackIFW` module :command:`cpack_ifw_configure_component` and
:command:`cpack_ifw_configure_component_group` commands gained a new
- ``USER_INTERFACES`` option to add a list of additonal pages to the IFW
+ ``USER_INTERFACES`` option to add a list of additional pages to the IFW
installer.
-* The :module:`CPackRPM` module learned to generate debuginfo
+* The :cpack_gen:`CPack RPM Generator` learned to generate debuginfo
packages on demand. See :variable:`CPACK_RPM_DEBUGINFO_PACKAGE`
and its per component version.
-* The :module:`CPackRPM` module learned to generate source rpm
+* The :cpack_gen:`CPack RPM Generator` learned to generate source rpm
(SRPM) packages on demand. See :variable:`CPACK_RPM_PACKAGE_SOURCES`,
:variable:`CPACK_RPM_SOURCE_PKG_BUILD_PARAMS` and
:variable:`CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX`.
-* The CPack NSIS generator now supports
+* The :cpack_gen:`CPack NSIS Generator` now supports
:variable:`CPACK_NSIS_<compName>_INSTALL_DIRECTORY`.
This can be used to set component specific installation directories.
-* The CPack WIX generator now supports
+* The :cpack_gen:`CPack WIX Generator` now supports
:variable:`CPACK_WIX_SKIP_PROGRAM_FOLDER` to allow specification
of a custom absolute installation prefix outside
of the ProgramFiles folders.
-* The CPack WIX generator now supports
+* The :cpack_gen:`CPack WIX Generator` now supports
:variable:`CPACK_COMPONENT_<compName>_DISABLED`.
This can be used to deselect a component from being installed by default.
-* The CPack WIX generator now supports :variable:`CPACK_WIX_PATCH_FILE`
- fragments for Feature elements.
+* The :cpack_gen:`CPack WIX Generator` now supports
+ :variable:`CPACK_WIX_PATCH_FILE` fragments for Feature elements.
-* The CPack WIX generator now supports
+* The :cpack_gen:`CPack WIX Generator` now supports
:variable:`CPACK_WIX_ROOT_FEATURE_TITLE` and
:variable:`CPACK_WIX_ROOT_FEATURE_DESCRIPTION` to allow the specification
of a custom title and description for the root feature element.
diff --git a/Help/release/3.8.rst b/Help/release/3.8.rst
index efb2aa5a7..de51a7bc3 100644
--- a/Help/release/3.8.rst
+++ b/Help/release/3.8.rst
@@ -307,7 +307,7 @@ CPack
option now is deprecated and will be removed in a future version of CMake.
Please use new ``SORTING_PRIORITY`` option instead.
-* The :module:`CPackIFW` module gained new
+* The :cpack_gen:`CPack IFW Generator` gained new
:variable:`CPACK_IFW_PACKAGE_WATERMARK`,
:variable:`CPACK_IFW_PACKAGE_BANNER`,
:variable:`CPACK_IFW_PACKAGE_BACKGROUND`,
@@ -317,26 +317,26 @@ CPack
:variable:`CPACK_IFW_PACKAGE_TITLE_COLOR`
variables to customize a QtIFW installer look.
-* The :module:`CPackProductBuild` module gained options to sign packages.
+* The :cpack_gen:`CPack productbuild Generator` gained options to sign packages.
See the variables :variable:`CPACK_PRODUCTBUILD_IDENTITY_NAME`,
:variable:`CPACK_PRODUCTBUILD_KEYCHAIN_PATH`,
:variable:`CPACK_PKGBUILD_IDENTITY_NAME`, and
:variable:`CPACK_PKGBUILD_KEYCHAIN_PATH`.
-* The :module:`CPackRPM` module learned to omit tags that are not supported by
- provided ``rpmbuild`` tool. If unsupported tags are set they are ignored
- and a developer warning is printed out.
+* The :cpack_gen:`CPack RPM Generator` learned to omit tags that are not
+ supported by provided ``rpmbuild`` tool. If unsupported tags are set they
+ are ignored and a developer warning is printed out.
-* The :module:`CPackRPM` module learned to generate main component package
- which forces generation of a rpm for defined component without component
- suffix in filename and package name.
+* The :cpack_gen:`CPack RPM Generator` learned to generate main component
+ package which forces generation of a rpm for defined component without
+ component suffix in filename and package name.
See :variable:`CPACK_RPM_MAIN_COMPONENT` variable.
-* The :module:`CPackRPM` module learned to generate a single ``debuginfo``
- package on demand even if components packaging is used.
+* The :cpack_gen:`CPack RPM Generator` learned to generate a single
+ ``debuginfo`` package on demand even if components packaging is used.
See :variable:`CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE` variable.
-* The :module:`CPackRPM` module learned to support
+* The :cpack_gen:`CPack RPM Generator` learned to support
multiple directives per file when using
:variable:`CPACK_RPM_USER_FILELIST` variable.
diff --git a/Help/release/3.9.rst b/Help/release/3.9.rst
index 897e268b5..89da62751 100644
--- a/Help/release/3.9.rst
+++ b/Help/release/3.9.rst
@@ -150,7 +150,7 @@ Modules
* The :module:`CMakeFindDependencyMacro` module ``find_dependency`` macro
now forwards all arguments to the underlying :command:`find_package`
call. Existing uses will continue to function as before, but callers can
- now access the full suite of arguments that ``find_package`` accepts.
+ now access the full suite of arguments that :command:`find_package` accepts.
* The :module:`FeatureSummary` module :command:`feature_summary` command now
accepts the new ``DEFAULT_DESCRIPTION`` option that will print the default
@@ -206,7 +206,7 @@ CTest
CPack
-----
-* The :module:`CPackArchive` module learned to modify the filename
+* The :cpack_gen:`CPack Archive Generator` learned to modify the filename
per-component. See the :variable:`CPACK_ARCHIVE_FILE_NAME` variable and
its per-component version :variable:`CPACK_ARCHIVE_<component>_FILE_NAME`.
@@ -220,23 +220,24 @@ CPack
internationalization support for ``DISPLAY_NAME`` and ``DESCRIPTION``
options.
-* The :module:`CPackIFW` module learned the new hint :variable:`CPACK_IFW_ROOT`
- variable for finding the QtIFW tool suite installed in a non-standard place.
+* The :cpack_gen:`CPack IFW Generator` learned the new hint
+ :variable:`CPACK_IFW_ROOT` variable for finding the QtIFW tool suite
+ installed in a non-standard place.
-* The :module:`CPackProductBuild` module gained a new
+* The :cpack_gen:`CPack productbuild Generator` gained a new
:variable:`CPACK_PRODUCTBUILD_RESOURCES_DIR` variable to
specify resources to be copied into the ``Resources``
directory.
-* The :module:`CPackRPM` module learned to modify the ``debuginfo`` package
- name. See the :variable:`CPACK_RPM_DEBUGINFO_FILE_NAME` variable.
+* The :cpack_gen:`CPack RPM Generator` learned to modify the ``debuginfo``
+ package name. See the :variable:`CPACK_RPM_DEBUGINFO_FILE_NAME` variable.
-* The :module:`CPackWIX` module patching system now has the ability to set
- additional attributes. This can be done by specifying attributes with
- the ``CPackWiXFragment`` XML tag after the ``Id`` attribute.
+* The :cpack_gen:`CPack WIX Generator` patching system now has the
+ ability to set additional attributes. This can be done by specifying
+ attributes with the ``CPackWiXFragment`` XML tag after the ``Id`` attribute.
See the :variable:`CPACK_WIX_PATCH_FILE` variable.
-* The CPack WIX generator implemented a new
+* The :cpack_gen:`CPack WIX Generator` implemented a new
:variable:`CPACK_WIX_ROOT_FOLDER_ID` variable which allows
using a custom root folder ID instead of the default
``ProgramFilesFolder`` / ``ProgramFiles64Folder``.
diff --git a/Help/release/index.rst b/Help/release/index.rst
index 6af282cff..35a47aa67 100644
--- a/Help/release/index.rst
+++ b/Help/release/index.rst
@@ -13,6 +13,12 @@ Releases
.. toctree::
:maxdepth: 1
+ 3.15 <3.15>
+ 3.14 <3.14>
+ 3.13 <3.13>
+ 3.12 <3.12>
+ 3.11 <3.11>
+ 3.10 <3.10>
3.9 <3.9>
3.8 <3.8>
3.7 <3.7>
diff --git a/Help/variable/APPLE.rst b/Help/variable/APPLE.rst
index 75eecf183..810d5fc3a 100644
--- a/Help/variable/APPLE.rst
+++ b/Help/variable/APPLE.rst
@@ -1,6 +1,5 @@
APPLE
-----
-``True`` if running on OS X.
-
-Set to ``true`` on OS X.
+Set to ``True`` when the target system is an Apple platform
+(macOS, iOS, tvOS or watchOS).
diff --git a/Help/variable/CMAKE_ANDROID_STL_TYPE.rst b/Help/variable/CMAKE_ANDROID_STL_TYPE.rst
index cfb76aa04..d174575c8 100644
--- a/Help/variable/CMAKE_ANDROID_STL_TYPE.rst
+++ b/Help/variable/CMAKE_ANDROID_STL_TYPE.rst
@@ -30,7 +30,8 @@ set to specify the STL variant to be used. The value may be one of:
``stlport_shared``
STLport Shared
-The default value is ``gnustl_static``. Note that this default differs from
+The default value is ``gnustl_static`` on NDK versions that provide it
+and otherwise ``c++_static``. Note that this default differs from
the native NDK build system because CMake may be used to build projects for
Android that are not natively implemented for it and use the C++ standard
library.
diff --git a/Help/variable/CMAKE_APPBUNDLE_PATH.rst b/Help/variable/CMAKE_APPBUNDLE_PATH.rst
index 2bc79ac3a..1c7ca51c2 100644
--- a/Help/variable/CMAKE_APPBUNDLE_PATH.rst
+++ b/Help/variable/CMAKE_APPBUNDLE_PATH.rst
@@ -1,6 +1,6 @@
CMAKE_APPBUNDLE_PATH
--------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
-for OS X application bundles used by the :command:`find_program`, and
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
+for macOS application bundles used by the :command:`find_program`, and
:command:`find_package` commands.
diff --git a/Help/variable/CMAKE_ARGC.rst b/Help/variable/CMAKE_ARGC.rst
index aec97119a..30db2a2da 100644
--- a/Help/variable/CMAKE_ARGC.rst
+++ b/Help/variable/CMAKE_ARGC.rst
@@ -3,6 +3,6 @@ CMAKE_ARGC
Number of command line arguments passed to CMake in script mode.
-When run in :ref:`-P <CMake Options>` script mode, CMake sets this variable to
-the number of command line arguments. See also :variable:`CMAKE_ARGV0`,
-``1``, ``2`` ...
+When run in :ref:`-P <Script Processing Mode>` script mode, CMake sets this
+variable to the number of command line arguments. See also
+:variable:`CMAKE_ARGV0`, ``1``, ``2`` ...
diff --git a/Help/variable/CMAKE_ARGV0.rst b/Help/variable/CMAKE_ARGV0.rst
index 8b1ecb79e..c4d1c219e 100644
--- a/Help/variable/CMAKE_ARGV0.rst
+++ b/Help/variable/CMAKE_ARGV0.rst
@@ -3,7 +3,7 @@ CMAKE_ARGV0
Command line argument passed to CMake in script mode.
-When run in :ref:`-P <CMake Options>` script mode, CMake sets this variable to
-the first command line argument. It then also sets ``CMAKE_ARGV1``,
+When run in :ref:`-P <Script Processing Mode>` 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 :variable:`CMAKE_ARGC`.
diff --git a/Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst b/Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst
index addc62de4..6c0c61b11 100644
--- a/Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst
+++ b/Help/variable/CMAKE_AUTOMOC_RELAXED_MODE.rst
@@ -1,6 +1,8 @@
CMAKE_AUTOMOC_RELAXED_MODE
--------------------------
+.. deprecated:: 3.15
+
Switch between strict and relaxed automoc mode.
By default, :prop_tgt:`AUTOMOC` behaves exactly as described in the
diff --git a/Help/variable/CMAKE_AUTORCC_OPTIONS.rst b/Help/variable/CMAKE_AUTORCC_OPTIONS.rst
index 298cb6be7..815d39d41 100644
--- a/Help/variable/CMAKE_AUTORCC_OPTIONS.rst
+++ b/Help/variable/CMAKE_AUTORCC_OPTIONS.rst
@@ -1,7 +1,16 @@
CMAKE_AUTORCC_OPTIONS
---------------------
-Whether to handle ``rcc`` automatically for Qt targets.
+Additional options for ``rcc`` when using :variable:`CMAKE_AUTORCC`.
This variable is used to initialize the :prop_tgt:`AUTORCC_OPTIONS` property on
all the targets. See that target property for additional information.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set(CMAKE_AUTORCC_OPTIONS "--compress;9")
+ # ...
diff --git a/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst b/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst
index 3c9b8c4f5..28fa92f16 100644
--- a/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst
+++ b/Help/variable/CMAKE_AUTOUIC_OPTIONS.rst
@@ -1,7 +1,16 @@
CMAKE_AUTOUIC_OPTIONS
---------------------
-Whether to handle ``uic`` automatically for Qt targets.
+Additional options for ``uic`` when using :variable:`CMAKE_AUTOUIC`.
This variable is used to initialize the :prop_tgt:`AUTOUIC_OPTIONS` property on
all the targets. See that target property for additional information.
+
+EXAMPLE
+^^^^^^^
+
+.. code-block:: cmake
+
+ # ...
+ set_property(CMAKE_AUTOUIC_OPTIONS "--no-protection")
+ # ...
diff --git a/Help/variable/CMAKE_BUILD_RPATH.rst b/Help/variable/CMAKE_BUILD_RPATH.rst
index f20eb418f..f5d53b88c 100644
--- a/Help/variable/CMAKE_BUILD_RPATH.rst
+++ b/Help/variable/CMAKE_BUILD_RPATH.rst
@@ -1,7 +1,7 @@
CMAKE_BUILD_RPATH
-----------------
-A :ref:`;-list <CMake Language Lists>` specifying runtime path (``RPATH``)
+:ref:`Semicolon-separated list <CMake Language Lists>` specifying runtime path (``RPATH``)
entries to add to binaries linked in the build tree (for platforms that
support it). The entries will *not* be used for binaries in the install
tree. See also the :variable:`CMAKE_INSTALL_RPATH` variable.
diff --git a/Help/variable/CMAKE_BUILD_TYPE.rst b/Help/variable/CMAKE_BUILD_TYPE.rst
index 2d54d6049..2d35635ac 100644
--- a/Help/variable/CMAKE_BUILD_TYPE.rst
+++ b/Help/variable/CMAKE_BUILD_TYPE.rst
@@ -5,7 +5,7 @@ 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
+``RelWithDebInfo``, ``MinSizeRel``, ... This variable is only meaningful to
single-configuration generators (such as :ref:`Makefile Generators` and
:generator:`Ninja`) i.e. those which choose a single configuration when CMake
runs to generate a build tree as opposed to multi-configuration generators
@@ -13,7 +13,7 @@ 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,
+``CMAKE_C_FLAGS_[DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL|...]``. For example,
in a build tree configured to build type ``Debug``, CMake will see to
having :variable:`CMAKE_C_FLAGS_DEBUG <CMAKE_<LANG>_FLAGS_DEBUG>` settings get
added to the :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>` settings. See
diff --git a/Help/variable/CMAKE_CFG_INTDIR.rst b/Help/variable/CMAKE_CFG_INTDIR.rst
index c36599adf..af82f7571 100644
--- a/Help/variable/CMAKE_CFG_INTDIR.rst
+++ b/Help/variable/CMAKE_CFG_INTDIR.rst
@@ -12,7 +12,7 @@ Example values:
::
- $(ConfigurationName) = Visual Studio 8, 9
+ $(ConfigurationName) = Visual Studio 9
$(Configuration) = Visual Studio 10
$(CONFIGURATION) = Xcode
. = Make-based tools
diff --git a/Help/variable/CMAKE_CROSSCOMPILING.rst b/Help/variable/CMAKE_CROSSCOMPILING.rst
index cf9865b61..7e6ec3371 100644
--- a/Help/variable/CMAKE_CROSSCOMPILING.rst
+++ b/Help/variable/CMAKE_CROSSCOMPILING.rst
@@ -1,8 +1,27 @@
CMAKE_CROSSCOMPILING
--------------------
-Is CMake currently cross compiling.
+Intended to indicate whether CMake is cross compiling, but note limitations
+discussed below.
-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.
+This variable will be set to true by CMake if the :variable:`CMAKE_SYSTEM_NAME`
+variable has been set manually (i.e. in a toolchain file or as a cache entry
+from the :manual:`cmake <cmake(1)>` command line). In most cases, manually
+setting :variable:`CMAKE_SYSTEM_NAME` will only be done when cross compiling,
+since it will otherwise be given the same value as
+:variable:`CMAKE_HOST_SYSTEM_NAME` if not manually set, which is correct for
+the non-cross-compiling case. In the event that :variable:`CMAKE_SYSTEM_NAME`
+is manually set to the same value as :variable:`CMAKE_HOST_SYSTEM_NAME`, then
+``CMAKE_CROSSCOMPILING`` will still be set to true.
+
+Another case to be aware of is that builds targeting Apple platforms other than
+macOS are handled differently to other cross compiling scenarios. Rather than
+relying on :variable:`CMAKE_SYSTEM_NAME` to select the target platform, Apple
+device builds use :variable:`CMAKE_OSX_SYSROOT` to select the appropriate SDK,
+which indirectly determines the target platform. Furthermore, when using the
+:generator:`Xcode` generator, developers can switch between device and
+simulator builds at build time rather than having a single
+choice at configure time, so the concept
+of whether the build is cross compiling or not is more complex. Therefore, the
+use of ``CMAKE_CROSSCOMPILING`` is not recommended for projects targeting Apple
+devices.
diff --git a/Help/variable/CMAKE_CROSSCOMPILING_EMULATOR.rst b/Help/variable/CMAKE_CROSSCOMPILING_EMULATOR.rst
index 95d2c7ffc..1d013b7a6 100644
--- a/Help/variable/CMAKE_CROSSCOMPILING_EMULATOR.rst
+++ b/Help/variable/CMAKE_CROSSCOMPILING_EMULATOR.rst
@@ -5,8 +5,12 @@ This variable is only used when :variable:`CMAKE_CROSSCOMPILING` is on. It
should point to a command on the host system that can run executable built
for the target system.
+If this variable contains a :ref:`semicolon-separated list <CMake Language
+Lists>`, then the first value is the command and remaining values are its
+arguments.
+
The command will be used to run :command:`try_run` generated executables,
-which avoids manual population of the TryRunResults.cmake file.
+which avoids manual population of the ``TryRunResults.cmake`` file.
It is also used as the default value for the
:prop_tgt:`CROSSCOMPILING_EMULATOR` target property of executables.
diff --git a/Help/variable/CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.rst b/Help/variable/CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.rst
index 768f571c0..7de50a5a7 100644
--- a/Help/variable/CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.rst
+++ b/Help/variable/CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.rst
@@ -2,6 +2,6 @@ CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES
--------------------------------------
When the ``CUDA`` language has been enabled, this provides a
-:ref:`;-list <CMake Language Lists>` of include directories provided
+:ref:`semicolon-separated list <CMake Language Lists>` of include directories provided
by the CUDA Toolkit. The value may be useful for C++ source files
to include CUDA headers.
diff --git a/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst b/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst
index 513276e57..a1fa1fffa 100644
--- a/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst
+++ b/Help/variable/CMAKE_DEBUG_TARGET_PROPERTIES.rst
@@ -5,10 +5,19 @@ 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.
+only be used when evaluating:
+
+* :prop_tgt:`AUTOUIC_OPTIONS`
+* :prop_tgt:`COMPILE_DEFINITIONS`
+* :prop_tgt:`COMPILE_FEATURES`
+* :prop_tgt:`COMPILE_OPTIONS`
+* :prop_tgt:`INCLUDE_DIRECTORIES`
+* :prop_tgt:`LINK_DIRECTORIES`
+* :prop_tgt:`LINK_OPTIONS`
+* :prop_tgt:`POSITION_INDEPENDENT_CODE`
+* :prop_tgt:`SOURCES`
+
+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_ENABLE_EXPORTS.rst b/Help/variable/CMAKE_ENABLE_EXPORTS.rst
index 9a877e7e6..7ec4d635d 100644
--- a/Help/variable/CMAKE_ENABLE_EXPORTS.rst
+++ b/Help/variable/CMAKE_ENABLE_EXPORTS.rst
@@ -12,7 +12,7 @@ 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 OS X, the
+require all symbols to be resolved at link time, such as macOS, 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
diff --git a/Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst b/Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst
index ee109ba1a..768ed64bf 100644
--- a/Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst
+++ b/Help/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.rst
@@ -1,11 +1,16 @@
CMAKE_EXPORT_NO_PACKAGE_REGISTRY
--------------------------------
-Disable the :command:`export(PACKAGE)` command.
+Disable the :command:`export(PACKAGE)` command when :policy:`CMP0090`
+is not set to ``NEW``.
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,
+If the ``CMAKE_EXPORT_NO_PACKAGE_REGISTRY`` variable is enabled,
the :command:`export(PACKAGE)` command will do nothing.
+If :policy:`CMP0090` is set to ``NEW`` this variable does nothing, and the
+:variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable controls the behavior
+instead.
+
See also :ref:`Disabling the Package Registry`.
diff --git a/Help/variable/CMAKE_EXTRA_GENERATOR.rst b/Help/variable/CMAKE_EXTRA_GENERATOR.rst
index 4d513e474..2c9232345 100644
--- a/Help/variable/CMAKE_EXTRA_GENERATOR.rst
+++ b/Help/variable/CMAKE_EXTRA_GENERATOR.rst
@@ -4,7 +4,7 @@ CMAKE_EXTRA_GENERATOR
The extra generator used to build the project. See
:manual:`cmake-generators(7)`.
-When using the Eclipse, CodeBlocks or KDevelop generators, CMake
+When using the Eclipse, CodeBlocks, CodeLite, Kate or Sublime generators, CMake
generates Makefiles (:variable:`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_FIND_APPBUNDLE.rst b/Help/variable/CMAKE_FIND_APPBUNDLE.rst
index e0727b547..7a05facf8 100644
--- a/Help/variable/CMAKE_FIND_APPBUNDLE.rst
+++ b/Help/variable/CMAKE_FIND_APPBUNDLE.rst
@@ -2,9 +2,9 @@ CMAKE_FIND_APPBUNDLE
--------------------
This variable affects how ``find_*`` commands choose between
-OS X Application Bundles and unix-style package components.
+macOS Application Bundles and unix-style package components.
-On Darwin or systems supporting OS X Application Bundles, the
+On Darwin or systems supporting macOS Application Bundles, the
``CMAKE_FIND_APPBUNDLE`` variable can be set to empty or
one of the following:
diff --git a/Help/variable/CMAKE_FIND_FRAMEWORK.rst b/Help/variable/CMAKE_FIND_FRAMEWORK.rst
index 790694ac5..4d5078fb6 100644
--- a/Help/variable/CMAKE_FIND_FRAMEWORK.rst
+++ b/Help/variable/CMAKE_FIND_FRAMEWORK.rst
@@ -2,9 +2,9 @@ CMAKE_FIND_FRAMEWORK
--------------------
This variable affects how ``find_*`` commands choose between
-OS X Frameworks and unix-style package components.
+macOS Frameworks and unix-style package components.
-On Darwin or systems supporting OS X Frameworks, the
+On Darwin or systems supporting macOS Frameworks, the
``CMAKE_FIND_FRAMEWORK`` variable can be set to empty or
one of the following:
diff --git a/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst b/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst
index c49d2641b..789dc99aa 100644
--- a/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst
+++ b/Help/variable/CMAKE_FIND_NO_INSTALL_PREFIX.rst
@@ -1,15 +1,19 @@
CMAKE_FIND_NO_INSTALL_PREFIX
----------------------------
-Ignore the :variable:`CMAKE_INSTALL_PREFIX` when searching for assets.
+Exclude the values of the :variable:`CMAKE_INSTALL_PREFIX` and
+:variable:`CMAKE_STAGING_PREFIX` variables from
+:variable:`CMAKE_SYSTEM_PREFIX_PATH`. CMake adds these project-destination
+prefixes to :variable:`CMAKE_SYSTEM_PREFIX_PATH` by default in order to
+support building a series of dependent packages and installing them into
+a common prefix. Set ``CMAKE_FIND_NO_INSTALL_PREFIX`` to ``TRUE``
+to suppress this behavior.
-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.
+The :variable:`CMAKE_SYSTEM_PREFIX_PATH` is initialized on the first call to a
+:command:`project` or :command:`enable_language` command. Therefore one must
+set ``CMAKE_FIND_NO_INSTALL_PREFIX`` before this in order to take effect. A
+user may set the variable as a cache entry on the command line to achieve this.
-Set ``CMAKE_FIND_NO_INSTALL_PREFIX`` to ``TRUE`` to tell
-:command:`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.
+Note that the prefix(es) 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_WARN_NO_MODULE.rst b/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst
index f1116bb62..5c4f23a4a 100644
--- a/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst
+++ b/Help/variable/CMAKE_FIND_PACKAGE_WARN_NO_MODULE.rst
@@ -17,3 +17,6 @@ Set ``CMAKE_FIND_PACKAGE_WARN_NO_MODULE`` to ``TRUE`` to tell
:command:`find_package` to warn when it implicitly assumes Config mode. This
helps developers enforce use of an explicit mode in all calls to
:command:`find_package` within a project.
+
+This variable has no effect if :variable:`CMAKE_FIND_PACKAGE_PREFER_CONFIG` is
+set to ``TRUE``.
diff --git a/Help/variable/CMAKE_FIND_ROOT_PATH.rst b/Help/variable/CMAKE_FIND_ROOT_PATH.rst
index ba2cf313e..6172c56ae 100644
--- a/Help/variable/CMAKE_FIND_ROOT_PATH.rst
+++ b/Help/variable/CMAKE_FIND_ROOT_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_FIND_ROOT_PATH
--------------------
-:ref:`;-list <CMake Language Lists>` of root paths to search on the filesystem.
+:ref:`Semicolon-separated list <CMake Language Lists>` 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
diff --git a/Help/variable/CMAKE_FRAMEWORK_PATH.rst b/Help/variable/CMAKE_FRAMEWORK_PATH.rst
index 5ff08e679..13ade4e5f 100644
--- a/Help/variable/CMAKE_FRAMEWORK_PATH.rst
+++ b/Help/variable/CMAKE_FRAMEWORK_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_FRAMEWORK_PATH
--------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
-for OS X frameworks used by the :command:`find_library`,
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
+for macOS frameworks used by the :command:`find_library`,
:command:`find_package`, :command:`find_path`, and :command:`find_file`
commands.
diff --git a/Help/variable/CMAKE_GENERATOR.rst b/Help/variable/CMAKE_GENERATOR.rst
index cce04c136..ec52cd4d8 100644
--- a/Help/variable/CMAKE_GENERATOR.rst
+++ b/Help/variable/CMAKE_GENERATOR.rst
@@ -5,3 +5,8 @@ The generator used to build the project. See :manual:`cmake-generators(7)`.
The name of the generator that is being used to generate the build
files. (e.g. ``Unix Makefiles``, ``Ninja``, etc.)
+
+The value of this variable should never be modified by project code.
+A generator may be selected via the :manual:`cmake(1)` ``-G`` option,
+interactively in :manual:`cmake-gui(1)`, or via the :envvar:`CMAKE_GENERATOR`
+environment variable.
diff --git a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst
index 50412ffff..2c115a3ab 100644
--- a/Help/variable/CMAKE_GENERATOR_PLATFORM.rst
+++ b/Help/variable/CMAKE_GENERATOR_PLATFORM.rst
@@ -6,7 +6,8 @@ Generator-specific target platform specification provided 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 platform name (e.g. via the :manual:`cmake(1)` ``-A``
-option) the value will be available in this variable.
+option or via the :envvar:`CMAKE_GENERATOR_PLATFORM` environment variable)
+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`
@@ -19,6 +20,8 @@ Platform specification is supported only on specific generators:
* For :ref:`Visual Studio Generators` with VS 2005 and above this
specifies the target architecture.
+* For :generator:`Green Hills MULTI` this specifies the target architecture.
+
See native build system documentation for allowed platform names.
Visual Studio Platform Selection
diff --git a/Help/variable/CMAKE_GENERATOR_TOOLSET.rst b/Help/variable/CMAKE_GENERATOR_TOOLSET.rst
index 11c37d746..a01a8b72c 100644
--- a/Help/variable/CMAKE_GENERATOR_TOOLSET.rst
+++ b/Help/variable/CMAKE_GENERATOR_TOOLSET.rst
@@ -5,7 +5,8 @@ Native build system toolset specification provided by user.
Some CMake generators support a toolset specification to tell the
native build system how to choose a compiler. If the user specifies
-a toolset (e.g. via the :manual:`cmake(1)` ``-T`` option) the value
+a toolset (e.g. via the :manual:`cmake(1)` ``-T`` option or via
+the :envvar:`CMAKE_GENERATOR_TOOLSET` environment variable) the value
will be available in this variable.
The value of this variable should never be modified by project code.
@@ -18,6 +19,7 @@ Toolset specification is supported only on specific generators:
* :ref:`Visual Studio Generators` for VS 2010 and above
* The :generator:`Xcode` generator for Xcode 3.0 and above
+* The :generator:`Green Hills MULTI` generator
See native build system documentation for allowed toolset names.
@@ -43,8 +45,13 @@ Supported pairs are:
and above with the CUDA toolkit VS integration installed.
See the :variable:`CMAKE_VS_PLATFORM_TOOLSET_CUDA` variable.
-``host=x64``
- Request use of the native ``x64`` toolchain on ``x64`` hosts.
+``host=<arch>``
+ Specify the host tools architecture as ``x64`` or ``x86``.
Supported by VS 2013 and above.
See the :variable:`CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE`
variable.
+
+``version=<version>``
+ Specify the toolset version to use. Supported by VS 2017
+ and above with the specified toolset installed.
+ See the :variable:`CMAKE_VS_PLATFORM_TOOLSET_VERSION` variable.
diff --git a/Help/variable/CMAKE_HOME_DIRECTORY.rst b/Help/variable/CMAKE_HOME_DIRECTORY.rst
index fdc5d8190..b03d95618 100644
--- a/Help/variable/CMAKE_HOME_DIRECTORY.rst
+++ b/Help/variable/CMAKE_HOME_DIRECTORY.rst
@@ -1,6 +1,9 @@
CMAKE_HOME_DIRECTORY
--------------------
-Path to top of source tree.
+Path to top of source tree. Same as :variable:`CMAKE_SOURCE_DIR`.
-This is the path to the top level of the source tree.
+This is an internal cache entry used to locate the source directory
+when loading a ``CMakeCache.txt`` from a build tree. It should not
+be used in project code. The variable :variable:`CMAKE_SOURCE_DIR`
+has the same value and should be preferred.
diff --git a/Help/variable/CMAKE_HOST_APPLE.rst b/Help/variable/CMAKE_HOST_APPLE.rst
index ac7b03004..9c205ec34 100644
--- a/Help/variable/CMAKE_HOST_APPLE.rst
+++ b/Help/variable/CMAKE_HOST_APPLE.rst
@@ -1,6 +1,6 @@
CMAKE_HOST_APPLE
----------------
-``True`` for Apple OS X operating systems.
+``True`` for Apple macOS operating systems.
-Set to ``true`` when the host system is Apple OS X.
+Set to ``true`` when the host system is Apple macOS.
diff --git a/Help/variable/CMAKE_HOST_SYSTEM.rst b/Help/variable/CMAKE_HOST_SYSTEM.rst
index c2a8f1a5f..12d11d198 100644
--- a/Help/variable/CMAKE_HOST_SYSTEM.rst
+++ b/Help/variable/CMAKE_HOST_SYSTEM.rst
@@ -1,7 +1,7 @@
CMAKE_HOST_SYSTEM
-----------------
-Composit Name of OS CMake is being run on.
+Composite 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.
diff --git a/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
index c67359272..e8926771c 100644
--- a/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
+++ b/Help/variable/CMAKE_HOST_SYSTEM_NAME.rst
@@ -4,5 +4,5 @@ CMAKE_HOST_SYSTEM_NAME
Name of the OS CMake is running on.
On systems that have the uname command, this variable is set to the
-output of ``uname -s``. ``Linux``, ``Windows``, and ``Darwin`` for OS X
+output of ``uname -s``. ``Linux``, ``Windows``, and ``Darwin`` for macOS
are the values found on the big three operating systems.
diff --git a/Help/variable/CMAKE_IGNORE_PATH.rst b/Help/variable/CMAKE_IGNORE_PATH.rst
index 92f377086..4bca34b7e 100644
--- a/Help/variable/CMAKE_IGNORE_PATH.rst
+++ b/Help/variable/CMAKE_IGNORE_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_IGNORE_PATH
-----------------
-:ref:`;-list <CMake Language Lists>` of directories to be *ignored* by
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories to be *ignored* by
the :command:`find_program`, :command:`find_library`, :command:`find_file`,
and :command:`find_path` commands. This is useful in cross-compiling
environments where some system directories contain incompatible but
diff --git a/Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst
index 6eea322f8..98d99eb64 100644
--- a/Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst
+++ b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR.rst
@@ -1,7 +1,7 @@
CMAKE_INCLUDE_CURRENT_DIR
-------------------------
-Automatically add the current source- and build directories to the include path.
+Automatically add the current source and build directories to the include path.
If this variable is enabled, CMake automatically adds
:variable:`CMAKE_CURRENT_SOURCE_DIR` and :variable:`CMAKE_CURRENT_BINARY_DIR`
diff --git a/Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst
index 5fc95f00b..697682ba6 100644
--- a/Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst
+++ b/Help/variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE.rst
@@ -1,7 +1,7 @@
CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE
--------------------------------------
-Automatically add the current source- and build directories to the
+Automatically add the current source and build directories to the
:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` target property.
If this variable is enabled, CMake automatically adds for each shared
diff --git a/Help/variable/CMAKE_INCLUDE_PATH.rst b/Help/variable/CMAKE_INCLUDE_PATH.rst
index e4e7f2cfc..4918e9960 100644
--- a/Help/variable/CMAKE_INCLUDE_PATH.rst
+++ b/Help/variable/CMAKE_INCLUDE_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_INCLUDE_PATH
------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
for the :command:`find_file` and :command:`find_path` commands. By default it
is empty, it is intended to be set by the project. See also
:variable:`CMAKE_SYSTEM_INCLUDE_PATH` and :variable:`CMAKE_PREFIX_PATH`.
diff --git a/Help/variable/CMAKE_INSTALL_NAME_DIR.rst b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
index 1f2d62bf6..5ba4c04cb 100644
--- a/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
+++ b/Help/variable/CMAKE_INSTALL_NAME_DIR.rst
@@ -1,7 +1,7 @@
CMAKE_INSTALL_NAME_DIR
----------------------
-OS X directory name for installed targets.
+macOS directory name for installed targets.
``CMAKE_INSTALL_NAME_DIR`` is used to initialize the
:prop_tgt:`INSTALL_NAME_DIR` property on all targets. See that target
diff --git a/Help/variable/CMAKE_INSTALL_PREFIX.rst b/Help/variable/CMAKE_INSTALL_PREFIX.rst
index 7bd87d6aa..02ba645c7 100644
--- a/Help/variable/CMAKE_INSTALL_PREFIX.rst
+++ b/Help/variable/CMAKE_INSTALL_PREFIX.rst
@@ -10,21 +10,7 @@ See :variable:`CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT` for how a
project might choose its own default.
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.
+whole installation. See :envvar:`DESTDIR` for more information.
The installation prefix is also added to :variable:`CMAKE_SYSTEM_PREFIX_PATH`
so that :command:`find_package`, :command:`find_program`,
diff --git a/Help/variable/CMAKE_JOB_POOL_LINK.rst b/Help/variable/CMAKE_JOB_POOL_LINK.rst
index 338f7714e..eeee6e069 100644
--- a/Help/variable/CMAKE_JOB_POOL_LINK.rst
+++ b/Help/variable/CMAKE_JOB_POOL_LINK.rst
@@ -1,5 +1,5 @@
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`
diff --git a/Help/variable/CMAKE_LANG_CLANG_TIDY.rst b/Help/variable/CMAKE_LANG_CLANG_TIDY.rst
index 492c12c6d..bd49de369 100644
--- a/Help/variable/CMAKE_LANG_CLANG_TIDY.rst
+++ b/Help/variable/CMAKE_LANG_CLANG_TIDY.rst
@@ -1,6 +1,13 @@
CMAKE_<LANG>_CLANG_TIDY
-----------------------
-Default value for :prop_tgt:`<LANG>_CLANG_TIDY` target property.
+Default value for :prop_tgt:`<LANG>_CLANG_TIDY` target property
+when ``<LANG>`` is ``C`` or ``CXX``.
+
This variable is used to initialize the property on each target as it is
-created. This is done only when ``<LANG>`` is ``C`` or ``CXX``.
+created. For example:
+
+.. code-block:: cmake
+
+ set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*)
+ add_executable(foo foo.cxx)
diff --git a/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst b/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst
index 5be935bad..cbe35441e 100644
--- a/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst
+++ b/Help/variable/CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN.rst
@@ -6,7 +6,7 @@ The external toolchain for cross-compiling, if supported.
Some compiler toolchains do not ship their own auxiliary 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
+``CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN`` may be set 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
diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst
index 0fab10ca8..8eb4fb612 100644
--- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst
+++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst
@@ -12,16 +12,19 @@ include:
ADSP = Analog VisualDSP++ (analog.com)
AppleClang = Apple Clang (apple.com)
ARMCC = ARM Compiler (arm.com)
+ ARMClang = ARM Compiler based on Clang (arm.com)
Bruce = Bruce C Compiler
CCur = Concurrent Fortran (ccur.com)
Clang = LLVM Clang (clang.llvm.org)
Cray = Cray Compiler (cray.com)
Embarcadero, Borland = Embarcadero (embarcadero.com)
+ Flang = Flang LLVM Fortran Compiler
G95 = G95 Fortran (g95.org)
GNU = GNU Compiler Collection (gcc.gnu.org)
+ GHS = Green Hills Software (www.ghs.com)
HP = Hewlett-Packard Compiler (hp.com)
+ IAR = IAR Systems (iar.com)
Intel = Intel Compiler (intel.com)
- MIPSpro = SGI MIPSpro (sgi.com)
MSVC = Microsoft Visual Studio (microsoft.com)
NVIDIA = NVIDIA CUDA Compiler (nvidia.com)
OpenWatcom = Open Watcom (openwatcom.org)
@@ -32,6 +35,7 @@ include:
TI = Texas Instruments (ti.com)
TinyCC = Tiny C Compiler (tinycc.org)
XL, VisualAge, zOS = IBM XL (ibm.com)
+ XLClang = IBM Clang-based XL (ibm.com)
This variable is not guaranteed to be defined for all compilers or
languages.
diff --git a/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst b/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst
index 7961f609e..e6c8bb58e 100644
--- a/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst
+++ b/Help/variable/CMAKE_LANG_COMPILER_LAUNCHER.rst
@@ -3,4 +3,5 @@ CMAKE_<LANG>_COMPILER_LAUNCHER
Default value for :prop_tgt:`<LANG>_COMPILER_LAUNCHER` target property.
This variable is used to initialize the property on each target as it is
-created. This is done only when ``<LANG>`` is ``C`` or ``CXX``.
+created. This is done only when ``<LANG>`` is ``C``, ``CXX``, ``Fortran``,
+or ``CUDA``.
diff --git a/Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst b/Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst
index be89f8529..16fcc0344 100644
--- a/Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst
+++ b/Help/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.rst
@@ -4,4 +4,5 @@ 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>``.
+library for the language ``<LANG>``. This rule variable is a ``;`` delimited
+list of commands to run to perform the linking step.
diff --git a/Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst b/Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst
index ae5f69d56..807229dec 100644
--- a/Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst
+++ b/Help/variable/CMAKE_LANG_CREATE_SHARED_MODULE.rst
@@ -4,4 +4,5 @@ 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>``.
+library for the language ``<LANG>``. This rule variable is a ``;`` delimited
+list of commands to run.
diff --git a/Help/variable/CMAKE_LANG_FLAGS.rst b/Help/variable/CMAKE_LANG_FLAGS.rst
index c57d92cbf..14b2694ef 100644
--- a/Help/variable/CMAKE_LANG_FLAGS.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS.rst
@@ -4,3 +4,14 @@ CMAKE_<LANG>_FLAGS
Flags for all build types.
``<LANG>`` flags used regardless of the value of :variable:`CMAKE_BUILD_TYPE`.
+
+This is initialized for each language from environment variables:
+
+* ``CMAKE_C_FLAGS``:
+ Initialized by the :envvar:`CFLAGS` environment variable.
+* ``CMAKE_CXX_FLAGS``:
+ Initialized by the :envvar:`CXXFLAGS` environment variable.
+* ``CMAKE_CUDA_FLAGS``:
+ Initialized by the :envvar:`CUDAFLAGS` environment variable.
+* ``CMAKE_Fortran_FLAGS``:
+ Initialized by the :envvar:`FFLAGS` environment variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst b/Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst
index a233d4ad7..6be424aa9 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_DEBUG.rst
@@ -1,6 +1,5 @@
CMAKE_<LANG>_FLAGS_DEBUG
------------------------
-Flags for ``Debug`` build type or configuration.
-
-``<LANG>`` flags used when :variable:`CMAKE_BUILD_TYPE` is ``Debug``.
+This variable is the ``Debug`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_DEBUG_INIT.rst b/Help/variable/CMAKE_LANG_FLAGS_DEBUG_INIT.rst
index dcddb2e26..de7fcfc1d 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_DEBUG_INIT.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_DEBUG_INIT.rst
@@ -1,10 +1,5 @@
CMAKE_<LANG>_FLAGS_DEBUG_INIT
-----------------------------
-Value used to initialize the :variable:`CMAKE_<LANG>_FLAGS_DEBUG` cache
-entry the first time a build tree is configured for language ``<LANG>``.
-This variable is meant to be set by a :variable:`toolchain file
-<CMAKE_TOOLCHAIN_FILE>`. CMake may prepend or append content to
-the value based on the environment and target platform.
-
-See also :variable:`CMAKE_<LANG>_FLAGS_INIT`.
+This variable is the ``Debug`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>_INIT` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_INIT.rst b/Help/variable/CMAKE_LANG_FLAGS_INIT.rst
index 1d32cc3fd..a88d1229e 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_INIT.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_INIT.rst
@@ -7,9 +7,5 @@ This variable is meant to be set by a :variable:`toolchain file
<CMAKE_TOOLCHAIN_FILE>`. CMake may prepend or append content to
the value based on the environment and target platform.
-See also the configuration-specific variables:
-
-* :variable:`CMAKE_<LANG>_FLAGS_DEBUG_INIT`
-* :variable:`CMAKE_<LANG>_FLAGS_RELEASE_INIT`
-* :variable:`CMAKE_<LANG>_FLAGS_MINSIZEREL_INIT`
-* :variable:`CMAKE_<LANG>_FLAGS_RELWITHDEBINFO_INIT`
+See also the configuration-specific
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>_INIT` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst b/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst
index a9436c184..634fab9d6 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL.rst
@@ -1,7 +1,5 @@
CMAKE_<LANG>_FLAGS_MINSIZEREL
-----------------------------
-Flags for ``MinSizeRel`` build type or configuration.
-
-``<LANG>`` flags used when :variable:`CMAKE_BUILD_TYPE` is ``MinSizeRel``
-(short for minimum size release).
+This variable is the ``MinSizeRel`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL_INIT.rst b/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL_INIT.rst
index c0aedf403..1e7003cec 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL_INIT.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_MINSIZEREL_INIT.rst
@@ -1,10 +1,5 @@
CMAKE_<LANG>_FLAGS_MINSIZEREL_INIT
----------------------------------
-Value used to initialize the :variable:`CMAKE_<LANG>_FLAGS_MINSIZEREL`
-cache entry the first time a build tree is configured for language ``<LANG>``.
-This variable is meant to be set by a :variable:`toolchain file
-<CMAKE_TOOLCHAIN_FILE>`. CMake may prepend or append content to
-the value based on the environment and target platform.
-
-See also :variable:`CMAKE_<LANG>_FLAGS_INIT`.
+This variable is the ``MinSizeRel`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>_INIT` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst b/Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst
index ffc5d795d..3baeab090 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_RELEASE.rst
@@ -1,6 +1,5 @@
CMAKE_<LANG>_FLAGS_RELEASE
--------------------------
-Flags for ``Release`` build type or configuration.
-
-``<LANG>`` flags used when :variable:`CMAKE_BUILD_TYPE` is ``Release``.
+This variable is the ``Release`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_RELEASE_INIT.rst b/Help/variable/CMAKE_LANG_FLAGS_RELEASE_INIT.rst
index 59f92ff6f..e7c73fea6 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_RELEASE_INIT.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_RELEASE_INIT.rst
@@ -1,10 +1,5 @@
CMAKE_<LANG>_FLAGS_RELEASE_INIT
-------------------------------
-Value used to initialize the :variable:`CMAKE_<LANG>_FLAGS_RELEASE`
-cache entry the first time a build tree is configured for language ``<LANG>``.
-This variable is meant to be set by a :variable:`toolchain file
-<CMAKE_TOOLCHAIN_FILE>`. CMake may prepend or append content to
-the value based on the environment and target platform.
-
-See also :variable:`CMAKE_<LANG>_FLAGS_INIT`.
+This variable is the ``Release`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>_INIT` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst b/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst
index 962768e44..67a507377 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO.rst
@@ -1,7 +1,5 @@
CMAKE_<LANG>_FLAGS_RELWITHDEBINFO
---------------------------------
-Flags for ``RelWithDebInfo`` type or configuration.
-
-``<LANG>`` flags used when :variable:`CMAKE_BUILD_TYPE` is ``RelWithDebInfo``
-(short for Release With Debug Information).
+This variable is the ``RelWithDebInfo`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` variable.
diff --git a/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT.rst b/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT.rst
index 915f02305..3ab39753d 100644
--- a/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT.rst
+++ b/Help/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT.rst
@@ -1,10 +1,5 @@
CMAKE_<LANG>_FLAGS_RELWITHDEBINFO_INIT
--------------------------------------
-Value used to initialize the :variable:`CMAKE_<LANG>_FLAGS_RELWITHDEBINFO`
-cache entry the first time a build tree is configured for language ``<LANG>``.
-This variable is meant to be set by a :variable:`toolchain file
-<CMAKE_TOOLCHAIN_FILE>`. CMake may prepend or append content to
-the value based on the environment and target platform.
-
-See also :variable:`CMAKE_<LANG>_FLAGS_INIT`.
+This variable is the ``RelWithDebInfo`` variant of the
+:variable:`CMAKE_<LANG>_FLAGS_<CONFIG>_INIT` variable.
diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst
index cc8085107..e361fd98e 100644
--- a/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst
+++ b/Help/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES.rst
@@ -6,4 +6,9 @@ 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.
+compilers, which is important for ``C``, ``CXX``, and ``CUDA`` to
+avoid overriding standard library headers.
+
+This value is not used for ``Fortran`` because it has no standard
+library headers and some compilers do not search their implicit
+include directories for module ``.mod`` files.
diff --git a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst
index a0bd8303c..e9e04be6e 100644
--- a/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst
+++ b/Help/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES.rst
@@ -9,9 +9,12 @@ 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
-:command:`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.
+Some toolchains read implicit directories from an environment variable such as
+``LIBRARY_PATH``. If using such an environment variable, keep its value
+consistent when operating in a given build tree because CMake saves the value
+detected when first creating a build tree.
+
+If policy :policy:`CMP0060` is not set to ``NEW``, then when a library in one
+of these directories is given by full path to :command:`target_link_libraries`
+CMake will generate the ``-l<name>`` form on link lines for historical
+purposes.
diff --git a/Help/variable/CMAKE_LIBRARY_PATH.rst b/Help/variable/CMAKE_LIBRARY_PATH.rst
index b1770dc26..8135b6581 100644
--- a/Help/variable/CMAKE_LIBRARY_PATH.rst
+++ b/Help/variable/CMAKE_LIBRARY_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_LIBRARY_PATH
------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
for the :command:`find_library` command. By default it is empty, it is
intended to be set by the project. See also
:variable:`CMAKE_SYSTEM_LIBRARY_PATH` and :variable:`CMAKE_PREFIX_PATH`.
diff --git a/Help/variable/CMAKE_MACOSX_BUNDLE.rst b/Help/variable/CMAKE_MACOSX_BUNDLE.rst
index 0badaf0da..43ddff517 100644
--- a/Help/variable/CMAKE_MACOSX_BUNDLE.rst
+++ b/Help/variable/CMAKE_MACOSX_BUNDLE.rst
@@ -5,3 +5,6 @@ Default value for :prop_tgt:`MACOSX_BUNDLE` of targets.
This variable is used to initialize the :prop_tgt:`MACOSX_BUNDLE` property on
all the targets. See that target property for additional information.
+
+This variable is set to ``ON`` by default if :variable:`CMAKE_SYSTEM_NAME`
+equals to :ref:`iOS, tvOS or watchOS <Cross Compiling for iOS, tvOS, or watchOS>`.
diff --git a/Help/variable/CMAKE_MACOSX_RPATH.rst b/Help/variable/CMAKE_MACOSX_RPATH.rst
index 042e807f5..2fc648d61 100644
--- a/Help/variable/CMAKE_MACOSX_RPATH.rst
+++ b/Help/variable/CMAKE_MACOSX_RPATH.rst
@@ -1,7 +1,7 @@
CMAKE_MACOSX_RPATH
-------------------
-Whether to use rpaths on OS X and iOS.
+Whether to use rpaths on macOS and iOS.
This variable is used to initialize the :prop_tgt:`MACOSX_RPATH` property on
all targets.
diff --git a/Help/variable/CMAKE_MAKE_PROGRAM.rst b/Help/variable/CMAKE_MAKE_PROGRAM.rst
index a3b997af2..a3c8b7c8a 100644
--- a/Help/variable/CMAKE_MAKE_PROGRAM.rst
+++ b/Help/variable/CMAKE_MAKE_PROGRAM.rst
@@ -19,15 +19,11 @@ to configure the project:
This generator stores ``CMAKE_MAKE_PROGRAM`` in the CMake cache
so that it may be edited by the user.
-* The :generator:`Xcode` generator sets this to ``xcodebuild`` (or possibly an
- otherwise undocumented ``cmakexbuild`` wrapper implementing some
- workarounds).
+* The :generator:`Xcode` generator sets this to ``xcodebuild``.
This generator prefers 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 ``xcodebuild`` is easy to find,
- the ``cmakexbuild`` wrapper is needed only for older Xcode versions,
- and the path to ``cmakexbuild`` may be outdated if CMake itself moves.
+ ahead of time. This is because ``xcodebuild`` is easy to find.
For compatibility with versions of CMake prior to 3.2, if
a user or project explicitly adds ``CMAKE_MAKE_PROGRAM`` to
@@ -55,9 +51,12 @@ to configure the project:
the CMake cache then CMake will use the specified value if
possible.
-* The :generator:`Green Hills MULTI` generator sets this to ``gbuild``.
- If a user or project explicitly adds ``CMAKE_MAKE_PROGRAM`` to
- the CMake cache then CMake will use the specified value.
+* The :generator:`Green Hills MULTI` generator sets this to the full
+ path to ``gbuild.exe(Windows)`` or ``gbuild(Linux)`` based upon
+ the toolset being used.
+
+ Once the generator has initialized a particular value for this
+ variable, changing the value has undefined behavior.
The ``CMAKE_MAKE_PROGRAM`` variable is set for use by project code.
The value is also used by the :manual:`cmake(1)` ``--build`` and
diff --git a/Help/variable/CMAKE_MFC_FLAG.rst b/Help/variable/CMAKE_MFC_FLAG.rst
index 5a392bfbb..2c4d1c551 100644
--- a/Help/variable/CMAKE_MFC_FLAG.rst
+++ b/Help/variable/CMAKE_MFC_FLAG.rst
@@ -1,15 +1,16 @@
CMAKE_MFC_FLAG
--------------
-Tell cmake to use MFC for an executable or dll.
+Use the MFC library 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
-project files. The CMakeSetup dialog used MFC and the ``CMakeLists.txt``
-looks like this:
+Enables the use of the Microsoft Foundation Classes (MFC).
+It should be set to ``1`` for the static MFC library, and
+``2`` for the shared MFC library. This is used in Visual Studio
+project files.
-::
+Usage example:
+
+.. code-block:: cmake
add_definitions(-D_AFXDLL)
set(CMAKE_MFC_FLAG 2)
diff --git a/Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst b/Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst
index 5a51634db..f466468d8 100644
--- a/Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst
+++ b/Help/variable/CMAKE_MINIMUM_REQUIRED_VERSION.rst
@@ -1,7 +1,5 @@
CMAKE_MINIMUM_REQUIRED_VERSION
------------------------------
-Version specified to :command:`cmake_minimum_required` command
-
-Variable containing the ``VERSION`` component specified in the
-:command:`cmake_minimum_required` command.
+The ``<min>`` version of CMake given to the most recent call to the
+:command:`cmake_minimum_required(VERSION)` command.
diff --git a/Help/variable/CMAKE_MODULE_PATH.rst b/Help/variable/CMAKE_MODULE_PATH.rst
index 5ea7cbbc0..4dcf6b526 100644
--- a/Help/variable/CMAKE_MODULE_PATH.rst
+++ b/Help/variable/CMAKE_MODULE_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_MODULE_PATH
-----------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
-for CMake modules to be loaded by the the :command:`include` or
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
+for CMake modules to be loaded by the :command:`include` or
:command:`find_package` commands before checking the default modules that come
with CMake. By default it is empty, it is intended to be set by the project.
diff --git a/Help/variable/CMAKE_OSX_ARCHITECTURES.rst b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
index 93916dd62..fdaca28e3 100644
--- a/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
+++ b/Help/variable/CMAKE_OSX_ARCHITECTURES.rst
@@ -1,10 +1,10 @@
CMAKE_OSX_ARCHITECTURES
-----------------------
-Target specific architectures for OS X and iOS.
+Target specific architectures for macOS and iOS.
This variable is used to initialize the :prop_tgt:`OSX_ARCHITECTURES`
-property on each target as it is creaed. See that target property
+property on each target as it is created. 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
index 4fb2caa4f..9df5edda6 100644
--- a/Help/variable/CMAKE_OSX_DEPLOYMENT_TARGET.rst
+++ b/Help/variable/CMAKE_OSX_DEPLOYMENT_TARGET.rst
@@ -1,10 +1,12 @@
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`).
+Specify the minimum version of the target platform (e.g. macOS or iOS)
+on which the target binaries are to be deployed. CMake uses this
+variable value for the ``-mmacosx-version-min`` flag or their respective
+target platform equivalents. For older Xcode versions that shipped
+multiple macOS SDKs this variable also helps to choose the SDK in case
+:variable:`CMAKE_OSX_SYSROOT` is unset.
If not set explicitly the value is initialized by the
``MACOSX_DEPLOYMENT_TARGET`` environment variable, if set,
diff --git a/Help/variable/CMAKE_OSX_SYSROOT.rst b/Help/variable/CMAKE_OSX_SYSROOT.rst
index f1d58c6b5..db9fccdd1 100644
--- a/Help/variable/CMAKE_OSX_SYSROOT.rst
+++ b/Help/variable/CMAKE_OSX_SYSROOT.rst
@@ -1,7 +1,7 @@
CMAKE_OSX_SYSROOT
-----------------
-Specify the location or name of the OS X platform SDK to be used.
+Specify the location or name of the macOS 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.
diff --git a/Help/variable/CMAKE_OSX_VARIABLE.txt b/Help/variable/CMAKE_OSX_VARIABLE.txt
index 385f871f3..16f3c1a1a 100644
--- a/Help/variable/CMAKE_OSX_VARIABLE.txt
+++ b/Help/variable/CMAKE_OSX_VARIABLE.txt
@@ -2,5 +2,10 @@ 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 should be set as a ``CACHE`` entry (or else CMake may
+remove it while initializing a cache entry of the same name).
-This variable is ignored on platforms other than OS X.
+Despite the ``OSX`` part in the variable name(s) they apply also to
+other SDKs than macOS like iOS, tvOS, or watchOS.
+
+This variable is ignored on platforms other than Apple.
diff --git a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
index aa23b65f9..fc52e7b5d 100644
--- a/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
+++ b/Help/variable/CMAKE_POLICY_WARNING_CMPNNNN.rst
@@ -19,6 +19,10 @@ warn by default:
policy :policy:`CMP0066`.
* ``CMAKE_POLICY_WARNING_CMP0067`` controls the warning for
policy :policy:`CMP0067`.
+* ``CMAKE_POLICY_WARNING_CMP0082`` controls the warning for
+ policy :policy:`CMP0082`.
+* ``CMAKE_POLICY_WARNING_CMP0089`` controls the warning for
+ policy :policy:`CMP0089`.
This variable should not be set by a project in CMake code. Project
developers running CMake may set this variable in their cache to
diff --git a/Help/variable/CMAKE_PREFIX_PATH.rst b/Help/variable/CMAKE_PREFIX_PATH.rst
index c2a4a6038..1d4fd0b42 100644
--- a/Help/variable/CMAKE_PREFIX_PATH.rst
+++ b/Help/variable/CMAKE_PREFIX_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_PREFIX_PATH
-----------------
-:ref:`;-list <CMake Language Lists>` of directories specifying installation
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying installation
*prefixes* to be searched by the :command:`find_package`,
:command:`find_program`, :command:`find_library`, :command:`find_file`, and
:command:`find_path` commands. Each command will add appropriate
diff --git a/Help/variable/CMAKE_PROGRAM_PATH.rst b/Help/variable/CMAKE_PROGRAM_PATH.rst
index 799e1192c..2d0c090df 100644
--- a/Help/variable/CMAKE_PROGRAM_PATH.rst
+++ b/Help/variable/CMAKE_PROGRAM_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_PROGRAM_PATH
------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
for the :command:`find_program` command. By default it is empty, it is
intended to be set by the project. See also
:variable:`CMAKE_SYSTEM_PROGRAM_PATH` and :variable:`CMAKE_PREFIX_PATH`.
diff --git a/Help/variable/CMAKE_PROJECT_DESCRIPTION.rst b/Help/variable/CMAKE_PROJECT_DESCRIPTION.rst
index f1911eced..51b0592ea 100644
--- a/Help/variable/CMAKE_PROJECT_DESCRIPTION.rst
+++ b/Help/variable/CMAKE_PROJECT_DESCRIPTION.rst
@@ -1,7 +1,35 @@
CMAKE_PROJECT_DESCRIPTION
-------------------------
-The description of the current project.
+The description of the top level project.
-This specifies description of the current project from the closest inherited
-:command:`project` command.
+This variable holds the description of the project as specified in the top
+level CMakeLists.txt file by a :command:`project` command. In the event that
+the top level CMakeLists.txt contains multiple :command:`project` calls,
+the most recently called one from that top level CMakeLists.txt will determine
+the value that ``CMAKE_PROJECT_DESCRIPTION`` contains. For example, consider
+the following top level CMakeLists.txt:
+
+.. code-block:: cmake
+
+ cmake_minimum_required(VERSION 3.0)
+ project(First DESCRIPTION "I am First")
+ project(Second DESCRIPTION "I am Second")
+ add_subdirectory(sub)
+ project(Third DESCRIPTION "I am Third")
+
+And ``sub/CMakeLists.txt`` with the following contents:
+
+.. code-block:: cmake
+
+ project(SubProj DESCRIPTION "I am SubProj")
+ message("CMAKE_PROJECT_DESCRIPTION = ${CMAKE_PROJECT_DESCRIPTION}")
+
+The most recently seen :command:`project` command from the top level
+CMakeLists.txt would be ``project(Second ...)``, so this will print::
+
+ CMAKE_PROJECT_DESCRIPTION = I am Second
+
+To obtain the description from the most recent call to :command:`project` in
+the current directory scope or above, see the :variable:`PROJECT_DESCRIPTION`
+variable.
diff --git a/Help/variable/CMAKE_PROJECT_NAME.rst b/Help/variable/CMAKE_PROJECT_NAME.rst
index 431e9f302..94b8dbab8 100644
--- a/Help/variable/CMAKE_PROJECT_NAME.rst
+++ b/Help/variable/CMAKE_PROJECT_NAME.rst
@@ -1,7 +1,35 @@
CMAKE_PROJECT_NAME
------------------
-The name of the current project.
+The name of the top level project.
-This specifies name of the current project from the closest inherited
-:command:`project` command.
+This variable holds the name of the project as specified in the top
+level CMakeLists.txt file by a :command:`project` command. In the event that
+the top level CMakeLists.txt contains multiple :command:`project` calls,
+the most recently called one from that top level CMakeLists.txt will determine
+the name that ``CMAKE_PROJECT_NAME`` contains. For example, consider
+the following top level CMakeLists.txt:
+
+.. code-block:: cmake
+
+ cmake_minimum_required(VERSION 3.0)
+ project(First)
+ project(Second)
+ add_subdirectory(sub)
+ project(Third)
+
+And ``sub/CMakeLists.txt`` with the following contents:
+
+.. code-block:: cmake
+
+ project(SubProj)
+ message("CMAKE_PROJECT_NAME = ${CMAKE_PROJECT_NAME}")
+
+The most recently seen :command:`project` command from the top level
+CMakeLists.txt would be ``project(Second)``, so this will print::
+
+ CMAKE_PROJECT_NAME = Second
+
+To obtain the name from the most recent call to :command:`project` in
+the current directory scope or above, see the :variable:`PROJECT_NAME`
+variable.
diff --git a/Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst b/Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst
index ba9df5a34..3485c38e4 100644
--- a/Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst
+++ b/Help/variable/CMAKE_PROJECT_PROJECT-NAME_INCLUDE.rst
@@ -1,6 +1,10 @@
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.
+A CMake language file or module to be included as the last step of any
+:command:`project` command calls that specify ``<PROJECT-NAME>`` as the project
+name. This is intended for injecting custom code into project builds without
+modifying their source.
+
+See also the :variable:`CMAKE_PROJECT_INCLUDE` and
+:variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variables.
diff --git a/Help/variable/CMAKE_SKIP_INSTALL_RULES.rst b/Help/variable/CMAKE_SKIP_INSTALL_RULES.rst
index 44966f32f..b77bb686a 100644
--- a/Help/variable/CMAKE_SKIP_INSTALL_RULES.rst
+++ b/Help/variable/CMAKE_SKIP_INSTALL_RULES.rst
@@ -3,6 +3,6 @@ CMAKE_SKIP_INSTALL_RULES
Whether to disable generation of installation rules.
-If ``TRUE``, cmake will neither generate installaton rules nor
+If ``TRUE``, CMake will neither generate installation rules nor
will it generate ``cmake_install.cmake`` files. This variable is ``FALSE`` by
default.
diff --git a/Help/variable/CMAKE_SOURCE_DIR.rst b/Help/variable/CMAKE_SOURCE_DIR.rst
index 416fbe1a8..d1f179838 100644
--- a/Help/variable/CMAKE_SOURCE_DIR.rst
+++ b/Help/variable/CMAKE_SOURCE_DIR.rst
@@ -7,7 +7,7 @@ This is the full path to the top level of the current CMake source
tree. For an in-source build, this would be the same as
:variable:`CMAKE_BINARY_DIR`.
-When run in -P script mode, CMake sets the variables
+When run in ``-P`` script mode, CMake sets the variables
:variable:`CMAKE_BINARY_DIR`, :variable:`CMAKE_SOURCE_DIR`,
:variable:`CMAKE_CURRENT_BINARY_DIR` and
:variable:`CMAKE_CURRENT_SOURCE_DIR` to the current working directory.
diff --git a/Help/variable/CMAKE_STAGING_PREFIX.rst b/Help/variable/CMAKE_STAGING_PREFIX.rst
index 1310e9471..bdb97faef 100644
--- a/Help/variable/CMAKE_STAGING_PREFIX.rst
+++ b/Help/variable/CMAKE_STAGING_PREFIX.rst
@@ -5,10 +5,10 @@ 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
+The :variable:`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`.
+If any ``RPATH``/``RUNPATH`` entries passed to the linker contain the
+:variable:`CMAKE_STAGING_PREFIX`, the matching path fragments are replaced
+with the :variable:`CMAKE_INSTALL_PREFIX`.
diff --git a/Help/variable/CMAKE_SYSROOT.rst b/Help/variable/CMAKE_SYSROOT.rst
index 64f81bbc2..35b944fa4 100644
--- a/Help/variable/CMAKE_SYSROOT.rst
+++ b/Help/variable/CMAKE_SYSROOT.rst
@@ -4,8 +4,8 @@ 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
+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
diff --git a/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst b/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst
index 3c6687c6e..666af4615 100644
--- a/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst
+++ b/Help/variable/CMAKE_SYSTEM_APPBUNDLE_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_SYSTEM_APPBUNDLE_PATH
---------------------------
-Search path for OS X application bundles used by the :command:`find_program`,
+Search path for macOS application bundles used by the :command:`find_program`,
and :command:`find_package` commands. By default it contains the standard
directories for the current system. It is *not* intended to be modified by
the project, use :variable:`CMAKE_APPBUNDLE_PATH` for this.
diff --git a/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst b/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst
index 1e8b0d947..14ba18eff 100644
--- a/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst
+++ b/Help/variable/CMAKE_SYSTEM_FRAMEWORK_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_SYSTEM_FRAMEWORK_PATH
---------------------------
-Search path for OS X frameworks used by the :command:`find_library`,
+Search path for macOS frameworks used by the :command:`find_library`,
:command:`find_package`, :command:`find_path`, and :command:`find_file`
commands. By default it contains the standard directories for the
current system. It is *not* intended to be modified by the project,
diff --git a/Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst b/Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst
index 4ad7e33ce..6afbd337a 100644
--- a/Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst
+++ b/Help/variable/CMAKE_SYSTEM_IGNORE_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_SYSTEM_IGNORE_PATH
------------------------
-:ref:`;-list <CMake Language Lists>` of directories to be *ignored* by
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories to be *ignored* by
the :command:`find_program`, :command:`find_library`, :command:`find_file`,
and :command:`find_path` commands. This is useful in cross-compiling
environments where some system directories contain incompatible but
diff --git a/Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst b/Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst
index 2c14345c0..680404ef5 100644
--- a/Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst
+++ b/Help/variable/CMAKE_SYSTEM_INCLUDE_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_SYSTEM_INCLUDE_PATH
-------------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
for the :command:`find_file` and :command:`find_path` commands. By default
this contains the standard directories for the current system. It is *not*
intended to be modified by the project; use :variable:`CMAKE_INCLUDE_PATH` for
diff --git a/Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst b/Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst
index 3969cb94c..116832bf9 100644
--- a/Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst
+++ b/Help/variable/CMAKE_SYSTEM_LIBRARY_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_SYSTEM_LIBRARY_PATH
-------------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
for the :command:`find_library` command. By default this contains the
standard directories for the current system. It is *not* intended to be
modified by the project; use :variable:`CMAKE_LIBRARY_PATH` for this.
diff --git a/Help/variable/CMAKE_SYSTEM_NAME.rst b/Help/variable/CMAKE_SYSTEM_NAME.rst
index c3a42e5b4..fef53eecb 100644
--- a/Help/variable/CMAKE_SYSTEM_NAME.rst
+++ b/Help/variable/CMAKE_SYSTEM_NAME.rst
@@ -4,6 +4,9 @@ CMAKE_SYSTEM_NAME
The name of the operating system for which CMake is to build.
See the :variable:`CMAKE_SYSTEM_VERSION` variable for the OS version.
+Note that ``CMAKE_SYSTEM_NAME`` is not set to anything by default when running
+in script mode, since it's not building anything.
+
System Name for Host Builds
^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst b/Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst
index e74dfad18..87a9d06a8 100644
--- a/Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst
+++ b/Help/variable/CMAKE_SYSTEM_PREFIX_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_SYSTEM_PREFIX_PATH
------------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying installation
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying installation
*prefixes* to be searched by the :command:`find_package`,
:command:`find_program`, :command:`find_library`, :command:`find_file`, and
:command:`find_path` commands. Each command will add appropriate
@@ -10,8 +10,11 @@ documentation.
By default this contains the standard directories for the current system, the
:variable:`CMAKE_INSTALL_PREFIX`, and the :variable:`CMAKE_STAGING_PREFIX`.
-It is *not* intended to be modified by the project; use
-:variable:`CMAKE_PREFIX_PATH` for this.
+The installation and staging prefixes may be excluded by setting
+the :variable:`CMAKE_FIND_NO_INSTALL_PREFIX` variable.
+
+``CMAKE_SYSTEM_PREFIX_PATH`` is *not* intended to be modified by the project;
+use :variable:`CMAKE_PREFIX_PATH` for this.
See also :variable:`CMAKE_SYSTEM_INCLUDE_PATH`,
:variable:`CMAKE_SYSTEM_LIBRARY_PATH`, :variable:`CMAKE_SYSTEM_PROGRAM_PATH`,
diff --git a/Help/variable/CMAKE_SYSTEM_PROCESSOR.rst b/Help/variable/CMAKE_SYSTEM_PROCESSOR.rst
index 09280dee6..8ad89f128 100644
--- a/Help/variable/CMAKE_SYSTEM_PROCESSOR.rst
+++ b/Help/variable/CMAKE_SYSTEM_PROCESSOR.rst
@@ -6,5 +6,3 @@ 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.
-
-* The :generator:`Green Hills MULTI` generator sets this to ``ARM`` by default.
diff --git a/Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst b/Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst
index cf1b83e80..9b7036182 100644
--- a/Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst
+++ b/Help/variable/CMAKE_SYSTEM_PROGRAM_PATH.rst
@@ -1,7 +1,7 @@
CMAKE_SYSTEM_PROGRAM_PATH
-------------------------
-:ref:`;-list <CMake Language Lists>` of directories specifying a search path
+:ref:`Semicolon-separated list <CMake Language Lists>` of directories specifying a search path
for the :command:`find_program` command. By default this contains the
standard directories for the current system. It is *not* intended to be
modified by the project; use :variable:`CMAKE_PROGRAM_PATH` for this.
diff --git a/Help/variable/CMAKE_Swift_LANGUAGE_VERSION.rst b/Help/variable/CMAKE_Swift_LANGUAGE_VERSION.rst
index 50121e286..b4a74eb03 100644
--- a/Help/variable/CMAKE_Swift_LANGUAGE_VERSION.rst
+++ b/Help/variable/CMAKE_Swift_LANGUAGE_VERSION.rst
@@ -1,5 +1,9 @@
CMAKE_Swift_LANGUAGE_VERSION
----------------------------
-Set to the Swift language version number. If not set, the legacy "2.3"
-version is assumed.
+Set to the Swift language version number. If not set, the oldest legacy
+version known to be available in the host Xcode version is assumed:
+
+* Swift ``4.0`` for Xcode 10.2 and above.
+* Swift ``3.0`` for Xcode 8.3 and above.
+* Swift ``2.3`` for Xcode 8.2 and below.
diff --git a/Help/variable/CMAKE_VS_DEVENV_COMMAND.rst b/Help/variable/CMAKE_VS_DEVENV_COMMAND.rst
index 51b42dd4b..f109a9eda 100644
--- a/Help/variable/CMAKE_VS_DEVENV_COMMAND.rst
+++ b/Help/variable/CMAKE_VS_DEVENV_COMMAND.rst
@@ -1,7 +1,7 @@
CMAKE_VS_DEVENV_COMMAND
-----------------------
-The generators for :generator:`Visual Studio 8 2005` and above set this
+The generators for :generator:`Visual Studio 9 2008` 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.
diff --git a/Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst b/Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst
index 6d196f917..ceedf2861 100644
--- a/Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst
+++ b/Help/variable/CMAKE_VS_INTEL_Fortran_PROJECT_VERSION.rst
@@ -1,7 +1,7 @@
CMAKE_VS_INTEL_Fortran_PROJECT_VERSION
--------------------------------------
-When generating for :generator:`Visual Studio 8 2005` or greater with the Intel
+When generating for :generator:`Visual Studio 9 2008` 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_PLATFORM_NAME.rst b/Help/variable/CMAKE_VS_PLATFORM_NAME.rst
index a532743fb..7a4642a31 100644
--- a/Help/variable/CMAKE_VS_PLATFORM_NAME.rst
+++ b/Help/variable/CMAKE_VS_PLATFORM_NAME.rst
@@ -1,8 +1,10 @@
CMAKE_VS_PLATFORM_NAME
----------------------
-Visual Studio target platform name.
+Visual Studio target platform name used by the current generator.
VS 8 and above allow project files to specify a target platform.
CMake provides the name of the chosen platform in this variable.
See the :variable:`CMAKE_GENERATOR_PLATFORM` variable for details.
+
+See also the :variable:`CMAKE_VS_PLATFORM_NAME_DEFAULT` variable.
diff --git a/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE.rst b/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE.rst
index 9b59c52a6..99ac90ddc 100644
--- a/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE.rst
+++ b/Help/variable/CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE.rst
@@ -3,8 +3,8 @@ CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE
Visual Studio preferred tool architecture.
-The :ref:`Visual Studio Generators` for VS 2013 and above support optional
-selection of a 64-bit toolchain on 64-bit hosts by specifying a ``host=x64``
-value in the :variable:`CMAKE_GENERATOR_TOOLSET` option. CMake provides
-the selected toolchain architecture preference in this variable (either
-``x64`` or empty).
+The :ref:`Visual Studio Generators` for VS 2013 and above support using
+either the 32-bit or 64-bit host toolchains by specifying a ``host=x86``
+or ``host=x64`` value in the :variable:`CMAKE_GENERATOR_TOOLSET` option.
+CMake provides the selected toolchain architecture preference in this
+variable (``x86``, ``x64``, or empty).
diff --git a/Help/variable/CMAKE_XCODE_GENERATE_SCHEME.rst b/Help/variable/CMAKE_XCODE_GENERATE_SCHEME.rst
index c9fcc92e0..5b1a003f0 100644
--- a/Help/variable/CMAKE_XCODE_GENERATE_SCHEME.rst
+++ b/Help/variable/CMAKE_XCODE_GENERATE_SCHEME.rst
@@ -1,11 +1,10 @@
CMAKE_XCODE_GENERATE_SCHEME
---------------------------
-If enabled, the Xcode generator will generate schema files. Those are
+If enabled, the :generator:`Xcode` generator will generate schema files. These
are useful to invoke analyze, archive, build-for-testing and test
actions from the command line.
-.. note::
-
- The Xcode Schema Generator is still experimental and subject to
- change.
+This variable initializes the
+:prop_tgt:`XCODE_GENERATE_SCHEME`
+target property on all targets.
diff --git a/Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst b/Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst
index 5dad6bd68..30ae23638 100644
--- a/Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst
+++ b/Help/variable/CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION.rst
@@ -5,7 +5,7 @@ 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
+file takes place. Some CPack generators, like ``NSIS``, enforce this
internally. This variable triggers the definition
of :variable:`CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION` when CPack
runs.
diff --git a/Help/variable/CTEST_CUSTOM_WARNING_EXCEPTION.rst b/Help/variable/CTEST_CUSTOM_WARNING_EXCEPTION.rst
index 36fa37d92..a03d47342 100644
--- a/Help/variable/CTEST_CUSTOM_WARNING_EXCEPTION.rst
+++ b/Help/variable/CTEST_CUSTOM_WARNING_EXCEPTION.rst
@@ -2,6 +2,6 @@ CTEST_CUSTOM_WARNING_EXCEPTION
------------------------------
A list of regular expressions which will be used to exclude when detecting
-warning messages in build outputs by the :command:`ctest_test` command.
+warning messages in build outputs by the :command:`ctest_build` command.
.. include:: CTEST_CUSTOM_XXX.txt
diff --git a/Help/variable/CTEST_CUSTOM_WARNING_MATCH.rst b/Help/variable/CTEST_CUSTOM_WARNING_MATCH.rst
index a35be96b5..18aa6b31d 100644
--- a/Help/variable/CTEST_CUSTOM_WARNING_MATCH.rst
+++ b/Help/variable/CTEST_CUSTOM_WARNING_MATCH.rst
@@ -2,6 +2,6 @@ CTEST_CUSTOM_WARNING_MATCH
--------------------------
A list of regular expressions which will be used to detect warning messages in
-build outputs by the :command:`ctest_test` command.
+build outputs by the :command:`ctest_build` command.
.. include:: CTEST_CUSTOM_XXX.txt
diff --git a/Help/variable/CTEST_SCP_COMMAND.rst b/Help/variable/CTEST_SCP_COMMAND.rst
index 0f128b14a..19ea8b33d 100644
--- a/Help/variable/CTEST_SCP_COMMAND.rst
+++ b/Help/variable/CTEST_SCP_COMMAND.rst
@@ -1,5 +1,4 @@
CTEST_SCP_COMMAND
-----------------
-Specify the CTest ``SCPCommand`` setting
-in a :manual:`ctest(1)` dashboard client script.
+Legacy option. Not used.
diff --git a/Help/variable/CTEST_TRIGGER_SITE.rst b/Help/variable/CTEST_TRIGGER_SITE.rst
index de9242807..a50e405cc 100644
--- a/Help/variable/CTEST_TRIGGER_SITE.rst
+++ b/Help/variable/CTEST_TRIGGER_SITE.rst
@@ -1,5 +1,4 @@
CTEST_TRIGGER_SITE
------------------
-Specify the CTest ``TriggerSite`` setting
-in a :manual:`ctest(1)` dashboard client script.
+Legacy option. Not used.
diff --git a/Help/variable/CTEST_UPDATE_VERSION_ONLY.rst b/Help/variable/CTEST_UPDATE_VERSION_ONLY.rst
index e646e6eea..a862baa14 100644
--- a/Help/variable/CTEST_UPDATE_VERSION_ONLY.rst
+++ b/Help/variable/CTEST_UPDATE_VERSION_ONLY.rst
@@ -1,5 +1,5 @@
CTEST_UPDATE_VERSION_ONLY
-------------------------
-Specify the CTest ``UpdateVersionOnly`` setting
+Specify the CTest :ref:`UpdateVersionOnly <UpdateVersionOnly>` setting
in a :manual:`ctest(1)` dashboard client script.
diff --git a/Help/variable/ENV.rst b/Help/variable/ENV.rst
index 368152aeb..2b439342e 100644
--- a/Help/variable/ENV.rst
+++ b/Help/variable/ENV.rst
@@ -1,7 +1,12 @@
ENV
---
-Access environment variables.
+Operator to read environment variables.
-Use the syntax ``$ENV{VAR}`` to read environment variable ``VAR``. See also
-the :command:`set` command to set ``ENV{VAR}``.
+Use the syntax ``$ENV{VAR}`` to read environment variable ``VAR``.
+
+To test whether an environment variable is defined, use the signature
+``if(DEFINED ENV{<name>})`` of the :command:`if` command.
+
+See the :command:`set` and :command:`unset` commands to see how to
+write or remove environment variables.
diff --git a/Help/variable/GHS-MULTI.rst b/Help/variable/GHS-MULTI.rst
index 0f91be8ad..fe3b17e18 100644
--- a/Help/variable/GHS-MULTI.rst
+++ b/Help/variable/GHS-MULTI.rst
@@ -1,4 +1,4 @@
GHS-MULTI
---------
-True when using Green Hills MULTI
+``True`` when using :generator:`Green Hills MULTI` generator.
diff --git a/Help/variable/LIBRARY_OUTPUT_PATH.rst b/Help/variable/LIBRARY_OUTPUT_PATH.rst
index ba02911e6..bb4328f5b 100644
--- a/Help/variable/LIBRARY_OUTPUT_PATH.rst
+++ b/Help/variable/LIBRARY_OUTPUT_PATH.rst
@@ -5,5 +5,5 @@ Old library location variable.
The target properties :prop_tgt:`ARCHIVE_OUTPUT_DIRECTORY`,
:prop_tgt:`LIBRARY_OUTPUT_DIRECTORY`, and :prop_tgt:`RUNTIME_OUTPUT_DIRECTORY`
-supercede this variable for a target if they are set. Library targets are
+supersede 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
index 22a087a77..ca8775cb3 100644
--- a/Help/variable/MSVC.rst
+++ b/Help/variable/MSVC.rst
@@ -1,8 +1,8 @@
MSVC
----
-``True`` when using Microsoft Visual C++.
-
-Set to ``true`` when the compiler is some version of Microsoft Visual C++.
+Set to ``true`` when the compiler is some version of Microsoft Visual
+C++ or another compiler simulating Visual C++. Any compiler defining
+``_MSC_VER`` is considered simulating Visual C++.
See also the :variable:`MSVC_VERSION` variable.
diff --git a/Help/variable/MSVC_VERSION.rst b/Help/variable/MSVC_VERSION.rst
index 8932147c6..45df37fa0 100644
--- a/Help/variable/MSVC_VERSION.rst
+++ b/Help/variable/MSVC_VERSION.rst
@@ -2,16 +2,23 @@ MSVC_VERSION
------------
The version of Microsoft Visual C/C++ being used if any.
+If a compiler simulating Visual C++ is being used, this variable is set
+to the toolset version simulated as given by the ``_MSC_VER``
+preprocessor definition.
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
- 1910 = VS 15.0
+ 1200 = VS 6.0
+ 1300 = VS 7.0
+ 1310 = VS 7.1
+ 1400 = VS 8.0 (v80 toolset)
+ 1500 = VS 9.0 (v90 toolset)
+ 1600 = VS 10.0 (v100 toolset)
+ 1700 = VS 11.0 (v110 toolset)
+ 1800 = VS 12.0 (v120 toolset)
+ 1900 = VS 14.0 (v140 toolset)
+ 1910-1919 = VS 15.0 (v141 toolset)
+ 1920-1929 = VS 16.0 (v142 toolset)
+
+See also the :variable:`CMAKE_<LANG>_COMPILER_VERSION` and
+:variable:`MSVC_TOOLSET_VERSION` variable.
diff --git a/Help/variable/PROJECT_DESCRIPTION.rst b/Help/variable/PROJECT_DESCRIPTION.rst
index 05ede8fcc..2833e1101 100644
--- a/Help/variable/PROJECT_DESCRIPTION.rst
+++ b/Help/variable/PROJECT_DESCRIPTION.rst
@@ -3,4 +3,7 @@ PROJECT_DESCRIPTION
Short project description given to the project command.
-This is the description given to the most recent :command:`project` command.
+This is the description given to the most recently called :command:`project`
+command in the current directory scope or above. To obtain the description
+of the top level project, see the :variable:`CMAKE_PROJECT_DESCRIPTION`
+variable.
diff --git a/Help/variable/PROJECT_NAME.rst b/Help/variable/PROJECT_NAME.rst
index 61aa8bc00..672680a71 100644
--- a/Help/variable/PROJECT_NAME.rst
+++ b/Help/variable/PROJECT_NAME.rst
@@ -3,4 +3,6 @@ PROJECT_NAME
Name of the project given to the project command.
-This is the name given to the most recent :command:`project` command.
+This is the name given to the most recently called :command:`project`
+command in the current directory scope or above. To obtain the name of
+the top level project, see the :variable:`CMAKE_PROJECT_NAME` variable.
diff --git a/Help/variable/UNIX.rst b/Help/variable/UNIX.rst
index 0877b7c07..49d866838 100644
--- a/Help/variable/UNIX.rst
+++ b/Help/variable/UNIX.rst
@@ -1,7 +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.
-:variable:`APPLE` and :variable:`CYGWIN`).
+Set to ``True`` when the target system is UNIX or UNIX-like
+(e.g. :variable:`APPLE` and :variable:`CYGWIN`). The
+:variable:`CMAKE_SYSTEM_NAME` variable should be queried if
+a more specific understanding of the target system is required.
diff --git a/Help/variable/WIN32.rst b/Help/variable/WIN32.rst
index 218906955..78ab77279 100644
--- a/Help/variable/WIN32.rst
+++ b/Help/variable/WIN32.rst
@@ -1,6 +1,4 @@
WIN32
-----
-``True`` on Windows systems, including Win64.
-
-Set to ``true`` when the target system is Windows.
+Set to ``True`` when the target system is Windows, including Win64.
diff --git a/Help/variable/XCODE_VERSION.rst b/Help/variable/XCODE_VERSION.rst
index b85d41e91..9caf19a41 100644
--- a/Help/variable/XCODE_VERSION.rst
+++ b/Help/variable/XCODE_VERSION.rst
@@ -3,5 +3,5 @@ XCODE_VERSION
Version of Xcode (:generator:`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``).
+Under the :generator:`Xcode` generator, this is the version of Xcode
+as specified in ``Xcode.app/Contents/version.plist`` (such as ``3.1.2``).
diff --git a/Modules/AddFileDependencies.cmake b/Modules/AddFileDependencies.cmake
index fdd843266..598a52fa9 100644
--- a/Modules/AddFileDependencies.cmake
+++ b/Modules/AddFileDependencies.cmake
@@ -1,23 +1,28 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# AddFileDependencies
-# -------------------
-#
-# ADD_FILE_DEPENDENCIES(source_file depend_files...)
-#
-# Adds the given files as dependencies to source_file
+#[=======================================================================[.rst:
+AddFileDependencies
+-------------------
+
+Add dependencies to a source file.
+
+.. code-block:: cmake
+
+ ADD_FILE_DEPENDENCIES(<source> <files>)
+
+Adds the given ``<files>`` to the dependencies of file ``<source>``.
+#]=======================================================================]
macro(ADD_FILE_DEPENDENCIES _file)
- get_source_file_property(_deps ${_file} OBJECT_DEPENDS)
- if (_deps)
- set(_deps ${_deps} ${ARGN})
- else ()
- set(_deps ${ARGN})
- endif ()
+ 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}")
+ set_source_files_properties(${_file} PROPERTIES OBJECT_DEPENDS "${_deps}")
endmacro()
diff --git a/Modules/AndroidTestUtilities.cmake b/Modules/AndroidTestUtilities.cmake
index 62d04f3ef..e333cdbc6 100644
--- a/Modules/AndroidTestUtilities.cmake
+++ b/Modules/AndroidTestUtilities.cmake
@@ -40,7 +40,7 @@ Module Functions
.. command:: android_add_test_data
- ::
+ .. code-block:: cmake
android_add_test_data(<test-name>
[FILES <files>...] [FILES_DEST <device-dir>]
diff --git a/Modules/AndroidTestUtilities/PushToAndroidDevice.cmake b/Modules/AndroidTestUtilities/PushToAndroidDevice.cmake
index 04529b10a..fccff6725 100644
--- a/Modules/AndroidTestUtilities/PushToAndroidDevice.cmake
+++ b/Modules/AndroidTestUtilities/PushToAndroidDevice.cmake
@@ -31,7 +31,7 @@ function(android_push_test_files_to_device)
set(out_var ${out_var} PARENT_SCOPE)
if(res_var)
string(REGEX REPLACE ";" " " com "${ARGN}")
- message(FATAL_ERROR "Error occured during adb command: adb ${com}\nError: ${err_var}.")
+ message(FATAL_ERROR "Error occurred during adb command: adb ${com}\nError: ${err_var}.")
endif()
endfunction()
diff --git a/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
index bc78016df..a6e5fda38 100644
--- a/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
+++ b/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in
@@ -18,14 +18,20 @@ else()
endif()
endif()
+
+# if the installed project requested no architecture check, don't perform the check
+if("@CVF_ARCH_INDEPENDENT@")
+ return()
+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()
+ 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)
+ 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
index de4a23af0..43fc4d0b1 100644
--- a/Modules/BasicConfigVersion-ExactVersion.cmake.in
+++ b/Modules/BasicConfigVersion-ExactVersion.cmake.in
@@ -34,9 +34,14 @@ if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
endif()
+# if the installed project requested no architecture check, don't perform the check
+if("@CVF_ARCH_INDEPENDENT@")
+ return()
+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()
+ return()
endif()
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
diff --git a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
index a32245dd5..8c3b6a212 100644
--- a/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
+++ b/Modules/BasicConfigVersion-SameMajorVersion.cmake.in
@@ -33,9 +33,14 @@ else()
endif()
+# if the installed project requested no architecture check, don't perform the check
+if("@CVF_ARCH_INDEPENDENT@")
+ return()
+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()
+ return()
endif()
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
diff --git a/Modules/BundleUtilities.cmake b/Modules/BundleUtilities.cmake
index 121a8f015..f94fc5cff 100644
--- a/Modules/BundleUtilities.cmake
+++ b/Modules/BundleUtilities.cmake
@@ -1,223 +1,247 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-#
-# As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
-# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
-#
-# ::
-#
-# 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.
-#
-# As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
-# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
-#
-# ::
-#
-# 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.
-#
-# As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
-# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
-#
-# ::
-#
-# 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.
-#
-# As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
-# which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
-#
-# ::
-#
-# 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.
+#[=======================================================================[.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:
+
+.. code-block:: cmake
+
+ 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``.
+
+DO NOT USE THESE FUNCTIONS AT CONFIGURE TIME (from ``CMakeLists.txt``)!
+Instead, invoke them from an :command:`install(CODE)` or
+:command:`install(SCRIPT)` rule.
+
+.. code-block:: cmake
+
+ fixup_bundle(<app> <libs> <dirs>)
+
+Fix up ``<app>`` 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.
+
+As an optional parameter (``IGNORE_ITEM``) a list of file names can be passed,
+which are then ignored
+(e.g. ``IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe"``).
+
+.. code-block:: cmake
+
+ 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>``.
+
+.. code-block:: cmake
+
+ verify_app(<app>)
+
+Verifies that an application ``<app>`` appears valid based on running
+analysis tools on it. Calls :command:`message(FATAL_ERROR)` if the application
+is not verified.
+
+As an optional parameter (``IGNORE_ITEM``) a list of file names can be passed,
+which are then ignored
+(e.g. ``IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe"``)
+
+.. code-block:: cmake
+
+ 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.
+
+.. code-block:: cmake
+
+ 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.
+
+.. code-block:: cmake
+
+ 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>``.
+
+.. code-block:: cmake
+
+ get_bundle_all_executables(<bundle> <exes_var>)
+
+Scans ``<bundle>`` bundle recursively for all ``<exes_var>`` executable
+files and accumulates them into a variable.
+
+.. code-block:: cmake
+
+ get_item_key(<item> <key_var>)
+
+Given ``<item>`` file name, generate ``<key_var>`` 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.
+
+.. code-block:: cmake
+
+ clear_bundle_keys(<keys_var>)
+
+Loop over the ``<keys_var>`` 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.
+
+.. code-block:: cmake
+
+ set_bundle_key_values(<keys_var> <context> <item> <exepath> <dirs>
+ <copyflag> [<rpaths>])
+
+Add ``<keys_var>`` key to the list (if necessary) for the given item.
+If added, also set all the variables associated with that key.
+
+.. code-block:: cmake
+
+ get_bundle_keys(<app> <libs> <dirs> <keys_var>)
+
+Loop over all the executable and library files within ``<app>`` 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.
+
+As an optional parameter (``IGNORE_ITEM``) a list of file names can be passed,
+which are then ignored
+(e.g. ``IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe"``)
+
+.. code-block:: cmake
+
+ 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>``.
+
+.. code-block:: cmake
+
+ 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.
+
+.. code-block:: cmake
+
+ 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.
+
+.. code-block:: cmake
+
+ 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.
+
+As an optional parameter (``IGNORE_ITEM``) a list of file names can be passed,
+which are then ignored
+(e.g. ``IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe"``)
+
+.. code-block:: cmake
+
+ verify_bundle_symlinks(<bundle> <result_var> <info_var>)
+
+Verifies that any symlinks found in the ``<bundle>`` 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.
+#]=======================================================================]
+
+function(_warn_cmp0080)
+ cmake_policy(GET_WARNING CMP0080 _cmp0080_warning)
+ message(AUTHOR_WARNING "${_cmp0080_warning}\n")
+endfunction()
+
+# Do not include this module at configure time!
+if(DEFINED CMAKE_GENERATOR)
+ cmake_policy(GET CMP0080 _BundleUtilities_CMP0080)
+ if(_BundleUtilities_CMP0080 STREQUAL "NEW")
+ message(FATAL_ERROR "BundleUtilities cannot be included at configure time!")
+ elseif(NOT _BundleUtilities_CMP0080 STREQUAL "OLD" AND NOT _CMP0080_SUPPRESS_WARNING)
+ _warn_cmp0080()
+ endif()
+endif()
# The functions defined in this file depend on the get_prerequisites function
# (and possibly others) found in:
@@ -421,7 +445,12 @@ function(get_item_rpaths item rpaths_var)
execute_process(
COMMAND "${otool_cmd}" -l "${item}"
OUTPUT_VARIABLE load_cmds_ov
+ RESULT_VARIABLE otool_rv
+ ERROR_VARIABLE otool_ev
)
+ if(NOT otool_rv STREQUAL "0")
+ message(FATAL_ERROR "otool -l failed: ${otool_rv}\n${otool_ev}")
+ endif()
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}")
@@ -692,6 +721,9 @@ function(link_resolved_item_into_bundle resolved_item resolved_embedded_item)
else()
get_filename_component(target_dir "${resolved_embedded_item}" DIRECTORY)
file(RELATIVE_PATH symlink_target "${target_dir}" "${resolved_item}")
+ if (NOT EXISTS "${target_dir}")
+ file(MAKE_DIRECTORY "${target_dir}")
+ endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${symlink_target}" "${resolved_embedded_item}")
endif()
endfunction()
@@ -852,9 +884,13 @@ function(fixup_bundle_item resolved_embedded_item exepath dirs)
execute_process(COMMAND chmod u+w "${resolved_embedded_item}")
endif()
+ # CMAKE_INSTALL_NAME_TOOL may not be set if executed in script mode
+ # Duplicated from CMakeFindBinUtils.cmake
+ find_program(CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+
# Only if install_name_tool supports -delete_rpath:
#
- execute_process(COMMAND install_name_tool
+ execute_process(COMMAND ${CMAKE_INSTALL_NAME_TOOL}
OUTPUT_VARIABLE install_name_tool_usage
ERROR_VARIABLE install_name_tool_usage
)
@@ -872,7 +908,7 @@ function(fixup_bundle_item resolved_embedded_item exepath dirs)
# to install_name_tool:
#
if(changes)
- set(cmd install_name_tool ${changes} "${resolved_embedded_item}")
+ set(cmd ${CMAKE_INSTALL_NAME_TOOL} ${changes} "${resolved_embedded_item}")
execute_process(COMMAND ${cmd} RESULT_VARIABLE install_name_tool_result)
if(NOT install_name_tool_result EQUAL 0)
string(REPLACE ";" "' '" msg "'${cmd}'")
diff --git a/Modules/CMakeASMCompiler.cmake.in b/Modules/CMakeASMCompiler.cmake.in
index 7b94d0f6e..b8e09fefa 100644
--- a/Modules/CMakeASMCompiler.cmake.in
+++ b/Modules/CMakeASMCompiler.cmake.in
@@ -5,10 +5,14 @@ set(CMAKE_ASM@ASM_DIALECT@_COMPILER_AR "@_CMAKE_ASM_COMPILER_AR@")
set(CMAKE_RANLIB "@CMAKE_RANLIB@")
set(CMAKE_ASM@ASM_DIALECT@_COMPILER_RANLIB "@_CMAKE_ASM_COMPILER_RANLIB@")
set(CMAKE_LINKER "@CMAKE_LINKER@")
+set(CMAKE_MT "@CMAKE_MT@")
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_VERSION "@_CMAKE_ASM_COMPILER_VERSION@")
set(CMAKE_ASM@ASM_DIALECT@_COMPILER_ENV_VAR "@_CMAKE_ASM_COMPILER_ENV_VAR@")
+@_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID@
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)
+@CMAKE_ASM_COMPILER_CUSTOM_CODE@
diff --git a/Modules/CMakeASMInformation.cmake b/Modules/CMakeASMInformation.cmake
index f7cf900fd..6b7373067 100644
--- a/Modules/CMakeASMInformation.cmake
+++ b/Modules/CMakeASMInformation.cmake
@@ -29,15 +29,15 @@ if(NOT _INCLUDED_FILE)
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)
+ include(Platform/${CMAKE_EFFECTIVE_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)
+ include(Platform/${CMAKE_EFFECTIVE_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)
+include(Platform/${CMAKE_EFFECTIVE_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)
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
endif()
# This should be included before the _INIT variables are
@@ -67,38 +67,7 @@ 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}")
-foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
- string(STRIP "${CMAKE_ASM${ASM_DIALECT}_FLAGS${c}_INIT}" CMAKE_ASM${ASM_DIALECT}_FLAGS${c}_INIT)
-endforeach()
-
-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)
- get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
- # default build type is none
- if(NOT _GENERATOR_IS_MULTI_CONFIG AND 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()
- unset(_GENERATOR_IS_MULTI_CONFIG)
- 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
- )
-
+cmake_initialize_per_config_variable(CMAKE_ASM${ASM_DIALECT}_FLAGS "Flags used by the ASM${ASM_DIALECT} compiler")
if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT)
set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
diff --git a/Modules/CMakeASM_NASMInformation.cmake b/Modules/CMakeASM_NASMInformation.cmake
index 1e3c60845..cb793e7c2 100644
--- a/Modules/CMakeASM_NASMInformation.cmake
+++ b/Modules/CMakeASM_NASMInformation.cmake
@@ -28,7 +28,9 @@ if(NOT CMAKE_ASM_NASM_OBJECT_FORMAT)
endif()
endif()
-set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <INCLUDES> <FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")
+if(NOT CMAKE_ASM_NASM_COMPILE_OBJECT)
+ set(CMAKE_ASM_NASM_COMPILE_OBJECT "<CMAKE_ASM_NASM_COMPILER> <INCLUDES> <FLAGS> -f ${CMAKE_ASM_NASM_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")
+endif()
# Load the generic ASMInformation file:
set(ASM_DIALECT "_NASM")
diff --git a/Modules/CMakeAddFortranSubdirectory.cmake b/Modules/CMakeAddFortranSubdirectory.cmake
index 4649f35a1..2613569d1 100644
--- a/Modules/CMakeAddFortranSubdirectory.cmake
+++ b/Modules/CMakeAddFortranSubdirectory.cmake
@@ -1,46 +1,47 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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".
+#[=======================================================================[.rst:
+CMakeAddFortranSubdirectory
+---------------------------
+
+Add a fortran-only subdirectory, find a fortran compiler, and build.
+
+The ``cmake_add_fortran_subdirectory`` function adds a subdirectory
+to a project that contains a fortran-only subproject. 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 :variable:`BUILD_SHARED_LIBS` is turned on in
+the project. In addition the :variable:`CMAKE_GNUtoMS` option is set
+to on, so that Microsoft ``.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``.
+#]=======================================================================]
set(_MS_MINGW_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
include(CheckLanguage)
diff --git a/Modules/CMakeAddNewLanguage.txt b/Modules/CMakeAddNewLanguage.txt
index 612e1a3a5..b0be590ae 100644
--- a/Modules/CMakeAddNewLanguage.txt
+++ b/Modules/CMakeAddNewLanguage.txt
@@ -1,7 +1,7 @@
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
+these files in :variable:`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,
@@ -17,17 +17,15 @@ 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
+ 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 "")
+ 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
-
-
+ 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
index 5d86d7313..775a5137d 100644
--- a/Modules/CMakeBackwardCompatibilityC.cmake
+++ b/Modules/CMakeBackwardCompatibilityC.cmake
@@ -59,9 +59,6 @@ if(NOT CMAKE_SKIP_COMPATIBILITY_TESTS)
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)
@@ -72,7 +69,6 @@ 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
index cbd5ea76c..02744a985 100644
--- a/Modules/CMakeBackwardCompatibilityCXX.cmake
+++ b/Modules/CMakeBackwardCompatibilityCXX.cmake
@@ -1,29 +1,27 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.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)
+#]=======================================================================]
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()
diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in
index 974a57927..9b8d423a6 100644
--- a/Modules/CMakeCCompiler.cmake.in
+++ b/Modules/CMakeCCompiler.cmake.in
@@ -2,6 +2,7 @@ set(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@")
set(CMAKE_C_COMPILER_ARG1 "@CMAKE_C_COMPILER_ARG1@")
set(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@")
set(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@")
+set(CMAKE_C_COMPILER_VERSION_INTERNAL "@CMAKE_C_COMPILER_VERSION_INTERNAL@")
set(CMAKE_C_COMPILER_WRAPPER "@CMAKE_C_COMPILER_WRAPPER@")
set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "@CMAKE_C_STANDARD_COMPUTED_DEFAULT@")
set(CMAKE_C_COMPILE_FEATURES "@CMAKE_C_COMPILE_FEATURES@")
@@ -11,14 +12,17 @@ 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_COMPILER_FRONTEND_VARIANT "@CMAKE_C_COMPILER_FRONTEND_VARIANT@")
set(CMAKE_C_SIMULATE_VERSION "@CMAKE_C_SIMULATE_VERSION@")
+@_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID@
@SET_MSVC_C_ARCHITECTURE_ID@
-@SET_CMAKE_XCODE_CURRENT_ARCH@
+@SET_CMAKE_XCODE_ARCHS@
set(CMAKE_AR "@CMAKE_AR@")
set(CMAKE_C_COMPILER_AR "@CMAKE_C_COMPILER_AR@")
set(CMAKE_RANLIB "@CMAKE_RANLIB@")
set(CMAKE_C_COMPILER_RANLIB "@CMAKE_C_COMPILER_RANLIB@")
set(CMAKE_LINKER "@CMAKE_LINKER@")
+set(CMAKE_MT "@CMAKE_MT@")
set(CMAKE_COMPILER_IS_GNUCC @CMAKE_COMPILER_IS_GNUCC@)
set(CMAKE_C_COMPILER_LOADED 1)
set(CMAKE_C_COMPILER_WORKS @CMAKE_C_COMPILER_WORKS@)
@@ -66,6 +70,7 @@ endif()
@CMAKE_C_SYSROOT_FLAG_CODE@
@CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG_CODE@
+set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES@")
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@")
diff --git a/Modules/CMakeCCompilerABI.c b/Modules/CMakeCCompilerABI.c
index 55f9a9b51..08cf39bd8 100644
--- a/Modules/CMakeCCompilerABI.c
+++ b/Modules/CMakeCCompilerABI.c
@@ -1,9 +1,9 @@
#ifdef __cplusplus
-#error "A C++ compiler has been selected for C."
+# error "A C++ compiler has been selected for C."
#endif
#ifdef __CLASSIC_C__
-#define const
+# define const
#endif
#include "CMakeCompilerABI.h"
diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in
index 95184c982..2f6bdb4a7 100644
--- a/Modules/CMakeCCompilerId.c.in
+++ b/Modules/CMakeCCompilerId.c.in
@@ -34,7 +34,8 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
@CMAKE_C_COMPILER_ID_ERROR_FOR_TEST@
#if !defined(__STDC__)
-# if defined(_MSC_VER) && !defined(__clang__)
+# if (defined(_MSC_VER) && !defined(__clang__)) \
+ || (defined(__ibmxl__) || defined(__IBMC__))
# define C_DIALECT "90"
# else
# define C_DIALECT
@@ -67,6 +68,9 @@ int main(int argc, char* argv[])
#ifdef COMPILER_VERSION_MAJOR
require += info_version[argc];
#endif
+#ifdef COMPILER_VERSION_INTERNAL
+ require += info_version_internal[argc];
+#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
diff --git a/Modules/CMakeCInformation.cmake b/Modules/CMakeCInformation.cmake
index 71aadb474..df43559c9 100644
--- a/Modules/CMakeCInformation.cmake
+++ b/Modules/CMakeCInformation.cmake
@@ -35,21 +35,21 @@ 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)
+ include(Platform/${CMAKE_EFFECTIVE_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)
+ include(Platform/${CMAKE_EFFECTIVE_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
+ include(Platform/${CMAKE_EFFECTIVE_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}
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
endif ()
@@ -102,30 +102,7 @@ endif()
set(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
-foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
- string(STRIP "${CMAKE_C_FLAGS${c}_INIT}" CMAKE_C_FLAGS${c}_INIT)
-endforeach()
-
-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)
- get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
- # default build type is none
- if(NOT _GENERATOR_IS_MULTI_CONFIG AND 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()
- unset(_GENERATOR_IS_MULTI_CONFIG)
- 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()
+cmake_initialize_per_config_variable(CMAKE_C_FLAGS "Flags used by the C compiler")
if(CMAKE_C_STANDARD_LIBRARIES_INIT)
set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
@@ -208,13 +185,6 @@ 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/CMakeCSharpCompiler.cmake.in b/Modules/CMakeCSharpCompiler.cmake.in
index 5ecc4800b..3d49b6bc9 100644
--- a/Modules/CMakeCSharpCompiler.cmake.in
+++ b/Modules/CMakeCSharpCompiler.cmake.in
@@ -2,6 +2,7 @@ set(CMAKE_CSharp_COMPILER "@CMAKE_CSharp_COMPILER@")
set(CMAKE_CSharp_COMPILER_ID "@CMAKE_CSharp_COMPILER_ID@")
set(CMAKE_CSharp_COMPILER_VERSION "@CMAKE_CSharp_COMPILER_VERSION@")
+set(CMAKE_CSharp_COMPILER_LOADED 1)
set(CMAKE_CSharp_COMPILER_WORKS "@CMAKE_CSharp_COMPILER_WORKS@")
set(CMAKE_CSharp_COMPILER_ID_RUN "@CMAKE_CSharp_COMPILER_ID_RUN@")
diff --git a/Modules/CMakeCSharpInformation.cmake b/Modules/CMakeCSharpInformation.cmake
index f71dcefe9..48e1a1e5f 100644
--- a/Modules/CMakeCSharpInformation.cmake
+++ b/Modules/CMakeCSharpInformation.cmake
@@ -10,7 +10,7 @@ get_filename_component(CMAKE_BASE_NAME "${CMAKE_CSharp_COMPILER}" NAME_WE)
set(CMAKE_BUILD_TYPE_INIT Debug)
-set(CMAKE_CSharp_FLAGS_INIT "/define:TRACE /langversion:3 /nowin32manifest")
+set(CMAKE_CSharp_FLAGS_INIT "/define:TRACE /langversion:3")
set(CMAKE_CSharp_FLAGS_DEBUG_INIT "/debug:full /optimize- /warn:3 /errorreport:prompt /define:DEBUG")
set(CMAKE_CSharp_FLAGS_RELEASE_INIT "/debug:none /optimize /warn:1 /errorreport:queue")
set(CMAKE_CSharp_FLAGS_RELWITHDEBINFO_INIT "/debug:full /optimize-")
@@ -44,23 +44,8 @@ endif()
# use _INIT variables so that this only happens the first time
# and you can set these flags in the cmake cache
set(CMAKE_CSharp_FLAGS_INIT "$ENV{CSFLAGS} ${CMAKE_CSharp_FLAGS_INIT}")
-# avoid just having a space as the initial value for the cache
-if(CMAKE_CSharp_FLAGS_INIT STREQUAL " ")
- set(CMAKE_CSharp_FLAGS_INIT)
-endif()
-set (CMAKE_CSharp_FLAGS "${CMAKE_CSharp_FLAGS_INIT}" CACHE STRING
- "Flags used by the C# compiler during all build types.")
-if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
- set (CMAKE_CSharp_FLAGS_DEBUG "${CMAKE_CSharp_FLAGS_DEBUG_INIT}" CACHE STRING
- "Flags used by the C# compiler during debug builds.")
- set (CMAKE_CSharp_FLAGS_MINSIZEREL "${CMAKE_CSharp_FLAGS_MINSIZEREL_INIT}" CACHE STRING
- "Flags used by the C# compiler during release builds for minimum size.")
- set (CMAKE_CSharp_FLAGS_RELEASE "${CMAKE_CSharp_FLAGS_RELEASE_INIT}" CACHE STRING
- "Flags used by the C# compiler during release builds.")
- set (CMAKE_CSharp_FLAGS_RELWITHDEBINFO "${CMAKE_CSharp_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
- "Flags used by the C# compiler during release builds with debug info.")
-endif()
+cmake_initialize_per_config_variable(CMAKE_CSharp_FLAGS "Flags used by the C# compiler")
if(CMAKE_CSharp_STANDARD_LIBRARIES_INIT)
set(CMAKE_CSharp_STANDARD_LIBRARIES "${CMAKE_CSharp_STANDARD_LIBRARIES_INIT}"
@@ -71,49 +56,12 @@ endif()
# set missing flags (if they are not defined). This is needed in the
# unlikely case that you have only C# and no C/C++ targets in your
# project.
-if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS)
- set(CMAKE_SHARED_LINKER_FLAGS "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_DEBUG)
- set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_RELEASE)
- set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL)
- set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO)
- set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "" CACHE STRING "" FORCE)
-endif()
-
-if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS)
- set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_DEBUG)
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_RELEASE)
- set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_MINSIZEREL)
- set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "" CACHE STRING "" FORCE)
-endif()
-if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO)
- set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "" CACHE STRING "" FORCE)
-endif()
+cmake_initialize_per_config_variable(CMAKE_EXE_LINKER_FLAGS "Flags used by the linker")
+cmake_initialize_per_config_variable(CMAKE_SHARED_LINKER_FLAGS "Flags used by the linker during the creation of shared libraries")
set(CMAKE_CSharp_CREATE_SHARED_LIBRARY "CSharp_NO_CREATE_SHARED_LIBRARY")
set(CMAKE_CSharp_CREATE_SHARED_MODULE "CSharp_NO_CREATE_SHARED_MODULE")
set(CMAKE_CSharp_LINK_EXECUTABLE "CSharp_NO_LINK_EXECUTABLE")
-mark_as_advanced(
- CMAKE_CSharp_FLAGS
- CMAKE_CSharp_FLAGS_RELEASE
- CMAKE_CSharp_FLAGS_RELWITHDEBINFO
- CMAKE_CSharp_FLAGS_MINSIZEREL
- CMAKE_CSharp_FLAGS_DEBUG
- )
-
set(CMAKE_CSharp_USE_RESPONSE_FILE_FOR_OBJECTS 1)
set(CMAKE_CSharp_INFORMATION_LOADED 1)
diff --git a/Modules/CMakeCUDACompiler.cmake.in b/Modules/CMakeCUDACompiler.cmake.in
index f524e5f36..711129a39 100644
--- a/Modules/CMakeCUDACompiler.cmake.in
+++ b/Modules/CMakeCUDACompiler.cmake.in
@@ -11,6 +11,7 @@ set(CMAKE_CUDA_SIMULATE_VERSION "@CMAKE_CUDA_SIMULATE_VERSION@")
set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX")
set(CMAKE_CUDA_HOST_COMPILER_ENV_VAR "CUDAHOSTCXX")
+set(CMAKE_CUDA_COMPILER_LOADED 1)
set(CMAKE_CUDA_COMPILER_ID_RUN 1)
set(CMAKE_CUDA_SOURCE_FILE_EXTENSIONS cu)
set(CMAKE_CUDA_LINKER_PREFERENCE 15)
@@ -22,6 +23,10 @@ set(CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES "@CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBR
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES@")
set(CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_CUDA_HOST_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
+set(CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES@")
set(CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES "@CMAKE_CUDA_IMPLICIT_LINK_LIBRARIES@")
set(CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES@")
set(CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "@CMAKE_CUDA_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES@")
+
+set(CMAKE_LINKER "@CMAKE_LINKER@")
+set(CMAKE_MT "@CMAKE_MT@")
diff --git a/Modules/CMakeCUDACompilerABI.cu b/Modules/CMakeCUDACompilerABI.cu
index 99bacefb6..702a7c53a 100644
--- a/Modules/CMakeCUDACompilerABI.cu
+++ b/Modules/CMakeCUDACompilerABI.cu
@@ -1,5 +1,5 @@
#ifndef __CUDACC__
-#error "A C or C++ compiler has been selected for CUDA"
+# error "A C or C++ compiler has been selected for CUDA"
#endif
#include "CMakeCompilerABI.h"
diff --git a/Modules/CMakeCUDACompilerId.cu.in b/Modules/CMakeCUDACompilerId.cu.in
index 018bab7ff..6eda9244c 100644
--- a/Modules/CMakeCUDACompilerId.cu.in
+++ b/Modules/CMakeCUDACompilerId.cu.in
@@ -17,7 +17,9 @@ char const* info_simulate = "INFO" ":" "simulate[" SIMULATE_ID "]";
@CMAKE_CUDA_COMPILER_ID_ERROR_FOR_TEST@
const char* info_language_dialect_default = "INFO" ":" "dialect_default["
-#if __cplusplus > 201402L
+#if __cplusplus > 201703L
+ "20"
+#elif __cplusplus >= 201703L
"17"
#elif __cplusplus >= 201402L
"14"
diff --git a/Modules/CMakeCUDAInformation.cmake b/Modules/CMakeCUDAInformation.cmake
index f4609cd8b..43ae989e0 100644
--- a/Modules/CMakeCUDAInformation.cmake
+++ b/Modules/CMakeCUDAInformation.cmake
@@ -17,9 +17,9 @@ endif()
if(CMAKE_CUDA_COMPILER_ID)
# load a hardware specific file, mostly useful for embedded compilers
if(CMAKE_SYSTEM_PROCESSOR)
- include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CUDA_COMPILER_ID}-CUDA-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_CUDA_COMPILER_ID}-CUDA-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
endif()
- include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CUDA_COMPILER_ID}-CUDA OPTIONAL)
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_CUDA_COMPILER_ID}-CUDA OPTIONAL)
endif()
@@ -74,24 +74,7 @@ endif()
# and you can set these flags in the cmake cache
set(CMAKE_CUDA_FLAGS_INIT "$ENV{CUDAFLAGS} ${CMAKE_CUDA_FLAGS_INIT}")
-foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
- string(STRIP "${CMAKE_CUDA_FLAGS${c}_INIT}" CMAKE_CUDA_FLAGS${c}_INIT)
-endforeach()
-
-set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS_INIT}" CACHE STRING
- "Flags used by the compiler during all build types.")
-
-if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
- set (CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG_INIT}" CACHE STRING
- "Flags used by the compiler during debug builds.")
- set (CMAKE_CUDA_FLAGS_MINSIZEREL "${CMAKE_CUDA_FLAGS_MINSIZEREL_INIT}" CACHE STRING
- "Flags used by the compiler during release builds for minimum size.")
- set (CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE_INIT}" CACHE STRING
- "Flags used by the compiler during release builds.")
- set (CMAKE_CUDA_FLAGS_RELWITHDEBINFO "${CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
- "Flags used by the compiler during release builds with debug info.")
-
-endif()
+cmake_initialize_per_config_variable(CMAKE_CUDA_FLAGS "Flags used by the CUDA compiler")
if(CMAKE_CUDA_STANDARD_LIBRARIES_INIT)
set(CMAKE_CUDA_STANDARD_LIBRARIES "${CMAKE_CUDA_STANDARD_LIBRARIES_INIT}"
@@ -185,7 +168,7 @@ endif()
# compile a cu file into an executable
if(NOT CMAKE_CUDA_LINK_EXECUTABLE)
set(CMAKE_CUDA_LINK_EXECUTABLE
- "<CMAKE_CUDA_HOST_LINK_LAUNCHER> <CMAKE_CUDA_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_LINKS}")
+ "<CMAKE_CUDA_HOST_LINK_LAUNCHER> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_LINKS}")
endif()
if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "8.0.0")
@@ -194,24 +177,31 @@ else()
set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "")
endif()
+# Add implicit host link directories that contain device libraries
+# to the device link line.
+set(__IMPLICT_DLINK_DIRS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
+if(__IMPLICT_DLINK_DIRS)
+ list(REMOVE_ITEM __IMPLICT_DLINK_DIRS ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES})
+endif()
+set(__IMPLICT_DLINK_FLAGS )
+foreach(dir ${__IMPLICT_DLINK_DIRS})
+ if(EXISTS "${dir}/libcurand_static.a")
+ string(APPEND __IMPLICT_DLINK_FLAGS " -L\"${dir}\"")
+ endif()
+endforeach()
+unset(__IMPLICT_DLINK_DIRS)
#These are used when linking relocatable (dc) cuda code
if(NOT CMAKE_CUDA_DEVICE_LINK_LIBRARY)
set(CMAKE_CUDA_DEVICE_LINK_LIBRARY
- "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+ "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <LANGUAGE_COMPILE_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}")
endif()
if(NOT CMAKE_CUDA_DEVICE_LINK_EXECUTABLE)
set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE
- "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+ "<CMAKE_CUDA_COMPILER> ${CMAKE_CUDA_HOST_FLAGS} <FLAGS> ${CMAKE_CUDA_COMPILE_OPTIONS_PIC} ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES>${__IMPLICT_DLINK_FLAGS}")
endif()
unset(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS)
-
-mark_as_advanced(
-CMAKE_CUDA_FLAGS
-CMAKE_CUDA_FLAGS_RELEASE
-CMAKE_CUDA_FLAGS_RELWITHDEBINFO
-CMAKE_CUDA_FLAGS_MINSIZEREL
-CMAKE_CUDA_FLAGS_DEBUG)
+unset(__IMPLICT_DLINK_FLAGS)
set(CMAKE_CUDA_INFORMATION_LOADED 1)
diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in
index fda79508b..e7f0e7074 100644
--- a/Modules/CMakeCXXCompiler.cmake.in
+++ b/Modules/CMakeCXXCompiler.cmake.in
@@ -2,6 +2,7 @@ set(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@")
set(CMAKE_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@")
set(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
set(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
+set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "@CMAKE_CXX_COMPILER_VERSION_INTERNAL@")
set(CMAKE_CXX_COMPILER_WRAPPER "@CMAKE_CXX_COMPILER_WRAPPER@")
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "@CMAKE_CXX_STANDARD_COMPUTED_DEFAULT@")
set(CMAKE_CXX_COMPILE_FEATURES "@CMAKE_CXX_COMPILE_FEATURES@")
@@ -9,17 +10,21 @@ 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_CXX17_COMPILE_FEATURES "@CMAKE_CXX17_COMPILE_FEATURES@")
+set(CMAKE_CXX20_COMPILE_FEATURES "@CMAKE_CXX20_COMPILE_FEATURES@")
set(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@")
set(CMAKE_CXX_SIMULATE_ID "@CMAKE_CXX_SIMULATE_ID@")
+set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "@CMAKE_CXX_COMPILER_FRONTEND_VARIANT@")
set(CMAKE_CXX_SIMULATE_VERSION "@CMAKE_CXX_SIMULATE_VERSION@")
+@_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID@
@SET_MSVC_CXX_ARCHITECTURE_ID@
-@SET_CMAKE_XCODE_CURRENT_ARCH@
+@SET_CMAKE_XCODE_ARCHS@
set(CMAKE_AR "@CMAKE_AR@")
set(CMAKE_CXX_COMPILER_AR "@CMAKE_CXX_COMPILER_AR@")
set(CMAKE_RANLIB "@CMAKE_RANLIB@")
set(CMAKE_CXX_COMPILER_RANLIB "@CMAKE_CXX_COMPILER_RANLIB@")
set(CMAKE_LINKER "@CMAKE_LINKER@")
+set(CMAKE_MT "@CMAKE_MT@")
set(CMAKE_COMPILER_IS_GNUCXX @CMAKE_COMPILER_IS_GNUCXX@)
set(CMAKE_CXX_COMPILER_LOADED 1)
set(CMAKE_CXX_COMPILER_WORKS @CMAKE_CXX_COMPILER_WORKS@)
@@ -68,6 +73,7 @@ endif()
@CMAKE_CXX_SYSROOT_FLAG_CODE@
@CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG_CODE@
+set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES@")
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@")
diff --git a/Modules/CMakeCXXCompilerABI.cpp b/Modules/CMakeCXXCompilerABI.cpp
index 2dee883fd..236053452 100644
--- a/Modules/CMakeCXXCompilerABI.cpp
+++ b/Modules/CMakeCXXCompilerABI.cpp
@@ -1,5 +1,5 @@
#ifndef __cplusplus
-#error "A C compiler has been selected for C++."
+# error "A C compiler has been selected for C++."
#endif
#include "CMakeCompilerABI.h"
diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in
index 9aa096dbb..34639b4b4 100644
--- a/Modules/CMakeCXXCompilerId.cpp.in
+++ b/Modules/CMakeCXXCompilerId.cpp.in
@@ -27,12 +27,20 @@ char const *info_cray = "INFO" ":" "compiler_wrapper[CrayPrgEnv]";
@CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@
@CMAKE_CXX_COMPILER_ID_ERROR_FOR_TEST@
+#if defined(_MSC_VER) && defined(_MSVC_LANG)
+#define CXX_STD _MSVC_LANG
+#else
+#define CXX_STD __cplusplus
+#endif
+
const char* info_language_dialect_default = "INFO" ":" "dialect_default["
-#if __cplusplus > 201402L
+#if CXX_STD > 201703L
+ "20"
+#elif CXX_STD >= 201703L
"17"
-#elif __cplusplus >= 201402L
+#elif CXX_STD >= 201402L
"14"
-#elif __cplusplus >= 201103L
+#elif CXX_STD >= 201103L
"11"
#else
"98"
@@ -49,6 +57,9 @@ int main(int argc, char* argv[])
#ifdef COMPILER_VERSION_MAJOR
require += info_version[argc];
#endif
+#ifdef COMPILER_VERSION_INTERNAL
+ require += info_version_internal[argc];
+#endif
#ifdef SIMULATE_ID
require += info_simulate[argc];
#endif
diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake
index ec731fae7..a896b99b6 100644
--- a/Modules/CMakeCXXInformation.cmake
+++ b/Modules/CMakeCXXInformation.cmake
@@ -36,19 +36,19 @@ 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)
+ include(Platform/${CMAKE_EFFECTIVE_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)
+ include(Platform/${CMAKE_EFFECTIVE_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)
+ include(Platform/${CMAKE_EFFECTIVE_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
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
RESULT_VARIABLE _INCLUDED_FILE)
endif ()
@@ -105,6 +105,12 @@ endif()
if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE)
set(CMAKE_CXX_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
endif()
+if(NOT CMAKE_CXX_LINK_OPTIONS_PIE)
+ set(CMAKE_CXX_LINK_OPTIONS_PIE ${CMAKE_C_LINK_OPTIONS_PIE})
+endif()
+if(NOT CMAKE_CXX_LINK_OPTIONS_NO_PIE)
+ set(CMAKE_CXX_LINK_OPTIONS_NO_PIE ${CMAKE_C_LINK_OPTIONS_NO_PIE})
+endif()
if(NOT CMAKE_CXX_COMPILE_OPTIONS_DLL)
set(CMAKE_CXX_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
@@ -158,10 +164,6 @@ 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
@@ -197,24 +199,7 @@ endforeach()
# and you can set these flags in the cmake cache
set(CMAKE_CXX_FLAGS_INIT "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}")
-foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
- string(STRIP "${CMAKE_CXX_FLAGS${c}_INIT}" CMAKE_CXX_FLAGS${c}_INIT)
-endforeach()
-
-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()
+cmake_initialize_per_config_variable(CMAKE_CXX_FLAGS "Flags used by the CXX compiler")
if(CMAKE_CXX_STANDARD_LIBRARIES_INIT)
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES_INIT}"
@@ -287,11 +272,6 @@ 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
index e60ffe019..e1ce617dc 100644
--- a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake
+++ b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake
@@ -7,28 +7,29 @@
# any way between releases.
macro (CHECK_COMPILER_FLAG_COMMON_PATTERNS _VAR)
- set(${_VAR}
- FAIL_REGEX "[Uu]nrecogni[sz]ed .*option" # GNU, NAG
- FAIL_REGEX "unknown .*option" # Clang
- FAIL_REGEX "optimization flag .* not supported" # Clang
- FAIL_REGEX "unknown argument ignored" # Clang (cl)
- FAIL_REGEX "ignoring unknown option" # MSVC, Intel
- 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 "Option .* is not recognized. Option will be ignored." # XL
- FAIL_REGEX "not supported in this configuration. ignored" # AIX
- FAIL_REGEX "File with unknown suffix passed to linker" # PGI
- FAIL_REGEX "[Uu]nknown switch" # 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
- )
+ set(${_VAR}
+ FAIL_REGEX "[Uu]nrecogni[sz]ed .*option" # GNU, NAG
+ FAIL_REGEX "unknown .*option" # Clang
+ FAIL_REGEX "optimization flag .* not supported" # Clang
+ FAIL_REGEX "unknown argument ignored" # Clang (cl)
+ FAIL_REGEX "ignoring unknown option" # MSVC, Intel
+ 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 "Option .* is not recognized. Option will be ignored." # XL
+ FAIL_REGEX "not supported in this configuration. ignored" # AIX
+ FAIL_REGEX "File with unknown suffix passed to linker" # PGI
+ FAIL_REGEX "[Uu]nknown switch" # 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
+ FAIL_REGEX "An invalid option .* appears on the command line" # Cray
+ )
endmacro ()
diff --git a/Modules/CMakeCommonLanguageInclude.cmake b/Modules/CMakeCommonLanguageInclude.cmake
index 43b5da022..b043e1815 100644
--- a/Modules/CMakeCommonLanguageInclude.cmake
+++ b/Modules/CMakeCommonLanguageInclude.cmake
@@ -10,120 +10,14 @@ string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " $ENV{LDFLAGS}")
string(APPEND CMAKE_SHARED_LINKER_FLAGS_INIT " $ENV{LDFLAGS}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS_INIT " $ENV{LDFLAGS}")
-foreach(t EXE SHARED MODULE STATIC)
- foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
- string(STRIP "${CMAKE_${t}_LINKER_FLAGS${c}_INIT}" CMAKE_${t}_LINKER_FLAGS${c}_INIT)
- endforeach()
-endforeach()
-
-if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
- get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
- # default build type is none
- if(NOT _GENERATOR_IS_MULTI_CONFIG AND 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()
- unset(_GENERATOR_IS_MULTI_CONFIG)
-
- 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.")
+cmake_initialize_per_config_variable(CMAKE_EXE_LINKER_FLAGS "Flags used by the linker")
+cmake_initialize_per_config_variable(CMAKE_SHARED_LINKER_FLAGS "Flags used by the linker during the creation of shared libraries")
+cmake_initialize_per_config_variable(CMAKE_MODULE_LINKER_FLAGS "Flags used by the linker during the creation of modules")
+cmake_initialize_per_config_variable(CMAKE_STATIC_LINKER_FLAGS "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
index ad481d6f0..45532afdb 100644
--- a/Modules/CMakeCompilerABI.h
+++ b/Modules/CMakeCompilerABI.h
@@ -2,35 +2,30 @@
/* Size of a pointer-to-data in bytes. */
#define SIZEOF_DPTR (sizeof(void*))
const char info_sizeof_dptr[] = {
+ /* clang-format off */
'I', 'N', 'F', 'O', ':', 's', 'i', 'z', 'e', 'o', 'f', '_', 'd', 'p', 't',
'r', '[', ('0' + ((SIZEOF_DPTR / 10) % 10)), ('0' + (SIZEOF_DPTR % 10)), ']',
'\0'
- /* clang-format needs this comment to break after the opening brace */
+ /* clang-format on */
};
/* 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"
+#if defined(__GNU__) && defined(__ELF__) && defined(__ARM_EABI__)
+# define ABI_ID "ELF ARMEABI"
#elif defined(__GNU__) && defined(__ELF__) && defined(__ARMEB__)
-#define ABI_ID "ELF ARM"
+# define ABI_ID "ELF ARM"
#elif defined(__GNU__) && defined(__ELF__) && defined(__ARMEL__)
-#define ABI_ID "ELF ARM"
+# define ABI_ID "ELF ARM"
#elif defined(__linux__) && defined(__ELF__) && defined(__amd64__) && \
defined(__ILP32__)
-#define ABI_ID "ELF X32"
+# define ABI_ID "ELF X32"
#elif defined(__ELF__)
-#define ABI_ID "ELF"
+# define ABI_ID "ELF"
#endif
#if defined(ABI_ID)
diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake
index f2d43b687..bb573b7dc 100644
--- a/Modules/CMakeCompilerIdDetection.cmake
+++ b/Modules/CMakeCompilerIdDetection.cmake
@@ -57,12 +57,14 @@ function(compiler_id_detection outvar lang)
HP
Compaq
zOS
+ XLClang
XL
VisualAge
PGI
Cray
TI
Fujitsu
+ GHS
)
if (lang STREQUAL C)
list(APPEND ordered_compilers
@@ -72,21 +74,20 @@ function(compiler_id_detection outvar lang)
endif()
list(APPEND ordered_compilers
SCO
+ ARMCC
AppleClang
+ ARMClang
Clang
GNU
MSVC
ADSP
IAR
- ARMCC
)
if (lang STREQUAL C)
list(APPEND ordered_compilers
SDCC
)
endif()
- list(APPEND ordered_compilers
- MIPSpro)
#Currently the only CUDA compilers are NVIDIA
if(lang STREQUAL CUDA)
@@ -97,6 +98,8 @@ function(compiler_id_detection outvar lang)
foreach(Id ${ordered_compilers})
string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n")
endforeach()
+ # Hard-code definitions for compilers that are no longer supported.
+ string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_MIPSpro 0\n")
endif()
set(pp_if "#if")
@@ -135,9 +138,6 @@ function(compiler_id_detection outvar lang)
/* 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\"
diff --git a/Modules/CMakeDependentOption.cmake b/Modules/CMakeDependentOption.cmake
index 21d3c96b3..6046d8585 100644
--- a/Modules/CMakeDependentOption.cmake
+++ b/Modules/CMakeDependentOption.cmake
@@ -1,27 +1,28 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
macro(CMAKE_DEPENDENT_OPTION option doc default depends force)
if(${option}_ISSET MATCHES "^${option}_ISSET$")
diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake
index 87c6b2872..e47f3a441 100644
--- a/Modules/CMakeDetermineASMCompiler.cmake
+++ b/Modules/CMakeDetermineASMCompiler.cmake
@@ -22,11 +22,9 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
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}")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_C_COMPILER})
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}")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST ${CMAKE_CXX_COMPILER})
else()
# List all default C and CXX compilers
set(CMAKE_ASM${ASM_DIALECT}_COMPILER_LIST
@@ -60,6 +58,18 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
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 Clang )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Clang "--version")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Clang "(clang version)")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS AppleClang )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_AppleClang "--version")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_AppleClang "(Apple LLVM version)")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ARMClang )
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMClang "--version")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMClang "armclang")
+
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")
@@ -77,14 +87,14 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
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_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)
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS IAR)
set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR )
set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler")
@@ -100,19 +110,53 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_YASM "--version")
set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_YASM "(yasm)")
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ADSP)
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ADSP "-version")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ADSP "Analog Devices")
+
+ list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS QCC)
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_QCC "-V")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_QCC "gcc_nto")
+
include(CMakeDetermineCompilerId)
set(userflags)
CMAKE_DETERMINE_COMPILER_ID_VENDOR(ASM${ASM_DIALECT} "${userflags}")
+ if("x${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}" STREQUAL "xIAR")
+ # primary necessary to detect architecture, so the right archiver and linker can be picked
+ # eg. "IAR Assembler V8.10.1.12857/W32 for ARM" or "IAR Assembler V4.11.1.4666 for Renesas RX"
+ # Cut out identification first, newline handling is a pain
+ string(REGEX MATCH "IAR Assembler[^\r\n]*" _compileid "${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT}")
+ if("${_compileid}" MATCHES "V([0-9]+\\.[0-9]+\\.[0-9]+)")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION ${CMAKE_MATCH_1})
+ endif()
+ string(REGEX MATCHALL "([A-Za-z0-9-]+)" _all_compileid_matches "${_compileid}")
+ if(_all_compileid_matches)
+ list(GET _all_compileid_matches "-1" CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID)
+ endif()
+ endif()
+ unset(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_OUTPUT)
+ unset(_all_compileid_matches)
+ unset(_compileid)
endif()
if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID)
- message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}")
+ if(CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION)
+ set(_version " ${CMAKE_ASM${ASM_DIALECT}_COMPILER_VERSION}")
+ else()
+ set(_version "")
+ endif()
+ if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID AND "x${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}" STREQUAL "xIAR")
+ set(_archid " ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}")
+ else()
+ set(_archid "")
+ endif()
+ message(STATUS "The ASM${ASM_DIALECT} compiler identification is ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}${_archid}${_version}")
+ unset(_archid)
+ unset(_version)
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
@@ -142,7 +186,10 @@ if (NOT _CMAKE_TOOLCHAIN_PREFIX)
endif ()
+set(_CMAKE_PROCESSING_LANGUAGE "ASM")
include(CMakeFindBinUtils)
+include(Compiler/${CMAKE_ASM${ASM_DIALECT}_COMPILER_ID}-FindBinUtils OPTIONAL)
+unset(_CMAKE_PROCESSING_LANGUAGE)
set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ENV_VAR "ASM${ASM_DIALECT}")
@@ -152,20 +199,37 @@ 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}")
-set(_CMAKE_ASM_COMPILER_AR "${CMAKE_ASM${ASM_DIALECT}_COMPILER_AR}")
-set(_CMAKE_ASM_COMPILER_RANLIB "${CMAKE_ASM${ASM_DIALECT}_COMPILER_RANLIB}")
+foreach(_var
+ COMPILER
+ COMPILER_ID
+ COMPILER_ARG1
+ COMPILER_ENV_VAR
+ COMPILER_AR
+ COMPILER_RANLIB
+ COMPILER_VERSION
+ )
+ set(_CMAKE_ASM_${_var} "${CMAKE_ASM${ASM_DIALECT}_${_var}}")
+endforeach()
+
+if(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID)
+ set(_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID
+ "set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID ${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID})")
+else()
+ set(_SET_CMAKE_ASM_COMPILER_ARCHITECTURE_ID "")
+endif()
# 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)
-set(_CMAKE_ASM_COMPILER_AR)
-set(_CMAKE_ASM_COMPILER_RANLIB)
+foreach(_var
+ COMPILER
+ COMPILER_ID
+ COMPILER_ARG1
+ COMPILER_ENV_VAR
+ COMPILER_AR
+ COMPILER_RANLIB
+ COMPILER_VERSION
+ )
+ unset(_CMAKE_ASM_${_var})
+endforeach()
diff --git a/Modules/CMakeDetermineASM_MASMCompiler.cmake b/Modules/CMakeDetermineASM_MASMCompiler.cmake
index 789b0494c..80188fb25 100644
--- a/Modules/CMakeDetermineASM_MASMCompiler.cmake
+++ b/Modules/CMakeDetermineASM_MASMCompiler.cmake
@@ -8,10 +8,10 @@ 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)
+ MATCHES ";(Win64|Itanium|x64|IA64);")
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT ml64)
else()
- set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT ml)
+ set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT ml)
endif()
include(CMakeDetermineASMCompiler)
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index 3caccdeab..037c33b6d 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -31,6 +31,7 @@ if(NOT CMAKE_C_COMPILER_NAMES)
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
+elseif("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
set(CMAKE_C_COMPILER_XCODE_TYPE sourcecode.c.c)
_cmake_find_compiler_path(C)
@@ -81,6 +82,9 @@ else()
# Try compiling K&R-compatible code (needed by Bruce C Compiler).
"-D__CLASSIC_C__"
+
+ # ARMClang need target options
+ "--target=arm-arm-none-eabi -mcpu=cortex-m3"
)
endif()
@@ -105,7 +109,7 @@ if(NOT CMAKE_C_COMPILER_ID_RUN)
# ...
# /path/to/cc ...CompilerIdC/...
# to extract the compiler front-end for the language.
- set(CMAKE_C_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdC/(\\./)?(CompilerIdC.xctest/)?CompilerIdC[ \t\n\\\"]")
+ set(CMAKE_C_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdC/(\\./)?(CompilerIdC.(framework|xctest)/)?CompilerIdC[ \t\n\\\"]")
set(CMAKE_C_COMPILER_ID_TOOL_MATCH_INDEX 2)
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
@@ -120,6 +124,22 @@ if(NOT CMAKE_C_COMPILER_ID_RUN)
elseif(CMAKE_C_PLATFORM_ID MATCHES "Cygwin")
set(CMAKE_COMPILER_IS_CYGWIN 1)
endif()
+else()
+ if(NOT DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT)
+ # Some toolchain files set our internal CMAKE_C_COMPILER_ID_RUN
+ # variable but are not aware of CMAKE_C_COMPILER_FRONTEND_VARIANT.
+ # They pre-date our support for the GNU-like variant targeting the
+ # MSVC ABI so we do not consider that here.
+ if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
+ set(CMAKE_C_COMPILER_FRONTEND_VARIANT "MSVC")
+ else()
+ set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")
+ endif()
+ else()
+ set(CMAKE_C_COMPILER_FRONTEND_VARIANT "")
+ endif()
+ endif()
endif()
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
@@ -135,16 +155,17 @@ endif ()
# "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")
+ if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|QCC")
get_filename_component(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME)
- if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ if (COMPILER_BASENAME MATCHES "^(.+-)(clang|g?cc)(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$")
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5})
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)?")
+ if(CMAKE_C_COMPILER_TARGET MATCHES "gcc_nto([a-z0-9]+_[0-9]+|[^_le]+)(le)?")
set(_CMAKE_TOOLCHAIN_PREFIX nto${CMAKE_MATCH_1}-)
endif()
endif ()
@@ -165,19 +186,26 @@ if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
endif ()
-include(CMakeFindBinUtils)
set(_CMAKE_PROCESSING_LANGUAGE "C")
+include(CMakeFindBinUtils)
include(Compiler/${CMAKE_C_COMPILER_ID}-FindBinUtils OPTIONAL)
unset(_CMAKE_PROCESSING_LANGUAGE)
+if(CMAKE_C_COMPILER_ARCHITECTURE_ID)
+ set(_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID
+ "set(CMAKE_C_COMPILER_ARCHITECTURE_ID ${CMAKE_C_COMPILER_ARCHITECTURE_ID})")
+else()
+ set(_SET_CMAKE_C_COMPILER_ARCHITECTURE_ID "")
+endif()
+
if(MSVC_C_ARCHITECTURE_ID)
set(SET_MSVC_C_ARCHITECTURE_ID
"set(MSVC_C_ARCHITECTURE_ID ${MSVC_C_ARCHITECTURE_ID})")
endif()
-if(CMAKE_C_XCODE_CURRENT_ARCH)
- set(SET_CMAKE_XCODE_CURRENT_ARCH
- "set(CMAKE_XCODE_CURRENT_ARCH ${CMAKE_C_XCODE_CURRENT_ARCH})")
+if(CMAKE_C_XCODE_ARCHS)
+ set(SET_CMAKE_XCODE_ARCHS
+ "set(CMAKE_XCODE_ARCHS \"${CMAKE_C_XCODE_ARCHS}\")")
endif()
# configure variables set in this file for fast reload later on
diff --git a/Modules/CMakeDetermineCSharpCompiler.cmake b/Modules/CMakeDetermineCSharpCompiler.cmake
index 55b2fb303..dab941431 100644
--- a/Modules/CMakeDetermineCSharpCompiler.cmake
+++ b/Modules/CMakeDetermineCSharpCompiler.cmake
@@ -1,8 +1,8 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio ([^89]|[89][0-9])")
- message(FATAL_ERROR
+if(NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio ([^9]|[9][0-9])")
+ message(FATAL_ERROR
"C# is currently only supported for Microsoft Visual Studio 2010 and later.")
endif()
@@ -23,7 +23,7 @@ if(NOT CMAKE_CSharp_COMPILER_ID_RUN)
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
CMAKE_DETERMINE_COMPILER_ID(CSharp CSFLAGS CMakeCSharpCompilerId.cs)
- execute_process(COMMAND "${CMAKE_CSharp_COMPILER}" "/help" OUTPUT_VARIABLE output)
+ execute_process(COMMAND "${CMAKE_CSharp_COMPILER}" "/help /preferreduilang:en-US" OUTPUT_VARIABLE output)
string(REPLACE "\n" ";" output "${output}")
foreach(line ${output})
string(TOUPPER ${line} line)
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index 89ac9fa67..490d6592e 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -6,7 +6,7 @@ include(${CMAKE_ROOT}/Modules//CMakeParseImplicitLinkInfo.cmake)
if( NOT ( ("${CMAKE_GENERATOR}" MATCHES "Make") OR
("${CMAKE_GENERATOR}" MATCHES "Ninja") OR
- ("${CMAKE_GENERATOR}" MATCHES "Visual Studio (1|[89][0-9])") ) )
+ ("${CMAKE_GENERATOR}" MATCHES "Visual Studio (1|[9][0-9])") ) )
message(FATAL_ERROR "CUDA language not currently supported by \"${CMAKE_GENERATOR}\" generator")
endif()
@@ -40,7 +40,6 @@ else()
endif()
#Allow the user to specify a host compiler
-set(CMAKE_CUDA_HOST_COMPILER "" CACHE FILEPATH "Host compiler to be used by nvcc")
if(NOT $ENV{CUDAHOSTCXX} STREQUAL "")
get_filename_component(CMAKE_CUDA_HOST_COMPILER $ENV{CUDAHOSTCXX} PROGRAM)
if(NOT EXISTS ${CMAKE_CUDA_HOST_COMPILER})
@@ -73,7 +72,10 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
CMAKE_DETERMINE_COMPILER_ID(CUDA CUDAFLAGS CMakeCUDACompilerId.cu)
endif()
+set(_CMAKE_PROCESSING_LANGUAGE "CUDA")
include(CMakeFindBinUtils)
+unset(_CMAKE_PROCESSING_LANGUAGE)
+
if(MSVC_CUDA_ARCHITECTURE_ID)
set(SET_MSVC_CUDA_ARCHITECTURE_ID
"set(MSVC_CUDA_ARCHITECTURE_ID ${MSVC_CUDA_ARCHITECTURE_ID})")
@@ -87,6 +89,15 @@ if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
set(_nvcc_log "")
string(REPLACE "\r" "" _nvcc_output_orig "${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}")
+ if(_nvcc_output_orig MATCHES "#\\\$ +PATH= *([^\n]*)\n")
+ set(_nvcc_path "${CMAKE_MATCH_1}")
+ string(APPEND _nvcc_log " found 'PATH=' string: [${_nvcc_path}]\n")
+ string(REPLACE ":" ";" _nvcc_path "${_nvcc_path}")
+ else()
+ set(_nvcc_path "")
+ string(REPLACE "\n" "\n " _nvcc_output_log "\n${_nvcc_output_orig}")
+ string(APPEND _nvcc_log " no 'PATH=' string found in nvcc output:${_nvcc_output_log}\n")
+ endif()
if(_nvcc_output_orig MATCHES "#\\\$ +LIBRARIES= *([^\n]*)\n")
set(_nvcc_libraries "${CMAKE_MATCH_1}")
string(APPEND _nvcc_log " found 'LIBRARIES=' string: [${_nvcc_libraries}]\n")
@@ -100,10 +111,15 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
if(_nvcc_libraries)
# Remove variable assignments.
string(REGEX REPLACE "#\\\$ *[^= ]+=[^\n]*\n" "" _nvcc_output "${_nvcc_output_orig}")
+ # Encode [] characters that break list expansion.
+ string(REPLACE "[" "{==={" _nvcc_output "${_nvcc_output}")
+ string(REPLACE "]" "}===}" _nvcc_output "${_nvcc_output}")
# Split lines.
string(REGEX REPLACE "\n+(#\\\$ )?" ";" _nvcc_output "${_nvcc_output}")
foreach(line IN LISTS _nvcc_output)
set(_nvcc_output_line "${line}")
+ string(REPLACE "{==={" "[" _nvcc_output_line "${_nvcc_output_line}")
+ string(REPLACE "}===}" "]" _nvcc_output_line "${_nvcc_output_line}")
string(APPEND _nvcc_log " considering line: [${_nvcc_output_line}]\n")
if("${_nvcc_output_line}" MATCHES "^ *nvlink")
string(APPEND _nvcc_log " ignoring nvlink line\n")
@@ -131,7 +147,26 @@ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL NVIDIA)
else()
#extract the compiler that is being used for linking
separate_arguments(_nvcc_link_line_args UNIX_COMMAND "${_nvcc_link_line}")
- list(GET _nvcc_link_line_args 0 CMAKE_CUDA_HOST_LINK_LAUNCHER)
+ list(GET _nvcc_link_line_args 0 _nvcc_host_link_launcher)
+ if(IS_ABSOLUTE "${_nvcc_host_link_launcher}")
+ string(APPEND _nvcc_log " extracted link launcher absolute path: [${_nvcc_host_link_launcher}]\n")
+ set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}")
+ else()
+ string(APPEND _nvcc_log " extracted link launcher name: [${_nvcc_host_link_launcher}]\n")
+ find_program(_nvcc_find_host_link_launcher
+ NAMES ${_nvcc_host_link_launcher}
+ PATHS ${_nvcc_path} NO_DEFAULT_PATH)
+ find_program(_nvcc_find_host_link_launcher
+ NAMES ${_nvcc_host_link_launcher})
+ if(_nvcc_find_host_link_launcher)
+ string(APPEND _nvcc_log " found link launcher absolute path: [${_nvcc_find_host_link_launcher}]\n")
+ set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_find_host_link_launcher}")
+ else()
+ string(APPEND _nvcc_log " could not find link launcher absolute path\n")
+ set(CMAKE_CUDA_HOST_LINK_LAUNCHER "${_nvcc_host_link_launcher}")
+ endif()
+ unset(_nvcc_find_host_link_launcher CACHE)
+ endif()
endif()
#prefix the line with cuda-fake-ld so that implicit link info believes it is
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
index 9150962d9..7274eecdf 100644
--- a/Modules/CMakeDetermineCXXCompiler.cmake
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -30,6 +30,7 @@ if(NOT CMAKE_CXX_COMPILER_NAMES)
endif()
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
+elseif("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
elseif("${CMAKE_GENERATOR}" MATCHES "Xcode")
set(CMAKE_CXX_COMPILER_XCODE_TYPE sourcecode.cpp.cpp)
_cmake_find_compiler_path(CXX)
@@ -73,6 +74,12 @@ else()
set(CMAKE_CXX_COMPILER_ID_TEST_FLAGS
# Try compiling to an object file only.
"-c"
+ # IAR does not detect language automatically
+ "--c++"
+ "--ec++"
+
+ # ARMClang need target options
+ "--target=arm-arm-none-eabi -mcpu=cortex-m3"
)
endif()
@@ -97,7 +104,7 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN)
# ...
# /path/to/cc ...CompilerIdCXX/...
# to extract the compiler front-end for the language.
- set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdCXX/(\\./)?(CompilerIdCXX.xctest/)?CompilerIdCXX[ \t\n\\\"]")
+ set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_REGEX "\nLd[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]*-o[^\r\n]*CompilerIdCXX/(\\./)?(CompilerIdCXX.(framework|xctest)/)?CompilerIdCXX[ \t\n\\\"]")
set(CMAKE_CXX_COMPILER_ID_TOOL_MATCH_INDEX 2)
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
@@ -112,6 +119,22 @@ if(NOT CMAKE_CXX_COMPILER_ID_RUN)
elseif(CMAKE_CXX_PLATFORM_ID MATCHES "Cygwin")
set(CMAKE_COMPILER_IS_CYGWIN 1)
endif()
+else()
+ if(NOT DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
+ # Some toolchain files set our internal CMAKE_CXX_COMPILER_ID_RUN
+ # variable but are not aware of CMAKE_CXX_COMPILER_FRONTEND_VARIANT.
+ # They pre-date our support for the GNU-like variant targeting the
+ # MSVC ABI so we do not consider that here.
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "MSVC")
+ else()
+ set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "GNU")
+ endif()
+ else()
+ set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "")
+ endif()
+ endif()
endif()
if (NOT _CMAKE_TOOLCHAIN_LOCATION)
@@ -129,16 +152,17 @@ endif ()
if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
- if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
+ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|QCC")
get_filename_component(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME)
- if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+\\.[0-9]+\\.[0-9]+)?(\\.exe)?$")
+ if (COMPILER_BASENAME MATCHES "^(.+-)(clan)?[gc]\\+\\+(-[0-9]+(\\.[0-9]+)*)?(-[^.]+)?(\\.exe)?$")
set(_CMAKE_TOOLCHAIN_PREFIX ${CMAKE_MATCH_1})
+ set(_CMAKE_COMPILER_SUFFIX ${CMAKE_MATCH_5})
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)?")
+ if(CMAKE_CXX_COMPILER_TARGET MATCHES "gcc_nto([a-z0-9]+_[0-9]+|[^_le]+)(le)")
set(_CMAKE_TOOLCHAIN_PREFIX nto${CMAKE_MATCH_1}-)
endif()
endif ()
@@ -160,19 +184,26 @@ if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
endif ()
-include(CMakeFindBinUtils)
set(_CMAKE_PROCESSING_LANGUAGE "CXX")
+include(CMakeFindBinUtils)
include(Compiler/${CMAKE_CXX_COMPILER_ID}-FindBinUtils OPTIONAL)
unset(_CMAKE_PROCESSING_LANGUAGE)
+if(CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
+ set(_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID
+ "set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})")
+else()
+ set(_SET_CMAKE_CXX_COMPILER_ARCHITECTURE_ID "")
+endif()
+
if(MSVC_CXX_ARCHITECTURE_ID)
set(SET_MSVC_CXX_ARCHITECTURE_ID
"set(MSVC_CXX_ARCHITECTURE_ID ${MSVC_CXX_ARCHITECTURE_ID})")
endif()
-if(CMAKE_CXX_XCODE_CURRENT_ARCH)
- set(SET_CMAKE_XCODE_CURRENT_ARCH
- "set(CMAKE_XCODE_CURRENT_ARCH ${CMAKE_CXX_XCODE_CURRENT_ARCH})")
+if(CMAKE_CXX_XCODE_ARCHS)
+ set(SET_CMAKE_XCODE_ARCHS
+ "set(CMAKE_XCODE_ARCHS \"${CMAKE_CXX_XCODE_ARCHS}\")")
endif()
# configure all variables set in this file
diff --git a/Modules/CMakeDetermineCompileFeatures.cmake b/Modules/CMakeDetermineCompileFeatures.cmake
index 3ed92bee3..01a81a1a8 100644
--- a/Modules/CMakeDetermineCompileFeatures.cmake
+++ b/Modules/CMakeDetermineCompileFeatures.cmake
@@ -49,6 +49,7 @@ function(cmake_determine_compile_features lang)
set(CMAKE_CXX11_COMPILE_FEATURES)
set(CMAKE_CXX14_COMPILE_FEATURES)
set(CMAKE_CXX17_COMPILE_FEATURES)
+ set(CMAKE_CXX20_COMPILE_FEATURES)
include("${CMAKE_ROOT}/Modules/Internal/FeatureTesting.cmake")
@@ -59,6 +60,9 @@ function(cmake_determine_compile_features lang)
return()
endif()
+ if (CMAKE_CXX17_COMPILE_FEATURES AND CMAKE_CXX20_COMPILE_FEATURES)
+ list(REMOVE_ITEM CMAKE_CXX20_COMPILE_FEATURES ${CMAKE_CXX17_COMPILE_FEATURES})
+ endif()
if (CMAKE_CXX14_COMPILE_FEATURES AND CMAKE_CXX17_COMPILE_FEATURES)
list(REMOVE_ITEM CMAKE_CXX17_COMPILE_FEATURES ${CMAKE_CXX14_COMPILE_FEATURES})
endif()
@@ -75,6 +79,7 @@ function(cmake_determine_compile_features lang)
${CMAKE_CXX11_COMPILE_FEATURES}
${CMAKE_CXX14_COMPILE_FEATURES}
${CMAKE_CXX17_COMPILE_FEATURES}
+ ${CMAKE_CXX20_COMPILE_FEATURES}
)
endif()
@@ -83,6 +88,7 @@ function(cmake_determine_compile_features lang)
set(CMAKE_CXX11_COMPILE_FEATURES ${CMAKE_CXX11_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_CXX14_COMPILE_FEATURES ${CMAKE_CXX14_COMPILE_FEATURES} PARENT_SCOPE)
set(CMAKE_CXX17_COMPILE_FEATURES ${CMAKE_CXX17_COMPILE_FEATURES} PARENT_SCOPE)
+ set(CMAKE_CXX20_COMPILE_FEATURES ${CMAKE_CXX20_COMPILE_FEATURES} PARENT_SCOPE)
message(STATUS "Detecting ${lang} compile features - done")
endif()
diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake
index 604ac27e6..06f3ba22d 100644
--- a/Modules/CMakeDetermineCompilerABI.cmake
+++ b/Modules/CMakeDetermineCompilerABI.cmake
@@ -6,7 +6,9 @@
# This is used internally by CMake and should not be included by user
# code.
+include(${CMAKE_ROOT}/Modules/CMakeParseImplicitIncludeInfo.cmake)
include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
+include(CMakeTestCompilerCommon)
function(CMAKE_DETERMINE_COMPILER_ABI lang src)
if(NOT DEFINED CMAKE_${lang}_ABI_COMPILED)
@@ -15,23 +17,48 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
# Compile the ABI identification source.
set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin")
set(CMAKE_FLAGS )
+ set(COMPILE_DEFINITIONS )
if(DEFINED CMAKE_${lang}_VERBOSE_FLAG)
set(CMAKE_FLAGS "-DEXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}")
+ set(COMPILE_DEFINITIONS "${CMAKE_${lang}_VERBOSE_FLAG}")
+ endif()
+ if(DEFINED CMAKE_${lang}_VERBOSE_COMPILE_FLAG)
+ set(COMPILE_DEFINITIONS "${CMAKE_${lang}_VERBOSE_COMPILE_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()
+ __TestCompiler_setTryCompileTargetType()
+
+ # 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)
+
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"
+ COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS}
OUTPUT_VARIABLE OUTPUT
COPY_FILE "${BIN}"
COPY_FILE_ERROR _copy_error
+ __CMAKE_INTERNAL ABI
)
+
+ # 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})
+
# Move result from cache to normal variable.
set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED})
unset(CMAKE_${lang}_ABI_COMPILED CACHE)
@@ -62,6 +89,26 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
set(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
endif()
+ # Parse implicit include directory for this language, if available.
+ if(CMAKE_${lang}_VERBOSE_FLAG)
+ set (implicit_incdirs "")
+ cmake_parse_implicit_include_info("${OUTPUT}" "${lang}"
+ implicit_incdirs log rv)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Parsed ${lang} implicit include dir info from above output: rv=${rv}\n${log}\n\n")
+ if("${rv}" STREQUAL "done")
+ # Entries that we have been told to explicitly pass as standard include
+ # directories will not be implicitly added by the compiler.
+ if(CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES)
+ list(REMOVE_ITEM implicit_incdirs ${CMAKE_${lang}_STANDARD_INCLUDE_DIRECTORIES})
+ endif()
+
+ # We parsed implicit include directories, so override the default initializer.
+ set(_CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES_INIT "${implicit_incdirs}")
+ endif()
+ endif()
+ set(CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES "${_CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES_INIT}" PARENT_SCOPE)
+
# Parse implicit linker information for this language, if available.
set(implicit_dirs "")
set(implicit_libs "")
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index 7588f63b7..edbc23b44 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -28,6 +28,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
foreach(testflags ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS_FIRST}
""
${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS})
+ separate_arguments(testflags UNIX_COMMAND "${testflags}")
CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${testflags}" "${userflags}" "${src}")
CMAKE_DETERMINE_COMPILER_ID_MATCH_VENDOR("${lang}" "${COMPILER_${lang}_PRODUCED_OUTPUT}")
if(CMAKE_${lang}_COMPILER_ID)
@@ -45,6 +46,14 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
endif()
endforeach()
+ # 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}")
+ 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()
+
# If the compiler is still unknown, try to query its vendor.
if(CMAKE_${lang}_COMPILER AND NOT CMAKE_${lang}_COMPILER_ID)
foreach(userflags "${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}" "")
@@ -52,6 +61,53 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
endforeach()
endif()
+ # If the compiler is still unknown, fallback to GHS
+ if(NOT CMAKE_${lang}_COMPILER_ID AND "${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
+ set(CMAKE_${lang}_COMPILER_ID GHS)
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "The ${lang} compiler identification is falling back to GHS.\n\n")
+ endif()
+
+ # CUDA < 7.5 is missing version macros
+ if(lang STREQUAL "CUDA"
+ AND CMAKE_${lang}_COMPILER_ID STREQUAL "NVIDIA"
+ AND NOT CMAKE_${lang}_COMPILER_VERSION)
+ execute_process(
+ COMMAND "${CMAKE_${lang}_COMPILER}"
+ --version
+ OUTPUT_VARIABLE output ERROR_VARIABLE output
+ RESULT_VARIABLE result
+ TIMEOUT 10
+ )
+ if(output MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=])
+ set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
+ endif()
+ endif()
+
+ # For Swift we need to explicitly query the version.
+ if(lang STREQUAL "Swift"
+ AND CMAKE_${lang}_COMPILER
+ AND NOT CMAKE_${lang}_COMPILER_VERSION)
+ execute_process(
+ COMMAND "${CMAKE_${lang}_COMPILER}"
+ -version
+ OUTPUT_VARIABLE output ERROR_VARIABLE output
+ RESULT_VARIABLE result
+ TIMEOUT 10
+ )
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Running the ${lang} compiler: \"${CMAKE_${lang}_COMPILER}\" -version\n"
+ "${output}\n"
+ )
+
+ if(output MATCHES [[Swift version ([0-9]+\.[0-9]+(\.[0-9]+)?)]])
+ set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_MATCH_1}")
+ if(NOT CMAKE_${lang}_COMPILER_ID)
+ set(CMAKE_Swift_COMPILER_ID "Apple")
+ endif()
+ endif()
+ endif()
+
if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL "GNU")
execute_process(
COMMAND "${CMAKE_${lang}_COMPILER}"
@@ -80,6 +136,31 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "")
endif()
+ set(_variant "")
+ if("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang")
+ if("x${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "xMSVC")
+ if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
+ else()
+ # Test whether an MSVC-like command-line option works.
+ execute_process(COMMAND "${CMAKE_${lang}_COMPILER}" -?
+ RESULT_VARIABLE _clang_result
+ OUTPUT_VARIABLE _clang_stdout
+ ERROR_VARIABLE _clang_stderr)
+ if(_clang_result EQUAL 0)
+ set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "MSVC")
+ else()
+ set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
+ endif()
+ endif()
+ set(_variant " with ${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}-like command-line")
+ else()
+ set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "GNU")
+ endif()
+ else()
+ set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "")
+ endif()
+
# Display the final identification result.
if(CMAKE_${lang}_COMPILER_ID)
if(CMAKE_${lang}_COMPILER_VERSION)
@@ -87,26 +168,30 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
else()
set(_version "")
endif()
+ if(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID AND "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xIAR")
+ set(_archid " ${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}")
+ else()
+ set(_archid "")
+ endif()
message(STATUS "The ${lang} compiler identification is "
- "${CMAKE_${lang}_COMPILER_ID}${_version}")
+ "${CMAKE_${lang}_COMPILER_ID}${_archid}${_version}${_variant}")
+ unset(_archid)
+ unset(_version)
+ unset(_variant)
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(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}" PARENT_SCOPE)
set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}"
PARENT_SCOPE)
- set(CMAKE_${lang}_XCODE_CURRENT_ARCH "${CMAKE_${lang}_XCODE_CURRENT_ARCH}" PARENT_SCOPE)
+ set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_${lang}_XCODE_ARCHS}" PARENT_SCOPE)
set(CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX "${CMAKE_${lang}_CL_SHOWINCLUDES_PREFIX}" PARENT_SCOPE)
+ set(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT "${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE)
+ set(CMAKE_${lang}_COMPILER_VERSION_INTERNAL "${CMAKE_${lang}_COMPILER_VERSION_INTERNAL}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_WRAPPER "${CMAKE_${lang}_COMPILER_WRAPPER}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
@@ -156,7 +241,10 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
set(vs_version ${CMAKE_MATCH_1})
set(id_platform ${CMAKE_VS_PLATFORM_NAME})
set(id_lang "${lang}")
- if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*")
+ set(id_PostBuildEvent_Command "")
+ if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "^[Ll][Ll][Vv][Mm](_v[0-9]+(_xp)?)?$")
+ set(id_cl_var "ClangClExecutable")
+ elseif(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*")
set(id_cl clang.exe)
else()
set(id_cl cl.exe)
@@ -195,9 +283,20 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "Intel")
set(id_cl icl.exe)
endif()
+ if(CMAKE_VS_PLATFORM_TOOLSET_VERSION)
+ set(id_sep "\\")
+ if(CMAKE_VS_PLATFORM_TOOLSET_VERSION VERSION_GREATER_EQUAL "14.20")
+ if(EXISTS "${CMAKE_GENERATOR_INSTANCE}/VC/Auxiliary/Build.${CMAKE_VS_PLATFORM_TOOLSET_VERSION}/Microsoft.VCToolsVersion.${CMAKE_VS_PLATFORM_TOOLSET_VERSION}.props")
+ set(id_sep ".")
+ endif()
+ endif()
+ set(id_toolset_version_props "<Import Project=\"${CMAKE_GENERATOR_INSTANCE}\\VC\\Auxiliary\\Build${id_sep}${CMAKE_VS_PLATFORM_TOOLSET_VERSION}\\Microsoft.VCToolsVersion.${CMAKE_VS_PLATFORM_TOOLSET_VERSION}.props\" />")
+ unset(id_sep)
+ endif()
endif()
else()
set(id_toolset "")
+ set(id_toolset_version_props "")
endif()
if(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE)
set(id_PreferredToolArchitecture "<PreferredToolArchitecture>${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}</PreferredToolArchitecture>")
@@ -211,15 +310,17 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
else()
set(id_system "")
endif()
- if(id_system AND CMAKE_SYSTEM_VERSION)
- set(id_system_version "<ApplicationTypeRevision>${CMAKE_SYSTEM_VERSION}</ApplicationTypeRevision>")
+ if(id_system AND CMAKE_SYSTEM_VERSION MATCHES "^([0-9]+\\.[0-9]+)")
+ set(id_system_version "<ApplicationTypeRevision>${CMAKE_MATCH_1}</ApplicationTypeRevision>")
else()
set(id_system_version "")
endif()
if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
set(id_WindowsTargetPlatformVersion "<WindowsTargetPlatformVersion>${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}</WindowsTargetPlatformVersion>")
endif()
- if(id_platform STREQUAL ARM)
+ if(id_platform STREQUAL ARM64)
+ set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARM64Support>true</WindowsSDKDesktopARM64Support>")
+ elseif(id_platform STREQUAL ARM)
set(id_WindowsSDKDesktopARMSupport "<WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>")
else()
set(id_WindowsSDKDesktopARMSupport "")
@@ -237,7 +338,11 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR})
set(id_src "${src}")
set(id_compile "ClCompile")
- set(id_PostBuildEvent_Command "for %%i in (${id_cl}) do %40echo CMAKE_${lang}_COMPILER=%%~$PATH:i")
+ if(id_cl_var)
+ set(id_PostBuildEvent_Command "echo CMAKE_${lang}_COMPILER=$(${id_cl_var})")
+ else()
+ set(id_PostBuildEvent_Command "for %%i in (${id_cl}) do %40echo CMAKE_${lang}_COMPILER=%%~$PATH:i")
+ endif()
set(id_Import_props "")
set(id_Import_targets "")
set(id_ItemDefinitionGroup_entry "")
@@ -301,6 +406,8 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
if("${lang}" STREQUAL "Swift")
if(CMAKE_Swift_LANGUAGE_VERSION)
set(id_lang_version "SWIFT_VERSION = ${CMAKE_Swift_LANGUAGE_VERSION};")
+ elseif(XCODE_VERSION VERSION_GREATER_EQUAL 10.2)
+ set(id_lang_version "SWIFT_VERSION = 4.0;")
elseif(XCODE_VERSION VERSION_GREATER_EQUAL 8.3)
set(id_lang_version "SWIFT_VERSION = 3.0;")
else()
@@ -318,12 +425,24 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
set(id_product_type "com.apple.product-type.tool")
if(CMAKE_OSX_SYSROOT)
set(id_sdkroot "SDKROOT = \"${CMAKE_OSX_SYSROOT}\";")
- if(CMAKE_OSX_SYSROOT MATCHES "(^|/)[Ii][Pp][Hh][Oo][Nn][Ee]")
+ if(CMAKE_OSX_SYSROOT MATCHES "(^|/)[Ii][Pp][Hh][Oo][Nn][Ee]" OR
+ CMAKE_OSX_SYSROOT MATCHES "(^|/)[Aa][Pp][Pp][Ll][Ee][Tt][Vv]")
set(id_product_type "com.apple.product-type.bundle.unit-test")
+ elseif(CMAKE_OSX_SYSROOT MATCHES "(^|/)[Ww][Aa][Tt][Cc][Hh]")
+ set(id_product_type "com.apple.product-type.framework")
endif()
else()
set(id_sdkroot "")
endif()
+ set(id_clang_cxx_library "")
+ set(stdlib_regex "(^| )(-stdlib=)([^ ]+)( |$)")
+ string(REGEX MATCHALL "${stdlib_regex}" all_stdlib_matches "${CMAKE_CXX_FLAGS}")
+ if(all_stdlib_matches)
+ list(GET all_stdlib_matches "-1" last_stdlib_match)
+ if(last_stdlib_match MATCHES "${stdlib_regex}")
+ set(id_clang_cxx_library "CLANG_CXX_LIBRARY = \"${CMAKE_MATCH_3}\";")
+ endif()
+ endif()
configure_file(${CMAKE_ROOT}/Modules/CompilerId/Xcode-3.pbxproj.in
${id_dir}/CompilerId${lang}.xcodeproj/project.pbxproj @ONLY)
unset(_ENV_MACOSX_DEPLOYMENT_TARGET)
@@ -349,8 +468,52 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS}
endif()
endif()
endif()
- if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "CURRENT_ARCH=([^%\r\n]+)[\r\n]")
- set(CMAKE_${lang}_XCODE_CURRENT_ARCH "${CMAKE_MATCH_1}" PARENT_SCOPE)
+ if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "ARCHS=([^%\r\n]+)[\r\n]")
+ set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_MATCH_1}")
+ separate_arguments(CMAKE_${lang}_XCODE_ARCHS)
+ set(CMAKE_${lang}_XCODE_ARCHS "${CMAKE_${lang}_XCODE_ARCHS}" PARENT_SCOPE)
+ endif()
+ elseif("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
+ set(id_dir ${CMAKE_${lang}_COMPILER_ID_DIR})
+ set(id_src "${src}")
+ if (GHS_PRIMARY_TARGET)
+ set(ghs_primary_target "${GHS_PRIMARY_TARGET}")
+ else()
+ set(ghs_primary_target "${CMAKE_GENERATOR_PLATFORM}_${GHS_TARGET_PLATFORM}.tgt")
+ endif()
+ if ("${GHS_TARGET_PLATFORM}" MATCHES "integrity")
+ set(bsp_name "macro GHS_BSP=${GHS_BSP_NAME}")
+ set(os_dir "macro GHS_OS=${GHS_OS_DIR}")
+ endif()
+ set(command "${CMAKE_MAKE_PROGRAM}" "-commands" "-top" "GHS_default.gpj")
+ configure_file(${CMAKE_ROOT}/Modules/CompilerId/GHS_default.gpj.in
+ ${id_dir}/GHS_default.gpj @ONLY)
+ configure_file(${CMAKE_ROOT}/Modules/CompilerId/GHS_lib.gpj.in
+ ${id_dir}/GHS_lib.gpj @ONLY)
+ execute_process(COMMAND ${command}
+ WORKING_DIRECTORY ${id_dir}
+ OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
+ RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT
+ )
+ # Match the compiler location line printed out.
+ set(ghs_toolpath "${CMAKE_MAKE_PROGRAM}")
+ if(CMAKE_HOST_UNIX)
+ string(REPLACE "/gbuild" "/" ghs_toolpath ${ghs_toolpath})
+ else()
+ string(REPLACE "/gbuild.exe" "/" ghs_toolpath ${ghs_toolpath})
+ string(REPLACE / "\\\\" ghs_toolpath ${ghs_toolpath})
+ endif()
+ if("${CMAKE_${lang}_COMPILER_ID_OUTPUT}" MATCHES "(${ghs_toolpath}[^ ]*)")
+ if(CMAKE_HOST_UNIX)
+ set(_comp "${CMAKE_MATCH_1}")
+ else()
+ set(_comp "${CMAKE_MATCH_1}.exe")
+ endif()
+ if(EXISTS "${_comp}")
+ file(TO_CMAKE_PATH "${_comp}" _comp)
+ set(CMAKE_${lang}_COMPILER_ID_TOOL "${_comp}" PARENT_SCOPE)
+ endif()
endif()
else()
execute_process(
@@ -411,6 +574,9 @@ ${CMAKE_${lang}_COMPILER_ID_OUTPUT}
# com.apple.package-type.bundle.unit-test
${_glob_id_dir}/*.xctest/*
+
+ # com.apple.product-type.framework
+ ${_glob_id_dir}/*.framework/*
)
list(REMOVE_ITEM files "${src}")
set(COMPILER_${lang}_PRODUCED_FILES "")
@@ -463,6 +629,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
set(COMPILER_VERSION_MINOR 0)
set(COMPILER_VERSION_PATCH 0)
set(COMPILER_VERSION_TWEAK 0)
+ set(COMPILER_VERSION_INTERNAL "")
set(HAVE_COMPILER_VERSION_MAJOR 0)
set(HAVE_COMPILER_VERSION_MINOR 0)
set(HAVE_COMPILER_VERSION_PATCH 0)
@@ -483,11 +650,20 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
file(STRINGS ${file}
CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 38
${CMAKE_${lang}_COMPILER_ID_STRINGS_PARAMETERS}
- REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
+ REGEX ".?I.?N.?F.?O.?:.?[A-Za-z0-9_]+\\[[^]]*\\]")
set(COMPILER_ID_TWICE)
+ # With the IAR Compiler, some strings are found twice, first time as incomplete
+ # list like "?<Constant "INFO:compiler[IAR]">". Remove the incomplete copies.
+ list(FILTER CMAKE_${lang}_COMPILER_ID_STRINGS EXCLUDE REGEX "\\?<Constant \\\"")
# In C# binaries, some strings are found more than once.
list(REMOVE_DUPLICATES CMAKE_${lang}_COMPILER_ID_STRINGS)
foreach(info ${CMAKE_${lang}_COMPILER_ID_STRINGS})
+ # The IAR-AVR compiler uses a binary format that places a '6'
+ # character (0x34) before each character in the string. Strip
+ # out these characters without removing any legitamate characters.
+ if("${info}" MATCHES "(.)I.N.F.O.:.")
+ string(REGEX REPLACE "${CMAKE_MATCH_1}(.)" "\\1" info "${info}")
+ endif()
if("${info}" MATCHES "INFO:compiler\\[([^]\"]*)\\]")
if(COMPILER_ID)
set(COMPILER_ID_TWICE 1)
@@ -501,9 +677,13 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
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 "${CMAKE_MATCH_1}")
string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}")
endif()
+ if("${info}" MATCHES "INFO:compiler_version_internal\\[([^]\"]*)\\]")
+ string(REGEX REPLACE "^0+([0-9])" "\\1" COMPILER_VERSION_INTERNAL "${CMAKE_MATCH_1}")
+ string(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION_INTERNAL "${COMPILER_VERSION_INTERNAL}")
+ endif()
foreach(comp MAJOR MINOR PATCH TWEAK)
foreach(digit 1 2 3 4 5 6 7 8 9)
if("${info}" MATCHES "INFO:compiler_version_${comp}_digit_${digit}\\[([0-9])\\]")
@@ -549,26 +729,28 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
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")
+ if(NOT peoffsethex STREQUAL "")
+ 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")
+ endif()
endif()
endif()
@@ -576,8 +758,10 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
if(COMPILER_ID AND NOT COMPILER_ID_TWICE)
set(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}")
set(CMAKE_${lang}_PLATFORM_ID "${PLATFORM_ID}")
+ set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
set(CMAKE_${lang}_COMPILER_VERSION "${COMPILER_VERSION}")
+ set(CMAKE_${lang}_COMPILER_VERSION_INTERNAL "${COMPILER_VERSION_INTERNAL}")
set(CMAKE_${lang}_SIMULATE_ID "${SIMULATE_ID}")
set(CMAKE_${lang}_SIMULATE_VERSION "${SIMULATE_VERSION}")
endif()
@@ -610,13 +794,10 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
# 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()
+ # Mach-O files start with MH_MAGIC or MH_CIGAM
+ if("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "feedface|cefaedfe|feedfacf|cffaedfe")
+ set(CMAKE_EXECUTABLE_FORMAT "MACHO" CACHE STRING "Executable file format")
+ endif()
endif()
if(NOT DEFINED CMAKE_EXECUTABLE_FORMAT)
@@ -625,9 +806,11 @@ function(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file)
# 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(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_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}_COMPILER_VERSION_INTERNAL "${CMAKE_${lang}_COMPILER_VERSION_INTERNAL}" PARENT_SCOPE)
set(CMAKE_${lang}_COMPILER_WRAPPER "${COMPILER_WRAPPER}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_ID "${CMAKE_${lang}_SIMULATE_ID}" PARENT_SCOPE)
set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE)
@@ -675,6 +858,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_VENDOR lang userflags)
"Checking whether the ${lang} compiler is ${vendor} using \"${flags}\" "
"matched \"${regex}\":\n${output}")
set(CMAKE_${lang}_COMPILER_ID "${vendor}" PARENT_SCOPE)
+ set(CMAKE_${lang}_COMPILER_ID_OUTPUT "${output}" PARENT_SCOPE)
break()
else()
if("${result}" MATCHES "timeout")
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
index d5220b4de..5ddd64fae 100644
--- a/Modules/CMakeDetermineFortranCompiler.cmake
+++ b/Modules/CMakeDetermineFortranCompiler.cmake
@@ -52,6 +52,7 @@ else()
# frt: Fujitsu F77 compiler
# pathf90/pathf95/pathf2003: PathScale Fortran compiler
# pgf77/pgf90/pgf95/pgfortran: Portland Group F77/F90/F95 compilers
+ # flang: Flang Fortran compiler
# xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
# lf95: Lahey-Fujitsu F95 compiler
# fl32: Microsoft Fortran 77 "PowerStation" compiler
@@ -65,22 +66,31 @@ else()
# 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
- ftn
- ifort ifc af95 af90 efc f95 pathf2003 pathf95 pgf95 pgfortran lf95 xlf95
- fort gfortran gfortran-4 g95 f90 pathf90 pgf90 xlf90 epcf90 fort77
- frt pgf77 xlf fl32 af77 g77 f77 nag
- )
+ if(CMAKE_HOST_WIN32)
+ set(CMAKE_Fortran_COMPILER_LIST
+ ifort pgf95 pgfortran lf95 fort
+ flang gfortran gfortran-4 g95 f90 pgf90
+ pgf77 g77 f77 nag
+ )
+ else()
+ set(CMAKE_Fortran_COMPILER_LIST
+ ftn
+ ifort ifc efc pgf95 pgfortran lf95 xlf95 fort
+ flang gfortran gfortran-4 g95 f90 pgf90
+ frt pgf77 xlf g77 f77 nag
+ )
+ endif()
# 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_Flang flang)
set(_Fortran_COMPILER_NAMES_PathScale pathf2003 pathf95 pathf90)
set(_Fortran_COMPILER_NAMES_XL xlf)
set(_Fortran_COMPILER_NAMES_VisualAge xlf95 xlf90 xlf)
- set(_Fortran_COMPILER_NAMES_NAG nagfor)
+ set(_Fortran_COMPILER_NAMES_NAG nagfor)
endif()
_cmake_find_compiler(Fortran)
@@ -256,11 +266,18 @@ if (CMAKE_CROSSCOMPILING AND NOT _CMAKE_TOOLCHAIN_PREFIX)
endif ()
-include(CMakeFindBinUtils)
set(_CMAKE_PROCESSING_LANGUAGE "Fortran")
+include(CMakeFindBinUtils)
include(Compiler/${CMAKE_Fortran_COMPILER_ID}-FindBinUtils OPTIONAL)
unset(_CMAKE_PROCESSING_LANGUAGE)
+if(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID)
+ set(_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID
+ "set(CMAKE_Fortran_COMPILER_ARCHITECTURE_ID ${CMAKE_Fortran_COMPILER_ARCHITECTURE_ID})")
+else()
+ set(_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID "")
+endif()
+
if(MSVC_Fortran_ARCHITECTURE_ID)
set(SET_MSVC_Fortran_ARCHITECTURE_ID
"set(MSVC_Fortran_ARCHITECTURE_ID ${MSVC_Fortran_ARCHITECTURE_ID})")
diff --git a/Modules/CMakeDetermineSwiftCompiler.cmake b/Modules/CMakeDetermineSwiftCompiler.cmake
index 2604906e5..2fcf7b0be 100644
--- a/Modules/CMakeDetermineSwiftCompiler.cmake
+++ b/Modules/CMakeDetermineSwiftCompiler.cmake
@@ -1,15 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-
include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
+# Local system-specific compiler preferences for this language.
+include(Platform/${CMAKE_SYSTEM_NAME}-Determine-Swift OPTIONAL)
+include(Platform/${CMAKE_SYSTEM_NAME}-Swift OPTIONAL)
+if(NOT CMAKE_Swift_COMPILER_NAMES)
+ set(CMAKE_Swift_COMPILER_NAMES swiftc)
+endif()
+
if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
if(XCODE_VERSION VERSION_LESS 6.1)
message(FATAL_ERROR "Swift language not supported by Xcode ${XCODE_VERSION}")
endif()
set(CMAKE_Swift_COMPILER_XCODE_TYPE sourcecode.swift)
_cmake_find_compiler_path(Swift)
+elseif("${CMAKE_GENERATOR}" STREQUAL "Ninja")
+ if(CMAKE_Swift_COMPILER)
+ _cmake_find_compiler_path(Swift)
+ else()
+ set(CMAKE_Swift_COMPILER_INIT NOTFOUND)
+
+ if(NOT $ENV{SWIFTC} STREQUAL "")
+ get_filename_component(CMAKE_Swift_COMPILER_INIT $ENV{SWIFTC} PROGRAM
+ PROGRAM_ARGS CMAKE_Swift_FLAGS_ENV_INIT)
+ if(CMAKE_Swift_FLAGS_ENV_INIT)
+ set(CMAKE_Swift_COMPILER_ARG1 "${CMAKE_Swift_FLAGS_ENV_INIT}" CACHE
+ STRING "First argument to the Swift compiler")
+ endif()
+ if(NOT EXISTS ${CMAKE_Swift_COMPILER_INIT})
+ message(FATAL_ERROR "Could not find compiler set in environment variable SWIFTC\n$ENV{SWIFTC}.\n${CMAKE_Swift_COMPILER_INIT}")
+ endif()
+ endif()
+
+ if(NOT CMAKE_Swift_COMPILER_INIT)
+ set(CMAKE_Swift_COMPILER_LIST swiftc ${_CMAKE_TOOLCHAIN_PREFIX}swiftc)
+ endif()
+
+ _cmake_find_compiler(Swift)
+ endif()
+ mark_as_advanced(CMAKE_Swift_COMPILER)
else()
message(FATAL_ERROR "Swift language not supported by \"${CMAKE_GENERATOR}\" generator")
endif()
@@ -18,11 +49,13 @@ endif()
if(NOT CMAKE_Swift_COMPILER_ID_RUN)
set(CMAKE_Swift_COMPILER_ID_RUN 1)
- list(APPEND CMAKE_Swift_COMPILER_ID_MATCH_VENDORS Apple)
- set(CMAKE_Swift_COMPILER_ID_MATCH_VENDOR_REGEX_Apple "com.apple.xcode.tools.swift.compiler")
+ if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
+ list(APPEND CMAKE_Swift_COMPILER_ID_MATCH_VENDORS Apple)
+ set(CMAKE_Swift_COMPILER_ID_MATCH_VENDOR_REGEX_Apple "com.apple.xcode.tools.swift.compiler")
- set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_REGEX "\nCompileSwiftSources[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]* -c[^\r\n]*CompilerIdSwift/CompilerId/main.swift")
- set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_INDEX 2)
+ set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_REGEX "\nCompileSwiftSources[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]* -c[^\r\n]*CompilerIdSwift/CompilerId/main.swift")
+ set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_INDEX 2)
+ endif()
# Try to identify the compiler.
set(CMAKE_Swift_COMPILER_ID)
@@ -34,10 +67,12 @@ if (NOT _CMAKE_TOOLCHAIN_LOCATION)
get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Swift_COMPILER}" PATH)
endif ()
+set(_CMAKE_PROCESSING_LANGUAGE "Swift")
include(CMakeFindBinUtils)
+unset(_CMAKE_PROCESSING_LANGUAGE)
# configure variables set in this file for fast reload later on
configure_file(${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in
- ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake
- @ONLY
- )
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake @ONLY)
+
+set(CMAKE_Swift_COMPILER_ENV_VAR "SWIFTC")
diff --git a/Modules/CMakeDetermineSystem.cmake b/Modules/CMakeDetermineSystem.cmake
index 20dcf1bb5..dc208c600 100644
--- a/Modules/CMakeDetermineSystem.cmake
+++ b/Modules/CMakeDetermineSystem.cmake
@@ -2,7 +2,7 @@
# file Copyright.txt or https://cmake.org/licensing for details.
-# This module is used by the Makefile generator to determin the following variables:
+# This module is used by the Makefile generator to determine 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}
@@ -13,7 +13,6 @@
# BSD/OS BSD/OS
# FreeBSD FreeBSD
# HP-UX HP-UX
-# IRIX IRIX
# Linux Linux
# GNU/kFreeBSD GNU/kFreeBSD
# NetBSD NetBSD
diff --git a/Modules/CMakeDetermineVSServicePack.cmake b/Modules/CMakeDetermineVSServicePack.cmake
index 026462144..53868d21a 100644
--- a/Modules/CMakeDetermineVSServicePack.cmake
+++ b/Modules/CMakeDetermineVSServicePack.cmake
@@ -1,35 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CMakeDetermineVSServicePack
+---------------------------
+
+.. deprecated:: 3.0
+
+ 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
+#]=======================================================================]
if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
message(DEPRECATION
@@ -41,32 +44,32 @@ 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)
+ 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()
@@ -76,7 +79,7 @@ endfunction()
function(_DetermineVSServicePack_FastCheckVersionWithCompiler _SUCCESS_VAR _VERSION_VAR)
if(EXISTS ${CMAKE_CXX_COMPILER})
execute_process(
- COMMAND ${CMAKE_CXX_COMPILER} /?
+ COMMAND ${CMAKE_CXX_COMPILER} -?
ERROR_VARIABLE _output
OUTPUT_QUIET
)
@@ -169,4 +172,3 @@ function(DetermineVSServicePack _pack)
endif()
endif()
endfunction()
-
diff --git a/Modules/CMakeExpandImportedTargets.cmake b/Modules/CMakeExpandImportedTargets.cmake
index ad065f050..b8f471c10 100644
--- a/Modules/CMakeExpandImportedTargets.cmake
+++ b/Modules/CMakeExpandImportedTargets.cmake
@@ -1,142 +1,148 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CMakeExpandImportedTargets
-# --------------------------
-#
-# Deprecated. Do not use.
-#
-# This module was once needed to expand imported targets to the underlying
-# libraries they reference on disk for use with the :command:`try_compile`
-# and :command:`try_run` commands. These commands now support imported
-# libraries in their ``LINK_LIBRARIES`` options (since CMake 2.8.11
-# for :command:`try_compile` and since CMake 3.2 for :command:`try_run`).
-#
-# This module does not support the policy :policy:`CMP0022` ``NEW``
-# behavior or use of the :prop_tgt:`INTERFACE_LINK_LIBRARIES` property
-# because :manual:`generator expressions <cmake-generator-expressions(7)>`
-# cannot be evaluated during configuration.
-#
-# ::
-#
-# 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}.
-#
-# ::
-#
-# cmake_expand_imported_targets(expandedLibs
-# LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
-# CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}" )
+#[=======================================================================[.rst:
+CMakeExpandImportedTargets
+--------------------------
-function(CMAKE_EXPAND_IMPORTED_TARGETS _RESULT )
+.. deprecated:: 3.4
- set(options )
- set(oneValueArgs CONFIGURATION )
- set(multiValueArgs LIBRARIES )
+ Do not use.
- cmake_parse_arguments(CEIT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+This module was once needed to expand imported targets to the underlying
+libraries they reference on disk for use with the :command:`try_compile`
+and :command:`try_run` commands. These commands now support imported
+libraries in their ``LINK_LIBRARIES`` options (since CMake 2.8.11
+for :command:`try_compile` and since CMake 3.2 for :command:`try_run`).
- if(CEIT_UNPARSED_ARGUMENTS)
- message(FATAL_ERROR "Unknown keywords given to CMAKE_EXPAND_IMPORTED_TARGETS(): \"${CEIT_UNPARSED_ARGUMENTS}\"")
- endif()
+This module does not support the policy :policy:`CMP0022` ``NEW``
+behavior or use of the :prop_tgt:`INTERFACE_LINK_LIBRARIES` property
+because :manual:`generator expressions <cmake-generator-expressions(7)>`
+cannot be evaluated during configuration.
- 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})
+::
+
+ 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}.
+
+::
+
+ cmake_expand_imported_targets(expandedLibs
+ LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
+ CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}" )
+#]=======================================================================]
+
+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)
+ # Would be better to test GENERATOR_IS_MULTI_CONFIG global property,
+ # but the documented behavior specifically says we check
+ # CMAKE_CONFIGURATION_TYPES and fall back to CMAKE_BUILD_TYPE if no
+ # config types are defined.
+ 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 (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)
+ 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/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake b/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake
index 3a72622e4..11f4a29b4 100644
--- a/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake
+++ b/Modules/CMakeExtraGeneratorDetermineCompilerMacrosAndIncludeDirs.cmake
@@ -27,6 +27,7 @@ macro(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _resultIncludeDirs _resultDefines
set(_compilerExecutable "${CMAKE_C_COMPILER}")
set(_arg1 "${CMAKE_C_COMPILER_ARG1}")
endif ()
+ separate_arguments(_arg1 NATIVE_COMMAND "${_arg1}")
execute_process(COMMAND ${_compilerExecutable} ${_arg1} ${_stdver} ${_stdlib} -v -E -x ${_lang} -dD dummy
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/CMakeFiles
ERROR_VARIABLE _gccOutput
@@ -66,10 +67,10 @@ macro(_DETERMINE_GCC_SYSTEM_INCLUDE_DIRS _lang _resultIncludeDirs _resultDefines
#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()
+ if ("${_value}" STREQUAL "")
list(APPEND ${_resultDefines} " ")
+ else()
+ list(APPEND ${_resultDefines} "${_value}")
endif()
endforeach()
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake
index e4103d0b7..0e8411640 100644
--- a/Modules/CMakeFindBinUtils.cmake
+++ b/Modules/CMakeFindBinUtils.cmake
@@ -14,28 +14,65 @@
# CMAKE_AR
# CMAKE_RANLIB
# CMAKE_LINKER
+# CMAKE_MT
# CMAKE_STRIP
# CMAKE_INSTALL_NAME_TOOL
# on UNIX, cygwin and mingw
+# Resolve full path of CMAKE_TOOL from user-defined name and SEARCH_PATH.
+function(__resolve_tool_path CMAKE_TOOL SEARCH_PATH DOCSTRING)
+
+ if(${CMAKE_TOOL})
+ # We only get here if CMAKE_TOOL was
+ # specified using -D or a pre-made CMakeCache.txt (e.g. via ctest)
+ # or set in CMAKE_TOOLCHAIN_FILE.
+
+ get_filename_component(_CMAKE_USER_TOOL_PATH "${${CMAKE_TOOL}}" DIRECTORY)
+ # Is CMAKE_TOOL a user-defined name instead of a full path?
+ if(NOT _CMAKE_USER_TOOL_PATH)
+
+ # Find CMAKE_TOOL in the SEARCH_PATH directory by user-defined name.
+ find_program(_CMAKE_TOOL_WITH_PATH NAMES ${${CMAKE_TOOL}} HINTS ${SEARCH_PATH})
+ if(_CMAKE_TOOL_WITH_PATH)
+
+ # Overwrite CMAKE_TOOL with full path found in SEARCH_PATH.
+ set(${CMAKE_TOOL} ${_CMAKE_TOOL_WITH_PATH} PARENT_SCOPE)
+
+ get_property(_CMAKE_TOOL_CACHED CACHE ${CMAKE_TOOL} PROPERTY TYPE)
+ # If CMAKE_TOOL is present in the CMake Cache, then overwrit it as well.
+ if(_CMAKE_TOOL_CACHED)
+ set(${CMAKE_TOOL} "${_CMAKE_TOOL_WITH_PATH}" CACHE STRING ${DOCSTRING} FORCE)
+ endif()
+
+ endif()
+ unset(_CMAKE_TOOL_WITH_PATH CACHE)
+
+ endif()
+
+ endif()
+
+endfunction()
+
+__resolve_tool_path(CMAKE_LINKER "${_CMAKE_TOOLCHAIN_LOCATION}" "Default Linker")
+__resolve_tool_path(CMAKE_MT "${_CMAKE_TOOLCHAIN_LOCATION}" "Default Manifest Tool")
+
+set(_CMAKE_TOOL_VARS "")
+
# if it's the MS C/CXX compiler, search for link
-if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC"
- OR (CMAKE_HOST_WIN32 AND (
- "x${CMAKE_C_COMPILER_ID}" STREQUAL "xPGI"
- OR "x${CMAKE_Fortran_COMPILER_ID}" STREQUAL "xPGI"
- ))
+if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND
+ ("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC"
+ OR NOT "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang"))
+ OR "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xMSVC"
+ OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xPGI")
+ OR (CMAKE_HOST_WIN32 AND "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xNVIDIA")
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})
+ find_program(CMAKE_MT NAMES mt HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
- mark_as_advanced(CMAKE_LINKER)
+ list(APPEND _CMAKE_TOOL_VARS CMAKE_LINKER CMAKE_MT)
# in all other cases search for ar, ranlib, etc.
else()
@@ -45,20 +82,29 @@ else()
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("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL Clang)
+ set(LLVM_OBJDUMP "llvm-objdump")
+ set(LLVM_LLD "ld.lld")
+ set(LLVM_RANLIB "llvm-ranlib")
+ set(LLVM_AR "llvm-ar")
+ endif()
+
+ find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} ${LLVM_AR} HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
+
+ find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib ${LLVM_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_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld ${LLVM_LLD} 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_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump ${LLVM_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)
+ list(APPEND _CMAKE_TOOL_VARS CMAKE_AR CMAKE_RANLIB CMAKE_STRIP CMAKE_LINKER CMAKE_NM CMAKE_OBJDUMP CMAKE_OBJCOPY)
endif()
@@ -69,5 +115,15 @@ if(CMAKE_PLATFORM_HAS_INSTALLNAME)
message(FATAL_ERROR "Could not find install_name_tool, please check your installation.")
endif()
- mark_as_advanced(CMAKE_INSTALL_NAME_TOOL)
+ list(APPEND _CMAKE_TOOL_VARS CMAKE_INSTALL_NAME_TOOL)
endif()
+
+# Mark any tool cache entries as advanced.
+foreach(var IN LISTS _CMAKE_TOOL_VARS)
+ get_property(_CMAKE_TOOL_CACHED CACHE ${var} PROPERTY TYPE)
+ if(_CMAKE_TOOL_CACHED)
+ mark_as_advanced(${var})
+ endif()
+endforeach()
+unset(_CMAKE_TOOL_VARS)
+unset(_CMAKE_TOOL_CACHED)
diff --git a/Modules/CMakeFindCodeBlocks.cmake b/Modules/CMakeFindCodeBlocks.cmake
index b76e5c57f..bf27ec111 100644
--- a/Modules/CMakeFindCodeBlocks.cmake
+++ b/Modules/CMakeFindCodeBlocks.cmake
@@ -8,7 +8,7 @@
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>" )
+ set(CMAKE_OPEN_PROJECT_COMMAND "${CMAKE_CODEBLOCKS_EXECUTABLE} <PROJECT_FILE>" )
endif()
# Determine builtin macros and include dirs:
@@ -28,3 +28,6 @@ endif()
# This variable is used by the CodeBlocks generator and appended to the make invocation commands.
set(CMAKE_CODEBLOCKS_MAKE_ARGUMENTS "${_CMAKE_CODEBLOCKS_INITIAL_MAKE_ARGS}" CACHE STRING "Additional command line arguments when CodeBlocks invokes make. Enter e.g. -j<some_number> to get parallel builds")
+
+# This variable is used by the CodeBlocks generator and allows the user to overwrite the autodetected CodeBlocks compiler id
+set(CMAKE_CODEBLOCKS_COMPILER_ID "" CACHE STRING "Id string of the compiler for the CodeBlocks IDE. Automatically detected when left empty")
diff --git a/Modules/CMakeFindDependencyMacro.cmake b/Modules/CMakeFindDependencyMacro.cmake
index 81606cef6..bcdfbebe3 100644
--- a/Modules/CMakeFindDependencyMacro.cmake
+++ b/Modules/CMakeFindDependencyMacro.cmake
@@ -1,55 +1,63 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CMakeFindDependencyMacro
-# -------------------------
-#
-# ::
-#
-# find_dependency(<dep> [...])
-#
-#
-# ``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 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.
-#
-# Any additional arguments specified are forwarded to :command:`find_package`.
-#
+#[=======================================================================[.rst:
+CMakeFindDependencyMacro
+-------------------------
+
+.. command:: find_dependency
+
+ The ``find_dependency()`` macro wraps a :command:`find_package` call for
+ a package dependency::
+
+ find_dependency(<dep> [...])
+
+ It is designed to be used in a
+ :ref:`Package Configuration File <Config File Packages>`
+ (``<PackageName>Config.cmake``). ``find_dependency`` forwards the correct
+ parameters for ``QUIET`` and ``REQUIRED`` which were passed to
+ the original :command:`find_package` call. Any additional arguments
+ specified are forwarded to :command:`find_package`.
+
+ If the dependency could not be found it sets an informative diagnostic
+ message and calls :command:`return` to end processing of the calling
+ package configuration file and return to the :command:`find_package`
+ command that loaded it.
+
+ .. note::
+
+ The call to :command:`return` makes this macro unsuitable to call
+ from :ref:`Find Modules`.
+#]=======================================================================]
macro(find_dependency dep)
+ 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} ${ARGN}
+ ${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_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} ${ARGN}
- ${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_required_arg)
- set(cmake_fd_quiet_arg)
- set(cmake_fd_exact_arg)
+ 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_required_arg)
+ set(cmake_fd_quiet_arg)
endmacro()
diff --git a/Modules/CMakeFindFrameworks.cmake b/Modules/CMakeFindFrameworks.cmake
index 6c4c52729..06c05fb91 100644
--- a/Modules/CMakeFindFrameworks.cmake
+++ b/Modules/CMakeFindFrameworks.cmake
@@ -1,15 +1,16 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CMakeFindFrameworks
-# -------------------
-#
-# helper module to find OSX frameworks
-#
-# This module reads hints about search locations from variables::
-#
-# CMAKE_FIND_FRAMEWORK_EXTRA_LOCATIONS - Extra directories
+#[=======================================================================[.rst:
+CMakeFindFrameworks
+-------------------
+
+helper module to find OSX frameworks
+
+This module reads hints about search locations from variables::
+
+ CMAKE_FIND_FRAMEWORK_EXTRA_LOCATIONS - Extra directories
+#]=======================================================================]
if(NOT CMAKE_FIND_FRAMEWORKS_INCLUDED)
set(CMAKE_FIND_FRAMEWORKS_INCLUDED 1)
diff --git a/Modules/CMakeFindPackageMode.cmake b/Modules/CMakeFindPackageMode.cmake
index 1261137c1..815dfc90d 100644
--- a/Modules/CMakeFindPackageMode.cmake
+++ b/Modules/CMakeFindPackageMode.cmake
@@ -1,33 +1,34 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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/Fortran/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
+#]=======================================================================]
if(NOT NAME)
message(FATAL_ERROR "Name of the package to be searched not specified. Set the CMake variable NAME, e.g. -DNAME=JPEG .")
@@ -65,6 +66,8 @@ if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin AND "${COMPILER_ID}" MATCHES GNU)
set(CMAKE_${LANGUAGE}_OSX_DEPLOYMENT_TARGET_FLAG "")
endif()
+include(CMakeSystemSpecificInitialize)
+
# 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/CMakeForceCompiler.cmake b/Modules/CMakeForceCompiler.cmake
index 1bc80fd75..704880631 100644
--- a/Modules/CMakeForceCompiler.cmake
+++ b/Modules/CMakeForceCompiler.cmake
@@ -1,69 +1,75 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CMakeForceCompiler
-# ------------------
-#
-# Deprecated. Do not use.
-#
-# The macros provided by this module were once intended for use by
-# cross-compiling toolchain files when CMake was not able to automatically
-# detect the compiler identification. Since the introduction of this module,
-# CMake's compiler identification capabilities have improved and can now be
-# taught to recognize any compiler. Furthermore, the suite of information
-# CMake detects from a compiler is now too extensive to be provided by
-# toolchain files using these macros.
-#
-# One common use case for this module was to skip CMake's checks for a
-# working compiler when using a cross-compiler that cannot link binaries
-# without special flags or custom linker scripts. This case is now supported
-# by setting the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable in the
-# toolchain file instead.
-#
-# -------------------------------------------------------------------------
-#
-# 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)
+#[=======================================================================[.rst:
+CMakeForceCompiler
+------------------
+
+.. deprecated:: 3.6
+
+ Do not use.
+
+The macros provided by this module were once intended for use by
+cross-compiling toolchain files when CMake was not able to automatically
+detect the compiler identification. Since the introduction of this module,
+CMake's compiler identification capabilities have improved and can now be
+taught to recognize any compiler. Furthermore, the suite of information
+CMake detects from a compiler is now too extensive to be provided by
+toolchain files using these macros.
+
+One common use case for this module was to skip CMake's checks for a
+working compiler when using a cross-compiler that cannot link binaries
+without special flags or custom linker scripts. This case is now supported
+by setting the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable in the
+toolchain file instead.
+
+-------------------------------------------------------------------------
+
+Macro ``CMAKE_FORCE_C_COMPILER`` has the following signature:
+
+::
+
+ CMAKE_FORCE_C_COMPILER(<compiler> <compiler-id>)
+
+It sets :variable:`CMAKE_C_COMPILER <CMAKE_<LANG>_COMPILER>` to
+the given compiler and the cmake internal variable
+:variable:`CMAKE_C_COMPILER_ID <CMAKE_<LANG>_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 :variable:`CMAKE_CXX_COMPILER <CMAKE_<LANG>_COMPILER>` to
+the given compiler and the cmake internal variable
+:variable:`CMAKE_CXX_COMPILER_ID <CMAKE_<LANG>_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 :variable:`CMAKE_Fortran_COMPILER <CMAKE_<LANG>_COMPILER>` to
+the given compiler and the cmake internal variable
+:variable:`CMAKE_Fortran_COMPILER_ID <CMAKE_<LANG>_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)
+#]=======================================================================]
macro(CMAKE_FORCE_C_COMPILER compiler id)
message(DEPRECATION "The CMAKE_FORCE_C_COMPILER macro is deprecated. "
diff --git a/Modules/CMakeFortranCompiler.cmake.in b/Modules/CMakeFortranCompiler.cmake.in
index d52119050..ae7b73ac4 100644
--- a/Modules/CMakeFortranCompiler.cmake.in
+++ b/Modules/CMakeFortranCompiler.cmake.in
@@ -6,6 +6,7 @@ set(CMAKE_Fortran_COMPILER_WRAPPER "@CMAKE_Fortran_COMPILER_WRAPPER@")
set(CMAKE_Fortran_PLATFORM_ID "@CMAKE_Fortran_PLATFORM_ID@")
set(CMAKE_Fortran_SIMULATE_ID "@CMAKE_Fortran_SIMULATE_ID@")
set(CMAKE_Fortran_SIMULATE_VERSION "@CMAKE_Fortran_SIMULATE_VERSION@")
+@_SET_CMAKE_Fortran_COMPILER_ARCHITECTURE_ID@
@SET_MSVC_Fortran_ARCHITECTURE_ID@
set(CMAKE_AR "@CMAKE_AR@")
set(CMAKE_Fortran_COMPILER_AR "@CMAKE_Fortran_COMPILER_AR@")
@@ -30,7 +31,7 @@ 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_SOURCE_FILE_EXTENSIONS f;F;fpp;FPP;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)
@@ -60,6 +61,7 @@ endif()
@CMAKE_Fortran_SYSROOT_FLAG_CODE@
@CMAKE_Fortran_OSX_DEPLOYMENT_TARGET_FLAG_CODE@
+set(CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES "@CMAKE_Fortran_IMPLICIT_INCLUDE_DIRECTORIES@")
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
index b34c28484..f4a5489a1 100644
--- a/Modules/CMakeFortranCompilerABI.F
+++ b/Modules/CMakeFortranCompilerABI.F
@@ -33,13 +33,7 @@
#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__)
+#if defined(__ELF__)
PRINT *, 'INFO:abi[ELF]'
#endif
PRINT *, 'ABI Detection'
diff --git a/Modules/CMakeFortranCompilerId.F.in b/Modules/CMakeFortranCompilerId.F.in
index 26b2ed656..30f8d4c45 100644
--- a/Modules/CMakeFortranCompilerId.F.in
+++ b/Modules/CMakeFortranCompilerId.F.in
@@ -2,6 +2,26 @@
#if 0
! Identify the compiler
#endif
+#if defined(_MSC_VER)
+ PRINT *, 'INFO:simulate[MSVC]'
+# if _MSC_VER >= 1900
+ PRINT *, 'INFO:simulate_version[019.00]'
+# elif _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
#if defined(__INTEL_COMPILER) || defined(__ICC)
PRINT *, 'INFO:compiler[Intel]'
# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100)
@@ -14,27 +34,6 @@
# if defined(__INTEL_COMPILER_BUILD_DATE)
# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE)
# endif
-
-# if defined(_MSC_VER)
- PRINT *, 'INFO:simulate[MSVC]'
-# if _MSC_VER >= 1900
- PRINT *, 'INFO:simulate_version[019.00]'
-# elif _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_F95)
PRINT *, 'INFO:compiler[SunPro]'
# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_F95>>8)
@@ -90,17 +89,15 @@
# if defined(__PGIC_PATCHLEVEL__)
# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__)
# endif
-#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(__FLANG)
+ PRINT *, 'INFO:compiler[Flang]'
+# define COMPILER_VERSION_MAJOR DEC(__FLANG_MAJOR__)
+# define COMPILER_VERSION_MINOR DEC(__FLANG_MINOR__)
+# if defined(__FLANG_PATCHLEVEL__)
+# define COMPILER_VERSION_PATCH DEC(__FLANG_PATCHLEVEL__)
+# 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 defined(NAGFOR)
@@ -108,11 +105,7 @@
#define COMPILER_VERSION_MAJOR DEC(__NAG_COMPILER_RELEASE/10)
#define COMPILER_VERSION_MINOR DEC(__NAG_COMPILER_RELEASE % 10)
#define COMPILER_VERSION_PATCH DEC(__NAG_COMPILER_BUILD)
-#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
+#else
PRINT *, 'INFO:compiler[]'
#endif
#if defined(__CRAYXE) || defined(__CRAYXC)
@@ -142,8 +135,6 @@
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__)
@@ -172,11 +163,7 @@
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
+#else
PRINT *, 'INFO:platform[]'
#endif
#if defined(_WIN32) && (defined(__INTEL_COMPILER) || defined(__ICC))
diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake
index 8005da6e4..ffa6a2471 100644
--- a/Modules/CMakeFortranInformation.cmake
+++ b/Modules/CMakeFortranInformation.cmake
@@ -22,10 +22,10 @@ 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)
+ include(Platform/${CMAKE_EFFECTIVE_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
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
RESULT_VARIABLE _INCLUDED_FILE)
endif ()
@@ -67,11 +67,6 @@ if(CMAKE_USER_MAKE_RULES_OVERRIDE_Fortran)
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()
@@ -79,6 +74,12 @@ endif()
if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIE)
set(CMAKE_Fortran_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE})
endif()
+if(NOT CMAKE_Fortran_LINK_OPTIONS_PIE)
+ set(CMAKE_Fortran_LINK_OPTIONS_PIE ${CMAKE_C_LINK_OPTIONS_PIE})
+endif()
+if(NOT CMAKE_Fortran_LINK_OPTIONS_NO_PIE)
+ set(CMAKE_Fortran_LINK_OPTIONS_NO_PIE ${CMAKE_C_LINK_OPTIONS_NO_PIE})
+endif()
if(NOT CMAKE_Fortran_COMPILE_OPTIONS_DLL)
set(CMAKE_Fortran_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL})
@@ -156,20 +157,11 @@ 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}")
-foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
- string(STRIP "${CMAKE_Fortran_FLAGS${c}_INIT}" CMAKE_Fortran_FLAGS${c}_INIT)
-endforeach()
-
-set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS_INIT}" CACHE STRING
- "Flags for Fortran compiler.")
+cmake_initialize_per_config_variable(CMAKE_Fortran_FLAGS "Flags used by the Fortran compiler")
include(CMakeCommonLanguageInclude)
@@ -221,24 +213,5 @@ if(CMAKE_Fortran_STANDARD_LIBRARIES_INIT)
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
index cd052376b..ddfc7bd23 100644
--- a/Modules/CMakeGenericSystem.cmake
+++ b/Modules/CMakeGenericSystem.cmake
@@ -1,6 +1,7 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
+include(CMakeInitializeConfigs)
set(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared") # -shared
@@ -8,7 +9,6 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use
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")
@@ -24,6 +24,10 @@ set(CMAKE_DL_LIBS "dl")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
+set(CMAKE_AUTOGEN_ORIGIN_DEPENDS ON)
+set(CMAKE_AUTOMOC_COMPILER_PREDEFINES ON)
+set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_NAMESPACE")
+
# basically all general purpose OSs support shared libs
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
@@ -76,6 +80,8 @@ function(GetDefaultWindowsPrefixBase var)
#
if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
set(arch_hint "x64")
+ elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
+ set(arch_hint "ARM64")
elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
set(arch_hint "ARM")
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
diff --git a/Modules/CMakeGraphVizOptions.cmake b/Modules/CMakeGraphVizOptions.cmake
index 420e3a9e7..1911e7392 100644
--- a/Modules/CMakeGraphVizOptions.cmake
+++ b/Modules/CMakeGraphVizOptions.cmake
@@ -1,119 +1,123 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 --graphviz=foo.dot 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"
-#
-# Valid graph types are:
-#
-# * "graph" : Nodes are joined with lines
-# * "digraph" : Nodes are joined with arrows showing direction
-# * "strict graph" : Like "graph" but max one line between each node
-# * "strict digraph" : Like "graph" but max one line between each node in each direction
-#
-# .. 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
+#[=======================================================================[.rst:
+CMakeGraphVizOptions
+--------------------
+
+The builtin graphviz support of CMake.
+
+Variables specific to the graphviz support
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+CMake
+can generate `graphviz <http://www.graphviz.org/>`_ files, showing the dependencies between the
+targets in a project and also external libraries which are linked
+against. When CMake is run with the ``--graphviz=foo.dot`` 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
+
+The different dependency types ``PUBLIC``, ``PRIVATE`` and ``INTERFACE``
+are represented as solid, dashed and dotted edges.
+
+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
+:variable:`CMAKE_BINARY_DIR` and then in :variable:`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"
+
+ Valid graph types are:
+
+ * "graph" : Nodes are joined with lines
+ * "digraph" : Nodes are joined with arrows showing direction
+ * "strict graph" : Like "graph" but max one line between each node
+ * "strict digraph" : Like "graph" but max one line between each node in each direction
+
+.. 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
+#]=======================================================================]
diff --git a/Modules/CMakeIOSInstallCombined.cmake b/Modules/CMakeIOSInstallCombined.cmake
index fad2e8f69..418bafd63 100644
--- a/Modules/CMakeIOSInstallCombined.cmake
+++ b/Modules/CMakeIOSInstallCombined.cmake
@@ -1,6 +1,8 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
# Function to print messages of this module
function(_ios_install_combined_message)
@@ -57,6 +59,7 @@ endfunction()
# Get architectures of given SDK (iphonesimulator/iphoneos)
function(_ios_install_combined_get_valid_archs sdk resultvar)
+ cmake_policy(PUSH)
cmake_policy(SET CMP0007 NEW)
if("${resultvar}" STREQUAL "")
@@ -73,6 +76,8 @@ function(_ios_install_combined_get_valid_archs sdk resultvar)
_ios_install_combined_message("Architectures (${sdk}): ${printable}")
set("${resultvar}" "${valid_archs}" PARENT_SCOPE)
+
+ cmake_policy(POP)
endfunction()
# Final target can contain more architectures that specified by SDK. This
@@ -161,8 +166,6 @@ function(_ios_install_combined_keep_archs lib archs)
endfunction()
function(_ios_install_combined_detect_sdks this_sdk_var corr_sdk_var)
- cmake_policy(SET CMP0057 NEW)
-
set(this_sdk "$ENV{PLATFORM_NAME}")
if("${this_sdk}" STREQUAL "")
message(FATAL_ERROR "Environment variable PLATFORM_NAME is empty")
@@ -305,3 +308,5 @@ function(ios_install_combined target destination)
_ios_install_combined_message("Install done: ${destination}")
endfunction()
+
+cmake_policy(POP)
diff --git a/Modules/CMakeJavaInformation.cmake b/Modules/CMakeJavaInformation.cmake
index 844bbbbbf..989afc11b 100644
--- a/Modules/CMakeJavaInformation.cmake
+++ b/Modules/CMakeJavaInformation.cmake
@@ -16,8 +16,8 @@ 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}")
+ 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.
@@ -30,7 +30,7 @@ if(NOT CMAKE_Java_CREATE_STATIC_LIBRARY)
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
+ # "${class_files_mask}" should really be "<OBJECTS>" but compiling a *.java
# file can create more than one *.class file...
endif()
diff --git a/Modules/CMakeLanguageInformation.cmake b/Modules/CMakeLanguageInformation.cmake
index 18c8624fa..674ab8696 100644
--- a/Modules/CMakeLanguageInformation.cmake
+++ b/Modules/CMakeLanguageInformation.cmake
@@ -9,10 +9,10 @@
macro(__cmake_include_compiler_wrapper lang)
set(_INCLUDED_WRAPPER_FILE 0)
if (CMAKE_${lang}_COMPILER_ID)
- include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_${lang}_COMPILER_WRAPPER}-${CMAKE_${lang}_COMPILER_ID}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_${lang}_COMPILER_WRAPPER}-${CMAKE_${lang}_COMPILER_ID}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
endif()
if (NOT _INCLUDED_WRAPPER_FILE)
- include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_${lang}_COMPILER_WRAPPER}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_${lang}_COMPILER_WRAPPER}-${lang} OPTIONAL RESULT_VARIABLE _INCLUDED_WRAPPER_FILE)
endif ()
# No platform - wrapper - lang information so maybe there's just wrapper - lang information
diff --git a/Modules/CMakeNinjaFindMake.cmake b/Modules/CMakeNinjaFindMake.cmake
index 6a0c47eec..702af1338 100644
--- a/Modules/CMakeNinjaFindMake.cmake
+++ b/Modules/CMakeNinjaFindMake.cmake
@@ -3,6 +3,6 @@
find_program(CMAKE_MAKE_PROGRAM
- NAMES ninja-build ninja
+ NAMES ninja-build ninja samu
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
index 90c2a5719..22fc95366 100644
--- a/Modules/CMakePackageConfigHelpers.cmake
+++ b/Modules/CMakePackageConfigHelpers.cmake
@@ -1,205 +1,223 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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``:
-#
-# ::
-#
-# 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)
+#[=======================================================================[.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 ``<PackageName>Config.cmake``
+or ``<PackageName>-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(<PackageName>)`` should be called at the end of
+the ``FooConfig.cmake`` file. 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. This macro should be
+called even if the package doesn't provide any components to make sure
+users are not specifying components erroneously. 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|SameMinorVersion|ExactVersion>
+ [ARCH_INDEPENDENT] )
+
+
+Writes a file for use as ``<PackageName>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 ``SameMinorVersion`` is used, the behaviour is the same as
+``SameMajorVersion``, but both major and minor version must be the same as
+requested, e.g version 0.2 will not be compatible if 0.1 is requested.
+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.
+
+If ``ARCH_INDEPENDENT`` is given, the installed package version will be
+considered compatible even if it was built for a different architecture than
+the requested architecture. Otherwise, an architecture check will be performed,
+and the package will be considered compatible only if the architecture matches
+exactly. For example, if the package is built for a 32-bit architecture, the
+package is only considered compatible if it is used on a 32-bit architecture,
+unless ``ARCH_INDEPENDENT`` is given, in which case the package is considered
+compatible on any architecture.
+
+.. note:: ``ARCH_INDEPENDENT`` is intended for header-only libraries or similar
+ packages with no binaries.
+
+Internally, this macro executes :command:`configure_file()` to create the
+resulting version file. Depending on the ``COMPATIBILITY``, the corresponding
+``BasicConfigVersion-<COMPATIBILITY>.cmake.in`` file is used.
+Please note that these 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``:
+
+::
+
+ 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)
+#]=======================================================================]
include(WriteBasicConfigVersionFile)
diff --git a/Modules/CMakeParseArguments.cmake b/Modules/CMakeParseArguments.cmake
index 7ee2bbace..c753b7f51 100644
--- a/Modules/CMakeParseArguments.cmake
+++ b/Modules/CMakeParseArguments.cmake
@@ -1,11 +1,12 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CMakeParseArguments
-# -------------------
-#
-# This module once implemented the :command:`cmake_parse_arguments` command
-# that is now implemented natively by CMake. It is now an empty placeholder
-# for compatibility with projects that include it to get the command from
-# CMake 3.4 and lower.
+#[=======================================================================[.rst:
+CMakeParseArguments
+-------------------
+
+This module once implemented the :command:`cmake_parse_arguments` command
+that is now implemented natively by CMake. It is now an empty placeholder
+for compatibility with projects that include it to get the command from
+CMake 3.4 and lower.
+#]=======================================================================]
diff --git a/Modules/CMakeParseImplicitLinkInfo.cmake b/Modules/CMakeParseImplicitLinkInfo.cmake
index 3b772784b..30659ebcb 100644
--- a/Modules/CMakeParseImplicitLinkInfo.cmake
+++ b/Modules/CMakeParseImplicitLinkInfo.cmake
@@ -1,6 +1,9 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
+cmake_policy(PUSH)
+cmake_policy(SET CMP0053 NEW)
+cmake_policy(SET CMP0054 NEW)
# Function parse implicit linker options.
# This is used internally by CMake and should not be included by user
@@ -142,7 +145,7 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj
# We remove items that are not language-specific.
set(implicit_libs "")
foreach(lib IN LISTS implicit_libs_tmp)
- if("x${lib}" MATCHES "^x(crt.*\\.o|System.*|.*libclang_rt.*|msvcrt.*|libvcruntime.*|libucrt.*|libcmt.*)$")
+ if("x${lib}" MATCHES "^x(crt.*\\.o|gcc_eh.*|.*libgcc_eh.*|System.*|.*libclang_rt.*|msvcrt.*|libvcruntime.*|libucrt.*|libcmt.*)$")
string(APPEND log " remove lib [${lib}]\n")
elseif(IS_ABSOLUTE "${lib}")
get_filename_component(abs "${lib}" ABSOLUTE)
@@ -185,3 +188,5 @@ function(CMAKE_PARSE_IMPLICIT_LINK_INFO text lib_var dir_var fwk_var log_var obj
set(${fwk_var} "${implicit_fwks}" PARENT_SCOPE)
set(${log_var} "${log}" PARENT_SCOPE)
endfunction()
+
+cmake_policy(POP)
diff --git a/Modules/CMakePlatformId.h.in b/Modules/CMakePlatformId.h.in
index 47eb00a39..542a6fe3c 100644
--- a/Modules/CMakePlatformId.h.in
+++ b/Modules/CMakePlatformId.h.in
@@ -32,9 +32,6 @@
#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"
@@ -94,6 +91,14 @@
# define PLATFORM_ID
# endif
+#elif defined(__INTEGRITY)
+# if defined(INT_178B)
+# define PLATFORM_ID "Integrity178"
+
+# else /* regular Integrity */
+# define PLATFORM_ID "Integrity"
+# endif
+
#else /* unknown platform */
# define PLATFORM_ID
@@ -114,6 +119,9 @@
# elif defined(_M_IX86)
# define ARCHITECTURE_ID "X86"
+# elif defined(_M_ARM64)
+# define ARCHITECTURE_ID "ARM64"
+
# elif defined(_M_ARM)
# if _M_ARM == 4
# define ARCHITECTURE_ID "ARMV4I"
@@ -144,6 +152,51 @@
# define ARCHITECTURE_ID ""
# endif
+#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
+# if defined(__ICCARM__)
+# define ARCHITECTURE_ID "ARM"
+
+# elif defined(__ICCRX__)
+# define ARCHITECTURE_ID "RX"
+
+# elif defined(__ICCRH850__)
+# define ARCHITECTURE_ID "RH850"
+
+# elif defined(__ICCRL78__)
+# define ARCHITECTURE_ID "RL78"
+
+# elif defined(__ICCRISCV__)
+# define ARCHITECTURE_ID "RISCV"
+
+# elif defined(__ICCAVR__)
+# define ARCHITECTURE_ID "AVR"
+
+# elif defined(__ICC430__)
+# define ARCHITECTURE_ID "MSP430"
+
+# else /* unknown architecture */
+# define ARCHITECTURE_ID ""
+# endif
+
+#elif defined(__ghs__)
+# if defined(__PPC64__)
+# define ARCHITECTURE_ID "PPC64"
+
+# elif defined(__ppc__)
+# define ARCHITECTURE_ID "PPC"
+
+# elif defined(__ARM__)
+# define ARCHITECTURE_ID "ARM"
+
+# elif defined(__x86_64__)
+# define ARCHITECTURE_ID "x64"
+
+# elif defined(__i386__)
+# define ARCHITECTURE_ID "X86"
+
+# else /* unknown architecture */
+# define ARCHITECTURE_ID ""
+# endif
#else
# define ARCHITECTURE_ID
#endif
@@ -188,6 +241,15 @@ char const info_version[] = {
']','\0'};
#endif
+/* Construct a string literal encoding the internal version number. */
+#ifdef COMPILER_VERSION_INTERNAL
+char const info_version_internal[] = {
+ 'I', 'N', 'F', 'O', ':',
+ 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','_',
+ 'i','n','t','e','r','n','a','l','[',
+ COMPILER_VERSION_INTERNAL,']','\0'};
+#endif
+
/* Construct a string literal encoding the version number components. */
#ifdef SIMULATE_VERSION_MAJOR
char const info_simulate_version[] = {
diff --git a/Modules/CMakePrintHelpers.cmake b/Modules/CMakePrintHelpers.cmake
index 21c333e31..aa40b59ca 100644
--- a/Modules/CMakePrintHelpers.cmake
+++ b/Modules/CMakePrintHelpers.cmake
@@ -1,57 +1,59 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 DOES_NOT_EXIST)
-#
-# Gives::
-#
-# -- CMAKE_C_COMPILER="/usr/bin/gcc" ; CMAKE_MAJOR_VERSION="2" ; DOES_NOT_EXIST=""
-
-function(CMAKE_PRINT_VARIABLES)
- set(msg "")
- foreach(var ${ARGN})
- if(msg)
- string(APPEND msg " ; ")
- endif()
- string(APPEND msg "${var}=\"${${var}}\"")
- endforeach()
- message(STATUS "${msg}")
+#[=======================================================================[.rst:
+CMakePrintHelpers
+-----------------
+
+Convenience functions 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 function 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 function will print the name of each variable followed by its value.
+Example::
+
+ cmake_print_variables(CMAKE_C_COMPILER CMAKE_MAJOR_VERSION DOES_NOT_EXIST)
+
+Gives::
+
+ -- CMAKE_C_COMPILER="/usr/bin/gcc" ; CMAKE_MAJOR_VERSION="2" ; DOES_NOT_EXIST=""
+#]=======================================================================]
+
+function(cmake_print_variables)
+ set(msg "")
+ foreach(var ${ARGN})
+ if(msg)
+ string(APPEND msg " ; ")
+ endif()
+ string(APPEND msg "${var}=\"${${var}}\"")
+ endforeach()
+ message(STATUS "${msg}")
endfunction()
-function(CMAKE_PRINT_PROPERTIES )
+function(cmake_print_properties)
set(options )
set(oneValueArgs )
set(multiValueArgs TARGETS SOURCES TESTS DIRECTORIES CACHE_ENTRIES PROPERTIES )
diff --git a/Modules/CMakePrintSystemInformation.cmake b/Modules/CMakePrintSystemInformation.cmake
index e74c801db..f873a4d97 100644
--- a/Modules/CMakePrintSystemInformation.cmake
+++ b/Modules/CMakePrintSystemInformation.cmake
@@ -1,14 +1,15 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
message("CMAKE_SYSTEM is ${CMAKE_SYSTEM} ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
message("CMAKE_SYSTEM file is ${CMAKE_SYSTEM_INFO_FILE}")
diff --git a/Modules/CMakePushCheckState.cmake b/Modules/CMakePushCheckState.cmake
index 2a527d5bd..3e519ee51 100644
--- a/Modules/CMakePushCheckState.cmake
+++ b/Modules/CMakePushCheckState.cmake
@@ -1,86 +1,91 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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, CMAKE_REQUIRED_INCLUDES and CMAKE_EXTRA_INCLUDE_FILES
-# 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()
+#[=======================================================================[.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_LINK_OPTIONS``, ``CMAKE_REQUIRED_LIBRARIES``,
+``CMAKE_REQUIRED_INCLUDES`` and ``CMAKE_EXTRA_INCLUDE_FILES`` 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:
+
+.. code-block:: cmake
+
+ 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()
+#]=======================================================================]
macro(CMAKE_RESET_CHECK_STATE)
- set(CMAKE_EXTRA_INCLUDE_FILES)
- set(CMAKE_REQUIRED_INCLUDES)
- set(CMAKE_REQUIRED_DEFINITIONS)
- set(CMAKE_REQUIRED_LIBRARIES)
- set(CMAKE_REQUIRED_FLAGS)
- set(CMAKE_REQUIRED_QUIET)
+ set(CMAKE_EXTRA_INCLUDE_FILES)
+ set(CMAKE_REQUIRED_INCLUDES)
+ set(CMAKE_REQUIRED_DEFINITIONS)
+ set(CMAKE_REQUIRED_LINK_OPTIONS)
+ 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()
+ 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")
+ math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}+1")
- set(_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_EXTRA_INCLUDE_FILES})
- 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})
+ set(_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_EXTRA_INCLUDE_FILES})
+ 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_LINK_OPTIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LINK_OPTIONS})
+ 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()
+ 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")
+ if("${_CMAKE_PUSH_CHECK_STATE_COUNTER}" GREATER "0")
- set(CMAKE_EXTRA_INCLUDE_FILES ${_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
- 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}})
+ set(CMAKE_EXTRA_INCLUDE_FILES ${_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
+ 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_LINK_OPTIONS ${_CMAKE_REQUIRED_LINK_OPTIONS_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()
+ math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}-1")
+ endif()
endmacro()
diff --git a/Modules/CMakeRCInformation.cmake b/Modules/CMakeRCInformation.cmake
index a34028867..7bf656775 100644
--- a/Modules/CMakeRCInformation.cmake
+++ b/Modules/CMakeRCInformation.cmake
@@ -19,23 +19,7 @@ include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL)
set(CMAKE_RC_FLAGS_INIT "$ENV{RCFLAGS} ${CMAKE_RC_FLAGS_INIT}")
-foreach(c "" _DEBUG _RELEASE _MINSIZEREL _RELWITHDEBINFO)
- string(STRIP "${CMAKE_RC_FLAGS${c}_INIT}" CMAKE_RC_FLAGS${c}_INIT)
-endforeach()
-
-set (CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS_INIT}" CACHE STRING
- "Flags for Windows Resource Compiler.")
-
-if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
- set (CMAKE_RC_FLAGS_DEBUG "${CMAKE_RC_FLAGS_DEBUG_INIT}" CACHE STRING
- "Flags for Windows Resource Compiler during debug builds.")
- set (CMAKE_RC_FLAGS_MINSIZEREL "${CMAKE_RC_FLAGS_MINSIZEREL_INIT}" CACHE STRING
- "Flags for Windows Resource Compiler during release builds for minimum size.")
- set (CMAKE_RC_FLAGS_RELEASE "${CMAKE_RC_FLAGS_RELEASE_INIT}" CACHE STRING
- "Flags for Windows Resource Compiler during release builds.")
- set (CMAKE_RC_FLAGS_RELWITHDEBINFO "${CMAKE_RC_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
- "Flags for Windows Resource Compiler during release builds with debug info.")
-endif()
+cmake_initialize_per_config_variable(CMAKE_RC_FLAGS "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
@@ -48,15 +32,8 @@ 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> <DEFINES> <INCLUDES> <FLAGS> /fo<OBJECT> <SOURCE>")
+ "<CMAKE_RC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> /fo <OBJECT> <SOURCE>")
endif()
-mark_as_advanced(
-CMAKE_RC_FLAGS
-CMAKE_RC_FLAGS_DEBUG
-CMAKE_RC_FLAGS_MINSIZEREL
-CMAKE_RC_FLAGS_RELEASE
-CMAKE_RC_FLAGS_RELWITHDEBINFO
-)
# set this variable so we can avoid loading this more than once.
set(CMAKE_RC_INFORMATION_LOADED 1)
diff --git a/Modules/CMakeSwiftCompiler.cmake.in b/Modules/CMakeSwiftCompiler.cmake.in
index 45f0a3105..7c8d1c19a 100644
--- a/Modules/CMakeSwiftCompiler.cmake.in
+++ b/Modules/CMakeSwiftCompiler.cmake.in
@@ -1,5 +1,14 @@
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
set(CMAKE_Swift_COMPILER "@CMAKE_Swift_COMPILER@")
set(CMAKE_Swift_COMPILER_ID "@CMAKE_Swift_COMPILER_ID@")
+set(CMAKE_Swift_COMPILER_VERSION "@CMAKE_Swift_COMPILER_VERSION@")
+
+set(CMAKE_Swift_COMPILER_LOADED 1)
+set(CMAKE_Swift_COMPILER_WORKS "@CMAKE_Swift_COMPILER_WORKS@")
+
+set(CMAKE_Swift_COMPILER_ENV_VAR "SWIFTC")
set(CMAKE_Swift_COMPILER_ID_RUN 1)
set(CMAKE_Swift_SOURCE_FILE_EXTENSIONS swift)
diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake
index d9b408d3b..f6510b922 100644
--- a/Modules/CMakeSwiftInformation.cmake
+++ b/Modules/CMakeSwiftInformation.cmake
@@ -1,32 +1,90 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-
-set(CMAKE_Swift_OUTPUT_EXTENSION .o)
-set(CMAKE_INCLUDE_FLAG_Swift "-I")
+if(UNIX)
+ set(CMAKE_Swift_OUTPUT_EXTENSION .o)
+else()
+ set(CMAKE_Swift_OUTPUT_EXTENSION .obj)
+endif()
# Load compiler-specific information.
if(CMAKE_Swift_COMPILER_ID)
include(Compiler/${CMAKE_Swift_COMPILER_ID}-Swift OPTIONAL)
-endif()
-# load the system- and compiler specific files
-if(CMAKE_Swift_COMPILER_ID)
- # load a hardware specific file, mostly useful for embedded compilers
if(CMAKE_SYSTEM_PROCESSOR)
- include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
endif()
- include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift OPTIONAL)
+ include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift OPTIONAL)
+endif()
+
+set(CMAKE_INCLUDE_FLAG_Swift "-I ")
+if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
+ set(CMAKE_SHARED_LIBRARY_SONAME_Swift_FLAG "-Xlinker -soname -Xlinker ")
+endif()
+
+set(CMAKE_Swift_COMPILE_OPTIONS_TARGET "-target ")
+set(CMAKE_Swift_COMPILER_ARG1 -frontend)
+set(CMAKE_Swift_DEFINE_FLAG -D)
+set(CMAKE_Swift_FRAMEWORK_SEARCH_FLAG "-F ")
+set(CMAKE_Swift_LIBRARY_PATH_FLAG "-L ")
+set(CMAKE_Swift_LIBRARY_PATH_TERMINATOR "")
+set(CMAKE_Swift_LINKER_WRAPPER_FLAG "-Xlinker" " ")
+set(CMAKE_Swift_RESPONSE_FILE_LINK_FLAG @)
+
+set(CMAKE_Swift_LINKER_PREFERENCE 50)
+set(CMAKE_Swift_LINKER_PREFERENCE_PROPAGATES 1)
+
+# NOTE(compnerd) use the short form for convenience and ease of search. They
+# are treated equivalent to their long form names as well as custom Swift
+# specific names.
+set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -libc MT)
+set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -libc MD)
+set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -libc MTd)
+set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -libc MDd)
+
+set(CMAKE_Swift_FLAGS_DEBUG_INIT "-g")
+set(CMAKE_Swift_FLAGS_RELEASE_INIT "-O")
+set(CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT "-O -g")
+set(CMAKE_Swift_FLAGS_MINSIZEREL_INIT "-Osize")
+
+# NOTE(compnerd) we do not have an object compile rule since we build the objects as part of the link step
+if(NOT CMAKE_Swift_COMPILE_OBJECT)
+ set(CMAKE_Swift_COMPILE_OBJECT ":")
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_Swift_FLAGS ${CMAKE_SHARED_LIBRARY_Swift_FLAGS})
- set(CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Swift_FLAGS})
+if(NOT CMAKE_Swift_NUM_THREADS MATCHES "^[0-9]+$")
+ cmake_host_system_information(RESULT CMAKE_Swift_NUM_THREADS QUERY NUMBER_OF_LOGICAL_CORES)
endif()
-include(CMakeCommonLanguageInclude)
+if(NOT CMAKE_Swift_CREATE_SHARED_LIBRARY)
+ if(CMAKE_Swift_COMPILER_TARGET)
+ set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -target <CMAKE_Swift_COMPILER_TARGET> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_SONAME> <LINK_LIBRARIES>")
+ else()
+ set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_SONAME> <LINK_LIBRARIES>")
+ endif()
+endif()
+
+if(NOT CMAKE_Swift_CREATE_SHARED_MODULE)
+ set(CMAKE_Swift_CREATE_SHARED_MODULE ${CMAKE_Swift_CREATE_SHARED_LIBRARY})
+endif()
+
+if(NOT CMAKE_Swift_LINK_EXECUTABLE)
+ if(CMAKE_Swift_COMPILER_TARGET)
+ set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -target <CMAKE_Swift_COMPILER_TARGET> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
+ else()
+ set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
+ endif()
+endif()
+
+if(NOT CMAKE_Swift_CREATE_STATIC_LIBRARY)
+ if(CMAKE_Swift_COMPILER_TARGET)
+ set(CMAKE_Swift_CREATE_STATIC_LIBRARY "${CMAKE_Swift_COMPILER} -target <CMAKE_Swift_COMPILER_TARGET> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
+ else()
+ set(CMAKE_Swift_CREATE_STATIC_LIBRARY "${CMAKE_Swift_COMPILER} -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
+ endif()
+
+ set(CMAKE_Swift_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <OBJECTS>")
+ set(CMAKE_Swift_ARCHIVE_FINISH "")
+endif()
set(CMAKE_Swift_INFORMATION_LOADED 1)
diff --git a/Modules/CMakeSystemSpecificInformation.cmake b/Modules/CMakeSystemSpecificInformation.cmake
index 03f348d72..c6a88144f 100644
--- a/Modules/CMakeSystemSpecificInformation.cmake
+++ b/Modules/CMakeSystemSpecificInformation.cmake
@@ -34,10 +34,9 @@ if(NOT _INCLUDED_SYSTEM_INFO_FILE)
${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()
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)
diff --git a/Modules/CMakeSystemSpecificInitialize.cmake b/Modules/CMakeSystemSpecificInitialize.cmake
index 6200e9c0d..21bcd403c 100644
--- a/Modules/CMakeSystemSpecificInitialize.cmake
+++ b/Modules/CMakeSystemSpecificInitialize.cmake
@@ -5,6 +5,19 @@
# This file is included by cmGlobalGenerator::EnableLanguage.
# It is included before the compiler has been determined.
+# The CMAKE_EFFECTIVE_SYSTEM_NAME is used to load compiler and compiler
+# wrapper configuration files. By default it equals to CMAKE_SYSTEM_NAME
+# but could be overridden in the ${CMAKE_SYSTEM_NAME}-Initialize files.
+#
+# It is useful to share the same aforementioned configuration files and
+# avoids duplicating them in case of tightly related platforms.
+#
+# An example are the platforms supported by Xcode (macOS, iOS, tvOS,
+# and watchOS). For all of those the CMAKE_EFFECTIVE_SYSTEM_NAME is
+# set to Apple which results in using
+# Platform/Apple-AppleClang-CXX.cmake for the Apple C++ compiler.
+set(CMAKE_EFFECTIVE_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
+
include(Platform/${CMAKE_SYSTEM_NAME}-Initialize OPTIONAL)
set(CMAKE_SYSTEM_SPECIFIC_INITIALIZE_LOADED 1)
diff --git a/Modules/CMakeTestCCompiler.cmake b/Modules/CMakeTestCCompiler.cmake
index 7f199699e..7bf6fde3b 100644
--- a/Modules/CMakeTestCCompiler.cmake
+++ b/Modules/CMakeTestCCompiler.cmake
@@ -11,6 +11,12 @@ endif()
include(CMakeTestCompilerCommon)
+# work around enforced code signing and / or missing exectuable target type
+set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE)
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE})
+endif()
+
# Remove any cached result from an older CMake version.
# We now store this in CMakeCCompiler.cmake.
unset(CMAKE_C_COMPILER_WORKS CACHE)
@@ -22,6 +28,7 @@ unset(CMAKE_C_COMPILER_WORKS CACHE)
# any makefiles or projects.
if(NOT CMAKE_C_COMPILER_WORKS)
PrintTestCompilerStatus("C" "")
+ __TestCompiler_setTryCompileTargetType()
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"
@@ -41,6 +48,7 @@ if(NOT CMAKE_C_COMPILER_WORKS)
set(CMAKE_C_COMPILER_WORKS ${CMAKE_C_COMPILER_WORKS})
unset(CMAKE_C_COMPILER_WORKS CACHE)
set(C_TEST_WAS_RUN 1)
+ __TestCompiler_restoreTryCompileTargetType()
endif()
if(NOT CMAKE_C_COMPILER_WORKS)
@@ -48,9 +56,10 @@ if(NOT CMAKE_C_COMPILER_WORKS)
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}\" "
+ string(REPLACE "\n" "\n " _output "${__CMAKE_C_COMPILER_OUTPUT}")
+ message(FATAL_ERROR "The C compiler\n \"${CMAKE_C_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
- "with the following output:\n ${__CMAKE_C_COMPILER_OUTPUT}\n\n"
+ "with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
else()
if(C_TEST_WAS_RUN)
@@ -83,4 +92,6 @@ else()
endif()
endif()
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
+unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
unset(__CMAKE_C_COMPILER_OUTPUT)
diff --git a/Modules/CMakeTestCSharpCompiler.cmake b/Modules/CMakeTestCSharpCompiler.cmake
index 1a8bf32e0..6715c30db 100644
--- a/Modules/CMakeTestCSharpCompiler.cmake
+++ b/Modules/CMakeTestCSharpCompiler.cmake
@@ -15,7 +15,7 @@ unset(CMAKE_CSharp_COMPILER_WORKS CACHE)
set(test_compile_file "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCSharpCompiler.cs")
# This file is used by EnableLanguage in cmGlobalGenerator to
-# determine that that selected C# compiler can actually compile
+# determine that the 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.
@@ -42,9 +42,10 @@ if(NOT CMAKE_CSharp_COMPILER_WORKS)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the C# compiler works failed with "
"the following output:\n${__CMAKE_CSharp_COMPILER_OUTPUT}\n\n")
- message(FATAL_ERROR "The C# compiler \"${CMAKE_CSharp_COMPILER}\" "
+ string(REPLACE "\n" "\n " _output "${__CMAKE_CSharp_COMPILER_OUTPUT}")
+ message(FATAL_ERROR "The C# compiler\n \"${CMAKE_CSharp_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
- "with the following output:\n ${__CMAKE_CSharp_COMPILER_OUTPUT}\n\n"
+ "with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
else()
if(CSharp_TEST_WAS_RUN)
diff --git a/Modules/CMakeTestCUDACompiler.cmake b/Modules/CMakeTestCUDACompiler.cmake
index 80113cb4a..f0454da67 100644
--- a/Modules/CMakeTestCUDACompiler.cmake
+++ b/Modules/CMakeTestCUDACompiler.cmake
@@ -15,7 +15,7 @@ include(CMakeTestCompilerCommon)
unset(CMAKE_CUDA_COMPILER_WORKS CACHE)
# This file is used by EnableLanguage in cmGlobalGenerator to
-# determine that that selected cuda compiler can actually compile
+# determine that the selected cuda 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.
@@ -42,9 +42,10 @@ if(NOT CMAKE_CUDA_COMPILER_WORKS)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the CUDA compiler works failed with "
"the following output:\n${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n")
- message(FATAL_ERROR "The CUDA compiler \"${CMAKE_CUDA_COMPILER}\" "
+ string(REPLACE "\n" "\n " _output "${__CMAKE_CUDA_COMPILER_OUTPUT}")
+ message(FATAL_ERROR "The CUDA compiler\n \"${CMAKE_CUDA_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
- "with the following output:\n ${__CMAKE_CUDA_COMPILER_OUTPUT}\n\n"
+ "with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
else()
if(CUDA_TEST_WAS_RUN)
diff --git a/Modules/CMakeTestCXXCompiler.cmake b/Modules/CMakeTestCXXCompiler.cmake
index a31067b60..7e595b74f 100644
--- a/Modules/CMakeTestCXXCompiler.cmake
+++ b/Modules/CMakeTestCXXCompiler.cmake
@@ -11,17 +11,24 @@ endif()
include(CMakeTestCompilerCommon)
+# work around enforced code signing and / or missing exectuable target type
+set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
+if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE)
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE})
+endif()
+
# 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
+# determine that the 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" "")
+ __TestCompiler_setTryCompileTargetType()
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"
@@ -34,6 +41,7 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
unset(CMAKE_CXX_COMPILER_WORKS CACHE)
set(CXX_TEST_WAS_RUN 1)
+ __TestCompiler_restoreTryCompileTargetType()
endif()
if(NOT CMAKE_CXX_COMPILER_WORKS)
@@ -41,9 +49,10 @@ if(NOT CMAKE_CXX_COMPILER_WORKS)
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}\" "
+ string(REPLACE "\n" "\n " _output "${__CMAKE_CXX_COMPILER_OUTPUT}")
+ message(FATAL_ERROR "The C++ compiler\n \"${CMAKE_CXX_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
- "with the following output:\n ${__CMAKE_CXX_COMPILER_OUTPUT}\n\n"
+ "with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
else()
if(CXX_TEST_WAS_RUN)
@@ -76,4 +85,6 @@ else()
endif()
endif()
+set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
+unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
unset(__CMAKE_CXX_COMPILER_OUTPUT)
diff --git a/Modules/CMakeTestCompilerCommon.cmake b/Modules/CMakeTestCompilerCommon.cmake
index f76076fe2..6ee5175dd 100644
--- a/Modules/CMakeTestCompilerCommon.cmake
+++ b/Modules/CMakeTestCompilerCommon.cmake
@@ -5,3 +5,23 @@
function(PrintTestCompilerStatus LANG MSG)
message(STATUS "Check for working ${LANG} compiler: ${CMAKE_${LANG}_COMPILER}${MSG}")
endfunction()
+
+# if required set the target type if not already explicitly set
+macro(__TestCompiler_setTryCompileTargetType)
+ if(NOT CMAKE_TRY_COMPILE_TARGET_TYPE)
+ if("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
+ #prefer static libraries to avoid linking issues
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(__CMAKE_TEST_COMPILER_TARGET_TYPE_RESTORE 1)
+ endif()
+ endif()
+endmacro()
+
+# restore the original value
+# -- not necessary if __TestCompiler_setTryCompileTargetType() was used in function scope
+macro(__TestCompiler_restoreTryCompileTargetType)
+ if(__CMAKE_TEST_COMPILER_TARGET_TYPE_RESTORE)
+ unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
+ unset(__CMAKE_TEST_COMPILER_TARGET_TYPE_RESTORE)
+ endif()
+endmacro()
diff --git a/Modules/CMakeTestFortranCompiler.cmake b/Modules/CMakeTestFortranCompiler.cmake
index c81694ef9..e9860e9de 100644
--- a/Modules/CMakeTestFortranCompiler.cmake
+++ b/Modules/CMakeTestFortranCompiler.cmake
@@ -16,7 +16,7 @@ include(CMakeTestCompilerCommon)
unset(CMAKE_Fortran_COMPILER_WORKS CACHE)
# This file is used by EnableLanguage in cmGlobalGenerator to
-# determine that that selected Fortran compiler can actually compile
+# determine that the 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.
@@ -41,9 +41,10 @@ if(NOT CMAKE_Fortran_COMPILER_WORKS)
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}\" "
+ string(REPLACE "\n" "\n " _output "${OUTPUT}")
+ message(FATAL_ERROR "The Fortran compiler\n \"${CMAKE_Fortran_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
- "with the following output:\n ${OUTPUT}\n\n"
+ "with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
else()
if(FORTRAN_TEST_WAS_RUN)
diff --git a/Modules/CMakeTestJavaCompiler.cmake b/Modules/CMakeTestJavaCompiler.cmake
index 23fdbdce7..3c33573b9 100644
--- a/Modules/CMakeTestJavaCompiler.cmake
+++ b/Modules/CMakeTestJavaCompiler.cmake
@@ -3,7 +3,7 @@
# This file is used by EnableLanguage in cmGlobalGenerator to
-# determine that that selected Fortran compiler can actually compile
+# determine that the 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.
diff --git a/Modules/CMakeTestRCCompiler.cmake b/Modules/CMakeTestRCCompiler.cmake
index c510d3a80..3123a6cf4 100644
--- a/Modules/CMakeTestRCCompiler.cmake
+++ b/Modules/CMakeTestRCCompiler.cmake
@@ -3,7 +3,7 @@
# This file is used by EnableLanguage in cmGlobalGenerator to
-# determine that that selected RC compiler can actually compile
+# determine that the 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.
diff --git a/Modules/CMakeTestSwiftCompiler.cmake b/Modules/CMakeTestSwiftCompiler.cmake
index 6393f44a0..841aee643 100644
--- a/Modules/CMakeTestSwiftCompiler.cmake
+++ b/Modules/CMakeTestSwiftCompiler.cmake
@@ -1,7 +1,6 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-
if(CMAKE_Swift_COMPILER_FORCED)
# The compiler configuration was forced by the user.
# Assume the user has configured all compiler information.
@@ -16,14 +15,13 @@ include(CMakeTestCompilerCommon)
unset(CMAKE_Swift_COMPILER_WORKS CACHE)
# This file is used by EnableLanguage in cmGlobalGenerator to
-# determine that that selected C++ compiler can actually compile
+# determine that the 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_Swift_COMPILER_WORKS)
PrintTestCompilerStatus("Swift" "")
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift
- "import Foundation\n"
"print(\"CMake\")\n")
try_compile(CMAKE_Swift_COMPILER_WORKS ${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift
@@ -39,9 +37,10 @@ if(NOT CMAKE_Swift_COMPILER_WORKS)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determining if the Swift compiler works failed with "
"the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
- message(FATAL_ERROR "The Swift compiler \"${CMAKE_Swift_COMPILER}\" "
+ string(REPLACE "\n" "\n " _output "${__CMAKE_Swift_COMPILER_OUTPUT}")
+ message(FATAL_ERROR "The Swift compiler\n \"${CMAKE_Swift_COMPILER}\"\n"
"is not able to compile a simple test program.\nIt fails "
- "with the following output:\n ${__CMAKE_Swift_COMPILER_OUTPUT}\n\n"
+ "with the following output:\n ${_output}\n\n"
"CMake will not be able to correctly generate this project.")
else()
if(Swift_TEST_WAS_RUN)
@@ -50,6 +49,11 @@ else()
"Determining if the Swift compiler works passed with "
"the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
endif()
+
+ # Re-configure to save learned information.
+ configure_file(${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in
+ ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake @ONLY)
+ include(${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake)
endif()
unset(__CMAKE_Swift_COMPILER_OUTPUT)
diff --git a/Modules/CMakeVerifyManifest.cmake b/Modules/CMakeVerifyManifest.cmake
index c477ab1c2..705ef8aa7 100644
--- a/Modules/CMakeVerifyManifest.cmake
+++ b/Modules/CMakeVerifyManifest.cmake
@@ -1,22 +1,23 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CMakeVerifyManifest
-# -------------------
-#
-#
-#
-# CMakeVerifyManifest.cmake
-#
-# This script is used to verify that embedded 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 embedded manifest
-# of 8.0.50608.0 to be used in a project even if that version was not
-# found in the .manifest file.
+#[=======================================================================[.rst:
+CMakeVerifyManifest
+-------------------
+
+
+
+CMakeVerifyManifest.cmake
+
+This script is used to verify that embedded 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 embedded 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
diff --git a/Modules/CPack.STGZ_Header.sh.in b/Modules/CPack.STGZ_Header.sh.in
index c61585136..70f63d2d6 100755
--- a/Modules/CPack.STGZ_Header.sh.in
+++ b/Modules/CPack.STGZ_Header.sh.in
@@ -7,9 +7,11 @@ cpack_usage()
Usage: $0 [options]
Options: [defaults in brackets after descriptions]
--help print this message
+ --version print cmake installer version
--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
+ --skip-license accept license
EOF
exit 1
}
diff --git a/Modules/CPack.background.png.in b/Modules/CPack.background.png.in
index 9339e7cad..a32ab3762 100644
--- a/Modules/CPack.background.png.in
+++ b/Modules/CPack.background.png.in
Binary files differ
diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake
index a63fc8325..c9008dbf9 100644
--- a/Modules/CPack.cmake
+++ b/Modules/CPack.cmake
@@ -1,298 +1,357 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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). Default value is::
-#
-# ${PROJECT_DESCRIPTION}
-#
-# if DESCRIPTION has given to the project() call or
-# CMake generated string with PROJECT_NAME otherwise.
-#
-# .. 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_PACKAGE_CHECKSUM
-#
-# An algorithm that will be used to generate additional file with checksum
-# of the package. Output file name will be::
-#
-# ${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}
-#
-# Supported algorithms are those listed by the
-# :ref:`string(\<HASH\>) <Supported Hash Algorithms>`
-# command.
-#
-# .. 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).
-#
-# .. variable:: CPACK_VERBATIM_VARIABLES
-#
-# If set to TRUE, values of variables prefixed with CPACK_ will be escaped
-# before being written to the configuration files, so that the cpack program
-# receives them exactly as they were specified. If not, characters like quotes
-# and backslashes can cause parsing errors or alter the value received by the
-# cpack program. Defaults to FALSE for backwards compatibility.
-#
-# * Mandatory : NO
-# * Default : FALSE
-#
-# 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 installs 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`.
+#[=======================================================================[.rst:
+CPack
+-----
+
+Build binary and source package installers.
+
+Introduction
+^^^^^^^^^^^^
+
+The CPack module generates a file ``CPackConfig.cmake`` intended for
+use in a subsequent run of the :manual:`cpack <cpack(1)>` program
+where it steers the generation of installers or/and source packages.
+
+Inclusion of the CPack module adds two new build targets, ``package``
+and ``package_source``, which build the binary and source installers
+respectively. The generated binary installers contain everything
+installed via CMake's :command:`install` command (and the deprecated
+commands :command:`install_files`, :command:`install_programs`, and
+:command:`install_targets`).
+
+For certain kinds of binary installers (including the graphical
+installers on macOS and Windows), CPack generates installers that
+allow users to select individual application components to install.
+See :module:`CPackComponent` module for further details.
+
+CPack Generators
+^^^^^^^^^^^^^^^^
+
+The :variable:`CPACK_GENERATOR` variable has different meanings in different
+contexts. In a ``CMakeLists.txt`` file, :variable:`CPACK_GENERATOR` is a
+*list of generators*: and when :manual:`cpack <cpack(1)>` is run with no other
+arguments, it will iterate over that list and produce one package for each
+generator. In a :variable:`CPACK_PROJECT_CONFIG_FILE`,
+:variable:`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 :variable:`CPACK_PROJECT_CONFIG_FILE`.
+
+The CMake source tree itself contains a :variable:`CPACK_PROJECT_CONFIG_FILE`.
+See the top level file ``CMakeCPackOptions.cmake.in`` for an example.
+
+If set, the :variable:`CPACK_PROJECT_CONFIG_FILE` is included automatically
+on a per-generator basis. It only need contain overrides.
+
+Here's how it works:
+
+* :manual:`cpack <cpack(1)>` runs
+* it includes ``CPackConfig.cmake``
+* it iterates over the generators given by the ``-G`` command line option,
+ or if no such option was specified, over the list of generators given by
+ the :variable:`CPACK_GENERATOR` variable set in the ``CPackConfig.cmake``
+ input file.
+* foreach generator, it then
+
+ - sets :variable:`CPACK_GENERATOR` to the one currently being iterated
+ - includes the :variable:`CPACK_PROJECT_CONFIG_FILE`
+ - produces the package for that generator
+
+This is the key: For each generator listed in :variable:`CPACK_GENERATOR` in
+``CPackConfig.cmake``, cpack will *reset* :variable:`CPACK_GENERATOR`
+internally to *the one currently being used* and then include the
+:variable:`CPACK_PROJECT_CONFIG_FILE`.
+
+Variables common to all CPack Generators
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+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, it defaults to
+ the project name.
+
+.. variable:: CPACK_PACKAGE_VENDOR
+
+ The name of the package vendor. (e.g., "Kitware"). The default is "Humanity".
+
+.. 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 a CPack config file or from the :manual:`cpack <cpack(1)>`
+ command line option ``-B``. If set, the command line option overrides the
+ value found in the config file.
+
+.. variable:: CPACK_PACKAGE_VERSION_MAJOR
+
+ Package major version. This variable will always be set, but its default
+ value depends on whether or not version details were given to the
+ :command:`project` command in the top level CMakeLists.txt file. If version
+ details were given, the default value will be
+ :variable:`CMAKE_PROJECT_VERSION_MAJOR`. If no version details were given,
+ a default version of 0.1.1 will be assumed, leading to
+ ``CPACK_PACKAGE_VERSION_MAJOR`` having a default value of 0.
+
+.. variable:: CPACK_PACKAGE_VERSION_MINOR
+
+ Package minor version. The default value is determined based on whether or
+ not version details were given to the :command:`project` command in the top
+ level CMakeLists.txt file. If version details were given, the default
+ value will be :variable:`CMAKE_PROJECT_VERSION_MINOR`, but if no minor
+ version component was specified then ``CPACK_PACKAGE_VERSION_MINOR`` will be
+ left unset. If no project version was given at all, a default version of
+ 0.1.1 will be assumed, leading to ``CPACK_PACKAGE_VERSION_MINOR`` having a
+ default value of 1.
+
+.. variable:: CPACK_PACKAGE_VERSION_PATCH
+
+ Package patch version. The default value is determined based on whether or
+ not version details were given to the :command:`project` command in the top
+ level CMakeLists.txt file. If version details were given, the default
+ value will be :variable:`CMAKE_PROJECT_VERSION_PATCH`, but if no patch
+ version component was specified then ``CPACK_PACKAGE_VERSION_PATCH`` will be
+ left unset. If no project version was given at all, a default version of
+ 0.1.1 will be assumed, leading to ``CPACK_PACKAGE_VERSION_PATCH`` having a
+ default value of 1.
+
+.. variable:: CPACK_PACKAGE_DESCRIPTION
+
+ A description of the project, used in places such as the introduction
+ screen of CPack-generated Windows installers. If not set, the value of
+ this variable is populated from the file named by
+ :variable:`CPACK_PACKAGE_DESCRIPTION_FILE`.
+
+.. variable:: CPACK_PACKAGE_DESCRIPTION_FILE
+
+ A text file used to describe the project when
+ :variable:`CPACK_PACKAGE_DESCRIPTION` is not explicitly set. The default
+ value for ``CPACK_PACKAGE_DESCRIPTION_FILE`` points to a built-in template
+ file ``Templates/CPack.GenericDescription.txt``.
+
+.. variable:: CPACK_PACKAGE_DESCRIPTION_SUMMARY
+
+ Short description of the project (only a few words). If the
+ :variable:`CMAKE_PROJECT_DESCRIPTION` variable is set, it is used as the
+ default value, otherwise the default will be a string generated by CMake
+ based on :variable:`CMAKE_PROJECT_NAME`.
+
+.. variable:: CPACK_PACKAGE_HOMEPAGE_URL
+
+ Project homepage URL. The default value is taken from the
+ :variable:`CMAKE_PROJECT_HOMEPAGE_URL` variable, which is set by the top
+ level :command:`project` command, or else the default will be empty if no
+ URL was provided to :command:`project`.
+
+.. 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 elements 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_PACKAGE_CHECKSUM
+
+ An algorithm that will be used to generate an additional file with the
+ checksum of the package. The output file name will be::
+
+ ${CPACK_PACKAGE_FILE_NAME}.${CPACK_PACKAGE_CHECKSUM}
+
+ Supported algorithms are those listed by the
+ :ref:`string(\<HASH\>) <Supported Hash Algorithms>` command.
+
+.. variable:: CPACK_PROJECT_CONFIG_FILE
+
+ CPack-time project CPack configuration file. This file is included at cpack
+ time, once per generator after CPack has set :variable:`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 the installed files 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
+ :command:`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 use 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 ``TRUE``.
+
+.. variable:: CPACK_GENERATOR
+
+ List of CPack generators to use. If not specified, CPack will create a
+ set of options following the naming pattern
+ :variable:`CPACK_BINARY_<GENNAME>` (e.g. ``CPACK_BINARY_NSIS``) allowing
+ the user to enable/disable individual generators. If the ``-G`` option is
+ given on the :manual:`cpack <cpack(1)>` command line, it will override this
+ variable and any ``CPACK_BINARY_<GENNAME>`` options.
+
+.. 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).
+
+.. variable:: CPACK_VERBATIM_VARIABLES
+
+ If set to ``TRUE``, values of variables prefixed with ``CPACK_`` will be
+ escaped before being written to the configuration files, so that the cpack
+ program receives them exactly as they were specified. If not, characters
+ like quotes and backslashes can cause parsing errors or alter the value
+ received by the cpack program. Defaults to ``FALSE`` for backwards
+ compatibility.
+
+Variables for Source Package Generators
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+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
+ :variable:`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.*``
+
+Variables for Advanced Use
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The following variables are for advanced uses of CPack:
+
+.. variable:: CPACK_CMAKE_GENERATOR
+
+ What CMake generator should be used if the project is a CMake
+ project. Defaults to the value of :variable:`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 installs everything.
+
+.. variable:: CPACK_SYSTEM_NAME
+
+ System name, defaults to the value of :variable:`CMAKE_SYSTEM_NAME`,
+ except on Windows where it will be ``win32`` or ``win64``.
+
+.. variable:: CPACK_PACKAGE_VERSION
+
+ Package full version, used internally. By default, this is built from
+ :variable:`CPACK_PACKAGE_VERSION_MAJOR`,
+ :variable:`CPACK_PACKAGE_VERSION_MINOR`, and
+ :variable:`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
+ installers 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`.
+
+.. variable:: CPACK_BINARY_<GENNAME>
+
+ CPack generated options for binary generators. The ``CPack.cmake`` module
+ generates (when :variable:`CPACK_GENERATOR` is not set) a set of CMake
+ options (see CMake :command:`option` command) which may then be used to
+ select the CPack generator(s) to be used when building the ``package``
+ target or when running :manual:`cpack <cpack(1)>` without the ``-G`` option.
+
+#]=======================================================================]
# Define this var in order to avoid (or warn) concerning multiple inclusion
if(CPack_CMake_INCLUDED)
@@ -338,7 +397,7 @@ function(cpack_encode_variables)
set(value "${${var}}")
endif()
- string(APPEND commands "\nSET(${var} \"${value}\")")
+ string(APPEND commands "\nset(${var} \"${value}\")")
endif()
endforeach()
@@ -359,11 +418,31 @@ endfunction()
# Set the package name
_cpack_set_default(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
-_cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "0")
-_cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "1")
-_cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
-_cpack_set_default(CPACK_PACKAGE_VERSION
- "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+
+# Set the package version
+if(CMAKE_PROJECT_VERSION_MAJOR GREATER_EQUAL 0)
+ _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "${CMAKE_PROJECT_VERSION_MAJOR}")
+ if(CMAKE_PROJECT_VERSION_MINOR GREATER_EQUAL 0)
+ _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "${CMAKE_PROJECT_VERSION_MINOR}")
+ if(CMAKE_PROJECT_VERSION_PATCH GREATER_EQUAL 0)
+ _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "${CMAKE_PROJECT_VERSION_PATCH}")
+ endif()
+ endif()
+else()
+ _cpack_set_default(CPACK_PACKAGE_VERSION_MAJOR "0")
+ _cpack_set_default(CPACK_PACKAGE_VERSION_MINOR "1")
+ _cpack_set_default(CPACK_PACKAGE_VERSION_PATCH "1")
+endif()
+if(NOT DEFINED CPACK_PACKAGE_VERSION)
+ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}")
+ if(CPACK_PACKAGE_VERSION_MINOR GREATER_EQUAL 0)
+ string(APPEND CPACK_PACKAGE_VERSION ".${CPACK_PACKAGE_VERSION_MINOR}")
+ if(CPACK_PACKAGE_VERSION_PATCH GREATER_EQUAL 0)
+ string(APPEND CPACK_PACKAGE_VERSION ".${CPACK_PACKAGE_VERSION_PATCH}")
+ endif()
+ endif()
+endif()
+
_cpack_set_default(CPACK_PACKAGE_VENDOR "Humanity")
if(CMAKE_PROJECT_DESCRIPTION)
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
@@ -372,6 +451,10 @@ else()
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"${CMAKE_PROJECT_NAME} built using CMake")
endif()
+if(CMAKE_PROJECT_HOMEPAGE_URL)
+ _cpack_set_default(CPACK_PACKAGE_HOMEPAGE_URL
+ "${CMAKE_PROJECT_HOMEPAGE_URL}")
+endif()
_cpack_set_default(CPACK_PACKAGE_DESCRIPTION_FILE
"${CMAKE_ROOT}/Templates/CPack.GenericDescription.txt")
@@ -384,6 +467,12 @@ _cpack_set_default(CPACK_RESOURCE_FILE_WELCOME
_cpack_set_default(CPACK_MODULE_PATH "${CMAKE_MODULE_PATH}")
+# Set default directory creation permissions mode
+if(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS)
+ _cpack_set_default(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
+ "${CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS}")
+endif()
+
if(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL)
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
endif()
@@ -446,16 +535,9 @@ macro(cpack_optional_append _list _cond _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
+# Provide options to choose generators we might check here if the required
+# tools for the generators exist and set the defaults according to the
+# results.
if(NOT CPACK_GENERATOR)
if(UNIX)
if(CYGWIN)
@@ -471,6 +553,7 @@ if(NOT CPACK_GENERATOR)
option(CPACK_BINARY_TZ "Enable to build TZ packages" ON)
endif()
option(CPACK_BINARY_DEB "Enable to build Debian packages" OFF)
+ option(CPACK_BINARY_FREEBSD "Enable to build FreeBSD 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)
@@ -479,10 +562,11 @@ if(NOT CPACK_GENERATOR)
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)
+ option(CPACK_BINARY_7Z "Enable to build 7-Zip packages" OFF)
+ option(CPACK_BINARY_NSIS "Enable to build NSIS packages" ON)
+ option(CPACK_BINARY_NUGET "Enable to build NuGet packages" OFF)
+ 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)
@@ -491,8 +575,10 @@ if(NOT CPACK_GENERATOR)
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_FREEBSD FREEBSD)
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_NUGET NuGet)
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_PRODUCTBUILD productbuild)
@@ -542,8 +628,10 @@ mark_as_advanced(
CPACK_BINARY_CYGWIN
CPACK_BINARY_DEB
CPACK_BINARY_DRAGNDROP
+ CPACK_BINARY_FREEBSD
CPACK_BINARY_IFW
CPACK_BINARY_NSIS
+ CPACK_BINARY_NUGET
CPACK_BINARY_OSXX11
CPACK_BINARY_PACKAGEMAKER
CPACK_BINARY_PRODUCTBUILD
diff --git a/Modules/CPackComponent.cmake b/Modules/CPackComponent.cmake
index 3a10b9930..211d7673c 100644
--- a/Modules/CPackComponent.cmake
+++ b/Modules/CPackComponent.cmake
@@ -1,303 +1,314 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>_HIDDEN
-#
-# True if this component is hidden from the user.
-#
-# .. variable:: CPACK_COMPONENT_<compName>_REQUIRED
-#
-# True if this component is required.
-#
-# .. variable:: CPACK_COMPONENT_<compName>_DISABLED
-#
-# True if this component is not selected to be installed by default.
-#
-# .. 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]
-# [PLIST 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.
-#
-# PLIST gives a filename that is passed to pkgbuild with the
-# ``--component-plist`` argument when using the productbuild generator.
-#
-# .. 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.,
-# https://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.
+#[=======================================================================[.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 macOS 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.
+
+ Instead of specifying all the desired components, it is possible to obtain a
+ list of all defined components and then remove the unwanted ones from the
+ list. The :command:`get_cmake_property` command can be used to obtain the
+ ``COMPONENTS`` property, then the :command:`list(REMOVE_ITEM)` command can be
+ used to remove the unwanted ones. For example, to use all defined components
+ except ``foo`` and ``bar``::
+
+ get_cmake_property(CPACK_COMPONENTS_ALL COMPONENTS)
+ list(REMOVE_ITEM CPACK_COMPONENTS_ALL "foo" "bar")
+
+.. 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) components
+ * 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>_HIDDEN
+
+ True if this component is hidden from the user.
+
+.. variable:: CPACK_COMPONENT_<compName>_REQUIRED
+
+ True if this component is required.
+
+.. variable:: CPACK_COMPONENT_<compName>_DISABLED
+
+ True if this component is not selected to be installed by default.
+
+.. 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]
+ [PLIST 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.
+
+PLIST gives a filename that is passed to pkgbuild with the
+``--component-plist`` argument when using the productbuild generator.
+
+.. 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 macOS, installers that download components on-the-fly can only
+be built and installed on system using macOS 10.5 or later.
+
+The site argument is a URL where the archives for downloadable
+components will reside, e.g.,
+https://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.
+#]=======================================================================]
# Define var in order to avoid multiple inclusion
if(NOT CPackComponent_CMake_INCLUDED)
diff --git a/Modules/CPackIFW.cmake b/Modules/CPackIFW.cmake
index c1cb52f16..42ef8c7b7 100644
--- a/Modules/CPackIFW.cmake
+++ b/Modules/CPackIFW.cmake
@@ -1,630 +1,331 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CPackIFW
-# --------
-#
-# .. _QtIFW: http://doc.qt.io/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 to create online and offline
-# binary cross-platform installers with a graphical user interface.
-#
-# CPack IFW generator prepares project installation and generates 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.
-#
-# You should also install QtIFW_ to use CPack ``IFW`` generator.
-#
-# Hints
-# ^^^^^
-#
-# Generally, the CPack ``IFW`` generator automatically finds QtIFW_ tools,
-# but if you don't use a default path for installation of the QtIFW_ tools,
-# the path may be specified in either a CMake or an environment variable:
-#
-# .. variable:: CPACK_IFW_ROOT
-#
-# An CMake variable which specifies the location of the QtIFW_ tool suite.
-#
-# The variable will be cached in the ``CPackConfig.cmake`` file and used at
-# CPack runtime.
-#
-# .. variable:: QTIFWDIR
-#
-# An environment variable which specifies the location of the QtIFW_ tool
-# suite.
-#
-# .. note::
-# The specified path should not contain "bin" at the end
-# (for example: "D:\\DevTools\\QtIFW2.0.5").
-#
-# The :variable:`CPACK_IFW_ROOT` variable has a higher priority and overrides
-# the value of the :variable:`QTIFWDIR` variable.
-#
-# Internationalization
-# ^^^^^^^^^^^^^^^^^^^^
-#
-# Some variables and command arguments support internationalization via
-# CMake script. This is an optional feature.
-#
-# Installers created by QtIFW_ tools have built-in support for
-# internationalization and many phrases are localized to many languages,
-# but this does not apply to the description of the your components and groups
-# that will be distributed.
-#
-# Localization of the description of your components and groups is useful for
-# users of your installers.
-#
-# A localized variable or argument can contain a single default value, and a
-# set of pairs the name of the locale and the localized value.
-#
-# For example:
-#
-# .. code-block:: cmake
-#
-# set(LOCALIZABLE_VARIABLE "Default value"
-# en "English value"
-# en_US "American value"
-# en_GB "Great Britain value"
-# )
-#
-# Variables
-# ^^^^^^^^^
-#
-# You can use the following variables to change behavior of CPack ``IFW``
-# generator.
-#
-# Debug
-# """"""
-#
-# .. variable:: CPACK_IFW_VERBOSE
-#
-# Set to ``ON`` to enable addition debug output.
-# By default is ``OFF``.
-#
-# 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 is used as QWizard::LogoPixmap.
-#
-# .. variable:: CPACK_IFW_PACKAGE_WATERMARK
-#
-# Filename for a watermark is used as QWizard::WatermarkPixmap.
-#
-# .. variable:: CPACK_IFW_PACKAGE_BANNER
-#
-# Filename for a banner is used as QWizard::BannerPixmap.
-#
-# .. variable:: CPACK_IFW_PACKAGE_BACKGROUND
-#
-# Filename for an image used as QWizard::BackgroundPixmap (only used by MacStyle).
-#
-# .. variable:: CPACK_IFW_PACKAGE_WIZARD_STYLE
-#
-# Wizard style to be used ("Modern", "Mac", "Aero" or "Classic").
-#
-# .. variable:: CPACK_IFW_PACKAGE_WIZARD_DEFAULT_WIDTH
-#
-# Default width of the wizard in pixels. Setting a banner image will override this.
-#
-# .. variable:: CPACK_IFW_PACKAGE_WIZARD_DEFAULT_HEIGHT
-#
-# Default height of the wizard in pixels. Setting a watermark image will override this.
-#
-# .. variable:: CPACK_IFW_PACKAGE_TITLE_COLOR
-#
-# Color of the titles and subtitles (takes an HTML color code, such as "#88FF33").
-#
-# .. variable:: CPACK_IFW_PACKAGE_START_MENU_DIRECTORY
-#
-# Name of the default program group for the product in the Windows Start menu.
-#
-# By default used :variable:`CPACK_IFW_PACKAGE_NAME`.
-#
-# .. 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_PACKAGE_MAINTENANCE_TOOL_NAME
-#
-# Filename of the generated maintenance tool.
-# The platform-specific executable file extension is appended.
-#
-# By default used QtIFW_ defaults (``maintenancetool``).
-#
-# .. variable:: CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_INI_FILE
-#
-# Filename for the configuration of the generated maintenance tool.
-#
-# By default used QtIFW_ defaults (``maintenancetool.ini``).
-#
-# .. variable:: CPACK_IFW_PACKAGE_ALLOW_NON_ASCII_CHARACTERS
-#
-# Set to ``ON`` if the installation path can contain non-ASCII characters.
-#
-# Is ``ON`` for QtIFW_ less 2.0 tools.
-#
-# .. variable:: CPACK_IFW_PACKAGE_ALLOW_SPACE_IN_PATH
-#
-# Set to ``OFF`` if the installation path cannot contain space characters.
-#
-# Is ``ON`` for QtIFW_ less 2.0 tools.
-#
-# .. variable:: CPACK_IFW_PACKAGE_CONTROL_SCRIPT
-#
-# Filename for a custom installer control script.
-#
-# .. variable:: CPACK_IFW_PACKAGE_RESOURCES
-#
-# List of additional resources ('.qrc' files) to include in the installer
-# binary.
-#
-# You can use :command:`cpack_ifw_add_package_resources` command to resolve
-# relative paths.
-#
-# .. 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`
-# or updated with command :command:`cpack_ifw_update_repository`.
-#
-# .. variable:: CPACK_IFW_DOWNLOAD_ALL
-#
-# If this is ``ON`` all components will be downloaded.
-# By default is ``OFF`` or used value
-# from ``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_FRAMEWORK_VERSION
-#
-# The version of used QtIFW_ tools.
-#
-# .. variable:: CPACK_IFW_BINARYCREATOR_EXECUTABLE
-#
-# The path to "binarycreator" command line client.
-#
-# This variable is cached and may be configured if needed.
-#
-# .. variable:: CPACK_IFW_REPOGEN_EXECUTABLE
-#
-# The path to "repogen" command line client.
-#
-# This variable is cached and may be configured if needed.
-#
-# .. variable:: CPACK_IFW_INSTALLERBASE_EXECUTABLE
-#
-# The path to "installerbase" installer executable base.
-#
-# This variable is cached and may be configured if needed.
-#
-# .. variable:: CPACK_IFW_DEVTOOL_EXECUTABLE
-#
-# The path to "devtool" command line client.
-#
-# This variable is cached and may be configured if needed.
-#
-# 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] [ESSENTIAL] [VIRTUAL]
-# [FORCED_INSTALLATION] [REQUIRES_ADMIN_RIGHTS]
-# [NAME <name>]
-# [DISPLAY_NAME <display_name>] # Note: Internationalization supported
-# [DESCRIPTION <description>] # Note: Internationalization supported
-# [UPDATE_TEXT <update_text>]
-# [VERSION <version>]
-# [RELEASE_DATE <release_date>]
-# [SCRIPT <script>]
-# [PRIORITY|SORTING_PRIORITY <sorting_priority>] # Note: PRIORITY is deprecated
-# [DEPENDS|DEPENDENCIES <com_id> ...]
-# [AUTO_DEPEND_ON <comp_id> ...]
-# [LICENSES <display_name> <file_path> ...]
-# [DEFAULT <value>]
-# [USER_INTERFACES <file_path> <file_path> ...]
-# [TRANSLATIONS <file_path> <file_path> ...])
-#
-# This command should be called after :command:`cpack_add_component` command.
-#
-# ``COMMON``
-# if set, then the component will be packaged and installed as part
-# of a group to which it belongs.
-#
-# ``ESSENTIAL``
-# if set, then the package manager stays disabled until that
-# component is updated.
-#
-# ``VIRTUAL``
-# if set, then the component will be hidden from the installer.
-# It is a equivalent of the ``HIDDEN`` option from the
-# :command:`cpack_add_component` command.
-#
-# ``FORCED_INSTALLATION``
-# if set, then the component must always be installed.
-# It is a equivalent of the ``REQUARED`` option from the
-# :command:`cpack_add_component` command.
-#
-# ``REQUIRES_ADMIN_RIGHTS``
-# set it if the component needs to be installed with elevated permissions.
-#
-# ``NAME``
-# is used to create domain-like identification for this component.
-# By default used origin component name.
-#
-# ``DISPLAY_NAME``
-# set to rewrite original name configured by
-# :command:`cpack_add_component` command.
-#
-# ``DESCRIPTION``
-# set to rewrite original description configured by
-# :command:`cpack_add_component` command.
-#
-# ``UPDATE_TEXT``
-# will be added to the component description if this is an update to
-# the component.
-#
-# ``VERSION``
-# is version of component.
-# By default used :variable:`CPACK_PACKAGE_VERSION`.
-#
-# ``RELEASE_DATE``
-# keep empty to auto generate.
-#
-# ``SCRIPT``
-# is a relative or absolute path to operations script
-# for this component.
-#
-# ``PRIORITY`` | ``SORTING_PRIORITY``
-# is priority of the component in the tree.
-# The ``PRIORITY`` option is deprecated and will be removed in a future
-# version of CMake. Please use ``SORTING_PRIORITY`` option instead.
-#
-# ``DEPENDS`` | ``DEPENDENCIES``
-# list of dependency component or component group identifiers in
-# QtIFW_ style.
-#
-# ``AUTO_DEPEND_ON``
-# list of identifiers of component or component group in QtIFW_ style
-# that this component has an automatic dependency on.
-#
-# ``LICENSES``
-# pair of <display_name> and <file_path> of license text for this
-# component. You can specify more then one license.
-#
-# ``DEFAULT``
-# Possible values are: TRUE, FALSE, and SCRIPT.
-# Set to FALSE to disable the component in the installer or to SCRIPT
-# to resolved during runtime (don't forget add the file of the script
-# as a value of the ``SCRIPT`` option).
-#
-# ``USER_INTERFACES``
-# is a list of <file_path> ('.ui' files) representing pages to load.
-#
-# ``TRANSLATIONS``
-# is a list of <file_path> ('.qm' files) representing translations to load.
-#
-#
-# .. command:: cpack_ifw_configure_component_group
-#
-# Sets the arguments specific to the CPack IFW generator.
-#
-# ::
-#
-# cpack_ifw_configure_component_group(<groupname> [VIRTUAL]
-# [FORCED_INSTALLATION] [REQUIRES_ADMIN_RIGHTS]
-# [NAME <name>]
-# [DISPLAY_NAME <display_name>] # Note: Internationalization supported
-# [DESCRIPTION <description>] # Note: Internationalization supported
-# [UPDATE_TEXT <update_text>]
-# [VERSION <version>]
-# [RELEASE_DATE <release_date>]
-# [SCRIPT <script>]
-# [PRIORITY|SORTING_PRIORITY <sorting_priority>] # Note: PRIORITY is deprecated
-# [DEPENDS|DEPENDENCIES <com_id> ...]
-# [AUTO_DEPEND_ON <comp_id> ...]
-# [LICENSES <display_name> <file_path> ...]
-# [DEFAULT <value>]
-# [USER_INTERFACES <file_path> <file_path> ...]
-# [TRANSLATIONS <file_path> <file_path> ...])
-#
-# This command should be called after :command:`cpack_add_component_group`
-# command.
-#
-# ``VIRTUAL``
-# if set, then the group will be hidden from the installer.
-# Note that setting this on a root component does not work.
-#
-# ``FORCED_INSTALLATION``
-# if set, then the group must always be installed.
-#
-# ``REQUIRES_ADMIN_RIGHTS``
-# set it if the component group needs to be installed with elevated
-# permissions.
-#
-# ``NAME``
-# is used to create domain-like identification for this component group.
-# By default used origin component group name.
-#
-# ``DISPLAY_NAME``
-# set to rewrite original name configured by
-# :command:`cpack_add_component_group` command.
-#
-# ``DESCRIPTION``
-# set to rewrite original description configured by
-# :command:`cpack_add_component_group` command.
-#
-# ``UPDATE_TEXT``
-# will be added to the component group description if this is an update to
-# the component group.
-#
-# ``VERSION``
-# is version of component group.
-# By default used :variable:`CPACK_PACKAGE_VERSION`.
-#
-# ``RELEASE_DATE``
-# keep empty to auto generate.
-#
-# ``SCRIPT``
-# is a relative or absolute path to operations script
-# for this component group.
-#
-# ``PRIORITY`` | ``SORTING_PRIORITY``
-# is priority of the component group in the tree.
-# The ``PRIORITY`` option is deprecated and will be removed in a future
-# version of CMake. Please use ``SORTING_PRIORITY`` option instead.
-#
-# ``DEPENDS`` | ``DEPENDENCIES``
-# list of dependency component or component group identifiers in
-# QtIFW_ style.
-#
-# ``AUTO_DEPEND_ON``
-# list of identifiers of component or component group in QtIFW_ style
-# that this component group has an automatic dependency on.
-#
-# ``LICENSES``
-# pair of <display_name> and <file_path> of license text for this
-# component group. You can specify more then one license.
-#
-# ``DEFAULT``
-# Possible values are: TRUE, FALSE, and SCRIPT.
-# Set to TRUE to preselect the group in the installer
-# (this takes effect only on groups that have no visible child components)
-# or to SCRIPT to resolved during runtime (don't forget add the file of
-# the script as a value of the ``SCRIPT`` option).
-#
-# ``USER_INTERFACES``
-# is a list of <file_path> ('.ui' files) representing pages to load.
-#
-# ``TRANSLATIONS``
-# is a list of <file_path> ('.qm' files) representing translations to load.
-#
-#
-# .. command:: cpack_ifw_add_repository
-#
-# Add QtIFW_ specific remote repository to binary installer.
-#
-# ::
-#
-# cpack_ifw_add_repository(<reponame> [DISABLED]
-# URL <url>
-# [USERNAME <username>]
-# [PASSWORD <password>]
-# [DISPLAY_NAME <display_name>])
-#
-# This command 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.
-#
-#
-# .. command:: cpack_ifw_update_repository
-#
-# Update QtIFW_ specific repository from remote repository.
-#
-# ::
-#
-# cpack_ifw_update_repository(<reponame>
-# [[ADD|REMOVE] URL <url>]|
-# [REPLACE OLD_URL <old_url> NEW_URL <new_url>]]
-# [USERNAME <username>]
-# [PASSWORD <password>]
-# [DISPLAY_NAME <display_name>])
-#
-# This command will also add the <reponame> repository
-# to a variable :variable:`CPACK_IFW_REPOSITORIES_ALL`.
-#
-# ``URL``
-# is points to a list of available components.
-#
-# ``OLD_URL``
-# is points to a list that will replaced.
-#
-# ``NEW_URL``
-# is points to a list that will replace to.
-#
-# ``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.
-#
-#
-# .. command:: cpack_ifw_add_package_resources
-#
-# Add additional resources in the installer binary.
-#
-# ::
-#
-# cpack_ifw_add_package_resources(<file_path> <file_path> ...)
-#
-# This command will also add the specified files
-# to a variable :variable:`CPACK_IFW_PACKAGE_RESOURCES`.
-#
-#
-# 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") # Default description
-# cpack_ifw_configure_component(myapp
-# DESCRIPTION ru_RU "Мое Приложение" # Localized description
-# 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 default CPack IFW generator makes 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 creates "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://doc.qt.io/qtinstallerframework/index.html
-#
-# * Component Scripting:
-# http://doc.qt.io/qtinstallerframework/scripting.html
-#
-# * Predefined Variables:
-# http://doc.qt.io/qtinstallerframework/scripting.html#predefined-variables
-#
-# * Promoting Updates:
-# http://doc.qt.io/qtinstallerframework/ifw-updates.html
-#
-# Download Qt Installer Framework for you platform from Qt site:
-# http://download.qt.io/official_releases/qt-installer-framework
-#
+#[=======================================================================[.rst:
+CPackIFW
+--------
+
+The documentation for the CPack IFW generator has moved here: :cpack_gen:`CPack IFW Generator`
+
+.. _QtIFW: http://doc.qt.io/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.
+
+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] [ESSENTIAL] [VIRTUAL]
+ [FORCED_INSTALLATION] [REQUIRES_ADMIN_RIGHTS]
+ [NAME <name>]
+ [DISPLAY_NAME <display_name>] # Note: Internationalization supported
+ [DESCRIPTION <description>] # Note: Internationalization supported
+ [UPDATE_TEXT <update_text>]
+ [VERSION <version>]
+ [RELEASE_DATE <release_date>]
+ [SCRIPT <script>]
+ [PRIORITY|SORTING_PRIORITY <sorting_priority>] # Note: PRIORITY is deprecated
+ [DEPENDS|DEPENDENCIES <com_id> ...]
+ [AUTO_DEPEND_ON <comp_id> ...]
+ [LICENSES <display_name> <file_path> ...]
+ [DEFAULT <value>]
+ [USER_INTERFACES <file_path> <file_path> ...]
+ [TRANSLATIONS <file_path> <file_path> ...]
+ [REPLACES <comp_id> ...]
+ [CHECKABLE <value>])
+
+ This command should be called after :command:`cpack_add_component` command.
+
+ ``COMMON``
+ if set, then the component will be packaged and installed as part
+ of a group to which it belongs.
+
+ ``ESSENTIAL``
+ if set, then the package manager stays disabled until that
+ component is updated.
+
+ ``VIRTUAL``
+ if set, then the component will be hidden from the installer.
+ It is a equivalent of the ``HIDDEN`` option from the
+ :command:`cpack_add_component` command.
+
+ ``FORCED_INSTALLATION``
+ if set, then the component must always be installed.
+ It is a equivalent of the ``REQUARED`` option from the
+ :command:`cpack_add_component` command.
+
+ ``REQUIRES_ADMIN_RIGHTS``
+ set it if the component needs to be installed with elevated permissions.
+
+ ``NAME``
+ is used to create domain-like identification for this component.
+ By default used origin component name.
+
+ ``DISPLAY_NAME``
+ set to rewrite original name configured by
+ :command:`cpack_add_component` command.
+
+ ``DESCRIPTION``
+ set to rewrite original description configured by
+ :command:`cpack_add_component` command.
+
+ ``UPDATE_TEXT``
+ will be added to the component description if this is an update to
+ the component.
+
+ ``VERSION``
+ is version of component.
+ By default used :variable:`CPACK_PACKAGE_VERSION`.
+
+ ``RELEASE_DATE``
+ keep empty to auto generate.
+
+ ``SCRIPT``
+ is a relative or absolute path to operations script
+ for this component.
+
+ ``PRIORITY`` | ``SORTING_PRIORITY``
+ is priority of the component in the tree.
+ The ``PRIORITY`` option is deprecated and will be removed in a future
+ version of CMake. Please use ``SORTING_PRIORITY`` option instead.
+
+ ``DEPENDS`` | ``DEPENDENCIES``
+ list of dependency component or component group identifiers in
+ QtIFW_ style.
+
+ ``AUTO_DEPEND_ON``
+ list of identifiers of component or component group in QtIFW_ style
+ that this component has an automatic dependency on.
+
+ ``LICENSES``
+ pair of <display_name> and <file_path> of license text for this
+ component. You can specify more then one license.
+
+ ``DEFAULT``
+ Possible values are: TRUE, FALSE, and SCRIPT.
+ Set to FALSE to disable the component in the installer or to SCRIPT
+ to resolved during runtime (don't forget add the file of the script
+ as a value of the ``SCRIPT`` option).
+
+ ``USER_INTERFACES``
+ is a list of <file_path> ('.ui' files) representing pages to load.
+
+ ``TRANSLATIONS``
+ is a list of <file_path> ('.qm' files) representing translations to load.
+
+ ``REPLACES``
+ list of identifiers of component or component group to replace.
+
+ ``CHECKABLE``
+ Possible values are: TRUE, FALSE.
+ Set to FALSE if you want to hide the checkbox for an item.
+ This is useful when only a few subcomponents should be selected
+ instead of all.
+
+
+.. command:: cpack_ifw_configure_component_group
+
+ Sets the arguments specific to the CPack IFW generator.
+
+ ::
+
+ cpack_ifw_configure_component_group(<groupname> [VIRTUAL]
+ [FORCED_INSTALLATION] [REQUIRES_ADMIN_RIGHTS]
+ [NAME <name>]
+ [DISPLAY_NAME <display_name>] # Note: Internationalization supported
+ [DESCRIPTION <description>] # Note: Internationalization supported
+ [UPDATE_TEXT <update_text>]
+ [VERSION <version>]
+ [RELEASE_DATE <release_date>]
+ [SCRIPT <script>]
+ [PRIORITY|SORTING_PRIORITY <sorting_priority>] # Note: PRIORITY is deprecated
+ [DEPENDS|DEPENDENCIES <com_id> ...]
+ [AUTO_DEPEND_ON <comp_id> ...]
+ [LICENSES <display_name> <file_path> ...]
+ [DEFAULT <value>]
+ [USER_INTERFACES <file_path> <file_path> ...]
+ [TRANSLATIONS <file_path> <file_path> ...]
+ [REPLACES <comp_id> ...]
+ [CHECKABLE <value>])
+
+ This command should be called after :command:`cpack_add_component_group`
+ command.
+
+ ``VIRTUAL``
+ if set, then the group will be hidden from the installer.
+ Note that setting this on a root component does not work.
+
+ ``FORCED_INSTALLATION``
+ if set, then the group must always be installed.
+
+ ``REQUIRES_ADMIN_RIGHTS``
+ set it if the component group needs to be installed with elevated
+ permissions.
+
+ ``NAME``
+ is used to create domain-like identification for this component group.
+ By default used origin component group name.
+
+ ``DISPLAY_NAME``
+ set to rewrite original name configured by
+ :command:`cpack_add_component_group` command.
+
+ ``DESCRIPTION``
+ set to rewrite original description configured by
+ :command:`cpack_add_component_group` command.
+
+ ``UPDATE_TEXT``
+ will be added to the component group description if this is an update to
+ the component group.
+
+ ``VERSION``
+ is version of component group.
+ By default used :variable:`CPACK_PACKAGE_VERSION`.
+
+ ``RELEASE_DATE``
+ keep empty to auto generate.
+
+ ``SCRIPT``
+ is a relative or absolute path to operations script
+ for this component group.
+
+ ``PRIORITY`` | ``SORTING_PRIORITY``
+ is priority of the component group in the tree.
+ The ``PRIORITY`` option is deprecated and will be removed in a future
+ version of CMake. Please use ``SORTING_PRIORITY`` option instead.
+
+ ``DEPENDS`` | ``DEPENDENCIES``
+ list of dependency component or component group identifiers in
+ QtIFW_ style.
+
+ ``AUTO_DEPEND_ON``
+ list of identifiers of component or component group in QtIFW_ style
+ that this component group has an automatic dependency on.
+
+ ``LICENSES``
+ pair of <display_name> and <file_path> of license text for this
+ component group. You can specify more then one license.
+
+ ``DEFAULT``
+ Possible values are: TRUE, FALSE, and SCRIPT.
+ Set to TRUE to preselect the group in the installer
+ (this takes effect only on groups that have no visible child components)
+ or to SCRIPT to resolved during runtime (don't forget add the file of
+ the script as a value of the ``SCRIPT`` option).
+
+ ``USER_INTERFACES``
+ is a list of <file_path> ('.ui' files) representing pages to load.
+
+ ``TRANSLATIONS``
+ is a list of <file_path> ('.qm' files) representing translations to load.
+
+ ``REPLACES``
+ list of identifiers of component or component group to replace.
+
+ ``CHECKABLE``
+ Possible values are: TRUE, FALSE.
+ Set to FALSE if you want to hide the checkbox for an item.
+ This is useful when only a few subcomponents should be selected
+ instead of all.
+
+
+.. command:: cpack_ifw_add_repository
+
+ Add QtIFW_ specific remote repository to binary installer.
+
+ ::
+
+ cpack_ifw_add_repository(<reponame> [DISABLED]
+ URL <url>
+ [USERNAME <username>]
+ [PASSWORD <password>]
+ [DISPLAY_NAME <display_name>])
+
+ This command 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.
+
+
+.. command:: cpack_ifw_update_repository
+
+ Update QtIFW_ specific repository from remote repository.
+
+ ::
+
+ cpack_ifw_update_repository(<reponame>
+ [[ADD|REMOVE] URL <url>]|
+ [REPLACE OLD_URL <old_url> NEW_URL <new_url>]]
+ [USERNAME <username>]
+ [PASSWORD <password>]
+ [DISPLAY_NAME <display_name>])
+
+ This command will also add the <reponame> repository
+ to a variable :variable:`CPACK_IFW_REPOSITORIES_ALL`.
+
+ ``URL``
+ is points to a list of available components.
+
+ ``OLD_URL``
+ is points to a list that will replaced.
+
+ ``NEW_URL``
+ is points to a list that will replace to.
+
+ ``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.
+
+
+.. command:: cpack_ifw_add_package_resources
+
+ Add additional resources in the installer binary.
+
+ ::
+
+ cpack_ifw_add_package_resources(<file_path> <file_path> ...)
+
+ This command will also add the specified files
+ to a variable :variable:`CPACK_IFW_PACKAGE_RESOURCES`.
+
+#]=======================================================================]
+
+# TODO:
+# All of the internal implementation CMake modules for other CPack generators
+# have been moved into the Internal/CPack directory. This one has not, because
+# it contains user-facing macros which would be lost if it were moved. At some
+# point, this module should be split into user-facing macros (which would live
+# in this module) and internal implementation details (which would live in
+# Internal/CPack/CPackIFW.cmake).
#=============================================================================
# Search Qt Installer Framework tools
@@ -776,7 +477,7 @@ if(CPACK_IFW_INSTALLERBASE_EXECUTABLE AND NOT CPACK_IFW_FRAMEWORK_VERSION_FORCED
endif()
endif()
endforeach()
- # Finaly try to get version from executable path
+ # Finally try to get version from executable path
if(NOT CPACK_IFW_FRAMEWORK_VERSION)
string(REGEX MATCH "[0-9]+(\\.[0-9]+)*"
CPACK_IFW_FRAMEWORK_VERSION "${CPACK_IFW_INSTALLERBASE_EXECUTABLE}")
@@ -796,7 +497,7 @@ if(CPACK_IFW_VERBOSE)
endif()
endif()
if(CPACK_IFW_INSTALLERBASE_EXECUTABLE AND NOT CPACK_IFW_FRAMEWORK_VERSION)
- message(WARNING "Could not detect QtIFW tools version. Set used version to variable \"CPACK_IFW_FRAMEWORK_VERSION_FORCED\" manualy.")
+ message(WARNING "Could not detect QtIFW tools version. Set used version to variable \"CPACK_IFW_FRAMEWORK_VERSION_FORCED\" manually.")
endif()
#=============================================================================
@@ -817,13 +518,13 @@ macro(_cpack_ifw_resolve_script _variable)
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")
+ message(WARNING "CPack IFW: script file \"${_ifw_script_file}\" does not exist")
set(${_ifw_script_macro})
endif()
endif()
endmacro()
-# Resolve full path to lisense file
+# Resolve full path to license file
macro(_cpack_ifw_resolve_lisenses _variable)
if(${_variable})
set(_ifw_license_file FALSE)
@@ -863,8 +564,8 @@ macro(cpack_ifw_configure_component compname)
string(TOUPPER ${compname} _CPACK_IFWCOMP_UNAME)
set(_IFW_OPT COMMON ESSENTIAL VIRTUAL FORCED_INSTALLATION REQUIRES_ADMIN_RIGHTS)
- set(_IFW_ARGS NAME VERSION RELEASE_DATE SCRIPT PRIORITY SORTING_PRIORITY UPDATE_TEXT DEFAULT)
- set(_IFW_MULTI_ARGS DISPLAY_NAME DESCRIPTION DEPENDS DEPENDENCIES AUTO_DEPEND_ON LICENSES USER_INTERFACES TRANSLATIONS)
+ set(_IFW_ARGS NAME VERSION RELEASE_DATE SCRIPT PRIORITY SORTING_PRIORITY UPDATE_TEXT DEFAULT CHECKABLE)
+ set(_IFW_MULTI_ARGS DISPLAY_NAME DESCRIPTION DEPENDS DEPENDENCIES AUTO_DEPEND_ON LICENSES USER_INTERFACES TRANSLATIONS REPLACES)
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)
@@ -904,8 +605,8 @@ macro(cpack_ifw_configure_component_group grpname)
string(TOUPPER ${grpname} _CPACK_IFWGRP_UNAME)
set(_IFW_OPT VIRTUAL FORCED_INSTALLATION REQUIRES_ADMIN_RIGHTS)
- set(_IFW_ARGS NAME VERSION RELEASE_DATE SCRIPT PRIORITY SORTING_PRIORITY UPDATE_TEXT DEFAULT)
- set(_IFW_MULTI_ARGS DISPLAY_NAME DESCRIPTION DEPENDS DEPENDENCIES AUTO_DEPEND_ON LICENSES USER_INTERFACES TRANSLATIONS)
+ set(_IFW_ARGS NAME VERSION RELEASE_DATE SCRIPT PRIORITY SORTING_PRIORITY UPDATE_TEXT DEFAULT CHECKABLE)
+ set(_IFW_MULTI_ARGS DISPLAY_NAME DESCRIPTION DEPENDS DEPENDENCIES AUTO_DEPEND_ON LICENSES USER_INTERFACES TRANSLATIONS REPLACES)
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)
@@ -915,6 +616,12 @@ macro(cpack_ifw_configure_component_group grpname)
set(_CPACK_IFWGRP_STR "\n# Configuration for IFW component group \"${grpname}\"\n")
+ foreach(_IFW_ARG_NAME ${_IFW_OPT})
+ cpack_append_option_set_command(
+ CPACK_IFW_COMPONENT_GROUP_${_CPACK_IFWGRP_UNAME}_${_IFW_ARG_NAME}
+ _CPACK_IFWGRP_STR)
+ endforeach()
+
foreach(_IFW_ARG_NAME ${_IFW_ARGS})
cpack_append_string_variable_set_command(
CPACK_IFW_COMPONENT_GROUP_${_CPACK_IFWGRP_UNAME}_${_IFW_ARG_NAME}
diff --git a/Modules/CPackIFWConfigureFile.cmake b/Modules/CPackIFWConfigureFile.cmake
index 790574a52..0abe0da37 100644
--- a/Modules/CPackIFWConfigureFile.cmake
+++ b/Modules/CPackIFWConfigureFile.cmake
@@ -1,32 +1,33 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CPackIFWConfigureFile
-# ---------------------
-#
-# The module defines :command:`configure_file` similar command to
-# configure file templates prepared in QtIFW/SDK/Creator style.
-#
-#
-# Commands
-# ^^^^^^^^
-#
-# The module defines the following commands:
-#
-# .. command:: cpack_ifw_configure_file
-#
-# Copy a file to another location and modify its contents.
-#
-# ::
-#
-# cpack_ifw_configure_file(<input> <output>)
-#
-# Copies an ``<input>`` file to an ``<output>`` file and substitutes variable
-# values referenced as ``%{VAR}`` or ``%VAR%`` in the input file content.
-# Each variable reference will be replaced with the current value of the
-# variable, or the empty string if the variable is not defined.
-#
+#[=======================================================================[.rst:
+CPackIFWConfigureFile
+---------------------
+
+The module defines :command:`configure_file` similar command to
+configure file templates prepared in QtIFW/SDK/Creator style.
+
+
+Commands
+^^^^^^^^
+
+The module defines the following commands:
+
+.. command:: cpack_ifw_configure_file
+
+ Copy a file to another location and modify its contents.
+
+ ::
+
+ cpack_ifw_configure_file(<input> <output>)
+
+ Copies an ``<input>`` file to an ``<output>`` file and substitutes variable
+ values referenced as ``%{VAR}`` or ``%VAR%`` in the input file content.
+ Each variable reference will be replaced with the current value of the
+ variable, or the empty string if the variable is not defined.
+
+#]=======================================================================]
# NOTE: This file used to himself packaging via CPack IFW generator and
# should be compatible with minimal CMake version defined in
diff --git a/Modules/CSharpUtilities.cmake b/Modules/CSharpUtilities.cmake
index e9e1510b6..6a4b5c7f7 100644
--- a/Modules/CSharpUtilities.cmake
+++ b/Modules/CSharpUtilities.cmake
@@ -184,6 +184,9 @@ Helper functions which are used by the above ones
#]=======================================================================]
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
function(csharp_get_filename_keys OUT)
set(${OUT} "")
foreach(f ${ARGN})
@@ -304,3 +307,5 @@ function(csharp_set_xaml_cs_properties)
endif()
endforeach()
endfunction()
+
+cmake_policy(POP)
diff --git a/Modules/CTest.cmake b/Modules/CTest.cmake
index 9370596a8..3a111ca92 100644
--- a/Modules/CTest.cmake
+++ b/Modules/CTest.cmake
@@ -27,12 +27,8 @@ 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)
+ set(CTEST_SUBMIT_URL "http://my.cdash.org/submit.php?project=MyProject")
(the CDash server can provide the file to a project administrator who
configures ``MyProject``). Settings in the config file are shared by
@@ -54,7 +50,7 @@ in the ``CTestConfig.cmake`` file.
option(BUILD_TESTING "Build the testing tree." ON)
# function to turn generator name into a version string
-# like vs8 vs9
+# like vs9 or vs10
function(GET_VS_VERSION_STRING generator var)
string(REGEX REPLACE "Visual Studio ([0-9][0-9]?)($|.*)" "\\1"
NUMBER "${generator}")
@@ -65,7 +61,7 @@ endfunction()
include(CTestUseLaunchers)
if(BUILD_TESTING)
- # Setup some auxilary macros
+ # Setup some auxiliary macros
macro(SET_IF_NOT_SET var val)
if(NOT DEFINED "${var}")
set("${var}" "${val}")
@@ -90,6 +86,7 @@ if(BUILD_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(SUBMIT_URL "${CTEST_SUBMIT_URL}")
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}")
@@ -112,6 +109,18 @@ if(BUILD_TESTING)
endif()
SET_IF_NOT_SET (NIGHTLY_START_TIME "00:00:00 EDT")
+ if(NOT SUBMIT_URL)
+ set(SUBMIT_URL "${DROP_METHOD}://")
+ if(DROP_SITE_USER)
+ string(APPEND SUBMIT_URL "${DROP_SITE_USER}")
+ if(DROP_SITE_PASSWORD)
+ string(APPEND SUBMIT_URL ":${DROP_SITE_PASSWORD}")
+ endif()
+ string(APPEND SUBMIT_URL "@")
+ endif()
+ string(APPEND SUBMIT_URL "${DROP_SITE}${DROP_LOCATION}")
+ endif()
+
find_program(CVSCOMMAND cvs )
set(CVS_UPDATE_OPTIONS "-d -A -P" CACHE STRING
"Options passed to the cvs update command.")
@@ -178,9 +187,6 @@ if(BUILD_TESTING)
)
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"
)
diff --git a/Modules/CTestCoverageCollectGCOV.cmake b/Modules/CTestCoverageCollectGCOV.cmake
index 1203be4c2..655827a73 100644
--- a/Modules/CTestCoverageCollectGCOV.cmake
+++ b/Modules/CTestCoverageCollectGCOV.cmake
@@ -1,69 +1,70 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CTestCoverageCollectGCOV
-# ------------------------
-#
-# This module provides the ``ctest_coverage_collect_gcov`` function.
-#
-# This function runs gcov on all .gcda files found in the binary tree
-# and packages the resulting .gcov files into a tar file.
-# This tarball also contains the following:
-#
-# * *data.json* defines the source and build directories for use by CDash.
-# * *Labels.json* indicates any :prop_sf:`LABELS` that have been set on the
-# source files.
-# * The *uncovered* directory holds any uncovered files found by
-# :variable:`CTEST_EXTRA_COVERAGE_GLOB`.
-#
-# After generating this tar file, it can be sent to CDash for display with the
-# :command:`ctest_submit(CDASH_UPLOAD)` command.
-#
-# .. command:: cdash_coverage_collect_gcov
-#
-# ::
-#
-# ctest_coverage_collect_gcov(TARBALL <tarfile>
-# [SOURCE <source_dir>][BUILD <build_dir>]
-# [GCOV_COMMAND <gcov_command>]
-# [GCOV_OPTIONS <options>...]
-# )
-#
-# Run gcov and package a tar file for CDash. The options are:
-#
-# ``TARBALL <tarfile>``
-# Specify the location of the ``.tar`` file to be created for later
-# upload to CDash. Relative paths will be interpreted with respect
-# to the top-level build directory.
-#
-# ``SOURCE <source_dir>``
-# Specify the top-level source directory for the build.
-# Default is the value of :variable:`CTEST_SOURCE_DIRECTORY`.
-#
-# ``BUILD <build_dir>``
-# Specify the top-level build directory for the build.
-# Default is the value of :variable:`CTEST_BINARY_DIRECTORY`.
-#
-# ``GCOV_COMMAND <gcov_command>``
-# Specify the full path to the ``gcov`` command on the machine.
-# Default is the value of :variable:`CTEST_COVERAGE_COMMAND`.
-#
-# ``GCOV_OPTIONS <options>...``
-# Specify options to be passed to gcov. The ``gcov`` command
-# is run as ``gcov <options>... -o <gcov-dir> <file>.gcda``.
-# If not specified, the default option is just ``-b``.
-#
-# ``GLOB``
-# Recursively search for .gcda files in build_dir rather than
-# determining search locations by reading TargetDirectories.txt.
-#
-# ``DELETE``
-# Delete coverage files after they've been packaged into the .tar.
-#
-# ``QUIET``
-# Suppress non-error messages that otherwise would have been
-# printed out by this function.
+#[=======================================================================[.rst:
+CTestCoverageCollectGCOV
+------------------------
+
+This module provides the ``ctest_coverage_collect_gcov`` function.
+
+This function runs gcov on all .gcda files found in the binary tree
+and packages the resulting .gcov files into a tar file.
+This tarball also contains the following:
+
+* *data.json* defines the source and build directories for use by CDash.
+* *Labels.json* indicates any :prop_sf:`LABELS` that have been set on the
+ source files.
+* The *uncovered* directory holds any uncovered files found by
+ :variable:`CTEST_EXTRA_COVERAGE_GLOB`.
+
+After generating this tar file, it can be sent to CDash for display with the
+:command:`ctest_submit(CDASH_UPLOAD)` command.
+
+.. command:: cdash_coverage_collect_gcov
+
+ ::
+
+ ctest_coverage_collect_gcov(TARBALL <tarfile>
+ [SOURCE <source_dir>][BUILD <build_dir>]
+ [GCOV_COMMAND <gcov_command>]
+ [GCOV_OPTIONS <options>...]
+ )
+
+ Run gcov and package a tar file for CDash. The options are:
+
+ ``TARBALL <tarfile>``
+ Specify the location of the ``.tar`` file to be created for later
+ upload to CDash. Relative paths will be interpreted with respect
+ to the top-level build directory.
+
+ ``SOURCE <source_dir>``
+ Specify the top-level source directory for the build.
+ Default is the value of :variable:`CTEST_SOURCE_DIRECTORY`.
+
+ ``BUILD <build_dir>``
+ Specify the top-level build directory for the build.
+ Default is the value of :variable:`CTEST_BINARY_DIRECTORY`.
+
+ ``GCOV_COMMAND <gcov_command>``
+ Specify the full path to the ``gcov`` command on the machine.
+ Default is the value of :variable:`CTEST_COVERAGE_COMMAND`.
+
+ ``GCOV_OPTIONS <options>...``
+ Specify options to be passed to gcov. The ``gcov`` command
+ is run as ``gcov <options>... -o <gcov-dir> <file>.gcda``.
+ If not specified, the default option is just ``-b -x``.
+
+ ``GLOB``
+ Recursively search for .gcda files in build_dir rather than
+ determining search locations by reading TargetDirectories.txt.
+
+ ``DELETE``
+ Delete coverage files after they've been packaged into the .tar.
+
+ ``QUIET``
+ Suppress non-error messages that otherwise would have been
+ printed out by this function.
+#]=======================================================================]
function(ctest_coverage_collect_gcov)
set(options QUIET GLOB DELETE)
@@ -94,7 +95,7 @@ function(ctest_coverage_collect_gcov)
set(gcda_files)
set(label_files)
if (GCOV_GLOB)
- file(GLOB_RECURSE gfiles RELATIVE ${binary_dir} "${binary_dir}/*.gcda")
+ file(GLOB_RECURSE gfiles "${binary_dir}/*.gcda")
list(LENGTH gfiles len)
# if we have gcda files then also grab the labels file for that target
if(${len} GREATER 0)
@@ -108,7 +109,7 @@ function(ctest_coverage_collect_gcov)
file(STRINGS "${binary_dir}/CMakeFiles/TargetDirectories.txt" target_dirs
ENCODING UTF-8)
foreach(target_dir ${target_dirs})
- file(GLOB_RECURSE gfiles RELATIVE ${binary_dir} "${target_dir}/*.gcda")
+ file(GLOB_RECURSE gfiles "${target_dir}/*.gcda")
list(LENGTH gfiles len)
# if we have gcda files then also grab the labels file for that target
if(${len} GREATER 0)
@@ -131,27 +132,21 @@ function(ctest_coverage_collect_gcov)
# setup the dir for the coverage files
set(coverage_dir "${binary_dir}/Testing/CoverageInfo")
file(MAKE_DIRECTORY "${coverage_dir}")
- # call gcov on each .gcda file
- foreach (gcda_file ${gcda_files})
- # get the directory of the gcda file
- get_filename_component(gcda_file ${binary_dir}/${gcda_file} ABSOLUTE)
- get_filename_component(gcov_dir ${gcda_file} DIRECTORY)
- # run gcov, this will produce the .gcov file in the current
- # working directory
- if(NOT DEFINED GCOV_GCOV_OPTIONS)
- set(GCOV_GCOV_OPTIONS -b)
- endif()
- execute_process(COMMAND
- ${gcov_command} ${GCOV_GCOV_OPTIONS} -o ${gcov_dir} ${gcda_file}
- OUTPUT_VARIABLE out
- RESULT_VARIABLE res
- WORKING_DIRECTORY ${coverage_dir})
-
- if (GCOV_DELETE)
- file(REMOVE ${gcda_file})
- endif()
+ # run gcov, this will produce the .gcov files in the current
+ # working directory
+ if(NOT DEFINED GCOV_GCOV_OPTIONS)
+ set(GCOV_GCOV_OPTIONS -b -x)
+ endif()
+ execute_process(COMMAND
+ ${gcov_command} ${GCOV_GCOV_OPTIONS} ${gcda_files}
+ OUTPUT_VARIABLE out
+ RESULT_VARIABLE res
+ WORKING_DIRECTORY ${coverage_dir})
+
+ if (GCOV_DELETE)
+ file(REMOVE ${gcda_files})
+ endif()
- endforeach()
if(NOT "${res}" EQUAL 0)
if (NOT GCOV_QUIET)
message(STATUS "Error running gcov: ${res} ${out}")
diff --git a/Modules/CTestScriptMode.cmake b/Modules/CTestScriptMode.cmake
index 5be78d5a3..7af3577e0 100644
--- a/Modules/CTestScriptMode.cmake
+++ b/Modules/CTestScriptMode.cmake
@@ -1,13 +1,14 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CTestScriptMode
-# ---------------
-#
-#
-#
-# This file is read by ctest in script mode (-S)
+#[=======================================================================[.rst:
+CTestScriptMode
+---------------
+
+
+
+This file is read by ctest in script mode (-S)
+#]=======================================================================]
# Determine the current system, so this information can be used
# in ctest scripts
diff --git a/Modules/CTestTargets.cmake b/Modules/CTestTargets.cmake
index ff9aada54..838fbbfeb 100644
--- a/Modules/CTestTargets.cmake
+++ b/Modules/CTestTargets.cmake
@@ -3,7 +3,7 @@
if(NOT RUN_FROM_CTEST_OR_DART)
- message(FATAL_ERROR "Do not incldue CTestTargets.cmake directly")
+ message(FATAL_ERROR "Do not include CTestTargets.cmake directly")
endif()
if(NOT PROJECT_BINARY_DIR)
@@ -38,7 +38,8 @@ endif()
#
set(__conf_types "")
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
# We need to pass the configuration type on the test command line.
set(__conf_types -C "${CMAKE_CFG_INTDIR}")
endif()
diff --git a/Modules/CTestUseLaunchers.cmake b/Modules/CTestUseLaunchers.cmake
index dc90513a9..3dff92605 100644
--- a/Modules/CTestUseLaunchers.cmake
+++ b/Modules/CTestUseLaunchers.cmake
@@ -1,32 +1,33 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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. If CTEST_USE_LAUNCHERS is on in a ctest -S script
-# the ctest_configure command will add -DCTEST_USE_LAUNCHERS:BOOL=TRUE
-# to the cmake command used to configure the project.
+#[=======================================================================[.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. If CTEST_USE_LAUNCHERS is on in a ctest -S script
+the ctest_configure command will add -DCTEST_USE_LAUNCHERS:BOOL=TRUE
+to the cmake command used to configure the project.
+#]=======================================================================]
if(NOT DEFINED CTEST_USE_LAUNCHERS AND DEFINED ENV{CTEST_USE_LAUNCHERS_DEFAULT})
set(CTEST_USE_LAUNCHERS "$ENV{CTEST_USE_LAUNCHERS_DEFAULT}"
diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake
index 1ba67fca3..a3e2da368 100644
--- a/Modules/CheckCCompilerFlag.cmake
+++ b/Modules/CheckCCompilerFlag.cmake
@@ -1,52 +1,63 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+CheckCCompilerFlag
+------------------
+Check whether the C compiler supports a given flag.
+
+.. command:: check_c_compiler_flag
+
+ .. code-block:: cmake
+
+ check_c_compiler_flag(<flag> <var>)
+
+ Check that the ``<flag>`` is accepted by the compiler without
+ a diagnostic. Stores the result in an internal cache entry
+ named ``<var>``.
+
+This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable
+and calls the ``check_c_source_compiles`` macro from the
+:module:`CheckCSourceCompiles` module. See documentation of that
+module for a listing of variables that can otherwise modify the build.
+
+A positive result from this check indicates only that the compiler did not
+issue a diagnostic message when given the flag. Whether the flag has any
+effect or even a specific one is beyond the scope of this module.
+
+.. note::
+ Since the :command:`try_compile` command forwards flags from variables
+ like :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags
+ in such variables may cause a false negative for this check.
+#]=======================================================================]
+
+include_guard(GLOBAL)
include(CheckCSourceCompiles)
include(CMakeCheckCompilerFlagCommonPatterns)
macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
- set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
- set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
+ 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}")
+ 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
index ac2c6c583..77ba0cc46 100644
--- a/Modules/CheckCSourceCompiles.cmake
+++ b/Modules/CheckCSourceCompiles.cmake
@@ -1,31 +1,71 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckCSourceCompiles
+--------------------
+
+Check if given C source compiles and links into an executable.
+
+.. command:: check_c_source_compiles
+
+ .. code-block:: cmake
+
+ check_c_source_compiles(<code> <resultVar>
+ [FAIL_REGEX <regex1> [<regex2>...]])
+
+ Check that the source supplied in ``<code>`` can be compiled as a C source
+ file and linked as an executable (so it must contain at least a ``main()``
+ function). The result will be stored in the internal cache variable specified
+ by ``<resultVar>``, with a boolean true value for success and boolean false
+ for failure. If ``FAIL_REGEX`` is provided, then failure is determined by
+ checking if anything in the output matches any of the specified regular
+ expressions.
+
+ The underlying check is performed by the :command:`try_compile` command. The
+ compile and link commands can be influenced by setting any of the following
+ variables prior to calling ``check_c_source_compiles()``:
+
+ ``CMAKE_REQUIRED_FLAGS``
+ Additional flags to pass to the compiler. Note that the contents of
+ :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
+ configuration-specific variable are automatically added to the compiler
+ command before the contents of ``CMAKE_REQUIRED_FLAGS``.
+
+ ``CMAKE_REQUIRED_DEFINITIONS``
+ A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
+ ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
+ ``<resultVar>`` will also be added automatically.
+
+ ``CMAKE_REQUIRED_INCLUDES``
+ A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler. These will be the only header search paths used by
+ ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
+ directory property will be ignored.
+
+ ``CMAKE_REQUIRED_LINK_OPTIONS``
+ A :ref:`;-list <CMake Language Lists>` of options to add to the link
+ command (see :command:`try_compile` for further details).
+
+ ``CMAKE_REQUIRED_LIBRARIES``
+ A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. These can be the name of system libraries or they can be
+ :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for
+ further details).
+
+ ``CMAKE_REQUIRED_QUIET``
+ If this variable evaluates to a boolean true value, all status messages
+ associated with the check will be suppressed.
+
+ The check is only performed once, with the result cached in the variable
+ named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
+ value rather than performing the check again, even if the ``<code>`` changes.
+ In order to force the check to be re-evaluated, the variable named by
+ ``<resultVar>`` must be manually removed from the cache.
+
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
if(NOT DEFINED "${VAR}")
@@ -42,6 +82,12 @@ macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
endforeach()
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -64,6 +110,7 @@ macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS}
${CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
"${CHECK_C_SOURCE_COMPILES_ADD_INCLUDES}"
@@ -96,4 +143,3 @@ macro(CHECK_C_SOURCE_COMPILES SOURCE VAR)
endif()
endif()
endmacro()
-
diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake
index 70aa9fd2d..eba70f2ba 100644
--- a/Modules/CheckCSourceRuns.cmake
+++ b/Modules/CheckCSourceRuns.cmake
@@ -1,36 +1,81 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckCSourceRuns
+----------------
+
+Check if given C source compiles and links into an executable and can
+subsequently be run.
+
+.. command:: check_c_source_runs
+
+ .. code-block:: cmake
+
+ check_c_source_runs(<code> <resultVar>)
+
+ Check that the source supplied in ``<code>`` can be compiled as a C source
+ file, linked as an executable and then run. The ``<code>`` must contain at
+ least a ``main()`` function. If the ``<code>`` could be built and run
+ successfully, the internal cache variable specified by ``<resultVar>`` will
+ be set to 1, otherwise it will be set to an value that evaluates to boolean
+ false (e.g. an empty string or an error message).
+
+ The underlying check is performed by the :command:`try_run` command. The
+ compile and link commands can be influenced by setting any of the following
+ variables prior to calling ``check_c_source_runs()``:
+
+ ``CMAKE_REQUIRED_FLAGS``
+ Additional flags to pass to the compiler. Note that the contents of
+ :variable:`CMAKE_C_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
+ configuration-specific variable are automatically added to the compiler
+ command before the contents of ``CMAKE_REQUIRED_FLAGS``.
+
+ ``CMAKE_REQUIRED_DEFINITIONS``
+ A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
+ ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
+ ``<resultVar>`` will also be added automatically.
+
+ ``CMAKE_REQUIRED_INCLUDES``
+ A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler. These will be the only header search paths used by
+ ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
+ directory property will be ignored.
+
+ ``CMAKE_REQUIRED_LINK_OPTIONS``
+ A :ref:`;-list <CMake Language Lists>` of options to add to the link
+ command (see :command:`try_run` for further details).
+
+ ``CMAKE_REQUIRED_LIBRARIES``
+ A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. These can be the name of system libraries or they can be
+ :ref:`Imported Targets <Imported Targets>` (see :command:`try_run` for
+ further details).
+
+ ``CMAKE_REQUIRED_QUIET``
+ If this variable evaluates to a boolean true value, all status messages
+ associated with the check will be suppressed.
+
+ The check is only performed once, with the result cached in the variable
+ named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
+ value rather than performing the check again, even if the ``<code>`` changes.
+ In order to force the check to be re-evaluated, the variable named by
+ ``<resultVar>`` must be manually removed from the cache.
+
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
if(NOT DEFINED "${VAR}")
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -53,11 +98,13 @@ macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_C_SOURCE_COMPILES_ADD_LINK_OPTIONS}
${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)
+ COMPILE_OUTPUT_VARIABLE OUTPUT
+ RUN_OUTPUT_VARIABLE RUN_OUTPUT)
# if it did not compile make the return value fail code of 1
if(NOT ${VAR}_COMPILED)
set(${VAR}_EXITCODE 1)
@@ -69,8 +116,10 @@ macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
message(STATUS "Performing Test ${VAR} - Success")
endif()
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
- "Performing C SOURCE FILE Test ${VAR} succeeded with the following output:\n"
+ "Performing C SOURCE FILE Test ${VAR} succeeded with the following compile output:\n"
"${OUTPUT}\n"
+ "...and run output:\n"
+ "${RUN_OUTPUT}\n"
"Return value: ${${VAR}}\n"
"Source file was:\n${SOURCE}\n")
else()
@@ -84,12 +133,13 @@ macro(CHECK_C_SOURCE_RUNS SOURCE VAR)
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"
+ "Performing C SOURCE FILE Test ${VAR} failed with the following compile output:\n"
"${OUTPUT}\n"
+ "...and run output:\n"
+ "${RUN_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
index afbb23128..5729843c3 100644
--- a/Modules/CheckCXXCompilerFlag.cmake
+++ b/Modules/CheckCXXCompilerFlag.cmake
@@ -1,52 +1,63 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+CheckCXXCompilerFlag
+------------------------
+Check whether the CXX compiler supports a given flag.
+
+.. command:: check_cxx_compiler_flag
+
+ .. code-block:: cmake
+
+ check_cxx_compiler_flag(<flag> <var>)
+
+ Check that the ``<flag>`` is accepted by the compiler without
+ a diagnostic. Stores the result in an internal cache entry
+ named ``<var>``.
+
+This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable
+and calls the ``check_cxx_source_compiles`` macro from the
+:module:`CheckCXXSourceCompiles` module. See documentation of that
+module for a listing of variables that can otherwise modify the build.
+
+A positive result from this check indicates only that the compiler did not
+issue a diagnostic message when given the flag. Whether the flag has any
+effect or even a specific one is beyond the scope of this module.
+
+.. note::
+ Since the :command:`try_compile` command forwards flags from variables
+ like :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags
+ in such variables may cause a false negative for this check.
+#]=======================================================================]
+
+include_guard(GLOBAL)
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 ()
+ 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
index e54d09e61..cc457a565 100644
--- a/Modules/CheckCXXSourceCompiles.cmake
+++ b/Modules/CheckCXXSourceCompiles.cmake
@@ -1,31 +1,71 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckCXXSourceCompiles
+----------------------
+
+Check if given C++ source compiles and links into an executable.
+
+.. command:: check_cxx_source_compiles
+
+ .. code-block:: cmake
+
+ check_cxx_source_compiles(<code> <resultVar>
+ [FAIL_REGEX <regex1> [<regex2>...]])
+
+ Check that the source supplied in ``<code>`` can be compiled as a C++ source
+ file and linked as an executable (so it must contain at least a ``main()``
+ function). The result will be stored in the internal cache variable specified
+ by ``<resultVar>``, with a boolean true value for success and boolean false
+ for failure. If ``FAIL_REGEX`` is provided, then failure is determined by
+ checking if anything in the output matches any of the specified regular
+ expressions.
+
+ The underlying check is performed by the :command:`try_compile` command. The
+ compile and link commands can be influenced by setting any of the following
+ variables prior to calling ``check_cxx_source_compiles()``:
+
+ ``CMAKE_REQUIRED_FLAGS``
+ Additional flags to pass to the compiler. Note that the contents of
+ :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
+ configuration-specific variable are automatically added to the compiler
+ command before the contents of ``CMAKE_REQUIRED_FLAGS``.
+
+ ``CMAKE_REQUIRED_DEFINITIONS``
+ A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
+ ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
+ ``<resultVar>`` will also be added automatically.
+
+ ``CMAKE_REQUIRED_INCLUDES``
+ A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler. These will be the only header search paths used by
+ ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
+ directory property will be ignored.
+
+ ``CMAKE_REQUIRED_LINK_OPTIONS``
+ A :ref:`;-list <CMake Language Lists>` of options to add to the link
+ command (see :command:`try_compile` for further details).
+
+ ``CMAKE_REQUIRED_LIBRARIES``
+ A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. These can be the name of system libraries or they can be
+ :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for
+ further details).
+
+ ``CMAKE_REQUIRED_QUIET``
+ If this variable evaluates to a boolean true value, all status messages
+ associated with the check will be suppressed.
+
+ The check is only performed once, with the result cached in the variable
+ named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
+ value rather than performing the check again, even if the ``<code>`` changes.
+ In order to force the check to be re-evaluated, the variable named by
+ ``<resultVar>`` must be manually removed from the cache.
+
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
if(NOT DEFINED "${VAR}")
@@ -43,6 +83,12 @@ macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -65,6 +111,7 @@ macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS}
${CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
"${CHECK_CXX_SOURCE_COMPILES_ADD_INCLUDES}"
@@ -97,4 +144,3 @@ macro(CHECK_CXX_SOURCE_COMPILES SOURCE VAR)
endif()
endif()
endmacro()
-
diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake
index e08365950..5e3f19581 100644
--- a/Modules/CheckCXXSourceRuns.cmake
+++ b/Modules/CheckCXXSourceRuns.cmake
@@ -1,36 +1,81 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckCXXSourceRuns
+------------------
+
+Check if given C++ source compiles and links into an executable and can
+subsequently be run.
+
+.. command:: check_cxx_source_runs
+
+ .. code-block:: cmake
+
+ check_cxx_source_runs(<code> <resultVar>)
+
+ Check that the source supplied in ``<code>`` can be compiled as a C++ source
+ file, linked as an executable and then run. The ``<code>`` must contain at
+ least a ``main()`` function. If the ``<code>`` could be built and run
+ successfully, the internal cache variable specified by ``<resultVar>`` will
+ be set to 1, otherwise it will be set to an value that evaluates to boolean
+ false (e.g. an empty string or an error message).
+
+ The underlying check is performed by the :command:`try_run` command. The
+ compile and link commands can be influenced by setting any of the following
+ variables prior to calling ``check_cxx_source_runs()``:
+
+ ``CMAKE_REQUIRED_FLAGS``
+ Additional flags to pass to the compiler. Note that the contents of
+ :variable:`CMAKE_CXX_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
+ configuration-specific variable are automatically added to the compiler
+ command before the contents of ``CMAKE_REQUIRED_FLAGS``.
+
+ ``CMAKE_REQUIRED_DEFINITIONS``
+ A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
+ ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
+ ``<resultVar>`` will also be added automatically.
+
+ ``CMAKE_REQUIRED_INCLUDES``
+ A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler. These will be the only header search paths used by
+ ``try_run()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
+ directory property will be ignored.
+
+ ``CMAKE_REQUIRED_LINK_OPTIONS``
+ A :ref:`;-list <CMake Language Lists>` of options to add to the link
+ command (see :command:`try_run` for further details).
+
+ ``CMAKE_REQUIRED_LIBRARIES``
+ A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. These can be the name of system libraries or they can be
+ :ref:`Imported Targets <Imported Targets>` (see :command:`try_run` for
+ further details).
+
+ ``CMAKE_REQUIRED_QUIET``
+ If this variable evaluates to a boolean true value, all status messages
+ associated with the check will be suppressed.
+
+ The check is only performed once, with the result cached in the variable
+ named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
+ value rather than performing the check again, even if the ``<code>`` changes.
+ In order to force the check to be re-evaluated, the variable named by
+ ``<resultVar>`` must be manually removed from the cache.
+
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR)
if(NOT DEFINED "${VAR}")
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -53,11 +98,13 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR)
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_CXX_SOURCE_COMPILES_ADD_LINK_OPTIONS}
${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)
+ COMPILE_OUTPUT_VARIABLE OUTPUT
+ RUN_OUTPUT_VARIABLE RUN_OUTPUT)
# if it did not compile make the return value fail code of 1
if(NOT ${VAR}_COMPILED)
@@ -72,6 +119,8 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE VAR)
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Performing C++ SOURCE FILE Test ${VAR} succeeded with the following output:\n"
"${OUTPUT}\n"
+ "...and run output:\n"
+ "${RUN_OUTPUT}\n"
"Return value: ${${VAR}}\n"
"Source file was:\n${SOURCE}\n")
else()
@@ -87,9 +136,10 @@ macro(CHECK_CXX_SOURCE_RUNS SOURCE 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"
+ "...and run output:\n"
+ "${RUN_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
index 354eea3d2..2cccd09ff 100644
--- a/Modules/CheckCXXSymbolExists.cmake
+++ b/Modules/CheckCXXSymbolExists.cmake
@@ -1,39 +1,53 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckCXXSymbolExists
+--------------------
+Check if a symbol exists as a function, variable, or macro in C++
+
+.. command:: CHECK_CXX_SYMBOL_EXISTS
+
+ .. code-block:: cmake
+
+ 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 :module:`CheckTypeSize`
+ or :module:`CheckCXXSourceCompiles`).
+
+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``
+ a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
+``CMAKE_REQUIRED_INCLUDES``
+ a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler.
+``CMAKE_REQUIRED_LINK_OPTIONS``
+ a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
+``CMAKE_REQUIRED_LIBRARIES``
+ a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. See policy :policy:`CMP0075`.
+``CMAKE_REQUIRED_QUIET``
+ execute quietly without messages.
+#]=======================================================================]
+
+include_guard(GLOBAL)
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}" )
+ __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
endmacro()
diff --git a/Modules/CheckForPthreads.c b/Modules/CheckForPthreads.c
index 6fc6f2634..e70ceb1da 100644
--- a/Modules/CheckForPthreads.c
+++ b/Modules/CheckForPthreads.c
@@ -1,41 +1,15 @@
#include <pthread.h>
-#include <stdio.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[])
+void* start_routine(void* args)
{
-#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;
+ return args;
}
-void* runner(void* args)
+int main(void)
{
- int cc;
- for (cc = 0; cc < 10; cc++) {
- printf("%p CC: %d\n", args, cc);
- }
- res++;
+ /* This is a compile and link test, no code to actually run things. */
+ pthread_t thread;
+ pthread_create(&thread, 0, start_routine, 0);
+ pthread_join(thread, 0);
return 0;
}
diff --git a/Modules/CheckFortranCompilerFlag.cmake b/Modules/CheckFortranCompilerFlag.cmake
index 8519fccf7..299cd8cfc 100644
--- a/Modules/CheckFortranCompilerFlag.cmake
+++ b/Modules/CheckFortranCompilerFlag.cmake
@@ -1,28 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CheckFortranCompilerFlag
-# ------------------------
-#
-# Check whether the Fortran compiler supports a given flag.
-#
-# CHECK_Fortran_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_fortran_source_compiles macro and
-# sets CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for
-# CheckFortranSourceCompiles 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.
+#[=======================================================================[.rst:
+CheckFortranCompilerFlag
+------------------------
+Check whether the Fortran compiler supports a given flag.
+
+.. command:: check_fortran_compiler_flag
+
+ .. code-block:: cmake
+
+ check_fortran_compiler_flag(<flag> <var>)
+
+ Check that the ``<flag>`` is accepted by the compiler without
+ a diagnostic. Stores the result in an internal cache entry
+ named ``<var>``.
+
+This command temporarily sets the ``CMAKE_REQUIRED_DEFINITIONS`` variable
+and calls the ``check_fortran_source_compiles`` macro from the
+:module:`CheckFortranSourceCompiles` module. See documentation of that
+module for a listing of variables that can otherwise modify the build.
+
+A positive result from this check indicates only that the compiler did not
+issue a diagnostic message when given the flag. Whether the flag has any
+effect or even a specific one is beyond the scope of this module.
+
+.. note::
+ Since the :command:`try_compile` command forwards flags from variables
+ like :variable:`CMAKE_Fortran_FLAGS <CMAKE_<LANG>_FLAGS>`, unknown flags
+ in such variables may cause a false negative for this check.
+#]=======================================================================]
+
+include_guard(GLOBAL)
include(CheckFortranSourceCompiles)
include(CMakeCheckCompilerFlagCommonPatterns)
diff --git a/Modules/CheckFortranFunctionExists.cmake b/Modules/CheckFortranFunctionExists.cmake
index 5fc740ab8..7ca205a6d 100644
--- a/Modules/CheckFortranFunctionExists.cmake
+++ b/Modules/CheckFortranFunctionExists.cmake
@@ -1,32 +1,50 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckFortranFunctionExists
+--------------------------
+
+Check if a Fortran function exists.
+
+.. command:: CHECK_FORTRAN_FUNCTION_EXISTS
+
+ .. code-block:: cmake
+
+ CHECK_FORTRAN_FUNCTION_EXISTS(<function> <result>)
+
+ where
+
+ ``<function>``
+ the name of the Fortran function
+ ``<result>``
+ 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_LINK_OPTIONS``
+ A :ref:`;-list <CMake Language Lists>` of options to add to the link
+ command (see :command:`try_compile` for further details).
+
+``CMAKE_REQUIRED_LIBRARIES``
+ A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. These can be the name of system libraries or they can be
+ :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for
+ further details).
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
if(NOT DEFINED ${VARIABLE})
message(STATUS "Looking for Fortran ${FUNCTION}")
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -45,6 +63,7 @@ macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE)
try_compile(${VARIABLE}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f
+ ${CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS}
${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
OUTPUT_VARIABLE OUTPUT
)
diff --git a/Modules/CheckFortranSourceCompiles.cmake b/Modules/CheckFortranSourceCompiles.cmake
index c42254cd9..f94b25468 100644
--- a/Modules/CheckFortranSourceCompiles.cmake
+++ b/Modules/CheckFortranSourceCompiles.cmake
@@ -1,35 +1,90 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CheckFortranSourceCompiles
-# --------------------------
-#
-# Check if given Fortran source compiles and links into an executable::
-#
-# CHECK_Fortran_SOURCE_COMPILES(<code> <var> [FAIL_REGEX <fail-regex>]
-# [SRC_EXT <ext>])
-#
-# 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-regex>``
-# Fail if test output matches this regex.
-# ``SRC_EXT <ext>``
-# Use source extension ``.<ext>`` instead of the default ``.F``.
-#
-# 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
+#[=======================================================================[.rst:
+CheckFortranSourceCompiles
+--------------------------
+
+Check if given Fortran source compiles and links into an executable.
+
+.. command:: check_fortran_source_compiles
+
+ .. code-block:: cmake
+
+ check_fortran_source_compiles(<code> <resultVar>
+ [FAIL_REGEX <regex>...]
+ [SRC_EXT <extension>]
+ )
+
+ Checks that the source supplied in ``<code>`` can be compiled as a Fortran
+ source file and linked as an executable. The ``<code>`` must be a Fortran program
+ containing at least an ``end`` statement--for example:
+
+ .. code-block:: cmake
+
+ check_fortran_source_compiles("character :: b; error stop b; end" F2018ESTOPOK SRC_EXT F90)
+
+ This command can help avoid costly build processes when a compiler lacks support
+ for a necessary feature, or a particular vendor library is not compatible with
+ the Fortran compiler version being used. This generate-time check may advise the
+ user of such before the main build process. See also the
+ :command:`check_fortran_source_runs` command to actually run the compiled code.
+
+ The result will be stored in the internal cache
+ variable ``<resultVar>``, with a boolean true value for success and boolean
+ false for failure.
+
+ If ``FAIL_REGEX`` is provided, then failure is determined by checking
+ if anything in the output matches any of the specified regular expressions.
+
+ By default, the test source file will be given a ``.F`` file extension. The
+ ``SRC_EXT`` option can be used to override this with ``.<extension>`` instead--
+ ``.F90`` is a typical choice.
+
+ The underlying check is performed by the :command:`try_compile` command. The
+ compile and link commands can be influenced by setting any of the following
+ variables prior to calling ``check_fortran_source_compiles()``:
+
+ ``CMAKE_REQUIRED_FLAGS``
+ Additional flags to pass to the compiler. Note that the contents of
+ :variable:`CMAKE_Fortran_FLAGS <CMAKE_<LANG>_FLAGS>` and its associated
+ configuration-specific variable are automatically added to the compiler
+ command before the contents of ``CMAKE_REQUIRED_FLAGS``.
+
+ ``CMAKE_REQUIRED_DEFINITIONS``
+ A :ref:`;-list <CMake Language Lists>` of compiler definitions of the form
+ ``-DFOO`` or ``-DFOO=bar``. A definition for the name specified by
+ ``<resultVar>`` will also be added automatically.
+
+ ``CMAKE_REQUIRED_INCLUDES``
+ A :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler. These will be the only header search paths used by
+ ``try_compile()``, i.e. the contents of the :prop_dir:`INCLUDE_DIRECTORIES`
+ directory property will be ignored.
+
+ ``CMAKE_REQUIRED_LINK_OPTIONS``
+ A :ref:`;-list <CMake Language Lists>` of options to add to the link
+ command (see :command:`try_compile` for further details).
+
+ ``CMAKE_REQUIRED_LIBRARIES``
+ A :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. These can be the name of system libraries or they can be
+ :ref:`Imported Targets <Imported Targets>` (see :command:`try_compile` for
+ further details).
+
+ ``CMAKE_REQUIRED_QUIET``
+ If this variable evaluates to a boolean true value, all status messages
+ associated with the check will be suppressed.
+
+ The check is only performed once, with the result cached in the variable
+ named by ``<resultVar>``. Every subsequent CMake run will re-use this cached
+ value rather than performing the check again, even if the ``<code>`` changes.
+ In order to force the check to be re-evaluated, the variable named by
+ ``<resultVar>`` must be manually removed from the cache.
+
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
if(NOT DEFINED "${VAR}")
@@ -50,6 +105,12 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
endif()
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${VAR} ${CMAKE_REQUIRED_FLAGS}")
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -72,6 +133,7 @@ macro(CHECK_Fortran_SOURCE_COMPILES SOURCE VAR)
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.${_SRC_EXT}
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_Fortran_SOURCE_COMPILES_ADD_LINK_OPTIONS}
${CHECK_Fortran_SOURCE_COMPILES_ADD_LIBRARIES}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
"${CHECK_Fortran_SOURCE_COMPILES_ADD_INCLUDES}"
diff --git a/Modules/CheckFunctionExists.c b/Modules/CheckFunctionExists.c
index 224e34041..13435e07e 100644
--- a/Modules/CheckFunctionExists.c
+++ b/Modules/CheckFunctionExists.c
@@ -1,19 +1,19 @@
#ifdef CHECK_FUNCTION_EXISTS
-#ifdef __cplusplus
+# ifdef __cplusplus
extern "C"
-#endif
+# endif
char
CHECK_FUNCTION_EXISTS(void);
-#ifdef __CLASSIC_C__
+# ifdef __CLASSIC_C__
int main()
{
int ac;
char* av[];
-#else
+# else
int main(int ac, char* av[])
{
-#endif
+# endif
CHECK_FUNCTION_EXISTS();
if (ac > 1000) {
return *av[0];
@@ -23,6 +23,6 @@ int main(int ac, char* av[])
#else /* CHECK_FUNCTION_EXISTS */
-#error "CHECK_FUNCTION_EXISTS has to specify the function"
+# error "CHECK_FUNCTION_EXISTS has to specify the function"
#endif /* CHECK_FUNCTION_EXISTS */
diff --git a/Modules/CheckFunctionExists.cmake b/Modules/CheckFunctionExists.cmake
index ef080621d..c39144fa8 100644
--- a/Modules/CheckFunctionExists.cmake
+++ b/Modules/CheckFunctionExists.cmake
@@ -1,42 +1,56 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>``. ``<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
-#
-# .. note::
-#
-# Prefer using :Module:`CheckSymbolExists` instead of this module,
-# for the following reasons:
-#
-# * ``check_function_exists()`` can't detect functions that are inlined
-# in headers or specified as a macro.
-#
-# * ``check_function_exists()`` can't detect anything in the 32-bit
-# versions of the Win32 API, because of a mismatch in calling conventions.
-#
-# * ``check_function_exists()`` only verifies linking, it does not verify
-# that the function is declared in system headers.
+#[=======================================================================[.rst:
+CheckFunctionExists
+-------------------
+
+Check if a C function can be linked
+
+.. command:: check_function_exists
+
+ .. code-block:: cmake
+
+ check_function_exists(<function> <variable>)
+
+ Checks that the ``<function>`` is provided by libraries on the system and store
+ the result in a ``<variable>``, which 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``
+ a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
+``CMAKE_REQUIRED_INCLUDES``
+ a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler.
+``CMAKE_REQUIRED_LINK_OPTIONS``
+ a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
+``CMAKE_REQUIRED_LIBRARIES``
+ a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. See policy :policy:`CMP0075`.
+``CMAKE_REQUIRED_QUIET``
+ execute quietly without messages.
+
+.. note::
+
+ Prefer using :Module:`CheckSymbolExists` instead of this module,
+ for the following reasons:
+
+ * ``check_function_exists()`` can't detect functions that are inlined
+ in headers or specified as a macro.
+
+ * ``check_function_exists()`` can't detect anything in the 32-bit
+ versions of the Win32 API, because of a mismatch in calling conventions.
+
+ * ``check_function_exists()`` only verifies linking, it does not verify
+ that the function is declared in system headers.
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
@@ -45,6 +59,12 @@ macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${FUNCTION}")
endif()
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -71,6 +91,7 @@ macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE)
${CMAKE_BINARY_DIR}
${_cfe_source}
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_FUNCTION_EXISTS_ADD_LINK_OPTIONS}
${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
"${CHECK_FUNCTION_EXISTS_ADD_INCLUDES}"
diff --git a/Modules/CheckIPOSupported.cmake b/Modules/CheckIPOSupported.cmake
index e04ab1c54..0d6ad20ae 100644
--- a/Modules/CheckIPOSupported.cmake
+++ b/Modules/CheckIPOSupported.cmake
@@ -26,7 +26,7 @@ property.
Set ``<output>`` variable with details about any error.
``LANGUAGES <lang>...``
Specify languages whose compilers to check.
- Languages ``C`` and ``CXX`` are supported.
+ Languages ``C``, ``CXX``, and ``Fortran`` are supported.
It makes no sense to use this module when :policy:`CMP0069` is set to ``OLD`` so
module will return error in this case. See policy :policy:`CMP0069` for details.
@@ -51,18 +51,17 @@ Examples
#]=======================================================================]
-include(CMakeParseArguments) # cmake_parse_arguments
-
# X_RESULT - name of the final result variable
# X_OUTPUT - name of the variable with information about error
macro(_ipo_not_supported output)
- string(COMPARE EQUAL "${X_RESULT}" "" is_empty)
- if(is_empty)
+ if(NOT X_RESULT)
message(FATAL_ERROR "IPO is not supported (${output}).")
endif()
set("${X_RESULT}" NO PARENT_SCOPE)
- set("${X_OUTPUT}" "${output}" PARENT_SCOPE)
+ if(X_OUTPUT)
+ set("${X_OUTPUT}" "${output}" PARENT_SCOPE)
+ endif()
endmacro()
# Run IPO/LTO test
@@ -125,7 +124,13 @@ macro(_ipo_run_language_check language)
)
if(NOT result)
- _ipo_not_supported("${output}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "${language} compiler IPO check failed with the following output:\n"
+ "${output}\n")
+ _ipo_not_supported("check failed to compile")
+ if(X_OUTPUT)
+ set("${X_OUTPUT}" "${output}" PARENT_SCOPE)
+ endif()
return()
endif()
endmacro()
@@ -219,7 +224,7 @@ function(check_ipo_supported)
endif()
endforeach()
- if(CMAKE_GENERATOR MATCHES "^Visual Studio ")
+ if(CMAKE_GENERATOR MATCHES "^Visual Studio 9 ")
_ipo_not_supported("CMake doesn't support IPO for current generator")
return()
endif()
diff --git a/Modules/CheckIncludeFile.cmake b/Modules/CheckIncludeFile.cmake
index c566e1448..d7b9481da 100644
--- a/Modules/CheckIncludeFile.cmake
+++ b/Modules/CheckIncludeFile.cmake
@@ -1,38 +1,47 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CheckIncludeFile
-# ----------------
-#
-# Provides a macro to check if a header file can be included in ``C``.
-#
-# .. command:: CHECK_INCLUDE_FILE
-#
-# ::
-#
-# CHECK_INCLUDE_FILE(<include> <variable> [<flags>])
-#
-# Check if the given ``<include>`` file may be included in a ``C``
-# source file and store the result in an internal cache entry named
-# ``<variable>``. The optional third argument may be used to add
-# compilation flags to the check (or use ``CMAKE_REQUIRED_FLAGS`` below).
-#
-# 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
-#
-# See the :module:`CheckIncludeFiles` module to check for multiple headers
-# at once. See the :module:`CheckIncludeFileCXX` module to check for headers
-# using the ``CXX`` language.
+#[=======================================================================[.rst:
+CheckIncludeFile
+----------------
+
+Provides a macro to check if a header file can be included in ``C``.
+
+.. command:: CHECK_INCLUDE_FILE
+
+ .. code-block:: cmake
+
+ CHECK_INCLUDE_FILE(<include> <variable> [<flags>])
+
+ Check if the given ``<include>`` file may be included in a ``C``
+ source file and store the result in an internal cache entry named
+ ``<variable>``. The optional third argument may be used to add
+ compilation flags to the check (or use ``CMAKE_REQUIRED_FLAGS`` below).
+
+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``
+ a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
+``CMAKE_REQUIRED_INCLUDES``
+ a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler.
+``CMAKE_REQUIRED_LINK_OPTIONS``
+ a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
+``CMAKE_REQUIRED_LIBRARIES``
+ a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. See policy :policy:`CMP0075`.
+``CMAKE_REQUIRED_QUIET``
+ execute quietly without messages.
+
+See the :module:`CheckIncludeFiles` module to check for multiple headers
+at once. See the :module:`CheckIncludeFileCXX` module to check for headers
+using the ``CXX`` language.
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
if(NOT DEFINED "${VARIABLE}")
@@ -53,14 +62,46 @@ macro(CHECK_INCLUDE_FILE INCLUDE VARIABLE)
string(APPEND CMAKE_C_FLAGS " ${ARGV2}")
endif()
+ set(_CIF_LINK_OPTIONS)
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(_CIF_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ endif()
+
+ set(_CIF_LINK_LIBRARIES "")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ cmake_policy(GET CMP0075 _CIF_CMP0075
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ if("x${_CIF_CMP0075}x" STREQUAL "xNEWx")
+ set(_CIF_LINK_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ elseif("x${_CIF_CMP0075}x" STREQUAL "xOLDx")
+ elseif(NOT _CIF_CMP0075_WARNED)
+ set(_CIF_CMP0075_WARNED 1)
+ message(AUTHOR_WARNING
+ "Policy CMP0075 is not set: Include file check macros honor CMAKE_REQUIRED_LIBRARIES. "
+ "Run \"cmake --help-policy CMP0075\" for policy details. "
+ "Use the cmake_policy command to set the policy and suppress this warning."
+ "\n"
+ "CMAKE_REQUIRED_LIBRARIES is set to:\n"
+ " ${CMAKE_REQUIRED_LIBRARIES}\n"
+ "For compatibility with CMake 3.11 and below this check is ignoring it."
+ )
+ endif()
+ unset(_CIF_CMP0075)
+ endif()
+
try_compile(${VARIABLE}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${_CIF_LINK_OPTIONS}
+ ${_CIF_LINK_LIBRARIES}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
"${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}"
OUTPUT_VARIABLE OUTPUT)
+ unset(_CIF_LINK_OPTIONS)
+ unset(_CIF_LINK_LIBRARIES)
if(${ARGC} EQUAL 3)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE})
diff --git a/Modules/CheckIncludeFileCXX.cmake b/Modules/CheckIncludeFileCXX.cmake
index 19b1ef6f8..de5a83b35 100644
--- a/Modules/CheckIncludeFileCXX.cmake
+++ b/Modules/CheckIncludeFileCXX.cmake
@@ -1,37 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CheckIncludeFileCXX
-# -------------------
-#
-# Provides a macro to check if a header file can be included in ``CXX``.
-#
-# .. command:: CHECK_INCLUDE_FILE_CXX
-#
-# ::
-#
-# CHECK_INCLUDE_FILE_CXX(<include> <variable> [<flags>])
-#
-# Check if the given ``<include>`` file may be included in a ``CXX``
-# source file and store the result in an internal cache entry named
-# ``<variable>``. The optional third argument may be used to add
-# compilation flags to the check (or use ``CMAKE_REQUIRED_FLAGS`` below).
-#
-# 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
-#
-# See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFiles`
-# to check for one or more ``C`` headers.
+#[=======================================================================[.rst:
+CheckIncludeFileCXX
+-------------------
+
+Provides a macro to check if a header file can be included in ``CXX``.
+
+.. command:: CHECK_INCLUDE_FILE_CXX
+
+ .. code-block:: cmake
+
+ CHECK_INCLUDE_FILE_CXX(<include> <variable> [<flags>])
+
+ Check if the given ``<include>`` file may be included in a ``CXX``
+ source file and store the result in an internal cache entry named
+ ``<variable>``. The optional third argument may be used to add
+ compilation flags to the check (or use ``CMAKE_REQUIRED_FLAGS`` below).
+
+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``
+ a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
+``CMAKE_REQUIRED_INCLUDES``
+ a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler.
+``CMAKE_REQUIRED_LINK_OPTIONS``
+ a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
+``CMAKE_REQUIRED_LIBRARIES``
+ a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. See policy :policy:`CMP0075`.
+``CMAKE_REQUIRED_QUIET``
+ execute quietly without messages.
+
+See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFiles`
+to check for one or more ``C`` headers.
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
if(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
@@ -52,14 +61,46 @@ macro(CHECK_INCLUDE_FILE_CXX INCLUDE VARIABLE)
string(APPEND CMAKE_CXX_FLAGS " ${ARGV2}")
endif()
+ set(_CIF_LINK_OPTIONS)
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(_CIF_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ endif()
+
+ set(_CIF_LINK_LIBRARIES "")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ cmake_policy(GET CMP0075 _CIF_CMP0075
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ if("x${_CIF_CMP0075}x" STREQUAL "xNEWx")
+ set(_CIF_LINK_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ elseif("x${_CIF_CMP0075}x" STREQUAL "xOLDx")
+ elseif(NOT _CIF_CMP0075_WARNED)
+ set(_CIF_CMP0075_WARNED 1)
+ message(AUTHOR_WARNING
+ "Policy CMP0075 is not set: Include file check macros honor CMAKE_REQUIRED_LIBRARIES. "
+ "Run \"cmake --help-policy CMP0075\" for policy details. "
+ "Use the cmake_policy command to set the policy and suppress this warning."
+ "\n"
+ "CMAKE_REQUIRED_LIBRARIES is set to:\n"
+ " ${CMAKE_REQUIRED_LIBRARIES}\n"
+ "For compatibility with CMake 3.11 and below this check is ignoring it."
+ )
+ endif()
+ unset(_CIF_CMP0075)
+ endif()
+
try_compile(${VARIABLE}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${_CIF_LINK_OPTIONS}
+ ${_CIF_LINK_LIBRARIES}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
"${CHECK_INCLUDE_FILE_CXX_INCLUDE_DIRS}"
OUTPUT_VARIABLE OUTPUT)
+ unset(_CIF_LINK_OPTIONS)
+ unset(_CIF_LINK_LIBRARIES)
if(${ARGC} EQUAL 3)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_SAVE})
diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake
index bef11a5e9..f52ab55fb 100644
--- a/Modules/CheckIncludeFiles.cmake
+++ b/Modules/CheckIncludeFiles.cmake
@@ -1,42 +1,81 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# CheckIncludeFiles
-# -----------------
-#
-# Provides a macro to check if a list of one or more header files can
-# be included together in ``C``.
-#
-# .. command:: CHECK_INCLUDE_FILES
-#
-# ::
-#
-# CHECK_INCLUDE_FILES("<includes>" <variable>)
-#
-# Check if the given ``<includes>`` list may be included together
-# in a ``C`` source file and store the result in an internal cache
-# entry named ``<variable>``. Specify the ``<includes>`` argument
-# as a :ref:`;-list <CMake Language Lists>` of header file names.
-#
-# 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
-#
-# See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFileCXX`
-# to check for a single header file in ``C`` or ``CXX`` languages.
+#[=======================================================================[.rst:
+CheckIncludeFiles
+-----------------
+
+Provides a macro to check if a list of one or more header files can
+be included together.
+
+.. command:: CHECK_INCLUDE_FILES
+
+ .. code-block:: cmake
+
+ CHECK_INCLUDE_FILES("<includes>" <variable> [LANGUAGE <language>])
+
+ Check if the given ``<includes>`` list may be included together
+ in a source file and store the result in an internal cache
+ entry named ``<variable>``. Specify the ``<includes>`` argument
+ as a :ref:`;-list <CMake Language Lists>` of header file names.
+
+ If ``LANGUAGE`` is set, the specified compiler will be used to perform the
+ check. Acceptable values are ``C`` and ``CXX``. If not set, the C compiler
+ will be used if enabled. If the C compiler is not enabled, the C++
+ compiler will be used if enabled.
+
+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``
+ a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
+``CMAKE_REQUIRED_INCLUDES``
+ a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler.
+``CMAKE_REQUIRED_LINK_OPTIONS``
+ a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
+``CMAKE_REQUIRED_LIBRARIES``
+ a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. See policy :policy:`CMP0075`.
+``CMAKE_REQUIRED_QUIET``
+ execute quietly without messages.
+
+See modules :module:`CheckIncludeFile` and :module:`CheckIncludeFileCXX`
+to check for a single header file in ``C`` or ``CXX`` languages.
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
if(NOT DEFINED "${VARIABLE}")
set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
+
+ if("x${ARGN}" STREQUAL "x")
+ if(CMAKE_C_COMPILER_LOADED)
+ set(_lang C)
+ elseif(CMAKE_CXX_COMPILER_LOADED)
+ set(_lang CXX)
+ else()
+ message(FATAL_ERROR "CHECK_INCLUDE_FILES needs either C or CXX language enabled.\n")
+ endif()
+ elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$")
+ set(_lang "${CMAKE_MATCH_1}")
+ elseif("x${ARGN}" MATCHES "^xLANGUAGE$")
+ message(FATAL_ERROR "No languages listed for LANGUAGE option.\nSupported languages: C, CXX.\n")
+ else()
+ message(FATAL_ERROR "Unknown arguments:\n ${ARGN}\n")
+ endif()
+
+ if(_lang STREQUAL "C")
+ set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${VARIABLE}.c)
+ elseif(_lang STREQUAL "CXX")
+ set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${VARIABLE}.cpp)
+ else()
+ message(FATAL_ERROR "Unknown language:\n ${_lang}\nSupported languages: C, CXX.\n")
+ endif()
+
if(CMAKE_REQUIRED_INCLUDES)
set(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
else()
@@ -51,7 +90,7 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
string(APPEND 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)
+ "${src}" @ONLY)
set(_INCLUDE ${INCLUDE}) # remove empty elements
if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$")
@@ -63,17 +102,49 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE)
set(_description "include file ${_INCLUDE}")
endif()
+ set(_CIF_LINK_OPTIONS)
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(_CIF_LINK_OPTIONS LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ endif()
+
+ set(_CIF_LINK_LIBRARIES "")
+ if(CMAKE_REQUIRED_LIBRARIES)
+ cmake_policy(GET CMP0075 _CIF_CMP0075
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ if("x${_CIF_CMP0075}x" STREQUAL "xNEWx")
+ set(_CIF_LINK_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ elseif("x${_CIF_CMP0075}x" STREQUAL "xOLDx")
+ elseif(NOT _CIF_CMP0075_WARNED)
+ set(_CIF_CMP0075_WARNED 1)
+ message(AUTHOR_WARNING
+ "Policy CMP0075 is not set: Include file check macros honor CMAKE_REQUIRED_LIBRARIES. "
+ "Run \"cmake --help-policy CMP0075\" for policy details. "
+ "Use the cmake_policy command to set the policy and suppress this warning."
+ "\n"
+ "CMAKE_REQUIRED_LIBRARIES is set to:\n"
+ " ${CMAKE_REQUIRED_LIBRARIES}\n"
+ "For compatibility with CMake 3.11 and below this check is ignoring it."
+ )
+ endif()
+ unset(_CIF_CMP0075)
+ 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
+ ${src}
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${_CIF_LINK_OPTIONS}
+ ${_CIF_LINK_LIBRARIES}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS}
"${CHECK_INCLUDE_FILES_INCLUDE_DIRS}"
OUTPUT_VARIABLE OUTPUT)
+ unset(_CIF_LINK_OPTIONS)
+ unset(_CIF_LINK_LIBRARIES)
if(${VARIABLE})
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${_description} - found")
diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake
index 1ea91d2d0..a1a3a7aac 100644
--- a/Modules/CheckLanguage.cmake
+++ b/Modules/CheckLanguage.cmake
@@ -1,53 +1,74 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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()
+#[=======================================================================[.rst:
+CheckLanguage
+-------------
+
+Check if a language can be enabled
+
+Usage:
+
+::
+
+ check_language(<lang>)
+
+where ``<lang>`` is a language that may be passed to :command:`enable_language`
+such as ``Fortran``. If :variable:`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 :variable:`CMAKE_<LANG>_COMPILER`
+as the compiler that was found, or ``NOTFOUND`` if the language cannot be
+enabled. For CUDA which can have an explicit host compiler, the cache
+:variable:`CMAKE_CUDA_HOST_COMPILER` variable will be set if it was required
+for compilation.
+
+Example:
+
+::
+
+ check_language(Fortran)
+ if(CMAKE_Fortran_COMPILER)
+ enable_language(Fortran)
+ else()
+ message(STATUS "No Fortran support")
+ endif()
+#]=======================================================================]
+
+include_guard(GLOBAL)
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"
+
+ set(extra_compiler_variables)
+ if(lang STREQUAL CUDA)
+ set(extra_compiler_variables "set(CMAKE_CUDA_HOST_COMPILER \\\"\${CMAKE_CUDA_HOST_COMPILER}\\\")")
+ endif()
+
+ set(content
"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\"
- )
-")
+ \"${extra_compiler_variables}\\n\"
+ )"
+ )
+
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt"
+ "${content}")
+ if(CMAKE_GENERATOR_INSTANCE)
+ set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
+ else()
+ set(_D_CMAKE_GENERATOR_INSTANCE "")
+ endif()
execute_process(
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}
COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
-A "${CMAKE_GENERATOR_PLATFORM}"
-T "${CMAKE_GENERATOR_TOOLSET}"
+ ${_D_CMAKE_GENERATOR_INSTANCE}
OUTPUT_VARIABLE output
ERROR_VARIABLE output
RESULT_VARIABLE result
@@ -66,5 +87,12 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
message(STATUS "${_desc} - ${CMAKE_${lang}_COMPILER}")
set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler")
mark_as_advanced(CMAKE_${lang}_COMPILER)
+
+ if(CMAKE_${lang}_HOST_COMPILER)
+ message(STATUS "Looking for a ${lang} host compiler - ${CMAKE_${lang}_HOST_COMPILER}")
+ set(CMAKE_${lang}_HOST_COMPILER "${CMAKE_${lang}_HOST_COMPILER}" CACHE FILEPATH "${lang} host compiler")
+ mark_as_advanced(CMAKE_${lang}_HOST_COMPILER)
+ endif()
+
endif()
endmacro()
diff --git a/Modules/CheckLibraryExists.cmake b/Modules/CheckLibraryExists.cmake
index 528a45085..6504df5d7 100644
--- a/Modules/CheckLibraryExists.cmake
+++ b/Modules/CheckLibraryExists.cmake
@@ -1,33 +1,41 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckLibraryExists
+------------------
+
+Check if the function exists.
+
+.. command:: CHECK_LIBRARY_EXISTS
+
+ .. code-block:: cmake
+
+ 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_LINK_OPTIONS = list of options to pass to link command
+ CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+ CMAKE_REQUIRED_QUIET = execute quietly without messages
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
if(NOT DEFINED "${VARIABLE}")
@@ -36,6 +44,11 @@ macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}")
endif()
+ set(CHECK_LIBRARY_EXISTS_LINK_OPTIONS)
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_LIBRARY_EXISTS_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ endif()
set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY})
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_LIBRARY_EXISTS_LIBRARIES
@@ -55,6 +68,7 @@ macro(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE)
${CMAKE_BINARY_DIR}
${_cle_source}
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_LIBRARY_EXISTS_LINK_OPTIONS}
LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION}
diff --git a/Modules/CheckPrototypeDefinition.cmake b/Modules/CheckPrototypeDefinition.cmake
index 785959496..a7b020c06 100644
--- a/Modules/CheckPrototypeDefinition.cmake
+++ b/Modules/CheckPrototypeDefinition.cmake
@@ -1,56 +1,68 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckPrototypeDefinition
+------------------------
-#
+Check if the prototype we expect is correct.
+
+.. command:: check_prototype_definition
+
+ .. code-block:: cmake
+ 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:
+
+ .. code-block:: cmake
+
+ 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 function 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_LINK_OPTIONS = list of options to pass to link command
+ CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+ CMAKE_REQUIRED_QUIET = execute quietly without messages
+#]=======================================================================]
+
+#
get_filename_component(__check_proto_def_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+include_guard(GLOBAL)
-function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE)
+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_LINK_OPTIONS)
+ set(CHECK_PROTOTYPE_DEFINITION_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_PROTOTYPE_DEFINITION_LINK_OPTIONS)
+ endif()
if (CMAKE_REQUIRED_LIBRARIES)
set(CHECK_PROTOTYPE_DEFINITION_LIBS
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -82,6 +94,7 @@ function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIAB
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_PROTOTYPE_DEFINITION_LINK_OPTIONS}
${CHECK_PROTOTYPE_DEFINITION_LIBS}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS}
"${CMAKE_SYMBOL_EXISTS_INCLUDES}"
diff --git a/Modules/CheckStructHasMember.cmake b/Modules/CheckStructHasMember.cmake
index 085b46492..842a8fdb7 100644
--- a/Modules/CheckStructHasMember.cmake
+++ b/Modules/CheckStructHasMember.cmake
@@ -1,74 +1,82 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.rst:
+CheckStructHasMember
+--------------------
+Check if the given struct or class has the specified member variable
+
+.. command:: CHECK_STRUCT_HAS_MEMBER
+
+ .. code-block:: cmake
+
+ 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_LINK_OPTIONS = list of options to pass to link command
+ CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+ CMAKE_REQUIRED_QUIET = execute quietly without messages
+
+
+Example:
+
+.. code-block:: cmake
+
+ CHECK_STRUCT_HAS_MEMBER("struct timeval" tv_sec sys/select.h
+ HAVE_TIMEVAL_TV_SEC LANGUAGE C)
+#]=======================================================================]
+
+include_guard(GLOBAL)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
macro (CHECK_STRUCT_HAS_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
- set(_INCLUDE_FILES)
- foreach (it ${_HEADER})
- string(APPEND _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 "
+ set(_INCLUDE_FILES)
+ foreach (it ${_HEADER})
+ string(APPEND _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()
{
- (void)sizeof(((${_STRUCT} *)0)->${_MEMBER});
- return 0;
+ (void)sizeof(((${_STRUCT} *)0)->${_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()
+ 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
index 6f1afcfda..b9ef8088f 100644
--- a/Modules/CheckSymbolExists.cmake
+++ b/Modules/CheckSymbolExists.cmake
@@ -10,7 +10,7 @@ or macro in ``C``.
.. command:: check_symbol_exists
- ::
+ .. code-block:: cmake
check_symbol_exists(<symbol> <files> <variable>)
@@ -32,31 +32,46 @@ 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
+ string of compile command line flags.
``CMAKE_REQUIRED_DEFINITIONS``
- list of macros to define (-DFOO=bar)
+ a :ref:`;-list <CMake Language Lists>` of macros to define (-DFOO=bar).
``CMAKE_REQUIRED_INCLUDES``
- list of include directories
+ a :ref:`;-list <CMake Language Lists>` of header search paths to pass to
+ the compiler.
+``CMAKE_REQUIRED_LINK_OPTIONS``
+ a :ref:`;-list <CMake Language Lists>` of options to add to the link command.
``CMAKE_REQUIRED_LIBRARIES``
- list of libraries to link
+ a :ref:`;-list <CMake Language Lists>` of libraries to add to the link
+ command. See policy :policy:`CMP0075`.
``CMAKE_REQUIRED_QUIET``
- execute quietly without messages
+ execute quietly without messages.
#]=======================================================================]
+include_guard(GLOBAL)
+
+cmake_policy(PUSH)
+cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
+
macro(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE)
if(CMAKE_C_COMPILER_LOADED)
- _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
+ __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
elseif(CMAKE_CXX_COMPILER_LOADED)
- _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
+ __CHECK_SYMBOL_EXISTS_IMPL("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.cxx" "${SYMBOL}" "${FILES}" "${VARIABLE}" )
else()
message(FATAL_ERROR "CHECK_SYMBOL_EXISTS needs either C or CXX language enabled")
endif()
endmacro()
-macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
+macro(__CHECK_SYMBOL_EXISTS_IMPL 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_LINK_OPTIONS)
+ set(CHECK_SYMBOL_EXISTS_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_SYMBOL_EXISTS_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_SYMBOL_EXISTS_LIBS
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -86,6 +101,7 @@ macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
${CMAKE_BINARY_DIR}
"${SOURCEFILE}"
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_SYMBOL_EXISTS_LINK_OPTIONS}
${CHECK_SYMBOL_EXISTS_LIBS}
CMAKE_FLAGS
-DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_SYMBOL_EXISTS_FLAGS}
@@ -114,3 +130,5 @@ macro(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE)
endif()
endif()
endmacro()
+
+cmake_policy(POP)
diff --git a/Modules/CheckTypeSize.c.in b/Modules/CheckTypeSize.c.in
index b6c368801..82035a336 100644
--- a/Modules/CheckTypeSize.c.in
+++ b/Modules/CheckTypeSize.c.in
@@ -9,10 +9,16 @@
# define KEY '_','_','p','p','c','_','_'
#elif defined(__ppc64__)
# define KEY '_','_','p','p','c','6','4','_','_'
+#elif defined(__aarch64__)
+# define KEY '_','_','a','a','r','c','h','6','4','_','_'
+#elif defined(__ARM_ARCH_7A__)
+# define KEY '_','_','A','R','M','_','A','R','C','H','_','7','A','_','_'
+#elif defined(__ARM_ARCH_7S__)
+# define KEY '_','_','A','R','M','_','A','R','C','H','_','7','S','_','_'
#endif
#define SIZE (sizeof(@type@))
-char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
+static char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[',
('0' + ((SIZE / 10000)%10)),
('0' + ((SIZE / 1000)%10)),
('0' + ((SIZE / 100)%10)),
diff --git a/Modules/CheckTypeSize.cmake b/Modules/CheckTypeSize.cmake
index fcf1df740..372737307 100644
--- a/Modules/CheckTypeSize.cmake
+++ b/Modules/CheckTypeSize.cmake
@@ -1,81 +1,87 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckTypeSize
+-------------
+
+Check sizeof a type
+
+.. command:: CHECK_TYPE_SIZE
+
+ .. code-block:: cmake
+
+ 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
+ :variable:`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:
+
+.. code-block:: cmake
+
+ 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_LINK_OPTIONS = list of options to pass to link command
+ 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
+#]=======================================================================]
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
+get_filename_component(__check_type_size_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
+
+include_guard(GLOBAL)
+
cmake_policy(PUSH)
cmake_policy(SET CMP0054 NEW)
-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)
@@ -113,6 +119,7 @@ function(__check_type_size_impl type var map builtin language)
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_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS}
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
CMAKE_FLAGS
"-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}"
diff --git a/Modules/CheckVariableExists.c b/Modules/CheckVariableExists.c
index 6e948771b..d68afb46a 100644
--- a/Modules/CheckVariableExists.c
+++ b/Modules/CheckVariableExists.c
@@ -2,15 +2,15 @@
extern int CHECK_VARIABLE_EXISTS;
-#ifdef __CLASSIC_C__
+# ifdef __CLASSIC_C__
int main()
{
int ac;
char* av[];
-#else
+# else
int main(int ac, char* av[])
{
-#endif
+# endif
if (ac > 1000) {
return *av[0];
}
@@ -19,6 +19,6 @@ int main(int ac, char* av[])
#else /* CHECK_VARIABLE_EXISTS */
-#error "CHECK_VARIABLE_EXISTS has to specify the variable"
+# error "CHECK_VARIABLE_EXISTS has to specify the variable"
#endif /* CHECK_VARIABLE_EXISTS */
diff --git a/Modules/CheckVariableExists.cmake b/Modules/CheckVariableExists.cmake
index fd5c36c6a..f4953a349 100644
--- a/Modules/CheckVariableExists.cmake
+++ b/Modules/CheckVariableExists.cmake
@@ -1,36 +1,41 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+CheckVariableExists
+-------------------
+
+Check if the variable exists.
+
+.. command:: CHECK_VARIABLE_EXISTS
+
+ .. code-block:: cmake
+
+ 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_LINK_OPTIONS = list of options to pass to link command
+ CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+ CMAKE_REQUIRED_QUIET = execute quietly without messages
+#]=======================================================================]
+
+include_guard(GLOBAL)
macro(CHECK_VARIABLE_EXISTS VAR VARIABLE)
if(NOT DEFINED "${VARIABLE}")
@@ -39,6 +44,12 @@ macro(CHECK_VARIABLE_EXISTS VAR VARIABLE)
if(NOT CMAKE_REQUIRED_QUIET)
message(STATUS "Looking for ${VAR}")
endif()
+ if(CMAKE_REQUIRED_LINK_OPTIONS)
+ set(CHECK_VARIABLE_EXISTS_ADD_LINK_OPTIONS
+ LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})
+ else()
+ set(CHECK_VARIABLE_EXISTS_ADD_LINK_OPTIONS)
+ endif()
if(CMAKE_REQUIRED_LIBRARIES)
set(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES
LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
@@ -49,6 +60,7 @@ macro(CHECK_VARIABLE_EXISTS VAR VARIABLE)
${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/CheckVariableExists.c
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+ ${CHECK_VARIABLE_EXISTS_ADD_LINK_OPTIONS}
${CHECK_VARIABLE_EXISTS_ADD_LIBRARIES}
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_VARIABLE_DEFINITIONS}
OUTPUT_VARIABLE OUTPUT)
diff --git a/Modules/Compiler/ARMCC-ASM.cmake b/Modules/Compiler/ARMCC-ASM.cmake
index 539d5259f..5819fc756 100644
--- a/Modules/Compiler/ARMCC-ASM.cmake
+++ b/Modules/Compiler/ARMCC-ASM.cmake
@@ -4,4 +4,4 @@ set(CMAKE_ASM_OUTPUT_EXTENSION ".o")
set(CMAKE_ASM_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")
-set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
+set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS S;s;asm;msa)
diff --git a/Modules/Compiler/ARMCC-DetermineCompiler.cmake b/Modules/Compiler/ARMCC-DetermineCompiler.cmake
index a3667d7c2..5f2d0f846 100644
--- a/Modules/Compiler/ARMCC-DetermineCompiler.cmake
+++ b/Modules/Compiler/ARMCC-DetermineCompiler.cmake
@@ -1,5 +1,5 @@
# ARMCC Toolchain
-set(_compiler_id_pp_test "defined(__ARMCC_VERSION)")
+set(_compiler_id_pp_test "defined(__ARMCC_VERSION) && !defined(__clang__)")
set(_compiler_id_version_compute "
#if __ARMCC_VERSION >= 1000000
diff --git a/Modules/Compiler/ARMCC.cmake b/Modules/Compiler/ARMCC.cmake
index 250a8f481..f94956821 100644
--- a/Modules/Compiler/ARMCC.cmake
+++ b/Modules/Compiler/ARMCC.cmake
@@ -34,4 +34,6 @@ macro(__compiler_armcc lang)
set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_AR> --create -cr <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_DEPFILE_FLAGS_${lang} "--depend=<DEPFILE> --depend_single_line --no_depend_system_headers")
+
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ")
endmacro()
diff --git a/Modules/Compiler/Absoft-Fortran.cmake b/Modules/Compiler/Absoft-Fortran.cmake
index da1fc80d4..76502dca7 100644
--- a/Modules/Compiler/Absoft-Fortran.cmake
+++ b/Modules/Compiler/Absoft-Fortran.cmake
@@ -8,3 +8,4 @@ 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")
+set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-X")
diff --git a/Modules/Compiler/AppleClang-C.cmake b/Modules/Compiler/AppleClang-C.cmake
index a48adec92..2794f52bb 100644
--- a/Modules/Compiler/AppleClang-C.cmake
+++ b/Modules/Compiler/AppleClang-C.cmake
@@ -4,12 +4,15 @@ __compiler_clang(C)
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0)
set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90")
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90")
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
endif()
__compiler_check_default_language_standard(C 4.0 99)
diff --git a/Modules/Compiler/AppleClang-CXX.cmake b/Modules/Compiler/AppleClang-CXX.cmake
index e5fd64721..3fa69904a 100644
--- a/Modules/Compiler/AppleClang-CXX.cmake
+++ b/Modules/Compiler/AppleClang-CXX.cmake
@@ -8,6 +8,7 @@ endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
@@ -16,10 +17,12 @@ endif()
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.1)
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14")
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
# AppleClang 5.0 knows this flag, but does not set a __cplusplus macro greater than 201103L
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y")
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y")
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.1)
@@ -27,4 +30,13 @@ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.1)
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z")
endif()
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
+endif()
+
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
+ set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a")
+ set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a")
+endif()
+
__compiler_check_default_language_standard(CXX 4.0 98)
diff --git a/Modules/Compiler/Bruce-C.cmake b/Modules/Compiler/Bruce-C.cmake
index cfabe6523..6b64e5806 100644
--- a/Modules/Compiler/Bruce-C.cmake
+++ b/Modules/Compiler/Bruce-C.cmake
@@ -5,3 +5,5 @@ string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -g")
string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -g -DNDEBUG")
+
+set(CMAKE_C_LINKER_WRAPPER_FLAG "-X")
diff --git a/Modules/Compiler/CMakeCommonCompilerMacros.cmake b/Modules/Compiler/CMakeCommonCompilerMacros.cmake
index 684fd30cb..96537f8dd 100644
--- a/Modules/Compiler/CMakeCommonCompilerMacros.cmake
+++ b/Modules/Compiler/CMakeCommonCompilerMacros.cmake
@@ -65,29 +65,72 @@ endmacro()
macro(cmake_record_c_compile_features)
set(_result 0)
if(_result EQUAL 0 AND DEFINED CMAKE_C11_STANDARD_COMPILE_OPTION)
- _record_compiler_features_c(11)
+ if(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_c(11)
+ else()
+ _record_compiler_features_c(11)
+ endif()
+ unset(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_C99_STANDARD_COMPILE_OPTION)
- _record_compiler_features_c(99)
+ if(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_c(99)
+ else()
+ _record_compiler_features_c(99)
+ endif()
+ unset(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_C90_STANDARD_COMPILE_OPTION)
- _record_compiler_features_c(90)
+ if(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_c(90)
+ else()
+ _record_compiler_features_c(90)
+ endif()
+ unset(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT)
endif()
endmacro()
# Define to allow compile features to be automatically determined
macro(cmake_record_cxx_compile_features)
set(_result 0)
+ if(_result EQUAL 0 AND DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION)
+ if(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_cxx(20)
+ else()
+ _record_compiler_features_cxx(20)
+ endif()
+ unset(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT)
+ endif()
if(_result EQUAL 0 AND DEFINED CMAKE_CXX17_STANDARD_COMPILE_OPTION)
- _record_compiler_features_cxx(17)
+ if(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_cxx(17)
+ else()
+ _record_compiler_features_cxx(17)
+ endif()
+ unset(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_CXX14_STANDARD_COMPILE_OPTION)
- _record_compiler_features_cxx(14)
+ if(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_cxx(14)
+ else()
+ _record_compiler_features_cxx(14)
+ endif()
+ unset(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_CXX11_STANDARD_COMPILE_OPTION)
- _record_compiler_features_cxx(11)
+ if(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_cxx(11)
+ else()
+ _record_compiler_features_cxx(11)
+ endif()
+ unset(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT)
endif()
if(_result EQUAL 0 AND DEFINED CMAKE_CXX98_STANDARD_COMPILE_OPTION)
- _record_compiler_features_cxx(98)
+ if(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT)
+ _has_compiler_features_cxx(98)
+ else()
+ _record_compiler_features_cxx(98)
+ endif()
+ unset(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT)
endif()
endmacro()
diff --git a/Modules/Compiler/Clang-C.cmake b/Modules/Compiler/Clang-C.cmake
index b881e2b03..0448965ee 100644
--- a/Modules/Compiler/Clang-C.cmake
+++ b/Modules/Compiler/Clang-C.cmake
@@ -2,19 +2,41 @@ include(Compiler/Clang)
__compiler_clang(C)
cmake_policy(GET CMP0025 appleClangPolicy)
-if(WIN32 OR (APPLE AND NOT appleClangPolicy STREQUAL NEW))
+if(APPLE AND NOT appleClangPolicy STREQUAL NEW)
return()
endif()
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
- set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90")
- set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90")
+ if(NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
+ set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c90")
+ set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu90")
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
- set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
- set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
+ set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
+ set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
- set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
- set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
+ set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
+ set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
+ else()
+ # clang-cl doesn't have any of these
+ set(CMAKE_C90_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_C90_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
+
+ set(CMAKE_C99_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_C99_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
+
+ set(CMAKE_C11_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_C11_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
+ endif()
endif()
-__compiler_check_default_language_standard(C 3.4 99 3.6 11)
+if(NOT "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
+ __compiler_check_default_language_standard(C 3.4 99 3.6 11)
+else()
+ set(CMAKE_C_STANDARD_DEFAULT "")
+endif()
diff --git a/Modules/Compiler/Clang-CXX.cmake b/Modules/Compiler/Clang-CXX.cmake
index d3707eed8..61709f828 100644
--- a/Modules/Compiler/Clang-CXX.cmake
+++ b/Modules/Compiler/Clang-CXX.cmake
@@ -1,7 +1,7 @@
include(Compiler/Clang)
__compiler_clang(CXX)
-if(NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
set(CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN "-fvisibility-inlines-hidden")
endif()
@@ -10,30 +10,121 @@ if(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("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
+ 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.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()
+ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.1)
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
+ 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_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z")
- set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z")
-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")
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
+ 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")
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
+ endif()
+
+ set(_clang_version_std17 5.0)
+ if(CMAKE_SYSTEM_NAME STREQUAL "Android")
+ set(_clang_version_std17 6.0)
+ endif()
+
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}")
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17")
+ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z")
+ endif()
+
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${_clang_version_std17}")
+ set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a")
+ set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a")
+ endif()
-__compiler_check_default_language_standard(CXX 2.1 98)
+ unset(_clang_version_std17)
+
+ if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ # The MSVC standard library requires C++14, and MSVC itself has no
+ # notion of operating in a mode not aware of at least that standard.
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++14")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++14")
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++14")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++14")
+
+ # This clang++ is missing some features because of MSVC compatibility.
+ unset(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT)
+ unset(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT)
+ unset(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT)
+ unset(CMAKE_CXX20_STANDARD__HAS_FULL_SUPPORT)
+ endif()
+
+ __compiler_check_default_language_standard(CXX 2.1 98)
+elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 3.9
+ AND CMAKE_CXX_SIMULATE_VERSION VERSION_GREATER_EQUAL 19.0)
+ # This version of clang-cl and the MSVC version it simulates have
+ # support for -std: flags.
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std:c++14")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std:c++14")
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++17")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++17")
+ set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std:c++latest")
+ set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std:c++latest")
+ else()
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++latest")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++latest")
+ endif()
+
+ __compiler_check_default_language_standard(CXX 3.9 14)
+else()
+ # This version of clang-cl, or the MSVC version it simulates, does not have
+ # language standards. Set these options as empty strings so the feature
+ # test infrastructure can at least check to see if they are defined.
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "")
+
+ # There is no meaningful default for this
+ set(CMAKE_CXX_STANDARD_DEFAULT "")
+
+ # There are no compiler modes so we only need to test features once.
+ # Override the default macro for this special case. Pretend that
+ # all language standards are available so that at least compilation
+ # can be attempted.
+ macro(cmake_record_cxx_compile_features)
+ list(APPEND CMAKE_CXX_COMPILE_FEATURES
+ cxx_std_98
+ cxx_std_11
+ cxx_std_14
+ cxx_std_17
+ cxx_std_20
+ )
+ _record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES)
+ endmacro()
+endif()
diff --git a/Modules/Compiler/Clang.cmake b/Modules/Compiler/Clang.cmake
index 7d476f965..c3f13f3a4 100644
--- a/Modules/Compiler/Clang.cmake
+++ b/Modules/Compiler/Clang.cmake
@@ -11,7 +11,8 @@ set(__COMPILER_CLANG 1)
include(Compiler/CMakeCommonCompilerMacros)
if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
+ OR "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC")
macro(__compiler_clang lang)
endmacro()
else()
@@ -20,6 +21,12 @@ else()
macro(__compiler_clang lang)
__compiler_gnu(${lang})
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ # Link options for PIE are already set in 'Compiler/GNU.cmake'
+ # but clang may require alternate syntax on some platforms
+ if (APPLE)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} -Xlinker -pie)
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE -Xlinker -no_pie)
+ endif()
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0)
@@ -29,6 +36,16 @@ else()
set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "--target=")
set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "--gcc-toolchain=")
endif()
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP)
+
+ if(CMAKE_${lang}_COMPILER_TARGET)
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0)
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "-target" "${CMAKE_${lang}_COMPILER_TARGET}")
+ else()
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "--target=${CMAKE_${lang}_COMPILER_TARGET}")
+ endif()
+ endif()
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
@@ -69,15 +86,15 @@ else()
endif()
set(CMAKE_${lang}_ARCHIVE_CREATE_IPO
- "${__ar} cr <TARGET> <LINK_FLAGS> <OBJECTS>"
+ "\"${__ar}\" cr <TARGET> <LINK_FLAGS> <OBJECTS>"
)
set(CMAKE_${lang}_ARCHIVE_APPEND_IPO
- "${__ar} r <TARGET> <LINK_FLAGS> <OBJECTS>"
+ "\"${__ar}\" r <TARGET> <LINK_FLAGS> <OBJECTS>"
)
set(CMAKE_${lang}_ARCHIVE_FINISH_IPO
- "${__ranlib} <TARGET>"
+ "\"${__ranlib}\" <TARGET>"
)
endmacro()
endif()
diff --git a/Modules/Compiler/Cray-C.cmake b/Modules/Compiler/Cray-C.cmake
index 87ce20f71..93409489b 100644
--- a/Modules/Compiler/Cray-C.cmake
+++ b/Modules/Compiler/Cray-C.cmake
@@ -2,8 +2,7 @@
# file Copyright.txt or https://cmake.org/licensing for details.
include(Compiler/Cray)
-
-set(CMAKE_C_VERBOSE_FLAG "-v")
+__compiler_cray(C)
string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
@@ -11,11 +10,14 @@ string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1)
set(CMAKE_C90_STANDARD_COMPILE_OPTION -h noc99,conform)
set(CMAKE_C90_EXTENSION_COMPILE_OPTION -h noc99,gnu)
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C99_STANDARD_COMPILE_OPTION -h c99,conform)
set(CMAKE_C99_EXTENSION_COMPILE_OPTION -h c99,gnu)
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.5)
set(CMAKE_C11_STANDARD_COMPILE_OPTION -h std=c11,conform)
set(CMAKE_C11_EXTENSION_COMPILE_OPTION -h std=c11,gnu)
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
endif ()
endif ()
diff --git a/Modules/Compiler/Cray-CXX.cmake b/Modules/Compiler/Cray-CXX.cmake
index 8506c0942..38c8b1ee9 100644
--- a/Modules/Compiler/Cray-CXX.cmake
+++ b/Modules/Compiler/Cray-CXX.cmake
@@ -2,8 +2,7 @@
# file Copyright.txt or https://cmake.org/licensing for details.
include(Compiler/Cray)
-
-set(CMAKE_CXX_VERBOSE_FLAG "-v")
+__compiler_cray(CXX)
string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG")
@@ -11,9 +10,16 @@ string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION -h conform)
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -h gnu)
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.4)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION -h std=c++11)
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION -h std=c++11,gnu)
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
+ endif()
+ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.6)
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION -h std=c++14)
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION -h std=c++14,gnu)
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
endif ()
endif ()
diff --git a/Modules/Compiler/Cray-Fortran.cmake b/Modules/Compiler/Cray-Fortran.cmake
index 5d81bb02c..ccb7c2ee5 100644
--- a/Modules/Compiler/Cray-Fortran.cmake
+++ b/Modules/Compiler/Cray-Fortran.cmake
@@ -1,4 +1,11 @@
-set(CMAKE_Fortran_VERBOSE_FLAG "-v")
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+include(Compiler/Cray)
+__compiler_cray(Fortran)
+
+set(CMAKE_Fortran_SUBMODULE_SEP "")
+set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
set(CMAKE_Fortran_MODOUT_FLAG -em)
set(CMAKE_Fortran_MODDIR_FLAG -J)
set(CMAKE_Fortran_MODDIR_DEFAULT .)
diff --git a/Modules/Compiler/Cray.cmake b/Modules/Compiler/Cray.cmake
index 8fe8eebda..c214afc69 100644
--- a/Modules/Compiler/Cray.cmake
+++ b/Modules/Compiler/Cray.cmake
@@ -8,3 +8,10 @@ endif()
set(__COMPILER_CRAY 1)
include(Compiler/CMakeCommonCompilerMacros)
+
+macro(__compiler_cray lang)
+ set(CMAKE_${lang}_VERBOSE_FLAG "-v")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC -h PIC)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE -h PIC)
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-h PIC")
+endmacro()
diff --git a/Modules/Compiler/CrayPrgEnv-C.cmake b/Modules/Compiler/CrayPrgEnv-C.cmake
index 6b461ce06..76aa93b95 100644
--- a/Modules/Compiler/CrayPrgEnv-C.cmake
+++ b/Modules/Compiler/CrayPrgEnv-C.cmake
@@ -4,8 +4,4 @@ endif()
set(__craylinux_crayprgenv_c 1)
include(Compiler/CrayPrgEnv)
-macro(__CrayPrgEnv_setup_C compiler_cmd link_cmd)
- __CrayPrgEnv_setup(C
- ${CMAKE_ROOT}/Modules/CMakeCCompilerABI.c
- ${compiler_cmd} ${link_cmd})
-endmacro()
+__CrayPrgEnv_setup(C)
diff --git a/Modules/Compiler/CrayPrgEnv-CXX.cmake b/Modules/Compiler/CrayPrgEnv-CXX.cmake
index aad85b67e..442370ecc 100644
--- a/Modules/Compiler/CrayPrgEnv-CXX.cmake
+++ b/Modules/Compiler/CrayPrgEnv-CXX.cmake
@@ -4,8 +4,4 @@ endif()
set(__craylinux_crayprgenv_cxx 1)
include(Compiler/CrayPrgEnv)
-macro(__CrayPrgEnv_setup_CXX compiler_cmd link_cmd)
- __CrayPrgEnv_setup(CXX
- ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp
- ${compiler_cmd} ${link_cmd})
-endmacro()
+__CrayPrgEnv_setup(CXX)
diff --git a/Modules/Compiler/CrayPrgEnv-Fortran.cmake b/Modules/Compiler/CrayPrgEnv-Fortran.cmake
index 9c4d2694a..85f82d3f7 100644
--- a/Modules/Compiler/CrayPrgEnv-Fortran.cmake
+++ b/Modules/Compiler/CrayPrgEnv-Fortran.cmake
@@ -4,8 +4,4 @@ endif()
set(__craylinux_crayprgenv_fortran 1)
include(Compiler/CrayPrgEnv)
-macro(__CrayPrgEnv_setup_Fortran compiler_cmd link_cmd)
- __CrayPrgEnv_setup(Fortran
- ${CMAKE_ROOT}/Modules/CMakeFortranCompilerABI.F
- ${compiler_cmd} ${link_cmd})
-endmacro()
+__CrayPrgEnv_setup(Fortran)
diff --git a/Modules/Compiler/CrayPrgEnv.cmake b/Modules/Compiler/CrayPrgEnv.cmake
index 9f8befda3..f6e46acaa 100644
--- a/Modules/Compiler/CrayPrgEnv.cmake
+++ b/Modules/Compiler/CrayPrgEnv.cmake
@@ -1,57 +1,109 @@
# Guard against multiple inclusions
-if(__craylinux_crayprgenv)
+if(__cmake_craype_crayprgenv)
return()
endif()
-set(__craylinux_crayprgenv 1)
+set(__cmake_craype_crayprgenv 1)
-macro(__cray_extract_args cmd tag_regex out_var make_absolute)
- string(REGEX MATCHALL "${tag_regex}" args "${cmd}")
- foreach(arg IN LISTS args)
- string(REGEX REPLACE "^${tag_regex}$" "\\2" param "${arg}")
- if(make_absolute)
- get_filename_component(param "${param}" ABSOLUTE)
- endif()
- list(APPEND ${out_var} ${param})
- endforeach()
-endmacro()
+# CrayPrgEnv: loaded when compiling through the Cray compiler wrapper.
+# The compiler wrapper can run on a front-end node or a compute node.
-function(__cray_extract_implicit src compiler_cmd link_cmd lang include_dirs_var link_dirs_var link_libs_var)
- set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CrayExtractImplicit_${lang}.bin")
- execute_process(
- COMMAND ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_VERBOSE_FLAG} -o ${BIN}
- RESULT_VARIABLE result
- OUTPUT_VARIABLE output
- ERROR_VARIABLE error
- )
- if(EXISTS "${BIN}")
- file(REMOVE "${BIN}")
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
+# One-time setup of the craype environment. First, check the wrapper config.
+# The wrapper's selection of a compiler (gcc, clang, intel, etc.) and
+# default include/library paths is selected using the "module" command.
+# The CRAYPE_LINK_TYPE environment variable partly controls if static
+# or dynamic binaries are generated (see __cmake_craype_linktype below).
+# Running cmake and then changing module and/or linktype configuration
+# may cause build problems (since the data in the cmake cache may no
+# longer be correct after the change). We can look for this and warn
+# the user about it. Second, use the "module" provided PKG_CONFIG_PATH-like
+# environment variable to add additional prefixes to the system prefix
+# path.
+function(__cmake_craype_setupenv)
+ if(NOT DEFINED __cmake_craype_setupenv_done) # only done once per run
+ set(__cmake_craype_setupenv_done 1 PARENT_SCOPE)
+ unset(__cmake_check)
+ set(CMAKE_CRAYPE_LINKTYPE "$ENV{CRAYPE_LINK_TYPE}" CACHE STRING
+ "saved value of CRAYPE_LINK_TYPE environment variable")
+ set(CMAKE_CRAYPE_LOADEDMODULES "$ENV{LOADEDMODULES}" CACHE STRING
+ "saved value of LOADEDMODULES environment variable")
+ mark_as_advanced(CMAKE_CRAYPE_LINKTYPE CMAKE_CRAYPE_LOADEDMODULES)
+ if (NOT "${CMAKE_CRAYPE_LINKTYPE}" STREQUAL "$ENV{CRAYPE_LINK_TYPE}")
+ string(APPEND __cmake_check "CRAYPE_LINK_TYPE ")
+ endif()
+ if (NOT "${CMAKE_CRAYPE_LOADEDMODULES}" STREQUAL "$ENV{LOADEDMODULES}")
+ string(APPEND __cmake_check "LOADEDMODULES ")
+ endif()
+ if(DEFINED __cmake_check)
+ message(STATUS "NOTE: ${__cmake_check}changed since initial config!")
+ message(STATUS "NOTE: this may cause unexpected build errors.")
+ endif()
+ # loop over variables of interest
+ foreach(pkgcfgvar PKG_CONFIG_PATH PKG_CONFIG_PATH_DEFAULT
+ PE_PKG_CONFIG_PATH)
+ file(TO_CMAKE_PATH "$ENV{${pkgcfgvar}}" pkgcfg)
+ foreach(path ${pkgcfg})
+ string(REGEX REPLACE "(.*)/lib[^/]*/pkgconfig$" "\\1" path "${path}")
+ if(NOT "${path}" STREQUAL "" AND
+ NOT "${path}" IN_LIST CMAKE_SYSTEM_PREFIX_PATH)
+ list(APPEND CMAKE_SYSTEM_PREFIX_PATH "${path}")
+ endif()
+ endforeach()
+ endforeach()
+ # push it up out of this function into the parent scope
+ set(CMAKE_SYSTEM_PREFIX_PATH "${CMAKE_SYSTEM_PREFIX_PATH}" PARENT_SCOPE)
endif()
- set(include_dirs)
- set(link_dirs)
- set(link_libs)
- string(REGEX REPLACE "\r?\n" ";" output_lines "${output}\n${error}")
- foreach(line IN LISTS output_lines)
- if("${line}" MATCHES "${compiler_cmd}")
- __cray_extract_args("${line}" " -(I ?|isystem )([^ ]*)" include_dirs 1)
- set(processed_include 1)
+endfunction()
+
+# The wrapper disables dynamic linking by default. Dynamic linking is
+# enabled either by setting $ENV{CRAYPE_LINK_TYPE} to "dynamic" or by
+# specifying "-dynamic" to the wrapper when linking. Specifying "-static"
+# to the wrapper when linking takes priority over $ENV{CRAYPE_LINK_TYPE}.
+# Furthermore, if you specify multiple "-dynamic" and "-static" flags to
+# the wrapper when linking, the last one will win. In this case, the
+# wrapper will also print a warning like:
+# Warning: -dynamic was already seen on command line, overriding with -static.
+#
+# note that cmake applies both CMAKE_${lang}_FLAGS and CMAKE_EXE_LINKER_FLAGS
+# (in that order) to the linking command, so -dynamic can appear in either
+# variable.
+#
+# Note: As of CrayPE v19.06 (which translates to the craype/2.6.0 module)
+# the default has changed and is now dynamic by default. This is handled
+# accordingly
+function(__cmake_craype_linktype lang rv)
+ # start with ENV, but allow flags to override
+ if(("$ENV{CRAYPE_VERSION}" STREQUAL "") OR
+ ("$ENV{CRAYPE_VERSION}" VERSION_LESS "2.6"))
+ if("$ENV{CRAYPE_LINK_TYPE}" STREQUAL "dynamic")
+ set(linktype dynamic)
+ else()
+ set(linktype static)
endif()
- if("${line}" MATCHES "${link_cmd}")
- __cray_extract_args("${line}" " -(L ?)([^ ]*)" link_dirs 1)
- __cray_extract_args("${line}" " -(l ?)([^ ]*)" link_libs 0)
- set(processed_link 1)
+ else()
+ if("$ENV{CRAYPE_LINK_TYPE}" STREQUAL "static")
+ set(linktype static)
+ else()
+ set(linktype dynamic)
endif()
- if(processed_include AND processed_link)
- break()
+ endif()
+
+ # combine flags and convert to a list so we can apply the flags in order
+ set(linkflags "${CMAKE_${lang}_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
+ string(REPLACE " " ";" linkflags "${linkflags}")
+ foreach(flag IN LISTS linkflags)
+ if("${flag}" STREQUAL "-dynamic")
+ set(linktype dynamic)
+ elseif("${flag}" STREQUAL "-static")
+ set(linktype static)
endif()
endforeach()
-
- set(${include_dirs_var} "${include_dirs}" PARENT_SCOPE)
- set(${link_dirs_var} "${link_dirs}" PARENT_SCOPE)
- set(${link_libs_var} "${link_libs}" PARENT_SCOPE)
- set(CRAY_${lang}_EXTRACTED_IMPLICIT 1 CACHE INTERNAL "" FORCE)
+ set(${rv} ${linktype} PARENT_SCOPE)
endfunction()
-macro(__CrayPrgEnv_setup lang test_src compiler_cmd link_cmd)
+macro(__CrayPrgEnv_setup lang)
if(DEFINED ENV{CRAYPE_VERSION})
message(STATUS "Cray Programming Environment $ENV{CRAYPE_VERSION} ${lang}")
elseif(DEFINED ENV{ASYNCPE_VERSION})
@@ -60,34 +112,25 @@ macro(__CrayPrgEnv_setup lang test_src compiler_cmd link_cmd)
message(STATUS "Cray Programming Environment (unknown version) ${lang}")
endif()
+ # setup the craype environment
+ __cmake_craype_setupenv()
+
# Flags for the Cray wrappers
set(CMAKE_STATIC_LIBRARY_LINK_${lang}_FLAGS "-static")
- set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-dynamic")
- # If the link type is not explicitly specified in the environment then
- # the Cray wrappers assume that the code will be built staticly so
- # we check the following condition(s) are NOT met
- # Compiler flags are explicitly dynamic
- # Env var is dynamic and compiler flags are not explicitly static
- if(NOT (((CMAKE_${lang}_FLAGS MATCHES "(^| )-dynamic($| )") OR
- (CMAKE_EXE_LINKER_FLAGS MATCHES "(^| )-dynamic($| )"))
- OR
- (("$ENV{CRAYPE_LINK_TYPE}" STREQUAL "dynamic") AND
- NOT ((CMAKE_${lang}_FLAGS MATCHES "(^| )-static($| )") OR
- (CMAKE_EXE_LINKER_FLAGS MATCHES "(^| )-static($| )")))))
+ # determine linktype from environment and compiler flags
+ __cmake_craype_linktype(${lang} __cmake_craype_${lang}_linktype)
+
+ # switch off shared libs if we get a static linktype
+ if("${__cmake_craype_${lang}_linktype}" STREQUAL "static")
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(BUILD_SHARED_LIBS FALSE CACHE BOOL "")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(CMAKE_LINK_SEARCH_START_STATIC TRUE)
endif()
- if(NOT CRAY_${lang}_EXTRACTED_IMPLICIT)
- __cray_extract_implicit(
- ${test_src} ${compiler_cmd} ${link_cmd} ${lang}
- CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES
- CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES
- CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES
- )
- endif()
+
endmacro()
+
+cmake_policy(POP)
diff --git a/Modules/Compiler/G95-Fortran.cmake b/Modules/Compiler/G95-Fortran.cmake
index 2c83fb8fc..03b7e08b9 100644
--- a/Modules/Compiler/G95-Fortran.cmake
+++ b/Modules/Compiler/G95-Fortran.cmake
@@ -7,3 +7,5 @@ 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")
+set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
+set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
diff --git a/Modules/Compiler/GHS-C.cmake b/Modules/Compiler/GHS-C.cmake
index c30bdecaf..a825b0bba 100644
--- a/Modules/Compiler/GHS-C.cmake
+++ b/Modules/Compiler/GHS-C.cmake
@@ -8,23 +8,3 @@ string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -Odebug -g")
string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Ospace")
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O")
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -O -g")
-
-set(CMAKE_C_GHS_KERNEL_FLAGS_DEBUG_INIT "-ldebug ${CMAKE_C_FLAGS_DEBUG_INIT}")
-set(CMAKE_C_GHS_KERNEL_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT}")
-set(CMAKE_C_GHS_KERNEL_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT}")
-set(CMAKE_C_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT
- "-ldebug ${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}")
-
-if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
- set (CMAKE_C_GHS_KERNEL_FLAGS_DEBUG "${CMAKE_C_GHS_KERNEL_FLAGS_DEBUG_INIT}"
- CACHE STRING "Kernel flags used by the compiler during debug builds.")
- set (CMAKE_C_GHS_KERNEL_FLAGS_MINSIZEREL
- "${CMAKE_C_GHS_KERNEL_FLAGS_MINSIZEREL_INIT}" CACHE STRING
- "Kernel flags used by the compiler during release builds for minimum size.")
- set (CMAKE_C_GHS_KERNEL_FLAGS_RELEASE
- "${CMAKE_C_GHS_KERNEL_FLAGS_RELEASE_INIT}"
- CACHE STRING "Kernel flags used by the compiler during release builds.")
- set (CMAKE_C_GHS_KERNEL_FLAGS_RELWITHDEBINFO
- "${CMAKE_C_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
- "Kernel flags used by the compiler during release builds with debug info.")
-endif()
diff --git a/Modules/Compiler/GHS-CXX.cmake b/Modules/Compiler/GHS-CXX.cmake
index b3018a7b6..07b504424 100644
--- a/Modules/Compiler/GHS-CXX.cmake
+++ b/Modules/Compiler/GHS-CXX.cmake
@@ -8,27 +8,3 @@ string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -Odebug -g")
string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -Ospace")
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -O")
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -O -g")
-
-set(CMAKE_CXX_GHS_KERNEL_FLAGS_DEBUG_INIT
- "-ldebug ${CMAKE_CXX_FLAGS_DEBUG_INIT}")
-set(CMAKE_CXX_GHS_KERNEL_FLAGS_MINSIZEREL_INIT
- "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}")
-set(CMAKE_CXX_GHS_KERNEL_FLAGS_RELEASE_INIT
- "${CMAKE_CXX_FLAGS_RELEASE_INIT}")
-set(CMAKE_CXX_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT
- "-ldebug ${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}")
-
-if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
- set (CMAKE_CXX_GHS_KERNEL_FLAGS_DEBUG
- "${CMAKE_CXX_GHS_KERNEL_FLAGS_DEBUG_INIT}"
- CACHE STRING "Kernel flags used by the compiler during debug builds.")
- set (CMAKE_CXX_GHS_KERNEL_FLAGS_MINSIZEREL
- "${CMAKE_CXX_GHS_KERNEL_FLAGS_MINSIZEREL_INIT}" CACHE STRING
- "Kernel flags used by the compiler during release builds for minimum size.")
- set (CMAKE_CXX_GHS_KERNEL_FLAGS_RELEASE
- "${CMAKE_CXX_GHS_KERNEL_FLAGS_RELEASE_INIT}"
- CACHE STRING "Kernel flags used by the compiler during release builds.")
- set (CMAKE_CXX_GHS_KERNEL_FLAGS_RELWITHDEBINFO
- "${CMAKE_CXX_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
- "Kernel flags used by the compiler during release builds with debug info.")
-endif()
diff --git a/Modules/Compiler/GHS-DetermineCompiler.cmake b/Modules/Compiler/GHS-DetermineCompiler.cmake
index 56d24e266..368b3759d 100644
--- a/Modules/Compiler/GHS-DetermineCompiler.cmake
+++ b/Modules/Compiler/GHS-DetermineCompiler.cmake
@@ -1,6 +1,9 @@
-set(_compiler_id_pp_test "defined(__INTEGRITY)")
+set(_compiler_id_pp_test "defined(__ghs__)")
set(_compiler_id_version_compute "
-# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__INTEGRITY_MAJOR_VERSION)
-# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__INTEGRITY_MINOR_VERSION)
-# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__INTEGRITY_PATCH_VERSION)")
+/* __GHS_VERSION_NUMBER = VVVVRP */
+# ifdef __GHS_VERSION_NUMBER
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__GHS_VERSION_NUMBER / 100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__GHS_VERSION_NUMBER / 10 % 10)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__GHS_VERSION_NUMBER % 10)
+# endif")
diff --git a/Modules/Compiler/GHS.cmake b/Modules/Compiler/GHS.cmake
index e6a867d04..b41c3ebf8 100644
--- a/Modules/Compiler/GHS.cmake
+++ b/Modules/Compiler/GHS.cmake
@@ -3,6 +3,6 @@ if(__COMPILER_GHS)
endif()
set(__COMPILER_GHS 1)
-set(CMAKE_EXECUTABLE_SUFFIX ".as")
-set(CMAKE_LIBRARY_PATH_TERMINATOR "\n")
-set(CMAKE_LIBRARY_PATH_FLAG " -L")
+set(CMAKE_EXECUTABLE_SUFFIX "")
+set(CMAKE_LIBRARY_PATH_TERMINATOR "")
+set(CMAKE_LIBRARY_PATH_FLAG "")
diff --git a/Modules/Compiler/GNU-C.cmake b/Modules/Compiler/GNU-C.cmake
index f072c546a..ca286b397 100644
--- a/Modules/Compiler/GNU-C.cmake
+++ b/Modules/Compiler/GNU-C.cmake
@@ -10,13 +10,16 @@ elseif (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
endif()
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.4)
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
endif()
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7)
set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
elseif (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c1x")
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu1x")
diff --git a/Modules/Compiler/GNU-CXX.cmake b/Modules/Compiler/GNU-CXX.cmake
index 4f1f30e87..fcaaeab43 100644
--- a/Modules/Compiler/GNU-CXX.cmake
+++ b/Modules/Compiler/GNU-CXX.cmake
@@ -17,6 +17,7 @@ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
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.4)
@@ -25,6 +26,10 @@ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.4)
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++0x")
endif()
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8.1)
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
+endif()
+
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14")
@@ -33,9 +38,21 @@ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y")
endif()
-if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
+endif()
+
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17")
+elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z")
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z")
endif()
+if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
+ set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a")
+ set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a")
+endif()
+
__compiler_check_default_language_standard(CXX 3.4 98 6.0 14)
diff --git a/Modules/Compiler/GNU-FindBinUtils.cmake b/Modules/Compiler/GNU-FindBinUtils.cmake
index 16b7bbda4..097fbf3ac 100644
--- a/Modules/Compiler/GNU-FindBinUtils.cmake
+++ b/Modules/Compiler/GNU-FindBinUtils.cmake
@@ -18,7 +18,7 @@ get_filename_component(__gcc_hints "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPIL
find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x_y}"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x}"
- "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar"
+ "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_COMPILER_SUFFIX}"
HINTS ${__gcc_hints}
DOC "A wrapper around 'ar' adding the appropriate '--plugin' option for the GCC compiler"
)
@@ -28,7 +28,7 @@ mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR)
find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x_y}"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x}"
- "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
+ "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_COMPILER_SUFFIX}"
HINTS ${__gcc_hints}
DOC "A wrapper around 'ranlib' adding the appropriate '--plugin' option for the GCC compiler"
)
diff --git a/Modules/Compiler/GNU-Fortran.cmake b/Modules/Compiler/GNU-Fortran.cmake
index 94dc2755a..6413769cf 100644
--- a/Modules/Compiler/GNU-Fortran.cmake
+++ b/Modules/Compiler/GNU-Fortran.cmake
@@ -1,12 +1,17 @@
include(Compiler/GNU)
__compiler_gnu(Fortran)
+set(CMAKE_Fortran_SUBMODULE_SEP "@")
+set(CMAKE_Fortran_SUBMODULE_EXT ".smod")
+
set(CMAKE_Fortran_PREPROCESS_SOURCE
"<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> -o <PREPROCESSED_SOURCE>")
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form")
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form")
+set(CMAKE_Fortran_POSTPROCESS_FLAG "-fpreprocessed")
+
# No -DNDEBUG for Fortran.
string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -Os")
string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3")
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake
index 675e50534..6b1bd3a13 100644
--- a/Modules/Compiler/GNU.cmake
+++ b/Modules/Compiler/GNU.cmake
@@ -9,13 +9,20 @@ endif()
set(__COMPILER_GNU 1)
include(Compiler/CMakeCommonCompilerMacros)
+include(Internal/CMakeCheckCompilerFlag)
macro(__compiler_gnu lang)
# Feature flags.
set(CMAKE_${lang}_VERBOSE_FLAG "-v")
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
+ set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4)
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ # Support of PIE at link stage depends on various elements : platform, compiler, linker
+ # so to activate it, module CheckPIESupported must be used.
+ set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER YES)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie")
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie")
endif()
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.0)
set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
@@ -24,6 +31,9 @@ macro(__compiler_gnu lang)
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
set(CMAKE_${lang}_COMPILE_OPTIONS_SYSROOT "--sysroot=")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
+
# 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
@@ -75,15 +85,23 @@ macro(__compiler_gnu lang)
#
# [1]: https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gcc/Optimize-Options.html
set(CMAKE_${lang}_ARCHIVE_CREATE_IPO
- "${CMAKE_${lang}_COMPILER_AR} cr <TARGET> <LINK_FLAGS> <OBJECTS>"
+ "\"${CMAKE_${lang}_COMPILER_AR}\" cr <TARGET> <LINK_FLAGS> <OBJECTS>"
)
set(CMAKE_${lang}_ARCHIVE_APPEND_IPO
- "${CMAKE_${lang}_COMPILER_AR} r <TARGET> <LINK_FLAGS> <OBJECTS>"
+ "\"${CMAKE_${lang}_COMPILER_AR}\" r <TARGET> <LINK_FLAGS> <OBJECTS>"
)
set(CMAKE_${lang}_ARCHIVE_FINISH_IPO
- "${CMAKE_${lang}_COMPILER_RANLIB} <TARGET>"
+ "\"${CMAKE_${lang}_COMPILER_RANLIB}\" <TARGET>"
)
endif()
+
+ set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}")
+ if(CMAKE_${lang}_COMPILER_ARG1)
+ separate_arguments(_COMPILER_ARGS NATIVE_COMMAND "${CMAKE_${lang}_COMPILER_ARG1}")
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND ${_COMPILER_ARGS})
+ unset(_COMPILER_ARGS)
+ endif()
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "-dM" "-E" "-c" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
endmacro()
diff --git a/Modules/Compiler/HP-C.cmake b/Modules/Compiler/HP-C.cmake
index b42ba2be8..8fa4c08e2 100644
--- a/Modules/Compiler/HP-C.cmake
+++ b/Modules/Compiler/HP-C.cmake
@@ -2,3 +2,6 @@ set(CMAKE_C_VERBOSE_FLAG "-v")
set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl,")
+set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
diff --git a/Modules/Compiler/HP-CXX.cmake b/Modules/Compiler/HP-CXX.cmake
index 7548754d3..5726b6494 100644
--- a/Modules/Compiler/HP-CXX.cmake
+++ b/Modules/Compiler/HP-CXX.cmake
@@ -3,6 +3,9 @@ set(CMAKE_CXX_VERBOSE_FLAG "-v")
set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+set(CMAKE_CXX_LINKER_WRAPPER_FLAG "-Wl,")
+set(CMAKE_CXX_LINKER_WRAPPER_FLAG_SEP ",")
+
# 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
diff --git a/Modules/Compiler/HP-Fortran.cmake b/Modules/Compiler/HP-Fortran.cmake
index a6ca2c2b8..63a033135 100644
--- a/Modules/Compiler/HP-Fortran.cmake
+++ b/Modules/Compiler/HP-Fortran.cmake
@@ -4,3 +4,6 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "+source=free")
set(CMAKE_Fortran_CREATE_ASSEMBLY_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
set(CMAKE_Fortran_CREATE_PREPROCESSED_SOURCE "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+
+set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Wl,")
+set(CMAKE_Fortran_LINKER_WRAPPER_FLAG ",")
diff --git a/Modules/Compiler/IAR-ASM.cmake b/Modules/Compiler/IAR-ASM.cmake
index 844c30e50..437678e19 100644
--- a/Modules/Compiler/IAR-ASM.cmake
+++ b/Modules/Compiler/IAR-ASM.cmake
@@ -2,13 +2,41 @@
include(Compiler/IAR)
-set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+if("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM")
+ set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -S <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ __compiler_iar_ilink(ASM)
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
-if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM")
+elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RX")
+ set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ __compiler_iar_ilink(ASM)
set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
-endif()
+elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RH850")
+ set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ __compiler_iar_ilink(ASM)
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
+
+elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RL78")
+ set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ __compiler_iar_ilink(ASM)
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
-if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR")
+elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "RISC-V")
+ set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ __compiler_iar_ilink(ASM)
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s;asm;msa)
+
+elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR")
+ set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -S <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ __compiler_iar_xlink(ASM)
set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s90;asm;msa)
+
+elseif("${CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430")
+ set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -S <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ __compiler_iar_xlink(ASM)
+ set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS s43;asm;msa)
+
+else()
+ message(FATAL_ERROR "CMAKE_ASM${ASM_DIALECT}_COMPILER_ARCHITECTURE_ID not detected. This should be automatic.")
endif()
diff --git a/Modules/Compiler/IAR-C.cmake b/Modules/Compiler/IAR-C.cmake
index f65b0c7da..18a4a7581 100644
--- a/Modules/Compiler/IAR-C.cmake
+++ b/Modules/Compiler/IAR-C.cmake
@@ -1,37 +1,65 @@
# This file is processed when the IAR compiler is used for a C file
-
include(Compiler/IAR)
+include(Compiler/CMakeCommonCompilerMacros)
-set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
-set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
-set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
-
-set(CMAKE_C_RESPONSE_FILE_LINK_FLAG "-f ")
-set(CMAKE_DEPFILE_FLAGS_C "--dependencies=ns <DEPFILE>")
+# Common
+if(NOT CMAKE_C_COMPILER_VERSION)
+ message(FATAL_ERROR "CMAKE_C_COMPILER_VERSION not detected. This should be automatic.")
+endif()
-# The toolchains for ARM and AVR are quite different:
-if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM")
+set(CMAKE_C_EXTENSION_COMPILE_OPTION -e)
- 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> ")
+if(CMAKE_C_COMPILER_VERSION_INTERNAL VERSION_GREATER 7)
+ set(CMAKE_C90_STANDARD_COMPILE_OPTION --c89)
+ set(CMAKE_C90_EXTENSION_COMPILE_OPTION --c89 -e)
+ set(CMAKE_C99_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_C99_EXTENSION_COMPILE_OPTION -e)
+elseif()
+ set(CMAKE_C90_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_C90_EXTENSION_COMPILE_OPTION -e)
+endif()
+if(CMAKE_C_COMPILER_VERSION_INTERNAL VERSION_GREATER 8)
+ set(CMAKE_C11_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_C11_EXTENSION_COMPILE_OPTION -e)
endif()
+# Architecture specific
+if("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM")
+ if(CMAKE_C_COMPILER_VERSION_INTERNAL VERSION_LESS 7)
+ # IAR ARM 4.X uses xlink.exe, detection is not yet implemented
+ message(FATAL_ERROR "CMAKE_C_COMPILER_VERSION = ${CMAKE_C_COMPILER_VERSION} not supported by CMake.")
+ endif()
+ __compiler_iar_ilink(C)
+ __compiler_check_default_language_standard(C 1.10 90 6.10 99 8.10 11)
-if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "AVR")
- set(CMAKE_C_OUTPUT_EXTENSION ".r90")
+elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "RX")
+ __compiler_iar_ilink(C)
+ __compiler_check_default_language_standard(C 1.10 90 2.10 99 4.10 11)
- if(NOT CMAKE_C_LINK_FLAGS)
- set(CMAKE_C_LINK_FLAGS "-Fmotorola")
- endif()
+elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "RH850")
+ __compiler_iar_ilink(C)
+ __compiler_check_default_language_standard(C 1.10 90 1.10 99 2.10 11)
- 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> ")
+elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "RL78")
+ __compiler_iar_ilink(C)
+ __compiler_check_default_language_standard(C 1.10 90 1.10 99 4.10 11)
-endif()
+elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "RISCV")
+ __compiler_iar_ilink(C)
+ __compiler_check_default_language_standard(C 1.10 90 1.10 99 1.10 11)
+
+elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR")
+ __compiler_iar_xlink(C)
+ __compiler_check_default_language_standard(C 7.10 99)
+ set(CMAKE_C_OUTPUT_EXTENSION ".r90")
+
+elseif("${CMAKE_C_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430")
+ __compiler_iar_xlink(C)
+ __compiler_check_default_language_standard(C 1.10 90 5.10 99)
+ set(CMAKE_C_OUTPUT_EXTENSION ".r43")
-# add the target specific include directory:
-get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH)
-get_filename_component(_compilerDir "${_compilerDir}" PATH)
-include_directories("${_compilerDir}/inc" )
+else()
+ message(FATAL_ERROR "CMAKE_C_COMPILER_ARCHITECTURE_ID not detected. This should be automatic.")
+endif()
diff --git a/Modules/Compiler/IAR-CXX.cmake b/Modules/Compiler/IAR-CXX.cmake
index f49968e90..e8f114205 100644
--- a/Modules/Compiler/IAR-CXX.cmake
+++ b/Modules/Compiler/IAR-CXX.cmake
@@ -1,35 +1,73 @@
# This file is processed when the IAR compiler is used for a C++ file
include(Compiler/IAR)
+include(Compiler/CMakeCommonCompilerMacros)
-set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
-
-set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
-set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
-
-set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "-f ")
-set(CMAKE_DEPFILE_FLAGS_CXX "--dependencies=ns <DEPFILE>")
+# Common
+if(NOT CMAKE_CXX_COMPILER_VERSION)
+ message(FATAL_ERROR "CMAKE_CXX_COMPILER_VERSION not detected. This should be automatic.")
+endif()
-if("${IAR_TARGET_ARCHITECTURE}" STREQUAL "ARM")
+if(NOT CMAKE_IAR_CXX_FLAG)
+ # The --c++ flag was introduced in platform version 9 for all architectures except ARM where it was introduced already in version 7
+ if(CMAKE_CXX_COMPILER_VERSION_INTERNAL VERSION_GREATER 8 OR
+ (CMAKE_CXX_COMPILER_VERSION_INTERNAL VERSION_GREATER 6 AND "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM") )
+ set(CMAKE_IAR_CXX_FLAG --c++)
+ else()
+ set(CMAKE_IAR_CXX_FLAG --eec++)
+ endif()
+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> <TARGET> --create <LINK_FLAGS> <OBJECTS> ")
+set(CMAKE_CXX_EXTENSION_COMPILE_OPTION -e)
+if(CMAKE_CXX_COMPILER_VERSION_INTERNAL VERSION_GREATER 7)
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION -e)
+ set(CMAKE_CXX03_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX03_EXTENSION_COMPILE_OPTION -e)
endif()
+if(CMAKE_CXX_COMPILER_VERSION_INTERNAL VERSION_GREATER 8)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION -e)
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION -e)
+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")
+# Architecture specific
+if("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "ARM")
+ if(CMAKE_CXX_COMPILER_VERSION_INTERNAL VERSION_LESS 7)
+ # IAR ARM 4.X uses xlink.exe, detection is not yet implemented
+ message(FATAL_ERROR "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_C_COMPILER_VERSION} not supported by CMake.")
endif()
+ __compiler_iar_ilink(CXX)
+ __compiler_check_default_language_standard(CXX 6.10 98 8.10 14)
- 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> ")
+elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "RX")
+ __compiler_iar_ilink(CXX)
+ __compiler_check_default_language_standard(CXX 2.10 98 4.10 14)
-endif()
+elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "RH850")
+ __compiler_iar_ilink(CXX)
+ __compiler_check_default_language_standard(CXX 1.10 98 2.10 14)
+
+elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "RL78")
+ __compiler_iar_ilink(CXX)
+ __compiler_check_default_language_standard(CXX 1.10 98 4.10 14)
+
+elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "RISCV")
+ __compiler_iar_ilink(CXX)
+ __compiler_check_default_language_standard(CXX 1.10 98 1.10 14)
-# add the target specific include directory:
-get_filename_component(_compilerDir "${CMAKE_C_COMPILER}" PATH)
-get_filename_component(_compilerDir "${_compilerDir}" PATH)
-include_directories("${_compilerDir}/inc")
+elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "AVR")
+ __compiler_iar_xlink(CXX)
+ __compiler_check_default_language_standard(CXX 7.10 98)
+
+elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "MSP430")
+ __compiler_iar_xlink(CXX)
+ __compiler_check_default_language_standard(CXX 5.10 98)
+ set(CMAKE_CXX_OUTPUT_EXTENSION ".r43")
+
+else()
+ message(FATAL_ERROR "CMAKE_CXX_COMPILER_ARCHITECTURE_ID not detected. This should be automatic." )
+endif()
diff --git a/Modules/Compiler/IAR-DetermineCompiler.cmake b/Modules/Compiler/IAR-DetermineCompiler.cmake
index c39810a24..57ca1c991 100644
--- a/Modules/Compiler/IAR-DetermineCompiler.cmake
+++ b/Modules/Compiler/IAR-DetermineCompiler.cmake
@@ -1,4 +1,39 @@
-
-# IAR Systems compiler for embedded systems.
+# IAR Systems compiler for ARM embedded systems.
# http://www.iar.com
-set(_compiler_id_pp_test "defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)")
+# http://supp.iar.com/FilesPublic/UPDINFO/004916/arm/doc/EWARM_DevelopmentGuide.ENU.pdf
+#
+# __IAR_SYSTEMS_ICC__ An integer that identifies the IAR compiler platform:
+# 9 and higher means C11 and C++14 as language default
+# 8 means C99 and C++03 as language default
+# 7 and lower means C89 and EC++ as language default.
+# __ICCARM__ An integer that is set to 1 when the code is compiled with the IAR C/C++ Compiler for ARM
+# __VER__ An integer that identifies the version number of the IAR compiler in use. For example,
+# version 5.11.3 is returned as 5011003.
+#
+# IAR Systems Compiler for AVR embedded systems
+# http://supp.iar.com/FilesPublic/UPDINFO/007051/ew/doc/EWAVR_CompilerReference.pdf
+#
+# __IAR_SYSTEMS_ICC__ An integer that identifies the IAR compiler platform.
+# __ICCAVR__ An integer that is set to 1 when the code is compiled with the IAR C/C++ Compiler for AVR
+# __VER__ An integer that identifies the version number of the IAR compiler in use.
+# The value is calculated by (100 * VERSION_MAJOR + VERSION_MINOR). For example the version
+# 3.34 is given as 334
+# __SUBVERSION__ An integer that identifies the subversion number of the compiler version number
+# for example 3 in 1.2.3.4. THis is used as the patch version, as seen when running iccavr
+# from the command line
+#
+
+set(_compiler_id_pp_test "defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)")
+
+set(_compiler_id_version_compute "
+# if defined(__VER__) && defined(__ICCARM__)
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@((__VER__) / 1000000)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(((__VER__) / 1000) % 1000)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@((__VER__) % 1000)
+# define @PREFIX@COMPILER_VERSION_INTERNAL @MACRO_DEC@(__IAR_SYSTEMS_ICC__)
+# elif defined(__VER__) && (defined(__ICCAVR__) || defined(__ICCRX__) || defined(__ICCRH850__) || defined(__ICCRL78__) || defined(__ICC430__) || defined(__ICCRISCV__))
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@((__VER__) / 100)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@((__VER__) - (((__VER__) / 100)*100))
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__SUBVERSION__)
+# define @PREFIX@COMPILER_VERSION_INTERNAL @MACRO_DEC@(__IAR_SYSTEMS_ICC__)
+# endif")
diff --git a/Modules/Compiler/IAR.cmake b/Modules/Compiler/IAR.cmake
index 8c45276db..8e75caafe 100644
--- a/Modules/Compiler/IAR.cmake
+++ b/Modules/Compiler/IAR.cmake
@@ -2,46 +2,113 @@
# Documentation can be downloaded here: http://www.iar.com/website1/1.0.1.0/675/1/
# The initial feature request is here: https://gitlab.kitware.com/cmake/cmake/issues/10176
# It also contains additional links and information.
+# See USER GUIDES -> C/C++ Development Guide and ReleaseNotes for EWARM:
+# version 6.30.8: http://supp.iar.com/FilesPublic/UPDINFO/006607/arm/doc/infocenter/index.ENU.html
+# version 7.60.1: http://supp.iar.com/FilesPublic/UPDINFO/011006/arm/doc/infocenter/index.ENU.html
+# version 8.10.1: http://netstorage.iar.com/SuppDB/Public/UPDINFO/011854/arm/doc/infocenter/index.ENU.html
-if(_IAR_CMAKE_LOADED)
- return()
-endif()
-set(_IAR_CMAKE_LOADED TRUE)
+# The IAR internal compiler platform generations (Predefined symbol __IAR_SYSTEMS_ICC__):
+# 9 and higher means C11 and C++14 as language default (EWARM v8.x, EWRX v4.x and higher)
+# 8 means C99 and C++03 as language default (EWARM v6.x, v7.x. EWRX v2.x, 3.x)
+# 7 and lower means C89 and EC++ as language default. (EWARM v5.x and lower)
+# C/C++ Standard versions
+#
+# IAR typically only supports one C and C++ Standard version,
+# the exception is C89 which is always supported and can be selected
+# if its not the default
+#
+# C++ is trickier, there were historically 3 switches,
+# and some IAR versions support multiple of those.
+# they are --eec++, --ec++ and --c++ and where used to
+# enable various language features like exceptions
+#
+# recent versions only have --c++ for full support
+# but can choose to disable features with further arguments
+#
+# C/C++ Standard compliance
+#
+# IAR has 3 modes: default, strict and extended
+# the extended mode is needed for popular libraries like CMSIS
+#
+# "Silent" Operation
+#
+# this really is different to most programs I know.
+# nothing meaningful from the operation is lost, just some redundant
+# code and data size printouts (that can be inspected with common tools).
-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)
+# This module is shared by multiple languages; use include blocker.
+include_guard()
-
-if("${CMAKE_C_COMPILER}" MATCHES "arm" OR "${CMAKE_CXX_COMPILER}" MATCHES "arm" OR "${CMAKE_ASM_COMPILER}" MATCHES "arm")
+macro(__compiler_iar_ilink lang)
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
+ if (${lang} STREQUAL "C" OR ${lang} STREQUAL "CXX")
+ set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
+ set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
+
+ set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-f ")
+ set(CMAKE_DEPFILE_FLAGS_${lang} "--dependencies=ns <DEPFILE>")
+
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
+ string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -r")
+ string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Ohz -DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -Oh -DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -Oh -r -DNDEBUG")
+ endif()
+
+ if (${lang} STREQUAL "ASM")
+ string(APPEND CMAKE_ASM_FLAGS_INIT " ")
+ string(APPEND CMAKE_ASM_FLAGS_DEBUG_INIT " -r")
+ string(APPEND CMAKE_ASM_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
+ string(APPEND CMAKE_ASM_FLAGS_RELEASE_INIT " -DNDEBUG")
+ string(APPEND CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT " -r -DNDEBUG")
+ endif()
- # 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(CMAKE_${lang}_LINK_EXECUTABLE "\"${CMAKE_IAR_LINKER}\" --silent <OBJECTS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
+ set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --create <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_CREATE "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --create <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_APPEND "\"${CMAKE_IAR_ARCHIVE}\" <TARGET> --replace <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_FINISH "")
- set(IAR_TARGET_ARCHITECTURE "ARM" CACHE STRING "IAR compiler target architecture")
-endif()
+ set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE)
+ set(CMAKE_AR "${CMAKE_IAR_ARCHIVE}" CACHE FILEPATH "The IAR archiver" FORCE)
+endmacro()
-if("${CMAKE_C_COMPILER}" MATCHES "avr" OR "${CMAKE_CXX_COMPILER}" MATCHES "avr" OR "${CMAKE_ASM_COMPILER}" MATCHES "avr")
+macro(__compiler_iar_xlink lang)
set(CMAKE_EXECUTABLE_SUFFIX ".bin")
+ if (${lang} STREQUAL "C" OR ${lang} STREQUAL "CXX")
- # 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(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
+ set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> --preprocess=cnl <PREPROCESSED_SOURCE>")
+ set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -lAH <ASSEMBLY_SOURCE> -o <OBJECT>.dummy")
- set(IAR_TARGET_ARCHITECTURE "AVR" CACHE STRING "IAR compiler target architecture")
+ set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-f ")
+ set(CMAKE_DEPFILE_FLAGS_${lang} "--dependencies=ns <DEPFILE>")
- set(CMAKE_LIBRARY_PATH_FLAG "-I")
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
+ string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -r")
+ string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Ohz -DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -Oh -DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -Oh -r -DNDEBUG")
+ endif()
+
+ if (${lang} STREQUAL "ASM")
+ string(APPEND CMAKE_ASM_FLAGS_INIT " ")
+ string(APPEND CMAKE_ASM_FLAGS_DEBUG_INIT " -r")
+ string(APPEND CMAKE_ASM_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
+ string(APPEND CMAKE_ASM_FLAGS_RELEASE_INIT " -DNDEBUG")
+ string(APPEND CMAKE_ASM_FLAGS_RELWITHDEBINFO_INIT " -r -DNDEBUG")
+ endif()
-endif()
+ set(CMAKE_${lang}_LINK_EXECUTABLE "\"${CMAKE_IAR_LINKER}\" -S <OBJECTS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES> -o <TARGET>")
+ set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${CMAKE_IAR_AR}\" <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_CREATE "\"${CMAKE_IAR_AR}\" <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_APPEND "")
+ set(CMAKE_${lang}_ARCHIVE_FINISH "")
-if(NOT IAR_TARGET_ARCHITECTURE)
- message(FATAL_ERROR "The IAR compiler for this architecture is not yet supported "
- "by CMake. Please go to https://gitlab.kitware.com/cmake/cmake/issues "
- "and enter a feature request there.")
-endif()
+ set(CMAKE_LIBRARY_PATH_FLAG "-I")
-set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE)
-set(CMAKE_AR "${CMAKE_IAR_AR}" CACHE FILEPATH "The IAR archiver" FORCE)
+ set(CMAKE_LINKER "${CMAKE_IAR_LINKER}" CACHE FILEPATH "The IAR linker" FORCE)
+ set(CMAKE_AR "${CMAKE_IAR_AR}" CACHE FILEPATH "The IAR archiver" FORCE)
+endmacro()
diff --git a/Modules/Compiler/Intel-C.cmake b/Modules/Compiler/Intel-C.cmake
index 4e4af2956..e9e59a20c 100644
--- a/Modules/Compiler/Intel-C.cmake
+++ b/Modules/Compiler/Intel-C.cmake
@@ -12,13 +12,16 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC")
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 16.0.0)
set(CMAKE_C11_STANDARD_COMPILE_OPTION "-Qstd=c11")
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-Qstd=c11")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
endif()
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.0)
set(CMAKE_C90_STANDARD_COMPILE_OPTION "-Qstd=c89")
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-Qstd=c89")
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C99_STANDARD_COMPILE_OPTION "-Qstd=c99")
set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-Qstd=c99")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
endif()
else()
@@ -26,13 +29,16 @@ else()
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15.0.0)
set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
endif()
if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 12.0)
set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89")
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu89")
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
endif()
endif()
diff --git a/Modules/Compiler/Intel-CXX-FeatureTests.cmake b/Modules/Compiler/Intel-CXX-FeatureTests.cmake
index 929a7c632..bbefe15de 100644
--- a/Modules/Compiler/Intel-CXX-FeatureTests.cmake
+++ b/Modules/Compiler/Intel-CXX-FeatureTests.cmake
@@ -31,11 +31,6 @@ set(_cmake_feature_test_cxx_aggregate_default_initializers "${Intel16_CXX14}")
set(_cmake_feature_test_cxx_contextual_conversions "${Intel16_CXX14}")
set(_cmake_feature_test_cxx_generic_lambdas "__cpp_generic_lambdas >= 201304")
set(_cmake_feature_test_cxx_digit_separators "${Intel16_CXX14}")
-# This test is supposed to work in Intel 14 but the compiler has a bug
-# in versions 14 and 15::
-# https://software.intel.com/en-us/forums/intel-c-compiler/topic/600514
-# It also appears to fail with an internal compiler error on Intel 16 and 17.
-#set(_cmake_feature_test_cxx_generalized_initializers "${Intel16_CXX14}")
unset(Intel16_CXX14)
set(Intel15 "__INTEL_COMPILER >= 1500")
@@ -75,6 +70,7 @@ set(_cmake_feature_test_cxx_override "${Intel14_CXX11}")
set(_cmake_feature_test_cxx_final "${Intel14_CXX11}")
set(_cmake_feature_test_cxx_noexcept "${Intel14_CXX11}")
set(_cmake_feature_test_cxx_defaulted_move_initializers "${Intel14_CXX11}")
+set(_cmake_feature_test_cxx_generalized_initializers "${Intel14_CXX11}")
unset(Intel14_CXX11)
set(Intel13_CXX11 "__INTEL_COMPILER >= 1300 && ${DETECT_CXX11}")
diff --git a/Modules/Compiler/Intel-CXX.cmake b/Modules/Compiler/Intel-CXX.cmake
index 0eb9e1fd7..b630a6bc4 100644
--- a/Modules/Compiler/Intel-CXX.cmake
+++ b/Modules/Compiler/Intel-CXX.cmake
@@ -9,6 +9,11 @@ set(CMAKE_DEPFILE_FLAGS_CXX "-MD -MT <OBJECT> -MF <DEPFILE>")
if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.0)
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-Qstd=c++17")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-Qstd=c++17")
+ endif()
+
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0)
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-Qstd=c++14")
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-Qstd=c++14")
@@ -25,18 +30,36 @@ if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
endif()
else()
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.0)
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17")
+ endif()
+
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17.0)
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
+ endif()
+
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.2)
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
- # todo: there is no gnu++14 value supported; figure out what to do
- set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++14")
elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.0)
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y")
- # todo: there is no gnu++14 value supported; figure out what to do
- set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++1y")
+ endif()
+
+ # Intel 15.0.2 accepts c++14 instead of c++1y, but not gnu++14
+ # instead of gnu++1y. Intel 17.0.0 accepts gnu++14 too.
+ if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0)
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++14")
+ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0.0)
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=gnu++1y")
+ endif()
+
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0)
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
endif()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0)
@@ -50,6 +73,7 @@ else()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.1)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
endif()
endif()
diff --git a/Modules/Compiler/Intel-DetermineCompiler.cmake b/Modules/Compiler/Intel-DetermineCompiler.cmake
index d7e453211..c31aa7752 100644
--- a/Modules/Compiler/Intel-DetermineCompiler.cmake
+++ b/Modules/Compiler/Intel-DetermineCompiler.cmake
@@ -18,9 +18,23 @@ set(_compiler_id_version_compute "
/* _MSC_VER = VVRR */
# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(_MSC_VER / 100)
# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(_MSC_VER % 100)
+# endif
+# if defined(__GNUC__)
+# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(__GNUC__)
+# elif defined(__GNUG__)
+# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(__GNUG__)
+# endif
+# if defined(__GNUC_MINOR__)
+# define @PREFIX@SIMULATE_VERSION_MINOR @MACRO_DEC@(__GNUC_MINOR__)
+# endif
+# if defined(__GNUC_PATCHLEVEL__)
+# define @PREFIX@SIMULATE_VERSION_PATCH @MACRO_DEC@(__GNUC_PATCHLEVEL__)
# endif")
set(_compiler_id_simulate "
# if defined(_MSC_VER)
# define @PREFIX@SIMULATE_ID \"MSVC\"
+# endif
+# if defined(__GNUC__)
+# define @PREFIX@SIMULATE_ID \"GNU\"
# endif")
diff --git a/Modules/Compiler/Intel-Fortran.cmake b/Modules/Compiler/Intel-Fortran.cmake
index a1320555a..5275ddf64 100644
--- a/Modules/Compiler/Intel-Fortran.cmake
+++ b/Modules/Compiler/Intel-Fortran.cmake
@@ -1,6 +1,9 @@
include(Compiler/Intel)
__compiler_intel(Fortran)
+set(CMAKE_Fortran_SUBMODULE_SEP "@")
+set(CMAKE_Fortran_SUBMODULE_EXT ".smod")
+
set(CMAKE_Fortran_MODDIR_FLAG "-module ")
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
diff --git a/Modules/Compiler/Intel.cmake b/Modules/Compiler/Intel.cmake
index 635ac4d3c..f2f16e010 100644
--- a/Modules/Compiler/Intel.cmake
+++ b/Modules/Compiler/Intel.cmake
@@ -25,6 +25,12 @@ else()
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3")
string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g")
- set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}" "-QdM" "-P" "-Za" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
+ set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}")
+ if(CMAKE_${lang}_COMPILER_ARG1)
+ separate_arguments(_COMPILER_ARGS NATIVE_COMMAND "${CMAKE_${lang}_COMPILER_ARG1}")
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND ${_COMPILER_ARGS})
+ unset(_COMPILER_ARGS)
+ endif()
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "-QdM" "-P" "-Za" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
endmacro()
endif()
diff --git a/Modules/Compiler/MSVC-CXX-FeatureTests.cmake b/Modules/Compiler/MSVC-CXX-FeatureTests.cmake
index 596958668..125974a8d 100644
--- a/Modules/Compiler/MSVC-CXX-FeatureTests.cmake
+++ b/Modules/Compiler/MSVC-CXX-FeatureTests.cmake
@@ -1,15 +1,18 @@
+# Reference: https://docs.microsoft.com/en-us/cpp/visual-cpp-language-conformance
+# https://blogs.msdn.microsoft.com/vcblog/2015/06/19/c111417-features-in-vs-2015-rtm/
+# https://blogs.msdn.microsoft.com/vcblog/2013/12/02/c1114-core-language-features-in-vs-2013-and-the-nov-2013-ctp/
+# https://blogs.msdn.microsoft.com/vcblog/2011/09/12/c11-features-in-visual-c-11/
-# Reference: http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx
-# http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx
-# http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx
-# http://www.visualstudio.com/en-us/news/vs2015-preview-vs.aspx
-# http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx
-# http://blogs.msdn.com/b/vcblog/archive/2015/06/19/c-11-14-17-features-in-vs-2015-rtm.aspx
+set(_cmake_oldestSupported "_MSC_VER >= 1600")
+# VS 2017 v15.3 fixes support for incomplete decltypes
+# https://docs.microsoft.com/en-us/cpp/cpp-conformance-improvements-2017#update_153
+set(_cmake_feature_test_cxx_decltype_incomplete_return_types "_MSC_VER >= 1911")
-set(_cmake_oldestSupported "_MSC_VER >= 1600")
+# VS 2017 v15.3 fixes support for "N3652 Extended constexpr"
+set(_cmake_feature_test_cxx_relaxed_constexpr "_MSC_VER >= 1911")
-# VS version 15 (not 2015) introduces support for aggregate initializers.
+# VS 2017 Preview introduces support for aggregate initializers.
set(_cmake_feature_test_cxx_aggregate_default_initializers "_MSC_FULL_VER >= 190024406")
# VS 2015 Update 2 introduces support for variable templates.
@@ -48,7 +51,6 @@ set(_cmake_feature_test_cxx_reference_qualified_functions "${MSVC_2015}")
# lists this as 'partial' in 2013
set(_cmake_feature_test_cxx_deleted_functions "${MSVC_2015}")
-set(MSVC_2013_v30723 "_MSC_FULL_VER >= 180030723")
# http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx
# Note 1. While previous version of VisualStudio said they supported these
# they silently produced bad code, and are now marked as having partial
@@ -56,7 +58,7 @@ set(MSVC_2013_v30723 "_MSC_FULL_VER >= 180030723")
# in MSVC 2015, so support the feature for that version, assuming that is true.
# The blog post also says that VS 2013 Update 3 generates an error in cases
# that previously produced bad code.
-set(_cmake_feature_test_cxx_generalized_initializers "${MSVC_2013_v30723}")
+set(_cmake_feature_test_cxx_generalized_initializers "_MSC_FULL_VER >= 180030723")
set(MSVC_2013 "_MSC_VER >= 1800")
set(_cmake_feature_test_cxx_alias_templates "${MSVC_2013}")
@@ -98,20 +100,10 @@ set(_cmake_feature_test_cxx_template_template_parameters "${MSVC_2010}")
set(_cmake_feature_test_cxx_trailing_return_types "${MSVC_2010}")
set(_cmake_feature_test_cxx_variadic_macros "${MSVC_2010}")
-# Currently unsupported:
-# set(_cmake_feature_test_cxx_relaxed_constexpr )
-# 'NSDMIs for aggregates'
-# set(_cmake_feature_test_cxx_aggregate_default_initializers )
-
-# In theory decltype incomplete return types was added in 2012
-# but without support for decltype_auto and return type deduction this
-# feature is unusable. This remains so as of VS 2015 Preview.
-# set(_cmake_feature_test_cxx_decltype_incomplete_return_types )
-
# Unset all the variables that we don't need exposed.
# _cmake_oldestSupported is required by WriteCompilerDetectionHeader
+set(MSVC_2017)
set(MSVC_2015)
-set(MSVC_2013_v30723)
set(MSVC_2013)
set(MSVC_2012)
set(MSVC_2010)
diff --git a/Modules/Compiler/MSVC-CXX.cmake b/Modules/Compiler/MSVC-CXX.cmake
index 9371301d7..915295d38 100644
--- a/Modules/Compiler/MSVC-CXX.cmake
+++ b/Modules/Compiler/MSVC-CXX.cmake
@@ -3,7 +3,36 @@
include(Compiler/CMakeCommonCompilerMacros)
-if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
+if ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0.24215.1 AND
+ CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) OR
+ CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10.25017)
+
+ # VS 2015 Update 3 and above support language standard level flags,
+ # with the default and minimum level being C++14.
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std:c++14")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std:c++14")
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.11.25505)
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++17")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++17")
+ else()
+ set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std:c++latest")
+ set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std:c++latest")
+ endif()
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.12.25835)
+ set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std:c++latest")
+ set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std:c++latest")
+ endif()
+
+ __compiler_check_default_language_standard(CXX 19.0 14)
+
+elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
# MSVC has no specific options to set language standards, but set them as
# empty strings anyways so the feature test infrastructure can at least check
# to see if they are defined.
@@ -15,7 +44,29 @@ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.0)
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "")
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "")
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "")
+ set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "")
# There is no meaningful default for this
set(CMAKE_CXX_STANDARD_DEFAULT "")
+
+ # There are no compiler modes so we only need to test features once.
+ # Override the default macro for this special case. Pretend that
+ # all language standards are available so that at least compilation
+ # can be attempted.
+ macro(cmake_record_cxx_compile_features)
+ list(APPEND CMAKE_CXX_COMPILE_FEATURES
+ cxx_std_98
+ cxx_std_11
+ cxx_std_14
+ cxx_std_17
+ cxx_std_20
+ )
+ _record_compiler_features(CXX "" CMAKE_CXX_COMPILE_FEATURES)
+ endmacro()
+endif()
+
+# /JMC "Just My Code" is only supported by MSVC 19.05 onward.
+if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
+ set(CMAKE_CXX_COMPILE_OPTIONS_JMC "-JMC")
endif()
diff --git a/Modules/Compiler/NAG-Fortran.cmake b/Modules/Compiler/NAG-Fortran.cmake
index 39aae1883..9973febc3 100644
--- a/Modules/Compiler/NAG-Fortran.cmake
+++ b/Modules/Compiler/NAG-Fortran.cmake
@@ -34,3 +34,4 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-PIC")
set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "-PIC")
+set(CMAKE_Fortran_RESPONSE_FILE_LINK_FLAG "-Wl,@")
diff --git a/Modules/Compiler/NVIDIA-CUDA.cmake b/Modules/Compiler/NVIDIA-CUDA.cmake
index 785e26998..c0ccb7147 100644
--- a/Modules/Compiler/NVIDIA-CUDA.cmake
+++ b/Modules/Compiler/NVIDIA-CUDA.cmake
@@ -1,4 +1,5 @@
set(CMAKE_CUDA_VERBOSE_FLAG "-v")
+set(CMAKE_CUDA_VERBOSE_COMPILE_FLAG "-Xcompiler=-v")
if(NOT "x${CMAKE_CUDA_SIMULATE_ID}" STREQUAL "xMSVC")
set(CMAKE_CUDA_COMPILE_OPTIONS_PIE -Xcompiler=-fPIE)
@@ -26,8 +27,21 @@ else()
set(CMAKE_CUDA11_EXTENSION_COMPILE_OPTION "-std=c++11")
if (NOT CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0)
+ set(CMAKE_CUDA98_STANDARD_COMPILE_OPTION "-std=c++03")
+ set(CMAKE_CUDA98_EXTENSION_COMPILE_OPTION "-std=c++03")
set(CMAKE_CUDA14_STANDARD_COMPILE_OPTION "-std=c++14")
set(CMAKE_CUDA14_EXTENSION_COMPILE_OPTION "-std=c++14")
endif()
endif()
+
+# FIXME: investigate use of --options-file.
+# Tell Makefile generator that nvcc does not support @<rspfile> syntax.
+set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_INCLUDES 0)
+set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_LIBRARIES 0)
+set(CMAKE_CUDA_USE_RESPONSE_FILE_FOR_OBJECTS 0)
+
+if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0")
+ set(CMAKE_CUDA_RESPONSE_FILE_LINK_FLAG "--options-file ")
+ set(CMAKE_CUDA_RESPONSE_FILE_FLAG "--options-file ")
+endif()
diff --git a/Modules/Compiler/NVIDIA-DetermineCompiler.cmake b/Modules/Compiler/NVIDIA-DetermineCompiler.cmake
index cb0beaf52..bf9111a24 100644
--- a/Modules/Compiler/NVIDIA-DetermineCompiler.cmake
+++ b/Modules/Compiler/NVIDIA-DetermineCompiler.cmake
@@ -2,9 +2,11 @@
set(_compiler_id_pp_test "defined(__NVCC__)")
set(_compiler_id_version_compute "
-# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__CUDACC_VER_MAJOR__)
-# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__CUDACC_VER_MINOR__)
-# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__CUDACC_VER_BUILD__)
+# if defined(__CUDACC_VER_MAJOR__)
+# define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__CUDACC_VER_MAJOR__)
+# define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__CUDACC_VER_MINOR__)
+# define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__CUDACC_VER_BUILD__)
+# endif
# if defined(_MSC_VER)
/* _MSC_VER = VVRR */
# define @PREFIX@SIMULATE_VERSION_MAJOR @MACRO_DEC@(_MSC_VER / 100)
diff --git a/Modules/Compiler/PGI-C.cmake b/Modules/Compiler/PGI-C.cmake
index 3b3848a2c..c39dbe517 100644
--- a/Modules/Compiler/PGI-C.cmake
+++ b/Modules/Compiler/PGI-C.cmake
@@ -6,11 +6,14 @@ string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.10)
set(CMAKE_C90_STANDARD_COMPILE_OPTION -c89)
set(CMAKE_C90_EXTENSION_COMPILE_OPTION -c89)
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C99_STANDARD_COMPILE_OPTION -c99)
set(CMAKE_C99_EXTENSION_COMPILE_OPTION -c99)
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 15.3)
set(CMAKE_C11_STANDARD_COMPILE_OPTION -c11)
set(CMAKE_C11_EXTENSION_COMPILE_OPTION -c11)
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
endif ()
endif ()
diff --git a/Modules/Compiler/PGI-CXX.cmake b/Modules/Compiler/PGI-CXX.cmake
index 35076bb38..c77de3605 100644
--- a/Modules/Compiler/PGI-CXX.cmake
+++ b/Modules/Compiler/PGI-CXX.cmake
@@ -6,15 +6,19 @@ string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.10)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION -A)
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION --gnu_extensions)
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.10)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION --c++11 -A)
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION --c++11 --gnu_extensions)
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.7)
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14 -A)
set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION --c++14 --gnu_extensions)
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17.1)
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION --c++17 -A)
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION --c++17 --gnu_extensions)
+ set(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT ON)
endif()
endif()
endif()
diff --git a/Modules/Compiler/PGI-Fortran.cmake b/Modules/Compiler/PGI-Fortran.cmake
index 478342436..3daf7987e 100644
--- a/Modules/Compiler/PGI-Fortran.cmake
+++ b/Modules/Compiler/PGI-Fortran.cmake
@@ -1,13 +1,15 @@
include(Compiler/PGI)
__compiler_pgi(Fortran)
+set(CMAKE_Fortran_SUBMODULE_SEP "-")
+set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
+
set(CMAKE_Fortran_PREPROCESS_SOURCE
"<CMAKE_Fortran_COMPILER> -Mpreprocess <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-Mnofreeform")
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-Mfreeform")
-string(APPEND CMAKE_Fortran_FLAGS_INIT " -Mpreprocess -Kieee")
string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -Mbounds")
set(CMAKE_Fortran_MODDIR_FLAG "-module ")
diff --git a/Modules/Compiler/PGI.cmake b/Modules/Compiler/PGI.cmake
index 0cbfd8a0b..4f8b90b13 100644
--- a/Modules/Compiler/PGI.cmake
+++ b/Modules/Compiler/PGI.cmake
@@ -19,16 +19,23 @@ macro(__compiler_pgi lang)
string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g -O0")
string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -O2 -s")
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -fast -O3")
- # -Mipa was dropped with PGI 16.3 from Windows versions
- if(NOT CMAKE_HOST_WIN32 OR CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 16.3)
- string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -Mipa=fast")
- endif()
string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -gopt")
if(CMAKE_HOST_WIN32)
string(APPEND CMAKE_${lang}_FLAGS_INIT " -Bdynamic")
endif()
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG ",")
+
+ set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
+ if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le AND (NOT CMAKE_HOST_WIN32 OR CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 16.3))
+ set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-Mipa=fast,inline")
+ else()
+ set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
+ endif()
+
# Preprocessing and assembly rules.
set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
diff --git a/Modules/Compiler/QCC-C.cmake b/Modules/Compiler/QCC-C.cmake
index ae4a2f491..6db619e57 100644
--- a/Modules/Compiler/QCC-C.cmake
+++ b/Modules/Compiler/QCC-C.cmake
@@ -1,2 +1,5 @@
+# To include compiler feature detection
+include(Compiler/GNU-C)
+
include(Compiler/QCC)
__compiler_qcc(C)
diff --git a/Modules/Compiler/QCC-CXX.cmake b/Modules/Compiler/QCC-CXX.cmake
index e86d1fa47..0e7314ae5 100644
--- a/Modules/Compiler/QCC-CXX.cmake
+++ b/Modules/Compiler/QCC-CXX.cmake
@@ -1,3 +1,6 @@
+# To include compiler feature detection
+include(Compiler/GNU-CXX)
+
include(Compiler/QCC)
__compiler_qcc(CXX)
diff --git a/Modules/Compiler/QCC.cmake b/Modules/Compiler/QCC.cmake
index 0da7050ba..9df826909 100644
--- a/Modules/Compiler/QCC.cmake
+++ b/Modules/Compiler/QCC.cmake
@@ -11,11 +11,22 @@ macro(__compiler_qcc lang)
set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "-V")
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-Wp,-isystem,")
- set(CMAKE_DEPFILE_FLAGS_${lang} "-Wc,-MD,<DEPFILE>,-MT,<OBJECT>,-MF,<DEPFILE>")
+ set(CMAKE_DEPFILE_FLAGS_${lang} "-Wp,-MD,<DEPFILE> -Wp,-MT,<OBJECT> -Wp,-MF,<DEPFILE>")
+
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE NO)
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
+ set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}")
+ if(CMAKE_${lang}_COMPILER_ARG1)
+ separate_arguments(_COMPILER_ARGS NATIVE_COMMAND "${CMAKE_${lang}_COMPILER_ARG1}")
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND ${_COMPILER_ARGS})
+ unset(_COMPILER_ARGS)
+ endif()
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "-Wp,-dM" "-E" "-c" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
+
unset(CMAKE_${lang}_COMPILE_OPTIONS_IPO)
unset(CMAKE_${lang}_ARCHIVE_CREATE_IPO)
unset(CMAKE_${lang}_ARCHIVE_APPEND_IPO)
diff --git a/Modules/Compiler/SCO.cmake b/Modules/Compiler/SCO.cmake
index c55a048a5..7f643d920 100644
--- a/Modules/Compiler/SCO.cmake
+++ b/Modules/Compiler/SCO.cmake
@@ -15,4 +15,7 @@ macro(__compiler_sco lang)
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")
+
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
endmacro()
diff --git a/Modules/Compiler/SunPro-C.cmake b/Modules/Compiler/SunPro-C.cmake
index 29c2f22f9..7e962b8ee 100644
--- a/Modules/Compiler/SunPro-C.cmake
+++ b/Modules/Compiler/SunPro-C.cmake
@@ -6,6 +6,10 @@ include(Compiler/SunPro)
set(CMAKE_C_VERBOSE_FLAG "-#")
set(CMAKE_C_COMPILE_OPTIONS_PIC -KPIC)
+set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+set(CMAKE_C_LINK_OPTIONS_PIE "")
+set(CMAKE_C_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_C_FLAGS "-KPIC")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-G")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-R")
@@ -18,6 +22,8 @@ string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -xO2 -xspace -DNDEBUG")
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -xO3 -DNDEBUG")
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -g -xO2 -DNDEBUG")
+set(CMAKE_DEPFILE_FLAGS_C "-xMD -xMF <DEPFILE>")
+
# 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
@@ -27,13 +33,19 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
set(CMAKE_${type}_LINK_DYNAMIC_C_FLAGS "-Bdynamic")
endforeach()
+set(CMAKE_C_LINKER_WRAPPER_FLAG "-Qoption" "ld" " ")
+set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
+
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.13)
set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89")
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=c89")
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=c99")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=c11")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
elseif (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.11)
set(CMAKE_C90_STANDARD_COMPILE_OPTION "")
set(CMAKE_C90_EXTENSION_COMPILE_OPTION "")
diff --git a/Modules/Compiler/SunPro-CXX-FeatureTests.cmake b/Modules/Compiler/SunPro-CXX-FeatureTests.cmake
index 60280cadc..e7133c153 100644
--- a/Modules/Compiler/SunPro-CXX-FeatureTests.cmake
+++ b/Modules/Compiler/SunPro-CXX-FeatureTests.cmake
@@ -1,10 +1,22 @@
# Based on GNU 4.8.2
-# http://docs.oracle.com/cd/E37069_01/html/E37071/gncix.html
+# https://docs.oracle.com/cd/E37069_01/html/E37071/gncix.html
+# https://docs.oracle.com/cd/E77782_01/html/E77784/gkeza.html
# Reference: http://gcc.gnu.org/projects/cxx0x.html
set(_cmake_oldestSupported "__SUNPRO_CC >= 0x5130")
+set(SolarisStudio126_CXX14 "(__SUNPRO_CC >= 0x5150) && __cplusplus >= 201402L")
+set(_cmake_feature_test_cxx_aggregate_default_initializers "${SolarisStudio126_CXX14}")
+set(_cmake_feature_test_cxx_digit_separators "${SolarisStudio126_CXX14}")
+set(_cmake_feature_test_cxx_generic_lambdas "${SolarisStudio126_CXX14}")
+set(_cmake_feature_test_cxx_lambda_init_captures "${SolarisStudio126_CXX14}")
+set(_cmake_feature_test_cxx_return_type_deduction "${SolarisStudio126_CXX14}")
+set(_cmake_feature_test_cxx_variable_templates "${SolarisStudio126_CXX14}")
+
+set(SolarisStudio126_CXX11 "(__SUNPRO_CC >= 0x5150) && __cplusplus >= 201103L")
+set(_cmake_feature_test_cxx_decltype_auto "${SolarisStudio126_CXX11}")
+
set(SolarisStudio125_CXX11 "(__SUNPRO_CC >= 0x5140) && __cplusplus >= 201103L")
set(_cmake_feature_test_cxx_binary_literals "${SolarisStudio125_CXX11}")
set(_cmake_feature_test_cxx_reference_qualified_functions "${SolarisStudio125_CXX11}")
diff --git a/Modules/Compiler/SunPro-CXX.cmake b/Modules/Compiler/SunPro-CXX.cmake
index 5cb7edced..c946c6436 100644
--- a/Modules/Compiler/SunPro-CXX.cmake
+++ b/Modules/Compiler/SunPro-CXX.cmake
@@ -6,6 +6,10 @@ include(Compiler/SunPro)
set(CMAKE_CXX_VERBOSE_FLAG "-v")
set(CMAKE_CXX_COMPILE_OPTIONS_PIC -KPIC)
+set(CMAKE_CXX_COMPILE_OPTIONS_PIE "")
+set(_CMAKE_CXX_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+set(CMAKE_CXX_LINK_OPTIONS_PIE "")
+set(CMAKE_CXX_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-KPIC")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-G")
set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG "-R")
@@ -18,6 +22,8 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -xO2 -xspace -DNDEBUG")
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -xO3 -DNDEBUG")
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -g -xO2 -DNDEBUG")
+set(CMAKE_DEPFILE_FLAGS_CXX "-xMD -xMF <DEPFILE>")
+
# 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
@@ -27,6 +33,9 @@ foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS "-Bdynamic")
endforeach()
+set(CMAKE_CXX_LINKER_WRAPPER_FLAG "-Qoption" "ld" " ")
+set(CMAKE_CXX_LINKER_WRAPPER_FLAG_SEP ",")
+
set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
@@ -39,9 +48,15 @@ set(CMAKE_CXX_CREATE_STATIC_LIBRARY
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++03")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=c++03")
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=c++11")
set(CMAKE_CXX_LINK_WITH_STANDARD_COMPILE_OPTION 1)
+
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.14)
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++14")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-std=c++14")
+ endif()
else()
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-library=stlport4")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-library=stlport4")
diff --git a/Modules/Compiler/SunPro-Fortran.cmake b/Modules/Compiler/SunPro-Fortran.cmake
index 9b25c0b25..0c93c94a8 100644
--- a/Modules/Compiler/SunPro-Fortran.cmake
+++ b/Modules/Compiler/SunPro-Fortran.cmake
@@ -3,6 +3,10 @@ set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-fixed")
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-free")
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-KPIC")
+set(CMAKE_Fortran_COMPILE_OPTIONS_PIE "")
+set(_CMAKE_Fortran_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+set(CMAKE_Fortran_LINK_OPTIONS_PIE "")
+set(CMAKE_Fortran_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_Fortran_FLAGS "-KPIC")
set(CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS "-G")
set(CMAKE_SHARED_LIBRARY_RUNTIME_Fortran_FLAG "-R")
@@ -18,6 +22,9 @@ string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -g -xO2 -DNDEBUG")
set(CMAKE_Fortran_MODDIR_FLAG "-moddir=")
set(CMAKE_Fortran_MODPATH_FLAG "-M")
+set(CMAKE_Fortran_LINKER_WRAPPER_FLAG "-Qoption" "ld" " ")
+set(CMAKE_Fortran_LINKER_WRAPPER_FLAG_SEP ",")
+
set(CMAKE_Fortran_PREPROCESS_SOURCE
"<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -F -fpp <SOURCE> -o <PREPROCESSED_SOURCE>")
diff --git a/Modules/Compiler/TI-C.cmake b/Modules/Compiler/TI-C.cmake
index ebc79f424..1c0f4bc1f 100644
--- a/Modules/Compiler/TI-C.cmake
+++ b/Modules/Compiler/TI-C.cmake
@@ -2,6 +2,14 @@ set(CMAKE_LIBRARY_PATH_FLAG "--search_path=")
set(CMAKE_LINK_LIBRARY_FLAG "--library=")
set(CMAKE_INCLUDE_FLAG_C "--include_path=")
+set(CMAKE_C90_STANDARD_COMPILE_OPTION "--c89")
+set(CMAKE_C90_EXTENSION_COMPILE_OPTION "--c89 --relaxed_ansi")
+
+set(CMAKE_C99_STANDARD_COMPILE_OPTION "--c99")
+set(CMAKE_C99_EXTENSION_COMPILE_OPTION "--c99 --relaxed_ansi")
+
+set(CMAKE_DEPFILE_FLAGS_C "--preproc_with_compile --preproc_dependency=<DEPFILE>")
+
set(CMAKE_C_CREATE_ASSEMBLY_SOURCE "<CMAKE_C_COMPILER> --compile_only --skip_assembler --c_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<ASSEMBLY_SOURCE>")
set(CMAKE_C_CREATE_PREPROCESSED_SOURCE "<CMAKE_C_COMPILER> --preproc_only --c_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>")
diff --git a/Modules/Compiler/TI-CXX.cmake b/Modules/Compiler/TI-CXX.cmake
index 4104c3b18..4c6af06cd 100644
--- a/Modules/Compiler/TI-CXX.cmake
+++ b/Modules/Compiler/TI-CXX.cmake
@@ -2,6 +2,8 @@ set(CMAKE_LIBRARY_PATH_FLAG "--search_path=")
set(CMAKE_LINK_LIBRARY_FLAG "--library=")
set(CMAKE_INCLUDE_FLAG_CXX "--include_path=")
+set(CMAKE_DEPFILE_FLAGS_CXX "--preproc_with_compile --preproc_dependency=<DEPFILE>")
+
set(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE "<CMAKE_CXX_COMPILER> --compile_only --skip_assembler --cpp_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<ASSEMBLY_SOURCE>")
set(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE "<CMAKE_CXX_COMPILER> --preproc_only --cpp_file=<SOURCE> <DEFINES> <INCLUDES> <FLAGS> --output_file=<PREPROCESSED_SOURCE>")
diff --git a/Modules/Compiler/TinyCC-C.cmake b/Modules/Compiler/TinyCC-C.cmake
index fbd2841e3..6367695b9 100644
--- a/Modules/Compiler/TinyCC-C.cmake
+++ b/Modules/Compiler/TinyCC-C.cmake
@@ -6,3 +6,6 @@ string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -g")
string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -DNDEBUG")
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -g -DNDEBUG")
+
+set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl,")
+set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
diff --git a/Modules/Compiler/XL-C.cmake b/Modules/Compiler/XL-C.cmake
index 5dc8bc17f..2077bdabd 100644
--- a/Modules/Compiler/XL-C.cmake
+++ b/Modules/Compiler/XL-C.cmake
@@ -6,36 +6,18 @@ string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
# -qthreaded = Ensures that all optimizations will be thread-safe
string(APPEND CMAKE_C_FLAGS_INIT " -qthreaded")
-# XL v13.1.1 for Linux ppc64 little-endian switched to using a clang based
-# front end and accepts the -std= option while only reserving -qlanglevel= for
-# compatibility. All other versions (previous versions on Linux ppc64
-# little-endian, all versions on Linux ppc64 big-endian, all versions on AIX
-# and BGQ, etc) are derived from the UNIX compiler and only accept the
-# -qlanglvl option.
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1)
- if (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND
- CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1)
- set(CMAKE_C90_STANDARD_COMPILE_OPTION "-std=c89")
- set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-std=gnu89")
- set(CMAKE_C99_STANDARD_COMPILE_OPTION "-std=c99")
- set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-std=gnu99")
- if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.2)
- set(CMAKE_C11_STANDARD_COMPILE_OPTION "-std=c11")
- set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-std=gnu11")
- else ()
- set(CMAKE_C11_STANDARD_COMPILE_OPTION "-qlanglvl=extc1x")
- set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-qlanglvl=extc1x")
- endif ()
- else ()
- set(CMAKE_C90_STANDARD_COMPILE_OPTION "-qlanglvl=stdc89")
- set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-qlanglvl=extc89")
- set(CMAKE_C99_STANDARD_COMPILE_OPTION "-qlanglvl=stdc99")
- set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-qlanglvl=extc99")
- if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1)
- set(CMAKE_C11_STANDARD_COMPILE_OPTION "-qlanglvl=extc1x")
- set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-qlanglvl=extc1x")
- endif ()
+ set(CMAKE_C90_STANDARD_COMPILE_OPTION "-qlanglvl=stdc89")
+ set(CMAKE_C90_EXTENSION_COMPILE_OPTION "-qlanglvl=extc89")
+ set(CMAKE_C90_STANDARD__HAS_FULL_SUPPORT ON)
+ set(CMAKE_C99_STANDARD_COMPILE_OPTION "-qlanglvl=stdc99")
+ set(CMAKE_C99_EXTENSION_COMPILE_OPTION "-qlanglvl=extc99")
+ set(CMAKE_C99_STANDARD__HAS_FULL_SUPPORT ON)
+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.1)
+ set(CMAKE_C11_STANDARD_COMPILE_OPTION "-qlanglvl=extc1x")
+ set(CMAKE_C11_EXTENSION_COMPILE_OPTION "-qlanglvl=extc1x")
+ set(CMAKE_C11_STANDARD__HAS_FULL_SUPPORT ON)
endif ()
endif()
-__compiler_check_default_language_standard(C 10.1 90)
+__compiler_check_default_language_standard(C 10.1 90 11.1 99)
diff --git a/Modules/Compiler/XL-CXX.cmake b/Modules/Compiler/XL-CXX.cmake
index b87e9238b..303785112 100644
--- a/Modules/Compiler/XL-CXX.cmake
+++ b/Modules/Compiler/XL-CXX.cmake
@@ -6,41 +6,23 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
# -qthreaded = Ensures that all optimizations will be thread-safe
string(APPEND CMAKE_CXX_FLAGS_INIT " -qthreaded")
-# XL v13.1.1 for Linux ppc64 little-endian switched to using a clang based
-# front end and accepts the -std= option while only reserving -qlanglevel= for
-# compatibility. All other versions (previous versions on Linux ppc64
-# little-endian, all versions on Linux ppc64 big-endian, all versions on AIX
-# and BGQ, etc) are derived from the UNIX compiler and only accept the
-# -qlanglvl option.
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.1)
- if (CMAKE_SYSTEM MATCHES "Linux.*ppc64")
- if (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND
- CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.1)
- set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++98")
- set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++98")
- if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.1.2)
- set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++11")
- set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++11")
- set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-std=c++1y")
- set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-qlanglvl=extended1y")
- else ()
- set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x")
- set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x")
- endif ()
- else ()
- # The non-clang based Linux ppc64 compiler, both big-endian and
- # little-endian lacks, the non-extension language level flags
- set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-qlanglvl=extended")
- set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-qlanglvl=extended")
- set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x")
- set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x")
- endif ()
- else ()
+ if(CMAKE_SYSTEM MATCHES "Linux")
+ set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "")
+ set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "")
+ else()
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-qlanglvl=strict98")
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-qlanglvl=extended")
- set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x")
- set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x")
- endif ()
+ endif()
+ set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-qlanglvl=extended0x")
+ set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-qlanglvl=extended0x")
+ set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
+ set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16.1.0)
+ set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-qlanglvl=extended1y")
+ set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION "-qlanglvl=extended1y")
+ set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
+ endif()
endif ()
__compiler_check_default_language_standard(CXX 10.1 98)
diff --git a/Modules/Compiler/XL-Fortran.cmake b/Modules/Compiler/XL-Fortran.cmake
index 6bab6f69e..c4fb09712 100644
--- a/Modules/Compiler/XL-Fortran.cmake
+++ b/Modules/Compiler/XL-Fortran.cmake
@@ -1,6 +1,9 @@
include(Compiler/XL)
__compiler_xl(Fortran)
+set(CMAKE_Fortran_SUBMODULE_SEP "_")
+set(CMAKE_Fortran_SUBMODULE_EXT ".smod")
+
set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-qfixed") # [=<right_margin>]
set(CMAKE_Fortran_FORMAT_FREE_FLAG "-qfree") # [=f90|ibm]
diff --git a/Modules/Compiler/XL.cmake b/Modules/Compiler/XL.cmake
index 478378570..a9cec113f 100644
--- a/Modules/Compiler/XL.cmake
+++ b/Modules/Compiler/XL.cmake
@@ -10,16 +10,16 @@ set(__COMPILER_XL 1)
include(Compiler/CMakeCommonCompilerMacros)
-# 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}_COMPILE_OPTIONS_PIE "-qpic")
+ set(CMAKE_${lang}_RESPONSE_FILE_FLAG "-qoptfile=")
+ set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-qoptfile=")
+
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g")
string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O")
@@ -28,19 +28,5 @@ macro(__compiler_xl lang)
set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <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()
+ set(CMAKE_DEPFILE_FLAGS_${lang} "-MF <DEPFILE> -qmakedep=gcc")
endmacro()
diff --git a/Modules/CompilerId/VS-10.vcxproj.in b/Modules/CompilerId/VS-10.vcxproj.in
index 6b9b361cc..32c4ffcc4 100644
--- a/Modules/CompilerId/VS-10.vcxproj.in
+++ b/Modules/CompilerId/VS-10.vcxproj.in
@@ -15,6 +15,7 @@
@id_WindowsTargetPlatformVersion@
@id_WindowsSDKDesktopARMSupport@
</PropertyGroup>
+ @id_toolset_version_props@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup>
@id_PreferredToolArchitecture@
diff --git a/Modules/CompilerId/Xcode-3.pbxproj.in b/Modules/CompilerId/Xcode-3.pbxproj.in
index 84f48ae65..672044e13 100644
--- a/Modules/CompilerId/Xcode-3.pbxproj.in
+++ b/Modules/CompilerId/Xcode-3.pbxproj.in
@@ -58,7 +58,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "echo \"GCC_VERSION=$GCC_VERSION\" ; echo \"CURRENT_ARCH=$CURRENT_ARCH\"";
+ shellScript = "echo \"GCC_VERSION=$GCC_VERSION\" ; echo \"ARCHS=$ARCHS\"";
showEnvVarsInLog = 0;
};
2C18F0B515DC1DCE00593670 = {
@@ -72,6 +72,7 @@
1DEB928608733DD80010E9CD = {
isa = XCBuildConfiguration;
buildSettings = {
+ CODE_SIGN_IDENTITY = "";
PRODUCT_NAME = CompilerId@id_lang@;
};
name = Debug;
@@ -85,6 +86,7 @@
SYMROOT = .;
@id_toolset@
@id_lang_version@
+ @id_clang_cxx_library@
@id_deployment_target@
@id_sdkroot@
};
diff --git a/Modules/Dart.cmake b/Modules/Dart.cmake
index e003cd5cc..154fe9d7d 100644
--- a/Modules/Dart.cmake
+++ b/Modules/Dart.cmake
@@ -1,27 +1,28 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
diff --git a/Modules/DartConfiguration.tcl.in b/Modules/DartConfiguration.tcl.in
index 0ff2eed8b..e4513b363 100644
--- a/Modules/DartConfiguration.tcl.in
+++ b/Modules/DartConfiguration.tcl.in
@@ -16,18 +16,11 @@ Site: @SITE@
# Build name is osname-revision-compiler, i.e. Linux-2.4.2-2smp-c++
BuildName: @BUILDNAME@
+# Subprojects
+LabelsForSubprojects: @CTEST_LABELS_FOR_SUBPROJECTS@
+
# 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@
+SubmitURL: @SUBMIT_URL@
# Dashboard start time
NightlyStartTime: @NIGHTLY_START_TIME@
diff --git a/Modules/DeployQt4.cmake b/Modules/DeployQt4.cmake
index 8ada451a6..4a18927c2 100644
--- a/Modules/DeployQt4.cmake
+++ b/Modules/DeployQt4.cmake
@@ -1,380 +1,400 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# 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}")
+ 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)
- unset(executable_path)
- if(ARGC GREATER 1)
- set(executable_path ${ARGV1})
- endif()
-
- 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()
+ unset(executable_path)
+ if(ARGC GREATER 1)
+ set(executable_path ${ARGV1})
+ endif()
-function(fixup_qt4_executable executable)
- unset(qtplugins)
- if(ARGC GREATER 1)
- set(qtplugins ${ARGV1})
- endif()
- unset(libs)
- if(ARGC GREATER 2)
- set(libs ${ARGV2})
- endif()
- unset(dirs)
- if(ARGC GREATER 3)
- set(dirs ${ARGV3})
- endif()
- unset(plugins_dir)
- if(ARGC GREATER 4)
- set(plugins_dir ${ARGV4})
- endif()
- unset(request_qt_conf)
- if(ARGC GREATER 5)
- set(request_qt_conf ${ARGV5})
- endif()
-
- 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 DEFINED 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}")
+ 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()
+cmake_policy(GET CMP0080 _cmp0080_value)
+if(NOT DEFINED CMAKE_GENERATOR OR NOT _cmp0080_value STREQUAL "NEW")
+ set(_CMP0080_SUPPRESS_WARNING TRUE)
+ include("${CMAKE_CURRENT_LIST_DIR}/BundleUtilities.cmake")
+ unset(_CMP0080_SUPPRESS_WARNING)
+
+ function(fixup_qt4_executable executable)
+ cmake_policy(GET CMP0080 _cmp0080_value)
+ if(_cmp0080_value STREQUAL "" AND DEFINED CMAKE_GENERATOR)
+ _warn_cmp0080()
+ endif()
+
+ unset(qtplugins)
+ if(ARGC GREATER 1)
+ set(qtplugins ${ARGV1})
+ endif()
+ unset(libs)
+ if(ARGC GREATER 2)
+ set(libs ${ARGV2})
+ endif()
+ unset(dirs)
+ if(ARGC GREATER 3)
+ set(dirs ${ARGV3})
+ endif()
+ unset(plugins_dir)
+ if(ARGC GREATER 4)
+ set(plugins_dir ${ARGV4})
+ endif()
+ unset(request_qt_conf)
+ if(ARGC GREATER 5)
+ set(request_qt_conf ${ARGV5})
+ endif()
+
+ 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 DEFINED 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()
+endif()
+
function(install_qt4_plugin_path plugin executable copy installed_plugin_path_var)
- unset(plugins_dir)
- if(ARGC GREATER 4)
- set(plugins_dir ${ARGV4})
- endif()
- unset(component)
- if(ARGC GREATER 5)
- set(component ${ARGV5})
- endif()
+ unset(plugins_dir)
+ if(ARGC GREATER 4)
+ set(plugins_dir ${ARGV4})
+ endif()
+ unset(component)
+ if(ARGC GREATER 5)
+ set(component ${ARGV5})
+ endif()
+ unset(configurations)
+ if(ARGC GREATER 6)
+ set(configurations ${ARGV6})
+ endif()
+
+ 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)
+ string(APPEND 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()
+ string(APPEND plugins_path "/${plugin_group}")
+
+ if(${copy})
+ file(MAKE_DIRECTORY "${plugins_path}")
+ file(COPY "${plugin}" DESTINATION "${plugins_path}")
+ else()
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(configurations AND (_isMultiConfig OR CMAKE_BUILD_TYPE))
+ set(configurations CONFIGURATIONS ${configurations})
+ else()
unset(configurations)
- if(ARGC GREATER 6)
- set(configurations ${ARGV6})
- endif()
-
- 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)
- string(APPEND 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()
- string(APPEND 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()
+ 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)
- unset(plugins_dir)
- if(ARGC GREATER 4)
- set(plugins_dir ${ARGV4})
- endif()
- unset(component)
- if(ARGC GREATER 5)
- set(component ${ARGV5})
- endif()
-
- 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)
+ unset(plugins_dir)
+ if(ARGC GREATER 4)
+ set(plugins_dir ${ARGV4})
+ endif()
+ unset(component)
+ if(ARGC GREATER 5)
+ set(component ${ARGV5})
+ endif()
+
+ 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()
+
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(_isMultiConfig OR CMAKE_BUILD_TYPE)
+ set(_RELEASE_CONFIGS ${CMAKE_CONFIGURATION_TYPES} "${CMAKE_BUILD_TYPE}")
+ if (_RELEASE_CONFIGS)
+ list(FILTER _RELEASE_CONFIGS EXCLUDE REGEX "[Dd][Ee][Bb][Uu][Gg]")
+ endif()
+ string(REPLACE ";" "|" _RELEASE_CONFIGS "${_RELEASE_CONFIGS}")
+ install_qt4_plugin_path("${plugin_release}" "${executable}" "${copy}" "${installed_plugin_path_var}_release" "${plugins_dir}" "${component}" "${_RELEASE_CONFIGS}")
+ install_qt4_plugin_path("${plugin_debug}" "${executable}" "${copy}" "${installed_plugin_path_var}_debug" "${plugins_dir}" "${component}" "Debug")
+ unset(_RELEASE_CONFIGS)
+
+ 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)
- unset(qtplugins)
- if(ARGC GREATER 1)
- set(qtplugins ${ARGV1})
- endif()
- unset(libs)
- if(ARGC GREATER 2)
- set(libs ${ARGV2})
- endif()
- unset(dirs)
- if(ARGC GREATER 3)
- set(dirs ${ARGV3})
- endif()
- unset(plugins_dir)
- if(ARGC GREATER 4)
- set(plugins_dir ${ARGV4})
- endif()
- unset(request_qt_conf)
- if(ARGC GREATER 5)
- set(request_qt_conf ${ARGV5})
- endif()
- unset(component)
- if(ARGC GREATER 6)
- set(component ${ARGV6})
- endif()
-
- 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}
- )
+ unset(qtplugins)
+ if(ARGC GREATER 1)
+ set(qtplugins ${ARGV1})
+ endif()
+ unset(libs)
+ if(ARGC GREATER 2)
+ set(libs ${ARGV2})
+ endif()
+ unset(dirs)
+ if(ARGC GREATER 3)
+ set(dirs ${ARGV3})
+ endif()
+ unset(plugins_dir)
+ if(ARGC GREATER 4)
+ set(plugins_dir ${ARGV4})
+ endif()
+ unset(request_qt_conf)
+ if(ARGC GREATER 5)
+ set(request_qt_conf ${ARGV5})
+ endif()
+ unset(component)
+ if(ARGC GREATER 6)
+ set(component ${ARGV6})
+ endif()
+
+ 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
index fc398e6c5..aaf24f656 100644
--- a/Modules/Documentation.cmake
+++ b/Modules/Documentation.cmake
@@ -1,14 +1,13 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# Documentation
-# -------------
-#
-# DocumentationVTK.cmake
-#
-# This file provides support for the VTK documentation framework. It
-# relies on several tools (Doxygen, Perl, etc).
+#[=======================================================================[.rst:
+Documentation
+-------------
+
+This module provides support for the VTK documentation framework. It
+relies on several tools (Doxygen, Perl, etc).
+#]=======================================================================]
#
# Build the documentation ?
@@ -40,7 +39,7 @@ if (BUILD_DOCUMENTATION)
)
#
- # The documentation process is controled by a batch file.
+ # The documentation process is controlled by a batch file.
# We will probably need bash to create the custom target
#
diff --git a/Modules/ExternalData.cmake b/Modules/ExternalData.cmake
index 7331fb2b4..e5dbcd963 100644
--- a/Modules/ExternalData.cmake
+++ b/Modules/ExternalData.cmake
@@ -1133,7 +1133,7 @@ if("${ExternalData_ACTION}" STREQUAL "fetch")
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}")
+ file(TOUCH "${file}")
else()
_ExternalData_link_or_copy("${obj}" "${file}")
endif()
diff --git a/Modules/ExternalProject-download.cmake.in b/Modules/ExternalProject-download.cmake.in
index 7f92596c5..99fb91781 100644
--- a/Modules/ExternalProject-download.cmake.in
+++ b/Modules/ExternalProject-download.cmake.in
@@ -116,6 +116,8 @@ foreach(i RANGE ${retry_number})
@TLS_VERIFY_CODE@
@TLS_CAINFO_CODE@
+ @NETRC_CODE@
+ @NETRC_FILE_CODE@
file(
DOWNLOAD
diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake
index 24957363e..20b37d222 100644
--- a/Modules/ExternalProject.cmake
+++ b/Modules/ExternalProject.cmake
@@ -5,413 +5,935 @@
ExternalProject
---------------
-Create custom targets to build projects in external trees
+.. only:: html
+
+ .. contents::
+
+External Project Definition
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. command:: ExternalProject_Add
- The ``ExternalProject_Add`` function creates a custom target to drive
+ The ``ExternalProject_Add()`` function creates a custom target to drive
download, update/patch, configure, build, install and test steps of an
- external project::
-
- ExternalProject_Add(<name> [<option>...])
-
- General options are:
-
- ``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 options are:
-
- ``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 <username>``
- Username for Subversion checkout and update
- ``SVN_PASSWORD <password>``
- 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_REMOTE_NAME <name>``
- The optional name of the remote, default to ``origin``
- ``GIT_SUBMODULES <module>...``
- Git submodules that shall be updated, all if empty
- ``GIT_SHALLOW 1``
- Tell Git to clone with ``--depth 1``. Use when ``GIT_TAG`` is not
- specified or when it names a branch in order to download only the
- tip of the branch without the rest of its history.
- ``GIT_PROGRESS 1``
- Tell Git to clone with ``--progress``. For large projects, the clone step
- does not output anything which can make the build appear to have stalled.
- This option forces Git to output progress information during the clone step
- so that forward progress is indicated.
- ``GIT_CONFIG <option>...``
- Tell Git to clone with ``--config <option>``. Use additional configuration
- parameters when cloning the project (``key=value`` as expected by ``git
- config``).
- ``HG_REPOSITORY <url>``
- URL of mercurial repo
- ``HG_TAG <tag>``
- Mercurial branch name, commit id or tag
- ``URL /.../src.tgz [/.../src.tgz]...``
- Full path or URL(s) of source. Multiple URLs are allowed as mirrors.
- ``URL_HASH ALGO=value``
- Hash of file at URL
- ``URL_MD5 md5``
- Equivalent to URL_HASH MD5=md5
- ``HTTP_USERNAME <username>``
- Username for download operation
- ``HTTP_PASSWORD <username>``
- Password for download operation
- ``HTTP_HEADER <header>``
- HTTP header for download operation. Suboption can be repeated several times.
- ``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
- ``DOWNLOAD_NO_EXTRACT 1``
- Just download the file and do not extract it; the full path to the
- downloaded file is available as ``<DOWNLOADED_FILE>``.
-
- Update/Patch step options are:
-
- ``UPDATE_COMMAND <cmd>...``
- Source work-tree update command
- ``UPDATE_DISCONNECTED 1``
- Never update automatically from the remote repository
- ``PATCH_COMMAND <cmd>...``
- Command to patch downloaded source
-
- Configure step options are:
-
- ``SOURCE_DIR <dir>``
- Source dir to be used for build
- ``SOURCE_SUBDIR <dir>``
- Path to source CMakeLists.txt relative to ``SOURCE_DIR``
- ``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 <platform>``
- Generator-specific platform name
- ``CMAKE_GENERATOR_TOOLSET <toolset>``
- Generator-specific toolset name
- ``CMAKE_ARGS <arg>...``
- Arguments to CMake command line.
- These arguments are passed to CMake command line, and can contain
- arguments other than cache values, see also
- :manual:`CMake Options <cmake(1)>`. Arguments in the form
- ``-Dvar:string=on`` are always passed to the command line, and
- therefore cannot be changed by the user.
- Arguments may use
- :manual:`generator expressions <cmake-generator-expressions(7)>`.
- ``CMAKE_CACHE_ARGS <arg>...``
- Initial cache arguments, of the form ``-Dvar:string=on``.
- These arguments are written in a pre-load a script that populates
- CMake cache, see also :manual:`cmake -C <cmake(1)>`. This allows one to
- overcome command line length limits.
- These arguments are :command:`set` using the ``FORCE`` argument,
- and therefore cannot be changed by the user.
- Arguments may use
- :manual:`generator expressions <cmake-generator-expressions(7)>`.
- ``CMAKE_CACHE_DEFAULT_ARGS <arg>...``
- Initial default cache arguments, of the form ``-Dvar:string=on``.
- These arguments are written in a pre-load a script that populates
- CMake cache, see also :manual:`cmake -C <cmake(1)>`. This allows one to
- overcome command line length limits.
- These arguments can be used as default value that will be set if no
- previous value is found in the cache, and that the user can change
- later.
- Arguments may use
- :manual:`generator expressions <cmake-generator-expressions(7)>`.
-
- Build step options are:
-
- ``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
- ``BUILD_BYPRODUCTS <file>...``
- Files that will be generated by the build command but may or may
- not have their modification time updated by subsequent builds.
-
- Install step options are:
-
- ``INSTALL_DIR <dir>``
- Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder.
- This does not actually configure the external project to install to
- the given prefix. That must be done by passing appropriate arguments
- to the external project configuration step, e.g. using ``<INSTALL_DIR>``.
- ``INSTALL_COMMAND <cmd>...``
- Command to drive installation of the external project after it has been
- built. This only happens at the *build* time of the calling project.
- In order to install files from the external project alongside the
- locally-built files, a separate local :command:`install` call must be
- added to pick the files up from one of the external project trees.
-
- Test step options are:
-
- ``TEST_BEFORE_INSTALL 1``
- Add test step executed before install step
- ``TEST_AFTER_INSTALL 1``
- Add test step executed after install step
- ``TEST_EXCLUDE_FROM_MAIN 1``
- Main target does not depend on the test step
- ``TEST_COMMAND <cmd>...``
- Command to drive test
-
- Output logging options are:
-
- ``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
-
- Steps can be given direct access to the terminal if possible. With
- the :generator:`Ninja` generator, this places the steps in the
- ``console`` :prop_gbl:`pool <JOB_POOLS>`. Options are:
-
- ``USES_TERMINAL_DOWNLOAD 1``
- Give download terminal access.
- ``USES_TERMINAL_UPDATE 1``
- Give update terminal access.
- ``USES_TERMINAL_CONFIGURE 1``
- Give configure terminal access.
- ``USES_TERMINAL_BUILD 1``
- Give build terminal access.
- ``USES_TERMINAL_TEST 1``
- Give test terminal access.
- ``USES_TERMINAL_INSTALL 1``
- Give install terminal access.
-
- Other options are:
-
- ``STEP_TARGETS <step-target>...``
- Generate custom targets for these steps
- ``INDEPENDENT_STEP_TARGETS <step-target>...``
- Generate custom targets for these steps that do not depend on other
- external projects even if a dependency is set
-
- 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_SUBDIR`` is set and no ``CONFIGURE_COMMAND`` is specified, the
- configure command will run CMake using the ``CMakeLists.txt`` located in the
- relative path specified by ``SOURCE_SUBDIR``, relative to the ``SOURCE_DIR``.
- If no ``SOURCE_SUBDIR`` is given, ``SOURCE_DIR`` is used.
-
- 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``).
-
- If ``UPDATE_DISCONNECTED`` is set, the update step is not executed
- automatically when building the main target. The update step can still
- be added as a step target and called manually. This is useful if you
- want to allow one to build the project when you are disconnected from the
- network (you might still need the network for the download step).
- This is disabled by default.
- The directory property ``EP_UPDATE_DISCONNECTED`` can be used to change
- the default value for all the external projects in the current
- directory and its subdirectories.
+ external project:
+
+ .. code-block:: cmake
+
+ ExternalProject_Add(<name> [<option>...])
+
+ The individual steps within the process can be driven independently if
+ required (e.g. for CDash submission) and extra custom steps can be defined,
+ along with the ability to control the step dependencies. The directory
+ structure used for the management of the external project can also be
+ customized. The function supports a large number of options which can be used
+ to tailor the external project behavior.
+
+ **Directory Options:**
+ Most of the time, the default directory layout is sufficient. It is largely
+ an implementation detail that the main project usually doesn't need to
+ change. In some circumstances, however, control over the directory layout
+ can be useful or necessary. The directory options are potentially more
+ useful from the point of view that the main build can use the
+ :command:`ExternalProject_Get_Property` command to retrieve their values,
+ thereby allowing the main project to refer to build artifacts of the
+ external project.
+
+ ``PREFIX <dir>``
+ Root directory for the external project. Unless otherwise noted below,
+ all other directories associated with the external project will be
+ created under here.
+
+ ``TMP_DIR <dir>``
+ Directory in which to store temporary files.
+
+ ``STAMP_DIR <dir>``
+ Directory in which to store the timestamps of each step. Log files from
+ individual steps are also created in here unless overriden by LOG_DIR
+ (see *Logging Options* below).
+
+ ``LOG_DIR <dir>``
+ Directory in which to store the logs of each step.
+
+ ``DOWNLOAD_DIR <dir>``
+ Directory in which to store downloaded files before unpacking them. This
+ directory is only used by the URL download method, all other download
+ methods use ``SOURCE_DIR`` directly instead.
+
+ ``SOURCE_DIR <dir>``
+ Source directory into which downloaded contents will be unpacked, or for
+ non-URL download methods, the directory in which the repository should be
+ checked out, cloned, etc. If no download method is specified, this must
+ point to an existing directory where the external project has already
+ been unpacked or cloned/checked out.
+
+ .. note::
+ If a download method is specified, any existing contents of the source
+ directory may be deleted. Only the URL download method checks whether
+ this directory is either missing or empty before initiating the
+ download, stopping with an error if it is not empty. All other
+ download methods silently discard any previous contents of the source
+ directory.
+
+ ``BINARY_DIR <dir>``
+ Specify the build directory location. This option is ignored if
+ ``BUILD_IN_SOURCE`` is enabled.
+
+ ``INSTALL_DIR <dir>``
+ Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder.
+ This does not actually configure the external project to install to
+ the given prefix. That must be done by passing appropriate arguments
+ to the external project configuration step, e.g. using ``<INSTALL_DIR>``.
+
+ If any of the above ``..._DIR`` options are not specified, their defaults
+ are computed as follows. If the ``PREFIX`` option is given 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>
+ LOG_DIR = <STAMP_DIR>
+
+ 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>
+ LOG_DIR = <STAMP_DIR>
+
+ 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 :variable:`CMAKE_CURRENT_BINARY_DIR` at the
+ point where ``ExternalProject_Add()`` is called.
+
+ **Download Step Options:**
+ A download method can be omitted if the ``SOURCE_DIR`` option is used to
+ point to an existing non-empty directory. Otherwise, one of the download
+ methods below must be specified (multiple download methods should not be
+ given) or a custom ``DOWNLOAD_COMMAND`` provided.
+
+ ``DOWNLOAD_COMMAND <cmd>...``
+ Overrides the command used for the download step
+ (:manual:`generator expressions <cmake-generator-expressions(7)>` are
+ supported). If this option is specified, all other download options will
+ be ignored. Providing an empty string for ``<cmd>`` effectively disables
+ the download step.
+
+ *URL Download*
+ ``URL <url1> [<url2>...]``
+ List of paths and/or URL(s) of the external project's source. When more
+ than one URL is given, they are tried in turn until one succeeds. A URL
+ may be an ordinary path in the local file system (in which case it
+ must be the only URL provided) or any downloadable URL supported by the
+ :command:`file(DOWNLOAD)` command. A local filesystem path may refer to
+ either an existing directory or to an archive file, whereas a URL is
+ expected to point to a file which can be treated as an archive. When an
+ archive is used, it will be unpacked automatically unless the
+ ``DOWNLOAD_NO_EXTRACT`` option is set to prevent it. The archive type
+ is determined by inspecting the actual content rather than using logic
+ based on the file extension.
+
+ ``URL_HASH <algo>=<hashValue>``
+ Hash of the archive file to be downloaded. The argument should be of
+ the form ``<algo>=<hashValue>`` where ``algo`` can be any of the hashing
+ algorithms supported by the :command:`file()` command. Specifying this
+ option is strongly recommended for URL downloads, as it ensures the
+ integrity of the downloaded content. It is also used as a check for a
+ previously downloaded file, allowing connection to the remote location
+ to be avoided altogether if the local directory already has a file from
+ an earlier download that matches the specified hash.
+
+ ``URL_MD5 <md5>``
+ Equivalent to ``URL_HASH MD5=<md5>``.
+
+ ``DOWNLOAD_NAME <fname>``
+ File name to use for the downloaded file. If not given, the end of the
+ URL is used to determine the file name. This option is rarely needed,
+ the default name is generally suitable and is not normally used outside
+ of code internal to the ``ExternalProject`` module.
+
+ ``DOWNLOAD_NO_EXTRACT <bool>``
+ Allows the extraction part of the download step to be disabled by
+ passing a boolean true value for this option. If this option is not
+ given, the downloaded contents will be unpacked automatically if
+ required. If extraction has been disabled, the full path to the
+ downloaded file is available as ``<DOWNLOADED_FILE>`` in subsequent
+ steps or as the property ``DOWNLOADED_FILE`` with the
+ :command:`ExternalProject_Get_Property` command.
+
+ ``DOWNLOAD_NO_PROGRESS <bool>``
+ Can be used to disable logging the download progress. If this option is
+ not given, download progress messages will be logged.
+
+ ``TIMEOUT <seconds>``
+ Maximum time allowed for file download operations.
+
+ ``HTTP_USERNAME <username>``
+ Username for the download operation if authentication is required.
+
+ ``HTTP_PASSWORD <password>``
+ Password for the download operation if authentication is required.
+
+ ``HTTP_HEADER <header1> [<header2>...]``
+ Provides an arbitrary list of HTTP headers for the download operation.
+ This can be useful for accessing content in systems like AWS, etc.
+
+ ``TLS_VERIFY <bool>``
+ Specifies whether certificate verification should be performed for
+ https URLs. If this option is not provided, the default behavior is
+ determined by the ``CMAKE_TLS_VERIFY`` variable (see
+ :command:`file(DOWNLOAD)`). If that is also not set, certificate
+ verification will not be performed. In situations where ``URL_HASH``
+ cannot be provided, this option can be an alternative verification
+ measure.
+
+ ``TLS_CAINFO <file>``
+ Specify a custom certificate authority file to use if ``TLS_VERIFY``
+ is enabled. If this option is not specified, the value of the
+ ``CMAKE_TLS_CAINFO`` variable will be used instead (see
+ :command:`file(DOWNLOAD)`)
+
+ ``NETRC <level>``
+ Specify whether the ``.netrc`` file is to be used for operation.
+ If this option is not specified, the value of the ``CMAKE_NETRC``
+ variable will be used instead (see :command:`file(DOWNLOAD)`)
+ Valid levels are:
+
+ ``IGNORED``
+ The ``.netrc`` file is ignored.
+ This is the default.
+ ``OPTIONAL``
+ The ``.netrc`` file is optional, and information in the URL
+ is preferred. The file will be scanned to find which ever
+ information is not specified in the URL.
+ ``REQUIRED``
+ The ``.netrc`` file is required, and information in the URL
+ is ignored.
+
+ ``NETRC_FILE <file>``
+ Specify an alternative ``.netrc`` file to the one in your home directory
+ if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option
+ is not specified, the value of the ``CMAKE_NETRC_FILE`` variable will
+ be used instead (see :command:`file(DOWNLOAD)`)
+
+ *Git*
+ NOTE: A git version of 1.6.5 or later is required if this download method
+ is used.
+
+ ``GIT_REPOSITORY <url>``
+ URL of the git repository. Any URL understood by the ``git`` command
+ may be used.
+
+ ``GIT_TAG <tag>``
+ Git branch name, tag or commit hash. Note that branch names and tags
+ should generally be specified as remote names (i.e. ``origin/myBranch``
+ rather than simply ``myBranch``). This ensures that if the remote end
+ has its tag moved or branch rebased or history rewritten, the local
+ clone will still be updated correctly. In general, however, specifying
+ a commit hash should be preferred for a number of reasons:
+
+ - If the local clone already has the commit corresponding to the hash,
+ no ``git fetch`` needs to be performed to check for changes each time
+ CMake is re-run. This can result in a significant speed up if many
+ external projects are being used.
+ - Using a specific git hash ensures that the main project's own history
+ is fully traceable to a specific point in the external project's
+ evolution. If a branch or tag name is used instead, then checking out
+ a specific commit of the main project doesn't necessarily pin the
+ whole build to a specific point in the life of the external project.
+ The lack of such deterministic behavior makes the main project lose
+ traceability and repeatability.
+
+ If ``GIT_SHALLOW`` is enabled then ``GIT_TAG`` works only with
+ branch names and tags. A commit hash is not allowed.
+
+ ``GIT_REMOTE_NAME <name>``
+ The optional name of the remote. If this option is not specified, it
+ defaults to ``origin``.
+
+ ``GIT_SUBMODULES <module>...``
+ Specific git submodules that should also be updated. If this option is
+ not provided, all git submodules will be updated.
+
+ ``GIT_SHALLOW <bool>``
+ When this option is enabled, the ``git clone`` operation will be given
+ the ``--depth 1`` option. This performs a shallow clone, which avoids
+ downloading the whole history and instead retrieves just the commit
+ denoted by the ``GIT_TAG`` option.
+
+ ``GIT_PROGRESS <bool>``
+ When enabled, this option instructs the ``git clone`` operation to
+ report its progress by passing it the ``--progress`` option. Without
+ this option, the clone step for large projects may appear to make the
+ build stall, since nothing will be logged until the clone operation
+ finishes. While this option can be used to provide progress to prevent
+ the appearance of the build having stalled, it may also make the build
+ overly noisy if lots of external projects are used.
+
+ ``GIT_CONFIG <option1> [<option2>...]``
+ Specify a list of config options to pass to ``git clone``. Each option
+ listed will be transformed into its own ``--config <option>`` on the
+ ``git clone`` command line, with each option required to be in the
+ form ``key=value``.
+
+ *Subversion*
+ ``SVN_REPOSITORY <url>``
+ URL of the Subversion repository.
+
+ ``SVN_REVISION -r<rev>``
+ Revision to checkout from the Subversion repository.
+
+ ``SVN_USERNAME <username>``
+ Username for the Subversion checkout and update.
+
+ ``SVN_PASSWORD <password>``
+ Password for the Subversion checkout and update.
+
+ ``SVN_TRUST_CERT <bool>``
+ Specifies whether to trust the Subversion server site certificate. If
+ enabled, the ``--trust-server-cert`` option is passed to the ``svn``
+ checkout and update commands.
+
+ *Mercurial*
+ ``HG_REPOSITORY <url>``
+ URL of the mercurial repository.
+
+ ``HG_TAG <tag>``
+ Mercurial branch name, tag or commit id.
+
+ *CVS*
+ ``CVS_REPOSITORY <cvsroot>``
+ CVSROOT of the CVS repository.
+
+ ``CVS_MODULE <mod>``
+ Module to checkout from the CVS repository.
+
+ ``CVS_TAG <tag>``
+ Tag to checkout from the CVS repository.
+
+ **Update/Patch Step Options:**
+ Whenever CMake is re-run, by default the external project's sources will be
+ updated if the download method supports updates (e.g. a git repository
+ would be checked if the ``GIT_TAG`` does not refer to a specific commit).
+
+ ``UPDATE_COMMAND <cmd>...``
+ Overrides the download method's update step with a custom command.
+ The command may use
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+ ``UPDATE_DISCONNECTED <bool>``
+ When enabled, this option causes the update step to be skipped. It does
+ not, however, prevent the download step. The update step can still be
+ added as a step target (see :command:`ExternalProject_Add_StepTargets`)
+ and called manually. This is useful if you want to allow developers to
+ build the project when disconnected from the network (the network may
+ still be needed for the download step though).
+
+ When this option is present, it is generally advisable to make the value
+ a cache variable under the developer's control rather than hard-coding
+ it. If this option is not present, the default value is taken from the
+ ``EP_UPDATE_DISCONNECTED`` directory property. If that is also not
+ defined, updates are performed as normal. The ``EP_UPDATE_DISCONNECTED``
+ directory property is intended as a convenience for controlling the
+ ``UPDATE_DISCONNECTED`` behavior for an entire section of a project's
+ directory hierarchy and may be a more convenient method of giving
+ developers control over whether or not to perform updates (assuming the
+ project also provides a cache variable or some other convenient method
+ for setting the directory property).
+
+ ``PATCH_COMMAND <cmd>...``
+ Specifies a custom command to patch the sources after an update. By
+ default, no patch command is defined. Note that it can be quite difficult
+ to define an appropriate patch command that performs robustly, especially
+ for download methods such as git where changing the ``GIT_TAG`` will not
+ discard changes from a previous patch, but the patch command will be
+ called again after updating to the new tag.
+
+ **Configure Step Options:**
+ The configure step is run after the download and update steps. By default,
+ the external project is assumed to be a CMake project, but this can be
+ overridden if required.
+
+ ``CONFIGURE_COMMAND <cmd>...``
+ The default configure command runs CMake with options based on the main
+ project. For non-CMake external projects, the ``CONFIGURE_COMMAND``
+ option must be used to override this behavior
+ (:manual:`generator expressions <cmake-generator-expressions(7)>` are
+ supported). For projects that require no configure step, specify this
+ option with an empty string as the command to execute.
+
+ ``CMAKE_COMMAND /.../cmake``
+ Specify an alternative cmake executable for the configure step (use an
+ absolute path). This is generally not recommended, since it is
+ usually desirable to use the same CMake version throughout the whole
+ build. This option is ignored if a custom configure command has been
+ specified with ``CONFIGURE_COMMAND``.
+
+ ``CMAKE_GENERATOR <gen>``
+ Override the CMake generator used for the configure step. Without this
+ option, the same generator as the main build will be used. This option is
+ ignored if a custom configure command has been specified with the
+ ``CONFIGURE_COMMAND`` option.
+
+ ``CMAKE_GENERATOR_PLATFORM <platform>``
+ Pass a generator-specific platform name to the CMake command (see
+ :variable:`CMAKE_GENERATOR_PLATFORM`). It is an error to provide this
+ option without the ``CMAKE_GENERATOR`` option.
+
+ ``CMAKE_GENERATOR_TOOLSET <toolset>``
+ Pass a generator-specific toolset name to the CMake command (see
+ :variable:`CMAKE_GENERATOR_TOOLSET`). It is an error to provide this
+ option without the ``CMAKE_GENERATOR`` option.
+
+ ``CMAKE_GENERATOR_INSTANCE <instance>``
+ Pass a generator-specific instance selection to the CMake command (see
+ :variable:`CMAKE_GENERATOR_INSTANCE`). It is an error to provide this
+ option without the ``CMAKE_GENERATOR`` option.
+
+ ``CMAKE_ARGS <arg>...``
+ The specified arguments are passed to the ``cmake`` command line. They
+ can be any argument the ``cmake`` command understands, not just cache
+ values defined by ``-D...`` arguments (see also
+ :manual:`CMake Options <cmake(1)>`). In addition, arguments may use
+ :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+ ``CMAKE_CACHE_ARGS <arg>...``
+ This is an alternate way of specifying cache variables where command line
+ length issues may become a problem. The arguments are expected to be in
+ the form ``-Dvar:STRING=value``, which are then transformed into
+ CMake :command:`set` commands with the ``FORCE`` option used. These
+ ``set()`` commands are written to a pre-load script which is then applied
+ using the :manual:`cmake -C <cmake(1)>` command line option. Arguments
+ may use :manual:`generator expressions <cmake-generator-expressions(7)>`.
+
+ ``CMAKE_CACHE_DEFAULT_ARGS <arg>...``
+ This is the same as the ``CMAKE_CACHE_ARGS`` option except the ``set()``
+ commands do not include the ``FORCE`` keyword. This means the values act
+ as initial defaults only and will not override any variables already set
+ from a previous run. Use this option with care, as it can lead to
+ different behavior depending on whether the build starts from a fresh
+ build directory or re-uses previous build contents.
+
+ If the CMake generator is the ``Green Hills MULTI`` and not overridden then
+ the orginal projects settings for the GHS toolset and target system
+ customization cache variables are propagated into the external project.
+
+ ``SOURCE_SUBDIR <dir>``
+ When no ``CONFIGURE_COMMAND`` option is specified, the configure step
+ assumes the external project has a ``CMakeLists.txt`` file at the top of
+ its source tree (i.e. in ``SOURCE_DIR``). The ``SOURCE_SUBDIR`` option
+ can be used to point to an alternative directory within the source tree
+ to use as the top of the CMake source tree instead. This must be a
+ relative path and it will be interpreted as being relative to
+ ``SOURCE_DIR``. When ``BUILD_IN_SOURCE 1`` is specified, the
+ ``BUILD_COMMAND`` is used to point to an alternative directory within the
+ source tree.
+
+ **Build Step Options:**
+ If the configure step assumed the external project uses CMake as its build
+ system, the build step will also. Otherwise, the build step will assume a
+ Makefile-based build and simply run ``make`` with no arguments as the
+ default build step. This can be overridden with custom build commands if
+ required.
+
+ ``BUILD_COMMAND <cmd>...``
+ Overrides the default build command
+ (:manual:`generator expressions <cmake-generator-expressions(7)>` are
+ supported). If this option is not given, the default build command will
+ be chosen to integrate with the main build in the most appropriate way
+ (e.g. using recursive ``make`` for Makefile generators or
+ ``cmake --build`` if the project uses a CMake build). This option can be
+ specified with an empty string as the command to make the build step do
+ nothing.
+
+ ``BUILD_IN_SOURCE <bool>``
+ When this option is enabled, the build will be done directly within the
+ external project's source tree. This should generally be avoided, the use
+ of a separate build directory is usually preferred, but it can be useful
+ when the external project assumes an in-source build. The ``BINARY_DIR``
+ option should not be specified if building in-source.
+
+ ``BUILD_ALWAYS <bool>``
+ Enabling this option forces the build step to always be run. This can be
+ the easiest way to robustly ensure that the external project's own build
+ dependencies are evaluated rather than relying on the default
+ success timestamp-based method. This option is not normally needed unless
+ developers are expected to modify something the external project's build
+ depends on in a way that is not detectable via the step target
+ dependencies (e.g. ``SOURCE_DIR`` is used without a download method and
+ developers might modify the sources in ``SOURCE_DIR``).
+
+ ``BUILD_BYPRODUCTS <file>...``
+ Specifies files that will be generated by the build command but which
+ might or might not have their modification time updated by subsequent
+ builds. These ultimately get passed through as ``BYPRODUCTS`` to the
+ build step's own underlying call to :command:`add_custom_command`.
+
+ **Install Step Options:**
+ If the configure step assumed the external project uses CMake as its build
+ system, the install step will also. Otherwise, the install step will assume
+ a Makefile-based build and simply run ``make install`` as the default build
+ step. This can be overridden with custom install commands if required.
+
+ ``INSTALL_COMMAND <cmd>...``
+ The external project's own install step is invoked as part of the main
+ project's *build*. It is done after the external project's build step
+ and may be before or after the external project's test step (see the
+ ``TEST_BEFORE_INSTALL`` option below). The external project's install
+ rules are not part of the main project's install rules, so if anything
+ from the external project should be installed as part of the main build,
+ these need to be specified in the main build as additional
+ :command:`install` commands. The default install step builds the
+ ``install`` target of the external project, but this can be overridden
+ with a custom command using this option
+ (:manual:`generator expressions <cmake-generator-expressions(7)>` are
+ supported). Passing an empty string as the ``<cmd>`` makes the install
+ step do nothing.
+
+ **Test Step Options:**
+ The test step is only defined if at least one of the following ``TEST_...``
+ options are provided.
+
+ ``TEST_COMMAND <cmd>...``
+ Overrides the default test command
+ (:manual:`generator expressions <cmake-generator-expressions(7)>` are
+ supported). If this option is not given, the default behavior of the test
+ step is to build the external project's own ``test`` target. This option
+ can be specified with ``<cmd>`` as an empty string, which allows the test
+ step to still be defined, but it will do nothing. Do not specify any of
+ the other ``TEST_...`` options if providing an empty string as the test
+ command, but prefer to omit all ``TEST_...`` options altogether if the
+ test step target is not needed.
+
+ ``TEST_BEFORE_INSTALL <bool>``
+ When this option is enabled, the test step will be executed before the
+ install step. The default behavior is for the test step to run after the
+ install step.
+
+ ``TEST_AFTER_INSTALL <bool>``
+ This option is mainly useful as a way to indicate that the test step is
+ desired but all default behavior is sufficient. Specifying this option
+ with a boolean true value ensures the test step is defined and that it
+ comes after the install step. If both ``TEST_BEFORE_INSTALL`` and
+ ``TEST_AFTER_INSTALL`` are enabled, the latter is silently ignored.
+
+ ``TEST_EXCLUDE_FROM_MAIN <bool>``
+ If enabled, the main build's default ALL target will not depend on the
+ test step. This can be a useful way of ensuring the test step is defined
+ but only gets invoked when manually requested.
+
+ **Output Logging Options:**
+ Each of the following ``LOG_...`` options can be used to wrap the relevant
+ step in a script to capture its output to files. The log files will be
+ created in ``LOG_DIR`` if supplied or otherwise the ``STAMP_DIR``
+ directory with step-specific file names.
+
+ ``LOG_DOWNLOAD <bool>``
+ When enabled, the output of the download step is logged to files.
+
+ ``LOG_UPDATE <bool>``
+ When enabled, the output of the update step is logged to files.
+
+ ``LOG_PATCH <bool>``
+ When enabled, the output of the patch step is logged to files.
+
+ ``LOG_CONFIGURE <bool>``
+ When enabled, the output of the configure step is logged to files.
+
+ ``LOG_BUILD <bool>``
+ When enabled, the output of the build step is logged to files.
+
+ ``LOG_INSTALL <bool>``
+ When enabled, the output of the install step is logged to files.
+
+ ``LOG_TEST <bool>``
+ When enabled, the output of the test step is logged to files.
+
+ ``LOG_MERGED_STDOUTERR <bool>``
+ When enabled, stdout and stderr will be merged for any step whose
+ output is being logged to files.
+
+ ``LOG_OUTPUT_ON_FAILURE <bool>``
+ This option only has an effect if at least one of the other ``LOG_<step>``
+ options is enabled. If an error occurs for a step which has logging to
+ file enabled, that step's output will be printed to the console if
+ ``LOG_OUTPUT_ON_FAILURE`` is set to true. For cases where a large amount
+ of output is recorded, just the end of that output may be printed to the
+ console.
+
+ **Terminal Access Options:**
+ Steps can be given direct access to the terminal in some cases. Giving a
+ step access to the terminal may allow it to receive terminal input if
+ required, such as for authentication details not provided by other options.
+ With the :generator:`Ninja` generator, these options place the steps in the
+ ``console`` :prop_gbl:`job pool <JOB_POOLS>`. Each step can be given access
+ to the terminal individually via the following options:
+
+ ``USES_TERMINAL_DOWNLOAD <bool>``
+ Give the download step access to the terminal.
+
+ ``USES_TERMINAL_UPDATE <bool>``
+ Give the update step access to the terminal.
+
+ ``USES_TERMINAL_CONFIGURE <bool>``
+ Give the configure step access to the terminal.
+
+ ``USES_TERMINAL_BUILD <bool>``
+ Give the build step access to the terminal.
+
+ ``USES_TERMINAL_INSTALL <bool>``
+ Give the install step access to the terminal.
+
+ ``USES_TERMINAL_TEST <bool>``
+ Give the test step access to the terminal.
+
+ **Target Options:**
+ ``DEPENDS <targets>...``
+ Specify other targets on which the external project depends. The other
+ targets will be brought up to date before any of the external project's
+ steps are executed. Because the external project uses additional custom
+ targets internally for each step, the ``DEPENDS`` option is the most
+ convenient way to ensure all of those steps depend on the other targets.
+ Simply doing
+ :command:`add_dependencies(\<name\> \<targets\>) <add_dependencies>` will
+ not make any of the steps dependent on ``<targets>``.
+
+ ``EXCLUDE_FROM_ALL <bool>``
+ When enabled, this option excludes the external project from the default
+ ALL target of the main build.
+
+ ``STEP_TARGETS <step-target>...``
+ Generate custom targets for the specified steps. This is required if the
+ steps need to be triggered manually or if they need to be used as
+ dependencies of other targets. If this option is not specified, the
+ default value is taken from the ``EP_STEP_TARGETS`` directory property.
+ See :command:`ExternalProject_Add_Step` below for further discussion of
+ the effects of this option.
+
+ ``INDEPENDENT_STEP_TARGETS <step-target>...``
+ Generate custom targets for the specified steps and prevent these targets
+ from having the usual dependencies applied to them. If this option is not
+ specified, the default value is taken from the
+ ``EP_INDEPENDENT_STEP_TARGETS`` directory property. This option is mostly
+ useful for allowing individual steps to be driven independently, such as
+ for a CDash setup where each step should be initiated and reported
+ individually rather than as one whole build. See
+ :command:`ExternalProject_Add_Step` below for further discussion of the
+ effects of this option.
+
+ **Miscellaneous Options:**
+ ``LIST_SEPARATOR <sep>``
+ For any of the various ``..._COMMAND`` options, replace ``;`` with
+ ``<sep>`` in the specified command lines. This can be useful where list
+ variables may be given in commands where they should end up as
+ space-separated arguments (``<sep>`` would be a single space character
+ string in this case).
+
+ ``COMMAND <cmd>...``
+ Any of the other ``..._COMMAND`` options can have additional commands
+ appended to them by following them with as many ``COMMAND ...`` options
+ as needed
+ (:manual:`generator expressions <cmake-generator-expressions(7)>` are
+ supported). For example:
+
+ .. code-block:: cmake
+
+ ExternalProject_Add(example
+ ... # Download options, etc.
+ BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting $<CONFIG> build"
+ COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG>
+ COMMAND ${CMAKE_COMMAND} -E echo "$<CONFIG> build complete"
+ )
+
+ It should also be noted that each build step is created via a call to
+ :command:`ExternalProject_Add_Step`. See that command's documentation for the
+ automatic substitutions that are supported for some options.
+
+Obtaining Project Properties
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. command:: ExternalProject_Get_Property
+
+ The ``ExternalProject_Get_Property()`` function retrieves external project
+ target properties:
+
+ .. code-block:: cmake
+
+ ExternalProject_Get_Property(<name> <prop1> [<prop2>...])
+
+ The function stores property values in variables of the same name. Property
+ names correspond to the keyword argument names of ``ExternalProject_Add()``.
+ For example, the source directory might be retrieved like so:
+
+ .. code-block:: cmake
+
+ ExternalProject_Get_property(myExtProj SOURCE_DIR)
+ message("Source dir of myExtProj = ${SOURCE_DIR}")
+
+Explicit Step Management
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+The ``ExternalProject_Add()`` function on its own is often sufficient for
+incorporating an external project into the main build. Certain scenarios
+require additional work to implement desired behavior, such as adding in a
+custom step or making steps available as manually triggerable targets. The
+``ExternalProject_Add_Step()``, ``ExternalProject_Add_StepTargets()`` and
+``ExternalProject_Add_StepDependencies`` functions provide the lower level
+control needed to implement such step-level capabilities.
.. command:: ExternalProject_Add_Step
- The ``ExternalProject_Add_Step`` function adds a custom step to an
- external project::
+ The ``ExternalProject_Add_Step()`` function specifies an additional custom
+ step for an external project defined by an earlier call to
+ :command:`ExternalProject_Add`:
+
+ .. code-block:: cmake
- ExternalProject_Add_Step(<name> <step> [<option>...])
+ ExternalProject_Add_Step(<name> <step> [<option>...])
- Options are:
+ ``<name>`` is the same as the name passed to the original call to
+ :command:`ExternalProject_Add`. The specified ``<step>`` must not be one of
+ the pre-defined steps (``mkdir``, ``download``, ``update``, ``skip-update``,
+ ``patch``, ``configure``, ``build``, ``install`` or ``test``). The supported
+ options are:
``COMMAND <cmd>...``
- Command line invoked by this step
+ The command line to be executed by this custom step
+ (:manual:`generator expressions <cmake-generator-expressions(7)>` are
+ supported). This option can be repeated multiple times to specify multiple
+ commands to be executed in order.
+
``COMMENT "<text>..."``
- Text printed when step executes
+ Text to be printed when the custom step executes.
+
``DEPENDEES <step>...``
- Steps on which this step depends
+ Other steps (custom or pre-defined) on which this step depends.
+
``DEPENDERS <step>...``
- Steps that depend on this step
+ Other steps (custom or pre-defined) that depend on this new custom step.
+
``DEPENDS <file>...``
- Files on which this step depends
+ Files on which this custom step depends.
+
``BYPRODUCTS <file>...``
- Files that will be generated by this step but may or may not
- have their modification time updated by subsequent builds.
- ``ALWAYS 1``
- No stamp file, step always runs
- ``EXCLUDE_FROM_MAIN 1``
- Main target does not depend on this step
+ Files that will be generated by this custom step but which might or might
+ not have their modification time updated by subsequent builds. This list of
+ files will ultimately be passed through as the ``BYPRODUCTS`` option to the
+ :command:`add_custom_command` used to implement the custom step internally.
+
+ ``ALWAYS <bool>``
+ When enabled, this option specifies that the custom step should always be
+ run (i.e. that it is always considered out of date).
+
+ ``EXCLUDE_FROM_MAIN <bool>``
+ When enabled, this option specifies that the external project's main target
+ does not depend on the custom step.
+
``WORKING_DIRECTORY <dir>``
- Working directory for command
- ``LOG 1``
- Wrap step in script to log output
- ``USES_TERMINAL 1``
- Give the step direct access to the terminal if possible.
+ Specifies the working directory to set before running the custom step's
+ command. If this option is not specified, the directory will be the value
+ of the :variable:`CMAKE_CURRENT_BINARY_DIR` at the point where
+ ``ExternalProject_Add_Step()`` was called.
+
+ ``LOG <bool>``
+ If set, this causes the output from the custom step to be captured to files
+ in the external project's ``LOG_DIR`` if supplied or ``STAMP_DIR``.
+
+ ``USES_TERMINAL <bool>``
+ If enabled, this gives the custom step direct access to the terminal if
+ possible.
+
+ The command line, comment, working directory and byproducts of every
+ standard and custom step are processed to replace the tokens
+ ``<SOURCE_DIR>``, ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>``
+ ``<TMP_DIR>``, ``<DOWNLOAD_DIR>`` and ``<DOWNLOADED_FILE>`` with their
+ corresponding property values defined in the original call to
+ :command:`ExternalProject_Add`.
- The command line, comment, working directory, and byproducts of every
- standard and custom step are processed to replace tokens ``<SOURCE_DIR>``,
- ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>``, and ``<TMP_DIR>``
- with corresponding property values.
+.. command:: ExternalProject_Add_StepTargets
-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::
+ The ``ExternalProject_Add_StepTargets()`` function generates targets for the
+ steps listed. The name of each created target will be of the form
+ ``<name>-<step>``:
+
+ .. code-block:: cmake
+
+ ExternalProject_Add_StepTargets(<name> [NO_DEPENDS] <step1> [<step2>...])
+
+ Creating a target for a step allows it to be used as a dependency of another
+ target or to be triggered manually. Having targets for specific steps also
+ allows them to be driven 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.
+
+ If the ``NO_DEPENDS`` option is specified, the step target will not depend on
+ the dependencies of the external project (i.e. on any dependencies of the
+ ``<name>`` custom target created by :command:`ExternalProject_Add`). This is
+ usually safe for the ``download``, ``update`` and ``patch`` steps, since they
+ do not typically require that the dependencies are updated and built. Using
+ ``NO_DEPENDS`` for any of the other pre-defined steps, however, may break
+ parallel builds. Only use ``NO_DEPENDS`` where it is certain that the named
+ steps genuinely do not have dependencies. For custom steps, consider whether
+ or not the custom commands require the dependencies to be configured, built
+ and installed.
+
+ Internally, :command:`ExternalProject_Add` calls
+ :command:`ExternalProject_Add_Step` to create each step. If any
+ ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` were specified, then
+ ``ExternalProject_Add_StepTargets()`` will also be called after
+ :command:`ExternalProject_Add_Step`. ``INDEPENDENT_STEP_TARGETS`` have the
+ ``NO_DEPENDS`` option set, whereas ``STEP_TARGETS`` do not. Other than that,
+ the two options result in ``ExternalProject_Add_StepTargets()`` being called
+ in the same way. Even if a step is not mentioned in either of those two
+ options, ``ExternalProject_Add_StepTargets()`` can still be called later to
+ manually define a target for the step.
+
+ The ``STEP_TARGETS`` and ``INDEPENDENT_STEP_TARGETS`` options for
+ :command:`ExternalProject_Add` are generally the easiest way to ensure
+ targets are created for specific steps of interest. For custom steps,
+ ``ExternalProject_Add_StepTargets()`` must be called explicitly if a target
+ should also be created for that custom step. An alternative to these two
+ options is to populate the ``EP_STEP_TARGETS`` and
+ ``EP_INDEPENDENT_STEP_TARGETS`` directory properties. These act as defaults
+ for the step target options and can save having to repeatedly specify the
+ same set of step targets when multiple external projects are being defined.
- ... BUILD_COMMAND make COMMAND echo done ...
+.. command:: ExternalProject_Add_StepDependencies
-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_Add_StepDependencies()`` function can be used to add
+ dependencies to a step. The dependencies added must be targets CMake already
+ knows about (these can be ordinary executable or library targets, custom
+ targets or even step targets of another external project):
-Arguments to ``<step>_COMMAND`` or ``COMMAND`` options may use
-:manual:`generator expressions <cmake-generator-expressions(7)>`.
+ .. code-block:: cmake
-.. command:: ExternalProject_Get_Property
+ ExternalProject_Add_StepDependencies(<name> <step> <target1> [<target2>...])
- The ``ExternalProject_Get_Property`` function retrieves external project
- target properties::
+ This function takes care to set both target and file level dependencies and
+ will ensure that parallel builds will not break. It should be used instead of
+ :command:`add_dependencies` whenever adding a dependency for some of the step
+ targets generated by the ``ExternalProject`` module.
- ExternalProject_Get_Property(<name> [prop1 [prop2 [...]]])
+Examples
+^^^^^^^^
- It stores property values in variables of the same name. Property
- names correspond to the keyword argument names of
- ``ExternalProject_Add``.
+The following example shows how to download and build a hypothetical project
+called *FooBar* from github:
-.. command:: ExternalProject_Add_StepTargets
+.. code-block:: cmake
- The ``ExternalProject_Add_StepTargets`` function generates custom
- targets for the steps listed::
-
- ExternalProject_Add_StepTargets(<name> [NO_DEPENDS] [step1 [step2 [...]]])
-
-If ``NO_DEPENDS`` is set, the target will not depend on the
-dependencies of the complete project. This is usually safe to use for
-the download, update, and patch steps that do not require that all the
-dependencies are updated and built. Using ``NO_DEPENDS`` for other
-of the default steps might break parallel builds, so you should avoid,
-it. For custom steps, you should consider whether or not the custom
-commands requires that the dependencies are configured, built and
-installed.
-
-If ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` is set then
-``ExternalProject_Add_StepTargets`` is automatically called at the end
-of matching calls to ``ExternalProject_Add_Step``. Pass
-``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` explicitly to
-individual ``ExternalProject_Add`` calls, or implicitly to all
-``ExternalProject_Add`` calls by setting the directory properties
-``EP_STEP_TARGETS`` and ``EP_INDEPENDENT_STEP_TARGETS``. The
-``INDEPENDENT`` version of the argument and of the property will call
-``ExternalProject_Add_StepTargets`` with the ``NO_DEPENDS`` argument.
-
-If ``STEP_TARGETS`` and ``INDEPENDENT_STEP_TARGETS`` are 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)
+ include(ExternalProject)
+ ExternalProject_Add(foobar
+ GIT_REPOSITORY git@github.com:FooCo/FooBar.git
+ GIT_TAG origin/release/1.2.3
+ )
-.. command:: ExternalProject_Add_StepDependencies
+For the sake of the example, also define a second hypothetical external project
+called *SecretSauce*, which is downloaded from a web server. Two URLs are given
+to take advantage of a faster internal network if available, with a fallback to
+a slower external server. The project is a typical ``Makefile`` project with no
+configure step, so some of the default commands are overridden. The build is
+only required to build the *sauce* target:
+
+.. code-block:: cmake
+
+ find_program(MAKE_EXE NAMES gmake nmake make)
+ ExternalProject_Add(secretsauce
+ URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
+ https://www.somecompany.com/downloads/sauce-2.7.zip
+ URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ${MAKE_EXE} sauce
+ )
+
+Suppose the build step of ``secretsauce`` requires that ``foobar`` must already
+be built. This could be enforced like so:
+
+.. code-block:: cmake
+
+ ExternalProject_Add_StepDependencies(secretsauce build foobar)
+
+Another alternative would be to create a custom target for ``foobar``'s build
+step and make ``secretsauce`` depend on that rather than the whole ``foobar``
+project. This would mean ``foobar`` only needs to be built, it doesn't need to
+run its install or test steps before ``secretsauce`` can be built. The
+dependency can also be defined along with the ``secretsauce`` project:
+
+.. code-block:: cmake
+
+ ExternalProject_Add_StepTargets(foobar build)
+ ExternalProject_Add(secretsauce
+ URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
+ https://www.somecompany.com/downloads/sauce-2.7.zip
+ URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ${MAKE_EXE} sauce
+ DEPENDS foobar-build
+ )
+
+Instead of calling :command:`ExternalProject_Add_StepTargets`, the target could
+be defined along with the ``foobar`` project itself:
+
+.. code-block:: cmake
+
+ ExternalProject_Add(foobar
+ GIT_REPOSITORY git@github.com:FooCo/FooBar.git
+ GIT_TAG origin/release/1.2.3
+ STEP_TARGETS build
+ )
+
+If many external projects should have the same set of step targets, setting a
+directory property may be more convenient. The ``build`` step target could be
+created automatically by setting the ``EP_STEP_TARGETS`` directory property
+before creating the external projects with :command:`ExternalProject_Add`:
+
+.. code-block:: cmake
- The ``ExternalProject_Add_StepDependencies`` function add some
- dependencies for some external project step::
+ set_property(DIRECTORY PROPERTY EP_STEP_TARGETS build)
- ExternalProject_Add_StepDependencies(<name> <step> [target1 [target2 [...]]])
+Lastly, suppose that ``secretsauce`` provides a script called ``makedoc`` which
+can be used to generate its own documentation. Further suppose that the script
+expects the output directory to be provided as the only parameter and that it
+should be run from the ``secretsauce`` source directory. A custom step and a
+custom target to trigger the script can be defined like so:
+
+.. code-block:: cmake
+
+ ExternalProject_Add_Step(secretsauce docs
+ COMMAND <SOURCE_DIR>/makedoc <BINARY_DIR>
+ WORKING_DIRECTORY <SOURCE_DIR>
+ COMMENT "Building secretsauce docs"
+ ALWAYS TRUE
+ EXCLUDE_FROM_MAIN TRUE
+ )
+ ExternalProject_Add_StepTargets(secretsauce docs)
+
+The custom step could then be triggered from the main build like so::
+
+ cmake --build . --target secretsauce-docs
- This function takes care to set both target and file level
- dependencies, and will ensure that parallel builds will not break.
- It should be used instead of :command:`add_dependencies()` when adding
- a dependency for some of the step targets generated by
- ``ExternalProject``.
#]=======================================================================]
+cmake_policy(PUSH)
+cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
+
# Pre-compute a regex to match documented keywords for each command.
-math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 16")
+math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 4")
file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines
LIMIT_COUNT ${_ep_documentation_line_count}
- REGEX "^\\.\\. command:: [A-Za-z0-9_]+|^ ``[A-Z0-9_]+ .*``$")
+ REGEX "^\\.\\. command:: [A-Za-z0-9_]+|^ +``[A-Z0-9_]+ [^`]*``$")
foreach(line IN LISTS lines)
if("${line}" MATCHES "^\\.\\. command:: ([A-Za-z0-9_]+)")
if(_ep_func)
@@ -421,8 +943,16 @@ foreach(line IN LISTS lines)
#message("function [${_ep_func}]")
set(_ep_keywords_${_ep_func} "^(")
set(_ep_keyword_sep)
- elseif("${line}" MATCHES "^ ``([A-Z0-9_]+) .*``$")
+ elseif("${line}" MATCHES "^ +``([A-Z0-9_]+) [^`]*``$")
set(_ep_key "${CMAKE_MATCH_1}")
+ # COMMAND should never be included as a keyword,
+ # for ExternalProject_Add(), as it is treated as a
+ # special case by argument parsing as an extension
+ # of a previous ..._COMMAND
+ if("x${_ep_key}x" STREQUAL "xCOMMANDx" AND
+ "x${_ep_func}x" STREQUAL "xExternalProject_Addx")
+ continue()
+ endif()
#message(" keyword [${_ep_key}]")
string(APPEND _ep_keywords_${_ep_func}
"${_ep_keyword_sep}${_ep_key}")
@@ -448,6 +978,11 @@ function(_ep_parse_arguments f name ns args)
# 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.
+
+ if(NOT DEFINED _ExternalProject_SELF)
+ message(FATAL_ERROR "error: ExternalProject module must be explicitly included before using ${f} function")
+ endif()
+
set(key)
foreach(arg IN LISTS args)
@@ -504,7 +1039,7 @@ define_property(DIRECTORY PROPERTY "EP_STEP_TARGETS" INHERITED
BRIEF_DOCS
"List of ExternalProject steps that automatically get corresponding targets"
FULL_DOCS
- "These targets will be dependent on the main target dependencies"
+ "These targets will be dependent on the main target dependencies. "
"See documentation of the ExternalProject_Add_StepTargets() function in the "
"ExternalProject module."
)
@@ -513,7 +1048,7 @@ define_property(DIRECTORY PROPERTY "EP_INDEPENDENT_STEP_TARGETS" INHERITED
BRIEF_DOCS
"List of ExternalProject steps that automatically get corresponding targets"
FULL_DOCS
- "These targets will not be dependent on the main target dependencies"
+ "These targets will not be dependent on the main target dependencies. "
"See documentation of the ExternalProject_Add_StepTargets() function in the "
"ExternalProject module."
)
@@ -526,11 +1061,6 @@ define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED
)
function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules git_shallow git_progress git_config src_name work_dir gitclone_infofile gitclone_stampfile tls_verify)
- if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
- set(git_clone_shallow_options "--depth 1 --no-single-branch")
- else()
- set(git_clone_shallow_options "--depth 1")
- endif()
if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5)
# Use `git checkout <tree-ish> --` to avoid ambiguity with a local path.
set(git_checkout_explicit-- "--")
@@ -540,18 +1070,41 @@ function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git
# because that will not search for remote branch names, a common use case.
set(git_checkout_explicit-- "")
endif()
- file(WRITE ${script_filename}
-"if(\"${git_tag}\" STREQUAL \"\")
- message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
-endif()
+ if("${git_tag}" STREQUAL "")
+ message(FATAL_ERROR "Tag for git checkout should not be empty.")
+ endif()
-set(run 0)
+ set(git_clone_options)
+ if(git_shallow)
+ if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
+ list(APPEND git_clone_options "--depth 1 --no-single-branch")
+ else()
+ list(APPEND git_clone_options "--depth 1")
+ endif()
+ endif()
+ if(git_progress)
+ list(APPEND git_clone_options --progress)
+ endif()
+ foreach(config IN LISTS git_config)
+ list(APPEND git_clone_options --config ${config})
+ endforeach()
+ if(NOT ${git_remote_name} STREQUAL "origin")
+ list(APPEND git_clone_options --origin \"${git_remote_name}\")
+ endif()
-if(\"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\")
- set(run 1)
-endif()
+ string (REPLACE ";" " " git_clone_options "${git_clone_options}")
+
+ set(git_options)
+ # disable cert checking if explicitly told not to do it
+ if(NOT "x${tls_verify}" STREQUAL "x" AND NOT tls_verify)
+ set(git_options
+ -c http.sslVerify=false)
+ endif()
+ string (REPLACE ";" " " git_options "${git_options}")
-if(NOT run)
+ file(WRITE ${script_filename}
+"
+if(NOT \"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\")
message(STATUS \"Avoiding repeated git clone, stamp file is up to date: '${gitclone_stampfile}'\")
return()
endif()
@@ -564,38 +1117,12 @@ if(error_code)
message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
endif()
-set(git_options)
-
-# disable cert checking if explicitly told not to do it
-set(tls_verify \"${tls_verify}\")
-if(NOT \"x${tls_verify}\" STREQUAL \"x\" AND NOT tls_verify)
- list(APPEND git_options
- -c http.sslVerify=false)
-endif()
-
-set(git_clone_options)
-
-set(git_shallow \"${git_shallow}\")
-if(git_shallow)
- list(APPEND git_clone_options ${git_clone_shallow_options})
-endif()
-
-set(git_progress \"${git_progress}\")
-if(git_progress)
- list(APPEND git_clone_options --progress)
-endif()
-
-set(git_config \"${git_config}\")
-foreach(config IN LISTS git_config)
- list(APPEND git_clone_options --config \${config})
-endforeach()
-
-# try the clone 3 times incase there is an odd git clone issue
+# try the clone 3 times in case 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}\" \${git_options} clone \${git_clone_options} --origin \"${git_remote_name}\" \"${git_repository}\" \"${src_name}\"
+ COMMAND \"${git_EXECUTABLE}\" ${git_options} clone ${git_clone_options} \"${git_repository}\" \"${src_name}\"
WORKING_DIRECTORY \"${work_dir}\"
RESULT_VARIABLE error_code
)
@@ -610,7 +1137,7 @@ if(error_code)
endif()
execute_process(
- COMMAND \"${git_EXECUTABLE}\" \${git_options} checkout ${git_tag} ${git_checkout_explicit--}
+ COMMAND \"${git_EXECUTABLE}\" ${git_options} checkout ${git_tag} ${git_checkout_explicit--}
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
@@ -619,16 +1146,7 @@ if(error_code)
endif()
execute_process(
- COMMAND \"${git_EXECUTABLE}\" \${git_options} submodule init ${git_submodules}
- 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}\" \${git_options} submodule update --recursive --init ${git_submodules}
+ COMMAND \"${git_EXECUTABLE}\" ${git_options} submodule update --recursive --init ${git_submodules}
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
@@ -642,7 +1160,6 @@ execute_process(
COMMAND \${CMAKE_COMMAND} -E copy
\"${gitclone_infofile}\"
\"${gitclone_stampfile}\"
- WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
if(error_code)
@@ -655,18 +1172,12 @@ 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)
+ if("${hg_tag}" STREQUAL "")
+ message(FATAL_ERROR "Tag for hg checkout should not be empty.")
+ endif()
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)
+"
+if(NOT \"${hgclone_infofile}\" IS_NEWER_THAN \"${hgclone_stampfile}\")
message(STATUS \"Avoiding repeated hg clone, stamp file is up to date: '${hgclone_stampfile}'\")
return()
endif()
@@ -703,7 +1214,6 @@ execute_process(
COMMAND \${CMAKE_COMMAND} -E copy
\"${hgclone_infofile}\"
\"${hgclone_stampfile}\"
- WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
if(error_code)
@@ -717,16 +1227,16 @@ endfunction()
function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name git_submodules git_repository work_dir)
+ if("${git_tag}" STREQUAL "")
+ message(FATAL_ERROR "Tag for git checkout should not be empty.")
+ endif()
if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.6)
set(git_stash_save_options --all --quiet)
else()
set(git_stash_save_options --quiet)
endif()
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}\"
@@ -888,7 +1398,7 @@ endif()
endfunction(_ep_write_gitupdate_script)
-function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_progress hash tls_verify tls_cainfo userpwd http_headers)
+function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_progress hash tls_verify tls_cainfo userpwd http_headers netrc netrc_file)
if(timeout)
set(TIMEOUT_ARGS TIMEOUT ${timeout})
set(TIMEOUT_MSG "${timeout} seconds")
@@ -913,6 +1423,8 @@ function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_p
set(TLS_VERIFY_CODE "")
set(TLS_CAINFO_CODE "")
+ set(NETRC_CODE "")
+ set(NETRC_FILE_CODE "")
# check for curl globals in the project
if(DEFINED CMAKE_TLS_VERIFY)
@@ -921,6 +1433,12 @@ function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_p
if(DEFINED CMAKE_TLS_CAINFO)
set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${CMAKE_TLS_CAINFO}\")")
endif()
+ if(DEFINED CMAKE_NETRC)
+ set(NETRC_CODE "set(CMAKE_NETRC \"${CMAKE_NETRC}\")")
+ endif()
+ if(DEFINED CMAKE_NETRC_FILE)
+ set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${CMAKE_NETRC_FILE}\")")
+ endif()
# now check for curl locals so that the local values
# will override the globals
@@ -935,6 +1453,16 @@ function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_p
if(tls_cainfo_len GREATER 0)
set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${tls_cainfo}\")")
endif()
+ # check for netrc argument
+ string(LENGTH "${netrc}" netrc_len)
+ if(netrc_len GREATER 0)
+ set(NETRC_CODE "set(CMAKE_NETRC \"${netrc}\")")
+ endif()
+ # check for netrc_file argument
+ string(LENGTH "${netrc_file}" netrc_file_len)
+ if(netrc_file_len GREATER 0)
+ set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${netrc_file}\")")
+ endif()
if(userpwd STREQUAL ":")
set(USERPWD_ARGS)
@@ -1108,6 +1636,8 @@ function(_ep_set_directories name)
endif()
endif()
set(top "${CMAKE_CURRENT_BINARY_DIR}")
+
+ # Apply defaults and convert to absolute paths.
set(places stamp download source binary install tmp)
foreach(var ${places})
string(TOUPPER "${var}" VAR)
@@ -1120,6 +1650,17 @@ function(_ep_set_directories name)
endif()
set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
endforeach()
+
+ # Special case for default log directory based on stamp directory.
+ get_property(log_dir TARGET ${name} PROPERTY _EP_LOG_DIR)
+ if(NOT log_dir)
+ get_property(log_dir TARGET ${name} PROPERTY _EP_STAMP_DIR)
+ endif()
+ if(NOT IS_ABSOLUTE "${log_dir}")
+ get_filename_component(log_dir "${top}/${log_dir}" ABSOLUTE)
+ endif()
+ set_property(TARGET ${name} PROPERTY _EP_LOG_DIR "${log_dir}")
+
get_property(source_subdir TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR)
if(NOT source_subdir)
set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "")
@@ -1133,7 +1674,11 @@ function(_ep_set_directories name)
endif()
if(build_in_source)
get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
- set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
+ if(source_subdir)
+ set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}/${source_subdir}")
+ else()
+ set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
+ endif()
endif()
# Make the directories at CMake configure time *and* add a custom command
@@ -1162,7 +1707,7 @@ macro(_ep_replace_location_tags target_name)
set(vars ${ARGN})
foreach(var ${vars})
if(${var})
- foreach(dir SOURCE_DIR SOURCE_SUBDIR BINARY_DIR INSTALL_DIR TMP_DIR DOWNLOADED_FILE)
+ foreach(dir SOURCE_DIR SOURCE_SUBDIR BINARY_DIR INSTALL_DIR TMP_DIR DOWNLOAD_DIR DOWNLOADED_FILE LOG_DIR)
get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
endforeach()
@@ -1182,7 +1727,7 @@ function(_ep_command_line_to_initial_cache var args force)
foreach(line ${args})
if("${line}" MATCHES "^-D(.*)")
set(line "${CMAKE_MATCH_1}")
- if(setArg)
+ if(NOT "${setArg}" STREQUAL "")
# This is required to build up lists in variables, or complete an entry
string(APPEND setArg "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
string(APPEND script_initial_cache "\n${setArg}")
@@ -1203,7 +1748,7 @@ function(_ep_command_line_to_initial_cache var args force)
endif()
endforeach()
# Catch the final line of the args
- if(setArg)
+ if(NOT "${setArg}" STREQUAL "")
string(APPEND setArg "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
string(APPEND script_initial_cache "\n${setArg}")
endif()
@@ -1286,7 +1831,8 @@ function(_ep_get_build_command name step cmd_var)
set(cmd "${CMAKE_COMMAND}")
endif()
set(args --build ".")
- if(CMAKE_CONFIGURATION_TYPES)
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(_isMultiConfig)
if (CMAKE_CFG_INTDIR AND
NOT CMAKE_CFG_INTDIR STREQUAL "." AND
NOT CMAKE_CFG_INTDIR MATCHES "\\$")
@@ -1311,7 +1857,7 @@ function(_ep_get_build_command name step cmd_var)
if("x${step}x" STREQUAL "xTESTx")
string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
set(args "")
- if(CMAKE_CONFIGURATION_TYPES)
+ if(_isMultiConfig)
list(APPEND args -C ${config})
endif()
endif()
@@ -1343,6 +1889,7 @@ function(_ep_get_build_command name step cmd_var)
endfunction()
function(_ep_write_log_script name step cmd_var)
+ ExternalProject_Get_Property(${name} log_dir)
ExternalProject_Get_Property(${name} stamp_dir)
set(command "${${cmd_var}}")
@@ -1414,23 +1961,66 @@ endif()
# Wrap the command in a script to log output to files.
set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
- set(logbase ${stamp_dir}/${name}-${step})
+ set(logbase ${log_dir}/${name}-${step})
+ get_property(log_merged TARGET ${name} PROPERTY _EP_LOG_MERGED_STDOUTERR)
+ get_property(log_output_on_failure TARGET ${name} PROPERTY _EP_LOG_OUTPUT_ON_FAILURE)
+ if (log_merged)
+ set(stdout_log "${logbase}.log")
+ set(stderr_log "${logbase}.log")
+ else()
+ set(stdout_log "${logbase}-out.log")
+ set(stderr_log "${logbase}-err.log")
+ endif()
set(code "
+cmake_minimum_required(VERSION 3.13)
${code_cygpath_make}
set(command \"${command}\")
+set(log_merged \"${log_merged}\")
+set(log_output_on_failure \"${log_output_on_failure}\")
+set(stdout_log \"${stdout_log}\")
+set(stderr_log \"${stderr_log}\")
execute_process(
COMMAND \${command}
RESULT_VARIABLE result
- OUTPUT_FILE \"${logbase}-out.log\"
- ERROR_FILE \"${logbase}-err.log\"
+ OUTPUT_FILE \"\${stdout_log}\"
+ ERROR_FILE \"\${stderr_log}\"
)
+macro(read_up_to_max_size log_file output_var)
+ file(SIZE \${log_file} determined_size)
+ set(max_size 10240)
+ if (determined_size GREATER max_size)
+ math(EXPR seek_position \"\${determined_size} - \${max_size}\")
+ file(READ \${log_file} \${output_var} OFFSET \${seek_position})
+ set(\${output_var} \"...skipping to end...\\n\${\${output_var}}\")
+ else()
+ file(READ \${log_file} \${output_var})
+ endif()
+endmacro()
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\")
- message(FATAL_ERROR \"\${msg}\")
+ if (\${log_merged})
+ set(msg \"\${msg}\\nSee also\\n \${stderr_log}\")
+ else()
+ set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\")
+ endif()
+ if (\${log_output_on_failure})
+ message(SEND_ERROR \"\${msg}\")
+ if (\${log_merged})
+ read_up_to_max_size(\"\${stderr_log}\" error_log_contents)
+ message(STATUS \"Log output is:\\n\${error_log_contents}\")
+ else()
+ read_up_to_max_size(\"\${stdout_log}\" out_log_contents)
+ read_up_to_max_size(\"\${stderr_log}\" err_log_contents)
+ message(STATUS \"stdout output is:\\n\${out_log_contents}\")
+ message(STATUS \"stderr output is:\\n\${err_log_contents}\")
+ endif()
+ message(FATAL_ERROR \"Stopping after outputting logs.\")
+ else()
+ message(FATAL_ERROR \"\${msg}\")
+ endif()
else()
set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
message(STATUS \"\${msg}\")
@@ -1451,7 +2041,8 @@ endfunction()
#
function(_ep_get_configuration_subdir_suffix suffix_var)
set(suffix "")
- if(CMAKE_CONFIGURATION_TYPES)
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(_isMultiConfig)
set(suffix "/${CMAKE_CFG_INTDIR}")
endif()
set(${suffix_var} "${suffix}" PARENT_SCOPE)
@@ -1468,6 +2059,15 @@ function(_ep_get_step_stampfile name step stampfile_var)
endfunction()
+function(_ep_get_complete_stampfile name stampfile_var)
+ set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
+ _ep_get_configuration_subdir_suffix(cfgdir)
+ set(stampfile "${cmf_dir}${cfgdir}/${name}-complete")
+
+ set(${stampfile_var} ${stampfile} PARENT_SCOPE)
+endfunction()
+
+
function(ExternalProject_Add_StepTargets name)
set(steps ${ARGN})
if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS")
@@ -1497,10 +2097,7 @@ 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_complete_stampfile(${name} complete_stamp_file)
_ep_get_step_stampfile(${name} ${step} stamp_file)
_ep_parse_arguments(ExternalProject_Add_Step
@@ -1575,7 +2172,8 @@ function(ExternalProject_Add_Step name step)
set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
set(touch)
# Remove any existing stamp in case the option changed in an existing tree.
- if(CMAKE_CONFIGURATION_TYPES)
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(_isMultiConfig)
foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
string(REPLACE "/${CMAKE_CFG_INTDIR}" "/${cfg}" stamp_file_config "${stamp_file}")
file(REMOVE ${stamp_file_config})
@@ -1694,7 +2292,7 @@ endfunction()
function(_ep_add_mkdir_command name)
ExternalProject_Get_Property(${name}
- source_dir binary_dir install_dir stamp_dir download_dir tmp_dir)
+ source_dir binary_dir install_dir stamp_dir download_dir tmp_dir log_dir)
_ep_get_configuration_subdir_suffix(cfgdir)
@@ -1706,6 +2304,7 @@ function(_ep_add_mkdir_command name)
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}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${log_dir}
)
endfunction()
@@ -1844,7 +2443,7 @@ function(_ep_add_download_command name)
#
set(repository ${git_repository})
set(module)
- set(tag)
+ set(tag ${git_remote_name})
configure_file(
"${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
"${stamp_dir}/${name}-gitinfo.txt"
@@ -1972,11 +2571,13 @@ function(_ep_add_download_command name)
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)
+ get_property(netrc TARGET ${name} PROPERTY _EP_NETRC)
+ get_property(netrc_file TARGET ${name} PROPERTY _EP_NETRC_FILE)
get_property(http_username TARGET ${name} PROPERTY _EP_HTTP_USERNAME)
get_property(http_password TARGET ${name} PROPERTY _EP_HTTP_PASSWORD)
get_property(http_headers TARGET ${name} PROPERTY _EP_HTTP_HEADER)
set(download_script "${stamp_dir}/download-${name}.cmake")
- _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}" "${http_username}:${http_password}" "${http_headers}")
+ _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}" "${http_username}:${http_password}" "${http_headers}" "${netrc}" "${netrc_file}")
set(cmd ${CMAKE_COMMAND} -P "${download_script}"
COMMAND)
if (no_extract)
@@ -2012,12 +2613,12 @@ function(_ep_add_download_command name)
" ${source_dir}\n"
"is not an existing non-empty directory. Please specify one of:\n"
" * SOURCE_DIR with an existing non-empty directory\n"
+ " * DOWNLOAD_COMMAND\n"
" * URL\n"
" * GIT_REPOSITORY\n"
+ " * SVN_REPOSITORY\n"
" * HG_REPOSITORY\n"
- " * CVS_REPOSITORY and CVS_MODULE\n"
- " * SVN_REVISION\n"
- " * DOWNLOAD_COMMAND"
+ " * CVS_REPOSITORY and CVS_MODULE"
)
endif()
endif()
@@ -2207,10 +2808,18 @@ function(_ep_add_patch_command name)
set(work_dir ${source_dir})
endif()
+ get_property(log TARGET ${name} PROPERTY _EP_LOG_PATCH)
+ if(log)
+ set(log LOG 1)
+ else()
+ set(log "")
+ endif()
+
ExternalProject_Add_Step(${name} patch
COMMAND ${cmd}
WORKING_DIRECTORY ${work_dir}
DEPENDEES download
+ ${log}
)
endfunction()
@@ -2235,19 +2844,18 @@ function(_ep_extract_configure_command var name)
get_property(cmake_cache_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_ARGS)
get_property(cmake_cache_default_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_DEFAULT_ARGS)
- if(cmake_cache_args OR cmake_cache_default_args)
- set(_ep_cache_args_script "<TMP_DIR>/${name}-cache-$<CONFIG>.cmake")
- if(cmake_cache_args)
- _ep_command_line_to_initial_cache(script_initial_cache_force "${cmake_cache_args}" 1)
- endif()
- if(cmake_cache_default_args)
- _ep_command_line_to_initial_cache(script_initial_cache_default "${cmake_cache_default_args}" 0)
- endif()
- _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${script_initial_cache_force}${script_initial_cache_default}")
- list(APPEND cmd "-C${_ep_cache_args_script}")
+ set(has_cmake_cache_args 0)
+ if(NOT "${cmake_cache_args}" STREQUAL "")
+ set(has_cmake_cache_args 1)
+ endif()
+
+ set(has_cmake_cache_default_args 0)
+ if(NOT "${cmake_cache_default_args}" STREQUAL "")
+ set(has_cmake_cache_default_args 1)
endif()
get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
+ get_target_property(cmake_generator_instance ${name} _EP_CMAKE_GENERATOR_INSTANCE)
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)
@@ -2258,11 +2866,24 @@ function(_ep_extract_configure_command var name)
if(cmake_generator_toolset)
list(APPEND cmd "-T${cmake_generator_toolset}")
endif()
+ if(cmake_generator_instance)
+ list(APPEND cmd "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${cmake_generator_instance}")
+ endif()
else()
if(CMAKE_EXTRA_GENERATOR)
list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
else()
list(APPEND cmd "-G${CMAKE_GENERATOR}")
+ if("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
+ set(has_cmake_cache_default_args 1)
+ set(cmake_cache_default_args ${cmake_cache_default_args}
+ "-DGHS_TARGET_PLATFORM:STRING=${GHS_TARGET_PLATFORM}"
+ "-DGHS_PRIMARY_TARGET:STRING=${GHS_PRIMARY_TARGET}"
+ "-DGHS_TOOLSET_ROOT:STRING=${GHS_TOOLSET_ROOT}"
+ "-DGHS_OS_ROOT:STRING=${GHS_OS_ROOT}"
+ "-DGHS_OS_DIR:STRING=${GHS_OS_DIR}"
+ "-DGHS_BSP_NAME:STRING=${GHS_BSP_NAME}")
+ endif()
endif()
if(cmake_generator_platform)
message(FATAL_ERROR "Option CMAKE_GENERATOR_PLATFORM not allowed without CMAKE_GENERATOR.")
@@ -2276,6 +2897,24 @@ function(_ep_extract_configure_command var name)
if(CMAKE_GENERATOR_TOOLSET)
list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
endif()
+ if(cmake_generator_instance)
+ message(FATAL_ERROR "Option CMAKE_GENERATOR_INSTANCE not allowed without CMAKE_GENERATOR.")
+ endif()
+ if(CMAKE_GENERATOR_INSTANCE)
+ list(APPEND cmd "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
+ endif()
+ endif()
+
+ if(has_cmake_cache_args OR has_cmake_cache_default_args)
+ set(_ep_cache_args_script "<TMP_DIR>/${name}-cache-$<CONFIG>.cmake")
+ if(has_cmake_cache_args)
+ _ep_command_line_to_initial_cache(script_initial_cache_force "${cmake_cache_args}" 1)
+ endif()
+ if(has_cmake_cache_default_args)
+ _ep_command_line_to_initial_cache(script_initial_cache_default "${cmake_cache_default_args}" 0)
+ endif()
+ _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${script_initial_cache_force}${script_initial_cache_default}")
+ list(APPEND cmd "-C${_ep_cache_args_script}")
endif()
list(APPEND cmd "<SOURCE_DIR><SOURCE_SUBDIR>")
@@ -2503,7 +3142,7 @@ function(ExternalProject_Add name)
# 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")
+ _ep_get_complete_stampfile(${name} complete_stamp_file)
# 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
@@ -2574,3 +3213,5 @@ function(ExternalProject_Add name)
#
_ep_add_test_command(${name})
endfunction()
+
+cmake_policy(POP)
diff --git a/Modules/FeatureSummary.cmake b/Modules/FeatureSummary.cmake
index 1b93304bb..4a3e83af3 100644
--- a/Modules/FeatureSummary.cmake
+++ b/Modules/FeatureSummary.cmake
@@ -97,8 +97,6 @@ Functions
#]=======================================================================]
-include(CMakeParseArguments)
-
function(_FS_GET_FEATURE_SUMMARY _property _var _includeQuiet)
get_property(_fsPkgTypes GLOBAL PROPERTY FeatureSummary_PKG_TYPES)
@@ -493,7 +491,7 @@ endfunction()
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
+ binaries will be severely 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
diff --git a/Modules/FindALSA.cmake b/Modules/FindALSA.cmake
index fa9a43438..88e2681eb 100644
--- a/Modules/FindALSA.cmake
+++ b/Modules/FindALSA.cmake
@@ -1,28 +1,45 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.rst:
+FindALSA
+--------
+
+Find Advanced Linux Sound Architecture (ALSA)
+
+Find the alsa libraries (``asound``)
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``ALSA::ALSA``, if
+ALSA has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``ALSA_FOUND``
+ True if ALSA_INCLUDE_DIR & ALSA_LIBRARY are found
+
+``ALSA_LIBRARIES``
+ List of libraries when using ALSA.
+
+``ALSA_INCLUDE_DIRS``
+ Where to find the ALSA headers.
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``ALSA_INCLUDE_DIR``
+ the ALSA include directory
+
+``ALSA_LIBRARY``
+ the absolute path of the asound library
+#]=======================================================================]
find_path(ALSA_INCLUDE_DIR NAMES alsa/asoundlib.h
DOC "The ALSA (asound) include directory"
@@ -47,6 +64,11 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA
if(ALSA_FOUND)
set( ALSA_LIBRARIES ${ALSA_LIBRARY} )
set( ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIR} )
+ if(NOT TARGET ALSA::ALSA)
+ add_library(ALSA::ALSA UNKNOWN IMPORTED)
+ set_target_properties(ALSA::ALSA PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${ALSA_INCLUDE_DIRS}")
+ set_property(TARGET ALSA::ALSA APPEND PROPERTY IMPORTED_LOCATION "${ALSA_LIBRARY}")
+ endif()
endif()
mark_as_advanced(ALSA_INCLUDE_DIR ALSA_LIBRARY)
diff --git a/Modules/FindASPELL.cmake b/Modules/FindASPELL.cmake
index 6944ac192..c2d29e295 100644
--- a/Modules/FindASPELL.cmake
+++ b/Modules/FindASPELL.cmake
@@ -1,21 +1,22 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
find_path(ASPELL_INCLUDE_DIR aspell.h )
diff --git a/Modules/FindAVIFile.cmake b/Modules/FindAVIFile.cmake
index 88a2a25b0..96554405d 100644
--- a/Modules/FindAVIFile.cmake
+++ b/Modules/FindAVIFile.cmake
@@ -1,34 +1,29 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindAVIFile
+-----------
-if (UNIX)
+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
+
+::
- find_path(AVIFILE_INCLUDE_DIR avifile.h
- /usr/local/avifile/include
- /usr/local/include/avifile
- )
+ 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
+#]=======================================================================]
+
+if (UNIX)
- find_library(AVIFILE_AVIPLAY_LIBRARY aviplay
- /usr/local/avifile/lib
- )
+ find_path(AVIFILE_INCLUDE_DIR avifile.h PATH_SUFFIXES avifile/include include/avifile include/avifile-0.7)
+ find_library(AVIFILE_AVIPLAY_LIBRARY aviplay aviplay-0.7 PATH_SUFFIXES avifile/lib)
endif ()
diff --git a/Modules/FindArmadillo.cmake b/Modules/FindArmadillo.cmake
index 95f0c5629..c4e55ce57 100644
--- a/Modules/FindArmadillo.cmake
+++ b/Modules/FindArmadillo.cmake
@@ -1,35 +1,35 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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")
+#[=======================================================================[.rst:
+FindArmadillo
+-------------
+
+Find the Armadillo C++ library.
+Armadillo is library for linear algebra & scientific computing.
+
+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")
+#]=======================================================================]
# UNIX paths are standard, no need to write.
find_library(ARMADILLO_LIBRARY
diff --git a/Modules/FindBISON.cmake b/Modules/FindBISON.cmake
index d684ccd86..6b5828eef 100644
--- a/Modules/FindBISON.cmake
+++ b/Modules/FindBISON.cmake
@@ -1,85 +1,86 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindBISON
-# ---------
-#
-# Find ``bison`` executable and provide a macro 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 macro::
-#
-# BISON_TARGET(<Name> <YaccInput> <CodeOutput>
-# [COMPILE_FLAGS <flags>]
-# [DEFINES_FILE <file>]
-# [VERBOSE [<file>]]
-# [REPORT_FILE <file>]
-# )
-#
-# 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.
-#
-# The options are:
-#
-# ``COMPILE_FLAGS <flags>``
-# Specify flags to be added to the ``bison`` command line.
-#
-# ``DEFINES_FILE <file>``
-# Specify a non-default header ``<file>`` to be generated by ``bison``.
-#
-# ``VERBOSE [<file>]``
-# Tell ``bison`` to write a report file of the grammar and parser.
-# If ``<file>`` is given, it specifies path the report file is copied to.
-# ``[<file>]`` is left for backward compatibility of this module.
-# Use ``VERBOSE REPORT_FILE <file>``.
-#
-# ``REPORT_FILE <file>``
-# Specify a non-default report ``<file>``, if generated.
-#
-# The macro defines the following 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``
-# All files generated by bison including the source, the header and the report
-#
-# ``BISON_<Name>_COMPILE_FLAGS``
-# Options used in the ``bison`` command line
-#
-# Example usage:
-#
-# .. code-block:: cmake
-#
-# find_package(BISON)
-# BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
-# DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
-# add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})
+#[=======================================================================[.rst:
+FindBISON
+---------
+
+Find ``bison`` executable and provide a macro 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. :command:`find_package(BISON 2.1.3)`.
+
+If ``bison`` is found, the module defines the macro::
+
+ BISON_TARGET(<Name> <YaccInput> <CodeOutput>
+ [COMPILE_FLAGS <flags>]
+ [DEFINES_FILE <file>]
+ [VERBOSE [<file>]]
+ [REPORT_FILE <file>]
+ )
+
+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.
+
+The options are:
+
+``COMPILE_FLAGS <flags>``
+ Specify flags to be added to the ``bison`` command line.
+
+``DEFINES_FILE <file>``
+ Specify a non-default header ``<file>`` to be generated by ``bison``.
+
+``VERBOSE [<file>]``
+ Tell ``bison`` to write a report file of the grammar and parser.
+ If ``<file>`` is given, it specifies path the report file is copied to.
+ ``[<file>]`` is left for backward compatibility of this module.
+ Use ``VERBOSE REPORT_FILE <file>``.
+
+``REPORT_FILE <file>``
+ Specify a non-default report ``<file>``, if generated.
+
+The macro defines the following 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``
+ All files generated by bison including the source, the header and the report
+
+``BISON_<Name>_COMPILE_FLAGS``
+ Options used in the ``bison`` command line
+
+Example usage:
+
+.. code-block:: cmake
+
+ find_package(BISON)
+ BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
+ DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
+ add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})
+#]=======================================================================]
find_program(BISON_EXECUTABLE NAMES bison win_bison DOC "path to the bison executable")
mark_as_advanced(BISON_EXECUTABLE)
@@ -149,17 +150,43 @@ if(BISON_EXECUTABLE)
set(BISON_TARGET_verbose_file "${ReportFile}")
list(APPEND BISON_TARGET_cmdopt "--report-file=${BISON_TARGET_verbose_file}")
endif()
+ if(NOT IS_ABSOLUTE "${BISON_TARGET_verbose_file}")
+ cmake_policy(GET CMP0088 _BISON_CMP0088
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ if("x${_BISON_CMP0088}x" STREQUAL "xNEWx")
+ set(BISON_TARGET_verbose_file "${CMAKE_CURRENT_BINARY_DIR}/${BISON_TARGET_verbose_file}")
+ else()
+ set(BISON_TARGET_verbose_file "${CMAKE_CURRENT_SOURCE_DIR}/${BISON_TARGET_verbose_file}")
+ endif()
+ unset(_BISON_CMP0088)
+ endif()
endmacro()
# internal macro
# adds a custom command and sets
- # BISON_TARGET_cmdopt, BISON_TARGET_verbose_file, BISON_TARGET_extraoutputs
+ # BISON_TARGET_cmdopt, BISON_TARGET_extraoutputs
macro(BISON_TARGET_option_verbose Name BisonOutput filename)
+ cmake_policy(GET CMP0088 _BISON_CMP0088
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ set(_BISON_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+ if("x${_BISON_CMP0088}x" STREQUAL "xNEWx")
+ set(_BISON_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+ unset(_BISON_CMP0088)
+
list(APPEND BISON_TARGET_cmdopt "--verbose")
- list(APPEND BISON_TARGET_extraoutputs
+ list(APPEND BISON_TARGET_outputs
"${BISON_TARGET_verbose_file}")
if (NOT "${filename}" STREQUAL "")
- add_custom_command(OUTPUT ${filename}
+ if(IS_ABSOLUTE "${filename}")
+ set(BISON_TARGET_verbose_extra_file "${filename}")
+ else()
+ set(BISON_TARGET_verbose_extra_file "${_BISON_WORKING_DIRECTORY}/${filename}")
+ endif()
+
+ add_custom_command(OUTPUT ${BISON_TARGET_verbose_extra_file}
COMMAND ${CMAKE_COMMAND} -E copy
"${BISON_TARGET_verbose_file}"
"${filename}"
@@ -167,10 +194,11 @@ if(BISON_EXECUTABLE)
DEPENDS
"${BISON_TARGET_verbose_file}"
COMMENT "[BISON][${Name}] Copying bison verbose table to ${filename}"
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
- set(BISON_${Name}_VERBOSE_FILE ${filename})
+ WORKING_DIRECTORY ${_BISON_WORKING_DIRECTORY})
list(APPEND BISON_TARGET_extraoutputs
- "${filename}")
+ "${BISON_TARGET_verbose_extra_file}")
+ unset(BISON_TARGET_verbose_extra_file)
+ unset(_BISON_WORKING_DIRECTORY)
endif()
endmacro()
@@ -225,22 +253,38 @@ if(BISON_EXECUTABLE)
list(APPEND BISON_TARGET_outputs "${BISON_TARGET_output_header}")
+ cmake_policy(GET CMP0088 _BISON_CMP0088
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ set(_BISON_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+ set(_BisonInput "${BisonInput}")
+ if("x${_BISON_CMP0088}x" STREQUAL "xNEWx")
+ set(_BISON_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+ if(NOT IS_ABSOLUTE "${_BisonInput}")
+ set(_BisonInput "${CMAKE_CURRENT_SOURCE_DIR}/${_BisonInput}")
+ endif()
+ endif()
+ unset(_BISON_CMP0088)
+
add_custom_command(OUTPUT ${BISON_TARGET_outputs}
- ${BISON_TARGET_extraoutputs}
- COMMAND ${BISON_EXECUTABLE} ${BISON_TARGET_cmdopt} -o ${BisonOutput} ${BisonInput}
+ COMMAND ${BISON_EXECUTABLE} ${BISON_TARGET_cmdopt} -o ${BisonOutput} ${_BisonInput}
VERBATIM
- DEPENDS ${BisonInput}
+ DEPENDS ${_BisonInput}
COMMENT "[BISON][${Name}] Building parser with bison ${BISON_VERSION}"
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+ WORKING_DIRECTORY ${_BISON_WORKING_DIRECTORY})
+
+ unset(_BISON_WORKING_DIRECTORY)
# define target variables
set(BISON_${Name}_DEFINED TRUE)
- set(BISON_${Name}_INPUT ${BisonInput})
+ set(BISON_${Name}_INPUT ${_BisonInput})
set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs} ${BISON_TARGET_extraoutputs})
set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})
set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")
set(BISON_${Name}_OUTPUT_HEADER "${BISON_TARGET_output_header}")
+ unset(_BisonInput)
+
endif()
endmacro()
#
diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake
index 2684617fe..d3acafcd9 100644
--- a/Modules/FindBLAS.cmake
+++ b/Modules/FindBLAS.cmake
@@ -1,67 +1,101 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
-# * OpenBLAS
-# * 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
-#
-# .. note::
-#
-# C/CXX should be enabled to use Intel mkl
-#
+#[=======================================================================[.rst:
+FindBLAS
+--------
+
+Find Basic Linear Algebra Subprograms (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).
+
+Input Variables
+^^^^^^^^^^^^^^^
+
+The following variables may be set to influence this module's behavior:
+
+``BLA_STATIC``
+ if ``ON`` use static linkage
+
+``BLA_VENDOR``
+ If set, checks only the specified vendor, if not set checks all the
+ possibilities. List of vendors valid in this module:
+
+ * Goto
+ * OpenBLAS
+ * FLAME
+ * ATLAS PhiPACK
+ * CXML
+ * DXML
+ * SunPerf
+ * SCSL
+ * SGIMATH
+ * IBMESSL
+ * Intel10_32 (intel mkl v10 32 bit)
+ * Intel10_64lp (intel mkl v10+ 64 bit, threaded code, lp64 model)
+ * Intel10_64lp_seq (intel mkl v10+ 64 bit, sequential code, lp64 model)
+ * Intel10_64ilp (intel mkl v10+ 64 bit, threaded code, ilp64 model)
+ * Intel10_64ilp_seq (intel mkl v10+ 64 bit, sequential code, ilp64 model)
+ * Intel (obsolete versions of mkl 32 and 64 bit)
+ * ACML
+ * ACML_MP
+ * ACML_GPU
+ * Apple
+ * NAS
+ * Generic
+
+``BLA_F95``
+ if ``ON`` tries to find the BLAS95 interfaces
+
+``BLA_PREFER_PKGCONFIG``
+ if set ``pkg-config`` will be used to search for a BLAS library first
+ and if one is found that is preferred
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``BLAS_FOUND``
+ 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 (may be empty if compiler implicitly links BLAS)
+``BLAS95_LIBRARIES``
+ uncached list of libraries (using full path name) to link against
+ to use BLAS95 interface
+``BLAS95_FOUND``
+ library implementing the BLAS95 interface is found
+
+.. note::
+
+ C or CXX must be enabled to use Intel Math Kernel Library (MKL)
+
+ For example, to use Intel MKL libraries and/or Intel compiler:
+
+ .. code-block:: cmake
+
+ set(BLA_VENDOR Intel10_64lp)
+ find_package(BLAS)
+
+Hints
+^^^^^
+
+Set ``MKLROOT`` environment variable to a directory that contains an MKL
+installation.
+
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
cmake_push_check_state()
set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
@@ -77,78 +111,97 @@ if( NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_C
endif()
endif()
+if(BLA_PREFER_PKGCONFIG)
+ find_package(PkgConfig)
+ pkg_check_modules(PKGC_BLAS blas)
+ if(PKGC_BLAS_FOUND)
+ set(BLAS_FOUND ${PKGC_BLAS_FOUND})
+ set(BLAS_LIBRARIES "${PKGC_BLAS_LINK_LIBRARIES}")
+ 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)
+ # 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 ()
-endif ()
-foreach(_library ${_list})
- set(_combined_name ${_combined_name}_${_library})
+ list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
- 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})
+ foreach(_library ${_list})
+ set(_combined_name ${_combined_name}_${_library})
+ if(NOT "${_thread}" STREQUAL "")
+ set(_combined_name ${_combined_name}_thread)
+ endif()
+ 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 ()
- 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)
+ 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 ()
- 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})
+ 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 (CMAKE_Fortran_COMPILER_LOADED)
+ check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
+ else()
+ check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
+ endif()
+ set(CMAKE_REQUIRED_LIBRARIES)
+ set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
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 (CMAKE_Fortran_COMPILER_LOADED)
- check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
+ if(_libraries_work)
+ if("${_list}" STREQUAL "")
+ set(${LIBRARIES} "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
+ else()
+ set(${LIBRARIES} ${${LIBRARIES}} ${_thread}) # for static link
+ endif()
else()
- check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
+ set(${LIBRARIES} FALSE)
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}}")
+ #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
endmacro()
set(BLAS_LINKER_FLAGS)
@@ -162,550 +215,605 @@ else ()
endif()
endif ()
+if (BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ # Implicitly linked BLAS libraries
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ ""
+ ""
+ )
+ endif()
+endif ()
+
+#BLAS in intel mkl 10+ library? (em64t 64bit)
+if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
+ if (NOT BLAS_LIBRARIES)
+
+ # System-specific settings
+ if (WIN32)
+ if (BLA_STATIC)
+ set(BLAS_mkl_DLL_SUFFIX "")
+ else()
+ set(BLAS_mkl_DLL_SUFFIX "_dll")
+ endif()
+ else()
+ # Switch to GNU Fortran support layer if needed (but not on Apple, where MKL does not provide it)
+ if(CMAKE_Fortran_COMPILER_LOADED AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
+ set(BLAS_mkl_INTFACE "gf")
+ set(BLAS_mkl_THREADING "gnu")
+ set(BLAS_mkl_OMP "gomp")
+ else()
+ set(BLAS_mkl_INTFACE "intel")
+ set(BLAS_mkl_THREADING "intel")
+ set(BLAS_mkl_OMP "iomp5")
+ endif()
+ set(BLAS_mkl_LM "-lm")
+ set(BLAS_mkl_LDL "-ldl")
+ endif()
+
+ if (BLA_VENDOR MATCHES "_64ilp")
+ set(BLAS_mkl_ILP_MODE "ilp64")
+ else ()
+ set(BLAS_mkl_ILP_MODE "lp64")
+ endif ()
+
+ if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
+ 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_f95)
+ set(_LIBRARIES BLAS95_LIBRARIES)
+ if (WIN32)
+ # 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 MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
+ "mkl_blas95_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX} mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
+ endif ()
+
+ # Add threading/sequential libs
+ set(BLAS_SEARCH_LIBS_WIN_THREAD "")
+ if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+ "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
+ endif()
+ if (NOT BLA_VENDOR MATCHES "_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")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
+
+ # mkl >= 10.3
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_OMP}")
+ endif ()
+ if (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95 mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
+
+ # mkl >= 10.3
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_OMP}")
+ endif ()
+ if (BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core")
+ endif ()
+ endif ()
+ else ()
+ set(BLAS_mkl_SEARCH_SYMBOL sgemm)
+ set(_LIBRARIES BLAS_LIBRARIES)
+ if (WIN32)
+ # 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 MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
+ "mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
+ endif ()
+
+ # Add threading/sequential libs
+ set(BLAS_SEARCH_LIBS_WIN_THREAD "")
+ if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+ "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+ # mkl >= 10.3
+ list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
+ "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
+ endif()
+ if (BLA_VENDOR MATCHES "_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")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
+
+ # mkl >= 10.3
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_OMP}")
+ endif ()
+ if (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
+ # old version
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
+
+ # mkl >= 10.3
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_OMP}")
+ endif ()
+ if (BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
+ list(APPEND BLAS_SEARCH_LIBS
+ "mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} 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 ()
+
+ if (DEFINED ENV{MKLROOT})
+ if (BLA_VENDOR STREQUAL "Intel10_32")
+ set(_BLAS_MKLROOT_LIB_DIR "$ENV{MKLROOT}/lib/ia32")
+ elseif (BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$")
+ set(_BLAS_MKLROOT_LIB_DIR "$ENV{MKLROOT}/lib/intel64")
+ endif ()
+ endif ()
+ if (_BLAS_MKLROOT_LIB_DIR)
+ if (WIN32)
+ string(APPEND _BLAS_MKLROOT_LIB_DIR "_win")
+ elseif (APPLE)
+ string(APPEND _BLAS_MKLROOT_LIB_DIR "_mac")
+ else ()
+ string(APPEND _BLAS_MKLROOT_LIB_DIR "_lin")
+ endif ()
+ endif ()
+
+ foreach (IT ${BLAS_SEARCH_LIBS})
+ string(REPLACE " " ";" SEARCH_LIBS ${IT})
+ if (NOT ${_LIBRARIES})
+ check_fortran_libraries(
+ ${_LIBRARIES}
+ BLAS
+ ${BLAS_mkl_SEARCH_SYMBOL}
+ ""
+ "${SEARCH_LIBS}"
+ "${CMAKE_THREAD_LIBS_INIT};${BLAS_mkl_LM};${BLAS_mkl_LDL}"
+ "${_BLAS_MKLROOT_LIB_DIR}"
+ )
+ endif ()
+ endforeach ()
+
+ endif ()
+ unset(BLAS_mkl_ILP_MODE)
+ unset(BLAS_mkl_INTFACE)
+ unset(BLAS_mkl_THREADING)
+ unset(BLAS_mkl_OMP)
+ unset(BLAS_mkl_DLL_SUFFIX)
+ unset(BLAS_mkl_LM)
+ unset(BLAS_mkl_LDL)
+ endif ()
+endif ()
+
+if(BLA_F95)
+ find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS95_LIBRARIES)
+ set(BLAS95_FOUND ${BLAS_FOUND})
+ if(BLAS_FOUND)
+ set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
+ 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()
+ 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 "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
- if(NOT BLAS_LIBRARIES)
- # OpenBLAS (http://www.openblas.net)
- check_fortran_libraries(
- BLAS_LIBRARIES
- BLAS
- sgemm
- ""
- "openblas"
- ""
- )
- endif()
+ if(NOT BLAS_LIBRARIES)
+ # OpenBLAS (http://www.openblas.net)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "openblas"
+ ""
+ )
+ endif()
+ if(NOT BLAS_LIBRARIES AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
+ if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
+ find_package(Threads)
+ else()
+ find_package(Threads REQUIRED)
+ endif()
+ # OpenBLAS (http://www.openblas.net)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "openblas"
+ "${CMAKE_THREAD_LIBS_INIT}"
+ )
+ endif()
+endif ()
+
+if (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")
+ if(NOT BLAS_LIBRARIES)
+ # FLAME's blis library (https://github.com/flame/blis)
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "blis"
+ ""
+ )
+ 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()
+ 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()
+ 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()
+ 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()
+ 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")
+ 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()
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()
+ 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()
+ 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()
+ 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 )
+ 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()
+ else()
file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
- endif()
- if( WIN32 )
+ endif()
+ if( WIN32 )
file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
- else()
+ 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 )
+ 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" )
+ 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" )
+ 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_COMPILER64 "pgi64" )
+ 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()
- 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()
+elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
+ set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
+endif()
- if( BLA_VENDOR STREQUAL "ACML_MP" )
+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()
+ 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" )
+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()
+ check_fortran_libraries (
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
+ )
+ if( BLAS_LIBRARIES )
+ break()
+ endif()
endforeach()
- else()
+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()
+ check_fortran_libraries (
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
+ )
+ if( BLAS_LIBRARIES )
+ break()
+ endif()
endforeach()
- endif()
+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)
+# 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;CALBLAS"
- ""
- )
- endif()
-endif () # ACML
-
-# Apple BLAS library?
-if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "acml;acml_mv"
+ ""
+ )
+endif()
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
+ sgemm
""
- "vecLib"
+ "acml_mp;acml_mv"
""
)
- endif ()
-endif ()
-# Generic BLAS library?
-if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
- if(NOT BLAS_LIBRARIES)
+endif()
+if(NOT BLAS_LIBRARIES)
check_fortran_libraries(
- BLAS_LIBRARIES
- BLAS
- sgemm
- ""
- "blas"
- ""
- )
- endif()
-endif ()
+ BLAS_LIBRARIES
+ BLAS
+ sgemm
+ ""
+ "acml;acml_mv;CALBLAS"
+ ""
+ )
+endif()
+endif () # ACML
-#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 (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
- if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
- find_package(Threads)
- else()
- find_package(Threads REQUIRED)
+# 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 ()
- 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 MATCHES "^Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
- list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
- "mkl_blas95_lp64${BLAS_mkl_DLL_SUFFIX} mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
- endif ()
-
- # Add threading/sequential libs
- set(BLAS_SEARCH_LIBS_WIN_THREAD "")
- if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All")
- list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
- "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
- endif()
- if (NOT BLA_VENDOR MATCHES "_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 MATCHES "^Intel10_64lp" OR BLA_VENDOR STREQUAL "All")
- list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
- "mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}")
- endif ()
-
- # Add threading/sequential libs
- set(BLAS_SEARCH_LIBS_WIN_THREAD "")
- if (NOT BLA_VENDOR MATCHES "_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 MATCHES "_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 ()
+if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
+ if ( NOT BLAS_LIBRARIES )
+ check_fortran_libraries(
+ BLAS_LIBRARIES
+ BLAS
+ dgemm
+ ""
+ "vecLib"
+ ""
+ )
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)
+# 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 ()
- 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 BLA_F95)
+ find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS_LIBRARIES)
+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()
+# On compilers that implicitly link BLAS (such as ftn, cc, and CC on Cray HPC machines)
+# we used a placeholder for empty BLAS_LIBRARIES to get through our logic above.
+if (BLAS_LIBRARIES STREQUAL "BLAS_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
+ set(BLAS_LIBRARIES "")
endif()
cmake_pop_check_state()
diff --git a/Modules/FindBZip2.cmake b/Modules/FindBZip2.cmake
index d2307f131..309b97145 100644
--- a/Modules/FindBZip2.cmake
+++ b/Modules/FindBZip2.cmake
@@ -1,30 +1,42 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindBZip2
-# ---------
-#
-# Try to find BZip2
-#
-# IMPORTED Targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines :prop_tgt:`IMPORTED` target ``BZip2::BZip2``, if
-# BZip2 has been found.
-#
-# Result Variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following variables:
-#
-# ::
-#
-# 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)
+#[=======================================================================[.rst:
+FindBZip2
+---------
+
+Try to find BZip2
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``BZip2::BZip2``, if
+BZip2 has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``BZIP2_FOUND``
+ system has BZip2
+``BZIP2_INCLUDE_DIRS``
+ the BZip2 include directories
+``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
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``BZIP2_INCLUDE_DIR``
+ the BZip2 include directory
+#]=======================================================================]
set(_BZIP2_PATHS PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Bzip2;InstallPath]"
@@ -38,6 +50,8 @@ if (NOT BZIP2_LIBRARIES)
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
SELECT_LIBRARY_CONFIGURATIONS(BZIP2)
+else ()
+ file(TO_CMAKE_PATH "${BZIP2_LIBRARIES}" BZIP2_LIBRARIES)
endif ()
if (BZIP2_INCLUDE_DIR AND EXISTS "${BZIP2_INCLUDE_DIR}/bzlib.h")
@@ -51,39 +65,40 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(BZip2
VERSION_VAR BZIP2_VERSION_STRING)
if (BZIP2_FOUND)
- include(${CMAKE_CURRENT_LIST_DIR}/CheckSymbolExists.cmake)
- include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
- cmake_push_check_state()
- set(CMAKE_REQUIRED_QUIET ${BZip2_FIND_QUIETLY})
- set(CMAKE_REQUIRED_INCLUDES ${BZIP2_INCLUDE_DIR})
- set(CMAKE_REQUIRED_LIBRARIES ${BZIP2_LIBRARIES})
- CHECK_SYMBOL_EXISTS(BZ2_bzCompressInit "bzlib.h" BZIP2_NEED_PREFIX)
- cmake_pop_check_state()
-
- if(NOT TARGET BZip2::BZip2)
- add_library(BZip2::BZip2 UNKNOWN IMPORTED)
+ set(BZIP2_INCLUDE_DIRS ${BZIP2_INCLUDE_DIR})
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckSymbolExists.cmake)
+ include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
+ cmake_push_check_state()
+ set(CMAKE_REQUIRED_QUIET ${BZip2_FIND_QUIETLY})
+ set(CMAKE_REQUIRED_INCLUDES ${BZIP2_INCLUDE_DIR})
+ set(CMAKE_REQUIRED_LIBRARIES ${BZIP2_LIBRARIES})
+ CHECK_SYMBOL_EXISTS(BZ2_bzCompressInit "bzlib.h" BZIP2_NEED_PREFIX)
+ cmake_pop_check_state()
+
+ if(NOT TARGET BZip2::BZip2)
+ add_library(BZip2::BZip2 UNKNOWN IMPORTED)
+ set_target_properties(BZip2::BZip2 PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIRS}")
+
+ if(BZIP2_LIBRARY_RELEASE)
+ set_property(TARGET BZip2::BZip2 APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(BZip2::BZip2 PROPERTIES
+ IMPORTED_LOCATION_RELEASE "${BZIP2_LIBRARY_RELEASE}")
+ endif()
+
+ if(BZIP2_LIBRARY_DEBUG)
+ set_property(TARGET BZip2::BZip2 APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(BZip2::BZip2 PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIRS}")
-
- if(BZIP2_LIBRARY_RELEASE)
- set_property(TARGET BZip2::BZip2 APPEND PROPERTY
- IMPORTED_CONFIGURATIONS RELEASE)
- set_target_properties(BZip2::BZip2 PROPERTIES
- IMPORTED_LOCATION_RELEASE "${BZIP2_LIBRARY_RELEASE}")
- endif()
-
- if(BZIP2_LIBRARY_DEBUG)
- set_property(TARGET BZip2::BZip2 APPEND PROPERTY
- IMPORTED_CONFIGURATIONS DEBUG)
- set_target_properties(BZip2::BZip2 PROPERTIES
- IMPORTED_LOCATION_DEBUG "${BZIP2_LIBRARY_DEBUG}")
- endif()
-
- if(NOT BZIP2_LIBRARY_RELEASE AND NOT BZIP2_LIBRARY_DEBUG)
- set_property(TARGET BZip2::BZip2 APPEND PROPERTY
- IMPORTED_LOCATION "${BZIP2_LIBRARY}")
- endif()
+ IMPORTED_LOCATION_DEBUG "${BZIP2_LIBRARY_DEBUG}")
+ endif()
+
+ if(NOT BZIP2_LIBRARY_RELEASE AND NOT BZIP2_LIBRARY_DEBUG)
+ set_property(TARGET BZip2::BZip2 APPEND PROPERTY
+ IMPORTED_LOCATION "${BZIP2_LIBRARY}")
endif()
+ endif()
endif ()
mark_as_advanced(BZIP2_INCLUDE_DIR)
diff --git a/Modules/FindBacktrace.cmake b/Modules/FindBacktrace.cmake
index 59ebdc26d..cf1632a57 100644
--- a/Modules/FindBacktrace.cmake
+++ b/Modules/FindBacktrace.cmake
@@ -1,41 +1,42 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindBacktrace
+-------------
+
+Find provider for `backtrace(3) <http://man7.org/linux/man-pages/man3/backtrace.3.html>`__.
+
+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 :command:`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.
+#]=======================================================================]
include(CMakePushCheckState)
include(CheckSymbolExists)
diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake
index 6d7cc27f4..af4947cae 100644
--- a/Modules/FindBoost.cmake
+++ b/Modules/FindBoost.cmake
@@ -1,216 +1,427 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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_RELEASE - Directory containing release Boost libraries
-# Boost_LIBRARY_DIR_DEBUG - Directory containing debug Boost libraries
-# Boost_<C>_LIBRARY_DEBUG - Component <C> library debug variant
-# Boost_<C>_LIBRARY_RELEASE - Component <C> library release variant
-#
-# The following :prop_tgt:`IMPORTED` targets are also defined::
-#
-# Boost::boost - Target for header-only dependencies
-# (Boost include directory)
-# Boost::<C> - Target for specific component dependency
-# (shared or static library); <C> is lower-
-# case
-# Boost::diagnostic_definitions - interface target to enable diagnostic
-# information about Boost's automatic linking
-# during compilation (adds BOOST_LIB_DIAGNOSTIC)
-# Boost::disable_autolinking - interface target to disable automatic
-# linking with MSVC (adds BOOST_ALL_NO_LIB)
-# Boost::dynamic_linking - interface target to enable dynamic linking
-# linking with MSVC (adds BOOST_ALL_DYN_LINK)
-#
-# Implicit dependencies such as Boost::filesystem requiring
-# Boost::system will be automatically detected and satisfied, even
-# if system is not specified when using find_package and if
-# Boost::system is not added to target_link_libraries. If using
-# Boost::thread, then Thread::Thread will also be added automatically.
-#
-# It is important to note that the imported targets behave differently
-# than variables created by this module: multiple calls to
-# find_package(Boost) in the same directory or sub-directories with
-# different options (e.g. static or shared) will not override the
-# values of the targets created by the first call.
-#
-# Users may set these hints or results as cache entries. Projects
-# should not read these entries directly but instead use the above
-# result variables. Note that some hint names start in upper-case
-# "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 directories in Boost_LIBRARY_DIR_DEBUG and
-# Boost_LIBRARY_DIR_RELEASE 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. A list may be
-# used if multiple compatible suffixes should
-# be tested for, in decreasing order of
-# preference.
-# 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.
-# Boost_LIBRARY_DIR - Default value for Boost_LIBRARY_DIR_RELEASE and
-# Boost_LIBRARY_DIR_DEBUG.
-#
-# 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 libraries and use imported targets::
-#
-# find_package(Boost 1.56 REQUIRED COMPONENTS
-# date_time filesystem iostreams)
-# add_executable(foo foo.cc)
-# target_link_libraries(foo Boost::date_time Boost::filesystem
-# Boost::iostreams)
-#
-# Example to find Boost headers and some *static* libraries::
-#
-# set(Boost_USE_STATIC_LIBS ON) # only find static libs
-# 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.
+#[=======================================================================[.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.67.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"
+ [OPTIONAL_COMPONENTS <libs>...]
+ # Optional 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_MACRO - BOOST_VERSION value from boost/version.hpp
+ Boost_VERSION_STRING - Boost version number in x.y.z format
+ Boost_VERSION - if CMP0093 NEW => same as Boost_VERSION_STRING
+ if CMP0093 OLD or unset => same as Boost_VERSION_MACRO
+ Boost_LIB_VERSION - Version string appended to library filenames
+ Boost_VERSION_MAJOR - Boost major version number (X in X.y.z)
+ alias: Boost_MAJOR_VERSION
+ Boost_VERSION_MINOR - Boost minor version number (Y in x.Y.z)
+ alias: Boost_MINOR_VERSION
+ Boost_VERSION_PATCH - Boost subminor version number (Z in x.y.Z)
+ alias: Boost_SUBMINOR_VERSION
+ Boost_VERSION_COUNT - Amount of version components (3)
+ Boost_LIB_DIAGNOSTIC_DEFINITIONS (Windows)
+ - Pass to add_definitions() to have diagnostic
+ information about Boost's automatic linking
+ displayed during compilation
+
+Note that Boost Python components require a Python version suffix
+(Boost 1.67 and later), e.g. ``python36`` or ``python27`` for the
+versions built against Python 3.6 and 2.7, respectively. This also
+applies to additional components using Python including
+``mpi_python`` and ``numpy``. Earlier Boost releases may use
+distribution-specific suffixes such as ``2``, ``3`` or ``2.7``.
+These may also be used as suffixes, but note that they are not
+portable.
+
+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_RELEASE - Directory containing release Boost libraries
+ Boost_LIBRARY_DIR_DEBUG - Directory containing debug Boost libraries
+ Boost_<C>_LIBRARY_DEBUG - Component <C> library debug variant
+ Boost_<C>_LIBRARY_RELEASE - Component <C> library release variant
+
+The following :prop_tgt:`IMPORTED` targets are also defined::
+
+ Boost::headers - Target for header-only dependencies
+ (Boost include directory)
+ alias: Boost::boost
+ Boost::<C> - Target for specific component dependency
+ (shared or static library); <C> is lower-
+ case
+ Boost::diagnostic_definitions - interface target to enable diagnostic
+ information about Boost's automatic linking
+ during compilation (adds BOOST_LIB_DIAGNOSTIC)
+ Boost::disable_autolinking - interface target to disable automatic
+ linking with MSVC (adds BOOST_ALL_NO_LIB)
+ Boost::dynamic_linking - interface target to enable dynamic linking
+ linking with MSVC (adds BOOST_ALL_DYN_LINK)
+
+Implicit dependencies such as ``Boost::filesystem`` requiring
+``Boost::system`` will be automatically detected and satisfied, even
+if system is not specified when using :command:`find_package` and if
+``Boost::system`` is not added to :command:`target_link_libraries`. If using
+``Boost::thread``, then ``Threads::Threads`` will also be added automatically.
+
+It is important to note that the imported targets behave differently
+than variables created by this module: multiple calls to
+:command:`find_package(Boost)` in the same directory or sub-directories with
+different options (e.g. static or shared) will not override the
+values of the targets created by the first call.
+
+Users may set these hints or results as ``CACHE`` entries. Projects
+should not read these entries directly but instead use the above
+result variables. Note that some hint names start in upper-case
+"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 directories in ``Boost_LIBRARY_DIR_DEBUG`` and
+``Boost_LIBRARY_DIR_RELEASE`` 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_DEBUG_LIBS - Set to ON or OFF to specify whether to search
+ and use the debug libraries. Default is ON.
+ Boost_USE_RELEASE_LIBS - Set to ON or OFF to specify whether to search
+ and use the release libraries. Default is ON.
+ 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. A list may be
+ used if multiple compatible suffixes should
+ be tested for, in decreasing order of
+ preference.
+ Boost_ARCHITECTURE - Set to the architecture-specific library suffix
+ (e.g. "-x64"). 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_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.67.0" instead of
+ "/usr/lib/libboost_system.so". This does not
+ affect linking and should not be enabled unless
+ the user needs this information.
+ Boost_LIBRARY_DIR - Default value for Boost_LIBRARY_DIR_RELEASE and
+ Boost_LIBRARY_DIR_DEBUG.
+
+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 libraries and use imported targets::
+
+ find_package(Boost 1.56 REQUIRED COMPONENTS
+ date_time filesystem iostreams)
+ add_executable(foo foo.cc)
+ target_link_libraries(foo Boost::date_time Boost::filesystem
+ Boost::iostreams)
+
+Example to find Boost Python 3.6 libraries and use imported targets::
+
+ find_package(Boost 1.67 REQUIRED COMPONENTS
+ python36 numpy36)
+ add_executable(foo foo.cc)
+ target_link_libraries(foo Boost::python36 Boost::numpy36)
+
+Example to find Boost headers and some *static* (release only) libraries::
+
+ set(Boost_USE_STATIC_LIBS ON) # only find static libs
+ set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and
+ set(Boost_USE_RELEASE_LIBS ON) # only find release libs
+ set(Boost_USE_MULTITHREADED ON)
+ set(Boost_USE_STATIC_RUNTIME OFF)
+ find_package(Boost 1.66.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 or from Boost 1.70.0 on
+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.
+#]=======================================================================]
+
+# The FPHSA helper provides standard way of reporting final search results to
+# the user including the version and component checks.
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+# Save project's policies
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
+function(_boost_get_existing_target component target_var)
+ set(names "${component}")
+ if(component MATCHES "^([a-z_]*)(python|numpy)([1-9])\\.?([0-9])?$")
+ # handle pythonXY and numpyXY versioned components and also python X.Y, mpi_python etc.
+ list(APPEND names
+ "${CMAKE_MATCH_1}${CMAKE_MATCH_2}" # python
+ "${CMAKE_MATCH_1}${CMAKE_MATCH_2}${CMAKE_MATCH_3}" # pythonX
+ "${CMAKE_MATCH_1}${CMAKE_MATCH_2}${CMAKE_MATCH_3}${CMAKE_MATCH_4}" #pythonXY
+ )
+ endif()
+ # https://github.com/boost-cmake/boost-cmake uses boost::file_system etc.
+ # So handle similar constructions of target names
+ string(TOLOWER "${component}" lower_component)
+ list(APPEND names "${lower_component}")
+ foreach(prefix Boost boost)
+ foreach(name IN LISTS names)
+ if(TARGET "${prefix}::${name}")
+ # The target may be an INTERFACE library that wraps around a single other
+ # target for compatibility. Unwrap this layer so we can extract real info.
+ if("${name}" MATCHES "^(python|numpy|mpi_python)([1-9])([0-9])$")
+ set(name_nv "${CMAKE_MATCH_1}")
+ if(TARGET "${prefix}::${name_nv}")
+ get_property(type TARGET "${prefix}::${name}" PROPERTY TYPE)
+ if(type STREQUAL "INTERFACE_LIBRARY")
+ get_property(lib TARGET "${prefix}::${name}" PROPERTY INTERFACE_LINK_LIBRARIES)
+ if("${lib}" STREQUAL "${prefix}::${name_nv}")
+ set(${target_var} "${prefix}::${name_nv}" PARENT_SCOPE)
+ return()
+ endif()
+ endif()
+ endif()
+ endif()
+ set(${target_var} "${prefix}::${name}" PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+ endforeach()
+ set(${target_var} "" PARENT_SCOPE)
+endfunction()
+
+function(_boost_get_canonical_target_name component target_var)
+ string(TOLOWER "${component}" component)
+ if(component MATCHES "^([a-z_]*)(python|numpy)([1-9])\\.?([0-9])?$")
+ # handle pythonXY and numpyXY versioned components and also python X.Y, mpi_python etc.
+ set(${target_var} "Boost::${CMAKE_MATCH_1}${CMAKE_MATCH_2}" PARENT_SCOPE)
+ else()
+ set(${target_var} "Boost::${component}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+macro(_boost_set_in_parent_scope name value)
+ # Set a variable in parent scope and make it visibile in current scope
+ set(${name} "${value}" PARENT_SCOPE)
+ set(${name} "${value}")
+endmacro()
+
+macro(_boost_set_if_unset name value)
+ if(NOT ${name})
+ _boost_set_in_parent_scope(${name} "${value}")
+ endif()
+endmacro()
+
+macro(_boost_set_cache_if_unset name value)
+ if(NOT ${name})
+ set(${name} "${value}" CACHE STRING "" FORCE)
+ endif()
+endmacro()
+
+macro(_boost_append_include_dir target)
+ get_target_property(inc "${target}" INTERFACE_INCLUDE_DIRECTORIES)
+ if(inc)
+ list(APPEND include_dirs "${inc}")
+ endif()
+endmacro()
+
+function(_boost_set_legacy_variables_from_config)
+ # Set legacy variables for compatibility if not set
+ set(include_dirs "")
+ set(library_dirs "")
+ set(libraries "")
+ # Header targets Boost::headers or Boost::boost
+ foreach(comp headers boost)
+ _boost_get_existing_target(${comp} target)
+ if(target)
+ _boost_append_include_dir("${target}")
+ endif()
+ endforeach()
+ # Library targets
+ foreach(comp IN LISTS Boost_FIND_COMPONENTS)
+ string(TOUPPER ${comp} uppercomp)
+ # Overwrite if set
+ _boost_set_in_parent_scope(Boost_${uppercomp}_FOUND "${Boost_${comp}_FOUND}")
+ if(Boost_${comp}_FOUND)
+ _boost_get_existing_target(${comp} target)
+ if(NOT target)
+ if(Boost_DEBUG OR Boost_VERBOSE)
+ message(WARNING "Could not find imported target for required component '${comp}'. Legacy variables for this component might be missing. Refer to the documentation of your Boost installation for help on variables to use.")
+ endif()
+ continue()
+ endif()
+ _boost_append_include_dir("${target}")
+ _boost_set_if_unset(Boost_${uppercomp}_LIBRARY "${target}")
+ _boost_set_if_unset(Boost_${uppercomp}_LIBRARIES "${target}") # Very old legacy variable
+ list(APPEND libraries "${target}")
+ get_property(type TARGET "${target}" PROPERTY TYPE)
+ if(NOT type STREQUAL "INTERFACE_LIBRARY")
+ foreach(cfg RELEASE DEBUG)
+ get_target_property(lib ${target} IMPORTED_LOCATION_${cfg})
+ if(lib)
+ get_filename_component(lib_dir "${lib}" DIRECTORY)
+ list(APPEND library_dirs ${lib_dir})
+ _boost_set_cache_if_unset(Boost_${uppercomp}_LIBRARY_${cfg} "${lib}")
+ endif()
+ endforeach()
+ elseif(Boost_DEBUG OR Boost_VERBOSE)
+ # For projects using only the Boost::* targets this warning can be safely ignored.
+ message(WARNING "Imported target '${target}' for required component '${comp}' has no artifact. Legacy variables for this component might be missing. Refer to the documentation of your Boost installation for help on variables to use.")
+ endif()
+ _boost_get_canonical_target_name("${comp}" canonical_target)
+ if(NOT TARGET "${canonical_target}")
+ add_library("${canonical_target}" INTERFACE IMPORTED)
+ target_link_libraries("${canonical_target}" INTERFACE "${target}")
+ endif()
+ endif()
+ endforeach()
+ list(REMOVE_DUPLICATES include_dirs)
+ list(REMOVE_DUPLICATES library_dirs)
+ _boost_set_if_unset(Boost_INCLUDE_DIRS "${include_dirs}")
+ _boost_set_if_unset(Boost_LIBRARY_DIRS "${library_dirs}")
+ _boost_set_if_unset(Boost_LIBRARIES "${libraries}")
+ _boost_set_if_unset(Boost_VERSION_STRING "${Boost_VERSION_MAJOR}.${Boost_VERSION_MINOR}.${Boost_VERSION_PATCH}")
+ find_path(Boost_INCLUDE_DIR
+ NAMES boost/version.hpp boost/config.hpp
+ HINTS ${Boost_INCLUDE_DIRS}
+ NO_DEFAULT_PATH
+ )
+ if(NOT Boost_VERSION_MACRO OR NOT Boost_LIB_VERSION)
+ set(version_file ${Boost_INCLUDE_DIR}/boost/version.hpp)
+ if(EXISTS "${version_file}")
+ file(STRINGS "${version_file}" contents REGEX "#define BOOST_(LIB_)?VERSION ")
+ if(contents MATCHES "#define BOOST_VERSION ([0-9]+)")
+ _boost_set_if_unset(Boost_VERSION_MACRO "${CMAKE_MATCH_1}")
+ endif()
+ if(contents MATCHES "#define BOOST_LIB_VERSION \"([0-9_]+)\"")
+ _boost_set_if_unset(Boost_LIB_VERSION "${CMAKE_MATCH_1}")
+ endif()
+ endif()
+ endif()
+ _boost_set_if_unset(Boost_MAJOR_VERSION ${Boost_VERSION_MAJOR})
+ _boost_set_if_unset(Boost_MINOR_VERSION ${Boost_VERSION_MINOR})
+ _boost_set_if_unset(Boost_SUBMINOR_VERSION ${Boost_VERSION_PATCH})
+ if(WIN32)
+ _boost_set_if_unset(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC")
+ endif()
+ if(NOT TARGET Boost::headers)
+ add_library(Boost::headers INTERFACE IMPORTED)
+ target_include_directories(Boost::headers INTERFACE ${Boost_INCLUDE_DIRS})
+ endif()
+ # Legacy targets w/o functionality as all handled by defined targets
+ foreach(lib diagnostic_definitions disable_autolinking dynamic_linking)
+ if(NOT TARGET Boost::${lib})
+ add_library(Boost::${lib} INTERFACE IMPORTED)
+ endif()
+ endforeach()
+ if(NOT TARGET Boost::boost)
+ add_library(Boost::boost INTERFACE IMPORTED)
+ target_link_libraries(Boost::boost INTERFACE Boost::headers)
+ endif()
+endfunction()
#-------------------------------------------------------------------------------
-# Before we go searching, check whether boost-cmake is available, unless the
-# user specifically asked NOT to search for boost-cmake.
+# Before we go searching, check whether a boost cmake package is available, unless
+# the user specifically asked NOT to search for one.
#
# 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.
@@ -232,14 +443,33 @@ if (NOT Boost_NO_BOOST_CMAKE)
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.
+ # If we found a boost cmake package, 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}")
+ if(Boost_FOUND)
+ # Convert component found variables to standard variables if required
+ # Necessary for legacy boost-cmake and 1.70 builtin BoostConfig
+ if(Boost_FIND_COMPONENTS)
+ # Ignore the meta-component "ALL", introduced by Boost 1.73
+ list(REMOVE_ITEM Boost_FIND_COMPONENTS "ALL")
+
+ foreach(_comp IN LISTS Boost_FIND_COMPONENTS)
+ if(DEFINED Boost_${_comp}_FOUND)
+ continue()
+ endif()
+ string(TOUPPER ${_comp} _uppercomp)
+ if(DEFINED Boost${_comp}_FOUND) # legacy boost-cmake project
+ set(Boost_${_comp}_FOUND ${Boost${_comp}_FOUND})
+ elseif(DEFINED Boost_${_uppercomp}_FOUND) # Boost 1.70
+ set(Boost_${_comp}_FOUND ${Boost_${_uppercomp}_FOUND})
+ endif()
+ endforeach()
endif()
+
+ find_package_handle_standard_args(Boost HANDLE_COMPONENTS CONFIG_MODE)
+ _boost_set_legacy_variables_from_config()
+
+ # Restore project's policies
+ cmake_policy(POP)
return()
endif()
endif()
@@ -249,6 +479,56 @@ endif()
# FindBoost functions & macros
#
+#
+# Print debug text if Boost_DEBUG is set.
+# Call example:
+# _Boost_DEBUG_PRINT("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "debug message")
+#
+function(_Boost_DEBUG_PRINT file line text)
+ if(Boost_DEBUG)
+ message(STATUS "[ ${file}:${line} ] ${text}")
+ endif()
+endfunction()
+
+#
+# _Boost_DEBUG_PRINT_VAR(file line variable_name [ENVIRONMENT]
+# [SOURCE "short explanation of origin of var value"])
+#
+# ENVIRONMENT - look up environment variable instead of CMake variable
+#
+# Print variable name and its value if Boost_DEBUG is set.
+# Call example:
+# _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" BOOST_ROOT)
+#
+function(_Boost_DEBUG_PRINT_VAR file line name)
+ if(Boost_DEBUG)
+ cmake_parse_arguments(_args "ENVIRONMENT" "SOURCE" "" ${ARGN})
+
+ unset(source)
+ if(_args_SOURCE)
+ set(source " (${_args_SOURCE})")
+ endif()
+
+ if(_args_ENVIRONMENT)
+ if(DEFINED ENV{${name}})
+ set(value "\"$ENV{${name}}\"")
+ else()
+ set(value "<unset>")
+ endif()
+ set(_name "ENV{${name}}")
+ else()
+ if(DEFINED "${name}")
+ set(value "\"${${name}}\"")
+ else()
+ set(value "<unset>")
+ endif()
+ set(_name "${name}")
+ endif()
+
+ _Boost_DEBUG_PRINT("${file}" "${line}" "${_name} = ${value}${source}")
+ endif()
+endfunction()
+
############################################
#
# Check the existence of the libraries.
@@ -264,13 +544,14 @@ endif()
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)
+ # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
+ # single-config generators, set optimized and debug libraries
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(_isMultiConfig 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
+ # For single-config generators where CMAKE_BUILD_TYPE has no value,
+ # just use the release libraries
set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
endif()
# FIXME: This probably should be set for both cases
@@ -292,13 +573,17 @@ macro(_Boost_ADJUST_LIB_VARS basename)
endif()
# If the debug & release library ends up being the same, omit the keywords
- if(${Boost_${basename}_LIBRARY_RELEASE} STREQUAL ${Boost_${basename}_LIBRARY_DEBUG})
+ 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 AND Boost_${basename}_HEADER)
set(Boost_${basename}_FOUND ON)
+ if("x${basename}" STREQUAL "xTHREAD" AND NOT TARGET Threads::Threads)
+ string(APPEND Boost_ERROR_REASON_THREAD " (missing dependency: Threads)")
+ set(Boost_THREAD_FOUND OFF)
+ endif()
endif()
endif()
@@ -361,30 +646,27 @@ macro(_Boost_FIND_LIBRARY var build_type)
# If Boost_LIBRARY_DIR_[RELEASE,DEBUG] is known then search only there.
if(Boost_LIBRARY_DIR_${build_type})
set(_boost_LIBRARY_SEARCH_DIRS_${build_type} ${Boost_LIBRARY_DIR_${build_type}} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
- if(Boost_DEBUG)
- message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
- " Boost_LIBRARY_DIR_${build_type} = ${Boost_LIBRARY_DIR_${build_type}}"
- " _boost_LIBRARY_SEARCH_DIRS_${build_type} = ${_boost_LIBRARY_SEARCH_DIRS_${build_type}}")
- endif()
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "Boost_LIBRARY_DIR_${build_type}")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "_boost_LIBRARY_SEARCH_DIRS_${build_type}")
endif()
endmacro()
#-------------------------------------------------------------------------------
-#
-# Runs compiler with "-dumpversion" and parses major/minor
-# version with a regex.
-#
-function(_Boost_COMPILER_DUMPVERSION _OUTPUT_VERSION)
+# Convert CMAKE_CXX_COMPILER_VERSION to boost compiler suffix version.
+function(_Boost_COMPILER_DUMPVERSION _OUTPUT_VERSION _OUTPUT_VERSION_MAJOR _OUTPUT_VERSION_MINOR)
+ string(REGEX REPLACE "([0-9]+)\\.([0-9]+)(\\.[0-9]+)?" "\\1"
+ _boost_COMPILER_VERSION_MAJOR "${CMAKE_CXX_COMPILER_VERSION}")
+ string(REGEX REPLACE "([0-9]+)\\.([0-9]+)(\\.[0-9]+)?" "\\2"
+ _boost_COMPILER_VERSION_MINOR "${CMAKE_CXX_COMPILER_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(_boost_COMPILER_VERSION "${_boost_COMPILER_VERSION_MAJOR}${_boost_COMPILER_VERSION_MINOR}")
set(${_OUTPUT_VERSION} ${_boost_COMPILER_VERSION} PARENT_SCOPE)
+ set(${_OUTPUT_VERSION_MAJOR} ${_boost_COMPILER_VERSION_MAJOR} PARENT_SCOPE)
+ set(${_OUTPUT_VERSION_MINOR} ${_boost_COMPILER_VERSION_MINOR} PARENT_SCOPE)
endfunction()
#
@@ -419,9 +701,7 @@ 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("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntel")
if(WIN32)
set (_boost_COMPILER "-iw")
else()
@@ -429,21 +709,20 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret)
endif()
elseif (GHSMULTI)
set(_boost_COMPILER "-ghs")
- elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
- if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10)
- set(_boost_COMPILER "-vc141;-vc140")
- elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
- set(_boost_COMPILER "-vc140")
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18)
- set(_boost_COMPILER "-vc120")
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17)
- set(_boost_COMPILER "-vc110")
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
- set(_boost_COMPILER "-vc100")
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
- set(_boost_COMPILER "-vc90")
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
- set(_boost_COMPILER "-vc80")
+ elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ if(MSVC_TOOLSET_VERSION GREATER_EQUAL 150)
+ # Not yet known.
+ set(_boost_COMPILER "")
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 140)
+ # MSVC toolset 14.x versions are forward compatible.
+ set(_boost_COMPILER "")
+ foreach(v 9 8 7 6 5 4 3 2 1 0)
+ if(MSVC_TOOLSET_VERSION GREATER_EQUAL 14${v})
+ list(APPEND _boost_COMPILER "-vc14${v}")
+ endif()
+ endforeach()
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80)
+ set(_boost_COMPILER "-vc${MSVC_TOOLSET_VERSION}")
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.10)
set(_boost_COMPILER "-vc71")
elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13) # Good luck!
@@ -451,6 +730,12 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret)
else() # VS 6.0 Good luck!
set(_boost_COMPILER "-vc6") # yes, this is correct
endif()
+
+ if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang")
+ string(REPLACE "." ";" VERSION_LIST "${CMAKE_CXX_COMPILER_VERSION}")
+ list(GET VERSION_LIST 0 CLANG_VERSION_MAJOR)
+ set(_boost_COMPILER "-clangw${CLANG_VERSION_MAJOR};${_boost_COMPILER}")
+ endif()
elseif (BORLAND)
set(_boost_COMPILER "-bcb")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
@@ -458,44 +743,52 @@ function(_Boost_GUESS_COMPILER_PREFIX _ret)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "XL")
set(_boost_COMPILER "-xlc")
elseif (MINGW)
- if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34)
+ if(Boost_VERSION_STRING VERSION_LESS 1.34)
set(_boost_COMPILER "-mgw") # no GCC version encoding prior to 1.34
else()
- _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION)
+ _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION _boost_COMPILER_VERSION_MAJOR _boost_COMPILER_VERSION_MINOR)
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)
+ _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION _boost_COMPILER_VERSION_MAJOR _boost_COMPILER_VERSION_MINOR)
+ if(NOT Boost_VERSION_STRING VERSION_LESS 1.69.0)
+ # From GCC 5 and clang 4, versioning changes and minor becomes patch.
+ # For those compilers, patch is exclude from compiler tag in Boost 1.69+ library naming.
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND _boost_COMPILER_VERSION_MAJOR VERSION_GREATER 4)
+ set(_boost_COMPILER_VERSION "${_boost_COMPILER_VERSION_MAJOR}")
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND _boost_COMPILER_VERSION_MAJOR VERSION_GREATER 3)
+ set(_boost_COMPILER_VERSION "${_boost_COMPILER_VERSION_MAJOR}")
+ endif()
+ endif()
+
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ if(Boost_VERSION_STRING 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.
+ if(Boost_VERSION_STRING VERSION_LESS 1.36.0)
+ # In Boost <= 1.35.0, there is no mangled compiler name for
+ # the macOS/Darwin version of GCC.
set(_boost_COMPILER "")
+ else()
+ # In Boost 1.36.0 and newer, the mangled compiler name used
+ # on macOS/Darwin is "xgcc".
+ set(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}")
endif()
else()
set(_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
endif()
endif()
- endif ()
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+ # TODO: Find out any Boost version constraints vs clang support.
+ set(_boost_COMPILER "-clang${_boost_COMPILER_VERSION}")
+ endif()
else()
- # TODO at least Boost_DEBUG here?
set(_boost_COMPILER "")
endif()
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "_boost_COMPILER" SOURCE "guessed")
set(${_ret} ${_boost_COMPILER} PARENT_SCOPE)
endfunction()
@@ -533,125 +826,131 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
# - Indent
# s;^set(; set(;;
# - Add conditionals
- # s;Scanning /path/to/boost/sources/boost_\(.*\)_\(.*\)_\(.*); elseif(NOT Boost_VERSION VERSION_LESS \10\20\3 AND Boost_VERSION VERSION_LESS xxxx);
+ # s;Scanning /path/to/boost/sources/boost_\(.*\)_\(.*\)_\(.*); elseif(NOT Boost_VERSION_STRING VERSION_LESS \1\.\2\.\3 AND Boost_VERSION_STRING VERSION_LESS xxxx);
#
# This results in the logic seen below, but will require the xxxx
# replacing with the following Boost release version (or the next
# minor version to be released, e.g. 1.59 was the latest at the time
- # of writing, making 1.60 the next, so 106000 is the needed version
- # number). Identical consecutive releases were then merged together
- # by updating the end range of the first block and removing the
- # following redundant blocks.
+ # of writing, making 1.60 the next. Identical consecutive releases
+ # were then merged together by updating the end range of the first
+ # block and removing the following redundant blocks.
#
# Running the script against all historical releases should be
# required only if the BoostScanDeps.cmake script logic is changed.
# The addition of a new release should only require it to be run
# against the new release.
+
+ # Handle Python version suffixes
+ if(component MATCHES "^(python|mpi_python|numpy)([0-9][0-9]?|[0-9]\\.[0-9])\$")
+ set(component "${CMAKE_MATCH_1}")
+ set(component_python_version "${CMAKE_MATCH_2}")
+ endif()
+
set(_Boost_IMPORTED_TARGETS TRUE)
- if(Boost_VERSION VERSION_LESS 103300)
- message(WARNING "Imported targets and dependency information not available for Boost version ${Boost_VERSION} (all versions older than 1.33)")
+ if(Boost_VERSION_STRING AND Boost_VERSION_STRING VERSION_LESS 1.33.0)
+ message(WARNING "Imported targets and dependency information not available for Boost version ${Boost_VERSION_STRING} (all versions older than 1.33)")
set(_Boost_IMPORTED_TARGETS FALSE)
- elseif(NOT Boost_VERSION VERSION_LESS 103300 AND Boost_VERSION VERSION_LESS 103500)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.33.0 AND Boost_VERSION_STRING VERSION_LESS 1.35.0)
set(_Boost_IOSTREAMS_DEPENDENCIES regex thread)
set(_Boost_REGEX_DEPENDENCIES thread)
set(_Boost_WAVE_DEPENDENCIES filesystem thread)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 103500 AND Boost_VERSION VERSION_LESS 103600)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.35.0 AND Boost_VERSION_STRING VERSION_LESS 1.36.0)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_WAVE_DEPENDENCIES filesystem system thread)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 103600 AND Boost_VERSION VERSION_LESS 103800)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.36.0 AND Boost_VERSION_STRING VERSION_LESS 1.38.0)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_WAVE_DEPENDENCIES filesystem system thread)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 103800 AND Boost_VERSION VERSION_LESS 104300)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.38.0 AND Boost_VERSION_STRING VERSION_LESS 1.43.0)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES date_time)
set(_Boost_WAVE_DEPENDENCIES filesystem system thread date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 104300 AND Boost_VERSION VERSION_LESS 104400)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.43.0 AND Boost_VERSION_STRING VERSION_LESS 1.44.0)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES date_time)
set(_Boost_WAVE_DEPENDENCIES filesystem system thread date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 104400 AND Boost_VERSION VERSION_LESS 104500)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.44.0 AND Boost_VERSION_STRING VERSION_LESS 1.45.0)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random serialization)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES date_time)
set(_Boost_WAVE_DEPENDENCIES serialization filesystem system thread date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 104500 AND Boost_VERSION VERSION_LESS 104700)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.45.0 AND Boost_VERSION_STRING VERSION_LESS 1.47.0)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES date_time)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 104700 AND Boost_VERSION VERSION_LESS 104800)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.47.0 AND Boost_VERSION_STRING VERSION_LESS 1.48.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES date_time)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 104800 AND Boost_VERSION VERSION_LESS 105000)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.48.0 AND Boost_VERSION_STRING VERSION_LESS 1.50.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES date_time)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 105000 AND Boost_VERSION VERSION_LESS 105300)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.50.0 AND Boost_VERSION_STRING VERSION_LESS 1.53.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 105300 AND Boost_VERSION VERSION_LESS 105400)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.53.0 AND Boost_VERSION_STRING VERSION_LESS 1.54.0)
set(_Boost_ATOMIC_DEPENDENCIES thread chrono system date_time)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
set(_Boost_IOSTREAMS_DEPENDENCIES regex)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 105400 AND Boost_VERSION VERSION_LESS 105500)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.54.0 AND Boost_VERSION_STRING VERSION_LESS 1.55.0)
set(_Boost_ATOMIC_DEPENDENCIES thread chrono system date_time)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
@@ -659,12 +958,12 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 105500 AND Boost_VERSION VERSION_LESS 105600)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.55.0 AND Boost_VERSION_STRING VERSION_LESS 1.56.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_COROUTINE_DEPENDENCIES context system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
@@ -672,12 +971,12 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 105600 AND Boost_VERSION VERSION_LESS 105900)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.56.0 AND Boost_VERSION_STRING VERSION_LESS 1.59.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_COROUTINE_DEPENDENCIES context system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
@@ -685,13 +984,13 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_RANDOM_DEPENDENCIES system)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 105900 AND Boost_VERSION VERSION_LESS 106000)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.59.0 AND Boost_VERSION_STRING VERSION_LESS 1.60.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_COROUTINE_DEPENDENCIES context system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
@@ -699,13 +998,13 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono atomic)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_RANDOM_DEPENDENCIES system)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 106000 AND Boost_VERSION VERSION_LESS 106100)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.60.0 AND Boost_VERSION_STRING VERSION_LESS 1.61.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_COROUTINE_DEPENDENCIES context system)
set(_Boost_FILESYSTEM_DEPENDENCIES system)
@@ -713,13 +1012,13 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_RANDOM_DEPENDENCIES system)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_TIMER_DEPENDENCIES chrono system)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 106100 AND Boost_VERSION VERSION_LESS 106200)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.61.0 AND Boost_VERSION_STRING VERSION_LESS 1.62.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
set(_Boost_COROUTINE_DEPENDENCIES context system)
@@ -728,12 +1027,12 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_RANDOM_DEPENDENCIES system)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 106200 AND Boost_VERSION VERSION_LESS 106300)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.62.0 AND Boost_VERSION_STRING VERSION_LESS 1.63.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
set(_Boost_COROUTINE_DEPENDENCIES context system)
@@ -743,12 +1042,12 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_RANDOM_DEPENDENCIES system)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- elseif(NOT Boost_VERSION VERSION_LESS 106300 AND Boost_VERSION VERSION_LESS 106500)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.63.0 AND Boost_VERSION_STRING VERSION_LESS 1.65.0)
set(_Boost_CHRONO_DEPENDENCIES system)
set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
set(_Boost_COROUTINE_DEPENDENCIES context system)
@@ -759,32 +1058,93 @@ function(_Boost_COMPONENT_DEPENDENCIES component _ret)
set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
set(_Boost_RANDOM_DEPENDENCIES system)
set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- else()
- if(NOT Boost_VERSION VERSION_LESS 106500)
- set(_Boost_CHRONO_DEPENDENCIES system)
- set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
- set(_Boost_COROUTINE_DEPENDENCIES context system)
- set(_Boost_FIBER_DEPENDENCIES context thread chrono system date_time)
- set(_Boost_FILESYSTEM_DEPENDENCIES system)
- set(_Boost_IOSTREAMS_DEPENDENCIES regex)
- set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
- set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
- set(_Boost_MPI_DEPENDENCIES serialization)
- set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization)
- set(_Boost_NUMPY_DEPENDENCIES python)
- set(_Boost_RANDOM_DEPENDENCIES system)
- set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
- set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
- set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
- endif()
- if(NOT Boost_VERSION VERSION_LESS 106600)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.65.0 AND Boost_VERSION_STRING VERSION_LESS 1.67.0)
+ set(_Boost_CHRONO_DEPENDENCIES system)
+ set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
+ set(_Boost_COROUTINE_DEPENDENCIES context system)
+ set(_Boost_FIBER_DEPENDENCIES context thread chrono system date_time)
+ set(_Boost_FILESYSTEM_DEPENDENCIES system)
+ set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+ set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
+ set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+ set(_Boost_MPI_DEPENDENCIES serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
+ set(_Boost_NUMPY_DEPENDENCIES python${component_python_version})
+ set(_Boost_RANDOM_DEPENDENCIES system)
+ set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+ set(_Boost_TIMER_DEPENDENCIES chrono system)
+ set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+ set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.67.0 AND Boost_VERSION_STRING VERSION_LESS 1.68.0)
+ set(_Boost_CHRONO_DEPENDENCIES system)
+ set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
+ set(_Boost_COROUTINE_DEPENDENCIES context system)
+ set(_Boost_FIBER_DEPENDENCIES context thread chrono system date_time)
+ set(_Boost_FILESYSTEM_DEPENDENCIES system)
+ set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+ set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
+ set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+ set(_Boost_MPI_DEPENDENCIES serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
+ set(_Boost_NUMPY_DEPENDENCIES python${component_python_version})
+ set(_Boost_RANDOM_DEPENDENCIES system)
+ set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+ set(_Boost_TIMER_DEPENDENCIES chrono system)
+ set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+ set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.68.0 AND Boost_VERSION_STRING VERSION_LESS 1.69.0)
+ set(_Boost_CHRONO_DEPENDENCIES system)
+ set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time)
+ set(_Boost_CONTRACT_DEPENDENCIES thread chrono system date_time)
+ set(_Boost_COROUTINE_DEPENDENCIES context system)
+ set(_Boost_FIBER_DEPENDENCIES context thread chrono system date_time)
+ set(_Boost_FILESYSTEM_DEPENDENCIES system)
+ set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+ set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic)
+ set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+ set(_Boost_MPI_DEPENDENCIES serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
+ set(_Boost_NUMPY_DEPENDENCIES python${component_python_version})
+ set(_Boost_RANDOM_DEPENDENCIES system)
+ set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic)
+ set(_Boost_TIMER_DEPENDENCIES chrono system)
+ set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic)
+ set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.69.0 AND Boost_VERSION_STRING VERSION_LESS 1.70.0)
+ set(_Boost_CONTRACT_DEPENDENCIES thread chrono date_time)
+ set(_Boost_COROUTINE_DEPENDENCIES context)
+ set(_Boost_FIBER_DEPENDENCIES context)
+ set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+ set(_Boost_LOG_DEPENDENCIES date_time log_setup filesystem thread regex chrono atomic)
+ set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+ set(_Boost_MPI_DEPENDENCIES serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
+ set(_Boost_NUMPY_DEPENDENCIES python${component_python_version})
+ set(_Boost_THREAD_DEPENDENCIES chrono date_time atomic)
+ set(_Boost_TIMER_DEPENDENCIES chrono system)
+ set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic)
+ set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+ elseif(NOT Boost_VERSION_STRING VERSION_LESS 1.70.0)
+ set(_Boost_CONTRACT_DEPENDENCIES thread chrono date_time)
+ set(_Boost_COROUTINE_DEPENDENCIES context)
+ set(_Boost_FIBER_DEPENDENCIES context)
+ set(_Boost_IOSTREAMS_DEPENDENCIES regex)
+ set(_Boost_LOG_DEPENDENCIES date_time log_setup filesystem thread regex chrono atomic)
+ set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic)
+ set(_Boost_MPI_DEPENDENCIES serialization)
+ set(_Boost_MPI_PYTHON_DEPENDENCIES python${component_python_version} mpi serialization)
+ set(_Boost_NUMPY_DEPENDENCIES python${component_python_version})
+ set(_Boost_THREAD_DEPENDENCIES chrono date_time atomic)
+ set(_Boost_TIMER_DEPENDENCIES chrono)
+ set(_Boost_WAVE_DEPENDENCIES filesystem serialization thread chrono date_time atomic)
+ set(_Boost_WSERIALIZATION_DEPENDENCIES serialization)
+ if(NOT Boost_VERSION_STRING VERSION_LESS 1.72.0)
message(WARNING "New Boost version may have incorrect or missing dependencies and imported targets")
- set(_Boost_IMPORTED_TARGETS FALSE)
endif()
endif()
@@ -809,15 +1169,26 @@ endfunction()
# _hdrs
#
function(_Boost_COMPONENT_HEADERS component _hdrs)
+ # Handle Python version suffixes
+ if(component MATCHES "^(python|mpi_python|numpy)([0-9][0-9]?|[0-9]\\.[0-9])\$")
+ set(component "${CMAKE_MATCH_1}")
+ set(component_python_version "${CMAKE_MATCH_2}")
+ endif()
+
# Note: new boost components will require adding here. The header
# must be present in all versions of Boost providing a library.
set(_Boost_ATOMIC_HEADERS "boost/atomic.hpp")
set(_Boost_CHRONO_HEADERS "boost/chrono.hpp")
set(_Boost_CONTAINER_HEADERS "boost/container/container_fwd.hpp")
- set(_Boost_CONTEXT_HEADERS "boost/context/all.hpp")
+ set(_Boost_CONTRACT_HEADERS "boost/contract.hpp")
+ if(Boost_VERSION_STRING VERSION_LESS 1.61.0)
+ set(_Boost_CONTEXT_HEADERS "boost/context/all.hpp")
+ else()
+ set(_Boost_CONTEXT_HEADERS "boost/context/detail/fcontext.hpp")
+ endif()
set(_Boost_COROUTINE_HEADERS "boost/coroutine/all.hpp")
- set(_Boost_EXCEPTION_HEADERS "boost/exception/exception.hpp")
set(_Boost_DATE_TIME_HEADERS "boost/date_time/date.hpp")
+ set(_Boost_EXCEPTION_HEADERS "boost/exception/exception.hpp")
set(_Boost_FIBER_HEADERS "boost/fiber/all.hpp")
set(_Boost_FILESYSTEM_HEADERS "boost/filesystem/path.hpp")
set(_Boost_GRAPH_HEADERS "boost/graph/adjacency_list.hpp")
@@ -843,6 +1214,12 @@ function(_Boost_COMPONENT_HEADERS component _hdrs)
set(_Boost_REGEX_HEADERS "boost/regex.hpp")
set(_Boost_SERIALIZATION_HEADERS "boost/serialization/serialization.hpp")
set(_Boost_SIGNALS_HEADERS "boost/signals.hpp")
+ set(_Boost_STACKTRACE_ADDR2LINE_HEADERS "boost/stacktrace.hpp")
+ set(_Boost_STACKTRACE_BACKTRACE_HEADERS "boost/stacktrace.hpp")
+ set(_Boost_STACKTRACE_BASIC_HEADERS "boost/stacktrace.hpp")
+ set(_Boost_STACKTRACE_NOOP_HEADERS "boost/stacktrace.hpp")
+ set(_Boost_STACKTRACE_WINDBG_CACHED_HEADERS "boost/stacktrace.hpp")
+ set(_Boost_STACKTRACE_WINDBG_HEADERS "boost/stacktrace.hpp")
set(_Boost_SYSTEM_HEADERS "boost/system/config.hpp")
set(_Boost_TEST_EXEC_MONITOR_HEADERS "boost/test/test_exec_monitor.hpp")
set(_Boost_THREAD_HEADERS "boost/thread.hpp")
@@ -893,9 +1270,7 @@ function(_Boost_MISSING_DEPENDENCIES componentvar extravar)
set(_Boost_${uppercomponent}_DEPENDENCIES ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE)
set(_Boost_IMPORTED_TARGETS ${_Boost_IMPORTED_TARGETS} PARENT_SCOPE)
foreach(componentdep ${_Boost_${uppercomponent}_DEPENDENCIES})
- list(FIND _boost_processed_components "${componentdep}" _boost_component_found)
- list(FIND _boost_new_components "${componentdep}" _boost_component_new)
- if (_boost_component_found EQUAL -1 AND _boost_component_new EQUAL -1)
+ if (NOT ("${componentdep}" IN_LIST _boost_processed_components OR "${componentdep}" IN_LIST _boost_new_components))
list(APPEND _boost_new_components ${componentdep})
endif()
endforeach()
@@ -915,11 +1290,17 @@ endfunction()
# Some boost libraries may require particular set of compler features.
# The very first one was `boost::fiber` introduced in Boost 1.62.
# One can check required compiler features of it in
-# `${Boost_ROOT}/libs/fiber/build/Jamfile.v2`.
+# - `${Boost_ROOT}/libs/fiber/build/Jamfile.v2`;
+# - `${Boost_ROOT}/libs/context/build/Jamfile.v2`.
+#
+# TODO (Re)Check compiler features on (every?) release ???
+# One may use the following command to get the files to check:
+#
+# $ find . -name Jamfile.v2 | grep build | xargs grep -l cxx1
#
function(_Boost_COMPILER_FEATURES component _ret)
- # Boost >= 1.62 and < 1.65
- if(NOT Boost_VERSION VERSION_LESS 106200 AND Boost_VERSION VERSION_LESS 106500)
+ # Boost >= 1.62
+ if(NOT Boost_VERSION_STRING VERSION_LESS 1.62.0)
set(_Boost_FIBER_COMPILER_FEATURES
cxx_alias_templates
cxx_auto_type
@@ -933,7 +1314,19 @@ function(_Boost_COMPILER_FEATURES component _ret)
cxx_thread_local
cxx_variadic_templates
)
+ # Compiler feature for `context` same as for `fiber`.
+ set(_Boost_CONTEXT_COMPILER_FEATURES ${_Boost_FIBER_COMPILER_FEATURES})
+ endif()
+
+ # Boost Contract library available in >= 1.67
+ if(NOT Boost_VERSION_STRING VERSION_LESS 1.67.0)
+ # From `libs/contract/build/boost_contract_build.jam`
+ set(_Boost_CONTRACT_COMPILER_FEATURES
+ cxx_lambdas
+ cxx_variadic_templates
+ )
endif()
+
string(TOUPPER ${component} uppercomponent)
set(${_ret} ${_Boost_${uppercomponent}_COMPILER_FEATURES} PARENT_SCOPE)
endfunction()
@@ -953,21 +1346,18 @@ function(_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS component
else()
set(_arch_suffix 32)
endif()
- if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.1)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0)
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0)
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-12.0)
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-11.0)
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-10.0)
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-9.0)
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
- list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-8.0)
+ if(MSVC_TOOLSET_VERSION GREATER_EQUAL 150)
+ # Not yet known.
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 140)
+ # MSVC toolset 14.x versions are forward compatible.
+ foreach(v 9 8 7 6 5 4 3 2 1 0)
+ if(MSVC_TOOLSET_VERSION GREATER_EQUAL 14${v})
+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.${v})
+ endif()
+ endforeach()
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80)
+ math(EXPR _toolset_major_version "${MSVC_TOOLSET_VERSION} / 10")
+ list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-${_toolset_major_version}.0)
endif()
set(${componentlibvar} ${${componentlibvar}} PARENT_SCOPE)
endif()
@@ -992,8 +1382,14 @@ if(NOT Boost_LIBRARY_DIR_DEBUG AND Boost_LIBRARY_DIR)
set(Boost_LIBRARY_DIR_DEBUG "${Boost_LIBRARY_DIR}")
endif()
+if(NOT DEFINED Boost_USE_DEBUG_LIBS)
+ set(Boost_USE_DEBUG_LIBS TRUE)
+endif()
+if(NOT DEFINED Boost_USE_RELEASE_LIBS)
+ set(Boost_USE_RELEASE_LIBS TRUE)
+endif()
if(NOT DEFINED Boost_USE_MULTITHREADED)
- set(Boost_USE_MULTITHREADED TRUE)
+ set(Boost_USE_MULTITHREADED TRUE)
endif()
if(NOT DEFINED Boost_USE_DEBUG_RUNTIME)
set(Boost_USE_DEBUG_RUNTIME TRUE)
@@ -1019,7 +1415,8 @@ else()
# _Boost_COMPONENT_HEADERS. See the instructions at the top of
# _Boost_COMPONENT_DEPENDENCIES.
set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
- "1.65.1" "1.65.0" "1.65"
+ "1.71.0" "1.71" "1.70.0" "1.70" "1.69.0" "1.69"
+ "1.68.0" "1.68" "1.67.0" "1.67" "1.66.0" "1.66" "1.65.1" "1.65.0" "1.65"
"1.64.0" "1.64" "1.63.0" "1.63" "1.62.0" "1.62" "1.61.0" "1.61" "1.60.0" "1.60"
"1.59.0" "1.59" "1.58.0" "1.58" "1.57.0" "1.57" "1.56.0" "1.56" "1.55.0" "1.55"
"1.54.0" "1.54" "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51"
@@ -1049,26 +1446,12 @@ else()
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()
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_TEST_VERSIONS")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_USE_MULTITHREADED")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_USE_STATIC_LIBS")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_USE_STATIC_RUNTIME")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_ADDITIONAL_VERSIONS")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_NO_SYSTEM_PATHS")
# Supply Boost_LIB_DIAGNOSTIC_DEFINITIONS as a convenience target. It
# will only contain any interface definitions on WIN32, but is created
@@ -1079,6 +1462,8 @@ if(NOT TARGET Boost::diagnostic_definitions)
add_library(Boost::diagnostic_definitions INTERFACE IMPORTED)
add_library(Boost::disable_autolinking INTERFACE IMPORTED)
add_library(Boost::dynamic_linking INTERFACE IMPORTED)
+ set_target_properties(Boost::dynamic_linking PROPERTIES
+ INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK")
endif()
if(WIN32)
# In windows, automatic linking is performed, so you do not have
@@ -1103,11 +1488,13 @@ if(WIN32)
INTERFACE_COMPILE_DEFINITIONS "BOOST_LIB_DIAGNOSTIC")
set_target_properties(Boost::disable_autolinking PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB")
- set_target_properties(Boost::dynamic_linking PROPERTIES
- INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK")
endif()
-_Boost_CHECK_SPELLING(Boost_ROOT)
+cmake_policy(GET CMP0074 _Boost_CMP0074)
+if(NOT "x${_Boost_CMP0074}x" STREQUAL "xNEWx")
+ _Boost_CHECK_SPELLING(Boost_ROOT)
+endif()
+unset(_Boost_CMP0074)
_Boost_CHECK_SPELLING(Boost_LIBRARYDIR)
_Boost_CHECK_SPELLING(Boost_INCLUDEDIR)
@@ -1133,18 +1520,12 @@ set(_Boost_VARS_DIR
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()
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "BOOST_ROOT")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "BOOST_ROOT" ENVIRONMENT)
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "BOOST_INCLUDEDIR")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "BOOST_INCLUDEDIR" ENVIRONMENT)
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "BOOST_LIBRARYDIR")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "BOOST_LIBRARYDIR" ENVIRONMENT)
# ------------------------------------------------------------------------
# Search for Boost include DIR
@@ -1176,7 +1557,7 @@ if(NOT Boost_INCLUDE_DIR)
list(APPEND _boost_INCLUDE_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH)
else()
if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
- foreach(ver ${_Boost_KNOWN_VERSIONS})
+ foreach(ver ${_boost_TEST_VERSIONS})
string(REPLACE "." "_" ver "${ver}")
list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS "C:/local/boost_${ver}")
endforeach()
@@ -1216,14 +1597,8 @@ if(NOT Boost_INCLUDE_DIR)
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()
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_INCLUDE_SEARCH_DIRS")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_PATH_SUFFIXES")
# Look for a standard boost header file.
find_path(Boost_INCLUDE_DIR
@@ -1237,73 +1612,54 @@ 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()
+ _Boost_DEBUG_PRINT("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp")
- # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
- set(Boost_VERSION 0)
+ # Extract Boost_VERSION_MACRO and Boost_LIB_VERSION from version.hpp
+ set(Boost_VERSION_MACRO 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()
+ if("${_boost_VERSION_HPP_CONTENTS}" MATCHES "#define BOOST_VERSION ([0-9]+)")
+ set(Boost_VERSION_MACRO "${CMAKE_MATCH_1}")
+ endif()
+ if("${_boost_VERSION_HPP_CONTENTS}" MATCHES "#define BOOST_LIB_VERSION \"([0-9_]+)\"")
+ set(Boost_LIB_VERSION "${CMAKE_MATCH_1}")
+ endif()
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")
+ # Calculate version components
+ math(EXPR Boost_VERSION_MAJOR "${Boost_VERSION_MACRO} / 100000")
+ math(EXPR Boost_VERSION_MINOR "${Boost_VERSION_MACRO} / 100 % 1000")
+ math(EXPR Boost_VERSION_PATCH "${Boost_VERSION_MACRO} % 100")
+ set(Boost_VERSION_COUNT 3)
- string(APPEND 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()
+ # Define alias variables for backwards compat.
+ set(Boost_MAJOR_VERSION ${Boost_VERSION_MAJOR})
+ set(Boost_MINOR_VERSION ${Boost_VERSION_MINOR})
+ set(Boost_SUBMINOR_VERSION ${Boost_VERSION_PATCH})
- 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.
- string(APPEND 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)
- string(APPEND Boost_ERROR_REASON
- ".${Boost_FIND_VERSION_PATCH}")
- endif ()
- if (NOT Boost_FIND_VERSION_EXACT)
- string(APPEND Boost_ERROR_REASON " (or newer)")
- endif ()
- string(APPEND Boost_ERROR_REASON ".")
- endif ()
+ # Define Boost version in x.y.z format
+ set(Boost_VERSION_STRING "${Boost_VERSION_MAJOR}.${Boost_VERSION_MINOR}.${Boost_VERSION_PATCH}")
+
+ # Define final Boost_VERSION
+ cmake_policy(GET CMP0093 _Boost_CMP0093
+ PARENT_SCOPE # undocumented, do not use outside of CMake
+ )
+ if("x${_Boost_CMP0093}x" STREQUAL "xNEWx")
+ set(Boost_VERSION ${Boost_VERSION_STRING})
else()
- # Caller will accept any Boost version.
- set(Boost_FOUND 1)
+ set(Boost_VERSION ${Boost_VERSION_MACRO})
endif()
-else()
- set(Boost_FOUND 0)
- string(APPEND 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.")
+ unset(_Boost_CMP0093)
+
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_VERSION")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_VERSION_STRING")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_VERSION_MACRO")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_VERSION_MAJOR")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_VERSION_MINOR")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_VERSION_PATCH")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_VERSION_COUNT")
endif()
# ------------------------------------------------------------------------
@@ -1320,6 +1676,9 @@ if ( NOT Boost_NAMESPACE )
set(Boost_NAMESPACE "boost")
endif()
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_LIB_PREFIX")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "Boost_NAMESPACE")
+
# ------------------------------------------------------------------------
# Suffix initialization and compiler suffix detection.
# ------------------------------------------------------------------------
@@ -1340,34 +1699,28 @@ _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()
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "_boost_COMPILER" SOURCE "user-specified via Boost_COMPILER")
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()
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_MULTITHREADED")
#======================
-# Systematically build up the Boost ABI tag
-# http://boost.org/doc/libs/1_41_0/more/getting_started/windows.html#library-naming
+# Systematically build up the Boost ABI tag for the 'tagged' and 'versioned' layouts
+# http://boost.org/doc/libs/1_66_0/more/getting_started/windows.html#library-naming
+# http://boost.org/doc/libs/1_66_0/boost/config/auto_link.hpp
+# http://boost.org/doc/libs/1_66_0/tools/build/src/tools/common.jam
+# http://boost.org/doc/libs/1_66_0/boostcpp.jam
set( _boost_RELEASE_ABI_TAG "-")
set( _boost_DEBUG_ABI_TAG "-")
# Key Use this library when:
@@ -1381,8 +1734,8 @@ endif()
# support libraries
if(WIN32 AND Boost_USE_DEBUG_RUNTIME)
if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC"
- OR "${CMAKE_CXX_COMPILER}" MATCHES "icl"
- OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc")
+ OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang"
+ OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xIntel")
string(APPEND _boost_DEBUG_ABI_TAG "g")
endif()
endif()
@@ -1399,18 +1752,51 @@ if(Boost_USE_STLPORT)
string(APPEND _boost_DEBUG_ABI_TAG "p")
endif()
# n using the STLport deprecated "native iostreams" feature
+# removed from the documentation in 1.43.0 but still present in
+# boost/config/auto_link.hpp
if(Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS)
string(APPEND _boost_RELEASE_ABI_TAG "n")
string(APPEND _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}")
+# -x86 Architecture and address model tag
+# First character is the architecture, then word-size, either 32 or 64
+# Only used in 'versioned' layout, added in Boost 1.66.0
+if(DEFINED Boost_ARCHITECTURE)
+ set(_boost_ARCHITECTURE_TAG "${Boost_ARCHITECTURE}")
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "_boost_ARCHITECTURE_TAG" SOURCE "user-specified via Boost_ARCHITECTURE")
+else()
+ set(_boost_ARCHITECTURE_TAG "")
+ # {CMAKE_CXX_COMPILER_ARCHITECTURE_ID} is not currently set for all compilers
+ if(NOT "x${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "x" AND NOT Boost_VERSION_STRING VERSION_LESS 1.66.0)
+ string(APPEND _boost_ARCHITECTURE_TAG "-")
+ # This needs to be kept in-sync with the section of CMakePlatformId.h.in
+ # inside 'defined(_WIN32) && defined(_MSC_VER)'
+ if(CMAKE_CXX_COMPILER_ARCHITECTURE_ID STREQUAL "IA64")
+ string(APPEND _boost_ARCHITECTURE_TAG "i")
+ elseif(CMAKE_CXX_COMPILER_ARCHITECTURE_ID STREQUAL "X86"
+ OR CMAKE_CXX_COMPILER_ARCHITECTURE_ID STREQUAL "x64")
+ string(APPEND _boost_ARCHITECTURE_TAG "x")
+ elseif(CMAKE_CXX_COMPILER_ARCHITECTURE_ID MATCHES "^ARM")
+ string(APPEND _boost_ARCHITECTURE_TAG "a")
+ elseif(CMAKE_CXX_COMPILER_ARCHITECTURE_ID STREQUAL "MIPS")
+ string(APPEND _boost_ARCHITECTURE_TAG "m")
+ endif()
+
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ string(APPEND _boost_ARCHITECTURE_TAG "64")
+ else()
+ string(APPEND _boost_ARCHITECTURE_TAG "32")
+ endif()
+ endif()
+ _Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "_boost_ARCHITECTURE_TAG" SOURCE "detected")
endif()
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_RELEASE_ABI_TAG")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_DEBUG_ABI_TAG")
+
# ------------------------------------------------------------------------
# Begin finding boost libraries
# ------------------------------------------------------------------------
@@ -1451,10 +1837,11 @@ foreach(c DEBUG RELEASE)
${Boost_INCLUDE_DIR}/stage/lib
)
_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "${Boost_INCLUDE_DIR}/..")
+ _Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "${Boost_INCLUDE_DIR}")
if( Boost_NO_SYSTEM_PATHS )
list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH)
else()
- foreach(ver ${_Boost_KNOWN_VERSIONS})
+ foreach(ver ${_boost_TEST_VERSIONS})
string(REPLACE "." "_" ver "${ver}")
_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "C:/local/boost_${ver}")
endforeach()
@@ -1468,11 +1855,8 @@ foreach(c DEBUG RELEASE)
endif()
endforeach()
-if(Boost_DEBUG)
- message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
- "_boost_LIBRARY_SEARCH_DIRS_RELEASE = ${_boost_LIBRARY_SEARCH_DIRS_RELEASE}"
- "_boost_LIBRARY_SEARCH_DIRS_DEBUG = ${_boost_LIBRARY_SEARCH_DIRS_DEBUG}")
-endif()
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_LIBRARY_SEARCH_DIRS_RELEASE")
+_Boost_DEBUG_PRINT_VAR("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}" "_boost_LIBRARY_SEARCH_DIRS_DEBUG")
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
if( Boost_USE_STATIC_LIBS )
@@ -1512,10 +1896,10 @@ 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()
+if(Boost_VERSION_STRING AND Boost_FIND_COMPONENTS)
+ if(Boost_VERSION_STRING VERSION_LESS 1.35.0)
+ list(REMOVE_ITEM Boost_FIND_COMPONENTS system)
+ endif()
endif()
# Additional components may be required via component dependencies.
@@ -1523,10 +1907,14 @@ endif()
_Boost_MISSING_DEPENDENCIES(Boost_FIND_COMPONENTS _Boost_EXTRA_FIND_COMPONENTS)
# If thread is required, get the thread libs as a dependency
-list(FIND Boost_FIND_COMPONENTS thread _Boost_THREAD_DEPENDENCY_LIBS)
-if(NOT _Boost_THREAD_DEPENDENCY_LIBS EQUAL -1)
- include(CMakeFindDependencyMacro)
- find_dependency(Threads)
+if("thread" IN_LIST Boost_FIND_COMPONENTS)
+ if(Boost_FIND_QUIETLY)
+ set(_Boost_find_quiet QUIET)
+ else()
+ set(_Boost_find_quiet "")
+ endif()
+ find_package(Threads ${_Boost_find_quiet})
+ unset(_Boost_find_quiet)
endif()
# If the user changed any of our control inputs flush previous results.
@@ -1561,14 +1949,45 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
endforeach()
endif()
+ # Handle Python version suffixes
+ unset(COMPONENT_PYTHON_VERSION_MAJOR)
+ unset(COMPONENT_PYTHON_VERSION_MINOR)
+ if(${COMPONENT} MATCHES "^(python|mpi_python|numpy)([0-9])\$")
+ set(COMPONENT_UNVERSIONED "${CMAKE_MATCH_1}")
+ set(COMPONENT_PYTHON_VERSION_MAJOR "${CMAKE_MATCH_2}")
+ elseif(${COMPONENT} MATCHES "^(python|mpi_python|numpy)([0-9])\\.?([0-9])\$")
+ set(COMPONENT_UNVERSIONED "${CMAKE_MATCH_1}")
+ set(COMPONENT_PYTHON_VERSION_MAJOR "${CMAKE_MATCH_2}")
+ set(COMPONENT_PYTHON_VERSION_MINOR "${CMAKE_MATCH_3}")
+ endif()
+
+ unset(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME)
+ if (COMPONENT_PYTHON_VERSION_MINOR)
+ # Boost >= 1.67
+ list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}")
+ # Debian/Ubuntu (Some versions omit the 2 and/or 3 from the suffix)
+ list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}${COMPONENT_PYTHON_VERSION_MAJOR}-py${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}")
+ list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-py${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}")
+ # Gentoo
+ list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-${COMPONENT_PYTHON_VERSION_MAJOR}.${COMPONENT_PYTHON_VERSION_MINOR}")
+ # RPMs
+ list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}-${COMPONENT_PYTHON_VERSION_MAJOR}${COMPONENT_PYTHON_VERSION_MINOR}")
+ endif()
+ if (COMPONENT_PYTHON_VERSION_MAJOR AND NOT COMPONENT_PYTHON_VERSION_MINOR)
+ # Boost < 1.67
+ list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME "${COMPONENT_UNVERSIONED}${COMPONENT_PYTHON_VERSION_MAJOR}")
+ endif()
+
# Consolidate and report component-specific hints.
+ if(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME)
+ list(REMOVE_DUPLICATES _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME)
+ _Boost_DEBUG_PRINT("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "Component-specific library search names for ${COMPONENT_NAME}: ${_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME}")
+ endif()
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()
+ _Boost_DEBUG_PRINT("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "Component-specific library search paths for ${COMPONENT}: ${_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT}")
endif()
#
@@ -1591,33 +2010,38 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
# Find RELEASE libraries
#
unset(_boost_RELEASE_NAMES)
- foreach(compiler IN LISTS _boost_COMPILER)
- list(APPEND _boost_RELEASE_NAMES
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} )
- endforeach()
- list(APPEND _boost_RELEASE_NAMES
- ${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}")
+ foreach(component IN LISTS _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME COMPONENT)
foreach(compiler IN LISTS _boost_COMPILER)
list(APPEND _boost_RELEASE_NAMES
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} )
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} )
endforeach()
list(APPEND _boost_RELEASE_NAMES
- ${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()
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component} )
+ if(_boost_STATIC_RUNTIME_WORKAROUND)
+ set(_boost_RELEASE_STATIC_ABI_TAG "-s${_boost_RELEASE_ABI_TAG}")
+ foreach(compiler IN LISTS _boost_COMPILER)
+ list(APPEND _boost_RELEASE_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} )
+ endforeach()
+ list(APPEND _boost_RELEASE_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} )
+ endif()
+ endforeach()
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}")
+ _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_RELEASE_NAMES ${_boost_RELEASE_NAMES})
endif()
+ _Boost_DEBUG_PRINT("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "Searching for ${UPPERCOMPONENT}_LIBRARY_RELEASE: ${_boost_RELEASE_NAMES}")
# if Boost_LIBRARY_DIR_RELEASE is not defined,
# but Boost_LIBRARY_DIR_DEBUG is, look there first for RELEASE libs
@@ -1628,45 +2052,51 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
# Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing.
string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS_RELEASE}")
- _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE RELEASE
- NAMES ${_boost_RELEASE_NAMES}
- HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
- NAMES_PER_DIR
- DOC "${_boost_docstring_release}"
- )
+ if(Boost_USE_RELEASE_LIBS)
+ _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE RELEASE
+ NAMES ${_boost_RELEASE_NAMES}
+ HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
+ NAMES_PER_DIR
+ DOC "${_boost_docstring_release}"
+ )
+ endif()
#
# Find DEBUG libraries
#
unset(_boost_DEBUG_NAMES)
- foreach(compiler IN LISTS _boost_COMPILER)
- list(APPEND _boost_DEBUG_NAMES
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION}
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} )
- endforeach()
- list(APPEND _boost_DEBUG_NAMES
- ${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}")
+ foreach(component IN LISTS _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT_NAME COMPONENT)
foreach(compiler IN LISTS _boost_COMPILER)
list(APPEND _boost_DEBUG_NAMES
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
- ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} )
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} )
endforeach()
list(APPEND _boost_DEBUG_NAMES
- ${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()
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${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}")
+ foreach(compiler IN LISTS _boost_COMPILER)
+ list(APPEND _boost_DEBUG_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} )
+ endforeach()
+ list(APPEND _boost_DEBUG_NAMES
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}${_boost_ARCHITECTURE_TAG}
+ ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${component}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} )
+ endif()
+ endforeach()
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()
+ _Boost_DEBUG_PRINT("${CMAKE_CURRENT_LIST_FILE}" "${CMAKE_CURRENT_LIST_LINE}"
+ "Searching for ${UPPERCOMPONENT}_LIBRARY_DEBUG: ${_boost_DEBUG_NAMES}")
# if Boost_LIBRARY_DIR_DEBUG is not defined,
# but Boost_LIBRARY_DIR_RELEASE is, look there first for DEBUG libs
@@ -1677,12 +2107,14 @@ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
# Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing.
string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS_DEBUG}")
- _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG DEBUG
- NAMES ${_boost_DEBUG_NAMES}
- HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
- NAMES_PER_DIR
- DOC "${_boost_docstring_debug}"
- )
+ if(Boost_USE_DEBUG_LIBS)
+ _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG DEBUG
+ NAMES ${_boost_DEBUG_NAMES}
+ HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
+ NAMES_PER_DIR
+ DOC "${_boost_docstring_debug}"
+ )
+ endif ()
if(Boost_REALPATH)
_Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "${_boost_docstring_release}")
@@ -1717,57 +2149,25 @@ if(Boost_LIBRARY_DIRS)
list(REMOVE_DUPLICATES Boost_LIBRARY_DIRS)
endif()
-# 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_MISSING_COMPONENTS AND _Boost_EXTRA_FIND_COMPONENTS)
- # Optional indirect dependencies are not counted as missing.
- list(REMOVE_ITEM _Boost_MISSING_COMPONENTS ${_Boost_EXTRA_FIND_COMPONENTS})
- endif()
+# ------------------------------------------------------------------------
+# Call FPHSA helper, see https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html
+# ------------------------------------------------------------------------
- if(Boost_DEBUG)
- message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] Boost_FOUND = ${Boost_FOUND}")
+# Define aliases as needed by the component handler in the FPHSA helper below
+foreach(_comp IN LISTS Boost_FIND_COMPONENTS)
+ string(TOUPPER ${_comp} _uppercomp)
+ if(DEFINED Boost_${_uppercomp}_FOUND)
+ set(Boost_${_comp}_FOUND ${Boost_${_uppercomp}_FOUND})
endif()
+endforeach()
- 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.
- string(APPEND Boost_ERROR_REASON
- "\nCould not find the following")
- if(Boost_USE_STATIC_LIBS)
- string(APPEND Boost_ERROR_REASON " static")
- endif()
- string(APPEND Boost_ERROR_REASON
- " Boost libraries:\n")
- foreach(COMPONENT ${_Boost_MISSING_COMPONENTS})
- string(APPEND 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})
- string(APPEND 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 ()
- string(APPEND 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 ()
+find_package_handle_standard_args(Boost
+ REQUIRED_VARS Boost_INCLUDE_DIR
+ VERSION_VAR Boost_VERSION_STRING
+ HANDLE_COMPONENTS)
- if( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT )
+if(Boost_FOUND)
+ if( NOT Boost_LIBRARY_DIRS )
# Compatibility Code for backwards compatibility with CMake
# 2.4's FindBoost module.
@@ -1811,15 +2211,24 @@ endif()
# ------------------------------------------------------------------------
if(Boost_FOUND)
- # For header-only libraries
- if(NOT TARGET Boost::boost)
- add_library(Boost::boost INTERFACE IMPORTED)
+ # The builtin CMake package in Boost 1.70+ introduces a new name
+ # for the header-only lib, let's provide the same UI in module mode
+ if(NOT TARGET Boost::headers)
+ add_library(Boost::headers INTERFACE IMPORTED)
if(Boost_INCLUDE_DIRS)
- set_target_properties(Boost::boost PROPERTIES
+ set_target_properties(Boost::headers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}")
endif()
endif()
+ # Define the old target name for header-only libraries for backwards
+ # compat.
+ if(NOT TARGET Boost::boost)
+ add_library(Boost::boost INTERFACE IMPORTED)
+ set_target_properties(Boost::boost
+ PROPERTIES INTERFACE_LINK_LIBRARIES Boost::headers)
+ endif()
+
foreach(COMPONENT ${Boost_FIND_COMPONENTS})
if(_Boost_IMPORTED_TARGETS AND NOT TARGET Boost::${COMPONENT})
string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
@@ -1875,43 +2284,20 @@ if(Boost_FOUND)
endif()
# ------------------------------------------------------------------------
-# Notification to end user about what was found
+# Finalize
# ------------------------------------------------------------------------
+# Report Boost_LIBRARIES
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:")
+foreach(_comp IN LISTS Boost_FIND_COMPONENTS)
+ string(TOUPPER ${_comp} _uppercomp)
+ if(Boost_${_uppercomp}_FOUND)
+ list(APPEND Boost_LIBRARIES ${Boost_${_uppercomp}_LIBRARY})
+ if(_comp STREQUAL "thread")
+ list(APPEND Boost_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
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()
+endforeach()
# Configure display of cache entries in GUI.
foreach(v BOOSTROOT BOOST_ROOT ${_Boost_VARS_INC} ${_Boost_VARS_LIB})
@@ -1949,3 +2335,6 @@ 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.")
+
+# Restore project's policies
+cmake_policy(POP)
diff --git a/Modules/FindBullet.cmake b/Modules/FindBullet.cmake
index fc6695c35..6d6418521 100644
--- a/Modules/FindBullet.cmake
+++ b/Modules/FindBullet.cmake
@@ -1,39 +1,40 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
macro(_FIND_BULLET_LIBRARY _var)
find_library(${_var}
@@ -51,12 +52,12 @@ macro(_FIND_BULLET_LIBRARY _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()
+ 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
diff --git a/Modules/FindCABLE.cmake b/Modules/FindCABLE.cmake
index 450e32237..1f4ae7633 100644
--- a/Modules/FindCABLE.cmake
+++ b/Modules/FindCABLE.cmake
@@ -1,27 +1,28 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
if(NOT CABLE)
find_path(CABLE_BUILD_DIR cableVersion.h)
diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake
index a4dca5433..33155059a 100644
--- a/Modules/FindCUDA.cmake
+++ b/Modules/FindCUDA.cmake
@@ -1,340 +1,382 @@
-#.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_LINK_LIBRARIES_KEYWORD (Default "")
-# -- The <PRIVATE|PUBLIC|INTERFACE> keyword to use for internal
-# target_link_libraries calls. The default is to use no keyword which
-# uses the old "plain" form of target_link_libraries. Note that is matters
-# because whatever is used inside the FindCUDA module must also be used
-# outside - the two forms of target_link_libraries cannot be mixed.
-#
-# 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 within 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_SOURCE_PROPERTY_FORMAT
-# -- If this source file property is set, it can override the format specified
-# to CUDA_WRAP_SRCS (OBJ, PTX, CUBIN, or FATBIN). If an input source file
-# is not a .cu file, setting this file will cause it to be treated as a .cu
-# file. See documentation for set_source_files_properties on how to set
-# this property.
-#
-# CUDA_USE_STATIC_CUDA_RUNTIME (Default ON)
-# -- When enabled the static version of the CUDA runtime library will be used
-# in CUDA_LIBRARIES. If the version of CUDA configured doesn't support
-# this option, then it will be silently disabled.
-#
-# 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_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures])
-# -- Selects GPU arch flags for nvcc based on target_CUDA_architectures
-# target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...)
-# - "Auto" detects local machine GPU compute arch at runtime.
-# - "Common" and "All" cover common and entire subsets of architectures
-# ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX
-# NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal
-# NUM: Any number. Only those pairs are currently accepted by NVCC though:
-# 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2
-# Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable}
-# Additionally, sets ${out_variable}_readable to the resulting numeric list
-# Example:
-# CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell)
-# LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS})
-#
-# More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA
-# 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 precede 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_HAS_FP16 -- Whether a short float (float16,fp16) is supported.
-#
-# 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 (alternative to:
-# CUDA_ADD_CUBLAS_TO_TARGET macro).
-# CUDA_cudart_static_LIBRARY -- Statically linkable cuda runtime library.
-# Only available for CUDA version 5.5+
-# CUDA_cudadevrt_LIBRARY -- Device runtime library.
-# Required for separable compilation.
-# 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_cusolver_LIBRARY -- CUDA Direct Solver library.
-# Only available for CUDA version 7.0+.
-# CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library.
-# Only available for CUDA version 3.2+.
-# CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib.
-# Only available for CUDA version 4.0+.
-# CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core).
-# Only available for CUDA version 5.5+.
-# CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
-# Only available for CUDA version 5.5+.
-# CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (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.
-#
+#[=======================================================================[.rst:
+FindCUDA
+--------
+
+.. deprecated:: 3.10
+
+ Superseded by first-class support for the CUDA language in CMake.
+
+Replacement
+^^^^^^^^^^^
+
+It is no longer necessary to use this module or call ``find_package(CUDA)``.
+Instead, list ``CUDA`` among the languages named in the top-level
+call to the :command:`project` command, or call the
+:command:`enable_language` command with ``CUDA``.
+Then one can add CUDA (``.cu``) sources to programs directly
+in calls to :command:`add_library` and :command:`add_executable`.
+
+Documentation of Deprecated Usage
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+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 macOS and should be reasonably up to date with CUDA C
+releases.
+
+This script makes use of the standard :command:`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 :command:`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 alphabetical 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_LINK_LIBRARIES_KEYWORD (Default "")
+ -- The <PRIVATE|PUBLIC|INTERFACE> keyword to use for internal
+ target_link_libraries calls. The default is to use no keyword which
+ uses the old "plain" form of target_link_libraries. Note that is matters
+ because whatever is used inside the FindCUDA module must also be used
+ outside - the two forms of target_link_libraries cannot be mixed.
+
+ 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)
+ -- 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,
+ the host compiler is constructed with one or more visual studio macros
+ such as $(VCInstallDir), that expands out to the path when
+ the command is run from within VS.
+ If the CUDAHOSTCXX environment variable is set it will
+ be used as the default.
+
+ 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_SOURCE_PROPERTY_FORMAT
+ -- If this source file property is set, it can override the format specified
+ to CUDA_WRAP_SRCS (OBJ, PTX, CUBIN, or FATBIN). If an input source file
+ is not a .cu file, setting this file will cause it to be treated as a .cu
+ file. See documentation for set_source_files_properties on how to set
+ this property.
+
+ CUDA_USE_STATIC_CUDA_RUNTIME (Default ON)
+ -- When enabled the static version of the CUDA runtime library will be used
+ in CUDA_LIBRARIES. If the version of CUDA configured doesn't support
+ this option, then it will be silently disabled.
+
+ 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 alphabetical 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 convenience 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_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures])
+ -- Selects GPU arch flags for nvcc based on target_CUDA_architectures
+ target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...)
+ - "Auto" detects local machine GPU compute arch at runtime.
+ - "Common" and "All" cover common and entire subsets of architectures
+ ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX
+ NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal
+ NUM: Any number. Only those pairs are currently accepted by NVCC though:
+ 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2
+ Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable}
+ Additionally, sets ${out_variable}_readable to the resulting numeric list
+ Example:
+ CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell)
+ LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS})
+
+ More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA
+ 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 precede 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_HAS_FP16 -- Whether a short float (float16,fp16) is supported.
+
+ 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 (alternative to:
+ CUDA_ADD_CUBLAS_TO_TARGET macro).
+ CUDA_cudart_static_LIBRARY -- Statically linkable cuda runtime library.
+ Only available for CUDA version 5.5+
+ CUDA_cudadevrt_LIBRARY -- Device runtime library.
+ Required for separable compilation.
+ 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_cusolver_LIBRARY -- CUDA Direct Solver library.
+ Only available for CUDA version 7.0+.
+ CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library.
+ Only available for CUDA version 3.2+.
+ CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib.
+ Only available for CUDA version 4.0+.
+ CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core).
+ Only available for CUDA version 5.5+.
+ CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 5.5 - 8.0.
+ CUDA_nppial_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppicc_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppicom_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppidei_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppif_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppig_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppim_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppist_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppisu_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_nppitc_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
+ Only available for CUDA version 9.0.
+ CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (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
@@ -489,10 +531,18 @@ set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output fil
option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON)
# Extra user settable flags
-set(CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments.")
+cmake_initialize_per_config_variable(CUDA_NVCC_FLAGS "Semi-colon delimit multiple arguments.")
+
+if(DEFINED ENV{CUDAHOSTCXX})
+ set(CUDA_HOST_COMPILER "$ENV{CUDAHOSTCXX}" CACHE FILEPATH "Host side compiler used by NVCC")
+elseif(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)Tools/MSVC/$(VCToolsVersion)/bin/Host$(Platform)/$(PlatformTarget)")
+ if(MSVC_VERSION LESS 1910)
+ set(_CUDA_MSVC_HOST_COMPILER "$(VCInstallDir)bin")
+ endif()
+
+ set(CUDA_HOST_COMPILER "${_CUDA_MSVC_HOST_COMPILER}" CACHE FILEPATH "Host side compiler used by NVCC")
-if(CMAKE_GENERATOR MATCHES "Visual Studio")
- set(CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC")
else()
if(APPLE
AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang"
@@ -515,6 +565,11 @@ else()
set(c_compiler_realpath "")
endif()
set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC")
+ elseif(MSVC AND "${CMAKE_C_COMPILER}" MATCHES "clcache|sccache")
+ # NVCC does not think it will work if it is passed clcache.exe or sccache.exe
+ # as the host compiler, which means that builds with CC=cl.exe won't work.
+ # Best to just feed it whatever the actual cl.exe is as the host compiler.
+ set(CUDA_HOST_COMPILER "cl.exe" CACHE FILEPATH "Host side compiler used by NVCC")
else()
set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}"
CACHE FILEPATH "Host side compiler used by NVCC")
@@ -522,7 +577,7 @@ else()
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)
+option(CUDA_PROPAGATE_HOST_FLAGS "Propagate 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)
@@ -543,19 +598,17 @@ mark_as_advanced(
CUDA_SEPARABLE_COMPILATION
)
-# 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.
+# Single config generators like Makefiles or Ninja don't usually have
+# CMAKE_CONFIGURATION_TYPES defined (but note that it can be defined if set by
+# projects or developers). Even CMAKE_BUILD_TYPE might not be defined for
+# single config generators (and should not be defined for multi-config
+# generators). To ensure we get a complete superset of all possible
+# configurations, we combine CMAKE_CONFIGURATION_TYPES, CMAKE_BUILD_TYPE and
+# all of the standard configurations, then weed out duplicates with
+# list(REMOVE_DUPLICATES). Looping over the unique set then ensures we have
+# each configuration-specific set of nvcc flags defined and marked as advanced.
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()
###############################################################################
###############################################################################
@@ -589,7 +642,6 @@ macro(cuda_unset_include_and_libraries)
unset(CUDA_npps_LIBRARY CACHE)
unset(CUDA_nvcuvenc_LIBRARY CACHE)
unset(CUDA_nvcuvid_LIBRARY CACHE)
- unset(CUDA_USE_STATIC_CUDA_RUNTIME CACHE)
unset(CUDA_GPU_DETECT_OUTPUT CACHE)
endmacro()
@@ -632,8 +684,7 @@ if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING)
find_path(CUDA_TOOLKIT_ROOT_DIR
NAMES nvcc nvcc.exe
PATHS /opt/cuda/bin
- /usr/local/bin
- /usr/local/cuda/bin
+ PATH_SUFFIXES cuda/bin
DOC "Toolkit location."
)
@@ -679,7 +730,11 @@ if(CMAKE_CROSSCOMPILING)
# add known CUDA targetr root path to the set of directories we search for programs, libraries and headers
set( CMAKE_FIND_ROOT_PATH "${CUDA_TOOLKIT_TARGET_DIR};${CMAKE_FIND_ROOT_PATH}")
macro( cuda_find_host_program )
- find_host_program( ${ARGN} )
+ if (COMMAND find_host_program)
+ find_host_program( ${ARGN} )
+ else()
+ find_program( ${ARGN} )
+ endif()
endmacro()
else()
# for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR
@@ -691,16 +746,20 @@ endif()
# CUDA_NVCC_EXECUTABLE
-cuda_find_host_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.
-cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc)
+if(DEFINED ENV{CUDA_NVCC_EXECUTABLE})
+ set(CUDA_NVCC_EXECUTABLE "$ENV{CUDA_NVCC_EXECUTABLE}" CACHE FILEPATH "The CUDA compiler")
+else()
+ cuda_find_host_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.
+ cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc)
+endif()
mark_as_advanced(CUDA_NVCC_EXECUTABLE)
if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION)
@@ -798,12 +857,17 @@ endif()
if(CUDA_cudart_static_LIBRARY)
# If static cudart available, use it by default, but provide a user-visible option to disable it.
option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON)
- set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY)
else()
# If not available, silently disable the option.
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE INTERNAL "")
+endif()
+
+if(CUDA_USE_STATIC_CUDA_RUNTIME)
+ set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY)
+else()
set(CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY)
endif()
+
if(NOT CUDA_VERSION VERSION_LESS "5.0")
cuda_find_library_local_first(CUDA_cudadevrt_LIBRARY cudadevrt "\"cudadevrt\" library")
mark_as_advanced(CUDA_cudadevrt_LIBRARY)
@@ -811,11 +875,7 @@ endif()
if(CUDA_USE_STATIC_CUDA_RUNTIME)
if(UNIX)
- # Check for the dependent libraries. Here we look for pthreads.
- if (DEFINED CMAKE_THREAD_PREFER_PTHREAD)
- set(_cuda_cmake_thread_prefer_pthread ${CMAKE_THREAD_PREFER_PTHREAD})
- endif()
- set(CMAKE_THREAD_PREFER_PTHREAD 1)
+ # Check for the dependent libraries.
# Many of the FindXYZ CMake comes with makes use of try_compile with int main(){return 0;}
# as the source file. Unfortunately this causes a warning with -Wstrict-prototypes and
@@ -826,13 +886,6 @@ if(CUDA_USE_STATIC_CUDA_RUNTIME)
find_package(Threads REQUIRED)
set(CMAKE_C_FLAGS ${_cuda_cmake_c_flags})
- if (DEFINED _cuda_cmake_thread_prefer_pthread)
- set(CMAKE_THREAD_PREFER_PTHREAD ${_cuda_cmake_thread_prefer_pthread})
- unset(_cuda_cmake_thread_prefer_pthread)
- else()
- unset(CMAKE_THREAD_PREFER_PTHREAD)
- endif()
-
if(NOT APPLE)
#On Linux, you must link against librt when using the static cuda runtime.
find_library(CUDA_rt_LIBRARY rt)
@@ -915,9 +968,28 @@ if(NOT CUDA_VERSION VERSION_LESS "3.2")
find_cuda_helper_libs(nvcuvid)
endif()
endif()
-if(CUDA_VERSION VERSION_GREATER "5.0")
+if(CUDA_VERSION VERSION_GREATER "5.0" AND CUDA_VERSION VERSION_LESS "9.2")
+ # In CUDA 9.2 cublas_device was deprecated
find_cuda_helper_libs(cublas_device)
- # In CUDA 5.5 NPP was splitted onto 3 separate libraries.
+endif()
+
+if(NOT CUDA_VERSION VERSION_LESS "9.0")
+ # In CUDA 9.0 NPP was nppi was removed
+ find_cuda_helper_libs(nppc)
+ find_cuda_helper_libs(nppial)
+ find_cuda_helper_libs(nppicc)
+ find_cuda_helper_libs(nppicom)
+ find_cuda_helper_libs(nppidei)
+ find_cuda_helper_libs(nppif)
+ find_cuda_helper_libs(nppig)
+ find_cuda_helper_libs(nppim)
+ find_cuda_helper_libs(nppist)
+ find_cuda_helper_libs(nppisu)
+ find_cuda_helper_libs(nppitc)
+ find_cuda_helper_libs(npps)
+ set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
+elseif(CUDA_VERSION VERSION_GREATER "5.0")
+ # In CUDA 5.5 NPP was split into 3 separate libraries.
find_cuda_helper_libs(nppc)
find_cuda_helper_libs(nppi)
find_cuda_helper_libs(npps)
@@ -1255,11 +1327,11 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
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
+ # various macros from within VS. Note that CCBIN is only used if
# -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches
- # $(VCInstallDir)/bin.
+ # _CUDA_MSVC_HOST_COMPILER
if(CMAKE_GENERATOR MATCHES "Visual Studio")
- set(ccbin_flags -D "\"CCBIN:PATH=$(VCInstallDir)bin\"" )
+ set(ccbin_flags -D "\"CCBIN:PATH=${_CUDA_MSVC_HOST_COMPILER}\"" )
else()
set(ccbin_flags)
endif()
@@ -1378,7 +1450,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
if( "${_cuda_host_flags}" MATCHES "-std=c\\+\\+11")
# Add the c++11 flag to nvcc if it isn't already present. Note that we only look at
# the main flag instead of the configuration specific flags.
- if( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std;c\\+\\+11" )
+ if( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std=c\\+\\+11" )
list(APPEND nvcc_flags --std c++11)
endif()
string(REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}")
@@ -1499,7 +1571,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files)
# Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND #######
cuda_include_nvcc_dependencies(${cmake_dependency_file})
- # Convience string for output ###########################################
+ # Convenience string for output #########################################
if(CUDA_BUILD_EMULATION)
set(cuda_build_type "Emulation")
else()
@@ -1698,6 +1770,7 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file}
${flags}
COMMENT "Building NVCC intermediate link file ${output_file_relative_path}"
+ COMMAND_EXPAND_LISTS
${_verbatim}
)
else()
@@ -1708,6 +1781,7 @@ function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options
COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_dir}"
COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}"
+ COMMAND_EXPAND_LISTS
${_verbatim}
)
endif()
@@ -1908,9 +1982,9 @@ endmacro()
###############################################################################
###############################################################################
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.
+ # Call this after you add all your CUDA targets, and you will get a
+ # convenience 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")
diff --git a/Modules/FindCUDA/make2cmake.cmake b/Modules/FindCUDA/make2cmake.cmake
index 7b5389ec5..580f24a40 100644
--- a/Modules/FindCUDA/make2cmake.cmake
+++ b/Modules/FindCUDA/make2cmake.cmake
@@ -40,7 +40,7 @@
# verbose:BOOL=<> OFF: Be as quiet as possible (default)
# ON : Extra output
#
-# input_file:FILEPATH=<> Path to dependecy file in makefile format
+# input_file:FILEPATH=<> Path to dependency file in makefile format
#
# output_file:FILEPATH=<> Path to file with dependencies in CMake readable variable
#
diff --git a/Modules/FindCUDA/run_nvcc.cmake b/Modules/FindCUDA/run_nvcc.cmake
index 25f2f72a2..6fc2439ad 100644
--- a/Modules/FindCUDA/run_nvcc.cmake
+++ b/Modules/FindCUDA/run_nvcc.cmake
@@ -50,6 +50,8 @@
# generated_cubin_file:STRING=<> File to generate. This argument must be passed
# in if build_cubin is true.
+cmake_policy(PUSH)
+cmake_policy(SET CMP0007 NEW)
if(NOT generated_file)
message(FATAL_ERROR "You must specify generated_file on the command line")
endif()
@@ -74,7 +76,7 @@ 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_DIRS "@CUDA_NVCC_INCLUDE_DIRS@") # list (needs to be in quotes to handle spaces properly).
-set(CUDA_NVCC_COMPILE_DEFINITIONS [==[@CUDA_NVCC_COMPILE_DEFINITIONS@]==]) # list (needs to be in quotes to handle spaces properly).
+set(CUDA_NVCC_COMPILE_DEFINITIONS [==[@CUDA_NVCC_COMPILE_DEFINITIONS@]==]) # list (needs to be in lua quotes see #16510 ).
set(format_flag "@format_flag@") # string
set(cuda_language_flag @cuda_language_flag@) # list
@@ -123,7 +125,7 @@ list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}})
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)
+ if (CUDA_HOST_COMPILER STREQUAL "@_CUDA_MSVC_HOST_COMPILER@" AND DEFINED CCBIN)
set(CCBIN -ccbin "${CCBIN}")
else()
set(CCBIN -ccbin "${CUDA_HOST_COMPILER}")
@@ -179,18 +181,13 @@ cuda_execute_process(
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.
+ # Note that this will remove all occurrences 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
+# defined in the generating passes of nvcc invocation. We will go ahead and manually
# define this for now until a future version fixes this bug.
set(CUDACC_DEFINE -D__CUDACC__)
@@ -304,3 +301,5 @@ if( build_cubin )
)
endif()
+
+cmake_policy(POP)
diff --git a/Modules/FindCUDA/select_compute_arch.cmake b/Modules/FindCUDA/select_compute_arch.cmake
index 8fb44d80a..7ddb70969 100644
--- a/Modules/FindCUDA/select_compute_arch.cmake
+++ b/Modules/FindCUDA/select_compute_arch.cmake
@@ -5,9 +5,9 @@
# - "Auto" detects local machine GPU compute arch at runtime.
# - "Common" and "All" cover common and entire subsets of architectures
# ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX
-# NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal
+# NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal Volta Turing
# NUM: Any number. Only those pairs are currently accepted by NVCC though:
-# 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2
+# 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 7.0 7.2 7.5
# Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable}
# Additionally, sets ${out_variable}_readable to the resulting numeric list
# Example:
@@ -17,25 +17,68 @@
# More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA
#
+if(CMAKE_CUDA_COMPILER_LOADED) # CUDA as a language
+ if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA"
+ AND CMAKE_CUDA_COMPILER_VERSION MATCHES "^([0-9]+\\.[0-9]+)")
+ set(CUDA_VERSION "${CMAKE_MATCH_1}")
+ endif()
+endif()
+
+# See: https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#gpu-feature-list
+
# This list will be used for CUDA_ARCH_NAME = All option
set(CUDA_KNOWN_GPU_ARCHITECTURES "Fermi" "Kepler" "Maxwell")
# This list will be used for CUDA_ARCH_NAME = Common option (enabled by default)
set(CUDA_COMMON_GPU_ARCHITECTURES "3.0" "3.5" "5.0")
-if (CUDA_VERSION VERSION_GREATER "6.5")
+if(CUDA_VERSION VERSION_LESS "7.0")
+ set(CUDA_LIMIT_GPU_ARCHITECTURE "5.2")
+endif()
+
+# This list is used to filter CUDA archs when autodetecting
+set(CUDA_ALL_GPU_ARCHITECTURES "3.0" "3.2" "3.5" "5.0")
+
+if(CUDA_VERSION VERSION_GREATER_EQUAL "7.0")
list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Kepler+Tegra" "Kepler+Tesla" "Maxwell+Tegra")
list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2")
-endif ()
-if (CUDA_VERSION VERSION_GREATER "7.5")
+ if(CUDA_VERSION VERSION_LESS "8.0")
+ list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX")
+ set(CUDA_LIMIT_GPU_ARCHITECTURE "6.0")
+ endif()
+endif()
+
+if(CUDA_VERSION VERSION_GREATER_EQUAL "8.0")
list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Pascal")
- list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1" "6.1+PTX")
-else()
- list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX")
+ list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1")
+ list(APPEND CUDA_ALL_GPU_ARCHITECTURES "6.0" "6.1" "6.2")
+
+ if(CUDA_VERSION VERSION_LESS "9.0")
+ list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.1+PTX")
+ set(CUDA_LIMIT_GPU_ARCHITECTURE "7.0")
+ endif()
endif ()
+if(CUDA_VERSION VERSION_GREATER_EQUAL "9.0")
+ list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Volta")
+ list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "7.0" "7.0+PTX")
+ list(APPEND CUDA_ALL_GPU_ARCHITECTURES "7.0" "7.0+PTX" "7.2" "7.2+PTX")
+
+ if(CUDA_VERSION VERSION_LESS "10.0")
+ set(CUDA_LIMIT_GPU_ARCHITECTURE "8.0")
+ endif()
+endif()
+
+if(CUDA_VERSION VERSION_GREATER_EQUAL "10.0")
+ list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Turing")
+ list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "7.5" "7.5+PTX")
+ list(APPEND CUDA_ALL_GPU_ARCHITECTURES "7.5" "7.5+PTX")
+ if(CUDA_VERSION VERSION_LESS "11.0")
+ set(CUDA_LIMIT_GPU_ARCHITECTURE "9.0")
+ endif()
+endif()
################################################################################################
# A function for automatic detection of GPUs installed (if autodetection is enabled)
@@ -44,7 +87,11 @@ endif ()
#
function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE)
if(NOT CUDA_GPU_DETECT_OUTPUT)
- set(file ${PROJECT_BINARY_DIR}/detect_cuda_compute_capabilities.cpp)
+ if(CMAKE_CUDA_COMPILER_LOADED) # CUDA as a language
+ set(file "${PROJECT_BINARY_DIR}/detect_cuda_compute_capabilities.cu")
+ else()
+ set(file "${PROJECT_BINARY_DIR}/detect_cuda_compute_capabilities.cpp")
+ endif()
file(WRITE ${file} ""
"#include <cuda_runtime.h>\n"
@@ -63,10 +110,18 @@ function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE)
" return 0;\n"
"}\n")
- try_run(run_result compile_result ${PROJECT_BINARY_DIR} ${file}
- CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDA_INCLUDE_DIRS}"
- LINK_LIBRARIES ${CUDA_LIBRARIES}
- RUN_OUTPUT_VARIABLE compute_capabilities)
+ if(CMAKE_CUDA_COMPILER_LOADED) # CUDA as a language
+ try_run(run_result compile_result ${PROJECT_BINARY_DIR} ${file}
+ RUN_OUTPUT_VARIABLE compute_capabilities)
+ else()
+ try_run(run_result compile_result ${PROJECT_BINARY_DIR} ${file}
+ CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CUDA_INCLUDE_DIRS}"
+ LINK_LIBRARIES ${CUDA_LIBRARIES}
+ RUN_OUTPUT_VARIABLE compute_capabilities)
+ endif()
+
+ # Filter unrelated content out of the output.
+ string(REGEX MATCHALL "[0-9]+\\.[0-9]+" compute_capabilities "${compute_capabilities}")
if(run_result EQUAL 0)
string(REPLACE "2.1" "2.1(2.0)" compute_capabilities "${compute_capabilities}")
@@ -79,7 +134,19 @@ function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE)
message(STATUS "Automatic GPU detection failed. Building for common architectures.")
set(${OUT_VARIABLE} ${CUDA_COMMON_GPU_ARCHITECTURES} PARENT_SCOPE)
else()
- set(${OUT_VARIABLE} ${CUDA_GPU_DETECT_OUTPUT} PARENT_SCOPE)
+ # Filter based on CUDA version supported archs
+ set(CUDA_GPU_DETECT_OUTPUT_FILTERED "")
+ separate_arguments(CUDA_GPU_DETECT_OUTPUT)
+ foreach(ITEM IN ITEMS ${CUDA_GPU_DETECT_OUTPUT})
+ if(CUDA_LIMIT_GPU_ARCHITECTURE AND ITEM VERSION_GREATER_EQUAL CUDA_LIMIT_GPU_ARCHITECTURE)
+ list(GET CUDA_COMMON_GPU_ARCHITECTURES -1 NEWITEM)
+ string(APPEND CUDA_GPU_DETECT_OUTPUT_FILTERED " ${NEWITEM}")
+ else()
+ string(APPEND CUDA_GPU_DETECT_OUTPUT_FILTERED " ${ITEM}")
+ endif()
+ endforeach()
+
+ set(${OUT_VARIABLE} ${CUDA_GPU_DETECT_OUTPUT_FILTERED} PARENT_SCOPE)
endif()
endfunction()
@@ -141,6 +208,12 @@ function(CUDA_SELECT_NVCC_ARCH_FLAGS out_variable)
elseif(${arch_name} STREQUAL "Pascal")
set(arch_bin 6.0 6.1)
set(arch_ptx 6.1)
+ elseif(${arch_name} STREQUAL "Volta")
+ set(arch_bin 7.0 7.0)
+ set(arch_ptx 7.0)
+ elseif(${arch_name} STREQUAL "Turing")
+ set(arch_bin 7.5)
+ set(arch_ptx 7.5)
else()
message(SEND_ERROR "Unknown CUDA Architecture Name ${arch_name} in CUDA_SELECT_NVCC_ARCH_FLAGS")
endif()
diff --git a/Modules/FindCURL.cmake b/Modules/FindCURL.cmake
index f4bcc36a9..aeebc842e 100644
--- a/Modules/FindCURL.cmake
+++ b/Modules/FindCURL.cmake
@@ -1,38 +1,87 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.rst:
+FindCURL
+--------
+
+Find the native CURL headers and libraries.
+
+This module accept optional COMPONENTS to check supported features and
+protocols::
+
+ PROTOCOLS: ICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3
+ POP3S RTMP RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP
+ FEATURES: SSL IPv6 UnixSockets libz AsynchDNS IDN GSS-API PSL SPNEGO
+ Kerberos NTLM NTLM_WB TLS-SRP HTTP2 HTTPS-proxy
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``CURL::libcurl``, if
+curl has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``CURL_FOUND``
+ "True" if ``curl`` found.
+
+``CURL_INCLUDE_DIRS``
+ where to find ``curl``/``curl.h``, etc.
+
+``CURL_LIBRARIES``
+ List of libraries when using ``curl``.
+
+``CURL_VERSION_STRING``
+ The version of ``curl`` found.
+#]=======================================================================]
+
+find_package(PkgConfig QUIET)
+if(PKG_CONFIG_FOUND)
+ pkg_check_modules(PC_CURL QUIET libcurl)
+ if(PC_CURL_FOUND)
+ set(CURL_VERSION_STRING ${PC_CURL_VERSION})
+ pkg_get_variable(CURL_SUPPORTED_PROTOCOLS libcurl supported_protocols)
+ pkg_get_variable(CURL_SUPPORTED_FEATURES libcurl supported_features)
+ endif()
+endif()
# Look for the header file.
-find_path(CURL_INCLUDE_DIR NAMES curl/curl.h)
+find_path(CURL_INCLUDE_DIR
+ NAMES curl/curl.h
+ HINTS ${PC_CURL_INCLUDE_DIRS})
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)
+if(NOT CURL_LIBRARY)
+ # Look for the library (sorted from most current/relevant entry to least).
+ find_library(CURL_LIBRARY_RELEASE 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
+ HINTS ${PC_CURL_LIBRARY_DIRS}
+ )
+ mark_as_advanced(CURL_LIBRARY_RELEASE)
+
+ find_library(CURL_LIBRARY_DEBUG NAMES
+ # Windows MSVC CMake builds in debug configuration on vcpkg:
+ libcurl-d_imp
+ libcurl-d
+ HINTS ${PC_CURL_LIBRARY_DIRS}
+ )
+ mark_as_advanced(CURL_LIBRARY_DEBUG)
+
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+ select_library_configurations(CURL)
+endif()
+
+if(CURL_INCLUDE_DIR AND NOT CURL_VERSION_STRING)
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 ]+\".*\"")
@@ -44,12 +93,85 @@ if(CURL_INCLUDE_DIR)
endforeach()
endif()
+if(CURL_FIND_COMPONENTS)
+ set(CURL_KNOWN_PROTOCOLS ICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTMP RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP)
+ set(CURL_KNOWN_FEATURES SSL IPv6 UnixSockets libz AsynchDNS IDN GSS-API PSL SPNEGO Kerberos NTLM NTLM_WB TLS-SRP HTTP2 HTTPS-proxy)
+ foreach(component IN LISTS CURL_KNOWN_PROTOCOLS CURL_KNOWN_FEATURES)
+ set(CURL_${component}_FOUND FALSE)
+ endforeach()
+ if(NOT PC_CURL_FOUND)
+ find_program(CURL_CONFIG_EXECUTABLE NAMES curl-config)
+ if(CURL_CONFIG_EXECUTABLE)
+ execute_process(COMMAND ${CURL_CONFIG_EXECUTABLE} --version
+ OUTPUT_VARIABLE CURL_CONFIG_VERSION_STRING
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND ${CURL_CONFIG_EXECUTABLE} --feature
+ OUTPUT_VARIABLE CURL_CONFIG_FEATURES_STRING
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REPLACE "\n" ";" CURL_SUPPORTED_FEATURES "${CURL_CONFIG_FEATURES_STRING}")
+ execute_process(COMMAND ${CURL_CONFIG_EXECUTABLE} --protocols
+ OUTPUT_VARIABLE CURL_CONFIG_PROTOCOLS_STRING
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(REPLACE "\n" ";" CURL_SUPPORTED_PROTOCOLS "${CURL_CONFIG_PROTOCOLS_STRING}")
+ endif()
+
+ endif()
+ foreach(component IN LISTS CURL_FIND_COMPONENTS)
+ list(FIND CURL_KNOWN_PROTOCOLS ${component} _found)
+ if(_found)
+ list(FIND CURL_SUPPORTED_PROTOCOLS ${component} _found)
+ if(_found)
+ set(CURL_${component}_FOUND TRUE)
+ elseif(CURL_FIND_REQUIRED)
+ message(FATAL_ERROR "CURL: Required protocol ${component} is not found")
+ endif()
+ else()
+ list(FIND CURL_SUPPORTED_FEATURES ${component} _found)
+ if(_found)
+ set(CURL_${component}_FOUND TRUE)
+ elseif(CURL_FIND_REQUIRED)
+ message(FATAL_ERROR "CURL: Required feature ${component} is not found")
+ endif()
+ endif()
+ endforeach()
+endif()
+
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL
+find_package_handle_standard_args(CURL
REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR
- VERSION_VAR CURL_VERSION_STRING)
+ VERSION_VAR CURL_VERSION_STRING
+ HANDLE_COMPONENTS)
if(CURL_FOUND)
set(CURL_LIBRARIES ${CURL_LIBRARY})
set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR})
+
+ if(NOT TARGET CURL::libcurl)
+ add_library(CURL::libcurl UNKNOWN IMPORTED)
+ set_target_properties(CURL::libcurl PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}")
+
+ if(EXISTS "${CURL_LIBRARY}")
+ set_target_properties(CURL::libcurl PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "${CURL_LIBRARY}")
+ endif()
+ if(CURL_LIBRARY_RELEASE)
+ set_property(TARGET CURL::libcurl APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(CURL::libcurl PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION_RELEASE "${CURL_LIBRARY_RELEASE}")
+ endif()
+ if(CURL_LIBRARY_DEBUG)
+ set_property(TARGET CURL::libcurl APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(CURL::libcurl PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION_DEBUG "${CURL_LIBRARY_DEBUG}")
+ endif()
+ endif()
endif()
diff --git a/Modules/FindCVS.cmake b/Modules/FindCVS.cmake
index d59dfb097..f81980039 100644
--- a/Modules/FindCVS.cmake
+++ b/Modules/FindCVS.cmake
@@ -1,27 +1,28 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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()
+#[=======================================================================[.rst:
+FindCVS
+-------
+
+Find the Concurrent Versions System (CVS).
+
+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()
+#]=======================================================================]
# CVSNT
diff --git a/Modules/FindCoin3D.cmake b/Modules/FindCoin3D.cmake
index f11903d6a..301e70bd6 100644
--- a/Modules/FindCoin3D.cmake
+++ b/Modules/FindCoin3D.cmake
@@ -1,22 +1,23 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindCoin3D
-# ----------
-#
-# Find Coin3D (Open Inventor)
-#
-# Coin3D is an implementation of the Open Inventor API. It provides
-# data structures and algorithms for 3D visualization.
-#
-# 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
+#[=======================================================================[.rst:
+FindCoin3D
+----------
+
+Find Coin3D (Open Inventor)
+
+Coin3D is an implementation of the Open Inventor API. It provides
+data structures and algorithms for 3D visualization.
+
+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
+#]=======================================================================]
if (WIN32)
if (CYGWIN)
diff --git a/Modules/FindCups.cmake b/Modules/FindCups.cmake
index 13d3b98d6..4e8232d07 100644
--- a/Modules/FindCups.cmake
+++ b/Modules/FindCups.cmake
@@ -1,22 +1,43 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.rst:
+FindCups
+--------
+
+Find the Common UNIX Printing System (CUPS).
+
+Set ``CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE`` to ``TRUE`` if you need a version which
+features this function (i.e. at least ``1.1.19``)
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``Cups::Cups``, if Cups has
+been found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``CUPS_FOUND``
+ true if CUPS headers and libraries were found
+``CUPS_INCLUDE_DIRS``
+ the directory containing the Cups headers
+``CUPS_LIBRARIES``
+ the libraries to link against to use CUPS.
+``CUPS_VERSION_STRING``
+ the version of CUPS found (since CMake 2.8.8)
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``CUPS_INCLUDE_DIR``
+ the directory containing the Cups headers
+#]=======================================================================]
find_path(CUPS_INCLUDE_DIR cups/cups.h )
@@ -65,3 +86,13 @@ else ()
endif ()
mark_as_advanced(CUPS_INCLUDE_DIR CUPS_LIBRARIES)
+
+if (CUPS_FOUND)
+ set(CUPS_INCLUDE_DIRS "${CUPS_INCLUDE_DIR}")
+ if (NOT TARGET Cups::Cups)
+ add_library(Cups::Cups INTERFACE IMPORTED)
+ set_target_properties(Cups::Cups PROPERTIES
+ INTERFACE_LINK_LIBRARIES "${CUPS_LIBRARIES}"
+ INTERFACE_INCLUDE_DIRECTORIES "${CUPS_INCLUDE_DIR}")
+ endif ()
+endif ()
diff --git a/Modules/FindCurses.cmake b/Modules/FindCurses.cmake
index 4365e996e..b3cd8fa49 100644
--- a/Modules/FindCurses.cmake
+++ b/Modules/FindCurses.cmake
@@ -1,50 +1,64 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+Set ``CURSES_NEED_WIDE`` to ``TRUE`` before the
+``find_package(Curses)`` call if unicode 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.
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
+# we don't know anything about cursesw, so only ncurses
+# may be ncursesw
+if(NOT CURSES_NEED_WIDE)
+ set(NCURSES_LIBRARY_NAME "ncurses")
+else()
+ set(NCURSES_LIBRARY_NAME "ncursesw")
+ # Also, if we are searchig fo wide curses - we are actually searching
+ # for ncurses, we don't know about any other unicode version.
+ set(CURSES_NEED_NCURSES TRUE)
+endif()
+
find_library(CURSES_CURSES_LIBRARY NAMES curses )
-find_library(CURSES_NCURSES_LIBRARY NAMES ncurses )
+find_library(CURSES_NCURSES_LIBRARY NAMES "${NCURSES_LIBRARY_NAME}" )
set(CURSES_USE_NCURSES FALSE)
if(CURSES_NCURSES_LIBRARY AND ((NOT CURSES_CURSES_LIBRARY) OR CURSES_NEED_NCURSES))
@@ -55,8 +69,14 @@ endif()
# 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)
+ if (CURSES_NEED_WIDE)
+ if(NOT EXISTS /usr/include/ncursesw/curses.h)
+ set(CURSES_USE_NCURSES TRUE)
+ endif()
+ else()
+ if(NOT EXISTS /usr/include/curses.h)
+ set(CURSES_USE_NCURSES TRUE)
+ endif()
endif()
endif()
@@ -96,18 +116,33 @@ if(CURSES_USE_NCURSES)
# Use CURSES_NCURSES_INCLUDE_PATH if set, for compatibility.
if(CURSES_NCURSES_INCLUDE_PATH)
+ if (CURSES_NEED_WIDE)
+ find_path(CURSES_INCLUDE_PATH
+ NAMES ncursesw/ncurses.h ncursesw/curses.h
+ PATHS ${CURSES_NCURSES_INCLUDE_PATH}
+ NO_DEFAULT_PATH
+ )
+ else()
+ 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()
+ endif()
+
+ if (CURSES_NEED_WIDE)
+ find_path(CURSES_INCLUDE_PATH
+ NAMES ncursesw/ncurses.h ncursesw/curses.h
+ HINTS "${_cursesParentDir}/include"
+ )
+ else()
find_path(CURSES_INCLUDE_PATH
NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h
- PATHS ${CURSES_NCURSES_INCLUDE_PATH}
- NO_DEFAULT_PATH
+ HINTS "${_cursesParentDir}/include"
)
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}")
@@ -123,10 +158,14 @@ 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"
- )
+ #We can't find anything with CURSES_NEED_WIDE because we know
+ #only about ncursesw unicode curses version
+ if(NOT CURSES_NEED_WIDE)
+ find_path(CURSES_INCLUDE_PATH
+ NAMES curses.h
+ HINTS "${_cursesParentDir}/include"
+ )
+ endif()
# Previous versions of FindCurses provided these values.
if(NOT DEFINED CURSES_CURSES_H_PATH)
@@ -139,31 +178,44 @@ 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")
+ if(CURSES_NEED_WIDE)
+ if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h")
+ set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h")
+ endif()
+ elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h")
- else()
+ endif()
+ if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H)
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")
+ if(CURSES_NEED_WIDE)
+ if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/curses.h")
+ set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/curses.h")
+ endif()
+ elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncurses/curses.h")
- else()
+ endif()
+ if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H)
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")
+if(NOT CURSES_NEED_WIDE)
+ #ncursesw can't be found for this paths
+ 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()
-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")
+ 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()
endif()
@@ -199,4 +251,5 @@ mark_as_advanced(
CURSES_CURSES_LIBRARY
CURSES_NCURSES_LIBRARY
CURSES_EXTRA_LIBRARY
+ CURSES_FORM_LIBRARY
)
diff --git a/Modules/FindCxxTest.cmake b/Modules/FindCxxTest.cmake
index 9ba1ff3e9..3fc0e938a 100644
--- a/Modules/FindCxxTest.cmake
+++ b/Modules/FindCxxTest.cmake
@@ -1,142 +1,143 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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, on
-# platforms where the script cannot be executed using its shebang line.
-#
-#
-#
-# 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 );
-# }
-# };
+#[=======================================================================[.rst:
+FindCxxTest
+-----------
+
+Find CxxTest unit testing framework.
+
+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, on
+ platforms where the script cannot be executed using its shebang line.
+
+
+
+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 );
+ }
+ };
+#]=======================================================================]
# Version 1.4 (11/18/10) (CMake 2.8.4)
# Issue 11384: Added support to the CXX_ADD_TEST macro so header
@@ -145,7 +146,7 @@
#
# 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
+# are present in the system. Whichever interpreter that is detected
# is now used to run the test generator program. If both interpreters
# are detected, the CXXTEST_USE_PYTHON variable is obeyed.
#
@@ -193,10 +194,10 @@ endmacro()
# main()
#=============================================================
if(NOT DEFINED CXXTEST_TESTGEN_ARGS)
- set(CXXTEST_TESTGEN_ARGS --error-printer)
+ set(CXXTEST_TESTGEN_ARGS --error-printer)
endif()
-find_package(PythonInterp QUIET)
+find_package(Python QUIET)
find_package(Perl QUIET)
find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h)
@@ -206,41 +207,41 @@ find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE
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})
- execute_process(COMMAND ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE} --version
- OUTPUT_VARIABLE _CXXTEST_OUT ERROR_VARIABLE _CXXTEST_OUT RESULT_VARIABLE _CXXTEST_RESULT)
- if(_CXXTEST_RESULT EQUAL 0)
- set(CXXTEST_TESTGEN_INTERPRETER "")
- else()
- set(CXXTEST_TESTGEN_INTERPRETER ${PYTHON_EXECUTABLE})
- endif()
- 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()
+if(PYTHON_FOUND OR PERL_FOUND)
+ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+ if(PYTHON_FOUND AND (CXXTEST_USE_PYTHON OR NOT PERL_FOUND OR NOT DEFINED CXXTEST_USE_PYTHON))
+ set(CXXTEST_TESTGEN_EXECUTABLE ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE})
+ execute_process(COMMAND ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE} --version
+ OUTPUT_VARIABLE _CXXTEST_OUT ERROR_VARIABLE _CXXTEST_OUT RESULT_VARIABLE _CXXTEST_RESULT)
+ if(_CXXTEST_RESULT EQUAL 0)
+ set(CXXTEST_TESTGEN_INTERPRETER "")
+ else()
+ set(CXXTEST_TESTGEN_INTERPRETER ${Python_EXECUTABLE})
+ endif()
+ 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()
+ 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
index c6913da17..5bbc802a0 100644
--- a/Modules/FindCygwin.cmake
+++ b/Modules/FindCygwin.cmake
@@ -1,11 +1,13 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindCygwin
-# ----------
-#
-# this module looks for Cygwin
+#[=======================================================================[.rst:
+FindCygwin
+----------
+
+Find Cygwin, a POSIX-compatible environment that runs natively
+on Microsoft Windows
+#]=======================================================================]
if (WIN32)
if(CYGWIN_INSTALL_PATH)
@@ -13,10 +15,12 @@ if (WIN32)
endif()
find_program(CYGWIN_BAT
- cygwin.bat
- "C:/Cygwin"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]"
+ NAMES cygwin.bat
+ PATHS
+ "C:/Cygwin"
+ "C:/Cygwin64"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup;rootdir]"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/;native]"
)
get_filename_component(CYGWIN_INSTALL_PATH "${CYGWIN_BAT}" DIRECTORY)
mark_as_advanced(CYGWIN_BAT)
diff --git a/Modules/FindDCMTK.cmake b/Modules/FindDCMTK.cmake
index 0d86e8e0a..d48de0896 100644
--- a/Modules/FindDCMTK.cmake
+++ b/Modules/FindDCMTK.cmake
@@ -1,82 +1,83 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindDCMTK
-# ---------
-#
-# Find DCMTK libraries and applications
-#
-# The module defines the following variables::
-#
-# DCMTK_INCLUDE_DIRS - Directories to include to use DCMTK
-# DCMTK_LIBRARIES - Files to link against to use DCMTK
-# DCMTK_FOUND - If false, don't try to use DCMTK
-# DCMTK_DIR - (optional) Source directory for DCMTK
-#
-# Compatibility
-# ^^^^^^^^^^^^^
-#
-# This module is able to find a version of DCMTK that does or does not export
-# a *DCMTKConfig.cmake* file. It applies a two step process:
-#
-# * Step 1: Attempt to find DCMTK version providing a *DCMTKConfig.cmake* file.
-# * Step 2: If step 1 failed, rely on *FindDCMTK.cmake* to set `DCMTK_*` variables details below.
-#
-#
-# `Recent DCMTK
-# <http://git.dcmtk.org/web?p=dcmtk.git;a=commit;h=662ae187c493c6b9a73dd5e3875372cebd0c11fe>`_
-# provides a *DCMTKConfig.cmake* :manual:`package configuration file
-# <cmake-packages(7)>`. To exclusively use the package configuration file
-# (recommended when possible), pass the `NO_MODULE` option to
-# :command:`find_package`. For example, `find_package(DCMTK NO_MODULE)`.
-# This requires official DCMTK snapshot *3.6.1_20140617* or newer.
-#
-#
-# Until all clients update to the more recent DCMTK, build systems will need
-# to support different versions of DCMTK.
-#
-# On any given system, the following combinations of DCMTK versions could be
-# considered:
-#
-# +--------+---------------------+-----------------------+-------------------+
-# | | SYSTEM DCMTK | LOCAL DCMTK | Supported ? |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case A | NA | [ ] DCMTKConfig | YES |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case B | NA | [X] DCMTKConfig | YES |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case C | [ ] DCMTKConfig | NA | YES |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case D | [X] DCMTKConfig | NA | YES |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case E | [ ] DCMTKConfig | [ ] DCMTKConfig | YES (*) |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case F | [X] DCMTKConfig | [ ] DCMTKConfig | NO |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case G | [ ] DCMTKConfig | [X] DCMTKConfig | YES |
-# +--------+---------------------+-----------------------+-------------------+
-# | Case H | [X] DCMTKConfig | [X] DCMTKConfig | YES |
-# +--------+---------------------+-----------------------+-------------------+
-#
-# (*) See Troubleshooting section.
-#
-# Legend:
-#
-# NA ...............: Means that no System or Local DCMTK is available
-#
-# [ ] DCMTKConfig ..: Means that the version of DCMTK does NOT export a DCMTKConfig.cmake file.
-#
-# [X] DCMTKConfig ..: Means that the version of DCMTK exports a DCMTKConfig.cmake file.
-#
-#
-# Troubleshooting
-# ^^^^^^^^^^^^^^^
-#
-# What to do if my project finds a different version of DCMTK?
-#
-# Remove DCMTK entry from the CMake cache per :command:`find_package`
-# documentation.
+#[=======================================================================[.rst:
+FindDCMTK
+---------
+
+Find DICOM ToolKit (DCMTK) libraries and applications
+
+The module defines the following variables::
+
+ DCMTK_INCLUDE_DIRS - Directories to include to use DCMTK
+ DCMTK_LIBRARIES - Files to link against to use DCMTK
+ DCMTK_FOUND - If false, don't try to use DCMTK
+ DCMTK_DIR - (optional) Source directory for DCMTK
+
+Compatibility
+^^^^^^^^^^^^^
+
+This module is able to find a version of DCMTK that does or does not export
+a *DCMTKConfig.cmake* file. It applies a two step process:
+
+* Step 1: Attempt to find DCMTK version providing a *DCMTKConfig.cmake* file.
+* Step 2: If step 1 failed, rely on *FindDCMTK.cmake* to set `DCMTK_*` variables details below.
+
+
+`Recent DCMTK
+<http://git.dcmtk.org/web?p=dcmtk.git;a=commit;h=662ae187c493c6b9a73dd5e3875372cebd0c11fe>`_
+provides a *DCMTKConfig.cmake* :manual:`package configuration file
+<cmake-packages(7)>`. To exclusively use the package configuration file
+(recommended when possible), pass the `NO_MODULE` option to
+:command:`find_package`. For example, `find_package(DCMTK NO_MODULE)`.
+This requires official DCMTK snapshot *3.6.1_20140617* or newer.
+
+
+Until all clients update to the more recent DCMTK, build systems will need
+to support different versions of DCMTK.
+
+On any given system, the following combinations of DCMTK versions could be
+considered:
+
++--------+---------------------+-----------------------+-------------------+
+| | SYSTEM DCMTK | LOCAL DCMTK | Supported ? |
++--------+---------------------+-----------------------+-------------------+
+| Case A | NA | [ ] DCMTKConfig | YES |
++--------+---------------------+-----------------------+-------------------+
+| Case B | NA | [X] DCMTKConfig | YES |
++--------+---------------------+-----------------------+-------------------+
+| Case C | [ ] DCMTKConfig | NA | YES |
++--------+---------------------+-----------------------+-------------------+
+| Case D | [X] DCMTKConfig | NA | YES |
++--------+---------------------+-----------------------+-------------------+
+| Case E | [ ] DCMTKConfig | [ ] DCMTKConfig | YES (*) |
++--------+---------------------+-----------------------+-------------------+
+| Case F | [X] DCMTKConfig | [ ] DCMTKConfig | NO |
++--------+---------------------+-----------------------+-------------------+
+| Case G | [ ] DCMTKConfig | [X] DCMTKConfig | YES |
++--------+---------------------+-----------------------+-------------------+
+| Case H | [X] DCMTKConfig | [X] DCMTKConfig | YES |
++--------+---------------------+-----------------------+-------------------+
+
+ (*) See Troubleshooting section.
+
+Legend:
+
+ NA ...............: Means that no System or Local DCMTK is available
+
+ [ ] DCMTKConfig ..: Means that the version of DCMTK does NOT export a DCMTKConfig.cmake file.
+
+ [X] DCMTKConfig ..: Means that the version of DCMTK exports a DCMTKConfig.cmake file.
+
+
+Troubleshooting
+^^^^^^^^^^^^^^^
+
+What to do if my project finds a different version of DCMTK?
+
+Remove DCMTK entry from the CMake cache per :command:`find_package`
+documentation.
+#]=======================================================================]
#
# Written for VXL by Amitha Perera.
@@ -199,7 +200,6 @@ if(DCMTK_oflog_LIBRARY_RELEASE OR DCMTK_oflog_LIBRARY_DEBUG)
# Hack - Not having a DCMTKConfig.cmake file to read the settings from, we will attempt to
# find the library in all cases.
# Ideally, pthread library should be discovered only if DCMTK_WITH_THREADS is enabled.
- set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads)
endif()
@@ -217,7 +217,7 @@ if(EXISTS ${DCMTK_DIR}/CMakeCache.txt)
if(NOT EXISTS ${EXTDCMTK_SOURCE_DIR})
message(FATAL_ERROR
"DCMTK build directory references
-nonexistant DCMTK source directory ${EXTDCMTK_SOURCE_DIR}")
+nonexistent DCMTK source directory ${EXTDCMTK_SOURCE_DIR}")
endif()
endif()
@@ -301,7 +301,7 @@ endif()
# Compatibility: This variable is deprecated
set(DCMTK_INCLUDE_DIR ${DCMTK_INCLUDE_DIRS})
-include(FindPackageHandleStandardArgs)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(DCMTK
REQUIRED_VARS ${DCMTK_INCLUDE_DIR_NAMES} DCMTK_LIBRARIES
FAIL_MESSAGE "Please set DCMTK_DIR and re-run configure")
@@ -309,20 +309,14 @@ find_package_handle_standard_args(DCMTK
# Workaround bug in packaging of DCMTK 3.6.0 on Debian.
# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=637687
if(DCMTK_FOUND AND UNIX AND NOT APPLE)
- include(CheckCXXSourceCompiles)
+ include(${CMAKE_CURRENT_LIST_DIR}/CheckIncludeFiles.cmake)
set(CMAKE_REQUIRED_FLAGS )
set(CMAKE_REQUIRED_DEFINITIONS )
set(CMAKE_REQUIRED_INCLUDES ${DCMTK_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${DCMTK_LIBRARIES})
set(CMAKE_REQUIRED_QUIET ${DCMTK_FIND_QUIETLY})
- check_cxx_source_compiles("#include <dcmtk/config/osconfig.h>\n#include <dcmtk/ofstd/ofstream.h>\nint main(int,char*[]){return 0;}"
- DCMTK_HAVE_CONFIG_H_OPTIONAL
- )
+ check_include_files("dcmtk/config/osconfig.h;dcmtk/ofstd/ofstream.h" DCMTK_HAVE_CONFIG_H_OPTIONAL LANGUAGE CXX)
if(NOT DCMTK_HAVE_CONFIG_H_OPTIONAL)
set(DCMTK_DEFINITIONS "HAVE_CONFIG_H")
endif()
endif()
-
-if(NOT DCMTK_FIND_QUIETLY)
- message(STATUS "Trying to find DCMTK relying on FindDCMTK.cmake - ok")
-endif()
diff --git a/Modules/FindDart.cmake b/Modules/FindDart.cmake
index acd4ef62d..04925783b 100644
--- a/Modules/FindDart.cmake
+++ b/Modules/FindDart.cmake
@@ -1,14 +1,15 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindDart
-# --------
-#
-# Find DART
-#
-# This module looks for the dart testing software and sets DART_ROOT to
-# point to where it found it.
+#[=======================================================================[.rst:
+FindDart
+--------
+
+Find DART
+
+This module looks for the dart testing software and sets DART_ROOT to
+point to where it found it.
+#]=======================================================================]
find_path(DART_ROOT README.INSTALL
HINTS
diff --git a/Modules/FindDevIL.cmake b/Modules/FindDevIL.cmake
index f6c8e3f24..998494365 100644
--- a/Modules/FindDevIL.cmake
+++ b/Modules/FindDevIL.cmake
@@ -1,35 +1,36 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-# DevIL_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.
+#[=======================================================================[.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.
+ DevIL_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.
+#]=======================================================================]
# TODO: Add version support.
# Tested under Linux and Windows (MSVC)
@@ -70,5 +71,5 @@ find_library(ILU_LIBRARIES
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DevIL DEFAULT_MSG
IL_LIBRARIES ILU_LIBRARIES
IL_INCLUDE_DIR)
-# provide legacy variable for compatiblity
+# provide legacy variable for compatibility
set(IL_FOUND ${DevIL_FOUND})
diff --git a/Modules/FindDoxygen.cmake b/Modules/FindDoxygen.cmake
index 46bf340dd..ebd0b24ab 100644
--- a/Modules/FindDoxygen.cmake
+++ b/Modules/FindDoxygen.cmake
@@ -69,6 +69,7 @@ Functions
doxygen_add_docs(targetName
[filesOrDirs...]
+ [ALL]
[WORKING_DIRECTORY dir]
[COMMENT comment])
@@ -91,6 +92,8 @@ Functions
the :command:`add_custom_target` command used to create the custom target
internally.
+ If ALL is set, the target will be added to the default build target.
+
The contents of the generated ``Doxyfile`` can be customized by setting CMake
variables before calling ``doxygen_add_docs()``. Any variable with a name of
the form ``DOXYGEN_<tag>`` will have its value substituted for the
@@ -244,7 +247,7 @@ required form if set.
TAGFILES
TCL_SUBST
-The following single value Doxygen options would be quoted automatically
+The following single value Doxygen options will be quoted automatically
if they contain at least one space:
::
@@ -292,6 +295,36 @@ if they contain at least one space:
WARN_LOGFILE
XML_OUTPUT
+There are situations where it may be undesirable for a particular config option
+to be automatically quoted by ``doxygen_add_docs()``, such as ``ALIASES`` which
+may need to include its own embedded quoting. The ``DOXYGEN_VERBATIM_VARS``
+variable can be used to specify a list of Doxygen variables (including the
+leading ``DOXYGEN_`` prefix) which should not be quoted. The project is then
+responsible for ensuring that those variables' values make sense when placed
+directly in the Doxygen input file. In the case of list variables, list items
+are still separated by spaces, it is only the automatic quoting that is
+skipped. For example, the following allows ``doxygen_add_docs()`` to apply
+quoting to ``DOXYGEN_PROJECT_BRIEF``, but not each item in the
+``DOXYGEN_ALIASES`` list (:ref:`bracket syntax <Bracket Argument>` can also
+be used to make working with embedded quotes easier):
+
+.. code-block:: cmake
+
+ set(DOXYGEN_PROJECT_BRIEF "String with spaces")
+ set(DOXYGEN_ALIASES
+ [[somealias="@some_command param"]]
+ "anotherAlias=@foobar"
+ )
+ set(DOXYGEN_VERBATIM_VARS DOXYGEN_ALIASES)
+
+The resultant ``Doxyfile`` will contain the following lines:
+
+.. code-block:: text
+
+ PROJECT_BRIEF = "String with spaces"
+ ALIASES = somealias="@some_command param" anotherAlias=@foobar
+
+
Deprecated Result Variables
^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -331,12 +364,15 @@ Deprecated Hint Variables
.. variable:: DOXYGEN_SKIP_DOT
- This variable has no any effect for component form of ``find_package``.
+ This variable has no effect for the component form of ``find_package``.
In backward compatibility mode (i.e. without components list) it prevents
the finder module from searching for Graphviz's ``dot`` utility.
#]=======================================================================]
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
# For backwards compatibility support
if(Doxygen_FIND_QUIETLY)
set(DOXYGEN_FIND_QUIETLY TRUE)
@@ -381,6 +417,8 @@ macro(_Doxygen_find_doxygen)
"[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
+ /Applications/Utilities/Doxygen.app/Contents/Resources
+ /Applications/Utilities/Doxygen.app/Contents/MacOS
DOC "Doxygen documentation generation tool (http://www.doxygen.org)"
)
mark_as_advanced(DOXYGEN_EXECUTABLE)
@@ -447,12 +485,18 @@ endmacro()
# Find Graphviz Dot...
#
macro(_Doxygen_find_dot)
- set(_x86 "(x86)")
- file(
- GLOB _Doxygen_GRAPHVIZ_BIN_DIRS
- "$ENV{ProgramFiles}/Graphviz*/bin"
- "$ENV{ProgramFiles${_x86}}/Graphviz*/bin"
- )
+ if(WIN32)
+ set(_x86 "(x86)")
+ file(
+ GLOB _Doxygen_GRAPHVIZ_BIN_DIRS
+ "$ENV{ProgramFiles}/Graphviz*/bin"
+ "$ENV{ProgramFiles${_x86}}/Graphviz*/bin"
+ )
+ unset(_x86)
+ else()
+ set(_Doxygen_GRAPHVIZ_BIN_DIRS "")
+ endif()
+
find_program(
DOXYGEN_DOT_EXECUTABLE
NAMES dot
@@ -462,8 +506,11 @@ macro(_Doxygen_find_dot)
"C:/Program Files/ATT/Graphviz/bin"
[HKEY_LOCAL_MACHINE\\SOFTWARE\\ATT\\Graphviz;InstallPath]/bin
/Applications/Graphviz.app/Contents/MacOS
+ /Applications/Utilities/Graphviz.app/Contents/MacOS
/Applications/Doxygen.app/Contents/Resources
/Applications/Doxygen.app/Contents/MacOS
+ /Applications/Utilities/Doxygen.app/Contents/Resources
+ /Applications/Utilities/Doxygen.app/Contents/MacOS
DOC "Dot tool for use with Doxygen"
)
mark_as_advanced(DOXYGEN_DOT_EXECUTABLE)
@@ -488,7 +535,6 @@ macro(_Doxygen_find_dot)
endif()
unset(_Doxygen_GRAPHVIZ_BIN_DIRS)
- unset(_x86)
endmacro()
#
@@ -667,7 +713,9 @@ if(TARGET Doxygen::doxygen)
if(_line MATCHES "([A-Z][A-Z0-9_]+)( *=)(.*)")
set(_key "${CMAKE_MATCH_1}")
set(_eql "${CMAKE_MATCH_2}")
- string(REPLACE ";" "\\\n" _value "${CMAKE_MATCH_3}")
+ set(_value "${CMAKE_MATCH_3}")
+ string(REPLACE "\\" "\\\\" _value "${_value}")
+ string(REPLACE ";" "\\\n" _value "${_value}")
list(APPEND _Doxygen_tpl_params "${_key}${_eql}${_value}")
endif()
endforeach()
@@ -716,12 +764,15 @@ endif()
function(doxygen_quote_value VARIABLE)
# Quote a value of the given variable if:
- # - variable parameter was really given
- # - a variable it points is defined
- # - a value doesn't quoted already
- # - and it has spaces
+ # - VARIABLE parameter was really given
+ # - the variable it names is defined and is not present in the list
+ # specified by DOXYGEN_VERBATIM_VARS (if set)
+ # - the value of the named variable isn't already quoted
+ # - the value has spaces
if(VARIABLE AND DEFINED ${VARIABLE} AND
- NOT ${VARIABLE} MATCHES "^\".* .*\"$" AND ${VARIABLE} MATCHES " ")
+ NOT ${VARIABLE} MATCHES "^\".* .*\"$" AND ${VARIABLE} MATCHES " " AND
+ NOT (DEFINED DOXYGEN_VERBATIM_VARS AND
+ "${VARIABLE}" IN_LIST DOXYGEN_VERBATIM_VARS))
set(${VARIABLE} "\"${${VARIABLE}}\"" PARENT_SCOPE)
endif()
endfunction()
@@ -730,8 +781,18 @@ function(doxygen_list_to_quoted_strings LIST_VARIABLE)
if(LIST_VARIABLE AND DEFINED ${LIST_VARIABLE})
unset(_inputs)
unset(_sep)
+ unset(_verbatim)
+ # Have to test if list items should be treated as verbatim here
+ # because we lose the variable name when we pass just one list item
+ # to doxygen_quote_value() below
+ if(DEFINED DOXYGEN_VERBATIM_VARS AND
+ "${LIST_VARIABLE}" IN_LIST DOXYGEN_VERBATIM_VARS)
+ set(_verbatim True)
+ endif()
foreach(_in IN LISTS ${LIST_VARIABLE})
- doxygen_quote_value(_in)
+ if(NOT _verbatim)
+ doxygen_quote_value(_in)
+ endif()
string(APPEND _inputs "${_sep}${_in}")
set(_sep " ")
endforeach()
@@ -740,7 +801,7 @@ function(doxygen_list_to_quoted_strings LIST_VARIABLE)
endfunction()
function(doxygen_add_docs targetName)
- set(_options)
+ set(_options ALL)
set(_one_value_args WORKING_DIRECTORY COMMENT)
set(_multi_value_args)
cmake_parse_arguments(_args
@@ -832,7 +893,11 @@ doxygen_add_docs() for target ${targetName}")
# and Lucent Bell Labs. The other options in this section have no
# effect if this option is set to NO.
# Doxygen's default value is: NO.
- set(DOXYGEN_HAVE_DOT ${DOXYGEN_DOT_FOUND})
+ if(Doxygen_dot_FOUND)
+ set(DOXYGEN_HAVE_DOT "YES")
+ else()
+ set(DOXYGEN_HAVE_DOT "NO")
+ endif()
endif()
if(NOT DEFINED DOXYGEN_DOT_MULTI_TARGETS)
@@ -909,7 +974,7 @@ doxygen_add_docs() for target ${targetName}")
"${DOXYGEN_OUTPUT_DIRECTORY}/${DOXYGEN_HTML_OUTPUT}")
endif()
set_property(DIRECTORY APPEND PROPERTY
- ADDITIONAL_MAKE_CLEAN_FILES "${_args_clean_html_dir}")
+ ADDITIONAL_CLEAN_FILES "${_args_clean_html_dir}")
endif()
# Build up a list of files we can identify from the inputs so we can list
@@ -1037,8 +1102,13 @@ doxygen_add_docs() for target ${targetName}")
set(_target_doxyfile "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.${targetName}")
configure_file("${_doxyfile_template}" "${_target_doxyfile}")
+ unset(_all)
+ if(${_args_ALL})
+ set(_all ALL)
+ endif()
+
# Add the target
- add_custom_target( ${targetName} VERBATIM
+ add_custom_target( ${targetName} ${_all} VERBATIM
COMMAND ${CMAKE_COMMAND} -E make_directory ${_original_doxygen_output_dir}
COMMAND "${DOXYGEN_EXECUTABLE}" "${_target_doxyfile}"
WORKING_DIRECTORY "${_args_WORKING_DIRECTORY}"
@@ -1048,3 +1118,5 @@ doxygen_add_docs() for target ${targetName}")
)
endfunction()
+
+cmake_policy(POP)
diff --git a/Modules/FindEXPAT.cmake b/Modules/FindEXPAT.cmake
index 09963fcda..15b419a61 100644
--- a/Modules/FindEXPAT.cmake
+++ b/Modules/FindEXPAT.cmake
@@ -1,19 +1,34 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindEXPAT
+---------
+
+Find the native Expat headers and library.
+Expat is a stream-oriented XML parser library written in C.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``EXPAT::EXPAT``
+ The Expat ``expat`` library, if found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``EXPAT_INCLUDE_DIRS``
+ where to find expat.h, etc.
+``EXPAT_LIBRARIES``
+ the libraries to link against to use Expat.
+``EXPAT_FOUND``
+ true if the Expat headers and libraries were found.
+
+#]=======================================================================]
find_package(PkgConfig QUIET)
@@ -49,10 +64,18 @@ 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.
+# Copy the results to the output variables and target.
if(EXPAT_FOUND)
set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
+
+ if(NOT TARGET EXPAT::EXPAT)
+ add_library(EXPAT::EXPAT UNKNOWN IMPORTED)
+ set_target_properties(EXPAT::EXPAT PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "${EXPAT_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}")
+ endif()
endif()
mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)
diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake
index fef7fb474..d22b7ec67 100644
--- a/Modules/FindFLEX.cmake
+++ b/Modules/FindFLEX.cmake
@@ -1,100 +1,103 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>]
-# [DEFINES_FILE <string>]
-# )
-#
-# which creates a custom command to generate the <FlexOutput> file from
-# the <FlexInput> file. If COMPILE_FLAGS option is specified, the next
-# parameter is added to the flex command line. If flex is configured to
-# output a header file, the DEFINES_FILE option may be used to specify its
-# name. Name is an alias used to get details of this custom command.
-# Indeed the macro defines the following variables:
-#
-# ::
-#
-# 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_${Name}_OUTPUT_HEADER - the header flex output, if any.
-#
-#
-#
-# 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}
-# )
-# ====================================================================
+#[=======================================================================[.rst:
+FindFLEX
+--------
+
+Find Fast Lexical Analyzer (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. :command:`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>]
+ [DEFINES_FILE <string>]
+ )
+
+which creates a custom command to generate the ``FlexOutput`` file from
+the ``FlexInput`` file. If ``COMPILE_FLAGS`` option is specified, the next
+parameter is added to the flex command line. If flex is configured to
+output a header file, the ``DEFINES_FILE`` option may be used to specify its
+name. Name is an alias used to get details of this custom command.
+Indeed the macro defines the following variables:
+
+::
+
+ 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_${Name}_OUTPUT_HEADER - the header flex output, if any.
+
+
+
+Flex scanners often 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}
+ )
+ target_link_libraries(Foo ${FLEX_LIBRARIES})
+ ====================================================================
+#]=======================================================================]
find_program(FLEX_EXECUTABLE NAMES flex win_flex DOC "path to the flex executable")
mark_as_advanced(FLEX_EXECUTABLE)
diff --git a/Modules/FindFLTK.cmake b/Modules/FindFLTK.cmake
index e6bd3c98b..e273642b5 100644
--- a/Modules/FindFLTK.cmake
+++ b/Modules/FindFLTK.cmake
@@ -1,61 +1,83 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindFLTK
+--------
+
+Find the Fast Light Toolkit (FLTK) library
+
+Input Variables
+^^^^^^^^^^^^^^^
+
+By default this module 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 the FLTK GL library
+
+``FLTK_SKIP_FORMS``
+ Set to true to disable searching for the FLTK Forms library
+
+``FLTK_SKIP_IMAGES``
+ Set to true to disable searching for the FLTK Images library
+
+FLTK is composed also by a binary tool. You can set the following option:
+
+``FLTK_SKIP_FLUID``
+ Set to true to not look for the FLUID binary
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+The following variables will be defined:
+
+``FLTK_FOUND``
+ True if all components not skipped were found
+
+``FLTK_INCLUDE_DIR``
+ Path to the include directory for FLTK header files
+
+``FLTK_LIBRARIES``
+ List of the FLTK libraries found
+
+``FLTK_FLUID_EXECUTABLE``
+ Path to the FLUID binary tool
+
+``FLTK_WRAP_UI``
+ True if FLUID is found, used to enable the FLTK_WRAP_UI command
+
+Cache Variables
+^^^^^^^^^^^^^^^
+
+The following cache variables are also available to set or use:
+
+``FLTK_BASE_LIBRARY_RELEASE``
+ The FLTK base library (optimized)
+
+``FLTK_BASE_LIBRARY_DEBUG``
+ The FLTK base library (debug)
+
+``FLTK_GL_LIBRARY_RELEASE``
+ The FLTK GL library (optimized)
+
+``FLTK_GL_LIBRARY_DEBUG``
+ The FLTK GL library (debug)
+
+``FLTK_FORMS_LIBRARY_RELEASE``
+ The FLTK Forms library (optimized)
+
+``FLTK_FORMS_LIBRARY_DEBUG``
+ The FLTK Forms library (debug)
+
+``FLTK_IMAGES_LIBRARY_RELEASE``
+ The FLTK Images protobuf library (optimized)
+
+``FLTK_IMAGES_LIBRARY_DEBUG``
+ The FLTK Images library (debug)
+#]=======================================================================]
if(NOT FLTK_SKIP_OPENGL)
find_package(OpenGL)
@@ -114,177 +136,183 @@ if(NOT 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
+ PATH_SUFFIXES
+ fltk
+ fltk/include
+ lib/fltk
+ lib/fltk/include
# 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)
+# Check if FLTK was built using CMake
+if(EXISTS ${FLTK_DIR}/FLTKConfig.cmake)
+ set(FLTK_BUILT_WITH_CMAKE 1)
+endif()
- # 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.")
+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
+ )
- # 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()
+ 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.")
- #
- # 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()
+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}
- /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)
+ ${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_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()
+ list(APPEND FLTK_INCLUDE_SEARCH_PATH ${_FLTK_POSSIBLE_INCLUDE_DIRS})
+
+ find_path(FLTK_INCLUDE_DIR
+ NAMES FL/Fl.h FL/Fl.H # fltk 1.1.9 has Fl.H (#8376)
+ PATH_SUFFIXES fltk fltk/include
+ 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()
- # 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})
+ list(APPEND FLTK_LIBRARY_SEARCH_PATH ${FLTK_INCLUDE_DIR}/lib ${_FLTK_POSSIBLE_LIBRARY_DIR})
+
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+
+ # Allow libraries to be set manually
+ if(NOT FLTK_BASE_LIBRARY)
+ find_library(FLTK_BASE_LIBRARY_RELEASE NAMES fltk PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ find_library(FLTK_BASE_LIBRARY_DEBUG NAMES fltkd PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ select_library_configurations(FLTK_BASE)
+ endif()
+ if(NOT FLTK_GL_LIBRARY)
+ find_library(FLTK_GL_LIBRARY_RELEASE NAMES fltkgl fltk_gl PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ find_library(FLTK_GL_LIBRARY_DEBUG NAMES fltkgld fltk_gld PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ select_library_configurations(FLTK_GL)
endif()
- if(NOT FLTK_SKIP_FORMS)
- list(APPEND FLTK_LIBRARIES ${FLTK_FORMS_LIBRARY})
+ if(NOT FLTK_FORMS_LIBRARY)
+ find_library(FLTK_FORMS_LIBRARY_RELEASE NAMES fltkforms fltk_forms PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ find_library(FLTK_FORMS_LIBRARY_DEBUG NAMES fltkformsd fltk_formsd PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ select_library_configurations(FLTK_FORMS)
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)
+ if(NOT FLTK_IMAGES_LIBRARY)
+ find_library(FLTK_IMAGES_LIBRARY_RELEASE NAMES fltkimages fltk_images PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ find_library(FLTK_IMAGES_LIBRARY_DEBUG NAMES fltkimagesd fltk_imagesd PATHS ${FLTK_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk fltk/lib)
+ select_library_configurations(FLTK_IMAGES)
+ endif()
+
+ # 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()
- list(APPEND FLTK_LIBRARIES ${FLTK_BASE_LIBRARY})
+
+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)
@@ -306,4 +334,3 @@ if(FLTK_FOUND)
set (FLTK_FLUID_EXE ${FLTK_FLUID_EXECUTABLE})
set (FLTK_LIBRARY ${FLTK_LIBRARIES})
endif()
-
diff --git a/Modules/FindFLTK2.cmake b/Modules/FindFLTK2.cmake
index a43e5ff27..a43f7a475 100644
--- a/Modules/FindFLTK2.cmake
+++ b/Modules/FindFLTK2.cmake
@@ -1,29 +1,30 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindFLTK2
+---------
+
+Find the native FLTK 2.0 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
+#]=======================================================================]
set (FLTK2_DIR $ENV{FLTK2_DIR} )
@@ -80,11 +81,11 @@ if(NOT 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
+ PATH_SUFFIXES
+ fltk2
+ fltk2/include
+ lib/fltk2
+ lib/fltk2/include
# Help the user find it if we cannot.
DOC "The ${FLTK2_DIR_STRING}"
@@ -175,25 +176,16 @@ if(FLTK2_DIR)
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} PATH_SUFFIXES fltk2 fltk2/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
- )
+ list(APPEND FLTK2_LIBRARY_SEARCH_PATH ${FLTK2_INCLUDE_DIR}/lib)
find_library(FLTK2_BASE_LIBRARY NAMES fltk2
- PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
+ PATHS ${FLTK2_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk2 fltk2/lib)
find_library(FLTK2_GL_LIBRARY NAMES fltk2_gl
- PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
+ PATHS ${FLTK2_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk2 fltk2/lib)
find_library(FLTK2_IMAGES_LIBRARY NAMES fltk2_images
- PATHS ${FLTK2_LIBRARY_SEARCH_PATH})
+ PATHS ${FLTK2_LIBRARY_SEARCH_PATH} PATH_SUFFIXES fltk2 fltk2/lib)
# Find the extra libraries needed for the fltk_images library.
if(UNIX)
@@ -251,4 +243,3 @@ else()
endif()
endif()
endif()
-
diff --git a/Modules/FindFreetype.cmake b/Modules/FindFreetype.cmake
index 9ea77df1d..3e6a177dc 100644
--- a/Modules/FindFreetype.cmake
+++ b/Modules/FindFreetype.cmake
@@ -1,28 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindFreetype
+------------
+
+Find the FreeType font renderer includes and library.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` target:
+
+``Freetype::Freetype``
+ The Freetype ``freetype`` library, if found
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``FREETYPE_FOUND``
+ true if the Freetype headers and libraries were found
+``FREETYPE_INCLUDE_DIRS``
+ directories containing the Freetype headers. This is the
+ concatenation of the variables:
+
+ ``FREETYPE_INCLUDE_DIR_ft2build``
+ directory holding the main Freetype API configuration header
+ ``FREETYPE_INCLUDE_DIR_freetype2``
+ directory holding Freetype public headers
+``FREETYPE_LIBRARIES``
+ the library to link against
+``FREETYPE_VERSION_STRING``
+ the version of freetype found (since CMake 2.8.8)
+
+Hints
+^^^^^
+
+The user may set the environment variable ``FREETYPE_DIR`` to the root
+directory of a Freetype installation.
+#]=======================================================================]
# Created by Eric Wing.
# Modifications by Alexander Neundorf.
@@ -46,10 +64,6 @@ set(FREETYPE_FIND_ARGS
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]
@@ -98,6 +112,9 @@ if(NOT FREETYPE_LIBRARY)
)
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(FREETYPE)
+else()
+ # on Windows, ensure paths are in canonical format (forward slahes):
+ file(TO_CMAKE_PATH "${FREETYPE_LIBRARY}" FREETYPE_LIBRARY)
endif()
unset(FREETYPE_FIND_ARGS)
@@ -150,3 +167,33 @@ mark_as_advanced(
FREETYPE_INCLUDE_DIR_freetype2
FREETYPE_INCLUDE_DIR_ft2build
)
+
+if(Freetype_FOUND)
+ if(NOT TARGET Freetype::Freetype)
+ add_library(Freetype::Freetype UNKNOWN IMPORTED)
+ set_target_properties(Freetype::Freetype PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${FREETYPE_INCLUDE_DIRS}")
+
+ if(FREETYPE_LIBRARY_RELEASE)
+ set_property(TARGET Freetype::Freetype APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(Freetype::Freetype PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
+ IMPORTED_LOCATION_RELEASE "${FREETYPE_LIBRARY_RELEASE}")
+ endif()
+
+ if(FREETYPE_LIBRARY_DEBUG)
+ set_property(TARGET Freetype::Freetype APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(Freetype::Freetype PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
+ IMPORTED_LOCATION_DEBUG "${FREETYPE_LIBRARY_DEBUG}")
+ endif()
+
+ if(NOT FREETYPE_LIBRARY_RELEASE AND NOT FREETYPE_LIBRARY_DEBUG)
+ set_target_properties(Freetype::Freetype PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "${FREETYPE_LIBRARY}")
+ endif()
+ endif()
+endif()
diff --git a/Modules/FindGCCXML.cmake b/Modules/FindGCCXML.cmake
index 1f8d738f8..e6c7f2434 100644
--- a/Modules/FindGCCXML.cmake
+++ b/Modules/FindGCCXML.cmake
@@ -1,19 +1,20 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindGCCXML
-# ----------
-#
-# Find the GCC-XML front-end executable.
-#
-#
-#
-# This module will define the following variables:
-#
-# ::
-#
-# GCCXML - the GCC-XML front-end executable.
+#[=======================================================================[.rst:
+FindGCCXML
+----------
+
+Find the GCC-XML front-end executable.
+
+
+
+This module will define the following variables:
+
+::
+
+ GCCXML - the GCC-XML front-end executable.
+#]=======================================================================]
find_program(GCCXML
NAMES gccxml
diff --git a/Modules/FindGDAL.cmake b/Modules/FindGDAL.cmake
index 0cce9cb9f..fde84d488 100644
--- a/Modules/FindGDAL.cmake
+++ b/Modules/FindGDAL.cmake
@@ -1,31 +1,49 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindGDAL
+--------
+
+Find Geospatial Data Abstraction Library (GDAL).
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``GDAL::GDAL``
+if GDAL has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``GDAL_FOUND``
+ True if GDAL is found.
+``GDAL_INCLUDE_DIRS``
+ Include directories for GDAL headers.
+``GDAL_LIBRARIES``
+ Libraries to link to GDAL.
+``GDAL_VERSION``
+ The version of GDAL found.
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``GDAL_LIBRARY``
+ The libgdal library file.
+``GDAL_INCLUDE_DIR``
+ The directory containing ``gdal.h``.
+
+Hints
+^^^^^
+
+Set ``GDAL_DIR`` or ``GDAL_ROOT`` in the environment to specify the
+GDAL installation prefix.
+#]=======================================================================]
-#
# $GDALDIR is an environment variable that would
# correspond to the ./configure --prefix=$GDAL_DIR
# used in building gdal.
@@ -50,13 +68,6 @@ find_path(GDAL_INCLUDE_DIR gdal.h
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)
@@ -69,20 +80,53 @@ if(UNIX)
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}")
+ # treat the output as a command line and split it up
+ separate_arguments(args NATIVE_COMMAND "${GDAL_CONFIG_LIBS}")
+
+ # only consider libraries whose name matches this pattern
+ set(name_pattern "[gG][dD][aA][lL]")
+
+ # consider each entry as a possible library path, name, or parent directory
+ foreach(arg IN LISTS args)
+ # library name
+ if("${arg}" MATCHES "^-l(.*)$")
+ set(lib "${CMAKE_MATCH_1}")
+
+ # only consider libraries whose name matches the expected pattern
+ if("${lib}" MATCHES "${name_pattern}")
+ list(APPEND _gdal_lib "${lib}")
+ endif()
+ # library search path
+ elseif("${arg}" MATCHES "^-L(.*)$")
+ list(APPEND _gdal_libpath "${CMAKE_MATCH_1}")
+ # assume this is a full path to a library
+ elseif(IS_ABSOLUTE "${arg}" AND EXISTS "${arg}")
+ # extract the file name
+ get_filename_component(lib "${arg}" NAME)
+
+ # only consider libraries whose name matches the expected pattern
+ if(NOT "${lib}" MATCHES "${name_pattern}")
+ continue()
+ endif()
+
+ # extract the file directory
+ get_filename_component(dir "${arg}" DIRECTORY)
+
+ # remove library prefixes/suffixes
+ string(REGEX REPLACE "^(${CMAKE_SHARED_LIBRARY_PREFIX}|${CMAKE_STATIC_LIBRARY_PREFIX})" "" lib "${lib}")
+ string(REGEX REPLACE "(${CMAKE_SHARED_LIBRARY_SUFFIX}|${CMAKE_STATIC_LIBRARY_SUFFIX})$" "" lib "${lib}")
+
+ # use the file name and directory as hints
+ list(APPEND _gdal_libpath "${dir}")
+ list(APPEND _gdal_lib "${lib}")
+ endif()
+ endforeach()
endif()
endif()
endif()
@@ -94,16 +138,28 @@ find_library(GDAL_LIBRARY
ENV GDAL_ROOT
${_gdal_libpath}
PATH_SUFFIXES lib
- PATHS
- /sw
- /opt/local
- /opt/csw
- /opt
- /usr/freeware
)
+if (EXISTS "${GDAL_INCLUDE_DIR}/gdal_version.h")
+ file(STRINGS "${GDAL_INCLUDE_DIR}/gdal_version.h" _gdal_version
+ REGEX "GDAL_RELEASE_NAME")
+ string(REGEX REPLACE ".*\"\(.*\)\"" "\\1" GDAL_VERSION "${_gdal_version}")
+ unset(_gdal_version)
+else ()
+ set(GDAL_VERSION GDAL_VERSION-NOTFOUND)
+endif ()
+
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL
+ VERSION_VAR GDAL_VERSION
+ REQUIRED_VARS GDAL_LIBRARY GDAL_INCLUDE_DIR)
+
+if (GDAL_FOUND AND NOT TARGET GDAL::GDAL)
+ add_library(GDAL::GDAL UNKNOWN IMPORTED)
+ set_target_properties(GDAL::GDAL PROPERTIES
+ IMPORTED_LOCATION "${GDAL_LIBRARY}"
+ INTERFACE_INCLUDE_DIRECTORIES "${GDAL_INCLUDE_DIR}")
+endif ()
set(GDAL_LIBRARIES ${GDAL_LIBRARY})
set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})
diff --git a/Modules/FindGIF.cmake b/Modules/FindGIF.cmake
index 0843d5fda..d5a143e81 100644
--- a/Modules/FindGIF.cmake
+++ b/Modules/FindGIF.cmake
@@ -1,28 +1,50 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindGIF
-# -------
-#
-# This finds the GIF library (giflib)
-#
-# The module defines the following variables:
-#
-# ``GIF_FOUND``
-# True if giflib was found
-# ``GIF_LIBRARIES``
-# Libraries to link to in order to use giflib
-# ``GIF_INCLUDE_DIR``
-# where to find the headers
-# ``GIF_VERSION``
-# 3, 4 or a full version string (eg 5.1.4) for versions >= 4.1.6
-#
-# 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
+#[=======================================================================[.rst:
+FindGIF
+-------
+
+This finds the Graphics Interchange Format (GIF) library (``giflib``)
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` target:
+
+``GIF::GIF``
+ The ``giflib`` library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``GIF_FOUND``
+ If false, do not try to use GIF.
+``GIF_INCLUDE_DIRS``
+ where to find gif_lib.h, etc.
+``GIF_LIBRARIES``
+ the libraries needed to use GIF.
+``GIF_VERSION``
+ 3, 4 or a full version string (eg 5.1.4) for versions >= 4.1.6.
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``GIF_INCLUDE_DIR``
+ where to find the GIF headers.
+``GIF_LIBRARY``
+ where to find the GIF library.
+
+Hints
+^^^^^
+
+``GIF_DIR`` is an environment variable that would correspond to the
+``./configure --prefix=$GIF_DIR``.
+#]=======================================================================]
# Created by Eric Wing.
# Modifications by Alexander Neundorf, Ben Campbell
@@ -31,9 +53,6 @@ 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 :-/
@@ -44,14 +63,8 @@ find_library(GIF_LIBRARY
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.
@@ -95,4 +108,20 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GIF REQUIRED_VARS GIF_LIBRARY GIF_INCLUDE_DIR
VERSION_VAR GIF_VERSION )
+if(GIF_FOUND)
+ set(GIF_INCLUDE_DIRS "${GIF_INCLUDE_DIR}")
+ set(GIF_LIBRARIES ${GIF_LIBRARY})
+
+ if(NOT TARGET GIF::GIF)
+ add_library(GIF::GIF UNKNOWN IMPORTED)
+ set_target_properties(GIF::GIF PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${GIF_INCLUDE_DIRS}")
+ if(EXISTS "${GIF_LIBRARY}")
+ set_target_properties(GIF::GIF PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "${GIF_LIBRARY}")
+ endif()
+ endif()
+endif()
+
mark_as_advanced(GIF_INCLUDE_DIR GIF_LIBRARY)
diff --git a/Modules/FindGLEW.cmake b/Modules/FindGLEW.cmake
index 11e872446..bd6981964 100644
--- a/Modules/FindGLEW.cmake
+++ b/Modules/FindGLEW.cmake
@@ -1,69 +1,342 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindGLEW
+--------
-find_path(GLEW_INCLUDE_DIR GL/glew.h)
+Find the OpenGL Extension Wrangler Library (GLEW)
+
+Input Variables
+^^^^^^^^^^^^^^^
+
+The following variables may be set to influence this module’s behavior:
+
+``GLEW_USE_STATIC_LIBS``
+ to find and create :prop_tgt:`IMPORTED` target for static linkage.
+
+``GLEW_VERBOSE``
+ to output a detailed log of this module.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :ref:`Imported Targets <Imported Targets>`:
-if(NOT GLEW_LIBRARY)
- find_library(GLEW_LIBRARY_RELEASE NAMES GLEW glew32 glew glew32s PATH_SUFFIXES lib64 libx32)
- find_library(GLEW_LIBRARY_DEBUG NAMES GLEWd glew32d glewd PATH_SUFFIXES lib64)
- include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
- select_library_configurations(GLEW)
-endif ()
+``GLEW::glew``
+ The GLEW shared library.
+``GLEW::glew_s``
+ The GLEW static library, if ``GLEW_USE_STATIC_LIBS`` is set to ``TRUE``.
+``GLEW::GLEW``
+ Duplicates either ``GLEW::glew`` or ``GLEW::glew_s`` based on availability.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``GLEW_INCLUDE_DIRS``
+ include directories for GLEW
+``GLEW_LIBRARIES``
+ libraries to link against GLEW
+``GLEW_SHARED_LIBRARIES``
+ libraries to link against shared GLEW
+``GLEW_STATIC_LIBRARIES``
+ libraries to link against static GLEW
+``GLEW_FOUND``
+ true if GLEW has been found and can be used
+``GLEW_VERSION``
+ GLEW version
+``GLEW_VERSION_MAJOR``
+ GLEW major version
+``GLEW_VERSION_MINOR``
+ GLEW minor version
+``GLEW_VERSION_MICRO``
+ GLEW micro version
+
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-find_package_handle_standard_args(GLEW
- REQUIRED_VARS GLEW_INCLUDE_DIR GLEW_LIBRARY)
+
+find_package(GLEW CONFIG QUIET)
if(GLEW_FOUND)
- set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR})
+ find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_CONFIG)
+ return()
+endif()
- if(NOT GLEW_LIBRARIES)
- set(GLEW_LIBRARIES ${GLEW_LIBRARY})
+if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: did not find GLEW CMake config file. Searching for libraries.")
+endif()
+
+if(APPLE)
+ find_package(OpenGL QUIET)
+
+ if(OpenGL_FOUND)
+ if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: Found OpenGL Framework.")
+ message(STATUS "FindGLEW: OPENGL_LIBRARIES: ${OPENGL_LIBRARIES}")
+ endif()
+ else()
+ if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: could not find GLEW library.")
+ endif()
+ return()
endif()
+endif()
+
- if (NOT TARGET GLEW::GLEW)
- add_library(GLEW::GLEW UNKNOWN IMPORTED)
- set_target_properties(GLEW::GLEW PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
+function(__glew_set_find_library_suffix shared_or_static)
+ if((UNIX AND NOT APPLE) AND "${shared_or_static}" MATCHES "SHARED")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" PARENT_SCOPE)
+ elseif((UNIX AND NOT APPLE) AND "${shared_or_static}" MATCHES "STATIC")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE)
+ elseif(APPLE AND "${shared_or_static}" MATCHES "SHARED")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib;.so" PARENT_SCOPE)
+ elseif(APPLE AND "${shared_or_static}" MATCHES "STATIC")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE)
+ elseif(WIN32 AND "${shared_or_static}" MATCHES "SHARED")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" PARENT_SCOPE)
+ elseif(WIN32 AND "${shared_or_static}" MATCHES "STATIC")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib;.dll.a" PARENT_SCOPE)
+ endif()
+
+ if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: CMAKE_FIND_LIBRARY_SUFFIXES for ${shared_or_static}: ${CMAKE_FIND_LIBRARY_SUFFIXES}")
+ endif()
+endfunction()
+
+
+if(GLEW_VERBOSE)
+ if(DEFINED GLEW_USE_STATIC_LIBS)
+ message(STATUS "FindGLEW: GLEW_USE_STATIC_LIBS: ${GLEW_USE_STATIC_LIBS}.")
+ else()
+ message(STATUS "FindGLEW: GLEW_USE_STATIC_LIBS is undefined. Treated as FALSE.")
+ endif()
+endif()
+
+find_path(GLEW_INCLUDE_DIR GL/glew.h)
+mark_as_advanced(GLEW_INCLUDE_DIR)
+
+set(GLEW_INCLUDE_DIRS ${GLEW_INCLUDE_DIR})
+
+if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: GLEW_INCLUDE_DIR: ${GLEW_INCLUDE_DIR}")
+ message(STATUS "FindGLEW: GLEW_INCLUDE_DIRS: ${GLEW_INCLUDE_DIRS}")
+endif()
+
+if("${CMAKE_GENERATOR_PLATFORM}" MATCHES "x64" OR "${CMAKE_GENERATOR}" MATCHES "Win64")
+ set(_arch "x64")
+else()
+ set(_arch "Win32")
+endif()
+
+
+set(__GLEW_CURRENT_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+
+__glew_set_find_library_suffix(SHARED)
+
+find_library(GLEW_SHARED_LIBRARY_RELEASE
+ NAMES GLEW glew glew32
+ PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch}
+ PATHS ENV GLEW_ROOT)
+
+find_library(GLEW_SHARED_LIBRARY_DEBUG
+ NAMES GLEWd glewd glew32d
+ PATH_SUFFIXES lib lib64
+ PATHS ENV GLEW_ROOT)
+
+
+__glew_set_find_library_suffix(STATIC)
+
+find_library(GLEW_STATIC_LIBRARY_RELEASE
+ NAMES GLEW glew glew32s
+ PATH_SUFFIXES lib lib64 libx32 lib/Release/${_arch}
+ PATHS ENV GLEW_ROOT)
+
+find_library(GLEW_STATIC_LIBRARY_DEBUG
+ NAMES GLEWds glewds glew32ds
+ PATH_SUFFIXES lib lib64
+ PATHS ENV GLEW_ROOT)
+
+set(CMAKE_FIND_LIBRARY_SUFFIXES ${__GLEW_CURRENT_FIND_LIBRARY_SUFFIXES})
+unset(__GLEW_CURRENT_FIND_LIBRARY_SUFFIXES)
+
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+
+select_library_configurations(GLEW_SHARED)
+select_library_configurations(GLEW_STATIC)
+
+if(NOT GLEW_USE_STATIC_LIBS)
+ set(GLEW_LIBRARIES ${GLEW_SHARED_LIBRARY})
+else()
+ set(GLEW_LIBRARIES ${GLEW_STATIC_LIBRARY})
+endif()
+
+
+if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY_RELEASE: ${GLEW_SHARED_LIBRARY_RELEASE}")
+ message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY_RELEASE: ${GLEW_STATIC_LIBRARY_RELEASE}")
+ message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY_DEBUG: ${GLEW_SHARED_LIBRARY_DEBUG}")
+ message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY_DEBUG: ${GLEW_STATIC_LIBRARY_DEBUG}")
+ message(STATUS "FindGLEW: GLEW_SHARED_LIBRARY: ${GLEW_SHARED_LIBRARY}")
+ message(STATUS "FindGLEW: GLEW_STATIC_LIBRARY: ${GLEW_STATIC_LIBRARY}")
+ message(STATUS "FindGLEW: GLEW_LIBRARIES: ${GLEW_LIBRARIES}")
+endif()
- if(GLEW_LIBRARY_RELEASE)
- set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- set_target_properties(GLEW::GLEW PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_LIBRARY_RELEASE}")
+
+# Read version from GL/glew.h file
+if(EXISTS "${GLEW_INCLUDE_DIR}/GL/glew.h")
+ file(STRINGS "${GLEW_INCLUDE_DIR}/GL/glew.h" _contents REGEX "^VERSION_.+ [0-9]+")
+ if(_contents)
+ string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MAJOR "${_contents}")
+ string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MINOR "${_contents}")
+ string(REGEX REPLACE ".*VERSION_MICRO[ \t]+([0-9]+).*" "\\1" GLEW_VERSION_MICRO "${_contents}")
+ set(GLEW_VERSION "${GLEW_VERSION_MAJOR}.${GLEW_VERSION_MINOR}.${GLEW_VERSION_MICRO}")
+ endif()
+endif()
+
+if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: GLEW_VERSION_MAJOR: ${GLEW_VERSION_MAJOR}")
+ message(STATUS "FindGLEW: GLEW_VERSION_MINOR: ${GLEW_VERSION_MINOR}")
+ message(STATUS "FindGLEW: GLEW_VERSION_MICRO: ${GLEW_VERSION_MICRO}")
+ message(STATUS "FindGLEW: GLEW_VERSION: ${GLEW_VERSION}")
+endif()
+
+find_package_handle_standard_args(GLEW
+ REQUIRED_VARS GLEW_INCLUDE_DIRS GLEW_LIBRARIES
+ VERSION_VAR GLEW_VERSION)
+
+if(NOT GLEW_FOUND)
+ if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: could not find GLEW library.")
+ endif()
+ return()
+endif()
+
+
+if(NOT TARGET GLEW::glew AND NOT GLEW_USE_STATIC_LIBS)
+ if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: Creating GLEW::glew imported target.")
+ endif()
+
+ add_library(GLEW::glew UNKNOWN IMPORTED)
+
+ set_target_properties(GLEW::glew
+ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
+
+ if(APPLE)
+ set_target_properties(GLEW::glew
+ PROPERTIES INTERFACE_LINK_LIBRARIES OpenGL::GL)
+ endif()
+
+ if(GLEW_SHARED_LIBRARY_RELEASE)
+ set_property(TARGET GLEW::glew
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+
+ set_target_properties(GLEW::glew
+ PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_SHARED_LIBRARY_RELEASE}")
+ endif()
+
+ if(GLEW_SHARED_LIBRARY_DEBUG)
+ set_property(TARGET GLEW::glew
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+
+ set_target_properties(GLEW::glew
+ PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_SHARED_LIBRARY_DEBUG}")
+ endif()
+
+elseif(NOT TARGET GLEW::glew_s AND GLEW_USE_STATIC_LIBS)
+ if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: Creating GLEW::glew_s imported target.")
+ endif()
+
+ add_library(GLEW::glew_s UNKNOWN IMPORTED)
+
+ set_target_properties(GLEW::glew_s
+ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
+
+ if(APPLE)
+ set_target_properties(GLEW::glew_s
+ PROPERTIES INTERFACE_LINK_LIBRARIES OpenGL::GL)
+ endif()
+
+ if(GLEW_STATIC_LIBRARY_RELEASE)
+ set_property(TARGET GLEW::glew_s
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+
+ set_target_properties(GLEW::glew_s
+ PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_STATIC_LIBRARY_RELEASE}")
+ endif()
+
+ if(GLEW_STATIC_LIBRARY_DEBUG)
+ set_property(TARGET GLEW::glew_s
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+
+ set_target_properties(GLEW::glew_s
+ PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_STATIC_LIBRARY_DEBUG}")
+ endif()
+endif()
+
+if(NOT TARGET GLEW::GLEW)
+ if(GLEW_VERBOSE)
+ message(STATUS "FindGLEW: Creating GLEW::GLEW imported target.")
+ endif()
+
+ add_library(GLEW::GLEW UNKNOWN IMPORTED)
+
+ set_target_properties(GLEW::GLEW
+ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLEW_INCLUDE_DIRS}")
+
+ if(APPLE)
+ set_target_properties(GLEW::GLEW
+ PROPERTIES INTERFACE_LINK_LIBRARIES OpenGL::GL)
+ endif()
+
+ if(TARGET GLEW::glew)
+ if(GLEW_SHARED_LIBRARY_RELEASE)
+ set_property(TARGET GLEW::GLEW
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+
+ set_target_properties(GLEW::GLEW
+ PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_SHARED_LIBRARY_RELEASE}")
endif()
- if(GLEW_LIBRARY_DEBUG)
- set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
- set_target_properties(GLEW::GLEW PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_LIBRARY_DEBUG}")
+ if(GLEW_SHARED_LIBRARY_DEBUG)
+ set_property(TARGET GLEW::GLEW
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+
+ set_target_properties(GLEW::GLEW
+ PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_SHARED_LIBRARY_DEBUG}")
endif()
- if(NOT GLEW_LIBRARY_RELEASE AND NOT GLEW_LIBRARY_DEBUG)
- set_property(TARGET GLEW::GLEW APPEND PROPERTY IMPORTED_LOCATION "${GLEW_LIBRARY}")
+ elseif(TARGET GLEW::glew_s)
+ if(GLEW_STATIC_LIBRARY_RELEASE)
+ set_property(TARGET GLEW::GLEW
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+
+ set_target_properties(GLEW::GLEW
+ PROPERTIES IMPORTED_LOCATION_RELEASE "${GLEW_STATIC_LIBRARY_RELEASE}")
endif()
+
+ if(GLEW_STATIC_LIBRARY_DEBUG AND GLEW_USE_STATIC_LIBS)
+ set_property(TARGET GLEW::GLEW
+ APPEND
+ PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+
+ set_target_properties(GLEW::GLEW
+ PROPERTIES IMPORTED_LOCATION_DEBUG "${GLEW_STATIC_LIBRARY_DEBUG}")
+ endif()
+
+ elseif(GLEW_VERBOSE)
+ message(WARNING "FindGLEW: no `GLEW::glew` or `GLEW::glew_s` target was created. Something went wrong in FindGLEW target creation.")
endif()
endif()
-
-mark_as_advanced(GLEW_INCLUDE_DIR)
diff --git a/Modules/FindGLU.cmake b/Modules/FindGLU.cmake
index dbec6d1cb..98928059c 100644
--- a/Modules/FindGLU.cmake
+++ b/Modules/FindGLU.cmake
@@ -15,4 +15,3 @@ 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
index 88d4b2918..a22bf5bca 100644
--- a/Modules/FindGLUT.cmake
+++ b/Modules/FindGLUT.cmake
@@ -1,53 +1,64 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindGLUT
+--------
+
+Find OpenGL Utility Toolkit (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.
+#]=======================================================================]
+
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
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
+ find_library( GLUT_glut_LIBRARY_RELEASE NAMES glut glut32 freeglut
PATHS
${OPENGL_LIBRARY_DIR}
${GLUT_ROOT_PATH}/Release
)
+ find_library( GLUT_glut_LIBRARY_DEBUG NAMES freeglutd
+ PATHS
+ ${OPENGL_LIBRARY_DIR}
+ ${GLUT_ROOT_PATH}/Debug
+ )
+ mark_as_advanced(GLUT_glut_LIBRARY_RELEASE GLUT_glut_LIBRARY_DEBUG)
+ select_library_configurations(GLUT_glut)
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")
+ mark_as_advanced(GLUT_glut_LIBRARY GLUT_cocoa_LIBRARY)
if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa)
add_library(GLUT::Cocoa UNKNOWN IMPORTED)
@@ -72,10 +83,12 @@ else ()
find_library( GLUT_Xi_LIBRARY Xi
/usr/openwin/lib
)
+ mark_as_advanced(GLUT_Xi_LIBRARY)
find_library( GLUT_Xmu_LIBRARY Xmu
/usr/openwin/lib
)
+ mark_as_advanced(GLUT_Xmu_LIBRARY)
if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi)
add_library(GLUT::Xi UNKNOWN IMPORTED)
@@ -104,6 +117,7 @@ else ()
/usr/openwin/lib
${_GLUT_glut_LIB_DIR}
)
+ mark_as_advanced(GLUT_glut_LIBRARY)
unset(_GLUT_INC_DIR)
unset(_GLUT_glut_LIB_DIR)
@@ -135,8 +149,24 @@ if (GLUT_FOUND)
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}")
+ if(GLUT_glut_LIBRARY_RELEASE)
+ set_property(TARGET GLUT::GLUT APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(GLUT::GLUT PROPERTIES
+ IMPORTED_LOCATION_RELEASE "${GLUT_glut_LIBRARY_RELEASE}")
+ endif()
+
+ if(GLUT_glut_LIBRARY_DEBUG)
+ set_property(TARGET GLUT::GLUT APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(GLUT::GLUT PROPERTIES
+ IMPORTED_LOCATION_DEBUG "${GLUT_glut_LIBRARY_DEBUG}")
+ endif()
+
+ if(NOT GLUT_glut_LIBRARY_RELEASE AND NOT GLUT_glut_LIBRARY_DEBUG)
+ set_property(TARGET GLUT::GLUT APPEND PROPERTY
+ IMPORTED_LOCATION "${GLUT_glut_LIBRARY}")
+ endif()
endif()
if(TARGET GLUT::Xmu)
@@ -160,9 +190,4 @@ if (GLUT_FOUND)
set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
endif()
-mark_as_advanced(
- GLUT_INCLUDE_DIR
- GLUT_glut_LIBRARY
- GLUT_Xmu_LIBRARY
- GLUT_Xi_LIBRARY
- )
+mark_as_advanced(GLUT_INCLUDE_DIR)
diff --git a/Modules/FindGSL.cmake b/Modules/FindGSL.cmake
index 8d10b6ce5..da1b3c4e4 100644
--- a/Modules/FindGSL.cmake
+++ b/Modules/FindGSL.cmake
@@ -1,60 +1,61 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindGSL
-# --------
-#
-# Find the native GSL includes and libraries.
-#
-# The GNU Scientific Library (GSL) is a numerical library for C and C++
-# programmers. It is free software under the GNU General Public
-# License.
-#
-# Imported Targets
-# ^^^^^^^^^^^^^^^^
-#
-# If GSL is found, this module defines the following :prop_tgt:`IMPORTED`
-# targets::
-#
-# GSL::gsl - The main GSL library.
-# GSL::gslcblas - The CBLAS support library used by GSL.
-#
-# Result Variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module will set the following variables in your project::
-#
-# GSL_FOUND - True if GSL found on the local system
-# GSL_INCLUDE_DIRS - Location of GSL header files.
-# GSL_LIBRARIES - The GSL libraries.
-# GSL_VERSION - The version of the discovered GSL install.
-#
-# Hints
-# ^^^^^
-#
-# Set ``GSL_ROOT_DIR`` to a directory that contains a GSL installation.
-#
-# This script expects to find libraries at ``$GSL_ROOT_DIR/lib`` and the GSL
-# headers at ``$GSL_ROOT_DIR/include/gsl``. The library directory may
-# optionally provide Release and Debug folders. If available, the libraries
-# named ``gsld``, ``gslblasd`` or ``cblasd`` are recognized as debug libraries.
-# For Unix-like systems, this script will use ``$GSL_ROOT_DIR/bin/gsl-config``
-# (if found) to aid in the discovery of GSL.
-#
-# Cache Variables
-# ^^^^^^^^^^^^^^^
-#
-# This module may set the following variables depending on platform and type
-# of GSL installation discovered. These variables may optionally be set to
-# help this module find the correct files::
-#
-# GSL_CBLAS_LIBRARY - Location of the GSL CBLAS library.
-# GSL_CBLAS_LIBRARY_DEBUG - Location of the debug GSL CBLAS library (if any).
-# GSL_CONFIG_EXECUTABLE - Location of the ``gsl-config`` script (if any).
-# GSL_LIBRARY - Location of the GSL library.
-# GSL_LIBRARY_DEBUG - Location of the debug GSL library (if any).
-#
+#[=======================================================================[.rst:
+FindGSL
+--------
+
+Find the native GNU Scientific Library (GSL) includes and libraries.
+
+The GNU Scientific Library (GSL) is a numerical library for C and C++
+programmers. It is free software under the GNU General Public
+License.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+If GSL is found, this module defines the following :prop_tgt:`IMPORTED`
+targets::
+
+ GSL::gsl - The main GSL library.
+ GSL::gslcblas - The CBLAS support library used by GSL.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project::
+
+ GSL_FOUND - True if GSL found on the local system
+ GSL_INCLUDE_DIRS - Location of GSL header files.
+ GSL_LIBRARIES - The GSL libraries.
+ GSL_VERSION - The version of the discovered GSL install.
+
+Hints
+^^^^^
+
+Set ``GSL_ROOT_DIR`` to a directory that contains a GSL installation.
+
+This script expects to find libraries at ``$GSL_ROOT_DIR/lib`` and the GSL
+headers at ``$GSL_ROOT_DIR/include/gsl``. The library directory may
+optionally provide Release and Debug folders. If available, the libraries
+named ``gsld``, ``gslblasd`` or ``cblasd`` are recognized as debug libraries.
+For Unix-like systems, this script will use ``$GSL_ROOT_DIR/bin/gsl-config``
+(if found) to aid in the discovery of GSL.
+
+Cache Variables
+^^^^^^^^^^^^^^^
+
+This module may set the following variables depending on platform and type
+of GSL installation discovered. These variables may optionally be set to
+help this module find the correct files::
+
+ GSL_CBLAS_LIBRARY - Location of the GSL CBLAS library.
+ GSL_CBLAS_LIBRARY_DEBUG - Location of the debug GSL CBLAS library (if any).
+ GSL_CONFIG_EXECUTABLE - Location of the ``gsl-config`` script (if any).
+ GSL_LIBRARY - Location of the GSL library.
+ GSL_LIBRARY_DEBUG - Location of the debug GSL library (if any).
+
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
diff --git a/Modules/FindGTK.cmake b/Modules/FindGTK.cmake
index 8a89cda6b..552b19a5f 100644
--- a/Modules/FindGTK.cmake
+++ b/Modules/FindGTK.cmake
@@ -1,18 +1,19 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindGTK
+-------
+
+Find GTK, 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
+#]=======================================================================]
# don't even bother under WIN32
if(UNIX)
@@ -31,20 +32,17 @@ if(UNIX)
# - Atanas Georgiev <atanas@cs.columbia.edu>
find_path( GTK_glibconfig_INCLUDE_PATH NAMES glibconfig.h
+ PATH_SUFFIXES glib/include lib/glib/include include/glib12
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
+ PATH_SUFFIXES gtk-1.2 glib-1.2 glib12 glib/include lib/glib/include
PATHS
/usr/openwin/share/include
- /usr/lib/glib/include
/opt/gnome/include
)
@@ -153,6 +151,3 @@ if(UNIX)
)
endif()
-
-
-
diff --git a/Modules/FindGTK2.cmake b/Modules/FindGTK2.cmake
index b87b9f3ab..83091f3d8 100644
--- a/Modules/FindGTK2.cmake
+++ b/Modules/FindGTK2.cmake
@@ -1,102 +1,101 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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_TARGETS - All imported targets
-# 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()
+#[=======================================================================[.rst:
+FindGTK2
+--------
+
+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_TARGETS - All imported targets
+ 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()
+#]=======================================================================]
# Version 1.6 (CMake 3.0)
# * Create targets for each library
@@ -260,6 +259,7 @@ function(_GTK2_FIND_INCLUDE_DIR _var _hdr)
gtkmm-2.4
libglade-2.0
libglademm-2.4
+ harfbuzz
pango-1.0
pangomm-1.4
sigc++-2.0
@@ -298,15 +298,11 @@ function(_GTK2_FIND_INCLUDE_DIR _var _hdr)
/usr/libx32
/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
@@ -354,13 +350,9 @@ function(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version)
if(_expand_vc AND MSVC)
# Add vc80/vc90/vc100 midfixes
- if(MSVC_VERSION EQUAL 1400)
- set(_library ${_library}-vc80)
- elseif(MSVC_VERSION EQUAL 1500)
- set(_library ${_library}-vc90)
- elseif(MSVC_VERSION EQUAL 1600)
- set(_library ${_library}-vc100)
- elseif(MSVC_VERSION EQUAL 1700)
+ if(MSVC_TOOLSET_VERSION LESS 110)
+ set(_library ${_library}-vc${MSVC_TOOLSET_VERSION})
+ else()
# Up to gtkmm-win 2.22.0-2 there are no vc110 libraries but vc100 can be used
set(_library ${_library}-vc100)
endif()
@@ -420,7 +412,6 @@ function(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version)
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
@@ -721,6 +712,8 @@ foreach(_GTK2_component ${GTK2_FIND_COMPONENTS})
_GTK2_FIND_LIBRARY (PANGO pango false true)
_GTK2_ADD_TARGET (PANGO GTK2_DEPENDS gobject glib)
+ _GTK2_FIND_INCLUDE_DIR(HARFBUZZ hb.h)
+
_GTK2_FIND_LIBRARY (PANGOCAIRO pangocairo false true)
_GTK2_ADD_TARGET (PANGOCAIRO GTK2_DEPENDS pango cairo gobject glib)
@@ -957,5 +950,5 @@ else()
endif()
if(GTK2_INCLUDE_DIRS)
- list(REMOVE_DUPLICATES GTK2_INCLUDE_DIRS)
+ list(REMOVE_DUPLICATES GTK2_INCLUDE_DIRS)
endif()
diff --git a/Modules/FindGTest.cmake b/Modules/FindGTest.cmake
index c4b4535ff..b0175febc 100644
--- a/Modules/FindGTest.cmake
+++ b/Modules/FindGTest.cmake
@@ -1,81 +1,82 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindGTest
-# ---------
-#
-# Locate the Google C++ Testing Framework.
-#
-# Imported targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following :prop_tgt:`IMPORTED` targets:
-#
-# ``GTest::GTest``
-# The Google Test ``gtest`` library, if found; adds Thread::Thread
-# automatically
-# ``GTest::Main``
-# The Google Test ``gtest_main`` library, if found
-#
-#
-# Result variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module will set the following variables in your project:
-#
-# ``GTEST_FOUND``
-# Found the Google Testing framework
-# ``GTEST_INCLUDE_DIRS``
-# the directory containing the Google Test headers
-#
-# The library variables below are set as normal variables. These
-# contain debug/optimized keywords when a debugging library is found.
-#
-# ``GTEST_LIBRARIES``
-# The Google Test ``gtest`` library; note it also requires linking
-# with an appropriate thread library
-# ``GTEST_MAIN_LIBRARIES``
-# The Google Test ``gtest_main`` library
-# ``GTEST_BOTH_LIBRARIES``
-# Both ``gtest`` and ``gtest_main``
-#
-# Cache variables
-# ^^^^^^^^^^^^^^^
-#
-# The following cache variables may also be set:
-#
-# ``GTEST_ROOT``
-# The root directory of the Google Test installation (may also be
-# set as an environment variable)
-# ``GTEST_MSVC_SEARCH``
-# If compiling with MSVC, this variable can be set to ``MT`` or
-# ``MD`` (the default) to enable searching a GTest build tree
-#
-#
-# Example usage
-# ^^^^^^^^^^^^^
-#
-# ::
-#
-# enable_testing()
-# find_package(GTest REQUIRED)
-#
-# add_executable(foo foo.cc)
-# target_link_libraries(foo GTest::GTest GTest::Main)
-#
-# add_test(AllTestsInFoo foo)
-#
-#
-# Deeper integration with CTest
-# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-#
-# See :module:`GoogleTest` for information on the :command:`gtest_add_tests`
-# command.
+#[=======================================================================[.rst:
+FindGTest
+---------
+
+Locate the Google C++ Testing Framework.
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``GTest::GTest``
+ The Google Test ``gtest`` library, if found; adds Thread::Thread
+ automatically
+``GTest::Main``
+ The Google Test ``gtest_main`` library, if found
+
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``GTEST_FOUND``
+ Found the Google Testing framework
+``GTEST_INCLUDE_DIRS``
+ the directory containing the Google Test headers
+
+The library variables below are set as normal variables. These
+contain debug/optimized keywords when a debugging library is found.
+
+``GTEST_LIBRARIES``
+ The Google Test ``gtest`` library; note it also requires linking
+ with an appropriate thread library
+``GTEST_MAIN_LIBRARIES``
+ The Google Test ``gtest_main`` library
+``GTEST_BOTH_LIBRARIES``
+ Both ``gtest`` and ``gtest_main``
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``GTEST_ROOT``
+ The root directory of the Google Test installation (may also be
+ set as an environment variable)
+``GTEST_MSVC_SEARCH``
+ If compiling with MSVC, this variable can be set to ``MT`` or
+ ``MD`` (the default) to enable searching a GTest build tree
+
+
+Example usage
+^^^^^^^^^^^^^
+
+::
+
+ enable_testing()
+ find_package(GTest REQUIRED)
+
+ add_executable(foo foo.cc)
+ target_link_libraries(foo GTest::GTest GTest::Main)
+
+ add_test(AllTestsInFoo foo)
+
+
+Deeper integration with CTest
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+See :module:`GoogleTest` for information on the :command:`gtest_add_tests`
+and :command:`gtest_discover_tests` commands.
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/GoogleTest.cmake)
-function(_gtest_append_debugs _endvar _library)
+function(__gtest_append_debugs _endvar _library)
if(${_library} AND ${_library}_DEBUG)
set(_output optimized ${${_library}} debug ${${_library}_DEBUG})
else()
@@ -84,7 +85,7 @@ function(_gtest_append_debugs _endvar _library)
set(${_endvar} ${_output} PARENT_SCOPE)
endfunction()
-function(_gtest_find_library _name)
+function(__gtest_find_library _name)
find_library(${_name}
NAMES ${ARGN}
HINTS
@@ -95,6 +96,56 @@ function(_gtest_find_library _name)
mark_as_advanced(${_name})
endfunction()
+macro(__gtest_determine_windows_library_type _var)
+ if(EXISTS "${${_var}}")
+ file(TO_NATIVE_PATH "${${_var}}" _lib_path)
+ get_filename_component(_name "${${_var}}" NAME_WE)
+ file(STRINGS "${${_var}}" _match REGEX "${_name}\\.dll" LIMIT_COUNT 1)
+ if(NOT _match STREQUAL "")
+ set(${_var}_TYPE SHARED PARENT_SCOPE)
+ else()
+ set(${_var}_TYPE UNKNOWN PARENT_SCOPE)
+ endif()
+ return()
+ endif()
+endmacro()
+
+function(__gtest_determine_library_type _var)
+ if(WIN32)
+ # For now, at least, only Windows really needs to know the library type
+ __gtest_determine_windows_library_type(${_var})
+ __gtest_determine_windows_library_type(${_var}_RELEASE)
+ __gtest_determine_windows_library_type(${_var}_DEBUG)
+ endif()
+ # If we get here, no determination was made from the above checks
+ set(${_var}_TYPE UNKNOWN PARENT_SCOPE)
+endfunction()
+
+function(__gtest_import_library _target _var _config)
+ if(_config)
+ set(_config_suffix "_${_config}")
+ else()
+ set(_config_suffix "")
+ endif()
+
+ set(_lib "${${_var}${_config_suffix}}")
+ if(EXISTS "${_lib}")
+ if(_config)
+ set_property(TARGET ${_target} APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS ${_config})
+ endif()
+ set_target_properties(${_target} PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES${_config_suffix} "CXX")
+ if(WIN32 AND ${_var}_TYPE STREQUAL SHARED)
+ set_target_properties(${_target} PROPERTIES
+ IMPORTED_IMPLIB${_config_suffix} "${_lib}")
+ else()
+ set_target_properties(${_target} PROPERTIES
+ IMPORTED_LOCATION${_config_suffix} "${_lib}")
+ endif()
+ endif()
+endfunction()
+
#
if(NOT DEFINED GTEST_MSVC_SEARCH)
@@ -131,15 +182,15 @@ 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)
+ __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)
+ __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)
@@ -147,63 +198,38 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTest DEFAULT_MSG GTEST_LIBRARY GTEST_INCLUDE_
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)
+ __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})
- include(CMakeFindDependencyMacro)
- find_dependency(Threads)
+ find_package(Threads QUIET)
if(NOT TARGET GTest::GTest)
- add_library(GTest::GTest UNKNOWN IMPORTED)
- set_target_properties(GTest::GTest PROPERTIES
- INTERFACE_LINK_LIBRARIES "Threads::Threads")
- if(GTEST_INCLUDE_DIRS)
- set_target_properties(GTest::GTest PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}")
- endif()
- if(EXISTS "${GTEST_LIBRARY}")
+ __gtest_determine_library_type(GTEST_LIBRARY)
+ add_library(GTest::GTest ${GTEST_LIBRARY_TYPE} IMPORTED)
+ if(TARGET Threads::Threads)
set_target_properties(GTest::GTest PROPERTIES
- IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
- IMPORTED_LOCATION "${GTEST_LIBRARY}")
+ INTERFACE_LINK_LIBRARIES Threads::Threads)
endif()
- if(EXISTS "${GTEST_LIBRARY_RELEASE}")
- set_property(TARGET GTest::GTest APPEND PROPERTY
- IMPORTED_CONFIGURATIONS RELEASE)
+ if(GTEST_LIBRARY_TYPE STREQUAL "SHARED")
set_target_properties(GTest::GTest PROPERTIES
- IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
- IMPORTED_LOCATION_RELEASE "${GTEST_LIBRARY_RELEASE}")
+ INTERFACE_COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
endif()
- if(EXISTS "${GTEST_LIBRARY_DEBUG}")
- set_property(TARGET GTest::GTest APPEND PROPERTY
- IMPORTED_CONFIGURATIONS DEBUG)
+ if(GTEST_INCLUDE_DIRS)
set_target_properties(GTest::GTest PROPERTIES
- IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
- IMPORTED_LOCATION_DEBUG "${GTEST_LIBRARY_DEBUG}")
+ INTERFACE_INCLUDE_DIRECTORIES "${GTEST_INCLUDE_DIRS}")
endif()
- endif()
- if(NOT TARGET GTest::Main)
- add_library(GTest::Main UNKNOWN IMPORTED)
- set_target_properties(GTest::Main PROPERTIES
- INTERFACE_LINK_LIBRARIES "GTest::GTest")
- if(EXISTS "${GTEST_MAIN_LIBRARY}")
- set_target_properties(GTest::Main PROPERTIES
- IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
- IMPORTED_LOCATION "${GTEST_MAIN_LIBRARY}")
- endif()
- if(EXISTS "${GTEST_MAIN_LIBRARY_RELEASE}")
- set_property(TARGET GTest::Main APPEND PROPERTY
- IMPORTED_CONFIGURATIONS RELEASE)
- set_target_properties(GTest::Main PROPERTIES
- IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
- IMPORTED_LOCATION_RELEASE "${GTEST_MAIN_LIBRARY_RELEASE}")
- endif()
- if(EXISTS "${GTEST_MAIN_LIBRARY_DEBUG}")
- set_property(TARGET GTest::Main APPEND PROPERTY
- IMPORTED_CONFIGURATIONS DEBUG)
- set_target_properties(GTest::Main PROPERTIES
- IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
- IMPORTED_LOCATION_DEBUG "${GTEST_MAIN_LIBRARY_DEBUG}")
- endif()
+ __gtest_import_library(GTest::GTest GTEST_LIBRARY "")
+ __gtest_import_library(GTest::GTest GTEST_LIBRARY "RELEASE")
+ __gtest_import_library(GTest::GTest GTEST_LIBRARY "DEBUG")
+ endif()
+ if(NOT TARGET GTest::Main)
+ __gtest_determine_library_type(GTEST_MAIN_LIBRARY)
+ add_library(GTest::Main ${GTEST_MAIN_LIBRARY_TYPE} IMPORTED)
+ set_target_properties(GTest::Main PROPERTIES
+ INTERFACE_LINK_LIBRARIES "GTest::GTest")
+ __gtest_import_library(GTest::Main GTEST_MAIN_LIBRARY "")
+ __gtest_import_library(GTest::Main GTEST_MAIN_LIBRARY "RELEASE")
+ __gtest_import_library(GTest::Main GTEST_MAIN_LIBRARY "DEBUG")
endif()
endif()
diff --git a/Modules/FindGettext.cmake b/Modules/FindGettext.cmake
index 803550715..213ad13de 100644
--- a/Modules/FindGettext.cmake
+++ b/Modules/FindGettext.cmake
@@ -1,75 +1,80 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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".
-#
-# .. note::
-# If you wish to use the Gettext library (libintl), use :module:`FindIntl`.
+#[=======================================================================[.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".
+
+.. note::
+ If you wish to use the Gettext library (libintl), use :module:`FindIntl`.
+#]=======================================================================]
find_program(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)
find_program(GETTEXT_MSGFMT_EXECUTABLE msgfmt)
if(GETTEXT_MSGMERGE_EXECUTABLE)
- execute_process(COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --version
+ 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)
+ get_filename_component(msgmerge_name ${GETTEXT_MSGMERGE_EXECUTABLE} NAME)
+ get_filename_component(msgmerge_namewe ${GETTEXT_MSGMERGE_EXECUTABLE} NAME_WE)
+ if (gettext_version MATCHES "^(${msgmerge_name}|${msgmerge_namewe}) \\([^\\)]*\\) ([0-9\\.]+[^ \n]*)")
+ set(GETTEXT_VERSION_STRING "${CMAKE_MATCH_2}")
+ endif()
+ unset(gettext_version)
+ unset(msgmerge_name)
+ unset(msgmerge_namewe)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
@@ -78,150 +83,150 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext
VERSION_VAR GETTEXT_VERSION_STRING)
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} )
+ 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()
+ # 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_custom_target(${uniqueTargetName} ${_addToAll} DEPENDS ${_gmoFiles})
- add_dependencies(translations ${uniqueTargetName})
+ 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 ()
+ 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)
+ 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()
+ if(_parsedArguments_ALL)
+ add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
+ else()
+ add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles})
+ endif()
- add_dependencies(potfiles ${uniqueTargetName})
+ 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()
+ 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)
+ 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()
+ if(_parsedArguments_ALL)
+ add_custom_target(${uniqueTargetName} ALL DEPENDS ${_gmoFiles})
+ else()
+ add_custom_target(${uniqueTargetName} DEPENDS ${_gmoFiles})
+ endif()
- add_dependencies(pofiles ${uniqueTargetName})
+ add_dependencies(pofiles ${uniqueTargetName})
endfunction()
diff --git a/Modules/FindGit.cmake b/Modules/FindGit.cmake
index fae31eb83..3491cdcc2 100644
--- a/Modules/FindGit.cmake
+++ b/Modules/FindGit.cmake
@@ -1,27 +1,34 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindGit
-# -------
-#
-# The module defines the following variables:
-#
-# ``GIT_EXECUTABLE``
-# Path to Git command-line client.
-# ``Git_FOUND``, ``GIT_FOUND``
-# True if the Git command-line client was found.
-# ``GIT_VERSION_STRING``
-# The version of Git found.
-#
-# Example usage:
-#
-# .. code-block:: cmake
-#
-# find_package(Git)
-# if(Git_FOUND)
-# message("Git found: ${GIT_EXECUTABLE}")
-# endif()
+#[=======================================================================[.rst:
+FindGit
+-------
+
+The module defines the following ``IMPORTED`` targets (when
+:prop_gbl:`CMAKE_ROLE` is ``PROJECT``):
+
+``Git::Git``
+ Executable of the Git command-line client.
+
+The module defines the following variables:
+
+``GIT_EXECUTABLE``
+ Path to Git command-line client.
+``Git_FOUND``, ``GIT_FOUND``
+ True if the Git command-line client was found.
+``GIT_VERSION_STRING``
+ The version of Git found.
+
+Example usage:
+
+.. code-block:: cmake
+
+ find_package(Git)
+ if(Git_FOUND)
+ message("Git found: ${GIT_EXECUTABLE}")
+ endif()
+#]=======================================================================]
# Look for 'git' or 'eg' (easy git)
#
@@ -77,6 +84,12 @@ if(GIT_EXECUTABLE)
string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
endif()
unset(git_version)
+
+ get_property(_findgit_role GLOBAL PROPERTY CMAKE_ROLE)
+ if(_findgit_role STREQUAL "PROJECT" AND NOT TARGET Git::Git)
+ add_executable(Git::Git IMPORTED)
+ set_property(TARGET Git::Git PROPERTY IMPORTED_LOCATION "${GIT_EXECUTABLE}")
+ endif()
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
diff --git a/Modules/FindGnuTLS.cmake b/Modules/FindGnuTLS.cmake
index 1a97d99ea..123a0f5d5 100644
--- a/Modules/FindGnuTLS.cmake
+++ b/Modules/FindGnuTLS.cmake
@@ -1,52 +1,53 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindGnuTLS
+----------
+
+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
+#]=======================================================================]
# 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)
+ # 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})
+ # 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}
- )
+ HINTS
+ ${PC_GNUTLS_INCLUDEDIR}
+ ${PC_GNUTLS_INCLUDE_DIRS}
+ )
find_library(GNUTLS_LIBRARY NAMES gnutls libgnutls
- HINTS
- ${PC_GNUTLS_LIBDIR}
- ${PC_GNUTLS_LIBRARY_DIRS}
- )
+ HINTS
+ ${PC_GNUTLS_LIBDIR}
+ ${PC_GNUTLS_LIBRARY_DIRS}
+ )
mark_as_advanced(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY)
@@ -56,6 +57,6 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(GnuTLS
VERSION_VAR GNUTLS_VERSION_STRING)
if(GNUTLS_FOUND)
- set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY})
- set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
+ set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY})
+ set(GNUTLS_INCLUDE_DIRS ${GNUTLS_INCLUDE_DIR})
endif()
diff --git a/Modules/FindGnuplot.cmake b/Modules/FindGnuplot.cmake
index aa4cd6c26..ca2467d68 100644
--- a/Modules/FindGnuplot.cmake
+++ b/Modules/FindGnuplot.cmake
@@ -1,25 +1,26 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake
index 5962c5bd4..08863c867 100644
--- a/Modules/FindHDF5.cmake
+++ b/Modules/FindHDF5.cmake
@@ -1,109 +1,131 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-#
-# Both the serial and parallel HDF5 wrappers are considered and the first
-# directory to contain either one will be used. In the event that both appear
-# in the same directory the serial version is preferentially selected. This
-# behavior can be reversed by setting the variable HDF5_PREFER_PARALLEL to
-# true.
-#
-# 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_FOUND - true if HDF5 was found on the system
-# HDF5_VERSION - HDF5 version in format Major.Minor.Release
-# 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_LIBRARIES - Required libraries for all requested bindings
-# HDF5_HL_LIBRARIES - Required libraries for the HDF5 high level API for all
-# bindings, if the HL component is enabled
-#
-# Available components are: C CXX Fortran and HL. For each enabled language
-# binding, a corresponding HDF5_${LANG}_LIBRARIES variable, and potentially
-# HDF5_${LANG}_DEFINITIONS, will be defined.
-# If the HL component is enabled, then an HDF5_${LANG}_HL_LIBRARIES will
-# also be defined. With all components enabled, the following variables will be defined:
-#
-# ::
-#
-# HDF5_C_DEFINITIONS -- Required compiler definitions for HDF5 C bindings
-# HDF5_CXX_DEFINITIONS -- Required compiler definitions for HDF5 C++ bindings
-# HDF5_Fortran_DEFINITIONS -- Required compiler definitions for HDF5 Fortran bindings
-# HDF5_C_INCLUDE_DIRS -- Required include directories for HDF5 C bindings
-# HDF5_CXX_INCLUDE_DIRS -- Required include directories for HDF5 C++ bindings
-# HDF5_Fortran_INCLUDE_DIRS -- Required include directories for HDF5 Fortran bindings
-# 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_C_HL_LIBRARIES - Required libraries for the high level C bindings
-# HDF5_CXX_HL_LIBRARIES - Required libraries for the high level C++ bindings
-# HDF5_Fortran_HL_LIBRARIES - Required libraries for the high level Fortran
-# bindings.
-#
-# 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_C_COMPILER_EXECUTABLE_NO_INTERROGATE - path to the primary C compiler
-# which is also the HDF5 wrapper
-# HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE - path to the primary C++
-# compiler which is also
-# the HDF5 wrapper
-# HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE - path to the primary
-# Fortran compiler which
-# is also the HDF5 wrapper
-# HDF5_DIFF_EXECUTABLE - the path to the HDF5 dataset comparison tool
-#
-# The following variable can be set to guide the search for HDF5 libraries and includes:
-#
-# ``HDF5_ROOT``
-# Specify the path to the HDF5 installation to use.
-#
-# ``HDF5_FIND_DEBUG``
-# Set to a true value to get some extra debugging output.
-#
-# ``HDF5_NO_FIND_PACKAGE_CONFIG_FILE``
-# Set to a true value to skip trying to find ``hdf5-config.cmake``.
+#[=======================================================================[.rst:
+FindHDF5
+--------
+
+Find Hierarchical Data Format (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.
+
+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.
+
+Both the serial and parallel ``HDF5`` wrappers are considered and the first
+directory to contain either one will be used. In the event that both appear
+in the same directory the serial version is preferentially selected. This
+behavior can be reversed by setting the variable ``HDF5_PREFER_PARALLEL`` to
+``True``.
+
+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.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``HDF5_FOUND``
+ HDF5 was found on the system
+``HDF5_VERSION``
+ HDF5 library version
+``HDF5_INCLUDE_DIRS``
+ Location of the HDF5 header files
+``HDF5_DEFINITIONS``
+ Required compiler definitions for HDF5
+``HDF5_LIBRARIES``
+ Required libraries for all requested bindings
+``HDF5_HL_LIBRARIES``
+ Required libraries for the HDF5 high level API for all bindings,
+ if the ``HL`` component is enabled
+
+Available components are: ``C`` ``CXX`` ``Fortran`` and ``HL``.
+For each enabled language binding, a corresponding ``HDF5_${LANG}_LIBRARIES``
+variable, and potentially ``HDF5_${LANG}_DEFINITIONS``, will be defined.
+If the ``HL`` component is enabled, then an ``HDF5_${LANG}_HL_LIBRARIES`` will
+also be defined. With all components enabled, the following variables will be defined:
+
+``HDF5_C_DEFINITIONS``
+ Required compiler definitions for HDF5 C bindings
+``HDF5_CXX_DEFINITIONS``
+ Required compiler definitions for HDF5 C++ bindings
+``HDF5_Fortran_DEFINITIONS``
+ Required compiler definitions for HDF5 Fortran bindings
+``HDF5_C_INCLUDE_DIRS``
+ Required include directories for HDF5 C bindings
+``HDF5_CXX_INCLUDE_DIRS``
+ Required include directories for HDF5 C++ bindings
+``HDF5_Fortran_INCLUDE_DIRS``
+ Required include directories for HDF5 Fortran bindings
+``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_C_HL_LIBRARIES``
+ Required libraries for the high level C bindings
+``HDF5_CXX_HL_LIBRARIES``
+ Required libraries for the high level C++ bindings
+``HDF5_Fortran_HL_LIBRARIES``
+ Required libraries for the high level Fortran bindings.
+
+``HDF5_IS_PARALLEL``
+ HDF5 library has parallel IO support
+``HDF5_C_COMPILER_EXECUTABLE``
+ path to the HDF5 C wrapper compiler
+``HDF5_CXX_COMPILER_EXECUTABLE``
+ path to the HDF5 C++ wrapper compiler
+``HDF5_Fortran_COMPILER_EXECUTABLE``
+ path to the HDF5 Fortran wrapper compiler
+``HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE``
+ path to the primary C compiler which is also the HDF5 wrapper
+``HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE``
+ path to the primary C++ compiler which is also the HDF5 wrapper
+``HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE``
+ path to the primary Fortran compiler which is also the HDF5 wrapper
+``HDF5_DIFF_EXECUTABLE``
+ path to the HDF5 dataset comparison tool
+
+Hints
+^^^^^
+
+The following variable can be set to guide the search for HDF5 libraries and includes:
+
+``HDF5_ROOT``
+ Specify the path to the HDF5 installation to use.
+
+``HDF5_FIND_DEBUG``
+ Set ``true`` to get extra debugging output.
+
+``HDF5_NO_FIND_PACKAGE_CONFIG_FILE``
+ Set ``true`` to skip trying to find ``hdf5-config.cmake``.
+#]=======================================================================]
# This module is maintained by Will Dicharry <wdicharry@stellarscience.com>.
@@ -187,8 +209,16 @@ function(_HDF5_test_regular_compiler_C success version is_parallel)
file(WRITE ${test_file}
"#include <hdf5.h>\n"
"#include <hdf5_hl.h>\n"
- "int main(void) {\n"
- " char const* info_ver = \"INFO\" \":\" H5_VERSION;\n"
+ "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n"
+ "#ifdef H5_HAVE_PARALLEL\n"
+ "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n"
+ "#endif\n"
+ "int main(int argc, char **argv) {\n"
+ " int require = 0;\n"
+ " require += info_ver[argc];\n"
+ "#ifdef H5_HAVE_PARALLEL\n"
+ " require += info_parallel[argc];\n"
+ "#endif\n"
" hid_t fid;\n"
" fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n"
" return 0;\n"
@@ -198,24 +228,19 @@ function(_HDF5_test_regular_compiler_C success version is_parallel)
)
endif()
if(${success})
- file(STRINGS ${scratch_directory}/compiler_has_h5_c INFO_VER
- REGEX "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
+ file(STRINGS ${scratch_directory}/compiler_has_h5_c INFO_STRINGS
+ REGEX "^INFO:"
)
string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
- INFO_VER "${INFO_VER}"
+ INFO_VER "${INFO_STRINGS}"
)
set(${version} ${CMAKE_MATCH_1})
if(CMAKE_MATCH_3)
- set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3})
+ set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3})
endif()
set(${version} ${${version}} PARENT_SCOPE)
- execute_process(COMMAND ${CMAKE_C_COMPILER} -showconfig
- OUTPUT_VARIABLE config_output
- ERROR_VARIABLE config_error
- RESULT_VARIABLE config_result
- )
- if(config_output MATCHES "Parallel HDF5: yes")
+ if(INFO_STRINGS MATCHES "INFO:PARALLEL")
set(${is_parallel} TRUE PARENT_SCOPE)
else()
set(${is_parallel} FALSE PARENT_SCOPE)
@@ -233,8 +258,16 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel)
"#ifndef H5_NO_NAMESPACE\n"
"using namespace H5;\n"
"#endif\n"
+ "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n"
+ "#ifdef H5_HAVE_PARALLEL\n"
+ "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n"
+ "#endif\n"
"int main(int argc, char **argv) {\n"
- " char const* info_ver = \"INFO\" \":\" H5_VERSION;\n"
+ " int require = 0;\n"
+ " require += info_ver[argc];\n"
+ "#ifdef H5_HAVE_PARALLEL\n"
+ " require += info_parallel[argc];\n"
+ "#endif\n"
" H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n"
" return 0;\n"
"}")
@@ -243,11 +276,11 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel)
)
endif()
if(${success})
- file(STRINGS ${scratch_directory}/compiler_has_h5_cxx INFO_VER
- REGEX "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
+ file(STRINGS ${scratch_directory}/compiler_has_h5_cxx INFO_STRINGS
+ REGEX "^INFO:"
)
string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
- INFO_VER "${INFO_VER}"
+ INFO_VER "${INFO_STRINGS}"
)
set(${version} ${CMAKE_MATCH_1})
if(CMAKE_MATCH_3)
@@ -255,12 +288,7 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel)
endif()
set(${version} ${${version}} PARENT_SCOPE)
- execute_process(COMMAND ${CMAKE_CXX_COMPILER} -showconfig
- OUTPUT_VARIABLE config_output
- ERROR_VARIABLE config_error
- RESULT_VARIABLE config_result
- )
- if(config_output MATCHES "Parallel HDF5: yes")
+ if(INFO_STRINGS MATCHES "INFO:PARALLEL")
set(${is_parallel} TRUE PARENT_SCOPE)
else()
set(${is_parallel} FALSE PARENT_SCOPE)
@@ -315,20 +343,22 @@ macro( _HDF5_invoke_compiler language output return_value version is_parallel)
elseif("${language}" STREQUAL "Fortran")
set(test_file ${scratch_dir}/cmake_hdf5_test.f90)
endif()
- exec_program( ${HDF5_${language}_COMPILER_EXECUTABLE}
- ARGS -show ${lib_type_args} ${test_file}
- OUTPUT_VARIABLE ${output}
- RETURN_VALUE ${return_value}
- )
+ execute_process(
+ COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} ${test_file}
+ OUTPUT_VARIABLE ${output}
+ ERROR_VARIABLE ${output}
+ RESULT_VARIABLE ${return_value}
+ )
if(NOT ${${return_value}} EQUAL 0)
message(STATUS
"Unable to determine HDF5 ${language} flags from HDF5 wrapper.")
endif()
- exec_program( ${HDF5_${language}_COMPILER_EXECUTABLE}
- ARGS -showconfig
- OUTPUT_VARIABLE config_output
- RETURN_VALUE config_return
- )
+ execute_process(
+ COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig
+ OUTPUT_VARIABLE config_output
+ ERROR_VARIABLE config_output
+ RESULT_VARIABLE config_return
+ )
if(NOT ${return_value} EQUAL 0)
message( STATUS
"Unable to determine HDF5 ${language} version from HDF5 wrapper.")
@@ -390,6 +420,45 @@ macro( _HDF5_parse_compile_line
endforeach()
endmacro()
+# Select a preferred imported configuration from a target
+function(_HDF5_select_imported_config target imported_conf)
+ # We will first assign the value to a local variable _imported_conf, then assign
+ # it to the function argument at the end.
+ get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE})
+ if (NOT _imported_conf)
+ # Get available imported configurations by examining target properties
+ get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS)
+ if(HDF5_FIND_DEBUG)
+ message(STATUS "Found imported configurations: ${_imported_conf}")
+ endif()
+ # Find the imported configuration that we prefer.
+ # We do this by making list of configurations in order of preference,
+ # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf
+ set(_preferred_confs ${CMAKE_BUILD_TYPE})
+ list(GET _imported_conf 0 _fallback_conf)
+ list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf})
+ if(HDF5_FIND_DEBUG)
+ message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}")
+ endif()
+ # Now find the first of these that is present in imported_conf
+ cmake_policy(PUSH)
+ cmake_policy(SET CMP0057 NEW) # support IN_LISTS
+ foreach (_conf IN LISTS _preferred_confs)
+ if (${_conf} IN_LIST _imported_conf)
+ set(_imported_conf ${_conf})
+ break()
+ endif()
+ endforeach()
+ cmake_policy(POP)
+ endif()
+ if(HDF5_FIND_DEBUG)
+ message(STATUS "Selected imported configuration: ${_imported_conf}")
+ endif()
+ # assign value to function argument
+ set(${imported_conf} ${_imported_conf} PARENT_SCOPE)
+endfunction()
+
+
if(NOT HDF5_ROOT)
set(HDF5_ROOT $ENV{HDF5_ROOT})
endif()
@@ -434,7 +503,7 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE)
#if we detect that occurrence clear the suffix
if(_suffix AND NOT TARGET ${HDF5_${_lang}_TARGET}${_suffix})
if(NOT TARGET ${HDF5_${_lang}_TARGET})
- #cant find this component with or without the suffix
+ #can't find this component with or without the suffix
#so bail out, and let the following locate HDF5
set(HDF5_FOUND FALSE)
break()
@@ -446,30 +515,39 @@ if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE)
message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}")
endif()
# Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib.
- get_target_property(_imported_conf ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_CONFIGURATIONS)
- get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} )
- if (NOT _lang_location)
+ _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf)
+ get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} )
+ if (NOT _hdf5_lang_location)
# no import lib, just try LOCATION
- get_target_property(_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION)
+ get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf})
+ if (NOT _hdf5_lang_location)
+ get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION)
+ endif()
endif()
- if( _lang_location )
- set(HDF5_${_lang}_LIBRARY ${_lang_location})
+ if( _hdf5_lang_location )
+ set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location})
list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
set(HDF5_${_lang}_FOUND True)
endif()
if(FIND_HL)
- get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_imported_conf} )
- if (NOT _lang_hl_location)
- get_target_property(_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION)
+ get_target_property(__lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} )
+ if (NOT _hdf5_lang_hl_location)
+ get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf})
+ if (NOT _hdf5_hl_lang_location)
+ get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION)
+ endif()
endif()
- if( _lang_hl_location )
- set(HDF5_${_lang}_HL_LIBRARY ${_lang_hl_location})
- list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
- set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
+ if( _hdf5_lang_hl_location )
+ set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location})
+ list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix})
+ set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix})
set(HDF5_HL_FOUND True)
endif()
+ unset(_hdf5_lang_hl_location)
endif()
+ unset(_hdf5_imported_conf)
+ unset(_hdf5_lang_location)
endforeach()
endif()
endif()
@@ -545,8 +623,12 @@ if(NOT HDF5_FOUND)
if("x${L}" MATCHES "hdf5")
# hdf5 library
set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
- if(UNIX AND HDF5_USE_STATIC_LIBRARIES)
- set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a)
+ if(HDF5_USE_STATIC_LIBRARIES)
+ if(WIN32)
+ set(_HDF5_SEARCH_NAMES_LOCAL lib${L})
+ else()
+ set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a)
+ endif()
endif()
else()
# external library
@@ -573,8 +655,12 @@ if(NOT HDF5_FOUND)
if("x${L}" MATCHES "hdf5")
# hdf5 library
set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
- if(UNIX AND HDF5_USE_STATIC_LIBRARIES)
- set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a)
+ if(HDF5_USE_STATIC_LIBRARIES)
+ if(WIN32)
+ set(_HDF5_SEARCH_NAMES_LOCAL lib${L})
+ else()
+ set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a)
+ endif()
endif()
else()
# external library
@@ -706,19 +792,22 @@ if( NOT HDF5_FOUND )
# find the HDF5 libraries
foreach(LIB IN LISTS HDF5_${__lang}_LIBRARY_NAMES)
- if(UNIX AND HDF5_USE_STATIC_LIBRARIES)
+ if(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 https://gitlab.kitware.com/cmake/cmake/issues/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${LIB}_debug.a ${LIB}d ${LIB}_debug
- lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_debug-static )
- set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} lib${LIB}-static.a ${LIB}-static)
+ lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug
+ lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static )
+ set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static)
else()
- set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_debug ${LIB}d-shared ${LIB}_debug-shared)
+ set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared)
set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared)
+ if(WIN32)
+ list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB")
+ endif()
endif()
find_library(HDF5_${LIB}_LIBRARY_DEBUG
NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
@@ -743,18 +832,18 @@ if( NOT HDF5_FOUND )
if(FIND_HL)
foreach(LIB IN LISTS HDF5_${__lang}_HL_LIBRARY_NAMES)
- if(UNIX AND HDF5_USE_STATIC_LIBRARIES)
+ if(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 https://gitlab.kitware.com/cmake/cmake/issues/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${LIB}_debug.a ${LIB}d ${LIB}_debug
- lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_debug-static )
- set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a ${LIB} lib${LIB}-static.a ${LIB}-static)
+ lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug
+ lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static )
+ set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a lib${LIB}-static)
else()
- set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_debug ${LIB}d-shared ${LIB}_debug-shared)
+ set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared)
set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared)
endif()
find_library(HDF5_${LIB}_LIBRARY_DEBUG
@@ -780,6 +869,7 @@ if( NOT HDF5_FOUND )
set(HDF5_HL_FOUND True)
endif()
+ _HDF5_remove_duplicates_from_beginning(HDF5_DEFINITIONS)
_HDF5_remove_duplicates_from_beginning(HDF5_INCLUDE_DIRS)
_HDF5_remove_duplicates_from_beginning(HDF5_LIBRARIES)
_HDF5_remove_duplicates_from_beginning(HDF5_HL_LIBRARIES)
@@ -855,11 +945,14 @@ if (HDF5_FIND_DEBUG)
message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}")
message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}")
+ message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}")
foreach(__lang IN LISTS HDF5_LANGUAGE_BINDINGS)
message(STATUS "HDF5_${__lang}_DEFINITIONS: ${HDF5_${__lang}_DEFINITIONS}")
message(STATUS "HDF5_${__lang}_INCLUDE_DIR: ${HDF5_${__lang}_INCLUDE_DIR}")
message(STATUS "HDF5_${__lang}_INCLUDE_DIRS: ${HDF5_${__lang}_INCLUDE_DIRS}")
message(STATUS "HDF5_${__lang}_LIBRARY: ${HDF5_${__lang}_LIBRARY}")
message(STATUS "HDF5_${__lang}_LIBRARIES: ${HDF5_${__lang}_LIBRARIES}")
+ message(STATUS "HDF5_${__lang}_HL_LIBRARY: ${HDF5_${__lang}_HL_LIBRARY}")
+ message(STATUS "HDF5_${__lang}_HL_LIBRARIES: ${HDF5_${__lang}_HL_LIBRARIES}")
endforeach()
endif()
diff --git a/Modules/FindHSPELL.cmake b/Modules/FindHSPELL.cmake
index bb0e2f08e..9724d2cf1 100644
--- a/Modules/FindHSPELL.cmake
+++ b/Modules/FindHSPELL.cmake
@@ -1,28 +1,29 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindHSPELL
+----------
+
+Try to find Hebrew spell-checker (Hspell) and morphology engine.
+
+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
+#]=======================================================================]
find_path(HSPELL_INCLUDE_DIR hspell.h)
diff --git a/Modules/FindHTMLHelp.cmake b/Modules/FindHTMLHelp.cmake
index 84e2458af..a11ad4d69 100644
--- a/Modules/FindHTMLHelp.cmake
+++ b/Modules/FindHTMLHelp.cmake
@@ -1,45 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.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)
+#]=======================================================================]
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"
+ NAMES hhc
+ PATHS
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]"
+ PATH_SUFFIXES "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"
+ NAMES htmlhelp.h
+ PATHS
+ "${HTML_HELP_COMPILER_PATH}/include"
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/include"
+ PATH_SUFFIXES "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"
+ NAMES htmlhelp
+ PATHS
+ "${HTML_HELP_COMPILER_PATH}/lib"
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\HTML Help Workshop;InstallDir]/lib"
+ PATH_SUFFIXES "HTML Help Workshop/lib"
)
mark_as_advanced(
diff --git a/Modules/FindHg.cmake b/Modules/FindHg.cmake
index 8aa553e79..1358363d2 100644
--- a/Modules/FindHg.cmake
+++ b/Modules/FindHg.cmake
@@ -1,45 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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()
+#[=======================================================================[.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()
+#]=======================================================================]
find_program(HG_EXECUTABLE
NAMES hg
diff --git a/Modules/FindICU.cmake b/Modules/FindICU.cmake
index 5210f0806..38081f5fa 100644
--- a/Modules/FindICU.cmake
+++ b/Modules/FindICU.cmake
@@ -1,84 +1,90 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindICU
-# -------
-#
-# Find the International Components for Unicode (ICU) libraries and
-# programs.
-#
-# This module supports multiple components.
-# Components can include any of: ``data``, ``i18n``, ``io``, ``le``,
-# ``lx``, ``test``, ``tu`` and ``uc``.
-#
-# Note that on Windows ``data`` is named ``dt`` and ``i18n`` is named
-# ``in``; any of the names may be used, and the appropriate
-# platform-specific library name will be automatically selected.
-#
-# This module reports information about the ICU installation in
-# several variables. General variables::
-#
-# ICU_VERSION - ICU release version
-# ICU_FOUND - true if the main programs and libraries were found
-# ICU_LIBRARIES - component libraries to be linked
-# ICU_INCLUDE_DIRS - the directories containing the ICU headers
-#
-# Imported targets::
-#
-# ICU::<C>
-#
-# Where ``<C>`` is the name of an ICU component, for example
-# ``ICU::i18n``.
-#
-# ICU programs are reported in::
-#
-# ICU_GENCNVAL_EXECUTABLE - path to gencnval executable
-# ICU_ICUINFO_EXECUTABLE - path to icuinfo executable
-# ICU_GENBRK_EXECUTABLE - path to genbrk executable
-# ICU_ICU-CONFIG_EXECUTABLE - path to icu-config executable
-# ICU_GENRB_EXECUTABLE - path to genrb executable
-# ICU_GENDICT_EXECUTABLE - path to gendict executable
-# ICU_DERB_EXECUTABLE - path to derb executable
-# ICU_PKGDATA_EXECUTABLE - path to pkgdata executable
-# ICU_UCONV_EXECUTABLE - path to uconv executable
-# ICU_GENCFU_EXECUTABLE - path to gencfu executable
-# ICU_MAKECONV_EXECUTABLE - path to makeconv executable
-# ICU_GENNORM2_EXECUTABLE - path to gennorm2 executable
-# ICU_GENCCODE_EXECUTABLE - path to genccode executable
-# ICU_GENSPREP_EXECUTABLE - path to gensprep executable
-# ICU_ICUPKG_EXECUTABLE - path to icupkg executable
-# ICU_GENCMN_EXECUTABLE - path to gencmn executable
-#
-# ICU component libraries are reported in::
-#
-# ICU_<C>_FOUND - ON if component was found
-# ICU_<C>_LIBRARIES - libraries for component
-#
-# Note that ``<C>`` is the uppercased name of the component.
-#
-# This module reads hints about search results from::
-#
-# ICU_ROOT - the root of the ICU installation
-#
-# The environment variable ``ICU_ROOT`` may also be used; the
-# ICU_ROOT variable takes precedence.
-#
-# The following cache variables may also be set::
-#
-# ICU_<P>_EXECUTABLE - the path to executable <P>
-# ICU_INCLUDE_DIR - the directory containing the ICU headers
-# ICU_<C>_LIBRARY - the library for component <C>
-#
-# .. note::
-#
-# In most cases none of the above variables will require setting,
-# unless multiple ICU versions are available and a specific version
-# is required.
-#
-# Other variables one may set to control this module are::
-#
-# ICU_DEBUG - Set to ON to enable debug output from FindICU.
+#[=======================================================================[.rst:
+FindICU
+-------
+
+Find the International Components for Unicode (ICU) libraries and
+programs.
+
+This module supports multiple components.
+Components can include any of: ``data``, ``i18n``, ``io``, ``le``,
+``lx``, ``test``, ``tu`` and ``uc``.
+
+Note that on Windows ``data`` is named ``dt`` and ``i18n`` is named
+``in``; any of the names may be used, and the appropriate
+platform-specific library name will be automatically selected.
+
+This module reports information about the ICU installation in
+several variables. General variables::
+
+ ICU_VERSION - ICU release version
+ ICU_FOUND - true if the main programs and libraries were found
+ ICU_LIBRARIES - component libraries to be linked
+ ICU_INCLUDE_DIRS - the directories containing the ICU headers
+
+Imported targets::
+
+ ICU::<C>
+
+Where ``<C>`` is the name of an ICU component, for example
+``ICU::i18n``.
+
+ICU programs are reported in::
+
+ ICU_GENCNVAL_EXECUTABLE - path to gencnval executable
+ ICU_ICUINFO_EXECUTABLE - path to icuinfo executable
+ ICU_GENBRK_EXECUTABLE - path to genbrk executable
+ ICU_ICU-CONFIG_EXECUTABLE - path to icu-config executable
+ ICU_GENRB_EXECUTABLE - path to genrb executable
+ ICU_GENDICT_EXECUTABLE - path to gendict executable
+ ICU_DERB_EXECUTABLE - path to derb executable
+ ICU_PKGDATA_EXECUTABLE - path to pkgdata executable
+ ICU_UCONV_EXECUTABLE - path to uconv executable
+ ICU_GENCFU_EXECUTABLE - path to gencfu executable
+ ICU_MAKECONV_EXECUTABLE - path to makeconv executable
+ ICU_GENNORM2_EXECUTABLE - path to gennorm2 executable
+ ICU_GENCCODE_EXECUTABLE - path to genccode executable
+ ICU_GENSPREP_EXECUTABLE - path to gensprep executable
+ ICU_ICUPKG_EXECUTABLE - path to icupkg executable
+ ICU_GENCMN_EXECUTABLE - path to gencmn executable
+
+ICU component libraries are reported in::
+
+ ICU_<C>_FOUND - ON if component was found
+ ICU_<C>_LIBRARIES - libraries for component
+
+ICU datafiles are reported in::
+
+ ICU_MAKEFILE_INC - Makefile.inc
+ ICU_PKGDATA_INC - pkgdata.inc
+
+Note that ``<C>`` is the uppercased name of the component.
+
+This module reads hints about search results from::
+
+ ICU_ROOT - the root of the ICU installation
+
+The environment variable ``ICU_ROOT`` may also be used; the
+ICU_ROOT variable takes precedence.
+
+The following cache variables may also be set::
+
+ ICU_<P>_EXECUTABLE - the path to executable <P>
+ ICU_INCLUDE_DIR - the directory containing the ICU headers
+ ICU_<C>_LIBRARY - the library for component <C>
+
+.. note::
+
+ In most cases none of the above variables will require setting,
+ unless multiple ICU versions are available and a specific version
+ is required.
+
+Other variables one may set to control this module are::
+
+ ICU_DEBUG - Set to ON to enable debug output from FindICU.
+#]=======================================================================]
# Written by Roger Leigh <rleigh@codelibre.net>
@@ -100,6 +106,10 @@ set(icu_programs
icupkg
gencmn)
+set(icu_data
+ Makefile.inc
+ pkgdata.inc)
+
# The ICU checks are contained in a function due to the large number
# of temporary variables needed.
function(_ICU_FIND)
@@ -116,32 +126,8 @@ function(_ICU_FIND)
endif()
endif()
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- # 64-bit binary directory
- set(_bin64 "bin64")
- # 64-bit library directory
- set(_lib64 "lib64")
- endif()
-
- # Generic 64-bit and 32-bit directories
- list(APPEND icu_binary_suffixes "${_bin64}" "bin")
- list(APPEND icu_library_suffixes "${_lib64}" "lib")
- list(APPEND icu_include_suffixes "include")
-
- # Find all ICU programs
- foreach(program ${icu_programs})
- string(TOUPPER "${program}" program_upcase)
- set(cache_var "ICU_${program_upcase}_EXECUTABLE")
- set(program_var "ICU_${program_upcase}_EXECUTABLE")
- find_program("${cache_var}" "${program}"
- HINTS ${icu_roots}
- PATH_SUFFIXES ${icu_binary_suffixes}
- DOC "ICU ${program} executable")
- mark_as_advanced(cache_var)
- set("${program_var}" "${${cache_var}}" PARENT_SCOPE)
- endforeach()
-
# Find include directory
+ list(APPEND icu_include_suffixes "include")
find_path(ICU_INCLUDE_DIR
NAMES "unicode/utypes.h"
HINTS ${icu_roots}
@@ -156,13 +142,45 @@ function(_ICU_FIND)
string(REGEX REPLACE "^#define[\t ]+U_ICU_VERSION[\t ]+\"([^ \\n]*)\".*"
"\\1" icu_version_string "${icu_header_str}")
+ set(ICU_VERSION "${icu_version_string}")
set(ICU_VERSION "${icu_version_string}" PARENT_SCOPE)
unset(icu_header_str)
unset(icu_version_string)
endif()
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ # 64-bit binary directory
+ set(_bin64 "bin64")
+ # 64-bit library directory
+ set(_lib64 "lib64")
+ endif()
+
+
+ # Find all ICU programs
+ list(APPEND icu_binary_suffixes "${_bin64}" "bin" "sbin")
+ foreach(program ${icu_programs})
+ string(TOUPPER "${program}" program_upcase)
+ set(cache_var "ICU_${program_upcase}_EXECUTABLE")
+ set(program_var "ICU_${program_upcase}_EXECUTABLE")
+ find_program("${cache_var}"
+ NAMES "${program}"
+ HINTS ${icu_roots}
+ PATH_SUFFIXES ${icu_binary_suffixes}
+ DOC "ICU ${program} executable"
+ NO_PACKAGE_ROOT_PATH
+ )
+ mark_as_advanced(cache_var)
+ set("${program_var}" "${${cache_var}}" PARENT_SCOPE)
+ endforeach()
+
# Find all ICU libraries
+ list(APPEND icu_library_suffixes "${_lib64}" "lib")
set(ICU_REQUIRED_LIBS_FOUND ON)
+ set(static_prefix )
+ # static icu libraries compiled with MSVC have the prefix 's'
+ if(MSVC)
+ set(static_prefix "s")
+ endif()
foreach(component ${ICU_FIND_COMPONENTS})
string(TOUPPER "${component}" component_upcase)
set(component_cache "ICU_${component_upcase}_LIBRARY")
@@ -197,14 +215,34 @@ function(_ICU_FIND)
list(APPEND component_debug_libnames "icui18nd")
endif()
- find_library("${component_cache_release}" ${component_libnames}
+ if(static_prefix)
+ unset(static_component_libnames)
+ unset(static_component_debug_libnames)
+ foreach(component_libname ${component_libnames})
+ list(APPEND static_component_libnames
+ ${static_prefix}${component_libname})
+ endforeach()
+ foreach(component_libname ${component_debug_libnames})
+ list(APPEND static_component_debug_libnames
+ ${static_prefix}${component_libname})
+ endforeach()
+ list(APPEND component_libnames ${static_component_libnames})
+ list(APPEND component_debug_libnames ${static_component_debug_libnames})
+ endif()
+ find_library("${component_cache_release}"
+ NAMES ${component_libnames}
HINTS ${icu_roots}
PATH_SUFFIXES ${icu_library_suffixes}
- DOC "ICU ${component} library (release)")
- find_library("${component_cache_debug}" ${component_debug_libnames}
+ DOC "ICU ${component} library (release)"
+ NO_PACKAGE_ROOT_PATH
+ )
+ find_library("${component_cache_debug}"
+ NAMES ${component_debug_libnames}
HINTS ${icu_roots}
PATH_SUFFIXES ${icu_library_suffixes}
- DOC "ICU ${component} library (debug)")
+ DOC "ICU ${component} library (debug)"
+ NO_PACKAGE_ROOT_PATH
+ )
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(ICU_${component_upcase})
mark_as_advanced("${component_cache_release}" "${component_cache_debug}")
@@ -233,6 +271,33 @@ function(_ICU_FIND)
set(_ICU_REQUIRED_LIBS_FOUND "${ICU_REQUIRED_LIBS_FOUND}" PARENT_SCOPE)
set(ICU_LIBRARY "${ICU_LIBRARY}" PARENT_SCOPE)
+ # Find all ICU data files
+ if(CMAKE_LIBRARY_ARCHITECTURE)
+ list(APPEND icu_data_suffixes
+ "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}"
+ "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu/${ICU_VERSION}"
+ "${_lib64}/${CMAKE_LIBRARY_ARCHITECTURE}/icu"
+ "lib/${CMAKE_LIBRARY_ARCHITECTURE}/icu")
+ endif()
+ list(APPEND icu_data_suffixes
+ "${_lib64}/icu/${ICU_VERSION}"
+ "lib/icu/${ICU_VERSION}"
+ "${_lib64}/icu"
+ "lib/icu")
+ foreach(data ${icu_data})
+ string(TOUPPER "${data}" data_upcase)
+ string(REPLACE "." "_" data_upcase "${data_upcase}")
+ set(cache_var "ICU_${data_upcase}")
+ set(data_var "ICU_${data_upcase}")
+ find_file("${cache_var}"
+ NAMES "${data}"
+ HINTS ${icu_roots}
+ PATH_SUFFIXES ${icu_data_suffixes}
+ DOC "ICU ${data} data file")
+ mark_as_advanced(cache_var)
+ set("${data_var}" "${${cache_var}}" PARENT_SCOPE)
+ endforeach()
+
if(NOT ICU_FIND_QUIETLY)
if(ICU_LIBS_FOUND)
message(STATUS "Found the following ICU libraries:")
@@ -308,6 +373,10 @@ if(ICU_FOUND)
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
IMPORTED_LOCATION_DEBUG "${${_ICU_component_cache_debug}}")
endif()
+ if(CMAKE_DL_LIBS AND _ICU_component STREQUAL "uc")
+ set_target_properties(${_ICU_imported_target} PROPERTIES
+ INTERFACE_LINK_LIBRARIES "${CMAKE_DL_LIBS}")
+ endif()
endif()
endif()
unset(_ICU_component_upcase)
@@ -334,6 +403,15 @@ if(ICU_DEBUG)
unset(program_lib)
endforeach()
+ foreach(data IN LISTS icu_data)
+ string(TOUPPER "${data}" data_upcase)
+ string(REPLACE "." "_" data_upcase "${data_upcase}")
+ set(data_lib "ICU_${data_upcase}")
+ message(STATUS "${data} data: ${${data_lib}}")
+ unset(data_upcase)
+ unset(data_lib)
+ endforeach()
+
foreach(component IN LISTS ICU_FIND_COMPONENTS)
string(TOUPPER "${component}" component_upcase)
set(component_lib "ICU_${component_upcase}_LIBRARIES")
diff --git a/Modules/FindIce.cmake b/Modules/FindIce.cmake
index e0286ee2c..5ce2b42d9 100644
--- a/Modules/FindIce.cmake
+++ b/Modules/FindIce.cmake
@@ -1,135 +1,215 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
-#
-# Imported targets::
-#
-# Ice::<C>
-#
-# Where ``<C>`` is the name of an Ice component, for example
-# ``Ice::Glacier2``.
-#
-# Ice slice 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_SLICE2JS_EXECUTABLE - path to slice2js executable
-# Ice_SLICE2PHP_EXECUTABLE - path to slice2php executable
-# Ice_SLICE2PY_EXECUTABLE - path to slice2py executable
-# Ice_SLICE2RB_EXECUTABLE - path to slice2rb executable
-#
-# Ice programs are reported in::
-#
-# Ice_GLACIER2ROUTER_EXECUTABLE - path to glacier2router executable
-# Ice_ICEBOX_EXECUTABLE - path to icebox executable
-# Ice_ICEBOXADMIN_EXECUTABLE - path to iceboxadmin executable
-# Ice_ICEBOXD_EXECUTABLE - path to iceboxd executable
-# Ice_ICEBOXNET_EXECUTABLE - path to iceboxnet executable
-# Ice_ICEGRIDADMIN_EXECUTABLE - path to icegridadmin executable
-# Ice_ICEGRIDNODE_EXECUTABLE - path to icegridnode executable
-# Ice_ICEGRIDNODED_EXECUTABLE - path to icegridnoded executable
-# Ice_ICEGRIDREGISTRY_EXECUTABLE - path to icegridregistry executable
-# Ice_ICEGRIDREGISTRYD_EXECUTABLE - path to icegridregistryd executable
-# Ice_ICEPATCH2CALC_EXECUTABLE - path to icepatch2calc executable
-# Ice_ICEPATCH2CLIENT_EXECUTABLE - path to icepatch2client executable
-# Ice_ICEPATCH2SERVER_EXECUTABLE - path to icepatch2server executable
-# Ice_ICESERVICEINSTALL_EXECUTABLE - path to iceserviceinstall executable
-# Ice_ICESTORMADMIN_EXECUTABLE - path to icestormadmin executable
-# Ice_ICESTORMMIGRATE_EXECUTABLE - path to icestormmigrate executable
-#
-# Ice db programs (Windows only; standard system versions on all other
-# platforms) are reported in::
-#
-# Ice_DB_ARCHIVE_EXECUTABLE - path to db_archive executable
-# Ice_DB_CHECKPOINT_EXECUTABLE - path to db_checkpoint executable
-# Ice_DB_DEADLOCK_EXECUTABLE - path to db_deadlock executable
-# Ice_DB_DUMP_EXECUTABLE - path to db_dump executable
-# Ice_DB_HOTBACKUP_EXECUTABLE - path to db_hotbackup executable
-# Ice_DB_LOAD_EXECUTABLE - path to db_load executable
-# Ice_DB_LOG_VERIFY_EXECUTABLE - path to db_log_verify executable
-# Ice_DB_PRINTLOG_EXECUTABLE - path to db_printlog executable
-# Ice_DB_RECOVER_EXECUTABLE - path to db_recover executable
-# Ice_DB_STAT_EXECUTABLE - path to db_stat executable
-# Ice_DB_TUNER_EXECUTABLE - path to db_tuner executable
-# Ice_DB_UPGRADE_EXECUTABLE - path to db_upgrade executable
-# Ice_DB_VERIFY_EXECUTABLE - path to db_verify executable
-# Ice_DUMPDB_EXECUTABLE - path to dumpdb executable
-# Ice_TRANSFORMDB_EXECUTABLE - path to transformdb 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 ``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.
+#[=======================================================================[.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``, ``IceDiscovery``, ``IceGrid``,
+``IceLocatorDiscovery``, ``IcePatch``, ``IceSSL``, ``IceStorm``,
+``IceUtil``, ``IceXML``, or ``Slice``.
+
+Ice 3.7 and later also include C++11-specific components:
+``Glacier2++11``, ``Ice++11``, ``IceBox++11``, ``IceDiscovery++11``
+``IceGrid``, ``IceLocatorDiscovery++11``, ``IceSSL++11``,
+``IceStorm++11``
+
+Note that the set of supported components is Ice version-specific.
+
+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
+
+Imported targets::
+
+ Ice::<C>
+
+Where ``<C>`` is the name of an Ice component, for example
+``Ice::Glacier2`` or ``Ice++11``.
+
+Ice slice programs are reported in::
+
+ Ice_SLICE2CONFLUENCE_EXECUTABLE - path to slice2confluence executable
+ 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_SLICE2JS_EXECUTABLE - path to slice2js executable
+ Ice_SLICE2MATLAB_EXECUTABLE - path to slice2matlab executable
+ Ice_SLICE2OBJC_EXECUTABLE - path to slice2objc executable
+ Ice_SLICE2PHP_EXECUTABLE - path to slice2php executable
+ Ice_SLICE2PY_EXECUTABLE - path to slice2py executable
+ Ice_SLICE2RB_EXECUTABLE - path to slice2rb executable
+
+Ice programs are reported in::
+
+ Ice_GLACIER2ROUTER_EXECUTABLE - path to glacier2router executable
+ Ice_ICEBOX_EXECUTABLE - path to icebox executable
+ Ice_ICEBOXXX11_EXECUTABLE - path to icebox++11 executable
+ Ice_ICEBOXADMIN_EXECUTABLE - path to iceboxadmin executable
+ Ice_ICEBOXD_EXECUTABLE - path to iceboxd executable
+ Ice_ICEBOXNET_EXECUTABLE - path to iceboxnet executable
+ Ice_ICEBRIDGE_EXECUTABLE - path to icebridge executable
+ Ice_ICEGRIDADMIN_EXECUTABLE - path to icegridadmin executable
+ Ice_ICEGRIDDB_EXECUTABLE - path to icegriddb executable
+ Ice_ICEGRIDNODE_EXECUTABLE - path to icegridnode executable
+ Ice_ICEGRIDNODED_EXECUTABLE - path to icegridnoded executable
+ Ice_ICEGRIDREGISTRY_EXECUTABLE - path to icegridregistry executable
+ Ice_ICEGRIDREGISTRYD_EXECUTABLE - path to icegridregistryd executable
+ Ice_ICEPATCH2CALC_EXECUTABLE - path to icepatch2calc executable
+ Ice_ICEPATCH2CLIENT_EXECUTABLE - path to icepatch2client executable
+ Ice_ICEPATCH2SERVER_EXECUTABLE - path to icepatch2server executable
+ Ice_ICESERVICEINSTALL_EXECUTABLE - path to iceserviceinstall executable
+ Ice_ICESTORMADMIN_EXECUTABLE - path to icestormadmin executable
+ Ice_ICESTORMDB_EXECUTABLE - path to icestormdb executable
+ Ice_ICESTORMMIGRATE_EXECUTABLE - path to icestormmigrate executable
+
+Ice db programs (Windows only; standard system versions on all other
+platforms) are reported in::
+
+ Ice_DB_ARCHIVE_EXECUTABLE - path to db_archive executable
+ Ice_DB_CHECKPOINT_EXECUTABLE - path to db_checkpoint executable
+ Ice_DB_DEADLOCK_EXECUTABLE - path to db_deadlock executable
+ Ice_DB_DUMP_EXECUTABLE - path to db_dump executable
+ Ice_DB_HOTBACKUP_EXECUTABLE - path to db_hotbackup executable
+ Ice_DB_LOAD_EXECUTABLE - path to db_load executable
+ Ice_DB_LOG_VERIFY_EXECUTABLE - path to db_log_verify executable
+ Ice_DB_PRINTLOG_EXECUTABLE - path to db_printlog executable
+ Ice_DB_RECOVER_EXECUTABLE - path to db_recover executable
+ Ice_DB_STAT_EXECUTABLE - path to db_stat executable
+ Ice_DB_TUNER_EXECUTABLE - path to db_tuner executable
+ Ice_DB_UPGRADE_EXECUTABLE - path to db_upgrade executable
+ Ice_DB_VERIFY_EXECUTABLE - path to db_verify executable
+ Ice_DUMPDB_EXECUTABLE - path to dumpdb executable
+ Ice_TRANSFORMDB_EXECUTABLE - path to transformdb 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 ``ICE_HOME`` may also be used; the
+Ice_HOME variable takes precedence.
+
+.. note::
+ On Windows, Ice 3.7.0 and later provide libraries via the NuGet
+ package manager. Appropriate NuGet packages will be searched for
+ using ``CMAKE_PREFIX_PATH``, or alternatively ``Ice_HOME`` may be
+ set to the location of a specific NuGet package to restrict the
+ search.
+
+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>
+ set(_Ice_db_programs
+ db_archive
+ db_checkpoint
+ db_deadlock
+ db_dump
+ db_hotbackup
+ db_load
+ db_log_verify
+ db_printlog
+ db_recover
+ db_stat
+ db_tuner
+ db_upgrade
+ db_verify
+ dumpdb
+ transformdb)
+
+ set(_Ice_programs
+ glacier2router
+ icebox
+ icebox++11
+ iceboxadmin
+ iceboxd
+ iceboxnet
+ icebridge
+ icegridadmin
+ icegriddb
+ icegridnode
+ icegridnoded
+ icegridregistry
+ icegridregistryd
+ icepatch2calc
+ icepatch2client
+ icepatch2server
+ iceserviceinstall
+ icestormadmin
+ icestormdb
+ icestormmigrate)
+
+ set(_Ice_slice_programs
+ slice2confluence
+ slice2cpp
+ slice2cs
+ slice2freezej
+ slice2freeze
+ slice2html
+ slice2java
+ slice2js
+ slice2matlab
+ slice2objc
+ slice2php
+ slice2py
+ slice2rb)
+
+
# 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.7
+ 3.7.0
3.6
3.6.3
3.6.2
@@ -146,6 +226,14 @@ function(_Ice_FIND)
3.3.1
3.3.0)
+ foreach(ver ${ice_versions})
+ string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\$" two_digit_version_match "${ver}")
+ if(two_digit_version_match)
+ string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\$" "\\1\\2" two_digit_version "${ver}")
+ list(APPEND ice_suffix_versions "${two_digit_version}")
+ endif()
+ endforeach()
+
# 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)
@@ -159,52 +247,79 @@ function(_Ice_FIND)
endif()
endif()
+ set(_bin "bin/Win32")
+ set(_lib "lib/Win32")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_bin "bin/x64")
+ set(_lib "lib/x64")
# 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")
+ unset(vcvers)
+ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
+ if(MSVC_TOOLSET_VERSION GREATER_EQUAL 141)
+ set(vcvers "141;140")
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 100)
+ set(vcvers "${MSVC_TOOLSET_VERSION}")
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 90)
+ set(vcvers "${MSVC_TOOLSET_VERSION}")
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")
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 80)
+ set(vcvers "${MSVC_TOOLSET_VERSION}")
+ set(vcyear "2005")
+ else() # Unknown version
+ set(vcvers Unknown)
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}")
+ if(vcvers)
+ list(APPEND ice_binary_suffixes "build/native/${_bin}/Release" "tools")
+ list(APPEND ice_debug_library_suffixes "build/native/${_lib}/Debug")
+ list(APPEND ice_release_library_suffixes "build/native/${_lib}/Release")
+ foreach(vcver IN LISTS vcvers)
+ # Earlier Ice (3.3) builds don't use vcnnn subdirectories, but are harmless to check.
+ list(APPEND ice_binary_suffixes "bin/vc${vcver}${_x64}" "bin/vc${vcver}")
+ list(APPEND ice_debug_library_suffixes "lib/vc${vcver}${_x64}" "lib/vc${vcver}")
+ list(APPEND ice_release_library_suffixes "lib/vc${vcver}${_x64}" "lib/vc${vcver}")
+ endforeach()
endif()
# Generic 64-bit and 32-bit directories
list(APPEND ice_binary_suffixes "bin${_x64}" "bin")
- list(APPEND ice_library_suffixes "libx32" "${_lib64}" "lib${_x64}" "lib")
+ list(APPEND ice_debug_library_suffixes "libx32" "${_lib64}" "lib${_x64}" "lib")
+ list(APPEND ice_release_library_suffixes "libx32" "${_lib64}" "lib${_x64}" "lib")
+ if(vcvers)
+ list(APPEND ice_include_suffixes "build/native/include")
+ endif()
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)
+ if(vcvers)
+ foreach(ice_version ${ice_versions})
+ foreach(vcver IN LISTS vcvers)
+ list(APPEND ice_nuget_dirs "zeroc.ice.v${vcver}.${ice_version}")
+ list(APPEND freeze_nuget_dirs "zeroc.freeze.v${vcver}.${ice_version}")
+ endforeach()
+ endforeach()
+ find_path(Ice_NUGET_DIR
+ NAMES "tools/slice2cpp.exe"
+ PATH_SUFFIXES ${ice_nuget_dirs}
+ DOC "Ice NuGet directory")
+ if(Ice_NUGET_DIR)
+ list(APPEND ice_roots "${Ice_NUGET_DIR}")
+ endif()
+ find_path(Freeze_NUGET_DIR
+ NAMES "tools/slice2freeze.exe"
+ PATH_SUFFIXES ${freeze_nuget_dirs}
+ DOC "Freeze NuGet directory")
+ if(Freeze_NUGET_DIR)
+ list(APPEND ice_roots "${Freeze_NUGET_DIR}")
+ endif()
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
@@ -239,55 +354,8 @@ function(_Ice_FIND)
endforeach()
endif()
- set(db_programs
- db_archive
- db_checkpoint
- db_deadlock
- db_dump
- db_hotbackup
- db_load
- db_log_verify
- db_printlog
- db_recover
- db_stat
- db_tuner
- db_upgrade
- db_verify
- dumpdb
- transformdb)
-
- set(ice_programs
- glacier2router
- icebox
- iceboxadmin
- iceboxd
- iceboxnet
- icegridadmin
- icegridnode
- icegridnoded
- icegridregistry
- icegridregistryd
- icepatch2calc
- icepatch2client
- icepatch2server
- iceserviceinstall
- icestormadmin
- icestormmigrate)
-
- set(slice_programs
- slice2cpp
- slice2cs
- slice2freezej
- slice2freeze
- slice2html
- slice2java
- slice2js
- slice2php
- slice2py
- slice2rb)
-
# Find all Ice programs
- foreach(program ${db_programs} ${ice_programs} ${slice_programs})
+ foreach(program ${_Ice_db_programs} ${_Ice_programs} ${_Ice_slice_programs})
string(TOUPPER "${program}" program_upcase)
set(cache_var "Ice_${program_upcase}_EXECUTABLE")
set(program_var "Ice_${program_upcase}_EXECUTABLE")
@@ -329,6 +397,13 @@ function(_Ice_FIND)
DOC "Ice include directory")
set(Ice_INCLUDE_DIR "${Ice_INCLUDE_DIR}" PARENT_SCOPE)
+ find_path(Freeze_INCLUDE_DIR
+ NAMES "Freeze/Freeze.h"
+ HINTS ${ice_roots}
+ PATH_SUFFIXES ${ice_include_suffixes}
+ DOC "Freeze include directory")
+ set(Freeze_INCLUDE_DIR "${Freeze_INCLUDE_DIR}" PARENT_SCOPE)
+
# In common use on Linux, MacOS X (homebrew) and FreeBSD; prefer
# version-specific dir
list(APPEND ice_slice_paths
@@ -336,6 +411,7 @@ function(_Ice_FIND)
list(APPEND ice_slice_suffixes
"Ice-${Ice_VERSION_SLICE2CPP_FULL}/slice"
"Ice-${Ice_VERSION_SLICE2CPP_SHORT}/slice"
+ "ice/slice"
Ice)
# Find slice directory
@@ -356,13 +432,39 @@ function(_Ice_FIND)
set(component_cache_release "${component_cache}_RELEASE")
set(component_cache_debug "${component_cache}_DEBUG")
set(component_found "${component_upcase}_FOUND")
- find_library("${component_cache_release}" "${component}"
+ set(component_library "${component}")
+ unset(component_library_release_names)
+ unset(component_library_debug_names)
+ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
+ string(REGEX MATCH ".+\\+\\+11$" component_library_cpp11 "${component_library}")
+ if(component_library_cpp11)
+ string(REGEX REPLACE "^(.+)(\\+\\+11)$" "\\1" component_library "${component_library}")
+ endif()
+ foreach(suffix_ver ${ice_suffix_versions})
+ set(_name "${component_library}${suffix_ver}")
+ if(component_library_cpp11)
+ string(APPEND _name "++11")
+ endif()
+ list(APPEND component_library_debug_names "${_name}d")
+ list(APPEND component_library_release_names "${_name}")
+ endforeach()
+ set(_name "${component_library}")
+ if(component_library_cpp11)
+ string(APPEND _name "++11")
+ endif()
+ list(APPEND component_library_debug_names "${_name}d")
+ list(APPEND component_library_release_names "${_name}")
+ else()
+ list(APPEND component_library_debug_names "${component_library}d")
+ list(APPEND component_library_release_names "${component_library}")
+ endif()
+ find_library("${component_cache_release}" ${component_library_release_names}
HINTS ${ice_roots}
- PATH_SUFFIXES ${ice_library_suffixes}
+ PATH_SUFFIXES ${ice_release_library_suffixes}
DOC "Ice ${component} library (release)")
- find_library("${component_cache_debug}" "${component}d"
+ find_library("${component_cache_debug}" ${component_library_debug_names}
HINTS ${ice_roots}
- PATH_SUFFIXES ${ice_library_suffixes}
+ PATH_SUFFIXES ${ice_debug_library_suffixes}
DOC "Ice ${component} library (debug)")
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(Ice_${component_upcase})
@@ -410,9 +512,14 @@ function(_Ice_FIND)
if(Ice_DEBUG)
message(STATUS "--------FindIce.cmake search debug--------")
message(STATUS "ICE binary path search order: ${ice_roots}")
+ message(STATUS "ICE binary suffixes: ${ice_binary_suffixes}")
message(STATUS "ICE include path search order: ${ice_roots}")
+ message(STATUS "ICE include suffixes: ${ice_include_suffixes}")
message(STATUS "ICE slice path search order: ${ice_roots} ${ice_slice_paths}")
+ message(STATUS "ICE slice suffixes: ${ice_slice_suffixes}")
message(STATUS "ICE library path search order: ${ice_roots}")
+ message(STATUS "ICE debug library suffixes: ${ice_debug_library_suffixes}")
+ message(STATUS "ICE release library suffixes: ${ice_release_library_suffixes}")
message(STATUS "----------------")
endif()
endfunction()
@@ -434,6 +541,9 @@ unset(_Ice_REQUIRED_LIBS_FOUND)
if(Ice_FOUND)
set(Ice_INCLUDE_DIRS "${Ice_INCLUDE_DIR}")
+ if (Freeze_INCLUDE_DIR)
+ list(APPEND Ice_INCLUDE_DIRS "${Freeze_INCLUDE_DIR}")
+ endif()
set(Ice_SLICE_DIRS "${Ice_SLICE_DIR}")
set(Ice_LIBRARIES "${Ice_LIBRARY}")
foreach(_Ice_component ${Ice_FIND_COMPONENTS})
@@ -448,10 +558,8 @@ if(Ice_FOUND)
set("${_Ice_component_lib}" "${${_Ice_component_cache}}")
if(NOT TARGET ${_Ice_imported_target})
add_library(${_Ice_imported_target} UNKNOWN IMPORTED)
- if()
- set_target_properties(${_Ice_imported_target} PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${Ice_INCLUDE_DIR}")
- endif()
+ set_target_properties(${_Ice_imported_target} PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${Ice_INCLUDE_DIRS}")
if(EXISTS "${${_Ice_component_cache}}")
set_target_properties(${_Ice_imported_target} PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
@@ -488,50 +596,13 @@ if(Ice_DEBUG)
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 "Freeze_INCLUDE_DIR directory: ${Freeze_INCLUDE_DIR}")
+ message(STATUS "Ice_INCLUDE_DIRS directory: ${Ice_INCLUDE_DIRS}")
- 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 "slice2js executable: ${Ice_SLICE2JS_EXECUTABLE}")
- message(STATUS "slice2php executable: ${Ice_SLICE2PHP_EXECUTABLE}")
- message(STATUS "slice2py executable: ${Ice_SLICE2PY_EXECUTABLE}")
- message(STATUS "slice2rb executable: ${Ice_SLICE2RB_EXECUTABLE}")
- message(STATUS "glacier2router executable: ${Ice_GLACIER2ROUTER_EXECUTABLE}")
-
- message(STATUS "icebox executable: ${Ice_ICEBOX_EXECUTABLE}")
- message(STATUS "iceboxadmin executable: ${Ice_ICEBOXADMIN_EXECUTABLE}")
- message(STATUS "iceboxd executable: ${Ice_ICEBOXD_EXECUTABLE}")
- message(STATUS "iceboxnet executable: ${Ice_ICEBOXNET_EXECUTABLE}")
- message(STATUS "icegridadmin executable: ${Ice_ICEGRIDADMIN_EXECUTABLE}")
- message(STATUS "icegridnode executable: ${Ice_ICEGRIDNODE_EXECUTABLE}")
- message(STATUS "icegridnoded executable: ${Ice_ICEGRIDNODED_EXECUTABLE}")
- message(STATUS "icegridregistry executable: ${Ice_ICEGRIDREGISTRY_EXECUTABLE}")
- message(STATUS "icegridregistryd executable: ${Ice_ICEGRIDREGISTRYD_EXECUTABLE}")
- message(STATUS "icepatch2calc executable: ${Ice_ICEPATCH2CALC_EXECUTABLE}")
- message(STATUS "icepatch2client executable: ${Ice_ICEPATCH2CLIENT_EXECUTABLE}")
- message(STATUS "icepatch2server executable: ${Ice_ICEPATCH2SERVER_EXECUTABLE}")
- message(STATUS "iceserviceinstall executable: ${Ice_ICESERVICEINSTALL_EXECUTABLE}")
- message(STATUS "icestormadmin executable: ${Ice_ICESTORMADMIN_EXECUTABLE}")
- message(STATUS "icestormmigrate executable: ${Ice_ICESTORMMIGRATE_EXECUTABLE}")
-
- message(STATUS "db_archive executable: ${Ice_DB_ARCHIVE_EXECUTABLE}")
- message(STATUS "db_checkpoint executable: ${Ice_DB_CHECKPOINT_EXECUTABLE}")
- message(STATUS "db_deadlock executable: ${Ice_DB_DEADLOCK_EXECUTABLE}")
- message(STATUS "db_dump executable: ${Ice_DB_DUMP_EXECUTABLE}")
- message(STATUS "db_hotbackup executable: ${Ice_DB_HOTBACKUP_EXECUTABLE}")
- message(STATUS "db_load executable: ${Ice_DB_LOAD_EXECUTABLE}")
- message(STATUS "db_log_verify executable: ${Ice_DB_LOG_VERIFY_EXECUTABLE}")
- message(STATUS "db_printlog executable: ${Ice_DB_PRINTLOG_EXECUTABLE}")
- message(STATUS "db_recover executable: ${Ice_DB_RECOVER_EXECUTABLE}")
- message(STATUS "db_stat executable: ${Ice_DB_STAT_EXECUTABLE}")
- message(STATUS "db_tuner executable: ${Ice_DB_TUNER_EXECUTABLE}")
- message(STATUS "db_upgrade executable: ${Ice_DB_UPGRADE_EXECUTABLE}")
- message(STATUS "db_verify executable: ${Ice_DB_VERIFY_EXECUTABLE}")
- message(STATUS "dumpdb executable: ${Ice_DUMPDB_EXECUTABLE}")
- message(STATUS "transformdb executable: ${Ice_TRANSFORMDB_EXECUTABLE}")
+ foreach(program ${_Ice_db_programs} ${_Ice_programs} ${_Ice_slice_programs})
+ string(TOUPPER "${program}" program_upcase)
+ message(STATUS "${program} executable: ${Ice_${program_upcase}_EXECUTABLE}")
+ endforeach()
foreach(component ${Ice_FIND_COMPONENTS})
string(TOUPPER "${component}" component_upcase)
@@ -542,3 +613,7 @@ if(Ice_DEBUG)
endforeach()
message(STATUS "----------------")
endif()
+
+unset(_Ice_db_programs)
+unset(_Ice_programs)
+unset(_Ice_slice_programs)
diff --git a/Modules/FindIcotool.cmake b/Modules/FindIcotool.cmake
index 26e95a0fa..d19c14579 100644
--- a/Modules/FindIcotool.cmake
+++ b/Modules/FindIcotool.cmake
@@ -1,20 +1,21 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindIcotool
+-----------
+
+Find icotool
+
+This module looks for icotool. Convert and create Win32 icon and cursor files.
+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.
+#]=======================================================================]
find_program(ICOTOOL_EXECUTABLE
icotool
diff --git a/Modules/FindImageMagick.cmake b/Modules/FindImageMagick.cmake
index 7d5534bc2..8bf5123b7 100644
--- a/Modules/FindImageMagick.cmake
+++ b/Modules/FindImageMagick.cmake
@@ -1,87 +1,88 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.).
+#[=======================================================================[.rst:
+FindImageMagick
+---------------
+
+Find ImageMagick binary suite.
+
+This module will search for a set of ImageMagick tools specified as
+components in the :command:`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 :command:`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 :command:`find_package` features are supported (i.e.,
+``QUIET``, ``REQUIRED``, etc.).
+#]=======================================================================]
find_package(PkgConfig QUIET)
@@ -104,6 +105,7 @@ function(FIND_IMAGEMAGICK_API component header)
PATH_SUFFIXES
ImageMagick ImageMagick-6 ImageMagick-7
DOC "Path to the ImageMagick arch-independent include dir."
+ NO_DEFAULT_PATH
)
find_path(ImageMagick_${component}_ARCH_INCLUDE_DIR
NAMES magick/magick-baseconfig.h
@@ -116,6 +118,7 @@ function(FIND_IMAGEMAGICK_API component header)
PATH_SUFFIXES
ImageMagick ImageMagick-6 ImageMagick-7
DOC "Path to the ImageMagick arch-specific include dir."
+ NO_DEFAULT_PATH
)
find_library(ImageMagick_${component}_LIBRARY
NAMES ${ARGN}
@@ -125,6 +128,7 @@ function(FIND_IMAGEMAGICK_API component header)
PATHS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\ImageMagick\\Current;BinPath]/lib"
DOC "Path to the ImageMagick Magick++ library."
+ NO_DEFAULT_PATH
)
# old version have only indep dir
@@ -196,24 +200,33 @@ foreach(component ${ImageMagick_FIND_COMPONENTS}
if(component STREQUAL "Magick++")
FIND_IMAGEMAGICK_API(Magick++ Magick++.h
Magick++ CORE_RL_Magick++_
+ Magick++-6 Magick++-7
Magick++-Q8 Magick++-Q16 Magick++-Q16HDRI Magick++-Q8HDRI
+ Magick++-6.Q64 Magick++-6.Q32 Magick++-6.Q64HDRI Magick++-6.Q32HDRI
Magick++-6.Q16 Magick++-6.Q8 Magick++-6.Q16HDRI Magick++-6.Q8HDRI
+ Magick++-7.Q64 Magick++-7.Q32 Magick++-7.Q64HDRI Magick++-7.Q32HDRI
Magick++-7.Q16 Magick++-7.Q8 Magick++-7.Q16HDRI Magick++-7.Q8HDRI
)
list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_Magick++_LIBRARY)
elseif(component STREQUAL "MagickWand")
FIND_IMAGEMAGICK_API(MagickWand "wand/MagickWand.h;MagickWand/MagickWand.h"
- Wand MagickWand CORE_RL_wand_
+ Wand MagickWand CORE_RL_wand_ CORE_RL_MagickWand_
+ MagickWand-6 MagickWand-7
MagickWand-Q16 MagickWand-Q8 MagickWand-Q16HDRI MagickWand-Q8HDRI
+ MagickWand-6.Q64 MagickWand-6.Q32 MagickWand-6.Q64HDRI MagickWand-6.Q32HDRI
MagickWand-6.Q16 MagickWand-6.Q8 MagickWand-6.Q16HDRI MagickWand-6.Q8HDRI
+ MagickWand-7.Q64 MagickWand-7.Q32 MagickWand-7.Q64HDRI MagickWand-7.Q32HDRI
MagickWand-7.Q16 MagickWand-7.Q8 MagickWand-7.Q16HDRI MagickWand-7.Q8HDRI
)
list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickWand_LIBRARY)
elseif(component STREQUAL "MagickCore")
FIND_IMAGEMAGICK_API(MagickCore "magick/MagickCore.h;MagickCore/MagickCore.h"
- Magick MagickCore CORE_RL_magick_
+ Magick MagickCore CORE_RL_magick_ CORE_RL_MagickCore_
+ MagickCore-6 MagickCore-7
MagickCore-Q16 MagickCore-Q8 MagickCore-Q16HDRI MagickCore-Q8HDRI
+ MagickCore-6.Q64 MagickCore-6.Q32 MagickCore-6.Q64HDRI MagickCore-6.Q32HDRI
MagickCore-6.Q16 MagickCore-6.Q8 MagickCore-6.Q16HDRI MagickCore-6.Q8HDRI
+ MagickCore-7.Q64 MagickCore-7.Q32 MagickCore-7.Q64HDRI MagickCore-7.Q32HDRI
MagickCore-7.Q16 MagickCore-7.Q8 MagickCore-7.Q16HDRI MagickCore-7.Q8HDRI
)
list(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickCore_LIBRARY)
diff --git a/Modules/FindIntl.cmake b/Modules/FindIntl.cmake
index f887721d6..3818d45ec 100644
--- a/Modules/FindIntl.cmake
+++ b/Modules/FindIntl.cmake
@@ -1,33 +1,34 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindIntl
-# --------
-#
-# Find the Gettext libintl headers and libraries.
-#
-# This module reports information about the Gettext libintl
-# installation in several variables. General variables::
-#
-# Intl_FOUND - true if the libintl headers and libraries were found
-# Intl_INCLUDE_DIRS - the directory containing the libintl headers
-# Intl_LIBRARIES - libintl libraries to be linked
-#
-# The following cache variables may also be set::
-#
-# Intl_INCLUDE_DIR - the directory containing the libintl headers
-# Intl_LIBRARY - the libintl library (if any)
-#
-# .. note::
-# On some platforms, such as Linux with GNU libc, the gettext
-# functions are present in the C standard library and libintl
-# is not required. ``Intl_LIBRARIES`` will be empty in this
-# case.
-#
-# .. note::
-# If you wish to use the Gettext tools (``msgmerge``,
-# ``msgfmt``, etc.), use :module:`FindGettext`.
+#[=======================================================================[.rst:
+FindIntl
+--------
+
+Find the Gettext libintl headers and libraries.
+
+This module reports information about the Gettext libintl
+installation in several variables. General variables::
+
+ Intl_FOUND - true if the libintl headers and libraries were found
+ Intl_INCLUDE_DIRS - the directory containing the libintl headers
+ Intl_LIBRARIES - libintl libraries to be linked
+
+The following cache variables may also be set::
+
+ Intl_INCLUDE_DIR - the directory containing the libintl headers
+ Intl_LIBRARY - the libintl library (if any)
+
+.. note::
+ On some platforms, such as Linux with GNU libc, the gettext
+ functions are present in the C standard library and libintl
+ is not required. ``Intl_LIBRARIES`` will be empty in this
+ case.
+
+.. note::
+ If you wish to use the Gettext tools (``msgmerge``,
+ ``msgfmt``, etc.), use :module:`FindGettext`.
+#]=======================================================================]
# Written by Roger Leigh <rleigh@codelibre.net>
diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake
index cebba10f0..237ea96dc 100644
--- a/Modules/FindJNI.cmake
+++ b/Modules/FindJNI.cmake
@@ -1,31 +1,51 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
-
-# Expand {libarch} occurences to java_libarch subdirectory(-ies) and set ${_var}
+#[=======================================================================[.rst:
+FindJNI
+-------
+
+Find Java Native Interface (JNI) libraries.
+
+JNI enables Java code running in a Java Virtual Machine (JVM) to call
+and be called by native applications and libraries written in other
+languages such as C, C++.
+
+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.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module sets the following result variables:
+
+``JNI_INCLUDE_DIRS``
+ the include dirs to use
+``JNI_LIBRARIES``
+ the libraries to use (JAWT and JVM)
+``JNI_FOUND``
+ TRUE if JNI headers and libraries were found.
+
+Cache Variables
+^^^^^^^^^^^^^^^
+
+The following cache variables are also available to set or use:
+
+``JAVA_AWT_LIBRARY``
+ the path to the Java AWT Native Interface (JAWT) library
+``JAVA_JVM_LIBRARY``
+ the path to the Java Virtual Machine (JVM) library
+``JAVA_INCLUDE_PATH``
+ the include path to jni.h
+``JAVA_INCLUDE_PATH2``
+ the include path to jni_md.h and jniport.h
+``JAVA_AWT_INCLUDE_PATH``
+ the include path to jawt.h
+#]=======================================================================]
+
+# Expand {libarch} occurrences 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
@@ -46,8 +66,11 @@ macro(java_append_library_directories _var)
set(_java_libarch "arm" "aarch32")
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" "mips64" "mips64el" "mipsn32" "mipsn32el")
+ # endianness of the underlying system.
+ set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}"
+ "mips" "mipsel" "mipseb" "mipsr6" "mipsr6el"
+ "mips64" "mips64el" "mips64r6" "mips64r6el"
+ "mipsn32" "mipsn32el" "mipsn32r6" "mipsn32r6el")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
set(_java_libarch "ppc64" "ppc64le")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
@@ -117,49 +140,102 @@ if(_JAVA_HOME)
${_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
+if (WIN32)
+ set (_JNI_HINTS)
+ execute_process(COMMAND REG QUERY HKLM\\SOFTWARE\\JavaSoft\\JDK /f "." /k
+ RESULT_VARIABLE _JNI_RESULT
+ OUTPUT_VARIABLE _JNI_VERSIONS
+ ERROR_QUIET)
+ if (NOT _JNI_RESULT)
+ string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\JDK\\\\[0-9.]+" _JNI_VERSIONS "${_JNI_VERSIONS}")
+ if (_JNI_VERSIONS)
+ # sort versions. Most recent first
+ ## handle version 9 apart from other versions to get correct ordering
+ set (_JNI_V9 ${_JNI_VERSIONS})
+ list (FILTER _JNI_VERSIONS EXCLUDE REGEX "JDK\\\\9")
+ list (SORT _JNI_VERSIONS)
+ list (REVERSE _JNI_VERSIONS)
+ list (FILTER _JNI_V9 INCLUDE REGEX "JDK\\\\9")
+ list (SORT _JNI_V9)
+ list (REVERSE _JNI_V9)
+ list (APPEND _JNI_VERSIONS ${_JNI_V9})
+ foreach (_JNI_HINT IN LISTS _JNI_VERSIONS)
+ list(APPEND _JNI_HINTS "[${_JNI_HINT};JavaHome]")
+ endforeach()
+ endif()
+ endif()
+
+ foreach (_JNI_HINT IN LISTS _JNI_HINTS)
+ list(APPEND JAVA_AWT_LIBRARY_DIRECTORIES "${_JNI_HINT}/lib")
+ endforeach()
+
+ 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.9;JavaHome]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/lib"
+ "[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"
+ )
+endif()
+
+set(_JNI_JAVA_DIRECTORIES_BASE
+ /usr/lib/jvm/java
+ /usr/lib/java
+ /usr/lib/jvm
+ /usr/local/lib/java
+ /usr/local/share/java
+ /usr/lib/j2sdk1.4-sun
+ /usr/lib/j2sdk1.5-sun
+ /opt/sun-jdk-1.5.0.04
+ /usr/lib/jvm/java-6-sun
+ /usr/lib/jvm/java-1.5.0-sun
+ /usr/lib/jvm/java-6-sun-1.6.0.00 # can this one be removed according to #8821 ? Alex
+ /usr/lib/jvm/java-6-openjdk
+ /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0 # 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
+ /usr/lib/jvm/default-java
# Arch Linux specific paths for default JVM
- /usr/lib/jvm/default/jre/lib/{libarch}
- /usr/lib/jvm/default/lib/{libarch}
+ /usr/lib/jvm/default
# Ubuntu specific paths for default JVM
- /usr/lib/jvm/java-8-openjdk-{libarch}/jre/lib/{libarch} # Ubuntu 15.10
- /usr/lib/jvm/java-7-openjdk-{libarch}/jre/lib/{libarch} # Ubuntu 15.10
- /usr/lib/jvm/java-6-openjdk-{libarch}/jre/lib/{libarch} # Ubuntu 15.10
+ /usr/lib/jvm/java-11-openjdk-{libarch} # Ubuntu 18.04 LTS
+ /usr/lib/jvm/java-8-openjdk-{libarch} # Ubuntu 15.10
+ /usr/lib/jvm/java-7-openjdk-{libarch} # Ubuntu 15.10
+ /usr/lib/jvm/java-6-openjdk-{libarch} # Ubuntu 15.10
# 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}
+ /usr/local/jdk-1.7.0
+ /usr/local/jre-1.7.0
+ /usr/local/jdk-1.6.0
+ /usr/local/jre-1.6.0
# SuSE specific paths for default JVM
- /usr/lib64/jvm/java/jre/lib/{libarch}
- /usr/lib64/jvm/jre/lib/{libarch}
+ /usr/lib64/jvm/java
+ /usr/lib64/jvm/jre
+ )
+
+set(_JNI_JAVA_AWT_LIBRARY_TRIES)
+set(_JNI_JAVA_INCLUDE_TRIES)
+
+foreach(_java_dir IN LISTS _JNI_JAVA_DIRECTORIES_BASE)
+ list(APPEND _JNI_JAVA_AWT_LIBRARY_TRIES
+ ${_java_dir}/jre/lib/{libarch}
+ ${_java_dir}/jre/lib
+ ${_java_dir}/lib/{libarch}
+ ${_java_dir}/lib
+ ${_java_dir}
+ )
+ list(APPEND _JNI_JAVA_INCLUDE_TRIES
+ ${_java_dir}/include
+ )
+endforeach()
+
+JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
+ ${_JNI_JAVA_AWT_LIBRARY_TRIES}
)
set(JAVA_JVM_LIBRARY_DIRECTORIES)
@@ -178,38 +254,24 @@ 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"
-)
+if (WIN32)
+ foreach (_JNI_HINT IN LISTS _JNI_HINTS)
+ list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES "${_JNI_HINT}/include")
+ endforeach()
+ list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.9;JavaHome]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.8;JavaHome]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.7;JavaHome]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.6;JavaHome]/include"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.5;JavaHome]/include"
+ "[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"
+ )
+endif()
JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_INCLUDE_DIRECTORIES
- /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/lib/jvm/java-8-openjdk-{libarch}/include # ubuntu 15.10
- /usr/lib/jvm/java-7-openjdk-{libarch}/include # ubuntu 15.10
- /usr/lib/jvm/java-6-openjdk-{libarch}/include # ubuntu 15.10
- /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
- # Arch specific path for default JVM
- /usr/lib/jvm/default/include
- # OpenBSD specific path for default JVM
- /usr/local/jdk-1.7.0/include
- /usr/local/jdk-1.6.0/include
- # SuSE specific paths for default JVM
- /usr/lib64/jvm/java/include
+ ${_JNI_JAVA_INCLUDE_TRIES}
)
foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
@@ -331,4 +393,3 @@ set(JNI_INCLUDE_DIRS
${JAVA_INCLUDE_PATH2}
${JAVA_AWT_INCLUDE_PATH}
)
-
diff --git a/Modules/FindJPEG.cmake b/Modules/FindJPEG.cmake
index e233714e0..0bb698979 100644
--- a/Modules/FindJPEG.cmake
+++ b/Modules/FindJPEG.cmake
@@ -1,42 +1,136 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindJPEG
+--------
+
+Find the Joint Photographic Experts Group (JPEG) library (``libjpeg``)
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``JPEG::JPEG``
+ The JPEG library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``JPEG_FOUND``
+ If false, do not try to use JPEG.
+``JPEG_INCLUDE_DIRS``
+ where to find jpeglib.h, etc.
+``JPEG_LIBRARIES``
+ the libraries needed to use JPEG.
+``JPEG_VERSION``
+ the version of the JPEG library found
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``JPEG_INCLUDE_DIRS``
+ where to find jpeglib.h, etc.
+``JPEG_LIBRARY_RELEASE``
+ where to find the JPEG library (optimized).
+``JPEG_LIBRARY_DEBUG``
+ where to find the JPEG library (debug).
+
+Obsolete variables
+^^^^^^^^^^^^^^^^^^
+
+``JPEG_INCLUDE_DIR``
+ where to find jpeglib.h, etc. (same as JPEG_INCLUDE_DIRS)
+``JPEG_LIBRARY``
+ where to find the JPEG library.
+#]=======================================================================]
find_path(JPEG_INCLUDE_DIR jpeglib.h)
-set(JPEG_NAMES ${JPEG_NAMES} jpeg libjpeg)
-find_library(JPEG_LIBRARY NAMES ${JPEG_NAMES} )
+set(jpeg_names ${JPEG_NAMES} jpeg jpeg-static libjpeg libjpeg-static)
+foreach(name ${jpeg_names})
+ list(APPEND jpeg_names_debug "${name}d")
+endforeach()
+
+if(NOT JPEG_LIBRARY)
+ find_library(JPEG_LIBRARY_RELEASE NAMES ${jpeg_names})
+ find_library(JPEG_LIBRARY_DEBUG NAMES ${jpeg_names_debug})
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+ select_library_configurations(JPEG)
+ mark_as_advanced(JPEG_LIBRARY_RELEASE JPEG_LIBRARY_DEBUG)
+endif()
+unset(jpeg_names)
+unset(jpeg_names_debug)
+
+if(JPEG_INCLUDE_DIR)
+ file(GLOB _JPEG_CONFIG_HEADERS_FEDORA "${JPEG_INCLUDE_DIR}/jconfig*.h")
+ file(GLOB _JPEG_CONFIG_HEADERS_DEBIAN "${JPEG_INCLUDE_DIR}/*/jconfig.h")
+ set(_JPEG_CONFIG_HEADERS
+ "${JPEG_INCLUDE_DIR}/jpeglib.h"
+ ${_JPEG_CONFIG_HEADERS_FEDORA}
+ ${_JPEG_CONFIG_HEADERS_DEBIAN})
+ foreach (_JPEG_CONFIG_HEADER IN LISTS _JPEG_CONFIG_HEADERS)
+ if (NOT EXISTS "${_JPEG_CONFIG_HEADER}")
+ continue ()
+ endif ()
+ file(STRINGS "${_JPEG_CONFIG_HEADER}"
+ jpeg_lib_version REGEX "^#define[\t ]+JPEG_LIB_VERSION[\t ]+.*")
+
+ if (NOT jpeg_lib_version)
+ continue ()
+ endif ()
+
+ string(REGEX REPLACE "^#define[\t ]+JPEG_LIB_VERSION[\t ]+([0-9]+).*"
+ "\\1" JPEG_VERSION "${jpeg_lib_version}")
+ break ()
+ endforeach ()
+ unset(jpeg_lib_version)
+ unset(_JPEG_CONFIG_HEADER)
+ unset(_JPEG_CONFIG_HEADERS)
+ unset(_JPEG_CONFIG_HEADERS_FEDORA)
+ unset(_JPEG_CONFIG_HEADERS_DEBIAN)
+endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(JPEG DEFAULT_MSG JPEG_LIBRARY JPEG_INCLUDE_DIR)
+find_package_handle_standard_args(JPEG
+ REQUIRED_VARS JPEG_LIBRARY JPEG_INCLUDE_DIR
+ VERSION_VAR JPEG_VERSION)
if(JPEG_FOUND)
set(JPEG_LIBRARIES ${JPEG_LIBRARY})
-endif()
+ set(JPEG_INCLUDE_DIRS "${JPEG_INCLUDE_DIR}")
-# Deprecated declarations.
-set (NATIVE_JPEG_INCLUDE_PATH ${JPEG_INCLUDE_DIR} )
-if(JPEG_LIBRARY)
- get_filename_component (NATIVE_JPEG_LIB_PATH ${JPEG_LIBRARY} PATH)
+ if(NOT TARGET JPEG::JPEG)
+ add_library(JPEG::JPEG UNKNOWN IMPORTED)
+ if(JPEG_INCLUDE_DIRS)
+ set_target_properties(JPEG::JPEG PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${JPEG_INCLUDE_DIRS}")
+ endif()
+ if(EXISTS "${JPEG_LIBRARY}")
+ set_target_properties(JPEG::JPEG PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+ IMPORTED_LOCATION "${JPEG_LIBRARY}")
+ endif()
+ if(EXISTS "${JPEG_LIBRARY_RELEASE}")
+ set_property(TARGET JPEG::JPEG APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties(JPEG::JPEG PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
+ IMPORTED_LOCATION_RELEASE "${JPEG_LIBRARY_RELEASE}")
+ endif()
+ if(EXISTS "${JPEG_LIBRARY_DEBUG}")
+ set_property(TARGET JPEG::JPEG APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties(JPEG::JPEG PROPERTIES
+ IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
+ IMPORTED_LOCATION_DEBUG "${JPEG_LIBRARY_DEBUG}")
+ endif()
+ endif()
endif()
-mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR )
+mark_as_advanced(JPEG_LIBRARY JPEG_INCLUDE_DIR)
diff --git a/Modules/FindJasper.cmake b/Modules/FindJasper.cmake
index db766576b..729a50350 100644
--- a/Modules/FindJasper.cmake
+++ b/Modules/FindJasper.cmake
@@ -1,20 +1,21 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.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)
+#]=======================================================================]
find_path(JASPER_INCLUDE_DIR jasper/jasper.h)
@@ -40,7 +41,7 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Jasper
VERSION_VAR JASPER_VERSION_STRING)
if (JASPER_FOUND)
- set(JASPER_LIBRARIES ${JASPER_LIBRARIES} ${JPEG_LIBRARIES} )
+ set(JASPER_LIBRARIES ${JASPER_LIBRARIES} ${JPEG_LIBRARIES} )
endif ()
mark_as_advanced(JASPER_INCLUDE_DIR)
diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake
index eb2242bf5..0d62cd669 100644
--- a/Modules/FindJava.cmake
+++ b/Modules/FindJava.cmake
@@ -1,74 +1,80 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-#
-# See also the :module:`FindJNI` module to find Java development tools.
-#
-# Specify one or more of the following components as you call this find module. See example below.
-#
-# ::
-#
-# Runtime = User just want to execute some Java byte-compiled
-# Development = Development tools (java, javac, javah and javadoc), includes Runtime component
-# IdlJ = idl compiler for Java
-# JarSigner = signer tool for jar
-#
-#
-# 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 documentation generator
-# Java_IDLJ_EXECUTABLE = the full path to the Java idl compiler
-# Java_JAR_EXECUTABLE = the full path to the Java archiver
-# Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer
-# Java_VERSION_STRING = Version of java found, 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_<component>_FOUND - TRUE if <component> is found.
-#
-#
-#
-# Example Usages:
-#
-# ::
-#
-# find_package(Java)
-# find_package(Java COMPONENTS Runtime)
-# find_package(Java COMPONENTS Development)
+#[=======================================================================[.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.
+
+See also the :module:`FindJNI` module to find Java Native Interface (JNI).
+
+Specify one or more of the following components as you call this find module. See example below.
+
+::
+
+ Runtime = Java Runtime Environment used to execute Java byte-compiled applications
+ Development = Development tools (java, javac, javah, jar and javadoc), includes Runtime component
+ IdlJ = Interface Description Language (IDL) to Java compiler
+ JarSigner = Signer and verifier tool for Java Archive (JAR) files
+
+
+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 documentation generator
+ Java_IDLJ_EXECUTABLE = the full path to the Java idl compiler
+ Java_JAR_EXECUTABLE = the full path to the Java archiver
+ Java_JARSIGNER_EXECUTABLE = the full path to the Java jar signer
+ Java_VERSION_STRING = Version of java found, 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
+:command:`find_package` syntax, e.g.
+
+.. code-block:: cmake
+
+ find_package(Java 1.8)
+
+NOTE: ``${Java_VERSION}`` and ``${Java_VERSION_STRING}`` are not guaranteed to
+be identical. For example some java version may return:
+``Java_VERSION_STRING = 1.8.0_17`` and ``Java_VERSION = 1.8.0.17``
+
+another example is the Java OEM, with: ``Java_VERSION_STRING = 1.8.0-oem``
+and ``Java_VERSION = 1.8.0``
+
+For these components the following variables are set:
+
+::
+
+ Java_FOUND - TRUE if all components are found.
+ Java_<component>_FOUND - TRUE if <component> is found.
+
+
+
+Example Usages:
+
+::
+
+ find_package(Java)
+ find_package(Java 1.8 REQUIRED)
+ find_package(Java COMPONENTS Runtime)
+ find_package(Java COMPONENTS Development)
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)
@@ -77,8 +83,37 @@ 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"
+if (WIN32)
+ macro (_JAVA_GET_INSTALLED_VERSIONS _KIND)
+ execute_process(COMMAND REG QUERY HKLM\\SOFTWARE\\JavaSoft\\${_KIND} /f "." /k
+ RESULT_VARIABLE _JAVA_RESULT
+ OUTPUT_VARIABLE _JAVA_VERSIONS
+ ERROR_QUIET)
+ if (NOT _JAVA_RESULT)
+ string (REGEX MATCHALL "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\JavaSoft\\\\${_KIND}\\\\[0-9.]+" _JAVA_VERSIONS "${_JAVA_VERSIONS}")
+ if (_JAVA_VERSIONS)
+ # sort versions. Most recent first
+ ## handle version 9 apart from other versions to get correct ordering
+ set (_JAVA_V9 ${_JAVA_VERSIONS})
+ list (FILTER _JAVA_VERSIONS EXCLUDE REGEX "${_KIND}\\\\9")
+ list (SORT _JAVA_VERSIONS)
+ list (REVERSE _JAVA_VERSIONS)
+ list (FILTER _JAVA_V9 INCLUDE REGEX "${_KIND}\\\\9")
+ list (SORT _JAVA_V9)
+ list (REVERSE _JAVA_V9)
+ list (APPEND _JAVA_VERSIONS ${_JAVA_V9})
+ foreach (_JAVA_HINT IN LISTS _JAVA_VERSIONS)
+ list(APPEND _JAVA_HINTS "[${_JAVA_HINT};JavaHome]/bin")
+ endforeach()
+ endif()
+ endif()
+ endmacro()
+
+ # search for installed versions for version 9 and upper
+ _JAVA_GET_INSTALLED_VERSIONS("JDK")
+ _JAVA_GET_INSTALLED_VERSIONS("JRE")
+
+ list(APPEND _JAVA_HINTS
"[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"
@@ -86,7 +121,6 @@ list(APPEND _JAVA_HINTS
"[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"
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\2.0;JavaHome]/bin"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.9;JavaHome]/bin"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.8;JavaHome]/bin"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.7;JavaHome]/bin"
@@ -95,6 +129,8 @@ list(APPEND _JAVA_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.4;JavaHome]/bin"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\1.3;JavaHome]/bin"
)
+endif()
+
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
set(_JAVA_PATHS
@@ -133,39 +169,72 @@ if(Java_JAVA_EXECUTABLE)
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
+ # Extract version components (up to 4 levels) from "java -version" output.
+ set(_java_version_regex [[(([0-9]+)(\.([0-9]+)(\.([0-9]+)(_([0-9]+))?)?)?.*)]])
+ if(var MATCHES "java version \"${_java_version_regex}\"")
+ # Sun, GCJ, older OpenJDK
+ set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
+ set(Java_VERSION_MAJOR "${CMAKE_MATCH_2}")
+ if (CMAKE_MATCH_4)
+ set(Java_VERSION_MINOR "${CMAKE_MATCH_4}")
+ else()
+ set(Java_VERSION_MINOR 0)
+ endif()
+ if (CMAKE_MATCH_6)
+ set(Java_VERSION_PATCH "${CMAKE_MATCH_6}")
+ else()
+ set(Java_VERSION_PATCH 0)
+ endif()
+ set(Java_VERSION_TWEAK "${CMAKE_MATCH_8}")
+ elseif(var MATCHES "openjdk version \"${_java_version_regex}\"")
+ # OpenJDK
set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
+ set(Java_VERSION_MAJOR "${CMAKE_MATCH_2}")
+ if (CMAKE_MATCH_4)
+ set(Java_VERSION_MINOR "${CMAKE_MATCH_4}")
+ else()
+ set(Java_VERSION_MINOR 0)
+ endif()
+ if (CMAKE_MATCH_6)
+ set(Java_VERSION_PATCH "${CMAKE_MATCH_6}")
+ else()
+ set(Java_VERSION_PATCH 0)
+ endif()
+ set(Java_VERSION_TWEAK "${CMAKE_MATCH_8}")
elseif(var MATCHES "openjdk version \"([0-9]+)-[A-Za-z]+\"")
# OpenJDK 9 early access builds or locally built
set(Java_VERSION_STRING "1.${CMAKE_MATCH_1}.0")
- elseif(var MATCHES "java full version \"kaffe-([0-9]+\\.[0-9]+\\.[0-9_]+)\"")
+ set(Java_VERSION_MAJOR "1")
+ set(Java_VERSION_MINOR "${CMAKE_MATCH_1}")
+ set(Java_VERSION_PATCH "0")
+ set(Java_VERSION_TWEAK "")
+ elseif(var MATCHES "java full version \"kaffe-${_java_version_regex}\"")
# 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}")
+ set(Java_VERSION_MAJOR "${CMAKE_MATCH_2}")
+ set(Java_VERSION_MINOR "${CMAKE_MATCH_4}")
+ set(Java_VERSION_PATCH "${CMAKE_MATCH_6}")
+ set(Java_VERSION_TWEAK "${CMAKE_MATCH_8}")
else()
if(NOT Java_FIND_QUIETLY)
- message(WARNING "regex not supported: ${var}. Please report")
+ string(REPLACE "\n" "\n " ver_msg "\n${var}")
+ message(WARNING "Java version not recognized:${ver_msg}\nPlease report.")
endif()
+ set(Java_VERSION_STRING "")
+ set(Java_VERSION_MAJOR "")
+ set(Java_VERSION_MINOR "")
+ set(Java_VERSION_PATCH "")
+ set(Java_VERSION_TWEAK "")
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})
+ set(Java_VERSION "${Java_VERSION_MAJOR}")
+ if(NOT "x${Java_VERSION}" STREQUAL "x")
+ foreach(c MINOR PATCH TWEAK)
+ if(NOT "x${Java_VERSION_${c}}" STREQUAL "x")
+ string(APPEND Java_VERSION ".${Java_VERSION_${c}}")
+ else()
+ break()
+ endif()
+ endforeach()
endif()
endif()
@@ -220,10 +289,18 @@ if(Java_FIND_COMPONENTS)
endif()
elseif(component STREQUAL "Development")
list(APPEND _JAVA_REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAVAC_EXECUTABLE
- Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE)
- if(Java_JAVA_EXECUTABLE AND Java_JAVAC_EXECUTABLE
- AND Java_JAVAH_EXECUTABLE AND Java_JAVADOC_EXECUTABLE)
- set(Java_Development_FOUND TRUE)
+ Java_JAR_EXECUTABLE Java_JAVADOC_EXECUTABLE)
+ if(Java_VERSION VERSION_LESS "10")
+ list(APPEND _JAVA_REQUIRED_VARS Java_JAVAH_EXECUTABLE)
+ if(Java_JAVA_EXECUTABLE AND Java_JAVAC_EXECUTABLE
+ AND Java_JAVAH_EXECUTABLE AND Java_JAR_EXECUTABLE AND Java_JAVADOC_EXECUTABLE)
+ set(Java_Development_FOUND TRUE)
+ endif()
+ else()
+ if(Java_JAVA_EXECUTABLE AND Java_JAVAC_EXECUTABLE
+ AND Java_JAR_EXECUTABLE AND Java_JAVADOC_EXECUTABLE)
+ set(Java_Development_FOUND TRUE)
+ endif()
endif()
elseif(component STREQUAL "IdlJ")
list(APPEND _JAVA_REQUIRED_VARS Java_IDLJ_EXECUTABLE)
@@ -251,11 +328,19 @@ if(Java_FIND_COMPONENTS)
endif()
else()
# Check for 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
- )
+ if(Java_VERSION VERSION_LESS "10")
+ 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_STRING
+ )
+ else()
+ find_package_handle_standard_args(Java
+ REQUIRED_VARS Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE
+ Java_JAVADOC_EXECUTABLE
+ VERSION_VAR Java_VERSION_STRING
+ )
+ endif()
endif()
diff --git a/Modules/FindKDE3.cmake b/Modules/FindKDE3.cmake
index 03216a5c1..30ea5e62f 100644
--- a/Modules/FindKDE3.cmake
+++ b/Modules/FindKDE3.cmake
@@ -1,144 +1,145 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>
+#[=======================================================================[.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>
+#]=======================================================================]
if(NOT UNIX AND KDE3_FIND_REQUIRED)
- message(FATAL_ERROR "Compiling KDE3 applications and libraries under Windows is not supported")
+ message(FATAL_ERROR "Compiling KDE3 applications and libraries under Windows is not supported")
endif()
# If Qt4 has already been found, fail.
@@ -169,24 +170,24 @@ 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
+ $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 )
+ 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}")
+ 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 ()
endif()
@@ -195,23 +196,22 @@ endif()
# 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
+ $ENV{KDEDIR}/include
+ ${KDE3PREFIX}/include
PATHS
- /opt/kde3/include
- /opt/kde/include
- /usr/include/kde
- /usr/local/include/kde
+ /opt/kde3/include
+ /opt/kde/include
+ PATH_SUFFIXES include/kde
)
#now the KDE library directory
find_library(KDE3_KDECORE_LIBRARY NAMES kdecore
HINTS
- $ENV{KDEDIR}/lib
- ${KDE3PREFIX}/lib
+ $ENV{KDEDIR}/lib
+ ${KDE3PREFIX}/lib
PATHS
- /opt/kde3/lib
- /opt/kde/lib
+ /opt/kde3/lib
+ /opt/kde/lib
)
set(QT_AND_KDECORE_LIBS ${QT_LIBRARIES} ${KDE3_KDECORE_LIBRARY})
@@ -219,49 +219,49 @@ 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)
- elseif(KDE3_KDECORE_LIBRARY MATCHES libx32)
- set(KDE3_LIBTOOL_DIR /libx32/kde3)
- else()
- set(KDE3_LIBTOOL_DIR /lib/kde3)
- endif()
+ if(KDE3_KDECORE_LIBRARY MATCHES lib64)
+ set(KDE3_LIBTOOL_DIR /lib64/kde3)
+ elseif(KDE3_KDECORE_LIBRARY MATCHES libx32)
+ set(KDE3_LIBTOOL_DIR /libx32/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
+ $ENV{KDEDIR}/bin
+ ${KDE3PREFIX}/bin
PATHS
- /opt/kde3/bin
- /opt/kde/bin
+ /opt/kde3/bin
+ /opt/kde/bin
)
find_program(KDE3_DCOPIDL2CPP_EXECUTABLE NAMES dcopidl2cpp
HINTS
- $ENV{KDEDIR}/bin
- ${KDE3PREFIX}/bin
+ $ENV{KDEDIR}/bin
+ ${KDE3PREFIX}/bin
PATHS
- /opt/kde3/bin
- /opt/kde/bin
+ /opt/kde3/bin
+ /opt/kde/bin
)
find_program(KDE3_KCFGC_EXECUTABLE NAMES kconfig_compiler
HINTS
- $ENV{KDEDIR}/bin
- ${KDE3PREFIX}/bin
+ $ENV{KDEDIR}/bin
+ ${KDE3PREFIX}/bin
PATHS
- /opt/kde3/bin
- /opt/kde/bin
+ /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)
+ set(KDE3_FOUND TRUE)
else ()
- set(KDE3_FOUND FALSE)
+ set(KDE3_FOUND FALSE)
endif ()
# add some KDE specific stuff
@@ -269,36 +269,36 @@ 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(_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")
@@ -311,51 +311,50 @@ 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()
+ 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")
+ #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()
+ 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
index bb98e53bd..695e9ac90 100644
--- a/Modules/FindKDE4.cmake
+++ b/Modules/FindKDE4.cmake
@@ -1,29 +1,30 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>
+#[=======================================================================[.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>
+#]=======================================================================]
# If Qt3 has already been found, fail.
if(QT_QT_LIBRARY)
@@ -56,47 +57,47 @@ find_program(KDE4_KDECONFIG_EXECUTABLE NAMES kde4-config
)
if (NOT KDE4_KDECONFIG_EXECUTABLE)
- if (KDE4_FIND_REQUIRED)
- message(FATAL_ERROR "ERROR: Could not find KDE4 kde4-config")
- endif ()
+ 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()
+ 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)
+ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${KDE4_DATA_DIR}/cmake/modules)
- if (KDE4_FIND_QUIETLY)
- set(_quiet QUIET)
- endif ()
+ if (KDE4_FIND_QUIETLY)
+ set(_quiet QUIET)
+ endif ()
- if (KDE4_FIND_REQUIRED)
- set(_req REQUIRED)
- endif ()
+ if (KDE4_FIND_REQUIRED)
+ set(_req REQUIRED)
+ endif ()
- # use FindKDE4Internal.cmake to do the rest
- find_package(KDE4Internal ${_req} ${_quiet} NO_POLICY_SCOPE)
+ # use FindKDE4Internal.cmake to do the rest
+ find_package(KDE4Internal ${_req} ${_quiet} NO_POLICY_SCOPE)
else ()
- if (KDE4_FIND_REQUIRED)
- message(FATAL_ERROR "ERROR: cmake/modules/FindKDE4Internal.cmake not found in ${_data_DIR}")
- endif ()
+ 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
index a451e6ccd..c9c3cce42 100644
--- a/Modules/FindLAPACK.cmake
+++ b/Modules/FindLAPACK.cmake
@@ -1,47 +1,76 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
-# * OpenBLAS
-# * ACML
-# * Apple
-# * NAS
-# * Generic
-#
+#[=======================================================================[.rst:
+FindLAPACK
+----------
+
+Find Linear Algebra PACKage (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).
+
+Input Variables
+^^^^^^^^^^^^^^^
+
+The following variables may be set to influence this module's behavior:
+
+``BLA_STATIC``
+ if ``ON`` use static linkage
+
+``BLA_VENDOR``
+ If set, checks only the specified vendor, if not set checks all the
+ possibilities. List of vendors valid in this module:
+
+ * ``Intel10_32`` (intel mkl v10 32 bit)
+ * ``Intel10_64lp`` (intel mkl v10+ 64 bit, threaded code, lp64 model)
+ * ``Intel10_64lp_seq`` (intel mkl v10+ 64 bit, sequential code, lp64 model)
+ * ``Intel10_64ilp`` (intel mkl v10+ 64 bit, threaded code, ilp64 model)
+ * ``Intel10_64ilp_seq`` (intel mkl v10+ 64 bit, sequential code, ilp64 model)
+ * ``Intel`` (obsolete versions of mkl 32 and 64 bit)
+ * ``OpenBLAS``
+ * ``FLAME``
+ * ``ACML``
+ * ``Apple``
+ * ``NAS``
+ * ``Generic``
+
+``BLA_F95``
+ if ``ON`` tries to find BLAS95/LAPACK95
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables:
+
+``LAPACK_FOUND``
+ 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``
+ library implementing the LAPACK95 interface is found
+
+.. note::
+
+ C or CXX must be enabled to use Intel MKL
+
+ For example, to use Intel MKL libraries and/or Intel compiler:
+
+ .. code-block:: cmake
+
+ set(BLA_VENDOR Intel10_64lp)
+ find_package(LAPACK)
+#]=======================================================================]
set(_lapack_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
@@ -94,6 +123,9 @@ if (NOT _libdir)
set(_libdir ENV LD_LIBRARY_PATH)
endif ()
endif ()
+
+list(APPEND _libdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
+
foreach(_library ${_list})
set(_combined_name ${_combined_name}_${_library})
@@ -108,7 +140,7 @@ foreach(_library ${_list})
set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
endif ()
else ()
- if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ 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 ()
@@ -137,16 +169,15 @@ if(_libraries_work)
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()
+if(_libraries_work)
+ set(${LIBRARIES} ${${LIBRARIES}} ${_blas} ${_threads})
+else()
+ set(${LIBRARIES} FALSE)
+endif()
endmacro()
@@ -173,6 +204,84 @@ if(BLAS_FOUND)
endif()
endif ()
+#intel lapack
+if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
+ if (NOT WIN32)
+ set(LAPACK_mkl_LM "-lm")
+ set(LAPACK_mkl_LDL "-ldl")
+ endif ()
+ if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
+ if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
+ find_PACKAGE(Threads)
+ else()
+ find_package(Threads REQUIRED)
+ endif()
+
+ if (BLA_VENDOR MATCHES "_64ilp")
+ set(LAPACK_mkl_ILP_MODE "ilp64")
+ else ()
+ set(LAPACK_mkl_ILP_MODE "lp64")
+ endif ()
+
+ set(LAPACK_SEARCH_LIBS "")
+
+ if (BLA_F95)
+ set(LAPACK_mkl_SEARCH_SYMBOL "cheev_f95")
+ 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_lapack95_${LAPACK_mkl_ILP_MODE}")
+ else()
+ set(LAPACK_mkl_SEARCH_SYMBOL "cheev")
+ set(_LIBRARIES LAPACK_LIBRARIES)
+ set(_BLAS_LIBRARIES ${BLAS_LIBRARIES})
+
+ # old
+ list(APPEND LAPACK_SEARCH_LIBS
+ "mkl_lapack")
+ endif()
+
+ # First try empty lapack libs
+ if (NOT ${_LIBRARIES})
+ check_lapack_libraries(
+ ${_LIBRARIES}
+ LAPACK
+ ${LAPACK_mkl_SEARCH_SYMBOL}
+ ""
+ ""
+ "${_BLAS_LIBRARIES}"
+ ""
+ )
+ endif ()
+ # Then try the search libs
+ foreach (IT ${LAPACK_SEARCH_LIBS})
+ if (NOT ${_LIBRARIES})
+ check_lapack_libraries(
+ ${_LIBRARIES}
+ LAPACK
+ ${LAPACK_mkl_SEARCH_SYMBOL}
+ ""
+ "${IT}"
+ "${_BLAS_LIBRARIES}"
+ "${CMAKE_THREAD_LIBS_INIT};${LAPACK_mkl_LM};${LAPACK_mkl_LDL}"
+ )
+ endif ()
+ endforeach ()
+
+ unset(LAPACK_mkl_ILP_MODE)
+ unset(LAPACK_mkl_SEARCH_SYMBOL)
+ unset(LAPACK_mkl_LM)
+ unset(LAPACK_mkl_LDL)
+ endif ()
+endif()
+
if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
if(NOT LAPACK_LIBRARIES)
check_lapack_libraries(
@@ -201,27 +310,41 @@ if (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
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 (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")
if(NOT LAPACK_LIBRARIES)
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
cheev
""
- "Accelerate"
+ "flame"
"${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(
@@ -251,123 +374,56 @@ if (BLA_VENDOR STREQUAL "Generic" OR
)
endif ()
endif ()
-#intel lapack
-if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
- if (NOT WIN32)
- set(LM "-lm")
- endif ()
- if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
- 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.")
+ if(LAPACK95_LIBRARIES)
+ set(LAPACK95_FOUND TRUE)
else()
- if(LAPACK_FIND_REQUIRED)
- message(FATAL_ERROR
- "A required library with LAPACK95 API not found. Please specify library location."
- )
+ set(LAPACK95_FOUND FALSE)
+ endif()
+ if(NOT LAPACK_FIND_QUIETLY)
+ if(LAPACK95_FOUND)
+ message(STATUS "A library with LAPACK95 API found.")
else()
- message(STATUS
- "A library with LAPACK95 API not found. Please specify library location."
- )
+ 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()
- endif()
- set(LAPACK_FOUND "${LAPACK95_FOUND}")
- set(LAPACK_LIBRARIES "${LAPACK95_LIBRARIES}")
+ 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.")
+ if(LAPACK_LIBRARIES)
+ set(LAPACK_FOUND TRUE)
else()
- if(LAPACK_FIND_REQUIRED)
- message(FATAL_ERROR
- "A required library with LAPACK API not found. Please specify library location."
- )
+ set(LAPACK_FOUND FALSE)
+ endif()
+
+ if(NOT LAPACK_FIND_QUIETLY)
+ if(LAPACK_FOUND)
+ message(STATUS "A library with LAPACK API found.")
else()
- message(STATUS
- "A library with LAPACK API not found. Please specify library location."
- )
+ 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()
endif()
cmake_pop_check_state()
diff --git a/Modules/FindLATEX.cmake b/Modules/FindLATEX.cmake
index d1f4fa497..b0dad7da3 100644
--- a/Modules/FindLATEX.cmake
+++ b/Modules/FindLATEX.cmake
@@ -1,56 +1,57 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindLATEX
-# ---------
-#
-# Find Latex
-#
-# This module finds an installed Latex and determines the location
-# of the compiler. Additionally the module looks for Latex-related
-# software like BibTeX.
-#
-# This module sets the following result variables::
-#
-# LATEX_FOUND: whether found Latex and requested components
-# LATEX_<component>_FOUND: whether found <component>
-# LATEX_COMPILER: path to the LaTeX compiler
-# PDFLATEX_COMPILER: path to the PdfLaTeX compiler
-# XELATEX_COMPILER: path to the XeLaTeX compiler
-# LUALATEX_COMPILER: path to the LuaLaTeX compiler
-# BIBTEX_COMPILER: path to the BibTeX compiler
-# BIBER_COMPILER: path to the Biber compiler
-# MAKEINDEX_COMPILER: path to the MakeIndex compiler
-# XINDY_COMPILER: path to the xindy compiler
-# DVIPS_CONVERTER: path to the DVIPS converter
-# DVIPDF_CONVERTER: path to the DVIPDF converter
-# PS2PDF_CONVERTER: path to the PS2PDF converter
-# PDFTOPS_CONVERTER: path to the pdftops converter
-# LATEX2HTML_CONVERTER: path to the LaTeX2Html converter
-# HTLATEX_COMPILER: path to the htlatex compiler
-#
-# Possible components are::
-#
-# PDFLATEX
-# XELATEX
-# LUALATEX
-# BIBTEX
-# BIBER
-# MAKEINDEX
-# XINDY
-# DVIPS
-# DVIPDF
-# PS2PDF
-# PDFTOPS
-# LATEX2HTML
-# HTLATEX
-#
-# Example Usages::
-#
-# find_package(LATEX)
-# find_package(LATEX COMPONENTS PDFLATEX)
-# find_package(LATEX COMPONENTS BIBTEX PS2PDF)
+#[=======================================================================[.rst:
+FindLATEX
+---------
+
+Find LaTeX
+
+This module finds an installed LaTeX and determines the location
+of the compiler. Additionally the module looks for Latex-related
+software like BibTeX.
+
+This module sets the following result variables::
+
+ LATEX_FOUND: whether found Latex and requested components
+ LATEX_<component>_FOUND: whether found <component>
+ LATEX_COMPILER: path to the LaTeX compiler
+ PDFLATEX_COMPILER: path to the PdfLaTeX compiler
+ XELATEX_COMPILER: path to the XeLaTeX compiler
+ LUALATEX_COMPILER: path to the LuaLaTeX compiler
+ BIBTEX_COMPILER: path to the BibTeX compiler
+ BIBER_COMPILER: path to the Biber compiler
+ MAKEINDEX_COMPILER: path to the MakeIndex compiler
+ XINDY_COMPILER: path to the xindy compiler
+ DVIPS_CONVERTER: path to the DVIPS converter
+ DVIPDF_CONVERTER: path to the DVIPDF converter
+ PS2PDF_CONVERTER: path to the PS2PDF converter
+ PDFTOPS_CONVERTER: path to the pdftops converter
+ LATEX2HTML_CONVERTER: path to the LaTeX2Html converter
+ HTLATEX_COMPILER: path to the htlatex compiler
+
+Possible components are::
+
+ PDFLATEX
+ XELATEX
+ LUALATEX
+ BIBTEX
+ BIBER
+ MAKEINDEX
+ XINDY
+ DVIPS
+ DVIPDF
+ PS2PDF
+ PDFTOPS
+ LATEX2HTML
+ HTLATEX
+
+Example Usages::
+
+ find_package(LATEX)
+ find_package(LATEX COMPONENTS PDFLATEX)
+ find_package(LATEX COMPONENTS BIBTEX PS2PDF)
+#]=======================================================================]
if (WIN32)
# Try to find the MikTex binary path (look for its package manager).
@@ -170,7 +171,7 @@ find_program(XINDY_COMPILER
/usr/bin
)
if (XINDY_COMPILER)
- set(LATEX_XINDY_FOUND TRUE)
+ set(LATEX_XINDY_FOUND TRUE)
else()
set(LATEX_XINDY_FOUND FALSE)
endif()
diff --git a/Modules/FindLTTngUST.cmake b/Modules/FindLTTngUST.cmake
index 00d5e7aed..9cd17eb05 100644
--- a/Modules/FindLTTngUST.cmake
+++ b/Modules/FindLTTngUST.cmake
@@ -1,37 +1,39 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindLTTngUST
-# ------------
-#
-# This module finds the `LTTng-UST <http://lttng.org/>`__ library.
-#
-# Imported target
-# ^^^^^^^^^^^^^^^
-#
-# This module defines the following :prop_tgt:`IMPORTED` target:
-#
-# ``LTTng::UST``
-# The LTTng-UST library, if found
-#
-# Result variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module sets the following
-#
-# ``LTTNGUST_FOUND``
-# ``TRUE`` if system has LTTng-UST
-# ``LTTNGUST_INCLUDE_DIRS``
-# The LTTng-UST include directories
-# ``LTTNGUST_LIBRARIES``
-# The libraries needed to use LTTng-UST
-# ``LTTNGUST_VERSION_STRING``
-# The LTTng-UST version
-# ``LTTNGUST_HAS_TRACEF``
-# ``TRUE`` if the ``tracef()`` API is available in the system's LTTng-UST
-# ``LTTNGUST_HAS_TRACELOG``
-# ``TRUE`` if the ``tracelog()`` API is available in the system's LTTng-UST
+#[=======================================================================[.rst:
+FindLTTngUST
+------------
+
+Find
+`Linux Trace Toolkit Next Generation (LTTng-UST) <http://lttng.org/>`__ library.
+
+Imported target
+^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` target:
+
+``LTTng::UST``
+ The LTTng-UST library, if found
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module sets the following
+
+``LTTNGUST_FOUND``
+ ``TRUE`` if system has LTTng-UST
+``LTTNGUST_INCLUDE_DIRS``
+ The LTTng-UST include directories
+``LTTNGUST_LIBRARIES``
+ The libraries needed to use LTTng-UST
+``LTTNGUST_VERSION_STRING``
+ The LTTng-UST version
+``LTTNGUST_HAS_TRACEF``
+ ``TRUE`` if the ``tracef()`` API is available in the system's LTTng-UST
+``LTTNGUST_HAS_TRACELOG``
+ ``TRUE`` if the ``tracelog()`` API is available in the system's LTTng-UST
+#]=======================================================================]
find_path(LTTNGUST_INCLUDE_DIRS NAMES lttng/tracepoint.h)
find_library(LTTNGUST_LIBRARIES NAMES lttng-ust)
diff --git a/Modules/FindLibArchive.cmake b/Modules/FindLibArchive.cmake
index 38e512fa3..ef27b7dc0 100644
--- a/Modules/FindLibArchive.cmake
+++ b/Modules/FindLibArchive.cmake
@@ -1,20 +1,22 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindLibArchive
+--------------
+
+Find libarchive library and headers.
+Libarchive is multi-format archive and compression library.
+
+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
+#]=======================================================================]
find_path(LibArchive_INCLUDE_DIR
NAMES archive.h
diff --git a/Modules/FindLibLZMA.cmake b/Modules/FindLibLZMA.cmake
index 8009bcfab..fc9765518 100644
--- a/Modules/FindLibLZMA.cmake
+++ b/Modules/FindLibLZMA.cmake
@@ -1,29 +1,48 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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")
+#[=======================================================================[.rst:
+FindLibLZMA
+-----------
+
+Find LZMA compression algorithm headers and library.
+
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``LibLZMA::LibLZMA``, if
+liblzma has been found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``LIBLZMA_FOUND``
+ True if liblzma headers and library were 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")
+#]=======================================================================]
find_path(LIBLZMA_INCLUDE_DIR lzma.h )
-find_library(LIBLZMA_LIBRARY lzma)
+find_library(LIBLZMA_LIBRARY NAMES lzma liblzma)
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]+")
@@ -40,27 +59,33 @@ endif()
# 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})
+ 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
+find_package_handle_standard_args(LibLZMA REQUIRED_VARS LIBLZMA_LIBRARY
+ LIBLZMA_INCLUDE_DIR
LIBLZMA_HAS_AUTO_DECODER
LIBLZMA_HAS_EASY_ENCODER
LIBLZMA_HAS_LZMA_PRESET
VERSION_VAR LIBLZMA_VERSION_STRING
)
+mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )
if (LIBLZMA_FOUND)
set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})
set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
+ if(NOT TARGET LibLZMA::LibLZMA)
+ add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED)
+ set_target_properties(LibLZMA::LibLZMA PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES ${LIBLZMA_INCLUDE_DIR}
+ IMPORTED_LINK_INTERFACE_LANGUAGES C
+ IMPORTED_LOCATION ${LIBLZMA_LIBRARY})
+ endif()
endif ()
-
-mark_as_advanced( LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY )
diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake
index 613f927e2..da8bfe0d4 100644
--- a/Modules/FindLibXml2.cmake
+++ b/Modules/FindLibXml2.cmake
@@ -1,22 +1,48 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.rst:
+FindLibXml2
+-----------
+
+Find the XML processing library (libxml2).
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``LibXml2::LibXml2``, if
+libxml2 has been found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``LibXml2_FOUND``
+ true if libxml2 headers and libraries were found
+``LIBXML2_INCLUDE_DIR``
+ the directory containing LibXml2 headers
+``LIBXML2_INCLUDE_DIRS``
+ list of the include directories needed to use LibXml2
+``LIBXML2_LIBRARIES``
+ LibXml2 libraries to be linked
+``LIBXML2_DEFINITIONS``
+ the compiler switches required for using LibXml2
+``LIBXML2_XMLLINT_EXECUTABLE``
+ path to the XML checking tool xmllint coming with LibXml2
+``LIBXML2_VERSION_STRING``
+ the version of LibXml2 found (since CMake 2.8.8)
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``LIBXML2_INCLUDE_DIR``
+ the directory containing LibXml2 headers
+``LIBXML2_LIBRARY``
+ path to the LibXml2 library
+#]=======================================================================]
# use pkg-config to get the directories and then use these values
# in the find_path() and find_library() calls
@@ -31,7 +57,14 @@ find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
PATH_SUFFIXES libxml2
)
-find_library(LIBXML2_LIBRARIES NAMES xml2 libxml2
+# CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of
+# the cache entry storing the find_library result. Use the
+# value if it was set by the project or user.
+if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY)
+ set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
+endif()
+
+find_library(LIBXML2_LIBRARY NAMES xml2 libxml2
HINTS
${PC_LIBXML_LIBDIR}
${PC_LIBXML_LIBRARY_DIRS}
@@ -52,9 +85,18 @@ elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.
unset(libxml2_version_str)
endif()
+set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS})
+set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY})
+
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
- REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR
+ REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR
VERSION_VAR LIBXML2_VERSION_STRING)
-mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE)
+mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE)
+
+if(LibXml2_FOUND AND NOT TARGET LibXml2::LibXml2)
+ add_library(LibXml2::LibXml2 UNKNOWN IMPORTED)
+ set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}")
+ set_property(TARGET LibXml2::LibXml2 APPEND PROPERTY IMPORTED_LOCATION "${LIBXML2_LIBRARY}")
+endif()
diff --git a/Modules/FindLibXslt.cmake b/Modules/FindLibXslt.cmake
index abd1963d5..01a9d8be3 100644
--- a/Modules/FindLibXslt.cmake
+++ b/Modules/FindLibXslt.cmake
@@ -1,29 +1,31 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindLibXslt
+-----------
+
+Find the XSL Transformations, Extensible Stylesheet Language
+Transformations (XSLT) library (LibXslt)
+
+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.
+#]=======================================================================]
# use pkg-config to get the directories and then use these values
# in the find_path() and find_library() calls
diff --git a/Modules/FindLua.cmake b/Modules/FindLua.cmake
index b59b9b3c6..caf9d69b2 100644
--- a/Modules/FindLua.cmake
+++ b/Modules/FindLua.cmake
@@ -1,47 +1,53 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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/
+#[=======================================================================[.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/
+#]=======================================================================]
+
+cmake_policy(PUSH) # Policies apply to functions at definition-time
+cmake_policy(SET CMP0012 NEW) # For while(TRUE)
unset(_lua_include_subdirs)
unset(_lua_library_names)
unset(_lua_append_versions)
# this is a function only to have all the variables inside go away automatically
-function(_lua_set_version_vars)
+function(_lua_get_versions)
set(LUA_VERSIONS5 5.3 5.2 5.1 5.0)
if (Lua_FIND_VERSION_EXACT)
@@ -59,6 +65,10 @@ function(_lua_set_version_vars)
list(APPEND _lua_append_versions ${subver})
endif ()
endforeach ()
+ # New version -> Search for it (heuristic only! Defines in include might have changed)
+ if (NOT _lua_append_versions)
+ set(_lua_append_versions ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR})
+ endif()
endif ()
endif ()
else ()
@@ -66,125 +76,153 @@ function(_lua_set_version_vars)
set(_lua_append_versions ${LUA_VERSIONS5})
endif ()
- list(APPEND _lua_include_subdirs "include/lua" "include")
-
- 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}
- )
- endforeach ()
+ if (LUA_Debug)
+ message(STATUS "Considering following Lua versions: ${_lua_append_versions}")
+ endif()
- set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE)
set(_lua_append_versions "${_lua_append_versions}" PARENT_SCOPE)
-endfunction(_lua_set_version_vars)
+endfunction()
-function(_lua_check_header_version _hdr_file)
- # 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 "${_hdr_file}" 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 ()
- foreach (ver IN LISTS _lua_append_versions)
- if (ver STREQUAL "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
- set(LUA_VERSION_MAJOR ${LUA_VERSION_MAJOR} PARENT_SCOPE)
- set(LUA_VERSION_MINOR ${LUA_VERSION_MINOR} PARENT_SCOPE)
- set(LUA_VERSION_PATCH ${LUA_VERSION_PATCH} PARENT_SCOPE)
- set(LUA_VERSION_STRING ${LUA_VERSION_STRING} PARENT_SCOPE)
- return()
- endif ()
- endforeach ()
-endfunction(_lua_check_header_version)
+function(_lua_set_version_vars)
+ set(_lua_include_subdirs_raw "lua")
+
+ foreach (ver IN LISTS _lua_append_versions)
+ string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}")
+ list(APPEND _lua_include_subdirs_raw
+ lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}
+ lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+ lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}
+ )
+ endforeach ()
-_lua_set_version_vars()
+ # Prepend "include/" to each path directly after the path
+ set(_lua_include_subdirs "include")
+ foreach (dir IN LISTS _lua_include_subdirs_raw)
+ list(APPEND _lua_include_subdirs "${dir}" "include/${dir}")
+ endforeach ()
-if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
- _lua_check_header_version("${LUA_INCLUDE_DIR}/lua.h")
-endif ()
+ set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE)
+endfunction(_lua_set_version_vars)
-if (NOT LUA_VERSION_STRING)
+function(_lua_get_header_version)
+ unset(LUA_VERSION_STRING PARENT_SCOPE)
+ set(_hdr_file "${LUA_INCLUDE_DIR}/lua.h")
+
+ if (NOT EXISTS "${_hdr_file}")
+ return()
+ endif ()
+
+ # 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 "${_hdr_file}" 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 ()
+ foreach (ver IN LISTS _lua_append_versions)
+ if (ver STREQUAL "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
+ set(LUA_VERSION_MAJOR ${LUA_VERSION_MAJOR} PARENT_SCOPE)
+ set(LUA_VERSION_MINOR ${LUA_VERSION_MINOR} PARENT_SCOPE)
+ set(LUA_VERSION_PATCH ${LUA_VERSION_PATCH} PARENT_SCOPE)
+ set(LUA_VERSION_STRING ${LUA_VERSION_STRING} PARENT_SCOPE)
+ return()
+ endif ()
+ endforeach ()
+endfunction(_lua_get_header_version)
+
+function(_lua_find_header)
+ _lua_set_version_vars()
+
+ # Initialize as local variable
+ set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH})
+ while (TRUE)
+ # Find the next header to test. Check each possible subdir in order
+ # This prefers e.g. higher versions as they are earlier in the list
+ # It is also consistent with previous versions of FindLua
foreach (subdir IN LISTS _lua_include_subdirs)
- unset(LUA_INCLUDE_PREFIX CACHE)
- find_path(LUA_INCLUDE_PREFIX ${subdir}/lua.h
- HINTS
- ENV LUA_DIR
- PATHS
- ~/Library/Frameworks
- /Library/Frameworks
- /sw # Fink
- /opt/local # DarwinPorts
- /opt/csw # Blastwave
- /opt
+ find_path(LUA_INCLUDE_DIR lua.h
+ HINTS ENV LUA_DIR
+ PATH_SUFFIXES ${subdir}
)
- if (LUA_INCLUDE_PREFIX)
- _lua_check_header_version("${LUA_INCLUDE_PREFIX}/${subdir}/lua.h")
- if (LUA_VERSION_STRING)
- set(LUA_INCLUDE_DIR "${LUA_INCLUDE_PREFIX}/${subdir}")
- break()
- endif ()
- endif ()
- endforeach ()
-endif ()
-unset(_lua_include_subdirs)
+ if (LUA_INCLUDE_DIR)
+ break()
+ endif()
+ endforeach()
+ # Did not found header -> Fail
+ if (NOT LUA_INCLUDE_DIR)
+ return()
+ endif()
+ _lua_get_header_version()
+ # Found accepted version -> Ok
+ if (LUA_VERSION_STRING)
+ if (LUA_Debug)
+ message(STATUS "Found suitable version ${LUA_VERSION_STRING} in ${LUA_INCLUDE_DIR}/lua.h")
+ endif()
+ return()
+ endif()
+ # Found wrong version -> Ignore this path and retry
+ if (LUA_Debug)
+ message(STATUS "Ignoring unsuitable version in ${LUA_INCLUDE_DIR}")
+ endif()
+ list(APPEND CMAKE_IGNORE_PATH "${LUA_INCLUDE_DIR}")
+ unset(LUA_INCLUDE_DIR CACHE)
+ unset(LUA_INCLUDE_DIR)
+ unset(LUA_INCLUDE_DIR PARENT_SCOPE)
+ endwhile ()
+endfunction()
+
+_lua_get_versions()
+_lua_find_header()
+_lua_get_header_version()
unset(_lua_append_versions)
if (LUA_VERSION_STRING)
- set(_lua_library_names
- lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}
- lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
- lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
- lua.${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
+ set(_lua_library_names
+ lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}
+ lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
+ lua-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
+ lua.${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}
)
endif ()
find_library(LUA_LIBRARY
NAMES ${_lua_library_names} lua
+ NAMES_PER_DIR
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}")
-
- # include dl library for statically-linked Lua library
- get_filename_component(LUA_LIB_EXT ${LUA_LIBRARY} EXT)
- if(LUA_LIB_EXT STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX)
- list(APPEND LUA_LIBRARIES ${CMAKE_DL_LIBS})
- endif()
-
- # For Windows and Mac, don't need to explicitly include the math library
- else ()
- set(LUA_LIBRARIES "${LUA_LIBRARY}")
- endif ()
+ # 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}")
+
+ # include dl library for statically-linked Lua library
+ get_filename_component(LUA_LIB_EXT ${LUA_LIBRARY} EXT)
+ if(LUA_LIB_EXT STREQUAL CMAKE_STATIC_LIBRARY_SUFFIX)
+ list(APPEND LUA_LIBRARIES ${CMAKE_DL_LIBS})
+ endif()
+
+ # For Windows and Mac, don't need to explicitly include the math library
+ else ()
+ set(LUA_LIBRARIES "${LUA_LIBRARY}")
+ endif ()
endif ()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
@@ -195,3 +233,5 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua
VERSION_VAR LUA_VERSION_STRING)
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY)
+
+cmake_policy(POP)
diff --git a/Modules/FindLua50.cmake b/Modules/FindLua50.cmake
index 838ca6a88..0575caac6 100644
--- a/Modules/FindLua50.cmake
+++ b/Modules/FindLua50.cmake
@@ -1,36 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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/
+#[=======================================================================[.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/
+#]=======================================================================]
find_path(LUA_INCLUDE_DIR lua.h
HINTS
@@ -39,9 +41,6 @@ find_path(LUA_INCLUDE_DIR lua.h
PATHS
~/Library/Frameworks
/Library/Frameworks
- /sw # Fink
- /opt/local # DarwinPorts
- /opt/csw # Blastwave
/opt
)
@@ -53,9 +52,6 @@ find_library(LUA_LIBRARY_lua
PATHS
~/Library/Frameworks
/Library/Frameworks
- /sw
- /opt/local
- /opt/csw
/opt
)
@@ -71,19 +67,16 @@ else()
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")
+ set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua};${MATH_LIBRARY_FOR_LUA}" CACHE STRING "This is the concatenation 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")
+ set( LUA_LIBRARIES "${LUA_LIBRARY_lualib};${LUA_LIBRARY_lua}" CACHE STRING "This is the concatenation of lua and lualib libraries")
endif()
endif()
endif()
@@ -95,4 +88,3 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
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
index f2b232216..283a3ebfc 100644
--- a/Modules/FindLua51.cmake
+++ b/Modules/FindLua51.cmake
@@ -1,37 +1,39 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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/
+#[=======================================================================[.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/
+#]=======================================================================]
find_path(LUA_INCLUDE_DIR lua.h
HINTS
@@ -40,9 +42,6 @@ find_path(LUA_INCLUDE_DIR lua.h
PATHS
~/Library/Frameworks
/Library/Frameworks
- /sw # Fink
- /opt/local # DarwinPorts
- /opt/csw # Blastwave
/opt
)
@@ -54,9 +53,6 @@ find_library(LUA_LIBRARY
PATHS
~/Library/Frameworks
/Library/Frameworks
- /sw
- /opt/local
- /opt/csw
/opt
)
@@ -86,4 +82,3 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
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
index 5c2dbbf6c..e366619ce 100644
--- a/Modules/FindMFC.cmake
+++ b/Modules/FindMFC.cmake
@@ -1,20 +1,21 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindMFC
+-------
+
+Find Microsoft Foundation Class Library (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.
+#]=======================================================================]
# Assume no MFC support
set(MFC_FOUND "NO")
@@ -31,6 +32,7 @@ if(MFC_ATTEMPT_TRY_COMPILE)
configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
message(STATUS "Looking for MFC")
+ # Try both shared and static as the root project may have set the /MT flag
try_compile(MFC_HAVE_MFC
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
@@ -38,6 +40,16 @@ if(MFC_ATTEMPT_TRY_COMPILE)
-DCMAKE_MFC_FLAG:STRING=2
-DCOMPILE_DEFINITIONS:STRING=-D_AFXDLL
OUTPUT_VARIABLE OUTPUT)
+ if(NOT MFC_HAVE_MFC)
+ configure_file(${CMAKE_ROOT}/Modules/CheckIncludeFile.cxx.in
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx)
+ try_compile(MFC_HAVE_MFC
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.cxx
+ CMAKE_FLAGS
+ -DCMAKE_MFC_FLAG:STRING=1
+ OUTPUT_VARIABLE OUTPUT)
+ endif()
if(MFC_HAVE_MFC)
message(STATUS "Looking for MFC - found")
set(MFC_HAVE_MFC 1 CACHE INTERNAL "Have MFC?")
diff --git a/Modules/FindMPEG.cmake b/Modules/FindMPEG.cmake
index cd1b0214e..e5a80e389 100644
--- a/Modules/FindMPEG.cmake
+++ b/Modules/FindMPEG.cmake
@@ -1,44 +1,43 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-
-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
-)
+#[=======================================================================[.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.
+#]=======================================================================]
+
+find_path(MPEG_INCLUDE_DIR
+ NAMES mpeg2.h mpeg2dec/mpeg2.h mpeg2dec/include/video_out.h)
+
+find_library(MPEG_mpeg2_LIBRARY mpeg2)
+
+find_library(MPEG_vo_LIBRARY vo)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPEG DEFAULT_MSG MPEG_INCLUDE_DIR MPEG_mpeg2_LIBRARY MPEG_vo_LIBRARY)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPEG DEFAULT_MSG MPEG_mpeg2_LIBRARY MPEG_INCLUDE_DIR)
if(MPEG_FOUND)
- set( MPEG_LIBRARIES ${MPEG_mpeg2_LIBRARY} ${MPEG_vo_LIBRARY} )
+ set( MPEG_LIBRARIES ${MPEG_mpeg2_LIBRARY} )
+ if(MPEG_vo_LIBRARY)
+ list(APPEND MPEG2_LIBRARIES ${MPEG_vo_LIBRARY})
+ endif()
endif()
mark_as_advanced(MPEG_INCLUDE_DIR MPEG_mpeg2_LIBRARY MPEG_vo_LIBRARY)
diff --git a/Modules/FindMPEG2.cmake b/Modules/FindMPEG2.cmake
index 2c75d7b2e..763d86a85 100644
--- a/Modules/FindMPEG2.cmake
+++ b/Modules/FindMPEG2.cmake
@@ -1,50 +1,47 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
find_path(MPEG2_INCLUDE_DIR
- NAMES mpeg2.h mpeg2dec/mpeg2.h
- PATHS /usr/local/livid
-)
+ NAMES mpeg2.h mpeg2dec/mpeg2.h)
-find_library(MPEG2_mpeg2_LIBRARY mpeg2
- /usr/local/livid/mpeg2dec/libmpeg2/.libs
-)
+find_library(MPEG2_mpeg2_LIBRARY mpeg2)
-find_library( MPEG2_vo_LIBRARY vo
- /usr/local/livid/mpeg2dec/libvo/.libs
-)
+find_library(MPEG2_vo_LIBRARY vo)
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})
+ set(MPEG2_LIBRARIES ${MPEG2_mpeg2_LIBRARY})
+ if(MPEG2_vo_LIBRARY)
+ list(APPEND MPEG2_LIBRARIES ${MPEG2_vo_LIBRARY})
+ endif()
#some native mpeg2 installations will depend
#on libSDL, if found, add it in.
- include(${CMAKE_CURRENT_LIST_DIR}/FindSDL.cmake)
+ find_package(SDL)
if(SDL_FOUND)
set( MPEG2_LIBRARIES ${MPEG2_LIBRARIES} ${SDL_LIBRARY})
endif()
diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake
index 37f325572..2b9b20cb1 100644
--- a/Modules/FindMPI.cmake
+++ b/Modules/FindMPI.cmake
@@ -1,143 +1,289 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-#
-# 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``
-# Variable indicating the MPI settings for ``<lang>`` were found.
-# ``MPI_<lang>_COMPILER``
-# MPI Compiler wrapper for ``<lang>``.
-# ``MPI_<lang>_COMPILE_FLAGS``
-# Compilation flags for MPI programs, separated by spaces.
-# This is *not* a :ref:`;-list <CMake Language Lists>`.
-# ``MPI_<lang>_INCLUDE_PATH``
-# Include path(s) for MPI header.
-# ``MPI_<lang>_LINK_FLAGS``
-# Linker flags for MPI programs.
-# ``MPI_<lang>_LIBRARIES``
-# All libraries to link MPI programs against.
-#
-# Additionally, the following :prop_tgt:`IMPORTED` targets are defined:
-#
-# ``MPI::MPI_<lang>``
-# Target for using MPI from ``<lang>``.
-#
-# Additionally, FindMPI sets the following variables for running MPI
-# programs from the command line:
-#
-# ``MPIEXEC``
-# Executable for running MPI programs, if provided.
-# ``MPIEXEC_NUMPROC_FLAG``
-# Flag to pass to ``MPIEXEC`` before giving it the number of processors to run on.
-# ``MPIEXEC_MAX_NUMPROCS``
-# Number of MPI processors to utilize. Defaults to the number
-# of processors detected on the host system.
-# ``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, call ``find_package(MPI)``. 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 (e.g. ``mpicc``) 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} ${MPIEXEC_MAX_NUMPROCS}
-# ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS
-#
-# where ``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.
+#[=======================================================================[.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.
+
+Variables for using MPI
+^^^^^^^^^^^^^^^^^^^^^^^
+
+The module exposes the components ``C``, ``CXX``, ``MPICXX`` and ``Fortran``.
+Each of these controls the various MPI languages to search for.
+The difference between ``CXX`` and ``MPICXX`` is that ``CXX`` refers to the
+MPI C API being usable from C++, whereas ``MPICXX`` refers to the MPI-2 C++ API
+that was removed again in MPI-3.
+
+Depending on the enabled components the following variables will be set:
+
+``MPI_FOUND``
+ Variable indicating that MPI settings for all requested languages have been found.
+ If no components are specified, this is true if MPI settings for all enabled languages
+ were detected. Note that the ``MPICXX`` component does not affect this variable.
+``MPI_VERSION``
+ Minimal version of MPI detected among the requested languages, or all enabled languages
+ if no components were specified.
+
+This module will set the following variables per language in your
+project, where ``<lang>`` is one of C, CXX, or Fortran:
+
+``MPI_<lang>_FOUND``
+ Variable indicating the MPI settings for ``<lang>`` were found and that
+ simple MPI test programs compile with the provided settings.
+``MPI_<lang>_COMPILER``
+ MPI compiler for ``<lang>`` if such a program exists.
+``MPI_<lang>_COMPILE_OPTIONS``
+ Compilation options for MPI programs in ``<lang>``, given as a :ref:`;-list <CMake Language Lists>`.
+``MPI_<lang>_COMPILE_DEFINITIONS``
+ Compilation definitions for MPI programs in ``<lang>``, given as a :ref:`;-list <CMake Language Lists>`.
+``MPI_<lang>_INCLUDE_DIRS``
+ Include path(s) for MPI header.
+``MPI_<lang>_LINK_FLAGS``
+ Linker flags for MPI programs.
+``MPI_<lang>_LIBRARIES``
+ All libraries to link MPI programs against.
+
+Additionally, the following :prop_tgt:`IMPORTED` targets are defined:
+
+``MPI::MPI_<lang>``
+ Target for using MPI from ``<lang>``.
+
+The following variables indicating which bindings are present will be defined:
+
+``MPI_MPICXX_FOUND``
+ Variable indicating whether the MPI-2 C++ bindings are present (introduced in MPI-2, removed with MPI-3).
+``MPI_Fortran_HAVE_F77_HEADER``
+ True if the Fortran 77 header ``mpif.h`` is available.
+``MPI_Fortran_HAVE_F90_MODULE``
+ True if the Fortran 90 module ``mpi`` can be used for accessing MPI (MPI-2 and higher only).
+``MPI_Fortran_HAVE_F08_MODULE``
+ True if the Fortran 2008 ``mpi_f08`` is available to MPI programs (MPI-3 and higher only).
+
+If possible, the MPI version will be determined by this module. The facilities to detect the MPI version
+were introduced with MPI-1.2, and therefore cannot be found for older MPI versions.
+
+``MPI_<lang>_VERSION_MAJOR``
+ Major version of MPI implemented for ``<lang>`` by the MPI distribution.
+``MPI_<lang>_VERSION_MINOR``
+ Minor version of MPI implemented for ``<lang>`` by the MPI distribution.
+``MPI_<lang>_VERSION``
+ MPI version implemented for ``<lang>`` by the MPI distribution.
+
+Note that there's no variable for the C bindings being accessible through ``mpi.h``, since the MPI standards
+always have required this binding to work in both C and C++ code.
+
+For running MPI programs, the module sets the following variables
+
+``MPIEXEC_EXECUTABLE``
+ Executable for running MPI programs, if such exists.
+``MPIEXEC_NUMPROC_FLAG``
+ Flag to pass to ``mpiexec`` before giving it the number of processors to run on.
+``MPIEXEC_MAX_NUMPROCS``
+ Number of MPI processors to utilize. Defaults to the number
+ of processors detected on the host system.
+``MPIEXEC_PREFLAGS``
+ Flags to pass to ``mpiexec`` directly before the executable to run.
+``MPIEXEC_POSTFLAGS``
+ Flags to pass to ``mpiexec`` after other flags.
+
+Variables for locating MPI
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+This module performs a three step search for an MPI implementation:
+
+1. Check if the compiler has MPI support built-in. This is the case if the user passed a
+ compiler wrapper as ``CMAKE_<LANG>_COMPILER`` or if they're on a Cray system.
+2. Attempt to find an MPI compiler wrapper and determine the compiler information from it.
+3. Try to find an MPI implementation that does not ship such a wrapper by guessing settings.
+ Currently, only Microsoft MPI and MPICH2 on Windows are supported.
+
+For controlling the second step, the following variables may be set:
+
+``MPI_<lang>_COMPILER``
+ Search for the specified compiler wrapper and use it.
+``MPI_<lang>_COMPILER_FLAGS``
+ Flags to pass to the MPI compiler wrapper during interrogation. Some compiler wrappers
+ support linking debug or tracing libraries if a specific flag is passed and this variable
+ may be used to obtain them.
+``MPI_COMPILER_FLAGS``
+ Used to initialize ``MPI_<lang>_COMPILER_FLAGS`` if no language specific flag has been given.
+ Empty by default.
+``MPI_EXECUTABLE_SUFFIX``
+ A suffix which is appended to all names that are being looked for. For instance you may set this
+ to ``.mpich`` or ``.openmpi`` to prefer the one or the other on Debian and its derivatives.
+
+In order to control the guessing step, the following variable may be set:
+
+``MPI_GUESS_LIBRARY_NAME``
+ Valid values are ``MSMPI`` and ``MPICH2``. If set, only the given library will be searched for.
+ By default, ``MSMPI`` will be preferred over ``MPICH2`` if both are available.
+ This also sets ``MPI_SKIP_COMPILER_WRAPPER`` to ``true``, which may be overridden.
+
+Each of the search steps may be skipped with the following control variables:
+
+``MPI_ASSUME_NO_BUILTIN_MPI``
+ If true, the module assumes that the compiler itself does not provide an MPI implementation and
+ skips to step 2.
+``MPI_SKIP_COMPILER_WRAPPER``
+ If true, no compiler wrapper will be searched for.
+``MPI_SKIP_GUESSING``
+ If true, the guessing step will be skipped.
+
+Additionally, the following control variable is available to change search behavior:
+
+``MPI_CXX_SKIP_MPICXX``
+ Add some definitions that will disable the MPI-2 C++ bindings.
+ Currently supported are MPICH, Open MPI, Platform MPI and derivatives thereof,
+ for example MVAPICH or Intel MPI.
+
+If the find procedure fails for a variable ``MPI_<lang>_WORKS``, then the settings detected by or passed to
+the module did not work and even a simple MPI test program failed to compile.
+
+If all of these parameters were not sufficient to find the right MPI implementation, a user may
+disable the entire autodetection process by specifying both a list of libraries in ``MPI_<lang>_LIBRARIES``
+and a list of include directories in ``MPI_<lang>_ADDITIONAL_INCLUDE_DIRS``.
+Any other variable may be set in addition to these two. The module will then validate the MPI settings and store the
+settings in the cache.
+
+Cache variables for MPI
+^^^^^^^^^^^^^^^^^^^^^^^
+
+The variable ``MPI_<lang>_INCLUDE_DIRS`` will be assembled from the following variables.
+For C and CXX:
+
+``MPI_<lang>_HEADER_DIR``
+ Location of the ``mpi.h`` header on disk.
+
+For Fortran:
+
+``MPI_Fortran_F77_HEADER_DIR``
+ Location of the Fortran 77 header ``mpif.h``, if it exists.
+``MPI_Fortran_MODULE_DIR``
+ Location of the ``mpi`` or ``mpi_f08`` modules, if available.
+
+For all languages the following variables are additionally considered:
+
+``MPI_<lang>_ADDITIONAL_INCLUDE_DIRS``
+ A :ref:`;-list <CMake Language Lists>` of paths needed in addition to the normal include directories.
+``MPI_<include_name>_INCLUDE_DIR``
+ Path variables for include folders referred to by ``<include_name>``.
+``MPI_<lang>_ADDITIONAL_INCLUDE_VARS``
+ A :ref:`;-list <CMake Language Lists>` of ``<include_name>`` that will be added to the include locations of ``<lang>``.
-include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+The variable ``MPI_<lang>_LIBRARIES`` will be assembled from the following variables:
-#
-# 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.
-#
+``MPI_<lib_name>_LIBRARY``
+ The location of a library called ``<lib_name>`` for use with MPI.
+``MPI_<lang>_LIB_NAMES``
+ A :ref:`;-list <CMake Language Lists>` of ``<lib_name>`` that will be added to the include locations of ``<lang>``.
+
+Usage of mpiexec
+^^^^^^^^^^^^^^^^
+
+When using ``MPIEXEC_EXECUTABLE`` to execute MPI applications, you should typically
+use all of the ``MPIEXEC_EXECUTABLE`` flags as follows:
+
+::
+
+ ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS}
+ ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS
+
+where ``EXECUTABLE`` is the MPI program, and ``ARGS`` are the arguments to
+pass to the MPI program.
+
+Advanced variables for using MPI
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The module can perform some advanced feature detections upon explicit request.
+
+**Important notice:** The following checks cannot be performed without *executing* an MPI test program.
+Consider the special considerations for the behavior of :command:`try_run` during cross compilation.
+Moreover, running an MPI program can cause additional issues, like a firewall notification on some systems.
+You should only enable these detections if you absolutely need the information.
+
+If the following variables are set to true, the respective search will be performed:
+
+``MPI_DETERMINE_Fortran_CAPABILITIES``
+ Determine for all available Fortran bindings what the values of ``MPI_SUBARRAYS_SUPPORTED`` and
+ ``MPI_ASYNC_PROTECTS_NONBLOCKING`` are and make their values available as ``MPI_Fortran_<binding>_SUBARRAYS``
+ and ``MPI_Fortran_<binding>_ASYNCPROT``, where ``<binding>`` is one of ``F77_HEADER``, ``F90_MODULE`` and
+ ``F08_MODULE``.
+``MPI_DETERMINE_LIBRARY_VERSION``
+ For each language, find the output of ``MPI_Get_library_version`` and make it available as ``MPI_<lang>_LIBRARY_VERSION_STRING``.
+ This information is usually tied to the runtime component of an MPI implementation and might differ depending on ``<lang>``.
+ Note that the return value is entirely implementation defined. This information might be used to identify
+ the MPI vendor and for example pick the correct one of multiple third party binaries that matches the MPI vendor.
+
+Backward Compatibility
+^^^^^^^^^^^^^^^^^^^^^^
+
+For backward compatibility with older versions of FindMPI, these
+variables are set, but deprecated:
-# 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 mpicc.bat)
-set(_MPI_CXX_COMPILER_NAMES mpicxx mpiCC mpcxx mpCC mpic++ mpc++
- mpicxx_r mpiCC_r mpcxx_r mpCC_r mpic++_r mpc++_r
- mpicxx.bat)
-set(_MPI_Fortran_COMPILER_NAMES mpif95 mpif95_r mpf95 mpf95_r
+::
+
+ MPI_COMPILER MPI_LIBRARY MPI_EXTRA_LIBRARY
+ MPI_COMPILE_FLAGS MPI_INCLUDE_PATH MPI_LINK_FLAGS
+ MPI_LIBRARIES
+
+In new projects, please use the ``MPI_<lang>_XXX`` equivalents.
+Additionally, the following variables are deprecated:
+
+``MPI_<lang>_COMPILE_FLAGS``
+ Use ``MPI_<lang>_COMPILE_OPTIONS`` and ``MPI_<lang>_COMPILE_DEFINITIONS`` instead.
+``MPI_<lang>_INCLUDE_PATH``
+ For consumption use ``MPI_<lang>_INCLUDE_DIRS`` and for specifying folders use ``MPI_<lang>_ADDITIONAL_INCLUDE_DIRS`` instead.
+``MPIEXEC``
+ Use ``MPIEXEC_EXECUTABLE`` instead.
+#]=======================================================================]
+
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+# Generic compiler names
+set(_MPI_C_GENERIC_COMPILER_NAMES mpicc mpcc mpicc_r mpcc_r)
+set(_MPI_CXX_GENERIC_COMPILER_NAMES mpicxx mpiCC mpcxx mpCC mpic++ mpc++
+ mpicxx_r mpiCC_r mpcxx_r mpCC_r mpic++_r mpc++_r)
+set(_MPI_Fortran_GENERIC_COMPILER_NAMES mpif95 mpif95_r mpf95 mpf95_r
mpif90 mpif90_r mpf90 mpf90_r
- mpif77 mpif77_r mpf77 mpf77_r)
+ mpif77 mpif77_r mpf77 mpf77_r
+ mpifc)
# 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_CXX_COMPILER_NAMES mpig++ mpg++ mpig++_r mpg++_r mpigxx)
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 mpiicc.bat)
-set(_MPI_Intel_CXX_COMPILER_NAMES mpiicpc mpiicxx mpiic++ mpiiCC mpiicpc.bat)
-set(_MPI_Intel_Fortran_COMPILER_NAMES mpiifort mpiif95 mpiif90 mpiif77 mpiifort.bat)
+# Intel MPI compiler names on Windows
+if(WIN32)
+ list(APPEND _MPI_C_GENERIC_COMPILER_NAMES mpicc.bat)
+ list(APPEND _MPI_CXX_GENERIC_COMPILER_NAMES mpicxx.bat)
+ list(APPEND _MPI_Fortran_GENERIC_COMPILER_NAMES mpifc.bat)
+
+ # Intel MPI compiler names
+ set(_MPI_Intel_C_COMPILER_NAMES mpiicc.bat)
+ set(_MPI_Intel_CXX_COMPILER_NAMES mpiicpc.bat)
+ set(_MPI_Intel_Fortran_COMPILER_NAMES mpiifort.bat mpif77.bat mpif90.bat)
+
+ # Intel MPI compiler names for MSMPI
+ set(_MPI_MSVC_C_COMPILER_NAMES mpicl.bat)
+ set(_MPI_MSVC_CXX_COMPILER_NAMES mpicl.bat)
+else()
+ # Intel compiler names
+ set(_MPI_Intel_C_COMPILER_NAMES mpiicc)
+ set(_MPI_Intel_CXX_COMPILER_NAMES mpiicpc mpiicxx mpiic++)
+ set(_MPI_Intel_Fortran_COMPILER_NAMES mpiifort mpiif95 mpiif90 mpiif77)
+endif()
# PGI compiler names
set(_MPI_PGI_C_COMPILER_NAMES mpipgcc mppgcc)
@@ -153,524 +299,1418 @@ set(_MPI_XL_Fortran_COMPILER_NAMES mpixlf95 mpixlf95_r mpxlf95 mpxlf95
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})
+# Prepend vendor-specific compiler wrappers to the list. If we don't know the compiler,
+# attempt all of them.
+# By attempting vendor-specific compiler names first, we should avoid situations where the compiler wrapper
+# stems from a proprietary MPI and won't know which compiler it's being used for. For instance, Intel MPI
+# controls its settings via the I_MPI_CC environment variables if the generic name is being used.
+# If we know which compiler we're working with, we can use the most specialized wrapper there is in order to
+# pick up the right settings for it.
+foreach (LANG IN ITEMS C CXX Fortran)
+ set(_MPI_${LANG}_COMPILER_NAMES "")
+ foreach (id IN ITEMS GNU Intel MSVC 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}${MPI_EXECUTABLE_SUFFIX})
endif()
- unset(_MPI_${id}_${lang}_COMPILER_NAMES) # clean up the namespace here
+ unset(_MPI_${id}_${LANG}_COMPILER_NAMES)
endforeach()
+ list(APPEND _MPI_${LANG}_COMPILER_NAMES ${_MPI_${LANG}_GENERIC_COMPILER_NAMES}${MPI_EXECUTABLE_SUFFIX})
+ unset(_MPI_${LANG}_GENERIC_COMPILER_NAMES)
endforeach()
+# Names to try for mpiexec
+# Only mpiexec commands are guaranteed to behave as described in the standard,
+# mpirun commands are not covered by the standard in any way whatsoever.
+# lamexec is the executable for LAM/MPI, srun is for SLURM or Open MPI with SLURM support.
+# srun -n X <executable> is however a valid command, so it behaves 'like' mpiexec.
+set(_MPIEXEC_NAMES_BASE mpiexec mpiexec.hydra mpiexec.mpd mpirun lamexec srun)
-# 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)
- # MSMPI
- file(TO_CMAKE_PATH "$ENV{MSMPI_BIN}" msmpi_bin_path) # The default path ends with a '\' and doesn't mix with ';' when appending.
- list(APPEND _MPI_PREFIX_PATH "${msmpi_bin_path}")
- unset(msmpi_bin_path)
- list(APPEND _MPI_PREFIX_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MPI;InstallRoot]/Bin")
- list(APPEND _MPI_PREFIX_PATH "$ENV{MSMPI_INC}/..") # The SDK is installed separately from the runtime
- # MPICH
- 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()
+unset(_MPIEXEC_NAMES)
+foreach(_MPIEXEC_NAME IN LISTS _MPIEXEC_NAMES_BASE)
+ list(APPEND _MPIEXEC_NAMES "${_MPIEXEC_NAME}${MPI_EXECUTABLE_SUFFIX}")
endforeach()
+unset(_MPIEXEC_NAMES_BASE)
-function (_mpi_check_compiler compiler options cmdvar resvar)
+function (_MPI_check_compiler LANG QUERY_FLAG OUTPUT_VARIABLE RESULT_VARIABLE)
+ if(DEFINED MPI_${LANG}_COMPILER_FLAGS)
+ separate_arguments(_MPI_COMPILER_WRAPPER_OPTIONS NATIVE_COMMAND "${MPI_${LANG}_COMPILER_FLAGS}")
+ else()
+ separate_arguments(_MPI_COMPILER_WRAPPER_OPTIONS NATIVE_COMMAND "${MPI_COMPILER_FLAGS}")
+ endif()
execute_process(
- COMMAND "${compiler}" ${options}
- OUTPUT_VARIABLE cmdline OUTPUT_STRIP_TRAILING_WHITESPACE
- ERROR_VARIABLE cmdline ERROR_STRIP_TRAILING_WHITESPACE
- RESULT_VARIABLE success)
- # Intel MPI 5.0.1 will return a zero return code even when the
- # argument to the MPI compiler wrapper is unknown. Attempt to
- # catch this case.
- if(cmdline MATCHES "undefined reference" OR cmdline MATCHES "unrecognized")
- set(success 255 )
- endif()
- set(${cmdvar} "${cmdline}" PARENT_SCOPE)
- set(${resvar} "${success}" PARENT_SCOPE)
+ COMMAND ${MPI_${LANG}_COMPILER} ${_MPI_COMPILER_WRAPPER_OPTIONS} ${QUERY_FLAG}
+ OUTPUT_VARIABLE WRAPPER_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE WRAPPER_OUTPUT ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE WRAPPER_RETURN)
+ # Some compiler wrappers will yield spurious zero return values, for example
+ # Intel MPI tolerates unknown arguments and if the MPI wrappers loads a shared
+ # library that has invalid or missing version information there would be warning
+ # messages emitted by ld.so in the compiler output. In either case, we'll treat
+ # the output as invalid.
+ if("${WRAPPER_OUTPUT}" MATCHES "undefined reference|unrecognized|need to set|no version information available|command not found")
+ set(WRAPPER_RETURN 255)
+ endif()
+ # Ensure that no error output might be passed upwards.
+ if(NOT WRAPPER_RETURN EQUAL 0)
+ unset(WRAPPER_OUTPUT)
+ else()
+ # Strip leading whitespace
+ string(REGEX REPLACE "^ +" "" WRAPPER_OUTPUT "${WRAPPER_OUTPUT}")
+ endif()
+ set(${OUTPUT_VARIABLE} "${WRAPPER_OUTPUT}" PARENT_SCOPE)
+ set(${RESULT_VARIABLE} "${WRAPPER_RETURN}" PARENT_SCOPE)
endfunction()
-#
-# 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.
- _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-showme:compile" MPI_COMPILE_CMDLINE 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)
+macro(_MPI_env_set_ifnot VAR VALUE)
+ if(NOT DEFINED ENV{${VAR}})
+ set(_MPI_${VAR}_WAS_SET FALSE)
+ set(ENV{${VAR}} ${${VALUE}})
+ else()
+ set(_MPI_${VAR}_WAS_SET TRUE)
+ endif()
+endmacro()
- else()
- # reset things here if something went wrong.
- set(MPI_COMPILE_CMDLINE)
- set(MPI_LINK_CMDLINE)
- endif()
- endif ()
+macro(_MPI_env_unset_ifnot VAR)
+ if(NOT _MPI_${VAR}_WAS_SET)
+ unset(ENV{${VAR}})
+ endif()
+endmacro()
+
+function (_MPI_interrogate_compiler LANG)
+ unset(MPI_COMPILE_CMDLINE)
+ unset(MPI_LINK_CMDLINE)
+
+ unset(MPI_COMPILE_OPTIONS_WORK)
+ unset(MPI_COMPILE_DEFINITIONS_WORK)
+ unset(MPI_INCLUDE_DIRS_WORK)
+ unset(MPI_LINK_FLAGS_WORK)
+ unset(MPI_LIB_NAMES_WORK)
+ unset(MPI_LIB_FULLPATHS_WORK)
+
+ # Define the MPICH and Intel MPI compiler variables to the compilers set in CMake.
+ # It's possible to have a per-compiler configuration in these MPI implementations and
+ # a particular MPICH derivate might check compiler interoperability.
+ # Intel MPI in particular does this with I_MPI_CHECK_COMPILER.
+ file(TO_NATIVE_PATH "${CMAKE_${LANG}_COMPILER}" _MPI_UNDERLAYING_COMPILER)
+ # On Windows, the Intel MPI batch scripts can only work with filnames - Full paths will break them.
+ # Due to the lack of other MPICH-based wrappers for Visual C++, we may treat this as default.
+ if(MSVC)
+ get_filename_component(_MPI_UNDERLAYING_COMPILER "${_MPI_UNDERLAYING_COMPILER}" NAME)
+ endif()
+ if("${LANG}" STREQUAL "C")
+ _MPI_env_set_ifnot(I_MPI_CC _MPI_UNDERLAYING_COMPILER)
+ _MPI_env_set_ifnot(MPICH_CC _MPI_UNDERLAYING_COMPILER)
+ elseif("${LANG}" STREQUAL "CXX")
+ _MPI_env_set_ifnot(I_MPI_CXX _MPI_UNDERLAYING_COMPILER)
+ _MPI_env_set_ifnot(MPICH_CXX _MPI_UNDERLAYING_COMPILER)
+ elseif("${LANG}" STREQUAL "Fortran")
+ _MPI_env_set_ifnot(I_MPI_FC _MPI_UNDERLAYING_COMPILER)
+ _MPI_env_set_ifnot(MPICH_FC _MPI_UNDERLAYING_COMPILER)
+ _MPI_env_set_ifnot(I_MPI_F77 _MPI_UNDERLAYING_COMPILER)
+ _MPI_env_set_ifnot(MPICH_F77 _MPI_UNDERLAYING_COMPILER)
+ _MPI_env_set_ifnot(I_MPI_F90 _MPI_UNDERLAYING_COMPILER)
+ _MPI_env_set_ifnot(MPICH_F90 _MPI_UNDERLAYING_COMPILER)
+ endif()
+
+ # Set these two variables for Intel MPI:
+ # - I_MPI_DEBUG_INFO_STRIP: It adds 'objcopy' lines to the compiler output. We support stripping them
+ # (see below), but if we can avoid them in the first place, we should.
+ # - I_MPI_FORT_BIND: By default Intel MPI makes the C/C++ compiler wrappers link Fortran bindings.
+ # This is so that mixed-language code doesn't require additional libraries when linking with mpicc.
+ # For our purposes, this makes little sense, since correct MPI usage from CMake already circumvenes this.
+ set(_MPI_ENV_VALUE "disable")
+ _MPI_env_set_ifnot(I_MPI_DEBUG_INFO_STRIP _MPI_ENV_VALUE)
+ _MPI_env_set_ifnot(I_MPI_FORT_BIND _MPI_ENV_VALUE)
+
+ # Check whether the -showme:compile option works. This indicates that we have either Open MPI
+ # or a newer version of LAM/MPI, and implies that -showme:link will also work.
+ # Open MPI also supports -show, but separates linker and compiler information
+ _MPI_check_compiler(${LANG} "-showme:compile" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN)
+ if (MPI_COMPILER_RETURN EQUAL 0)
+ _MPI_check_compiler(${LANG} "-showme:link" MPI_LINK_CMDLINE MPI_COMPILER_RETURN)
+
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ unset(MPI_COMPILE_CMDLINE)
+ endif()
+ endif()
+
+ # MPICH and MVAPICH offer -compile-info and -link-info.
+ # For modern versions, both do the same as -show. However, for old versions, they do differ
+ # when called for mpicxx and mpif90 and it's necessary to use them over -show in order to find the
+ # removed MPI C++ bindings.
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ _MPI_check_compiler(${LANG} "-compile-info" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN)
+
+ if (MPI_COMPILER_RETURN EQUAL 0)
+ _MPI_check_compiler(${LANG} "-link-info" MPI_LINK_CMDLINE MPI_COMPILER_RETURN)
- # Older versions of LAM-MPI have "-showme". Try to find that.
if (NOT MPI_COMPILER_RETURN EQUAL 0)
- _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-showme" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN)
+ unset(MPI_COMPILE_CMDLINE)
endif()
+ endif()
+ endif()
- # MVAPICH uses -compile-info and -link-info. Try them.
- if (NOT MPI_COMPILER_RETURN EQUAL 0)
- _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-compile-info" MPI_COMPILE_CMDLINE 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()
+ # MPICH, MVAPICH2 and Intel MPI just use "-show". Open MPI also offers this, but the
+ # -showme commands are more specialized.
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ _MPI_check_compiler(${LANG} "-show" MPI_COMPILE_CMDLINE 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)
+ # Older versions of LAM/MPI have "-showme". Open MPI also supports this.
+ # Unknown to MPICH, MVAPICH and Intel MPI.
+ if (NOT MPI_COMPILER_RETURN EQUAL 0)
+ _MPI_check_compiler(${LANG} "-showme" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN)
+ endif()
+
+ if (MPI_COMPILER_RETURN EQUAL 0 AND DEFINED MPI_COMPILE_CMDLINE)
+ # Intel MPI can be run with -compchk or I_MPI_CHECK_COMPILER set to 1.
+ # In this case, -show will be prepended with a line to the compiler checker. This is a script that performs
+ # compatibility checks and returns a non-zero exit code together with an error if something fails.
+ # It has to be called as "compchk.sh <arch> <compiler>". Here, <arch> is one out of 32 (i686), 64 (ia64) or 32e (x86_64).
+ # The compiler is identified by filename, and can be either the MPI compiler or the underlying compiler.
+ # NOTE: It is vital to run this script while the environment variables are set up, otherwise it can check the wrong compiler.
+ if("${MPI_COMPILE_CMDLINE}" MATCHES "^([^\" ]+/compchk.sh|\"[^\"]+/compchk.sh\") +([^ ]+)")
+ # Now CMAKE_MATCH_1 contains the path to the compchk.sh file and CMAKE_MATCH_2 the architecture flag.
+ unset(COMPILER_CHECKER_OUTPUT)
+ execute_process(
+ COMMAND ${CMAKE_MATCH_1} ${CMAKE_MATCH_2} ${MPI_${LANG}_COMPILER}
+ OUTPUT_VARIABLE COMPILER_CHECKER_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_VARIABLE COMPILER_CHECKER_OUTPUT ERROR_STRIP_TRAILING_WHITESPACE
+ RESULT_VARIABLE MPI_COMPILER_RETURN)
+ # If it returned a non-zero value, the check below will fail and cause the interrogation to be aborted.
+ if(NOT MPI_COMPILER_RETURN EQUAL 0)
+ if(NOT MPI_FIND_QUIETLY)
+ message(STATUS "Intel MPI compiler check failed: ${COMPILER_CHECKER_OUTPUT}")
endif()
+ else()
+ # Since the check passed, we can remove the compchk.sh script.
+ string(REGEX REPLACE "^([^\" ]+|\"[^\"]+\")/compchk.sh.*\n" "" MPI_COMPILE_CMDLINE "${MPI_COMPILE_CMDLINE}")
endif()
+ endif()
+ endif()
- # MPICH just uses "-show". Try it.
- if (NOT MPI_COMPILER_RETURN EQUAL 0)
- _mpi_check_compiler("${MPI_${lang}_COMPILER}" "-show" MPI_COMPILE_CMDLINE MPI_COMPILER_RETURN)
+ # Revert changes to the environment made previously
+ if("${LANG}" STREQUAL "C")
+ _MPI_env_unset_ifnot(I_MPI_CC)
+ _MPI_env_unset_ifnot(MPICH_CC)
+ elseif("${LANG}" STREQUAL "CXX")
+ _MPI_env_unset_ifnot(I_MPI_CXX)
+ _MPI_env_unset_ifnot(MPICH_CXX)
+ elseif("${LANG}" STREQUAL "Fortran")
+ _MPI_env_unset_ifnot(I_MPI_FC)
+ _MPI_env_unset_ifnot(MPICH_FC)
+ _MPI_env_unset_ifnot(I_MPI_F77)
+ _MPI_env_unset_ifnot(MPICH_F77)
+ _MPI_env_unset_ifnot(I_MPI_F90)
+ _MPI_env_unset_ifnot(MPICH_F90)
+ endif()
+
+ _MPI_env_unset_ifnot(I_MPI_DEBUG_INFO_STRIP)
+ _MPI_env_unset_ifnot(I_MPI_FORT_BIND)
+
+ if (NOT (MPI_COMPILER_RETURN EQUAL 0) OR NOT (DEFINED MPI_COMPILE_CMDLINE))
+ # Cannot interrogate this compiler, so exit.
+ set(MPI_${LANG}_WRAPPER_FOUND FALSE PARENT_SCOPE)
+ return()
+ endif()
+ unset(MPI_COMPILER_RETURN)
+
+ # 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 DEFINED MPI_LINK_CMDLINE)
+ set(MPI_LINK_CMDLINE "${MPI_COMPILE_CMDLINE}")
+ endif()
+
+ # Visual Studio parsers permit each flag prefixed by either / or -.
+ # We'll normalize this to the - syntax we use for CMake purposes anyways.
+ if(MSVC)
+ foreach(_MPI_VARIABLE IN ITEMS COMPILE LINK)
+ # The Intel MPI wrappers on Windows prefix their output with some copyright boilerplate.
+ # To prevent possible problems, we discard this text before proceeding with any further matching.
+ string(REGEX REPLACE "^[^ ]+ for the Intel\\(R\\) MPI Library [^\n]+ for Windows\\*\nCopyright\\(C\\) [^\n]+, Intel Corporation\\. All rights reserved\\.\n\n" ""
+ MPI_${_MPI_VARIABLE}_CMDLINE "${MPI_${_MPI_VARIABLE}_CMDLINE}")
+ string(REGEX REPLACE "(^| )/" "\\1-" MPI_${_MPI_VARIABLE}_CMDLINE "${MPI_${_MPI_VARIABLE}_CMDLINE}")
+ string(REPLACE "-libpath:" "-LIBPATH:" MPI_${_MPI_VARIABLE}_CMDLINE "${MPI_${_MPI_VARIABLE}_CMDLINE}")
+ endforeach()
+ endif()
+
+ # For MSVC and cl-compatible compilers, the keyword /link indicates a point after which
+ # everything following is passed to the linker. In this case, we drop all prior information
+ # from the link line and treat any unknown extra flags as linker flags.
+ set(_MPI_FILTERED_LINK_INFORMATION FALSE)
+ if(MSVC)
+ if(MPI_LINK_CMDLINE MATCHES " -(link|LINK) ")
+ string(REGEX REPLACE ".+-(link|LINK) +" "" MPI_LINK_CMDLINE "${MPI_LINK_CMDLINE}")
+ set(_MPI_FILTERED_LINK_INFORMATION TRUE)
+ endif()
+ string(REGEX REPLACE " +-(link|LINK) .+" "" MPI_COMPILE_CMDLINE "${MPI_COMPILE_CMDLINE}")
+ endif()
+
+ if(UNIX)
+ # At this point, we obtained some output from a compiler wrapper that works.
+ # We'll now try to parse it into variables with meaning to us.
+ if("${LANG}" STREQUAL "Fortran")
+ # If MPICH (and derivates) didn't recognize the Fortran compiler include flag during configuration,
+ # they'll return a set of three commands, consisting out of a symlink command for mpif.h,
+ # the actual compiler command and deletion of the created symlink.
+ # Especially with M(VA)PICH-1, this appears to happen erroneously, and therefore we should translate
+ # this output into an additional include directory and then drop it from the output.
+ if("${MPI_COMPILE_CMDLINE}" MATCHES "^ln -s ([^\" ]+|\"[^\"]+\") mpif.h")
+ get_filename_component(MPI_INCLUDE_DIRS_WORK "${CMAKE_MATCH_1}" DIRECTORY)
+ string(REGEX REPLACE "^ln -s ([^\" ]+|\"[^\"]+\") mpif.h\n" "" MPI_COMPILE_CMDLINE "${MPI_COMPILE_CMDLINE}")
+ string(REGEX REPLACE "^ln -s ([^\" ]+|\"[^\"]+\") mpif.h\n" "" MPI_LINK_CMDLINE "${MPI_LINK_CMDLINE}")
+ string(REGEX REPLACE "\nrm -f mpif.h$" "" MPI_COMPILE_CMDLINE "${MPI_COMPILE_CMDLINE}")
+ string(REGEX REPLACE "\nrm -f mpif.h$" "" MPI_LINK_CMDLINE "${MPI_LINK_CMDLINE}")
endif()
+ 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()
+ # If Intel MPI was configured for static linkage with -static_mpi, the wrapper will by default strip
+ # debug information from resulting binaries (see I_MPI_DEBUG_INFO_STRIP).
+ # Since we cannot process this information into CMake logic, we need to discard the resulting objcopy
+ # commands from the output.
+ string(REGEX REPLACE "(^|\n)objcopy[^\n]+(\n|$)" "" MPI_COMPILE_CMDLINE "${MPI_COMPILE_CMDLINE}")
+ string(REGEX REPLACE "(^|\n)objcopy[^\n]+(\n|$)" "" MPI_LINK_CMDLINE "${MPI_LINK_CMDLINE}")
+ endif()
+
+ # For Visual C++, extracting compiler options in a generic fashion isn't easy. However, no MPI implementation
+ # on Windows seems to require any specific ones, either.
+ if(NOT MSVC)
+ # Extract compile options from the compile command line.
+ string(REGEX MATCHALL "(^| )-f([^\" ]+|\"[^\"]+\")" MPI_ALL_COMPILE_OPTIONS "${MPI_COMPILE_CMDLINE}")
+
+ foreach(_MPI_COMPILE_OPTION IN LISTS MPI_ALL_COMPILE_OPTIONS)
+ string(REGEX REPLACE "^ " "" _MPI_COMPILE_OPTION "${_MPI_COMPILE_OPTION}")
+
+ # Ignore -fstack-protector directives: These occur on MPICH and MVAPICH when the libraries
+ # themselves were built with this flag. However, this flag is unrelated to using MPI, and
+ # we won't match the accompanying --param-ssp-size and -Wp,-D_FORTIFY_SOURCE flags and therefore
+ # produce inconsistent results with the regularly flags.
+ # Similarly, aliasing flags do not belong into our flag array.
+ if(NOT "${_MPI_COMPILE_OPTION}" MATCHES "^-f((no-|)(stack-protector|strict-aliasing)|PI[CE]|pi[ce])")
+ list(APPEND MPI_COMPILE_OPTIONS_WORK "${_MPI_COMPILE_OPTION}")
+ endif()
+ endforeach()
+ endif()
+
+ # For GNU-style compilers, it's possible to prefix includes and definitions with certain flags to pass them
+ # only to the preprocessor. For CMake purposes, we need to treat, but ignore such scopings.
+ # Note that we do not support spaces between the arguments, i.e. -Wp,-I -Wp,/opt/mympi will not be parsed
+ # correctly. This form does not seem to occur in any common MPI implementation, however.
+ if(NOT MSVC)
+ set(_MPI_PREPROCESSOR_FLAG_REGEX "(-Wp,|-Xpreprocessor )?")
+ else()
+ set(_MPI_PREPROCESSOR_FLAG_REGEX "")
+ endif()
+
+ # Same deal as above, for the definitions.
+ string(REGEX MATCHALL "(^| )${_MPI_PREPROCESSOR_FLAG_REGEX}-D *([^\" ]+|\"[^\"]+\")" MPI_ALL_COMPILE_DEFINITIONS "${MPI_COMPILE_CMDLINE}")
+
+ foreach(_MPI_COMPILE_DEFINITION IN LISTS MPI_ALL_COMPILE_DEFINITIONS)
+ string(REGEX REPLACE "^ ?${_MPI_PREPROCESSOR_FLAG_REGEX}-D *" "" _MPI_COMPILE_DEFINITION "${_MPI_COMPILE_DEFINITION}")
+ string(REPLACE "\"" "" _MPI_COMPILE_DEFINITION "${_MPI_COMPILE_DEFINITION}")
+ if(NOT "${_MPI_COMPILE_DEFINITION}" MATCHES "^_FORTIFY_SOURCE.*")
+ list(APPEND MPI_COMPILE_DEFINITIONS_WORK "${_MPI_COMPILE_DEFINITION}")
+ endif()
+ endforeach()
+
+ # Extract include paths from compile command line
+ string(REGEX MATCHALL "(^| )${_MPI_PREPROCESSOR_FLAG_REGEX}${CMAKE_INCLUDE_FLAG_${LANG}} *([^\" ]+|\"[^\"]+\")"
+ MPI_ALL_INCLUDE_PATHS "${MPI_COMPILE_CMDLINE}")
+
+ # If extracting failed to work, we'll try using -showme:incdirs.
+ # Unlike before, we do this without the environment variables set up, but since only MPICH derivates are affected by any of them, and
+ # -showme:... is only supported by Open MPI and LAM/MPI, this isn't a concern.
+ if (NOT MPI_ALL_INCLUDE_PATHS)
+ _MPI_check_compiler(${LANG} "-showme:incdirs" MPI_INCDIRS_CMDLINE MPI_INCDIRS_COMPILER_RETURN)
+ if(MPI_INCDIRS_COMPILER_RETURN)
+ separate_arguments(MPI_ALL_INCLUDE_PATHS NATIVE_COMMAND "${MPI_INCDIRS_CMDLINE}")
+ endif()
+ endif()
+
+ foreach(_MPI_INCLUDE_PATH IN LISTS MPI_ALL_INCLUDE_PATHS)
+ string(REGEX REPLACE "^ ?${_MPI_PREPROCESSOR_FLAG_REGEX}${CMAKE_INCLUDE_FLAG_${LANG}} *" "" _MPI_INCLUDE_PATH "${_MPI_INCLUDE_PATH}")
+ string(REPLACE "\"" "" _MPI_INCLUDE_PATH "${_MPI_INCLUDE_PATH}")
+ get_filename_component(_MPI_INCLUDE_PATH "${_MPI_INCLUDE_PATH}" REALPATH)
+ list(APPEND MPI_INCLUDE_DIRS_WORK "${_MPI_INCLUDE_PATH}")
+ endforeach()
+
+ # The next step are linker flags and library directories. Here, we first take the flags given in raw -L or -LIBPATH: syntax.
+ string(REGEX MATCHALL "(^| )${CMAKE_LIBRARY_PATH_FLAG} *([^\" ]+|\"[^\"]+\")" MPI_DIRECT_LINK_PATHS "${MPI_LINK_CMDLINE}")
+ foreach(_MPI_LPATH IN LISTS MPI_DIRECT_LINK_PATHS)
+ string(REGEX REPLACE "(^| )${CMAKE_LIBRARY_PATH_FLAG} *" "" _MPI_LPATH "${_MPI_LPATH}")
+ list(APPEND MPI_ALL_LINK_PATHS "${_MPI_LPATH}")
+ endforeach()
+
+ # If the link commandline hasn't been filtered (e.g. when using MSVC and /link), we need to extract the relevant parts first.
+ if(NOT _MPI_FILTERED_LINK_INFORMATION)
+ string(REGEX MATCHALL "(^| )(-Wl,|-Xlinker +)([^\" ]+|\"[^\"]+\")" MPI_LINK_FLAGS "${MPI_LINK_CMDLINE}")
+
+ # In this case, we could also find some indirectly given linker paths, e.g. prefixed by -Xlinker or -Wl,
+ # Since syntaxes like -Wl,-L -Wl,/my/path/to/lib are also valid, we parse these paths by first removing -Wl, and -Xlinker
+ # from the list of filtered flags and then parse the remainder of the output.
+ string(REGEX REPLACE "(-Wl,|-Xlinker +)" "" MPI_LINK_FLAGS_RAW "${MPI_LINK_FLAGS}")
+
+ # Now we can parse the leftover output. Note that spaces can now be handled since the above example would reduce to
+ # -L /my/path/to/lib and can be extracted correctly.
+ string(REGEX MATCHALL "^(${CMAKE_LIBRARY_PATH_FLAG},? *|--library-path=)([^\" ]+|\"[^\"]+\")"
+ MPI_INDIRECT_LINK_PATHS "${MPI_LINK_FLAGS_RAW}")
+
+ foreach(_MPI_LPATH IN LISTS MPI_INDIRECT_LINK_PATHS)
+ string(REGEX REPLACE "^(${CMAKE_LIBRARY_PATH_FLAG},? *|--library-path=)" "" _MPI_LPATH "${_MPI_LPATH}")
+ list(APPEND MPI_ALL_LINK_PATHS "${_MPI_LPATH}")
+ endforeach()
+
+ # We need to remove the flags we extracted from the linker flag list now.
+ string(REGEX REPLACE "(^| )(-Wl,|-Xlinker +)(${CMAKE_LIBRARY_PATH_FLAG},? *(-Wl,|-Xlinker +)?|--library-path=)([^\" ]+|\"[^\"]+\")" ""
+ MPI_LINK_CMDLINE_FILTERED "${MPI_LINK_CMDLINE}")
+
+ # Some MPI implementations pass on options they themselves were built with. Since -z,noexecstack is a common
+ # hardening, we should strip it. In general, the -z options should be undesirable.
+ string(REGEX REPLACE "(^| )-Wl,-z(,[^ ]+| +-Wl,[^ ]+)" "" MPI_LINK_CMDLINE_FILTERED "${MPI_LINK_CMDLINE_FILTERED}")
+ string(REGEX REPLACE "(^| )-Xlinker +-z +-Xlinker +[^ ]+" "" MPI_LINK_CMDLINE_FILTERED "${MPI_LINK_CMDLINE_FILTERED}")
+
+ # We only consider options of the form -Wl or -Xlinker:
+ string(REGEX MATCHALL "(^| )(-Wl,|-Xlinker +)([^\" ]+|\"[^\"]+\")" MPI_ALL_LINK_FLAGS "${MPI_LINK_CMDLINE_FILTERED}")
+
+ # As a next step, we assemble the linker flags extracted in a preliminary flags string
+ foreach(_MPI_LINK_FLAG IN LISTS MPI_ALL_LINK_FLAGS)
+ string(STRIP "${_MPI_LINK_FLAG}" _MPI_LINK_FLAG)
+ if (MPI_LINK_FLAGS_WORK)
+ string(APPEND MPI_LINK_FLAGS_WORK " ${_MPI_LINK_FLAG}")
else()
- message(STATUS "Unable to determine MPI from MPI driver ${MPI_${lang}_COMPILER}")
- set(MPI_COMPILE_CMDLINE)
- set(MPI_LINK_CMDLINE)
+ set(MPI_LINK_FLAGS_WORK "${_MPI_LINK_FLAG}")
endif()
+ endforeach()
+ else()
+ # In the filtered case, we obtain the link time flags by just stripping the library paths.
+ string(REGEX REPLACE "(^| )${CMAKE_LIBRARY_PATH_FLAG} *([^\" ]+|\"[^\"]+\")" "" MPI_LINK_CMDLINE_FILTERED "${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 we failed to extract any linker paths, we'll try using the -showme:libdirs option with the MPI compiler.
+ # This will return a list of folders, not a set of flags!
+ if (NOT MPI_ALL_LINK_PATHS)
+ _MPI_check_compiler(${LANG} "-showme:libdirs" MPI_LIBDIRS_CMDLINE MPI_LIBDIRS_COMPILER_RETURN)
+ if(MPI_LIBDIRS_COMPILER_RETURN)
+ separate_arguments(MPI_ALL_LINK_PATHS NATIVE_COMMAND "${MPI_LIBDIRS_CMDLINE}")
+ endif()
+ endif()
- # 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)
+ # We need to remove potential quotes and convert the paths to CMake syntax while resolving them, too.
+ foreach(_MPI_LPATH IN LISTS MPI_ALL_LINK_PATHS)
+ string(REPLACE "\"" "" _MPI_LPATH "${_MPI_LPATH}")
+ get_filename_component(_MPI_LPATH "${_MPI_LPATH}" REALPATH)
+ list(APPEND MPI_LINK_DIRECTORIES_WORK "${_MPI_LPATH}")
+ endforeach()
- foreach(FLAG ${MPI_ALL_COMPILE_FLAGS})
- string(REGEX REPLACE "^ " "" FLAG ${FLAG})
- if (MPI_COMPILE_FLAGS_WORK)
- string(APPEND MPI_COMPILE_FLAGS_WORK " ${FLAG}")
- else()
- set(MPI_COMPILE_FLAGS_WORK ${FLAG})
- endif()
- endforeach()
+ # Extract the set of libraries to link against from the link command line
+ # This only makes sense if CMAKE_LINK_LIBRARY_FLAG is defined, i.e. a -lxxxx syntax is supported by the compiler.
+ if(CMAKE_LINK_LIBRARY_FLAG)
+ string(REGEX MATCHALL "(^| )${CMAKE_LINK_LIBRARY_FLAG}([^\" ]+|\"[^\"]+\")"
+ MPI_LIBNAMES "${MPI_LINK_CMDLINE}")
+
+ foreach(_MPI_LIB_NAME IN LISTS MPI_LIBNAMES)
+ string(REGEX REPLACE "^ ?${CMAKE_LINK_LIBRARY_FLAG}" "" _MPI_LIB_NAME "${_MPI_LIB_NAME}")
+ string(REPLACE "\"" "" _MPI_LIB_NAME "${_MPI_LIB_NAME}")
+ list(APPEND MPI_LIB_NAMES_WORK "${_MPI_LIB_NAME}")
+ endforeach()
+ endif()
- # Extract include paths from compile command line
- string(REGEX MATCHALL "(^| )-I([^\" ]+|\"[^\"]+\")" MPI_ALL_INCLUDE_PATHS "${MPI_COMPILE_CMDLINE}")
- set(MPI_INCLUDE_PATH_WORK)
+ # Treat linker objects given by full path, for example static libraries, import libraries
+ # or shared libraries if there aren't any import libraries in use on the system.
+ # Note that we do not consider CMAKE_<TYPE>_LIBRARY_PREFIX intentionally here: The linker will for a given file
+ # decide how to link it based on file type, not based on a prefix like 'lib'.
+ set(_MPI_LIB_SUFFIX_REGEX "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ if(DEFINED CMAKE_IMPORT_LIBRARY_SUFFIX)
+ if(NOT ("${CMAKE_IMPORT_LIBRARY_SUFFIX}" STREQUAL "${CMAKE_STATIC_LIBRARY_SUFFIX}"))
+ string(APPEND _MPI_SUFFIX_REGEX "|${CMAKE_IMPORT_LIBRARY_SUFFIX}")
+ endif()
+ else()
+ string(APPEND _MPI_LIB_SUFFIX_REGEX "|${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ endif()
+ set(_MPI_LIB_NAME_REGEX "(([^\" ]+(${_MPI_LIB_SUFFIX_REGEX}))|(\"[^\"]+(${_MPI_LIB_SUFFIX_REGEX})\"))( +|$)")
+ string(REPLACE "." "\\." _MPI_LIB_NAME_REGEX "${_MPI_LIB_NAME_REGEX}")
+
+ string(REGEX MATCHALL "${_MPI_LIB_NAME_REGEX}" MPI_LIBNAMES "${MPI_LINK_CMDLINE}")
+ foreach(_MPI_LIB_NAME IN LISTS MPI_LIBNAMES)
+ string(REGEX REPLACE "^ +\"?|\"? +$" "" _MPI_LIB_NAME "${_MPI_LIB_NAME}")
+ get_filename_component(_MPI_LIB_PATH "${_MPI_LIB_NAME}" DIRECTORY)
+ if(NOT "${_MPI_LIB_PATH}" STREQUAL "")
+ list(APPEND MPI_LIB_FULLPATHS_WORK "${_MPI_LIB_NAME}")
+ else()
+ list(APPEND MPI_LIB_NAMES_WORK "${_MPI_LIB_NAME}")
+ endif()
+ endforeach()
- foreach(IPATH ${MPI_ALL_INCLUDE_PATHS})
- string(REGEX REPLACE "^ ?-I" "" IPATH ${IPATH})
- string(REPLACE "//" "/" IPATH ${IPATH})
- string(REPLACE "\"" "" IPATH ${IPATH})
- file(TO_CMAKE_PATH "${IPATH}" IPATH)
- list(APPEND MPI_INCLUDE_PATH_WORK ${IPATH})
- endforeach()
+ # Save the explicitly given link directories
+ set(MPI_LINK_DIRECTORIES_LEFTOVER "${MPI_LINK_DIRECTORIES_WORK}")
- # 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()
+ # An MPI compiler wrapper could have its MPI libraries in the implictly
+ # linked directories of the compiler itself.
+ if(DEFINED CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES)
+ list(APPEND MPI_LINK_DIRECTORIES_WORK "${CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES}")
+ 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()
+ # Determine full path names for all of the libraries that one needs
+ # to link against in an MPI program
+ unset(MPI_PLAIN_LIB_NAMES_WORK)
+ foreach(_MPI_LIB_NAME IN LISTS MPI_LIB_NAMES_WORK)
+ get_filename_component(_MPI_PLAIN_LIB_NAME "${_MPI_LIB_NAME}" NAME_WE)
+ list(APPEND MPI_PLAIN_LIB_NAMES_WORK "${_MPI_PLAIN_LIB_NAME}")
+ find_library(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY
+ NAMES "${_MPI_LIB_NAME}" "lib${_MPI_LIB_NAME}"
+ HINTS ${MPI_LINK_DIRECTORIES_WORK}
+ DOC "Location of the ${_MPI_PLAIN_LIB_NAME} library for MPI"
+ )
+ mark_as_advanced(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY)
+ # Remove the directory from the remainder list.
+ if(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY)
+ get_filename_component(_MPI_TAKEN_DIRECTORY "${MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY}" DIRECTORY)
+ list(REMOVE_ITEM MPI_LINK_DIRECTORIES_LEFTOVER "${_MPI_TAKEN_DIRECTORY}")
+ endif()
+ endforeach()
- # Extract linker paths from the link command line
- string(REGEX MATCHALL "(^| |-Wl,)(-L|/LIBPATH:)([^\" ]+|\"[^\"]+\")" MPI_ALL_LINK_PATHS "${MPI_LINK_CMDLINE}")
- set(MPI_LINK_PATH)
- foreach(LPATH ${MPI_ALL_LINK_PATHS})
- string(REGEX REPLACE "^(| |-Wl,)(-L|/LIBPATH:)" "" LPATH ${LPATH})
- string(REPLACE "//" "/" LPATH ${LPATH})
- list(APPEND MPI_LINK_PATH ${LPATH})
- endforeach()
+ # Add the link directories given explicitly that we haven't used back as linker directories.
+ if(NOT WIN32)
+ foreach(_MPI_LINK_DIRECTORY IN LISTS MPI_LINK_DIRECTORIES_LEFTOVER)
+ file(TO_NATIVE_PATH "${_MPI_LINK_DIRECTORY}" _MPI_LINK_DIRECTORY_ACTUAL)
+ string(FIND "${_MPI_LINK_DIRECTORY_ACTUAL}" " " _MPI_LINK_DIRECTORY_CONTAINS_SPACE)
+ if(NOT _MPI_LINK_DIRECTORY_CONTAINS_SPACE EQUAL -1)
+ set(_MPI_LINK_DIRECTORY_ACTUAL "\"${_MPI_LINK_DIRECTORY_ACTUAL}\"")
+ endif()
+ if(MPI_LINK_FLAGS_WORK)
+ string(APPEND MPI_LINK_FLAGS_WORK " ${CMAKE_LIBRARY_PATH_FLAG}${_MPI_LINK_DIRECTORY_ACTUAL}")
+ else()
+ set(MPI_LINK_FLAGS_WORK "${CMAKE_LIBRARY_PATH_FLAG}${_MPI_LINK_DIRECTORY_ACTUAL}")
+ endif()
+ endforeach()
+ endif()
- # 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()
+ # Deal with the libraries given with full path next
+ unset(MPI_DIRECT_LIB_NAMES_WORK)
+ foreach(_MPI_LIB_FULLPATH IN LISTS MPI_LIB_FULLPATHS_WORK)
+ get_filename_component(_MPI_PLAIN_LIB_NAME "${_MPI_LIB_FULLPATH}" NAME_WE)
+ list(APPEND MPI_DIRECT_LIB_NAMES_WORK "${_MPI_PLAIN_LIB_NAME}")
+ set(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY "${_MPI_LIB_FULLPATH}" CACHE FILEPATH "Location of the ${_MPI_PLAIN_LIB_NAME} library for MPI")
+ mark_as_advanced(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY)
+ endforeach()
+ # Directly linked objects should be linked first in case some generic linker flags are needed for them.
+ if(MPI_DIRECT_LIB_NAMES_WORK)
+ set(MPI_PLAIN_LIB_NAMES_WORK "${MPI_DIRECT_LIB_NAMES_WORK};${MPI_PLAIN_LIB_NAMES_WORK}")
+ endif()
- # Extract linker flags from the link command line
- string(REGEX MATCHALL "(^| )(-Wl,|-Xlinker )([^\" ]+|\"[^\"]+\")" MPI_ALL_LINK_FLAGS "${MPI_LINK_CMDLINE}")
- set(MPI_LINK_FLAGS_WORK)
- foreach(FLAG ${MPI_ALL_LINK_FLAGS})
- string(REGEX REPLACE "^ " "" FLAG ${FLAG})
- if (MPI_LINK_FLAGS_WORK)
- string(APPEND MPI_LINK_FLAGS_WORK " ${FLAG}")
- else()
- set(MPI_LINK_FLAGS_WORK ${FLAG})
- endif()
- endforeach()
+ # MPI might require pthread to work. The above mechanism wouldn't detect it, but we need to
+ # link it in that case. -lpthread is covered by the normal library treatment on the other hand.
+ if("${MPI_COMPILE_CMDLINE}" MATCHES "-pthread")
+ list(APPEND MPI_COMPILE_OPTIONS_WORK "-pthread")
+ if(MPI_LINK_FLAGS_WORK)
+ string(APPEND MPI_LINK_FLAGS_WORK " -pthread")
+ else()
+ set(MPI_LINK_FLAGS_WORK "-pthread")
+ endif()
+ endif()
+
+ if(MPI_${LANG}_EXTRA_COMPILE_DEFINITIONS)
+ list(APPEND MPI_COMPILE_DEFINITIONS_WORK "${MPI_${LANG}_EXTRA_COMPILE_DEFINITIONS}")
+ endif()
+ if(MPI_${LANG}_EXTRA_COMPILE_OPTIONS)
+ list(APPEND MPI_COMPILE_OPTIONS_WORK "${MPI_${LANG}_EXTRA_COMPILE_OPTIONS}")
+ endif()
+ if(MPI_${LANG}_EXTRA_LIB_NAMES)
+ list(APPEND MPI_PLAIN_LIB_NAMES_WORK "${MPI_${LANG}_EXTRA_LIB_NAMES}")
+ endif()
+
+ # If we found MPI, set up all of the appropriate cache entries
+ if(NOT MPI_${LANG}_COMPILE_OPTIONS)
+ set(MPI_${LANG}_COMPILE_OPTIONS ${MPI_COMPILE_OPTIONS_WORK} CACHE STRING "MPI ${LANG} compilation options" FORCE)
+ endif()
+ if(NOT MPI_${LANG}_COMPILE_DEFINITIONS)
+ set(MPI_${LANG}_COMPILE_DEFINITIONS ${MPI_COMPILE_DEFINITIONS_WORK} CACHE STRING "MPI ${LANG} compilation definitions" FORCE)
+ endif()
+ if(NOT MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)
+ set(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS ${MPI_INCLUDE_DIRS_WORK} CACHE STRING "MPI ${LANG} additional include directories" FORCE)
+ endif()
+ if(NOT MPI_${LANG}_LINK_FLAGS)
+ set(MPI_${LANG}_LINK_FLAGS ${MPI_LINK_FLAGS_WORK} CACHE STRING "MPI ${LANG} linker flags" FORCE)
+ endif()
+ if(NOT MPI_${LANG}_LIB_NAMES)
+ set(MPI_${LANG}_LIB_NAMES ${MPI_PLAIN_LIB_NAMES_WORK} CACHE STRING "MPI ${LANG} libraries to link against" FORCE)
+ endif()
+ set(MPI_${LANG}_WRAPPER_FOUND TRUE PARENT_SCOPE)
+endfunction()
- # Extract the set of libraries to link against from the link command
- # line
- string(REGEX MATCHALL "(^| )-l([^\" ]+|\"[^\"]+\")" MPI_LIBNAMES "${MPI_LINK_CMDLINE}")
- if(WIN32)
- # The intel wrappers on windows link against static versions of the MPI libraries.
- # The static libraries are simply listed on the command line without -l.
- # For instance: " icl ... impi.lib "
- string(REGEX MATCHALL "(^| )([^\" ]+)\\.lib" tmp "${MPI_LINK_CMDLINE}")
- list(APPEND MPI_LIBNAMES ${tmp})
+function(_MPI_guess_settings LANG)
+ set(MPI_GUESS_FOUND FALSE)
+ # Currently only MSMPI and MPICH2 on Windows are supported, so we can skip this search if we're not targeting that.
+ if(WIN32)
+ # MSMPI
+
+ # The environment variables MSMPI_INC and MSMPILIB32/64 are the only ways of locating the MSMPI_SDK,
+ # which is installed separately from the runtime. Thus it's possible to have mpiexec but not MPI headers
+ # or import libraries and vice versa.
+ if(NOT MPI_GUESS_LIBRARY_NAME OR "${MPI_GUESS_LIBRARY_NAME}" STREQUAL "MSMPI")
+ # We first attempt to locate the msmpi.lib. Should be find it, we'll assume that the MPI present is indeed
+ # Microsoft MPI.
+ if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
+ set(MPI_MSMPI_LIB_PATH "$ENV{MSMPI_LIB64}")
+ set(MPI_MSMPI_INC_PATH_EXTRA "$ENV{MSMPI_INC}/x64")
+ else()
+ set(MPI_MSMPI_LIB_PATH "$ENV{MSMPI_LIB32}")
+ set(MPI_MSMPI_INC_PATH_EXTRA "$ENV{MSMPI_INC}/x86")
+ endif()
+
+ find_library(MPI_msmpi_LIBRARY
+ NAMES msmpi
+ HINTS ${MPI_MSMPI_LIB_PATH}
+ DOC "Location of the msmpi library for Microsoft MPI")
+ mark_as_advanced(MPI_msmpi_LIBRARY)
+
+ if(MPI_msmpi_LIBRARY)
+ # Next, we attempt to locate the MPI header. Note that for Fortran we know that mpif.h is a way
+ # MSMPI can be used and therefore that header has to be present.
+ if(NOT MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)
+ get_filename_component(MPI_MSMPI_INC_DIR "$ENV{MSMPI_INC}" REALPATH)
+ set(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS "${MPI_MSMPI_INC_DIR}" CACHE STRING "MPI ${LANG} additional include directories" FORCE)
+ unset(MPI_MSMPI_INC_DIR)
endif()
- # 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)
- string(APPEND 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})
- if(WIN32)
- string(REGEX REPLACE "\\.lib$" "" LIB ${LIB})
+ # For MSMPI, one can compile the MPI module by building the mpi.f90 shipped with the MSMPI SDK,
+ # thus it might be present or provided by the user. Figuring out which is supported is done later on.
+ # The PGI Fortran compiler for instance ships a prebuilt set of modules in its own include folder.
+ # Should a user be employing PGI or have built its own set and provided it via cache variables, the
+ # splitting routine would have located the module files.
+
+ # For C and C++, we're done here (MSMPI does not ship the MPI-2 C++ bindings) - however, for Fortran
+ # we need some extra library to glue Fortran support together:
+ # MSMPI ships 2-4 Fortran libraries, each for different Fortran compiler behaviors. The library names
+ # ending with a c are using the cdecl calling convention, whereas those ending with an s are for Fortran
+ # implementations using stdcall. Therefore, the 64-bit MSMPI only ships those ending in 'c', whereas the 32-bit
+ # has both variants available.
+ # The second difference is the last but one letter, if it's an e(nd), the length of a string argument is
+ # passed by the Fortran compiler after all other arguments on the parameter list, if it's an m(ixed),
+ # it's passed immediately after the string address.
+
+ # To summarize:
+ # - msmpifec: CHARACTER length passed after the parameter list and using cdecl calling convention
+ # - msmpifmc: CHARACTER length passed directly after string address and using cdecl calling convention
+ # - msmpifes: CHARACTER length passed after the parameter list and using stdcall calling convention
+ # - msmpifms: CHARACTER length passed directly after string address and using stdcall calling convention
+ # 32-bit MSMPI ships all four libraries, 64-bit MSMPI ships only the first two.
+
+ # As is, Intel Fortran and PGI Fortran both use the 'ec' variant of the calling convention, whereas
+ # the old Compaq Visual Fortran compiler defaulted to the 'ms' version. It's possible to make Intel Fortran
+ # use the CVF calling convention using /iface:cvf, but we assume - and this is also assumed in FortranCInterface -
+ # this isn't the case. It's also possible to make CVF use the 'ec' variant, using /iface=(cref,nomixed_str_len_arg).
+
+ # Our strategy is now to locate all libraries, but enter msmpifec into the LIB_NAMES array.
+ # Should this not be adequate it's a straightforward way for a user to change the LIB_NAMES array and
+ # have his library found. Still, this should not be necessary outside of exceptional cases, as reasoned.
+ if ("${LANG}" STREQUAL "Fortran")
+ set(MPI_MSMPI_CALLINGCONVS c)
+ if("${CMAKE_SIZEOF_VOID_P}" EQUAL 4)
+ list(APPEND MPI_MSMPI_CALLINGCONVS s)
endif()
- string(STRIP ${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}")
+ foreach(mpistrlenpos IN ITEMS e m)
+ foreach(mpicallingconv IN LISTS MPI_MSMPI_CALLINGCONVS)
+ find_library(MPI_msmpif${mpistrlenpos}${mpicallingconv}_LIBRARY
+ NAMES msmpif${mpistrlenpos}${mpicallingconv}
+ HINTS "${MPI_MSMPI_LIB_PATH}"
+ DOC "Location of the msmpi${mpistrlenpos}${mpicallingconv} library for Microsoft MPI")
+ mark_as_advanced(MPI_msmpif${mpistrlenpos}${mpicallingconv}_LIBRARY)
+ endforeach()
+ endforeach()
+ if(NOT MPI_${LANG}_LIB_NAMES)
+ set(MPI_${LANG}_LIB_NAMES "msmpi;msmpifec" CACHE STRING "MPI ${LANG} libraries to link against" FORCE)
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")
+ # At this point we're *not* done. MSMPI requires an additional include file for Fortran giving the value
+ # of MPI_AINT. This file is called mpifptr.h located in the x64 and x86 subfolders, respectively.
+ find_path(MPI_mpifptr_INCLUDE_DIR
+ NAMES "mpifptr.h"
+ HINTS "${MPI_MSMPI_INC_PATH_EXTRA}"
+ DOC "Location of the mpifptr.h extra header for Microsoft MPI")
+ if(NOT MPI_${LANG}_ADDITIONAL_INCLUDE_VARS)
+ set(MPI_${LANG}_ADDITIONAL_INCLUDE_VARS "mpifptr" CACHE STRING "MPI ${LANG} additional include directory variables, given in the form MPI_<name>_INCLUDE_DIR." FORCE)
+ endif()
+ mark_as_advanced(MPI_${LANG}_ADDITIONAL_INCLUDE_VARS MPI_mpifptr_INCLUDE_DIR)
+ else()
+ if(NOT MPI_${LANG}_LIB_NAMES)
+ set(MPI_${LANG}_LIB_NAMES "msmpi" CACHE STRING "MPI ${LANG} libraries to link against" FORCE)
+ endif()
endif()
- endif()
+ mark_as_advanced(MPI_${LANG}_LIB_NAMES)
+ set(MPI_GUESS_FOUND TRUE)
- 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 x64)
- set(MS_MPI_ARCH_DIR2 amd64)
- else()
- set(MS_MPI_ARCH_DIR x86)
- set(MS_MPI_ARCH_DIR2 i386)
+ if(_MPIEXEC_NOT_GIVEN)
+ unset(MPIEXEC_EXECUTABLE CACHE)
+ endif()
+
+ find_program(MPIEXEC_EXECUTABLE
+ NAMES mpiexec
+ HINTS $ENV{MSMPI_BIN} "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MPI;InstallRoot]/Bin"
+ DOC "Executable for running MPI programs.")
endif()
+ endif()
+
+ # At this point there's not many MPIs that we could still consider.
+ # OpenMPI 1.6.x and below supported Windows, but these ship compiler wrappers that still work.
+ # The only other relevant MPI implementation without a wrapper is MPICH2, which had Windows support in 1.4.1p1 and older.
+ if(NOT MPI_GUESS_FOUND AND (NOT MPI_GUESS_LIBRARY_NAME OR "${MPI_GUESS_LIBRARY_NAME}" STREQUAL "MPICH2"))
+ set(MPI_MPICH_PREFIX_PATHS
+ "$ENV{ProgramW6432}/MPICH2/lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH\\SMPD;binary]/../lib"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH2;Path]/lib"
+ )
- 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} Lib/${MS_MPI_ARCH_DIR2})
- 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})
+ # All of C, C++ and Fortran will need mpi.lib, so we'll look for this first
+ find_library(MPI_mpi_LIBRARY
+ NAMES mpi
+ HINTS ${MPI_MPICH_PREFIX_PATHS})
+ mark_as_advanced(MPI_mpi_LIBRARY)
+ # If we found mpi.lib, we detect the rest of MPICH2
+ if(MPI_mpi_LIBRARY)
+ set(MPI_MPICH_LIB_NAMES "mpi")
+ # If MPI-2 C++ bindings are requested, we need to locate cxx.lib as well.
+ # Otherwise, MPICH_SKIP_MPICXX will be defined and these bindings aren't needed.
+ if("${LANG}" STREQUAL "CXX" AND NOT MPI_CXX_SKIP_MPICXX)
+ find_library(MPI_cxx_LIBRARY
+ NAMES cxx
+ HINTS ${MPI_MPICH_PREFIX_PATHS})
+ mark_as_advanced(MPI_cxx_LIBRARY)
+ list(APPEND MPI_MPICH_LIB_NAMES "cxx")
+ # For Fortran, MPICH2 provides three different libraries:
+ # fmpich2.lib which uses uppercase symbols and cdecl,
+ # fmpich2s.lib which uses uppercase symbols and stdcall (32-bit only),
+ # fmpich2g.lib which uses lowercase symbols with double underscores and cdecl.
+ # fmpich2s.lib would be useful for Compaq Visual Fortran, fmpich2g.lib has to be used with GNU g77 and is also
+ # provided in the form of an .a archive for MinGW and Cygwin. From our perspective, fmpich2.lib is the only one
+ # we need to try, and if it doesn't work with the given Fortran compiler we'd find out later on during validation
+ elseif("${LANG}" STREQUAL "Fortran")
+ find_library(MPI_fmpich2_LIBRARY
+ NAMES fmpich2
+ HINTS ${MPI_MPICH_PREFIX_PATHS})
+ find_library(MPI_fmpich2s_LIBRARY
+ NAMES fmpich2s
+ HINTS ${MPI_MPICH_PREFIX_PATHS})
+ find_library(MPI_fmpich2g_LIBRARY
+ NAMES fmpich2g
+ HINTS ${MPI_MPICH_PREFIX_PATHS})
+ mark_as_advanced(MPI_fmpich2_LIBRARY MPI_fmpich2s_LIBRARY MPI_fmpich2g_LIBRARY)
+ list(APPEND MPI_MPICH_LIB_NAMES "fmpich2")
+ endif()
+
+ if(NOT MPI_${LANG}_LIB_NAMES)
+ set(MPI_${LANG}_LIB_NAMES "${MPI_MPICH_LIB_NAMES}" CACHE STRING "MPI ${LANG} libraries to link against" FORCE)
+ endif()
+ unset(MPI_MPICH_LIB_NAMES)
+
+ if(NOT MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)
+ # For MPICH2, the include folder would be in ../include relative to the library folder.
+ get_filename_component(MPI_MPICH_ROOT_DIR "${MPI_mpi_LIBRARY}" DIRECTORY)
+ get_filename_component(MPI_MPICH_ROOT_DIR "${MPI_MPICH_ROOT_DIR}" DIRECTORY)
+ if(IS_DIRECTORY "${MPI_MPICH_ROOT_DIR}/include")
+ set(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS "${MPI_MPICH_ROOT_DIR}/include" CACHE STRING "MPI ${LANG} additional include directory variables, given in the form MPI_<name>_INCLUDE_DIR." FORCE)
+ endif()
+ unset(MPI_MPICH_ROOT_DIR)
+ endif()
+ set(MPI_GUESS_FOUND TRUE)
+
+ if(_MPIEXEC_NOT_GIVEN)
+ unset(MPIEXEC_EXECUTABLE CACHE)
endif()
- endif()
- if (NOT MPI_LIBRARIES_WORK)
- set(MPI_LIBRARIES_WORK "MPI_${lang}_LIBRARIES-NOTFOUND")
+ find_program(MPIEXEC_EXECUTABLE
+ NAMES ${_MPIEXEC_NAMES}
+ HINTS "$ENV{ProgramW6432}/MPICH2/bin"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH\\SMPD;binary]"
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MPICH2;Path]/bin"
+ DOC "Executable for running MPI programs.")
endif()
+ unset(MPI_MPICH_PREFIX_PATHS)
endif()
+ endif()
+ set(MPI_${LANG}_GUESS_FOUND "${MPI_GUESS_FOUND}" PARENT_SCOPE)
+endfunction()
- # 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)
+function(_MPI_adjust_compile_definitions LANG)
+ if("${LANG}" STREQUAL "CXX")
+ # To disable the C++ bindings, we need to pass some definitions since the mpi.h header has to deal with both C and C++
+ # bindings in MPI-2.
+ if(MPI_CXX_SKIP_MPICXX AND NOT MPI_${LANG}_COMPILE_DEFINITIONS MATCHES "SKIP_MPICXX")
+ # MPICH_SKIP_MPICXX is being used in MPICH and derivatives like MVAPICH or Intel MPI
+ # OMPI_SKIP_MPICXX is being used in Open MPI
+ # _MPICC_H is being used for IBM Platform MPI
+ list(APPEND MPI_${LANG}_COMPILE_DEFINITIONS "MPICH_SKIP_MPICXX" "OMPI_SKIP_MPICXX" "_MPICC_H")
+ set(MPI_${LANG}_COMPILE_DEFINITIONS "${MPI_${LANG}_COMPILE_DEFINITIONS}" CACHE STRING "MPI ${LANG} compilation definitions" FORCE)
+ endif()
+ endif()
+endfunction()
- # clear out our temporary lib/header detection 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)
+macro(_MPI_assemble_libraries LANG)
+ set(MPI_${LANG}_LIBRARIES "")
+ # Only for libraries do we need to check whether the compiler's linking stage is separate.
+ if(NOT "${MPI_${LANG}_COMPILER}" STREQUAL "${CMAKE_${LANG}_COMPILER}" OR NOT MPI_${LANG}_WORKS_IMPLICIT)
+ foreach(mpilib IN LISTS MPI_${LANG}_LIB_NAMES)
+ list(APPEND MPI_${LANG}_LIBRARIES ${MPI_${mpilib}_LIBRARY})
+ endforeach()
endif()
+endmacro()
- # 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)
+macro(_MPI_assemble_include_dirs LANG)
+ if("${MPI_${LANG}_COMPILER}" STREQUAL "${CMAKE_${LANG}_COMPILER}")
+ set(MPI_${LANG}_INCLUDE_DIRS "")
else()
- set(MPI_${lang}_FOUND FALSE PARENT_SCOPE)
+ set(MPI_${LANG}_INCLUDE_DIRS "${MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS}")
+ if("${LANG}" MATCHES "(C|CXX)")
+ if(MPI_${LANG}_HEADER_DIR)
+ list(APPEND MPI_${LANG}_INCLUDE_DIRS "${MPI_${LANG}_HEADER_DIR}")
+ endif()
+ else() # Fortran
+ if(MPI_${LANG}_F77_HEADER_DIR)
+ list(APPEND MPI_${LANG}_INCLUDE_DIRS "${MPI_${LANG}_F77_HEADER_DIR}")
+ endif()
+ if(MPI_${LANG}_MODULE_DIR AND NOT "${MPI_${LANG}_MODULE_DIR}" IN_LIST MPI_${LANG}_INCLUDE_DIRS)
+ list(APPEND MPI_${LANG}_INCLUDE_DIRS "${MPI_${LANG}_MODULE_DIR}")
+ endif()
+ endif()
+ if(MPI_${LANG}_ADDITIONAL_INCLUDE_VARS)
+ foreach(MPI_ADDITIONAL_INC_DIR IN LISTS MPI_${LANG}_ADDITIONAL_INCLUDE_VARS)
+ list(APPEND MPI_${LANG}_INCLUDE_DIRS "${MPI_${MPI_ADDITIONAL_INC_DIR}_INCLUDE_DIR}")
+ endforeach()
+ endif()
+ endif()
+endmacro()
+
+function(_MPI_split_include_dirs LANG)
+ if("${MPI_${LANG}_COMPILER}" STREQUAL "${CMAKE_${LANG}_COMPILER}")
+ return()
+ endif()
+ # Backwards compatibility: Search INCLUDE_PATH if given.
+ if(MPI_${LANG}_INCLUDE_PATH)
+ list(APPEND MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS "${MPI_${LANG}_INCLUDE_PATH}")
+ endif()
+
+ # We try to find the headers/modules among those paths (and system paths)
+ # For C/C++, we just need to have a look for mpi.h.
+ if("${LANG}" MATCHES "(C|CXX)")
+ find_path(MPI_${LANG}_HEADER_DIR "mpi.h"
+ HINTS ${MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS}
+ )
+ mark_as_advanced(MPI_${LANG}_HEADER_DIR)
+ if(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)
+ list(REMOVE_ITEM MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS "${MPI_${LANG}_HEADER_DIR}")
+ endif()
+ # Fortran is more complicated here: An implementation could provide
+ # any of the Fortran 77/90/2008 APIs for MPI. For example, MSMPI
+ # only provides Fortran 77 and - if mpi.f90 is built - potentially
+ # a Fortran 90 module.
+ elseif("${LANG}" STREQUAL "Fortran")
+ find_path(MPI_${LANG}_F77_HEADER_DIR "mpif.h"
+ HINTS ${MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS}
+ )
+ find_path(MPI_${LANG}_MODULE_DIR
+ NAMES "mpi.mod" "mpi_f08.mod"
+ HINTS ${MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS}
+ )
+ if(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)
+ list(REMOVE_ITEM MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS
+ "${MPI_${LANG}_F77_HEADER_DIR}"
+ "${MPI_${LANG}_MODULE_DIR}"
+ )
+ endif()
+ mark_as_advanced(MPI_${LANG}_F77_HEADER_DIR MPI_${LANG}_MODULE_DIR)
+ endif()
+ # Remove duplicates and default system directories from the list.
+ if(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)
+ list(REMOVE_DUPLICATES MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)
+ foreach(MPI_IMPLICIT_INC_DIR IN LISTS CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES)
+ list(REMOVE_ITEM MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS ${MPI_IMPLICIT_INC_DIR})
+ endforeach()
endif()
+ set(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS ${MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS} CACHE STRING "MPI ${LANG} additional include directories" FORCE)
endfunction()
+macro(_MPI_create_imported_target LANG)
+ if(NOT TARGET MPI::MPI_${LANG})
+ add_library(MPI::MPI_${LANG} INTERFACE IMPORTED)
+ endif()
+
+ # When this is consumed for compiling CUDA, use '-Xcompiler' to wrap '-pthread'.
+ string(REPLACE "-pthread" "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler >-pthread"
+ _MPI_${LANG}_COMPILE_OPTIONS "${MPI_${LANG}_COMPILE_OPTIONS}")
+ set_property(TARGET MPI::MPI_${LANG} PROPERTY INTERFACE_COMPILE_OPTIONS "${_MPI_${LANG}_COMPILE_OPTIONS}")
+ unset(_MPI_${LANG}_COMPILE_OPTIONS)
+
+ set_property(TARGET MPI::MPI_${LANG} PROPERTY INTERFACE_COMPILE_DEFINITIONS "${MPI_${LANG}_COMPILE_DEFINITIONS}")
-# 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")
+ if(MPI_${LANG}_LINK_FLAGS)
+ set_property(TARGET MPI::MPI_${LANG} PROPERTY INTERFACE_LINK_OPTIONS "SHELL:${MPI_${LANG}_LINK_FLAGS}")
+ endif()
+ # If the compiler links MPI implicitly, no libraries will be found as they're contained within
+ # CMAKE_<LANG>_IMPLICIT_LINK_LIBRARIES already.
+ if(MPI_${LANG}_LIBRARIES)
+ set_property(TARGET MPI::MPI_${LANG} PROPERTY INTERFACE_LINK_LIBRARIES "${MPI_${LANG}_LIBRARIES}")
+ endif()
+ # Given the new design of FindMPI, INCLUDE_DIRS will always be located, even under implicit linking.
+ set_property(TARGET MPI::MPI_${LANG} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${MPI_${LANG}_INCLUDE_DIRS}")
+endmacro()
+
+function(_MPI_try_staged_settings LANG MPI_TEST_FILE_NAME MODE RUN_BINARY SUPPRESS_ERRORS)
+ set(WORK_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindMPI")
+ set(SRC_DIR "${CMAKE_ROOT}/Modules/FindMPI")
+ set(BIN_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindMPI/${MPI_TEST_FILE_NAME}_${LANG}.bin")
+ unset(MPI_TEST_COMPILE_DEFINITIONS)
+ if("${LANG}" STREQUAL "Fortran")
+ if("${MODE}" STREQUAL "F90_MODULE")
+ set(MPI_Fortran_INCLUDE_LINE "use mpi\n implicit none")
+ elseif("${MODE}" STREQUAL "F08_MODULE")
+ set(MPI_Fortran_INCLUDE_LINE "use mpi_f08\n implicit none")
+ else() # F77 header
+ set(MPI_Fortran_INCLUDE_LINE "implicit none\n include 'mpif.h'")
+ endif()
+ configure_file("${SRC_DIR}/${MPI_TEST_FILE_NAME}.f90.in" "${WORK_DIR}/${MPI_TEST_FILE_NAME}.f90" @ONLY)
+ set(MPI_TEST_SOURCE_FILE "${WORK_DIR}/${MPI_TEST_FILE_NAME}.f90")
+ elseif("${LANG}" STREQUAL "CXX")
+ configure_file("${SRC_DIR}/${MPI_TEST_FILE_NAME}.c" "${WORK_DIR}/${MPI_TEST_FILE_NAME}.cpp" COPYONLY)
+ set(MPI_TEST_SOURCE_FILE "${WORK_DIR}/${MPI_TEST_FILE_NAME}.cpp")
+ if("${MODE}" STREQUAL "TEST_MPICXX")
+ set(MPI_TEST_COMPILE_DEFINITIONS TEST_MPI_MPICXX)
+ endif()
+ else() # C
+ set(MPI_TEST_SOURCE_FILE "${SRC_DIR}/${MPI_TEST_FILE_NAME}.c")
+ endif()
+ if(RUN_BINARY)
+ try_run(MPI_RUN_RESULT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE} MPI_RESULT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE}
+ "${CMAKE_BINARY_DIR}" SOURCES "${MPI_TEST_SOURCE_FILE}"
+ COMPILE_DEFINITIONS ${MPI_TEST_COMPILE_DEFINITIONS}
+ LINK_LIBRARIES MPI::MPI_${LANG}
+ RUN_OUTPUT_VARIABLE MPI_RUN_OUTPUT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE}
+ COMPILE_OUTPUT_VARIABLE _MPI_TRY_${MPI_TEST_FILE_NAME}_${MODE}_OUTPUT)
+ set(MPI_RUN_OUTPUT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE} "${MPI_RUN_OUTPUT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE}}" PARENT_SCOPE)
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)
+ try_compile(MPI_RESULT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE}
+ "${CMAKE_BINARY_DIR}" SOURCES "${MPI_TEST_SOURCE_FILE}"
+ COMPILE_DEFINITIONS ${MPI_TEST_COMPILE_DEFINITIONS}
+ LINK_LIBRARIES MPI::MPI_${LANG}
+ COPY_FILE "${BIN_FILE}"
+ OUTPUT_VARIABLE _MPI_TRY_${MPI_TEST_FILE_NAME}_${MODE}_OUTPUT)
+ endif()
+ if(NOT SUPPRESS_ERRORS)
+ if(NOT MPI_RESULT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE})
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "The MPI test ${MPI_TEST_FILE_NAME} for ${LANG} in mode ${MODE} failed to compile with the following output:\n${_MPI_TRY_${MPI_TEST_FILE_NAME}_${MODE}_OUTPUT}\n\n")
+ elseif(DEFINED MPI_RUN_RESULT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE} AND MPI_RUN_RESULT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE})
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "The MPI test ${MPI_TEST_FILE_NAME} for ${LANG} in mode ${MODE} failed to run with the following output:\n${MPI_RUN_OUTPUT_${LANG}_${MPI_TEST_FILE_NAME}_${MODE}}\n\n")
+ endif()
+ endif()
endfunction()
-# End definitions, commence real work here.
+macro(_MPI_check_lang_works LANG SUPPRESS_ERRORS)
+ # For Fortran we may have by the MPI-3 standard an implementation that provides:
+ # - the mpi_f08 module
+ # - *both*, the mpi module and 'mpif.h'
+ # Since older MPI standards (MPI-1) did not define anything but 'mpif.h', we need to check all three individually.
+ if( NOT MPI_${LANG}_WORKS )
+ if("${LANG}" STREQUAL "Fortran")
+ set(MPI_Fortran_INTEGER_LINE "(kind=MPI_INTEGER_KIND)")
+ _MPI_try_staged_settings(${LANG} test_mpi F77_HEADER FALSE ${SUPPRESS_ERRORS})
+ _MPI_try_staged_settings(${LANG} test_mpi F90_MODULE FALSE ${SUPPRESS_ERRORS})
+ _MPI_try_staged_settings(${LANG} test_mpi F08_MODULE FALSE ${SUPPRESS_ERRORS})
+
+ set(MPI_${LANG}_WORKS FALSE)
+
+ foreach(mpimethod IN ITEMS F77_HEADER F08_MODULE F90_MODULE)
+ if(MPI_RESULT_${LANG}_test_mpi_${mpimethod})
+ set(MPI_${LANG}_WORKS TRUE)
+ set(MPI_${LANG}_HAVE_${mpimethod} TRUE)
+ else()
+ set(MPI_${LANG}_HAVE_${mpimethod} FALSE)
+ endif()
+ endforeach()
+ # MPI-1 versions had no MPI_INTGER_KIND defined, so we need to try without it.
+ # However, MPI-1 also did not define the Fortran 90 and 08 modules, so we only try the F77 header.
+ unset(MPI_Fortran_INTEGER_LINE)
+ if(NOT MPI_${LANG}_WORKS)
+ _MPI_try_staged_settings(${LANG} test_mpi F77_HEADER_NOKIND FALSE ${SUPPRESS_ERRORS})
+ if(MPI_RESULT_${LANG}_test_mpi_F77_HEADER_NOKIND)
+ set(MPI_${LANG}_WORKS TRUE)
+ set(MPI_${LANG}_HAVE_F77_HEADER TRUE)
+ endif()
+ endif()
+ else()
+ _MPI_try_staged_settings(${LANG} test_mpi normal FALSE ${SUPPRESS_ERRORS})
+ # If 'test_mpi' built correctly, we've found valid MPI settings. There might not be MPI-2 C++ support, but there can't
+ # be MPI-2 C++ support without the C bindings being present, so checking for them is sufficient.
+ set(MPI_${LANG}_WORKS "${MPI_RESULT_${LANG}_test_mpi_normal}")
+ endif()
+ endif()
+endmacro()
+
+# Some systems install various MPI implementations in separate folders in some MPI prefix
+# This macro enumerates all such subfolders and adds them to the list of hints that will be searched.
+macro(MPI_search_mpi_prefix_folder PREFIX_FOLDER)
+ if(EXISTS "${PREFIX_FOLDER}")
+ file(GLOB _MPI_folder_children RELATIVE "${PREFIX_FOLDER}" "${PREFIX_FOLDER}/*")
+ foreach(_MPI_folder_child IN LISTS _MPI_folder_children)
+ if(IS_DIRECTORY "${PREFIX_FOLDER}/${_MPI_folder_child}")
+ list(APPEND MPI_HINT_DIRS "${PREFIX_FOLDER}/${_MPI_folder_child}")
+ endif()
+ endforeach()
+ endif()
+endmacro()
+
+set(MPI_HINT_DIRS ${MPI_HOME} $ENV{MPI_HOME} $ENV{I_MPI_ROOT})
+if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
+ # SUSE Linux Enterprise Server stores its MPI implementations under /usr/lib64/mpi/gcc/<name>
+ # We enumerate the subfolders and append each as a prefix
+ MPI_search_mpi_prefix_folder("/usr/lib64/mpi/gcc")
+elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "FreeBSD")
+ # FreeBSD ships mpich under the normal system paths - but available openmpi implementations
+ # will be found in /usr/local/mpi/<name>
+ MPI_search_mpi_prefix_folder("/usr/local/mpi")
+endif()
+
+# Most MPI distributions have some form of mpiexec or mpirun which gives us something we can look for.
+# The MPI standard does not mandate the existence of either, but instead only makes requirements if a distribution
+# ships an mpiexec program (mpirun executables are not regulated by the standard).
-# 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
+# We defer searching for mpiexec binaries belonging to guesses until later. By doing so, mismatches between mpiexec
+# and the MPI we found should be reduced.
+if(NOT MPIEXEC_EXECUTABLE)
+ set(_MPIEXEC_NOT_GIVEN TRUE)
+else()
+ set(_MPIEXEC_NOT_GIVEN FALSE)
+endif()
+
+find_program(MPIEXEC_EXECUTABLE
+ NAMES ${_MPIEXEC_NAMES}
+ PATH_SUFFIXES bin sbin
+ HINTS ${MPI_HINT_DIRS}
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 "${MPIEXEC_EXECUTABLE}" PATH)
get_filename_component(_MPI_BASE_DIR "${_MPI_BASE_DIR}" PATH)
# According to the MPI standard, section 8.8 -n is a guaranteed, and the only guaranteed way to
# launch an MPI process using mpiexec if such a program exists.
-set(MPIEXEC_NUMPROC_FLAG "-n" 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 the number of processes to the processor count and the previous default
-# of 2 if that couldn't be determined.
-include(${CMAKE_CURRENT_LIST_DIR}/ProcessorCount.cmake)
-ProcessorCount(_MPIEXEC_NUMPROCS)
-if("${_MPIEXEC_NUMPROCS}" EQUAL "0")
- set(_MPIEXEC_NUMPROCS 2)
-endif()
-set(MPIEXEC_MAX_NUMPROCS "${_MPIEXEC_NUMPROCS}" CACHE STRING "Maximum number of processors available to run MPI applications.")
-unset(_MPIEXEC_NUMPROCS)
-mark_as_advanced(MPIEXEC MPIEXEC_NUMPROC_FLAG MPIEXEC_PREFLAGS MPIEXEC_POSTFLAGS MPIEXEC_MAX_NUMPROCS)
+set(MPIEXEC_NUMPROC_FLAG "-n" 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 be placed after all flags passed to mpiexec.")
+# Set the number of processes to the physical processor count
+cmake_host_system_information(RESULT _MPIEXEC_NUMPROCS QUERY NUMBER_OF_PHYSICAL_CORES)
+set(MPIEXEC_MAX_NUMPROCS "${_MPIEXEC_NUMPROCS}" CACHE STRING "Maximum number of processors available to run MPI applications.")
+unset(_MPIEXEC_NUMPROCS)
+mark_as_advanced(MPIEXEC_EXECUTABLE 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.
+# 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)
+if(NOT MPI_IGNORE_LEGACY_VARIABLES)
+ foreach (LANG IN ITEMS 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()
+
+ # Chop the old compile flags into options and definitions
- # 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}}")
+ unset(MPI_${LANG}_EXTRA_COMPILE_DEFINITIONS)
+ unset(MPI_${LANG}_EXTRA_COMPILE_OPTIONS)
+ if(MPI_${LANG}_COMPILE_FLAGS)
+ separate_arguments(MPI_SEPARATE_FLAGS NATIVE_COMMAND "${MPI_${LANG}_COMPILE_FLAGS}")
+ foreach(_MPI_FLAG IN LISTS MPI_SEPARATE_FLAGS)
+ if("${_MPI_FLAG}" MATCHES "^ *-D([^ ]+)")
+ list(APPEND MPI_${LANG}_EXTRA_COMPILE_DEFINITIONS "${CMAKE_MATCH_1}")
+ else()
+ list(APPEND MPI_${LANG}_EXTRA_COMPILE_OPTIONS "${_MPI_FLAG}")
+ endif()
+ endforeach()
+ unset(MPI_SEPARATE_FLAGS)
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()
+ # If a list of libraries was given, we'll split it into new-style cache variables
+ unset(MPI_${LANG}_EXTRA_LIB_NAMES)
+ if(NOT MPI_${LANG}_LIB_NAMES)
+ foreach(_MPI_LIB IN LISTS MPI_${LANG}_LIBRARIES MPI_LIBRARY MPI_EXTRA_LIBRARY)
+ if(_MPI_LIB)
+ get_filename_component(_MPI_PLAIN_LIB_NAME "${_MPI_LIB}" NAME_WE)
+ get_filename_component(_MPI_LIB_NAME "${_MPI_LIB}" NAME)
+ get_filename_component(_MPI_LIB_DIR "${_MPI_LIB}" DIRECTORY)
+ list(APPEND MPI_${LANG}_EXTRA_LIB_NAMES "${_MPI_PLAIN_LIB_NAME}")
+ find_library(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY
+ NAMES "${_MPI_LIB_NAME}" "lib${_MPI_LIB_NAME}"
+ HINTS ${_MPI_LIB_DIR} $ENV{MPI_LIB}
+ DOC "Location of the ${_MPI_PLAIN_LIB_NAME} library for MPI"
+ )
+ mark_as_advanced(MPI_${_MPI_PLAIN_LIB_NAME}_LIBRARY)
+ endif()
+ endforeach()
+ endif()
+ endforeach()
+endif()
#=============================================================================
+unset(MPI_VERSION)
+unset(MPI_VERSION_MAJOR)
+unset(MPI_VERSION_MINOR)
+
+unset(_MPI_MIN_VERSION)
+
+# If the user specified a library name we assume they prefer that library over a wrapper. If not, they can disable skipping manually.
+if(NOT DEFINED MPI_SKIP_COMPILER_WRAPPER AND MPI_GUESS_LIBRARY_NAME)
+ set(MPI_SKIP_COMPILER_WRAPPER TRUE)
+endif()
# 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)
- if (NOT IS_ABSOLUTE "${MPI_${lang}_COMPILER}")
- # 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)
- endif()
- # If the user specifies a compiler, we don't want to try to search libraries either.
- set(try_libs FALSE)
+foreach(LANG IN ITEMS C CXX Fortran)
+ if(CMAKE_${LANG}_COMPILER_LOADED)
+ if(NOT MPI_FIND_COMPONENTS)
+ set(_MPI_FIND_${LANG} TRUE)
+ elseif( ${LANG} IN_LIST MPI_FIND_COMPONENTS)
+ set(_MPI_FIND_${LANG} TRUE)
+ elseif( ${LANG} STREQUAL CXX AND NOT MPI_CXX_SKIP_MPICXX AND MPICXX IN_LIST MPI_FIND_COMPONENTS )
+ set(_MPI_FIND_${LANG} TRUE)
else()
- set(try_libs TRUE)
+ set(_MPI_FIND_${LANG} FALSE)
+ endif()
+ else()
+ set(_MPI_FIND_${LANG} FALSE)
+ endif()
+ if(_MPI_FIND_${LANG})
+ if( ${LANG} STREQUAL CXX AND NOT MPICXX IN_LIST MPI_FIND_COMPONENTS )
+ set(MPI_CXX_SKIP_MPICXX FALSE CACHE BOOL "If true, the MPI-2 C++ bindings are disabled using definitions.")
+ mark_as_advanced(MPI_CXX_SKIP_MPICXX)
endif()
+ if(NOT (MPI_${LANG}_LIB_NAMES AND (MPI_${LANG}_INCLUDE_PATH OR MPI_${LANG}_INCLUDE_DIRS OR MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS)))
+ set(MPI_${LANG}_TRIED_IMPLICIT FALSE)
+ set(MPI_${LANG}_WORKS_IMPLICIT FALSE)
+ if(NOT MPI_${LANG}_COMPILER AND NOT MPI_ASSUME_NO_BUILTIN_MPI)
+ # Should the imported targets be empty, we effectively try whether the compiler supports MPI on its own, which is the case on e.g.
+ # Cray PrgEnv.
+ _MPI_create_imported_target(${LANG})
+ _MPI_check_lang_works(${LANG} TRUE)
+
+ # If the compiler can build MPI code on its own, it functions as an MPI compiler and we'll set the variable to point to it.
+ if(MPI_${LANG}_WORKS)
+ set(MPI_${LANG}_COMPILER "${CMAKE_${LANG}_COMPILER}" CACHE FILEPATH "MPI compiler for ${LANG}" FORCE)
+ set(MPI_${LANG}_WORKS_IMPLICIT TRUE)
+ endif()
+ set(MPI_${LANG}_TRIED_IMPLICIT 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)
+ if(NOT "${MPI_${LANG}_COMPILER}" STREQUAL "${CMAKE_${LANG}_COMPILER}" OR NOT MPI_${LANG}_WORKS)
+ set(MPI_${LANG}_WRAPPER_FOUND FALSE)
+ set(MPI_PINNED_COMPILER FALSE)
+
+ if(NOT MPI_SKIP_COMPILER_WRAPPER)
+ if(MPI_${LANG}_COMPILER)
+ # If the user supplies a compiler *name* instead of an absolute path, assume that we need to find THAT compiler.
+ if (NOT IS_ABSOLUTE "${MPI_${LANG}_COMPILER}")
+ # 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}")
+ unset(MPI_${LANG}_COMPILER CACHE)
+ endif()
+ # If the user specifies a compiler, we don't want to try to search libraries either.
+ set(MPI_PINNED_COMPILER TRUE)
+ endif()
+
+ # If we have an MPI base directory, we'll try all compiler names in that one first.
+ # This should prevent mixing different MPI environments
+ if(_MPI_BASE_DIR)
+ find_program(MPI_${LANG}_COMPILER
+ NAMES ${_MPI_${LANG}_COMPILER_NAMES}
+ PATH_SUFFIXES bin sbin
+ HINTS ${_MPI_BASE_DIR}
+ NO_DEFAULT_PATH
+ DOC "MPI compiler for ${LANG}"
+ )
+ endif()
- # 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)
+ # If the base directory did not help (for example because the mpiexec isn't in the same directory as the compilers),
+ # we shall try searching in the default paths.
+ find_program(MPI_${LANG}_COMPILER
+ NAMES ${_MPI_${LANG}_COMPILER_NAMES}
+ PATH_SUFFIXES bin sbin
+ DOC "MPI compiler for ${LANG}"
+ )
+
+ if("${MPI_${LANG}_COMPILER}" STREQUAL "${CMAKE_${LANG}_COMPILER}")
+ set(MPI_PINNED_COMPILER TRUE)
+
+ # If we haven't made the implicit compiler test yet, perform it now.
+ if(NOT MPI_${LANG}_TRIED_IMPLICIT)
+ _MPI_create_imported_target(${LANG})
+ _MPI_check_lang_works(${LANG} TRUE)
+ endif()
+
+ # Should the MPI compiler not work implicitly for MPI, still interrogate it.
+ # Otherwise, MPI compilers for which CMake has separate linking stages, e.g. Intel MPI on Windows where link.exe is being used
+ # directly during linkage instead of CMAKE_<LANG>_COMPILER will not work.
+ if(NOT MPI_${LANG}_WORKS)
+ set(MPI_${LANG}_WORKS_IMPLICIT FALSE)
+ _MPI_interrogate_compiler(${LANG})
+ else()
+ set(MPI_${LANG}_WORKS_IMPLICIT TRUE)
+ endif()
+ elseif(MPI_${LANG}_COMPILER)
+ _MPI_interrogate_compiler(${LANG})
+ endif()
+ endif()
+
+ if(NOT MPI_PINNED_COMPILER AND NOT MPI_${LANG}_WRAPPER_FOUND)
+ # If MPI_PINNED_COMPILER wasn't given, and the MPI compiler we potentially found didn't work, we withdraw it.
+ set(MPI_${LANG}_COMPILER "MPI_${LANG}_COMPILER-NOTFOUND" CACHE FILEPATH "MPI compiler for ${LANG}" FORCE)
+ if(NOT MPI_SKIP_GUESSING)
+ # For C++, we may use the settings for C. Should a given compiler wrapper for C++ not exist, but one for C does, we copy over the
+ # settings for C. An MPI distribution that is in this situation would be IBM Platform MPI.
+ if("${LANG}" STREQUAL "CXX" AND MPI_C_WRAPPER_FOUND)
+ set(MPI_${LANG}_COMPILE_OPTIONS ${MPI_C_COMPILE_OPTIONS} CACHE STRING "MPI ${LANG} compilation options" )
+ set(MPI_${LANG}_COMPILE_DEFINITIONS ${MPI_C_COMPILE_DEFINITIONS} CACHE STRING "MPI ${LANG} compilation definitions" )
+ set(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS ${MPI_C_INCLUDE_DIRS} CACHE STRING "MPI ${LANG} additional include directories")
+ set(MPI_${LANG}_LINK_FLAGS ${MPI_C_LINK_FLAGS} CACHE STRING "MPI ${LANG} linker flags" )
+ set(MPI_${LANG}_LIB_NAMES ${MPI_C_LIB_NAMES} CACHE STRING "MPI ${LANG} libraries to link against" )
+ else()
+ _MPI_guess_settings(${LANG})
+ endif()
+ endif()
+ endif()
+ endif()
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})
+ _MPI_split_include_dirs(${LANG})
+ _MPI_assemble_include_dirs(${LANG})
+ _MPI_assemble_libraries(${LANG})
- 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)
+ _MPI_adjust_compile_definitions(${LANG})
+ # We always create imported targets even if they're empty
+ _MPI_create_imported_target(${LANG})
+
+ if(NOT MPI_${LANG}_WORKS)
+ _MPI_check_lang_works(${LANG} FALSE)
+ endif()
+
+ # Next, we'll initialize the MPI variables that have not been previously set.
+ set(MPI_${LANG}_COMPILE_OPTIONS "" CACHE STRING "MPI ${LANG} compilation flags" )
+ set(MPI_${LANG}_COMPILE_DEFINITIONS "" CACHE STRING "MPI ${LANG} compilation definitions" )
+ set(MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS "" CACHE STRING "MPI ${LANG} additional include directories")
+ set(MPI_${LANG}_LINK_FLAGS "" CACHE STRING "MPI ${LANG} linker flags" )
+ if(NOT MPI_${LANG}_COMPILER STREQUAL CMAKE_${LANG}_COMPILER)
+ set(MPI_${LANG}_LIB_NAMES "" CACHE STRING "MPI ${LANG} libraries to link against" )
endif()
+ mark_as_advanced(MPI_${LANG}_COMPILE_OPTIONS MPI_${LANG}_COMPILE_DEFINITIONS MPI_${LANG}_LINK_FLAGS
+ MPI_${LANG}_LIB_NAMES MPI_${LANG}_ADDITIONAL_INCLUDE_DIRS MPI_${LANG}_COMPILER)
+
+ # If we've found MPI, then we'll perform additional analysis: Determine the MPI version, MPI library version, supported
+ # MPI APIs (i.e. MPI-2 C++ bindings). For Fortran we also need to find specific parameters if we're under MPI-3.
+ if(MPI_${LANG}_WORKS)
+ if("${LANG}" STREQUAL "CXX" AND NOT DEFINED MPI_MPICXX_FOUND)
+ if(NOT MPI_CXX_SKIP_MPICXX AND NOT MPI_CXX_VALIDATE_SKIP_MPICXX)
+ _MPI_try_staged_settings(${LANG} test_mpi MPICXX FALSE FALSE)
+ if(MPI_RESULT_${LANG}_test_mpi_MPICXX)
+ set(MPI_MPICXX_FOUND TRUE)
+ else()
+ set(MPI_MPICXX_FOUND FALSE)
+ endif()
+ else()
+ set(MPI_MPICXX_FOUND FALSE)
+ endif()
+ endif()
+
+ # At this point, we know the bindings present but not the MPI version or anything else.
+ if(NOT DEFINED MPI_${LANG}_VERSION)
+ unset(MPI_${LANG}_VERSION_MAJOR)
+ unset(MPI_${LANG}_VERSION_MINOR)
+ endif()
+ set(MPI_BIN_FOLDER ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindMPI)
+
+ # For Fortran, we'll want to use the most modern MPI binding to test capabilities other than the
+ # Fortran parameters, since those depend on the method of consumption.
+ # For C++, we can always use the C bindings, and should do so, since the C++ bindings do not exist in MPI-3
+ # whereas the C bindings do, and the C++ bindings never offered any feature advantage over their C counterparts.
+ if("${LANG}" STREQUAL "Fortran")
+ if(MPI_${LANG}_HAVE_F08_MODULE)
+ set(MPI_${LANG}_HIGHEST_METHOD F08_MODULE)
+ elseif(MPI_${LANG}_HAVE_F90_MODULE)
+ set(MPI_${LANG}_HIGHEST_METHOD F90_MODULE)
+ else()
+ set(MPI_${LANG}_HIGHEST_METHOD F77_HEADER)
+ endif()
- if(MPI_${lang}_FOUND)
- if(NOT TARGET MPI::MPI_${lang})
- add_library(MPI::MPI_${lang} INTERFACE IMPORTED)
+ # Another difference between C and Fortran is that we can't use the preprocessor to determine whether MPI_VERSION
+ # and MPI_SUBVERSION are provided. These defines did not exist in MPI 1.0 and 1.1 and therefore might not
+ # exist. For C/C++, test_mpi.c will handle the MPI_VERSION extraction, but for Fortran, we need mpiver.f90.
+ if(NOT DEFINED MPI_${LANG}_VERSION)
+ _MPI_try_staged_settings(${LANG} mpiver ${MPI_${LANG}_HIGHEST_METHOD} FALSE FALSE)
+ if(MPI_RESULT_${LANG}_mpiver_${MPI_${LANG}_HIGHEST_METHOD})
+ file(STRINGS ${MPI_BIN_FOLDER}/mpiver_${LANG}.bin _MPI_VERSION_STRING LIMIT_COUNT 1 REGEX "INFO:MPI-VER")
+ if("${_MPI_VERSION_STRING}" MATCHES ".*INFO:MPI-VER\\[([0-9]+)\\.([0-9]+)\\].*")
+ set(MPI_${LANG}_VERSION_MAJOR "${CMAKE_MATCH_1}")
+ set(MPI_${LANG}_VERSION_MINOR "${CMAKE_MATCH_2}")
+ set(MPI_${LANG}_VERSION "${MPI_${LANG}_VERSION_MAJOR}.${MPI_${LANG}_VERSION_MINOR}")
+ endif()
+ endif()
+ endif()
+
+ # Finally, we want to find out which capabilities a given interface supports, compare the MPI-3 standard.
+ # This is determined by interface specific parameters MPI_SUBARRAYS_SUPPORTED and MPI_ASYNC_PROTECTS_NONBLOCKING
+ # and might vary between the different methods of consumption.
+ if(MPI_DETERMINE_Fortran_CAPABILITIES AND NOT MPI_Fortran_CAPABILITIES_DETERMINED)
+ foreach(mpimethod IN ITEMS F08_MODULE F90_MODULE F77_HEADER)
+ if(MPI_${LANG}_HAVE_${mpimethod})
+ set(MPI_${LANG}_${mpimethod}_SUBARRAYS FALSE)
+ set(MPI_${LANG}_${mpimethod}_ASYNCPROT FALSE)
+ _MPI_try_staged_settings(${LANG} fortranparam_mpi ${mpimethod} TRUE FALSE)
+ if(MPI_RESULT_${LANG}_fortranparam_mpi_${mpimethod} AND
+ NOT "${MPI_RUN_RESULT_${LANG}_fortranparam_mpi_${mpimethod}}" STREQUAL "FAILED_TO_RUN")
+ if("${MPI_RUN_OUTPUT_${LANG}_fortranparam_mpi_${mpimethod}}" MATCHES
+ ".*INFO:SUBARRAYS\\[ *([TF]) *\\]-ASYNCPROT\\[ *([TF]) *\\].*")
+ if("${CMAKE_MATCH_1}" STREQUAL "T")
+ set(MPI_${LANG}_${mpimethod}_SUBARRAYS TRUE)
+ endif()
+ if("${CMAKE_MATCH_2}" STREQUAL "T")
+ set(MPI_${LANG}_${mpimethod}_ASYNCPROT TRUE)
+ endif()
+ endif()
+ endif()
+ endif()
+ endforeach()
+ set(MPI_Fortran_CAPABILITIES_DETERMINED TRUE)
+ endif()
+ else()
+ set(MPI_${LANG}_HIGHEST_METHOD normal)
+
+ # By the MPI-2 standard, MPI_VERSION and MPI_SUBVERSION are valid for both C and C++ bindings.
+ if(NOT DEFINED MPI_${LANG}_VERSION)
+ file(STRINGS ${MPI_BIN_FOLDER}/test_mpi_${LANG}.bin _MPI_VERSION_STRING LIMIT_COUNT 1 REGEX "INFO:MPI-VER")
+ if("${_MPI_VERSION_STRING}" MATCHES ".*INFO:MPI-VER\\[([0-9]+)\\.([0-9]+)\\].*")
+ set(MPI_${LANG}_VERSION_MAJOR "${CMAKE_MATCH_1}")
+ set(MPI_${LANG}_VERSION_MINOR "${CMAKE_MATCH_2}")
+ set(MPI_${LANG}_VERSION "${MPI_${LANG}_VERSION_MAJOR}.${MPI_${LANG}_VERSION_MINOR}")
+ endif()
+ endif()
endif()
- if(MPI_${lang}_COMPILE_FLAGS)
- separate_arguments(_MPI_${lang}_COMPILE_OPTIONS NATIVE_COMMAND "${MPI_${lang}_COMPILE_FLAGS}")
- set_property(TARGET MPI::MPI_${lang} PROPERTY
- INTERFACE_COMPILE_OPTIONS "${_MPI_${lang}_COMPILE_OPTIONS}")
+
+ unset(MPI_BIN_FOLDER)
+
+ # At this point, we have dealt with determining the MPI version and parameters for each Fortran method available.
+ # The one remaining issue is to determine which MPI library is installed.
+ # Determining the version and vendor of the MPI library is only possible via MPI_Get_library_version() at runtime,
+ # and therefore we cannot do this while cross-compiling (a user may still define MPI_<lang>_LIBRARY_VERSION_STRING
+ # themselves and we'll attempt splitting it, which is equivalent to provide the try_run output).
+ # It's also worth noting that the installed version string can depend on the language, or on the system the binary
+ # runs on if MPI is not statically linked.
+ if(MPI_DETERMINE_LIBRARY_VERSION AND NOT MPI_${LANG}_LIBRARY_VERSION_STRING)
+ _MPI_try_staged_settings(${LANG} libver_mpi ${MPI_${LANG}_HIGHEST_METHOD} TRUE FALSE)
+ if(MPI_RESULT_${LANG}_libver_mpi_${MPI_${LANG}_HIGHEST_METHOD} AND
+ "${MPI_RUN_RESULT_${LANG}_libver_mpi_${MPI_${LANG}_HIGHEST_METHOD}}" EQUAL "0")
+ string(STRIP "${MPI_RUN_OUTPUT_${LANG}_libver_mpi_${MPI_${LANG}_HIGHEST_METHOD}}"
+ MPI_${LANG}_LIBRARY_VERSION_STRING)
+ else()
+ set(MPI_${LANG}_LIBRARY_VERSION_STRING "NOTFOUND")
+ endif()
endif()
+ endif()
- unset(_MPI_${lang}_LINK_LINE)
- if(MPI_${lang}_LINK_FLAGS)
- list(APPEND _MPI_${lang}_LINK_LINE "${MPI_${lang}_LINK_FLAGS}")
+ set(MPI_${LANG}_FIND_QUIETLY ${MPI_FIND_QUIETLY})
+ set(MPI_${LANG}_FIND_VERSION ${MPI_FIND_VERSION})
+ set(MPI_${LANG}_FIND_VERSION_EXACT ${MPI_FIND_VERSION_EXACT})
+
+ unset(MPI_${LANG}_REQUIRED_VARS)
+ if (NOT "${MPI_${LANG}_COMPILER}" STREQUAL "${CMAKE_${LANG}_COMPILER}")
+ foreach(mpilibname IN LISTS MPI_${LANG}_LIB_NAMES)
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${mpilibname}_LIBRARY")
+ endforeach()
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${LANG}_LIB_NAMES")
+ if("${LANG}" STREQUAL "Fortran")
+ # For Fortran we only need one of the module or header directories to have *some* support for MPI.
+ if(NOT MPI_${LANG}_MODULE_DIR)
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${LANG}_F77_HEADER_DIR")
+ endif()
+ if(NOT MPI_${LANG}_F77_HEADER_DIR)
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${LANG}_MODULE_DIR")
+ endif()
+ else()
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${LANG}_HEADER_DIR")
+ endif()
+ if(MPI_${LANG}_ADDITIONAL_INCLUDE_VARS)
+ foreach(mpiincvar IN LISTS MPI_${LANG}_ADDITIONAL_INCLUDE_VARS)
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${mpiincvar}_INCLUDE_DIR")
+ endforeach()
+ endif()
+ # Append the works variable now. If the settings did not work, this will show up properly.
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${LANG}_WORKS")
+ else()
+ # If the compiler worked implicitly, use its path as output.
+ # Should the compiler variable be set, we also require it to work.
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${LANG}_COMPILER")
+ if(MPI_${LANG}_COMPILER)
+ list(APPEND MPI_${LANG}_REQUIRED_VARS "MPI_${LANG}_WORKS")
endif()
- list(APPEND _MPI_${lang}_LINK_LINE "${MPI_${lang}_LIBRARIES}")
- set_property(TARGET MPI::MPI_${lang} PROPERTY
- INTERFACE_LINK_LIBRARIES "${_MPI_${lang}_LINK_LINE}")
+ endif()
+ find_package_handle_standard_args(MPI_${LANG} REQUIRED_VARS ${MPI_${LANG}_REQUIRED_VARS}
+ VERSION_VAR MPI_${LANG}_VERSION)
- set_property(TARGET MPI::MPI_${lang} PROPERTY
- INTERFACE_INCLUDE_DIRECTORIES "${MPI_${lang}_INCLUDE_PATH}")
+ if(DEFINED MPI_${LANG}_VERSION)
+ if(NOT _MPI_MIN_VERSION OR _MPI_MIN_VERSION VERSION_GREATER MPI_${LANG}_VERSION)
+ set(_MPI_MIN_VERSION MPI_${LANG}_VERSION)
+ endif()
endif()
endif()
endforeach()
+unset(_MPI_REQ_VARS)
+foreach(LANG IN ITEMS C CXX Fortran)
+ if((NOT MPI_FIND_COMPONENTS AND CMAKE_${LANG}_COMPILER_LOADED) OR LANG IN_LIST MPI_FIND_COMPONENTS)
+ list(APPEND _MPI_REQ_VARS "MPI_${LANG}_FOUND")
+ endif()
+endforeach()
+
+if(MPICXX IN_LIST MPI_FIND_COMPONENTS)
+ list(APPEND _MPI_REQ_VARS "MPI_MPICXX_FOUND")
+endif()
+
+find_package_handle_standard_args(MPI
+ REQUIRED_VARS ${_MPI_REQ_VARS}
+ VERSION_VAR ${_MPI_MIN_VERSION}
+ HANDLE_COMPONENTS)
#=============================================================================
# More backward compatibility stuff
-#
-# Bare MPI sans ${lang} vars are set to CXX then C, depending on what was found.
+
+# For compatibility reasons, we also define MPIEXEC
+set(MPIEXEC "${MPIEXEC_EXECUTABLE}")
+
+# Copy over MPI_<LANG>_INCLUDE_PATH from the assembled INCLUDE_DIRS.
+foreach(LANG IN ITEMS C CXX Fortran)
+ if(MPI_${LANG}_FOUND)
+ set(MPI_${LANG}_INCLUDE_PATH "${MPI_${LANG}_INCLUDE_DIRS}")
+ unset(MPI_${LANG}_COMPILE_FLAGS)
+ if(MPI_${LANG}_COMPILE_OPTIONS)
+ list(JOIN MPI_${LANG}_COMPILE_OPTIONS " " MPI_${LANG}_COMPILE_FLAGS)
+ endif()
+ if(MPI_${LANG}_COMPILE_DEFINITIONS)
+ foreach(_MPI_DEF IN LISTS MPI_${LANG}_COMPILE_DEFINITIONS)
+ string(APPEND MPI_${LANG}_COMPILE_FLAGS " -D${_MPI_DEF}")
+ endforeach()
+ endif()
+ endif()
+endforeach()
+
+# 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)
+set(_MPI_OLD_VARS COMPILER INCLUDE_PATH COMPILE_FLAGS LINK_FLAGS LIBRARIES)
if (MPI_CXX_FOUND)
foreach (var ${_MPI_OLD_VARS})
set(MPI_${var} ${MPI_CXX_${var}})
@@ -679,28 +1719,27 @@ 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)
+ set(MPI_LIBRARY "${MPI_LIBRARY_WORK}")
+ unset(MPI_LIBRARY_WORK)
else()
- set(MPI_LIBRARY "MPI_LIBRARY-NOTFOUND" CACHE FILEPATH "MPI library to link against" FORCE)
+ set(MPI_LIBRARY "MPI_LIBRARY-NOTFOUND")
endif()
list(LENGTH MPI_LIBRARIES MPI_NUMLIBS)
if (MPI_NUMLIBS GREATER 1)
- set(MPI_EXTRA_LIBRARY_WORK ${MPI_LIBRARIES})
+ 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)
+ set(MPI_EXTRA_LIBRARY "${MPI_EXTRA_LIBRARY_WORK}")
+ unset(MPI_EXTRA_LIBRARY_WORK)
else()
- set(MPI_EXTRA_LIBRARY "MPI_EXTRA_LIBRARY-NOTFOUND" CACHE STRING "Extra MPI libraries to link against" FORCE)
+ set(MPI_EXTRA_LIBRARY "MPI_EXTRA_LIBRARY-NOTFOUND")
endif()
-mark_as_advanced(MPI_LIBRARY MPI_EXTRA_LIBRARY)
+set(MPI_IGNORE_LEGACY_VARIABLES TRUE)
#=============================================================================
# unset these vars to cleanup namespace
@@ -708,5 +1747,7 @@ unset(_MPI_OLD_VARS)
unset(_MPI_PREFIX_PATH)
unset(_MPI_BASE_DIR)
foreach (lang C CXX Fortran)
- unset(_MPI_${lang}_COMPILER_NAMES)
+ unset(_MPI_${LANG}_COMPILER_NAMES)
endforeach()
+
+cmake_policy(POP)
diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake
index 80bcda36b..354764217 100644
--- a/Modules/FindMatlab.cmake
+++ b/Modules/FindMatlab.cmake
@@ -1,219 +1,232 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindMatlab
-# ----------
-#
-# Finds Matlab installations and provides Matlab tools and libraries to cmake.
-#
-# This package first intention is to find the libraries associated with Matlab
-# in order to be able to build Matlab extensions (mex files). It can also be
-# used:
-#
-# * run specific commands in Matlab
-# * declare Matlab unit test
-# * retrieve various information from Matlab (mex extensions, versions and
-# release queries, ...)
-#
-# The module supports the following components:
-#
-# * ``MX_LIBRARY``, ``ENG_LIBRARY`` and ``MAT_LIBRARY``: respectively the MX,
-# ENG and MAT libraries of Matlab
-# * ``MAIN_PROGRAM`` the Matlab binary program.
-# * ``MEX_COMPILER`` the MEX compiler.
-# * ``SIMULINK`` the Simulink environment.
-#
-# .. note::
-#
-# The version given to the :command:`find_package` directive is the Matlab
-# **version**, which should not be confused with the Matlab *release* name
-# (eg. `R2014`).
-# The :command:`matlab_get_version_from_release_name` and
-# :command:`matlab_get_release_name_from_version` allow a mapping
-# from the release name to the version.
-#
-# The variable :variable:`Matlab_ROOT_DIR` may be specified in order to give
-# the path of the desired Matlab version. Otherwise, the behaviour is platform
-# specific:
-#
-# * Windows: The installed versions of Matlab are retrieved from the
-# Windows registry
-# * OS X: The installed versions of Matlab are given by the MATLAB
-# paths in ``/Application``. If no such application is found, it falls back
-# to the one that might be accessible from the PATH.
-# * Unix: The desired Matlab should be accessible from the PATH.
-#
-# Additional information is provided when :variable:`MATLAB_FIND_DEBUG` is set.
-# When a Matlab binary is found automatically and the ``MATLAB_VERSION``
-# is not given, the version is queried from Matlab directly.
-# On Windows, it can make a window running Matlab appear.
-#
-# The mapping of the release names and the version of Matlab is performed by
-# defining pairs (name, version). The variable
-# :variable:`MATLAB_ADDITIONAL_VERSIONS` may be provided before the call to
-# the :command:`find_package` in order to handle additional versions.
-#
-# A Matlab scripts can be added to the set of tests using the
-# :command:`matlab_add_unit_test`. By default, the Matlab unit test framework
-# will be used (>= 2013a) to run this script, but regular ``.m`` files
-# returning an exit code can be used as well (0 indicating a success).
-#
-# Module Input Variables
-# ^^^^^^^^^^^^^^^^^^^^^^
-#
-# Users or projects may set the following variables to configure the module
-# behaviour:
-#
-# :variable:`Matlab_ROOT_DIR`
-# the root of the Matlab installation.
-# :variable:`MATLAB_FIND_DEBUG`
-# outputs debug information
-# :variable:`MATLAB_ADDITIONAL_VERSIONS`
-# additional versions of Matlab for the automatic retrieval of the installed
-# versions.
-#
-# Variables defined by the module
-# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-#
-# Result variables
-# """"""""""""""""
-#
-# ``Matlab_FOUND``
-# ``TRUE`` if the Matlab installation is found, ``FALSE``
-# otherwise. All variable below are defined if Matlab is found.
-# ``Matlab_ROOT_DIR``
-# the final root of the Matlab installation determined by the FindMatlab
-# module.
-# ``Matlab_MAIN_PROGRAM``
-# the Matlab binary program. Available only if the component ``MAIN_PROGRAM``
-# is given in the :command:`find_package` directive.
-# ``Matlab_INCLUDE_DIRS``
-# the path of the Matlab libraries headers
-# ``Matlab_MEX_LIBRARY``
-# library for mex, always available.
-# ``Matlab_MX_LIBRARY``
-# mx library of Matlab (arrays). Available only if the component
-# ``MX_LIBRARY`` has been requested.
-# ``Matlab_ENG_LIBRARY``
-# Matlab engine library. Available only if the component ``ENG_LIBRARY``
-# is requested.
-# ``Matlab_MAT_LIBRARY``
-# Matlab matrix library. Available only if the component ``MAT_LIBRARY``
-# is requested.
-# ``Matlab_LIBRARIES``
-# the whole set of libraries of Matlab
-# ``Matlab_MEX_COMPILER``
-# the mex compiler of Matlab. Currently not used.
-# Available only if the component ``MEX_COMPILER`` is asked
-#
-# Cached variables
-# """"""""""""""""
-#
-# ``Matlab_MEX_EXTENSION``
-# the extension of the mex files for the current platform (given by Matlab).
-# ``Matlab_ROOT_DIR``
-# the location of the root of the Matlab installation found. If this value
-# is changed by the user, the result variables are recomputed.
-#
-# Provided macros
-# ^^^^^^^^^^^^^^^
-#
-# :command:`matlab_get_version_from_release_name`
-# returns the version from the release name
-# :command:`matlab_get_release_name_from_version`
-# returns the release name from the Matlab version
-#
-# Provided functions
-# ^^^^^^^^^^^^^^^^^^
-#
-# :command:`matlab_add_mex`
-# adds a target compiling a MEX file.
-# :command:`matlab_add_unit_test`
-# adds a Matlab unit test file as a test to the project.
-# :command:`matlab_extract_all_installed_versions_from_registry`
-# parses the registry for all Matlab versions. Available on Windows only.
-# The part of the registry parsed is dependent on the host processor
-# :command:`matlab_get_all_valid_matlab_roots_from_registry`
-# returns all the possible Matlab paths, according to a previously
-# given list. Only the existing/accessible paths are kept. This is mainly
-# useful for the searching all possible Matlab installation.
-# :command:`matlab_get_mex_suffix`
-# returns the suffix to be used for the mex files
-# (platform/architecture dependent)
-# :command:`matlab_get_version_from_matlab_run`
-# returns the version of Matlab, given the full directory of the Matlab
-# program.
-#
-#
-# Known issues
-# ^^^^^^^^^^^^
-#
-# **Symbol clash in a MEX target**
-# By default, every symbols inside a MEX
-# file defined with the command :command:`matlab_add_mex` have hidden
-# visibility, except for the entry point. This is the default behaviour of
-# the MEX compiler, which lowers the risk of symbol collision between the
-# libraries shipped with Matlab, and the libraries to which the MEX file is
-# linking to. This is also the default on Windows platforms.
-#
-# However, this is not sufficient in certain case, where for instance your
-# MEX file is linking against libraries that are already loaded by Matlab,
-# even if those libraries have different SONAMES.
-# A possible solution is to hide the symbols of the libraries to which the
-# MEX target is linking to. This can be achieved in GNU GCC compilers with
-# the linker option ``-Wl,--exclude-libs,ALL``.
-#
-# **Tests using GPU resources**
-# in case your MEX file is using the GPU and
-# in order to be able to run unit tests on this MEX file, the GPU resources
-# should be properly released by Matlab. A possible solution is to make
-# Matlab aware of the use of the GPU resources in the session, which can be
-# performed by a command such as ``D = gpuDevice()`` at the beginning of
-# the test script (or via a fixture).
-#
-#
-# Reference
-# ^^^^^^^^^
-#
-# .. variable:: Matlab_ROOT_DIR
-#
-# The root folder of the Matlab installation. If set before the call to
-# :command:`find_package`, the module will look for the components in that
-# path. If not set, then an automatic search of Matlab
-# will be performed. If set, it should point to a valid version of Matlab.
-#
-# .. variable:: MATLAB_FIND_DEBUG
-#
-# If set, the lookup of Matlab and the intermediate configuration steps are
-# outputted to the console.
-#
-# .. variable:: MATLAB_ADDITIONAL_VERSIONS
-#
-# If set, specifies additional versions of Matlab that may be looked for.
-# The variable should be a list of strings, organised by pairs of release
-# name and versions, such as follows::
-#
-# set(MATLAB_ADDITIONAL_VERSIONS
-# "release_name1=corresponding_version1"
-# "release_name2=corresponding_version2"
-# ...
-# )
-#
-# Example::
-#
-# set(MATLAB_ADDITIONAL_VERSIONS
-# "R2013b=8.2"
-# "R2013a=8.1"
-# "R2012b=8.0")
-#
-# The order of entries in this list matters when several versions of
-# Matlab are installed. The priority is set according to the ordering in
-# this list.
+#[=======================================================================[.rst:
+FindMatlab
+----------
+
+Finds Matlab or Matlab Compiler Runtime (MCR) and provides Matlab tools,
+libraries and compilers to CMake.
+
+This package primary purpose is to find the libraries associated with Matlab
+or the MCR in order to be able to build Matlab extensions (mex files). It
+can also be used:
+
+* to run specific commands in Matlab in case Matlab is available
+* for declaring Matlab unit test
+* to retrieve various information from Matlab (mex extensions, versions and
+ release queries, ...)
+
+The module supports the following components:
+
+* ``ENG_LIBRARY`` and ``MAT_LIBRARY``: respectively the ``ENG`` and ``MAT``
+ libraries of Matlab
+* ``MAIN_PROGRAM`` the Matlab binary program. Note that this component is not
+ available on the MCR version, and will yield an error if the MCR is found
+ instead of the regular Matlab installation.
+* ``MEX_COMPILER`` the MEX compiler.
+* ``MCC_COMPILER`` the MCC compiler, included with the Matlab Compiler add-on.
+* ``SIMULINK`` the Simulink environment.
+
+.. note::
+
+ The version given to the :command:`find_package` directive is the Matlab
+ **version**, which should not be confused with the Matlab *release* name
+ (eg. `R2014`).
+ The :command:`matlab_get_version_from_release_name` and
+ :command:`matlab_get_release_name_from_version` provide a mapping
+ between the release name and the version.
+
+The variable :variable:`Matlab_ROOT_DIR` may be specified in order to give
+the path of the desired Matlab version. Otherwise, the behaviour is platform
+specific:
+
+* Windows: The installed versions of Matlab/MCR are retrieved from the
+ Windows registry
+* OS X: The installed versions of Matlab/MCR are given by the MATLAB
+ default installation paths in ``/Application``. If no such application is
+ found, it falls back to the one that might be accessible from the ``PATH``.
+* Unix: The desired Matlab should be accessible from the ``PATH``. This does
+ not work for MCR installation and :variable:`Matlab_ROOT_DIR` should be
+ specified on this platform.
+
+Additional information is provided when :variable:`MATLAB_FIND_DEBUG` is set.
+When a Matlab/MCR installation is found automatically and the ``MATLAB_VERSION``
+is not given, the version is queried from Matlab directly (on Windows this
+may pop up a Matlab window) or from the MCR installation.
+
+The mapping of the release names and the version of Matlab is performed by
+defining pairs (name, version). The variable
+:variable:`MATLAB_ADDITIONAL_VERSIONS` may be provided before the call to
+the :command:`find_package` in order to handle additional versions.
+
+A Matlab scripts can be added to the set of tests using the
+:command:`matlab_add_unit_test`. By default, the Matlab unit test framework
+will be used (>= 2013a) to run this script, but regular ``.m`` files
+returning an exit code can be used as well (0 indicating a success).
+
+Module Input Variables
+^^^^^^^^^^^^^^^^^^^^^^
+
+Users or projects may set the following variables to configure the module
+behaviour:
+
+:variable:`Matlab_ROOT_DIR`
+ the root of the Matlab installation.
+:variable:`MATLAB_FIND_DEBUG`
+ outputs debug information
+:variable:`MATLAB_ADDITIONAL_VERSIONS`
+ additional versions of Matlab for the automatic retrieval of the installed
+ versions.
+
+Variables defined by the module
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Result variables
+""""""""""""""""
+
+``Matlab_FOUND``
+ ``TRUE`` if the Matlab installation is found, ``FALSE``
+ otherwise. All variable below are defined if Matlab is found.
+``Matlab_ROOT_DIR``
+ the final root of the Matlab installation determined by the FindMatlab
+ module.
+``Matlab_MAIN_PROGRAM``
+ the Matlab binary program. Available only if the component ``MAIN_PROGRAM``
+ is given in the :command:`find_package` directive.
+``Matlab_INCLUDE_DIRS``
+ the path of the Matlab libraries headers
+``Matlab_MEX_LIBRARY``
+ library for mex, always available.
+``Matlab_MX_LIBRARY``
+ mx library of Matlab (arrays), always available.
+``Matlab_ENG_LIBRARY``
+ Matlab engine library. Available only if the component ``ENG_LIBRARY``
+ is requested.
+``Matlab_MAT_LIBRARY``
+ Matlab matrix library. Available only if the component ``MAT_LIBRARY``
+ is requested.
+``Matlab_ENGINE_LIBRARY``
+ Matlab C++ engine library, always available for R2018a and newer.
+``Matlab_DATAARRAY_LIBRARY``
+ Matlab C++ data array library, always available for R2018a and newer.
+``Matlab_LIBRARIES``
+ the whole set of libraries of Matlab
+``Matlab_MEX_COMPILER``
+ the mex compiler of Matlab. Currently not used.
+ Available only if the component ``MEX_COMPILER`` is requested.
+``Matlab_MCC_COMPILER``
+ the mcc compiler of Matlab. Included with the Matlab Compiler add-on.
+ Available only if the component ``MCC_COMPILER`` is requested.
+
+Cached variables
+""""""""""""""""
+
+``Matlab_MEX_EXTENSION``
+ the extension of the mex files for the current platform (given by Matlab).
+``Matlab_ROOT_DIR``
+ the location of the root of the Matlab installation found. If this value
+ is changed by the user, the result variables are recomputed.
+
+Provided macros
+^^^^^^^^^^^^^^^
+
+:command:`matlab_get_version_from_release_name`
+ returns the version from the release name
+:command:`matlab_get_release_name_from_version`
+ returns the release name from the Matlab version
+
+Provided functions
+^^^^^^^^^^^^^^^^^^
+
+:command:`matlab_add_mex`
+ adds a target compiling a MEX file.
+:command:`matlab_add_unit_test`
+ adds a Matlab unit test file as a test to the project.
+:command:`matlab_extract_all_installed_versions_from_registry`
+ parses the registry for all Matlab versions. Available on Windows only.
+ The part of the registry parsed is dependent on the host processor
+:command:`matlab_get_all_valid_matlab_roots_from_registry`
+ returns all the possible Matlab or MCR paths, according to a previously
+ given list. Only the existing/accessible paths are kept. This is mainly
+ useful for the searching all possible Matlab installation.
+:command:`matlab_get_mex_suffix`
+ returns the suffix to be used for the mex files
+ (platform/architecture dependent)
+:command:`matlab_get_version_from_matlab_run`
+ returns the version of Matlab/MCR, given the full directory of the Matlab/MCR
+ installation path.
+
+
+Known issues
+^^^^^^^^^^^^
+
+**Symbol clash in a MEX target**
+ By default, every symbols inside a MEX
+ file defined with the command :command:`matlab_add_mex` have hidden
+ visibility, except for the entry point. This is the default behaviour of
+ the MEX compiler, which lowers the risk of symbol collision between the
+ libraries shipped with Matlab, and the libraries to which the MEX file is
+ linking to. This is also the default on Windows platforms.
+
+ However, this is not sufficient in certain case, where for instance your
+ MEX file is linking against libraries that are already loaded by Matlab,
+ even if those libraries have different SONAMES.
+ A possible solution is to hide the symbols of the libraries to which the
+ MEX target is linking to. This can be achieved in GNU GCC compilers with
+ the linker option ``-Wl,--exclude-libs,ALL``.
+
+**Tests using GPU resources**
+ in case your MEX file is using the GPU and
+ in order to be able to run unit tests on this MEX file, the GPU resources
+ should be properly released by Matlab. A possible solution is to make
+ Matlab aware of the use of the GPU resources in the session, which can be
+ performed by a command such as ``D = gpuDevice()`` at the beginning of
+ the test script (or via a fixture).
+
+
+Reference
+^^^^^^^^^
+
+.. variable:: Matlab_ROOT_DIR
+
+ The root folder of the Matlab installation. If set before the call to
+ :command:`find_package`, the module will look for the components in that
+ path. If not set, then an automatic search of Matlab
+ will be performed. If set, it should point to a valid version of Matlab.
+
+.. variable:: MATLAB_FIND_DEBUG
+
+ If set, the lookup of Matlab and the intermediate configuration steps are
+ outputted to the console.
+
+.. variable:: MATLAB_ADDITIONAL_VERSIONS
+
+ If set, specifies additional versions of Matlab that may be looked for.
+ The variable should be a list of strings, organised by pairs of release
+ name and versions, such as follows::
+
+ set(MATLAB_ADDITIONAL_VERSIONS
+ "release_name1=corresponding_version1"
+ "release_name2=corresponding_version2"
+ ...
+ )
+
+ Example::
+
+ set(MATLAB_ADDITIONAL_VERSIONS
+ "R2013b=8.2"
+ "R2013a=8.1"
+ "R2012b=8.0")
+
+ The order of entries in this list matters when several versions of
+ Matlab are installed. The priority is set according to the ordering in
+ this list.
+#]=======================================================================]
set(_FindMatlab_SELF_DIR "${CMAKE_CURRENT_LIST_DIR}")
-include(FindPackageHandleStandardArgs)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)
@@ -225,6 +238,9 @@ if(NOT MATLAB_ADDITIONAL_VERSIONS)
endif()
set(MATLAB_VERSIONS_MAPPING
+ "R2018b=9.5"
+ "R2018a=9.4"
+ "R2017b=9.3"
"R2017a=9.2"
"R2016b=9.1"
"R2016a=9.0"
@@ -236,7 +252,6 @@ set(MATLAB_VERSIONS_MAPPING
"R2013a=8.1"
"R2012b=8.0"
"R2012a=7.14"
-
"R2011b=7.13"
"R2011a=7.12"
"R2010b=7.11"
@@ -252,11 +267,12 @@ if(NOT EXISTS "${_matlab_temporary_folder}")
file(MAKE_DIRECTORY "${_matlab_temporary_folder}")
endif()
-#.rst:
-# .. command:: matlab_get_version_from_release_name
-#
-# Returns the version of Matlab (17.58) from a release name (R2017k)
-macro (matlab_get_version_from_release_name release_name version_name)
+#[=======================================================================[.rst:
+.. command:: matlab_get_version_from_release_name
+
+ Returns the version of Matlab (17.58) from a release name (R2017k)
+#]=======================================================================]
+macro(matlab_get_version_from_release_name release_name version_name)
string(REGEX MATCHALL "${release_name}=([0-9]+\\.?[0-9]*)" _matched ${MATLAB_VERSIONS_MAPPING})
@@ -264,7 +280,7 @@ macro (matlab_get_version_from_release_name release_name version_name)
if(NOT _matched STREQUAL "")
set(${version_name} ${CMAKE_MATCH_1})
else()
- message(WARNING "The release name ${release_name} is not registered")
+ message(WARNING "[MATLAB] The release name ${release_name} is not registered")
endif()
unset(_matched)
@@ -274,11 +290,12 @@ endmacro()
-#.rst:
-# .. command:: matlab_get_release_name_from_version
-#
-# Returns the release name (R2017k) from the version of Matlab (17.58)
-macro (matlab_get_release_name_from_version version release_name)
+#[=======================================================================[.rst:
+.. command:: matlab_get_release_name_from_version
+
+ Returns the release name (R2017k) from the version of Matlab (17.58)
+#]=======================================================================]
+macro(matlab_get_release_name_from_version version release_name)
set(${release_name} "")
foreach(_var IN LISTS MATLAB_VERSIONS_MAPPING)
@@ -292,7 +309,7 @@ macro (matlab_get_release_name_from_version version release_name)
unset(_var)
unset(_matched)
if(${release_name} STREQUAL "")
- message(WARNING "The version ${version} is not registered")
+ message(WARNING "[MATLAB] The version ${version} is not registered")
endif()
endmacro()
@@ -334,69 +351,74 @@ macro(matlab_get_supported_versions list_versions)
endmacro()
-#.rst:
-# .. command:: matlab_extract_all_installed_versions_from_registry
-#
-# This function parses the registry and founds the Matlab versions that are
-# installed. The found versions are returned in `matlab_versions`.
-# Set `win64` to `TRUE` if the 64 bit version of Matlab should be looked for
-# The returned list contains all versions under
-# ``HKLM\\SOFTWARE\\Mathworks\\MATLAB`` or an empty list in case an error
-# occurred (or nothing found).
-#
-# .. note::
-#
-# Only the versions are provided. No check is made over the existence of the
-# installation referenced in the registry,
-#
+#[=======================================================================[.rst:
+.. command:: matlab_extract_all_installed_versions_from_registry
+
+ This function parses the registry and founds the Matlab versions that are
+ installed. The found versions are returned in `matlab_versions`.
+ Set `win64` to `TRUE` if the 64 bit version of Matlab should be looked for
+ The returned list contains all versions under
+ ``HKLM\\SOFTWARE\\Mathworks\\MATLAB`` and
+ ``HKLM\\SOFTWARE\\Mathworks\\MATLAB Runtime`` or an empty list in case an
+ error occurred (or nothing found).
+
+ .. note::
+
+ Only the versions are provided. No check is made over the existence of the
+ installation referenced in the registry,
+
+#]=======================================================================]
function(matlab_extract_all_installed_versions_from_registry win64 matlab_versions)
if(NOT CMAKE_HOST_WIN32)
- message(FATAL_ERROR "This macro can only be called by a windows host (call to reg.exe")
+ message(FATAL_ERROR "[MATLAB] This macro can only be called by a windows host (call to reg.exe)")
endif()
-
- if(${win64} AND ${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "64")
+ if(${win64} AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "64")
set(APPEND_REG "/reg:64")
else()
set(APPEND_REG "/reg:32")
endif()
- # /reg:64 should be added on 64 bits capable OSs in order to enable the
- # redirection of 64 bits applications
- execute_process(
- COMMAND reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Mathworks\\MATLAB /f * /k ${APPEND_REG}
- RESULT_VARIABLE resultMatlab
- OUTPUT_VARIABLE varMatlab
- ERROR_VARIABLE errMatlab
- INPUT_FILE NUL
- )
+ set(matlabs_from_registry)
+ foreach(_installation_type IN ITEMS "MATLAB" "MATLAB Runtime")
- set(matlabs_from_registry)
- if(${resultMatlab} EQUAL 0)
+ # /reg:64 should be added on 64 bits capable OSs in order to enable the
+ # redirection of 64 bits applications
+ execute_process(
+ COMMAND reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Mathworks\\${_installation_type} /f * /k ${APPEND_REG}
+ RESULT_VARIABLE resultMatlab
+ OUTPUT_VARIABLE varMatlab
+ ERROR_VARIABLE errMatlab
+ INPUT_FILE NUL
+ )
- string(
- REGEX MATCHALL "MATLAB\\\\([0-9]+(\\.[0-9]+)?)"
- matlab_versions_regex ${varMatlab})
- foreach(match IN LISTS matlab_versions_regex)
- string(
- REGEX MATCH "MATLAB\\\\(([0-9]+)(\\.([0-9]+))?)"
- current_match ${match})
+ if(${resultMatlab} EQUAL 0)
- set(_matlab_current_version ${CMAKE_MATCH_1})
- set(current_matlab_version_major ${CMAKE_MATCH_2})
- set(current_matlab_version_minor ${CMAKE_MATCH_4})
- if(NOT current_matlab_version_minor)
- set(current_matlab_version_minor "0")
- endif()
+ string(
+ REGEX MATCHALL "MATLAB\\\\([0-9]+(\\.[0-9]+)?)"
+ matlab_versions_regex ${varMatlab})
+
+ foreach(match IN LISTS matlab_versions_regex)
+ string(
+ REGEX MATCH "MATLAB\\\\(([0-9]+)(\\.([0-9]+))?)"
+ current_match ${match})
+
+ set(_matlab_current_version ${CMAKE_MATCH_1})
+ set(current_matlab_version_major ${CMAKE_MATCH_2})
+ set(current_matlab_version_minor ${CMAKE_MATCH_4})
+ if(NOT current_matlab_version_minor)
+ set(current_matlab_version_minor "0")
+ endif()
- list(APPEND matlabs_from_registry ${_matlab_current_version})
- unset(_matlab_current_version)
- endforeach(match)
+ list(APPEND matlabs_from_registry ${_matlab_current_version})
+ unset(_matlab_current_version)
+ endforeach()
- endif()
+ endif()
+ endforeach()
if(matlabs_from_registry)
list(REMOVE_DUPLICATES matlabs_from_registry)
@@ -441,7 +463,6 @@ macro(extract_matlab_versions_from_registry_brute_force matlab_versions)
# list(APPEND matlab_supported_versions MATLAB_ADDITIONAL_VERSIONS)
# endif()
-
# we order from more recent to older
if(matlab_supported_versions)
list(REMOVE_DUPLICATES matlab_supported_versions)
@@ -449,40 +470,40 @@ macro(extract_matlab_versions_from_registry_brute_force matlab_versions)
list(REVERSE matlab_supported_versions)
endif()
-
set(${matlab_versions} ${matlab_supported_versions})
+endmacro()
+
-endmacro()
+#[=======================================================================[.rst:
+.. command:: matlab_get_all_valid_matlab_roots_from_registry
+ Populates the Matlab root with valid versions of Matlab or
+ Matlab Runtime (MCR).
+ The returned matlab_roots is organized in triplets
+ ``(type,version_number,matlab_root_path)``, where ``type``
+ indicates either ``MATLAB`` or ``MCR``.
+ ::
-#.rst:
-# .. command:: matlab_get_all_valid_matlab_roots_from_registry
-#
-# Populates the Matlab root with valid versions of Matlab.
-# The returned matlab_roots is organized in pairs
-# ``(version_number,matlab_root_path)``.
-#
-# ::
-#
-# matlab_get_all_valid_matlab_roots_from_registry(
-# matlab_versions
-# matlab_roots)
-#
-# ``matlab_versions``
-# the versions of each of the Matlab installations
-# ``matlab_roots``
-# the location of each of the Matlab installations
+ matlab_get_all_valid_matlab_roots_from_registry(
+ matlab_versions
+ matlab_roots)
+
+ ``matlab_versions``
+ the versions of each of the Matlab or MCR installations
+ ``matlab_roots``
+ the location of each of the Matlab or MCR installations
+#]=======================================================================]
function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_roots)
# The matlab_versions comes either from
# extract_matlab_versions_from_registry_brute_force or
# matlab_extract_all_installed_versions_from_registry.
-
set(_matlab_roots_list )
+ # check for Matlab installations
foreach(_matlab_current_version ${matlab_versions})
get_filename_component(
current_MATLAB_ROOT
@@ -490,32 +511,47 @@ function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_
ABSOLUTE)
if(EXISTS ${current_MATLAB_ROOT})
- list(APPEND _matlab_roots_list ${_matlab_current_version} ${current_MATLAB_ROOT})
+ list(APPEND _matlab_roots_list "MATLAB" ${_matlab_current_version} ${current_MATLAB_ROOT})
endif()
- endforeach(_matlab_current_version)
- unset(_matlab_current_version)
+ endforeach()
+
+ # Check for MCR installations
+ foreach(_matlab_current_version ${matlab_versions})
+ get_filename_component(
+ current_MATLAB_ROOT
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB Runtime\\${_matlab_current_version};MATLABROOT]"
+ ABSOLUTE)
+
+ # remove the dot
+ string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}")
+
+ if(EXISTS ${current_MATLAB_ROOT})
+ list(APPEND _matlab_roots_list "MCR" ${_matlab_current_version} "${current_MATLAB_ROOT}/v${_matlab_current_version_without_dot}")
+ endif()
+
+ endforeach()
set(${matlab_roots} ${_matlab_roots_list} PARENT_SCOPE)
- unset(_matlab_roots_list)
endfunction()
-#.rst:
-# .. command:: matlab_get_mex_suffix
-#
-# Returns the extension of the mex files (the suffixes).
-# This function should not be called before the appropriate Matlab root has
-# been found.
-#
-# ::
-#
-# matlab_get_mex_suffix(
-# matlab_root
-# mex_suffix)
-#
-# ``matlab_root``
-# the root of the Matlab installation
-# ``mex_suffix``
-# the variable name in which the suffix will be returned.
+#[=======================================================================[.rst:
+.. command:: matlab_get_mex_suffix
+
+ Returns the extension of the mex files (the suffixes).
+ This function should not be called before the appropriate Matlab root has
+ been found.
+
+ ::
+
+ matlab_get_mex_suffix(
+ matlab_root
+ mex_suffix)
+
+ ``matlab_root``
+ the root of the Matlab/MCR installation
+ ``mex_suffix``
+ the variable name in which the suffix will be returned.
+#]=======================================================================]
function(matlab_get_mex_suffix matlab_root mex_suffix)
# todo setup the extension properly. Currently I do not know if this is
@@ -548,7 +584,9 @@ function(matlab_get_mex_suffix matlab_root mex_suffix)
)
endif()
endforeach(current_mexext_suffix)
-
+ if(MATLAB_FIND_DEBUG)
+ message(STATUS "[MATLAB] Determining mex files extensions from '${matlab_root}/bin' with program '${Matlab_MEXEXTENSIONS_PROG}'")
+ endif()
# the program has been found?
if((NOT Matlab_MEXEXTENSIONS_PROG) OR (NOT EXISTS ${Matlab_MEXEXTENSIONS_PROG}))
@@ -568,12 +606,29 @@ function(matlab_get_mex_suffix matlab_root mex_suffix)
set(devnull INPUT_FILE NUL)
endif()
+ # this is the preferred way. If this does not work properly (eg. MCR on Windows), then we use our own knowledge
execute_process(
COMMAND ${Matlab_MEXEXTENSIONS_PROG}
OUTPUT_VARIABLE _matlab_mex_extension
+ #RESULT_VARIABLE _matlab_mex_extension_call
ERROR_VARIABLE _matlab_mex_extension_error
${devnull})
- string(STRIP ${_matlab_mex_extension} _matlab_mex_extension)
+
+ if(NOT "${_matlab_mex_extension_error}" STREQUAL "")
+ if(WIN32)
+ # this is only for intel architecture
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_matlab_mex_extension "mexw64")
+ else()
+ set(_matlab_mex_extension "mexw32")
+ endif()
+ endif()
+ endif()
+
+ string(STRIP "${_matlab_mex_extension}" _matlab_mex_extension)
+ if(MATLAB_FIND_DEBUG)
+ message(STATUS "[MATLAB] '${Matlab_MEXEXTENSIONS_PROG}' : returned '${_matlab_mex_extension_call}', determined extension '${_matlab_mex_extension}' and error string is '${_matlab_mex_extension_error}'")
+ endif()
unset(Matlab_MEXEXTENSIONS_PROG CACHE)
set(${mex_suffix} ${_matlab_mex_extension} PARENT_SCOPE)
@@ -582,27 +637,28 @@ endfunction()
-#.rst:
-# .. command:: matlab_get_version_from_matlab_run
-#
-# This function runs Matlab program specified on arguments and extracts its
-# version.
-#
-# ::
-#
-# matlab_get_version_from_matlab_run(
-# matlab_binary_path
-# matlab_list_versions)
-#
-# ``matlab_binary_path``
-# the location of the `matlab` binary executable
-# ``matlab_list_versions``
-# the version extracted from Matlab
+#[=======================================================================[.rst:
+.. command:: matlab_get_version_from_matlab_run
+
+ This function runs Matlab program specified on arguments and extracts its
+ version. If the path provided for the Matlab installation points to an MCR
+ installation, the version is extracted from the installed files.
+
+ ::
+
+ matlab_get_version_from_matlab_run(
+ matlab_binary_path
+ matlab_list_versions)
+
+ ``matlab_binary_path``
+ the location of the `matlab` binary executable
+ ``matlab_list_versions``
+ the version extracted from Matlab
+#]=======================================================================]
function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_versions)
set(${matlab_list_versions} "" PARENT_SCOPE)
-
if(MATLAB_FIND_DEBUG)
message(STATUS "[MATLAB] Determining the version of Matlab from ${matlab_binary_program}")
endif()
@@ -669,7 +725,7 @@ function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_ve
file(REMOVE "${_matlab_temporary_folder}/matlabVersionLog.cmaketmp")
set(index -1)
- string(FIND ${_matlab_version_from_cmd} "ans" index)
+ string(FIND "${_matlab_version_from_cmd}" "ans" index)
if(index EQUAL -1)
if(MATLAB_FIND_DEBUG)
@@ -679,14 +735,14 @@ function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_ve
else()
set(matlab_list_of_all_versions_tmp)
- string(SUBSTRING ${_matlab_version_from_cmd} ${index} -1 substring_ans)
+ string(SUBSTRING "${_matlab_version_from_cmd}" ${index} -1 substring_ans)
string(
- REGEX MATCHALL "ans[\r\n\t ]*=[\r\n\t ]*([0-9]+(\\.[0-9]+)?)"
+ REGEX MATCHALL "ans[\r\n\t ]*=[\r\n\t ]*'?([0-9]+(\\.[0-9]+)?)"
matlab_versions_regex
${substring_ans})
foreach(match IN LISTS matlab_versions_regex)
string(
- REGEX MATCH "ans[\r\n\t ]*=[\r\n\t ]*(([0-9]+)(\\.([0-9]+))?)"
+ REGEX MATCH "ans[\r\n\t ]*=[\r\n\t ]*'?(([0-9]+)(\\.([0-9]+))?)"
current_match ${match})
list(APPEND matlab_list_of_all_versions_tmp ${CMAKE_MATCH_1})
@@ -700,74 +756,77 @@ function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_ve
endfunction()
-#.rst:
-# .. command:: matlab_add_unit_test
-#
-# Adds a Matlab unit test to the test set of cmake/ctest.
-# This command requires the component ``MAIN_PROGRAM``.
-# The unit test uses the Matlab unittest framework (default, available
-# starting Matlab 2013b+) except if the option ``NO_UNITTEST_FRAMEWORK``
-# is given.
-#
-# The function expects one Matlab test script file to be given.
-# In the case ``NO_UNITTEST_FRAMEWORK`` is given, the unittest script file
-# should contain the script to be run, plus an exit command with the exit
-# value. This exit value will be passed to the ctest framework (0 success,
-# non 0 failure). Additional arguments accepted by :command:`add_test` can be
-# passed through ``TEST_ARGS`` (eg. ``CONFIGURATION <config> ...``).
-#
-# ::
-#
-# matlab_add_unit_test(
-# NAME <name>
-# UNITTEST_FILE matlab_file_containing_unittest.m
-# [CUSTOM_MATLAB_COMMAND matlab_command_to_run_as_test]
-# [UNITTEST_PRECOMMAND matlab_command_to_run]
-# [TIMEOUT timeout]
-# [ADDITIONAL_PATH path1 [path2 ...]]
-# [MATLAB_ADDITIONAL_STARTUP_OPTIONS option1 [option2 ...]]
-# [TEST_ARGS arg1 [arg2 ...]]
-# [NO_UNITTEST_FRAMEWORK]
-# )
-#
-# The function arguments are:
-#
-# ``NAME``
-# name of the unittest in ctest.
-# ``UNITTEST_FILE``
-# the matlab unittest file. Its path will be automatically
-# added to the Matlab path.
-# ``CUSTOM_MATLAB_COMMAND``
-# Matlab script command to run as the test.
-# If this is not set, then the following is run:
-# ``runtests('matlab_file_name'), exit(max([ans(1,:).Failed]))``
-# where ``matlab_file_name`` is the ``UNITTEST_FILE`` without the extension.
-# ``UNITTEST_PRECOMMAND``
-# Matlab script command to be ran before the file
-# containing the test (eg. GPU device initialisation based on CMake
-# variables).
-# ``TIMEOUT``
-# the test timeout in seconds. Defaults to 180 seconds as the
-# Matlab unit test may hang.
-# ``ADDITIONAL_PATH``
-# a list of paths to add to the Matlab path prior to
-# running the unit test.
-# ``MATLAB_ADDITIONAL_STARTUP_OPTIONS``
-# a list of additional option in order
-# to run Matlab from the command line.
-# ``-nosplash -nodesktop -nodisplay`` are always added.
-# ``TEST_ARGS``
-# Additional options provided to the add_test command. These
-# options are added to the default options (eg. "CONFIGURATIONS Release")
-# ``NO_UNITTEST_FRAMEWORK``
-# when set, indicates that the test should not
-# use the unittest framework of Matlab (available for versions >= R2013a).
-# ``WORKING_DIRECTORY``
-# This will be the working directory for the test. If specified it will
-# also be the output directory used for the log file of the test run.
-# If not specifed the temporary directory ``${CMAKE_BINARY_DIR}/Matlab`` will
-# be used as the working directory and the log location.
-#
+#[=======================================================================[.rst:
+.. command:: matlab_add_unit_test
+
+ Adds a Matlab unit test to the test set of cmake/ctest.
+ This command requires the component ``MAIN_PROGRAM`` and hence is not
+ available for an MCR installation.
+
+ The unit test uses the Matlab unittest framework (default, available
+ starting Matlab 2013b+) except if the option ``NO_UNITTEST_FRAMEWORK``
+ is given.
+
+ The function expects one Matlab test script file to be given.
+ In the case ``NO_UNITTEST_FRAMEWORK`` is given, the unittest script file
+ should contain the script to be run, plus an exit command with the exit
+ value. This exit value will be passed to the ctest framework (0 success,
+ non 0 failure). Additional arguments accepted by :command:`add_test` can be
+ passed through ``TEST_ARGS`` (eg. ``CONFIGURATION <config> ...``).
+
+ ::
+
+ matlab_add_unit_test(
+ NAME <name>
+ UNITTEST_FILE matlab_file_containing_unittest.m
+ [CUSTOM_TEST_COMMAND matlab_command_to_run_as_test]
+ [UNITTEST_PRECOMMAND matlab_command_to_run]
+ [TIMEOUT timeout]
+ [ADDITIONAL_PATH path1 [path2 ...]]
+ [MATLAB_ADDITIONAL_STARTUP_OPTIONS option1 [option2 ...]]
+ [TEST_ARGS arg1 [arg2 ...]]
+ [NO_UNITTEST_FRAMEWORK]
+ )
+
+ The function arguments are:
+
+ ``NAME``
+ name of the unittest in ctest.
+ ``UNITTEST_FILE``
+ the matlab unittest file. Its path will be automatically
+ added to the Matlab path.
+ ``CUSTOM_TEST_COMMAND``
+ Matlab script command to run as the test.
+ If this is not set, then the following is run:
+ ``runtests('matlab_file_name'), exit(max([ans(1,:).Failed]))``
+ where ``matlab_file_name`` is the ``UNITTEST_FILE`` without the extension.
+ ``UNITTEST_PRECOMMAND``
+ Matlab script command to be ran before the file
+ containing the test (eg. GPU device initialisation based on CMake
+ variables).
+ ``TIMEOUT``
+ the test timeout in seconds. Defaults to 180 seconds as the
+ Matlab unit test may hang.
+ ``ADDITIONAL_PATH``
+ a list of paths to add to the Matlab path prior to
+ running the unit test.
+ ``MATLAB_ADDITIONAL_STARTUP_OPTIONS``
+ a list of additional option in order
+ to run Matlab from the command line.
+ ``-nosplash -nodesktop -nodisplay`` are always added.
+ ``TEST_ARGS``
+ Additional options provided to the add_test command. These
+ options are added to the default options (eg. "CONFIGURATIONS Release")
+ ``NO_UNITTEST_FRAMEWORK``
+ when set, indicates that the test should not
+ use the unittest framework of Matlab (available for versions >= R2013a).
+ ``WORKING_DIRECTORY``
+ This will be the working directory for the test. If specified it will
+ also be the output directory used for the log file of the test run.
+ If not specified the temporary directory ``${CMAKE_BINARY_DIR}/Matlab`` will
+ be used as the working directory and the log location.
+
+#]=======================================================================]
function(matlab_add_unit_test)
if(NOT Matlab_MAIN_PROGRAM)
@@ -806,58 +865,65 @@ function(matlab_add_unit_test)
endfunction()
-#.rst:
-# .. command:: matlab_add_mex
-#
-# Adds a Matlab MEX target.
-# This commands compiles the given sources with the current tool-chain in
-# order to produce a MEX file. The final name of the produced output may be
-# specified, as well as additional link libraries, and a documentation entry
-# for the MEX file. Remaining arguments of the call are passed to the
-# :command:`add_library` or :command:`add_executable` command.
-#
-# ::
-#
-# matlab_add_mex(
-# NAME <name>
-# [EXECUTABLE | MODULE | SHARED]
-# SRC src1 [src2 ...]
-# [OUTPUT_NAME output_name]
-# [DOCUMENTATION file.txt]
-# [LINK_TO target1 target2 ...]
-# [...]
-# )
-#
-# ``NAME``
-# name of the target.
-# ``SRC``
-# list of source files.
-# ``LINK_TO``
-# a list of additional link dependencies. The target links to ``libmex``
-# by default. If ``Matlab_MX_LIBRARY`` is defined, it also
-# links to ``libmx``.
-# ``OUTPUT_NAME``
-# if given, overrides the default name. The default name is
-# the name of the target without any prefix and
-# with ``Matlab_MEX_EXTENSION`` suffix.
-# ``DOCUMENTATION``
-# if given, the file ``file.txt`` will be considered as
-# being the documentation file for the MEX file. This file is copied into
-# the same folder without any processing, with the same name as the final
-# mex file, and with extension `.m`. In that case, typing ``help <name>``
-# in Matlab prints the documentation contained in this file.
-# ``MODULE`` or ``SHARED`` may be given to specify the type of library to be
-# created. ``EXECUTABLE`` may be given to create an executable instead of
-# a library. If no type is given explicitly, the type is ``SHARED``.
-#
-# The documentation file is not processed and should be in the following
-# format:
-#
-# ::
-#
-# % This is the documentation
-# function ret = mex_target_output_name(input1)
-#
+#[=======================================================================[.rst:
+.. command:: matlab_add_mex
+
+ Adds a Matlab MEX target.
+ This commands compiles the given sources with the current tool-chain in
+ order to produce a MEX file. The final name of the produced output may be
+ specified, as well as additional link libraries, and a documentation entry
+ for the MEX file. Remaining arguments of the call are passed to the
+ :command:`add_library` or :command:`add_executable` command.
+
+ ::
+
+ matlab_add_mex(
+ NAME <name>
+ [EXECUTABLE | MODULE | SHARED]
+ SRC src1 [src2 ...]
+ [OUTPUT_NAME output_name]
+ [DOCUMENTATION file.txt]
+ [LINK_TO target1 target2 ...]
+ [R2017b | R2018a]
+ [...]
+ )
+
+ ``NAME``
+ name of the target.
+ ``SRC``
+ list of source files.
+ ``LINK_TO``
+ a list of additional link dependencies. The target links to ``libmex``
+ and ``libmx`` by default.
+ ``OUTPUT_NAME``
+ if given, overrides the default name. The default name is
+ the name of the target without any prefix and
+ with ``Matlab_MEX_EXTENSION`` suffix.
+ ``DOCUMENTATION``
+ if given, the file ``file.txt`` will be considered as
+ being the documentation file for the MEX file. This file is copied into
+ the same folder without any processing, with the same name as the final
+ mex file, and with extension `.m`. In that case, typing ``help <name>``
+ in Matlab prints the documentation contained in this file.
+ ``R2017b`` or ``R2018a`` may be given to specify the version of the C API
+ to use: ``R2017b`` specifies the traditional (separate complex) C API,
+ and corresponds to the ``-R2017b`` flag for the `mex` command. ``R2018a``
+ specifies the new interleaved complex C API, and corresponds to the
+ ``-R2018a`` flag for the `mex` command. Ignored if MATLAB version prior
+ to R2018a. Defaults to ``R2017b``.
+ ``MODULE`` or ``SHARED`` may be given to specify the type of library to be
+ created. ``EXECUTABLE`` may be given to create an executable instead of
+ a library. If no type is given explicitly, the type is ``SHARED``.
+
+ The documentation file is not processed and should be in the following
+ format:
+
+ ::
+
+ % This is the documentation
+ function ret = mex_target_output_name(input1)
+
+#]=======================================================================]
function(matlab_add_mex)
if(NOT WIN32)
@@ -874,7 +940,7 @@ function(matlab_add_mex)
endif()
- set(options EXECUTABLE MODULE SHARED)
+ set(options EXECUTABLE MODULE SHARED R2017b R2018a)
set(oneValueArgs NAME DOCUMENTATION OUTPUT_NAME)
set(multiValueArgs LINK_TO SRC)
@@ -889,9 +955,25 @@ function(matlab_add_mex)
set(${prefix}_OUTPUT_NAME ${${prefix}_NAME})
endif()
+ if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, add version source file
+ # TODO: check the file extensions in ${${prefix}_SRC} to see if they're C or C++ files
+ # Currently, the C and C++ versions of the version files are identical, so this doesn't matter.
+ set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/c_mexapi_version.c")
+ #set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/cpp_mexapi_version.cpp")
+ endif()
+
+ if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.4") # For 9.4 (R2018a) and newer, add API macro
+ if(${${prefix}_R2018a})
+ set(MEX_API_MACRO "MATLAB_DEFAULT_RELEASE=R2018a")
+ else()
+ set(MEX_API_MACRO "MATLAB_DEFAULT_RELEASE=R2017b")
+ endif()
+ endif()
+
if(${prefix}_EXECUTABLE)
add_executable(${${prefix}_NAME}
${${prefix}_SRC}
+ ${MEX_VERSION_FILE}
${${prefix}_DOCUMENTATION}
${${prefix}_UNPARSED_ARGUMENTS})
else()
@@ -904,23 +986,25 @@ function(matlab_add_mex)
add_library(${${prefix}_NAME}
${type}
${${prefix}_SRC}
+ ${MEX_VERSION_FILE}
${${prefix}_DOCUMENTATION}
${${prefix}_UNPARSED_ARGUMENTS})
endif()
target_include_directories(${${prefix}_NAME} PRIVATE ${Matlab_INCLUDE_DIRS})
- if(DEFINED Matlab_MX_LIBRARY)
- target_link_libraries(${${prefix}_NAME} ${Matlab_MX_LIBRARY})
+ if(Matlab_HAS_CPP_API)
+ target_link_libraries(${${prefix}_NAME} ${Matlab_ENGINE_LIBRARY} ${Matlab_DATAARRAY_LIBRARY})
endif()
- target_link_libraries(${${prefix}_NAME} ${Matlab_MEX_LIBRARY} ${${prefix}_LINK_TO})
+ target_link_libraries(${${prefix}_NAME} ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY} ${${prefix}_LINK_TO})
set_target_properties(${${prefix}_NAME}
PROPERTIES
PREFIX ""
OUTPUT_NAME ${${prefix}_OUTPUT_NAME}
SUFFIX ".${Matlab_MEX_EXTENSION}")
+ target_compile_definitions(${${prefix}_NAME} PRIVATE ${MEX_API_MACRO} MATLAB_MEX_FILE)
# documentation
if(NOT ${${prefix}_DOCUMENTATION} STREQUAL "")
@@ -929,73 +1013,87 @@ function(matlab_add_mex)
TARGET ${${prefix}_NAME}
PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${${prefix}_DOCUMENTATION} $<TARGET_FILE_DIR:${${prefix}_NAME}>/${output_name}.m
- COMMENT "Copy ${${prefix}_NAME} documentation file into the output folder"
+ COMMENT "[MATLAB] Copy ${${prefix}_NAME} documentation file into the output folder"
)
endif() # documentation
# entry point in the mex file + taking care of visibility and symbol clashes.
if(WIN32)
+
+ if (MSVC)
+
+ set(_link_flags "${_link_flags} /EXPORT:mexFunction")
+ if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, export version
+ set(_link_flags "${_link_flags} /EXPORT:mexfilerequiredapiversion")
+ endif()
+
+ if(Matlab_HAS_CPP_API)
+ set(_link_flags "${_link_flags} /EXPORT:mexCreateMexFunction /EXPORT:mexDestroyMexFunction /EXPORT:mexFunctionAdapter")
+ #TODO: Is this necessary?
+ endif()
+
+ set_property(TARGET ${${prefix}_NAME} APPEND PROPERTY LINK_FLAGS ${_link_flags})
+
+ endif() # TODO: what if there's a different compiler on Windows?
+
set_target_properties(${${prefix}_NAME}
PROPERTIES
DEFINE_SYMBOL "DLL_EXPORT_SYM=__declspec(dllexport)")
+
else()
- if(HAS_MINUS_PTHREAD AND NOT APPLE)
- # Apparently, compiling with -pthread generated the proper link flags
- # and some defines at compilation
- target_compile_options(${${prefix}_NAME} PRIVATE "-pthread")
+ if(${Matlab_VERSION_STRING} VERSION_LESS "9.1") # For versions prior to 9.1 (R2016b)
+ set(_ver_map_files ${Matlab_EXTERN_LIBRARY_DIR}/mexFunction.map)
+ else() # For 9.1 (R2016b) and newer
+ set(_ver_map_files ${Matlab_EXTERN_LIBRARY_DIR}/c_exportsmexfileversion.map)
endif()
+ if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.5") # For 9.5 (R2018b) (and newer?)
+ target_compile_options(${${prefix}_NAME} PRIVATE "-fvisibility=default")
+ # This one is weird, it might be a bug in <mex.h> for R2018b. When compiling with
+ # -fvisibility=hidden, the symbol `mexFunction` cannot be exported. Reading the
+ # source code for <mex.h>, it seems that the preprocessor macro `MW_NEEDS_VERSION_H`
+ # needs to be defined for `__attribute__ ((visibility("default")))` to be added
+ # in front of the declaration of `mexFunction`. In previous versions of MATLAB this
+ # was not the case, there `DLL_EXPORT_SYM` needed to be defined.
+ # Adding `-fvisibility=hidden` to the `mex` command causes the build to fail.
+ # TODO: Check that this is still necessary in R2019a when it comes out.
+ endif()
- # if we do not do that, the symbols linked from eg. boost remain weak and
- # then clash with the ones defined in the matlab process. So by default
- # the symbols are hidden.
- # This also means that for shared libraries (like MEX), the entry point
- # should be explicitly declared with default visibility, otherwise Matlab
- # cannot find the entry point.
- # Note that this is particularly meaningful if the MEX wrapper itself
- # contains symbols that are clashing with Matlab (that are compiled in the
- # MEX file). In order to propagate the visibility options to the libraries
- # to which the MEX file is linked against, the -Wl,--exclude-libs,ALL
- # option should also be specified.
+ if(APPLE)
- set_target_properties(${${prefix}_NAME}
- PROPERTIES
- CXX_VISIBILITY_PRESET "hidden"
- C_VISIBILITY_PRESET "hidden"
- VISIBILITY_INLINES_HIDDEN ON
- )
+ if(Matlab_HAS_CPP_API)
+ list(APPEND _ver_map_files ${Matlab_EXTERN_LIBRARY_DIR}/cppMexFunction.map) # This one doesn't exist on Linux
+ set(_link_flags "${_link_flags} -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter")
+ # On MacOS, the MEX command adds the above, without it the link breaks
+ # because we indiscriminately use "cppMexFunction.map" even for C API MEX-files.
+ endif()
+
+ set(_export_flag_name -exported_symbols_list)
+
+ else() # Linux
+
+ if(HAS_MINUS_PTHREAD)
+ # Apparently, compiling with -pthread generated the proper link flags
+ # and some defines at compilation
+ target_compile_options(${${prefix}_NAME} PRIVATE "-pthread")
+ endif()
+
+ set(_link_flags "${_link_flags} -Wl,--as-needed")
- # get_target_property(
- # _previous_link_flags
- # ${${prefix}_NAME}
- # LINK_FLAGS)
- # if(NOT _previous_link_flags)
- # set(_previous_link_flags)
- # endif()
-
- # if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
- # set_target_properties(${${prefix}_NAME}
- # PROPERTIES
- # LINK_FLAGS "${_previous_link_flags} -Wl,--exclude-libs,ALL"
- # # -Wl,--version-script=${_FindMatlab_SELF_DIR}/MatlabLinuxVisibility.map"
- # )
- # elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- # # in this case, all other symbols become hidden.
- # set_target_properties(${${prefix}_NAME}
- # PROPERTIES
- # LINK_FLAGS "${_previous_link_flags} -Wl,-exported_symbol,_mexFunction"
- # #-Wl,-exported_symbols_list,${_FindMatlab_SELF_DIR}/MatlabOSXVisilibity.map"
- # )
- # endif()
+ set(_export_flag_name --version-script)
+ endif()
+ foreach(_file ${_ver_map_files})
+ set(_link_flags "${_link_flags} -Wl,${_export_flag_name},${_file}")
+ endforeach()
set_target_properties(${${prefix}_NAME}
PROPERTIES
DEFINE_SYMBOL "DLL_EXPORT_SYM=__attribute__ ((visibility (\"default\")))"
- )
-
+ LINK_FLAGS "${_link_flags}"
+ ) # The `mex` command doesn't add this define. Is it necessary?
endif()
@@ -1005,10 +1103,10 @@ endfunction()
# (internal)
# Used to get the version of matlab, using caching. This basically transforms the
# output of the root list, with possible unknown version, to a version
-#
-function(_Matlab_get_version_from_root matlab_root matlab_known_version matlab_final_version)
+# This can possibly run Matlab for extracting the version.
+function(_Matlab_get_version_from_root matlab_root matlab_or_mcr matlab_known_version matlab_final_version)
- # if the version is not trivial, we query matlab for that
+ # if the version is not trivial, we query matlab (if not MCR) for that
# we keep track of the location of matlab that induced this version
#if(NOT DEFINED Matlab_PROG_VERSION_STRING_AUTO_DETECT)
# set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version")
@@ -1021,174 +1119,211 @@ function(_Matlab_get_version_from_root matlab_root matlab_known_version matlab_f
return()
endif()
- #
- set(_matlab_current_program ${Matlab_MAIN_PROGRAM})
-
- # do we already have a matlab program?
- if(NOT _matlab_current_program)
-
- set(_find_matlab_options)
- if(matlab_root AND EXISTS ${matlab_root})
- set(_find_matlab_options PATHS ${matlab_root} ${matlab_root}/bin NO_DEFAULT_PATH)
+ if("${matlab_or_mcr}" STREQUAL "UNKNOWN")
+ if(MATLAB_FIND_DEBUG)
+ message(WARNING "[MATLAB] Determining Matlab or MCR")
endif()
- find_program(
- _matlab_current_program
- matlab
- ${_find_matlab_options}
- DOC "Matlab main program"
- )
- endif()
+ if(EXISTS "${matlab_root}/appdata/version.xml")
+ # we inspect the application version.xml file that contains the product information
+ file(STRINGS "${matlab_root}/appdata/version.xml" productinfo_string NEWLINE_CONSUME)
+ string(REGEX MATCH "<installedProductData.*displayedString=\"([a-zA-Z ]+)\".*/>"
+ product_reg_match
+ ${productinfo_string}
+ )
+
+ # default fallback to Matlab
+ set(matlab_or_mcr "MATLAB")
+ if(NOT "${CMAKE_MATCH_1}" STREQUAL "")
+ string(TOLOWER "${CMAKE_MATCH_1}" product_reg_match)
+
+ if("${product_reg_match}" STREQUAL "matlab runtime")
+ set(matlab_or_mcr "MCR")
+ endif()
+ endif()
+ endif()
- if(NOT _matlab_current_program OR NOT EXISTS ${_matlab_current_program})
- # if not found, clear the dependent variables
if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Cannot find the main matlab program under ${matlab_root}")
+ message(WARNING "[MATLAB] '${matlab_root}' contains the '${matlab_or_mcr}'")
endif()
- set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
- set(Matlab_VERSION_STRING_INTERNAL "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
- unset(_matlab_current_program)
- unset(_matlab_current_program CACHE)
- return()
endif()
- # full real path for path comparison
- get_filename_component(_matlab_main_real_path_tmp "${_matlab_current_program}" REALPATH)
- unset(_matlab_current_program)
- unset(_matlab_current_program CACHE)
+ # UNKNOWN is the default behaviour in case we
+ # - have an erroneous matlab_root
+ # - have an initial 'UNKNOWN'
+ if("${matlab_or_mcr}" STREQUAL "MATLAB" OR "${matlab_or_mcr}" STREQUAL "UNKNOWN")
+ # MATLAB versions
+ set(_matlab_current_program ${Matlab_MAIN_PROGRAM})
- # is it the same as the previous one?
- if(_matlab_main_real_path_tmp STREQUAL Matlab_PROG_VERSION_STRING_AUTO_DETECT)
- set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE)
- return()
- endif()
+ # do we already have a matlab program?
+ if(NOT _matlab_current_program)
- # update the location of the program
- set(Matlab_PROG_VERSION_STRING_AUTO_DETECT ${_matlab_main_real_path_tmp} CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
-
- set(matlab_list_of_all_versions)
- matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions)
+ set(_find_matlab_options)
+ if(matlab_root AND EXISTS ${matlab_root})
+ set(_find_matlab_options PATHS ${matlab_root} ${matlab_root}/bin NO_DEFAULT_PATH)
+ endif()
- list(LENGTH matlab_list_of_all_versions list_of_all_versions_length)
- if(${list_of_all_versions_length} GREATER 0)
- list(GET matlab_list_of_all_versions 0 _matlab_version_tmp)
- else()
- set(_matlab_version_tmp "unknown")
- endif()
+ find_program(
+ _matlab_current_program
+ matlab
+ ${_find_matlab_options}
+ DOC "Matlab main program"
+ )
+ endif()
- # set the version into the cache
- set(Matlab_VERSION_STRING_INTERNAL ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
+ if(NOT _matlab_current_program OR NOT EXISTS ${_matlab_current_program})
+ # if not found, clear the dependent variables
+ if(MATLAB_FIND_DEBUG)
+ message(WARNING "[MATLAB] Cannot find the main matlab program under ${matlab_root}")
+ endif()
+ set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
+ set(Matlab_VERSION_STRING_INTERNAL "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
+ unset(_matlab_current_program)
+ unset(_matlab_current_program CACHE)
+ return()
+ endif()
- # warning, just in case several versions found (should not happen)
- if((${list_of_all_versions_length} GREATER 1) AND MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Found several versions, taking the first one (versions found ${matlab_list_of_all_versions})")
- endif()
+ # full real path for path comparison
+ get_filename_component(_matlab_main_real_path_tmp "${_matlab_current_program}" REALPATH)
+ unset(_matlab_current_program)
+ unset(_matlab_current_program CACHE)
- # return the updated value
- set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE)
+ # is it the same as the previous one?
+ if(_matlab_main_real_path_tmp STREQUAL Matlab_PROG_VERSION_STRING_AUTO_DETECT)
+ set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE)
+ return()
+ endif()
-endfunction()
+ # update the location of the program
+ set(Matlab_PROG_VERSION_STRING_AUTO_DETECT
+ ${_matlab_main_real_path_tmp}
+ CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
+ set(matlab_list_of_all_versions)
+ matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions)
+ list(LENGTH matlab_list_of_all_versions list_of_all_versions_length)
+ if(${list_of_all_versions_length} GREATER 0)
+ list(GET matlab_list_of_all_versions 0 _matlab_version_tmp)
+ else()
+ set(_matlab_version_tmp "unknown")
+ endif()
+ # set the version into the cache
+ set(Matlab_VERSION_STRING_INTERNAL ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
+ # warning, just in case several versions found (should not happen)
+ if((${list_of_all_versions_length} GREATER 1) AND MATLAB_FIND_DEBUG)
+ message(WARNING "[MATLAB] Found several versions, taking the first one (versions found ${matlab_list_of_all_versions})")
+ endif()
+ # return the updated value
+ set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE)
+ elseif(EXISTS "${matlab_root}/VersionInfo.xml")
+ # MCR
+ # we cannot run anything in order to extract the version. We assume that the file
+ # VersionInfo.xml exists under the MatlabRoot, we look for it and extract the version from there
+ set(_matlab_version_tmp "unknown")
+ file(STRINGS "${matlab_root}/VersionInfo.xml" versioninfo_string NEWLINE_CONSUME)
+
+ if(versioninfo_string)
+ # parses "<version>9.2.0.538062</version>"
+ string(REGEX MATCH "<version>(.*)</version>"
+ version_reg_match
+ ${versioninfo_string}
+ )
+
+ if(NOT "${version_reg_match}" STREQUAL "")
+ if("${CMAKE_MATCH_1}" MATCHES "(([0-9])\\.([0-9]))[\\.0-9]*")
+ set(_matlab_version_tmp "${CMAKE_MATCH_1}")
+ endif()
+ endif()
+ endif()
+ set(${matlab_final_version} "${_matlab_version_tmp}" PARENT_SCOPE)
+ set(Matlab_VERSION_STRING_INTERNAL
+ "${_matlab_version_tmp}"
+ CACHE INTERNAL "Matlab (MCR) version (automatically determined)"
+ FORCE)
+ endif() # Matlab or MCR
+endfunction()
-# ###################################
-# Exploring the possible Matlab_ROOTS
-# this variable will get all Matlab installations found in the current system.
-set(_matlab_possible_roots)
+# Utility function for finding Matlab or MCR on Win32
+function(_Matlab_find_instances_win32 matlab_roots)
+ # On WIN32, we look for Matlab installation in the registry
+ # if unsuccessful, we look for all known revision and filter the existing
+ # ones.
+ # testing if we are able to extract the needed information from the registry
+ set(_matlab_versions_from_registry)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_matlab_win64 ON)
+ else()
+ set(_matlab_win64 OFF)
+ endif()
-if(Matlab_ROOT_DIR)
- # if the user specifies a possible root, we keep this one
+ matlab_extract_all_installed_versions_from_registry(_matlab_win64 _matlab_versions_from_registry)
- if(NOT EXISTS ${Matlab_ROOT_DIR})
- # if Matlab_ROOT_DIR specified but erroneous
+ # the returned list is empty, doing the search on all known versions
+ if(NOT _matlab_versions_from_registry)
if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] the specified path for Matlab_ROOT_DIR does not exist (${Matlab_ROOT_DIR})")
- endif()
- else()
- # NOTFOUND indicates the code below to search for the version automatically
- if("${Matlab_VERSION_STRING_INTERNAL}" STREQUAL "")
- list(APPEND _matlab_possible_roots "NOTFOUND" ${Matlab_ROOT_DIR}) # empty version
- else()
- list(APPEND _matlab_possible_roots ${Matlab_VERSION_STRING_INTERNAL} ${Matlab_ROOT_DIR}) # cached version
+ message(STATUS "[MATLAB] Search for Matlab from the registry unsuccessful, testing all supported versions")
endif()
+ extract_matlab_versions_from_registry_brute_force(_matlab_versions_from_registry)
endif()
+ # filtering the results with the registry keys
+ matlab_get_all_valid_matlab_roots_from_registry("${_matlab_versions_from_registry}" _matlab_possible_roots)
+ set(${matlab_roots} ${_matlab_possible_roots} PARENT_SCOPE)
-else()
-
- # if the user does not specify the possible installation root, we look for
- # one installation using the appropriate heuristics
-
- if(WIN32)
+endfunction()
- # On WIN32, we look for Matlab installation in the registry
- # if unsuccessful, we look for all known revision and filter the existing
- # ones.
+# Utility function for finding Matlab or MCR on OSX
+function(_Matlab_find_instances_osx matlab_roots)
- # testing if we are able to extract the needed information from the registry
- set(_matlab_versions_from_registry)
- matlab_extract_all_installed_versions_from_registry(CMAKE_CL_64 _matlab_versions_from_registry)
+ set(_matlab_possible_roots)
+ # on mac, we look for the /Application paths
+ # this corresponds to the behaviour on Windows. On Linux, we do not have
+ # any other guess.
+ matlab_get_supported_releases(_matlab_releases)
+ if(MATLAB_FIND_DEBUG)
+ message(STATUS "[MATLAB] Matlab supported versions ${_matlab_releases}. If more version should be supported "
+ "the variable MATLAB_ADDITIONAL_VERSIONS can be set according to the documentation")
+ endif()
- # the returned list is empty, doing the search on all known versions
- if(NOT _matlab_versions_from_registry)
+ foreach(_matlab_current_release IN LISTS _matlab_releases)
+ matlab_get_version_from_release_name("${_matlab_current_release}" _matlab_current_version)
+ string(REPLACE "." "" _matlab_current_version_without_dot "${_matlab_current_version}")
+ set(_matlab_base_path "/Applications/MATLAB_${_matlab_current_release}.app")
+ # Check Matlab, has precedence over MCR
+ if(EXISTS ${_matlab_base_path})
if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Search for Matlab from the registry unsuccessful, testing all supported versions")
+ message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_base_path}")
endif()
-
- extract_matlab_versions_from_registry_brute_force(_matlab_versions_from_registry)
+ list(APPEND _matlab_possible_roots "MATLAB" ${_matlab_current_version} ${_matlab_base_path})
endif()
- # filtering the results with the registry keys
- matlab_get_all_valid_matlab_roots_from_registry("${_matlab_versions_from_registry}" _matlab_possible_roots)
- unset(_matlab_versions_from_registry)
-
- elseif(APPLE)
-
- # on mac, we look for the /Application paths
- # this corresponds to the behaviour on Windows. On Linux, we do not have
- # any other guess.
- matlab_get_supported_releases(_matlab_releases)
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Matlab supported versions ${_matlab_releases}. If more version should be supported "
- "the variable MATLAB_ADDITIONAL_VERSIONS can be set according to the documentation")
- endif()
-
- foreach(_matlab_current_release IN LISTS _matlab_releases)
- set(_matlab_full_string "/Applications/MATLAB_${_matlab_current_release}.app")
- if(EXISTS ${_matlab_full_string})
- set(_matlab_current_version)
- matlab_get_version_from_release_name("${_matlab_current_release}" _matlab_current_version)
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_full_string}")
- endif()
- list(APPEND _matlab_possible_roots ${_matlab_current_version} ${_matlab_full_string})
- unset(_matlab_current_version)
+ # Checks MCR
+ set(_mcr_path "/Applications/MATLAB/MATLAB_Runtime/v${_matlab_current_version_without_dot}")
+ if(EXISTS "${_mcr_path}")
+ if(MATLAB_FIND_DEBUG)
+ message(STATUS "[MATLAB] Found MCR version ${_matlab_current_release} (${_matlab_current_version}) in ${_mcr_path}")
endif()
+ list(APPEND _matlab_possible_roots "MCR" ${_matlab_current_version} ${_mcr_path})
+ endif()
- unset(_matlab_full_string)
- endforeach(_matlab_current_release)
-
- unset(_matlab_current_release)
- unset(_matlab_releases)
+ endforeach()
+ set(${matlab_roots} ${_matlab_possible_roots} PARENT_SCOPE)
- endif()
-
-endif()
+endfunction()
+# Utility function for finding Matlab or MCR from the PATH
+function(_Matlab_find_instances_from_path matlab_roots)
-
-list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots)
-if(_numbers_of_matlab_roots EQUAL 0)
- # if we have not found anything, we fall back on the PATH
-
+ set(_matlab_possible_roots)
# At this point, we have no other choice than trying to find it from PATH.
# If set by the user, this wont change
@@ -1196,7 +1331,6 @@ if(_numbers_of_matlab_roots EQUAL 0)
_matlab_main_tmp
NAMES matlab)
-
if(_matlab_main_tmp)
# we then populate the list of roots, with empty version
if(MATLAB_FIND_DEBUG)
@@ -1211,17 +1345,88 @@ if(_numbers_of_matlab_roots EQUAL 0)
get_filename_component(_matlab_current_location "${_matlab_current_location}" DIRECTORY)
get_filename_component(_matlab_current_location "${_matlab_current_location}" DIRECTORY) # Matlab should be in bin
- list(APPEND _matlab_possible_roots "NOTFOUND" ${_matlab_current_location})
+ # We found the Matlab program
+ list(APPEND _matlab_possible_roots "MATLAB" "NOTFOUND" ${_matlab_current_location})
+
+ # we remove this from the CACHE
+ unset(_matlab_main_tmp CACHE)
+ else()
+ find_program(
+ _matlab_mex_tmp
+ NAMES mex)
+ if(_matlab_mex_tmp)
+ # we then populate the list of roots, with empty version
+ if(MATLAB_FIND_DEBUG)
+ message(STATUS "[MATLAB] mex compiler found from PATH: ${_matlab_mex_tmp}")
+ endif()
+
+ # resolve symlinks
+ get_filename_component(_mex_current_location "${_matlab_mex_tmp}" REALPATH)
+
+ # get the directory (the command below has to be run twice)
+ # this will be the matlab root
+ get_filename_component(_mex_current_location "${_mex_current_location}" DIRECTORY)
+ get_filename_component(_mex_current_location "${_mex_current_location}" DIRECTORY) # Matlab Runtime mex compiler should be in bin
+
+ # We found the Matlab program
+ list(APPEND _matlab_possible_roots "MCR" "NOTFOUND" ${_mex_current_location})
+
+ unset(_matlab_mex_tmp CACHE)
+ else()
+ if(MATLAB_FIND_DEBUG)
+ message(STATUS "[MATLAB] mex compiler not found")
+ endif()
+ endif()
- unset(_matlab_current_location)
endif()
- unset(_matlab_main_tmp CACHE)
-endif()
+ set(${matlab_roots} ${_matlab_possible_roots} PARENT_SCOPE)
+endfunction()
+# ###################################
+# Exploring the possible Matlab_ROOTS
+# this variable will get all Matlab installations found in the current system.
+set(_matlab_possible_roots)
+
+if(Matlab_ROOT_DIR)
+ # if the user specifies a possible root, we keep this one
+
+ if(NOT EXISTS "${Matlab_ROOT_DIR}")
+ # if Matlab_ROOT_DIR specified but erroneous
+ if(MATLAB_FIND_DEBUG)
+ message(WARNING "[MATLAB] the specified path for Matlab_ROOT_DIR does not exist (${Matlab_ROOT_DIR})")
+ endif()
+ else()
+ # NOTFOUND indicates the code below to search for the version automatically
+ if("${Matlab_VERSION_STRING_INTERNAL}" STREQUAL "")
+ list(APPEND _matlab_possible_roots "UNKNOWN" "NOTFOUND" ${Matlab_ROOT_DIR}) # empty version, empty MCR/Matlab indication
+ else()
+ list(APPEND _matlab_possible_roots "UNKNOWN" ${Matlab_VERSION_STRING_INTERNAL} ${Matlab_ROOT_DIR}) # cached version
+ endif()
+ endif()
+else()
+
+ # if the user does not specify the possible installation root, we look for
+ # one installation using the appropriate heuristics.
+ # There is apparently no standard way on Linux.
+ if(CMAKE_HOST_WIN32)
+ _Matlab_find_instances_win32(_matlab_possible_roots_win32)
+ list(APPEND _matlab_possible_roots ${_matlab_possible_roots_win32})
+ elseif(APPLE)
+ _Matlab_find_instances_osx(_matlab_possible_roots_osx)
+ list(APPEND _matlab_possible_roots ${_matlab_possible_roots_osx})
+ endif()
+endif()
+
+
+list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots)
+if(_numbers_of_matlab_roots EQUAL 0)
+ # if we have not found anything, we fall back on the PATH
+ _Matlab_find_instances_from_path(_matlab_possible_roots)
+endif()
if(MATLAB_FIND_DEBUG)
@@ -1235,12 +1440,14 @@ endif()
# take the first possible Matlab root
list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots)
set(Matlab_VERSION_STRING "NOTFOUND")
+set(Matlab_Or_MCR "UNKNOWN")
if(_numbers_of_matlab_roots GREATER 0)
- list(GET _matlab_possible_roots 0 Matlab_VERSION_STRING)
- list(GET _matlab_possible_roots 1 Matlab_ROOT_DIR)
+ list(GET _matlab_possible_roots 0 Matlab_Or_MCR)
+ list(GET _matlab_possible_roots 1 Matlab_VERSION_STRING)
+ list(GET _matlab_possible_roots 2 Matlab_ROOT_DIR)
# adding a warning in case of ambiguity
- if(_numbers_of_matlab_roots GREATER 2 AND MATLAB_FIND_DEBUG)
+ if(_numbers_of_matlab_roots GREATER 3 AND MATLAB_FIND_DEBUG)
message(WARNING "[MATLAB] Found several distributions of Matlab. Setting the current version to ${Matlab_VERSION_STRING} (located ${Matlab_ROOT_DIR})."
" If this is not the desired behaviour, provide the -DMatlab_ROOT_DIR=... on the command line")
endif()
@@ -1253,13 +1460,17 @@ if(DEFINED Matlab_ROOT_DIR_LAST_CACHED)
if(NOT Matlab_ROOT_DIR_LAST_CACHED STREQUAL Matlab_ROOT_DIR)
set(_Matlab_cached_vars
+ Matlab_VERSION_STRING
Matlab_INCLUDE_DIRS
Matlab_MEX_LIBRARY
Matlab_MEX_COMPILER
+ Matlab_MCC_COMPILER
Matlab_MAIN_PROGRAM
Matlab_MX_LIBRARY
Matlab_ENG_LIBRARY
Matlab_MAT_LIBRARY
+ Matlab_ENGINE_LIBRARY
+ Matlab_DATAARRAY_LIBRARY
Matlab_MEX_EXTENSION
Matlab_SIMULINK_INCLUDE_DIR
@@ -1267,7 +1478,7 @@ if(DEFINED Matlab_ROOT_DIR_LAST_CACHED)
Matlab_MEXEXTENSIONS_PROG
Matlab_ROOT_DIR_LAST_CACHED
#Matlab_PROG_VERSION_STRING_AUTO_DETECT
- Matlab_VERSION_STRING_INTERNAL
+ #Matlab_VERSION_STRING_INTERNAL
)
foreach(_var IN LISTS _Matlab_cached_vars)
if(DEFINED ${_var})
@@ -1283,18 +1494,18 @@ set(Matlab_ROOT_DIR ${Matlab_ROOT_DIR} CACHE PATH "Matlab installation root path
# Fix the version, in case this one is NOTFOUND
_Matlab_get_version_from_root(
"${Matlab_ROOT_DIR}"
+ "${Matlab_Or_MCR}"
${Matlab_VERSION_STRING}
Matlab_VERSION_STRING
)
-
-
-
if(MATLAB_FIND_DEBUG)
message(STATUS "[MATLAB] Current version is ${Matlab_VERSION_STRING} located ${Matlab_ROOT_DIR}")
endif()
-
+if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.4") # MATLAB 9.4 (R2018a) and newer have a new C++ API
+ set(Matlab_HAS_CPP_API 1)
+endif()
if(Matlab_ROOT_DIR)
file(TO_CMAKE_PATH ${Matlab_ROOT_DIR} Matlab_ROOT_DIR)
@@ -1333,6 +1544,8 @@ set(Matlab_BINARIES_DIR
${Matlab_ROOT_DIR}/bin/${_matlab_bin_prefix}${_matlab_current_suffix})
set(Matlab_EXTERN_LIBRARY_DIR
${Matlab_ROOT_DIR}/extern/lib/${_matlab_bin_prefix}${_matlab_current_suffix})
+set(Matlab_EXTERN_BINARIES_DIR
+ ${Matlab_ROOT_DIR}/extern/bin/${_matlab_bin_prefix}${_matlab_current_suffix})
if(WIN32)
if(MINGW)
@@ -1342,7 +1555,7 @@ if(WIN32)
endif()
set(_matlab_lib_prefix_for_search "lib")
else()
- set(_matlab_lib_dir_for_search ${Matlab_BINARIES_DIR})
+ set(_matlab_lib_dir_for_search ${Matlab_BINARIES_DIR} ${Matlab_EXTERN_BINARIES_DIR})
set(_matlab_lib_prefix_for_search "lib")
endif()
@@ -1393,7 +1606,6 @@ _Matlab_find_library(
PATHS ${_matlab_lib_dir_for_search}
NO_DEFAULT_PATH
)
-
list(APPEND _matlab_required_variables Matlab_MEX_LIBRARY)
# the MEX extension is required
@@ -1434,21 +1646,18 @@ if(_matlab_find_matlab_program GREATER -1)
endif()
unset(_matlab_find_matlab_program)
-# Component MX library
-list(FIND Matlab_FIND_COMPONENTS MX_LIBRARY _matlab_find_mx)
-if(_matlab_find_mx GREATER -1)
- _Matlab_find_library(
- ${_matlab_lib_prefix_for_search}
- Matlab_MX_LIBRARY
- mx
- PATHS ${_matlab_lib_dir_for_search}
- NO_DEFAULT_PATH
- )
- if(Matlab_MX_LIBRARY)
- set(Matlab_MX_LIBRARY_FOUND TRUE)
- endif()
+# The MX library is required
+_Matlab_find_library(
+ ${_matlab_lib_prefix_for_search}
+ Matlab_MX_LIBRARY
+ mx
+ PATHS ${_matlab_lib_dir_for_search}
+ NO_DEFAULT_PATH
+)
+list(APPEND _matlab_required_variables Matlab_MX_LIBRARY)
+if(Matlab_MX_LIBRARY)
+ set(Matlab_MX_LIBRARY_FOUND TRUE)
endif()
-unset(_matlab_find_mx)
# Component ENG library
list(FIND Matlab_FIND_COMPONENTS ENG_LIBRARY _matlab_find_eng)
@@ -1498,9 +1707,60 @@ if(_matlab_find_simulink GREATER -1)
endif()
unset(_matlab_find_simulink)
+# component MCC Compiler
+list(FIND Matlab_FIND_COMPONENTS MCC_COMPILER _matlab_find_mcc_compiler)
+if(_matlab_find_mcc_compiler GREATER -1)
+ find_program(
+ Matlab_MCC_COMPILER
+ "mcc"
+ PATHS ${Matlab_BINARIES_DIR}
+ DOC "Matlab MCC compiler"
+ NO_DEFAULT_PATH
+ )
+ if(Matlab_MCC_COMPILER)
+ set(Matlab_MCC_COMPILER_FOUND TRUE)
+ endif()
+endif()
+unset(_matlab_find_mcc_compiler)
+
+if(Matlab_HAS_CPP_API)
+
+ # The MatlabEngine library is required for R2018a+
+ _Matlab_find_library(
+ ${_matlab_lib_prefix_for_search}
+ Matlab_ENGINE_LIBRARY
+ MatlabEngine
+ PATHS ${_matlab_lib_dir_for_search}
+ DOC "MatlabEngine Library"
+ NO_DEFAULT_PATH
+ )
+ list(APPEND _matlab_required_variables Matlab_ENGINE_LIBRARY)
+ if(Matlab_ENGINE_LIBRARY)
+ set(Matlab_ENGINE_LIBRARY_FOUND TRUE)
+ endif()
+
+ # The MatlabDataArray library is required for R2018a+
+ _Matlab_find_library(
+ ${_matlab_lib_prefix_for_search}
+ Matlab_DATAARRAY_LIBRARY
+ MatlabDataArray
+ PATHS ${_matlab_lib_dir_for_search}
+ DOC "MatlabDataArray Library"
+ NO_DEFAULT_PATH
+ )
+ list(APPEND _matlab_required_variables Matlab_DATAARRAY_LIBRARY)
+ if(Matlab_DATAARRAY_LIBRARY)
+ set(Matlab_DATAARRAY_LIBRARY_FOUND TRUE)
+ endif()
+
+endif()
+
unset(_matlab_lib_dir_for_search)
-set(Matlab_LIBRARIES ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY} ${Matlab_ENG_LIBRARY} ${Matlab_MAT_LIBRARY})
+set(Matlab_LIBRARIES
+ ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY}
+ ${Matlab_ENG_LIBRARY} ${Matlab_MAT_LIBRARY}
+ ${Matlab_DATAARRAY_LIBRARY} ${Matlab_ENGINE_LIBRARY})
find_package_handle_standard_args(
Matlab
@@ -1522,6 +1782,8 @@ if(Matlab_INCLUDE_DIRS AND Matlab_LIBRARIES)
Matlab_MEX_LIBRARY
Matlab_MX_LIBRARY
Matlab_ENG_LIBRARY
+ Matlab_ENGINE_LIBRARY
+ Matlab_DATAARRAY_LIBRARY
Matlab_MAT_LIBRARY
Matlab_INCLUDE_DIRS
Matlab_FOUND
diff --git a/Modules/FindMotif.cmake b/Modules/FindMotif.cmake
index 7304d957c..4f7080a44 100644
--- a/Modules/FindMotif.cmake
+++ b/Modules/FindMotif.cmake
@@ -1,19 +1,20 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
set(MOTIF_FOUND 0)
diff --git a/Modules/FindOpenAL.cmake b/Modules/FindOpenAL.cmake
index c3d202ee8..27dcaf5e9 100644
--- a/Modules/FindOpenAL.cmake
+++ b/Modules/FindOpenAL.cmake
@@ -1,21 +1,22 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindOpenAL
+----------
+
+
+Finds Open Audio Library (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.
+#]=======================================================================]
# This makes the presumption that you are include al.h like
# #include "al.h"
@@ -58,13 +59,10 @@
find_path(OPENAL_INCLUDE_DIR al.h
HINTS
ENV OPENALDIR
- PATH_SUFFIXES include/AL include/OpenAL include
+ PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL
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]
)
@@ -83,9 +81,6 @@ find_library(OPENAL_LIBRARY
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]
)
diff --git a/Modules/FindOpenCL.cmake b/Modules/FindOpenCL.cmake
index b8a7d822f..9891724e4 100644
--- a/Modules/FindOpenCL.cmake
+++ b/Modules/FindOpenCL.cmake
@@ -1,35 +1,36 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindOpenCL
-# ----------
-#
-# Try to find OpenCL
-#
-# IMPORTED Targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines :prop_tgt:`IMPORTED` target ``OpenCL::OpenCL``, if
-# OpenCL has been found.
-#
-# Result Variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following variables::
-#
-# 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
-#
+#[=======================================================================[.rst:
+FindOpenCL
+----------
+
+Finds Open Computing Language (OpenCL)
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``OpenCL::OpenCL``, if
+OpenCL has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables::
+
+ 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
+
+#]=======================================================================]
function(_FIND_OPENCL_VERSION)
include(CheckSymbolExists)
@@ -37,7 +38,7 @@ function(_FIND_OPENCL_VERSION)
set(CMAKE_REQUIRED_QUIET ${OpenCL_FIND_QUIETLY})
CMAKE_PUSH_CHECK_STATE()
- foreach(VERSION "2_0" "1_2" "1_1" "1_0")
+ foreach(VERSION "2_2" "2_1" "2_0" "1_2" "1_1" "1_0")
set(CMAKE_REQUIRED_INCLUDES "${OpenCL_INCLUDE_DIR}")
if(APPLE)
@@ -76,6 +77,7 @@ find_path(OpenCL_INCLUDE_DIR
ENV NVSDKCOMPUTE_ROOT
ENV CUDA_PATH
ENV ATISTREAMSDKROOT
+ ENV OCL_ROOT
PATH_SUFFIXES
include
OpenCL/common/inc
@@ -94,6 +96,7 @@ if(WIN32)
ENV CUDA_PATH
ENV NVSDKCOMPUTE_ROOT
ENV ATISTREAMSDKROOT
+ ENV OCL_ROOT
PATH_SUFFIXES
"AMD APP/lib/x86"
lib/x86
@@ -109,6 +112,7 @@ if(WIN32)
ENV CUDA_PATH
ENV NVSDKCOMPUTE_ROOT
ENV ATISTREAMSDKROOT
+ ENV OCL_ROOT
PATH_SUFFIXES
"AMD APP/lib/x86_64"
lib/x86_64
@@ -116,13 +120,27 @@ if(WIN32)
OpenCL/common/lib/x64)
endif()
else()
- find_library(OpenCL_LIBRARY
- NAMES OpenCL
- PATHS
- ENV AMDAPPSDKROOT
- PATH_SUFFIXES
- lib/x86_64
- lib/x64)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
+ find_library(OpenCL_LIBRARY
+ NAMES OpenCL
+ PATHS
+ ENV AMDAPPSDKROOT
+ ENV CUDA_PATH
+ PATH_SUFFIXES
+ lib/x86
+ lib)
+ elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ find_library(OpenCL_LIBRARY
+ NAMES OpenCL
+ PATHS
+ ENV AMDAPPSDKROOT
+ ENV CUDA_PATH
+ PATH_SUFFIXES
+ lib/x86_64
+ lib/x64
+ lib
+ lib64)
+ endif()
endif()
set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})
diff --git a/Modules/FindOpenGL.cmake b/Modules/FindOpenGL.cmake
index af83fb735..23bb001de 100644
--- a/Modules/FindOpenGL.cmake
+++ b/Modules/FindOpenGL.cmake
@@ -1,62 +1,140 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+FindOpenGL
+----------
+FindModule for OpenGL and OpenGL Utility Library (GLU).
+
+Optional COMPONENTS
+^^^^^^^^^^^^^^^^^^^
+
+This module respects several optional COMPONENTS: ``EGL``, ``GLX``, and
+``OpenGL``. There are corresponding import targets for each of these flags.
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines the :prop_tgt:`IMPORTED` targets:
+
+``OpenGL::GL``
+ Defined to the platform-specific OpenGL libraries if the system has OpenGL.
+``OpenGL::OpenGL``
+ Defined to libOpenGL if the system is GLVND-based.
+``OpenGL::GLU``
+ Defined if the system has OpenGL Utility Library (GLU).
+``OpenGL::GLX``
+ Defined if the system has OpenGL Extension to the X Window System (GLX).
+``OpenGL::EGL``
+ Defined if the system has EGL.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module sets the following variables:
+
+``OPENGL_FOUND``
+ True, if the system has OpenGL and all components are found.
+``OPENGL_XMESA_FOUND``
+ True, if the system has XMESA.
+``OPENGL_GLU_FOUND``
+ True, if the system has GLU.
+``OpenGL_OpenGL_FOUND``
+ True, if the system has an OpenGL library.
+``OpenGL_GLX_FOUND``
+ True, if the system has GLX.
+``OpenGL_EGL_FOUND``
+ True, if the system has EGL.
+``OPENGL_INCLUDE_DIR``
+ Path to the OpenGL include directory.
+``OPENGL_EGL_INCLUDE_DIRS``
+ Path to the EGL include directory.
+``OPENGL_LIBRARIES``
+ Paths to the OpenGL library, windowing system libraries, and GLU libraries.
+ On Linux, this assumes GLX and is never correct for EGL-based targets.
+ Clients are encouraged to use the ``OpenGL::*`` import targets instead.
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``OPENGL_egl_LIBRARY``
+ Path to the EGL library.
+``OPENGL_glu_LIBRARY``
+ Path to the GLU library.
+``OPENGL_glx_LIBRARY``
+ Path to the GLVND 'GLX' library.
+``OPENGL_opengl_LIBRARY``
+ Path to the GLVND 'OpenGL' library
+``OPENGL_gl_LIBRARY``
+ Path to the OpenGL library. New code should prefer the ``OpenGL::*`` import
+ targets.
+
+Linux-specific
+^^^^^^^^^^^^^^
+
+Some Linux systems utilize GLVND as a new ABI for OpenGL. GLVND separates
+context libraries from OpenGL itself; OpenGL lives in "libOpenGL", and
+contexts are defined in "libGLX" or "libEGL". GLVND is currently the only way
+to get OpenGL 3+ functionality via EGL in a manner portable across vendors.
+Projects may use GLVND explicitly with target ``OpenGL::OpenGL`` and either
+``OpenGL::GLX`` or ``OpenGL::EGL``.
+
+Projects may use the ``OpenGL::GL`` target (or ``OPENGL_LIBRARIES`` variable)
+to use legacy GL interfaces. These will use the legacy GL library located
+by ``OPENGL_gl_LIBRARY``, if available. If ``OPENGL_gl_LIBRARY`` is empty or
+not found and GLVND is available, the ``OpenGL::GL`` target will use GLVND
+``OpenGL::OpenGL`` and ``OpenGL::GLX`` (and the ``OPENGL_LIBRARIES``
+variable will use the corresponding libraries). Thus, for non-EGL-based
+Linux targets, the ``OpenGL::GL`` target is most portable.
+
+A ``OpenGL_GL_PREFERENCE`` variable may be set to specify the preferred way
+to provide legacy GL interfaces in case multiple choices are available.
+The value may be one of:
+
+``GLVND``
+ If the GLVND OpenGL and GLX libraries are available, prefer them.
+ This forces ``OPENGL_gl_LIBRARY`` to be empty.
+ This is the default if components were requested (since components
+ correspond to GLVND libraries) or if policy :policy:`CMP0072` is
+ set to ``NEW``.
+
+``LEGACY``
+ Prefer to use the legacy libGL library, if available.
+ This is the default if no components were requested and
+ policy :policy:`CMP0072` is not set to ``NEW``.
+
+For EGL targets the client must rely on GLVND support on the user's system.
+Linking should use the ``OpenGL::OpenGL OpenGL::EGL`` targets. Using GLES*
+libraries is theoretically possible in place of ``OpenGL::OpenGL``, but this
+module does not currently support that; contributions welcome.
+
+``OPENGL_egl_LIBRARY`` and ``OPENGL_EGL_INCLUDE_DIRS`` are defined in the case of
+GLVND. For non-GLVND Linux and other systems these are left undefined.
+
+macOS-Specific
+^^^^^^^^^^^^^^
+
+On OSX FindOpenGL defaults 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.
+#]=======================================================================]
set(_OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
-if (CYGWIN)
+# Provide OPENGL_USE_<C> variables for each component.
+foreach(component ${OpenGL_FIND_COMPONENTS})
+ string(TOUPPER ${component} _COMPONENT)
+ set(OPENGL_USE_${_COMPONENT} 1)
+endforeach()
+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)
@@ -70,7 +148,6 @@ elseif (WIN32)
endif()
elseif (APPLE)
-
# The OpenGL.framework provides both gl and glu
find_library(OPENGL_gl_LIBRARY OpenGL DOC "OpenGL library for OS X")
find_library(OPENGL_glu_LIBRARY OpenGL DOC
@@ -104,29 +181,168 @@ else()
# 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
+ /opt/graphics/OpenGL/include
${_OPENGL_INCLUDE_PATH}
)
- list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
-
+ find_path(OPENGL_GLX_INCLUDE_DIR GL/glx.h ${_OPENGL_INCLUDE_PATH})
+ find_path(OPENGL_EGL_INCLUDE_DIR EGL/egl.h ${_OPENGL_INCLUDE_PATH})
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
+ /opt/graphics/OpenGL/include
+ )
+
+ # Search for the GLVND libraries. We do this regardless of COMPONENTS; we'll
+ # take into account the COMPONENTS logic later.
+ find_library(OPENGL_opengl_LIBRARY
+ NAMES OpenGL
+ PATHS ${_OPENGL_LIB_PATH}
+ )
+
+ find_library(OPENGL_glx_LIBRARY
+ NAMES GLX
+ PATHS ${_OPENGL_LIB_PATH}
+ PATH_SUFFIXES libglvnd
)
- find_library(OPENGL_gl_LIBRARY
- NAMES GL MesaGL
- PATHS /opt/graphics/OpenGL/lib
+ find_library(OPENGL_egl_LIBRARY
+ NAMES EGL
+ PATHS ${_OPENGL_LIB_PATH}
+ PATH_SUFFIXES libglvnd
+ )
+
+ find_library(OPENGL_glu_LIBRARY
+ NAMES GLU MesaGLU
+ PATHS ${OPENGL_gl_LIBRARY}
+ /opt/graphics/OpenGL/lib
/usr/openwin/lib
- /usr/shlib /usr/X11R6/lib
- ${_OPENGL_LIB_PATH}
+ /usr/shlib
)
+ set(_OpenGL_GL_POLICY_WARN 0)
+ if(NOT DEFINED OpenGL_GL_PREFERENCE)
+ set(OpenGL_GL_PREFERENCE "")
+ endif()
+ if(NOT OpenGL_GL_PREFERENCE STREQUAL "")
+ # A preference has been explicitly specified.
+ if(NOT OpenGL_GL_PREFERENCE MATCHES "^(GLVND|LEGACY)$")
+ message(FATAL_ERROR
+ "OpenGL_GL_PREFERENCE value '${OpenGL_GL_PREFERENCE}' not recognized. "
+ "Allowed values are 'GLVND' and 'LEGACY'."
+ )
+ endif()
+ elseif(OpenGL_FIND_COMPONENTS)
+ # No preference was explicitly specified, but the caller did request
+ # at least one GLVND component. Prefer GLVND for legacy GL.
+ set(OpenGL_GL_PREFERENCE "GLVND")
+ else()
+ # No preference was explicitly specified and no GLVND components were
+ # requested. Use a policy to choose the default.
+ cmake_policy(GET CMP0072 _OpenGL_GL_POLICY)
+ if("x${_OpenGL_GL_POLICY}x" STREQUAL "xNEWx")
+ set(OpenGL_GL_PREFERENCE "GLVND")
+ else()
+ set(OpenGL_GL_PREFERENCE "LEGACY")
+ if("x${_OpenGL_GL_POLICY}x" STREQUAL "xx")
+ set(_OpenGL_GL_POLICY_WARN 1)
+ endif()
+ endif()
+ unset(_OpenGL_GL_POLICY)
+ endif()
+
+ if("x${OpenGL_GL_PREFERENCE}x" STREQUAL "xGLVNDx" AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY)
+ # We can provide legacy GL using GLVND libraries.
+ # Do not use any legacy GL library.
+ set(OPENGL_gl_LIBRARY "")
+ else()
+ # We cannot provide legacy GL using GLVND libraries.
+ # Search for the legacy GL library.
+ find_library(OPENGL_gl_LIBRARY
+ NAMES GL MesaGL
+ PATHS /opt/graphics/OpenGL/lib
+ /usr/openwin/lib
+ /usr/shlib
+ ${_OPENGL_LIB_PATH}
+ PATH_SUFFIXES libglvnd
+ )
+ endif()
+
+ if(_OpenGL_GL_POLICY_WARN AND OPENGL_gl_LIBRARY AND OPENGL_opengl_LIBRARY AND OPENGL_glx_LIBRARY)
+ cmake_policy(GET_WARNING CMP0072 _cmp0072_warning)
+ message(AUTHOR_WARNING
+ "${_cmp0072_warning}\n"
+ "FindOpenGL found both a legacy GL library:\n"
+ " OPENGL_gl_LIBRARY: ${OPENGL_gl_LIBRARY}\n"
+ "and GLVND libraries for OpenGL and GLX:\n"
+ " OPENGL_opengl_LIBRARY: ${OPENGL_opengl_LIBRARY}\n"
+ " OPENGL_glx_LIBRARY: ${OPENGL_glx_LIBRARY}\n"
+ "OpenGL_GL_PREFERENCE has not been set to \"GLVND\" or \"LEGACY\", so for "
+ "compatibility with CMake 3.10 and below the legacy GL library will be used."
+ )
+ endif()
+ unset(_OpenGL_GL_POLICY_WARN)
+
+ # FPHSA cannot handle "this OR that is required", so we conditionally set what
+ # it must look for. First clear any previous config we might have done:
+ set(_OpenGL_REQUIRED_VARS)
+
+ # now we append the libraries as appropriate. The complicated logic
+ # basically comes down to "use libOpenGL when we can, and add in specific
+ # context mechanisms when requested, or we need them to preserve the previous
+ # default where glx is always available."
+ if((NOT OPENGL_USE_EGL AND
+ NOT OPENGL_opengl_LIBRARY AND
+ OPENGL_glx_LIBRARY AND
+ NOT OPENGL_gl_LIBRARY) OR
+ (NOT OPENGL_USE_EGL AND
+ NOT OPENGL_glx_LIBRARY AND
+ NOT OPENGL_gl_LIBRARY) OR
+ (NOT OPENGL_USE_EGL AND
+ OPENGL_opengl_LIBRARY AND
+ OPENGL_glx_LIBRARY) OR
+ ( OPENGL_USE_EGL))
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_opengl_LIBRARY)
+ endif()
+
+ # GLVND GLX library. Preferred when available.
+ if((NOT OPENGL_USE_OPENGL AND
+ NOT OPENGL_USE_GLX AND
+ NOT OPENGL_USE_EGL AND
+ NOT OPENGL_glx_LIBRARY AND
+ NOT OPENGL_gl_LIBRARY) OR
+ ( OPENGL_USE_GLX AND
+ NOT OPENGL_USE_EGL AND
+ NOT OPENGL_glx_LIBRARY AND
+ NOT OPENGL_gl_LIBRARY) OR
+ (NOT OPENGL_USE_EGL AND
+ OPENGL_opengl_LIBRARY AND
+ OPENGL_glx_LIBRARY) OR
+ (OPENGL_USE_GLX AND OPENGL_USE_EGL))
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_glx_LIBRARY)
+ endif()
+
+ # GLVND EGL library.
+ if(OPENGL_USE_EGL)
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_egl_LIBRARY)
+ endif()
+
+ # Old-style "libGL" library: used as a fallback when GLVND isn't available.
+ if((NOT OPENGL_USE_EGL AND
+ NOT OPENGL_opengl_LIBRARY AND
+ OPENGL_glx_LIBRARY AND
+ OPENGL_gl_LIBRARY) OR
+ (NOT OPENGL_USE_EGL AND
+ NOT OPENGL_glx_LIBRARY AND
+ OPENGL_gl_LIBRARY))
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_gl_LIBRARY)
+ endif()
+
+ # We always need the 'gl.h' include dir.
+ list(APPEND _OpenGL_REQUIRED_VARS OPENGL_INCLUDE_DIR)
+
unset(_OPENGL_INCLUDE_PATH)
unset(_OPENGL_LIB_PATH)
@@ -135,44 +351,91 @@ else()
PATHS ${OPENGL_gl_LIBRARY}
/opt/graphics/OpenGL/lib
/usr/openwin/lib
- /usr/shlib /usr/X11R6/lib
+ /usr/shlib
)
-
endif ()
-if(OPENGL_gl_LIBRARY)
+if(OPENGL_xmesa_INCLUDE_DIR)
+ set( OPENGL_XMESA_FOUND "YES" )
+else()
+ set( OPENGL_XMESA_FOUND "NO" )
+endif()
- if(OPENGL_xmesa_INCLUDE_DIR)
- set( OPENGL_XMESA_FOUND "YES" )
- else()
- set( OPENGL_XMESA_FOUND "NO" )
- endif()
+if(OPENGL_glu_LIBRARY)
+ set( OPENGL_GLU_FOUND "YES" )
+else()
+ set( OPENGL_GLU_FOUND "NO" )
+endif()
- set( OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY} ${OPENGL_LIBRARIES})
- if(OPENGL_glu_LIBRARY)
- set( OPENGL_GLU_FOUND "YES" )
- if(NOT "${OPENGL_glu_LIBRARY}" STREQUAL "${OPENGL_gl_LIBRARY}")
- set( OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY} ${OPENGL_LIBRARIES} )
- endif()
- else()
- set( OPENGL_GLU_FOUND "NO" )
- endif()
+# OpenGL_OpenGL_FOUND is a bit unique in that it is okay if /either/ libOpenGL
+# or libGL is found.
+# Using libGL with libEGL is never okay, though; we handle that case later.
+if(NOT OPENGL_opengl_LIBRARY AND NOT OPENGL_gl_LIBRARY)
+ set(OpenGL_OpenGL_FOUND FALSE)
+else()
+ set(OpenGL_OpenGL_FOUND TRUE)
+endif()
- # This deprecated setting is for backward compatibility with CMake1.4
- set (OPENGL_LIBRARY ${OPENGL_LIBRARIES})
+if(OPENGL_glx_LIBRARY AND OPENGL_GLX_INCLUDE_DIR)
+ set(OpenGL_GLX_FOUND TRUE)
+else()
+ set(OpenGL_GLX_FOUND FALSE)
+endif()
+if(OPENGL_egl_LIBRARY AND OPENGL_EGL_INCLUDE_DIR)
+ set(OpenGL_EGL_FOUND TRUE)
+else()
+ set(OpenGL_EGL_FOUND FALSE)
endif()
-# This deprecated setting is for backward compatibility with CMake1.4
-set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
+# User-visible names should be plural.
+if(OPENGL_EGL_INCLUDE_DIR)
+ set(OPENGL_EGL_INCLUDE_DIRS ${OPENGL_EGL_INCLUDE_DIR})
+endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS})
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenGL REQUIRED_VARS ${_OpenGL_REQUIRED_VARS}
+ HANDLE_COMPONENTS)
unset(_OpenGL_REQUIRED_VARS)
# OpenGL:: targets
if(OPENGL_FOUND)
- if(NOT TARGET OpenGL::GL)
+ # ::OpenGL is a GLVND library, and thus Linux-only: we don't bother checking
+ # for a framework version of this library.
+ if(OPENGL_opengl_LIBRARY AND NOT TARGET OpenGL::OpenGL)
+ if(IS_ABSOLUTE "${OPENGL_opengl_LIBRARY}")
+ add_library(OpenGL::OpenGL UNKNOWN IMPORTED)
+ set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LOCATION
+ "${OPENGL_opengl_LIBRARY}")
+ else()
+ add_library(OpenGL::OpenGL INTERFACE IMPORTED)
+ set_target_properties(OpenGL::OpenGL PROPERTIES IMPORTED_LIBNAME
+ "${OPENGL_opengl_LIBRARY}")
+ endif()
+ set_target_properties(OpenGL::OpenGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
+ "${OPENGL_INCLUDE_DIR}")
+ endif()
+
+ # ::GLX is a GLVND library, and thus Linux-only: we don't bother checking
+ # for a framework version of this library.
+ if(OpenGL_GLX_FOUND AND NOT TARGET OpenGL::GLX)
+ if(IS_ABSOLUTE "${OPENGL_glx_LIBRARY}")
+ add_library(OpenGL::GLX UNKNOWN IMPORTED)
+ set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LOCATION
+ "${OPENGL_glx_LIBRARY}")
+ else()
+ add_library(OpenGL::GLX INTERFACE IMPORTED)
+ set_target_properties(OpenGL::GLX PROPERTIES IMPORTED_LIBNAME
+ "${OPENGL_glx_LIBRARY}")
+ endif()
+ set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_LINK_LIBRARIES
+ OpenGL::OpenGL)
+ set_target_properties(OpenGL::GLX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
+ "${OPENGL_GLX_INCLUDE_DIR}")
+ endif()
+
+ if(OPENGL_gl_LIBRARY AND NOT TARGET OpenGL::GL)
+ # A legacy GL library is available, so use it for the legacy GL target.
if(IS_ABSOLUTE "${OPENGL_gl_LIBRARY}")
add_library(OpenGL::GL UNKNOWN IMPORTED)
if(OPENGL_gl_LIBRARY MATCHES "/([^/]+)\\.framework$")
@@ -193,6 +456,38 @@ if(OPENGL_FOUND)
endif()
set_target_properties(OpenGL::GL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENGL_INCLUDE_DIR}")
+ elseif(NOT TARGET OpenGL::GL AND TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX)
+ # A legacy GL library is not available, but we can provide the legacy GL
+ # target using GLVND OpenGL+GLX.
+ add_library(OpenGL::GL INTERFACE IMPORTED)
+ set_target_properties(OpenGL::GL PROPERTIES INTERFACE_LINK_LIBRARIES
+ OpenGL::OpenGL)
+ set_property(TARGET OpenGL::GL APPEND PROPERTY INTERFACE_LINK_LIBRARIES
+ OpenGL::GLX)
+ set_target_properties(OpenGL::GL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
+ "${OPENGL_INCLUDE_DIR}")
+ endif()
+
+ # ::EGL is a GLVND library, and thus Linux-only: we don't bother checking
+ # for a framework version of this library.
+ # Note we test for OpenGL::OpenGL as a target. When this module is updated to
+ # support GLES, we would additionally want to check for the hypothetical GLES
+ # target and enable EGL if either ::GLES or ::OpenGL is created.
+ if(TARGET OpenGL::OpenGL AND OpenGL_EGL_FOUND AND NOT TARGET OpenGL::EGL)
+ if(IS_ABSOLUTE "${OPENGL_egl_LIBRARY}")
+ add_library(OpenGL::EGL UNKNOWN IMPORTED)
+ set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LOCATION
+ "${OPENGL_egl_LIBRARY}")
+ else()
+ add_library(OpenGL::EGL INTERFACE IMPORTED)
+ set_target_properties(OpenGL::EGL PROPERTIES IMPORTED_LIBNAME
+ "${OPENGL_egl_LIBRARY}")
+ endif()
+ set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_LINK_LIBRARIES
+ OpenGL::OpenGL)
+ # Note that EGL's include directory is different from OpenGL/GLX's!
+ set_target_properties(OpenGL::EGL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
+ "${OPENGL_EGL_INCLUDE_DIR}")
endif()
if(OPENGL_GLU_FOUND AND NOT TARGET OpenGL::GLU)
@@ -217,11 +512,34 @@ if(OPENGL_FOUND)
set_target_properties(OpenGL::GLU PROPERTIES
INTERFACE_LINK_LIBRARIES OpenGL::GL)
endif()
+
+ # OPENGL_LIBRARIES mirrors OpenGL::GL's logic ...
+ if(OPENGL_gl_LIBRARY)
+ set(OPENGL_LIBRARIES ${OPENGL_gl_LIBRARY})
+ elseif(TARGET OpenGL::OpenGL AND TARGET OpenGL::GLX)
+ set(OPENGL_LIBRARIES ${OPENGL_opengl_LIBRARY} ${OPENGL_glx_LIBRARY})
+ else()
+ set(OPENGL_LIBRARIES "")
+ endif()
+ # ... and also includes GLU, if available.
+ if(TARGET OpenGL::GLU)
+ list(APPEND OPENGL_LIBRARIES ${OPENGL_glu_LIBRARY})
+ endif()
endif()
+# This deprecated setting is for backward compatibility with CMake1.4
+set(OPENGL_LIBRARY ${OPENGL_LIBRARIES})
+# This deprecated setting is for backward compatibility with CMake1.4
+set(OPENGL_INCLUDE_PATH ${OPENGL_INCLUDE_DIR})
+
mark_as_advanced(
OPENGL_INCLUDE_DIR
OPENGL_xmesa_INCLUDE_DIR
+ OPENGL_egl_LIBRARY
OPENGL_glu_LIBRARY
+ OPENGL_glx_LIBRARY
OPENGL_gl_LIBRARY
+ OPENGL_opengl_LIBRARY
+ OPENGL_EGL_INCLUDE_DIR
+ OPENGL_GLX_INCLUDE_DIR
)
diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake
index ee74a1afe..def23bb13 100644
--- a/Modules/FindOpenMP.cmake
+++ b/Modules/FindOpenMP.cmake
@@ -1,77 +1,83 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-#
-# Variables
-# ^^^^^^^^^
-#
-# This module will set the following variables per language in your
-# project, where ``<lang>`` is one of C, CXX, or Fortran:
-#
-# ``OpenMP_<lang>_FOUND``
-# Variable indicating if OpenMP support for ``<lang>`` was detected.
-# ``OpenMP_<lang>_FLAGS``
-# OpenMP compiler flags for ``<lang>``, separated by spaces.
-#
-# For linking with OpenMP code written in ``<lang>``, the following
-# variables are provided:
-#
-# ``OpenMP_<lang>_LIB_NAMES``
-# :ref:`;-list <CMake Language Lists>` of libraries for OpenMP programs for ``<lang>``.
-# ``OpenMP_<libname>_LIBRARY``
-# Location of the individual libraries needed for OpenMP support in ``<lang>``.
-# ``OpenMP_<lang>_LIBRARIES``
-# A list of libraries needed to link with OpenMP code written in ``<lang>``.
-#
-# Additionally, the module provides :prop_tgt:`IMPORTED` targets:
-#
-# ``OpenMP::OpenMP_<lang>``
-# Target for using OpenMP from ``<lang>``.
-#
-# Specifically for Fortran, the module sets the following variables:
-#
-# ``OpenMP_Fortran_HAVE_OMPLIB_HEADER``
-# Boolean indicating if OpenMP is accessible through ``omp_lib.h``.
-# ``OpenMP_Fortran_HAVE_OMPLIB_MODULE``
-# Boolean indicating if OpenMP is accessible through the ``omp_lib`` Fortran module.
-#
-# The module will also try to provide the OpenMP version variables:
-#
-# ``OpenMP_<lang>_SPEC_DATE``
-# Date of the OpenMP specification implemented by the ``<lang>`` compiler.
-# ``OpenMP_<lang>_VERSION_MAJOR``
-# Major version of OpenMP implemented by the ``<lang>`` compiler.
-# ``OpenMP_<lang>_VERSION_MINOR``
-# Minor version of OpenMP implemented by the ``<lang>`` compiler.
-# ``OpenMP_<lang>_VERSION``
-# OpenMP version implemented by the ``<lang>`` compiler.
-#
-# The specification date is formatted as given in the OpenMP standard:
-# ``yyyymm`` where ``yyyy`` and ``mm`` represents the year and month of
-# the OpenMP specification implemented by the ``<lang>`` compiler.
-#
-# Backward Compatibility
-# ^^^^^^^^^^^^^^^^^^^^^^
-#
-# For backward compatibility with older versions of FindOpenMP, these
-# variables are set, but deprecated::
-#
-# OpenMP_FOUND
-#
-# In new projects, please use the ``OpenMP_<lang>_XXX`` equivalents.
+#[=======================================================================[.rst:
+FindOpenMP
+----------
+
+Finds Open Multi-Processing (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.
+
+Variables
+^^^^^^^^^
+
+The module exposes the components ``C``, ``CXX``, and ``Fortran``.
+Each of these controls the various languages to search OpenMP support for.
+
+Depending on the enabled components the following variables will be set:
+
+``OpenMP_FOUND``
+ Variable indicating that OpenMP flags for all requested languages have been found.
+ If no components are specified, this is true if OpenMP settings for all enabled languages
+ were detected.
+``OpenMP_VERSION``
+ Minimal version of the OpenMP standard detected among the requested languages,
+ or all enabled languages if no components were specified.
+
+This module will set the following variables per language in your
+project, where ``<lang>`` is one of C, CXX, or Fortran:
+
+``OpenMP_<lang>_FOUND``
+ Variable indicating if OpenMP support for ``<lang>`` was detected.
+``OpenMP_<lang>_FLAGS``
+ OpenMP compiler flags for ``<lang>``, separated by spaces.
+
+For linking with OpenMP code written in ``<lang>``, the following
+variables are provided:
+
+``OpenMP_<lang>_LIB_NAMES``
+ :ref:`;-list <CMake Language Lists>` of libraries for OpenMP programs for ``<lang>``.
+``OpenMP_<libname>_LIBRARY``
+ Location of the individual libraries needed for OpenMP support in ``<lang>``.
+``OpenMP_<lang>_LIBRARIES``
+ A list of libraries needed to link with OpenMP code written in ``<lang>``.
+
+Additionally, the module provides :prop_tgt:`IMPORTED` targets:
+
+``OpenMP::OpenMP_<lang>``
+ Target for using OpenMP from ``<lang>``.
+
+Specifically for Fortran, the module sets the following variables:
+
+``OpenMP_Fortran_HAVE_OMPLIB_HEADER``
+ Boolean indicating if OpenMP is accessible through ``omp_lib.h``.
+``OpenMP_Fortran_HAVE_OMPLIB_MODULE``
+ Boolean indicating if OpenMP is accessible through the ``omp_lib`` Fortran module.
+
+The module will also try to provide the OpenMP version variables:
+
+``OpenMP_<lang>_SPEC_DATE``
+ Date of the OpenMP specification implemented by the ``<lang>`` compiler.
+``OpenMP_<lang>_VERSION_MAJOR``
+ Major version of OpenMP implemented by the ``<lang>`` compiler.
+``OpenMP_<lang>_VERSION_MINOR``
+ Minor version of OpenMP implemented by the ``<lang>`` compiler.
+``OpenMP_<lang>_VERSION``
+ OpenMP version implemented by the ``<lang>`` compiler.
+
+The specification date is formatted as given in the OpenMP standard:
+``yyyymm`` where ``yyyy`` and ``mm`` represents the year and month of
+the OpenMP specification implemented by the ``<lang>`` compiler.
+#]=======================================================================]
cmake_policy(PUSH)
+cmake_policy(SET CMP0012 NEW) # if() recognizes numbers and booleans
+cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
cmake_policy(SET CMP0057 NEW) # if IN_LIST
function(_OPENMP_FLAG_CANDIDATES LANG)
@@ -80,6 +86,7 @@ function(_OPENMP_FLAG_CANDIDATES LANG)
set(OMP_FLAG_GNU "-fopenmp")
set(OMP_FLAG_Clang "-fopenmp=libomp" "-fopenmp=libiomp5" "-fopenmp")
+ set(OMP_FLAG_AppleClang "-Xclang -fopenmp")
set(OMP_FLAG_HP "+Oopenmp")
if(WIN32)
set(OMP_FLAG_Intel "-Qopenmp")
@@ -89,16 +96,16 @@ function(_OPENMP_FLAG_CANDIDATES LANG)
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_NAG "-openmp")
set(OMP_FLAG_Absoft "-openmp")
set(OMP_FLAG_PGI "-mp")
+ set(OMP_FLAG_Flang "-fopenmp")
set(OMP_FLAG_SunPro "-xopenmp")
set(OMP_FLAG_XL "-qsmp=omp")
- # Cray compiles with OpenMP automatically
- set(OMP_FLAG_Cray " ")
+ # Cray compiler activate OpenMP with -h omp, which is enabled by default.
+ set(OMP_FLAG_Cray " " "-h omp")
# If we know the correct flags, use those
if(DEFINED OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID})
@@ -117,8 +124,11 @@ endfunction()
set(OpenMP_C_CXX_TEST_SOURCE
"
#include <omp.h>
-int main() {
-#ifndef _OPENMP
+int main(void) {
+#ifdef _OPENMP
+ omp_get_max_threads();
+ return 0;
+#else
breaks_on_purpose
#endif
}
@@ -155,20 +165,29 @@ function(_OPENMP_WRITE_SOURCE_FILE LANG SRC_FILE_CONTENT_VAR SRC_FILE_NAME SRC_F
set(${SRC_FILE_FULLPATH} "${SRC_FILE}" PARENT_SCOPE)
endfunction()
-include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseImplicitLinkInfo.cmake)
function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR)
_OPENMP_FLAG_CANDIDATES("${LANG}")
_OPENMP_WRITE_SOURCE_FILE("${LANG}" "TEST_SOURCE" OpenMPTryFlag _OPENMP_TEST_SRC)
+ unset(OpenMP_VERBOSE_COMPILE_OPTIONS)
+ separate_arguments(OpenMP_VERBOSE_OPTIONS NATIVE_COMMAND "${CMAKE_${LANG}_VERBOSE_FLAG}")
+ foreach(_VERBOSE_OPTION IN LISTS OpenMP_VERBOSE_OPTIONS)
+ if(NOT _VERBOSE_OPTION MATCHES "^-Wl,")
+ list(APPEND OpenMP_VERBOSE_COMPILE_OPTIONS ${_VERBOSE_OPTION})
+ endif()
+ endforeach()
+
foreach(OPENMP_FLAG IN LISTS OpenMP_${LANG}_FLAG_CANDIDATES)
set(OPENMP_FLAGS_TEST "${OPENMP_FLAG}")
- if(CMAKE_${LANG}_VERBOSE_FLAG)
- string(APPEND OPENMP_FLAGS_TEST " ${CMAKE_${LANG}_VERBOSE_FLAG}")
+ if(OpenMP_VERBOSE_COMPILE_OPTIONS)
+ string(APPEND OPENMP_FLAGS_TEST " ${OpenMP_VERBOSE_COMPILE_OPTIONS}")
endif()
string(REGEX REPLACE "[-/=+]" "" OPENMP_PLAIN_FLAG "${OPENMP_FLAG}")
try_compile( OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG} ${CMAKE_BINARY_DIR} ${_OPENMP_TEST_SRC}
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${OPENMP_FLAGS_TEST}"
+ LINK_LIBRARIES ${CMAKE_${LANG}_VERBOSE_FLAG}
OUTPUT_VARIABLE OpenMP_TRY_COMPILE_OUTPUT
)
@@ -197,34 +216,69 @@ function(_OPENMP_GET_FLAGS LANG FLAG_MODE OPENMP_FLAG_VAR OPENMP_LIB_NAMES_VAR)
unset(_OPENMP_LIB_NAMES)
foreach(_OPENMP_IMPLICIT_LIB IN LISTS OpenMP_${LANG}_IMPLICIT_LIBRARIES)
- if(NOT "${_OPENMP_IMPLICIT_LIB}" IN_LIST CMAKE_${LANG}_IMPLICIT_LINK_LIBRARIES)
- find_library(OpenMP_${_OPENMP_IMPLICIT_LIB}_LIBRARY
- NAMES "${_OPENMP_IMPLICIT_LIB}"
- HINTS ${OpenMP_${LANG}_IMPLICIT_LINK_DIRS}
- )
- mark_as_advanced(OpenMP_${_OPENMP_IMPLICIT_LIB}_LIBRARY)
- list(APPEND _OPENMP_LIB_NAMES ${_OPENMP_IMPLICIT_LIB})
+ get_filename_component(_OPENMP_IMPLICIT_LIB_DIR "${_OPENMP_IMPLICIT_LIB}" DIRECTORY)
+ get_filename_component(_OPENMP_IMPLICIT_LIB_NAME "${_OPENMP_IMPLICIT_LIB}" NAME)
+ get_filename_component(_OPENMP_IMPLICIT_LIB_PLAIN "${_OPENMP_IMPLICIT_LIB}" NAME_WE)
+ string(REGEX REPLACE "([][+.*?()^$])" "\\\\\\1" _OPENMP_IMPLICIT_LIB_PLAIN_ESC "${_OPENMP_IMPLICIT_LIB_PLAIN}")
+ string(REGEX REPLACE "([][+.*?()^$])" "\\\\\\1" _OPENMP_IMPLICIT_LIB_PATH_ESC "${_OPENMP_IMPLICIT_LIB}")
+ if(NOT ( "${_OPENMP_IMPLICIT_LIB}" IN_LIST CMAKE_${LANG}_IMPLICIT_LINK_LIBRARIES
+ OR "${CMAKE_${LANG}_STANDARD_LIBRARIES}" MATCHES "(^| )(-Wl,)?(-l)?(${_OPENMP_IMPLICIT_LIB_PLAIN_ESC}|${_OPENMP_IMPLICIT_LIB_PATH_ESC})( |$)"
+ OR "${CMAKE_${LANG}_LINK_EXECUTABLE}" MATCHES "(^| )(-Wl,)?(-l)?(${_OPENMP_IMPLICIT_LIB_PLAIN_ESC}|${_OPENMP_IMPLICIT_LIB_PATH_ESC})( |$)" ) )
+ if(_OPENMP_IMPLICIT_LIB_DIR)
+ set(OpenMP_${_OPENMP_IMPLICIT_LIB_PLAIN}_LIBRARY "${_OPENMP_IMPLICIT_LIB}" CACHE FILEPATH
+ "Path to the ${_OPENMP_IMPLICIT_LIB_PLAIN} library for OpenMP")
+ else()
+ find_library(OpenMP_${_OPENMP_IMPLICIT_LIB_PLAIN}_LIBRARY
+ NAMES "${_OPENMP_IMPLICIT_LIB_NAME}"
+ DOC "Path to the ${_OPENMP_IMPLICIT_LIB_PLAIN} library for OpenMP"
+ HINTS ${OpenMP_${LANG}_IMPLICIT_LINK_DIRS}
+ CMAKE_FIND_ROOT_PATH_BOTH
+ NO_DEFAULT_PATH
+ )
+ endif()
+ mark_as_advanced(OpenMP_${_OPENMP_IMPLICIT_LIB_PLAIN}_LIBRARY)
+ list(APPEND _OPENMP_LIB_NAMES ${_OPENMP_IMPLICIT_LIB_PLAIN})
endif()
endforeach()
set("${OPENMP_LIB_NAMES_VAR}" "${_OPENMP_LIB_NAMES}" PARENT_SCOPE)
else()
- # The Intel compiler on windows has no verbose mode, so we need to treat it explicitly
- if("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "Intel" AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
- set("${OPENMP_LIB_NAMES_VAR}" "libiomp5md" PARENT_SCOPE)
- find_library(OpenMP_libiomp5md_LIBRARY
- NAMES "libiomp5md"
- HINTS ${CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES}
- )
- mark_as_advanced(OpenMP_libiomp5md_LIBRARY)
- else()
- set("${OPENMP_LIB_NAMES_VAR}" "" PARENT_SCOPE)
- endif()
+ # We do not know how to extract implicit OpenMP libraries for this compiler.
+ # Assume that it handles them automatically, e.g. the Intel Compiler on
+ # Windows should put the dependency in its object files.
+ set("${OPENMP_LIB_NAMES_VAR}" "" PARENT_SCOPE)
endif()
break()
+ elseif(CMAKE_${LANG}_COMPILER_ID STREQUAL "AppleClang"
+ AND CMAKE_${LANG}_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0")
+
+ # Check for separate OpenMP library on AppleClang 7+
+ find_library(OpenMP_libomp_LIBRARY
+ NAMES omp gomp iomp5
+ HINTS ${CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES}
+ )
+ mark_as_advanced(OpenMP_libomp_LIBRARY)
+
+ if(OpenMP_libomp_LIBRARY)
+ try_compile( OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG} ${CMAKE_BINARY_DIR} ${_OPENMP_TEST_SRC}
+ CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${OPENMP_FLAGS_TEST}"
+ LINK_LIBRARIES ${CMAKE_${LANG}_VERBOSE_FLAG} ${OpenMP_libomp_LIBRARY}
+ OUTPUT_VARIABLE OpenMP_TRY_COMPILE_OUTPUT
+ )
+ if(OpenMP_COMPILE_RESULT_${FLAG_MODE}_${OPENMP_PLAIN_FLAG})
+ set("${OPENMP_FLAG_VAR}" "${OPENMP_FLAG}" PARENT_SCOPE)
+ set("${OPENMP_LIB_NAMES_VAR}" "libomp" PARENT_SCOPE)
+ break()
+ endif()
+ endif()
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Detecting ${LANG} OpenMP failed with the following output:\n${OpenMP_TRY_COMPILE_OUTPUT}\n\n")
endif()
set("${OPENMP_LIB_NAMES_VAR}" "NOTFOUND" PARENT_SCOPE)
set("${OPENMP_FLAG_VAR}" "NOTFOUND" PARENT_SCOPE)
endforeach()
+
+ unset(OpenMP_VERBOSE_COMPILE_OPTIONS)
endfunction()
set(OpenMP_C_CXX_CHECK_VERSION_SOURCE
@@ -240,9 +294,10 @@ const char ompver_str[] = { 'I', 'N', 'F', 'O', ':', 'O', 'p', 'e', 'n', 'M',
('0' + ((_OPENMP/10)%10)),
('0' + ((_OPENMP/1)%10)),
']', '\\0' };
-int main()
+int main(void)
{
puts(ompver_str);
+ return 0;
}
")
@@ -272,7 +327,8 @@ function(_OPENMP_GET_SPEC_DATE LANG SPEC_DATE)
string(REGEX REPLACE "[-/=+]" "" OPENMP_PLAIN_FLAG "${OPENMP_FLAG}")
try_compile(OpenMP_SPECTEST_${LANG}_${OPENMP_PLAIN_FLAG} "${CMAKE_BINARY_DIR}" "${_OPENMP_TEST_SRC}"
CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${OpenMP_${LANG}_FLAGS}"
- COPY_FILE ${BIN_FILE})
+ COPY_FILE ${BIN_FILE}
+ OUTPUT_VARIABLE OpenMP_TRY_COMPILE_OUTPUT)
if(${OpenMP_SPECTEST_${LANG}_${OPENMP_PLAIN_FLAG}})
file(STRINGS ${BIN_FILE} specstr LIMIT_COUNT 1 REGEX "INFO:OpenMP-date")
@@ -280,12 +336,18 @@ function(_OPENMP_GET_SPEC_DATE LANG SPEC_DATE)
if("${specstr}" MATCHES "${regex_spec_date}")
set(${SPEC_DATE} "${CMAKE_MATCH_1}" PARENT_SCOPE)
endif()
+ else()
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Detecting ${LANG} OpenMP version failed with the following output:\n${OpenMP_TRY_COMPILE_OUTPUT}\n\n")
endif()
endfunction()
macro(_OPENMP_SET_VERSION_BY_SPEC_DATE LANG)
set(OpenMP_SPEC_DATE_MAP
+ # Preview versions
+ "201611=5.0" # OpenMP 5.0 preview 1
# Combined versions, 2.5 onwards
+ "201811=5.0"
"201511=4.5"
"201307=4.0"
"201107=3.1"
@@ -302,8 +364,15 @@ macro(_OPENMP_SET_VERSION_BY_SPEC_DATE LANG)
# Fortran version 1.0
"199710=1.0"
)
+ if(MSVC)
+ list(APPEND OpenMP_SPEC_DATE_MAP "2019=2.0")
+ endif()
- string(REGEX MATCHALL "${OpenMP_${LANG}_SPEC_DATE}=([0-9]+)\\.([0-9]+)" _version_match "${OpenMP_SPEC_DATE_MAP}")
+ if(OpenMP_${LANG}_SPEC_DATE)
+ string(REGEX MATCHALL "${OpenMP_${LANG}_SPEC_DATE}=([0-9]+)\\.([0-9]+)" _version_match "${OpenMP_SPEC_DATE_MAP}")
+ else()
+ set(_version_match "")
+ endif()
if(NOT _version_match STREQUAL "")
set(OpenMP_${LANG}_VERSION_MAJOR ${CMAKE_MATCH_1})
set(OpenMP_${LANG}_VERSION_MINOR ${CMAKE_MATCH_2})
@@ -372,19 +441,25 @@ if(CMAKE_Fortran_COMPILER_LOADED)
endif()
endif()
-set(OPENMP_FOUND TRUE)
+if(NOT OpenMP_FIND_COMPONENTS)
+ set(OpenMP_FINDLIST C CXX Fortran)
+else()
+ set(OpenMP_FINDLIST ${OpenMP_FIND_COMPONENTS})
+endif()
-foreach(LANG IN ITEMS C CXX Fortran)
+unset(_OpenMP_MIN_VERSION)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+
+foreach(LANG IN LISTS OpenMP_FINDLIST)
if(CMAKE_${LANG}_COMPILER_LOADED)
- if (NOT OpenMP_${LANG}_SPEC_DATE)
+ if (NOT OpenMP_${LANG}_SPEC_DATE AND OpenMP_${LANG}_FLAGS)
_OPENMP_GET_SPEC_DATE("${LANG}" OpenMP_${LANG}_SPEC_DATE_INTERNAL)
set(OpenMP_${LANG}_SPEC_DATE "${OpenMP_${LANG}_SPEC_DATE_INTERNAL}" CACHE
INTERNAL "${LANG} compiler's OpenMP specification date")
_OPENMP_SET_VERSION_BY_SPEC_DATE("${LANG}")
endif()
- include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-
set(OpenMP_${LANG}_FIND_QUIETLY ${OpenMP_FIND_QUIETLY})
set(OpenMP_${LANG}_FIND_REQUIRED ${OpenMP_FIND_REQUIRED})
set(OpenMP_${LANG}_FIND_VERSION ${OpenMP_FIND_VERSION})
@@ -405,6 +480,11 @@ foreach(LANG IN ITEMS C CXX Fortran)
)
if(OpenMP_${LANG}_FOUND)
+ if(DEFINED OpenMP_${LANG}_VERSION)
+ if(NOT _OpenMP_MIN_VERSION OR _OpenMP_MIN_VERSION VERSION_GREATER OpenMP_${LANG}_VERSION)
+ set(_OpenMP_MIN_VERSION OpenMP_${LANG}_VERSION)
+ endif()
+ endif()
set(OpenMP_${LANG}_LIBRARIES "")
foreach(_OPENMP_IMPLICIT_LIB IN LISTS OpenMP_${LANG}_LIB_NAMES)
list(APPEND OpenMP_${LANG}_LIBRARIES "${OpenMP_${_OPENMP_IMPLICIT_LIB}_LIBRARY}")
@@ -416,20 +496,30 @@ foreach(LANG IN ITEMS C CXX Fortran)
if(OpenMP_${LANG}_FLAGS)
separate_arguments(_OpenMP_${LANG}_OPTIONS NATIVE_COMMAND "${OpenMP_${LANG}_FLAGS}")
set_property(TARGET OpenMP::OpenMP_${LANG} PROPERTY
- INTERFACE_COMPILE_OPTIONS "${_OpenMP_${LANG}_OPTIONS}")
+ INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:${LANG}>:${_OpenMP_${LANG}_OPTIONS}>")
unset(_OpenMP_${LANG}_OPTIONS)
endif()
if(OpenMP_${LANG}_LIBRARIES)
set_property(TARGET OpenMP::OpenMP_${LANG} PROPERTY
INTERFACE_LINK_LIBRARIES "${OpenMP_${LANG}_LIBRARIES}")
endif()
- else()
- set(OPENMP_FOUND FALSE)
endif()
endif()
endforeach()
-set(OpenMP_FOUND ${OPENMP_FOUND})
+unset(_OpenMP_REQ_VARS)
+foreach(LANG IN ITEMS C CXX Fortran)
+ if((NOT OpenMP_FIND_COMPONENTS AND CMAKE_${LANG}_COMPILER_LOADED) OR LANG IN_LIST OpenMP_FIND_COMPONENTS)
+ list(APPEND _OpenMP_REQ_VARS "OpenMP_${LANG}_FOUND")
+ endif()
+endforeach()
+
+find_package_handle_standard_args(OpenMP
+ REQUIRED_VARS ${_OpenMP_REQ_VARS}
+ VERSION_VAR ${_OpenMP_MIN_VERSION}
+ HANDLE_COMPONENTS)
+
+set(OPENMP_FOUND ${OpenMP_FOUND})
if(CMAKE_Fortran_COMPILER_LOADED AND OpenMP_Fortran_FOUND)
if(NOT DEFINED OpenMP_Fortran_HAVE_OMPLIB_MODULE)
diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake
index f32eb501d..5f947fe54 100644
--- a/Modules/FindOpenSSL.cmake
+++ b/Modules/FindOpenSSL.cmake
@@ -1,46 +1,54 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindOpenSSL
-# -----------
-#
-# Find the OpenSSL encryption library.
-#
-# Imported Targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following :prop_tgt:`IMPORTED` targets:
-#
-# ``OpenSSL::SSL``
-# The OpenSSL ``ssl`` library, if found.
-# ``OpenSSL::Crypto``
-# The OpenSSL ``crypto`` library, if found.
-#
-# Result Variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module will set the following variables in your project:
-#
-# ``OPENSSL_FOUND``
-# System has the OpenSSL library.
-# ``OPENSSL_INCLUDE_DIR``
-# The OpenSSL include directory.
-# ``OPENSSL_CRYPTO_LIBRARY``
-# The OpenSSL crypto library.
-# ``OPENSSL_SSL_LIBRARY``
-# The OpenSSL SSL library.
-# ``OPENSSL_LIBRARIES``
-# All OpenSSL libraries.
-# ``OPENSSL_VERSION``
-# This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``).
-#
-# Hints
-# ^^^^^
-#
-# Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation.
-# Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries.
-# Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib.
+#[=======================================================================[.rst:
+FindOpenSSL
+-----------
+
+Find the OpenSSL encryption library.
+
+Optional COMPONENTS
+^^^^^^^^^^^^^^^^^^^
+
+This module supports two optional COMPONENTS: ``Crypto`` and ``SSL``. Both
+components have associated imported targets, as described below.
+
+Imported Targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``OpenSSL::SSL``
+ The OpenSSL ``ssl`` library, if found.
+``OpenSSL::Crypto``
+ The OpenSSL ``crypto`` library, if found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``OPENSSL_FOUND``
+ System has the OpenSSL library. If no components are requested it only
+ requires the crypto library.
+``OPENSSL_INCLUDE_DIR``
+ The OpenSSL include directory.
+``OPENSSL_CRYPTO_LIBRARY``
+ The OpenSSL crypto library.
+``OPENSSL_SSL_LIBRARY``
+ The OpenSSL SSL library.
+``OPENSSL_LIBRARIES``
+ All OpenSSL libraries.
+``OPENSSL_VERSION``
+ This is set to ``$major.$minor.$revision$patch`` (e.g. ``0.9.8s``).
+
+Hints
+^^^^^
+
+Set ``OPENSSL_ROOT_DIR`` to the root directory of an OpenSSL installation.
+Set ``OPENSSL_USE_STATIC_LIBS`` to ``TRUE`` to look for static libraries.
+Set ``OPENSSL_MSVC_STATIC_RT`` set ``TRUE`` to choose the MT version of the lib.
+#]=======================================================================]
if (UNIX)
find_package(PkgConfig QUIET)
@@ -110,7 +118,7 @@ if(WIN32 AND NOT CYGWIN)
# * MTd for static-debug
# Implementation details:
- # We are using the libraries located in the VC subdir instead of the parent directory eventhough :
+ # We are using the libraries located in the VC subdir instead of the parent directory even though :
# libeay32MD.lib is identical to ../libeay32.lib, and
# ssleay32MD.lib is identical to ../ssleay32.lib
# enable OPENSSL_USE_STATIC_LIBS to use the static libs located in lib/VC/static
@@ -149,6 +157,7 @@ if(WIN32 AND NOT CYGWIN)
libcryptod
libeay32${_OPENSSL_MSVC_RT_MODE}d
libeay32d
+ cryptod
NAMES_PER_DIR
${_OPENSSL_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES
@@ -176,6 +185,7 @@ if(WIN32 AND NOT CYGWIN)
libssld
ssleay32${_OPENSSL_MSVC_RT_MODE}d
ssleay32d
+ ssld
NAMES_PER_DIR
${_OPENSSL_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES
@@ -369,28 +379,47 @@ if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h")
endif ()
endif ()
-include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-
set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} )
-if (OPENSSL_VERSION)
- find_package_handle_standard_args(OpenSSL
- REQUIRED_VARS
- #OPENSSL_SSL_LIBRARY # FIXME: require based on a component request?
- OPENSSL_CRYPTO_LIBRARY
- 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_SSL_LIBRARY # FIXME: require based on a component request?
+foreach(_comp IN LISTS OpenSSL_FIND_COMPONENTS)
+ if(_comp STREQUAL "Crypto")
+ if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND
+ (EXISTS "${OPENSSL_CRYPTO_LIBRARY}" OR
+ EXISTS "${LIB_EAY_LIBRARY_DEBUG}" OR
+ EXISTS "${LIB_EAY_LIBRARY_RELEASE}")
+ )
+ set(OpenSSL_${_comp}_FOUND TRUE)
+ else()
+ set(OpenSSL_${_comp}_FOUND FALSE)
+ endif()
+ elseif(_comp STREQUAL "SSL")
+ if(EXISTS "${OPENSSL_INCLUDE_DIR}" AND
+ (EXISTS "${OPENSSL_SSL_LIBRARY}" OR
+ EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR
+ EXISTS "${SSL_EAY_LIBRARY_RELEASE}")
+ )
+ set(OpenSSL_${_comp}_FOUND TRUE)
+ else()
+ set(OpenSSL_${_comp}_FOUND FALSE)
+ endif()
+ else()
+ message(WARNING "${_comp} is not a valid OpenSSL component")
+ set(OpenSSL_${_comp}_FOUND FALSE)
+ endif()
+endforeach()
+unset(_comp)
+
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+find_package_handle_standard_args(OpenSSL
+ REQUIRED_VARS
OPENSSL_CRYPTO_LIBRARY
OPENSSL_INCLUDE_DIR
- )
-endif ()
+ VERSION_VAR
+ OPENSSL_VERSION
+ HANDLE_COMPONENTS
+ FAIL_MESSAGE
+ "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR"
+)
mark_as_advanced(OPENSSL_INCLUDE_DIR OPENSSL_LIBRARIES)
@@ -423,6 +452,7 @@ if(OPENSSL_FOUND)
IMPORTED_LOCATION_DEBUG "${LIB_EAY_LIBRARY_DEBUG}")
endif()
endif()
+
if(NOT TARGET OpenSSL::SSL AND
(EXISTS "${OPENSSL_SSL_LIBRARY}" OR
EXISTS "${SSL_EAY_LIBRARY_DEBUG}" OR
diff --git a/Modules/FindOpenSceneGraph.cmake b/Modules/FindOpenSceneGraph.cmake
index 425aa4581..27909bcea 100644
--- a/Modules/FindOpenSceneGraph.cmake
+++ b/Modules/FindOpenSceneGraph.cmake
@@ -1,102 +1,105 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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})
+#[=======================================================================[.rst:
+FindOpenSceneGraph
+------------------
+
+Find OpenSceneGraph (3D graphics application programming interface)
+
+This module searches for the OpenSceneGraph core "osg" library as well
+as :module:`FindOpenThreads`, 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 :command:`cmake_minimum_required(VERSION 2.6.3)` or download
+and place :module:`FindOpenThreads`, :module:`Findosg` functions,
+:module:`Findosg` and ``Find<etc>.cmake`` files into your
+:variable:`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. :variable:`CMAKE_PREFIX_PATH` can also be
+used for this (see :command:`find_library` CMake documentation).
+
+``<MODULE>_DIR``
+ (where ``MODULE`` is of the form "OSGVOLUME" and there is
+ a :module:`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})
+#]=======================================================================]
#
# Naming convention:
diff --git a/Modules/FindOpenThreads.cmake b/Modules/FindOpenThreads.cmake
index 54804b87d..bc45eea7b 100644
--- a/Modules/FindOpenThreads.cmake
+++ b/Modules/FindOpenThreads.cmake
@@ -1,30 +1,31 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <OpenThreads/Thread>
@@ -47,6 +48,8 @@
# standard install paths.
# Explicit -DVAR=value arguments should still be able to override everything.
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+
find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
HINTS
ENV OPENTHREADS_INCLUDE_DIR
@@ -58,17 +61,11 @@ find_path(OPENTHREADS_INCLUDE_DIR OpenThreads/Thread
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
+find_library(OPENTHREADS_LIBRARY_RELEASE
NAMES OpenThreads OpenThreadsWin32
HINTS
ENV OPENTHREADS_LIBRARY_DIR
@@ -80,12 +77,6 @@ find_library(OPENTHREADS_LIBRARY
ENV OSG_ROOT
${OPENTHREADS_DIR}
${OSG_DIR}
- PATHS
- /sw
- /opt/local
- /opt/csw
- /opt
- /usr/freeware
PATH_SUFFIXES lib
)
@@ -102,22 +93,10 @@ find_library(OPENTHREADS_LIBRARY_DEBUG
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()
+select_library_configurations(OPENTHREADS)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenThreads DEFAULT_MSG
diff --git a/Modules/FindPHP4.cmake b/Modules/FindPHP4.cmake
index 426453bd4..34b4adb01 100644
--- a/Modules/FindPHP4.cmake
+++ b/Modules/FindPHP4.cmake
@@ -1,20 +1,21 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
set(PHP4_POSSIBLE_INCLUDE_PATHS
/usr/include/php4
diff --git a/Modules/FindPNG.cmake b/Modules/FindPNG.cmake
index dceb6bcc5..a7908c5c3 100644
--- a/Modules/FindPNG.cmake
+++ b/Modules/FindPNG.cmake
@@ -1,49 +1,50 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindPNG
-# -------
-#
-# Find libpng, the official reference library for the PNG image format.
-#
-# Imported targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following :prop_tgt:`IMPORTED` target:
-#
-# ``PNG::PNG``
-# The libpng library, if found.
-#
-# Result variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module will set the following variables in your project:
-#
-# ``PNG_INCLUDE_DIRS``
-# where to find png.h, etc.
-# ``PNG_LIBRARIES``
-# the libraries to link against to use PNG.
-# ``PNG_DEFINITIONS``
-# You should add_definitions(${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)
-#
-# Obsolete variables
-# ^^^^^^^^^^^^^^^^^^
-#
-# The following variables may also be set, for backwards compatibility:
-#
-# ``PNG_LIBRARY``
-# where to find the PNG library.
-# ``PNG_INCLUDE_DIR``
-# where to find the PNG headers (same as PNG_INCLUDE_DIRS)
-#
-# Since PNG depends on the ZLib compression library, none of the above
-# will be defined unless ZLib can be found.
+#[=======================================================================[.rst:
+FindPNG
+-------
+
+Find libpng, the official reference library for the PNG image format.
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` target:
+
+``PNG::PNG``
+ The libpng library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``PNG_INCLUDE_DIRS``
+ where to find png.h, etc.
+``PNG_LIBRARIES``
+ the libraries to link against to use PNG.
+``PNG_DEFINITIONS``
+ You should add_definitions(${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)
+
+Obsolete variables
+^^^^^^^^^^^^^^^^^^
+
+The following variables may also be set, for backwards compatibility:
+
+``PNG_LIBRARY``
+ where to find the PNG library.
+``PNG_INCLUDE_DIR``
+ where to find the PNG headers (same as PNG_INCLUDE_DIRS)
+
+Since PNG depends on the ZLib compression library, none of the above
+will be defined unless ZLib can be found.
+#]=======================================================================]
if(PNG_FIND_QUIETLY)
set(_FIND_ZLIB_ARG QUIET)
@@ -51,9 +52,7 @@ endif()
find_package(ZLIB ${_FIND_ZLIB_ARG})
if(ZLIB_FOUND)
- find_path(PNG_PNG_INCLUDE_DIR png.h
- /usr/local/include/libpng # OpenBSD
- )
+ find_path(PNG_PNG_INCLUDE_DIR png.h PATH_SUFFIXES include/libpng)
list(APPEND PNG_NAMES png libpng)
unset(PNG_NAMES_DEBUG)
@@ -101,13 +100,14 @@ if(ZLIB_FOUND)
# No need to define PNG_USE_DLL here, because it's default for Cygwin.
else()
set (PNG_DEFINITIONS -DPNG_STATIC)
+ set(_PNG_COMPILE_DEFINITIONS PNG_STATIC)
endif()
endif ()
if(NOT TARGET PNG::PNG)
add_library(PNG::PNG UNKNOWN IMPORTED)
set_target_properties(PNG::PNG PROPERTIES
- INTERFACE_COMPILE_DEFINITIONS "${PNG_DEFINITIONS}"
+ INTERFACE_COMPILE_DEFINITIONS "${_PNG_COMPILE_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${PNG_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
if(EXISTS "${PNG_LIBRARY}")
@@ -130,6 +130,8 @@ if(ZLIB_FOUND)
IMPORTED_LOCATION_DEBUG "${PNG_LIBRARY_DEBUG}")
endif()
endif()
+
+ unset(_PNG_COMPILE_DEFINITIONS)
endif ()
if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake
index b851a90ff..1722d6aaf 100644
--- a/Modules/FindPackageHandleStandardArgs.cmake
+++ b/Modules/FindPackageHandleStandardArgs.cmake
@@ -145,7 +145,7 @@ 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:
+ # <PackageName>_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()
@@ -175,11 +175,12 @@ 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 up the arguments for `cmake_parse_arguments`.
set(options CONFIG_MODE HANDLE_COMPONENTS)
set(oneValueArgs FAIL_MESSAGE VERSION_VAR FOUND_VAR)
set(multiValueArgs REQUIRED_VARS)
+
+# Check whether we are in 'simple' or 'extended' mode:
set(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} )
list(FIND _KEYWORDS_FOR_EXTENDED_MODE "${_FIRST_ARG}" INDEX)
@@ -188,8 +189,7 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
set(FPHSA_REQUIRED_VARS ${ARGN})
set(FPHSA_VERSION_VAR)
else()
-
- CMAKE_PARSE_ARGUMENTS(FPHSA "${options}" "${oneValueArgs}" "${multiValueArgs}" ${_FIRST_ARG} ${ARGN})
+ 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}\"")
@@ -198,6 +198,18 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
if(NOT FPHSA_FAIL_MESSAGE)
set(FPHSA_FAIL_MESSAGE "DEFAULT_MSG")
endif()
+
+ # In config-mode, we rely on the variable <PackageName>_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()
endif()
# now that we collected all arguments, process them
@@ -206,18 +218,6 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
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)
@@ -289,15 +289,15 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
# 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})
+ set(_FOUND_VERSION ${${FPHSA_VERSION_VAR}})
if(${_NAME}_FIND_VERSION_EXACT) # exact version required
# count the dots in the version string
- string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${VERSION}")
+ string(REGEX REPLACE "[^.]" "" _VERSION_DOTS "${_FOUND_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)
@@ -312,31 +312,31 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
else ()
set(_VERSION_REGEX "[^.]*\\.[^.]*\\.[^.]*\\.[^.]*")
endif ()
- string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${VERSION}")
+ string(REGEX REPLACE "^(${_VERSION_REGEX})\\..*" "\\1" _VERSION_HEAD "${_FOUND_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_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
set(VERSION_OK FALSE)
else ()
- set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
+ set(VERSION_MSG "(found suitable exact version \"${_FOUND_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}\"")
+ if (NOT ${_NAME}_FIND_VERSION VERSION_EQUAL _FOUND_VERSION)
+ set(VERSION_MSG "Found unsuitable version \"${_FOUND_VERSION}\", but required is exact version \"${${_NAME}_FIND_VERSION}\"")
set(VERSION_OK FALSE)
else ()
- set(VERSION_MSG "(found suitable exact version \"${VERSION}\")")
+ set(VERSION_MSG "(found suitable exact version \"${_FOUND_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}\"")
+ if (${_NAME}_FIND_VERSION VERSION_GREATER _FOUND_VERSION)
+ set(VERSION_MSG "Found unsuitable version \"${_FOUND_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}\")")
+ set(VERSION_MSG "(found suitable version \"${_FOUND_VERSION}\", minimum required is \"${${_NAME}_FIND_VERSION}\")")
endif ()
endif()
@@ -351,13 +351,14 @@ function(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG)
endif()
else ()
- if(VERSION)
- set(VERSION_MSG "(found version \"${VERSION}\")")
+ # Check with DEFINED as the found version may be 0.
+ if(DEFINED ${FPHSA_VERSION_VAR})
+ set(VERSION_MSG "(found version \"${${FPHSA_VERSION_VAR}}\")")
endif()
endif ()
if(VERSION_OK)
- string(APPEND DETAILS "[v${VERSION}(${${_NAME}_FIND_VERSION})]")
+ string(APPEND DETAILS "[v${${FPHSA_VERSION_VAR}}(${${_NAME}_FIND_VERSION})]")
else()
set(${_NAME}_FOUND FALSE)
endif()
diff --git a/Modules/FindPackageMessage.cmake b/Modules/FindPackageMessage.cmake
index 6821cee4f..0628b9816 100644
--- a/Modules/FindPackageMessage.cmake
+++ b/Modules/FindPackageMessage.cmake
@@ -1,35 +1,36 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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()
-
-function(FIND_PACKAGE_MESSAGE pkg msg details)
+#[=======================================================================[.rst:
+FindPackageMessage
+------------------
+
+.. code-block:: cmake
+
+ find_package_message(<name> "message for user" "find result details")
+
+This function 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:
+
+.. code-block:: cmake
+
+ if(X11_FOUND)
+ find_package_message(X11 "Found X11: ${X11_X11_LIB}"
+ "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]")
+ else()
+ ...
+ endif()
+#]=======================================================================]
+
+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}")
diff --git a/Modules/FindPerl.cmake b/Modules/FindPerl.cmake
index 423fc6987..fd120bf8e 100644
--- a/Modules/FindPerl.cmake
+++ b/Modules/FindPerl.cmake
@@ -1,19 +1,20 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.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)
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
@@ -28,6 +29,7 @@ if(WIN32)
NAME)
set(PERL_POSSIBLE_BIN_PATHS ${PERL_POSSIBLE_BIN_PATHS}
"C:/Perl/bin"
+ "C:/Strawberry/perl/bin"
[HKEY_LOCAL_MACHINE\\SOFTWARE\\ActiveState\\ActivePerl\\${ActivePerl_CurrentVersion}]/bin
)
endif()
diff --git a/Modules/FindPerlLibs.cmake b/Modules/FindPerlLibs.cmake
index e01e75e2d..7e27f3188 100644
--- a/Modules/FindPerlLibs.cmake
+++ b/Modules/FindPerlLibs.cmake
@@ -1,224 +1,126 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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 (-V:installsitesearch)
+ PERL_SITEARCH = path to the sitelib install directory (-V:installsitearch)
+ PERL_SITELIB = path to the sitelib install directory (-V:installsitelib)
+ PERL_VENDORARCH = path to the vendor arch install directory (-V:installvendorarch)
+ PERL_VENDORLIB = path to the vendor lib install directory (-V:installvendorlib)
+ PERL_ARCHLIB = path to the core arch lib install directory (-V:archlib)
+ PERL_PRIVLIB = path to the core priv lib install directory (-V:privlib)
+ PERL_UPDATE_ARCHLIB = path to the update arch lib install directory (-V:installarchlib)
+ PERL_UPDATE_PRIVLIB = path to the update priv lib install directory (-V:installprivlib)
+ PERL_EXTRA_C_FLAGS = Compilation flags used to build perl
+#]=======================================================================]
# 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 ()
+ function (perl_get_info _pgi_info tag)
+ cmake_parse_arguments(_PGI "IS_PATH" "" "" ${ARGN})
- ### 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 ()
+ set (${_pgi_info} NOTFOUND PARENT_SCOPE)
+ execute_process(COMMAND "${PERL_EXECUTABLE}" -V:${tag}
+ OUTPUT_VARIABLE result
+ RESULT_VARIABLE status)
+ if (NOT status)
+ string(REGEX REPLACE "${tag}='([^']*)'.*" "\\1" result "${result}")
+ if (_PGI_IS_PATH)
+ file(TO_CMAKE_PATH "${result}" result)
+ endif()
+ set (${_pgi_info} "${result}" PARENT_SCOPE)
+ endif ()
+ endfunction()
+
+ ### PERL_PREFIX
+ perl_get_info(PERL_PREFIX prefix IS_PATH)
+
+ ### PERL_ARCHNAME
+ perl_get_info(PERL_ARCHNAME archname)
### 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_get_info(PERL_EXTRA_C_FLAGS cppflags)
### 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_get_info(PERL_SITESEARCH installsitesearch IS_PATH)
+
+ ### PERL_SITEARCH
+ perl_get_info(PERL_SITEARCH installsitearch IS_PATH)
### 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_get_info(PERL_SITELIB installsitelib IS_PATH)
### 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_get_info(PERL_VENDORARCH installvendorarch IS_PATH)
### 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_get_info(PERL_VENDORLIB installvendorlib IS_PATH)
### 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_get_info(PERL_ARCHLIB archlib IS_PATH)
### 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_get_info(PERL_PRIVLIB privlib IS_PATH)
+
+ ### PERL_UPDATE_ARCHLIB
+ perl_get_info(PERL_UPDATE_ARCHLIB installarchlib IS_PATH)
+
+ ### PERL_UPDATE_PRIVLIB
+ perl_get_info(PERL_UPDATE_PRIVLIB installprivlib IS_PATH)
### 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 ()
+ perl_get_info(PERL_POSSIBLE_LIBRARY_NAMES libperl)
+ if (NOT PERL_POSSIBLE_LIBRARY_NAMES)
set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl)
- endif ()
+ endif()
+ if (CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN")
+ # on MSYS and CYGWIN environments, current perl -V:libperl gives shared library name
+ # rather than the import library. So, extends possible library names
+ list (APPEND PERL_POSSIBLE_LIBRARY_NAMES perl)
+ endif()
### PERL_INCLUDE_PATH
find_path(PERL_INCLUDE_PATH
NAMES
perl.h
PATHS
- ${PERL_ARCHLIB}/CORE
+ "${PERL_UPDATE_ARCHLIB}/CORE"
+ "${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
@@ -230,7 +132,8 @@ if (PERL_EXECUTABLE)
NAMES
${PERL_POSSIBLE_LIBRARY_NAMES}
PATHS
- ${PERL_ARCHLIB}/CORE
+ "${PERL_UPDATE_ARCHLIB}/CORE"
+ "${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
diff --git a/Modules/FindPhysFS.cmake b/Modules/FindPhysFS.cmake
index cfe9b0f19..a32f83aae 100644
--- a/Modules/FindPhysFS.cmake
+++ b/Modules/FindPhysFS.cmake
@@ -1,20 +1,21 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
find_path(PHYSFS_INCLUDE_DIR physfs.h
HINTS
@@ -23,9 +24,6 @@ find_path(PHYSFS_INCLUDE_DIR physfs.h
PATHS
~/Library/Frameworks
/Library/Frameworks
- /sw # Fink
- /opt/local # DarwinPorts
- /opt/csw # Blastwave
/opt
)
@@ -37,9 +35,6 @@ find_library(PHYSFS_LIBRARY
PATHS
~/Library/Frameworks
/Library/Frameworks
- /sw
- /opt/local
- /opt/csw
/opt
)
diff --git a/Modules/FindPike.cmake b/Modules/FindPike.cmake
index dff55a480..b78db2adb 100644
--- a/Modules/FindPike.cmake
+++ b/Modules/FindPike.cmake
@@ -1,30 +1,28 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
-
-file(GLOB PIKE_POSSIBLE_INCLUDE_PATHS
- /usr/include/pike/*
- /usr/local/include/pike/*)
+#[=======================================================================[.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
+#]=======================================================================]
find_path(PIKE_INCLUDE_PATH program.h
- ${PIKE_POSSIBLE_INCLUDE_PATHS})
+ ${PIKE_POSSIBLE_INCLUDE_PATHS}
+ PATH_SUFFIXES include/pike8.0/pike include/pike7.8/pike include/pike7.4/pike)
find_program(PIKE_EXECUTABLE
- NAMES pike7.4
+ NAMES pike8.0 pike 7.8 pike7.4
)
mark_as_advanced(
diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake
index a5357fa1c..e05d5c8e5 100644
--- a/Modules/FindPkgConfig.cmake
+++ b/Modules/FindPkgConfig.cmake
@@ -1,19 +1,24 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[========================================[.rst:
+FindPkgConfig
+-------------
+
+A ``pkg-config`` module for CMake.
+
+Finds the ``pkg-config`` executable and adds the :command:`pkg_get_variable`,
+:command:`pkg_check_modules` and :command:`pkg_search_module` commands. The
+following variables will also be set:
+
+``PKG_CONFIG_FOUND``
+ if pkg-config executable was found
+``PKG_CONFIG_EXECUTABLE``
+ pathname of the pkg-config program
+``PKG_CONFIG_VERSION_STRING``
+ version of pkg-config (since CMake 2.8.8)
+
+#]========================================]
### Common stuff ####
set(PKG_CONFIG_VERSION 1)
@@ -79,23 +84,8 @@ macro(_pkgconfig_invoke _pkglist _prefix _varname _regexp)
endif()
endmacro()
-#[========================================[.rst:
-.. command:: pkg_get_variable
-
- Retrieves the value of a variable from a package::
-
- pkg_get_variable(<RESULT> <MODULE> <VARIABLE>)
-
- If multiple values are returned variable will contain a
- :ref:`;-list <CMake Language Lists>`.
-
- For example:
-
- .. code-block:: cmake
-
- pkg_get_variable(GI_GIRDIR gobject-introspection-1.0 girdir)
-#]========================================]
-function (pkg_get_variable result pkg variable)
+# Internal version of pkg_get_variable; expects PKG_CONFIG_PATH to already be set
+function (_pkg_get_variable result pkg variable)
_pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}")
set("${result}"
"${prefix_result}"
@@ -110,12 +100,13 @@ macro(_pkgconfig_invoke_dyn _pkglist _prefix _varname cleanup_regexp)
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 _imp_target)
+macro(_pkgconfig_parse_options _result _is_req _is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global)
set(${_is_req} 0)
set(${_is_silent} 0)
set(${_no_cmake_path} 0)
set(${_no_cmake_environment_path} 0)
set(${_imp_target} 0)
+ set(${_imp_target_global} 0)
if(DEFINED PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
if(NOT PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
set(${_no_cmake_path} 1)
@@ -142,14 +133,22 @@ macro(_pkgconfig_parse_options _result _is_req _is_silent _no_cmake_path _no_cma
if (_pkg STREQUAL "IMPORTED_TARGET")
set(${_imp_target} 1)
endif()
+ if (_pkg STREQUAL "GLOBAL")
+ set(${_imp_target_global} 1)
+ endif()
endforeach()
+ if (${_imp_target_global} AND NOT ${_imp_target})
+ message(SEND_ERROR "the argument GLOBAL may only be used together with IMPORTED_TARGET")
+ endif()
+
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")
list(REMOVE_ITEM ${_result} "IMPORTED_TARGET")
+ list(REMOVE_ITEM ${_result} "GLOBAL")
endmacro()
# Add the content of a variable or an environment variable to a list of
@@ -179,26 +178,24 @@ endfunction()
# scan the LDFLAGS returned by pkg-config for library directories and
# libraries, figure out the absolute paths of that libraries in the
-# given directories, and create an imported target from them
-function(_pkg_create_imp_target _prefix _no_cmake_path _no_cmake_environment_path)
+# given directories
+function(_pkg_find_libs _prefix _no_cmake_path _no_cmake_environment_path)
unset(_libs)
unset(_find_opts)
# set the options that are used as long as the .pc file does not provide a library
# path to look into
if(_no_cmake_path)
- set(_find_opts "NO_CMAKE_PATH")
+ list(APPEND _find_opts "NO_CMAKE_PATH")
endif()
if(_no_cmake_environment_path)
- string(APPEND _find_opts " NO_CMAKE_ENVIRONMENT_PATH")
+ list(APPEND _find_opts "NO_CMAKE_ENVIRONMENT_PATH")
endif()
unset(_search_paths)
foreach (flag IN LISTS ${_prefix}_LDFLAGS)
if (flag MATCHES "^-L(.*)")
- # only look into the given paths from now on
list(APPEND _search_paths ${CMAKE_MATCH_1})
- set(_find_opts HINTS ${_search_paths} NO_DEFAULT_PATH)
continue()
endif()
if (flag MATCHES "^-l(.*)")
@@ -207,25 +204,45 @@ function(_pkg_create_imp_target _prefix _no_cmake_path _no_cmake_environment_pat
continue()
endif()
+ if(_search_paths)
+ # Firstly search in -L paths
+ find_library(pkgcfg_lib_${_prefix}_${_pkg_search}
+ NAMES ${_pkg_search}
+ HINTS ${_search_paths} NO_DEFAULT_PATH)
+ endif()
find_library(pkgcfg_lib_${_prefix}_${_pkg_search}
NAMES ${_pkg_search}
${_find_opts})
+ mark_as_advanced(pkgcfg_lib_${_prefix}_${_pkg_search})
list(APPEND _libs "${pkgcfg_lib_${_prefix}_${_pkg_search}}")
endforeach()
+ set(${_prefix}_LINK_LIBRARIES "${_libs}" PARENT_SCOPE)
+endfunction()
+
+# create an imported target from all the information returned by pkg-config
+function(_pkg_create_imp_target _prefix _imp_target_global)
# only create the target if it is linkable, i.e. no executables
if (NOT TARGET PkgConfig::${_prefix}
- AND ( ${_prefix}_INCLUDE_DIRS OR _libs OR ${_prefix}_CFLAGS_OTHER ))
- add_library(PkgConfig::${_prefix} INTERFACE IMPORTED)
+ AND ( ${_prefix}_INCLUDE_DIRS OR ${_prefix}_LINK_LIBRARIES OR ${_prefix}_LDFLAGS_OTHER OR ${_prefix}_CFLAGS_OTHER ))
+ if(${_imp_target_global})
+ set(_global_opt "GLOBAL")
+ else()
+ unset(_global_opt)
+ endif()
+ add_library(PkgConfig::${_prefix} INTERFACE IMPORTED ${_global_opt})
- unset(_props)
if(${_prefix}_INCLUDE_DIRS)
set_property(TARGET PkgConfig::${_prefix} PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${${_prefix}_INCLUDE_DIRS}")
endif()
- if(_libs)
+ if(${_prefix}_LINK_LIBRARIES)
+ set_property(TARGET PkgConfig::${_prefix} PROPERTY
+ INTERFACE_LINK_LIBRARIES "${${_prefix}_LINK_LIBRARIES}")
+ endif()
+ if(${_prefix}_LDFLAGS_OTHER)
set_property(TARGET PkgConfig::${_prefix} PROPERTY
- INTERFACE_LINK_LIBRARIES "${_libs}")
+ INTERFACE_LINK_OPTIONS "${${_prefix}_LDFLAGS_OTHER}")
endif()
if(${_prefix}_CFLAGS_OTHER)
set_property(TARGET PkgConfig::${_prefix} PROPERTY
@@ -234,8 +251,113 @@ function(_pkg_create_imp_target _prefix _no_cmake_path _no_cmake_environment_pat
endif()
endfunction()
+# recalculate the dynamic output
+# this is a macro and not a function so the result of _pkg_find_libs is automatically propagated
+macro(_pkg_recalculate _prefix _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global)
+ _pkg_find_libs(${_prefix} ${_no_cmake_path} ${_no_cmake_environment_path})
+ if(${_imp_target})
+ _pkg_create_imp_target(${_prefix} ${_imp_target_global})
+ endif()
+endmacro()
+
###
-macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cmake_environment_path _imp_target _prefix)
+macro(_pkg_set_path_internal)
+ 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, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
+ get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
+ if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
+ list(APPEND _lib_dirs "lib32/pkgconfig")
+ endif()
+ get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
+ if(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
+ list(APPEND _lib_dirs "lib64/pkgconfig")
+ endif()
+ get_property(uselibx32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIBX32_PATHS)
+ if(uselibx32 AND CMAKE_INTERNAL_PLATFORM_ABI STREQUAL "ELF X32")
+ list(APPEND _lib_dirs "libx32/pkgconfig")
+ endif()
+ endif()
+ endif()
+ if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" AND NOT CMAKE_CROSSCOMPILING)
+ list(APPEND _lib_dirs "libdata/pkgconfig")
+ endif()
+ list(APPEND _lib_dirs "lib/pkgconfig")
+ list(APPEND _lib_dirs "share/pkgconfig")
+
+ # Check if directories exist and eventually append them to the
+ # pkgconfig path list
+ 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()
+endmacro()
+
+macro(_pkg_restore_path_internal)
+ if(NOT _extra_paths STREQUAL "")
+ # Restore the environment variable
+ set(ENV{PKG_CONFIG_PATH} "${_pkgconfig_path_old}")
+ endif()
+
+ unset(_extra_paths)
+ unset(_pkgconfig_path_old)
+endmacro()
+
+###
+macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global _prefix)
_pkgconfig_unset(${_prefix}_FOUND)
_pkgconfig_unset(${_prefix}_VERSION)
_pkgconfig_unset(${_prefix}_PREFIX)
@@ -274,92 +396,14 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
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, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
- get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
- if(uselib32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
- list(APPEND _lib_dirs "lib32/pkgconfig")
- endif()
- get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
- if(uselib64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
- list(APPEND _lib_dirs "lib64/pkgconfig")
- endif()
- get_property(uselibx32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIBX32_PATHS)
- if(uselibx32 AND CMAKE_INTERNAL_PLATFORM_ABI STREQUAL "ELF X32")
- list(APPEND _lib_dirs "libx32/pkgconfig")
- endif()
- endif()
- endif()
- list(APPEND _lib_dirs "lib/pkgconfig")
- list(APPEND _lib_dirs "share/pkgconfig")
-
- # Check if directories exist and eventually append them to the
- # pkgconfig path list
- 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()
+ _pkg_set_path_internal()
# 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 "(.*[^><])(>=|=|<=)(.*)")
+ 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}")
@@ -377,9 +421,11 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
list(APPEND _pkg_check_modules_packages "${_pkg_check_modules_pkg_name}")
# create the final query which is of the format:
+ # * <pkg-name> > <version>
# * <pkg-name> >= <version>
# * <pkg-name> = <version>
# * <pkg-name> <= <version>
+ # * <pkg-name> < <version>
# * --exists <pkg-name>
list(APPEND _pkg_check_modules_exist_query --print-errors --short-errors)
if (_pkg_check_modules_pkg_op)
@@ -450,18 +496,10 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
_pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS "" --cflags )
_pkgconfig_invoke_dyn("${_pkg_check_modules_packages}" "${_prefix}" CFLAGS_OTHER "" --cflags-only-other )
- if (_imp_target)
- _pkg_create_imp_target("${_prefix}" _no_cmake_path _no_cmake_environment_path)
- endif()
- endif()
-
- if(NOT "${_extra_paths}" STREQUAL "")
- # Restore the environment variable
- set(ENV{PKG_CONFIG_PATH} "${_pkgconfig_path_old}")
+ _pkg_recalculate("${_prefix}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global})
endif()
- unset(_extra_paths)
- unset(_pkgconfig_path_old)
+ _pkg_restore_path_internal()
else()
if (${_is_required})
message(SEND_ERROR "pkg-config tool not found")
@@ -469,130 +507,143 @@ macro(_pkg_check_modules_internal _is_required _is_silent _no_cmake_path _no_cma
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]
- [IMPORTED_TARGET]
- <MODULE> [<MODULE>]*)
+ Checks for all the given modules, setting a variety of result variables in
+ the calling scope.
+ .. code-block:: cmake
- 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.
- The ``IMPORTED_TARGET`` argument will create an imported target named
- PkgConfig::<PREFIX>> that can be passed directly as an argument to
- :command:`target_link_libraries`.
-
- 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
-
- Every variable containing multiple values will be a
- :ref:`;-list <CMake Language Lists>`.
-
- 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>
+ pkg_check_modules(<prefix>
+ [REQUIRED] [QUIET]
+ [NO_CMAKE_PATH]
+ [NO_CMAKE_ENVIRONMENT_PATH]
+ [IMPORTED_TARGET [GLOBAL]]
+ <moduleSpec> [<moduleSpec>...])
+
+ When the ``REQUIRED`` argument is given, the command will fail with an error
+ if module(s) could not be found.
+
+ When the ``QUIET`` argument is given, 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 to a
+ boolean ``True`` value, then the :variable:`CMAKE_PREFIX_PATH`,
+ :variable:`CMAKE_FRAMEWORK_PATH`, and :variable:`CMAKE_APPBUNDLE_PATH` cache
+ and environment variables will be added to the ``pkg-config`` search path.
+ The ``NO_CMAKE_PATH`` and ``NO_CMAKE_ENVIRONMENT_PATH`` arguments
+ disable this behavior for the cache variables and environment variables
+ respectively.
+
+ The ``IMPORTED_TARGET`` argument will create an imported target named
+ ``PkgConfig::<prefix>`` that can be passed directly as an argument to
+ :command:`target_link_libraries`. The ``GLOBAL`` argument will make the
+ imported target available in global scope.
+
+ Each ``<moduleSpec>`` can be either a bare module name or it can be a
+ module name with a version constraint (operators ``=``, ``<``, ``>``,
+ ``<=`` and ``>=`` are supported). The following are examples for a module
+ named ``foo`` with various constraints:
+
+ - ``foo`` matches any version.
+ - ``foo<2`` only matches versions before 2.
+ - ``foo>=3.1`` matches any version from 3.1 or later.
+ - ``foo=1.2.3`` requires that foo must be exactly version 1.2.3.
+
+ The following variables may be set upon return. Two sets of values exist:
+ One for the common case (``<XXX> = <prefix>``) and another for the
+ information ``pkg-config`` provides when called with the ``--static``
+ option (``<XXX> = <prefix>_STATIC``).
+
+ ``<XXX>_FOUND``
+ set to 1 if module(s) exist
+ ``<XXX>_LIBRARIES``
+ only the libraries (without the '-l')
+ ``<XXX>_LINK_LIBRARIES``
+ the libraries and their absolute paths
+ ``<XXX>_LIBRARY_DIRS``
+ the paths of the libraries (without the '-L')
+ ``<XXX>_LDFLAGS``
+ all required linker flags
+ ``<XXX>_LDFLAGS_OTHER``
+ all other linker flags
+ ``<XXX>_INCLUDE_DIRS``
+ the '-I' preprocessor flags (without the '-I')
+ ``<XXX>_CFLAGS``
+ all required cflags
+ ``<XXX>_CFLAGS_OTHER``
+ the other compiler flags
+
+ All but ``<XXX>_FOUND`` may be a :ref:`;-list <CMake Language Lists>` if the
+ associated variable returned from ``pkg-config`` has multiple values.
+
+ There are some special variables whose prefix depends on the number of
+ ``<moduleSpec>`` given. When there is only one ``<moduleSpec>``,
+ ``<YYY>`` will simply be ``<prefix>``, but if two or more ``<moduleSpec>``
+ items are given, ``<YYY>`` will be ``<prefix>_<moduleName>``.
+
+ ``<YYY>_VERSION``
+ version of the module
+ ``<YYY>_PREFIX``
+ prefix directory of the module
+ ``<YYY>_INCLUDEDIR``
+ include directory of the module
+ ``<YYY>_LIBDIR``
+ lib directory of the module
+
+ Examples:
- Examples
+ .. code-block:: cmake
- .. code-block:: cmake
+ pkg_check_modules (GLIB2 glib-2.0)
- pkg_check_modules (GLIB2 glib-2.0)
+ Looks for any version of glib2. If found, the output variable
+ ``GLIB2_VERSION`` will hold the actual version found.
- .. code-block:: cmake
+ .. code-block:: cmake
- pkg_check_modules (GLIB2 glib-2.0>=2.10)
+ 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``
+ Looks for at least version 2.10 of glib2. If found, the output variable
+ ``GLIB2_VERSION`` will hold the actual version found.
- .. code-block:: cmake
+ .. code-block:: cmake
- pkg_check_modules (FOO glib-2.0>=2.10 gtk+-2.0)
+ 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``
+ Looks for both glib2-2.0 (at least version 2.10) and any version of
+ gtk2+-2.0. Only if both are found will ``FOO`` be considered found.
+ The ``FOO_glib-2.0_VERSION`` and ``FOO_gtk+-2.0_VERSION`` variables will be
+ set to their respective found module versions.
- .. code-block:: cmake
+ .. code-block:: cmake
pkg_check_modules (XRENDER REQUIRED xrender)
- Defines for example::
+ Requires any version of ``xrender``. Example output variables set by a
+ successful call::
- XRENDER_LIBRARIES=Xrender;X11``
- XRENDER_STATIC_LIBRARIES=Xrender;X11;pthread;Xau;Xdmcp
+ XRENDER_LIBRARIES=Xrender;X11
+ XRENDER_STATIC_LIBRARIES=Xrender;X11;pthread;Xau;Xdmcp
#]========================================]
macro(pkg_check_modules _prefix _module0)
- _pkgconfig_parse_options(_pkg_modules _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path _imp_target "${_module0}" ${ARGN})
+ _pkgconfig_parse_options(_pkg_modules _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global "${_module0}" ${ARGN})
# check cached value
- if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND OR NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0};${ARGN}")
- _pkg_check_modules_internal("${_pkg_is_required}" "${_pkg_is_silent}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} "${_prefix}" ${_pkg_modules})
+ if (NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION} OR NOT ${_prefix}_FOUND OR
+ (NOT "${ARGN}" STREQUAL "" AND NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0};${ARGN}") OR
+ ( "${ARGN}" STREQUAL "" AND NOT "${__pkg_config_arguments_${_prefix}}" STREQUAL "${_module0}"))
+ _pkg_check_modules_internal("${_pkg_is_required}" "${_pkg_is_silent}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global} "${_prefix}" ${_pkg_modules})
_pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION})
if (${_prefix}_FOUND)
_pkgconfig_set(__pkg_config_arguments_${_prefix} "${_module0};${ARGN}")
endif()
- elseif (${_prefix}_FOUND AND ${_imp_target})
- _pkg_create_imp_target("${_prefix}" _no_cmake_path _no_cmake_environment_path)
+ else()
+ if (${_prefix}_FOUND)
+ _pkg_recalculate("${_prefix}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global})
+ endif()
endif()
endmacro()
@@ -600,22 +651,27 @@ 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. ::
+ The behavior of this command is the same as :command:`pkg_check_modules`,
+ except that rather than checking for all the specified modules, it searches
+ for just the first successful match.
- pkg_search_module(<PREFIX> [REQUIRED] [QUIET]
- [NO_CMAKE_PATH] [NO_CMAKE_ENVIRONMENT_PATH]
- [IMPORTED_TARGET]
- <MODULE> [<MODULE>]*)
+ .. code-block:: cmake
- Examples
+ pkg_search_module(<prefix>
+ [REQUIRED] [QUIET]
+ [NO_CMAKE_PATH]
+ [NO_CMAKE_ENVIRONMENT_PATH]
+ [IMPORTED_TARGET [GLOBAL]]
+ <moduleSpec> [<moduleSpec>...])
- .. code-block:: cmake
+ Example:
- pkg_search_module (BAR libxml-2.0 libxml2 libxml>=2)
+ .. code-block:: cmake
+
+ pkg_search_module (BAR libxml-2.0 libxml2 libxml>=2)
#]========================================]
macro(pkg_search_module _prefix _module0)
- _pkgconfig_parse_options(_pkg_modules_alt _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path _imp_target "${_module0}" ${ARGN})
+ _pkgconfig_parse_options(_pkg_modules_alt _pkg_is_required _pkg_is_silent _no_cmake_path _no_cmake_environment_path _imp_target _imp_target_global "${_module0}" ${ARGN})
# 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)
@@ -627,7 +683,7 @@ macro(pkg_search_module _prefix _module0)
# 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} ${_imp_target} "${_prefix}" "${_pkg_alt}")
+ _pkg_check_modules_internal(0 1 ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global} "${_prefix}" "${_pkg_alt}")
endif()
if (${_prefix}_FOUND)
@@ -642,28 +698,61 @@ macro(pkg_search_module _prefix _module0)
endif()
_pkgconfig_set(__pkg_config_checked_${_prefix} ${PKG_CONFIG_VERSION})
- elseif (${_prefix}_FOUND AND ${_imp_target})
- _pkg_create_imp_target("${_prefix}" _no_cmake_path _no_cmake_environment_path)
+ elseif (${_prefix}_FOUND)
+ _pkg_recalculate("${_prefix}" ${_no_cmake_path} ${_no_cmake_environment_path} ${_imp_target} ${_imp_target_global})
endif()
endmacro()
+#[========================================[.rst:
+.. command:: pkg_get_variable
+
+ Retrieves the value of a pkg-config variable ``varName`` and stores it in the
+ result variable ``resultVar`` in the calling scope.
+
+ .. code-block:: cmake
+
+ pkg_get_variable(<resultVar> <moduleName> <varName>)
+
+ If ``pkg-config`` returns multiple values for the specified variable,
+ ``resultVar`` will contain a :ref:`;-list <CMake Language Lists>`.
+
+ For example:
+
+ .. code-block:: cmake
+
+ pkg_get_variable(GI_GIRDIR gobject-introspection-1.0 girdir)
+#]========================================]
+function (pkg_get_variable result pkg variable)
+ _pkg_set_path_internal()
+ _pkgconfig_invoke("${pkg}" "prefix" "result" "" "--variable=${variable}")
+ set("${result}"
+ "${prefix_result}"
+ PARENT_SCOPE)
+ _pkg_restore_path_internal()
+endfunction ()
+
#[========================================[.rst:
-.. variable:: PKG_CONFIG_EXECUTABLE
+Variables Affecting Behavior
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Path to the pkg-config executable.
+.. variable:: PKG_CONFIG_EXECUTABLE
+ This can be set to the path of the pkg-config executable. If not provided,
+ it will be set by the module as a result of calling :command:`find_program`
+ internally. The ``PKG_CONFIG`` environment variable can be used as a hint.
.. 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.
+ Specifies whether :command:`pkg_check_modules` and
+ :command:`pkg_search_module` should add the paths in the
+ :variable:`CMAKE_PREFIX_PATH`, :variable:`CMAKE_FRAMEWORK_PATH` and
+ :variable:`CMAKE_APPBUNDLE_PATH` cache and environment variables to the
+ ``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.
+ 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.
#]========================================]
diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake
index 9e2194ce4..dfdd2111d 100644
--- a/Modules/FindPostgreSQL.cmake
+++ b/Modules/FindPostgreSQL.cmake
@@ -1,20 +1,34 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindPostgreSQL
-# --------------
-#
-# Find the PostgreSQL installation.
-#
-# This module defines
-#
-# ::
-#
-# PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking
-# PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers
-# PostgreSQL_LIBRARY_DIRS - the link directories for PostgreSQL libraries
-# PostgreSQL_VERSION_STRING - the version of PostgreSQL found (since CMake 2.8.8)
+#[=======================================================================[.rst:
+FindPostgreSQL
+--------------
+
+Find the PostgreSQL installation.
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``PostgreSQL::PostgreSQL``
+if PostgreSQL has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``PostgreSQL_FOUND``
+ True if PostgreSQL is found.
+``PostgreSQL_LIBRARIES``
+ the PostgreSQL libraries needed for linking
+``PostgreSQL_INCLUDE_DIRS``
+ the directories of the PostgreSQL headers
+``PostgreSQL_LIBRARY_DIRS``
+ the link directories for PostgreSQL libraries
+``PostgreSQL_VERSION_STRING``
+ the version of PostgreSQL found
+#]=======================================================================]
# ----------------------------------------------------------------------------
# History:
@@ -23,11 +37,11 @@
# ----------------------------------------------------------------------------
# Note:
# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
-# version mumber of the implementation of PostgreSQL.
+# version number 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.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
+# "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "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")
@@ -48,6 +62,8 @@
# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries
# PostgreSQL_LIBRARIES - The PostgreSQL libraries.
#
+# The ``PostgreSQL::PostgreSQL`` imported target is also created.
+#
# ----------------------------------------------------------------------------
# If you have installed PostgreSQL in a non-standard location.
# (Please note that in the following comments, it is assumed that <Your Path>
@@ -71,7 +87,7 @@ set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to wher
set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS}
- "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0")
+ "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0")
# Define additional search paths for root directories.
set( PostgreSQL_ROOT_DIRECTORIES
@@ -139,17 +155,38 @@ if ( WIN32 )
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
- ${PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES}
- # Help the user find it if we cannot.
- DOC "The ${PostgreSQL_LIBRARY_DIR_MESSAGE}"
-)
-get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH)
+function(__postgresql_find_library _name)
+ find_library(${_name}
+ NAMES ${ARGN}
+ PATHS
+ ${PostgreSQL_ROOT_DIRECTORIES}
+ PATH_SUFFIXES
+ lib
+ ${PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES}
+ # Help the user find it if we cannot.
+ DOC "The ${PostgreSQL_LIBRARY_DIR_MESSAGE}"
+ )
+endfunction()
+
+# For compatibility with versions prior to this multi-config search, honor
+# any PostgreSQL_LIBRARY that is already specified and skip the search.
+if(PostgreSQL_LIBRARY)
+ set(PostgreSQL_LIBRARIES "${PostgreSQL_LIBRARY}")
+ get_filename_component(PostgreSQL_LIBRARY_DIR "${PostgreSQL_LIBRARY}" PATH)
+else()
+ __postgresql_find_library(PostgreSQL_LIBRARY_RELEASE ${PostgreSQL_LIBRARY_TO_FIND})
+ __postgresql_find_library(PostgreSQL_LIBRARY_DEBUG ${PostgreSQL_LIBRARY_TO_FIND}d)
+ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
+ select_library_configurations(PostgreSQL)
+ mark_as_advanced(PostgreSQL_LIBRARY_RELEASE PostgreSQL_LIBRARY_DEBUG)
+ if(PostgreSQL_LIBRARY_RELEASE)
+ get_filename_component(PostgreSQL_LIBRARY_DIR "${PostgreSQL_LIBRARY_RELEASE}" PATH)
+ elseif(PostgreSQL_LIBRARY_DEBUG)
+ get_filename_component(PostgreSQL_LIBRARY_DIR "${PostgreSQL_LIBRARY_DEBUG}" PATH)
+ else()
+ set(PostgreSQL_LIBRARY_DIR "")
+ endif()
+endif()
if (PostgreSQL_INCLUDE_DIR)
# Some platforms include multiple pg_config.hs for multi-lib configurations
@@ -159,14 +196,45 @@ if (PostgreSQL_INCLUDE_DIR)
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 ]+\".*\"")
+ REGEX "^#define[\t ]+PG_VERSION_NUM[\t ]+.*")
if(pgsql_version_str)
- string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*"
- "\\1" PostgreSQL_VERSION_STRING "${pgsql_version_str}")
+ string(REGEX REPLACE "^#define[\t ]+PG_VERSION_NUM[\t ]+([0-9]*).*"
+ "\\1" _PostgreSQL_VERSION_NUM "${pgsql_version_str}")
break()
endif()
endif()
endforeach()
+ if (_PostgreSQL_VERSION_NUM)
+ # 9.x and older encoding
+ if (_PostgreSQL_VERSION_NUM LESS 100000)
+ math(EXPR _PostgreSQL_major_version "${_PostgreSQL_VERSION_NUM} / 10000")
+ math(EXPR _PostgreSQL_minor_version "${_PostgreSQL_VERSION_NUM} % 10000 / 100")
+ math(EXPR _PostgreSQL_patch_version "${_PostgreSQL_VERSION_NUM} % 100")
+ set(PostgreSQL_VERSION_STRING "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}.${_PostgreSQL_patch_version}")
+ unset(_PostgreSQL_major_version)
+ unset(_PostgreSQL_minor_version)
+ unset(_PostgreSQL_patch_version)
+ else ()
+ math(EXPR _PostgreSQL_major_version "${_PostgreSQL_VERSION_NUM} / 10000")
+ math(EXPR _PostgreSQL_minor_version "${_PostgreSQL_VERSION_NUM} % 10000")
+ set(PostgreSQL_VERSION_STRING "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}")
+ unset(_PostgreSQL_major_version)
+ unset(_PostgreSQL_minor_version)
+ endif ()
+ else ()
+ 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()
+ endif ()
+ unset(_PostgreSQL_VERSION_NUM)
unset(pgsql_version_str)
endif()
@@ -177,11 +245,36 @@ find_package_handle_standard_args(PostgreSQL
VERSION_VAR PostgreSQL_VERSION_STRING)
set(PostgreSQL_FOUND ${POSTGRESQL_FOUND})
+function(__postgresql_import_library _target _var _config)
+ if(_config)
+ set(_config_suffix "_${_config}")
+ else()
+ set(_config_suffix "")
+ endif()
+
+ set(_lib "${${_var}${_config_suffix}}")
+ if(EXISTS "${_lib}")
+ if(_config)
+ set_property(TARGET ${_target} APPEND PROPERTY
+ IMPORTED_CONFIGURATIONS ${_config})
+ endif()
+ set_target_properties(${_target} PROPERTIES
+ IMPORTED_LOCATION${_config_suffix} "${_lib}")
+ endif()
+endfunction()
+
# Now try to get the include and library path.
if(PostgreSQL_FOUND)
+ if (NOT TARGET PostgreSQL::PostgreSQL)
+ add_library(PostgreSQL::PostgreSQL UNKNOWN IMPORTED)
+ set_target_properties(PostgreSQL::PostgreSQL PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIR};${PostgreSQL_TYPE_INCLUDE_DIR}")
+ __postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "")
+ __postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "RELEASE")
+ __postgresql_import_library(PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "DEBUG")
+ endif ()
set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
- set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY})
endif()
-mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR PostgreSQL_LIBRARY )
+mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR)
diff --git a/Modules/FindProducer.cmake b/Modules/FindProducer.cmake
index 500c8edf6..65495b5ba 100644
--- a/Modules/FindProducer.cmake
+++ b/Modules/FindProducer.cmake
@@ -1,35 +1,36 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <Producer/CameraGroup>
@@ -44,12 +45,9 @@ find_path(PRODUCER_INCLUDE_DIR Producer/CameraGroup
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
+ /opt
+ [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OpenThreads_ROOT]
+ [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]
)
find_library(PRODUCER_LIBRARY
@@ -60,9 +58,6 @@ find_library(PRODUCER_LIBRARY
ENV OSGDIR
PATH_SUFFIXES lib
PATHS
- /sw
- /opt/local
- /opt/csw
/opt
)
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 33262f3d6..76bc873fd 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -1,187 +1,295 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 and vsprojects/Release
-# or vsprojects/x64/Debug and vsprojects/x64/Release)
-# will be searched for libraries and binaries.
-# ``Protobuf_IMPORT_DIRS``
-# List of additional directories to be searched for
-# imported .proto files.
-# ``Protobuf_DEBUG``
-# Show debug messages.
-# ``Protobuf_USE_STATIC_LIBS``
-# Set to ON to force the use of the static libraries.
-# Default is OFF.
-#
-# Defines the following variables:
-#
-# ``Protobuf_FOUND``
-# Found the Google Protocol Buffers library
-# (libprotobuf & header files)
-# ``Protobuf_VERSION``
-# Version of package found.
-# ``Protobuf_INCLUDE_DIRS``
-# Include directories for Google Protocol Buffers
-# ``Protobuf_LIBRARIES``
-# The protobuf libraries
-# ``Protobuf_PROTOC_LIBRARIES``
-# The protoc libraries
-# ``Protobuf_LITE_LIBRARIES``
-# The protobuf-lite libraries
-#
-# The following :prop_tgt:`IMPORTED` targets are also defined:
-#
-# ``protobuf::libprotobuf``
-# The protobuf library.
-# ``protobuf::libprotobuf-lite``
-# The protobuf lite library.
-# ``protobuf::libprotoc``
-# The protoc library.
-#
-# 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
-# ``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:
-#
-# .. code-block:: cmake
-#
-# find_package(Protobuf REQUIRED)
-# include_directories(${Protobuf_INCLUDE_DIRS})
-# include_directories(${CMAKE_CURRENT_BINARY_DIR})
-# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto)
-# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto)
-# protobuf_generate_python(PROTO_PY foo.proto)
-# add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
-# target_link_libraries(bar ${Protobuf_LIBRARIES})
-#
-# .. note::
-# The ``protobuf_generate_cpp`` and ``protobuf_generate_python``
-# functions and :command:`add_executable` or :command:`add_library`
-# calls only work properly within the same directory.
-#
-# .. command:: protobuf_generate_cpp
-#
-# Add custom commands to process ``.proto`` files to C++::
-#
-# protobuf_generate_cpp (<SRCS> <HDRS> [EXPORT_MACRO <MACRO>] [<ARGN>...])
-#
-# ``SRCS``
-# Variable to define with autogenerated source files
-# ``HDRS``
-# Variable to define with autogenerated header files
-# ``EXPORT_MACRO``
-# is a macro which should expand to ``__declspec(dllexport)`` or
-# ``__declspec(dllimport)`` depending on what is being compiled.
-# ``ARGN``
-# ``.proto`` files
-#
-# .. command:: protobuf_generate_python
-#
-# Add custom commands to process ``.proto`` files to Python::
-#
-# protobuf_generate_python (<PY> [<ARGN>...])
-#
-# ``PY``
-# Variable to define with autogenerated Python files
-# ``ARGN``
-# ``.proto`` filess
+#[=======================================================================[.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 and vsprojects/Release
+ or vsprojects/x64/Debug and vsprojects/x64/Release)
+ will be searched for libraries and binaries.
+``Protobuf_IMPORT_DIRS``
+ List of additional directories to be searched for
+ imported .proto files.
+``Protobuf_DEBUG``
+ Show debug messages.
+``Protobuf_USE_STATIC_LIBS``
+ Set to ON to force the use of the static libraries.
+ Default is OFF.
+
+Defines the following variables:
+
+``Protobuf_FOUND``
+ Found the Google Protocol Buffers library
+ (libprotobuf & header files)
+``Protobuf_VERSION``
+ Version of package found.
+``Protobuf_INCLUDE_DIRS``
+ Include directories for Google Protocol Buffers
+``Protobuf_LIBRARIES``
+ The protobuf libraries
+``Protobuf_PROTOC_LIBRARIES``
+ The protoc libraries
+``Protobuf_LITE_LIBRARIES``
+ The protobuf-lite libraries
+
+The following :prop_tgt:`IMPORTED` targets are also defined:
+
+``protobuf::libprotobuf``
+ The protobuf library.
+``protobuf::libprotobuf-lite``
+ The protobuf lite library.
+``protobuf::libprotoc``
+ The protoc library.
+``protobuf::protoc``
+ The protoc compiler.
+
+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
+``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:
+
+.. code-block:: cmake
+
+ find_package(Protobuf REQUIRED)
+ include_directories(${Protobuf_INCLUDE_DIRS})
+ include_directories(${CMAKE_CURRENT_BINARY_DIR})
+ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto)
+ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto)
+ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS DESCRIPTORS PROTO_DESCS foo.proto)
+ protobuf_generate_python(PROTO_PY foo.proto)
+ add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
+ target_link_libraries(bar ${Protobuf_LIBRARIES})
+
+.. note::
+ The ``protobuf_generate_cpp`` and ``protobuf_generate_python``
+ functions and :command:`add_executable` or :command:`add_library`
+ calls only work properly within the same directory.
+
+.. command:: protobuf_generate_cpp
+
+ Add custom commands to process ``.proto`` files to C++::
+
+ protobuf_generate_cpp (<SRCS> <HDRS>
+ [DESCRIPTORS <DESC>] [EXPORT_MACRO <MACRO>] [<ARGN>...])
+
+ ``SRCS``
+ Variable to define with autogenerated source files
+ ``HDRS``
+ Variable to define with autogenerated header files
+ ``DESCRIPTORS``
+ Variable to define with autogenerated descriptor files, if requested.
+ ``EXPORT_MACRO``
+ is a macro which should expand to ``__declspec(dllexport)`` or
+ ``__declspec(dllimport)`` depending on what is being compiled.
+ ``ARGN``
+ ``.proto`` files
+
+.. command:: protobuf_generate_python
+
+ Add custom commands to process ``.proto`` files to Python::
+
+ protobuf_generate_python (<PY> [<ARGN>...])
+
+ ``PY``
+ Variable to define with autogenerated Python files
+ ``ARGN``
+ ``.proto`` filess
+#]=======================================================================]
+
+function(protobuf_generate)
+ set(_options APPEND_PATH DESCRIPTORS)
+ set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO PROTOC_OUT_DIR)
+ if(COMMAND target_sources)
+ list(APPEND _singleargs TARGET)
+ endif()
+ set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS)
-function(PROTOBUF_GENERATE_CPP SRCS HDRS)
- cmake_parse_arguments(protobuf "" "EXPORT_MACRO" "" ${ARGN})
+ cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}")
- set(PROTO_FILES "${protobuf_UNPARSED_ARGUMENTS}")
- if(NOT PROTO_FILES)
- message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
+ if(NOT protobuf_generate_PROTOS AND NOT protobuf_generate_TARGET)
+ message(SEND_ERROR "Error: protobuf_generate called without any targets or source files")
return()
endif()
- if(protobuf_EXPORT_MACRO)
- set(DLL_EXPORT_DECL "dllexport_decl=${protobuf_EXPORT_MACRO}:")
+ if(NOT protobuf_generate_OUT_VAR AND NOT protobuf_generate_TARGET)
+ message(SEND_ERROR "Error: protobuf_generate called without a target or output variable")
+ return()
endif()
- if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ if(NOT protobuf_generate_LANGUAGE)
+ set(protobuf_generate_LANGUAGE cpp)
+ endif()
+ string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE)
+
+ if(NOT protobuf_generate_PROTOC_OUT_DIR)
+ set(protobuf_generate_PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
+ endif()
+
+ if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp)
+ set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:")
+ endif()
+
+ if(NOT protobuf_generate_GENERATE_EXTENSIONS)
+ if(protobuf_generate_LANGUAGE STREQUAL cpp)
+ set(protobuf_generate_GENERATE_EXTENSIONS .pb.h .pb.cc)
+ elseif(protobuf_generate_LANGUAGE STREQUAL python)
+ set(protobuf_generate_GENERATE_EXTENSIONS _pb2.py)
+ else()
+ message(SEND_ERROR "Error: protobuf_generate given unknown Language ${LANGUAGE}, please provide a value for GENERATE_EXTENSIONS")
+ return()
+ endif()
+ endif()
+
+ if(protobuf_generate_TARGET)
+ get_target_property(_source_list ${protobuf_generate_TARGET} SOURCES)
+ foreach(_file ${_source_list})
+ if(_file MATCHES "proto$")
+ list(APPEND protobuf_generate_PROTOS ${_file})
+ endif()
+ endforeach()
+ endif()
+
+ if(NOT protobuf_generate_PROTOS)
+ message(SEND_ERROR "Error: protobuf_generate could not find any .proto files")
+ return()
+ endif()
+
+ if(protobuf_generate_APPEND_PATH)
# Create an include path for each file specified
- foreach(FIL ${PROTO_FILES})
- get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
- get_filename_component(ABS_PATH ${ABS_FIL} PATH)
- list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ foreach(_file ${protobuf_generate_PROTOS})
+ get_filename_component(_abs_file ${_file} ABSOLUTE)
+ get_filename_component(_abs_path ${_abs_file} PATH)
+ list(FIND _protobuf_include_path ${_abs_path} _contains_already)
if(${_contains_already} EQUAL -1)
- list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ list(APPEND _protobuf_include_path -I ${_abs_path})
endif()
endforeach()
else()
set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
endif()
+ foreach(DIR ${protobuf_generate_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()
+
+ set(_generated_srcs_all)
+ foreach(_proto ${protobuf_generate_PROTOS})
+ get_filename_component(_abs_file ${_proto} ABSOLUTE)
+ get_filename_component(_abs_dir ${_abs_file} DIRECTORY)
+ get_filename_component(_basename ${_proto} NAME_WE)
+ file(RELATIVE_PATH _rel_dir ${CMAKE_CURRENT_SOURCE_DIR} ${_abs_dir})
+
+ set(_possible_rel_dir)
+ if (NOT protobuf_generate_APPEND_PATH)
+ set(_possible_rel_dir ${_rel_dir}/)
+ endif()
+
+ set(_generated_srcs)
+ foreach(_ext ${protobuf_generate_GENERATE_EXTENSIONS})
+ list(APPEND _generated_srcs "${protobuf_generate_PROTOC_OUT_DIR}/${_possible_rel_dir}${_basename}${_ext}")
+ endforeach()
+
+ if(protobuf_generate_DESCRIPTORS AND protobuf_generate_LANGUAGE STREQUAL cpp)
+ set(_descriptor_file "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.desc")
+ set(_dll_desc_out "--descriptor_set_out=${_descriptor_file}")
+ list(APPEND _generated_srcs ${_descriptor_file})
+ endif()
+ list(APPEND _generated_srcs_all ${_generated_srcs})
+
+ add_custom_command(
+ OUTPUT ${_generated_srcs}
+ COMMAND protobuf::protoc
+ ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_dll_desc_out} ${_protobuf_include_path} ${_abs_file}
+ DEPENDS ${_abs_file} protobuf::protoc
+ COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${_generated_srcs_all} PROPERTIES GENERATED TRUE)
+ if(protobuf_generate_OUT_VAR)
+ set(${protobuf_generate_OUT_VAR} ${_generated_srcs_all} PARENT_SCOPE)
+ endif()
+ if(protobuf_generate_TARGET)
+ target_sources(${protobuf_generate_TARGET} PRIVATE ${_generated_srcs_all})
+ endif()
+endfunction()
+
+function(PROTOBUF_GENERATE_CPP SRCS HDRS)
+ cmake_parse_arguments(protobuf_generate_cpp "" "EXPORT_MACRO;DESCRIPTORS" "" ${ARGN})
+
+ set(_proto_files "${protobuf_generate_cpp_UNPARSED_ARGUMENTS}")
+ if(NOT _proto_files)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ set(_append_arg APPEND_PATH)
+ endif()
+
+ if(protobuf_generate_cpp_DESCRIPTORS)
+ set(_descriptors DESCRIPTORS)
+ endif()
+
if(DEFINED PROTOBUF_IMPORT_DIRS AND NOT DEFINED Protobuf_IMPORT_DIRS)
set(Protobuf_IMPORT_DIRS "${PROTOBUF_IMPORT_DIRS}")
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()
+ set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS})
endif()
+ set(_outvar)
+ protobuf_generate(${_append_arg} ${_descriptors} LANGUAGE cpp EXPORT_MACRO ${protobuf_generate_cpp_EXPORT_MACRO} OUT_VAR _outvar ${_import_arg} PROTOS ${_proto_files})
+
set(${SRCS})
set(${HDRS})
- foreach(FIL ${PROTO_FILES})
- get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
- get_filename_component(FIL_WE ${FIL} NAME_WE)
- if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH)
- get_filename_component(FIL_DIR ${FIL} DIRECTORY)
- if(FIL_DIR)
- set(FIL_WE "${FIL_DIR}/${FIL_WE}")
- endif()
- endif()
-
- list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
- list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
+ if(protobuf_generate_cpp_DESCRIPTORS)
+ set(${protobuf_generate_cpp_DESCRIPTORS})
+ endif()
- 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=${DLL_EXPORT_DECL}${CMAKE_CURRENT_BINARY_DIR}" ${_protobuf_include_path} ${ABS_FIL}
- DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
- COMMENT "Running C++ protocol buffer compiler on ${FIL}"
- VERBATIM )
+ foreach(_file ${_outvar})
+ if(_file MATCHES "cc$")
+ list(APPEND ${SRCS} ${_file})
+ elseif(_file MATCHES "desc$")
+ list(APPEND ${protobuf_generate_cpp_DESCRIPTORS} ${_file})
+ else()
+ list(APPEND ${HDRS} ${_file})
+ endif()
endforeach()
-
- set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+ if(protobuf_generate_cpp_DESCRIPTORS)
+ set(${protobuf_generate_cpp_DESCRIPTORS} "${${protobuf_generate_cpp_DESCRIPTORS}}" PARENT_SCOPE)
+ endif()
endfunction()
function(PROTOBUF_GENERATE_PYTHON SRCS)
@@ -191,17 +299,7 @@ function(PROTOBUF_GENERATE_PYTHON SRCS)
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})
+ set(_append_arg APPEND_PATH)
endif()
if(DEFINED PROTOBUF_IMPORT_DIRS AND NOT DEFINED Protobuf_IMPORT_DIRS)
@@ -209,36 +307,12 @@ function(PROTOBUF_GENERATE_PYTHON SRCS)
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()
+ set(_import_arg IMPORT_DIRS ${Protobuf_IMPORT_DIRS})
endif()
- set(${SRCS})
- foreach(FIL ${ARGN})
- get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
- get_filename_component(FIL_WE ${FIL} NAME_WE)
- if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH)
- get_filename_component(FIL_DIR ${FIL} DIRECTORY)
- if(FIL_DIR)
- set(FIL_WE "${FIL_DIR}/${FIL_WE}")
- endif()
- endif()
-
- list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py")
- add_custom_command(
- OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py"
- COMMAND ${Protobuf_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
- DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
- COMMENT "Running Python protocol buffer compiler on ${FIL}"
- VERBATIM )
- endforeach()
-
- set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(_outvar)
+ protobuf_generate(${_append_arg} LANGUAGE python OUT_VAR _outvar ${_import_arg} PROTOS ${ARGN})
+ set(${SRCS} ${_outvar} PARENT_SCOPE)
endfunction()
@@ -311,21 +385,16 @@ function(_protobuf_find_libraries name filename)
mark_as_advanced(${name}_LIBRARY_DEBUG)
select_library_configurations(${name})
+
+ if(UNIX AND Threads_FOUND)
+ list(APPEND ${name}_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
+ endif()
+
set(${name}_LIBRARY "${${name}_LIBRARY}" PARENT_SCOPE)
set(${name}_LIBRARIES "${${name}_LIBRARIES}" 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.
#
@@ -346,6 +415,11 @@ if(MSVC)
find_path(Protobuf_SRC_ROOT_FOLDER protobuf.pc.in)
endif()
+if(UNIX)
+ # Protobuf headers may depend on threading.
+ find_package(Threads QUIET)
+endif()
+
# The Protobuf library
_protobuf_find_libraries(Protobuf protobuf)
#DOC "The Google Protocol Buffers RELEASE Library"
@@ -360,10 +434,6 @@ 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
@@ -451,6 +521,10 @@ if(Protobuf_INCLUDE_DIR)
set_target_properties(protobuf::libprotobuf PROPERTIES
IMPORTED_LOCATION_DEBUG "${Protobuf_LIBRARY_DEBUG}")
endif()
+ if(UNIX AND TARGET Threads::Threads)
+ set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES Threads::Threads)
+ endif()
endif()
endif()
@@ -475,6 +549,10 @@ if(Protobuf_INCLUDE_DIR)
set_target_properties(protobuf::libprotobuf-lite PROPERTIES
IMPORTED_LOCATION_DEBUG "${Protobuf_LITE_LIBRARY_DEBUG}")
endif()
+ if(UNIX AND TARGET Threads::Threads)
+ set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES Threads::Threads)
+ endif()
endif()
endif()
@@ -499,6 +577,20 @@ if(Protobuf_INCLUDE_DIR)
set_target_properties(protobuf::libprotoc PROPERTIES
IMPORTED_LOCATION_DEBUG "${Protobuf_PROTOC_LIBRARY_DEBUG}")
endif()
+ if(UNIX AND TARGET Threads::Threads)
+ set_property(TARGET protobuf::libprotoc APPEND PROPERTY
+ INTERFACE_LINK_LIBRARIES Threads::Threads)
+ endif()
+ endif()
+ endif()
+
+ if(Protobuf_PROTOC_EXECUTABLE)
+ if(NOT TARGET protobuf::protoc)
+ add_executable(protobuf::protoc IMPORTED)
+ if(EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
+ set_target_properties(protobuf::protoc PROPERTIES
+ IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}")
+ endif()
endif()
endif()
endif()
diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake
index 64b98a879..da33301af 100644
--- a/Modules/FindPythonInterp.cmake
+++ b/Modules/FindPythonInterp.cmake
@@ -1,46 +1,51 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 calling both ``find_package(PythonInterp)`` and
-# ``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to
-# get the currently active Python version by default with a consistent version
-# of PYTHON_LIBRARIES.
+#[=======================================================================[.rst:
+FindPythonInterp
+----------------
+
+.. deprecated:: 3.12
+
+ Use :module:`FindPython3`, :module:`FindPython2` or :module:`FindPython` instead.
+
+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 calling both ``find_package(PythonInterp)`` and
+``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to
+get the currently active Python version by default with a consistent version
+of PYTHON_LIBRARIES.
+#]=======================================================================]
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.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
+set(_PYTHON3_VERSIONS 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
if(PythonInterp_FIND_VERSION)
if(PythonInterp_FIND_VERSION_COUNT GREATER 1)
@@ -100,6 +105,9 @@ if(NOT PYTHON_EXECUTABLE)
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-32\\InstallPath]
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-64\\InstallPath]
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-32\\InstallPath]
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-64\\InstallPath]
)
endforeach()
endif()
@@ -122,7 +130,9 @@ if(PYTHON_EXECUTABLE)
endif()
else()
# sys.version predates sys.version_info, so use that
- execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)"
+ # sys.version was first documented for Python 1.5, so assume version 1.4
+ # if retrieving sys.version fails.
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "try: import sys; sys.stdout.write(sys.version)\nexcept: sys.stdout.write(\"1.4.0\")"
OUTPUT_VARIABLE _VERSION
RESULT_VARIABLE _PYTHON_VERSION_RESULT
ERROR_QUIET)
@@ -136,12 +146,10 @@ if(PYTHON_EXECUTABLE)
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_MINOR "4")
- set(PYTHON_VERSION_PATCH "0")
+ unset(PYTHON_VERSION_STRING)
+ unset(PYTHON_VERSION_MAJOR)
+ unset(PYTHON_VERSION_MINOR)
+ unset(PYTHON_VERSION_PATCH)
endif()
endif()
unset(_PYTHON_VERSION_RESULT)
diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake
index 63ec9a84e..1d62ac43e 100644
--- a/Modules/FindPythonLibs.cmake
+++ b/Modules/FindPythonLibs.cmake
@@ -1,44 +1,49 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 calling both ``find_package(PythonInterp)`` and
-# ``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to
-# get the currently active Python version by default with a consistent version
-# of PYTHON_LIBRARIES.
+#[=======================================================================[.rst:
+FindPythonLibs
+--------------
+
+.. deprecated:: 3.12
+
+ Use :module:`FindPython3`, :module:`FindPython2` or :module:`FindPython` instead.
+
+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 calling both ``find_package(PythonInterp)`` and
+``find_package(PythonLibs)``, call ``find_package(PythonInterp)`` first to
+get the currently active Python version by default with a consistent version
+of PYTHON_LIBRARIES.
+#]=======================================================================]
# Use the executable's path as a hint
set(_Python_LIBRARY_PATH_HINT)
@@ -74,7 +79,7 @@ set(CMAKE_FIND_FRAMEWORK LAST)
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.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
+set(_PYTHON3_VERSIONS 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0)
if(PythonLibs_FIND_VERSION)
if(PythonLibs_FIND_VERSION_COUNT GREATER 1)
@@ -117,17 +122,54 @@ unset(_PYTHON1_VERSIONS)
unset(_PYTHON2_VERSIONS)
unset(_PYTHON3_VERSIONS)
+# Python distribution: define which architectures can be used
+if (CMAKE_SIZEOF_VOID_P)
+ # In this case, search only for 64bit or 32bit
+ math (EXPR _PYTHON_ARCH "${CMAKE_SIZEOF_VOID_P} * 8")
+ set (_PYTHON_ARCH2 _PYTHON_PREFIX_ARCH})
+else()
+ if (PYTHON_EXECUTABLE)
+ # determine interpreter architecture
+ execute_process (COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; print(sys.maxsize > 2**32)"
+ RESULT_VARIABLE _PYTHON_RESULT
+ OUTPUT_VARIABLE _PYTHON_IS64BIT
+ ERROR_VARIABLE _PYTHON_IS64BIT)
+ if (NOT _PYTHON_RESULT)
+ if (_PYTHON_IS64BIT)
+ set (_PYTHON_ARCH 64)
+ set (_PYTHON_ARCH2 64)
+ else()
+ set (_PYTHON_ARCH 32)
+ set (_PYTHON_ARCH2 32)
+ endif()
+ endif()
+ else()
+ # architecture unknown, search for both 64bit and 32bit
+ set (_PYTHON_ARCH 64)
+ set (_PYTHON_ARCH2 32)
+ endif()
+endif()
+
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
+ NAMES_PER_DIR
HINTS ${_Python_LIBRARY_PATH_HINT}
PATHS
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs/Debug
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs/Debug
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs/Debug
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs/Debug
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs
)
endif()
@@ -145,20 +187,22 @@ foreach(_CURRENT_VERSION ${_Python_VERSIONS})
python${_CURRENT_VERSION}m
python${_CURRENT_VERSION}u
python${_CURRENT_VERSION}
+ NAMES_PER_DIR
HINTS
${_Python_LIBRARY_PATH_HINT}
PATHS
${PYTHON_FRAMEWORK_LIBRARIES}
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\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
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/libs
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/libs
)
# 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
+ NAMES_PER_DIR
# This is where the static library is usually located
PATH_SUFFIXES python${_CURRENT_VERSION}/config
)
@@ -198,7 +242,11 @@ foreach(_CURRENT_VERSION ${_Python_VERSIONS})
PATHS
${PYTHON_FRAMEWORK_INCLUDES}
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/include
+ [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/include
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH}\\InstallPath]/include
+ [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}-${_PYTHON_ARCH2}\\InstallPath]/include
PATH_SUFFIXES
python${_CURRENT_VERSION}mu
python${_CURRENT_VERSION}m
diff --git a/Modules/FindQt.cmake b/Modules/FindQt.cmake
index 4d8aea92e..d6a06628e 100644
--- a/Modules/FindQt.cmake
+++ b/Modules/FindQt.cmake
@@ -1,37 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-#
-# This module can only detect and switch between Qt versions 3 and 4. It
-# cannot handle Qt5 or any later versions.
-#
-# ::
-#
-# 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.
+#[=======================================================================[.rst:
+FindQt
+------
+
+Searches for all installed versions of Qt3 or Qt4.
+
+This module cannot handle Qt5 or any later versions.
+For those, see :manual:`cmake-qt(7)`.
+
+This module exists for the :command:`find_package` command only if
+policy :policy:`CMP0084` is not set to ``NEW``.
+
+This module 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.
+#]=======================================================================]
+
+if(_findqt_testing)
+ set(_findqt_included TRUE)
+ return()
+endif()
# look for signs of qt3 installations
file(GLOB GLOB_TEMP_VAR /usr/lib*/qt-3*/bin/qmake /usr/lib*/qt3*/bin/qmake)
@@ -105,13 +114,11 @@ find_file( QT4_QGLOBAL_H_FILE qglobal.h
"[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 )
+ C:/Progra~1/qt/include/Qt
+ PATH_SUFFIXES qt/include/Qt include/Qt)
if(QT4_QGLOBAL_H_FILE)
set(QT4_INSTALLED TRUE)
@@ -125,14 +132,10 @@ find_file( QT3_QGLOBAL_H_FILE qglobal.h
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 )
+ PATH_SUFFIXES qt/include include/qt3)
if(QT3_QGLOBAL_H_FILE)
set(QT3_INSTALLED TRUE)
diff --git a/Modules/FindQt3.cmake b/Modules/FindQt3.cmake
index fa9f3a15c..563ed46ec 100644
--- a/Modules/FindQt3.cmake
+++ b/Modules/FindQt3.cmake
@@ -1,37 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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
@@ -61,14 +62,10 @@ find_path(QT_INCLUDE_DIR qt.h
"[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
+ PATH_SUFFIXES lib/qt/include lib/qt3/include include/qt include/qt3 qt/include qt3/include
)
# if qglobal.h is not in the qt_include_dir then set
@@ -101,13 +98,10 @@ if (QT_MT_REQUIRED)
"[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
+ lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
)
else ()
@@ -122,13 +116,10 @@ else ()
"[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
+ lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
)
endif ()
@@ -141,12 +132,10 @@ find_library(QT_QASSISTANTCLIENT_LIBRARY
"[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
+ lib lib/qt lib/qt3 qt qt3 qt/lib qt3/lib
)
# Qt 3 should prefer QTDIR over the PATH
@@ -159,15 +148,10 @@ find_program(QT_MOC_EXECUTABLE
"[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
+ bin lib/qt lib/qt3 qt qt3 qt/bin qt3/bin lib/qt/bin lib/qt3/bin
)
if(QT_MOC_EXECUTABLE)
@@ -184,14 +168,10 @@ find_program(QT_UIC_EXECUTABLE
"[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
+ bin lib/qt lib/qt3 qt qt3 qt/bin qt3/bin lib/qt/bin lib/qt3/bin
)
if(QT_UIC_EXECUTABLE)
diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake
index b0c49e564..a145b4649 100644
--- a/Modules/FindQt4.cmake
+++ b/Modules/FindQt4.cmake
@@ -1,304 +1,305 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 :prop_tgt:`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
-# 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::QtDeclarative``
-# The QtDeclarative 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.
+#[=======================================================================[.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 :prop_tgt:`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
+ 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::QtDeclarative``
+ The QtDeclarative 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.
+#]=======================================================================]
# Use find_package( Qt4 COMPONENTS ... ) to enable modules
if( Qt4_FIND_COMPONENTS )
@@ -355,19 +356,21 @@ macro (_QT4_ADJUST_LIB_VARS _camelCaseBasename)
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}" )
+ set(_location "${QT_${basename}_LIBRARY_RELEASE}")
+ if(QT_USE_FRAMEWORKS AND EXISTS ${_location}/${_camelCaseBasename})
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${_location}/${_camelCaseBasename}" )
else()
- set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${QT_${basename}_LIBRARY_RELEASE}" )
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_RELEASE "${_location}" )
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}" )
+ set(_location "${QT_${basename}_LIBRARY_DEBUG}")
+ if(QT_USE_FRAMEWORKS AND EXISTS ${_location}/${_camelCaseBasename})
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${_location}/${_camelCaseBasename}" )
else()
- set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${QT_${basename}_LIBRARY_DEBUG}" )
+ set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY IMPORTED_LOCATION_DEBUG "${_location}" )
endif()
endif ()
set_property(TARGET Qt4::${_camelCaseBasename} PROPERTY
@@ -396,13 +399,14 @@ macro (_QT4_ADJUST_LIB_VARS _camelCaseBasename)
# 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)
+ # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
+ # single-config generators, set optimized and debug libraries
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ if(_isMultiConfig 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
+ # For single-config generators where CMAKE_BUILD_TYPE has no value,
+ # 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})
@@ -544,15 +548,11 @@ if (QT_QMAKE_EXECUTABLE AND
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)
+ HINTS ${qt_mkspecs_dirs}
+ PATH_SUFFIXES mkspecs share/qt4/mkspecs
+ DOC "The location of the Qt mkspecs containing qconfig.pri")
endif()
if(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
@@ -706,14 +706,15 @@ if (QT_QMAKE_EXECUTABLE AND
# 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)
+ if(CMAKE_CROSSCOMPILING OR NOT qt_plugins_dir)
+ find_path(QT_PLUGINS_DIR
+ NAMES accessible bearer codecs designer graphicssystems iconengines imageformats inputmethods qmltooling script sqldrivers
+ HINTS ${qt_plugins_dir}
+ PATH_SUFFIXES plugins lib/qt4/plugins
+ DOC "The location of the Qt plugins")
+ else()
+ set(QT_PLUGINS_DIR ${qt_plugins_dir} CACHE PATH "The location of the Qt plugins")
+ endif()
endif ()
# ask qmake for the translations directory
@@ -725,18 +726,13 @@ if (QT_QMAKE_EXECUTABLE AND
# 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()
+ if(CMAKE_CROSSCOMPILING OR NOT qt_imports_dir)
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)
+ HINTS ${qt_imports_dir}
+ PATH_SUFFIXES imports lib/qt4/imports
+ DOC "The location of the Qt imports")
+ else()
+ set(QT_IMPORTS_DIR ${qt_imports_dir} CACHE PATH "The location of the Qt imports")
endif()
endif ()
diff --git a/Modules/FindQuickTime.cmake b/Modules/FindQuickTime.cmake
index 995d8826b..107486daa 100644
--- a/Modules/FindQuickTime.cmake
+++ b/Modules/FindQuickTime.cmake
@@ -1,20 +1,21 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
find_path(QUICKTIME_INCLUDE_DIR QuickTime/QuickTime.h QuickTime.h
HINTS
diff --git a/Modules/FindRTI.cmake b/Modules/FindRTI.cmake
index b2ef0761a..54d2bec9f 100644
--- a/Modules/FindRTI.cmake
+++ b/Modules/FindRTI.cmake
@@ -1,37 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>
+#[=======================================================================[.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>
+#]=======================================================================]
macro(RTI_MESSAGE_QUIETLY QUIET TYPE MSG)
if(NOT ${QUIET})
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake
index a9f8d3545..7e01fbc98 100644
--- a/Modules/FindRuby.cmake
+++ b/Modules/FindRuby.cmake
@@ -1,37 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
-#
-# Also:
-#
-# ``RUBY_INCLUDE_PATH``
-# same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
+#[=======================================================================[.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
+
+Also:
+
+``RUBY_INCLUDE_PATH``
+ same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
+#]=======================================================================]
# RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
# RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
@@ -48,17 +49,20 @@ 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(DEFINED Ruby_FIND_VERSION_MAJOR AND DEFINED 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})
+ 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")
+ set(Ruby_FIND_VERSION_SHORT_NODOT "18")
endif()
if(NOT Ruby_FIND_VERSION_EXACT)
+ list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.4 ruby24)
+ list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.3 ruby23)
+ list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby2.2 ruby22)
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)
@@ -90,115 +94,131 @@ if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR)
# 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
- )
+ _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()
+ # 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()
+ # check whether we found 2.2.x
+ if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?2")
+ set(RUBY_VERSION_MAJOR 2)
+ set(RUBY_VERSION_MINOR 2)
+ endif()
+ # check whether we found 2.3.x
+ if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?3")
+ set(RUBY_VERSION_MAJOR 2)
+ set(RUBY_VERSION_MINOR 3)
+ endif()
+ # check whether we found 2.4.x
+ if(${RUBY_EXECUTABLE} MATCHES "ruby2\\.?4")
+ set(RUBY_VERSION_MAJOR 2)
+ set(RUBY_VERSION_MINOR 4)
+ 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}")
+ 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/ )
+ 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} )
+ 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()
@@ -206,33 +226,33 @@ endif()
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( MSVC_VERSION EQUAL 1200 )
- set( _RUBY_MSVC_RUNTIME "60" )
- endif()
- if( MSVC_VERSION EQUAL 1300 )
- set( _RUBY_MSVC_RUNTIME "70" )
- endif()
- if( MSVC_VERSION EQUAL 1310 )
- set( _RUBY_MSVC_RUNTIME "71" )
- endif()
- if( MSVC_VERSION EQUAL 1400 )
- set( _RUBY_MSVC_RUNTIME "80" )
- endif()
- if( MSVC_VERSION EQUAL 1500 )
- set( _RUBY_MSVC_RUNTIME "90" )
- endif()
-
- set(_RUBY_ARCH_PREFIX "")
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(_RUBY_ARCH_PREFIX "x64-")
- endif()
-
- list(APPEND _RUBY_POSSIBLE_LIB_NAMES
- "${_RUBY_ARCH_PREFIX}msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}"
- "${_RUBY_ARCH_PREFIX}msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}-static"
- "${_RUBY_ARCH_PREFIX}msvcrt-ruby${_RUBY_NODOT_VERSION}"
- "${_RUBY_ARCH_PREFIX}msvcrt-ruby${_RUBY_NODOT_VERSION}-static" )
+ set( _RUBY_MSVC_RUNTIME "" )
+ if( MSVC_VERSION EQUAL 1200 )
+ set( _RUBY_MSVC_RUNTIME "60" )
+ endif()
+ if( MSVC_VERSION EQUAL 1300 )
+ set( _RUBY_MSVC_RUNTIME "70" )
+ endif()
+ if( MSVC_VERSION EQUAL 1310 )
+ set( _RUBY_MSVC_RUNTIME "71" )
+ endif()
+ if( MSVC_VERSION EQUAL 1400 )
+ set( _RUBY_MSVC_RUNTIME "80" )
+ endif()
+ if( MSVC_VERSION EQUAL 1500 )
+ set( _RUBY_MSVC_RUNTIME "90" )
+ endif()
+
+ set(_RUBY_ARCH_PREFIX "")
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_RUBY_ARCH_PREFIX "x64-")
+ endif()
+
+ list(APPEND _RUBY_POSSIBLE_LIB_NAMES
+ "${_RUBY_ARCH_PREFIX}msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}"
+ "${_RUBY_ARCH_PREFIX}msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}-static"
+ "${_RUBY_ARCH_PREFIX}msvcrt-ruby${_RUBY_NODOT_VERSION}"
+ "${_RUBY_ARCH_PREFIX}msvcrt-ruby${_RUBY_NODOT_VERSION}-static" )
endif()
find_library(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} )
@@ -240,23 +260,23 @@ find_library(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBL
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)
+ 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 "--------------------")
+ 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}
diff --git a/Modules/FindSDL.cmake b/Modules/FindSDL.cmake
index 341001897..8d793a975 100644
--- a/Modules/FindSDL.cmake
+++ b/Modules/FindSDL.cmake
@@ -1,75 +1,76 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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).
+#[=======================================================================[.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).
+#]=======================================================================]
find_path(SDL_INCLUDE_DIR SDL.h
HINTS
@@ -111,9 +112,6 @@ if(NOT SDL_BUILDING_LIBRARY)
ENV SDLDIR
PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX}
PATHS
- /sw
- /opt/local
- /opt/csw
/opt
)
endif()
diff --git a/Modules/FindSDL_image.cmake b/Modules/FindSDL_image.cmake
index 8cdaa7a05..e687b4983 100644
--- a/Modules/FindSDL_image.cmake
+++ b/Modules/FindSDL_image.cmake
@@ -1,40 +1,41 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 compatibility 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).
+#[=======================================================================[.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 compatibility 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).
+#]=======================================================================]
if(NOT SDL_IMAGE_INCLUDE_DIR AND SDLIMAGE_INCLUDE_DIR)
set(SDL_IMAGE_INCLUDE_DIR ${SDLIMAGE_INCLUDE_DIR} CACHE PATH "directory cache
diff --git a/Modules/FindSDL_mixer.cmake b/Modules/FindSDL_mixer.cmake
index 35233d121..315400a30 100644
--- a/Modules/FindSDL_mixer.cmake
+++ b/Modules/FindSDL_mixer.cmake
@@ -1,40 +1,41 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 compatibility 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).
+#[=======================================================================[.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 compatibility 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).
+#]=======================================================================]
if(NOT SDL_MIXER_INCLUDE_DIR AND SDLMIXER_INCLUDE_DIR)
set(SDL_MIXER_INCLUDE_DIR ${SDLMIXER_INCLUDE_DIR} CACHE PATH "directory cache
diff --git a/Modules/FindSDL_net.cmake b/Modules/FindSDL_net.cmake
index b40694668..28cb4d6c2 100644
--- a/Modules/FindSDL_net.cmake
+++ b/Modules/FindSDL_net.cmake
@@ -1,39 +1,40 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 compatibility 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).
+#[=======================================================================[.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 compatibility 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).
+#]=======================================================================]
if(NOT SDL_NET_INCLUDE_DIR AND SDLNET_INCLUDE_DIR)
set(SDL_NET_INCLUDE_DIR ${SDLNET_INCLUDE_DIR} CACHE PATH "directory cache
diff --git a/Modules/FindSDL_sound.cmake b/Modules/FindSDL_sound.cmake
index cf33a4c2c..8d2f9f8fc 100644
--- a/Modules/FindSDL_sound.cmake
+++ b/Modules/FindSDL_sound.cmake
@@ -1,84 +1,85 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
-# 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.
+#[=======================================================================[.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.
+ 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.
+#]=======================================================================]
set(SDL_SOUND_EXTRAS "" CACHE STRING "SDL_sound extra flags")
mark_as_advanced(SDL_SOUND_EXTRAS)
@@ -151,226 +152,199 @@ if(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY)
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})
- string(APPEND 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
+ )
+
+ # 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})
+ string(APPEND TMP_TRY_LIBS " \"${lib}\"")
+ endforeach()
+
+
+ # 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
+ )
+
+
+ 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
+ /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
+ /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
+ /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
+ /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()
-
- set(SDL_SOUND_LIBRARIES ${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARIES_TMP})
- else()
- set(SDL_SOUND_LIBRARIES ${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARY})
- endif()
+ 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
+ /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
+ /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
+ /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
+ /opt
+ PATH_SUFFIXES lib
+ )
+ if(OGG_LIBRARY)
+ set(SDL_SOUND_LIBRARIES_TMP ${SDL_SOUND_LIBRARIES_TMP} ${OGG_LIBRARY})
+ endif()
+ endif()
+ endif()
+
+ set(SDL_SOUND_LIBRARIES ${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARIES_TMP})
+ else()
+ set(SDL_SOUND_LIBRARIES ${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARY})
+ endif()
endif()
if(SDL_SOUND_INCLUDE_DIR AND EXISTS "${SDL_SOUND_INCLUDE_DIR}/SDL_sound.h")
diff --git a/Modules/FindSDL_ttf.cmake b/Modules/FindSDL_ttf.cmake
index aa705f226..d5721da0a 100644
--- a/Modules/FindSDL_ttf.cmake
+++ b/Modules/FindSDL_ttf.cmake
@@ -1,39 +1,40 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 compatibility 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).
+#[=======================================================================[.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 compatibility 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).
+#]=======================================================================]
if(NOT SDL_TTF_INCLUDE_DIR AND SDLTTF_INCLUDE_DIR)
set(SDL_TTF_INCLUDE_DIR ${SDLTTF_INCLUDE_DIR} CACHE PATH "directory cache
diff --git a/Modules/FindSWIG.cmake b/Modules/FindSWIG.cmake
index 92c032f6a..ae6ae56f7 100644
--- a/Modules/FindSWIG.cmake
+++ b/Modules/FindSWIG.cmake
@@ -1,31 +1,32 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+FindSWIG
+--------
-find_program(SWIG_EXECUTABLE NAMES swig3.0 swig2.0 swig)
+Find Simplified Wrapper and Interface Generator (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. :command:`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``
+#]=======================================================================]
+
+find_program(SWIG_EXECUTABLE NAMES swig4.0 swig3.0 swig2.0 swig)
if(SWIG_EXECUTABLE)
execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
@@ -63,4 +64,4 @@ 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)
+mark_as_advanced(SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE)
diff --git a/Modules/FindSelfPackers.cmake b/Modules/FindSelfPackers.cmake
index 01d064139..1abbcbd7a 100644
--- a/Modules/FindSelfPackers.cmake
+++ b/Modules/FindSelfPackers.cmake
@@ -1,38 +1,31 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
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(
diff --git a/Modules/FindSquish.cmake b/Modules/FindSquish.cmake
index 09bdf1ff9..7d495059a 100644
--- a/Modules/FindSquish.cmake
+++ b/Modules/FindSquish.cmake
@@ -1,123 +1,124 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
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.")
@@ -144,9 +145,6 @@ if(NOT 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()
diff --git a/Modules/FindSubversion.cmake b/Modules/FindSubversion.cmake
index 537d3b241..ce280e277 100644
--- a/Modules/FindSubversion.cmake
+++ b/Modules/FindSubversion.cmake
@@ -1,65 +1,69 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 compatibility 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()
+#[=======================================================================[.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 compatibility 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> [IGNORE_SVN_FAILURE])
+ 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 if running
+Subversion's ``info`` command on ``<dir>`` succeeds; otherwise a
+``SEND_ERROR`` message is generated. The error can be ignored by providing the
+``IGNORE_SVN_FAILURE`` option, which causes these variables to remain
+undefined.
+
+::
+
+ <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()
+#]=======================================================================]
find_program(Subversion_SVN_EXECUTABLE svn
PATHS
@@ -84,6 +88,14 @@ if(Subversion_SVN_EXECUTABLE)
"\\2" Subversion_VERSION_SVN "${Subversion_VERSION_SVN}")
macro(Subversion_WC_INFO dir prefix)
+
+ cmake_parse_arguments(
+ "Subversion_WC_INFO"
+ "IGNORE_SVN_FAILURE"
+ "" ""
+ ${ARGN}
+ )
+
# 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}")
@@ -95,10 +107,7 @@ if(Subversion_SVN_EXECUTABLE)
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()
-
+ if(${Subversion_svn_info_result} EQUAL 0)
string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
"\\2" ${prefix}_WC_URL "${${prefix}_WC_INFO}")
string(REGEX REPLACE "^(.*\n)?Repository Root: ([^\n]+).*"
@@ -111,7 +120,8 @@ if(Subversion_SVN_EXECUTABLE)
"\\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}")
-
+ elseif(NOT Subversion_WC_INFO_IGNORE_SVN_FAILURE)
+ message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
endif()
# restore the previous LC_ALL
diff --git a/Modules/FindTCL.cmake b/Modules/FindTCL.cmake
index b6e24a36d..be47c39a0 100644
--- a/Modules/FindTCL.cmake
+++ b/Modules/FindTCL.cmake
@@ -1,48 +1,49 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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/developers, 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.
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindFrameworks.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/FindTclsh.cmake)
@@ -82,11 +83,18 @@ set(TCLTK_POSSIBLE_LIB_PATHS
"${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
- )
+)
+
+set(TCLTK_POSSIBLE_LIB_PATH_SUFFIXES
+ lib/tcl/tcl8.7
+ lib/tcl/tk8.7
+ lib/tcl/tcl8.6
+ lib/tcl/tk8.6
+ lib/tcl/tcl8.5
+ lib/tcl/tk8.5
+ lib/tcl/tcl8.4
+ lib/tcl/tk8.4
+)
if(WIN32)
get_filename_component(
@@ -111,26 +119,30 @@ find_library(TCL_LIBRARY
NAMES
tcl
tcl${TCL_LIBRARY_VERSION} tcl${TCL_TCLSH_VERSION} tcl${TK_WISH_VERSION}
- tcl86 tcl8.6
+ tcl87 tcl8.7 tcl87t tcl8.7t
+ tcl86 tcl8.6 tcl86t tcl8.6t
tcl85 tcl8.5
tcl84 tcl8.4
tcl83 tcl8.3
tcl82 tcl8.2
tcl80 tcl8.0
PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+ PATH_SUFFIXES ${TCLTK_POSSIBLE_LIB_PATH_SUFFIXES}
)
find_library(TK_LIBRARY
NAMES
tk
tk${TK_LIBRARY_VERSION} tk${TCL_TCLSH_VERSION} tk${TK_WISH_VERSION}
- tk86 tk8.6
+ tk87 tk8.7 tk87t tk8.7t
+ tk86 tk8.6 tk86t tk8.6t
tk85 tk8.5
tk84 tk8.4
tk83 tk8.3
tk82 tk8.2
tk80 tk8.0
PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+ PATH_SUFFIXES ${TCLTK_POSSIBLE_LIB_PATH_SUFFIXES}
)
CMAKE_FIND_FRAMEWORKS(Tcl)
@@ -164,20 +176,22 @@ set(TCLTK_POSSIBLE_INCLUDE_PATHS
${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
+ )
+
+set(TCLTK_POSSIBLE_INCLUDE_PATH_SUFFIXES
+ include/tcl${TK_LIBRARY_VERSION}
+ include/tcl${TCL_LIBRARY_VERSION}
+ include/tcl8.7
+ include/tk8.7
+ include/tcl8.6
+ include/tk8.6
+ include/tcl8.5
+ include/tk8.5
+ include/tcl8.4
+ include/tk8.4
+ include/tcl8.3
+ include/tcl8.2
+ include/tcl8.0
)
if(WIN32)
@@ -198,11 +212,13 @@ endif()
find_path(TCL_INCLUDE_PATH
NAMES tcl.h
HINTS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
+ PATH_SUFFIXES ${TCLTK_POSSIBLE_INCLUDE_PATH_SUFFIXES}
)
find_path(TK_INCLUDE_PATH
NAMES tk.h
HINTS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
+ PATH_SUFFIXES ${TCLTK_POSSIBLE_INCLUDE_PATH_SUFFIXES}
)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
diff --git a/Modules/FindTIFF.cmake b/Modules/FindTIFF.cmake
index b622ca61c..00a3a415a 100644
--- a/Modules/FindTIFF.cmake
+++ b/Modules/FindTIFF.cmake
@@ -1,43 +1,44 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindTIFF
-# --------
-#
-# Find the TIFF library (libtiff).
-#
-# Imported targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following :prop_tgt:`IMPORTED` targets:
-#
-# ``TIFF::TIFF``
-# The TIFF library, if found.
-#
-# Result variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module will set the following variables in your project:
-#
-# ``TIFF_FOUND``
-# true if the TIFF headers and libraries were found
-# ``TIFF_INCLUDE_DIR``
-# the directory containing the TIFF headers
-# ``TIFF_INCLUDE_DIRS``
-# the directory containing the TIFF headers
-# ``TIFF_LIBRARIES``
-# TIFF libraries to be linked
-#
-# Cache variables
-# ^^^^^^^^^^^^^^^
-#
-# The following cache variables may also be set:
-#
-# ``TIFF_INCLUDE_DIR``
-# the directory containing the TIFF headers
-# ``TIFF_LIBRARY``
-# the path to the TIFF library
+#[=======================================================================[.rst:
+FindTIFF
+--------
+
+Find the TIFF library (``libtiff``).
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``TIFF::TIFF``
+ The TIFF library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``TIFF_FOUND``
+ true if the TIFF headers and libraries were found
+``TIFF_INCLUDE_DIR``
+ the directory containing the TIFF headers
+``TIFF_INCLUDE_DIRS``
+ the directory containing the TIFF headers
+``TIFF_LIBRARIES``
+ TIFF libraries to be linked
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``TIFF_INCLUDE_DIR``
+ the directory containing the TIFF headers
+``TIFF_LIBRARY``
+ the path to the TIFF library
+#]=======================================================================]
find_path(TIFF_INCLUDE_DIR tiff.h)
diff --git a/Modules/FindTclStub.cmake b/Modules/FindTclStub.cmake
index 9711bd6f8..8f634809e 100644
--- a/Modules/FindTclStub.cmake
+++ b/Modules/FindTclStub.cmake
@@ -1,48 +1,49 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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/developers, 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.
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindTCL.cmake)
@@ -101,6 +102,7 @@ find_library(TCL_STUB_LIBRARY
NAMES
tclstub
tclstub${TK_LIBRARY_VERSION} tclstub${TCL_TCLSH_VERSION} tclstub${TK_WISH_VERSION}
+ tclstub87 tclstub8.7
tclstub86 tclstub8.6
tclstub85 tclstub8.5
tclstub84 tclstub8.4
@@ -114,6 +116,7 @@ find_library(TK_STUB_LIBRARY
NAMES
tkstub
tkstub${TCL_LIBRARY_VERSION} tkstub${TCL_TCLSH_VERSION} tkstub${TK_WISH_VERSION}
+ tkstub87 tkstub8.7
tkstub86 tkstub8.6
tkstub85 tkstub8.5
tkstub84 tkstub8.4
diff --git a/Modules/FindTclsh.cmake b/Modules/FindTclsh.cmake
index 9fcb41cb4..82be473b1 100644
--- a/Modules/FindTclsh.cmake
+++ b/Modules/FindTclsh.cmake
@@ -1,23 +1,24 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
if(CYGWIN)
find_program(TCL_TCLSH NAMES cygtclsh83 cygtclsh80)
@@ -68,6 +69,7 @@ endif()
set(TCL_TCLSH_NAMES
tclsh
tclsh${TCL_LIBRARY_VERSION} tclsh${TK_LIBRARY_VERSION} tclsh${TK_WISH_VERSION}
+ tclsh87 tclsh8.7
tclsh86 tclsh8.6
tclsh85 tclsh8.5
tclsh84 tclsh8.4
@@ -82,11 +84,11 @@ find_program(TCL_TCLSH
)
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)
+ 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()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake
index 2c6a58beb..b0c91b2ac 100644
--- a/Modules/FindThreads.cmake
+++ b/Modules/FindThreads.cmake
@@ -1,64 +1,75 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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 preferred 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.
+#[=======================================================================[.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_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
+
+If the use of the -pthread compiler and linker flag is preferred then the
+caller can set
+
+::
+
+ THREADS_PREFER_PTHREAD_FLAG
+
+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.
+#]=======================================================================]
include (CheckLibraryExists)
-include (CheckSymbolExists)
set(Threads_FOUND FALSE)
set(CMAKE_REQUIRED_QUIET_SAVE ${CMAKE_REQUIRED_QUIET})
set(CMAKE_REQUIRED_QUIET ${Threads_FIND_QUIETLY})
if(CMAKE_C_COMPILER_LOADED)
include (CheckIncludeFile)
+ include (CheckCSourceCompiles)
elseif(CMAKE_CXX_COMPILER_LOADED)
include (CheckIncludeFileCXX)
+ include (CheckCXXSourceCompiles)
else()
message(FATAL_ERROR "FindThreads only works if either C or CXX language is enabled")
endif()
-# Do we have sproc?
-if(CMAKE_SYSTEM_NAME MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD)
- include (CheckIncludeFiles)
- CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
-endif()
+# simple pthread test code
+set(PTHREAD_C_CXX_TEST_SOURCE [====[
+#include <pthread.h>
+
+void* test_func(void* data)
+{
+ return data;
+}
+
+int main(void)
+{
+ pthread_t thread;
+ pthread_create(&thread, NULL, test_func, NULL);
+ pthread_detach(thread);
+ pthread_join(thread, NULL);
+ pthread_atfork(NULL, NULL, NULL);
+ pthread_exit(NULL);
+
+ return 0;
+}
+]====])
# Internal helper macro.
# Do NOT even think about using it outside of this file!
@@ -86,23 +97,16 @@ macro(_check_pthreads_flag)
set(_threads_src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/FindThreads/CheckForPthreads.cxx)
configure_file(${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.c "${_threads_src}" COPYONLY)
endif()
- try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
+ try_compile(THREADS_HAVE_PTHREAD_ARG
${CMAKE_BINARY_DIR}
${_threads_src}
CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread
- COMPILE_OUTPUT_VARIABLE OUTPUT)
+ OUTPUT_VARIABLE OUTPUT)
unset(_threads_src)
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()
+ set(Threads_FOUND TRUE)
+ message(STATUS "Check if compiler accepts -pthread - yes")
else()
message(STATUS "Check if compiler accepts -pthread - no")
file(APPEND
@@ -119,53 +123,57 @@ macro(_check_pthreads_flag)
endif()
endmacro()
-if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD)
- # We have sproc
- set(CMAKE_USE_SPROC_INIT 1)
+# Do we have pthreads?
+if(CMAKE_C_COMPILER_LOADED)
+ CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H)
else()
- # Do we have pthreads?
- if(CMAKE_C_COMPILER_LOADED)
- CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H)
- else()
- CHECK_INCLUDE_FILE_CXX("pthread.h" CMAKE_HAVE_PTHREAD_H)
- endif()
- 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_INCLUDE_FILE_CXX("pthread.h" CMAKE_HAVE_PTHREAD_H)
+endif()
- # 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()
+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.
+ # We list some pthread functions in PTHREAD_C_CXX_TEST_SOURCE test code.
+ # If the pthread functions already exist in C library, we could just use
+ # them instead of linking to the additional pthread library.
+ if(CMAKE_C_COMPILER_LOADED)
+ CHECK_C_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD)
+ elseif(CMAKE_CXX_COMPILER_LOADED)
+ CHECK_CXX_SOURCE_COMPILES("${PTHREAD_C_CXX_TEST_SOURCE}" CMAKE_HAVE_LIBC_PTHREAD)
+ endif()
+ if(CMAKE_HAVE_LIBC_PTHREAD)
+ 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 ()
+
+ if(CMAKE_SYSTEM MATCHES "GHS-MULTI")
+ _check_threads_lib(posix pthread_create CMAKE_HAVE_PTHREADS_CREATE)
+ 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()
-
- _check_pthreads_flag()
endif()
+
+ _check_pthreads_flag()
endif()
-if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE)
+if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_PTHREAD)
set(CMAKE_USE_PTHREADS_INIT 1)
set(Threads_FOUND TRUE)
endif()
@@ -215,7 +223,9 @@ 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")
+ set_property(TARGET Threads::Threads
+ PROPERTY INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-Xcompiler -pthread>"
+ "$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>")
endif()
if(CMAKE_THREAD_LIBS_INIT)
diff --git a/Modules/FindUnixCommands.cmake b/Modules/FindUnixCommands.cmake
index d2b6a4d7f..2513f5c29 100644
--- a/Modules/FindUnixCommands.cmake
+++ b/Modules/FindUnixCommands.cmake
@@ -1,24 +1,22 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindUnixCommands
-# ----------------
-#
-# Find Unix commands, including the ones from Cygwin
-#
-# This module looks for the Unix commands bash, cp, gzip, mv, rm, and tar
-# and stores the result in the variables BASH, CP, GZIP, MV, RM, and TAR.
+#[=======================================================================[.rst:
+FindUnixCommands
+----------------
+
+Find Unix commands, including the ones from Cygwin
+
+This module looks for the Unix commands ``bash``, ``cp``, ``gzip``,
+``mv``, ``rm``, and ``tar`` and stores the result in the variables
+``BASH``, ``CP``, ``GZIP``, ``MV``, ``RM``, and ``TAR``.
+#]=======================================================================]
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
@@ -27,10 +25,6 @@ mark_as_advanced(
find_program(CP
cp
${CYGWIN_INSTALL_PATH}/bin
- /bin
- /usr/bin
- /usr/local/bin
- /sbin
)
mark_as_advanced(
CP
@@ -39,10 +33,6 @@ mark_as_advanced(
find_program(GZIP
gzip
${CYGWIN_INSTALL_PATH}/bin
- /bin
- /usr/bin
- /usr/local/bin
- /sbin
)
mark_as_advanced(
GZIP
@@ -51,10 +41,6 @@ mark_as_advanced(
find_program(MV
mv
${CYGWIN_INSTALL_PATH}/bin
- /bin
- /usr/bin
- /usr/local/bin
- /sbin
)
mark_as_advanced(
MV
@@ -63,10 +49,6 @@ mark_as_advanced(
find_program(RM
rm
${CYGWIN_INSTALL_PATH}/bin
- /bin
- /usr/bin
- /usr/local/bin
- /sbin
)
mark_as_advanced(
RM
@@ -78,10 +60,6 @@ find_program(TAR
gtar
PATH
${CYGWIN_INSTALL_PATH}/bin
- /bin
- /usr/bin
- /usr/local/bin
- /sbin
)
mark_as_advanced(
TAR
diff --git a/Modules/FindVulkan.cmake b/Modules/FindVulkan.cmake
index 1f4c8ade9..ae8d72dd9 100644
--- a/Modules/FindVulkan.cmake
+++ b/Modules/FindVulkan.cmake
@@ -1,32 +1,34 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindVulkan
-# ----------
-#
-# Try to find Vulkan
-#
-# IMPORTED Targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines :prop_tgt:`IMPORTED` target ``Vulkan::Vulkan``, if
-# Vulkan has been found.
-#
-# Result Variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following variables::
-#
-# Vulkan_FOUND - True if Vulkan was found
-# Vulkan_INCLUDE_DIRS - include directories for Vulkan
-# Vulkan_LIBRARIES - link against this library to use Vulkan
-#
-# The module will also define two cache variables::
-#
-# Vulkan_INCLUDE_DIR - the Vulkan include directory
-# Vulkan_LIBRARY - the path to the Vulkan library
-#
+#[=======================================================================[.rst:
+FindVulkan
+----------
+
+Find Vulkan, which isis a low-overhead, cross-platform 3D graphics
+and computing API.
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``Vulkan::Vulkan``, if
+Vulkan has been found.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This module defines the following variables::
+
+ Vulkan_FOUND - "True" if Vulkan was found
+ Vulkan_INCLUDE_DIRS - include directories for Vulkan
+ Vulkan_LIBRARIES - link against this library to use Vulkan
+
+The module will also define two cache variables::
+
+ Vulkan_INCLUDE_DIR - the Vulkan include directory
+ Vulkan_LIBRARY - the path to the Vulkan library
+
+#]=======================================================================]
if(WIN32)
find_path(Vulkan_INCLUDE_DIR
@@ -65,7 +67,7 @@ endif()
set(Vulkan_LIBRARIES ${Vulkan_LIBRARY})
set(Vulkan_INCLUDE_DIRS ${Vulkan_INCLUDE_DIR})
-include(FindPackageHandleStandardArgs)
+include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(Vulkan
DEFAULT_MSG
Vulkan_LIBRARY Vulkan_INCLUDE_DIR)
diff --git a/Modules/FindWget.cmake b/Modules/FindWget.cmake
index 4fcb2fa37..bd01ec201 100644
--- a/Modules/FindWget.cmake
+++ b/Modules/FindWget.cmake
@@ -1,18 +1,19 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/FindCygwin.cmake)
diff --git a/Modules/FindWish.cmake b/Modules/FindWish.cmake
index b64b04138..b332bde9b 100644
--- a/Modules/FindWish.cmake
+++ b/Modules/FindWish.cmake
@@ -1,23 +1,24 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
if(UNIX)
find_program(TK_WISH cygwish80 )
diff --git a/Modules/FindX11.cmake b/Modules/FindX11.cmake
index f7dfc8257..b28dd125d 100644
--- a/Modules/FindX11.cmake
+++ b/Modules/FindX11.cmake
@@ -1,58 +1,59 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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 and targets:
+
+::
+
+ X11_ICE_INCLUDE_PATH, X11_ICE_LIB, X11_ICE_FOUND, X11::ICE
+ X11_SM_INCLUDE_PATH, X11_SM_LIB, X11_SM_FOUND, X11::SM
+ X11_X11_INCLUDE_PATH, X11_X11_LIB, X11::X11
+ X11_Xaccessrules_INCLUDE_PATH,
+ X11_Xaccessstr_INCLUDE_PATH, X11_Xaccess_FOUND
+ X11_Xau_INCLUDE_PATH, X11_Xau_LIB, X11_Xau_FOUND, X11::Xau
+ X11_Xcomposite_INCLUDE_PATH, X11_Xcomposite_LIB, X11_Xcomposite_FOUND, X11::Xcomposite
+ X11_Xcursor_INCLUDE_PATH, X11_Xcursor_LIB, X11_Xcursor_FOUND, X11::Xcursor
+ X11_Xdamage_INCLUDE_PATH, X11_Xdamage_LIB, X11_Xdamage_FOUND, X11::Xdamage
+ X11_Xdmcp_INCLUDE_PATH, X11_Xdmcp_LIB, X11_Xdmcp_FOUND, X11::Xdmcp
+ X11_Xext_INCLUDE_PATH, X11_Xext_LIB, X11_Xext_FOUND, X11::Xext
+ X11_Xxf86misc_INCLUDE_PATH, X11_Xxf86misc_LIB, X11_Xxf86misc_FOUND, X11::Xxf86misc
+ X11_Xxf86vm_INCLUDE_PATH, X11_Xxf86vm_LIB X11_Xxf86vm_FOUND, X11::Xxf86vm
+ X11_Xfixes_INCLUDE_PATH, X11_Xfixes_LIB, X11_Xfixes_FOUND, X11::Xfixes
+ X11_Xft_INCLUDE_PATH, X11_Xft_LIB, X11_Xft_FOUND, X11::Xft
+ X11_Xi_INCLUDE_PATH, X11_Xi_LIB, X11_Xi_FOUND, X11::Xi
+ X11_Xinerama_INCLUDE_PATH, X11_Xinerama_LIB, X11_Xinerama_FOUND, X11::Xinerama
+ X11_Xkb_INCLUDE_PATH,
+ X11_Xkblib_INCLUDE_PATH, X11_Xkb_FOUND, X11::Xkb
+ X11_xkbfile_INCLUDE_PATH, X11_xkbfile_LIB, X11_xkbfile_FOUND, X11::xkbfile
+ X11_Xmu_INCLUDE_PATH, X11_Xmu_LIB, X11_Xmu_FOUND, X11::Xmu
+ X11_Xpm_INCLUDE_PATH, X11_Xpm_LIB, X11_Xpm_FOUND, X11::Xpm
+ X11_Xtst_INCLUDE_PATH, X11_Xtst_LIB, X11_Xtst_FOUND, X11::Xtst
+ X11_Xrandr_INCLUDE_PATH, X11_Xrandr_LIB, X11_Xrandr_FOUND, X11::Xrandr
+ X11_Xrender_INCLUDE_PATH, X11_Xrender_LIB, X11_Xrender_FOUND, X11::Xrender
+ X11_XRes_INCLUDE_PATH, X11_XRes_LIB, X11_XRes_FOUND, X11::XRes
+ X11_Xss_INCLUDE_PATH, X11_Xss_LIB, X11_Xss_FOUND, X11::Xss
+ X11_Xt_INCLUDE_PATH, X11_Xt_LIB, X11_Xt_FOUND, X11::Xt
+ X11_Xutil_INCLUDE_PATH, X11_Xutil_FOUND, X11::Xutil
+ X11_Xv_INCLUDE_PATH, X11_Xv_LIB, X11_Xv_FOUND, X11::Xv
+ 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_XSync_INCLUDE_PATH, (in X11_Xext_LIB), X11_XSync_FOUND
+#]=======================================================================]
if (UNIX)
set(X11_FOUND 0)
@@ -97,31 +98,38 @@ if (UNIX)
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_Xext_INCLUDE_PATH X11/extensions/Xext.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_Xxf86misc_INCLUDE_PATH X11/extensions/xf86misc.h ${X11_INC_SEARCH_PATH})
+ find_path(X11_Xxf86vm_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_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_Xtst_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_Xss_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})
+ # Backwards compatibility.
+ set(X11_Xinput_INCLUDE_PATH "${X11_Xi_INCLUDE_PATH}")
+ set(X11_xf86misc_INCLUDE_PATH "${X11_Xxf86misc_INCLUDE_PATH}")
+ set(X11_xf86vmode_INCLUDE_PATH "${X11_Xxf8vm_INCLUDE_PATH}")
+ set(X11_Xkbfile_INCLUDE_PATH "${X11_xkbfile_INCLUDE_PATH}")
+ set(X11_XTest_INCLUDE_PATH "${X11_Xtst_INCLUDE_PATH}")
+ set(X11_Xscreensaver_INCLUDE_PATH "${X11_Xss_INCLUDE_PATH}")
find_library(X11_X11_LIB X11 ${X11_LIB_SEARCH_PATH})
@@ -138,20 +146,25 @@ if (UNIX)
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_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_Xss_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_Xtst_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})
+ # Backwards compatibility.
+ set(X11_Xinput_LIB "${X11_Xi_LIB}")
+ set(X11_Xkbfile_LIB "${X11_xkbfile_LIB}")
+ set(X11_XTest_LIB "${X11_Xtst_LIB}")
+ set(X11_Xscreensaver_LIB "${X11_Xss_LIB}")
+
set(X11_LIBRARY_DIR "")
if(X11_X11_LIB)
get_filename_component(X11_LIBRARY_DIR ${X11_X11_LIB} PATH)
@@ -159,31 +172,31 @@ if (UNIX)
set(X11_INCLUDE_DIR) # start with empty list
if(X11_X11_INCLUDE_PATH)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_X11_INCLUDE_PATH})
+ list(APPEND X11_INCLUDE_DIR ${X11_X11_INCLUDE_PATH})
endif()
if(X11_Xlib_INCLUDE_PATH)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xlib_INCLUDE_PATH})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND X11_LIBRARIES ${X11_X11_LIB})
endif()
if(X11_Xext_LIB)
set(X11_Xext_FOUND TRUE)
- set(X11_LIBRARIES ${X11_LIBRARIES} ${X11_Xext_LIB})
+ list(APPEND X11_LIBRARIES ${X11_Xext_LIB})
endif()
if(X11_Xt_LIB AND X11_Xt_INCLUDE_PATH)
@@ -191,13 +204,17 @@ if (UNIX)
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})
+ find_package(Freetype QUIET)
+ find_package(Fontconfig QUIET)
+ if (FREETYPE_FOUND AND Fontconfig_FOUND)
+ set(X11_Xft_FOUND TRUE)
+ endif ()
+ list(APPEND 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})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xv_INCLUDE_PATH})
endif()
if (X11_Xau_LIB AND X11_Xau_INCLUDE_PATH)
@@ -206,118 +223,124 @@ if (UNIX)
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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND X11_INCLUDE_DIR ${X11_XShm_INCLUDE_PATH})
endif ()
- if (X11_XTest_INCLUDE_PATH AND X11_XTest_LIB)
+ if (X11_Xtst_INCLUDE_PATH AND X11_Xtst_LIB)
+ set(X11_Xtst_FOUND TRUE)
+ # Backwards compatibility.
set(X11_XTest_FOUND TRUE)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_XTest_INCLUDE_PATH})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xtst_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})
+ # Backwards compatibility.
+ set(X11_Xinput_FOUND TRUE)
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND 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})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xrandr_INCLUDE_PATH})
endif ()
- if (X11_xf86misc_INCLUDE_PATH AND X11_Xxf86misc_LIB)
+ if (X11_Xxf86misc_INCLUDE_PATH AND X11_Xxf86misc_LIB)
+ set(X11_Xxf86misc_FOUND TRUE)
+ # Backwards compatibility.
set(X11_xf86misc_FOUND TRUE)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_xf86misc_INCLUDE_PATH})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xxf86misc_INCLUDE_PATH})
endif ()
- if (X11_xf86vmode_INCLUDE_PATH AND X11_Xxf86vm_LIB)
+ if (X11_Xxf86vm_INCLUDE_PATH AND X11_Xxf86vm_LIB)
+ set(X11_Xxf86vm_FOUND TRUE)
+ # Backwards compatibility.
set(X11_xf86vmode_FOUND TRUE)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_xf86vmode_INCLUDE_PATH})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xxf86vm_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})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xcursor_INCLUDE_PATH})
endif ()
- if (X11_Xscreensaver_INCLUDE_PATH AND X11_Xscreensaver_LIB)
+ if (X11_Xss_INCLUDE_PATH AND X11_Xss_LIB)
+ set(X11_Xss_FOUND TRUE)
set(X11_Xscreensaver_FOUND TRUE)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xscreensaver_INCLUDE_PATH})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xss_INCLUDE_PATH})
endif ()
if (X11_dpms_INCLUDE_PATH)
set(X11_dpms_FOUND TRUE)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_dpms_INCLUDE_PATH})
+ list(APPEND 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} )
+ list(APPEND X11_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH} )
endif ()
- if (X11_Xkbfile_INCLUDE_PATH AND X11_Xkbfile_LIB AND X11_Xlib_INCLUDE_PATH)
+ if (X11_xkbfile_INCLUDE_PATH AND X11_xkbfile_LIB AND X11_Xlib_INCLUDE_PATH)
+ set(X11_xkbfile_FOUND TRUE)
+ # Backwards compatibility.
set(X11_Xkbfile_FOUND TRUE)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xkbfile_INCLUDE_PATH} )
+ list(APPEND 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})
+ list(APPEND X11_INCLUDE_DIR ${X11_Xmu_INCLUDE_PATH})
endif ()
if (X11_XSync_INCLUDE_PATH)
set(X11_XSync_FOUND TRUE)
- set(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_XSync_INCLUDE_PATH})
+ list(APPEND X11_INCLUDE_DIR ${X11_XSync_INCLUDE_PATH})
endif ()
if(X11_ICE_LIB AND X11_ICE_INCLUDE_PATH)
@@ -339,6 +362,11 @@ if (UNIX)
set(X11_FOUND 1)
endif ()
+ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+ find_package_handle_standard_args(X11
+ REQUIRED_VARS X11_X11_INCLUDE_PATH X11_X11_LIB
+ HANDLE_COMPONENTS)
+
if(X11_FOUND)
include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/CheckLibraryExists.cmake)
@@ -351,69 +379,69 @@ if (UNIX)
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)
+ 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)
+ 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)
+ list(APPEND X11_X_EXTRA_LIBS -ldnet)
else ()
- CHECK_LIBRARY_EXISTS("dnet_stub" "dnet_ntoa" "" X11_LIB_DNET_STUB_HAS_DNET_NTOA)
+ 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)
+ list(APPEND X11_X_EXTRA_LIBS -ldnet_stub)
endif ()
endif ()
endif()
# Find library needed for gethostbyname.
- CHECK_FUNCTION_EXISTS("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
+ check_function_exists("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
if(NOT CMAKE_HAVE_GETHOSTBYNAME)
- CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_LIB_NSL_HAS_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)
+ list(APPEND X11_X_EXTRA_LIBS -lnsl)
else ()
- CHECK_LIBRARY_EXISTS("bsd" "gethostbyname" "" CMAKE_LIB_BSD_HAS_GETHOSTBYNAME)
+ 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)
+ list(APPEND X11_X_EXTRA_LIBS -lbsd)
endif ()
endif ()
endif()
# Find library needed for connect.
- CHECK_FUNCTION_EXISTS("connect" CMAKE_HAVE_CONNECT)
+ check_function_exists("connect" CMAKE_HAVE_CONNECT)
if(NOT CMAKE_HAVE_CONNECT)
- CHECK_LIBRARY_EXISTS("socket" "connect" "" CMAKE_LIB_SOCKET_HAS_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})
+ list(INSERT X11_X_EXTRA_LIBS 0 -lsocket)
endif ()
endif()
# Find library needed for remove.
- CHECK_FUNCTION_EXISTS("remove" CMAKE_HAVE_REMOVE)
+ check_function_exists("remove" CMAKE_HAVE_REMOVE)
if(NOT CMAKE_HAVE_REMOVE)
- CHECK_LIBRARY_EXISTS("posix" "remove" "" CMAKE_LIB_POSIX_HAS_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)
+ list(APPEND X11_X_EXTRA_LIBS -lposix)
endif ()
endif()
# Find library needed for shmat.
- CHECK_FUNCTION_EXISTS("shmat" CMAKE_HAVE_SHMAT)
+ check_function_exists("shmat" CMAKE_HAVE_SHMAT)
if(NOT CMAKE_HAVE_SHMAT)
- CHECK_LIBRARY_EXISTS("ipc" "shmat" "" CMAKE_LIB_IPS_HAS_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)
+ list(APPEND X11_X_EXTRA_LIBS -lipc)
endif ()
endif()
endif()
if (X11_ICE_FOUND)
- CHECK_LIBRARY_EXISTS("ICE" "IceConnectionNumber" "${X11_LIBRARY_DIR}"
+ 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})
+ list(INSERT X11_X_PRE_LIBS 0 ${X11_SM_LIB})
endif()
endif()
endif ()
@@ -421,18 +449,222 @@ if (UNIX)
# 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")
+ if (NOT TARGET X11::X11)
+ add_library(X11::X11 UNKNOWN IMPORTED)
+ set_target_properties(X11::X11 PROPERTIES
+ IMPORTED_LOCATION "${X11_X11_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_X11_INCLUDE_PATH}")
endif ()
endif ()
+ if (X11_ICE_FOUND AND NOT TARGET X11::ICE)
+ add_library(X11::ICE UNKNOWN IMPORTED)
+ set_target_properties(X11::ICE PROPERTIES
+ IMPORTED_LOCATION "${X11_ICE_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_ICE_INCLUDE_PATH}")
+ endif ()
+
+ if (X11_SM_FOUND AND NOT TARGET X11::SM)
+ add_library(X11::SM UNKNOWN IMPORTED)
+ set_target_properties(X11::SM PROPERTIES
+ IMPORTED_LOCATION "${X11_SM_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_SM_INCLUDE_PATH}")
+ endif ()
+
+ if (X11_Xau_FOUND AND NOT TARGET X11::Xau)
+ add_library(X11::Xau UNKNOWN IMPORTED)
+ set_target_properties(X11::Xau PROPERTIES
+ IMPORTED_LOCATION "${X11_Xau_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xau_INCLUDE_PATH}")
+ endif ()
+
+ if (X11_Xcomposite_FOUND AND NOT TARGET X11::Xcomposite)
+ add_library(X11::Xcomposite UNKNOWN IMPORTED)
+ set_target_properties(X11::Xcomposite PROPERTIES
+ IMPORTED_LOCATION "${X11_Xcomposite_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xcomposite_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_Xcursor_FOUND AND NOT TARGET X11::Xcursor)
+ add_library(X11::Xcursor UNKNOWN IMPORTED)
+ set_target_properties(X11::Xcursor PROPERTIES
+ IMPORTED_LOCATION "${X11_Xcursor_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xcursor_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xrender;X11::Xfixes;X11::X11")
+ endif ()
+
+ if (X11_Xdamage_FOUND AND NOT TARGET X11::Xdamage)
+ add_library(X11::Xdamage UNKNOWN IMPORTED)
+ set_target_properties(X11::Xdamage PROPERTIES
+ IMPORTED_LOCATION "${X11_Xdamage_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xdamage_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xfixes;X11::X11")
+ endif ()
+
+ if (X11_Xdmcp_FOUND AND NOT TARGET X11::Xdmcp)
+ add_library(X11::Xdmcp UNKNOWN IMPORTED)
+ set_target_properties(X11::Xdmcp PROPERTIES
+ IMPORTED_LOCATION "${X11_Xdmcp_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xdmcp_INCLUDE_PATH}")
+ endif ()
+
+ if (X11_Xext_FOUND AND NOT TARGET X11::Xext)
+ add_library(X11::Xext UNKNOWN IMPORTED)
+ set_target_properties(X11::Xext PROPERTIES
+ IMPORTED_LOCATION "${X11_Xext_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xext_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_Xxf86misc_FOUND AND NOT TARGET X11::Xxf86misc)
+ add_library(X11::Xxf86misc UNKNOWN IMPORTED)
+ set_target_properties(X11::Xxf86misc PROPERTIES
+ IMPORTED_LOCATION "${X11_Xxf86misc_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xxf86misc_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11;X11::Xext")
+ endif ()
+
+ if (X11_Xxf86vm_FOUND AND NOT TARGET X11::Xxf86vm)
+ add_library(X11::Xxf86vm UNKNOWN IMPORTED)
+ set_target_properties(X11::Xxf86vm PROPERTIES
+ IMPORTED_LOCATION "${X11_Xxf86vm_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xxf86vm_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11;X11::Xext")
+ endif ()
+
+ if (X11_Xfixes_FOUND AND NOT TARGET X11::Xfixes)
+ add_library(X11::Xfixes UNKNOWN IMPORTED)
+ set_target_properties(X11::Xfixes PROPERTIES
+ IMPORTED_LOCATION "${X11_Xfixes_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xfixes_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_Xft_FOUND AND NOT TARGET X11::Xft)
+ add_library(X11::Xft UNKNOWN IMPORTED)
+ set_target_properties(X11::Xft PROPERTIES
+ IMPORTED_LOCATION "${X11_Xft_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xft_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xrender;X11::X11;Fontconfig::Fontconfig;Freetype::Freetype")
+ endif ()
+
+ if (X11_Xi_FOUND AND NOT TARGET X11::Xi)
+ add_library(X11::Xi UNKNOWN IMPORTED)
+ set_target_properties(X11::Xi PROPERTIES
+ IMPORTED_LOCATION "${X11_Xi_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xi_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
+ endif ()
+
+ if (X11_Xinerama_FOUND AND NOT TARGET X11::Xinerama)
+ add_library(X11::Xinerama UNKNOWN IMPORTED)
+ set_target_properties(X11::Xinerama PROPERTIES
+ IMPORTED_LOCATION "${X11_Xinerama_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xinerama_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
+ endif ()
+
+ if (X11_Xkb_FOUND AND NOT TARGET X11::Xkb)
+ add_library(X11::Xkb INTERFACE IMPORTED)
+ set_target_properties(X11::Xkb PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xkb_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_xkbfile_FOUND AND NOT TARGET X11::xkbfile)
+ add_library(X11::xkbfile UNKNOWN IMPORTED)
+ set_target_properties(X11::xkbfile PROPERTIES
+ IMPORTED_LOCATION "${X11_xkbfile_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_xkbfile_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_Xmu_FOUND AND NOT TARGET X11::Xmu)
+ add_library(X11::Xmu UNKNOWN IMPORTED)
+ set_target_properties(X11::Xmu PROPERTIES
+ IMPORTED_LOCATION "${X11_Xmu_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xmu_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xt;X11::Xext;X11::X11")
+ endif ()
+
+ if (X11_Xpm_FOUND AND NOT TARGET X11::Xpm)
+ add_library(X11::Xpm UNKNOWN IMPORTED)
+ set_target_properties(X11::Xpm PROPERTIES
+ IMPORTED_LOCATION "${X11_Xpm_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xpm_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_Xtst_FOUND AND NOT TARGET X11::Xtst)
+ add_library(X11::Xtst UNKNOWN IMPORTED)
+ set_target_properties(X11::Xtst PROPERTIES
+ IMPORTED_LOCATION "${X11_Xtst_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xtst_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xi;X11::Xext;X11::X11")
+ endif ()
+
+ if (X11_Xrandr_FOUND AND NOT TARGET X11::Xrandr)
+ add_library(X11::Xrandr UNKNOWN IMPORTED)
+ set_target_properties(X11::Xrandr PROPERTIES
+ IMPORTED_LOCATION "${X11_Xrandr_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xrandr_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xrender;X11::Xext;X11::X11")
+ endif ()
+
+ if (X11_Xrender_FOUND AND NOT TARGET X11::Xrender)
+ add_library(X11::Xrender UNKNOWN IMPORTED)
+ set_target_properties(X11::Xrender PROPERTIES
+ IMPORTED_LOCATION "${X11_Xrender_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xrender_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_XRes_FOUND AND NOT TARGET X11::XRes)
+ add_library(X11::XRes UNKNOWN IMPORTED)
+ set_target_properties(X11::XRes PROPERTIES
+ IMPORTED_LOCATION "${X11_XRes_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_XRes_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
+ endif ()
+
+ if (X11_Xss_FOUND AND NOT TARGET X11::Xss)
+ add_library(X11::Xss UNKNOWN IMPORTED)
+ set_target_properties(X11::Xss PROPERTIES
+ IMPORTED_LOCATION "${X11_Xss_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xss_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
+ endif ()
+
+ if (X11_Xt_FOUND AND NOT TARGET X11::Xt)
+ add_library(X11::Xt UNKNOWN IMPORTED)
+ set_target_properties(X11::Xt PROPERTIES
+ IMPORTED_LOCATION "${X11_Xt_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xt_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::ICE;X11::SM;X11::X11")
+ endif ()
+
+ if (X11_Xutil_FOUND AND NOT TARGET X11::Xutil)
+ add_library(X11::Xutil INTERFACE IMPORTED)
+ set_target_properties(X11::Xutil PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xutil_INCLUDE_PATH}"
+ # libX11 contains the implementations for functions in the Xutil.h
+ # header.
+ INTERFACE_LINK_LIBRARIES "X11::X11")
+ endif ()
+
+ if (X11_Xv_FOUND AND NOT TARGET X11::Xv)
+ add_library(X11::Xv UNKNOWN IMPORTED)
+ set_target_properties(X11::Xv PROPERTIES
+ IMPORTED_LOCATION "${X11_Xv_LIB}"
+ INTERFACE_INCLUDE_DIRECTORIES "${X11_Xv_INCLUDE_PATH}"
+ INTERFACE_LINK_LIBRARIES "X11::Xext;X11::X11")
+ endif ()
+
mark_as_advanced(
X11_X11_INCLUDE_PATH
X11_X11_LIB
+ X11_Xext_INCLUDE_PATH
X11_Xext_LIB
X11_Xau_LIB
X11_Xau_INCLUDE_PATH
@@ -440,7 +672,6 @@ if (UNIX)
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
@@ -452,15 +683,15 @@ if (UNIX)
X11_XRes_LIB
X11_XRes_INCLUDE_PATH
X11_Xxf86misc_LIB
- X11_xf86misc_INCLUDE_PATH
+ X11_Xxf86misc_INCLUDE_PATH
X11_Xxf86vm_LIB
- X11_xf86vmode_INCLUDE_PATH
+ X11_Xxf86vm_INCLUDE_PATH
X11_Xi_LIB
X11_Xi_INCLUDE_PATH
X11_Xinerama_LIB
X11_Xinerama_INCLUDE_PATH
- X11_XTest_LIB
- X11_XTest_INCLUDE_PATH
+ X11_Xtst_LIB
+ X11_Xtst_INCLUDE_PATH
X11_Xcursor_LIB
X11_Xcursor_INCLUDE_PATH
X11_dpms_INCLUDE_PATH
@@ -473,16 +704,14 @@ if (UNIX)
X11_Xdmcp_INCLUDE_PATH
X11_Xkb_INCLUDE_PATH
X11_Xkblib_INCLUDE_PATH
- X11_Xkbfile_INCLUDE_PATH
- X11_Xkbfile_LIB
+ X11_xkbfile_INCLUDE_PATH
+ X11_xkbfile_LIB
X11_Xmu_INCLUDE_PATH
X11_Xmu_LIB
- X11_Xscreensaver_INCLUDE_PATH
- X11_Xscreensaver_LIB
+ X11_Xss_INCLUDE_PATH
+ X11_Xss_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
@@ -498,5 +727,3 @@ if (UNIX)
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/FindXCTest.cmake b/Modules/FindXCTest.cmake
index ffdf677cc..15721e184 100644
--- a/Modules/FindXCTest.cmake
+++ b/Modules/FindXCTest.cmake
@@ -61,6 +61,22 @@ The following variables are set by including this module:
#]=======================================================================]
+set(_PRESERVED_CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH}")
+
+if(CMAKE_EFFECTIVE_SYSTEM_NAME STREQUAL "Apple"
+ AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ # Non-macos systems set the CMAKE_FIND_ROOT_PATH_MODE to "ONLY" which
+ # restricts the search paths too much to find XCTest.framework. In
+ # contrast to the regular system frameworks which reside within the
+ # SDK direectory the XCTest framework is located in the respective
+ # platform directory which is not added to the CMAKE_FIND_ROOT_PATH
+ # (only to CMAKE_SYSTEM_FRAMEWORK_PATH) and therefore not searched.
+ #
+ # Until this is properly addressed, temporaily add the platform
+ # directory to CMAKE_FIND_ROOT_PATH.
+ list(APPEND CMAKE_FIND_ROOT_PATH "${_CMAKE_OSX_SYSROOT_PATH}/../..")
+endif()
+
find_path(XCTest_INCLUDE_DIR
NAMES "XCTest/XCTest.h"
DOC "XCTest include directory")
@@ -71,6 +87,9 @@ find_library(XCTest_LIBRARY
DOC "XCTest Framework library")
mark_as_advanced(XCTest_LIBRARY)
+set(CMAKE_FIND_ROOT_PATH "${_PRESERVED_CMAKE_FIND_ROOT_PATH}")
+unset(_PRESERVED_CMAKE_FIND_ROOT_PATH)
+
execute_process(
COMMAND xcrun --find xctest
OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE
@@ -136,7 +155,7 @@ function(xctest_add_bundle target testee)
XCODE_ATTRIBUTE_TEST_HOST "$<TARGET_FILE:${testee}>")
if(NOT XCODE_VERSION VERSION_LESS 7.3)
set_target_properties(${target} PROPERTIES
- LIBRARY_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:${testee}>/../PlugIns")
+ LIBRARY_OUTPUT_DIRECTORY "$<TARGET_BUNDLE_CONTENT_DIR:${testee}>/PlugIns")
endif()
else(XCODE)
target_link_libraries(${target}
@@ -183,7 +202,7 @@ function(xctest_add_test name bundle)
add_test(
NAME ${name}
- COMMAND ${XCTest_EXECUTABLE} $<TARGET_LINKER_FILE_DIR:${bundle}>/../..)
+ COMMAND ${XCTest_EXECUTABLE} $<TARGET_BUNDLE_DIR:${bundle}>)
# point loader to testee in case rpath is disabled
diff --git a/Modules/FindXMLRPC.cmake b/Modules/FindXMLRPC.cmake
index f0b258397..69e6df22b 100644
--- a/Modules/FindXMLRPC.cmake
+++ b/Modules/FindXMLRPC.cmake
@@ -1,35 +1,36 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.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)
+#]=======================================================================]
# First find the config script from which to obtain other values.
find_program(XMLRPC_C_CONFIG NAMES xmlrpc-c-config)
@@ -43,20 +44,12 @@ endif()
# Lookup the include directories needed for the components requested.
if(XMLRPC_C_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()
+ 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
+ )
# Parse the include flags.
if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
@@ -65,6 +58,7 @@ if(XMLRPC_C_FOUND)
XMLRPC_C_CONFIG_CFLAGS "${XMLRPC_C_CONFIG_CFLAGS}")
# Look for -I options.
+ # FIXME: Use these as hints to a find_path call to find the headers.
set(XMLRPC_INCLUDE_DIRS)
foreach(flag ${XMLRPC_C_CONFIG_CFLAGS})
if("${flag}" MATCHES "^-I(.+)")
@@ -80,20 +74,12 @@ endif()
# Lookup the libraries needed for the components requested.
if(XMLRPC_C_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()
+ 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
+ )
# Parse the library names and directories.
if("${XMLRPC_C_CONFIG_RESULT}" STREQUAL "0")
@@ -139,5 +125,5 @@ endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
XMLRPC
- REQUIRED_VARS XMLRPC_C_FOUND XMLRPC_LIBRARIES XMLRPC_INCLUDE_DIRS
+ REQUIRED_VARS XMLRPC_C_FOUND XMLRPC_LIBRARIES
FAIL_MESSAGE "XMLRPC was not found. Make sure the entries XMLRPC_* are set.")
diff --git a/Modules/FindXalanC.cmake b/Modules/FindXalanC.cmake
index 1951b49e1..3adaa44d3 100644
--- a/Modules/FindXalanC.cmake
+++ b/Modules/FindXalanC.cmake
@@ -1,45 +1,46 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindXalanC
-# -----------
-#
-# Find the Apache Xalan-C++ XSL transform processor headers and libraries.
-#
-# Imported targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following :prop_tgt:`IMPORTED` targets:
-#
-# ``XalanC::XalanC``
-# The Xalan-C++ ``xalan-c`` library, if found.
-#
-# Result variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module will set the following variables in your project:
-#
-# ``XalanC_FOUND``
-# true if the Xalan headers and libraries were found
-# ``XalanC_VERSION``
-# Xalan release version
-# ``XalanC_INCLUDE_DIRS``
-# the directory containing the Xalan headers; note
-# ``XercesC_INCLUDE_DIRS`` is also required
-# ``XalanC_LIBRARIES``
-# Xalan libraries to be linked; note ``XercesC_LIBRARIES`` is also
-# required
-#
-# Cache variables
-# ^^^^^^^^^^^^^^^
-#
-# The following cache variables may also be set:
-#
-# ``XalanC_INCLUDE_DIR``
-# the directory containing the Xalan headers
-# ``XalanC_LIBRARY``
-# the Xalan library
+#[=======================================================================[.rst:
+FindXalanC
+-----------
+
+Find the Apache Xalan-C++ XSL transform processor headers and libraries.
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``XalanC::XalanC``
+ The Xalan-C++ ``xalan-c`` library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``XalanC_FOUND``
+ true if the Xalan headers and libraries were found
+``XalanC_VERSION``
+ Xalan release version
+``XalanC_INCLUDE_DIRS``
+ the directory containing the Xalan headers; note
+ ``XercesC_INCLUDE_DIRS`` is also required
+``XalanC_LIBRARIES``
+ Xalan libraries to be linked; note ``XercesC_LIBRARIES`` is also
+ required
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``XalanC_INCLUDE_DIR``
+ the directory containing the Xalan headers
+``XalanC_LIBRARY``
+ the Xalan library
+#]=======================================================================]
# Written by Roger Leigh <rleigh@codelibre.net>
@@ -75,7 +76,7 @@ find_path(XalanC_INCLUDE_DIR
DOC "Xalan-C++ include directory")
mark_as_advanced(XalanC_INCLUDE_DIR)
-if(XalanC_INCLUDE_DIR)
+if(XalanC_INCLUDE_DIR AND EXISTS "${XalanC_INCLUDE_DIR}/xalanc/Include/XalanVersion.hpp")
_XalanC_GET_VERSION("${XalanC_INCLUDE_DIR}/xalanc/Include/XalanVersion.hpp")
endif()
diff --git a/Modules/FindXercesC.cmake b/Modules/FindXercesC.cmake
index 51e68d599..47bfd6288 100644
--- a/Modules/FindXercesC.cmake
+++ b/Modules/FindXercesC.cmake
@@ -1,43 +1,44 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# FindXercesC
-# -----------
-#
-# Find the Apache Xerces-C++ validating XML parser headers and libraries.
-#
-# Imported targets
-# ^^^^^^^^^^^^^^^^
-#
-# This module defines the following :prop_tgt:`IMPORTED` targets:
-#
-# ``XercesC::XercesC``
-# The Xerces-C++ ``xerces-c`` library, if found.
-#
-# Result variables
-# ^^^^^^^^^^^^^^^^
-#
-# This module will set the following variables in your project:
-#
-# ``XercesC_FOUND``
-# true if the Xerces headers and libraries were found
-# ``XercesC_VERSION``
-# Xerces release version
-# ``XercesC_INCLUDE_DIRS``
-# the directory containing the Xerces headers
-# ``XercesC_LIBRARIES``
-# Xerces libraries to be linked
-#
-# Cache variables
-# ^^^^^^^^^^^^^^^
-#
-# The following cache variables may also be set:
-#
-# ``XercesC_INCLUDE_DIR``
-# the directory containing the Xerces headers
-# ``XercesC_LIBRARY``
-# the Xerces library
+#[=======================================================================[.rst:
+FindXercesC
+-----------
+
+Find the Apache Xerces-C++ validating XML parser headers and libraries.
+
+Imported targets
+^^^^^^^^^^^^^^^^
+
+This module defines the following :prop_tgt:`IMPORTED` targets:
+
+``XercesC::XercesC``
+ The Xerces-C++ ``xerces-c`` library, if found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``XercesC_FOUND``
+ true if the Xerces headers and libraries were found
+``XercesC_VERSION``
+ Xerces release version
+``XercesC_INCLUDE_DIRS``
+ the directory containing the Xerces headers
+``XercesC_LIBRARIES``
+ Xerces libraries to be linked
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``XercesC_INCLUDE_DIR``
+ the directory containing the Xerces headers
+``XercesC_LIBRARY``
+ the Xerces library
+#]=======================================================================]
# Written by Roger Leigh <rleigh@codelibre.net>
@@ -59,6 +60,9 @@ function(_XercesC_GET_VERSION version_hdr)
endif()
set(XercesC_VERSION "${XercesC_MAJOR}.${XercesC_MINOR}.${XercesC_PATCH}" PARENT_SCOPE)
+ set(XercesC_VERSION_MAJOR "${XercesC_MAJOR}" PARENT_SCOPE)
+ set(XercesC_VERSION_MINOR "${XercesC_MINOR}" PARENT_SCOPE)
+ set(XercesC_VERSION_PATCH "${XercesC_PATCH}" PARENT_SCOPE)
else()
message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information")
endif()
@@ -70,22 +74,26 @@ find_path(XercesC_INCLUDE_DIR
DOC "Xerces-C++ include directory")
mark_as_advanced(XercesC_INCLUDE_DIR)
+if(XercesC_INCLUDE_DIR AND EXISTS "${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
+ _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
+endif()
+
if(NOT XercesC_LIBRARY)
# Find all XercesC libraries
find_library(XercesC_LIBRARY_RELEASE
- NAMES "xerces-c" "xerces-c_3"
+ NAMES "xerces-c" "xerces-c_${XercesC_VERSION_MAJOR}"
DOC "Xerces-C++ libraries (release)")
find_library(XercesC_LIBRARY_DEBUG
- NAMES "xerces-cd" "xerces-c_3D" "xerces-c_3_1D"
+ NAMES "xerces-cd" "xerces-c_${XercesC_VERSION_MAJOR}D" "xerces-c_${XercesC_VERSION_MAJOR}_${XercesC_VERSION_MINOR}D"
DOC "Xerces-C++ libraries (debug)")
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
select_library_configurations(XercesC)
mark_as_advanced(XercesC_LIBRARY_RELEASE XercesC_LIBRARY_DEBUG)
endif()
-if(XercesC_INCLUDE_DIR)
- _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
-endif()
+unset(XercesC_VERSION_MAJOR)
+unset(XercesC_VERSION_MINOR)
+unset(XercesC_VERSION_PATCH)
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC
diff --git a/Modules/FindZLIB.cmake b/Modules/FindZLIB.cmake
index 406599949..79e2313d5 100644
--- a/Modules/FindZLIB.cmake
+++ b/Modules/FindZLIB.cmake
@@ -1,53 +1,54 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
set(_ZLIB_SEARCHES)
@@ -58,14 +59,16 @@ if(ZLIB_ROOT)
endif()
# Normal search.
+set(_ZLIB_x86 "(x86)")
set(_ZLIB_SEARCH_NORMAL
- PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
- "$ENV{PROGRAMFILES}/zlib"
- )
+ PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]"
+ "$ENV{ProgramFiles}/zlib"
+ "$ENV{ProgramFiles${_ZLIB_x86}}/zlib")
+unset(_ZLIB_x86)
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
-set(ZLIB_NAMES z zlib zdll zlib1)
-set(ZLIB_NAMES_DEBUG zlibd zlibd1)
+set(ZLIB_NAMES z zlib zdll zlib1 zlibstatic)
+set(ZLIB_NAMES_DEBUG zd zlibd zdlld zlibd1 zlib1d zlibstaticd)
# Try each search configuration.
foreach(search ${_ZLIB_SEARCHES})
@@ -75,8 +78,8 @@ endforeach()
# Allow ZLIB_LIBRARY to be set manually, as the location of the zlib library
if(NOT ZLIB_LIBRARY)
foreach(search ${_ZLIB_SEARCHES})
- find_library(ZLIB_LIBRARY_RELEASE NAMES ${ZLIB_NAMES} ${${search}} PATH_SUFFIXES lib)
- find_library(ZLIB_LIBRARY_DEBUG NAMES ${ZLIB_NAMES_DEBUG} ${${search}} PATH_SUFFIXES lib)
+ find_library(ZLIB_LIBRARY_RELEASE NAMES ${ZLIB_NAMES} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
+ find_library(ZLIB_LIBRARY_DEBUG NAMES ${ZLIB_NAMES_DEBUG} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
endforeach()
include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
diff --git a/Modules/Findosg.cmake b/Modules/Findosg.cmake
index 474ea82b5..027f315cd 100644
--- a/Modules/Findosg.cmake
+++ b/Modules/Findosg.cmake
@@ -1,42 +1,41 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgAnimation.cmake b/Modules/FindosgAnimation.cmake
index 5b26b6485..65e301649 100644
--- a/Modules/FindosgAnimation.cmake
+++ b/Modules/FindosgAnimation.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgDB.cmake b/Modules/FindosgDB.cmake
index 6ddf53ce0..a28f65007 100644
--- a/Modules/FindosgDB.cmake
+++ b/Modules/FindosgDB.cmake
@@ -1,36 +1,45 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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 :module:`FindOpenGL` module doesn't
+work with your system as an example). If you want to use a more
+convenient module that includes everything, use the
+:module:`FindOpenSceneGraph` 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
+
+``OSGDB_LIBRARY``
+ The osgDB library
+
+``OSGDB_LIBRARY_DEBUG``
+ The osgDB debug library
+
+``$OSGDIR`` is an environment variable that would correspond to::
+
+ ./configure --prefix=$OSGDIR used in building osg.
+
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgFX.cmake b/Modules/FindosgFX.cmake
index e4bc276d7..438fab7d5 100644
--- a/Modules/FindosgFX.cmake
+++ b/Modules/FindosgFX.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgGA.cmake b/Modules/FindosgGA.cmake
index 97adeb7af..7b6ef30a2 100644
--- a/Modules/FindosgGA.cmake
+++ b/Modules/FindosgGA.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgIntrospection.cmake b/Modules/FindosgIntrospection.cmake
index e735942c3..625e4c26e 100644
--- a/Modules/FindosgIntrospection.cmake
+++ b/Modules/FindosgIntrospection.cmake
@@ -1,37 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgManipulator.cmake b/Modules/FindosgManipulator.cmake
index b88f1a414..857ff5d57 100644
--- a/Modules/FindosgManipulator.cmake
+++ b/Modules/FindosgManipulator.cmake
@@ -1,37 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgParticle.cmake b/Modules/FindosgParticle.cmake
index 059746a61..91a30dc7e 100644
--- a/Modules/FindosgParticle.cmake
+++ b/Modules/FindosgParticle.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgPresentation.cmake b/Modules/FindosgPresentation.cmake
index 84a410526..eae75d638 100644
--- a/Modules/FindosgPresentation.cmake
+++ b/Modules/FindosgPresentation.cmake
@@ -1,38 +1,39 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgProducer.cmake b/Modules/FindosgProducer.cmake
index e5700bfc4..33b9f7311 100644
--- a/Modules/FindosgProducer.cmake
+++ b/Modules/FindosgProducer.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgQt.cmake b/Modules/FindosgQt.cmake
index 04a2393e5..cf356303c 100644
--- a/Modules/FindosgQt.cmake
+++ b/Modules/FindosgQt.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgShadow.cmake b/Modules/FindosgShadow.cmake
index 0a7ba2379..0049c4e1d 100644
--- a/Modules/FindosgShadow.cmake
+++ b/Modules/FindosgShadow.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgSim.cmake b/Modules/FindosgSim.cmake
index 15426a273..43ba54211 100644
--- a/Modules/FindosgSim.cmake
+++ b/Modules/FindosgSim.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgTerrain.cmake b/Modules/FindosgTerrain.cmake
index 04eae1450..c6f5b690a 100644
--- a/Modules/FindosgTerrain.cmake
+++ b/Modules/FindosgTerrain.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgText.cmake b/Modules/FindosgText.cmake
index 1e2d9fdfd..fd3c2324f 100644
--- a/Modules/FindosgText.cmake
+++ b/Modules/FindosgText.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgUtil.cmake b/Modules/FindosgUtil.cmake
index 13e0b803e..e84727aef 100644
--- a/Modules/FindosgUtil.cmake
+++ b/Modules/FindosgUtil.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgViewer.cmake b/Modules/FindosgViewer.cmake
index a91c49c14..2174357ec 100644
--- a/Modules/FindosgViewer.cmake
+++ b/Modules/FindosgViewer.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgVolume.cmake b/Modules/FindosgVolume.cmake
index 1178ed37d..35defef6b 100644
--- a/Modules/FindosgVolume.cmake
+++ b/Modules/FindosgVolume.cmake
@@ -1,36 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/FindosgWidget.cmake b/Modules/FindosgWidget.cmake
index 78999ec3f..c7aae448e 100644
--- a/Modules/FindosgWidget.cmake
+++ b/Modules/FindosgWidget.cmake
@@ -1,37 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# Header files are presumed to be included like
# #include <osg/PositionAttitudeTransform>
diff --git a/Modules/Findosg_functions.cmake b/Modules/Findosg_functions.cmake
index c81c4485e..563b6bd7a 100644
--- a/Modules/Findosg_functions.cmake
+++ b/Modules/Findosg_functions.cmake
@@ -1,41 +1,38 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
+
+include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
#
# 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
- )
+ 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
+ )
endfunction()
@@ -43,56 +40,38 @@ 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()
+ string(TOUPPER ${module} module_uc)
+
+ find_library(${module_uc}_LIBRARY_RELEASE
+ NAMES ${library}
+ HINTS
+ ENV ${module_uc}_DIR
+ ENV OSG_DIR
+ ENV OSGDIR
+ ENV OSG_ROOT
+ ${${module_uc}_DIR}
+ ${OSG_DIR}
+ PATH_SUFFIXES lib
+ )
+
+ 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
+ )
+
+ select_library_configurations(${module_uc})
+
+ # the variables set by select_library_configurations go out of scope
+ # here, so we need to set them again
+ set(${module_uc}_LIBRARY ${${module_uc}_LIBRARY} PARENT_SCOPE)
+ set(${module_uc}_LIBRARIES ${${module_uc}_LIBRARIES} PARENT_SCOPE)
endfunction()
#
@@ -100,8 +79,8 @@ endfunction()
# 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)
+ 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
index af4daf061..c813ead47 100644
--- a/Modules/FindwxWidgets.cmake
+++ b/Modules/FindwxWidgets.cmake
@@ -1,111 +1,112 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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})
+#[=======================================================================[.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 ... OPTIONAL_COMPONENTS net ...)
+
+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 gl core base OPTIONAL_COMPONENTS net)
+ 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 gl core base OPTIONAL_COMPONENTS net)
+ include(${wxWidgets_USE_FILE})
+ # and for each of your dependent executable/library targets:
+ target_link_libraries(<YourTarget> ${wxWidgets_LIBRARIES})
+#]=======================================================================]
#
# FIXME: check this and provide a correct sample usage...
@@ -396,6 +397,9 @@ if(wxWidgets_FIND_STYLE STREQUAL "win32")
list(APPEND wxWidgets_LIBRARIES
debug ${WX_${LIB}d} optimized ${WX_${LIB}}
)
+ set(wxWidgets_${LIB}_FOUND TRUE)
+ elseif(NOT wxWidgets_FIND_REQUIRED_${LIB})
+ DBG_MSG_V("- ignored optional missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
else()
DBG_MSG_V("- not found due to missing WX_${LIB}=${WX_${LIB}} or WX_${LIB}d=${WX_${LIB}d}")
set(wxWidgets_FOUND FALSE)
@@ -408,9 +412,11 @@ if(wxWidgets_FIND_STYLE STREQUAL "win32")
if(WX_${LIB}${_DBG})
DBG_MSG_V("Found ${LIB}${_DBG}")
list(APPEND wxWidgets_LIBRARIES ${WX_${LIB}${_DBG}})
+ set(wxWidgets_${LIB}_FOUND TRUE)
+ elseif(NOT wxWidgets_FIND_REQUIRED_${LIB})
+ DBG_MSG_V("- ignored optional missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
else()
- DBG_MSG_V(
- "- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
+ DBG_MSG_V("- not found due to missing WX_${LIB}${_DBG}=${WX_${LIB}${_DBG}}")
set(wxWidgets_FOUND FALSE)
endif()
endforeach()
@@ -498,19 +504,7 @@ if(wxWidgets_FIND_STYLE STREQUAL "win32")
set(_WX_TOOL gcc)
elseif(MSVC)
set(_WX_TOOL vc)
- if(MSVC_VERSION EQUAL 1910)
- set(_WX_TOOLVER 141)
- elseif(MSVC_VERSION EQUAL 1900)
- set(_WX_TOOLVER 140)
- elseif(MSVC_VERSION EQUAL 1800)
- set(_WX_TOOLVER 120)
- elseif(MSVC_VERSION EQUAL 1700)
- set(_WX_TOOLVER 110)
- elseif(MSVC_VERSION EQUAL 1600)
- set(_WX_TOOLVER 100)
- elseif(MSVC_VERSION EQUAL 1500)
- set(_WX_TOOLVER 90)
- endif()
+ set(_WX_TOOLVER ${MSVC_TOOLSET_VERSION})
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_WX_ARCH _x64)
endif()
@@ -527,8 +521,10 @@ if(wxWidgets_FIND_STYLE STREQUAL "win32")
mswunivu/wx/setup.h
mswunivud/wx/setup.h
PATHS
+ ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_dll # prefer shared
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_dll # prefer shared
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_dll # prefer shared
+ ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_lib
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_lib
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_lib
DOC "Path to wxWidgets libraries"
@@ -546,8 +542,10 @@ if(wxWidgets_FIND_STYLE STREQUAL "win32")
mswunivu/wx/setup.h
mswunivud/wx/setup.h
PATHS
+ ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_lib # prefer static
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_lib # prefer static
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_lib # prefer static
+ ${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}_xp${_WX_ARCH}_dll
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_TOOLVER}${_WX_ARCH}_dll
${WX_ROOT_DIR}/lib/${_WX_TOOL}${_WX_ARCH}_dll
DOC "Path to wxWidgets libraries"
@@ -747,7 +745,7 @@ else()
#-----------------------------------------------------------------
# Support cross-compiling, only search in the target platform.
find_program(wxWidgets_CONFIG_EXECUTABLE
- NAMES wx-config wx-config-3.1 wx-config-3.0 wx-config-2.9 wx-config-2.8
+ NAMES $ENV{WX_CONFIG} wx-config wx-config-3.1 wx-config-3.0 wx-config-2.9 wx-config-2.8
DOC "Location of wxWidgets library configuration provider binary (wx-config)."
ONLY_CMAKE_FIND_ROOT_PATH
)
@@ -778,28 +776,24 @@ else()
)
if(RET EQUAL 0)
string(STRIP "${wxWidgets_CXX_FLAGS}" wxWidgets_CXX_FLAGS)
- separate_arguments(wxWidgets_CXX_FLAGS)
+ separate_arguments(wxWidgets_CXX_FLAGS_LIST NATIVE_COMMAND "${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}")
+ # parse definitions and include dirs from cxxflags
+ # drop the -D and -I prefixes
+ set(wxWidgets_CXX_FLAGS)
+ foreach(arg IN LISTS wxWidgets_CXX_FLAGS_LIST)
+ if("${arg}" MATCHES "^-I(.*)$")
+ # include directory
+ list(APPEND wxWidgets_INCLUDE_DIRS "${CMAKE_MATCH_1}")
+ elseif("${arg}" MATCHES "^-D(.*)$")
+ # compile definition
+ list(APPEND wxWidgets_DEFINITIONS "${CMAKE_MATCH_1}")
+ else()
+ list(APPEND wxWidgets_CXX_FLAGS "${arg}")
+ endif()
+ endforeach()
DBG_MSG_V("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}")
DBG_MSG_V("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}")
@@ -815,11 +809,24 @@ else()
# - 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}")
+ unset(_cmp_req)
+ unset(_cmp_opt)
+ foreach(_cmp IN LISTS wxWidgets_FIND_COMPONENTS)
+ if(wxWidgets_FIND_REQUIRED_${_cmp})
+ list(APPEND _cmp_req "${_cmp}")
+ else()
+ list(APPEND _cmp_opt "${_cmp}")
+ endif()
+ endforeach()
+ DBG_MSG_V("wxWidgets required components : ${_cmp_req}")
+ DBG_MSG_V("wxWidgets optional components : ${_cmp_opt}")
+ if(DEFINED _cmp_opt)
+ string(REPLACE ";" "," _cmp_opt "--optional-libs ${_cmp_opt}")
+ endif()
+ string(REPLACE ";" "," _cmp_req "${_cmp_req}")
execute_process(
COMMAND sh "${wxWidgets_CONFIG_EXECUTABLE}"
- ${wxWidgets_SELECT_OPTIONS} --libs ${wxWidgets_FIND_COMPONENTS}
+ ${wxWidgets_SELECT_OPTIONS} --libs ${_cmp_req} ${_cmp_opt}
OUTPUT_VARIABLE wxWidgets_LIBRARIES
RESULT_VARIABLE RET
ERROR_QUIET
@@ -837,7 +844,7 @@ else()
# extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
string(REGEX MATCHALL "-L[^;]+"
wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARIES}")
- string(REPLACE "-L" ""
+ string(REGEX REPLACE "-L([^;]+)" "\\1"
wxWidgets_LIBRARY_DIRS "${wxWidgets_LIBRARY_DIRS}")
DBG_MSG_V("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}")
@@ -845,8 +852,10 @@ else()
else()
set(wxWidgets_FOUND FALSE)
- DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${wxWidgets_FIND_COMPONENTS} FAILED with RET=${RET}")
+ DBG_MSG("${wxWidgets_CONFIG_EXECUTABLE} --libs ${_cmp_req} ${_cmp_opt} FAILED with RET=${RET}")
endif()
+ unset(_cmp_req)
+ unset(_cmp_opt)
endif()
# When using wx-config in MSYS, the include paths are UNIX style paths which may or may
@@ -875,6 +884,26 @@ else()
set(wxWidgets_INCLUDE_DIRS ${_tmp_path})
separate_arguments(wxWidgets_INCLUDE_DIRS)
list(REMOVE_ITEM wxWidgets_INCLUDE_DIRS "")
+
+ set(_tmp_path "")
+ foreach(_path ${wxWidgets_LIBRARY_DIRS})
+ execute_process(
+ COMMAND cygpath -w ${_path}
+ OUTPUT_VARIABLE _native_path
+ RESULT_VARIABLE _retv
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_QUIET
+ )
+ if(_retv EQUAL 0)
+ file(TO_CMAKE_PATH ${_native_path} _native_path)
+ DBG_MSG_V("Path ${_path} converted to ${_native_path}")
+ string(APPEND _tmp_path " ${_native_path}")
+ endif()
+ endforeach()
+ DBG_MSG("Setting wxWidgets_LIBRARY_DIRS = ${_tmp_path}")
+ set(wxWidgets_LIBRARY_DIRS ${_tmp_path})
+ separate_arguments(wxWidgets_LIBRARY_DIRS)
+ list(REMOVE_ITEM wxWidgets_LIBRARY_DIRS "")
endif()
unset(_cygpath_exe CACHE)
endif()
@@ -915,16 +944,18 @@ if (_wx_lib_missing)
endif()
unset(_wx_lib_missing)
-# Check if a specfic version was requested by find_package().
+# Check if a specific version was requested by find_package().
if(wxWidgets_FOUND)
- find_file(_filename wx/version.h PATHS ${wxWidgets_INCLUDE_DIRS} NO_DEFAULT_PATH)
- dbg_msg("_filename: ${_filename}")
+ unset(_wx_filename)
+ find_file(_wx_filename wx/version.h PATHS ${wxWidgets_INCLUDE_DIRS} NO_DEFAULT_PATH)
+ dbg_msg("_wx_filename: ${_wx_filename}")
- if(NOT _filename)
+ if(NOT _wx_filename)
message(FATAL_ERROR "wxWidgets wx/version.h file not found in ${wxWidgets_INCLUDE_DIRS}.")
endif()
- file(READ ${_filename} _wx_version_h)
+ file(READ "${_wx_filename}" _wx_version_h)
+ unset(_wx_filename CACHE)
string(REGEX REPLACE "^(.*\n)?#define +wxMAJOR_VERSION +([0-9]+).*"
"\\2" wxWidgets_VERSION_MAJOR "${_wx_version_h}" )
@@ -950,10 +981,18 @@ DBG_MSG("wxWidgets_USE_FILE : ${wxWidgets_USE_FILE}")
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
+# FIXME: set wxWidgets_<comp>_FOUND for wx-config branch
+# and use HANDLE_COMPONENTS on Unix too
+if(wxWidgets_FIND_STYLE STREQUAL "win32")
+ set(wxWidgets_HANDLE_COMPONENTS "HANDLE_COMPONENTS")
+endif()
+
find_package_handle_standard_args(wxWidgets
REQUIRED_VARS wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS
VERSION_VAR wxWidgets_VERSION_STRING
+ ${wxWidgets_HANDLE_COMPONENTS}
)
+unset(wxWidgets_HANDLE_COMPONENTS)
#=====================================================================
# Macros for use in wxWidgets apps.
@@ -964,8 +1003,9 @@ find_package_handle_standard_args(wxWidgets
#=====================================================================
# Resource file compiler.
-find_program(wxWidgets_wxrc_EXECUTABLE wxrc
- ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
+find_program(wxWidgets_wxrc_EXECUTABLE
+ NAMES $ENV{WXRC_CMD} wxrc
+ PATHS ${wxWidgets_ROOT_DIR}/utils/wxrc/vc_msw
DOC "Location of wxWidgets resource file compiler binary (wxrc)"
)
diff --git a/Modules/FindwxWindows.cmake b/Modules/FindwxWindows.cmake
index 76eb6be47..35840f5f9 100644
--- a/Modules/FindwxWindows.cmake
+++ b/Modules/FindwxWindows.cmake
@@ -1,84 +1,87 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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)
+#[=======================================================================[.rst:
+FindwxWindows
+-------------
+
+.. deprecated:: 3.0
+
+ Replaced by :module:`FindwxWidgets`.
+
+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. 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)
+#]=======================================================================]
# ------------------------------------------------------------------
#
@@ -390,7 +393,7 @@ if(WIN32_STYLE_FIND)
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)
+ ## these ones don't seem required, in particular ctl3d32 is not necessary (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}
@@ -546,7 +549,7 @@ if(WIN32_STYLE_FIND)
endif()
- ## not neccessary in wxWindows 2.4.1 and 2.6.2
+ ## not necessary 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)
@@ -617,7 +620,8 @@ else()
# 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
+ find_program(CMAKE_WXWINDOWS_WXCONFIG_EXECUTABLE
+ NAMES $ENV{WX_CONFIG} wx-config
HINTS
ENV WXWIN
$ENV{WXWIN}/bin
diff --git a/Modules/FortranCInterface/CMakeLists.txt b/Modules/FortranCInterface/CMakeLists.txt
index e3b81d7c3..381080bba 100644
--- a/Modules/FortranCInterface/CMakeLists.txt
+++ b/Modules/FortranCInterface/CMakeLists.txt
@@ -15,11 +15,11 @@ int main() { return 0; }
# List manglings of global symbol names to try.
set(global_symbols
my_sub # VisualAge
- my_sub_ # GNU, Intel, HP, SunPro, MIPSpro, PGI
+ my_sub_ # GNU, Intel, HP, SunPro, PGI
my_sub__ # GNU g77
MY_SUB # Intel on Windows
mysub # VisualAge
- mysub_ # GNU, Intel, HP, SunPro, MIPSpro, PGI
+ mysub_ # GNU, Intel, HP, SunPro, PGI
MYSUB # Intel on Windows
${FortranCInterface_GLOBAL_SYMBOLS}
)
@@ -48,7 +48,6 @@ set(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"
diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake
index 64bd09e68..4db4e18fd 100644
--- a/Modules/GNUInstallDirs.cmake
+++ b/Modules/GNUInstallDirs.cmake
@@ -1,127 +1,131 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# GNUInstallDirs
-# --------------
-#
-# Define GNU standard installation directories
-#
-# Provides install directory variables as defined by the
-# `GNU Coding Standards`_.
-#
-# .. _`GNU Coding Standards`: https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
-#
-# Result Variables
-# ^^^^^^^^^^^^^^^^
-#
-# Inclusion of this module defines the following variables:
-#
-# ``CMAKE_INSTALL_<dir>``
-#
-# Destination for files of a given type. This value may be passed to
-# the ``DESTINATION`` options of :command:`install` commands for the
-# corresponding file type.
-#
-# ``CMAKE_INSTALL_FULL_<dir>``
-#
-# The absolute path generated from the corresponding ``CMAKE_INSTALL_<dir>``
-# value. If the value is not already an absolute path, an absolute path
-# is constructed typically by prepending the value of the
-# :variable:`CMAKE_INSTALL_PREFIX` variable. However, there are some
-# `special cases`_ as documented below.
-#
-# 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``)
-# ``RUNSTATEDIR``
-# run-time variable data (``LOCALSTATEDIR/run``)
-# ``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``)
-#
-# 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.
-#
-# Special Cases
-# ^^^^^^^^^^^^^
-#
-# The following values of :variable:`CMAKE_INSTALL_PREFIX` are special:
-#
-# ``/``
-#
-# For ``<dir>`` other than the ``SYSCONFDIR``, ``LOCALSTATEDIR`` and
-# ``RUNSTATEDIR``, the value of ``CMAKE_INSTALL_<dir>`` is prefixed
-# with ``usr/`` if it is not user-specified as an absolute path.
-# For example, the ``INCLUDEDIR`` value ``include`` becomes ``usr/include``.
-# This is required by the `GNU Coding Standards`_, which state:
-#
-# When building the complete GNU system, the prefix will be empty
-# and ``/usr`` will be a symbolic link to ``/``.
-#
-# ``/usr``
-#
-# For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
-# ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
-# prepending just ``/`` to the value of ``CMAKE_INSTALL_<dir>``
-# if it is not user-specified as an absolute path.
-# For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc``.
-# This is required by the `GNU Coding Standards`_.
-#
-# ``/opt/...``
-#
-# For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
-# ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
-# *appending* the prefix to the value of ``CMAKE_INSTALL_<dir>``
-# if it is not user-specified as an absolute path.
-# For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc/opt/...``.
-# This is defined by the `Filesystem Hierarchy Standard`_.
-#
-# .. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
-#
-# Macros
-# ^^^^^^
-#
-# .. command:: GNUInstallDirs_get_absolute_install_dir
-#
-# ::
-#
-# GNUInstallDirs_get_absolute_install_dir(absvar var)
-#
-# Set the given variable ``absvar`` to the absolute path contained
-# within the variable ``var``. This is to allow the computation of an
-# absolute path, accounting for all the special cases documented
-# above. While this macro is used to compute the various
-# ``CMAKE_INSTALL_FULL_<dir>`` variables, it is exposed publicly to
-# allow users who create additional path variables to also compute
-# absolute paths where necessary, using the same logic.
+#[=======================================================================[.rst:
+GNUInstallDirs
+--------------
+
+Define GNU standard installation directories
+
+Provides install directory variables as defined by the
+`GNU Coding Standards`_.
+
+.. _`GNU Coding Standards`: https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+Inclusion of this module defines the following variables:
+
+``CMAKE_INSTALL_<dir>``
+
+ Destination for files of a given type. This value may be passed to
+ the ``DESTINATION`` options of :command:`install` commands for the
+ corresponding file type.
+
+``CMAKE_INSTALL_FULL_<dir>``
+
+ The absolute path generated from the corresponding ``CMAKE_INSTALL_<dir>``
+ value. If the value is not already an absolute path, an absolute path
+ is constructed typically by prepending the value of the
+ :variable:`CMAKE_INSTALL_PREFIX` variable. However, there are some
+ `special cases`_ as documented below.
+
+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``)
+``RUNSTATEDIR``
+ run-time variable data (``LOCALSTATEDIR/run``)
+``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``)
+
+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.
+
+Special Cases
+^^^^^^^^^^^^^
+
+The following values of :variable:`CMAKE_INSTALL_PREFIX` are special:
+
+``/``
+
+ For ``<dir>`` other than the ``SYSCONFDIR``, ``LOCALSTATEDIR`` and
+ ``RUNSTATEDIR``, the value of ``CMAKE_INSTALL_<dir>`` is prefixed
+ with ``usr/`` if it is not user-specified as an absolute path.
+ For example, the ``INCLUDEDIR`` value ``include`` becomes ``usr/include``.
+ This is required by the `GNU Coding Standards`_, which state:
+
+ When building the complete GNU system, the prefix will be empty
+ and ``/usr`` will be a symbolic link to ``/``.
+
+``/usr``
+
+ For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
+ ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
+ prepending just ``/`` to the value of ``CMAKE_INSTALL_<dir>``
+ if it is not user-specified as an absolute path.
+ For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc``.
+ This is required by the `GNU Coding Standards`_.
+
+``/opt/...``
+
+ For ``<dir>`` equal to ``SYSCONFDIR``, ``LOCALSTATEDIR`` or
+ ``RUNSTATEDIR``, the ``CMAKE_INSTALL_FULL_<dir>`` is computed by
+ *appending* the prefix to the value of ``CMAKE_INSTALL_<dir>``
+ if it is not user-specified as an absolute path.
+ For example, the ``SYSCONFDIR`` value ``etc`` becomes ``/etc/opt/...``.
+ This is defined by the `Filesystem Hierarchy Standard`_.
+
+.. _`Filesystem Hierarchy Standard`: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
+
+Macros
+^^^^^^
+
+.. command:: GNUInstallDirs_get_absolute_install_dir
+
+ ::
+
+ GNUInstallDirs_get_absolute_install_dir(absvar var)
+
+ Set the given variable ``absvar`` to the absolute path contained
+ within the variable ``var``. This is to allow the computation of an
+ absolute path, accounting for all the special cases documented
+ above. While this macro is used to compute the various
+ ``CMAKE_INSTALL_FULL_<dir>`` variables, it is exposed publicly to
+ allow users who create additional path variables to also compute
+ absolute paths where necessary, using the same logic.
+#]=======================================================================]
+
+cmake_policy(PUSH)
+cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
# Convert a cache variable to PATH type
@@ -202,7 +206,7 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR OR (_libdir_set
# - 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
+ # reason is: amd64 ABI: https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI
# 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"
@@ -273,14 +277,18 @@ _GNUInstallDirs_cache_path(CMAKE_INSTALL_DATAROOTDIR "share"
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_DATADIR "${CMAKE_INSTALL_DATAROOTDIR}"
"Read-only architecture-independent data (DATAROOTDIR)")
-if(CMAKE_SYSTEM_NAME MATCHES "^(.*BSD|DragonFly)$")
+if(CMAKE_SYSTEM_NAME MATCHES "^(([^kF].*)?BSD|DragonFly)$")
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_INFODIR "info"
"Info documentation (info)")
- _GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_MANDIR "man"
- "Man documentation (man)")
else()
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_INFODIR "${CMAKE_INSTALL_DATAROOTDIR}/info"
"Info documentation (DATAROOTDIR/info)")
+endif()
+
+if(CMAKE_SYSTEM_NAME MATCHES "^(([^k].*)?BSD|DragonFly)$")
+ _GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_MANDIR "man"
+ "Man documentation (man)")
+else()
_GNUInstallDirs_cache_path_fallback(CMAKE_INSTALL_MANDIR "${CMAKE_INSTALL_DATAROOTDIR}/man"
"Man documentation (DATAROOTDIR/man)")
endif()
@@ -371,3 +379,5 @@ foreach(dir
)
GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_${dir} CMAKE_INSTALL_${dir})
endforeach()
+
+cmake_policy(POP)
diff --git a/Modules/GenerateExportHeader.cmake b/Modules/GenerateExportHeader.cmake
index 4573c2e77..e4481f66d 100644
--- a/Modules/GenerateExportHeader.cmake
+++ b/Modules/GenerateExportHeader.cmake
@@ -1,189 +1,192 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>]
-# [CUSTOM_CONTENT_FROM_VARIABLE <variable>]
-# )
-#
-#
-# 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``.
-# They will be followed by content taken from the variable specified by
-# the ``CUSTOM_CONTENT_FROM_VARIABLE`` option, if any.
-# 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 specifying 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.
+#[=======================================================================[.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>]
+ [INCLUDE_GUARD_NAME <include_guard_name>]
+ [STATIC_DEFINE <static_define>]
+ [NO_DEPRECATED_MACRO_NAME <no_deprecated_macro_name>]
+ [DEFINE_NO_DEPRECATED]
+ [PREFIX_NAME <prefix_name>]
+ [CUSTOM_CONTENT_FROM_VARIABLE <variable>]
+ )
+
+
+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``.
+They will be followed by content taken from the variable specified by
+the ``CUSTOM_CONTENT_FROM_VARIABLE`` option, if any.
+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 specifying 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.
+#]=======================================================================]
+
+include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
# TODO: Install this macro separately?
@@ -193,6 +196,13 @@ macro(_check_cxx_compiler_attribute _ATTRIBUTE _RESULT)
)
endmacro()
+# TODO: Install this macro separately?
+macro(_check_c_compiler_attribute _ATTRIBUTE _RESULT)
+ check_c_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")
@@ -212,9 +222,15 @@ macro(_test_compiler_hidden_visibility)
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)
+ if (CMAKE_CXX_COMPILER_LOADED)
+ check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
+ check_cxx_compiler_flag(-fvisibility-inlines-hidden
+ COMPILER_HAS_HIDDEN_INLINE_VISIBILITY)
+ else()
+ check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY)
+ check_c_compiler_flag(-fvisibility-inlines-hidden
+ COMPILER_HAS_HIDDEN_INLINE_VISIBILITY)
+ endif()
endif()
endmacro()
@@ -231,14 +247,27 @@ macro(_test_compiler_has_deprecated)
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")
+ if (CMAKE_CXX_COMPILER_LOADED)
+ _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()
else()
- _check_cxx_compiler_attribute("__declspec(deprecated)"
- COMPILER_HAS_DEPRECATED)
+ _check_c_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_c_compiler_attribute("__declspec(deprecated)"
+ COMPILER_HAS_DEPRECATED)
+ endif()
+
endif()
endif()
endmacro()
@@ -277,7 +306,7 @@ macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY)
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 CUSTOM_CONTENT_FROM_VARIABLE)
+ NO_DEPRECATED_MACRO_NAME CUSTOM_CONTENT_FROM_VARIABLE INCLUDE_GUARD_NAME)
set(multiValueArgs)
cmake_parse_arguments(_GEH "${options}" "${oneValueArgs}" "${multiValueArgs}"
@@ -341,7 +370,11 @@ macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY)
endif()
string(MAKE_C_IDENTIFIER ${NO_DEPRECATED_MACRO_NAME} NO_DEPRECATED_MACRO_NAME)
- set(INCLUDE_GUARD_NAME "${EXPORT_MACRO_NAME}_H")
+ if(_GEH_INCLUDE_GUARD_NAME)
+ set(INCLUDE_GUARD_NAME ${_GEH_INCLUDE_GUARD_NAME})
+ else()
+ set(INCLUDE_GUARD_NAME "${EXPORT_MACRO_NAME}_H")
+ endif()
get_target_property(EXPORT_IMPORT_CONDITION ${TARGET_LIBRARY} DEFINE_SYMBOL)
diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake
index 4e52cb300..5be467621 100644
--- a/Modules/GetPrerequisites.cmake
+++ b/Modules/GetPrerequisites.cmake
@@ -1,181 +1,179 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+GetPrerequisites
+----------------
-function(gp_append_unique list_var value)
- set(contains 0)
+Functions to analyze and list executable file prerequisites.
- foreach(item ${${list_var}})
- if(item STREQUAL "${value}")
- set(contains 1)
- break()
- endif()
- endforeach()
+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:
- if(NOT contains)
+::
+
+ 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...
+
+The variable GET_PREREQUISITES_VERBOSE can be set to true to enable verbose
+output.
+
+::
+
+ 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
+#]=======================================================================]
+
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
+function(gp_append_unique list_var value)
+ if(NOT value IN_LIST ${list_var})
set(${list_var} ${${list_var}} "${value}" PARENT_SCOPE)
endif()
endfunction()
@@ -275,7 +273,6 @@ function(gp_item_default_embedded_path item default_embedded_path_var)
# 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:
@@ -294,20 +291,11 @@ function(gp_item_default_embedded_path item default_embedded_path_var)
#
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):
+ # Embed frameworks and .dylibs in the embedded "Frameworks" directory
+ # (sibling of MacOS):
#
- if(NOT overridden)
- if(item MATCHES "[^/]+\\.framework/")
- set(path "@executable_path/../Frameworks")
- set(overridden 1)
- endif()
+ if(item MATCHES "[^/]+\\.framework/" OR item MATCHES "\\.dylib$")
+ set(path "@executable_path/../Frameworks")
endif()
endif()
@@ -653,12 +641,24 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
set(rpaths "")
endif()
+ if(GET_PREREQUISITES_VERBOSE)
+ set(verbose 1)
+ endif()
+
if(NOT IS_ABSOLUTE "${target}")
message("warning: target '${target}' is not absolute...")
endif()
if(NOT EXISTS "${target}")
message("warning: target '${target}' does not exist...")
+ return()
+ endif()
+
+ # Check for a script by extension (.bat,.sh,...) or if the file starts with "#!" (shebang)
+ file(READ ${target} file_contents LIMIT 5)
+ if(target MATCHES "\\.(bat|c?sh|bash|ksh|cmd)$" OR file_contents MATCHES "^#!")
+ message(STATUS "GetPrequisites(${target}) : ignoring script file")
+ # Clear var
set(${prerequisites_var} "" PARENT_SCOPE)
return()
endif()
@@ -688,8 +688,6 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
"$ENV{VS71COMNTOOLS}/../../VC7/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>
@@ -723,25 +721,25 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
set(gp_cmd_maybe_filter) # optional command to pre-filter gp_tool results
- if(gp_tool STREQUAL "ldd")
+ if(gp_tool MATCHES "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)
- elseif(gp_tool STREQUAL "otool")
+ elseif(gp_tool MATCHES "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)
- elseif(gp_tool STREQUAL "dumpbin")
+ elseif(gp_tool MATCHES "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)
- elseif(gp_tool STREQUAL "objdump")
+ elseif(gp_tool MATCHES "objdump$")
set(gp_cmd_args "-p")
set(gp_regex "^\t*DLL Name: (.*\\.[Dd][Ll][Ll])${eol_char}$")
set(gp_regex_error "")
@@ -764,7 +762,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
endif()
- if(gp_tool STREQUAL "dumpbin")
+ if(gp_tool MATCHES "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
@@ -793,7 +791,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
#
# </setup-gp_tool-vars>
- if(gp_tool STREQUAL "ldd")
+ if(gp_tool MATCHES "ldd$")
set(old_ld_env "$ENV{LD_LIBRARY_PATH}")
set(new_ld_env "${exepath}")
foreach(dir ${dirs})
@@ -818,7 +816,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
ERROR_VARIABLE gp_ev
)
- if(gp_tool STREQUAL "dumpbin")
+ if(gp_tool MATCHES "dumpbin$")
# Exclude delay load dependencies under windows (they are listed in dumpbin output after the message below)
string(FIND "${gp_cmd_ov}" "Image has the following delay load dependencies" gp_delayload_pos)
if (${gp_delayload_pos} GREATER -1)
@@ -832,7 +830,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
endif()
if(NOT gp_rv STREQUAL "0")
- if(gp_tool STREQUAL "dumpbin")
+ if(gp_tool MATCHES "dumpbin$")
# dumpbin error messages seem to go to stdout
message(FATAL_ERROR "${gp_cmd} failed: ${gp_rv}\n${gp_ev}\n${gp_cmd_ov}")
else()
@@ -840,7 +838,7 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
endif()
endif()
- if(gp_tool STREQUAL "ldd")
+ if(gp_tool MATCHES "ldd$")
set(ENV{LD_LIBRARY_PATH} "${old_ld_env}")
endif()
@@ -860,9 +858,9 @@ function(get_prerequisites target prerequisites_var exclude_system recurse exepa
# 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")
+ if(gp_tool MATCHES "otool$")
execute_process(
- COMMAND otool -D ${target}
+ COMMAND ${gp_cmd} -D ${target}
RESULT_VARIABLE otool_rv
OUTPUT_VARIABLE gp_install_id_ov
ERROR_VARIABLE otool_ev
@@ -1039,3 +1037,5 @@ function(list_prerequisites_by_glob glob_arg glob_exp)
endif()
endforeach()
endfunction()
+
+cmake_policy(POP)
diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake
index 7415e0681..a5bb86360 100644
--- a/Modules/GoogleTest.cmake
+++ b/Modules/GoogleTest.cmake
@@ -5,7 +5,33 @@
GoogleTest
----------
-This module defines functions to help use the Google Test infrastructure.
+This module defines functions to help use the Google Test infrastructure. Two
+mechanisms for adding tests are provided. :command:`gtest_add_tests` has been
+around for some time, originally via ``find_package(GTest)``.
+:command:`gtest_discover_tests` was introduced in CMake 3.10.
+
+The (older) :command:`gtest_add_tests` scans source files to identify tests.
+This is usually effective, with some caveats, including in cross-compiling
+environments, and makes setting additional properties on tests more convenient.
+However, its handling of parameterized tests is less comprehensive, and it
+requires re-running CMake to detect changes to the list of tests.
+
+The (newer) :command:`gtest_discover_tests` discovers tests by asking the
+compiled test executable to enumerate its tests. This is more robust and
+provides better handling of parameterized tests, and does not require CMake
+to be re-run when tests change. However, it may not work in a cross-compiling
+environment, and setting test properties is less convenient.
+
+More details can be found in the documentation of the respective functions.
+
+Both commands are intended to replace use of :command:`add_test` to register
+tests, and will create a separate CTest test for each Google Test test case.
+Note that this is in some cases less efficient, as common set-up and tear-down
+logic cannot be shared by multiple test cases executing in the same instance.
+However, it provides more fine-grained pass/fail information to CTest, which is
+usually considered as more beneficial. By default, the CTest test name is the
+same as the Google Test name (i.e. ``suite.testcase``); see also
+``TEST_PREFIX`` and ``TEST_SUFFIX``.
.. command:: gtest_add_tests
@@ -22,12 +48,25 @@ This module defines functions to help use the Google Test infrastructure.
[TEST_LIST outVar]
)
+ ``gtest_add_tests`` attempts to identify tests by scanning source files.
+ Although this is generally effective, it uses only a basic regular expression
+ match, which can be defeated by atypical test declarations, and is unable to
+ fully "split" parameterized tests. Additionally, it requires that CMake be
+ re-run to discover any newly added, removed or renamed tests (by default,
+ this means that CMake is re-run when any test source file is changed, but see
+ ``SKIP_DEPENDENCY``). However, it has the advantage of declaring tests at
+ CMake time, which somewhat simplifies setting additional properties on tests,
+ and always works in a cross-compiling environment.
+
+ The options are:
+
``TARGET target``
- This must be a known CMake target. CMake will substitute the location of
- the built executable when running the test.
+ Specifies the Google Test executable, which must be a known CMake
+ executable target. CMake will substitute the location of the built
+ executable when running the test.
``SOURCES src1...``
- When provided, only the listed files will be scanned for test cases. If
+ When provided, only the listed files will be scanned for test cases. If
this option is not given, the :prop_tgt:`SOURCES` property of the
specified ``target`` will be used to obtain the list of sources.
@@ -35,31 +74,30 @@ This module defines functions to help use the Google Test infrastructure.
Any extra arguments to pass on the command line to each test case.
``WORKING_DIRECTORY dir``
- Specifies the directory in which to run the discovered test cases. If this
+ Specifies the directory in which to run the discovered test cases. If this
option is not provided, the current binary directory is used.
``TEST_PREFIX prefix``
- Allows the specified ``prefix`` to be prepended to the name of each
- discovered test case. This can be useful when the same source files are
- being used in multiple calls to ``gtest_add_test()`` but with different
- ``EXTRA_ARGS``.
+ Specifies a ``prefix`` to be prepended to the name of each discovered test
+ case. This can be useful when the same source files are being used in
+ multiple calls to ``gtest_add_test()`` but with different ``EXTRA_ARGS``.
``TEST_SUFFIX suffix``
Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of
- every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` can be
- specified.
+ every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may
+ be specified.
``SKIP_DEPENDENCY``
Normally, the function creates a dependency which will cause CMake to be
- re-run if any of the sources being scanned are changed. This is to ensure
- that the list of discovered tests is updated. If this behavior is not
+ re-run if any of the sources being scanned are changed. This is to ensure
+ that the list of discovered tests is updated. If this behavior is not
desired (as may be the case while actually writing the test cases), this
option can be used to prevent the dependency from being added.
``TEST_LIST outVar``
The variable named by ``outVar`` will be populated in the calling scope
- with the list of discovered test cases. This allows the caller to do things
- like manipulate test properties of the discovered tests.
+ with the list of discovered test cases. This allows the caller to do
+ things like manipulate test properties of the discovered tests.
.. code-block:: cmake
@@ -77,7 +115,7 @@ This module defines functions to help use the Google Test infrastructure.
set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10)
set_tests_properties(${withArgsTests} PROPERTIES TIMEOUT 20)
- For backward compatibility reasons, the following form is also supported::
+ For backward compatibility, the following form is also supported::
gtest_add_tests(exe args files...)
@@ -99,8 +137,112 @@ This module defines functions to help use the Google Test infrastructure.
add_executable(FooTest FooUnitTest.cxx)
gtest_add_tests(FooTest "${FooTestArgs}" AUTO)
+.. command:: gtest_discover_tests
+
+ Automatically add tests with CTest by querying the compiled test executable
+ for available tests::
+
+ gtest_discover_tests(target
+ [EXTRA_ARGS arg1...]
+ [WORKING_DIRECTORY dir]
+ [TEST_PREFIX prefix]
+ [TEST_SUFFIX suffix]
+ [NO_PRETTY_TYPES] [NO_PRETTY_VALUES]
+ [PROPERTIES name1 value1...]
+ [TEST_LIST var]
+ [DISCOVERY_TIMEOUT seconds]
+ )
+
+ ``gtest_discover_tests`` sets up a post-build command on the test executable
+ that generates the list of tests by parsing the output from running the test
+ with the ``--gtest_list_tests`` argument. Compared to the source parsing
+ approach of :command:`gtest_add_tests`, this ensures that the full list of
+ tests, including instantiations of parameterized tests, is obtained. Since
+ test discovery occurs at build time, it is not necessary to re-run CMake when
+ the list of tests changes.
+ However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set
+ in order to function in a cross-compiling environment.
+
+ Additionally, setting properties on tests is somewhat less convenient, since
+ the tests are not available at CMake time. Additional test properties may be
+ assigned to the set of tests as a whole using the ``PROPERTIES`` option. If
+ more fine-grained test control is needed, custom content may be provided
+ through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES`
+ directory property. The set of discovered tests is made accessible to such a
+ script via the ``<target>_TESTS`` variable.
+
+ The options are:
+
+ ``target``
+ Specifies the Google Test executable, which must be a known CMake
+ executable target. CMake will substitute the location of the built
+ executable when running the test.
+
+ ``EXTRA_ARGS arg1...``
+ Any extra arguments to pass on the command line to each test case.
+
+ ``WORKING_DIRECTORY dir``
+ Specifies the directory in which to run the discovered test cases. If this
+ option is not provided, the current binary directory is used.
+
+ ``TEST_PREFIX prefix``
+ Specifies a ``prefix`` to be prepended to the name of each discovered test
+ case. This can be useful when the same test executable is being used in
+ multiple calls to ``gtest_discover_tests()`` but with different
+ ``EXTRA_ARGS``.
+
+ ``TEST_SUFFIX suffix``
+ Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of
+ every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may
+ be specified.
+
+ ``NO_PRETTY_TYPES``
+ By default, the type index of type-parameterized tests is replaced by the
+ actual type name in the CTest test name. If this behavior is undesirable
+ (e.g. because the type names are unwieldy), this option will suppress this
+ behavior.
+
+ ``NO_PRETTY_VALUES``
+ By default, the value index of value-parameterized tests is replaced by the
+ actual value in the CTest test name. If this behavior is undesirable
+ (e.g. because the value strings are unwieldy), this option will suppress
+ this behavior.
+
+ ``PROPERTIES name1 value1...``
+ Specifies additional properties to be set on all tests discovered by this
+ invocation of ``gtest_discover_tests``.
+
+ ``TEST_LIST var``
+ Make the list of tests available in the variable ``var``, rather than the
+ default ``<target>_TESTS``. This can be useful when the same test
+ executable is being used in multiple calls to ``gtest_discover_tests()``.
+ Note that this variable is only available in CTest.
+
+ ``DISCOVERY_TIMEOUT num``
+ Specifies how long (in seconds) CMake will wait for the test to enumerate
+ available tests. If the test takes longer than this, discovery (and your
+ build) will fail. Most test executables will enumerate their tests very
+ quickly, but under some exceptional circumstances, a test may require a
+ longer timeout. The default is 5. See also the ``TIMEOUT`` option of
+ :command:`execute_process`.
+
+ .. note::
+
+ In CMake versions 3.10.1 and 3.10.2, this option was called ``TIMEOUT``.
+ This clashed with the ``TIMEOUT`` test property, which is one of the
+ common properties that would be set with the ``PROPERTIES`` keyword,
+ usually leading to legal but unintended behavior. The keyword was
+ changed to ``DISCOVERY_TIMEOUT`` in CMake 3.10.3 to address this
+ problem. The ambiguous behavior of the ``TIMEOUT`` keyword in 3.10.1
+ and 3.10.2 has not been preserved.
+
#]=======================================================================]
+# Save project's policies
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
+#------------------------------------------------------------------------------
function(gtest_add_tests)
if (ARGC LESS 1)
@@ -166,7 +308,7 @@ function(gtest_add_tests)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${source})
endif()
file(READ "${source}" contents)
- string(REGEX MATCHALL "${gtest_test_type_regex} *\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${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})
@@ -224,3 +366,98 @@ function(gtest_add_tests)
endif()
endfunction()
+
+#------------------------------------------------------------------------------
+function(gtest_discover_tests TARGET)
+ cmake_parse_arguments(
+ ""
+ "NO_PRETTY_TYPES;NO_PRETTY_VALUES"
+ "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;DISCOVERY_TIMEOUT"
+ "EXTRA_ARGS;PROPERTIES"
+ ${ARGN}
+ )
+
+ if(NOT _WORKING_DIRECTORY)
+ set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
+ endif()
+ if(NOT _TEST_LIST)
+ set(_TEST_LIST ${TARGET}_TESTS)
+ endif()
+ if(NOT _DISCOVERY_TIMEOUT)
+ set(_DISCOVERY_TIMEOUT 5)
+ endif()
+
+ get_property(
+ has_counter
+ TARGET ${TARGET}
+ PROPERTY CTEST_DISCOVERED_TEST_COUNTER
+ SET
+ )
+ if(has_counter)
+ get_property(
+ counter
+ TARGET ${TARGET}
+ PROPERTY CTEST_DISCOVERED_TEST_COUNTER
+ )
+ math(EXPR counter "${counter} + 1")
+ else()
+ set(counter 1)
+ endif()
+ set_property(
+ TARGET ${TARGET}
+ PROPERTY CTEST_DISCOVERED_TEST_COUNTER
+ ${counter}
+ )
+
+ # Define rule to generate test list for aforementioned test executable
+ set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}[${counter}]")
+ set(ctest_include_file "${ctest_file_base}_include.cmake")
+ set(ctest_tests_file "${ctest_file_base}_tests.cmake")
+ get_property(crosscompiling_emulator
+ TARGET ${TARGET}
+ PROPERTY CROSSCOMPILING_EMULATOR
+ )
+ add_custom_command(
+ TARGET ${TARGET} POST_BUILD
+ BYPRODUCTS "${ctest_tests_file}"
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_TARGET=${TARGET}"
+ -D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
+ -D "TEST_EXECUTOR=${crosscompiling_emulator}"
+ -D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
+ -D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
+ -D "TEST_PROPERTIES=${_PROPERTIES}"
+ -D "TEST_PREFIX=${_TEST_PREFIX}"
+ -D "TEST_SUFFIX=${_TEST_SUFFIX}"
+ -D "NO_PRETTY_TYPES=${_NO_PRETTY_TYPES}"
+ -D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}"
+ -D "TEST_LIST=${_TEST_LIST}"
+ -D "CTEST_FILE=${ctest_tests_file}"
+ -D "TEST_DISCOVERY_TIMEOUT=${_DISCOVERY_TIMEOUT}"
+ -P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}"
+ VERBATIM
+ )
+
+ file(WRITE "${ctest_include_file}"
+ "if(EXISTS \"${ctest_tests_file}\")\n"
+ " include(\"${ctest_tests_file}\")\n"
+ "else()\n"
+ " add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n"
+ "endif()\n"
+ )
+
+ # Add discovered tests to directory TEST_INCLUDE_FILES
+ set_property(DIRECTORY
+ APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
+ )
+
+endfunction()
+
+###############################################################################
+
+set(_GOOGLETEST_DISCOVER_TESTS_SCRIPT
+ ${CMAKE_CURRENT_LIST_DIR}/GoogleTestAddTests.cmake
+)
+
+# Restore project's policies
+cmake_policy(POP)
diff --git a/Modules/ITKCompatibility.cmake b/Modules/ITKCompatibility.cmake
index fef065381..7d211b61e 100644
--- a/Modules/ITKCompatibility.cmake
+++ b/Modules/ITKCompatibility.cmake
@@ -2,6 +2,6 @@
# file Copyright.txt or https://cmake.org/licensing for details.
-# work around an old bug in ITK prior to verison 3.0
+# work around an old bug in ITK prior to version 3.0
set(TIFF_RIGHT_VERSION 1)
diff --git a/Modules/InstallRequiredSystemLibraries.cmake b/Modules/InstallRequiredSystemLibraries.cmake
index 4e8713a08..0e1429d74 100644
--- a/Modules/InstallRequiredSystemLibraries.cmake
+++ b/Modules/InstallRequiredSystemLibraries.cmake
@@ -1,60 +1,94 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# InstallRequiredSystemLibraries
-# ------------------------------
-#
-# Include this module to search for compiler-provided system runtime
-# libraries and add install rules for them. Some optional variables
-# may be set prior to including the module to adjust behavior:
-#
-# ``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS``
-# Specify additional runtime libraries that may not be detected.
-# After inclusion any detected libraries will be appended to this.
-#
-# ``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP``
-# Set to TRUE to skip calling the :command:`install(PROGRAMS)` command to
-# allow the includer to specify its own install rule, using the value of
-# ``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS`` to get the list of libraries.
-#
-# ``CMAKE_INSTALL_DEBUG_LIBRARIES``
-# Set to TRUE to install the debug runtime libraries when available
-# with MSVC tools.
-#
-# ``CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY``
-# Set to TRUE to install only the debug runtime libraries with MSVC
-# tools even if the release runtime libraries are also available.
-#
-# ``CMAKE_INSTALL_UCRT_LIBRARIES``
-# Set to TRUE to install the Windows Universal CRT libraries for
-# app-local deployment (e.g. to Windows XP). This is meaningful
-# only with MSVC from Visual Studio 2015 or higher.
-#
-# One may set a ``CMAKE_WINDOWS_KITS_10_DIR`` *environment variable*
-# to an absolute path to tell CMake to look for Windows 10 SDKs in
-# a custom location. The specified directory is expected to contain
-# ``Redist/ucrt/DLLs/*`` directories.
-#
-# ``CMAKE_INSTALL_MFC_LIBRARIES``
-# Set to TRUE to install the MSVC MFC runtime libraries.
-#
-# ``CMAKE_INSTALL_OPENMP_LIBRARIES``
-# Set to TRUE to install the MSVC OpenMP runtime libraries
-#
-# ``CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION``
-# Specify the :command:`install(PROGRAMS)` command ``DESTINATION``
-# option. If not specified, the default is ``bin`` on Windows
-# and ``lib`` elsewhere.
-#
-# ``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS``
-# Set to TRUE to disable warnings about required library files that
-# do not exist. (For example, Visual Studio Express editions may
-# not provide the redistributable files.)
-#
-# ``CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT``
-# Specify the :command:`install(PROGRAMS)` command ``COMPONENT``
-# option. If not specified, no such option will be used.
+#[=======================================================================[.rst:
+InstallRequiredSystemLibraries
+------------------------------
+
+Include this module to search for compiler-provided system runtime
+libraries and add install rules for them. Some optional variables
+may be set prior to including the module to adjust behavior:
+
+``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS``
+ Specify additional runtime libraries that may not be detected.
+ After inclusion any detected libraries will be appended to this.
+
+``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP``
+ Set to TRUE to skip calling the :command:`install(PROGRAMS)` command to
+ allow the includer to specify its own install rule, using the value of
+ ``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS`` to get the list of libraries.
+
+``CMAKE_INSTALL_DEBUG_LIBRARIES``
+ Set to TRUE to install the debug runtime libraries when available
+ with MSVC tools.
+
+``CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY``
+ Set to TRUE to install only the debug runtime libraries with MSVC
+ tools even if the release runtime libraries are also available.
+
+``CMAKE_INSTALL_UCRT_LIBRARIES``
+ Set to TRUE to install the Windows Universal CRT libraries for
+ app-local deployment (e.g. to Windows XP). This is meaningful
+ only with MSVC from Visual Studio 2015 or higher.
+
+ One may set a ``CMAKE_WINDOWS_KITS_10_DIR`` *environment variable*
+ to an absolute path to tell CMake to look for Windows 10 SDKs in
+ a custom location. The specified directory is expected to contain
+ ``Redist/ucrt/DLLs/*`` directories.
+
+``CMAKE_INSTALL_MFC_LIBRARIES``
+ Set to TRUE to install the MSVC MFC runtime libraries.
+
+``CMAKE_INSTALL_OPENMP_LIBRARIES``
+ Set to TRUE to install the MSVC OpenMP runtime libraries
+
+``CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION``
+ Specify the :command:`install(PROGRAMS)` command ``DESTINATION``
+ option. If not specified, the default is ``bin`` on Windows
+ and ``lib`` elsewhere.
+
+``CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS``
+ Set to TRUE to disable warnings about required library files that
+ do not exist. (For example, Visual Studio Express editions may
+ not provide the redistributable files.)
+
+``CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT``
+ Specify the :command:`install(PROGRAMS)` command ``COMPONENT``
+ option. If not specified, no such option will be used.
+#]=======================================================================]
+
+cmake_policy(PUSH)
+cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
+
+set(_IRSL_HAVE_Intel FALSE)
+set(_IRSL_HAVE_MSVC FALSE)
+foreach(LANG IN ITEMS C CXX Fortran)
+ if("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "Intel")
+ if(NOT _IRSL_HAVE_Intel)
+ get_filename_component(_Intel_basedir "${CMAKE_${LANG}_COMPILER}" PATH)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(_Intel_archdir intel64)
+ else()
+ set(_Intel_archdir x86)
+ endif()
+ set(_Intel_compiler_ver ${CMAKE_${LANG}_COMPILER_VERSION})
+ if(WIN32)
+ get_filename_component(_Intel_redistdir "${_Intel_basedir}/../../redist/${_Intel_archdir}/compiler" ABSOLUTE)
+ elseif(APPLE)
+ get_filename_component(_Intel_redistdir "${_Intel_basedir}/../../compiler/lib" ABSOLUTE)
+ else()
+ if(EXISTS "${_Intel_basedir}/../lib/${_Intel_archdir}_lin")
+ get_filename_component(_Intel_redistdir "${_Intel_basedir}/../lib/${_Intel_archdir}" ABSOLUTE)
+ else()
+ get_filename_component(_Intel_redistdir "${_Intel_basedir}/../../compiler/lib/${_Intel_archdir}_lin" ABSOLUTE)
+ endif()
+ endif()
+ set(_IRSL_HAVE_Intel TRUE)
+ endif()
+ elseif("${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "MSVC")
+ set(_IRSL_HAVE_MSVC TRUE)
+ endif()
+endforeach()
if(MSVC)
file(TO_CMAKE_PATH "$ENV{SYSTEMROOT}" SYSTEMROOT)
@@ -88,9 +122,7 @@ if(MSVC)
)
endif()
- if(MSVC_VERSION EQUAL 1400)
- set(MSVC_REDIST_NAME VC80)
-
+ if(MSVC_TOOLSET_VERSION EQUAL 80)
# Find the runtime library redistribution directory.
get_filename_component(msvc_install_dir
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\8.0;InstallDir]" ABSOLUTE)
@@ -130,9 +162,7 @@ if(MSVC)
endif()
endif()
- if(MSVC_VERSION EQUAL 1500)
- set(MSVC_REDIST_NAME VC90)
-
+ if(MSVC_TOOLSET_VERSION EQUAL 90)
# Find the runtime library redistribution directory.
get_filename_component(msvc_install_dir
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\9.0;InstallDir]" ABSOLUTE)
@@ -176,34 +206,39 @@ if(MSVC)
endif()
set(MSVC_REDIST_NAME "")
- set(_MSVCRT_DLL_VERSION "")
- set(_MSVCRT_IDE_VERSION "")
+ set(_MSVC_DLL_VERSION "")
+ set(_MSVC_IDE_VERSION "")
if(MSVC_VERSION GREATER_EQUAL 2000)
message(WARNING "MSVC ${MSVC_VERSION} not yet supported.")
- elseif(MSVC_VERSION GREATER_EQUAL 1911)
+ elseif(MSVC_TOOLSET_VERSION GREATER_EQUAL 143)
+ message(WARNING "MSVC toolset v${MSVC_TOOLSET_VERSION} not yet supported.")
+ elseif(MSVC_TOOLSET_VERSION EQUAL 142)
+ set(MSVC_REDIST_NAME VC142)
+ set(_MSVC_DLL_VERSION 140)
+ set(_MSVC_IDE_VERSION 16)
+ if(MSVC_VERSION EQUAL 1920)
+ # VS2019 named this differently prior to update 1.
+ set(MSVC_REDIST_NAME VC141)
+ endif()
+ elseif(MSVC_TOOLSET_VERSION EQUAL 141)
set(MSVC_REDIST_NAME VC141)
- set(_MSVCRT_DLL_VERSION 140)
- set(_MSVCRT_IDE_VERSION 15)
- elseif(MSVC_VERSION EQUAL 1910)
- set(MSVC_REDIST_NAME VC150)
- set(_MSVCRT_DLL_VERSION 140)
- set(_MSVCRT_IDE_VERSION 15)
- elseif(MSVC_VERSION EQUAL 1900)
- set(MSVC_REDIST_NAME VC140)
- set(_MSVCRT_DLL_VERSION 140)
- set(_MSVCRT_IDE_VERSION 14)
- elseif(MSVC_VERSION EQUAL 1800)
- set(MSVC_REDIST_NAME VC120)
- set(_MSVCRT_DLL_VERSION 120)
- set(_MSVCRT_IDE_VERSION 12)
- elseif(MSVC_VERSION EQUAL 1700)
- set(MSVC_REDIST_NAME VC110)
- set(_MSVCRT_DLL_VERSION 110)
- set(_MSVCRT_IDE_VERSION 11)
- elseif(MSVC_VERSION EQUAL 1600)
- set(MSVC_REDIST_NAME VC100)
- set(_MSVCRT_DLL_VERSION 100)
- set(_MSVCRT_IDE_VERSION 10)
+ set(_MSVC_DLL_VERSION 140)
+ set(_MSVC_IDE_VERSION 15)
+ if(MSVC_VERSION EQUAL 1910)
+ # VS2017 named this differently prior to update 3.
+ set(MSVC_REDIST_NAME VC150)
+ endif()
+ elseif(MSVC_TOOLSET_VERSION)
+ set(MSVC_REDIST_NAME VC${MSVC_TOOLSET_VERSION})
+ math(EXPR _MSVC_DLL_VERSION "${MSVC_TOOLSET_VERSION} / 10 * 10")
+ math(EXPR _MSVC_IDE_VERSION "${MSVC_TOOLSET_VERSION} / 10")
+ endif()
+
+ set(_MSVCRT_DLL_VERSION "")
+ set(_MSVCRT_IDE_VERSION "")
+ if(_MSVC_IDE_VERSION GREATER_EQUAL 10)
+ set(_MSVCRT_DLL_VERSION "${_MSVC_DLL_VERSION}")
+ set(_MSVCRT_IDE_VERSION "${_MSVC_IDE_VERSION}")
endif()
if(_MSVCRT_DLL_VERSION)
@@ -216,10 +251,19 @@ if(MSVC)
endif()
if(NOT vs VERSION_LESS 15)
set(_vs_redist_paths "")
- cmake_host_system_information(RESULT _vs_dir QUERY VS_${vs}_DIR) # undocumented query
- if(IS_DIRECTORY "${_vs_dir}")
- file(GLOB _vs_redist_paths "${_vs_dir}/VC/Redist/MSVC/*")
- endif()
+ # The toolset and its redistributables may come with any VS version 15 or newer.
+ set(_MSVC_IDE_VERSIONS 16 15)
+ foreach(_vs_ver ${_MSVC_IDE_VERSIONS})
+ set(_vs_glob_redist_paths "")
+ cmake_host_system_information(RESULT _vs_dir QUERY VS_${_vs_ver}_DIR) # undocumented query
+ if(IS_DIRECTORY "${_vs_dir}")
+ file(GLOB _vs_glob_redist_paths "${_vs_dir}/VC/Redist/MSVC/*")
+ list(REVERSE _vs_glob_redist_paths)
+ list(APPEND _vs_redist_paths ${_vs_glob_redist_paths})
+ endif()
+ unset(_vs_glob_redist_paths)
+ endforeach()
+ unset(_MSVC_IDE_VERSIONS)
unset(_vs_dir)
else()
get_filename_component(_vs_dir
@@ -244,6 +288,9 @@ if(MSVC)
"${MSVC_CRT_DIR}/msvcp${v}.dll"
)
if(NOT vs VERSION_LESS 14)
+ if(EXISTS "${MSVC_CRT_DIR}/vcruntime${v}_1.dll")
+ list(APPEND __install__libs "${MSVC_CRT_DIR}/vcruntime${v}_1.dll")
+ endif()
list(APPEND __install__libs
"${MSVC_CRT_DIR}/vcruntime${v}.dll"
"${MSVC_CRT_DIR}/concrt${v}.dll"
@@ -262,6 +309,9 @@ if(MSVC)
"${MSVC_CRT_DIR}/msvcp${v}d.dll"
)
if(NOT vs VERSION_LESS 14)
+ if(EXISTS "${MSVC_CRT_DIR}/vcruntime${v}_1d.dll")
+ list(APPEND __install__libs "${MSVC_CRT_DIR}/vcruntime${v}_1d.dll")
+ endif()
list(APPEND __install__libs
"${MSVC_CRT_DIR}/vcruntime${v}d.dll"
"${MSVC_CRT_DIR}/concrt${v}d.dll"
@@ -276,7 +326,15 @@ if(MSVC)
get_filename_component(windows_kits_dir
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE)
set(programfilesx86 "ProgramFiles(x86)")
- find_path(WINDOWS_KITS_DIR NAMES Redist/ucrt/DLLs/${CMAKE_MSVC_ARCH}/ucrtbase.dll
+ if(";${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION};$ENV{UCRTVersion};$ENV{WindowsSDKVersion};" MATCHES [=[;(10\.[0-9.]+)[;\]]=])
+ set(__ucrt_version "${CMAKE_MATCH_1}/")
+ else()
+ set(__ucrt_version "")
+ endif()
+ find_path(WINDOWS_KITS_DIR
+ NAMES
+ Redist/${__ucrt_version}ucrt/DLLs/${CMAKE_MSVC_ARCH}/ucrtbase.dll
+ Redist/ucrt/DLLs/${CMAKE_MSVC_ARCH}/ucrtbase.dll
PATHS
$ENV{CMAKE_WINDOWS_KITS_10_DIR}
"${windows_kits_dir}"
@@ -287,11 +345,19 @@ if(MSVC)
# Glob the list of UCRT DLLs.
if(NOT CMAKE_INSTALL_DEBUG_LIBRARIES_ONLY)
- file(GLOB __ucrt_dlls "${WINDOWS_KITS_DIR}/Redist/ucrt/DLLs/${CMAKE_MSVC_ARCH}/*.dll")
+ if(EXISTS "${WINDOWS_KITS_DIR}/Redist/${__ucrt_version}ucrt/DLLs/${CMAKE_MSVC_ARCH}/ucrtbase.dll")
+ file(GLOB __ucrt_dlls "${WINDOWS_KITS_DIR}/Redist/${__ucrt_version}ucrt/DLLs/${CMAKE_MSVC_ARCH}/*.dll")
+ else()
+ file(GLOB __ucrt_dlls "${WINDOWS_KITS_DIR}/Redist/ucrt/DLLs/${CMAKE_MSVC_ARCH}/*.dll")
+ endif()
list(APPEND __install__libs ${__ucrt_dlls})
endif()
if(CMAKE_INSTALL_DEBUG_LIBRARIES)
- file(GLOB __ucrt_dlls "${WINDOWS_KITS_DIR}/bin/${CMAKE_MSVC_ARCH}/ucrt/*.dll")
+ if(EXISTS "${WINDOWS_KITS_DIR}/bin/${__ucrt_version}${CMAKE_MSVC_ARCH}/ucrt/ucrtbased.dll")
+ file(GLOB __ucrt_dlls "${WINDOWS_KITS_DIR}/bin/${__ucrt_version}${CMAKE_MSVC_ARCH}/ucrt/*.dll")
+ else()
+ file(GLOB __ucrt_dlls "${WINDOWS_KITS_DIR}/bin/${CMAKE_MSVC_ARCH}/ucrt/*.dll")
+ endif()
list(APPEND __install__libs ${__ucrt_dlls})
endif()
endif()
@@ -336,7 +402,7 @@ if(MSVC)
)
endif()
- # include the language dll's for vs8 as well as the actuall dll's
+ # include the language dll's for vs8 as well as the actual dll's
set(MSVC_MFCLOC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC80.MFCLOC")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
@@ -380,7 +446,7 @@ if(MSVC)
)
endif()
- # include the language dll's for vs9 as well as the actuall dll's
+ # include the language dll's for vs9 as well as the actual dll's
set(MSVC_MFCLOC_DIR "${MSVC_REDIST_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.VC90.MFCLOC")
# Install the manifest that allows DLLs to be loaded from the
# directory containing the executable.
@@ -400,23 +466,9 @@ if(MSVC)
set(_MFC_DLL_VERSION "")
set(_MFC_IDE_VERSION "")
- if(MSVC_VERSION GREATER_EQUAL 2000)
- # Version not yet supported.
- elseif(MSVC_VERSION GREATER_EQUAL 1910)
- set(_MFC_DLL_VERSION 140)
- set(_MFC_IDE_VERSION 15)
- elseif(MSVC_VERSION EQUAL 1900)
- set(_MFC_DLL_VERSION 140)
- set(_MFC_IDE_VERSION 14)
- elseif(MSVC_VERSION EQUAL 1800)
- set(_MFC_DLL_VERSION 120)
- set(_MFC_IDE_VERSION 12)
- elseif(MSVC_VERSION EQUAL 1700)
- set(_MFC_DLL_VERSION 110)
- set(_MFC_IDE_VERSION 11)
- elseif(MSVC_VERSION EQUAL 1600)
- set(_MFC_DLL_VERSION 100)
- set(_MFC_IDE_VERSION 10)
+ if(_MSVC_IDE_VERSION GREATER_EQUAL 10)
+ set(_MFC_DLL_VERSION ${_MSVC_DLL_VERSION})
+ set(_MFC_IDE_VERSION ${_MSVC_IDE_VERSION})
endif()
if(_MFC_DLL_VERSION)
@@ -448,6 +500,10 @@ if(MSVC)
if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfc${v}d.dll")
set(__install__libs ${__install__libs}
"${MSVC_MFC_DIR}/mfc${v}d.dll"
+ )
+ endif()
+ if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfcm${v}d.dll")
+ set(__install__libs ${__install__libs}
"${MSVC_MFC_DIR}/mfcm${v}d.dll"
)
endif()
@@ -462,12 +518,16 @@ if(MSVC)
if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfc${v}.dll")
set(__install__libs ${__install__libs}
"${MSVC_MFC_DIR}/mfc${v}.dll"
+ )
+ endif()
+ if("${v}" LESS 12 OR EXISTS "${MSVC_MFC_DIR}/mfcm${v}.dll")
+ set(__install__libs ${__install__libs}
"${MSVC_MFC_DIR}/mfcm${v}.dll"
)
endif()
endif()
- # include the language dll's as well as the actuall dll's
+ # include the language dll's as well as the actual dll's
set(MSVC_MFCLOC_DIR "${MSVC_REDIST_MFC_DIR}/${CMAKE_MSVC_ARCH}/Microsoft.${MSVC_REDIST_NAME}.MFCLOC")
set(__install__libs ${__install__libs}
"${MSVC_MFCLOC_DIR}/mfc${v}chs.dll"
@@ -486,33 +546,9 @@ if(MSVC)
# MSVC 8 was the first version with OpenMP
# Furthermore, there is no debug version of this
- if(CMAKE_INSTALL_OPENMP_LIBRARIES)
- set(_MSOMP_DLL_VERSION "")
- set(_MSOMP_IDE_VERSION "")
- if(MSVC_VERSION GREATER_EQUAL 2000)
- # Version not yet supported.
- elseif(MSVC_VERSION GREATER_EQUAL 1910)
- set(_MSOMP_DLL_VERSION 140)
- set(_MSOMP_IDE_VERSION 15)
- elseif(MSVC_VERSION EQUAL 1900)
- set(_MSOMP_DLL_VERSION 140)
- set(_MSOMP_IDE_VERSION 14)
- elseif(MSVC_VERSION EQUAL 1800)
- set(_MSOMP_DLL_VERSION 120)
- set(_MSOMP_IDE_VERSION 12)
- elseif(MSVC_VERSION EQUAL 1700)
- set(_MSOMP_DLL_VERSION 110)
- set(_MSOMP_IDE_VERSION 11)
- elseif(MSVC_VERSION EQUAL 1600)
- set(_MSOMP_DLL_VERSION 100)
- set(_MSOMP_IDE_VERSION 10)
- elseif(MSVC_VERSION EQUAL 1500)
- set(_MSOMP_DLL_VERSION 90)
- set(_MSOMP_IDE_VERSION 9)
- elseif(MSVC_VERSION EQUAL 1400)
- set(_MSOMP_DLL_VERSION 80)
- set(_MSOMP_IDE_VERSION 8)
- endif()
+ if(CMAKE_INSTALL_OPENMP_LIBRARIES AND _IRSL_HAVE_MSVC)
+ set(_MSOMP_DLL_VERSION ${_MSVC_DLL_VERSION})
+ set(_MSOMP_IDE_VERSION ${_MSVC_IDE_VERSION})
if(_MSOMP_DLL_VERSION)
set(v "${_MSOMP_DLL_VERSION}")
@@ -545,6 +581,119 @@ if(MSVC)
endforeach()
endif()
+if(_IRSL_HAVE_Intel)
+ unset(__install_libs)
+ if(CMAKE_INSTALL_OPENMP_LIBRARIES)
+ if(WIN32)
+ list(APPEND __install_libs "${_Intel_redistdir}/libiomp5md.dll" "${_Intel_redistdir}/libiompstubs5md.dll")
+ elseif(APPLE)
+ list(APPEND __install_libs "${_Intel_redistdir}/libiomp5.dylib" "${_Intel_redistdir}/libiompstubs5.dylib")
+ else()
+ list(APPEND __install_libs "${_Intel_redistdir}/libiomp5.so" "${_Intel_redistdir}/libiompstubs5.so")
+ if(_Intel_compiler_ver VERSION_LESS 17)
+ list(APPEND __install_libs "${_Intel_redistdir}/libomp_db.so")
+ endif()
+ if(_Intel_compiler_ver VERSION_LESS 13)
+ list(APPEND __install_libs "${_Intel_redistdir}/libiompprof5.so")
+ endif()
+ endif()
+ endif()
+ if(WIN32)
+ set(__install_dirs "${_Intel_redistdir}/1033")
+ if(EXISTS "${_Intel_redistdir}/1041")
+ list(APPEND __install_dirs "${_Intel_redistdir}/1041")
+ endif()
+ if(_Intel_compiler_ver VERSION_LESS 18)
+ list(APPEND __install_dirs "${_Intel_redistdir}/irml" "${_Intel_redistdir}/irml_c")
+ endif()
+ foreach(__Intel_lib IN ITEMS cilkrts20.dll libchkp.dll libioffload_host.dll libirngmd.dll
+ libmmd.dll libmmdd.dll libmpx.dll liboffload.dll svml_dispmd.dll)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ if(CMAKE_C_COMPILER_ID STREQUAL Intel OR CMAKE_CXX_COMPILER_ID STREQUAL Intel)
+ list(APPEND __install_libs "${_Intel_redistdir}/libgfxoffload.dll")
+ endif()
+ if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
+ foreach(__Intel_lib IN ITEMS ifdlg100.dll libicaf.dll libifcoremd.dll libifcoremdd.dll libifcorert.dll libifcorertd.dll libifportmd.dll)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ endif()
+ elseif(APPLE)
+ foreach(__Intel_lib IN ITEMS libchkp.dylib libcilkrts.5.dylib libcilkrts.dylib libimf.dylib libintlc.dylib libirc.dylib libirng.dylib libsvml.dylib)
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ if(CMAKE_C_COMPILER_ID STREQUAL Intel OR CMAKE_CXX_COMPILER_ID STREQUAL Intel)
+ if(_Intel_compiler_ver VERSION_LESS 17)
+ list(APPEND __install_libs "${_Intel_redistdir}/libistrconv.dylib")
+ endif()
+ endif()
+ if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
+ foreach(__Intel_lib IN ITEMS libifcore.dylib libifcoremt.dylib libifport.dylib libifportmt.dylib)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ endif()
+ else()
+ foreach(__Intel_lib IN ITEMS libchkp.so libcilkrts.so libcilkrts.so.5 libimf.so libintlc.so libintlc.so.5 libirc.so libpdbx.so libpdbx.so.5 libsvml.so)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ if(_Intel_compiler_ver VERSION_GREATER_EQUAL 13)
+ foreach(__Intel_lib IN ITEMS libirng.so liboffload.so liboffload.so.5)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ endif()
+ if(CMAKE_C_COMPILER_ID STREQUAL Intel OR CMAKE_CXX_COMPILER_ID STREQUAL Intel)
+ set(__install_dirs "${_Intel_redistdir}/irml")
+ list(APPEND __install_libs "${_Intel_redistdir}/cilk_db.so")
+ if(_Intel_compiler_ver VERSION_GREATER_EQUAL 15)
+ list(APPEND __install_libs "${_Intel_redistdir}/libistrconv.so" "${_Intel_redistdir}/libgfxoffload.so")
+ endif()
+ endif()
+ if(_Intel_compiler_ver VERSION_GREATER_EQUAL 16)
+ foreach(__Intel_lib IN ITEMS libioffload_host.so libioffload_host.so.5 libioffload_target.so libioffload_target.so.5 libmpx.so offload_main)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ endif()
+ if(_Intel_compiler_ver VERSION_LESS 15)
+ foreach(__Intel_lib IN ITEMS libcxaguard.so libcxaguard.so.5)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ endif()
+ if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
+ foreach(__Intel_lib IN ITEMS libicaf.so libifcore.so libifcore.so.5 libifcoremt.so libifcoremt.so.5 libifport.so libifport.so.5)
+
+ list(APPEND __install_libs "${_Intel_redistdir}/${__Intel_lib}")
+ endforeach()
+ endif()
+ endif()
+
+ foreach(lib IN LISTS __install_libs)
+ if(EXISTS ${lib})
+ list(APPEND 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}'")
+ endif()
+ endif()
+ endforeach()
+
+ foreach(dir IN LISTS __install_dirs)
+ if(EXISTS ${dir})
+ list(APPEND CMAKE_INSTALL_SYSTEM_RUNTIME_DIRECTORIES ${dir})
+ else()
+ if(NOT CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
+ message(WARNING "system runtime library file does not exist: '${dir}'")
+ endif()
+ endif()
+ endforeach()
+endif()
+
if(WATCOM)
get_filename_component( CompilerPath ${CMAKE_C_COMPILER} PATH )
if(CMAKE_C_COMPILER_VERSION)
@@ -598,5 +747,12 @@ if(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS)
DESTINATION ${CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION}
${_CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT}
)
+
+ install(DIRECTORY ${CMAKE_INSTALL_SYSTEM_RUNTIME_DIRECTORIES}
+ DESTINATION ${CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION}
+ ${_CMAKE_INSTALL_SYSTEM_RUNTIME_COMPONENT}
+ )
endif()
endif()
+
+cmake_policy(POP)
diff --git a/Modules/Internal/FeatureTesting.cmake b/Modules/Internal/FeatureTesting.cmake
index de336e708..75be473f3 100644
--- a/Modules/Internal/FeatureTesting.cmake
+++ b/Modules/Internal/FeatureTesting.cmake
@@ -71,10 +71,35 @@ endmacro()
macro(_record_compiler_features_c std)
list(APPEND CMAKE_C${std}_COMPILE_FEATURES c_std_${std})
- _record_compiler_features(C "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES)
+
+ get_property(lang_level_has_features GLOBAL PROPERTY CMAKE_C${std}_KNOWN_FEATURES)
+ if(lang_level_has_features)
+ _record_compiler_features(C "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES)
+ endif()
+ unset(lang_level_has_features)
endmacro()
macro(_record_compiler_features_cxx std)
list(APPEND CMAKE_CXX${std}_COMPILE_FEATURES cxx_std_${std})
- _record_compiler_features(CXX "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES)
+
+ get_property(lang_level_has_features GLOBAL PROPERTY CMAKE_CXX${std}_KNOWN_FEATURES)
+ if(lang_level_has_features)
+ _record_compiler_features(CXX "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES)
+ endif()
+ unset(lang_level_has_features)
+endmacro()
+
+macro(_has_compiler_features lang level compile_flags feature_list)
+ # presume all known features are supported
+ get_property(known_features GLOBAL PROPERTY CMAKE_${lang}${level}_KNOWN_FEATURES)
+ list(APPEND ${feature_list} ${known_features})
+endmacro()
+
+macro(_has_compiler_features_c std)
+ list(APPEND CMAKE_C${std}_COMPILE_FEATURES c_std_${std})
+ _has_compiler_features(C ${std} "${CMAKE_C${std}_STANDARD_COMPILE_OPTION}" CMAKE_C${std}_COMPILE_FEATURES)
+endmacro()
+macro(_has_compiler_features_cxx std)
+ list(APPEND CMAKE_CXX${std}_COMPILE_FEATURES cxx_std_${std})
+ _has_compiler_features(CXX ${std} "${CMAKE_CXX${std}_STANDARD_COMPILE_OPTION}" CMAKE_CXX${std}_COMPILE_FEATURES)
endmacro()
diff --git a/Modules/KDE3Macros.cmake b/Modules/KDE3Macros.cmake
index b3f31ed62..1c353ba84 100644
--- a/Modules/KDE3Macros.cmake
+++ b/Modules/KDE3Macros.cmake
@@ -26,105 +26,106 @@ 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})
+ foreach (_current_FILE ${ARGN})
- get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
- get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+ 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)
+ 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)
+ 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}
- )
+ add_custom_command(OUTPUT ${_kidl}
+ COMMAND ${KDE3_DCOPIDL_EXECUTABLE}
+ ARGS ${_tmp_FILE} > ${_kidl}
+ DEPENDS ${_tmp_FILE}
+ )
- endif ()
+ endif ()
- if (NOT HAVE_${_basename}_SKEL_RULE)
- set(HAVE_${_basename}_SKEL_RULE ON)
+ 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}
- )
+ add_custom_command(OUTPUT ${_skel}
+ COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE}
+ ARGS --c++-suffix cpp --no-signals --no-stub ${_kidl}
+ DEPENDS ${_kidl}
+ )
- endif ()
+ endif ()
- set(${_sources} ${${_sources}} ${_skel})
+ set(${_sources} ${${_sources}} ${_skel})
- endforeach ()
+ endforeach ()
endmacro()
macro(KDE3_ADD_DCOP_STUBS _sources)
- foreach (_current_FILE ${ARGN})
+ foreach (_current_FILE ${ARGN})
- get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+ get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
- get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+ 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)
+ 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)
+ 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}
- )
+ add_custom_command(OUTPUT ${_kidl}
+ COMMAND ${KDE3_DCOPIDL_EXECUTABLE}
+ ARGS ${_tmp_FILE} > ${_kidl}
+ DEPENDS ${_tmp_FILE}
+ )
- endif ()
+ endif ()
- if (NOT HAVE_${_basename}_STUB_RULE)
- set(HAVE_${_basename}_STUB_RULE ON)
+ 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}
- )
+ add_custom_command(OUTPUT ${_stub_CPP}
+ COMMAND ${KDE3_DCOPIDL2CPP_EXECUTABLE}
+ ARGS --c++-suffix cpp --no-signals --no-skel ${_kidl}
+ DEPENDS ${_kidl}
+ )
- endif ()
+ endif ()
- set(${_sources} ${${_sources}} ${_stub_CPP})
+ set(${_sources} ${${_sources}} ${_stub_CPP})
- endforeach ()
+ endforeach ()
endmacro()
macro(KDE3_ADD_KCFG_FILES _sources)
- foreach (_current_FILE ${ARGN})
+ foreach (_current_FILE ${ARGN})
- get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+ get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
- get_filename_component(_basename ${_tmp_FILE} NAME_WE)
+ get_filename_component(_basename ${_tmp_FILE} NAME_WE)
- file(READ ${_tmp_FILE} _contents)
- string(REGEX REPLACE "^(.*\n)?File=([^\n]+)\n.*$" "\\2" _kcfg_FILE "${_contents}")
+ 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)
+ 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} )
+ 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})
+ set(${_sources} ${${_sources}} ${_src_FILE})
- endforeach ()
+ endforeach ()
endmacro()
@@ -132,22 +133,22 @@ 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})
+ foreach (_current_FILE ${ARGN})
- get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE)
+ 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)
+ 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}
- )
+ add_custom_command(OUTPUT ${_moc}
+ COMMAND ${QT_MOC_EXECUTABLE}
+ ARGS ${_tmp_FILE} -o ${_moc}
+ DEPENDS ${_tmp_FILE}
+ )
- set(${_sources} ${${_sources}} ${_moc})
+ set(${_sources} ${${_sources}} ${_moc})
- endforeach ()
+ endforeach ()
endmacro()
@@ -156,186 +157,186 @@ 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 ()
+ 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})
+ set(_matching_FILES )
+ foreach (_current_FILE ${ARGN})
- get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
+ 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 "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)
+ if (EXISTS ${_abs_FILE} AND NOT _skip)
- file(STRINGS ${_abs_FILE} _match REGEX "#include +[^ ]+\\.moc[\">]")
+ file(STRINGS ${_abs_FILE} _match REGEX "#include +[^ ]+\\.moc[\">]")
- get_filename_component(_abs_PATH ${_abs_FILE} PATH)
+ get_filename_component(_abs_PATH ${_abs_FILE} PATH)
- foreach (_current_MOC_INC IN LISTS _match)
- string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
+ 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})
+ 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_custom_command(OUTPUT ${_moc}
+ COMMAND ${QT_MOC_EXECUTABLE}
+ ARGS ${_header} -o ${_moc}
+ DEPENDS ${_header}
+ )
- ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
+ ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
- endforeach ()
- unset(_match)
- unset(_header)
- unset(_moc)
- endif ()
- endforeach ()
+ 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 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 "mime")
+ set(_icon_GROUP "mimetypes")
+ endif ()
- if (${_group} STREQUAL "filesys")
- set(_icon_GROUP "filesystems")
- endif ()
+ if (${_group} STREQUAL "filesys")
+ set(_icon_GROUP "filesystems")
+ endif ()
- if (${_group} STREQUAL "device")
- set(_icon_GROUP "devices")
- endif ()
+ if (${_group} STREQUAL "device")
+ set(_icon_GROUP "devices")
+ endif ()
- if (${_group} STREQUAL "app")
- set(_icon_GROUP "apps")
- endif ()
+ if (${_group} STREQUAL "app")
+ set(_icon_GROUP "apps")
+ endif ()
- if (${_group} STREQUAL "action")
- set(_icon_GROUP "actions")
- 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 ()
+ # 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 ()
+ 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")
+ 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})
+ 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 ()
+ file(WRITE ${_filename} "//autogenerated file\n")
+ foreach (_current_FILE ${ARGN})
+ file(APPEND ${_filename} "#include \"${_current_FILE}\"\n")
+ endforeach ()
endmacro()
@@ -346,24 +347,24 @@ 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 (${_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})
+ add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN})
# endif ()
- if(_first_SRC)
- set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
- endif()
+ if(_first_SRC)
+ set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
+ endif()
- KDE3_INSTALL_LIBTOOL_FILE(${_target_NAME})
+ KDE3_INSTALL_LIBTOOL_FILE(${_target_NAME})
endmacro()
@@ -374,13 +375,13 @@ macro(KDE3_ADD_KDEINIT_EXECUTABLE _target_NAME )
# 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} )
+ 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)
+ 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} )
+ add_executable( ${_target_NAME} ${CMAKE_CURRENT_BINARY_DIR}/${_target_NAME}_dummy.cpp )
+ target_link_libraries( ${_target_NAME} kdeinit_${_target_NAME} )
endmacro()
@@ -391,7 +392,7 @@ macro(KDE3_ADD_EXECUTABLE _target_NAME )
# KDE3_CREATE_FINAL_FILE(${_target_NAME}_final.cpp ${ARGN})
# add_executable(${_target_NAME} ${_target_NAME}_final.cpp)
# else ()
- add_executable(${_target_NAME} ${ARGN} )
+ add_executable(${_target_NAME} ${ARGN} )
# endif ()
endmacro()
diff --git a/Modules/MacroAddFileDependencies.cmake b/Modules/MacroAddFileDependencies.cmake
index db2681478..ca60b5702 100644
--- a/Modules/MacroAddFileDependencies.cmake
+++ b/Modules/MacroAddFileDependencies.cmake
@@ -1,29 +1,30 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
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 ()
+ 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}")
+ set_source_files_properties(${_file} PROPERTIES OBJECT_DEPENDS "${_deps}")
endmacro ()
diff --git a/Modules/MatlabTestsRedirect.cmake b/Modules/MatlabTestsRedirect.cmake
index 64d580db6..fc36fc3b4 100644
--- a/Modules/MatlabTestsRedirect.cmake
+++ b/Modules/MatlabTestsRedirect.cmake
@@ -55,11 +55,12 @@ endif()
if(no_unittest_framework)
- set(unittest_to_run "try, ${unittest_file_to_run_name}, catch err, disp('An exception has been thrown during the execution'), disp(err), disp(err.stack), exit(1), end, exit(0)")
+ set(unittest_to_run "${unittest_file_to_run_name}")
endif()
+set(command_to_run "try, ${unittest_to_run}, catch err, disp('An exception has been thrown during the execution'), disp(err), disp(err.stack), exit(1), end, exit(0)")
set(Matlab_SCRIPT_TO_RUN
- "addpath(${concat_string}); ${cmd_to_run_before_test}; ${unittest_to_run}"
+ "addpath(${concat_string}); ${cmd_to_run_before_test}; ${command_to_run}"
)
# if the working directory is not specified then default
# to the output_directory because the log file will go there
diff --git a/Modules/NSIS.template.in b/Modules/NSIS.template.in
index 9001888da..f75ae7836 100644
--- a/Modules/NSIS.template.in
+++ b/Modules/NSIS.template.in
@@ -847,7 +847,7 @@ Section "Uninstall"
@CPACK_NSIS_DELETE_ICONS@
@CPACK_NSIS_DELETE_ICONS_EXTRA@
- ;Delete empty start menu parent diretories
+ ;Delete empty start menu parent directories
StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
startMenuDeleteLoop:
@@ -866,7 +866,7 @@ Section "Uninstall"
Delete "$SMPROGRAMS\$MUI_TEMP\Uninstall.lnk"
@CPACK_NSIS_DELETE_ICONS_EXTRA@
- ;Delete empty start menu parent diretories
+ ;Delete empty start menu parent directories
StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"
secondStartMenuDeleteLoop:
diff --git a/Modules/Platform/AIX-GNU.cmake b/Modules/Platform/AIX-GNU.cmake
index 7f08c4a35..0abbb6175 100644
--- a/Modules/Platform/AIX-GNU.cmake
+++ b/Modules/Platform/AIX-GNU.cmake
@@ -24,5 +24,7 @@ macro(__aix_compiler_gnu lang)
set(CMAKE_${lang}_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH 1)
set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath")
- unset(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY)
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 7 OR CMAKE_SYSTEM_VERSION VERSION_LESS 7.1)
+ unset(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY)
+ endif()
endmacro()
diff --git a/Modules/Platform/AIX-XL.cmake b/Modules/Platform/AIX-XL.cmake
index b3078fffb..06a806b95 100644
--- a/Modules/Platform/AIX-XL.cmake
+++ b/Modules/Platform/AIX-XL.cmake
@@ -25,4 +25,26 @@ macro(__aix_compiler_xl lang)
set(CMAKE_SHARED_MODULE_${lang}_FLAGS " ")
set(CMAKE_${lang}_LINK_FLAGS "-Wl,-bnoipath")
+
+ # Find the CreateExportList program that comes with this toolchain.
+ find_program(CMAKE_XL_CreateExportList
+ NAMES CreateExportList
+ DOC "IBM XL CreateExportList tool"
+ )
+
+ # 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> -Wl,-bE:<OBJECT_DIR>/objects.exp <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>"
+ )
+ endif()
endmacro()
diff --git a/Modules/Platform/Android-Clang-CXX.cmake b/Modules/Platform/Android-Clang-CXX.cmake
index 711183645..85d508880 100644
--- a/Modules/Platform/Android-Clang-CXX.cmake
+++ b/Modules/Platform/Android-Clang-CXX.cmake
@@ -1,2 +1,9 @@
include(Platform/Android-Clang)
__android_compiler_clang(CXX)
+if(_ANDROID_STL_NOSTDLIBXX)
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6)
+ string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " -nostdlib++")
+ else()
+ string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " -nodefaultlibs -lgcc -lc -lm -ldl")
+ endif()
+endif()
diff --git a/Modules/Platform/Android-Clang.cmake b/Modules/Platform/Android-Clang.cmake
index f739ab1ef..9ed1e01f9 100644
--- a/Modules/Platform/Android-Clang.cmake
+++ b/Modules/Platform/Android-Clang.cmake
@@ -40,5 +40,6 @@ macro(__android_compiler_clang lang)
endif()
if(NOT CMAKE_${lang}_COMPILER_TARGET)
set(CMAKE_${lang}_COMPILER_TARGET "${_ANDROID_ABI_CLANG_TARGET}")
+ list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "--target=${CMAKE_${lang}_COMPILER_TARGET}")
endif()
endmacro()
diff --git a/Modules/Platform/Android-Common.cmake b/Modules/Platform/Android-Common.cmake
index 80a8f410d..f8b934693 100644
--- a/Modules/Platform/Android-Common.cmake
+++ b/Modules/Platform/Android-Common.cmake
@@ -32,8 +32,10 @@ if(CMAKE_ANDROID_NDK)
)
endif()
unset(_ANDROID_STL_TYPE_FOUND)
- else()
+ elseif(IS_DIRECTORY ${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++)
set(CMAKE_ANDROID_STL_TYPE "gnustl_static")
+ else()
+ set(CMAKE_ANDROID_STL_TYPE "c++_static")
endif()
unset(_ANDROID_STL_TYPES)
diff --git a/Modules/Platform/Android-Determine.cmake b/Modules/Platform/Android-Determine.cmake
index add1dc1f7..bb42eedde 100644
--- a/Modules/Platform/Android-Determine.cmake
+++ b/Modules/Platform/Android-Determine.cmake
@@ -18,6 +18,9 @@ if(CMAKE_SYSTEM_VERSION EQUAL 1)
return()
endif()
+cmake_policy(PUSH)
+cmake_policy(SET CMP0057 NEW) # if IN_LIST
+
# If the user provided CMAKE_SYSROOT for us, extract information from it.
set(_ANDROID_SYSROOT_NDK "")
set(_ANDROID_SYSROOT_API "")
@@ -261,7 +264,40 @@ if(NOT CMAKE_ANDROID_ARCH_ABI)
else()
# https://developer.android.com/ndk/guides/application_mk.html
# Default is the oldest ARM ABI.
- set(CMAKE_ANDROID_ARCH_ABI "armeabi")
+
+ # Lookup the available ABIs among all toolchains.
+ set(_ANDROID_ABIS "")
+ file(GLOB _ANDROID_CONFIG_MKS
+ "${CMAKE_ANDROID_NDK}/build/core/toolchains/*/config.mk"
+ "${CMAKE_ANDROID_NDK}/toolchains/*/config.mk"
+ )
+ foreach(config_mk IN LISTS _ANDROID_CONFIG_MKS)
+ file(STRINGS "${config_mk}" _ANDROID_TOOL_ABIS REGEX "^TOOLCHAIN_ABIS :=")
+ string(REPLACE "TOOLCHAIN_ABIS :=" "" _ANDROID_TOOL_ABIS "${_ANDROID_TOOL_ABIS}")
+ separate_arguments(_ANDROID_TOOL_ABIS UNIX_COMMAND "${_ANDROID_TOOL_ABIS}")
+ list(APPEND _ANDROID_ABIS ${_ANDROID_TOOL_ABIS})
+ unset(_ANDROID_TOOL_ABIS)
+ endforeach()
+ unset(_ANDROID_CONFIG_MKS)
+
+ # Choose the oldest among the available arm ABIs.
+ if(_ANDROID_ABIS)
+ list(REMOVE_DUPLICATES _ANDROID_ABIS)
+ cmake_policy(PUSH)
+ cmake_policy(SET CMP0057 NEW)
+ foreach(abi armeabi armeabi-v7a arm64-v8a)
+ if("${abi}" IN_LIST _ANDROID_ABIS)
+ set(CMAKE_ANDROID_ARCH_ABI "${abi}")
+ break()
+ endif()
+ endforeach()
+ cmake_policy(POP)
+ endif()
+ unset(_ANDROID_ABIS)
+
+ if(NOT CMAKE_ANDROID_ARCH_ABI)
+ set(CMAKE_ANDROID_ARCH_ABI "armeabi")
+ endif()
endif()
endif()
set(CMAKE_ANDROID_ARCH "${_ANDROID_ABI_${CMAKE_ANDROID_ARCH_ABI}_ARCH}")
@@ -338,3 +374,5 @@ endif()
# Report the chosen architecture.
message(STATUS "Android: Targeting API '${CMAKE_SYSTEM_VERSION}' with architecture '${CMAKE_ANDROID_ARCH}', ABI '${CMAKE_ANDROID_ARCH_ABI}', and processor '${CMAKE_SYSTEM_PROCESSOR}'")
+
+cmake_policy(POP)
diff --git a/Modules/Platform/Android-GNU-CXX.cmake b/Modules/Platform/Android-GNU-CXX.cmake
index 41279d1f7..d30d0ff4e 100644
--- a/Modules/Platform/Android-GNU-CXX.cmake
+++ b/Modules/Platform/Android-GNU-CXX.cmake
@@ -1,2 +1,5 @@
include(Platform/Android-GNU)
__android_compiler_gnu(CXX)
+if(_ANDROID_STL_NOSTDLIBXX)
+ string(APPEND CMAKE_CXX_STANDARD_LIBRARIES " -nodefaultlibs -lgcc -lc -lm -ldl")
+endif()
diff --git a/Modules/Platform/Android.cmake b/Modules/Platform/Android.cmake
index 3d69733bb..f08f84176 100644
--- a/Modules/Platform/Android.cmake
+++ b/Modules/Platform/Android.cmake
@@ -2,9 +2,11 @@ include(Platform/Linux)
set(ANDROID 1)
-# 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)
+# Conventionally Android does not use versioned soname
+# But in modern versions it is acceptable
+if(NOT DEFINED CMAKE_PLATFORM_NO_VERSIONED_SONAME)
+ set(CMAKE_PLATFORM_NO_VERSIONED_SONAME 1)
+endif()
# Android reportedly ignores RPATH, and we cannot predict the install
# location anyway.
diff --git a/Modules/Platform/Android/Determine-Compiler-NDK.cmake b/Modules/Platform/Android/Determine-Compiler-NDK.cmake
index 064992514..5f2cc524e 100644
--- a/Modules/Platform/Android/Determine-Compiler-NDK.cmake
+++ b/Modules/Platform/Android/Determine-Compiler-NDK.cmake
@@ -35,7 +35,18 @@ elseif(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION)
endif()
set(_ANDROID_TOOL_PATTERNS "*-${CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION}")
else()
- set(_ANDROID_TOOL_PATTERNS "*-[0-9].[0-9]")
+ # If we can find any gcc toolchains then use one by default.
+ # Otherwise we look for clang toolchains (e.g. NDK r18+).
+ file(GLOB _ANDROID_CONFIG_MKS_FOR_GCC
+ "${CMAKE_ANDROID_NDK}/build/core/toolchains/*-[0-9].[0-9]/config.mk"
+ "${CMAKE_ANDROID_NDK}/toolchains/*-[0-9].[0-9]/config.mk"
+ )
+ if(_ANDROID_CONFIG_MKS_FOR_GCC)
+ set(_ANDROID_TOOL_PATTERNS "*-[0-9].[0-9]")
+ else()
+ set(_ANDROID_TOOL_PATTERNS "*-clang")
+ endif()
+ unset(_ANDROID_CONFIG_MKS_FOR_GCC)
endif()
set(_ANDROID_CONFIG_MK_PATTERNS)
foreach(base "build/core/toolchains" "toolchains")
diff --git a/Modules/Platform/Android/abi-common.cmake b/Modules/Platform/Android/abi-common.cmake
index 10fb8972d..6bce3c705 100644
--- a/Modules/Platform/Android/abi-common.cmake
+++ b/Modules/Platform/Android/abi-common.cmake
@@ -12,9 +12,25 @@ if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
-if(CMAKE_POSITION_INDEPENDENT_CODE)
- string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -fPIE -pie")
+cmake_policy(GET CMP0083 _CMP0083)
+if(_CMP0083 STREQUAL NEW)
+ # PIE Flags are managed by compiler configuration files
+ if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 16)
+ # ensure PIE flags are passed to the linker
+ set(CMAKE_C_LINK_PIE_SUPPORTED YES CACHE INTERNAL "PIE (C)")
+ set(CMAKE_CXX_LINK_PIE_SUPPORTED YES CACHE INTERNAL "PIE (CXX)")
+ if(CMAKE_SYSTEM_VERSION VERSION_GREATER_EQUAL 21)
+ # no PIE executable are no longer supported
+ set(CMAKE_C_LINK_NO_PIE_SUPPORTED NO CACHE INTERNAL "NO_PIE (C)")
+ set(CMAKE_CXX_LINK_NO_PIE_SUPPORTED NO CACHE INTERNAL "NO_PIE (CXX)")
+ endif()
+ endif()
+else()
+ if(CMAKE_POSITION_INDEPENDENT_CODE)
+ string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -fPIE -pie")
+ endif()
endif()
+unset(_CMP0083)
string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -Wl,--gc-sections")
diff --git a/Modules/Platform/Android/ndk-stl-c++.cmake b/Modules/Platform/Android/ndk-stl-c++.cmake
index a12411c78..1cafd1fd7 100644
--- a/Modules/Platform/Android/ndk-stl-c++.cmake
+++ b/Modules/Platform/Android/ndk-stl-c++.cmake
@@ -1,6 +1,7 @@
# <ndk>/sources/cxx-stl/llvm-libc++/Android.mk
set(_ANDROID_STL_RTTI 1)
set(_ANDROID_STL_EXCEPTIONS 1)
+set(_ANDROID_STL_NOSTDLIBXX 1)
macro(__android_stl_cxx lang filename)
# Add the include directory.
if(EXISTS "${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libcxx/include/cstddef")
diff --git a/Modules/Platform/Android/ndk-stl-gabi++.cmake b/Modules/Platform/Android/ndk-stl-gabi++.cmake
index 850a47a99..d3b9e45af 100644
--- a/Modules/Platform/Android/ndk-stl-gabi++.cmake
+++ b/Modules/Platform/Android/ndk-stl-gabi++.cmake
@@ -1,6 +1,7 @@
# <ndk>/sources/cxx-stl/gabi++/Android.mk
set(_ANDROID_STL_RTTI 1)
set(_ANDROID_STL_EXCEPTIONS 1)
+set(_ANDROID_STL_NOSTDLIBXX 1)
macro(__android_stl_gabixx lang filename)
__android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gabi++/include" 1)
__android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${CMAKE_ANDROID_ARCH_ABI}/${filename}" 1)
diff --git a/Modules/Platform/Android/ndk-stl-gnustl.cmake b/Modules/Platform/Android/ndk-stl-gnustl.cmake
index b3226ee0e..46cedc601 100644
--- a/Modules/Platform/Android/ndk-stl-gnustl.cmake
+++ b/Modules/Platform/Android/ndk-stl-gnustl.cmake
@@ -1,6 +1,7 @@
# <ndk>/sources/cxx-stl/gnu-libstdc++/Android.mk
set(_ANDROID_STL_RTTI 1)
set(_ANDROID_STL_EXCEPTIONS 1)
+set(_ANDROID_STL_NOSTDLIBXX 1)
macro(__android_stl_gnustl lang filename)
__android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION}/include" 1)
__android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${CMAKE_${lang}_ANDROID_TOOLCHAIN_VERSION}/libs/${CMAKE_ANDROID_ARCH_ABI}/include" 1)
diff --git a/Modules/Platform/Android/ndk-stl-none.cmake b/Modules/Platform/Android/ndk-stl-none.cmake
index 9049c91de..45122f71a 100644
--- a/Modules/Platform/Android/ndk-stl-none.cmake
+++ b/Modules/Platform/Android/ndk-stl-none.cmake
@@ -1,2 +1,3 @@
+set(_ANDROID_STL_NOSTDLIBXX 1)
macro(__android_stl lang)
endmacro()
diff --git a/Modules/Platform/Android/ndk-stl-stlport.cmake b/Modules/Platform/Android/ndk-stl-stlport.cmake
index eab6b945c..efad33bdc 100644
--- a/Modules/Platform/Android/ndk-stl-stlport.cmake
+++ b/Modules/Platform/Android/ndk-stl-stlport.cmake
@@ -1,6 +1,7 @@
# <ndk>/sources/cxx-stl/stlport/Android.mk
set(_ANDROID_STL_RTTI 1)
set(_ANDROID_STL_EXCEPTIONS 1)
+set(_ANDROID_STL_NOSTDLIBXX 0)
macro(__android_stl_stlport lang filename)
__android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/stlport/stlport" 1)
__android_stl_lib(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/stlport/libs/${CMAKE_ANDROID_ARCH_ABI}/${filename}" 1)
diff --git a/Modules/Platform/Android/ndk-stl-system.cmake b/Modules/Platform/Android/ndk-stl-system.cmake
index dd554fe30..7d86a40ae 100644
--- a/Modules/Platform/Android/ndk-stl-system.cmake
+++ b/Modules/Platform/Android/ndk-stl-system.cmake
@@ -1,6 +1,7 @@
# <ndk>/android-ndk-r11c/sources/cxx-stl/system/Android.mk
set(_ANDROID_STL_RTTI 0)
set(_ANDROID_STL_EXCEPTIONS 0)
+set(_ANDROID_STL_NOSTDLIBXX 0)
macro(__android_stl lang)
__android_stl_inc(${lang} "${CMAKE_ANDROID_NDK}/sources/cxx-stl/system/include" 1)
endmacro()
diff --git a/Modules/Platform/CYGWIN-GNU.cmake b/Modules/Platform/CYGWIN-GNU.cmake
index 784c8c676..ca90712dc 100644
--- a/Modules/Platform/CYGWIN-GNU.cmake
+++ b/Modules/Platform/CYGWIN-GNU.cmake
@@ -27,6 +27,9 @@ macro(__cygwin_compiler_gnu lang)
# No -fPIC on cygwin
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
+ set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE "")
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
# Initialize C link type selection flags. These flags are used when
diff --git a/Modules/Platform/CrayLinuxEnvironment.cmake b/Modules/Platform/CrayLinuxEnvironment.cmake
index a1a3d3f10..f2aaf3f71 100644
--- a/Modules/Platform/CrayLinuxEnvironment.cmake
+++ b/Modules/Platform/CrayLinuxEnvironment.cmake
@@ -1,6 +1,5 @@
-# Compute Node Linux doesn't quite work the same as native Linux so all of this
-# needs to be custom. We use the variables defined through Cray's environment
-# modules to set up the right paths for things.
+# CrayLinuxEnvironment: loaded by users cross-compiling on a Cray front-end
+# node by specifying "-DCMAKE_SYSTEM_NAME=CrayLinuxEnvironment" to cmake
set(UNIX 1)
@@ -30,13 +29,6 @@ endif()
# Note: this may need to change in the future with 64-bit ARM
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
-set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
-set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
-set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
-set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
-
-set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
-
# Don't override shared lib support if it's already been set and possibly
# overridden elsewhere by the CrayPrgEnv module
if(NOT CMAKE_FIND_LIBRARY_SUFFIXES)
@@ -44,12 +36,9 @@ if(NOT CMAKE_FIND_LIBRARY_SUFFIXES)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()
-set(CMAKE_DL_LIBS dl)
+# The rest of this file is based on UnixPaths.cmake, adjusted for Cray
-# Note: Much of this is pulled from UnixPaths.cmake but adjusted to the Cray
-# environment accordingly
-
-# Get the install directory of the running cmake to the search directories
+# 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)
@@ -81,7 +70,6 @@ if (NOT CMAKE_FIND_NO_INSTALL_PREFIX)
endif()
list(APPEND CMAKE_SYSTEM_INCLUDE_PATH
- $ENV{SYSROOT_DIR}/usr/include
$ENV{SYSROOT_DIR}/usr/include/X11
)
list(APPEND CMAKE_SYSTEM_LIBRARY_PATH
@@ -95,57 +83,5 @@ list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
$ENV{SYSROOT_DIR}/lib64
)
-# Compute the intersection of several lists
-function(__cray_list_intersect OUTPUT INPUT0)
- if(ARGC EQUAL 2)
- list(APPEND ${OUTPUT} ${${INPUT0}})
- else()
- foreach(I IN LISTS ${INPUT0})
- set(__is_common 1)
- foreach(L IN LISTS ARGN)
- list(FIND ${L} "${I}" __idx)
- if(__idx EQUAL -1)
- set(__is_common 0)
- break()
- endif()
- endforeach()
- if(__is_common)
- list(APPEND ${OUTPUT} "${I}")
- endif()
- endforeach()
- endif()
- set(${OUTPUT} ${${OUTPUT}} PARENT_SCOPE)
-endfunction()
-
-macro(__list_clean_dupes var)
- if(${var})
- list(REMOVE_DUPLICATES ${var})
- endif()
-endmacro()
-
-get_property(__langs GLOBAL PROPERTY ENABLED_LANGUAGES)
-set(__cray_inc_path_vars)
-set(__cray_lib_path_vars)
-foreach(__lang IN LISTS __langs)
- list(APPEND __cray_inc_path_vars CMAKE_${__lang}_IMPLICIT_INCLUDE_DIRECTORIES)
- list(APPEND __cray_lib_path_vars CMAKE_${__lang}_IMPLICIT_LINK_DIRECTORIES)
-endforeach()
-if(__cray_inc_path_vars)
- __cray_list_intersect(__cray_implicit_include_dirs ${__cray_inc_path_vars})
- if(__cray_implicit_include_dirs)
- list(INSERT CMAKE_SYSTEM_INCLUDE_PATH 0 ${__cray_implicit_include_dirs})
- endif()
-endif()
-if(__cray_lib_path_vars)
- __cray_list_intersect(__cray_implicit_library_dirs ${__cray_lib_path_vars})
- if(__cray_implicit_library_dirs)
- list(INSERT CMAKE_SYSTEM_LIBRARY_PATH 0 ${__cray_implicit_library_dirs})
- endif()
-endif()
-__list_clean_dupes(CMAKE_SYSTEM_PREFIX_PATH)
-__list_clean_dupes(CMAKE_SYSTEM_INCLUDE_PATH)
-__list_clean_dupes(CMAKE_SYSTEM_LIBRARY_PATH)
-__list_clean_dupes(CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES)
-
# Enable use of lib64 search path variants by default.
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake
index b539e457d..2d797f68f 100644
--- a/Modules/Platform/Darwin-Initialize.cmake
+++ b/Modules/Platform/Darwin-Initialize.cmake
@@ -20,6 +20,10 @@ execute_process(COMMAND sw_vers -productVersion
set(CMAKE_OSX_ARCHITECTURES "$ENV{CMAKE_OSX_ARCHITECTURES}" CACHE STRING
"Build architectures for OSX")
+# macOS, iOS, tvOS, and watchOS should lookup compilers from
+# Platform/Apple-${CMAKE_CXX_COMPILER_ID}-<LANG>
+set(CMAKE_EFFECTIVE_SYSTEM_NAME "Apple")
+
#----------------------------------------------------------------------------
# _CURRENT_OSX_VERSION - as a two-component string: 10.5, 10.6, ...
#
@@ -30,7 +34,7 @@ string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*$" "\\1"
# 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)
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND _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()
@@ -45,6 +49,12 @@ 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_SYSTEM_NAME STREQUAL iOS)
+ set(_CMAKE_OSX_SYSROOT_DEFAULT "iphoneos")
+elseif(CMAKE_SYSTEM_NAME STREQUAL tvOS)
+ set(_CMAKE_OSX_SYSROOT_DEFAULT "appletvos")
+elseif(CMAKE_SYSTEM_NAME STREQUAL watchOS)
+ set(_CMAKE_OSX_SYSROOT_DEFAULT "watchos")
elseif("${CMAKE_GENERATOR}" MATCHES Xcode
OR CMAKE_OSX_DEPLOYMENT_TARGET
OR CMAKE_OSX_ARCHITECTURES MATCHES "[^;]"
diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake
index 727baa6e1..7e02814cd 100644
--- a/Modules/Platform/Darwin.cmake
+++ b/Modules/Platform/Darwin.cmake
@@ -1,5 +1,22 @@
set(APPLE 1)
+if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS")
+ if(NOT DEFINED CMAKE_MACOSX_BUNDLE)
+ set(CMAKE_MACOSX_BUNDLE ON)
+ endif()
+
+ list(APPEND CMAKE_FIND_ROOT_PATH "${_CMAKE_OSX_SYSROOT_PATH}")
+ if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+ endif()
+ if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+ endif()
+ if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
+ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+ endif()
+endif()
+
# Darwin versions:
# 6.x == Mac OSX 10.2 (Jaguar)
# 7.x == Mac OSX 10.3 (Panther)
@@ -206,7 +223,7 @@ 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)
+ list(APPEND _CMAKE_${lang}_IMPLICIT_INCLUDE_DIRECTORIES_INIT ${_CMAKE_OSX_SYSROOT_PATH}/usr/include)
endforeach()
endif()
list(APPEND CMAKE_SYSTEM_PREFIX_PATH
diff --git a/Modules/Platform/DragonFly.cmake b/Modules/Platform/DragonFly.cmake
index c22677b9d..12e5f3ccc 100644
--- a/Modules/Platform/DragonFly.cmake
+++ b/Modules/Platform/DragonFly.cmake
@@ -3,3 +3,7 @@
# see http://archive.netbsd.se/?ml=dfbsd-users&a=2007-07&m=4678361
include(Platform/FreeBSD)
+
+# DragonFly BSD requires -z origin to enable $ORIGIN expansion in RPATH.
+# This is not required for FreeBSD since 10.2-RELEASE.
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-z,origin,-rpath,")
diff --git a/Modules/Platform/FreeBSD.cmake b/Modules/Platform/FreeBSD.cmake
index ce4d3ce49..4a4c00dc4 100644
--- a/Modules/Platform/FreeBSD.cmake
+++ b/Modules/Platform/FreeBSD.cmake
@@ -1,11 +1,14 @@
set(CMAKE_DL_LIBS "")
set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+# PIE link options are managed in Compiler/<compiler>.cmake file
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
+# Does not require -z origin since 10.2-RELEASE
+set(CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN "\$ORIGIN")
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")
diff --git a/Modules/Platform/Fuchsia.cmake b/Modules/Platform/Fuchsia.cmake
index 896da7bfb..4b1380506 100644
--- a/Modules/Platform/Fuchsia.cmake
+++ b/Modules/Platform/Fuchsia.cmake
@@ -3,6 +3,9 @@ set(FUCHSIA 1)
set(CMAKE_DL_LIBS "")
set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER YES)
+set(CMAKE_C_LINK_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE} "-pie")
+set(CMAKE_C_LINK_OPTIONS_NO_PIE "-no-pie")
set(CMAKE_SHARED_LIBRARY_C_FLAGS "-fPIC")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
diff --git a/Modules/Platform/GNU.cmake b/Modules/Platform/GNU.cmake
index e8c3b657b..fac29a8fa 100644
--- a/Modules/Platform/GNU.cmake
+++ b/Modules/Platform/GNU.cmake
@@ -8,6 +8,33 @@ 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")
+# 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()
+
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
index 2da920ab0..8613be359 100644
--- a/Modules/Platform/GNUtoMS_lib.bat.in
+++ b/Modules/Platform/GNUtoMS_lib.bat.in
@@ -1,3 +1,4 @@
@echo off
+set VSCMD_START_DIR=.
call "@CMAKE_GNUtoMS_BAT@"
lib /machine:"@CMAKE_GNUtoMS_ARCH@" %*
diff --git a/Modules/Platform/Generic-ADSP-C.cmake b/Modules/Platform/Generic-ADSP-C.cmake
index de1cee298..c8597cda7 100644
--- a/Modules/Platform/Generic-ADSP-C.cmake
+++ b/Modules/Platform/Generic-ADSP-C.cmake
@@ -9,6 +9,9 @@ string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " ")
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " ")
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " ")
+set(CMAKE_C_LINKER_WRAPPER_FLAG "-flags-link" " ")
+set(CMAKE_C_LINKER_WRAPPER_FLAG_SEP ",")
+
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>")
@@ -17,4 +20,3 @@ set(CMAKE_C_LINK_EXECUTABLE
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
index 0cde8f2e6..d76bb66bd 100644
--- a/Modules/Platform/Generic-ADSP-CXX.cmake
+++ b/Modules/Platform/Generic-ADSP-CXX.cmake
@@ -7,6 +7,9 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " ")
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " ")
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " ")
+set(CMAKE_CXX_LINKER_WRAPPER_FLAG "-flags-link" " ")
+set(CMAKE_CXX_LINKER_WRAPPER_FLAG_SEP ",")
+
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>")
@@ -15,4 +18,3 @@ set(CMAKE_CXX_LINK_EXECUTABLE
set(CMAKE_CXX_CREATE_SHARED_LIBRARY)
set(CMAKE_CXX_CREATE_MODULE_LIBRARY)
-
diff --git a/Modules/Platform/Generic-SDCC-C.cmake b/Modules/Platform/Generic-SDCC-C.cmake
index bbefe193e..aef4abf17 100644
--- a/Modules/Platform/Generic-SDCC-C.cmake
+++ b/Modules/Platform/Generic-SDCC-C.cmake
@@ -37,11 +37,13 @@ if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
set (CMAKE_EXE_LINKER_FLAGS_INIT --model-small)
endif()
+set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl" ",")
+
# compile a C file into an object file
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <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>")
+set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
# needs sdcc 2.7.0 + sddclib from cvs
set(CMAKE_C_CREATE_STATIC_LIBRARY
@@ -51,4 +53,3 @@ set(CMAKE_C_CREATE_STATIC_LIBRARY
# not supported by sdcc
set(CMAKE_C_CREATE_SHARED_LIBRARY "")
set(CMAKE_C_CREATE_MODULE_LIBRARY "")
-
diff --git a/Modules/Platform/Haiku.cmake b/Modules/Platform/Haiku.cmake
index dfc2664d3..7e0af6166 100644
--- a/Modules/Platform/Haiku.cmake
+++ b/Modules/Platform/Haiku.cmake
@@ -11,6 +11,7 @@ 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_ORIGIN_TOKEN "\$ORIGIN")
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")
diff --git a/Modules/Platform/Linux-GNU.cmake b/Modules/Platform/Linux-GNU.cmake
index ce30a26a5..6878254ee 100644
--- a/Modules/Platform/Linux-GNU.cmake
+++ b/Modules/Platform/Linux-GNU.cmake
@@ -12,5 +12,4 @@ 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")
- set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}" "-dM" "-E" "-c" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
endmacro()
diff --git a/Modules/Platform/Linux-Intel.cmake b/Modules/Platform/Linux-Intel.cmake
index ee9aac26a..3b5ca59ca 100644
--- a/Modules/Platform/Linux-Intel.cmake
+++ b/Modules/Platform/Linux-Intel.cmake
@@ -23,6 +23,12 @@ endif()
macro(__linux_compiler_intel lang)
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
+ set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+ if (NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 13.0)
+ set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER YES)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie")
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie")
+ endif()
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
@@ -30,6 +36,9 @@ macro(__linux_compiler_intel lang)
# executables that use dlopen but do not set ENABLE_EXPORTS.
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
+ set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
+
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
if(XIAR)
diff --git a/Modules/Platform/Linux-PGI.cmake b/Modules/Platform/Linux-PGI.cmake
index db032c292..034165454 100644
--- a/Modules/Platform/Linux-PGI.cmake
+++ b/Modules/Platform/Linux-PGI.cmake
@@ -12,6 +12,9 @@ macro(__linux_compiler_pgi lang)
# Shared library compile and link flags.
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
+ set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE "")
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS " ")
diff --git a/Modules/Platform/Linux.cmake b/Modules/Platform/Linux.cmake
index 1f8c1b4c1..b5d5464ea 100644
--- a/Modules/Platform/Linux.cmake
+++ b/Modules/Platform/Linux.cmake
@@ -1,6 +1,7 @@
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_ORIGIN_TOKEN "\$ORIGIN")
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")
diff --git a/Modules/Platform/NetBSD.cmake b/Modules/Platform/NetBSD.cmake
index 1004eb310..d99cb4a77 100644
--- a/Modules/Platform/NetBSD.cmake
+++ b/Modules/Platform/NetBSD.cmake
@@ -1,11 +1,13 @@
set(CMAKE_DL_LIBS "")
set(CMAKE_C_COMPILE_OPTIONS_PIC "-fPIC")
set(CMAKE_C_COMPILE_OPTIONS_PIE "-fPIE")
+# PIE link options are managed in Compiler/<compiler>.cmake file
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_ORIGIN_TOKEN "\$ORIGIN")
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")
diff --git a/Modules/Platform/OpenBSD.cmake b/Modules/Platform/OpenBSD.cmake
index 6466a0a01..97e2a6a83 100644
--- a/Modules/Platform/OpenBSD.cmake
+++ b/Modules/Platform/OpenBSD.cmake
@@ -15,6 +15,10 @@ if(NOT CMAKE_PLATFORM_RUNTIME_PATH)
"${LDCONFIG_HINTS}")
endif()
+# OpenBSD requires -z origin to enable $ORIGIN expansion in RPATH.
+# This is not required for NetBSD.
+set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-z,origin,-rpath,")
+
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_OPENBSD_VERSIONING 1)
# OpenBSD has no multilib
diff --git a/Modules/Platform/SINIX.cmake b/Modules/Platform/SINIX.cmake
index c37a113d3..e3b0a0516 100644
--- a/Modules/Platform/SINIX.cmake
+++ b/Modules/Platform/SINIX.cmake
@@ -1,4 +1,7 @@
set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+set(CMAKE_C_LINK_OPTIONS_PIE "")
+set(CMAKE_C_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_C_FLAGS "-K PIC")
include(Platform/UnixPaths)
diff --git a/Modules/Platform/SunOS-GNU.cmake b/Modules/Platform/SunOS-GNU.cmake
index 485f23533..47334d6cb 100644
--- a/Modules/Platform/SunOS-GNU.cmake
+++ b/Modules/Platform/SunOS-GNU.cmake
@@ -11,6 +11,7 @@ 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_RPATH_ORIGIN_TOKEN "\$ORIGIN")
set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-h")
# Initialize C link type selection flags. These flags are used when
diff --git a/Modules/Platform/SunOS.cmake b/Modules/Platform/SunOS.cmake
index e19e89a27..78eccf706 100644
--- a/Modules/Platform/SunOS.cmake
+++ b/Modules/Platform/SunOS.cmake
@@ -1,10 +1,10 @@
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 ":")
+ 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()
include(Platform/UnixPaths)
diff --git a/Modules/Platform/UNIX_SV.cmake b/Modules/Platform/UNIX_SV.cmake
index 1ec96aea2..bd1ffce3a 100644
--- a/Modules/Platform/UNIX_SV.cmake
+++ b/Modules/Platform/UNIX_SV.cmake
@@ -1,5 +1,8 @@
set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+set(CMAKE_C_LINK_OPTIONS_PIE "")
+set(CMAKE_C_LINK_OPTIONS_NO_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
index 5687653cf..97f744d52 100644
--- a/Modules/Platform/UnixPaths.cmake
+++ b/Modules/Platform/UnixPaths.cmake
@@ -63,12 +63,28 @@ 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
+if(CMAKE_SYSROOT_COMPILE)
+ set(_cmake_sysroot_compile "${CMAKE_SYSROOT_COMPILE}")
+else()
+ set(_cmake_sysroot_compile "${CMAKE_SYSROOT}")
+endif()
+
+# Default per-language values. These may be later replaced after
+# parsing the implicit directory information from compiler output.
+set(_CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES_INIT
+ ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}
+ "${_cmake_sysroot_compile}/usr/include"
)
-list(APPEND CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
- /usr/include
+set(_CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES_INIT
+ ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}
+ "${_cmake_sysroot_compile}/usr/include"
)
+set(_CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES_INIT
+ ${CMAKE_CUDA_IMPLICIT_INCLUDE_DIRECTORIES}
+ "${_cmake_sysroot_compile}/usr/include"
+ )
+
+unset(_cmake_sysroot_compile)
# Enable use of lib32 and lib64 search path variants by default.
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS TRUE)
diff --git a/Modules/Platform/UnixWare.cmake b/Modules/Platform/UnixWare.cmake
index e649bd2a4..94888d9c0 100644
--- a/Modules/Platform/UnixWare.cmake
+++ b/Modules/Platform/UnixWare.cmake
@@ -1,5 +1,8 @@
set(CMAKE_C_COMPILE_OPTIONS_PIC -K PIC)
set(CMAKE_C_COMPILE_OPTIONS_PIE "")
+set(_CMAKE_C_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+set(CMAKE_C_LINK_OPTIONS_PIE "")
+set(CMAKE_C_LINK_OPTIONS_NO_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-Clang-CXX.cmake b/Modules/Platform/Windows-Clang-CXX.cmake
index 2c3688a36..f1d40f265 100644
--- a/Modules/Platform/Windows-Clang-CXX.cmake
+++ b/Modules/Platform/Windows-Clang-CXX.cmake
@@ -1,2 +1,3 @@
include(Platform/Windows-Clang)
+set(_COMPILE_CXX_MSVC " -TP")
__windows_compiler_clang(CXX)
diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake
index bcfda93cd..b317da650 100644
--- a/Modules/Platform/Windows-Clang.cmake
+++ b/Modules/Platform/Windows-Clang.cmake
@@ -8,12 +8,120 @@ if(__WINDOWS_CLANG)
endif()
set(__WINDOWS_CLANG 1)
+macro(__windows_compiler_clang_gnu lang)
+ set(CMAKE_LIBRARY_PATH_FLAG "-L")
+ set(CMAKE_LINK_LIBRARY_FLAG "-l")
+
+ set(CMAKE_IMPORT_LIBRARY_PREFIX "")
+ set(CMAKE_SHARED_LIBRARY_PREFIX "")
+ set(CMAKE_SHARED_MODULE_PREFIX "")
+ set(CMAKE_STATIC_LIBRARY_PREFIX "")
+ set(CMAKE_EXECUTABLE_SUFFIX ".exe")
+ set(CMAKE_IMPORT_LIBRARY_SUFFIX ".lib")
+ set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
+ set(CMAKE_SHARED_MODULE_SUFFIX ".dll")
+ set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
+ set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <OBJECT> -MF <DEPFILE>")
+
+ set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll" ".dll.a" ".a" ".lib")
+ set(CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS 1)
+ set (CMAKE_LINK_DEF_FILE_FLAG "-Xlinker /DEF:")
+
+ if("${CMAKE_${lang}_SIMULATE_VERSION}" MATCHES "^([0-9]+)\\.([0-9]+)")
+ math(EXPR MSVC_VERSION "${CMAKE_MATCH_1}*100 + ${CMAKE_MATCH_2}")
+ endif()
+
+ # No -fPIC on Windows
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
+ set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
+ set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE "")
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
+ set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
+
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
+ set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
+
+ # Create archiving rules to support large object file lists for static libraries.
+ set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
+ set(CMAKE_${lang}_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
+ set(CMAKE_${lang}_CREATE_SHARED_LIBRARY
+ "<CMAKE_${lang}_COMPILER> -nostartfiles -nostdlib <CMAKE_SHARED_LIBRARY_${lang}_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS> -o <TARGET> ${CMAKE_GNULD_IMAGE_VERSION} -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <OBJECTS> <LINK_LIBRARIES>")
+ set(CMAKE_${lang}_CREATE_SHARED_MODULE ${CMAKE_${lang}_CREATE_SHARED_LIBRARY})
+ set(CMAKE_${lang}_LINK_EXECUTABLE
+ "<CMAKE_${lang}_COMPILER> -nostartfiles -nostdlib <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> -Xlinker /implib:<TARGET_IMPLIB> -Xlinker /pdb:<TARGET_PDB> -Xlinker /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> ${CMAKE_GNULD_IMAGE_VERSION} <LINK_LIBRARIES>")
+
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -Xclang -flto-visibility-public-std -D_MT -Xclang --dependent-lib=libcmt)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -D_DLL -D_MT -Xclang --dependent-lib=msvcrt)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -D_DEBUG -Xclang -flto-visibility-public-std -D_MT -Xclang --dependent-lib=libcmtd)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd)
+
+ if(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT)
+ set(__ADDED_FLAGS "")
+ set(__ADDED_FLAGS_DEBUG "")
+ else()
+ set(__ADDED_FLAGS_DEBUG "-D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd")
+ set(__ADDED_FLAGS "-D_DLL -D_MT -Xclang --dependent-lib=msvcrt")
+ endif()
+
+ string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g -Xclang -gcodeview -O0 ${__ADDED_FLAGS_DEBUG}")
+ string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG ${__ADDED_FLAGS}")
+ string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG ${__ADDED_FLAGS}")
+ string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG -Xclang -gcodeview ${__ADDED_FLAGS}")
+ set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
+
+ unset(__ADDED_FLAGS)
+ unset(__ADDED_FLAGS_DEBUG)
+ string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE_LOWER)
+ set(CMAKE_${lang}_STANDARD_LIBRARIES_INIT "-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames")
+
+ enable_language(RC)
+endmacro()
+
if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
- include(Platform/Windows-MSVC)
- macro(__windows_compiler_clang lang)
- __windows_compiler_msvc(${lang})
- endmacro()
+
+ if ( DEFINED CMAKE_C_COMPILER_ID AND DEFINED CMAKE_CXX_COMPILER_ID
+ AND NOT "x${CMAKE_C_COMPILER_ID}" STREQUAL "x${CMAKE_CXX_COMPILER_ID}")
+ message(FATAL_ERROR "The current configuration mixes Clang and MSVC or "
+ "some other CL compatible compiler tool. This is not supported. "
+ "Use either clang or MSVC as both C and C++ compilers.")
+ endif()
+
+ if ( DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT AND DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT
+ AND NOT "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}")
+ message(FATAL_ERROR "The current configuration uses the Clang compiler "
+ "tool with mixed frontend variants, both the GNU and in MSVC CL "
+ "like variants. This is not supported. Use either clang/clang++ "
+ "or clang-cl as both C and C++ compilers.")
+ endif()
+
+ if ( "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" )
+ include(Platform/Windows-MSVC)
+
+ macro(__windows_compiler_clang lang)
+ set(_COMPILE_${lang} "${_COMPILE_${lang}_MSVC}")
+ __windows_compiler_msvc(${lang})
+ endmacro()
+ else()
+ cmake_policy(GET CMP0091 __WINDOWS_CLANG_CMP0091)
+ if(__WINDOWS_CLANG_CMP0091 STREQUAL "NEW")
+ set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
+ else()
+ set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "")
+ endif()
+ unset(__WINDOWS_CLANG_CMP0091)
+
+ set(CMAKE_BUILD_TYPE_INIT Debug)
+
+ macro(__windows_compiler_clang lang)
+ __windows_compiler_clang_gnu(${lang})
+ endmacro()
+ endif()
+
else()
include(Platform/Windows-GNU)
macro(__windows_compiler_clang lang)
diff --git a/Modules/Platform/Windows-Embarcadero.cmake b/Modules/Platform/Windows-Embarcadero.cmake
index f8e1c9e56..48b936eb6 100644
--- a/Modules/Platform/Windows-Embarcadero.cmake
+++ b/Modules/Platform/Windows-Embarcadero.cmake
@@ -76,6 +76,8 @@ macro(__embarcadero_language lang)
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "${_tD}") # ... while this is a space separated string.
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
+ set (CMAKE_${lang}_LINKER_WRAPPER_FLAG "-l")
+
# compile a source file into an object file
# place <DEFINES> outside the response file because Borland refuses
# to parse quotes from the response file.
diff --git a/Modules/Platform/Windows-GNU.cmake b/Modules/Platform/Windows-GNU.cmake
index cfb325b9d..71189b169 100644
--- a/Modules/Platform/Windows-GNU.cmake
+++ b/Modules/Platform/Windows-GNU.cmake
@@ -72,6 +72,9 @@ macro(__windows_compiler_gnu lang)
# No -fPIC on Windows
set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "")
set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "")
+ set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
+ set(CMAKE_${lang}_LINK_OPTIONS_PIE "")
+ set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "")
set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "")
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS ${__WINDOWS_GNU_LD_RESPONSE})
diff --git a/Modules/Platform/Windows-Intel-C.cmake b/Modules/Platform/Windows-Intel-C.cmake
index 767fec541..06d8f50ff 100644
--- a/Modules/Platform/Windows-Intel-C.cmake
+++ b/Modules/Platform/Windows-Intel-C.cmake
@@ -1,2 +1,4 @@
include(Platform/Windows-Intel)
__windows_compiler_intel(C)
+set(CMAKE_NINJA_DEPTYPE_C intel) # special value handled by CMake
+set(CMAKE_DEPFILE_FLAGS_C "-QMMD -QMT <OBJECT> -QMF <DEPFILE>")
diff --git a/Modules/Platform/Windows-Intel-CXX.cmake b/Modules/Platform/Windows-Intel-CXX.cmake
index 84cd303ec..666de6ee4 100644
--- a/Modules/Platform/Windows-Intel-CXX.cmake
+++ b/Modules/Platform/Windows-Intel-CXX.cmake
@@ -1,3 +1,5 @@
include(Platform/Windows-Intel)
set(_COMPILE_CXX " /TP")
__windows_compiler_intel(CXX)
+set(CMAKE_NINJA_DEPTYPE_CXX intel) # special value handled by CMake
+set(CMAKE_DEPFILE_FLAGS_CXX "-QMMD -QMT <OBJECT> -QMF <DEPFILE>")
diff --git a/Modules/Platform/Windows-Intel-Fortran.cmake b/Modules/Platform/Windows-Intel-Fortran.cmake
index 3981a092b..e3804fb86 100644
--- a/Modules/Platform/Windows-Intel-Fortran.cmake
+++ b/Modules/Platform/Windows-Intel-Fortran.cmake
@@ -4,8 +4,41 @@ set(_COMPILE_Fortran " /fpp")
set(CMAKE_Fortran_MODDIR_FLAG "-module:")
set(CMAKE_Fortran_STANDARD_LIBRARIES_INIT "user32.lib")
__windows_compiler_intel(Fortran)
-string(APPEND CMAKE_Fortran_FLAGS_INIT " /W1 /nologo /fpp /libs:dll /threads")
-string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " /Od /debug:full /dbglibs")
+if(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT)
+ set(_LIBSDLL "")
+ set(_DBGLIBS "")
+ set(_THREADS "")
+else()
+ set(_LIBSDLL " /libs:dll")
+ set(_DBGLIBS " /dbglibs")
+ set(_THREADS " /threads")
+endif()
+
+cmake_policy(GET CMP0092 _cmp0092)
+if(NOT _cmp0092 STREQUAL "NEW")
+ string(APPEND CMAKE_Fortran_FLAGS_INIT " /W1")
+endif()
+unset(_cmp0092)
+
+string(APPEND CMAKE_Fortran_FLAGS_INIT " /nologo /fpp${_LIBSDLL}${_THREADS}")
+string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " /Od /debug:full${_DBGLIBS}")
string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " /O1 /DNDEBUG")
string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " /O2 /DNDEBUG")
string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " /O2 /debug:full /DNDEBUG")
+unset(_LIBSDLL)
+unset(_DBGLIBS)
+unset(_THREADS)
+
+set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -threads -libs:static)
+set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -threads -libs:dll)
+set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -threads -libs:static -dbglibs)
+set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -threads -libs:dll -dbglibs)
+
+# Intel Fortran for Windows supports single-threaded RTL but it is
+# not implemented by the Visual Studio integration.
+if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_SingleThreaded -libs:static)
+ set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_SingleThreadedDLL -libs:dll)
+ set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_SingleThreadedDebug -libs:static -dbglibs)
+ set(CMAKE_Fortran_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_SingleThreadedDebugDLL -libs:dll -dbglibs)
+endif()
diff --git a/Modules/Platform/Windows-Intel.cmake b/Modules/Platform/Windows-Intel.cmake
index ba31001ea..96b1760ab 100644
--- a/Modules/Platform/Windows-Intel.cmake
+++ b/Modules/Platform/Windows-Intel.cmake
@@ -11,7 +11,7 @@ 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}")
+ string(REPLACE "<CMAKE_LINKER> /lib" "xilib" 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()
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index cfe6e1c21..7a83859ec 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -17,7 +17,7 @@ set(MSVC 1)
# 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)
+ set(CMAKE_LINKER link)
endif()
if(CMAKE_VERBOSE_MAKEFILE)
@@ -48,7 +48,11 @@ else()
endif()
if(NOT MSVC_VERSION)
- if(CMAKE_C_SIMULATE_VERSION)
+ if("x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC")
+ set(_compiler_version ${CMAKE_C_COMPILER_VERSION})
+ elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
+ set(_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
+ elseif(CMAKE_C_SIMULATE_VERSION)
set(_compiler_version ${CMAKE_C_SIMULATE_VERSION})
elseif(CMAKE_CXX_SIMULATE_VERSION)
set(_compiler_version ${CMAKE_CXX_SIMULATE_VERSION})
@@ -67,6 +71,34 @@ if(NOT MSVC_VERSION)
message(FATAL_ERROR "MSVC compiler version not detected properly: ${_compiler_version}")
endif()
+ if(MSVC_VERSION GREATER_EQUAL 1920)
+ # VS 2019 or greater
+ set(MSVC_TOOLSET_VERSION 142)
+ elseif(MSVC_VERSION GREATER_EQUAL 1910)
+ # VS 2017 or greater
+ set(MSVC_TOOLSET_VERSION 141)
+ elseif(MSVC_VERSION EQUAL 1900)
+ # VS 2015
+ set(MSVC_TOOLSET_VERSION 140)
+ elseif(MSVC_VERSION EQUAL 1800)
+ # VS 2013
+ set(MSVC_TOOLSET_VERSION 120)
+ elseif(MSVC_VERSION EQUAL 1700)
+ # VS 2012
+ set(MSVC_TOOLSET_VERSION 110)
+ elseif(MSVC_VERSION EQUAL 1600)
+ # VS 2010
+ set(MSVC_TOOLSET_VERSION 100)
+ elseif(MSVC_VERSION EQUAL 1500)
+ # VS 2008
+ set(MSVC_TOOLSET_VERSION 90)
+ elseif(MSVC_VERSION EQUAL 1400)
+ # VS 2005
+ set(MSVC_TOOLSET_VERSION 80)
+ else()
+ # We don't support MSVC_TOOLSET_VERSION for earlier compiler.
+ endif()
+
set(MSVC10)
set(MSVC11)
set(MSVC12)
@@ -122,7 +154,9 @@ set(CMAKE_BUILD_TYPE_INIT Debug)
# Compute an architecture family from the architecture id.
foreach(lang C CXX)
set(_MSVC_${lang}_ARCHITECTURE_FAMILY "${MSVC_${lang}_ARCHITECTURE_ID}")
- if(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^ARM")
+ if(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^ARM64")
+ set(_MSVC_${lang}_ARCHITECTURE_FAMILY "ARM64")
+ elseif(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^ARM")
set(_MSVC_${lang}_ARCHITECTURE_FAMILY "ARM")
elseif(_MSVC_${lang}_ARCHITECTURE_FAMILY MATCHES "^SH")
set(_MSVC_${lang}_ARCHITECTURE_FAMILY "SHx")
@@ -175,7 +209,7 @@ elseif(WINDOWS_PHONE OR WINDOWS_STORE)
set(CMAKE_C_STANDARD_LIBRARIES_INIT "WindowsApp.lib")
elseif(WINDOWS_PHONE)
set(CMAKE_C_STANDARD_LIBRARIES_INIT "WindowsPhoneCore.lib RuntimeObject.lib PhoneAppModelHost.lib")
- elseif(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM" OR _MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM")
+ elseif(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM" OR _MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM" OR _MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM64" OR _MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM64")
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")
@@ -183,10 +217,10 @@ elseif(WINDOWS_PHONE OR WINDOWS_STORE)
else()
set(_PLATFORM_DEFINES "/DWIN32")
- if(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM" OR _MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM")
+ if(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM" OR _MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM" OR _MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM64" OR _MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM64")
set(CMAKE_C_STANDARD_LIBRARIES_INIT "kernel32.lib user32.lib")
elseif(MSVC_VERSION GREATER 1310)
- if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "(v[0-9]+_clang_.*|LLVM-vs[0-9]+.*)")
+ if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*")
# Clang/C2 in MSVC14 Update 1 seems to not support -fsantinize (yet?)
# set(_RTC1 "-fsantinize=memory,safe-stack")
set(_FLAGS_CXX " -frtti -fexceptions")
@@ -215,6 +249,8 @@ set (CMAKE_LINK_DEF_FILE_FLAG "/DEF:")
if(MSVC_C_ARCHITECTURE_ID)
if(MSVC_C_ARCHITECTURE_ID MATCHES "^ARMV.I")
set(_MACHINE_ARCH_FLAG "/machine:THUMB")
+ elseif(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM64")
+ set(_MACHINE_ARCH_FLAG "/machine:ARM64")
elseif(_MSVC_C_ARCHITECTURE_FAMILY STREQUAL "ARM")
set(_MACHINE_ARCH_FLAG "/machine:ARM")
else()
@@ -223,6 +259,8 @@ if(MSVC_C_ARCHITECTURE_ID)
elseif(MSVC_CXX_ARCHITECTURE_ID)
if(MSVC_CXX_ARCHITECTURE_ID MATCHES "^ARMV.I")
set(_MACHINE_ARCH_FLAG "/machine:THUMB")
+ elseif(_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM64")
+ set(_MACHINE_ARCH_FLAG "/machine:ARM64")
elseif(_MSVC_CXX_ARCHITECTURE_FAMILY STREQUAL "ARM")
set(_MACHINE_ARCH_FLAG "/machine:ARM")
else()
@@ -260,11 +298,19 @@ endforeach()
string(APPEND CMAKE_STATIC_LINKER_FLAGS_INIT " ${_MACHINE_ARCH_FLAG}")
unset(_MACHINE_ARCH_FLAG)
+cmake_policy(GET CMP0091 __WINDOWS_MSVC_CMP0091)
+if(__WINDOWS_MSVC_CMP0091 STREQUAL "NEW")
+ set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
+else()
+ set(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT "")
+endif()
+unset(__WINDOWS_MSVC_CMP0091)
+
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 --intdir=<OBJECT_DIR> --manifests <MANIFESTS> -- ")
- set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe --intdir=<OBJECT_DIR> --manifests <MANIFESTS> -- ")
+ set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll --intdir=<OBJECT_DIR> --rc=<CMAKE_RC_COMPILER> --mt=<CMAKE_MT> --manifests <MANIFESTS> -- ")
+ set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe --intdir=<OBJECT_DIR> --rc=<CMAKE_RC_COMPILER> --mt=<CMAKE_MT> --manifests <MANIFESTS> -- ")
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}")
@@ -283,37 +329,99 @@ macro(__windows_compiler_msvc lang)
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}")
+ if("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC")
+ set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
+ set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
+
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "/GL")
+ set(CMAKE_${lang}_LINK_OPTIONS_IPO "/INCREMENTAL:NO" "/LTCG")
+ string(REPLACE "<LINK_FLAGS> " "/LTCG <LINK_FLAGS> "
+ CMAKE_${lang}_CREATE_STATIC_LIBRARY_IPO "${CMAKE_${lang}_CREATE_STATIC_LIBRARY}")
+ elseif("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang" OR
+ "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xFlang")
+ set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
+ set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
+
+ # '-flto=thin' available since Clang 3.9 and Xcode 8
+ # * http://clang.llvm.org/docs/ThinLTO.html#clang-llvm
+ # * https://trac.macports.org/wiki/XcodeVersionInfo
+ set(_CMAKE_LTO_THIN TRUE)
+ if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.9)
+ set(_CMAKE_LTO_THIN FALSE)
+ endif()
+
+ if(_CMAKE_LTO_THIN)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto=thin")
+ else()
+ set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto")
+ endif()
+ endif()
+
if("x${lang}" STREQUAL "xC" OR
"x${lang}" STREQUAL "xCXX")
- if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "(v[0-9]+_clang_.*|LLVM-vs[0-9]+.*)")
+ if(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT)
+ set(_MDd "")
+ set(_MD "")
+ else()
+ set(_MDd " /MDd")
+ set(_MD " /MD")
+ endif()
+
+ cmake_policy(GET CMP0092 _cmp0092)
+ if(_cmp0092 STREQUAL "NEW")
+ set(_W3 "")
+ set(_Wall "")
+ else()
+ set(_W3 " /W3")
+ set(_Wall " -Wall")
+ endif()
+ unset(_cmp0092)
+
+ if(CMAKE_VS_PLATFORM_TOOLSET MATCHES "v[0-9]+_clang_.*")
# note: MSVC 14 2015 Update 1 sets -fno-ms-compatibility by default, but this does not allow one to compile many projects
# that include MS's own headers. CMake itself is affected project too.
- string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} -fms-extensions -fms-compatibility -D_WINDOWS -Wall${_FLAGS_${lang}}")
- string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " /MDd -gline-tables-only -fno-inline -O0 ${_RTC1}")
- string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " /MD -O2 -DNDEBUG")
- string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " /MD -gline-tables-only -O2 -fno-inline -DNDEBUG")
- string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " /MD -DNDEBUG") # TODO: Add '-Os' once VS generator maps it properly for Clang
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} -fms-extensions -fms-compatibility -D_WINDOWS${_Wall}${_FLAGS_${lang}}")
+ string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT "${_MDd} -gline-tables-only -fno-inline -O0 ${_RTC1}")
+ string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT "${_MD} -O2 -DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "${_MD} -gline-tables-only -O2 -fno-inline -DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "${_MD} -DNDEBUG") # TODO: Add '-Os' once VS generator maps it properly for Clang
else()
- string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS /W3${_FLAGS_${lang}}")
- string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " /MDd /Zi /Ob0 /Od ${_RTC1}")
- string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " /MD /O2 /Ob2 /DNDEBUG")
- string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " /MD /Zi /O2 /Ob1 /DNDEBUG")
- string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " /MD /O1 /Ob1 /DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_INIT " ${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_${lang}} /D_WINDOWS${_W3}${_FLAGS_${lang}}")
+ string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT "${_MDd} /Zi /Ob0 /Od ${_RTC1}")
+ string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT "${_MD} /O2 /Ob2 /DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "${_MD} /Zi /O2 /Ob1 /DNDEBUG")
+ string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "${_MD} /O1 /Ob1 /DNDEBUG")
endif()
+ unset(_Wall)
+ unset(_W3)
+ unset(_MDd)
+ unset(_MD)
+
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -MT)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -MD)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -MTd)
+ set(CMAKE_${lang}_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -MDd)
endif()
set(CMAKE_${lang}_LINKER_SUPPORTS_PDB ON)
set(CMAKE_NINJA_DEPTYPE_${lang} msvc)
+ __windows_compiler_msvc_enable_rc("${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_${lang}}")
+endmacro()
+macro(__windows_compiler_msvc_enable_rc flags)
if(NOT CMAKE_RC_COMPILER_INIT)
set(CMAKE_RC_COMPILER_INIT rc)
endif()
if(NOT CMAKE_RC_FLAGS_INIT)
- string(APPEND CMAKE_RC_FLAGS_INIT " ${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_${lang}}")
+ # llvm-rc fails when flags are specified with /D and no space after
+ string(REPLACE " /D" " -D" fixed_flags " ${flags}")
+ string(APPEND CMAKE_RC_FLAGS_INIT " ${fixed_flags}")
endif()
if(NOT CMAKE_RC_FLAGS_DEBUG_INIT)
- string(APPEND CMAKE_RC_FLAGS_DEBUG_INIT " /D_DEBUG")
+ string(APPEND CMAKE_RC_FLAGS_DEBUG_INIT " -D_DEBUG")
endif()
enable_language(RC)
- set(CMAKE_NINJA_CMCLDEPS_RC 1)
+ if(NOT DEFINED CMAKE_NINJA_CMCLDEPS_RC)
+ set(CMAKE_NINJA_CMCLDEPS_RC 1)
+ endif()
endmacro()
diff --git a/Modules/Platform/Windows-NVIDIA-CUDA.cmake b/Modules/Platform/Windows-NVIDIA-CUDA.cmake
index 970c2c6d1..94d77b961 100644
--- a/Modules/Platform/Windows-NVIDIA-CUDA.cmake
+++ b/Modules/Platform/Windows-NVIDIA-CUDA.cmake
@@ -15,10 +15,10 @@ foreach(lib ${CMAKE_CUDA_HOST_IMPLICIT_LINK_LIBRARIES})
string(APPEND __IMPLICT_LINKS " \"${lib}\"")
endforeach()
set(CMAKE_CUDA_LINK_EXECUTABLE
- "<CMAKE_CUDA_HOST_LINK_LAUNCHER> <CMAKE_CUDA_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <LINK_LIBRARIES>${__IMPLICT_LINKS}")
+ "<CMAKE_CUDA_HOST_LINK_LAUNCHER> <LINK_FLAGS> <OBJECTS> /out:<TARGET> /implib:<TARGET_IMPLIB> /pdb:<TARGET_PDB> /version:<TARGET_VERSION_MAJOR>.<TARGET_VERSION_MINOR> <LINK_LIBRARIES>${__IMPLICT_LINKS}")
-set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll --intdir=<OBJECT_DIR> --manifests <MANIFESTS> -- ")
-set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe --intdir=<OBJECT_DIR> --manifests <MANIFESTS> -- ")
+set(_CMAKE_VS_LINK_DLL "<CMAKE_COMMAND> -E vs_link_dll --intdir=<OBJECT_DIR> --rc=<CMAKE_RC_COMPILER> --mt=<CMAKE_MT> --manifests <MANIFESTS> -- ")
+set(_CMAKE_VS_LINK_EXE "<CMAKE_COMMAND> -E vs_link_exe --intdir=<OBJECT_DIR> --rc=<CMAKE_RC_COMPILER> --mt=<CMAKE_MT> --manifests <MANIFESTS> -- ")
set(CMAKE_CUDA_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>${__IMPLICT_LINKS} ${CMAKE_END_TEMP_FILE}")
@@ -26,7 +26,7 @@ set(CMAKE_CUDA_CREATE_SHARED_MODULE ${CMAKE_CUDA_CREATE_SHARED_LIBRARY})
set(CMAKE_CUDA_CREATE_STATIC_LIBRARY "<CMAKE_LINKER> /lib ${CMAKE_CL_NOLOGO} <LINK_FLAGS> /out:<TARGET> <OBJECTS> ")
set(CMAKE_CUDA_LINKER_SUPPORTS_PDB ON)
set(CMAKE_CUDA_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_CUDA_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>${__IMPLICT_LINKS} ${CMAKE_END_TEMP_FILE}")
+ "${_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} <LINK_FLAGS> <LINK_LIBRARIES>${__IMPLICT_LINKS} ${CMAKE_END_TEMP_FILE}")
unset(_CMAKE_VS_LINK_EXE)
unset(_CMAKE_VS_LINK_EXE)
@@ -36,19 +36,60 @@ else()
set(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS "")
endif()
+# Add implicit host link directories that contain device libraries
+# to the device link line.
+set(__IMPLICT_DLINK_DIRS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
+if(__IMPLICT_DLINK_DIRS)
+ list(REMOVE_ITEM __IMPLICT_DLINK_DIRS ${CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES})
+endif()
+set(__IMPLICT_DLINK_FLAGS )
+foreach(dir ${__IMPLICT_DLINK_DIRS})
+ if(EXISTS "${dir}/curand_static.lib")
+ string(APPEND __IMPLICT_DLINK_FLAGS " -L\"${dir}\"")
+ endif()
+endforeach()
+unset(__IMPLICT_DLINK_DIRS)
+
set(CMAKE_CUDA_DEVICE_LINK_LIBRARY
- "<CMAKE_CUDA_COMPILER> <CMAKE_CUDA_LINK_FLAGS> <LANGUAGE_COMPILE_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS")
+ "<CMAKE_CUDA_COMPILER> <LANGUAGE_COMPILE_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}")
set(CMAKE_CUDA_DEVICE_LINK_EXECUTABLE
- "<CMAKE_CUDA_COMPILER> <FLAGS> <CMAKE_CUDA_LINK_FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS")
+ "<CMAKE_CUDA_COMPILER> <FLAGS> ${_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS} -shared -dlink <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Xcompiler=-Fd<TARGET_COMPILE_PDB>,-FS${__IMPLICT_DLINK_FLAGS}")
unset(_CMAKE_CUDA_EXTRA_DEVICE_LINK_FLAGS)
+unset(__IMPLICT_DLINK_FLAGS)
string(REPLACE "/D" "-D" _PLATFORM_DEFINES_CUDA "${_PLATFORM_DEFINES}${_PLATFORM_DEFINES_CXX}")
-string(APPEND CMAKE_CUDA_FLAGS_INIT " ${PLATFORM_DEFINES_CUDA} -D_WINDOWS -Xcompiler=\"/W3${_FLAGS_CXX}\"")
-string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -Xcompiler=\"-MDd -Zi -Ob0 -Od ${_RTC1}\"")
-string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -Xcompiler=\"-MD -O2 -Ob2\" -DNDEBUG")
-string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -Xcompiler=\"-MD -Zi -O2 -Ob1\" -DNDEBUG")
-string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Xcompiler=\"-MD -O1 -Ob1\" -DNDEBUG")
+if(CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT)
+ set(_MDd "")
+ set(_MD "")
+else()
+ set(_MDd "-MDd ")
+ set(_MD "-MD ")
+endif()
+
+cmake_policy(GET CMP0092 _cmp0092)
+if(_cmp0092 STREQUAL "NEW")
+ set(_W3 "")
+else()
+ set(_W3 "/W3")
+endif()
+unset(_cmp0092)
+
+string(APPEND CMAKE_CUDA_FLAGS_INIT " ${PLATFORM_DEFINES_CUDA} -D_WINDOWS -Xcompiler=\"${_W3}${_FLAGS_CXX}\"")
+string(APPEND CMAKE_CUDA_FLAGS_DEBUG_INIT " -Xcompiler=\"${_MDd}-Zi -Ob0 -Od ${_RTC1}\"")
+string(APPEND CMAKE_CUDA_FLAGS_RELEASE_INIT " -Xcompiler=\"${_MD}-O2 -Ob2\" -DNDEBUG")
+string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO_INIT " -Xcompiler=\"${_MD}-Zi -O2 -Ob1\" -DNDEBUG")
+string(APPEND CMAKE_CUDA_FLAGS_MINSIZEREL_INIT " -Xcompiler=\"${_MD}-O1 -Ob1\" -DNDEBUG")
+unset(_W3)
+unset(_MDd)
+unset(_MD)
+
+set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded -Xcompiler=-MT)
+set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -Xcompiler=-MD)
+set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -Xcompiler=-MTd)
+set(CMAKE_CUDA_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -Xcompiler=-MDd)
set(CMAKE_CUDA_STANDARD_LIBRARIES_INIT "${CMAKE_C_STANDARD_LIBRARIES_INIT}")
+
+__windows_compiler_msvc_enable_rc("${_PLATFORM_DEFINES} ${_PLATFORM_DEFINES_CXX}")
diff --git a/Modules/Platform/Windows-df.cmake b/Modules/Platform/Windows-df.cmake
index c59be457e..f94891427 100644
--- a/Modules/Platform/Windows-df.cmake
+++ b/Modules/Platform/Windows-df.cmake
@@ -30,9 +30,6 @@ set(CMAKE_Fortran_LINK_EXECUTABLE
set(CMAKE_CREATE_WIN32_EXE /winapp)
set(CMAKE_CREATE_CONSOLE_EXE )
-if(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)
diff --git a/Modules/ProcessorCount.cmake b/Modules/ProcessorCount.cmake
index 772a6150e..8c252566a 100644
--- a/Modules/ProcessorCount.cmake
+++ b/Modules/ProcessorCount.cmake
@@ -1,44 +1,45 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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, Linux, macOS, 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
@@ -69,6 +70,20 @@ function(ProcessorCount var)
endif()
if(NOT count)
+ # Linux (systems with nproc):
+ # Prefer nproc to getconf if available as getconf may return the host CPU count in Linux containers
+ find_program(ProcessorCount_cmd_nproc nproc)
+ mark_as_advanced(ProcessorCount_cmd_nproc)
+ if(ProcessorCount_cmd_nproc)
+ execute_process(COMMAND ${ProcessorCount_cmd_nproc}
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ OUTPUT_VARIABLE count)
+ #message("ProcessorCount: trying nproc '${ProcessorCount_cmd_nproc}'")
+ endif()
+ endif()
+
+ if(NOT count)
# Linux (systems with getconf):
find_program(ProcessorCount_cmd_getconf getconf)
mark_as_advanced(ProcessorCount_cmd_getconf)
@@ -114,22 +129,6 @@ function(ProcessorCount var)
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)
diff --git a/Modules/Qt4ConfigDependentSettings.cmake b/Modules/Qt4ConfigDependentSettings.cmake
index e21ecf42e..4699ecdad 100644
--- a/Modules/Qt4ConfigDependentSettings.cmake
+++ b/Modules/Qt4ConfigDependentSettings.cmake
@@ -1,13 +1,14 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# Qt4ConfigDependentSettings
-# --------------------------
-#
-#
-#
-# This file is included by FindQt4.cmake, don't include it directly.
+#[=======================================================================[.rst:
+Qt4ConfigDependentSettings
+--------------------------
+
+
+
+This file is included by FindQt4.cmake, don't include it directly.
+#]=======================================================================]
###############################################
#
@@ -255,7 +256,6 @@ 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})
diff --git a/Modules/Qt4Macros.cmake b/Modules/Qt4Macros.cmake
index 047891866..33cacf10b 100644
--- a/Modules/Qt4Macros.cmake
+++ b/Modules/Qt4Macros.cmake
@@ -1,13 +1,14 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# Qt4Macros
-# ---------
-#
-#
-#
-# This file is included by FindQt4.cmake, don't include it directly.
+#[=======================================================================[.rst:
+Qt4Macros
+---------
+
+
+
+This file is included by FindQt4.cmake, don't include it directly.
+#]=======================================================================]
######################################
#
@@ -139,19 +140,20 @@ 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 (${ARGC} GREATER 3 AND "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
+ # 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 (${ARGC} GREATER 3 AND "x${ARGV2}" STREQUAL "xTARGET")
+ set(moc_target ${ARGV3})
+ endif()
+ QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}")
+ set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file
+ set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE) # don't run autouic on this file
endmacro ()
@@ -166,6 +168,8 @@ macro (QT4_WRAP_CPP outfiles )
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_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file
+ set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE) # don't run autouic on this file
set(${outfiles} ${${outfiles}} ${outfile})
endforeach()
@@ -185,6 +189,8 @@ macro (QT4_WRAP_UI outfiles )
COMMAND Qt4::uic
ARGS ${ui_options} -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile} VERBATIM)
+ set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file
+ set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE) # don't run autouic on this file
set(${outfiles} ${${outfiles}} ${outfile})
endforeach ()
@@ -233,6 +239,8 @@ macro (QT4_ADD_RESOURCES outfiles )
ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile}
MAIN_DEPENDENCY ${infile}
DEPENDS ${_RC_DEPENDS} "${out_depends}" VERBATIM)
+ set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file
+ set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE) # don't run autouic on this file
set(${outfiles} ${${outfiles}} ${outfile})
endforeach ()
@@ -245,19 +253,19 @@ macro(QT4_ADD_DBUS_INTERFACE _sources _interface _basename)
set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
- get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
+ get_property(_nonamespace SOURCE ${_interface} PROPERTY NO_NAMESPACE)
if(_nonamespace)
set(_params -N -m)
else()
set(_params -m)
endif()
- get_source_file_property(_classname ${_interface} CLASSNAME)
+ get_property(_classname SOURCE ${_interface} PROPERTY CLASSNAME)
if(_classname)
set(_params ${_params} -c ${_classname})
endif()
- get_source_file_property(_include ${_interface} INCLUDE)
+ get_property(_include SOURCE ${_interface} PROPERTY INCLUDE)
if(_include)
set(_params ${_params} -i ${_include})
endif()
@@ -266,7 +274,8 @@ macro(QT4_ADD_DBUS_INTERFACE _sources _interface _basename)
COMMAND Qt4::qdbusxml2cpp ${_params} -p ${_basename} ${_infile}
DEPENDS ${_infile} VERBATIM)
- set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
+ set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file
+ set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOUIC TRUE) # don't run autouic on this file
QT4_GENERATE_MOC("${_header}" "${_moc}")
@@ -350,7 +359,8 @@ macro(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optional
endif()
QT4_GENERATE_MOC("${_header}" "${_moc}")
- set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
+ set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOMOC TRUE) # don't run automoc on this file
+ set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOUIC TRUE) # don't run autouic on this file
MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
@@ -374,7 +384,7 @@ macro(QT4_AUTOMOC)
# 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)
+ get_property(_skip SOURCE ${_abs_FILE} PROPERTY SKIP_AUTOMOC)
if ( NOT _skip AND EXISTS ${_abs_FILE} )
@@ -404,49 +414,49 @@ 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})
- string(APPEND _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)
- string(APPEND _pro_includes " \\\n \"${_abs_include}\"")
- endforeach()
- file(GENERATE OUTPUT ${_ts_pro} CONTENT "SOURCES =${_pro_srcs}\nINCLUDEPATH =${_pro_includes}\n")
- endif()
- add_custom_command(OUTPUT ${_ts_file}
+ 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})
+ string(APPEND _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)
+ string(APPEND _pro_includes " \\\n \"${_abs_include}\"")
+ endforeach()
+ file(GENERATE OUTPUT ${_ts_pro} CONTENT "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})
+ endforeach()
+ QT4_ADD_TRANSLATION(${_qm_files} ${_my_tsfiles})
endmacro()
@@ -454,7 +464,7 @@ 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)
+ get_property(output_location SOURCE ${_abs_FILE} PROPERTY OUTPUT_LOCATION)
if(output_location)
file(MAKE_DIRECTORY "${output_location}")
set(qm "${output_location}/${qm}.qm")
diff --git a/Modules/SelectLibraryConfigurations.cmake b/Modules/SelectLibraryConfigurations.cmake
index dce6f9926..4c0e9a8c0 100644
--- a/Modules/SelectLibraryConfigurations.cmake
+++ b/Modules/SelectLibraryConfigurations.cmake
@@ -1,36 +1,45 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+SelectLibraryConfigurations
+---------------------------
+
+.. code-block:: cmake
+
+ select_library_configurations(basename)
+
+This macro takes a library base name as an argument, and will choose
+good values for the variables
+
+::
+
+ basename_LIBRARY
+ basename_LIBRARIES
+ basename_LIBRARY_DEBUG
+ 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.
+#]=======================================================================]
# This macro was adapted from the FindQt4 CMake module and is maintained by Will
# Dicharry <wdicharry@stellarscience.com>.
-macro( select_library_configurations basename )
+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()
@@ -38,11 +47,12 @@ macro( select_library_configurations basename )
set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
endif()
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
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.
+ ( _isMultiConfig OR CMAKE_BUILD_TYPE ) )
+ # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
+ # single-config generators, set optimized and debug libraries
set( ${basename}_LIBRARY "" )
foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE )
list( APPEND ${basename}_LIBRARY optimized "${_libname}" )
diff --git a/Modules/Squish4RunTestCase.bat b/Modules/Squish4RunTestCase.bat
index ad1cc8c3b..c6582085a 100755
--- a/Modules/Squish4RunTestCase.bat
+++ b/Modules/Squish4RunTestCase.bat
@@ -1,24 +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%
+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/SquishTestScript.cmake b/Modules/SquishTestScript.cmake
index cfdfaec1b..2a80be56f 100644
--- a/Modules/SquishTestScript.cmake
+++ b/Modules/SquishTestScript.cmake
@@ -1,21 +1,22 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
# print out the variable that we are using
message(STATUS "squish_aut='${squish_aut}'")
@@ -34,7 +35,7 @@ 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
+# parse environment variables
foreach(i ${squish_env_vars})
message(STATUS "parsing env var key/value pair ${i}")
string(REGEX MATCH "([^=]*)=(.*)" squish_env_name ${i})
diff --git a/Modules/TestBigEndian.cmake b/Modules/TestBigEndian.cmake
index cc627d016..0c6e188c0 100644
--- a/Modules/TestBigEndian.cmake
+++ b/Modules/TestBigEndian.cmake
@@ -1,18 +1,21 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
+
+include(CheckTypeSize)
macro(TEST_BIG_ENDIAN VARIABLE)
if(NOT DEFINED HAVE_${VARIABLE})
@@ -27,8 +30,6 @@ macro(TEST_BIG_ENDIAN VARIABLE)
message(FATAL_ERROR "TEST_BIG_ENDIAN needs either C or CXX language enabled")
endif()
- include(CheckTypeSize)
-
CHECK_TYPE_SIZE("unsigned short" CMAKE_SIZEOF_UNSIGNED_SHORT LANGUAGE ${_test_language})
if(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2)
message(STATUS "Using unsigned short")
diff --git a/Modules/TestCXXAcceptsFlag.cmake b/Modules/TestCXXAcceptsFlag.cmake
index 10019ec68..92a362e2f 100644
--- a/Modules/TestCXXAcceptsFlag.cmake
+++ b/Modules/TestCXXAcceptsFlag.cmake
@@ -1,22 +1,25 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.rst:
+TestCXXAcceptsFlag
+------------------
+
+.. deprecated:: 3.0
+
+ 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
+#]=======================================================================]
macro(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
if(NOT DEFINED ${VARIABLE})
diff --git a/Modules/TestForANSIForScope.cmake b/Modules/TestForANSIForScope.cmake
index 7d2aad61b..272e4ec8b 100644
--- a/Modules/TestForANSIForScope.cmake
+++ b/Modules/TestForANSIForScope.cmake
@@ -1,18 +1,19 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
if(NOT DEFINED CMAKE_ANSI_FOR_SCOPE)
message(STATUS "Check for ANSI scope")
diff --git a/Modules/TestForANSIStreamHeaders.cmake b/Modules/TestForANSIStreamHeaders.cmake
index e890c677f..e532a71b7 100644
--- a/Modules/TestForANSIStreamHeaders.cmake
+++ b/Modules/TestForANSIStreamHeaders.cmake
@@ -1,18 +1,19 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CheckIncludeFileCXX.cmake)
diff --git a/Modules/TestForSSTREAM.cmake b/Modules/TestForSSTREAM.cmake
index 0bfbfbbbd..e70df00ab 100644
--- a/Modules/TestForSSTREAM.cmake
+++ b/Modules/TestForSSTREAM.cmake
@@ -1,17 +1,18 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
if(NOT DEFINED CMAKE_HAS_ANSI_STRING_STREAM)
message(STATUS "Check for sstream")
diff --git a/Modules/TestForSTDNamespace.cmake b/Modules/TestForSTDNamespace.cmake
index 3ae80c744..703e631eb 100644
--- a/Modules/TestForSTDNamespace.cmake
+++ b/Modules/TestForSTDNamespace.cmake
@@ -1,17 +1,18 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# TestForSTDNamespace
-# -------------------
-#
-# Test for std:: namespace support
-#
-# check if the compiler supports std:: on stl classes
-#
-# ::
-#
-# CMAKE_NO_STD_NAMESPACE - defined by the results
+#[=======================================================================[.rst:
+TestForSTDNamespace
+-------------------
+
+Test for std:: namespace support
+
+check if the compiler supports std:: on stl classes
+
+::
+
+ CMAKE_NO_STD_NAMESPACE - defined by the results
+#]=======================================================================]
if(NOT DEFINED CMAKE_STD_NAMESPACE)
message(STATUS "Check for STD namespace")
diff --git a/Modules/UseEcos.cmake b/Modules/UseEcos.cmake
index 942bc38bb..60324b1bd 100644
--- a/Modules/UseEcos.cmake
+++ b/Modules/UseEcos.cmake
@@ -1,68 +1,69 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
# 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.")
+ 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}")
+ 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")
+ 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}")
+ 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.")
+ 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}")
+ 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 ()
+ 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/)
+ include_directories(${CMAKE_CURRENT_BINARY_DIR}/ecos/install/include/)
endmacro()
@@ -70,47 +71,47 @@ 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")
+ 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")
+ set(ECOS_LD_MCPU "-mcpu=xscale")
#for compiling
- add_definitions(-mcpu=xscale -mapcs-frame)
+ add_definitions(-mcpu=xscale -mapcs-frame)
#for the obj-tools
- set(ECOS_ARCH_PREFIX "arm-elf-")
+ 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")
+ 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 "")
+ set(ECOS_LD_MCPU "")
#for compiling
- add_definitions()
+ add_definitions()
#for the obj-tools
- set(ECOS_ARCH_PREFIX "powerpc-eabi-")
+ 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")
+ 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 "")
+ set(ECOS_LD_MCPU "")
#for compiling
- add_definitions()
+ add_definitions()
#for the obj-tools
- set(ECOS_ARCH_PREFIX "i386-elf-")
+ set(ECOS_ARCH_PREFIX "i386-elf-")
endmacro ()
@@ -121,13 +122,13 @@ endmacro ()
#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)
+ 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)
+ get_filename_component(_abs_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../${_current_FILE} ABSOLUTE)
endif ()
- list(APPEND ${_target_FILES} ${_abs_FILE})
- endforeach ()
+ list(APPEND ${_target_FILES} ${_abs_FILE})
+ endforeach ()
endmacro()
# the default ecos config file name
@@ -138,29 +139,29 @@ set(ECOS_CONFIG_FILE ecos.ecc)
#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()
+ 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 )
+ 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
@@ -172,64 +173,64 @@ get_filename_component( ECOS_CMAKE_MODULE_DIR ${CMAKE_CURRENT_LIST_FILE} 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)
+ #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})
+ ECOS_ADD_TARGET_LIB(${ARGN})
-# when using nmake makefiles, the custom buildtype supresses the default cl.exe flags
+# when using nmake makefiles, the custom buildtype suppresses 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> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
- set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+ set(CMAKE_BUILD_TYPE CUSTOM_ECOS_BUILD)
+ set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+ set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <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}")
+ 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")
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
+ set (CMAKE_CXX_FLAGS "${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")
+ 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
- )
+ 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_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 )
+ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_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
index 11828757b..07984885b 100644
--- a/Modules/UseJava.cmake
+++ b/Modules/UseJava.cmake
@@ -1,409 +1,374 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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. Source files can be java files or listing files
-# (prefixed by '@'). 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() function 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.
-# CLASSDIR 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)
-# install_jar(target_name DESTINATION destination [COMPONENT component])
-#
-# 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.
-#
-# Target Properties:
-#
-# ::
-#
-# The install_jar() function sets the INSTALL_DESTINATION target property
-# on jars so installed. This property holds the DESTINATION as described
-# above, and is used by install_jar_exports(). You can get this property
-# with the
-# get_property(TARGET <target_name> PROPERTY INSTALL_DESTINATION)
-# command.
-#
-#
-#
-# ::
-#
-# install_jni_symlink(target_name destination)
-# install_jni_symlink(target_name DESTINATION destination [COMPONENT component])
-#
-# 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.
-#
-# ::
-#
-# install_jar_exports(TARGETS jars...
-# [NAMESPACE <namespace>]
-# FILE <filename>
-# DESTINATION <dir> [COMPONENT <component>])
-#
-# This command installs a target export file ``<filename>`` for the named jar
-# targets to the given ``DESTINATION``. Its function is similar to that of
-# :command:`install(EXPORTS ...)`.
-#
-# ::
-#
-# export_jars(TARGETS jars...
-# [NAMESPACE <namespace>]
-# FILE <filename>)
-#
-# This command writes a target export file ``<filename>`` for the named jar
-# targets. Its function is similar to that of :command:`export(...)`.
-#
-# ::
-#
-# 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.
-#
-# ::
-#
-# create_javah(TARGET <target>
-# GENERATED_FILES <VAR>
-# CLASSES <class>...
-# [CLASSPATH <classpath>...]
-# [DEPENDS <depend>...]
-# [OUTPUT_NAME <path>|OUTPUT_DIR <path>]
-# )
-#
-# Create C header files from java classes. These files provide the connective glue
-# that allow your Java and C code to interact.
-#
-# There are two main signatures for create_javah. The first signature
-# returns generated files through variable specified by GENERATED_FILES option:
-#
-# ::
-#
-# Example:
-# Create_javah(GENERATED_FILES files_headers
-# CLASSES org.cmake.HelloWorld
-# CLASSPATH hello.jar
-# )
-#
-#
-#
-# The second signature for create_javah creates a target which encapsulates
-# header files generation.
-#
-# ::
-#
-# Example:
-# Create_javah(TARGET target_headers
-# CLASSES org.cmake.HelloWorld
-# CLASSPATH hello.jar
-# )
-#
-#
-#
-# Both signatures share same options.
-#
-# ``CLASSES <class>...``
-# Specifies Java classes used to generate headers.
-#
-# ``CLASSPATH <classpath>...``
-# Specifies various paths to look up classes. Here .class files, jar files or targets
-# created by command add_jar can be used.
-#
-# ``DEPENDS <depend>...``
-# Targets on which the javah target depends
-#
-# ``OUTPUT_NAME <path>``
-# Concatenates the resulting header files for all the classes listed by option CLASSES
-# into <path>. Same behavior as option '-o' of javah tool.
-#
-# ``OUTPUT_DIR <path>``
-# Sets the directory where the header files will be generated. Same behavior as option
-# '-d' of javah tool. If not specified, ${CMAKE_CURRENT_BINARY_DIR} is used as output directory.
+#[=======================================================================[.rst:
+UseJava
+-------
+
+Use Module for Java
+
+This file provides functions for Java. It is assumed that
+:module:`FindJava` has already been loaded. See :module:`FindJava` for
+information on how to load Java into your CMake project.
+
+Creating And Installing JARs
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: cmake
+
+ add_jar(<target_name>
+ [SOURCES] <source1> [<source2>...] [<resource1>...]
+ [INCLUDE_JARS <jar1> [<jar2>...]]
+ [ENTRY_POINT <entry>]
+ [VERSION <version>]
+ [OUTPUT_NAME <name>]
+ [OUTPUT_DIR <dir>]
+ [GENERATE_NATIVE_HEADERS <target> [DESTINATION <dir>]]
+ )
+
+This command creates a ``<target_name>.jar``. It compiles the given
+``<source>`` files and adds the given ``<resource>`` files to
+the jar file. Source files can be java files or listing files
+(prefixed by ``@``). 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``.
+
+Optionally, using option ``GENERATE_NATIVE_HEADERS``, native header files can
+be generated for methods declared as native. These files provide the
+connective glue that allow your Java and C code to interact. An INTERFACE
+target will be created for an easy usage of generated files. Sub-option
+``DESTINATION`` can be used to specify the output directory for generated
+header files.
+
+``GENERATE_NATIVE_HEADERS`` option requires, at least, version 1.8 of the JDK.
+
+The ``add_jar()`` function sets the following target properties on
+``<target_name>``:
+
+``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.
+``CLASSDIR``
+ The directory where the class files can be found. For example to use them
+ with ``javah``.
+
+.. code-block:: cmake
+
+ install_jar(<target_name> <destination>)
+ install_jar(<target_name> DESTINATION <destination> [COMPONENT <component>])
+
+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.
+
+The ``install_jar()`` function sets the ``INSTALL_DESTINATION`` target
+property on jars so installed. This property holds the ``<destination>`` as
+described above, and is used by ``install_jar_exports()``. You can get this
+information with :command:`get_property` and the ``INSTALL_DESTINATION``
+property key.
+
+.. code-block:: cmake
+
+ install_jni_symlink(<target_name> <destination>)
+ install_jni_symlink(<target_name> DESTINATION <destination> [COMPONENT <component>])
+
+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.
+
+.. code-block:: cmake
+
+ install_jar_exports(TARGETS <jars>...
+ [NAMESPACE <namespace>]
+ FILE <filename>
+ DESTINATION <destination> [COMPONENT <component>])
+
+This command installs a target export file ``<filename>`` for the named jar
+targets to the given ``<destination>`` directory. Its function is similar to
+that of :command:`install(EXPORTS)`.
+
+.. code-block:: cmake
+
+ export_jars(TARGETS <jars>...
+ [NAMESPACE <namespace>]
+ FILE <filename>)
+
+This command writes a target export file ``<filename>`` for the named ``<jars>``
+targets. Its function is similar to that of :command:`export`.
+
+
+Examples
+""""""""
+
+To add compile flags to the target you can set these flags with the following
+variable:
+
+.. code-block:: cmake
+
+ 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.
+
+.. code-block:: cmake
+
+ set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/shibboleet.jar)
+
+To use a different output name for the target you can set it with:
+
+.. code-block:: cmake
+
+ 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:
+
+.. code-block:: cmake
+
+ 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:
+
+.. code-block:: cmake
+
+ 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:
+
+.. code-block:: cmake
+
+ 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()``. The following example 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.
+
+.. code-block:: cmake
+
+ 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:
+
+.. code-block:: cmake
+
+ 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:
+
+.. code-block:: cmake
+
+ 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)
+
+For an optimum usage of option ``GENERATE_NATIVE_HEADERS``, it is recommended to
+include module JNI before any call to ``add_jar()``. The produced target for
+native headers can then be used to compile C/C++ sources with the
+:command:`target_link_libraries` command.
+
+.. code-block:: cmake
+
+ find_package(JNI)
+ add_jar(foo foo.java GENERATE_NATIVE_HEADERS foo-native)
+ add_library(bar bar.cpp)
+ target_link_libraries(bar PRIVATE foo-native)
+
+
+Finding JARs
+^^^^^^^^^^^^
+
+.. code-block:: cmake
+
+ 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 store 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.
+
+
+Javadoc
+^^^^^^^
+
+The ``create_javadoc()`` command can be used to 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.
+
+.. code-block:: cmake
+
+ 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]
+ )
+
+For example:
+
+.. code-block:: cmake
+
+ create_javadoc(my_example_doc
+ PACKAGES com.example.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.
+
+.. code-block:: cmake
+
+ 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]
+ )
+
+For example:
+
+.. code-block:: cmake
+
+ 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``.
+
+If you don't set the ``INSTALLPATH``, then by default the documentation will
+be installed to :
+
+::
+
+ ${CMAKE_INSTALL_PREFIX}/share/javadoc/<VAR>
+
+
+Header Generation
+^^^^^^^^^^^^^^^^^
+
+.. code-block:: cmake
+
+ create_javah(TARGET <target> | GENERATED_FILES <VAR>
+ CLASSES <class>...
+ [CLASSPATH <classpath>...]
+ [DEPENDS <depend>...]
+ [OUTPUT_NAME <path>|OUTPUT_DIR <path>]
+ )
+
+Create C header files from java classes. These files provide the connective glue
+that allow your Java and C code to interact.
+
+.. deprecated:: 3.11
+
+.. note::
+
+ This command will no longer be supported starting with version 10 of the JDK
+ due to the `suppression of javah tool <http://openjdk.java.net/jeps/313>`_.
+ The ``add_jar(GENERATE_NATIVE_HEADERS)`` command should be used instead.
+
+There are two main signatures for ``create_javah()``. The first signature
+returns generated files through variable specified by the ``GENERATED_FILES``
+option. For example:
+
+.. code-block:: cmake
+
+ create_javah(GENERATED_FILES files_headers
+ CLASSES org.cmake.HelloWorld
+ CLASSPATH hello.jar
+ )
+
+The second signature for ``create_javah()`` creates a target which encapsulates
+header files generation. E.g.
+
+.. code-block:: cmake
+
+ create_javah(TARGET target_headers
+ CLASSES org.cmake.HelloWorld
+ CLASSPATH hello.jar
+ )
+
+Both signatures share same options.
+
+``CLASSES <class>...``
+ Specifies Java classes used to generate headers.
+
+``CLASSPATH <classpath>...``
+ Specifies various paths to look up classes. Here .class files, jar files or
+ targets created by command add_jar can be used.
+
+``DEPENDS <depend>...``
+ Targets on which the javah target depends.
+
+``OUTPUT_NAME <path>``
+ Concatenates the resulting header files for all the classes listed by option
+ ``CLASSES`` into ``<path>``. Same behavior as option ``-o`` of javah tool.
+
+``OUTPUT_DIR <path>``
+ Sets the directory where the header files will be generated. Same behavior
+ as option ``-d`` of javah tool. If not specified,
+ :variable:`CMAKE_CURRENT_BINARY_DIR` is used as the output directory.
+#]=======================================================================]
function (__java_copy_file src dest comment)
add_custom_command(
@@ -416,7 +381,7 @@ function (__java_copy_file src dest comment)
endfunction ()
function(__java_lcat VAR)
- foreach(_line ${ARGN})
+ foreach(_line IN LISTS ARGN)
string(APPEND ${VAR} "${_line}\n")
endforeach()
@@ -448,7 +413,7 @@ function(add_jar _TARGET_NAME)
cmake_parse_arguments(_add_jar
""
"VERSION;OUTPUT_DIR;OUTPUT_NAME;ENTRY_POINT;MANIFEST"
- "SOURCES;INCLUDE_JARS"
+ "SOURCES;INCLUDE_JARS;GENERATE_NATIVE_HEADERS"
${ARGN}
)
@@ -481,6 +446,8 @@ function(add_jar _TARGET_NAME)
else()
get_filename_component(_add_jar_OUTPUT_DIR ${_add_jar_OUTPUT_DIR} ABSOLUTE)
endif()
+ # ensure output directory exists
+ file (MAKE_DIRECTORY "${_add_jar_OUTPUT_DIR}")
if (_add_jar_ENTRY_POINT)
set(_ENTRY_POINT_OPTION e)
@@ -492,6 +459,31 @@ function(add_jar _TARGET_NAME)
get_filename_component (_MANIFEST_VALUE "${_add_jar_MANIFEST}" ABSOLUTE)
endif ()
+ unset (_GENERATE_NATIVE_HEADERS)
+ if (_add_jar_GENERATE_NATIVE_HEADERS)
+ # Raise an error if JDK version is less than 1.8 because javac -h is not supported
+ # by earlier versions.
+ if (Java_VERSION VERSION_LESS 1.8)
+ message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS is not supported with this version of Java.")
+ endif()
+ cmake_parse_arguments (_add_jar_GENERATE_NATIVE_HEADERS "" "DESTINATION" "" ${_add_jar_GENERATE_NATIVE_HEADERS})
+ if (NOT _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS)
+ message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: missing required argument.")
+ endif()
+ list (LENGTH _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS length)
+ if (length GREATER 1)
+ list (REMOVE_AT _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS 0)
+ message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: ${_add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS}: unexpected argument(s).")
+ endif()
+ if (NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION)
+ set (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers")
+ endif()
+
+ set (_GENERATE_NATIVE_HEADERS_TARGET ${_add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS})
+ set (_GENERATE_NATIVE_HEADERS_OUTPUT_DIR "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION}")
+ set (_GENERATE_NATIVE_HEADERS -h "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}")
+ endif()
+
if (LIBRARY_OUTPUT_PATH)
set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH})
else ()
@@ -511,11 +503,11 @@ function(add_jar _TARGET_NAME)
set(CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
endif()
- foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH})
+ foreach (JAVA_INCLUDE_DIR IN LISTS CMAKE_JAVA_INCLUDE_PATH)
string(APPEND 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(CMAKE_JAVA_CLASS_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir")
set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar")
if (_add_jar_OUTPUT_NAME AND _add_jar_VERSION)
@@ -535,7 +527,7 @@ function(add_jar _TARGET_NAME)
set(_JAVA_COMPILE_DEPENDS)
set(_JAVA_RESOURCE_FILES)
set(_JAVA_RESOURCE_FILES_RELATIVE)
- foreach(_JAVA_SOURCE_FILE ${_JAVA_SOURCE_FILES})
+ foreach(_JAVA_SOURCE_FILE IN LISTS _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)
@@ -546,11 +538,11 @@ function(add_jar _TARGET_NAME)
list(APPEND _JAVA_COMPILE_FILELISTS ${_JAVA_FULL})
elseif (_JAVA_EXT MATCHES ".java")
- file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
+ file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${CMAKE_CURRENT_BINARY_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})
+ if (_BIN_LEN LESS _SRC_LEN)
set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH})
else ()
set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH})
@@ -580,14 +572,14 @@ function(add_jar _TARGET_NAME)
endif ()
endforeach()
- foreach(_JAVA_INCLUDE_JAR ${_add_jar_INCLUDE_JARS})
+ foreach(_JAVA_INCLUDE_JAR IN LISTS _add_jar_INCLUDE_JARS)
if (TARGET ${_JAVA_INCLUDE_JAR})
get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE)
if (_JAVA_JAR_PATH)
string(APPEND 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})
+ list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_JAR_PATH})
else ()
message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar")
endif ()
@@ -623,6 +615,7 @@ function(add_jar _TARGET_NAME)
${CMAKE_JAVA_COMPILE_FLAGS}
-classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
-d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
+ ${_GENERATE_NATIVE_HEADERS}
${_JAVA_SOURCES_FILELISTS}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS}
@@ -647,7 +640,7 @@ function(add_jar _TARGET_NAME)
# create the jar file
set(_JAVA_JAR_OUTPUT_PATH
- ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME})
+ "${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME}")
if (CMAKE_JNI_TARGET)
add_custom_command(
OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
@@ -733,6 +726,18 @@ function(add_jar _TARGET_NAME)
${CMAKE_JAVA_CLASS_OUTPUT_PATH}
)
+ if (_GENERATE_NATIVE_HEADERS)
+ # create an INTERFACE library encapsulating include directory for generated headers
+ add_library (${_GENERATE_NATIVE_HEADERS_TARGET} INTERFACE)
+ target_include_directories (${_GENERATE_NATIVE_HEADERS_TARGET} INTERFACE
+ "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}"
+ ${JNI_INCLUDE_DIRS})
+ # this INTERFACE library depends on jar generation
+ add_dependencies (${_GENERATE_NATIVE_HEADERS_TARGET} ${_TARGET_NAME})
+
+ set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES
+ "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}")
+ endif()
endfunction()
function(INSTALL_JAR _TARGET_NAME)
@@ -834,15 +839,15 @@ function (find_jar VARIABLE)
set(_state "name")
- foreach (arg ${ARGN})
- if (${_state} STREQUAL "name")
- if (${arg} STREQUAL "VERSIONS")
+ foreach (arg IN LISTS ARGN)
+ if (_state STREQUAL "name")
+ if (arg STREQUAL "VERSIONS")
set(_state "versions")
- elseif (${arg} STREQUAL "NAMES")
+ elseif (arg STREQUAL "NAMES")
set(_state "names")
- elseif (${arg} STREQUAL "PATHS")
+ elseif (arg STREQUAL "PATHS")
set(_state "paths")
- elseif (${arg} STREQUAL "DOC")
+ elseif (arg STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_names ${arg})
@@ -850,22 +855,22 @@ function (find_jar VARIABLE)
set(_jar_doc "Finding ${arg} jar")
endif ()
endif ()
- elseif (${_state} STREQUAL "versions")
- if (${arg} STREQUAL "NAMES")
+ elseif (_state STREQUAL "versions")
+ if (arg STREQUAL "NAMES")
set(_state "names")
- elseif (${arg} STREQUAL "PATHS")
+ elseif (arg STREQUAL "PATHS")
set(_state "paths")
- elseif (${arg} STREQUAL "DOC")
+ elseif (arg STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_versions ${_jar_versions} ${arg})
endif ()
- elseif (${_state} STREQUAL "names")
- if (${arg} STREQUAL "VERSIONS")
+ elseif (_state STREQUAL "names")
+ if (arg STREQUAL "VERSIONS")
set(_state "versions")
- elseif (${arg} STREQUAL "PATHS")
+ elseif (arg STREQUAL "PATHS")
set(_state "paths")
- elseif (${arg} STREQUAL "DOC")
+ elseif (arg STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_names ${_jar_names} ${arg})
@@ -873,22 +878,22 @@ function (find_jar VARIABLE)
set(_jar_doc "Finding ${arg} jar")
endif ()
endif ()
- elseif (${_state} STREQUAL "paths")
- if (${arg} STREQUAL "VERSIONS")
+ elseif (_state STREQUAL "paths")
+ if (arg STREQUAL "VERSIONS")
set(_state "versions")
- elseif (${arg} STREQUAL "NAMES")
+ elseif (arg STREQUAL "NAMES")
set(_state "names")
- elseif (${arg} STREQUAL "DOC")
+ elseif (arg STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_paths ${_jar_paths} ${arg})
endif ()
- elseif (${_state} STREQUAL "doc")
- if (${arg} STREQUAL "VERSIONS")
+ elseif (_state STREQUAL "doc")
+ if (arg STREQUAL "VERSIONS")
set(_state "versions")
- elseif (${arg} STREQUAL "NAMES")
+ elseif (arg STREQUAL "NAMES")
set(_state "names")
- elseif (${arg} STREQUAL "PATHS")
+ elseif (arg STREQUAL "PATHS")
set(_state "paths")
else ()
set(_jar_doc ${arg})
@@ -900,8 +905,8 @@ function (find_jar VARIABLE)
message(FATAL_ERROR "find_jar: No name to search for given")
endif ()
- foreach (jar_name ${_jar_names})
- foreach (version ${_jar_versions})
+ foreach (jar_name IN LISTS _jar_names)
+ foreach (version IN LISTS _jar_versions)
set(_jar_files ${_jar_files} ${jar_name}-${version}.jar)
endforeach ()
set(_jar_files ${_jar_files} ${jar_name}.jar)
@@ -928,252 +933,252 @@ function(create_javadoc _target)
set(_state "package")
- foreach (arg ${ARGN})
- if (${_state} STREQUAL "package")
- if (${arg} STREQUAL "PACKAGES")
+ foreach (arg IN LISTS ARGN)
+ if (_state STREQUAL "package")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_packages ${arg})
set(_state "packages")
endif ()
- elseif (${_state} STREQUAL "packages")
- if (${arg} STREQUAL "FILES")
+ elseif (_state STREQUAL "packages")
+ if (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_packages ${arg})
endif ()
- elseif (${_state} STREQUAL "files")
- if (${arg} STREQUAL "PACKAGES")
+ elseif (_state STREQUAL "files")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_files ${arg})
endif ()
- elseif (${_state} STREQUAL "sourcepath")
- if (${arg} STREQUAL "PACKAGES")
+ elseif (_state STREQUAL "sourcepath")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_sourcepath ${arg})
endif ()
- elseif (${_state} STREQUAL "classpath")
- if (${arg} STREQUAL "PACKAGES")
+ elseif (_state STREQUAL "classpath")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_classpath ${arg})
endif ()
- elseif (${_state} STREQUAL "installpath")
- if (${arg} STREQUAL "PACKAGES")
+ elseif (_state STREQUAL "installpath")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_installpath ${arg})
endif ()
- elseif (${_state} STREQUAL "doctitle")
+ elseif (_state STREQUAL "doctitle")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_doctitle ${arg})
endif ()
- elseif (${_state} STREQUAL "windowtitle")
+ elseif (_state STREQUAL "windowtitle")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_windowtitle ${arg})
endif ()
- elseif (${_state} STREQUAL "author")
- if (${arg} STREQUAL "PACKAGES")
+ elseif (_state STREQUAL "author")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_author ${arg})
endif ()
- elseif (${_state} STREQUAL "use")
- if (${arg} STREQUAL "PACKAGES")
+ elseif (_state STREQUAL "use")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_use ${arg})
endif ()
- elseif (${_state} STREQUAL "version")
- if (${arg} STREQUAL "PACKAGES")
+ elseif (_state STREQUAL "version")
+ if (arg STREQUAL "PACKAGES")
set(_state "packages")
- elseif (${arg} STREQUAL "FILES")
+ elseif (arg STREQUAL "FILES")
set(_state "files")
- elseif (${arg} STREQUAL "SOURCEPATH")
+ elseif (arg STREQUAL "SOURCEPATH")
set(_state "sourcepath")
- elseif (${arg} STREQUAL "CLASSPATH")
+ elseif (arg STREQUAL "CLASSPATH")
set(_state "classpath")
- elseif (${arg} STREQUAL "INSTALLPATH")
+ elseif (arg STREQUAL "INSTALLPATH")
set(_state "installpath")
- elseif (${arg} STREQUAL "DOCTITLE")
+ elseif (arg STREQUAL "DOCTITLE")
set(_state "doctitle")
- elseif (${arg} STREQUAL "WINDOWTITLE")
+ elseif (arg STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
- elseif (${arg} STREQUAL "AUTHOR")
+ elseif (arg STREQUAL "AUTHOR")
set(_state "author")
- elseif (${arg} STREQUAL "USE")
+ elseif (arg STREQUAL "USE")
set(_state "use")
- elseif (${arg} STREQUAL "VERSION")
+ elseif (arg STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_version ${arg})
@@ -1186,7 +1191,7 @@ function(create_javadoc _target)
if (_javadoc_sourcepath)
set(_start TRUE)
- foreach(_path ${_javadoc_sourcepath})
+ foreach(_path IN LISTS _javadoc_sourcepath)
if (_start)
set(_sourcepath ${_path})
set(_start FALSE)
@@ -1199,7 +1204,7 @@ function(create_javadoc _target)
if (_javadoc_classpath)
set(_start TRUE)
- foreach(_path ${_javadoc_classpath})
+ foreach(_path IN LISTS _javadoc_classpath)
if (_start)
set(_classpath ${_path})
set(_start FALSE)
@@ -1244,6 +1249,12 @@ function(create_javadoc _target)
endfunction()
function (create_javah)
+ if (Java_VERSION VERSION_GREATER_EQUAL 10)
+ message (FATAL_ERROR "create_javah: not supported with this Java version. Use add_jar(GENERATE_NATIVE_HEADERS) instead.")
+ elseif (Java_VERSION VERSION_GREATER_EQUAL 1.8)
+ message (DEPRECATION "create_javah: this command will no longer be supported starting with version 10 of JDK. Update your project by using command add_jar(GENERATE_NATIVE_HEADERS) instead.")
+ endif()
+
cmake_parse_arguments(_create_javah
""
"TARGET;GENERATED_FILES;OUTPUT_NAME;OUTPUT_DIR"
@@ -1360,7 +1371,7 @@ function(export_jars)
# Set content of generated exports file
string(REPLACE ";" " " __targets__ "${_export_jars_TARGETS}")
set(__targetdefs__ "")
- foreach(_target ${_export_jars_TARGETS})
+ foreach(_target IN LISTS _export_jars_TARGETS)
get_target_property(_jarpath ${_target} JAR_FILE)
get_filename_component(_jarpath ${_jarpath} PATH)
__java_export_jar(__targetdefs__ ${_target} "${_jarpath}")
@@ -1398,7 +1409,7 @@ function(install_jar_exports)
endif()
# Determine relative path from installed export file to install prefix
- if(IS_ABSOLUTE ${_install_jar_exports_DESTINATION})
+ if(IS_ABSOLUTE "${_install_jar_exports_DESTINATION}")
file(RELATIVE_PATH _relpath
${_install_jar_exports_DESTINATION}
${CMAKE_INSTALL_PREFIX}
@@ -1417,7 +1428,7 @@ function(install_jar_exports)
# Set content of generated exports file
string(REPLACE ";" " " __targets__ "${_install_jar_exports_TARGETS}")
set(__targetdefs__ "set(_prefix \${CMAKE_CURRENT_LIST_DIR}/${_relpath})\n\n")
- foreach(_target ${_install_jar_exports_TARGETS})
+ foreach(_target IN LISTS _install_jar_exports_TARGETS)
get_target_property(_dir ${_target} INSTALL_DESTINATION)
__java_export_jar(__targetdefs__ ${_target} "\${_prefix}/${_dir}")
endforeach()
diff --git a/Modules/UseJavaClassFilelist.cmake b/Modules/UseJavaClassFilelist.cmake
index c2f9afa4f..1c4baa9d4 100644
--- a/Modules/UseJavaClassFilelist.cmake
+++ b/Modules/UseJavaClassFilelist.cmake
@@ -1,17 +1,18 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.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.
+#]=======================================================================]
if (CMAKE_JAVA_CLASS_OUTPUT_PATH)
if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
diff --git a/Modules/UseJavaSymlinks.cmake b/Modules/UseJavaSymlinks.cmake
index 358b9ef5c..3969f54fa 100644
--- a/Modules/UseJavaSymlinks.cmake
+++ b/Modules/UseJavaSymlinks.cmake
@@ -1,15 +1,16 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# UseJavaSymlinks
-# ---------------
-#
-#
-#
-#
-#
-# Helper script for UseJava.cmake
+#[=======================================================================[.rst:
+UseJavaSymlinks
+---------------
+
+
+
+
+
+Helper script for UseJava.cmake
+#]=======================================================================]
if (UNIX AND _JAVA_TARGET_OUTPUT_LINK)
if (_JAVA_TARGET_OUTPUT_NAME)
diff --git a/Modules/UsePkgConfig.cmake b/Modules/UsePkgConfig.cmake
index 28618eb10..32d228dab 100644
--- a/Modules/UsePkgConfig.cmake
+++ b/Modules/UsePkgConfig.cmake
@@ -1,24 +1,25 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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
+#[=======================================================================[.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
+#]=======================================================================]
find_program(PKGCONFIG_EXECUTABLE NAMES pkg-config )
diff --git a/Modules/UseQt4.cmake b/Modules/UseQt4.cmake
index c8eab7766..8fec717c0 100644
--- a/Modules/UseQt4.cmake
+++ b/Modules/UseQt4.cmake
@@ -1,15 +1,16 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+UseQt4
+------
+
+Use Module for QT4
+
+Sets up C and C++ to use Qt 4. It is assumed that :module:`FindQt` has
+already been loaded. See :module:`FindQt` for information on how to load
+Qt 4 into your CMake project.
+#]=======================================================================]
add_definitions(${QT_DEFINITIONS})
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>)
@@ -104,4 +105,3 @@ foreach(module QT3SUPPORT QTOPENGL QTASSISTANT QTDESIGNER QTMOTIF QTNSPLUGIN
endif ()
endforeach()
-
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake
index fc815ddf8..78522da6d 100644
--- a/Modules/UseSWIG.cmake
+++ b/Modules/UseSWIG.cmake
@@ -1,91 +1,299 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.rst:
-# UseSWIG
-# -------
-#
-# Defines the following macros for use with SWIG:
-#
-# ::
-#
-# SWIG_ADD_LIBRARY(<name>
-# [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>]
-# LANGUAGE <language>
-# SOURCES <file>...
-# )
-# - 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_LIBRARY 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_library(mymod LANGUAGE python SOURCES 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.
-#
-# CMAKE_SWIG_OUTDIR allows one to specify where to write
-# the language specific files (swig -outdir option).
-#
-# SWIG_OUTFILE_DIR allows one to specify where to write the output file
-# (swig -o option). If not specified, CMAKE_SWIG_OUTDIR is used.
-#
-# 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")
+#[=======================================================================[.rst:
+UseSWIG
+-------
+
+This file provides support for ``SWIG``. It is assumed that :module:`FindSWIG`
+module has already been loaded.
+
+Defines the following command for use with ``SWIG``:
+
+.. command:: swig_add_library
+
+ Define swig module with given name and specified language::
+
+ swig_add_library(<name>
+ [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>]
+ LANGUAGE <language>
+ [NO_PROXY]
+ [OUTPUT_DIR <directory>]
+ [OUTFILE_DIR <directory>]
+ SOURCES <file>...
+ )
+
+ Targets created with the ``swig_add_library`` command have the same
+ capabilities as targets created with the :command:`add_library` command, so
+ those targets can be used with any command expecting a target (e.g.
+ :command:`target_link_libraries`).
+
+ .. note::
+
+ This command creates a target with the specified ``<name>`` when
+ policy :policy:`CMP0078` is set to ``NEW``. Otherwise, the legacy
+ behavior will choose a different target name and store it in the
+ ``SWIG_MODULE_<name>_REAL_NAME`` variable.
+
+ .. note::
+
+ For multi-config generators, this module does not support
+ configuration-specific files generated by ``SWIG``. All build
+ configurations must result in the same generated source file.
+
+ ``TYPE``
+ ``SHARED``, ``MODULE`` and ``STATIC`` have the same semantic as for the
+ :command:`add_library` command. If ``USE_BUILD_SHARED_LIBS`` is specified,
+ the library type will be ``STATIC`` or ``SHARED`` based on whether the
+ current value of the :variable:`BUILD_SHARED_LIBS` variable is ``ON``. If
+ no type is specified, ``MODULE`` will be used.
+
+ ``LANGUAGE``
+ Specify the target language.
+
+ ``NO_PROXY``
+ Prevent the generation of the wrapper layer (swig ``-noproxy`` option).
+
+ ``OUTPUT_DIR``
+ Specify where to write the language specific files (swig ``-outdir``
+ option). If not given, the ``CMAKE_SWIG_OUTDIR`` variable will be used.
+ If neither is specified, the default depends on the value of the
+ ``UseSWIG_MODULE_VERSION`` variable as follows:
+
+ * If ``UseSWIG_MODULE_VERSION`` is 1 or is undefined, output is written to
+ the :variable:`CMAKE_CURRENT_BINARY_DIR` directory.
+ * If ``UseSWIG_MODULE_VERSION`` is 2, a dedicated directory will be used.
+ The path of this directory can be retrieved from the
+ ``SWIG_SUPPORT_FILES_DIRECTORY`` target property.
+
+ ``OUTFILE_DIR``
+ Specify an output directory name where the generated source file will be
+ placed (swig -o option). If not specified, the ``SWIG_OUTFILE_DIR`` variable
+ will be used. If neither is specified, ``OUTPUT_DIR`` or
+ ``CMAKE_SWIG_OUTDIR`` is used instead.
+
+ ``SOURCES``
+ List of sources for the library. Files with extension ``.i`` will be
+ identified as sources for the ``SWIG`` tool. Other files will be handled in
+ the standard way. This behavior can be overriden by specifying the variable
+ ``SWIG_SOURCE_FILE_EXTENSIONS``.
+
+ .. note::
+
+ If ``UseSWIG_MODULE_VERSION`` is set to 2, it is **strongly** recommended
+ to use a dedicated directory unique to the target when either the
+ ``OUTPUT_DIR`` option or the ``CMAKE_SWIG_OUTDIR`` variable are specified.
+ The output directory contents are erased as part of the target build, so
+ to prevent interference between targets or losing other important files,
+ each target should have its own dedicated output directory.
+
+.. command:: swig_link_libraries
+
+ Link libraries to swig module::
+
+ swig_link_libraries(<name> <item>...)
+
+ This command has same capabilities as :command:`target_link_libraries`
+ command.
+
+ .. note::
+
+ If variable ``UseSWIG_TARGET_NAME_PREFERENCE`` is set to ``STANDARD``, this
+ command is deprecated and :command:`target_link_libraries` command must be
+ used instead.
+
+Source file properties on module files **must** be set before the invocation
+of the ``swig_add_library`` command to specify special behavior of SWIG and
+ensure generated files will receive the required settings.
+
+``CPLUSPLUS``
+ Call SWIG in c++ mode. For example:
+
+ .. code-block:: cmake
+
+ set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON)
+ swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
+
+``INCLUDE_DIRECTORIES``, ``COMPILE_DEFINITIONS`` and ``COMPILE_OPTIONS``
+ Add custom flags to SWIG compiler and have same semantic as properties
+ :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
+ :prop_sf:`COMPILE_OPTIONS`.
+
+``USE_TARGET_INCLUDE_DIRECTORIES``
+ If set to ``TRUE``, contents of target property
+ :prop_tgt:`INCLUDE_DIRECTORIES` will be forwarded to ``SWIG`` compiler.
+ If set to ``FALSE`` target property :prop_tgt:`INCLUDE_DIRECTORIES` will be
+ ignored. If not set, target property ``SWIG_USE_TARGET_INCLUDE_DIRECTORIES``
+ will be considered.
+
+``GENERATED_INCLUDE_DIRECTORIES``, ``GENERATED_COMPILE_DEFINITIONS`` and ``GENERATED_COMPILE_OPTIONS``
+ Add custom flags to the C/C++ generated source. They will fill, respectively,
+ properties :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
+ :prop_sf:`COMPILE_OPTIONS` of generated C/C++ file.
+
+``DEPENDS``
+ Specify additional dependencies to the source file.
+
+``SWIG_MODULE_NAME``
+ Specify the actual import name of the module in the target language.
+ This is required if it cannot be scanned automatically from source
+ or different from the module file basename. For example:
+
+ .. code-block:: cmake
+
+ set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname)
+
+ .. note::
+
+ If policy :policy:`CMP0086` is set to ``NEW``, ``-module <module_name>``
+ is passed to ``SWIG`` compiler.
+
+Target library properties can be set to apply same configuration to all SWIG
+input files.
+
+``SWIG_INCLUDE_DIRECTORIES``, ``SWIG_COMPILE_DEFINITIONS`` and ``SWIG_COMPILE_OPTIONS``
+ These properties will be applied to all SWIG input files and have same
+ semantic as target properties :prop_tgt:`INCLUDE_DIRECTORIES`,
+ :prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`COMPILE_OPTIONS`.
+
+ .. code-block:: cmake
+
+ set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
+ swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
+ set_property(TARGET mymod PROPERTY SWIG_COMPILE_DEFINITIONS MY_DEF1 MY_DEF2)
+ set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb)
+
+``SWIG_USE_TARGET_INCLUDE_DIRECTORIES``
+ If set to ``TRUE``, contents of target property
+ :prop_tgt:`INCLUDE_DIRECTORIES` will be forwarded to ``SWIG`` compiler.
+ If set to ``FALSE`` or not defined, target property
+ :prop_tgt:`INCLUDE_DIRECTORIES` will be ignored. This behavior can be
+ overridden by specifying source property ``USE_TARGET_INCLUDE_DIRECTORIES``.
+
+``SWIG_GENERATED_INCLUDE_DIRECTORIES``, ``SWIG_GENERATED_COMPILE_DEFINITIONS`` and ``SWIG_GENERATED_COMPILE_OPTIONS``
+ These properties will populate, respectively, properties
+ :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
+ :prop_sf:`COMPILE_FLAGS` of all generated C/C++ files.
+
+``SWIG_DEPENDS``
+ Add dependencies to all SWIG input files.
+
+The following target properties are output properties and can be used to get
+information about support files generated by ``SWIG`` interface compilation.
+
+``SWIG_SUPPORT_FILES``
+ This output property list of wrapper files generated during SWIG compilation.
+
+ .. code-block:: cmake
+
+ set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
+ swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
+ get_property(support_files TARGET mymod PROPERTY SWIG_SUPPORT_FILES)
+
+ .. note::
+
+ Only most principal support files are listed. In case some advanced
+ features of ``SWIG`` are used (for example ``%template``), associated
+ support files may not be listed. Prefer to use the
+ ``SWIG_SUPPORT_FILES_DIRECTORY`` property to handle support files.
+
+``SWIG_SUPPORT_FILES_DIRECTORY``
+ This output property specifies the directory where support files will be
+ generated.
+
+Some variables can be set to customize the behavior of ``swig_add_library``
+as well as ``SWIG``:
+
+``UseSWIG_MODULE_VERSION``
+ Specify different behaviors for ``UseSWIG`` module.
+
+ * Set to 1 or undefined: Legacy behavior is applied.
+ * Set to 2: A new strategy is applied regarding support files: the output
+ directory of support files is erased before ``SWIG`` interface compilation.
+
+``CMAKE_SWIG_FLAGS``
+ Add flags to all swig calls.
+
+``CMAKE_SWIG_OUTDIR``
+ Specify where to write the language specific files (swig ``-outdir`` option).
+
+``SWIG_OUTFILE_DIR``
+ Specify an output directory name where the generated source file will be
+ placed. If not specified, ``CMAKE_SWIG_OUTDIR`` is used.
+
+``SWIG_MODULE_<name>_EXTRA_DEPS``
+ Specify extra dependencies for the generated module for ``<name>``.
+
+``SWIG_SOURCE_FILE_EXTENSIONS``
+ Specify a list of source file extensions to override the default
+ behavior of considering only ``.i`` files as sources for the ``SWIG``
+ tool. For example:
+
+ .. code-block:: cmake
+
+ set(SWIG_SOURCE_FILE_EXTENSIONS ".i" ".swg")
+#]=======================================================================]
+
+cmake_policy(GET CMP0078 target_name_policy)
+cmake_policy(GET CMP0086 module_name_policy)
+
+cmake_policy (VERSION 3.12)
+if (target_name_policy)
+ # respect user choice regarding CMP0078 policy
+ cmake_policy(SET CMP0078 ${target_name_policy})
+endif()
+if (module_name_policy)
+ # respect user choice regarding CMP0086 policy
+ cmake_policy(SET CMP0086 ${module_name_policy})
+endif()
+unset(target_name_policy)
+unset(module_name_policy)
set(SWIG_CXX_EXTENSION "cxx")
set(SWIG_EXTRA_LIBRARIES "")
set(SWIG_PYTHON_EXTRA_FILE_EXTENSIONS ".py")
set(SWIG_JAVA_EXTRA_FILE_EXTENSIONS ".java" "JNI.java")
+set(SWIG_CSHARP_EXTRA_FILE_EXTENSIONS ".cs" "PINVOKE.cs")
+
+set(SWIG_MANAGE_SUPPORT_FILES_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/UseSWIG/ManageSupportFiles.cmake")
+
+##
+## PRIVATE functions
+##
+function (__SWIG_COMPUTE_TIMESTAMP name language infile workingdir __timestamp)
+ get_filename_component(filename "${infile}" NAME_WE)
+ set(${__timestamp}
+ "${workingdir}/${filename}${language}.stamp" PARENT_SCOPE)
+ # get_filename_component(filename "${infile}" ABSOLUTE)
+ # string(UUID uuid NAMESPACE 9735D882-D2F8-4E1D-88C9-A0A4F1F6ECA4
+ # NAME ${name}-${language}-${filename} TYPE SHA1)
+ # set(${__timestamp} "${workingdir}/${uuid}.stamp" PARENT_SCOPE)
+endfunction()
#
# 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}")
+ string(TOUPPER "${language}" SWIG_MODULE_${name}_LANGUAGE)
+ string(TOLOWER "${language}" SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG)
- set(SWIG_MODULE_${name}_REAL_NAME "${name}")
- if (";${CMAKE_SWIG_FLAGS};" MATCHES ";-noproxy;")
+ if (NOT DEFINED SWIG_MODULE_${name}_NOPROXY)
+ set (SWIG_MODULE_${name}_NOPROXY FALSE)
+ endif()
+ if ("-noproxy" IN_LIST CMAKE_SWIG_FLAGS)
set (SWIG_MODULE_${name}_NOPROXY TRUE)
endif ()
- if("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xUNKNOWN")
+
+ if (SWIG_MODULE_${name}_NOPROXY AND
+ NOT ("-noproxy" IN_LIST CMAKE_SWIG_FLAGS OR "-noproxy" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
+ list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-noproxy")
+ endif()
+ if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "UNKNOWN")
message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found")
- elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xPYTHON" 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("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xPERL")
- set(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
- elseif("x${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "xCSHARP")
- # 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}")
+ elseif(SWIG_MODULE_${name}_LANGUAGE STREQUAL "PERL" AND
+ NOT "-shadow" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS)
+ list(APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
endif()
endmacro()
@@ -94,79 +302,126 @@ endmacro()
# 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")
+function(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
+ set(files)
+ get_source_file_property(module_basename
+ "${infile}" SWIG_MODULE_NAME)
+ if(NOT module_basename)
# try to get module name from "%module foo" syntax
- if ( EXISTS ${infile} )
- file ( STRINGS ${infile} _MODULE_NAME REGEX "[ ]*%module[ ]*[a-zA-Z0-9_]+.*" )
+ if ( EXISTS "${infile}" )
+ file ( STRINGS "${infile}" module_basename 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}")
+ if ( module_basename )
+ string ( REGEX REPLACE "[ ]*%module[ ]*([a-zA-Z0-9_]+).*" "\\1" module_basename "${module_basename}" )
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_]+.*" )
+ if ( EXISTS "${infile}" )
+ file ( STRINGS "${infile}" module_basename 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}")
+ if ( module_basename )
+ string ( REGEX REPLACE "[ ]*%module[ ]*\\(.*\\)[ ]*([a-zA-Z0-9_]+).*" "\\1" module_basename "${module_basename}" )
else ()
# fallback to file basename
- get_filename_component(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename ${infile} NAME_WE)
+ get_filename_component(module_basename "${infile}" NAME_WE)
endif ()
endif ()
endif()
foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSIONS})
- set(extra_file "${generatedpath}/${SWIG_GET_EXTRA_OUTPUT_FILES_module_basename}${it}")
- list(APPEND ${outfiles} ${extra_file})
- # Treat extra outputs as plain files regardless of language.
- set_property(SOURCE "${extra_file}" PROPERTY LANGUAGE "")
+ set(extra_file "${generatedpath}/${module_basename}${it}")
+ if (extra_file MATCHES "\\.cs$" AND CMAKE_CSharp_COMPILER_LOADED)
+ set_source_files_properties(${extra_file} PROPERTIES LANGUAGE "CSharp")
+ else()
+ # Treat extra outputs as plain files regardless of language.
+ set_source_files_properties(${extra_file} PROPERTIES LANGUAGE "")
+ endif()
+ list(APPEND files "${extra_file}")
endforeach()
-endmacro()
+
+ set (${outfiles} ${files} PARENT_SCOPE)
+endfunction()
#
# 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})
+function(SWIG_ADD_SOURCE_TO_MODULE name outfiles 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)
+ get_source_file_property(swig_source_file_cplusplus "${infile}" CPLUSPLUS)
# If CMAKE_SWIG_OUTDIR was specified then pass it to -outdir
if(CMAKE_SWIG_OUTDIR)
- set(swig_outdir ${CMAKE_SWIG_OUTDIR})
+ set(outdir ${CMAKE_SWIG_OUTDIR})
else()
- set(swig_outdir ${CMAKE_CURRENT_BINARY_DIR})
+ set(outdir ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(SWIG_OUTFILE_DIR)
- set(swig_outfile_dir ${SWIG_OUTFILE_DIR})
+ set(outfiledir ${SWIG_OUTFILE_DIR})
else()
- set(swig_outfile_dir ${swig_outdir})
+ set(outfiledir ${outdir})
endif()
+ if(SWIG_WORKING_DIR)
+ set (workingdir "${SWIG_WORKING_DIR}")
+ else()
+ set(workingdir "${outdir}")
+ endif()
+
+ if(SWIG_TARGET_NAME)
+ set(target_name ${SWIG_TARGET_NAME})
+ else()
+ set(target_name ${name})
+ endif()
+
+ set (swig_source_file_flags ${CMAKE_SWIG_FLAGS})
+ # handle various swig compile flags properties
+ get_source_file_property (include_directories "${infile}" INCLUDE_DIRECTORIES)
+ if (include_directories)
+ list (APPEND swig_source_file_flags "$<$<BOOL:${include_directories}>:-I$<JOIN:${include_directories},$<SEMICOLON>-I>>")
+ endif()
+ set (property "$<TARGET_PROPERTY:${target_name},SWIG_INCLUDE_DIRECTORIES>")
+ list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:$<TARGET_GENEX_EVAL:${target_name},${property}>,$<SEMICOLON>-I>>")
+ set (property "$<TARGET_PROPERTY:${target_name},INCLUDE_DIRECTORIES>")
+ get_source_file_property(use_target_include_dirs "${infile}" USE_TARGET_INCLUDE_DIRECTORIES)
+ if (use_target_include_dirs)
+ list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
+ elseif(use_target_include_dirs STREQUAL "NOTFOUND")
+ # not defined at source level, rely on target level
+ list (APPEND swig_source_file_flags "$<$<AND:$<BOOL:$<TARGET_PROPERTY:${target_name},SWIG_USE_TARGET_INCLUDE_DIRECTORIES>>,$<BOOL:${property}>>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
+ endif()
+
+ set (property "$<TARGET_PROPERTY:${target_name},SWIG_COMPILE_DEFINITIONS>")
+ list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-D$<JOIN:$<TARGET_GENEX_EVAL:${target_name},${property}>,$<SEMICOLON>-D>>")
+ get_source_file_property (compile_definitions "${infile}" COMPILE_DEFINITIONS)
+ if (compile_definitions)
+ list (APPEND swig_source_file_flags "$<$<BOOL:${compile_definitions}>:-D$<JOIN:${compile_definitions},$<SEMICOLON>-D>>")
+ endif()
+
+ list (APPEND swig_source_file_flags "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_COMPILE_OPTIONS>>")
+ get_source_file_property (compile_options "${infile}" COMPILE_OPTIONS)
+ if (compile_options)
+ list (APPEND swig_source_file_flags ${compile_options})
+ endif()
+
+ # legacy support
+ get_source_file_property (swig_flags "${infile}" SWIG_FLAGS)
+ if (swig_flags)
+ list (APPEND swig_source_file_flags ${swig_flags})
+ endif()
+
+ get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE)
+
if (NOT SWIG_MODULE_${name}_NOPROXY)
SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE}
swig_extra_generated_files
- "${swig_outdir}"
+ "${outdir}"
"${swig_source_file_fullname}")
endif()
set(swig_generated_file_fullname
- "${swig_outfile_dir}/${swig_source_file_name_we}")
+ "${outfiledir}/${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
string(APPEND swig_generated_file_fullname
@@ -180,46 +435,129 @@ macro(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
".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()
+ get_directory_property (cmake_include_directories INCLUDE_DIRECTORIES)
+ list (REMOVE_DUPLICATES cmake_include_directories)
+ set (swig_include_dirs)
+ if (cmake_include_directories)
+ set (swig_include_dirs "$<$<BOOL:${cmake_include_directories}>:-I$<JOIN:${cmake_include_directories},$<SEMICOLON>-I>>")
+ endif()
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++")
+ list (APPEND swig_special_flags "-c++")
+ endif()
+
+ cmake_policy(GET CMP0086 module_name_policy)
+ if (module_name_policy STREQUAL "NEW")
+ get_source_file_property(module_name "${infile}" SWIG_MODULE_NAME)
+ if (module_name)
+ list (APPEND swig_special_flags "-module" "${module_name}")
+ endif()
+ else()
+ if (NOT module_name_policy)
+ cmake_policy(GET_WARNING CMP0086 _cmp0086_warning)
+ message(AUTHOR_WARNING "${_cmp0086_warning}\n")
+ endif()
+ endif()
+
+ set (swig_extra_flags)
+ if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "CSHARP")
+ if(NOT ("-dllimport" IN_LIST swig_source_file_flags OR "-dllimport" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
+ # This makes sure that the name used in the generated DllImport
+ # matches the library name created by CMake
+ list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport" "$<TARGET_FILE_PREFIX:${target_name}>$<TARGET_FILE_BASE_NAME:${target_name}>")
+ endif()
+ endif()
+ if (SWIG_MODULE_${name}_LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY)
+ if(NOT ("-interface" IN_LIST swig_source_file_flags OR "-interface" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
+ # This makes sure that the name used in the proxy code
+ # matches the library name created by CMake
+ list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-interface" "$<TARGET_FILE_PREFIX:${target_name}>$<TARGET_FILE_BASE_NAME:${target_name}>")
+ endif()
+ endif()
+ list (APPEND swig_extra_flags ${SWIG_MODULE_${name}_EXTRA_FLAGS})
+
+ # dependencies
+ set (swig_dependencies ${SWIG_MODULE_${name}_EXTRA_DEPS} $<TARGET_PROPERTY:${target_name},SWIG_DEPENDS>)
+ get_source_file_property(file_depends "${infile}" DEPENDS)
+ if (file_depends)
+ list (APPEND swig_dependencies ${file_depends})
endif()
- set(swig_extra_flags)
- if(SWIG_MODULE_${name}_EXTRA_FLAGS)
- set(swig_extra_flags ${swig_extra_flags} ${SWIG_MODULE_${name}_EXTRA_FLAGS})
+
+ if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
+ # as part of custom command, start by removing old generated files
+ # to ensure obsolete files do not stay
+ set (swig_file_outdir "${workingdir}/${swig_source_file_name_we}.files")
+ set (swig_cleanup_command COMMAND "${CMAKE_COMMAND}" "-DSUPPORT_FILES_WORKING_DIRECTORY=${swig_file_outdir}" "-DSUPPORT_FILES_OUTPUT_DIRECTORY=${outdir}" -DACTION=CLEAN -P "${SWIG_MANAGE_SUPPORT_FILES_SCRIPT}")
+ set (swig_copy_command COMMAND "${CMAKE_COMMAND}" "-DSUPPORT_FILES_WORKING_DIRECTORY=${swig_file_outdir}" "-DSUPPORT_FILES_OUTPUT_DIRECTORY=${outdir}" -DACTION=COPY -P "${SWIG_MANAGE_SUPPORT_FILES_SCRIPT}")
+ else()
+ set (swig_file_outdir "${outdir}")
+ unset (swig_cleanup_command)
+ unset (swig_copy_command)
+ endif()
+
+ # IMPLICIT_DEPENDS below can not handle situations where a dependent file is
+ # removed. We need an extra step with timestamp and custom target, see #16830
+ # As this is needed only for Makefile generator do it conditionally
+ if(CMAKE_GENERATOR MATCHES "Make")
+ __swig_compute_timestamp(${name} ${SWIG_MODULE_${name}_LANGUAGE}
+ "${infile}" "${workingdir}" swig_generated_timestamp)
+ set(swig_custom_output "${swig_generated_timestamp}")
+ set(swig_custom_products
+ BYPRODUCTS "${swig_generated_file_fullname}" ${swig_extra_generated_files})
+ set(swig_timestamp_command
+ COMMAND ${CMAKE_COMMAND} -E touch "${swig_generated_timestamp}")
+ else()
+ set(swig_custom_output
+ "${swig_generated_file_fullname}" ${swig_extra_generated_files})
+ set(swig_custom_products)
+ set(swig_timestamp_command)
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}
+ OUTPUT ${swig_custom_output}
+ ${swig_custom_products}
+ ${swig_cleanup_command}
+ # Let's create the ${outdir} at execution time, in case dir contains $(OutDir)
+ COMMAND "${CMAKE_COMMAND}" -E make_directory ${outdir} ${outfiledir}
+ ${swig_timestamp_command}
+ COMMAND "${CMAKE_COMMAND}" -E env "SWIG_LIB=${SWIG_DIR}" "${SWIG_EXECUTABLE}"
+ "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
+ "${swig_source_file_flags}"
+ -outdir "${swig_file_outdir}"
${swig_special_flags}
${swig_extra_flags}
- ${swig_include_dirs}
+ "${swig_include_dirs}"
-o "${swig_generated_file_fullname}"
"${swig_source_file_fullname}"
+ ${swig_copy_command}
MAIN_DEPENDENCY "${swig_source_file_fullname}"
- DEPENDS ${SWIG_MODULE_${name}_EXTRA_DEPS}
+ DEPENDS ${swig_dependencies}
IMPLICIT_DEPENDS CXX "${swig_source_file_fullname}"
- COMMENT "Swig source")
+ COMMENT "Swig compile ${infile} for ${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
+ COMMAND_EXPAND_LISTS)
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()
+
+ ## add all properties for generated file to various properties
+ get_property (include_directories SOURCE "${infile}" PROPERTY GENERATED_INCLUDE_DIRECTORIES)
+ set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY INCLUDE_DIRECTORIES ${include_directories} $<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_GENERATED_INCLUDE_DIRECTORIES>>)
+
+ get_property (compile_definitions SOURCE "${infile}" PROPERTY GENERATED_COMPILE_DEFINITIONS)
+ set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_DEFINITIONS $<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_GENERATED_COMPILE_DEFINITIONS>> ${compile_definitions})
+
+ get_property (compile_options SOURCE "${infile}" PROPERTY GENERATED_COMPILE_OPTIONS)
+ set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_OPTIONS $<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_GENERATED_COMPILE_OPTIONS>> ${compile_options})
+
+ if (SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG MATCHES "php")
+ set_property (SOURCE "${swig_generated_file_fullname}" APPEND PROPERTY INCLUDE_DIRECTORIES "${outdir}")
+ endif()
+
+ set(${outfiles} "${swig_generated_file_fullname}" ${swig_extra_generated_files} PARENT_SCOPE)
+
+ # legacy support
+ set (swig_generated_file_fullname "${swig_generated_file_fullname}" PARENT_SCOPE)
+endfunction()
#
# Create Swig module
@@ -233,13 +571,19 @@ macro(SWIG_ADD_MODULE name language)
endmacro()
-macro(SWIG_ADD_LIBRARY name)
- set(options "")
+function(SWIG_ADD_LIBRARY name)
+ set(options NO_PROXY)
set(oneValueArgs LANGUAGE
- TYPE)
+ TYPE
+ OUTPUT_DIR
+ OUTFILE_DIR)
set(multiValueArgs SOURCES)
cmake_parse_arguments(_SAM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+ if (_SAM_UNPARSED_ARGUMENTS)
+ message(FATAL_ERROR "SWIG_ADD_LIBRARY: ${_SAM_UNPARSED_ARGUMENTS}: unexpected arguments")
+ endif()
+
if(NOT DEFINED _SAM_LANGUAGE)
message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing LANGUAGE argument")
endif()
@@ -250,60 +594,169 @@ macro(SWIG_ADD_LIBRARY name)
if(NOT DEFINED _SAM_TYPE)
set(_SAM_TYPE MODULE)
- elseif("${_SAM_TYPE}" STREQUAL "USE_BUILD_SHARED_LIBS")
+ elseif(_SAM_TYPE STREQUAL "USE_BUILD_SHARED_LIBS")
unset(_SAM_TYPE)
endif()
+ cmake_policy(GET CMP0078 target_name_policy)
+ if (target_name_policy STREQUAL "NEW")
+ set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
+ else()
+ if (NOT target_name_policy)
+ cmake_policy(GET_WARNING CMP0078 _cmp0078_warning)
+ message(AUTHOR_WARNING "${_cmp0078_warning}\n")
+ endif()
+ if (NOT DEFINED UseSWIG_TARGET_NAME_PREFERENCE)
+ set (UseSWIG_TARGET_NAME_PREFERENCE LEGACY)
+ elseif (NOT UseSWIG_TARGET_NAME_PREFERENCE MATCHES "^(LEGACY|STANDARD)$")
+ message (FATAL_ERROR "UseSWIG_TARGET_NAME_PREFERENCE: ${UseSWIG_TARGET_NAME_PREFERENCE}: invalid value. 'LEGACY' or 'STANDARD' is expected.")
+ endif()
+ endif()
+
+ if (NOT DEFINED UseSWIG_MODULE_VERSION)
+ set (UseSWIG_MODULE_VERSION 1)
+ elseif (NOT UseSWIG_MODULE_VERSION MATCHES "^(1|2)$")
+ message (FATAL_ERROR "UseSWIG_MODULE_VERSION: ${UseSWIG_MODULE_VERSION}: invalid value. 1 or 2 is expected.")
+ endif()
+
+ set (SWIG_MODULE_${name}_NOPROXY ${_SAM_NO_PROXY})
swig_module_initialize(${name} ${_SAM_LANGUAGE})
- set(swig_dot_i_sources)
- set(swig_other_sources)
- foreach(it ${_SAM_SOURCES})
- if(${it} MATCHES "\\.i$")
- set(swig_dot_i_sources ${swig_dot_i_sources} "${it}")
+ # compute real target name.
+ if (UseSWIG_TARGET_NAME_PREFERENCE STREQUAL "LEGACY" AND
+ 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(target_name "_${name}")
+ else()
+ set(target_name "${name}")
+ endif()
+
+ if (TARGET ${target_name})
+ # a target with same name is already defined.
+ # call NOW add_library command to raise the most useful error message
+ add_library(${target_name})
+ return()
+ endif()
+
+ set (workingdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target_name}.dir")
+ # set special variable to pass extra information to command SWIG_ADD_SOURCE_TO_MODULE
+ # which cannot be changed due to legacy compatibility
+ set (SWIG_WORKING_DIR "${workingdir}")
+ set (SWIG_TARGET_NAME "${target_name}")
+
+ set (outputdir "${_SAM_OUTPUT_DIR}")
+ if (NOT _SAM_OUTPUT_DIR)
+ if (CMAKE_SWIG_OUTDIR)
+ set (outputdir "${CMAKE_SWIG_OUTDIR}")
else()
- set(swig_other_sources ${swig_other_sources} "${it}")
+ if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
+ set (outputdir "${workingdir}/${_SAM_LANGUAGE}.files")
+ else()
+ set (outputdir "${CMAKE_CURRENT_BINARY_DIR}")
+ endif()
endif()
- endforeach()
+ endif()
+
+ set (outfiledir "${_SAM_OUTFILE_DIR}")
+ if(NOT _SAM_OUTFILE_DIR)
+ if (SWIG_OUTFILE_DIR)
+ set (outfiledir "${SWIG_OUTFILE_DIR}")
+ else()
+ if (_SAM_OUTPUT_DIR OR CMAKE_SWIG_OUTDIR)
+ set (outfiledir "${outputdir}")
+ else()
+ set (outfiledir "${workingdir}")
+ endif()
+ endif()
+ endif()
+ # set again, locally, predefined variables to ensure compatibility
+ # with command SWIG_ADD_SOURCE_TO_MODULE
+ set(CMAKE_SWIG_OUTDIR "${outputdir}")
+ set(SWIG_OUTFILE_DIR "${outfiledir}")
+
+ # See if the user has specified source extensions for swig files?
+ if (NOT DEFINED SWIG_SOURCE_FILE_EXTENSIONS)
+ # Assume the default (*.i) file extension for Swig source files
+ set(SWIG_SOURCE_FILE_EXTENSIONS ".i")
+ endif()
+
+ # Generate a regex out of file extensions.
+ string(REGEX REPLACE "([$^.*+?|()-])" "\\\\\\1" swig_source_ext_regex "${SWIG_SOURCE_FILE_EXTENSIONS}")
+ list (JOIN swig_source_ext_regex "|" swig_source_ext_regex)
+ string (PREPEND swig_source_ext_regex "(")
+ string (APPEND swig_source_ext_regex ")$")
+
+ set(swig_dot_i_sources ${_SAM_SOURCES})
+ list(FILTER swig_dot_i_sources INCLUDE REGEX ${swig_source_ext_regex})
+ if (NOT swig_dot_i_sources)
+ message(FATAL_ERROR "SWIG_ADD_LIBRARY: no SWIG interface files specified")
+ endif()
+ set(swig_other_sources ${_SAM_SOURCES})
+ list(REMOVE_ITEM swig_other_sources ${swig_dot_i_sources})
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}")
+ set(swig_generated_timestamps)
+ foreach(swig_it IN LISTS swig_dot_i_sources)
+ SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source "${swig_it}")
+ list (APPEND swig_generated_sources "${swig_generated_source}")
+ if(CMAKE_GENERATOR MATCHES "Make")
+ __swig_compute_timestamp(${name} ${SWIG_MODULE_${name}_LANGUAGE} "${swig_it}"
+ "${workingdir}" swig_timestamp)
+ list (APPEND swig_generated_timestamps "${swig_timestamp}")
+ endif()
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}
+ set_property (DIRECTORY APPEND PROPERTY
+ ADDITIONAL_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps})
+ if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
+ set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${outputdir}")
+ endif()
+
+ add_library(${target_name}
${_SAM_TYPE}
${swig_generated_sources}
${swig_other_sources})
- if("${_SAM_TYPE}" STREQUAL "MODULE")
- set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES NO_SONAME ON)
+ if(CMAKE_GENERATOR MATCHES "Make")
+ # see IMPLICIT_DEPENDS above
+ add_custom_target(${name}_swig_compilation DEPENDS ${swig_generated_timestamps})
+ add_dependencies(${target_name} ${name}_swig_compilation)
+ endif()
+ if(_SAM_TYPE STREQUAL "MODULE")
+ set_target_properties(${target_name} PROPERTIES NO_SONAME ON)
endif()
string(TOLOWER "${_SAM_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 (swig_lowercase_language STREQUAL "octave")
+ set_target_properties(${target_name} PROPERTIES PREFIX "")
+ set_target_properties(${target_name} PROPERTIES SUFFIX ".oct")
+ elseif (swig_lowercase_language STREQUAL "go")
+ set_target_properties(${target_name} PROPERTIES PREFIX "")
+ elseif (swig_lowercase_language STREQUAL "java")
+ # 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
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")
- if("${_SAM_TYPE}" STREQUAL "MODULE")
- set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
+ set_target_properties (${target_name} PROPERTIES SUFFIX ".jnilib")
+ endif()
+ if ((WIN32 AND MINGW) OR CYGWIN OR CMAKE_SYSTEM_NAME STREQUAL MSYS)
+ set_target_properties(${target_name} PROPERTIES PREFIX "")
+ endif()
+ elseif (swig_lowercase_language STREQUAL "lua")
+ if(_SAM_TYPE STREQUAL "MODULE")
+ set_target_properties(${target_name} PROPERTIES PREFIX "")
+ endif()
+ elseif (swig_lowercase_language STREQUAL "python")
+ if (UseSWIG_TARGET_NAME_PREFERENCE STREQUAL "STANDARD" 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_target_properties(${target_name} PROPERTIES PREFIX "_")
+ else()
+ set_target_properties(${target_name} PROPERTIES PREFIX "")
endif()
- 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.
@@ -313,34 +766,72 @@ macro(SWIG_ADD_LIBRARY name)
# .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")
+ set_target_properties(${target_name} PROPERTIES SUFFIX ".pyd")
endif()
- elseif ("${swig_lowercase_language}" STREQUAL "r")
- set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
- elseif ("${swig_lowercase_language}" STREQUAL "ruby")
+ elseif (swig_lowercase_language STREQUAL "r")
+ set_target_properties(${target_name} PROPERTIES PREFIX "")
+ 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 "")
+ set_target_properties (${target_name} PROPERTIES PREFIX "")
if (APPLE)
- set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".bundle")
+ set_target_properties (${target_name} PROPERTIES SUFFIX ".bundle")
+ endif ()
+ elseif (swig_lowercase_language STREQUAL "perl")
+ # assume empty prefix because we expect the module to be dynamically loaded
+ set_target_properties (${target_name} PROPERTIES PREFIX "")
+ if (APPLE)
+ set_target_properties (${target_name} PROPERTIES SUFFIX ".dylib")
endif ()
else()
# assume empty prefix because we expect the module to be dynamically loaded
- set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
+ set_target_properties (${target_name} PROPERTIES PREFIX "")
endif ()
-endmacro()
+
+ # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directory of support files
+ set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY "${outputdir}")
+ # target property SWIG_SUPPORT_FILES lists principal proxy support files
+ if (NOT SWIG_MODULE_${name}_NOPROXY)
+ string(TOUPPER "${_SAM_LANGUAGE}" swig_uppercase_language)
+ set(swig_all_support_files)
+ foreach (swig_it IN LISTS SWIG_${swig_uppercase_language}_EXTRA_FILE_EXTENSIONS)
+ set (swig_support_files ${swig_generated_sources})
+ list (FILTER swig_support_files INCLUDE REGEX ".*${swig_it}$")
+ list(APPEND swig_all_support_files ${swig_support_files})
+ endforeach()
+ if (swig_all_support_files)
+ list(REMOVE_DUPLICATES swig_all_support_files)
+ endif()
+ set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES ${swig_all_support_files})
+ endif()
+
+ # to ensure legacy behavior, export some variables
+ set (SWIG_MODULE_${name}_LANGUAGE "${SWIG_MODULE_${name}_LANGUAGE}" PARENT_SCOPE)
+ set (SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" PARENT_SCOPE)
+ set (SWIG_MODULE_${name}_REAL_NAME "${target_name}" PARENT_SCOPE)
+ set (SWIG_MODULE_${name}_NOPROXY "${SWIG_MODULE_${name}_NOPROXY}" PARENT_SCOPE)
+ set (SWIG_MODULE_${name}_EXTRA_FLAGS "${SWIG_MODULE_${name}_EXTRA_FLAGS}" PARENT_SCOPE)
+ # the last one is a bit crazy but it is documented, so...
+ # NOTA: works as expected if only ONE input file is specified
+ set (swig_generated_file_fullname "${swig_generated_file_fullname}" PARENT_SCOPE)
+endfunction()
#
# 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})
+function(SWIG_LINK_LIBRARIES name)
+ if (UseSWIG_TARGET_NAME_PREFERENCE STREQUAL "STANDARD")
+ message(DEPRECATION "SWIG_LINK_LIBRARIES is deprecated. Use TARGET_LINK_LIBRARIES instead.")
+ target_link_libraries(${name} ${ARGN})
else()
- message(SEND_ERROR "Cannot find Swig library \"${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()
endif()
-endmacro()
+endfunction()
diff --git a/Modules/Use_wxWindows.cmake b/Modules/Use_wxWindows.cmake
index bd8cc01c1..782874c10 100644
--- a/Modules/Use_wxWindows.cmake
+++ b/Modules/Use_wxWindows.cmake
@@ -1,35 +1,37 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+Use_wxWindows
+-------------
+
+.. deprecated:: 2.8.10
+
+ Use ``find_package(wxWidgets)`` and ``include(${wxWidgets_USE_FILE})`` instead.
+
+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.
+#]=======================================================================]
# -----------------------------------------------------
# 16.Feb.2004: changed INCLUDE to FIND_PACKAGE to read from users own non-system CMAKE_MODULE_PATH (Jan Woetzel JW)
@@ -65,4 +67,3 @@ if(WXWINDOWS_FOUND)
else()
message(SEND_ERROR "wxWindows not found by Use_wxWindows.cmake")
endif()
-
diff --git a/Modules/UsewxWidgets.cmake b/Modules/UsewxWidgets.cmake
index a50d03d53..eed041021 100644
--- a/Modules/UsewxWidgets.cmake
+++ b/Modules/UsewxWidgets.cmake
@@ -1,41 +1,42 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>
+#[=======================================================================[.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>
+#]=======================================================================]
# debug message and logging.
# comment these out for distribution
diff --git a/Modules/WriteBasicConfigVersionFile.cmake b/Modules/WriteBasicConfigVersionFile.cmake
index 7c9467ab3..45f9e587a 100644
--- a/Modules/WriteBasicConfigVersionFile.cmake
+++ b/Modules/WriteBasicConfigVersionFile.cmake
@@ -1,26 +1,29 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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.
+#[=======================================================================[.rst:
+WriteBasicConfigVersionFile
+---------------------------
+
+.. deprecated:: 3.0
+
+ Use the identical command :command:`write_basic_package_version_file()`
+ from module :module:`CMakePackageConfigHelpers`.
+
+::
+
+ WRITE_BASIC_CONFIG_VERSION_FILE( filename
+ [VERSION major.minor.patch]
+ COMPATIBILITY (AnyNewerVersion|SameMajorVersion|SameMinorVersion|ExactVersion)
+ [ARCH_INDEPENDENT]
+ )
+
+
+#]=======================================================================]
function(WRITE_BASIC_CONFIG_VERSION_FILE _filename)
- set(options )
+ set(options ARCH_INDEPENDENT )
set(oneValueArgs VERSION COMPATIBILITY )
set(multiValueArgs )
diff --git a/Modules/WriteCompilerDetectionHeader.cmake b/Modules/WriteCompilerDetectionHeader.cmake
index e7f991249..23d81b5fc 100644
--- a/Modules/WriteCompilerDetectionHeader.cmake
+++ b/Modules/WriteCompilerDetectionHeader.cmake
@@ -1,227 +1,236 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
-#.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>
-# [OUTPUT_FILES_VAR <output_files_var> OUTPUT_DIR <output_dir>]
-# COMPILERS <compiler> [...]
-# FEATURES <feature> [...]
-# [VERSION <version>]
-# [PROLOG <prolog>]
-# [EPILOG <epilog>]
-# [ALLOW_UNKNOWN_COMPILERS]
-# [ALLOW_UNKNOWN_COMPILER_VERSIONS]
-# )
-#
-# The ``write_compiler_detection_header`` function generates the
-# file ``<file>`` with macros which all have the prefix ``<prefix>``.
-#
-# By default, all content is written directly to the ``<file>``. The
-# ``OUTPUT_FILES_VAR`` may be specified to cause the compiler-specific
-# content to be written to separate files. The separate files are then
-# available in the ``<output_files_var>`` and may be consumed by the caller
-# for installation for example. The ``OUTPUT_DIR`` specifies a relative
-# path from the main ``<file>`` to the compiler-specific files. For example:
-#
-# .. code-block:: cmake
-#
-# write_compiler_detection_header(
-# FILE climbingstats_compiler_detection.h
-# PREFIX ClimbingStats
-# OUTPUT_FILES_VAR support_files
-# OUTPUT_DIR compilers
-# COMPILERS GNU Clang MSVC Intel
-# FEATURES cxx_variadic_templates
-# )
-# install(FILES
-# ${CMAKE_CURRENT_BINARY_DIR}/climbingstats_compiler_detection.h
-# DESTINATION include
-# )
-# install(FILES
-# ${support_files}
-# DESTINATION include/compilers
-# )
-#
-#
-# ``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.
-# The ``{c,cxx}_std_*`` meta-features are ignored if requested.
-#
-# See the :manual:`cmake-compile-features(7)` manual for information on
-# compile features.
-#
-# ``ALLOW_UNKNOWN_COMPILERS`` and ``ALLOW_UNKNOWN_COMPILER_VERSIONS`` cause
-# the module to generate conditions that treat unknown compilers as simply
-# lacking all features. Without these options the default behavior is to
-# generate a ``#error`` for unknown compilers.
-#
-# 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 AppleClang MSVC Intel
-# 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]]``
-# ``cxx_thread_local`` ``<PREFIX>_THREAD_LOCAL`` ``thread_local``
-# ============================= ================================ =====================
-#
-# 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=
-# )
+#[=======================================================================[.rst:
+WriteCompilerDetectionHeader
+----------------------------
+
+This module provides the function ``write_compiler_detection_header()``.
+
+This 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>
+ [OUTPUT_FILES_VAR <output_files_var> OUTPUT_DIR <output_dir>]
+ COMPILERS <compiler> [...]
+ FEATURES <feature> [...]
+ [BARE_FEATURES <feature> [...]]
+ [VERSION <version>]
+ [PROLOG <prolog>]
+ [EPILOG <epilog>]
+ [ALLOW_UNKNOWN_COMPILERS]
+ [ALLOW_UNKNOWN_COMPILER_VERSIONS]
+ )
+
+This generates the file ``<file>`` with macros which all have the prefix
+``<prefix>``.
+
+By default, all content is written directly to the ``<file>``. The
+``OUTPUT_FILES_VAR`` may be specified to cause the compiler-specific
+content to be written to separate files. The separate files are then
+available in the ``<output_files_var>`` and may be consumed by the caller
+for installation for example. The ``OUTPUT_DIR`` specifies a relative
+path from the main ``<file>`` to the compiler-specific files. For example:
+
+.. code-block:: cmake
+
+ write_compiler_detection_header(
+ FILE climbingstats_compiler_detection.h
+ PREFIX ClimbingStats
+ OUTPUT_FILES_VAR support_files
+ OUTPUT_DIR compilers
+ COMPILERS GNU Clang MSVC Intel
+ FEATURES cxx_variadic_templates
+ )
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/climbingstats_compiler_detection.h
+ DESTINATION include
+ )
+ install(FILES
+ ${support_files}
+ DESTINATION include/compilers
+ )
+
+
+``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.
+The ``{c,cxx}_std_*`` meta-features are ignored if requested.
+
+See the :manual:`cmake-compile-features(7)` manual for information on
+compile features.
+
+``BARE_FEATURES`` will define the compatibility macros with the name used in
+newer versions of the language standard, so the code can use the new feature
+name unconditionally.
+
+``ALLOW_UNKNOWN_COMPILERS`` and ``ALLOW_UNKNOWN_COMPILER_VERSIONS`` cause
+the module to generate conditions that treat unknown compilers as simply
+lacking all features. Without these options the default behavior is to
+generate a ``#error`` for unknown compilers and versions.
+
+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 AppleClang MSVC Intel
+ 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.
+
+If ``BARE_FEATURES cxx_final`` was given as argument the ``final`` keyword
+will be defined for old compilers, too.
+
+The following features generate corresponding symbol defines and if they
+are available as ``BARE_FEATURES``:
+
+========================== =================================== ================= ======
+ Feature Define Symbol bare
+========================== =================================== ================= ======
+``c_restrict`` ``<PREFIX>_RESTRICT`` ``restrict`` yes
+``cxx_constexpr`` ``<PREFIX>_CONSTEXPR`` ``constexpr`` yes
+``cxx_deleted_functions`` ``<PREFIX>_DELETED_FUNCTION`` ``= delete``
+``cxx_extern_templates`` ``<PREFIX>_EXTERN_TEMPLATE`` ``extern``
+``cxx_final`` ``<PREFIX>_FINAL`` ``final`` yes
+``cxx_noexcept`` ``<PREFIX>_NOEXCEPT`` ``noexcept`` yes
+``cxx_noexcept`` ``<PREFIX>_NOEXCEPT_EXPR(X)`` ``noexcept(X)``
+``cxx_override`` ``<PREFIX>_OVERRIDE`` ``override`` yes
+========================== =================================== ================= ======
+
+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 bare
+============================= ================================ ===================== ======
+``cxx_alignas`` ``<PREFIX>_ALIGNAS`` ``alignas``
+``cxx_alignof`` ``<PREFIX>_ALIGNOF`` ``alignof``
+``cxx_nullptr`` ``<PREFIX>_NULLPTR`` ``nullptr`` yes
+``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]]``
+``cxx_thread_local`` ``<PREFIX>_THREAD_LOCAL`` ``thread_local``
+============================= ================================ ===================== ======
+
+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=
+ )
+#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CMakeCompilerIdDetection.cmake)
@@ -252,6 +261,37 @@ macro(_simpledefine FEATURE_NAME FEATURE_TESTNAME FEATURE_STRING FEATURE_DEFAULT
endif()
endmacro()
+macro(_simplebaredefine FEATURE_NAME FEATURE_STRING FEATURE_DEFAULT_STRING)
+ if (feature STREQUAL "${FEATURE_NAME}")
+ string(APPEND file_content "
+# if !(defined(${def_name}) && ${def_name})
+# define ${FEATURE_STRING} ${FEATURE_DEFAULT_STRING}
+# endif
+\n")
+ endif()
+endmacro()
+
+function(_check_feature_lists C_FEATURE_VAR CXX_FEATURE_VAR)
+ foreach(feature ${ARGN})
+ if (feature MATCHES "^c_std_")
+ # ignored
+ elseif (feature MATCHES "^cxx_std_")
+ # ignored
+ elseif (feature MATCHES "^cxx_")
+ list(APPEND _langs CXX)
+ list(APPEND ${CXX_FEATURE_VAR} ${feature})
+ elseif (feature MATCHES "^c_")
+ list(APPEND _langs C)
+ list(APPEND ${C_FEATURE_VAR} ${feature})
+ else()
+ message(FATAL_ERROR "Unsupported feature ${feature}.")
+ endif()
+ endforeach()
+ set(${C_FEATURE_VAR} ${${C_FEATURE_VAR}} PARENT_SCOPE)
+ set(${CXX_FEATURE_VAR} ${${CXX_FEATURE_VAR}} PARENT_SCOPE)
+ set(_langs ${_langs} PARENT_SCOPE)
+endfunction()
+
function(write_compiler_detection_header
file_keyword file_arg
prefix_keyword prefix_arg
@@ -264,13 +304,13 @@ function(write_compiler_detection_header
endif()
set(options ALLOW_UNKNOWN_COMPILERS ALLOW_UNKNOWN_COMPILER_VERSIONS)
set(oneValueArgs VERSION EPILOG PROLOG OUTPUT_FILES_VAR OUTPUT_DIR)
- set(multiValueArgs COMPILERS FEATURES)
+ set(multiValueArgs COMPILERS FEATURES BARE_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)
+ if (NOT _WCD_FEATURES AND NOT _WCD_BARE_FEATURES)
message(FATAL_ERROR "Invalid arguments. write_compiler_detection_header requires at least one feature.")
endif()
@@ -377,21 +417,8 @@ function(write_compiler_detection_header
)\n")
endif()
- foreach(feature ${_WCD_FEATURES})
- if (feature MATCHES "^c_std_")
- # ignored
- elseif (feature MATCHES "^cxx_std_")
- # ignored
- elseif (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()
+ _check_feature_lists(C_features CXX_features ${_WCD_FEATURES})
+ _check_feature_lists(C_bare_features CXX_bare_features ${_WCD_BARE_FEATURES})
list(REMOVE_DUPLICATES _langs)
if(_WCD_OUTPUT_FILES_VAR)
@@ -557,7 +584,18 @@ template<> struct ${prefix_arg}StaticAssert<true>{};
# endif
\n")
endif()
- _simpledefine(cxx_nullptr NULLPTR nullptr 0)
+ if (feature STREQUAL cxx_nullptr)
+ set(def_value "${prefix_arg}_NULLPTR")
+ string(APPEND file_content "
+# if defined(${def_name}) && ${def_name}
+# define ${def_value} nullptr
+# elif ${prefix_arg}_COMPILER_IS_GNU
+# define ${def_value} __null
+# else
+# define ${def_value} 0
+# endif
+\n")
+ endif()
if (feature STREQUAL cxx_thread_local)
set(def_value "${prefix_arg}_THREAD_LOCAL")
string(APPEND file_content "
@@ -595,6 +633,29 @@ template<> struct ${prefix_arg}StaticAssert<true>{};
endif()
endforeach()
+ foreach(feature ${${_lang}_bare_features})
+ string(TOUPPER ${feature} feature_upper)
+ set(feature_PP "COMPILER_${feature_upper}")
+ set(def_name ${prefix_arg}_${feature_PP})
+ _simplebaredefine(c_restrict restrict "")
+ _simplebaredefine(cxx_constexpr constexpr "")
+ _simplebaredefine(cxx_final final "")
+ _simplebaredefine(cxx_override override "")
+ if (feature STREQUAL cxx_nullptr)
+ set(def_value "nullptr")
+ string(APPEND file_content "
+# if !(defined(${def_name}) && ${def_name})
+# if ${prefix_arg}_COMPILER_IS_GNU
+# define ${def_value} __null
+# else
+# define ${def_value} 0
+# endif
+# endif
+\n")
+ endif()
+ _simplebaredefine(cxx_noexcept noexcept "")
+ endforeach()
+
string(APPEND file_content "#endif\n")
endforeach()
diff --git a/Modules/ecos_clean.cmake b/Modules/ecos_clean.cmake
index 21126f624..480b1ce83 100644
--- a/Modules/ecos_clean.cmake
+++ b/Modules/ecos_clean.cmake
@@ -7,10 +7,10 @@ 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()
+ 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
index 9dd75bf56..c518b3d7a 100644
--- a/Modules/exportheader.cmake.in
+++ b/Modules/exportheader.cmake.in
@@ -39,4 +39,4 @@
# endif
#endif
@CUSTOM_CONTENT@
-#endif
+#endif /* @INCLUDE_GUARD_NAME@ */
diff --git a/Modules/readme.txt b/Modules/readme.txt
index 1e0c13b6a..a62947806 100644
--- a/Modules/readme.txt
+++ b/Modules/readme.txt
@@ -1,4 +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:
-https://cmake.org/Wiki/CMake:Module_Maintainers
+https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/dev/Module-Maintainers
diff --git a/README.rst b/README.rst
index d5acd4a7c..76783ec1c 100644
--- a/README.rst
+++ b/README.rst
@@ -6,10 +6,12 @@ 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 Documentation Page`_. The `CMake Community Wiki`_ also
+references useful guides and recipes.
.. _`CMake Home Page`: https://cmake.org
.. _`CMake Documentation Page`: https://cmake.org/cmake/help/documentation.html
+.. _`CMake Community Wiki`: https://gitlab.kitware.com/cmake/community/wikis/home
CMake is maintained and supported by `Kitware`_ and developed in
collaboration with a productive community of contributors.
@@ -36,7 +38,7 @@ Supported Platforms
* FreeBSD
* OpenBSD
* Solaris
-* HP-UX
+* AIX
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.
@@ -51,25 +53,43 @@ Building CMake from Scratch
UNIX/Mac OSX/MinGW/MSYS/Cygwin
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-You need to have a compiler and a make installed.
+You need to have a C++ compiler (supporting C++11) and a ``make`` installed.
Run the ``bootstrap`` script you find in the source directory of CMake.
You can use the ``--help`` option to see the supported options.
You may use the ``--prefix=<install_prefix>`` option to specify a custom
-installation directory for CMake. You can run the ``bootstrap`` script from
-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::
+installation directory for CMake. Once this has finished successfully,
+run ``make`` and ``make install``.
- $ ./bootstrap && make && make install
+For example, if you simply want to build and install CMake from source,
+you can build directly in the source tree::
+
+ $ ./bootstrap && make && sudo make install
+
+Or, if you plan to develop CMake or otherwise run the test suite, create
+a separate build tree::
+
+ $ mkdir cmake-build && cd cmake-build
+ $ ../cmake-source/bootstrap && make
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.
+There are two ways for building CMake under Windows:
+
+1. Compile with MSVC from VS 2015 or later.
+ You need to download and install a binary release of CMake. You can get
+ these releases from the `CMake Download Page`_. Then proceed with the
+ instructions below for `Building CMake with CMake`_.
+
+2. Bootstrap with MinGW under MSYS2.
+ Download and install `MSYS2`_. Then install the required build tools::
+
+ $ pacman -S --needed git base-devel mingw-w64-x86_64-gcc
+
+ and bootstrap as above.
.. _`CMake Download Page`: https://cmake.org/cmake/resources/software.html
+.. _`MSYS2`: https://www.msys2.org/
Building CMake with CMake
-------------------------
@@ -81,6 +101,13 @@ For instructions how to do this, see documentation on `Running CMake`_.
.. _`Running CMake`: https://cmake.org/cmake/help/runningcmake.html
+To build the documentation, install `Sphinx`_ and configure CMake with
+``-DSPHINX_HTML=ON`` and/or ``-DSPHINX_MAN=ON`` to enable the "html" or
+"man" builder. Add ``-DSPHINX_EXECUTABLE=/path/to/sphinx-build`` if the
+tool is not found automatically.
+
+.. _`Sphinx`: http://sphinx-doc.org
+
Reporting Bugs
==============
diff --git a/Source/CMakeInstallDestinations.cmake b/Source/CMakeInstallDestinations.cmake
index 28f4e87ad..e82bec3cd 100644
--- a/Source/CMakeInstallDestinations.cmake
+++ b/Source/CMakeInstallDestinations.cmake
@@ -2,19 +2,22 @@
if(BEOS)
set(CMAKE_BIN_DIR_DEFAULT "bin") # HAIKU
set(CMAKE_DATA_DIR_DEFAULT "share/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") # HAIKU
- set(CMAKE_MAN_DIR_DEFAULT "documentation/man") # HAIKU
set(CMAKE_DOC_DIR_DEFAULT "documentation/doc/cmake-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") # HAIKU
+ set(CMAKE_INFO_DIR_DEFAULT "documentation/info") # HAIKU
+ set(CMAKE_MAN_DIR_DEFAULT "documentation/man") # HAIKU
set(CMAKE_XDGDATA_DIR_DEFAULT "share") # HAIKU
elseif(CYGWIN)
set(CMAKE_BIN_DIR_DEFAULT "bin") # CYGWIN
set(CMAKE_DATA_DIR_DEFAULT "share/cmake-${CMake_VERSION}") # CYGWIN
set(CMAKE_DOC_DIR_DEFAULT "share/doc/cmake-${CMake_VERSION}") # CYGWIN
+ set(CMAKE_INFO_DIR_DEFAULT "share/info") # CYGWIN
set(CMAKE_MAN_DIR_DEFAULT "share/man") # CYGWIN
set(CMAKE_XDGDATA_DIR_DEFAULT "share") # CYGWIN
else()
set(CMAKE_BIN_DIR_DEFAULT "bin") # OTHER
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_INFO_DIR_DEFAULT "info") # OTHER
set(CMAKE_MAN_DIR_DEFAULT "man") # OTHER
set(CMAKE_XDGDATA_DIR_DEFAULT "share") # OTHER
endif()
@@ -22,6 +25,7 @@ endif()
set(CMAKE_BIN_DIR_DESC "bin")
set(CMAKE_DATA_DIR_DESC "data")
set(CMAKE_DOC_DIR_DESC "docs")
+set(CMAKE_INFO_DIR_DESC "Info manual")
set(CMAKE_MAN_DIR_DESC "man pages")
set(CMAKE_XDGDATA_DIR_DESC "XDG specific files")
@@ -35,6 +39,7 @@ foreach(v
CMAKE_BIN_DIR
CMAKE_DATA_DIR
CMAKE_DOC_DIR
+ CMAKE_INFO_DIR
CMAKE_MAN_DIR
CMAKE_XDGDATA_DIR
)
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index 40403ca25..695e07598 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -31,6 +31,16 @@ else()
set(CMAKE_USE_ELF_PARSER)
endif()
+if(NOT CMake_DEFAULT_RECURSION_LIMIT)
+ if(DEFINED ENV{DASHBOARD_TEST_FROM_CTEST})
+ set(CMake_DEFAULT_RECURSION_LIMIT 100)
+ elseif(MINGW)
+ set(CMake_DEFAULT_RECURSION_LIMIT 400)
+ else()
+ set(CMake_DEFAULT_RECURSION_LIMIT 1000)
+ endif()
+endif()
+
if(APPLE)
set(CMAKE_USE_MACH_PARSER 1)
endif()
@@ -82,7 +92,6 @@ include_directories(
${CMAKE_ZLIB_INCLUDES}
${CMAKE_EXPAT_INCLUDES}
${CMAKE_TAR_INCLUDES}
- ${CMAKE_COMPRESS_INCLUDES}
${CMake_HAIKU_INCLUDE_DIRS}
)
@@ -131,7 +140,11 @@ set(SRCS
LexerParser/cmListFileLexer.c
LexerParser/cmListFileLexer.in.l
+ cmAffinity.cxx
+ cmAffinity.h
cmArchiveWrite.cxx
+ cmArgumentParser.cxx
+ cmArgumentParser.h
cmBase32.cxx
cmCacheManager.cxx
cmCacheManager.h
@@ -205,6 +218,18 @@ set(SRCS
cmExtraKateGenerator.h
cmExtraSublimeTextGenerator.cxx
cmExtraSublimeTextGenerator.h
+ cmFileAPI.cxx
+ cmFileAPI.h
+ cmFileAPICache.cxx
+ cmFileAPICache.h
+ cmFileAPICodemodel.cxx
+ cmFileAPICodemodel.h
+ cmFileAPICMakeFiles.cxx
+ cmFileAPICMakeFiles.h
+ cmFileCopier.cxx
+ cmFileCopier.h
+ cmFileInstaller.cxx
+ cmFileInstaller.h
cmFileLock.cxx
cmFileLock.h
cmFileLockPool.cxx
@@ -213,9 +238,15 @@ set(SRCS
cmFileLockResult.h
cmFilePathChecksum.cxx
cmFilePathChecksum.h
- cmFileTimeComparison.cxx
- cmFileTimeComparison.h
+ cmFileTime.cxx
+ cmFileTime.h
+ cmFileTimeCache.cxx
+ cmFileTimeCache.h
+ cmFileTimes.cxx
+ cmFileTimes.h
cmFortranParserImpl.cxx
+ cmFSPermissions.cxx
+ cmFSPermissions.h
cmGeneratedFileStream.cxx
cmGeneratorExpressionContext.cxx
cmGeneratorExpressionContext.h
@@ -235,6 +266,8 @@ set(SRCS
cmGeneratorExpression.h
cmGeneratorTarget.cxx
cmGeneratorTarget.h
+ cmGetPipes.cxx
+ cmGetPipes.h
cmGlobalCommonGenerator.cxx
cmGlobalCommonGenerator.h
cmGlobalGenerator.cxx
@@ -242,6 +275,8 @@ set(SRCS
cmGlobalGeneratorFactory.h
cmGlobalUnixMakefileGenerator3.cxx
cmGlobalUnixMakefileGenerator3.h
+ cmGlobVerificationManager.cxx
+ cmGlobVerificationManager.h
cmGraphAdjacencyList.h
cmGraphVizWriter.cxx
cmGraphVizWriter.h
@@ -254,11 +289,14 @@ set(SRCS
cmInstallFilesGenerator.cxx
cmInstallScriptGenerator.h
cmInstallScriptGenerator.cxx
+ cmInstallSubdirectoryGenerator.h
+ cmInstallSubdirectoryGenerator.cxx
cmInstallTargetGenerator.h
cmInstallTargetGenerator.cxx
cmInstallDirectoryGenerator.h
cmInstallDirectoryGenerator.cxx
cmLinkedTree.h
+ cmLinkItem.cxx
cmLinkItem.h
cmLinkLineComputer.cxx
cmLinkLineComputer.h
@@ -281,6 +319,7 @@ set(SRCS
cmMakefileExecutableTargetGenerator.cxx
cmMakefileLibraryTargetGenerator.cxx
cmMakefileUtilityTargetGenerator.cxx
+ cmMessageType.h
cmMessenger.cxx
cmMessenger.h
cmMSVC60LinkLineComputer.cxx
@@ -307,12 +346,18 @@ set(SRCS
cmPropertyDefinitionMap.h
cmPropertyMap.cxx
cmPropertyMap.h
- cmQtAutoGeneratorCommon.cxx
- cmQtAutoGeneratorCommon.h
- cmQtAutoGeneratorInitializer.cxx
- cmQtAutoGeneratorInitializer.h
- cmQtAutoGenerators.cxx
- cmQtAutoGenerators.h
+ cmQtAutoGen.cxx
+ cmQtAutoGen.h
+ cmQtAutoGenerator.cxx
+ cmQtAutoGenerator.h
+ cmQtAutoGenGlobalInitializer.cxx
+ cmQtAutoGenGlobalInitializer.h
+ cmQtAutoGenInitializer.cxx
+ cmQtAutoGenInitializer.h
+ cmQtAutoMocUic.cxx
+ cmQtAutoMocUic.h
+ cmQtAutoRcc.cxx
+ cmQtAutoRcc.h
cmRST.cxx
cmRST.h
cmScriptGenerator.h
@@ -321,6 +366,7 @@ set(SRCS
cmSourceFile.h
cmSourceFileLocation.cxx
cmSourceFileLocation.h
+ cmSourceFileLocationKind.h
cmSourceGroup.cxx
cmSourceGroup.h
cmState.cxx
@@ -342,10 +388,18 @@ set(SRCS
cmTestGenerator.cxx
cmTestGenerator.h
cmUuid.cxx
+ cmUVHandlePtr.cxx
+ cmUVHandlePtr.h
+ cmUVProcessChain.cxx
+ cmUVProcessChain.h
+ cmUVStreambuf.h
+ cmUVSignalHackRAII.h
cmVariableWatch.cxx
cmVariableWatch.h
cmVersion.cxx
cmVersion.h
+ cmWorkerPool.cxx
+ cmWorkerPool.h
cmWorkingDirectory.cxx
cmWorkingDirectory.h
cmXMLParser.cxx
@@ -356,13 +410,20 @@ set(SRCS
cmXMLWriter.h
cmake.cxx
cmake.h
+ cm_string_view.cxx
+ cm_string_view.hxx
+ cm_static_string_view.hxx
cmCommand.cxx
cmCommand.h
cmCommands.cxx
cmCommands.h
+ cmAddCompileDefinitionsCommand.cxx
+ cmAddCompileDefinitionsCommand.h
cmAddCompileOptionsCommand.cxx
cmAddCompileOptionsCommand.h
+ cmAddLinkOptionsCommand.cxx
+ cmAddLinkOptionsCommand.h
cmAddCustomCommandCommand.cxx
cmAddCustomCommandCommand.h
cmAddCustomTargetCommand.cxx
@@ -393,8 +454,6 @@ set(SRCS
cmCMakeMinimumRequired.h
cmCMakePolicyCommand.cxx
cmCMakePolicyCommand.h
- cmCommandArgumentsHelper.cxx
- cmCommandArgumentsHelper.h
cmConditionEvaluator.cxx
cmConditionEvaluator.h
cmConfigureFileCommand.cxx
@@ -469,6 +528,8 @@ set(SRCS
cmIncludeDirectoryCommand.h
cmIncludeExternalMSProjectCommand.cxx
cmIncludeExternalMSProjectCommand.h
+ cmIncludeGuardCommand.cxx
+ cmIncludeGuardCommand.h
cmIncludeRegularExpressionCommand.cxx
cmIncludeRegularExpressionCommand.h
cmInstallCommand.cxx
@@ -541,6 +602,9 @@ set(SRCS
cmSiteNameCommand.h
cmSourceGroupCommand.cxx
cmSourceGroupCommand.h
+ cmString.cxx
+ cmString.hxx
+ cmStringReplaceHelper.cxx
cmStringCommand.cxx
cmStringCommand.h
cmSubdirCommand.cxx
@@ -555,6 +619,10 @@ set(SRCS
cmTargetCompileOptionsCommand.h
cmTargetIncludeDirectoriesCommand.cxx
cmTargetIncludeDirectoriesCommand.h
+ cmTargetLinkOptionsCommand.cxx
+ cmTargetLinkOptionsCommand.h
+ cmTargetLinkDirectoriesCommand.cxx
+ cmTargetLinkDirectoriesCommand.h
cmTargetLinkLibrariesCommand.cxx
cmTargetLinkLibrariesCommand.h
cmTargetPropCommandBase.cxx
@@ -584,23 +652,21 @@ set(SRCS
cmWriteFileCommand.cxx
cmWriteFileCommand.h
- cm_auto_ptr.hxx
cm_get_date.h
cm_get_date.c
cm_utf8.h
cm_utf8.c
cm_codecvt.hxx
cm_codecvt.cxx
+ cm_thread.hxx
+
+ cmDuration.h
+ cmDuration.cxx
)
SET_PROPERTY(SOURCE cmProcessOutput.cxx APPEND PROPERTY COMPILE_DEFINITIONS
KWSYS_ENCODING_DEFAULT_CODEPAGE=${KWSYS_ENCODING_DEFAULT_CODEPAGE})
-# 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}
@@ -655,10 +721,10 @@ if (WIN32)
cmGlobalVisualStudio12Generator.cxx
cmGlobalVisualStudio14Generator.h
cmGlobalVisualStudio14Generator.cxx
- cmGlobalVisualStudio15Generator.h
- cmGlobalVisualStudio15Generator.cxx
cmGlobalVisualStudioGenerator.cxx
cmGlobalVisualStudioGenerator.h
+ cmGlobalVisualStudioVersionedGenerator.h
+ cmGlobalVisualStudioVersionedGenerator.cxx
cmIDEFlagTable.h
cmIDEOptions.cxx
cmIDEOptions.h
@@ -672,14 +738,6 @@ if (WIN32)
cmVisualStudioSlnParser.cxx
cmVisualStudioWCEPlatformParser.h
cmVisualStudioWCEPlatformParser.cxx
- cmGlobalGhsMultiGenerator.cxx
- cmGlobalGhsMultiGenerator.h
- cmLocalGhsMultiGenerator.cxx
- cmLocalGhsMultiGenerator.h
- cmGhsMultiTargetGenerator.cxx
- cmGhsMultiTargetGenerator.h
- cmGhsMultiGpj.cxx
- cmGhsMultiGpj.h
cmVSSetupHelper.cxx
cmVSSetupHelper.h
)
@@ -699,6 +757,22 @@ if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
)
endif()
+# GHS support
+# Works only for windows and linux
+if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ set(SRCS ${SRCS}
+ cmGlobalGhsMultiGenerator.cxx
+ cmGlobalGhsMultiGenerator.h
+ cmLocalGhsMultiGenerator.cxx
+ cmLocalGhsMultiGenerator.h
+ cmGhsMultiTargetGenerator.cxx
+ cmGhsMultiTargetGenerator.h
+ cmGhsMultiGpj.cxx
+ cmGhsMultiGpj.h
+ )
+endif()
+
+
# Ninja support
set(SRCS ${SRCS}
cmGlobalNinjaGenerator.cxx
@@ -714,6 +788,8 @@ set(SRCS ${SRCS}
cmNinjaUtilityTargetGenerator.h
cmNinjaLinkLineComputer.cxx
cmNinjaLinkLineComputer.h
+ cmNinjaLinkLineDeviceComputer.cxx
+ cmNinjaLinkLineDeviceComputer.h
)
# Temporary variable for tools targets
@@ -741,7 +817,7 @@ foreach(check
else()
set(CMake_${check} 0)
endif()
- set_property(SOURCE cmFileTimeComparison.cxx APPEND PROPERTY
+ set_property(SOURCE cmFileTime.cxx APPEND PROPERTY
COMPILE_DEFINITIONS CMake_${check}=${CMake_${check}})
endforeach()
@@ -749,12 +825,13 @@ endforeach()
add_library(CMakeLib ${SRCS})
target_link_libraries(CMakeLib cmsys
${CMAKE_EXPAT_LIBRARIES} ${CMAKE_ZLIB_LIBRARIES}
- ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES}
+ ${CMAKE_TAR_LIBRARIES}
${CMAKE_CURL_LIBRARIES}
${CMAKE_JSONCPP_LIBRARIES}
${CMAKE_LIBUV_LIBRARIES}
${CMAKE_LIBRHASH_LIBRARIES}
${CMake_KWIML_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT}
)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
@@ -766,9 +843,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR MATCHES "sparc"
endif()
endif()
-# On Apple we need CoreFoundation
+# On Apple we need CoreFoundation and CoreServices
if(APPLE)
target_link_libraries(CMakeLib "-framework CoreFoundation")
+ target_link_libraries(CMakeLib "-framework CoreServices")
endif()
if(WIN32 AND NOT UNIX)
@@ -777,12 +855,13 @@ if(WIN32 AND NOT UNIX)
target_link_libraries(CMakeLib rpcrt4 crypt32)
endif()
+target_compile_definitions(CMakeLib PUBLIC ${CLANG_TIDY_DEFINITIONS})
+
#
# CTestLib
#
include_directories(
"${CMake_SOURCE_DIR}/Source/CTest"
- ${CMAKE_XMLRPC_INCLUDES}
${CMAKE_CURL_INCLUDES}
)
#
@@ -790,7 +869,6 @@ include_directories(
#
set(CTEST_SRCS cmCTest.cxx
CTest/cmProcess.cxx
- CTest/cmCTestBatchTestHandler.cxx
CTest/cmCTestBuildAndTestHandler.cxx
CTest/cmCTestBuildCommand.cxx
CTest/cmCTestBuildHandler.cxx
@@ -849,7 +927,7 @@ set(CTEST_SRCS cmCTest.cxx
# Build CTestLib
add_library(CTestLib ${CTEST_SRCS})
-target_link_libraries(CTestLib CMakeLib ${CMAKE_CURL_LIBRARIES} ${CMAKE_XMLRPC_LIBRARIES})
+target_link_libraries(CTestLib CMakeLib ${CMAKE_CURL_LIBRARIES})
#
# CPack
@@ -863,10 +941,13 @@ include_directories(
set(CPACK_SRCS
CPack/cmCPackArchiveGenerator.cxx
CPack/cmCPackComponentGroup.cxx
+ CPack/cmCPackDebGenerator.cxx
+ CPack/cmCPackExternalGenerator.cxx
CPack/cmCPackGeneratorFactory.cxx
CPack/cmCPackGenerator.cxx
CPack/cmCPackLog.cxx
CPack/cmCPackNSISGenerator.cxx
+ CPack/cmCPackNuGetGenerator.cxx
CPack/cmCPackSTGZGenerator.cxx
CPack/cmCPackTGZGenerator.cxx
CPack/cmCPackTXZGenerator.cxx
@@ -896,15 +977,48 @@ if(CYGWIN)
)
endif()
+option(CPACK_ENABLE_FREEBSD_PKG "Add FreeBSD pkg(8) generator to CPack." OFF)
+
if(UNIX)
set(CPACK_SRCS ${CPACK_SRCS}
- CPack/cmCPackDebGenerator.cxx
CPack/cmCPackRPMGenerator.cxx
)
+
+ # Optionally, try to use pkg(8)
+ if(CPACK_ENABLE_FREEBSD_PKG)
+ # On UNIX, you may find FreeBSD's pkg(8) and attendant
+ # library -- it can be used on FreeBSD, Dragonfly, NetBSD,
+ # OpenBSD and also Linux and OSX. Look for the header and
+ # the library; it's a warning on FreeBSD if they're not
+ # found, and informational on other platforms.
+ find_path(FREEBSD_PKG_INCLUDE_DIRS "pkg.h")
+ if(FREEBSD_PKG_INCLUDE_DIRS)
+ find_library(FREEBSD_PKG_LIBRARIES
+ pkg
+ DOC "FreeBSD pkg(8) library")
+ if(FREEBSD_PKG_LIBRARIES)
+ set(CPACK_SRCS ${CPACK_SRCS}
+ CPack/cmCPackFreeBSDGenerator.cxx
+ )
+ endif()
+ endif()
+
+ if (NOT FREEBSD_PKG_INCLUDE_DIRS OR NOT FREEBSD_PKG_LIBRARIES)
+ message(FATAL_ERROR "CPack needs libpkg(3) to produce FreeBSD packages natively.")
+ endif()
+ else()
+ set(FREEBSD_PKG_INCLUDE_DIRS NOTFOUND)
+ set(FREEBSD_PKG_LIBRARIES NOTFOUND)
+ endif()
endif()
-if(WIN32)
+if(CYGWIN)
+ find_package(LibUUID)
+endif()
+if(WIN32 OR (CYGWIN AND LibUUID_FOUND))
set(CPACK_SRCS ${CPACK_SRCS}
+ CPack/WiX/cmCMakeToWixPath.cxx
+ CPack/WiX/cmCMakeToWixPath.h
CPack/WiX/cmCPackWIXGenerator.cxx
CPack/WiX/cmCPackWIXGenerator.h
CPack/WiX/cmWIXAccessControlList.cxx
@@ -925,7 +1039,7 @@ if(WIN32)
CPack/WiX/cmWIXShortcut.h
CPack/WiX/cmWIXSourceWriter.cxx
CPack/WiX/cmWIXSourceWriter.h
- )
+ )
endif()
if(APPLE)
@@ -958,11 +1072,18 @@ if(APPLE)
"See CMakeFiles/CMakeError.log for details of the failure.")
endif()
endif()
+if(CYGWIN AND LibUUID_FOUND)
+ target_link_libraries(CPackLib ${LibUUID_LIBRARIES})
+ include_directories(CPackLib ${LibUUID_INCLUDE_DIRS})
+ set_property(SOURCE CPack/cmCPackGeneratorFactory.cxx PROPERTY COMPILE_DEFINITIONS HAVE_LIBUUID)
+endif()
+if(CPACK_ENABLE_FREEBSD_PKG AND FREEBSD_PKG_INCLUDE_DIRS AND FREEBSD_PKG_LIBRARIES)
+ target_link_libraries(CPackLib ${FREEBSD_PKG_LIBRARIES})
+ include_directories(${FREEBSD_PKG_INCLUDE_DIRS})
+ add_definitions(-DHAVE_FREEBSD_PKG)
+endif()
if(APPLE)
- add_executable(cmakexbuild cmakexbuild.cxx)
- list(APPEND _tools cmakexbuild)
- target_link_libraries(cmakexbuild CMakeLib)
add_executable(OSXScriptLauncher
CPack/OSXScriptLauncher.cxx)
target_link_libraries(OSXScriptLauncher cmsys)
@@ -974,18 +1095,19 @@ add_executable(cmake cmakemain.cxx cmcmd.cxx cmcmd.h ${MANIFEST_FILE})
list(APPEND _tools cmake)
target_link_libraries(cmake CMakeLib)
-if(CMake_ENABLE_SERVER_MODE)
- add_library(CMakeServerLib
- cmFileMonitor.cxx cmFileMonitor.h
- cmServer.cxx cmServer.h
- cmServerConnection.cxx cmServerConnection.h
- cmServerProtocol.cxx cmServerProtocol.h
- )
- target_link_libraries(CMakeServerLib CMakeLib)
- set_property(SOURCE cmcmd.cxx APPEND PROPERTY COMPILE_DEFINITIONS HAVE_SERVER_MODE=1)
-
- target_link_libraries(cmake CMakeServerLib)
-endif()
+add_library(CMakeServerLib
+ cmConnection.h cmConnection.cxx
+ cmFileMonitor.cxx cmFileMonitor.h
+ cmJsonObjectDictionary.h
+ cmJsonObjects.h
+ cmJsonObjects.cxx
+ cmPipeConnection.cxx cmPipeConnection.h
+ cmServer.cxx cmServer.h
+ cmServerConnection.cxx cmServerConnection.h
+ cmServerProtocol.cxx cmServerProtocol.h
+ )
+target_link_libraries(CMakeServerLib CMakeLib)
+target_link_libraries(cmake CMakeServerLib)
# Build CTest executable
add_executable(ctest ctest.cxx ${MANIFEST_FILE})
@@ -1011,6 +1133,19 @@ endif()
include (${CMake_BINARY_DIR}/Source/LocalUserOptions.cmake OPTIONAL)
include (${CMake_SOURCE_DIR}/Source/LocalUserOptions.cmake OPTIONAL)
+if(WIN32)
+ # Add Windows executable version information.
+ configure_file("CMakeVersion.rc.in" "CMakeVersion.rc" @ONLY)
+
+ # We use a separate object library for this to work around a limitation of
+ # MinGW's windres tool with spaces in the path to the include directories.
+ add_library(CMakeVersion OBJECT "${CMAKE_CURRENT_BINARY_DIR}/CMakeVersion.rc")
+ set_property(TARGET CMakeVersion PROPERTY INCLUDE_DIRECTORIES "")
+ foreach(_tool ${_tools})
+ target_sources(${_tool} PRIVATE $<TARGET_OBJECTS:CMakeVersion>)
+ endforeach()
+endif()
+
# Install tools
foreach(_tool ${_tools})
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index ecf511607..ba06c4f7e 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,5 +1,5 @@
# CMake version number components.
set(CMake_VERSION_MAJOR 3)
-set(CMake_VERSION_MINOR 9)
-set(CMake_VERSION_PATCH 4)
+set(CMake_VERSION_MINOR 15)
+set(CMake_VERSION_PATCH 6)
#set(CMake_VERSION_RC 0)
diff --git a/Source/CMakeVersionCompute.cmake b/Source/CMakeVersionCompute.cmake
index d9218d731..72a580058 100644
--- a/Source/CMakeVersionCompute.cmake
+++ b/Source/CMakeVersionCompute.cmake
@@ -27,3 +27,18 @@ endif()
if(CMake_VERSION_IS_DIRTY)
set(CMake_VERSION ${CMake_VERSION}-dirty)
endif()
+
+# Compute the binary version that appears in the RC file. Version
+# components in the RC file are 16-bit integers so we may have to
+# split the patch component.
+if(CMake_VERSION_PATCH MATCHES "^([0-9]+)([0-9][0-9][0-9][0-9])$")
+ set(CMake_RCVERSION_YEAR "${CMAKE_MATCH_1}")
+ set(CMake_RCVERSION_MONTH_DAY "${CMAKE_MATCH_2}")
+ string(REGEX REPLACE "^0+" "" CMake_RCVERSION_MONTH_DAY "${CMake_RCVERSION_MONTH_DAY}")
+ set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_RCVERSION_YEAR},${CMake_RCVERSION_MONTH_DAY})
+ unset(CMake_RCVERSION_MONTH_DAY)
+ unset(CMake_RCVERSION_YEAR)
+else()
+ set(CMake_RCVERSION ${CMake_VERSION_MAJOR},${CMake_VERSION_MINOR},${CMake_VERSION_PATCH})
+endif()
+set(CMake_RCVERSION_STR ${CMake_VERSION})
diff --git a/Source/CPack/IFW/cmCPackIFWCommon.cxx b/Source/CPack/IFW/cmCPackIFWCommon.cxx
index e8f05bd50..1e7264156 100644
--- a/Source/CPack/IFW/cmCPackIFWCommon.cxx
+++ b/Source/CPack/IFW/cmCPackIFWCommon.cxx
@@ -15,14 +15,14 @@
#include <vector>
cmCPackIFWCommon::cmCPackIFWCommon()
- : Generator(CM_NULLPTR)
+ : Generator(nullptr)
{
}
const char* cmCPackIFWCommon::GetOption(const std::string& op) const
{
return this->Generator ? this->Generator->cmCPackGenerator::GetOption(op)
- : CM_NULLPTR;
+ : nullptr;
}
bool cmCPackIFWCommon::IsOn(const std::string& op) const
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.cxx b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
index 226ea0a29..c1b6eea9a 100644
--- a/Source/CPack/IFW/cmCPackIFWGenerator.cxx
+++ b/Source/CPack/IFW/cmCPackIFWGenerator.cxx
@@ -9,6 +9,7 @@
#include "cmCPackIFWPackage.h"
#include "cmCPackIFWRepository.h"
#include "cmCPackLog.h" // IWYU pragma: keep
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
@@ -20,9 +21,7 @@ cmCPackIFWGenerator::cmCPackIFWGenerator()
this->Generator = this;
}
-cmCPackIFWGenerator::~cmCPackIFWGenerator()
-{
-}
+cmCPackIFWGenerator::~cmCPackIFWGenerator() = default;
int cmCPackIFWGenerator::PackageFiles()
{
@@ -49,10 +48,23 @@ int cmCPackIFWGenerator::PackageFiles()
ifwCmd += " -p " + this->toplevel + "/packages";
if (!this->PkgsDirsVector.empty()) {
- for (std::vector<std::string>::iterator it =
- this->PkgsDirsVector.begin();
- it != this->PkgsDirsVector.end(); ++it) {
- ifwCmd += " -p " + *it;
+ for (std::string const& it : this->PkgsDirsVector) {
+ ifwCmd += " -p " + it;
+ }
+ }
+
+ if (!this->RepoDirsVector.empty()) {
+ if (!this->IsVersionLess("3.1")) {
+ for (std::string const& rd : this->RepoDirsVector) {
+ ifwCmd += " --repository " + rd;
+ }
+ } else {
+ cmCPackIFWLogger(WARNING,
+ "The \"CPACK_IFW_REPOSITORIES_DIRECTORIES\" "
+ << "variable is set, but content will be skipped, "
+ << "because this feature available only since "
+ << "QtIFW 3.1. Please update your QtIFW instance."
+ << std::endl);
}
}
@@ -72,15 +84,16 @@ int cmCPackIFWGenerator::PackageFiles()
std::string output;
int retVal = 1;
cmCPackIFWLogger(OUTPUT, "- Generate repository" << std::endl);
- bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output,
- &output, &retVal, CM_NULLPTR,
- this->GeneratorVerbose, 0);
+ bool res = cmSystemTools::RunSingleCommand(
+ ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
if (!res || retVal) {
- cmGeneratedFileStream ofs(ifwTmpFile.c_str());
+ cmGeneratedFileStream ofs(ifwTmpFile);
ofs << "# Run command: " << ifwCmd << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
- cmCPackIFWLogger(ERROR, "Problem running IFW command: "
+ cmCPackIFWLogger(ERROR,
+ "Problem running IFW command: "
<< ifwCmd << std::endl
<< "Please check " << ifwTmpFile << " for errors"
<< std::endl);
@@ -89,15 +102,16 @@ int cmCPackIFWGenerator::PackageFiles()
if (!this->Repository.RepositoryUpdate.empty() &&
!this->Repository.PatchUpdatesXml()) {
- cmCPackIFWLogger(WARNING, "Problem patch IFW \"Updates\" "
+ cmCPackIFWLogger(WARNING,
+ "Problem patch IFW \"Updates\" "
<< "file: "
<< this->toplevel + "/repository/Updates.xml"
<< std::endl);
}
- cmCPackIFWLogger(OUTPUT, "- repository: " << this->toplevel
- << "/repository generated"
- << std::endl);
+ cmCPackIFWLogger(OUTPUT,
+ "- repository: " << this->toplevel
+ << "/repository generated" << std::endl);
}
// Run binary creator
@@ -121,10 +135,23 @@ int cmCPackIFWGenerator::PackageFiles()
ifwCmd += " -p " + this->toplevel + "/packages";
if (!this->PkgsDirsVector.empty()) {
- for (std::vector<std::string>::iterator it =
- this->PkgsDirsVector.begin();
- it != this->PkgsDirsVector.end(); ++it) {
- ifwCmd += " -p " + *it;
+ for (std::string const& it : this->PkgsDirsVector) {
+ ifwCmd += " -p " + it;
+ }
+ }
+
+ if (!this->RepoDirsVector.empty()) {
+ if (!this->IsVersionLess("3.1")) {
+ for (std::string const& rd : this->RepoDirsVector) {
+ ifwCmd += " --repository " + rd;
+ }
+ } else {
+ cmCPackIFWLogger(WARNING,
+ "The \"CPACK_IFW_REPOSITORIES_DIRECTORIES\" "
+ << "variable is set, but content will be skipped, "
+ << "because this feature available only since "
+ << "QtIFW 3.1. Please update your QtIFW instance."
+ << std::endl);
}
}
@@ -164,20 +191,22 @@ int cmCPackIFWGenerator::PackageFiles()
ifwCmd += " " + this->packageFileNames[0];
} else {
ifwCmd += " installer";
+ ifwCmd += this->OutputExtension;
}
cmCPackIFWLogger(VERBOSE, "Execute: " << ifwCmd << std::endl);
std::string output;
int retVal = 1;
cmCPackIFWLogger(OUTPUT, "- Generate package" << std::endl);
- bool res = cmSystemTools::RunSingleCommand(ifwCmd.c_str(), &output,
- &output, &retVal, CM_NULLPTR,
- this->GeneratorVerbose, 0);
+ bool res = cmSystemTools::RunSingleCommand(
+ ifwCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
if (!res || retVal) {
- cmGeneratedFileStream ofs(ifwTmpFile.c_str());
+ cmGeneratedFileStream ofs(ifwTmpFile);
ofs << "# Run command: " << ifwCmd << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
- cmCPackIFWLogger(ERROR, "Problem running IFW command: "
+ cmCPackIFWLogger(ERROR,
+ "Problem running IFW command: "
<< ifwCmd << std::endl
<< "Please check " << ifwTmpFile << " for errors"
<< std::endl);
@@ -205,7 +234,7 @@ const char* cmCPackIFWGenerator::GetPackagingInstallPrefix()
const char* cmCPackIFWGenerator::GetOutputExtension()
{
- return this->ExecutableSuffix.c_str();
+ return this->OutputExtension.c_str();
}
int cmCPackIFWGenerator::InitializeInternal()
@@ -225,14 +254,15 @@ int cmCPackIFWGenerator::InitializeInternal()
const char* BinCreatorStr = this->GetOption(BinCreatorOpt);
if (!BinCreatorStr || cmSystemTools::IsNOTFOUND(BinCreatorStr)) {
- this->BinCreator = "";
+ this->BinCreator.clear();
} else {
this->BinCreator = BinCreatorStr;
}
if (this->BinCreator.empty()) {
- cmCPackIFWLogger(ERROR, "Cannot find QtIFW compiler \"binarycreator\": "
- "likely it is not installed, or not in your PATH"
+ cmCPackIFWLogger(ERROR,
+ "Cannot find QtIFW compiler \"binarycreator\": "
+ "likely it is not installed, or not in your PATH"
<< std::endl);
return 0;
}
@@ -241,7 +271,7 @@ int cmCPackIFWGenerator::InitializeInternal()
const char* RepoGenStr = this->GetOption(RepoGenOpt);
if (!RepoGenStr || cmSystemTools::IsNOTFOUND(RepoGenStr)) {
- this->RepoGen = "";
+ this->RepoGen.clear();
} else {
this->RepoGen = RepoGenStr;
}
@@ -265,6 +295,13 @@ int cmCPackIFWGenerator::InitializeInternal()
cmSystemTools::ExpandListArgument(dirs, this->PkgsDirsVector);
}
+ // Additional repositories dirs
+ this->RepoDirsVector.clear();
+ if (const char* dirs =
+ this->GetOption("CPACK_IFW_REPOSITORIES_DIRECTORIES")) {
+ cmSystemTools::ExpandListArgument(dirs, this->RepoDirsVector);
+ }
+
// Installer
this->Installer.Generator = this;
this->Installer.ConfigureFromOptions();
@@ -281,9 +318,8 @@ int cmCPackIFWGenerator::InitializeInternal()
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) {
- this->GetRepository(*rit);
+ for (std::string const& r : RepoAllVector) {
+ this->GetRepository(r);
}
}
@@ -305,16 +341,29 @@ int cmCPackIFWGenerator::InitializeInternal()
}
// Executable suffix
- if (const char* optExeSuffix = this->GetOption("CMAKE_EXECUTABLE_SUFFIX")) {
- this->ExecutableSuffix = optExeSuffix;
- if (this->ExecutableSuffix.empty()) {
- std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME"));
- if (sysName == "Linux") {
- this->ExecutableSuffix = ".run";
- }
- }
+ std::string exeSuffix(this->GetOption("CMAKE_EXECUTABLE_SUFFIX"));
+ std::string sysName(this->GetOption("CMAKE_SYSTEM_NAME"));
+ if (sysName == "Linux") {
+ this->ExecutableSuffix = ".run";
+ } else if (sysName == "Windows") {
+ this->ExecutableSuffix = ".exe";
+ } else if (sysName == "Darwin") {
+ this->ExecutableSuffix = ".app";
+ } else {
+ this->ExecutableSuffix = exeSuffix;
+ }
+
+ // Output extension
+ if (const char* optOutExt =
+ this->GetOption("CPACK_IFW_PACKAGE_FILE_EXTENSION")) {
+ this->OutputExtension = optOutExt;
+ } else if (sysName == "Darwin") {
+ this->OutputExtension = ".dmg";
} else {
- this->ExecutableSuffix = this->cmCPackGenerator::GetOutputExtension();
+ this->OutputExtension = this->ExecutableSuffix;
+ }
+ if (this->OutputExtension.empty()) {
+ this->OutputExtension = this->cmCPackGenerator::GetOutputExtension();
}
return this->Superclass::InitializeInternal();
@@ -370,7 +419,8 @@ cmCPackComponent* cmCPackIFWGenerator::GetComponent(
}
} else {
this->Packages.erase(name);
- cmCPackIFWLogger(ERROR, "Cannot configure package \""
+ cmCPackIFWLogger(ERROR,
+ "Cannot configure package \""
<< name << "\" for component \"" << component->Name
<< "\"" << std::endl);
}
@@ -405,7 +455,8 @@ cmCPackComponentGroup* cmCPackIFWGenerator::GetComponentGroup(
this->BinaryPackages.insert(package);
} else {
this->Packages.erase(name);
- cmCPackIFWLogger(ERROR, "Cannot configure package \""
+ cmCPackIFWLogger(ERROR,
+ "Cannot configure package \""
<< name << "\" for component group \"" << group->Name
<< "\"" << std::endl);
}
@@ -520,7 +571,7 @@ cmCPackIFWPackage* cmCPackIFWGenerator::GetGroupPackage(
{
std::map<cmCPackComponentGroup*, cmCPackIFWPackage*>::const_iterator pit =
this->GroupPackages.find(group);
- return pit != this->GroupPackages.end() ? pit->second : CM_NULLPTR;
+ return pit != this->GroupPackages.end() ? pit->second : nullptr;
}
cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage(
@@ -528,7 +579,7 @@ cmCPackIFWPackage* cmCPackIFWGenerator::GetComponentPackage(
{
std::map<cmCPackComponent*, cmCPackIFWPackage*>::const_iterator pit =
this->ComponentPackages.find(component);
- return pit != this->ComponentPackages.end() ? pit->second : CM_NULLPTR;
+ return pit != this->ComponentPackages.end() ? pit->second : nullptr;
}
cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository(
@@ -550,8 +601,9 @@ cmCPackIFWRepository* cmCPackIFWGenerator::GetRepository(
}
} else {
this->Repositories.erase(repositoryName);
- repository = CM_NULLPTR;
- cmCPackIFWLogger(WARNING, "Invalid repository \""
+ repository = nullptr;
+ cmCPackIFWLogger(WARNING,
+ "Invalid repository \""
<< repositoryName << "\""
<< " configuration. Repository will be skipped."
<< std::endl);
diff --git a/Source/CPack/IFW/cmCPackIFWGenerator.h b/Source/CPack/IFW/cmCPackIFWGenerator.h
index 8348ceeec..0430122c9 100644
--- a/Source/CPack/IFW/cmCPackIFWGenerator.h
+++ b/Source/CPack/IFW/cmCPackIFWGenerator.h
@@ -22,7 +22,9 @@
*
* http://qt-project.org/doc/qtinstallerframework/index.html
*/
-class cmCPackIFWGenerator : public cmCPackGenerator, public cmCPackIFWCommon
+class cmCPackIFWGenerator
+ : public cmCPackGenerator
+ , public cmCPackIFWCommon
{
public:
cmCPackTypeMacro(cmCPackIFWGenerator, cmCPackGenerator);
@@ -47,7 +49,7 @@ public:
/**
* Destruct IFW generator
*/
- ~cmCPackIFWGenerator() CM_OVERRIDE;
+ ~cmCPackIFWGenerator() override;
protected:
// cmCPackGenerator reimplementation
@@ -56,18 +58,18 @@ protected:
* @brief Initialize generator
* @return 0 on failure
*/
- int InitializeInternal() CM_OVERRIDE;
- int PackageFiles() CM_OVERRIDE;
- const char* GetPackagingInstallPrefix() CM_OVERRIDE;
+ int InitializeInternal() override;
+ int PackageFiles() override;
+ const char* GetPackagingInstallPrefix() override;
/**
- * @brief Extension of binary installer
- * @return Executable suffix or value from default implementation
+ * @brief Target binary extension
+ * @return Executable suffix or disk image format
*/
- const char* GetOutputExtension() CM_OVERRIDE;
+ const char* GetOutputExtension() override;
std::string GetComponentInstallDirNameSuffix(
- const std::string& componentName) CM_OVERRIDE;
+ const std::string& componentName) override;
/**
* @brief Get Component
@@ -79,7 +81,7 @@ protected:
* @return Pointer to component
*/
cmCPackComponent* GetComponent(const std::string& projectName,
- const std::string& componentName) CM_OVERRIDE;
+ const std::string& componentName) override;
/**
* @brief Get group of component
@@ -91,12 +93,12 @@ protected:
* @return Pointer to component group
*/
cmCPackComponentGroup* GetComponentGroup(
- const std::string& projectName, const std::string& groupName) CM_OVERRIDE;
+ const std::string& projectName, const std::string& groupName) override;
- enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const
- CM_OVERRIDE;
- bool SupportsAbsoluteDestination() const CM_OVERRIDE;
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir()
+ const override;
+ bool SupportsAbsoluteDestination() const override;
+ bool SupportsComponentInstallation() const override;
protected:
// Methods
@@ -143,10 +145,12 @@ private:
std::string BinCreator;
std::string FrameworkVersion;
std::string ExecutableSuffix;
+ std::string OutputExtension;
bool OnlineOnly;
bool ResolveDuplicateNames;
std::vector<std::string> PkgsDirsVector;
+ std::vector<std::string> RepoDirsVector;
};
#endif
diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.cxx b/Source/CPack/IFW/cmCPackIFWInstaller.cxx
index 288e924e5..a075a17e3 100644
--- a/Source/CPack/IFW/cmCPackIFWInstaller.cxx
+++ b/Source/CPack/IFW/cmCPackIFWInstaller.cxx
@@ -16,15 +16,14 @@
#include <stddef.h>
#include <utility>
-cmCPackIFWInstaller::cmCPackIFWInstaller()
-{
-}
+cmCPackIFWInstaller::cmCPackIFWInstaller() = default;
void cmCPackIFWInstaller::printSkippedOptionWarning(
const std::string& optionName, const std::string& optionValue)
{
cmCPackIFWLogger(
- WARNING, "Option "
+ WARNING,
+ "Option "
<< optionName << " is set to \"" << optionValue
<< "\" but will be skipped because the specified file does not exist."
<< std::endl);
@@ -93,6 +92,15 @@ void cmCPackIFWInstaller::ConfigureFromOptions()
}
}
+ // RemoveTargetDir
+ if (this->IsSetToOff("CPACK_IFW_PACKAGE_REMOVE_TARGET_DIR")) {
+ this->RemoveTargetDir = "false";
+ } else if (this->IsOn("CPACK_IFW_PACKAGE_REMOVE_TARGET_DIR")) {
+ this->RemoveTargetDir = "true";
+ } else {
+ this->RemoveTargetDir.clear();
+ }
+
// Logo
if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_LOGO")) {
if (cmSystemTools::FileExists(option)) {
@@ -137,12 +145,22 @@ void cmCPackIFWInstaller::ConfigureFromOptions()
if (this->WizardStyle != "Modern" && this->WizardStyle != "Aero" &&
this->WizardStyle != "Mac" && this->WizardStyle != "Classic") {
cmCPackIFWLogger(
- WARNING, "Option CPACK_IFW_PACKAGE_WIZARD_STYLE has unknown value \""
+ WARNING,
+ "Option CPACK_IFW_PACKAGE_WIZARD_STYLE has unknown value \""
<< option << "\". Expected values are: Modern, Aero, Mac, Classic."
<< std::endl);
}
}
+ // StyleSheet
+ if (const char* option = this->GetOption("CPACK_IFW_PACKAGE_STYLE_SHEET")) {
+ if (cmSystemTools::FileExists(option)) {
+ this->StyleSheet = option;
+ } else {
+ this->printSkippedOptionWarning("CPACK_IFW_PACKAGE_STYLE_SHEET", option);
+ }
+ }
+
// WizardDefaultWidth
if (const char* option =
this->GetOption("CPACK_IFW_PACKAGE_WIZARD_DEFAULT_WIDTH")) {
@@ -262,7 +280,7 @@ public:
std::string path, basePath;
protected:
- void StartElement(const std::string& name, const char** /*atts*/) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** /*atts*/) override
{
this->file = name == "file";
if (file) {
@@ -270,21 +288,20 @@ protected:
}
}
- void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
+ void CharacterDataHandler(const char* data, int length) override
{
if (this->file) {
std::string content(data, data + length);
content = cmSystemTools::TrimWhitespace(content);
std::string source = this->basePath + "/" + content;
std::string destination = this->path + "/" + content;
- if (!cmSystemTools::CopyFileIfDifferent(source.data(),
- destination.data())) {
+ if (!cmSystemTools::CopyFileIfDifferent(source, destination)) {
this->hasErrors = true;
}
}
}
- void EndElement(const std::string& /*name*/) CM_OVERRIDE {}
+ void EndElement(const std::string& /*name*/) override {}
};
void cmCPackIFWInstaller::GenerateInstallerFile()
@@ -295,7 +312,7 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
}
// Output stream
- cmGeneratedFileStream fout((this->Directory + "/config/config.xml").data());
+ cmGeneratedFileStream fout(this->Directory + "/config/config.xml");
cmXMLWriter xout(fout);
xout.StartDocument();
@@ -373,6 +390,14 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
xout.Element("WizardStyle", this->WizardStyle);
}
+ // Stylesheet
+ if (!this->StyleSheet.empty()) {
+ std::string name = cmSystemTools::GetFilenameName(this->StyleSheet);
+ std::string path = this->Directory + "/config/" + name;
+ cmsys::SystemTools::CopyFileIfDifferent(this->StyleSheet, path);
+ xout.Element("StyleSheet", name);
+ }
+
// WizardDefaultWidth
if (!this->WizardDefaultWidth.empty()) {
xout.Element("WizardDefaultWidth", this->WizardDefaultWidth);
@@ -406,9 +431,8 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
// Remote repositories
if (!this->RemoteRepositories.empty()) {
xout.StartElement("RemoteRepositories");
- for (RepositoriesVector::iterator rit = this->RemoteRepositories.begin();
- rit != this->RemoteRepositories.end(); ++rit) {
- (*rit)->WriteRepositoryConfig(xout);
+ for (cmCPackIFWRepository* r : this->RemoteRepositories) {
+ r->WriteRepositoryConfig(xout);
}
xout.EndElement();
}
@@ -423,6 +447,10 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
xout.Element("MaintenanceToolIniFile", this->MaintenanceToolIniFile);
}
+ if (!this->RemoveTargetDir.empty()) {
+ xout.Element("RemoveTargetDir", this->RemoveTargetDir);
+ }
+
// Different allows
if (this->IsVersionLess("2.0")) {
// CPack IFW default policy
@@ -455,9 +483,10 @@ void cmCPackIFWInstaller::GenerateInstallerFile()
std::string name = cmSystemTools::GetFilenameName(this->Resources[i]);
std::string path = this->Directory + "/resources/" + name;
cmsys::SystemTools::CopyFileIfDifferent(this->Resources[i], path);
- resources.push_back(name);
+ resources.push_back(std::move(name));
} else {
- cmCPackIFWLogger(WARNING, "Can't copy resources from \""
+ cmCPackIFWLogger(WARNING,
+ "Can't copy resources from \""
<< this->Resources[i]
<< "\". Resource will be skipped." << std::endl);
}
@@ -492,9 +521,8 @@ void cmCPackIFWInstaller::GeneratePackageFiles()
}
// Generate packages meta information
- for (PackagesMap::iterator pit = this->Packages.begin();
- pit != this->Packages.end(); ++pit) {
- cmCPackIFWPackage* package = pit->second;
+ for (auto& p : this->Packages) {
+ cmCPackIFWPackage* package = p.second;
package->GeneratePackageFile();
}
}
diff --git a/Source/CPack/IFW/cmCPackIFWInstaller.h b/Source/CPack/IFW/cmCPackIFWInstaller.h
index b635f4222..be51fa5fb 100644
--- a/Source/CPack/IFW/cmCPackIFWInstaller.h
+++ b/Source/CPack/IFW/cmCPackIFWInstaller.h
@@ -72,6 +72,9 @@ public:
/// Wizard style name
std::string WizardStyle;
+ /// Filename for a style sheet
+ std::string StyleSheet;
+
/// Wizard width
std::string WizardDefaultWidth;
@@ -99,6 +102,10 @@ public:
/// Set to true if the installation path can contain non-ASCII characters
std::string AllowNonAsciiCharacters;
+ /// Set to false if the target directory should not be deleted when
+ /// uninstalling
+ std::string RemoveTargetDir;
+
/// Set to false if the installation path cannot contain space characters
std::string AllowSpaceInPath;
diff --git a/Source/CPack/IFW/cmCPackIFWPackage.cxx b/Source/CPack/IFW/cmCPackIFWPackage.cxx
index c5311c31c..a1a52b185 100644
--- a/Source/CPack/IFW/cmCPackIFWPackage.cxx
+++ b/Source/CPack/IFW/cmCPackIFWPackage.cxx
@@ -24,9 +24,7 @@ cmCPackIFWPackage::CompareStruct::CompareStruct()
}
//------------------------------------------------------- DependenceStruct ---
-cmCPackIFWPackage::DependenceStruct::DependenceStruct()
-{
-}
+cmCPackIFWPackage::DependenceStruct::DependenceStruct() = default;
cmCPackIFWPackage::DependenceStruct::DependenceStruct(
const std::string& dependence)
@@ -92,7 +90,7 @@ std::string cmCPackIFWPackage::DependenceStruct::NameWithCompare() const
//------------------------------------------------------ cmCPackIFWPackage ---
cmCPackIFWPackage::cmCPackIFWPackage()
- : Installer(CM_NULLPTR)
+ : Installer(nullptr)
{
}
@@ -111,25 +109,25 @@ void cmCPackIFWPackage::DefaultConfiguration()
{
this->DisplayName.clear();
this->Description.clear();
- this->Version = "";
- this->ReleaseDate = "";
- this->Script = "";
+ this->Version.clear();
+ this->ReleaseDate.clear();
+ this->Script.clear();
this->Licenses.clear();
this->UserInterfaces.clear();
this->Translations.clear();
- this->SortingPriority = "";
- this->UpdateText = "";
- this->Default = "";
- this->Essential = "";
- this->Virtual = "";
- this->ForcedInstallation = "";
- this->RequiresAdminRights = "";
+ this->SortingPriority.clear();
+ this->UpdateText.clear();
+ this->Default.clear();
+ this->Essential.clear();
+ this->Virtual.clear();
+ this->ForcedInstallation.clear();
+ this->RequiresAdminRights.clear();
}
-// Defaul configuration (all in one package)
+// Default configuration (all in one package)
int cmCPackIFWPackage::ConfigureFromOptions()
{
- // Restore defaul configuration
+ // Restore default configuration
this->DefaultConfiguration();
// Name
@@ -168,7 +166,7 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component)
return 0;
}
- // Restore defaul configuration
+ // Restore default configuration
this->DefaultConfiguration();
std::string prefix = "CPACK_IFW_COMPONENT_" +
@@ -203,10 +201,8 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component)
// CMake dependencies
if (!component->Dependencies.empty()) {
- std::vector<cmCPackComponent*>::iterator dit;
- for (dit = component->Dependencies.begin();
- dit != component->Dependencies.end(); ++dit) {
- this->Dependencies.insert(this->Generator->ComponentPackages[*dit]);
+ for (cmCPackComponent* dep : component->Dependencies) {
+ this->Dependencies.insert(this->Generator->ComponentPackages[dep]);
}
}
@@ -228,7 +224,8 @@ int cmCPackIFWPackage::ConfigureFromComponent(cmCPackComponent* component)
if (const char* option = this->GetOption(prefix + "PRIORITY")) {
this->SortingPriority = option;
cmCPackIFWLogger(
- WARNING, "The \"PRIORITY\" option is set "
+ WARNING,
+ "The \"PRIORITY\" option is set "
<< "for component \"" << component->Name << "\", but there option is "
<< "deprecated. Please use \"SORTING_PRIORITY\" option instead."
<< std::endl);
@@ -257,7 +254,7 @@ int cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup* group)
return 0;
}
- // Restore defaul configuration
+ // Restore default configuration
this->DefaultConfiguration();
std::string prefix = "CPACK_IFW_COMPONENT_GROUP_" +
@@ -305,7 +302,8 @@ int cmCPackIFWPackage::ConfigureFromGroup(cmCPackComponentGroup* group)
if (const char* option = this->GetOption(prefix + "PRIORITY")) {
this->SortingPriority = option;
cmCPackIFWLogger(
- WARNING, "The \"PRIORITY\" option is set "
+ WARNING,
+ "The \"PRIORITY\" option is set "
<< "for component group \"" << group->Name
<< "\", but there option is "
<< "deprecated. Please use \"SORTING_PRIORITY\" option instead."
@@ -359,7 +357,7 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix)
if (this->IsSetToEmpty(option)) {
this->DisplayName.clear();
} else if (const char* value = this->GetOption(option)) {
- this->ExpandListArgument(value, this->DisplayName);
+ cmCPackIFWPackage::ExpandListArgument(value, this->DisplayName);
}
// Description
@@ -367,7 +365,7 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix)
if (this->IsSetToEmpty(option)) {
this->Description.clear();
} else if (const char* value = this->GetOption(option)) {
- this->ExpandListArgument(value, this->Description);
+ cmCPackIFWPackage::ExpandListArgument(value, this->Description);
}
// Release date
@@ -413,9 +411,8 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix)
if (const char* value = this->GetOption(option)) {
cmSystemTools::ExpandListArgument(value, deps);
}
- for (std::vector<std::string>::iterator dit = deps.begin();
- dit != deps.end(); ++dit) {
- DependenceStruct dep(*dit);
+ for (std::string const& d : deps) {
+ DependenceStruct dep(d);
if (this->Generator->Packages.count(dep.Name)) {
cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name];
dep.Name = depPkg.Name;
@@ -435,9 +432,8 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix)
} else if (const char* value = this->GetOption(option)) {
std::vector<std::string> depsOn;
cmSystemTools::ExpandListArgument(value, depsOn);
- for (std::vector<std::string>::iterator dit = depsOn.begin();
- dit != depsOn.end(); ++dit) {
- DependenceStruct dep(*dit);
+ for (std::string const& d : depsOn) {
+ DependenceStruct dep(d);
if (this->Generator->Packages.count(dep.Name)) {
cmCPackIFWPackage& depPkg = this->Generator->Packages[dep.Name];
dep.Name = depPkg.Name;
@@ -486,6 +482,15 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix)
this->ForcedInstallation = "false";
}
+ // Replaces
+ option = prefix + "REPLACES";
+ if (this->IsSetToEmpty(option)) {
+ this->Replaces.clear();
+ } else if (const char* value = this->GetOption(option)) {
+ this->Replaces.clear();
+ cmSystemTools::ExpandListArgument(value, this->Replaces);
+ }
+
// Requires admin rights
option = prefix + "REQUIRES_ADMIN_RIGHTS";
if (this->IsSetToEmpty(option)) {
@@ -496,6 +501,16 @@ int cmCPackIFWPackage::ConfigureFromPrefix(const std::string& prefix)
this->RequiresAdminRights = "false";
}
+ // Checkable
+ option = prefix + "CHECKABLE";
+ if (this->IsSetToEmpty(option)) {
+ this->Checkable.clear();
+ } else if (this->IsOn(option)) {
+ this->Checkable = "true";
+ } else if (this->IsSetToOff(option)) {
+ this->Checkable = "false";
+ }
+
return 1;
}
@@ -511,7 +526,7 @@ void cmCPackIFWPackage::GeneratePackageFile()
}
// Output stream
- cmGeneratedFileStream fout((this->Directory + "/meta/package.xml").data());
+ cmGeneratedFileStream fout(this->Directory + "/meta/package.xml");
cmXMLWriter xout(fout);
xout.StartDocument();
@@ -521,26 +536,22 @@ void cmCPackIFWPackage::GeneratePackageFile()
xout.StartElement("Package");
// DisplayName (with translations)
- for (std::map<std::string, std::string>::iterator it =
- this->DisplayName.begin();
- it != this->DisplayName.end(); ++it) {
+ for (auto const& dn : this->DisplayName) {
xout.StartElement("DisplayName");
- if (!it->first.empty()) {
- xout.Attribute("xml:lang", it->first);
+ if (!dn.first.empty()) {
+ xout.Attribute("xml:lang", dn.first);
}
- xout.Content(it->second);
+ xout.Content(dn.second);
xout.EndElement();
}
// Description (with translations)
- for (std::map<std::string, std::string>::iterator it =
- this->Description.begin();
- it != this->Description.end(); ++it) {
+ for (auto const& d : this->Description) {
xout.StartElement("Description");
- if (!it->first.empty()) {
- xout.Attribute("xml:lang", it->first);
+ if (!d.first.empty()) {
+ xout.Attribute("xml:lang", d.first);
}
- xout.Content(it->second);
+ xout.Content(d.second);
xout.EndElement();
}
@@ -568,46 +579,43 @@ void cmCPackIFWPackage::GeneratePackageFile()
// User Interfaces (copy to meta dir)
std::vector<std::string> userInterfaces = UserInterfaces;
- for (size_t i = 0; i < userInterfaces.size(); i++) {
- std::string name = cmSystemTools::GetFilenameName(userInterfaces[i]);
+ for (std::string& userInterface : userInterfaces) {
+ std::string name = cmSystemTools::GetFilenameName(userInterface);
std::string path = this->Directory + "/meta/" + name;
- cmsys::SystemTools::CopyFileIfDifferent(userInterfaces[i], path);
- userInterfaces[i] = name;
+ cmsys::SystemTools::CopyFileIfDifferent(userInterface, path);
+ userInterface = name;
}
if (!userInterfaces.empty()) {
xout.StartElement("UserInterfaces");
- for (size_t i = 0; i < userInterfaces.size(); i++) {
- xout.Element("UserInterface", userInterfaces[i]);
+ for (std::string const& userInterface : userInterfaces) {
+ xout.Element("UserInterface", userInterface);
}
xout.EndElement();
}
// Translations (copy to meta dir)
std::vector<std::string> translations = Translations;
- for (size_t i = 0; i < translations.size(); i++) {
- std::string name = cmSystemTools::GetFilenameName(translations[i]);
+ for (std::string& translation : translations) {
+ std::string name = cmSystemTools::GetFilenameName(translation);
std::string path = this->Directory + "/meta/" + name;
- cmsys::SystemTools::CopyFileIfDifferent(translations[i], path);
- translations[i] = name;
+ cmsys::SystemTools::CopyFileIfDifferent(translation, path);
+ translation = name;
}
if (!translations.empty()) {
xout.StartElement("Translations");
- for (size_t i = 0; i < translations.size(); i++) {
- xout.Element("Translation", translations[i]);
+ for (std::string const& translation : translations) {
+ xout.Element("Translation", translation);
}
xout.EndElement();
}
// Dependencies
std::set<DependenceStruct> compDepSet;
- for (std::set<DependenceStruct*>::iterator ait =
- this->AlienDependencies.begin();
- ait != this->AlienDependencies.end(); ++ait) {
- compDepSet.insert(*(*ait));
+ for (DependenceStruct* ad : this->AlienDependencies) {
+ compDepSet.insert(*ad);
}
- for (std::set<cmCPackIFWPackage*>::iterator it = this->Dependencies.begin();
- it != this->Dependencies.end(); ++it) {
- compDepSet.insert(DependenceStruct((*it)->Name));
+ for (cmCPackIFWPackage* d : this->Dependencies) {
+ compDepSet.insert(DependenceStruct(d->Name));
}
// Write dependencies
if (!compDepSet.empty()) {
@@ -624,10 +632,8 @@ void cmCPackIFWPackage::GeneratePackageFile()
// Automatic dependency on
std::set<DependenceStruct> compAutoDepSet;
- for (std::set<DependenceStruct*>::iterator ait =
- this->AlienAutoDependOn.begin();
- ait != this->AlienAutoDependOn.end(); ++ait) {
- compAutoDepSet.insert(*(*ait));
+ for (DependenceStruct* aad : this->AlienAutoDependOn) {
+ compAutoDepSet.insert(*aad);
}
// Write automatic dependency on
if (!compAutoDepSet.empty()) {
@@ -665,6 +671,19 @@ void cmCPackIFWPackage::GeneratePackageFile()
xout.Element("ForcedInstallation", this->ForcedInstallation);
}
+ // Replaces
+ if (!this->Replaces.empty()) {
+ std::ostringstream replaces;
+ std::vector<std::string>::iterator it = this->Replaces.begin();
+ replaces << *it;
+ ++it;
+ while (it != this->Replaces.end()) {
+ replaces << "," << *it;
+ ++it;
+ }
+ xout.Element("Replaces", replaces.str());
+ }
+
if (!this->RequiresAdminRights.empty()) {
xout.Element("RequiresAdminRights", this->RequiresAdminRights);
}
@@ -685,6 +704,11 @@ void cmCPackIFWPackage::GeneratePackageFile()
xout.Element("SortingPriority", this->SortingPriority);
}
+ // Checkable
+ if (!this->Checkable.empty()) {
+ xout.Element("Checkable", this->Checkable);
+ }
+
xout.EndElement();
xout.EndDocument();
}
diff --git a/Source/CPack/IFW/cmCPackIFWPackage.h b/Source/CPack/IFW/cmCPackIFWPackage.h
index cec59b03c..ae411462a 100644
--- a/Source/CPack/IFW/cmCPackIFWPackage.h
+++ b/Source/CPack/IFW/cmCPackIFWPackage.h
@@ -114,9 +114,15 @@ public:
/// Determines that the package must always be installed
std::string ForcedInstallation;
+ /// List of components to replace
+ std::vector<std::string> Replaces;
+
/// Package needs to be installed with elevated permissions
std::string RequiresAdminRights;
+ /// Set to false if you want to hide the checkbox for an item
+ std::string Checkable;
+
public:
// Internal implementation
diff --git a/Source/CPack/IFW/cmCPackIFWRepository.cxx b/Source/CPack/IFW/cmCPackIFWRepository.cxx
index b115db057..8042167ed 100644
--- a/Source/CPack/IFW/cmCPackIFWRepository.cxx
+++ b/Source/CPack/IFW/cmCPackIFWRepository.cxx
@@ -62,49 +62,49 @@ bool cmCPackIFWRepository::ConfigureFromOptions()
if (const char* url = this->GetOption(prefix + "URL")) {
this->Url = url;
} else {
- this->Url = "";
+ this->Url.clear();
}
// Old url
if (const char* oldUrl = this->GetOption(prefix + "OLD_URL")) {
this->OldUrl = oldUrl;
} else {
- this->OldUrl = "";
+ this->OldUrl.clear();
}
// New url
if (const char* newUrl = this->GetOption(prefix + "NEW_URL")) {
this->NewUrl = newUrl;
} else {
- this->NewUrl = "";
+ this->NewUrl.clear();
}
// Enabled
if (this->IsOn(prefix + "DISABLED")) {
this->Enabled = "0";
} else {
- this->Enabled = "";
+ this->Enabled.clear();
}
// Username
if (const char* username = this->GetOption(prefix + "USERNAME")) {
this->Username = username;
} else {
- this->Username = "";
+ this->Username.clear();
}
// Password
if (const char* password = this->GetOption(prefix + "PASSWORD")) {
this->Password = password;
} else {
- this->Password = "";
+ this->Password.clear();
}
// DisplayName
if (const char* displayName = this->GetOption(prefix + "DISPLAY_NAME")) {
this->DisplayName = displayName;
} else {
- this->DisplayName = "";
+ this->DisplayName.clear();
}
return this->IsValid();
@@ -128,7 +128,7 @@ public:
bool patched;
protected:
- void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** atts) override
{
this->xout.StartElement(name);
this->StartFragment(atts);
@@ -143,7 +143,7 @@ protected:
}
}
- void EndElement(const std::string& name) CM_OVERRIDE
+ void EndElement(const std::string& name) override
{
if (name == "Updates" && !this->patched) {
this->repository->WriteRepositoryUpdates(this->xout);
@@ -159,10 +159,10 @@ protected:
}
}
- void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
+ void CharacterDataHandler(const char* data, int length) override
{
std::string content(data, data + length);
- if (content == "" || content == " " || content == " " ||
+ if (content.empty() || content == " " || content == " " ||
content == "\n") {
return;
}
@@ -183,7 +183,7 @@ bool cmCPackIFWRepository::PatchUpdatesXml()
this->Directory + "/repository/UpdatesPatch.xml";
// Output stream
- cmGeneratedFileStream fout(updatesPatchXml.data());
+ cmGeneratedFileStream fout(updatesPatchXml);
cmXMLWriter xout(fout);
xout.StartDocument();
@@ -200,7 +200,7 @@ bool cmCPackIFWRepository::PatchUpdatesXml()
fout.Close();
- return cmSystemTools::RenameFile(updatesPatchXml.data(), updatesXml.data());
+ return cmSystemTools::RenameFile(updatesPatchXml, updatesXml);
}
void cmCPackIFWRepository::WriteRepositoryConfig(cmXMLWriter& xout)
@@ -279,9 +279,8 @@ void cmCPackIFWRepository::WriteRepositoryUpdates(cmXMLWriter& xout)
{
if (!this->RepositoryUpdate.empty()) {
xout.StartElement("RepositoryUpdate");
- for (RepositoriesVector::iterator rit = this->RepositoryUpdate.begin();
- rit != this->RepositoryUpdate.end(); ++rit) {
- (*rit)->WriteRepositoryUpdate(xout);
+ for (cmCPackIFWRepository* r : this->RepositoryUpdate) {
+ r->WriteRepositoryUpdate(xout);
}
xout.EndElement();
}
diff --git a/Source/CPack/OSXScriptLauncher.cxx b/Source/CPack/OSXScriptLauncher.cxx
index b48bf1214..00d272c83 100644
--- a/Source/CPack/OSXScriptLauncher.cxx
+++ b/Source/CPack/OSXScriptLauncher.cxx
@@ -34,7 +34,7 @@ int main(int argc, char* argv[])
}
fileName = CFSTR("RuntimeScript");
if (!(scriptFileURL =
- CFBundleCopyResourceURL(appBundle, fileName, NULL, NULL))) {
+ CFBundleCopyResourceURL(appBundle, fileName, nullptr, nullptr))) {
DebugError("CFBundleCopyResourceURL failed");
return 1;
}
@@ -46,8 +46,7 @@ int main(int argc, char* argv[])
// 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) {
+ if (!CFURLGetFileSystemRepresentation(scriptFileURL, true, path, PATH_MAX)) {
DebugError("CFURLGetFileSystemRepresentation failed");
return 1;
}
@@ -71,10 +70,10 @@ int main(int argc, char* argv[])
for (cc = 1; cc < argc; ++cc) {
args.push_back(argv[cc]);
}
- args.push_back(0);
+ args.push_back(nullptr);
cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*args.begin());
+ cmsysProcess_SetCommand(cp, args.data());
cmsysProcess_SetWorkingDirectory(cp, scriptDirectory.c_str());
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
cmsysProcess_SetTimeout(cp, 0);
@@ -83,7 +82,7 @@ int main(int argc, char* argv[])
std::vector<char> tempOutput;
char* data;
int length;
- while (cmsysProcess_WaitForData(cp, &data, &length, 0)) {
+ while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
// Translate NULL characters in the output into valid text.
for (int i = 0; i < length; ++i) {
if (data[i] == '\0') {
@@ -93,7 +92,7 @@ int main(int argc, char* argv[])
std::cout.write(data, length);
}
- cmsysProcess_WaitForExit(cp, 0);
+ cmsysProcess_WaitForExit(cp, nullptr);
bool result = true;
if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) {
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
index 274dfd0ce..045d93d87 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx
@@ -22,7 +22,13 @@
#include "cmsys/FStream.hxx"
#include "cmsys/SystemTools.hxx"
-#include <rpc.h> // for GUID generation
+#ifdef _WIN32
+# include <rpc.h> // for GUID generation (windows only)
+#else
+# include <uuid/uuid.h> // for GUID generation (libuuid)
+#endif
+
+#include "cmCMakeToWixPath.h"
cmCPackWIXGenerator::cmCPackWIXGenerator()
: Patch(0)
@@ -49,15 +55,14 @@ bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command)
{
std::string logFileName = this->CPackTopLevel + "/wix.log";
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Running WiX command: " << command
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Running WiX command: " << command << std::endl);
std::string output;
int returnValue = 0;
- bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output,
- &output, &returnValue, 0,
- cmSystemTools::OUTPUT_NONE);
+ bool status = cmSystemTools::RunSingleCommand(
+ command, &output, &output, &returnValue, 0, cmSystemTools::OUTPUT_NONE);
cmsys::ofstream logFile(logFileName.c_str(), std::ios::app);
logFile << command << std::endl;
@@ -65,8 +70,9 @@ bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command)
logFile.close();
if (!status || returnValue) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running WiX candle. "
- "Please check '"
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running WiX candle. "
+ "Please check '"
<< logFileName << "' for errors." << std::endl);
return false;
@@ -89,9 +95,12 @@ bool cmCPackWIXGenerator::RunCandleCommand(std::string const& sourceFile,
command << " -arch " << GetArchitecture();
command << " -out " << QuotePath(objectFile);
- for (extension_set_t::const_iterator i = CandleExtensions.begin();
- i != CandleExtensions.end(); ++i) {
- command << " -ext " << QuotePath(*i);
+ for (std::string const& ext : CandleExtensions) {
+ command << " -ext " << QuotePath(ext);
+ }
+
+ if (sourceFile.rfind(this->CPackTopLevel, 0) != 0) {
+ command << " " << QuotePath("-I" + this->CPackTopLevel);
}
AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command);
@@ -111,11 +120,10 @@ bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles)
std::ostringstream command;
command << QuotePath(executable);
command << " -nologo";
- command << " -out " << QuotePath(packageFileNames.at(0));
+ command << " -out " << QuotePath(CMakeToWixPath(packageFileNames.at(0)));
- for (extension_set_t::const_iterator i = this->LightExtensions.begin();
- i != this->LightExtensions.end(); ++i) {
- command << " -ext " << QuotePath(*i);
+ for (std::string const& ext : this->LightExtensions) {
+ command << " -ext " << QuotePath(ext);
}
const char* const cultures = GetOption("CPACK_WIX_CULTURES");
@@ -133,8 +141,8 @@ bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles)
int cmCPackWIXGenerator::PackageFiles()
{
if (!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Fatal WiX Generator Error"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Fatal WiX Generator Error" << std::endl);
return false;
}
@@ -143,9 +151,9 @@ int cmCPackWIXGenerator::PackageFiles()
bool cmCPackWIXGenerator::InitializeWiXConfiguration()
{
- if (!ReadListFile("CPackWIX.cmake")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while executing CPackWIX.cmake"
- << std::endl);
+ if (!ReadListFile("Internal/CPack/CPackWIX.cmake")) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while executing CPackWIX.cmake" << std::endl);
return false;
}
@@ -162,12 +170,13 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration()
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);
+ 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)) {
@@ -219,8 +228,8 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration()
std::vector<std::string> patchFilePaths;
cmSystemTools::ExpandListArgument(patchFilePath, patchFilePaths);
- for (size_t i = 0; i < patchFilePaths.size(); ++i) {
- if (!this->Patch->LoadFragments(patchFilePaths[i])) {
+ for (std::string const& p : patchFilePaths) {
+ if (!this->Patch->LoadFragments(p)) {
return false;
}
}
@@ -254,9 +263,7 @@ bool cmCPackWIXGenerator::PackageFilesImpl()
std::set<std::string> usedBaseNames;
std::ostringstream objectFiles;
- for (size_t i = 0; i < this->WixSources.size(); ++i) {
- std::string const& sourceFilename = this->WixSources[i];
-
+ for (std::string const& sourceFilename : this->WixSources) {
std::string baseName =
cmSystemTools::GetFilenameWithoutLastExtension(sourceFilename);
@@ -274,11 +281,12 @@ bool cmCPackWIXGenerator::PackageFilesImpl()
std::string objectFilename =
this->CPackTopLevel + "/" + uniqueBaseName + ".wixobj";
- if (!RunCandleCommand(sourceFilename, objectFilename)) {
+ if (!RunCandleCommand(CMakeToWixPath(sourceFilename),
+ CMakeToWixPath(objectFilename))) {
return false;
}
- objectFiles << " " << QuotePath(objectFilename);
+ objectFiles << " " << QuotePath(CMakeToWixPath(objectFilename));
}
AppendUserSuppliedExtraObjects(objectFiles);
@@ -306,8 +314,8 @@ void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream)
cmSystemTools::ExpandListArgument(cpackWixExtraObjects,
expandedExtraObjects);
- for (size_t i = 0; i < expandedExtraObjects.size(); ++i) {
- stream << " " << QuotePath(expandedExtraObjects[i]);
+ for (std::string const& obj : expandedExtraObjects) {
+ stream << " " << QuotePath(obj);
}
}
@@ -324,10 +332,10 @@ void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile()
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");
+ CopyDefinition(includeFile, "CPACK_WIX_LICENSE_RTF", DefinitionType::PATH);
+ CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_ICON", DefinitionType::PATH);
+ CopyDefinition(includeFile, "CPACK_WIX_UI_BANNER", DefinitionType::PATH);
+ CopyDefinition(includeFile, "CPACK_WIX_UI_DIALOG", DefinitionType::PATH);
SetOptionIfNotSet("CPACK_WIX_PROGRAM_MENU_FOLDER",
GetOption("CPACK_PACKAGE_NAME"));
CopyDefinition(includeFile, "CPACK_WIX_PROGRAM_MENU_FOLDER");
@@ -345,9 +353,7 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile()
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];
-
+ for (std::string const& name : options) {
if (name.length() > prefix.length() &&
name.substr(0, prefix.length()) == prefix) {
std::string id = name.substr(prefix.length());
@@ -369,8 +375,9 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile()
includeFile.AddAttribute("Id", "FindInstallLocation");
includeFile.AddAttribute("Root", "HKLM");
includeFile.AddAttribute(
- "Key", "Software\\Microsoft\\Windows\\"
- "CurrentVersion\\Uninstall\\[WIX_UPGRADE_DETECTED]");
+ "Key",
+ "Software\\Microsoft\\Windows\\"
+ "CurrentVersion\\Uninstall\\[WIX_UPGRADE_DETECTED]");
includeFile.AddAttribute("Name", "InstallLocation");
includeFile.AddAttribute("Type", "raw");
includeFile.EndElement("RegistrySearch");
@@ -396,11 +403,16 @@ void cmCPackWIXGenerator::CreateWiXProductFragmentIncludeFile()
}
void cmCPackWIXGenerator::CopyDefinition(cmWIXSourceWriter& source,
- std::string const& name)
+ std::string const& name,
+ DefinitionType type)
{
const char* value = GetOption(name.c_str());
if (value) {
- AddDefinition(source, name, value);
+ if (type == DefinitionType::PATH) {
+ AddDefinition(source, name, CMakeToWixPath(value));
+ } else {
+ AddDefinition(source, name, value);
+ }
}
}
@@ -503,16 +515,14 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
globalShortcuts.AddShortcutTypes(emittedShortcutTypes);
} else {
- for (std::map<std::string, cmCPackComponent>::const_iterator i =
- this->Components.begin();
- i != this->Components.end(); ++i) {
- cmCPackComponent const& component = i->second;
+ for (auto const& i : this->Components) {
+ cmCPackComponent const& component = i.second;
std::string componentPath = toplevel;
componentPath += "/";
componentPath += component.Name;
- std::string componentFeatureId = "CM_C_" + component.Name;
+ std::string const componentFeatureId = "CM_C_" + component.Name;
cmWIXShortcuts featureShortcuts;
AddComponentsToFeature(componentPath, componentFeatureId,
@@ -608,9 +618,10 @@ bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate()
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);
+ if (!ConfigureFile(wixTemplate, mainSourceFilePath)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed creating '" << mainSourceFilePath
+ << "'' from template." << std::endl);
return false;
}
@@ -623,19 +634,15 @@ bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate()
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;
+ for (auto const& i : ComponentGroups) {
+ cmCPackComponentGroup const& group = i.second;
if (group.ParentGroup == 0) {
featureDefinitions.EmitFeatureForComponentGroup(group, *this->Patch);
}
}
- for (std::map<std::string, cmCPackComponent>::const_iterator i =
- this->Components.begin();
- i != this->Components.end(); ++i) {
- cmCPackComponent const& component = i->second;
+ for (auto const& i : this->Components) {
+ cmCPackComponent const& component = i.second;
if (!component.Group) {
featureDefinitions.EmitFeatureForComponent(component, *this->Patch);
@@ -957,8 +964,8 @@ bool cmCPackWIXGenerator::RequireOption(std::string const& name,
return true;
} else {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Required variable "
- << name << " not set" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Required variable " << name << " not set" << std::endl);
return false;
}
@@ -978,6 +985,7 @@ std::string cmCPackWIXGenerator::GetArchitecture() const
std::string cmCPackWIXGenerator::GenerateGUID()
{
+#ifdef _WIN32
UUID guid;
UuidCreate(&guid);
@@ -987,6 +995,14 @@ std::string cmCPackWIXGenerator::GenerateGUID()
std::string result =
cmsys::Encoding::ToNarrow(reinterpret_cast<wchar_t*>(tmp));
RpcStringFreeW(&tmp);
+#else
+ uuid_t guid;
+ char guid_ch[37] = { 0 };
+
+ uuid_generate(guid);
+ uuid_unparse(guid, guid_ch);
+ std::string result = guid_ch;
+#endif
return cmSystemTools::UpperCase(result);
}
@@ -1135,9 +1151,8 @@ void cmCPackWIXGenerator::AddCustomFlags(std::string const& variableName,
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);
+ for (std::string const& i : list) {
+ stream << " " << QuotePath(i);
}
}
diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.h b/Source/CPack/WiX/cmCPackWIXGenerator.h
index b2633a7f9..f8c76449b 100644
--- a/Source/CPack/WiX/cmCPackWIXGenerator.h
+++ b/Source/CPack/WiX/cmCPackWIXGenerator.h
@@ -28,26 +28,32 @@ public:
~cmCPackWIXGenerator();
protected:
- virtual int InitializeInternal();
+ int InitializeInternal() override;
- virtual int PackageFiles();
+ int PackageFiles() override;
- virtual const char* GetOutputExtension() { return ".msi"; }
+ const char* GetOutputExtension() override { return ".msi"; }
- virtual enum CPackSetDestdirSupport SupportsSetDestdir() const
+ enum CPackSetDestdirSupport SupportsSetDestdir() const override
{
return SETDESTDIR_UNSUPPORTED;
}
- virtual bool SupportsAbsoluteDestination() const { return false; }
+ bool SupportsAbsoluteDestination() const override { return false; }
- virtual bool SupportsComponentInstallation() const { return true; }
+ bool SupportsComponentInstallation() const override { 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::set<std::string> extension_set_t;
+ enum class DefinitionType
+ {
+ STRING,
+ PATH
+ };
+
bool InitializeWiXConfiguration();
bool PackageFilesImpl();
@@ -58,7 +64,8 @@ private:
void CreateWiXProductFragmentIncludeFile();
- void CopyDefinition(cmWIXSourceWriter& source, std::string const& name);
+ void CopyDefinition(cmWIXSourceWriter& source, std::string const& name,
+ DefinitionType type = DefinitionType::STRING);
void AddDefinition(cmWIXSourceWriter& source, std::string const& name,
std::string const& value);
diff --git a/Source/CPack/WiX/cmWIXAccessControlList.cxx b/Source/CPack/WiX/cmWIXAccessControlList.cxx
index 744a93298..563de02ae 100644
--- a/Source/CPack/WiX/cmWIXAccessControlList.cxx
+++ b/Source/CPack/WiX/cmWIXAccessControlList.cxx
@@ -20,8 +20,8 @@ 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]);
+ for (std::string const& entry : entries) {
+ this->CreatePermissionElement(entry);
}
return true;
@@ -56,9 +56,9 @@ void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry)
if (!domain.empty()) {
this->SourceWriter.AddAttribute("Domain", domain);
}
- for (size_t i = 0; i < permissions.size(); ++i) {
+ for (std::string const& permission : permissions) {
this->EmitBooleanAttribute(entry,
- cmSystemTools::TrimWhitespace(permissions[i]));
+ cmSystemTools::TrimWhitespace(permission));
}
this->SourceWriter.EndElement("Permission");
}
@@ -66,8 +66,9 @@ void cmWIXAccessControlList::CreatePermissionElement(std::string const& entry)
void cmWIXAccessControlList::ReportError(std::string const& entry,
std::string const& message)
{
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed processing ACL entry '"
- << entry << "': " << message << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed processing ACL entry '" << entry << "': " << message
+ << std::endl);
}
bool cmWIXAccessControlList::IsBooleanAttribute(std::string const& name)
diff --git a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
index 0be43776e..a7a064881 100644
--- a/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFeaturesSourceWriter.cxx
@@ -46,16 +46,12 @@ void cmWIXFeaturesSourceWriter::EmitFeatureForComponentGroup(
patch.ApplyFragment("CM_G_" + group.Name, *this);
- for (std::vector<cmCPackComponentGroup*>::const_iterator i =
- group.Subgroups.begin();
- i != group.Subgroups.end(); ++i) {
- EmitFeatureForComponentGroup(**i, patch);
+ for (cmCPackComponentGroup* subgroup : group.Subgroups) {
+ EmitFeatureForComponentGroup(*subgroup, patch);
}
- for (std::vector<cmCPackComponent*>::const_iterator i =
- group.Components.begin();
- i != group.Components.end(); ++i) {
- EmitFeatureForComponent(**i, patch);
+ for (cmCPackComponent* component : group.Components) {
+ EmitFeatureForComponent(*component, patch);
}
EndElement("Feature");
diff --git a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
index b4cd1a3d6..dd3caf9d3 100644
--- a/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx
@@ -11,6 +11,8 @@
#include "cm_sys_stat.h"
+#include "cmCMakeToWixPath.h"
+
cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger,
std::string const& filename,
GuidType componentGuidType)
@@ -139,7 +141,7 @@ std::string cmWIXFilesSourceWriter::EmitComponentFile(
patch.ApplyFragment(componentId, *this);
BeginElement("File");
AddAttribute("Id", fileId);
- AddAttribute("Source", filePath);
+ AddAttribute("Source", CMakeToWixPath(filePath));
AddAttribute("KeyPath", "yes");
mode_t fileMode = 0;
diff --git a/Source/CPack/WiX/cmWIXPatch.cxx b/Source/CPack/WiX/cmWIXPatch.cxx
index 287a644bb..ca232f94b 100644
--- a/Source/CPack/WiX/cmWIXPatch.cxx
+++ b/Source/CPack/WiX/cmWIXPatch.cxx
@@ -13,8 +13,9 @@ bool cmWIXPatch::LoadFragments(std::string const& patchFilePath)
{
cmWIXPatchParser parser(Fragments, Logger);
if (!parser.ParseFile(patchFilePath.c_str())) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Failed parsing XML patch file: '"
- << patchFilePath << "'" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed parsing XML patch file: '" << patchFilePath << "'"
+ << std::endl);
return false;
}
@@ -29,10 +30,8 @@ void cmWIXPatch::ApplyFragment(std::string const& id,
return;
const cmWIXPatchElement& fragment = i->second;
- for (cmWIXPatchElement::attributes_t::const_iterator attr_i =
- fragment.attributes.begin();
- attr_i != fragment.attributes.end(); ++attr_i) {
- writer.AddAttribute(attr_i->first, attr_i->second);
+ for (auto const& attr : fragment.attributes) {
+ writer.AddAttribute(attr.first, attr.second);
}
this->ApplyElementChildren(fragment, writer);
@@ -42,11 +41,7 @@ void cmWIXPatch::ApplyFragment(std::string const& id,
void cmWIXPatch::ApplyElementChildren(const cmWIXPatchElement& element,
cmWIXSourceWriter& writer)
{
- for (cmWIXPatchElement::child_list_t::const_iterator j =
- element.children.begin();
- j != element.children.end(); ++j) {
- cmWIXPatchNode* node = *j;
-
+ for (cmWIXPatchNode* node : element.children) {
switch (node->type()) {
case cmWIXPatchNode::ELEMENT:
ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer);
@@ -63,10 +58,8 @@ void cmWIXPatch::ApplyElement(const cmWIXPatchElement& element,
{
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 (auto const& attr : element.attributes) {
+ writer.AddAttribute(attr.first, attr.second);
}
this->ApplyElementChildren(element, writer);
@@ -77,14 +70,13 @@ void cmWIXPatch::ApplyElement(const cmWIXPatchElement& element,
bool cmWIXPatch::CheckForUnappliedFragments()
{
std::string fragmentList;
- for (cmWIXPatchParser::fragment_map_t::const_iterator i = Fragments.begin();
- i != Fragments.end(); ++i) {
+ for (auto const& fragment : Fragments) {
if (!fragmentList.empty()) {
fragmentList += ", ";
}
fragmentList += "'";
- fragmentList += i->first;
+ fragmentList += fragment.first;
fragmentList += "'";
}
diff --git a/Source/CPack/WiX/cmWIXPatchParser.cxx b/Source/CPack/WiX/cmWIXPatchParser.cxx
index 0dcc74ae0..c6ca9441a 100644
--- a/Source/CPack/WiX/cmWIXPatchParser.cxx
+++ b/Source/CPack/WiX/cmWIXPatchParser.cxx
@@ -22,8 +22,8 @@ cmWIXPatchNode::~cmWIXPatchNode()
cmWIXPatchElement::~cmWIXPatchElement()
{
- for (child_list_t::iterator i = children.begin(); i != children.end(); ++i) {
- delete *i;
+ for (cmWIXPatchNode* child : children) {
+ delete child;
}
}
@@ -72,7 +72,7 @@ void cmWIXPatchParser::StartElement(const std::string& name, const char** atts)
void cmWIXPatchParser::StartFragment(const char** attributes)
{
- cmWIXPatchElement* new_element = CM_NULLPTR;
+ cmWIXPatchElement* new_element = nullptr;
/* find the id of for fragment */
for (size_t i = 0; attributes[i]; i += 2) {
const std::string key = attributes[i];
@@ -90,7 +90,7 @@ void cmWIXPatchParser::StartFragment(const char** attributes)
}
}
- /* add any additional attributes for the fragement */
+ /* add any additional attributes for the fragment */
if (!new_element) {
ReportValidationError("No 'Id' specified for 'CPackWixFragment' element");
} else {
diff --git a/Source/CPack/WiX/cmWIXRichTextFormatWriter.h b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h
index 30df87814..21be8ee66 100644
--- a/Source/CPack/WiX/cmWIXRichTextFormatWriter.h
+++ b/Source/CPack/WiX/cmWIXRichTextFormatWriter.h
@@ -3,7 +3,7 @@
#ifndef cmWIXRichTextFormatWriter_h
#define cmWIXRichTextFormatWriter_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmsys/FStream.hxx"
#include <string>
diff --git a/Source/CPack/WiX/cmWIXShortcut.cxx b/Source/CPack/WiX/cmWIXShortcut.cxx
index e5dea94c4..cd1988a1c 100644
--- a/Source/CPack/WiX/cmWIXShortcut.cxx
+++ b/Source/CPack/WiX/cmWIXShortcut.cxx
@@ -47,10 +47,9 @@ bool cmWIXShortcuts::EmitShortcuts(
return false;
}
- for (shortcut_id_map_t::const_iterator j = id_map.begin(); j != id_map.end();
- ++j) {
- std::string const& id = j->first;
- shortcut_list_t const& shortcutList = j->second;
+ for (auto const& j : id_map) {
+ std::string const& id = j.first;
+ shortcut_list_t const& shortcutList = j.second;
for (size_t shortcutListIndex = 0; shortcutListIndex < shortcutList.size();
++shortcutListIndex) {
@@ -68,9 +67,8 @@ bool cmWIXShortcuts::EmitShortcuts(
void cmWIXShortcuts::AddShortcutTypes(std::set<Type>& types)
{
- for (shortcut_type_map_t::const_iterator i = this->Shortcuts.begin();
- i != this->Shortcuts.end(); ++i) {
- types.insert(i->first);
+ for (auto const& shortcut : this->Shortcuts) {
+ types.insert(shortcut.first);
}
}
@@ -96,9 +94,9 @@ void cmWIXShortcuts::CreateFromProperty(std::string const& propertyName,
std::vector<std::string> list;
installedFile.GetPropertyAsList(propertyName, list);
- for (size_t i = 0; i < list.size(); ++i) {
+ for (std::string const& label : list) {
cmWIXShortcut shortcut;
- shortcut.label = list[i];
+ shortcut.label = label;
shortcut.workingDirectoryId = directoryId;
insert(type, id, shortcut);
}
diff --git a/Source/CPack/WiX/cmWIXSourceWriter.cxx b/Source/CPack/WiX/cmWIXSourceWriter.cxx
index a86e28d1c..6adf80bac 100644
--- a/Source/CPack/WiX/cmWIXSourceWriter.cxx
+++ b/Source/CPack/WiX/cmWIXSourceWriter.cxx
@@ -32,7 +32,8 @@ cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger,
cmWIXSourceWriter::~cmWIXSourceWriter()
{
if (Elements.size() > 1) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, Elements.size() - 1
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ Elements.size() - 1
<< " WiX elements were still open when closing '"
<< SourceFilename << "'" << std::endl);
return;
@@ -65,7 +66,8 @@ void cmWIXSourceWriter::EndElement(std::string const& name)
}
if (Elements.back() != name) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "WiX element <"
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "WiX element <"
<< Elements.back() << "> can not be closed by </" << name
<< "> in '" << SourceFilename << "'" << std::endl);
return;
@@ -158,9 +160,7 @@ 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];
+ for (char c : value) {
switch (c) {
case '<':
result += "&lt;";
diff --git a/Source/CPack/cmCPack7zGenerator.cxx b/Source/CPack/cmCPack7zGenerator.cxx
index f0c41a2a1..741377012 100644
--- a/Source/CPack/cmCPack7zGenerator.cxx
+++ b/Source/CPack/cmCPack7zGenerator.cxx
@@ -10,6 +10,4 @@ cmCPack7zGenerator::cmCPack7zGenerator()
{
}
-cmCPack7zGenerator::~cmCPack7zGenerator()
-{
-}
+cmCPack7zGenerator::~cmCPack7zGenerator() = default;
diff --git a/Source/CPack/cmCPack7zGenerator.h b/Source/CPack/cmCPack7zGenerator.h
index 42a47810c..8af4c4a4d 100644
--- a/Source/CPack/cmCPack7zGenerator.h
+++ b/Source/CPack/cmCPack7zGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPack7zGenerator_h
#define cmCPack7zGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackArchiveGenerator.h"
#include "cmCPackGenerator.h"
@@ -20,10 +20,10 @@ public:
* Construct generator
*/
cmCPack7zGenerator();
- ~cmCPack7zGenerator() CM_OVERRIDE;
+ ~cmCPack7zGenerator() override;
protected:
- const char* GetOutputExtension() CM_OVERRIDE { return ".7z"; }
+ const char* GetOutputExtension() override { return ".7z"; }
};
#endif
diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx
index 575c94924..98fb29d14 100644
--- a/Source/CPack/cmCPackArchiveGenerator.cxx
+++ b/Source/CPack/cmCPackArchiveGenerator.cxx
@@ -9,6 +9,7 @@
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
+#include <cstring>
#include <map>
#include <ostream>
#include <utility>
@@ -21,9 +22,7 @@ cmCPackArchiveGenerator::cmCPackArchiveGenerator(cmArchiveWrite::Compress t,
this->ArchiveFormat = format;
}
-cmCPackArchiveGenerator::~cmCPackArchiveGenerator()
-{
-}
+cmCPackArchiveGenerator::~cmCPackArchiveGenerator() = default;
std::string cmCPackArchiveGenerator::GetArchiveComponentFileName(
const std::string& component, bool isGroupName)
@@ -52,6 +51,7 @@ int cmCPackArchiveGenerator::InitializeInternal()
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
return this->Superclass::InitializeInternal();
}
+
int cmCPackArchiveGenerator::addOneComponentToArchive(
cmArchiveWrite& archive, cmCPackComponent* component)
{
@@ -62,6 +62,13 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(
localToplevel += "/" + component->Name;
// Change to local toplevel
cmWorkingDirectory workdir(localToplevel);
+ if (workdir.Failed()) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed to change working directory to "
+ << localToplevel << " : "
+ << std::strerror(workdir.GetLastResult()) << std::endl);
+ return 0;
+ }
std::string filePrefix;
if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) {
filePrefix = this->GetOption("CPACK_PACKAGE_FILE_NAME");
@@ -74,15 +81,14 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(
filePrefix += installPrefix + 1;
filePrefix += "/";
}
- std::vector<std::string>::const_iterator fileIt;
- for (fileIt = component->Files.begin(); fileIt != component->Files.end();
- ++fileIt) {
- std::string rp = filePrefix + *fileIt;
+ for (std::string const& file : component->Files) {
+ std::string rp = filePrefix + file;
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file: " << rp << std::endl);
- archive.Add(rp, 0, CM_NULLPTR, false);
+ archive.Add(rp, 0, nullptr, false);
if (!archive) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: "
- << archive.GetError() << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "ERROR while packaging files: " << archive.GetError()
+ << std::endl);
return 0;
}
}
@@ -96,20 +102,23 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(
*/
#define DECLARE_AND_OPEN_ARCHIVE(filename, archive) \
cmGeneratedFileStream gf; \
- gf.Open((filename).c_str(), false, true); \
+ gf.Open((filename), false, true); \
if (!GenerateHeader(&gf)) { \
cmCPackLogger(cmCPackLog::LOG_ERROR, \
- "Problem to generate Header for archive < " \
+ "Problem to generate Header for archive <" \
<< (filename) << ">." << std::endl); \
return 0; \
} \
cmArchiveWrite archive(gf, this->Compress, this->ArchiveFormat); \
- if (!(archive)) { \
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem to create archive < " \
- << (filename) << ">. ERROR =" << (archive).GetError() \
- << std::endl); \
- return 0; \
- }
+ do { \
+ if (!(archive)) { \
+ cmCPackLogger(cmCPackLog::LOG_ERROR, \
+ "Problem to create archive <" \
+ << (filename) << ">, ERROR = " << (archive).GetError() \
+ << std::endl); \
+ return 0; \
+ } \
+ } while (false)
int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
{
@@ -117,79 +126,72 @@ int cmCPackArchiveGenerator::PackageComponents(bool ignoreGroup)
// 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);
+ for (auto const& compG : this->ComponentGroups) {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Packaging component group: " << compG.first << std::endl);
// Begin the archive for this group
std::string packageFileName = std::string(toplevel) + "/" +
- this->GetArchiveComponentFileName(compGIt->first, true);
+ this->GetArchiveComponentFileName(compG.first, true);
// 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) {
+ for (cmCPackComponent* comp : (compG.second).Components) {
// Add the files of this component to the archive
- addOneComponentToArchive(archive, *compIt);
+ addOneComponentToArchive(archive, comp);
}
}
// add the generated package to package file names list
- packageFileNames.push_back(packageFileName);
+ packageFileNames.push_back(std::move(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) {
+ for (auto& comp : this->Components) {
// Does the component belong to a group?
- if (compIt->second.Group == CM_NULLPTR) {
+ if (comp.second.Group == nullptr) {
cmCPackLogger(
- cmCPackLog::LOG_VERBOSE, "Component <"
- << compIt->second.Name
+ cmCPackLog::LOG_VERBOSE,
+ "Component <"
+ << comp.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;
+ localToplevel += "/" + comp.first;
packageFileName +=
- "/" + this->GetArchiveComponentFileName(compIt->first, false);
+ "/" + this->GetArchiveComponentFileName(comp.first, false);
{
DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive);
// Add the files of this component to the archive
- addOneComponentToArchive(archive, &(compIt->second));
+ addOneComponentToArchive(archive, &(comp.second));
}
// add the generated package to package file names list
- packageFileNames.push_back(packageFileName);
+ packageFileNames.push_back(std::move(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) {
+ for (auto& comp : this->Components) {
std::string localToplevel(this->GetOption("CPACK_TEMPORARY_DIRECTORY"));
std::string packageFileName = std::string(toplevel);
- localToplevel += "/" + compIt->first;
+ localToplevel += "/" + comp.first;
packageFileName +=
- "/" + this->GetArchiveComponentFileName(compIt->first, false);
+ "/" + this->GetArchiveComponentFileName(comp.first, false);
{
DECLARE_AND_OPEN_ARCHIVE(packageFileName, archive);
// Add the files of this component to the archive
- addOneComponentToArchive(archive, &(compIt->second));
+ addOneComponentToArchive(archive, &(comp.second));
}
// add the generated package to package file names list
- packageFileNames.push_back(packageFileName);
+ packageFileNames.push_back(std::move(packageFileName));
}
}
return 1;
@@ -199,7 +201,7 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne()
{
// reset the package file names
packageFileNames.clear();
- packageFileNames.push_back(std::string(toplevel));
+ packageFileNames.emplace_back(toplevel);
packageFileNames[0] += "/";
if (this->IsSet("CPACK_ARCHIVE_FILE_NAME")) {
@@ -217,11 +219,9 @@ int cmCPackArchiveGenerator::PackageComponentsAllInOne()
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) {
+ for (auto& comp : this->Components) {
// Add the files of this component to the archive
- addOneComponentToArchive(archive, &(compIt->second));
+ addOneComponentToArchive(archive, &(comp.second));
}
// archive goes out of scope so it will finalized and closed.
@@ -249,17 +249,23 @@ int cmCPackArchiveGenerator::PackageFiles()
// CASE 3 : NON COMPONENT package.
DECLARE_AND_OPEN_ARCHIVE(packageFileNames[0], archive);
- std::vector<std::string>::const_iterator fileIt;
cmWorkingDirectory workdir(toplevel);
- for (fileIt = files.begin(); fileIt != files.end(); ++fileIt) {
+ if (workdir.Failed()) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed to change working directory to "
+ << toplevel << " : "
+ << std::strerror(workdir.GetLastResult()) << std::endl);
+ return 0;
+ }
+ for (std::string const& file : files) {
// Get the relative path to the file
- std::string rp =
- cmSystemTools::RelativePath(toplevel.c_str(), fileIt->c_str());
- archive.Add(rp, 0, CM_NULLPTR, false);
+ std::string rp = cmSystemTools::RelativePath(toplevel, file);
+ archive.Add(rp, 0, nullptr, false);
if (!archive) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem while adding file< "
- << *fileIt << "> to archive <" << packageFileNames[0]
- << "> .ERROR =" << archive.GetError() << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem while adding file <"
+ << file << "> to archive <" << packageFileNames[0]
+ << ">, ERROR = " << archive.GetError() << std::endl);
return 0;
}
}
diff --git a/Source/CPack/cmCPackArchiveGenerator.h b/Source/CPack/cmCPackArchiveGenerator.h
index e7116c466..998385432 100644
--- a/Source/CPack/cmCPackArchiveGenerator.h
+++ b/Source/CPack/cmCPackArchiveGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackArchiveGenerator_h
#define cmCPackArchiveGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmArchiveWrite.h"
#include "cmCPackGenerator.h"
@@ -28,11 +28,11 @@ public:
* Construct generator
*/
cmCPackArchiveGenerator(cmArchiveWrite::Compress, std::string const& format);
- ~cmCPackArchiveGenerator() CM_OVERRIDE;
+ ~cmCPackArchiveGenerator() override;
// Used to add a header to the archive
virtual int GenerateHeader(std::ostream* os);
// component support
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ bool SupportsComponentInstallation() const override;
private:
// get archive component filename
@@ -40,7 +40,7 @@ private:
bool isGroupName);
protected:
- int InitializeInternal() CM_OVERRIDE;
+ int InitializeInternal() override;
/**
* Add the files belonging to the specified component
* to the provided (already opened) archive.
@@ -56,7 +56,7 @@ protected:
* method will call either PackageComponents or
* PackageComponentsAllInOne.
*/
- int PackageFiles() CM_OVERRIDE;
+ int PackageFiles() override;
/**
* The method used to package files when component
* install is used. This will create one
@@ -68,7 +68,7 @@ protected:
* components will be put in a single installer.
*/
int PackageComponentsAllInOne();
- const char* GetOutputExtension() CM_OVERRIDE = 0;
+ const char* GetOutputExtension() override = 0;
cmArchiveWrite::Compress Compress;
std::string ArchiveFormat;
};
diff --git a/Source/CPack/cmCPackBundleGenerator.cxx b/Source/CPack/cmCPackBundleGenerator.cxx
index d5389014a..3a476f44b 100644
--- a/Source/CPack/cmCPackBundleGenerator.cxx
+++ b/Source/CPack/cmCPackBundleGenerator.cxx
@@ -8,18 +8,14 @@
#include "cmCPackLog.h"
#include "cmSystemTools.h"
-cmCPackBundleGenerator::cmCPackBundleGenerator()
-{
-}
+cmCPackBundleGenerator::cmCPackBundleGenerator() = default;
-cmCPackBundleGenerator::~cmCPackBundleGenerator()
-{
-}
+cmCPackBundleGenerator::~cmCPackBundleGenerator() = default;
int cmCPackBundleGenerator::InitializeInternal()
{
const char* name = this->GetOption("CPACK_BUNDLE_NAME");
- if (0 == name) {
+ if (nullptr == name) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPACK_BUNDLE_NAME must be set to use the Bundle generator."
<< std::endl);
@@ -32,8 +28,8 @@ int cmCPackBundleGenerator::InitializeInternal()
"codesign", std::vector<std::string>(), false);
if (codesign_path.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate codesign command"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot locate codesign command" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_COMMAND_CODESIGN", codesign_path.c_str());
@@ -59,8 +55,8 @@ int cmCPackBundleGenerator::ConstructBundle()
? this->GetOption("CPACK_BUNDLE_NAME")
: "";
if (cpack_bundle_name.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_BUNDLE_NAME must be set."
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_BUNDLE_NAME must be set." << std::endl);
return 0;
}
@@ -69,8 +65,8 @@ int cmCPackBundleGenerator::ConstructBundle()
? this->GetOption("CPACK_BUNDLE_PLIST")
: "";
if (cpack_bundle_plist.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_BUNDLE_PLIST must be set."
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_BUNDLE_PLIST must be set." << std::endl);
return 0;
}
@@ -79,8 +75,8 @@ int cmCPackBundleGenerator::ConstructBundle()
? this->GetOption("CPACK_BUNDLE_ICON")
: "";
if (cpack_bundle_icon.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_BUNDLE_ICON must be set."
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_BUNDLE_ICON must be set." << std::endl);
return 0;
}
@@ -213,8 +209,7 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
cmSystemTools::ExpandListArgument(sign_files, relFiles);
// sign the files supplied by the user, ie. frameworks.
- for (std::vector<std::string>::iterator it = relFiles.begin();
- it != relFiles.end(); ++it) {
+ for (auto const& file : relFiles) {
std::ostringstream temp_sign_file_cmd;
temp_sign_file_cmd << this->GetOption("CPACK_COMMAND_CODESIGN");
temp_sign_file_cmd << " " << sign_parameter << " -s \""
@@ -223,11 +218,11 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
temp_sign_file_cmd << this->GetOption("CPACK_APPLE_BUNDLE_ID");
temp_sign_file_cmd << " \"";
temp_sign_file_cmd << bundle_path;
- temp_sign_file_cmd << *it << "\"";
+ temp_sign_file_cmd << file << "\"";
if (!this->RunCommand(temp_sign_file_cmd, &output)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
- "Error signing file:" << bundle_path << *it << std::endl
+ "Error signing file:" << bundle_path << file << std::endl
<< output << std::endl);
return 0;
@@ -270,8 +265,8 @@ int cmCPackBundleGenerator::SignBundle(const std::string& src_dir)
return 0;
}
- cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Application has been codesigned"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Application has been codesigned" << std::endl);
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
(this->GetOption("CPACK_BUNDLE_APPLE_ENTITLEMENTS")
? "with entitlement sandboxing"
diff --git a/Source/CPack/cmCPackBundleGenerator.h b/Source/CPack/cmCPackBundleGenerator.h
index 861fe4b09..27bac3a5a 100644
--- a/Source/CPack/cmCPackBundleGenerator.h
+++ b/Source/CPack/cmCPackBundleGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackBundleGenerator_h
#define cmCPackBundleGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -21,15 +21,15 @@ public:
cmCPackTypeMacro(cmCPackBundleGenerator, cmCPackDragNDropGenerator);
cmCPackBundleGenerator();
- virtual ~cmCPackBundleGenerator();
+ ~cmCPackBundleGenerator() override;
protected:
- int InitializeInternal() CM_OVERRIDE;
- const char* GetPackagingInstallPrefix() CM_OVERRIDE;
+ int InitializeInternal() override;
+ const char* GetPackagingInstallPrefix() override;
int ConstructBundle();
int SignBundle(const std::string& src_dir);
- int PackageFiles() CM_OVERRIDE;
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ int PackageFiles() override;
+ bool SupportsComponentInstallation() const override;
std::string InstallPrefix;
};
diff --git a/Source/CPack/cmCPackComponentGroup.cxx b/Source/CPack/cmCPackComponentGroup.cxx
index e39398ad5..f888a5f5d 100644
--- a/Source/CPack/cmCPackComponentGroup.cxx
+++ b/Source/CPack/cmCPackComponentGroup.cxx
@@ -5,7 +5,6 @@
#include "cmSystemTools.h"
#include <string>
-#include <vector>
unsigned long cmCPackComponent::GetInstalledSize(
const std::string& installDir) const
@@ -14,11 +13,10 @@ unsigned long cmCPackComponent::GetInstalledSize(
return this->TotalSize;
}
- std::vector<std::string>::const_iterator fileIt;
- for (fileIt = this->Files.begin(); fileIt != this->Files.end(); ++fileIt) {
+ for (std::string const& file : this->Files) {
std::string path = installDir;
path += '/';
- path += *fileIt;
+ path += file;
this->TotalSize += cmSystemTools::FileLength(path);
}
diff --git a/Source/CPack/cmCPackComponentGroup.h b/Source/CPack/cmCPackComponentGroup.h
index 26d69ba68..bb980d77f 100644
--- a/Source/CPack/cmCPackComponentGroup.h
+++ b/Source/CPack/cmCPackComponentGroup.h
@@ -3,7 +3,7 @@
#ifndef cmCPackComponentGroup_h
#define cmCPackComponentGroup_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -36,7 +36,7 @@ class cmCPackComponent
{
public:
cmCPackComponent()
- : Group(CM_NULLPTR)
+ : Group(nullptr)
, IsRequired(true)
, IsHidden(false)
, IsDisabledByDefault(false)
@@ -114,7 +114,7 @@ class cmCPackComponentGroup
{
public:
cmCPackComponentGroup()
- : ParentGroup(CM_NULLPTR)
+ : ParentGroup(nullptr)
{
}
@@ -143,4 +143,29 @@ public:
std::vector<cmCPackComponentGroup*> Subgroups;
};
+/** \class cmCPackInstallCMakeProject
+ * \brief A single quadruplet from the CPACK_INSTALL_CMAKE_PROJECTS variable.
+ */
+class cmCPackInstallCMakeProject
+{
+public:
+ /// The directory of the CMake project.
+ std::string Directory;
+
+ /// The name of the CMake project.
+ std::string ProjectName;
+
+ /// The name of the component (or component set) to install.
+ std::string Component;
+
+ /// The subdirectory to install into.
+ std::string SubDirectory;
+
+ /// The list of installation types.
+ std::vector<cmCPackInstallationType*> InstallationTypes;
+
+ /// The list of components.
+ std::vector<cmCPackComponent*> Components;
+};
+
#endif
diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
index 2119f782b..49a9f15c3 100644
--- a/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
+++ b/Source/CPack/cmCPackCygwinBinaryGenerator.cxx
@@ -44,10 +44,9 @@ int cmCPackCygwinBinaryGenerator::PackageFiles()
// 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) {
+ for (std::string const& file : files) {
// remove the temp dir and replace with /usr
- ofs << (*i).substr(tempdir.size()) << "\n";
+ ofs << file.substr(tempdir.size()) << "\n";
}
ofs << manifest << "\n";
}
diff --git a/Source/CPack/cmCPackCygwinBinaryGenerator.h b/Source/CPack/cmCPackCygwinBinaryGenerator.h
index 58e80bda7..f87a1343b 100644
--- a/Source/CPack/cmCPackCygwinBinaryGenerator.h
+++ b/Source/CPack/cmCPackCygwinBinaryGenerator.h
@@ -17,7 +17,7 @@ public:
* Construct generator
*/
cmCPackCygwinBinaryGenerator();
- virtual ~cmCPackCygwinBinaryGenerator();
+ ~cmCPackCygwinBinaryGenerator() override;
protected:
virtual int InitializeInternal();
diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.cxx b/Source/CPack/cmCPackCygwinSourceGenerator.cxx
index 2c289f668..889f29a59 100644
--- a/Source/CPack/cmCPackCygwinSourceGenerator.cxx
+++ b/Source/CPack/cmCPackCygwinSourceGenerator.cxx
@@ -15,8 +15,8 @@
// system tools because it is not implemented robustly enough to move
// files across directories.
#ifdef _WIN32
-#include "cm_sys_stat.h"
-#include <windows.h>
+# include "cm_sys_stat.h"
+# include <windows.h>
#endif
cmCPackCygwinSourceGenerator::cmCPackCygwinSourceGenerator()
@@ -73,7 +73,8 @@ int cmCPackCygwinSourceGenerator::PackageFiles()
if (!cmSystemTools::CopyFileAlways(
this->GetOption("CPACK_CYGWIN_PATCH_FILE"),
this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: ["
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "problem copying: ["
<< this->GetOption("CPACK_CYGWIN_PATCH_FILE") << "]\nto\n["
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
return 0;
@@ -87,7 +88,8 @@ int cmCPackCygwinSourceGenerator::PackageFiles()
if (!cmSystemTools::CopyFileAlways(
this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT"),
this->GetOption("CPACK_TOPLEVEL_DIRECTORY"))) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "problem copying: "
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "problem copying: "
<< this->GetOption("CPACK_CYGWIN_BUILD_SCRIPT") << "\nto\n"
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "]\n");
return 0;
@@ -96,7 +98,8 @@ int cmCPackCygwinSourceGenerator::PackageFiles()
outerTarFile += "-";
const char* patch = this->GetOption("CPACK_CYGWIN_PATCH_NUMBER");
if (!patch) {
- cmCPackLogger(cmCPackLog::LOG_WARNING, "CPACK_CYGWIN_PATCH_NUMBER"
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "CPACK_CYGWIN_PATCH_NUMBER"
<< " not specified, defaulting to 1\n");
patch = "1";
}
@@ -147,7 +150,8 @@ 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"
+ cmCPackLogger(cmCPackLog::LOG_WARNING,
+ "CPACK_CYGWIN_PATCH_NUMBER"
<< " not specified, defaulting to 1\n");
patch = "1";
}
diff --git a/Source/CPack/cmCPackCygwinSourceGenerator.h b/Source/CPack/cmCPackCygwinSourceGenerator.h
index 896de1d3e..a909b1595 100644
--- a/Source/CPack/cmCPackCygwinSourceGenerator.h
+++ b/Source/CPack/cmCPackCygwinSourceGenerator.h
@@ -17,7 +17,7 @@ public:
* Construct generator
*/
cmCPackCygwinSourceGenerator();
- virtual ~cmCPackCygwinSourceGenerator();
+ ~cmCPackCygwinSourceGenerator() override;
protected:
const char* GetPackagingInstallPrefix();
diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx
index af54fce33..cfb5efd0e 100644
--- a/Source/CPack/cmCPackDebGenerator.cxx
+++ b/Source/CPack/cmCPackDebGenerator.cxx
@@ -6,36 +6,436 @@
#include "cmCPackComponentGroup.h"
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
+#include "cmCryptoHash.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
#include "cm_sys_stat.h"
#include "cmsys/Glob.hxx"
-#include <limits.h>
#include <map>
#include <ostream>
#include <set>
-#include <stdio.h>
#include <string.h>
#include <utility>
-// 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);
+namespace {
-cmCPackDebGenerator::cmCPackDebGenerator()
+class DebGenerator
{
+public:
+ DebGenerator(cmCPackLog* logger, std::string outputName, std::string workDir,
+ std::string topLevelDir, std::string temporaryDir,
+ const char* debianCompressionType,
+ const char* debianArchiveType,
+ std::map<std::string, std::string> controlValues,
+ bool genShLibs, std::string shLibsFilename, bool genPostInst,
+ std::string postInst, bool genPostRm, std::string postRm,
+ const char* controlExtra, bool permissionStrctPolicy,
+ std::vector<std::string> packageFiles);
+
+ bool generate() const;
+
+private:
+ void generateDebianBinaryFile() const;
+ void generateControlFile() const;
+ bool generateDataTar() const;
+ std::string generateMD5File() const;
+ bool generateControlTar(std::string const& md5Filename) const;
+ bool generateDeb() const;
+
+ cmCPackLog* Logger;
+ const std::string OutputName;
+ const std::string WorkDir;
+ std::string CompressionSuffix;
+ const std::string TopLevelDir;
+ const std::string TemporaryDir;
+ const char* DebianArchiveType;
+ const std::map<std::string, std::string> ControlValues;
+ const bool GenShLibs;
+ const std::string ShLibsFilename;
+ const bool GenPostInst;
+ const std::string PostInst;
+ const bool GenPostRm;
+ const std::string PostRm;
+ const char* ControlExtra;
+ const bool PermissionStrictPolicy;
+ const std::vector<std::string> PackageFiles;
+ cmArchiveWrite::Compress TarCompressionType;
+};
+
+DebGenerator::DebGenerator(
+ cmCPackLog* logger, std::string outputName, std::string workDir,
+ std::string topLevelDir, std::string temporaryDir,
+ const char* debianCompressionType, const char* debianArchiveType,
+ std::map<std::string, std::string> controlValues, bool genShLibs,
+ std::string shLibsFilename, bool genPostInst, std::string postInst,
+ bool genPostRm, std::string postRm, const char* controlExtra,
+ bool permissionStrictPolicy, std::vector<std::string> packageFiles)
+ : Logger(logger)
+ , OutputName(std::move(outputName))
+ , WorkDir(std::move(workDir))
+ , TopLevelDir(std::move(topLevelDir))
+ , TemporaryDir(std::move(temporaryDir))
+ , DebianArchiveType(debianArchiveType ? debianArchiveType : "gnutar")
+ , ControlValues(std::move(controlValues))
+ , GenShLibs(genShLibs)
+ , ShLibsFilename(std::move(shLibsFilename))
+ , GenPostInst(genPostInst)
+ , PostInst(std::move(postInst))
+ , GenPostRm(genPostRm)
+ , PostRm(std::move(postRm))
+ , ControlExtra(controlExtra)
+ , PermissionStrictPolicy(permissionStrictPolicy)
+ , PackageFiles(std::move(packageFiles))
+{
+ if (!debianCompressionType) {
+ debianCompressionType = "gzip";
+ }
+
+ if (!strcmp(debianCompressionType, "lzma")) {
+ CompressionSuffix = ".lzma";
+ TarCompressionType = cmArchiveWrite::CompressLZMA;
+ } else if (!strcmp(debianCompressionType, "xz")) {
+ CompressionSuffix = ".xz";
+ TarCompressionType = cmArchiveWrite::CompressXZ;
+ } else if (!strcmp(debianCompressionType, "bzip2")) {
+ CompressionSuffix = ".bz2";
+ TarCompressionType = cmArchiveWrite::CompressBZip2;
+ } else if (!strcmp(debianCompressionType, "gzip")) {
+ CompressionSuffix = ".gz";
+ TarCompressionType = cmArchiveWrite::CompressGZip;
+ } else if (!strcmp(debianCompressionType, "none")) {
+ CompressionSuffix.clear();
+ TarCompressionType = cmArchiveWrite::CompressNone;
+ } else {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error unrecognized compression type: "
+ << debianCompressionType << std::endl);
+ }
+}
+
+bool DebGenerator::generate() const
+{
+ generateDebianBinaryFile();
+ generateControlFile();
+ if (!generateDataTar()) {
+ return false;
+ }
+ std::string md5Filename = generateMD5File();
+ if (!generateControlTar(md5Filename)) {
+ return false;
+ }
+ return generateDeb();
+}
+
+void DebGenerator::generateDebianBinaryFile() const
+{
+ // debian-binary file
+ const std::string dbfilename = WorkDir + "/debian-binary";
+ cmGeneratedFileStream out(dbfilename);
+ out << "2.0";
+ out << std::endl; // required for valid debian package
+}
+
+void DebGenerator::generateControlFile() const
+{
+ std::string ctlfilename = WorkDir + "/control";
+
+ cmGeneratedFileStream out(ctlfilename);
+ for (auto const& kv : ControlValues) {
+ out << kv.first << ": " << kv.second << "\n";
+ }
+
+ unsigned long totalSize = 0;
+ {
+ std::string dirName = TemporaryDir;
+ dirName += '/';
+ for (std::string const& file : PackageFiles) {
+ totalSize += cmSystemTools::FileLength(file);
+ }
+ }
+ out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n";
+ out << std::endl;
+}
+
+bool DebGenerator::generateDataTar() const
+{
+ std::string filename_data_tar = WorkDir + "/data.tar" + CompressionSuffix;
+ cmGeneratedFileStream fileStream_data_tar;
+ fileStream_data_tar.Open(filename_data_tar, false, true);
+ if (!fileStream_data_tar) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error opening the file \""
+ << filename_data_tar << "\" for writing" << std::endl);
+ return false;
+ }
+ cmArchiveWrite data_tar(fileStream_data_tar, TarCompressionType,
+ DebianArchiveType);
+
+ // uid/gid should be the one of the root user, and this root user has
+ // always uid/gid equal to 0.
+ data_tar.SetUIDAndGID(0u, 0u);
+ data_tar.SetUNAMEAndGNAME("root", "root");
+
+ // 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 = WorkDir.length();
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "WDIR: \"" << WorkDir << "\", length = " << topLevelLength
+ << std::endl);
+ std::set<std::string> orderedFiles;
+
+ // we have to reconstruct the parent folders as well
+
+ for (std::string currentPath : PackageFiles) {
+ while (currentPath != WorkDir) {
+ // the last one IS WorkDir, but we do not want this one:
+ // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application
+ // should not add XXX/application
+ orderedFiles.insert(currentPath);
+ currentPath = cmSystemTools::CollapseFullPath("..", currentPath);
+ }
+ }
+
+ for (std::string const& file : orderedFiles) {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "FILEIT: \"" << file << "\"" << std::endl);
+ std::string::size_type slashPos = file.find('/', topLevelLength + 1);
+ std::string relativeDir =
+ file.substr(topLevelLength, slashPos - topLevelLength);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "RELATIVEDIR: \"" << relativeDir << "\"" << std::endl);
+
+#ifdef WIN32
+ std::string mode_t_adt_filename = file + ":cmake_mode_t";
+ cmsys::ifstream permissionStream(mode_t_adt_filename.c_str());
+
+ mode_t permissions = 0;
+
+ if (permissionStream) {
+ permissionStream >> std::oct >> permissions;
+ }
+
+ if (permissions != 0) {
+ data_tar.SetPermissions(permissions);
+ } else if (cmSystemTools::FileIsDirectory(file)) {
+ data_tar.SetPermissions(0755);
+ } else {
+ data_tar.ClearPermissions();
+ }
+#endif
+
+ // do not recurse because the loop will do it
+ if (!data_tar.Add(file, topLevelLength, ".", false)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem adding file to tar:"
+ << std::endl
+ << "#top level directory: " << WorkDir << std::endl
+ << "#file: " << file << std::endl
+ << "#error:" << data_tar.GetError() << std::endl);
+ return false;
+ }
+ }
+ return true;
+}
+
+std::string DebGenerator::generateMD5File() const
+{
+ std::string md5filename = WorkDir + "/md5sums";
+
+ cmGeneratedFileStream out(md5filename);
+
+ std::string topLevelWithTrailingSlash = TemporaryDir;
+ topLevelWithTrailingSlash += '/';
+ for (std::string const& file : PackageFiles) {
+ // hash only regular files
+ if (cmSystemTools::FileIsDirectory(file) ||
+ cmSystemTools::FileIsSymlink(file)) {
+ continue;
+ }
+
+ std::string output =
+ cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
+ if (output.empty()) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem computing the md5 of " << file << std::endl);
+ }
+
+ output += " " + file + "\n";
+ // 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)
+ return md5filename;
+}
+
+bool DebGenerator::generateControlTar(std::string const& md5Filename) const
+{
+ std::string filename_control_tar = WorkDir + "/control.tar.gz";
+
+ cmGeneratedFileStream fileStream_control_tar;
+ fileStream_control_tar.Open(filename_control_tar, false, true);
+ if (!fileStream_control_tar) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error opening the file \""
+ << filename_control_tar << "\" for writing" << std::endl);
+ return false;
+ }
+ cmArchiveWrite control_tar(fileStream_control_tar,
+ cmArchiveWrite::CompressGZip, DebianArchiveType);
+
+ // sets permissions and uid/gid for the files
+ control_tar.SetUIDAndGID(0u, 0u);
+ control_tar.SetUNAMEAndGNAME("root", "root");
+
+ /* permissions are set according to
+ https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners
+ and
+ https://lintian.debian.org/tags/control-file-has-bad-permissions.html
+ */
+ const mode_t permission644 = 0644;
+ const mode_t permissionExecute = 0111;
+ const mode_t permission755 = permission644 | permissionExecute;
+
+ // for md5sum and control (that we have generated here), we use 644
+ // (RW-R--R--)
+ // so that deb lintian doesn't warn about it
+ control_tar.SetPermissions(permission644);
+
+ // adds control and md5sums
+ if (!control_tar.Add(md5Filename, WorkDir.length(), ".") ||
+ !control_tar.Add(WorkDir + "/control", WorkDir.length(), ".")) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error adding file to tar:"
+ << std::endl
+ << "#top level directory: " << WorkDir << std::endl
+ << "#file: \"control\" or \"md5sums\"" << std::endl
+ << "#error:" << control_tar.GetError() << std::endl);
+ return false;
+ }
+
+ // adds generated shlibs file
+ if (GenShLibs) {
+ if (!control_tar.Add(ShLibsFilename, WorkDir.length(), ".")) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error adding file to tar:"
+ << std::endl
+ << "#top level directory: " << WorkDir << std::endl
+ << "#file: \"shlibs\"" << std::endl
+ << "#error:" << control_tar.GetError() << std::endl);
+ return false;
+ }
+ }
+
+ // adds LDCONFIG related files
+ if (GenPostInst) {
+ control_tar.SetPermissions(permission755);
+ if (!control_tar.Add(PostInst, WorkDir.length(), ".")) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error adding file to tar:"
+ << std::endl
+ << "#top level directory: " << WorkDir << std::endl
+ << "#file: \"postinst\"" << std::endl
+ << "#error:" << control_tar.GetError() << std::endl);
+ return false;
+ }
+ control_tar.SetPermissions(permission644);
+ }
+
+ if (GenPostRm) {
+ control_tar.SetPermissions(permission755);
+ if (!control_tar.Add(PostRm, WorkDir.length(), ".")) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error adding file to tar:"
+ << std::endl
+ << "#top level directory: " << WorkDir << std::endl
+ << "#file: \"postinst\"" << std::endl
+ << "#error:" << control_tar.GetError() << std::endl);
+ return false;
+ }
+ control_tar.SetPermissions(permission644);
+ }
+
+ // for the other files, we use
+ // -either the original permission on the files
+ // -either a permission strictly defined by the Debian policies
+ if (ControlExtra) {
+ // permissions are now controlled by the original file permissions
+
+ static const char* strictFiles[] = { "config", "postinst", "postrm",
+ "preinst", "prerm" };
+ std::set<std::string> setStrictFiles(
+ strictFiles, strictFiles + sizeof(strictFiles) / sizeof(strictFiles[0]));
+
+ // default
+ control_tar.ClearPermissions();
+
+ std::vector<std::string> controlExtraList;
+ cmSystemTools::ExpandListArgument(ControlExtra, controlExtraList);
+ for (std::string const& i : controlExtraList) {
+ std::string filenamename = cmsys::SystemTools::GetFilenameName(i);
+ std::string localcopy = WorkDir + "/" + filenamename;
+
+ if (PermissionStrictPolicy) {
+ control_tar.SetPermissions(
+ setStrictFiles.count(filenamename) ? permission755 : permission644);
+ }
+
+ // if we can copy the file, it means it does exist, let's add it:
+ if (cmsys::SystemTools::CopyFileIfDifferent(i, localcopy)) {
+ control_tar.Add(localcopy, WorkDir.length(), ".");
+ }
+ }
+ }
+
+ return true;
}
-cmCPackDebGenerator::~cmCPackDebGenerator()
+bool DebGenerator::generateDeb() const
{
+ // ar -r your-package-name.deb debian-binary control.tar.* data.tar.*
+ // 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
+ std::string const outputPath = TopLevelDir + "/" + OutputName;
+ std::string const tlDir = WorkDir + "/";
+ cmGeneratedFileStream debStream;
+ debStream.Open(outputPath, false, true);
+ cmArchiveWrite deb(debStream, cmArchiveWrite::CompressNone, "arbsd");
+
+ // uid/gid should be the one of the root user, and this root user has
+ // always uid/gid equal to 0.
+ deb.SetUIDAndGID(0u, 0u);
+ deb.SetUNAMEAndGNAME("root", "root");
+
+ if (!deb.Add(tlDir + "debian-binary", tlDir.length()) ||
+ !deb.Add(tlDir + "control.tar.gz", tlDir.length()) ||
+ !deb.Add(tlDir + "data.tar" + CompressionSuffix, tlDir.length())) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error creating debian package:"
+ << std::endl
+ << "#top level directory: " << TopLevelDir << std::endl
+ << "#file: " << OutputName << std::endl
+ << "#error:" << deb.GetError() << std::endl);
+ return false;
+ }
+ return true;
}
+} // end anonymous namespace
+
+cmCPackDebGenerator::cmCPackDebGenerator() = default;
+
+cmCPackDebGenerator::~cmCPackDebGenerator() = default;
+
int cmCPackDebGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr");
@@ -72,25 +472,27 @@ int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel,
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);
+ if (!this->ReadListFile("Internal/CPack/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("GEN_WDIR"));
- findExpr += "/*";
- gl.RecurseOn();
- gl.SetRecurseListDirs(true);
- if (!gl.FindFiles(findExpr)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR,
- "Cannot find any files in the installed directory"
- << std::endl);
- return 0;
+ { // Isolate globbing of binaries vs. dbgsyms
+ cmsys::Glob gl;
+ std::string findExpr(this->GetOption("GEN_WDIR"));
+ findExpr += "/*";
+ gl.RecurseOn();
+ gl.SetRecurseListDirs(true);
+ if (!gl.FindFiles(findExpr)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find any files in the installed directory"
+ << std::endl);
+ return 0;
+ }
+ packageFiles = gl.GetFiles();
}
- packageFiles = gl.GetFiles();
int res = createDeb();
if (res != 1) {
@@ -100,7 +502,33 @@ int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel,
packageFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
packageFileName += "/";
packageFileName += this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME");
- packageFileNames.push_back(packageFileName);
+ packageFileNames.push_back(std::move(packageFileName));
+
+ if (this->IsOn("GEN_CPACK_DEBIAN_DEBUGINFO_PACKAGE")) {
+ cmsys::Glob gl;
+ std::string findExpr(this->GetOption("GEN_DBGSYMDIR"));
+ findExpr += "/*";
+ gl.RecurseOn();
+ gl.SetRecurseListDirs(true);
+ if (!gl.FindFiles(findExpr)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find any files in the installed directory"
+ << std::endl);
+ return 0;
+ }
+ packageFiles = gl.GetFiles();
+
+ res = createDbgsymDDeb();
+ if (res != 1) {
+ retval = 0;
+ }
+ // add the generated package to package file names list
+ packageFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ packageFileName += "/";
+ packageFileName += this->GetOption("GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME");
+ packageFileNames.push_back(std::move(packageFileName));
+ }
+
return retval;
}
@@ -115,37 +543,32 @@ int cmCPackDebGenerator::PackageComponents(bool ignoreGroup)
// 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);
+ for (auto const& compG : this->ComponentGroups) {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Packaging component group: " << compG.first << std::endl);
// Begin the archive for this group
- retval &= PackageOnePack(initialTopLevel, compGIt->first);
+ retval &= PackageOnePack(initialTopLevel, compG.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) {
+ for (auto const& comp : this->Components) {
// Does the component belong to a group?
- if (compIt->second.Group == CM_NULLPTR) {
+ if (comp.second.Group == nullptr) {
cmCPackLogger(
- cmCPackLog::LOG_VERBOSE, "Component <"
- << compIt->second.Name
+ cmCPackLog::LOG_VERBOSE,
+ "Component <"
+ << comp.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);
+ retval &= PackageOnePack(initialTopLevel, comp.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);
+ for (auto const& comp : this->Components) {
+ retval &= PackageOnePack(initialTopLevel, comp.first);
}
}
return retval;
@@ -195,9 +618,9 @@ int cmCPackDebGenerator::PackageComponentsAllInOne(
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);
+ if (!this->ReadListFile("Internal/CPack/CPackDeb.cmake")) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackDeb.cmake" << std::endl);
retval = 0;
return retval;
}
@@ -223,7 +646,7 @@ int cmCPackDebGenerator::PackageComponentsAllInOne(
packageFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
packageFileName += "/";
packageFileName += this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME");
- packageFileNames.push_back(packageFileName);
+ packageFileNames.push_back(std::move(packageFileName));
return retval;
}
@@ -250,114 +673,81 @@ int cmCPackDebGenerator::PackageFiles()
int cmCPackDebGenerator::createDeb()
{
- // debian-binary file
- const std::string strGenWDIR(this->GetOption("GEN_WDIR"));
- const std::string dbfilename = strGenWDIR + "/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 = strGenWDIR + "/control";
+ std::map<std::string, std::string> controlValues;
// debian policy enforce lower case for package name
- // mandatory entries:
- std::string debian_pkg_name = cmsys::SystemTools::LowerCase(
+ controlValues["Package"] = cmsys::SystemTools::LowerCase(
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_NAME"));
- const char* debian_pkg_version =
+ controlValues["Version"] =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_VERSION");
- const char* debian_pkg_section =
+ controlValues["Section"] =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SECTION");
- const char* debian_pkg_priority =
+ controlValues["Priority"] =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PRIORITY");
- const char* debian_pkg_arch =
+ controlValues["Architecture"] =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE");
- const char* maintainer =
+ controlValues["Maintainer"] =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER");
- const char* desc = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION");
+ controlValues["Description"] =
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION");
- // optional entries
+ const char* debian_pkg_source =
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE");
+ if (debian_pkg_source && *debian_pkg_source) {
+ controlValues["Source"] = debian_pkg_source;
+ }
const char* debian_pkg_dep =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_DEPENDS");
+ if (debian_pkg_dep && *debian_pkg_dep) {
+ controlValues["Depends"] = debian_pkg_dep;
+ }
const char* debian_pkg_rec =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS");
+ if (debian_pkg_rec && *debian_pkg_rec) {
+ controlValues["Recommends"] = debian_pkg_rec;
+ }
const char* debian_pkg_sug =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS");
+ if (debian_pkg_sug && *debian_pkg_sug) {
+ controlValues["Suggests"] = debian_pkg_sug;
+ }
const char* debian_pkg_url =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE");
+ if (debian_pkg_url && *debian_pkg_url) {
+ controlValues["Homepage"] = debian_pkg_url;
+ }
const char* debian_pkg_predep =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PREDEPENDS");
+ if (debian_pkg_predep && *debian_pkg_predep) {
+ controlValues["Pre-Depends"] = debian_pkg_predep;
+ }
const char* debian_pkg_enhances =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ENHANCES");
+ if (debian_pkg_enhances && *debian_pkg_enhances) {
+ controlValues["Enhances"] = debian_pkg_enhances;
+ }
const char* debian_pkg_breaks =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_BREAKS");
+ if (debian_pkg_breaks && *debian_pkg_breaks) {
+ controlValues["Breaks"] = debian_pkg_breaks;
+ }
const char* debian_pkg_conflicts =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONFLICTS");
+ if (debian_pkg_conflicts && *debian_pkg_conflicts) {
+ controlValues["Conflicts"] = debian_pkg_conflicts;
+ }
const char* debian_pkg_provides =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_PROVIDES");
+ if (debian_pkg_provides && *debian_pkg_provides) {
+ controlValues["Provides"] = debian_pkg_provides;
+ }
const char* debian_pkg_replaces =
this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_REPLACES");
- const char* debian_pkg_source =
- this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE");
-
- { // the scope is needed for cmGeneratedFileStream
- cmGeneratedFileStream out(ctlfilename.c_str());
- 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_source && *debian_pkg_source) {
- out << "Source: " << debian_pkg_source << "\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);
- }
- }
- out << "Installed-Size: " << (totalSize + 1023) / 1024 << "\n";
- out << "Maintainer: " << maintainer << "\n";
- out << "Description: " << desc << "\n";
- out << std::endl;
+ if (debian_pkg_replaces && *debian_pkg_replaces) {
+ controlValues["Replaces"] = debian_pkg_replaces;
}
+ const std::string strGenWDIR(this->GetOption("GEN_WDIR"));
const std::string shlibsfilename = strGenWDIR + "/shlibs";
const char* debian_pkg_shlibs =
@@ -365,7 +755,7 @@ int cmCPackDebGenerator::createDeb()
const bool gen_shibs = this->IsOn("CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS") &&
debian_pkg_shlibs && *debian_pkg_shlibs;
if (gen_shibs) {
- cmGeneratedFileStream out(shlibsfilename.c_str());
+ cmGeneratedFileStream out(shlibsfilename);
out << debian_pkg_shlibs;
out << std::endl;
}
@@ -373,7 +763,7 @@ int cmCPackDebGenerator::createDeb()
const std::string postinst = strGenWDIR + "/postinst";
const std::string postrm = strGenWDIR + "/postrm";
if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST")) {
- cmGeneratedFileStream out(postinst.c_str());
+ cmGeneratedFileStream out(postinst);
out << "#!/bin/sh\n\n"
"set -e\n\n"
"if [ \"$1\" = \"configure\" ]; then\n"
@@ -381,7 +771,7 @@ int cmCPackDebGenerator::createDeb()
"fi\n";
}
if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM")) {
- cmGeneratedFileStream out(postrm.c_str());
+ cmGeneratedFileStream out(postrm);
out << "#!/bin/sh\n\n"
"set -e\n\n"
"if [ \"$1\" = \"remove\" ]; then\n"
@@ -389,288 +779,74 @@ int cmCPackDebGenerator::createDeb()
"fi\n";
}
- cmArchiveWrite::Compress tar_compression_type = cmArchiveWrite::CompressGZip;
- const char* debian_compression_type =
- this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE");
- if (!debian_compression_type) {
- debian_compression_type = "gzip";
- }
-
- std::string compression_suffix;
- if (!strcmp(debian_compression_type, "lzma")) {
- compression_suffix = ".lzma";
- tar_compression_type = cmArchiveWrite::CompressLZMA;
- } else if (!strcmp(debian_compression_type, "xz")) {
- compression_suffix = ".xz";
- tar_compression_type = cmArchiveWrite::CompressXZ;
- } else if (!strcmp(debian_compression_type, "bzip2")) {
- compression_suffix = ".bz2";
- tar_compression_type = cmArchiveWrite::CompressBZip2;
- } else if (!strcmp(debian_compression_type, "gzip")) {
- compression_suffix = ".gz";
- tar_compression_type = cmArchiveWrite::CompressGZip;
- } else if (!strcmp(debian_compression_type, "none")) {
- compression_suffix = "";
- tar_compression_type = cmArchiveWrite::CompressNone;
- } else {
- cmCPackLogger(cmCPackLog::LOG_ERROR,
- "Error unrecognized compression type: "
- << debian_compression_type << std::endl);
- }
+ DebGenerator gen(
+ Logger, this->GetOption("GEN_CPACK_OUTPUT_FILE_NAME"), strGenWDIR,
+ this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
+ this->GetOption("CPACK_TEMPORARY_DIRECTORY"),
+ this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"),
+ this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, gen_shibs,
+ shlibsfilename, this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST"), postinst,
+ this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM"), postrm,
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA"),
+ this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION"),
+ packageFiles);
- const char* debian_archive_type =
- this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE");
- if (!debian_archive_type) {
- debian_archive_type = "paxr";
+ if (!gen.generate()) {
+ return 0;
}
+ return 1;
+}
- std::string filename_data_tar =
- strGenWDIR + "/data.tar" + compression_suffix;
-
- // atomic file generation for data.tar
- {
- cmGeneratedFileStream fileStream_data_tar;
- fileStream_data_tar.Open(filename_data_tar.c_str(), false, true);
- if (!fileStream_data_tar) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error opening the file \""
- << filename_data_tar << "\" for writing" << std::endl);
- return 0;
- }
- cmArchiveWrite data_tar(fileStream_data_tar, tar_compression_type,
- debian_archive_type);
-
- // uid/gid should be the one of the root user, and this root user has
- // always uid/gid equal to 0.
- data_tar.SetUIDAndGID(0u, 0u);
- data_tar.SetUNAMEAndGNAME("root", "root");
-
- // 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 = strGenWDIR.length();
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "WDIR: \""
- << strGenWDIR << "\", length = " << topLevelLength
- << std::endl);
- std::set<std::string> orderedFiles;
-
- // we have to reconstruct the parent folders as well
-
- for (std::vector<std::string>::const_iterator fileIt =
- packageFiles.begin();
- fileIt != packageFiles.end(); ++fileIt) {
- std::string currentPath = *fileIt;
- while (currentPath != strGenWDIR) {
- // the last one IS strGenWDIR, but we do not want this one:
- // XXX/application/usr/bin/myprogram with GEN_WDIR=XXX/application
- // should not add XXX/application
- orderedFiles.insert(currentPath);
- currentPath = cmSystemTools::CollapseCombinedPath(currentPath, "..");
- }
- }
-
- for (std::set<std::string>::const_iterator fileIt = orderedFiles.begin();
- fileIt != orderedFiles.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);
-
- // do not recurse because the loop will do it
- if (!data_tar.Add(*fileIt, topLevelLength, ".", false)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem adding file to tar:"
- << std::endl
- << "#top level directory: " << strGenWDIR << std::endl
- << "#file: " << *fileIt << std::endl
- << "#error:" << data_tar.GetError() << std::endl);
- return 0;
- }
- }
- } // scope for file generation
-
- std::string md5filename = strGenWDIR + "/md5sums";
- {
- // the scope is needed for cmGeneratedFileStream
- cmGeneratedFileStream out(md5filename.c_str());
-
- std::string topLevelWithTrailingSlash =
- this->GetOption("CPACK_TEMPORARY_DIRECTORY");
- topLevelWithTrailingSlash += '/';
- for (std::vector<std::string>::const_iterator fileIt =
- packageFiles.begin();
- fileIt != packageFiles.end(); ++fileIt) {
- // hash only regular files
- if (cmSystemTools::FileIsDirectory(*fileIt) ||
- cmSystemTools::FileIsSymlink(*fileIt)) {
- continue;
- }
+int cmCPackDebGenerator::createDbgsymDDeb()
+{
+ // Packages containing debug symbols follow the same structure as .debs
+ // but have different metadata and content.
- char md5sum[33];
- if (!cmSystemTools::ComputeFileMD5(*fileIt, md5sum)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem computing the md5 of "
- << *fileIt << std::endl);
- }
+ std::map<std::string, std::string> controlValues;
+ // debian policy enforce lower case for package name
+ std::string packageNameLower = cmsys::SystemTools::LowerCase(
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_NAME"));
+ const char* debian_pkg_version =
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_VERSION");
- md5sum[32] = 0;
+ controlValues["Package"] = packageNameLower + "-dbgsym";
+ controlValues["Package-Type"] = "ddeb";
+ controlValues["Version"] = debian_pkg_version;
+ controlValues["Auto-Built-Package"] = "debug-symbols";
+ controlValues["Depends"] = this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_NAME") +
+ std::string(" (= ") + debian_pkg_version + ")";
+ controlValues["Section"] = "debug";
+ controlValues["Priority"] = "optional";
+ controlValues["Architecture"] =
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE");
+ controlValues["Maintainer"] =
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER");
+ controlValues["Description"] =
+ std::string("debug symbols for ") + packageNameLower;
- std::string output(md5sum);
- output += " " + *fileIt + "\n";
- // 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)
+ const char* debian_pkg_source =
+ this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_SOURCE");
+ if (debian_pkg_source && *debian_pkg_source) {
+ controlValues["Source"] = debian_pkg_source;
+ }
+ const char* debian_build_ids = this->GetOption("GEN_BUILD_IDS");
+ if (debian_build_ids && *debian_build_ids) {
+ controlValues["Build-Ids"] = debian_build_ids;
}
- std::string filename_control_tar = strGenWDIR + "/control.tar.gz";
- // atomic file generation for control.tar
- {
- cmGeneratedFileStream fileStream_control_tar;
- fileStream_control_tar.Open(filename_control_tar.c_str(), false, true);
- if (!fileStream_control_tar) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error opening the file \""
- << filename_control_tar << "\" for writing"
- << std::endl);
- return 0;
- }
- cmArchiveWrite control_tar(fileStream_control_tar,
- cmArchiveWrite::CompressGZip,
- debian_archive_type);
-
- // sets permissions and uid/gid for the files
- control_tar.SetUIDAndGID(0u, 0u);
- control_tar.SetUNAMEAndGNAME("root", "root");
-
- /* permissions are set according to
- https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners
- and
- https://lintian.debian.org/tags/control-file-has-bad-permissions.html
- */
- const mode_t permission644 = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
- const mode_t permissionExecute = S_IXUSR | S_IXGRP | S_IXOTH;
- const mode_t permission755 = permission644 | permissionExecute;
-
- // for md5sum and control (that we have generated here), we use 644
- // (RW-R--R--)
- // so that deb lintian doesn't warn about it
- control_tar.SetPermissions(permission644);
-
- // adds control and md5sums
- if (!control_tar.Add(md5filename, strGenWDIR.length(), ".") ||
- !control_tar.Add(strGenWDIR + "/control", strGenWDIR.length(), ".")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:"
- << std::endl
- << "#top level directory: " << strGenWDIR << std::endl
- << "#file: \"control\" or \"md5sums\"" << std::endl
- << "#error:" << control_tar.GetError() << std::endl);
- return 0;
- }
-
- // adds generated shlibs file
- if (gen_shibs) {
- if (!control_tar.Add(shlibsfilename, strGenWDIR.length(), ".")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:"
- << std::endl
- << "#top level directory: " << strGenWDIR << std::endl
- << "#file: \"shlibs\"" << std::endl
- << "#error:" << control_tar.GetError() << std::endl);
- return 0;
- }
- }
-
- // adds LDCONFIG related files
- if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTINST")) {
- control_tar.SetPermissions(permission755);
- if (!control_tar.Add(postinst, strGenWDIR.length(), ".")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:"
- << std::endl
- << "#top level directory: " << strGenWDIR << std::endl
- << "#file: \"postinst\"" << std::endl
- << "#error:" << control_tar.GetError() << std::endl);
- return 0;
- }
- control_tar.SetPermissions(permission644);
- }
+ DebGenerator gen(
+ Logger, this->GetOption("GEN_CPACK_DBGSYM_OUTPUT_FILE_NAME"),
+ this->GetOption("GEN_DBGSYMDIR"),
- if (this->IsOn("GEN_CPACK_DEBIAN_GENERATE_POSTRM")) {
- control_tar.SetPermissions(permission755);
- if (!control_tar.Add(postrm, strGenWDIR.length(), ".")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding file to tar:"
- << std::endl
- << "#top level directory: " << strGenWDIR << std::endl
- << "#file: \"postinst\"" << std::endl
- << "#error:" << control_tar.GetError() << std::endl);
- return 0;
- }
- control_tar.SetPermissions(permission644);
- }
+ this->GetOption("CPACK_TOPLEVEL_DIRECTORY"),
+ this->GetOption("CPACK_TEMPORARY_DIRECTORY"),
+ this->GetOption("GEN_CPACK_DEBIAN_COMPRESSION_TYPE"),
+ this->GetOption("GEN_CPACK_DEBIAN_ARCHIVE_TYPE"), controlValues, false, "",
+ false, "", false, "", nullptr,
+ this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION"),
+ packageFiles);
- // for the other files, we use
- // -either the original permission on the files
- // -either a permission strictly defined by the Debian policies
- const char* controlExtra =
- this->GetOption("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA");
- if (controlExtra) {
- // permissions are now controlled by the original file permissions
-
- const bool permissionStrictPolicy =
- this->IsSet("GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION");
-
- static const char* strictFiles[] = { "config", "postinst", "postrm",
- "preinst", "prerm" };
- std::set<std::string> setStrictFiles(
- strictFiles,
- strictFiles + sizeof(strictFiles) / sizeof(strictFiles[0]));
-
- // default
- control_tar.ClearPermissions();
-
- 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 = strGenWDIR + "/" + filenamename;
-
- if (permissionStrictPolicy) {
- control_tar.SetPermissions(setStrictFiles.count(filenamename)
- ? permission755
- : permission644);
- }
-
- // if we can copy the file, it means it does exist, let's add it:
- if (cmsys::SystemTools::CopyFileIfDifferent(*i, localcopy)) {
- control_tar.Add(localcopy, strGenWDIR.length(), ".");
- }
- }
- }
- }
-
- // 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 = strGenWDIR + "/";
- 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("GEN_CPACK_OUTPUT_FILE_NAME");
- int res = ar_append(outputFileName.c_str(), arFiles);
- if (res != 0) {
- std::string tmpFile =
- this->GetOption("GEN_CPACK_TEMPORARY_PACKAGE_FILE_NAME");
- tmpFile += "/Deb.log";
- cmGeneratedFileStream ofs(tmpFile.c_str());
- ofs << "# Problem creating archive using: " << res << std::endl;
+ if (!gen.generate()) {
return 0;
}
return 1;
@@ -695,252 +871,8 @@ std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix(
// the current COMPONENT belongs to.
std::string groupVar =
"CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP";
- if (CM_NULLPTR != GetOption(groupVar)) {
+ if (nullptr != GetOption(groupVar)) {
return std::string(GetOption(groupVar));
}
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.
- */
-
-#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, (unsigned)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, (unsigned)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 != CM_NULLPTR) {
- 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(CM_NULLPTR, CM_NULLPTR, 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 == CM_NULLPTR) {
- 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
index e7cde1145..2244fe72e 100644
--- a/Source/CPack/cmCPackDebGenerator.h
+++ b/Source/CPack/cmCPackDebGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackDebGenerator_h
#define cmCPackDebGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackGenerator.h"
@@ -23,7 +23,7 @@ public:
* Construct generator
*/
cmCPackDebGenerator();
- ~cmCPackDebGenerator() CM_OVERRIDE;
+ ~cmCPackDebGenerator() override;
static bool CanGenerate()
{
@@ -40,7 +40,7 @@ public:
}
protected:
- int InitializeInternal() CM_OVERRIDE;
+ int InitializeInternal() override;
/**
* This method factors out the work done in component packaging case.
*/
@@ -57,14 +57,16 @@ protected:
* components will be put in a single installer.
*/
int PackageComponentsAllInOne(const std::string& compInstDirName);
- int PackageFiles() CM_OVERRIDE;
- const char* GetOutputExtension() CM_OVERRIDE { return ".deb"; }
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ int PackageFiles() override;
+ const char* GetOutputExtension() override { return ".deb"; }
+ bool SupportsComponentInstallation() const override;
std::string GetComponentInstallDirNameSuffix(
- const std::string& componentName) CM_OVERRIDE;
+ const std::string& componentName) override;
private:
int createDeb();
+ int createDbgsymDDeb();
+
std::vector<std::string> packageFiles;
};
diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx
index d26d5bc1a..7a3742b55 100644
--- a/Source/CPack/cmCPackDragNDropGenerator.cxx
+++ b/Source/CPack/cmCPackDragNDropGenerator.cxx
@@ -4,6 +4,7 @@
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
@@ -20,7 +21,7 @@
// For the old LocaleStringToLangAndRegionCodes() function, to convert
// to the old Script Manager RegionCode values needed for the 'LPic' data
// structure used for generating multi-lingual SLAs.
-#include <CoreServices/CoreServices.h>
+# include <CoreServices/CoreServices.h>
#endif
static const char* SLAHeader =
@@ -61,23 +62,21 @@ cmCPackDragNDropGenerator::cmCPackDragNDropGenerator()
this->componentPackageMethod = ONE_PACKAGE;
}
-cmCPackDragNDropGenerator::~cmCPackDragNDropGenerator()
-{
-}
+cmCPackDragNDropGenerator::~cmCPackDragNDropGenerator() = default;
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");
+ paths.emplace_back("/Applications/Xcode.app/Contents/Developer/Tools");
+ paths.emplace_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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot locate hdiutil command" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_COMMAND_HDIUTIL", hdiutil_path.c_str());
@@ -85,16 +84,16 @@ int cmCPackDragNDropGenerator::InitializeInternal()
const std::string setfile_path =
cmSystemTools::FindProgram("SetFile", paths, false);
if (setfile_path.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot locate SetFile command"
- << std::endl);
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot locate Rez command" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_COMMAND_REZ", rez_path.c_str());
@@ -123,8 +122,8 @@ int cmCPackDragNDropGenerator::InitializeInternal()
return 0;
}
if (!cmSystemTools::FileExists(slaDirectory, false)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_DMG_SLA_DIR does not exist"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_DMG_SLA_DIR does not exist" << std::endl);
return 0;
}
@@ -136,17 +135,19 @@ int cmCPackDragNDropGenerator::InitializeInternal()
"CPACK_DMG_SLA_LANGUAGES set but empty" << std::endl);
return 0;
}
- for (size_t i = 0; i < languages.size(); ++i) {
- std::string license = slaDirectory + "/" + languages[i] + ".license.txt";
+ for (auto const& language : languages) {
+ std::string license = slaDirectory + "/" + language + ".license.txt";
if (!singleLicense && !cmSystemTools::FileExists(license)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing license file "
- << languages[i] << ".license.txt" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Missing license file " << language << ".license.txt"
+ << std::endl);
return 0;
}
- std::string menu = slaDirectory + "/" + languages[i] + ".menu.txt";
+ std::string menu = slaDirectory + "/" + language + ".menu.txt";
if (!cmSystemTools::FileExists(menu)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Missing menu file "
- << languages[i] << ".menu.txt" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Missing menu file " << language << ".menu.txt"
+ << std::endl);
return 0;
}
}
@@ -185,19 +186,19 @@ int cmCPackDragNDropGenerator::PackageFiles()
// loop to create dmg files
packageFileNames.clear();
- for (size_t i = 0; i < package_files.size(); i++) {
+ for (auto const& package_file : package_files) {
std::string full_package_name = std::string(toplevel) + std::string("/");
- if (package_files[i] == "ALL_IN_ONE") {
+ if (package_file == "ALL_IN_ONE") {
full_package_name += this->GetOption("CPACK_PACKAGE_FILE_NAME");
} else {
- full_package_name += package_files[i];
+ full_package_name += package_file;
}
full_package_name += std::string(GetOutputExtension());
packageFileNames.push_back(full_package_name);
std::string src_dir = toplevel;
src_dir += "/";
- src_dir += package_files[i];
+ src_dir += package_file;
if (0 == this->CreateDMG(src_dir, full_package_name)) {
return 0;
@@ -209,10 +210,10 @@ int cmCPackDragNDropGenerator::PackageFiles()
bool cmCPackDragNDropGenerator::CopyFile(std::ostringstream& source,
std::ostringstream& 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);
+ if (!cmSystemTools::CopyFileIfDifferent(source.str(), target.str())) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error copying " << source.str() << " to " << target.str()
+ << std::endl);
return false;
}
@@ -226,14 +227,14 @@ bool cmCPackDragNDropGenerator::CreateEmptyFile(std::ostringstream& target,
cmsys::ofstream fout(target.str().c_str(), std::ios::out | std::ios::binary);
if (!fout) {
return false;
- } else {
- // Seek to desired size - 1 byte
- fout.seekp(size - 1, std::ios::beg);
- char byte = 0;
- // Write one byte to ensure file grows
- fout.write(&byte, 1);
}
+ // Seek to desired size - 1 byte
+ fout.seekp(size - 1, std::ios::beg);
+ char byte = 0;
+ // Write one byte to ensure file grows
+ fout.write(&byte, 1);
+
return true;
}
@@ -242,13 +243,13 @@ bool cmCPackDragNDropGenerator::RunCommand(std::ostringstream& command,
{
int exit_code = 1;
- bool result =
- cmSystemTools::RunSingleCommand(command.str().c_str(), output, output,
- &exit_code, 0, this->GeneratorVerbose, 0);
+ bool result = cmSystemTools::RunSingleCommand(
+ command.str(), output, output, &exit_code, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
if (!result || exit_code) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error executing: " << command.str()
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error executing: " << command.str() << std::endl);
return false;
}
@@ -399,8 +400,8 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
std::ostringstream dummy_padding;
dummy_padding << staging.str() << "/.dummy-padding-file";
if (!this->CreateEmptyFile(dummy_padding, 1048576)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error creating dummy padding file."
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error creating dummy padding file." << std::endl);
return 0;
}
@@ -411,18 +412,22 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
std::string temp_image = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
temp_image += "/temp.dmg";
+ std::string create_error;
std::ostringstream 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 << " -fs HFS+";
temp_image_command << " -format " << temp_image_format;
temp_image_command << " \"" << temp_image << "\"";
- if (!this->RunCommand(temp_image_command)) {
+ if (!this->RunCommand(temp_image_command, &create_error)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
- "Error generating temporary disk image." << std::endl);
+ "Error generating temporary disk image." << std::endl
+ << create_error
+ << std::endl);
return 0;
}
@@ -448,28 +453,32 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
cmsys::RegularExpression mountpoint_regex(".*(/Volumes/[^\n]+)\n.*");
mountpoint_regex.find(attach_output.c_str());
std::string const temp_mount = mountpoint_regex.match(1);
+ std::string const temp_mount_name =
+ temp_mount.substr(sizeof("/Volumes/") - 1);
// Remove dummy padding file so we have enough space on RW image ...
std::ostringstream dummy_padding;
dummy_padding << temp_mount << "/.dummy-padding-file";
if (!cmSystemTools::RemoveFile(dummy_padding.str())) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error removing dummy padding file."
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error removing dummy padding file." << std::endl);
had_error = true;
}
// Optionally set the custom icon flag for the image ...
if (!had_error && !cpack_package_icon.empty()) {
+ std::string error;
std::ostringstream setfile_command;
setfile_command << this->GetOption("CPACK_COMMAND_SETFILE");
setfile_command << " -a C";
setfile_command << " \"" << temp_mount << "\"";
- if (!this->RunCommand(setfile_command)) {
+ if (!this->RunCommand(setfile_command, &error)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Error assigning custom icon to temporary disk image."
- << std::endl);
+ << std::endl
+ << error << std::endl);
had_error = true;
}
@@ -481,7 +490,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
std::ostringstream setup_script_command;
setup_script_command << "osascript"
<< " \"" << cpack_dmg_ds_store_setup_script << "\""
- << " \"" << cpack_dmg_volume_name << "\"";
+ << " \"" << temp_mount_name << "\"";
std::string error;
if (!this->RunCommand(setup_script_command, &error)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -521,7 +530,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
cmSystemTools::ExpandListArgument(cpack_dmg_languages, languages);
}
- cmGeneratedFileStream ofs(sla_r.c_str());
+ cmGeneratedFileStream ofs(sla_r);
ofs << "#include <CoreServices/CoreServices.r>\n\n";
if (oldStyle) {
ofs << SLAHeader;
@@ -551,16 +560,18 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
header_data.push_back(languages.size());
for (size_t i = 0; i < languages.size(); ++i) {
CFStringRef language_cfstring = CFStringCreateWithCString(
- NULL, languages[i].c_str(), kCFStringEncodingUTF8);
+ nullptr, languages[i].c_str(), kCFStringEncodingUTF8);
CFStringRef iso_language =
CFLocaleCreateCanonicalLanguageIdentifierFromString(
- NULL, language_cfstring);
+ nullptr, language_cfstring);
if (!iso_language) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, languages[i]
- << " is not a recognized language" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ languages[i] << " is not a recognized language"
+ << std::endl);
}
- char* iso_language_cstr = (char*)malloc(65);
- CFStringGetCString(iso_language, iso_language_cstr, 64,
+ char iso_language_cstr[65];
+ CFStringGetCString(iso_language, iso_language_cstr,
+ sizeof(iso_language_cstr) - 1,
kCFStringEncodingMacRoman);
LangCode lang = 0;
RegionCode region = 0;
@@ -573,11 +584,9 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
cmCPackLogger(cmCPackLog::LOG_ERROR,
"No language/region code available for "
<< iso_language_cstr << std::endl);
- free(iso_language_cstr);
return 0;
}
#ifdef HAVE_CoreServices
- free(iso_language_cstr);
header_data.push_back(region);
header_data.push_back(i);
header_data.push_back(0);
@@ -630,9 +639,10 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
ofs.Close();
if (have_write_license_error) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error writing license file to SLA."
- << std::endl
- << error << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error writing license file to SLA." << std::endl
+ << error
+ << std::endl);
return 0;
}
@@ -684,9 +694,9 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
embed_sla_command << "\"" << temp_image << "\"";
if (!this->RunCommand(embed_sla_command, &error)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error adding SLA." << std::endl
- << error
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error adding SLA." << std::endl
+ << error << std::endl);
return 0;
}
@@ -715,9 +725,13 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir,
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);
+ std::string convert_error;
+
+ if (!this->RunCommand(final_image_command, &convert_error)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error compressing disk image." << std::endl
+ << convert_error
+ << std::endl);
return 0;
}
@@ -767,7 +781,8 @@ std::string cmCPackDragNDropGenerator::GetComponentInstallDirNameSuffix(
bool cmCPackDragNDropGenerator::WriteLicense(
cmGeneratedFileStream& outputStream, int licenseNumber,
- std::string licenseLanguage, std::string licenseFile, std::string* error)
+ std::string licenseLanguage, const std::string& licenseFile,
+ std::string* error)
{
if (!licenseFile.empty() && !singleLicense) {
licenseNumber = 5002;
@@ -793,8 +808,8 @@ bool cmCPackDragNDropGenerator::WriteLicense(
if (!this->BreakLongLine(line, lines, error)) {
return false;
}
- for (size_t i = 0; i < lines.size(); ++i) {
- outputStream << " \"" << lines[i] << "\"\n";
+ for (auto const& l : lines) {
+ outputStream << " \"" << l << "\"\n";
}
}
outputStream << " \"\\n\"\n";
@@ -863,10 +878,11 @@ bool cmCPackDragNDropGenerator::BreakLongLine(const std::string& line,
size_t line_length = max_line_length;
if (i + line_length > line.size()) {
line_length = line.size() - i;
- } else
+ } else {
while (line_length > 0 && line[i + line_length - 1] != ' ') {
line_length = line_length - 1;
}
+ }
if (line_length == 0) {
*error = "Please make sure there are no words "
diff --git a/Source/CPack/cmCPackDragNDropGenerator.h b/Source/CPack/cmCPackDragNDropGenerator.h
index ae2cc173f..d8c5c8337 100644
--- a/Source/CPack/cmCPackDragNDropGenerator.h
+++ b/Source/CPack/cmCPackDragNDropGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackDragNDropGenerator_h
#define cmCPackDragNDropGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <sstream>
#include <stddef.h>
@@ -23,32 +23,30 @@ public:
cmCPackTypeMacro(cmCPackDragNDropGenerator, cmCPackGenerator);
cmCPackDragNDropGenerator();
- virtual ~cmCPackDragNDropGenerator();
+ ~cmCPackDragNDropGenerator() override;
protected:
- int InitializeInternal() CM_OVERRIDE;
- const char* GetOutputExtension() CM_OVERRIDE;
- int PackageFiles() CM_OVERRIDE;
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ int InitializeInternal() override;
+ const char* GetOutputExtension() override;
+ int PackageFiles() override;
+ bool SupportsComponentInstallation() const override;
bool CopyFile(std::ostringstream& source, std::ostringstream& target);
bool CreateEmptyFile(std::ostringstream& target, size_t size);
bool RunCommand(std::ostringstream& command, std::string* output = 0);
std::string GetComponentInstallDirNameSuffix(
- const std::string& componentName) CM_OVERRIDE;
+ const std::string& componentName) override;
int CreateDMG(const std::string& src_dir, const std::string& output_file);
- std::string InstallPrefix;
-
private:
std::string slaDirectory;
bool singleLicense;
bool WriteLicense(cmGeneratedFileStream& outputStream, int licenseNumber,
- std::string licenseLanguage, std::string licenseFile,
- std::string* error);
+ std::string licenseLanguage,
+ const std::string& licenseFile, std::string* error);
bool BreakLongLine(const std::string& line, std::vector<std::string>& lines,
std::string* error);
void EscapeQuotesAndBackslashes(std::string& line);
diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx
index d8e2753cf..7e07ff488 100644
--- a/Source/CPack/cmCPackGenerator.cxx
+++ b/Source/CPack/cmCPackGenerator.cxx
@@ -6,45 +6,46 @@
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
+#include <cstring>
+#include <memory> // IWYU pragma: keep
#include <utility>
#include "cmCPackComponentGroup.h"
#include "cmCPackLog.h"
#include "cmCryptoHash.h"
+#include "cmDuration.h"
+#include "cmFSPermissions.h"
+#include "cmFileTimes.h"
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmState.h"
#include "cmStateSnapshot.h"
+#include "cmVersion.h"
#include "cmWorkingDirectory.h"
#include "cmXMLSafe.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
#if defined(__HAIKU__)
-#include <FindDirectory.h>
-#include <StorageDefs.h>
+# include <FindDirectory.h>
+# include <StorageDefs.h>
#endif
cmCPackGenerator::cmCPackGenerator()
{
this->GeneratorVerbose = cmSystemTools::OUTPUT_NONE;
- this->MakefileMap = CM_NULLPTR;
- this->Logger = CM_NULLPTR;
+ this->MakefileMap = nullptr;
+ this->Logger = nullptr;
this->componentPackageMethod = ONE_PACKAGE_PER_GROUP;
}
cmCPackGenerator::~cmCPackGenerator()
{
- this->MakefileMap = CM_NULLPTR;
+ this->MakefileMap = nullptr;
}
-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 cmCPackGenerator::DisplayVerboseOutput(const std::string& msg,
+ float progress)
{
(void)progress;
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "" << msg << std::endl);
@@ -57,9 +58,10 @@ int cmCPackGenerator::PrepareNames()
// 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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_SET_DESTDIR is set to ON but the '"
+ << Name << "' generator does NOT support it."
+ << std::endl);
return 0;
}
if (SETDESTDIR_SHOULD_NOT_BE_USED == SupportsSetDestdir()) {
@@ -88,8 +90,8 @@ int cmCPackGenerator::PrepareNames()
std::string outName = pfname;
tempDirectory += "/" + outName;
if (!this->GetOutputExtension()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "No output extension specified"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "No output extension specified" << std::endl);
return 0;
}
outName += this->GetOutputExtension();
@@ -121,8 +123,8 @@ int cmCPackGenerator::PrepareNames()
"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);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Look for: " << descFileName << std::endl);
if (!cmSystemTools::FileExists(descFileName)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Cannot find description file name: ["
@@ -156,9 +158,10 @@ int cmCPackGenerator::PrepareNames()
}
const char* algoSignature = this->GetOption("CPACK_PACKAGE_CHECKSUM");
if (algoSignature) {
- if (cmCryptoHash::New(algoSignature).get() == CM_NULLPTR) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot recognize algorithm: "
- << algoSignature << std::endl);
+ if (!cmCryptoHash::New(algoSignature)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot recognize algorithm: " << algoSignature
+ << std::endl);
return 0;
}
}
@@ -184,7 +187,7 @@ int cmCPackGenerator::InstallProject()
const char* tempInstallDirectory = tempInstallDirectoryStr.c_str();
int res = 1;
- if (!cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory.c_str())) {
+ if (!cmsys::SystemTools::MakeDirectory(bareTempInstallDirectory)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem creating temporary directory: "
<< (tempInstallDirectory ? tempInstallDirectory : "(NULL)")
@@ -201,6 +204,30 @@ int cmCPackGenerator::InstallProject()
cmSystemTools::PutEnv("DESTDIR=");
}
+ // prepare default created directory permissions
+ mode_t default_dir_mode_v = 0;
+ mode_t* default_dir_mode = nullptr;
+ const char* default_dir_install_permissions =
+ this->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
+ if (default_dir_install_permissions && *default_dir_install_permissions) {
+ std::vector<std::string> items;
+ cmSystemTools::ExpandListArgument(default_dir_install_permissions, items);
+ for (const auto& arg : items) {
+ if (!cmFSPermissions::stringToModeT(arg, default_dir_mode_v)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Invalid permission value '"
+ << arg
+ << "'."
+ " CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS "
+ "value is invalid."
+ << std::endl);
+ return 0;
+ }
+ }
+
+ default_dir_mode = &default_dir_mode_v;
+ }
+
// If the CPackConfig file sets CPACK_INSTALL_COMMANDS then run them
// as listed
if (!this->InstallProjectViaInstallCommands(setDestDir,
@@ -218,15 +245,15 @@ int cmCPackGenerator::InstallProject()
// 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)) {
+ if (!this->InstallProjectViaInstalledDirectories(
+ setDestDir, tempInstallDirectory, default_dir_mode)) {
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)) {
+ if (!this->InstallProjectViaInstallCMakeProjects(
+ setDestDir, bareTempInstallDirectory, default_dir_mode)) {
return 0;
}
@@ -248,26 +275,25 @@ int cmCPackGenerator::InstallProjectViaInstallCommands(
cmSystemTools::PutEnv(tempInstallDirectoryEnv);
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);
+ for (std::string const& ic : installCommandsVector) {
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << ic << std::endl);
std::string output;
int retVal = 1;
- bool resB =
- cmSystemTools::RunSingleCommand(it->c_str(), &output, &output, &retVal,
- CM_NULLPTR, this->GeneratorVerbose, 0);
+ bool resB = cmSystemTools::RunSingleCommand(
+ ic, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
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
+ cmGeneratedFileStream ofs(tmpFile);
+ ofs << "# Run command: " << ic << 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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running install command: "
+ << ic << std::endl
+ << "Please check " << tmpFile << " for errors"
+ << std::endl);
return 0;
}
}
@@ -276,7 +302,8 @@ int cmCPackGenerator::InstallProjectViaInstallCommands(
}
int cmCPackGenerator::InstallProjectViaInstalledDirectories(
- bool setDestDir, const std::string& tempInstallDirectory)
+ bool setDestDir, const std::string& tempInstallDirectory,
+ const mode_t* default_dir_mode)
{
(void)setDestDir;
(void)tempInstallDirectory;
@@ -286,12 +313,10 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
std::vector<std::string> ignoreFilesRegexString;
cmSystemTools::ExpandListArgument(cpackIgnoreFiles,
ignoreFilesRegexString);
- std::vector<std::string>::iterator it;
- for (it = ignoreFilesRegexString.begin();
- it != ignoreFilesRegexString.end(); ++it) {
+ for (std::string const& ifr : ignoreFilesRegexString) {
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
- "Create ignore files regex for: " << *it << std::endl);
- ignoreFilesRegex.push_back(it->c_str());
+ "Create ignore files regex for: " << ifr << std::endl);
+ ignoreFilesRegex.emplace_back(ifr);
}
}
const char* installDirectories =
@@ -313,7 +338,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
const std::string& tempDir = tempInstallDirectory;
for (it = installDirectoriesVector.begin();
it != installDirectoriesVector.end(); ++it) {
- std::vector<std::pair<std::string, std::string> > symlinkedFiles;
+ std::vector<std::pair<std::string, std::string>> symlinkedFiles;
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Find files" << std::endl);
cmsys::Glob gl;
std::string top = *it;
@@ -332,17 +357,14 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
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) {
+ for (std::string const& gf : files) {
bool skip = false;
- std::string inFile = *gfit;
- if (cmSystemTools::FileIsDirectory(*gfit)) {
+ std::string inFile = gf;
+ if (cmSystemTools::FileIsDirectory(gf)) {
inFile += '/';
}
- for (regIt = ignoreFilesRegex.begin(); regIt != ignoreFilesRegex.end();
- ++regIt) {
- if (regIt->find(inFile.c_str())) {
+ for (cmsys::RegularExpression& reg : ignoreFilesRegex) {
+ if (reg.find(inFile)) {
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
"Ignore file: " << inFile << std::endl);
skip = true;
@@ -352,63 +374,71 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
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);
+ filePath += "/" + subdir + "/" + cmSystemTools::RelativePath(top, gf);
+ 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)) {
std::string targetFile;
std::string inFileRelative =
- cmSystemTools::RelativePath(top.c_str(), inFile.c_str());
+ cmSystemTools::RelativePath(top, inFile);
cmSystemTools::ReadSymlink(inFile, targetFile);
- symlinkedFiles.push_back(
- std::pair<std::string, std::string>(targetFile, inFileRelative));
+ symlinkedFiles.emplace_back(std::move(targetFile),
+ std::move(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);
+ else if (!(cmSystemTools::CopyFileIfDifferent(inFile, filePath) &&
+ cmFileTimes::Copy(inFile, filePath))) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem copying file: " << inFile << " -> "
+ << filePath << std::endl);
return 0;
}
}
/* rebuild symlinks in the installed tree */
if (!symlinkedFiles.empty()) {
- std::vector<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);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Change dir to: " << goToDir << std::endl);
cmWorkingDirectory workdir(goToDir);
- for (symlinkedIt = symlinkedFiles.begin();
- symlinkedIt != symlinkedFiles.end(); ++symlinkedIt) {
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Will create a symlink: "
- << symlinkedIt->second << "--> "
- << symlinkedIt->first << std::endl);
+ if (workdir.Failed()) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Failed to change working directory to "
+ << goToDir << " : "
+ << std::strerror(workdir.GetLastResult())
+ << std::endl);
+ return 0;
+ }
+ for (auto const& symlinked : symlinkedFiles) {
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Will create a symlink: " << symlinked.second << "--> "
+ << symlinked.first
+ << std::endl);
// make sure directory exists for symlink
std::string destDir =
- cmSystemTools::GetFilenamePath(symlinkedIt->second);
- if (!destDir.empty() && !cmSystemTools::MakeDirectory(destDir)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create dir: "
+ cmSystemTools::GetFilenamePath(symlinked.second);
+ if (!destDir.empty() &&
+ !cmSystemTools::MakeDirectory(destDir, default_dir_mode)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot create dir: "
<< destDir << "\nTrying to create symlink: "
- << symlinkedIt->second << "--> "
- << symlinkedIt->first << std::endl);
+ << symlinked.second << "--> " << symlinked.first
+ << std::endl);
}
- if (!cmSystemTools::CreateSymlink(symlinkedIt->first,
- symlinkedIt->second)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create symlink: "
- << symlinkedIt->second << "--> "
- << symlinkedIt->first << std::endl);
+ if (!cmSystemTools::CreateSymlink(symlinked.first,
+ symlinked.second)) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot create symlink: "
+ << symlinked.second << "--> " << symlinked.first
+ << std::endl);
return 0;
}
}
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Going back to: " << curDir
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Going back to: " << curDir << std::endl);
}
}
}
@@ -420,14 +450,11 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
{
const char* cmakeScripts = this->GetOption("CPACK_INSTALL_SCRIPT");
if (cmakeScripts && *cmakeScripts) {
- cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Install scripts: " << cmakeScripts
- << std::endl);
+ 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;
+ for (std::string const& installScript : cmakeScriptsVector) {
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Install script: " << installScript << std::endl);
@@ -465,7 +492,7 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
tempInstallDirectory.c_str());
this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
tempInstallDirectory.c_str());
- int res = this->MakefileMap->ReadListFile(installScript.c_str());
+ bool res = this->MakefileMap->ReadListFile(installScript);
if (cmSystemTools::GetErrorOccuredFlag() || !res) {
return 0;
}
@@ -475,7 +502,8 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
}
int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
- bool setDestDir, const std::string& baseTempInstallDirectory)
+ bool setDestDir, const std::string& baseTempInstallDirectory,
+ const mode_t* default_dir_mode)
{
const char* cmakeProjects = this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
const char* cmakeGenerator = this->GetOption("CPACK_CMAKE_GENERATOR");
@@ -510,10 +538,13 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
++it;
std::string installProjectName = *it;
++it;
- std::string installComponent = *it;
+ cmCPackInstallCMakeProject project;
+
+ project.Directory = installDirectory;
+ project.ProjectName = installProjectName;
+ project.Component = *it;
++it;
- std::string installSubDirectory = *it;
- std::string installFile = installDirectory + "/cmake_install.cmake";
+ project.SubDirectory = *it;
std::vector<std::string> componentsVector;
@@ -524,38 +555,36 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
* - the user did not request Monolithic install
* (this works at CPack time too)
*/
- if (this->SupportsComponentInstallation() &
+ 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";
+ cmSystemTools::UpperCase(project.Component) + "_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);
+ for (std::string const& installType : installTypesVector) {
+ project.InstallationTypes.push_back(
+ this->GetInstallationType(project.ProjectName, installType));
}
}
// Determine the set of components that will be used in this project
std::string componentsVar =
- "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(installComponent);
+ "CPACK_COMPONENTS_" + cmSystemTools::UpperCase(project.Component);
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);
+ for (std::string const& comp : componentsVector) {
+ project.Components.push_back(
+ this->GetComponent(project.ProjectName, comp));
}
componentInstall = true;
}
}
if (componentsVector.empty()) {
- componentsVector.push_back(installComponent);
+ componentsVector.push_back(project.Component);
}
const char* buildConfigCstr = this->GetOption("CPACK_BUILD_CONFIG");
@@ -575,289 +604,318 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
// on windows.
cmSystemTools::SetForceUnixPaths(globalGenerator->GetForceUnixPaths());
- // Does this generator require pre-install?
- if (const char* preinstall =
- globalGenerator->GetPreinstallTargetName()) {
- std::string buildCommand = globalGenerator->GenerateCMakeBuildCommand(
- preinstall, buildConfig, "", false);
- cmCPackLogger(cmCPackLog::LOG_DEBUG,
- "- Install command: " << buildCommand << std::endl);
- cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Run preinstall target for: "
- << installProjectName << std::endl);
- std::string output;
- int retVal = 1;
- bool resB = cmSystemTools::RunSingleCommand(
- buildCommand.c_str(), &output, &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: " << buildCommand << std::endl
- << "# Directory: " << installDirectory << std::endl
- << "# Output:" << std::endl
- << output << std::endl;
- cmCPackLogger(
- cmCPackLog::LOG_ERROR, "Problem running install command: "
- << buildCommand << std::endl
- << "Please check " << tmpFile << " for errors" << std::endl);
- return 0;
- }
+ if (!this->RunPreinstallTarget(project.ProjectName, project.Directory,
+ globalGenerator, buildConfig)) {
+ return 0;
}
+
delete globalGenerator;
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
- "- Install project: " << installProjectName << std::endl);
+ "- Install project: " << project.ProjectName << 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);
+ for (std::string const& component : componentsVector) {
+ if (!this->InstallCMakeProject(
+ setDestDir, project.Directory, baseTempInstallDirectory,
+ default_dir_mode, component, componentInstall,
+ project.SubDirectory, buildConfig, absoluteDestFiles)) {
+ return 0;
}
+ }
- cmake cm(cmake::RoleScript);
- cm.SetHomeDirectory("");
- cm.SetHomeOutputDirectory("");
- cm.GetCurrentSnapshot().SetDefaultDefinitions();
- cm.AddCMakePaths();
- cm.SetProgressCallback(cmCPackGeneratorProgress, this);
- cmGlobalGenerator gg(&cm);
- CM_AUTO_PTR<cmMakefile> mf(
- new cmMakefile(&gg, cm.GetCurrentSnapshot()));
- if (!installSubDirectory.empty() && installSubDirectory != "/" &&
- installSubDirectory != ".") {
- tempInstallDirectory += 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");
- }
- }
+ this->CMakeProjects.push_back(project);
+ }
+ }
+ this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
+ absoluteDestFiles.c_str());
+ return 1;
+}
- if (!setDestDir) {
- tempInstallDirectory += this->GetPackagingInstallPrefix();
- }
+int cmCPackGenerator::RunPreinstallTarget(
+ const std::string& installProjectName, const std::string& installDirectory,
+ cmGlobalGenerator* globalGenerator, const std::string& buildConfig)
+{
+ // Does this generator require pre-install?
+ if (const char* preinstall = globalGenerator->GetPreinstallTargetName()) {
+ std::string buildCommand = globalGenerator->GenerateCMakeBuildCommand(
+ preinstall, buildConfig, "", false);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Install command: " << buildCommand << 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, &output, &retVal, installDirectory.c_str(),
+ this->GeneratorVerbose, cmDuration::zero());
+ if (!resB || retVal) {
+ std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
+ tmpFile += "/PreinstallOutput.log";
+ cmGeneratedFileStream ofs(tmpFile);
+ ofs << "# Run command: " << buildCommand << std::endl
+ << "# Directory: " << installDirectory << std::endl
+ << "# Output:" << std::endl
+ << output << std::endl;
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running install command: "
+ << buildCommand << std::endl
+ << "Please check " << tmpFile << " for errors"
+ << std::endl);
+ return 0;
+ }
+ }
- 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());
+ return 1;
+}
- 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);
- 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());
+int cmCPackGenerator::InstallCMakeProject(
+ bool setDestDir, const std::string& installDirectory,
+ const std::string& baseTempInstallDirectory, const mode_t* default_dir_mode,
+ const std::string& component, bool componentInstall,
+ const std::string& installSubDirectory, const std::string& buildConfig,
+ std::string& absoluteDestFiles)
+{
+ std::string tempInstallDirectory = baseTempInstallDirectory;
+ std::string installFile = installDirectory + "/cmake_install.cmake";
- if (!cmsys::SystemTools::MakeDirectory(
- tempInstallDirectory.c_str())) {
- cmCPackLogger(cmCPackLog::LOG_ERROR,
- "Problem creating temporary directory: "
- << tempInstallDirectory << std::endl);
- return 0;
- }
+ if (componentInstall) {
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Install component: " << component << std::endl);
+ }
- cmCPackLogger(cmCPackLog::LOG_DEBUG,
- "- Using non-DESTDIR install... (mf->AddDefinition)"
- << std::endl);
- cmCPackLogger(cmCPackLog::LOG_DEBUG,
- "- Setting CMAKE_INSTALL_PREFIX to '"
- << tempInstallDirectory << "'" << std::endl);
- }
+ cmake cm(cmake::RoleScript, cmState::CPack);
+ cm.SetHomeDirectory("");
+ cm.SetHomeOutputDirectory("");
+ cm.GetCurrentSnapshot().SetDefaultDefinitions();
+ cm.AddCMakePaths();
+ cm.SetProgressCallback([this](const std::string& msg, float prog) {
+ this->DisplayVerboseOutput(msg, prog);
+ });
+ cm.SetTrace(this->Trace);
+ cm.SetTraceExpand(this->TraceExpand);
+ cmGlobalGenerator gg(&cm);
+ cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+ if (!installSubDirectory.empty() && installSubDirectory != "/" &&
+ installSubDirectory != ".") {
+ tempInstallDirectory += 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(component);
+ if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) {
+ tempInstallDirectory += "/";
+ tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME");
+ }
+ }
- 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());
- }
+ const char* default_dir_inst_permissions =
+ this->GetOption("CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS");
+ if (default_dir_inst_permissions && *default_dir_inst_permissions) {
+ mf.AddDefinition("CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS",
+ default_dir_inst_permissions);
+ }
- // 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.SetRecurseListDirs(true);
- glB.FindFiles(findExpr);
- filesBefore = glB.GetFiles();
- std::sort(filesBefore.begin(), filesBefore.end());
- }
+ if (!setDestDir) {
+ tempInstallDirectory += this->GetPackagingInstallPrefix();
+ }
- // 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(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"));
- }
+ 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());
- // 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.SetRecurseListDirs(true);
- glA.SetRecurseThroughSymlinks(false);
- 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('/'));
- Components[installComponent].Files.push_back(localFileName);
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Adding file <"
- << localFileName << "> to component <"
- << installComponent << ">" << std::endl);
- }
- }
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "- Creating directory: '" << dir << "'" << std::endl);
- if (CM_NULLPTR !=
- mf->GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
- if (!absoluteDestFiles.empty()) {
- 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 (CM_NULLPTR != 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;
- }
+ if (!cmsys::SystemTools::MakeDirectory(dir, default_dir_mode)) {
+ 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,
+ default_dir_mode)) {
+ 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(component);
+ if (installComponentLowerCase != "all") {
+ mf.AddDefinition("CMAKE_INSTALL_COMPONENT", component.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)
+ std::string const& InstallPrefix = tempInstallDirectory;
+ std::vector<std::string> filesBefore;
+ std::string findExpr = tempInstallDirectory;
+ if (componentInstall) {
+ cmsys::Glob glB;
+ findExpr += "/*";
+ glB.RecurseOn();
+ glB.SetRecurseListDirs(true);
+ 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
+ bool res = mf.ReadListFile(installFile);
+ // 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.SetRecurseListDirs(true);
+ glA.SetRecurseThroughSymlinks(false);
+ 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);
+ localFileName =
+ localFileName.substr(localFileName.find_first_not_of('/'));
+ Components[component].Files.push_back(localFileName);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Adding file <" << localFileName << "> to component <"
+ << component << ">" << std::endl);
+ }
+ }
+
+ if (nullptr != mf.GetDefinition("CPACK_ABSOLUTE_DESTINATION_FILES")) {
+ if (!absoluteDestFiles.empty()) {
+ 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(component);
+ if (nullptr != 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"));
}
}
}
- this->SetOption("CPACK_ABSOLUTE_DESTINATION_FILES",
- absoluteDestFiles.c_str());
+ if (cmSystemTools::GetErrorOccuredFlag() || !res) {
+ return 0;
+ }
return 1;
}
@@ -865,7 +923,7 @@ bool cmCPackGenerator::ReadListFile(const char* moduleName)
{
bool retval;
std::string fullPath = this->MakefileMap->GetModulesFile(moduleName);
- retval = this->MakefileMap->ReadListFile(fullPath.c_str());
+ retval = this->MakefileMap->ReadListFile(fullPath);
// include FATAL_ERROR and ERROR in the return status
retval = retval && (!cmSystemTools::GetErrorOccuredFlag());
return retval;
@@ -887,16 +945,16 @@ void cmCPackGenerator::SetOption(const std::string& op, const char* value)
this->MakefileMap->RemoveDefinition(op);
return;
}
- cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass()
- << "::SetOption(" << op << ", " << value << ")"
- << std::endl);
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "Create package using " << this->Name << std::endl);
// Prepare CPack internal name and check
// values for many CPACK_xxx vars
@@ -914,8 +972,9 @@ int cmCPackGenerator::DoPackage()
const char* toplevelDirectory =
this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
if (cmSystemTools::FileExists(toplevelDirectory)) {
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Remove toplevel directory: "
- << toplevelDirectory << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Remove toplevel directory: " << toplevelDirectory
+ << std::endl);
if (!cmSystemTools::RepeatedRemoveDirectory(toplevelDirectory)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem removing toplevel directory: "
@@ -924,8 +983,8 @@ int cmCPackGenerator::DoPackage()
}
}
}
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "About to install project "
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "About to install project " << std::endl);
if (!this->InstallProject()) {
return 0;
@@ -950,12 +1009,13 @@ int cmCPackGenerator::DoPackage()
}
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Create package" << std::endl);
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Package files to: "
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Remove old package file" << std::endl);
cmSystemTools::RemoveFile(tempPackageFileName);
}
if (cmSystemTools::IsOn(
@@ -972,17 +1032,25 @@ int cmCPackGenerator::DoPackage()
* may update this during PackageFiles.
* (either putting several names or updating the provided one)
*/
- packageFileNames.push_back(tempPackageFileName ? tempPackageFileName : "");
+ packageFileNames.emplace_back(tempPackageFileName ? tempPackageFileName
+ : "");
toplevel = tempDirectory;
- if (!this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem compressing the directory"
- << std::endl);
- return 0;
+ { // scope that enables package generators to run internal scripts with
+ // latest CMake policies enabled
+ cmMakefile::ScopePushPop pp{ this->MakefileMap };
+ this->MakefileMap->SetPolicyVersion(cmVersion::GetCMakeVersion(),
+ std::string());
+
+ if (!this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag()) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem compressing the directory" << std::endl);
+ return 0;
+ }
}
/* Prepare checksum algorithm*/
const char* algo = this->GetOption("CPACK_PACKAGE_CHECKSUM");
- CM_AUTO_PTR<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : "");
+ std::unique_ptr<cmCryptoHash> crypto = cmCryptoHash::New(algo ? algo : "");
/*
* Copy the generated packages to final destination
@@ -990,46 +1058,49 @@ int cmCPackGenerator::DoPackage()
* - 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;
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Copying final package(s) [" << packageFileNames.size()
+ << "]:" << std::endl);
/* now copy package one by one */
- for (it = packageFileNames.begin(); it != packageFileNames.end(); ++it) {
+ for (std::string const& pkgFileName : packageFileNames) {
std::string tmpPF(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
- std::string filename(cmSystemTools::GetFilenameName(*it));
- tempPackageFileName = it->c_str();
+ std::string filename(cmSystemTools::GetFilenameName(pkgFileName));
+ tempPackageFileName = pkgFileName.c_str();
tmpPF += "/" + filename;
const char* packageFileName = tmpPF.c_str();
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy final package(s): "
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Copy final package(s): "
<< (tempPackageFileName ? tempPackageFileName : "(NULL)")
<< " to " << (packageFileName ? packageFileName : "(NULL)")
<< std::endl);
- if (!cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
- packageFileName)) {
+ if (!cmSystemTools::CopyFileIfDifferent(pkgFileName, tmpPF)) {
cmCPackLogger(
- cmCPackLog::LOG_ERROR, "Problem copying the package: "
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- package: " << packageFileName << " generated."
+ << std::endl);
/* Generate checksum file */
- if (crypto.get() != CM_NULLPTR) {
+ if (crypto) {
std::string hashFile(this->GetOption("CPACK_OUTPUT_FILE_PREFIX"));
- hashFile +=
- "/" + filename.substr(0, filename.rfind(this->GetOutputExtension()));
+ hashFile += "/" + filename;
hashFile += "." + cmSystemTools::LowerCase(algo);
cmsys::ofstream outF(hashFile.c_str());
if (!outF) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot create checksum file: "
- << hashFile << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot create checksum file: " << hashFile
+ << std::endl);
return 0;
}
outF << crypto->HashFile(packageFileName) << " " << filename << "\n";
- cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- checksum file: "
- << hashFile << " generated." << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- checksum file: " << hashFile << " generated."
+ << std::endl);
}
}
@@ -1149,7 +1220,8 @@ const char* cmCPackGenerator::GetInstallPath()
const char* cmCPackGenerator::GetPackagingInstallPrefix()
{
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "GetPackagingInstallPrefix: '"
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "GetPackagingInstallPrefix: '"
<< this->GetOption("CPACK_PACKAGING_INSTALL_PREFIX") << "'"
<< std::endl);
@@ -1158,11 +1230,12 @@ const char* cmCPackGenerator::GetPackagingInstallPrefix()
std::string cmCPackGenerator::FindTemplate(const char* name)
{
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for template: "
- << (name ? name : "(NULL)") << std::endl);
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Found template: " << ffile << std::endl);
return ffile;
}
@@ -1173,7 +1246,8 @@ bool cmCPackGenerator::ConfigureString(const std::string& inString,
return true;
}
-bool cmCPackGenerator::ConfigureFile(const char* inName, const char* outName,
+bool cmCPackGenerator::ConfigureFile(const std::string& inName,
+ const std::string& outName,
bool copyOnly /* = false */)
{
return this->MakefileMap->ConfigureFile(inName, outName, copyOnly, true,
@@ -1182,9 +1256,8 @@ bool cmCPackGenerator::ConfigureFile(const char* inName, const char* outName,
int cmCPackGenerator::CleanTemporaryDirectory()
{
- std::string tempInstallDirectoryWithPostfix =
+ std::string tempInstallDirectory =
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);
@@ -1225,15 +1298,15 @@ int cmCPackGenerator::PrepareGroupingKind()
std::string groupingType;
// Second way to specify grouping
- if (CM_NULLPTR != this->GetOption("CPACK_COMPONENTS_GROUPING")) {
+ if (nullptr != this->GetOption("CPACK_COMPONENTS_GROUPING")) {
groupingType = this->GetOption("CPACK_COMPONENTS_GROUPING");
}
if (!groupingType.empty()) {
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "["
- << this->Name << "]"
- << " requested component grouping = " << groupingType
- << std::endl);
+ 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") {
@@ -1242,11 +1315,11 @@ int cmCPackGenerator::PrepareGroupingKind()
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);
+ cmCPackLog::LOG_WARNING,
+ "[" << this->Name << "]"
+ << " requested component grouping type <" << groupingType
+ << "> UNKNOWN not in (ALL_COMPONENTS_IN_ONE,IGNORE,ONE_PER_GROUP)"
+ << std::endl);
}
}
@@ -1260,11 +1333,11 @@ int cmCPackGenerator::PrepareGroupingKind()
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);
+ 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
@@ -1275,10 +1348,10 @@ int cmCPackGenerator::PrepareGroupingKind()
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);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "[" << this->Name << "]"
+ << " requested component grouping = "
+ << method_names[componentPackageMethod] << std::endl);
return 1;
}
@@ -1341,7 +1414,8 @@ bool cmCPackGenerator::SupportsComponentInstallation() const
bool cmCPackGenerator::WantsComponentInstallation() const
{
- return (!IsOn("CPACK_MONOLITHIC_INSTALL") && SupportsComponentInstallation()
+ return (!IsOn("CPACK_MONOLITHIC_INSTALL") &&
+ SupportsComponentInstallation()
// check that we have at least one group or component
&& (!this->ComponentGroups.empty() || !this->Components.empty()));
}
@@ -1407,7 +1481,7 @@ cmCPackComponent* cmCPackGenerator::GetComponent(
component->Group = GetComponentGroup(projectName, groupName);
component->Group->Components.push_back(component);
} else {
- component->Group = CM_NULLPTR;
+ component->Group = nullptr;
}
const char* description = this->GetOption(macroPrefix + "_DESCRIPTION");
@@ -1420,11 +1494,9 @@ cmCPackComponent* cmCPackGenerator::GetComponent(
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) {
+ for (std::string const& installType : installTypesVector) {
component->InstallationTypes.push_back(
- this->GetInstallationType(projectName, *installTypesIt));
+ this->GetInstallationType(projectName, installType));
}
}
@@ -1433,10 +1505,8 @@ cmCPackComponent* cmCPackGenerator::GetComponent(
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);
+ for (std::string const& depend : dependsVector) {
+ cmCPackComponent* child = GetComponent(projectName, depend);
component->Dependencies.push_back(child);
child->ReverseDependencies.push_back(component);
}
@@ -1475,7 +1545,7 @@ cmCPackComponentGroup* cmCPackGenerator::GetComponentGroup(
group->ParentGroup = GetComponentGroup(projectName, parentGroupName);
group->ParentGroup->Subgroups.push_back(group);
} else {
- group->ParentGroup = CM_NULLPTR;
+ group->ParentGroup = nullptr;
}
}
return group;
diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h
index 45777fa05..3c06d4196 100644
--- a/Source/CPack/cmCPackGenerator.h
+++ b/Source/CPack/cmCPackGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackGenerator_h
#define cmCPackGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
#include <sstream>
@@ -12,8 +12,10 @@
#include "cmCPackComponentGroup.h"
#include "cmSystemTools.h"
+#include "cm_sys_stat.h"
class cmCPackLog;
+class cmGlobalGenerator;
class cmInstalledFile;
class cmMakefile;
@@ -35,6 +37,16 @@ public:
}
/**
+ * Put underlying cmake scripts in trace mode.
+ */
+ void SetTrace(bool val) { this->Trace = val; }
+
+ /**
+ * Put underlying cmake scripts in expanded trace mode.
+ */
+ void SetTraceExpand(bool val) { this->TraceExpand = val; }
+
+ /**
* Returns true if the generator may work on this system.
* Rational:
* Some CPack generator may run on some host and may not on others
@@ -84,7 +96,7 @@ public:
void SetLogger(cmCPackLog* log) { this->Logger = log; }
//! Display verbose information via logger
- void DisplayVerboseOutput(const char* msg, float progress);
+ void DisplayVerboseOutput(const std::string& msg, float progress);
bool ReadListFile(const char* moduleName);
@@ -105,7 +117,7 @@ protected:
cmInstalledFile const* GetInstalledFile(std::string const& name) const;
virtual const char* GetOutputExtension() { return ".cpack"; }
- virtual const char* GetOutputPostfix() { return CM_NULLPTR; }
+ virtual const char* GetOutputPostfix() { return nullptr; }
/**
* Prepare requested grouping kind from CPACK_xxx vars
@@ -157,7 +169,8 @@ protected:
virtual const char* GetPackagingInstallPrefix();
virtual std::string FindTemplate(const char* name);
- virtual bool ConfigureFile(const char* inName, const char* outName,
+ virtual bool ConfigureFile(const std::string& inName,
+ const std::string& outName,
bool copyOnly = false);
virtual bool ConfigureString(const std::string& input, std::string& output);
virtual int InitializeInternal();
@@ -168,9 +181,22 @@ protected:
virtual int InstallProjectViaInstallScript(
bool setDestDir, const std::string& tempInstallDirectory);
virtual int InstallProjectViaInstalledDirectories(
- bool setDestDir, const std::string& tempInstallDirectory);
+ bool setDestDir, const std::string& tempInstallDirectory,
+ const mode_t* default_dir_mode);
virtual int InstallProjectViaInstallCMakeProjects(
- bool setDestDir, const std::string& tempInstallDirectory);
+ bool setDestDir, const std::string& tempInstallDirectory,
+ const mode_t* default_dir_mode);
+
+ virtual int RunPreinstallTarget(const std::string& installProjectName,
+ const std::string& installDirectory,
+ cmGlobalGenerator* globalGenerator,
+ const std::string& buildConfig);
+ virtual int InstallCMakeProject(
+ bool setDestDir, const std::string& installDirectory,
+ const std::string& baseTempInstallDirectory,
+ const mode_t* default_dir_mode, const std::string& component,
+ bool componentInstall, const std::string& installSubDirectory,
+ const std::string& buildConfig, std::string& absoluteDestFiles);
/**
* The various level of support of
@@ -258,6 +284,7 @@ protected:
*/
std::vector<std::string> files;
+ std::vector<cmCPackInstallCMakeProject> CMakeProjects;
std::map<std::string, cmCPackInstallationType> InstallationTypes;
/**
* The set of components.
@@ -292,14 +319,15 @@ protected:
ComponentPackageMethod componentPackageMethod;
cmCPackLog* Logger;
+ bool Trace;
+ bool TraceExpand;
-private:
cmMakefile* MakefileMap;
};
#define cmCPackTypeMacro(klass, superclass) \
typedef superclass Superclass; \
- const char* GetNameOfClass() CM_OVERRIDE { return #klass; } \
+ const char* GetNameOfClass() override { return #klass; } \
static cmCPackGenerator* CreateGenerator() { return new klass; } \
class cmCPackTypeMacro_UseTrailingSemicolon
diff --git a/Source/CPack/cmCPackGeneratorFactory.cxx b/Source/CPack/cmCPackGeneratorFactory.cxx
index 31f48c7e3..2c5ab4d78 100644
--- a/Source/CPack/cmCPackGeneratorFactory.cxx
+++ b/Source/CPack/cmCPackGeneratorFactory.cxx
@@ -2,16 +2,21 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCPackGeneratorFactory.h"
-#include "cmConfigure.h"
#include <ostream>
#include <utility>
#include "IFW/cmCPackIFWGenerator.h"
#include "cmAlgorithms.h"
#include "cmCPack7zGenerator.h"
+#ifdef HAVE_FREEBSD_PKG
+# include "cmCPackFreeBSDGenerator.h"
+#endif
+#include "cmCPackDebGenerator.h"
+#include "cmCPackExternalGenerator.h"
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
#include "cmCPackNSISGenerator.h"
+#include "cmCPackNuGetGenerator.h"
#include "cmCPackSTGZGenerator.h"
#include "cmCPackTGZGenerator.h"
#include "cmCPackTXZGenerator.h"
@@ -20,26 +25,25 @@
#include "cmCPackZIPGenerator.h"
#ifdef __APPLE__
-#include "cmCPackBundleGenerator.h"
-#include "cmCPackDragNDropGenerator.h"
-#include "cmCPackOSXX11Generator.h"
-#include "cmCPackPackageMakerGenerator.h"
-#include "cmCPackProductBuildGenerator.h"
+# include "cmCPackBundleGenerator.h"
+# include "cmCPackDragNDropGenerator.h"
+# include "cmCPackOSXX11Generator.h"
+# include "cmCPackPackageMakerGenerator.h"
+# include "cmCPackProductBuildGenerator.h"
#endif
#ifdef __CYGWIN__
-#include "cmCPackCygwinBinaryGenerator.h"
-#include "cmCPackCygwinSourceGenerator.h"
+# include "cmCPackCygwinBinaryGenerator.h"
+# include "cmCPackCygwinSourceGenerator.h"
#endif
#if !defined(_WIN32) && !defined(__QNXNTO__) && !defined(__BEOS__) && \
!defined(__HAIKU__)
-#include "cmCPackDebGenerator.h"
-#include "cmCPackRPMGenerator.h"
+# include "cmCPackRPMGenerator.h"
#endif
-#ifdef _WIN32
-#include "WiX/cmCPackWIXGenerator.h"
+#if defined(_WIN32) || (defined(__CYGWIN__) && defined(HAVE_LIBUUID))
+# include "WiX/cmCPackWIXGenerator.h"
#endif
cmCPackGeneratorFactory::cmCPackGeneratorFactory()
@@ -85,7 +89,7 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
this->RegisterGenerator("7Z", "7-Zip file format",
cmCPack7zGenerator::CreateGenerator);
}
-#ifdef _WIN32
+#if defined(_WIN32) || (defined(__CYGWIN__) && defined(HAVE_LIBUUID))
if (cmCPackWIXGenerator::CanGenerate()) {
this->RegisterGenerator("WIX", "MSI file format via WiX tools",
cmCPackWIXGenerator::CreateGenerator);
@@ -99,6 +103,18 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
this->RegisterGenerator("TZ", "Tar Compress compression",
cmCPackTarCompressGenerator::CreateGenerator);
}
+ if (cmCPackDebGenerator::CanGenerate()) {
+ this->RegisterGenerator("DEB", "Debian packages",
+ cmCPackDebGenerator::CreateGenerator);
+ }
+ if (cmCPackNuGetGenerator::CanGenerate()) {
+ this->RegisterGenerator("NuGet", "NuGet packages",
+ cmCPackNuGetGenerator::CreateGenerator);
+ }
+ if (cmCPackExternalGenerator::CanGenerate()) {
+ this->RegisterGenerator("External", "CPack External packages",
+ cmCPackExternalGenerator::CreateGenerator);
+ }
#ifdef __APPLE__
if (cmCPackDragNDropGenerator::CanGenerate()) {
this->RegisterGenerator("DragNDrop", "Mac OSX Drag And Drop",
@@ -123,15 +139,17 @@ cmCPackGeneratorFactory::cmCPackGeneratorFactory()
#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
+#ifdef HAVE_FREEBSD_PKG
+ if (cmCPackFreeBSDGenerator::CanGenerate()) {
+ this->RegisterGenerator("FREEBSD", "FreeBSD pkg(8) packages",
+ cmCPackFreeBSDGenerator::CreateGenerator);
+ }
+#endif
}
cmCPackGeneratorFactory::~cmCPackGeneratorFactory()
@@ -144,7 +162,7 @@ cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator(
{
cmCPackGenerator* gen = this->NewGeneratorInternal(name);
if (!gen) {
- return CM_NULLPTR;
+ return nullptr;
}
this->Generators.push_back(gen);
gen->SetLogger(this->Logger);
@@ -157,7 +175,7 @@ cmCPackGenerator* cmCPackGeneratorFactory::NewGeneratorInternal(
cmCPackGeneratorFactory::t_GeneratorCreatorsMap::iterator it =
this->GeneratorCreators.find(name);
if (it == this->GeneratorCreators.end()) {
- return CM_NULLPTR;
+ return nullptr;
}
return (it->second)();
}
diff --git a/Source/CPack/cmCPackGeneratorFactory.h b/Source/CPack/cmCPackGeneratorFactory.h
index 7f633e473..972f0f73c 100644
--- a/Source/CPack/cmCPackGeneratorFactory.h
+++ b/Source/CPack/cmCPackGeneratorFactory.h
@@ -22,6 +22,9 @@ public:
cmCPackGeneratorFactory();
~cmCPackGeneratorFactory();
+ cmCPackGeneratorFactory(const cmCPackGeneratorFactory&) = delete;
+ cmCPackGeneratorFactory& operator=(const cmCPackGeneratorFactory&) = delete;
+
//! Get the generator
cmCPackGenerator* NewGenerator(const std::string& name);
void DeleteGenerator(cmCPackGenerator* gen);
diff --git a/Source/CPack/cmCPackLog.cxx b/Source/CPack/cmCPackLog.cxx
index 5c7123959..a3ca4b590 100644
--- a/Source/CPack/cmCPackLog.cxx
+++ b/Source/CPack/cmCPackLog.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCPackLog.h"
-#include "cmConfigure.h"
#include <iostream>
#include "cmGeneratedFileStream.h"
@@ -19,13 +18,13 @@ cmCPackLog::cmCPackLog()
this->DefaultOutput = &std::cout;
this->DefaultError = &std::cerr;
- this->LogOutput = CM_NULLPTR;
+ this->LogOutput = nullptr;
this->LogOutputCleanup = false;
}
cmCPackLog::~cmCPackLog()
{
- this->SetLogOutputStream(CM_NULLPTR);
+ this->SetLogOutputStream(nullptr);
}
void cmCPackLog::SetLogOutputStream(std::ostream* os)
@@ -39,13 +38,13 @@ void cmCPackLog::SetLogOutputStream(std::ostream* os)
bool cmCPackLog::SetLogOutputFile(const char* fname)
{
- cmGeneratedFileStream* cg = CM_NULLPTR;
+ cmGeneratedFileStream* cg = nullptr;
if (fname) {
cg = new cmGeneratedFileStream(fname);
}
if (cg && !*cg) {
delete cg;
- cg = CM_NULLPTR;
+ cg = nullptr;
}
this->SetLogOutputStream(cg);
if (!cg) {
diff --git a/Source/CPack/cmCPackLog.h b/Source/CPack/cmCPackLog.h
index 10deda450..65281e3d8 100644
--- a/Source/CPack/cmCPackLog.h
+++ b/Source/CPack/cmCPackLog.h
@@ -26,6 +26,9 @@ public:
cmCPackLog();
~cmCPackLog();
+ cmCPackLog(const cmCPackLog&) = delete;
+ cmCPackLog& operator=(const cmCPackLog&) = delete;
+
enum __log_tags
{
NOTAG = 0,
@@ -84,7 +87,7 @@ public:
bool SetLogOutputFile(const char* fname);
//! Set the various prefixes for the logging. SetPrefix sets the generic
- // prefix that overwrittes missing ones.
+ // prefix that overwrites missing ones.
void SetPrefix(std::string const& pfx) { this->Prefix = pfx; }
void SetOutputPrefix(std::string const& pfx) { this->OutputPrefix = pfx; }
void SetVerbosePrefix(std::string const& pfx) { this->VerbosePrefix = pfx; }
diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx
index 9697a3832..e2020c5ae 100644
--- a/Source/CPack/cmCPackNSISGenerator.cxx
+++ b/Source/CPack/cmCPackNSISGenerator.cxx
@@ -5,6 +5,7 @@
#include "cmCPackComponentGroup.h"
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
@@ -19,9 +20,9 @@
/* NSIS uses different command line syntax on Windows and others */
#ifdef _WIN32
-#define NSIS_OPT "/"
+# define NSIS_OPT "/"
#else
-#define NSIS_OPT "-"
+# define NSIS_OPT "-"
#endif
cmCPackNSISGenerator::cmCPackNSISGenerator(bool nsis64)
@@ -29,9 +30,7 @@ cmCPackNSISGenerator::cmCPackNSISGenerator(bool nsis64)
Nsis64 = nsis64;
}
-cmCPackNSISGenerator::~cmCPackNSISGenerator()
-{
-}
+cmCPackNSISGenerator::~cmCPackNSISGenerator() = default;
int cmCPackNSISGenerator::PackageFiles()
{
@@ -59,11 +58,9 @@ int cmCPackNSISGenerator::PackageFiles()
std::string nsisInstallOptions = nsisFileName + "/NSIS.InstallOptions.ini";
nsisFileName += "/project.nsi";
std::ostringstream str;
- std::vector<std::string>::const_iterator it;
- for (it = files.begin(); it != files.end(); ++it) {
+ for (std::string const& file : files) {
std::string outputDir = "$INSTDIR";
- std::string fileN =
- cmSystemTools::RelativePath(toplevel.c_str(), it->c_str());
+ std::string fileN = cmSystemTools::RelativePath(toplevel, file);
if (!this->Components.empty()) {
const std::string::size_type pos = fileN.find('/');
@@ -82,17 +79,15 @@ int cmCPackNSISGenerator::PackageFiles()
str << " Delete \"" << outputDir << "\\" << fileN << "\"" << std::endl;
}
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Files: " << str.str()
- << 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;
std::ostringstream dstr;
- for (sit = dirs.begin(); sit != dirs.end(); ++sit) {
+ for (std::string const& dir : dirs) {
std::string componentName;
- std::string fileN =
- cmSystemTools::RelativePath(toplevel.c_str(), sit->c_str());
+ std::string fileN = cmSystemTools::RelativePath(toplevel, dir);
if (fileN.empty()) {
continue;
}
@@ -117,15 +112,16 @@ int cmCPackNSISGenerator::PackageFiles()
dstr << " RMDir \"" << componentOutputDir << "\\" << fileN << "\""
<< std::endl;
if (!componentName.empty()) {
- this->Components[componentName].Directories.push_back(fileN);
+ this->Components[componentName].Directories.push_back(std::move(fileN));
}
}
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Uninstall Dirs: " << dstr.str()
- << std::endl);
+ 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);
+ 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;
@@ -186,7 +182,7 @@ int cmCPackNSISGenerator::PackageFiles()
this->SetOptionIfNotSet("CPACK_NSIS_INSTALLER_MUI_COMPONENTS_DESC", "");
this->SetOptionIfNotSet("CPACK_NSIS_PAGE_COMPONENTS", "");
this->SetOptionIfNotSet("CPACK_NSIS_FULL_INSTALL",
- "File /r \"${INST_DIR}\\*.*\"");
+ R"(File /r "${INST_DIR}\*.*")");
this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTIONS", "");
this->SetOptionIfNotSet("CPACK_NSIS_COMPONENT_SECTION_LIST", "");
this->SetOptionIfNotSet("CPACK_NSIS_SECTION_SELECTED_VARS", "");
@@ -205,65 +201,59 @@ int cmCPackNSISGenerator::PackageFiles()
// 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) {
+ for (auto& installType : this->InstallationTypes) {
+ installTypes[installType.second.Index - 1] = &installType.second;
+ }
+ for (cmCPackInstallationType* installType : installTypes) {
installTypesCode += "InstType \"";
- installTypesCode += (*installTypeIt2)->DisplayName;
+ installTypesCode += installType->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 == CM_NULLPTR) {
+ for (auto& group : this->ComponentGroups) {
+ if (group.second.ParentGroup == nullptr) {
componentCode +=
- this->CreateComponentGroupDescription(&groupIt->second, macrosOut);
+ this->CreateComponentGroupDescription(&group.second, macrosOut);
}
// Add the group description, if any.
- if (!groupIt->second.Description.empty()) {
+ if (!group.second.Description.empty()) {
groupDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" +
- groupIt->first + "} \"" +
- this->TranslateNewlines(groupIt->second.Description) + "\"\n";
+ group.first + "} \"" +
+ cmCPackNSISGenerator::TranslateNewlines(group.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()) {
+ for (auto& comp : this->Components) {
+ if (comp.second.Files.empty()) {
// NSIS cannot cope with components that have no files.
continue;
}
anyDownloadedComponents =
- anyDownloadedComponents || compIt->second.IsDownloaded;
+ anyDownloadedComponents || comp.second.IsDownloaded;
- if (!compIt->second.Group) {
+ if (!comp.second.Group) {
componentCode +=
- this->CreateComponentDescription(&compIt->second, macrosOut);
+ this->CreateComponentDescription(&comp.second, macrosOut);
}
// Add this component to the various section lists.
- sectionList += " !insertmacro \"${MacroName}\" \"";
- sectionList += compIt->first;
+ sectionList += R"( !insertmacro "${MacroName}" ")";
+ sectionList += comp.first;
sectionList += "\"\n";
- selectedVarsList += "Var " + compIt->first + "_selected\n";
- selectedVarsList += "Var " + compIt->first + "_was_installed\n";
+ selectedVarsList += "Var " + comp.first + "_selected\n";
+ selectedVarsList += "Var " + comp.first + "_was_installed\n";
// Add the component description, if any.
- if (!compIt->second.Description.empty()) {
+ if (!comp.second.Description.empty()) {
componentDescriptions += " !insertmacro MUI_DESCRIPTION_TEXT ${" +
- compIt->first + "} \"" +
- this->TranslateNewlines(compIt->second.Description) + "\"\n";
+ comp.first + "} \"" +
+ cmCPackNSISGenerator::TranslateNewlines(comp.second.Description) +
+ "\"\n";
}
}
@@ -302,27 +292,27 @@ int cmCPackNSISGenerator::PackageFiles()
this->SetOption("CPACK_NSIS_DEFINES", defines.c_str());
}
- this->ConfigureFile(nsisInInstallOptions.c_str(),
- nsisInstallOptions.c_str());
- this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str());
+ this->ConfigureFile(nsisInInstallOptions, nsisInstallOptions);
+ this->ConfigureFile(nsisInFileName, nsisFileName);
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, &output, &retVal,
- CM_NULLPTR, this->GeneratorVerbose, 0);
+ bool res = cmSystemTools::RunSingleCommand(
+ nsisCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
if (!res || retVal) {
- cmGeneratedFileStream ofs(tmpFile.c_str());
+ cmGeneratedFileStream ofs(tmpFile);
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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running NSIS command: " << nsisCmd << std::endl
+ << "Please check "
+ << tmpFile << " for errors"
+ << std::endl);
return 0;
}
return 1;
@@ -337,31 +327,34 @@ int cmCPackNSISGenerator::InitializeInternal()
"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", CM_NULLPTR);
+ this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", nullptr);
}
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackNSISGenerator::Initialize()"
- << std::endl);
+ 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)) {
+ 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)) {
+ 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)) {
+ if (!gotRegValue &&
+ cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath,
+ cmsys::SystemTools::KeyWOW64_32)) {
gotRegValue = true;
}
if (!gotRegValue &&
@@ -369,13 +362,15 @@ int cmCPackNSISGenerator::InitializeInternal()
"HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS\\Unicode", nsisPath)) {
gotRegValue = true;
}
- if (!gotRegValue && cmsys::SystemTools::ReadRegistryValue(
- "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath,
- cmsys::SystemTools::KeyWOW64_32)) {
+ 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)) {
+ if (!gotRegValue &&
+ cmsys::SystemTools::ReadRegistryValue(
+ "HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS", nsisPath)) {
gotRegValue = true;
}
@@ -406,13 +401,13 @@ int cmCPackNSISGenerator::InitializeInternal()
}
std::string nsisCmd = "\"" + nsisPath + "\" " NSIS_OPT "VERSION";
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Test NSIS version: " << nsisCmd
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Test NSIS version: " << nsisCmd << std::endl);
std::string output;
int retVal = 1;
- bool resS =
- cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &output, &retVal,
- CM_NULLPTR, this->GeneratorVerbose, 0);
+ bool resS = cmSystemTools::RunSingleCommand(
+ nsisCmd, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
cmsys::RegularExpression versionRex("v([0-9]+.[0-9]+)");
cmsys::RegularExpression versionRexCVS("v(.*)\\.cvs");
if (!resS || retVal ||
@@ -420,21 +415,22 @@ int cmCPackNSISGenerator::InitializeInternal()
const char* topDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
std::string tmpFile = topDir ? topDir : ".";
tmpFile += "/NSISOutput.log";
- cmGeneratedFileStream ofs(tmpFile.c_str());
+ cmGeneratedFileStream ofs(tmpFile);
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);
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "NSIS Version: " << nsisVersion << std::endl);
if (nsisVersion < minNSISVersion) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"CPack requires NSIS Version 2.09 or greater. "
@@ -445,8 +441,8 @@ int cmCPackNSISGenerator::InitializeInternal()
}
if (versionRexCVS.find(output)) {
// No version check for NSIS cvs build
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "NSIS Version: CVS "
- << versionRexCVS.match(1) << std::endl);
+ 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");
@@ -458,19 +454,19 @@ int cmCPackNSISGenerator::InitializeInternal()
this->GetOption("CPACK_NSIS_EXECUTABLES_DIRECTORY");
std::vector<std::string> cpackPackageDesktopLinksVector;
if (cpackPackageDeskTopLinks) {
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: "
- << cpackPackageDeskTopLinks << std::endl);
+ 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) {
+ for (std::string const& cpdl : cpackPackageDesktopLinksVector) {
cmCPackLogger(cmCPackLog::LOG_DEBUG,
- "CPACK_CREATE_DESKTOP_LINKS: " << *i << std::endl);
+ "CPACK_CREATE_DESKTOP_LINKS: " << cpdl << std::endl);
}
} else {
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "CPACK_CREATE_DESKTOP_LINKS: "
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "CPACK_CREATE_DESKTOP_LINKS: "
<< "not set" << std::endl);
}
@@ -478,8 +474,9 @@ int cmCPackNSISGenerator::InitializeInternal()
std::ostringstream deleteStr;
if (cpackPackageExecutables) {
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: "
- << cpackPackageExecutables << "." << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "The cpackPackageExecutables: " << cpackPackageExecutables
+ << "." << std::endl);
std::vector<std::string> cpackPackageExecutablesVector;
cmSystemTools::ExpandListArgument(cpackPackageExecutables,
cpackPackageExecutablesVector);
@@ -497,10 +494,10 @@ int cmCPackNSISGenerator::InitializeInternal()
std::string execName = *it;
++it;
std::string linkName = *it;
- str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName
- << ".lnk\" \"$INSTDIR\\" << cpackNsisExecutablesDirectory << "\\"
+ str << R"( CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\)" << linkName
+ << R"(.lnk" "$INSTDIR\)" << cpackNsisExecutablesDirectory << "\\"
<< execName << ".exe\"" << std::endl;
- deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
+ deleteStr << R"( Delete "$SMPROGRAMS\$MUI_TEMP\)" << linkName
<< ".lnk\"" << std::endl;
// see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
// if so add a desktop link
@@ -510,7 +507,7 @@ int cmCPackNSISGenerator::InitializeInternal()
execName) != cpackPackageDesktopLinksVector.end()) {
str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
str << " CreateShortCut \"$DESKTOP\\" << linkName
- << ".lnk\" \"$INSTDIR\\" << cpackNsisExecutablesDirectory << "\\"
+ << R"(.lnk" "$INSTDIR\)" << cpackNsisExecutablesDirectory << "\\"
<< execName << ".exe\"" << std::endl;
deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
deleteStr << " Delete \"$DESKTOP\\" << linkName << ".lnk\""
@@ -566,15 +563,15 @@ void cmCPackNSISGenerator::CreateMenuLinks(std::ostream& str,
++it;
std::string linkName = *it;
if (!url) {
- str << " CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName
- << ".lnk\" \"$INSTDIR\\" << sourceName << "\"" << std::endl;
- deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
+ str << R"( CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\)" << linkName
+ << R"(.lnk" "$INSTDIR\)" << sourceName << "\"" << std::endl;
+ deleteStr << R"( Delete "$SMPROGRAMS\$MUI_TEMP\)" << linkName
<< ".lnk\"" << std::endl;
} else {
- str << " WriteINIStr \"$SMPROGRAMS\\$STARTMENU_FOLDER\\" << linkName
- << ".url\" \"InternetShortcut\" \"URL\" \"" << sourceName << "\""
+ str << R"( WriteINIStr "$SMPROGRAMS\$STARTMENU_FOLDER\)" << linkName
+ << R"(.url" "InternetShortcut" "URL" ")" << sourceName << "\""
<< std::endl;
- deleteStr << " Delete \"$SMPROGRAMS\\$MUI_TEMP\\" << linkName
+ deleteStr << R"( Delete "$SMPROGRAMS\$MUI_TEMP\)" << linkName
<< ".url\"" << std::endl;
}
// see if CPACK_CREATE_DESKTOP_LINK_ExeName is on
@@ -584,7 +581,7 @@ void cmCPackNSISGenerator::CreateMenuLinks(std::ostream& str,
if (this->IsSet(desktop)) {
str << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
str << " CreateShortCut \"$DESKTOP\\" << linkName
- << ".lnk\" \"$INSTDIR\\" << sourceName << "\"" << std::endl;
+ << R"(.lnk" "$INSTDIR\)" << sourceName << "\"" << std::endl;
deleteStr << " StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2\n";
deleteStr << " Delete \"$DESKTOP\\" << linkName << ".lnk\""
<< std::endl;
@@ -610,7 +607,7 @@ bool cmCPackNSISGenerator::GetListOfSubdirectories(
}
}
}
- dirs.push_back(topdir);
+ dirs.emplace_back(topdir);
return true;
}
@@ -647,11 +644,9 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
componentCode += " SectionIn RO\n";
} else if (!component->InstallationTypes.empty()) {
std::ostringstream out;
- std::vector<cmCPackInstallationType*>::iterator installTypeIter;
- for (installTypeIter = component->InstallationTypes.begin();
- installTypeIter != component->InstallationTypes.end();
- ++installTypeIter) {
- out << " " << (*installTypeIter)->Index;
+ for (cmCPackInstallationType const* installType :
+ component->InstallationTypes) {
+ out << " " << installType->Index;
}
componentCode += " SectionIn" + out.str() + "\n";
}
@@ -682,8 +677,8 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
uploadDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
uploadDirectory += "/CPackUploads";
}
- if (!cmSystemTools::FileExists(uploadDirectory.c_str())) {
- if (!cmSystemTools::MakeDirectory(uploadDirectory.c_str())) {
+ if (!cmSystemTools::FileExists(uploadDirectory)) {
+ if (!cmSystemTools::MakeDirectory(uploadDirectory)) {
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Unable to create NSIS upload directory "
<< uploadDirectory << std::endl);
@@ -696,21 +691,22 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Building downloaded component archive: " << archiveFile
<< std::endl);
- if (cmSystemTools::FileExists(archiveFile.c_str(), true)) {
+ if (cmSystemTools::FileExists(archiveFile, true)) {
if (!cmSystemTools::RemoveFile(archiveFile)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Unable to remove archive file "
- << archiveFile << std::endl);
+ 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");
+ this->ReadListFile("Internal/CPack/CPackZIP.cmake");
if (!this->IsSet("ZIP_EXECUTABLE")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Unable to find ZIP program"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Unable to find ZIP program" << std::endl);
return "";
}
}
@@ -729,20 +725,18 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
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) {
+ cmGeneratedFileStream out(zipListFileName);
+ for (std::string const& file : component->Files) {
if (needQuotesInFile) {
out << "\"";
}
- out << *fileIt;
+ out << file;
if (needQuotesInFile) {
out << "\"";
}
out << std::endl;
- totalSize += cmSystemTools::FileLength(dirName + *fileIt);
+ totalSize += cmSystemTools::FileLength(dirName + file);
}
}
@@ -753,20 +747,21 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
zipListFileName.c_str());
std::string output;
int retVal = -1;
- int res = cmSystemTools::RunSingleCommand(cmd.c_str(), &output, &output,
- &retVal, dirName.c_str(),
- cmSystemTools::OUTPUT_NONE, 0);
+ int res = cmSystemTools::RunSingleCommand(
+ cmd, &output, &output, &retVal, dirName.c_str(),
+ cmSystemTools::OUTPUT_NONE, cmDuration::zero());
if (!res || retVal) {
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/CompressZip.log";
- cmGeneratedFileStream ofs(tmpFile.c_str());
+ cmGeneratedFileStream ofs(tmpFile);
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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running zip command: " << cmd << std::endl
+ << "Please check "
+ << tmpFile << " for errors"
+ << std::endl);
return "";
}
@@ -798,17 +793,14 @@ std::string cmCPackNSISGenerator::CreateComponentDescription(
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;
+ for (std::string const& pathIt : component->Files) {
+ path = pathIt;
std::replace(path.begin(), path.end(), '/', '\\');
macrosOut << " Delete \"" << componentOutputDir << "\\" << path << "\"\n";
}
- for (pathIt = component->Directories.begin();
- pathIt != component->Directories.end(); ++pathIt) {
- path = *pathIt;
+ for (std::string const& pathIt : component->Directories) {
+ path = pathIt;
std::replace(path.begin(), path.end(), '/', '\\');
macrosOut << " RMDir \"" << componentOutputDir << "\\" << path << "\"\n";
}
@@ -841,17 +833,14 @@ std::string cmCPackNSISGenerator::CreateSelectionDependenciesDescription(
visited.insert(component);
std::ostringstream out;
- std::vector<cmCPackComponent*>::iterator dependIt;
- for (dependIt = component->Dependencies.begin();
- dependIt != component->Dependencies.end(); ++dependIt) {
+ for (cmCPackComponent* depend : component->Dependencies) {
// Write NSIS code to select this dependency
- out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n";
+ out << " SectionGetFlags ${" << depend->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";
+ out << " SectionSetFlags ${" << depend->Name << "} $0\n";
+ out << " IntOp $" << depend->Name << "_selected 0 + ${SF_SELECTED}\n";
// Recurse
- out << CreateSelectionDependenciesDescription(*dependIt, visited).c_str();
+ out << CreateSelectionDependenciesDescription(depend, visited).c_str();
}
return out.str();
@@ -867,19 +856,16 @@ std::string cmCPackNSISGenerator::CreateDeselectionDependenciesDescription(
visited.insert(component);
std::ostringstream out;
- std::vector<cmCPackComponent*>::iterator dependIt;
- for (dependIt = component->ReverseDependencies.begin();
- dependIt != component->ReverseDependencies.end(); ++dependIt) {
+ for (cmCPackComponent* depend : component->ReverseDependencies) {
// Write NSIS code to deselect this dependency
- out << " SectionGetFlags ${" << (*dependIt)->Name << "} $0\n";
+ out << " SectionGetFlags ${" << depend->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";
+ out << " SectionSetFlags ${" << depend->Name << "} $0\n";
+ out << " IntOp $" << depend->Name << "_selected 0 + 0\n";
// Recurse
- out
- << CreateDeselectionDependenciesDescription(*dependIt, visited).c_str();
+ out << CreateDeselectionDependenciesDescription(depend, visited).c_str();
}
return out.str();
@@ -903,20 +889,16 @@ std::string cmCPackNSISGenerator::CreateComponentGroupDescription(
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);
+ for (cmCPackComponentGroup* g : group->Subgroups) {
+ code += this->CreateComponentGroupDescription(g, macrosOut);
}
- std::vector<cmCPackComponent*>::iterator comp;
- for (comp = group->Components.begin(); comp != group->Components.end();
- ++comp) {
- if ((*comp)->Files.empty()) {
+ for (cmCPackComponent* comp : group->Components) {
+ if (comp->Files.empty()) {
continue;
}
- code += this->CreateComponentDescription(*comp, macrosOut);
+ code += this->CreateComponentDescription(comp, macrosOut);
}
code += "SectionGroupEnd\n";
return code;
diff --git a/Source/CPack/cmCPackNSISGenerator.h b/Source/CPack/cmCPackNSISGenerator.h
index 77be3256d..fc9ad9ace 100644
--- a/Source/CPack/cmCPackNSISGenerator.h
+++ b/Source/CPack/cmCPackNSISGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackNSISGenerator_h
#define cmCPackNSISGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackGenerator.h"
@@ -34,22 +34,22 @@ public:
* Construct generator
*/
cmCPackNSISGenerator(bool nsis64 = false);
- ~cmCPackNSISGenerator() CM_OVERRIDE;
+ ~cmCPackNSISGenerator() override;
protected:
- int InitializeInternal() CM_OVERRIDE;
+ int InitializeInternal() override;
void CreateMenuLinks(std::ostream& str, std::ostream& deleteStr);
- int PackageFiles() CM_OVERRIDE;
- const char* GetOutputExtension() CM_OVERRIDE { return ".exe"; }
- const char* GetOutputPostfix() CM_OVERRIDE { return "win32"; }
+ int PackageFiles() override;
+ const char* GetOutputExtension() override { return ".exe"; }
+ const char* GetOutputPostfix() override { return "win32"; }
bool GetListOfSubdirectories(const char* dir,
std::vector<std::string>& dirs);
- enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir() const
- CM_OVERRIDE;
- bool SupportsAbsoluteDestination() const CM_OVERRIDE;
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ enum cmCPackGenerator::CPackSetDestdirSupport SupportsSetDestdir()
+ const override;
+ bool SupportsAbsoluteDestination() const override;
+ bool SupportsComponentInstallation() const override;
/// Produce a string that contains the NSIS code to describe a
/// particular component. Any added macros will be emitted via
diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx
index 8ea88a87a..90e0afe7f 100644
--- a/Source/CPack/cmCPackOSXX11Generator.cxx
+++ b/Source/CPack/cmCPackOSXX11Generator.cxx
@@ -6,17 +6,14 @@
#include "cmCPackGenerator.h"
#include "cmCPackLog.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
#include "cm_sys_stat.h"
-cmCPackOSXX11Generator::cmCPackOSXX11Generator()
-{
-}
+cmCPackOSXX11Generator::cmCPackOSXX11Generator() = default;
-cmCPackOSXX11Generator::~cmCPackOSXX11Generator()
-{
-}
+cmCPackOSXX11Generator::~cmCPackOSXX11Generator() = default;
int cmCPackOSXX11Generator::PackageFiles()
{
@@ -26,8 +23,9 @@ int cmCPackOSXX11Generator::PackageFiles()
const char* cpackPackageExecutables =
this->GetOption("CPACK_PACKAGE_EXECUTABLES");
if (cpackPackageExecutables) {
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "The cpackPackageExecutables: "
- << cpackPackageExecutables << "." << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "The cpackPackageExecutables: " << cpackPackageExecutables
+ << "." << std::endl);
std::ostringstream str;
std::ostringstream deleteStr;
std::vector<std::string> cpackPackageExecutablesVector;
@@ -77,14 +75,15 @@ int cmCPackOSXX11Generator::PackageFiles()
if (iconFile) {
std::string iconFileName = cmsys::SystemTools::GetFilenameName(iconFile);
if (!cmSystemTools::FileExists(iconFile)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find icon file: "
+ 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->ConfigureFile(iconFile, destFileName, true);
this->SetOptionIfNotSet("CPACK_APPLE_GUI_ICON", iconFileName.c_str());
}
@@ -108,8 +107,8 @@ int cmCPackOSXX11Generator::PackageFiles()
!this->CopyResourcePlistFile("OSXScriptLauncher", appdir,
this->GetOption("CPACK_PACKAGE_FILE_NAME"),
true)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem copying the resource files" << std::endl);
return 0;
}
@@ -144,19 +143,20 @@ int cmCPackOSXX11Generator::PackageFiles()
tmpFile += "/hdiutilOutput.log";
std::ostringstream dmgCmd;
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
- << "\" create -ov -format UDZO -srcfolder \"" << diskImageDirectory
- << "\" \"" << packageFileNames[0] << "\"";
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress disk image using command: "
- << dmgCmd.str() << std::endl);
+ << "\" create -ov -fs HFS+ -format UDZO -srcfolder \""
+ << diskImageDirectory << "\" \"" << packageFileNames[0] << "\"";
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Compress disk image using command: " << dmgCmd.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, &output,
- &retVal, 0, this->GeneratorVerbose, 0);
+ res = cmSystemTools::RunSingleCommand(
+ dmgCmd.str(), &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
if (res && !retVal) {
numTries = -1;
break;
@@ -165,11 +165,12 @@ int cmCPackOSXX11Generator::PackageFiles()
numTries--;
}
if (!res || retVal) {
- cmGeneratedFileStream ofs(tmpFile.c_str());
+ cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << dmgCmd.str() << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: "
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running hdiutil command: "
<< dmgCmd.str() << std::endl
<< "Please check " << tmpFile << " for errors"
<< std::endl);
@@ -181,13 +182,13 @@ int cmCPackOSXX11Generator::PackageFiles()
int cmCPackOSXX11Generator::InitializeInternal()
{
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackOSXX11Generator::Initialize()"
- << std::endl);
+ 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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find hdiutil compiler" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
@@ -235,7 +236,7 @@ bool cmCPackOSXX11Generator::CopyCreateResourceFile(const std::string& name)
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
<< (inFileName ? inFileName : "(NULL)")
<< " to " << destFileName << std::endl);
- this->ConfigureFile(inFileName, destFileName.c_str());
+ this->ConfigureFile(inFileName, destFileName);
return true;
}
*/
@@ -262,9 +263,10 @@ bool cmCPackOSXX11Generator::CopyResourcePlistFile(
destFileName += "/";
destFileName += outputFileName;
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
- << inFileName << " to " << destFileName << std::endl);
- this->ConfigureFile(inFileName.c_str(), destFileName.c_str(), copyOnly);
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Configure file: " << inFileName << " to " << destFileName
+ << std::endl);
+ this->ConfigureFile(inFileName, destFileName, copyOnly);
return true;
}
diff --git a/Source/CPack/cmCPackOSXX11Generator.h b/Source/CPack/cmCPackOSXX11Generator.h
index 0eebc6dd1..a6461c854 100644
--- a/Source/CPack/cmCPackOSXX11Generator.h
+++ b/Source/CPack/cmCPackOSXX11Generator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackOSXX11Generator_h
#define cmCPackOSXX11Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -23,13 +23,13 @@ public:
* Construct generator
*/
cmCPackOSXX11Generator();
- virtual ~cmCPackOSXX11Generator();
+ ~cmCPackOSXX11Generator() override;
protected:
- virtual int InitializeInternal() CM_OVERRIDE;
- int PackageFiles() CM_OVERRIDE;
- const char* GetPackagingInstallPrefix() CM_OVERRIDE;
- const char* GetOutputExtension() CM_OVERRIDE { return ".dmg"; }
+ virtual int InitializeInternal() override;
+ int PackageFiles() override;
+ const char* GetPackagingInstallPrefix() override;
+ const char* GetOutputExtension() override { return ".dmg"; }
// bool CopyCreateResourceFile(const std::string& name,
// const std::string& dir);
diff --git a/Source/CPack/cmCPackPKGGenerator.cxx b/Source/CPack/cmCPackPKGGenerator.cxx
index 70ae267fb..8c22c65b0 100644
--- a/Source/CPack/cmCPackPKGGenerator.cxx
+++ b/Source/CPack/cmCPackPKGGenerator.cxx
@@ -15,9 +15,7 @@ cmCPackPKGGenerator::cmCPackPKGGenerator()
this->componentPackageMethod = ONE_PACKAGE;
}
-cmCPackPKGGenerator::~cmCPackPKGGenerator()
-{
-}
+cmCPackPKGGenerator::~cmCPackPKGGenerator() = default;
bool cmCPackPKGGenerator::SupportsComponentInstallation() const
{
@@ -26,8 +24,8 @@ bool cmCPackPKGGenerator::SupportsComponentInstallation() const
int cmCPackPKGGenerator::InitializeInternal()
{
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackPKGGenerator::Initialize()"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "cmCPackPKGGenerator::Initialize()" << std::endl);
return this->Superclass::InitializeInternal();
}
@@ -42,9 +40,9 @@ std::string cmCPackPKGGenerator::GetPackageName(
out << cmSystemTools::GetFilenameWithoutLastExtension(packagesDir) << "-"
<< component.Name << ".pkg";
return out.str();
- } else {
- return component.ArchiveFile + ".pkg";
}
+
+ return component.ArchiveFile + ".pkg";
}
void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile)
@@ -52,8 +50,9 @@ void cmCPackPKGGenerator::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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find input file: " << distributionTemplate
+ << std::endl);
return;
}
@@ -67,21 +66,17 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile)
xout.StartElement("choices-outline");
// 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, xout);
+ for (auto const& group : this->ComponentGroups) {
+ if (group.second.ParentGroup == nullptr) {
+ CreateChoiceOutline(group.second, xout);
}
}
// 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) {
+ for (auto const& comp : this->Components) {
+ if (!comp.second.Group) {
xout.StartElement("line");
- xout.Attribute("choice", compIt->first + "Choice");
+ xout.Attribute("choice", comp.first + "Choice");
xout.Content(""); // Avoid self-closing tag.
xout.EndElement();
}
@@ -95,13 +90,11 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile)
xout.EndElement(); // choices-outline>
// Create the actual choices
- for (groupIt = this->ComponentGroups.begin();
- groupIt != this->ComponentGroups.end(); ++groupIt) {
- CreateChoice(groupIt->second, xout);
+ for (auto const& group : this->ComponentGroups) {
+ CreateChoice(group.second, xout);
}
- for (compIt = this->Components.begin(); compIt != this->Components.end();
- ++compIt) {
- CreateChoice(compIt->second, xout);
+ for (auto const& comp : this->Components) {
+ CreateChoice(comp.second, xout);
}
if (!this->PostFlightComponent.Name.empty()) {
@@ -112,7 +105,7 @@ void cmCPackPKGGenerator::WriteDistributionFile(const char* metapackageFile)
// Create the distribution.dist file in the metapackage to turn it
// into a distribution package.
- this->ConfigureFile(distributionTemplate.c_str(), distributionFile.c_str());
+ this->ConfigureFile(distributionTemplate, distributionFile);
}
void cmCPackPKGGenerator::CreateChoiceOutline(
@@ -120,17 +113,13 @@ void cmCPackPKGGenerator::CreateChoiceOutline(
{
xout.StartElement("line");
xout.Attribute("choice", group.Name + "Choice");
- std::vector<cmCPackComponentGroup*>::const_iterator groupIt;
- for (groupIt = group.Subgroups.begin(); groupIt != group.Subgroups.end();
- ++groupIt) {
- CreateChoiceOutline(**groupIt, xout);
+ for (cmCPackComponentGroup* subgroup : group.Subgroups) {
+ CreateChoiceOutline(*subgroup, xout);
}
- std::vector<cmCPackComponent*>::const_iterator compIt;
- for (compIt = group.Components.begin(); compIt != group.Components.end();
- ++compIt) {
+ for (cmCPackComponent* comp : group.Components) {
xout.StartElement("line");
- xout.Attribute("choice", (*compIt)->Name + "Choice");
+ xout.Attribute("choice", comp->Name + "Choice");
xout.Content(""); // Avoid self-closing tag.
xout.EndElement();
}
@@ -189,7 +178,7 @@ void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component,
// 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.
- std::ostringstream selected("my.choice.selected");
+ std::ostringstream selected("my.choice.selected", std::ios_base::ate);
std::set<const cmCPackComponent*> visited;
AddDependencyAttributes(component, visited, selected);
visited.clear();
@@ -224,7 +213,8 @@ void cmCPackPKGGenerator::CreateChoice(const cmCPackComponent& component,
xout.Content(this->GetPackageName(component));
} else {
xout.Content("file:./");
- xout.Content(relativePackageLocation);
+ xout.Content(cmSystemTools::EncodeURL(relativePackageLocation,
+ /*escapeSlashes=*/false));
}
xout.EndElement(); // pkg-ref
}
@@ -238,11 +228,9 @@ void cmCPackPKGGenerator::AddDependencyAttributes(
}
visited.insert(&component);
- std::vector<cmCPackComponent*>::const_iterator dependIt;
- for (dependIt = component.Dependencies.begin();
- dependIt != component.Dependencies.end(); ++dependIt) {
- out << " && choices['" << (*dependIt)->Name << "Choice'].selected";
- AddDependencyAttributes(**dependIt, visited, out);
+ for (cmCPackComponent* depend : component.Dependencies) {
+ out << " && choices['" << depend->Name << "Choice'].selected";
+ AddDependencyAttributes(*depend, visited, out);
}
}
@@ -255,11 +243,9 @@ void cmCPackPKGGenerator::AddReverseDependencyAttributes(
}
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);
+ for (cmCPackComponent* depend : component.ReverseDependencies) {
+ out << " || choices['" << depend->Name << "Choice'].selected";
+ AddReverseDependencyAttributes(*depend, visited, out);
}
}
@@ -270,23 +256,26 @@ bool cmCPackPKGGenerator::CopyCreateResourceFile(const std::string& name,
std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
const char* inFileName = this->GetOption(cpackVar);
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);
+ 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);
+ 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: "
+ cmCPackLog::LOG_ERROR,
+ "Bad file extension specified: "
<< ext
<< ". Currently only .rtfd, .rtf, .html, and .txt files allowed."
<< std::endl);
@@ -305,7 +294,7 @@ bool cmCPackPKGGenerator::CopyCreateResourceFile(const std::string& name,
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
"Configure file: " << (inFileName ? inFileName : "(NULL)")
<< " to " << destFileName << std::endl);
- this->ConfigureFile(inFileName, destFileName.c_str());
+ this->ConfigureFile(inFileName, destFileName);
return true;
}
@@ -330,9 +319,10 @@ bool cmCPackPKGGenerator::CopyResourcePlistFile(const std::string& name,
destFileName += "/";
destFileName += outName;
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: "
- << inFileName << " to " << destFileName << std::endl);
- this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Configure file: " << inFileName << " to " << destFileName
+ << std::endl);
+ this->ConfigureFile(inFileName, destFileName);
return true;
}
diff --git a/Source/CPack/cmCPackPKGGenerator.h b/Source/CPack/cmCPackPKGGenerator.h
index f873c5936..69286ffde 100644
--- a/Source/CPack/cmCPackPKGGenerator.h
+++ b/Source/CPack/cmCPackPKGGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackPKGGenerator_h
#define cmCPackPKGGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <sstream>
@@ -27,13 +27,13 @@ public:
* Construct generator
*/
cmCPackPKGGenerator();
- virtual ~cmCPackPKGGenerator();
+ ~cmCPackPKGGenerator() override;
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ bool SupportsComponentInstallation() const override;
protected:
- int InitializeInternal() CM_OVERRIDE;
- const char* GetOutputPostfix() CM_OVERRIDE { return "darwin"; }
+ int InitializeInternal() override;
+ const char* GetOutputPostfix() override { return "darwin"; }
// Copies or creates the resource file with the given name to the
// package or package staging directory dirName. The variable
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx
index 8db7cfb3d..3d93c48f1 100644
--- a/Source/CPack/cmCPackPackageMakerGenerator.cxx
+++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx
@@ -13,6 +13,7 @@
#include "cmCPackComponentGroup.h"
#include "cmCPackLog.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
#include "cmXMLWriter.h"
@@ -29,9 +30,7 @@ cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
this->PackageCompatibilityVersion = getVersion(10, 4);
}
-cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
-{
-}
+cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator() = default;
bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
{
@@ -250,8 +249,8 @@ int cmCPackPackageMakerGenerator::PackageFiles()
!this->CopyCreateResourceFile("Welcome", resDir) ||
!this->CopyResourcePlistFile("Info.plist") ||
!this->CopyResourcePlistFile("Description.plist")) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem copying the resource files" << std::endl);
return 0;
}
@@ -275,8 +274,9 @@ int cmCPackPackageMakerGenerator::PackageFiles()
if (this->PackageMakerVersion > 2.0) {
pkgCmd << " -v";
}
- if (!RunPackageMaker(pkgCmd.str().c_str(), packageDirFileName.c_str()))
+ 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.
@@ -287,16 +287,16 @@ int cmCPackPackageMakerGenerator::PackageFiles()
tmpFile += "/hdiutilOutput.log";
std::ostringstream dmgCmd;
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE")
- << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
- << "\" \"" << packageFileNames[0] << "\"";
+ << "\" create -ov -fs HFS+ -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, &output,
- &retVal, 0, this->GeneratorVerbose, 0);
+ res = cmSystemTools::RunSingleCommand(
+ dmgCmd.str(), &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
if (res && !retVal) {
numTries = -1;
break;
@@ -305,11 +305,12 @@ int cmCPackPackageMakerGenerator::PackageFiles()
numTries--;
}
if (!res || retVal) {
- cmGeneratedFileStream ofs(tmpFile.c_str());
+ cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << dmgCmd.str() << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: "
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running hdiutil command: "
<< dmgCmd.str() << std::endl
<< "Please check " << tmpFile << " for errors"
<< std::endl);
@@ -337,16 +338,16 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
// 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");
+ paths.emplace_back("/Applications/Xcode.app/Contents/Applications"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.emplace_back("/Applications/Utilities"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.emplace_back("/Applications"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.emplace_back("/Developer/Applications/Utilities"
+ "/PackageMaker.app/Contents/MacOS");
+ paths.emplace_back("/Developer/Applications"
+ "/PackageMaker.app/Contents/MacOS");
std::string pkgPath;
const char* inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM");
@@ -355,8 +356,8 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
} else {
pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false);
if (pkgPath.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find PackageMaker compiler" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
@@ -413,12 +414,13 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
}
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);
+ 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);
+ 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
@@ -446,8 +448,8 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
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);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find hdiutil compiler" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM_DISK_IMAGE",
@@ -466,18 +468,20 @@ bool cmCPackPackageMakerGenerator::RunPackageMaker(const char* command,
std::string output;
int retVal = 1;
bool res = cmSystemTools::RunSingleCommand(
- command, &output, &output, &retVal, 0, this->GeneratorVerbose, 0);
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running package maker"
- << std::endl);
+ command, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Done running package maker" << std::endl);
if (!res || retVal) {
- cmGeneratedFileStream ofs(tmpFile.c_str());
+ cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << command << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
- cmCPackLogger(
- cmCPackLog::LOG_ERROR, "Problem running PackageMaker command: "
- << command << std::endl
- << "Please check " << tmpFile << " for errors" << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem running PackageMaker command: "
+ << command << std::endl
+ << "Please check " << tmpFile << " for errors"
+ << std::endl);
return false;
}
// sometimes the command finishes but the directory is not yet
@@ -502,8 +506,9 @@ bool cmCPackPackageMakerGenerator::GenerateComponentPackage(
const char* packageFile, const char* packageDir,
const cmCPackComponent& component)
{
- cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building component package: "
- << packageFile << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Building component package: " << packageFile
+ << std::endl);
// The command that will be used to run PackageMaker
std::ostringstream pkgCmd;
diff --git a/Source/CPack/cmCPackPackageMakerGenerator.h b/Source/CPack/cmCPackPackageMakerGenerator.h
index 62745152b..0575587d5 100644
--- a/Source/CPack/cmCPackPackageMakerGenerator.h
+++ b/Source/CPack/cmCPackPackageMakerGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackPackageMakerGenerator_h
#define cmCPackPackageMakerGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackGenerator.h"
#include "cmCPackPKGGenerator.h"
@@ -25,13 +25,13 @@ public:
* Construct generator
*/
cmCPackPackageMakerGenerator();
- virtual ~cmCPackPackageMakerGenerator();
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ ~cmCPackPackageMakerGenerator() override;
+ bool SupportsComponentInstallation() const override;
protected:
- int InitializeInternal() CM_OVERRIDE;
- int PackageFiles() CM_OVERRIDE;
- const char* GetOutputExtension() CM_OVERRIDE { return ".dmg"; }
+ int InitializeInternal() override;
+ int PackageFiles() override;
+ const char* GetOutputExtension() override { return ".dmg"; }
// Run PackageMaker with the given command line, which will (if
// successful) produce the given package file. Returns true if
diff --git a/Source/CPack/cmCPackProductBuildGenerator.cxx b/Source/CPack/cmCPackProductBuildGenerator.cxx
index 1389eaa5a..94b5b5f7e 100644
--- a/Source/CPack/cmCPackProductBuildGenerator.cxx
+++ b/Source/CPack/cmCPackProductBuildGenerator.cxx
@@ -8,6 +8,7 @@
#include "cmCPackComponentGroup.h"
#include "cmCPackLog.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmSystemTools.h"
@@ -16,9 +17,7 @@ cmCPackProductBuildGenerator::cmCPackProductBuildGenerator()
this->componentPackageMethod = ONE_PACKAGE;
}
-cmCPackProductBuildGenerator::~cmCPackProductBuildGenerator()
-{
-}
+cmCPackProductBuildGenerator::~cmCPackProductBuildGenerator() = default;
int cmCPackProductBuildGenerator::PackageFiles()
{
@@ -54,7 +53,7 @@ int cmCPackProductBuildGenerator::PackageFiles()
} else {
if (!this->GenerateComponentPackage(basePackageDir,
this->GetOption("CPACK_PACKAGE_NAME"),
- toplevel, NULL)) {
+ toplevel, nullptr)) {
return 0;
}
}
@@ -66,8 +65,8 @@ int cmCPackProductBuildGenerator::PackageFiles()
this->GetOption("CPACK_PRODUCTBUILD_RESOURCES_DIR");
if (!cmSystemTools::CopyADirectory(userResDir, resDir)) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Problem copying the resource files" << std::endl);
return 0;
}
}
@@ -120,16 +119,16 @@ int cmCPackProductBuildGenerator::InitializeInternal()
std::string program =
cmSystemTools::FindProgram("pkgbuild", no_paths, false);
if (program.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find pkgbuild executable"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find pkgbuild executable" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_COMMAND_PKGBUILD", program.c_str());
program = cmSystemTools::FindProgram("productbuild", no_paths, false);
if (program.empty()) {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find productbuild executable"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Cannot find productbuild executable" << std::endl);
return 0;
}
this->SetOptionIfNotSet("CPACK_COMMAND_PRODUCTBUILD", program.c_str());
@@ -143,14 +142,14 @@ bool cmCPackProductBuildGenerator::RunProductBuild(const std::string& command)
tmpFile += "/ProductBuildOutput.log";
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Execute: " << command << std::endl);
- std::string output, error_output;
+ std::string output;
int retVal = 1;
- bool res =
- cmSystemTools::RunSingleCommand(command.c_str(), &output, &error_output,
- &retVal, 0, this->GeneratorVerbose, 0);
+ bool res = cmSystemTools::RunSingleCommand(
+ command, &output, &output, &retVal, nullptr, this->GeneratorVerbose,
+ cmDuration::zero());
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Done running command" << std::endl);
if (!res || retVal) {
- cmGeneratedFileStream ofs(tmpFile.c_str());
+ cmGeneratedFileStream ofs(tmpFile);
ofs << "# Run command: " << command << std::endl
<< "# Output:" << std::endl
<< output << std::endl;
@@ -171,10 +170,11 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage(
packageFile += '/';
packageFile += packageFileName;
- cmCPackLogger(cmCPackLog::LOG_OUTPUT, "- Building component package: "
- << packageFile << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_OUTPUT,
+ "- Building component package: " << packageFile
+ << std::endl);
- const char* comp_name = component ? component->Name.c_str() : NULL;
+ const char* comp_name = component ? component->Name.c_str() : nullptr;
const char* preflight = this->GetComponentScript("PREFLIGHT", comp_name);
const char* postflight = this->GetComponentScript("POSTFLIGHT", comp_name);
@@ -190,7 +190,7 @@ bool cmCPackProductBuildGenerator::GenerateComponentPackage(
cmCPackLogger(cmCPackLog::LOG_ERROR,
"Problem creating installer directory: " << scriptDir
<< std::endl);
- return 0;
+ return false;
}
// if preflight, postflight, or postupgrade are set
diff --git a/Source/CPack/cmCPackProductBuildGenerator.h b/Source/CPack/cmCPackProductBuildGenerator.h
index 12093a0e8..015fe4ace 100644
--- a/Source/CPack/cmCPackProductBuildGenerator.h
+++ b/Source/CPack/cmCPackProductBuildGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackProductBuildGenerator_h
#define cmCPackProductBuildGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -25,12 +25,12 @@ public:
* Construct generator
*/
cmCPackProductBuildGenerator();
- virtual ~cmCPackProductBuildGenerator();
+ ~cmCPackProductBuildGenerator() override;
protected:
- int InitializeInternal() CM_OVERRIDE;
- int PackageFiles() CM_OVERRIDE;
- const char* GetOutputExtension() CM_OVERRIDE { return ".pkg"; }
+ int InitializeInternal() override;
+ int PackageFiles() override;
+ const char* GetOutputExtension() override { return ".pkg"; }
// Run ProductBuild with the given command line, which will (if
// successful) produce the given package file. Returns true if
diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx
index 8ec03c236..33ab62bdf 100644
--- a/Source/CPack/cmCPackRPMGenerator.cxx
+++ b/Source/CPack/cmCPackRPMGenerator.cxx
@@ -14,13 +14,9 @@
#include "cmCPackLog.h"
#include "cmSystemTools.h"
-cmCPackRPMGenerator::cmCPackRPMGenerator()
-{
-}
+cmCPackRPMGenerator::cmCPackRPMGenerator() = default;
-cmCPackRPMGenerator::~cmCPackRPMGenerator()
-{
-}
+cmCPackRPMGenerator::~cmCPackRPMGenerator() = default;
int cmCPackRPMGenerator::InitializeInternal()
{
@@ -89,9 +85,9 @@ int cmCPackRPMGenerator::PackageOnePack(std::string const& initialToplevel,
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);
+ if (!this->ReadListFile("Internal/CPack/CPackRPM.cmake")) {
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackRPM.cmake" << std::endl);
retval = 0;
}
@@ -148,7 +144,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
for (compIt = this->Components.begin();
compIt != this->Components.end(); ++compIt) {
// Does the component belong to a group?
- if (compIt->second.Group == CM_NULLPTR) {
+ if (compIt->second.Group == nullptr) {
std::string component(compIt->first);
std::transform(component.begin(), component.end(),
component.begin(), ::toupper);
@@ -165,7 +161,8 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
}
if (shouldSet) {
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Setting "
+ cmCPackLogger(cmCPackLog::LOG_VERBOSE,
+ "Setting "
<< "CPACK_RPM_DEBUGINFO_PACKAGE because "
<< "CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is set but "
<< " none of the "
@@ -203,8 +200,9 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
continue;
}
- cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Packaging component group: "
- << compGIt->first << std::endl);
+ 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)
@@ -214,7 +212,7 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
for (compIt = this->Components.begin(); compIt != this->Components.end();
++compIt) {
// Does the component belong to a group?
- if (compIt->second.Group == CM_NULLPTR) {
+ if (compIt->second.Group == nullptr) {
std::string component(compIt->first);
std::transform(component.begin(), component.end(), component.begin(),
::toupper);
@@ -226,7 +224,8 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
}
cmCPackLogger(
- cmCPackLog::LOG_VERBOSE, "Component <"
+ cmCPackLog::LOG_VERBOSE,
+ "Component <"
<< compIt->second.Name
<< "> does not belong to any group, package it separately."
<< std::endl);
@@ -242,7 +241,8 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
} else if (mainCompIt != this->Components.end()) {
retval &= PackageOnePack(initialTopLevel, mainCompIt->first);
} else {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT set"
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_RPM_MAIN_COMPONENT set"
<< " to non existing component.\n");
retval = 0;
}
@@ -276,7 +276,8 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
if (mainCompIt != this->Components.end()) {
retval &= PackageOnePack(initialTopLevel, mainCompIt->first);
} else {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT set"
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "CPACK_RPM_MAIN_COMPONENT set"
<< " to non existing component.\n");
retval = 0;
}
@@ -290,8 +291,9 @@ int cmCPackRPMGenerator::PackageComponents(bool 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);
+ 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)
@@ -299,9 +301,10 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
for (compIt = this->Components.begin(); compIt != this->Components.end();
++compIt) {
// Does the component belong to a group?
- if (compIt->second.Group == CM_NULLPTR) {
+ if (compIt->second.Group == nullptr) {
cmCPackLogger(
- cmCPackLog::LOG_VERBOSE, "Component <"
+ cmCPackLog::LOG_VERBOSE,
+ "Component <"
<< compIt->second.Name
<< "> does not belong to any group, package it separately."
<< std::endl);
@@ -320,7 +323,8 @@ int cmCPackRPMGenerator::PackageComponents(bool ignoreGroup)
}
} else {
cmCPackLogger(
- cmCPackLog::LOG_ERROR, "CPACK_RPM_MAIN_COMPONENT not set but"
+ cmCPackLog::LOG_ERROR,
+ "CPACK_RPM_MAIN_COMPONENT not set but"
<< " it is mandatory with CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE"
<< " being set.\n");
retval = 0;
@@ -377,11 +381,11 @@ int cmCPackRPMGenerator::PackageComponentsAllInOne(
component_path.c_str());
}
- if (this->ReadListFile("CPackRPM.cmake")) {
+ if (this->ReadListFile("Internal/CPack/CPackRPM.cmake")) {
AddGeneratedPackageNames();
} else {
- cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake"
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_ERROR,
+ "Error while execution CPackRPM.cmake" << std::endl);
retval = 0;
}
@@ -430,7 +434,7 @@ std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix(
// the current COMPONENT belongs to.
std::string groupVar =
"CPACK_COMPONENT_" + cmSystemTools::UpperCase(componentName) + "_GROUP";
- if (CM_NULLPTR != GetOption(groupVar)) {
+ if (nullptr != GetOption(groupVar)) {
return std::string(GetOption(groupVar));
}
return componentName;
diff --git a/Source/CPack/cmCPackRPMGenerator.h b/Source/CPack/cmCPackRPMGenerator.h
index 52cfc13ed..27d3b6339 100644
--- a/Source/CPack/cmCPackRPMGenerator.h
+++ b/Source/CPack/cmCPackRPMGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackRPMGenerator_h
#define cmCPackRPMGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackGenerator.h"
@@ -26,7 +26,7 @@ public:
* Construct generator
*/
cmCPackRPMGenerator();
- ~cmCPackRPMGenerator() CM_OVERRIDE;
+ ~cmCPackRPMGenerator() override;
static bool CanGenerate()
{
@@ -43,8 +43,8 @@ public:
}
protected:
- int InitializeInternal() CM_OVERRIDE;
- int PackageFiles() CM_OVERRIDE;
+ int InitializeInternal() override;
+ int PackageFiles() override;
/**
* This method factors out the work done in component packaging case.
*/
@@ -61,10 +61,10 @@ protected:
* components will be put in a single installer.
*/
int PackageComponentsAllInOne(const std::string& compInstDirName);
- const char* GetOutputExtension() CM_OVERRIDE { return ".rpm"; }
- bool SupportsComponentInstallation() const CM_OVERRIDE;
+ const char* GetOutputExtension() override { return ".rpm"; }
+ bool SupportsComponentInstallation() const override;
std::string GetComponentInstallDirNameSuffix(
- const std::string& componentName) CM_OVERRIDE;
+ const std::string& componentName) override;
void AddGeneratedPackageNames();
};
diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx
index c54161426..aba15d239 100644
--- a/Source/CPack/cmCPackSTGZGenerator.cxx
+++ b/Source/CPack/cmCPackSTGZGenerator.cxx
@@ -13,13 +13,9 @@
#include "cmSystemTools.h"
#include "cm_sys_stat.h"
-cmCPackSTGZGenerator::cmCPackSTGZGenerator()
-{
-}
+cmCPackSTGZGenerator::cmCPackSTGZGenerator() = default;
-cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
-{
-}
+cmCPackSTGZGenerator::~cmCPackSTGZGenerator() = default;
int cmCPackSTGZGenerator::InitializeInternal()
{
@@ -48,9 +44,8 @@ int cmCPackSTGZGenerator::PackageFiles()
* 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(),
+ for (std::string const& pfn : packageFileNames) {
+ retval &= cmSystemTools::SetPermissions(pfn.c_str(),
#if defined(_MSC_VER) || defined(__MINGW32__)
S_IREAD | S_IWRITE | S_IEXEC
#else
@@ -58,7 +53,7 @@ int cmCPackSTGZGenerator::PackageFiles()
S_IRGRP | S_IWGRP | S_IXGRP |
S_IROTH | S_IWOTH | S_IXOTH
#endif
- );
+ );
}
return retval;
}
@@ -102,8 +97,8 @@ int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
++ptr;
}
counter++;
- cmCPackLogger(cmCPackLog::LOG_DEBUG, "Number of lines: " << counter
- << std::endl);
+ cmCPackLogger(cmCPackLog::LOG_DEBUG,
+ "Number of lines: " << counter << std::endl);
char buffer[1024];
sprintf(buffer, "%d", counter);
cmSystemTools::ReplaceString(res, headerLengthTag, buffer);
diff --git a/Source/CPack/cmCPackSTGZGenerator.h b/Source/CPack/cmCPackSTGZGenerator.h
index 8304e8076..9cf184b19 100644
--- a/Source/CPack/cmCPackSTGZGenerator.h
+++ b/Source/CPack/cmCPackSTGZGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackSTGZGenerator_h
#define cmCPackSTGZGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackGenerator.h"
#include "cmCPackTGZGenerator.h"
@@ -23,13 +23,13 @@ public:
* Construct generator
*/
cmCPackSTGZGenerator();
- ~cmCPackSTGZGenerator() CM_OVERRIDE;
+ ~cmCPackSTGZGenerator() override;
protected:
- int PackageFiles() CM_OVERRIDE;
- int InitializeInternal() CM_OVERRIDE;
- int GenerateHeader(std::ostream* os) CM_OVERRIDE;
- const char* GetOutputExtension() CM_OVERRIDE { return ".sh"; }
+ int PackageFiles() override;
+ int InitializeInternal() override;
+ int GenerateHeader(std::ostream* os) override;
+ const char* GetOutputExtension() override { return ".sh"; }
};
#endif
diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx
index eaf8186fe..6f4676ef9 100644
--- a/Source/CPack/cmCPackTGZGenerator.cxx
+++ b/Source/CPack/cmCPackTGZGenerator.cxx
@@ -10,6 +10,4 @@ cmCPackTGZGenerator::cmCPackTGZGenerator()
{
}
-cmCPackTGZGenerator::~cmCPackTGZGenerator()
-{
-}
+cmCPackTGZGenerator::~cmCPackTGZGenerator() = default;
diff --git a/Source/CPack/cmCPackTGZGenerator.h b/Source/CPack/cmCPackTGZGenerator.h
index 9426b3a01..7be3d9d33 100644
--- a/Source/CPack/cmCPackTGZGenerator.h
+++ b/Source/CPack/cmCPackTGZGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackTGZGenerator_h
#define cmCPackTGZGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackArchiveGenerator.h"
#include "cmCPackGenerator.h"
@@ -20,10 +20,10 @@ public:
* Construct generator
*/
cmCPackTGZGenerator();
- ~cmCPackTGZGenerator() CM_OVERRIDE;
+ ~cmCPackTGZGenerator() override;
protected:
- const char* GetOutputExtension() CM_OVERRIDE { return ".tar.gz"; }
+ const char* GetOutputExtension() override { return ".tar.gz"; }
};
#endif
diff --git a/Source/CPack/cmCPackTXZGenerator.cxx b/Source/CPack/cmCPackTXZGenerator.cxx
index e55e903e9..ccbccde95 100644
--- a/Source/CPack/cmCPackTXZGenerator.cxx
+++ b/Source/CPack/cmCPackTXZGenerator.cxx
@@ -10,6 +10,4 @@ cmCPackTXZGenerator::cmCPackTXZGenerator()
{
}
-cmCPackTXZGenerator::~cmCPackTXZGenerator()
-{
-}
+cmCPackTXZGenerator::~cmCPackTXZGenerator() = default;
diff --git a/Source/CPack/cmCPackTXZGenerator.h b/Source/CPack/cmCPackTXZGenerator.h
index 3b96e2d78..4aa59730e 100644
--- a/Source/CPack/cmCPackTXZGenerator.h
+++ b/Source/CPack/cmCPackTXZGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackTXZGenerator_h
#define cmCPackTXZGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackArchiveGenerator.h"
#include "cmCPackGenerator.h"
@@ -20,10 +20,10 @@ public:
* Construct generator
*/
cmCPackTXZGenerator();
- ~cmCPackTXZGenerator() CM_OVERRIDE;
+ ~cmCPackTXZGenerator() override;
protected:
- const char* GetOutputExtension() CM_OVERRIDE { return ".tar.xz"; }
+ const char* GetOutputExtension() override { return ".tar.xz"; }
};
#endif
diff --git a/Source/CPack/cmCPackTarBZip2Generator.cxx b/Source/CPack/cmCPackTarBZip2Generator.cxx
index c7a3dd429..85abeb1ca 100644
--- a/Source/CPack/cmCPackTarBZip2Generator.cxx
+++ b/Source/CPack/cmCPackTarBZip2Generator.cxx
@@ -10,6 +10,4 @@ cmCPackTarBZip2Generator::cmCPackTarBZip2Generator()
{
}
-cmCPackTarBZip2Generator::~cmCPackTarBZip2Generator()
-{
-}
+cmCPackTarBZip2Generator::~cmCPackTarBZip2Generator() = default;
diff --git a/Source/CPack/cmCPackTarBZip2Generator.h b/Source/CPack/cmCPackTarBZip2Generator.h
index 9b4b8f4ff..7975ddaee 100644
--- a/Source/CPack/cmCPackTarBZip2Generator.h
+++ b/Source/CPack/cmCPackTarBZip2Generator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackTarBZip2Generator_h
#define cmCPackTarBZip2Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackArchiveGenerator.h"
#include "cmCPackGenerator.h"
@@ -19,10 +19,10 @@ public:
* Construct generator
*/
cmCPackTarBZip2Generator();
- ~cmCPackTarBZip2Generator() CM_OVERRIDE;
+ ~cmCPackTarBZip2Generator() override;
protected:
- const char* GetOutputExtension() CM_OVERRIDE { return ".tar.bz2"; }
+ const char* GetOutputExtension() override { return ".tar.bz2"; }
};
#endif
diff --git a/Source/CPack/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx
index 0a7cd978c..55a6de53c 100644
--- a/Source/CPack/cmCPackTarCompressGenerator.cxx
+++ b/Source/CPack/cmCPackTarCompressGenerator.cxx
@@ -10,6 +10,4 @@ cmCPackTarCompressGenerator::cmCPackTarCompressGenerator()
{
}
-cmCPackTarCompressGenerator::~cmCPackTarCompressGenerator()
-{
-}
+cmCPackTarCompressGenerator::~cmCPackTarCompressGenerator() = default;
diff --git a/Source/CPack/cmCPackTarCompressGenerator.h b/Source/CPack/cmCPackTarCompressGenerator.h
index 381d6eb2f..37c7f48c8 100644
--- a/Source/CPack/cmCPackTarCompressGenerator.h
+++ b/Source/CPack/cmCPackTarCompressGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackTarCompressGenerator_h
#define cmCPackTarCompressGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackArchiveGenerator.h"
#include "cmCPackGenerator.h"
@@ -19,10 +19,10 @@ public:
* Construct generator
*/
cmCPackTarCompressGenerator();
- ~cmCPackTarCompressGenerator() CM_OVERRIDE;
+ ~cmCPackTarCompressGenerator() override;
protected:
- const char* GetOutputExtension() CM_OVERRIDE { return ".tar.Z"; }
+ const char* GetOutputExtension() override { return ".tar.Z"; }
};
#endif
diff --git a/Source/CPack/cmCPackZIPGenerator.cxx b/Source/CPack/cmCPackZIPGenerator.cxx
index 6b77c363d..f06494c44 100644
--- a/Source/CPack/cmCPackZIPGenerator.cxx
+++ b/Source/CPack/cmCPackZIPGenerator.cxx
@@ -10,6 +10,4 @@ cmCPackZIPGenerator::cmCPackZIPGenerator()
{
}
-cmCPackZIPGenerator::~cmCPackZIPGenerator()
-{
-}
+cmCPackZIPGenerator::~cmCPackZIPGenerator() = default;
diff --git a/Source/CPack/cmCPackZIPGenerator.h b/Source/CPack/cmCPackZIPGenerator.h
index 00c872029..58ec79ef1 100644
--- a/Source/CPack/cmCPackZIPGenerator.h
+++ b/Source/CPack/cmCPackZIPGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackZIPGenerator_h
#define cmCPackZIPGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCPackArchiveGenerator.h"
#include "cmCPackGenerator.h"
@@ -20,10 +20,10 @@ public:
* Construct generator
*/
cmCPackZIPGenerator();
- ~cmCPackZIPGenerator() CM_OVERRIDE;
+ ~cmCPackZIPGenerator() override;
protected:
- const char* GetOutputExtension() CM_OVERRIDE { return ".zip"; }
+ const char* GetOutputExtension() override { return ".zip"; }
};
#endif
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx
index a44bc3d68..58b9e70fa 100644
--- a/Source/CPack/cpack.cxx
+++ b/Source/CPack/cpack.cxx
@@ -1,11 +1,11 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
-#include "cmConfigure.h"
#include "cmsys/CommandLineArguments.hxx"
#include "cmsys/Encoding.hxx"
#include <iostream>
#include <map>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stddef.h>
#include <string>
@@ -13,7 +13,7 @@
#include <vector>
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmsys/ConsoleBuf.hxx"
+# include "cmsys/ConsoleBuf.hxx"
#endif
#include "cmCPackGenerator.h"
@@ -21,35 +21,40 @@
#include "cmCPackLog.h"
#include "cmDocumentation.h"
#include "cmDocumentationEntry.h"
+#include "cmDocumentationFormatter.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
static const char* cmDocumentationName[][2] = {
- { CM_NULLPTR, " cpack - Packaging driver provided by CMake." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, " cpack - Packaging driver provided by CMake." },
+ { nullptr, nullptr }
};
static const char* cmDocumentationUsage[][2] = {
- { CM_NULLPTR, " cpack -G <generator> [options]" },
- { CM_NULLPTR, CM_NULLPTR }
+ // clang-format off
+ { nullptr, " cpack [options]" },
+ { nullptr, nullptr }
+ // clang-format on
};
static const char* cmDocumentationOptions[][2] = {
- { "-G <generator>", "Use the specified generator to generate package." },
+ { "-G <generators>", "Override/define CPACK_GENERATOR" },
{ "-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" },
- { CM_NULLPTR, CM_NULLPTR }
+ { "--config <configFile>", "Specify the config file." },
+ { "--verbose,-V", "Enable verbose output" },
+ { "--trace", "Put underlying cmake scripts in trace mode." },
+ { "--trace-expand", "Put underlying cmake scripts in expanded trace mode." },
+ { "--debug", "Enable debug output (for CPack developers)" },
+ { "-P <packageName>", "Override/define CPACK_PACKAGE_NAME" },
+ { "-R <packageVersion>", "Override/define CPACK_PACKAGE_VERSION" },
+ { "-B <packageDirectory>", "Override/define CPACK_PACKAGE_DIRECTORY" },
+ { "--vendor <vendorName>", "Override/define CPACK_PACKAGE_VENDOR" },
+ { nullptr, nullptr }
};
int cpackUnknownArgument(const char* /*unused*/, void* /*unused*/)
@@ -77,16 +82,23 @@ int cpackDefinitionArgument(const char* argument, const char* cValue,
return 0;
}
std::string key = value.substr(0, pos);
- value = value.c_str() + pos + 1;
+ value = value.substr(pos + 1);
def->Map[key] = value;
- cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: "
- << key << " to \"" << value << "\"" << std::endl);
+ cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG,
+ "Set CPack variable: " << key << " to \"" << value << "\""
+ << std::endl);
return 1;
}
+static void cpackProgressCallback(const std::string& message, float /*unused*/)
+{
+ std::cout << "-- " << message << std::endl;
+}
+
// this is CPack.
int main(int argc, char const* const* argv)
{
+ cmSystemTools::EnsureStdPipes();
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
// Replace streambuf so we can output Unicode to console
cmsys::ConsoleBuf::Manager consoleOut(std::cout);
@@ -99,6 +111,8 @@ int main(int argc, char const* const* argv)
argc = args.argc();
argv = args.argv();
+ cmSystemTools::EnableMSVCDebugHook();
+ cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv[0]);
cmCPackLog log;
@@ -107,8 +121,6 @@ int main(int argc, char const* const* argv)
log.SetOutputPrefix("CPack: ");
log.SetVerbosePrefix("CPack Verbose: ");
- cmSystemTools::EnableMSVCDebugHook();
-
if (cmSystemTools::GetCurrentWorkingDirectory().empty()) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Current working directory cannot be established."
@@ -120,6 +132,8 @@ int main(int argc, char const* const* argv)
bool help = false;
bool helpVersion = false;
bool verbose = false;
+ bool trace = false;
+ bool traceExpand = false;
bool debug = false;
std::string helpFull;
std::string helpMAN;
@@ -136,7 +150,7 @@ int main(int argc, char const* const* argv)
cpackDefinitions definitions;
definitions.Log = &log;
- cpackConfigFile = "";
+ cpackConfigFile.clear();
cmsys::CommandLineArguments arg;
arg.Initialize(argc, argv);
@@ -155,6 +169,10 @@ int main(int argc, char const* const* argv)
arg.AddArgument("--debug", argT::NO_ARGUMENT, &debug, "-V");
arg.AddArgument("--config", argT::SPACE_ARGUMENT, &cpackConfigFile,
"CPack configuration file");
+ arg.AddArgument("--trace", argT::NO_ARGUMENT, &trace,
+ "Put underlying cmake scripts in trace mode.");
+ arg.AddArgument("--trace-expand", argT::NO_ARGUMENT, &traceExpand,
+ "Put underlying cmake scripts in expanded trace mode.");
arg.AddArgument("-C", argT::SPACE_ARGUMENT, &cpackBuildConfig,
"CPack build configuration");
arg.AddArgument("-G", argT::SPACE_ARGUMENT, &generator, "CPack generator");
@@ -188,17 +206,25 @@ int main(int argc, char const* const* argv)
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Read CPack config file: " << cpackConfigFile << std::endl);
- cmake cminst(cmake::RoleScript);
+ cmake cminst(cmake::RoleScript, cmState::CPack);
cminst.SetHomeDirectory("");
cminst.SetHomeOutputDirectory("");
+ cminst.SetProgressCallback(cpackProgressCallback);
cminst.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator cmgg(&cminst);
- CM_AUTO_PTR<cmMakefile> globalMF(
- new cmMakefile(&cmgg, cminst.GetCurrentSnapshot()));
+ cmMakefile globalMF(&cmgg, cminst.GetCurrentSnapshot());
#if defined(__CYGWIN__)
- globalMF->AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0");
+ globalMF.AddDefinition("CMAKE_LEGACY_CYGWIN_WIN32", "0");
#endif
+ if (trace) {
+ cminst.SetTrace(true);
+ }
+ if (traceExpand) {
+ cminst.SetTrace(true);
+ cminst.SetTraceExpand(true);
+ }
+
bool cpackConfigFileSpecified = true;
if (cpackConfigFile.empty()) {
cpackConfigFile = cmSystemTools::GetCurrentWorkingDirectory();
@@ -208,7 +234,7 @@ int main(int argc, char const* const* argv)
cmCPackGeneratorFactory generators;
generators.SetLogger(&log);
- cmCPackGenerator* cpackGenerator = CM_NULLPTR;
+ cmCPackGenerator* cpackGenerator = nullptr;
cmDocumentation doc;
doc.addCPackStandardDocSections();
@@ -226,16 +252,16 @@ int main(int argc, char const* const* argv)
// 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(systemFile.c_str())) {
+ globalMF.GetModulesFile("CMakeDetermineSystem.cmake");
+ if (!globalMF.ReadListFile(systemFile)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Error reading CMakeDetermineSystem.cmake" << std::endl);
return 1;
}
systemFile =
- globalMF->GetModulesFile("CMakeSystemSpecificInformation.cmake");
- if (!globalMF->ReadListFile(systemFile.c_str())) {
+ globalMF.GetModulesFile("CMakeSystemSpecificInformation.cmake");
+ if (!globalMF.ReadListFile(systemFile)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Error reading CMakeSystemSpecificInformation.cmake"
<< std::endl);
@@ -243,15 +269,15 @@ int main(int argc, char const* const* argv)
}
if (!cpackBuildConfig.empty()) {
- globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
+ globalMF.AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
}
- if (cmSystemTools::FileExists(cpackConfigFile.c_str())) {
+ if (cmSystemTools::FileExists(cpackConfigFile)) {
cpackConfigFile = cmSystemTools::CollapseFullPath(cpackConfigFile);
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Read CPack configuration file: " << cpackConfigFile
<< std::endl);
- if (!globalMF->ReadListFile(cpackConfigFile.c_str())) {
+ if (!globalMF.ReadListFile(cpackConfigFile)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Problem reading CPack config file: \""
<< cpackConfigFile << "\"" << std::endl);
@@ -265,58 +291,53 @@ int main(int argc, char const* const* argv)
}
if (!generator.empty()) {
- globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str());
+ globalMF.AddDefinition("CPACK_GENERATOR", generator.c_str());
}
if (!cpackProjectName.empty()) {
- globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
+ globalMF.AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
}
if (!cpackProjectVersion.empty()) {
- globalMF->AddDefinition("CPACK_PACKAGE_VERSION",
- cpackProjectVersion.c_str());
+ globalMF.AddDefinition("CPACK_PACKAGE_VERSION",
+ cpackProjectVersion.c_str());
}
if (!cpackProjectVendor.empty()) {
- globalMF->AddDefinition("CPACK_PACKAGE_VENDOR",
- cpackProjectVendor.c_str());
+ 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());
+ 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());
+ 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());
+ for (auto const& cd : definitions.Map) {
+ globalMF.AddDefinition(cd.first, cd.second.c_str());
}
- const char* cpackModulesPath =
- globalMF->GetDefinition("CPACK_MODULE_PATH");
+ const char* cpackModulesPath = globalMF.GetDefinition("CPACK_MODULE_PATH");
if (cpackModulesPath) {
- globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath);
+ globalMF.AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath);
}
- const char* genList = globalMF->GetDefinition("CPACK_GENERATOR");
+ const char* genList = globalMF.GetDefinition("CPACK_GENERATOR");
if (!genList) {
- cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack generator not specified"
- << std::endl);
+ 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::ScopePushPop raii(globalMF.get());
- cmMakefile* mf = globalMF.get();
+ for (std::string const& gen : generatorsVector) {
+ cmMakefile::ScopePushPop raii(&globalMF);
+ cmMakefile* mf = &globalMF;
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"Specified generator: " << gen << std::endl);
if (parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME")) {
@@ -341,12 +362,29 @@ int main(int argc, char const* const* argv)
}
if (parsed) {
cpackGenerator = generators.NewGenerator(gen);
- if (!cpackGenerator) {
+ if (cpackGenerator) {
+ cpackGenerator->SetTrace(trace);
+ cpackGenerator->SetTraceExpand(traceExpand);
+ } else {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
- "Cannot initialize CPack generator: " << gen
- << std::endl);
+ "Could not create CPack generator: " << gen
+ << std::endl);
+ // Print out all the valid generators
+ cmDocumentation generatorDocs;
+ std::vector<cmDocumentationEntry> v;
+ for (auto const& g : generators.GetGeneratorsList()) {
+ cmDocumentationEntry e;
+ e.Name = g.first;
+ e.Brief = g.second;
+ v.push_back(std::move(e));
+ }
+ generatorDocs.SetSection("Generators", v);
+ std::cerr << "\n";
+ generatorDocs.PrintDocumentation(cmDocumentation::ListGenerators,
+ std::cerr);
parsed = 0;
}
+
if (parsed && !cpackGenerator->Initialize(gen, mf)) {
cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
"Cannot initialize the generator " << gen
@@ -355,21 +393,23 @@ int main(int argc, char const* const* argv)
}
if (!mf->GetDefinition("CPACK_INSTALL_COMMANDS") &&
+ !mf->GetDefinition("CPACK_INSTALL_SCRIPT") &&
!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_INSTALL_COMMANDS, CPACK_INSTALL_SCRIPT, or "
"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,
+ "Use generator: " << cpackGenerator->GetNameOfClass()
+ << std::endl);
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
"For project: " << projName << std::endl);
@@ -414,13 +454,11 @@ int main(int argc, char const* const* argv)
doc.PrependSection("Options", cmDocumentationOptions);
std::vector<cmDocumentationEntry> v;
- cmCPackGeneratorFactory::DescriptionsMap::const_iterator generatorIt;
- for (generatorIt = generators.GetGeneratorsList().begin();
- generatorIt != generators.GetGeneratorsList().end(); ++generatorIt) {
+ for (auto const& g : generators.GetGeneratorsList()) {
cmDocumentationEntry e;
- e.Name = generatorIt->first;
- e.Brief = generatorIt->second;
- v.push_back(e);
+ e.Name = g.first;
+ e.Brief = g.second;
+ v.push_back(std::move(e));
}
doc.SetSection("Generators", v);
diff --git a/Source/CTest/cmCTestBZR.cxx b/Source/CTest/cmCTestBZR.cxx
index 94f39c265..b957856e8 100644
--- a/Source/CTest/cmCTestBZR.cxx
+++ b/Source/CTest/cmCTestBZR.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestBZR.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestVC.h"
#include "cmProcessTools.h"
@@ -77,9 +78,7 @@ cmCTestBZR::cmCTestBZR(cmCTest* ct, std::ostream& log)
cmSystemTools::PutEnv("BZR_PROGRESS_BAR=none");
}
-cmCTestBZR::~cmCTestBZR()
-{
-}
+cmCTestBZR::~cmCTestBZR() = default;
class cmCTestBZR::InfoParser : public cmCTestVC::LineParser
{
@@ -98,7 +97,7 @@ private:
bool CheckOutFound;
cmsys::RegularExpression RegexCheckOut;
cmsys::RegularExpression RegexParent;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexCheckOut.find(this->Line)) {
this->BZR->URL = this->RegexCheckOut.match(1);
@@ -123,7 +122,7 @@ public:
private:
std::string& Rev;
cmsys::RegularExpression RegexRevno;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexRevno.find(this->Line)) {
this->Rev = this->RegexRevno.match(1);
@@ -136,13 +135,13 @@ 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", CM_NULLPTR };
+ const char* bzr_info[] = { bzr, "info", nullptr };
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", CM_NULLPTR };
+ const char* bzr_revno[] = { bzr, "revno", nullptr };
std::string rev;
RevnoParser rout(this, "revno-out> ", rev);
OutputLogger rerr(this->Log, "revno-err> ");
@@ -155,8 +154,9 @@ bool 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");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Old revision of repository is: " << this->OldRevision
+ << "\n");
this->PriorRev.Rev = this->OldRevision;
return true;
}
@@ -165,14 +165,16 @@ bool 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");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " New revision of repository is: " << this->NewRevision
+ << "\n");
this->Log << "URL = " << this->URL << "\n";
return true;
}
-class cmCTestBZR::LogParser : public cmCTestVC::OutputLogger,
- private cmXMLParser
+class cmCTestBZR::LogParser
+ : public cmCTestVC::OutputLogger
+ , private cmXMLParser
{
public:
LogParser(cmCTestBZR* bzr, const char* prefix)
@@ -182,15 +184,15 @@ public:
{
this->InitializeParser();
}
- ~LogParser() CM_OVERRIDE { this->CleanupParser(); }
+ ~LogParser() override { this->CleanupParser(); }
- int InitializeParser() CM_OVERRIDE
+ int InitializeParser() override
{
int res = cmXMLParser::InitializeParser();
if (res) {
XML_SetUnknownEncodingHandler(static_cast<XML_Parser>(this->Parser),
cmBZRXMLParserUnknownEncodingHandler,
- CM_NULLPTR);
+ nullptr);
}
return res;
}
@@ -207,14 +209,14 @@ private:
cmsys::RegularExpression EmailRegex;
- bool ProcessChunk(const char* data, int length) CM_OVERRIDE
+ bool ProcessChunk(const char* data, int length) override
{
this->OutputLogger::ProcessChunk(data, length);
this->ParseChunk(data, length);
return true;
}
- void StartElement(const std::string& name, const char** /*atts*/) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** /*atts*/) override
{
this->CData.clear();
if (name == "log") {
@@ -239,12 +241,12 @@ private:
}
}
- void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
+ void CharacterDataHandler(const char* data, int length) override
{
- this->CData.insert(this->CData.end(), data, data + length);
+ cmAppend(this->CData, data, data + length);
}
- void EndElement(const std::string& name) CM_OVERRIDE
+ void EndElement(const std::string& name) override
{
if (name == "log") {
this->BZR->DoRevision(this->Rev, this->Changes);
@@ -274,7 +276,7 @@ private:
this->CData.clear();
}
- void ReportError(int /*line*/, int /*column*/, const char* msg) CM_OVERRIDE
+ void ReportError(int /*line*/, int /*column*/, const char* msg) override
{
this->BZR->Log << "Error parsing bzr log xml: " << msg << "\n";
}
@@ -294,7 +296,7 @@ private:
cmCTestBZR* BZR;
cmsys::RegularExpression RegexUpdate;
- bool ProcessChunk(const char* first, int length) CM_OVERRIDE
+ bool ProcessChunk(const char* first, int length) override
{
bool last_is_new_line = (*first == '\r' || *first == '\n');
@@ -309,11 +311,11 @@ private:
// Hand this line to the subclass implementation.
if (!this->ProcessLine()) {
- this->Line = "";
+ this->Line.clear();
return false;
}
- this->Line = "";
+ this->Line.clear();
last_is_new_line = true;
}
} else {
@@ -325,7 +327,7 @@ private:
return true;
}
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexUpdate.find(this->Line)) {
this->DoPath(this->RegexUpdate.match(1)[0],
@@ -364,7 +366,7 @@ bool cmCTestBZR::UpdateImpl()
if (opts.empty()) {
opts = this->CTest->GetCTestConfiguration("BZRUpdateOptions");
}
- std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
// TODO: if(this->CTest->GetTestModel() == cmCTest::NIGHTLY)
@@ -373,14 +375,13 @@ bool cmCTestBZR::UpdateImpl()
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());
+ for (std::string const& arg : args) {
+ bzr_update.push_back(arg.c_str());
}
bzr_update.push_back(this->URL.c_str());
- bzr_update.push_back(CM_NULLPTR);
+ bzr_update.push_back(nullptr);
// For some reason bzr uses stderr to display the update status.
OutputLogger out(this->Log, "pull-out> ");
@@ -408,8 +409,7 @@ bool cmCTestBZR::LoadRevisions()
// 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(),
- CM_NULLPTR
+ bzr, "log", "-v", "-r", revs.c_str(), "--xml", this->URL.c_str(), nullptr
};
{
LogParser out(this, "log-out> ");
@@ -433,7 +433,7 @@ public:
private:
cmCTestBZR* BZR;
cmsys::RegularExpression RegexStatus;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexStatus.find(this->Line)) {
this->DoPath(this->RegexStatus.match(1)[0],
@@ -467,7 +467,7 @@ bool cmCTestBZR::LoadModifications()
{
// Run "bzr status" which reports local modifications.
const char* bzr = this->CommandLineTool.c_str();
- const char* bzr_status[] = { bzr, "status", "-SV", CM_NULLPTR };
+ const char* bzr_status[] = { bzr, "status", "-SV", nullptr };
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
index 2e8e88f95..d5c78c760 100644
--- a/Source/CTest/cmCTestBZR.h
+++ b/Source/CTest/cmCTestBZR.h
@@ -3,7 +3,7 @@
#ifndef cmCTestBZR_h
#define cmCTestBZR_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGlobalVC.h"
@@ -22,20 +22,20 @@ public:
/** Construct with a CTest instance and update log stream. */
cmCTestBZR(cmCTest* ctest, std::ostream& log);
- ~cmCTestBZR() CM_OVERRIDE;
+ ~cmCTestBZR() override;
private:
// Implement cmCTestVC internal API.
- bool NoteOldRevision() CM_OVERRIDE;
- bool NoteNewRevision() CM_OVERRIDE;
- bool UpdateImpl() CM_OVERRIDE;
+ bool NoteOldRevision() override;
+ bool NoteNewRevision() override;
+ bool UpdateImpl() override;
// URL of repository directory checked out in the working tree.
std::string URL;
std::string LoadInfo();
- bool LoadModifications() CM_OVERRIDE;
- bool LoadRevisions() CM_OVERRIDE;
+ bool LoadModifications() override;
+ bool LoadRevisions() override;
// Parsing helper classes.
class InfoParser;
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.cxx b/Source/CTest/cmCTestBuildAndTestHandler.cxx
index cc290715c..9ad96699b 100644
--- a/Source/CTest/cmCTestBuildAndTestHandler.cxx
+++ b/Source/CTest/cmCTestBuildAndTestHandler.cxx
@@ -5,11 +5,16 @@
#include "cmCTest.h"
#include "cmCTestTestHandler.h"
#include "cmGlobalGenerator.h"
+#include "cmMakefile.h"
+#include "cmState.h"
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
#include "cmake.h"
#include "cmsys/Process.h"
+#include <chrono>
+#include <cstring>
+#include <ratio>
#include <stdlib.h>
cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
@@ -17,7 +22,7 @@ cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
this->BuildTwoConfig = false;
this->BuildNoClean = false;
this->BuildNoCMake = false;
- this->Timeout = 0;
+ this->Timeout = cmDuration::zero();
}
void cmCTestBuildAndTestHandler::Initialize()
@@ -32,7 +37,7 @@ const char* cmCTestBuildAndTestHandler::GetOutput()
}
int cmCTestBuildAndTestHandler::ProcessHandler()
{
- this->Output = "";
+ this->Output.clear();
std::string output;
cmSystemTools::ResetErrorOccuredFlag();
int retv = this->RunCMakeAndTest(&this->Output);
@@ -45,27 +50,20 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
std::string& cmakeOutString,
cmake* cm)
{
- unsigned int k;
std::vector<std::string> args;
args.push_back(cmSystemTools::GetCMakeCommand());
args.push_back(this->SourceDir);
if (!this->BuildGenerator.empty()) {
- std::string generator = "-G";
- generator += this->BuildGenerator;
- args.push_back(generator);
+ args.push_back("-G" + this->BuildGenerator);
}
if (!this->BuildGeneratorPlatform.empty()) {
- std::string platform = "-A";
- platform += this->BuildGeneratorPlatform;
- args.push_back(platform);
+ args.push_back("-A" + this->BuildGeneratorPlatform);
}
if (!this->BuildGeneratorToolset.empty()) {
- std::string toolset = "-T";
- toolset += this->BuildGeneratorToolset;
- args.push_back(toolset);
+ args.push_back("-T" + this->BuildGeneratorToolset);
}
- const char* config = CM_NULLPTR;
+ const char* config = nullptr;
if (!this->CTest->GetConfigType().empty()) {
config = this->CTest->GetConfigType().c_str();
}
@@ -76,12 +74,11 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
#endif
if (config) {
- std::string btype = "-DCMAKE_BUILD_TYPE:STRING=" + std::string(config);
- args.push_back(btype);
+ args.push_back("-DCMAKE_BUILD_TYPE:STRING=" + std::string(config));
}
- for (k = 0; k < this->BuildOptions.size(); ++k) {
- args.push_back(this->BuildOptions[k]);
+ for (std::string const& opt : this->BuildOptions) {
+ args.push_back(opt);
}
if (cm->Run(args) != 0) {
out << "Error: cmake execution failed\n";
@@ -112,27 +109,6 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
return 0;
}
-void CMakeMessageCallback(const char* m, const char* /*unused*/,
- bool& /*unused*/, void* s)
-{
- std::string* out = (std::string*)s;
- *out += m;
- *out += "\n";
-}
-
-void CMakeProgressCallback(const char* msg, float /*unused*/, 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;
@@ -141,18 +117,35 @@ 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);
+ cmSystemTools::SetMessageCallback(
+ [&s](const std::string& msg, const char* /*unused*/) {
+ s += msg;
+ s += "\n";
+ });
+
+ cmSystemTools::SetStdoutCallback([&s](std::string const& m) { s += m; });
+ cmSystemTools::SetStderrCallback([&s](std::string const& m) { s += m; });
+
+ this->CM.SetProgressCallback([&s](const std::string& msg, float prog) {
+ if (prog < 0) {
+ s += msg;
+ s += "\n";
+ }
+ });
}
+
~cmCTestBuildAndTestCaptureRAII()
{
- this->CM.SetProgressCallback(CM_NULLPTR, CM_NULLPTR);
- cmSystemTools::SetStderrCallback(CM_NULLPTR, CM_NULLPTR);
- cmSystemTools::SetStdoutCallback(CM_NULLPTR, CM_NULLPTR);
- cmSystemTools::SetMessageCallback(CM_NULLPTR, CM_NULLPTR);
+ this->CM.SetProgressCallback(nullptr);
+ cmSystemTools::SetStderrCallback(nullptr);
+ cmSystemTools::SetStdoutCallback(nullptr);
+ cmSystemTools::SetMessageCallback(nullptr);
}
+
+ cmCTestBuildAndTestCaptureRAII(const cmCTestBuildAndTestCaptureRAII&) =
+ delete;
+ cmCTestBuildAndTestCaptureRAII& operator=(
+ const cmCTestBuildAndTestCaptureRAII&) = delete;
};
int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
@@ -167,7 +160,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
return 1;
}
- cmake cm(cmake::RoleProject);
+ cmake cm(cmake::RoleProject, cmState::Project);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
std::string cmakeOutString;
@@ -193,21 +186,36 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
// we need to honor the timeout specified, the timeout include cmake, build
// and test time
- double clock_start = cmSystemTools::GetTime();
+ auto clock_start = std::chrono::steady_clock::now();
// make sure the binary dir is there
out << "Internal cmake changing into directory: " << this->BinaryDir
<< std::endl;
if (!cmSystemTools::FileIsDirectory(this->BinaryDir)) {
- cmSystemTools::MakeDirectory(this->BinaryDir.c_str());
+ cmSystemTools::MakeDirectory(this->BinaryDir);
}
cmWorkingDirectory workdir(this->BinaryDir);
+ if (workdir.Failed()) {
+ auto msg = "Failed to change working directory to " + this->BinaryDir +
+ " : " + std::strerror(workdir.GetLastResult()) + "\n";
+ if (outstring) {
+ *outstring = msg;
+ } else {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, msg);
+ }
+ return 1;
+ }
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);
+ cmGlobalGenerator* gen = cm.CreateGlobalGenerator(this->BuildGenerator);
+ cm.SetGlobalGenerator(gen);
+ if (!this->BuildGeneratorPlatform.empty()) {
+ cmMakefile mf(gen, cm.GetCurrentSnapshot());
+ if (!gen->SetGeneratorPlatform(this->BuildGeneratorPlatform, &mf)) {
+ return 1;
+ }
+ }
// Load the cache to make CMAKE_MAKE_PROGRAM available.
cm.LoadCache(this->BinaryDir);
@@ -219,16 +227,15 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
}
// do the build
- std::vector<std::string>::iterator tarIt;
if (this->BuildTargets.empty()) {
- 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) {
+ this->BuildTargets.emplace_back();
+ }
+ for (std::string const& tar : this->BuildTargets) {
+ cmDuration remainingTime = std::chrono::seconds(0);
+ if (this->Timeout > cmDuration::zero()) {
+ remainingTime =
+ this->Timeout - (std::chrono::steady_clock::now() - clock_start);
+ if (remainingTime <= std::chrono::seconds(0)) {
if (outstring) {
*outstring = "--build-and-test timeout exceeded. ";
}
@@ -236,7 +243,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
}
}
std::string output;
- const char* config = CM_NULLPTR;
+ const char* config = nullptr;
if (!this->CTest->GetConfigType().empty()) {
config = this->CTest->GetConfigType().c_str();
}
@@ -249,9 +256,9 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
config = "Debug";
}
int retVal = cm.GetGlobalGenerator()->Build(
- this->SourceDir, this->BinaryDir, this->BuildProject, *tarIt, output,
- this->BuildMakeProgram, config, !this->BuildNoClean, false, false,
- remainingTime);
+ cmake::NO_BUILD_PARALLEL_LEVEL, this->SourceDir, this->BinaryDir,
+ this->BuildProject, { tar }, output, this->BuildMakeProgram, config,
+ !this->BuildNoClean, false, false, remainingTime);
out << output;
// if the build failed then return
if (retVal) {
@@ -287,13 +294,13 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
cmCTestTestHandler::FindExecutable(this->CTest, this->TestCommand.c_str(),
resultingConfig, extraPaths, failed);
- if (!cmSystemTools::FileExists(fullPath.c_str())) {
+ if (!cmSystemTools::FileExists(fullPath)) {
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 << "\n";
- for (unsigned int i = 0; i < failed.size(); ++i) {
- out << failed[i] << "\n";
+ for (std::string const& fail : failed) {
+ out << fail << "\n";
}
if (outstring) {
*outstring = out.str();
@@ -305,28 +312,38 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
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());
+ for (std::string const& testCommandArg : this->TestCommandArgs) {
+ testCommand.push_back(testCommandArg.c_str());
}
- testCommand.push_back(CM_NULLPTR);
+ testCommand.push_back(nullptr);
std::string outs;
int retval = 0;
// run the test from the this->BuildRunDir if set
if (!this->BuildRunDir.empty()) {
out << "Run test in directory: " << this->BuildRunDir << "\n";
- cmSystemTools::ChangeDirectory(this->BuildRunDir);
+ if (!workdir.SetDirectory(this->BuildRunDir)) {
+ out << "Failed to change working directory : "
+ << std::strerror(workdir.GetLastResult()) << "\n";
+ if (outstring) {
+ *outstring = out.str();
+ } else {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, out.str());
+ }
+ return 1;
+ }
}
out << "Running test command: \"" << fullPath << "\"";
- for (size_t k = 0; k < this->TestCommandArgs.size(); ++k) {
- out << " \"" << this->TestCommandArgs[k] << "\"";
+ for (std::string const& testCommandArg : this->TestCommandArgs) {
+ out << " \"" << testCommandArg << "\"";
}
out << "\n";
// how much time is remaining
- double remainingTime = 0;
- if (this->Timeout > 0) {
- remainingTime = this->Timeout - cmSystemTools::GetTime() + clock_start;
- if (remainingTime <= 0) {
+ cmDuration remainingTime = std::chrono::seconds(0);
+ if (this->Timeout > cmDuration::zero()) {
+ remainingTime =
+ this->Timeout - (std::chrono::steady_clock::now() - clock_start);
+ if (remainingTime <= std::chrono::seconds(0)) {
if (outstring) {
*outstring = "--build-and-test timeout exceeded. ";
}
@@ -334,8 +351,8 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
}
}
- int runTestRes = this->CTest->RunTest(testCommand, &outs, &retval,
- CM_NULLPTR, remainingTime, CM_NULLPTR);
+ int runTestRes = this->CTest->RunTest(testCommand, &outs, &retval, nullptr,
+ remainingTime, nullptr);
if (runTestRes != cmsysProcess_State_Exited || retval != 0) {
out << "Test command failed: " << testCommand[0] << "\n";
@@ -364,7 +381,7 @@ int cmCTestBuildAndTestHandler::ProcessCommandLineArguments(
idx++;
this->BinaryDir = allArgs[idx];
// dir must exist before CollapseFullPath is called
- cmSystemTools::MakeDirectory(this->BinaryDir.c_str());
+ cmSystemTools::MakeDirectory(this->BinaryDir);
this->BinaryDir = cmSystemTools::CollapseFullPath(this->BinaryDir);
this->SourceDir = cmSystemTools::CollapseFullPath(this->SourceDir);
} else {
@@ -394,7 +411,7 @@ int cmCTestBuildAndTestHandler::ProcessCommandLineArguments(
}
if (currentArg.find("--test-timeout", 0) == 0 && idx < allArgs.size() - 1) {
idx++;
- this->Timeout = atof(allArgs[idx].c_str());
+ this->Timeout = cmDuration(atof(allArgs[idx].c_str()));
}
if (currentArg == "--build-generator" && idx < allArgs.size() - 1) {
idx++;
diff --git a/Source/CTest/cmCTestBuildAndTestHandler.h b/Source/CTest/cmCTestBuildAndTestHandler.h
index 2e85e9fed..2d47b1580 100644
--- a/Source/CTest/cmCTestBuildAndTestHandler.h
+++ b/Source/CTest/cmCTestBuildAndTestHandler.h
@@ -3,9 +3,10 @@
#ifndef cmCTestBuildAndTestHandler_h
#define cmCTestBuildAndTestHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGenericHandler.h"
+#include "cmDuration.h"
#include <sstream>
#include <stddef.h>
@@ -26,12 +27,12 @@ public:
/*
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
//! Set all the build and test arguments
- int ProcessCommandLineArguments(const std::string& currentArg, size_t& idx,
- const std::vector<std::string>& allArgs)
- CM_OVERRIDE;
+ int ProcessCommandLineArguments(
+ const std::string& currentArg, size_t& idx,
+ const std::vector<std::string>& allArgs) override;
/*
* Get the output variable
@@ -40,10 +41,10 @@ public:
cmCTestBuildAndTestHandler();
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
protected:
- ///! Run CMake and build a test and then run it as a single test.
+ //! Run CMake and build a test and then run it as a single test.
int RunCMakeAndTest(std::string* output);
int RunCMake(std::string* outstring, std::ostringstream& out,
std::string& cmakeOutString, cmake* cm);
@@ -67,7 +68,7 @@ protected:
std::vector<std::string> TestCommandArgs;
std::vector<std::string> BuildTargets;
bool BuildNoCMake;
- double Timeout;
+ cmDuration Timeout;
};
#endif
diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx
index 4c8276007..2eacaf144 100644
--- a/Source/CTest/cmCTestBuildCommand.cxx
+++ b/Source/CTest/cmCTestBuildCommand.cxx
@@ -4,9 +4,9 @@
#include "cmCTest.h"
#include "cmCTestBuildHandler.h"
-#include "cmCTestGenericHandler.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmake.h"
@@ -17,14 +17,14 @@ class cmExecutionStatus;
cmCTestBuildCommand::cmCTestBuildCommand()
{
- this->GlobalGenerator = CM_NULLPTR;
+ this->GlobalGenerator = nullptr;
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] = CM_NULLPTR;
+ this->Arguments[ctb_LAST] = nullptr;
this->Last = ctb_LAST;
}
@@ -32,18 +32,16 @@ cmCTestBuildCommand::~cmCTestBuildCommand()
{
if (this->GlobalGenerator) {
delete this->GlobalGenerator;
- this->GlobalGenerator = CM_NULLPTR;
+ this->GlobalGenerator = nullptr;
}
}
cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
{
- cmCTestGenericHandler* handler = this->CTest->GetInitializedHandler("build");
- if (!handler) {
- this->SetError("internal CTest error. Cannot instantiate build handler");
- return CM_NULLPTR;
- }
- this->Handler = (cmCTestBuildHandler*)handler;
+ cmCTestBuildHandler* handler = this->CTest->GetBuildHandler();
+ handler->Initialize();
+
+ this->Handler = handler;
const char* ctestBuildCommand =
this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");
@@ -53,10 +51,6 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
} 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
@@ -81,15 +75,14 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
? this->Values[ctb_TARGET]
: this->Makefile->GetDefinition("CTEST_BUILD_TARGET");
- if (cmakeGeneratorName && *cmakeGeneratorName && cmakeProjectName &&
- *cmakeProjectName) {
+ if (cmakeGeneratorName && *cmakeGeneratorName) {
if (!cmakeBuildConfiguration) {
cmakeBuildConfiguration = "Release";
}
if (this->GlobalGenerator) {
if (this->GlobalGenerator->GetName() != cmakeGeneratorName) {
delete this->GlobalGenerator;
- this->GlobalGenerator = CM_NULLPTR;
+ this->GlobalGenerator = nullptr;
}
}
if (!this->GlobalGenerator) {
@@ -100,13 +93,13 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
std::string e = "could not create generator named \"";
e += cmakeGeneratorName;
e += "\"";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e);
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
cmSystemTools::SetFatalErrorOccured();
- return CM_NULLPTR;
+ return nullptr;
}
}
if (strlen(cmakeBuildConfiguration) == 0) {
- const char* config = CM_NULLPTR;
+ const char* config = nullptr;
#ifdef CMAKE_INTDIR
config = CMAKE_INTDIR;
#endif
@@ -132,18 +125,11 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
/* clang-format off */
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 "
+ "is set. Otherwise, set CTEST_BUILD_COMMAND to build the project "
"with a custom command line.";
/* clang-format on */
this->SetError(ostr.str());
- return CM_NULLPTR;
+ return nullptr;
}
}
@@ -153,6 +139,12 @@ cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
this->Quiet);
}
+ if (const char* labelsForSubprojects =
+ this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
+ this->CTest->SetCTestConfiguration("LabelsForSubprojects",
+ labelsForSubprojects, this->Quiet);
+ }
+
handler->SetQuiet(this->Quiet);
return handler;
}
diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h
index 9cf6a9652..77b05498d 100644
--- a/Source/CTest/cmCTestBuildCommand.h
+++ b/Source/CTest/cmCTestBuildCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestBuildCommand_h
#define cmCTestBuildCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
@@ -25,12 +25,12 @@ class cmCTestBuildCommand : public cmCTestHandlerCommand
{
public:
cmCTestBuildCommand();
- ~cmCTestBuildCommand() CM_OVERRIDE;
+ ~cmCTestBuildCommand() override;
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestBuildCommand* ni = new cmCTestBuildCommand;
ni->CTest = this->CTest;
@@ -41,10 +41,10 @@ public:
/**
* The name of the command as specified in CMakeList.txt.
*/
- std::string GetName() const CM_OVERRIDE { return "ctest_build"; }
+ std::string GetName() const override { return "ctest_build"; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
cmGlobalGenerator* GlobalGenerator;
@@ -62,7 +62,7 @@ protected:
ctb_LAST
};
- cmCTestGenericHandler* InitializeHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeHandler() override;
};
#endif
diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx
index 18ef05c67..c8e4fa1b4 100644
--- a/Source/CTest/cmCTestBuildHandler.cxx
+++ b/Source/CTest/cmCTestBuildHandler.cxx
@@ -4,7 +4,8 @@
#include "cmAlgorithms.h"
#include "cmCTest.h"
-#include "cmFileTimeComparison.h"
+#include "cmDuration.h"
+#include "cmFileTimeCache.h"
#include "cmGeneratedFileStream.h"
#include "cmMakefile.h"
#include "cmProcessOutput.h"
@@ -17,6 +18,7 @@
#include <set>
#include <stdlib.h>
#include <string.h>
+#include <utility>
static const char* cmCTestErrorMatches[] = {
"^[Bb]us [Ee]rror",
@@ -30,13 +32,13 @@ static const char* cmCTestErrorMatches[] = {
"^Error: ",
"^Error ",
"[0-9] ERROR: ",
- "^\"[^\"]+\", line [0-9]+: [^Ww]",
+ R"(^"[^"]+", line [0-9]+: [^Ww])",
"^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
"^ld([^:])*:([ \\t])*ERROR([^:])*:",
- "^ild:([ \\t])*\\(undefined symbol\\)",
+ R"(^ild:([ \t])*\(undefined symbol\))",
"([^ :]+) : (error|fatal error|catastrophic error)",
"([^:]+): (Error:|error|undefined reference|multiply defined)",
- "([^:]+)\\(([^\\)]+)\\) ?: (error|fatal error|catastrophic error)",
+ R"(([^:]+)\(([^\)]+)\) ?: (error|fatal error|catastrophic error))",
"^fatal error C[0-9]+:",
": syntax error ",
"^collect2: ld returned 1 exit status",
@@ -48,14 +50,14 @@ static const char* cmCTestErrorMatches[] = {
"^CMake Error.*:",
":[ \\t]cannot find",
":[ \\t]can't find",
- ": \\*\\*\\* No rule to make target [`'].*\\'. Stop",
- ": \\*\\*\\* No targets specified and no makefile found",
+ R"(: \*\*\* No rule to make target [`'].*\'. Stop)",
+ R"(: \*\*\* 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]\\)",
+ R"(", 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.",
@@ -64,23 +66,24 @@ static const char* cmCTestErrorMatches[] = {
"ld: 0711-993 Error occurred while writing to the output file:",
"ld: fatal: ",
"final link failed:",
- "make: \\*\\*\\*.*Error",
- "make\\[.*\\]: \\*\\*\\*.*Error",
- "\\*\\*\\* Error code",
+ R"(make: \*\*\*.*Error)",
+ R"(make\[.*\]: \*\*\*.*Error)",
+ R"(\*\*\* Error code)",
"nternal error:",
- "Makefile:[0-9]+: \\*\\*\\* .* Stop\\.",
+ R"(Makefile:[0-9]+: \*\*\* .* Stop\.)",
": No such file or directory",
": Invalid argument",
"^The project cannot be built\\.",
"^\\[ERROR\\]",
"^Command .* failed with exit code",
- CM_NULLPTR
+ nullptr
};
static const char* cmCTestErrorExceptions[] = {
"instantiated from ",
"candidates are:",
": warning",
+ ": WARNING",
": \\(Warning\\)",
": note",
"Note:",
@@ -89,7 +92,7 @@ static const char* cmCTestErrorExceptions[] = {
":[ \\t]+Where:",
"([^ :]+):([0-9]+): Warning",
"------ Build started: .* ------",
- CM_NULLPTR
+ nullptr
};
static const char* cmCTestWarningMatches[] = {
@@ -98,29 +101,29 @@ static const char* cmCTestWarningMatches[] = {
"^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
"^ld([^:])*:([ \\t])*WARNING([^:])*:",
"([^:]+): warning ([0-9]+):",
- "^\"[^\"]+\", line [0-9]+: [Ww](arning|arnung)",
+ R"(^"[^"]+", 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]\\)",
+ R"(", 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]*\\):",
+ R"(".*", line [0-9]+: remark\([0-9]*\):)",
"cc-[0-9]* CC: REMARK File = .*, Line = [0-9]*",
"^CMake Warning.*:",
"^\\[WARNING\\]",
- CM_NULLPTR
+ nullptr
};
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",
+ R"(/usr/.*/X11/Xlib\.h:[0-9]+: war.*: ANSI C\+\+ forbids declaration)",
+ R"(/usr/.*/X11/Xutil\.h:[0-9]+: war.*: ANSI C\+\+ forbids declaration)",
+ R"(/usr/.*/X11/XResource\.h:[0-9]+: war.*: ANSI C\+\+ forbids declaration)",
"WARNING 84 :",
"WARNING 47 :",
"makefile:",
@@ -134,7 +137,7 @@ static const char* cmCTestWarningExceptions[] = {
"ld32: WARNING 85: definition of dataKey in",
"cc: warning 422: Unknown option \"\\+b",
"_with_warning_C",
- CM_NULLPTR
+ nullptr
};
struct cmCTestBuildCompileErrorWarningRex
@@ -147,12 +150,12 @@ struct cmCTestBuildCompileErrorWarningRex
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 },
+ { R"(^([a-zA-Z.\:/0-9_+ ~-]+)\(([0-9]+)\))", 1, 2 },
+ { R"(^[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 },
- { CM_NULLPTR, 0, 0 }
+ { nullptr, 0, 0 }
};
cmCTestBuildHandler::cmCTestBuildHandler()
@@ -171,8 +174,8 @@ cmCTestBuildHandler::cmCTestBuildHandler()
void cmCTestBuildHandler::Initialize()
{
this->Superclass::Initialize();
- this->StartBuild = "";
- this->EndBuild = "";
+ this->StartBuild.clear();
+ this->EndBuild.clear();
this->CustomErrorMatches.clear();
this->CustomErrorExceptions.clear();
this->CustomWarningMatches.clear();
@@ -190,8 +193,8 @@ void cmCTestBuildHandler::Initialize()
this->BuildOutputLogSize = 0;
this->CurrentProcessingLine.clear();
- this->SimplifySourceDir = "";
- this->SimplifyBuildDir = "";
+ this->SimplifySourceDir.clear();
+ this->SimplifyBuildDir.clear();
this->OutputLineCounter = 0;
this->ErrorsAndWarnings.clear();
this->LastErrorOrWarning = this->ErrorsAndWarnings.end();
@@ -260,11 +263,11 @@ std::string cmCTestBuildHandler::GetMakeCommand()
"MakeCommand:" << makeCommand << "\n", this->Quiet);
std::string configType = this->CTest->GetConfigType();
- if (configType == "") {
+ if (configType.empty()) {
configType =
this->CTest->GetCTestConfiguration("DefaultCTestConfigurationType");
}
- if (configType == "") {
+ if (configType.empty()) {
configType = "Release";
}
@@ -282,7 +285,7 @@ int cmCTestBuildHandler::ProcessHandler()
this->Quiet);
// do we have time for this
- if (this->CTest->GetRemainingTimeAllowed() < 120) {
+ if (this->CTest->GetRemainingTimeAllowed() < std::chrono::minutes(2)) {
return 0;
}
@@ -294,10 +297,11 @@ int cmCTestBuildHandler::ProcessHandler()
cmCTestWarningErrorFileLine[entry].RegularExpressionString)) {
r.FileIndex = cmCTestWarningErrorFileLine[entry].FileIndex;
r.LineIndex = cmCTestWarningErrorFileLine[entry].LineIndex;
- this->ErrorWarningFileLineRegex.push_back(r);
+ this->ErrorWarningFileLineRegex.push_back(std::move(r));
} else {
cmCTestLog(
- this->CTest, ERROR_MESSAGE, "Problem Compiling regular expression: "
+ this->CTest, ERROR_MESSAGE,
+ "Problem Compiling regular expression: "
<< cmCTestWarningErrorFileLine[entry].RegularExpressionString
<< std::endl);
}
@@ -323,46 +327,48 @@ int cmCTestBuildHandler::ProcessHandler()
std::string const& useLaunchers =
this->CTest->GetCTestConfiguration("UseLaunchers");
- this->UseCTestLaunch = cmSystemTools::IsOn(useLaunchers.c_str());
+ this->UseCTestLaunch = cmSystemTools::IsOn(useLaunchers);
// Create a last build log
cmGeneratedFileStream ofs;
- double elapsed_time_start = cmSystemTools::GetTime();
+ auto elapsed_time_start = std::chrono::steady_clock::now();
if (!this->StartLogFile("Build", ofs)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build log file"
- << std::endl);
+ 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]);
+ this->CustomErrorMatches.emplace_back(cmCTestErrorMatches[cc]);
}
for (cc = 0; cmCTestErrorExceptions[cc]; cc++) {
- this->CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
+ this->CustomErrorExceptions.emplace_back(cmCTestErrorExceptions[cc]);
}
for (cc = 0; cmCTestWarningMatches[cc]; cc++) {
- this->CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
+ this->CustomWarningMatches.emplace_back(cmCTestWarningMatches[cc]);
}
for (cc = 0; cmCTestWarningExceptions[cc]; cc++) {
- this->CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
+ this->CustomWarningExceptions.emplace_back(cmCTestWarningExceptions[cc]);
}
// Pre-compile regular expressions objects for all regular expressions
- std::vector<std::string>::iterator it;
#define cmCTestBuildHandlerPopulateRegexVector(strings, regexes) \
- regexes.clear(); \
- cmCTestOptionalLog(this->CTest, DEBUG, \
- this << "Add " #regexes << std::endl, this->Quiet); \
- for (it = (strings).begin(); it != (strings).end(); ++it) { \
+ do { \
+ regexes.clear(); \
cmCTestOptionalLog(this->CTest, DEBUG, \
- "Add " #strings ": " << *it << std::endl, \
- this->Quiet); \
- (regexes).push_back(it->c_str()); \
- }
+ this << "Add " #regexes << std::endl, this->Quiet); \
+ for (std::string const& s : (strings)) { \
+ cmCTestOptionalLog(this->CTest, DEBUG, \
+ "Add " #strings ": " << s << std::endl, \
+ this->Quiet); \
+ (regexes).emplace_back(s); \
+ } \
+ } while (false)
+
cmCTestBuildHandlerPopulateRegexVector(this->CustomErrorMatches,
this->ErrorMatchRegex);
cmCTestBuildHandlerPopulateRegexVector(this->CustomErrorExceptions,
@@ -373,15 +379,15 @@ int cmCTestBuildHandler::ProcessHandler()
this->WarningExceptionRegex);
// Determine source and binary tree substitutions to simplify the output.
- this->SimplifySourceDir = "";
- this->SimplifyBuildDir = "";
+ this->SimplifySourceDir.clear();
+ this->SimplifyBuildDir.clear();
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 = srcdir.substr(cc);
srcdirrep = "/..." + srcdirrep;
srcdir = srcdir.substr(0, cc + 1);
break;
@@ -395,7 +401,7 @@ int cmCTestBuildHandler::ProcessHandler()
std::string bindirrep;
for (cc = bindir.size() - 2; cc > 0; cc--) {
if (bindir[cc] == '/') {
- bindirrep = bindir.c_str() + cc;
+ bindirrep = bindir.substr(cc);
bindirrep = "/..." + bindirrep;
bindir = bindir.substr(0, cc + 1);
break;
@@ -408,12 +414,12 @@ int cmCTestBuildHandler::ProcessHandler()
// Remember start build time
this->StartBuild = this->CTest->CurrentTime();
- this->StartBuildTime = cmSystemTools::GetTime();
+ this->StartBuildTime = std::chrono::system_clock::now();
int retVal = 0;
int res = cmsysProcess_State_Exited;
if (!this->CTest->GetShowOnly()) {
- res = this->RunMakeCommand(makeCommand.c_str(), &retVal,
- buildDirectory.c_str(), 0, ofs);
+ res = this->RunMakeCommand(makeCommand, &retVal, buildDirectory.c_str(), 0,
+ ofs);
} else {
cmCTestOptionalLog(this->CTest, DEBUG,
"Build with command: " << makeCommand << std::endl,
@@ -422,31 +428,29 @@ int cmCTestBuildHandler::ProcessHandler()
// 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;
+ this->EndBuildTime = std::chrono::system_clock::now();
+ auto elapsed_build_time =
+ std::chrono::steady_clock::now() - 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(),
+ for (cmCTestBuildErrorWarning& evit : this->ErrorsAndWarnings) {
+ cmSystemTools::ReplaceString(evit.Text, this->SimplifySourceDir.c_str(),
"/.../");
- cmSystemTools::ReplaceString(evit->PreContext,
+ cmSystemTools::ReplaceString(evit.PreContext,
this->SimplifySourceDir.c_str(), "/.../");
- cmSystemTools::ReplaceString(evit->PostContext,
+ 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(),
+ for (cmCTestBuildErrorWarning& evit : this->ErrorsAndWarnings) {
+ cmSystemTools::ReplaceString(evit.Text, this->SimplifyBuildDir.c_str(),
"/.../");
- cmSystemTools::ReplaceString(evit->PreContext,
+ cmSystemTools::ReplaceString(evit.PreContext,
this->SimplifyBuildDir.c_str(), "/.../");
- cmSystemTools::ReplaceString(evit->PostContext,
+ cmSystemTools::ReplaceString(evit.PostContext,
this->SimplifyBuildDir.c_str(), "/.../");
}
}
@@ -454,8 +458,8 @@ int cmCTestBuildHandler::ProcessHandler()
// Generate XML output
cmGeneratedFileStream xofs;
if (!this->StartResultingXML(cmCTest::PartBuild, "Build", xofs)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create build XML file"
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create build XML file" << std::endl);
return -1;
}
cmXMLWriter xml(xofs);
@@ -468,19 +472,20 @@ int cmCTestBuildHandler::ProcessHandler()
this->GenerateXMLFooter(xml, elapsed_build_time);
if (res != cmsysProcess_State_Exited || retVal || this->TotalErrors > 0) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Error(s) when building project"
- << std::endl);
+ 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);
+ 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;
}
@@ -488,38 +493,34 @@ int cmCTestBuildHandler::ProcessHandler()
void cmCTestBuildHandler::GenerateXMLHeader(cmXMLWriter& xml)
{
this->CTest->StartXML(xml, this->AppendXML);
+ this->CTest->GenerateSubprojectsOutput(xml);
xml.StartElement("Build");
xml.Element("StartDateTime", this->StartBuild);
- xml.Element("StartBuildTime",
- static_cast<unsigned int>(this->StartBuildTime));
+ xml.Element("StartBuildTime", this->StartBuildTime);
xml.Element("BuildCommand", this->GetMakeCommand());
}
class cmCTestBuildHandler::FragmentCompare
{
public:
- FragmentCompare(cmFileTimeComparison* ftc)
+ FragmentCompare(cmFileTimeCache* ftc)
: FTC(ftc)
{
}
- FragmentCompare()
- : FTC(CM_NULLPTR)
- {
- }
+ FragmentCompare() = default;
bool operator()(std::string const& l, std::string const& r) const
{
// 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) {
+ if (this->FTC->Compare(l, r, &result) && result != 0) {
return result < 0;
}
return l < r;
}
private:
- cmFileTimeComparison* FTC;
+ cmFileTimeCache* FTC = nullptr;
};
void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml)
@@ -529,7 +530,7 @@ void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml)
}
// Sort XML fragments in chronological order.
- cmFileTimeComparison ftc;
+ cmFileTimeCache ftc;
FragmentCompare fragmentCompare(&ftc);
typedef std::set<std::string, FragmentCompare> Fragments;
Fragments fragments(fragmentCompare);
@@ -555,9 +556,8 @@ void cmCTestBuildHandler::GenerateXMLLaunched(cmXMLWriter& xml)
}
// Copy the fragments into the final XML file.
- for (Fragments::const_iterator fi = fragments.begin(); fi != fragments.end();
- ++fi) {
- xml.FragmentFile(fi->c_str());
+ for (std::string const& f : fragments) {
+ xml.FragmentFile(f.c_str());
}
}
@@ -587,12 +587,11 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
xml.StartElement(cm->Error ? "Error" : "Warning");
xml.Element("BuildLogLine", cm->LogLine);
xml.Element("Text", cm->Text);
- 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);
+ for (cmCTestCompileErrorWarningRex& rit :
+ this->ErrorWarningFileLineRegex) {
+ cmsys::RegularExpression* re = &rit.RegularExpression;
+ if (re->find(cm->Text)) {
+ 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);
@@ -608,7 +607,7 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
cm->SourceFile = cmSystemTools::CollapseFullPath(cm->SourceFile);
cmSystemTools::ReplaceString(cm->SourceFile, srcdir.c_str(), "");
}
- cm->LineNumber = atoi(re->match(rit->LineIndex).c_str());
+ cm->LineNumber = atoi(re->match(rit.LineIndex).c_str());
break;
}
}
@@ -640,7 +639,7 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
}
void cmCTestBuildHandler::GenerateXMLFooter(cmXMLWriter& xml,
- double elapsed_build_time)
+ cmDuration elapsed_build_time)
{
xml.StartElement("Log");
xml.Attribute("Encoding", "base64");
@@ -648,9 +647,11 @@ void cmCTestBuildHandler::GenerateXMLFooter(cmXMLWriter& xml,
xml.EndElement(); // Log
xml.Element("EndDateTime", this->EndBuild);
- xml.Element("EndBuildTime", static_cast<unsigned int>(this->EndBuildTime));
- xml.Element("ElapsedMinutes",
- static_cast<int>(elapsed_build_time / 6) / 10.0);
+ xml.Element("EndBuildTime", this->EndBuildTime);
+ xml.Element(
+ "ElapsedMinutes",
+ std::chrono::duration_cast<std::chrono::minutes>(elapsed_build_time)
+ .count());
xml.EndElement(); // Build
this->CTest->EndXML(xml);
}
@@ -679,6 +680,8 @@ class cmCTestBuildHandler::LaunchHelper
public:
LaunchHelper(cmCTestBuildHandler* handler);
~LaunchHelper();
+ LaunchHelper(const LaunchHelper&) = delete;
+ LaunchHelper& operator=(const LaunchHelper&) = delete;
private:
cmCTestBuildHandler* Handler;
@@ -711,7 +714,7 @@ cmCTestBuildHandler::LaunchHelper::LaunchHelper(cmCTestBuildHandler* handler)
if (this->Handler->UseCTestLaunch) {
// Enable launcher fragments.
- cmSystemTools::MakeDirectory(launchDir.c_str());
+ cmSystemTools::MakeDirectory(launchDir);
this->WriteLauncherConfig();
std::string launchEnv = "CTEST_LAUNCH_LOGS=";
launchEnv += launchDir;
@@ -742,7 +745,7 @@ void cmCTestBuildHandler::LaunchHelper::WriteLauncherConfig()
// Give some testing configuration information to the launcher.
std::string fname = this->Handler->CTestLaunchDir;
fname += "/CTestLaunchConfig.cmake";
- cmGeneratedFileStream fout(fname.c_str());
+ cmGeneratedFileStream fout(fname);
std::string srcdir = this->CTest->GetCTestConfiguration("SourceDirectory");
fout << "set(CTEST_SOURCE_DIRECTORY \"" << srcdir << "\")\n";
}
@@ -757,16 +760,16 @@ void cmCTestBuildHandler::LaunchHelper::WriteScrapeMatchers(
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";
+ cmGeneratedFileStream fout(fname);
+ for (std::string const& m : matchers) {
+ fout << m << "\n";
}
}
-int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
- const char* dir, int timeout,
- std::ostream& ofs, Encoding encoding)
+int cmCTestBuildHandler::RunMakeCommand(const std::string& command,
+ int* retVal, const char* dir,
+ int timeout, std::ostream& ofs,
+ Encoding encoding)
{
// First generate the command and arguments
std::vector<std::string> args = cmSystemTools::ParseArguments(command);
@@ -776,18 +779,20 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
}
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.reserve(args.size() + 1);
+ for (std::string const& arg : args) {
+ argv.push_back(arg.c_str());
}
- argv.push_back(CM_NULLPTR);
+ argv.push_back(nullptr);
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command:",
- this->Quiet);
- std::vector<const char*>::iterator ait;
- for (ait = argv.begin(); ait != argv.end() && *ait; ++ait) {
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Run command:", this->Quiet);
+ for (char const* arg : argv) {
+ if (!arg) {
+ break;
+ }
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- " \"" << *ait << "\"", this->Quiet);
+ " \"" << arg << "\"", this->Quiet);
}
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
this->Quiet);
@@ -798,7 +803,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
// Now create process object
cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
cmsysProcess_SetTimeout(cp, timeout);
@@ -813,7 +818,8 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
cmProcessOutput processOutput(encoding);
std::string strdata;
cmCTestOptionalLog(
- this->CTest, HANDLER_PROGRESS_OUTPUT, " Each symbol represents "
+ this->CTest, HANDLER_PROGRESS_OUTPUT,
+ " Each symbol represents "
<< tick_len << " bytes of output." << std::endl
<< (this->UseCTestLaunch
? ""
@@ -834,7 +840,7 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
// For every chunk of data
int res;
- while ((res = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR))) {
+ while ((res = cmsysProcess_WaitForData(cp, &data, &length, nullptr))) {
// Replace '\0' with '\n', since '\0' does not really make sense. This is
// for Visual Studio output
for (int cc = 0; cc < length; ++cc) {
@@ -865,17 +871,18 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
&this->BuildProcessingQueue);
}
- this->ProcessBuffer(CM_NULLPTR, 0, tick, tick_len, ofs,
+ this->ProcessBuffer(nullptr, 0, tick, tick_len, ofs,
&this->BuildProcessingQueue);
- this->ProcessBuffer(CM_NULLPTR, 0, tick, tick_len, ofs,
+ this->ProcessBuffer(nullptr, 0, tick, tick_len, ofs,
&this->BuildProcessingErrorQueue);
- cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, " Size of output: "
+ cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT,
+ " Size of output: "
<< ((this->BuildOutputLogSize + 512) / 1024) << "K"
<< std::endl,
this->Quiet);
// Properly handle output of the build command
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
int result = cmsysProcess_GetState(cp);
if (result == cmsysProcess_State_Exited) {
@@ -894,10 +901,10 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
errorwarning.Text =
"*** WARNING non-zero return value in ctest from: ";
errorwarning.Text += argv[0];
- errorwarning.PreContext = "";
- errorwarning.PostContext = "";
+ errorwarning.PreContext.clear();
+ errorwarning.PostContext.clear();
errorwarning.Error = false;
- this->ErrorsAndWarnings.push_back(errorwarning);
+ this->ErrorsAndWarnings.push_back(std::move(errorwarning));
this->TotalWarnings++;
}
}
@@ -917,13 +924,14 @@ int cmCTestBuildHandler::RunMakeCommand(const char* command, int* retVal,
errorwarning.LogLine = 1;
errorwarning.Text = "*** ERROR executing: ";
errorwarning.Text += cmsysProcess_GetErrorString(cp);
- errorwarning.PreContext = "";
- errorwarning.PostContext = "";
+ errorwarning.PreContext.clear();
+ errorwarning.PostContext.clear();
errorwarning.Error = true;
- this->ErrorsAndWarnings.push_back(errorwarning);
+ this->ErrorsAndWarnings.push_back(std::move(errorwarning));
this->TotalErrors++;
- cmCTestLog(this->CTest, ERROR_MESSAGE, "There was an error: "
- << cmsysProcess_GetErrorString(cp) << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "There was an error: " << cmsysProcess_GetErrorString(cp)
+ << std::endl);
}
cmsysProcess_Delete(cp);
@@ -970,10 +978,9 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
if (it != queue->end()) {
// Create a contiguous array for the line
this->CurrentProcessingLine.clear();
- this->CurrentProcessingLine.insert(this->CurrentProcessingLine.end(),
- queue->begin(), it);
+ cmAppend(this->CurrentProcessingLine, queue->begin(), it);
this->CurrentProcessingLine.push_back(0);
- const char* line = &*this->CurrentProcessingLine.begin();
+ const char* line = this->CurrentProcessingLine.data();
// Process the line
int lineType = this->ProcessSingleLine(line);
@@ -1002,19 +1009,17 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
// This is an error or warning, so generate report
errorwarning.LogLine = static_cast<int>(this->OutputLineCounter + 1);
errorwarning.Text = line;
- errorwarning.PreContext = "";
- errorwarning.PostContext = "";
+ errorwarning.PreContext.clear();
+ errorwarning.PostContext.clear();
// 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";
+ for (std::string const& pc : this->PreContext) {
+ errorwarning.PreContext += pc + "\n";
}
this->PreContext.clear();
// Store report
- this->ErrorsAndWarnings.push_back(errorwarning);
+ this->ErrorsAndWarnings.push_back(std::move(errorwarning));
this->LastErrorOrWarning = this->ErrorsAndWarnings.end() - 1;
this->PostContextCount = 0;
} else {
@@ -1030,7 +1035,7 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
}
} else {
// Otherwise store pre-context for the next error
- this->PreContext.push_back(line);
+ this->PreContext.emplace_back(line);
if (this->PreContext.size() > this->MaxPreContext) {
this->PreContext.erase(this->PreContext.begin(),
this->PreContext.end() -
@@ -1052,7 +1057,8 @@ void cmCTestBuildHandler::ProcessBuffer(const char* data, size_t length,
this->LastTickChar, this->Quiet);
tickDisplayed = true;
if (tick % tick_line_len == 0 && tick > 0) {
- cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT, " Size: "
+ cmCTestOptionalLog(this->CTest, HANDLER_PROGRESS_OUTPUT,
+ " Size: "
<< ((this->BuildOutputLogSize + 512) / 1024) << "K"
<< std::endl
<< " ",
@@ -1081,8 +1087,6 @@ int cmCTestBuildHandler::ProcessSingleLine(const char* data)
cmCTestOptionalLog(this->CTest, DEBUG, "Line: [" << data << "]" << std::endl,
this->Quiet);
- std::vector<cmsys::RegularExpression>::iterator it;
-
int warningLine = 0;
int errorLine = 0;
@@ -1091,9 +1095,8 @@ int cmCTestBuildHandler::ProcessSingleLine(const char* data)
if (!this->ErrorQuotaReached) {
// Errors
int wrxCnt = 0;
- for (it = this->ErrorMatchRegex.begin(); it != this->ErrorMatchRegex.end();
- ++it) {
- if (it->find(data)) {
+ for (cmsys::RegularExpression& rx : this->ErrorMatchRegex) {
+ if (rx.find(data)) {
errorLine = 1;
cmCTestOptionalLog(this->CTest, DEBUG,
" Error Line: " << data << " (matches: "
@@ -1106,11 +1109,11 @@ int cmCTestBuildHandler::ProcessSingleLine(const char* data)
}
// Error exceptions
wrxCnt = 0;
- for (it = this->ErrorExceptionRegex.begin();
- it != this->ErrorExceptionRegex.end(); ++it) {
- if (it->find(data)) {
+ for (cmsys::RegularExpression& rx : this->ErrorExceptionRegex) {
+ if (rx.find(data)) {
errorLine = 0;
- cmCTestOptionalLog(this->CTest, DEBUG, " Not an error Line: "
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ " Not an error Line: "
<< data << " (matches: "
<< this->CustomErrorExceptions[wrxCnt] << ")"
<< std::endl,
@@ -1123,11 +1126,11 @@ int cmCTestBuildHandler::ProcessSingleLine(const char* data)
if (!this->WarningQuotaReached) {
// Warnings
int wrxCnt = 0;
- for (it = this->WarningMatchRegex.begin();
- it != this->WarningMatchRegex.end(); ++it) {
- if (it->find(data)) {
+ for (cmsys::RegularExpression& rx : this->WarningMatchRegex) {
+ if (rx.find(data)) {
warningLine = 1;
- cmCTestOptionalLog(this->CTest, DEBUG, " Warning Line: "
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ " Warning Line: "
<< data << " (matches: "
<< this->CustomWarningMatches[wrxCnt] << ")"
<< std::endl,
@@ -1139,11 +1142,11 @@ int cmCTestBuildHandler::ProcessSingleLine(const char* data)
wrxCnt = 0;
// Warning exceptions
- for (it = this->WarningExceptionRegex.begin();
- it != this->WarningExceptionRegex.end(); ++it) {
- if (it->find(data)) {
+ for (cmsys::RegularExpression& rx : this->WarningExceptionRegex) {
+ if (rx.find(data)) {
warningLine = 0;
- cmCTestOptionalLog(this->CTest, DEBUG, " Not a warning Line: "
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ " Not a warning Line: "
<< data << " (matches: "
<< this->CustomWarningExceptions[wrxCnt] << ")"
<< std::endl,
diff --git a/Source/CTest/cmCTestBuildHandler.h b/Source/CTest/cmCTestBuildHandler.h
index ef3cddf1b..722c59009 100644
--- a/Source/CTest/cmCTestBuildHandler.h
+++ b/Source/CTest/cmCTestBuildHandler.h
@@ -3,12 +3,14 @@
#ifndef cmCTestBuildHandler_h
#define cmCTestBuildHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGenericHandler.h"
+#include "cmDuration.h"
#include "cmProcessOutput.h"
#include "cmsys/RegularExpression.hxx"
+#include <chrono>
#include <deque>
#include <iosfwd>
#include <stddef.h>
@@ -31,16 +33,16 @@ public:
/*
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
cmCTestBuildHandler();
- void PopulateCustomVectors(cmMakefile* mf) CM_OVERRIDE;
+ void PopulateCustomVectors(cmMakefile* mf) override;
/**
* Initialize handler
*/
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
int GetTotalErrors() { return this->TotalErrors; }
int GetTotalWarnings() { return this->TotalWarnings; }
@@ -50,7 +52,7 @@ private:
//! 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 RunMakeCommand(const std::string& command, int* retVal, const char* dir,
int timeout, std::ostream& ofs,
Encoding encoding = cmProcessOutput::Auto);
@@ -86,14 +88,14 @@ private:
void GenerateXMLHeader(cmXMLWriter& xml);
void GenerateXMLLaunched(cmXMLWriter& xml);
void GenerateXMLLogScraped(cmXMLWriter& xml);
- void GenerateXMLFooter(cmXMLWriter& xml, double elapsed_build_time);
+ void GenerateXMLFooter(cmXMLWriter& xml, cmDuration elapsed_build_time);
bool IsLaunchedErrorFile(const char* fname);
bool IsLaunchedWarningFile(const char* fname);
std::string StartBuild;
std::string EndBuild;
- double StartBuildTime;
- double EndBuildTime;
+ std::chrono::system_clock::time_point StartBuildTime;
+ std::chrono::system_clock::time_point EndBuildTime;
std::vector<std::string> CustomErrorMatches;
std::vector<std::string> CustomErrorExceptions;
diff --git a/Source/CTest/cmCTestCVS.cxx b/Source/CTest/cmCTestCVS.cxx
index fad360ba4..9c038399e 100644
--- a/Source/CTest/cmCTestCVS.cxx
+++ b/Source/CTest/cmCTestCVS.cxx
@@ -16,9 +16,7 @@ cmCTestCVS::cmCTestCVS(cmCTest* ct, std::ostream& log)
{
}
-cmCTestCVS::~cmCTestCVS()
-{
-}
+cmCTestCVS::~cmCTestCVS() = default;
class cmCTestCVS::UpdateParser : public cmCTestVC::LineParser
{
@@ -46,7 +44,7 @@ private:
cmsys::RegularExpression RegexFileRemoved1;
cmsys::RegularExpression RegexFileRemoved2;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexFileUpdated.find(this->Line)) {
this->DoFile(PathUpdated, this->RegexFileUpdated.match(2));
@@ -80,7 +78,7 @@ bool cmCTestCVS::UpdateImpl()
opts = "-dP";
}
}
- std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
// Specify the start time for nightly testing.
if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) {
@@ -92,11 +90,10 @@ bool cmCTestCVS::UpdateImpl()
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());
+ for (std::string const& arg : args) {
+ cvs_update.push_back(arg.c_str());
}
- cvs_update.push_back(CM_NULLPTR);
+ cvs_update.push_back(nullptr);
UpdateParser out(this, "up-out> ");
UpdateParser err(this, "up-err> ");
@@ -112,8 +109,8 @@ public:
, Revisions(revs)
, Section(SectionHeader)
{
- this->SetLog(&cvs->Log, prefix),
- this->RegexRevision.compile("^revision +([^ ]*) *$");
+ this->SetLog(&cvs->Log, prefix);
+ this->RegexRevision.compile("^revision +([^ ]*) *$");
this->RegexBranches.compile("^branches: .*$");
this->RegexPerson.compile("^date: +([^;]+); +author: +([^;]+);");
}
@@ -133,10 +130,11 @@ private:
SectionType Section;
Revision Rev;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
- if (this->Line == ("======================================="
- "======================================")) {
+ if (this->Line ==
+ ("======================================="
+ "======================================")) {
// This line ends the revision list.
if (this->Section == SectionRevisions) {
this->FinishRevision();
@@ -221,8 +219,9 @@ void cmCTestCVS::LoadRevisions(std::string const& file, const char* branchFlag,
// 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(), CM_NULLPTR };
+ const char* cvs_log[] = {
+ cvs, "log", "-N", branchFlag, file.c_str(), nullptr
+ };
LogParser out(this, "log-out> ", revisions);
OutputLogger err(this->Log, "log-err> ");
@@ -241,12 +240,12 @@ void cmCTestCVS::WriteXMLDirectory(cmXMLWriter& xml, std::string const& 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;
+ for (auto const& fi : dir) {
+ std::string full = path + slash + fi.first;
// Load two real or unknown revisions.
revisions.clear();
- if (fi->second != PathUpdated) {
+ 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);
@@ -255,8 +254,8 @@ void cmCTestCVS::WriteXMLDirectory(cmXMLWriter& xml, std::string const& path,
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);
+ File f(fi.second, &revisions[0], &revisions[1]);
+ this->WriteXMLEntry(xml, path, fi.first, full, f);
}
xml.EndElement(); // Directory
}
@@ -268,10 +267,8 @@ bool cmCTestCVS::WriteXMLUpdates(cmXMLWriter& xml)
" "
<< 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);
+ for (auto const& d : this->Dirs) {
+ this->WriteXMLDirectory(xml, d.first, d.second);
}
cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
diff --git a/Source/CTest/cmCTestCVS.h b/Source/CTest/cmCTestCVS.h
index 1208cfad6..77fc3cc25 100644
--- a/Source/CTest/cmCTestCVS.h
+++ b/Source/CTest/cmCTestCVS.h
@@ -3,7 +3,7 @@
#ifndef cmCTestCVS_h
#define cmCTestCVS_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestVC.h"
@@ -25,12 +25,12 @@ public:
/** Construct with a CTest instance and update log stream. */
cmCTestCVS(cmCTest* ctest, std::ostream& log);
- ~cmCTestCVS() CM_OVERRIDE;
+ ~cmCTestCVS() override;
private:
// Implement cmCTestVC internal API.
- bool UpdateImpl() CM_OVERRIDE;
- bool WriteXMLUpdates(cmXMLWriter& xml) CM_OVERRIDE;
+ bool UpdateImpl() override;
+ bool WriteXMLUpdates(cmXMLWriter& xml) override;
// Update status for files in each directory.
class Directory : public std::map<std::string, PathStatus>
diff --git a/Source/CTest/cmCTestCommand.h b/Source/CTest/cmCTestCommand.h
index 6fc237aac..8efb4194c 100644
--- a/Source/CTest/cmCTestCommand.h
+++ b/Source/CTest/cmCTestCommand.h
@@ -20,8 +20,8 @@ class cmCTestCommand : public cmCommand
public:
cmCTestCommand()
{
- this->CTest = CM_NULLPTR;
- this->CTestScriptHandler = CM_NULLPTR;
+ this->CTest = nullptr;
+ this->CTestScriptHandler = nullptr;
}
cmCTest* CTest;
diff --git a/Source/CTest/cmCTestConfigureCommand.cxx b/Source/CTest/cmCTestConfigureCommand.cxx
index 73e893df3..74a932a65 100644
--- a/Source/CTest/cmCTestConfigureCommand.cxx
+++ b/Source/CTest/cmCTestConfigureCommand.cxx
@@ -3,7 +3,7 @@
#include "cmCTestConfigureCommand.h"
#include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
+#include "cmCTestConfigureHandler.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
@@ -16,7 +16,7 @@
cmCTestConfigureCommand::cmCTestConfigureCommand()
{
this->Arguments[ctc_OPTIONS] = "OPTIONS";
- this->Arguments[ctc_LAST] = CM_NULLPTR;
+ this->Arguments[ctc_LAST] = nullptr;
this->Last = ctc_LAST;
}
@@ -33,7 +33,7 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
"Build directory not specified. Either use BUILD "
"argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY "
"variable");
- return CM_NULLPTR;
+ return nullptr;
}
const char* ctestConfigureCommand =
@@ -53,15 +53,15 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
"Source directory not specified. Either use SOURCE "
"argument to CTEST_CONFIGURE command or set CTEST_SOURCE_DIRECTORY "
"variable");
- return CM_NULLPTR;
+ return nullptr;
}
const std::string cmakelists_file = source_dir + "/CMakeLists.txt";
- if (!cmSystemTools::FileExists(cmakelists_file.c_str())) {
+ if (!cmSystemTools::FileExists(cmakelists_file)) {
std::ostringstream e;
e << "CMakeLists.txt file does not exist [" << cmakelists_file << "]";
this->SetError(e.str());
- return CM_NULLPTR;
+ return nullptr;
}
bool multiConfig = false;
@@ -79,18 +79,13 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
cmakeConfigureCommand += cmSystemTools::GetCMakeCommand();
cmakeConfigureCommand += "\"";
- std::vector<std::string>::const_iterator it;
- std::string option;
- for (it = options.begin(); it != options.end(); ++it) {
- option = *it;
-
+ for (std::string const& option : options) {
cmakeConfigureCommand += " \"";
cmakeConfigureCommand += option;
cmakeConfigureCommand += "\"";
- if ((CM_NULLPTR != strstr(option.c_str(), "CMAKE_BUILD_TYPE=")) ||
- (CM_NULLPTR !=
- strstr(option.c_str(), "CMAKE_BUILD_TYPE:STRING="))) {
+ if ((nullptr != strstr(option.c_str(), "CMAKE_BUILD_TYPE=")) ||
+ (nullptr != strstr(option.c_str(), "CMAKE_BUILD_TYPE:STRING="))) {
cmakeBuildTypeInOptions = true;
}
}
@@ -137,17 +132,18 @@ cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
"Configure command is not specified. If this is a "
"\"built with CMake\" project, set CTEST_CMAKE_GENERATOR. If not, "
"set CTEST_CONFIGURE_COMMAND.");
- return CM_NULLPTR;
+ return nullptr;
}
}
- cmCTestGenericHandler* handler =
- this->CTest->GetInitializedHandler("configure");
- if (!handler) {
- this->SetError(
- "internal CTest error. Cannot instantiate configure handler");
- return CM_NULLPTR;
+ if (const char* labelsForSubprojects =
+ this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
+ this->CTest->SetCTestConfiguration("LabelsForSubprojects",
+ labelsForSubprojects, this->Quiet);
}
+
+ cmCTestConfigureHandler* handler = this->CTest->GetConfigureHandler();
+ handler->Initialize();
handler->SetQuiet(this->Quiet);
return handler;
}
diff --git a/Source/CTest/cmCTestConfigureCommand.h b/Source/CTest/cmCTestConfigureCommand.h
index 917f5ab8b..0cbcbfaa8 100644
--- a/Source/CTest/cmCTestConfigureCommand.h
+++ b/Source/CTest/cmCTestConfigureCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestConfigureCommand_h
#define cmCTestConfigureCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
@@ -25,7 +25,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestConfigureCommand* ni = new cmCTestConfigureCommand;
ni->CTest = this->CTest;
@@ -36,10 +36,10 @@ public:
/**
* The name of the command as specified in CMakeList.txt.
*/
- std::string GetName() const CM_OVERRIDE { return "ctest_configure"; }
+ std::string GetName() const override { return "ctest_configure"; }
protected:
- cmCTestGenericHandler* InitializeHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeHandler() override;
enum
{
diff --git a/Source/CTest/cmCTestConfigureHandler.cxx b/Source/CTest/cmCTestConfigureHandler.cxx
index 5d87f3fb4..7e93189cd 100644
--- a/Source/CTest/cmCTestConfigureHandler.cxx
+++ b/Source/CTest/cmCTestConfigureHandler.cxx
@@ -3,16 +3,15 @@
#include "cmCTestConfigureHandler.h"
#include "cmCTest.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
-#include "cmSystemTools.h"
#include "cmXMLWriter.h"
+#include <chrono>
#include <ostream>
#include <string>
-cmCTestConfigureHandler::cmCTestConfigureHandler()
-{
-}
+cmCTestConfigureHandler::cmCTestConfigureHandler() = default;
void cmCTestConfigureHandler::Initialize()
{
@@ -43,28 +42,28 @@ int cmCTestConfigureHandler::ProcessHandler()
return -1;
}
- double elapsed_time_start = cmSystemTools::GetTime();
+ auto elapsed_time_start = std::chrono::steady_clock::now();
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);
+ 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());
+ auto start_time_time = std::chrono::system_clock::now();
cmGeneratedFileStream ofs;
this->StartLogFile("Configure", ofs);
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Configure with command: " << cCommand << std::endl,
this->Quiet);
- res = this->CTest->RunMakeCommand(cCommand.c_str(), output, &retVal,
- buildDirectory.c_str(), 0, ofs);
+ res = this->CTest->RunMakeCommand(cCommand, output, &retVal,
+ buildDirectory.c_str(),
+ cmDuration::zero(), ofs);
if (ofs) {
ofs.close();
@@ -73,6 +72,7 @@ int cmCTestConfigureHandler::ProcessHandler()
if (os) {
cmXMLWriter xml(os);
this->CTest->StartXML(xml, this->AppendXML);
+ this->CTest->GenerateSubprojectsOutput(xml);
xml.StartElement("Configure");
xml.Element("StartDateTime", start_time);
xml.Element("StartConfigureTime", start_time_time);
@@ -81,12 +81,11 @@ int cmCTestConfigureHandler::ProcessHandler()
xml.Element("Log", output);
xml.Element("ConfigureStatus", retVal);
xml.Element("EndDateTime", this->CTest->CurrentTime());
- xml.Element("EndConfigureTime",
- static_cast<unsigned int>(cmSystemTools::GetTime()));
- xml.Element(
- "ElapsedMinutes",
- static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start) / 6) /
- 10.0);
+ xml.Element("EndConfigureTime", std::chrono::system_clock::now());
+ xml.Element("ElapsedMinutes",
+ std::chrono::duration_cast<std::chrono::minutes>(
+ std::chrono::steady_clock::now() - elapsed_time_start)
+ .count());
xml.EndElement(); // Configure
this->CTest->EndXML(xml);
}
diff --git a/Source/CTest/cmCTestConfigureHandler.h b/Source/CTest/cmCTestConfigureHandler.h
index 2b452829c..680401c84 100644
--- a/Source/CTest/cmCTestConfigureHandler.h
+++ b/Source/CTest/cmCTestConfigureHandler.h
@@ -3,7 +3,7 @@
#ifndef cmCTestConfigureHandler_h
#define cmCTestConfigureHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGenericHandler.h"
@@ -19,11 +19,11 @@ public:
/*
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
cmCTestConfigureHandler();
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
};
#endif
diff --git a/Source/CTest/cmCTestCoverageCommand.cxx b/Source/CTest/cmCTestCoverageCommand.cxx
index 535da586d..07aae768c 100644
--- a/Source/CTest/cmCTestCoverageCommand.cxx
+++ b/Source/CTest/cmCTestCoverageCommand.cxx
@@ -19,12 +19,8 @@ cmCTestGenericHandler* cmCTestCoverageCommand::InitializeHandler()
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "CoverageExtraFlags", "CTEST_COVERAGE_EXTRA_FLAGS",
this->Quiet);
- cmCTestCoverageHandler* handler = static_cast<cmCTestCoverageHandler*>(
- this->CTest->GetInitializedHandler("coverage"));
- if (!handler) {
- this->SetError("internal CTest error. Cannot instantiate test handler");
- return CM_NULLPTR;
- }
+ cmCTestCoverageHandler* handler = this->CTest->GetCoverageHandler();
+ handler->Initialize();
// If a LABELS option was given, select only files with the labels.
if (this->LabelsMentioned) {
diff --git a/Source/CTest/cmCTestCoverageCommand.h b/Source/CTest/cmCTestCoverageCommand.h
index 78c4f61f6..1ae2d869a 100644
--- a/Source/CTest/cmCTestCoverageCommand.h
+++ b/Source/CTest/cmCTestCoverageCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestCoverageCommand_h
#define cmCTestCoverageCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
@@ -26,7 +26,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestCoverageCommand* ni = new cmCTestCoverageCommand;
ni->CTest = this->CTest;
@@ -37,15 +37,15 @@ public:
/**
* The name of the command as specified in CMakeList.txt.
*/
- std::string GetName() const CM_OVERRIDE { return "ctest_coverage"; }
+ std::string GetName() const override { return "ctest_coverage"; }
typedef cmCTestHandlerCommand Superclass;
protected:
- cmCTestGenericHandler* InitializeHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeHandler() override;
- bool CheckArgumentKeyword(std::string const& arg) CM_OVERRIDE;
- bool CheckArgumentValue(std::string const& arg) CM_OVERRIDE;
+ bool CheckArgumentKeyword(std::string const& arg) override;
+ bool CheckArgumentValue(std::string const& arg) override;
enum
{
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx
index 28fae1c7e..f6028c4fc 100644
--- a/Source/CTest/cmCTestCoverageHandler.cxx
+++ b/Source/CTest/cmCTestCoverageHandler.cxx
@@ -2,7 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestCoverageHandler.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmParseBlanketJSCoverage.h"
#include "cmParseCacheCoverage.h"
@@ -14,13 +16,14 @@
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
#include "cmXMLWriter.h"
-#include "cmake.h"
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/Process.h"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
+#include <chrono>
+#include <cstring>
#include <iomanip>
#include <iterator>
#include <sstream>
@@ -39,7 +42,7 @@ public:
{
this->Process = cmsysProcess_New();
this->PipeState = -1;
- this->TimeOut = -1;
+ this->TimeOut = cmDuration(-1);
}
~cmCTestRunProcess()
{
@@ -50,38 +53,37 @@ public:
}
cmsysProcess_Delete(this->Process);
}
+ cmCTestRunProcess(const cmCTestRunProcess&) = delete;
+ cmCTestRunProcess& operator=(const cmCTestRunProcess&) = delete;
void SetCommand(const char* command)
{
this->CommandLineStrings.clear();
- this->CommandLineStrings.push_back(command);
- ;
+ this->CommandLineStrings.emplace_back(command);
}
void AddArgument(const char* arg)
{
if (arg) {
- this->CommandLineStrings.push_back(arg);
+ this->CommandLineStrings.emplace_back(arg);
}
}
void SetWorkingDirectory(const char* dir) { this->WorkingDirectory = dir; }
- void SetTimeout(double t) { this->TimeOut = t; }
+ void SetTimeout(cmDuration 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());
+ for (std::string const& cl : this->CommandLineStrings) {
+ args.push_back(cl.c_str());
}
- args.push_back(CM_NULLPTR); // null terminate
- cmsysProcess_SetCommand(this->Process, &*args.begin());
+ args.push_back(nullptr); // null terminate
+ cmsysProcess_SetCommand(this->Process, args.data());
if (!this->WorkingDirectory.empty()) {
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);
+ if (this->TimeOut >= cmDuration::zero()) {
+ cmsysProcess_SetTimeout(this->Process, this->TimeOut.count());
}
cmsysProcess_Execute(this->Process);
this->PipeState = cmsysProcess_GetState(this->Process);
@@ -97,7 +99,7 @@ public:
{
cmsysProcess_SetPipeFile(this->Process, cmsysProcess_Pipe_STDERR, fname);
}
- int WaitForExit(double* timeout = CM_NULLPTR)
+ int WaitForExit(double* timeout = nullptr)
{
this->PipeState = cmsysProcess_WaitForExit(this->Process, timeout);
return this->PipeState;
@@ -109,12 +111,10 @@ private:
cmsysProcess* Process;
std::vector<std::string> CommandLineStrings;
std::string WorkingDirectory;
- double TimeOut;
+ cmDuration TimeOut;
};
-cmCTestCoverageHandler::cmCTestCoverageHandler()
-{
-}
+cmCTestCoverageHandler::cmCTestCoverageHandler() = default;
void cmCTestCoverageHandler::Initialize()
{
@@ -136,10 +136,9 @@ void cmCTestCoverageHandler::CleanCoverageLogFiles(std::ostream& log)
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);
+ for (std::string const& f : files) {
+ log << "Removing old coverage log: " << f << "\n";
+ cmSystemTools::RemoveFile(f);
}
}
@@ -176,34 +175,31 @@ void cmCTestCoverageHandler::StartCoverageLogXML(cmXMLWriter& xml)
this->CTest->StartXML(xml, this->AppendXML);
xml.StartElement("CoverageLog");
xml.Element("StartDateTime", this->CTest->CurrentTime());
- xml.Element("StartTime",
- static_cast<unsigned int>(cmSystemTools::GetTime()));
+ xml.Element("StartTime", std::chrono::system_clock::now());
}
void cmCTestCoverageHandler::EndCoverageLogXML(cmXMLWriter& xml)
{
xml.Element("EndDateTime", this->CTest->CurrentTime());
- xml.Element("EndTime", static_cast<unsigned int>(cmSystemTools::GetTime()));
+ xml.Element("EndTime", std::chrono::system_clock::now());
xml.EndElement(); // CoverageLog
this->CTest->EndXML(xml);
}
-bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file,
- const char* srcDir,
- const char* binDir)
+bool cmCTestCoverageHandler::ShouldIDoCoverage(std::string const& file,
+ std::string const& srcDir,
+ std::string const& 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)) {
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " File "
- << file << " is excluded in CTestCustom.ctest"
- << std::endl;
- , this->Quiet);
+ for (cmsys::RegularExpression& rx : this->CustomCoverageExcludeRegex) {
+ if (rx.find(file)) {
+ cmCTestOptionalLog(
+ this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " File " << file << " is excluded in CTestCustom.ctest" << std::endl;
+ , this->Quiet);
return false;
}
}
@@ -230,7 +226,7 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file,
checkDir = fBinDir;
}
std::string ndc = cmSystemTools::FileExistsInParentDirectories(
- ".NoDartCoverage", fFile.c_str(), checkDir.c_str());
+ ".NoDartCoverage", fFile, checkDir);
if (!ndc.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Found: " << ndc << " so skip coverage of " << file
@@ -244,7 +240,7 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file,
// If it is the same as fileDir, then ignore, otherwise check.
std::string relPath;
if (!checkDir.empty()) {
- relPath = cmSystemTools::RelativePath(checkDir.c_str(), fFile.c_str());
+ relPath = cmSystemTools::RelativePath(checkDir, fFile);
} else {
relPath = fFile;
}
@@ -261,8 +257,8 @@ bool cmCTestCoverageHandler::ShouldIDoCoverage(const char* file,
return true;
}
- ndc = cmSystemTools::FileExistsInParentDirectories(
- ".NoDartCoverage", fFile.c_str(), checkDir.c_str());
+ ndc = cmSystemTools::FileExistsInParentDirectories(".NoDartCoverage", fFile,
+ checkDir);
if (!ndc.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Found: " << ndc << " so skip coverage of: " << file
@@ -281,13 +277,12 @@ int cmCTestCoverageHandler::ProcessHandler()
this->CTest->ClearSubmitFiles(cmCTest::PartCoverage);
int error = 0;
// do we have time for this
- if (this->CTest->GetRemainingTimeAllowed() < 120) {
+ if (this->CTest->GetRemainingTimeAllowed() < std::chrono::minutes(2)) {
return error;
}
std::string coverage_start_time = this->CTest->CurrentTime();
- unsigned int coverage_start_time_time =
- static_cast<unsigned int>(cmSystemTools::GetTime());
+ auto coverage_start_time_time = std::chrono::system_clock::now();
std::string sourceDir =
this->CTest->GetCTestConfiguration("SourceDirectory");
std::string binaryDir = this->CTest->GetCTestConfiguration("BuildDirectory");
@@ -295,13 +290,14 @@ int cmCTestCoverageHandler::ProcessHandler()
this->LoadLabels();
cmGeneratedFileStream ofs;
- double elapsed_time_start = cmSystemTools::GetTime();
+ auto elapsed_time_start = std::chrono::steady_clock::now();
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;
+ ofs << "Performing coverage: "
+ << elapsed_time_start.time_since_epoch().count() << std::endl;
this->CleanCoverageLogFiles(ofs);
cmSystemTools::ConvertToUnixSlashes(sourceDir);
@@ -319,11 +315,8 @@ int cmCTestCoverageHandler::ProcessHandler()
// 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()));
+ for (std::string const& rex : this->CustomCoverageExclude) {
+ this->CustomCoverageExcludeRegex.emplace_back(rex);
}
if (this->HandleBullseyeCoverage(&cont)) {
@@ -396,8 +389,8 @@ int cmCTestCoverageHandler::ProcessHandler()
if (!this->StartResultingXML(cmCTest::PartCoverage, "Coverage",
covSumFile)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open coverage summary file."
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open coverage summary file." << std::endl);
return -1;
}
covSumFile.setf(std::ios::fixed, std::ios::floatfield);
@@ -414,7 +407,6 @@ int cmCTestCoverageHandler::ProcessHandler()
return -1;
}
this->StartCoverageLogXML(covLogXML);
- cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator fileIterator;
int cnt = 0;
long total_tested = 0;
long total_untested = 0;
@@ -430,22 +422,22 @@ int cmCTestCoverageHandler::ProcessHandler()
std::vector<std::string> errorsWhileAccumulating;
file_count = 0;
- for (fileIterator = cont.TotalCoverage.begin();
- fileIterator != cont.TotalCoverage.end(); ++fileIterator) {
+ for (auto const& file : cont.TotalCoverage) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush,
this->Quiet);
file_count++;
if (file_count % 50 == 0) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " processed: "
- << file_count << " out of "
- << cont.TotalCoverage.size() << std::endl,
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ " processed: " << file_count << " out of "
+ << cont.TotalCoverage.size()
+ << std::endl,
this->Quiet);
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " ", this->Quiet);
}
- const std::string fullFileName = fileIterator->first;
- bool shouldIDoCoverage = this->ShouldIDoCoverage(
- fullFileName.c_str(), sourceDir.c_str(), binaryDir.c_str());
+ const std::string fullFileName = file.first;
+ bool shouldIDoCoverage =
+ this->ShouldIDoCoverage(fullFileName, sourceDir, binaryDir);
if (!shouldIDoCoverage) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
".NoDartCoverage found, so skip coverage check for: "
@@ -458,7 +450,7 @@ int cmCTestCoverageHandler::ProcessHandler()
"Process file: " << fullFileName << std::endl,
this->Quiet);
- if (!cmSystemTools::FileExists(fullFileName.c_str())) {
+ if (!cmSystemTools::FileExists(fullFileName)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot find file: " << fullFileName << std::endl);
continue;
@@ -478,7 +470,7 @@ int cmCTestCoverageHandler::ProcessHandler()
std::string shortFileName =
this->CTest->GetShortPathToFile(fullFileName.c_str());
const cmCTestCoverageHandlerContainer::SingleFileCoverageVector& fcov =
- fileIterator->second;
+ file.second;
covLogXML.StartElement("File");
covLogXML.Attribute("Name", fileName);
covLogXML.Attribute("FullPath", shortFileName);
@@ -531,8 +523,9 @@ int cmCTestCoverageHandler::ProcessHandler()
float cper = 0;
float cmet = 0;
if (tested + untested > 0) {
- cper = (100 * SAFEDIV(static_cast<float>(tested),
- static_cast<float>(tested + untested)));
+ 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)));
}
@@ -554,14 +547,13 @@ int cmCTestCoverageHandler::ProcessHandler()
}
// 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;
+ for (std::string const& u : uncovered) {
+ std::string fileName = cmSystemTools::GetFilenameName(u);
+ std::string fullPath = cont.SourceDir + "/" + u;
covLogXML.StartElement("File");
covLogXML.Attribute("Name", fileName);
- covLogXML.Attribute("FullPath", *i);
+ covLogXML.Attribute("FullPath", u);
covLogXML.StartElement("Report");
cmsys::ifstream ifs(fullPath.c_str());
@@ -577,7 +569,7 @@ int cmCTestCoverageHandler::ProcessHandler()
int untested = 0;
std::string line;
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- "Actually performing coverage for: " << *i << std::endl,
+ "Actually performing coverage for: " << u << std::endl,
this->Quiet);
while (cmSystemTools::GetLineFromStream(ifs, line)) {
covLogXML.StartElement("Line");
@@ -593,13 +585,13 @@ int cmCTestCoverageHandler::ProcessHandler()
total_untested += untested;
covSumXML.StartElement("File");
covSumXML.Attribute("Name", fileName);
- covSumXML.Attribute("FullPath", *i);
+ covSumXML.Attribute("FullPath", u);
covSumXML.Attribute("Covered", "true");
covSumXML.Element("LOCTested", 0);
covSumXML.Element("LOCUnTested", untested);
covSumXML.Element("PercentCoverage", 0);
covSumXML.Element("CoverageMetric", 0);
- this->WriteXMLLabels(covSumXML, *i);
+ this->WriteXMLLabels(covSumXML, u);
covSumXML.EndElement(); // File
}
@@ -610,10 +602,8 @@ int cmCTestCoverageHandler::ProcessHandler()
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);
+ for (std::string const& er : errorsWhileAccumulating) {
+ cmCTestLog(this->CTest, ERROR_MESSAGE, " " << er << std::endl);
}
}
@@ -631,23 +621,22 @@ int cmCTestCoverageHandler::ProcessHandler()
covSumXML.Element("LOC", total_lines);
covSumXML.Element("PercentCoverage", percent_coverage);
covSumXML.Element("EndDateTime", end_time);
- covSumXML.Element("EndTime",
- static_cast<unsigned int>(cmSystemTools::GetTime()));
- covSumXML.Element(
- "ElapsedMinutes",
- static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start) / 6) /
- 10.0);
+ covSumXML.Element("EndTime", std::chrono::system_clock::now());
+ covSumXML.Element("ElapsedMinutes",
+ std::chrono::duration_cast<std::chrono::minutes>(
+ std::chrono::steady_clock::now() - elapsed_time_start)
+ .count());
covSumXML.EndElement(); // Coverage
this->CTest->EndXML(covSumXML);
- 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);
+ 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
@@ -670,17 +659,14 @@ void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile* mf)
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) {
+ for (std::string const& cce : this->CustomCoverageExclude) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- " Add coverage exclude: " << *it << std::endl,
+ " Add coverage exclude: " << cce << std::endl,
this->Quiet);
}
- for (it = this->ExtraCoverageGlobs.begin();
- it != this->ExtraCoverageGlobs.end(); ++it) {
+ for (std::string const& ecg : this->ExtraCoverageGlobs) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- " Add coverage glob: " << *it << std::endl,
+ " Add coverage glob: " << ecg << std::endl,
this->Quiet);
}
}
@@ -691,9 +677,9 @@ void cmCTestCoverageHandler::PopulateCustomVectors(cmMakefile* mf)
// Compare file names: fnc(fn1) == fnc(fn2) // fnc == file name compare
//
#ifdef _WIN32
-#define fnc(s) cmSystemTools::LowerCase(s)
+# define fnc(s) cmSystemTools::LowerCase(s)
#else
-#define fnc(s) s
+# define fnc(s) s
#endif
bool IsFileInDir(const std::string& infile, const std::string& indir)
@@ -733,7 +719,7 @@ int cmCTestCoverageHandler::HandleCoberturaCoverage(
// build the find file string with the directory from above
coverageXMLFile += "/coverage.xml";
- if (cmSystemTools::FileExists(coverageXMLFile.c_str())) {
+ if (cmSystemTools::FileExists(coverageXMLFile)) {
// If file exists, parse it
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Parsing Cobertura XML file: " << coverageXMLFile
@@ -756,7 +742,7 @@ int cmCTestCoverageHandler::HandleMumpsCoverage(
cmParseGTMCoverage cov(*cont, this->CTest);
std::string coverageFile =
this->CTest->GetBinaryDir() + "/gtm_coverage.mcov";
- if (cmSystemTools::FileExists(coverageFile.c_str())) {
+ if (cmSystemTools::FileExists(coverageFile)) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Parsing Cache Coverage: " << coverageFile << std::endl,
this->Quiet);
@@ -769,7 +755,7 @@ int cmCTestCoverageHandler::HandleMumpsCoverage(
this->Quiet);
cmParseCacheCoverage ccov(*cont, this->CTest);
coverageFile = this->CTest->GetBinaryDir() + "/cache_coverage.cmcov";
- if (cmSystemTools::FileExists(coverageFile.c_str())) {
+ if (cmSystemTools::FileExists(coverageFile)) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Parsing Cache Coverage: " << coverageFile << std::endl,
this->Quiet);
@@ -803,6 +789,9 @@ struct cmCTestCoverageHandlerLocale
cmSystemTools::UnsetEnv("LC_ALL");
}
}
+ cmCTestCoverageHandlerLocale(const cmCTestCoverageHandlerLocale&) = delete;
+ cmCTestCoverageHandlerLocale& operator=(
+ const cmCTestCoverageHandlerLocale&) = delete;
std::string lc_all;
};
@@ -825,15 +814,11 @@ int cmCTestCoverageHandler::HandleJacocoCoverage(
// ...and in the binary directory.
cmsys::Glob g2;
- std::vector<std::string> binFiles;
g2.SetRecurse(true);
std::string binaryDir = this->CTest->GetCTestConfiguration("BuildDirectory");
std::string binCoverageFile = binaryDir + "/*jacoco.xml";
g2.FindFiles(binCoverageFile);
- binFiles = g2.GetFiles();
- if (!binFiles.empty()) {
- files.insert(files.end(), binFiles.begin(), binFiles.end());
- }
+ cmAppend(files, g2.GetFiles());
if (!files.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -877,6 +862,24 @@ int cmCTestCoverageHandler::HandleDelphiCoverage(
return static_cast<int>(cont->TotalCoverage.size());
}
+static std::string joinCommandLine(const std::vector<std::string>& args)
+{
+ std::string ret;
+
+ for (std::string const& s : args) {
+ if (s.find(' ') == std::string::npos) {
+ ret += s + ' ';
+ } else {
+ ret += "\"" + s + "\" ";
+ }
+ }
+
+ // drop trailing whitespace
+ ret.erase(ret.size() - 1);
+
+ return ret;
+}
+
int cmCTestCoverageHandler::HandleBlanketJSCoverage(
cmCTestCoverageHandlerContainer* cont)
{
@@ -895,12 +898,12 @@ int cmCTestCoverageHandler::HandleBlanketJSCoverage(
// Blanket.js output. Check for the "node-jscoverage"
// string on the second line
std::string line;
- for (unsigned int fileEntry = 0; fileEntry < files.size(); fileEntry++) {
- cmsys::ifstream in(files[fileEntry].c_str());
+ for (std::string const& fileEntry : files) {
+ cmsys::ifstream in(fileEntry.c_str());
cmSystemTools::GetLineFromStream(in, line);
cmSystemTools::GetLineFromStream(in, line);
if (line.find("node-jscoverage") != std::string::npos) {
- blanketFiles.push_back(files[fileEntry]);
+ blanketFiles.push_back(fileEntry);
}
}
// Take all files with the node-jscoverage string and parse those
@@ -924,7 +927,8 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
std::string gcovCommand =
this->CTest->GetCTestConfiguration("CoverageCommand");
if (gcovCommand.empty()) {
- cmCTestLog(this->CTest, WARNING, "Could not find gcov." << std::endl);
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Could not find gcov." << std::endl, this->Quiet);
return 0;
}
std::string gcovExtraFlags =
@@ -961,7 +965,6 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
std::vector<std::string> files;
this->FindGCovFiles(files);
- std::vector<std::string>::iterator it;
if (files.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -973,7 +976,12 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
std::string testingDir = this->CTest->GetBinaryDir() + "/Testing";
std::string tempDir = testingDir + "/CoverageInfo";
- cmSystemTools::MakeDirectory(tempDir.c_str());
+ if (!cmSystemTools::MakeDirectory(tempDir)) {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unable to make directory: " << tempDir << std::endl);
+ cont->Error++;
+ return 0;
+ }
cmWorkingDirectory workdir(tempDir);
int gcovStyle = 0;
@@ -992,19 +1000,26 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
cmCTestCoverageHandlerLocale locale_C;
static_cast<void>(locale_C);
+ std::vector<std::string> basecovargs =
+ cmSystemTools::ParseArguments(gcovExtraFlags);
+ basecovargs.insert(basecovargs.begin(), gcovCommand);
+ basecovargs.emplace_back("-o");
+
// 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) {
+ for (std::string const& f : files) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush,
this->Quiet);
// Call gcov to get coverage data for this *.gcda file:
//
- std::string fileDir = cmSystemTools::GetFilenamePath(*it);
- std::string command = "\"" + gcovCommand + "\" " + gcovExtraFlags + " " +
- "-o \"" + fileDir + "\" " + "\"" + *it + "\"";
+ std::string fileDir = cmSystemTools::GetFilenamePath(f);
+ std::vector<std::string> covargs = basecovargs;
+ covargs.push_back(fileDir);
+ covargs.push_back(f);
+ const std::string command = joinCommandLine(covargs);
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
command << std::endl, this->Quiet);
@@ -1014,23 +1029,24 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
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*/);
+ int res = this->CTest->RunCommand(covargs, &output, &errors, &retVal,
+ tempDir.c_str(),
+ cmDuration::zero() /*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);
+ "Problem running coverage on file: " << f << 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,
+ "Coverage command returned: "
+ << retVal << " while processing: " << f << std::endl);
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Command produced error: " << cont->Error << std::endl);
}
@@ -1044,86 +1060,84 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
this->Quiet);
std::vector<std::string> lines;
- std::vector<std::string>::iterator line;
-
- cmSystemTools::Split(output.c_str(), lines);
+ cmsys::SystemTools::Split(output, lines);
- for (line = lines.begin(); line != lines.end(); ++line) {
+ for (std::string const& line : lines) {
std::string sourceFile;
std::string gcovFile;
cmCTestOptionalLog(this->CTest, DEBUG,
- "Line: [" << *line << "]" << std::endl, this->Quiet);
+ "Line: [" << line << "]" << std::endl, this->Quiet);
- if (line->empty()) {
+ if (line.empty()) {
// Ignore empty line; probably style 2
- } else if (st1re1.find(line->c_str())) {
+ } else if (st1re1.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 1;
}
if (gcovStyle != 1) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e1"
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown gcov output style e1" << std::endl);
cont->Error++;
break;
}
- actualSourceFile = "";
+ actualSourceFile.clear();
sourceFile = st1re1.match(2);
- } else if (st1re2.find(line->c_str())) {
+ } else if (st1re2.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 1;
}
if (gcovStyle != 1) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e2"
- << std::endl);
+ 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())) {
+ } else if (st2re1.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 2;
}
if (gcovStyle != 2) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e3"
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown gcov output style e3" << std::endl);
cont->Error++;
break;
}
- actualSourceFile = "";
+ actualSourceFile.clear();
sourceFile = st2re1.match(1);
- } else if (st2re2.find(line->c_str())) {
+ } else if (st2re2.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 2;
}
if (gcovStyle != 2) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e4"
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown gcov output style e4" << std::endl);
cont->Error++;
break;
}
- } else if (st2re3.find(line->c_str())) {
+ } else if (st2re3.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 2;
}
if (gcovStyle != 2) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e5"
- << std::endl);
+ 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())) {
+ } else if (st2re4.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 2;
}
if (gcovStyle != 2) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e6"
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown gcov output style e6" << std::endl);
cont->Error++;
break;
}
@@ -1132,42 +1146,45 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
"Warning: " << st2re4.match(1)
<< " had unexpected EOF" << std::endl,
this->Quiet);
- } else if (st2re5.find(line->c_str())) {
+ } else if (st2re5.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 2;
}
if (gcovStyle != 2) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e7"
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown gcov output style e7" << std::endl);
cont->Error++;
break;
}
- cmCTestOptionalLog(this->CTest, WARNING, "Warning: Cannot open file: "
- << st2re5.match(1) << std::endl,
+ cmCTestOptionalLog(this->CTest, WARNING,
+ "Warning: Cannot open file: " << st2re5.match(1)
+ << std::endl,
this->Quiet);
- } else if (st2re6.find(line->c_str())) {
+ } else if (st2re6.find(line)) {
if (gcovStyle == 0) {
gcovStyle = 2;
}
if (gcovStyle != 2) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown gcov output style e8"
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown gcov output style e8" << std::endl);
cont->Error++;
break;
}
- cmCTestOptionalLog(this->CTest, WARNING, "Warning: File: "
- << st2re6.match(1) << " is newer than "
- << st2re6.match(2) << std::endl,
+ cmCTestOptionalLog(this->CTest, WARNING,
+ "Warning: File: " << st2re6.match(1)
+ << " is newer than "
+ << st2re6.match(2) << std::endl,
this->Quiet);
} 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);
+ 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();
}
@@ -1235,11 +1252,11 @@ int cmCTestCoverageHandler::HandleGCovCoverage(
}
}
- actualSourceFile = "";
+ actualSourceFile.clear();
}
if (!sourceFile.empty() && actualSourceFile.empty()) {
- gcovFile = "";
+ gcovFile.clear();
// Is it in the source dir or the binary dir?
//
@@ -1332,7 +1349,6 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
"Error while finding LCov files.\n");
return 0;
}
- std::vector<std::string>::iterator it;
if (files.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -1357,14 +1373,26 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
cmCTestCoverageHandlerLocale locale_C;
static_cast<void>(locale_C);
+ std::vector<std::string> covargs =
+ cmSystemTools::ParseArguments(lcovExtraFlags);
+ covargs.insert(covargs.begin(), lcovCommand);
+ const std::string command = joinCommandLine(covargs);
+
// 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) {
+ for (std::string const& f : files) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "." << std::flush,
this->Quiet);
- std::string fileDir = cmSystemTools::GetFilenamePath(*it);
+ std::string fileDir = cmSystemTools::GetFilenamePath(f);
cmWorkingDirectory workdir(fileDir);
- std::string command = "\"" + lcovCommand + "\" " + lcovExtraFlags + " ";
+ if (workdir.Failed()) {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unable to change working directory to "
+ << fileDir << " : "
+ << std::strerror(workdir.GetLastResult()) << std::endl);
+ cont->Error++;
+ continue;
+ }
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Current coverage dir: " << fileDir << std::endl,
@@ -1377,23 +1405,24 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
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,
- fileDir.c_str(), 0 /*this->TimeOut*/);
+ int res = this->CTest->RunCommand(covargs, &output, &errors, &retVal,
+ fileDir.c_str(),
+ cmDuration::zero() /*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);
+ "Problem running coverage on file: " << f << 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,
+ "Coverage command returned: "
+ << retVal << " while processing: " << f << std::endl);
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Command produced error: " << cont->Error << std::endl);
}
@@ -1407,15 +1436,13 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
this->Quiet);
std::vector<std::string> lines;
- std::vector<std::string>::iterator line;
-
- cmSystemTools::Split(output.c_str(), lines);
+ cmsys::SystemTools::Split(output, lines);
- for (line = lines.begin(); line != lines.end(); ++line) {
+ for (std::string const& line : lines) {
std::string sourceFile;
std::string lcovFile;
- if (line->empty()) {
+ if (line.empty()) {
// Ignore empty line
}
// Look for LCOV files in binary directory
@@ -1435,12 +1462,10 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
" looking for LCOV files in: " << daGlob << std::endl, this->Quiet);
gl.FindFiles(daGlob);
// Keep a list of all LCOV files
- lcovFiles.insert(lcovFiles.end(), gl.GetFiles().begin(),
- gl.GetFiles().end());
+ cmAppend(lcovFiles, gl.GetFiles());
- for (std::vector<std::string>::iterator a = lcovFiles.begin();
- a != lcovFiles.end(); ++a) {
- lcovFile = *a;
+ for (std::string const& file : lcovFiles) {
+ lcovFile = file;
cmsys::ifstream srcead(lcovFile.c_str());
if (!srcead) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
@@ -1462,10 +1487,9 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
sourceFile = srcname;
actualSourceFile = srcname;
- for (std::vector<std::string>::iterator t = lcovFiles.begin();
- t != lcovFiles.end(); ++t) {
+ for (std::string const& t : lcovFiles) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- "Found LCOV File: " << *t << std::endl,
+ "Found LCOV File: " << t << std::endl,
this->Quiet);
}
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -1537,7 +1561,7 @@ int cmCTestCoverageHandler::HandleLCovCoverage(
}
}
- actualSourceFile = "";
+ actualSourceFile.clear();
}
}
}
@@ -1562,10 +1586,9 @@ void cmCTestCoverageHandler::FindGCovFiles(std::vector<std::string>& files)
gl.RecurseOn();
gl.RecurseThroughSymlinksOff();
- for (LabelMapType::const_iterator lmi = this->TargetDirs.begin();
- lmi != this->TargetDirs.end(); ++lmi) {
+ for (auto const& lm : this->TargetDirs) {
// Skip targets containing no interesting labels.
- if (!this->IntersectsFilter(lmi->second)) {
+ if (!this->IntersectsFilter(lm.second)) {
continue;
}
@@ -1573,15 +1596,15 @@ void cmCTestCoverageHandler::FindGCovFiles(std::vector<std::string>& files)
// support directory.
cmCTestOptionalLog(
this->CTest, HANDLER_VERBOSE_OUTPUT,
- " globbing for coverage in: " << lmi->first << std::endl, this->Quiet);
- std::string daGlob = lmi->first;
+ " globbing for coverage in: " << lm.first << std::endl, this->Quiet);
+ std::string daGlob = lm.first;
daGlob += "/*.da";
gl.FindFiles(daGlob);
- files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
- daGlob = lmi->first;
+ cmAppend(files, gl.GetFiles());
+ daGlob = lm.first;
daGlob += "/*.gcda";
gl.FindFiles(daGlob);
- files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+ cmAppend(files, gl.GetFiles());
}
}
@@ -1593,6 +1616,12 @@ bool cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
gl.RecurseThroughSymlinksOff();
std::string buildDir = this->CTest->GetCTestConfiguration("BuildDirectory");
cmWorkingDirectory workdir(buildDir);
+ if (workdir.Failed()) {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unable to change working directory to " << buildDir
+ << std::endl);
+ return false;
+ }
// Run profmerge to merge all *.dyn files into dpi files
if (!cmSystemTools::RunSingleCommand("profmerge")) {
@@ -1612,7 +1641,7 @@ bool cmCTestCoverageHandler::FindLCovFiles(std::vector<std::string>& files)
"Error while finding files matching " << daGlob << std::endl);
return false;
}
- files.insert(files.end(), gl.GetFiles().begin(), gl.GetFiles().end());
+ cmAppend(files, gl.GetFiles());
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Now searching in: " << daGlob << std::endl, this->Quiet);
return true;
@@ -1639,16 +1668,15 @@ int cmCTestCoverageHandler::HandleTracePyCoverage(
std::string testingDir = this->CTest->GetBinaryDir() + "/Testing";
std::string tempDir = testingDir + "/CoverageInfo";
- cmSystemTools::MakeDirectory(tempDir.c_str());
+ cmSystemTools::MakeDirectory(tempDir);
- 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);
+ for (std::string const& file : files) {
+ std::string fileName = this->FindFile(cont, file);
if (fileName.empty()) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot find source Python file corresponding to: "
- << *fileIt << std::endl);
+ << file << std::endl);
continue;
}
@@ -1660,11 +1688,11 @@ int cmCTestCoverageHandler::HandleTracePyCoverage(
cmCTestCoverageHandlerContainer::SingleFileCoverageVector* vec =
&cont->TotalCoverage[actualSourceFile];
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- " in file: " << *fileIt << std::endl, this->Quiet);
- cmsys::ifstream ifile(fileIt->c_str());
+ " in file: " << file << std::endl, this->Quiet);
+ cmsys::ifstream ifile(file.c_str());
if (!ifile) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
- "Cannot open file: " << *fileIt << std::endl);
+ "Cannot open file: " << file << std::endl);
} else {
long cnt = -1;
std::string nl;
@@ -1736,11 +1764,11 @@ std::string cmCTestCoverageHandler::FindFile(
cmSystemTools::GetFilenameWithoutLastExtension(fileName);
// First check in source and binary directory
std::string fullName = cont->SourceDir + "/" + fileNameNoE + ".py";
- if (cmSystemTools::FileExists(fullName.c_str())) {
+ if (cmSystemTools::FileExists(fullName)) {
return fullName;
}
fullName = cont->BinaryDir + "/" + fileNameNoE + ".py";
- if (cmSystemTools::FileExists(fullName.c_str())) {
+ if (cmSystemTools::FileExists(fullName)) {
return fullName;
}
return "";
@@ -1761,7 +1789,7 @@ const char* bullseyeHelp[] = {
" condition evaluated true or false, respectively.",
" * A k indicates a constant decision or condition.",
" * The slash / means this probe is excluded from summary results. ",
- CM_NULLPTR
+ nullptr
};
}
@@ -1789,8 +1817,9 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"run covbr: " << std::endl, this->Quiet);
- if (!this->RunBullseyeCommand(cont, "covbr", CM_NULLPTR, outputFile)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "error running covbr for."
+ if (!this->RunBullseyeCommand(cont, "covbr", nullptr, outputFile)) {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "error running covbr for."
<< "\n");
return -1;
}
@@ -1862,7 +1891,7 @@ int cmCTestCoverageHandler::RunBullseyeCoverageBranch(
covLogXML.StartElement("Report");
// write the bullseye header
line = 0;
- for (int k = 0; bullseyeHelp[k] != CM_NULLPTR; ++k) {
+ for (int k = 0; bullseyeHelp[k] != nullptr; ++k) {
covLogXML.StartElement("Line");
covLogXML.Attribute("Number", line);
covLogXML.Attribute("Count", -1);
@@ -1954,17 +1983,16 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary(
cmXMLWriter xml(covSumFile);
if (!this->StartResultingXML(cmCTest::PartCoverage, "Coverage",
covSumFile)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open coverage summary file."
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot open coverage summary file." << std::endl);
return 0;
}
this->CTest->StartXML(xml, this->AppendXML);
- double elapsed_time_start = cmSystemTools::GetTime();
+ auto elapsed_time_start = std::chrono::steady_clock::now();
std::string coverage_start_time = this->CTest->CurrentTime();
xml.StartElement("Coverage");
xml.Element("StartDateTime", coverage_start_time);
- xml.Element("StartTime",
- static_cast<unsigned int>(cmSystemTools::GetTime()));
+ xml.Element("StartTime", std::chrono::system_clock::now());
std::string stdline;
std::string errline;
// expected output:
@@ -2007,15 +2035,15 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary(
}
std::string file = sourceFile;
coveredFileNames.insert(file);
- if (!cmSystemTools::FileIsFullPath(sourceFile.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(sourceFile)) {
// file will be relative to the binary dir
file = cont->BinaryDir;
file += "/";
file += sourceFile;
}
file = cmSystemTools::CollapseFullPath(file);
- bool shouldIDoCoverage = this->ShouldIDoCoverage(
- file.c_str(), cont->SourceDir.c_str(), cont->BinaryDir.c_str());
+ bool shouldIDoCoverage =
+ this->ShouldIDoCoverage(file, cont->SourceDir, cont->BinaryDir);
if (!shouldIDoCoverage) {
cmCTestOptionalLog(
this->CTest, HANDLER_VERBOSE_OUTPUT,
@@ -2085,11 +2113,11 @@ int cmCTestCoverageHandler::RunBullseyeSourceSummary(
xml.Element("LOC", total_functions);
xml.Element("PercentCoverage", SAFEDIV(percent_coverage, number_files));
xml.Element("EndDateTime", end_time);
- xml.Element("EndTime", static_cast<unsigned int>(cmSystemTools::GetTime()));
- xml.Element(
- "ElapsedMinutes",
- static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start) / 6) /
- 10.0);
+ xml.Element("EndTime", std::chrono::system_clock::now());
+ xml.Element("ElapsedMinutes",
+ std::chrono::duration_cast<std::chrono::minutes>(
+ std::chrono::steady_clock::now() - elapsed_time_start)
+ .count());
xml.EndElement(); // Coverage
this->CTest->EndXML(xml);
@@ -2172,7 +2200,8 @@ bool cmCTestCoverageHandler::ParseBullsEyeCovsrcLine(
}
// should be at the end now
if (pos != std::string::npos) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Error parsing input : "
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error parsing input : "
<< inputLine << " last pos not npos = " << pos << "\n");
}
return true;
@@ -2193,7 +2222,7 @@ int cmCTestCoverageHandler::GetLabelId(std::string const& label)
void cmCTestCoverageHandler::LoadLabels()
{
std::string fileList = this->CTest->GetBinaryDir();
- fileList += cmake::GetCMakeFilesDirectory();
+ fileList += "/CMakeFiles";
fileList += "/TargetDirectories.txt";
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
" target directory list [" << fileList << "]\n",
@@ -2256,9 +2285,8 @@ void cmCTestCoverageHandler::WriteXMLLabels(cmXMLWriter& xml,
LabelMapType::const_iterator li = this->SourceLabels.find(source);
if (li != this->SourceLabels.end() && !li->second.empty()) {
xml.StartElement("Labels");
- for (LabelSet::const_iterator lsi = li->second.begin();
- lsi != li->second.end(); ++lsi) {
- xml.Element("Label", this->Labels[*lsi]);
+ for (auto const& ls : li->second) {
+ xml.Element("Label", this->Labels[ls]);
}
xml.EndElement(); // Labels
}
@@ -2268,9 +2296,8 @@ 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));
+ for (std::string const& l : labels) {
+ this->LabelFilter.insert(this->GetLabelId(l));
}
}
@@ -2310,29 +2337,23 @@ std::set<std::string> cmCTestCoverageHandler::FindUncoveredFiles(
{
std::set<std::string> extraMatches;
- for (std::vector<std::string>::iterator i = this->ExtraCoverageGlobs.begin();
- i != this->ExtraCoverageGlobs.end(); ++i) {
+ for (std::string const& ecg : this->ExtraCoverageGlobs) {
cmsys::Glob gl;
gl.RecurseOn();
gl.RecurseThroughSymlinksOff();
- std::string glob = cont->SourceDir + "/" + *i;
+ std::string glob = cont->SourceDir + "/" + ecg;
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()));
+ for (std::string const& f : files) {
+ if (this->ShouldIDoCoverage(f, cont->SourceDir, cont->BinaryDir)) {
+ extraMatches.insert(this->CTest->GetShortPathToFile(f.c_str()));
}
}
}
if (!extraMatches.empty()) {
- for (cmCTestCoverageHandlerContainer::TotalCoverageMap::iterator i =
- cont->TotalCoverage.begin();
- i != cont->TotalCoverage.end(); ++i) {
- std::string shortPath =
- this->CTest->GetShortPathToFile(i->first.c_str());
+ for (auto const& i : cont->TotalCoverage) {
+ std::string shortPath = this->CTest->GetShortPathToFile(i.first.c_str());
extraMatches.erase(shortPath);
}
}
diff --git a/Source/CTest/cmCTestCoverageHandler.h b/Source/CTest/cmCTestCoverageHandler.h
index 933f60660..6492fe951 100644
--- a/Source/CTest/cmCTestCoverageHandler.h
+++ b/Source/CTest/cmCTestCoverageHandler.h
@@ -3,7 +3,7 @@
#ifndef cmCTestCoverageHandler_h
#define cmCTestCoverageHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGenericHandler.h"
@@ -42,23 +42,23 @@ public:
/*
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
cmCTestCoverageHandler();
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
/**
* This method is called when reading CTest custom file
*/
- void PopulateCustomVectors(cmMakefile* mf) CM_OVERRIDE;
+ void PopulateCustomVectors(cmMakefile* mf) override;
/** 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);
+ bool ShouldIDoCoverage(std::string const& file, std::string const& srcDir,
+ std::string const& binDir);
void CleanCoverageLogFiles(std::ostream& log);
bool StartCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
void EndCoverageLogFile(cmGeneratedFileStream& ostr, int logFileCount);
diff --git a/Source/CTest/cmCTestCurl.cxx b/Source/CTest/cmCTestCurl.cxx
index b80ea5ade..cc63e4563 100644
--- a/Source/CTest/cmCTestCurl.cxx
+++ b/Source/CTest/cmCTestCurl.cxx
@@ -2,10 +2,11 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestCurl.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
+#include "cmCurl.h"
#include "cmSystemTools.h"
-#include "cmConfigure.h"
#include <ostream>
#include <stdio.h>
@@ -42,32 +43,27 @@ namespace {
size_t curlWriteMemoryCallback(void* ptr, size_t size, size_t nmemb,
void* data)
{
- int realsize = (int)(size * nmemb);
-
- std::vector<char>* vec = static_cast<std::vector<char>*>(data);
+ int realsize = static_cast<int>(size * nmemb);
const char* chPtr = static_cast<char*>(ptr);
- vec->insert(vec->end(), chPtr, chPtr + realsize);
+ cmAppend(*static_cast<std::vector<char>*>(data), chPtr, chPtr + realsize);
return realsize;
}
size_t curlDebugCallback(CURL* /*unused*/, curl_infotype /*unused*/,
char* chPtr, size_t size, void* data)
{
- std::vector<char>* vec = static_cast<std::vector<char>*>(data);
- vec->insert(vec->end(), chPtr, chPtr + size);
-
+ cmAppend(*static_cast<std::vector<char>*>(data), chPtr, chPtr + size);
return size;
}
}
void cmCTestCurl::SetCurlOptions(std::vector<std::string> const& args)
{
- for (std::vector<std::string>::const_iterator i = args.begin();
- i != args.end(); ++i) {
- if (*i == "CURLOPT_SSL_VERIFYPEER_OFF") {
+ for (std::string const& arg : args) {
+ if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
this->VerifyPeerOff = true;
}
- if (*i == "CURLOPT_SSL_VERIFYHOST_OFF") {
+ if (arg == "CURLOPT_SSL_VERIFYHOST_OFF") {
this->VerifyHostOff = true;
}
}
@@ -78,6 +74,7 @@ bool cmCTestCurl::InitCurl()
if (!this->Curl) {
return false;
}
+ cmCurlSetCAInfo(this->Curl);
if (this->VerifyPeerOff) {
curl_easy_setopt(this->Curl, CURLOPT_SSL_VERIFYPEER, 0);
}
@@ -111,7 +108,7 @@ bool cmCTestCurl::UploadFile(std::string const& local_file,
std::string const& url, std::string const& fields,
std::string& response)
{
- response = "";
+ response.clear();
if (!this->InitCurl()) {
cmCTestLog(this->CTest, ERROR_MESSAGE, "Initialization of curl failed");
return false;
@@ -145,20 +142,19 @@ bool cmCTestCurl::UploadFile(std::string const& local_file,
::curl_easy_setopt(this->Curl, CURLOPT_DEBUGFUNCTION, curlDebugCallback);
// Set Content-Type to satisfy fussy modsecurity rules.
struct curl_slist* headers =
- ::curl_slist_append(CM_NULLPTR, "Content-Type: text/xml");
+ ::curl_slist_append(nullptr, "Content-Type: text/xml");
// Add any additional headers that the user specified.
- for (std::vector<std::string>::const_iterator h = this->HttpHeaders.begin();
- h != this->HttpHeaders.end(); ++h) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Add HTTP Header: \"" << *h << "\"" << std::endl,
+ for (std::string const& h : this->HttpHeaders) {
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ " Add HTTP Header: \"" << h << "\"" << std::endl,
this->Quiet);
- headers = ::curl_slist_append(headers, h->c_str());
+ headers = ::curl_slist_append(headers, h.c_str());
}
::curl_easy_setopt(this->Curl, CURLOPT_HTTPHEADER, headers);
std::vector<char> responseData;
std::vector<char> debugData;
- ::curl_easy_setopt(this->Curl, CURLOPT_FILE, (void*)&responseData);
- ::curl_easy_setopt(this->Curl, CURLOPT_DEBUGDATA, (void*)&debugData);
+ ::curl_easy_setopt(this->Curl, CURLOPT_FILE, &responseData);
+ ::curl_easy_setopt(this->Curl, CURLOPT_DEBUGDATA, &debugData);
::curl_easy_setopt(this->Curl, CURLOPT_FAILONERROR, 1);
// Now run off and do what you've been told!
::curl_easy_perform(this->Curl);
@@ -178,7 +174,8 @@ bool cmCTestCurl::UploadFile(std::string const& local_file,
"Curl debug: [" << curlDebug << "]\n", this->Quiet);
}
if (response.empty()) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "No response from server.\n"
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "No response from server.\n"
<< curlDebug);
return false;
}
@@ -188,8 +185,9 @@ bool cmCTestCurl::UploadFile(std::string const& local_file,
bool cmCTestCurl::HttpRequest(std::string const& url,
std::string const& fields, std::string& response)
{
- response = "";
- cmCTestOptionalLog(this->CTest, DEBUG, "HttpRequest\n"
+ response.clear();
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ "HttpRequest\n"
<< "url: " << url << "\n"
<< "fields " << fields << "\n",
this->Quiet);
@@ -207,20 +205,18 @@ bool cmCTestCurl::HttpRequest(std::string const& url,
::curl_easy_setopt(this->Curl, CURLOPT_DEBUGFUNCTION, curlDebugCallback);
std::vector<char> responseData;
std::vector<char> debugData;
- ::curl_easy_setopt(this->Curl, CURLOPT_FILE, (void*)&responseData);
- ::curl_easy_setopt(this->Curl, CURLOPT_DEBUGDATA, (void*)&debugData);
+ ::curl_easy_setopt(this->Curl, CURLOPT_FILE, &responseData);
+ ::curl_easy_setopt(this->Curl, CURLOPT_DEBUGDATA, &debugData);
::curl_easy_setopt(this->Curl, CURLOPT_FAILONERROR, 1);
// Add headers if any were specified.
- struct curl_slist* headers = CM_NULLPTR;
+ struct curl_slist* headers = nullptr;
if (!this->HttpHeaders.empty()) {
- for (std::vector<std::string>::const_iterator h =
- this->HttpHeaders.begin();
- h != this->HttpHeaders.end(); ++h) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Add HTTP Header: \"" << *h << "\"" << std::endl,
+ for (std::string const& h : this->HttpHeaders) {
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ " Add HTTP Header: \"" << h << "\"" << std::endl,
this->Quiet);
- headers = ::curl_slist_append(headers, h->c_str());
+ headers = ::curl_slist_append(headers, h.c_str());
}
}
@@ -245,10 +241,10 @@ bool cmCTestCurl::HttpRequest(std::string const& url,
void cmCTestCurl::SetProxyType()
{
- this->HTTPProxy = "";
+ this->HTTPProxy.clear();
// this is the default
this->HTTPProxyType = CURLPROXY_HTTP;
- this->HTTPProxyAuth = "";
+ this->HTTPProxyAuth.clear();
if (cmSystemTools::GetEnv("HTTP_PROXY", this->HTTPProxy)) {
std::string port;
if (cmSystemTools::GetEnv("HTTP_PROXY_PORT", port)) {
diff --git a/Source/CTest/cmCTestCurl.h b/Source/CTest/cmCTestCurl.h
index 427a39232..6186af8d2 100644
--- a/Source/CTest/cmCTestCurl.h
+++ b/Source/CTest/cmCTestCurl.h
@@ -16,7 +16,9 @@ class cmCTestCurl
public:
cmCTestCurl(cmCTest*);
~cmCTestCurl();
- bool UploadFile(std::string const& url, std::string const& file,
+ cmCTestCurl(const cmCTestCurl&) = delete;
+ cmCTestCurl& operator=(const cmCTestCurl&) = delete;
+ bool UploadFile(std::string const& local_file, std::string const& url,
std::string const& fields, std::string& response);
bool HttpRequest(std::string const& url, std::string const& fields,
std::string& response);
diff --git a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
index 503ed234d..9425ece95 100644
--- a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
+++ b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestEmptyBinaryDirectoryCommand_h
#define cmCTestEmptyBinaryDirectoryCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
@@ -27,7 +27,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestEmptyBinaryDirectoryCommand* ni =
new cmCTestEmptyBinaryDirectoryCommand;
@@ -41,7 +41,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/CTest/cmCTestGIT.cxx b/Source/CTest/cmCTestGIT.cxx
index 230aedf3b..9d9761ce2 100644
--- a/Source/CTest/cmCTestGIT.cxx
+++ b/Source/CTest/cmCTestGIT.cxx
@@ -31,9 +31,7 @@ cmCTestGIT::cmCTestGIT(cmCTest* ct, std::ostream& log)
this->CurrentGitVersion = 0;
}
-cmCTestGIT::~cmCTestGIT()
-{
-}
+cmCTestGIT::~cmCTestGIT() = default;
class cmCTestGIT::OneLineParser : public cmCTestVC::LineParser
{
@@ -46,7 +44,7 @@ public:
private:
std::string& Line1;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
// Only the first line is of interest.
this->Line1 = this->Line;
@@ -58,8 +56,8 @@ 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", "--", CM_NULLPTR };
+ const char* git_rev_list[] = { git, "rev-list", "-n", "1",
+ "HEAD", "--", nullptr };
std::string rev;
OneLineParser out(this, "rl-out> ", rev);
OutputLogger err(this->Log, "rl-err> ");
@@ -70,8 +68,9 @@ std::string cmCTestGIT::GetWorkingRevision()
bool cmCTestGIT::NoteOldRevision()
{
this->OldRevision = this->GetWorkingRevision();
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
- << this->OldRevision << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Old revision of repository is: " << this->OldRevision
+ << "\n");
this->PriorRev.Rev = this->OldRevision;
return true;
}
@@ -79,8 +78,9 @@ bool cmCTestGIT::NoteOldRevision()
bool cmCTestGIT::NoteNewRevision()
{
this->NewRevision = this->GetWorkingRevision();
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
- << this->NewRevision << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " New revision of repository is: " << this->NewRevision
+ << "\n");
return true;
}
@@ -90,11 +90,11 @@ std::string cmCTestGIT::FindGitDir()
// 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", CM_NULLPTR };
+ char const* git_rev_parse[] = { git, "rev-parse", "--git-dir", nullptr };
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, CM_NULLPTR,
+ if (this->RunChild(git_rev_parse, &rev_parse_out, &rev_parse_err, nullptr,
cmProcessOutput::UTF8)) {
git_dir = git_dir_line;
}
@@ -113,12 +113,12 @@ std::string cmCTestGIT::FindGitDir()
// 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())) {
+ if (cmSystemTools::FileExists(cygpath_exe)) {
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, CM_NULLPTR,
+ if (this->RunChild(cygpath, &cygpath_out, &cygpath_err, nullptr,
cmProcessOutput::UTF8)) {
git_dir = git_dir_line;
}
@@ -134,12 +134,11 @@ std::string cmCTestGIT::FindTopDir()
// 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",
- CM_NULLPTR };
+ char const* git_rev_parse[] = { git, "rev-parse", "--show-cdup", nullptr };
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, CM_NULLPTR,
+ if (this->RunChild(git_rev_parse, &rev_parse_out, &rev_parse_err, nullptr,
cmProcessOutput::UTF8) &&
!cdup.empty()) {
top_dir += "/";
@@ -163,14 +162,13 @@ bool cmCTestGIT::UpdateByFetchAndReset()
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());
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
+ for (std::string const& arg : args) {
+ git_fetch.push_back(arg.c_str());
}
// Sentinel argument.
- git_fetch.push_back(CM_NULLPTR);
+ git_fetch.push_back(nullptr);
// Fetch upstream refs.
OutputLogger fetch_out(this->Log, "fetch-out> ");
@@ -205,8 +203,7 @@ bool cmCTestGIT::UpdateByFetchAndReset()
}
// Reset the local branch to point at that tracked from upstream.
- char const* git_reset[] = { git, "reset", "--hard", sha1.c_str(),
- CM_NULLPTR };
+ char const* git_reset[] = { git, "reset", "--hard", sha1.c_str(), nullptr };
OutputLogger reset_out(this->Log, "reset-out> ");
OutputLogger reset_err(this->Log, "reset-err> ");
return this->RunChild(&git_reset[0], &reset_out, &reset_err);
@@ -217,11 +214,11 @@ 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.reserve(git_custom_command.size() + 1);
+ for (std::string const& i : git_custom_command) {
+ git_custom.push_back(i.c_str());
}
- git_custom.push_back(CM_NULLPTR);
+ git_custom.push_back(nullptr);
OutputLogger custom_out(this->Log, "custom-out> ");
OutputLogger custom_err(this->Log, "custom-err> ");
@@ -250,18 +247,18 @@ bool cmCTestGIT::UpdateImpl()
// Git < 1.6.5 did not support submodule --recursive
if (this->GetGitVersion() < cmCTestGITVersion(1, 6, 5, 0)) {
- recursive = CM_NULLPTR;
+ recursive = nullptr;
// No need to require >= 1.6.5 if there are no submodules.
- if (cmSystemTools::FileExists((top_dir + "/.gitmodules").c_str())) {
+ if (cmSystemTools::FileExists(top_dir + "/.gitmodules")) {
this->Log << "Git < 1.6.5 cannot update submodules recursively\n";
}
}
// Git < 1.8.1 did not support sync --recursive
if (this->GetGitVersion() < cmCTestGITVersion(1, 8, 1, 0)) {
- sync_recursive = CM_NULLPTR;
+ sync_recursive = nullptr;
// No need to require >= 1.8.1 if there are no submodules.
- if (cmSystemTools::FileExists((top_dir + "/.gitmodules").c_str())) {
+ if (cmSystemTools::FileExists(top_dir + "/.gitmodules")) {
this->Log << "Git < 1.8.1 cannot synchronize submodules recursively\n";
}
}
@@ -273,9 +270,8 @@ bool cmCTestGIT::UpdateImpl()
std::string init_submodules =
this->CTest->GetCTestConfiguration("GITInitSubmodules");
- if (cmSystemTools::IsOn(init_submodules.c_str())) {
- char const* git_submodule_init[] = { git, "submodule", "init",
- CM_NULLPTR };
+ if (cmSystemTools::IsOn(init_submodules)) {
+ char const* git_submodule_init[] = { git, "submodule", "init", nullptr };
ret = this->RunChild(git_submodule_init, &submodule_out, &submodule_err,
top_dir.c_str());
@@ -285,7 +281,7 @@ bool cmCTestGIT::UpdateImpl()
}
char const* git_submodule_sync[] = { git, "submodule", "sync",
- sync_recursive, CM_NULLPTR };
+ sync_recursive, nullptr };
ret = this->RunChild(git_submodule_sync, &submodule_out, &submodule_err,
top_dir.c_str());
@@ -294,7 +290,7 @@ bool cmCTestGIT::UpdateImpl()
}
char const* git_submodule[] = { git, "submodule", "update", recursive,
- CM_NULLPTR };
+ nullptr };
return this->RunChild(git_submodule, &submodule_out, &submodule_err,
top_dir.c_str());
}
@@ -303,7 +299,7 @@ unsigned int cmCTestGIT::GetGitVersion()
{
if (!this->CurrentGitVersion) {
const char* git = this->CommandLineTool.c_str();
- char const* git_version[] = { git, "--version", CM_NULLPTR };
+ char const* git_version[] = { git, "--version", nullptr };
std::string version;
OneLineParser version_out(this, "version-out> ", version);
OutputLogger version_err(this->Log, "version-err> ");
@@ -359,7 +355,7 @@ protected:
this->Changes.clear();
}
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->Line[0] == ':') {
this->DiffField = DiffFieldChange;
@@ -477,15 +473,8 @@ private:
{
std::string Name;
std::string EMail;
- unsigned long Time;
- long TimeZone;
- Person()
- : Name()
- , EMail()
- , Time(0)
- , TimeZone(0)
- {
- }
+ unsigned long Time = 0;
+ long TimeZone = 0;
};
void ParsePerson(const char* str, Person& person)
@@ -513,11 +502,11 @@ private:
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);
+ person.Time = strtoul(c, const_cast<char**>(&c), 10);
+ person.TimeZone = strtol(c, const_cast<char**>(&c), 10);
}
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->Line.empty()) {
if (this->Section == SectionBody && this->LineEnd == '\0') {
@@ -557,15 +546,15 @@ private:
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 ")) {
+ if (cmHasLiteralPrefix(this->Line, "commit ")) {
+ this->Rev.Rev = this->Line.substr(7);
+ } else if (cmHasLiteralPrefix(this->Line, "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 ")) {
+ } else if (cmHasLiteralPrefix(this->Line, "committer ")) {
Person committer;
this->ParsePerson(this->Line.c_str() + 10, committer);
this->Rev.Committer = committer.Name;
@@ -615,13 +604,13 @@ bool cmCTestGIT::LoadRevisions()
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(), "--", CM_NULLPTR };
+ range.c_str(), "--", nullptr };
const char* git_diff_tree[] = {
git, "diff-tree", "--stdin", "--always", "-z",
- "-r", "--pretty=raw", "--encoding=utf-8", CM_NULLPTR
+ "-r", "--pretty=raw", "--encoding=utf-8", nullptr
};
- this->Log << this->ComputeCommandLine(git_rev_list) << " | "
- << this->ComputeCommandLine(git_diff_tree) << "\n";
+ this->Log << cmCTestGIT::ComputeCommandLine(git_rev_list) << " | "
+ << cmCTestGIT::ComputeCommandLine(git_diff_tree) << "\n";
cmsysProcess* cp = cmsysProcess_New();
cmsysProcess_AddCommand(cp, git_rev_list);
@@ -630,7 +619,7 @@ bool cmCTestGIT::LoadRevisions()
CommitParser out(this, "dt-out> ");
OutputLogger err(this->Log, "dt-err> ");
- this->RunProcess(cp, &out, &err, cmProcessOutput::UTF8);
+ cmCTestGIT::RunProcess(cp, &out, &err, cmProcessOutput::UTF8);
// Send one extra zero-byte to terminate the last record.
out.Process("", 1);
@@ -645,23 +634,21 @@ bool cmCTestGIT::LoadModifications()
// Use 'git update-index' to refresh the index w.r.t. the work tree.
const char* git_update_index[] = { git, "update-index", "--refresh",
- CM_NULLPTR };
+ nullptr };
OutputLogger ui_out(this->Log, "ui-out> ");
OutputLogger ui_err(this->Log, "ui-err> ");
- this->RunChild(git_update_index, &ui_out, &ui_err, CM_NULLPTR,
+ this->RunChild(git_update_index, &ui_out, &ui_err, nullptr,
cmProcessOutput::UTF8);
// Use 'git diff-index' to get modified files.
const char* git_diff_index[] = { git, "diff-index", "-z",
- "HEAD", "--", CM_NULLPTR };
+ "HEAD", "--", nullptr };
DiffParser out(this, "di-out> ");
OutputLogger err(this->Log, "di-err> ");
- this->RunChild(git_diff_index, &out, &err, CM_NULLPTR,
- cmProcessOutput::UTF8);
+ this->RunChild(git_diff_index, &out, &err, nullptr, cmProcessOutput::UTF8);
- for (std::vector<Change>::const_iterator ci = out.Changes.begin();
- ci != out.Changes.end(); ++ci) {
- this->DoModification(PathModified, ci->Path);
+ for (Change const& c : out.Changes) {
+ this->DoModification(PathModified, c.Path);
}
return true;
}
diff --git a/Source/CTest/cmCTestGIT.h b/Source/CTest/cmCTestGIT.h
index 4bf8294e6..ade430fae 100644
--- a/Source/CTest/cmCTestGIT.h
+++ b/Source/CTest/cmCTestGIT.h
@@ -3,7 +3,7 @@
#ifndef cmCTestGIT_h
#define cmCTestGIT_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGlobalVC.h"
@@ -22,15 +22,15 @@ public:
/** Construct with a CTest instance and update log stream. */
cmCTestGIT(cmCTest* ctest, std::ostream& log);
- ~cmCTestGIT() CM_OVERRIDE;
+ ~cmCTestGIT() override;
private:
unsigned int CurrentGitVersion;
unsigned int GetGitVersion();
std::string GetWorkingRevision();
- bool NoteOldRevision() CM_OVERRIDE;
- bool NoteNewRevision() CM_OVERRIDE;
- bool UpdateImpl() CM_OVERRIDE;
+ bool NoteOldRevision() override;
+ bool NoteNewRevision() override;
+ bool UpdateImpl() override;
std::string FindGitDir();
std::string FindTopDir();
@@ -39,8 +39,8 @@ private:
bool UpdateByCustom(std::string const& custom);
bool UpdateInternal();
- bool LoadRevisions() CM_OVERRIDE;
- bool LoadModifications() CM_OVERRIDE;
+ bool LoadRevisions() override;
+ bool LoadModifications() override;
// "public" needed by older Sun compilers
public:
diff --git a/Source/CTest/cmCTestGenericHandler.cxx b/Source/CTest/cmCTestGenericHandler.cxx
index 19034c01b..d3020b513 100644
--- a/Source/CTest/cmCTestGenericHandler.cxx
+++ b/Source/CTest/cmCTestGenericHandler.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestGenericHandler.h"
-#include "cmConfigure.h"
#include <sstream>
#include <utility>
@@ -12,16 +11,14 @@
cmCTestGenericHandler::cmCTestGenericHandler()
{
this->HandlerVerbose = cmSystemTools::OUTPUT_NONE;
- this->CTest = CM_NULLPTR;
+ this->CTest = nullptr;
this->SubmitIndex = 0;
this->AppendXML = false;
this->Quiet = false;
this->TestLoad = 0;
}
-cmCTestGenericHandler::~cmCTestGenericHandler()
-{
-}
+cmCTestGenericHandler::~cmCTestGenericHandler() = default;
void cmCTestGenericHandler::SetOption(const std::string& op, const char* value)
{
@@ -58,10 +55,8 @@ void cmCTestGenericHandler::Initialize()
this->AppendXML = false;
this->TestLoad = 0;
this->Options.clear();
- t_StringToString::iterator it;
- for (it = this->PersistentOptions.begin();
- it != this->PersistentOptions.end(); ++it) {
- this->Options[it->first] = it->second;
+ for (auto const& po : this->PersistentOptions) {
+ this->Options[po.first] = po.second;
}
}
@@ -70,7 +65,7 @@ const char* cmCTestGenericHandler::GetOption(const std::string& op)
cmCTestGenericHandler::t_StringToString::iterator remit =
this->Options.find(op);
if (remit == this->Options.end()) {
- return CM_NULLPTR;
+ return nullptr;
}
return remit->second.c_str();
}
@@ -103,8 +98,9 @@ bool cmCTestGenericHandler::StartResultingXML(cmCTest::Part part,
}
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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create resulting XML file: " << ostr.str()
+ << std::endl);
return false;
}
this->CTest->AddSubmitFile(part, ostr.str().c_str());
diff --git a/Source/CTest/cmCTestGenericHandler.h b/Source/CTest/cmCTestGenericHandler.h
index e881252c9..cf91b4fa6 100644
--- a/Source/CTest/cmCTestGenericHandler.h
+++ b/Source/CTest/cmCTestGenericHandler.h
@@ -25,7 +25,7 @@ class cmCTestGenericHandler
{
public:
/**
- * If verbose then more informaiton is printed out
+ * If verbose then more information is printed out
*/
void SetVerbose(bool val)
{
diff --git a/Source/CTest/cmCTestGlobalVC.cxx b/Source/CTest/cmCTestGlobalVC.cxx
index 25294b5ae..54ebd4f0c 100644
--- a/Source/CTest/cmCTestGlobalVC.cxx
+++ b/Source/CTest/cmCTestGlobalVC.cxx
@@ -15,9 +15,7 @@ cmCTestGlobalVC::cmCTestGlobalVC(cmCTest* ct, std::ostream& log)
this->PriorRev = this->Unknown;
}
-cmCTestGlobalVC::~cmCTestGlobalVC()
-{
-}
+cmCTestGlobalVC::~cmCTestGlobalVC() = default;
const char* cmCTestGlobalVC::LocalPath(std::string const& path)
{
@@ -48,15 +46,14 @@ void cmCTestGlobalVC::DoRevision(Revision const& revision,
/* clang-format on */
// 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)) {
+ for (Change const& c : changes) {
+ if (const char* local = this->LocalPath(c.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 << " "
+ this->Log << " " << c.Action << " " << local << " "
<< "\n";
}
}
@@ -83,9 +80,9 @@ void cmCTestGlobalVC::WriteXMLDirectory(cmXMLWriter& xml,
const char* slash = path.empty() ? "" : "/";
xml.StartElement("Directory");
xml.Element("Name", path);
- 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);
+ for (auto const& f : dir) {
+ std::string const full = path + slash + f.first;
+ this->WriteXMLEntry(xml, path, f.first, full, f.second);
}
xml.EndElement(); // Directory
}
@@ -114,11 +111,14 @@ bool cmCTestGlobalVC::WriteXMLUpdates(cmXMLWriter& xml)
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);
+ for (auto const& d : this->Dirs) {
+ this->WriteXMLDirectory(xml, d.first, d.second);
}
return result;
}
+
+void cmCTestGlobalVC::SetNewRevision(std::string const& revision)
+{
+ this->NewRevision = revision;
+}
diff --git a/Source/CTest/cmCTestGlobalVC.h b/Source/CTest/cmCTestGlobalVC.h
index a5273d3dd..9c572152e 100644
--- a/Source/CTest/cmCTestGlobalVC.h
+++ b/Source/CTest/cmCTestGlobalVC.h
@@ -3,7 +3,7 @@
#ifndef cmCTestGlobalVC_h
#define cmCTestGlobalVC_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestVC.h"
@@ -26,11 +26,13 @@ public:
/** Construct with a CTest instance and update log stream. */
cmCTestGlobalVC(cmCTest* ctest, std::ostream& log);
- ~cmCTestGlobalVC() CM_OVERRIDE;
+ ~cmCTestGlobalVC() override;
protected:
// Implement cmCTestVC internal API.
- bool WriteXMLUpdates(cmXMLWriter& xml) CM_OVERRIDE;
+ bool WriteXMLUpdates(cmXMLWriter& xml) override;
+
+ void SetNewRevision(std::string const& revision) override;
/** Represent a vcs-reported action for one path in a revision. */
struct Change
diff --git a/Source/CTest/cmCTestHG.cxx b/Source/CTest/cmCTestHG.cxx
index 49f9a6500..ba2252a30 100644
--- a/Source/CTest/cmCTestHG.cxx
+++ b/Source/CTest/cmCTestHG.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestHG.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestVC.h"
#include "cmProcessTools.h"
@@ -18,9 +19,7 @@ cmCTestHG::cmCTestHG(cmCTest* ct, std::ostream& log)
this->PriorRev = this->Unknown;
}
-cmCTestHG::~cmCTestHG()
-{
-}
+cmCTestHG::~cmCTestHG() = default;
class cmCTestHG::IdentifyParser : public cmCTestVC::LineParser
{
@@ -36,7 +35,7 @@ private:
std::string& Rev;
cmsys::RegularExpression RegexIdentify;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexIdentify.find(this->Line)) {
this->Rev = this->RegexIdentify.match(1);
@@ -60,7 +59,7 @@ private:
cmCTestHG* HG;
cmsys::RegularExpression RegexStatus;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexStatus.find(this->Line)) {
this->DoPath(this->RegexStatus.match(1)[0], this->RegexStatus.match(2));
@@ -96,7 +95,7 @@ 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", CM_NULLPTR };
+ const char* hg_identify[] = { hg, "identify", "-i", nullptr };
std::string rev;
IdentifyParser out(this, "rev-out> ", rev);
OutputLogger err(this->Log, "rev-err> ");
@@ -107,8 +106,9 @@ std::string cmCTestHG::GetWorkingRevision()
bool cmCTestHG::NoteOldRevision()
{
this->OldRevision = this->GetWorkingRevision();
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
- << this->OldRevision << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Old revision of repository is: " << this->OldRevision
+ << "\n");
this->PriorRev.Rev = this->OldRevision;
return true;
}
@@ -116,8 +116,9 @@ bool cmCTestHG::NoteOldRevision()
bool cmCTestHG::NoteNewRevision()
{
this->NewRevision = this->GetWorkingRevision();
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
- << this->NewRevision << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " New revision of repository is: " << this->NewRevision
+ << "\n");
return true;
}
@@ -126,7 +127,7 @@ 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", CM_NULLPTR };
+ const char* hg_pull[] = { hg, "pull", "-v", nullptr };
OutputLogger out(this->Log, "pull-out> ");
OutputLogger err(this->Log, "pull-err> ");
this->RunChild(&hg_pull[0], &out, &err);
@@ -144,22 +145,22 @@ bool cmCTestHG::UpdateImpl()
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());
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
+ for (std::string const& arg : args) {
+ hg_update.push_back(arg.c_str());
}
// Sentinel argument.
- hg_update.push_back(CM_NULLPTR);
+ hg_update.push_back(nullptr);
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
+class cmCTestHG::LogParser
+ : public cmCTestVC::OutputLogger
+ , private cmXMLParser
{
public:
LogParser(cmCTestHG* hg, const char* prefix)
@@ -168,7 +169,8 @@ public:
{
this->InitializeParser();
}
- ~LogParser() CM_OVERRIDE { this->CleanupParser(); }
+ ~LogParser() override { this->CleanupParser(); }
+
private:
cmCTestHG* HG;
@@ -179,31 +181,32 @@ private:
Change CurChange;
std::vector<char> CData;
- bool ProcessChunk(const char* data, int length) CM_OVERRIDE
+ bool ProcessChunk(const char* data, int length) override
{
this->OutputLogger::ProcessChunk(data, length);
this->ParseChunk(data, length);
return true;
}
- void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** atts) override
{
this->CData.clear();
if (name == "logentry") {
this->Rev = Revision();
- if (const char* rev = this->FindAttribute(atts, "revision")) {
+ if (const char* rev =
+ cmCTestHG::LogParser::FindAttribute(atts, "revision")) {
this->Rev.Rev = rev;
}
this->Changes.clear();
}
}
- void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
+ void CharacterDataHandler(const char* data, int length) override
{
- this->CData.insert(this->CData.end(), data, data + length);
+ cmAppend(this->CData, data, data + length);
}
- void EndElement(const std::string& name) CM_OVERRIDE
+ void EndElement(const std::string& name) override
{
if (name == "logentry") {
this->HG->DoRevision(this->Rev, this->Changes);
@@ -217,25 +220,25 @@ private:
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) {
+ for (std::string const& path : paths) {
// Updated by default, will be modified using file_adds and
// file_dels.
this->CurChange = Change('U');
- this->CurChange.Path = paths[i];
+ this->CurChange.Path = path;
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';
+ for (Change& change : this->Changes) {
+ if (added_paths.find(change.Path) != std::string::npos) {
+ change.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';
+ for (Change& change : this->Changes) {
+ if (added_paths.find(change.Path) != std::string::npos) {
+ change.Action = 'D';
}
}
}
@@ -246,19 +249,19 @@ private:
{
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];
+ for (char i : this->CData) {
+ if (i != ' ') {
+ currPath += i;
} else {
output.push_back(currPath);
- currPath = "";
+ currPath.clear();
}
}
output.push_back(currPath);
return output;
}
- void ReportError(int /*line*/, int /*column*/, const char* msg) CM_OVERRIDE
+ void ReportError(int /*line*/, int /*column*/, const char* msg) override
{
this->HG->Log << "Error parsing hg log xml: " << msg << "\n";
}
@@ -286,7 +289,7 @@ bool cmCTestHG::LoadRevisions()
"</logentry>\n";
const char* hg_log[] = {
hg, "log", "--removed", "-r", range.c_str(),
- "--template", hgXMLTemplate, CM_NULLPTR
+ "--template", hgXMLTemplate, nullptr
};
LogParser out(this, "log-out> ");
@@ -302,7 +305,7 @@ bool cmCTestHG::LoadModifications()
{
// Use 'hg status' to get modified files.
const char* hg = this->CommandLineTool.c_str();
- const char* hg_status[] = { hg, "status", CM_NULLPTR };
+ const char* hg_status[] = { hg, "status", nullptr };
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
index ec9eaffe8..c12d61887 100644
--- a/Source/CTest/cmCTestHG.h
+++ b/Source/CTest/cmCTestHG.h
@@ -3,7 +3,7 @@
#ifndef cmCTestHG_h
#define cmCTestHG_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGlobalVC.h"
@@ -22,16 +22,16 @@ public:
/** Construct with a CTest instance and update log stream. */
cmCTestHG(cmCTest* ctest, std::ostream& log);
- ~cmCTestHG() CM_OVERRIDE;
+ ~cmCTestHG() override;
private:
std::string GetWorkingRevision();
- bool NoteOldRevision() CM_OVERRIDE;
- bool NoteNewRevision() CM_OVERRIDE;
- bool UpdateImpl() CM_OVERRIDE;
+ bool NoteOldRevision() override;
+ bool NoteNewRevision() override;
+ bool UpdateImpl() override;
- bool LoadRevisions() CM_OVERRIDE;
- bool LoadModifications() CM_OVERRIDE;
+ bool LoadRevisions() override;
+ bool LoadModifications() override;
// Parsing helper classes.
class IdentifyParser;
diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx
index c99e450d0..adf955399 100644
--- a/Source/CTest/cmCTestHandlerCommand.cxx
+++ b/Source/CTest/cmCTestHandlerCommand.cxx
@@ -5,10 +5,11 @@
#include "cmCTest.h"
#include "cmCTestGenericHandler.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
-#include "cmake.h"
+#include <cstring>
#include <sstream>
#include <stdlib.h>
@@ -20,7 +21,7 @@ cmCTestHandlerCommand::cmCTestHandlerCommand()
size_t cc;
this->Arguments.reserve(INIT_SIZE);
for (cc = 0; cc < INIT_SIZE; ++cc) {
- this->Arguments.push_back(CM_NULLPTR);
+ this->Arguments.push_back(nullptr);
}
this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
this->Arguments[ct_CAPTURE_CMAKE_ERROR] = "CAPTURE_CMAKE_ERROR";
@@ -75,6 +76,8 @@ public:
}
}
}
+ SaveRestoreErrorState(const SaveRestoreErrorState&) = delete;
+ SaveRestoreErrorState& operator=(const SaveRestoreErrorState&) = delete;
private:
bool InitialErrorState;
@@ -89,7 +92,7 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
SaveRestoreErrorState errorState;
// Allocate space for argument values.
this->Values.clear();
- this->Values.resize(this->Last, CM_NULLPTR);
+ this->Values.resize(this->Last, nullptr);
// Process input arguments.
this->ArgumentDoing = ArgumentDoingNone;
@@ -97,12 +100,11 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
// bad one so that CAPTURE_CMAKE_ERROR can override setting the
// global error state
bool foundBadArgument = false;
- for (unsigned int i = 0; i < args.size(); ++i) {
+ for (std::string const& arg : args) {
// Check this argument.
- if (!this->CheckArgumentKeyword(args[i]) &&
- !this->CheckArgumentValue(args[i])) {
+ if (!this->CheckArgumentKeyword(arg) && !this->CheckArgumentValue(arg)) {
std::ostringstream e;
- e << "called with unknown argument \"" << args[i] << "\".";
+ e << "called with unknown argument \"" << arg << "\".";
this->SetError(e.str());
foundBadArgument = true;
}
@@ -151,20 +153,21 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
cmSystemTools::CollapseFullPath(this->Values[ct_BUILD]).c_str(),
this->Quiet);
} else {
- const char* bdir =
+ std::string const& bdir =
this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
- if (bdir) {
+ if (!bdir.empty()) {
this->CTest->SetCTestConfiguration(
"BuildDirectory", cmSystemTools::CollapseFullPath(bdir).c_str(),
this->Quiet);
} else {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "CTEST_BINARY_DIRECTORY not set"
- << std::endl;);
+ 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);
+ 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(),
@@ -186,8 +189,9 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot instantiate test handler " << this->GetName()
+ << std::endl);
if (capureCMakeError) {
this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
"-1");
@@ -204,21 +208,25 @@ bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
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]));
- }
+ handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
}
cmWorkingDirectory workdir(
this->CTest->GetCTestConfiguration("BuildDirectory"));
+ if (workdir.Failed()) {
+ this->SetError("failed to change directory to " +
+ this->CTest->GetCTestConfiguration("BuildDirectory") +
+ " : " + std::strerror(workdir.GetLastResult()));
+ if (capureCMakeError) {
+ this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
+ "-1");
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ this->GetName() << " " << this->GetError() << "\n");
+ // return success because failure is recorded in CAPTURE_CMAKE_ERROR
+ return true;
+ }
+ return false;
+ }
+
int res = handler->ProcessHandler();
if (this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE]) {
std::ostringstream str;
@@ -283,13 +291,13 @@ bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
if (this->Values[k]) {
std::ostringstream e;
e << "Called with more than one value for " << this->Arguments[k];
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::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");
+ 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
index 0ea061225..79d61f3c7 100644
--- a/Source/CTest/cmCTestHandlerCommand.h
+++ b/Source/CTest/cmCTestHandlerCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestHandlerCommand_h
#define cmCTestHandlerCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
@@ -34,7 +34,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
enum
{
diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx
index 5b213518a..a96513e8c 100644
--- a/Source/CTest/cmCTestLaunch.cxx
+++ b/Source/CTest/cmCTestLaunch.cxx
@@ -2,12 +2,11 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestLaunch.h"
-#include "cmConfigure.h"
-
#include "cmsys/FStream.hxx"
#include "cmsys/Process.h"
#include "cmsys/RegularExpression.hxx"
#include <iostream>
+#include <memory> // IWYU pragma: keep
#include <stdlib.h>
#include <string.h>
@@ -16,22 +15,22 @@
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmProcessOutput.h"
+#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmXMLWriter.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
#ifdef _WIN32
-#include <fcntl.h> // for _O_BINARY
-#include <io.h> // for _setmode
-#include <stdio.h> // for std{out,err} and fileno
+# include <fcntl.h> // for _O_BINARY
+# include <io.h> // for _setmode
+# include <stdio.h> // for std{out,err} and fileno
#endif
cmCTestLaunch::cmCTestLaunch(int argc, const char* const* argv)
{
this->Passthru = true;
- this->Process = CM_NULLPTR;
+ this->Process = nullptr;
this->ExitCode = 1;
this->CWD = cmSystemTools::GetCurrentWorkingDirectory();
@@ -129,7 +128,7 @@ bool cmCTestLaunch::ParseArguments(int argc, const char* const* argv)
return true;
}
this->RealArgC = 0;
- this->RealArgV = CM_NULLPTR;
+ this->RealArgV = nullptr;
std::cerr << "No launch/command separator ('--') found!\n";
return false;
}
@@ -147,7 +146,7 @@ void cmCTestLaunch::HandleRealArg(const char* arg)
return;
}
#endif
- this->RealArgs.push_back(arg);
+ this->RealArgs.emplace_back(arg);
}
void cmCTestLaunch::ComputeFileNames()
@@ -171,9 +170,8 @@ void cmCTestLaunch::ComputeFileNames()
cmCryptoHash md5(cmCryptoHash::AlgoMD5);
md5.Initialize();
md5.Append(this->CWD);
- for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
- ai != this->RealArgs.end(); ++ai) {
- md5.Append(*ai);
+ for (std::string const& realArg : this->RealArgs) {
+ md5.Append(realArg);
}
this->LogHash = md5.FinalizeHex();
@@ -224,11 +222,11 @@ void cmCTestLaunch::RunChild()
// Record child stdout and stderr if necessary.
if (!this->Passthru) {
- char* data = CM_NULLPTR;
+ char* data = nullptr;
int length = 0;
cmProcessOutput processOutput;
std::string strdata;
- while (int p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) {
+ while (int p = cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
if (p == cmsysProcess_Pipe_STDOUT) {
processOutput.DecodeText(data, length, strdata, 1);
fout.write(strdata.c_str(), strdata.size());
@@ -254,7 +252,7 @@ void cmCTestLaunch::RunChild()
}
// Wait for the real command to finish.
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
this->ExitCode = cmsysProcess_GetExitValue(cp);
}
@@ -285,7 +283,7 @@ void cmCTestLaunch::LoadLabels()
// Labels are listed in per-target files.
std::string fname = this->OptionBuildDir;
- fname += cmake::GetCMakeFilesDirectory();
+ fname += "/CMakeFiles";
fname += "/";
fname += this->OptionTargetName;
fname += ".dir/Labels.txt";
@@ -310,7 +308,7 @@ void cmCTestLaunch::LoadLabels()
if (line[0] == ' ') {
// Label lines appear indented by one space.
if (inTarget || inSource) {
- this->Labels.insert(line.c_str() + 1);
+ this->Labels.insert(line.substr(1));
}
} else if (!this->OptionSource.empty() && !inSource) {
// Non-indented lines specify a source file name. The first one
@@ -348,30 +346,29 @@ void cmCTestLaunch::WriteXML()
logXML += ".xml";
// Use cmGeneratedFileStream to atomically create the report file.
- cmGeneratedFileStream fxml(logXML.c_str());
+ cmGeneratedFileStream fxml(logXML);
cmXMLWriter xml(fxml, 2);
- xml.StartElement("Failure");
- xml.Attribute("type", this->IsError() ? "Error" : "Warning");
- this->WriteXMLAction(xml);
- this->WriteXMLCommand(xml);
- this->WriteXMLResult(xml);
- this->WriteXMLLabels(xml);
- xml.EndElement(); // Failure
+ cmXMLElement e2(xml, "Failure");
+ e2.Attribute("type", this->IsError() ? "Error" : "Warning");
+ this->WriteXMLAction(e2);
+ this->WriteXMLCommand(e2);
+ this->WriteXMLResult(e2);
+ this->WriteXMLLabels(e2);
}
-void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
+void cmCTestLaunch::WriteXMLAction(cmXMLElement& e2)
{
- xml.Comment("Meta-information about the build action");
- xml.StartElement("Action");
+ e2.Comment("Meta-information about the build action");
+ cmXMLElement e3(e2, "Action");
// TargetName
if (!this->OptionTargetName.empty()) {
- xml.Element("TargetName", this->OptionTargetName);
+ e3.Element("TargetName", this->OptionTargetName);
}
// Language
if (!this->OptionLanguage.empty()) {
- xml.Element("Language", this->OptionLanguage);
+ e3.Element("Language", this->OptionLanguage);
}
// SourceFile
@@ -380,23 +377,22 @@ void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
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()) &&
+ if (cmSystemTools::FileIsFullPath(this->SourceDir) &&
+ cmSystemTools::FileIsFullPath(source) &&
cmSystemTools::IsSubDirectory(source, this->SourceDir)) {
- source =
- cmSystemTools::RelativePath(this->SourceDir.c_str(), source.c_str());
+ source = cmSystemTools::RelativePath(this->SourceDir, source);
}
- xml.Element("SourceFile", source);
+ e3.Element("SourceFile", source);
}
// OutputFile
if (!this->OptionOutput.empty()) {
- xml.Element("OutputFile", this->OptionOutput);
+ e3.Element("OutputFile", this->OptionOutput);
}
// OutputType
- const char* outputType = CM_NULLPTR;
+ const char* outputType = nullptr;
if (!this->OptionTargetType.empty()) {
if (this->OptionTargetType == "EXECUTABLE") {
outputType = "executable";
@@ -411,106 +407,99 @@ void cmCTestLaunch::WriteXMLAction(cmXMLWriter& xml)
outputType = "object file";
}
if (outputType) {
- xml.Element("OutputType", outputType);
+ e3.Element("OutputType", outputType);
}
-
- xml.EndElement(); // Action
}
-void cmCTestLaunch::WriteXMLCommand(cmXMLWriter& xml)
+void cmCTestLaunch::WriteXMLCommand(cmXMLElement& e2)
{
- xml.Comment("Details of command");
- xml.StartElement("Command");
+ e2.Comment("Details of command");
+ cmXMLElement e3(e2, "Command");
if (!this->CWD.empty()) {
- xml.Element("WorkingDirectory", this->CWD);
+ e3.Element("WorkingDirectory", this->CWD);
}
- for (std::vector<std::string>::const_iterator ai = this->RealArgs.begin();
- ai != this->RealArgs.end(); ++ai) {
- xml.Element("Argument", *ai);
+ for (std::string const& realArg : this->RealArgs) {
+ e3.Element("Argument", realArg);
}
- xml.EndElement(); // Command
}
-void cmCTestLaunch::WriteXMLResult(cmXMLWriter& xml)
+void cmCTestLaunch::WriteXMLResult(cmXMLElement& e2)
{
- xml.Comment("Result of command");
- xml.StartElement("Result");
+ e2.Comment("Result of command");
+ cmXMLElement e3(e2, "Result");
// StdOut
- xml.StartElement("StdOut");
- this->DumpFileToXML(xml, this->LogOut);
- xml.EndElement(); // StdOut
+ this->DumpFileToXML(e3, "StdOut", this->LogOut);
// StdErr
- xml.StartElement("StdErr");
- this->DumpFileToXML(xml, this->LogErr);
- xml.EndElement(); // StdErr
+ this->DumpFileToXML(e3, "StdErr", this->LogErr);
// ExitCondition
- xml.StartElement("ExitCondition");
+ cmXMLElement e4(e3, "ExitCondition");
cmsysProcess* cp = this->Process;
switch (cmsysProcess_GetState(cp)) {
case cmsysProcess_State_Starting:
- xml.Content("No process has been executed");
+ e4.Content("No process has been executed");
break;
case cmsysProcess_State_Executing:
- xml.Content("The process is still executing");
+ e4.Content("The process is still executing");
break;
case cmsysProcess_State_Disowned:
- xml.Content("Disowned");
+ e4.Content("Disowned");
break;
case cmsysProcess_State_Killed:
- xml.Content("Killed by parent");
+ e4.Content("Killed by parent");
break;
case cmsysProcess_State_Expired:
- xml.Content("Killed when timeout expired");
+ e4.Content("Killed when timeout expired");
break;
case cmsysProcess_State_Exited:
- xml.Content(this->ExitCode);
+ e4.Content(this->ExitCode);
break;
case cmsysProcess_State_Exception:
- xml.Content("Terminated abnormally: ");
- xml.Content(cmsysProcess_GetExceptionString(cp));
+ e4.Content("Terminated abnormally: ");
+ e4.Content(cmsysProcess_GetExceptionString(cp));
break;
case cmsysProcess_State_Error:
- xml.Content("Error administrating child process: ");
- xml.Content(cmsysProcess_GetErrorString(cp));
+ e4.Content("Error administrating child process: ");
+ e4.Content(cmsysProcess_GetErrorString(cp));
break;
- };
- xml.EndElement(); // ExitCondition
-
- xml.EndElement(); // Result
+ }
}
-void cmCTestLaunch::WriteXMLLabels(cmXMLWriter& xml)
+void cmCTestLaunch::WriteXMLLabels(cmXMLElement& e2)
{
this->LoadLabels();
if (!this->Labels.empty()) {
- xml.Comment("Interested parties");
- xml.StartElement("Labels");
- for (std::set<std::string>::const_iterator li = this->Labels.begin();
- li != this->Labels.end(); ++li) {
- xml.Element("Label", *li);
+ e2.Comment("Interested parties");
+ cmXMLElement e3(e2, "Labels");
+ for (std::string const& label : this->Labels) {
+ e3.Element("Label", label);
}
- xml.EndElement(); // Labels
}
}
-void cmCTestLaunch::DumpFileToXML(cmXMLWriter& xml, std::string const& fname)
+void cmCTestLaunch::DumpFileToXML(cmXMLElement& e3, const char* tag,
+ std::string const& fname)
{
cmsys::ifstream fin(fname.c_str(), std::ios::in | std::ios::binary);
std::string line;
const char* sep = "";
+ cmXMLElement e4(e3, tag);
while (cmSystemTools::GetLineFromStream(fin, line)) {
if (MatchesFilterPrefix(line)) {
continue;
}
-
- xml.Content(sep);
- xml.Content(line);
+ if (this->Match(line, this->RegexWarningSuppress)) {
+ line = "[CTest: warning suppressed] " + line;
+ } else if (this->Match(line, this->RegexWarning)) {
+ line = "[CTest: warning matched] " + line;
+ }
+ e4.Content(sep);
+ e4.Content(line);
sep = "\n";
}
}
@@ -545,9 +534,9 @@ void cmCTestLaunch::LoadScrapeRules()
// 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]");
+ this->RegexWarning.emplace_back("(^|[ :])[Ww][Aa][Rr][Nn][Ii][Nn][Gg]");
+ this->RegexWarning.emplace_back("(^|[ :])[Rr][Ee][Mm][Aa][Rr][Kk]");
+ this->RegexWarning.emplace_back("(^|[ :])[Nn][Oo][Tt][Ee]");
// Load custom match rules given to us by CTest.
this->LoadScrapeRules("Warning", this->RegexWarning);
@@ -565,7 +554,7 @@ void cmCTestLaunch::LoadScrapeRules(
std::string line;
cmsys::RegularExpression rex;
while (cmSystemTools::GetLineFromStream(fin, line)) {
- if (rex.compile(line.c_str())) {
+ if (rex.compile(line)) {
regexps.push_back(rex);
}
}
@@ -595,9 +584,8 @@ bool cmCTestLaunch::ScrapeLog(std::string const& fname)
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())) {
+ for (cmsys::RegularExpression& r : regexps) {
+ if (r.find(line)) {
return true;
}
}
@@ -623,17 +611,16 @@ int cmCTestLaunch::Main(int argc, const char* const argv[])
void cmCTestLaunch::LoadConfig()
{
- cmake cm(cmake::RoleScript);
+ cmake cm(cmake::RoleScript, cmState::CTest);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
- CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
+ cmMakefile mf(&gg, cm.GetCurrentSnapshot());
std::string fname = this->LogDir;
fname += "CTestLaunchConfig.cmake";
- if (cmSystemTools::FileExists(fname.c_str()) &&
- mf->ReadListFile(fname.c_str())) {
- this->SourceDir = mf->GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
+ if (cmSystemTools::FileExists(fname) && mf.ReadListFile(fname)) {
+ this->SourceDir = mf.GetSafeDefinition("CTEST_SOURCE_DIRECTORY");
cmSystemTools::ConvertToUnixSlashes(this->SourceDir);
}
}
diff --git a/Source/CTest/cmCTestLaunch.h b/Source/CTest/cmCTestLaunch.h
index 29986ff60..107fd6174 100644
--- a/Source/CTest/cmCTestLaunch.h
+++ b/Source/CTest/cmCTestLaunch.h
@@ -10,7 +10,7 @@
#include <string>
#include <vector>
-class cmXMLWriter;
+class cmXMLElement;
/** \class cmCTestLaunch
* \brief Launcher for make rules to report results for ctest
@@ -28,6 +28,9 @@ private:
cmCTestLaunch(int argc, const char* const* argv);
~cmCTestLaunch();
+ cmCTestLaunch(const cmCTestLaunch&) = delete;
+ cmCTestLaunch& operator=(const cmCTestLaunch&) = delete;
+
// Run the real command.
int Run();
void RunChild();
@@ -89,11 +92,11 @@ private:
// Methods to generate the xml fragment.
void WriteXML();
- void WriteXMLAction(cmXMLWriter& xml);
- void WriteXMLCommand(cmXMLWriter& xml);
- void WriteXMLResult(cmXMLWriter& xml);
- void WriteXMLLabels(cmXMLWriter& xml);
- void DumpFileToXML(cmXMLWriter& xml, std::string const& fname);
+ void WriteXMLAction(cmXMLElement&);
+ void WriteXMLCommand(cmXMLElement&);
+ void WriteXMLResult(cmXMLElement&);
+ void WriteXMLLabels(cmXMLElement&);
+ void DumpFileToXML(cmXMLElement&, const char* tag, std::string const& fname);
// Configuration
void LoadConfig();
diff --git a/Source/CTest/cmCTestMemCheckCommand.cxx b/Source/CTest/cmCTestMemCheckCommand.cxx
index b9cae3bfe..7dad1cec5 100644
--- a/Source/CTest/cmCTestMemCheckCommand.cxx
+++ b/Source/CTest/cmCTestMemCheckCommand.cxx
@@ -7,21 +7,20 @@
#include <vector>
#include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
#include "cmCTestMemCheckHandler.h"
#include "cmMakefile.h"
cmCTestMemCheckCommand::cmCTestMemCheckCommand()
{
this->Arguments[ctm_DEFECT_COUNT] = "DEFECT_COUNT";
- this->Arguments[ctm_LAST] = CM_NULLPTR;
+ this->Arguments[ctm_LAST] = nullptr;
this->Last = ctm_LAST;
}
cmCTestGenericHandler* cmCTestMemCheckCommand::InitializeActualHandler()
{
- cmCTestGenericHandler* handler =
- this->CTest->GetInitializedHandler("memcheck");
+ cmCTestMemCheckHandler* handler = this->CTest->GetMemCheckHandler();
+ handler->Initialize();
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "MemoryCheckType", "CTEST_MEMORYCHECK_TYPE", this->Quiet);
diff --git a/Source/CTest/cmCTestMemCheckCommand.h b/Source/CTest/cmCTestMemCheckCommand.h
index fa595594a..b6b3c4028 100644
--- a/Source/CTest/cmCTestMemCheckCommand.h
+++ b/Source/CTest/cmCTestMemCheckCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestMemCheckCommand_h
#define cmCTestMemCheckCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestTestCommand.h"
@@ -23,7 +23,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestMemCheckCommand* ni = new cmCTestMemCheckCommand;
ni->CTest = this->CTest;
@@ -32,9 +32,9 @@ public:
}
protected:
- cmCTestGenericHandler* InitializeActualHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeActualHandler() override;
- void ProcessAdditionalValues(cmCTestGenericHandler* handler) CM_OVERRIDE;
+ void ProcessAdditionalValues(cmCTestGenericHandler* handler) override;
enum
{
diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx
index c35f0bc70..b09e7bb22 100644
--- a/Source/CTest/cmCTestMemCheckHandler.cxx
+++ b/Source/CTest/cmCTestMemCheckHandler.cxx
@@ -3,6 +3,7 @@
#include "cmCTestMemCheckHandler.h"
#include "cmCTest.h"
+#include "cmDuration.h"
#include "cmSystemTools.h"
#include "cmXMLParser.h"
#include "cmXMLWriter.h"
@@ -10,9 +11,11 @@
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
+#include <chrono>
#include <iostream>
#include <sstream>
#include <string.h>
+#include <utility>
struct CatToErrorType
{
@@ -28,14 +31,15 @@ static CatToErrorType cmCTestMemCheckBoundsChecker[] = {
{ "Allocation Conflict", cmCTestMemCheckHandler::FMM },
{ "Bad Pointer Use", cmCTestMemCheckHandler::FMW },
{ "Dangling Pointer", cmCTestMemCheckHandler::FMR },
- { CM_NULLPTR, 0 }
+ { nullptr, 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);
+ cmCTest* ctest = static_cast<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
@@ -45,9 +49,9 @@ public:
cmBoundsCheckerParser(cmCTest* c)
{
this->CTest = c;
- this->SetErrorCallback(xmlReportError, (void*)c);
+ this->SetErrorCallback(xmlReportError, c);
}
- void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** atts) override
{
if (name == "MemoryLeak" || name == "ResourceLeak") {
this->Errors.push_back(cmCTestMemCheckHandler::MLK);
@@ -58,23 +62,23 @@ public:
std::ostringstream ostr;
ostr << name << ":\n";
int i = 0;
- for (; atts[i] != CM_NULLPTR; i += 2) {
+ for (; atts[i] != nullptr; i += 2) {
ostr << " " << atts[i] << " - " << atts[i + 1] << "\n";
}
ostr << "\n";
this->Log += ostr.str();
}
- void EndElement(const std::string& /*name*/) CM_OVERRIDE {}
+ void EndElement(const std::string& /*name*/) override {}
const char* GetAttribute(const char* name, const char** atts)
{
int i = 0;
- for (; atts[i] != CM_NULLPTR; ++i) {
+ for (; atts[i] != nullptr; ++i) {
if (strcmp(name, atts[i]) == 0) {
return atts[i + 1];
}
}
- return CM_NULLPTR;
+ return nullptr;
}
void ParseError(const char** atts)
{
@@ -122,11 +126,11 @@ void cmCTestMemCheckHandler::Initialize()
this->LogWithPID = false;
this->CustomMaximumPassedTestOutputSize = 0;
this->CustomMaximumFailedTestOutputSize = 0;
- this->MemoryTester = "";
+ this->MemoryTester.clear();
this->MemoryTesterDynamicOptions.clear();
this->MemoryTesterOptions.clear();
this->MemoryTesterStyle = UNKNOWN;
- this->MemoryTesterOutputFile = "";
+ this->MemoryTesterOutputFile.clear();
this->DefectCount = 0;
}
@@ -157,15 +161,13 @@ int cmCTestMemCheckHandler::PostProcessHandler()
void cmCTestMemCheckHandler::GenerateTestCommand(
std::vector<std::string>& args, int test)
{
- std::vector<std::string>::size_type pp;
std::string index;
std::ostringstream stream;
std::string memcheckcommand =
- cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str());
+ cmSystemTools::ConvertToOutputPath(this->MemoryTester);
stream << test;
index = stream.str();
- for (pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp++) {
- std::string arg = this->MemoryTesterDynamicOptions[pp];
+ for (std::string arg : this->MemoryTesterDynamicOptions) {
std::string::size_type pos = arg.find("??");
if (pos != std::string::npos) {
arg.replace(pos, 2, index);
@@ -177,21 +179,21 @@ void cmCTestMemCheckHandler::GenerateTestCommand(
}
// Create a copy of the memory tester environment variable.
// This is used for memory testing programs that pass options
- // via environment varaibles.
+ // via environment variables.
std::string memTesterEnvironmentVariable =
this->MemoryTesterEnvironmentVariable;
- for (pp = 0; pp < this->MemoryTesterOptions.size(); pp++) {
+ for (std::string const& arg : this->MemoryTesterOptions) {
if (!memTesterEnvironmentVariable.empty()) {
// If we are using env to pass options, append all the options to
// this string with space separation.
- memTesterEnvironmentVariable += " " + this->MemoryTesterOptions[pp];
+ memTesterEnvironmentVariable += " " + arg;
}
// for regular options just add them to args and memcheckcommand
// which is just used for display
else {
- args.push_back(this->MemoryTesterOptions[pp]);
+ args.push_back(arg);
memcheckcommand += " \"";
- memcheckcommand += this->MemoryTesterOptions[pp];
+ memcheckcommand += arg;
memcheckcommand += "\"";
}
}
@@ -228,9 +230,9 @@ void cmCTestMemCheckHandler::InitializeResultsVectors()
// 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", CM_NULLPTR
+ "ABR", "ABW", "ABWL", "COR", "EXU", "FFM", "FIM", "FMM",
+ "FMR", "FMW", "FUM", "IPR", "IPW", "MAF", "MLK", "MPK",
+ "NPR", "ODS", "PAR", "PLK", "UMC", "UMR", nullptr
};
static const char* cmCTestMemCheckResultLongStrings[] = {
"Threading Problem",
@@ -255,12 +257,12 @@ void cmCTestMemCheckHandler::InitializeResultsVectors()
"PLK",
"Uninitialized Memory Conditional",
"Uninitialized Memory Read",
- CM_NULLPTR
+ nullptr
};
this->GlobalResults.clear();
- for (int i = 0; cmCTestMemCheckResultStrings[i] != CM_NULLPTR; ++i) {
- this->ResultStrings.push_back(cmCTestMemCheckResultStrings[i]);
- this->ResultStringsLong.push_back(cmCTestMemCheckResultLongStrings[i]);
+ for (int i = 0; cmCTestMemCheckResultStrings[i] != nullptr; ++i) {
+ this->ResultStrings.emplace_back(cmCTestMemCheckResultStrings[i]);
+ this->ResultStringsLong.emplace_back(cmCTestMemCheckResultLongStrings[i]);
this->GlobalResults.push_back(0);
}
}
@@ -291,6 +293,7 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
return;
}
this->CTest->StartXML(xml, this->AppendXML);
+ this->CTest->GenerateSubprojectsOutput(xml);
xml.StartElement("DynamicAnalysis");
switch (this->MemoryTesterStyle) {
case cmCTestMemCheckHandler::VALGRIND:
@@ -325,9 +328,8 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
xml.Element("StartTestTime", this->StartTestTime);
xml.StartElement("TestList");
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;
+ for (cmCTestTestResult const& result : this->TestResults) {
+ std::string testPath = result.Path + "/" + result.Name;
xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str()));
}
xml.EndElement(); // TestList
@@ -335,12 +337,12 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
"-- Processing memory checking output:\n", this->Quiet);
size_t total = this->TestResults.size();
for (cc = 0; cc < this->TestResults.size(); cc++) {
- cmCTestTestResult* result = &this->TestResults[cc];
+ cmCTestTestResult const& 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) {
+ bool res =
+ this->ProcessMemCheckOutput(result.Output, memcheckstr, memcheckresults);
+ if (res && result.Status == cmCTestMemCheckHandler::COMPLETED) {
continue;
}
this->CleanTestOutput(
@@ -363,12 +365,12 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
xml.EndElement(); // Results
if (memoryErrors > 0) {
const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
- std::string outname = result->Name + " ";
+ std::string outname = result.Name + " ";
outname.resize(maxTestNameWidth + 4, '.');
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, cc + 1
- << "/" << total << " MemCheck: #"
- << result->TestCount << ": " << outname
- << " Defects: " << memoryErrors << std::endl,
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ cc + 1 << "/" << total << " MemCheck: #"
+ << result.TestCount << ": " << outname
+ << " Defects: " << memoryErrors << std::endl,
this->Quiet);
}
xml.StartElement("Log");
@@ -410,8 +412,10 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
xml.Element("EndDateTime", this->EndTest);
xml.Element("EndTestTime", this->EndTestTime);
- xml.Element("ElapsedMinutes",
- static_cast<int>(this->ElapsedTestingTime / 6) / 10.0);
+ xml.Element(
+ "ElapsedMinutes",
+ std::chrono::duration_cast<std::chrono::minutes>(this->ElapsedTestingTime)
+ .count());
xml.EndElement(); // DynamicAnalysis
this->CTest->EndXML(xml);
@@ -419,11 +423,11 @@ void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
bool cmCTestMemCheckHandler::InitializeMemoryChecking()
{
- this->MemoryTesterEnvironmentVariable = "";
- this->MemoryTester = "";
+ this->MemoryTesterEnvironmentVariable.clear();
+ this->MemoryTester.clear();
// Setup the command
if (cmSystemTools::FileExists(
- this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str())) {
+ this->CTest->GetCTestConfiguration("MemoryCheckCommand"))) {
this->MemoryTester =
this->CTest->GetCTestConfiguration("MemoryCheckCommand");
std::string testerName =
@@ -440,17 +444,15 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
this->MemoryTesterStyle = cmCTestMemCheckHandler::UNKNOWN;
}
} else if (cmSystemTools::FileExists(
- this->CTest->GetCTestConfiguration("PurifyCommand").c_str())) {
+ this->CTest->GetCTestConfiguration("PurifyCommand"))) {
this->MemoryTester = this->CTest->GetCTestConfiguration("PurifyCommand");
this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
} else if (cmSystemTools::FileExists(
- this->CTest->GetCTestConfiguration("ValgrindCommand")
- .c_str())) {
+ this->CTest->GetCTestConfiguration("ValgrindCommand"))) {
this->MemoryTester = this->CTest->GetCTestConfiguration("ValgrindCommand");
this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
} else if (cmSystemTools::FileExists(
- this->CTest->GetCTestConfiguration("BoundsCheckerCommand")
- .c_str())) {
+ this->CTest->GetCTestConfiguration("BoundsCheckerCommand"))) {
this->MemoryTester =
this->CTest->GetCTestConfiguration("BoundsCheckerCommand");
this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
@@ -518,7 +520,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
this->CTest->GetCTestConfiguration("ValgrindCommandOptions");
}
this->MemoryTesterOptions =
- cmSystemTools::ParseArguments(memoryTesterOptions.c_str());
+ cmSystemTools::ParseArguments(memoryTesterOptions);
this->MemoryTesterOutputFile =
this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.??.log";
@@ -526,17 +528,16 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
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");
+ this->MemoryTesterOptions.emplace_back("-q");
+ this->MemoryTesterOptions.emplace_back("--tool=memcheck");
+ this->MemoryTesterOptions.emplace_back("--leak-check=yes");
+ this->MemoryTesterOptions.emplace_back("--show-reachable=yes");
+ this->MemoryTesterOptions.emplace_back("--num-callers=50");
}
if (!this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
.empty()) {
- if (!cmSystemTools::FileExists(
- this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
- .c_str())) {
+ if (!cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile"))) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot find memory checker suppression file: "
<< this->CTest->GetCTestConfiguration(
@@ -544,12 +545,12 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
<< std::endl);
return false;
}
- std::string suppressions = "--suppressions=" +
- this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
- this->MemoryTesterOptions.push_back(suppressions);
+ this->MemoryTesterOptions.push_back(
+ "--suppressions=" +
+ this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile"));
}
- std::string outputFile = "--log-file=" + this->MemoryTesterOutputFile;
- this->MemoryTesterDynamicOptions.push_back(outputFile);
+ this->MemoryTesterDynamicOptions.push_back("--log-file=" +
+ this->MemoryTesterOutputFile);
break;
}
case cmCTestMemCheckHandler::PURIFY: {
@@ -557,9 +558,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
#ifdef _WIN32
if (this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
.size()) {
- if (!cmSystemTools::FileExists(
- this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
- .c_str())) {
+ if (!cmSystemTools::FileExists(this->CTest->GetCTestConfiguration(
+ "MemoryCheckSuppressionFile"))) {
cmCTestLog(
this->CTest, ERROR_MESSAGE,
"Cannot find memory checker suppression file: "
@@ -586,11 +586,11 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
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.emplace_back("/B");
+ this->MemoryTesterDynamicOptions.push_back(std::move(dpbdFile));
+ this->MemoryTesterDynamicOptions.emplace_back("/X");
this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile);
- this->MemoryTesterOptions.push_back("/M");
+ this->MemoryTesterOptions.emplace_back("/M");
break;
}
// these are almost the same but the env var used is different
@@ -604,8 +604,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
// 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");
+ this->MemoryTesterDynamicOptions.emplace_back("-E");
+ this->MemoryTesterDynamicOptions.emplace_back("env");
std::string envVar;
std::string extraOptions;
std::string suppressionsOption;
@@ -725,15 +725,14 @@ bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput(
cmsys::RegularExpression leakWarning("(Direct|Indirect) leak of .*");
int defects = 0;
std::vector<std::string> lines;
- cmSystemTools::Split(str.c_str(), lines);
+ cmsys::SystemTools::Split(str, lines);
std::ostringstream ostr;
- log = "";
- for (std::vector<std::string>::iterator i = lines.begin(); i != lines.end();
- ++i) {
+ log.clear();
+ for (std::string const& l : lines) {
std::string resultFound;
- if (leakWarning.find(*i)) {
+ if (leakWarning.find(l)) {
resultFound = leakWarning.match(1) + " leak";
- } else if (sanitizerWarning.find(*i)) {
+ } else if (sanitizerWarning.find(l)) {
resultFound = sanitizerWarning.match(1);
}
if (!resultFound.empty()) {
@@ -746,7 +745,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput(
defects++;
ostr << "<b>" << this->ResultStrings[idx] << "</b> ";
}
- ostr << *i << std::endl;
+ ostr << l << std::endl;
}
log = ostr.str();
this->DefectCount += defects;
@@ -756,18 +755,17 @@ 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);
+ cmsys::SystemTools::Split(str, lines);
std::ostringstream ostr;
- log = "";
+ log.clear();
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) {
+ for (std::string const& l : lines) {
std::vector<int>::size_type failure = this->ResultStrings.size();
- if (pfW.find(*i)) {
+ if (pfW.find(l)) {
std::vector<int>::size_type cc;
for (cc = 0; cc < this->ResultStrings.size(); cc++) {
if (pfW.match(1) == this->ResultStrings[cc]) {
@@ -776,8 +774,9 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput(
}
}
if (cc == this->ResultStrings.size()) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown Purify memory fault: "
- << pfW.match(1) << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unknown Purify memory fault: " << pfW.match(1)
+ << std::endl);
ostr << "*** Unknown Purify memory fault: " << pfW.match(1)
<< std::endl;
}
@@ -787,7 +786,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput(
results[failure]++;
defects++;
}
- ostr << *i << std::endl;
+ ostr << l << std::endl;
}
log = ostr.str();
@@ -799,7 +798,7 @@ 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);
+ cmsys::SystemTools::Split(str, lines);
bool unlimitedOutput = false;
if (str.find("CTEST_FULL_OUTPUT") != std::string::npos ||
this->CustomMaximumFailedTestOutputSize == 0) {
@@ -809,16 +808,16 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
std::string::size_type cc;
std::ostringstream ostr;
- log = "";
+ log.clear();
int defects = 0;
cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
cmsys::RegularExpression vgFIM(
- "== .*Invalid free\\(\\) / delete / delete\\[\\]");
+ R"(== .*Invalid free\(\) / delete / delete\[\])");
cmsys::RegularExpression vgFMM(
- "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
+ R"(== .*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,]+");
@@ -848,7 +847,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
cmsys::RegularExpression vgABR("== .*pthread_mutex_unlock: mutex is "
"locked by a different thread");
std::vector<std::string::size_type> nonValGrindOutput;
- double sttime = cmSystemTools::GetTime();
+ auto sttime = std::chrono::steady_clock::now();
cmCTestOptionalLog(this->CTest, DEBUG,
"Start test: " << lines.size() << std::endl, this->Quiet);
std::string::size_type totalOutputSize = 0;
@@ -907,11 +906,9 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
// 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();
- ostr << lines[*i] << std::endl;
+ for (std::string::size_type i : nonValGrindOutput) {
+ totalOutputSize += lines[i].size();
+ ostr << lines[i] << std::endl;
if (!unlimitedOutput &&
totalOutputSize >
static_cast<size_t>(this->CustomMaximumFailedTestOutputSize)) {
@@ -923,8 +920,11 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
break; // stop the copy of output if we are full
}
}
- cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
- << (cmSystemTools::GetTime() - sttime) << std::endl,
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ "End test (elapsed: "
+ << cmDurationTo<unsigned int>(
+ std::chrono::steady_clock::now() - sttime)
+ << "s)" << std::endl,
this->Quiet);
log = ostr.str();
this->DefectCount += defects;
@@ -934,10 +934,10 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
const std::string& str, std::string& log, std::vector<int>& results)
{
- log = "";
- double sttime = cmSystemTools::GetTime();
+ log.clear();
+ auto sttime = std::chrono::steady_clock::now();
std::vector<std::string> lines;
- cmSystemTools::Split(str.c_str(), lines);
+ cmsys::SystemTools::Split(str, lines);
cmCTestOptionalLog(this->CTest, DEBUG,
"Start test: " << lines.size() << std::endl, this->Quiet);
std::vector<std::string>::size_type cc;
@@ -962,12 +962,15 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
}
}
int defects = 0;
- for (cc = 0; cc < parser.Errors.size(); ++cc) {
- results[parser.Errors[cc]]++;
+ for (int err : parser.Errors) {
+ results[err]++;
defects++;
}
- cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
- << (cmSystemTools::GetTime() - sttime) << std::endl,
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ "End test (elapsed: "
+ << cmDurationTo<unsigned int>(
+ std::chrono::steady_clock::now() - sttime)
+ << "s)" << std::endl,
this->Quiet);
if (defects) {
// only put the output of Bounds Checker if there were
@@ -990,9 +993,8 @@ void cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res, int 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);
+ for (std::string const& f : files) {
+ this->AppendMemTesterOutput(res, f);
}
}
}
@@ -1085,16 +1087,16 @@ void cmCTestMemCheckHandler::TestOutputFileNames(
g.FindFiles(ofile);
if (g.GetFiles().empty()) {
std::string log = "Cannot find memory tester output file: " + ofile;
- cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
- ofile = "";
+ cmCTestLog(this->CTest, WARNING, log << std::endl);
+ ofile.clear();
} else {
files = g.GetFiles();
return;
}
- } else if (!cmSystemTools::FileExists(ofile.c_str())) {
+ } else if (!cmSystemTools::FileExists(ofile)) {
std::string log = "Cannot find memory tester output file: " + ofile;
- cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
- ofile = "";
+ cmCTestLog(this->CTest, WARNING, log << std::endl);
+ ofile.clear();
}
- files.push_back(ofile);
+ files.push_back(std::move(ofile));
}
diff --git a/Source/CTest/cmCTestMemCheckHandler.h b/Source/CTest/cmCTestMemCheckHandler.h
index 333c2e2dd..746d72c01 100644
--- a/Source/CTest/cmCTestMemCheckHandler.h
+++ b/Source/CTest/cmCTestMemCheckHandler.h
@@ -3,7 +3,7 @@
#ifndef cmCTestMemCheckHandler_h
#define cmCTestMemCheckHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestTestHandler.h"
@@ -24,19 +24,18 @@ class cmCTestMemCheckHandler : public cmCTestTestHandler
public:
typedef cmCTestTestHandler Superclass;
- void PopulateCustomVectors(cmMakefile* mf) CM_OVERRIDE;
+ void PopulateCustomVectors(cmMakefile* mf) override;
cmCTestMemCheckHandler();
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
int GetDefectCount();
protected:
- int PreProcessHandler() CM_OVERRIDE;
- int PostProcessHandler() CM_OVERRIDE;
- void GenerateTestCommand(std::vector<std::string>& args,
- int test) CM_OVERRIDE;
+ int PreProcessHandler() override;
+ int PostProcessHandler() override;
+ void GenerateTestCommand(std::vector<std::string>& args, int test) override;
private:
enum
@@ -115,20 +114,20 @@ private:
// this type of checker
void InitializeResultsVectors();
- ///! Initialize memory checking subsystem.
+ //! Initialize memory checking subsystem.
bool InitializeMemoryChecking();
/**
* Generate the Dart compatible output
*/
- void GenerateDartOutput(cmXMLWriter& xml) CM_OVERRIDE;
+ void GenerateDartOutput(cmXMLWriter& xml) override;
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.
+ // different memory errors.
bool ProcessMemCheckOutput(const std::string& str, std::string& log,
std::vector<int>& results);
bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
@@ -144,11 +143,11 @@ private:
void PostProcessTest(cmCTestTestResult& res, int test);
void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test);
- ///! append MemoryTesterOutputFile to the test log
+ //! append MemoryTesterOutputFile to the test log
void AppendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
std::string const& filename);
- ///! generate the output filename for the given test index
+ //! generate the output filename for the given test index
void TestOutputFileNames(int test, std::vector<std::string>& files);
};
diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx
index 2c16a0d1e..1b71f2ab6 100644
--- a/Source/CTest/cmCTestMultiProcessHandler.cxx
+++ b/Source/CTest/cmCTestMultiProcessHandler.cxx
@@ -2,25 +2,43 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestMultiProcessHandler.h"
+#include "cmAffinity.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestRunTest.h"
-#include "cmCTestScriptHandler.h"
#include "cmCTestTestHandler.h"
+#include "cmDuration.h"
+#include "cmListFileCache.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
+#include "cm_jsoncpp_value.h"
+#include "cm_jsoncpp_writer.h"
+#include "cm_uv.h"
+
+#include "cmUVSignalHackRAII.h" // IWYU pragma: keep
+
#include "cmsys/FStream.hxx"
-#include "cmsys/String.hxx"
#include "cmsys/SystemInformation.hxx"
+
#include <algorithm>
+#include <chrono>
+#include <cstring>
#include <iomanip>
+#include <iostream>
#include <list>
#include <math.h>
#include <sstream>
#include <stack>
#include <stdlib.h>
+#include <unordered_map>
#include <utility>
+namespace cmsys {
+class RegularExpression;
+}
+
class TestComparator
{
public:
@@ -28,7 +46,6 @@ public:
: Handler(handler)
{
}
- ~TestComparator() {}
// Sorts tests in descending order of cost
bool operator()(int index1, int index2) const
@@ -45,16 +62,16 @@ cmCTestMultiProcessHandler::cmCTestMultiProcessHandler()
{
this->ParallelLevel = 1;
this->TestLoad = 0;
+ this->FakeLoadForTesting = 0;
this->Completed = 0;
this->RunningCount = 0;
- this->StopTimePassed = false;
+ this->ProcessorsAvailable = cmAffinity::GetProcessorsAvailable();
+ this->HaveAffinity = this->ProcessorsAvailable.size();
this->HasCycles = false;
this->SerialTestRunning = false;
}
-cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler()
-{
-}
+cmCTestMultiProcessHandler::~cmCTestMultiProcessHandler() = default;
// Set the tests
void cmCTestMultiProcessHandler::SetTests(TestMap& tests,
@@ -64,10 +81,9 @@ void cmCTestMultiProcessHandler::SetTests(TestMap& 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;
+ for (auto const& t : this->Tests) {
+ this->TestRunningMap[t.first] = false;
+ this->TestFinishMap[t.first] = false;
}
if (!this->CTest->GetShowOnly()) {
this->ReadCostData();
@@ -88,6 +104,16 @@ void cmCTestMultiProcessHandler::SetParallelLevel(size_t level)
void cmCTestMultiProcessHandler::SetTestLoad(unsigned long load)
{
this->TestLoad = load;
+
+ std::string fake_load_value;
+ if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING",
+ fake_load_value)) {
+ if (!cmSystemTools::StringToULong(fake_load_value.c_str(),
+ &this->FakeLoadForTesting)) {
+ cmSystemTools::Error("Failed to parse fake load value: " +
+ fake_load_value);
+ }
+ }
}
void cmCTestMultiProcessHandler::RunTests()
@@ -96,24 +122,37 @@ void cmCTestMultiProcessHandler::RunTests()
if (this->HasCycles) {
return;
}
+#ifdef CMAKE_UV_SIGNAL_HACK
+ cmUVSignalHackRAII hackRAII;
+#endif
this->TestHandler->SetMaxIndex(this->FindMaxIndex());
+
+ uv_loop_init(&this->Loop);
this->StartNextTests();
- while (!this->Tests.empty()) {
- if (this->StopTimePassed) {
- return;
- }
- this->CheckOutput();
- this->StartNextTests();
- }
- // let all running tests finish
- while (this->CheckOutput()) {
- }
+ uv_run(&this->Loop, UV_RUN_DEFAULT);
+ uv_loop_close(&this->Loop);
+
this->MarkFinished();
this->UpdateCostData();
}
-void cmCTestMultiProcessHandler::StartTestProcess(int test)
+bool cmCTestMultiProcessHandler::StartTestProcess(int test)
{
+ if (this->HaveAffinity && this->Properties[test]->WantAffinity) {
+ size_t needProcessors = this->GetProcessorsUsed(test);
+ if (needProcessors > this->ProcessorsAvailable.size()) {
+ return false;
+ }
+ std::vector<size_t> affinity;
+ affinity.reserve(needProcessors);
+ for (size_t i = 0; i < needProcessors; ++i) {
+ auto p = this->ProcessorsAvailable.begin();
+ affinity.push_back(*p);
+ this->ProcessorsAvailable.erase(p);
+ }
+ this->Properties[test]->Affinity = std::move(affinity);
+ }
+
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"test " << test << "\n", this->Quiet);
this->TestRunningMap[test] = true; // mark the test as running
@@ -121,7 +160,7 @@ void cmCTestMultiProcessHandler::StartTestProcess(int test)
this->EraseTest(test);
this->RunningCount += GetProcessorsUsed(test);
- cmCTestRunTest* testRun = new cmCTestRunTest(this->TestHandler);
+ cmCTestRunTest* testRun = new cmCTestRunTest(*this);
if (this->CTest->GetRepeatUntilFail()) {
testRun->SetRunUntilFailOn();
testRun->SetNumberOfRuns(this->CTest->GetTestRepeat());
@@ -131,42 +170,53 @@ void cmCTestMultiProcessHandler::StartTestProcess(int test)
// Find any failed dependencies for this test. We assume the more common
// scenario has no failed tests, so make it the outer loop.
- for (std::vector<std::string>::const_iterator it = this->Failed->begin();
- it != this->Failed->end(); ++it) {
- if (this->Properties[test]->RequireSuccessDepends.find(*it) !=
+ for (std::string const& f : *this->Failed) {
+ if (this->Properties[test]->RequireSuccessDepends.find(f) !=
this->Properties[test]->RequireSuccessDepends.end()) {
- testRun->AddFailedDependency(*it);
+ testRun->AddFailedDependency(f);
}
}
- cmWorkingDirectory workdir(this->Properties[test]->Directory);
-
- // Lock the resources we'll be using
+ // Always lock the resources we'll be using, even if we fail to set the
+ // working directory because FinishTestProcess() will try to unlock them
this->LockResources(test);
- if (testRun->StartTest(this->Total)) {
- this->RunningTests.insert(testRun);
- } else if (testRun->IsStopTimePassed()) {
- this->StopTimePassed = true;
- delete testRun;
- return;
+ cmWorkingDirectory workdir(this->Properties[test]->Directory);
+ if (workdir.Failed()) {
+ testRun->StartFailure("Failed to change working directory to " +
+ this->Properties[test]->Directory + " : " +
+ std::strerror(workdir.GetLastResult()));
} else {
-
- for (TestMap::iterator j = this->Tests.begin(); j != this->Tests.end();
- ++j) {
- j->second.erase(test);
+ if (testRun->StartTest(this->Completed, this->Total)) {
+ return true;
}
+ }
+
+ this->FinishTestProcess(testRun, false);
+ return false;
+}
- this->UnlockResources(test);
- this->Completed++;
- this->TestFinishMap[test] = true;
- this->TestRunningMap[test] = false;
- this->RunningCount -= GetProcessorsUsed(test);
- testRun->EndTest(this->Completed, this->Total, false);
- if (!this->Properties[test]->Disabled) {
- this->Failed->push_back(this->Properties[test]->Name);
+bool cmCTestMultiProcessHandler::CheckStopTimePassed()
+{
+ if (!this->StopTimePassed) {
+ std::chrono::system_clock::time_point stop_time =
+ this->CTest->GetStopTime();
+ if (stop_time != std::chrono::system_clock::time_point() &&
+ stop_time <= std::chrono::system_clock::now()) {
+ this->SetStopTimePassed();
}
- delete testRun;
+ }
+ return this->StopTimePassed;
+}
+
+void cmCTestMultiProcessHandler::SetStopTimePassed()
+{
+ if (!this->StopTimePassed) {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "The stop time has been passed. "
+ "Stopping all tests."
+ << std::endl);
+ this->StopTimePassed = true;
}
}
@@ -183,10 +233,8 @@ void cmCTestMultiProcessHandler::LockResources(int index)
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);
+ for (std::string const& i : this->Properties[index]->LockedResources) {
+ this->LockedResources.erase(i);
}
if (this->Properties[index]->RunSerial) {
this->SerialTestRunning = false;
@@ -208,6 +256,11 @@ inline size_t cmCTestMultiProcessHandler::GetProcessorsUsed(int test)
if (processors > this->ParallelLevel) {
processors = this->ParallelLevel;
}
+ // Cap tests that want affinity to the maximum affinity available.
+ if (this->HaveAffinity && processors > this->HaveAffinity &&
+ this->Properties[test]->WantAffinity) {
+ processors = this->HaveAffinity;
+ }
return processors;
}
@@ -219,18 +272,15 @@ std::string cmCTestMultiProcessHandler::GetName(int test)
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()) {
+ for (std::string const& i : this->Properties[test]->LockedResources) {
+ 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;
+ return this->StartTestProcess(test);
}
// This test was not able to start because it is waiting
// on depends to run
@@ -239,7 +289,23 @@ bool cmCTestMultiProcessHandler::StartTest(int test)
void cmCTestMultiProcessHandler::StartNextTests()
{
+ if (this->TestLoadRetryTimer.get() != nullptr) {
+ // This timer may be waiting to call StartNextTests again.
+ // Since we have been called it is no longer needed.
+ uv_timer_stop(this->TestLoadRetryTimer);
+ }
+
+ if (this->Tests.empty()) {
+ this->TestLoadRetryTimer.reset();
+ return;
+ }
+
+ if (this->CheckStopTimePassed()) {
+ return;
+ }
+
size_t numToStart = 0;
+
if (this->RunningCount < this->ParallelLevel) {
numToStart = this->ParallelLevel - this->RunningCount;
}
@@ -255,7 +321,6 @@ void cmCTestMultiProcessHandler::StartNextTests()
}
bool allTestsFailedTestLoadCheck = false;
- bool usedFakeLoadForTesting = false;
size_t minProcessorsRequired = this->ParallelLevel;
std::string testWithMinProcessors;
@@ -268,15 +333,11 @@ void cmCTestMultiProcessHandler::StartNextTests()
allTestsFailedTestLoadCheck = true;
// Check for a fake load average value used in testing.
- std::string fake_load_value;
- if (cmSystemTools::GetEnv("__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING",
- fake_load_value)) {
- usedFakeLoadForTesting = true;
- if (!cmSystemTools::StringToULong(fake_load_value.c_str(),
- &systemLoad)) {
- cmSystemTools::Error("Failed to parse fake load value: ",
- fake_load_value.c_str());
- }
+ if (this->FakeLoadForTesting > 0) {
+ systemLoad = this->FakeLoadForTesting;
+ // Drop the fake load for the next iteration to a value low enough
+ // that the next iteration will start tests.
+ this->FakeLoadForTesting = 1;
}
// If it's not set, look up the true load average.
else {
@@ -292,24 +353,24 @@ void cmCTestMultiProcessHandler::StartNextTests()
}
TestList copy = this->SortedTests;
- for (TestList::iterator test = copy.begin(); test != copy.end(); ++test) {
+ for (auto const& test : copy) {
// Take a nap if we're currently performing a RUN_SERIAL test.
if (this->SerialTestRunning) {
break;
}
// We can only start a RUN_SERIAL test if no other tests are also running.
- if (this->Properties[*test]->RunSerial && this->RunningCount > 0) {
+ if (this->Properties[test]->RunSerial && this->RunningCount > 0) {
continue;
}
- size_t processors = GetProcessorsUsed(*test);
+ size_t processors = GetProcessorsUsed(test);
bool testLoadOk = true;
if (this->TestLoad > 0) {
if (processors <= spareLoad) {
- cmCTestLog(this->CTest, DEBUG, "OK to run "
- << GetName(*test) << ", it requires " << processors
- << " procs & system load is: " << systemLoad
- << std::endl);
+ cmCTestLog(this->CTest, DEBUG,
+ "OK to run " << GetName(test) << ", it requires "
+ << processors << " procs & system load is: "
+ << systemLoad << std::endl);
allTestsFailedTestLoadCheck = false;
} else {
testLoadOk = false;
@@ -318,14 +379,10 @@ void cmCTestMultiProcessHandler::StartNextTests()
if (processors <= minProcessorsRequired) {
minProcessorsRequired = processors;
- testWithMinProcessors = GetName(*test);
+ testWithMinProcessors = GetName(test);
}
- if (testLoadOk && processors <= numToStart && this->StartTest(*test)) {
- if (this->StopTimePassed) {
- return;
- }
-
+ if (testLoadOk && processors <= numToStart && this->StartTest(test)) {
numToStart -= processors;
} else if (numToStart == 0) {
break;
@@ -333,10 +390,22 @@ void cmCTestMultiProcessHandler::StartNextTests()
}
if (allTestsFailedTestLoadCheck) {
+ // Find out whether there are any non RUN_SERIAL tests left, so that the
+ // correct warning may be displayed.
+ bool onlyRunSerialTestsLeft = true;
+ for (auto const& test : copy) {
+ if (!this->Properties[test]->RunSerial) {
+ onlyRunSerialTestsLeft = false;
+ }
+ }
cmCTestLog(this->CTest, HANDLER_OUTPUT, "***** WAITING, ");
+
if (this->SerialTestRunning) {
cmCTestLog(this->CTest, HANDLER_OUTPUT,
"Waiting for RUN_SERIAL test to finish.");
+ } else if (onlyRunSerialTestsLeft) {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ "Only RUN_SERIAL tests remain, awaiting available slot.");
} else {
/* clang-format off */
cmCTestLog(this->CTest, HANDLER_OUTPUT,
@@ -348,63 +417,69 @@ void cmCTestMultiProcessHandler::StartNextTests()
}
cmCTestLog(this->CTest, HANDLER_OUTPUT, "*****" << std::endl);
- if (usedFakeLoadForTesting) {
- // Break out of the infinite loop of waiting for our fake load
- // to come down.
- this->StopTimePassed = true;
- } else {
- // Wait between 1 and 5 seconds before trying again.
- cmCTestScriptHandler::SleepInSeconds(cmSystemTools::RandomSeed() % 5 +
- 1);
+ // Wait between 1 and 5 seconds before trying again.
+ unsigned int milliseconds = (cmSystemTools::RandomSeed() % 5 + 1) * 1000;
+ if (this->FakeLoadForTesting) {
+ milliseconds = 10;
+ }
+ if (this->TestLoadRetryTimer.get() == nullptr) {
+ this->TestLoadRetryTimer.init(this->Loop, this);
}
+ this->TestLoadRetryTimer.start(
+ &cmCTestMultiProcessHandler::OnTestLoadRetryCB, milliseconds, 0);
}
}
-bool cmCTestMultiProcessHandler::CheckOutput()
+void cmCTestMultiProcessHandler::OnTestLoadRetryCB(uv_timer_t* timer)
{
- // no more output we are done
- if (this->RunningTests.empty()) {
- return false;
+ auto self = static_cast<cmCTestMultiProcessHandler*>(timer->data);
+ self->StartNextTests();
+}
+
+void cmCTestMultiProcessHandler::FinishTestProcess(cmCTestRunTest* runner,
+ bool started)
+{
+ this->Completed++;
+
+ int test = runner->GetIndex();
+ auto properties = runner->GetTestProperties();
+
+ bool testResult = runner->EndTest(this->Completed, this->Total, started);
+ if (runner->TimedOutForStopTime()) {
+ this->SetStopTimePassed();
}
- 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);
+ if (started) {
+ if (!this->StopTimePassed && runner->StartAgain(this->Completed)) {
+ this->Completed--; // remove the completed test because run again
+ return;
}
}
- for (std::vector<cmCTestRunTest*>::iterator i = finished.begin();
- i != finished.end(); ++i) {
- this->Completed++;
- cmCTestRunTest* p = *i;
- int test = p->GetIndex();
- bool testResult = p->EndTest(this->Completed, this->Total, true);
- if (p->StartAgain()) {
- this->Completed--; // remove the completed test because run again
- continue;
- }
- if (testResult) {
- 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;
+ if (testResult) {
+ this->Passed->push_back(properties->Name);
+ } else if (!properties->Disabled) {
+ this->Failed->push_back(properties->Name);
+ }
+
+ for (auto& t : this->Tests) {
+ t.second.erase(test);
+ }
+
+ this->TestFinishMap[test] = true;
+ this->TestRunningMap[test] = false;
+ this->WriteCheckpoint(test);
+ this->UnlockResources(test);
+ this->RunningCount -= GetProcessorsUsed(test);
+
+ for (auto p : properties->Affinity) {
+ this->ProcessorsAvailable.insert(p);
+ }
+ properties->Affinity.clear();
+
+ delete runner;
+ if (started) {
+ this->StartNextTests();
}
- return true;
}
void cmCTestMultiProcessHandler::UpdateCostData()
@@ -416,7 +491,7 @@ void cmCTestMultiProcessHandler::UpdateCostData()
PropertiesMap temp = this->Properties;
- if (cmSystemTools::FileExists(fname.c_str())) {
+ if (cmSystemTools::FileExists(fname)) {
cmsys::ifstream fin;
fin.open(fname.c_str());
@@ -425,7 +500,7 @@ void cmCTestMultiProcessHandler::UpdateCostData()
if (line == "---") {
break;
}
- std::vector<cmsys::String> parts = cmSystemTools::SplitString(line, ' ');
+ std::vector<std::string> parts = cmSystemTools::SplitString(line, ' ');
// Format: <name> <previous_runs> <avg_cost>
if (parts.size() < 3) {
break;
@@ -451,26 +526,25 @@ void cmCTestMultiProcessHandler::UpdateCostData()
}
// 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";
+ for (auto const& i : temp) {
+ 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 << "\n";
+ for (std::string const& f : *this->Failed) {
+ fout << f << "\n";
}
fout.close();
- cmSystemTools::RenameFile(tmpout.c_str(), fname.c_str());
+ cmSystemTools::RenameFile(tmpout, fname);
}
void cmCTestMultiProcessHandler::ReadCostData()
{
std::string fname = this->CTest->GetCostDataFile();
- if (cmSystemTools::FileExists(fname.c_str(), true)) {
+ if (cmSystemTools::FileExists(fname, true)) {
cmsys::ifstream fin;
fin.open(fname.c_str());
std::string line;
@@ -479,7 +553,7 @@ void cmCTestMultiProcessHandler::ReadCostData()
break;
}
- std::vector<cmsys::String> parts = cmSystemTools::SplitString(line, ' ');
+ std::vector<std::string> parts = cmSystemTools::SplitString(line, ' ');
// Probably an older version of the file, will be fixed next run
if (parts.size() < 3) {
@@ -505,7 +579,7 @@ void cmCTestMultiProcessHandler::ReadCostData()
}
// Next part of the file is the failed tests
while (std::getline(fin, line)) {
- if (line != "") {
+ if (!line.empty()) {
this->LastTestsFailed.push_back(line);
}
}
@@ -517,10 +591,9 @@ int cmCTestMultiProcessHandler::SearchByName(std::string const& name)
{
int index = -1;
- for (PropertiesMap::iterator i = this->Properties.begin();
- i != this->Properties.end(); ++i) {
- if (i->second->Name == name) {
- index = i->first;
+ for (auto const& p : this->Properties) {
+ if (p.second->Name == name) {
+ index = p.first;
}
}
return index;
@@ -540,21 +613,20 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
TestSet alreadySortedTests;
std::list<TestSet> priorityStack;
- priorityStack.push_back(TestSet());
+ priorityStack.emplace_back();
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) {
+ for (auto const& t : this->Tests) {
if (std::find(this->LastTestsFailed.begin(), this->LastTestsFailed.end(),
- this->Properties[i->first]->Name) !=
+ this->Properties[t.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);
+ this->SortedTests.push_back(t.first);
+ alreadySortedTests.insert(t.first);
} else {
- topLevel.insert(i->first);
+ topLevel.insert(t.first);
}
}
@@ -563,18 +635,16 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
// further dependencies exist.
while (!priorityStack.back().empty()) {
TestSet& previousSet = priorityStack.back();
- priorityStack.push_back(TestSet());
+ priorityStack.emplace_back();
TestSet& currentSet = priorityStack.back();
- for (TestSet::const_iterator i = previousSet.begin();
- i != previousSet.end(); ++i) {
- TestSet const& dependencies = this->Tests[*i];
+ for (auto const& i : previousSet) {
+ TestSet const& dependencies = this->Tests[i];
currentSet.insert(dependencies.begin(), dependencies.end());
}
- for (TestSet::const_iterator i = currentSet.begin(); i != currentSet.end();
- ++i) {
- previousSet.erase(*i);
+ for (auto const& i : currentSet) {
+ previousSet.erase(i);
}
}
@@ -583,22 +653,16 @@ void cmCTestMultiProcessHandler::CreateParallelTestCostList()
// 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);
-
+ for (TestSet const& currentSet : cmReverseRange(priorityStack)) {
TestList sortedCopy;
-
- sortedCopy.insert(sortedCopy.end(), currentSet.begin(), currentSet.end());
-
- 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);
+ cmAppend(sortedCopy, currentSet);
+ std::stable_sort(sortedCopy.begin(), sortedCopy.end(),
+ TestComparator(this));
+
+ for (auto const& j : sortedCopy) {
+ if (alreadySortedTests.find(j) == alreadySortedTests.end()) {
+ this->SortedTests.push_back(j);
+ alreadySortedTests.insert(j);
}
}
}
@@ -608,10 +672,9 @@ 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);
+ for (int i : dependencySet) {
+ GetAllTestDependencies(i, dependencies);
+ dependencies.push_back(i);
}
}
@@ -619,20 +682,16 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList()
{
TestList presortedList;
- for (TestMap::iterator i = this->Tests.begin(); i != this->Tests.end();
- ++i) {
- presortedList.push_back(i->first);
+ for (auto const& i : this->Tests) {
+ presortedList.push_back(i.first);
}
- TestComparator comp(this);
- std::stable_sort(presortedList.begin(), presortedList.end(), comp);
+ std::stable_sort(presortedList.begin(), presortedList.end(),
+ TestComparator(this));
TestSet alreadySortedTests;
- for (TestList::const_iterator i = presortedList.begin();
- i != presortedList.end(); ++i) {
- int test = *i;
-
+ for (int test : presortedList) {
if (alreadySortedTests.find(test) != alreadySortedTests.end()) {
continue;
}
@@ -640,10 +699,7 @@ void cmCTestMultiProcessHandler::CreateSerialTestCostList()
TestList dependencies;
GetAllTestDependencies(test, dependencies);
- for (TestList::const_iterator j = dependencies.begin();
- j != dependencies.end(); ++j) {
- int testDependency = *j;
-
+ for (int testDependency : dependencies) {
if (alreadySortedTests.find(testDependency) ==
alreadySortedTests.end()) {
alreadySortedTests.insert(testDependency);
@@ -673,32 +729,358 @@ void cmCTestMultiProcessHandler::MarkFinished()
cmSystemTools::RemoveFile(fname);
}
+static Json::Value DumpToJsonArray(const std::set<std::string>& values)
+{
+ Json::Value jsonArray = Json::arrayValue;
+ for (auto& it : values) {
+ jsonArray.append(it);
+ }
+ return jsonArray;
+}
+
+static Json::Value DumpToJsonArray(const std::vector<std::string>& values)
+{
+ Json::Value jsonArray = Json::arrayValue;
+ for (auto& it : values) {
+ jsonArray.append(it);
+ }
+ return jsonArray;
+}
+
+static Json::Value DumpRegExToJsonArray(
+ const std::vector<std::pair<cmsys::RegularExpression, std::string>>& values)
+{
+ Json::Value jsonArray = Json::arrayValue;
+ for (auto& it : values) {
+ jsonArray.append(it.second);
+ }
+ return jsonArray;
+}
+
+static Json::Value DumpMeasurementToJsonArray(
+ const std::map<std::string, std::string>& values)
+{
+ Json::Value jsonArray = Json::arrayValue;
+ for (auto& it : values) {
+ Json::Value measurement = Json::objectValue;
+ measurement["measurement"] = it.first;
+ measurement["value"] = it.second;
+ jsonArray.append(measurement);
+ }
+ return jsonArray;
+}
+
+static Json::Value DumpTimeoutAfterMatch(
+ cmCTestTestHandler::cmCTestTestProperties& testProperties)
+{
+ Json::Value timeoutAfterMatch = Json::objectValue;
+ timeoutAfterMatch["timeout"] = testProperties.AlternateTimeout.count();
+ timeoutAfterMatch["regex"] =
+ DumpRegExToJsonArray(testProperties.TimeoutRegularExpressions);
+ return timeoutAfterMatch;
+}
+
+static Json::Value DumpCTestProperty(std::string const& name,
+ Json::Value value)
+{
+ Json::Value property = Json::objectValue;
+ property["name"] = name;
+ property["value"] = std::move(value);
+ return property;
+}
+
+static Json::Value DumpCTestProperties(
+ cmCTestTestHandler::cmCTestTestProperties& testProperties)
+{
+ Json::Value properties = Json::arrayValue;
+ if (!testProperties.AttachOnFail.empty()) {
+ properties.append(DumpCTestProperty(
+ "ATTACHED_FILES_ON_FAIL", DumpToJsonArray(testProperties.AttachOnFail)));
+ }
+ if (!testProperties.AttachedFiles.empty()) {
+ properties.append(DumpCTestProperty(
+ "ATTACHED_FILES", DumpToJsonArray(testProperties.AttachedFiles)));
+ }
+ if (testProperties.Cost != 0.0f) {
+ properties.append(
+ DumpCTestProperty("COST", static_cast<double>(testProperties.Cost)));
+ }
+ if (!testProperties.Depends.empty()) {
+ properties.append(
+ DumpCTestProperty("DEPENDS", DumpToJsonArray(testProperties.Depends)));
+ }
+ if (testProperties.Disabled) {
+ properties.append(DumpCTestProperty("DISABLED", testProperties.Disabled));
+ }
+ if (!testProperties.Environment.empty()) {
+ properties.append(DumpCTestProperty(
+ "ENVIRONMENT", DumpToJsonArray(testProperties.Environment)));
+ }
+ if (!testProperties.ErrorRegularExpressions.empty()) {
+ properties.append(DumpCTestProperty(
+ "FAIL_REGULAR_EXPRESSION",
+ DumpRegExToJsonArray(testProperties.ErrorRegularExpressions)));
+ }
+ if (!testProperties.FixturesCleanup.empty()) {
+ properties.append(DumpCTestProperty(
+ "FIXTURES_CLEANUP", DumpToJsonArray(testProperties.FixturesCleanup)));
+ }
+ if (!testProperties.FixturesRequired.empty()) {
+ properties.append(DumpCTestProperty(
+ "FIXTURES_REQUIRED", DumpToJsonArray(testProperties.FixturesRequired)));
+ }
+ if (!testProperties.FixturesSetup.empty()) {
+ properties.append(DumpCTestProperty(
+ "FIXTURES_SETUP", DumpToJsonArray(testProperties.FixturesSetup)));
+ }
+ if (!testProperties.Labels.empty()) {
+ properties.append(
+ DumpCTestProperty("LABELS", DumpToJsonArray(testProperties.Labels)));
+ }
+ if (!testProperties.Measurements.empty()) {
+ properties.append(DumpCTestProperty(
+ "MEASUREMENT", DumpMeasurementToJsonArray(testProperties.Measurements)));
+ }
+ if (!testProperties.RequiredRegularExpressions.empty()) {
+ properties.append(DumpCTestProperty(
+ "PASS_REGULAR_EXPRESSION",
+ DumpRegExToJsonArray(testProperties.RequiredRegularExpressions)));
+ }
+ if (testProperties.WantAffinity) {
+ properties.append(
+ DumpCTestProperty("PROCESSOR_AFFINITY", testProperties.WantAffinity));
+ }
+ if (testProperties.Processors != 1) {
+ properties.append(
+ DumpCTestProperty("PROCESSORS", testProperties.Processors));
+ }
+ if (!testProperties.RequiredFiles.empty()) {
+ properties.append(DumpCTestProperty(
+ "REQUIRED_FILES", DumpToJsonArray(testProperties.RequiredFiles)));
+ }
+ if (!testProperties.LockedResources.empty()) {
+ properties.append(DumpCTestProperty(
+ "RESOURCE_LOCK", DumpToJsonArray(testProperties.LockedResources)));
+ }
+ if (testProperties.RunSerial) {
+ properties.append(
+ DumpCTestProperty("RUN_SERIAL", testProperties.RunSerial));
+ }
+ if (testProperties.SkipReturnCode != -1) {
+ properties.append(
+ DumpCTestProperty("SKIP_RETURN_CODE", testProperties.SkipReturnCode));
+ }
+ if (testProperties.ExplicitTimeout) {
+ properties.append(
+ DumpCTestProperty("TIMEOUT", testProperties.Timeout.count()));
+ }
+ if (!testProperties.TimeoutRegularExpressions.empty()) {
+ properties.append(DumpCTestProperty(
+ "TIMEOUT_AFTER_MATCH", DumpTimeoutAfterMatch(testProperties)));
+ }
+ if (testProperties.WillFail) {
+ properties.append(DumpCTestProperty("WILL_FAIL", testProperties.WillFail));
+ }
+ if (!testProperties.Directory.empty()) {
+ properties.append(
+ DumpCTestProperty("WORKING_DIRECTORY", testProperties.Directory));
+ }
+ return properties;
+}
+
+class BacktraceData
+{
+ std::unordered_map<std::string, Json::ArrayIndex> CommandMap;
+ std::unordered_map<std::string, Json::ArrayIndex> FileMap;
+ std::unordered_map<cmListFileContext const*, Json::ArrayIndex> NodeMap;
+ Json::Value Commands = Json::arrayValue;
+ Json::Value Files = Json::arrayValue;
+ Json::Value Nodes = Json::arrayValue;
+
+ Json::ArrayIndex AddCommand(std::string const& command)
+ {
+ auto i = this->CommandMap.find(command);
+ if (i == this->CommandMap.end()) {
+ i = this->CommandMap.emplace(command, this->Commands.size()).first;
+ this->Commands.append(command);
+ }
+ return i->second;
+ }
+
+ Json::ArrayIndex AddFile(std::string const& file)
+ {
+ auto i = this->FileMap.find(file);
+ if (i == this->FileMap.end()) {
+ i = this->FileMap.emplace(file, this->Files.size()).first;
+ this->Files.append(file);
+ }
+ return i->second;
+ }
+
+public:
+ bool Add(cmListFileBacktrace const& bt, Json::ArrayIndex& index);
+ Json::Value Dump();
+};
+
+bool BacktraceData::Add(cmListFileBacktrace const& bt, Json::ArrayIndex& index)
+{
+ if (bt.Empty()) {
+ return false;
+ }
+ cmListFileContext const* top = &bt.Top();
+ auto found = this->NodeMap.find(top);
+ if (found != this->NodeMap.end()) {
+ index = found->second;
+ return true;
+ }
+ Json::Value entry = Json::objectValue;
+ entry["file"] = this->AddFile(top->FilePath);
+ if (top->Line) {
+ entry["line"] = static_cast<int>(top->Line);
+ }
+ if (!top->Name.empty()) {
+ entry["command"] = this->AddCommand(top->Name);
+ }
+ Json::ArrayIndex parent;
+ if (this->Add(bt.Pop(), parent)) {
+ entry["parent"] = parent;
+ }
+ index = this->NodeMap[top] = this->Nodes.size();
+ this->Nodes.append(std::move(entry)); // NOLINT(*)
+ return true;
+}
+
+Json::Value BacktraceData::Dump()
+{
+ Json::Value backtraceGraph;
+ this->CommandMap.clear();
+ this->FileMap.clear();
+ this->NodeMap.clear();
+ backtraceGraph["commands"] = std::move(this->Commands);
+ backtraceGraph["files"] = std::move(this->Files);
+ backtraceGraph["nodes"] = std::move(this->Nodes);
+ return backtraceGraph;
+}
+
+static void AddBacktrace(BacktraceData& backtraceGraph, Json::Value& object,
+ cmListFileBacktrace const& bt)
+{
+ Json::ArrayIndex backtrace;
+ if (backtraceGraph.Add(bt, backtrace)) {
+ object["backtrace"] = backtrace;
+ }
+}
+
+static Json::Value DumpCTestInfo(
+ cmCTestRunTest& testRun,
+ cmCTestTestHandler::cmCTestTestProperties& testProperties,
+ BacktraceData& backtraceGraph)
+{
+ Json::Value testInfo = Json::objectValue;
+ // test name should always be present
+ testInfo["name"] = testProperties.Name;
+ std::string const& config = testRun.GetCTest()->GetConfigType();
+ if (!config.empty()) {
+ testInfo["config"] = config;
+ }
+ std::string const& command = testRun.GetActualCommand();
+ if (!command.empty()) {
+ std::vector<std::string> commandAndArgs;
+ commandAndArgs.push_back(command);
+ const std::vector<std::string>& args = testRun.GetArguments();
+ if (!args.empty()) {
+ commandAndArgs.reserve(args.size() + 1);
+ cmAppend(commandAndArgs, args);
+ }
+ testInfo["command"] = DumpToJsonArray(commandAndArgs);
+ }
+ Json::Value properties = DumpCTestProperties(testProperties);
+ if (!properties.empty()) {
+ testInfo["properties"] = properties;
+ }
+ if (!testProperties.Backtrace.Empty()) {
+ AddBacktrace(backtraceGraph, testInfo, testProperties.Backtrace);
+ }
+ return testInfo;
+}
+
+static Json::Value DumpVersion(int major, int minor)
+{
+ Json::Value version = Json::objectValue;
+ version["major"] = major;
+ version["minor"] = minor;
+ return version;
+}
+
+void cmCTestMultiProcessHandler::PrintOutputAsJson()
+{
+ this->TestHandler->SetMaxIndex(this->FindMaxIndex());
+
+ Json::Value result = Json::objectValue;
+ result["kind"] = "ctestInfo";
+ result["version"] = DumpVersion(1, 0);
+
+ BacktraceData backtraceGraph;
+ Json::Value tests = Json::arrayValue;
+ for (auto& it : this->Properties) {
+ cmCTestTestHandler::cmCTestTestProperties& p = *it.second;
+
+ // Don't worry if this fails, we are only showing the test list, not
+ // running the tests
+ cmWorkingDirectory workdir(p.Directory);
+ cmCTestRunTest testRun(*this);
+ testRun.SetIndex(p.Index);
+ testRun.SetTestProperties(&p);
+ testRun.ComputeArguments();
+
+ // Skip tests not available in this configuration.
+ if (p.Args.size() >= 2 && p.Args[1] == "NOT_AVAILABLE") {
+ continue;
+ }
+
+ Json::Value testInfo = DumpCTestInfo(testRun, p, backtraceGraph);
+ tests.append(testInfo);
+ }
+ result["backtraceGraph"] = backtraceGraph.Dump();
+ result["tests"] = std::move(tests);
+
+ Json::StreamWriterBuilder builder;
+ builder["indentation"] = " ";
+ std::unique_ptr<Json::StreamWriter> jout(builder.newStreamWriter());
+ jout->write(result, &std::cout);
+}
+
// For ShowOnly mode
void cmCTestMultiProcessHandler::PrintTestList()
{
+ if (this->CTest->GetOutputAsJson()) {
+ PrintOutputAsJson();
+ return;
+ }
+
this->TestHandler->SetMaxIndex(this->FindMaxIndex());
int count = 0;
- for (PropertiesMap::iterator it = this->Properties.begin();
- it != this->Properties.end(); ++it) {
+ for (auto& it : this->Properties) {
count++;
- cmCTestTestHandler::cmCTestTestProperties& p = *it->second;
+ cmCTestTestHandler::cmCTestTestProperties& p = *it.second;
+ // Don't worry if this fails, we are only showing the test list, not
+ // running the tests
cmWorkingDirectory workdir(p.Directory);
- cmCTestRunTest testRun(this->TestHandler);
+ cmCTestRunTest testRun(*this);
testRun.SetIndex(p.Index);
testRun.SetTestProperties(&p);
testRun.ComputeArguments(); // logs the command in verbose mode
if (!p.Labels.empty()) // print the labels
{
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Labels:",
- this->Quiet);
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Labels:", this->Quiet);
}
- for (std::vector<std::string>::iterator label = p.Labels.begin();
- label != p.Labels.end(); ++label) {
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << *label,
+ for (std::string const& label : p.Labels) {
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " " << label,
this->Quiet);
}
if (!p.Labels.empty()) // print the labels
@@ -729,7 +1111,8 @@ void cmCTestMultiProcessHandler::PrintTestList()
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl, this->Quiet);
}
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ std::endl
<< "Total Tests: " << this->Total << std::endl,
this->Quiet);
}
@@ -737,9 +1120,8 @@ void cmCTestMultiProcessHandler::PrintTestList()
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;
+ for (auto& it : this->Properties) {
+ cmCTestTestHandler::cmCTestTestProperties& p = *it.second;
allLabels.insert(p.Labels.begin(), p.Labels.end());
}
@@ -750,10 +1132,9 @@ void cmCTestMultiProcessHandler::PrintLabels()
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"No Labels Exist" << std::endl, this->Quiet);
}
- for (std::set<std::string>::iterator label = allLabels.begin();
- label != allLabels.end(); ++label) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " " << *label << std::endl, this->Quiet);
+ for (std::string const& label : allLabels) {
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " " << label << std::endl,
+ this->Quiet);
}
}
@@ -762,7 +1143,7 @@ void cmCTestMultiProcessHandler::CheckResume()
std::string fname =
this->CTest->GetBinaryDir() + "/Testing/Temporary/CTestCheckpoint.txt";
if (this->CTest->GetFailover()) {
- if (cmSystemTools::FileExists(fname.c_str(), true)) {
+ if (cmSystemTools::FileExists(fname, true)) {
*this->TestHandler->LogFile
<< "Resuming previously interrupted test set" << std::endl
<< "----------------------------------------------------------"
@@ -777,7 +1158,7 @@ void cmCTestMultiProcessHandler::CheckResume()
}
fin.close();
}
- } else if (cmSystemTools::FileExists(fname.c_str(), true)) {
+ } else if (cmSystemTools::FileExists(fname, true)) {
cmSystemTools::RemoveFile(fname);
}
}
@@ -794,10 +1175,9 @@ void cmCTestMultiProcessHandler::RemoveTest(int index)
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;
+ for (auto const& i : this->Tests) {
+ if (i.first > max) {
+ max = i.first;
}
}
return max;
@@ -809,10 +1189,9 @@ bool cmCTestMultiProcessHandler::CheckCycles()
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Checking test dependency graph..." << std::endl,
this->Quiet);
- for (TestMap::iterator it = this->Tests.begin(); it != this->Tests.end();
- ++it) {
+ for (auto const& it : this->Tests) {
// DFS from each element to itself
- int root = it->first;
+ int root = it.first;
std::set<int> visited;
std::stack<int> s;
s.push(root);
@@ -820,9 +1199,8 @@ bool cmCTestMultiProcessHandler::CheckCycles()
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) {
+ for (auto const& d : this->Tests[test]) {
+ if (d == root) {
// cycle exists
cmCTestLog(
this->CTest, ERROR_MESSAGE,
@@ -832,7 +1210,7 @@ bool cmCTestMultiProcessHandler::CheckCycles()
<< "\".\nPlease fix the cycle and run ctest again.\n");
return false;
}
- s.push(*d);
+ s.push(d);
}
}
}
diff --git a/Source/CTest/cmCTestMultiProcessHandler.h b/Source/CTest/cmCTestMultiProcessHandler.h
index dccc2c896..93bb880fe 100644
--- a/Source/CTest/cmCTestMultiProcessHandler.h
+++ b/Source/CTest/cmCTestMultiProcessHandler.h
@@ -12,6 +12,9 @@
#include <string>
#include <vector>
+#include "cmUVHandlePtr.h"
+#include "cm_uv.h"
+
class cmCTest;
class cmCTestRunTest;
@@ -23,6 +26,7 @@ class cmCTestRunTest;
class cmCTestMultiProcessHandler
{
friend class TestComparator;
+ friend class cmCTestRunTest;
public:
struct TestSet : public std::set<int>
@@ -47,6 +51,7 @@ public:
void SetParallelLevel(size_t);
void SetTestLoad(unsigned long load);
virtual void RunTests();
+ void PrintOutputAsJson();
void PrintTestList();
void PrintLabels();
@@ -71,11 +76,12 @@ public:
cmCTestTestHandler* GetTestHandler() { return this->TestHandler; }
void SetQuiet(bool b) { this->Quiet = b; }
+
protected:
// Start the next test or tests as many as are allowed by
// ParallelLevel
void StartNextTests();
- void StartTestProcess(int test);
+ bool StartTestProcess(int test);
bool StartTest(int test);
// Mark the checkpoint for the given test
void WriteCheckpoint(int index);
@@ -95,9 +101,10 @@ protected:
// 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 FinishTestProcess(cmCTestRunTest* runner, bool started);
+
+ static void OnTestLoadRetryCB(uv_timer_t* timer);
+
void RemoveTest(int index);
// Check if we need to resume an interrupted test set
void CheckResume();
@@ -107,6 +114,9 @@ protected:
inline size_t GetProcessorsUsed(int index);
std::string GetName(int index);
+ bool CheckStopTimePassed();
+ void SetStopTimePassed();
+
void LockResources(int index);
void UnlockResources(int index);
// map from test number to set of depend tests
@@ -117,7 +127,9 @@ protected:
// Number of tests that are complete
size_t Completed;
size_t RunningCount;
- bool StopTimePassed;
+ std::set<size_t> ProcessorsAvailable;
+ size_t HaveAffinity;
+ bool StopTimePassed = false;
// list of test properties (indices concurrent to the test map)
PropertiesMap Properties;
std::map<int, bool> TestRunningMap;
@@ -130,7 +142,9 @@ protected:
std::vector<cmCTestTestHandler::cmCTestTestResult>* TestResults;
size_t ParallelLevel; // max number of process that can be run at once
unsigned long TestLoad;
- std::set<cmCTestRunTest*> RunningTests; // current running tests
+ unsigned long FakeLoadForTesting;
+ uv_loop_t Loop;
+ cm::uv_timer_ptr TestLoadRetryTimer;
cmCTestTestHandler* TestHandler;
cmCTest* CTest;
bool HasCycles;
diff --git a/Source/CTest/cmCTestP4.cxx b/Source/CTest/cmCTestP4.cxx
index c80221634..2eb8dba29 100644
--- a/Source/CTest/cmCTestP4.cxx
+++ b/Source/CTest/cmCTestP4.cxx
@@ -2,9 +2,11 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestP4.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestVC.h"
#include "cmProcessTools.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
#include "cmsys/RegularExpression.hxx"
@@ -19,9 +21,7 @@ cmCTestP4::cmCTestP4(cmCTest* ct, std::ostream& log)
this->PriorRev = this->Unknown;
}
-cmCTestP4::~cmCTestP4()
-{
-}
+cmCTestP4::~cmCTestP4() = default;
class cmCTestP4::IdentifyParser : public cmCTestVC::LineParser
{
@@ -37,7 +37,7 @@ private:
std::string& Rev;
cmsys::RegularExpression RegexIdentify;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexIdentify.find(this->Line)) {
this->Rev = this->RegexIdentify.match(1);
@@ -61,7 +61,7 @@ private:
cmsys::RegularExpression RegexIdentify;
cmCTestP4* P4;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexIdentify.find(this->Line)) {
P4->ChangeLists.push_back(this->RegexIdentify.match(1));
@@ -84,7 +84,7 @@ private:
cmsys::RegularExpression RegexUser;
cmCTestP4* P4;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexUser.find(this->Line)) {
User NewUser;
@@ -127,7 +127,7 @@ private:
std::string CurrentPath;
cmsys::RegularExpression RegexDiff;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (!this->Line.empty() && this->Line[0] == '=' &&
this->RegexDiff.find(this->Line)) {
@@ -155,7 +155,7 @@ cmCTestP4::User cmCTestP4::GetUserData(const std::string& username)
p4_users.push_back("-m");
p4_users.push_back("1");
p4_users.push_back(username.c_str());
- p4_users.push_back(CM_NULLPTR);
+ p4_users.push_back(nullptr);
UserParser out(this, "users-out> ");
OutputLogger err(this->Log, "users-err> ");
@@ -195,7 +195,7 @@ public:
{
this->SetLog(&P4->Log, prefix);
this->RegexHeader.compile("^Change ([0-9]+) by (.+)@(.+) on (.*)$");
- this->RegexDiff.compile("^\\.\\.\\. (.*)#[0-9]+ ([^ ]+)$");
+ this->RegexDiff.compile(R"(^\.\.\. (.*)#[0-9]+ ([^ ]+)$)");
}
private:
@@ -217,7 +217,7 @@ private:
SectionType Section;
Revision Rev;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->Line.empty()) {
this->NextSection();
@@ -307,34 +307,30 @@ void cmCTestP4::SetP4Options(std::vector<char const*>& CommandOptions)
{
if (P4Options.empty()) {
const char* p4 = this->CommandLineTool.c_str();
- P4Options.push_back(p4);
+ P4Options.emplace_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.emplace_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");
+ P4Options.emplace_back("-L");
+ P4Options.emplace_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());
-
- P4Options.insert(P4Options.end(), args.begin(), args.end());
+ cmAppend(P4Options, cmSystemTools::ParseArguments(opts));
}
CommandOptions.clear();
- for (std::vector<std::string>::iterator i = P4Options.begin();
- i != P4Options.end(); ++i) {
- CommandOptions.push_back(i->c_str());
+ for (std::string const& o : P4Options) {
+ CommandOptions.push_back(o.c_str());
}
}
@@ -350,7 +346,7 @@ std::string cmCTestP4::GetWorkingRevision()
std::string source = this->SourceDirectory + "/...#have";
p4_identify.push_back(source.c_str());
- p4_identify.push_back(CM_NULLPTR);
+ p4_identify.push_back(nullptr);
std::string rev;
IdentifyParser out(this, "p4_changes-out> ", rev);
@@ -373,8 +369,9 @@ bool cmCTestP4::NoteOldRevision()
{
this->OldRevision = this->GetWorkingRevision();
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " Old revision of repository is: "
- << this->OldRevision << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Old revision of repository is: " << this->OldRevision
+ << "\n");
this->PriorRev.Rev = this->OldRevision;
return true;
}
@@ -383,8 +380,9 @@ bool cmCTestP4::NoteNewRevision()
{
this->NewRevision = this->GetWorkingRevision();
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " New revision of repository is: "
- << this->NewRevision << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " New revision of repository is: " << this->NewRevision
+ << "\n");
return true;
}
@@ -399,7 +397,8 @@ bool cmCTestP4::LoadRevisions()
// 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 "
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " At least one of the revisions "
<< "is unknown. No repository changes will be reported.\n");
return false;
}
@@ -411,7 +410,7 @@ bool cmCTestP4::LoadRevisions()
p4_changes.push_back("changes");
p4_changes.push_back(range.c_str());
- p4_changes.push_back(CM_NULLPTR);
+ p4_changes.push_back(nullptr);
ChangesParser out(this, "p4_changes-out> ");
OutputLogger err(this->Log, "p4_changes-err> ");
@@ -425,13 +424,12 @@ bool cmCTestP4::LoadRevisions()
// 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) {
+ for (std::string const& i : cmReverseRange(ChangeLists)) {
SetP4Options(p4_describe);
p4_describe.push_back("describe");
p4_describe.push_back("-s");
- p4_describe.push_back(i->c_str());
- p4_describe.push_back(CM_NULLPTR);
+ p4_describe.push_back(i.c_str());
+ p4_describe.push_back(nullptr);
DescribeParser outDescribe(this, "p4_describe-out> ");
OutputLogger errDescribe(this->Log, "p4_describe-err> ");
@@ -451,7 +449,7 @@ bool cmCTestP4::LoadModifications()
p4_diff.push_back("-dn");
std::string source = this->SourceDirectory + "/...";
p4_diff.push_back(source.c_str());
- p4_diff.push_back(CM_NULLPTR);
+ p4_diff.push_back(nullptr);
DiffParser out(this, "p4_diff-out> ");
OutputLogger err(this->Log, "p4_diff-err> ");
@@ -465,11 +463,11 @@ bool cmCTestP4::UpdateCustom(const std::string& custom)
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.reserve(p4_custom_command.size() + 1);
+ for (std::string const& i : p4_custom_command) {
+ p4_custom.push_back(i.c_str());
}
- p4_custom.push_back(CM_NULLPTR);
+ p4_custom.push_back(nullptr);
OutputLogger custom_out(this->Log, "p4_customsync-out> ");
OutputLogger custom_err(this->Log, "p4_customsync-err> ");
@@ -501,10 +499,9 @@ bool cmCTestP4::UpdateImpl()
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::vector<std::string> args = cmSystemTools::ParseArguments(opts);
+ for (std::string const& arg : args) {
+ p4_sync.push_back(arg.c_str());
}
std::string source = this->SourceDirectory + "/...";
@@ -520,7 +517,7 @@ bool cmCTestP4::UpdateImpl()
}
p4_sync.push_back(source.c_str());
- p4_sync.push_back(CM_NULLPTR);
+ p4_sync.push_back(nullptr);
OutputLogger out(this->Log, "p4_sync-out> ");
OutputLogger err(this->Log, "p4_sync-err> ");
diff --git a/Source/CTest/cmCTestP4.h b/Source/CTest/cmCTestP4.h
index e234efbfb..b14edf7e9 100644
--- a/Source/CTest/cmCTestP4.h
+++ b/Source/CTest/cmCTestP4.h
@@ -3,7 +3,7 @@
#ifndef cmCTestP4_h
#define cmCTestP4_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGlobalVC.h"
@@ -24,7 +24,7 @@ public:
/** Construct with a CTest instance and update log stream. */
cmCTestP4(cmCTest* ctest, std::ostream& log);
- ~cmCTestP4() CM_OVERRIDE;
+ ~cmCTestP4() override;
private:
std::vector<std::string> ChangeLists;
@@ -51,13 +51,13 @@ private:
void SetP4Options(std::vector<char const*>& options);
std::string GetWorkingRevision();
- bool NoteOldRevision() CM_OVERRIDE;
- bool NoteNewRevision() CM_OVERRIDE;
- bool UpdateImpl() CM_OVERRIDE;
+ bool NoteOldRevision() override;
+ bool NoteNewRevision() override;
+ bool UpdateImpl() override;
bool UpdateCustom(const std::string& custom);
- bool LoadRevisions() CM_OVERRIDE;
- bool LoadModifications() CM_OVERRIDE;
+ bool LoadRevisions() override;
+ bool LoadModifications() override;
class ChangesParser;
class DescribeParser;
diff --git a/Source/CTest/cmCTestReadCustomFilesCommand.cxx b/Source/CTest/cmCTestReadCustomFilesCommand.cxx
index b21be872f..ed14d0688 100644
--- a/Source/CTest/cmCTestReadCustomFilesCommand.cxx
+++ b/Source/CTest/cmCTestReadCustomFilesCommand.cxx
@@ -14,9 +14,8 @@ bool cmCTestReadCustomFilesCommand::InitialPass(
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);
+ for (std::string const& arg : args) {
+ this->CTest->ReadCustomConfigurationFileTree(arg.c_str(), this->Makefile);
}
return true;
diff --git a/Source/CTest/cmCTestReadCustomFilesCommand.h b/Source/CTest/cmCTestReadCustomFilesCommand.h
index 5989fa0fc..ba25c516c 100644
--- a/Source/CTest/cmCTestReadCustomFilesCommand.h
+++ b/Source/CTest/cmCTestReadCustomFilesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestReadCustomFilesCommand_h
#define cmCTestReadCustomFilesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
@@ -27,7 +27,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestReadCustomFilesCommand* ni = new cmCTestReadCustomFilesCommand;
ni->CTest = this->CTest;
@@ -39,7 +39,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/CTest/cmCTestRunScriptCommand.cxx b/Source/CTest/cmCTestRunScriptCommand.cxx
index 238284a3f..a7e47d35c 100644
--- a/Source/CTest/cmCTestRunScriptCommand.cxx
+++ b/Source/CTest/cmCTestRunScriptCommand.cxx
@@ -39,7 +39,8 @@ bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args,
++i;
} else {
int ret;
- cmCTestScriptHandler::RunScript(this->CTest, args[i].c_str(), !np, &ret);
+ cmCTestScriptHandler::RunScript(this->CTest, this->Makefile,
+ args[i].c_str(), !np, &ret);
std::ostringstream str;
str << ret;
this->Makefile->AddDefinition(returnVariable, str.str().c_str());
diff --git a/Source/CTest/cmCTestRunScriptCommand.h b/Source/CTest/cmCTestRunScriptCommand.h
index 9bd09659d..9d8b4b587 100644
--- a/Source/CTest/cmCTestRunScriptCommand.h
+++ b/Source/CTest/cmCTestRunScriptCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestRunScriptCommand_h
#define cmCTestRunScriptCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
@@ -27,7 +27,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestRunScriptCommand* ni = new cmCTestRunScriptCommand;
ni->CTest = this->CTest;
@@ -40,7 +40,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx
index 0c4269e3d..31976b994 100644
--- a/Source/CTest/cmCTestRunTest.cxx
+++ b/Source/CTest/cmCTestRunTest.cxx
@@ -4,178 +4,85 @@
#include "cmCTest.h"
#include "cmCTestMemCheckHandler.h"
-#include "cmCTestTestHandler.h"
+#include "cmCTestMultiProcessHandler.h"
#include "cmProcess.h"
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
-#include "cmConfigure.h"
-#include "cm_curl.h"
-#include "cm_zlib.h"
-#include "cmsys/Base64.h"
-#include "cmsys/Process.h"
#include "cmsys/RegularExpression.hxx"
+#include <chrono>
+#include <cmAlgorithms.h>
+#include <cstdint>
+#include <cstring>
#include <iomanip>
+#include <ratio>
#include <sstream>
#include <stdio.h>
-#include <time.h>
#include <utility>
-cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
+cmCTestRunTest::cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler)
+ : MultiTestHandler(multiHandler)
{
- this->CTest = handler->CTest;
- this->TestHandler = handler;
- this->TestProcess = CM_NULLPTR;
- this->TestResult.ExecutionTime = 0;
+ this->CTest = multiHandler.CTest;
+ this->TestHandler = multiHandler.TestHandler;
+ this->TestResult.ExecutionTime = cmDuration::zero();
this->TestResult.ReturnValue = 0;
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
this->TestResult.TestCount = 0;
- this->TestResult.Properties = CM_NULLPTR;
- this->ProcessOutput = "";
- this->CompressedOutput = "";
- this->CompressionRatio = 2;
- this->StopTimePassed = false;
+ this->TestResult.Properties = nullptr;
this->NumberOfRunsLeft = 1; // default to 1 run of the test
this->RunUntilFail = false; // default to run the test once
this->RunAgain = false; // default to not having to run again
}
-cmCTestRunTest::~cmCTestRunTest()
+void cmCTestRunTest::CheckOutput(std::string const& line)
{
-}
-
-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;
- }
- if (p == cmsysProcess_Pipe_STDOUT) {
- // Store this line of output.
- cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex()
- << ": " << line << std::endl);
- this->ProcessOutput += line;
- this->ProcessOutput += "\n";
-
- // Check for TIMEOUT_AFTER_MATCH property.
- if (!this->TestProperties->TimeoutRegularExpressions.empty()) {
- std::vector<
- std::pair<cmsys::RegularExpression, std::string> >::iterator regIt;
- for (regIt = this->TestProperties->TimeoutRegularExpressions.begin();
- regIt != this->TestProperties->TimeoutRegularExpressions.end();
- ++regIt) {
- if (regIt->first.find(this->ProcessOutput.c_str())) {
- cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->GetIndex()
- << ": "
- << "Test timeout changed to "
- << this->TestProperties->AlternateTimeout
- << std::endl);
- this->TestProcess->ResetStartTime();
- this->TestProcess->ChangeTimeout(
- this->TestProperties->AlternateTimeout);
- this->TestProperties->TimeoutRegularExpressions.clear();
- break;
- }
- }
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->GetIndex() << ": " << line << std::endl);
+ this->ProcessOutput += line;
+ this->ProcessOutput += "\n";
+
+ // Check for TIMEOUT_AFTER_MATCH property.
+ if (!this->TestProperties->TimeoutRegularExpressions.empty()) {
+ for (auto& reg : this->TestProperties->TimeoutRegularExpressions) {
+ if (reg.first.find(this->ProcessOutput)) {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->GetIndex()
+ << ": "
+ << "Test timeout changed to "
+ << std::chrono::duration_cast<std::chrono::seconds>(
+ this->TestProperties->AlternateTimeout)
+ .count()
+ << std::endl);
+ this->TestProcess->ResetStartTime();
+ this->TestProcess->ChangeTimeout(
+ this->TestProperties->AlternateTimeout);
+ this->TestProperties->TimeoutRegularExpressions.clear();
+ break;
}
- } 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_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)];
-
- size_t rlen = cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1);
-
- this->CompressedOutput.clear();
- for (size_t 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->ShouldCompressTestOutput())) {
- 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;
+ cmProcess::State res =
+ started ? this->TestProcess->GetProcessStatus() : cmProcess::State::Error;
+ if (res != cmProcess::State::Expired) {
+ this->TimeoutIsForStopTime = false;
+ }
+ std::int64_t retVal = this->TestProcess->GetExitValue();
bool forceFail = false;
bool skipped = false;
bool outputTestErrorsToConsole = false;
if (!this->TestProperties->RequiredRegularExpressions.empty() &&
this->FailedDependencies.empty()) {
bool found = false;
- for (passIt = this->TestProperties->RequiredRegularExpressions.begin();
- passIt != this->TestProperties->RequiredRegularExpressions.end();
- ++passIt) {
- if (passIt->first.find(this->ProcessOutput.c_str())) {
+ for (auto& pass : this->TestProperties->RequiredRegularExpressions) {
+ if (pass.first.find(this->ProcessOutput)) {
found = true;
reason = "Required regular expression found.";
break;
@@ -186,30 +93,27 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
forceFail = true;
}
reason += "Regex=[";
- for (passIt = this->TestProperties->RequiredRegularExpressions.begin();
- passIt != this->TestProperties->RequiredRegularExpressions.end();
- ++passIt) {
- reason += passIt->second;
+ for (auto& pass : this->TestProperties->RequiredRegularExpressions) {
+ reason += pass.second;
reason += "\n";
}
reason += "]";
}
if (!this->TestProperties->ErrorRegularExpressions.empty() &&
this->FailedDependencies.empty()) {
- for (passIt = this->TestProperties->ErrorRegularExpressions.begin();
- passIt != this->TestProperties->ErrorRegularExpressions.end();
- ++passIt) {
- if (passIt->first.find(this->ProcessOutput.c_str())) {
+ for (auto& pass : this->TestProperties->ErrorRegularExpressions) {
+ if (pass.first.find(this->ProcessOutput)) {
reason = "Error regular expression found in output.";
reason += " Regex=[";
- reason += passIt->second;
+ reason += pass.second;
reason += "]";
forceFail = true;
break;
}
}
}
- if (res == cmsysProcess_State_Exited) {
+ std::ostringstream outputStream;
+ if (res == cmProcess::State::Exited) {
bool success = !forceFail &&
(retVal == 0 ||
!this->TestProperties->RequiredRegularExpressions.empty());
@@ -224,51 +128,82 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
} else if ((success && !this->TestProperties->WillFail) ||
(!success && this->TestProperties->WillFail)) {
this->TestResult.Status = cmCTestTestHandler::COMPLETED;
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed ");
+ outputStream << " Passed ";
} else {
this->TestResult.Status = cmCTestTestHandler::FAILED;
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason);
- outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
+ outputStream << "***Failed " << reason;
+ outputTestErrorsToConsole =
+ this->CTest->GetOutputTestOutputOnTestFailure();
}
- } else if (res == cmsysProcess_State_Expired) {
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout ");
+ } else if (res == cmProcess::State::Expired) {
+ outputStream << "***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: ");
+ outputTestErrorsToConsole =
+ this->CTest->GetOutputTestOutputOnTestFailure();
+ } else if (res == cmProcess::State::Exception) {
+ outputTestErrorsToConsole =
+ this->CTest->GetOutputTestOutputOnTestFailure();
+ outputStream << "***Exception: ";
+ this->TestResult.ExceptionStatus =
+ this->TestProcess->GetExitExceptionString();
switch (this->TestProcess->GetExitException()) {
- case cmsysProcess_Exception_Fault:
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
+ case cmProcess::Exception::Fault:
+ outputStream << "SegFault";
this->TestResult.Status = cmCTestTestHandler::SEGFAULT;
break;
- case cmsysProcess_Exception_Illegal:
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
+ case cmProcess::Exception::Illegal:
+ outputStream << "Illegal";
this->TestResult.Status = cmCTestTestHandler::ILLEGAL;
break;
- case cmsysProcess_Exception_Interrupt:
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
+ case cmProcess::Exception::Interrupt:
+ outputStream << "Interrupt";
this->TestResult.Status = cmCTestTestHandler::INTERRUPT;
break;
- case cmsysProcess_Exception_Numerical:
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
+ case cmProcess::Exception::Numerical:
+ outputStream << "Numerical";
this->TestResult.Status = cmCTestTestHandler::NUMERICAL;
break;
default:
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->TestResult.ExceptionStatus);
this->TestResult.Status = cmCTestTestHandler::OTHER_FAULT;
}
} else if ("Disabled" == this->TestResult.CompletionStatus) {
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run (Disabled) ");
- } else // cmsysProcess_State_Error
+ outputStream << "***Not Run (Disabled) ";
+ } else // cmProcess::State::Error
{
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run ");
+ outputStream << "***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");
+ sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime().count());
+ outputStream << buf << "\n";
+
+ if (this->CTest->GetTestProgressOutput()) {
+ if (!passed) {
+ // If the test did not pass, reprint test name and error
+ std::string output = GetTestPrefix(completed, total);
+ std::string testName = this->TestProperties->Name;
+ const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
+ testName.resize(maxTestNameWidth + 4, '.');
+
+ output += testName;
+ output += outputStream.str();
+ outputStream.str("");
+ outputStream.clear();
+ outputStream << output;
+ cmCTestLog(this->CTest, HANDLER_TEST_PROGRESS_OUTPUT, "\n"); // flush
+ }
+ if (completed == total) {
+ std::string testName =
+ GetTestPrefix(completed, total) + this->TestProperties->Name + "\n";
+ cmCTestLog(this->CTest, HANDLER_TEST_PROGRESS_OUTPUT, testName);
+ }
+ }
+ if (!this->CTest->GetTestProgressOutput() || !passed) {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, outputStream.str());
+ }
if (outputTestErrorsToConsole) {
cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl);
@@ -278,11 +213,7 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
*this->TestHandler->LogFile << "Test time = " << buf << std::endl;
}
- // Set the working directory to the tests directory to process Dart files.
- {
- cmWorkingDirectory workdir(this->TestProperties->Directory);
- this->DartProcessing();
- }
+ this->DartProcessing();
// if this is doing MemCheck then all the output needs to be put into
// Output since that is what is parsed by cmCTestMemCheckHandler
@@ -303,12 +234,16 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
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;
+ auto ttime = this->TestProcess->GetTotalTime();
+ auto hours = std::chrono::duration_cast<std::chrono::hours>(ttime);
+ ttime -= hours;
+ auto minutes = std::chrono::duration_cast<std::chrono::minutes>(ttime);
+ ttime -= minutes;
+ auto seconds = std::chrono::duration_cast<std::chrono::seconds>(ttime);
char buffer[100];
- sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
+ sprintf(buffer, "%02d:%02d:%02d", static_cast<unsigned>(hours.count()),
+ static_cast<unsigned>(minutes.count()),
+ static_cast<unsigned>(seconds.count()));
*this->TestHandler->LogFile
<< "----------------------------------------------------------"
<< std::endl;
@@ -334,10 +269,18 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
// 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();
+ std::string compressedOutput;
+ if (!this->TestHandler->MemCheck &&
+ this->CTest->ShouldCompressTestOutput()) {
+ std::string str = this->ProcessOutput;
+ if (this->CTest->CompressString(str)) {
+ compressedOutput = std::move(str);
+ }
+ }
+ bool compress = !compressedOutput.empty() &&
+ compressedOutput.length() < this->ProcessOutput.length();
this->TestResult.Output =
- compress ? this->CompressedOutput : this->ProcessOutput;
+ compress ? compressedOutput : this->ProcessOutput;
this->TestResult.CompressOutput = compress;
this->TestResult.ReturnValue = this->TestProcess->GetExitValue();
if (!skipped) {
@@ -352,11 +295,11 @@ bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
if (!this->NeedsToRerun()) {
this->TestHandler->TestResults.push_back(this->TestResult);
}
- delete this->TestProcess;
+ this->TestProcess.reset();
return passed || skipped;
}
-bool cmCTestRunTest::StartAgain()
+bool cmCTestRunTest::StartAgain(size_t completed)
{
if (!this->RunAgain) {
return false;
@@ -364,7 +307,14 @@ bool cmCTestRunTest::StartAgain()
this->RunAgain = false; // reset
// change to tests directory
cmWorkingDirectory workdir(this->TestProperties->Directory);
- this->StartTest(this->TotalNumberOfTests);
+ if (workdir.Failed()) {
+ this->StartFailure("Failed to change working directory to " +
+ this->TestProperties->Directory + " : " +
+ std::strerror(workdir.GetLastResult()));
+ return true;
+ }
+
+ this->StartTest(completed, this->TotalNumberOfTests);
return true;
}
@@ -388,7 +338,7 @@ void cmCTestRunTest::ComputeWeightedCost()
{
double prev = static_cast<double>(this->TestProperties->PreviousRuns);
double avgcost = static_cast<double>(this->TestProperties->Cost);
- double current = this->TestResult.ExecutionTime;
+ double current = this->TestResult.ExecutionTime.count();
if (this->TestResult.Status == cmCTestTestHandler::COMPLETED) {
this->TestProperties->Cost =
@@ -402,75 +352,133 @@ void cmCTestRunTest::MemCheckPostProcess()
if (!this->TestHandler->MemCheck) {
return;
}
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
- << ": process test output now: "
- << this->TestProperties->Name << " "
- << this->TestResult.Name << std::endl,
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->Index << ": process test output now: "
+ << this->TestProperties->Name << " "
+ << this->TestResult.Name << std::endl,
this->TestHandler->GetQuiet());
cmCTestMemCheckHandler* handler =
static_cast<cmCTestMemCheckHandler*>(this->TestHandler);
handler->PostProcessTest(this->TestResult, this->Index);
}
+void cmCTestRunTest::StartFailure(std::string const& output)
+{
+ // Still need to log the Start message so the test summary records our
+ // attempt to start this test
+ if (!this->CTest->GetTestProgressOutput()) {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ std::setw(2 * getNumWidth(this->TotalNumberOfTests) + 8)
+ << "Start "
+ << std::setw(getNumWidth(this->TestHandler->GetMaxIndex()))
+ << this->TestProperties->Index << ": "
+ << this->TestProperties->Name << std::endl);
+ }
+
+ this->ProcessOutput.clear();
+ if (!output.empty()) {
+ *this->TestHandler->LogFile << output << std::endl;
+ cmCTestLog(this->CTest, ERROR_MESSAGE, output << std::endl);
+ }
+
+ this->TestResult.Properties = this->TestProperties;
+ this->TestResult.ExecutionTime = cmDuration::zero();
+ this->TestResult.CompressOutput = false;
+ this->TestResult.ReturnValue = -1;
+ this->TestResult.CompletionStatus = "Failed to start";
+ this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
+ this->TestResult.TestCount = this->TestProperties->Index;
+ this->TestResult.Name = this->TestProperties->Name;
+ this->TestResult.Path = this->TestProperties->Directory;
+ this->TestResult.Output = output;
+ this->TestResult.FullCommandLine.clear();
+ this->TestProcess = cm::make_unique<cmProcess>(*this);
+}
+
+std::string cmCTestRunTest::GetTestPrefix(size_t completed, size_t total) const
+{
+ std::ostringstream outputStream;
+ outputStream << std::setw(getNumWidth(total)) << completed << "/";
+ outputStream << std::setw(getNumWidth(total)) << total << " ";
+
+ if (this->TestHandler->MemCheck) {
+ outputStream << "MemCheck";
+ } else {
+ outputStream << "Test";
+ }
+
+ std::ostringstream indexStr;
+ indexStr << " #" << this->Index << ":";
+ outputStream << std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
+ << indexStr.str();
+ outputStream << " ";
+
+ return outputStream.str();
+}
+
// Starts the execution of a test. Returns once it has started
-bool cmCTestRunTest::StartTest(size_t total)
+bool cmCTestRunTest::StartTest(size_t completed, size_t total)
{
this->TotalNumberOfTests = total; // save for rerun case
- 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);
+ if (!this->CTest->GetTestProgressOutput()) {
+ 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);
+ } else {
+ std::string testName =
+ GetTestPrefix(completed, total) + this->TestProperties->Name + "\n";
+ cmCTestLog(this->CTest, HANDLER_TEST_PROGRESS_OUTPUT, testName);
+ }
+
this->ProcessOutput.clear();
+ this->TestResult.Properties = this->TestProperties;
+ this->TestResult.ExecutionTime = cmDuration::zero();
+ this->TestResult.CompressOutput = false;
+ this->TestResult.ReturnValue = -1;
+ this->TestResult.TestCount = this->TestProperties->Index;
+ this->TestResult.Name = this->TestProperties->Name;
+ this->TestResult.Path = this->TestProperties->Directory;
+
// Return immediately if test is disabled
if (this->TestProperties->Disabled) {
- this->TestResult.Properties = this->TestProperties;
- this->TestResult.ExecutionTime = 0;
- this->TestResult.CompressOutput = false;
- this->TestResult.ReturnValue = -1;
this->TestResult.CompletionStatus = "Disabled";
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
- this->TestResult.TestCount = this->TestProperties->Index;
- this->TestResult.Name = this->TestProperties->Name;
- this->TestResult.Path = this->TestProperties->Directory;
- this->TestProcess = new cmProcess;
+ this->TestProcess = cm::make_unique<cmProcess>(*this);
this->TestResult.Output = "Disabled";
- this->TestResult.FullCommandLine = "";
+ this->TestResult.FullCommandLine.clear();
return false;
}
- 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;
+ // Check for failed fixture dependencies before we even look at the command
+ // arguments because if we are not going to run the test, the command and
+ // its arguments are irrelevant. This matters for the case where a fixture
+ // dependency might be creating the executable we want to run.
if (!this->FailedDependencies.empty()) {
- this->TestProcess = new cmProcess;
+ this->TestProcess = cm::make_unique<cmProcess>(*this);
std::string msg = "Failed test dependencies:";
- for (std::set<std::string>::const_iterator it =
- this->FailedDependencies.begin();
- it != this->FailedDependencies.end(); ++it) {
- msg += " " + *it;
+ for (std::string const& failedDep : this->FailedDependencies) {
+ msg += " " + failedDep;
}
*this->TestHandler->LogFile << msg << std::endl;
cmCTestLog(this->CTest, HANDLER_OUTPUT, msg << std::endl);
this->TestResult.Output = msg;
- this->TestResult.FullCommandLine = "";
+ this->TestResult.FullCommandLine.clear();
this->TestResult.CompletionStatus = "Fixture dependency failed";
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
return false;
}
+ this->ComputeArguments();
+ std::vector<std::string>& args = this->TestProperties->Args;
if (args.size() >= 2 && args[1] == "NOT_AVAILABLE") {
- this->TestProcess = new cmProcess;
+ this->TestProcess = cm::make_unique<cmProcess>(*this);
std::string msg;
if (this->CTest->GetConfigType().empty()) {
msg = "Test not available without configuration.";
@@ -483,61 +491,71 @@ bool cmCTestRunTest::StartTest(size_t total)
*this->TestHandler->LogFile << msg << std::endl;
cmCTestLog(this->CTest, ERROR_MESSAGE, msg << std::endl);
this->TestResult.Output = msg;
- this->TestResult.FullCommandLine = "";
+ this->TestResult.FullCommandLine.clear();
this->TestResult.CompletionStatus = "Missing Configuration";
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())) {
+ for (std::string const& file : this->TestProperties->RequiredFiles) {
+ if (!cmSystemTools::FileExists(file)) {
// Required file was not found
- this->TestProcess = new cmProcess;
+ this->TestProcess = cm::make_unique<cmProcess>(*this);
*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.FullCommandLine.clear();
this->TestResult.CompletionStatus = "Required Files Missing";
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
return false;
}
}
// log and return if we did not find the executable
- if (this->ActualCommand == "") {
+ if (this->ActualCommand.empty()) {
// if the command was not found create a TestResult object
// that has that information
- this->TestProcess = new cmProcess;
+ this->TestProcess = cm::make_unique<cmProcess>(*this);
*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.FullCommandLine.clear();
this->TestResult.CompletionStatus = "Unable to find executable";
this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
return false;
}
this->StartTime = this->CTest->CurrentTime();
- double timeout = this->ResolveTimeout();
+ auto timeout = this->TestProperties->Timeout;
- if (this->StopTimePassed) {
- return false;
+ this->TimeoutIsForStopTime = false;
+ std::chrono::system_clock::time_point stop_time = this->CTest->GetStopTime();
+ if (stop_time != std::chrono::system_clock::time_point()) {
+ std::chrono::duration<double> stop_timeout =
+ (stop_time - std::chrono::system_clock::now()) % std::chrono::hours(24);
+
+ if (stop_timeout <= std::chrono::duration<double>::zero()) {
+ stop_timeout = std::chrono::duration<double>::zero();
+ }
+ if (timeout == std::chrono::duration<double>::zero() ||
+ stop_timeout < timeout) {
+ this->TimeoutIsForStopTime = true;
+ timeout = stop_timeout;
+ }
}
+
return this->ForkProcess(timeout, this->TestProperties->ExplicitTimeout,
- &this->TestProperties->Environment);
+ &this->TestProperties->Environment,
+ &this->TestProperties->Affinity);
}
void cmCTestRunTest::ComputeArguments()
{
- this->Arguments.clear(); // reset becaue this might be a rerun
+ this->Arguments.clear(); // reset because this might be a rerun
std::vector<std::string>::const_iterator j =
this->TestProperties->Args.begin();
++j; // skip test name
@@ -554,14 +572,13 @@ void cmCTestRunTest::ComputeArguments()
++j; // skip the executable (it will be actualCommand)
}
std::string testCommand =
- cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
+ cmSystemTools::ConvertToOutputPath(this->ActualCommand);
// 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) {
+ for (std::string const& arg : this->Arguments) {
testCommand += " \"";
- testCommand += *i;
+ testCommand += arg;
testCommand += "\"";
}
@@ -574,22 +591,21 @@ void cmCTestRunTest::ComputeArguments()
this->TestResult.FullCommandLine = testCommand;
// Print the test command in verbose mode
- cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ std::endl
<< this->Index << ": "
<< (this->TestHandler->MemCheck ? "MemCheck" : "Test")
<< " command: " << testCommand << std::endl);
// Print any test-specific env vars in verbose mode
if (!this->TestProperties->Environment.empty()) {
- cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
- << ": "
- << "Environment variables: " << std::endl);
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->Index << ": "
+ << "Environment variables: " << std::endl);
}
- for (std::vector<std::string>::const_iterator e =
- this->TestProperties->Environment.begin();
- e != this->TestProperties->Environment.end(); ++e) {
- cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": " << *e
- << std::endl);
+ for (std::string const& env : this->TestProperties->Environment) {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->Index << ": " << env << std::endl);
}
}
@@ -597,10 +613,10 @@ void cmCTestRunTest::DartProcessing()
{
if (!this->ProcessOutput.empty() &&
this->ProcessOutput.find("<DartMeasurement") != std::string::npos) {
- if (this->TestHandler->DartStuff.find(this->ProcessOutput.c_str())) {
+ if (this->TestHandler->DartStuff.find(this->ProcessOutput)) {
this->TestResult.DartString = this->TestHandler->DartStuff.match(1);
// keep searching and replacing until none are left
- while (this->TestHandler->DartStuff1.find(this->ProcessOutput.c_str())) {
+ while (this->TestHandler->DartStuff1.find(this->ProcessOutput)) {
// replace the exact match for the string
cmSystemTools::ReplaceString(
this->ProcessOutput, this->TestHandler->DartStuff1.match(1).c_str(),
@@ -610,92 +626,42 @@ void cmCTestRunTest::DartProcessing()
}
}
-double cmCTestRunTest::ResolveTimeout()
+bool cmCTestRunTest::ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
+ std::vector<std::string>* environment,
+ std::vector<size_t>* affinity)
{
- double timeout = this->TestProperties->Timeout;
-
- if (this->CTest->GetStopTime() == "") {
- return timeout;
- }
- struct tm* lctime;
- time_t current_time = time(CM_NULLPTR);
- 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 = cm::make_unique<cmProcess>(*this);
this->TestProcess->SetId(this->Index);
- this->TestProcess->SetWorkingDirectory(
- this->TestProperties->Directory.c_str());
- this->TestProcess->SetCommand(this->ActualCommand.c_str());
+ this->TestProcess->SetWorkingDirectory(this->TestProperties->Directory);
+ this->TestProcess->SetCommand(this->ActualCommand);
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) {
+ cmDuration timeout = this->CTest->GetRemainingTimeAllowed();
+ if (timeout != cmCTest::MaxDuration()) {
+ timeout -= std::chrono::minutes(2);
+ }
+ if (this->CTest->GetTimeOut() > cmDuration::zero() &&
+ this->CTest->GetTimeOut() < timeout) {
timeout = this->CTest->GetTimeOut();
}
- if (testTimeOut > 0 &&
+ if (testTimeOut > cmDuration::zero() &&
testTimeOut < this->CTest->GetRemainingTimeAllowed()) {
timeout = testTimeOut;
}
// always have at least 1 second if we got to here
- if (timeout <= 0) {
- timeout = 1;
+ if (timeout <= cmDuration::zero()) {
+ timeout = std::chrono::seconds(1);
}
// handle timeout explicitly set to 0
- if (testTimeOut == 0 && explicitTimeout) {
- timeout = 0;
- }
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
- << ": "
- << "Test timeout computed to be: " << timeout << "\n",
+ if (testTimeOut == cmDuration::zero() && explicitTimeout) {
+ timeout = cmDuration::zero();
+ }
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ this->Index << ": "
+ << "Test timeout computed to be: "
+ << cmDurationTo<unsigned int>(timeout)
+ << "\n",
this->TestHandler->GetQuiet());
this->TestProcess->SetTimeout(timeout);
@@ -708,49 +674,47 @@ bool cmCTestRunTest::ForkProcess(double testTimeOut, bool explicitTimeout,
cmSystemTools::AppendEnv(*environment);
}
- return this->TestProcess->StartProcess();
+ return this->TestProcess->StartProcess(this->MultiTestHandler.Loop,
+ affinity);
}
void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
{
- // if this is the last or only run of this test
- // then print out completed / total
+ std::ostringstream outputStream;
+
+ // If this is the last or only run of this test, or progress output is
+ // requested, then print out completed / total.
// Only issue is if a test fails and we are running until fail
// then it will never print out the completed / total, same would
// got for run until pass. Trick is when this is called we don't
// yet know if we are passing or failing.
- if (this->NumberOfRunsLeft == 1) {
- cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
- << completed << "/");
- cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
- << total << " ");
+ if (this->NumberOfRunsLeft == 1 || this->CTest->GetTestProgressOutput()) {
+ outputStream << std::setw(getNumWidth(total)) << completed << "/";
+ outputStream << std::setw(getNumWidth(total)) << total << " ";
}
// if this is one of several runs of a test just print blank space
// to keep things neat
else {
- cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
- << " "
- << " ");
- cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
- << " "
- << " ");
+ outputStream << std::setw(getNumWidth(total)) << " ";
+ outputStream << std::setw(getNumWidth(total)) << " ";
}
if (this->TestHandler->MemCheck) {
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "MemCheck");
+ outputStream << "MemCheck";
} else {
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "Test");
+ outputStream << "Test";
}
std::ostringstream indexStr;
indexStr << " #" << this->Index << ":";
- cmCTestLog(this->CTest, HANDLER_OUTPUT,
- std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
- << indexStr.str());
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
+ outputStream << std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
+ << indexStr.str();
+ outputStream << " ";
+
const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
std::string outname = this->TestProperties->Name + " ";
outname.resize(maxTestNameWidth + 4, '.');
+ outputStream << outname;
*this->TestHandler->LogFile << this->TestProperties->Index << "/"
<< this->TestHandler->TotalNumberOfTests
@@ -762,9 +726,8 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
<< 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 << "\"";
+ for (std::string const& arg : this->Arguments) {
+ *this->TestHandler->LogFile << " \"" << arg << "\"";
}
*this->TestHandler->LogFile
<< std::endl
@@ -779,7 +742,15 @@ void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
*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
- << " ... ");
+ if (!this->CTest->GetTestProgressOutput()) {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, outputStream.str());
+ }
+
+ cmCTestLog(this->CTest, DEBUG,
+ "Testing " << this->TestProperties->Name << " ... ");
+}
+
+void cmCTestRunTest::FinalizeTest()
+{
+ this->MultiTestHandler.FinishTestProcess(this, true);
}
diff --git a/Source/CTest/cmCTestRunTest.h b/Source/CTest/cmCTestRunTest.h
index d3bb2296f..38cc417e5 100644
--- a/Source/CTest/cmCTestRunTest.h
+++ b/Source/CTest/cmCTestRunTest.h
@@ -11,9 +11,11 @@
#include <vector>
#include "cmCTestTestHandler.h"
+#include "cmDuration.h"
+#include "cmProcess.h" // IWYU pragma: keep (for unique_ptr)
class cmCTest;
-class cmProcess;
+class cmCTestMultiProcessHandler;
/** \class cmRunTest
* \brief represents a single test to be run
@@ -23,8 +25,7 @@ class cmProcess;
class cmCTestRunTest
{
public:
- cmCTestRunTest(cmCTestTestHandler* handler);
- ~cmCTestRunTest();
+ explicit cmCTestRunTest(cmCTestMultiProcessHandler& multiHandler);
void SetNumberOfRuns(int n) { this->NumberOfRunsLeft = n; }
void SetRunUntilFailOn() { this->RunUntilFail = true; }
@@ -49,21 +50,16 @@ public:
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();
+ void CheckOutput(std::string const& line);
// launch the test process, return whether it started correctly
- bool StartTest(size_t total);
+ bool StartTest(size_t completed, 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
@@ -71,44 +67,49 @@ public:
void ComputeWeightedCost();
- bool StartAgain();
+ bool StartAgain(size_t completed);
+
+ void StartFailure(std::string const& output);
+
+ cmCTest* GetCTest() const { return this->CTest; }
+
+ std::string& GetActualCommand() { return this->ActualCommand; }
+
+ const std::vector<std::string>& GetArguments() { return this->Arguments; }
+
+ void FinalizeTest();
+
+ bool TimedOutForStopTime() const { return this->TimeoutIsForStopTime; }
private:
bool NeedsToRerun();
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);
+ bool ForkProcess(cmDuration testTimeOut, bool explicitTimeout,
+ std::vector<std::string>* environment,
+ std::vector<size_t>* affinity);
void WriteLogOutputTop(size_t completed, size_t total);
// Run post processing of the process output for MemCheck
void MemCheckPostProcess();
+ // Returns "completed/total Test #Index: "
+ std::string GetTestPrefix(size_t completed, size_t total) const;
+
cmCTestTestHandler::cmCTestTestProperties* TestProperties;
+ bool TimeoutIsForStopTime = false;
// 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::unique_ptr<cmProcess> TestProcess;
std::string ProcessOutput;
- std::string CompressedOutput;
- double CompressionRatio;
// The test results
cmCTestTestHandler::cmCTestTestResult TestResult;
+ cmCTestMultiProcessHandler& MultiTestHandler;
int Index;
std::set<std::string> FailedDependencies;
std::string StartTime;
std::string ActualCommand;
std::vector<std::string> Arguments;
- bool StopTimePassed;
bool RunUntilFail;
int NumberOfRunsLeft;
bool RunAgain;
@@ -117,14 +118,12 @@ private:
inline int getNumWidth(size_t n)
{
- int numWidth = 1;
- if (n >= 10) {
- numWidth = 2;
- }
- if (n >= 100) {
- numWidth = 3;
+ int w = 1;
+ while (n >= 10) {
+ n /= 10;
+ ++w;
}
- return numWidth;
+ return w;
}
#endif
diff --git a/Source/CTest/cmCTestSVN.cxx b/Source/CTest/cmCTestSVN.cxx
index f60f78c21..c834686d7 100644
--- a/Source/CTest/cmCTestSVN.cxx
+++ b/Source/CTest/cmCTestSVN.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestSVN.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestVC.h"
#include "cmProcessTools.h"
@@ -26,9 +27,7 @@ cmCTestSVN::cmCTestSVN(cmCTest* ct, std::ostream& log)
this->PriorRev = this->Unknown;
}
-cmCTestSVN::~cmCTestSVN()
-{
-}
+cmCTestSVN::~cmCTestSVN() = default;
void cmCTestSVN::CleanupImpl()
{
@@ -59,7 +58,7 @@ private:
cmsys::RegularExpression RegexRev;
cmsys::RegularExpression RegexURL;
cmsys::RegularExpression RegexRoot;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexRev.find(this->Line)) {
this->Rev = this->RegexRev.match(1);
@@ -103,16 +102,14 @@ bool cmCTestSVN::NoteOldRevision()
return false;
}
- std::vector<SVNInfo>::iterator itbeg = this->Repositories.begin();
- std::vector<SVNInfo>::iterator itend = this->Repositories.end();
- for (; itbeg != itend; itbeg++) {
- SVNInfo& svninfo = *itbeg;
+ for (SVNInfo& svninfo : this->Repositories) {
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");
+ 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
@@ -127,16 +124,14 @@ bool cmCTestSVN::NoteNewRevision()
return false;
}
- std::vector<SVNInfo>::iterator itbeg = this->Repositories.begin();
- std::vector<SVNInfo>::iterator itend = this->Repositories.end();
- for (; itbeg != itend; itbeg++) {
- SVNInfo& svninfo = *itbeg;
+ for (SVNInfo& svninfo : this->Repositories) {
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");
+ 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
@@ -205,7 +200,7 @@ private:
cmCTestSVN* SVN;
cmsys::RegularExpression RegexUpdate;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexUpdate.find(this->Line)) {
this->DoPath(this->RegexUpdate.match(1)[0],
@@ -248,7 +243,7 @@ bool cmCTestSVN::UpdateImpl()
if (opts.empty()) {
opts = this->CTest->GetCTestConfiguration("SVNUpdateOptions");
}
- std::vector<std::string> args = cmSystemTools::ParseArguments(opts.c_str());
+ std::vector<std::string> args = cmSystemTools::ParseArguments(opts);
// Specify the start time for nightly testing.
if (this->CTest->GetTestModel() == cmCTest::NIGHTLY) {
@@ -257,9 +252,8 @@ bool cmCTestSVN::UpdateImpl()
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());
+ for (std::string const& arg : args) {
+ svn_update.push_back(arg.c_str());
}
UpdateParser out(this, "up-out> ");
@@ -276,21 +270,18 @@ bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters,
std::vector<char const*> args;
args.push_back(this->CommandLineTool.c_str());
-
- args.insert(args.end(), parameters.begin(), parameters.end());
-
+ cmAppend(args, parameters);
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());
+ cmSystemTools::ParseArguments(userOptions);
+ for (std::string const& opt : parsedUserOptions) {
+ args.push_back(opt.c_str());
}
- args.push_back(CM_NULLPTR);
+ args.push_back(nullptr);
if (strcmp(parameters[0], "update") == 0) {
return RunUpdateCommand(&args[0], out, err);
@@ -298,8 +289,9 @@ bool cmCTestSVN::RunSVNCommand(std::vector<char const*> const& parameters,
return RunChild(&args[0], out, err);
}
-class cmCTestSVN::LogParser : public cmCTestVC::OutputLogger,
- private cmXMLParser
+class cmCTestSVN::LogParser
+ : public cmCTestVC::OutputLogger
+ , private cmXMLParser
{
public:
LogParser(cmCTestSVN* svn, const char* prefix, SVNInfo& svninfo)
@@ -309,7 +301,8 @@ public:
{
this->InitializeParser();
}
- ~LogParser() CM_OVERRIDE { this->CleanupParser(); }
+ ~LogParser() override { this->CleanupParser(); }
+
private:
cmCTestSVN* SVN;
cmCTestSVN::SVNInfo& SVNRepo;
@@ -321,37 +314,39 @@ private:
Change CurChange;
std::vector<char> CData;
- bool ProcessChunk(const char* data, int length) CM_OVERRIDE
+ bool ProcessChunk(const char* data, int length) override
{
this->OutputLogger::ProcessChunk(data, length);
this->ParseChunk(data, length);
return true;
}
- void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** atts) override
{
this->CData.clear();
if (name == "logentry") {
this->Rev = Revision();
this->Rev.SVNInfo = &SVNRepo;
- if (const char* rev = this->FindAttribute(atts, "revision")) {
+ if (const char* rev =
+ cmCTestSVN::LogParser::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")) {
+ if (const char* action =
+ cmCTestSVN::LogParser::FindAttribute(atts, "action")) {
this->CurChange.Action = action[0];
}
}
}
- void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
+ void CharacterDataHandler(const char* data, int length) override
{
- this->CData.insert(this->CData.end(), data, data + length);
+ cmAppend(this->CData, data, data + length);
}
- void EndElement(const std::string& name) CM_OVERRIDE
+ void EndElement(const std::string& name) override
{
if (name == "logentry") {
this->SVN->DoRevisionSVN(this->Rev, this->Changes);
@@ -370,7 +365,7 @@ private:
this->CData.clear();
}
- void ReportError(int /*line*/, int /*column*/, const char* msg) CM_OVERRIDE
+ void ReportError(int /*line*/, int /*column*/, const char* msg) override
{
this->SVN->Log << "Error parsing svn log xml: " << msg << "\n";
}
@@ -380,10 +375,7 @@ bool cmCTestSVN::LoadRevisions()
{
bool result = true;
// Get revisions for all the external repositories
- std::vector<SVNInfo>::iterator itbeg = this->Repositories.begin();
- std::vector<SVNInfo>::iterator itend = this->Repositories.end();
- for (; itbeg != itend; itbeg++) {
- SVNInfo& svninfo = *itbeg;
+ for (SVNInfo& svninfo : this->Repositories) {
result = this->LoadRevisions(svninfo) && result;
}
return result;
@@ -421,7 +413,7 @@ void cmCTestSVN::DoRevisionSVN(Revision const& revision,
// Ignore changes in the old revision for external repositories
if (revision.Rev == revision.SVNInfo->OldRevision &&
- revision.SVNInfo->LocalPath != "") {
+ !revision.SVNInfo->LocalPath.empty()) {
return;
}
@@ -441,7 +433,7 @@ public:
private:
cmCTestSVN* SVN;
cmsys::RegularExpression RegexStatus;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexStatus.find(this->Line)) {
this->DoPath(this->RegexStatus.match(1)[0],
@@ -507,7 +499,7 @@ public:
private:
cmCTestSVN* SVN;
cmsys::RegularExpression RegexExternal;
- bool ProcessLine() CM_OVERRIDE
+ bool ProcessLine() override
{
if (this->RegexExternal.find(this->Line)) {
this->DoPath(this->RegexExternal.match(1));
@@ -522,11 +514,11 @@ private:
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;
+ local_path = path.substr(this->SVN->SourceDirectory.size() + 1);
} else {
local_path = path;
}
- this->SVN->Repositories.push_back(SVNInfo(local_path.c_str()));
+ this->SVN->Repositories.emplace_back(local_path);
}
};
@@ -537,7 +529,7 @@ bool cmCTestSVN::LoadRepositories()
}
// Info for root repository
- this->Repositories.push_back(SVNInfo(""));
+ this->Repositories.emplace_back();
this->RootInfo = &(this->Repositories.back());
// Run "svn status" to get the list of external repositories
@@ -561,7 +553,7 @@ std::string cmCTestSVN::SVNInfo::BuildLocalPath(std::string const& path) const
// 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());
+ local_path += path.substr(this->Base.size());
} else {
local_path += path;
}
diff --git a/Source/CTest/cmCTestSVN.h b/Source/CTest/cmCTestSVN.h
index 46b077835..5c8505d49 100644
--- a/Source/CTest/cmCTestSVN.h
+++ b/Source/CTest/cmCTestSVN.h
@@ -3,11 +3,12 @@
#ifndef cmCTestSVN_h
#define cmCTestSVN_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGlobalVC.h"
#include <iosfwd>
+#include <list>
#include <string>
#include <vector>
@@ -24,14 +25,14 @@ public:
/** Construct with a CTest instance and update log stream. */
cmCTestSVN(cmCTest* ctest, std::ostream& log);
- ~cmCTestSVN() CM_OVERRIDE;
+ ~cmCTestSVN() override;
private:
// Implement cmCTestVC internal API.
- void CleanupImpl() CM_OVERRIDE;
- bool NoteOldRevision() CM_OVERRIDE;
- bool NoteNewRevision() CM_OVERRIDE;
- bool UpdateImpl() CM_OVERRIDE;
+ void CleanupImpl() override;
+ bool NoteOldRevision() override;
+ bool NoteNewRevision() override;
+ bool UpdateImpl() override;
bool RunSVNCommand(std::vector<char const*> const& parameters,
OutputParser* out, OutputParser* err);
@@ -40,7 +41,7 @@ private:
struct SVNInfo
{
- SVNInfo(const char* path)
+ SVNInfo(std::string const& path = std::string())
: LocalPath(path)
{
}
@@ -70,15 +71,16 @@ private:
friend struct Revision;
// Info of all the repositories (root, externals and nested ones).
- std::vector<SVNInfo> Repositories;
+ // Use std::list so the elements don't move in memory.
+ std::list<SVNInfo> Repositories;
// Pointer to the infos of the root repository.
SVNInfo* RootInfo;
std::string LoadInfo(SVNInfo& svninfo);
bool LoadRepositories();
- bool LoadModifications() CM_OVERRIDE;
- bool LoadRevisions() CM_OVERRIDE;
+ bool LoadModifications() override;
+ bool LoadRevisions() override;
bool LoadRevisions(SVNInfo& svninfo);
void GuessBase(SVNInfo& svninfo, std::vector<Change> const& changes);
@@ -86,7 +88,7 @@ private:
void DoRevisionSVN(Revision const& revision,
std::vector<Change> const& changes);
- void WriteXMLGlobal(cmXMLWriter& xml) CM_OVERRIDE;
+ void WriteXMLGlobal(cmXMLWriter& xml) override;
class ExternalParser;
// Parsing helper classes.
diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx
index 1d29dfac2..a739f440c 100644
--- a/Source/CTest/cmCTestScriptHandler.cxx
+++ b/Source/CTest/cmCTestScriptHandler.cxx
@@ -5,6 +5,7 @@
#include "cmsys/Directory.hxx"
#include "cmsys/Process.h"
#include <map>
+#include <ratio>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
@@ -26,6 +27,7 @@
#include "cmCTestTestCommand.h"
#include "cmCTestUpdateCommand.h"
#include "cmCTestUploadCommand.h"
+#include "cmDuration.h"
#include "cmFunctionBlocker.h"
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
@@ -37,9 +39,9 @@
#include "cmake.h"
#ifdef _WIN32
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
class cmExecutionStatus;
@@ -51,10 +53,8 @@ struct cmListFileFunction;
class cmCTestScriptFunctionBlocker : public cmFunctionBlocker
{
public:
- cmCTestScriptFunctionBlocker() {}
- ~cmCTestScriptFunctionBlocker() CM_OVERRIDE {}
bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
- cmExecutionStatus& /*status*/) CM_OVERRIDE;
+ cmExecutionStatus& /*status*/) override;
// virtual bool ShouldRemove(const cmListFileFunction& lff, cmMakefile &mf);
// virtual void ScopeEnded(cmMakefile &mf);
@@ -75,13 +75,14 @@ cmCTestScriptHandler::cmCTestScriptHandler()
this->Backup = false;
this->EmptyBinDir = false;
this->EmptyBinDirOnce = false;
- this->Makefile = CM_NULLPTR;
- this->CMake = CM_NULLPTR;
- this->GlobalGenerator = CM_NULLPTR;
+ this->Makefile = nullptr;
+ this->ParentMakefile = nullptr;
+ this->CMake = nullptr;
+ this->GlobalGenerator = nullptr;
- this->ScriptStartTime = 0;
+ this->ScriptStartTime = std::chrono::steady_clock::time_point();
- // the *60 is becuase the settings are in minutes but GetTime is seconds
+ // the *60 is because the settings are in minutes but GetTime is seconds
this->MinimumInterval = 30 * 60;
this->ContinuousDuration = -1;
}
@@ -93,31 +94,32 @@ void cmCTestScriptHandler::Initialize()
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->SourceDir.clear();
+ this->BinaryDir.clear();
+ this->BackupSourceDir.clear();
+ this->BackupBinaryDir.clear();
+ this->CTestRoot.clear();
+ this->CVSCheckOut.clear();
+ this->CTestCmd.clear();
+ this->UpdateCmd.clear();
+ this->CTestEnv.clear();
+ this->InitialCache.clear();
+ this->CMakeCmd.clear();
+ this->CMOutFile.clear();
this->ExtraUpdates.clear();
this->MinimumInterval = 20 * 60;
this->ContinuousDuration = -1;
// what time in seconds did this script start running
- this->ScriptStartTime = 0;
+ this->ScriptStartTime = std::chrono::steady_clock::time_point();
delete this->Makefile;
- this->Makefile = CM_NULLPTR;
+ this->Makefile = nullptr;
+ this->ParentMakefile = nullptr;
delete this->GlobalGenerator;
- this->GlobalGenerator = CM_NULLPTR;
+ this->GlobalGenerator = nullptr;
delete this->CMake;
}
@@ -133,7 +135,7 @@ cmCTestScriptHandler::~cmCTestScriptHandler()
void cmCTestScriptHandler::AddConfigurationScript(const char* script,
bool pscope)
{
- this->ConfigurationScripts.push_back(script);
+ this->ConfigurationScripts.emplace_back(script);
this->ScriptProcessScope.push_back(pscope);
}
@@ -158,11 +160,10 @@ void cmCTestScriptHandler::UpdateElapsedTime()
{
if (this->Makefile) {
// set the current elapsed time
- char timeString[20];
- int itime = static_cast<unsigned int>(cmSystemTools::GetTime() -
- this->ScriptStartTime);
- sprintf(timeString, "%i", itime);
- this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString);
+ auto itime = cmDurationTo<unsigned int>(std::chrono::steady_clock::now() -
+ this->ScriptStartTime);
+ auto timeString = std::to_string(itime);
+ this->Makefile->AddDefinition("CTEST_ELAPSED_TIME", timeString.c_str());
}
}
@@ -183,8 +184,9 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
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");
+ 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 =
@@ -193,11 +195,11 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
for (size_t i = 1; i < initArgs.size(); ++i) {
argv.push_back(initArgs[i].c_str());
}
- argv.push_back(CM_NULLPTR);
+ argv.push_back(nullptr);
// Now create process object
cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetCommand(cp, argv.data());
// cmsysProcess_SetWorkingDirectory(cp, dir);
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
// cmsysProcess_SetTimeout(cp, timeout);
@@ -206,20 +208,22 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
std::vector<char> out;
std::vector<char> err;
std::string line;
- int pipe = cmSystemTools::WaitForLine(cp, line, 100.0, out, err);
+ int pipe =
+ cmSystemTools::WaitForLine(cp, line, std::chrono::seconds(100), out, err);
while (pipe != cmsysProcess_Pipe_None) {
- cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Output: " << line
- << "\n");
+ 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);
+ pipe = cmSystemTools::WaitForLine(cp, line, std::chrono::seconds(100), out,
+ err);
}
// Properly handle output of the build command
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
int result = cmsysProcess_GetState(cp);
int retVal = 0;
bool failed = false;
@@ -227,17 +231,19 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
retVal = cmsysProcess_GetExitValue(cp);
} else if (result == cmsysProcess_State_Exception) {
retVal = cmsysProcess_GetExitException(cp);
- cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was an exception: "
+ 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);
+ 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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "\tError executing ctest: " << cmsysProcess_GetErrorString(cp)
+ << std::endl);
failed = true;
}
cmsysProcess_Delete(cp);
@@ -245,28 +251,18 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
std::ostringstream message;
message << "Error running command: [";
message << result << "] ";
- for (std::vector<const char*>::iterator i = argv.begin(); i != argv.end();
- ++i) {
- if (*i) {
- message << *i << " ";
+ for (const char* arg : argv) {
+ if (arg) {
+ message << arg << " ";
}
}
- cmCTestLog(this->CTest, ERROR_MESSAGE, message.str() << argv[0]
- << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ message.str() << argv[0] << std::endl);
return -1;
}
return retVal;
}
-static void ctestScriptProgressCallback(const char* m, float /*unused*/,
- 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
@@ -275,7 +271,7 @@ void cmCTestScriptHandler::CreateCMake()
delete this->GlobalGenerator;
delete this->Makefile;
}
- this->CMake = new cmake(cmake::RoleScript);
+ this->CMake = new cmake(cmake::RoleScript, cmState::CTest);
this->CMake->SetHomeDirectory("");
this->CMake->SetHomeOutputDirectory("");
this->CMake->GetCurrentSnapshot().SetDefaultDefinitions();
@@ -287,8 +283,17 @@ void cmCTestScriptHandler::CreateCMake()
snapshot.GetDirectory().SetCurrentSource(cwd);
snapshot.GetDirectory().SetCurrentBinary(cwd);
this->Makefile = new cmMakefile(this->GlobalGenerator, snapshot);
+ if (this->ParentMakefile) {
+ this->Makefile->SetRecursionDepth(
+ this->ParentMakefile->GetRecursionDepth());
+ }
- this->CMake->SetProgressCallback(ctestScriptProgressCallback, this->CTest);
+ this->CMake->SetProgressCallback(
+ [this](const std::string& m, float /*unused*/) {
+ if (!m.empty()) {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- " << m << std::endl);
+ }
+ });
this->AddCTestCommand("ctest_build", new cmCTestBuildCommand);
this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand);
@@ -325,8 +330,8 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
script_arg = total_script_arg.substr(comma_pos + 1);
}
// make sure the file exists
- if (!cmSystemTools::FileExists(script.c_str())) {
- cmSystemTools::Error("Cannot find file: ", script.c_str());
+ if (!cmSystemTools::FileExists(script)) {
+ cmSystemTools::Error("Cannot find file: " + script);
return 1;
}
@@ -344,6 +349,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
this->Makefile->AddDefinition("CMAKE_EXECUTABLE_NAME",
cmSystemTools::GetCMakeCommand().c_str());
this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", true);
+ this->SetRunCurrentScript(true);
this->UpdateElapsedTime();
// add the script arg if defined
@@ -367,23 +373,22 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
ctest scripting easier. */
std::string systemFile =
this->Makefile->GetModulesFile("CTestScriptMode.cmake");
- if (!this->Makefile->ReadListFile(systemFile.c_str()) ||
+ if (!this->Makefile->ReadListFile(systemFile) ||
cmSystemTools::GetErrorOccuredFlag()) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in read:" << systemFile
- << "\n");
+ 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());
+ for (auto const& d : defs) {
+ this->Makefile->AddDefinition(d.first, d.second.c_str());
}
// finally read in the script
- if (!this->Makefile->ReadListFile(script.c_str()) ||
+ if (!this->Makefile->ReadListFile(script) ||
cmSystemTools::GetErrorOccuredFlag()) {
// Reset the error flag so that it can run more than
// one script with an error when you use ctest_run_script.
@@ -394,7 +399,7 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg)
return 0;
}
-// extract variabels from the script to set ivars
+// extract variables from the script to set ivars
int cmCTestScriptHandler::ExtractVariables()
{
// Temporary variables
@@ -442,10 +447,11 @@ int cmCTestScriptHandler::ExtractVariables()
if (updateVal) {
if (this->UpdateCmd.empty()) {
cmSystemTools::Error(
- updateVar, " specified without specifying CTEST_CVS_COMMAND.");
+ std::string(updateVar) +
+ " specified without specifying CTEST_CVS_COMMAND.");
return 12;
}
- this->ExtraUpdates.push_back(updateVal);
+ this->ExtraUpdates.emplace_back(updateVal);
}
}
@@ -466,8 +472,8 @@ int cmCTestScriptHandler::ExtractVariables()
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());
+ "Some required settings in the configuration file were missing:\n" +
+ msg);
return 4;
}
@@ -509,7 +515,7 @@ int cmCTestScriptHandler::RunConfigurationScript(
int result;
- this->ScriptStartTime = cmSystemTools::GetTime();
+ this->ScriptStartTime = std::chrono::steady_clock::now();
// read in the script
if (pscope) {
@@ -525,8 +531,9 @@ int cmCTestScriptHandler::RunConfigurationScript(
return result;
}
- // only run the curent script if we should
- if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT")) {
+ // only run the current script if we should
+ if (this->Makefile && this->Makefile->IsOn("CTEST_RUN_CURRENT_SCRIPT") &&
+ this->ShouldRunCurrentScript) {
return this->RunCurrentScript();
}
return result;
@@ -537,7 +544,7 @@ int cmCTestScriptHandler::RunCurrentScript()
int result;
// do not run twice
- this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", false);
+ this->SetRunCurrentScript(false);
// no popup widows
cmSystemTools::SetRunCommandHideConsole(true);
@@ -557,25 +564,28 @@ int cmCTestScriptHandler::RunCurrentScript()
// 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?
+ // for a continuous, do we need to run it more than once?
if (this->ContinuousDuration >= 0) {
this->UpdateElapsedTime();
- double ending_time = cmSystemTools::GetTime() + this->ContinuousDuration;
+ auto ending_time =
+ std::chrono::steady_clock::now() + cmDuration(this->ContinuousDuration);
if (this->EmptyBinDirOnce) {
this->EmptyBinDir = true;
}
do {
- double interval = cmSystemTools::GetTime();
+ auto startOfInterval = std::chrono::steady_clock::now();
result = this->RunConfigurationDashboard();
- interval = cmSystemTools::GetTime() - interval;
- if (interval < this->MinimumInterval) {
- this->SleepInSeconds(
- static_cast<unsigned int>(this->MinimumInterval - interval));
+ auto interval = std::chrono::steady_clock::now() - startOfInterval;
+ auto minimumInterval = cmDuration(this->MinimumInterval);
+ if (interval < minimumInterval) {
+ auto sleepTime =
+ cmDurationTo<unsigned int>(minimumInterval - interval);
+ this->SleepInSeconds(sleepTime);
}
if (this->EmptyBinDirOnce) {
this->EmptyBinDir = false;
}
- } while (cmSystemTools::GetTime() < ending_time);
+ } while (std::chrono::steady_clock::now() < ending_time);
}
// otherwise just run it once
else {
@@ -592,18 +602,17 @@ int cmCTestScriptHandler::CheckOutSourceDir()
int retVal;
bool res;
- if (!cmSystemTools::FileExists(this->SourceDir.c_str()) &&
+ if (!cmSystemTools::FileExists(this->SourceDir) &&
!this->CVSCheckOut.empty()) {
// we must now checkout the src dir
- output = "";
+ output.clear();
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Run cvs: " << this->CVSCheckOut << std::endl);
res = cmSystemTools::RunSingleCommand(
- this->CVSCheckOut.c_str(), &output, &output, &retVal,
- this->CTestRoot.c_str(), this->HandlerVerbose, 0 /*this->TimeOut*/);
+ this->CVSCheckOut, &output, &output, &retVal, this->CTestRoot.c_str(),
+ this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/);
if (!res || retVal != 0) {
- cmSystemTools::Error("Unable to perform cvs checkout:\n",
- output.c_str());
+ cmSystemTools::Error("Unable to perform cvs checkout:\n" + output);
return 6;
}
}
@@ -623,10 +632,10 @@ int cmCTestScriptHandler::BackupDirectories()
// 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())) {
+ if (cmSystemTools::FileExists(this->BackupSourceDir)) {
cmSystemTools::RemoveADirectory(this->BackupSourceDir);
}
- if (cmSystemTools::FileExists(this->BackupBinaryDir.c_str())) {
+ if (cmSystemTools::FileExists(this->BackupBinaryDir)) {
cmSystemTools::RemoveADirectory(this->BackupBinaryDir);
}
@@ -654,24 +663,23 @@ int cmCTestScriptHandler::PerformExtraUpdates()
// 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) {
+ for (std::string const& eu : this->ExtraUpdates) {
std::vector<std::string> cvsArgs;
- cmSystemTools::ExpandListArgument(*it, cvsArgs);
+ cmSystemTools::ExpandListArgument(eu, cvsArgs);
if (cvsArgs.size() == 2) {
std::string fullCommand = command;
fullCommand += " update ";
fullCommand += cvsArgs[1];
- output = "";
+ output.clear();
retVal = 0;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Run Update: " << fullCommand << std::endl);
res = cmSystemTools::RunSingleCommand(
- fullCommand.c_str(), &output, &output, &retVal, cvsArgs[0].c_str(),
- this->HandlerVerbose, 0 /*this->TimeOut*/);
+ fullCommand, &output, &output, &retVal, cvsArgs[0].c_str(),
+ this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/);
if (!res || retVal != 0) {
- cmSystemTools::Error("Unable to perform extra updates:\n", it->c_str(),
- "\nWith output:\n", output.c_str());
+ cmSystemTools::Error("Unable to perform extra updates:\n" + eu +
+ "\nWith output:\n" + output);
return 0;
}
}
@@ -710,11 +718,11 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
}
// make sure the binary directory exists if it isn't the srcdir
- if (!cmSystemTools::FileExists(this->BinaryDir.c_str()) &&
+ if (!cmSystemTools::FileExists(this->BinaryDir) &&
this->SourceDir != this->BinaryDir) {
- if (!cmSystemTools::MakeDirectory(this->BinaryDir.c_str())) {
- cmSystemTools::Error("Unable to create the binary directory:\n",
- this->BinaryDir.c_str());
+ if (!cmSystemTools::MakeDirectory(this->BinaryDir)) {
+ cmSystemTools::Error("Unable to create the binary directory:\n" +
+ this->BinaryDir);
this->RestoreBackupDirectories();
return 7;
}
@@ -751,8 +759,8 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
// put the initial cache into the bin dir
if (!this->InitialCache.empty()) {
- if (!this->WriteInitialCache(this->BinaryDir.c_str(),
- this->InitialCache.c_str())) {
+ if (!cmCTestScriptHandler::WriteInitialCache(this->BinaryDir.c_str(),
+ this->InitialCache.c_str())) {
this->RestoreBackupDirectories();
return 9;
}
@@ -765,25 +773,25 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
command = this->CMakeCmd;
command += " \"";
command += this->SourceDir;
- output = "";
+ output.clear();
command += "\"";
retVal = 0;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Run cmake command: " << command << std::endl);
res = cmSystemTools::RunSingleCommand(
- command.c_str(), &output, &output, &retVal, this->BinaryDir.c_str(),
- this->HandlerVerbose, 0 /*this->TimeOut*/);
+ command, &output, &output, &retVal, this->BinaryDir.c_str(),
+ this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/);
if (!this->CMOutFile.empty()) {
std::string cmakeOutputFile = this->CMOutFile;
- if (!cmSystemTools::FileIsFullPath(cmakeOutputFile.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(cmakeOutputFile)) {
cmakeOutputFile = this->BinaryDir + "/" + cmakeOutputFile;
}
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Write CMake output to file: " << cmakeOutputFile
<< std::endl);
- cmGeneratedFileStream fout(cmakeOutputFile.c_str());
+ cmGeneratedFileStream fout(cmakeOutputFile);
if (fout) {
fout << output.c_str();
} else {
@@ -803,15 +811,15 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
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 = "";
+ for (std::string const& ctestCommand : ctestCommands) {
+ command = ctestCommand;
+ output.clear();
retVal = 0;
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Run ctest command: " << command << std::endl);
res = cmSystemTools::RunSingleCommand(
- command.c_str(), &output, &output, &retVal, this->BinaryDir.c_str(),
- this->HandlerVerbose, 0 /*this->TimeOut*/);
+ command, &output, &output, &retVal, this->BinaryDir.c_str(),
+ this->HandlerVerbose, cmDuration::zero() /*this->TimeOut*/);
// did something critical fail in ctest
if (!res || cmakeFailed || retVal & cmCTest::BUILD_ERRORS) {
@@ -833,7 +841,7 @@ int cmCTestScriptHandler::RunConfigurationDashboard()
}
}
- // if all was succesful, delete the backup dirs to free up disk space
+ // if all was successful, delete the backup dirs to free up disk space
if (this->Backup) {
cmSystemTools::RemoveADirectory(this->BackupSourceDir);
cmSystemTools::RemoveADirectory(this->BackupBinaryDir);
@@ -847,12 +855,12 @@ bool cmCTestScriptHandler::WriteInitialCache(const char* directory,
{
std::string cacheFile = directory;
cacheFile += "/CMakeCache.txt";
- cmGeneratedFileStream fout(cacheFile.c_str());
+ cmGeneratedFileStream fout(cacheFile);
if (!fout) {
return false;
}
- if (text != CM_NULLPTR) {
+ if (text != nullptr) {
fout.write(text, strlen(text));
}
@@ -870,10 +878,10 @@ void cmCTestScriptHandler::RestoreBackupDirectories()
// 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())) {
+ if (cmSystemTools::FileExists(this->SourceDir)) {
cmSystemTools::RemoveADirectory(this->SourceDir);
}
- if (cmSystemTools::FileExists(this->BinaryDir.c_str())) {
+ if (cmSystemTools::FileExists(this->BinaryDir)) {
cmSystemTools::RemoveADirectory(this->BinaryDir);
}
// rename the src and binary directories
@@ -882,11 +890,13 @@ void cmCTestScriptHandler::RestoreBackupDirectories()
}
}
-bool cmCTestScriptHandler::RunScript(cmCTest* ctest, const char* sname,
- bool InProcess, int* returnValue)
+bool cmCTestScriptHandler::RunScript(cmCTest* ctest, cmMakefile* mf,
+ const char* sname, bool InProcess,
+ int* returnValue)
{
cmCTestScriptHandler* sh = new cmCTestScriptHandler();
sh->SetCTestInstance(ctest);
+ sh->ParentMakefile = mf;
sh->AddConfigurationScript(sname, InProcess);
int res = sh->ProcessHandler();
if (returnValue) {
@@ -912,7 +922,7 @@ bool cmCTestScriptHandler::EmptyBinaryDirectory(const char* sname)
std::string check = sname;
check += "/CMakeCache.txt";
- if (!cmSystemTools::FileExists(check.c_str())) {
+ if (!cmSystemTools::FileExists(check)) {
return false;
}
@@ -958,19 +968,26 @@ bool cmCTestScriptHandler::TryToRemoveBinaryDirectoryOnce(
return cmSystemTools::RemoveADirectory(directoryPath);
}
-double cmCTestScriptHandler::GetRemainingTimeAllowed()
+cmDuration cmCTestScriptHandler::GetRemainingTimeAllowed()
{
if (!this->Makefile) {
- return 1.0e7;
+ return cmCTest::MaxDuration();
}
const char* timelimitS = this->Makefile->GetDefinition("CTEST_TIME_LIMIT");
if (!timelimitS) {
- return 1.0e7;
+ return cmCTest::MaxDuration();
}
- double timelimit = atof(timelimitS);
+ auto timelimit = cmDuration(atof(timelimitS));
- return timelimit - cmSystemTools::GetTime() + this->ScriptStartTime;
+ auto duration = std::chrono::duration_cast<cmDuration>(
+ std::chrono::steady_clock::now() - this->ScriptStartTime);
+ return (timelimit - duration);
+}
+
+void cmCTestScriptHandler::SetRunCurrentScript(bool value)
+{
+ this->ShouldRunCurrentScript = value;
}
diff --git a/Source/CTest/cmCTestScriptHandler.h b/Source/CTest/cmCTestScriptHandler.h
index 667870260..d93b5f8e7 100644
--- a/Source/CTest/cmCTestScriptHandler.h
+++ b/Source/CTest/cmCTestScriptHandler.h
@@ -3,10 +3,12 @@
#ifndef cmCTestScriptHandler_h
#define cmCTestScriptHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGenericHandler.h"
+#include "cmDuration.h"
+#include <chrono>
#include <string>
#include <vector>
@@ -65,13 +67,13 @@ public:
/**
* Run a dashboard using a specified confiuration script
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
/*
* Run a script
*/
- static bool RunScript(cmCTest* ctest, const char* script, bool InProcess,
- int* returnValue);
+ static bool RunScript(cmCTest* ctest, cmMakefile* mf, const char* script,
+ bool InProcess, int* returnValue);
int RunCurrentScript();
/*
@@ -93,17 +95,20 @@ public:
/**
* 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
+ * not been set it returns a very large value.
*/
- double GetRemainingTimeAllowed();
+ cmDuration GetRemainingTimeAllowed();
cmCTestScriptHandler();
- ~cmCTestScriptHandler() CM_OVERRIDE;
+ ~cmCTestScriptHandler() override;
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
void CreateCMake();
cmake* GetCMake() { return this->CMake; }
+
+ void SetRunCurrentScript(bool value);
+
private:
// reads in a script
int ReadInScript(const std::string& total_script_arg);
@@ -134,6 +139,8 @@ private:
std::vector<std::string> ConfigurationScripts;
std::vector<bool> ScriptProcessScope;
+ bool ShouldRunCurrentScript;
+
bool Backup;
bool EmptyBinDir;
bool EmptyBinDirOnce;
@@ -156,9 +163,10 @@ private:
double ContinuousDuration;
// what time in seconds did this script start running
- double ScriptStartTime;
+ std::chrono::steady_clock::time_point ScriptStartTime;
cmMakefile* Makefile;
+ cmMakefile* ParentMakefile;
cmGlobalGenerator* GlobalGenerator;
cmake* CMake;
};
diff --git a/Source/CTest/cmCTestSleepCommand.h b/Source/CTest/cmCTestSleepCommand.h
index f0b5f1eeb..5cd185a81 100644
--- a/Source/CTest/cmCTestSleepCommand.h
+++ b/Source/CTest/cmCTestSleepCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestSleepCommand_h
#define cmCTestSleepCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
@@ -27,7 +27,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestSleepCommand* ni = new cmCTestSleepCommand;
ni->CTest = this->CTest;
@@ -40,7 +40,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/CTest/cmCTestStartCommand.cxx b/Source/CTest/cmCTestStartCommand.cxx
index 01a874b45..67ff2db05 100644
--- a/Source/CTest/cmCTestStartCommand.cxx
+++ b/Source/CTest/cmCTestStartCommand.cxx
@@ -28,41 +28,41 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
}
size_t cnt = 0;
- const char* smodel = args[cnt].c_str();
- const char* src_dir = CM_NULLPTR;
- const char* bld_dir = CM_NULLPTR;
+ const char* smodel = nullptr;
+ const char* src_dir = nullptr;
+ const char* bld_dir = nullptr;
- cnt++;
-
- this->CTest->SetSpecificTrack(CM_NULLPTR);
- if (cnt < args.size() - 1) {
+ while (cnt < args.size()) {
if (args[cnt] == "TRACK") {
cnt++;
+ if (cnt >= args.size() || args[cnt] == "APPEND" ||
+ args[cnt] == "QUIET") {
+ this->SetError("TRACK argument missing track name");
+ return false;
+ }
this->CTest->SetSpecificTrack(args[cnt].c_str());
cnt++;
- }
- }
-
- if (cnt < args.size()) {
- if (args[cnt] == "APPEND") {
+ } else if (args[cnt] == "APPEND") {
cnt++;
this->CreateNewTag = false;
- }
- }
- if (cnt < args.size()) {
- if (args[cnt] == "QUIET") {
+ } else if (args[cnt] == "QUIET") {
cnt++;
this->Quiet = true;
- }
- }
-
- if (cnt < args.size()) {
- src_dir = args[cnt].c_str();
- cnt++;
- if (cnt < args.size()) {
+ } else if (!smodel) {
+ smodel = args[cnt].c_str();
+ cnt++;
+ } else if (!src_dir) {
+ src_dir = args[cnt].c_str();
+ cnt++;
+ } else if (!bld_dir) {
bld_dir = args[cnt].c_str();
+ cnt++;
+ } else {
+ this->SetError("Too many arguments");
+ return false;
}
}
+
if (!src_dir) {
src_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
}
@@ -79,6 +79,11 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
"as an argument or set CTEST_BINARY_DIRECTORY");
return false;
}
+ if (!smodel && this->CreateNewTag) {
+ this->SetError("no test model specified and APPEND not specified. Specify "
+ "either a test model or the APPEND argument");
+ return false;
+ }
cmSystemTools::AddKeepPath(src_dir);
cmSystemTools::AddKeepPath(bld_dir);
@@ -92,11 +97,22 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
this->CTest->SetCTestConfiguration("BuildDirectory", binaryDir.c_str(),
this->Quiet);
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Run dashboard with model "
- << smodel << std::endl
- << " Source directory: " << src_dir << std::endl
- << " Build directory: " << bld_dir << std::endl,
- this->Quiet);
+ if (smodel) {
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ "Run dashboard with model "
+ << smodel << std::endl
+ << " Source directory: " << src_dir << std::endl
+ << " Build directory: " << bld_dir << std::endl,
+ this->Quiet);
+ } else {
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ "Run dashboard with "
+ "to-be-determined model"
+ << std::endl
+ << " Source directory: " << src_dir << std::endl
+ << " Build directory: " << bld_dir << std::endl,
+ this->Quiet);
+ }
const char* track = this->CTest->GetSpecificTrack();
if (track) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
@@ -105,7 +121,7 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
// Log startup actions.
std::string startLogFile = binaryDir + "/Testing/Temporary/LastStart.log";
- cmGeneratedFileStream ofs(startLogFile.c_str());
+ cmGeneratedFileStream ofs(startLogFile);
if (!ofs) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot create log file: LastStart.log" << std::endl);
@@ -126,9 +142,14 @@ bool cmCTestStartCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
- this->Makefile->AddDefinition("CTEST_RUN_CURRENT_SCRIPT", "OFF");
+ this->CTest->SetRunCurrentScript(false);
this->CTest->SetSuppressUpdatingCTestConfiguration(true);
- int model = this->CTest->GetTestModelFromString(smodel);
+ int model;
+ if (smodel) {
+ model = cmCTest::GetTestModelFromString(smodel);
+ } else {
+ model = cmCTest::UNKNOWN;
+ }
this->CTest->SetTestModel(model);
this->CTest->SetProduceXML(true);
diff --git a/Source/CTest/cmCTestStartCommand.h b/Source/CTest/cmCTestStartCommand.h
index b4943f92d..542f27c13 100644
--- a/Source/CTest/cmCTestStartCommand.h
+++ b/Source/CTest/cmCTestStartCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestStartCommand_h
#define cmCTestStartCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestCommand.h"
@@ -27,7 +27,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestStartCommand* ni = new cmCTestStartCommand;
ni->CTest = this->CTest;
@@ -42,7 +42,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* Will this invocation of ctest_start create a new TAG file?
diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx
index 409eb51fc..afc3e67d9 100644
--- a/Source/CTest/cmCTestSubmitCommand.cxx
+++ b/Source/CTest/cmCTestSubmitCommand.cxx
@@ -3,99 +3,84 @@
#include "cmCTestSubmitCommand.h"
#include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
#include "cmCTestSubmitHandler.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
-#include "cmake.h"
#include <sstream>
class cmExecutionStatus;
+cmCTestSubmitCommand::cmCTestSubmitCommand()
+{
+ this->PartsMentioned = false;
+ this->FilesMentioned = false;
+ this->InternalTest = false;
+ this->RetryCount = "";
+ this->RetryDelay = "";
+ this->CDashUpload = false;
+ this->Arguments[cts_BUILD_ID] = "BUILD_ID";
+ this->Last = cts_LAST;
+}
+
+/**
+ * This is a virtual constructor for the command.
+ */
+cmCommand* cmCTestSubmitCommand::Clone()
+{
+ cmCTestSubmitCommand* ni = new cmCTestSubmitCommand;
+ ni->CTest = this->CTest;
+ ni->CTestScriptHandler = this->CTestScriptHandler;
+ return ni;
+}
+
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");
- const char* ctestProjectName =
- this->Makefile->GetDefinition("CTEST_PROJECT_NAME");
- if (!ctestDropMethod) {
- ctestDropMethod = "http";
- }
+ const char* submitURL = !this->SubmitURL.empty()
+ ? this->SubmitURL.c_str()
+ : this->Makefile->GetDefinition("CTEST_SUBMIT_URL");
- 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("ProjectName", ctestProjectName,
- this->Quiet);
- this->CTest->SetCTestConfiguration("DropMethod", ctestDropMethod,
- this->Quiet);
- this->CTest->SetCTestConfiguration("DropSite", ctestDropSite, this->Quiet);
- this->CTest->SetCTestConfiguration("DropLocation", ctestDropLocation,
- this->Quiet);
-
- this->CTest->SetCTestConfiguration(
- "IsCDash", ctestDropSiteCDash ? "TRUE" : "FALSE", this->Quiet);
-
- // Only propagate TriggerSite for non-CDash projects:
- //
- if (!ctestDropSiteCDash) {
- this->CTest->SetCTestConfiguration("TriggerSite", ctestTriggerSite,
- this->Quiet);
+ if (submitURL) {
+ this->CTest->SetCTestConfiguration("SubmitURL", submitURL, this->Quiet);
+ } else {
+ this->CTest->SetCTestConfigurationFromCMakeVariable(
+ this->Makefile, "DropMethod", "CTEST_DROP_METHOD", this->Quiet);
+ this->CTest->SetCTestConfigurationFromCMakeVariable(
+ this->Makefile, "DropSiteUser", "CTEST_DROP_SITE_USER", this->Quiet);
+ this->CTest->SetCTestConfigurationFromCMakeVariable(
+ this->Makefile, "DropSitePassword", "CTEST_DROP_SITE_PASSWORD",
+ this->Quiet);
+ this->CTest->SetCTestConfigurationFromCMakeVariable(
+ this->Makefile, "DropSite", "CTEST_DROP_SITE", this->Quiet);
+ this->CTest->SetCTestConfigurationFromCMakeVariable(
+ this->Makefile, "DropLocation", "CTEST_DROP_LOCATION", this->Quiet);
}
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "CurlOptions", "CTEST_CURL_OPTIONS", this->Quiet);
- this->CTest->SetCTestConfigurationFromCMakeVariable(
- this->Makefile, "DropSiteUser", "CTEST_DROP_SITE_USER", this->Quiet);
- this->CTest->SetCTestConfigurationFromCMakeVariable(
- this->Makefile, "DropSitePassword", "CTEST_DROP_SITE_PASSWORD",
- this->Quiet);
- this->CTest->SetCTestConfigurationFromCMakeVariable(
- this->Makefile, "ScpCommand", "CTEST_SCP_COMMAND", this->Quiet);
const char* notesFilesVariable =
this->Makefile->GetDefinition("CTEST_NOTES_FILES");
if (notesFilesVariable) {
std::vector<std::string> notesFiles;
- cmCTest::VectorOfStrings newNotesFiles;
cmSystemTools::ExpandListArgument(notesFilesVariable, notesFiles);
- newNotesFiles.insert(newNotesFiles.end(), notesFiles.begin(),
- notesFiles.end());
- this->CTest->GenerateNotesFile(newNotesFiles);
+ this->CTest->GenerateNotesFile(notesFiles);
}
const char* extraFilesVariable =
this->Makefile->GetDefinition("CTEST_EXTRA_SUBMIT_FILES");
if (extraFilesVariable) {
std::vector<std::string> extraFiles;
- cmCTest::VectorOfStrings newExtraFiles;
cmSystemTools::ExpandListArgument(extraFilesVariable, extraFiles);
- newExtraFiles.insert(newExtraFiles.end(), extraFiles.begin(),
- extraFiles.end());
- if (!this->CTest->SubmitExtraFiles(newExtraFiles)) {
+ if (!this->CTest->SubmitExtraFiles(extraFiles)) {
this->SetError("problem submitting extra files.");
- return CM_NULLPTR;
+ return nullptr;
}
}
- cmCTestGenericHandler* handler =
- this->CTest->GetInitializedHandler("submit");
- if (!handler) {
- this->SetError("internal CTest error. Cannot instantiate submit handler");
- return CM_NULLPTR;
- }
+ cmCTestSubmitHandler* handler = this->CTest->GetSubmitHandler();
+ handler->Initialize();
// If no FILES or PARTS given, *all* PARTS are submitted by default.
//
@@ -117,38 +102,30 @@ cmCTestGenericHandler* cmCTestSubmitCommand::InitializeHandler()
// 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);
+ handler->SelectParts(std::set<cmCTest::Part>());
+ 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);
+ handler->SelectParts(this->Parts);
}
// Pass along any HTTPHEADER to the handler if this option was given.
if (!this->HttpHeaders.empty()) {
- static_cast<cmCTestSubmitHandler*>(handler)->SetHttpHeaders(
- this->HttpHeaders);
+ handler->SetHttpHeaders(this->HttpHeaders);
}
- 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");
+ handler->SetOption("RetryDelay", this->RetryDelay.c_str());
+ handler->SetOption("RetryCount", this->RetryCount.c_str());
+ handler->SetOption("InternalTest", this->InternalTest ? "ON" : "OFF");
handler->SetQuiet(this->Quiet);
if (this->CDashUpload) {
- static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
- "CDashUploadFile", this->CDashUploadFile.c_str());
- static_cast<cmCTestSubmitHandler*>(handler)->SetOption(
- "CDashUploadType", this->CDashUploadType.c_str());
+ handler->SetOption("CDashUploadFile", this->CDashUploadFile.c_str());
+ handler->SetOption("CDashUploadType", this->CDashUploadType.c_str());
}
return handler;
}
@@ -157,7 +134,15 @@ bool cmCTestSubmitCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
this->CDashUpload = !args.empty() && args[0] == "CDASH_UPLOAD";
- return this->cmCTestHandlerCommand::InitialPass(args, status);
+
+ bool ret = this->cmCTestHandlerCommand::InitialPass(args, status);
+
+ if (this->Values[cts_BUILD_ID] && *this->Values[cts_BUILD_ID]) {
+ this->Makefile->AddDefinition(this->Values[cts_BUILD_ID],
+ this->CTest->GetBuildID().c_str());
+ }
+
+ return ret;
}
bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
@@ -203,6 +188,11 @@ bool cmCTestSubmitCommand::CheckArgumentKeyword(std::string const& arg)
return true;
}
+ if (arg == "SUBMIT_URL") {
+ this->ArgumentDoing = ArgumentDoingSubmitURL;
+ return true;
+ }
+
if (arg == "INTERNAL_TEST_CHECKSUM") {
this->InternalTest = true;
return true;
@@ -222,20 +212,20 @@ bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
} else {
std::ostringstream e;
e << "Part name \"" << arg << "\" is invalid.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
this->ArgumentDoing = ArgumentDoingError;
}
return true;
}
if (this->ArgumentDoing == ArgumentDoingFiles) {
- if (cmSystemTools::FileExists(arg.c_str())) {
+ if (cmSystemTools::FileExists(arg)) {
this->Files.insert(arg);
} else {
std::ostringstream e;
e << "File \"" << arg << "\" does not exist. Cannot submit "
<< "a non-existent file.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
this->ArgumentDoing = ArgumentDoingError;
}
return true;
@@ -268,6 +258,12 @@ bool cmCTestSubmitCommand::CheckArgumentValue(std::string const& arg)
return true;
}
+ if (this->ArgumentDoing == ArgumentDoingSubmitURL) {
+ this->ArgumentDoing = ArgumentDoingNone;
+ this->SubmitURL = arg;
+ return true;
+ }
+
// Look for other arguments.
return this->Superclass::CheckArgumentValue(arg);
}
diff --git a/Source/CTest/cmCTestSubmitCommand.h b/Source/CTest/cmCTestSubmitCommand.h
index cf65cdc8d..1e270466d 100644
--- a/Source/CTest/cmCTestSubmitCommand.h
+++ b/Source/CTest/cmCTestSubmitCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestSubmitCommand_h
#define cmCTestSubmitCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTest.h"
#include "cmCTestHandlerCommand.h"
@@ -25,42 +25,24 @@ class cmExecutionStatus;
class cmCTestSubmitCommand : public cmCTestHandlerCommand
{
public:
- cmCTestSubmitCommand()
- {
- this->PartsMentioned = false;
- this->FilesMentioned = false;
- this->InternalTest = false;
- this->RetryCount = "";
- this->RetryDelay = "";
- this->CDashUpload = false;
- }
-
- /**
- * This is a virtual constructor for the command.
- */
- cmCommand* Clone() CM_OVERRIDE
- {
- cmCTestSubmitCommand* ni = new cmCTestSubmitCommand;
- ni->CTest = this->CTest;
- ni->CTestScriptHandler = this->CTestScriptHandler;
- return ni;
- }
+ cmCTestSubmitCommand();
+ cmCommand* Clone() override;
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* The name of the command as specified in CMakeList.txt.
*/
- std::string GetName() const CM_OVERRIDE { return "ctest_submit"; }
+ std::string GetName() const override { return "ctest_submit"; }
typedef cmCTestHandlerCommand Superclass;
protected:
- cmCTestGenericHandler* InitializeHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeHandler() override;
- bool CheckArgumentKeyword(std::string const& arg) CM_OVERRIDE;
- bool CheckArgumentValue(std::string const& arg) CM_OVERRIDE;
+ bool CheckArgumentKeyword(std::string const& arg) override;
+ bool CheckArgumentValue(std::string const& arg) override;
enum
{
@@ -71,20 +53,28 @@ protected:
ArgumentDoingCDashUpload,
ArgumentDoingCDashUploadType,
ArgumentDoingHttpHeader,
+ ArgumentDoingSubmitURL,
ArgumentDoingLast2
};
+ enum
+ {
+ cts_BUILD_ID = ct_LAST,
+ cts_LAST
+ };
+
bool PartsMentioned;
std::set<cmCTest::Part> Parts;
bool FilesMentioned;
bool InternalTest;
- cmCTest::SetOfStrings Files;
+ std::set<std::string> Files;
std::string RetryCount;
std::string RetryDelay;
bool CDashUpload;
std::string CDashUploadFile;
std::string CDashUploadType;
std::vector<std::string> HttpHeaders;
+ std::string SubmitURL;
};
#endif
diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx
index 8d62fa156..54c4bae08 100644
--- a/Source/CTest/cmCTestSubmitHandler.cxx
+++ b/Source/CTest/cmCTestSubmitHandler.cxx
@@ -5,30 +5,24 @@
#include "cm_curl.h"
#include "cm_jsoncpp_reader.h"
#include "cm_jsoncpp_value.h"
-#include "cmsys/Process.h"
+#include <chrono>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestCurl.h"
#include "cmCTestScriptHandler.h"
+#include "cmCryptoHash.h"
#include "cmCurl.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
-#include "cmProcessOutput.h"
#include "cmState.h"
#include "cmSystemTools.h"
-#include "cmThirdParty.h"
-#include "cmWorkingDirectory.h"
#include "cmXMLParser.h"
#include "cmake.h"
-#if defined(CTEST_USE_XMLRPC)
-#include "cmVersion.h"
-#include "cm_sys_stat.h"
-#include "cm_xmlrpc.h"
-#endif
-
#define SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT 120
typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
@@ -36,10 +30,6 @@ typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
class cmCTestSubmitHandler::ResponseParser : public cmXMLParser
{
public:
- ResponseParser() { this->Status = STATUS_OK; }
- ~ResponseParser() CM_OVERRIDE {}
-
-public:
enum StatusType
{
STATUS_OK,
@@ -47,10 +37,11 @@ public:
STATUS_ERROR
};
- StatusType Status;
+ StatusType Status = STATUS_OK;
std::string Filename;
std::string MD5;
std::string Message;
+ std::string BuildID;
private:
std::vector<char> CurrentValue;
@@ -65,17 +56,17 @@ private:
}
void StartElement(const std::string& /*name*/,
- const char** /*atts*/) CM_OVERRIDE
+ const char** /*atts*/) override
{
this->CurrentValue.clear();
}
- void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
+ void CharacterDataHandler(const char* data, int length) override
{
- this->CurrentValue.insert(this->CurrentValue.end(), data, data + length);
+ cmAppend(this->CurrentValue, data, data + length);
}
- void EndElement(const std::string& name) CM_OVERRIDE
+ void EndElement(const std::string& name) override
{
if (name == "status") {
std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
@@ -92,6 +83,8 @@ private:
this->MD5 = this->GetCurrentValue();
} else if (name == "message") {
this->Message = this->GetCurrentValue();
+ } else if (name == "buildId") {
+ this->BuildID = this->GetCurrentValue();
}
}
};
@@ -99,13 +92,10 @@ private:
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);
+ int realsize = static_cast<int>(size * nmemb);
const char* chPtr = static_cast<char*>(ptr);
- vec->insert(vec->end(), chPtr, chPtr + realsize);
-
+ cmAppend(*static_cast<cmCTestSubmitHandlerVectorOfChar*>(data), chPtr,
+ chPtr + realsize);
return realsize;
}
@@ -114,16 +104,12 @@ static size_t cmCTestSubmitHandlerCurlDebugCallback(CURL* /*unused*/,
char* chPtr, size_t size,
void* data)
{
- cmCTestSubmitHandlerVectorOfChar* vec =
- static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
- vec->insert(vec->end(), chPtr, chPtr + size);
-
+ cmAppend(*static_cast<cmCTestSubmitHandlerVectorOfChar*>(data), chPtr,
+ chPtr + size);
return size;
}
cmCTestSubmitHandler::cmCTestSubmitHandler()
- : HTTPProxy()
- , FTPProxy()
{
this->Initialize();
}
@@ -135,167 +121,19 @@ void cmCTestSubmitHandler::Initialize()
p = cmCTest::Part(p + 1)) {
this->SubmitPart[p] = true;
}
- this->CDash = false;
this->HasWarnings = false;
this->HasErrors = false;
this->Superclass::Initialize();
- this->HTTPProxy = "";
+ this->HTTPProxy.clear();
this->HTTPProxyType = 0;
- this->HTTPProxyAuth = "";
- this->FTPProxy = "";
- this->FTPProxyType = 0;
- this->LogFile = CM_NULLPTR;
+ this->HTTPProxyAuth.clear();
+ this->LogFile = nullptr;
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);
-
- ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
- *this->LogFile << "\tUpload file: " << local_file << " to " << upload_as
- << std::endl;
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- " Upload file: " << local_file << " to "
- << upload_as << std::endl,
- this->Quiet);
-
- ::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.empty()) {
- cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
- << cmCTestLogWrite(&*chunk.begin(), chunk.size())
- << "]" << std::endl,
- this->Quiet);
- }
- if (!chunkDebug.empty()) {
- cmCTestOptionalLog(
- this->CTest, DEBUG, "CURL debug output: ["
- << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
- << std::endl,
- this->Quiet);
- }
-
- 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.empty()) {
- *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);
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Uploaded: " + local_file << std::endl,
- this->Quiet);
- }
- }
- ::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)
+bool cmCTestSubmitHandler::SubmitUsingHTTP(
+ const std::string& localprefix, const std::vector<std::string>& files,
+ const std::string& remoteprefix, const std::string& url)
{
CURL* curl;
CURLcode res;
@@ -303,37 +141,32 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
char error_buffer[1024];
// Set Content-Type to satisfy fussy modsecurity rules.
struct curl_slist* headers =
- ::curl_slist_append(CM_NULLPTR, "Content-Type: text/xml");
+ ::curl_slist_append(nullptr, "Content-Type: text/xml");
// Add any additional headers that the user specified.
- for (std::vector<std::string>::const_iterator h = this->HttpHeaders.begin();
- h != this->HttpHeaders.end(); ++h) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Add HTTP Header: \"" << *h << "\"" << std::endl,
+ for (std::string const& h : this->HttpHeaders) {
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ " Add HTTP Header: \"" << h << "\"" << std::endl,
this->Quiet);
- headers = ::curl_slist_append(headers, h->c_str());
+ headers = ::curl_slist_append(headers, h.c_str());
}
/* 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") {
+ for (std::string const& arg : args) {
+ if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
verifyPeerOff = true;
}
- if (*i == "CURLOPT_SSL_VERIFYHOST_OFF") {
+ if (arg == "CURLOPT_SSL_VERIFYHOST_OFF") {
verifyHostOff = true;
}
}
- std::string::size_type kk;
- cmCTest::SetOfStrings::const_iterator file;
- for (file = files.begin(); file != files.end(); ++file) {
+ for (std::string const& file : files) {
/* get a curl handle */
curl = curl_easy_init();
if (curl) {
@@ -388,53 +221,72 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
- std::string local_file = *file;
- if (!cmSystemTools::FileExists(local_file.c_str())) {
- local_file = localprefix + "/" + *file;
+ std::string local_file = file;
+ bool initialize_cdash_buildid = false;
+ if (!cmSystemTools::FileExists(local_file)) {
+ local_file = localprefix + "/" + file;
+ // If this file exists within the local Testing directory we assume
+ // that it will be associated with the current build in CDash.
+ initialize_cdash_buildid = true;
}
std::string remote_file =
- remoteprefix + cmSystemTools::GetFilenameName(*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 ofile = cmSystemTools::EncodeURL(remote_file);
+ std::string upload_as = url +
+ ((url.find('?') == std::string::npos) ? '?' : '&') +
+ "FileName=" + ofile;
+
+ if (initialize_cdash_buildid) {
+ // Provide extra arguments to CDash so that it can initialize and
+ // return a buildid.
+ cmCTestCurl ctest_curl(this->CTest);
+ upload_as += "&build=";
+ upload_as +=
+ ctest_curl.Escape(this->CTest->GetCTestConfiguration("BuildName"));
+ upload_as += "&site=";
+ upload_as +=
+ ctest_curl.Escape(this->CTest->GetCTestConfiguration("Site"));
+ upload_as += "&stamp=";
+ upload_as += ctest_curl.Escape(this->CTest->GetCurrentTag());
+ upload_as += "-";
+ upload_as += ctest_curl.Escape(this->CTest->GetTestModelString());
+ cmCTestScriptHandler* ch = this->CTest->GetScriptHandler();
+ cmake* cm = ch->GetCMake();
+ if (cm) {
+ const char* subproject =
+ cm->GetState()->GetGlobalProperty("SubProject");
+ if (subproject) {
+ upload_as += "&subproject=";
+ upload_as += ctest_curl.Escape(subproject);
+ }
}
}
- std::string upload_as = url +
- ((url.find('?') == std::string::npos) ? '?' : '&') + "FileName=" +
- ofile;
+
+ // Generate Done.xml right before it is submitted.
+ // The reason for this is two-fold:
+ // 1) It must be generated after some other part has been submitted
+ // so we have a buildId to refer to in its contents.
+ // 2) By generating Done.xml here its timestamp will be as late as
+ // possible. This gives us a more accurate record of how long the
+ // entire build took to complete.
+ if (file == "Done.xml") {
+ this->CTest->GenerateDoneFile();
+ }
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;
+ upload_as +=
+ cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5);
}
- if (!cmSystemTools::FileExists(local_file.c_str())) {
+ if (!cmSystemTools::FileExists(local_file)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
" Cannot find file: " << local_file << std::endl);
::curl_easy_cleanup(curl);
@@ -454,6 +306,10 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
// specify target
::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
+ // CURLAUTH_BASIC is default, and here we allow additional methods,
+ // including more secure ones
+ ::curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
+
// now specify which file to upload
::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
@@ -472,23 +328,25 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
/* 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);
+ ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
+ ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
// Now run off and do what you've been told!
res = ::curl_easy_perform(curl);
if (!chunk.empty()) {
- cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
- << cmCTestLogWrite(&*chunk.begin(), chunk.size())
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ "CURL output: ["
+ << cmCTestLogWrite(chunk.data(), chunk.size())
<< "]" << std::endl,
this->Quiet);
this->ParseResponse(chunk);
}
if (!chunkDebug.empty()) {
cmCTestOptionalLog(
- this->CTest, DEBUG, "CURL debug output: ["
- << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
+ this->CTest, DEBUG,
+ "CURL debug output: ["
+ << cmCTestLogWrite(chunkDebug.data(), chunkDebug.size()) << "]"
<< std::endl,
this->Quiet);
}
@@ -496,30 +354,31 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
// If curl failed for any reason, or checksum fails, wait and retry
//
if (res != CURLE_OK || this->HasErrors) {
- std::string retryDelay = this->GetOption("RetryDelay") == CM_NULLPTR
+ std::string retryDelay = this->GetOption("RetryDelay") == nullptr
? ""
: this->GetOption("RetryDelay");
- std::string retryCount = this->GetOption("RetryCount") == CM_NULLPTR
+ std::string retryCount = this->GetOption("RetryCount") == nullptr
? ""
: this->GetOption("RetryCount");
- int delay = retryDelay == ""
- ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
- .c_str())
- : atoi(retryDelay.c_str());
- int count = retryCount == ""
+ auto delay = cmDuration(
+ retryDelay.empty()
+ ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
+ .c_str())
+ : atoi(retryDelay.c_str()));
+ int count = retryCount.empty()
? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
.c_str())
: atoi(retryCount.c_str());
for (int i = 0; i < count; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Submit failed, waiting " << delay
+ " Submit failed, waiting " << delay.count()
<< " seconds...\n",
this->Quiet);
- double stop = cmSystemTools::GetTime() + delay;
- while (cmSystemTools::GetTime() < stop) {
+ auto stop = std::chrono::steady_clock::now() + delay;
+ while (std::chrono::steady_clock::now() < stop) {
cmSystemTools::Delay(100);
}
@@ -539,11 +398,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
res = ::curl_easy_perform(curl);
if (!chunk.empty()) {
- cmCTestOptionalLog(
- this->CTest, DEBUG, "CURL output: ["
- << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
- << std::endl,
- this->Quiet);
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ "CURL output: ["
+ << cmCTestLogWrite(chunk.data(), chunk.size())
+ << "]" << std::endl,
+ this->Quiet);
this->ParseResponse(chunk);
}
@@ -555,8 +414,9 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
fclose(ftpfile);
if (res) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, " Error when uploading file: "
- << local_file << std::endl);
+ 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
@@ -566,10 +426,11 @@ bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
// avoid deref of begin for zero size array
if (!chunk.empty()) {
*this->LogFile << " Curl output was: "
- << cmCTestLogWrite(&*chunk.begin(), chunk.size())
+ << cmCTestLogWrite(chunk.data(), chunk.size())
<< std::endl;
- cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
- << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "CURL output: ["
+ << cmCTestLogWrite(chunk.data(), chunk.size()) << "]"
<< std::endl);
}
::curl_easy_cleanup(curl);
@@ -605,6 +466,7 @@ void cmCTestSubmitHandler::ParseResponse(
" Submission failed: " << parser.Message << std::endl);
return;
}
+ this->CTest->SetBuildID(parser.BuildID);
}
output = cmSystemTools::UpperCase(output);
if (output.find("WARNING") != std::string::npos) {
@@ -615,395 +477,12 @@ void cmCTestSubmitHandler::ParseResponse(
}
if (this->HasWarnings || this->HasErrors) {
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " Server Response:\n"
- << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Server Response:\n"
+ << cmCTestLogWrite(chunk.data(), 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.empty()) {
- 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('?') == std::string::npos) ? '?' : '&') + "xmlfile=" +
- ofile;
- *this->LogFile << "Trigger url: " << turl << std::endl;
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- " Trigger url: " << turl << std::endl, this->Quiet);
- 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.empty()) {
- *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.empty()) {
- cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
- << cmCTestLogWrite(&*chunk.begin(), chunk.size())
- << "]" << std::endl,
- this->Quiet);
- }
- if (!chunkDebug.empty()) {
- cmCTestOptionalLog(
- this->CTest, DEBUG, "CURL debug output: ["
- << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
- << std::endl,
- this->Quiet);
- }
-
- // always cleanup
- ::curl_easy_cleanup(curl);
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
- this->Quiet);
- }
- }
- ::curl_global_cleanup();
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Dart server triggered..." << std::endl, this->Quiet);
- 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.empty() || localprefix.empty() || files.empty() ||
- remoteprefix.empty() || url.empty()) {
- return false;
- }
-
- 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(CM_NULLPTR);
-
- 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();
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Execute \""
- << argv[0] << "\" \"" << argv[1] << "\" \"" << argv[2]
- << "\"" << std::endl,
- this->Quiet);
- *this->LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
- << argv[2] << "\"" << std::endl;
-
- cmsysProcess_SetCommand(cp, &*argv.begin());
- cmsysProcess_Execute(cp);
- char* data;
- int length;
- cmProcessOutput processOutput;
- std::string strdata;
-
- while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) {
- processOutput.DecodeText(data, length, strdata);
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- cmCTestLogWrite(strdata.c_str(), strdata.size()),
- this->Quiet);
- }
- processOutput.DecodeText(std::string(), strdata);
- if (!strdata.empty()) {
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- cmCTestLogWrite(strdata.c_str(), strdata.size()),
- this->Quiet);
- }
-
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
-
- int result = cmsysProcess_GetState(cp);
-
- if (result == cmsysProcess_State_Exited) {
- retVal = cmsysProcess_GetExitValue(cp);
- if (retVal != 0) {
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- "\tSCP returned: " << retVal << std::endl,
- this->Quiet);
- *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);
- return problems == 0;
-}
-
-bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix,
- const std::set<std::string>& files,
- const std::string& remoteprefix,
- const std::string& destination)
-{
- if (localprefix.empty() || files.empty() || remoteprefix.empty() ||
- destination.empty()) {
- /* clang-format off */
- 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);
- /* clang-format on */
- return false;
- }
-
- cmCTest::SetOfStrings::const_iterator file;
- 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, rfname);
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Copy file: "
- << lfname << " to " << rfname << std::endl,
- this->Quiet);
- }
- std::string tagDoneFile = destination + "/" + remoteprefix + "DONE";
- cmSystemTools::Touch(tagDoneFile, true);
- 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. */
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Submitting to: "
- << realURL << " (" << remoteprefix << ")" << std::endl,
- this->Quiet);
- 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;
- }
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Submit file: " << local_file << std::endl,
- this->Quiet);
- struct stat st;
- if (::stat(local_file.c_str(), &st)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE,
- " Cannot find file: " << local_file << 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
- << std::endl);
- return false;
- }
- size_t fileSize = static_cast<size_t>(st.st_size);
- FILE* fp = cmsys::SystemTools::Fopen(local_file, "rb");
- if (!fp) {
- cmCTestLog(this->CTest, ERROR_MESSAGE,
- " Cannot open file: " << local_file << 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 << 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& /*unused*/, std::set<std::string> const& /*unused*/,
- std::string const& /*unused*/, std::string const& /*unused*/)
-{
- return false;
-}
-#endif
-
-void cmCTestSubmitHandler::ConstructCDashURL(std::string& dropMethod,
- std::string& url)
-{
- dropMethod = this->CTest->GetCTestConfiguration("DropMethod");
- url = dropMethod;
- url += "://";
- if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
- url += this->CTest->GetCTestConfiguration("DropSiteUser");
- cmCTestOptionalLog(
- this->CTest, HANDLER_OUTPUT,
- this->CTest->GetCTestConfiguration("DropSiteUser").c_str(), this->Quiet);
- if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
- url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******", this->Quiet);
- }
- url += "@";
- }
- url += this->CTest->GetCTestConfiguration("DropSite") +
- this->CTest->GetCTestConfiguration("DropLocation");
-}
-
int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
std::string const& typeString)
{
@@ -1012,8 +491,8 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
return -1;
}
if (!cmSystemTools::FileExists(file)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not found: '"
- << file << "'\n");
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Upload file not found: '" << file << "'\n");
return -1;
}
cmCTestCurl curl(this->CTest);
@@ -1024,12 +503,15 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
curl.SetCurlOptions(args);
curl.SetTimeOutSeconds(SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
curl.SetHttpHeaders(this->HttpHeaders);
- std::string dropMethod;
- std::string url;
- this->ConstructCDashURL(dropMethod, url);
- std::string::size_type pos = url.find("submit.php?");
- url = url.substr(0, pos + 10);
- if (!(dropMethod == "http" || dropMethod == "https")) {
+ std::string url = this->CTest->GetSubmitURL();
+ std::string fields;
+ std::string::size_type pos = url.find('?');
+ if (pos != std::string::npos) {
+ fields = url.substr(pos + 1);
+ url = url.substr(0, pos);
+ }
+ if (!cmHasLiteralPrefix(url, "http://") &&
+ !cmHasLiteralPrefix(url, "https://")) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Only http and https are supported for CDASH_UPLOAD\n");
return -1;
@@ -1037,45 +519,49 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
bool internalTest = cmSystemTools::IsOn(this->GetOption("InternalTest"));
// Get RETRY_COUNT and RETRY_DELAY values if they were set.
- std::string retryDelayString = this->GetOption("RetryDelay") == CM_NULLPTR
+ std::string retryDelayString = this->GetOption("RetryDelay") == nullptr
? ""
: this->GetOption("RetryDelay");
- std::string retryCountString = this->GetOption("RetryCount") == CM_NULLPTR
+ std::string retryCountString = this->GetOption("RetryCount") == nullptr
? ""
: this->GetOption("RetryCount");
- unsigned long retryDelay = 0;
- if (retryDelayString != "") {
- if (!cmSystemTools::StringToULong(retryDelayString.c_str(), &retryDelay)) {
- cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
- << retryDelayString << std::endl);
+ auto retryDelay = std::chrono::seconds(0);
+ if (!retryDelayString.empty()) {
+ unsigned long retryDelayValue = 0;
+ if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
+ &retryDelayValue)) {
+ cmCTestLog(this->CTest, WARNING,
+ "Invalid value for 'RETRY_DELAY' : " << retryDelayString
+ << std::endl);
+ } else {
+ retryDelay = std::chrono::seconds(retryDelayValue);
}
}
unsigned long retryCount = 0;
- if (retryCountString != "") {
+ if (!retryCountString.empty()) {
if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
- cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
- << retryCountString << std::endl);
+ cmCTestLog(this->CTest, WARNING,
+ "Invalid value for 'RETRY_DELAY' : " << retryCountString
+ << std::endl);
}
}
- char md5sum[33];
- md5sum[32] = 0;
- cmSystemTools::ComputeFileMD5(file, md5sum);
+ std::string md5sum =
+ cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
// 1. request the buildid and check to see if the file
// has already been uploaded
// TODO I added support for subproject. You would need to add
// a "&subproject=subprojectname" to the first POST.
- cmCTestScriptHandler* ch =
- static_cast<cmCTestScriptHandler*>(this->CTest->GetHandler("script"));
+ cmCTestScriptHandler* ch = this->CTest->GetScriptHandler();
cmake* cm = ch->GetCMake();
const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
// TODO: Encode values for a URL instead of trusting caller.
std::ostringstream str;
- str << "project="
- << curl.Escape(this->CTest->GetCTestConfiguration("ProjectName")) << "&";
if (subproject) {
str << "subproject=" << curl.Escape(subproject) << "&";
}
+ auto timeNow =
+ std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
<< curl.Escape(this->CTest->GetTestModelString()) << "&"
<< "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
@@ -1084,11 +570,14 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
<< "site=" << curl.Escape(this->CTest->GetCTestConfiguration("Site"))
<< "&"
<< "track=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
- << "starttime=" << (int)cmSystemTools::GetTime() << "&"
- << "endtime=" << (int)cmSystemTools::GetTime() << "&"
+ << "starttime=" << timeNow << "&"
+ << "endtime=" << timeNow << "&"
<< "datafilesmd5[0]=" << md5sum << "&"
<< "type=" << curl.Escape(typeString);
- std::string fields = str.str();
+ if (!fields.empty()) {
+ fields += '&';
+ }
+ fields += str.str();
cmCTestOptionalLog(this->CTest, DEBUG,
"fields: " << fields << "\nurl:" << url
<< "\nfile: " << file << "\n",
@@ -1100,12 +589,12 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
// If request failed, wait and retry.
for (unsigned long i = 0; i < retryCount; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Request failed, waiting " << retryDelay
+ " Request failed, waiting " << retryDelay.count()
<< " seconds...\n",
this->Quiet);
- double stop = cmSystemTools::GetTime() + static_cast<double>(retryDelay);
- while (cmSystemTools::GetTime() < stop) {
+ auto stop = std::chrono::steady_clock::now() + retryDelay;
+ while (std::chrono::steady_clock::now() < stop) {
cmSystemTools::Delay(100);
}
@@ -1121,7 +610,8 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
}
}
if (!internalTest && !requestSucceeded) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in HttpRequest\n"
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error in HttpRequest\n"
<< response);
return -1;
}
@@ -1131,7 +621,8 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
Json::Value json;
Json::Reader reader;
if (!internalTest && !reader.parse(response, json)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "error parsing json string ["
<< response << "]\n"
<< reader.getFormattedErrorMessages() << "\n");
return -1;
@@ -1174,12 +665,12 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
// If upload failed, wait and retry.
for (unsigned long i = 0; i < retryCount; i++) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Upload failed, waiting " << retryDelay
+ " Upload failed, waiting " << retryDelay.count()
<< " seconds...\n",
this->Quiet);
- double stop = cmSystemTools::GetTime() + static_cast<double>(retryDelay);
- while (cmSystemTools::GetTime() < stop) {
+ auto stop = std::chrono::steady_clock::now() + retryDelay;
+ while (std::chrono::steady_clock::now() < stop) {
cmSystemTools::Delay(100);
}
@@ -1198,12 +689,14 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
}
if (!uploadSucceeded) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "error uploading to CDash. "
- << file << " " << url << " " << fstr.str());
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "error uploading to CDash. " << file << " " << url << " "
+ << fstr.str());
return -1;
}
if (!reader.parse(response, json)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "error parsing json string ["
<< response << "]\n"
<< reader.getFormattedErrorMessages() << "\n");
return -1;
@@ -1221,11 +714,6 @@ int cmCTestSubmitHandler::ProcessHandler()
if (cdashUploadFile && cdashUploadType) {
return this->HandleCDashUploadFile(cdashUploadFile, cdashUploadType);
}
- std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
- // cdash does not need to trigger so just return true
- if (!iscdash.empty()) {
- this->CDash = true;
- }
const std::string& buildDirectory =
this->CTest->GetCTestConfiguration("BuildDirectory");
@@ -1263,46 +751,20 @@ int cmCTestSubmitHandler::ProcessHandler()
}
}
- 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.empty()) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
" Use HTTP Proxy: " << this->HTTPProxy << std::endl,
this->Quiet);
}
- if (!this->FTPProxy.empty()) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Use FTP Proxy: " << this->FTPProxy << std::endl,
- this->Quiet);
- }
cmGeneratedFileStream ofs;
this->StartLogFile("Submit", ofs);
- cmCTest::SetOfStrings files;
+ std::vector<std::string> files;
std::string prefix = this->GetSubmitResultsPrefix();
if (!this->Files.empty()) {
// Submit the explicitly selected files:
- //
- files.insert(this->Files.begin(), this->Files.end());
+ cmAppend(files, this->Files);
}
// Add to the list of files to submit from any selected, existing parts:
@@ -1324,13 +786,11 @@ int cmCTestSubmitHandler::ProcessHandler()
cmCTestOptionalLog(this->CTest, DEBUG,
"Globbing for: " << gpath << std::endl, this->Quiet);
if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) {
- size_t cc;
- for (cc = 0; cc < gfiles.size(); cc++) {
- gfiles[cc] = gfiles[cc].substr(glen);
+ for (std::string& gfile : gfiles) {
+ gfile = gfile.substr(glen);
cmCTestOptionalLog(this->CTest, DEBUG,
- "Glob file: " << gfiles[cc] << std::endl,
- this->Quiet);
- this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfiles[cc].c_str());
+ "Glob file: " << gfile << std::endl, this->Quiet);
+ this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile.c_str());
}
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
@@ -1350,22 +810,32 @@ int cmCTestSubmitHandler::ProcessHandler()
}
// Submit files from this part.
- std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
- files.insert(pfiles.begin(), pfiles.end());
+ cmAppend(files, this->CTest->GetSubmitFiles(p));
+ }
+
+ // Make sure files are unique, but preserve order.
+ {
+ // This endPos intermediate is needed to work around non-conformant C++11
+ // standard libraries that have erase(iterator,iterator) instead of
+ // erase(const_iterator,const_iterator).
+ size_t endPos = cmRemoveDuplicates(files) - files.cbegin();
+ files.erase(files.begin() + endPos, files.end());
+ }
+
+ // Submit Done.xml last
+ if (this->SubmitPart[cmCTest::PartDone]) {
+ files.emplace_back("Done.xml");
}
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;
+ for (std::string const& file : files) {
+ ofs << cnt << "\t" << file << std::endl;
cnt++;
}
}
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Submit files (using "
- << this->CTest->GetCTestConfiguration("DropMethod")
- << ")" << std::endl,
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Submit files\n",
this->Quiet);
const char* specificTrack = this->CTest->GetSpecificTrack();
if (specificTrack) {
@@ -1375,209 +845,32 @@ int cmCTestSubmitHandler::ProcessHandler()
}
this->SetLogFile(&ofs);
- std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
-
- if (dropMethod == "" || dropMethod == "ftp") {
- ofs << "Using drop method: FTP" << std::endl;
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Using FTP submit method" << std::endl
- << " Drop site: ftp://",
- this->Quiet);
- 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").empty()) {
- cmCTestOptionalLog(
- this->CTest, HANDLER_OUTPUT,
- this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
- this->Quiet);
- if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
- this->Quiet);
- }
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
- }
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- this->CTest->GetCTestConfiguration("DropSite")
- << this->CTest->GetCTestConfiguration("DropLocation")
- << std::endl,
- this->Quiet);
- 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) {
- cmCTestOptionalLog(
- this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
- << std::endl
- << " Trigger site: "
- << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
- this->Quiet);
- 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;
- }
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Submission successful" << std::endl, this->Quiet);
- 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;
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Using HTTP submit method" << std::endl
- << " Drop site:" << url,
- this->Quiet);
- if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
- url += this->CTest->GetCTestConfiguration("DropSiteUser");
- cmCTestOptionalLog(
- this->CTest, HANDLER_OUTPUT,
- this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
- this->Quiet);
- if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
- url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
- this->Quiet);
- }
- url += "@";
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
- }
- url += this->CTest->GetCTestConfiguration("DropSite") +
- this->CTest->GetCTestConfiguration("DropLocation");
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- this->CTest->GetCTestConfiguration("DropSite")
- << this->CTest->GetCTestConfiguration("DropLocation")
- << std::endl,
- this->Quiet);
- 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) {
- cmCTestOptionalLog(
- this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
- << std::endl
- << " Trigger site: "
- << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
- this->Quiet);
- 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 {
- cmCTestOptionalLog(
- this->CTest, HANDLER_OUTPUT, " Submission successful"
- << (this->HasWarnings ? ", with warnings." : "") << std::endl,
- this->Quiet);
- 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;
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Using XML-RPC submit method" << std::endl,
- this->Quiet);
- 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;
- }
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Submission successful" << std::endl, this->Quiet);
- ofs << " Submission successful" << std::endl;
- return 0;
-#else
+ std::string url = this->CTest->GetSubmitURL();
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ " SubmitURL: " << url << '\n', this->Quiet);
+ if (!this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
+ this->CTest->GetCurrentTag(),
+ files, prefix, url)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
- " Submission method \"xmlrpc\" not compiled into CTest!"
- << std::endl);
+ " Problems when submitting via HTTP\n");
+ ofs << " Problems when submitting via HTTP\n";
return -1;
-#endif
- } else if (dropMethod == "scp") {
- std::string url;
- if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
- 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
- cmWorkingDirectory workdir(buildDirectory);
-
- if (!this->SubmitUsingSCP(this->CTest->GetCTestConfiguration("ScpCommand"),
- "Testing/" + this->CTest->GetCurrentTag(), files,
- prefix, url)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE,
- " Problems when submitting via SCP" << std::endl);
- ofs << " Problems when submitting via SCP" << std::endl;
- return -1;
- }
+ }
+ if (this->HasErrors) {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Errors occurred during submission.\n");
+ ofs << " Errors occurred during submission.\n";
+ } else {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Submission successful" << std::endl, this->Quiet);
- 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
- cmWorkingDirectory workdir(buildDirectory);
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- " Change directory: " << buildDirectory << std::endl,
+ " Submission successful"
+ << (this->HasWarnings ? ", with warnings." : "")
+ << std::endl,
this->Quiet);
-
- if (!this->SubmitUsingCP("Testing/" + this->CTest->GetCurrentTag(), files,
- prefix, location)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE,
- " Problems when submitting via CP" << std::endl);
- ofs << " Problems when submitting via cp" << std::endl;
- return -1;
- }
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
- " Submission successful" << std::endl, this->Quiet);
- ofs << " Submission successful" << std::endl;
- return 0;
+ ofs << " Submission successful"
+ << (this->HasWarnings ? ", with warnings." : "") << std::endl;
}
- cmCTestLog(this->CTest, ERROR_MESSAGE, " Unknown submission method: \""
- << dropMethod << "\"" << std::endl);
- return -1;
+ return 0;
}
std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
@@ -1600,7 +893,7 @@ void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
}
}
-void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
+void cmCTestSubmitHandler::SelectFiles(std::set<std::string> const& files)
{
this->Files.insert(files.begin(), files.end());
}
diff --git a/Source/CTest/cmCTestSubmitHandler.h b/Source/CTest/cmCTestSubmitHandler.h
index 2923f4f3d..e0fed10e0 100644
--- a/Source/CTest/cmCTestSubmitHandler.h
+++ b/Source/CTest/cmCTestSubmitHandler.h
@@ -3,7 +3,7 @@
#ifndef cmCTestSubmitHandler_h
#define cmCTestSubmitHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTest.h"
#include "cmCTestGenericHandler.h"
@@ -25,20 +25,20 @@ public:
typedef cmCTestGenericHandler Superclass;
cmCTestSubmitHandler();
- ~cmCTestSubmitHandler() CM_OVERRIDE { this->LogFile = CM_NULLPTR; }
+ ~cmCTestSubmitHandler() override { this->LogFile = nullptr; }
/*
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
/** 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);
+ void SelectFiles(std::set<std::string> const& files);
// handle the cdash file upload protocol
int HandleCDashUploadFile(std::string const& file, std::string const& type);
@@ -48,38 +48,16 @@ public:
this->HttpHeaders = v;
}
- void ConstructCDashURL(std::string& dropMethod, std::string& url);
-
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::vector<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;
@@ -92,14 +70,11 @@ private:
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;
+ std::set<std::string> Files;
std::vector<std::string> HttpHeaders;
};
diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx
index 075b1403a..cfd5e3dd2 100644
--- a/Source/CTest/cmCTestTestCommand.cxx
+++ b/Source/CTest/cmCTestTestCommand.cxx
@@ -4,9 +4,12 @@
#include "cmCTest.h"
#include "cmCTestGenericHandler.h"
+#include "cmCTestTestHandler.h"
+#include "cmDuration.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
+#include <chrono>
#include <sstream>
#include <stdlib.h>
#include <vector>
@@ -27,7 +30,7 @@ cmCTestTestCommand::cmCTestTestCommand()
this->Arguments[ctt_SCHEDULE_RANDOM] = "SCHEDULE_RANDOM";
this->Arguments[ctt_STOP_TIME] = "STOP_TIME";
this->Arguments[ctt_TEST_LOAD] = "TEST_LOAD";
- this->Arguments[ctt_LAST] = CM_NULLPTR;
+ this->Arguments[ctt_LAST] = nullptr;
this->Last = ctt_LAST;
}
@@ -36,14 +39,14 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
const char* ctestTimeout =
this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
- double timeout;
+ cmDuration timeout;
if (ctestTimeout) {
- timeout = atof(ctestTimeout);
+ timeout = cmDuration(atof(ctestTimeout));
} else {
timeout = this->CTest->GetTimeOut();
- if (timeout <= 0) {
+ if (timeout <= cmDuration::zero()) {
// By default use timeout of 10 minutes
- timeout = 600;
+ timeout = std::chrono::minutes(10);
}
}
this->CTest->SetTimeOut(timeout);
@@ -110,25 +113,35 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
if (!cmSystemTools::StringToULong(this->Values[ctt_TEST_LOAD],
&testLoad)) {
testLoad = 0;
- cmCTestLog(this->CTest, WARNING, "Invalid value for 'TEST_LOAD' : "
+ cmCTestLog(this->CTest, WARNING,
+ "Invalid value for 'TEST_LOAD' : "
<< this->Values[ctt_TEST_LOAD] << std::endl);
}
} else if (ctestTestLoad && *ctestTestLoad) {
if (!cmSystemTools::StringToULong(ctestTestLoad, &testLoad)) {
testLoad = 0;
- cmCTestLog(this->CTest, WARNING, "Invalid value for 'CTEST_TEST_LOAD' : "
- << ctestTestLoad << std::endl);
+ cmCTestLog(this->CTest, WARNING,
+ "Invalid value for 'CTEST_TEST_LOAD' : " << ctestTestLoad
+ << std::endl);
}
} else {
testLoad = this->CTest->GetTestLoad();
}
handler->SetTestLoad(testLoad);
+ if (const char* labelsForSubprojects =
+ this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
+ this->CTest->SetCTestConfiguration("LabelsForSubprojects",
+ labelsForSubprojects, this->Quiet);
+ }
+
handler->SetQuiet(this->Quiet);
return handler;
}
cmCTestGenericHandler* cmCTestTestCommand::InitializeActualHandler()
{
- return this->CTest->GetInitializedHandler("test");
+ cmCTestTestHandler* handler = this->CTest->GetTestHandler();
+ handler->Initialize();
+ return handler;
}
diff --git a/Source/CTest/cmCTestTestCommand.h b/Source/CTest/cmCTestTestCommand.h
index be7e7831f..11c0db955 100644
--- a/Source/CTest/cmCTestTestCommand.h
+++ b/Source/CTest/cmCTestTestCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestTestCommand_h
#define cmCTestTestCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
@@ -25,7 +25,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestTestCommand* ni = new cmCTestTestCommand;
ni->CTest = this->CTest;
@@ -36,11 +36,11 @@ public:
/**
* The name of the command as specified in CMakeList.txt.
*/
- std::string GetName() const CM_OVERRIDE { return "ctest_test"; }
+ std::string GetName() const override { return "ctest_test"; }
protected:
virtual cmCTestGenericHandler* InitializeActualHandler();
- cmCTestGenericHandler* InitializeHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeHandler() override;
enum
{
diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx
index 674be6052..0ed56c850 100644
--- a/Source/CTest/cmCTestTestHandler.cxx
+++ b/Source/CTest/cmCTestTestHandler.cxx
@@ -1,27 +1,28 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestTestHandler.h"
-
-#include "cmsys/Base64.h"
-#include "cmsys/Directory.hxx"
-#include "cmsys/FStream.hxx"
-#include "cmsys/RegularExpression.hxx"
#include <algorithm>
+#include <chrono>
+#include <cmath>
+#include <cmsys/Base64.h>
+#include <cmsys/Directory.hxx>
+#include <cmsys/RegularExpression.hxx>
+#include <cstring>
#include <functional>
#include <iomanip>
#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <time.h>
#include "cmAlgorithms.h"
#include "cmCTest.h"
-#include "cmCTestBatchTestHandler.h"
#include "cmCTestMultiProcessHandler.h"
#include "cmCommand.h"
+#include "cmDuration.h"
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
@@ -30,9 +31,9 @@
#include "cmSystemTools.h"
#include "cmWorkingDirectory.h"
#include "cmXMLWriter.h"
-#include "cm_auto_ptr.hxx"
#include "cm_utf8.h"
#include "cmake.h"
+#include "cmsys/FStream.hxx"
class cmExecutionStatus;
@@ -42,7 +43,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
c->TestHandler = this->TestHandler;
@@ -54,7 +55,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& /*unused*/) CM_OVERRIDE;
+ cmExecutionStatus& /*unused*/) override;
cmCTestTestHandler* TestHandler;
};
@@ -66,17 +67,16 @@ bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args,
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) {
+ for (std::string const& arg : args) {
std::string fname;
- if (cmSystemTools::FileIsFullPath(it->c_str())) {
- fname = *it;
+ if (cmSystemTools::FileIsFullPath(arg)) {
+ fname = arg;
} else {
fname = cwd;
fname += "/";
- fname += *it;
+ fname += arg;
}
if (!cmSystemTools::FileIsDirectory(fname)) {
@@ -86,6 +86,11 @@ bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args,
bool readit = false;
{
cmWorkingDirectory workdir(fname);
+ if (workdir.Failed()) {
+ this->SetError("Failed to change directory to " + fname + " : " +
+ std::strerror(workdir.GetLastResult()));
+ return false;
+ }
const char* testFilename;
if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
// does the CTestTestfile.cmake exist ?
@@ -99,7 +104,7 @@ bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args,
}
fname += "/";
fname += testFilename;
- readit = this->Makefile->ReadDependentFile(fname.c_str());
+ readit = this->Makefile->ReadDependentFile(fname);
}
if (!readit) {
std::string m = "Could not find include file: ";
@@ -117,7 +122,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand;
c->TestHandler = this->TestHandler;
@@ -129,7 +134,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& /*unused*/) CM_OVERRIDE;
+ cmExecutionStatus& /*unused*/) override;
cmCTestTestHandler* TestHandler;
};
@@ -146,7 +151,7 @@ bool cmCTestAddSubdirectoryCommand::InitialPass(
fname += "/";
fname += args[0];
- if (!cmSystemTools::FileExists(fname.c_str())) {
+ if (!cmSystemTools::FileExists(fname)) {
// No subdirectory? So what...
return true;
}
@@ -165,7 +170,7 @@ bool cmCTestAddSubdirectoryCommand::InitialPass(
}
fname += "/";
fname += testFilename;
- readit = this->Makefile->ReadDependentFile(fname.c_str());
+ readit = this->Makefile->ReadDependentFile(fname);
}
if (!readit) {
std::string m = "Could not find include file: ";
@@ -182,7 +187,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
c->TestHandler = this->TestHandler;
@@ -194,7 +199,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& /*args*/,
- cmExecutionStatus& /*unused*/) CM_OVERRIDE;
+ cmExecutionStatus& /*unused*/) override;
cmCTestTestHandler* TestHandler;
};
@@ -215,7 +220,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestSetTestsPropertiesCommand* c = new cmCTestSetTestsPropertiesCommand;
c->TestHandler = this->TestHandler;
@@ -227,7 +232,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& /*args*/,
- cmExecutionStatus& /*unused*/) CM_OVERRIDE;
+ cmExecutionStatus& /*unused*/) override;
cmCTestTestHandler* TestHandler;
};
@@ -238,6 +243,36 @@ bool cmCTestSetTestsPropertiesCommand::InitialPass(
return this->TestHandler->SetTestsProperties(args);
}
+class cmCTestSetDirectoryPropertiesCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ cmCommand* Clone() override
+ {
+ cmCTestSetDirectoryPropertiesCommand* c =
+ new cmCTestSetDirectoryPropertiesCommand;
+ c->TestHandler = this->TestHandler;
+ return c;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ bool InitialPass(std::vector<std::string> const& /*unused*/,
+ cmExecutionStatus& /*unused*/) override;
+
+ cmCTestTestHandler* TestHandler;
+};
+
+bool cmCTestSetDirectoryPropertiesCommand::InitialPass(
+ std::vector<std::string> const& args, cmExecutionStatus&)
+{
+ return this->TestHandler->SetDirectoryProperties(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.
@@ -305,7 +340,7 @@ cmCTestTestHandler::cmCTestTestHandler()
this->MemCheck = false;
- this->LogFile = CM_NULLPTR;
+ this->LogFile = nullptr;
// regex to detect <DartMeasurement>...</DartMeasurement>
this->DartStuff.compile("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
@@ -318,13 +353,13 @@ void cmCTestTestHandler::Initialize()
{
this->Superclass::Initialize();
- this->ElapsedTestingTime = -1;
+ this->ElapsedTestingTime = cmDuration();
this->TestResults.clear();
this->CustomTestsIgnore.clear();
- this->StartTest = "";
- this->EndTest = "";
+ this->StartTest.clear();
+ this->EndTest.clear();
this->CustomPreTest.clear();
this->CustomPostTest.clear();
@@ -340,13 +375,13 @@ void cmCTestTestHandler::Initialize()
this->UseExcludeRegExpFirst = false;
this->IncludeLabelRegularExpression = "";
this->ExcludeLabelRegularExpression = "";
- this->IncludeRegExp = "";
- this->ExcludeRegExp = "";
+ this->IncludeRegExp.clear();
+ this->ExcludeRegExp.clear();
this->ExcludeFixtureRegExp.clear();
this->ExcludeFixtureSetupRegExp.clear();
this->ExcludeFixtureCleanupRegExp.clear();
- TestsToRunString = "";
+ TestsToRunString.clear();
this->UseUnion = false;
this->TestList.clear();
}
@@ -438,11 +473,12 @@ int cmCTestTestHandler::ProcessHandler()
this->TestResults.clear();
- cmCTestOptionalLog(
- this->CTest, HANDLER_OUTPUT, (this->MemCheck ? "Memory check" : "Test")
- << " project " << cmSystemTools::GetCurrentWorkingDirectory()
- << std::endl,
- this->Quiet);
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ (this->MemCheck ? "Memory check" : "Test")
+ << " project "
+ << cmSystemTools::GetCurrentWorkingDirectory()
+ << std::endl,
+ this->Quiet);
if (!this->PreProcessHandler()) {
return -1;
}
@@ -456,30 +492,29 @@ int cmCTestTestHandler::ProcessHandler()
int total;
// start the real time clock
- double clock_start, clock_finish;
- clock_start = cmSystemTools::GetTime();
+ auto clock_start = std::chrono::steady_clock::now();
this->ProcessDirectory(passed, failed);
- clock_finish = cmSystemTools::GetTime();
+ auto clock_finish = std::chrono::steady_clock::now();
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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "No tests were found!!!" << std::endl);
}
} else {
if (this->HandlerVerbose && !passed.empty() &&
(this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag)) {
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ std::endl
<< "The following tests passed:" << std::endl,
this->Quiet);
- for (std::vector<std::string>::iterator j = passed.begin();
- j != passed.end(); ++j) {
+ for (std::string const& j : passed) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- "\t" << *j << std::endl, this->Quiet);
+ "\t" << j << std::endl, this->Quiet);
}
}
@@ -489,11 +524,10 @@ int cmCTestTestHandler::ProcessHandler()
SetOfTests resultsSet(this->TestResults.begin(), this->TestResults.end());
std::vector<cmCTestTestHandler::cmCTestTestResult> disabledTests;
- for (SetOfTests::iterator ftit = resultsSet.begin();
- ftit != resultsSet.end(); ++ftit) {
- if (cmHasLiteralPrefix(ftit->CompletionStatus, "SKIP_RETURN_CODE=") ||
- ftit->CompletionStatus == "Disabled") {
- disabledTests.push_back(*ftit);
+ for (cmCTestTestResult const& ft : resultsSet) {
+ if (cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_RETURN_CODE=") ||
+ ft.CompletionStatus == "Disabled") {
+ disabledTests.push_back(ft);
}
}
@@ -502,57 +536,82 @@ int cmCTestTestHandler::ProcessHandler()
percent = 99;
}
- cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
- << static_cast<int>(percent + .5f) << "% tests passed, "
- << failed.size() << " tests failed out of " << total
- << std::endl);
+ std::string passColorCode;
+ std::string failedColorCode;
+ if (failed.empty()) {
+ passColorCode = this->CTest->GetColorCode(cmCTest::Color::GREEN);
+ } else {
+ failedColorCode = this->CTest->GetColorCode(cmCTest::Color::RED);
+ }
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ std::endl
+ << passColorCode << std::lround(percent) << "% tests passed"
+ << this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR)
+ << ", " << failedColorCode << failed.size() << " tests failed"
+ << this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR)
+ << " out of " << total << std::endl);
+ if ((!this->CTest->GetLabelsForSubprojects().empty() &&
+ this->CTest->GetSubprojectSummary())) {
+ this->PrintLabelOrSubprojectSummary(true);
+ }
if (this->CTest->GetLabelSummary()) {
- this->PrintLabelSummary();
+ this->PrintLabelOrSubprojectSummary(false);
}
char realBuf[1024];
- sprintf(realBuf, "%6.2f sec", (double)(clock_finish - clock_start));
+ cmDuration durationInSecs = clock_finish - clock_start;
+ sprintf(realBuf, "%6.2f sec", durationInSecs.count());
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"\nTotal Test time (real) = " << realBuf << "\n",
this->Quiet);
if (!disabledTests.empty()) {
cmGeneratedFileStream ofs;
- cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ std::endl
<< "The following tests did not run:" << std::endl);
this->StartLogFile("TestsDisabled", ofs);
const char* disabled_reason;
- for (std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator dtit =
- disabledTests.begin();
- dtit != disabledTests.end(); ++dtit) {
- ofs << dtit->TestCount << ":" << dtit->Name << std::endl;
- if (dtit->CompletionStatus == "Disabled") {
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->CTest->GetColorCode(cmCTest::Color::BLUE));
+ for (cmCTestTestResult const& dt : disabledTests) {
+ ofs << dt.TestCount << ":" << dt.Name << std::endl;
+ if (dt.CompletionStatus == "Disabled") {
disabled_reason = "Disabled";
} else {
disabled_reason = "Skipped";
}
- cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t"
- << std::setw(3) << dtit->TestCount << " - " << dtit->Name
- << " (" << disabled_reason << ")" << std::endl);
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ "\t" << std::setw(3) << dt.TestCount << " - " << dt.Name
+ << " (" << disabled_reason << ")" << std::endl);
}
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR));
}
if (!failed.empty()) {
cmGeneratedFileStream ofs;
- cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ std::endl
<< "The following tests FAILED:" << std::endl);
this->StartLogFile("TestsFailed", ofs);
- for (SetOfTests::iterator ftit = resultsSet.begin();
- ftit != resultsSet.end(); ++ftit) {
- if (ftit->Status != cmCTestTestHandler::COMPLETED &&
- !cmHasLiteralPrefix(ftit->CompletionStatus, "SKIP_RETURN_CODE=") &&
- ftit->CompletionStatus != "Disabled") {
- ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
+ for (cmCTestTestResult const& ft : resultsSet) {
+ if (ft.Status != cmCTestTestHandler::COMPLETED &&
+ !cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_RETURN_CODE=") &&
+ ft.CompletionStatus != "Disabled") {
+ ofs << ft.TestCount << ":" << ft.Name << std::endl;
+ auto testColor = cmCTest::Color::RED;
+ if (this->GetTestStatus(ft) == "Not Run") {
+ testColor = cmCTest::Color::YELLOW;
+ }
cmCTestLog(
- this->CTest, HANDLER_OUTPUT, "\t"
- << std::setw(3) << ftit->TestCount << " - " << ftit->Name << " ("
- << this->GetTestStatus(ftit->Status) << ")" << std::endl);
+ this->CTest, HANDLER_OUTPUT,
+ "\t" << this->CTest->GetColorCode(testColor) << std::setw(3)
+ << ft.TestCount << " - " << ft.Name << " ("
+ << this->GetTestStatus(ft) << ")"
+ << this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR)
+ << std::endl);
}
}
}
@@ -563,10 +622,11 @@ int cmCTestTestHandler::ProcessHandler()
if (!this->StartResultingXML(
(this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest),
(this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot create "
<< (this->MemCheck ? "memory check" : "testing")
<< " XML file" << std::endl);
- this->LogFile = CM_NULLPTR;
+ this->LogFile = nullptr;
return 1;
}
cmXMLWriter xml(xmlfile);
@@ -574,88 +634,100 @@ int cmCTestTestHandler::ProcessHandler()
}
if (!this->PostProcessHandler()) {
- this->LogFile = CM_NULLPTR;
+ this->LogFile = nullptr;
return -1;
}
if (!failed.empty()) {
- this->LogFile = CM_NULLPTR;
+ this->LogFile = nullptr;
return -1;
}
- this->LogFile = CM_NULLPTR;
+ this->LogFile = nullptr;
return 0;
}
-void cmCTestTestHandler::PrintLabelSummary()
+void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject)
{
- cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
+ // collect subproject labels
+ std::vector<std::string> subprojects =
+ this->CTest->GetLabelsForSubprojects();
std::map<std::string, double> labelTimes;
std::map<std::string, int> labelCounts;
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.empty()) {
- for (std::vector<std::string>::iterator l = p.Labels.begin();
- l != p.Labels.end(); ++l) {
- if ((*l).size() > maxlen) {
- maxlen = (*l).size();
+ // initialize maps
+ for (cmCTestTestProperties& p : this->TestList) {
+ for (std::string const& l : p.Labels) {
+ // first check to see if the current label is a subproject label
+ bool isSubprojectLabel = false;
+ std::vector<std::string>::iterator subproject =
+ std::find(subprojects.begin(), subprojects.end(), l);
+ if (subproject != subprojects.end()) {
+ isSubprojectLabel = true;
+ }
+ // if we are doing sub projects and this label is one, then use it
+ // if we are not doing sub projects and the label is not one use it
+ if ((doSubProject && isSubprojectLabel) ||
+ (!doSubProject && !isSubprojectLabel)) {
+ if (l.size() > maxlen) {
+ maxlen = l.size();
}
- labels.insert(*l);
- labelTimes[*l] = 0;
- labelCounts[*l] = 0;
+ labels.insert(l);
+ labelTimes[l] = 0;
+ labelCounts[l] = 0;
}
}
}
- cmCTestTestHandler::TestResultsVector::iterator ri =
- this->TestResults.begin();
// fill maps
- for (; ri != this->TestResults.end(); ++ri) {
- cmCTestTestResult& result = *ri;
+ for (cmCTestTestResult& result : this->TestResults) {
cmCTestTestProperties& p = *result.Properties;
- if (!p.Labels.empty()) {
- for (std::vector<std::string>::iterator l = p.Labels.begin();
- l != p.Labels.end(); ++l) {
- labelTimes[*l] += result.ExecutionTime;
- ++labelCounts[*l];
+ for (std::string const& l : p.Labels) {
+ // only use labels found in labels
+ if (labels.find(l) != labels.end()) {
+ labelTimes[l] +=
+ result.ExecutionTime.count() * result.Properties->Processors;
+ ++labelCounts[l];
}
}
}
+ // if no labels are found return and print nothing
+ if (labels.empty()) {
+ return;
+ }
// now print times
- if (!labels.empty()) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\nLabel Time Summary:",
- this->Quiet);
+ if (doSubProject) {
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ "\nSubproject Time Summary:", this->Quiet);
+ } else {
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ "\nLabel Time Summary:", this->Quiet);
}
- for (std::set<std::string>::const_iterator i = labels.begin();
- i != labels.end(); ++i) {
- std::string label = *i;
+ for (std::string const& i : labels) {
+ std::string label = i;
label.resize(maxlen + 3, ' ');
char buf[1024];
- sprintf(buf, "%6.2f sec", labelTimes[*i]);
+ sprintf(buf, "%6.2f sec*proc", labelTimes[i]);
std::ostringstream labelCountStr;
- labelCountStr << "(" << labelCounts[*i] << " test";
- if (labelCounts[*i] > 1) {
+ labelCountStr << "(" << labelCounts[i] << " test";
+ if (labelCounts[i] > 1) {
labelCountStr << "s";
}
labelCountStr << ")";
-
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n"
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ "\n"
<< label << " = " << buf << " "
<< labelCountStr.str(),
this->Quiet);
if (this->LogFile) {
- *this->LogFile << "\n" << *i << " = " << buf << "\n";
+ *this->LogFile << "\n" << i << " = " << buf << "\n";
}
}
- if (!labels.empty()) {
- if (this->LogFile) {
- *this->LogFile << "\n";
- }
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet);
+ if (this->LogFile) {
+ *this->LogFile << "\n";
}
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet);
}
void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
@@ -673,9 +745,8 @@ void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
// 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)) {
+ for (std::string const& l : it.Labels) {
+ if (this->IncludeLabelRegularExpression.find(l)) {
found = true;
}
}
@@ -699,9 +770,8 @@ void cmCTestTestHandler::CheckLabelFilterExclude(cmCTestTestProperties& it)
// 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)) {
+ for (std::string const& l : it.Labels) {
+ if (this->ExcludeLabelRegularExpression.find(l)) {
found = true;
}
}
@@ -730,16 +800,15 @@ void cmCTestTestHandler::ComputeTestList()
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) {
+ for (cmCTestTestProperties& tp : this->TestList) {
+ this->CheckLabelFilter(tp);
+ if (tp.IsInBasedOnREOptions) {
inREcnt++;
}
}
// expand the test list based on the union flag
if (this->UseUnion) {
- this->ExpandTestsToRunInformation((int)tmsize);
+ this->ExpandTestsToRunInformation(static_cast<int>(tmsize));
} else {
this->ExpandTestsToRunInformation(inREcnt);
}
@@ -748,9 +817,9 @@ void cmCTestTestHandler::ComputeTestList()
inREcnt = 0;
std::string last_directory;
ListOfTests finalList;
- for (it = this->TestList.begin(); it != this->TestList.end(); it++) {
+ for (cmCTestTestProperties& tp : this->TestList) {
cnt++;
- if (it->IsInBasedOnREOptions) {
+ if (tp.IsInBasedOnREOptions) {
inREcnt++;
}
@@ -759,7 +828,7 @@ void cmCTestTestHandler::ComputeTestList()
if ((!this->TestsToRun.empty() &&
std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt) ==
this->TestsToRun.end()) &&
- !it->IsInBasedOnREOptions) {
+ !tp.IsInBasedOnREOptions) {
continue;
}
} else {
@@ -767,12 +836,12 @@ void cmCTestTestHandler::ComputeTestList()
if ((!this->TestsToRun.empty() &&
std::find(this->TestsToRun.begin(), this->TestsToRun.end(),
inREcnt) == this->TestsToRun.end()) ||
- !it->IsInBasedOnREOptions) {
+ !tp.IsInBasedOnREOptions) {
continue;
}
}
- it->Index = cnt; // save the index into the test list for this test
- finalList.push_back(*it);
+ tp.Index = cnt; // save the index into the test list for this test
+ finalList.push_back(tp);
}
UpdateForFixtures(finalList);
@@ -789,10 +858,9 @@ void cmCTestTestHandler::ComputeTestListForRerunFailed()
{
this->ExpandTestsToRunInformationForRerunFailed();
- cmCTestTestHandler::ListOfTests::iterator it;
ListOfTests finalList;
int cnt = 0;
- for (it = this->TestList.begin(); it != this->TestList.end(); it++) {
+ for (cmCTestTestProperties& tp : this->TestList) {
cnt++;
// if this test is not in our list of tests to run, then skip it.
@@ -802,8 +870,8 @@ void cmCTestTestHandler::ComputeTestListForRerunFailed()
continue;
}
- it->Index = cnt;
- finalList.push_back(*it);
+ tp.Index = cnt;
+ finalList.push_back(tp);
}
UpdateForFixtures(finalList);
@@ -857,24 +925,18 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
it != this->TestList.end(); ++it) {
const cmCTestTestProperties& p = *it;
- const std::set<std::string>& setups = p.FixturesSetup;
- for (std::set<std::string>::const_iterator depsIt = setups.begin();
- depsIt != setups.end(); ++depsIt) {
- fixtureSetups.insert(std::make_pair(*depsIt, it));
+ for (std::string const& deps : p.FixturesSetup) {
+ fixtureSetups.insert(std::make_pair(deps, it));
}
- const std::set<std::string>& cleanups = p.FixturesCleanup;
- for (std::set<std::string>::const_iterator depsIt = cleanups.begin();
- depsIt != cleanups.end(); ++depsIt) {
- fixtureCleanups.insert(std::make_pair(*depsIt, it));
+ for (std::string const& deps : p.FixturesCleanup) {
+ fixtureCleanups.insert(std::make_pair(deps, it));
}
}
// Prepare fast lookup of tests already included in our list of tests
std::set<std::string> addedTests;
- for (ListOfTests::const_iterator it = tests.begin(); it != tests.end();
- ++it) {
- const cmCTestTestProperties& p = *it;
+ for (cmCTestTestProperties const& p : tests) {
addedTests.insert(p.Name);
}
@@ -882,8 +944,8 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
// tests array for tests which require that fixture and tests which are
// setups for that fixture. They are needed at the end to populate
// dependencies of the cleanup tests in our final list of tests.
- std::map<std::string, std::vector<size_t> > fixtureRequirements;
- std::map<std::string, std::vector<size_t> > setupFixturesAdded;
+ std::map<std::string, std::vector<size_t>> fixtureRequirements;
+ std::map<std::string, std::vector<size_t>> setupFixturesAdded;
// Use integer index for iteration because we append to
// the tests vector as we go
@@ -908,10 +970,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
// Must copy the set of fixtures required because we may invalidate
// the tests array by appending to it
std::set<std::string> fixtures = tests[i].FixturesRequired;
- for (std::set<std::string>::const_iterator fixturesIt = fixtures.begin();
- fixturesIt != fixtures.end(); ++fixturesIt) {
-
- const std::string& requiredFixtureName = *fixturesIt;
+ for (std::string const& requiredFixtureName : fixtures) {
if (requiredFixtureName.empty()) {
continue;
}
@@ -1010,11 +1069,7 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
}
// 2. Record all setup fixtures included in the final list of tests
- for (std::set<std::string>::const_iterator fixturesIt =
- tests[i].FixturesSetup.begin();
- fixturesIt != tests[i].FixturesSetup.end(); ++fixturesIt) {
-
- const std::string& setupFixtureName = *fixturesIt;
+ for (std::string const& setupFixtureName : tests[i].FixturesSetup) {
if (setupFixtureName.empty()) {
continue;
}
@@ -1028,23 +1083,18 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
// setup tests for that fixture. The latter is required to handle the
// pathological case where setup and cleanup tests are in the test set
// but no other test has that fixture as a requirement.
- for (ListOfTests::iterator tIt = tests.begin(); tIt != tests.end(); ++tIt) {
- cmCTestTestProperties& p = *tIt;
+ for (cmCTestTestProperties& p : tests) {
const std::set<std::string>& cleanups = p.FixturesCleanup;
- for (std::set<std::string>::const_iterator fIt = cleanups.begin();
- fIt != cleanups.end(); ++fIt) {
- const std::string& fixture = *fIt;
-
+ for (std::string const& fixture : cleanups) {
// This cleanup test could be part of the original test list that was
// passed in. It is then possible that no other test requires the
// fIt fixture, so we have to check for this.
- std::map<std::string, std::vector<size_t> >::const_iterator cIt =
+ std::map<std::string, std::vector<size_t>>::const_iterator cIt =
fixtureRequirements.find(fixture);
if (cIt != fixtureRequirements.end()) {
const std::vector<size_t>& indices = cIt->second;
- for (std::vector<size_t>::const_iterator indexIt = indices.begin();
- indexIt != indices.end(); ++indexIt) {
- const std::string& reqTestName = tests[*indexIt].Name;
+ for (size_t index : indices) {
+ const std::string& reqTestName = tests[index].Name;
if (std::find(p.Depends.begin(), p.Depends.end(), reqTestName) ==
p.Depends.end()) {
p.Depends.push_back(reqTestName);
@@ -1057,9 +1107,8 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
cIt = setupFixturesAdded.find(fixture);
if (cIt != setupFixturesAdded.end()) {
const std::vector<size_t>& indices = cIt->second;
- for (std::vector<size_t>::const_iterator indexIt = indices.begin();
- indexIt != indices.end(); ++indexIt) {
- const std::string& setupTestName = tests[*indexIt].Name;
+ for (size_t index : indices) {
+ const std::string& setupTestName = tests[index].Name;
if (std::find(p.Depends.begin(), p.Depends.end(), setupTestName) ==
p.Depends.end()) {
p.Depends.push_back(setupTestName);
@@ -1069,18 +1118,17 @@ void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
}
}
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Added "
- << fixtureTestsAdded
- << " tests to meet fixture requirements" << std::endl,
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Added " << fixtureTestsAdded
+ << " tests to meet fixture requirements"
+ << std::endl,
this->Quiet);
}
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;
+ for (cmCTestTestProperties& p : this->TestList) {
if (max < p.Name.size()) {
max = p.Name.size();
}
@@ -1101,8 +1149,9 @@ bool cmCTestTestHandler::GetValue(const char* tag, int& value,
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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: " << tag << " found [" << line << "]"
+ << std::endl);
ret = false;
}
return ret;
@@ -1118,8 +1167,9 @@ bool cmCTestTestHandler::GetValue(const char* tag, double& value,
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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: " << tag << " found [" << line << "]"
+ << std::endl);
ret = false;
}
return ret;
@@ -1144,8 +1194,9 @@ bool cmCTestTestHandler::GetValue(const char* tag, bool& 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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: " << tag << " found [" << line << "]"
+ << std::endl);
ret = false;
}
return ret;
@@ -1161,8 +1212,9 @@ bool cmCTestTestHandler::GetValue(const char* tag, size_t& value,
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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: " << tag << " found [" << line << "]"
+ << std::endl);
ret = false;
}
return ret;
@@ -1177,8 +1229,9 @@ bool cmCTestTestHandler::GetValue(const char* tag, std::string& value,
if (line == tag) {
ret = cmSystemTools::GetLineFromStream(fin, value);
} else {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: "
- << tag << " found [" << line << "]" << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "parse error: missing tag: " << tag << " found [" << line << "]"
+ << std::endl);
ret = false;
}
return ret;
@@ -1189,12 +1242,10 @@ void cmCTestTestHandler::ProcessDirectory(std::vector<std::string>& passed,
{
this->ComputeTestList();
this->StartTest = this->CTest->CurrentTime();
- this->StartTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
- double elapsed_time_start = cmSystemTools::GetTime();
+ this->StartTestTime = std::chrono::system_clock::now();
+ auto elapsed_time_start = std::chrono::steady_clock::now();
- cmCTestMultiProcessHandler* parallel = this->CTest->GetBatchJobs()
- ? new cmCTestBatchTestHandler
- : new cmCTestMultiProcessHandler;
+ cmCTestMultiProcessHandler* parallel = new cmCTestMultiProcessHandler;
parallel->SetCTest(this->CTest);
parallel->SetParallelLevel(this->CTest->GetParallelLevel());
parallel->SetTestHandler(this);
@@ -1215,36 +1266,33 @@ void cmCTestTestHandler::ProcessDirectory(std::vector<std::string>& passed,
bool randomSchedule = this->CTest->GetScheduleType() == "Random";
if (randomSchedule) {
- srand((unsigned)time(CM_NULLPTR));
+ srand(static_cast<unsigned>(time(nullptr)));
}
- for (ListOfTests::iterator it = this->TestList.begin();
- it != this->TestList.end(); ++it) {
- cmCTestTestProperties& p = *it;
+ for (cmCTestTestProperties& p : this->TestList) {
cmCTestMultiProcessHandler::TestSet depends;
if (randomSchedule) {
p.Cost = static_cast<float>(rand());
}
- if (p.Timeout == 0 && this->CTest->GetGlobalTimeout() != 0) {
+ if (p.Timeout == cmDuration::zero() &&
+ this->CTest->GetGlobalTimeout() != cmDuration::zero()) {
p.Timeout = this->CTest->GetGlobalTimeout();
}
if (!p.Depends.empty()) {
- 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);
+ for (std::string const& i : p.Depends) {
+ for (cmCTestTestProperties const& it2 : this->TestList) {
+ 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;
+ tests[p.Index] = depends;
+ properties[p.Index] = &p;
}
parallel->SetTests(tests, properties);
parallel->SetPassFailVectors(&passed, &failed);
@@ -1260,8 +1308,9 @@ void cmCTestTestHandler::ProcessDirectory(std::vector<std::string>& passed,
}
delete parallel;
this->EndTest = this->CTest->CurrentTime();
- this->EndTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
- this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
+ this->EndTestTime = std::chrono::system_clock::now();
+ this->ElapsedTestingTime =
+ std::chrono::steady_clock::now() - elapsed_time_start;
*this->LogFile << "End testing: " << this->CTest->CurrentTime() << std::endl;
}
@@ -1277,83 +1326,85 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml)
}
this->CTest->StartXML(xml, this->AppendXML);
+ this->CTest->GenerateSubprojectsOutput(xml);
xml.StartElement("Testing");
xml.Element("StartDateTime", this->StartTest);
xml.Element("StartTestTime", this->StartTestTime);
xml.StartElement("TestList");
- 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;
+ for (cmCTestTestResult const& result : this->TestResults) {
+ std::string testPath = result.Path + "/" + result.Name;
xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str()));
}
xml.EndElement(); // TestList
- for (cc = 0; cc < this->TestResults.size(); cc++) {
- cmCTestTestResult* result = &this->TestResults[cc];
+ for (cmCTestTestResult& result : this->TestResults) {
this->WriteTestResultHeader(xml, result);
xml.StartElement("Results");
- if (result->Status != cmCTestTestHandler::NOT_RUN) {
- if (result->Status != cmCTestTestHandler::COMPLETED ||
- result->ReturnValue) {
+ if (result.Status != cmCTestTestHandler::NOT_RUN) {
+ if (result.Status != cmCTestTestHandler::COMPLETED ||
+ result.ReturnValue) {
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Exit Code");
- xml.Element("Value", this->GetTestStatus(result->Status));
+ xml.Element("Value", this->GetTestStatus(result));
xml.EndElement(); // NamedMeasurement
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Exit Value");
- xml.Element("Value", result->ReturnValue);
+ xml.Element("Value", result.ReturnValue);
xml.EndElement(); // NamedMeasurement
}
- this->GenerateRegressionImages(xml, result->DartString);
+ this->GenerateRegressionImages(xml, result.DartString);
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "numeric/double");
xml.Attribute("name", "Execution Time");
- xml.Element("Value", result->ExecutionTime);
+ xml.Element("Value", result.ExecutionTime.count());
xml.EndElement(); // NamedMeasurement
- if (!result->Reason.empty()) {
+ if (!result.Reason.empty()) {
const char* reasonType = "Pass Reason";
- if (result->Status != cmCTestTestHandler::COMPLETED) {
+ if (result.Status != cmCTestTestHandler::COMPLETED) {
reasonType = "Fail Reason";
}
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", reasonType);
- xml.Element("Value", result->Reason);
+ xml.Element("Value", result.Reason);
xml.EndElement(); // NamedMeasurement
}
}
xml.StartElement("NamedMeasurement");
+ xml.Attribute("type", "numeric/double");
+ xml.Attribute("name", "Processors");
+ xml.Element("Value", result.Properties->Processors);
+ xml.EndElement(); // NamedMeasurement
+
+ xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Completion Status");
- xml.Element("Value", result->CompletionStatus);
+ xml.Element("Value", result.CompletionStatus);
xml.EndElement(); // NamedMeasurement
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Command Line");
- xml.Element("Value", result->FullCommandLine);
+ xml.Element("Value", result.FullCommandLine);
xml.EndElement(); // NamedMeasurement
- std::map<std::string, std::string>::iterator measureIt;
- for (measureIt = result->Properties->Measurements.begin();
- measureIt != result->Properties->Measurements.end(); ++measureIt) {
+ for (auto const& measure : result.Properties->Measurements) {
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
- xml.Attribute("name", measureIt->first);
- xml.Element("Value", measureIt->second);
+ xml.Attribute("name", measure.first);
+ xml.Element("Value", measure.second);
xml.EndElement(); // NamedMeasurement
}
xml.StartElement("Measurement");
xml.StartElement("Value");
- if (result->CompressOutput) {
+ if (result.CompressOutput) {
xml.Attribute("encoding", "base64");
xml.Attribute("compression", "gzip");
}
- xml.Content(result->Output);
+ xml.Content(result.Output);
xml.EndElement(); // Value
xml.EndElement(); // Measurement
xml.EndElement(); // Results
@@ -1364,39 +1415,40 @@ void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml)
xml.Element("EndDateTime", this->EndTest);
xml.Element("EndTestTime", this->EndTestTime);
- xml.Element("ElapsedMinutes",
- static_cast<int>(this->ElapsedTestingTime / 6) / 10.0);
+ xml.Element(
+ "ElapsedMinutes",
+ std::chrono::duration_cast<std::chrono::minutes>(this->ElapsedTestingTime)
+ .count());
xml.EndElement(); // Testing
this->CTest->EndXML(xml);
}
void cmCTestTestHandler::WriteTestResultHeader(cmXMLWriter& xml,
- cmCTestTestResult* result)
+ cmCTestTestResult const& result)
{
xml.StartElement("Test");
- if (result->Status == cmCTestTestHandler::COMPLETED) {
+ if (result.Status == cmCTestTestHandler::COMPLETED) {
xml.Attribute("Status", "passed");
- } else if (result->Status == cmCTestTestHandler::NOT_RUN) {
+ } else if (result.Status == cmCTestTestHandler::NOT_RUN) {
xml.Attribute("Status", "notrun");
} else {
xml.Attribute("Status", "failed");
}
- std::string testPath = result->Path + "/" + result->Name;
- xml.Element("Name", result->Name);
- xml.Element("Path", this->CTest->GetShortPathToFile(result->Path.c_str()));
+ std::string testPath = result.Path + "/" + result.Name;
+ xml.Element("Name", result.Name);
+ xml.Element("Path", this->CTest->GetShortPathToFile(result.Path.c_str()));
xml.Element("FullName", this->CTest->GetShortPathToFile(testPath.c_str()));
- xml.Element("FullCommandLine", result->FullCommandLine);
+ xml.Element("FullCommandLine", result.FullCommandLine);
}
void cmCTestTestHandler::WriteTestResultFooter(cmXMLWriter& xml,
- cmCTestTestResult* result)
+ cmCTestTestResult const& result)
{
- if (!result->Properties->Labels.empty()) {
+ if (!result.Properties->Labels.empty()) {
xml.StartElement("Labels");
- std::vector<std::string> const& labels = result->Properties->Labels;
- for (std::vector<std::string>::const_iterator li = labels.begin();
- li != labels.end(); ++li) {
- xml.Element("Label", *li);
+ std::vector<std::string> const& labels = result.Properties->Labels;
+ for (std::string const& label : labels) {
+ xml.Element("Label", label);
}
xml.EndElement(); // Labels
}
@@ -1405,20 +1457,18 @@ void cmCTestTestHandler::WriteTestResultFooter(cmXMLWriter& xml,
}
void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml,
- cmCTestTestResult* result)
+ cmCTestTestResult& result)
{
- if (result->Status != cmCTestTestHandler::COMPLETED &&
- !result->Properties->AttachOnFail.empty()) {
- 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) {
- const std::string& base64 = this->CTest->Base64GzipEncodeFile(*file);
- std::string fname = cmSystemTools::GetFilenameName(*file);
+ if (result.Status != cmCTestTestHandler::COMPLETED &&
+ !result.Properties->AttachOnFail.empty()) {
+ result.Properties->AttachedFiles.insert(
+ result.Properties->AttachedFiles.end(),
+ result.Properties->AttachOnFail.begin(),
+ result.Properties->AttachOnFail.end());
+ }
+ for (std::string const& file : result.Properties->AttachedFiles) {
+ const std::string& base64 = this->CTest->Base64GzipEncodeFile(file);
+ std::string const fname = cmSystemTools::GetFilenameName(file);
xml.StartElement("NamedMeasurement");
xml.Attribute("name", "Attached File");
xml.Attribute("encoding", "base64");
@@ -1432,18 +1482,16 @@ void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml,
int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec)
{
- std::vector<std::string>::iterator it;
- for (it = vec.begin(); it != vec.end(); ++it) {
+ for (std::string const& it : vec) {
int retVal = 0;
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- "Run command: " << *it << std::endl, this->Quiet);
- if (!cmSystemTools::RunSingleCommand(it->c_str(), CM_NULLPTR, CM_NULLPTR,
- &retVal, CM_NULLPTR,
- cmSystemTools::OUTPUT_MERGE
+ "Run command: " << it << std::endl, this->Quiet);
+ if (!cmSystemTools::RunSingleCommand(it, nullptr, nullptr, &retVal,
+ nullptr, cmSystemTools::OUTPUT_MERGE
/*this->Verbose*/) ||
retVal != 0) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
- "Problem running command: " << *it << std::endl);
+ "Problem running command: " << it << std::endl);
return 0;
}
}
@@ -1476,7 +1524,7 @@ void cmCTestTestHandler::AddConfigurations(
}
tempPath = filepath + filename;
attempted.push_back(tempPath);
- attemptedConfigs.push_back("");
+ attemptedConfigs.emplace_back();
if (!ctest->GetConfigType().empty()) {
tempPath = filepath;
@@ -1499,32 +1547,32 @@ void cmCTestTestHandler::AddConfigurations(
tempPath += "Release/";
tempPath += filename;
attempted.push_back(tempPath);
- attemptedConfigs.push_back("Release");
+ attemptedConfigs.emplace_back("Release");
tempPath = filepath;
tempPath += "Debug/";
tempPath += filename;
attempted.push_back(tempPath);
- attemptedConfigs.push_back("Debug");
+ attemptedConfigs.emplace_back("Debug");
tempPath = filepath;
tempPath += "MinSizeRel/";
tempPath += filename;
attempted.push_back(tempPath);
- attemptedConfigs.push_back("MinSizeRel");
+ attemptedConfigs.emplace_back("MinSizeRel");
tempPath = filepath;
tempPath += "RelWithDebInfo/";
tempPath += filename;
attempted.push_back(tempPath);
- attemptedConfigs.push_back("RelWithDebInfo");
+ attemptedConfigs.emplace_back("RelWithDebInfo");
tempPath = filepath;
tempPath += "Deployment/";
tempPath += filename;
attempted.push_back(tempPath);
- attemptedConfigs.push_back("Deployment");
+ attemptedConfigs.emplace_back("Deployment");
tempPath = filepath;
tempPath += "Development/";
tempPath += filename;
attempted.push_back(tempPath);
- attemptedConfigs.push_back("Deployment");
+ attemptedConfigs.emplace_back("Deployment");
}
}
@@ -1554,11 +1602,9 @@ std::string cmCTestTestHandler::FindExecutable(
// if extraPaths are provided and we were not passed a full path, try them,
// try any extra paths
if (filepath.empty()) {
- for (unsigned int i = 0; i < extraPaths.size(); ++i) {
- std::string filepathExtra =
- cmSystemTools::GetFilenamePath(extraPaths[i]);
- std::string filenameExtra =
- cmSystemTools::GetFilenameName(extraPaths[i]);
+ for (std::string const& extraPath : extraPaths) {
+ std::string filepathExtra = cmSystemTools::GetFilenamePath(extraPath);
+ std::string filenameExtra = cmSystemTools::GetFilenameName(extraPath);
cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
filepathExtra, filenameExtra);
}
@@ -1570,7 +1616,7 @@ std::string cmCTestTestHandler::FindExecutable(
// now look in the paths we specified above
for (unsigned int ai = 0; ai < attempted.size() && fullPath.empty(); ++ai) {
// first check without exe extension
- if (cmSystemTools::FileExists(attempted[ai].c_str()) &&
+ if (cmSystemTools::FileExists(attempted[ai]) &&
!cmSystemTools::FileIsDirectory(attempted[ai])) {
fullPath = cmSystemTools::CollapseFullPath(attempted[ai]);
resultingConfig = attemptedConfigs[ai];
@@ -1580,7 +1626,7 @@ std::string cmCTestTestHandler::FindExecutable(
failed.push_back(attempted[ai]);
tempPath = attempted[ai];
tempPath += cmSystemTools::GetExecutableExtension();
- if (cmSystemTools::FileExists(tempPath.c_str()) &&
+ if (cmSystemTools::FileExists(tempPath) &&
!cmSystemTools::FileIsDirectory(tempPath)) {
fullPath = cmSystemTools::CollapseFullPath(tempPath);
resultingConfig = attemptedConfigs[ai];
@@ -1593,19 +1639,19 @@ std::string cmCTestTestHandler::FindExecutable(
// if everything else failed, check the users path, but only if a full path
// wasn't specified
if (fullPath.empty() && filepath.empty()) {
- std::string path = cmSystemTools::FindProgram(filename.c_str());
- if (path != "") {
- resultingConfig = "";
+ std::string const path = cmSystemTools::FindProgram(filename.c_str());
+ if (!path.empty()) {
+ resultingConfig.clear();
return path;
}
}
if (fullPath.empty()) {
- cmCTestLog(ctest, HANDLER_OUTPUT, "Could not find executable "
+ 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 << "\n");
+ for (std::string const& f : failed) {
+ cmCTestLog(ctest, HANDLER_OUTPUT, f << "\n");
}
}
@@ -1630,14 +1676,14 @@ void cmCTestTestHandler::GetListOfTests()
}
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Constructing a list of tests" << std::endl, this->Quiet);
- cmake cm(cmake::RoleScript);
+ cmake cm(cmake::RoleScript, cmState::CTest);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
- CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
- mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
- this->CTest->GetConfigType().c_str());
+ cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+ mf.AddDefinition("CTEST_CONFIGURATION_TYPE",
+ this->CTest->GetConfigType().c_str());
// Add handler for ADD_TEST
cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
@@ -1660,6 +1706,13 @@ void cmCTestTestHandler::GetListOfTests()
newCom4->TestHandler = this;
cm.GetState()->AddBuiltinCommand("set_tests_properties", newCom4);
+ // Add handler for SET_DIRECTORY_PROPERTIES
+ cm.GetState()->RemoveBuiltinCommand("set_directory_properties");
+ cmCTestSetDirectoryPropertiesCommand* newCom5 =
+ new cmCTestSetDirectoryPropertiesCommand;
+ newCom5->TestHandler = this;
+ cm.GetState()->AddBuiltinCommand("set_directory_properties", newCom5);
+
const char* testFilename;
if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
// does the CTestTestfile.cmake exist ?
@@ -1671,7 +1724,7 @@ void cmCTestTestHandler::GetListOfTests()
return;
}
- if (!mf->ReadListFile(testFilename)) {
+ if (!mf.ReadListFile(testFilename)) {
return;
}
if (cmSystemTools::GetErrorOccuredFlag()) {
@@ -1693,17 +1746,20 @@ void cmCTestTestHandler::UseExcludeRegExp()
this->UseExcludeRegExpFirst = !this->UseIncludeRegExpFlag;
}
-const char* cmCTestTestHandler::GetTestStatus(int status)
+std::string cmCTestTestHandler::GetTestStatus(cmCTestTestResult const& result)
{
static const char* statuses[] = { "Not Run", "Timeout", "SEGFAULT",
"ILLEGAL", "INTERRUPT", "NUMERICAL",
"OTHER_FAULT", "Failed", "BAD_COMMAND",
"Completed" };
-
+ int status = result.Status;
if (status < cmCTestTestHandler::NOT_RUN ||
status > cmCTestTestHandler::COMPLETED) {
return "No Status";
}
+ if (status == cmCTestTestHandler::OTHER_FAULT) {
+ return result.ExceptionStatus;
+ }
return statuses[status];
}
@@ -1774,8 +1830,8 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
cmsys::Directory directory;
if (directory.Load(dirName) == 0) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to read the contents of "
- << dirName << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Unable to read the contents of " << dirName << std::endl);
return;
}
@@ -1792,7 +1848,7 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
if (fileNameSubstring != pattern) {
continue;
}
- if (logName == "") {
+ if (logName.empty()) {
logName = fileName;
} else {
// if multiple matching logs were found we use the most recently
@@ -1808,10 +1864,10 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
std::string lastTestsFailedLog =
this->CTest->GetBinaryDir() + "/Testing/Temporary/" + logName;
- if (!cmSystemTools::FileExists(lastTestsFailedLog.c_str())) {
+ if (!cmSystemTools::FileExists(lastTestsFailedLog)) {
if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels()) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, lastTestsFailedLog
- << " does not exist!" << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ lastTestsFailedLog << " does not exist!" << std::endl);
}
return;
}
@@ -1833,7 +1889,8 @@ void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
ifs.close();
} else if (!this->CTest->GetShowOnly() &&
!this->CTest->ShouldPrintLabels()) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem reading file: "
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Problem reading file: "
<< lastTestsFailedLog
<< " while generating list of previously failed tests."
<< std::endl);
@@ -1921,7 +1978,7 @@ void cmCTestTestHandler::GenerateRegressionImages(cmXMLWriter& xml,
} else if (measurementfile.find(cxml)) {
const std::string& filename =
cmCTest::CleanString(measurementfile.match(5));
- if (cmSystemTools::FileExists(filename.c_str())) {
+ if (cmSystemTools::FileExists(filename)) {
long len = cmSystemTools::FileLength(filename);
if (len == 0) {
std::string k1 = measurementfile.match(1);
@@ -1942,11 +1999,12 @@ void cmCTestTestHandler::GenerateRegressionImages(cmXMLWriter& xml,
xml.Element("Value", "Image " + filename + " is empty");
xml.EndElement();
} else {
- cmsys::ifstream ifs(filename.c_str(), std::ios::in
+ 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>(
@@ -1983,9 +2041,9 @@ void cmCTestTestHandler::GenerateRegressionImages(cmXMLWriter& xml,
xml.Attribute("text", "text/string");
xml.Element("Value", "File " + filename + " not found");
xml.EndElement();
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "File \""
- << filename << "\" not found." << std::endl,
- this->Quiet);
+ cmCTestOptionalLog(
+ this->CTest, HANDLER_OUTPUT,
+ "File \"" << filename << "\" not found." << std::endl, this->Quiet);
}
cxml.erase(measurementfile.start(),
measurementfile.end() - measurementfile.start());
@@ -2086,116 +2144,142 @@ bool cmCTestTestHandler::SetTestsProperties(
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) {
+ for (std::string const& t : tests) {
+ for (cmCTestTestProperties& rt : this->TestList) {
+ if (t == rt.Name) {
+ if (key == "_BACKTRACE_TRIPLES") {
+ std::vector<std::string> triples;
+ // allow empty args in the triples
+ cmSystemTools::ExpandListArgument(val, triples, true);
+
+ // Ensure we have complete triples otherwise the data is corrupt.
+ if (triples.size() % 3 == 0) {
+ cmState state;
+ rt.Backtrace = cmListFileBacktrace(state.CreateBaseSnapshot());
+
+ // the first entry represents the top of the trace so we need to
+ // reconstruct the backtrace in reverse
+ for (size_t i = triples.size(); i >= 3; i -= 3) {
+ cmListFileContext fc;
+ fc.FilePath = triples[i - 3];
+ long line = 0;
+ if (!cmSystemTools::StringToLong(triples[i - 2].c_str(),
+ &line)) {
+ line = 0;
+ }
+ fc.Line = line;
+ fc.Name = triples[i - 1];
+ rt.Backtrace = rt.Backtrace.Push(fc);
+ }
+ }
+ }
if (key == "WILL_FAIL") {
- rtit->WillFail = cmSystemTools::IsOn(val.c_str());
+ rt.WillFail = cmSystemTools::IsOn(val);
}
if (key == "DISABLED") {
- rtit->Disabled = cmSystemTools::IsOn(val.c_str());
+ rt.Disabled = cmSystemTools::IsOn(val);
}
if (key == "ATTACHED_FILES") {
- cmSystemTools::ExpandListArgument(val, rtit->AttachedFiles);
+ cmSystemTools::ExpandListArgument(val, rt.AttachedFiles);
}
if (key == "ATTACHED_FILES_ON_FAIL") {
- cmSystemTools::ExpandListArgument(val, rtit->AttachOnFail);
+ cmSystemTools::ExpandListArgument(val, rt.AttachOnFail);
}
if (key == "RESOURCE_LOCK") {
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(val, lval);
- rtit->LockedResources.insert(lval.begin(), lval.end());
+ rt.LockedResources.insert(lval.begin(), lval.end());
}
if (key == "FIXTURES_SETUP") {
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(val, lval);
- rtit->FixturesSetup.insert(lval.begin(), lval.end());
+ rt.FixturesSetup.insert(lval.begin(), lval.end());
}
if (key == "FIXTURES_CLEANUP") {
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(val, lval);
- rtit->FixturesCleanup.insert(lval.begin(), lval.end());
+ rt.FixturesCleanup.insert(lval.begin(), lval.end());
}
if (key == "FIXTURES_REQUIRED") {
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(val, lval);
- rtit->FixturesRequired.insert(lval.begin(), lval.end());
+ rt.FixturesRequired.insert(lval.begin(), lval.end());
}
if (key == "TIMEOUT") {
- rtit->Timeout = atof(val.c_str());
- rtit->ExplicitTimeout = true;
+ rt.Timeout = cmDuration(atof(val.c_str()));
+ rt.ExplicitTimeout = true;
}
if (key == "COST") {
- rtit->Cost = static_cast<float>(atof(val.c_str()));
+ rt.Cost = static_cast<float>(atof(val.c_str()));
}
if (key == "REQUIRED_FILES") {
- cmSystemTools::ExpandListArgument(val, rtit->RequiredFiles);
+ cmSystemTools::ExpandListArgument(val, rt.RequiredFiles);
}
if (key == "RUN_SERIAL") {
- rtit->RunSerial = cmSystemTools::IsOn(val.c_str());
+ rt.RunSerial = cmSystemTools::IsOn(val);
}
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)));
+ for (std::string const& cr : lval) {
+ rt.ErrorRegularExpressions.emplace_back(cr, cr);
}
}
if (key == "PROCESSORS") {
- rtit->Processors = atoi(val.c_str());
- if (rtit->Processors < 1) {
- rtit->Processors = 1;
+ rt.Processors = atoi(val.c_str());
+ if (rt.Processors < 1) {
+ rt.Processors = 1;
}
}
+ if (key == "PROCESSOR_AFFINITY") {
+ rt.WantAffinity = cmSystemTools::IsOn(val);
+ }
if (key == "SKIP_RETURN_CODE") {
- rtit->SkipReturnCode = atoi(val.c_str());
- if (rtit->SkipReturnCode < 0 || rtit->SkipReturnCode > 255) {
- rtit->SkipReturnCode = -1;
+ rt.SkipReturnCode = atoi(val.c_str());
+ if (rt.SkipReturnCode < 0 || rt.SkipReturnCode > 255) {
+ rt.SkipReturnCode = -1;
}
}
if (key == "DEPENDS") {
- cmSystemTools::ExpandListArgument(val, rtit->Depends);
+ cmSystemTools::ExpandListArgument(val, rt.Depends);
}
if (key == "ENVIRONMENT") {
- cmSystemTools::ExpandListArgument(val, rtit->Environment);
+ cmSystemTools::ExpandListArgument(val, rt.Environment);
}
if (key == "LABELS") {
- cmSystemTools::ExpandListArgument(val, rtit->Labels);
+ std::vector<std::string> Labels;
+ cmSystemTools::ExpandListArgument(val, Labels);
+ rt.Labels.insert(rt.Labels.end(), Labels.begin(), Labels.end());
+ // sort the array
+ std::sort(rt.Labels.begin(), rt.Labels.end());
+ // remove duplicates
+ std::vector<std::string>::iterator new_end =
+ std::unique(rt.Labels.begin(), rt.Labels.end());
+ rt.Labels.erase(new_end, rt.Labels.end());
}
if (key == "MEASUREMENT") {
size_t pos = val.find_first_of('=');
if (pos != std::string::npos) {
std::string mKey = val.substr(0, pos);
- const char* mVal = val.c_str() + pos + 1;
- rtit->Measurements[mKey] = mVal;
+ std::string mVal = val.substr(pos + 1);
+ rt.Measurements[mKey] = std::move(mVal);
} else {
- rtit->Measurements[val] = "1";
+ rt.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)));
+ for (std::string const& cr : lval) {
+ rt.RequiredRegularExpressions.emplace_back(cr, cr);
}
}
if (key == "WORKING_DIRECTORY") {
- rtit->Directory = val;
+ rt.Directory = val;
}
if (key == "TIMEOUT_AFTER_MATCH") {
std::vector<std::string> propArgs;
@@ -2205,15 +2289,11 @@ bool cmCTestTestHandler::SetTestsProperties(
"TIMEOUT_AFTER_MATCH expects two arguments, found "
<< propArgs.size() << std::endl);
} else {
- rtit->AlternateTimeout = atof(propArgs[0].c_str());
+ rt.AlternateTimeout = cmDuration(atof(propArgs[0].c_str()));
std::vector<std::string> lval;
cmSystemTools::ExpandListArgument(propArgs[1], lval);
- std::vector<std::string>::iterator crit;
- for (crit = lval.begin(); crit != lval.end(); ++crit) {
- rtit->TimeoutRegularExpressions.push_back(
- std::pair<cmsys::RegularExpression, std::string>(
- cmsys::RegularExpression(crit->c_str()),
- std::string(*crit)));
+ for (std::string const& cr : lval) {
+ rt.TimeoutRegularExpressions.emplace_back(cr, cr);
}
}
}
@@ -2224,6 +2304,53 @@ bool cmCTestTestHandler::SetTestsProperties(
return true;
}
+bool cmCTestTestHandler::SetDirectoryProperties(
+ 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;
+ for (cmCTestTestProperties& rt : this->TestList) {
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ if (cwd == rt.Directory) {
+ if (key == "LABELS") {
+ std::vector<std::string> DirectoryLabels;
+ cmSystemTools::ExpandListArgument(val, DirectoryLabels);
+ rt.Labels.insert(rt.Labels.end(), DirectoryLabels.begin(),
+ DirectoryLabels.end());
+
+ // sort the array
+ std::sort(rt.Labels.begin(), rt.Labels.end());
+ // remove duplicates
+ std::vector<std::string>::iterator new_end =
+ std::unique(rt.Labels.begin(), rt.Labels.end());
+ rt.Labels.erase(new_end, rt.Labels.end());
+ }
+ }
+ }
+ }
+ return true;
+}
+
bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
{
const std::string& testname = args[0];
@@ -2231,7 +2358,7 @@ bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
this->Quiet);
if (this->UseExcludeRegExpFlag && this->UseExcludeRegExpFirst &&
- this->ExcludeTestsRegularExpression.find(testname.c_str())) {
+ this->ExcludeTestsRegularExpression.find(testname)) {
return true;
}
if (this->MemCheck) {
@@ -2278,17 +2405,18 @@ bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
test.WillFail = false;
test.Disabled = false;
test.RunSerial = false;
- test.Timeout = 0;
+ test.Timeout = cmDuration::zero();
test.ExplicitTimeout = false;
test.Cost = 0;
test.Processors = 1;
+ test.WantAffinity = false;
test.SkipReturnCode = -1;
test.PreviousRuns = 0;
if (this->UseIncludeRegExpFlag &&
- !this->IncludeTestsRegularExpression.find(testname.c_str())) {
+ !this->IncludeTestsRegularExpression.find(testname)) {
test.IsInBasedOnREOptions = false;
} else if (this->UseExcludeRegExpFlag && !this->UseExcludeRegExpFirst &&
- this->ExcludeTestsRegularExpression.find(testname.c_str())) {
+ this->ExcludeTestsRegularExpression.find(testname)) {
test.IsInBasedOnREOptions = false;
}
this->TestList.push_back(test);
diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h
index 0edcb143a..7f3f5e4f8 100644
--- a/Source/CTest/cmCTestTestHandler.h
+++ b/Source/CTest/cmCTestTestHandler.h
@@ -3,11 +3,15 @@
#ifndef cmCTestTestHandler_h
#define cmCTestTestHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGenericHandler.h"
+#include "cmDuration.h"
+#include "cmListFileCache.h"
#include "cmsys/RegularExpression.hxx"
+#include <chrono>
+#include <cstdint>
#include <iosfwd>
#include <map>
#include <set>
@@ -28,7 +32,6 @@ class cmCTestTestHandler : public cmCTestGenericHandler
{
friend class cmCTestRunTest;
friend class cmCTestMultiProcessHandler;
- friend class cmCTestBatchTestHandler;
public:
typedef cmCTestGenericHandler Superclass;
@@ -36,10 +39,10 @@ public:
/**
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
/**
- * When both -R and -I are used should te resulting test list be the
+ * When both -R and -I are used should the resulting test list be the
* intersection or the union of the lists. By default it is the
* intersection.
*/
@@ -54,9 +57,9 @@ public:
/**
* This method is called when reading CTest custom file
*/
- void PopulateCustomVectors(cmMakefile* mf) CM_OVERRIDE;
+ void PopulateCustomVectors(cmMakefile* mf) override;
- ///! Control the use of the regular expresisons, call these methods to turn
+ //! Control the use of the regular expresisons, call these methods to turn
/// them on
void UseIncludeRegExp();
void UseExcludeRegExp();
@@ -75,7 +78,7 @@ public:
this->CustomMaximumFailedTestOutputSize = n;
}
- ///! pass the -I argument down
+ //! pass the -I argument down
void SetTestsToRunInformation(const char*);
cmCTestTestHandler();
@@ -90,7 +93,12 @@ public:
*/
bool SetTestsProperties(const std::vector<std::string>& args);
- void Initialize() CM_OVERRIDE;
+ /**
+ * Set directory properties
+ */
+ bool SetDirectoryProperties(const std::vector<std::string>& args);
+
+ void Initialize() override;
// NOTE: This struct is Saved/Restored
// in cmCTestTestHandler, if you add to this class
@@ -105,11 +113,11 @@ public:
std::vector<std::string> Depends;
std::vector<std::string> AttachedFiles;
std::vector<std::string> AttachOnFail;
- std::vector<std::pair<cmsys::RegularExpression, std::string> >
+ std::vector<std::pair<cmsys::RegularExpression, std::string>>
ErrorRegularExpressions;
- std::vector<std::pair<cmsys::RegularExpression, std::string> >
+ std::vector<std::pair<cmsys::RegularExpression, std::string>>
RequiredRegularExpressions;
- std::vector<std::pair<cmsys::RegularExpression, std::string> >
+ std::vector<std::pair<cmsys::RegularExpression, std::string>>
TimeoutRegularExpressions;
std::map<std::string, std::string> Measurements;
bool IsInBasedOnREOptions;
@@ -118,12 +126,14 @@ public:
float Cost;
int PreviousRuns;
bool RunSerial;
- double Timeout;
+ cmDuration Timeout;
bool ExplicitTimeout;
- double AlternateTimeout;
+ cmDuration AlternateTimeout;
int Index;
// Requested number of process slots
int Processors;
+ bool WantAffinity;
+ std::vector<size_t> Affinity;
// return code of test which will mark test as "not run"
int SkipReturnCode;
std::vector<std::string> Environment;
@@ -133,6 +143,8 @@ public:
std::set<std::string> FixturesCleanup;
std::set<std::string> FixturesRequired;
std::set<std::string> RequireSuccessDepends;
+ // Private test generator properties used to track backtraces
+ cmListFileBacktrace Backtrace;
};
struct cmCTestTestResult
@@ -141,9 +153,10 @@ public:
std::string Path;
std::string Reason;
std::string FullCommandLine;
- double ExecutionTime;
- int ReturnValue;
+ cmDuration ExecutionTime;
+ std::int64_t ReturnValue;
int Status;
+ std::string ExceptionStatus;
bool CompressOutput;
std::string CompletionStatus;
std::string Output;
@@ -182,15 +195,17 @@ protected:
virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
int ExecuteCommands(std::vector<std::string>& vec);
- void WriteTestResultHeader(cmXMLWriter& xml, cmCTestTestResult* result);
- void WriteTestResultFooter(cmXMLWriter& xml, cmCTestTestResult* result);
+ void WriteTestResultHeader(cmXMLWriter& xml,
+ cmCTestTestResult const& result);
+ void WriteTestResultFooter(cmXMLWriter& xml,
+ cmCTestTestResult const& result);
// Write attached test files into the xml
- void AttachFiles(cmXMLWriter& xml, cmCTestTestResult* result);
+ void AttachFiles(cmXMLWriter& xml, cmCTestTestResult& result);
//! Clean test output to specified length
bool CleanTestOutput(std::string& output, size_t length);
- double ElapsedTestingTime;
+ cmDuration ElapsedTestingTime;
typedef std::vector<cmCTestTestResult> TestResultsVector;
TestResultsVector TestResults;
@@ -198,8 +213,8 @@ protected:
std::vector<std::string> CustomTestsIgnore;
std::string StartTest;
std::string EndTest;
- unsigned int StartTestTime;
- unsigned int EndTestTime;
+ std::chrono::system_clock::time_point StartTestTime;
+ std::chrono::system_clock::time_point EndTestTime;
bool MemCheck;
int CustomMaximumPassedTestOutputSize;
int CustomMaximumFailedTestOutputSize;
@@ -226,7 +241,8 @@ private:
*/
virtual void GenerateDartOutput(cmXMLWriter& xml);
- void PrintLabelSummary();
+ void PrintLabelOrSubprojectSummary(bool isSubProject);
+
/**
* Run the tests for a directory and any subdirectories
*/
@@ -262,7 +278,7 @@ private:
*/
std::string FindTheExecutable(const char* exe);
- const char* GetTestStatus(int status);
+ std::string GetTestStatus(cmCTestTestResult const&);
void ExpandTestsToRunInformation(size_t numPossibleTests);
void ExpandTestsToRunInformationForRerunFailed();
diff --git a/Source/CTest/cmCTestUpdateCommand.cxx b/Source/CTest/cmCTestUpdateCommand.cxx
index 8c037545f..65dc9211a 100644
--- a/Source/CTest/cmCTestUpdateCommand.cxx
+++ b/Source/CTest/cmCTestUpdateCommand.cxx
@@ -3,7 +3,7 @@
#include "cmCTestUpdateCommand.h"
#include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
+#include "cmCTestUpdateHandler.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
@@ -62,6 +62,9 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
this->Makefile, "UpdateVersionOnly", "CTEST_UPDATE_VERSION_ONLY",
this->Quiet);
this->CTest->SetCTestConfigurationFromCMakeVariable(
+ this->Makefile, "UpdateVersionOverride", "CTEST_UPDATE_VERSION_OVERRIDE",
+ this->Quiet);
+ this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "HGCommand", "CTEST_HG_COMMAND", this->Quiet);
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "HGUpdateOptions", "CTEST_HG_UPDATE_OPTIONS", this->Quiet);
@@ -74,16 +77,12 @@ cmCTestGenericHandler* cmCTestUpdateCommand::InitializeHandler()
this->CTest->SetCTestConfigurationFromCMakeVariable(
this->Makefile, "P4Options", "CTEST_P4_OPTIONS", this->Quiet);
- cmCTestGenericHandler* handler =
- this->CTest->GetInitializedHandler("update");
- if (!handler) {
- this->SetError("internal CTest error. Cannot instantiate update handler");
- return CM_NULLPTR;
- }
+ cmCTestUpdateHandler* handler = this->CTest->GetUpdateHandler();
+ handler->Initialize();
handler->SetCommand(this);
if (source_dir.empty()) {
this->SetError("source directory not specified. Please use SOURCE tag");
- return CM_NULLPTR;
+ return nullptr;
}
handler->SetOption("SourceDirectory", source_dir.c_str());
handler->SetQuiet(this->Quiet);
diff --git a/Source/CTest/cmCTestUpdateCommand.h b/Source/CTest/cmCTestUpdateCommand.h
index 3b8f0a641..3b2f3e102 100644
--- a/Source/CTest/cmCTestUpdateCommand.h
+++ b/Source/CTest/cmCTestUpdateCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCTestUpdateCommand_h
#define cmCTestUpdateCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestHandlerCommand.h"
@@ -25,7 +25,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestUpdateCommand* ni = new cmCTestUpdateCommand;
ni->CTest = this->CTest;
@@ -36,10 +36,10 @@ public:
/**
* The name of the command as specified in CMakeList.txt.
*/
- std::string GetName() const CM_OVERRIDE { return "ctest_update"; }
+ std::string GetName() const override { return "ctest_update"; }
protected:
- cmCTestGenericHandler* InitializeHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeHandler() override;
};
#endif
diff --git a/Source/CTest/cmCTestUpdateHandler.cxx b/Source/CTest/cmCTestUpdateHandler.cxx
index e08a9b7bd..5cfc4a7cd 100644
--- a/Source/CTest/cmCTestUpdateHandler.cxx
+++ b/Source/CTest/cmCTestUpdateHandler.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestUpdateHandler.h"
+#include "cmAlgorithms.h"
#include "cmCLocaleEnvironmentScope.h"
#include "cmCTest.h"
#include "cmCTestBZR.h"
@@ -16,7 +17,8 @@
#include "cmVersion.h"
#include "cmXMLWriter.h"
-#include "cm_auto_ptr.hxx"
+#include <chrono>
+#include <memory> // IWYU pragma: keep
#include <sstream>
static const char* cmCTestUpdateHandlerUpdateStrings[] = {
@@ -32,20 +34,19 @@ static const char* cmCTestUpdateHandlerUpdateToString(int type)
return cmCTestUpdateHandlerUpdateStrings[type];
}
-cmCTestUpdateHandler::cmCTestUpdateHandler()
-{
-}
+cmCTestUpdateHandler::cmCTestUpdateHandler() = default;
void cmCTestUpdateHandler::Initialize()
{
this->Superclass::Initialize();
- this->UpdateCommand = "";
+ this->UpdateCommand.clear();
this->UpdateType = e_CVS;
}
int cmCTestUpdateHandler::DetermineType(const char* cmd, const char* type)
{
- cmCTestOptionalLog(this->CTest, DEBUG, "Determine update type from command: "
+ cmCTestOptionalLog(this->CTest, DEBUG,
+ "Determine update type from command: "
<< cmd << " and type: " << type << std::endl,
this->Quiet);
if (type && *type) {
@@ -128,34 +129,35 @@ int cmCTestUpdateHandler::ProcessHandler()
return -1;
}
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Use "
+ cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
+ " Use "
<< cmCTestUpdateHandlerUpdateToString(this->UpdateType)
<< " repository type" << std::endl;
, this->Quiet);
// Create an object to interact with the VCS tool.
- CM_AUTO_PTR<cmCTestVC> vc;
+ std::unique_ptr<cmCTestVC> vc;
switch (this->UpdateType) {
case e_CVS:
- vc.reset(new cmCTestCVS(this->CTest, ofs));
+ vc = cm::make_unique<cmCTestCVS>(this->CTest, ofs);
break;
case e_SVN:
- vc.reset(new cmCTestSVN(this->CTest, ofs));
+ vc = cm::make_unique<cmCTestSVN>(this->CTest, ofs);
break;
case e_BZR:
- vc.reset(new cmCTestBZR(this->CTest, ofs));
+ vc = cm::make_unique<cmCTestBZR>(this->CTest, ofs);
break;
case e_GIT:
- vc.reset(new cmCTestGIT(this->CTest, ofs));
+ vc = cm::make_unique<cmCTestGIT>(this->CTest, ofs);
break;
case e_HG:
- vc.reset(new cmCTestHG(this->CTest, ofs));
+ vc = cm::make_unique<cmCTestHG>(this->CTest, ofs);
break;
case e_P4:
- vc.reset(new cmCTestP4(this->CTest, ofs));
+ vc = cm::make_unique<cmCTestP4>(this->CTest, ofs);
break;
default:
- vc.reset(new cmCTestVC(this->CTest, ofs));
+ vc = cm::make_unique<cmCTestVC>(this->CTest, ofs);
break;
}
vc->SetCommandLineTool(this->UpdateCommand);
@@ -169,14 +171,13 @@ int cmCTestUpdateHandler::ProcessHandler()
//
cmGeneratedFileStream os;
if (!this->StartResultingXML(cmCTest::PartUpdate, "Update", os)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot open log file"
- << std::endl);
+ 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();
+ auto start_time_time = std::chrono::system_clock::now();
+ auto elapsed_time_start = std::chrono::steady_clock::now();
bool updated = vc->Update();
std::string buildname =
@@ -190,13 +191,18 @@ int cmCTestUpdateHandler::ProcessHandler()
std::string("ctest-") + cmVersion::GetCMakeVersion());
xml.Element("Site", this->CTest->GetCTestConfiguration("Site"));
xml.Element("BuildName", buildname);
- xml.Element("BuildStamp", this->CTest->GetCurrentTag() + "-" +
+ xml.Element("BuildStamp",
+ this->CTest->GetCurrentTag() + "-" +
this->CTest->GetTestModelString());
xml.Element("StartDateTime", start_time);
xml.Element("StartTime", start_time_time);
xml.Element("UpdateCommand", vc->GetUpdateCommandLine());
xml.Element("UpdateType",
cmCTestUpdateHandlerUpdateToString(this->UpdateType));
+ std::string changeId = this->CTest->GetCTestConfiguration("ChangeId");
+ if (!changeId.empty()) {
+ xml.Element("ChangeId", changeId);
+ }
bool loadedMods = vc->WriteXML(xml);
@@ -208,9 +214,9 @@ int cmCTestUpdateHandler::ProcessHandler()
this->Quiet);
}
if (int numModified = vc->GetPathCount(cmCTestVC::PathModified)) {
- cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Found "
- << numModified << " locally modified files\n",
- this->Quiet);
+ cmCTestOptionalLog(
+ this->CTest, HANDLER_OUTPUT,
+ " Found " << numModified << " locally modified files\n", this->Quiet);
localModifications += numModified;
}
if (int numConflicting = vc->GetPathCount(cmCTestVC::PathConflicting)) {
@@ -223,11 +229,11 @@ int cmCTestUpdateHandler::ProcessHandler()
cmCTestOptionalLog(this->CTest, DEBUG, "End" << std::endl, this->Quiet);
std::string end_time = this->CTest->CurrentTime();
xml.Element("EndDateTime", end_time);
- xml.Element("EndTime", static_cast<unsigned int>(cmSystemTools::GetTime()));
- xml.Element(
- "ElapsedMinutes",
- static_cast<int>((cmSystemTools::GetTime() - elapsed_time_start) / 6) /
- 10.0);
+ xml.Element("EndTime", std::chrono::system_clock::now());
+ xml.Element("ElapsedMinutes",
+ std::chrono::duration_cast<std::chrono::minutes>(
+ std::chrono::steady_clock::now() - elapsed_time_start)
+ .count());
xml.StartElement("UpdateReturnStatus");
if (localModifications) {
@@ -240,8 +246,9 @@ int cmCTestUpdateHandler::ProcessHandler()
if (!updated) {
xml.Content("Update command failed:\n");
xml.Content(vc->GetUpdateCommandLine());
- cmCTestLog(this->CTest, HANDLER_OUTPUT, " Update command failed: "
- << vc->GetUpdateCommandLine() << "\n");
+ cmCTestLog(this->CTest, HANDLER_OUTPUT,
+ " Update command failed: " << vc->GetUpdateCommandLine()
+ << "\n");
}
xml.EndElement(); // UpdateReturnStatus
xml.EndElement(); // Update
@@ -256,37 +263,37 @@ int cmCTestUpdateHandler::DetectVCS(const char* dir)
"Check directory: " << sourceDirectory << std::endl,
this->Quiet);
sourceDirectory += "/.svn";
- if (cmSystemTools::FileExists(sourceDirectory.c_str())) {
+ if (cmSystemTools::FileExists(sourceDirectory)) {
return cmCTestUpdateHandler::e_SVN;
}
sourceDirectory = dir;
sourceDirectory += "/CVS";
- if (cmSystemTools::FileExists(sourceDirectory.c_str())) {
+ if (cmSystemTools::FileExists(sourceDirectory)) {
return cmCTestUpdateHandler::e_CVS;
}
sourceDirectory = dir;
sourceDirectory += "/.bzr";
- if (cmSystemTools::FileExists(sourceDirectory.c_str())) {
+ if (cmSystemTools::FileExists(sourceDirectory)) {
return cmCTestUpdateHandler::e_BZR;
}
sourceDirectory = dir;
sourceDirectory += "/.git";
- if (cmSystemTools::FileExists(sourceDirectory.c_str())) {
+ if (cmSystemTools::FileExists(sourceDirectory)) {
return cmCTestUpdateHandler::e_GIT;
}
sourceDirectory = dir;
sourceDirectory += "/.hg";
- if (cmSystemTools::FileExists(sourceDirectory.c_str())) {
+ if (cmSystemTools::FileExists(sourceDirectory)) {
return cmCTestUpdateHandler::e_HG;
}
sourceDirectory = dir;
sourceDirectory += "/.p4";
- if (cmSystemTools::FileExists(sourceDirectory.c_str())) {
+ if (cmSystemTools::FileExists(sourceDirectory)) {
return cmCTestUpdateHandler::e_P4;
}
sourceDirectory = dir;
sourceDirectory += "/.p4config";
- if (cmSystemTools::FileExists(sourceDirectory.c_str())) {
+ if (cmSystemTools::FileExists(sourceDirectory)) {
return cmCTestUpdateHandler::e_P4;
}
return cmCTestUpdateHandler::e_UNKNOWN;
@@ -309,7 +316,7 @@ bool cmCTestUpdateHandler::SelectVCS()
// If no update command was specified, lookup one for this VCS tool.
if (this->UpdateCommand.empty()) {
- const char* key = CM_NULLPTR;
+ const char* key = nullptr;
switch (this->UpdateType) {
case e_CVS:
key = "CVSCommand";
diff --git a/Source/CTest/cmCTestUpdateHandler.h b/Source/CTest/cmCTestUpdateHandler.h
index 0cd284421..0f51d3f3e 100644
--- a/Source/CTest/cmCTestUpdateHandler.h
+++ b/Source/CTest/cmCTestUpdateHandler.h
@@ -3,7 +3,7 @@
#ifndef cmCTestUpdateHandler_h
#define cmCTestUpdateHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCTestGenericHandler.h"
@@ -23,7 +23,7 @@ public:
/*
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
cmCTestUpdateHandler();
@@ -42,7 +42,7 @@ public:
/**
* Initialize handler
*/
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
private:
// Some structures needed for update
diff --git a/Source/CTest/cmCTestUploadCommand.cxx b/Source/CTest/cmCTestUploadCommand.cxx
index 717117a5f..59fbf371c 100644
--- a/Source/CTest/cmCTestUploadCommand.cxx
+++ b/Source/CTest/cmCTestUploadCommand.cxx
@@ -6,22 +6,16 @@
#include <vector>
#include "cmCTest.h"
-#include "cmCTestGenericHandler.h"
#include "cmCTestUploadHandler.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
-#include "cmake.h"
cmCTestGenericHandler* cmCTestUploadCommand::InitializeHandler()
{
- cmCTestGenericHandler* handler =
- this->CTest->GetInitializedHandler("upload");
- if (!handler) {
- this->SetError("internal CTest error. Cannot instantiate upload handler");
- return CM_NULLPTR;
- }
- static_cast<cmCTestUploadHandler*>(handler)->SetFiles(this->Files);
-
+ cmCTestUploadHandler* handler = this->CTest->GetUploadHandler();
+ handler->Initialize();
+ handler->SetFiles(this->Files);
handler->SetQuiet(this->Quiet);
return handler;
}
@@ -51,14 +45,14 @@ bool cmCTestUploadCommand::CheckArgumentValue(std::string const& arg)
return true;
}
if (this->ArgumentDoing == ArgumentDoingFiles) {
- if (cmSystemTools::FileExists(arg.c_str())) {
+ if (cmSystemTools::FileExists(arg)) {
this->Files.insert(arg);
return true;
}
std::ostringstream e;
e << "File \"" << arg << "\" does not exist. Cannot submit "
<< "a non-existent file.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
this->ArgumentDoing = ArgumentDoingError;
return false;
}
diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h
index 6e721796a..0d3b06e43 100644
--- a/Source/CTest/cmCTestUploadCommand.h
+++ b/Source/CTest/cmCTestUploadCommand.h
@@ -3,11 +3,11 @@
#ifndef cmCTestUploadCommand_h
#define cmCTestUploadCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
-#include "cmCTest.h"
#include "cmCTestHandlerCommand.h"
+#include <set>
#include <string>
class cmCTestGenericHandler;
@@ -22,12 +22,10 @@ class cmCommand;
class cmCTestUploadCommand : public cmCTestHandlerCommand
{
public:
- cmCTestUploadCommand() {}
-
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmCTestUploadCommand* ni = new cmCTestUploadCommand;
ni->CTest = this->CTest;
@@ -38,15 +36,15 @@ public:
/**
* The name of the command as specified in CMakeList.txt.
*/
- std::string GetName() const CM_OVERRIDE { return "ctest_upload"; }
+ std::string GetName() const override { return "ctest_upload"; }
typedef cmCTestHandlerCommand Superclass;
protected:
- cmCTestGenericHandler* InitializeHandler() CM_OVERRIDE;
+ cmCTestGenericHandler* InitializeHandler() override;
- bool CheckArgumentKeyword(std::string const& arg) CM_OVERRIDE;
- bool CheckArgumentValue(std::string const& arg) CM_OVERRIDE;
+ bool CheckArgumentKeyword(std::string const& arg) override;
+ bool CheckArgumentValue(std::string const& arg) override;
enum
{
@@ -55,7 +53,7 @@ protected:
ArgumentDoingLast2
};
- cmCTest::SetOfStrings Files;
+ std::set<std::string> Files;
};
#endif
diff --git a/Source/CTest/cmCTestUploadHandler.cxx b/Source/CTest/cmCTestUploadHandler.cxx
index 05a39840d..9efdf70b8 100644
--- a/Source/CTest/cmCTestUploadHandler.cxx
+++ b/Source/CTest/cmCTestUploadHandler.cxx
@@ -2,12 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestUploadHandler.h"
+#include "cmCTest.h"
#include "cmGeneratedFileStream.h"
#include "cmVersion.h"
#include "cmXMLWriter.h"
#include <ostream>
-#include <set>
#include <string>
cmCTestUploadHandler::cmCTestUploadHandler()
@@ -21,7 +21,7 @@ void cmCTestUploadHandler::Initialize()
this->Files.clear();
}
-void cmCTestUploadHandler::SetFiles(const cmCTest::SetOfStrings& files)
+void cmCTestUploadHandler::SetFiles(std::set<std::string> const& files)
{
this->Files = files;
}
@@ -31,13 +31,12 @@ 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);
+ 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;
cmXMLWriter xml(ofs);
xml.StartDocument();
@@ -47,22 +46,23 @@ int cmCTestUploadHandler::ProcessHandler()
"<file:///Dart/Source/Server/XSL/Build.xsl> \"");
xml.StartElement("Site");
xml.Attribute("BuildName", buildname);
- xml.Attribute("BuildStamp", this->CTest->GetCurrentTag() + "-" +
+ xml.Attribute("BuildStamp",
+ this->CTest->GetCurrentTag() + "-" +
this->CTest->GetTestModelString());
xml.Attribute("Name", this->CTest->GetCTestConfiguration("Site"));
xml.Attribute("Generator",
- std::string("ctest") + cmVersion::GetCMakeVersion());
+ std::string("ctest-") + cmVersion::GetCMakeVersion());
this->CTest->AddSiteProperties(xml);
xml.StartElement("Upload");
- for (it = this->Files.begin(); it != this->Files.end(); it++) {
+ for (std::string const& file : this->Files) {
cmCTestOptionalLog(this->CTest, OUTPUT,
- "\tUpload file: " << *it << std::endl, this->Quiet);
+ "\tUpload file: " << file << std::endl, this->Quiet);
xml.StartElement("File");
- xml.Attribute("filename", *it);
+ xml.Attribute("filename", file);
xml.StartElement("Content");
xml.Attribute("encoding", "base64");
- xml.Content(this->CTest->Base64EncodeFile(*it));
+ xml.Content(this->CTest->Base64EncodeFile(file));
xml.EndElement(); // Content
xml.EndElement(); // File
}
diff --git a/Source/CTest/cmCTestUploadHandler.h b/Source/CTest/cmCTestUploadHandler.h
index 1e8d3c801..4d8fab487 100644
--- a/Source/CTest/cmCTestUploadHandler.h
+++ b/Source/CTest/cmCTestUploadHandler.h
@@ -3,11 +3,13 @@
#ifndef cmCTestUploadHandler_h
#define cmCTestUploadHandler_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
-#include "cmCTest.h"
#include "cmCTestGenericHandler.h"
+#include <set>
+#include <string>
+
/** \class cmCTestUploadHandler
* \brief Helper class for CTest
*
@@ -20,20 +22,19 @@ public:
typedef cmCTestGenericHandler Superclass;
cmCTestUploadHandler();
- ~cmCTestUploadHandler() CM_OVERRIDE {}
/*
* The main entry point for this class
*/
- int ProcessHandler() CM_OVERRIDE;
+ int ProcessHandler() override;
- void Initialize() CM_OVERRIDE;
+ void Initialize() override;
/** Specify a set of files to submit. */
- void SetFiles(cmCTest::SetOfStrings const& files);
+ void SetFiles(std::set<std::string> const& files);
private:
- cmCTest::SetOfStrings Files;
+ std::set<std::string> Files;
};
#endif
diff --git a/Source/CTest/cmCTestVC.cxx b/Source/CTest/cmCTestVC.cxx
index fb2742e08..eea41cf74 100644
--- a/Source/CTest/cmCTestVC.cxx
+++ b/Source/CTest/cmCTestVC.cxx
@@ -24,9 +24,7 @@ cmCTestVC::cmCTestVC(cmCTest* ct, std::ostream& log)
this->Unknown.Rev = "Unknown";
}
-cmCTestVC::~cmCTestVC()
-{
-}
+cmCTestVC::~cmCTestVC() = default;
void cmCTestVC::SetCommandLineTool(std::string const& tool)
{
@@ -47,7 +45,7 @@ bool cmCTestVC::InitialCheckout(const char* command)
std::string parent = cmSystemTools::GetFilenamePath(this->SourceDirectory);
cmCTestLog(this->CTest, HANDLER_OUTPUT,
" Perform checkout in directory: " << parent << "\n");
- if (!cmSystemTools::MakeDirectory(parent.c_str())) {
+ if (!cmSystemTools::MakeDirectory(parent)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot create directory: " << parent << std::endl);
return false;
@@ -56,11 +54,11 @@ bool cmCTestVC::InitialCheckout(const char* command)
// 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.reserve(args.size() + 1);
+ for (std::string const& arg : args) {
+ vc_co.push_back(arg.c_str());
}
- vc_co.push_back(CM_NULLPTR);
+ vc_co.push_back(nullptr);
// Run the initial checkout command and log its output.
this->Log << "--- Begin Initial Checkout ---\n";
@@ -69,8 +67,8 @@ bool cmCTestVC::InitialCheckout(const char* command)
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);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Initial checkout failed!" << std::endl);
}
return result;
}
@@ -79,13 +77,13 @@ bool cmCTestVC::RunChild(char const* const* cmd, OutputParser* out,
OutputParser* err, const char* workDir,
Encoding encoding)
{
- this->Log << this->ComputeCommandLine(cmd) << "\n";
+ this->Log << cmCTestVC::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, encoding);
+ cmCTestVC::RunProcess(cp, out, err, encoding);
int result = cmsysProcess_GetExitValue(cp);
cmsysProcess_Delete(cp);
return result == 0;
@@ -113,7 +111,7 @@ bool cmCTestVC::RunUpdateCommand(char const* const* cmd, OutputParser* out,
}
// Run the command.
- return this->RunChild(cmd, out, err, CM_NULLPTR, encoding);
+ return this->RunChild(cmd, out, err, nullptr, encoding);
}
std::string cmCTestVC::GetNightlyTime()
@@ -143,10 +141,19 @@ void cmCTestVC::CleanupImpl()
bool cmCTestVC::Update()
{
bool result = true;
+
+ // Use the explicitly specified version.
+ std::string versionOverride =
+ this->CTest->GetCTestConfiguration("UpdateVersionOverride");
+ if (!versionOverride.empty()) {
+ this->SetNewRevision(versionOverride);
+ return 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->CTest->GetCTestConfiguration("UpdateVersionOnly"))) {
result = this->NoteOldRevision() && result;
this->Log << "--- Begin Update ---\n";
result = this->UpdateImpl() && result;
@@ -168,6 +175,11 @@ bool cmCTestVC::NoteNewRevision()
return true;
}
+void cmCTestVC::SetNewRevision(std::string const& /*unused*/)
+{
+ // We do nothing by default.
+}
+
bool cmCTestVC::UpdateImpl()
{
cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
diff --git a/Source/CTest/cmCTestVC.h b/Source/CTest/cmCTestVC.h
index 6400bcda3..2a4765d28 100644
--- a/Source/CTest/cmCTestVC.h
+++ b/Source/CTest/cmCTestVC.h
@@ -3,7 +3,7 @@
#ifndef cmCTestVC_h
#define cmCTestVC_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -70,6 +70,7 @@ protected:
virtual bool NoteOldRevision();
virtual bool UpdateImpl();
virtual bool NoteNewRevision();
+ virtual void SetNewRevision(std::string const& revision);
virtual bool WriteXMLUpdates(cmXMLWriter& xml);
#if defined(__SUNPRO_CC) && __SUNPRO_CC <= 0x510
@@ -100,8 +101,8 @@ protected:
Revision const* PriorRev;
File()
: Status(PathUpdated)
- , Rev(CM_NULLPTR)
- , PriorRev(CM_NULLPTR)
+ , Rev(nullptr)
+ , PriorRev(nullptr)
{
}
File(PathStatus status, Revision const* rev, Revision const* priorRev)
@@ -117,12 +118,12 @@ protected:
/** Run a command line and send output to given parsers. */
bool RunChild(char const* const* cmd, OutputParser* out, OutputParser* err,
- const char* workDir = CM_NULLPTR,
+ const char* workDir = nullptr,
Encoding encoding = cmProcessOutput::Auto);
/** Run VC update command line and send output to given parsers. */
bool RunUpdateCommand(char const* const* cmd, OutputParser* out,
- OutputParser* err = CM_NULLPTR,
+ OutputParser* err = nullptr,
Encoding encoding = cmProcessOutput::Auto);
/** Write xml element for one file. */
diff --git a/Source/CTest/cmParseBlanketJSCoverage.cxx b/Source/CTest/cmParseBlanketJSCoverage.cxx
index 83a7b75eb..63d6a15d8 100644
--- a/Source/CTest/cmParseBlanketJSCoverage.cxx
+++ b/Source/CTest/cmParseBlanketJSCoverage.cxx
@@ -20,7 +20,7 @@ public:
{
}
- virtual ~JSONParser() {}
+ virtual ~JSONParser() = default;
std::string getValue(std::string const& line, int type)
{
@@ -112,17 +112,15 @@ cmParseBlanketJSCoverage::cmParseBlanketJSCoverage(
bool cmParseBlanketJSCoverage::LoadCoverageData(std::vector<std::string> files)
{
- size_t i = 0;
- std::string path;
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Found " << files.size() << " Files" << std::endl,
this->Coverage.Quiet);
- for (i = 0; i < files.size(); i++) {
+ for (std::string const& file : files) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
- "Reading JSON File " << files[i] << std::endl,
+ "Reading JSON File " << file << std::endl,
this->Coverage.Quiet);
- if (!this->ReadJSONFile(files[i])) {
+ if (!this->ReadJSONFile(file)) {
return false;
}
}
diff --git a/Source/CTest/cmParseCacheCoverage.cxx b/Source/CTest/cmParseCacheCoverage.cxx
index 629010cf1..ca1fe70e4 100644
--- a/Source/CTest/cmParseCacheCoverage.cxx
+++ b/Source/CTest/cmParseCacheCoverage.cxx
@@ -53,10 +53,8 @@ void cmParseCacheCoverage::RemoveUnCoveredFiles()
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) {
+ for (int i : v) {
+ if (i > 0) {
nothing = false;
break;
}
@@ -102,10 +100,11 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file)
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");
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Empty file : " << file
+ << " referenced in this line of cmcov data:\n"
+ "["
+ << line << "]\n");
return false;
}
separateLine.clear();
@@ -114,8 +113,9 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file)
separateLine[1] != "Line" || separateLine[2] != "RtnLine" ||
separateLine[3] != "Code") {
cmCTestLog(this->CTest, ERROR_MESSAGE,
- "Bad first line of cmcov file : " << file << " line:\n"
- "["
+ "Bad first line of cmcov file : " << file
+ << " line:\n"
+ "["
<< line << "]\n");
}
std::string routine;
@@ -130,8 +130,9 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file)
if (separateLine.size() < 4) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Bad line of cmcov file expected at least 4 found: "
- << separateLine.size() << " " << file << " line:\n"
- "["
+ << 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] << " ");
@@ -148,7 +149,7 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file)
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Could not find mumps file for routine: " << routine
<< "\n");
- filepath = "";
+ filepath.clear();
continue; // move to next line
}
}
@@ -156,8 +157,8 @@ bool cmParseCacheCoverage::ReadCMCovFile(const char* file)
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 = "";
+ routine.clear(); // at the end of this routine
+ filepath.clear();
continue; // move to next line
}
}
diff --git a/Source/CTest/cmParseCacheCoverage.h b/Source/CTest/cmParseCacheCoverage.h
index 005d27258..081f5fa13 100644
--- a/Source/CTest/cmParseCacheCoverage.h
+++ b/Source/CTest/cmParseCacheCoverage.h
@@ -3,7 +3,7 @@
#ifndef cmParseCacheCoverage_h
#define cmParseCacheCoverage_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmParseMumpsCoverage.h"
@@ -26,7 +26,7 @@ public:
protected:
// implement virtual from parent
- bool LoadCoverageData(const char* dir) CM_OVERRIDE;
+ bool LoadCoverageData(const char* dir) override;
// remove files with no coverage
void RemoveUnCoveredFiles();
// Read a single mcov file
diff --git a/Source/CTest/cmParseCoberturaCoverage.cxx b/Source/CTest/cmParseCoberturaCoverage.cxx
index ba55cd7b2..848a034c9 100644
--- a/Source/CTest/cmParseCoberturaCoverage.cxx
+++ b/Source/CTest/cmParseCoberturaCoverage.cxx
@@ -5,7 +5,6 @@
#include "cmSystemTools.h"
#include "cmXMLParser.h"
-#include "cmConfigure.h"
#include "cmsys/FStream.hxx"
#include <stdlib.h>
#include <string.h>
@@ -14,21 +13,14 @@ class cmParseCoberturaCoverage::XMLParser : public cmXMLParser
{
public:
XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont)
- : CTest(ctest)
+ : FilePaths{ cont.SourceDir, cont.BinaryDir }
+ , CTest(ctest)
, Coverage(cont)
{
- this->InSources = false;
- this->InSource = false;
- this->SkipThisClass = false;
- this->FilePaths.push_back(this->Coverage.SourceDir);
- this->FilePaths.push_back(this->Coverage.BinaryDir);
- this->CurFileName = "";
}
- ~XMLParser() CM_OVERRIDE {}
-
protected:
- void EndElement(const std::string& name) CM_OVERRIDE
+ void EndElement(const std::string& name) override
{
if (name == "source") {
this->InSource = false;
@@ -39,7 +31,7 @@ protected:
}
}
- void CharacterDataHandler(const char* data, int length) CM_OVERRIDE
+ void CharacterDataHandler(const char* data, int length) override
{
std::string tmp;
tmp.insert(0, data, length);
@@ -51,7 +43,7 @@ protected:
}
}
- void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** atts) override
{
std::string FoundSource;
std::string finalpath;
@@ -68,23 +60,23 @@ protected:
<< std::endl,
this->Coverage.Quiet);
std::string filename = atts[tagCount + 1];
- this->CurFileName = "";
+ this->CurFileName.clear();
// Check if this is an absolute path that falls within our
// source or binary directories.
- for (size_t i = 0; i < FilePaths.size(); i++) {
- if (filename.find(FilePaths[i]) == 0) {
+ for (std::string const& filePath : FilePaths) {
+ if (filename.find(filePath) == 0) {
this->CurFileName = filename;
break;
}
}
- if (this->CurFileName == "") {
+ if (this->CurFileName.empty()) {
// Check if this is a path that is relative to our source or
// binary directories.
- for (size_t i = 0; i < FilePaths.size(); i++) {
- finalpath = FilePaths[i] + "/" + filename;
- if (cmSystemTools::FileExists(finalpath.c_str())) {
+ for (std::string const& filePath : FilePaths) {
+ finalpath = filePath + "/" + filename;
+ if (cmSystemTools::FileExists(finalpath)) {
this->CurFileName = finalpath;
break;
}
@@ -92,7 +84,7 @@ protected:
}
cmsys::ifstream fin(this->CurFileName.c_str());
- if (this->CurFileName == "" || !fin) {
+ if (this->CurFileName.empty() || !fin) {
this->CurFileName =
this->Coverage.BinaryDir + "/" + atts[tagCount + 1];
fin.open(this->CurFileName.c_str());
@@ -145,9 +137,9 @@ protected:
}
private:
- bool InSources;
- bool InSource;
- bool SkipThisClass;
+ bool InSources = false;
+ bool InSource = false;
+ bool SkipThisClass = false;
std::vector<std::string> FilePaths;
typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector
FileLinesType;
diff --git a/Source/CTest/cmParseDelphiCoverage.cxx b/Source/CTest/cmParseDelphiCoverage.cxx
index 4b781a6db..9eda6f8f3 100644
--- a/Source/CTest/cmParseDelphiCoverage.cxx
+++ b/Source/CTest/cmParseDelphiCoverage.cxx
@@ -20,7 +20,7 @@ public:
{
}
- virtual ~HTMLParser() {}
+ virtual ~HTMLParser() = default;
bool initializeDelphiFile(
std::string const& filename,
@@ -44,7 +44,7 @@ public:
// Check that the begin is the first non-space string on the line
if ((beginPos == line.find_first_not_of(' ')) &&
beginPos != std::string::npos) {
- beginSet.push_back("begin");
+ beginSet.emplace_back("begin");
coverageVector.push_back(-1);
continue;
}
@@ -71,7 +71,8 @@ public:
}
}
// Based up what was found, add a line to the coverageVector
- if (!beginSet.empty() && line != "" && !blockComFlag && !lineComFlag) {
+ if (!beginSet.empty() && !line.empty() && !blockComFlag &&
+ !lineComFlag) {
coverageVector.push_back(0);
} else {
coverageVector.push_back(-1);
@@ -107,8 +108,9 @@ public:
while (true) {
lastoffset = line.find('(', pos);
if (lastoffset == std::string::npos) {
- cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, endnamepos
- << "File not found " << lastoffset << std::endl,
+ cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ endnamepos << "File not found " << lastoffset
+ << std::endl,
this->Coverage.Quiet);
return false;
}
diff --git a/Source/CTest/cmParseGTMCoverage.cxx b/Source/CTest/cmParseGTMCoverage.cxx
index e4ee699c4..072275372 100644
--- a/Source/CTest/cmParseGTMCoverage.cxx
+++ b/Source/CTest/cmParseGTMCoverage.cxx
@@ -1,5 +1,6 @@
#include "cmParseGTMCoverage.h"
+#include "cmAlgorithms.h"
#include "cmCTest.h"
#include "cmCTestCoverageHandler.h"
#include "cmSystemTools.h"
@@ -75,7 +76,8 @@ bool cmParseGTMCoverage::ReadMCovFile(const char* file)
this->Coverage.TotalCoverage[lastpath][lastoffset + linenumber] +=
count;
} else {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Can not find mumps file : "
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Can not find mumps file : "
<< lastroutine
<< " referenced in this line of mcov data:\n"
"["
@@ -85,6 +87,10 @@ bool cmParseGTMCoverage::ReadMCovFile(const char* file)
}
// Find the full path to the file
bool found = this->FindMumpsFile(routine, filepath);
+ if (!found && cmHasLiteralSuffix(routine, "%")) {
+ routine.erase(0, 1);
+ found = this->FindMumpsFile(routine, filepath);
+ }
if (found) {
int lineoffset = 0;
if (this->FindFunctionInMumpsFile(filepath, function, lineoffset)) {
@@ -93,7 +99,7 @@ bool cmParseGTMCoverage::ReadMCovFile(const char* file)
// 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.
+ // into the executable code set in addition to the count found.
if (coverageVector[lineoffset + linenumber] == -1 && count > 0) {
coverageVector[lineoffset + linenumber] += count + 1;
} else {
@@ -102,9 +108,11 @@ bool cmParseGTMCoverage::ReadMCovFile(const char* file)
lastoffset = lineoffset;
}
} else {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Can not find mumps file : "
- << routine << " referenced in this line of mcov data:\n"
- "["
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Can not find mumps file : "
+ << routine
+ << " referenced in this line of mcov data:\n"
+ "["
<< line << "]\n");
}
lastfunction = function;
@@ -144,8 +152,9 @@ bool cmParseGTMCoverage::FindFunctionInMumpsFile(std::string const& filepath,
linenum++; // move to next line count
}
lineoffset = 0;
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Could not find entry point : "
- << function << " in " << filepath << "\n");
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Could not find entry point : " << function << " in " << filepath
+ << "\n");
return false;
}
@@ -156,7 +165,7 @@ bool cmParseGTMCoverage::ParseMCOVLine(std::string const& line,
{
// this method parses lines from the .mcov file
// each line has ^COVERAGE(...) in it, and there
- // are several varients of coverage lines:
+ // are several variants of coverage lines:
//
// ^COVERAGE("DIC11","PR1",0)="2:0:0:0"
// ( file , entry, line ) = "number_executed:timing_info"
@@ -182,14 +191,14 @@ bool cmParseGTMCoverage::ParseMCOVLine(std::string const& line,
// save the argument into the argument vector
args.push_back(arg);
// start on a new argument
- arg = "";
+ arg.clear();
// 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 != '%') {
+ // all chars except " and ( get stored in the arg string
+ if (cur != '\"' && cur != '(') {
arg.append(1, line[pos]);
}
}
@@ -221,8 +230,8 @@ bool cmParseGTMCoverage::ParseMCOVLine(std::string const& line,
}
// less then two arguments is an error
if (args.size() < 2) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Error parsing mcov line: ["
- << line << "]\n");
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Error parsing mcov line: [" << line << "]\n");
return false;
}
routine = args[0]; // the routine is the first argument
@@ -233,8 +242,8 @@ bool cmParseGTMCoverage::ParseMCOVLine(std::string const& line,
// 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 = "";
+ routine.clear();
+ function.clear();
} else {
// this is the format for this line
// ^COVERAGE("%RSEL","SRC",count)
diff --git a/Source/CTest/cmParseGTMCoverage.h b/Source/CTest/cmParseGTMCoverage.h
index c4949d416..13afbbc26 100644
--- a/Source/CTest/cmParseGTMCoverage.h
+++ b/Source/CTest/cmParseGTMCoverage.h
@@ -3,7 +3,7 @@
#ifndef cmParseGTMCoverage_h
#define cmParseGTMCoverage_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmParseMumpsCoverage.h"
@@ -25,7 +25,7 @@ public:
protected:
// implement virtual from parent
- bool LoadCoverageData(const char* dir) CM_OVERRIDE;
+ bool LoadCoverageData(const char* dir) override;
// Read a single mcov file
bool ReadMCovFile(const char* f);
// find out what line in a mumps file (filepath) the given entry point
diff --git a/Source/CTest/cmParseJacocoCoverage.cxx b/Source/CTest/cmParseJacocoCoverage.cxx
index d15864a79..b78142a81 100644
--- a/Source/CTest/cmParseJacocoCoverage.cxx
+++ b/Source/CTest/cmParseJacocoCoverage.cxx
@@ -1,7 +1,5 @@
#include "cmParseJacocoCoverage.h"
-#include "cmConfigure.h"
-
#include "cmCTest.h"
#include "cmCTestCoverageHandler.h"
#include "cmSystemTools.h"
@@ -20,28 +18,25 @@ public:
: CTest(ctest)
, Coverage(cont)
{
- this->FilePath = "";
- this->PackagePath = "";
- this->PackageName = "";
}
- ~XMLParser() CM_OVERRIDE {}
-
protected:
- void EndElement(const std::string& /*name*/) CM_OVERRIDE {}
+ void EndElement(const std::string& /*name*/) override {}
- void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
+ void StartElement(const std::string& name, const char** atts) override
{
if (name == "package") {
this->PackageName = atts[1];
- this->PackagePath = "";
+ this->PackagePath.clear();
} else if (name == "sourcefile") {
+ this->FilePath.clear();
std::string fileName = atts[1];
- if (this->PackagePath == "") {
+ if (this->PackagePath.empty()) {
if (!this->FindPackagePath(fileName)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find file: "
- << this->PackageName << "/" << fileName << std::endl);
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Cannot find file: " << this->PackageName << "/"
+ << fileName << std::endl);
this->Coverage.Error++;
return;
}
@@ -121,9 +116,8 @@ protected:
}
// Check if any of the locations found match our package.
- for (std::vector<std::string>::const_iterator fi = files.begin();
- fi != files.end(); ++fi) {
- std::string dir = cmsys::SystemTools::GetParentDirectory(*fi);
+ for (std::string const& f : files) {
+ std::string dir = cmsys::SystemTools::GetParentDirectory(f);
if (cmsys::SystemTools::StringEndsWith(dir, this->PackageName.c_str())) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Found package directory for " << fileName << ": "
diff --git a/Source/CTest/cmParseMumpsCoverage.cxx b/Source/CTest/cmParseMumpsCoverage.cxx
index eb29f55c0..4a81ee4f7 100644
--- a/Source/CTest/cmParseMumpsCoverage.cxx
+++ b/Source/CTest/cmParseMumpsCoverage.cxx
@@ -4,7 +4,6 @@
#include "cmCTestCoverageHandler.h"
#include "cmSystemTools.h"
-#include "cmConfigure.h"
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include <map>
@@ -19,9 +18,7 @@ cmParseMumpsCoverage::cmParseMumpsCoverage(
{
}
-cmParseMumpsCoverage::~cmParseMumpsCoverage()
-{
-}
+cmParseMumpsCoverage::~cmParseMumpsCoverage() = default;
bool cmParseMumpsCoverage::ReadCoverageFile(const char* file)
{
@@ -113,14 +110,12 @@ bool cmParseMumpsCoverage::LoadPackages(const char* d)
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
+ for (std::string& file : glob.GetFiles()) {
+ std::string name = cmSystemTools::GetFilenameName(file);
+ this->RoutineToDirectory[name.substr(0, name.size() - 2)] = file;
+ // initialize each file, this is left out until CDash is fixed
// to handle large numbers of files
- this->InitializeMumpsFile(*fileIt);
+ this->InitializeMumpsFile(file);
}
return true;
}
@@ -135,8 +130,8 @@ bool cmParseMumpsCoverage::FindMumpsFile(std::string const& routine,
return true;
}
// try some alternate names
- const char* tryname[] = { "GUX", "GTM", "ONT", CM_NULLPTR };
- for (int k = 0; tryname[k] != CM_NULLPTR; k++) {
+ const char* tryname[] = { "GUX", "GTM", "ONT", nullptr };
+ for (int k = 0; tryname[k] != nullptr; k++) {
std::string routine2 = routine + tryname[k];
i = this->RoutineToDirectory.find(routine2);
if (i != this->RoutineToDirectory.end()) {
diff --git a/Source/CTest/cmParsePHPCoverage.cxx b/Source/CTest/cmParsePHPCoverage.cxx
index 761ebec65..a6e65c9df 100644
--- a/Source/CTest/cmParsePHPCoverage.cxx
+++ b/Source/CTest/cmParsePHPCoverage.cxx
@@ -153,7 +153,8 @@ bool cmParsePHPCoverage::ReadFileInformation(std::istream& in)
delete[] s;
// read close quote
if (in.get(c) && c != '"') {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "failed to read close quote\n"
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "failed to read close quote\n"
<< "read [" << c << "]\n");
return false;
}
@@ -184,8 +185,8 @@ bool cmParsePHPCoverage::ReadPHPData(const char* file)
}
for (int i = 0; i < size; i++) {
if (!this->ReadFileInformation(in)) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Failed to read file #" << i
- << "\n");
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Failed to read file #" << i << "\n");
return false;
}
in.get(c);
diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx
index f4ec6da29..7a3b82e61 100644
--- a/Source/CTest/cmProcess.cxx
+++ b/Source/CTest/cmProcess.cxx
@@ -2,26 +2,37 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmProcess.h"
-#include "cmConfigure.h"
-#include "cmProcessOutput.h"
-#include "cmSystemTools.h"
+#include "cmAlgorithms.h"
+#include "cmCTest.h"
+#include "cmCTestRunTest.h"
+#include "cmCTestTestHandler.h"
+#include "cmGetPipes.h"
+#include "cmsys/Process.h"
+
#include <iostream>
+#include <signal.h>
+#include <string>
+#if defined(_WIN32)
+# include "cm_kwiml.h"
+#endif
+#include <utility>
+
+#define CM_PROCESS_BUF_SIZE 65536
-cmProcess::cmProcess()
+cmProcess::cmProcess(cmCTestRunTest& runner)
+ : Runner(runner)
+ , Conv(cmProcessOutput::UTF8, CM_PROCESS_BUF_SIZE)
{
- this->Process = CM_NULLPTR;
- this->Timeout = 0;
- this->TotalTime = 0;
+ this->Timeout = cmDuration::zero();
+ this->TotalTime = cmDuration::zero();
this->ExitValue = 0;
this->Id = 0;
- this->StartTime = 0;
+ this->StartTime = std::chrono::steady_clock::time_point();
}
-cmProcess::~cmProcess()
-{
- cmsysProcess_Delete(this->Process);
-}
-void cmProcess::SetCommand(const char* command)
+cmProcess::~cmProcess() = default;
+
+void cmProcess::SetCommand(std::string const& command)
{
this->Command = command;
}
@@ -31,32 +42,121 @@ void cmProcess::SetCommandArguments(std::vector<std::string> const& args)
this->Arguments = args;
}
-bool cmProcess::StartProcess()
+void cmProcess::SetWorkingDirectory(std::string const& dir)
{
+ this->WorkingDirectory = dir;
+}
+
+bool cmProcess::StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity)
+{
+ this->ProcessState = cmProcess::State::Error;
if (this->Command.empty()) {
return false;
}
- this->StartTime = cmSystemTools::GetTime();
+ this->StartTime = std::chrono::steady_clock::now();
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());
+ for (std::string const& arg : this->Arguments) {
+ this->ProcessArgs.push_back(arg.c_str());
+ }
+ this->ProcessArgs.push_back(nullptr); // null terminate the list
+
+ cm::uv_timer_ptr timer;
+ int status = timer.init(loop, this);
+ if (status != 0) {
+ cmCTestLog(this->Runner.GetCTest(), ERROR_MESSAGE,
+ "Error initializing timer: " << uv_strerror(status)
+ << std::endl);
+ return false;
+ }
+
+ cm::uv_pipe_ptr pipe_writer;
+ cm::uv_pipe_ptr pipe_reader;
+
+ pipe_writer.init(loop, 0);
+ pipe_reader.init(loop, 0, this);
+
+ int fds[2] = { -1, -1 };
+ status = cmGetPipes(fds);
+ if (status != 0) {
+ cmCTestLog(this->Runner.GetCTest(), ERROR_MESSAGE,
+ "Error initializing pipe: " << uv_strerror(status)
+ << std::endl);
+ return false;
+ }
+
+ uv_pipe_open(pipe_reader, fds[0]);
+ uv_pipe_open(pipe_writer, fds[1]);
+
+ uv_stdio_container_t stdio[3];
+ stdio[0].flags = UV_INHERIT_FD;
+ stdio[0].data.fd = 0;
+ stdio[1].flags = UV_INHERIT_STREAM;
+ stdio[1].data.stream = pipe_writer;
+ stdio[2] = stdio[1];
+
+ uv_process_options_t options = uv_process_options_t();
+ options.file = this->Command.data();
+ options.args = const_cast<char**>(this->ProcessArgs.data());
+ options.stdio_count = 3; // in, out and err
+ options.exit_cb = &cmProcess::OnExitCB;
+ options.stdio = stdio;
+#if !defined(CMAKE_USE_SYSTEM_LIBUV)
+ std::vector<char> cpumask;
+ if (affinity && !affinity->empty()) {
+ cpumask.resize(static_cast<size_t>(uv_cpumask_size()), 0);
+ for (auto p : *affinity) {
+ cpumask[p] = 1;
+ }
+ options.cpumask = cpumask.data();
+ options.cpumask_size = cpumask.size();
+ } else {
+ options.cpumask = nullptr;
+ options.cpumask_size = 0;
+ }
+#else
+ static_cast<void>(affinity);
+#endif
+
+ status =
+ uv_read_start(pipe_reader, &cmProcess::OnAllocateCB, &cmProcess::OnReadCB);
+
+ if (status != 0) {
+ cmCTestLog(this->Runner.GetCTest(), ERROR_MESSAGE,
+ "Error starting read events: " << uv_strerror(status)
+ << std::endl);
+ return false;
}
- this->ProcessArgs.push_back(CM_NULLPTR); // null terminate the list
- this->Process = cmsysProcess_New();
- cmsysProcess_SetCommand(this->Process, &*this->ProcessArgs.begin());
- if (!this->WorkingDirectory.empty()) {
- cmsysProcess_SetWorkingDirectory(this->Process,
- this->WorkingDirectory.c_str());
+
+ status = this->Process.spawn(loop, options, this);
+ if (status != 0) {
+ cmCTestLog(this->Runner.GetCTest(), ERROR_MESSAGE,
+ "Process not started\n " << this->Command << "\n["
+ << uv_strerror(status) << "]\n");
+ return false;
+ }
+
+ this->PipeReader = std::move(pipe_reader);
+ this->Timer = std::move(timer);
+
+ this->StartTimer();
+
+ this->ProcessState = cmProcess::State::Executing;
+ return true;
+}
+
+void cmProcess::StartTimer()
+{
+ auto properties = this->Runner.GetTestProperties();
+ auto msec =
+ std::chrono::duration_cast<std::chrono::milliseconds>(this->Timeout);
+
+ if (msec != std::chrono::milliseconds(0) || !properties->ExplicitTimeout) {
+ this->Timer.start(&cmProcess::OnTimeoutCB,
+ static_cast<uint64_t>(msec.count()), 0);
}
- cmsysProcess_SetTimeout(this->Process, this->Timeout);
- cmsysProcess_SetOption(this->Process, cmsysProcess_Option_MergeOutput, 1);
- cmsysProcess_Execute(this->Process);
- return (cmsysProcess_GetState(this->Process) ==
- cmsysProcess_State_Executing);
}
bool cmProcess::Buffer::GetLine(std::string& line)
@@ -65,7 +165,7 @@ bool cmProcess::Buffer::GetLine(std::string& line)
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;
+ const char* text = this->data() + this->First;
size_type length = this->Last - this->First;
while (length && text[length - 1] == '\r') {
length--;
@@ -95,7 +195,7 @@ bool cmProcess::Buffer::GetLast(std::string& line)
{
// Return the partial last line, if any.
if (!this->empty()) {
- line.assign(&*this->begin(), this->size());
+ line.assign(this->data(), this->size());
this->First = this->Last = 0;
this->clear();
return true;
@@ -103,140 +203,500 @@ bool cmProcess::Buffer::GetLast(std::string& line)
return false;
}
-int cmProcess::GetNextOutputLine(std::string& line, double timeout)
+void cmProcess::OnReadCB(uv_stream_t* stream, ssize_t nread,
+ const uv_buf_t* buf)
{
- cmProcessOutput processOutput(cmProcessOutput::UTF8);
- std::string strdata;
- for (;;) {
- // Look for lines already buffered.
- if (this->Output.GetLine(line)) {
- return cmsysProcess_Pipe_STDOUT;
- }
+ auto self = static_cast<cmProcess*>(stream->data);
+ self->OnRead(nread, buf);
+}
- // 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;
- }
- if (p == cmsysProcess_Pipe_STDOUT) {
- processOutput.DecodeText(data, length, strdata);
- this->Output.insert(this->Output.end(), strdata.begin(), strdata.end());
- } else { // p == cmsysProcess_Pipe_None
- // The process will provide no more data.
- break;
+void cmProcess::OnRead(ssize_t nread, const uv_buf_t* buf)
+{
+ std::string line;
+ if (nread > 0) {
+ std::string strdata;
+ this->Conv.DecodeText(buf->base, static_cast<size_t>(nread), strdata);
+ cmAppend(this->Output, strdata);
+
+ while (this->Output.GetLine(line)) {
+ this->Runner.CheckOutput(line);
+ line.clear();
}
+
+ return;
+ }
+
+ if (nread == 0) {
+ return;
}
- processOutput.DecodeText(std::string(), strdata);
- if (!strdata.empty()) {
- this->Output.insert(this->Output.end(), strdata.begin(), strdata.end());
+
+ // The process will provide no more data.
+ if (nread != UV_EOF) {
+ auto error = static_cast<int>(nread);
+ cmCTestLog(this->Runner.GetCTest(), ERROR_MESSAGE,
+ "Error reading stream: " << uv_strerror(error) << std::endl);
}
// Look for partial last lines.
if (this->Output.GetLast(line)) {
- return cmsysProcess_Pipe_STDOUT;
+ this->Runner.CheckOutput(line);
}
- // No more data. Wait for process exit.
- if (!cmsysProcess_WaitForExit(this->Process, &timeout)) {
- return cmsysProcess_Pipe_Timeout;
+ this->ReadHandleClosed = true;
+ this->PipeReader.reset();
+ if (this->ProcessHandleClosed) {
+ uv_timer_stop(this->Timer);
+ this->Runner.FinalizeTest();
+ }
+}
+
+void cmProcess::OnAllocateCB(uv_handle_t* handle, size_t suggested_size,
+ uv_buf_t* buf)
+{
+ auto self = static_cast<cmProcess*>(handle->data);
+ self->OnAllocate(suggested_size, buf);
+}
+
+void cmProcess::OnAllocate(size_t /*suggested_size*/, uv_buf_t* buf)
+{
+ if (this->Buf.size() != CM_PROCESS_BUF_SIZE) {
+ this->Buf.resize(CM_PROCESS_BUF_SIZE);
+ }
+
+ *buf =
+ uv_buf_init(this->Buf.data(), static_cast<unsigned int>(this->Buf.size()));
+}
+
+void cmProcess::OnTimeoutCB(uv_timer_t* timer)
+{
+ auto self = static_cast<cmProcess*>(timer->data);
+ self->OnTimeout();
+}
+
+void cmProcess::OnTimeout()
+{
+ if (this->ProcessState != cmProcess::State::Executing) {
+ return;
+ }
+ this->ProcessState = cmProcess::State::Expired;
+ bool const was_still_reading = !this->ReadHandleClosed;
+ if (!this->ReadHandleClosed) {
+ this->ReadHandleClosed = true;
+ this->PipeReader.reset();
+ }
+ if (!this->ProcessHandleClosed) {
+ // Kill the child and let our on-exit handler finish the test.
+ cmsysProcess_KillPID(static_cast<unsigned long>(this->Process->pid));
+ } else if (was_still_reading) {
+ // Our on-exit handler already ran but did not finish the test
+ // because we were still reading output. We've just dropped
+ // our read handler, so we need to finish the test now.
+ this->Runner.FinalizeTest();
+ }
+}
+
+void cmProcess::OnExitCB(uv_process_t* process, int64_t exit_status,
+ int term_signal)
+{
+ auto self = static_cast<cmProcess*>(process->data);
+ self->OnExit(exit_status, term_signal);
+}
+
+void cmProcess::OnExit(int64_t exit_status, int term_signal)
+{
+ if (this->ProcessState != cmProcess::State::Expired) {
+ if (
+#if defined(_WIN32)
+ ((DWORD)exit_status & 0xF0000000) == 0xC0000000
+#else
+ term_signal != 0
+#endif
+ ) {
+ this->ProcessState = cmProcess::State::Exception;
+ } else {
+ this->ProcessState = cmProcess::State::Exited;
+ }
}
// Record exit information.
- this->ExitValue = cmsysProcess_GetExitValue(this->Process);
- this->TotalTime = cmSystemTools::GetTime() - this->StartTime;
+ this->ExitValue = exit_status;
+ this->Signal = term_signal;
+ this->TotalTime = std::chrono::steady_clock::now() - 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;
-}
-
-void cmProcess::ChangeTimeout(double t)
+ if (this->TotalTime <= cmDuration::zero()) {
+ this->TotalTime = cmDuration::zero();
+ }
+
+ this->ProcessHandleClosed = true;
+ if (this->ReadHandleClosed) {
+ uv_timer_stop(this->Timer);
+ this->Runner.FinalizeTest();
+ }
+}
+
+cmProcess::State cmProcess::GetProcessStatus()
+{
+ return this->ProcessState;
+}
+
+void cmProcess::ChangeTimeout(cmDuration t)
{
this->Timeout = t;
- cmsysProcess_SetTimeout(this->Process, this->Timeout);
+ this->StartTimer();
}
void cmProcess::ResetStartTime()
{
- cmsysProcess_ResetStartTime(this->Process);
- this->StartTime = cmSystemTools::GetTime();
+ this->StartTime = std::chrono::steady_clock::now();
}
-int cmProcess::GetExitException()
+cmProcess::Exception cmProcess::GetExitException()
{
- return cmsysProcess_GetExitException(this->Process);
+ auto exception = Exception::None;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ auto exit_code = (DWORD)this->ExitValue;
+ if ((exit_code & 0xF0000000) != 0xC0000000) {
+ return exception;
+ }
+
+ if (exit_code) {
+ switch (exit_code) {
+ case STATUS_DATATYPE_MISALIGNMENT:
+ case STATUS_ACCESS_VIOLATION:
+ case STATUS_IN_PAGE_ERROR:
+ case STATUS_INVALID_HANDLE:
+ case STATUS_NONCONTINUABLE_EXCEPTION:
+ case STATUS_INVALID_DISPOSITION:
+ case STATUS_ARRAY_BOUNDS_EXCEEDED:
+ case STATUS_STACK_OVERFLOW:
+ exception = Exception::Fault;
+ break;
+ case STATUS_FLOAT_DENORMAL_OPERAND:
+ case STATUS_FLOAT_DIVIDE_BY_ZERO:
+ case STATUS_FLOAT_INEXACT_RESULT:
+ case STATUS_FLOAT_INVALID_OPERATION:
+ case STATUS_FLOAT_OVERFLOW:
+ case STATUS_FLOAT_STACK_CHECK:
+ case STATUS_FLOAT_UNDERFLOW:
+# ifdef STATUS_FLOAT_MULTIPLE_FAULTS
+ case STATUS_FLOAT_MULTIPLE_FAULTS:
+# endif
+# ifdef STATUS_FLOAT_MULTIPLE_TRAPS
+ case STATUS_FLOAT_MULTIPLE_TRAPS:
+# endif
+ case STATUS_INTEGER_DIVIDE_BY_ZERO:
+ case STATUS_INTEGER_OVERFLOW:
+ exception = Exception::Numerical;
+ break;
+ case STATUS_CONTROL_C_EXIT:
+ exception = Exception::Interrupt;
+ break;
+ case STATUS_ILLEGAL_INSTRUCTION:
+ case STATUS_PRIVILEGED_INSTRUCTION:
+ exception = Exception::Illegal;
+ break;
+ default:
+ exception = Exception::Other;
+ }
+ }
+#else
+ if (this->Signal) {
+ switch (this->Signal) {
+ case SIGSEGV:
+ exception = Exception::Fault;
+ break;
+ case SIGFPE:
+ exception = Exception::Numerical;
+ break;
+ case SIGINT:
+ exception = Exception::Interrupt;
+ break;
+ case SIGILL:
+ exception = Exception::Illegal;
+ break;
+ default:
+ exception = Exception::Other;
+ }
+ }
+#endif
+ return exception;
+}
+
+std::string cmProcess::GetExitExceptionString()
+{
+ std::string exception_str;
+#if defined(_WIN32)
+ switch (this->ExitValue) {
+ case STATUS_CONTROL_C_EXIT:
+ exception_str = "User interrupt";
+ break;
+ case STATUS_FLOAT_DENORMAL_OPERAND:
+ exception_str = "Floating-point exception (denormal operand)";
+ break;
+ case STATUS_FLOAT_DIVIDE_BY_ZERO:
+ exception_str = "Divide-by-zero";
+ break;
+ case STATUS_FLOAT_INEXACT_RESULT:
+ exception_str = "Floating-point exception (inexact result)";
+ break;
+ case STATUS_FLOAT_INVALID_OPERATION:
+ exception_str = "Invalid floating-point operation";
+ break;
+ case STATUS_FLOAT_OVERFLOW:
+ exception_str = "Floating-point overflow";
+ break;
+ case STATUS_FLOAT_STACK_CHECK:
+ exception_str = "Floating-point stack check failed";
+ break;
+ case STATUS_FLOAT_UNDERFLOW:
+ exception_str = "Floating-point underflow";
+ break;
+# ifdef STATUS_FLOAT_MULTIPLE_FAULTS
+ case STATUS_FLOAT_MULTIPLE_FAULTS:
+ exception_str = "Floating-point exception (multiple faults)";
+ break;
+# endif
+# ifdef STATUS_FLOAT_MULTIPLE_TRAPS
+ case STATUS_FLOAT_MULTIPLE_TRAPS:
+ exception_str = "Floating-point exception (multiple traps)";
+ break;
+# endif
+ case STATUS_INTEGER_DIVIDE_BY_ZERO:
+ exception_str = "Integer divide-by-zero";
+ break;
+ case STATUS_INTEGER_OVERFLOW:
+ exception_str = "Integer overflow";
+ break;
+
+ case STATUS_DATATYPE_MISALIGNMENT:
+ exception_str = "Datatype misalignment";
+ break;
+ case STATUS_ACCESS_VIOLATION:
+ exception_str = "Access violation";
+ break;
+ case STATUS_IN_PAGE_ERROR:
+ exception_str = "In-page error";
+ break;
+ case STATUS_INVALID_HANDLE:
+ exception_str = "Invalid handle";
+ break;
+ case STATUS_NONCONTINUABLE_EXCEPTION:
+ exception_str = "Noncontinuable exception";
+ break;
+ case STATUS_INVALID_DISPOSITION:
+ exception_str = "Invalid disposition";
+ break;
+ case STATUS_ARRAY_BOUNDS_EXCEEDED:
+ exception_str = "Array bounds exceeded";
+ break;
+ case STATUS_STACK_OVERFLOW:
+ exception_str = "Stack overflow";
+ break;
+
+ case STATUS_ILLEGAL_INSTRUCTION:
+ exception_str = "Illegal instruction";
+ break;
+ case STATUS_PRIVILEGED_INSTRUCTION:
+ exception_str = "Privileged instruction";
+ break;
+ case STATUS_NO_MEMORY:
+ default:
+ char buf[1024];
+ const char* fmt = "Exit code 0x%" KWIML_INT_PRIx64 "\n";
+ _snprintf(buf, 1024, fmt, this->ExitValue);
+ exception_str.assign(buf);
+ }
+#else
+ switch (this->Signal) {
+# ifdef SIGSEGV
+ case SIGSEGV:
+ exception_str = "Segmentation fault";
+ break;
+# endif
+# ifdef SIGBUS
+# if !defined(SIGSEGV) || SIGBUS != SIGSEGV
+ case SIGBUS:
+ exception_str = "Bus error";
+ break;
+# endif
+# endif
+# ifdef SIGFPE
+ case SIGFPE:
+ exception_str = "Floating-point exception";
+ break;
+# endif
+# ifdef SIGILL
+ case SIGILL:
+ exception_str = "Illegal instruction";
+ break;
+# endif
+# ifdef SIGINT
+ case SIGINT:
+ exception_str = "User interrupt";
+ break;
+# endif
+# ifdef SIGABRT
+ case SIGABRT:
+ exception_str = "Child aborted";
+ break;
+# endif
+# ifdef SIGKILL
+ case SIGKILL:
+ exception_str = "Child killed";
+ break;
+# endif
+# ifdef SIGTERM
+ case SIGTERM:
+ exception_str = "Child terminated";
+ break;
+# endif
+# ifdef SIGHUP
+ case SIGHUP:
+ exception_str = "SIGHUP";
+ break;
+# endif
+# ifdef SIGQUIT
+ case SIGQUIT:
+ exception_str = "SIGQUIT";
+ break;
+# endif
+# ifdef SIGTRAP
+ case SIGTRAP:
+ exception_str = "SIGTRAP";
+ break;
+# endif
+# ifdef SIGIOT
+# if !defined(SIGABRT) || SIGIOT != SIGABRT
+ case SIGIOT:
+ exception_str = "SIGIOT";
+ break;
+# endif
+# endif
+# ifdef SIGUSR1
+ case SIGUSR1:
+ exception_str = "SIGUSR1";
+ break;
+# endif
+# ifdef SIGUSR2
+ case SIGUSR2:
+ exception_str = "SIGUSR2";
+ break;
+# endif
+# ifdef SIGPIPE
+ case SIGPIPE:
+ exception_str = "SIGPIPE";
+ break;
+# endif
+# ifdef SIGALRM
+ case SIGALRM:
+ exception_str = "SIGALRM";
+ break;
+# endif
+# ifdef SIGSTKFLT
+ case SIGSTKFLT:
+ exception_str = "SIGSTKFLT";
+ break;
+# endif
+# ifdef SIGCHLD
+ case SIGCHLD:
+ exception_str = "SIGCHLD";
+ break;
+# elif defined(SIGCLD)
+ case SIGCLD:
+ exception_str = "SIGCLD";
+ break;
+# endif
+# ifdef SIGCONT
+ case SIGCONT:
+ exception_str = "SIGCONT";
+ break;
+# endif
+# ifdef SIGSTOP
+ case SIGSTOP:
+ exception_str = "SIGSTOP";
+ break;
+# endif
+# ifdef SIGTSTP
+ case SIGTSTP:
+ exception_str = "SIGTSTP";
+ break;
+# endif
+# ifdef SIGTTIN
+ case SIGTTIN:
+ exception_str = "SIGTTIN";
+ break;
+# endif
+# ifdef SIGTTOU
+ case SIGTTOU:
+ exception_str = "SIGTTOU";
+ break;
+# endif
+# ifdef SIGURG
+ case SIGURG:
+ exception_str = "SIGURG";
+ break;
+# endif
+# ifdef SIGXCPU
+ case SIGXCPU:
+ exception_str = "SIGXCPU";
+ break;
+# endif
+# ifdef SIGXFSZ
+ case SIGXFSZ:
+ exception_str = "SIGXFSZ";
+ break;
+# endif
+# ifdef SIGVTALRM
+ case SIGVTALRM:
+ exception_str = "SIGVTALRM";
+ break;
+# endif
+# ifdef SIGPROF
+ case SIGPROF:
+ exception_str = "SIGPROF";
+ break;
+# endif
+# ifdef SIGWINCH
+ case SIGWINCH:
+ exception_str = "SIGWINCH";
+ break;
+# endif
+# ifdef SIGPOLL
+ case SIGPOLL:
+ exception_str = "SIGPOLL";
+ break;
+# endif
+# ifdef SIGIO
+# if !defined(SIGPOLL) || SIGIO != SIGPOLL
+ case SIGIO:
+ exception_str = "SIGIO";
+ break;
+# endif
+# endif
+# ifdef SIGPWR
+ case SIGPWR:
+ exception_str = "SIGPWR";
+ break;
+# endif
+# ifdef SIGSYS
+ case SIGSYS:
+ exception_str = "SIGSYS";
+ break;
+# endif
+# ifdef SIGUNUSED
+# if !defined(SIGSYS) || SIGUNUSED != SIGSYS
+ case SIGUNUSED:
+ exception_str = "SIGUNUSED";
+ break;
+# endif
+# endif
+ default:
+ exception_str = "Signal ";
+ exception_str += std::to_string(this->Signal);
+ }
+#endif
+ return exception_str;
}
diff --git a/Source/CTest/cmProcess.h b/Source/CTest/cmProcess.h
index 86e905aca..a0a4b6b20 100644
--- a/Source/CTest/cmProcess.h
+++ b/Source/CTest/cmProcess.h
@@ -4,11 +4,20 @@
#define cmProcess_h
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmDuration.h"
-#include "cmsys/Process.h"
+#include "cmProcessOutput.h"
+#include "cmUVHandlePtr.h"
+#include "cm_uv.h"
+
+#include <chrono>
+#include <stddef.h>
+#include <stdint.h>
#include <string>
#include <vector>
+class cmCTestRunTest;
+
/** \class cmProcess
* \brief run a process with c++
*
@@ -17,41 +26,80 @@
class cmProcess
{
public:
- cmProcess();
+ explicit cmProcess(cmCTestRunTest& runner);
~cmProcess();
- const char* GetCommand() { return this->Command.c_str(); }
- void SetCommand(const char* command);
+ void SetCommand(std::string const& command);
void SetCommandArguments(std::vector<std::string> const& arg);
- void SetWorkingDirectory(const char* dir) { this->WorkingDirectory = dir; }
- void SetTimeout(double t) { this->Timeout = t; }
- void ChangeTimeout(double t);
+ void SetWorkingDirectory(std::string const& dir);
+ void SetTimeout(cmDuration t) { this->Timeout = t; }
+ void ChangeTimeout(cmDuration t);
void ResetStartTime();
// Return true if the process starts
- bool StartProcess();
+ bool StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity);
+
+ enum class State
+ {
+ Starting,
+ Error,
+ Exception,
+ Executing,
+ Exited,
+ Expired,
+ Killed,
+ Disowned
+ };
- // return the process status
- int GetProcessStatus();
- // Report the status of the program
- int ReportStatus();
+ State GetProcessStatus();
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 or stderr
- * cmsysProcess_Pipe_Timeout = Timeout expired while waiting
- */
- int GetNextOutputLine(std::string& line, double timeout);
+ int64_t GetExitValue() { return this->ExitValue; }
+ cmDuration GetTotalTime() { return this->TotalTime; }
+
+ enum class Exception
+ {
+ None,
+ Fault,
+ Illegal,
+ Interrupt,
+ Numerical,
+ Other
+ };
+
+ Exception GetExitException();
+ std::string GetExitExceptionString();
private:
- double Timeout;
- double StartTime;
- double TotalTime;
- cmsysProcess* Process;
+ cmDuration Timeout;
+ std::chrono::steady_clock::time_point StartTime;
+ cmDuration TotalTime;
+ bool ReadHandleClosed = false;
+ bool ProcessHandleClosed = false;
+
+ cm::uv_process_ptr Process;
+ cm::uv_pipe_ptr PipeReader;
+ cm::uv_timer_ptr Timer;
+ std::vector<char> Buf;
+
+ cmCTestRunTest& Runner;
+ cmProcessOutput Conv;
+ int Signal = 0;
+ cmProcess::State ProcessState = cmProcess::State::Starting;
+
+ static void OnExitCB(uv_process_t* process, int64_t exit_status,
+ int term_signal);
+ static void OnTimeoutCB(uv_timer_t* timer);
+ static void OnReadCB(uv_stream_t* stream, ssize_t nread,
+ const uv_buf_t* buf);
+ static void OnAllocateCB(uv_handle_t* handle, size_t suggested_size,
+ uv_buf_t* buf);
+
+ void OnExit(int64_t exit_status, int term_signal);
+ void OnTimeout();
+ void OnRead(ssize_t nread, const uv_buf_t* buf);
+ void OnAllocate(size_t suggested_size, uv_buf_t* buf);
+
+ void StartTimer();
+
class Buffer : public std::vector<char>
{
// Half-open index range of partial line already scanned.
@@ -73,7 +121,7 @@ private:
std::vector<std::string> Arguments;
std::vector<const char*> ProcessArgs;
int Id;
- int ExitValue;
+ int64_t ExitValue;
};
#endif
diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake
index 3b0802579..fb68ed78c 100644
--- a/Source/Checks/cm_cxx_features.cmake
+++ b/Source/Checks/cm_cxx_features.cmake
@@ -14,10 +14,20 @@ function(cm_check_cxx_feature name)
CMAKE_FLAGS ${maybe_cxx_standard}
OUTPUT_VARIABLE OUTPUT
)
+ set(check_output "${OUTPUT}")
# Filter out MSBuild output that looks like a warning.
- string(REGEX REPLACE " +0 Warning\\(s\\)" "" check_output "${OUTPUT}")
+ string(REGEX REPLACE " +0 Warning\\(s\\)" "" check_output "${check_output}")
+ # Filter out warnings caused by user flags.
+ string(REGEX REPLACE "[^\n]*warning:[^\n]*-Winvalid-command-line-argument[^\n]*" "" check_output "${check_output}")
+ # Filter out warnings caused by local configuration.
+ string(REGEX REPLACE "[^\n]*warning:[^\n]*directory not found for option[^\n]*" "" check_output "${check_output}")
+ string(REGEX REPLACE "[^\n]*warning:[^\n]*object file compiled with -mlong-branch which is no longer needed[^\n]*" "" check_output "${check_output}")
+ # Filter out other warnings unrelated to feature checks.
+ string(REGEX REPLACE "[^\n]*warning:[^\n]*sprintf\\(\\) is often misused, please use snprintf[^\n]*" "" check_output "${check_output}")
+ # Filter out xcodebuild warnings.
+ string(REGEX REPLACE "[^\n]* xcodebuild\\[[0-9]*:[0-9]*\\] warning: [^\n]*" "" check_output "${check_output}")
# If using the feature causes warnings, treat it as broken/unavailable.
- if(check_output MATCHES "[Ww]arning")
+ if(check_output MATCHES "(^|[ :])[Ww][Aa][Rr][Nn][Ii][Nn][Gg]")
set(CMake_HAVE_CXX_${FEATURE} OFF CACHE INTERNAL "TRY_COMPILE" FORCE)
endif()
if(CMake_HAVE_CXX_${FEATURE})
@@ -38,21 +48,8 @@ function(cm_check_cxx_feature name)
endif()
endfunction()
-cm_check_cxx_feature(auto_ptr)
-cm_check_cxx_feature(eq_delete)
-cm_check_cxx_feature(fallthrough)
-if(NOT CMake_HAVE_CXX_FALLTHROUGH)
- cm_check_cxx_feature(gnu_fallthrough)
- if(NOT CMake_HAVE_CXX_GNU_FALLTHROUGH)
- cm_check_cxx_feature(attribute_fallthrough)
- endif()
-endif()
cm_check_cxx_feature(make_unique)
if(CMake_HAVE_CXX_MAKE_UNIQUE)
set(CMake_HAVE_CXX_UNIQUE_PTR 1)
endif()
-cm_check_cxx_feature(nullptr)
-cm_check_cxx_feature(override)
cm_check_cxx_feature(unique_ptr)
-cm_check_cxx_feature(unordered_map)
-cm_check_cxx_feature(unordered_set)
diff --git a/Source/CursesDialog/CMakeLists.txt b/Source/CursesDialog/CMakeLists.txt
index c5ac1f1a6..c51b0dd0e 100644
--- a/Source/CursesDialog/CMakeLists.txt
+++ b/Source/CursesDialog/CMakeLists.txt
@@ -2,25 +2,21 @@
# file Copyright.txt or https://cmake.org/licensing for details.
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
+ CursesDialog/cmCursesOptionsWidget.cxx
+ CursesDialog/cmCursesBoolWidget.cxx
+ CursesDialog/cmCursesCacheEntryComposite.cxx
+ CursesDialog/cmCursesDummyWidget.cxx
+ CursesDialog/cmCursesFilePathWidget.cxx
+ CursesDialog/cmCursesForm.cxx
+ CursesDialog/cmCursesLabelWidget.cxx
+ CursesDialog/cmCursesLongMessageForm.cxx
+ CursesDialog/cmCursesMainForm.cxx
+ CursesDialog/cmCursesPathWidget.cxx
+ CursesDialog/cmCursesStringWidget.cxx
+ CursesDialog/cmCursesWidget.cxx
+ CursesDialog/ccmake.cxx
)
-if( NOT CMAKE_USE_SYSTEM_FORM )
- include_directories(${CMake_SOURCE_DIR}/Source/CursesDialog/form
- ${CMake_BINARY_DIR}/Source/CursesDialog/form)
-endif()
include_directories(${CURSES_INCLUDE_PATH})
diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx
index 28a0e95b9..7caed0cd5 100644
--- a/Source/CursesDialog/ccmake.cxx
+++ b/Source/CursesDialog/ccmake.cxx
@@ -1,12 +1,12 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
-#include "cmConfigure.h"
#include "cmCursesForm.h"
#include "cmCursesMainForm.h"
#include "cmCursesStandardIncludes.h"
#include "cmDocumentation.h"
-#include "cmDocumentationEntry.h"
+#include "cmDocumentationEntry.h" // IWYU pragma: keep
+#include "cmState.h"
#include "cmSystemTools.h"
#include "cmake.h"
@@ -18,30 +18,32 @@
#include <vector>
static const char* cmDocumentationName[][2] = {
- { CM_NULLPTR, " ccmake - Curses Interface for CMake." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, " ccmake - Curses Interface for CMake." },
+ { nullptr, nullptr }
};
static const char* cmDocumentationUsage[][2] = {
- { CM_NULLPTR, " ccmake <path-to-source>\n"
- " ccmake <path-to-existing-build>" },
- { CM_NULLPTR,
+ { nullptr,
+ " ccmake <path-to-source>\n"
+ " ccmake <path-to-existing-build>" },
+ { nullptr,
"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." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, nullptr }
};
static const char* cmDocumentationUsageNote[][2] = {
- { CM_NULLPTR, "Run 'ccmake --help' for more information." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, "Run 'ccmake --help' for more information." },
+ { nullptr, nullptr }
};
-static const char* cmDocumentationOptions[]
- [2] = { CMAKE_STANDARD_OPTIONS_TABLE,
- { CM_NULLPTR, CM_NULLPTR } };
+static const char* cmDocumentationOptions[][2] = {
+ CMAKE_STANDARD_OPTIONS_TABLE,
+ { nullptr, nullptr }
+};
-cmCursesForm* cmCursesForm::CurrentForm = CM_NULLPTR;
+cmCursesForm* cmCursesForm::CurrentForm = nullptr;
extern "C" {
@@ -63,37 +65,31 @@ void onsig(int /*unused*/)
}
}
-void CMakeMessageHandler(const char* message, const char* title,
- bool& /*unused*/, void* clientData)
-{
- cmCursesForm* self = static_cast<cmCursesForm*>(clientData);
- self->AddError(message, title);
-}
-
int main(int argc, char const* const* argv)
{
+ cmSystemTools::EnsureStdPipes();
cmsys::Encoding::CommandLineArguments encoding_args =
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
argc = encoding_args.argc();
argv = encoding_args.argv();
+ cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv[0]);
cmDocumentation doc;
doc.addCMakeStandardDocSections();
if (doc.CheckOptions(argc, argv)) {
- cmake hcm(cmake::RoleInternal);
+ cmake hcm(cmake::RoleInternal, cmState::Unknown);
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
hcm.AddCMakePaths();
- std::vector<cmDocumentationEntry> generators;
- hcm.GetGeneratorDocumentation(generators);
+ auto generators = hcm.GetGeneratorsDocumentation();
doc.SetName("ccmake");
doc.SetSection("Name", cmDocumentationName);
doc.SetSection("Usage", cmDocumentationUsage);
if (argc == 1) {
doc.AppendSection("Usage", cmDocumentationUsageNote);
}
- doc.SetSection("Generators", generators);
+ doc.AppendSection("Generators", generators);
doc.PrependSection("Options", cmDocumentationOptions);
return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1;
}
@@ -106,7 +102,7 @@ int main(int argc, char const* const* argv)
if (strcmp(argv[j], "-debug") == 0) {
debug = true;
} else {
- args.push_back(argv[j]);
+ args.emplace_back(argv[j]);
}
}
@@ -154,7 +150,10 @@ int main(int argc, char const* const* argv)
return 1;
}
- cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
+ cmSystemTools::SetMessageCallback(
+ [myform](const std::string& message, const char* title) {
+ myform->AddError(message, title);
+ });
cmCursesForm::CurrentForm = myform;
@@ -169,7 +168,7 @@ int main(int argc, char const* const* argv)
touchwin(stdscr);
endwin();
delete cmCursesForm::CurrentForm;
- cmCursesForm::CurrentForm = CM_NULLPTR;
+ cmCursesForm::CurrentForm = nullptr;
std::cout << std::endl << std::endl;
diff --git a/Source/CursesDialog/cmCursesBoolWidget.h b/Source/CursesDialog/cmCursesBoolWidget.h
index 90bcc2209..8c9625635 100644
--- a/Source/CursesDialog/cmCursesBoolWidget.h
+++ b/Source/CursesDialog/cmCursesBoolWidget.h
@@ -3,7 +3,7 @@
#ifndef cmCursesBoolWidget_h
#define cmCursesBoolWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmCursesWidget.h"
@@ -12,16 +12,17 @@ class cmCursesMainForm;
class cmCursesBoolWidget : public cmCursesWidget
{
- CM_DISABLE_COPY(cmCursesBoolWidget)
-
public:
cmCursesBoolWidget(int width, int height, int left, int top);
+ cmCursesBoolWidget(cmCursesBoolWidget const&) = delete;
+ cmCursesBoolWidget& operator=(cmCursesBoolWidget const&) = delete;
+
// Description:
// Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was
// handled.
- bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
+ bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override;
// Description:
// Set/Get the value (on/off).
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
index d071c9178..c1dd591e0 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
@@ -25,7 +25,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
{
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
- this->Entry = CM_NULLPTR;
+ this->Entry = nullptr;
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
}
@@ -43,7 +43,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
}
- this->Entry = CM_NULLPTR;
+ this->Entry = nullptr;
const char* value = cm->GetState()->GetCacheEntryValue(key);
assert(value);
switch (cm->GetState()->GetCacheEntryType(key)) {
@@ -72,9 +72,8 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
this->Entry = ow;
std::vector<std::string> options;
cmSystemTools::ExpandListArgument(stringsProp, options);
- for (std::vector<std::string>::iterator si = options.begin();
- si != options.end(); ++si) {
- ow->AddOption(*si);
+ for (auto const& opt : options) {
+ ow->AddOption(opt);
}
ow->SetOption(value);
} else {
@@ -84,7 +83,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
break;
}
case cmStateEnums::UNINITIALIZED:
- cmSystemTools::Error("Found an undefined variable: ", key.c_str());
+ cmSystemTools::Error("Found an undefined variable: " + key);
break;
default:
// TODO : put warning message here
@@ -104,5 +103,5 @@ const char* cmCursesCacheEntryComposite::GetValue()
if (this->Label) {
return this->Label->GetValue();
}
- return CM_NULLPTR;
+ return nullptr;
}
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.h b/Source/CursesDialog/cmCursesCacheEntryComposite.h
index 3c500785d..0a69d3a9b 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.h
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.h
@@ -3,7 +3,7 @@
#ifndef cmCursesCacheEntryComposite_h
#define cmCursesCacheEntryComposite_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -13,14 +13,17 @@ class cmake;
class cmCursesCacheEntryComposite
{
- CM_DISABLE_COPY(cmCursesCacheEntryComposite)
-
public:
cmCursesCacheEntryComposite(const std::string& key, int labelwidth,
int entrywidth);
cmCursesCacheEntryComposite(const std::string& key, cmake* cm, bool isNew,
int labelwidth, int entrywidth);
~cmCursesCacheEntryComposite();
+
+ cmCursesCacheEntryComposite(cmCursesCacheEntryComposite const&) = delete;
+ cmCursesCacheEntryComposite& operator=(cmCursesCacheEntryComposite const&) =
+ delete;
+
const char* GetValue();
friend class cmCursesMainForm;
diff --git a/Source/CursesDialog/cmCursesDummyWidget.h b/Source/CursesDialog/cmCursesDummyWidget.h
index d9bb6babc..07b7288ab 100644
--- a/Source/CursesDialog/cmCursesDummyWidget.h
+++ b/Source/CursesDialog/cmCursesDummyWidget.h
@@ -3,7 +3,7 @@
#ifndef cmCursesDummyWidget_h
#define cmCursesDummyWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmCursesWidget.h"
@@ -12,16 +12,17 @@ class cmCursesMainForm;
class cmCursesDummyWidget : public cmCursesWidget
{
- CM_DISABLE_COPY(cmCursesDummyWidget)
-
public:
cmCursesDummyWidget(int width, int height, int left, int top);
+ cmCursesDummyWidget(cmCursesDummyWidget const&) = delete;
+ cmCursesDummyWidget& operator=(cmCursesDummyWidget const&) = delete;
+
// Description:
// Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was
// handled.
- bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
+ bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override;
};
#endif // cmCursesDummyWidget_h
diff --git a/Source/CursesDialog/cmCursesFilePathWidget.h b/Source/CursesDialog/cmCursesFilePathWidget.h
index 6ad535b99..3f71259d5 100644
--- a/Source/CursesDialog/cmCursesFilePathWidget.h
+++ b/Source/CursesDialog/cmCursesFilePathWidget.h
@@ -3,16 +3,17 @@
#ifndef cmCursesFilePathWidget_h
#define cmCursesFilePathWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesPathWidget.h"
class cmCursesFilePathWidget : public cmCursesPathWidget
{
- CM_DISABLE_COPY(cmCursesFilePathWidget)
-
public:
cmCursesFilePathWidget(int width, int height, int left, int top);
+
+ cmCursesFilePathWidget(cmCursesFilePathWidget const&) = delete;
+ cmCursesFilePathWidget& operator=(cmCursesFilePathWidget const&) = delete;
};
#endif // cmCursesFilePathWidget_h
diff --git a/Source/CursesDialog/cmCursesForm.cxx b/Source/CursesDialog/cmCursesForm.cxx
index 06c1e9c70..bd65c4a08 100644
--- a/Source/CursesDialog/cmCursesForm.cxx
+++ b/Source/CursesDialog/cmCursesForm.cxx
@@ -7,7 +7,7 @@ bool cmCursesForm::Debug = false;
cmCursesForm::cmCursesForm()
{
- this->Form = CM_NULLPTR;
+ this->Form = nullptr;
}
cmCursesForm::~cmCursesForm()
@@ -15,7 +15,7 @@ cmCursesForm::~cmCursesForm()
if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
- this->Form = CM_NULLPTR;
+ this->Form = nullptr;
}
}
diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h
index 553105c76..78429059e 100644
--- a/Source/CursesDialog/cmCursesForm.h
+++ b/Source/CursesDialog/cmCursesForm.h
@@ -3,20 +3,23 @@
#ifndef cmCursesForm_h
#define cmCursesForm_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmsys/FStream.hxx"
+#include <string>
+
class cmCursesForm
{
- CM_DISABLE_COPY(cmCursesForm)
-
public:
cmCursesForm();
virtual ~cmCursesForm();
+ cmCursesForm(cmCursesForm const&) = delete;
+ cmCursesForm& operator=(cmCursesForm const&) = delete;
+
// Description:
// Handle user input.
virtual void HandleInput() = 0;
@@ -33,7 +36,7 @@ public:
// Description:
// During a CMake run, an error handle should add errors
// to be displayed afterwards.
- virtual void AddError(const char*, const char*) {}
+ virtual void AddError(const std::string&, const char*) {}
// Description:
// Turn debugging on. This will create ccmakelog.txt.
diff --git a/Source/CursesDialog/cmCursesLabelWidget.cxx b/Source/CursesDialog/cmCursesLabelWidget.cxx
index 1dfd4ce47..83aea5a2c 100644
--- a/Source/CursesDialog/cmCursesLabelWidget.cxx
+++ b/Source/CursesDialog/cmCursesLabelWidget.cxx
@@ -14,9 +14,7 @@ cmCursesLabelWidget::cmCursesLabelWidget(int width, int height, int left,
this->SetValue(name);
}
-cmCursesLabelWidget::~cmCursesLabelWidget()
-{
-}
+cmCursesLabelWidget::~cmCursesLabelWidget() = default;
bool cmCursesLabelWidget::HandleInput(int& /*key*/, cmCursesMainForm* /*fm*/,
WINDOW* /*w*/)
diff --git a/Source/CursesDialog/cmCursesLabelWidget.h b/Source/CursesDialog/cmCursesLabelWidget.h
index 267de7c8c..2ee9cfca8 100644
--- a/Source/CursesDialog/cmCursesLabelWidget.h
+++ b/Source/CursesDialog/cmCursesLabelWidget.h
@@ -3,7 +3,7 @@
#ifndef cmCursesLabelWidget_h
#define cmCursesLabelWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmCursesWidget.h"
@@ -14,18 +14,19 @@ class cmCursesMainForm;
class cmCursesLabelWidget : public cmCursesWidget
{
- CM_DISABLE_COPY(cmCursesLabelWidget)
-
public:
cmCursesLabelWidget(int width, int height, int left, int top,
const std::string& name);
- ~cmCursesLabelWidget() CM_OVERRIDE;
+ ~cmCursesLabelWidget() override;
+
+ cmCursesLabelWidget(cmCursesLabelWidget const&) = delete;
+ cmCursesLabelWidget& operator=(cmCursesLabelWidget const&) = delete;
// Description:
// Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was
// handled
- bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
+ bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override;
};
#endif // cmCursesLabelWidget_h
diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx
index 7fb065d30..4e887d68f 100644
--- a/Source/CursesDialog/cmCursesLongMessageForm.cxx
+++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx
@@ -19,15 +19,14 @@ 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);
+ for (std::string const& message : messages) {
+ this->Messages += message;
// Add one blank line after each message
this->Messages += "\n\n";
}
this->Title = title;
- this->Fields[0] = CM_NULLPTR;
- this->Fields[1] = CM_NULLPTR;
+ this->Fields[0] = nullptr;
+ this->Fields[1] = nullptr;
}
cmCursesLongMessageForm::~cmCursesLongMessageForm()
@@ -43,7 +42,7 @@ void cmCursesLongMessageForm::UpdateStatusBar()
getmaxyx(stdscr, y, x);
char bar[cmCursesMainForm::MAX_WIDTH];
- size_t size = strlen(this->Title.c_str());
+ size_t size = this->Title.size();
if (size >= cmCursesMainForm::MAX_WIDTH) {
size = cmCursesMainForm::MAX_WIDTH - 1;
}
@@ -105,7 +104,7 @@ void cmCursesLongMessageForm::Render(int /*left*/, int /*top*/, int /*width*/,
if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
- this->Form = CM_NULLPTR;
+ this->Form = nullptr;
}
const char* msg = this->Messages.c_str();
@@ -114,7 +113,7 @@ void cmCursesLongMessageForm::Render(int /*left*/, int /*top*/, int /*width*/,
if (this->Fields[0]) {
free_field(this->Fields[0]);
- this->Fields[0] = CM_NULLPTR;
+ this->Fields[0] = nullptr;
}
this->Fields[0] = new_field(y - 6, x - 2, 1, 1, 0, 0);
diff --git a/Source/CursesDialog/cmCursesLongMessageForm.h b/Source/CursesDialog/cmCursesLongMessageForm.h
index cd8e0953a..466b4e1b0 100644
--- a/Source/CursesDialog/cmCursesLongMessageForm.h
+++ b/Source/CursesDialog/cmCursesLongMessageForm.h
@@ -3,7 +3,7 @@
#ifndef cmCursesLongMessageForm_h
#define cmCursesLongMessageForm_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesForm.h"
#include "cmCursesStandardIncludes.h"
@@ -13,21 +13,22 @@
class cmCursesLongMessageForm : public cmCursesForm
{
- CM_DISABLE_COPY(cmCursesLongMessageForm)
-
public:
cmCursesLongMessageForm(std::vector<std::string> const& messages,
const char* title);
- ~cmCursesLongMessageForm() CM_OVERRIDE;
+ ~cmCursesLongMessageForm() override;
+
+ cmCursesLongMessageForm(cmCursesLongMessageForm const&) = delete;
+ cmCursesLongMessageForm& operator=(cmCursesLongMessageForm const&) = delete;
// Description:
// Handle user input.
- void HandleInput() CM_OVERRIDE;
+ void HandleInput() override;
// Description:
// Display form. Use a window of size width x height, starting
// at top, left.
- void Render(int left, int top, int width, int height) CM_OVERRIDE;
+ void Render(int left, int top, int width, int height) override;
// Description:
// This method should normally called only by the form.
@@ -37,7 +38,7 @@ public:
// Description:
// This method should normally called only by the form.
// The only exception is during a resize.
- void UpdateStatusBar() CM_OVERRIDE;
+ void UpdateStatusBar() override;
protected:
std::string Messages;
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 026320a1f..028e85298 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -17,30 +17,32 @@
#include "cmVersion.h"
#include "cmake.h"
+#include <algorithm>
#include <stdio.h>
#include <string.h>
+#include <utility>
inline int ctrl(int z)
{
return (z & 037);
}
-cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
+cmCursesMainForm::cmCursesMainForm(std::vector<std::string> args,
int initWidth)
- : Args(args)
+ : Args(std::move(args))
, InitialWidth(initWidth)
{
this->NumberOfPages = 0;
- this->Fields = CM_NULLPTR;
- this->Entries = CM_NULLPTR;
+ this->Fields = nullptr;
+ this->Entries = nullptr;
this->AdvancedMode = false;
this->NumberOfVisibleEntries = 0;
this->OkToGenerate = false;
- this->HelpMessage.push_back(
+ this->HelpMessage.emplace_back(
"Welcome to ccmake, curses based user interface for CMake.");
- this->HelpMessage.push_back("");
- this->HelpMessage.push_back(s_ConstHelpMessage);
- this->CMakeInstance = new cmake(cmake::RoleProject);
+ this->HelpMessage.emplace_back();
+ this->HelpMessage.emplace_back(s_ConstHelpMessage);
+ this->CMakeInstance = new cmake(cmake::RoleProject, cmState::Project);
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeCursesCommand());
@@ -59,7 +61,7 @@ cmCursesMainForm::~cmCursesMainForm()
if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
- this->Form = CM_NULLPTR;
+ this->Form = nullptr;
}
delete[] this->Fields;
@@ -70,25 +72,18 @@ cmCursesMainForm::~cmCursesMainForm()
delete this->Entries;
if (this->CMakeInstance) {
delete this->CMakeInstance;
- this->CMakeInstance = CM_NULLPTR;
+ this->CMakeInstance = nullptr;
}
}
// 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;
+ return this->Entries &&
+ std::any_of(this->Entries->begin(), this->Entries->end(),
+ [&key](cmCursesCacheEntryComposite* entry) {
+ return key == entry->Key;
+ });
}
// Create new cmCursesCacheEntryComposite entries from the cache
@@ -105,10 +100,9 @@ void cmCursesMainForm::InitializeUI()
// Count non-internal and non-static entries
int count = 0;
- for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it) {
+ for (std::string const& key : cacheKeys) {
cmStateEnums::CacheEntryType t =
- this->CMakeInstance->GetState()->GetCacheEntryType(*it);
+ this->CMakeInstance->GetState()->GetCacheEntryType(key);
if (t != cmStateEnums::INTERNAL && t != cmStateEnums::STATIC &&
t != cmStateEnums::UNINITIALIZED) {
++count;
@@ -128,11 +122,9 @@ void cmCursesMainForm::InitializeUI()
// Create the composites.
// First add entries which are new
- for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it) {
- std::string key = *it;
+ for (std::string const& key : cacheKeys) {
cmStateEnums::CacheEntryType t =
- this->CMakeInstance->GetState()->GetCacheEntryType(*it);
+ this->CMakeInstance->GetState()->GetCacheEntryType(key);
if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC ||
t == cmStateEnums::UNINITIALIZED) {
continue;
@@ -146,11 +138,9 @@ void cmCursesMainForm::InitializeUI()
}
// then add entries which are old
- for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it) {
- std::string key = *it;
+ for (std::string const& key : cacheKeys) {
cmStateEnums::CacheEntryType t =
- this->CMakeInstance->GetState()->GetCacheEntryType(*it);
+ this->CMakeInstance->GetState()->GetCacheEntryType(key);
if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC ||
t == cmStateEnums::UNINITIALIZED) {
continue;
@@ -180,7 +170,7 @@ void cmCursesMainForm::RePost()
if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
- this->Form = CM_NULLPTR;
+ this->Form = nullptr;
}
delete[] this->Fields;
if (this->AdvancedMode) {
@@ -188,13 +178,12 @@ void cmCursesMainForm::RePost()
} 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) {
+ for (cmCursesCacheEntryComposite* entry : *this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- (*it)->GetValue(), "ADVANCED");
+ entry->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
}
@@ -210,36 +199,35 @@ void cmCursesMainForm::RePost()
this->Fields = new FIELD*[3 * this->NumberOfVisibleEntries + 1];
size_t cc;
for (cc = 0; cc < 3 * this->NumberOfVisibleEntries + 1; cc++) {
- this->Fields[cc] = CM_NULLPTR;
+ this->Fields[cc] = nullptr;
}
// Assign fields
int j = 0;
- std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
+ for (cmCursesCacheEntryComposite* entry : *this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- (*it)->GetValue(), "ADVANCED");
+ entry->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && 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;
+ this->Fields[3 * j] = entry->Label->Field;
+ this->Fields[3 * j + 1] = entry->IsNewLabel->Field;
+ this->Fields[3 * j + 2] = entry->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;
+ const auto& front = *this->Entries->front();
+ this->Fields[0] = front.Label->Field;
+ this->Fields[1] = front.IsNewLabel->Field;
+ this->Fields[2] = front.Entry->Field;
this->NumberOfVisibleEntries = 1;
}
// Has to be null terminated.
- this->Fields[3 * this->NumberOfVisibleEntries] = CM_NULLPTR;
+ this->Fields[3 * this->NumberOfVisibleEntries] = nullptr;
}
void cmCursesMainForm::Render(int left, int top, int width, int height)
@@ -259,7 +247,7 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
// Delete the previous form
unpost_form(this->Form);
free_form(this->Form);
- this->Form = CM_NULLPTR;
+ this->Form = nullptr;
}
// Wrong window size
@@ -276,13 +264,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
} 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) {
+ for (cmCursesCacheEntryComposite* entry : *this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- (*it)->GetValue(), "ADVANCED");
+ entry->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
}
@@ -295,13 +282,12 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
if (height > 0) {
bool isNewPage;
int i = 0;
- std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
+ for (cmCursesCacheEntryComposite* entry : *this->Entries) {
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue(entry->GetValue());
bool advanced =
this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
- (*it)->GetValue(), "ADVANCED");
+ entry->GetValue(), "ADVANCED");
if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
}
@@ -312,10 +298,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
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);
+ entry->Label->Move(left, top + row - 1, isNewPage);
+ entry->IsNewLabel->Move(left + 32, top + row - 1, false);
+ entry->Entry->Move(left + 33, top + row - 1, false);
+ entry->Entry->SetPage(this->NumberOfPages);
i++;
}
}
@@ -341,23 +327,21 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */)
}
// Give the current widget (if it exists), a chance to print keys
- cmCursesWidget* cw = CM_NULLPTR;
+ cmCursesWidget* cw = nullptr;
if (this->Form) {
FIELD* currentField = current_field(this->Form);
cw = reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
}
char fmt_s[] = "%s";
- if (cw == CM_NULLPTR || !cw->PrintKeys()) {
+ if (cw == nullptr || !cw->PrintKeys()) {
char firstLine[512] = "";
char secondLine[512] = "";
char thirdLine[512] = "";
if (process) {
- const char* clearLine =
- " ";
- strcpy(firstLine, clearLine);
- strcpy(secondLine, clearLine);
- strcpy(thirdLine, clearLine);
+ memset(firstLine, ' ', 68);
+ memset(secondLine, ' ', 68);
+ memset(thirdLine, ' ', 68);
} else {
if (this->OkToGenerate) {
sprintf(firstLine,
@@ -372,15 +356,16 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */)
sprintf(thirdLine, toggleKeyInstruction,
this->AdvancedMode ? "On" : "Off");
}
- sprintf(secondLine, "Press [h] for help "
- "Press [q] to quit without generating");
+ 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 Press [d] to delete an entry";
if (process) {
- strcpy(fmt, " ");
+ memset(fmt, ' ', 27);
}
printw(fmt_s, fmt);
curses_move(y - 3, 0);
@@ -413,9 +398,10 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
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),
+ printw(fmt,
+ (cmCursesMainForm::MIN_WIDTH < this->InitialWidth
+ ? this->InitialWidth
+ : cmCursesMainForm::MIN_WIDTH),
cmCursesMainForm::MIN_HEIGHT);
touchwin(stdscr);
wrefresh(stdscr);
@@ -425,7 +411,7 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
// Get the key of the current entry
FIELD* cur = current_field(this->Form);
int findex = field_index(cur);
- cmCursesWidget* lbl = CM_NULLPTR;
+ cmCursesWidget* lbl = nullptr;
if (findex >= 0) {
lbl = reinterpret_cast<cmCursesWidget*>(
field_userptr(this->Fields[findex - 2]));
@@ -456,41 +442,27 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
// 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 curFieldLen = strlen(curField);
size_t helpLen = strlen(help);
- size_t width;
- if (x < cmCursesMainForm::MAX_WIDTH) {
- width = x;
- } else {
- width = cmCursesMainForm::MAX_WIDTH;
- }
+ size_t width = std::min<size_t>(x, cmCursesMainForm::MAX_WIDTH);
if (message) {
curField = message;
curFieldLen = strlen(message);
+ strncpy(bar, curField, width);
if (curFieldLen < width) {
- strcpy(bar, curField);
- for (i = curFieldLen; i < width; ++i) {
- bar[i] = ' ';
- }
- } else {
- strncpy(bar, curField, width);
+ memset(bar + curFieldLen, ' ', width - curFieldLen);
}
} else {
- if (curFieldLen >= width) {
- strncpy(bar, curField, width);
- } else {
- strcpy(bar, curField);
+ strncpy(bar, curField, width);
+ if (curFieldLen < width) {
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] = ' ';
- }
+ strncpy(bar + curFieldLen + 2, help, width - curFieldLen - 2);
+ if (curFieldLen + helpLen + 2 < width) {
+ memset(bar + curFieldLen + helpLen + 2, ' ',
+ width - (curFieldLen + helpLen + 2));
}
}
}
@@ -503,9 +475,7 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
char vertmp[128];
sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion());
size_t sideSpace = (width - strlen(vertmp));
- for (i = 0; i < sideSpace; i++) {
- version[i] = ' ';
- }
+ memset(version, ' ', sideSpace);
sprintf(version + sideSpace, "%s", vertmp);
version[width] = '\0';
@@ -520,21 +490,17 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
pos_form_cursor(this->Form);
}
-void cmCursesMainForm::UpdateProgress(const char* msg, float prog, void* vp)
+void cmCursesMainForm::UpdateProgress(const std::string& msg, float prog)
{
- 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));
+ sprintf(tmp, "%s %i%%", msg.c_str(), static_cast<int>(100 * prog));
} else {
- cmsg = msg;
+ cmsg = msg.c_str();
}
- cm->UpdateStatusBar(cmsg);
- cm->PrintKeys(1);
+ this->UpdateStatusBar(cmsg);
+ this->PrintKeys(1);
curses_move(1, 1);
touchwin(stdscr);
refresh();
@@ -550,14 +516,16 @@ int cmCursesMainForm::Configure(int noconfigure)
this->PrintKeys(1);
touchwin(stdscr);
refresh();
- this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress,
- this);
+ this->CMakeInstance->SetProgressCallback(
+ [this](const std::string& msg, float prog) {
+ this->UpdateProgress(msg, prog);
+ });
// always save the current gui values to disk
this->FillCacheManagerFromUI();
this->CMakeInstance->SaveCache(
this->CMakeInstance->GetHomeOutputDirectory());
- this->LoadCache(CM_NULLPTR);
+ this->LoadCache(nullptr);
// Get rid of previous errors
this->Errors = std::vector<std::string>();
@@ -574,7 +542,7 @@ int cmCursesMainForm::Configure(int noconfigure)
} else {
retVal = this->CMakeInstance->Configure();
}
- this->CMakeInstance->SetProgressCallback(CM_NULLPTR, CM_NULLPTR);
+ this->CMakeInstance->SetProgressCallback(nullptr);
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
@@ -585,10 +553,11 @@ int cmCursesMainForm::Configure(int noconfigure)
}
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.");
+ 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;
@@ -619,8 +588,10 @@ int cmCursesMainForm::Generate()
this->PrintKeys(1);
touchwin(stdscr);
refresh();
- this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress,
- this);
+ this->CMakeInstance->SetProgressCallback(
+ [this](const std::string& msg, float prog) {
+ this->UpdateProgress(msg, prog);
+ });
// Get rid of previous errors
this->Errors = std::vector<std::string>();
@@ -628,7 +599,7 @@ int cmCursesMainForm::Generate()
// run the generate process
int retVal = this->CMakeInstance->Generate();
- this->CMakeInstance->SetProgressCallback(CM_NULLPTR, CM_NULLPTR);
+ this->CMakeInstance->SetProgressCallback(nullptr);
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
if (retVal != 0 || !this->Errors.empty()) {
@@ -664,9 +635,10 @@ int cmCursesMainForm::Generate()
return 0;
}
-void cmCursesMainForm::AddError(const char* message, const char* /*unused*/)
+void cmCursesMainForm::AddError(const std::string& message,
+ const char* /*unused*/)
{
- this->Errors.push_back(message);
+ this->Errors.emplace_back(message);
}
void cmCursesMainForm::RemoveEntry(const char* value)
@@ -675,28 +647,29 @@ void cmCursesMainForm::RemoveEntry(const char* 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;
- }
+ auto removeIt =
+ std::find_if(this->Entries->begin(), this->Entries->end(),
+ [value](cmCursesCacheEntryComposite* entry) -> bool {
+ const char* val = entry->GetValue();
+ return val != nullptr && !strcmp(value, val);
+ });
+
+ if (removeIt != this->Entries->end()) {
+ this->CMakeInstance->UnwatchUnusedCli(value);
+ this->Entries->erase(removeIt);
}
}
// 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++) {
- std::string cacheKey = (*this->Entries)[i]->Key;
+ for (cmCursesCacheEntryComposite* entry : *this->Entries) {
+ const std::string& cacheKey = entry->Key;
const char* existingValue =
this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey);
if (existingValue) {
std::string oldValue = existingValue;
- std::string newValue = (*this->Entries)[i]->Entry->GetValue();
+ std::string newValue = entry->Entry->GetValue();
std::string fixedOldValue;
std::string fixedNewValue;
cmStateEnums::CacheEntryType t =
@@ -723,7 +696,7 @@ void cmCursesMainForm::FixValue(cmStateEnums::CacheEntryType type,
cmSystemTools::ConvertToUnixSlashes(out);
}
if (type == cmStateEnums::BOOL) {
- if (cmSystemTools::IsOff(out.c_str())) {
+ if (cmSystemTools::IsOff(out)) {
out = "OFF";
} else {
out = "ON";
@@ -877,7 +850,7 @@ void cmCursesMainForm::HandleInput()
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(
field_userptr(this->Fields[findex - 2]));
const char* curField = lbl->GetValue();
- const char* helpString = CM_NULLPTR;
+ const char* helpString = nullptr;
const char* existingValue =
this->CMakeInstance->GetState()->GetCacheEntryValue(curField);
@@ -962,7 +935,7 @@ void cmCursesMainForm::HandleInput()
// (findex always corresponds to the value field)
FIELD* nextCur;
if (findex == 2) {
- nextCur = CM_NULLPTR;
+ nextCur = nullptr;
} else if (findex == 3 * this->NumberOfVisibleEntries - 1) {
nextCur = this->Fields[findex - 5];
} else {
@@ -992,17 +965,14 @@ void cmCursesMainForm::HandleInput()
if (nextCur) {
// make the next or prev. current field after deletion
- nextCur = CM_NULLPTR;
- 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);
+ auto nextEntryIt =
+ std::find_if(this->Entries->begin(), this->Entries->end(),
+ [&nextVal](cmCursesCacheEntryComposite* entry) {
+ return nextVal == entry->Key;
+ });
+
+ if (nextEntryIt != this->Entries->end()) {
+ set_current_field(this->Form, (*nextEntryIt)->Entry->Field);
}
}
}
@@ -1041,7 +1011,7 @@ void cmCursesMainForm::JumpToCacheEntry(const char* astr)
int findex = start_index;
for (;;) {
if (!str.empty()) {
- cmCursesWidget* lbl = CM_NULLPTR;
+ cmCursesWidget* lbl = nullptr;
if (findex >= 0) {
lbl = reinterpret_cast<cmCursesWidget*>(
field_userptr(this->Fields[findex - 2]));
diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h
index e35cf3ed7..d37997581 100644
--- a/Source/CursesDialog/cmCursesMainForm.h
+++ b/Source/CursesDialog/cmCursesMainForm.h
@@ -3,7 +3,7 @@
#ifndef cmCursesMainForm_h
#define cmCursesMainForm_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesForm.h"
#include "cmCursesStandardIncludes.h"
@@ -23,11 +23,12 @@ class cmake;
*/
class cmCursesMainForm : public cmCursesForm
{
- CM_DISABLE_COPY(cmCursesMainForm)
-
public:
- cmCursesMainForm(std::vector<std::string> const& args, int initwidth);
- ~cmCursesMainForm() CM_OVERRIDE;
+ cmCursesMainForm(std::vector<std::string> args, int initwidth);
+ ~cmCursesMainForm() override;
+
+ cmCursesMainForm(cmCursesMainForm const&) = delete;
+ cmCursesMainForm& operator=(cmCursesMainForm const&) = delete;
/**
* Set the widgets which represent the cache entries.
@@ -37,13 +38,13 @@ public:
/**
* Handle user input.
*/
- void HandleInput() CM_OVERRIDE;
+ void HandleInput() override;
/**
* Display form. Use a window of size width x height, starting
* at top, left.
*/
- void Render(int left, int top, int width, int height) CM_OVERRIDE;
+ void Render(int left, int top, int width, int height) override;
/**
* Returns true if an entry with the given key is in the
@@ -64,7 +65,7 @@ public:
* exception is during a resize. The optional argument specifies the
* string to be displayed in the status bar.
*/
- void UpdateStatusBar() CM_OVERRIDE { this->UpdateStatusBar(CM_NULLPTR); }
+ void UpdateStatusBar() override { this->UpdateStatusBar(nullptr); }
virtual void UpdateStatusBar(const char* message);
/**
@@ -80,7 +81,7 @@ public:
* During a CMake run, an error handle should add errors
* to be displayed afterwards.
*/
- void AddError(const char* message, const char* title) CM_OVERRIDE;
+ void AddError(const std::string& message, const char* title) override;
/**
* Used to do a configure. If argument is specified, it does only the check
@@ -101,8 +102,7 @@ public:
/**
* Progress callback
*/
- static void UpdateProgressOld(const char* msg, float prog, void*);
- static void UpdateProgress(const char* msg, float prog, void*);
+ void UpdateProgress(const std::string& msg, float prog);
protected:
// Copy the cache values from the user interface to the actual
@@ -125,7 +125,7 @@ protected:
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
+ // Command line arguments to be passed to cmake each time
// it is run
std::vector<std::string> Args;
// Message displayed when user presses 'h'
diff --git a/Source/CursesDialog/cmCursesOptionsWidget.cxx b/Source/CursesDialog/cmCursesOptionsWidget.cxx
index d26a98f86..eb773ad0f 100644
--- a/Source/CursesDialog/cmCursesOptionsWidget.cxx
+++ b/Source/CursesDialog/cmCursesOptionsWidget.cxx
@@ -23,6 +23,9 @@ cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height, int left,
bool cmCursesOptionsWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/,
WINDOW* w)
{
+ if (this->Options.empty()) {
+ return false;
+ }
switch (key) {
case 10: // 10 == enter
case KEY_ENTER:
@@ -75,9 +78,8 @@ 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) {
+ for (auto const& opt : this->Options) {
+ if (opt == value) {
this->CurrentOption = index;
}
index++;
diff --git a/Source/CursesDialog/cmCursesOptionsWidget.h b/Source/CursesDialog/cmCursesOptionsWidget.h
index 7f4416f95..0128d6a42 100644
--- a/Source/CursesDialog/cmCursesOptionsWidget.h
+++ b/Source/CursesDialog/cmCursesOptionsWidget.h
@@ -3,7 +3,7 @@
#ifndef cmCursesOptionsWidget_h
#define cmCursesOptionsWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmCursesWidget.h"
@@ -15,16 +15,17 @@ class cmCursesMainForm;
class cmCursesOptionsWidget : public cmCursesWidget
{
- CM_DISABLE_COPY(cmCursesOptionsWidget)
-
public:
cmCursesOptionsWidget(int width, int height, int left, int top);
+ cmCursesOptionsWidget(cmCursesOptionsWidget const&) = delete;
+ cmCursesOptionsWidget& operator=(cmCursesOptionsWidget const&) = delete;
+
// Description:
// Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was
// handled.
- bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
+ bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override;
void SetOption(const std::string&);
void AddOption(std::string const&);
void NextOption();
diff --git a/Source/CursesDialog/cmCursesPathWidget.h b/Source/CursesDialog/cmCursesPathWidget.h
index ae6c16d02..1eace03a6 100644
--- a/Source/CursesDialog/cmCursesPathWidget.h
+++ b/Source/CursesDialog/cmCursesPathWidget.h
@@ -3,7 +3,7 @@
#ifndef cmCursesPathWidget_h
#define cmCursesPathWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmCursesStringWidget.h"
@@ -14,18 +14,19 @@ class cmCursesMainForm;
class cmCursesPathWidget : public cmCursesStringWidget
{
- CM_DISABLE_COPY(cmCursesPathWidget)
-
public:
cmCursesPathWidget(int width, int height, int left, int top);
+ cmCursesPathWidget(cmCursesPathWidget const&) = delete;
+ cmCursesPathWidget& operator=(cmCursesPathWidget const&) = delete;
+
/**
* This method is called when different keys are pressed. The
* subclass can have a special implementation handler for this.
*/
- void OnTab(cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
- void OnReturn(cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
- void OnType(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
+ void OnTab(cmCursesMainForm* fm, WINDOW* w) override;
+ void OnReturn(cmCursesMainForm* fm, WINDOW* w) override;
+ void OnType(int& key, cmCursesMainForm* fm, WINDOW* w) override;
protected:
std::string LastString;
diff --git a/Source/CursesDialog/cmCursesStandardIncludes.h b/Source/CursesDialog/cmCursesStandardIncludes.h
index 5c5950483..5b0ad5824 100644
--- a/Source/CursesDialog/cmCursesStandardIncludes.h
+++ b/Source/CursesDialog/cmCursesStandardIncludes.h
@@ -3,11 +3,16 @@
#ifndef cmCursesStandardIncludes_h
#define cmCursesStandardIncludes_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+
+// Record whether __attribute__ is currently defined. See purpose below.
+#ifndef __attribute__
+# define cm_no__attribute__
+#endif
#if defined(__hpux)
-#define _BOOL_DEFINED
-#include <sys/time.h>
+# define _BOOL_DEFINED
+# include <sys/time.h>
#endif
#include <form.h>
@@ -29,4 +34,12 @@ inline void curses_clear()
#undef erase
#undef clear
+// The curses headers on some platforms (e.g. Solaris) may
+// define __attribute__ as a macro. This breaks C++ headers
+// in some cases, so undefine it now.
+#if defined(cm_no__attribute__) && defined(__attribute__)
+# undef __attribute__
+#endif
+#undef cm_no__attribute__
+
#endif // cmCursesStandardIncludes_h
diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx
index ff189f01e..5e2a329d9 100644
--- a/Source/CursesDialog/cmCursesStringWidget.cxx
+++ b/Source/CursesDialog/cmCursesStringWidget.cxx
@@ -74,7 +74,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
return false;
}
- this->OriginalString = CM_NULLPTR;
+ this->OriginalString = nullptr;
this->Done = false;
char debugMessage[128];
@@ -188,9 +188,7 @@ bool cmCursesStringWidget::PrintKeys()
char fmt_s[] = "%s";
char firstLine[512];
// Clean the toolbar
- for (int i = 0; i < 512; i++) {
- firstLine[i] = ' ';
- }
+ memset(firstLine, ' ', sizeof(firstLine));
firstLine[511] = '\0';
curses_move(y - 4, 0);
printw(fmt_s, firstLine);
diff --git a/Source/CursesDialog/cmCursesStringWidget.h b/Source/CursesDialog/cmCursesStringWidget.h
index 5eb33666d..021515ba3 100644
--- a/Source/CursesDialog/cmCursesStringWidget.h
+++ b/Source/CursesDialog/cmCursesStringWidget.h
@@ -3,7 +3,7 @@
#ifndef cmCursesStringWidget_h
#define cmCursesStringWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmCursesWidget.h"
@@ -20,24 +20,25 @@ class cmCursesMainForm;
class cmCursesStringWidget : public cmCursesWidget
{
- CM_DISABLE_COPY(cmCursesStringWidget)
-
public:
cmCursesStringWidget(int width, int height, int left, int top);
+ cmCursesStringWidget(cmCursesStringWidget const&) = delete;
+ cmCursesStringWidget& operator=(cmCursesStringWidget const&) = delete;
+
/**
* Handle user input. Called by the container of this widget
* when this widget has focus. Returns true if the input was
* handled.
*/
- bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) CM_OVERRIDE;
+ bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override;
/**
* Set/Get the string.
*/
void SetString(const std::string& value);
const char* GetString();
- const char* GetValue() CM_OVERRIDE;
+ const char* GetValue() override;
/**
* Set/Get InEdit flag. Can be used to tell the widget to leave
@@ -59,7 +60,7 @@ public:
* in the toolbar and return true. Otherwise, return false
* and the parent widget will print.
*/
- bool PrintKeys() CM_OVERRIDE;
+ bool PrintKeys() override;
protected:
// true if the widget is in edit mode
diff --git a/Source/CursesDialog/cmCursesWidget.cxx b/Source/CursesDialog/cmCursesWidget.cxx
index 054f27e29..cc07411d4 100644
--- a/Source/CursesDialog/cmCursesWidget.cxx
+++ b/Source/CursesDialog/cmCursesWidget.cxx
@@ -14,7 +14,7 @@ cmCursesWidget::~cmCursesWidget()
{
if (this->Field) {
free_field(this->Field);
- this->Field = CM_NULLPTR;
+ this->Field = nullptr;
}
}
diff --git a/Source/CursesDialog/cmCursesWidget.h b/Source/CursesDialog/cmCursesWidget.h
index 3470d7096..f761f6d8a 100644
--- a/Source/CursesDialog/cmCursesWidget.h
+++ b/Source/CursesDialog/cmCursesWidget.h
@@ -3,7 +3,7 @@
#ifndef cmCursesWidget_h
#define cmCursesWidget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmCursesStandardIncludes.h"
#include "cmStateTypes.h"
@@ -14,12 +14,13 @@ class cmCursesMainForm;
class cmCursesWidget
{
- CM_DISABLE_COPY(cmCursesWidget)
-
public:
cmCursesWidget(int width, int height, int left, int top);
virtual ~cmCursesWidget();
+ cmCursesWidget(cmCursesWidget const&) = delete;
+ cmCursesWidget& operator=(cmCursesWidget const&) = delete;
+
/**
* Handle user input. Called by the container of this widget
* when this widget has focus. Returns true if the input was
diff --git a/Source/CursesDialog/form/CMakeLists.txt b/Source/CursesDialog/form/CMakeLists.txt
index 0677043a9..b468f5b31 100644
--- a/Source/CursesDialog/form/CMakeLists.txt
+++ b/Source/CursesDialog/form/CMakeLists.txt
@@ -3,12 +3,9 @@
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
+add_library(cmForm
fld_arg.c
fld_attr.c
fld_current.c
@@ -49,10 +46,16 @@ set( FORM_SRCS
fty_num.c
fty_regex.c
)
-
-include_directories(${CMAKE_FORM_SOURCE_DIR})
-add_library(cmForm ${FORM_SRCS} )
+
+target_include_directories(cmForm
+ PUBLIC
+ ${CURSES_INCLUDE_PATH}
+ ${CMAKE_FORM_BINARY_DIR}
+ ${CMAKE_FORM_SOURCE_DIR}
+ )
+
target_link_libraries(cmForm ${CURSES_LIBRARY})
+
if(CURSES_EXTRA_LIBRARY)
target_link_libraries(cmForm ${CURSES_EXTRA_LIBRARY})
endif()
diff --git a/Source/CursesDialog/form/frm_post.c b/Source/CursesDialog/form/frm_post.c
index 924fe6a9e..fc0a35946 100644
--- a/Source/CursesDialog/form/frm_post.c
+++ b/Source/CursesDialog/form/frm_post.c
@@ -67,7 +67,7 @@ int post_form(FORM * form)
if ((form->cols > width) || (form->rows > height))
RETURN(E_NO_ROOM);
- /* reset form->curpage to an invald value. This forces Set_Form_Page
+ /* reset form->curpage to an invalid value. This forces Set_Form_Page
to do the page initialization which is required by post_form.
*/
page = form->curpage;
diff --git a/Source/LexerParser/cmCommandArgumentLexer.cxx b/Source/LexerParser/cmCommandArgumentLexer.cxx
index 12dce3758..58799123f 100644
--- a/Source/LexerParser/cmCommandArgumentLexer.cxx
+++ b/Source/LexerParser/cmCommandArgumentLexer.cxx
@@ -1,7 +1,4 @@
#include "cmStandardLexer.h"
-#line 2 "cmCommandArgumentLexer.cxx"
-
-#line 4 "cmCommandArgumentLexer.cxx"
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -11,11 +8,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmCommandArgument_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmCommandArgument_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmCommandArgument_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmCommandArgument_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmCommandArgument_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmCommandArgument_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmCommandArgument_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmCommandArgument_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmCommandArgument_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmCommandArgument_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmCommandArgument_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmCommandArgument_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmCommandArgument_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmCommandArgument_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmCommandArgument_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmCommandArgument_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmCommandArgument_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmCommandArgument_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmCommandArgument_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmCommandArgument_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmCommandArgument_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmCommandArgument_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmCommandArgument_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmCommandArgument_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmCommandArgument_yylex_ALREADY_DEFINED
+#else
+#define yylex cmCommandArgument_yylex
+#endif
+
+#ifdef yyrestart
+#define cmCommandArgument_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmCommandArgument_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmCommandArgument_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmCommandArgument_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmCommandArgument_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmCommandArgument_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmCommandArgument_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmCommandArgument_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmCommandArgument_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmCommandArgument_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmCommandArgument_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmCommandArgument_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmCommandArgument_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmCommandArgument_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmCommandArgument_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmCommandArgument_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmCommandArgument_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmCommandArgument_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmCommandArgument_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmCommandArgument_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmCommandArgument_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmCommandArgument_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmCommandArgument_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmCommandArgument_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmCommandArgument_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmCommandArgument_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmCommandArgument_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmCommandArgument_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmCommandArgument_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmCommandArgument_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmCommandArgument_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmCommandArgument_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmCommandArgument_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmCommandArgument_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmCommandArgument_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmCommandArgument_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmCommandArgument_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmCommandArgument_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmCommandArgument_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmCommandArgument_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmCommandArgument_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmCommandArgument_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmCommandArgument_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmCommandArgument_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -86,10 +293,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -102,12 +315,10 @@ typedef unsigned int flex_uint32_t;
/* 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.
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
*/
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -131,20 +342,16 @@ typedef void* yyscan_t;
* 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_NEW_FILE yyrestart( yyin , yyscanner )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
@@ -194,7 +401,6 @@ typedef size_t yy_size_t;
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
-
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
#ifndef YY_STRUCT_YY_BUFFER_STATE
@@ -254,7 +460,7 @@ struct yy_buffer_state
* 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
+ * (via yyrestart()), so that the user can continue scanning by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
@@ -271,73 +477,67 @@ struct yy_buffer_state
#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 );
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void yypop_buffer_state ( yyscan_t yyscanner );
-#define YY_FLUSH_BUFFER cmCommandArgument_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+static void yyensure_buffer_stack ( yyscan_t yyscanner );
+static void yy_load_buffer_state ( yyscan_t yyscanner );
+static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
+#define YY_FLUSH_BUFFER 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 );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const 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
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
+#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
- cmCommandArgument_yyensure_buffer_stack (yyscanner); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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(yyscanner) (/*CONSTCOND*/1)
#define YY_SKIP_YYWRAP
-
-typedef unsigned char YY_CHAR;
+typedef flex_uint8_t 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 yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
+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 yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
@@ -348,7 +548,6 @@ static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
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,
@@ -358,14 +557,14 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
-static yyconst flex_int16_t yy_accept[30] =
+static const 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 YY_CHAR yy_ec[256] =
+static const YY_CHAR yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -397,13 +596,13 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;
-static yyconst YY_CHAR yy_meta[12] =
+static const YY_CHAR yy_meta[12] =
{ 0,
1, 2, 3, 4, 3, 4, 4, 4, 3, 5,
3
} ;
-static yyconst flex_uint16_t yy_base[35] =
+static const 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,
@@ -411,7 +610,7 @@ static yyconst flex_uint16_t yy_base[35] =
21, 26, 9, 30
} ;
-static yyconst flex_int16_t yy_def[35] =
+static const 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,
@@ -419,7 +618,7 @@ static yyconst flex_int16_t yy_def[35] =
29, 29, 29, 29
} ;
-static yyconst flex_uint16_t yy_nxt[53] =
+static const 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,
@@ -429,7 +628,7 @@ static yyconst flex_uint16_t yy_nxt[53] =
29, 29
} ;
-static yyconst flex_int16_t yy_chk[53] =
+static const 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,
@@ -446,8 +645,6 @@ static yyconst flex_int16_t yy_chk[53] =
#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"
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
/*
@@ -456,32 +653,37 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmCommandArgument_yy --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
Modify cmCommandArgumentLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in cmCommandArgument_yy_scan_bytes for loop condition of _yybytes_len to size_t
+ - remove trailing whitespace: sed -i 's/\s*$//' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmCommandArgumentLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#include "cmCommandArgumentParserHelper.h"
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = yyextra->LexInput(buf, max_size); }
+ do { result = yyextra->LexInput(buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmCommandArgumentParserTokens.h"
-/*--------------------------------------------------------------------------*/
+static const char *DCURLYVariable = "${";
+static const char *RCURLYVariable = "}";
+static const char *ATVariable = "@";
+static const char *DOLLARVariable = "$";
+static const char *LCURLYVariable = "{";
+static const char *BSLASHVariable = "\\";
-
-#line 484 "cmCommandArgumentLexer.cxx"
+/*--------------------------------------------------------------------------*/
#define INITIAL 0
#define ESCAPES 1
@@ -525,44 +727,44 @@ struct yyguts_t
}; /* end struct yyguts_t */
-static int yy_init_globals (yyscan_t yyscanner );
+static int yy_init_globals ( yyscan_t yyscanner );
-int cmCommandArgument_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmCommandArgument_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 yylex_destroy ( yyscan_t yyscanner );
-int cmCommandArgument_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmCommandArgument_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmCommandArgument_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmCommandArgument_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmCommandArgument_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmCommandArgument_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -570,9 +772,9 @@ void cmCommandArgument_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmCommandArgument_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmCommandArgument_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
@@ -581,19 +783,18 @@ extern int cmCommandArgument_yywrap (yyscan_t yyscanner );
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
-
#ifdef __cplusplus
-static int yyinput (yyscan_t yyscanner );
+static int yyinput ( yyscan_t yyscanner );
#else
-static int input (yyscan_t yyscanner );
+static int input ( yyscan_t yyscanner );
#endif
#endif
@@ -624,7 +825,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- size_t n; \
+ int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -637,7 +838,7 @@ static int input (yyscan_t yyscanner );
else \
{ \
errno=0; \
- while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
@@ -678,9 +879,9 @@ static int input (yyscan_t yyscanner );
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmCommandArgument_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmCommandArgument_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng
@@ -725,19 +926,15 @@ YY_DECL
yyout = stdout;
if ( ! YY_CURRENT_BUFFER ) {
- cmCommandArgument_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmCommandArgument_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
{
-#line 42 "cmCommandArgumentLexer.in.l"
-
-
-#line 740 "cmCommandArgumentLexer.cxx"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
@@ -765,9 +962,9 @@ yy_match:
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 30 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 41 );
@@ -796,7 +993,6 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 44 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
@@ -805,7 +1001,6 @@ YY_RULE_SETUP
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 50 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
@@ -814,7 +1009,6 @@ YY_RULE_SETUP
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 56 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
@@ -823,37 +1017,33 @@ YY_RULE_SETUP
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 62 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->DCURLYVariable;
+ yylvalp->str = DCURLYVariable;
return cal_DCURLY;
}
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 69 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->RCURLYVariable;
+ yylvalp->str = RCURLYVariable;
return cal_RCURLY;
}
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 76 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->ATVariable;
+ yylvalp->str = ATVariable;
return cal_AT;
}
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 83 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
@@ -862,7 +1052,6 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 89 "cmCommandArgumentLexer.in.l"
{
if ( !yyextra->HandleEscapeSymbol(yylvalp, *(yytext+1)) )
{
@@ -874,7 +1063,6 @@ YY_RULE_SETUP
case 9:
/* rule 9 can match eol */
YY_RULE_SETUP
-#line 97 "cmCommandArgumentLexer.in.l"
{
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
@@ -883,46 +1071,40 @@ YY_RULE_SETUP
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 103 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->DOLLARVariable;
+ yylvalp->str = DOLLARVariable;
return cal_DOLLAR;
}
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 109 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->LCURLYVariable;
+ yylvalp->str = LCURLYVariable;
return cal_LCURLY;
}
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 115 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->BSLASHVariable;
+ yylvalp->str = BSLASHVariable;
return cal_BSLASH;
}
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 121 "cmCommandArgumentLexer.in.l"
{
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->BSLASHVariable;
+ yylvalp->str = BSLASHVariable;
return cal_SYMBOL;
}
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 127 "cmCommandArgumentLexer.in.l"
ECHO;
YY_BREAK
-#line 925 "cmCommandArgumentLexer.cxx"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(ESCAPES):
case YY_STATE_EOF(NOESCAPES):
@@ -942,7 +1124,7 @@ case YY_STATE_EOF(NOESCAPES):
/* 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
+ * 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
@@ -1002,7 +1184,7 @@ case YY_STATE_EOF(NOESCAPES):
{
yyg->yy_did_buffer_switch_on_eof = 0;
- if ( cmCommandArgument_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
@@ -1056,7 +1238,7 @@ case YY_STATE_EOF(NOESCAPES):
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
-} /* end of cmCommandArgument_yylex */
+} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
*
@@ -1070,7 +1252,7 @@ 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;
- yy_size_t number_to_move, i;
+ 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] )
@@ -1099,7 +1281,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Try to read more data. */
/* First move last chars to start of buffer. */
- number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
@@ -1135,7 +1317,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
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 );
+ yyrealloc( (void *) b->yy_ch_buf,
+ (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
}
else
/* Can't grow it, we don't own it. */
@@ -1167,7 +1350,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
- cmCommandArgument_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
}
else
@@ -1181,12 +1364,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
ret_val = EOB_ACT_CONTINUE_SCAN;
- if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ if ((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. */
int 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 );
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
+ (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ /* "- 2" to take care of EOB's */
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
}
yyg->yy_n_chars += number_to_move;
@@ -1220,9 +1406,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 30 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
}
return yy_current_state;
@@ -1249,9 +1435,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 30 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
yy_is_jam = (yy_current_state == 29);
(void)yyg;
@@ -1287,7 +1473,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{ /* need more input */
- int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
@@ -1304,13 +1490,13 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
*/
/* Reset buffer status. */
- cmCommandArgument_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
- if ( cmCommandArgument_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
return 0;
if ( ! yyg->yy_did_buffer_switch_on_eof )
@@ -1342,34 +1528,34 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
* @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)
+ void yyrestart (FILE * input_file , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! YY_CURRENT_BUFFER ){
- cmCommandArgument_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmCommandArgument_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmCommandArgument_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
- cmCommandArgument_yy_load_buffer_state(yyscanner );
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
+ 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)
+ void 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);
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
*/
- cmCommandArgument_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
if ( YY_CURRENT_BUFFER == new_buffer )
return;
@@ -1382,17 +1568,17 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- cmCommandArgument_yy_load_buffer_state(yyscanner );
+ 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
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after 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)
+static void 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;
@@ -1407,35 +1593,35 @@ static void cmCommandArgument_yy_load_buffer_state (yyscan_t yyscanner)
* @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 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 );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
- b->yy_buf_size = (yy_size_t)size;
+ 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 );
+ b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_is_our_buffer = 1;
- cmCommandArgument_yy_init_buffer(b,file ,yyscanner);
+ yy_init_buffer( b, file , yyscanner);
return b;
}
/** Destroy the buffer.
- * @param b a buffer created with cmCommandArgument_yy_create_buffer()
+ * @param b a buffer created with yy_create_buffer()
* @param yyscanner The scanner object.
*/
- void cmCommandArgument_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+ void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1446,28 +1632,28 @@ static void cmCommandArgument_yy_load_buffer_state (yyscan_t yyscanner)
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
- cmCommandArgument_yyfree((void *) b->yy_ch_buf ,yyscanner );
+ yyfree( (void *) b->yy_ch_buf , yyscanner );
- cmCommandArgument_yyfree((void *) b ,yyscanner );
+ 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 cmCommandArgument_yyrestart() or at EOF.
+ * such as during a yyrestart() or at EOF.
*/
- static void cmCommandArgument_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+ static void 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);
+ 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.
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from 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){
@@ -1484,7 +1670,7 @@ static void cmCommandArgument_yy_load_buffer_state (yyscan_t yyscanner)
* @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)
+ void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! b )
@@ -1505,7 +1691,7 @@ static void cmCommandArgument_yy_load_buffer_state (yyscan_t yyscanner)
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == YY_CURRENT_BUFFER )
- cmCommandArgument_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
/** Pushes the new state onto the stack. The new state becomes
@@ -1514,15 +1700,15 @@ static void cmCommandArgument_yy_load_buffer_state (yyscan_t yyscanner)
* @param new_buffer The new state.
* @param yyscanner The scanner object.
*/
-void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+void 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);
+ yyensure_buffer_stack(yyscanner);
- /* This block is copied from cmCommandArgument_yy_switch_to_buffer. */
+ /* This block is copied from yy_switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
@@ -1536,8 +1722,8 @@ void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_
yyg->yy_buffer_stack_top++;
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- /* copied from cmCommandArgument_yy_switch_to_buffer. */
- cmCommandArgument_yy_load_buffer_state(yyscanner );
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
@@ -1545,19 +1731,19 @@ void cmCommandArgument_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_
* The next element becomes the new top.
* @param yyscanner The scanner object.
*/
-void cmCommandArgument_yypop_buffer_state (yyscan_t yyscanner)
+void 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_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 );
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
}
@@ -1565,9 +1751,9 @@ void cmCommandArgument_yypop_buffer_state (yyscan_t yyscanner)
/* Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
-static void cmCommandArgument_yyensure_buffer_stack (yyscan_t yyscanner)
+static void yyensure_buffer_stack (yyscan_t yyscanner)
{
- int num_to_alloc;
+ yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
@@ -1577,11 +1763,11 @@ static void cmCommandArgument_yyensure_buffer_stack (yyscan_t yyscanner)
* immediate realloc on the next call.
*/
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmCommandArgument_yyalloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)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()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
@@ -1596,12 +1782,12 @@ static void cmCommandArgument_yyensure_buffer_stack (yyscan_t yyscanner)
yy_size_t 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 = (struct yy_buffer_state**)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()" );
+ YY_FATAL_ERROR( "out of dynamic memory in 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*));
@@ -1615,7 +1801,7 @@ static void cmCommandArgument_yyensure_buffer_stack (yyscan_t yyscanner)
* @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 yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
@@ -1625,11 +1811,11 @@ YY_BUFFER_STATE cmCommandArgument_yy_scan_buffer (char * base, yy_size_t size
/* They forgot to leave room for the EOB's. */
return NULL;
- b = (YY_BUFFER_STATE) cmCommandArgument_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_scan_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_size = (int) (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 = NULL;
@@ -1639,53 +1825,53 @@ YY_BUFFER_STATE cmCommandArgument_yy_scan_buffer (char * base, yy_size_t size
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
- cmCommandArgument_yy_switch_to_buffer(b ,yyscanner );
+ yy_switch_to_buffer( b , yyscanner );
return b;
}
-/** Setup the input buffer state to scan a string. The next call to cmCommandArgument_yylex() will
+/** Setup the input buffer state to scan a string. The next call to 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_scan_bytes() instead.
*/
-YY_BUFFER_STATE cmCommandArgument_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
{
- return cmCommandArgument_yy_scan_bytes(yystr,(int) strlen(yystr) ,yyscanner);
+ return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
}
-/** Setup the input buffer state to scan the given bytes. The next call to cmCommandArgument_yylex() will
+/** Setup the input buffer state to scan the given bytes. The next call to 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 cmCommandArgument_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
- yy_size_t i;
+ int i;
/* Get memory for full buffer, including space for trailing EOB's. */
- n = (yy_size_t) _yybytes_len + 2;
- buf = (char *) cmCommandArgument_yyalloc(n ,yyscanner );
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) yyalloc( n , yyscanner );
if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmCommandArgument_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
- for ( i = 0; i < (size_t)_yybytes_len; ++i )
+ 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);
+ b = yy_scan_buffer( buf, n , yyscanner);
if ( ! b )
- YY_FATAL_ERROR( "bad buffer in cmCommandArgument_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
@@ -1699,11 +1885,11 @@ YY_BUFFER_STATE cmCommandArgument_yy_scan_bytes (yyconst char * yybytes, int _
#define YY_EXIT_FAILURE 2
#endif
-static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- (void) fprintf( stderr, "%s\n", msg );
+ fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
@@ -1729,7 +1915,7 @@ static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
/** Get the user-defined data for this scanner.
* @param yyscanner The scanner object.
*/
-YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner)
+YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyextra;
@@ -1738,7 +1924,7 @@ YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner)
/** Get the current line number.
* @param yyscanner The scanner object.
*/
-int cmCommandArgument_yyget_lineno (yyscan_t yyscanner)
+int yyget_lineno (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1751,7 +1937,7 @@ int cmCommandArgument_yyget_lineno (yyscan_t yyscanner)
/** Get the current column number.
* @param yyscanner The scanner object.
*/
-int cmCommandArgument_yyget_column (yyscan_t yyscanner)
+int yyget_column (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1764,7 +1950,7 @@ int cmCommandArgument_yyget_column (yyscan_t yyscanner)
/** Get the input stream.
* @param yyscanner The scanner object.
*/
-FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner)
+FILE *yyget_in (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyin;
@@ -1773,7 +1959,7 @@ FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner)
/** Get the output stream.
* @param yyscanner The scanner object.
*/
-FILE *cmCommandArgument_yyget_out (yyscan_t yyscanner)
+FILE *yyget_out (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyout;
@@ -1782,7 +1968,7 @@ FILE *cmCommandArgument_yyget_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
-int cmCommandArgument_yyget_leng (yyscan_t yyscanner)
+int yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
@@ -1792,7 +1978,7 @@ int cmCommandArgument_yyget_leng (yyscan_t yyscanner)
* @param yyscanner The scanner object.
*/
-char *cmCommandArgument_yyget_text (yyscan_t yyscanner)
+char *yyget_text (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yytext;
@@ -1802,7 +1988,7 @@ char *cmCommandArgument_yyget_text (yyscan_t yyscanner)
* @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)
+void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyextra = user_defined ;
@@ -1812,13 +1998,13 @@ void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yysca
* @param _line_number line number
* @param yyscanner The scanner object.
*/
-void cmCommandArgument_yyset_lineno (int _line_number , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
yylineno = _line_number;
}
@@ -1827,13 +2013,13 @@ void cmCommandArgument_yyset_lineno (int _line_number , yyscan_t yyscanner)
* @param _column_no column number
* @param yyscanner The scanner object.
*/
-void cmCommandArgument_yyset_column (int _column_no , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_column called with no buffer" );
yycolumn = _column_no;
}
@@ -1842,27 +2028,27 @@ void cmCommandArgument_yyset_column (int _column_no , yyscan_t yyscanner)
* input buffer.
* @param _in_str A readable stream.
* @param yyscanner The scanner object.
- * @see cmCommandArgument_yy_switch_to_buffer
+ * @see yy_switch_to_buffer
*/
-void cmCommandArgument_yyset_in (FILE * _in_str , yyscan_t yyscanner)
+void 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)
+void 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)
+int 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)
+void yyset_debug (int _bdebug , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ;
@@ -1872,20 +2058,18 @@ void cmCommandArgument_yyset_debug (int _bdebug , yyscan_t yyscanner)
/* User-visible API */
-/* cmCommandArgument_yylex_init is special because it creates the scanner itself, so it is
+/* 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)
-
+int 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 );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -1898,27 +2082,25 @@ int cmCommandArgument_yylex_init(yyscan_t* ptr_yy_globals)
return yy_init_globals ( *ptr_yy_globals );
}
-/* cmCommandArgument_yylex_init_extra has the same functionality as cmCommandArgument_yylex_init, but follows the
+/* yylex_init_extra has the same functionality as 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 user defined value in the first argument will be available to yyalloc in
* the yyextra field.
*/
-
-int cmCommandArgument_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
-
+int 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);
+ 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 );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -1929,7 +2111,7 @@ int cmCommandArgument_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* p
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);
+ yyset_extra (yy_user_defined, *ptr_yy_globals);
return yy_init_globals ( *ptr_yy_globals );
}
@@ -1938,7 +2120,7 @@ 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.
+ * This function is called from yylex_destroy(), so don't allocate here.
*/
yyg->yy_buffer_stack = NULL;
@@ -1962,37 +2144,37 @@ static int yy_init_globals (yyscan_t yyscanner)
#endif
/* For future reference: Set errno on error, since we are called by
- * cmCommandArgument_yylex_init()
+ * yylex_init()
*/
return 0;
}
-/* cmCommandArgument_yylex_destroy is for both reentrant and non-reentrant scanners. */
-int cmCommandArgument_yylex_destroy (yyscan_t yyscanner)
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int 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_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
YY_CURRENT_BUFFER_LVALUE = NULL;
- cmCommandArgument_yypop_buffer_state(yyscanner);
+ yypop_buffer_state(yyscanner);
}
/* Destroy the stack itself. */
- cmCommandArgument_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyfree(yyg->yy_buffer_stack , yyscanner);
yyg->yy_buffer_stack = NULL;
/* Destroy the start condition stack. */
- cmCommandArgument_yyfree(yyg->yy_start_stack ,yyscanner );
+ 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. */
+ * yylex() is called, initialization will occur. */
yy_init_globals( yyscanner);
/* Destroy the main struct (reentrant only). */
- cmCommandArgument_yyfree ( yyscanner , yyscanner );
+ yyfree ( yyscanner , yyscanner );
yyscanner = NULL;
return 0;
}
@@ -2002,7 +2184,7 @@ int cmCommandArgument_yylex_destroy (yyscan_t yyscanner)
*/
#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2014,7 +2196,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
{
int n;
for ( n = 0; s[n]; ++n )
@@ -2024,14 +2206,14 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
}
#endif
-void *cmCommandArgument_yyalloc (yy_size_t size , yyscan_t yyscanner)
+void *yyalloc (yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
return malloc(size);
}
-void *cmCommandArgument_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
+void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2046,19 +2228,15 @@ void *cmCommandArgument_yyrealloc (void * ptr, yy_size_t size , yyscan_t yysca
return realloc(ptr, size);
}
-void cmCommandArgument_yyfree (void * ptr , yyscan_t yyscanner)
+void yyfree (void * ptr , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- free( (char *) ptr ); /* see cmCommandArgument_yyrealloc() for (char *) cast */
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
-#line 127 "cmCommandArgumentLexer.in.l"
-
-
-
/*--------------------------------------------------------------------------*/
void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
{
@@ -2070,3 +2248,5 @@ void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
BEGIN(ESCAPES);
}
}
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmCommandArgumentLexer.h b/Source/LexerParser/cmCommandArgumentLexer.h
index 82e87b557..567751349 100644
--- a/Source/LexerParser/cmCommandArgumentLexer.h
+++ b/Source/LexerParser/cmCommandArgumentLexer.h
@@ -2,10 +2,6 @@
#define cmCommandArgument_yyHEADER_H 1
#define cmCommandArgument_yyIN_HEADER 1
-#line 6 "cmCommandArgumentLexer.h"
-
-#line 8 "cmCommandArgumentLexer.h"
-
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -14,11 +10,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmCommandArgument_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmCommandArgument_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmCommandArgument_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmCommandArgument_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmCommandArgument_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmCommandArgument_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmCommandArgument_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmCommandArgument_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmCommandArgument_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmCommandArgument_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmCommandArgument_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmCommandArgument_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmCommandArgument_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmCommandArgument_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmCommandArgument_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmCommandArgument_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmCommandArgument_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmCommandArgument_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmCommandArgument_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmCommandArgument_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmCommandArgument_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmCommandArgument_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmCommandArgument_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmCommandArgument_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmCommandArgument_yylex_ALREADY_DEFINED
+#else
+#define yylex cmCommandArgument_yylex
+#endif
+
+#ifdef yyrestart
+#define cmCommandArgument_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmCommandArgument_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmCommandArgument_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmCommandArgument_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmCommandArgument_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmCommandArgument_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmCommandArgument_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmCommandArgument_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmCommandArgument_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmCommandArgument_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmCommandArgument_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmCommandArgument_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmCommandArgument_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmCommandArgument_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmCommandArgument_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmCommandArgument_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmCommandArgument_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmCommandArgument_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmCommandArgument_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmCommandArgument_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmCommandArgument_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmCommandArgument_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmCommandArgument_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmCommandArgument_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmCommandArgument_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmCommandArgument_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmCommandArgument_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmCommandArgument_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmCommandArgument_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmCommandArgument_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmCommandArgument_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmCommandArgument_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmCommandArgument_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmCommandArgument_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmCommandArgument_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmCommandArgument_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmCommandArgument_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmCommandArgument_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmCommandArgument_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmCommandArgument_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmCommandArgument_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmCommandArgument_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmCommandArgument_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmCommandArgument_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -89,10 +295,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -193,21 +405,21 @@ struct yy_buffer_state
};
#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 );
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void 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 );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const 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 );
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
/* Begin user sect3 */
@@ -227,42 +439,42 @@ void cmCommandArgument_yyfree (void * ,yyscan_t yyscanner );
#define YY_EXTRA_TYPE void *
#endif
-int cmCommandArgument_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmCommandArgument_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 yylex_destroy ( yyscan_t yyscanner );
-int cmCommandArgument_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmCommandArgument_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmCommandArgument_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmCommandArgument_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmCommandArgument_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmCommandArgument_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmCommandArgument_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmCommandArgument_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmCommandArgument_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -270,18 +482,18 @@ void cmCommandArgument_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmCommandArgument_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmCommandArgument_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
@@ -309,9 +521,9 @@ static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmCommandArgument_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmCommandArgument_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* yy_get_previous_state - get the state just before the EOB char was reached */
@@ -328,9 +540,150 @@ extern int cmCommandArgument_yylex (yyscan_t yyscanner);
#undef YY_DECL
#endif
-#line 127 "cmCommandArgumentLexer.in.l"
-
+#ifndef cmCommandArgument_yy_create_buffer_ALREADY_DEFINED
+#undef yy_create_buffer
+#endif
+#ifndef cmCommandArgument_yy_delete_buffer_ALREADY_DEFINED
+#undef yy_delete_buffer
+#endif
+#ifndef cmCommandArgument_yy_scan_buffer_ALREADY_DEFINED
+#undef yy_scan_buffer
+#endif
+#ifndef cmCommandArgument_yy_scan_string_ALREADY_DEFINED
+#undef yy_scan_string
+#endif
+#ifndef cmCommandArgument_yy_scan_bytes_ALREADY_DEFINED
+#undef yy_scan_bytes
+#endif
+#ifndef cmCommandArgument_yy_init_buffer_ALREADY_DEFINED
+#undef yy_init_buffer
+#endif
+#ifndef cmCommandArgument_yy_flush_buffer_ALREADY_DEFINED
+#undef yy_flush_buffer
+#endif
+#ifndef cmCommandArgument_yy_load_buffer_state_ALREADY_DEFINED
+#undef yy_load_buffer_state
+#endif
+#ifndef cmCommandArgument_yy_switch_to_buffer_ALREADY_DEFINED
+#undef yy_switch_to_buffer
+#endif
+#ifndef cmCommandArgument_yypush_buffer_state_ALREADY_DEFINED
+#undef yypush_buffer_state
+#endif
+#ifndef cmCommandArgument_yypop_buffer_state_ALREADY_DEFINED
+#undef yypop_buffer_state
+#endif
+#ifndef cmCommandArgument_yyensure_buffer_stack_ALREADY_DEFINED
+#undef yyensure_buffer_stack
+#endif
+#ifndef cmCommandArgument_yylex_ALREADY_DEFINED
+#undef yylex
+#endif
+#ifndef cmCommandArgument_yyrestart_ALREADY_DEFINED
+#undef yyrestart
+#endif
+#ifndef cmCommandArgument_yylex_init_ALREADY_DEFINED
+#undef yylex_init
+#endif
+#ifndef cmCommandArgument_yylex_init_extra_ALREADY_DEFINED
+#undef yylex_init_extra
+#endif
+#ifndef cmCommandArgument_yylex_destroy_ALREADY_DEFINED
+#undef yylex_destroy
+#endif
+#ifndef cmCommandArgument_yyget_debug_ALREADY_DEFINED
+#undef yyget_debug
+#endif
+#ifndef cmCommandArgument_yyset_debug_ALREADY_DEFINED
+#undef yyset_debug
+#endif
+#ifndef cmCommandArgument_yyget_extra_ALREADY_DEFINED
+#undef yyget_extra
+#endif
+#ifndef cmCommandArgument_yyset_extra_ALREADY_DEFINED
+#undef yyset_extra
+#endif
+#ifndef cmCommandArgument_yyget_in_ALREADY_DEFINED
+#undef yyget_in
+#endif
+#ifndef cmCommandArgument_yyset_in_ALREADY_DEFINED
+#undef yyset_in
+#endif
+#ifndef cmCommandArgument_yyget_out_ALREADY_DEFINED
+#undef yyget_out
+#endif
+#ifndef cmCommandArgument_yyset_out_ALREADY_DEFINED
+#undef yyset_out
+#endif
+#ifndef cmCommandArgument_yyget_leng_ALREADY_DEFINED
+#undef yyget_leng
+#endif
+#ifndef cmCommandArgument_yyget_text_ALREADY_DEFINED
+#undef yyget_text
+#endif
+#ifndef cmCommandArgument_yyget_lineno_ALREADY_DEFINED
+#undef yyget_lineno
+#endif
+#ifndef cmCommandArgument_yyset_lineno_ALREADY_DEFINED
+#undef yyset_lineno
+#endif
+#ifndef cmCommandArgument_yyget_column_ALREADY_DEFINED
+#undef yyget_column
+#endif
+#ifndef cmCommandArgument_yyset_column_ALREADY_DEFINED
+#undef yyset_column
+#endif
+#ifndef cmCommandArgument_yywrap_ALREADY_DEFINED
+#undef yywrap
+#endif
+#ifndef cmCommandArgument_yyget_lval_ALREADY_DEFINED
+#undef yyget_lval
+#endif
+#ifndef cmCommandArgument_yyset_lval_ALREADY_DEFINED
+#undef yyset_lval
+#endif
+#ifndef cmCommandArgument_yyget_lloc_ALREADY_DEFINED
+#undef yyget_lloc
+#endif
+#ifndef cmCommandArgument_yyset_lloc_ALREADY_DEFINED
+#undef yyset_lloc
+#endif
+#ifndef cmCommandArgument_yyalloc_ALREADY_DEFINED
+#undef yyalloc
+#endif
+#ifndef cmCommandArgument_yyrealloc_ALREADY_DEFINED
+#undef yyrealloc
+#endif
+#ifndef cmCommandArgument_yyfree_ALREADY_DEFINED
+#undef yyfree
+#endif
+#ifndef cmCommandArgument_yytext_ALREADY_DEFINED
+#undef yytext
+#endif
+#ifndef cmCommandArgument_yyleng_ALREADY_DEFINED
+#undef yyleng
+#endif
+#ifndef cmCommandArgument_yyin_ALREADY_DEFINED
+#undef yyin
+#endif
+#ifndef cmCommandArgument_yyout_ALREADY_DEFINED
+#undef yyout
+#endif
+#ifndef cmCommandArgument_yy_flex_debug_ALREADY_DEFINED
+#undef yy_flex_debug
+#endif
+#ifndef cmCommandArgument_yylineno_ALREADY_DEFINED
+#undef yylineno
+#endif
+#ifndef cmCommandArgument_yytables_fload_ALREADY_DEFINED
+#undef yytables_fload
+#endif
+#ifndef cmCommandArgument_yytables_destroy_ALREADY_DEFINED
+#undef yytables_destroy
+#endif
+#ifndef cmCommandArgument_yyTABLES_NAME_ALREADY_DEFINED
+#undef yyTABLES_NAME
+#endif
-#line 335 "cmCommandArgumentLexer.h"
#undef cmCommandArgument_yyIN_HEADER
#endif /* cmCommandArgument_yyHEADER_H */
diff --git a/Source/LexerParser/cmCommandArgumentLexer.in.l b/Source/LexerParser/cmCommandArgumentLexer.in.l
index e3a80948c..010d54bf5 100644
--- a/Source/LexerParser/cmCommandArgumentLexer.in.l
+++ b/Source/LexerParser/cmCommandArgumentLexer.in.l
@@ -7,31 +7,41 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmCommandArgument_yy --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l
Modify cmCommandArgumentLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in yy_scan_bytes for loop condition of _yybytes_len to size_t
+ - remove trailing whitespace: sed -i 's/\s*$//' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmCommandArgumentLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#include "cmCommandArgumentParserHelper.h"
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = yyextra->LexInput(buf, max_size); }
+ do { result = yyextra->LexInput(buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmCommandArgumentParserTokens.h"
+static const char *DCURLYVariable = "${";
+static const char *RCURLYVariable = "}";
+static const char *ATVariable = "@";
+static const char *DOLLARVariable = "$";
+static const char *LCURLYVariable = "{";
+static const char *BSLASHVariable = "\\";
+
/*--------------------------------------------------------------------------*/
%}
+%option prefix="cmCommandArgument_yy"
+
%option reentrant
%option noyywrap
%option nounput
@@ -62,21 +72,21 @@ Modify cmCommandArgumentLexer.cxx:
"${" {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->DCURLYVariable;
+ yylvalp->str = DCURLYVariable;
return cal_DCURLY;
}
"}" {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->RCURLYVariable;
+ yylvalp->str = RCURLYVariable;
return cal_RCURLY;
}
"@" {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->ATVariable;
+ yylvalp->str = ATVariable;
return cal_AT;
}
@@ -102,25 +112,25 @@ Modify cmCommandArgumentLexer.cxx:
"$" {
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->DOLLARVariable;
+ yylvalp->str = DOLLARVariable;
return cal_DOLLAR;
}
"{" {
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->LCURLYVariable;
+ yylvalp->str = LCURLYVariable;
return cal_LCURLY;
}
<ESCAPES>"\\" {
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->BSLASHVariable;
+ yylvalp->str = BSLASHVariable;
return cal_BSLASH;
}
<NOESCAPES>"\\" {
//yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
- yylvalp->str = yyextra->BSLASHVariable;
+ yylvalp->str = BSLASHVariable;
return cal_SYMBOL;
}
@@ -137,3 +147,5 @@ void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes)
BEGIN(ESCAPES);
}
}
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmCommandArgumentParser.cxx b/Source/LexerParser/cmCommandArgumentParser.cxx
index aed0826c0..b965b32e8 100644
--- a/Source/LexerParser/cmCommandArgumentParser.cxx
+++ b/Source/LexerParser/cmCommandArgumentParser.cxx
@@ -126,8 +126,11 @@ static void cmCommandArgument_yyerror(yyscan_t yyscanner, const char* message);
# pragma warning (disable: 4244) /* loss of precision */
# pragma warning (disable: 4702) /* unreachable code */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
-#line 131 "cmCommandArgumentParser.cxx" /* yacc.c:339 */
+#line 134 "cmCommandArgumentParser.cxx" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
@@ -200,7 +203,7 @@ int cmCommandArgument_yyparse (yyscan_t yyscanner);
/* Copy the second part of user declarations. */
-#line 204 "cmCommandArgumentParser.cxx" /* yacc.c:358 */
+#line 207 "cmCommandArgumentParser.cxx" /* yacc.c:358 */
#ifdef short
# undef short
@@ -498,9 +501,9 @@ static const yytype_uint8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 96, 96, 102, 105, 110, 113, 118, 121, 126,
- 129, 132, 135, 138, 141, 146, 149, 152, 155, 160,
- 163, 168, 171, 176, 179
+ 0, 99, 99, 105, 108, 113, 116, 121, 124, 129,
+ 132, 135, 138, 141, 144, 149, 152, 155, 158, 163,
+ 166, 171, 174, 179, 182
};
#endif
@@ -510,7 +513,7 @@ static const yytype_uint8 yyrline[] =
static const char *const yytname[] =
{
"$end", "error", "$undefined", "cal_ENVCURLY", "cal_NCURLY",
- "cal_DCURLY", "\"$\"", "\"{\"", "\"}\"", "cal_NAME", "\"\\\\\"",
+ "cal_DCURLY", "\"$\"", "\"{\"", "\"}\"", "cal_NAME", R"("\\")",
"cal_SYMBOL", "\"@\"", "cal_ERROR", "cal_ATNAME", "$accept", "Start",
"GoalWithOptionalBackSlash", "Goal", "String", "OuterText", "Variable",
"EnvVarName", "MultipleIds", "ID", YY_NULLPTR
@@ -1297,192 +1300,192 @@ yyreduce:
switch (yyn)
{
case 2:
-#line 96 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 99 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = 0;
yyGetParser->SetResult((yyvsp[0].str));
}
-#line 1306 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1309 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 3:
-#line 102 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 105 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1314 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1317 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 4:
-#line 105 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 108 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = yyGetParser->CombineUnions((yyvsp[-1].str), (yyvsp[0].str));
}
-#line 1322 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1325 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 5:
-#line 110 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 113 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = 0;
}
-#line 1330 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1333 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 6:
-#line 113 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 116 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = yyGetParser->CombineUnions((yyvsp[-1].str), (yyvsp[0].str));
}
-#line 1338 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1341 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 7:
-#line 118 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 121 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1346 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1349 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 8:
-#line 121 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 124 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1354 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1357 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 9:
-#line 126 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 129 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1362 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1365 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 10:
-#line 129 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 132 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1370 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1373 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 11:
-#line 132 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 135 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1378 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1381 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 12:
-#line 135 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 138 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1386 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1389 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 13:
-#line 138 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 141 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1394 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1397 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 14:
-#line 141 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 144 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1402 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1405 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 15:
-#line 146 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 149 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = yyGetParser->ExpandSpecialVariable((yyvsp[-2].str), (yyvsp[-1].str));
}
-#line 1410 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1413 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 16:
-#line 149 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 152 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = yyGetParser->ExpandSpecialVariable((yyvsp[-2].str), (yyvsp[-1].str));
}
-#line 1418 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1421 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 17:
-#line 152 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 155 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = yyGetParser->ExpandVariable((yyvsp[-1].str));
}
-#line 1426 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1429 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 18:
-#line 155 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 158 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = yyGetParser->ExpandVariableForAt((yyvsp[0].str));
}
-#line 1434 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1437 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 19:
-#line 160 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 163 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1442 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1445 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 20:
-#line 163 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 166 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[-1].str);
}
-#line 1450 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1453 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 21:
-#line 168 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 171 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = 0;
}
-#line 1458 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1461 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 22:
-#line 171 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 174 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = yyGetParser->CombineUnions((yyvsp[-1].str), (yyvsp[0].str));
}
-#line 1466 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1469 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 23:
-#line 176 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 179 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1474 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1477 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
case 24:
-#line 179 "cmCommandArgumentParser.y" /* yacc.c:1646 */
+#line 182 "cmCommandArgumentParser.y" /* yacc.c:1646 */
{
(yyval.str) = (yyvsp[0].str);
}
-#line 1482 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1485 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
break;
-#line 1486 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
+#line 1489 "cmCommandArgumentParser.cxx" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@@ -1712,7 +1715,7 @@ yyreturn:
#endif
return yyresult;
}
-#line 184 "cmCommandArgumentParser.y" /* yacc.c:1906 */
+#line 187 "cmCommandArgumentParser.y" /* yacc.c:1906 */
/* End of grammar */
diff --git a/Source/LexerParser/cmCommandArgumentParser.y b/Source/LexerParser/cmCommandArgumentParser.y
index 55a88dffa..0c6aad547 100644
--- a/Source/LexerParser/cmCommandArgumentParser.y
+++ b/Source/LexerParser/cmCommandArgumentParser.y
@@ -55,6 +55,9 @@ static void cmCommandArgument_yyerror(yyscan_t yyscanner, const char* message);
# pragma warning (disable: 4244) /* loss of precision */
# pragma warning (disable: 4702) /* unreachable code */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
%}
/* Generate a reentrant parser object. */
diff --git a/Source/LexerParser/cmDependsJavaLexer.cxx b/Source/LexerParser/cmDependsJavaLexer.cxx
index 8159f47bb..d703e3c95 100644
--- a/Source/LexerParser/cmDependsJavaLexer.cxx
+++ b/Source/LexerParser/cmDependsJavaLexer.cxx
@@ -1,7 +1,4 @@
#include "cmStandardLexer.h"
-#line 2 "cmDependsJavaLexer.cxx"
-
-#line 4 "cmDependsJavaLexer.cxx"
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -11,11 +8,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmDependsJava_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmDependsJava_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmDependsJava_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmDependsJava_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmDependsJava_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmDependsJava_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmDependsJava_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmDependsJava_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmDependsJava_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmDependsJava_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmDependsJava_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmDependsJava_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmDependsJava_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmDependsJava_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmDependsJava_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmDependsJava_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmDependsJava_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmDependsJava_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmDependsJava_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmDependsJava_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmDependsJava_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmDependsJava_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmDependsJava_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmDependsJava_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmDependsJava_yylex_ALREADY_DEFINED
+#else
+#define yylex cmDependsJava_yylex
+#endif
+
+#ifdef yyrestart
+#define cmDependsJava_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmDependsJava_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmDependsJava_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmDependsJava_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmDependsJava_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmDependsJava_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmDependsJava_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmDependsJava_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmDependsJava_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmDependsJava_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmDependsJava_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmDependsJava_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmDependsJava_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmDependsJava_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmDependsJava_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmDependsJava_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmDependsJava_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmDependsJava_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmDependsJava_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmDependsJava_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmDependsJava_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmDependsJava_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmDependsJava_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmDependsJava_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmDependsJava_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmDependsJava_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmDependsJava_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmDependsJava_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmDependsJava_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmDependsJava_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmDependsJava_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmDependsJava_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmDependsJava_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmDependsJava_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmDependsJava_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmDependsJava_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmDependsJava_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmDependsJava_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmDependsJava_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmDependsJava_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmDependsJava_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmDependsJava_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmDependsJava_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmDependsJava_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -86,10 +293,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -102,12 +315,10 @@ typedef unsigned int flex_uint32_t;
/* 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.
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
*/
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -131,20 +342,16 @@ typedef void* yyscan_t;
* 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_NEW_FILE yyrestart( yyin , yyscanner )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
@@ -194,7 +401,6 @@ typedef size_t yy_size_t;
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
-
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
#ifndef YY_STRUCT_YY_BUFFER_STATE
@@ -254,7 +460,7 @@ struct yy_buffer_state
* 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
+ * (via yyrestart()), so that the user can continue scanning by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
@@ -271,73 +477,67 @@ struct yy_buffer_state
#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)
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void 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 );
+static void yyensure_buffer_stack ( yyscan_t yyscanner );
+static void yy_load_buffer_state ( yyscan_t yyscanner );
+static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
+#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , 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 );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
-#define yy_new_buffer cmDependsJava_yy_create_buffer
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
+#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
- cmDependsJava_yyensure_buffer_stack (yyscanner); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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(yyscanner) (/*CONSTCOND*/1)
#define YY_SKIP_YYWRAP
-
-typedef unsigned char YY_CHAR;
+typedef flex_uint8_t 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 yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
+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 yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
@@ -348,7 +548,6 @@ static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
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,
@@ -358,7 +557,7 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
-static yyconst flex_int16_t yy_accept[327] =
+static const 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,
@@ -398,7 +597,7 @@ static yyconst flex_int16_t yy_accept[327] =
27, 29, 107, 107, 45, 0
} ;
-static yyconst YY_CHAR yy_ec[256] =
+static const YY_CHAR yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 2, 2, 1, 1, 1, 1, 1, 1, 1,
@@ -430,7 +629,7 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;
-static yyconst YY_CHAR yy_meta[65] =
+static const YY_CHAR yy_meta[65] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 1,
1, 1, 1, 1, 1, 1, 1, 3, 3, 3,
@@ -441,7 +640,7 @@ static yyconst YY_CHAR yy_meta[65] =
1, 1, 1, 1
} ;
-static yyconst flex_uint16_t yy_base[334] =
+static const 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,
@@ -482,7 +681,7 @@ static yyconst flex_uint16_t yy_base[334] =
232, 96, 235
} ;
-static yyconst flex_int16_t yy_def[334] =
+static const 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,
@@ -523,7 +722,7 @@ static yyconst flex_int16_t yy_def[334] =
326, 326, 326
} ;
-static yyconst flex_uint16_t yy_nxt[479] =
+static const 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,
@@ -579,7 +778,7 @@ static yyconst flex_uint16_t yy_nxt[479] =
326, 326, 326, 326, 326, 326, 326, 326
} ;
-static yyconst flex_int16_t yy_chk[479] =
+static const 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,
@@ -642,8 +841,6 @@ static yyconst flex_int16_t yy_chk[479] =
#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"
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
/*
@@ -652,18 +849,19 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmDependsJava_yy --header-file=cmDependsJavaLexer.h -ocmDependsJavaLexer.cxx cmDependsJavaLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline --header-file=cmDependsJavaLexer.h -ocmDependsJavaLexer.cxx cmDependsJavaLexer.in.l
Modify cmDependsJavaLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmDependsJavaLexer.h cmDependsJavaLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in cmDependsJava_yy_scan_bytes for loop condition of _yybytes_len to size_t
+ - remove trailing whitespace: sed -i 's/\s*$//' cmDependsJavaLexer.h cmDependsJavaLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmDependsJavaLexer.h cmDependsJavaLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmDependsJavaLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#include <iostream>
#include "cmDependsJavaParserHelper.h"
@@ -671,7 +869,7 @@ Modify cmDependsJavaLexer.cxx:
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = yyextra->LexInput(buf, max_size); }
+ do { result = yyextra->LexInput(buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmDependsJavaParserTokens.h"
@@ -682,9 +880,6 @@ Modify cmDependsJavaLexer.cxx:
/*--------------------------------------------------------------------------*/
-
-#line 686 "cmDependsJavaLexer.cxx"
-
#define INITIAL 0
#define comment 1
#define string 2
@@ -727,44 +922,44 @@ struct yyguts_t
}; /* end struct yyguts_t */
-static int yy_init_globals (yyscan_t yyscanner );
+static int yy_init_globals ( yyscan_t yyscanner );
-int cmDependsJava_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmDependsJava_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 cmDependsJava_yylex_destroy (yyscan_t yyscanner );
+int yylex_destroy ( yyscan_t yyscanner );
-int cmDependsJava_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmDependsJava_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmDependsJava_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmDependsJava_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmDependsJava_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmDependsJava_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmDependsJava_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmDependsJava_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmDependsJava_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmDependsJava_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmDependsJava_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmDependsJava_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmDependsJava_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmDependsJava_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -772,32 +967,31 @@ void cmDependsJava_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmDependsJava_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmDependsJava_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef YY_NO_UNPUT
- static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);
+ static void yyunput ( int c, char *buf_ptr , yyscan_t yyscanner);
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
-
#ifdef __cplusplus
-static int yyinput (yyscan_t yyscanner );
+static int yyinput ( yyscan_t yyscanner );
#else
-static int input (yyscan_t yyscanner );
+static int input ( yyscan_t yyscanner );
#endif
#endif
@@ -828,7 +1022,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- size_t n; \
+ int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -841,7 +1035,7 @@ static int input (yyscan_t yyscanner );
else \
{ \
errno=0; \
- while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
@@ -882,9 +1076,9 @@ static int input (yyscan_t yyscanner );
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmDependsJava_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmDependsJava_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng
@@ -929,18 +1123,15 @@ YY_DECL
yyout = stdout;
if ( ! YY_CURRENT_BUFFER ) {
- cmDependsJava_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmDependsJava_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
{
-#line 48 "cmDependsJavaLexer.in.l"
-
-#line 943 "cmDependsJavaLexer.cxx"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
@@ -968,9 +1159,9 @@ yy_match:
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 327 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 414 );
@@ -999,539 +1190,432 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 49 "cmDependsJavaLexer.in.l"
{ BEGIN(comment); }
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 50 "cmDependsJavaLexer.in.l"
{ BEGIN(INITIAL); }
YY_BREAK
case 3:
/* rule 3 can match eol */
YY_RULE_SETUP
-#line 51 "cmDependsJavaLexer.in.l"
{}
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 53 "cmDependsJavaLexer.in.l"
{ BEGIN(string); }
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 54 "cmDependsJavaLexer.in.l"
{ BEGIN(INITIAL); return jp_STRINGLITERAL; }
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 55 "cmDependsJavaLexer.in.l"
{}
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 57 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_ABSTRACT; }
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 58 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_ASSERT; }
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 59 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_BOOLEAN_TYPE; }
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 60 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_BREAK; }
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 61 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_BYTE_TYPE; }
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 62 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_CASE; }
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 63 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_CATCH; }
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 64 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_CHAR_TYPE; }
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 65 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_CLASS; }
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 66 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_CONTINUE; }
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 67 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_DEFAULT; }
YY_BREAK
case 18:
YY_RULE_SETUP
-#line 68 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_DO; }
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 69 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_DOUBLE_TYPE; }
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 70 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_ELSE; }
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 71 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_EXTENDS; }
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 72 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_FINAL; }
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 73 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_FINALLY; }
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 74 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_FLOAT_TYPE; }
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 75 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_FOR; }
YY_BREAK
case 26:
YY_RULE_SETUP
-#line 76 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_IF; }
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 77 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_IMPLEMENTS; }
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 78 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_IMPORT; }
YY_BREAK
case 29:
YY_RULE_SETUP
-#line 79 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_INSTANCEOF; }
YY_BREAK
case 30:
YY_RULE_SETUP
-#line 80 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_INT_TYPE; }
YY_BREAK
case 31:
YY_RULE_SETUP
-#line 81 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_INTERFACE; }
YY_BREAK
case 32:
YY_RULE_SETUP
-#line 82 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_LONG_TYPE; }
YY_BREAK
case 33:
YY_RULE_SETUP
-#line 83 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_NATIVE; }
YY_BREAK
case 34:
YY_RULE_SETUP
-#line 84 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_NEW; }
YY_BREAK
case 35:
YY_RULE_SETUP
-#line 85 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_PACKAGE; }
YY_BREAK
case 36:
YY_RULE_SETUP
-#line 86 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_PRIVATE; }
YY_BREAK
case 37:
YY_RULE_SETUP
-#line 87 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_PROTECTED; }
YY_BREAK
case 38:
YY_RULE_SETUP
-#line 88 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_PUBLIC; }
YY_BREAK
case 39:
YY_RULE_SETUP
-#line 89 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_RETURN; }
YY_BREAK
case 40:
YY_RULE_SETUP
-#line 90 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_SHORT_TYPE; }
YY_BREAK
case 41:
YY_RULE_SETUP
-#line 91 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_STATIC; }
YY_BREAK
case 42:
YY_RULE_SETUP
-#line 92 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_STRICTFP; }
YY_BREAK
case 43:
YY_RULE_SETUP
-#line 93 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_SUPER; }
YY_BREAK
case 44:
YY_RULE_SETUP
-#line 94 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_SWITCH; }
YY_BREAK
case 45:
YY_RULE_SETUP
-#line 95 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_SYNCHRONIZED; }
YY_BREAK
case 46:
YY_RULE_SETUP
-#line 96 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_THIS; }
YY_BREAK
case 47:
YY_RULE_SETUP
-#line 97 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_THROW; }
YY_BREAK
case 48:
YY_RULE_SETUP
-#line 98 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_THROWS; }
YY_BREAK
case 49:
YY_RULE_SETUP
-#line 99 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_TRANSIENT; }
YY_BREAK
case 50:
YY_RULE_SETUP
-#line 100 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_TRY; }
YY_BREAK
case 51:
YY_RULE_SETUP
-#line 101 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_VOID; }
YY_BREAK
case 52:
YY_RULE_SETUP
-#line 102 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_VOLATILE; }
YY_BREAK
case 53:
YY_RULE_SETUP
-#line 103 "cmDependsJavaLexer.in.l"
{ KEYWORD; return jp_WHILE; }
YY_BREAK
case 54:
YY_RULE_SETUP
-#line 105 "cmDependsJavaLexer.in.l"
{ PRIMITIVE; return jp_BOOLEANLITERAL; }
YY_BREAK
case 55:
/* rule 55 can match eol */
YY_RULE_SETUP
-#line 106 "cmDependsJavaLexer.in.l"
{ PRIMITIVE; return jp_CHARACTERLITERAL; }
YY_BREAK
case 56:
YY_RULE_SETUP
-#line 107 "cmDependsJavaLexer.in.l"
{ PRIMITIVE; return jp_DECIMALINTEGERLITERAL; }
YY_BREAK
case 57:
YY_RULE_SETUP
-#line 108 "cmDependsJavaLexer.in.l"
{ PRIMITIVE; return jp_FLOATINGPOINTLITERAL; }
YY_BREAK
case 58:
YY_RULE_SETUP
-#line 109 "cmDependsJavaLexer.in.l"
{ PRIMITIVE; return jp_HEXINTEGERLITERAL; }
YY_BREAK
case 59:
YY_RULE_SETUP
-#line 110 "cmDependsJavaLexer.in.l"
{ PRIMITIVE; return jp_NULLLITERAL; }
YY_BREAK
case 60:
YY_RULE_SETUP
-#line 112 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_AND; }
YY_BREAK
case 61:
YY_RULE_SETUP
-#line 113 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_ANDAND; }
YY_BREAK
case 62:
YY_RULE_SETUP
-#line 114 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_ANDEQUALS; }
YY_BREAK
case 63:
YY_RULE_SETUP
-#line 115 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_BRACKETEND; }
YY_BREAK
case 64:
YY_RULE_SETUP
-#line 116 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_BRACKETSTART; }
YY_BREAK
case 65:
YY_RULE_SETUP
-#line 117 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_CARROT; }
YY_BREAK
case 66:
YY_RULE_SETUP
-#line 118 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_CARROTEQUALS; }
YY_BREAK
case 67:
YY_RULE_SETUP
-#line 119 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_COLON; }
YY_BREAK
case 68:
YY_RULE_SETUP
-#line 120 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_COMMA; }
YY_BREAK
case 69:
YY_RULE_SETUP
-#line 121 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_CURLYEND; }
YY_BREAK
case 70:
YY_RULE_SETUP
-#line 122 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_CURLYSTART; }
YY_BREAK
case 71:
YY_RULE_SETUP
-#line 123 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_DIVIDE; }
YY_BREAK
case 72:
YY_RULE_SETUP
-#line 124 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_DIVIDEEQUALS; }
YY_BREAK
case 73:
YY_RULE_SETUP
-#line 125 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_DOLLAR; }
YY_BREAK
case 74:
YY_RULE_SETUP
-#line 126 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_DOT; }
YY_BREAK
case 75:
YY_RULE_SETUP
-#line 127 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_EQUALS; }
YY_BREAK
case 76:
YY_RULE_SETUP
-#line 128 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_EQUALSEQUALS; }
YY_BREAK
case 77:
YY_RULE_SETUP
-#line 129 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_EXCLAMATION; }
YY_BREAK
case 78:
YY_RULE_SETUP
-#line 130 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_EXCLAMATIONEQUALS; }
YY_BREAK
case 79:
YY_RULE_SETUP
-#line 131 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_GREATER; }
YY_BREAK
case 80:
YY_RULE_SETUP
-#line 132 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_GTEQUALS; }
YY_BREAK
case 81:
YY_RULE_SETUP
-#line 133 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_GTGT; }
YY_BREAK
case 82:
YY_RULE_SETUP
-#line 134 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_GTGTEQUALS; }
YY_BREAK
case 83:
YY_RULE_SETUP
-#line 135 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_GTGTGT; }
YY_BREAK
case 84:
YY_RULE_SETUP
-#line 136 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_GTGTGTEQUALS; }
YY_BREAK
case 85:
YY_RULE_SETUP
-#line 137 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_LESLESEQUALS; }
YY_BREAK
case 86:
YY_RULE_SETUP
-#line 138 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_LESSTHAN; }
YY_BREAK
case 87:
YY_RULE_SETUP
-#line 139 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_LTEQUALS; }
YY_BREAK
case 88:
YY_RULE_SETUP
-#line 140 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_LTLT; }
YY_BREAK
case 89:
YY_RULE_SETUP
-#line 141 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_MINUS; }
YY_BREAK
case 90:
YY_RULE_SETUP
-#line 142 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_MINUSEQUALS; }
YY_BREAK
case 91:
YY_RULE_SETUP
-#line 143 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_MINUSMINUS; }
YY_BREAK
case 92:
YY_RULE_SETUP
-#line 144 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PAREEND; }
YY_BREAK
case 93:
YY_RULE_SETUP
-#line 145 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PARESTART; }
YY_BREAK
case 94:
YY_RULE_SETUP
-#line 146 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PERCENT; }
YY_BREAK
case 95:
YY_RULE_SETUP
-#line 147 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PERCENTEQUALS; }
YY_BREAK
case 96:
YY_RULE_SETUP
-#line 148 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PIPE; }
YY_BREAK
case 97:
YY_RULE_SETUP
-#line 149 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PIPEEQUALS; }
YY_BREAK
case 98:
YY_RULE_SETUP
-#line 150 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PIPEPIPE; }
YY_BREAK
case 99:
YY_RULE_SETUP
-#line 151 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PLUS; }
YY_BREAK
case 100:
YY_RULE_SETUP
-#line 152 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PLUSEQUALS; }
YY_BREAK
case 101:
YY_RULE_SETUP
-#line 153 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_PLUSPLUS; }
YY_BREAK
case 102:
YY_RULE_SETUP
-#line 154 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_QUESTION; }
YY_BREAK
case 103:
YY_RULE_SETUP
-#line 155 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_SEMICOL; }
YY_BREAK
case 104:
YY_RULE_SETUP
-#line 156 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_TILDE; }
YY_BREAK
case 105:
YY_RULE_SETUP
-#line 157 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_TIMES; }
YY_BREAK
case 106:
YY_RULE_SETUP
-#line 158 "cmDependsJavaLexer.in.l"
{ SYMBOL; return jp_TIMESEQUALS; }
YY_BREAK
case 107:
YY_RULE_SETUP
-#line 160 "cmDependsJavaLexer.in.l"
{
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return jp_NAME;
@@ -1540,18 +1624,15 @@ YY_RULE_SETUP
case 108:
/* rule 108 can match eol */
YY_RULE_SETUP
-#line 165 "cmDependsJavaLexer.in.l"
{ }
YY_BREAK
case 109:
/* rule 109 can match eol */
YY_RULE_SETUP
-#line 166 "cmDependsJavaLexer.in.l"
{ }
YY_BREAK
case 110:
YY_RULE_SETUP
-#line 167 "cmDependsJavaLexer.in.l"
{
std::cerr << "Unknown character: " << yytext[0]
<< " (" << (int)yytext[0] << ")" << std::endl;
@@ -1561,10 +1642,8 @@ YY_RULE_SETUP
YY_BREAK
case 111:
YY_RULE_SETUP
-#line 174 "cmDependsJavaLexer.in.l"
ECHO;
YY_BREAK
-#line 1567 "cmDependsJavaLexer.cxx"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(comment):
case YY_STATE_EOF(string):
@@ -1584,7 +1663,7 @@ case YY_STATE_EOF(string):
/* 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
+ * 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
@@ -1644,7 +1723,7 @@ case YY_STATE_EOF(string):
{
yyg->yy_did_buffer_switch_on_eof = 0;
- if ( cmDependsJava_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
@@ -1698,7 +1777,7 @@ case YY_STATE_EOF(string):
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
-} /* end of cmDependsJava_yylex */
+} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
*
@@ -1712,7 +1791,7 @@ 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;
- yy_size_t number_to_move, i;
+ 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] )
@@ -1741,7 +1820,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Try to read more data. */
/* First move last chars to start of buffer. */
- number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
@@ -1777,7 +1856,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
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 );
+ yyrealloc( (void *) b->yy_ch_buf,
+ (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
}
else
/* Can't grow it, we don't own it. */
@@ -1809,7 +1889,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
- cmDependsJava_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
}
else
@@ -1823,12 +1903,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
ret_val = EOB_ACT_CONTINUE_SCAN;
- if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ if ((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. */
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cmDependsJava_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
+ (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ /* "- 2" to take care of EOB's */
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
}
yyg->yy_n_chars += number_to_move;
@@ -1862,9 +1945,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 327 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
}
return yy_current_state;
@@ -1891,9 +1974,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 327 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
yy_is_jam = (yy_current_state == 326);
(void)yyg;
@@ -1967,7 +2050,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{ /* need more input */
- int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
@@ -1984,13 +2067,13 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
*/
/* Reset buffer status. */
- cmDependsJava_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
- if ( cmDependsJava_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
return 0;
if ( ! yyg->yy_did_buffer_switch_on_eof )
@@ -2022,34 +2105,34 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
* @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)
+ void yyrestart (FILE * input_file , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! YY_CURRENT_BUFFER ){
- cmDependsJava_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmDependsJava_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmDependsJava_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
- cmDependsJava_yy_load_buffer_state(yyscanner );
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
+ 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)
+ void 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);
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
*/
- cmDependsJava_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
if ( YY_CURRENT_BUFFER == new_buffer )
return;
@@ -2062,17 +2145,17 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- cmDependsJava_yy_load_buffer_state(yyscanner );
+ 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
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after 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)
+static void 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;
@@ -2087,35 +2170,35 @@ static void cmDependsJava_yy_load_buffer_state (yyscan_t yyscanner)
* @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 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 );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
- b->yy_buf_size = (yy_size_t)size;
+ 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 );
+ b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_is_our_buffer = 1;
- cmDependsJava_yy_init_buffer(b,file ,yyscanner);
+ yy_init_buffer( b, file , yyscanner);
return b;
}
/** Destroy the buffer.
- * @param b a buffer created with cmDependsJava_yy_create_buffer()
+ * @param b a buffer created with yy_create_buffer()
* @param yyscanner The scanner object.
*/
- void cmDependsJava_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+ void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -2126,28 +2209,28 @@ static void cmDependsJava_yy_load_buffer_state (yyscan_t yyscanner)
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
- cmDependsJava_yyfree((void *) b->yy_ch_buf ,yyscanner );
+ yyfree( (void *) b->yy_ch_buf , yyscanner );
- cmDependsJava_yyfree((void *) b ,yyscanner );
+ 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 cmDependsJava_yyrestart() or at EOF.
+ * such as during a yyrestart() or at EOF.
*/
- static void cmDependsJava_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+ static void 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);
+ 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.
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from 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){
@@ -2164,7 +2247,7 @@ static void cmDependsJava_yy_load_buffer_state (yyscan_t yyscanner)
* @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)
+ void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! b )
@@ -2185,7 +2268,7 @@ static void cmDependsJava_yy_load_buffer_state (yyscan_t yyscanner)
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == YY_CURRENT_BUFFER )
- cmDependsJava_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
/** Pushes the new state onto the stack. The new state becomes
@@ -2194,15 +2277,15 @@ static void cmDependsJava_yy_load_buffer_state (yyscan_t yyscanner)
* @param new_buffer The new state.
* @param yyscanner The scanner object.
*/
-void cmDependsJava_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+void 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);
+ yyensure_buffer_stack(yyscanner);
- /* This block is copied from cmDependsJava_yy_switch_to_buffer. */
+ /* This block is copied from yy_switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
@@ -2216,8 +2299,8 @@ void cmDependsJava_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yy
yyg->yy_buffer_stack_top++;
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- /* copied from cmDependsJava_yy_switch_to_buffer. */
- cmDependsJava_yy_load_buffer_state(yyscanner );
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
@@ -2225,19 +2308,19 @@ void cmDependsJava_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yy
* The next element becomes the new top.
* @param yyscanner The scanner object.
*/
-void cmDependsJava_yypop_buffer_state (yyscan_t yyscanner)
+void 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_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 );
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
}
@@ -2245,9 +2328,9 @@ void cmDependsJava_yypop_buffer_state (yyscan_t yyscanner)
/* Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
-static void cmDependsJava_yyensure_buffer_stack (yyscan_t yyscanner)
+static void yyensure_buffer_stack (yyscan_t yyscanner)
{
- int num_to_alloc;
+ yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
@@ -2257,11 +2340,11 @@ static void cmDependsJava_yyensure_buffer_stack (yyscan_t yyscanner)
* immediate realloc on the next call.
*/
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmDependsJava_yyalloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
if ( ! yyg->yy_buffer_stack )
- YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yyensure_buffer_stack()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
@@ -2276,12 +2359,12 @@ static void cmDependsJava_yyensure_buffer_stack (yyscan_t yyscanner)
yy_size_t grow_size = 8 /* arbitrary grow size */;
num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmDependsJava_yyrealloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)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 cmDependsJava_yyensure_buffer_stack()" );
+ YY_FATAL_ERROR( "out of dynamic memory in 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*));
@@ -2295,7 +2378,7 @@ static void cmDependsJava_yyensure_buffer_stack (yyscan_t yyscanner)
* @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 yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
@@ -2305,11 +2388,11 @@ YY_BUFFER_STATE cmDependsJava_yy_scan_buffer (char * base, yy_size_t size , yy
/* They forgot to leave room for the EOB's. */
return NULL;
- b = (YY_BUFFER_STATE) cmDependsJava_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_scan_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_size = (int) (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 = NULL;
@@ -2319,53 +2402,53 @@ YY_BUFFER_STATE cmDependsJava_yy_scan_buffer (char * base, yy_size_t size , yy
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
- cmDependsJava_yy_switch_to_buffer(b ,yyscanner );
+ yy_switch_to_buffer( b , yyscanner );
return b;
}
-/** Setup the input buffer state to scan a string. The next call to cmDependsJava_yylex() will
+/** Setup the input buffer state to scan a string. The next call to 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
- * cmDependsJava_yy_scan_bytes() instead.
+ * yy_scan_bytes() instead.
*/
-YY_BUFFER_STATE cmDependsJava_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
{
- return cmDependsJava_yy_scan_bytes(yystr,(int) strlen(yystr) ,yyscanner);
+ return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
}
-/** Setup the input buffer state to scan the given bytes. The next call to cmDependsJava_yylex() will
+/** Setup the input buffer state to scan the given bytes. The next call to 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 cmDependsJava_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
- yy_size_t i;
+ int i;
/* Get memory for full buffer, including space for trailing EOB's. */
- n = (yy_size_t) _yybytes_len + 2;
- buf = (char *) cmDependsJava_yyalloc(n ,yyscanner );
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) yyalloc( n , yyscanner );
if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmDependsJava_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
- for ( i = 0; i < (size_t)_yybytes_len; ++i )
+ for ( i = 0; i < _yybytes_len; ++i )
buf[i] = yybytes[i];
buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
- b = cmDependsJava_yy_scan_buffer(buf,n ,yyscanner);
+ b = yy_scan_buffer( buf, n , yyscanner);
if ( ! b )
- YY_FATAL_ERROR( "bad buffer in cmDependsJava_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
@@ -2379,11 +2462,11 @@ YY_BUFFER_STATE cmDependsJava_yy_scan_bytes (yyconst char * yybytes, int _yyby
#define YY_EXIT_FAILURE 2
#endif
-static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- (void) fprintf( stderr, "%s\n", msg );
+ fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
@@ -2409,7 +2492,7 @@ static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
/** Get the user-defined data for this scanner.
* @param yyscanner The scanner object.
*/
-YY_EXTRA_TYPE cmDependsJava_yyget_extra (yyscan_t yyscanner)
+YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyextra;
@@ -2418,7 +2501,7 @@ YY_EXTRA_TYPE cmDependsJava_yyget_extra (yyscan_t yyscanner)
/** Get the current line number.
* @param yyscanner The scanner object.
*/
-int cmDependsJava_yyget_lineno (yyscan_t yyscanner)
+int yyget_lineno (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -2431,7 +2514,7 @@ int cmDependsJava_yyget_lineno (yyscan_t yyscanner)
/** Get the current column number.
* @param yyscanner The scanner object.
*/
-int cmDependsJava_yyget_column (yyscan_t yyscanner)
+int yyget_column (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -2444,7 +2527,7 @@ int cmDependsJava_yyget_column (yyscan_t yyscanner)
/** Get the input stream.
* @param yyscanner The scanner object.
*/
-FILE *cmDependsJava_yyget_in (yyscan_t yyscanner)
+FILE *yyget_in (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyin;
@@ -2453,7 +2536,7 @@ FILE *cmDependsJava_yyget_in (yyscan_t yyscanner)
/** Get the output stream.
* @param yyscanner The scanner object.
*/
-FILE *cmDependsJava_yyget_out (yyscan_t yyscanner)
+FILE *yyget_out (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyout;
@@ -2462,7 +2545,7 @@ FILE *cmDependsJava_yyget_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
-int cmDependsJava_yyget_leng (yyscan_t yyscanner)
+int yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
@@ -2472,7 +2555,7 @@ int cmDependsJava_yyget_leng (yyscan_t yyscanner)
* @param yyscanner The scanner object.
*/
-char *cmDependsJava_yyget_text (yyscan_t yyscanner)
+char *yyget_text (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yytext;
@@ -2482,7 +2565,7 @@ char *cmDependsJava_yyget_text (yyscan_t yyscanner)
* @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)
+void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyextra = user_defined ;
@@ -2492,13 +2575,13 @@ void cmDependsJava_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner
* @param _line_number line number
* @param yyscanner The scanner object.
*/
-void cmDependsJava_yyset_lineno (int _line_number , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
yylineno = _line_number;
}
@@ -2507,13 +2590,13 @@ void cmDependsJava_yyset_lineno (int _line_number , yyscan_t yyscanner)
* @param _column_no column number
* @param yyscanner The scanner object.
*/
-void cmDependsJava_yyset_column (int _column_no , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_column called with no buffer" );
yycolumn = _column_no;
}
@@ -2522,27 +2605,27 @@ void cmDependsJava_yyset_column (int _column_no , yyscan_t yyscanner)
* input buffer.
* @param _in_str A readable stream.
* @param yyscanner The scanner object.
- * @see cmDependsJava_yy_switch_to_buffer
+ * @see yy_switch_to_buffer
*/
-void cmDependsJava_yyset_in (FILE * _in_str , yyscan_t yyscanner)
+void 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)
+void 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)
+int 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)
+void yyset_debug (int _bdebug , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ;
@@ -2552,20 +2635,18 @@ void cmDependsJava_yyset_debug (int _bdebug , yyscan_t yyscanner)
/* User-visible API */
-/* cmDependsJava_yylex_init is special because it creates the scanner itself, so it is
+/* 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)
-
+int 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 );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -2578,27 +2659,25 @@ int cmDependsJava_yylex_init(yyscan_t* ptr_yy_globals)
return yy_init_globals ( *ptr_yy_globals );
}
-/* cmDependsJava_yylex_init_extra has the same functionality as cmDependsJava_yylex_init, but follows the
+/* yylex_init_extra has the same functionality as 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 cmDependsJava_yyalloc in
+ * The user defined value in the first argument will be available to yyalloc in
* the yyextra field.
*/
-
-int cmDependsJava_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
-
+int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
{
struct yyguts_t dummy_yyguts;
- cmDependsJava_yyset_extra (yy_user_defined, &dummy_yyguts);
+ yyset_extra (yy_user_defined, &dummy_yyguts);
if (ptr_yy_globals == NULL){
errno = EINVAL;
return 1;
}
- *ptr_yy_globals = (yyscan_t) cmDependsJava_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -2609,7 +2688,7 @@ int cmDependsJava_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_y
yy_init_globals. Leave at 0x00 for releases. */
memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
- cmDependsJava_yyset_extra (yy_user_defined, *ptr_yy_globals);
+ yyset_extra (yy_user_defined, *ptr_yy_globals);
return yy_init_globals ( *ptr_yy_globals );
}
@@ -2618,7 +2697,7 @@ 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 cmDependsJava_yylex_destroy(), so don't allocate here.
+ * This function is called from yylex_destroy(), so don't allocate here.
*/
yyg->yy_buffer_stack = NULL;
@@ -2642,37 +2721,37 @@ static int yy_init_globals (yyscan_t yyscanner)
#endif
/* For future reference: Set errno on error, since we are called by
- * cmDependsJava_yylex_init()
+ * yylex_init()
*/
return 0;
}
-/* cmDependsJava_yylex_destroy is for both reentrant and non-reentrant scanners. */
-int cmDependsJava_yylex_destroy (yyscan_t yyscanner)
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int 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_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
YY_CURRENT_BUFFER_LVALUE = NULL;
- cmDependsJava_yypop_buffer_state(yyscanner);
+ yypop_buffer_state(yyscanner);
}
/* Destroy the stack itself. */
- cmDependsJava_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyfree(yyg->yy_buffer_stack , yyscanner);
yyg->yy_buffer_stack = NULL;
/* Destroy the start condition stack. */
- cmDependsJava_yyfree(yyg->yy_start_stack ,yyscanner );
+ 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
- * cmDependsJava_yylex() is called, initialization will occur. */
+ * yylex() is called, initialization will occur. */
yy_init_globals( yyscanner);
/* Destroy the main struct (reentrant only). */
- cmDependsJava_yyfree ( yyscanner , yyscanner );
+ yyfree ( yyscanner , yyscanner );
yyscanner = NULL;
return 0;
}
@@ -2682,7 +2761,7 @@ int cmDependsJava_yylex_destroy (yyscan_t yyscanner)
*/
#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2694,7 +2773,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
{
int n;
for ( n = 0; s[n]; ++n )
@@ -2704,14 +2783,14 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
}
#endif
-void *cmDependsJava_yyalloc (yy_size_t size , yyscan_t yyscanner)
+void *yyalloc (yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
return malloc(size);
}
-void *cmDependsJava_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
+void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2726,13 +2805,15 @@ void *cmDependsJava_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner
return realloc(ptr, size);
}
-void cmDependsJava_yyfree (void * ptr , yyscan_t yyscanner)
+void yyfree (void * ptr , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- free( (char *) ptr ); /* see cmDependsJava_yyrealloc() for (char *) cast */
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
-#line 174 "cmDependsJavaLexer.in.l"
+/*--------------------------------------------------------------------------*/
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmDependsJavaLexer.h b/Source/LexerParser/cmDependsJavaLexer.h
index ccadd70b9..f1e87d246 100644
--- a/Source/LexerParser/cmDependsJavaLexer.h
+++ b/Source/LexerParser/cmDependsJavaLexer.h
@@ -2,10 +2,6 @@
#define cmDependsJava_yyHEADER_H 1
#define cmDependsJava_yyIN_HEADER 1
-#line 6 "cmDependsJavaLexer.h"
-
-#line 8 "cmDependsJavaLexer.h"
-
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -14,11 +10,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmDependsJava_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmDependsJava_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmDependsJava_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmDependsJava_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmDependsJava_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmDependsJava_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmDependsJava_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmDependsJava_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmDependsJava_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmDependsJava_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmDependsJava_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmDependsJava_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmDependsJava_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmDependsJava_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmDependsJava_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmDependsJava_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmDependsJava_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmDependsJava_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmDependsJava_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmDependsJava_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmDependsJava_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmDependsJava_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmDependsJava_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmDependsJava_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmDependsJava_yylex_ALREADY_DEFINED
+#else
+#define yylex cmDependsJava_yylex
+#endif
+
+#ifdef yyrestart
+#define cmDependsJava_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmDependsJava_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmDependsJava_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmDependsJava_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmDependsJava_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmDependsJava_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmDependsJava_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmDependsJava_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmDependsJava_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmDependsJava_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmDependsJava_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmDependsJava_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmDependsJava_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmDependsJava_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmDependsJava_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmDependsJava_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmDependsJava_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmDependsJava_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmDependsJava_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmDependsJava_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmDependsJava_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmDependsJava_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmDependsJava_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmDependsJava_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmDependsJava_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmDependsJava_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmDependsJava_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmDependsJava_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmDependsJava_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmDependsJava_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmDependsJava_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmDependsJava_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmDependsJava_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmDependsJava_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmDependsJava_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmDependsJava_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmDependsJava_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmDependsJava_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmDependsJava_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmDependsJava_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmDependsJava_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmDependsJava_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmDependsJava_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmDependsJava_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -89,10 +295,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -193,21 +405,21 @@ struct yy_buffer_state
};
#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 );
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void 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 );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const 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 );
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
/* Begin user sect3 */
@@ -227,42 +439,42 @@ void cmDependsJava_yyfree (void * ,yyscan_t yyscanner );
#define YY_EXTRA_TYPE void *
#endif
-int cmDependsJava_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmDependsJava_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 cmDependsJava_yylex_destroy (yyscan_t yyscanner );
+int yylex_destroy ( yyscan_t yyscanner );
-int cmDependsJava_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmDependsJava_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmDependsJava_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmDependsJava_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmDependsJava_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmDependsJava_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmDependsJava_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmDependsJava_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmDependsJava_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmDependsJava_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmDependsJava_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmDependsJava_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmDependsJava_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmDependsJava_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -270,18 +482,18 @@ void cmDependsJava_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmDependsJava_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmDependsJava_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
@@ -309,9 +521,9 @@ static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmDependsJava_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmDependsJava_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* yy_get_previous_state - get the state just before the EOB char was reached */
@@ -328,9 +540,150 @@ extern int cmDependsJava_yylex (yyscan_t yyscanner);
#undef YY_DECL
#endif
-#line 174 "cmDependsJavaLexer.in.l"
-
+#ifndef cmDependsJava_yy_create_buffer_ALREADY_DEFINED
+#undef yy_create_buffer
+#endif
+#ifndef cmDependsJava_yy_delete_buffer_ALREADY_DEFINED
+#undef yy_delete_buffer
+#endif
+#ifndef cmDependsJava_yy_scan_buffer_ALREADY_DEFINED
+#undef yy_scan_buffer
+#endif
+#ifndef cmDependsJava_yy_scan_string_ALREADY_DEFINED
+#undef yy_scan_string
+#endif
+#ifndef cmDependsJava_yy_scan_bytes_ALREADY_DEFINED
+#undef yy_scan_bytes
+#endif
+#ifndef cmDependsJava_yy_init_buffer_ALREADY_DEFINED
+#undef yy_init_buffer
+#endif
+#ifndef cmDependsJava_yy_flush_buffer_ALREADY_DEFINED
+#undef yy_flush_buffer
+#endif
+#ifndef cmDependsJava_yy_load_buffer_state_ALREADY_DEFINED
+#undef yy_load_buffer_state
+#endif
+#ifndef cmDependsJava_yy_switch_to_buffer_ALREADY_DEFINED
+#undef yy_switch_to_buffer
+#endif
+#ifndef cmDependsJava_yypush_buffer_state_ALREADY_DEFINED
+#undef yypush_buffer_state
+#endif
+#ifndef cmDependsJava_yypop_buffer_state_ALREADY_DEFINED
+#undef yypop_buffer_state
+#endif
+#ifndef cmDependsJava_yyensure_buffer_stack_ALREADY_DEFINED
+#undef yyensure_buffer_stack
+#endif
+#ifndef cmDependsJava_yylex_ALREADY_DEFINED
+#undef yylex
+#endif
+#ifndef cmDependsJava_yyrestart_ALREADY_DEFINED
+#undef yyrestart
+#endif
+#ifndef cmDependsJava_yylex_init_ALREADY_DEFINED
+#undef yylex_init
+#endif
+#ifndef cmDependsJava_yylex_init_extra_ALREADY_DEFINED
+#undef yylex_init_extra
+#endif
+#ifndef cmDependsJava_yylex_destroy_ALREADY_DEFINED
+#undef yylex_destroy
+#endif
+#ifndef cmDependsJava_yyget_debug_ALREADY_DEFINED
+#undef yyget_debug
+#endif
+#ifndef cmDependsJava_yyset_debug_ALREADY_DEFINED
+#undef yyset_debug
+#endif
+#ifndef cmDependsJava_yyget_extra_ALREADY_DEFINED
+#undef yyget_extra
+#endif
+#ifndef cmDependsJava_yyset_extra_ALREADY_DEFINED
+#undef yyset_extra
+#endif
+#ifndef cmDependsJava_yyget_in_ALREADY_DEFINED
+#undef yyget_in
+#endif
+#ifndef cmDependsJava_yyset_in_ALREADY_DEFINED
+#undef yyset_in
+#endif
+#ifndef cmDependsJava_yyget_out_ALREADY_DEFINED
+#undef yyget_out
+#endif
+#ifndef cmDependsJava_yyset_out_ALREADY_DEFINED
+#undef yyset_out
+#endif
+#ifndef cmDependsJava_yyget_leng_ALREADY_DEFINED
+#undef yyget_leng
+#endif
+#ifndef cmDependsJava_yyget_text_ALREADY_DEFINED
+#undef yyget_text
+#endif
+#ifndef cmDependsJava_yyget_lineno_ALREADY_DEFINED
+#undef yyget_lineno
+#endif
+#ifndef cmDependsJava_yyset_lineno_ALREADY_DEFINED
+#undef yyset_lineno
+#endif
+#ifndef cmDependsJava_yyget_column_ALREADY_DEFINED
+#undef yyget_column
+#endif
+#ifndef cmDependsJava_yyset_column_ALREADY_DEFINED
+#undef yyset_column
+#endif
+#ifndef cmDependsJava_yywrap_ALREADY_DEFINED
+#undef yywrap
+#endif
+#ifndef cmDependsJava_yyget_lval_ALREADY_DEFINED
+#undef yyget_lval
+#endif
+#ifndef cmDependsJava_yyset_lval_ALREADY_DEFINED
+#undef yyset_lval
+#endif
+#ifndef cmDependsJava_yyget_lloc_ALREADY_DEFINED
+#undef yyget_lloc
+#endif
+#ifndef cmDependsJava_yyset_lloc_ALREADY_DEFINED
+#undef yyset_lloc
+#endif
+#ifndef cmDependsJava_yyalloc_ALREADY_DEFINED
+#undef yyalloc
+#endif
+#ifndef cmDependsJava_yyrealloc_ALREADY_DEFINED
+#undef yyrealloc
+#endif
+#ifndef cmDependsJava_yyfree_ALREADY_DEFINED
+#undef yyfree
+#endif
+#ifndef cmDependsJava_yytext_ALREADY_DEFINED
+#undef yytext
+#endif
+#ifndef cmDependsJava_yyleng_ALREADY_DEFINED
+#undef yyleng
+#endif
+#ifndef cmDependsJava_yyin_ALREADY_DEFINED
+#undef yyin
+#endif
+#ifndef cmDependsJava_yyout_ALREADY_DEFINED
+#undef yyout
+#endif
+#ifndef cmDependsJava_yy_flex_debug_ALREADY_DEFINED
+#undef yy_flex_debug
+#endif
+#ifndef cmDependsJava_yylineno_ALREADY_DEFINED
+#undef yylineno
+#endif
+#ifndef cmDependsJava_yytables_fload_ALREADY_DEFINED
+#undef yytables_fload
+#endif
+#ifndef cmDependsJava_yytables_destroy_ALREADY_DEFINED
+#undef yytables_destroy
+#endif
+#ifndef cmDependsJava_yyTABLES_NAME_ALREADY_DEFINED
+#undef yyTABLES_NAME
+#endif
-#line 335 "cmDependsJavaLexer.h"
#undef cmDependsJava_yyIN_HEADER
#endif /* cmDependsJava_yyHEADER_H */
diff --git a/Source/LexerParser/cmDependsJavaLexer.in.l b/Source/LexerParser/cmDependsJavaLexer.in.l
index 8cb42b17a..3dd3c224a 100644
--- a/Source/LexerParser/cmDependsJavaLexer.in.l
+++ b/Source/LexerParser/cmDependsJavaLexer.in.l
@@ -7,18 +7,19 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmDependsJava_yy --header-file=cmDependsJavaLexer.h -ocmDependsJavaLexer.cxx cmDependsJavaLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline --header-file=cmDependsJavaLexer.h -ocmDependsJavaLexer.cxx cmDependsJavaLexer.in.l
Modify cmDependsJavaLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmDependsJavaLexer.h cmDependsJavaLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in yy_scan_bytes for loop condition of _yybytes_len to size_t
+ - remove trailing whitespace: sed -i 's/\s*$//' cmDependsJavaLexer.h cmDependsJavaLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmDependsJavaLexer.h cmDependsJavaLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmDependsJavaLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#include <iostream>
#include "cmDependsJavaParserHelper.h"
@@ -26,7 +27,7 @@ Modify cmDependsJavaLexer.cxx:
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = yyextra->LexInput(buf, max_size); }
+ do { result = yyextra->LexInput(buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmDependsJavaParserTokens.h"
@@ -38,6 +39,8 @@ Modify cmDependsJavaLexer.cxx:
/*--------------------------------------------------------------------------*/
%}
+%option prefix="cmDependsJava_yy"
+
%option reentrant
%option noyywrap
%pointer
@@ -172,3 +175,7 @@ null { PRIMITIVE; return jp_NULLLITERAL; }
}
%%
+
+/*--------------------------------------------------------------------------*/
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmDependsJavaParser.cxx b/Source/LexerParser/cmDependsJavaParser.cxx
index bc45d45e1..e83afa9ea 100644
--- a/Source/LexerParser/cmDependsJavaParser.cxx
+++ b/Source/LexerParser/cmDependsJavaParser.cxx
@@ -107,7 +107,7 @@ static void cmDependsJava_yyerror(yyscan_t yyscanner, const char* message);
#define YYMAXDEPTH 1000000
-#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp);
+#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. */
@@ -115,8 +115,11 @@ static void cmDependsJava_yyerror(yyscan_t yyscanner, const char* message);
# pragma warning (disable: 4102) /* Unused goto label. */
# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
-#line 120 "cmDependsJavaParser.cxx" /* yacc.c:339 */
+#line 123 "cmDependsJavaParser.cxx" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
@@ -371,7 +374,7 @@ int cmDependsJava_yyparse (yyscan_t yyscanner);
/* Copy the second part of user declarations. */
-#line 375 "cmDependsJavaParser.cxx" /* yacc.c:358 */
+#line 378 "cmDependsJavaParser.cxx" /* yacc.c:358 */
#ifdef short
# undef short
@@ -679,42 +682,42 @@ static const yytype_uint8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 179, 179, 188, 196, 204, 212, 220, 228, 237,
- 245, 254, 262, 271, 276, 281, 286, 291, 296, 301,
- 306, 312, 320, 329, 339, 348, 357, 365, 375, 381,
- 388, 395, 401, 408, 417, 427, 437, 446, 454, 463,
- 472, 478, 487, 493, 502, 508, 517, 529, 537, 546,
- 558, 571, 579, 587, 596, 604, 613, 613, 613, 614,
- 615, 615, 615, 615, 615, 615, 616, 619, 629, 638,
- 647, 656, 666, 672, 681, 690, 699, 707, 716, 725,
- 731, 740, 748, 756, 764, 773, 781, 790, 796, 804,
- 813, 821, 830, 839, 848, 856, 865, 873, 881, 890,
- 899, 909, 916, 926, 936, 943, 950, 953, 959, 969,
- 979, 989, 995, 1005, 1015, 1025, 1034, 1044, 1055, 1065,
- 1072, 1082, 1091, 1101, 1110, 1120, 1126, 1136, 1145, 1155,
- 1165, 1172, 1181, 1190, 1199, 1208, 1216, 1225, 1234, 1244,
- 1254, 1263, 1273, 1283, 1290, 1299, 1309, 1318, 1328, 1337,
- 1344, 1354, 1363, 1373, 1382, 1391, 1401, 1411, 1420, 1430,
- 1439, 1448, 1457, 1466, 1475, 1485, 1494, 1503, 1512, 1521,
- 1531, 1540, 1549, 1558, 1567, 1576, 1585, 1594, 1603, 1612,
- 1621, 1630, 1640, 1650, 1661, 1671, 1681, 1690, 1699, 1708,
- 1717, 1726, 1735, 1745, 1755, 1765, 1775, 1782, 1789, 1796,
- 1806, 1813, 1823, 1833, 1842, 1852, 1861, 1871, 1878, 1885,
- 1892, 1900, 1907, 1917, 1924, 1934, 1944, 1951, 1961, 1970,
- 1980, 1990, 1999, 2009, 2018, 2028, 2039, 2046, 2053, 2064,
- 2074, 2084, 2094, 2103, 2113, 2120, 2130, 2139, 2149, 2156,
- 2166, 2175, 2185, 2194, 2200, 2209, 2218, 2227, 2236, 2246,
- 2256, 2263, 2273, 2280, 2290, 2299, 2309, 2318, 2327, 2336,
- 2346, 2353, 2363, 2372, 2382, 2392, 2398, 2405, 2415, 2425,
- 2435, 2446, 2456, 2467, 2477, 2488, 2498, 2508, 2517, 2526,
- 2535, 2544, 2554, 2564, 2574, 2583, 2592, 2601, 2610, 2620,
- 2630, 2640, 2649, 2658, 2667, 2677, 2686, 2695, 2702, 2711,
- 2720, 2729, 2739, 2748, 2757, 2767, 2776, 2785, 2794, 2804,
- 2813, 2822, 2831, 2840, 2849, 2859, 2868, 2877, 2887, 2896,
- 2906, 2915, 2925, 2934, 2944, 2953, 2963, 2972, 2982, 2991,
- 3001, 3010, 3020, 3030, 3040, 3049, 3059, 3068, 3077, 3086,
- 3095, 3104, 3113, 3122, 3131, 3140, 3149, 3158, 3168, 3178,
- 3188, 3197
+ 0, 182, 182, 191, 199, 207, 215, 223, 231, 240,
+ 248, 257, 265, 274, 279, 284, 289, 294, 299, 304,
+ 309, 315, 323, 332, 342, 351, 360, 368, 378, 384,
+ 391, 398, 404, 411, 420, 430, 440, 449, 457, 466,
+ 475, 481, 490, 496, 505, 511, 520, 532, 540, 549,
+ 561, 574, 582, 590, 599, 607, 616, 616, 616, 617,
+ 618, 618, 618, 618, 618, 618, 619, 622, 632, 641,
+ 650, 659, 669, 675, 684, 693, 702, 710, 719, 728,
+ 734, 743, 751, 759, 767, 776, 784, 793, 799, 807,
+ 816, 824, 833, 842, 851, 859, 868, 876, 884, 893,
+ 902, 912, 919, 929, 939, 946, 953, 956, 962, 972,
+ 982, 992, 998, 1008, 1018, 1028, 1037, 1047, 1058, 1068,
+ 1075, 1085, 1094, 1104, 1113, 1123, 1129, 1139, 1148, 1158,
+ 1168, 1175, 1184, 1193, 1202, 1211, 1219, 1228, 1237, 1247,
+ 1257, 1266, 1276, 1286, 1293, 1302, 1312, 1321, 1331, 1340,
+ 1347, 1357, 1366, 1376, 1385, 1394, 1404, 1414, 1423, 1433,
+ 1442, 1451, 1460, 1469, 1478, 1488, 1497, 1506, 1515, 1524,
+ 1534, 1543, 1552, 1561, 1570, 1579, 1588, 1597, 1606, 1615,
+ 1624, 1633, 1643, 1653, 1664, 1674, 1684, 1693, 1702, 1711,
+ 1720, 1729, 1738, 1748, 1758, 1768, 1778, 1785, 1792, 1799,
+ 1809, 1816, 1826, 1836, 1845, 1855, 1864, 1874, 1881, 1888,
+ 1895, 1903, 1910, 1920, 1927, 1937, 1947, 1954, 1964, 1973,
+ 1983, 1993, 2002, 2012, 2021, 2031, 2042, 2049, 2056, 2067,
+ 2077, 2087, 2097, 2106, 2116, 2123, 2133, 2142, 2152, 2159,
+ 2169, 2178, 2188, 2197, 2203, 2212, 2221, 2230, 2239, 2249,
+ 2259, 2266, 2276, 2283, 2293, 2302, 2312, 2321, 2330, 2339,
+ 2349, 2356, 2366, 2375, 2385, 2395, 2401, 2408, 2418, 2428,
+ 2438, 2449, 2459, 2470, 2480, 2491, 2501, 2511, 2520, 2529,
+ 2538, 2547, 2557, 2567, 2577, 2586, 2595, 2604, 2613, 2623,
+ 2633, 2643, 2652, 2661, 2670, 2680, 2689, 2698, 2705, 2714,
+ 2723, 2732, 2742, 2751, 2760, 2770, 2779, 2788, 2797, 2807,
+ 2816, 2825, 2834, 2843, 2852, 2862, 2871, 2880, 2890, 2899,
+ 2909, 2918, 2928, 2937, 2947, 2956, 2966, 2975, 2985, 2994,
+ 3004, 3013, 3023, 3033, 3043, 3052, 3062, 3071, 3080, 3089,
+ 3098, 3107, 3116, 3125, 3134, 3143, 3152, 3161, 3171, 3181,
+ 3191, 3200
};
#endif
@@ -2282,214 +2285,214 @@ yyreduce:
switch (yyn)
{
case 2:
-#line 180 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 183 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2293 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2296 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 3:
-#line 189 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 192 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2304 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2307 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 4:
-#line 197 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 200 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2315 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2318 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 5:
-#line 205 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 208 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2326 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2329 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 6:
-#line 213 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 216 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2337 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2340 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 7:
-#line 221 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 224 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2348 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2351 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 8:
-#line 229 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 232 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2359 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2362 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 9:
-#line 238 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 241 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2370 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2373 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 10:
-#line 246 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 249 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2381 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2384 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 11:
-#line 255 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 258 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2392 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2395 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 12:
-#line 263 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 266 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2403 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2406 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 13:
-#line 272 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 275 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2411 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2414 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 14:
-#line 277 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 280 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2419 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2422 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 15:
-#line 282 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 285 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2427 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2430 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 16:
-#line 287 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 290 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2435 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2438 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 17:
-#line 292 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 295 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2443 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2446 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 18:
-#line 297 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 300 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2451 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2454 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 19:
-#line 302 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 305 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2459 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2462 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 20:
-#line 307 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 310 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
}
-#line 2467 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2470 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 21:
-#line 313 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 316 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2478 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2481 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 22:
-#line 321 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 324 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2489 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2492 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 23:
-#line 330 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 333 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpStoreClass((yyvsp[0].str));
@@ -2497,44 +2500,44 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2501 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2504 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 24:
-#line 340 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 343 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2512 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2515 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 25:
-#line 349 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 352 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2523 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2526 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 26:
-#line 358 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 361 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2534 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2537 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 27:
-#line 366 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 369 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpStoreClass((yyvsp[-1].str));
@@ -2542,56 +2545,56 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2546 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2549 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 28:
-#line 376 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 379 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = (yyvsp[0].str);
}
-#line 2555 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2558 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 29:
-#line 382 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 385 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = (yyvsp[0].str);
}
-#line 2564 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2567 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 30:
-#line 389 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 392 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = (yyvsp[0].str);
}
-#line 2573 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2576 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 31:
-#line 396 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 399 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = (yyvsp[0].str);
}
-#line 2582 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2585 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 32:
-#line 402 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 405 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
(yyval.str) = (yyvsp[0].str);
}
-#line 2591 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2594 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 33:
-#line 409 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 412 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->AddClassFound((yyvsp[-2].str));
@@ -2599,11 +2602,11 @@ yyreduce:
yyGetParser->DeallocateParserType(&((yyvsp[-2].str)));
(yyval.str) = const_cast<char*>(yyGetParser->GetCurrentCombine());
}
-#line 2603 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2606 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 34:
-#line 418 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 421 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpStoreClass((yyvsp[-2].str));
@@ -2612,11 +2615,11 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2616 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2619 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 35:
-#line 428 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 431 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpStoreClass((yyvsp[-2].str));
@@ -2625,118 +2628,118 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2629 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2632 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 36:
-#line 438 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 441 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2640 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2643 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 37:
-#line 447 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 450 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2651 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2654 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 38:
-#line 455 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 458 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2662 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2665 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 39:
-#line 464 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 467 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2673 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2676 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 40:
-#line 472 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 475 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2683 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2686 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 41:
-#line 479 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 482 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2694 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2697 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 42:
-#line 487 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 490 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2704 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2707 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 43:
-#line 494 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 497 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2715 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2718 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 44:
-#line 502 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 505 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2725 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2728 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 45:
-#line 509 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 512 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2736 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2739 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 46:
-#line 518 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 521 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->SetCurrentPackage((yyvsp[-1].str));
@@ -2746,33 +2749,33 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2750 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2753 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 47:
-#line 530 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 533 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2761 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2764 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 48:
-#line 538 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 541 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2772 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2775 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 49:
-#line 547 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 550 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->AddPackagesImport((yyvsp[-1].str));
@@ -2782,11 +2785,11 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2786 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2789 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 50:
-#line 559 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 562 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
std::string str = (yyvsp[-3].str);
@@ -2797,77 +2800,77 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2801 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2804 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 51:
-#line 572 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 575 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2812 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2815 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 52:
-#line 580 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 583 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2823 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2826 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 53:
-#line 588 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 591 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2834 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2837 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 54:
-#line 597 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 600 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2845 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2848 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 55:
-#line 605 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 608 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2856 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2859 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 67:
-#line 620 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 623 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
yyGetParser->StartClass((yyvsp[0].str));
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
jpCheckEmpty(3);
}
-#line 2867 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2870 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 68:
-#line 630 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 633 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -2875,11 +2878,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
yyGetParser->EndClass();
}
-#line 2879 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2882 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 69:
-#line 639 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 642 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(2);
@@ -2887,11 +2890,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
yyGetParser->EndClass();
}
-#line 2891 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2894 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 70:
-#line 648 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 651 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -2899,11 +2902,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
yyGetParser->EndClass();
}
-#line 2903 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2906 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 71:
-#line 657 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 660 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -2911,226 +2914,226 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
yyGetParser->EndClass();
}
-#line 2915 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2918 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 72:
-#line 666 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 669 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2925 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2928 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 73:
-#line 673 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 676 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2936 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2939 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 74:
-#line 682 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 685 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2947 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2950 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 75:
-#line 691 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 694 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2958 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2961 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 76:
-#line 700 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 703 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2969 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2972 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 77:
-#line 708 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 711 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2980 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2983 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 78:
-#line 717 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 720 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 2991 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 2994 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 79:
-#line 725 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 728 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3001 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3004 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 80:
-#line 732 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 735 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3012 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3015 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 81:
-#line 741 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 744 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3023 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3026 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 82:
-#line 749 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 752 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3034 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3037 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 83:
-#line 757 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 760 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3045 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3048 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 84:
-#line 765 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 768 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3056 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3059 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 85:
-#line 774 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 777 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3067 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3070 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 86:
-#line 782 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 785 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3078 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3081 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 87:
-#line 791 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 794 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
}
-#line 3086 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3089 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 88:
-#line 797 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 800 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3097 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3100 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 89:
-#line 805 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 808 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3108 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3111 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 90:
-#line 814 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 817 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3119 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3122 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 91:
-#line 822 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 825 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3130 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3133 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 92:
-#line 831 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 834 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
@@ -3138,77 +3141,77 @@ yyreduce:
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3142 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3145 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 93:
-#line 840 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 843 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3153 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3156 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 94:
-#line 849 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 852 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3164 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3167 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 95:
-#line 857 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 860 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3175 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3178 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 96:
-#line 866 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 869 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3186 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3189 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 97:
-#line 874 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 877 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3197 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3200 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 98:
-#line 882 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 885 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3208 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3211 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 99:
-#line 891 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 894 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -3216,11 +3219,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3220 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3223 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 100:
-#line 900 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 903 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -3228,22 +3231,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3232 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3235 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 101:
-#line 909 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 912 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3243 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3246 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 102:
-#line 917 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 920 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3251,11 +3254,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3255 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3258 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 103:
-#line 927 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 930 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
yyGetParser->DeallocateParserType(&((yyvsp[-3].str)));
@@ -3264,40 +3267,40 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3268 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3271 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 104:
-#line 937 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 940 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
}
-#line 3277 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3280 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 105:
-#line 943 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 946 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3288 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3291 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 107:
-#line 954 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 957 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
}
-#line 3297 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3300 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 108:
-#line 960 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 963 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -3305,11 +3308,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3309 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3312 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 109:
-#line 970 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 973 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -3317,11 +3320,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3321 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3324 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 110:
-#line 980 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 983 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3329,20 +3332,20 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3333 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3336 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 111:
-#line 990 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 993 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
}
-#line 3342 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3345 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 112:
-#line 996 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 999 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -3350,11 +3353,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3354 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3357 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 113:
-#line 1006 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1009 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3362,11 +3365,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3366 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3369 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 114:
-#line 1016 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1019 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3374,11 +3377,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3378 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3381 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 115:
-#line 1026 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1029 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -3386,11 +3389,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3390 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3393 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 116:
-#line 1035 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1038 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -3398,11 +3401,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3402 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3405 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 117:
-#line 1045 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1048 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
yyGetParser->DeallocateParserType(&((yyvsp[-3].str)));
@@ -3411,11 +3414,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3415 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3418 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 118:
-#line 1056 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1059 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -3423,22 +3426,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3427 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3430 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 119:
-#line 1065 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1068 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3438 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3441 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 120:
-#line 1073 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1076 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3446,11 +3449,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3450 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3453 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 121:
-#line 1083 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1086 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -3458,11 +3461,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3462 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3465 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 122:
-#line 1092 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1095 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -3470,22 +3473,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3474 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3477 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 123:
-#line 1102 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1105 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
yyGetParser->StartClass((yyvsp[0].str));
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
jpCheckEmpty(3);
}
-#line 3485 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3488 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 124:
-#line 1111 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1114 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3493,21 +3496,21 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
yyGetParser->EndClass();
}
-#line 3497 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3500 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 125:
-#line 1120 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1123 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3507 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3510 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 126:
-#line 1127 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1130 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3515,11 +3518,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3519 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3522 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 127:
-#line 1137 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1140 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3527,11 +3530,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3531 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3534 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 128:
-#line 1146 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1149 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -3539,11 +3542,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3543 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3546 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 129:
-#line 1156 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1159 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -3551,33 +3554,33 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3555 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3558 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 130:
-#line 1165 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1168 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3566 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3569 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 131:
-#line 1173 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1176 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3577 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3580 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 132:
-#line 1182 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1185 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3585,11 +3588,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3589 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3592 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 133:
-#line 1191 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1194 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3597,11 +3600,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3601 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3604 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 134:
-#line 1200 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1203 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3609,22 +3612,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3613 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3616 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 135:
-#line 1209 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1212 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3624 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3627 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 136:
-#line 1217 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1220 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3632,22 +3635,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3636 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3639 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 137:
-#line 1226 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1229 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3647 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3650 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 138:
-#line 1235 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1238 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3655,11 +3658,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3659 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3662 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 139:
-#line 1245 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1248 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3667,11 +3670,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3671 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3674 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 140:
-#line 1255 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1258 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3679,11 +3682,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3683 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3686 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 141:
-#line 1264 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1267 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3691,11 +3694,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3695 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3698 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 142:
-#line 1274 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1277 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -3703,22 +3706,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3707 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3710 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 143:
-#line 1283 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1286 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3718 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3721 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 144:
-#line 1291 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1294 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3726,11 +3729,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3730 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3733 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 145:
-#line 1300 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1303 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -3738,11 +3741,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3742 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3745 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 146:
-#line 1310 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1313 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3750,11 +3753,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3754 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3757 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 147:
-#line 1319 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1322 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -3762,33 +3765,33 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3766 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3769 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 148:
-#line 1329 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1332 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3777 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3780 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 149:
-#line 1337 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1340 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 3788 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3791 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 150:
-#line 1345 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1348 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3796,11 +3799,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3800 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3803 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 151:
-#line 1355 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1358 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3808,11 +3811,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3812 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3815 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 152:
-#line 1364 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1367 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(2);
@@ -3820,11 +3823,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3824 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3827 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 153:
-#line 1374 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1377 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3832,11 +3835,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3836 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3839 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 154:
-#line 1383 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1386 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3844,11 +3847,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3848 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3851 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 155:
-#line 1392 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1395 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3856,11 +3859,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3860 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3863 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 156:
-#line 1402 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1405 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(2);
@@ -3868,11 +3871,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3872 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3875 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 157:
-#line 1412 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1415 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(3);
@@ -3880,11 +3883,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3884 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3887 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 158:
-#line 1421 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1424 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(2);
@@ -3892,11 +3895,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3896 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3899 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 159:
-#line 1431 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1434 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3904,11 +3907,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3908 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3911 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 160:
-#line 1440 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1443 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3916,11 +3919,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3920 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3923 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 161:
-#line 1449 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1452 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3928,11 +3931,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3932 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3935 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 162:
-#line 1458 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1461 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3940,11 +3943,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3944 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3947 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 163:
-#line 1467 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1470 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3952,11 +3955,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3956 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3959 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 164:
-#line 1476 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1479 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3964,11 +3967,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3968 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3971 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 165:
-#line 1486 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1489 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3976,11 +3979,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3980 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3983 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 166:
-#line 1495 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1498 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -3988,11 +3991,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 3992 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 3995 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 167:
-#line 1504 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1507 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4000,11 +4003,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4004 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4007 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 168:
-#line 1513 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1516 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4012,11 +4015,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4016 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4019 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 169:
-#line 1522 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1525 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4024,11 +4027,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4028 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4031 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 170:
-#line 1532 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1535 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4036,11 +4039,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4040 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4043 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 171:
-#line 1541 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1544 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4048,11 +4051,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4052 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4055 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 172:
-#line 1550 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1553 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4060,11 +4063,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4064 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4067 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 173:
-#line 1559 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1562 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4072,11 +4075,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4076 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4079 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 174:
-#line 1568 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1571 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4084,11 +4087,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4088 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4091 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 175:
-#line 1577 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1580 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4096,11 +4099,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4100 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4103 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 176:
-#line 1586 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1589 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4108,11 +4111,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4112 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4115 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 177:
-#line 1595 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1598 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4120,11 +4123,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4124 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4127 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 178:
-#line 1604 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1607 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4132,11 +4135,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4136 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4139 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 179:
-#line 1613 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1616 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4144,11 +4147,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4148 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4151 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 180:
-#line 1622 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1625 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4156,11 +4159,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4160 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4163 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 181:
-#line 1631 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1634 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4168,11 +4171,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4172 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4175 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 182:
-#line 1641 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1644 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4180,11 +4183,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4184 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4187 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 183:
-#line 1651 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1654 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[-2].str)));
@@ -4193,11 +4196,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4197 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4200 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 184:
-#line 1662 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1665 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4205,11 +4208,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4209 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4212 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 185:
-#line 1672 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1675 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -4217,11 +4220,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4221 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4224 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 186:
-#line 1682 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1685 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4229,11 +4232,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4233 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4236 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 187:
-#line 1691 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1694 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4241,11 +4244,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4245 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4248 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 188:
-#line 1700 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1703 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4253,11 +4256,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4257 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4260 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 189:
-#line 1709 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1712 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4265,11 +4268,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4269 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4272 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 190:
-#line 1718 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1721 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4277,11 +4280,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4281 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4284 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 191:
-#line 1727 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1730 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4289,11 +4292,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4293 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4296 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 192:
-#line 1736 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1739 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4301,11 +4304,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4305 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4308 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 193:
-#line 1746 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1749 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -4313,11 +4316,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4317 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4320 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 194:
-#line 1756 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1759 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(7);
jpCheckEmpty(7);
@@ -4325,11 +4328,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4329 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4332 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 195:
-#line 1766 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1769 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(7);
jpCheckEmpty(7);
@@ -4337,40 +4340,40 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4341 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4344 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 196:
-#line 1776 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1779 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
}
-#line 4350 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4353 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 197:
-#line 1783 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1786 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
}
-#line 4359 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4362 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 198:
-#line 1789 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1792 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4370 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4373 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 199:
-#line 1797 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1800 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4378,22 +4381,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4382 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4385 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 200:
-#line 1806 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1809 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4393 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4396 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 201:
-#line 1814 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1817 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -4401,11 +4404,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4405 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4408 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 202:
-#line 1824 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1827 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -4413,11 +4416,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4417 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4420 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 203:
-#line 1834 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1837 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4425,11 +4428,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4429 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4432 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 204:
-#line 1843 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1846 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -4437,11 +4440,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4441 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4444 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 205:
-#line 1853 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1856 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4449,11 +4452,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4453 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4456 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 206:
-#line 1862 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1865 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -4461,58 +4464,58 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4465 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4468 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 207:
-#line 1872 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1875 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
}
-#line 4474 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4477 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 208:
-#line 1879 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1882 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
}
-#line 4483 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4486 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 209:
-#line 1886 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1889 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(7);
}
-#line 4492 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4495 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 210:
-#line 1894 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1897 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(9);
}
-#line 4501 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4504 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 211:
-#line 1900 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1903 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4512 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4515 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 212:
-#line 1908 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1911 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4520,22 +4523,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4524 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4527 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 213:
-#line 1917 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1920 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4535 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4538 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 214:
-#line 1925 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1928 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4543,33 +4546,33 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4547 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4550 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 215:
-#line 1936 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1939 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(9);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4558 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4561 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 216:
-#line 1944 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1947 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4569 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4572 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 217:
-#line 1952 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1955 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4577,11 +4580,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4581 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4584 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 218:
-#line 1962 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1965 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4589,11 +4592,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4593 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4596 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 219:
-#line 1971 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1974 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4601,11 +4604,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4605 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4608 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 220:
-#line 1981 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1984 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4613,11 +4616,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4617 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4620 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 221:
-#line 1991 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 1994 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4625,11 +4628,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4629 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4632 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 222:
-#line 2000 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2003 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4637,11 +4640,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4641 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4644 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 223:
-#line 2010 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2013 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4649,11 +4652,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4653 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4656 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 224:
-#line 2019 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2022 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -4661,11 +4664,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4665 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4668 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 225:
-#line 2029 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2032 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[-1].str)));
@@ -4674,31 +4677,31 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4678 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4681 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 226:
-#line 2039 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2042 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4689 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4692 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 227:
-#line 2047 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2050 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
}
-#line 4698 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4701 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 228:
-#line 2054 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2057 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[-1].str)));
@@ -4707,11 +4710,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4711 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4714 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 229:
-#line 2065 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2068 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4719,11 +4722,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4723 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4726 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 230:
-#line 2075 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2078 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4731,11 +4734,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4735 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4738 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 231:
-#line 2085 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2088 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -4743,11 +4746,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4747 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4750 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 232:
-#line 2095 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2098 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4755,11 +4758,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4759 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4762 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 233:
-#line 2104 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2107 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -4767,22 +4770,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4771 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4774 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 234:
-#line 2113 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2116 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4782 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4785 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 235:
-#line 2121 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2124 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4790,11 +4793,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4794 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4797 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 236:
-#line 2131 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2134 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4802,11 +4805,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4806 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4809 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 237:
-#line 2140 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2143 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -4814,20 +4817,20 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4818 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4821 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 238:
-#line 2150 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2153 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
}
-#line 4827 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4830 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 239:
-#line 2157 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2160 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -4835,11 +4838,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4839 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4842 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 240:
-#line 2167 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2170 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4847,11 +4850,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4851 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4854 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 241:
-#line 2176 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2179 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4859,11 +4862,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4863 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4866 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 242:
-#line 2186 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2189 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4871,20 +4874,20 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4875 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4878 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 243:
-#line 2195 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2198 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
}
-#line 4884 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4887 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 244:
-#line 2201 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2204 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -4892,11 +4895,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4896 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4899 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 245:
-#line 2210 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2213 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4904,11 +4907,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4908 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4911 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 246:
-#line 2219 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2222 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4916,11 +4919,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4920 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4923 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 247:
-#line 2228 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2231 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4928,11 +4931,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4932 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4935 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 248:
-#line 2237 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2240 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4940,11 +4943,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4944 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4947 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 249:
-#line 2247 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2250 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(6);
jpCheckEmpty(6);
@@ -4952,22 +4955,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4956 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4959 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 250:
-#line 2256 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2259 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4967 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4970 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 251:
-#line 2264 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2267 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4975,22 +4978,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 4979 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4982 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 252:
-#line 2273 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2276 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 4990 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 4993 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 253:
-#line 2281 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2284 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -4998,11 +5001,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5002 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5005 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 254:
-#line 2291 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2294 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5010,11 +5013,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5014 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5017 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 255:
-#line 2300 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2303 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5022,11 +5025,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5026 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5029 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 256:
-#line 2310 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2313 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -5034,11 +5037,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5038 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5041 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 257:
-#line 2319 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2322 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -5046,11 +5049,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5050 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5053 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 258:
-#line 2328 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2331 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -5058,11 +5061,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5062 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5065 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 259:
-#line 2337 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2340 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -5070,22 +5073,22 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5074 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5077 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 260:
-#line 2346 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2349 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(0);
(yyval.str) = 0;
yyGetParser->SetCurrentCombine("");
}
-#line 5085 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5088 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 261:
-#line 2354 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2357 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5093,11 +5096,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5097 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5100 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 262:
-#line 2364 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2367 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5105,11 +5108,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5109 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5112 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 263:
-#line 2373 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2376 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5117,11 +5120,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5121 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5124 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 264:
-#line 2383 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2386 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5129,29 +5132,29 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5133 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5136 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 265:
-#line 2393 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2396 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
}
-#line 5142 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5145 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 266:
-#line 2399 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2402 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
}
-#line 5151 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5154 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 267:
-#line 2406 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2409 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
@@ -5160,11 +5163,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5164 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5167 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 268:
-#line 2416 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2419 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
@@ -5173,11 +5176,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5177 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5180 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 269:
-#line 2426 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2429 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
@@ -5186,11 +5189,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5190 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5193 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 270:
-#line 2436 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2439 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
@@ -5199,11 +5202,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5203 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5206 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 271:
-#line 2447 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2450 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
yyGetParser->DeallocateParserType(&((yyvsp[-3].str)));
@@ -5212,11 +5215,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5216 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5219 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 272:
-#line 2457 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2460 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(6);
yyGetParser->DeallocateParserType(&((yyvsp[-5].str)));
@@ -5226,11 +5229,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5230 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5233 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 273:
-#line 2468 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2471 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(6);
yyGetParser->DeallocateParserType(&((yyvsp[-3].str)));
@@ -5239,11 +5242,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5243 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5246 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 274:
-#line 2478 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2481 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(6);
yyGetParser->DeallocateParserType(&((yyvsp[-3].str)));
@@ -5252,11 +5255,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5256 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5259 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 275:
-#line 2489 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2492 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
yyGetParser->DeallocateParserType(&((yyvsp[-3].str)));
@@ -5265,11 +5268,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5269 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5272 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 276:
-#line 2499 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2502 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -5277,11 +5280,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5281 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5284 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 277:
-#line 2509 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2512 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5289,11 +5292,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5293 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5296 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 278:
-#line 2518 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2521 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
@@ -5301,11 +5304,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5305 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5308 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 279:
-#line 2527 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2530 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5313,11 +5316,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5317 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5320 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 280:
-#line 2536 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2539 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5325,11 +5328,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5329 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5332 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 281:
-#line 2545 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2548 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5337,11 +5340,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5341 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5344 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 282:
-#line 2555 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2558 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5349,11 +5352,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5353 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5356 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 283:
-#line 2565 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2568 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5361,11 +5364,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5365 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5368 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 284:
-#line 2575 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2578 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5373,11 +5376,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5377 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5380 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 285:
-#line 2584 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2587 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5385,11 +5388,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5389 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5392 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 286:
-#line 2593 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2596 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5397,11 +5400,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5401 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5404 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 287:
-#line 2602 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2605 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5409,11 +5412,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5413 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5416 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 288:
-#line 2611 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2614 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5421,11 +5424,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5425 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5428 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 289:
-#line 2621 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2624 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5433,11 +5436,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5437 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5440 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 290:
-#line 2631 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2634 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5445,11 +5448,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5449 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5452 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 291:
-#line 2641 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2644 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5457,11 +5460,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5461 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5464 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 292:
-#line 2650 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2653 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5469,11 +5472,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5473 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5476 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 293:
-#line 2659 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2662 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(2);
jpCheckEmpty(2);
@@ -5481,11 +5484,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5485 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5488 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 294:
-#line 2668 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2671 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5493,11 +5496,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5497 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5500 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 295:
-#line 2678 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2681 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -5505,11 +5508,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5509 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5512 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 296:
-#line 2687 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2690 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(4);
jpCheckEmpty(4);
@@ -5517,20 +5520,20 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5521 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5524 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 297:
-#line 2696 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2699 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
}
-#line 5530 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5533 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 298:
-#line 2703 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2706 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5538,11 +5541,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5542 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5545 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 299:
-#line 2712 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2715 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5550,11 +5553,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5554 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5557 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 300:
-#line 2721 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2724 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5562,11 +5565,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5566 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5569 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 301:
-#line 2730 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2733 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5574,11 +5577,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5578 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5581 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 302:
-#line 2740 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2743 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5586,11 +5589,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5590 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5593 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 303:
-#line 2749 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2752 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5598,11 +5601,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5602 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5605 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 304:
-#line 2758 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2761 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5610,11 +5613,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5614 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5617 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 305:
-#line 2768 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2771 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5622,11 +5625,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5626 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5629 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 306:
-#line 2777 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2780 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5634,11 +5637,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5638 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5641 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 307:
-#line 2786 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2789 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5646,11 +5649,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5650 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5653 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 308:
-#line 2795 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2798 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5658,11 +5661,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5662 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5665 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 309:
-#line 2805 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2808 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5670,11 +5673,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5674 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5677 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 310:
-#line 2814 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2817 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5682,11 +5685,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5686 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5689 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 311:
-#line 2823 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2826 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5694,11 +5697,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5698 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5701 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 312:
-#line 2832 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2835 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5706,11 +5709,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5710 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5713 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 313:
-#line 2841 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2844 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5718,11 +5721,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5722 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5725 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 314:
-#line 2850 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2853 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5730,11 +5733,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5734 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5737 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 315:
-#line 2860 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2863 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5742,11 +5745,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5746 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5749 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 316:
-#line 2869 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2872 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5754,11 +5757,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5758 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5761 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 317:
-#line 2878 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2881 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5766,11 +5769,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5770 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5773 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 318:
-#line 2888 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2891 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5778,11 +5781,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5782 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5785 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 319:
-#line 2897 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2900 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5790,11 +5793,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5794 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5797 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 320:
-#line 2907 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2910 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5802,11 +5805,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5806 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5809 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 321:
-#line 2916 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2919 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5814,11 +5817,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5818 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5821 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 322:
-#line 2926 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2929 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5826,11 +5829,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5830 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5833 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 323:
-#line 2935 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2938 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5838,11 +5841,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5842 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5845 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 324:
-#line 2945 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2948 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5850,11 +5853,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5854 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5857 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 325:
-#line 2954 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2957 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5862,11 +5865,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5866 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5869 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 326:
-#line 2964 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2967 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5874,11 +5877,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5878 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5881 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 327:
-#line 2973 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2976 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5886,11 +5889,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5890 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5893 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 328:
-#line 2983 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2986 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5898,11 +5901,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5902 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5905 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 329:
-#line 2992 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 2995 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(5);
jpCheckEmpty(5);
@@ -5910,11 +5913,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5914 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5917 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 330:
-#line 3002 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3005 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5922,11 +5925,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5926 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5929 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 331:
-#line 3011 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3014 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5934,11 +5937,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5938 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5941 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 332:
-#line 3021 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3024 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpCheckEmpty(3);
@@ -5946,11 +5949,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5950 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5953 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 333:
-#line 3031 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3034 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
yyGetParser->DeallocateParserType(&((yyvsp[0].str)));
@@ -5959,11 +5962,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5963 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5966 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 334:
-#line 3041 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3044 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5971,11 +5974,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5975 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5978 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 335:
-#line 3050 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3053 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5983,11 +5986,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5987 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 5990 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 336:
-#line 3060 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3063 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -5995,11 +5998,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 5999 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6002 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 337:
-#line 3069 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3072 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6007,11 +6010,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6011 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6014 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 338:
-#line 3078 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3081 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6019,11 +6022,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6023 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6026 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 339:
-#line 3087 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3090 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6031,11 +6034,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6035 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6038 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 340:
-#line 3096 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3099 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6043,11 +6046,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6047 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6050 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 341:
-#line 3105 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3108 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6055,11 +6058,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6059 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6062 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 342:
-#line 3114 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3117 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6067,11 +6070,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6071 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6074 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 343:
-#line 3123 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3126 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6079,11 +6082,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6083 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6086 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 344:
-#line 3132 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3135 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6091,11 +6094,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6095 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6098 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 345:
-#line 3141 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3144 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6103,11 +6106,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6107 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6110 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 346:
-#line 3150 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3153 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6115,11 +6118,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6119 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6122 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 347:
-#line 3159 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3162 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6127,11 +6130,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6131 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6134 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 348:
-#line 3169 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3172 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6139,11 +6142,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6143 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6146 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 349:
-#line 3179 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3182 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6151,11 +6154,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6155 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6158 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 350:
-#line 3189 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3192 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(1);
jpCheckEmpty(1);
@@ -6163,11 +6166,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6167 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6170 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
case 351:
-#line 3198 "cmDependsJavaParser.y" /* yacc.c:1646 */
+#line 3201 "cmDependsJavaParser.y" /* yacc.c:1646 */
{
jpElementStart(3);
jpStoreClass((yyvsp[-2].str));
@@ -6176,11 +6179,11 @@ yyreduce:
yyGetParser->SetCurrentCombine("");
}
-#line 6180 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6183 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
break;
-#line 6184 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
+#line 6187 "cmDependsJavaParser.cxx" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@@ -6410,7 +6413,7 @@ yyreturn:
#endif
return yyresult;
}
-#line 3207 "cmDependsJavaParser.y" /* yacc.c:1906 */
+#line 3210 "cmDependsJavaParser.y" /* yacc.c:1906 */
/* End of grammar */
diff --git a/Source/LexerParser/cmDependsJavaParser.y b/Source/LexerParser/cmDependsJavaParser.y
index f7eb22818..d15cffc56 100644
--- a/Source/LexerParser/cmDependsJavaParser.y
+++ b/Source/LexerParser/cmDependsJavaParser.y
@@ -36,7 +36,7 @@ static void cmDependsJava_yyerror(yyscan_t yyscanner, const char* message);
#define YYMAXDEPTH 1000000
-#define jpCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp);
+#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. */
@@ -44,6 +44,9 @@ static void cmDependsJava_yyerror(yyscan_t yyscanner, const char* message);
# pragma warning (disable: 4102) /* Unused goto label. */
# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
%}
/* Generate a reentrant parser object. */
diff --git a/Source/LexerParser/cmExprLexer.cxx b/Source/LexerParser/cmExprLexer.cxx
index fb6f0db98..72e59b689 100644
--- a/Source/LexerParser/cmExprLexer.cxx
+++ b/Source/LexerParser/cmExprLexer.cxx
@@ -1,7 +1,4 @@
#include "cmStandardLexer.h"
-#line 2 "cmExprLexer.cxx"
-
-#line 4 "cmExprLexer.cxx"
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -11,11 +8,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmExpr_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmExpr_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmExpr_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmExpr_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmExpr_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmExpr_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmExpr_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmExpr_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmExpr_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmExpr_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmExpr_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmExpr_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmExpr_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmExpr_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmExpr_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmExpr_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmExpr_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmExpr_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmExpr_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmExpr_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmExpr_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmExpr_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmExpr_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmExpr_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmExpr_yylex_ALREADY_DEFINED
+#else
+#define yylex cmExpr_yylex
+#endif
+
+#ifdef yyrestart
+#define cmExpr_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmExpr_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmExpr_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmExpr_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmExpr_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmExpr_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmExpr_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmExpr_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmExpr_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmExpr_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmExpr_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmExpr_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmExpr_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmExpr_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmExpr_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmExpr_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmExpr_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmExpr_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmExpr_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmExpr_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmExpr_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmExpr_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmExpr_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmExpr_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmExpr_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmExpr_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmExpr_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmExpr_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmExpr_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmExpr_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmExpr_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmExpr_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmExpr_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmExpr_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmExpr_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmExpr_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmExpr_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmExpr_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmExpr_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmExpr_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmExpr_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmExpr_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmExpr_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmExpr_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -86,10 +293,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -102,12 +315,10 @@ typedef unsigned int flex_uint32_t;
/* 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.
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
*/
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -131,20 +342,16 @@ typedef void* yyscan_t;
* 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_NEW_FILE yyrestart( yyin , yyscanner )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
@@ -194,7 +401,6 @@ typedef size_t yy_size_t;
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
-
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
#ifndef YY_STRUCT_YY_BUFFER_STATE
@@ -254,7 +460,7 @@ struct yy_buffer_state
* 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
+ * (via yyrestart()), so that the user can continue scanning by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
@@ -271,73 +477,67 @@ struct yy_buffer_state
#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)
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void 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 );
+static void yyensure_buffer_stack ( yyscan_t yyscanner );
+static void yy_load_buffer_state ( yyscan_t yyscanner );
+static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
+#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , 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 );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
-#define yy_new_buffer cmExpr_yy_create_buffer
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
+#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
- cmExpr_yyensure_buffer_stack (yyscanner); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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(yyscanner) (/*CONSTCOND*/1)
#define YY_SKIP_YYWRAP
-
-typedef unsigned char YY_CHAR;
+typedef flex_uint8_t 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 yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
+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 yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
@@ -348,9 +548,8 @@ static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
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
+#define YY_NUM_RULES 18
+#define YY_END_OF_BUFFER 19
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@@ -358,29 +557,29 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
-static yyconst flex_int16_t yy_accept[23] =
+static const flex_int16_t yy_accept[29] =
{ 0,
- 0, 0, 16, 15, 6, 8, 13, 14, 4, 2,
- 3, 5, 1, 15, 15, 9, 7, 10, 1, 11,
- 12, 0
+ 0, 0, 19, 17, 1, 18, 8, 10, 15, 16,
+ 6, 4, 5, 7, 2, 2, 17, 17, 11, 9,
+ 12, 2, 0, 13, 14, 3, 3, 0
} ;
-static yyconst YY_CHAR yy_ec[256] =
+static const YY_CHAR yy_ec[256] =
{ 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 1, 1, 1, 4, 5, 1, 6,
+ 7, 8, 9, 1, 10, 1, 11, 12, 13, 13,
+ 13, 13, 13, 13, 13, 13, 13, 1, 1, 14,
+ 1, 15, 1, 1, 16, 16, 16, 16, 16, 16,
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, 17, 1, 1,
+ 1, 1, 1, 18, 1, 1, 16, 16, 16, 16,
- 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,
+ 16, 16, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 17,
+ 1, 1, 1, 19, 1, 20, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -397,40 +596,46 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;
-static yyconst YY_CHAR yy_meta[16] =
+static const YY_CHAR yy_meta[21] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1
+ 1, 2, 2, 1, 1, 3, 4, 1, 1, 1
} ;
-static yyconst flex_uint16_t yy_base[23] =
+static const flex_int16_t yy_base[32] =
{ 0,
- 0, 0, 20, 21, 21, 21, 21, 21, 21, 21,
- 21, 21, 9, 7, 5, 21, 21, 21, 6, 21,
- 21, 21
+ 0, 0, 34, 35, 35, 35, 35, 35, 35, 35,
+ 35, 35, 35, 35, 16, 9, 18, 11, 35, 35,
+ 35, 11, 0, 35, 35, 0, 0, 35, 23, 26,
+ 28
} ;
-static yyconst flex_int16_t yy_def[23] =
+static const flex_int16_t yy_def[32] =
{ 0,
- 22, 1, 22, 22, 22, 22, 22, 22, 22, 22,
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
- 22, 0
+ 28, 1, 28, 28, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 29, 28, 28, 28, 28, 28,
+ 28, 28, 30, 28, 28, 31, 31, 0, 28, 28,
+ 28
} ;
-static yyconst flex_uint16_t yy_nxt[37] =
+static const flex_int16_t yy_nxt[56] =
{ 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
+ 14, 15, 16, 17, 18, 4, 4, 19, 20, 21,
+ 22, 22, 22, 22, 22, 25, 22, 26, 26, 27,
+ 27, 24, 23, 28, 3, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28
} ;
-static yyconst flex_int16_t yy_chk[37] =
+static const flex_int16_t yy_chk[56] =
{ 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
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 16, 16, 22, 22, 29, 18, 29, 30, 30, 31,
+ 31, 17, 15, 3, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28
} ;
/* The intent behind this definition is that it'll catch
@@ -440,8 +645,6 @@ static yyconst flex_int16_t yy_chk[37] =
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
-#line 1 "cmExprLexer.in.l"
-#line 2 "cmExprLexer.in.l"
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
/*
@@ -450,30 +653,32 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmExpr_yy --header-file=cmExprLexer.h -ocmExprLexer.cxx cmExprLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline --header-file=cmExprLexer.h -ocmExprLexer.cxx cmExprLexer.in.l
Modify cmExprLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmExprLexer.h cmExprLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in cmExpr_yy_scan_bytes for loop condition of _yybytes_len to size_t
+ - remove trailing whitespace: sed -i 's/\s*$//' cmExprLexer.h cmExprLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmExprLexer.h cmExprLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmExprLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#include "cmExprParserHelper.h"
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = yyextra->LexInput(buf, max_size); }
+ do { result = yyextra->LexInput(buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmExprParserTokens.h"
+#include <string>
+
/*--------------------------------------------------------------------------*/
-#line 476 "cmExprLexer.cxx"
#define INITIAL 0
@@ -515,44 +720,44 @@ struct yyguts_t
}; /* end struct yyguts_t */
-static int yy_init_globals (yyscan_t yyscanner );
+static int yy_init_globals ( yyscan_t yyscanner );
-int cmExpr_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmExpr_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 cmExpr_yylex_destroy (yyscan_t yyscanner );
+int yylex_destroy ( yyscan_t yyscanner );
-int cmExpr_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmExpr_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmExpr_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmExpr_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmExpr_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmExpr_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmExpr_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmExpr_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmExpr_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmExpr_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmExpr_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmExpr_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmExpr_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmExpr_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -560,32 +765,31 @@ void cmExpr_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmExpr_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmExpr_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef YY_NO_UNPUT
- static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);
+ static void yyunput ( int c, char *buf_ptr , yyscan_t yyscanner);
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
-
#ifdef __cplusplus
-static int yyinput (yyscan_t yyscanner );
+static int yyinput ( yyscan_t yyscanner );
#else
-static int input (yyscan_t yyscanner );
+static int input ( yyscan_t yyscanner );
#endif
#endif
@@ -616,7 +820,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- size_t n; \
+ int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -629,7 +833,7 @@ static int input (yyscan_t yyscanner );
else \
{ \
errno=0; \
- while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
@@ -670,9 +874,9 @@ static int input (yyscan_t yyscanner );
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmExpr_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmExpr_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng
@@ -717,19 +921,15 @@ YY_DECL
yyout = stdout;
if ( ! YY_CURRENT_BUFFER ) {
- cmExpr_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmExpr_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
{
-#line 39 "cmExprLexer.in.l"
-
-
-#line 732 "cmExprLexer.cxx"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
@@ -756,13 +956,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 23 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ if ( yy_current_state >= 29 )
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
- while ( yy_base[yy_current_state] != 21 );
+ while ( yy_base[yy_current_state] != 35 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@@ -788,80 +988,76 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 41 "cmExprLexer.in.l"
-{ yylvalp->Number = atoi(yytext); return exp_NUMBER; }
+{}
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 43 "cmExprLexer.in.l"
-{ return exp_PLUS; }
+{ yylvalp->Number = std::stoll(yytext, nullptr, 10); return exp_NUMBER; }
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 44 "cmExprLexer.in.l"
-{ return exp_MINUS; }
+{ yylvalp->Number = std::stoll(yytext, nullptr, 16); return exp_NUMBER; }
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 45 "cmExprLexer.in.l"
-{ return exp_TIMES; }
+{ return exp_PLUS; }
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 46 "cmExprLexer.in.l"
-{ return exp_DIVIDE; }
+{ return exp_MINUS; }
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 47 "cmExprLexer.in.l"
-{ return exp_MOD; }
+{ return exp_TIMES; }
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 48 "cmExprLexer.in.l"
-{ return exp_OR; }
+{ return exp_DIVIDE; }
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 49 "cmExprLexer.in.l"
-{ return exp_AND; }
+{ return exp_MOD; }
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 50 "cmExprLexer.in.l"
-{ return exp_XOR; }
+{ return exp_OR; }
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 51 "cmExprLexer.in.l"
-{ return exp_NOT; }
+{ return exp_AND; }
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 52 "cmExprLexer.in.l"
-{ return exp_SHIFTLEFT; }
+{ return exp_XOR; }
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 53 "cmExprLexer.in.l"
-{ return exp_SHIFTRIGHT; }
+{ return exp_NOT; }
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 54 "cmExprLexer.in.l"
-{ return exp_OPENPARENT; }
+{ return exp_SHIFTLEFT; }
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 55 "cmExprLexer.in.l"
-{ return exp_CLOSEPARENT; }
+{ return exp_SHIFTRIGHT; }
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 57 "cmExprLexer.in.l"
+{ return exp_OPENPARENT; }
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+{ return exp_CLOSEPARENT; }
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+{ yyextra->UnexpectedChar(yytext[0]); }
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
ECHO;
YY_BREAK
-#line 864 "cmExprLexer.cxx"
case YY_STATE_EOF(INITIAL):
yyterminate();
@@ -879,7 +1075,7 @@ case YY_STATE_EOF(INITIAL):
/* 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
+ * 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
@@ -939,7 +1135,7 @@ case YY_STATE_EOF(INITIAL):
{
yyg->yy_did_buffer_switch_on_eof = 0;
- if ( cmExpr_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
@@ -993,7 +1189,7 @@ case YY_STATE_EOF(INITIAL):
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
-} /* end of cmExpr_yylex */
+} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
*
@@ -1007,7 +1203,7 @@ 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;
- yy_size_t number_to_move, i;
+ 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] )
@@ -1036,7 +1232,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Try to read more data. */
/* First move last chars to start of buffer. */
- number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
@@ -1072,7 +1268,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
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 );
+ yyrealloc( (void *) b->yy_ch_buf,
+ (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
}
else
/* Can't grow it, we don't own it. */
@@ -1104,7 +1301,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
- cmExpr_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
}
else
@@ -1118,12 +1315,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
ret_val = EOB_ACT_CONTINUE_SCAN;
- if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ if ((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. */
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cmExpr_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
+ (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ /* "- 2" to take care of EOB's */
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
}
yyg->yy_n_chars += number_to_move;
@@ -1156,10 +1356,10 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 23 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ if ( yy_current_state >= 29 )
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
}
return yy_current_state;
@@ -1185,11 +1385,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 23 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ if ( yy_current_state >= 29 )
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
- yy_is_jam = (yy_current_state == 22);
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ yy_is_jam = (yy_current_state == 28);
(void)yyg;
return yy_is_jam ? 0 : yy_current_state;
@@ -1262,7 +1462,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{ /* need more input */
- int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
@@ -1279,13 +1479,13 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
*/
/* Reset buffer status. */
- cmExpr_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
- if ( cmExpr_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
return 0;
if ( ! yyg->yy_did_buffer_switch_on_eof )
@@ -1317,34 +1517,34 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
* @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)
+ void yyrestart (FILE * input_file , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! YY_CURRENT_BUFFER ){
- cmExpr_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmExpr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmExpr_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
- cmExpr_yy_load_buffer_state(yyscanner );
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
+ 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)
+ void 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);
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
*/
- cmExpr_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
if ( YY_CURRENT_BUFFER == new_buffer )
return;
@@ -1357,17 +1557,17 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- cmExpr_yy_load_buffer_state(yyscanner );
+ 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
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after 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)
+static void 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;
@@ -1382,35 +1582,35 @@ static void cmExpr_yy_load_buffer_state (yyscan_t yyscanner)
* @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 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 );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
- b->yy_buf_size = (yy_size_t)size;
+ 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 );
+ b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_is_our_buffer = 1;
- cmExpr_yy_init_buffer(b,file ,yyscanner);
+ yy_init_buffer( b, file , yyscanner);
return b;
}
/** Destroy the buffer.
- * @param b a buffer created with cmExpr_yy_create_buffer()
+ * @param b a buffer created with yy_create_buffer()
* @param yyscanner The scanner object.
*/
- void cmExpr_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+ void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1421,28 +1621,28 @@ static void cmExpr_yy_load_buffer_state (yyscan_t yyscanner)
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
- cmExpr_yyfree((void *) b->yy_ch_buf ,yyscanner );
+ yyfree( (void *) b->yy_ch_buf , yyscanner );
- cmExpr_yyfree((void *) b ,yyscanner );
+ 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 cmExpr_yyrestart() or at EOF.
+ * such as during a yyrestart() or at EOF.
*/
- static void cmExpr_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+ static void 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);
+ 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.
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from 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){
@@ -1459,7 +1659,7 @@ static void cmExpr_yy_load_buffer_state (yyscan_t yyscanner)
* @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)
+ void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! b )
@@ -1480,7 +1680,7 @@ static void cmExpr_yy_load_buffer_state (yyscan_t yyscanner)
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == YY_CURRENT_BUFFER )
- cmExpr_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
/** Pushes the new state onto the stack. The new state becomes
@@ -1489,15 +1689,15 @@ static void cmExpr_yy_load_buffer_state (yyscan_t yyscanner)
* @param new_buffer The new state.
* @param yyscanner The scanner object.
*/
-void cmExpr_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+void 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);
+ yyensure_buffer_stack(yyscanner);
- /* This block is copied from cmExpr_yy_switch_to_buffer. */
+ /* This block is copied from yy_switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
@@ -1511,8 +1711,8 @@ void cmExpr_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner
yyg->yy_buffer_stack_top++;
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- /* copied from cmExpr_yy_switch_to_buffer. */
- cmExpr_yy_load_buffer_state(yyscanner );
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
@@ -1520,19 +1720,19 @@ void cmExpr_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner
* The next element becomes the new top.
* @param yyscanner The scanner object.
*/
-void cmExpr_yypop_buffer_state (yyscan_t yyscanner)
+void 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_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 );
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
}
@@ -1540,9 +1740,9 @@ void cmExpr_yypop_buffer_state (yyscan_t yyscanner)
/* Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
-static void cmExpr_yyensure_buffer_stack (yyscan_t yyscanner)
+static void yyensure_buffer_stack (yyscan_t yyscanner)
{
- int num_to_alloc;
+ yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
@@ -1552,11 +1752,11 @@ static void cmExpr_yyensure_buffer_stack (yyscan_t yyscanner)
* immediate realloc on the next call.
*/
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmExpr_yyalloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
if ( ! yyg->yy_buffer_stack )
- YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yyensure_buffer_stack()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
@@ -1571,12 +1771,12 @@ static void cmExpr_yyensure_buffer_stack (yyscan_t yyscanner)
yy_size_t grow_size = 8 /* arbitrary grow size */;
num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmExpr_yyrealloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)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 cmExpr_yyensure_buffer_stack()" );
+ YY_FATAL_ERROR( "out of dynamic memory in 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*));
@@ -1590,7 +1790,7 @@ static void cmExpr_yyensure_buffer_stack (yyscan_t yyscanner)
* @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 yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
@@ -1600,11 +1800,11 @@ YY_BUFFER_STATE cmExpr_yy_scan_buffer (char * base, yy_size_t size , yyscan_t
/* They forgot to leave room for the EOB's. */
return NULL;
- b = (YY_BUFFER_STATE) cmExpr_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_scan_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_size = (int) (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 = NULL;
@@ -1614,53 +1814,53 @@ YY_BUFFER_STATE cmExpr_yy_scan_buffer (char * base, yy_size_t size , yyscan_t
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
- cmExpr_yy_switch_to_buffer(b ,yyscanner );
+ yy_switch_to_buffer( b , yyscanner );
return b;
}
-/** Setup the input buffer state to scan a string. The next call to cmExpr_yylex() will
+/** Setup the input buffer state to scan a string. The next call to 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
- * cmExpr_yy_scan_bytes() instead.
+ * yy_scan_bytes() instead.
*/
-YY_BUFFER_STATE cmExpr_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
{
- return cmExpr_yy_scan_bytes(yystr,(int) strlen(yystr) ,yyscanner);
+ return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
}
-/** Setup the input buffer state to scan the given bytes. The next call to cmExpr_yylex() will
+/** Setup the input buffer state to scan the given bytes. The next call to 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 cmExpr_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
- yy_size_t i;
+ int i;
/* Get memory for full buffer, including space for trailing EOB's. */
- n = (yy_size_t) _yybytes_len + 2;
- buf = (char *) cmExpr_yyalloc(n ,yyscanner );
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) yyalloc( n , yyscanner );
if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmExpr_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
- for ( i = 0; i < (size_t)_yybytes_len; ++i )
+ for ( i = 0; i < _yybytes_len; ++i )
buf[i] = yybytes[i];
buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
- b = cmExpr_yy_scan_buffer(buf,n ,yyscanner);
+ b = yy_scan_buffer( buf, n , yyscanner);
if ( ! b )
- YY_FATAL_ERROR( "bad buffer in cmExpr_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
@@ -1674,11 +1874,11 @@ YY_BUFFER_STATE cmExpr_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len
#define YY_EXIT_FAILURE 2
#endif
-static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- (void) fprintf( stderr, "%s\n", msg );
+ fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
@@ -1704,7 +1904,7 @@ static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
/** Get the user-defined data for this scanner.
* @param yyscanner The scanner object.
*/
-YY_EXTRA_TYPE cmExpr_yyget_extra (yyscan_t yyscanner)
+YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyextra;
@@ -1713,7 +1913,7 @@ YY_EXTRA_TYPE cmExpr_yyget_extra (yyscan_t yyscanner)
/** Get the current line number.
* @param yyscanner The scanner object.
*/
-int cmExpr_yyget_lineno (yyscan_t yyscanner)
+int yyget_lineno (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1726,7 +1926,7 @@ int cmExpr_yyget_lineno (yyscan_t yyscanner)
/** Get the current column number.
* @param yyscanner The scanner object.
*/
-int cmExpr_yyget_column (yyscan_t yyscanner)
+int yyget_column (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1739,7 +1939,7 @@ int cmExpr_yyget_column (yyscan_t yyscanner)
/** Get the input stream.
* @param yyscanner The scanner object.
*/
-FILE *cmExpr_yyget_in (yyscan_t yyscanner)
+FILE *yyget_in (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyin;
@@ -1748,7 +1948,7 @@ FILE *cmExpr_yyget_in (yyscan_t yyscanner)
/** Get the output stream.
* @param yyscanner The scanner object.
*/
-FILE *cmExpr_yyget_out (yyscan_t yyscanner)
+FILE *yyget_out (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyout;
@@ -1757,7 +1957,7 @@ FILE *cmExpr_yyget_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
-int cmExpr_yyget_leng (yyscan_t yyscanner)
+int yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
@@ -1767,7 +1967,7 @@ int cmExpr_yyget_leng (yyscan_t yyscanner)
* @param yyscanner The scanner object.
*/
-char *cmExpr_yyget_text (yyscan_t yyscanner)
+char *yyget_text (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yytext;
@@ -1777,7 +1977,7 @@ char *cmExpr_yyget_text (yyscan_t yyscanner)
* @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)
+void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyextra = user_defined ;
@@ -1787,13 +1987,13 @@ void cmExpr_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
* @param _line_number line number
* @param yyscanner The scanner object.
*/
-void cmExpr_yyset_lineno (int _line_number , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
yylineno = _line_number;
}
@@ -1802,13 +2002,13 @@ void cmExpr_yyset_lineno (int _line_number , yyscan_t yyscanner)
* @param _column_no column number
* @param yyscanner The scanner object.
*/
-void cmExpr_yyset_column (int _column_no , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_column called with no buffer" );
yycolumn = _column_no;
}
@@ -1817,27 +2017,27 @@ void cmExpr_yyset_column (int _column_no , yyscan_t yyscanner)
* input buffer.
* @param _in_str A readable stream.
* @param yyscanner The scanner object.
- * @see cmExpr_yy_switch_to_buffer
+ * @see yy_switch_to_buffer
*/
-void cmExpr_yyset_in (FILE * _in_str , yyscan_t yyscanner)
+void 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)
+void 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)
+int 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)
+void yyset_debug (int _bdebug , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ;
@@ -1847,20 +2047,18 @@ void cmExpr_yyset_debug (int _bdebug , yyscan_t yyscanner)
/* User-visible API */
-/* cmExpr_yylex_init is special because it creates the scanner itself, so it is
+/* 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)
-
+int 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 );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -1873,27 +2071,25 @@ int cmExpr_yylex_init(yyscan_t* ptr_yy_globals)
return yy_init_globals ( *ptr_yy_globals );
}
-/* cmExpr_yylex_init_extra has the same functionality as cmExpr_yylex_init, but follows the
+/* yylex_init_extra has the same functionality as 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 cmExpr_yyalloc in
+ * The user defined value in the first argument will be available to yyalloc in
* the yyextra field.
*/
-
-int cmExpr_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
-
+int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
{
struct yyguts_t dummy_yyguts;
- cmExpr_yyset_extra (yy_user_defined, &dummy_yyguts);
+ yyset_extra (yy_user_defined, &dummy_yyguts);
if (ptr_yy_globals == NULL){
errno = EINVAL;
return 1;
}
- *ptr_yy_globals = (yyscan_t) cmExpr_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -1904,7 +2100,7 @@ int cmExpr_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globa
yy_init_globals. Leave at 0x00 for releases. */
memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
- cmExpr_yyset_extra (yy_user_defined, *ptr_yy_globals);
+ yyset_extra (yy_user_defined, *ptr_yy_globals);
return yy_init_globals ( *ptr_yy_globals );
}
@@ -1913,7 +2109,7 @@ 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 cmExpr_yylex_destroy(), so don't allocate here.
+ * This function is called from yylex_destroy(), so don't allocate here.
*/
yyg->yy_buffer_stack = NULL;
@@ -1937,37 +2133,37 @@ static int yy_init_globals (yyscan_t yyscanner)
#endif
/* For future reference: Set errno on error, since we are called by
- * cmExpr_yylex_init()
+ * yylex_init()
*/
return 0;
}
-/* cmExpr_yylex_destroy is for both reentrant and non-reentrant scanners. */
-int cmExpr_yylex_destroy (yyscan_t yyscanner)
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int 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_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
YY_CURRENT_BUFFER_LVALUE = NULL;
- cmExpr_yypop_buffer_state(yyscanner);
+ yypop_buffer_state(yyscanner);
}
/* Destroy the stack itself. */
- cmExpr_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyfree(yyg->yy_buffer_stack , yyscanner);
yyg->yy_buffer_stack = NULL;
/* Destroy the start condition stack. */
- cmExpr_yyfree(yyg->yy_start_stack ,yyscanner );
+ 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
- * cmExpr_yylex() is called, initialization will occur. */
+ * yylex() is called, initialization will occur. */
yy_init_globals( yyscanner);
/* Destroy the main struct (reentrant only). */
- cmExpr_yyfree ( yyscanner , yyscanner );
+ yyfree ( yyscanner , yyscanner );
yyscanner = NULL;
return 0;
}
@@ -1977,7 +2173,7 @@ int cmExpr_yylex_destroy (yyscan_t yyscanner)
*/
#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -1989,7 +2185,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
{
int n;
for ( n = 0; s[n]; ++n )
@@ -1999,14 +2195,14 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
}
#endif
-void *cmExpr_yyalloc (yy_size_t size , yyscan_t yyscanner)
+void *yyalloc (yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
return malloc(size);
}
-void *cmExpr_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
+void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2021,13 +2217,15 @@ void *cmExpr_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
return realloc(ptr, size);
}
-void cmExpr_yyfree (void * ptr , yyscan_t yyscanner)
+void yyfree (void * ptr , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- free( (char *) ptr ); /* see cmExpr_yyrealloc() for (char *) cast */
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
-#line 57 "cmExprLexer.in.l"
+/*--------------------------------------------------------------------------*/
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmExprLexer.h b/Source/LexerParser/cmExprLexer.h
index 835a7a36a..b55ee92e5 100644
--- a/Source/LexerParser/cmExprLexer.h
+++ b/Source/LexerParser/cmExprLexer.h
@@ -2,10 +2,6 @@
#define cmExpr_yyHEADER_H 1
#define cmExpr_yyIN_HEADER 1
-#line 6 "cmExprLexer.h"
-
-#line 8 "cmExprLexer.h"
-
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -14,11 +10,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmExpr_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmExpr_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmExpr_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmExpr_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmExpr_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmExpr_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmExpr_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmExpr_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmExpr_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmExpr_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmExpr_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmExpr_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmExpr_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmExpr_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmExpr_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmExpr_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmExpr_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmExpr_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmExpr_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmExpr_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmExpr_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmExpr_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmExpr_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmExpr_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmExpr_yylex_ALREADY_DEFINED
+#else
+#define yylex cmExpr_yylex
+#endif
+
+#ifdef yyrestart
+#define cmExpr_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmExpr_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmExpr_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmExpr_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmExpr_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmExpr_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmExpr_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmExpr_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmExpr_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmExpr_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmExpr_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmExpr_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmExpr_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmExpr_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmExpr_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmExpr_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmExpr_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmExpr_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmExpr_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmExpr_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmExpr_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmExpr_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmExpr_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmExpr_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmExpr_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmExpr_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmExpr_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmExpr_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmExpr_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmExpr_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmExpr_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmExpr_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmExpr_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmExpr_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmExpr_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmExpr_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmExpr_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmExpr_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmExpr_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmExpr_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmExpr_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmExpr_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmExpr_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmExpr_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -89,10 +295,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -193,21 +405,21 @@ struct yy_buffer_state
};
#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 );
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void 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 );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const 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 );
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
/* Begin user sect3 */
@@ -225,42 +437,42 @@ void cmExpr_yyfree (void * ,yyscan_t yyscanner );
#define YY_EXTRA_TYPE void *
#endif
-int cmExpr_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmExpr_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 cmExpr_yylex_destroy (yyscan_t yyscanner );
+int yylex_destroy ( yyscan_t yyscanner );
-int cmExpr_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmExpr_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmExpr_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmExpr_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmExpr_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmExpr_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmExpr_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmExpr_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmExpr_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmExpr_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmExpr_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmExpr_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmExpr_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmExpr_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -268,18 +480,18 @@ void cmExpr_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmExpr_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmExpr_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
@@ -307,9 +519,9 @@ static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmExpr_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmExpr_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* yy_get_previous_state - get the state just before the EOB char was reached */
@@ -326,9 +538,150 @@ extern int cmExpr_yylex (yyscan_t yyscanner);
#undef YY_DECL
#endif
-#line 57 "cmExprLexer.in.l"
-
+#ifndef cmExpr_yy_create_buffer_ALREADY_DEFINED
+#undef yy_create_buffer
+#endif
+#ifndef cmExpr_yy_delete_buffer_ALREADY_DEFINED
+#undef yy_delete_buffer
+#endif
+#ifndef cmExpr_yy_scan_buffer_ALREADY_DEFINED
+#undef yy_scan_buffer
+#endif
+#ifndef cmExpr_yy_scan_string_ALREADY_DEFINED
+#undef yy_scan_string
+#endif
+#ifndef cmExpr_yy_scan_bytes_ALREADY_DEFINED
+#undef yy_scan_bytes
+#endif
+#ifndef cmExpr_yy_init_buffer_ALREADY_DEFINED
+#undef yy_init_buffer
+#endif
+#ifndef cmExpr_yy_flush_buffer_ALREADY_DEFINED
+#undef yy_flush_buffer
+#endif
+#ifndef cmExpr_yy_load_buffer_state_ALREADY_DEFINED
+#undef yy_load_buffer_state
+#endif
+#ifndef cmExpr_yy_switch_to_buffer_ALREADY_DEFINED
+#undef yy_switch_to_buffer
+#endif
+#ifndef cmExpr_yypush_buffer_state_ALREADY_DEFINED
+#undef yypush_buffer_state
+#endif
+#ifndef cmExpr_yypop_buffer_state_ALREADY_DEFINED
+#undef yypop_buffer_state
+#endif
+#ifndef cmExpr_yyensure_buffer_stack_ALREADY_DEFINED
+#undef yyensure_buffer_stack
+#endif
+#ifndef cmExpr_yylex_ALREADY_DEFINED
+#undef yylex
+#endif
+#ifndef cmExpr_yyrestart_ALREADY_DEFINED
+#undef yyrestart
+#endif
+#ifndef cmExpr_yylex_init_ALREADY_DEFINED
+#undef yylex_init
+#endif
+#ifndef cmExpr_yylex_init_extra_ALREADY_DEFINED
+#undef yylex_init_extra
+#endif
+#ifndef cmExpr_yylex_destroy_ALREADY_DEFINED
+#undef yylex_destroy
+#endif
+#ifndef cmExpr_yyget_debug_ALREADY_DEFINED
+#undef yyget_debug
+#endif
+#ifndef cmExpr_yyset_debug_ALREADY_DEFINED
+#undef yyset_debug
+#endif
+#ifndef cmExpr_yyget_extra_ALREADY_DEFINED
+#undef yyget_extra
+#endif
+#ifndef cmExpr_yyset_extra_ALREADY_DEFINED
+#undef yyset_extra
+#endif
+#ifndef cmExpr_yyget_in_ALREADY_DEFINED
+#undef yyget_in
+#endif
+#ifndef cmExpr_yyset_in_ALREADY_DEFINED
+#undef yyset_in
+#endif
+#ifndef cmExpr_yyget_out_ALREADY_DEFINED
+#undef yyget_out
+#endif
+#ifndef cmExpr_yyset_out_ALREADY_DEFINED
+#undef yyset_out
+#endif
+#ifndef cmExpr_yyget_leng_ALREADY_DEFINED
+#undef yyget_leng
+#endif
+#ifndef cmExpr_yyget_text_ALREADY_DEFINED
+#undef yyget_text
+#endif
+#ifndef cmExpr_yyget_lineno_ALREADY_DEFINED
+#undef yyget_lineno
+#endif
+#ifndef cmExpr_yyset_lineno_ALREADY_DEFINED
+#undef yyset_lineno
+#endif
+#ifndef cmExpr_yyget_column_ALREADY_DEFINED
+#undef yyget_column
+#endif
+#ifndef cmExpr_yyset_column_ALREADY_DEFINED
+#undef yyset_column
+#endif
+#ifndef cmExpr_yywrap_ALREADY_DEFINED
+#undef yywrap
+#endif
+#ifndef cmExpr_yyget_lval_ALREADY_DEFINED
+#undef yyget_lval
+#endif
+#ifndef cmExpr_yyset_lval_ALREADY_DEFINED
+#undef yyset_lval
+#endif
+#ifndef cmExpr_yyget_lloc_ALREADY_DEFINED
+#undef yyget_lloc
+#endif
+#ifndef cmExpr_yyset_lloc_ALREADY_DEFINED
+#undef yyset_lloc
+#endif
+#ifndef cmExpr_yyalloc_ALREADY_DEFINED
+#undef yyalloc
+#endif
+#ifndef cmExpr_yyrealloc_ALREADY_DEFINED
+#undef yyrealloc
+#endif
+#ifndef cmExpr_yyfree_ALREADY_DEFINED
+#undef yyfree
+#endif
+#ifndef cmExpr_yytext_ALREADY_DEFINED
+#undef yytext
+#endif
+#ifndef cmExpr_yyleng_ALREADY_DEFINED
+#undef yyleng
+#endif
+#ifndef cmExpr_yyin_ALREADY_DEFINED
+#undef yyin
+#endif
+#ifndef cmExpr_yyout_ALREADY_DEFINED
+#undef yyout
+#endif
+#ifndef cmExpr_yy_flex_debug_ALREADY_DEFINED
+#undef yy_flex_debug
+#endif
+#ifndef cmExpr_yylineno_ALREADY_DEFINED
+#undef yylineno
+#endif
+#ifndef cmExpr_yytables_fload_ALREADY_DEFINED
+#undef yytables_fload
+#endif
+#ifndef cmExpr_yytables_destroy_ALREADY_DEFINED
+#undef yytables_destroy
+#endif
+#ifndef cmExpr_yyTABLES_NAME_ALREADY_DEFINED
+#undef yyTABLES_NAME
+#endif
-#line 333 "cmExprLexer.h"
#undef cmExpr_yyIN_HEADER
#endif /* cmExpr_yyHEADER_H */
diff --git a/Source/LexerParser/cmExprLexer.in.l b/Source/LexerParser/cmExprLexer.in.l
index 25ddba460..f8a422431 100644
--- a/Source/LexerParser/cmExprLexer.in.l
+++ b/Source/LexerParser/cmExprLexer.in.l
@@ -7,38 +7,45 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmExpr_yy --header-file=cmExprLexer.h -ocmExprLexer.cxx cmExprLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline --header-file=cmExprLexer.h -ocmExprLexer.cxx cmExprLexer.in.l
Modify cmExprLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmExprLexer.h cmExprLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in yy_scan_bytes for loop condition of _yybytes_len to size_t
+ - remove trailing whitespace: sed -i 's/\s*$//' cmExprLexer.h cmExprLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmExprLexer.h cmExprLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmExprLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#include "cmExprParserHelper.h"
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = yyextra->LexInput(buf, max_size); }
+ do { result = yyextra->LexInput(buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmExprParserTokens.h"
+#include <string>
+
/*--------------------------------------------------------------------------*/
%}
+%option prefix="cmExpr_yy"
+
%option reentrant
%option noyywrap
%pointer
%%
+[ \t] {}
-[0-9][0-9]* { yylvalp->Number = atoi(yytext); return exp_NUMBER; }
+[0-9][0-9]* { yylvalp->Number = std::stoll(yytext, nullptr, 10); return exp_NUMBER; }
+0[xX][0-9a-fA-F][0-9a-fA-F]* { yylvalp->Number = std::stoll(yytext, nullptr, 16); return exp_NUMBER; }
"+" { return exp_PLUS; }
"-" { return exp_MINUS; }
@@ -53,5 +60,10 @@ Modify cmExprLexer.cxx:
">>" { return exp_SHIFTRIGHT; }
"(" { return exp_OPENPARENT; }
")" { return exp_CLOSEPARENT; }
+. { yyextra->UnexpectedChar(yytext[0]); }
%%
+
+/*--------------------------------------------------------------------------*/
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmExprParser.cxx b/Source/LexerParser/cmExprParser.cxx
index 67664a5f5..73ece2b4f 100644
--- a/Source/LexerParser/cmExprParser.cxx
+++ b/Source/LexerParser/cmExprParser.cxx
@@ -89,6 +89,7 @@ Modify cmExprParser.cxx:
#include <stdlib.h>
#include <string.h>
+#include <stdexcept>
/*-------------------------------------------------------------------------*/
#define YYDEBUG 1
@@ -107,8 +108,11 @@ static void cmExpr_yyerror(yyscan_t yyscanner, const char* message);
# pragma warning (disable: 4102) /* Unused goto label. */
# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
-#line 112 "cmExprParser.cxx" /* yacc.c:339 */
+#line 116 "cmExprParser.cxx" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
@@ -185,7 +189,7 @@ int cmExpr_yyparse (yyscan_t yyscanner);
/* Copy the second part of user declarations. */
-#line 189 "cmExprParser.cxx" /* yacc.c:358 */
+#line 193 "cmExprParser.cxx" /* yacc.c:358 */
#ifdef short
# undef short
@@ -484,9 +488,9 @@ static const yytype_uint8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 73, 73, 78, 81, 86, 89, 94, 97, 102,
- 105, 108, 113, 116, 119, 124, 127, 130, 133, 138,
- 141, 144, 149, 152
+ 0, 77, 77, 82, 85, 90, 93, 98, 101, 106,
+ 109, 112, 117, 120, 123, 128, 131, 134, 140, 145,
+ 148, 151, 156, 159
};
#endif
@@ -1281,183 +1285,186 @@ yyreduce:
switch (yyn)
{
case 2:
-#line 73 "cmExprParser.y" /* yacc.c:1646 */
+#line 77 "cmExprParser.y" /* yacc.c:1646 */
{
cmExpr_yyget_extra(yyscanner)->SetResult((yyvsp[0].Number));
}
-#line 1289 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1293 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 3:
-#line 78 "cmExprParser.y" /* yacc.c:1646 */
+#line 82 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1297 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1301 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 4:
-#line 81 "cmExprParser.y" /* yacc.c:1646 */
+#line 85 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) | (yyvsp[0].Number);
}
-#line 1305 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1309 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 5:
-#line 86 "cmExprParser.y" /* yacc.c:1646 */
+#line 90 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1313 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1317 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 6:
-#line 89 "cmExprParser.y" /* yacc.c:1646 */
+#line 93 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) ^ (yyvsp[0].Number);
}
-#line 1321 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1325 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 7:
-#line 94 "cmExprParser.y" /* yacc.c:1646 */
+#line 98 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1329 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1333 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 8:
-#line 97 "cmExprParser.y" /* yacc.c:1646 */
+#line 101 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) & (yyvsp[0].Number);
}
-#line 1337 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1341 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 9:
-#line 102 "cmExprParser.y" /* yacc.c:1646 */
+#line 106 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1345 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1349 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 10:
-#line 105 "cmExprParser.y" /* yacc.c:1646 */
+#line 109 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) << (yyvsp[0].Number);
}
-#line 1353 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1357 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 11:
-#line 108 "cmExprParser.y" /* yacc.c:1646 */
+#line 112 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) >> (yyvsp[0].Number);
}
-#line 1361 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1365 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 12:
-#line 113 "cmExprParser.y" /* yacc.c:1646 */
+#line 117 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1369 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1373 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 13:
-#line 116 "cmExprParser.y" /* yacc.c:1646 */
+#line 120 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) + (yyvsp[0].Number);
}
-#line 1377 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1381 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 14:
-#line 119 "cmExprParser.y" /* yacc.c:1646 */
+#line 123 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) - (yyvsp[0].Number);
}
-#line 1385 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1389 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 15:
-#line 124 "cmExprParser.y" /* yacc.c:1646 */
+#line 128 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1393 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1397 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 16:
-#line 127 "cmExprParser.y" /* yacc.c:1646 */
+#line 131 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) * (yyvsp[0].Number);
}
-#line 1401 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1405 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 17:
-#line 130 "cmExprParser.y" /* yacc.c:1646 */
+#line 134 "cmExprParser.y" /* yacc.c:1646 */
{
+ if (yyvsp[0].Number == 0) {
+ throw std::overflow_error("divide by zero");
+ }
(yyval.Number) = (yyvsp[-2].Number) / (yyvsp[0].Number);
}
-#line 1409 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1416 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 18:
-#line 133 "cmExprParser.y" /* yacc.c:1646 */
+#line 140 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-2].Number) % (yyvsp[0].Number);
}
-#line 1417 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1424 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 19:
-#line 138 "cmExprParser.y" /* yacc.c:1646 */
+#line 145 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1425 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1432 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 20:
-#line 141 "cmExprParser.y" /* yacc.c:1646 */
+#line 148 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = + (yyvsp[0].Number);
}
-#line 1433 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1440 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 21:
-#line 144 "cmExprParser.y" /* yacc.c:1646 */
+#line 151 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = - (yyvsp[0].Number);
}
-#line 1441 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1448 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 22:
-#line 149 "cmExprParser.y" /* yacc.c:1646 */
+#line 156 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[0].Number);
}
-#line 1449 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1456 "cmExprParser.cxx" /* yacc.c:1646 */
break;
case 23:
-#line 152 "cmExprParser.y" /* yacc.c:1646 */
+#line 159 "cmExprParser.y" /* yacc.c:1646 */
{
(yyval.Number) = (yyvsp[-1].Number);
}
-#line 1457 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1464 "cmExprParser.cxx" /* yacc.c:1646 */
break;
-#line 1461 "cmExprParser.cxx" /* yacc.c:1646 */
+#line 1468 "cmExprParser.cxx" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@@ -1687,7 +1694,7 @@ yyreturn:
#endif
return yyresult;
}
-#line 157 "cmExprParser.y" /* yacc.c:1906 */
+#line 164 "cmExprParser.y" /* yacc.c:1906 */
/* End of grammar */
diff --git a/Source/LexerParser/cmExprParser.y b/Source/LexerParser/cmExprParser.y
index d1c3a97a7..213747340 100644
--- a/Source/LexerParser/cmExprParser.y
+++ b/Source/LexerParser/cmExprParser.y
@@ -18,6 +18,7 @@ Modify cmExprParser.cxx:
#include <stdlib.h>
#include <string.h>
+#include <stdexcept>
/*-------------------------------------------------------------------------*/
#define YYDEBUG 1
@@ -36,6 +37,9 @@ static void cmExpr_yyerror(yyscan_t yyscanner, const char* message);
# pragma warning (disable: 4102) /* Unused goto label. */
# pragma warning (disable: 4065) /* Switch statement contains default but no case. */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
%}
/* Generate a reentrant parser object. */
@@ -128,6 +132,9 @@ term:
$<Number>$ = $<Number>1 * $<Number>3;
}
| term exp_DIVIDE unary {
+ if (yyvsp[0].Number == 0) {
+ throw std::overflow_error("divide by zero");
+ }
$<Number>$ = $<Number>1 / $<Number>3;
}
| term exp_MOD unary {
diff --git a/Source/LexerParser/cmFortranLexer.cxx b/Source/LexerParser/cmFortranLexer.cxx
index 01c09acb7..bcda77c30 100644
--- a/Source/LexerParser/cmFortranLexer.cxx
+++ b/Source/LexerParser/cmFortranLexer.cxx
@@ -1,7 +1,4 @@
#include "cmStandardLexer.h"
-#line 2 "cmFortranLexer.cxx"
-
-#line 4 "cmFortranLexer.cxx"
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -11,11 +8,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmFortran_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmFortran_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmFortran_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmFortran_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmFortran_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmFortran_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmFortran_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmFortran_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmFortran_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmFortran_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmFortran_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmFortran_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmFortran_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmFortran_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmFortran_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmFortran_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmFortran_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmFortran_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmFortran_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmFortran_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmFortran_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmFortran_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmFortran_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmFortran_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmFortran_yylex_ALREADY_DEFINED
+#else
+#define yylex cmFortran_yylex
+#endif
+
+#ifdef yyrestart
+#define cmFortran_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmFortran_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmFortran_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmFortran_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmFortran_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmFortran_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmFortran_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmFortran_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmFortran_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmFortran_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmFortran_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmFortran_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmFortran_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmFortran_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmFortran_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmFortran_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmFortran_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmFortran_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmFortran_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmFortran_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmFortran_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmFortran_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmFortran_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmFortran_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmFortran_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmFortran_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmFortran_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmFortran_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmFortran_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmFortran_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmFortran_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmFortran_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmFortran_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmFortran_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmFortran_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmFortran_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmFortran_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmFortran_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmFortran_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmFortran_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmFortran_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmFortran_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmFortran_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmFortran_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -86,10 +293,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -102,12 +315,10 @@ typedef unsigned int flex_uint32_t;
/* 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.
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
*/
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -131,20 +342,16 @@ typedef void* yyscan_t;
* 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 cmFortran_yyrestart(yyin ,yyscanner )
-
+#define YY_NEW_FILE yyrestart( yyin , yyscanner )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
@@ -194,7 +401,6 @@ typedef size_t yy_size_t;
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
-
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
#ifndef YY_STRUCT_YY_BUFFER_STATE
@@ -254,7 +460,7 @@ struct yy_buffer_state
* possible backing-up.
*
* When we actually see the EOF, we change the status to "new"
- * (via cmFortran_yyrestart()), so that the user can continue scanning by
+ * (via yyrestart()), so that the user can continue scanning by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
@@ -271,73 +477,67 @@ struct yy_buffer_state
#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 cmFortran_yyrestart (FILE *input_file ,yyscan_t yyscanner );
-void cmFortran_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
-void cmFortran_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void cmFortran_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void cmFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-void cmFortran_yypop_buffer_state (yyscan_t yyscanner );
-
-static void cmFortran_yyensure_buffer_stack (yyscan_t yyscanner );
-static void cmFortran_yy_load_buffer_state (yyscan_t yyscanner );
-static void cmFortran_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
-
-#define YY_FLUSH_BUFFER cmFortran_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void yypop_buffer_state ( yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+static void yyensure_buffer_stack ( yyscan_t yyscanner );
+static void yy_load_buffer_state ( yyscan_t yyscanner );
+static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
+#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner)
-void *cmFortran_yyalloc (yy_size_t ,yyscan_t yyscanner );
-void *cmFortran_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
-void cmFortran_yyfree (void * ,yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
-#define yy_new_buffer cmFortran_yy_create_buffer
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
+#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
- cmFortran_yyensure_buffer_stack (yyscanner); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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 ){\
- cmFortran_yyensure_buffer_stack (yyscanner); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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 cmFortran_yywrap(yyscanner) (/*CONSTCOND*/1)
#define YY_SKIP_YYWRAP
-
-typedef unsigned char YY_CHAR;
+typedef flex_uint8_t 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 yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
+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 yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
@@ -348,7 +548,6 @@ static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
yyg->yy_hold_char = *yy_cp; \
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
-
#define YY_NUM_RULES 54
#define YY_END_OF_BUFFER 55
/* This struct is not used in this scanner,
@@ -358,7 +557,7 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
-static yyconst flex_int16_t yy_accept[210] =
+static const flex_int16_t yy_accept[210] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55, 49, 51, 50, 53, 1, 49, 33, 2, 47,
@@ -368,16 +567,16 @@ static yyconst flex_int16_t yy_accept[210] =
0, 0, 33, 33, 34, 36, 39, 49, 46, 46,
46, 46, 46, 46, 0, 52, 46, 0, 0, 0,
12, 0, 0, 0, 0, 0, 0, 49, 0, 11,
- 46, 0, 0, 5, 0, 0, 0, 29, 0, 0,
+ 46, 0, 0, 5, 0, 0, 0, 0, 29, 0,
33, 33, 33, 33, 0, 0, 40, 46, 46, 46,
46, 45, 12, 12, 0, 0, 0, 23, 0, 0,
0, 0, 0, 0, 6, 0, 0, 0, 0, 0,
0, 0, 0, 0, 46, 46, 46, 46, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 30, 31, 0, 0, 0, 0, 0, 0, 46, 46,
+ 0, 30, 31, 0, 0, 0, 0, 0, 46, 46,
46, 46, 0, 24, 25, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 32, 27, 0, 0, 20, 0,
+ 0, 0, 0, 0, 20, 32, 27, 0, 0, 0,
46, 46, 43, 46, 0, 26, 21, 0, 0, 0,
19, 0, 0, 18, 28, 0, 0, 41, 46, 46,
17, 22, 0, 7, 38, 7, 15, 0, 46, 46,
@@ -385,7 +584,7 @@ static yyconst flex_int16_t yy_accept[210] =
14, 16, 42, 44, 0, 0, 0, 13, 0
} ;
-static yyconst YY_CHAR yy_ec[256] =
+static const YY_CHAR yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
@@ -417,7 +616,7 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;
-static yyconst YY_CHAR yy_meta[50] =
+static const YY_CHAR yy_meta[50] =
{ 0,
1, 2, 2, 3, 4, 3, 3, 1, 1, 3,
3, 3, 3, 1, 3, 5, 3, 3, 1, 3,
@@ -426,40 +625,40 @@ static yyconst YY_CHAR yy_meta[50] =
7, 7, 7, 7, 7, 7, 7, 7, 7
} ;
-static yyconst flex_uint16_t yy_base[219] =
+static const flex_int16_t yy_base[219] =
{ 0,
- 0, 48, 0, 49, 513, 56, 52, 57, 62, 68,
- 515, 0, 583, 583, 509, 583, 97, 74, 583, 583,
- 583, 583, 491, 583, 423, 421, 0, 19, 40, 392,
- 36, 47, 86, 146, 88, 186, 413, 235, 275, 583,
- 407, 98, 583, 583, 0, 386, 583, 323, 65, 73,
- 81, 74, 127, 146, 583, 583, 583, 108, 0, 89,
- 120, 92, 362, 116, 161, 583, 0, 167, 371, 0,
- 168, 131, 146, 171, 81, 89, 352, 420, 353, 583,
- 0, 349, 178, 196, 175, 197, 188, 208, 196, 197,
- 256, 262, 324, 330, 337, 143, 0, 151, 220, 56,
-
- 305, 0, 336, 139, 225, 315, 305, 322, 318, 163,
- 320, 268, 266, 369, 583, 340, 347, 350, 350, 351,
- 357, 350, 357, 363, 140, 235, 359, 218, 362, 375,
- 379, 380, 381, 385, 384, 404, 405, 243, 235, 213,
- 583, 583, 405, 407, 410, 171, 410, 409, 419, 418,
- 423, 426, 311, 583, 583, 428, 429, 431, 173, 462,
- 435, 166, 145, 438, 583, 583, 441, 444, 583, 433,
- 448, 89, 0, 438, 450, 583, 583, 452, 457, 487,
- 583, 114, 0, 583, 583, 457, 462, 0, 465, 463,
- 583, 583, 468, 583, 583, 583, 583, 470, 471, 474,
-
- 500, 583, 0, 0, 505, 0, 65, 583, 583, 524,
- 531, 537, 540, 547, 554, 561, 568, 575
+ 0, 48, 0, 49, 464, 56, 52, 57, 62, 68,
+ 466, 0, 468, 468, 462, 468, 74, 81, 468, 468,
+ 468, 468, 447, 468, 442, 440, 0, 19, 41, 427,
+ 47, 41, 90, 119, 97, 158, 455, 207, 247, 468,
+ 454, 101, 468, 468, 0, 455, 468, 105, 430, 423,
+ 62, 67, 119, 151, 468, 468, 468, 121, 0, 90,
+ 93, 110, 431, 112, 142, 468, 0, 160, 295, 0,
+ 162, 411, 123, 102, 408, 405, 446, 344, 447, 468,
+ 0, 444, 170, 174, 420, 421, 132, 404, 95, 404,
+ 180, 186, 192, 228, 297, 397, 0, 168, 144, 52,
+
+ 411, 0, 204, 217, 397, 179, 390, 170, 389, 378,
+ 364, 390, 389, 230, 468, 363, 355, 337, 337, 334,
+ 335, 335, 330, 334, 187, 339, 267, 339, 327, 327,
+ 327, 324, 325, 325, 318, 319, 318, 354, 352, 323,
+ 327, 468, 468, 310, 307, 305, 297, 297, 275, 275,
+ 277, 279, 287, 468, 468, 286, 283, 273, 196, 307,
+ 200, 238, 234, 210, 468, 468, 468, 174, 171, 162,
+ 279, 182, 0, 269, 150, 468, 468, 137, 109, 323,
+ 468, 239, 0, 468, 468, 72, 71, 0, 283, 283,
+ 468, 468, 51, 468, 468, 468, 468, 37, 283, 288,
+
+ 330, 468, 0, 0, 331, 0, 52, 468, 468, 384,
+ 391, 397, 400, 407, 414, 421, 428, 435
} ;
-static yyconst flex_int16_t yy_def[219] =
+static const flex_int16_t yy_def[219] =
{ 0,
209, 1, 1, 1, 1, 1, 210, 210, 210, 210,
209, 211, 209, 209, 212, 209, 211, 209, 209, 209,
209, 209, 209, 209, 209, 211, 213, 213, 213, 213,
- 213, 213, 211, 213, 209, 209, 209, 214, 209, 209,
+ 213, 213, 211, 213, 209, 211, 209, 214, 209, 209,
209, 209, 209, 209, 211, 212, 209, 209, 209, 209,
209, 209, 209, 215, 209, 209, 209, 211, 213, 213,
213, 213, 213, 213, 209, 209, 34, 209, 209, 69,
@@ -482,7 +681,7 @@ static yyconst flex_int16_t yy_def[219] =
209, 209, 209, 209, 209, 209, 209, 209
} ;
-static yyconst flex_uint16_t yy_nxt[633] =
+static const flex_int16_t yy_nxt[518] =
{ 0,
12, 13, 14, 13, 13, 15, 16, 12, 17, 18,
19, 20, 21, 12, 22, 12, 23, 24, 12, 25,
@@ -491,72 +690,59 @@ static yyconst flex_uint16_t yy_nxt[633] =
27, 27, 28, 27, 29, 27, 27, 31, 32, 35,
35, 60, 35, 35, 41, 36, 36, 35, 37, 41,
35, 42, 43, 36, 41, 60, 42, 43, 44, 38,
- 41, 42, 61, 63, 44, 53, 53, 42, 53, 54,
- 39, 39, 64, 55, 63, 208, 61, 65, 66, 68,
- 65, 85, 68, 127, 64, 69, 39, 39, 48, 83,
-
- 84, 48, 83, 86, 127, 87, 90, 85, 88, 95,
- 110, 189, 95, 89, 97, 195, 195, 100, 86, 87,
- 90, 111, 49, 50, 88, 110, 51, 89, 53, 53,
- 97, 53, 54, 100, 52, 111, 55, 96, 49, 50,
- 104, 51, 102, 104, 98, 52, 45, 92, 53, 183,
- 92, 93, 96, 45, 45, 94, 99, 105, 102, 45,
- 98, 67, 65, 66, 45, 65, 45, 45, 68, 104,
- 182, 68, 104, 105, 69, 124, 106, 149, 107, 83,
- 84, 125, 83, 71, 45, 67, 45, 70, 149, 124,
- 70, 106, 107, 45, 45, 136, 125, 114, 108, 45,
-
- 114, 71, 116, 109, 45, 115, 45, 45, 168, 136,
- 179, 72, 73, 119, 108, 74, 75, 109, 116, 168,
- 122, 179, 123, 76, 45, 45, 117, 72, 73, 119,
- 74, 75, 118, 120, 76, 78, 122, 80, 123, 163,
- 121, 117, 78, 78, 118, 164, 126, 162, 78, 120,
- 78, 152, 129, 78, 121, 78, 78, 92, 53, 164,
- 92, 93, 126, 92, 53, 94, 92, 93, 129, 150,
- 139, 94, 138, 78, 78, 79, 79, 80, 79, 79,
+ 41, 42, 208, 61, 44, 48, 64, 42, 48, 202,
+ 39, 39, 53, 53, 63, 53, 54, 61, 64, 127,
+ 55, 65, 66, 201, 65, 63, 39, 39, 68, 49,
+
+ 127, 68, 83, 84, 69, 83, 48, 87, 88, 48,
+ 89, 50, 198, 90, 197, 97, 51, 98, 52, 45,
+ 53, 53, 95, 53, 54, 95, 45, 45, 55, 99,
+ 49, 97, 45, 98, 67, 100, 121, 45, 102, 45,
+ 45, 122, 50, 65, 66, 108, 65, 51, 109, 52,
+ 193, 100, 92, 53, 102, 92, 93, 45, 67, 70,
+ 94, 68, 70, 104, 68, 96, 104, 69, 106, 107,
+ 126, 83, 84, 71, 83, 114, 118, 71, 114, 119,
+ 192, 92, 53, 115, 92, 93, 126, 92, 53, 94,
+ 92, 93, 191, 92, 53, 94, 92, 93, 125, 72,
+
+ 73, 94, 74, 75, 189, 104, 76, 78, 104, 80,
+ 187, 133, 186, 125, 78, 78, 134, 185, 104, 103,
+ 78, 104, 78, 130, 149, 78, 131, 78, 78, 92,
+ 53, 114, 92, 93, 114, 149, 184, 94, 183, 115,
+ 195, 195, 182, 181, 179, 78, 78, 79, 79, 80,
79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
- 81, 79, 79, 79, 79, 79, 79, 81, 81, 81,
-
+ 79, 79, 81, 79, 79, 79, 79, 79, 79, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
- 81, 81, 81, 79, 81, 81, 81, 81, 81, 81,
- 81, 81, 81, 81, 48, 92, 53, 48, 92, 93,
- 132, 92, 53, 94, 92, 93, 128, 104, 95, 94,
- 104, 95, 135, 175, 130, 137, 132, 133, 49, 50,
- 131, 103, 51, 113, 134, 80, 112, 175, 135, 130,
- 52, 137, 131, 133, 49, 50, 96, 51, 134, 140,
- 114, 52, 70, 114, 141, 70, 142, 144, 115, 143,
- 146, 96, 145, 147, 140, 101, 103, 148, 47, 151,
- 141, 153, 142, 144, 143, 146, 72, 73, 145, 147,
-
- 74, 75, 154, 148, 151, 155, 153, 157, 76, 156,
- 158, 82, 72, 73, 159, 74, 75, 77, 154, 76,
- 78, 155, 80, 157, 156, 62, 158, 78, 78, 159,
- 160, 161, 165, 78, 166, 78, 167, 169, 78, 170,
- 78, 78, 58, 57, 171, 172, 160, 161, 165, 173,
- 166, 174, 167, 169, 170, 176, 177, 178, 78, 78,
- 171, 172, 181, 180, 184, 173, 180, 174, 185, 186,
- 187, 176, 177, 178, 188, 190, 191, 103, 181, 192,
- 184, 187, 193, 197, 185, 186, 190, 198, 180, 199,
- 188, 180, 191, 200, 201, 192, 202, 203, 193, 197,
-
- 204, 205, 103, 198, 205, 199, 205, 56, 200, 205,
- 201, 47, 202, 203, 209, 37, 204, 209, 206, 209,
- 209, 209, 209, 206, 40, 40, 40, 40, 40, 40,
- 40, 45, 209, 209, 209, 45, 45, 46, 46, 46,
- 46, 46, 46, 46, 59, 209, 59, 79, 79, 79,
+ 81, 81, 81, 81, 81, 79, 81, 81, 81, 81,
+ 81, 81, 81, 81, 81, 81, 70, 151, 95, 70,
+
+ 171, 95, 172, 173, 174, 188, 190, 199, 180, 203,
+ 103, 180, 151, 200, 204, 178, 171, 190, 172, 173,
+ 174, 188, 103, 199, 180, 203, 177, 180, 200, 176,
+ 204, 205, 205, 175, 205, 205, 72, 73, 103, 74,
+ 75, 96, 170, 76, 78, 169, 80, 168, 206, 206,
+ 167, 78, 78, 166, 165, 164, 163, 78, 162, 78,
+ 161, 160, 78, 159, 78, 78, 158, 157, 156, 155,
+ 154, 153, 152, 150, 148, 147, 146, 145, 144, 143,
+ 142, 141, 78, 78, 40, 40, 40, 40, 40, 40,
+ 40, 45, 140, 139, 138, 45, 45, 46, 46, 46,
+
+ 46, 46, 46, 46, 59, 137, 59, 79, 79, 79,
79, 79, 79, 79, 91, 91, 91, 91, 91, 91,
- 91, 194, 194, 194, 209, 194, 194, 194, 196, 209,
- 196, 209, 196, 196, 196, 207, 207, 207, 207, 207,
- 209, 207, 11, 209, 209, 209, 209, 209, 209, 209,
+ 91, 194, 194, 194, 136, 194, 194, 194, 196, 135,
+ 196, 132, 196, 196, 196, 207, 207, 207, 207, 207,
+ 129, 207, 128, 124, 123, 120, 117, 116, 113, 80,
+ 112, 111, 110, 105, 101, 86, 85, 47, 82, 77,
+ 62, 58, 57, 56, 47, 209, 37, 11, 209, 209,
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
-
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
+
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
- 209, 209
+ 209, 209, 209, 209, 209, 209, 209
} ;
-static yyconst flex_int16_t yy_chk[633] =
+static const flex_int16_t yy_chk[518] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@@ -565,69 +751,56 @@ static yyconst flex_int16_t yy_chk[633] =
1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
4, 28, 2, 4, 7, 2, 4, 6, 6, 8,
6, 7, 7, 6, 9, 28, 8, 8, 9, 6,
- 10, 9, 29, 31, 10, 18, 18, 10, 18, 18,
- 6, 6, 32, 18, 31, 207, 29, 33, 33, 35,
- 33, 49, 35, 100, 32, 35, 6, 6, 17, 42,
-
- 42, 17, 42, 50, 100, 50, 52, 49, 51, 58,
- 75, 172, 58, 51, 60, 182, 182, 62, 50, 50,
- 52, 76, 17, 17, 51, 75, 17, 51, 53, 53,
- 60, 53, 53, 62, 17, 76, 53, 58, 17, 17,
- 104, 17, 64, 104, 61, 17, 34, 54, 54, 163,
- 54, 54, 58, 34, 34, 54, 61, 72, 64, 34,
- 61, 34, 65, 65, 34, 65, 34, 34, 68, 71,
- 162, 68, 71, 72, 68, 96, 73, 125, 73, 83,
- 83, 98, 83, 71, 34, 34, 36, 36, 125, 96,
- 36, 73, 73, 36, 36, 110, 98, 84, 74, 36,
-
- 84, 36, 85, 74, 36, 84, 36, 36, 146, 110,
- 159, 36, 36, 87, 74, 36, 36, 74, 85, 146,
- 89, 159, 90, 36, 36, 36, 86, 36, 36, 87,
- 36, 36, 86, 88, 36, 38, 89, 38, 90, 139,
- 88, 86, 38, 38, 86, 140, 99, 138, 38, 88,
- 38, 128, 105, 38, 88, 38, 38, 91, 91, 140,
- 91, 91, 99, 92, 92, 91, 92, 92, 105, 126,
- 113, 92, 112, 38, 38, 39, 39, 39, 39, 39,
+ 10, 9, 207, 29, 10, 17, 32, 10, 17, 198,
+ 6, 6, 18, 18, 31, 18, 18, 29, 32, 100,
+ 18, 33, 33, 193, 33, 31, 6, 6, 35, 17,
+
+ 100, 35, 42, 42, 35, 42, 48, 51, 51, 48,
+ 52, 17, 187, 52, 186, 60, 17, 61, 17, 34,
+ 53, 53, 58, 53, 53, 58, 34, 34, 53, 61,
+ 48, 60, 34, 61, 34, 62, 89, 34, 64, 34,
+ 34, 89, 48, 65, 65, 74, 65, 48, 74, 48,
+ 179, 62, 54, 54, 64, 54, 54, 34, 34, 36,
+ 54, 68, 36, 71, 68, 58, 71, 68, 73, 73,
+ 99, 83, 83, 36, 83, 84, 87, 71, 84, 87,
+ 178, 91, 91, 84, 91, 91, 99, 92, 92, 91,
+ 92, 92, 175, 93, 93, 92, 93, 93, 98, 36,
+
+ 36, 93, 36, 36, 172, 103, 36, 38, 103, 38,
+ 170, 108, 169, 98, 38, 38, 108, 168, 104, 103,
+ 38, 104, 38, 106, 125, 38, 106, 38, 38, 94,
+ 94, 114, 94, 94, 114, 125, 164, 94, 163, 114,
+ 182, 182, 162, 161, 159, 38, 38, 39, 39, 39,
39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
-
39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
- 39, 39, 39, 39, 48, 93, 93, 48, 93, 93,
- 107, 94, 94, 93, 94, 94, 101, 103, 95, 94,
- 103, 95, 109, 153, 106, 111, 107, 108, 48, 48,
- 106, 103, 48, 82, 108, 79, 77, 153, 109, 106,
- 48, 111, 106, 108, 48, 48, 95, 48, 108, 116,
- 114, 48, 69, 114, 117, 69, 118, 120, 114, 119,
- 122, 95, 121, 123, 116, 63, 69, 124, 46, 127,
- 117, 129, 118, 120, 119, 122, 69, 69, 121, 123,
-
- 69, 69, 130, 124, 127, 131, 129, 133, 69, 132,
- 134, 41, 69, 69, 135, 69, 69, 37, 130, 69,
- 78, 131, 78, 133, 132, 30, 134, 78, 78, 135,
- 136, 137, 143, 78, 144, 78, 145, 147, 78, 148,
- 78, 78, 26, 25, 149, 150, 136, 137, 143, 151,
- 144, 152, 145, 147, 148, 156, 157, 158, 78, 78,
- 149, 150, 161, 160, 164, 151, 160, 152, 167, 168,
- 170, 156, 157, 158, 171, 174, 175, 160, 161, 178,
- 164, 170, 179, 186, 167, 168, 174, 187, 180, 189,
- 171, 180, 175, 190, 193, 178, 198, 199, 179, 186,
-
- 200, 201, 180, 187, 201, 189, 205, 23, 190, 205,
- 193, 15, 198, 199, 11, 5, 200, 0, 201, 0,
- 0, 0, 0, 205, 210, 210, 210, 210, 210, 210,
- 210, 211, 0, 0, 0, 211, 211, 212, 212, 212,
- 212, 212, 212, 212, 213, 0, 213, 214, 214, 214,
+ 39, 39, 39, 39, 39, 39, 69, 127, 95, 69,
+
+ 149, 95, 150, 151, 152, 171, 174, 189, 160, 199,
+ 69, 160, 127, 190, 200, 158, 149, 174, 150, 151,
+ 152, 171, 160, 189, 180, 199, 157, 180, 190, 156,
+ 200, 201, 205, 153, 201, 205, 69, 69, 180, 69,
+ 69, 95, 148, 69, 78, 147, 78, 146, 201, 205,
+ 145, 78, 78, 144, 141, 140, 139, 78, 138, 78,
+ 137, 136, 78, 135, 78, 78, 134, 133, 132, 131,
+ 130, 129, 128, 126, 124, 123, 122, 121, 120, 119,
+ 118, 117, 78, 78, 210, 210, 210, 210, 210, 210,
+ 210, 211, 116, 113, 112, 211, 211, 212, 212, 212,
+
+ 212, 212, 212, 212, 213, 111, 213, 214, 214, 214,
214, 214, 214, 214, 215, 215, 215, 215, 215, 215,
- 215, 216, 216, 216, 0, 216, 216, 216, 217, 0,
- 217, 0, 217, 217, 217, 218, 218, 218, 218, 218,
- 0, 218, 209, 209, 209, 209, 209, 209, 209, 209,
+ 215, 216, 216, 216, 110, 216, 216, 216, 217, 109,
+ 217, 107, 217, 217, 217, 218, 218, 218, 218, 218,
+ 105, 218, 101, 96, 90, 88, 86, 85, 82, 79,
+ 77, 76, 75, 72, 63, 50, 49, 46, 41, 37,
+ 30, 26, 25, 23, 15, 11, 5, 209, 209, 209,
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
-
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
+
209, 209, 209, 209, 209, 209, 209, 209, 209, 209,
- 209, 209
+ 209, 209, 209, 209, 209, 209, 209
} ;
/* The intent behind this definition is that it'll catch
@@ -637,8 +810,6 @@ static yyconst flex_int16_t yy_chk[633] =
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
-#line 1 "cmFortranLexer.in.l"
-#line 2 "cmFortranLexer.in.l"
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
/*-------------------------------------------------------------------------
@@ -657,18 +828,18 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex -i --nounistd -DFLEXINT_H --prefix=cmFortran_yy --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
+ flex -i --nounistd -DFLEXINT_H --noline --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
Modify cmFortranLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmFortranLexer.h cmFortranLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in cmFortran_yy_scan_bytes for loop condition of _yybytes_len to size_t
-
+ - remove trailing whitespace: sed -i 's/\s*$//' cmFortranLexer.h cmFortranLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmFortranLexer.h cmFortranLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmFortranLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#undef YY_NO_UNPUT
#define cmFortranLexer_cxx
@@ -677,16 +848,13 @@ Modify cmFortranLexer.cxx:
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = cmFortranParser_Input(yyextra, buf, max_size); }
+ do { result = cmFortranParser_Input(yyextra, buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmFortranParserTokens.h"
/*--------------------------------------------------------------------------*/
-
-#line 688 "cmFortranLexer.cxx"
-
#define INITIAL 0
#define free_fmt 1
#define fixed_fmt 2
@@ -731,44 +899,44 @@ struct yyguts_t
}; /* end struct yyguts_t */
-static int yy_init_globals (yyscan_t yyscanner );
+static int yy_init_globals ( yyscan_t yyscanner );
-int cmFortran_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmFortran_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 cmFortran_yylex_destroy (yyscan_t yyscanner );
+int yylex_destroy ( yyscan_t yyscanner );
-int cmFortran_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmFortran_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmFortran_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmFortran_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmFortran_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmFortran_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmFortran_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmFortran_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmFortran_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmFortran_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmFortran_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmFortran_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmFortran_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmFortran_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -776,32 +944,31 @@ void cmFortran_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmFortran_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmFortran_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef YY_NO_UNPUT
- static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);
+ static void yyunput ( int c, char *buf_ptr , yyscan_t yyscanner);
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
-
#ifdef __cplusplus
-static int yyinput (yyscan_t yyscanner );
+static int yyinput ( yyscan_t yyscanner );
#else
-static int input (yyscan_t yyscanner );
+static int input ( yyscan_t yyscanner );
#endif
#endif
@@ -832,7 +999,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- size_t n; \
+ int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -845,7 +1012,7 @@ static int input (yyscan_t yyscanner );
else \
{ \
errno=0; \
- while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
@@ -886,9 +1053,9 @@ static int input (yyscan_t yyscanner );
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmFortran_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmFortran_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng
@@ -936,19 +1103,15 @@ YY_DECL
yyout = stdout;
if ( ! YY_CURRENT_BUFFER ) {
- cmFortran_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmFortran_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
{
-#line 56 "cmFortranLexer.in.l"
-
-
-#line 951 "cmFortranLexer.cxx"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
@@ -977,12 +1140,12 @@ yy_match:
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 210 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
- while ( yy_base[yy_current_state] != 583 );
+ while ( yy_base[yy_current_state] != 468 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@@ -1008,7 +1171,6 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 58 "cmFortranLexer.in.l"
{
cmFortranParser_StringStart(yyextra);
cmFortranParser_SetOldStartcond(yyextra, YY_START);
@@ -1017,7 +1179,6 @@ YY_RULE_SETUP
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 64 "cmFortranLexer.in.l"
{
cmFortranParser_StringStart(yyextra);
cmFortranParser_SetOldStartcond(yyextra, YY_START);
@@ -1025,10 +1186,8 @@ YY_RULE_SETUP
}
YY_BREAK
case 3:
-#line 71 "cmFortranLexer.in.l"
case 4:
YY_RULE_SETUP
-#line 71 "cmFortranLexer.in.l"
{
BEGIN(cmFortranParser_GetOldStartcond(yyextra) );
yylvalp->string = strdup(cmFortranParser_StringEnd(yyextra));
@@ -1037,17 +1196,14 @@ YY_RULE_SETUP
YY_BREAK
case 5:
/* rule 5 can match eol */
-#line 78 "cmFortranLexer.in.l"
case 6:
/* rule 6 can match eol */
YY_RULE_SETUP
-#line 78 "cmFortranLexer.in.l"
/* Ignore (continued strings, free fmt) */
YY_BREAK
case 7:
/* rule 7 can match eol */
YY_RULE_SETUP
-#line 80 "cmFortranLexer.in.l"
{
if (cmFortranParser_GetOldStartcond(yyextra) == fixed_fmt)
; /* Ignore (cont. strings, fixed fmt) */
@@ -1060,7 +1216,6 @@ YY_RULE_SETUP
case 8:
/* rule 8 can match eol */
YY_RULE_SETUP
-#line 90 "cmFortranLexer.in.l"
{
unput ('\n');
BEGIN(INITIAL);
@@ -1069,7 +1224,6 @@ YY_RULE_SETUP
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 96 "cmFortranLexer.in.l"
{
cmFortranParser_StringAppend(yyextra, yytext[0]);
}
@@ -1077,24 +1231,20 @@ YY_RULE_SETUP
case 10:
/* rule 10 can match eol */
YY_RULE_SETUP
-#line 100 "cmFortranLexer.in.l"
{ return EOSTMT; } /* Treat comments like */
YY_BREAK
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
-#line 101 "cmFortranLexer.in.l"
{ return EOSTMT; } /* empty lines */
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 103 "cmFortranLexer.in.l"
{ return CPP_LINE_DIRECTIVE; }
YY_BREAK
case 13:
/* rule 13 can match eol */
YY_RULE_SETUP
-#line 104 "cmFortranLexer.in.l"
{
yytext[yyleng-1] = 0;
yylvalp->string = strdup(strchr(yytext, '<')+1);
@@ -1103,171 +1253,138 @@ YY_RULE_SETUP
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 109 "cmFortranLexer.in.l"
{ return CPP_INCLUDE; }
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 110 "cmFortranLexer.in.l"
{ return F90PPR_INCLUDE; }
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 111 "cmFortranLexer.in.l"
{ return COCO_INCLUDE; }
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 113 "cmFortranLexer.in.l"
{ return CPP_DEFINE; }
YY_BREAK
case 18:
YY_RULE_SETUP
-#line 114 "cmFortranLexer.in.l"
{ return F90PPR_DEFINE; }
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 116 "cmFortranLexer.in.l"
{ return CPP_UNDEF; }
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 117 "cmFortranLexer.in.l"
{ return F90PPR_UNDEF; }
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 119 "cmFortranLexer.in.l"
{ return CPP_IFDEF; }
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 120 "cmFortranLexer.in.l"
{ return CPP_IFNDEF; }
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 121 "cmFortranLexer.in.l"
{ return CPP_IF; }
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 122 "cmFortranLexer.in.l"
{ return CPP_ELIF; }
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 123 "cmFortranLexer.in.l"
{ return CPP_ELSE; }
YY_BREAK
case 26:
YY_RULE_SETUP
-#line 124 "cmFortranLexer.in.l"
{ return CPP_ENDIF; }
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 126 "cmFortranLexer.in.l"
{ return F90PPR_IFDEF; }
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 127 "cmFortranLexer.in.l"
{ return F90PPR_IFNDEF; }
YY_BREAK
case 29:
YY_RULE_SETUP
-#line 128 "cmFortranLexer.in.l"
{ return F90PPR_IF; }
YY_BREAK
case 30:
YY_RULE_SETUP
-#line 129 "cmFortranLexer.in.l"
{ return F90PPR_ELIF; }
YY_BREAK
case 31:
YY_RULE_SETUP
-#line 130 "cmFortranLexer.in.l"
{ return F90PPR_ELSE; }
YY_BREAK
case 32:
YY_RULE_SETUP
-#line 131 "cmFortranLexer.in.l"
{ return F90PPR_ENDIF; }
YY_BREAK
/* Line continuations, possible involving comments. */
case 33:
/* rule 33 can match eol */
YY_RULE_SETUP
-#line 134 "cmFortranLexer.in.l"
YY_BREAK
case 34:
/* rule 34 can match eol */
YY_RULE_SETUP
-#line 135 "cmFortranLexer.in.l"
YY_BREAK
case 35:
YY_RULE_SETUP
-#line 137 "cmFortranLexer.in.l"
{ return COMMA; }
YY_BREAK
case 36:
YY_RULE_SETUP
-#line 139 "cmFortranLexer.in.l"
{ return DCOLON; }
YY_BREAK
case 37:
YY_RULE_SETUP
-#line 140 "cmFortranLexer.in.l"
{ return COLON; }
YY_BREAK
case 38:
/* rule 38 can match eol */
YY_RULE_SETUP
-#line 142 "cmFortranLexer.in.l"
{ return GARBAGE; }
YY_BREAK
case 39:
YY_RULE_SETUP
-#line 144 "cmFortranLexer.in.l"
{ return ASSIGNMENT_OP; }
YY_BREAK
case 40:
YY_RULE_SETUP
-#line 146 "cmFortranLexer.in.l"
{ return END; }
YY_BREAK
case 41:
YY_RULE_SETUP
-#line 147 "cmFortranLexer.in.l"
{ return INCLUDE; }
YY_BREAK
case 42:
YY_RULE_SETUP
-#line 148 "cmFortranLexer.in.l"
{ return INTERFACE; }
YY_BREAK
case 43:
YY_RULE_SETUP
-#line 149 "cmFortranLexer.in.l"
{ return MODULE; }
YY_BREAK
case 44:
YY_RULE_SETUP
-#line 150 "cmFortranLexer.in.l"
{ return SUBMODULE; }
YY_BREAK
case 45:
YY_RULE_SETUP
-#line 151 "cmFortranLexer.in.l"
{ return USE; }
YY_BREAK
case 46:
YY_RULE_SETUP
-#line 153 "cmFortranLexer.in.l"
{
yylvalp->string = strdup(yytext);
return WORD;
@@ -1275,39 +1392,32 @@ YY_RULE_SETUP
YY_BREAK
case 47:
YY_RULE_SETUP
-#line 158 "cmFortranLexer.in.l"
{ return LPAREN; }
YY_BREAK
case 48:
YY_RULE_SETUP
-#line 159 "cmFortranLexer.in.l"
{ return RPAREN; }
YY_BREAK
case 49:
YY_RULE_SETUP
-#line 161 "cmFortranLexer.in.l"
{ return GARBAGE; }
YY_BREAK
case 50:
/* rule 50 can match eol */
YY_RULE_SETUP
-#line 163 "cmFortranLexer.in.l"
{ return EOSTMT; }
YY_BREAK
case 51:
YY_RULE_SETUP
-#line 166 "cmFortranLexer.in.l"
/* Ignore */
YY_BREAK
case 52:
/* rule 52 can match eol */
YY_RULE_SETUP
-#line 167 "cmFortranLexer.in.l"
/* Ignore line-endings preceded by \ */
YY_BREAK
case 53:
YY_RULE_SETUP
-#line 169 "cmFortranLexer.in.l"
{ return *yytext; }
YY_BREAK
case YY_STATE_EOF(INITIAL):
@@ -1315,7 +1425,6 @@ 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 171 "cmFortranLexer.in.l"
{
if(!cmFortranParser_FilePop(yyextra) )
{
@@ -1325,10 +1434,8 @@ case YY_STATE_EOF(str_dq):
YY_BREAK
case 54:
YY_RULE_SETUP
-#line 178 "cmFortranLexer.in.l"
ECHO;
YY_BREAK
-#line 1331 "cmFortranLexer.cxx"
case YY_END_OF_BUFFER:
{
@@ -1344,7 +1451,7 @@ ECHO;
/* 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
- * cmFortran_yylex(). If so, then we have to assure
+ * 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
@@ -1404,7 +1511,7 @@ ECHO;
{
yyg->yy_did_buffer_switch_on_eof = 0;
- if ( cmFortran_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
@@ -1458,7 +1565,7 @@ ECHO;
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
-} /* end of cmFortran_yylex */
+} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
*
@@ -1472,7 +1579,7 @@ 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;
- yy_size_t number_to_move, i;
+ 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] )
@@ -1501,7 +1608,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Try to read more data. */
/* First move last chars to start of buffer. */
- number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
@@ -1537,7 +1644,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
- cmFortran_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
+ yyrealloc( (void *) b->yy_ch_buf,
+ (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
}
else
/* Can't grow it, we don't own it. */
@@ -1569,7 +1677,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
- cmFortran_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
}
else
@@ -1583,12 +1691,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
ret_val = EOB_ACT_CONTINUE_SCAN;
- if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ if ((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. */
int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
- YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cmFortran_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
+ (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ /* "- 2" to take care of EOB's */
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
}
yyg->yy_n_chars += number_to_move;
@@ -1623,9 +1734,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 210 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
}
return yy_current_state;
@@ -1652,9 +1763,9 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 210 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
yy_is_jam = (yy_current_state == 209);
(void)yyg;
@@ -1728,7 +1839,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{ /* need more input */
- int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
@@ -1745,13 +1856,13 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
*/
/* Reset buffer status. */
- cmFortran_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
- if ( cmFortran_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
return 0;
if ( ! yyg->yy_did_buffer_switch_on_eof )
@@ -1785,34 +1896,34 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
* @param yyscanner The scanner object.
* @note This function does not reset the start condition to @c INITIAL .
*/
- void cmFortran_yyrestart (FILE * input_file , yyscan_t yyscanner)
+ void yyrestart (FILE * input_file , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! YY_CURRENT_BUFFER ){
- cmFortran_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmFortran_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmFortran_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
- cmFortran_yy_load_buffer_state(yyscanner );
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
+ yy_load_buffer_state( yyscanner );
}
/** Switch to a different input buffer.
* @param new_buffer The new input buffer.
* @param yyscanner The scanner object.
*/
- void cmFortran_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+ void 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
- * cmFortran_yypop_buffer_state();
- * cmFortran_yypush_buffer_state(new_buffer);
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
*/
- cmFortran_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
if ( YY_CURRENT_BUFFER == new_buffer )
return;
@@ -1825,17 +1936,17 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- cmFortran_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
/* We don't actually know whether we did this switch during
- * EOF (cmFortran_yywrap()) processing, but the only time this flag
- * is looked at is after cmFortran_yywrap() is called, so it's safe
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after yywrap() is called, so it's safe
* to go ahead and always set it.
*/
yyg->yy_did_buffer_switch_on_eof = 1;
}
-static void cmFortran_yy_load_buffer_state (yyscan_t yyscanner)
+static void 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;
@@ -1850,35 +1961,35 @@ static void cmFortran_yy_load_buffer_state (yyscan_t yyscanner)
* @param yyscanner The scanner object.
* @return the allocated buffer state.
*/
- YY_BUFFER_STATE cmFortran_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
+ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
- b = (YY_BUFFER_STATE) cmFortran_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmFortran_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
- b->yy_buf_size = (yy_size_t)size;
+ 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 *) cmFortran_yyalloc(b->yy_buf_size + 2 ,yyscanner );
+ b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmFortran_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_is_our_buffer = 1;
- cmFortran_yy_init_buffer(b,file ,yyscanner);
+ yy_init_buffer( b, file , yyscanner);
return b;
}
/** Destroy the buffer.
- * @param b a buffer created with cmFortran_yy_create_buffer()
+ * @param b a buffer created with yy_create_buffer()
* @param yyscanner The scanner object.
*/
- void cmFortran_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+ void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1889,28 +2000,28 @@ static void cmFortran_yy_load_buffer_state (yyscan_t yyscanner)
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
- cmFortran_yyfree((void *) b->yy_ch_buf ,yyscanner );
+ yyfree( (void *) b->yy_ch_buf , yyscanner );
- cmFortran_yyfree((void *) b ,yyscanner );
+ 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 cmFortran_yyrestart() or at EOF.
+ * such as during a yyrestart() or at EOF.
*/
- static void cmFortran_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
{
int oerrno = errno;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
- cmFortran_yy_flush_buffer(b ,yyscanner);
+ yy_flush_buffer( b , yyscanner);
b->yy_input_file = file;
b->yy_fill_buffer = 1;
- /* If b is the current buffer, then cmFortran_yy_init_buffer was _probably_
- * called from cmFortran_yyrestart() or through yy_get_next_buffer.
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from 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){
@@ -1927,7 +2038,7 @@ static void cmFortran_yy_load_buffer_state (yyscan_t yyscanner)
* @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
* @param yyscanner The scanner object.
*/
- void cmFortran_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+ void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! b )
@@ -1948,7 +2059,7 @@ static void cmFortran_yy_load_buffer_state (yyscan_t yyscanner)
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == YY_CURRENT_BUFFER )
- cmFortran_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
/** Pushes the new state onto the stack. The new state becomes
@@ -1957,15 +2068,15 @@ static void cmFortran_yy_load_buffer_state (yyscan_t yyscanner)
* @param new_buffer The new state.
* @param yyscanner The scanner object.
*/
-void cmFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (new_buffer == NULL)
return;
- cmFortran_yyensure_buffer_stack(yyscanner);
+ yyensure_buffer_stack(yyscanner);
- /* This block is copied from cmFortran_yy_switch_to_buffer. */
+ /* This block is copied from yy_switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
@@ -1979,8 +2090,8 @@ void cmFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscan
yyg->yy_buffer_stack_top++;
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- /* copied from cmFortran_yy_switch_to_buffer. */
- cmFortran_yy_load_buffer_state(yyscanner );
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
@@ -1988,19 +2099,19 @@ void cmFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscan
* The next element becomes the new top.
* @param yyscanner The scanner object.
*/
-void cmFortran_yypop_buffer_state (yyscan_t yyscanner)
+void yypop_buffer_state (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!YY_CURRENT_BUFFER)
return;
- cmFortran_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
+ 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) {
- cmFortran_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
}
@@ -2008,9 +2119,9 @@ void cmFortran_yypop_buffer_state (yyscan_t yyscanner)
/* Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
-static void cmFortran_yyensure_buffer_stack (yyscan_t yyscanner)
+static void yyensure_buffer_stack (yyscan_t yyscanner)
{
- int num_to_alloc;
+ yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
@@ -2020,11 +2131,11 @@ static void cmFortran_yyensure_buffer_stack (yyscan_t yyscanner)
* immediate realloc on the next call.
*/
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmFortran_yyalloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
if ( ! yyg->yy_buffer_stack )
- YY_FATAL_ERROR( "out of dynamic memory in cmFortran_yyensure_buffer_stack()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
@@ -2039,12 +2150,12 @@ static void cmFortran_yyensure_buffer_stack (yyscan_t yyscanner)
yy_size_t grow_size = 8 /* arbitrary grow size */;
num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmFortran_yyrealloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)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 cmFortran_yyensure_buffer_stack()" );
+ YY_FATAL_ERROR( "out of dynamic memory in 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*));
@@ -2058,7 +2169,7 @@ static void cmFortran_yyensure_buffer_stack (yyscan_t yyscanner)
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
-YY_BUFFER_STATE cmFortran_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
@@ -2068,11 +2179,11 @@ YY_BUFFER_STATE cmFortran_yy_scan_buffer (char * base, yy_size_t size , yyscan
/* They forgot to leave room for the EOB's. */
return NULL;
- b = (YY_BUFFER_STATE) cmFortran_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmFortran_yy_scan_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_size = (int) (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 = NULL;
@@ -2082,53 +2193,53 @@ YY_BUFFER_STATE cmFortran_yy_scan_buffer (char * base, yy_size_t size , yyscan
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
- cmFortran_yy_switch_to_buffer(b ,yyscanner );
+ yy_switch_to_buffer( b , yyscanner );
return b;
}
-/** Setup the input buffer state to scan a string. The next call to cmFortran_yylex() will
+/** Setup the input buffer state to scan a string. The next call to 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
- * cmFortran_yy_scan_bytes() instead.
+ * yy_scan_bytes() instead.
*/
-YY_BUFFER_STATE cmFortran_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
{
- return cmFortran_yy_scan_bytes(yystr,(int) strlen(yystr) ,yyscanner);
+ return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
}
-/** Setup the input buffer state to scan the given bytes. The next call to cmFortran_yylex() will
+/** Setup the input buffer state to scan the given bytes. The next call to 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 cmFortran_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
- yy_size_t i;
+ int i;
/* Get memory for full buffer, including space for trailing EOB's. */
- n = (yy_size_t) _yybytes_len + 2;
- buf = (char *) cmFortran_yyalloc(n ,yyscanner );
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) yyalloc( n , yyscanner );
if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmFortran_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
- for ( i = 0; i < (size_t)_yybytes_len; ++i )
+ for ( i = 0; i < _yybytes_len; ++i )
buf[i] = yybytes[i];
buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
- b = cmFortran_yy_scan_buffer(buf,n ,yyscanner);
+ b = yy_scan_buffer( buf, n , yyscanner);
if ( ! b )
- YY_FATAL_ERROR( "bad buffer in cmFortran_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
@@ -2142,11 +2253,11 @@ YY_BUFFER_STATE cmFortran_yy_scan_bytes (yyconst char * yybytes, int _yybytes_
#define YY_EXIT_FAILURE 2
#endif
-static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- (void) fprintf( stderr, "%s\n", msg );
+ fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
@@ -2172,7 +2283,7 @@ static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
/** Get the user-defined data for this scanner.
* @param yyscanner The scanner object.
*/
-YY_EXTRA_TYPE cmFortran_yyget_extra (yyscan_t yyscanner)
+YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyextra;
@@ -2181,7 +2292,7 @@ YY_EXTRA_TYPE cmFortran_yyget_extra (yyscan_t yyscanner)
/** Get the current line number.
* @param yyscanner The scanner object.
*/
-int cmFortran_yyget_lineno (yyscan_t yyscanner)
+int yyget_lineno (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -2194,7 +2305,7 @@ int cmFortran_yyget_lineno (yyscan_t yyscanner)
/** Get the current column number.
* @param yyscanner The scanner object.
*/
-int cmFortran_yyget_column (yyscan_t yyscanner)
+int yyget_column (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -2207,7 +2318,7 @@ int cmFortran_yyget_column (yyscan_t yyscanner)
/** Get the input stream.
* @param yyscanner The scanner object.
*/
-FILE *cmFortran_yyget_in (yyscan_t yyscanner)
+FILE *yyget_in (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyin;
@@ -2216,7 +2327,7 @@ FILE *cmFortran_yyget_in (yyscan_t yyscanner)
/** Get the output stream.
* @param yyscanner The scanner object.
*/
-FILE *cmFortran_yyget_out (yyscan_t yyscanner)
+FILE *yyget_out (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyout;
@@ -2225,7 +2336,7 @@ FILE *cmFortran_yyget_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
-int cmFortran_yyget_leng (yyscan_t yyscanner)
+int yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
@@ -2235,7 +2346,7 @@ int cmFortran_yyget_leng (yyscan_t yyscanner)
* @param yyscanner The scanner object.
*/
-char *cmFortran_yyget_text (yyscan_t yyscanner)
+char *yyget_text (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yytext;
@@ -2245,7 +2356,7 @@ char *cmFortran_yyget_text (yyscan_t yyscanner)
* @param user_defined The data to be associated with this scanner.
* @param yyscanner The scanner object.
*/
-void cmFortran_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
+void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyextra = user_defined ;
@@ -2255,13 +2366,13 @@ void cmFortran_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
* @param _line_number line number
* @param yyscanner The scanner object.
*/
-void cmFortran_yyset_lineno (int _line_number , yyscan_t yyscanner)
+void 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( "cmFortran_yyset_lineno called with no buffer" );
+ YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
yylineno = _line_number;
}
@@ -2270,13 +2381,13 @@ void cmFortran_yyset_lineno (int _line_number , yyscan_t yyscanner)
* @param _column_no column number
* @param yyscanner The scanner object.
*/
-void cmFortran_yyset_column (int _column_no , yyscan_t yyscanner)
+void 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( "cmFortran_yyset_column called with no buffer" );
+ YY_FATAL_ERROR( "yyset_column called with no buffer" );
yycolumn = _column_no;
}
@@ -2285,27 +2396,27 @@ void cmFortran_yyset_column (int _column_no , yyscan_t yyscanner)
* input buffer.
* @param _in_str A readable stream.
* @param yyscanner The scanner object.
- * @see cmFortran_yy_switch_to_buffer
+ * @see yy_switch_to_buffer
*/
-void cmFortran_yyset_in (FILE * _in_str , yyscan_t yyscanner)
+void yyset_in (FILE * _in_str , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyin = _in_str ;
}
-void cmFortran_yyset_out (FILE * _out_str , yyscan_t yyscanner)
+void yyset_out (FILE * _out_str , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyout = _out_str ;
}
-int cmFortran_yyget_debug (yyscan_t yyscanner)
+int yyget_debug (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yy_flex_debug;
}
-void cmFortran_yyset_debug (int _bdebug , yyscan_t yyscanner)
+void yyset_debug (int _bdebug , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ;
@@ -2315,20 +2426,18 @@ void cmFortran_yyset_debug (int _bdebug , yyscan_t yyscanner)
/* User-visible API */
-/* cmFortran_yylex_init is special because it creates the scanner itself, so it is
+/* 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 cmFortran_yylex_init(yyscan_t* ptr_yy_globals)
-
+int yylex_init(yyscan_t* ptr_yy_globals)
{
if (ptr_yy_globals == NULL){
errno = EINVAL;
return 1;
}
- *ptr_yy_globals = (yyscan_t) cmFortran_yyalloc ( sizeof( struct yyguts_t ), NULL );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -2341,27 +2450,25 @@ int cmFortran_yylex_init(yyscan_t* ptr_yy_globals)
return yy_init_globals ( *ptr_yy_globals );
}
-/* cmFortran_yylex_init_extra has the same functionality as cmFortran_yylex_init, but follows the
+/* yylex_init_extra has the same functionality as 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 cmFortran_yyalloc in
+ * The user defined value in the first argument will be available to yyalloc in
* the yyextra field.
*/
-
-int cmFortran_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
-
+int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
{
struct yyguts_t dummy_yyguts;
- cmFortran_yyset_extra (yy_user_defined, &dummy_yyguts);
+ yyset_extra (yy_user_defined, &dummy_yyguts);
if (ptr_yy_globals == NULL){
errno = EINVAL;
return 1;
}
- *ptr_yy_globals = (yyscan_t) cmFortran_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -2372,7 +2479,7 @@ int cmFortran_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_gl
yy_init_globals. Leave at 0x00 for releases. */
memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
- cmFortran_yyset_extra (yy_user_defined, *ptr_yy_globals);
+ yyset_extra (yy_user_defined, *ptr_yy_globals);
return yy_init_globals ( *ptr_yy_globals );
}
@@ -2381,7 +2488,7 @@ 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 cmFortran_yylex_destroy(), so don't allocate here.
+ * This function is called from yylex_destroy(), so don't allocate here.
*/
yyg->yy_buffer_stack = NULL;
@@ -2405,37 +2512,37 @@ static int yy_init_globals (yyscan_t yyscanner)
#endif
/* For future reference: Set errno on error, since we are called by
- * cmFortran_yylex_init()
+ * yylex_init()
*/
return 0;
}
-/* cmFortran_yylex_destroy is for both reentrant and non-reentrant scanners. */
-int cmFortran_yylex_destroy (yyscan_t yyscanner)
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int yylex_destroy (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
/* Pop the buffer stack, destroying each element. */
while(YY_CURRENT_BUFFER){
- cmFortran_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
+ yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
YY_CURRENT_BUFFER_LVALUE = NULL;
- cmFortran_yypop_buffer_state(yyscanner);
+ yypop_buffer_state(yyscanner);
}
/* Destroy the stack itself. */
- cmFortran_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyfree(yyg->yy_buffer_stack , yyscanner);
yyg->yy_buffer_stack = NULL;
/* Destroy the start condition stack. */
- cmFortran_yyfree(yyg->yy_start_stack ,yyscanner );
+ 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
- * cmFortran_yylex() is called, initialization will occur. */
+ * yylex() is called, initialization will occur. */
yy_init_globals( yyscanner);
/* Destroy the main struct (reentrant only). */
- cmFortran_yyfree ( yyscanner , yyscanner );
+ yyfree ( yyscanner , yyscanner );
yyscanner = NULL;
return 0;
}
@@ -2445,7 +2552,7 @@ int cmFortran_yylex_destroy (yyscan_t yyscanner)
*/
#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2457,7 +2564,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
{
int n;
for ( n = 0; s[n]; ++n )
@@ -2467,14 +2574,14 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
}
#endif
-void *cmFortran_yyalloc (yy_size_t size , yyscan_t yyscanner)
+void *yyalloc (yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
return malloc(size);
}
-void *cmFortran_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
+void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2489,19 +2596,15 @@ void *cmFortran_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
return realloc(ptr, size);
}
-void cmFortran_yyfree (void * ptr , yyscan_t yyscanner)
+void yyfree (void * ptr , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- free( (char *) ptr ); /* see cmFortran_yyrealloc() for (char *) cast */
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
-#line 178 "cmFortranLexer.in.l"
-
-
-
/*--------------------------------------------------------------------------*/
YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
{
@@ -2509,3 +2612,5 @@ YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return YY_CURRENT_BUFFER;
}
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmFortranLexer.h b/Source/LexerParser/cmFortranLexer.h
index ddda91965..7bb9b4434 100644
--- a/Source/LexerParser/cmFortranLexer.h
+++ b/Source/LexerParser/cmFortranLexer.h
@@ -2,10 +2,6 @@
#define cmFortran_yyHEADER_H 1
#define cmFortran_yyIN_HEADER 1
-#line 6 "cmFortranLexer.h"
-
-#line 8 "cmFortranLexer.h"
-
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -14,11 +10,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmFortran_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmFortran_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmFortran_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmFortran_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmFortran_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmFortran_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmFortran_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmFortran_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmFortran_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmFortran_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmFortran_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmFortran_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmFortran_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmFortran_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmFortran_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmFortran_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmFortran_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmFortran_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmFortran_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmFortran_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmFortran_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmFortran_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmFortran_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmFortran_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmFortran_yylex_ALREADY_DEFINED
+#else
+#define yylex cmFortran_yylex
+#endif
+
+#ifdef yyrestart
+#define cmFortran_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmFortran_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmFortran_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmFortran_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmFortran_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmFortran_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmFortran_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmFortran_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmFortran_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmFortran_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmFortran_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmFortran_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmFortran_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmFortran_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmFortran_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmFortran_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmFortran_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmFortran_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmFortran_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmFortran_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmFortran_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmFortran_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmFortran_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmFortran_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmFortran_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmFortran_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmFortran_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmFortran_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmFortran_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmFortran_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmFortran_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmFortran_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmFortran_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmFortran_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmFortran_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmFortran_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmFortran_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmFortran_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmFortran_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmFortran_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmFortran_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmFortran_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmFortran_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmFortran_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -89,10 +295,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -193,21 +405,21 @@ struct yy_buffer_state
};
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
-void cmFortran_yyrestart (FILE *input_file ,yyscan_t yyscanner );
-void cmFortran_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
-void cmFortran_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void cmFortran_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
-void cmFortran_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
-void cmFortran_yypop_buffer_state (yyscan_t yyscanner );
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void yypop_buffer_state ( yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
-YY_BUFFER_STATE cmFortran_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
-void *cmFortran_yyalloc (yy_size_t ,yyscan_t yyscanner );
-void *cmFortran_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
-void cmFortran_yyfree (void * ,yyscan_t yyscanner );
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
/* Begin user sect3 */
@@ -229,42 +441,42 @@ void cmFortran_yyfree (void * ,yyscan_t yyscanner );
#define YY_EXTRA_TYPE void *
#endif
-int cmFortran_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmFortran_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 cmFortran_yylex_destroy (yyscan_t yyscanner );
+int yylex_destroy ( yyscan_t yyscanner );
-int cmFortran_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmFortran_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmFortran_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmFortran_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmFortran_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmFortran_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmFortran_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmFortran_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmFortran_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmFortran_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmFortran_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmFortran_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmFortran_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmFortran_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -272,18 +484,18 @@ void cmFortran_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmFortran_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmFortran_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
@@ -311,9 +523,9 @@ static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmFortran_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmFortran_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* yy_get_previous_state - get the state just before the EOB char was reached */
@@ -330,9 +542,150 @@ extern int cmFortran_yylex (yyscan_t yyscanner);
#undef YY_DECL
#endif
-#line 178 "cmFortranLexer.in.l"
-
+#ifndef cmFortran_yy_create_buffer_ALREADY_DEFINED
+#undef yy_create_buffer
+#endif
+#ifndef cmFortran_yy_delete_buffer_ALREADY_DEFINED
+#undef yy_delete_buffer
+#endif
+#ifndef cmFortran_yy_scan_buffer_ALREADY_DEFINED
+#undef yy_scan_buffer
+#endif
+#ifndef cmFortran_yy_scan_string_ALREADY_DEFINED
+#undef yy_scan_string
+#endif
+#ifndef cmFortran_yy_scan_bytes_ALREADY_DEFINED
+#undef yy_scan_bytes
+#endif
+#ifndef cmFortran_yy_init_buffer_ALREADY_DEFINED
+#undef yy_init_buffer
+#endif
+#ifndef cmFortran_yy_flush_buffer_ALREADY_DEFINED
+#undef yy_flush_buffer
+#endif
+#ifndef cmFortran_yy_load_buffer_state_ALREADY_DEFINED
+#undef yy_load_buffer_state
+#endif
+#ifndef cmFortran_yy_switch_to_buffer_ALREADY_DEFINED
+#undef yy_switch_to_buffer
+#endif
+#ifndef cmFortran_yypush_buffer_state_ALREADY_DEFINED
+#undef yypush_buffer_state
+#endif
+#ifndef cmFortran_yypop_buffer_state_ALREADY_DEFINED
+#undef yypop_buffer_state
+#endif
+#ifndef cmFortran_yyensure_buffer_stack_ALREADY_DEFINED
+#undef yyensure_buffer_stack
+#endif
+#ifndef cmFortran_yylex_ALREADY_DEFINED
+#undef yylex
+#endif
+#ifndef cmFortran_yyrestart_ALREADY_DEFINED
+#undef yyrestart
+#endif
+#ifndef cmFortran_yylex_init_ALREADY_DEFINED
+#undef yylex_init
+#endif
+#ifndef cmFortran_yylex_init_extra_ALREADY_DEFINED
+#undef yylex_init_extra
+#endif
+#ifndef cmFortran_yylex_destroy_ALREADY_DEFINED
+#undef yylex_destroy
+#endif
+#ifndef cmFortran_yyget_debug_ALREADY_DEFINED
+#undef yyget_debug
+#endif
+#ifndef cmFortran_yyset_debug_ALREADY_DEFINED
+#undef yyset_debug
+#endif
+#ifndef cmFortran_yyget_extra_ALREADY_DEFINED
+#undef yyget_extra
+#endif
+#ifndef cmFortran_yyset_extra_ALREADY_DEFINED
+#undef yyset_extra
+#endif
+#ifndef cmFortran_yyget_in_ALREADY_DEFINED
+#undef yyget_in
+#endif
+#ifndef cmFortran_yyset_in_ALREADY_DEFINED
+#undef yyset_in
+#endif
+#ifndef cmFortran_yyget_out_ALREADY_DEFINED
+#undef yyget_out
+#endif
+#ifndef cmFortran_yyset_out_ALREADY_DEFINED
+#undef yyset_out
+#endif
+#ifndef cmFortran_yyget_leng_ALREADY_DEFINED
+#undef yyget_leng
+#endif
+#ifndef cmFortran_yyget_text_ALREADY_DEFINED
+#undef yyget_text
+#endif
+#ifndef cmFortran_yyget_lineno_ALREADY_DEFINED
+#undef yyget_lineno
+#endif
+#ifndef cmFortran_yyset_lineno_ALREADY_DEFINED
+#undef yyset_lineno
+#endif
+#ifndef cmFortran_yyget_column_ALREADY_DEFINED
+#undef yyget_column
+#endif
+#ifndef cmFortran_yyset_column_ALREADY_DEFINED
+#undef yyset_column
+#endif
+#ifndef cmFortran_yywrap_ALREADY_DEFINED
+#undef yywrap
+#endif
+#ifndef cmFortran_yyget_lval_ALREADY_DEFINED
+#undef yyget_lval
+#endif
+#ifndef cmFortran_yyset_lval_ALREADY_DEFINED
+#undef yyset_lval
+#endif
+#ifndef cmFortran_yyget_lloc_ALREADY_DEFINED
+#undef yyget_lloc
+#endif
+#ifndef cmFortran_yyset_lloc_ALREADY_DEFINED
+#undef yyset_lloc
+#endif
+#ifndef cmFortran_yyalloc_ALREADY_DEFINED
+#undef yyalloc
+#endif
+#ifndef cmFortran_yyrealloc_ALREADY_DEFINED
+#undef yyrealloc
+#endif
+#ifndef cmFortran_yyfree_ALREADY_DEFINED
+#undef yyfree
+#endif
+#ifndef cmFortran_yytext_ALREADY_DEFINED
+#undef yytext
+#endif
+#ifndef cmFortran_yyleng_ALREADY_DEFINED
+#undef yyleng
+#endif
+#ifndef cmFortran_yyin_ALREADY_DEFINED
+#undef yyin
+#endif
+#ifndef cmFortran_yyout_ALREADY_DEFINED
+#undef yyout
+#endif
+#ifndef cmFortran_yy_flex_debug_ALREADY_DEFINED
+#undef yy_flex_debug
+#endif
+#ifndef cmFortran_yylineno_ALREADY_DEFINED
+#undef yylineno
+#endif
+#ifndef cmFortran_yytables_fload_ALREADY_DEFINED
+#undef yytables_fload
+#endif
+#ifndef cmFortran_yytables_destroy_ALREADY_DEFINED
+#undef yytables_destroy
+#endif
+#ifndef cmFortran_yyTABLES_NAME_ALREADY_DEFINED
+#undef yyTABLES_NAME
+#endif
-#line 337 "cmFortranLexer.h"
#undef cmFortran_yyIN_HEADER
#endif /* cmFortran_yyHEADER_H */
diff --git a/Source/LexerParser/cmFortranLexer.in.l b/Source/LexerParser/cmFortranLexer.in.l
index 112121037..3d38a7dad 100644
--- a/Source/LexerParser/cmFortranLexer.in.l
+++ b/Source/LexerParser/cmFortranLexer.in.l
@@ -17,18 +17,18 @@ This file must be translated to C++ and modified to build everywhere.
Run flex >= 2.6 like this:
- flex -i --nounistd -DFLEXINT_H --prefix=cmFortran_yy --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
+ flex -i --nounistd -DFLEXINT_H --noline --header-file=cmFortranLexer.h -ocmFortranLexer.cxx cmFortranLexer.in.l
Modify cmFortranLexer.cxx:
- - remove trailing whitespace: sed -i 's/\s*$//' cmFortranLexer.h cmFortranLexer.cxx
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in yy_scan_bytes for loop condition of _yybytes_len to size_t
-
+ - remove trailing whitespace: sed -i 's/\s*$//' cmFortranLexer.h cmFortranLexer.cxx
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmFortranLexer.h cmFortranLexer.cxx
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmFortranLexer.cxx
*/
/* IWYU pragma: no_forward_declare yyguts_t */
+#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */
+
#undef YY_NO_UNPUT
#define cmFortranLexer_cxx
@@ -37,7 +37,7 @@ Modify cmFortranLexer.cxx:
/* Replace the lexer input function. */
#undef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
- { result = cmFortranParser_Input(yyextra, buf, max_size); }
+ do { result = cmFortranParser_Input(yyextra, buf, max_size); } while (0)
/* Include the set of tokens from the parser. */
#include "cmFortranParserTokens.h"
@@ -45,6 +45,7 @@ Modify cmFortranLexer.cxx:
/*--------------------------------------------------------------------------*/
%}
+%option prefix="cmFortran_yy"
%option reentrant
%option noyywrap
@@ -147,7 +148,7 @@ $[ \t]*endif { return F90PPR_ENDIF; }
[Ii][Nn][Cc][Ll][Uu][Dd][Ee] { return INCLUDE; }
[Ii][Nn][Tt][Ee][Rr][Ff][Aa][Cc][Ee] { return INTERFACE; }
[Mm][Oo][Dd][Uu][Ll][Ee] { return MODULE; }
-[Ss][Uu][bb][Mm][Oo][Dd][Uu][Ll][Ee] { return SUBMODULE; }
+[Ss][Uu][Bb][Mm][Oo][Dd][Uu][Ll][Ee] { return SUBMODULE; }
[Uu][Ss][Ee] { return USE; }
[a-zA-Z_][a-zA-Z_0-9]* {
@@ -184,3 +185,5 @@ YY_BUFFER_STATE cmFortranLexer_GetCurrentBuffer(yyscan_t yyscanner)
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return YY_CURRENT_BUFFER;
}
+
+#endif /* __clang_analyzer__ */
diff --git a/Source/LexerParser/cmFortranParser.cxx b/Source/LexerParser/cmFortranParser.cxx
index 2b3452f2e..015cab9f9 100644
--- a/Source/LexerParser/cmFortranParser.cxx
+++ b/Source/LexerParser/cmFortranParser.cxx
@@ -127,8 +127,11 @@ static void cmFortran_yyerror(yyscan_t yyscanner, const char* message)
# pragma warning (disable: 4127) /* Conditional expression is constant. */
# pragma warning (disable: 4244) /* Conversion to smaller type, data loss. */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
-#line 132 "cmFortranParser.cxx" /* yacc.c:339 */
+#line 135 "cmFortranParser.cxx" /* yacc.c:339 */
# ifndef YY_NULLPTR
# if defined __cplusplus && 201103L <= __cplusplus
@@ -248,11 +251,11 @@ extern int cmFortran_yydebug;
union YYSTYPE
{
-#line 70 "cmFortranParser.y" /* yacc.c:355 */
+#line 73 "cmFortranParser.y" /* yacc.c:355 */
char* string;
-#line 256 "cmFortranParser.cxx" /* yacc.c:355 */
+#line 259 "cmFortranParser.cxx" /* yacc.c:355 */
};
typedef union YYSTYPE YYSTYPE;
@@ -268,7 +271,7 @@ int cmFortran_yyparse (yyscan_t yyscanner);
/* Copy the second part of user declarations. */
-#line 272 "cmFortranParser.cxx" /* yacc.c:358 */
+#line 275 "cmFortranParser.cxx" /* yacc.c:358 */
#ifdef short
# undef short
@@ -569,13 +572,13 @@ static const yytype_uint8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 98, 98, 98, 101, 105, 110, 119, 125, 132,
- 137, 141, 146, 154, 159, 164, 169, 174, 179, 184,
- 189, 194, 198, 202, 206, 210, 211, 216, 216, 216,
- 217, 217, 218, 218, 219, 219, 220, 220, 221, 221,
- 222, 222, 223, 223, 224, 224, 225, 225, 228, 229,
- 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243
+ 0, 101, 101, 101, 104, 108, 113, 122, 128, 135,
+ 140, 144, 149, 157, 162, 167, 172, 177, 182, 187,
+ 192, 197, 201, 205, 209, 213, 214, 219, 219, 219,
+ 220, 220, 221, 221, 222, 222, 223, 223, 224, 224,
+ 225, 225, 226, 226, 227, 227, 228, 228, 231, 232,
+ 233, 234, 235, 236, 237, 238, 239, 240, 241, 242,
+ 243, 244, 245, 246
};
#endif
@@ -1527,26 +1530,26 @@ yyreduce:
switch (yyn)
{
case 4:
-#line 101 "cmFortranParser.y" /* yacc.c:1646 */
+#line 104 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, true);
}
-#line 1536 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1539 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 5:
-#line 105 "cmFortranParser.y" /* yacc.c:1646 */
+#line 108 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUse(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1546 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1549 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 6:
-#line 110 "cmFortranParser.y" /* yacc.c:1646 */
+#line 113 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
if (cmsysString_strcasecmp((yyvsp[-2].string), "function") != 0 &&
@@ -1556,63 +1559,63 @@ yyreduce:
}
free((yyvsp[-2].string));
}
-#line 1560 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1563 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 7:
-#line 119 "cmFortranParser.y" /* yacc.c:1646 */
+#line 122 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
- cmFortranParser_RuleUse(parser, (yyvsp[-4].string));
+ cmFortranParser_RuleSubmodule(parser, (yyvsp[-4].string), (yyvsp[-2].string));
free((yyvsp[-4].string));
free((yyvsp[-2].string));
}
-#line 1571 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1574 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 8:
-#line 125 "cmFortranParser.y" /* yacc.c:1646 */
+#line 128 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
- cmFortranParser_RuleUse(parser, (yyvsp[-6].string));
+ cmFortranParser_RuleSubmoduleNested(parser, (yyvsp[-6].string), (yyvsp[-4].string), (yyvsp[-2].string));
free((yyvsp[-6].string));
free((yyvsp[-4].string));
free((yyvsp[-2].string));
}
-#line 1583 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1586 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 9:
-#line 132 "cmFortranParser.y" /* yacc.c:1646 */
+#line 135 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, true);
free((yyvsp[-2].string));
}
-#line 1593 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1596 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 10:
-#line 137 "cmFortranParser.y" /* yacc.c:1646 */
+#line 140 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_SetInInterface(parser, false);
}
-#line 1602 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1605 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 11:
-#line 141 "cmFortranParser.y" /* yacc.c:1646 */
+#line 144 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUse(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1612 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1615 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 12:
-#line 146 "cmFortranParser.y" /* yacc.c:1646 */
+#line 149 "cmFortranParser.y" /* yacc.c:1646 */
{
if (cmsysString_strcasecmp((yyvsp[-4].string), "non_intrinsic") == 0) {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
@@ -1621,139 +1624,139 @@ yyreduce:
free((yyvsp[-4].string));
free((yyvsp[-2].string));
}
-#line 1625 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1628 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 13:
-#line 154 "cmFortranParser.y" /* yacc.c:1646 */
+#line 157 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleInclude(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1635 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1638 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 14:
-#line 159 "cmFortranParser.y" /* yacc.c:1646 */
+#line 162 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleLineDirective(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1645 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1648 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 15:
-#line 164 "cmFortranParser.y" /* yacc.c:1646 */
+#line 167 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleInclude(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1655 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1658 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 16:
-#line 169 "cmFortranParser.y" /* yacc.c:1646 */
+#line 172 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleInclude(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1665 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1668 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 17:
-#line 174 "cmFortranParser.y" /* yacc.c:1646 */
+#line 177 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleDefine(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1675 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1678 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 18:
-#line 179 "cmFortranParser.y" /* yacc.c:1646 */
+#line 182 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleUndef(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1685 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1688 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 19:
-#line 184 "cmFortranParser.y" /* yacc.c:1646 */
+#line 187 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleIfdef(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1695 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1698 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 20:
-#line 189 "cmFortranParser.y" /* yacc.c:1646 */
+#line 192 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleIfndef(parser, (yyvsp[-2].string));
free((yyvsp[-2].string));
}
-#line 1705 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1708 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 21:
-#line 194 "cmFortranParser.y" /* yacc.c:1646 */
+#line 197 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleIf(parser);
}
-#line 1714 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1717 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 22:
-#line 198 "cmFortranParser.y" /* yacc.c:1646 */
+#line 201 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleElif(parser);
}
-#line 1723 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1726 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 23:
-#line 202 "cmFortranParser.y" /* yacc.c:1646 */
+#line 205 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleElse(parser);
}
-#line 1732 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1735 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 24:
-#line 206 "cmFortranParser.y" /* yacc.c:1646 */
+#line 209 "cmFortranParser.y" /* yacc.c:1646 */
{
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
cmFortranParser_RuleEndif(parser);
}
-#line 1741 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1744 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 48:
-#line 228 "cmFortranParser.y" /* yacc.c:1646 */
+#line 231 "cmFortranParser.y" /* yacc.c:1646 */
{ free ((yyvsp[0].string)); }
-#line 1747 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1750 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
case 55:
-#line 235 "cmFortranParser.y" /* yacc.c:1646 */
+#line 238 "cmFortranParser.y" /* yacc.c:1646 */
{ free ((yyvsp[0].string)); }
-#line 1753 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1756 "cmFortranParser.cxx" /* yacc.c:1646 */
break;
-#line 1757 "cmFortranParser.cxx" /* yacc.c:1646 */
+#line 1760 "cmFortranParser.cxx" /* yacc.c:1646 */
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@@ -1983,6 +1986,6 @@ yyreturn:
#endif
return yyresult;
}
-#line 246 "cmFortranParser.y" /* yacc.c:1906 */
+#line 249 "cmFortranParser.y" /* yacc.c:1906 */
/* End of grammar */
diff --git a/Source/LexerParser/cmFortranParser.y b/Source/LexerParser/cmFortranParser.y
index acfb40ad8..87f3e0a16 100644
--- a/Source/LexerParser/cmFortranParser.y
+++ b/Source/LexerParser/cmFortranParser.y
@@ -56,6 +56,9 @@ static void cmFortran_yyerror(yyscan_t yyscanner, const char* message)
# pragma warning (disable: 4127) /* Conditional expression is constant. */
# pragma warning (disable: 4244) /* Conversion to smaller type, data loss. */
#endif
+#if defined(__GNUC__) && __GNUC__ >= 8
+# pragma GCC diagnostic ignored "-Wconversion"
+#endif
%}
/* Generate a reentrant parser object. */
@@ -118,13 +121,13 @@ stmt:
}
| SUBMODULE LPAREN WORD RPAREN WORD other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
- cmFortranParser_RuleUse(parser, $3);
+ cmFortranParser_RuleSubmodule(parser, $3, $5);
free($3);
free($5);
}
| SUBMODULE LPAREN WORD COLON WORD RPAREN WORD other EOSTMT {
cmFortranParser* parser = cmFortran_yyget_extra(yyscanner);
- cmFortranParser_RuleUse(parser, $3);
+ cmFortranParser_RuleSubmoduleNested(parser, $3, $5, $7);
free($3);
free($5);
free($7);
diff --git a/Source/LexerParser/cmFortranParserTokens.h b/Source/LexerParser/cmFortranParserTokens.h
index 8d6a5fe5a..29c6d60a9 100644
--- a/Source/LexerParser/cmFortranParserTokens.h
+++ b/Source/LexerParser/cmFortranParserTokens.h
@@ -130,7 +130,7 @@ extern int cmFortran_yydebug;
union YYSTYPE
{
-#line 70 "cmFortranParser.y" /* yacc.c:1909 */
+#line 73 "cmFortranParser.y" /* yacc.c:1909 */
char* string;
diff --git a/Source/LexerParser/cmListFileLexer.c b/Source/LexerParser/cmListFileLexer.c
index 3dd3b85b9..15dcda04a 100644
--- a/Source/LexerParser/cmListFileLexer.c
+++ b/Source/LexerParser/cmListFileLexer.c
@@ -1,7 +1,4 @@
#include "cmStandardLexer.h"
-#line 2 "cmListFileLexer.c"
-
-#line 4 "cmListFileLexer.c"
#define FLEXINT_H 1
#define YY_INT_ALIGNED short int
@@ -11,11 +8,221 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 1
+#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
+#ifdef yy_create_buffer
+#define cmListFileLexer_yy_create_buffer_ALREADY_DEFINED
+#else
+#define yy_create_buffer cmListFileLexer_yy_create_buffer
+#endif
+
+#ifdef yy_delete_buffer
+#define cmListFileLexer_yy_delete_buffer_ALREADY_DEFINED
+#else
+#define yy_delete_buffer cmListFileLexer_yy_delete_buffer
+#endif
+
+#ifdef yy_scan_buffer
+#define cmListFileLexer_yy_scan_buffer_ALREADY_DEFINED
+#else
+#define yy_scan_buffer cmListFileLexer_yy_scan_buffer
+#endif
+
+#ifdef yy_scan_string
+#define cmListFileLexer_yy_scan_string_ALREADY_DEFINED
+#else
+#define yy_scan_string cmListFileLexer_yy_scan_string
+#endif
+
+#ifdef yy_scan_bytes
+#define cmListFileLexer_yy_scan_bytes_ALREADY_DEFINED
+#else
+#define yy_scan_bytes cmListFileLexer_yy_scan_bytes
+#endif
+
+#ifdef yy_init_buffer
+#define cmListFileLexer_yy_init_buffer_ALREADY_DEFINED
+#else
+#define yy_init_buffer cmListFileLexer_yy_init_buffer
+#endif
+
+#ifdef yy_flush_buffer
+#define cmListFileLexer_yy_flush_buffer_ALREADY_DEFINED
+#else
+#define yy_flush_buffer cmListFileLexer_yy_flush_buffer
+#endif
+
+#ifdef yy_load_buffer_state
+#define cmListFileLexer_yy_load_buffer_state_ALREADY_DEFINED
+#else
+#define yy_load_buffer_state cmListFileLexer_yy_load_buffer_state
+#endif
+
+#ifdef yy_switch_to_buffer
+#define cmListFileLexer_yy_switch_to_buffer_ALREADY_DEFINED
+#else
+#define yy_switch_to_buffer cmListFileLexer_yy_switch_to_buffer
+#endif
+
+#ifdef yypush_buffer_state
+#define cmListFileLexer_yypush_buffer_state_ALREADY_DEFINED
+#else
+#define yypush_buffer_state cmListFileLexer_yypush_buffer_state
+#endif
+
+#ifdef yypop_buffer_state
+#define cmListFileLexer_yypop_buffer_state_ALREADY_DEFINED
+#else
+#define yypop_buffer_state cmListFileLexer_yypop_buffer_state
+#endif
+
+#ifdef yyensure_buffer_stack
+#define cmListFileLexer_yyensure_buffer_stack_ALREADY_DEFINED
+#else
+#define yyensure_buffer_stack cmListFileLexer_yyensure_buffer_stack
+#endif
+
+#ifdef yylex
+#define cmListFileLexer_yylex_ALREADY_DEFINED
+#else
+#define yylex cmListFileLexer_yylex
+#endif
+
+#ifdef yyrestart
+#define cmListFileLexer_yyrestart_ALREADY_DEFINED
+#else
+#define yyrestart cmListFileLexer_yyrestart
+#endif
+
+#ifdef yylex_init
+#define cmListFileLexer_yylex_init_ALREADY_DEFINED
+#else
+#define yylex_init cmListFileLexer_yylex_init
+#endif
+
+#ifdef yylex_init_extra
+#define cmListFileLexer_yylex_init_extra_ALREADY_DEFINED
+#else
+#define yylex_init_extra cmListFileLexer_yylex_init_extra
+#endif
+
+#ifdef yylex_destroy
+#define cmListFileLexer_yylex_destroy_ALREADY_DEFINED
+#else
+#define yylex_destroy cmListFileLexer_yylex_destroy
+#endif
+
+#ifdef yyget_debug
+#define cmListFileLexer_yyget_debug_ALREADY_DEFINED
+#else
+#define yyget_debug cmListFileLexer_yyget_debug
+#endif
+
+#ifdef yyset_debug
+#define cmListFileLexer_yyset_debug_ALREADY_DEFINED
+#else
+#define yyset_debug cmListFileLexer_yyset_debug
+#endif
+
+#ifdef yyget_extra
+#define cmListFileLexer_yyget_extra_ALREADY_DEFINED
+#else
+#define yyget_extra cmListFileLexer_yyget_extra
+#endif
+
+#ifdef yyset_extra
+#define cmListFileLexer_yyset_extra_ALREADY_DEFINED
+#else
+#define yyset_extra cmListFileLexer_yyset_extra
+#endif
+
+#ifdef yyget_in
+#define cmListFileLexer_yyget_in_ALREADY_DEFINED
+#else
+#define yyget_in cmListFileLexer_yyget_in
+#endif
+
+#ifdef yyset_in
+#define cmListFileLexer_yyset_in_ALREADY_DEFINED
+#else
+#define yyset_in cmListFileLexer_yyset_in
+#endif
+
+#ifdef yyget_out
+#define cmListFileLexer_yyget_out_ALREADY_DEFINED
+#else
+#define yyget_out cmListFileLexer_yyget_out
+#endif
+
+#ifdef yyset_out
+#define cmListFileLexer_yyset_out_ALREADY_DEFINED
+#else
+#define yyset_out cmListFileLexer_yyset_out
+#endif
+
+#ifdef yyget_leng
+#define cmListFileLexer_yyget_leng_ALREADY_DEFINED
+#else
+#define yyget_leng cmListFileLexer_yyget_leng
+#endif
+
+#ifdef yyget_text
+#define cmListFileLexer_yyget_text_ALREADY_DEFINED
+#else
+#define yyget_text cmListFileLexer_yyget_text
+#endif
+
+#ifdef yyget_lineno
+#define cmListFileLexer_yyget_lineno_ALREADY_DEFINED
+#else
+#define yyget_lineno cmListFileLexer_yyget_lineno
+#endif
+
+#ifdef yyset_lineno
+#define cmListFileLexer_yyset_lineno_ALREADY_DEFINED
+#else
+#define yyset_lineno cmListFileLexer_yyset_lineno
+#endif
+
+#ifdef yyget_column
+#define cmListFileLexer_yyget_column_ALREADY_DEFINED
+#else
+#define yyget_column cmListFileLexer_yyget_column
+#endif
+
+#ifdef yyset_column
+#define cmListFileLexer_yyset_column_ALREADY_DEFINED
+#else
+#define yyset_column cmListFileLexer_yyset_column
+#endif
+
+#ifdef yywrap
+#define cmListFileLexer_yywrap_ALREADY_DEFINED
+#else
+#define yywrap cmListFileLexer_yywrap
+#endif
+
+#ifdef yyalloc
+#define cmListFileLexer_yyalloc_ALREADY_DEFINED
+#else
+#define yyalloc cmListFileLexer_yyalloc
+#endif
+
+#ifdef yyrealloc
+#define cmListFileLexer_yyrealloc_ALREADY_DEFINED
+#else
+#define yyrealloc cmListFileLexer_yyrealloc
+#endif
+
+#ifdef yyfree
+#define cmListFileLexer_yyfree_ALREADY_DEFINED
+#else
+#define yyfree cmListFileLexer_yyfree
+#endif
+
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
@@ -86,10 +293,16 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
+#ifndef SIZE_MAX
+#define SIZE_MAX (~(size_t)0)
+#endif
+
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
+/* begin standard C++ headers. */
+
/* TODO: this is always defined, so inline it */
#define yyconst const
@@ -102,12 +315,10 @@ typedef unsigned int flex_uint32_t;
/* 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.
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
*/
-#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
/* An opaque pointer. */
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -131,20 +342,16 @@ typedef void* yyscan_t;
* 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_NEW_FILE yyrestart( yyin , yyscanner )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
@@ -180,7 +387,7 @@ typedef size_t yy_size_t;
/* 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.
+ * existing scanners that call yyless() from OUTSIDE 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.
@@ -213,7 +420,6 @@ typedef size_t yy_size_t;
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
-
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
#ifndef YY_STRUCT_YY_BUFFER_STATE
@@ -273,7 +479,7 @@ struct yy_buffer_state
* 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
+ * (via yyrestart()), so that the user can continue scanning by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
@@ -290,73 +496,67 @@ struct yy_buffer_state
#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 );
+void yyrestart ( FILE *input_file , yyscan_t yyscanner );
+void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
+void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
+void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
+void yypop_buffer_state ( yyscan_t yyscanner );
-#define YY_FLUSH_BUFFER cmListFileLexer_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
+static void yyensure_buffer_stack ( yyscan_t yyscanner );
+static void yy_load_buffer_state ( yyscan_t yyscanner );
+static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
+#define YY_FLUSH_BUFFER 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 );
+YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
+YY_BUFFER_STATE yy_scan_bytes ( const 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
+void *yyalloc ( yy_size_t , yyscan_t yyscanner );
+void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
+void yyfree ( void * , yyscan_t yyscanner );
+#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
- cmListFileLexer_yyensure_buffer_stack (yyscanner); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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); \
+ yyensure_buffer_stack (yyscanner); \
YY_CURRENT_BUFFER_LVALUE = \
- cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
+ 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(yyscanner) (/*CONSTCOND*/1)
#define YY_SKIP_YYWRAP
-
-typedef unsigned char YY_CHAR;
+typedef flex_uint8_t 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 yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
+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 yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
@@ -367,7 +567,6 @@ static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
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,
@@ -377,19 +576,19 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
-static yyconst flex_int16_t yy_accept[77] =
+static const flex_int16_t yy_accept[79] =
{ 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
+ 15, 23, 23, 17, 19, 20, 21, 24, 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 YY_CHAR yy_ec[256] =
+static const YY_CHAR yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
@@ -421,108 +620,122 @@ static yyconst YY_CHAR yy_ec[256] =
1, 1, 1, 1, 1
} ;
-static yyconst YY_CHAR yy_meta[16] =
+static const YY_CHAR yy_meta[17] =
{ 0,
1, 1, 2, 3, 4, 3, 1, 3, 5, 6,
- 1, 6, 1, 1, 7
+ 1, 6, 1, 1, 7, 2
} ;
-static yyconst flex_uint16_t yy_base[95] =
+static const flex_int16_t yy_base[97] =
{ 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
+ 0, 0, 14, 28, 42, 56, 70, 84, 18, 19,
+ 68, 100, 16, 298, 298, 54, 58, 298, 298, 13,
+ 115, 0, 298, 51, 298, 298, 21, 298, 0, 298,
+ 53, 298, 298, 0, 0, 126, 55, 0, 25, 25,
+ 53, 0, 0, 136, 53, 0, 57, 0, 0, 42,
+ 50, 298, 0, 43, 0, 146, 160, 45, 172, 43,
+ 26, 0, 42, 177, 0, 42, 188, 40, 298, 40,
+ 0, 38, 37, 34, 32, 31, 23, 298, 197, 204,
+ 211, 218, 225, 232, 239, 245, 252, 259, 262, 268,
+ 275, 278, 280, 286, 289, 291
} ;
-static yyconst flex_int16_t yy_def[95] =
+static const flex_int16_t yy_def[97] =
{ 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
+ 78, 1, 79, 79, 80, 80, 81, 81, 82, 82,
+ 78, 78, 78, 78, 78, 78, 12, 78, 78, 12,
+ 78, 83, 78, 84, 78, 78, 84, 78, 85, 78,
+ 78, 78, 78, 86, 12, 87, 12, 88, 78, 78,
+ 89, 20, 12, 90, 12, 21, 78, 91, 12, 84,
+ 84, 78, 85, 78, 86, 87, 78, 56, 87, 92,
+ 78, 57, 89, 90, 57, 64, 90, 93, 78, 57,
+ 94, 95, 92, 96, 93, 95, 96, 0, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78
} ;
-static yyconst flex_uint16_t yy_nxt[253] =
+static const flex_int16_t yy_nxt[315] =
{ 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
+ 12, 20, 21, 22, 12, 23, 25, 39, 26, 39,
+ 14, 14, 42, 52, 42, 50, 39, 27, 39, 28,
+ 25, 64, 26, 28, 28, 61, 61, 47, 47, 56,
+ 65, 27, 64, 28, 30, 57, 56, 60, 65, 74,
+ 62, 57, 72, 54, 50, 51, 31, 28, 30, 69,
+ 68, 62, 60, 54, 51, 41, 40, 78, 78, 78,
+ 31, 28, 30, 78, 78, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78, 33, 28, 30, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 33, 28,
+
+ 35, 78, 78, 78, 36, 78, 37, 78, 78, 35,
+ 35, 35, 35, 38, 35, 43, 78, 78, 78, 44,
+ 78, 45, 78, 78, 43, 46, 43, 47, 48, 43,
+ 57, 78, 58, 78, 78, 78, 78, 78, 78, 59,
+ 65, 78, 66, 78, 78, 78, 78, 78, 78, 67,
+ 57, 78, 58, 78, 78, 78, 78, 78, 78, 59,
+ 57, 78, 78, 78, 36, 78, 70, 78, 78, 57,
+ 57, 57, 57, 71, 57, 56, 78, 56, 78, 56,
+ 56, 65, 78, 66, 78, 78, 78, 78, 78, 78,
+ 67, 64, 78, 64, 78, 64, 64, 24, 24, 24,
+
+ 24, 24, 24, 24, 29, 29, 29, 29, 29, 29,
+ 29, 32, 32, 32, 32, 32, 32, 32, 34, 34,
+ 34, 34, 34, 34, 34, 49, 78, 49, 49, 49,
+ 49, 49, 50, 78, 50, 78, 50, 50, 50, 53,
+ 78, 53, 53, 53, 53, 55, 78, 55, 55, 55,
+ 55, 55, 56, 78, 78, 56, 78, 56, 56, 35,
+ 78, 35, 35, 35, 35, 35, 63, 63, 64, 78,
+ 78, 64, 78, 64, 64, 43, 78, 43, 43, 43,
+ 43, 43, 73, 73, 75, 75, 57, 78, 57, 57,
+ 57, 57, 57, 76, 76, 77, 77, 11, 78, 78,
+
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78
} ;
-static yyconst flex_int16_t yy_chk[253] =
+static const flex_int16_t yy_chk[315] =
{ 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
+ 1, 1, 1, 1, 1, 1, 3, 13, 3, 13,
+ 9, 10, 20, 27, 20, 27, 39, 3, 39, 3,
+ 4, 77, 4, 9, 10, 40, 61, 40, 61, 76,
+ 75, 4, 74, 4, 5, 73, 72, 70, 68, 66,
+ 63, 60, 58, 54, 51, 50, 5, 5, 6, 47,
+ 45, 41, 37, 31, 24, 17, 16, 11, 0, 0,
+ 6, 6, 7, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 7, 7, 8, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 8, 8,
+
+ 12, 0, 0, 0, 12, 0, 12, 0, 0, 12,
+ 12, 12, 12, 12, 12, 21, 0, 0, 0, 21,
+ 0, 21, 0, 0, 21, 21, 21, 21, 21, 21,
+ 36, 0, 36, 0, 0, 0, 0, 0, 0, 36,
+ 44, 0, 44, 0, 0, 0, 0, 0, 0, 44,
+ 56, 0, 56, 0, 0, 0, 0, 0, 0, 56,
+ 57, 0, 0, 0, 57, 0, 57, 0, 0, 57,
+ 57, 57, 57, 57, 57, 59, 0, 59, 0, 59,
+ 59, 64, 0, 64, 0, 0, 0, 0, 0, 0,
+ 64, 67, 0, 67, 0, 67, 67, 79, 79, 79,
+
+ 79, 79, 79, 79, 80, 80, 80, 80, 80, 80,
+ 80, 81, 81, 81, 81, 81, 81, 81, 82, 82,
+ 82, 82, 82, 82, 82, 83, 0, 83, 83, 83,
+ 83, 83, 84, 0, 84, 0, 84, 84, 84, 85,
+ 0, 85, 85, 85, 85, 86, 0, 86, 86, 86,
+ 86, 86, 87, 0, 0, 87, 0, 87, 87, 88,
+ 0, 88, 88, 88, 88, 88, 89, 89, 90, 0,
+ 0, 90, 0, 90, 90, 91, 0, 91, 91, 91,
+ 91, 91, 92, 92, 93, 93, 94, 0, 94, 94,
+ 94, 94, 94, 95, 95, 96, 96, 78, 78, 78,
+
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78
} ;
/* Table of booleans, true if rule could match eol. */
-static yyconst flex_int32_t yy_rule_can_match_eol[25] =
+static const 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, };
@@ -534,8 +747,6 @@ static yyconst flex_int32_t yy_rule_can_match_eol[25] =
#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"
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
/*
@@ -544,20 +755,18 @@ This file must be translated to C and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmListFileLexer_yy -ocmListFileLexer.c cmListFileLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline -ocmListFileLexer.c cmListFileLexer.in.l
Modify cmListFileLexer.c:
- - remove trailing whitespace: sed -i 's/\s*$//' cmListFileLexer.c
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in cmListFileLexer_yy_scan_bytes for loop condition of _yybytes_len to size_t
- - change type of variable yyl under yy_find_action from yy_size_t to int
+ - remove trailing whitespace: sed -i 's/\s*$//' cmListFileLexer.c
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmListFileLexer.c
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmListFileLexer.c
*/
/* IWYU pragma: no_forward_declare yyguts_t */
-#ifdef WIN32
+#ifdef _WIN32
#include "cmsys/Encoding.h"
#endif
@@ -596,15 +805,10 @@ 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); }
+ do { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); } while (0)
/*--------------------------------------------------------------------------*/
-
-
-
-#line 606 "cmListFileLexer.c"
-
#define INITIAL 0
#define STRING 1
#define BRACKET 2
@@ -649,44 +853,44 @@ struct yyguts_t
}; /* end struct yyguts_t */
-static int yy_init_globals (yyscan_t yyscanner );
+static int yy_init_globals ( yyscan_t yyscanner );
-int cmListFileLexer_yylex_init (yyscan_t* scanner);
+int yylex_init (yyscan_t* scanner);
-int cmListFileLexer_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
+int 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 yylex_destroy ( yyscan_t yyscanner );
-int cmListFileLexer_yyget_debug (yyscan_t yyscanner );
+int yyget_debug ( yyscan_t yyscanner );
-void cmListFileLexer_yyset_debug (int debug_flag ,yyscan_t yyscanner );
+void yyset_debug ( int debug_flag , yyscan_t yyscanner );
-YY_EXTRA_TYPE cmListFileLexer_yyget_extra (yyscan_t yyscanner );
+YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
-void cmListFileLexer_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
+void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
-FILE *cmListFileLexer_yyget_in (yyscan_t yyscanner );
+FILE *yyget_in ( yyscan_t yyscanner );
-void cmListFileLexer_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
+void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
-FILE *cmListFileLexer_yyget_out (yyscan_t yyscanner );
+FILE *yyget_out ( yyscan_t yyscanner );
-void cmListFileLexer_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
+void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
- int cmListFileLexer_yyget_leng (yyscan_t yyscanner );
+ int yyget_leng ( yyscan_t yyscanner );
-char *cmListFileLexer_yyget_text (yyscan_t yyscanner );
+char *yyget_text ( yyscan_t yyscanner );
-int cmListFileLexer_yyget_lineno (yyscan_t yyscanner );
+int yyget_lineno ( yyscan_t yyscanner );
-void cmListFileLexer_yyset_lineno (int _line_number ,yyscan_t yyscanner );
+void yyset_lineno ( int _line_number , yyscan_t yyscanner );
-int cmListFileLexer_yyget_column (yyscan_t yyscanner );
+int yyget_column ( yyscan_t yyscanner );
-void cmListFileLexer_yyset_column (int _column_no ,yyscan_t yyscanner );
+void yyset_column ( int _column_no , yyscan_t yyscanner );
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -694,32 +898,31 @@ void cmListFileLexer_yyset_column (int _column_no ,yyscan_t yyscanner );
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
-extern "C" int cmListFileLexer_yywrap (yyscan_t yyscanner );
+extern "C" int yywrap ( yyscan_t yyscanner );
#else
-extern int cmListFileLexer_yywrap (yyscan_t yyscanner );
+extern int yywrap ( yyscan_t yyscanner );
#endif
#endif
#ifndef YY_NO_UNPUT
- static void yyunput (int c,char *buf_ptr ,yyscan_t yyscanner);
+ static void yyunput ( int c, char *buf_ptr , yyscan_t yyscanner);
#endif
#ifndef yytext_ptr
-static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
+static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
+static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
#endif
#ifndef YY_NO_INPUT
-
#ifdef __cplusplus
-static int yyinput (yyscan_t yyscanner );
+static int yyinput ( yyscan_t yyscanner );
#else
-static int input (yyscan_t yyscanner );
+static int input ( yyscan_t yyscanner );
#endif
#endif
@@ -750,7 +953,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- size_t n; \
+ int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -763,7 +966,7 @@ static int input (yyscan_t yyscanner );
else \
{ \
errno=0; \
- while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
@@ -804,9 +1007,9 @@ static int input (yyscan_t yyscanner );
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
-extern int cmListFileLexer_yylex (yyscan_t yyscanner);
+extern int yylex (yyscan_t yyscanner);
-#define YY_DECL int cmListFileLexer_yylex (yyscan_t yyscanner)
+#define YY_DECL int yylex (yyscan_t yyscanner)
#endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng
@@ -851,19 +1054,15 @@ YY_DECL
yyout = stdout;
if ( ! YY_CURRENT_BUFFER ) {
- cmListFileLexer_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmListFileLexer_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
{
-#line 80 "cmListFileLexer.in.l"
-
-
-#line 866 "cmListFileLexer.c"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
@@ -890,13 +1089,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 77 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ if ( yy_current_state >= 79 )
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
- while ( yy_base[yy_current_state] != 237 );
+ while ( yy_base[yy_current_state] != 298 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@@ -935,7 +1134,6 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
/* rule 1 can match eol */
YY_RULE_SETUP
-#line 82 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_Newline;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -948,7 +1146,6 @@ YY_RULE_SETUP
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
-#line 91 "cmListFileLexer.in.l"
{
const char* bracket = yytext;
lexer->comment = yytext[0] == '#';
@@ -971,7 +1168,6 @@ YY_RULE_SETUP
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 111 "cmListFileLexer.in.l"
{
lexer->column += yyleng;
BEGIN(COMMENT);
@@ -979,14 +1175,12 @@ YY_RULE_SETUP
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 116 "cmListFileLexer.in.l"
{
lexer->column += yyleng;
}
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 120 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ParenLeft;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -996,7 +1190,6 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 127 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ParenRight;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1006,7 +1199,6 @@ YY_RULE_SETUP
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 134 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_Identifier;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1016,7 +1208,6 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 141 "cmListFileLexer.in.l"
{
/* Handle ]]====]=======]*/
cmListFileLexerAppend(lexer, yytext, yyleng);
@@ -1028,7 +1219,6 @@ YY_RULE_SETUP
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 150 "cmListFileLexer.in.l"
{
lexer->column += yyleng;
/* Erase the partial bracket from the token. */
@@ -1040,7 +1230,6 @@ YY_RULE_SETUP
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 159 "cmListFileLexer.in.l"
{
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
@@ -1049,7 +1238,6 @@ YY_RULE_SETUP
case 11:
/* rule 11 can match eol */
YY_RULE_SETUP
-#line 164 "cmListFileLexer.in.l"
{
cmListFileLexerAppend(lexer, yytext, yyleng);
++lexer->line;
@@ -1059,7 +1247,6 @@ YY_RULE_SETUP
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 171 "cmListFileLexer.in.l"
{
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
@@ -1068,7 +1255,6 @@ YY_RULE_SETUP
YY_BREAK
case YY_STATE_EOF(BRACKET):
case YY_STATE_EOF(BRACKETEND):
-#line 177 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_BadBracket;
BEGIN(INITIAL);
@@ -1077,7 +1263,6 @@ case YY_STATE_EOF(BRACKETEND):
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 183 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1087,7 +1272,6 @@ YY_RULE_SETUP
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 190 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1097,7 +1281,6 @@ YY_RULE_SETUP
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 197 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1107,7 +1290,6 @@ YY_RULE_SETUP
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 204 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ArgumentQuoted;
cmListFileLexerSetToken(lexer, "", 0);
@@ -1117,7 +1299,6 @@ YY_RULE_SETUP
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 211 "cmListFileLexer.in.l"
{
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
@@ -1126,7 +1307,6 @@ YY_RULE_SETUP
case 18:
/* rule 18 can match eol */
YY_RULE_SETUP
-#line 216 "cmListFileLexer.in.l"
{
/* Continuation: text is not part of string */
++lexer->line;
@@ -1136,7 +1316,6 @@ YY_RULE_SETUP
case 19:
/* rule 19 can match eol */
YY_RULE_SETUP
-#line 222 "cmListFileLexer.in.l"
{
cmListFileLexerAppend(lexer, yytext, yyleng);
++lexer->line;
@@ -1145,7 +1324,6 @@ YY_RULE_SETUP
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 228 "cmListFileLexer.in.l"
{
lexer->column += yyleng;
BEGIN(INITIAL);
@@ -1154,14 +1332,12 @@ YY_RULE_SETUP
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 234 "cmListFileLexer.in.l"
{
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
}
YY_BREAK
case YY_STATE_EOF(STRING):
-#line 239 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_BadString;
BEGIN(INITIAL);
@@ -1170,7 +1346,6 @@ case YY_STATE_EOF(STRING):
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 245 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_Space;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1180,7 +1355,6 @@ YY_RULE_SETUP
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 252 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_BadCharacter;
cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1190,7 +1364,6 @@ YY_RULE_SETUP
YY_BREAK
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(COMMENT):
-#line 259 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_None;
cmListFileLexerSetToken(lexer, 0, 0);
@@ -1199,10 +1372,8 @@ case YY_STATE_EOF(COMMENT):
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 265 "cmListFileLexer.in.l"
ECHO;
YY_BREAK
-#line 1205 "cmListFileLexer.c"
case YY_END_OF_BUFFER:
{
@@ -1218,7 +1389,7 @@ ECHO;
/* 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
+ * 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
@@ -1278,7 +1449,7 @@ ECHO;
{
yyg->yy_did_buffer_switch_on_eof = 0;
- if ( cmListFileLexer_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
@@ -1332,7 +1503,7 @@ ECHO;
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
-} /* end of cmListFileLexer_yylex */
+} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
*
@@ -1346,7 +1517,7 @@ 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;
- yy_size_t number_to_move, i;
+ 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] )
@@ -1375,7 +1546,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
/* Try to read more data. */
/* First move last chars to start of buffer. */
- number_to_move = (yy_size_t) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
+ number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
@@ -1411,7 +1582,8 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
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 );
+ yyrealloc( (void *) b->yy_ch_buf,
+ (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
}
else
/* Can't grow it, we don't own it. */
@@ -1443,7 +1615,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
- cmListFileLexer_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
}
else
@@ -1457,12 +1629,15 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
ret_val = EOB_ACT_CONTINUE_SCAN;
- if ((int) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ if ((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. */
int 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 );
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
+ (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ /* "- 2" to take care of EOB's */
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
}
yyg->yy_n_chars += number_to_move;
@@ -1486,7 +1661,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
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);
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 16);
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
@@ -1495,10 +1670,10 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 77 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ if ( yy_current_state >= 79 )
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
}
return yy_current_state;
@@ -1515,7 +1690,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
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;
+ YY_CHAR yy_c = 16;
if ( yy_accept[yy_current_state] )
{
yyg->yy_last_accepting_state = yy_current_state;
@@ -1524,11 +1699,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 77 )
- yy_c = yy_meta[(unsigned int) yy_c];
+ if ( yy_current_state >= 79 )
+ yy_c = yy_meta[yy_c];
}
- yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
- yy_is_jam = (yy_current_state == 76);
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ yy_is_jam = (yy_current_state == 78);
(void)yyg;
return yy_is_jam ? 0 : yy_current_state;
@@ -1605,7 +1780,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
else
{ /* need more input */
- int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
+ int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
++yyg->yy_c_buf_p;
switch ( yy_get_next_buffer( yyscanner ) )
@@ -1622,13 +1797,13 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
*/
/* Reset buffer status. */
- cmListFileLexer_yyrestart(yyin ,yyscanner);
+ yyrestart( yyin , yyscanner);
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
- if ( cmListFileLexer_yywrap(yyscanner ) )
+ if ( yywrap( yyscanner ) )
return 0;
if ( ! yyg->yy_did_buffer_switch_on_eof )
@@ -1667,34 +1842,34 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
* @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)
+ void yyrestart (FILE * input_file , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! YY_CURRENT_BUFFER ){
- cmListFileLexer_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
YY_CURRENT_BUFFER_LVALUE =
- cmListFileLexer_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
+ yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
}
- cmListFileLexer_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
- cmListFileLexer_yy_load_buffer_state(yyscanner );
+ yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
+ 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)
+ void 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);
+ * yypop_buffer_state();
+ * yypush_buffer_state(new_buffer);
*/
- cmListFileLexer_yyensure_buffer_stack (yyscanner);
+ yyensure_buffer_stack (yyscanner);
if ( YY_CURRENT_BUFFER == new_buffer )
return;
@@ -1707,17 +1882,17 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- cmListFileLexer_yy_load_buffer_state(yyscanner );
+ 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
+ * EOF (yywrap()) processing, but the only time this flag
+ * is looked at is after 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)
+static void 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;
@@ -1732,35 +1907,35 @@ static void cmListFileLexer_yy_load_buffer_state (yyscan_t yyscanner)
* @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 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 );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
- b->yy_buf_size = (yy_size_t)size;
+ 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 );
+ b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
if ( ! b->yy_ch_buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_create_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_is_our_buffer = 1;
- cmListFileLexer_yy_init_buffer(b,file ,yyscanner);
+ yy_init_buffer( b, file , yyscanner);
return b;
}
/** Destroy the buffer.
- * @param b a buffer created with cmListFileLexer_yy_create_buffer()
+ * @param b a buffer created with yy_create_buffer()
* @param yyscanner The scanner object.
*/
- void cmListFileLexer_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
+ void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -1771,28 +1946,28 @@ static void cmListFileLexer_yy_load_buffer_state (yyscan_t yyscanner)
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
- cmListFileLexer_yyfree((void *) b->yy_ch_buf ,yyscanner );
+ yyfree( (void *) b->yy_ch_buf , yyscanner );
- cmListFileLexer_yyfree((void *) b ,yyscanner );
+ 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.
+ * such as during a yyrestart() or at EOF.
*/
- static void cmListFileLexer_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
+ static void 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);
+ 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.
+ /* If b is the current buffer, then yy_init_buffer was _probably_
+ * called from 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){
@@ -1809,7 +1984,7 @@ static void cmListFileLexer_yy_load_buffer_state (yyscan_t yyscanner)
* @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)
+ void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if ( ! b )
@@ -1830,7 +2005,7 @@ static void cmListFileLexer_yy_load_buffer_state (yyscan_t yyscanner)
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == YY_CURRENT_BUFFER )
- cmListFileLexer_yy_load_buffer_state(yyscanner );
+ yy_load_buffer_state( yyscanner );
}
/** Pushes the new state onto the stack. The new state becomes
@@ -1839,15 +2014,15 @@ static void cmListFileLexer_yy_load_buffer_state (yyscan_t yyscanner)
* @param new_buffer The new state.
* @param yyscanner The scanner object.
*/
-void cmListFileLexer_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
+void 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);
+ yyensure_buffer_stack(yyscanner);
- /* This block is copied from cmListFileLexer_yy_switch_to_buffer. */
+ /* This block is copied from yy_switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
@@ -1861,8 +2036,8 @@ void cmListFileLexer_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t
yyg->yy_buffer_stack_top++;
YY_CURRENT_BUFFER_LVALUE = new_buffer;
- /* copied from cmListFileLexer_yy_switch_to_buffer. */
- cmListFileLexer_yy_load_buffer_state(yyscanner );
+ /* copied from yy_switch_to_buffer. */
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
@@ -1870,19 +2045,19 @@ void cmListFileLexer_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t
* The next element becomes the new top.
* @param yyscanner The scanner object.
*/
-void cmListFileLexer_yypop_buffer_state (yyscan_t yyscanner)
+void 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_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 );
+ yy_load_buffer_state( yyscanner );
yyg->yy_did_buffer_switch_on_eof = 1;
}
}
@@ -1890,9 +2065,9 @@ void cmListFileLexer_yypop_buffer_state (yyscan_t yyscanner)
/* Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
-static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner)
+static void yyensure_buffer_stack (yyscan_t yyscanner)
{
- int num_to_alloc;
+ yy_size_t num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
@@ -1902,11 +2077,11 @@ static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner)
* immediate realloc on the next call.
*/
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
- yyg->yy_buffer_stack = (struct yy_buffer_state**)cmListFileLexer_yyalloc
+ yyg->yy_buffer_stack = (struct yy_buffer_state**)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()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
@@ -1921,12 +2096,12 @@ static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner)
yy_size_t 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 = (struct yy_buffer_state**)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()" );
+ YY_FATAL_ERROR( "out of dynamic memory in 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*));
@@ -1940,7 +2115,7 @@ static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner)
* @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 yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
@@ -1950,11 +2125,11 @@ YY_BUFFER_STATE cmListFileLexer_yy_scan_buffer (char * base, yy_size_t size ,
/* They forgot to leave room for the EOB's. */
return NULL;
- b = (YY_BUFFER_STATE) cmListFileLexer_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
+ b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
if ( ! b )
- YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_scan_buffer()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
- b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
+ b->yy_buf_size = (int) (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 = NULL;
@@ -1964,53 +2139,53 @@ YY_BUFFER_STATE cmListFileLexer_yy_scan_buffer (char * base, yy_size_t size ,
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
- cmListFileLexer_yy_switch_to_buffer(b ,yyscanner );
+ yy_switch_to_buffer( b , yyscanner );
return b;
}
-/** Setup the input buffer state to scan a string. The next call to cmListFileLexer_yylex() will
+/** Setup the input buffer state to scan a string. The next call to 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_scan_bytes() instead.
*/
-YY_BUFFER_STATE cmListFileLexer_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
+YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
{
- return cmListFileLexer_yy_scan_bytes(yystr,(int) strlen(yystr) ,yyscanner);
+ return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
}
-/** Setup the input buffer state to scan the given bytes. The next call to cmListFileLexer_yylex() will
+/** Setup the input buffer state to scan the given bytes. The next call to 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 yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
- yy_size_t i;
+ int i;
/* Get memory for full buffer, including space for trailing EOB's. */
- n = (yy_size_t) _yybytes_len + 2;
- buf = (char *) cmListFileLexer_yyalloc(n ,yyscanner );
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) yyalloc( n , yyscanner );
if ( ! buf )
- YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
- for ( i = 0; i < (size_t)_yybytes_len; ++i )
+ 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);
+ b = yy_scan_buffer( buf, n , yyscanner);
if ( ! b )
- YY_FATAL_ERROR( "bad buffer in cmListFileLexer_yy_scan_bytes()" );
+ YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
@@ -2024,11 +2199,11 @@ YY_BUFFER_STATE cmListFileLexer_yy_scan_bytes (yyconst char * yybytes, int _yy
#define YY_EXIT_FAILURE 2
#endif
-static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
+static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- (void) fprintf( stderr, "%s\n", msg );
+ fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
@@ -2054,7 +2229,7 @@ static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
/** Get the user-defined data for this scanner.
* @param yyscanner The scanner object.
*/
-YY_EXTRA_TYPE cmListFileLexer_yyget_extra (yyscan_t yyscanner)
+YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyextra;
@@ -2063,7 +2238,7 @@ YY_EXTRA_TYPE cmListFileLexer_yyget_extra (yyscan_t yyscanner)
/** Get the current line number.
* @param yyscanner The scanner object.
*/
-int cmListFileLexer_yyget_lineno (yyscan_t yyscanner)
+int yyget_lineno (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -2076,7 +2251,7 @@ int cmListFileLexer_yyget_lineno (yyscan_t yyscanner)
/** Get the current column number.
* @param yyscanner The scanner object.
*/
-int cmListFileLexer_yyget_column (yyscan_t yyscanner)
+int yyget_column (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
@@ -2089,7 +2264,7 @@ int cmListFileLexer_yyget_column (yyscan_t yyscanner)
/** Get the input stream.
* @param yyscanner The scanner object.
*/
-FILE *cmListFileLexer_yyget_in (yyscan_t yyscanner)
+FILE *yyget_in (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyin;
@@ -2098,7 +2273,7 @@ FILE *cmListFileLexer_yyget_in (yyscan_t yyscanner)
/** Get the output stream.
* @param yyscanner The scanner object.
*/
-FILE *cmListFileLexer_yyget_out (yyscan_t yyscanner)
+FILE *yyget_out (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyout;
@@ -2107,7 +2282,7 @@ FILE *cmListFileLexer_yyget_out (yyscan_t yyscanner)
/** Get the length of the current token.
* @param yyscanner The scanner object.
*/
-int cmListFileLexer_yyget_leng (yyscan_t yyscanner)
+int yyget_leng (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yyleng;
@@ -2117,7 +2292,7 @@ int cmListFileLexer_yyget_leng (yyscan_t yyscanner)
* @param yyscanner The scanner object.
*/
-char *cmListFileLexer_yyget_text (yyscan_t yyscanner)
+char *yyget_text (yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
return yytext;
@@ -2127,7 +2302,7 @@ char *cmListFileLexer_yyget_text (yyscan_t yyscanner)
* @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)
+void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yyextra = user_defined ;
@@ -2137,13 +2312,13 @@ void cmListFileLexer_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscann
* @param _line_number line number
* @param yyscanner The scanner object.
*/
-void cmListFileLexer_yyset_lineno (int _line_number , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
yylineno = _line_number;
}
@@ -2152,13 +2327,13 @@ void cmListFileLexer_yyset_lineno (int _line_number , yyscan_t yyscanner)
* @param _column_no column number
* @param yyscanner The scanner object.
*/
-void cmListFileLexer_yyset_column (int _column_no , yyscan_t yyscanner)
+void 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" );
+ YY_FATAL_ERROR( "yyset_column called with no buffer" );
yycolumn = _column_no;
}
@@ -2167,27 +2342,27 @@ void cmListFileLexer_yyset_column (int _column_no , yyscan_t yyscanner)
* input buffer.
* @param _in_str A readable stream.
* @param yyscanner The scanner object.
- * @see cmListFileLexer_yy_switch_to_buffer
+ * @see yy_switch_to_buffer
*/
-void cmListFileLexer_yyset_in (FILE * _in_str , yyscan_t yyscanner)
+void 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)
+void 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)
+int 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)
+void yyset_debug (int _bdebug , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
yy_flex_debug = _bdebug ;
@@ -2197,20 +2372,18 @@ void cmListFileLexer_yyset_debug (int _bdebug , yyscan_t yyscanner)
/* User-visible API */
-/* cmListFileLexer_yylex_init is special because it creates the scanner itself, so it is
+/* 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)
-
+int 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 );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -2223,27 +2396,25 @@ int cmListFileLexer_yylex_init(yyscan_t* ptr_yy_globals)
return yy_init_globals ( *ptr_yy_globals );
}
-/* cmListFileLexer_yylex_init_extra has the same functionality as cmListFileLexer_yylex_init, but follows the
+/* yylex_init_extra has the same functionality as 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 user defined value in the first argument will be available to yyalloc in
* the yyextra field.
*/
-
-int cmListFileLexer_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
-
+int 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);
+ 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 );
+ *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
if (*ptr_yy_globals == NULL){
errno = ENOMEM;
@@ -2254,7 +2425,7 @@ int cmListFileLexer_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr
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);
+ yyset_extra (yy_user_defined, *ptr_yy_globals);
return yy_init_globals ( *ptr_yy_globals );
}
@@ -2263,7 +2434,7 @@ 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.
+ * This function is called from yylex_destroy(), so don't allocate here.
*/
yyg->yy_buffer_stack = NULL;
@@ -2287,37 +2458,37 @@ static int yy_init_globals (yyscan_t yyscanner)
#endif
/* For future reference: Set errno on error, since we are called by
- * cmListFileLexer_yylex_init()
+ * yylex_init()
*/
return 0;
}
-/* cmListFileLexer_yylex_destroy is for both reentrant and non-reentrant scanners. */
-int cmListFileLexer_yylex_destroy (yyscan_t yyscanner)
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
+int 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_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
YY_CURRENT_BUFFER_LVALUE = NULL;
- cmListFileLexer_yypop_buffer_state(yyscanner);
+ yypop_buffer_state(yyscanner);
}
/* Destroy the stack itself. */
- cmListFileLexer_yyfree(yyg->yy_buffer_stack ,yyscanner);
+ yyfree(yyg->yy_buffer_stack , yyscanner);
yyg->yy_buffer_stack = NULL;
/* Destroy the start condition stack. */
- cmListFileLexer_yyfree(yyg->yy_start_stack ,yyscanner );
+ 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. */
+ * yylex() is called, initialization will occur. */
yy_init_globals( yyscanner);
/* Destroy the main struct (reentrant only). */
- cmListFileLexer_yyfree ( yyscanner , yyscanner );
+ yyfree ( yyscanner , yyscanner );
yyscanner = NULL;
return 0;
}
@@ -2327,7 +2498,7 @@ int cmListFileLexer_yylex_destroy (yyscan_t yyscanner)
*/
#ifndef yytext_ptr
-static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
+static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2339,7 +2510,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca
#endif
#ifdef YY_NEED_STRLEN
-static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
+static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
{
int n;
for ( n = 0; s[n]; ++n )
@@ -2349,14 +2520,14 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
}
#endif
-void *cmListFileLexer_yyalloc (yy_size_t size , yyscan_t yyscanner)
+void *yyalloc (yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
return malloc(size);
}
-void *cmListFileLexer_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
+void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
@@ -2371,19 +2542,15 @@ void *cmListFileLexer_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscann
return realloc(ptr, size);
}
-void cmListFileLexer_yyfree (void * ptr , yyscan_t yyscanner)
+void yyfree (void * ptr , yyscan_t yyscanner)
{
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
(void)yyg;
- free( (char *) ptr ); /* see cmListFileLexer_yyrealloc() for (char *) cast */
+ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
-#line 265 "cmListFileLexer.in.l"
-
-
-
/*--------------------------------------------------------------------------*/
static void cmListFileLexerSetToken(cmListFileLexer* lexer, const char* text,
int length)
diff --git a/Source/LexerParser/cmListFileLexer.in.l b/Source/LexerParser/cmListFileLexer.in.l
index 5152dbf08..fdf14d2d3 100644
--- a/Source/LexerParser/cmListFileLexer.in.l
+++ b/Source/LexerParser/cmListFileLexer.in.l
@@ -7,20 +7,18 @@ This file must be translated to C and modified to build everywhere.
Run flex >= 2.6 like this:
- flex --nounistd -DFLEXINT_H --prefix=cmListFileLexer_yy -ocmListFileLexer.c cmListFileLexer.in.l
+ flex --nounistd -DFLEXINT_H --noline -ocmListFileLexer.c cmListFileLexer.in.l
Modify cmListFileLexer.c:
- - remove trailing whitespace: sed -i 's/\s*$//' cmListFileLexer.c
- - remove blank lines at end of file
- - #include "cmStandardLexer.h" at the top
- - add cast in yy_scan_bytes for loop condition of _yybytes_len to size_t
- - change type of variable yyl under yy_find_action from yy_size_t to int
+ - remove trailing whitespace: sed -i 's/\s*$//' cmListFileLexer.c
+ - remove blank lines at end of file: sed -i '${/^$/d;}' cmListFileLexer.c
+ - #include "cmStandardLexer.h" at the top: sed -i '1i#include "cmStandardLexer.h"' cmListFileLexer.c
*/
/* IWYU pragma: no_forward_declare yyguts_t */
-#ifdef WIN32
+#ifdef _WIN32
#include "cmsys/Encoding.h"
#endif
@@ -59,11 +57,13 @@ 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); }
+ do { result = cmListFileLexerInput(cmListFileLexer_yyget_extra(yyscanner), buf, max_size); } while (0)
/*--------------------------------------------------------------------------*/
%}
+%option prefix="cmListFileLexer_yy"
+
%option reentrant
%option yylineno
%option noyywrap
@@ -74,7 +74,7 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer);
%x COMMENT
MAKEVAR \$\([A-Za-z0-9_]*\)
-UNQUOTED ([^ \t\r\n\(\)#\\\"[=]|\\.)
+UNQUOTED ([^ \0\t\r\n\(\)#\\\"[=]|\\[^\0\n])
LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
%%
@@ -113,7 +113,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
BEGIN(COMMENT);
}
-<COMMENT>.* {
+<COMMENT>[^\0\n]* {
lexer->column += yyleng;
}
@@ -156,7 +156,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
return 1;
}
-<BRACKET>([^]\n])+ {
+<BRACKET>([^]\0\n])+ {
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
}
@@ -168,7 +168,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
BEGIN(BRACKET);
}
-<BRACKET,BRACKETEND>. {
+<BRACKET,BRACKETEND>[^\0\n] {
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
BEGIN(BRACKET);
@@ -208,7 +208,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
BEGIN(STRING);
}
-<STRING>([^\\\n\"]|\\.)+ {
+<STRING>([^\\\0\n\"]|\\[^\0\n])+ {
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
}
@@ -231,7 +231,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
return 1;
}
-<STRING>. {
+<STRING>[^\0\n] {
cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng;
}
@@ -439,11 +439,15 @@ static cmListFileLexer_BOM cmListFileLexer_ReadBOM(FILE* f)
if (fread(b, 1, 2, f) == 2 && b[0] == 0 && b[1] == 0) {
return cmListFileLexer_BOM_UTF32LE;
}
- fsetpos(f, &p);
+ if (fsetpos(f, &p) != 0) {
+ return cmListFileLexer_BOM_Broken;
+ }
return cmListFileLexer_BOM_UTF16LE;
}
}
- rewind(f);
+ if (fseek(f, 0, SEEK_SET) != 0) {
+ return cmListFileLexer_BOM_Broken;
+ }
return cmListFileLexer_BOM_None;
}
diff --git a/Source/Modules/FindLibUV.cmake b/Source/Modules/FindLibUV.cmake
index ba13d75f8..0554d62c2 100644
--- a/Source/Modules/FindLibUV.cmake
+++ b/Source/Modules/FindLibUV.cmake
@@ -63,6 +63,8 @@ mark_as_advanced(LibUV_INCLUDE_DIR)
set(_LibUV_H_REGEX "#[ \t]*define[ \t]+UV_VERSION_(MAJOR|MINOR|PATCH)[ \t]+[0-9]+")
if(LibUV_INCLUDE_DIR AND EXISTS "${LibUV_INCLUDE_DIR}/uv-version.h")
file(STRINGS "${LibUV_INCLUDE_DIR}/uv-version.h" _LibUV_H REGEX "${_LibUV_H_REGEX}")
+elseif(LibUV_INCLUDE_DIR AND EXISTS "${LibUV_INCLUDE_DIR}/uv/version.h")
+ file(STRINGS "${LibUV_INCLUDE_DIR}/uv/version.h" _LibUV_H REGEX "${_LibUV_H_REGEX}")
elseif(LibUV_INCLUDE_DIR AND EXISTS "${LibUV_INCLUDE_DIR}/uv.h")
file(STRINGS "${LibUV_INCLUDE_DIR}/uv.h" _LibUV_H REGEX "${_LibUV_H_REGEX}")
else()
diff --git a/Source/QtDialog/AddCacheEntry.cxx b/Source/QtDialog/AddCacheEntry.cxx
index 6284ac946..f5e0777bf 100644
--- a/Source/QtDialog/AddCacheEntry.cxx
+++ b/Source/QtDialog/AddCacheEntry.cxx
@@ -21,8 +21,8 @@ AddCacheEntry::AddCacheEntry(QWidget* p, const QStringList& varNames,
, VarTypes(varTypes)
{
this->setupUi(this);
- for (int i = 0; i < NumTypes; i++) {
- this->Type->addItem(TypeStrings[i]);
+ for (auto const& elem : TypeStrings) {
+ this->Type->addItem(elem);
}
QWidget* cb = new QCheckBox();
QWidget* path = new QCMakePathEditor();
@@ -32,12 +32,12 @@ AddCacheEntry::AddCacheEntry(QWidget* p, const QStringList& varNames,
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);
+ AddCacheEntry::setTabOrder(this->Name, this->Type);
+ AddCacheEntry::setTabOrder(this->Type, cb);
+ AddCacheEntry::setTabOrder(cb, path);
+ AddCacheEntry::setTabOrder(path, filepath);
+ AddCacheEntry::setTabOrder(filepath, string);
+ AddCacheEntry::setTabOrder(string, this->Description);
QCompleter* completer = new QCompleter(this->VarNames, this);
this->Name->setCompleter(completer);
connect(completer, SIGNAL(activated(const QString&)), this,
diff --git a/Source/QtDialog/AddCacheEntry.h b/Source/QtDialog/AddCacheEntry.h
index cc710f558..65e11c06d 100644
--- a/Source/QtDialog/AddCacheEntry.h
+++ b/Source/QtDialog/AddCacheEntry.h
@@ -11,7 +11,9 @@
#include "ui_AddCacheEntry.h"
-class AddCacheEntry : public QWidget, public Ui::AddCacheEntry
+class AddCacheEntry
+ : public QWidget
+ , public Ui::AddCacheEntry
{
Q_OBJECT
public:
diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt
index 9e9df781e..cb89d19fd 100644
--- a/Source/QtDialog/CMakeLists.txt
+++ b/Source/QtDialog/CMakeLists.txt
@@ -2,9 +2,6 @@
# file Copyright.txt or https://cmake.org/licensing for details.
project(QtDialog)
-if(POLICY CMP0020)
- cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required
-endif()
CMake_OPTIONAL_COMPONENT(cmake-gui)
find_package(Qt5Widgets QUIET)
if (Qt5Widgets_FOUND)
@@ -19,9 +16,20 @@ if (Qt5Widgets_FOUND)
macro(qt4_add_resources)
qt5_add_resources(${ARGN})
endmacro()
+
set(CMake_QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
set(QT_QTMAIN_LIBRARY ${Qt5Core_QTMAIN_LIBRARIES})
+ # Try to find the package WinExtras for the task bar progress
+ if(WIN32)
+ find_package(Qt5WinExtras QUIET)
+ if (Qt5WinExtras_FOUND)
+ include_directories(${Qt5WinExtras_INCLUDE_DIRS})
+ add_definitions(-DQT_WINEXTRAS)
+ list(APPEND CMake_QT_LIBRARIES ${Qt5WinExtras_LIBRARIES})
+ endif()
+ endif()
+
# Remove this when the minimum version of Qt is 4.6.
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
@@ -33,8 +41,14 @@ if (Qt5Widgets_FOUND)
PROPERTY COMPILE_DEFINITIONS USE_QXcbIntegrationPlugin)
endif()
+ if(CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES)
+ list(APPEND CMake_QT_LIBRARIES ${CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES})
+ set_property(SOURCE CMakeSetup.cxx
+ PROPERTY COMPILE_DEFINITIONS USE_QWindowsIntegrationPlugin)
+ endif()
+
# We need to install platform plugin and add qt.conf for Qt5 on Mac and Windows.
- # FIXME: This should be part of Qt5 CMake scripts, but unfortunatelly
+ # FIXME: This should be part of Qt5 CMake scripts, but unfortunately
# Qt5 support is missing there.
if(CMake_INSTALL_DEPENDENCIES AND (APPLE OR WIN32))
macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var)
@@ -65,7 +79,7 @@ if (Qt5Widgets_FOUND)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
DESTINATION "${CMAKE_INSTALL_PREFIX}/Resources"
${COMPONENT})
- elseif(WIN32)
+ elseif(WIN32 AND NOT CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES)
install_qt5_plugin("Qt5::QWindowsIntegrationPlugin" QT_PLUGINS)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf"
"[Paths]\nPlugins = ../${_qt_plugin_dir}\n")
@@ -160,6 +174,10 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS} ${MANIFEST_FILE})
target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${CMake_QT_LIBRARIES})
+if(WIN32)
+ target_sources(cmake-gui PRIVATE $<TARGET_OBJECTS:CMakeVersion>)
+endif()
+
# cmake-gui has not been updated for `include-what-you-use`.
# Block the tool until this is done.
set_target_properties(cmake-gui PROPERTIES
diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx
index 7fa2ac661..c9ebba83a 100644
--- a/Source/QtDialog/CMakeSetup.cxx
+++ b/Source/QtDialog/CMakeSetup.cxx
@@ -22,19 +22,20 @@
#include "cmSystemTools.h" // IWYU pragma: keep
-static const char* cmDocumentationName[][2] = { { CM_NULLPTR,
+static const char* cmDocumentationName[][2] = { { nullptr,
" cmake-gui - CMake GUI." },
- { CM_NULLPTR, CM_NULLPTR } };
+ { nullptr, nullptr } };
static const char* cmDocumentationUsage[][2] = {
- { CM_NULLPTR, " cmake-gui [options]\n"
- " cmake-gui [options] <path-to-source>\n"
- " cmake-gui [options] <path-to-existing-build>" },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr,
+ " cmake-gui [options]\n"
+ " cmake-gui [options] <path-to-source>\n"
+ " cmake-gui [options] <path-to-existing-build>\n"
+ " cmake-gui [options] -S <path-to-source> -B <path-to-build>\n" },
+ { nullptr, nullptr }
};
-static const char* cmDocumentationOptions[]
- [2] = { { CM_NULLPTR, CM_NULLPTR } };
+static const char* cmDocumentationOptions[][2] = { { nullptr, nullptr } };
#if defined(Q_OS_MAC)
static int cmOSXInstall(std::string dir);
@@ -45,13 +46,22 @@ static void cmAddPluginPath();
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
#endif
+#if defined(USE_QWindowsIntegrationPlugin)
+Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
+# if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
+Q_IMPORT_PLUGIN(QWindowsVistaStylePlugin);
+# endif
+#endif
+
int main(int argc, char** argv)
{
+ cmSystemTools::EnsureStdPipes();
cmsys::Encoding::CommandLineArguments encoding_args =
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
int argc2 = encoding_args.argc();
char const* const* argv2 = encoding_args.argv();
+ cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv2[0]);
// check docs first so that X is not need to get docs
// do docs, if args were given
@@ -59,13 +69,12 @@ int main(int argc, char** argv)
doc.addCMakeStandardDocSections();
if (argc2 > 1 && doc.CheckOptions(argc2, argv2)) {
// Construct and print requested documentation.
- cmake hcm(cmake::RoleInternal);
+ cmake hcm(cmake::RoleInternal, cmState::Unknown);
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
hcm.AddCMakePaths();
- std::vector<cmDocumentationEntry> generators;
- hcm.GetGeneratorDocumentation(generators);
+ auto generators = hcm.GetGeneratorsDocumentation();
doc.SetName("cmake");
doc.SetSection("Name", cmDocumentationName);
doc.SetSection("Usage", cmDocumentationUsage);
@@ -93,6 +102,10 @@ int main(int argc, char** argv)
cmAddPluginPath();
#endif
+#if QT_VERSION >= 0x050600
+ QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+#endif
+
QApplication app(argc, argv);
setlocale(LC_NUMERIC, "C");
@@ -121,36 +134,66 @@ int main(int argc, char** argv)
QTranslator translator;
QString transfile = QString("cmake_%1").arg(QLocale::system().name());
translator.load(transfile, translationsDir.path());
- app.installTranslator(&translator);
+ QApplication::installTranslator(&translator);
// app setup
- app.setApplicationName("CMakeSetup");
- app.setOrganizationName("Kitware");
+ QApplication::setApplicationName("CMakeSetup");
+ QApplication::setOrganizationName("Kitware");
QIcon appIcon;
appIcon.addFile(":/Icons/CMakeSetup32.png");
appIcon.addFile(":/Icons/CMakeSetup128.png");
- app.setWindowIcon(appIcon);
+ QApplication::setWindowIcon(appIcon);
CMakeSetupDialog dialog;
dialog.show();
- cmsys::CommandLineArguments arg;
- arg.Initialize(argc2, argv2);
+ QStringList args = QApplication::arguments();
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();
+ for (int i = 1; i < args.size(); ++i) {
+ const QString& arg = args[i];
+ if (arg.startsWith("-S")) {
+ QString path = arg.mid(2);
+ if (path.isEmpty()) {
+ ++i;
+ if (i >= args.size()) {
+ std::cerr << "No source directory specified for -S" << std::endl;
+ return 1;
+ }
+ path = args[i];
+ if (path[0] == '-') {
+ std::cerr << "No source directory specified for -S" << std::endl;
+ return 1;
+ }
+ }
+
+ sourceDirectory =
+ cmSystemTools::CollapseFullPath(path.toLocal8Bit().data());
+ cmSystemTools::ConvertToUnixSlashes(sourceDirectory);
+ } else if (arg.startsWith("-B")) {
+ QString path = arg.mid(2);
+ if (path.isEmpty()) {
+ ++i;
+ if (i >= args.size()) {
+ std::cerr << "No build directory specified for -B" << std::endl;
+ return 1;
+ }
+ path = args[i];
+ if (path[0] == '-') {
+ std::cerr << "No build directory specified for -B" << std::endl;
+ return 1;
+ }
+ }
+
+ binaryDirectory =
+ cmSystemTools::CollapseFullPath(path.toLocal8Bit().data());
+ cmSystemTools::ConvertToUnixSlashes(binaryDirectory);
+ }
+ }
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) {
std::string filePath =
cmSystemTools::CollapseFullPath(args[1].toLocal8Bit().data());
@@ -180,14 +223,14 @@ int main(int argc, char** argv)
}
}
- return app.exec();
+ return QApplication::exec();
}
#if defined(Q_OS_MAC)
-#include "cm_sys_stat.h"
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
+# include "cm_sys_stat.h"
+# include <errno.h>
+# include <string.h>
+# include <unistd.h>
static bool cmOSXInstall(std::string const& dir, std::string const& tool)
{
if (tool.empty()) {
@@ -207,12 +250,11 @@ static bool cmOSXInstall(std::string const& dir, std::string const& tool)
if (symlink(tool.c_str(), link.c_str()) == 0) {
std::cerr << "Linked: '" << link << "' -> '" << tool << "'\n";
return true;
- } else {
- int err = errno;
- std::cerr << "Failed: '" << link << "' -> '" << tool
- << "': " << strerror(err) << "\n";
- return false;
}
+ int err = errno;
+ std::cerr << "Failed: '" << link << "' -> '" << tool
+ << "': " << strerror(err) << "\n";
+ return false;
}
static int cmOSXInstall(std::string dir)
{
diff --git a/Source/QtDialog/CMakeSetup.icns b/Source/QtDialog/CMakeSetup.icns
index 4a50c0416..e0bf8fdfa 100644
--- a/Source/QtDialog/CMakeSetup.icns
+++ b/Source/QtDialog/CMakeSetup.icns
Binary files differ
diff --git a/Source/QtDialog/CMakeSetup.ico b/Source/QtDialog/CMakeSetup.ico
index e13bb156f..1ac13c830 100644
--- a/Source/QtDialog/CMakeSetup.ico
+++ b/Source/QtDialog/CMakeSetup.ico
Binary files differ
diff --git a/Source/QtDialog/CMakeSetup128.png b/Source/QtDialog/CMakeSetup128.png
index 12f1d9a9a..32984e104 100644
--- a/Source/QtDialog/CMakeSetup128.png
+++ b/Source/QtDialog/CMakeSetup128.png
Binary files differ
diff --git a/Source/QtDialog/CMakeSetup32.png b/Source/QtDialog/CMakeSetup32.png
index 7bbcee413..78df82f15 100644
--- a/Source/QtDialog/CMakeSetup32.png
+++ b/Source/QtDialog/CMakeSetup32.png
Binary files differ
diff --git a/Source/QtDialog/CMakeSetup64.png b/Source/QtDialog/CMakeSetup64.png
index 43a8cc6af..5c2dbf552 100644
--- a/Source/QtDialog/CMakeSetup64.png
+++ b/Source/QtDialog/CMakeSetup64.png
Binary files differ
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx
index 57f8e107e..e98cdcf4a 100644
--- a/Source/QtDialog/CMakeSetupDialog.cxx
+++ b/Source/QtDialog/CMakeSetupDialog.cxx
@@ -21,6 +21,11 @@
#include <QToolButton>
#include <QUrl>
+#ifdef QT_WINEXTRAS
+# include <QWinTaskbarButton>
+# include <QWinTaskbarProgress>
+#endif
+
#include "AddCacheEntry.h"
#include "FirstConfigure.h"
#include "QCMake.h"
@@ -32,7 +37,7 @@
QCMakeThread::QCMakeThread(QObject* p)
: QThread(p)
- , CMakeInstance(CM_NULLPTR)
+ , CMakeInstance(nullptr)
{
}
@@ -48,7 +53,7 @@ void QCMakeThread::run()
emit this->cmakeInitialized();
this->exec();
delete this->CMakeInstance;
- this->CMakeInstance = CM_NULLPTR;
+ this->CMakeInstance = nullptr;
}
CMakeSetupDialog::CMakeSetupDialog()
@@ -108,7 +113,7 @@ CMakeSetupDialog::CMakeSetupDialog()
QMenu* ToolsMenu = this->menuBar()->addMenu(tr("&Tools"));
this->ConfigureAction = ToolsMenu->addAction(tr("&Configure"));
- // prevent merging with Preferences menu item on Mac OS X
+ // prevent merging with Preferences menu item on macOS
this->ConfigureAction->setMenuRole(QAction::NoRole);
QObject::connect(this->ConfigureAction, SIGNAL(triggered(bool)), this,
SLOT(doConfigure()));
@@ -188,6 +193,9 @@ CMakeSetupDialog::CMakeSetupDialog()
connect(this->Output, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(doOutputContextMenu(const QPoint&)));
+ // disable open project button
+ this->OpenProjectButton->setDisabled(true);
+
// start the cmake worker thread
this->CMakeThread = new QCMakeThread(this);
QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()), this,
@@ -249,6 +257,10 @@ void CMakeSetupDialog::initialize()
SIGNAL(outputMessage(QString)), this,
SLOT(message(QString)));
+ QObject::connect(this->CMakeThread->cmakeInstance(),
+ SIGNAL(openPossible(bool)), this->OpenProjectButton,
+ SLOT(setEnabled(bool)));
+
QObject::connect(this->groupedCheck, SIGNAL(toggled(bool)), this,
SLOT(setGroupedView(bool)));
QObject::connect(this->advancedCheck, SIGNAL(toggled(bool)), this,
@@ -287,6 +299,11 @@ void CMakeSetupDialog::initialize()
} else {
this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text());
}
+
+#ifdef QT_WINEXTRAS
+ this->TaskbarButton = new QWinTaskbarButton(this);
+ this->TaskbarButton->setWindow(this->windowHandle());
+#endif
}
CMakeSetupDialog::~CMakeSetupDialog()
@@ -374,6 +391,10 @@ void CMakeSetupDialog::doConfigure()
this->CacheValues->scrollToTop();
}
this->ProgressBar->reset();
+
+#ifdef QT_WINEXTRAS
+ this->TaskbarButton->progress()->reset();
+#endif
}
bool CMakeSetupDialog::doConfigureInternal()
@@ -488,28 +509,17 @@ void CMakeSetupDialog::doGenerate()
this->enterState(ReadyConfigure);
this->ProgressBar->reset();
+#ifdef QT_WINEXTRAS
+ this->TaskbarButton->progress()->reset();
+#endif
this->ConfigureNeeded = true;
}
-QString CMakeSetupDialog::getProjectFilename()
-{
- QStringList nameFilter;
- nameFilter << "*.sln"
- << "*.xcodeproj";
- QDir directory(this->BinaryDirectory->currentText());
- QStringList nlnFile = directory.entryList(nameFilter);
-
- if (nlnFile.count() == 1) {
- return this->BinaryDirectory->currentText() + "/" + nlnFile.at(0);
- }
-
- return QString();
-}
-
void CMakeSetupDialog::doOpenProject()
{
- QDesktopServices::openUrl(QUrl::fromLocalFile(this->getProjectFilename()));
+ QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), "open",
+ Qt::QueuedConnection);
}
void CMakeSetupDialog::closeEvent(QCloseEvent* e)
@@ -630,11 +640,6 @@ void CMakeSetupDialog::updateBinaryDirectory(const QString& dir)
this->BinaryDirectory->setEditText(dir);
this->BinaryDirectory->blockSignals(false);
}
- if (!this->getProjectFilename().isEmpty()) {
- this->OpenProjectButton->setEnabled(true);
- } else {
- this->OpenProjectButton->setEnabled(false);
- }
}
void CMakeSetupDialog::doBinaryBrowse()
@@ -686,6 +691,12 @@ void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent)
{
percent = (percent * ProgressFactor) + ProgressOffset;
this->ProgressBar->setValue(qRound(percent * 100));
+
+#ifdef QT_WINEXTRAS
+ QWinTaskbarProgress* progress = this->TaskbarButton->progress();
+ progress->setVisible(true);
+ progress->setValue(qRound(percent * 100));
+#endif
}
void CMakeSetupDialog::error(const QString& msg)
@@ -739,6 +750,7 @@ bool CMakeSetupDialog::setupFirstConfigure()
if (dialog.exec() == QDialog::Accepted) {
dialog.saveToSettings();
this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
+ this->CMakeThread->cmakeInstance()->setPlatform(dialog.getPlatform());
this->CMakeThread->cmakeInstance()->setToolset(dialog.getToolset());
QCMakeCacheModel* m = this->CacheValues->cacheModel();
@@ -850,11 +862,11 @@ void CMakeSetupDialog::doAbout()
"built using Qt %2 (qt-project.org).\n"
#ifdef USE_LGPL
"\n"
- "The Qt Toolkit is Copyright (C) Digia Plc and/or its subsidiary(-ies).\n"
+ "The Qt Toolkit is Copyright (C) The Qt Company Ltd.\n"
"Qt is licensed under terms of the GNU LGPLv" USE_LGPL ", available at:\n"
" \"%3\""
#endif
- );
+ );
msg = msg.arg(cmVersion::GetCMakeVersion());
msg = msg.arg(qVersion());
#ifdef USE_LGPL
@@ -1001,8 +1013,9 @@ void CMakeSetupDialog::removeSelectedCacheEntries()
void CMakeSetupDialog::selectionChanged()
{
QModelIndexList idxs = this->CacheValues->selectionModel()->selectedRows();
- if (idxs.count() && (this->CurrentState == ReadyConfigure ||
- this->CurrentState == ReadyGenerate)) {
+ if (idxs.count() &&
+ (this->CurrentState == ReadyConfigure ||
+ this->CurrentState == ReadyGenerate)) {
this->RemoveEntry->setEnabled(true);
} else {
this->RemoveEntry->setEnabled(false);
@@ -1039,9 +1052,6 @@ void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
this->GenerateButton->setEnabled(true);
this->GenerateAction->setEnabled(true);
this->ConfigureButton->setEnabled(true);
- if (!this->getProjectFilename().isEmpty()) {
- this->OpenProjectButton->setEnabled(true);
- }
this->ConfigureButton->setText(tr("&Configure"));
this->GenerateButton->setText(tr("&Generate"));
} else if (s == ReadyGenerate) {
@@ -1049,9 +1059,6 @@ void CMakeSetupDialog::enterState(CMakeSetupDialog::State s)
this->GenerateButton->setEnabled(true);
this->GenerateAction->setEnabled(true);
this->ConfigureButton->setEnabled(true);
- if (!this->getProjectFilename().isEmpty()) {
- this->OpenProjectButton->setEnabled(true);
- }
this->ConfigureButton->setText(tr("&Configure"));
this->GenerateButton->setText(tr("&Generate"));
}
@@ -1195,7 +1202,7 @@ void CMakeSetupDialog::setSearchFilter(const QString& str)
this->CacheValues->setSearchFilter(str);
}
-void CMakeSetupDialog::doOutputContextMenu(const QPoint& pt)
+void CMakeSetupDialog::doOutputContextMenu(QPoint pt)
{
QMenu* menu = this->Output->createStandardContextMenu();
diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h
index 1abdb462d..39c1053cb 100644
--- a/Source/QtDialog/CMakeSetupDialog.h
+++ b/Source/QtDialog/CMakeSetupDialog.h
@@ -15,8 +15,14 @@ class CMakeCacheModel;
class QProgressBar;
class QToolButton;
+#ifdef QT_WINEXTRAS
+class QWinTaskbarButton;
+#endif
+
/// Qt user interface for CMake
-class CMakeSetupDialog : public QMainWindow, public Ui::CMakeSetupDialog
+class CMakeSetupDialog
+ : public QMainWindow
+ , public Ui::CMakeSetupDialog
{
Q_OBJECT
public:
@@ -31,7 +37,6 @@ protected slots:
void initialize();
void doConfigure();
void doGenerate();
- QString getProjectFilename();
void doOpenProject();
void doInstallForCommandLine();
void doHelp();
@@ -70,7 +75,7 @@ protected slots:
bool doConfigureInternal();
bool doGenerateInternal();
void exitLoop(int);
- void doOutputContextMenu(const QPoint&);
+ void doOutputContextMenu(QPoint pt);
void doOutputFindDialog();
void doOutputFindNext(bool directionForward = true);
void doOutputFindPrev();
@@ -117,6 +122,10 @@ protected:
QEventLoop LocalLoop;
+#ifdef QT_WINEXTRAS
+ QWinTaskbarButton* TaskbarButton;
+#endif
+
float ProgressOffset;
float ProgressFactor;
};
diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui
index 8d8e0cdc2..dc22a2989 100644
--- a/Source/QtDialog/CMakeSetupDialog.ui
+++ b/Source/QtDialog/CMakeSetupDialog.ui
@@ -57,6 +57,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="styleSheet">
+ <string notr="true">padding-left: 0</string>
+ </property>
<property name="editable">
<bool>true</bool>
</property>
diff --git a/Source/QtDialog/Compilers.h b/Source/QtDialog/Compilers.h
index 6c8c8f52a..96770e3f4 100644
--- a/Source/QtDialog/Compilers.h
+++ b/Source/QtDialog/Compilers.h
@@ -3,17 +3,19 @@
#ifndef COMPILERS_HPP
#define COMPILERS_HPP
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <QWidget>
#include <ui_Compilers.h>
-class Compilers : public QWidget, public Ui::Compilers
+class Compilers
+ : public QWidget
+ , public Ui::Compilers
{
Q_OBJECT
public:
- Compilers(QWidget* p = CM_NULLPTR)
+ Compilers(QWidget* p = nullptr)
: QWidget(p)
{
this->setupUi(this);
diff --git a/Source/QtDialog/Delete16.png b/Source/QtDialog/Delete16.png
index 16989fee1..9d2f2b7ec 100644
--- a/Source/QtDialog/Delete16.png
+++ b/Source/QtDialog/Delete16.png
Binary files differ
diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx
index b193a2782..364a378b3 100644
--- a/Source/QtDialog/FirstConfigure.cxx
+++ b/Source/QtDialog/FirstConfigure.cxx
@@ -16,8 +16,12 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p)
this->GeneratorOptions = new QComboBox(this);
l->addWidget(this->GeneratorOptions);
+ // Add the generator platform
+ this->PlatformFrame = CreatePlatformWidgets();
+ l->addWidget(PlatformFrame);
+
// Add the ability to specify toolset (-T parameter)
- ToolsetFrame = CreateToolsetWidgets();
+ this->ToolsetFrame = CreateToolsetWidgets();
l->addWidget(ToolsetFrame);
l->addSpacing(6);
@@ -45,7 +49,7 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p)
SLOT(onSelectionChanged(bool)));
QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)), this,
SLOT(onSelectionChanged(bool)));
- QObject::connect(GeneratorOptions,
+ QObject::connect(this->GeneratorOptions,
SIGNAL(currentIndexChanged(QString const&)), this,
SLOT(onGeneratorChanged(QString const&)));
}
@@ -65,10 +69,25 @@ QFrame* StartCompilerSetup::CreateToolsetWidgets()
return frame;
}
-StartCompilerSetup::~StartCompilerSetup()
+QFrame* StartCompilerSetup::CreatePlatformWidgets()
{
+ QFrame* frame = new QFrame(this);
+ QVBoxLayout* l = new QVBoxLayout(frame);
+ l->setContentsMargins(0, 0, 0, 0);
+
+ this->PlatformLabel = new QLabel(tr("Optional platform for generator"));
+ l->addWidget(this->PlatformLabel);
+
+ this->PlatformOptions = new QComboBox(frame);
+ this->PlatformOptions->setEditable(true);
+
+ l->addWidget(this->PlatformOptions);
+
+ return frame;
}
+StartCompilerSetup::~StartCompilerSetup() = default;
+
void StartCompilerSetup::setGenerators(
std::vector<cmake::GeneratorInfo> const& gens)
{
@@ -76,13 +95,32 @@ void StartCompilerSetup::setGenerators(
QStringList generator_list;
- std::vector<cmake::GeneratorInfo>::const_iterator it;
- for (it = gens.begin(); it != gens.end(); ++it) {
- generator_list.append(QString::fromLocal8Bit(it->name.c_str()));
+ for (cmake::GeneratorInfo const& gen : gens) {
+ generator_list.append(QString::fromLocal8Bit(gen.name.c_str()));
- if (it->supportsToolset) {
+ if (gen.supportsPlatform) {
+ this->GeneratorsSupportingPlatform.append(
+ QString::fromLocal8Bit(gen.name.c_str()));
+
+ this
+ ->GeneratorDefaultPlatform[QString::fromLocal8Bit(gen.name.c_str())] =
+ QString::fromLocal8Bit(gen.defaultPlatform.c_str());
+
+ std::vector<std::string>::const_iterator platformIt =
+ gen.supportedPlatforms.cbegin();
+ while (platformIt != gen.supportedPlatforms.cend()) {
+
+ this->GeneratorSupportedPlatforms.insert(
+ QString::fromLocal8Bit(gen.name.c_str()),
+ QString::fromLocal8Bit((*platformIt).c_str()));
+
+ platformIt++;
+ }
+ }
+
+ if (gen.supportsToolset) {
this->GeneratorsSupportingToolset.append(
- QString::fromLocal8Bit(it->name.c_str()));
+ QString::fromLocal8Bit(gen.name.c_str()));
}
}
@@ -102,6 +140,11 @@ QString StartCompilerSetup::getGenerator() const
return this->GeneratorOptions->currentText();
};
+QString StartCompilerSetup::getPlatform() const
+{
+ return this->PlatformOptions->currentText();
+};
+
QString StartCompilerSetup::getToolset() const
{
return this->Toolset->text();
@@ -136,6 +179,31 @@ void StartCompilerSetup::onSelectionChanged(bool on)
void StartCompilerSetup::onGeneratorChanged(QString const& name)
{
+ // Display the generator platform for the generators supporting it
+ if (GeneratorsSupportingPlatform.contains(name)) {
+
+ // Change the label title to include the default platform
+ std::string label = "Optional platform for generator";
+ label += "(if empty, generator uses: ";
+ label += this->GeneratorDefaultPlatform[name].toStdString();
+ label += ")";
+ this->PlatformLabel->setText(tr(label.c_str()));
+
+ // Regenerate the list of supported platform
+ this->PlatformOptions->clear();
+ QStringList platform_list;
+ platform_list.append("");
+
+ QList<QString> platforms = this->GeneratorSupportedPlatforms.values(name);
+ platform_list.append(platforms);
+
+ this->PlatformOptions->addItems(platform_list);
+ PlatformFrame->show();
+ } else {
+ PlatformFrame->hide();
+ }
+
+ // Display the toolset box for the generators supporting it
if (GeneratorsSupportingToolset.contains(name)) {
ToolsetFrame->show();
} else {
@@ -166,9 +234,7 @@ NativeCompilerSetup::NativeCompilerSetup(QWidget* p)
this->setupUi(c);
}
-NativeCompilerSetup::~NativeCompilerSetup()
-{
-}
+NativeCompilerSetup::~NativeCompilerSetup() = default;
QString NativeCompilerSetup::getCCompiler() const
{
@@ -230,9 +296,7 @@ CrossCompilerSetup::CrossCompilerSetup(QWidget* p)
this->registerField("systemName*", this->systemName);
}
-CrossCompilerSetup::~CrossCompilerSetup()
-{
-}
+CrossCompilerSetup::~CrossCompilerSetup() = default;
QString CrossCompilerSetup::getCCompiler() const
{
@@ -301,7 +365,7 @@ QString CrossCompilerSetup::getFindRoot() const
void CrossCompilerSetup::setFindRoot(const QString& t)
{
- return this->crossFindRoot->setText(t);
+ this->crossFindRoot->setText(t);
}
int CrossCompilerSetup::getProgramMode() const
@@ -343,9 +407,7 @@ ToolchainCompilerSetup::ToolchainCompilerSetup(QWidget* p)
l->addWidget(this->ToolchainFile);
}
-ToolchainCompilerSetup::~ToolchainCompilerSetup()
-{
-}
+ToolchainCompilerSetup::~ToolchainCompilerSetup() = default;
QString ToolchainCompilerSetup::toolchainFile() const
{
@@ -375,9 +437,7 @@ FirstConfigure::FirstConfigure()
this->setPage(ToolchainSetup, this->mToolchainCompilerSetupPage);
}
-FirstConfigure::~FirstConfigure()
-{
-}
+FirstConfigure::~FirstConfigure() = default;
void FirstConfigure::setGenerators(
std::vector<cmake::GeneratorInfo> const& gens)
@@ -390,6 +450,11 @@ QString FirstConfigure::getGenerator() const
return this->mStartCompilerSetupPage->getGenerator();
}
+QString FirstConfigure::getPlatform() const
+{
+ return this->mStartCompilerSetupPage->getPlatform();
+}
+
QString FirstConfigure::getToolset() const
{
return this->mStartCompilerSetupPage->getToolset();
diff --git a/Source/QtDialog/FirstConfigure.h b/Source/QtDialog/FirstConfigure.h
index c467ddb19..d1db5bff6 100644
--- a/Source/QtDialog/FirstConfigure.h
+++ b/Source/QtDialog/FirstConfigure.h
@@ -35,6 +35,7 @@ public:
void setCurrentGenerator(const QString& gen);
QString getGenerator() const;
QString getToolset() const;
+ QString getPlatform() const;
bool defaultSetup() const;
bool compilerSetup() const;
@@ -56,14 +57,23 @@ protected:
QFrame* ToolsetFrame;
QLineEdit* Toolset;
QLabel* ToolsetLabel;
+ QFrame* PlatformFrame;
+ QComboBox* PlatformOptions;
+ QLabel* PlatformLabel;
QStringList GeneratorsSupportingToolset;
+ QStringList GeneratorsSupportingPlatform;
+ QMultiMap<QString, QString> GeneratorSupportedPlatforms;
+ QMap<QString, QString> GeneratorDefaultPlatform;
private:
QFrame* CreateToolsetWidgets();
+ QFrame* CreatePlatformWidgets();
};
//! the page that gives basic options for native compilers
-class NativeCompilerSetup : public QWizardPage, protected Ui::Compilers
+class NativeCompilerSetup
+ : public QWizardPage
+ , protected Ui::Compilers
{
Q_OBJECT
public:
@@ -83,7 +93,9 @@ public:
};
//! the page that gives options for cross compilers
-class CrossCompilerSetup : public QWizardPage, protected Ui::CrossCompiler
+class CrossCompilerSetup
+ : public QWizardPage
+ , protected Ui::CrossCompiler
{
Q_OBJECT
public:
@@ -155,6 +167,7 @@ public:
void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
QString getGenerator() const;
+ QString getPlatform() const;
QString getToolset() const;
bool defaultSetup() const;
diff --git a/Source/QtDialog/Plus16.png b/Source/QtDialog/Plus16.png
index 552f6f004..1c33bc763 100644
--- a/Source/QtDialog/Plus16.png
+++ b/Source/QtDialog/Plus16.png
Binary files differ
diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx
index d473d9b8f..f357f9032 100644
--- a/Source/QtDialog/QCMake.cxx
+++ b/Source/QtDialog/QCMake.cxx
@@ -10,7 +10,7 @@
#include "cmSystemTools.h"
#ifdef Q_OS_WIN
-#include "qt_windows.h" // For SetErrorMode
+# include "qt_windows.h" // For SetErrorMode
#endif
QCMake::QCMake(QObject* p)
@@ -23,32 +23,33 @@ QCMake::QCMake(QObject* p)
cmSystemTools::DisableRunCommandOutput();
cmSystemTools::SetRunCommandHideConsole(true);
- cmSystemTools::SetMessageCallback(QCMake::messageCallback, this);
- cmSystemTools::SetStdoutCallback(QCMake::stdoutCallback, this);
- cmSystemTools::SetStderrCallback(QCMake::stderrCallback, this);
- this->CMakeInstance = new cmake(cmake::RoleProject);
+ cmSystemTools::SetMessageCallback(
+ [this](std::string const& msg, const char* title) {
+ this->messageCallback(msg, title);
+ });
+ cmSystemTools::SetStdoutCallback(
+ [this](std::string const& msg) { this->stdoutCallback(msg); });
+ cmSystemTools::SetStderrCallback(
+ [this](std::string const& msg) { this->stderrCallback(msg); });
+
+ this->CMakeInstance = new cmake(cmake::RoleProject, cmState::Project);
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeGUICommand());
- this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
+ this->CMakeInstance->SetProgressCallback(
+ [this](const std::string& msg, float percent) {
+ this->progressCallback(msg, percent);
+ });
- cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this);
+ cmSystemTools::SetInterruptCallback(
+ [this] { return this->interruptCallback(); });
std::vector<cmake::GeneratorInfo> generators;
- this->CMakeInstance->GetRegisteredGenerators(generators);
-
- std::vector<cmake::GeneratorInfo>::const_iterator it;
- for (it = generators.begin(); it != generators.end(); ++it) {
- // Skip the generator "KDevelop3", since there is also
- // "KDevelop3 - Unix Makefiles", which is the full and official name.
- // The short name is actually only still there since this was the name
- // in CMake 2.4, to keep "command line argument compatibility", but
- // this is not necessary in the GUI.
- if (it->name == "KDevelop3") {
- continue;
- }
+ this->CMakeInstance->GetRegisteredGenerators(
+ generators, /*includeNamesWithPlatform=*/false);
- this->AvailableGenerators.push_back(*it);
+ for (cmake::GeneratorInfo const& gen : generators) {
+ this->AvailableGenerators.push_back(gen);
}
}
@@ -83,6 +84,7 @@ void QCMake::setBinaryDirectory(const QString& _dir)
cmState* state = this->CMakeInstance->GetState();
this->setGenerator(QString());
this->setToolset(QString());
+ this->setPlatform(QString());
if (!this->CMakeInstance->LoadCache(
this->BinaryDirectory.toLocal8Bit().data())) {
QDir testDir(this->BinaryDirectory);
@@ -103,18 +105,26 @@ void QCMake::setBinaryDirectory(const QString& _dir)
}
const char* gen = state->GetCacheEntryValue("CMAKE_GENERATOR");
if (gen) {
- const char* extraGen =
+ const std::string* extraGen =
state->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
std::string curGen =
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
- gen, extraGen ? extraGen : "");
+ gen, extraGen ? *extraGen : "");
this->setGenerator(QString::fromLocal8Bit(curGen.c_str()));
}
+ const char* platform =
+ state->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM");
+ if (platform) {
+ this->setPlatform(QString::fromLocal8Bit(platform));
+ }
+
const char* toolset = state->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET");
if (toolset) {
this->setToolset(QString::fromLocal8Bit(toolset));
}
+
+ checkOpenPossible();
}
}
@@ -126,6 +136,14 @@ void QCMake::setGenerator(const QString& gen)
}
}
+void QCMake::setPlatform(const QString& platform)
+{
+ if (this->Platform != platform) {
+ this->Platform = platform;
+ emit this->platformChanged(this->Platform);
+ }
+}
+
void QCMake::setToolset(const QString& toolset)
{
if (this->Toolset != toolset) {
@@ -147,7 +165,8 @@ void QCMake::configure()
this->CMakeInstance->SetGlobalGenerator(
this->CMakeInstance->CreateGlobalGenerator(
this->Generator.toLocal8Bit().data()));
- this->CMakeInstance->SetGeneratorPlatform("");
+ this->CMakeInstance->SetGeneratorPlatform(
+ this->Platform.toLocal8Bit().data());
this->CMakeInstance->SetGeneratorToolset(this->Toolset.toLocal8Bit().data());
this->CMakeInstance->LoadCache();
this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
@@ -183,6 +202,26 @@ void QCMake::generate()
#endif
emit this->generateDone(err);
+ checkOpenPossible();
+}
+
+void QCMake::open()
+{
+#ifdef Q_OS_WIN
+ UINT lastErrorMode = SetErrorMode(0);
+#endif
+
+ InterruptFlag = 0;
+ cmSystemTools::ResetErrorOccuredFlag();
+
+ auto successful = this->CMakeInstance->Open(
+ this->BinaryDirectory.toLocal8Bit().data(), false);
+
+#ifdef Q_OS_WIN
+ SetErrorMode(lastErrorMode);
+#endif
+
+ emit this->openDone(successful);
}
void QCMake::setProperties(const QCMakePropertyList& newProps)
@@ -194,24 +233,23 @@ void QCMake::setProperties(const QCMakePropertyList& newProps)
// set the value of properties
cmState* state = this->CMakeInstance->GetState();
std::vector<std::string> cacheKeys = state->GetCacheEntryKeys();
- for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it) {
- cmStateEnums::CacheEntryType t = state->GetCacheEntryType(*it);
+ for (std::string const& key : cacheKeys) {
+ cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key);
if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC) {
continue;
}
QCMakeProperty prop;
- prop.Key = QString::fromLocal8Bit(it->c_str());
+ prop.Key = QString::fromLocal8Bit(key.c_str());
int idx = props.indexOf(prop);
if (idx == -1) {
- toremove.append(QString::fromLocal8Bit(it->c_str()));
+ toremove.append(QString::fromLocal8Bit(key.c_str()));
} else {
prop = props[idx];
if (prop.Value.type() == QVariant::Bool) {
- state->SetCacheEntryValue(*it, prop.Value.toBool() ? "ON" : "OFF");
+ state->SetCacheEntryValue(key, prop.Value.toBool() ? "ON" : "OFF");
} else {
- state->SetCacheEntryValue(*it,
+ state->SetCacheEntryValue(key,
prop.Value.toString().toLocal8Bit().data());
}
props.removeAt(idx);
@@ -257,22 +295,21 @@ QCMakePropertyList QCMake::properties() const
cmState* state = this->CMakeInstance->GetState();
std::vector<std::string> cacheKeys = state->GetCacheEntryKeys();
- for (std::vector<std::string>::const_iterator i = cacheKeys.begin();
- i != cacheKeys.end(); ++i) {
- cmStateEnums::CacheEntryType t = state->GetCacheEntryType(*i);
+ for (std::string const& key : cacheKeys) {
+ cmStateEnums::CacheEntryType t = state->GetCacheEntryType(key);
if (t == cmStateEnums::INTERNAL || t == cmStateEnums::STATIC ||
t == cmStateEnums::UNINITIALIZED) {
continue;
}
- const char* cachedValue = state->GetCacheEntryValue(*i);
+ const char* cachedValue = state->GetCacheEntryValue(key);
QCMakeProperty prop;
- prop.Key = QString::fromLocal8Bit(i->c_str());
+ prop.Key = QString::fromLocal8Bit(key.c_str());
prop.Help =
- QString::fromLocal8Bit(state->GetCacheEntryProperty(*i, "HELPSTRING"));
+ QString::fromLocal8Bit(state->GetCacheEntryProperty(key, "HELPSTRING"));
prop.Value = QString::fromLocal8Bit(cachedValue);
- prop.Advanced = state->GetCacheEntryPropertyAsBool(*i, "ADVANCED");
+ prop.Advanced = state->GetCacheEntryPropertyAsBool(key, "ADVANCED");
if (t == cmStateEnums::BOOL) {
prop.Type = QCMakeProperty::BOOL;
prop.Value = cmSystemTools::IsOn(cachedValue);
@@ -283,7 +320,7 @@ QCMakePropertyList QCMake::properties() const
} else if (t == cmStateEnums::STRING) {
prop.Type = QCMakeProperty::STRING;
const char* stringsProperty =
- state->GetCacheEntryProperty(*i, "STRINGS");
+ state->GetCacheEntryProperty(key, "STRINGS");
if (stringsProperty) {
prop.Strings = QString::fromLocal8Bit(stringsProperty).split(";");
}
@@ -300,46 +337,40 @@ void QCMake::interrupt()
this->InterruptFlag.ref();
}
-bool QCMake::interruptCallback(void* cd)
+bool QCMake::interruptCallback()
{
- QCMake* self = reinterpret_cast<QCMake*>(cd);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
- return self->InterruptFlag;
+ return this->InterruptFlag;
#else
- return self->InterruptFlag.load();
+ return this->InterruptFlag.load();
#endif
}
-void QCMake::progressCallback(const char* msg, float percent, void* cd)
+void QCMake::progressCallback(const std::string& msg, float percent)
{
- QCMake* self = reinterpret_cast<QCMake*>(cd);
if (percent >= 0) {
- emit self->progressChanged(QString::fromLocal8Bit(msg), percent);
+ emit this->progressChanged(QString::fromStdString(msg), percent);
} else {
- emit self->outputMessage(QString::fromLocal8Bit(msg));
+ emit this->outputMessage(QString::fromStdString(msg));
}
QCoreApplication::processEvents();
}
-void QCMake::messageCallback(const char* msg, const char* /*title*/,
- bool& /*stop*/, void* cd)
+void QCMake::messageCallback(std::string const& msg, const char* /*title*/)
{
- QCMake* self = reinterpret_cast<QCMake*>(cd);
- emit self->errorMessage(QString::fromLocal8Bit(msg));
+ emit this->errorMessage(QString::fromStdString(msg));
QCoreApplication::processEvents();
}
-void QCMake::stdoutCallback(const char* msg, size_t len, void* cd)
+void QCMake::stdoutCallback(std::string const& msg)
{
- QCMake* self = reinterpret_cast<QCMake*>(cd);
- emit self->outputMessage(QString::fromLocal8Bit(msg, int(len)));
+ emit this->outputMessage(QString::fromStdString(msg));
QCoreApplication::processEvents();
}
-void QCMake::stderrCallback(const char* msg, size_t len, void* cd)
+void QCMake::stderrCallback(std::string const& msg)
{
- QCMake* self = reinterpret_cast<QCMake*>(cd);
- emit self->outputMessage(QString::fromLocal8Bit(msg, int(len)));
+ emit this->outputMessage(QString::fromStdString(msg));
QCoreApplication::processEvents();
}
@@ -450,3 +481,10 @@ void QCMake::setWarnUnusedMode(bool value)
{
this->WarnUnusedMode = value;
}
+
+void QCMake::checkOpenPossible()
+{
+ auto data = this->BinaryDirectory.toLocal8Bit().data();
+ auto possible = this->CMakeInstance->Open(data, true);
+ emit openPossible(possible);
+}
diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h
index e14cdf2c9..f2fd6d923 100644
--- a/Source/QtDialog/QCMake.h
+++ b/Source/QtDialog/QCMake.h
@@ -3,13 +3,13 @@
#ifndef QCMake_h
#define QCMake_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmake.h"
#ifdef _MSC_VER
-#pragma warning(disable : 4127)
-#pragma warning(disable : 4512)
+# pragma warning(disable : 4127)
+# pragma warning(disable : 4512)
#endif
#include <vector>
@@ -63,7 +63,7 @@ class QCMake : public QObject
{
Q_OBJECT
public:
- QCMake(QObject* p = CM_NULLPTR);
+ QCMake(QObject* p = nullptr);
~QCMake();
public slots:
/// load the cache file in a directory
@@ -75,11 +75,15 @@ public slots:
/// set the desired generator to use
void setGenerator(const QString& generator);
/// set the desired generator to use
+ void setPlatform(const QString& platform);
+ /// set the desired generator to use
void setToolset(const QString& toolset);
/// do the configure step
void configure();
/// generate the files
void generate();
+ /// open the project
+ void open();
/// set the property values
void setProperties(const QCMakePropertyList&);
/// interrupt the configure or generate process (if connecting, make a direct
@@ -111,6 +115,8 @@ public slots:
void setWarnUninitializedMode(bool value);
/// set whether to run cmake with warnings about unused variables
void setWarnUnusedMode(bool value);
+ /// check if project IDE open is possible and emit openPossible signal
+ void checkOpenPossible();
public:
/// get the list of cache properties
@@ -151,22 +157,29 @@ signals:
void debugOutputChanged(bool);
/// signal when the toolset changes
void toolsetChanged(const QString& toolset);
+ /// signal when the platform changes
+ void platformChanged(const QString& platform);
+ /// signal when open is done
+ void openDone(bool successful);
+ /// signal when open is done
+ void openPossible(bool possible);
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 interruptCallback();
+ void progressCallback(std::string const& msg, float percent);
+ void messageCallback(std::string const& msg, const char* title);
+ void stdoutCallback(std::string const& msg);
+ void stderrCallback(std::string const& msg);
+
bool WarnUninitializedMode;
bool WarnUnusedMode;
bool WarnUnusedAllMode;
QString SourceDirectory;
QString BinaryDirectory;
QString Generator;
+ QString Platform;
QString Toolset;
std::vector<cmake::GeneratorInfo> AvailableGenerators;
QString CMakeExecutable;
diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx
index 08c2d58d5..78a271024 100644
--- a/Source/QtDialog/QCMakeCacheView.cxx
+++ b/Source/QtDialog/QCMakeCacheView.cxx
@@ -23,7 +23,7 @@ public:
}
protected:
- bool filterAcceptsRow(int row, const QModelIndex& p) const CM_OVERRIDE
+ bool filterAcceptsRow(int row, const QModelIndex& p) const override
{
QStringList strs;
const QAbstractItemModel* m = this->sourceModel();
@@ -77,7 +77,7 @@ public:
protected:
bool ShowAdvanced;
- bool filterAcceptsRow(int row, const QModelIndex& p) const CM_OVERRIDE
+ bool filterAcceptsRow(int row, const QModelIndex& p) const override
{
const QAbstractItemModel* m = this->sourceModel();
QModelIndex idx = m->index(row, 0, p);
@@ -186,9 +186,7 @@ QCMakeCacheModel::QCMakeCacheModel(QObject* p)
this->setHorizontalHeaderLabels(labels);
}
-QCMakeCacheModel::~QCMakeCacheModel()
-{
-}
+QCMakeCacheModel::~QCMakeCacheModel() = default;
static uint qHash(const QCMakeProperty& p)
{
@@ -248,9 +246,9 @@ void QCMakeCacheModel::setProperties(const QCMakePropertyList& props)
}
} else if (this->View == GroupView) {
QMap<QString, QCMakePropertyList> newPropsTree;
- this->breakProperties(newProps, newPropsTree);
+ QCMakeCacheModel::breakProperties(newProps, newPropsTree);
QMap<QString, QCMakePropertyList> newPropsTree2;
- this->breakProperties(newProps2, newPropsTree2);
+ QCMakeCacheModel::breakProperties(newProps2, newPropsTree2);
QStandardItem* root = this->invisibleRootItem();
@@ -539,7 +537,7 @@ QWidget* QCMakeCacheModelDelegate::createEditor(
QModelIndex var = idx.sibling(idx.row(), 0);
int type = var.data(QCMakeCacheModel::TypeRole).toInt();
if (type == QCMakeProperty::BOOL) {
- return CM_NULLPTR;
+ return nullptr;
}
if (type == QCMakeProperty::PATH) {
QCMakePathEditor* editor =
@@ -614,7 +612,7 @@ bool QCMakeCacheModelDelegate::editorEvent(QEvent* e,
// 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
+ // workaround for what looks like a bug in Qt on macOS
// 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
@@ -642,7 +640,7 @@ QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option,
QStyleOptionButton opt;
opt.QStyleOption::operator=(option);
sz = sz.expandedTo(
- style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, CM_NULLPTR)
+ style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, nullptr)
.size());
return sz;
diff --git a/Source/QtDialog/QCMakeWidgets.cxx b/Source/QtDialog/QCMakeWidgets.cxx
index 7f0cafa37..eab418fe7 100644
--- a/Source/QtDialog/QCMakeWidgets.cxx
+++ b/Source/QtDialog/QCMakeWidgets.cxx
@@ -7,10 +7,11 @@
#include <QFileInfo>
#include <QResizeEvent>
#include <QToolButton>
+#include <utility>
-QCMakeFileEditor::QCMakeFileEditor(QWidget* p, const QString& var)
+QCMakeFileEditor::QCMakeFileEditor(QWidget* p, QString var)
: QLineEdit(p)
- , Variable(var)
+ , Variable(std::move(var))
{
this->ToolButton = new QToolButton(this);
this->ToolButton->setText("...");
@@ -57,7 +58,7 @@ void QCMakeFilePathEditor::chooseFile()
emit this->fileDialogExists(true);
path =
QFileDialog::getOpenFileName(this, title, info.absolutePath(), QString(),
- CM_NULLPTR, QFileDialog::DontResolveSymlinks);
+ nullptr, QFileDialog::DontResolveSymlinks);
emit this->fileDialogExists(false);
if (!path.isEmpty()) {
@@ -89,7 +90,7 @@ void QCMakePathEditor::chooseFile()
// use same QDirModel for all completers
static QDirModel* fileDirModel()
{
- static QDirModel* m = CM_NULLPTR;
+ static QDirModel* m = nullptr;
if (!m) {
m = new QDirModel();
}
@@ -97,7 +98,7 @@ static QDirModel* fileDirModel()
}
static QDirModel* pathDirModel()
{
- static QDirModel* m = CM_NULLPTR;
+ static QDirModel* m = nullptr;
if (!m) {
m = new QDirModel();
m->setFilter(QDir::AllDirs | QDir::Drives | QDir::NoDotAndDotDot);
diff --git a/Source/QtDialog/QCMakeWidgets.h b/Source/QtDialog/QCMakeWidgets.h
index 1ec666ff6..5d2368eab 100644
--- a/Source/QtDialog/QCMakeWidgets.h
+++ b/Source/QtDialog/QCMakeWidgets.h
@@ -3,7 +3,7 @@
#ifndef QCMakeWidgets_h
#define QCMakeWidgets_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <QComboBox>
#include <QCompleter>
@@ -18,7 +18,7 @@ class QCMakeFileEditor : public QLineEdit
{
Q_OBJECT
public:
- QCMakeFileEditor(QWidget* p, const QString& var);
+ QCMakeFileEditor(QWidget* p, QString var);
protected slots:
virtual void chooseFile() = 0;
signals:
@@ -35,7 +35,7 @@ class QCMakePathEditor : public QCMakeFileEditor
{
Q_OBJECT
public:
- QCMakePathEditor(QWidget* p = CM_NULLPTR, const QString& var = QString());
+ QCMakePathEditor(QWidget* p = nullptr, const QString& var = QString());
void chooseFile();
};
@@ -44,8 +44,7 @@ class QCMakeFilePathEditor : public QCMakeFileEditor
{
Q_OBJECT
public:
- QCMakeFilePathEditor(QWidget* p = CM_NULLPTR,
- const QString& var = QString());
+ QCMakeFilePathEditor(QWidget* p = nullptr, const QString& var = QString());
void chooseFile();
};
diff --git a/Source/QtDialog/RegexExplorer.cxx b/Source/QtDialog/RegexExplorer.cxx
index abed70e90..746fd8af2 100644
--- a/Source/QtDialog/RegexExplorer.cxx
+++ b/Source/QtDialog/RegexExplorer.cxx
@@ -8,7 +8,7 @@ RegexExplorer::RegexExplorer(QWidget* p)
{
this->setupUi(this);
- for (int i = 1; i < cmsys::RegularExpression::NSUBEXP; ++i) {
+ for (int i = 1; i < cmsys::RegularExpressionMatch::NSUBEXP; ++i) {
matchNumber->addItem(QString("Match %1").arg(QString::number(i)),
QVariant(i));
}
@@ -20,7 +20,7 @@ void RegexExplorer::setStatusColor(QWidget* widget, bool successful)
QColor color = successful ? QColor(0, 127, 0) : Qt::red;
QPalette palette = widget->palette();
- palette.setColor(QPalette::Foreground, color);
+ palette.setColor(QPalette::WindowText, color);
widget->setPalette(palette);
}
@@ -105,7 +105,7 @@ void RegexExplorer::on_matchNumber_currentIndexChanged(int index)
QVariant itemData = matchNumber->itemData(index);
int idx = itemData.toInt();
- if (idx < 1 || idx >= cmsys::RegularExpression::NSUBEXP) {
+ if (idx < 1 || idx >= cmsys::RegularExpressionMatch::NSUBEXP) {
return;
}
diff --git a/Source/QtDialog/RegexExplorer.h b/Source/QtDialog/RegexExplorer.h
index 867989279..c7dbb76cd 100644
--- a/Source/QtDialog/RegexExplorer.h
+++ b/Source/QtDialog/RegexExplorer.h
@@ -12,7 +12,9 @@
class QString;
class QWidget;
-class RegexExplorer : public QDialog, public Ui::RegexExplorer
+class RegexExplorer
+ : public QDialog
+ , public Ui::RegexExplorer
{
Q_OBJECT
public:
diff --git a/Source/QtDialog/WarningMessagesDialog.h b/Source/QtDialog/WarningMessagesDialog.h
index acb830d85..9b29ad63c 100644
--- a/Source/QtDialog/WarningMessagesDialog.h
+++ b/Source/QtDialog/WarningMessagesDialog.h
@@ -12,7 +12,9 @@
/**
* Dialog window for setting the warning message related options.
*/
-class WarningMessagesDialog : public QDialog, public Ui_MessagesDialog
+class WarningMessagesDialog
+ : public QDialog
+ , public Ui_MessagesDialog
{
Q_OBJECT
diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx
index e96226a4b..a1072948f 100644
--- a/Source/bindexplib.cxx
+++ b/Source/bindexplib.cxx
@@ -8,59 +8,60 @@
-------------------------------------------------------------------------*/
/*
-*----------------------------------------------------------------------
-* Program: dumpexts.exe
-* Author: Gordon Chaffee
-*
-* History: The real functionality of this file was written by
-* Matt Pietrek in 1993 in his pedump utility. I've
-* modified it to dump the externals in a bunch of object
-* files to create a .def file.
-*
-* Notes: Visual C++ puts an underscore before each exported symbol.
-* This file removes them. I don't know if this is a problem
-* this other compilers. If _MSC_VER is defined,
-* the underscore is removed. If not, it isn't. To get a
-* full dump of an object file, use the -f option. This can
-* help determine the something that may be different with a
-* compiler other than Visual C++.
-* ======================================
-* Corrections (Axel 2006-04-04):
-* Conversion to C++. Mostly.
-*
+ *----------------------------------------------------------------------
+ * Program: dumpexts.exe
+ * Author: Gordon Chaffee
+ *
+ * History: The real functionality of this file was written by
+ * Matt Pietrek in 1993 in his pedump utility. I've
+ * modified it to dump the externals in a bunch of object
+ * files to create a .def file.
+ *
+ * Notes: Visual C++ puts an underscore before each exported symbol.
+ * This file removes them. I don't know if this is a problem
+ * this other compilers. If _MSC_VER is defined,
+ * the underscore is removed. If not, it isn't. To get a
+ * full dump of an object file, use the -f option. This can
+ * help determine the something that may be different with a
+ * compiler other than Visual C++.
+ * ======================================
+ * Corrections (Axel 2006-04-04):
+ * Conversion to C++. Mostly.
+ *
* Extension (Axel 2006-03-15)
* As soon as an object file contains an /EXPORT directive (which
* is generated by the compiler when a symbol is declared as
- * declspec(dllexport)) no to-be-exported symbols are printed,
+ * __declspec(dllexport) no to-be-exported symbols are printed,
* as the linker will see these directives, and if those directives
* are present we only export selectively (i.e. we trust the
* programmer).
*
* ======================================
-* ======================================
-* Corrections (Valery Fine 23/02/98):
-*
-* The "(vector) deleting destructor" MUST not be exported
-* To recognize it the following test are introduced:
-* "@@UAEPAXI@Z" scalar deleting dtor
-* "@@QAEPAXI@Z" vector deleting dtor
-* "AEPAXI@Z" vector deleting dtor with thunk adjustor
-* ======================================
-* Corrections (Valery Fine 12/02/97):
-*
-* It created a wrong EXPORTS for the global pointers and constants.
-* The Section Header has been involved to discover the missing information
-* Now the pointers are correctly supplied supplied with "DATA" descriptor
-* the constants with no extra descriptor.
-*
-* Corrections (Valery Fine 16/09/96):
-*
-* It didn't work for C++ code with global variables and class definitons
-* The DumpExternalObject function has been introduced to generate .DEF file
-*
-* Author: Valery Fine 16/09/96 (E-mail: fine@vxcern.cern.ch)
-*----------------------------------------------------------------------
-*/
+ * ======================================
+ * Corrections (Valery Fine 23/02/98):
+ *
+ * The "(vector) deleting destructor" MUST not be exported
+ * To recognize it the following test are introduced:
+ * "@@UAEPAXI@Z" scalar deleting dtor
+ * "@@QAEPAXI@Z" vector deleting dtor
+ * "AEPAXI@Z" vector deleting dtor with thunk adjustor
+ * ======================================
+ * Corrections (Valery Fine 12/02/97):
+ *
+ * It created a wrong EXPORTS for the global pointers and constants.
+ * The Section Header has been involved to discover the missing information
+ * Now the pointers are correctly supplied with "DATA" descriptor
+ * the constants with no extra descriptor.
+ *
+ * Corrections (Valery Fine 16/09/96):
+ *
+ * It didn't work for C++ code with global variables and class definitions
+ * The DumpExternalObject function has been introduced to generate .DEF
+ *file
+ *
+ * Author: Valery Fine 16/09/96 (E-mail: fine@vxcern.cern.ch)
+ *----------------------------------------------------------------------
+ */
#include "bindexplib.h"
#include "cmsys/Encoding.hxx"
@@ -68,8 +69,20 @@
#include <iostream>
#include <windows.h>
+#ifndef IMAGE_FILE_MACHINE_ARM
+# define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
+#endif
+
+#ifndef IMAGE_FILE_MACHINE_THUMB
+# define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian
+#endif
+
#ifndef IMAGE_FILE_MACHINE_ARMNT
-#define IMAGE_FILE_MACHINE_ARMNT 0x01c4
+# define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
+#endif
+
+#ifndef IMAGE_FILE_MACHINE_ARM64
+# define IMAGE_FILE_MACHINE_ARM64 0xaa64 // ARM64 Little-Endian
#endif
typedef struct cmANON_OBJECT_HEADER_BIGOBJ
@@ -176,7 +189,7 @@ public:
{
this->ObjectImageHeader = ih;
this->SymbolTable =
- (SymbolTableType*)((DWORD_PTR) this->ObjectImageHeader +
+ (SymbolTableType*)((DWORD_PTR)this->ObjectImageHeader +
this->ObjectImageHeader->PointerToSymbolTable);
this->SectionHeaders = GetSectionHeaderOffset(this->ObjectImageHeader);
this->SymbolCount = this->ObjectImageHeader->NumberOfSymbols;
@@ -215,10 +228,10 @@ public:
(pSymbolTable->Type == 0x20 || pSymbolTable->Type == 0x0)) {
if (pSymbolTable->StorageClass == IMAGE_SYM_CLASS_EXTERNAL) {
/*
- * The name of the Function entry points
- */
+ * The name of the Function entry points
+ */
if (pSymbolTable->N.Name.Short != 0) {
- symbol = "";
+ symbol.clear();
symbol.insert(0, (const char*)pSymbolTable->N.ShortName, 8);
} else {
symbol = stringTable + pSymbolTable->N.Name.Long;
@@ -270,8 +283,8 @@ public:
}
/*
- * Take into account any aux symbols
- */
+ * Take into account any aux symbols
+ */
i += pSymbolTable->NumberOfAuxSymbols;
pSymbolTable += pSymbolTable->NumberOfAuxSymbols;
pSymbolTable++;
@@ -294,7 +307,6 @@ bool DumpFile(const char* filename, std::set<std::string>& symbols,
HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
- PIMAGE_DOS_HEADER dosHeader;
hFile = CreateFileW(cmsys::Encoding::ToWide(filename).c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
@@ -320,36 +332,42 @@ bool DumpFile(const char* filename, std::set<std::string>& symbols,
return false;
}
- dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
+ const PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
fprintf(stderr, "File is an executable. I don't dump those.\n");
return false;
- }
- /* Does it look like a COFF OBJ file??? */
- else if (((dosHeader->e_magic == IMAGE_FILE_MACHINE_I386) ||
- (dosHeader->e_magic == IMAGE_FILE_MACHINE_AMD64) ||
- (dosHeader->e_magic == IMAGE_FILE_MACHINE_ARMNT)) &&
- (dosHeader->e_sp == 0)) {
- /*
- * The two tests above aren't what they look like. They're
- * really checking for IMAGE_FILE_HEADER.Machine == i386 (0x14C)
- * and IMAGE_FILE_HEADER.SizeOfOptionalHeader == 0;
- */
- DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL> symbolDumper(
- (PIMAGE_FILE_HEADER)lpFileBase, symbols, dataSymbols,
- (dosHeader->e_magic == IMAGE_FILE_MACHINE_I386));
- symbolDumper.DumpObjFile();
} else {
- // check for /bigobj format
- cmANON_OBJECT_HEADER_BIGOBJ* h = (cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase;
- if (h->Sig1 == 0x0 && h->Sig2 == 0xffff) {
- DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX> symbolDumper(
- (cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase, symbols, dataSymbols,
- (h->Machine == IMAGE_FILE_MACHINE_I386));
+ const PIMAGE_FILE_HEADER imageHeader = (PIMAGE_FILE_HEADER)lpFileBase;
+ /* Does it look like a COFF OBJ file??? */
+ if (((imageHeader->Machine == IMAGE_FILE_MACHINE_I386) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_AMD64) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_ARM) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_ARMNT) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_ARM64)) &&
+ (imageHeader->Characteristics == 0)) {
+ /*
+ * The tests above are checking for IMAGE_FILE_HEADER.Machine
+ * if it contains supported machine formats (currently ARM and x86)
+ * and IMAGE_FILE_HEADER.Characteristics == 0 indicating that
+ * this is not linked COFF OBJ file;
+ */
+ DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL> symbolDumper(
+ (PIMAGE_FILE_HEADER)lpFileBase, symbols, dataSymbols,
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_I386));
symbolDumper.DumpObjFile();
} else {
- printf("unrecognized file format in '%s'\n", filename);
- return false;
+ // check for /bigobj format
+ cmANON_OBJECT_HEADER_BIGOBJ* h =
+ (cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase;
+ if (h->Sig1 == 0x0 && h->Sig2 == 0xffff) {
+ DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX>
+ symbolDumper((cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase, symbols,
+ dataSymbols, (h->Machine == IMAGE_FILE_MACHINE_I386));
+ symbolDumper.DumpObjFile();
+ } else {
+ printf("unrecognized file format in '%s'\n", filename);
+ return false;
+ }
}
}
UnmapViewOfFile(lpFileBase);
@@ -372,7 +390,7 @@ bool bindexplib::AddDefinitionFile(const char* filename)
}
std::string str;
while (std::getline(infile, str)) {
- // skip the LIBRAY and EXPORTS lines (if any)
+ // skip the LIBRARY and EXPORTS lines (if any)
if ((str.compare(0, 7, "LIBRARY") == 0) ||
(str.compare(0, 7, "EXPORTS") == 0)) {
continue;
@@ -394,12 +412,10 @@ bool bindexplib::AddDefinitionFile(const char* filename)
void bindexplib::WriteFile(FILE* file)
{
fprintf(file, "EXPORTS \n");
- for (std::set<std::string>::const_iterator i = this->DataSymbols.begin();
- i != this->DataSymbols.end(); ++i) {
- fprintf(file, "\t%s \t DATA\n", i->c_str());
+ for (std::string const& ds : this->DataSymbols) {
+ fprintf(file, "\t%s \t DATA\n", ds.c_str());
}
- for (std::set<std::string>::const_iterator i = this->Symbols.begin();
- i != this->Symbols.end(); ++i) {
- fprintf(file, "\t%s\n", i->c_str());
+ for (std::string const& s : this->Symbols) {
+ fprintf(file, "\t%s\n", s.c_str());
}
}
diff --git a/Source/bindexplib.h b/Source/bindexplib.h
index bc904e9f8..3e22ac78e 100644
--- a/Source/bindexplib.h
+++ b/Source/bindexplib.h
@@ -3,7 +3,7 @@
#ifndef bindexplib_h
#define bindexplib_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <stdio.h>
diff --git a/Source/cmAddCompileOptionsCommand.cxx b/Source/cmAddCompileOptionsCommand.cxx
index 21a8012d8..412fb38a2 100644
--- a/Source/cmAddCompileOptionsCommand.cxx
+++ b/Source/cmAddCompileOptionsCommand.cxx
@@ -13,9 +13,8 @@ bool cmAddCompileOptionsCommand::InitialPass(
return true;
}
- for (std::vector<std::string>::const_iterator i = args.begin();
- i != args.end(); ++i) {
- this->Makefile->AddCompileOption(i->c_str());
+ for (std::string const& i : args) {
+ this->Makefile->AddCompileOption(i);
}
return true;
}
diff --git a/Source/cmAddCompileOptionsCommand.h b/Source/cmAddCompileOptionsCommand.h
index 297f901db..3d53d097b 100644
--- a/Source/cmAddCompileOptionsCommand.h
+++ b/Source/cmAddCompileOptionsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmAddCompileOptionsCommand_h
#define cmAddCompileOptionsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -18,14 +18,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddCompileOptionsCommand; }
+ cmCommand* Clone() override { return new cmAddCompileOptionsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx
index b5e7c9ea9..0be3c85e1 100644
--- a/Source/cmAddCustomCommandCommand.cxx
+++ b/Source/cmAddCustomCommandCommand.cxx
@@ -3,16 +3,18 @@
#include "cmAddCustomCommandCommand.h"
#include <sstream>
+#include <unordered_set>
+#include <utility>
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmSourceFile.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -29,9 +31,9 @@ bool cmAddCustomCommandCommand::InitialPass(
return false;
}
- std::string source, target, main_dependency, working, depfile;
+ std::string source, target, main_dependency, working, depfile, job_pool;
std::string comment_buffer;
- const char* comment = CM_NULLPTR;
+ const char* comment = nullptr;
std::vector<std::string> depends, outputs, output, byproducts;
bool verbatim = false;
bool append = false;
@@ -63,64 +65,116 @@ bool cmAddCustomCommandCommand::InitialPass(
doing_comment,
doing_working_directory,
doing_depfile,
+ doing_job_pool,
doing_nothing
};
tdoing doing = doing_nothing;
- for (unsigned int j = 0; j < args.size(); ++j) {
- std::string const& copy = args[j];
+#define MAKE_STATIC_KEYWORD(KEYWORD) \
+ static const std::string key##KEYWORD = #KEYWORD
+ MAKE_STATIC_KEYWORD(APPEND);
+ MAKE_STATIC_KEYWORD(ARGS);
+ MAKE_STATIC_KEYWORD(BYPRODUCTS);
+ MAKE_STATIC_KEYWORD(COMMAND);
+ MAKE_STATIC_KEYWORD(COMMAND_EXPAND_LISTS);
+ MAKE_STATIC_KEYWORD(COMMENT);
+ MAKE_STATIC_KEYWORD(DEPENDS);
+ MAKE_STATIC_KEYWORD(DEPFILE);
+ MAKE_STATIC_KEYWORD(IMPLICIT_DEPENDS);
+ MAKE_STATIC_KEYWORD(JOB_POOL);
+ MAKE_STATIC_KEYWORD(MAIN_DEPENDENCY);
+ MAKE_STATIC_KEYWORD(OUTPUT);
+ MAKE_STATIC_KEYWORD(OUTPUTS);
+ MAKE_STATIC_KEYWORD(POST_BUILD);
+ MAKE_STATIC_KEYWORD(PRE_BUILD);
+ MAKE_STATIC_KEYWORD(PRE_LINK);
+ MAKE_STATIC_KEYWORD(SOURCE);
+ MAKE_STATIC_KEYWORD(TARGET);
+ MAKE_STATIC_KEYWORD(USES_TERMINAL);
+ MAKE_STATIC_KEYWORD(VERBATIM);
+ MAKE_STATIC_KEYWORD(WORKING_DIRECTORY);
+#undef MAKE_STATIC_KEYWORD
+ static std::unordered_set<std::string> keywords;
+ if (keywords.empty()) {
+ keywords.insert(keyAPPEND);
+ keywords.insert(keyARGS);
+ keywords.insert(keyBYPRODUCTS);
+ keywords.insert(keyCOMMAND);
+ keywords.insert(keyCOMMAND_EXPAND_LISTS);
+ keywords.insert(keyCOMMENT);
+ keywords.insert(keyDEPENDS);
+ keywords.insert(keyDEPFILE);
+ keywords.insert(keyIMPLICIT_DEPENDS);
+ keywords.insert(keyJOB_POOL);
+ keywords.insert(keyMAIN_DEPENDENCY);
+ keywords.insert(keyOUTPUT);
+ keywords.insert(keyOUTPUTS);
+ keywords.insert(keyPOST_BUILD);
+ keywords.insert(keyPRE_BUILD);
+ keywords.insert(keyPRE_LINK);
+ keywords.insert(keySOURCE);
+ keywords.insert(keyTARGET);
+ keywords.insert(keyUSES_TERMINAL);
+ keywords.insert(keyVERBATIM);
+ keywords.insert(keyWORKING_DIRECTORY);
+ }
- if (copy == "SOURCE") {
- doing = doing_source;
- } else if (copy == "COMMAND") {
- doing = doing_command;
+ for (std::string const& copy : args) {
+ if (keywords.count(copy)) {
+ if (copy == keySOURCE) {
+ doing = doing_source;
+ } else if (copy == keyCOMMAND) {
+ 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 == "USES_TERMINAL") {
- uses_terminal = true;
- } else if (copy == "COMMAND_EXPAND_LISTS") {
- command_expand_lists = 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 == "BYPRODUCTS") {
- doing = doing_byproducts;
- } 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 if (copy == "DEPFILE") {
- doing = doing_depfile;
- if (this->Makefile->GetGlobalGenerator()->GetName() != "Ninja") {
- this->SetError("Option DEPFILE not supported by " +
- this->Makefile->GetGlobalGenerator()->GetName());
- return false;
+ // Save the current command before starting the next command.
+ if (!currentLine.empty()) {
+ commandLines.push_back(currentLine);
+ currentLine.clear();
+ }
+ } else if (copy == keyPRE_BUILD) {
+ cctype = cmTarget::PRE_BUILD;
+ } else if (copy == keyPRE_LINK) {
+ cctype = cmTarget::PRE_LINK;
+ } else if (copy == keyPOST_BUILD) {
+ cctype = cmTarget::POST_BUILD;
+ } else if (copy == keyVERBATIM) {
+ verbatim = true;
+ } else if (copy == keyAPPEND) {
+ append = true;
+ } else if (copy == keyUSES_TERMINAL) {
+ uses_terminal = true;
+ } else if (copy == keyCOMMAND_EXPAND_LISTS) {
+ command_expand_lists = true;
+ } else if (copy == keyTARGET) {
+ doing = doing_target;
+ } else if (copy == keyARGS) {
+ // Ignore this old keyword.
+ } else if (copy == keyDEPENDS) {
+ doing = doing_depends;
+ } else if (copy == keyOUTPUTS) {
+ doing = doing_outputs;
+ } else if (copy == keyOUTPUT) {
+ doing = doing_output;
+ } else if (copy == keyBYPRODUCTS) {
+ doing = doing_byproducts;
+ } else if (copy == keyWORKING_DIRECTORY) {
+ doing = doing_working_directory;
+ } else if (copy == keyMAIN_DEPENDENCY) {
+ doing = doing_main_dependency;
+ } else if (copy == keyIMPLICIT_DEPENDS) {
+ doing = doing_implicit_depends_lang;
+ } else if (copy == keyCOMMENT) {
+ doing = doing_comment;
+ } else if (copy == keyDEPFILE) {
+ doing = doing_depfile;
+ if (this->Makefile->GetGlobalGenerator()->GetName() != "Ninja") {
+ this->SetError("Option DEPFILE not supported by " +
+ this->Makefile->GetGlobalGenerator()->GetName());
+ return false;
+ }
+ } else if (copy == keyJOB_POOL) {
+ doing = doing_job_pool;
}
} else {
std::string filename;
@@ -128,7 +182,7 @@ bool cmAddCustomCommandCommand::InitialPass(
case doing_output:
case doing_outputs:
case doing_byproducts:
- if (!cmSystemTools::FileIsFullPath(copy.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(copy)) {
// 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
@@ -155,13 +209,16 @@ bool cmAddCustomCommandCommand::InitialPass(
break;
}
- if (cmSystemTools::FileIsFullPath(filename.c_str())) {
+ if (cmSystemTools::FileIsFullPath(filename)) {
filename = cmSystemTools::CollapseFullPath(filename);
}
switch (doing) {
case doing_depfile:
depfile = copy;
break;
+ case doing_job_pool:
+ job_pool = copy;
+ break;
case doing_working_directory:
working = copy;
break;
@@ -186,9 +243,7 @@ bool cmAddCustomCommandCommand::InitialPass(
depends.push_back(dep);
// Add the implicit dependency language and file.
- cmCustomCommand::ImplicitDependsPair entry(implicit_depends_lang,
- dep);
- implicit_depends.push_back(entry);
+ implicit_depends.emplace_back(implicit_depends_lang, dep);
// Switch back to looking for a language.
doing = doing_implicit_depends_lang;
@@ -202,7 +257,7 @@ bool cmAddCustomCommandCommand::InitialPass(
case doing_depends: {
std::string dep = copy;
cmSystemTools::ConvertToUnixSlashes(dep);
- depends.push_back(dep);
+ depends.push_back(std::move(dep));
} break;
case doing_outputs:
outputs.push_back(filename);
@@ -271,10 +326,9 @@ bool cmAddCustomCommandCommand::InitialPass(
return false;
}
- // Convert working directory to a full path.
- if (!working.empty()) {
- const char* build_dir = this->Makefile->GetCurrentBinaryDirectory();
- working = cmSystemTools::CollapseFullPath(working, build_dir);
+ if (uses_terminal && !job_pool.empty()) {
+ this->SetError("JOB_POOL is shadowed by USES_TERMINAL.");
+ return false;
}
// Choose which mode of the command to use.
@@ -284,14 +338,14 @@ bool cmAddCustomCommandCommand::InitialPass(
std::vector<std::string> no_depends;
this->Makefile->AddCustomCommandToTarget(
target, byproducts, no_depends, commandLines, cctype, comment,
- working.c_str(), escapeOldStyle, uses_terminal, depfile,
+ working.c_str(), escapeOldStyle, uses_terminal, depfile, job_pool,
command_expand_lists);
} else if (target.empty()) {
// Target is empty, use the output.
this->Makefile->AddCustomCommandToOutput(
output, byproducts, depends, main_dependency, commandLines, comment,
working.c_str(), false, escapeOldStyle, uses_terminal,
- command_expand_lists, depfile);
+ command_expand_lists, depfile, job_pool);
// Add implicit dependency scanning requests if any were given.
if (!implicit_depends.empty()) {
@@ -320,7 +374,7 @@ bool cmAddCustomCommandCommand::InitialPass(
} else {
bool issueMessage = true;
std::ostringstream e;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0050)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0050) << "\n";
@@ -331,7 +385,7 @@ bool cmAddCustomCommandCommand::InitialPass(
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
break;
}
@@ -339,7 +393,7 @@ bool cmAddCustomCommandCommand::InitialPass(
e << "The SOURCE signatures of add_custom_command are no longer "
"supported.";
this->Makefile->IssueMessage(messageType, e.str());
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
@@ -355,12 +409,11 @@ bool cmAddCustomCommandCommand::InitialPass(
bool cmAddCustomCommandCommand::CheckOutputs(
const std::vector<std::string>& outputs)
{
- for (std::vector<std::string>::const_iterator o = outputs.begin();
- o != outputs.end(); ++o) {
+ for (std::string const& o : outputs) {
// 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 +
+ if (!this->Makefile->CanIWriteThisFile(o)) {
+ std::string e = "attempted to have a file \"" + o +
"\" in a source directory as an output of custom command.";
this->SetError(e);
cmSystemTools::SetFatalErrorOccured();
@@ -368,10 +421,10 @@ bool cmAddCustomCommandCommand::CheckOutputs(
}
// Make sure the output file name has no invalid characters.
- std::string::size_type pos = o->find_first_of("#<>");
+ std::string::size_type pos = o.find_first_of("#<>");
if (pos != std::string::npos) {
std::ostringstream msg;
- msg << "called with OUTPUT containing a \"" << (*o)[pos]
+ msg << "called with OUTPUT containing a \"" << o[pos]
<< "\". This character is not allowed.";
this->SetError(msg.str());
return false;
diff --git a/Source/cmAddCustomCommandCommand.h b/Source/cmAddCustomCommandCommand.h
index c3a91b2a3..6af4f1055 100644
--- a/Source/cmAddCustomCommandCommand.h
+++ b/Source/cmAddCustomCommandCommand.h
@@ -3,7 +3,7 @@
#ifndef cmAddCustomCommandCommand_h
#define cmAddCustomCommandCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddCustomCommandCommand; }
+ cmCommand* Clone() override { return new cmAddCustomCommandCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
bool CheckOutputs(const std::vector<std::string>& outputs);
diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx
index 87e114780..0ecd5f5a2 100644
--- a/Source/cmAddCustomTargetCommand.cxx
+++ b/Source/cmAddCustomTargetCommand.cxx
@@ -3,15 +3,16 @@
#include "cmAddCustomTargetCommand.h"
#include <sstream>
+#include <utility>
#include "cmCustomCommandLines.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
-#include "cmPolicies.h"
+#include "cmMessageType.h"
+#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -49,8 +50,9 @@ bool cmAddCustomTargetCommand::InitialPass(
bool uses_terminal = false;
bool command_expand_lists = false;
std::string comment_buffer;
- const char* comment = CM_NULLPTR;
+ const char* comment = nullptr;
std::vector<std::string> sources;
+ std::string job_pool;
// Keep track of parser state.
enum tdoing
@@ -61,6 +63,7 @@ bool cmAddCustomTargetCommand::InitialPass(
doing_working_directory,
doing_comment,
doing_source,
+ doing_job_pool,
doing_nothing
};
tdoing doing = doing_command;
@@ -96,6 +99,8 @@ bool cmAddCustomTargetCommand::InitialPass(
command_expand_lists = true;
} else if (copy == "COMMENT") {
doing = doing_comment;
+ } else if (copy == "JOB_POOL") {
+ doing = doing_job_pool;
} else if (copy == "COMMAND") {
doing = doing_command;
@@ -116,7 +121,7 @@ bool cmAddCustomTargetCommand::InitialPass(
break;
case doing_byproducts: {
std::string filename;
- if (!cmSystemTools::FileIsFullPath(copy.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(copy)) {
filename = this->Makefile->GetCurrentBinaryDirectory();
filename += "/";
}
@@ -127,7 +132,7 @@ bool cmAddCustomTargetCommand::InitialPass(
case doing_depends: {
std::string dep = copy;
cmSystemTools::ConvertToUnixSlashes(dep);
- depends.push_back(dep);
+ depends.push_back(std::move(dep));
} break;
case doing_comment:
comment_buffer = copy;
@@ -136,6 +141,9 @@ bool cmAddCustomTargetCommand::InitialPass(
case doing_source:
sources.push_back(copy);
break;
+ case doing_job_pool:
+ job_pool = copy;
+ break;
default:
this->SetError("Wrong syntax. Unknown type of argument.");
return false;
@@ -160,35 +168,9 @@ bool cmAddCustomTargetCommand::InitialPass(
if (nameOk) {
nameOk = targetName.find(':') == std::string::npos;
}
- if (!nameOk) {
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
- std::ostringstream e;
- bool issueMessage = false;
- switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) {
- case cmPolicies::WARN:
- e << cmPolicies::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) {
- /* clang-format off */
- e << "The target name \"" << targetName <<
- "\" is reserved or not valid for certain "
- "CMake features, such as generator expressions, and may result "
- "in undefined behavior.";
- /* clang-format on */
- this->Makefile->IssueMessage(messageType, e.str());
-
- if (messageType == cmake::FATAL_ERROR) {
- return false;
- }
- }
+ if (!nameOk &&
+ !this->Makefile->CheckCMP0037(targetName, cmStateEnums::UTILITY)) {
+ return false;
}
// Store the last command line finished.
@@ -206,38 +188,36 @@ bool cmAddCustomTargetCommand::InitialPass(
}
}
- // Convert working directory to a full path.
- if (!working_directory.empty()) {
- const char* build_dir = this->Makefile->GetCurrentBinaryDirectory();
- working_directory =
- cmSystemTools::CollapseFullPath(working_directory, build_dir);
- }
-
if (commandLines.empty() && !byproducts.empty()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"BYPRODUCTS may not be specified without any COMMAND");
return true;
}
if (commandLines.empty() && uses_terminal) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"USES_TERMINAL may not be specified without any COMMAND");
return true;
}
if (commandLines.empty() && command_expand_lists) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"COMMAND_EXPAND_LISTS may not be specified without any COMMAND");
return true;
}
+ if (uses_terminal && !job_pool.empty()) {
+ this->SetError("JOB_POOL is shadowed by USES_TERMINAL.");
+ return false;
+ }
+
// Add the utility target to the makefile.
bool escapeOldStyle = !verbatim;
cmTarget* target = this->Makefile->AddUtilityCommand(
- targetName, excludeFromAll, working_directory.c_str(), byproducts, depends,
- commandLines, escapeOldStyle, comment, uses_terminal,
- command_expand_lists);
+ targetName, cmMakefile::TargetOrigin::Project, excludeFromAll,
+ working_directory.c_str(), byproducts, depends, commandLines,
+ escapeOldStyle, comment, uses_terminal, command_expand_lists, job_pool);
// Add additional user-specified source files to the target.
target->AddSources(sources);
diff --git a/Source/cmAddCustomTargetCommand.h b/Source/cmAddCustomTargetCommand.h
index 7229c2779..1a55116e3 100644
--- a/Source/cmAddCustomTargetCommand.h
+++ b/Source/cmAddCustomTargetCommand.h
@@ -3,7 +3,7 @@
#ifndef cmAddCustomTargetCommand_h
#define cmAddCustomTargetCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddCustomTargetCommand; }
+ cmCommand* Clone() override { return new cmAddCustomTargetCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmAddDefinitionsCommand.cxx b/Source/cmAddDefinitionsCommand.cxx
index 9e0607c60..62e57a309 100644
--- a/Source/cmAddDefinitionsCommand.cxx
+++ b/Source/cmAddDefinitionsCommand.cxx
@@ -15,9 +15,8 @@ bool cmAddDefinitionsCommand::InitialPass(std::vector<std::string> const& args,
return true;
}
- for (std::vector<std::string>::const_iterator i = args.begin();
- i != args.end(); ++i) {
- this->Makefile->AddDefineFlag(i->c_str());
+ for (std::string const& i : args) {
+ this->Makefile->AddDefineFlag(i);
}
return true;
}
diff --git a/Source/cmAddDefinitionsCommand.h b/Source/cmAddDefinitionsCommand.h
index abf5a5964..7b75638cb 100644
--- a/Source/cmAddDefinitionsCommand.h
+++ b/Source/cmAddDefinitionsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmAddDefinitionsCommand_h
#define cmAddDefinitionsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddDefinitionsCommand; }
+ cmCommand* Clone() override { return new cmAddDefinitionsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx
index a73b57e82..4956a471c 100644
--- a/Source/cmAddDependenciesCommand.cxx
+++ b/Source/cmAddDependenciesCommand.cxx
@@ -5,8 +5,9 @@
#include <sstream>
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmRange.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -24,13 +25,13 @@ bool cmAddDependenciesCommand::InitialPass(
std::ostringstream e;
e << "Cannot add target-level dependencies to alias target \""
<< target_name << "\".\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
if (cmTarget* target = this->Makefile->FindTargetToUse(target_name)) {
- std::vector<std::string>::const_iterator s = args.begin();
- ++s; // skip over target_name
- for (; s != args.end(); ++s) {
- target->AddUtility(*s, this->Makefile);
+
+ // skip over target_name
+ for (std::string const& arg : cmMakeRange(args).advance(1)) {
+ target->AddUtility(arg, this->Makefile);
}
} else {
std::ostringstream e;
@@ -40,7 +41,7 @@ bool cmAddDependenciesCommand::InitialPass(
<< "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());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
return true;
diff --git a/Source/cmAddDependenciesCommand.h b/Source/cmAddDependenciesCommand.h
index c7328d63e..e10df7109 100644
--- a/Source/cmAddDependenciesCommand.h
+++ b/Source/cmAddDependenciesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmDependenciessCommand_h
#define cmDependenciessCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddDependenciesCommand; }
+ cmCommand* Clone() override { return new cmAddDependenciesCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index 1d0376fe0..5685fdf4b 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -7,10 +7,8 @@
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
-#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -18,7 +16,7 @@ class cmExecutionStatus;
bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
- if (args.size() < 2) {
+ if (args.empty()) {
this->SetError("called with incorrect number of arguments");
return false;
}
@@ -63,35 +61,9 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
if (nameOk && !importTarget && !isAlias) {
nameOk = exename.find(':') == std::string::npos;
}
- if (!nameOk) {
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
- std::ostringstream e;
- bool issueMessage = false;
- switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) {
- case cmPolicies::WARN:
- e << cmPolicies::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) {
- /* clang-format off */
- e << "The target name \"" << exename <<
- "\" is reserved or not valid for certain "
- "CMake features, such as generator expressions, and may result "
- "in undefined behavior.";
- /* clang-format on */
- this->Makefile->IssueMessage(messageType, e.str());
-
- if (messageType == cmake::FATAL_ERROR) {
- return false;
- }
- }
+ if (!nameOk &&
+ !this->Makefile->CheckCMP0037(exename, cmStateEnums::EXECUTABLE)) {
+ return false;
}
// Special modifiers are not allowed with IMPORTED signature.
@@ -127,7 +99,7 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
- const char* aliasedName = s->c_str();
+ std::string const& aliasedName = *s;
if (this->Makefile->IsAlias(aliasedName)) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << exename << "\" because target \""
@@ -140,8 +112,7 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
if (!aliasedTarget) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << exename << "\" because target \""
- << aliasedName << "\" does not already "
- "exist.";
+ << aliasedName << "\" does not already exist.";
this->SetError(e.str());
return false;
}
@@ -149,15 +120,15 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
if (type != cmStateEnums::EXECUTABLE) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << exename << "\" because target \""
- << aliasedName << "\" is not an "
- "executable.";
+ << aliasedName << "\" is not an executable.";
this->SetError(e.str());
return false;
}
- if (aliasedTarget->IsImported()) {
+ if (aliasedTarget->IsImported() &&
+ !aliasedTarget->IsImportedGloballyVisible()) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << exename << "\" because target \""
- << aliasedName << "\" is IMPORTED.";
+ << aliasedName << "\" is imported but not globally visible.";
this->SetError(e.str());
return false;
}
@@ -191,15 +162,9 @@ bool cmAddExecutableCommand::InitialPass(std::vector<std::string> const& args,
}
}
- 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);
+ this->Makefile->AddExecutable(exename, srclists, excludeFromAll);
if (use_win32) {
tgt->SetProperty("WIN32_EXECUTABLE", "ON");
}
diff --git a/Source/cmAddExecutableCommand.h b/Source/cmAddExecutableCommand.h
index 8100da185..bdf607d8d 100644
--- a/Source/cmAddExecutableCommand.h
+++ b/Source/cmAddExecutableCommand.h
@@ -3,7 +3,7 @@
#ifndef cmExecutablesCommand_h
#define cmExecutablesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddExecutableCommand; }
+ cmCommand* Clone() override { return new cmAddExecutableCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index ebf17632a..ad12e89b9 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -4,15 +4,15 @@
#include <sstream>
+#include "cmAlgorithms.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
-#include "cmPolicies.h"
+#include "cmMessageType.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -175,35 +175,8 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
if (nameOk && !importTarget && !isAlias) {
nameOk = libName.find(':') == std::string::npos;
}
- if (!nameOk) {
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
- std::ostringstream e;
- bool issueMessage = false;
- switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0037)) {
- case cmPolicies::WARN:
- if (type != cmStateEnums::INTERFACE_LIBRARY) {
- e << cmPolicies::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 (!nameOk && !this->Makefile->CheckCMP0037(libName, type)) {
+ return false;
}
if (isAlias) {
@@ -226,7 +199,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
- const char* aliasedName = s->c_str();
+ std::string const& aliasedName = *s;
if (this->Makefile->IsAlias(aliasedName)) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << libName << "\" because target \""
@@ -239,8 +212,9 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
if (!aliasedTarget) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << libName << "\" because target \""
- << aliasedName << "\" does not already "
- "exist.";
+ << aliasedName
+ << "\" does not already "
+ "exist.";
this->SetError(e.str());
return false;
}
@@ -249,17 +223,20 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
aliasedType != cmStateEnums::STATIC_LIBRARY &&
aliasedType != cmStateEnums::MODULE_LIBRARY &&
aliasedType != cmStateEnums::OBJECT_LIBRARY &&
- aliasedType != cmStateEnums::INTERFACE_LIBRARY) {
+ aliasedType != cmStateEnums::INTERFACE_LIBRARY &&
+ !(aliasedType == cmStateEnums::UNKNOWN_LIBRARY &&
+ aliasedTarget->IsImported())) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << libName << "\" because target \""
<< aliasedName << "\" is not a library.";
this->SetError(e.str());
return false;
}
- if (aliasedTarget->IsImported()) {
+ if (aliasedTarget->IsImported() &&
+ !aliasedTarget->IsImportedGloballyVisible()) {
std::ostringstream e;
e << "cannot create ALIAS target \"" << libName << "\" because target \""
- << aliasedName << "\" is IMPORTED.";
+ << aliasedName << "\" is imported but not globally visible.";
this->SetError(e.str());
return false;
}
@@ -285,7 +262,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
<< (type == cmStateEnums::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());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
type = cmStateEnums::STATIC_LIBRARY;
}
@@ -301,7 +278,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
if (!this->Makefile->GetGlobalGenerator()->HasKnownObjectFileLocation(
&reason)) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"The OBJECT library type may not be used for IMPORTED libraries" +
reason + ".");
return true;
@@ -333,7 +310,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
// A non-imported target may not have UNKNOWN type.
if (type == cmStateEnums::UNKNOWN_LIBRARY) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"The UNKNOWN library type may be used only for IMPORTED libraries.");
return true;
}
@@ -362,15 +339,7 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& args,
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");
- }
-
- srclists.insert(srclists.end(), s, args.end());
+ cmAppend(srclists, s, args.end());
this->Makefile->AddLibrary(libName, type, srclists, excludeFromAll);
diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h
index df49fae93..aa212611d 100644
--- a/Source/cmAddLibraryCommand.h
+++ b/Source/cmAddLibraryCommand.h
@@ -3,7 +3,7 @@
#ifndef cmLibrarysCommand_h
#define cmLibrarysCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddLibraryCommand; }
+ cmCommand* Clone() override { return new cmAddLibraryCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmAddSubDirectoryCommand.cxx b/Source/cmAddSubDirectoryCommand.cxx
index 1727ca56f..7947188a5 100644
--- a/Source/cmAddSubDirectoryCommand.cxx
+++ b/Source/cmAddSubDirectoryCommand.cxx
@@ -6,6 +6,7 @@
#include <string.h>
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
class cmExecutionStatus;
@@ -20,21 +21,19 @@ bool cmAddSubDirectoryCommand::InitialPass(
}
// store the binpath
- std::string const& srcArg = args[0];
+ std::string const& srcArg = args.front();
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") {
+ for (std::string const& arg : cmMakeRange(args).advance(1)) {
+ if (arg == "EXCLUDE_FROM_ALL") {
excludeFromAll = true;
continue;
}
if (binArg.empty()) {
- binArg = *i;
+ binArg = arg;
} else {
this->SetError("called with incorrect number of arguments");
return false;
@@ -44,7 +43,7 @@ bool cmAddSubDirectoryCommand::InitialPass(
// 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())) {
+ if (cmSystemTools::FileIsFullPath(srcArg)) {
srcPath = srcArg;
} else {
srcPath = this->Makefile->GetCurrentSourceDirectory();
@@ -80,21 +79,21 @@ bool cmAddSubDirectoryCommand::InitialPass(
// Remove the CurrentDirectory from the srcPath and replace it
// with the CurrentOutputDirectory.
- const char* src = this->Makefile->GetCurrentSourceDirectory();
- const char* bin = this->Makefile->GetCurrentBinaryDirectory();
- size_t srcLen = strlen(src);
- size_t binLen = strlen(bin);
- if (srcLen > 0 && src[srcLen - 1] == '/') {
+ const std::string& src = this->Makefile->GetCurrentSourceDirectory();
+ const std::string& bin = this->Makefile->GetCurrentBinaryDirectory();
+ size_t srcLen = src.length();
+ size_t binLen = bin.length();
+ if (srcLen > 0 && src.back() == '/') {
--srcLen;
}
- if (binLen > 0 && bin[binLen - 1] == '/') {
+ if (binLen > 0 && bin.back() == '/') {
--binLen;
}
- binPath = std::string(bin, binLen) + srcPath.substr(srcLen);
+ binPath = bin.substr(0, 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())) {
+ if (cmSystemTools::FileIsFullPath(binArg)) {
binPath = binArg;
} else {
binPath = this->Makefile->GetCurrentBinaryDirectory();
diff --git a/Source/cmAddSubDirectoryCommand.h b/Source/cmAddSubDirectoryCommand.h
index 0e71ffd85..0ea442329 100644
--- a/Source/cmAddSubDirectoryCommand.h
+++ b/Source/cmAddSubDirectoryCommand.h
@@ -3,7 +3,7 @@
#ifndef cmAddSubDirectoryCommand_h
#define cmAddSubDirectoryCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddSubDirectoryCommand; }
+ cmCommand* Clone() override { return new cmAddSubDirectoryCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmAddTestCommand.cxx b/Source/cmAddTestCommand.cxx
index 3a3afdb05..bf28702ce 100644
--- a/Source/cmAddTestCommand.cxx
+++ b/Source/cmAddTestCommand.cxx
@@ -27,8 +27,7 @@ bool cmAddTestCommand::InitialPass(std::vector<std::string> const& args,
}
// Collect the command with arguments.
- std::vector<std::string> command;
- command.insert(command.end(), args.begin() + 1, args.end());
+ std::vector<std::string> command(args.begin() + 1, args.end());
// Create the test but add a generator only the first time it is
// seen. This preserves behavior from before test generators.
diff --git a/Source/cmAddTestCommand.h b/Source/cmAddTestCommand.h
index a098a03f1..bea3f3d5d 100644
--- a/Source/cmAddTestCommand.h
+++ b/Source/cmAddTestCommand.h
@@ -3,7 +3,7 @@
#ifndef cmAddTestCommand_h
#define cmAddTestCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAddTestCommand; }
+ cmCommand* Clone() override { return new cmAddTestCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
bool HandleNameMode(std::vector<std::string> const& args);
diff --git a/Source/cmAlgorithms.h b/Source/cmAlgorithms.h
index 4adfe2328..d1e32b0d4 100644
--- a/Source/cmAlgorithms.h
+++ b/Source/cmAlgorithms.h
@@ -5,13 +5,17 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmRange.h"
+
#include "cm_kwiml.h"
#include <algorithm>
#include <functional>
#include <iterator>
+#include <memory>
#include <sstream>
#include <string.h>
#include <string>
+#include <unordered_set>
#include <utility>
#include <vector>
@@ -42,22 +46,6 @@ inline bool cmHasLiteralSuffixImpl(const char* str1, const char* str2,
}
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(const T& str1, const char (&str2)[N])
{
return cmHasLiteralPrefixImpl(str1, str2, N - 1);
@@ -75,8 +63,8 @@ struct cmStrCmp
: m_test(test)
{
}
- cmStrCmp(const std::string& test)
- : m_test(test)
+ cmStrCmp(std::string test)
+ : m_test(std::move(test))
{
}
@@ -119,7 +107,7 @@ struct cmIsPair
};
template <typename K, typename V>
-struct cmIsPair<std::pair<K, V> >
+struct cmIsPair<std::pair<K, V>>
{
enum
{
@@ -170,62 +158,29 @@ private:
};
}
-template <typename const_iterator_>
-struct cmRange
-{
- typedef const_iterator_ const_iterator;
- typedef typename std::iterator_traits<const_iterator>::value_type value_type;
- typedef typename std::iterator_traits<const_iterator>::difference_type
- difference_type;
- cmRange(const_iterator begin_, const_iterator end_)
- : Begin(begin_)
- , End(end_)
- {
- }
- const_iterator begin() const { return Begin; }
- const_iterator end() const { return End; }
- bool empty() const { return std::distance(Begin, End) == 0; }
- difference_type size() const { return std::distance(Begin, End); }
- cmRange& advance(KWIML_INT_intptr_t amount)
- {
- std::advance(Begin, amount);
- return *this;
- }
-
- cmRange& retreat(KWIML_INT_intptr_t amount)
- {
- std::advance(End, -amount);
- return *this;
- }
-
-private:
- const_iterator Begin;
- const_iterator End;
-};
-
typedef cmRange<std::vector<std::string>::const_iterator> cmStringRange;
class cmListFileBacktrace;
typedef cmRange<std::vector<cmListFileBacktrace>::const_iterator>
cmBacktraceRange;
-template <typename Iter1, typename Iter2>
-cmRange<Iter1> cmMakeRange(Iter1 begin, Iter2 end)
+template <typename Range>
+void cmDeleteAll(Range const& r)
{
- return cmRange<Iter1>(begin, end);
+ std::for_each(r.begin(), r.end(),
+ ContainerAlgorithms::DefaultDeleter<Range>());
}
-template <typename Range>
-cmRange<typename Range::const_iterator> cmMakeRange(Range const& range)
+template <typename T, typename Range>
+void cmAppend(std::vector<T>& v, Range const& r)
{
- return cmRange<typename Range::const_iterator>(range.begin(), range.end());
+ v.insert(v.end(), r.begin(), r.end());
}
-template <typename Range>
-void cmDeleteAll(Range const& r)
+template <typename T, typename InputIt>
+void cmAppend(std::vector<T>& v, InputIt first, InputIt last)
{
- std::for_each(r.begin(), r.end(),
- ContainerAlgorithms::DefaultDeleter<Range>());
+ v.insert(v.end(), first, last);
}
template <typename Range>
@@ -290,63 +245,45 @@ typename Range::const_iterator cmRemoveMatching(Range& r, MatchRange const& m)
ContainerAlgorithms::BinarySearcher<MatchRange>(m));
}
-namespace ContainerAlgorithms {
-
-template <typename Range, typename T = typename Range::value_type>
-struct RemoveDuplicatesAPI
+template <typename ForwardIterator>
+ForwardIterator cmRemoveDuplicates(ForwardIterator first, ForwardIterator last)
{
- typedef typename Range::const_iterator const_iterator;
- typedef typename Range::const_iterator value_type;
-
- static bool lessThan(value_type a, value_type b) { return *a < *b; }
- static value_type uniqueValue(const_iterator a) { return a; }
- template <typename It>
- static bool valueCompare(It it, const_iterator it2)
+ using Value = typename std::iterator_traits<ForwardIterator>::value_type;
+ using Hash = struct
{
- return **it != *it2;
- }
-};
-
-template <typename Range, typename T>
-struct RemoveDuplicatesAPI<Range, T*>
-{
- typedef typename Range::const_iterator const_iterator;
- typedef T* value_type;
+ std::size_t operator()(ForwardIterator it) const
+ {
+ return std::hash<Value>{}(*it);
+ }
+ };
- static bool lessThan(value_type a, value_type b) { return a < b; }
- static value_type uniqueValue(const_iterator a) { return *a; }
- template <typename It>
- static bool valueCompare(It it, const_iterator it2)
+ using Equal = struct
{
- return *it != *it2;
+ bool operator()(ForwardIterator it1, ForwardIterator it2) const
+ {
+ return *it1 == *it2;
+ }
+ };
+ std::unordered_set<ForwardIterator, Hash, Equal> uniq;
+
+ ForwardIterator result = first;
+ while (first != last) {
+ if (uniq.find(first) == uniq.end()) {
+ if (result != first) {
+ *result = std::move(*first);
+ }
+ uniq.insert(result);
+ ++result;
+ }
+ ++first;
}
-};
+ return result;
}
template <typename Range>
typename Range::const_iterator cmRemoveDuplicates(Range& r)
{
- typedef typename ContainerAlgorithms::RemoveDuplicatesAPI<Range> API;
- typedef typename API::value_type T;
- std::vector<T> unique;
- unique.reserve(r.size());
- std::vector<size_t> indices;
- size_t count = 0;
- const typename Range::const_iterator end = r.end();
- for (typename Range::const_iterator it = r.begin(); it != end;
- ++it, ++count) {
- const typename std::vector<T>::iterator low = std::lower_bound(
- unique.begin(), unique.end(), API::uniqueValue(it), API::lessThan);
- if (low == unique.end() || API::valueCompare(low, it)) {
- unique.insert(low, API::uniqueValue(it));
- } else {
- indices.push_back(count);
- }
- }
- if (indices.empty()) {
- return end;
- }
- return cmRemoveIndices(r, indices);
+ return cmRemoveDuplicates(r.begin(), r.end());
}
template <typename Range>
@@ -369,16 +306,7 @@ std::string cmWrap(char prefix, Range const& r, char suffix,
template <typename Range, typename T>
typename Range::const_iterator cmFindNot(Range const& r, T const& t)
{
- return std::find_if(r.begin(), r.end(),
- std::bind1st(std::not_equal_to<T>(), t));
-}
-
-template <typename Range>
-cmRange<typename Range::const_reverse_iterator> cmReverseRange(
- Range const& range)
-{
- return cmRange<typename Range::const_reverse_iterator>(range.rbegin(),
- range.rend());
+ return std::find_if(r.begin(), r.end(), [&t](T const& i) { return i != t; });
}
template <class Iter>
@@ -387,6 +315,14 @@ std::reverse_iterator<Iter> cmMakeReverseIterator(Iter it)
return std::reverse_iterator<Iter>(it);
}
+inline bool cmHasPrefix(std::string const& str, std::string const& prefix)
+{
+ if (str.size() < prefix.size()) {
+ return false;
+ }
+ return str.compare(0, prefix.size(), prefix) == 0;
+}
+
inline bool cmHasSuffix(const std::string& str, const std::string& suffix)
{
if (str.size() < suffix.size()) {
@@ -402,4 +338,89 @@ inline void cmStripSuffixIfExists(std::string& str, const std::string& suffix)
}
}
+namespace cm {
+
+#if defined(CMake_HAVE_CXX_MAKE_UNIQUE)
+
+using std::make_unique;
+
+#else
+
+template <typename T, typename... Args>
+std::unique_ptr<T> make_unique(Args&&... args)
+{
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+#endif
+
+#if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
+
+using std::size;
+
+#else
+
+// std::size backport from C++17.
+template <class C>
+# if !defined(_MSC_VER) || _MSC_VER >= 1900
+constexpr
+# endif
+ auto
+ size(C const& c) -> decltype(c.size())
+{
+ return c.size();
+}
+
+template <typename T, size_t N>
+# if !defined(_MSC_VER) || _MSC_VER >= 1900
+constexpr
+# endif
+ std::size_t
+ size(const T (&)[N]) throw()
+{
+ return N;
+}
+
+#endif
+
+template <typename T>
+int isize(const T& t)
+{
+ return static_cast<int>(cm::size(t));
+}
+
+#if __cplusplus >= 201402L || defined(_MSVC_LANG) && _MSVC_LANG >= 201402L
+
+using std::cbegin;
+using std::cend;
+
+#else
+
+// std::c{begin,end} backport from C++14
+template <class C>
+# if defined(_MSC_VER) && _MSC_VER < 1900
+auto cbegin(C const& c)
+# else
+constexpr auto cbegin(C const& c) noexcept(noexcept(std::begin(c)))
+# endif
+ -> decltype(std::begin(c))
+{
+ return std::begin(c);
+}
+
+template <class C>
+# if defined(_MSC_VER) && _MSC_VER < 1900
+auto cend(C const& c)
+# else
+constexpr auto cend(C const& c) noexcept(noexcept(std::end(c)))
+# endif
+ -> decltype(std::end(c))
+{
+ return std::end(c);
+}
+
+#endif
+
+} // namespace cm
+
#endif
diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx
index 0f13b114f..359d57af6 100644
--- a/Source/cmArchiveWrite.cxx
+++ b/Source/cmArchiveWrite.cxx
@@ -10,11 +10,12 @@
#include "cmsys/Encoding.hxx"
#include "cmsys/FStream.hxx"
#include <iostream>
+#include <sstream>
#include <string.h>
#include <time.h>
#ifndef __LA_SSIZE_T
-#define __LA_SSIZE_T la_ssize_t
+# define __LA_SSIZE_T la_ssize_t
#endif
static std::string cm_archive_error_string(struct archive* a)
@@ -53,6 +54,8 @@ public:
{
}
~Entry() { archive_entry_free(this->Object); }
+ Entry(const Entry&) = delete;
+ Entry& operator=(const Entry&) = delete;
operator struct archive_entry*() { return this->Object; }
};
@@ -94,13 +97,25 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c,
return;
}
break;
- case CompressGZip:
+ case CompressGZip: {
if (archive_write_add_filter_gzip(this->Archive) != ARCHIVE_OK) {
this->Error = "archive_write_add_filter_gzip: ";
this->Error += cm_archive_error_string(this->Archive);
return;
}
- break;
+ std::string source_date_epoch;
+ cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch);
+ if (!source_date_epoch.empty()) {
+ // We're not able to specify an arbitrary timestamp for gzip.
+ // The next best thing is to omit the timestamp entirely.
+ if (archive_write_set_filter_option(this->Archive, "gzip", "timestamp",
+ nullptr) != ARCHIVE_OK) {
+ this->Error = "archive_write_set_filter_option: ";
+ this->Error += cm_archive_error_string(this->Archive);
+ return;
+ }
+ }
+ } break;
case CompressBZip2:
if (archive_write_add_filter_bzip2(this->Archive) != ARCHIVE_OK) {
this->Error = "archive_write_add_filter_bzip2: ";
@@ -122,7 +137,14 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c,
return;
}
break;
- };
+ case CompressZstd:
+ if (archive_write_add_filter_zstd(this->Archive) != ARCHIVE_OK) {
+ this->Error = "archive_write_add_filter_zstd: ";
+ 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: ";
@@ -146,9 +168,9 @@ cmArchiveWrite::cmArchiveWrite(std::ostream& os, Compress c,
}
if (archive_write_open(
- this->Archive, this, CM_NULLPTR,
+ this->Archive, this, nullptr,
reinterpret_cast<archive_write_callback*>(&Callback::Write),
- CM_NULLPTR) != ARCHIVE_OK) {
+ nullptr) != ARCHIVE_OK) {
this->Error = "archive_write_open: ";
this->Error += cm_archive_error_string(this->Archive);
return;
@@ -164,12 +186,10 @@ cmArchiveWrite::~cmArchiveWrite()
bool cmArchiveWrite::Add(std::string path, size_t skip, const char* prefix,
bool recursive)
{
- if (this->Okay()) {
- if (!path.empty() && path[path.size() - 1] == '/') {
- path.erase(path.size() - 1);
- }
- this->AddPath(path.c_str(), skip, prefix, recursive);
+ if (!path.empty() && path.back() == '/') {
+ path.erase(path.size() - 1);
}
+ this->AddPath(path.c_str(), skip, prefix, recursive);
return this->Okay();
}
@@ -205,6 +225,7 @@ bool cmArchiveWrite::AddPath(const char* path, size_t skip, const char* prefix,
bool cmArchiveWrite::AddFile(const char* file, size_t skip, const char* prefix)
{
+ this->Error = "";
// 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)) {
@@ -224,9 +245,9 @@ bool cmArchiveWrite::AddFile(const char* file, size_t skip, const char* prefix)
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, CM_NULLPTR) !=
+ if (archive_read_disk_entry_from_file(this->Disk, e, -1, nullptr) !=
ARCHIVE_OK) {
- this->Error = "archive_read_disk_entry_from_file '";
+ this->Error = "Unable to read from file '";
this->Error += file;
this->Error += "': ";
this->Error += cm_archive_error_string(this->Disk);
@@ -243,6 +264,17 @@ bool cmArchiveWrite::AddFile(const char* file, size_t skip, const char* prefix)
return false;
}
archive_entry_set_mtime(e, t, 0);
+ } else {
+ std::string source_date_epoch;
+ cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch);
+ if (!source_date_epoch.empty()) {
+ std::istringstream iss(source_date_epoch);
+ time_t epochTime;
+ iss >> epochTime;
+ if (iss.eof() && !iss.fail()) {
+ archive_entry_set_mtime(e, epochTime, 0);
+ }
+ }
}
// manages the uid/guid of the entry (if any)
diff --git a/Source/cmArchiveWrite.h b/Source/cmArchiveWrite.h
index 4c85c0d16..9ea88d3dc 100644
--- a/Source/cmArchiveWrite.h
+++ b/Source/cmArchiveWrite.h
@@ -10,7 +10,7 @@
#include <string>
#if !defined(CMAKE_BUILD_WITH_CMAKE)
-#error "cmArchiveWrite not allowed during bootstrap build!"
+# error "cmArchiveWrite not allowed during bootstrap build!"
#endif
template <typename T>
@@ -28,6 +28,7 @@ public:
void Clear() { this->IsValueSet = false; }
bool IsSet() const { return this->IsValueSet; }
T Get() const { return Value; }
+
private:
T Value;
bool IsValueSet;
@@ -39,8 +40,6 @@ private:
*/
class cmArchiveWrite
{
- typedef void (cmArchiveWrite::*safe_bool)();
- void safe_bool_true() {}
public:
/** Compression type. */
enum Compress
@@ -50,7 +49,8 @@ public:
CompressGZip,
CompressBZip2,
CompressLZMA,
- CompressXZ
+ CompressXZ,
+ CompressZstd
};
/** Construct with output stream to which to write archive. */
@@ -59,6 +59,9 @@ public:
~cmArchiveWrite();
+ cmArchiveWrite(const cmArchiveWrite&) = delete;
+ cmArchiveWrite& operator=(const cmArchiveWrite&) = delete;
+
/**
* Add a path (file or directory) to the archive. Directories are
* added recursively. The "path" must be readable on disk, either
@@ -67,14 +70,11 @@ public:
* 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 = CM_NULLPTR,
+ bool Add(std::string path, size_t skip = 0, const char* prefix = nullptr,
bool recursive = true);
/** Returns true if there has been no error. */
- operator safe_bool() const
- {
- return this->Okay() ? &cmArchiveWrite::safe_bool_true : CM_NULLPTR;
- }
+ explicit operator bool() const { return this->Okay(); }
/** Returns true if there has been an error. */
bool operator!() const { return !this->Okay(); }
diff --git a/Source/cmAuxSourceDirectoryCommand.cxx b/Source/cmAuxSourceDirectoryCommand.cxx
index 847a41660..106e7a79a 100644
--- a/Source/cmAuxSourceDirectoryCommand.cxx
+++ b/Source/cmAuxSourceDirectoryCommand.cxx
@@ -5,6 +5,7 @@
#include "cmsys/Directory.hxx"
#include <algorithm>
#include <stddef.h>
+#include <utility>
#include "cmAlgorithms.h"
#include "cmMakefile.h"
@@ -26,7 +27,7 @@ bool cmAuxSourceDirectoryCommand::InitialPass(
std::string sourceListValue;
std::string const& templateDirectory = args[0];
std::string tdir;
- if (!cmSystemTools::FileIsFullPath(templateDirectory.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(templateDirectory)) {
tdir = this->Makefile->GetCurrentSourceDirectory();
tdir += "/";
tdir += templateDirectory;
@@ -54,10 +55,8 @@ bool cmAuxSourceDirectoryCommand::InitialPass(
std::string ext = file.substr(dotpos + 1);
std::string base = file.substr(0, dotpos);
// Process only source files
- std::vector<std::string> const& srcExts =
- this->Makefile->GetCMakeInstance()->GetSourceExtensions();
- if (!base.empty() &&
- std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) {
+ auto cm = this->Makefile->GetCMakeInstance();
+ if (!base.empty() && cm->IsSourceExtension(ext)) {
std::string fullname = templateDirectory;
fullname += "/";
fullname += file;
@@ -65,7 +64,7 @@ bool cmAuxSourceDirectoryCommand::InitialPass(
// depends can be done
cmSourceFile* sf = this->Makefile->GetOrCreateSource(fullname);
sf->SetProperty("ABSTRACT", "0");
- files.push_back(fullname);
+ files.push_back(std::move(fullname));
}
}
}
diff --git a/Source/cmAuxSourceDirectoryCommand.h b/Source/cmAuxSourceDirectoryCommand.h
index e49e86117..3742e3e9b 100644
--- a/Source/cmAuxSourceDirectoryCommand.h
+++ b/Source/cmAuxSourceDirectoryCommand.h
@@ -3,7 +3,7 @@
#ifndef cmAuxSourceDirectoryCommand_h
#define cmAuxSourceDirectoryCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -27,14 +27,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmAuxSourceDirectoryCommand; }
+ cmCommand* Clone() override { return new cmAuxSourceDirectoryCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmBase32.cxx b/Source/cmBase32.cxx
index 1dac212c2..80ada4766 100644
--- a/Source/cmBase32.cxx
+++ b/Source/cmBase32.cxx
@@ -34,13 +34,9 @@ void Base32Encode5(const unsigned char src[5], char dst[8])
// -- Class methods
-cmBase32Encoder::cmBase32Encoder()
-{
-}
+cmBase32Encoder::cmBase32Encoder() = default;
-cmBase32Encoder::~cmBase32Encoder()
-{
-}
+cmBase32Encoder::~cmBase32Encoder() = default;
std::string cmBase32Encoder::encodeString(const unsigned char* input,
size_t len, bool padding)
diff --git a/Source/cmBreakCommand.cxx b/Source/cmBreakCommand.cxx
index 3772c6fb6..d07898fd6 100644
--- a/Source/cmBreakCommand.cxx
+++ b/Source/cmBreakCommand.cxx
@@ -6,8 +6,8 @@
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
-#include "cmake.h"
// cmBreakCommand
bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
@@ -16,7 +16,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
if (!this->Makefile->IsLoopBlock()) {
bool issueMessage = true;
std::ostringstream e;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0055)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0055) << "\n";
@@ -27,7 +27,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
break;
}
@@ -35,7 +35,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
e << "A BREAK command was found outside of a proper "
"FOREACH or WHILE loop scope.";
this->Makefile->IssueMessage(messageType, e.str());
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
@@ -46,7 +46,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
if (!args.empty()) {
bool issueMessage = true;
std::ostringstream e;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0055)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0055) << "\n";
@@ -57,14 +57,14 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
break;
}
if (issueMessage) {
e << "The BREAK command does not accept any arguments.";
this->Makefile->IssueMessage(messageType, e.str());
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
diff --git a/Source/cmBreakCommand.h b/Source/cmBreakCommand.h
index fcca45c31..3b1856736 100644
--- a/Source/cmBreakCommand.h
+++ b/Source/cmBreakCommand.h
@@ -3,7 +3,7 @@
#ifndef cmBreakCommand_h
#define cmBreakCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmBreakCommand; }
+ cmCommand* Clone() override { return new cmBreakCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmBuildCommand.cxx b/Source/cmBuildCommand.cxx
index fd876004b..428a0b224 100644
--- a/Source/cmBuildCommand.cxx
+++ b/Source/cmBuildCommand.cxx
@@ -6,9 +6,9 @@
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -84,7 +84,7 @@ bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
if (!project_name.empty()) {
this->Makefile->IssueMessage(
- cmake::AUTHOR_WARNING,
+ MessageType::AUTHOR_WARNING,
"Ignoring PROJECT_NAME option because it has no effect.");
}
diff --git a/Source/cmBuildCommand.h b/Source/cmBuildCommand.h
index 1f357a980..e0529a414 100644
--- a/Source/cmBuildCommand.h
+++ b/Source/cmBuildCommand.h
@@ -3,7 +3,7 @@
#ifndef cmBuildCommand_h
#define cmBuildCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmBuildCommand; }
+ cmCommand* Clone() override { return new cmBuildCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* The primary command signature with optional, KEYWORD-based args.
diff --git a/Source/cmBuildNameCommand.cxx b/Source/cmBuildNameCommand.cxx
index 9d2c0c642..ddff68686 100644
--- a/Source/cmBuildNameCommand.cxx
+++ b/Source/cmBuildNameCommand.cxx
@@ -36,12 +36,12 @@ bool cmBuildNameCommand::InitialPass(std::vector<std::string> const& args,
std::string buildname = "WinNT";
if (this->Makefile->GetDefinition("UNIX")) {
- buildname = "";
+ buildname.clear();
cmSystemTools::RunSingleCommand("uname -a", &buildname, &buildname);
if (!buildname.empty()) {
std::string RegExp = "([^ ]*) [^ ]* ([^ ]*) ";
- cmsys::RegularExpression reg(RegExp.c_str());
- if (reg.find(buildname.c_str())) {
+ cmsys::RegularExpression reg(RegExp);
+ if (reg.find(buildname)) {
buildname = reg.match(1) + "-" + reg.match(2);
}
}
diff --git a/Source/cmBuildNameCommand.h b/Source/cmBuildNameCommand.h
index ff26c559c..4bb72d147 100644
--- a/Source/cmBuildNameCommand.h
+++ b/Source/cmBuildNameCommand.h
@@ -3,7 +3,7 @@
#ifndef cmBuildNameCommand_h
#define cmBuildNameCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,9 +15,9 @@ class cmExecutionStatus;
class cmBuildNameCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmBuildNameCommand; }
+ cmCommand* Clone() override { return new cmBuildNameCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmCLocaleEnvironmentScope.cxx b/Source/cmCLocaleEnvironmentScope.cxx
index 28e8f2efc..737e3ea86 100644
--- a/Source/cmCLocaleEnvironmentScope.cxx
+++ b/Source/cmCLocaleEnvironmentScope.cxx
@@ -45,10 +45,9 @@ void cmCLocaleEnvironmentScope::SetEnv(std::string const& key,
cmCLocaleEnvironmentScope::~cmCLocaleEnvironmentScope()
{
- for (backup_map_t::const_iterator i = this->EnvironmentBackup.begin();
- i != this->EnvironmentBackup.end(); ++i) {
+ for (auto const& envb : this->EnvironmentBackup) {
std::ostringstream tmp;
- tmp << i->first << "=" << i->second;
+ tmp << envb.first << "=" << envb.second;
cmSystemTools::PutEnv(tmp.str());
}
}
diff --git a/Source/cmCLocaleEnvironmentScope.h b/Source/cmCLocaleEnvironmentScope.h
index e956cb24d..93032c12e 100644
--- a/Source/cmCLocaleEnvironmentScope.h
+++ b/Source/cmCLocaleEnvironmentScope.h
@@ -3,19 +3,21 @@
#ifndef cmCLocaleEnvironmentScope_h
#define cmCLocaleEnvironmentScope_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
#include <string>
class cmCLocaleEnvironmentScope
{
- CM_DISABLE_COPY(cmCLocaleEnvironmentScope)
-
public:
cmCLocaleEnvironmentScope();
~cmCLocaleEnvironmentScope();
+ cmCLocaleEnvironmentScope(cmCLocaleEnvironmentScope const&) = delete;
+ cmCLocaleEnvironmentScope& operator=(cmCLocaleEnvironmentScope const&) =
+ delete;
+
private:
std::string GetEnv(std::string const& key);
void SetEnv(std::string const& key, std::string const& value);
diff --git a/Source/cmCMakeHostSystemInformationCommand.cxx b/Source/cmCMakeHostSystemInformationCommand.cxx
index 4475c5a52..54f08bbcd 100644
--- a/Source/cmCMakeHostSystemInformationCommand.cxx
+++ b/Source/cmCMakeHostSystemInformationCommand.cxx
@@ -8,9 +8,12 @@
#include "cmsys/SystemInformation.hxx"
#if defined(_WIN32)
-#include "cmSystemTools.h"
-#include "cmVSSetupHelper.h"
-#define HAVE_VS_SETUP_HELPER
+# include "cmAlgorithms.h"
+# include "cmGlobalGenerator.h"
+# include "cmGlobalVisualStudioVersionedGenerator.h"
+# include "cmSystemTools.h"
+# include "cmVSSetupHelper.h"
+# define HAVE_VS_SETUP_HELPER
#endif
class cmExecutionStatus;
@@ -76,9 +79,85 @@ bool cmCMakeHostSystemInformationCommand::GetValue(
value = this->ValueToString(info.GetTotalPhysicalMemory());
} else if (key == "AVAILABLE_PHYSICAL_MEMORY") {
value = this->ValueToString(info.GetAvailablePhysicalMemory());
+ } else if (key == "IS_64BIT") {
+ value = this->ValueToString(info.Is64Bits());
+ } else if (key == "HAS_FPU") {
+ value = this->ValueToString(
+ info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_FPU));
+ } else if (key == "HAS_MMX") {
+ value = this->ValueToString(
+ info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_MMX));
+ } else if (key == "HAS_MMX_PLUS") {
+ value = this->ValueToString(info.DoesCPUSupportFeature(
+ cmsys::SystemInformation::CPU_FEATURE_MMX_PLUS));
+ } else if (key == "HAS_SSE") {
+ value = this->ValueToString(
+ info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE));
+ } else if (key == "HAS_SSE2") {
+ value = this->ValueToString(
+ info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE2));
+ } else if (key == "HAS_SSE_FP") {
+ value = this->ValueToString(info.DoesCPUSupportFeature(
+ cmsys::SystemInformation::CPU_FEATURE_SSE_FP));
+ } else if (key == "HAS_SSE_MMX") {
+ value = this->ValueToString(info.DoesCPUSupportFeature(
+ cmsys::SystemInformation::CPU_FEATURE_SSE_MMX));
+ } else if (key == "HAS_AMD_3DNOW") {
+ value = this->ValueToString(info.DoesCPUSupportFeature(
+ cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW));
+ } else if (key == "HAS_AMD_3DNOW_PLUS") {
+ value = this->ValueToString(info.DoesCPUSupportFeature(
+ cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW_PLUS));
+ } else if (key == "HAS_IA64") {
+ value = this->ValueToString(
+ info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_IA64));
+ } else if (key == "HAS_SERIAL_NUMBER") {
+ value = this->ValueToString(info.DoesCPUSupportFeature(
+ cmsys::SystemInformation::CPU_FEATURE_SERIALNUMBER));
+ } else if (key == "PROCESSOR_NAME") {
+ value = this->ValueToString(info.GetExtendedProcessorName());
+ } else if (key == "PROCESSOR_DESCRIPTION") {
+ value = info.GetCPUDescription();
+ } else if (key == "PROCESSOR_SERIAL_NUMBER") {
+ value = this->ValueToString(info.GetProcessorSerialNumber());
+ } else if (key == "OS_NAME") {
+ value = this->ValueToString(info.GetOSName());
+ } else if (key == "OS_RELEASE") {
+ value = this->ValueToString(info.GetOSRelease());
+ } else if (key == "OS_VERSION") {
+ value = this->ValueToString(info.GetOSVersion());
+ } else if (key == "OS_PLATFORM") {
+ value = this->ValueToString(info.GetOSPlatform());
#ifdef HAVE_VS_SETUP_HELPER
} else if (key == "VS_15_DIR") {
- cmVSSetupAPIHelper vsSetupAPIHelper;
+ // If generating for the VS 15 IDE, use the same instance.
+ cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
+ if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 15 ")) {
+ cmGlobalVisualStudioVersionedGenerator* vs15gen =
+ static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg);
+ if (vs15gen->GetVSInstance(value)) {
+ return true;
+ }
+ }
+
+ // Otherwise, find a VS 15 instance ourselves.
+ cmVSSetupAPIHelper vsSetupAPIHelper(15);
+ if (vsSetupAPIHelper.GetVSInstanceInfo(value)) {
+ cmSystemTools::ConvertToUnixSlashes(value);
+ }
+ } else if (key == "VS_16_DIR") {
+ // If generating for the VS 16 IDE, use the same instance.
+ cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
+ if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 16 ")) {
+ cmGlobalVisualStudioVersionedGenerator* vs16gen =
+ static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg);
+ if (vs16gen->GetVSInstance(value)) {
+ return true;
+ }
+ }
+
+ // Otherwise, find a VS 16 instance ourselves.
+ cmVSSetupAPIHelper vsSetupAPIHelper(16);
if (vsSetupAPIHelper.GetVSInstanceInfo(value)) {
cmSystemTools::ConvertToUnixSlashes(value);
}
diff --git a/Source/cmCMakeHostSystemInformationCommand.h b/Source/cmCMakeHostSystemInformationCommand.h
index ef6ca3730..b8716418c 100644
--- a/Source/cmCMakeHostSystemInformationCommand.h
+++ b/Source/cmCMakeHostSystemInformationCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCMakeHostSystemInformationCommand_h
#define cmCMakeHostSystemInformationCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <stddef.h>
#include <string>
@@ -20,7 +20,7 @@ class SystemInformation;
* \brief Query host system specific information
*
* cmCMakeHostSystemInformationCommand queries system information of
- * the sytem on which CMake runs.
+ * the system on which CMake runs.
*/
class cmCMakeHostSystemInformationCommand : public cmCommand
{
@@ -28,7 +28,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
return new cmCMakeHostSystemInformationCommand;
}
@@ -38,7 +38,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
bool GetValue(cmsys::SystemInformation& info, std::string const& key,
diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx
index 942688cee..4b4bca243 100644
--- a/Source/cmCMakeMinimumRequired.cxx
+++ b/Source/cmCMakeMinimumRequired.cxx
@@ -6,9 +6,9 @@
#include <stdio.h>
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -19,10 +19,10 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
// Process arguments.
std::string version_string;
bool doing_version = false;
- for (unsigned int i = 0; i < args.size(); ++i) {
- if (args[i] == "VERSION") {
+ for (std::string const& arg : args) {
+ if (arg == "VERSION") {
doing_version = true;
- } else if (args[i] == "FATAL_ERROR") {
+ } else if (arg == "FATAL_ERROR") {
if (doing_version) {
this->SetError("called with no value for VERSION.");
return false;
@@ -30,9 +30,9 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
doing_version = false;
} else if (doing_version) {
doing_version = false;
- version_string = args[i];
+ version_string = arg;
} else {
- this->UnknownArguments.push_back(args[i]);
+ this->UnknownArguments.push_back(arg);
}
}
if (doing_version) {
@@ -42,12 +42,27 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
// Make sure there was a version to check.
if (version_string.empty()) {
- return this->EnforceUnknownArguments();
+ return this->EnforceUnknownArguments(std::string());
+ }
+
+ // Separate the <min> version and any trailing ...<max> component.
+ std::string::size_type const dd = version_string.find("...");
+ std::string const version_min = version_string.substr(0, dd);
+ std::string const version_max = dd != std::string::npos
+ ? version_string.substr(dd + 3, std::string::npos)
+ : std::string();
+ if (dd != std::string::npos &&
+ (version_min.empty() || version_max.empty())) {
+ std::ostringstream e;
+ e << "VERSION \"" << version_string
+ << R"(" does not have a version on both sides of "...".)";
+ this->SetError(e.str());
+ return false;
}
// Save the required version string.
this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION",
- version_string.c_str());
+ version_min.c_str());
// Get the current version number.
unsigned int current_major = cmVersion::GetMajorVersion();
@@ -61,10 +76,10 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
unsigned int required_minor = 0;
unsigned int required_patch = 0;
unsigned int required_tweak = 0;
- if (sscanf(version_string.c_str(), "%u.%u.%u.%u", &required_major,
+ if (sscanf(version_min.c_str(), "%u.%u.%u.%u", &required_major,
&required_minor, &required_patch, &required_tweak) < 2) {
std::ostringstream e;
- e << "could not parse VERSION \"" << version_string << "\".";
+ e << "could not parse VERSION \"" << version_min << "\".";
this->SetError(e.str());
return false;
}
@@ -78,39 +93,64 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
current_patch == required_patch && current_tweak < required_tweak)) {
// The current version is too low.
std::ostringstream e;
- e << "CMake " << version_string
+ e << "CMake " << version_min
<< " or higher is required. You are running version "
<< cmVersion::GetCMakeVersion();
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
return true;
}
// The version is not from the future, so enforce unknown arguments.
- if (!this->EnforceUnknownArguments()) {
+ if (!this->EnforceUnknownArguments(version_max)) {
return false;
}
if (required_major < 2 || (required_major == 2 && required_minor < 4)) {
this->Makefile->IssueMessage(
- cmake::AUTHOR_WARNING,
+ MessageType::AUTHOR_WARNING,
"Compatibility with CMake < 2.4 is not supported by CMake >= 3.0.");
- this->Makefile->SetPolicyVersion("2.4");
+ this->Makefile->SetPolicyVersion("2.4", version_max);
} else {
- this->Makefile->SetPolicyVersion(version_string.c_str());
+ this->Makefile->SetPolicyVersion(version_min, version_max);
}
return true;
}
-bool cmCMakeMinimumRequired::EnforceUnknownArguments()
+bool cmCMakeMinimumRequired::EnforceUnknownArguments(
+ std::string const& version_max)
{
- if (!this->UnknownArguments.empty()) {
- std::ostringstream e;
- e << "called with unknown argument \"" << this->UnknownArguments[0]
- << "\".";
- this->SetError(e.str());
- return false;
+ if (this->UnknownArguments.empty()) {
+ return true;
}
- return true;
+
+ // Consider the max version if at least two components were given.
+ unsigned int max_major = 0;
+ unsigned int max_minor = 0;
+ unsigned int max_patch = 0;
+ unsigned int max_tweak = 0;
+ if (sscanf(version_max.c_str(), "%u.%u.%u.%u", &max_major, &max_minor,
+ &max_patch, &max_tweak) >= 2) {
+ unsigned int current_major = cmVersion::GetMajorVersion();
+ unsigned int current_minor = cmVersion::GetMinorVersion();
+ unsigned int current_patch = cmVersion::GetPatchVersion();
+ unsigned int current_tweak = cmVersion::GetTweakVersion();
+
+ if ((current_major < max_major) ||
+ (current_major == max_major && current_minor < max_minor) ||
+ (current_major == max_major && current_minor == max_minor &&
+ current_patch < max_patch) ||
+ (current_major == max_major && current_minor == max_minor &&
+ current_patch == max_patch && current_tweak < max_tweak)) {
+ // A ...<max> version was given that is larger than the current
+ // version of CMake, so tolerate unknown arguments.
+ return true;
+ }
+ }
+
+ std::ostringstream e;
+ e << "called with unknown argument \"" << this->UnknownArguments[0] << "\".";
+ this->SetError(e.str());
+ return false;
}
diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h
index 45b6b7885..f9b61e142 100644
--- a/Source/cmCMakeMinimumRequired.h
+++ b/Source/cmCMakeMinimumRequired.h
@@ -3,7 +3,7 @@
#ifndef cmCMakeMinimumRequired_h
#define cmCMakeMinimumRequired_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,18 +23,18 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmCMakeMinimumRequired; }
+ cmCommand* Clone() override { return new cmCMakeMinimumRequired; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
std::vector<std::string> UnknownArguments;
- bool EnforceUnknownArguments();
+ bool EnforceUnknownArguments(std::string const& version_max);
};
#endif
diff --git a/Source/cmCMakePolicyCommand.cxx b/Source/cmCMakePolicyCommand.cxx
index 3ccc815e6..8da5ef760 100644
--- a/Source/cmCMakePolicyCommand.cxx
+++ b/Source/cmCMakePolicyCommand.cxx
@@ -5,10 +5,10 @@
#include <sstream>
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmState.h"
#include "cmStateTypes.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -46,6 +46,9 @@ bool cmCMakePolicyCommand::InitialPass(std::vector<std::string> const& args,
if (args[0] == "VERSION") {
return this->HandleVersionMode(args);
}
+ if (args[0] == "GET_WARNING") {
+ return this->HandleGetWarningMode(args);
+ }
std::ostringstream e;
e << "given unknown first argument \"" << args[0] << "\"";
@@ -95,7 +98,11 @@ bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
{
- if (args.size() != 3) {
+ bool parent_scope = false;
+ if (args.size() == 4 && args[3] == "PARENT_SCOPE") {
+ // Undocumented PARENT_SCOPE option for use within CMake.
+ parent_scope = true;
+ } else if (args.size() != 3) {
this->SetError("GET must be given exactly 2 additional arguments.");
return false;
}
@@ -115,7 +122,8 @@ bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
}
// Lookup the policy setting.
- cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
+ cmPolicies::PolicyStatus status =
+ this->Makefile->GetPolicyStatus(pid, parent_scope);
switch (status) {
case cmPolicies::OLD:
// Report that the policy is set to OLD.
@@ -138,7 +146,7 @@ bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
<< "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());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
}
@@ -156,6 +164,53 @@ bool cmCMakePolicyCommand::HandleVersionMode(
this->SetError("VERSION given too many arguments");
return false;
}
- this->Makefile->SetPolicyVersion(args[1].c_str());
+ std::string const& version_string = args[1];
+
+ // Separate the <min> version and any trailing ...<max> component.
+ std::string::size_type const dd = version_string.find("...");
+ std::string const version_min = version_string.substr(0, dd);
+ std::string const version_max = dd != std::string::npos
+ ? version_string.substr(dd + 3, std::string::npos)
+ : std::string();
+ if (dd != std::string::npos &&
+ (version_min.empty() || version_max.empty())) {
+ std::ostringstream e;
+ e << "VERSION \"" << version_string
+ << R"(" does not have a version on both sides of "...".)";
+ this->SetError(e.str());
+ return false;
+ }
+
+ this->Makefile->SetPolicyVersion(version_min, version_max);
+ return true;
+}
+
+bool cmCMakePolicyCommand::HandleGetWarningMode(
+ std::vector<std::string> const& args)
+{
+ if (args.size() != 3) {
+ this->SetError(
+ "GET_WARNING 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 (!cmPolicies::GetPolicyID(id.c_str(), pid)) {
+ std::ostringstream e;
+ e << "GET_WARNING given policy \"" << id
+ << "\" which is not known to this version of CMake.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Lookup the policy warning.
+ this->Makefile->AddDefinition(var,
+ cmPolicies::GetPolicyWarning(pid).c_str());
+
return true;
}
diff --git a/Source/cmCMakePolicyCommand.h b/Source/cmCMakePolicyCommand.h
index 0e88243f5..cca140617 100644
--- a/Source/cmCMakePolicyCommand.h
+++ b/Source/cmCMakePolicyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCMakePolicyCommand_h
#define cmCMakePolicyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,19 +24,20 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmCMakePolicyCommand; }
+ cmCommand* Clone() override { return new cmCMakePolicyCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
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);
+ bool HandleGetWarningMode(std::vector<std::string> const& args);
};
#endif
diff --git a/Source/cmCPackPropertiesGenerator.cxx b/Source/cmCPackPropertiesGenerator.cxx
index 57a8b383c..a33b824f3 100644
--- a/Source/cmCPackPropertiesGenerator.cxx
+++ b/Source/cmCPackPropertiesGenerator.cxx
@@ -6,7 +6,6 @@
#include <map>
#include <ostream>
-#include <utility>
cmCPackPropertiesGenerator::cmCPackPropertiesGenerator(
cmLocalGenerator* lg, cmInstalledFile const& installedFile,
@@ -27,19 +26,17 @@ void cmCPackPropertiesGenerator::GenerateScriptForConfig(
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;
+ for (cmInstalledFile::PropertyMapType::value_type const& i : properties) {
+ std::string const& name = i.first;
+ cmInstalledFile::Property const& property = i.second;
os << indent << "set_property(INSTALL "
<< cmOutputConverter::EscapeForCMake(expandedFileName) << " PROPERTY "
<< cmOutputConverter::EscapeForCMake(name);
- for (cmInstalledFile::ExpressionVectorType::const_iterator j =
- property.ValueExpressions.begin();
- j != property.ValueExpressions.end(); ++j) {
- std::string value = (*j)->Evaluate(this->LG, config);
+ for (cmInstalledFile::ExpressionVectorType::value_type const& j :
+ property.ValueExpressions) {
+ std::string value = j->Evaluate(this->LG, config);
os << " " << cmOutputConverter::EscapeForCMake(value);
}
diff --git a/Source/cmCPackPropertiesGenerator.h b/Source/cmCPackPropertiesGenerator.h
index 48f4c10f4..ad943c588 100644
--- a/Source/cmCPackPropertiesGenerator.h
+++ b/Source/cmCPackPropertiesGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmCPackPropertiesGenerator_h
#define cmCPackPropertiesGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmScriptGenerator.h"
@@ -20,16 +20,18 @@ class cmLocalGenerator;
*/
class cmCPackPropertiesGenerator : public cmScriptGenerator
{
- CM_DISABLE_COPY(cmCPackPropertiesGenerator)
-
public:
cmCPackPropertiesGenerator(cmLocalGenerator* lg,
cmInstalledFile const& installedFile,
std::vector<std::string> const& configurations);
+ cmCPackPropertiesGenerator(cmCPackPropertiesGenerator const&) = delete;
+ cmCPackPropertiesGenerator& operator=(cmCPackPropertiesGenerator const&) =
+ delete;
+
protected:
void GenerateScriptForConfig(std::ostream& os, const std::string& config,
- Indent indent) CM_OVERRIDE;
+ Indent indent) override;
cmLocalGenerator* LG;
cmInstalledFile const& InstalledFile;
diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx
index e78f5fe04..255a8e62a 100644
--- a/Source/cmCPluginAPI.cxx
+++ b/Source/cmCPluginAPI.cxx
@@ -17,7 +17,7 @@
#include <stdlib.h>
#ifdef __QNX__
-#include <malloc.h> /* for malloc/free on QNX */
+# include <malloc.h> /* for malloc/free on QNX */
#endif
extern "C" {
@@ -108,32 +108,32 @@ const char* CCONV cmGetProjectName(void* arg)
const char* CCONV cmGetHomeDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
- return mf->GetHomeDirectory();
+ return mf->GetHomeDirectory().c_str();
}
const char* CCONV cmGetHomeOutputDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
- return mf->GetHomeOutputDirectory();
+ return mf->GetHomeOutputDirectory().c_str();
}
const char* CCONV cmGetStartDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
- return mf->GetCurrentSourceDirectory();
+ return mf->GetCurrentSourceDirectory().c_str();
}
const char* CCONV cmGetStartOutputDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
- return mf->GetCurrentBinaryDirectory();
+ return mf->GetCurrentBinaryDirectory().c_str();
}
const char* CCONV cmGetCurrentDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
- return mf->GetCurrentSourceDirectory();
+ return mf->GetCurrentSourceDirectory().c_str();
}
const char* CCONV cmGetCurrentOutputDirectory(void* arg)
{
cmMakefile* mf = static_cast<cmMakefile*>(arg);
- return mf->GetCurrentBinaryDirectory();
+ return mf->GetCurrentBinaryDirectory().c_str();
}
const char* CCONV cmGetDefinition(void* arg, const char* def)
{
@@ -167,11 +167,11 @@ void CCONV cmAddLinkDirectoryForTarget(void* arg, const char* tgt,
cmTarget* t = mf->FindLocalNonAliasTarget(tgt);
if (!t) {
cmSystemTools::Error(
- "Attempt to add link directories to non-existent target: ", tgt,
- " for directory ", d);
+ "Attempt to add link directories to non-existent target: " +
+ std::string(tgt) + " for directory " + std::string(d));
return;
}
- t->AddLinkDirectory(d);
+ t->InsertLinkDirectory(d, mf->GetBacktrace());
}
void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs,
@@ -181,7 +181,7 @@ void CCONV cmAddExecutable(void* arg, const char* exename, int numSrcs,
std::vector<std::string> srcs2;
int i;
for (i = 0; i < numSrcs; ++i) {
- srcs2.push_back(srcs[i]);
+ srcs2.emplace_back(srcs[i]);
}
cmTarget* tg = mf->AddExecutable(exename, srcs2);
if (win32) {
@@ -218,8 +218,8 @@ void CCONV cmAddUtilityCommand(void* arg, const char* utilityName,
}
// Pass the call to the makefile instance.
- mf->AddUtilityCommand(utilityName, (all ? false : true), CM_NULLPTR,
- depends2, commandLines);
+ mf->AddUtilityCommand(utilityName, cmMakefile::TargetOrigin::Project,
+ (all ? false : true), nullptr, depends2, commandLines);
}
void CCONV cmAddCustomCommand(void* arg, const char* source,
const char* command, int numArgs,
@@ -257,7 +257,7 @@ void CCONV cmAddCustomCommand(void* arg, const char* source,
}
// Pass the call to the makefile instance.
- const char* no_comment = CM_NULLPTR;
+ const char* no_comment = nullptr;
mf->AddCustomCommandOldStyle(target, outputs2, depends2, source,
commandLines, no_comment);
}
@@ -291,8 +291,8 @@ void CCONV cmAddCustomCommandToOutput(void* arg, const char* output,
}
// Pass the call to the makefile instance.
- const char* no_comment = CM_NULLPTR;
- const char* no_working_dir = CM_NULLPTR;
+ const char* no_comment = nullptr;
+ const char* no_working_dir = nullptr;
mf->AddCustomCommandToOutput(output, depends2, main_dependency, commandLines,
no_comment, no_working_dir);
}
@@ -333,8 +333,8 @@ void CCONV cmAddCustomCommandToTarget(void* arg, const char* target,
// Pass the call to the makefile instance.
std::vector<std::string> no_byproducts;
std::vector<std::string> no_depends;
- const char* no_comment = CM_NULLPTR;
- const char* no_working_dir = CM_NULLPTR;
+ const char* no_comment = nullptr;
+ const char* no_working_dir = nullptr;
mf->AddCustomCommandToTarget(target, no_byproducts, no_depends, commandLines,
cctype, no_comment, no_working_dir);
}
@@ -347,7 +347,7 @@ static void addLinkLibrary(cmMakefile* mf, std::string const& target,
std::ostringstream e;
e << "Attempt to add link library \"" << lib << "\" to target \"" << target
<< "\" which is not built in this directory.";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
@@ -362,7 +362,7 @@ static void addLinkLibrary(cmMakefile* mf, std::string const& target,
<< " 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.";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
t->AddLinkLibrary(*mf, lib, llt);
@@ -393,11 +393,12 @@ void CCONV cmAddLibrary(void* arg, const char* libname, int shared,
std::vector<std::string> srcs2;
int i;
for (i = 0; i < numSrcs; ++i) {
- srcs2.push_back(srcs[i]);
+ srcs2.emplace_back(srcs[i]);
}
- mf->AddLibrary(libname, (shared ? cmStateEnums::SHARED_LIBRARY
- : cmStateEnums::STATIC_LIBRARY),
- srcs2);
+ mf->AddLibrary(
+ libname,
+ (shared ? cmStateEnums::SHARED_LIBRARY : cmStateEnums::STATIC_LIBRARY),
+ srcs2);
}
char CCONV* cmExpandVariablesInString(void* arg, const char* source,
@@ -405,14 +406,9 @@ char CCONV* cmExpandVariablesInString(void* arg, const char* source,
{
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.empty()) {
- strcpy(res, result.c_str());
- }
- res[result.size()] = '\0';
- return res;
+ std::string const& result =
+ mf->ExpandVariablesInString(barf, escapeQuotes != 0, atOnly != 0);
+ return strdup(result.c_str());
}
int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs,
@@ -423,8 +419,7 @@ int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs,
lff.Name = name;
for (int i = 0; i < numArgs; ++i) {
// Assume all arguments are quoted.
- lff.Arguments.push_back(
- cmListFileArgument(args[i], cmListFileArgument::Quoted, 0));
+ lff.Arguments.emplace_back(args[i], cmListFileArgument::Quoted, 0);
}
cmExecutionStatus status;
return mf->ExecuteCommand(lff, status);
@@ -440,10 +435,10 @@ void CCONV cmExpandSourceListArguments(void* arg, int numArgs,
std::vector<std::string> result;
int i;
for (i = 0; i < numArgs; ++i) {
- result.push_back(args[i]);
+ result.emplace_back(args[i]);
}
int resargc = static_cast<int>(result.size());
- char** resargv = CM_NULLPTR;
+ char** resargv = nullptr;
if (resargc) {
resargv = (char**)malloc(resargc * sizeof(char*));
}
@@ -460,9 +455,7 @@ void CCONV cmFreeArguments(int argc, char** argv)
for (i = 0; i < argc; ++i) {
free(argv[i]);
}
- if (argv) {
- free(argv);
- }
+ free(argv);
}
int CCONV cmGetTotalArgumentSize(int argc, char** argv)
@@ -481,11 +474,7 @@ int CCONV cmGetTotalArgumentSize(int argc, char** argv)
// API for source files.
struct cmCPluginAPISourceFile
{
- cmCPluginAPISourceFile()
- : RealSourceFile(CM_NULLPTR)
- {
- }
- cmSourceFile* RealSourceFile;
+ cmSourceFile* RealSourceFile = nullptr;
std::string SourceName;
std::string SourceExtension;
std::string FullPath;
@@ -502,24 +491,27 @@ public:
typedef std::map<cmSourceFile*, cmCPluginAPISourceFile*> derived;
typedef derived::iterator iterator;
typedef derived::value_type value_type;
+ cmCPluginAPISourceFileMap() = default;
~cmCPluginAPISourceFileMap()
{
- for (iterator i = this->begin(); i != this->end(); ++i) {
- delete i->second;
+ for (auto const& i : *this) {
+ delete i.second;
}
}
+ cmCPluginAPISourceFileMap(const cmCPluginAPISourceFileMap&) = delete;
+ cmCPluginAPISourceFileMap& operator=(const cmCPluginAPISourceFileMap&) =
+ delete;
};
cmCPluginAPISourceFileMap cmCPluginAPISourceFiles;
void* CCONV cmCreateSourceFile(void)
{
- return (void*)new cmCPluginAPISourceFile;
+ return new cmCPluginAPISourceFile;
}
void* CCONV cmCreateNewSourceFile(void*)
{
- cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile;
- return (void*)sf;
+ return new cmCPluginAPISourceFile;
}
void CCONV cmDestroySourceFile(void* arg)
@@ -552,9 +544,9 @@ void CCONV* cmGetSource(void* arg, const char* name)
cmCPluginAPISourceFileMap::value_type entry(rsf, sf);
i = cmCPluginAPISourceFiles.insert(entry).first;
}
- return (void*)i->second;
+ return i->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
void* CCONV cmAddSource(void* arg, void* arg2)
@@ -562,15 +554,14 @@ void* CCONV cmAddSource(void* arg, void* arg2)
cmMakefile* mf = static_cast<cmMakefile*>(arg);
cmCPluginAPISourceFile* osf = static_cast<cmCPluginAPISourceFile*>(arg2);
if (osf->FullPath.empty()) {
- return CM_NULLPTR;
+ return nullptr;
}
// 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);
+ for (std::string const& d : osf->Depends) {
+ rsf->AddDepend(d);
}
// Create the proxy for the real source file.
@@ -582,7 +573,7 @@ void* CCONV cmAddSource(void* arg, void* arg2)
// Store the proxy in the map so it can be re-used and deleted later.
cmCPluginAPISourceFiles[rsf] = sf;
- return (void*)sf;
+ return sf;
}
const char* CCONV cmSourceFileGetSourceName(void* arg)
@@ -638,7 +629,7 @@ void CCONV cmSourceFileAddDepend(void* arg, const char* depend)
if (cmSourceFile* rsf = sf->RealSourceFile) {
rsf->AddDepend(depend);
} else {
- sf->Depends.push_back(depend);
+ sf->Depends.emplace_back(depend);
}
}
@@ -658,10 +649,10 @@ void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir,
std::vector<std::string> headerExts;
int i;
for (i = 0; i < numSourceExtensions; ++i) {
- sourceExts.push_back(sourceExtensions[i]);
+ sourceExts.emplace_back(sourceExtensions[i]);
}
for (i = 0; i < numHeaderExtensions; ++i) {
- headerExts.push_back(headerExtensions[i]);
+ headerExts.emplace_back(headerExtensions[i]);
}
// Save the original name given.
@@ -674,7 +665,7 @@ void CCONV cmSourceFileSetName(void* arg, const char* name, const char* 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())) {
+ if (cmSystemTools::FileExists(hname)) {
sf->SourceName = cmSystemTools::GetFilenamePath(name);
if (!sf->SourceName.empty()) {
sf->SourceName += "/";
@@ -696,26 +687,24 @@ void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir,
}
// Next, try the various source extensions
- for (std::vector<std::string>::const_iterator ext = sourceExts.begin();
- ext != sourceExts.end(); ++ext) {
+ for (std::string const& ext : sourceExts) {
hname = pathname;
hname += ".";
- hname += *ext;
- if (cmSystemTools::FileExists(hname.c_str())) {
- sf->SourceExtension = *ext;
+ hname += ext;
+ if (cmSystemTools::FileExists(hname)) {
+ 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) {
+ for (std::string const& ext : headerExts) {
hname = pathname;
hname += ".";
- hname += *ext;
- if (cmSystemTools::FileExists(hname.c_str())) {
- sf->SourceExtension = *ext;
+ hname += ext;
+ if (cmSystemTools::FileExists(hname)) {
+ sf->SourceExtension = ext;
sf->FullPath = hname;
return;
}
@@ -724,15 +713,13 @@ void CCONV cmSourceFileSetName(void* arg, const char* name, const char* dir,
std::ostringstream 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::string const& ext : sourceExts) {
+ e << " ." << ext;
}
- for (std::vector<std::string>::const_iterator ext = headerExts.begin();
- ext != headerExts.end(); ++ext) {
- e << " ." << *ext;
+ for (std::string const& ext : headerExts) {
+ e << " ." << ext;
}
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
}
void CCONV cmSourceFileSetName2(void* arg, const char* name, const char* dir,
@@ -763,25 +750,19 @@ void CCONV cmSourceFileSetName2(void* arg, const char* name, const char* dir,
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;
+ return strdup(sres.c_str());
}
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;
+ return strdup(sres.c_str());
}
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;
+ return strdup(sres.c_str());
}
void CCONV cmCopyFileIfDifferent(const char* name1, const char* name2)
diff --git a/Source/cmCPluginAPI.h b/Source/cmCPluginAPI.h
index 88b81c6c1..adc57a202 100644
--- a/Source/cmCPluginAPI.h
+++ b/Source/cmCPluginAPI.h
@@ -19,9 +19,9 @@ extern "C" {
#endif
#ifdef __WATCOMC__
-#define CCONV __cdecl
+# define CCONV __cdecl
#else
-#define CCONV
+# define CCONV
#endif
/*=========================================================================
this is the structure of function entry points that a plugin may call. This
@@ -161,9 +161,9 @@ typedef struct
CM_PLUGIN_EXPORT should be used by plugins
=========================================================================*/
#ifdef _WIN32
-#define CM_PLUGIN_EXPORT __declspec(dllexport)
+# define CM_PLUGIN_EXPORT __declspec(dllexport)
#else
-#define CM_PLUGIN_EXPORT
+# define CM_PLUGIN_EXPORT
#endif
/*=========================================================================
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx
index e2605561a..d1226c3c8 100644
--- a/Source/cmCTest.cxx
+++ b/Source/cmCTest.cxx
@@ -9,11 +9,13 @@
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/Process.h"
-#include "cmsys/String.hxx"
#include "cmsys/SystemInformation.hxx"
+#include <algorithm>
+#include <chrono>
#include <ctype.h>
#include <iostream>
#include <map>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
@@ -22,6 +24,11 @@
#include <time.h>
#include <utility>
#include <vector>
+#if defined(_WIN32)
+# include <windows.h> // IWYU pragma: keep
+#else
+# include <unistd.h> // IWYU pragma: keep
+#endif
#include "cmAlgorithms.h"
#include "cmCTestBuildAndTestHandler.h"
@@ -36,7 +43,6 @@
#include "cmCTestTestHandler.h"
#include "cmCTestUpdateHandler.h"
#include "cmCTestUploadHandler.h"
-#include "cmCurl.h"
#include "cmDynamicLoader.h"
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
@@ -49,33 +55,170 @@
#include "cmVersion.h"
#include "cmVersionConfig.h"
#include "cmXMLWriter.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
#if defined(__BEOS__) || defined(__HAIKU__)
-#include <be/kernel/OS.h> /* disable_debugger() API. */
+# include <be/kernel/OS.h> /* disable_debugger() API. */
#endif
-#define DEBUGOUT \
- std::cout << __LINE__ << " "; \
- std::cout
-#define DEBUGERR \
- std::cerr << __LINE__ << " "; \
- std::cerr
+struct cmCTest::Private
+{
+ /** Representation of one part. */
+ struct PartInfo
+ {
+ void SetName(const std::string& name) { this->Name = name; }
+ const std::string& GetName() const { return this->Name; }
+
+ void Enable() { this->Enabled = true; }
+ explicit operator bool() const { return this->Enabled; }
+
+ std::vector<std::string> SubmitFiles;
+
+ private:
+ bool Enabled = false;
+ std::string Name;
+ };
+
+ int RepeatTests = 1; // default to run each test once
+ bool RepeatUntilFail = false;
+ std::string ConfigType;
+ std::string ScheduleType;
+ std::chrono::system_clock::time_point StopTime;
+ bool TestProgressOutput = false;
+ bool Verbose = false;
+ bool ExtraVerbose = false;
+ bool ProduceXML = false;
+ bool LabelSummary = true;
+ bool SubprojectSummary = true;
+ bool UseHTTP10 = false;
+ bool PrintLabels = false;
+ bool Failover = false;
+
+ bool FlushTestProgressLine = false;
+
+ bool ForceNewCTestProcess = false;
+
+ bool RunConfigurationScript = false;
+
+ // these are helper classes
+ cmCTestBuildHandler BuildHandler;
+ cmCTestBuildAndTestHandler BuildAndTestHandler;
+ cmCTestCoverageHandler CoverageHandler;
+ cmCTestScriptHandler ScriptHandler;
+ cmCTestTestHandler TestHandler;
+ cmCTestUpdateHandler UpdateHandler;
+ cmCTestConfigureHandler ConfigureHandler;
+ cmCTestMemCheckHandler MemCheckHandler;
+ cmCTestSubmitHandler SubmitHandler;
+ cmCTestUploadHandler UploadHandler;
+
+ std::vector<cmCTestGenericHandler*> GetTestingHandlers()
+ {
+ return { &this->BuildHandler, &this->BuildAndTestHandler,
+ &this->CoverageHandler, &this->ScriptHandler,
+ &this->TestHandler, &this->UpdateHandler,
+ &this->ConfigureHandler, &this->MemCheckHandler,
+ &this->SubmitHandler, &this->UploadHandler };
+ }
+
+ std::map<std::string, cmCTestGenericHandler*> GetNamedTestingHandlers()
+ {
+ return { { "build", &this->BuildHandler },
+ { "buildtest", &this->BuildAndTestHandler },
+ { "coverage", &this->CoverageHandler },
+ { "script", &this->ScriptHandler },
+ { "test", &this->TestHandler },
+ { "update", &this->UpdateHandler },
+ { "configure", &this->ConfigureHandler },
+ { "memcheck", &this->MemCheckHandler },
+ { "submit", &this->SubmitHandler },
+ { "upload", &this->UploadHandler } };
+ }
+
+ bool ShowOnly = false;
+ bool OutputAsJson = false;
+ int OutputAsJsonVersion = 1;
+
+ // 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.
+ std::map<std::string, std::string> CTestConfiguration;
+ std::map<std::string, std::string> CTestConfigurationOverwrites;
+
+ PartInfo Parts[PartCount];
+ std::map<std::string, Part> PartMap;
+
+ std::string CurrentTag;
+ bool TomorrowTag = false;
+
+ int TestModel = cmCTest::EXPERIMENTAL;
+ std::string SpecificTrack;
+
+ cmDuration TimeOut = cmDuration::zero();
+
+ cmDuration GlobalTimeout = cmDuration::zero();
+
+ int MaxTestNameWidth = 30;
+
+ int ParallelLevel = 1;
+ bool ParallelLevelSetInCli = false;
+
+ unsigned long TestLoad = 0;
+
+ int CompatibilityMode;
+
+ // information for the --build-and-test options
+ std::string BinaryDir;
+
+ std::string NotesFiles;
+
+ bool InteractiveDebugMode = true;
+
+ bool ShortDateFormat = true;
+
+ bool CompressXMLFiles = false;
+ bool CompressTestOutput = true;
+
+ // By default we write output to the process output streams.
+ std::ostream* StreamOut = &std::cout;
+ std::ostream* StreamErr = &std::cerr;
+
+ bool SuppressUpdatingCTestConfiguration = false;
+
+ bool Debug = false;
+ bool ShowLineNumbers = false;
+ bool Quiet = false;
+
+ std::string BuildID;
+
+ std::vector<std::string> InitialCommandLineArguments;
+
+ int SubmitIndex = 0;
+
+ cmGeneratedFileStream* OutputLogFile = nullptr;
+ int OutputLogFileLastTag = -1;
+
+ bool OutputTestOutputOnTestFailure = false;
+ bool OutputColorCode = cmCTest::ColoredOutputSupportedByConsole();
+
+ std::map<std::string, std::string> Definitions;
+};
struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag)
{
struct tm* lctime;
- time_t tctime = time(CM_NULLPTR);
+ time_t tctime = time(nullptr);
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);
+ 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
@@ -84,7 +227,7 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag)
// 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(CM_NULLPTR);
+ tctime = time(nullptr);
cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl);
const int dayLength = 24 * 60 * 60;
@@ -97,16 +240,17 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag)
// 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);
+ 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);
+ 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;
@@ -115,6 +259,11 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag)
return lctime;
}
+bool cmCTest::GetTomorrowTag() const
+{
+ return this->Impl->TomorrowTag;
+}
+
std::string cmCTest::CleanString(const std::string& str)
{
std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
@@ -130,11 +279,11 @@ std::string cmCTest::CleanString(const std::string& str)
std::string cmCTest::CurrentTime()
{
- time_t currenttime = time(CM_NULLPTR);
+ time_t currenttime = time(nullptr);
struct tm* t = localtime(&currenttime);
// return ::CleanString(ctime(&currenttime));
char current_time[1024];
- if (this->ShortDateFormat) {
+ if (this->Impl->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);
@@ -146,101 +295,19 @@ std::string cmCTest::CurrentTime()
std::string cmCTest::GetCostDataFile()
{
std::string fname = this->GetCTestConfiguration("CostDataFile");
- if (fname == "") {
+ if (fname.empty()) {
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 const& fields,
- std::string const& putFile, int timeout)
-{
- CURL* curl;
- FILE* file;
- ::curl_global_init(CURL_GLOBAL_ALL);
- curl = ::curl_easy_init();
- cmCurlSetCAInfo(curl);
-
- // 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, "rb");
- ::curl_easy_setopt(curl, CURLOPT_INFILE, file);
- // fall through to append GET fields
- case cmCTest::HTTP_GET:
- if (!fields.empty()) {
- 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)
-{
- std::ostringstream 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, CM_NULLPTR, 16)));
+ out.append(1, char(strtoul(buf, nullptr, 16)));
c += 2;
} else {
out.append(1, *c);
@@ -250,88 +317,39 @@ std::string cmCTest::DecodeURL(const std::string& in)
}
cmCTest::cmCTest()
-{
- this->LabelSummary = true;
- this->ParallelLevel = 1;
- this->ParallelLevelSetInCli = false;
- this->TestLoad = 0;
- 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->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 = CM_NULLPTR;
- this->OutputLogFileLastTag = -1;
- this->SuppressUpdatingCTestConfiguration = false;
- this->DartVersion = 1;
- this->DropSiteCDash = false;
- this->OutputTestOutputOnTestFailure = false;
- this->RepeatTests = 1; // default to run each test once
- this->RepeatUntilFail = false;
- std::string outOnFail;
- if (cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE", outOnFail)) {
- this->OutputTestOutputOnTestFailure =
- !cmSystemTools::IsOff(outOnFail.c_str());
- }
- 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");
+ : Impl(new Private)
+{
+ std::string envValue;
+ if (cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE", envValue)) {
+ this->Impl->OutputTestOutputOnTestFailure =
+ !cmSystemTools::IsOff(envValue);
+ }
+ envValue.clear();
+ if (cmSystemTools::GetEnv("CTEST_PROGRESS_OUTPUT", envValue)) {
+ this->Impl->TestProgressOutput = !cmSystemTools::IsOff(envValue);
+ }
+
+ this->Impl->Parts[PartStart].SetName("Start");
+ this->Impl->Parts[PartUpdate].SetName("Update");
+ this->Impl->Parts[PartConfigure].SetName("Configure");
+ this->Impl->Parts[PartBuild].SetName("Build");
+ this->Impl->Parts[PartTest].SetName("Test");
+ this->Impl->Parts[PartCoverage].SetName("Coverage");
+ this->Impl->Parts[PartMemCheck].SetName("MemCheck");
+ this->Impl->Parts[PartSubmit].SetName("Submit");
+ this->Impl->Parts[PartNotes].SetName("Notes");
+ this->Impl->Parts[PartExtraFiles].SetName("ExtraFiles");
+ this->Impl->Parts[PartUpload].SetName("Upload");
+ this->Impl->Parts[PartDone].SetName("Done");
// 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->Impl
+ ->PartMap[cmSystemTools::LowerCase(this->Impl->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);
+ for (auto& handler : this->Impl->GetTestingHandlers()) {
+ handler->SetCTestInstance(this);
}
// Make sure we can capture the build tool output.
@@ -340,31 +358,40 @@ cmCTest::cmCTest()
cmCTest::~cmCTest()
{
- cmDeleteAll(this->TestingHandlers);
- this->SetOutputLogFileName(CM_NULLPTR);
+ delete this->Impl->OutputLogFile;
+}
+
+int cmCTest::GetParallelLevel() const
+{
+ return this->Impl->ParallelLevel;
}
void cmCTest::SetParallelLevel(int level)
{
- this->ParallelLevel = level < 1 ? 1 : level;
+ this->Impl->ParallelLevel = level < 1 ? 1 : level;
+}
+
+unsigned long cmCTest::GetTestLoad() const
+{
+ return this->Impl->TestLoad;
}
void cmCTest::SetTestLoad(unsigned long load)
{
- this->TestLoad = load;
+ this->Impl->TestLoad = load;
}
bool cmCTest::ShouldCompressTestOutput()
{
- return this->CompressTestOutput;
+ return this->Impl->CompressTestOutput;
}
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()) {
+ auto const i = this->Impl->PartMap.find(lower_name);
+ if (i != this->Impl->PartMap.end()) {
return i->second;
}
@@ -380,29 +407,30 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
}
cmCTestOptionalLog(this, DEBUG, "Here: " << __LINE__ << std::endl, quiet);
- if (!this->InteractiveDebugMode) {
+ if (!this->Impl->InteractiveDebugMode) {
this->BlockTestErrorDiagnostics();
} else {
cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1");
}
- this->BinaryDir = binary_dir;
- cmSystemTools::ConvertToUnixSlashes(this->BinaryDir);
+ this->Impl->BinaryDir = binary_dir;
+ cmSystemTools::ConvertToUnixSlashes(this->Impl->BinaryDir);
this->UpdateCTestConfiguration();
cmCTestOptionalLog(this, DEBUG, "Here: " << __LINE__ << std::endl, quiet);
- if (this->ProduceXML) {
+ if (this->Impl->ProduceXML) {
cmCTestOptionalLog(this, DEBUG, "Here: " << __LINE__ << std::endl, quiet);
- cmCTestOptionalLog(
- this, OUTPUT, " Site: "
- << this->GetCTestConfiguration("Site") << std::endl
- << " Build name: "
- << cmCTest::SafeBuildIdField(this->GetCTestConfiguration("BuildName"))
- << std::endl,
- quiet);
+ cmCTestOptionalLog(this, OUTPUT,
+ " Site: "
+ << this->GetCTestConfiguration("Site") << std::endl
+ << " Build name: "
+ << cmCTest::SafeBuildIdField(
+ this->GetCTestConfiguration("BuildName"))
+ << std::endl,
+ quiet);
cmCTestOptionalLog(this, DEBUG, "Produce XML is on" << std::endl, quiet);
- if (this->TestModel == cmCTest::NIGHTLY &&
+ if (this->Impl->TestModel == cmCTest::NIGHTLY &&
this->GetCTestConfiguration("NightlyStartTime").empty()) {
cmCTestOptionalLog(
this, WARNING,
@@ -416,36 +444,36 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
}
}
- cmake cm(cmake::RoleScript);
+ cmake cm(cmake::RoleScript, cmState::CTest);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
- CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
- if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(),
- mf.get())) {
+ cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+ if (!this->ReadCustomConfigurationFileTree(this->Impl->BinaryDir.c_str(),
+ &mf)) {
cmCTestOptionalLog(
this, DEBUG, "Cannot find custom configuration file tree" << std::endl,
quiet);
return 0;
}
- if (this->ProduceXML) {
+ if (this->Impl->ProduceXML) {
// Verify "Testing" directory exists:
//
- std::string testingDir = this->BinaryDir + "/Testing";
- if (cmSystemTools::FileExists(testingDir.c_str())) {
+ std::string testingDir = this->Impl->BinaryDir + "/Testing";
+ if (cmSystemTools::FileExists(testingDir)) {
if (!cmSystemTools::FileIsDirectory(testingDir)) {
- cmCTestLog(this, ERROR_MESSAGE, "File "
- << testingDir
- << " is in the place of the testing directory"
- << std::endl);
+ 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);
+ if (!cmSystemTools::MakeDirectory(testingDir)) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Cannot create directory " << testingDir << std::endl);
return 0;
}
}
@@ -462,8 +490,8 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
std::string tag;
if (createNewTag) {
- time_t tctime = time(CM_NULLPTR);
- if (this->TomorrowTag) {
+ time_t tctime = time(nullptr);
+ if (this->Impl->TomorrowTag) {
tctime += (24 * 60 * 60);
}
struct tm* lctime = gmtime(&tctime);
@@ -477,26 +505,32 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
&min);
if (year != lctime->tm_year + 1900 || mon != lctime->tm_mon + 1 ||
day != lctime->tm_mday) {
- tag = "";
+ tag.clear();
}
- std::string tagmode;
- if (cmSystemTools::GetLineFromStream(tfin, tagmode)) {
- if (tagmode.size() > 4 && !this->Parts[PartStart]) {
- this->TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
- }
+ std::string track;
+ if (cmSystemTools::GetLineFromStream(tfin, track) &&
+ !this->Impl->Parts[PartStart] && !command) {
+ this->Impl->SpecificTrack = track;
+ }
+ std::string model;
+ if (cmSystemTools::GetLineFromStream(tfin, model) &&
+ !this->Impl->Parts[PartStart] && !command) {
+ this->Impl->TestModel = GetTestModelFromString(model.c_str());
}
tfin.close();
}
- if (tag.empty() || (CM_NULLPTR != command) || this->Parts[PartStart]) {
+ if (tag.empty() || (nullptr != command) ||
+ this->Impl->Parts[PartStart]) {
cmCTestOptionalLog(
this, DEBUG,
"TestModel: " << this->GetTestModelString() << std::endl, quiet);
- cmCTestOptionalLog(
- this, DEBUG, "TestModel: " << this->TestModel << std::endl, quiet);
- if (this->TestModel == cmCTest::NIGHTLY) {
+ cmCTestOptionalLog(this, DEBUG,
+ "TestModel: " << this->Impl->TestModel << std::endl,
+ quiet);
+ if (this->Impl->TestModel == cmCTest::NIGHTLY) {
lctime = this->GetNightlyTime(
this->GetCTestConfiguration("NightlyStartTime"),
- this->TomorrowTag);
+ this->Impl->TomorrowTag);
}
char datestring[100];
sprintf(datestring, "%04d%02d%02d-%02d%02d", lctime->tm_year + 1900,
@@ -507,34 +541,88 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
if (ofs) {
ofs << tag << std::endl;
ofs << this->GetTestModelString() << std::endl;
+ switch (this->Impl->TestModel) {
+ case cmCTest::EXPERIMENTAL:
+ ofs << "Experimental" << std::endl;
+ break;
+ case cmCTest::NIGHTLY:
+ ofs << "Nightly" << std::endl;
+ break;
+ case cmCTest::CONTINUOUS:
+ ofs << "Continuous" << std::endl;
+ break;
+ }
}
ofs.close();
- if (CM_NULLPTR == command) {
- cmCTestOptionalLog(this, OUTPUT, "Create new tag: "
- << tag << " - " << this->GetTestModelString()
- << std::endl,
+ if (nullptr == command) {
+ cmCTestOptionalLog(this, OUTPUT,
+ "Create new tag: " << tag << " - "
+ << this->GetTestModelString()
+ << std::endl,
quiet);
}
}
} else {
+ std::string track;
+ std::string modelStr;
+ int model = cmCTest::UNKNOWN;
+
if (tfin) {
cmSystemTools::GetLineFromStream(tfin, tag);
+ cmSystemTools::GetLineFromStream(tfin, track);
+ if (cmSystemTools::GetLineFromStream(tfin, modelStr)) {
+ model = GetTestModelFromString(modelStr.c_str());
+ }
tfin.close();
}
if (tag.empty()) {
- cmCTestLog(this, ERROR_MESSAGE, "Cannot read existing TAG file in "
- << testingDir << std::endl);
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Cannot read existing TAG file in " << testingDir
+ << std::endl);
return 0;
}
- cmCTestOptionalLog(this, OUTPUT, " Use existing tag: "
- << tag << " - " << this->GetTestModelString()
- << std::endl,
+ if (this->Impl->TestModel == cmCTest::UNKNOWN) {
+ if (model == cmCTest::UNKNOWN) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "TAG file does not contain model and "
+ "no model specified in start command"
+ << std::endl);
+ return 0;
+ }
+
+ this->SetTestModel(model);
+ }
+
+ if (model != this->Impl->TestModel && model != cmCTest::UNKNOWN &&
+ this->Impl->TestModel != cmCTest::UNKNOWN) {
+ cmCTestOptionalLog(this, WARNING,
+ "Model given in TAG does not match "
+ "model given in ctest_start()"
+ << std::endl,
+ quiet);
+ }
+
+ if (!this->Impl->SpecificTrack.empty() &&
+ track != this->Impl->SpecificTrack) {
+ cmCTestOptionalLog(this, WARNING,
+ "Track given in TAG does not match "
+ "track given in ctest_start()"
+ << std::endl,
+ quiet);
+ } else {
+ this->Impl->SpecificTrack = track;
+ }
+
+ cmCTestOptionalLog(this, OUTPUT,
+ " Use existing tag: " << tag << " - "
+ << this->GetTestModelString()
+ << std::endl,
quiet);
}
- this->CurrentTag = tag;
+ this->Impl->CurrentTag = tag;
}
return 1;
@@ -544,10 +632,9 @@ 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;
+ this->Impl->BuildID = "";
for (Part p = PartStart; p != PartCount; p = Part(p + 1)) {
- this->Parts[p].SubmitFiles.clear();
+ this->Impl->Parts[p].SubmitFiles.clear();
}
cmMakefile* mf = command->GetMakefile();
@@ -561,32 +648,24 @@ bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command)
bld_dir_fname += "/CTestConfig.cmake";
cmSystemTools::ConvertToUnixSlashes(bld_dir_fname);
- if (cmSystemTools::FileExists(bld_dir_fname.c_str())) {
+ if (cmSystemTools::FileExists(bld_dir_fname)) {
fname = bld_dir_fname;
- } else if (cmSystemTools::FileExists(src_dir_fname.c_str())) {
+ } else if (cmSystemTools::FileExists(src_dir_fname)) {
fname = src_dir_fname;
}
if (!fname.empty()) {
- cmCTestOptionalLog(this, OUTPUT, " Reading ctest configuration file: "
- << fname << std::endl,
+ cmCTestOptionalLog(this, OUTPUT,
+ " Reading ctest configuration file: " << fname
+ << std::endl,
command->ShouldBeQuiet());
- bool readit = mf->ReadDependentFile(fname.c_str());
+ bool readit = mf->ReadDependentFile(fname);
if (!readit) {
std::string m = "Could not find include file: ";
m += fname;
command->SetError(m);
return false;
}
- } else {
- cmCTestOptionalLog(this, WARNING,
- "Cannot locate CTest configuration: in BuildDirectory: "
- << bld_dir_fname << std::endl,
- command->ShouldBeQuiet());
- cmCTestOptionalLog(
- this, WARNING, "Cannot locate CTest configuration: in SourceDirectory: "
- << src_dir_fname << std::endl,
- command->ShouldBeQuiet());
}
this->SetCTestConfigurationFromCMakeVariable(mf, "NightlyStartTime",
@@ -596,52 +675,38 @@ bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command)
command->ShouldBeQuiet());
this->SetCTestConfigurationFromCMakeVariable(
mf, "BuildName", "CTEST_BUILD_NAME", command->ShouldBeQuiet());
- 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;
}
- cmCTestOptionalLog(this, OUTPUT, " Use "
- << this->GetTestModelString()
- << " tag: " << this->GetCurrentTag() << std::endl,
+ cmCTestOptionalLog(this, OUTPUT,
+ " Use " << this->GetTestModelString() << " tag: "
+ << this->GetCurrentTag() << std::endl,
command->ShouldBeQuiet());
return true;
}
bool cmCTest::UpdateCTestConfiguration()
{
- if (this->SuppressUpdatingCTestConfiguration) {
+ if (this->Impl->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";
- }
+ std::string fileName = this->Impl->BinaryDir + "/CTestConfiguration.ini";
+ if (!cmSystemTools::FileExists(fileName)) {
+ fileName = this->Impl->BinaryDir + "/DartConfiguration.tcl";
}
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
"UpdateCTestConfiguration from :" << fileName << "\n");
- if (!cmSystemTools::FileExists(fileName.c_str())) {
+ if (!cmSystemTools::FileExists(fileName)) {
// No need to exit if we are not producing XML
- if (this->ProduceXML) {
- cmCTestLog(this, ERROR_MESSAGE, "Cannot find file: " << fileName
- << std::endl);
+ if (this->Impl->ProduceXML) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Cannot find file: " << fileName << std::endl);
return false;
}
} else {
- cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Parse Config file:" << fileName
- << "\n");
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
+ "Parse Config file:" << fileName << "\n");
// parse the dart test file
cmsys::ifstream fin(fileName.c_str());
@@ -658,7 +723,7 @@ bool cmCTest::UpdateCTestConfiguration()
if (line.empty()) {
continue;
}
- while (fin && (line[line.size() - 1] == '\\')) {
+ while (fin && (line.back() == '\\')) {
line = line.substr(0, line.size() - 1);
buffer[0] = 0;
fin.getline(buffer, 1023);
@@ -674,15 +739,16 @@ bool cmCTest::UpdateCTestConfiguration()
}
std::string key = line.substr(0, cpos);
std::string value = cmCTest::CleanString(line.substr(cpos + 1));
- this->CTestConfiguration[key] = value;
+ this->Impl->CTestConfiguration[key] = value;
}
fin.close();
}
if (!this->GetCTestConfiguration("BuildDirectory").empty()) {
- this->BinaryDir = this->GetCTestConfiguration("BuildDirectory");
- cmSystemTools::ChangeDirectory(this->BinaryDir);
+ this->Impl->BinaryDir = this->GetCTestConfiguration("BuildDirectory");
+ cmSystemTools::ChangeDirectory(this->Impl->BinaryDir);
}
- this->TimeOut = atoi(this->GetCTestConfiguration("TimeOut").c_str());
+ this->Impl->TimeOut =
+ std::chrono::seconds(atoi(this->GetCTestConfiguration("TimeOut").c_str()));
std::string const& testLoad = this->GetCTestConfiguration("TestLoad");
if (!testLoad.empty()) {
unsigned long load;
@@ -693,9 +759,9 @@ bool cmCTest::UpdateCTestConfiguration()
"Invalid value for 'Test Load' : " << testLoad << std::endl);
}
}
- if (this->ProduceXML) {
- this->CompressXMLFiles = cmSystemTools::IsOn(
- this->GetCTestConfiguration("CompressSubmission").c_str());
+ if (this->Impl->ProduceXML) {
+ this->Impl->CompressXMLFiles =
+ cmSystemTools::IsOn(this->GetCTestConfiguration("CompressSubmission"));
}
return true;
}
@@ -713,26 +779,32 @@ void cmCTest::BlockTestErrorDiagnostics()
void cmCTest::SetTestModel(int mode)
{
- this->InteractiveDebugMode = false;
- this->TestModel = mode;
+ this->Impl->InteractiveDebugMode = false;
+ this->Impl->TestModel = mode;
+}
+
+int cmCTest::GetTestModel() const
+{
+ return this->Impl->TestModel;
}
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();
+ this->Impl->Parts[p].Enable();
}
return true;
}
Part p = this->GetPartFromName(ttype);
if (p != PartCount) {
- this->Parts[p].Enable();
+ this->Impl->Parts[p].Enable();
return true;
}
if (report) {
- cmCTestLog(this, ERROR_MESSAGE, "Don't know about test \""
- << ttype << "\" yet..." << std::endl);
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Don't know about test \"" << ttype << "\" yet..."
+ << std::endl);
}
return false;
}
@@ -744,33 +816,34 @@ void cmCTest::Finalize()
bool cmCTest::OpenOutputFile(const std::string& path, const std::string& name,
cmGeneratedFileStream& stream, bool compress)
{
- std::string testingDir = this->BinaryDir + "/Testing";
+ std::string testingDir = this->Impl->BinaryDir + "/Testing";
if (!path.empty()) {
testingDir += "/" + path;
}
- if (cmSystemTools::FileExists(testingDir.c_str())) {
+ if (cmSystemTools::FileExists(testingDir)) {
if (!cmSystemTools::FileIsDirectory(testingDir)) {
- cmCTestLog(this, ERROR_MESSAGE, "File "
- << testingDir << " is in the place of the testing directory"
- << std::endl);
+ 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);
+ if (!cmSystemTools::MakeDirectory(testingDir)) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Cannot create directory " << testingDir << std::endl);
return false;
}
}
std::string filename = testingDir + "/" + name;
- stream.Open(filename.c_str());
+ stream.Open(filename);
if (!stream) {
- cmCTestLog(this, ERROR_MESSAGE, "Problem opening file: " << filename
- << std::endl);
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Problem opening file: " << filename << std::endl);
return false;
}
if (compress) {
- if (this->CompressXMLFiles) {
+ if (this->Impl->CompressXMLFiles) {
stream.SetCompression(true);
}
}
@@ -795,40 +868,59 @@ bool cmCTest::AddIfExists(Part part, const char* file)
bool cmCTest::CTestFileExists(const std::string& filename)
{
- std::string testingDir =
- this->BinaryDir + "/Testing/" + this->CurrentTag + "/" + filename;
- return cmSystemTools::FileExists(testingDir.c_str());
+ std::string testingDir = this->Impl->BinaryDir + "/Testing/" +
+ this->Impl->CurrentTag + "/" + filename;
+ return cmSystemTools::FileExists(testingDir);
}
-cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler)
+cmCTestBuildHandler* cmCTest::GetBuildHandler()
{
- cmCTest::t_TestingHandlers::iterator it =
- this->TestingHandlers.find(handler);
- if (it == this->TestingHandlers.end()) {
- return CM_NULLPTR;
- }
- it->second->Initialize();
- return it->second;
+ return &this->Impl->BuildHandler;
}
-cmCTestGenericHandler* cmCTest::GetHandler(const char* handler)
+cmCTestBuildAndTestHandler* cmCTest::GetBuildAndTestHandler()
{
- cmCTest::t_TestingHandlers::iterator it =
- this->TestingHandlers.find(handler);
- if (it == this->TestingHandlers.end()) {
- return CM_NULLPTR;
- }
- return it->second;
+ return &this->Impl->BuildAndTestHandler;
}
-int cmCTest::ExecuteHandler(const char* shandler)
+cmCTestCoverageHandler* cmCTest::GetCoverageHandler()
{
- cmCTestGenericHandler* handler = this->GetHandler(shandler);
- if (!handler) {
- return -1;
- }
- handler->Initialize();
- return handler->ProcessHandler();
+ return &this->Impl->CoverageHandler;
+}
+
+cmCTestScriptHandler* cmCTest::GetScriptHandler()
+{
+ return &this->Impl->ScriptHandler;
+}
+
+cmCTestTestHandler* cmCTest::GetTestHandler()
+{
+ return &this->Impl->TestHandler;
+}
+
+cmCTestUpdateHandler* cmCTest::GetUpdateHandler()
+{
+ return &this->Impl->UpdateHandler;
+}
+
+cmCTestConfigureHandler* cmCTest::GetConfigureHandler()
+{
+ return &this->Impl->ConfigureHandler;
+}
+
+cmCTestMemCheckHandler* cmCTest::GetMemCheckHandler()
+{
+ return &this->Impl->MemCheckHandler;
+}
+
+cmCTestSubmitHandler* cmCTest::GetSubmitHandler()
+{
+ return &this->Impl->SubmitHandler;
+}
+
+cmCTestUploadHandler* cmCTest::GetUploadHandler()
+{
+ return &this->Impl->UploadHandler;
}
int cmCTest::ProcessSteps()
@@ -838,10 +930,11 @@ int cmCTest::ProcessSteps()
int update_count = 0;
for (Part p = PartStart; notest && p != PartCount; p = Part(p + 1)) {
- notest = !this->Parts[p];
+ notest = !this->Impl->Parts[p];
}
- if (this->Parts[PartUpdate] && (this->GetRemainingTimeAllowed() - 120 > 0)) {
- cmCTestGenericHandler* uphandler = this->GetHandler("update");
+ if (this->Impl->Parts[PartUpdate] &&
+ (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
+ cmCTestUpdateHandler* uphandler = this->GetUpdateHandler();
uphandler->SetPersistentOption(
"SourceDirectory",
this->GetCTestConfiguration("SourceDirectory").c_str());
@@ -850,44 +943,45 @@ int cmCTest::ProcessSteps()
res |= cmCTest::UPDATE_ERRORS;
}
}
- if (this->TestModel == cmCTest::CONTINUOUS && !update_count) {
+ if (this->Impl->TestModel == cmCTest::CONTINUOUS && !update_count) {
return 0;
}
- if (this->Parts[PartConfigure] &&
- (this->GetRemainingTimeAllowed() - 120 > 0)) {
- if (this->GetHandler("configure")->ProcessHandler() < 0) {
+ if (this->Impl->Parts[PartConfigure] &&
+ (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
+ if (this->GetConfigureHandler()->ProcessHandler() < 0) {
res |= cmCTest::CONFIGURE_ERRORS;
}
}
- if (this->Parts[PartBuild] && (this->GetRemainingTimeAllowed() - 120 > 0)) {
+ if (this->Impl->Parts[PartBuild] &&
+ (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
this->UpdateCTestConfiguration();
- if (this->GetHandler("build")->ProcessHandler() < 0) {
+ if (this->GetBuildHandler()->ProcessHandler() < 0) {
res |= cmCTest::BUILD_ERRORS;
}
}
- if ((this->Parts[PartTest] || notest) &&
- (this->GetRemainingTimeAllowed() - 120 > 0)) {
+ if ((this->Impl->Parts[PartTest] || notest) &&
+ (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
this->UpdateCTestConfiguration();
- if (this->GetHandler("test")->ProcessHandler() < 0) {
+ if (this->GetTestHandler()->ProcessHandler() < 0) {
res |= cmCTest::TEST_ERRORS;
}
}
- if (this->Parts[PartCoverage] &&
- (this->GetRemainingTimeAllowed() - 120 > 0)) {
+ if (this->Impl->Parts[PartCoverage] &&
+ (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
this->UpdateCTestConfiguration();
- if (this->GetHandler("coverage")->ProcessHandler() < 0) {
+ if (this->GetCoverageHandler()->ProcessHandler() < 0) {
res |= cmCTest::COVERAGE_ERRORS;
}
}
- if (this->Parts[PartMemCheck] &&
- (this->GetRemainingTimeAllowed() - 120 > 0)) {
+ if (this->Impl->Parts[PartMemCheck] &&
+ (this->GetRemainingTimeAllowed() > std::chrono::minutes(2))) {
this->UpdateCTestConfiguration();
- if (this->GetHandler("memcheck")->ProcessHandler() < 0) {
+ if (this->GetMemCheckHandler()->ProcessHandler() < 0) {
res |= cmCTest::MEMORY_ERRORS;
}
}
if (!notest) {
- std::string notes_dir = this->BinaryDir + "/Testing/Notes";
+ std::string notes_dir = this->Impl->BinaryDir + "/Testing/Notes";
if (cmSystemTools::FileIsDirectory(notes_dir)) {
cmsys::Directory d;
d.Load(notes_dir);
@@ -895,26 +989,26 @@ int cmCTest::ProcessSteps()
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()) &&
+ if (cmSystemTools::FileExists(fullname) &&
!cmSystemTools::FileIsDirectory(fullname)) {
- if (!this->NotesFiles.empty()) {
- this->NotesFiles += ";";
+ if (!this->Impl->NotesFiles.empty()) {
+ this->Impl->NotesFiles += ";";
}
- this->NotesFiles += fullname;
- this->Parts[PartNotes].Enable();
+ this->Impl->NotesFiles += fullname;
+ this->Impl->Parts[PartNotes].Enable();
}
}
}
}
- if (this->Parts[PartNotes]) {
+ if (this->Impl->Parts[PartNotes]) {
this->UpdateCTestConfiguration();
- if (!this->NotesFiles.empty()) {
- this->GenerateNotesFile(this->NotesFiles.c_str());
+ if (!this->Impl->NotesFiles.empty()) {
+ this->GenerateNotesFile(this->Impl->NotesFiles.c_str());
}
}
- if (this->Parts[PartSubmit]) {
+ if (this->Impl->Parts[PartSubmit]) {
this->UpdateCTestConfiguration();
- if (this->GetHandler("submit")->ProcessHandler() < 0) {
+ if (this->GetSubmitHandler()->ProcessHandler() < 0) {
res |= cmCTest::SUBMIT_ERRORS;
}
}
@@ -926,10 +1020,10 @@ int cmCTest::ProcessSteps()
std::string cmCTest::GetTestModelString()
{
- if (!this->SpecificTrack.empty()) {
- return this->SpecificTrack;
+ if (!this->Impl->SpecificTrack.empty()) {
+ return this->Impl->SpecificTrack;
}
- switch (this->TestModel) {
+ switch (this->Impl->TestModel) {
case cmCTest::NIGHTLY:
return "Nightly";
case cmCTest::CONTINUOUS:
@@ -944,10 +1038,10 @@ int cmCTest::GetTestModelFromString(const char* str)
return cmCTest::EXPERIMENTAL;
}
std::string rstr = cmSystemTools::LowerCase(str);
- if (cmHasLiteralPrefix(rstr.c_str(), "cont")) {
+ if (cmHasLiteralPrefix(rstr, "cont")) {
return cmCTest::CONTINUOUS;
}
- if (cmHasLiteralPrefix(rstr.c_str(), "nigh")) {
+ if (cmHasLiteralPrefix(rstr, "nigh")) {
return cmCTest::NIGHTLY;
}
return cmCTest::EXPERIMENTAL;
@@ -958,8 +1052,8 @@ int cmCTest::GetTestModelFromString(const char* str)
//######################################################################
//######################################################################
-int cmCTest::RunMakeCommand(const char* command, std::string& output,
- int* retVal, const char* dir, int timeout,
+int cmCTest::RunMakeCommand(const std::string& command, std::string& output,
+ int* retVal, const char* dir, cmDuration timeout,
std::ostream& ofs, Encoding encoding)
{
// First generate the command and arguments
@@ -970,26 +1064,28 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output,
}
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.reserve(args.size() + 1);
+ for (std::string const& a : args) {
+ argv.push_back(a.c_str());
}
- argv.push_back(CM_NULLPTR);
+ argv.push_back(nullptr);
- output = "";
+ output.clear();
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 << "\"");
+ for (char const* arg : argv) {
+ if (!arg) {
+ break;
+ }
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << arg << "\"");
}
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl);
// Now create process object
cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
- cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_SetTimeout(cp, timeout.count());
cmsysProcess_Execute(cp);
// Initialize tick's
@@ -1001,14 +1097,15 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output,
int length;
cmProcessOutput processOutput(encoding);
std::string strdata;
- cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Each . represents "
- << tick_len << " bytes of output" << std::endl
- << " " << std::flush);
- while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) {
+ cmCTestLog(this, HANDLER_PROGRESS_OUTPUT,
+ " Each . represents " << tick_len << " bytes of output"
+ << std::endl
+ << " " << std::flush);
+ while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
processOutput.DecodeText(data, length, strdata);
- for (size_t cc = 0; cc < strdata.size(); ++cc) {
- if (strdata[cc] == 0) {
- strdata[cc] = '\n';
+ for (char& cc : strdata) {
+ if (cc == 0) {
+ cc = '\n';
}
}
output.append(strdata);
@@ -1037,10 +1134,11 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output,
ofs << cmCTestLogWrite(strdata.c_str(), strdata.size());
}
}
- cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Size of output: "
- << int(double(output.size()) / 1024.0) << "K" << std::endl);
+ cmCTestLog(this, HANDLER_PROGRESS_OUTPUT,
+ " Size of output: " << int(double(output.size()) / 1024.0) << "K"
+ << std::endl);
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
int result = cmsysProcess_GetState(cp);
@@ -1050,16 +1148,17 @@ int cmCTest::RunMakeCommand(const char* command, std::string& 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);
+ 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);
+ cmCTestLog(this, ERROR_MESSAGE,
+ "There was an error: " << cmsysProcess_GetErrorString(cp)
+ << std::endl);
}
cmsysProcess_Delete(cp);
@@ -1073,58 +1172,69 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output,
//######################################################################
int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
- int* retVal, std::ostream* log, double testTimeOut,
+ int* retVal, std::ostream* log, cmDuration testTimeOut,
std::vector<std::string>* environment, Encoding encoding)
{
bool modifyEnv = (environment && !environment->empty());
// determine how much time we have
- double timeout = this->GetRemainingTimeAllowed() - 120;
- if (this->TimeOut > 0 && this->TimeOut < timeout) {
- timeout = this->TimeOut;
+ cmDuration timeout = this->GetRemainingTimeAllowed();
+ if (timeout != cmCTest::MaxDuration()) {
+ timeout -= std::chrono::minutes(2);
+ }
+ if (this->Impl->TimeOut > cmDuration::zero() &&
+ this->Impl->TimeOut < timeout) {
+ timeout = this->Impl->TimeOut;
}
- if (testTimeOut > 0 && testTimeOut < this->GetRemainingTimeAllowed()) {
+ if (testTimeOut > cmDuration::zero() &&
+ testTimeOut < this->GetRemainingTimeAllowed()) {
timeout = testTimeOut;
}
// always have at least 1 second if we got to here
- if (timeout <= 0) {
- timeout = 1;
+ if (timeout <= cmDuration::zero()) {
+ timeout = std::chrono::seconds(1);
}
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
- "Test timeout computed to be: " << timeout << "\n");
+ "Test timeout computed to be: "
+ << (timeout == cmCTest::MaxDuration()
+ ? std::string("infinite")
+ : std::to_string(cmDurationTo<unsigned int>(timeout)))
+ << "\n");
if (cmSystemTools::SameFile(argv[0], cmSystemTools::GetCTestCommand()) &&
- !this->ForceNewCTestProcess) {
+ !this->Impl->ForceNewCTestProcess) {
cmCTest inst;
- inst.ConfigType = this->ConfigType;
- inst.TimeOut = timeout;
+ inst.Impl->ConfigType = this->Impl->ConfigType;
+ inst.Impl->TimeOut = timeout;
// Capture output of the child ctest.
std::ostringstream oss;
inst.SetStreams(&oss, &oss);
std::vector<std::string> args;
- for (unsigned int i = 0; i < argv.size(); ++i) {
- if (argv[i]) {
+ for (char const* i : argv) {
+ if (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");
+ if (strcmp(i, "--build-generator") == 0 &&
+ timeout != cmCTest::MaxDuration() &&
+ timeout > cmDuration::zero()) {
+ args.emplace_back("--test-timeout");
std::ostringstream msg;
- msg << timeout;
+ msg << cmDurationTo<unsigned int>(timeout);
args.push_back(msg.str());
}
- args.push_back(argv[i]);
+ args.emplace_back(i);
}
}
if (log) {
*log << "* Run internal CTest" << std::endl;
}
- CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv;
+ std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
if (modifyEnv) {
- saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
+ saveEnv = cm::make_unique<cmSystemTools::SaveRestoreEnvironment>();
cmSystemTools::AppendEnv(*environment);
}
@@ -1146,33 +1256,33 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
}
std::vector<char> tempOutput;
if (output) {
- *output = "";
+ output->clear();
}
- CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv;
+ std::unique_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
if (modifyEnv) {
- saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
+ saveEnv = cm::make_unique<cmSystemTools::SaveRestoreEnvironment>();
cmSystemTools::AppendEnv(*environment);
}
cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetCommand(cp, argv.data());
cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl);
if (cmSystemTools::GetRunCommandHideConsole()) {
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
}
- cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_SetTimeout(cp, timeout.count());
cmsysProcess_Execute(cp);
char* data;
int length;
cmProcessOutput processOutput(encoding);
std::string strdata;
- while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) {
+ while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
processOutput.DecodeText(data, length, strdata);
if (output) {
- tempOutput.insert(tempOutput.end(), data, data + length);
+ cmAppend(tempOutput, data, data + length);
}
cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
cmCTestLogWrite(strdata.c_str(), strdata.size()));
@@ -1189,23 +1299,23 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
}
}
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
processOutput.DecodeText(tempOutput, tempOutput);
if (output && tempOutput.begin() != tempOutput.end()) {
- output->append(&*tempOutput.begin(), tempOutput.size());
+ output->append(tempOutput.data(), tempOutput.size());
}
- cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed"
- << std::endl);
+ 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) {
+ if (*retVal != 0 && this->Impl->OutputTestOutputOnTestFailure) {
OutputTestErrors(tempOutput);
}
} else if (result == cmsysProcess_State_Exception) {
- if (this->OutputTestOutputOnTestFailure) {
+ if (this->Impl->OutputTestOutputOnTestFailure) {
OutputTestErrors(tempOutput);
}
*retVal = cmsysProcess_GetExitException(cp);
@@ -1214,16 +1324,18 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output,
if (output) {
*output += outerr;
}
- cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl
- << std::flush);
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
+ outerr << std::endl
+ << std::flush);
} else if (result == cmsysProcess_State_Error) {
std::string outerr = "\n*** ERROR executing: ";
outerr += cmsysProcess_GetErrorString(cp);
if (output) {
*output += outerr;
}
- cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl
- << std::flush);
+ cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
+ outerr << std::endl
+ << std::flush);
}
cmsysProcess_Delete(cp);
@@ -1234,7 +1346,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value)
{
std::string safevalue(value);
- if (safevalue != "") {
+ if (!safevalue.empty()) {
// Disallow non-filename and non-space whitespace characters.
// If they occur, replace them with ""
//
@@ -1253,7 +1365,7 @@ std::string cmCTest::SafeBuildIdField(const std::string& value)
}
}
- if (safevalue == "") {
+ if (safevalue.empty()) {
safevalue = "(empty)";
}
@@ -1262,9 +1374,10 @@ std::string cmCTest::SafeBuildIdField(const std::string& value)
void cmCTest::StartXML(cmXMLWriter& xml, bool append)
{
- if (this->CurrentTag.empty()) {
- cmCTestLog(this, ERROR_MESSAGE, "Current Tag empty, this may mean"
- " NightlStartTime was not set correctly."
+ if (this->Impl->CurrentTag.empty()) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Current Tag empty, this may mean"
+ " NightlStartTime was not set correctly."
<< std::endl);
cmSystemTools::SetFatalErrorOccured();
}
@@ -1277,7 +1390,7 @@ void cmCTest::StartXML(cmXMLWriter& xml, bool append)
std::string buildname =
cmCTest::SafeBuildIdField(this->GetCTestConfiguration("BuildName"));
- std::string stamp = cmCTest::SafeBuildIdField(this->CurrentTag + "-" +
+ std::string stamp = cmCTest::SafeBuildIdField(this->Impl->CurrentTag + "-" +
this->GetTestModelString());
std::string site =
cmCTest::SafeBuildIdField(this->GetCTestConfiguration("Site"));
@@ -1325,8 +1438,7 @@ void cmCTest::StartXML(cmXMLWriter& xml, bool append)
void cmCTest::AddSiteProperties(cmXMLWriter& xml)
{
- cmCTestScriptHandler* ch =
- static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ cmCTestScriptHandler* ch = this->GetScriptHandler();
cmake* cm = ch->GetCMake();
// if no CMake then this is the old style script and props like
// this will not work anyway.
@@ -1345,9 +1457,8 @@ void cmCTest::AddSiteProperties(cmXMLWriter& xml)
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) {
- xml.Element("Label", *i);
+ for (std::string const& i : args) {
+ xml.Element("Label", i);
}
xml.EndElement();
}
@@ -1363,6 +1474,33 @@ void cmCTest::AddSiteProperties(cmXMLWriter& xml)
}
}
+void cmCTest::GenerateSubprojectsOutput(cmXMLWriter& xml)
+{
+ for (std::string const& subproj : this->GetLabelsForSubprojects()) {
+ xml.StartElement("Subproject");
+ xml.Attribute("name", subproj);
+ xml.Element("Label", subproj);
+ xml.EndElement(); // Subproject
+ }
+}
+
+std::vector<std::string> cmCTest::GetLabelsForSubprojects()
+{
+ std::string labelsForSubprojects =
+ this->GetCTestConfiguration("LabelsForSubprojects");
+ std::vector<std::string> subprojects;
+ cmSystemTools::ExpandListArgument(labelsForSubprojects, subprojects);
+
+ // sort the array
+ std::sort(subprojects.begin(), subprojects.end());
+ // remove duplicates
+ std::vector<std::string>::iterator new_end =
+ std::unique(subprojects.begin(), subprojects.end());
+ subprojects.erase(new_end, subprojects.end());
+
+ return subprojects;
+}
+
void cmCTest::EndXML(cmXMLWriter& xml)
{
xml.EndElement(); // Site
@@ -1370,11 +1508,10 @@ void cmCTest::EndXML(cmXMLWriter& xml)
}
int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml,
- const cmCTest::VectorOfStrings& files)
+ std::vector<std::string> const& files)
{
std::string buildname =
cmCTest::SafeBuildIdField(this->GetCTestConfiguration("BuildName"));
- cmCTest::VectorOfStrings::const_iterator it;
xml.StartDocument();
xml.ProcessingInstruction("xml-stylesheet",
"type=\"text/xsl\" "
@@ -1383,22 +1520,22 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml,
xml.StartElement("Site");
xml.Attribute("BuildName", buildname);
xml.Attribute("BuildStamp",
- this->CurrentTag + "-" + this->GetTestModelString());
+ this->Impl->CurrentTag + "-" + this->GetTestModelString());
xml.Attribute("Name", this->GetCTestConfiguration("Site"));
xml.Attribute("Generator",
- std::string("ctest") + cmVersion::GetCMakeVersion());
+ std::string("ctest-") + cmVersion::GetCMakeVersion());
this->AddSiteProperties(xml);
xml.StartElement("Notes");
- for (it = files.begin(); it != files.end(); it++) {
- cmCTestLog(this, OUTPUT, "\tAdd file: " << *it << std::endl);
+ for (std::string const& file : files) {
+ cmCTestLog(this, OUTPUT, "\tAdd file: " << file << std::endl);
std::string note_time = this->CurrentTime();
xml.StartElement("Note");
- xml.Attribute("Name", *it);
- xml.Element("Time", cmSystemTools::GetTime());
+ xml.Attribute("Name", file);
+ xml.Element("Time", std::chrono::system_clock::now());
xml.Element("DateTime", note_time);
xml.StartElement("Text");
- cmsys::ifstream ifs(it->c_str());
+ cmsys::ifstream ifs(file.c_str());
if (ifs) {
std::string line;
while (cmSystemTools::GetLineFromStream(ifs, line)) {
@@ -1407,9 +1544,10 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml,
}
ifs.close();
} else {
- xml.Content("Problem reading file: " + *it + "\n");
- cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: "
- << *it << " while creating notes" << std::endl);
+ xml.Content("Problem reading file: " + file + "\n");
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Problem reading file: " << file << " while creating notes"
+ << std::endl);
}
xml.EndElement(); // Text
xml.EndElement(); // Note
@@ -1420,10 +1558,10 @@ int cmCTest::GenerateCTestNotesOutput(cmXMLWriter& xml,
return 1;
}
-int cmCTest::GenerateNotesFile(const VectorOfStrings& files)
+int cmCTest::GenerateNotesFile(std::vector<std::string> const& files)
{
cmGeneratedFileStream ofs;
- if (!this->OpenOutputFile(this->CurrentTag, "Notes.xml", ofs)) {
+ if (!this->OpenOutputFile(this->Impl->CurrentTag, "Notes.xml", ofs)) {
cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl);
return 1;
}
@@ -1438,11 +1576,10 @@ int cmCTest::GenerateNotesFile(const char* cfiles)
return 1;
}
- VectorOfStrings files;
-
cmCTestLog(this, OUTPUT, "Create notes file" << std::endl);
- files = cmSystemTools::SplitString(cfiles, ';');
+ std::vector<std::string> const files =
+ cmSystemTools::SplitString(cfiles, ';');
if (files.empty()) {
return 1;
}
@@ -1450,16 +1587,35 @@ int cmCTest::GenerateNotesFile(const char* cfiles)
return this->GenerateNotesFile(files);
}
+int cmCTest::GenerateDoneFile()
+{
+ cmGeneratedFileStream ofs;
+ if (!this->OpenOutputFile(this->Impl->CurrentTag, "Done.xml", ofs)) {
+ cmCTestLog(this, ERROR_MESSAGE, "Cannot open done file" << std::endl);
+ return 1;
+ }
+ cmXMLWriter xml(ofs);
+ xml.StartDocument();
+ xml.StartElement("Done");
+ xml.Element("buildId", this->Impl->BuildID);
+ xml.Element("time", std::chrono::system_clock::now());
+ xml.EndElement(); // Done
+ xml.EndDocument();
+
+ return 0;
+}
+
std::string cmCTest::Base64GzipEncodeFile(std::string const& file)
{
std::string tarFile = file + "_temp.tar.gz";
std::vector<std::string> files;
files.push_back(file);
- if (!cmSystemTools::CreateTar(tarFile.c_str(), files,
- cmSystemTools::TarCompressGZip, false)) {
- cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while "
- "encoding file: "
+ if (!cmSystemTools::CreateTar(tarFile, files, cmSystemTools::TarCompressGZip,
+ false)) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Error creating tar while "
+ "encoding file: "
<< file << std::endl);
return "";
}
@@ -1471,11 +1627,12 @@ std::string cmCTest::Base64GzipEncodeFile(std::string const& file)
std::string cmCTest::Base64EncodeFile(std::string const& file)
{
size_t const len = cmSystemTools::FileLength(file);
- cmsys::ifstream ifs(file.c_str(), std::ios::in
+ cmsys::ifstream ifs(file.c_str(),
+ std::ios::in
#ifdef _WIN32
| std::ios::binary
#endif
- );
+ );
std::vector<char> file_buffer(len + 1);
ifs.read(&file_buffer[0], len);
ifs.close();
@@ -1489,16 +1646,16 @@ std::string cmCTest::Base64EncodeFile(std::string const& file)
return std::string(&encoded_buffer[0], rlen);
}
-bool cmCTest::SubmitExtraFiles(const VectorOfStrings& files)
+bool cmCTest::SubmitExtraFiles(std::vector<std::string> const& 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;);
+ for (std::string const& file : files) {
+ if (!cmSystemTools::FileExists(file)) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Cannot find extra file: " << file << " to submit."
+ << std::endl;);
return false;
}
- this->AddSubmitFile(PartExtraFiles, it->c_str());
+ this->AddSubmitFile(PartExtraFiles, file.c_str());
}
return true;
}
@@ -1509,11 +1666,10 @@ bool cmCTest::SubmitExtraFiles(const char* cfiles)
return true;
}
- VectorOfStrings files;
-
cmCTestLog(this, OUTPUT, "Submit extra files" << std::endl);
- files = cmSystemTools::SplitString(cfiles, ';');
+ std::vector<std::string> const files =
+ cmSystemTools::SplitString(cfiles, ';');
if (files.empty()) {
return true;
}
@@ -1652,7 +1808,8 @@ void cmCTest::ErrorMessageUnknownDashDValue(std::string& val)
"CTest -D called with incorrect option: " << val << std::endl);
cmCTestLog(
- this, ERROR_MESSAGE, "Available options are:"
+ this, ERROR_MESSAGE,
+ "Available options are:"
<< std::endl
<< " ctest -D Continuous" << std::endl
<< " ctest -D Continuous(Start|Update|Configure|Build)" << std::endl
@@ -1680,17 +1837,17 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
{
std::string arg = args[i];
if (this->CheckArgument(arg, "-F")) {
- this->Failover = true;
+ this->Impl->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;
+ this->Impl->ParallelLevelSetInCli = true;
} else if (arg.find("-j") == 0) {
int plevel = atoi(arg.substr(2).c_str());
this->SetParallelLevel(plevel);
- this->ParallelLevelSetInCli = true;
+ this->Impl->ParallelLevelSetInCli = true;
}
if (this->CheckArgument(arg, "--repeat-until-fail")) {
if (i >= args.size() - 1) {
@@ -1704,9 +1861,9 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
"'--repeat-until-fail' given non-integer value '" + args[i] + "'";
return false;
}
- this->RepeatTests = static_cast<int>(repeat);
+ this->Impl->RepeatTests = static_cast<int>(repeat);
if (repeat > 1) {
- this->RepeatUntilFail = true;
+ this->Impl->RepeatUntilFail = true;
}
}
@@ -1722,21 +1879,21 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
if (this->CheckArgument(arg, "--no-compress-output")) {
- this->CompressTestOutput = false;
+ this->Impl->CompressTestOutput = false;
}
if (this->CheckArgument(arg, "--print-labels")) {
- this->PrintLabels = true;
+ this->Impl->PrintLabels = true;
}
if (this->CheckArgument(arg, "--http1.0")) {
- this->UseHTTP10 = true;
+ this->Impl->UseHTTP10 = true;
}
if (this->CheckArgument(arg, "--timeout") && i < args.size() - 1) {
i++;
- double timeout = (double)atof(args[i].c_str());
- this->GlobalTimeout = timeout;
+ auto timeout = cmDuration(atof(args[i].c_str()));
+ this->Impl->GlobalTimeout = timeout;
}
if (this->CheckArgument(arg, "--stop-time") && i < args.size() - 1) {
@@ -1751,44 +1908,44 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
if (this->CheckArgument(arg, "--debug")) {
- this->Debug = true;
- this->ShowLineNumbers = true;
+ this->Impl->Debug = true;
+ this->Impl->ShowLineNumbers = true;
}
if (this->CheckArgument(arg, "--track") && i < args.size() - 1) {
i++;
- this->SpecificTrack = args[i];
+ this->Impl->SpecificTrack = args[i];
}
if (this->CheckArgument(arg, "--show-line-numbers")) {
- this->ShowLineNumbers = true;
+ this->Impl->ShowLineNumbers = true;
}
if (this->CheckArgument(arg, "--no-label-summary")) {
- this->LabelSummary = false;
+ this->Impl->LabelSummary = false;
+ }
+ if (this->CheckArgument(arg, "--no-subproject-summary")) {
+ this->Impl->SubprojectSummary = false;
}
if (this->CheckArgument(arg, "-Q", "--quiet")) {
- this->Quiet = true;
+ this->Impl->Quiet = true;
}
- if (this->CheckArgument(arg, "-V", "--verbose")) {
- this->Verbose = true;
+ if (this->CheckArgument(arg, "--progress")) {
+ this->Impl->TestProgressOutput = true;
}
- if (this->CheckArgument(arg, "-B")) {
- this->BatchJobs = true;
+ if (this->CheckArgument(arg, "-V", "--verbose")) {
+ this->Impl->Verbose = true;
}
if (this->CheckArgument(arg, "-VV", "--extra-verbose")) {
- this->ExtraVerbose = true;
- this->Verbose = true;
+ this->Impl->ExtraVerbose = true;
+ this->Impl->Verbose = true;
}
if (this->CheckArgument(arg, "--output-on-failure")) {
- this->OutputTestOutputOnTestFailure = true;
+ this->Impl->OutputTestOutputOnTestFailure = true;
}
if (this->CheckArgument(arg, "--test-output-size-passed") &&
i < args.size() - 1) {
i++;
long outputSize;
if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize)) {
- if (cmCTestTestHandler* pCTestTestHandler =
- static_cast<cmCTestTestHandler*>(this->TestingHandlers["test"])) {
- pCTestTestHandler->SetTestOutputSizePassed(int(outputSize));
- }
+ this->Impl->TestHandler.SetTestOutputSizePassed(int(outputSize));
} else {
cmCTestLog(this, WARNING,
"Invalid value for '--test-output-size-passed': " << args[i]
@@ -1800,10 +1957,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
i++;
long outputSize;
if (cmSystemTools::StringToLong(args[i].c_str(), &outputSize)) {
- if (cmCTestTestHandler* pCTestTestHandler =
- static_cast<cmCTestTestHandler*>(this->TestingHandlers["test"])) {
- pCTestTestHandler->SetTestOutputSizeFailed(int(outputSize));
- }
+ this->Impl->TestHandler.SetTestOutputSizeFailed(int(outputSize));
} else {
cmCTestLog(this, WARNING,
"Invalid value for '--test-output-size-failed': " << args[i]
@@ -1811,7 +1965,24 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
}
if (this->CheckArgument(arg, "-N", "--show-only")) {
- this->ShowOnly = true;
+ this->Impl->ShowOnly = true;
+ }
+ if (cmSystemTools::StringStartsWith(arg.c_str(), "--show-only=")) {
+ this->Impl->ShowOnly = true;
+
+ // Check if a specific format is requested. Defaults to human readable
+ // text.
+ std::string argWithFormat = "--show-only=";
+ std::string format = arg.substr(argWithFormat.length());
+ if (format == "json-v1") {
+ // Force quiet mode so the only output is the json object model.
+ this->Impl->Quiet = true;
+ this->Impl->OutputAsJson = true;
+ this->Impl->OutputAsJsonVersion = 1;
+ } else if (format != "human") {
+ errormsg = "'--show-only=' given unknown value '" + format + "'";
+ return false;
+ }
}
if (this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1) {
@@ -1820,25 +1991,25 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
}
if (this->CheckArgument(arg, "--tomorrow-tag")) {
- this->TomorrowTag = true;
+ this->Impl->TomorrowTag = true;
}
if (this->CheckArgument(arg, "--force-new-ctest-process")) {
- this->ForceNewCTestProcess = true;
+ this->Impl->ForceNewCTestProcess = true;
}
if (this->CheckArgument(arg, "-W", "--max-width") && i < args.size() - 1) {
i++;
- this->MaxTestNameWidth = atoi(args[i].c_str());
+ this->Impl->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());
+ this->Impl->InteractiveDebugMode = cmSystemTools::IsOn(args[i]);
}
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;
+ this->Impl->SubmitIndex = atoi(args[i].c_str());
+ if (this->Impl->SubmitIndex < 0) {
+ this->Impl->SubmitIndex = 0;
}
}
@@ -1847,7 +2018,7 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
this->AddCTestConfigurationOverwrite(args[i]);
}
if (this->CheckArgument(arg, "-A", "--add-notes") && i < args.size() - 1) {
- this->ProduceXML = true;
+ this->Impl->ProduceXML = true;
this->SetTest("Notes");
i++;
this->SetNotesFiles(args[i].c_str());
@@ -1857,82 +2028,114 @@ bool cmCTest::HandleCommandLineArguments(size_t& i,
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());
+ this->GetTestHandler()->SetPersistentOption("TestsToRunInformation",
+ args[i].c_str());
+ this->GetMemCheckHandler()->SetPersistentOption("TestsToRunInformation",
+ args[i].c_str());
}
if (this->CheckArgument(arg, "-U", "--union")) {
- this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
- this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
+ this->GetTestHandler()->SetPersistentOption("UseUnion", "true");
+ this->GetMemCheckHandler()->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());
+ this->GetTestHandler()->SetPersistentOption("IncludeRegularExpression",
+ args[i].c_str());
+ this->GetMemCheckHandler()->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());
+ this->GetTestHandler()->SetPersistentOption("LabelRegularExpression",
+ args[i].c_str());
+ this->GetMemCheckHandler()->SetPersistentOption("LabelRegularExpression",
+ args[i].c_str());
}
if (this->CheckArgument(arg, "-LE", "--label-exclude") &&
i < args.size() - 1) {
i++;
- this->GetHandler("test")->SetPersistentOption(
+ this->GetTestHandler()->SetPersistentOption(
+ "ExcludeLabelRegularExpression", args[i].c_str());
+ this->GetMemCheckHandler()->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());
+ this->GetTestHandler()->SetPersistentOption("ExcludeRegularExpression",
+ args[i].c_str());
+ this->GetMemCheckHandler()->SetPersistentOption("ExcludeRegularExpression",
+ args[i].c_str());
}
if (this->CheckArgument(arg, "-FA", "--fixture-exclude-any") &&
i < args.size() - 1) {
i++;
- this->GetHandler("test")->SetPersistentOption(
+ this->GetTestHandler()->SetPersistentOption(
+ "ExcludeFixtureRegularExpression", args[i].c_str());
+ this->GetMemCheckHandler()->SetPersistentOption(
"ExcludeFixtureRegularExpression", args[i].c_str());
- this->GetHandler("memcheck")
- ->SetPersistentOption("ExcludeFixtureRegularExpression",
- args[i].c_str());
}
if (this->CheckArgument(arg, "-FS", "--fixture-exclude-setup") &&
i < args.size() - 1) {
i++;
- this->GetHandler("test")->SetPersistentOption(
+ this->GetTestHandler()->SetPersistentOption(
+ "ExcludeFixtureSetupRegularExpression", args[i].c_str());
+ this->GetMemCheckHandler()->SetPersistentOption(
"ExcludeFixtureSetupRegularExpression", args[i].c_str());
- this->GetHandler("memcheck")
- ->SetPersistentOption("ExcludeFixtureSetupRegularExpression",
- args[i].c_str());
}
if (this->CheckArgument(arg, "-FC", "--fixture-exclude-cleanup") &&
i < args.size() - 1) {
i++;
- this->GetHandler("test")->SetPersistentOption(
+ this->GetTestHandler()->SetPersistentOption(
+ "ExcludeFixtureCleanupRegularExpression", args[i].c_str());
+ this->GetMemCheckHandler()->SetPersistentOption(
"ExcludeFixtureCleanupRegularExpression", args[i].c_str());
- this->GetHandler("memcheck")
- ->SetPersistentOption("ExcludeFixtureCleanupRegularExpression",
- args[i].c_str());
}
if (this->CheckArgument(arg, "--rerun-failed")) {
- this->GetHandler("test")->SetPersistentOption("RerunFailed", "true");
- this->GetHandler("memcheck")->SetPersistentOption("RerunFailed", "true");
+ this->GetTestHandler()->SetPersistentOption("RerunFailed", "true");
+ this->GetMemCheckHandler()->SetPersistentOption("RerunFailed", "true");
}
return true;
}
+#if !defined(_WIN32)
+bool cmCTest::ConsoleIsNotDumb()
+{
+ std::string term_env_variable;
+ if (cmSystemTools::GetEnv("TERM", term_env_variable)) {
+ return isatty(1) && term_env_variable != "dumb";
+ }
+ return false;
+}
+#endif
+
+bool cmCTest::ProgressOutputSupportedByConsole()
+{
+#if defined(_WIN32)
+ // On Windows we need a console buffer.
+ void* console = GetStdHandle(STD_OUTPUT_HANDLE);
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+ return GetConsoleScreenBufferInfo(console, &csbi);
+#else
+ // On UNIX we need a non-dumb tty.
+ return ConsoleIsNotDumb();
+#endif
+}
+
+bool cmCTest::ColoredOutputSupportedByConsole()
+{
+#if defined(_WIN32)
+ // Not supported on Windows
+ return false;
+#else
+ // On UNIX we need a non-dumb tty.
+ return ConsoleIsNotDumb();
+#endif
+}
+
// handle the -S -SR and -SP arguments
void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
bool& SRArgumentSpecified)
@@ -1940,10 +2143,9 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
std::string arg = args[i];
if (this->CheckArgument(arg, "-SP", "--script-new-process") &&
i < args.size() - 1) {
- this->RunConfigurationScript = true;
+ this->Impl->RunConfigurationScript = true;
i++;
- cmCTestScriptHandler* ch =
- static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ cmCTestScriptHandler* ch = this->GetScriptHandler();
// -SR is an internal argument, -SP should be ignored when it is passed
if (!SRArgumentSpecified) {
ch->AddConfigurationScript(args[i].c_str(), false);
@@ -1952,18 +2154,16 @@ void cmCTest::HandleScriptArguments(size_t& i, std::vector<std::string>& args,
if (this->CheckArgument(arg, "-SR", "--script-run") && i < args.size() - 1) {
SRArgumentSpecified = true;
- this->RunConfigurationScript = true;
+ this->Impl->RunConfigurationScript = true;
i++;
- cmCTestScriptHandler* ch =
- static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ cmCTestScriptHandler* ch = this->GetScriptHandler();
ch->AddConfigurationScript(args[i].c_str(), true);
}
if (this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1) {
- this->RunConfigurationScript = true;
+ this->Impl->RunConfigurationScript = true;
i++;
- cmCTestScriptHandler* ch =
- static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ cmCTestScriptHandler* ch = this->GetScriptHandler();
// -SR is an internal argument, -S should be ignored when it is passed
if (!SRArgumentSpecified) {
ch->AddConfigurationScript(args[i].c_str(), true);
@@ -1978,7 +2178,7 @@ bool cmCTest::AddVariableDefinition(const std::string& arg)
cmStateEnums::CacheEntryType type = cmStateEnums::UNINITIALIZED;
if (cmake::ParseCacheEntry(arg, name, value, type)) {
- this->Definitions[name] = value;
+ this->Impl->Definitions[name] = value;
return true;
}
@@ -1994,15 +2194,14 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
bool SRArgumentSpecified = false;
// copy the command line
- this->InitialCommandLineArguments.insert(
- this->InitialCommandLineArguments.end(), args.begin(), args.end());
+ cmAppend(this->Impl->InitialCommandLineArguments, args);
// process the command line arguments
for (size_t i = 1; i < args.size(); ++i) {
// handle the simple commandline arguments
std::string errormsg;
if (!this->HandleCommandLineArguments(i, args, errormsg)) {
- cmSystemTools::Error(errormsg.c_str());
+ cmSystemTools::Error(errormsg);
return 1;
}
@@ -2012,7 +2211,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
// --dashboard: handle a request for a dashboard
std::string arg = args[i];
if (this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1) {
- this->ProduceXML = true;
+ this->Impl->ProduceXML = true;
i++;
std::string targ = args[i];
// AddTestsForDashboard parses the dashboard type and converts it
@@ -2048,7 +2247,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
// --extra-submit
if (this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1) {
- this->ProduceXML = true;
+ this->Impl->ProduceXML = true;
this->SetTest("Submit");
i++;
if (!this->SubmitExtraFiles(args[i].c_str())) {
@@ -2063,16 +2262,14 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
// --schedule-random
if (this->CheckArgument(arg, "--schedule-random")) {
- this->ScheduleType = "Random";
+ this->Impl->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)) {
+ for (auto& handler : this->Impl->GetTestingHandlers()) {
+ if (!handler->ProcessCommandLineArguments(arg, i, args)) {
cmCTestLog(this, ERROR_MESSAGE,
"Problem parsing command line arguments within a handler");
return 0;
@@ -2081,7 +2278,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
} // the close of the for argument loop
// handle CTEST_PARALLEL_LEVEL environment variable
- if (!this->ParallelLevelSetInCli) {
+ if (!this->Impl->ParallelLevelSetInCli) {
std::string parallel;
if (cmSystemTools::GetEnv("CTEST_PARALLEL_LEVEL", parallel)) {
int plevel = atoi(parallel.c_str());
@@ -2089,6 +2286,18 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output)
}
}
+ // TestProgressOutput only supported if console supports it and not logging
+ // to a file
+ this->Impl->TestProgressOutput = this->Impl->TestProgressOutput &&
+ !this->Impl->OutputLogFile && this->ProgressOutputSupportedByConsole();
+#ifdef _WIN32
+ if (this->Impl->TestProgressOutput) {
+ // Disable output line buffering so we can print content without
+ // a newline.
+ std::setvbuf(stdout, nullptr, _IONBF, 0);
+ }
+#endif
+
// now what should cmake do? if --build-and-test was specified then
// we run the build and test handler and return
if (cmakeAndTest) {
@@ -2109,13 +2318,15 @@ bool cmCTest::HandleTestActionArgument(const char* ctestExec, size_t& i,
std::string arg = args[i];
if (this->CheckArgument(arg, "-T", "--test-action") &&
(i < args.size() - 1)) {
- this->ProduceXML = true;
+ this->Impl->ProduceXML = true;
i++;
if (!this->SetTest(args[i].c_str(), false)) {
success = false;
- cmCTestLog(this, ERROR_MESSAGE, "CTest -T called with incorrect option: "
- << args[i] << std::endl);
- cmCTestLog(this, ERROR_MESSAGE, "Available options are:"
+ 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
@@ -2149,9 +2360,11 @@ bool cmCTest::HandleTestModelArgument(const char* ctestExec, size_t& i,
this->SetTestModel(cmCTest::EXPERIMENTAL);
} else {
success = false;
- cmCTestLog(this, ERROR_MESSAGE, "CTest -M called with incorrect option: "
- << str << std::endl);
- cmCTestLog(this, ERROR_MESSAGE, "Available options are:"
+ 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
@@ -2165,18 +2378,16 @@ int cmCTest::ExecuteTests()
{
int res;
// call process directory
- if (this->RunConfigurationScript) {
- if (this->ExtraVerbose) {
+ if (this->Impl->RunConfigurationScript) {
+ if (this->Impl->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);
+ for (auto& handler : this->Impl->GetTestingHandlers()) {
+ handler->SetVerbose(this->Impl->ExtraVerbose);
+ handler->SetSubmitIndex(this->Impl->SubmitIndex);
}
- this->GetHandler("script")->SetVerbose(this->Verbose);
- res = this->GetHandler("script")->ProcessHandler();
+ this->GetScriptHandler()->SetVerbose(this->Impl->Verbose);
+ res = this->GetScriptHandler()->ProcessHandler();
if (res != 0) {
cmCTestLog(this, DEBUG,
"running script failing returning: " << res << std::endl);
@@ -2185,19 +2396,17 @@ int cmCTest::ExecuteTests()
} 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);
+ this->Impl->ExtraVerbose = this->Impl->Verbose;
+ this->Impl->Verbose = true;
+ for (auto& handler : this->Impl->GetTestingHandlers()) {
+ handler->SetVerbose(this->Impl->Verbose);
+ handler->SetSubmitIndex(this->Impl->SubmitIndex);
}
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
- if (!this->Initialize(cwd.c_str(), CM_NULLPTR)) {
+ if (!this->Initialize(cwd.c_str(), nullptr)) {
res = 12;
- cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard."
- << std::endl);
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Problem initializing the dashboard." << std::endl);
} else {
res = this->ProcessSteps();
}
@@ -2212,17 +2421,16 @@ int cmCTest::ExecuteTests()
int cmCTest::RunCMakeAndTest(std::string* output)
{
- this->Verbose = true;
- cmCTestBuildAndTestHandler* handler =
- static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
+ this->Impl->Verbose = true;
+ cmCTestBuildAndTestHandler* handler = this->GetBuildAndTestHandler();
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);
+ cmCTestLog(this, DEBUG,
+ "build and test failing returning: " << retv << std::endl);
}
return retv;
}
@@ -2232,36 +2440,82 @@ void cmCTest::SetNotesFiles(const char* notes)
if (!notes) {
return;
}
- this->NotesFiles = notes;
+ this->Impl->NotesFiles = notes;
+}
+
+std::chrono::system_clock::time_point cmCTest::GetStopTime() const
+{
+ return this->Impl->StopTime;
+}
+
+void cmCTest::SetStopTime(std::string const& time_str)
+{
+
+ struct tm* lctime;
+ time_t current_time = time(nullptr);
+ 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, time_str.c_str(), tzone_offset);
+
+ time_t stop_time = curl_getdate(buf, &current_time);
+ if (stop_time == -1) {
+ this->Impl->StopTime = std::chrono::system_clock::time_point();
+ return;
+ }
+ this->Impl->StopTime = std::chrono::system_clock::from_time_t(stop_time);
+
+ if (stop_time < current_time) {
+ this->Impl->StopTime += std::chrono::hours(24);
+ }
+}
+
+std::string cmCTest::GetScheduleType() const
+{
+ return this->Impl->ScheduleType;
}
-void cmCTest::SetStopTime(std::string const& time)
+void cmCTest::SetScheduleType(std::string const& type)
{
- this->StopTime = time;
- this->DetermineNextDayStop();
+ this->Impl->ScheduleType = type;
}
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);
+ 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);
+ if (cmSystemTools::FileExists(fname)) {
+ cmCTestLog(this, DEBUG,
+ "* Read custom CTest configuration file: " << fname
+ << std::endl);
bool erroroc = cmSystemTools::GetErrorOccuredFlag();
cmSystemTools::ResetErrorOccuredFlag();
- if (!mf->ReadListFile(fname.c_str()) ||
- cmSystemTools::GetErrorOccuredFlag()) {
- cmCTestLog(this, ERROR_MESSAGE, "Problem reading custom configuration: "
- << fname << std::endl);
+ if (!mf->ReadListFile(fname) || cmSystemTools::GetErrorOccuredFlag()) {
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Problem reading custom configuration: " << fname
+ << std::endl);
}
found = true;
if (erroroc) {
@@ -2272,19 +2526,18 @@ int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf)
std::string rexpr = dir;
rexpr += "/CTestCustom.ctest";
cmCTestLog(this, DEBUG, "* Check for file: " << rexpr << std::endl);
- if (!found && cmSystemTools::FileExists(rexpr.c_str())) {
+ if (!found && cmSystemTools::FileExists(rexpr)) {
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(fileIt->c_str()) ||
- cmSystemTools::GetErrorOccuredFlag()) {
+ for (const std::string& file : files) {
+ cmCTestLog(this, DEBUG,
+ "* Read custom CTest configuration file: " << file
+ << std::endl);
+ if (!mf->ReadListFile(file) || cmSystemTools::GetErrorOccuredFlag()) {
cmCTestLog(this, ERROR_MESSAGE,
- "Problem reading custom configuration: " << *fileIt
+ "Problem reading custom configuration: " << file
<< std::endl);
}
}
@@ -2292,13 +2545,12 @@ int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf)
}
if (found) {
- cmCTest::t_TestingHandlers::iterator it;
- for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end();
- ++it) {
+ for (auto& handler : this->Impl->GetNamedTestingHandlers()) {
cmCTestLog(this, DEBUG,
"* Read custom CTest configuration vectors for handler: "
- << it->first << " (" << it->second << ")" << std::endl);
- it->second->PopulateCustomVectors(mf);
+ << handler.first << " (" << handler.second << ")"
+ << std::endl);
+ handler.second->PopulateCustomVectors(mf);
}
}
@@ -2317,9 +2569,8 @@ void cmCTest::PopulateCustomVector(cmMakefile* mf, const std::string& def,
vec.clear();
cmSystemTools::ExpandListArgument(dval, vec);
- for (std::vector<std::string>::const_iterator it = vec.begin();
- it != vec.end(); ++it) {
- cmCTestLog(this, DEBUG, " -- " << *it << std::endl);
+ for (std::string const& it : vec) {
+ cmCTestLog(this, DEBUG, " -- " << it << std::endl);
}
}
@@ -2342,17 +2593,15 @@ std::string cmCTest::GetShortPathToFile(const char* cfname)
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());
+ std::string srcRelpath = cmSystemTools::RelativePath(sourceDir, fname);
+ std::string bldRelpath = cmSystemTools::RelativePath(buildDir, fname);
// If any contains "." it is not parent directory
bool inSrc = srcRelpath.find("..") == std::string::npos;
bool inBld = bldRelpath.find("..") == std::string::npos;
// TODO: Handle files with .. in their name
- std::string* res = CM_NULLPTR;
+ std::string* res = nullptr;
if (inSrc && inBld) {
// If both have relative path with no dots, pick the shorter one
@@ -2375,7 +2624,7 @@ std::string cmCTest::GetShortPathToFile(const char* cfname)
cmSystemTools::ConvertToUnixSlashes(*res);
path = "./" + *res;
- if (path[path.size() - 1] == '/') {
+ if (path.back() == '/') {
path = path.substr(0, path.size() - 1);
}
}
@@ -2387,54 +2636,23 @@ std::string cmCTest::GetShortPathToFile(const char* cfname)
std::string cmCTest::GetCTestConfiguration(const std::string& name)
{
- if (this->CTestConfigurationOverwrites.find(name) !=
- this->CTestConfigurationOverwrites.end()) {
- return this->CTestConfigurationOverwrites[name];
+ if (this->Impl->CTestConfigurationOverwrites.find(name) !=
+ this->Impl->CTestConfigurationOverwrites.end()) {
+ return this->Impl->CTestConfigurationOverwrites[name];
}
- return this->CTestConfiguration[name];
+ return this->Impl->CTestConfiguration[name];
}
void cmCTest::EmptyCTestConfiguration()
{
- this->CTestConfiguration.clear();
-}
-
-void cmCTest::DetermineNextDayStop()
-{
- struct tm* lctime;
- time_t current_time = time(CM_NULLPTR);
- 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;
- }
+ this->Impl->CTestConfiguration.clear();
}
void cmCTest::SetCTestConfiguration(const char* name, const char* value,
bool suppress)
{
- cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT, "SetCTestConfiguration:"
+ cmCTestOptionalLog(this, HANDLER_VERBOSE_OUTPUT,
+ "SetCTestConfiguration:"
<< name << ":" << (value ? value : "(null)") << "\n",
suppress);
@@ -2442,67 +2660,224 @@ void cmCTest::SetCTestConfiguration(const char* name, const char* value,
return;
}
if (!value) {
- this->CTestConfiguration.erase(name);
+ this->Impl->CTestConfiguration.erase(name);
return;
}
- this->CTestConfiguration[name] = value;
+ this->Impl->CTestConfiguration[name] = value;
+}
+
+std::string cmCTest::GetSubmitURL()
+{
+ std::string url = this->GetCTestConfiguration("SubmitURL");
+ if (url.empty()) {
+ std::string method = this->GetCTestConfiguration("DropMethod");
+ std::string user = this->GetCTestConfiguration("DropSiteUser");
+ std::string password = this->GetCTestConfiguration("DropSitePassword");
+ std::string site = this->GetCTestConfiguration("DropSite");
+ std::string location = this->GetCTestConfiguration("DropLocation");
+
+ url = method.empty() ? "http" : method;
+ url += "://";
+ if (!user.empty()) {
+ url += user;
+ if (!password.empty()) {
+ url += ':';
+ url += password;
+ }
+ url += '@';
+ }
+ url += site;
+ url += location;
+ }
+ return url;
}
std::string cmCTest::GetCurrentTag()
{
- return this->CurrentTag;
+ return this->Impl->CurrentTag;
}
std::string cmCTest::GetBinaryDir()
{
- return this->BinaryDir;
+ return this->Impl->BinaryDir;
}
std::string const& cmCTest::GetConfigType()
{
- return this->ConfigType;
+ return this->Impl->ConfigType;
+}
+
+cmDuration cmCTest::GetTimeOut() const
+{
+ return this->Impl->TimeOut;
+}
+
+void cmCTest::SetTimeOut(cmDuration t)
+{
+ this->Impl->TimeOut = t;
+}
+
+cmDuration cmCTest::GetGlobalTimeout() const
+{
+ return this->Impl->GlobalTimeout;
}
bool cmCTest::GetShowOnly()
{
- return this->ShowOnly;
+ return this->Impl->ShowOnly;
+}
+
+bool cmCTest::GetOutputAsJson()
+{
+ return this->Impl->OutputAsJson;
+}
+
+int cmCTest::GetOutputAsJsonVersion()
+{
+ return this->Impl->OutputAsJsonVersion;
+}
+
+bool cmCTest::ShouldUseHTTP10() const
+{
+ return this->Impl->UseHTTP10;
+}
+
+bool cmCTest::ShouldPrintLabels() const
+{
+ return this->Impl->PrintLabels;
}
int cmCTest::GetMaxTestNameWidth() const
{
- return this->MaxTestNameWidth;
+ return this->Impl->MaxTestNameWidth;
+}
+
+void cmCTest::SetMaxTestNameWidth(int w)
+{
+ this->Impl->MaxTestNameWidth = w;
}
void cmCTest::SetProduceXML(bool v)
{
- this->ProduceXML = v;
+ this->Impl->ProduceXML = v;
}
bool cmCTest::GetProduceXML()
{
- return this->ProduceXML;
+ return this->Impl->ProduceXML;
+}
+
+std::vector<std::string>& cmCTest::GetInitialCommandLineArguments()
+{
+ return this->Impl->InitialCommandLineArguments;
}
const char* cmCTest::GetSpecificTrack()
{
- if (this->SpecificTrack.empty()) {
- return CM_NULLPTR;
+ if (this->Impl->SpecificTrack.empty()) {
+ return nullptr;
}
- return this->SpecificTrack.c_str();
+ return this->Impl->SpecificTrack.c_str();
}
void cmCTest::SetSpecificTrack(const char* track)
{
if (!track) {
- this->SpecificTrack = "";
+ this->Impl->SpecificTrack.clear();
return;
}
- this->SpecificTrack = track;
+ this->Impl->SpecificTrack = track;
+}
+
+void cmCTest::SetFailover(bool failover)
+{
+ this->Impl->Failover = failover;
+}
+
+bool cmCTest::GetFailover() const
+{
+ return this->Impl->Failover;
+}
+
+bool cmCTest::GetTestProgressOutput() const
+{
+ return this->Impl->TestProgressOutput;
+}
+
+bool cmCTest::GetVerbose() const
+{
+ return this->Impl->Verbose;
+}
+
+bool cmCTest::GetExtraVerbose() const
+{
+ return this->Impl->ExtraVerbose;
+}
+
+void cmCTest::SetStreams(std::ostream* out, std::ostream* err)
+{
+ this->Impl->StreamOut = out;
+ this->Impl->StreamErr = err;
+}
+
+bool cmCTest::GetLabelSummary() const
+{
+ return this->Impl->LabelSummary;
+}
+
+bool cmCTest::GetSubprojectSummary() const
+{
+ return this->Impl->SubprojectSummary;
+}
+
+bool cmCTest::GetOutputTestOutputOnTestFailure() const
+{
+ return this->Impl->OutputTestOutputOnTestFailure;
+}
+
+const std::map<std::string, std::string>& cmCTest::GetDefinitions() const
+{
+ return this->Impl->Definitions;
+}
+
+int cmCTest::GetTestRepeat() const
+{
+ return this->Impl->RepeatTests;
+}
+
+bool cmCTest::GetRepeatUntilFail() const
+{
+ return this->Impl->RepeatUntilFail;
+}
+
+void cmCTest::SetBuildID(const std::string& id)
+{
+ this->Impl->BuildID = id;
+}
+
+std::string cmCTest::GetBuildID() const
+{
+ return this->Impl->BuildID;
}
void cmCTest::AddSubmitFile(Part part, const char* name)
{
- this->Parts[part].SubmitFiles.push_back(name);
+ this->Impl->Parts[part].SubmitFiles.emplace_back(name);
+}
+
+std::vector<std::string> const& cmCTest::GetSubmitFiles(Part part) const
+{
+ return this->Impl->Parts[part].SubmitFiles;
+}
+
+void cmCTest::ClearSubmitFiles(Part part)
+{
+ this->Impl->Parts[part].SubmitFiles.clear();
+}
+
+void cmCTest::SetSuppressUpdatingCTestConfiguration(bool val)
+{
+ this->Impl->SuppressUpdatingCTestConfiguration = val;
}
void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
@@ -2518,14 +2893,14 @@ void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
}
std::string key = overStr.substr(0, epos);
std::string value = overStr.substr(epos + 1);
- this->CTestConfigurationOverwrites[key] = value;
+ this->Impl->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;
+ this->Impl->ConfigType = ct ? ct : "";
+ cmSystemTools::ReplaceString(this->Impl->ConfigType, ".\\", "");
+ std::string confTypeEnv = "CMAKE_CONFIG_TYPE=" + this->Impl->ConfigType;
cmSystemTools::PutEnv(confTypeEnv);
}
@@ -2546,33 +2921,28 @@ bool cmCTest::SetCTestConfigurationFromCMakeVariable(
return true;
}
-bool cmCTest::RunCommand(const char* command, std::string* stdOut,
- std::string* stdErr, int* retVal, const char* dir,
- double timeout, Encoding encoding)
+bool cmCTest::RunCommand(std::vector<std::string> const& args,
+ std::string* stdOut, std::string* stdErr, int* retVal,
+ const char* dir, cmDuration timeout,
+ Encoding encoding)
{
- std::vector<std::string> args = cmSystemTools::ParseArguments(command);
-
- if (args.empty()) {
- 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.reserve(args.size() + 1);
+ for (std::string const& a : args) {
+ argv.push_back(a.c_str());
}
- argv.push_back(CM_NULLPTR);
+ argv.push_back(nullptr);
- *stdOut = "";
- *stdErr = "";
+ stdOut->clear();
+ stdErr->clear();
cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
if (cmSystemTools::GetRunCommandHideConsole()) {
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
}
- cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_SetTimeout(cp, timeout.count());
cmsysProcess_Execute(cp);
std::vector<char> tempOutput;
@@ -2584,38 +2954,38 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut,
int res;
bool done = false;
while (!done) {
- res = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR);
+ res = cmsysProcess_WaitForData(cp, &data, &length, nullptr);
switch (res) {
case cmsysProcess_Pipe_STDOUT:
- tempOutput.insert(tempOutput.end(), data, data + length);
+ cmAppend(tempOutput, data, data + length);
break;
case cmsysProcess_Pipe_STDERR:
- tempError.insert(tempError.end(), data, data + length);
+ cmAppend(tempError, data, data + length);
break;
default:
done = true;
}
if ((res == cmsysProcess_Pipe_STDOUT || res == cmsysProcess_Pipe_STDERR) &&
- this->ExtraVerbose) {
+ this->Impl->ExtraVerbose) {
processOutput.DecodeText(data, length, strdata);
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
}
}
- if (this->ExtraVerbose) {
+ if (this->Impl->ExtraVerbose) {
processOutput.DecodeText(std::string(), strdata);
if (!strdata.empty()) {
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
}
}
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
if (!tempOutput.empty()) {
processOutput.DecodeText(tempOutput, tempOutput);
- stdOut->append(&*tempOutput.begin(), tempOutput.size());
+ stdOut->append(tempOutput.data(), tempOutput.size());
}
if (!tempError.empty()) {
processOutput.DecodeText(tempError, tempError);
- stdErr->append(&*tempError.begin(), tempError.size());
+ stdErr->append(tempError.data(), tempError.size());
}
bool result = true;
@@ -2650,12 +3020,12 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut,
void cmCTest::SetOutputLogFileName(const char* name)
{
- if (this->OutputLogFile) {
- delete this->OutputLogFile;
- this->OutputLogFile = CM_NULLPTR;
+ if (this->Impl->OutputLogFile) {
+ delete this->Impl->OutputLogFile;
+ this->Impl->OutputLogFile = nullptr;
}
if (name) {
- this->OutputLogFile = new cmGeneratedFileStream(name);
+ this->Impl->OutputLogFile = new cmGeneratedFileStream(name);
}
}
@@ -2663,22 +3033,18 @@ static const char* cmCTestStringLogType[] = { "DEBUG",
"OUTPUT",
"HANDLER_OUTPUT",
"HANDLER_PROGRESS_OUTPUT",
+ "HANDLER_TEST_PROGRESS_OUTPUT",
"HANDLER_VERBOSE_OUTPUT",
"WARNING",
"ERROR_MESSAGE",
- CM_NULLPTR };
+ nullptr };
#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;
-}
+ do { \
+ if (this->Impl->ShowLineNumbers) { \
+ (stream) << std::endl << file << ":" << line << " "; \
+ } \
+ } while (false)
void cmCTest::Log(int logType, const char* file, int line, const char* msg,
bool suppress)
@@ -2690,42 +3056,70 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg,
return;
}
if (logType == cmCTest::HANDLER_PROGRESS_OUTPUT &&
- (this->Debug || this->ExtraVerbose)) {
+ (this->Impl->Debug || this->Impl->ExtraVerbose)) {
return;
}
- if (this->OutputLogFile) {
+ if (this->Impl->OutputLogFile) {
bool display = true;
- if (logType == cmCTest::DEBUG && !this->Debug) {
+ if (logType == cmCTest::DEBUG && !this->Impl->Debug) {
display = false;
}
- if (logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Debug &&
- !this->ExtraVerbose) {
+ if (logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Impl->Debug &&
+ !this->Impl->ExtraVerbose) {
display = false;
}
if (display) {
- cmCTestLogOutputFileLine(*this->OutputLogFile);
- if (logType != this->OutputLogFileLastTag) {
- *this->OutputLogFile << "[";
+ cmCTestLogOutputFileLine(*this->Impl->OutputLogFile);
+ if (logType != this->Impl->OutputLogFileLastTag) {
+ *this->Impl->OutputLogFile << "[";
if (logType >= OTHER || logType < 0) {
- *this->OutputLogFile << "OTHER";
+ *this->Impl->OutputLogFile << "OTHER";
} else {
- *this->OutputLogFile << cmCTestStringLogType[logType];
+ *this->Impl->OutputLogFile << cmCTestStringLogType[logType];
}
- *this->OutputLogFile << "] " << std::endl << std::flush;
+ *this->Impl->OutputLogFile << "] " << std::endl << std::flush;
}
- *this->OutputLogFile << msg << std::flush;
- if (logType != this->OutputLogFileLastTag) {
- *this->OutputLogFile << std::endl << std::flush;
- this->OutputLogFileLastTag = logType;
+ *this->Impl->OutputLogFile << msg << std::flush;
+ if (logType != this->Impl->OutputLogFileLastTag) {
+ *this->Impl->OutputLogFile << std::endl << std::flush;
+ this->Impl->OutputLogFileLastTag = logType;
}
}
}
- if (!this->Quiet) {
- std::ostream& out = *this->StreamOut;
- std::ostream& err = *this->StreamErr;
+ if (!this->Impl->Quiet) {
+ std::ostream& out = *this->Impl->StreamOut;
+ std::ostream& err = *this->Impl->StreamErr;
+
+ if (logType == HANDLER_TEST_PROGRESS_OUTPUT) {
+ if (this->Impl->TestProgressOutput) {
+ cmCTestLogOutputFileLine(out);
+ if (this->Impl->FlushTestProgressLine) {
+ printf("\r");
+ this->Impl->FlushTestProgressLine = false;
+ out.flush();
+ }
+
+ std::string msg_str{ msg };
+ auto const lineBreakIt = msg_str.find('\n');
+ if (lineBreakIt != std::string::npos) {
+ this->Impl->FlushTestProgressLine = true;
+ msg_str.erase(std::remove(msg_str.begin(), msg_str.end(), '\n'),
+ msg_str.end());
+ }
+
+ out << msg_str;
+#ifndef _WIN32
+ printf("\x1B[K"); // move caret to end
+#endif
+ out.flush();
+ return;
+ }
+ logType = HANDLER_OUTPUT;
+ }
+
switch (logType) {
case DEBUG:
- if (this->Debug) {
+ if (this->Impl->Debug) {
cmCTestLogOutputFileLine(out);
out << msg;
out.flush();
@@ -2733,14 +3127,14 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg,
break;
case OUTPUT:
case HANDLER_OUTPUT:
- if (this->Debug || this->Verbose) {
+ if (this->Impl->Debug || this->Impl->Verbose) {
cmCTestLogOutputFileLine(out);
out << msg;
out.flush();
}
break;
case HANDLER_VERBOSE_OUTPUT:
- if (this->Debug || this->ExtraVerbose) {
+ if (this->Impl->Debug || this->Impl->ExtraVerbose) {
cmCTestLogOutputFileLine(out);
out << msg;
out.flush();
@@ -2765,23 +3159,40 @@ void cmCTest::Log(int logType, const char* file, int line, const char* msg,
}
}
-double cmCTest::GetRemainingTimeAllowed()
+std::string cmCTest::GetColorCode(Color color) const
{
- if (!this->GetHandler("script")) {
- return 1.0e7;
+ if (this->Impl->OutputColorCode) {
+#if defined(_WIN32)
+ // Not supported on Windows
+ static_cast<void>(color);
+#else
+ return "\033[0;" + std::to_string(static_cast<int>(color)) + "m";
+#endif
}
- cmCTestScriptHandler* ch =
- static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
+ return "";
+}
+
+cmDuration cmCTest::GetRemainingTimeAllowed()
+{
+ return this->GetScriptHandler()->GetRemainingTimeAllowed();
+}
+
+cmDuration cmCTest::MaxDuration()
+{
+ return cmDuration(1.0e7);
+}
- return ch->GetRemainingTimeAllowed();
+void cmCTest::SetRunCurrentScript(bool value)
+{
+ this->GetScriptHandler()->SetRunCurrentScript(value);
}
void cmCTest::OutputTestErrors(std::vector<char> const& process_output)
{
std::string test_outputs("\n*** Test Failed:\n");
if (!process_output.empty()) {
- test_outputs.append(&*process_output.begin(), process_output.size());
+ test_outputs.append(process_output.data(), process_output.size());
}
cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush);
}
@@ -2813,8 +3224,8 @@ bool cmCTest::CompressString(std::string& str)
ret = deflate(&strm, Z_FINISH);
if (ret != Z_STREAM_END) {
- cmCTestLog(this, ERROR_MESSAGE, "Error during gzip compression."
- << std::endl);
+ cmCTestLog(this, ERROR_MESSAGE,
+ "Error during gzip compression." << std::endl);
return false;
}
diff --git a/Source/cmCTest.h b/Source/cmCTest.h
index 60f3295e7..d300c33fa 100644
--- a/Source/cmCTest.h
+++ b/Source/cmCTest.h
@@ -3,18 +3,29 @@
#ifndef cmCTest_h
#define cmCTest_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmDuration.h"
#include "cmProcessOutput.h"
-#include "cmsys/String.hxx"
+
+#include <chrono>
#include <map>
-#include <set>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
-class cmCTestGenericHandler;
+class cmCTestBuildHandler;
+class cmCTestBuildAndTestHandler;
+class cmCTestCoverageHandler;
+class cmCTestScriptHandler;
+class cmCTestTestHandler;
+class cmCTestUpdateHandler;
+class cmCTestConfigureHandler;
+class cmCTestMemCheckHandler;
+class cmCTestSubmitHandler;
+class cmCTestUploadHandler;
class cmCTestStartCommand;
class cmGeneratedFileStream;
class cmMakefile;
@@ -29,9 +40,6 @@ class cmXMLWriter;
*/
class cmCTest
{
- friend class cmCTestRunTest;
- friend class cmCTestMultiProcessHandler;
-
public:
typedef cmProcessOutput::Encoding Encoding;
/** Enumerate parts of the testing and submission process. */
@@ -48,54 +56,16 @@ public:
PartNotes,
PartExtraFiles,
PartUpload,
+ PartDone,
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 const& fields = "",
- std::string const& 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 = CM_NULLPTR);
+ int Run(std::vector<std::string>&, std::string* output = nullptr);
/**
* Initialize and finalize testing
@@ -130,25 +100,25 @@ public:
/**
* Is the tomorrow tag set?
*/
- bool GetTomorrowTag() { return this->TomorrowTag; }
+ bool GetTomorrowTag() const;
/**
* Try to run tests of the project
*/
int TestDirectory(bool memcheck);
- /** what is the configuraiton type, e.g. Debug, Release etc. */
+ /** what is the configuration type, e.g. Debug, Release etc. */
std::string const& GetConfigType();
- double GetTimeOut() { return this->TimeOut; }
- void SetTimeOut(double t) { this->TimeOut = t; }
+ cmDuration GetTimeOut() const;
+ void SetTimeOut(cmDuration t);
- double GetGlobalTimeout() { return this->GlobalTimeout; }
+ cmDuration GetGlobalTimeout() const;
/** how many test to run at the same time */
- int GetParallelLevel() { return this->ParallelLevel; }
+ int GetParallelLevel() const;
void SetParallelLevel(int);
- unsigned long GetTestLoad() { return this->TestLoad; }
+ unsigned long GetTestLoad() const;
void SetTestLoad(unsigned long);
/**
@@ -166,7 +136,7 @@ public:
* Set the cmake test mode (experimental, nightly, continuous).
*/
void SetTestModel(int mode);
- int GetTestModel() { return this->TestModel; }
+ int GetTestModel() const;
std::string GetTestModelString();
static int GetTestModelFromString(const char* str);
@@ -176,12 +146,17 @@ public:
bool suppress = false);
void EmptyCTestConfiguration();
+ std::string GetSubmitURL();
+
/**
* constructor and destructor
*/
cmCTest();
~cmCTest();
+ cmCTest(const cmCTest&) = delete;
+ cmCTest& operator=(const cmCTest&) = delete;
+
/** Set the notes files to be created. */
void SetNotesFiles(const char* notes);
@@ -200,9 +175,11 @@ public:
/**
* 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
+ * not been set it returns a very large duration.
*/
- double GetRemainingTimeAllowed();
+ cmDuration GetRemainingTimeAllowed();
+
+ static cmDuration MaxDuration();
/**
* Open file in the output directory and set the stream
@@ -213,23 +190,27 @@ public:
/** Should we only show what we would do? */
bool GetShowOnly();
- bool ShouldUseHTTP10() { return this->UseHTTP10; }
+ bool GetOutputAsJson();
+
+ int GetOutputAsJsonVersion();
- bool ShouldPrintLabels() { return this->PrintLabels; }
+ bool ShouldUseHTTP10() const;
+
+ bool ShouldPrintLabels() const;
bool ShouldCompressTestOutput();
bool CompressString(std::string& str);
- std::string GetStopTime() { return this->StopTime; }
+ std::chrono::system_clock::time_point GetStopTime() const;
void SetStopTime(std::string const& time);
/** Used for parallel ctest job scheduling */
- std::string GetScheduleType() { return this->ScheduleType; }
- void SetScheduleType(std::string const& type) { this->ScheduleType = type; }
+ std::string GetScheduleType() const;
+ void SetScheduleType(std::string const& type);
/** The max output width */
int GetMaxTestNameWidth() const;
- void SetMaxTestNameWidth(int w) { this->MaxTestNameWidth = w; }
+ void SetMaxTestNameWidth(int w);
/**
* Run a single executable command and put the stdout and stderr
@@ -245,15 +226,11 @@ public:
* 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 = CM_NULLPTR,
- const char* dir = CM_NULLPTR, double timeout = 0.0,
+ bool RunCommand(std::vector<std::string> const& args, std::string* stdOut,
+ std::string* stdErr, int* retVal = nullptr,
+ const char* dir = nullptr,
+ cmDuration timeout = cmDuration::zero(),
Encoding encoding = cmProcessOutput::Auto);
/**
@@ -272,8 +249,9 @@ public:
* 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,
+ int RunMakeCommand(const std::string& command, std::string& output,
+ int* retVal, const char* dir, cmDuration timeout,
+ std::ostream& ofs,
Encoding encoding = cmProcessOutput::Auto);
/** Return the current tag */
@@ -292,9 +270,10 @@ public:
enum
{
- EXPERIMENTAL,
- NIGHTLY,
- CONTINUOUS
+ UNKNOWN = -1,
+ EXPERIMENTAL = 0,
+ NIGHTLY = 1,
+ CONTINUOUS = 2,
};
/** provide some more detailed info on the return code for ctest */
@@ -320,21 +299,23 @@ public:
* 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::ostream* logfile, cmDuration testTimeOut,
std::vector<std::string>* environment,
Encoding encoding = cmProcessOutput::Auto);
/**
- * 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);
+ cmCTestBuildHandler* GetBuildHandler();
+ cmCTestBuildAndTestHandler* GetBuildAndTestHandler();
+ cmCTestCoverageHandler* GetCoverageHandler();
+ cmCTestScriptHandler* GetScriptHandler();
+ cmCTestTestHandler* GetTestHandler();
+ cmCTestUpdateHandler* GetUpdateHandler();
+ cmCTestConfigureHandler* GetConfigureHandler();
+ cmCTestMemCheckHandler* GetMemCheckHandler();
+ cmCTestSubmitHandler* GetSubmitHandler();
+ cmCTestUploadHandler* GetUploadHandler();
/**
* Set the CTest variable from CMake variable
@@ -344,9 +325,6 @@ public:
const std::string& cmake_var,
bool suppress = false);
- /** 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&);
@@ -354,10 +332,7 @@ public:
* Should ctect configuration be updated. When using new style ctest
* script, this should be true.
*/
- void SetSuppressUpdatingCTestConfiguration(bool val)
- {
- this->SuppressUpdatingCTestConfiguration = val;
- }
+ void SetSuppressUpdatingCTestConfiguration(bool val);
/**
* Add overwrite to ctest configuration.
@@ -367,11 +342,14 @@ public:
void AddCTestConfigurationOverwrite(const std::string& encstr);
/** Create XML file that contains all the notes specified */
- int GenerateNotesFile(const VectorOfStrings& files);
+ int GenerateNotesFile(std::vector<std::string> const& files);
+
+ /** Create XML file to indicate that build is complete */
+ int GenerateDoneFile();
/** Submit extra files to the server */
bool SubmitExtraFiles(const char* files);
- bool SubmitExtraFiles(const VectorOfStrings& files);
+ bool SubmitExtraFiles(std::vector<std::string> const& files);
/** Set the output log file name */
void SetOutputLogFileName(const char* name);
@@ -386,6 +364,7 @@ public:
OUTPUT,
HANDLER_OUTPUT,
HANDLER_PROGRESS_OUTPUT,
+ HANDLER_TEST_PROGRESS_OUTPUT,
HANDLER_VERBOSE_OUTPUT,
WARNING,
ERROR_MESSAGE,
@@ -396,143 +375,74 @@ public:
void Log(int logType, const char* file, int line, const char* msg,
bool suppress = false);
- /** Get the version of dart server */
- int GetDartVersion() { return this->DartVersion; }
- int GetDropSiteCDash() { return this->DropSiteCDash; }
+ /** Color values */
+ enum class Color
+ {
+ CLEAR_COLOR = 0,
+ RED = 31,
+ GREEN = 32,
+ YELLOW = 33,
+ BLUE = 34
+ };
+
+ /** Get color code characters for a specific color */
+ std::string GetColorCode(Color color) const;
+
+ /** The Build ID is assigned by CDash */
+ void SetBuildID(const std::string& id);
+ std::string GetBuildID() const;
/** 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(); }
+ std::vector<std::string> const& GetSubmitFiles(Part part) const;
+ void ClearSubmitFiles(Part part);
/**
* 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;
- }
+ std::vector<std::string>& GetInitialCommandLineArguments();
/** 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 SetFailover(bool failover);
+ bool GetFailover() const;
- void SetBatchJobs(bool batch = true) { this->BatchJobs = batch; }
- bool GetBatchJobs() { return this->BatchJobs; }
+ bool GetTestProgressOutput() const;
- bool GetVerbose() { return this->Verbose; }
- bool GetExtraVerbose() { return this->ExtraVerbose; }
+ bool GetVerbose() const;
+ bool GetExtraVerbose() const;
/** Direct process output to given streams. */
- void SetStreams(std::ostream* out, std::ostream* err)
- {
- this->StreamOut = out;
- this->StreamErr = err;
- }
+ void SetStreams(std::ostream* out, std::ostream* err);
+
void AddSiteProperties(cmXMLWriter& xml);
- bool GetLabelSummary() { return this->LabelSummary; }
+
+ bool GetLabelSummary() const;
+ bool GetSubprojectSummary() const;
std::string GetCostDataFile();
- const std::map<std::string, std::string>& GetDefinitions()
- {
- return this->Definitions;
- }
+ bool GetOutputTestOutputOnTestFailure() const;
+
+ const std::map<std::string, std::string>& GetDefinitions() const;
/** Return the number of times a test should be run */
- int GetTestRepeat() { return this->RepeatTests; }
+ int GetTestRepeat() const;
/** Return true if test should run until fail */
- bool GetRepeatUntilFail() { return this->RepeatUntilFail; }
-
-private:
- int RepeatTests;
- bool RepeatUntilFail;
- 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;
-
- 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;
+ bool GetRepeatUntilFail() const;
- int ParallelLevel;
- bool ParallelLevelSetInCli;
+ void GenerateSubprojectsOutput(cmXMLWriter& xml);
+ std::vector<std::string> GetLabelsForSubprojects();
- unsigned long TestLoad;
+ void SetRunCurrentScript(bool value);
- int CompatibilityMode;
-
- // information for the --build-and-test options
- std::string BinaryDir;
-
- std::string NotesFiles;
-
- bool InteractiveDebugMode;
-
- bool ShortDateFormat;
-
- bool CompressXMLFiles;
- bool CompressTestOutput;
-
- void InitStreams();
- std::ostream* StreamOut;
- std::ostream* StreamErr;
+private:
+ int GenerateNotesFile(const char* files);
void BlockTestErrorDiagnostics();
@@ -559,7 +469,18 @@ private:
bool HandleCommandLineArguments(size_t& i, std::vector<std::string>& args,
std::string& errormsg);
- /** hande the -S -SP and -SR arguments */
+#if !defined(_WIN32)
+ /** returns true iff the console supports progress output */
+ static bool ConsoleIsNotDumb();
+#endif
+
+ /** returns true iff the console supports progress output */
+ static bool ProgressOutputSupportedByConsole();
+
+ /** returns true iff the console supports colored output */
+ static bool ColoredOutputSupportedByConsole();
+
+ /** handle the -S -SP and -SR arguments */
void HandleScriptArguments(size_t& i, std::vector<std::string>& args,
bool& SRArgumentSpecified);
@@ -567,11 +488,12 @@ private:
bool UpdateCTestConfiguration();
/** Create note from files. */
- int GenerateCTestNotesOutput(cmXMLWriter& xml, const VectorOfStrings& files);
+ int GenerateCTestNotesOutput(cmXMLWriter& xml,
+ std::vector<std::string> const& files);
/** Check if the argument is the one specified */
bool CheckArgument(const std::string& arg, const char* varg1,
- const char* varg2 = CM_NULLPTR);
+ const char* varg2 = nullptr);
/** Output errors from a test */
void OutputTestErrors(std::vector<char> const& process_output);
@@ -587,25 +509,8 @@ private:
int RunCMakeAndTest(std::string* output);
int ExecuteTests();
- 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;
+ struct Private;
+ std::unique_ptr<Private> Impl;
};
class cmCTestLogWrite
diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx
index 0b025ab6f..358f095bb 100644
--- a/Source/cmCacheManager.cxx
+++ b/Source/cmCacheManager.cxx
@@ -8,12 +8,14 @@
#include <sstream>
#include <stdio.h>
#include <string.h>
+#include <string>
#include "cmGeneratedFileStream.h"
+#include "cmMessageType.h"
+#include "cmMessenger.h"
#include "cmState.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
-#include "cmake.h"
cmCacheManager::cmCacheManager()
{
@@ -24,7 +26,7 @@ cmCacheManager::cmCacheManager()
void cmCacheManager::CleanCMakeFiles(const std::string& path)
{
std::string glob = path;
- glob += cmake::GetCMakeFilesDirectory();
+ glob += "/CMakeFiles";
glob += "/*.cmake";
cmsys::Glob globIt;
globIt.FindFiles(glob);
@@ -42,7 +44,7 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal,
if (internal) {
this->Cache.clear();
}
- if (!cmSystemTools::FileExists(cacheFile.c_str())) {
+ if (!cmSystemTools::FileExists(cacheFile)) {
this->CleanCMakeFiles(path);
return false;
}
@@ -120,20 +122,20 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal,
std::ostringstream error;
error << "Parse error in cache file " << cacheFile;
error << " on line " << lineno << ". Offending entry: " << realbuffer;
- cmSystemTools::Error(error.str().c_str());
+ cmSystemTools::Error(error.str());
}
}
this->CacheMajorVersion = 0;
this->CacheMinorVersion = 0;
- if (const char* cmajor =
+ if (const std::string* cmajor =
this->GetInitializedCacheValue("CMAKE_CACHE_MAJOR_VERSION")) {
unsigned int v = 0;
- if (sscanf(cmajor, "%u", &v) == 1) {
+ if (sscanf(cmajor->c_str(), "%u", &v) == 1) {
this->CacheMajorVersion = v;
}
- if (const char* cminor =
+ if (const std::string* cminor =
this->GetInitializedCacheValue("CMAKE_CACHE_MINOR_VERSION")) {
- if (sscanf(cminor, "%u", &v) == 1) {
+ if (sscanf(cminor->c_str(), "%u", &v) == 1) {
this->CacheMinorVersion = v;
}
}
@@ -151,29 +153,31 @@ bool cmCacheManager::LoadCache(const std::string& path, bool internal,
}
// check to make sure the cache directory has not
// been moved
- const char* oldDir = this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR");
+ const std::string* oldDir =
+ this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR");
if (internal && oldDir) {
std::string currentcwd = path;
- std::string oldcwd = oldDir;
+ std::string oldcwd = *oldDir;
cmSystemTools::ConvertToUnixSlashes(currentcwd);
currentcwd += "/CMakeCache.txt";
oldcwd += "/CMakeCache.txt";
if (!cmSystemTools::SameFile(oldcwd, currentcwd)) {
- std::string message =
- std::string("The current CMakeCache.txt directory ") + currentcwd +
- std::string(" is different than the directory ") +
- std::string(this->GetInitializedCacheValue("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());
+ const std::string* dir =
+ this->GetInitializedCacheValue("CMAKE_CACHEFILE_DIR");
+ std::ostringstream message;
+ message << "The current CMakeCache.txt directory " << currentcwd
+ << " is different than the directory " << (dir ? *dir : "")
+ << " 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.str());
}
}
return true;
}
const char* cmCacheManager::PersistentProperties[] = { "ADVANCED", "MODIFIED",
- "STRINGS", CM_NULLPTR };
+ "STRINGS", nullptr };
bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
CacheEntry& e)
@@ -184,7 +188,7 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
}
const char* end = entryKey.c_str() + entryKey.size();
- for (const char** p = this->PersistentProperties; *p; ++p) {
+ for (const char** p = cmCacheManager::PersistentProperties; *p; ++p) {
std::string::size_type plen = strlen(*p) + 1;
if (entryKey.size() > plen && *(end - plen) == '-' &&
strcmp(end - plen + 1, *p) == 0) {
@@ -205,9 +209,10 @@ bool cmCacheManager::ReadPropertyEntry(std::string const& entryKey,
return false;
}
-void cmCacheManager::WritePropertyEntries(std::ostream& os, CacheIterator i)
+void cmCacheManager::WritePropertyEntries(std::ostream& os, CacheIterator i,
+ cmMessenger* messenger)
{
- for (const char** p = this->PersistentProperties; *p; ++p) {
+ for (const char** p = cmCacheManager::PersistentProperties; *p; ++p) {
if (const char* value = i.GetProperty(*p)) {
std::string helpstring = *p;
helpstring += " property for variable: ";
@@ -217,41 +222,41 @@ void cmCacheManager::WritePropertyEntries(std::ostream& os, CacheIterator i)
std::string key = i.GetName();
key += "-";
key += *p;
- this->OutputKey(os, key);
+ cmCacheManager::OutputKey(os, key);
os << ":INTERNAL=";
- this->OutputValue(os, value);
+ cmCacheManager::OutputValue(os, value);
os << "\n";
+ cmCacheManager::OutputNewlineTruncationWarning(os, key, value,
+ messenger);
}
}
}
-bool cmCacheManager::SaveCache(const std::string& path)
+bool cmCacheManager::SaveCache(const std::string& path, cmMessenger* messenger)
{
std::string cacheFile = path;
cacheFile += "/CMakeCache.txt";
- cmGeneratedFileStream fout(cacheFile.c_str());
+ cmGeneratedFileStream fout(cacheFile);
fout.SetCopyIfDifferent(true);
if (!fout) {
- cmSystemTools::Error("Unable to open cache file for save. ",
- cacheFile.c_str());
+ cmSystemTools::Error("Unable to open cache file for save. " + cacheFile);
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 "
+ this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION",
+ std::to_string(cmVersion::GetMajorVersion()).c_str(),
+ "Major version of cmake used to create the "
"current loaded cache",
cmStateEnums::INTERNAL);
- sprintf(temp, "%d", cmVersion::GetMajorVersion());
- this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", temp,
- "Major version of cmake used to create the "
+ this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION",
+ std::to_string(cmVersion::GetMinorVersion()).c_str(),
+ "Minor version of cmake used to create the "
"current loaded cache",
cmStateEnums::INTERNAL);
- sprintf(temp, "%d", cmVersion::GetPatchVersion());
- this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION", temp,
+ this->AddCacheEntry("CMAKE_CACHE_PATCH_VERSION",
+ std::to_string(cmVersion::GetPatchVersion()).c_str(),
"Patch version of cmake used to create the "
"current loaded cache",
cmStateEnums::INTERNAL);
@@ -297,16 +302,13 @@ bool cmCacheManager::SaveCache(const std::string& path)
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;
+ for (auto const& i : this->Cache) {
+ CacheEntry const& ce = i.second;
cmStateEnums::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");
+ cmSystemTools::Error("Cache entry \"" + i.first + "\" is uninitialized");
*/
} else if (t != cmStateEnums::INTERNAL) {
// Format is key:type=value
@@ -315,10 +317,13 @@ bool cmCacheManager::SaveCache(const std::string& path)
} else {
cmCacheManager::OutputHelpString(fout, "Missing description");
}
- this->OutputKey(fout, i->first);
+ cmCacheManager::OutputKey(fout, i.first);
fout << ":" << cmState::CacheEntryTypeToString(t) << "=";
- this->OutputValue(fout, ce.Value);
- fout << "\n\n";
+ cmCacheManager::OutputValue(fout, ce.Value);
+ fout << "\n";
+ cmCacheManager::OutputNewlineTruncationWarning(fout, i.first, ce.Value,
+ messenger);
+ fout << "\n";
}
}
@@ -335,28 +340,30 @@ bool cmCacheManager::SaveCache(const std::string& path)
}
cmStateEnums::CacheEntryType t = i.GetType();
- this->WritePropertyEntries(fout, i);
+ this->WritePropertyEntries(fout, i, messenger);
if (t == cmStateEnums::INTERNAL) {
// Format is key:type=value
if (const char* help = i.GetProperty("HELPSTRING")) {
- this->OutputHelpString(fout, help);
+ cmCacheManager::OutputHelpString(fout, help);
}
- this->OutputKey(fout, i.GetName());
+ cmCacheManager::OutputKey(fout, i.GetName());
fout << ":" << cmState::CacheEntryTypeToString(t) << "=";
- this->OutputValue(fout, i.GetValue());
+ cmCacheManager::OutputValue(fout, i.GetValue());
fout << "\n";
+ cmCacheManager::OutputNewlineTruncationWarning(fout, i.GetName(),
+ i.GetValue(), messenger);
}
}
fout << "\n";
fout.Close();
std::string checkCacheFile = path;
- checkCacheFile += cmake::GetCMakeFilesDirectory();
- cmSystemTools::MakeDirectory(checkCacheFile.c_str());
+ checkCacheFile += "/CMakeFiles";
+ cmSystemTools::MakeDirectory(checkCacheFile);
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());
+ cmSystemTools::Error("Unable to open check cache file for write. " +
+ checkCacheFile);
return false;
}
checkCache << "# This file is generated by cmake for dependency checking "
@@ -370,11 +377,11 @@ bool cmCacheManager::DeleteCache(const std::string& path)
cmSystemTools::ConvertToUnixSlashes(cacheFile);
std::string cmakeFiles = cacheFile;
cacheFile += "/CMakeCache.txt";
- if (cmSystemTools::FileExists(cacheFile.c_str())) {
+ if (cmSystemTools::FileExists(cacheFile)) {
cmSystemTools::RemoveFile(cacheFile);
// now remove the files in the CMakeFiles directory
// this cleans up language cache files
- cmakeFiles += cmake::GetCMakeFilesDirectory();
+ cmakeFiles += "/CMakeFiles";
if (cmSystemTools::FileIsDirectory(cmakeFiles)) {
cmSystemTools::RemoveADirectory(cmakeFiles);
}
@@ -392,9 +399,21 @@ void cmCacheManager::OutputKey(std::ostream& fout, std::string const& key)
void cmCacheManager::OutputValue(std::ostream& fout, std::string const& value)
{
+ // look for and truncate newlines
+ std::string::size_type newline = value.find('\n');
+ if (newline != std::string::npos) {
+ std::string truncated = value.substr(0, newline);
+ OutputValueNoNewlines(fout, truncated);
+ } else {
+ OutputValueNoNewlines(fout, value);
+ }
+}
+
+void cmCacheManager::OutputValueNoNewlines(std::ostream& fout,
+ std::string const& value)
+{
// if value has trailing space or tab, enclose it in single quotes
- if (!value.empty() &&
- (value[value.size() - 1] == ' ' || value[value.size() - 1] == '\t')) {
+ if (!value.empty() && (value.back() == ' ' || value.back() == '\t')) {
fout << '\'' << value << '\'';
} else {
fout << value;
@@ -425,6 +444,50 @@ void cmCacheManager::OutputHelpString(std::ostream& fout,
}
}
+void cmCacheManager::OutputWarningComment(std::ostream& fout,
+ std::string const& message,
+ bool wrapSpaces)
+{
+ std::string::size_type end = message.size();
+ std::string oneLine;
+ std::string::size_type pos = 0;
+ for (std::string::size_type i = 0; i <= end; i++) {
+ if ((i == end) || (message[i] == '\n') ||
+ ((i - pos >= 60) && (message[i] == ' ') && wrapSpaces)) {
+ fout << "# ";
+ if (message[pos] == '\n') {
+ pos++;
+ fout << "\\n";
+ }
+ oneLine = message.substr(pos, i - pos);
+ fout << oneLine << "\n";
+ pos = i;
+ }
+ }
+}
+
+void cmCacheManager::OutputNewlineTruncationWarning(std::ostream& fout,
+ std::string const& key,
+ std::string const& value,
+ cmMessenger* messenger)
+{
+ if (value.find('\n') != std::string::npos) {
+ if (messenger) {
+ std::string message = "Value of ";
+ message += key;
+ message += " contained a newline; truncating";
+ messenger->IssueMessage(MessageType::WARNING, message);
+ }
+
+ std::string comment = "WARNING: Value of ";
+ comment += key;
+ comment += " contained a newline and was truncated. Original value:";
+
+ OutputWarningComment(fout, comment, true);
+ OutputWarningComment(fout, value, false);
+ }
+}
+
void cmCacheManager::RemoveCacheEntry(const std::string& key)
{
CacheEntryMap::iterator i = this->Cache.find(key);
@@ -440,7 +503,7 @@ cmCacheManager::CacheEntry* cmCacheManager::GetCacheEntry(
if (i != this->Cache.end()) {
return &i->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char* key)
@@ -448,25 +511,23 @@ cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char* key)
return CacheIterator(*this, key);
}
-const char* cmCacheManager::GetInitializedCacheValue(
+const std::string* cmCacheManager::GetInitializedCacheValue(
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 &i->second.Value;
}
- return CM_NULLPTR;
+ return nullptr;
}
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 != cmStateEnums::INTERNAL) {
- out << (*i).first << " = " << (*i).second.Value << std::endl;
+ for (auto const& i : this->Cache) {
+ if (i.second.Type != cmStateEnums::INTERNAL) {
+ out << i.first << " = " << i.second.Value << std::endl;
}
}
out << "\n\n";
@@ -484,7 +545,7 @@ void cmCacheManager::AddCacheEntry(const std::string& key, const char* value,
e.Value = value;
e.Initialized = true;
} else {
- e.Value = "";
+ e.Value.clear();
}
e.Type = type;
// make sure we only use unix style paths
@@ -494,18 +555,18 @@ void cmCacheManager::AddCacheEntry(const std::string& key, const char* value,
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);
+ for (std::string& i : paths) {
+ cmSystemTools::ConvertToUnixSlashes(i);
e.Value += sep;
- e.Value += *i;
+ e.Value += i;
sep = ";";
}
} else {
cmSystemTools::ConvertToUnixSlashes(e.Value);
}
}
- e.SetProperty("HELPSTRING", helpString
+ e.SetProperty("HELPSTRING",
+ helpString
? helpString
: "(This variable does not exist and should not be used)");
}
@@ -548,13 +609,13 @@ void cmCacheManager::CacheIterator::SetValue(const char* value)
entry->Value = value;
entry->Initialized = true;
} else {
- entry->Value = "";
+ entry->Value.clear();
}
}
bool cmCacheManager::CacheIterator::GetValueAsBool() const
{
- return cmSystemTools::IsOn(this->GetEntry().Value.c_str());
+ return cmSystemTools::IsOn(this->GetEntry().Value);
}
std::vector<std::string> cmCacheManager::CacheEntry::GetPropertyList() const
@@ -610,7 +671,7 @@ const char* cmCacheManager::CacheIterator::GetProperty(
if (!this->IsAtEnd()) {
return this->GetEntry().GetProperty(prop);
}
- return CM_NULLPTR;
+ return nullptr;
}
void cmCacheManager::CacheIterator::SetProperty(const std::string& p,
@@ -647,5 +708,5 @@ void cmCacheManager::CacheIterator::SetProperty(const std::string& p, bool v)
bool cmCacheManager::CacheIterator::PropertyExists(
const std::string& prop) const
{
- return this->GetProperty(prop) != CM_NULLPTR;
+ return this->GetProperty(prop) != nullptr;
}
diff --git a/Source/cmCacheManager.h b/Source/cmCacheManager.h
index c464311c6..65f22f72b 100644
--- a/Source/cmCacheManager.h
+++ b/Source/cmCacheManager.h
@@ -15,7 +15,7 @@
#include "cmPropertyMap.h"
#include "cmStateTypes.h"
-class cmake;
+class cmMessenger;
/** \class cmCacheManager
* \brief Control class for cmake's cache
@@ -34,20 +34,14 @@ private:
struct CacheEntry
{
std::string Value;
- cmStateEnums::CacheEntryType Type;
+ cmStateEnums::CacheEntryType Type = cmStateEnums::UNINITIALIZED;
cmPropertyMap Properties;
std::vector<std::string> GetPropertyList() const;
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(cmStateEnums::UNINITIALIZED)
- , Initialized(false)
- {
- }
+ bool Initialized = false;
};
public:
@@ -99,40 +93,40 @@ public:
CacheEntry& GetEntry() { return this->Position->second; }
};
- ///! return an iterator to iterate through the cache map
+ //! return an iterator to iterate through the cache map
cmCacheManager::CacheIterator NewIterator() { return CacheIterator(*this); }
- ///! Load a cache for given makefile. Loads from path/CMakeCache.txt.
+ //! Load a cache for given makefile. Loads from path/CMakeCache.txt.
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 path/CMakeCache.txt
- bool SaveCache(const std::string& path);
+ //! Save cache for given makefile. Saves to output path/CMakeCache.txt
+ bool SaveCache(const std::string& path, cmMessenger* messenger);
- ///! Delete the cache given
+ //! Delete the cache given
bool DeleteCache(const std::string& path);
- ///! Print the cache to a stream
+ //! 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 = CM_NULLPTR);
+ //! Get the iterator for an entry with a given key.
+ cmCacheManager::CacheIterator GetCacheIterator(const char* key = nullptr);
- ///! Remove an entry from the cache
+ //! Remove an entry from the cache
void RemoveCacheEntry(const std::string& key);
- ///! Get the number of entries in the cache
+ //! Get the number of entries in the cache
int GetSize() { return static_cast<int>(this->Cache.size()); }
- ///! Get a value from the cache given a key
- const char* GetInitializedCacheValue(const std::string& key) const;
+ //! Get a value from the cache given a key
+ const std::string* GetInitializedCacheValue(const std::string& key) const;
const char* GetCacheEntryValue(const std::string& key)
{
cmCacheManager::CacheIterator it = this->GetCacheIterator(key.c_str());
if (it.IsAtEnd()) {
- return CM_NULLPTR;
+ return nullptr;
}
return it.GetValue();
}
@@ -175,8 +169,7 @@ public:
void RemoveCacheEntryProperty(std::string const& key,
std::string const& propName)
{
- this->GetCacheIterator(key.c_str())
- .SetProperty(propName, (void*)CM_NULLPTR);
+ this->GetCacheIterator(key.c_str()).SetProperty(propName, nullptr);
}
void AppendCacheEntryProperty(std::string const& key,
@@ -204,14 +197,14 @@ public:
unsigned int GetCacheMinorVersion() const { return this->CacheMinorVersion; }
protected:
- ///! Add an entry into the cache
+ //! Add an entry into the cache
void AddCacheEntry(const std::string& key, const char* value,
const char* helpString,
cmStateEnums::CacheEntryType type);
- ///! Get a cache entry object for a key
+ //! Get a cache entry object for a key
CacheEntry* GetCacheEntry(const std::string& key);
- ///! Clean out the CMakeFiles directory if no CMakeCache.txt
+ //! Clean out the CMakeFiles directory if no CMakeCache.txt
void CleanCMakeFiles(const std::string& path);
// Cache version info
@@ -219,16 +212,25 @@ protected:
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 OutputWarningComment(std::ostream& fout,
+ std::string const& message,
+ bool wrapSpaces);
+ static void OutputNewlineTruncationWarning(std::ostream& fout,
+ std::string const& key,
+ std::string const& value,
+ cmMessenger* messenger);
static void OutputKey(std::ostream& fout, std::string const& key);
static void OutputValue(std::ostream& fout, std::string const& value);
+ static void OutputValueNoNewlines(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 i);
+ void WritePropertyEntries(std::ostream& os, CacheIterator i,
+ cmMessenger* messenger);
CacheEntryMap Cache;
// Only cmake and cmState should be able to add cache values
diff --git a/Source/cmCallVisualStudioMacro.cxx b/Source/cmCallVisualStudioMacro.cxx
index 99fe5877e..f7a224492 100644
--- a/Source/cmCallVisualStudioMacro.cxx
+++ b/Source/cmCallVisualStudioMacro.cxx
@@ -7,7 +7,7 @@
#include "cmSystemTools.h"
#if defined(_MSC_VER)
-#define HAVE_COMDEF_H
+# define HAVE_COMDEF_H
#endif
// Just for this file:
@@ -16,41 +16,41 @@ static bool LogErrorsAsMessages;
#if defined(HAVE_COMDEF_H)
-#include <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.
//
-#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
-
-///! 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 _hresult_oss; \
- _hresult_oss.flags(std::ios::hex); \
- _hresult_oss << context << " failed HRESULT, hr = 0x" << hr \
- << std::endl; \
- _hresult_oss.flags(std::ios::dec); \
- _hresult_oss << __FILE__ << "(" << __LINE__ << ")"; \
- cmSystemTools::Message(_hresult_oss.str().c_str()); \
- } \
- }
+# 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
+
+//! 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 _hresult_oss; \
+ _hresult_oss.flags(std::ios::hex); \
+ _hresult_oss << context << " failed HRESULT, hr = 0x" << hr \
+ << std::endl; \
+ _hresult_oss.flags(std::ios::dec); \
+ _hresult_oss << __FILE__ << "(" << __LINE__ << ")"; \
+ cmSystemTools::Message(_hresult_oss.str()); \
+ } \
+ }
-///! Using the given instance of Visual Studio, call the named macro
+//! Using the given instance of Visual Studio, call the named macro
HRESULT InstanceCallMacro(IDispatch* vsIDE, const std::string& macro,
const std::string& args)
{
@@ -61,7 +61,8 @@ HRESULT InstanceCallMacro(IDispatch* vsIDE, const std::string& macro,
if (0 != vsIDE) {
DISPID dispid = (DISPID)-1;
- OLECHAR* name = L"ExecuteCommand";
+ wchar_t execute_command[] = L"ExecuteCommand";
+ OLECHAR* name = execute_command;
hr =
vsIDE->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
@@ -119,7 +120,8 @@ HRESULT InstanceCallMacro(IDispatch* vsIDE, const std::string& macro,
}
oss << " dwHelpContext: " << excep.dwHelpContext << std::endl;
oss << " pvReserved: " << excep.pvReserved << std::endl;
- oss << " pfnDeferredFillIn: " << excep.pfnDeferredFillIn << std::endl;
+ oss << " pfnDeferredFillIn: "
+ << reinterpret_cast<void*>(excep.pfnDeferredFillIn) << std::endl;
oss << " scode: " << excep.scode << std::endl;
}
@@ -133,14 +135,15 @@ HRESULT InstanceCallMacro(IDispatch* vsIDE, const std::string& macro,
return hr;
}
-///! Get the Solution object from the IDE object
+//! 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";
+ wchar_t solution[] = L"Solution";
+ OLECHAR* name = solution;
hr =
vsIDE->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
@@ -176,14 +179,15 @@ HRESULT GetSolutionObject(IDispatch* vsIDE, IDispatchPtr& vsSolution)
return hr;
}
-///! Get the FullName property from the Solution object
+//! 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";
+ wchar_t full_name[] = L"FullName";
+ OLECHAR* name = full_name;
hr = vsSolution->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT,
&dispid);
@@ -220,7 +224,7 @@ HRESULT GetSolutionFullName(IDispatch* vsSolution, std::string& fullName)
return hr;
}
-///! Get the FullName property from the Solution object, given the IDE object
+//! Get the FullName property from the Solution object, given the IDE object
HRESULT GetIDESolutionFullName(IDispatch* vsIDE, std::string& fullName)
{
IDispatchPtr vsSolution;
@@ -235,8 +239,8 @@ HRESULT GetIDESolutionFullName(IDispatch* vsIDE, std::string& fullName)
return hr;
}
-///! Get all running objects from the Windows running object table.
-///! Save them in a map by their display names.
+//! 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
@@ -292,8 +296,8 @@ HRESULT GetRunningInstances(std::map<std::string, IUnknownPtr>& mrot)
return hr;
}
-///! Do the two file names refer to the same Visual Studio solution? Or are
-///! we perhaps looking for any and all solutions?
+//! 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") {
@@ -310,9 +314,9 @@ bool FilesSameSolution(const std::string& slnFile, const std::string& slnName)
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.
+//! 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)
{
@@ -384,8 +388,8 @@ int cmCallVisualStudioMacro::GetNumberOfRunningVisualStudioInstances(
return count;
}
-///! Get all running objects from the Windows running object table.
-///! Save them in a map by their display names.
+//! 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,
@@ -446,7 +450,7 @@ int cmCallVisualStudioMacro::CallMacro(const std::string& slnFile,
if (err && LogErrorsAsMessages) {
std::ostringstream oss;
oss << "cmCallVisualStudioMacro::CallMacro failed, err = " << err;
- cmSystemTools::Message(oss.str().c_str());
+ cmSystemTools::Message(oss.str());
}
return 0;
diff --git a/Source/cmCallVisualStudioMacro.h b/Source/cmCallVisualStudioMacro.h
index ad35d306a..9b5b3a843 100644
--- a/Source/cmCallVisualStudioMacro.h
+++ b/Source/cmCallVisualStudioMacro.h
@@ -3,7 +3,7 @@
#ifndef cmCallVisualStudioMacro_h
#define cmCallVisualStudioMacro_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -16,16 +16,16 @@
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.
+ //! 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.
+ //! 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);
diff --git a/Source/cmCommand.h b/Source/cmCommand.h
index ad72fe208..9ccd773f6 100644
--- a/Source/cmCommand.h
+++ b/Source/cmCommand.h
@@ -3,7 +3,7 @@
#ifndef cmCommand_h
#define cmCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,21 +24,19 @@ struct cmListFileArgument;
*/
class cmCommand
{
- CM_DISABLE_COPY(cmCommand)
-
public:
/**
* Construct the command. By default it has no makefile.
*/
- cmCommand()
- : Makefile(CM_NULLPTR)
- {
- }
+ cmCommand() = default;
/**
* Need virtual destructor to destroy real command type.
*/
- virtual ~cmCommand() {}
+ virtual ~cmCommand() = default;
+
+ cmCommand(cmCommand const&) = delete;
+ cmCommand& operator=(cmCommand const&) = delete;
/**
* Specify the makefile.
@@ -90,7 +88,7 @@ public:
void SetError(const std::string& e);
protected:
- cmMakefile* Makefile;
+ cmMakefile* Makefile = nullptr;
private:
std::string Error;
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx
index 4eb4531f6..ca2996741 100644
--- a/Source/cmCommandArgumentParserHelper.cxx
+++ b/Source/cmCommandArgumentParserHelper.cxx
@@ -6,7 +6,6 @@
#include "cmMakefile.h"
#include "cmState.h"
#include "cmSystemTools.h"
-#include "cmake.h"
#include <iostream>
#include <sstream>
@@ -16,18 +15,9 @@ int cmCommandArgument_yyparse(yyscan_t yyscanner);
//
cmCommandArgumentParserHelper::cmCommandArgumentParserHelper()
{
- this->WarnUninitialized = false;
- this->CheckSystemVars = false;
this->FileLine = -1;
- this->FileName = CM_NULLPTR;
+ this->FileName = nullptr;
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;
@@ -44,10 +34,10 @@ void cmCommandArgumentParserHelper::SetLineFile(long line, const char* file)
this->FileName = file;
}
-char* cmCommandArgumentParserHelper::AddString(const std::string& str)
+const char* cmCommandArgumentParserHelper::AddString(const std::string& str)
{
if (str.empty()) {
- return this->EmptyVariable;
+ return "";
}
char* stVal = new char[str.size() + 1];
strcpy(stVal, str.c_str());
@@ -55,14 +45,14 @@ char* cmCommandArgumentParserHelper::AddString(const std::string& str)
return stVal;
}
-char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key,
- const char* var)
+const char* cmCommandArgumentParserHelper::ExpandSpecialVariable(
+ const char* key, const char* var)
{
if (!key) {
return this->ExpandVariable(var);
}
if (!var) {
- return this->EmptyVariable;
+ return "";
}
if (strcmp(key, "ENV") == 0) {
std::string str;
@@ -72,29 +62,29 @@ char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key,
}
return this->AddString(str);
}
- return this->EmptyVariable;
+ return "";
}
if (strcmp(key, "CACHE") == 0) {
- if (const char* c =
+ if (const std::string* c =
this->Makefile->GetState()->GetInitializedCacheValue(var)) {
if (this->EscapeQuotes) {
- return this->AddString(cmSystemTools::EscapeQuotes(c));
+ return this->AddString(cmSystemTools::EscapeQuotes(*c));
}
- return this->AddString(c);
+ return this->AddString(*c);
}
- return this->EmptyVariable;
+ return "";
}
std::ostringstream e;
e << "Syntax $" << key << "{} is not supported. "
<< "Only ${}, $ENV{}, and $CACHE{} are allowed.";
this->SetError(e.str());
- return CM_NULLPTR;
+ return nullptr;
}
-char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
+const char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
{
if (!var) {
- return CM_NULLPTR;
+ return nullptr;
}
if (this->FileLine >= 0 && strcmp(var, "CMAKE_CURRENT_LIST_LINE") == 0) {
std::ostringstream ostr;
@@ -102,22 +92,11 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
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())) {
- std::ostringstream msg;
- msg << "uninitialized variable \'" << var << "\'";
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
- }
+ if (!value) {
+ this->Makefile->MaybeWarnUninitialized(var, this->FileName);
+ if (!this->RemoveEmpty) {
+ return nullptr;
}
- return CM_NULLPTR;
}
if (this->EscapeQuotes && value) {
return this->AddString(cmSystemTools::EscapeQuotes(value));
@@ -125,11 +104,11 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
return this->AddString(value ? value : "");
}
-char* cmCommandArgumentParserHelper::ExpandVariableForAt(const char* var)
+const char* cmCommandArgumentParserHelper::ExpandVariableForAt(const char* var)
{
if (this->ReplaceAtSyntax) {
// try to expand the variable
- char* ret = this->ExpandVariable(var);
+ const 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) {
@@ -150,7 +129,8 @@ char* cmCommandArgumentParserHelper::ExpandVariableForAt(const char* var)
return this->AddString(ref);
}
-char* cmCommandArgumentParserHelper::CombineUnions(char* in1, char* in2)
+const char* cmCommandArgumentParserHelper::CombineUnions(const char* in1,
+ const char* in2)
{
if (!in1) {
return in2;
@@ -169,17 +149,18 @@ char* cmCommandArgumentParserHelper::CombineUnions(char* in1, char* in2)
void cmCommandArgumentParserHelper::AllocateParserType(
cmCommandArgumentParserHelper::ParserType* pt, const char* str, int len)
{
- pt->str = CM_NULLPTR;
+ pt->str = nullptr;
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);
+ char* out = new char[len + 1];
+ memcpy(out, str, len);
+ out[len] = 0;
+ pt->str = out;
+ this->Variables.push_back(out);
}
bool cmCommandArgumentParserHelper::HandleEscapeSymbol(
@@ -234,7 +215,7 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
this->InputBufferPos = 0;
this->CurrentLine = 0;
- this->Result = "";
+ this->Result.clear();
yyscan_t yyscanner;
cmCommandArgument_yylex_init(&yyscanner);
@@ -257,9 +238,8 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
void cmCommandArgumentParserHelper::CleanupParser()
{
- std::vector<char*>::iterator sit;
- for (sit = this->Variables.begin(); sit != this->Variables.end(); ++sit) {
- delete[] * sit;
+ for (char* var : this->Variables) {
+ delete[] var;
}
this->Variables.erase(this->Variables.begin(), this->Variables.end());
}
@@ -291,14 +271,12 @@ void cmCommandArgumentParserHelper::Error(const char* 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 = "";
+ this->Result.clear();
return;
}
this->Result = value;
diff --git a/Source/cmCommandArgumentParserHelper.h b/Source/cmCommandArgumentParserHelper.h
index 465ca9e28..25e689224 100644
--- a/Source/cmCommandArgumentParserHelper.h
+++ b/Source/cmCommandArgumentParserHelper.h
@@ -3,7 +3,7 @@
#ifndef cmCommandArgumentParserHelper_h
#define cmCommandArgumentParserHelper_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -12,17 +12,19 @@ class cmMakefile;
class cmCommandArgumentParserHelper
{
- CM_DISABLE_COPY(cmCommandArgumentParserHelper)
-
public:
struct ParserType
{
- char* str;
+ const char* str;
};
cmCommandArgumentParserHelper();
~cmCommandArgumentParserHelper();
+ cmCommandArgumentParserHelper(cmCommandArgumentParserHelper const&) = delete;
+ cmCommandArgumentParserHelper& operator=(
+ cmCommandArgumentParserHelper const&) = delete;
+
int ParseString(const char* str, int verb);
// For the lexer:
@@ -35,11 +37,11 @@ public:
void Error(const char* str);
// For yacc
- char* CombineUnions(char* in1, char* in2);
+ const char* CombineUnions(const char* in1, const char* in2);
- char* ExpandSpecialVariable(const char* key, const char* var);
- char* ExpandVariable(const char* var);
- char* ExpandVariableForAt(const char* var);
+ const char* ExpandSpecialVariable(const char* key, const char* var);
+ const char* ExpandVariable(const char* var);
+ const char* ExpandVariableForAt(const char* var);
void SetResult(const char* value);
void SetMakefile(const cmMakefile* mf);
@@ -53,13 +55,6 @@ public:
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;
@@ -69,7 +64,7 @@ private:
void Print(const char* place, const char* str);
void SafePrintMissing(const char* str, int line, int cnt);
- char* AddString(const std::string& str);
+ const char* AddString(const std::string& str);
void CleanupParser();
void SetError(std::string const& msg);
@@ -82,8 +77,6 @@ private:
long FileLine;
int CurrentLine;
int Verbose;
- bool WarnUninitialized;
- bool CheckSystemVars;
bool EscapeQuotes;
bool NoEscapeMode;
bool ReplaceAtSyntax;
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index e1d8ef143..63c539734 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -4,6 +4,7 @@
#include "cmPolicies.h"
#include "cmState.h"
+#include "cmAddCompileDefinitionsCommand.h"
#include "cmAddCustomCommandCommand.h"
#include "cmAddCustomTargetCommand.h"
#include "cmAddDefinitionsCommand.h"
@@ -42,6 +43,7 @@
#include "cmIfCommand.h"
#include "cmIncludeCommand.h"
#include "cmIncludeDirectoryCommand.h"
+#include "cmIncludeGuardCommand.h"
#include "cmIncludeRegularExpressionCommand.h"
#include "cmInstallCommand.h"
#include "cmInstallFilesCommand.h"
@@ -67,42 +69,45 @@
#include "cmSiteNameCommand.h"
#include "cmStringCommand.h"
#include "cmSubdirCommand.h"
+#include "cmTargetCompileDefinitionsCommand.h"
+#include "cmTargetCompileFeaturesCommand.h"
+#include "cmTargetCompileOptionsCommand.h"
+#include "cmTargetIncludeDirectoriesCommand.h"
#include "cmTargetLinkLibrariesCommand.h"
+#include "cmTargetSourcesCommand.h"
#include "cmTryCompileCommand.h"
#include "cmTryRunCommand.h"
#include "cmUnsetCommand.h"
#include "cmWhileCommand.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmAddCompileOptionsCommand.h"
-#include "cmAuxSourceDirectoryCommand.h"
-#include "cmBuildNameCommand.h"
-#include "cmCMakeHostSystemInformationCommand.h"
-#include "cmExportCommand.h"
-#include "cmExportLibraryDependenciesCommand.h"
-#include "cmFLTKWrapUICommand.h"
-#include "cmIncludeExternalMSProjectCommand.h"
-#include "cmInstallProgramsCommand.h"
-#include "cmLinkLibrariesCommand.h"
-#include "cmLoadCacheCommand.h"
-#include "cmLoadCommandCommand.h"
-#include "cmOutputRequiredFilesCommand.h"
-#include "cmQTWrapCPPCommand.h"
-#include "cmQTWrapUICommand.h"
-#include "cmRemoveCommand.h"
-#include "cmRemoveDefinitionsCommand.h"
-#include "cmSourceGroupCommand.h"
-#include "cmSubdirDependsCommand.h"
-#include "cmTargetCompileDefinitionsCommand.h"
-#include "cmTargetCompileFeaturesCommand.h"
-#include "cmTargetCompileOptionsCommand.h"
-#include "cmTargetIncludeDirectoriesCommand.h"
-#include "cmTargetSourcesCommand.h"
-#include "cmUseMangledMesaCommand.h"
-#include "cmUtilitySourceCommand.h"
-#include "cmVariableRequiresCommand.h"
-#include "cmVariableWatchCommand.h"
-#include "cmWriteFileCommand.h"
+# include "cmAddCompileOptionsCommand.h"
+# include "cmAddLinkOptionsCommand.h"
+# include "cmAuxSourceDirectoryCommand.h"
+# include "cmBuildNameCommand.h"
+# include "cmCMakeHostSystemInformationCommand.h"
+# include "cmExportCommand.h"
+# include "cmExportLibraryDependenciesCommand.h"
+# include "cmFLTKWrapUICommand.h"
+# include "cmIncludeExternalMSProjectCommand.h"
+# include "cmInstallProgramsCommand.h"
+# include "cmLinkLibrariesCommand.h"
+# include "cmLoadCacheCommand.h"
+# include "cmLoadCommandCommand.h"
+# include "cmOutputRequiredFilesCommand.h"
+# include "cmQTWrapCPPCommand.h"
+# include "cmQTWrapUICommand.h"
+# include "cmRemoveCommand.h"
+# include "cmRemoveDefinitionsCommand.h"
+# include "cmSourceGroupCommand.h"
+# include "cmSubdirDependsCommand.h"
+# include "cmTargetLinkDirectoriesCommand.h"
+# include "cmTargetLinkOptionsCommand.h"
+# include "cmUseMangledMesaCommand.h"
+# include "cmUtilitySourceCommand.h"
+# include "cmVariableRequiresCommand.h"
+# include "cmVariableWatchCommand.h"
+# include "cmWriteFileCommand.h"
#endif
void GetScriptingCommands(cmState* state)
@@ -132,6 +137,7 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("get_property", new cmGetPropertyCommand);
state->AddBuiltinCommand("if", new cmIfCommand);
state->AddBuiltinCommand("include", new cmIncludeCommand);
+ state->AddBuiltinCommand("include_guard", new cmIncludeGuardCommand);
state->AddBuiltinCommand("list", new cmListCommand);
state->AddBuiltinCommand("macro", new cmMacroCommand);
state->AddBuiltinCommand("make_directory", new cmMakeDirectoryCommand);
@@ -154,32 +160,39 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("while", new cmWhileCommand);
state->AddUnexpectedCommand(
- "else", "An ELSE command was found outside of a proper "
- "IF ENDIF structure. Or its arguments did not match "
- "the opening IF command.");
+ "else",
+ "An ELSE command was found outside of a proper "
+ "IF ENDIF structure. Or its arguments did not match "
+ "the opening IF command.");
state->AddUnexpectedCommand(
- "elseif", "An ELSEIF command was found outside of a proper "
- "IF ENDIF structure.");
+ "elseif",
+ "An ELSEIF command was found outside of a proper "
+ "IF ENDIF structure.");
state->AddUnexpectedCommand(
- "endforeach", "An ENDFOREACH command was found outside of a proper "
- "FOREACH ENDFOREACH structure. Or its arguments did "
- "not match the opening FOREACH command.");
+ "endforeach",
+ "An ENDFOREACH command was found outside of a proper "
+ "FOREACH ENDFOREACH structure. Or its arguments did "
+ "not match the opening FOREACH command.");
state->AddUnexpectedCommand(
- "endfunction", "An ENDFUNCTION command was found outside of a proper "
- "FUNCTION ENDFUNCTION structure. Or its arguments did not "
- "match the opening FUNCTION command.");
+ "endfunction",
+ "An ENDFUNCTION command was found outside of a proper "
+ "FUNCTION ENDFUNCTION structure. Or its arguments did not "
+ "match the opening FUNCTION command.");
state->AddUnexpectedCommand(
- "endif", "An ENDIF command was found outside of a proper "
- "IF ENDIF structure. Or its arguments did not match "
- "the opening IF command.");
+ "endif",
+ "An ENDIF command was found outside of a proper "
+ "IF ENDIF structure. Or its arguments did not match "
+ "the opening IF command.");
state->AddUnexpectedCommand(
- "endmacro", "An ENDMACRO command was found outside of a proper "
- "MACRO ENDMACRO structure. Or its arguments did not "
- "match the opening MACRO command.");
+ "endmacro",
+ "An ENDMACRO command was found outside of a proper "
+ "MACRO ENDMACRO structure. Or its arguments did not "
+ "match the opening MACRO command.");
state->AddUnexpectedCommand(
- "endwhile", "An ENDWHILE command was found outside of a proper "
- "WHILE ENDWHILE structure. Or its arguments did not "
- "match the opening WHILE command.");
+ "endwhile",
+ "An ENDWHILE command was found outside of a proper "
+ "WHILE ENDWHILE structure. Or its arguments did not "
+ "match the opening WHILE command.");
#if defined(CMAKE_BUILD_WITH_CMAKE)
state->AddBuiltinCommand("cmake_host_system_information",
@@ -236,12 +249,23 @@ void GetProjectCommands(cmState* state)
state->AddBuiltinCommand("set_tests_properties",
new cmSetTestsPropertiesCommand);
state->AddBuiltinCommand("subdirs", new cmSubdirCommand);
+ state->AddBuiltinCommand("target_compile_definitions",
+ new cmTargetCompileDefinitionsCommand);
+ state->AddBuiltinCommand("target_compile_features",
+ new cmTargetCompileFeaturesCommand);
+ state->AddBuiltinCommand("target_compile_options",
+ new cmTargetCompileOptionsCommand);
+ state->AddBuiltinCommand("target_include_directories",
+ new cmTargetIncludeDirectoriesCommand);
state->AddBuiltinCommand("target_link_libraries",
new cmTargetLinkLibrariesCommand);
+ state->AddBuiltinCommand("target_sources", new cmTargetSourcesCommand);
state->AddBuiltinCommand("try_compile", new cmTryCompileCommand);
state->AddBuiltinCommand("try_run", new cmTryRunCommand);
#if defined(CMAKE_BUILD_WITH_CMAKE)
+ state->AddBuiltinCommand("add_compile_definitions",
+ new cmAddCompileDefinitionsCommand);
state->AddBuiltinCommand("add_compile_options",
new cmAddCompileOptionsCommand);
state->AddBuiltinCommand("aux_source_directory",
@@ -251,22 +275,18 @@ void GetProjectCommands(cmState* state)
state->AddBuiltinCommand("include_external_msproject",
new cmIncludeExternalMSProjectCommand);
state->AddBuiltinCommand("install_programs", new cmInstallProgramsCommand);
+ state->AddBuiltinCommand("add_link_options", new cmAddLinkOptionsCommand);
state->AddBuiltinCommand("link_libraries", new cmLinkLibrariesCommand);
+ state->AddBuiltinCommand("target_link_options",
+ new cmTargetLinkOptionsCommand);
+ state->AddBuiltinCommand("target_link_directories",
+ new cmTargetLinkDirectoriesCommand);
state->AddBuiltinCommand("load_cache", new cmLoadCacheCommand);
state->AddBuiltinCommand("qt_wrap_cpp", new cmQTWrapCPPCommand);
state->AddBuiltinCommand("qt_wrap_ui", new cmQTWrapUICommand);
state->AddBuiltinCommand("remove_definitions",
new cmRemoveDefinitionsCommand);
state->AddBuiltinCommand("source_group", new cmSourceGroupCommand);
- state->AddBuiltinCommand("target_compile_definitions",
- new cmTargetCompileDefinitionsCommand);
- state->AddBuiltinCommand("target_compile_features",
- new cmTargetCompileFeaturesCommand);
- state->AddBuiltinCommand("target_compile_options",
- new cmTargetCompileOptionsCommand);
- state->AddBuiltinCommand("target_include_directories",
- new cmTargetIncludeDirectoriesCommand);
- state->AddBuiltinCommand("target_sources", new cmTargetSourcesCommand);
state->AddDisallowedCommand(
"export_library_dependencies", new cmExportLibraryDependenciesCommand,
@@ -341,7 +361,7 @@ void GetProjectCommandsInScriptMode(cmState* state)
CM_UNEXPECTED_PROJECT_COMMAND("try_compile");
CM_UNEXPECTED_PROJECT_COMMAND("try_run");
- // deprected commands
+ // deprecated commands
CM_UNEXPECTED_PROJECT_COMMAND("export_library_dependencies");
CM_UNEXPECTED_PROJECT_COMMAND("load_command");
CM_UNEXPECTED_PROJECT_COMMAND("output_required_files");
diff --git a/Source/cmCommonTargetGenerator.cxx b/Source/cmCommonTargetGenerator.cxx
index 391d65c40..66250f329 100644
--- a/Source/cmCommonTargetGenerator.cxx
+++ b/Source/cmCommonTargetGenerator.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCommonTargetGenerator.h"
-#include "cmConfigure.h"
#include <set>
#include <sstream>
#include <utility>
@@ -22,16 +21,15 @@
cmCommonTargetGenerator::cmCommonTargetGenerator(cmGeneratorTarget* gt)
: GeneratorTarget(gt)
, Makefile(gt->Makefile)
- , LocalGenerator(static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
- , GlobalGenerator(static_cast<cmGlobalCommonGenerator*>(
+ , LocalCommonGenerator(
+ static_cast<cmLocalCommonGenerator*>(gt->LocalGenerator))
+ , GlobalCommonGenerator(static_cast<cmGlobalCommonGenerator*>(
gt->LocalGenerator->GetGlobalGenerator()))
- , ConfigName(LocalGenerator->GetConfigName())
+ , ConfigName(LocalCommonGenerator->GetConfigName())
{
}
-cmCommonTargetGenerator::~cmCommonTargetGenerator()
-{
-}
+cmCommonTargetGenerator::~cmCommonTargetGenerator() = default;
std::string const& cmCommonTargetGenerator::GetConfigName() const
{
@@ -62,10 +60,10 @@ void cmCommonTargetGenerator::AddModuleDefinitionFlag(
// 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->ConvertToOutputFormat(
+ flag += this->LocalCommonGenerator->ConvertToOutputFormat(
linkLineComputer->ConvertToLinkReference(mdi->DefFile),
cmOutputConverter::SHELL);
- this->LocalGenerator->AppendFlags(flags, flag);
+ this->LocalCommonGenerator->AppendFlags(flags, flag);
}
void cmCommonTargetGenerator::AppendFortranFormatFlags(
@@ -78,7 +76,7 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags(
const char* tgtfmt = this->GeneratorTarget->GetProperty("Fortran_FORMAT");
format = cmOutputConverter::GetFortranFormat(tgtfmt);
}
- const char* var = CM_NULLPTR;
+ const char* var = nullptr;
switch (format) {
case cmOutputConverter::FortranFormatFixed:
var = "CMAKE_Fortran_FORMAT_FIXED_FLAG";
@@ -90,8 +88,8 @@ void cmCommonTargetGenerator::AppendFortranFormatFlags(
break;
}
if (var) {
- this->LocalGenerator->AppendFlags(flags,
- this->Makefile->GetDefinition(var));
+ this->LocalCommonGenerator->AppendFlags(
+ flags, this->Makefile->GetDefinition(var));
}
}
@@ -101,8 +99,8 @@ std::string cmCommonTargetGenerator::GetFlags(const std::string& l)
if (i == this->FlagsByLanguage.end()) {
std::string flags;
- this->LocalGenerator->GetTargetCompileFlags(this->GeneratorTarget,
- this->ConfigName, l, flags);
+ this->LocalCommonGenerator->GetTargetCompileFlags(
+ this->GeneratorTarget, this->ConfigName, l, flags);
ByLanguageMap::value_type entry(l, flags);
i = this->FlagsByLanguage.insert(entry).first;
@@ -115,11 +113,11 @@ std::string cmCommonTargetGenerator::GetDefines(const std::string& l)
ByLanguageMap::iterator i = this->DefinesByLanguage.find(l);
if (i == this->DefinesByLanguage.end()) {
std::set<std::string> defines;
- this->LocalGenerator->GetTargetDefines(this->GeneratorTarget,
- this->ConfigName, l, defines);
+ this->LocalCommonGenerator->GetTargetDefines(this->GeneratorTarget,
+ this->ConfigName, l, defines);
std::string definesString;
- this->LocalGenerator->JoinDefines(defines, definesString, l);
+ this->LocalCommonGenerator->JoinDefines(defines, definesString, l);
ByLanguageMap::value_type entry(l, definesString);
i = this->DefinesByLanguage.insert(entry).first;
@@ -147,11 +145,10 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories()
if (cmComputeLinkInformation* cli =
this->GeneratorTarget->GetLinkInformation(this->ConfigName)) {
cmComputeLinkInformation::ItemVector const& items = cli->GetItems();
- for (cmComputeLinkInformation::ItemVector::const_iterator i =
- items.begin();
- i != items.end(); ++i) {
- cmGeneratorTarget const* linkee = i->Target;
- if (linkee && !linkee->IsImported()
+ for (auto const& item : items) {
+ cmGeneratorTarget const* linkee = item.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.
@@ -161,7 +158,7 @@ std::vector<std::string> cmCommonTargetGenerator::GetLinkedTargetDirectories()
std::string di = lg->GetCurrentBinaryDirectory();
di += "/";
di += lg->GetTargetDirectory(linkee);
- dirs.push_back(di);
+ dirs.push_back(std::move(di));
}
}
}
@@ -196,11 +193,12 @@ std::string cmCommonTargetGenerator::GetManifests()
this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
std::vector<std::string> manifests;
- for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
- mi != manifest_srcs.end(); ++mi) {
- manifests.push_back(this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->ConvertToRelativePath(
- this->LocalGenerator->GetWorkingDirectory(), (*mi)->GetFullPath()),
+ manifests.reserve(manifest_srcs.size());
+ for (cmSourceFile const* manifest_src : manifest_srcs) {
+ manifests.push_back(this->LocalCommonGenerator->ConvertToOutputFormat(
+ this->LocalCommonGenerator->MaybeConvertToRelativePath(
+ this->LocalCommonGenerator->GetWorkingDirectory(),
+ manifest_src->GetFullPath()),
cmOutputConverter::SHELL));
}
@@ -233,6 +231,6 @@ void cmCommonTargetGenerator::AppendOSXVerFlag(std::string& flags,
// Append the flag since a non-zero version is specified.
std::ostringstream vflag;
vflag << flag << major << "." << minor << "." << patch;
- this->LocalGenerator->AppendFlags(flags, vflag.str());
+ this->LocalCommonGenerator->AppendFlags(flags, vflag.str());
}
}
diff --git a/Source/cmCommonTargetGenerator.h b/Source/cmCommonTargetGenerator.h
index c36145fe2..6b0f74efd 100644
--- a/Source/cmCommonTargetGenerator.h
+++ b/Source/cmCommonTargetGenerator.h
@@ -37,8 +37,8 @@ protected:
cmGeneratorTarget* GeneratorTarget;
cmMakefile* Makefile;
- cmLocalCommonGenerator* LocalGenerator;
- cmGlobalCommonGenerator* GlobalGenerator;
+ cmLocalCommonGenerator* LocalCommonGenerator;
+ cmGlobalCommonGenerator* GlobalCommonGenerator;
std::string ConfigName;
void AppendFortranFormatFlags(std::string& flags,
diff --git a/Source/cmComputeComponentGraph.cxx b/Source/cmComputeComponentGraph.cxx
index a02d8854b..113463f63 100644
--- a/Source/cmComputeComponentGraph.cxx
+++ b/Source/cmComputeComponentGraph.cxx
@@ -18,9 +18,7 @@ cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input)
this->TransferEdges();
}
-cmComputeComponentGraph::~cmComputeComponentGraph()
-{
-}
+cmComputeComponentGraph::~cmComputeComponentGraph() = default;
void cmComputeComponentGraph::Tarjan()
{
@@ -57,8 +55,8 @@ void cmComputeComponentGraph::TarjanVisit(int i)
// Follow outgoing edges.
EdgeList const& nl = this->InputGraph[i];
- for (EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni) {
- int j = *ni;
+ for (cmGraphEdge const& ni : nl) {
+ 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
@@ -88,7 +86,7 @@ void cmComputeComponentGraph::TarjanVisit(int i)
if (this->TarjanEntries[i].Root == i) {
// Yes. Create it.
int c = static_cast<int>(this->Components.size());
- this->Components.push_back(NodeList());
+ this->Components.emplace_back();
NodeList& component = this->Components[c];
// Populate the component list.
@@ -119,14 +117,14 @@ void cmComputeComponentGraph::TransferEdges()
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;
+ for (cmGraphEdge const& ni : nl) {
+ 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()));
+ this->ComponentGraph[i_component].emplace_back(
+ j_component, ni.IsStrong(), ni.GetBacktrace());
}
}
}
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 9c516ee8d..186deb60c 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -6,8 +6,10 @@
#include "cmComputeComponentGraph.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
+#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
@@ -194,7 +196,7 @@ cmComputeLinkDepends::cmComputeLinkDepends(const cmGeneratorTarget* target,
this->OldLinkDirMode = false;
// No computation has been done.
- this->CCG = CM_NULLPTR;
+ this->CCG = nullptr;
}
cmComputeLinkDepends::~cmComputeLinkDepends()
@@ -239,8 +241,9 @@ cmComputeLinkDepends::Compute()
// Display the constraint graph.
if (this->DebugMode) {
- fprintf(stderr, "---------------------------------------"
- "---------------------------------------\n");
+ 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");
@@ -254,11 +257,7 @@ cmComputeLinkDepends::Compute()
// Iterate in reverse order so we can keep only the last occurrence
// of a shared library.
std::set<int> emmitted;
- for (std::vector<int>::const_reverse_iterator
- li = this->FinalLinkOrder.rbegin(),
- le = this->FinalLinkOrder.rend();
- li != le; ++li) {
- int i = *li;
+ for (int i : cmReverseRange(this->FinalLinkOrder)) {
LinkEntry const& e = this->EntryList[i];
cmGeneratorTarget const* t = e.Target;
// Entries that we know the linker will re-use do not need to be repeated.
@@ -278,23 +277,23 @@ cmComputeLinkDepends::Compute()
return this->FinalLinkEntries;
}
-std::map<std::string, int>::iterator cmComputeLinkDepends::AllocateLinkEntry(
- std::string const& item)
+std::map<cmLinkItem, int>::iterator cmComputeLinkDepends::AllocateLinkEntry(
+ cmLinkItem const& item)
{
- std::map<std::string, int>::value_type index_entry(
+ std::map<cmLinkItem, int>::value_type index_entry(
item, static_cast<int>(this->EntryList.size()));
- std::map<std::string, int>::iterator lei =
+ std::map<cmLinkItem, int>::iterator lei =
this->LinkEntryIndex.insert(index_entry).first;
- this->EntryList.push_back(LinkEntry());
- this->InferredDependSets.push_back(CM_NULLPTR);
- this->EntryConstraintGraph.push_back(EdgeList());
+ this->EntryList.emplace_back();
+ this->InferredDependSets.push_back(nullptr);
+ this->EntryConstraintGraph.emplace_back();
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);
+ std::map<cmLinkItem, 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;
@@ -306,15 +305,16 @@ int cmComputeLinkDepends::AddLinkEntry(cmLinkItem const& item)
// Initialize the item entry.
int index = lei->second;
LinkEntry& entry = this->EntryList[index];
- entry.Item = item;
+ entry.Item = item.AsStr();
entry.Target = item.Target;
- entry.IsFlag = (!entry.Target && item[0] == '-' && item[1] != 'l' &&
- item.substr(0, 10) != "-framework");
+ entry.IsFlag =
+ (!entry.Target && entry.Item[0] == '-' && entry.Item[1] != 'l' &&
+ entry.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, CM_NULLPTR };
+ BFSEntry qe = { index, nullptr };
this->BFSQueue.push(qe);
} else {
// Look for an old-style <item>_LIB_DEPENDS variable.
@@ -357,10 +357,8 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry qe)
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);
+ for (cmLinkItem const& oi : iface->WrongConfigLibraries) {
+ this->CheckWrongConfigItem(oi);
}
}
} else {
@@ -385,10 +383,9 @@ void cmComputeLinkDepends::FollowSharedDeps(int depender_index,
void cmComputeLinkDepends::QueueSharedDependencies(
int depender_index, std::vector<cmLinkItem> const& deps)
{
- for (std::vector<cmLinkItem>::const_iterator li = deps.begin();
- li != deps.end(); ++li) {
+ for (cmLinkItem const& li : deps) {
SharedDepEntry qe;
- qe.Item = *li;
+ qe.Item = li;
qe.DependerIndex = depender_index;
this->SharedDepQueue.push(qe);
}
@@ -397,7 +394,7 @@ void cmComputeLinkDepends::QueueSharedDependencies(
void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
{
// Check if the target already has an entry.
- std::map<std::string, int>::iterator lei =
+ std::map<cmLinkItem, int>::iterator lei =
this->LinkEntryIndex.find(dep.Item);
if (lei == this->LinkEntryIndex.end()) {
// Allocate a spot for the item entry.
@@ -405,7 +402,7 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
// Initialize the item entry.
LinkEntry& entry = this->EntryList[lei->second];
- entry.Item = dep.Item;
+ entry.Item = dep.Item.AsStr();
entry.Target = dep.Item.Target;
// This item was added specifically because it is a dependent
@@ -420,7 +417,8 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
// This shared library dependency must follow the item that listed
// it.
- this->EntryConstraintGraph[dep.DependerIndex].push_back(index);
+ this->EntryConstraintGraph[dep.DependerIndex].emplace_back(
+ index, true, cmListFileBacktrace());
// Target items may have their own dependencies.
if (entry.Target) {
@@ -445,25 +443,24 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index,
std::vector<cmLinkItem> actual_libs;
cmTargetLinkLibraryType llt = GENERAL_LibraryType;
bool haveLLT = false;
- for (std::vector<std::string>::const_iterator di = deplist.begin();
- di != deplist.end(); ++di) {
- if (*di == "debug") {
+ for (std::string const& d : deplist) {
+ if (d == "debug") {
llt = DEBUG_LibraryType;
haveLLT = true;
- } else if (*di == "optimized") {
+ } else if (d == "optimized") {
llt = OPTIMIZED_LibraryType;
haveLLT = true;
- } else if (*di == "general") {
+ } else if (d == "general") {
llt = GENERAL_LibraryType;
haveLLT = true;
- } else if (!di->empty()) {
+ } else if (!d.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;
+ std::string var = d;
var += "_LINK_TYPE";
if (const char* val = this->Makefile->GetDefinition(var)) {
if (strcmp(val, "debug") == 0) {
@@ -476,10 +473,9 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index,
// If the library is meant for this link type then use it.
if (llt == GENERAL_LibraryType || llt == this->LinkType) {
- cmLinkItem item(*di, this->FindTargetToLink(depender_index, *di));
- actual_libs.push_back(item);
+ actual_libs.emplace_back(this->ResolveLinkItem(depender_index, d));
} else if (this->OldLinkDirMode) {
- cmLinkItem item(*di, this->FindTargetToLink(depender_index, *di));
+ cmLinkItem item = this->ResolveLinkItem(depender_index, d);
this->CheckWrongConfigItem(item);
}
@@ -499,10 +495,8 @@ void cmComputeLinkDepends::AddDirectLinkEntries()
cmLinkImplementation 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);
+ for (cmLinkItem const& wi : impl->WrongConfigLibraries) {
+ this->CheckWrongConfigItem(wi);
}
}
@@ -514,37 +508,36 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_index,
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) {
+ for (T const& l : libs) {
// Skip entries that will resolve to the target getting linked or
// are empty.
- cmLinkItem const& item = *li;
- if (item == this->Target->GetName() || item.empty()) {
+ cmLinkItem const& item = l;
+ if (item.AsStr() == this->Target->GetName() || item.AsStr().empty()) {
continue;
}
// Add a link entry for this item.
- int dependee_index = this->AddLinkEntry(*li);
+ int dependee_index = this->AddLinkEntry(l);
// The dependee must come after the depender.
if (depender_index >= 0) {
- this->EntryConstraintGraph[depender_index].push_back(dependee_index);
+ this->EntryConstraintGraph[depender_index].emplace_back(
+ dependee_index, false, cmListFileBacktrace());
} 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) {
+ for (auto& dependSet : dependSets) {
// 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);
+ dependee_index != dependSet.first) {
+ dependSet.second.insert(dependee_index);
}
}
@@ -556,14 +549,13 @@ void cmComputeLinkDepends::AddLinkEntries(int depender_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);
+ for (auto const& dependSet : dependSets) {
+ this->InferredDependSets[dependSet.first]->push_back(dependSet.second);
}
}
-cmGeneratorTarget const* cmComputeLinkDepends::FindTargetToLink(
- int depender_index, const std::string& name)
+cmLinkItem cmComputeLinkDepends::ResolveLinkItem(int depender_index,
+ const std::string& name)
{
// Look for a target in the scope of the depender.
cmGeneratorTarget const* from = this->Target;
@@ -573,7 +565,7 @@ cmGeneratorTarget const* cmComputeLinkDepends::FindTargetToLink(
from = depender;
}
}
- return from->FindTargetToLink(name);
+ return from->ResolveLinkItem(name, cmListFileBacktrace());
}
void cmComputeLinkDepends::InferDependencies()
@@ -591,31 +583,33 @@ void cmComputeLinkDepends::InferDependencies()
}
// Intersect the sets for this item.
- DependSetList::const_iterator i = sets->begin();
- DependSet common = *i;
- for (++i; i != sets->end(); ++i) {
+ DependSet common = sets->front();
+ for (DependSet const& i : cmMakeRange(*sets).advance(1)) {
DependSet intersection;
- std::set_intersection(common.begin(), common.end(), i->begin(), i->end(),
+ std::set_intersection(common.begin(), common.end(), i.begin(), i.end(),
std::inserter(intersection, intersection.begin()));
common = intersection;
}
// Add the inferred dependencies to the graph.
cmGraphEdgeList& edges = this->EntryConstraintGraph[depender_index];
- edges.insert(edges.end(), common.begin(), common.end());
+ edges.reserve(edges.size() + common.size());
+ for (auto const& c : common) {
+ edges.emplace_back(c, true, cmListFileBacktrace());
+ }
}
}
void cmComputeLinkDepends::CleanConstraintGraph()
{
- for (Graph::iterator i = this->EntryConstraintGraph.begin();
- i != this->EntryConstraintGraph.end(); ++i) {
+ for (cmGraphEdgeList& edgeList : this->EntryConstraintGraph) {
// 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());
+ std::sort(edgeList.begin(), edgeList.end());
// Make the edge list unique.
- i->erase(std::unique(i->begin(), i->end()), i->end());
+ edgeList.erase(std::unique(edgeList.begin(), edgeList.end()),
+ edgeList.end());
}
}
@@ -660,9 +654,8 @@ void cmComputeLinkDepends::OrderLinkEntires()
}
// Start with the original link line.
- for (std::vector<int>::const_iterator i = this->OriginalEntries.begin();
- i != this->OriginalEntries.end(); ++i) {
- this->VisitEntry(*i);
+ for (int originalEntry : this->OriginalEntries) {
+ this->VisitEntry(originalEntry);
}
// Now explore anything left pending. Since the component graph is
@@ -684,13 +677,12 @@ void cmComputeLinkDepends::DisplayComponents()
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;
+ for (int i : nl) {
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;
+ for (cmGraphEdge const& oi : ol) {
+ int i = oi;
fprintf(stderr, " followed by Component (%d)\n", i);
}
fprintf(stderr, " topo order index %d\n", this->ComponentOrder[c]);
@@ -712,9 +704,8 @@ void cmComputeLinkDepends::VisitComponent(unsigned int c)
// 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);
+ for (cmGraphEdge const& edge : cmReverseRange(nl)) {
+ this->VisitComponent(edge);
}
// Assign an ordering id to this component.
@@ -771,10 +762,10 @@ void cmComputeLinkDepends::VisitEntry(int index)
// are now pending.
if (completed) {
EdgeList const& ol = this->CCG->GetComponentGraphEdges(component);
- for (EdgeList::const_iterator oi = ol.begin(); oi != ol.end(); ++oi) {
+ for (cmGraphEdge const& oi : ol) {
// This entire component is now pending no matter whether it has
// been partially seen already.
- this->MakePendingComponent(*oi);
+ this->MakePendingComponent(oi);
}
}
}
@@ -816,8 +807,8 @@ cmComputeLinkDepends::MakePendingComponent(unsigned int component)
int cmComputeLinkDepends::ComputeComponentCount(NodeList const& nl)
{
unsigned int count = 2;
- for (NodeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni) {
- if (cmGeneratorTarget const* target = this->EntryList[*ni].Target) {
+ for (int ni : nl) {
+ if (cmGeneratorTarget const* target = this->EntryList[ni].Target) {
if (cmLinkInterface const* iface =
target->GetLinkInterface(this->Config, this->Target)) {
if (iface->Multiplicity > count) {
@@ -832,13 +823,11 @@ int cmComputeLinkDepends::ComputeComponentCount(NodeList const& nl)
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());
+ for (LinkEntry const& lei : this->FinalLinkEntries) {
+ 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, " item [%s]\n", lei.Item.c_str());
}
}
fprintf(stderr, "\n");
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
index 84ee9161f..dfaaf8b96 100644
--- a/Source/cmComputeLinkDepends.h
+++ b/Source/cmComputeLinkDepends.h
@@ -31,27 +31,16 @@ public:
const std::string& config);
~cmComputeLinkDepends();
+ cmComputeLinkDepends(const cmComputeLinkDepends&) = delete;
+ cmComputeLinkDepends& operator=(const cmComputeLinkDepends&) = delete;
+
// Basic information about each link item.
struct LinkEntry
{
std::string Item;
- cmGeneratorTarget const* Target;
- bool IsSharedDep;
- bool IsFlag;
- LinkEntry()
- : Item()
- , Target(CM_NULLPTR)
- , IsSharedDep(false)
- , IsFlag(false)
- {
- }
- LinkEntry(LinkEntry const& r)
- : Item(r.Item)
- , Target(r.Target)
- , IsSharedDep(r.IsSharedDep)
- , IsFlag(r.IsFlag)
- {
- }
+ cmGeneratorTarget const* Target = nullptr;
+ bool IsSharedDep = false;
+ bool IsFlag = false;
};
typedef std::vector<LinkEntry> EntryVector;
@@ -72,19 +61,18 @@ private:
std::string Config;
EntryVector FinalLinkEntries;
- std::map<std::string, int>::iterator AllocateLinkEntry(
- std::string const& item);
+ std::map<cmLinkItem, int>::iterator AllocateLinkEntry(
+ cmLinkItem 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);
- cmGeneratorTarget const* FindTargetToLink(int depender_index,
- const std::string& name);
+ cmLinkItem ResolveLinkItem(int depender_index, const std::string& name);
// One entry for each unique item.
std::vector<LinkEntry> EntryList;
- std::map<std::string, int> LinkEntryIndex;
+ std::map<cmLinkItem, int> LinkEntryIndex;
// BFS of initial dependencies.
struct BFSEntry
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index b2deaaa85..44d8615e0 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -8,6 +8,7 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmOrderDirectories.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
@@ -30,7 +31,7 @@ Notes about linking on various platforms:
------------------------------------------------------------------------------
-Linux, FreeBSD, Mac OS X, IRIX, Sun, Windows:
+Linux, FreeBSD, macOS, Sun, Windows:
Linking to libraries using the full path works fine.
@@ -240,27 +241,24 @@ because this need be done only for shared libraries without soname-s.
cmComputeLinkInformation::cmComputeLinkInformation(
const cmGeneratorTarget* target, const std::string& config)
-{
// Store context information.
- this->Target = target;
- this->Makefile = this->Target->Target->GetMakefile();
- this->GlobalGenerator =
- this->Target->GetLocalGenerator()->GetGlobalGenerator();
- this->CMakeInstance = this->GlobalGenerator->GetCMakeInstance();
-
+ : Target(target)
+ , Makefile(target->Target->GetMakefile())
+ , GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator())
+ , CMakeInstance(this->GlobalGenerator->GetCMakeInstance())
+ // The configuration being linked.
+ , Config(config)
+{
// Check whether to recognize OpenBSD-style library versioned names.
this->OpenBSD = this->Makefile->GetState()->GetGlobalPropertyAsBool(
"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 = CM_NULLPTR;
+ this->OrderDependentRPath = nullptr;
// Get the language used for linking this target.
this->LinkLanguage = this->Target->GetLinkerLanguage(config);
@@ -281,7 +279,7 @@ cmComputeLinkInformation::cmComputeLinkInformation(
// 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 = CM_NULLPTR;
+ this->LoaderFlag = nullptr;
if (!this->UseImportLibrary &&
this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) {
std::string loader_flag_var = "CMAKE_SHARED_MODULE_LOADER_";
@@ -360,10 +358,10 @@ cmComputeLinkInformation::cmComputeLinkInformation(
}
// Add the search path entries requested by the user to path ordering.
- this->OrderLinkerSearchPath->AddUserDirectories(
- this->Target->GetLinkDirectories());
- this->OrderRuntimeSearchPath->AddUserDirectories(
- this->Target->GetLinkDirectories());
+ std::vector<std::string> directories;
+ this->Target->GetLinkDirectories(directories, config, this->LinkLanguage);
+ this->OrderLinkerSearchPath->AddUserDirectories(directories);
+ this->OrderRuntimeSearchPath->AddUserDirectories(directories);
// Set up the implicit link directories.
this->LoadImplicitLinkInfo();
@@ -390,8 +388,7 @@ cmComputeLinkInformation::cmComputeLinkInformation(
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();
- this->OldLinkDirMask.insert(dirs.begin(), dirs.end());
+ this->OldLinkDirMask.insert(directories.begin(), directories.end());
}
this->CMP0060Warn = this->Makefile->PolicyOptionalWarningEnabled(
@@ -406,17 +403,18 @@ cmComputeLinkInformation::~cmComputeLinkInformation()
}
cmComputeLinkInformation::ItemVector const&
-cmComputeLinkInformation::GetItems()
+cmComputeLinkInformation::GetItems() const
{
return this->Items;
}
std::vector<std::string> const& cmComputeLinkInformation::GetDirectories()
+ const
{
return this->OrderLinkerSearchPath->GetOrderedDirectories();
}
-std::string cmComputeLinkInformation::GetRPathLinkString()
+std::string cmComputeLinkInformation::GetRPathLinkString() const
{
// If there is no separate linker runtime search flag (-rpath-link)
// there is no reason to compute a string.
@@ -424,22 +422,24 @@ std::string cmComputeLinkInformation::GetRPathLinkString()
return "";
}
- // Construct the linker runtime search path.
+ // Construct the linker runtime search path. These MUST NOT contain tokens
+ // such as $ORIGIN, see https://sourceware.org/bugzilla/show_bug.cgi?id=16936
return cmJoin(this->OrderDependentRPath->GetOrderedDirectories(), ":");
}
-std::vector<std::string> const& cmComputeLinkInformation::GetDepends()
+std::vector<std::string> const& cmComputeLinkInformation::GetDepends() const
{
return this->Depends;
}
std::vector<std::string> const& cmComputeLinkInformation::GetFrameworkPaths()
+ const
{
return this->FrameworkPaths;
}
const std::set<const cmGeneratorTarget*>&
-cmComputeLinkInformation::GetSharedLibrariesLinked()
+cmComputeLinkInformation::GetSharedLibrariesLinked() const
{
return this->SharedLibrariesLinked;
}
@@ -457,8 +457,8 @@ bool cmComputeLinkInformation::Compute()
// 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());
+ "CMake can not determine linker language for target: " +
+ this->Target->GetName());
return false;
}
@@ -468,13 +468,11 @@ bool cmComputeLinkInformation::Compute()
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);
+ for (cmComputeLinkDepends::LinkEntry const& linkEntry : linkEntries) {
+ if (linkEntry.IsSharedDep) {
+ this->AddSharedDepItem(linkEntry.Item, linkEntry.Target);
} else {
- this->AddItem(lei->Item, lei->Target);
+ this->AddItem(linkEntry.Item, linkEntry.Target);
}
}
@@ -494,17 +492,14 @@ bool cmComputeLinkInformation::Compute()
// directories.
std::set<cmGeneratorTarget const*> const& wrongItems =
cld.GetOldWrongConfigItems();
- for (std::set<cmGeneratorTarget const*>::const_iterator i =
- wrongItems.begin();
- i != wrongItems.end(); ++i) {
- cmGeneratorTarget const* tgt = *i;
+ for (cmGeneratorTarget const* tgt : wrongItems) {
bool implib = (this->UseImportLibrary &&
(tgt->GetType() == cmStateEnums::SHARED_LIBRARY));
cmStateEnums::ArtifactType artifact = implib
? cmStateEnums::ImportLibraryArtifact
: cmStateEnums::RuntimeBinaryArtifact;
- std::string lib = tgt->GetFullPath(this->Config, artifact, true);
- this->OldLinkDirItems.push_back(lib);
+ this->OldLinkDirItems.push_back(
+ tgt->GetFullPath(this->Config, artifact, true));
}
}
@@ -528,7 +523,7 @@ bool cmComputeLinkInformation::Compute()
"name."
;
/* clang-format on */
- this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+ this->CMakeInstance->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
this->Target->GetBacktrace());
}
@@ -540,11 +535,10 @@ void cmComputeLinkInformation::AddImplicitLinkInfo()
// The link closure lists all languages whose implicit info is needed.
cmGeneratorTarget::LinkClosure const* lc =
this->Target->GetLinkClosure(this->Config);
- for (std::vector<std::string>::const_iterator li = lc->Languages.begin();
- li != lc->Languages.end(); ++li) {
+ for (std::string const& li : lc->Languages) {
// Skip those of the linker language. They are implicit.
- if (*li != this->LinkLanguage) {
- this->AddImplicitLinkInfo(*li);
+ if (li != this->LinkLanguage) {
+ this->AddImplicitLinkInfo(li);
}
}
}
@@ -559,10 +553,9 @@ void cmComputeLinkInformation::AddImplicitLinkInfo(std::string const& lang)
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, CM_NULLPTR);
+ for (std::string const& i : libsVec) {
+ if (this->ImplicitLinkLibs.find(i) == this->ImplicitLinkLibs.end()) {
+ this->AddItem(i, nullptr);
}
}
}
@@ -605,19 +598,22 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
std::string exe = tgt->GetFullPath(config, artifact, true);
linkItem += exe;
- this->Items.push_back(Item(linkItem, true, tgt));
- this->Depends.push_back(exe);
+ this->Items.emplace_back(linkItem, true, tgt);
+ this->Depends.push_back(std::move(exe));
} else if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
// Add the interface library as an item so it can be considered as part
// of COMPATIBLE_INTERFACE_ enforcement. The generators will ignore
// this for the actual link line.
- this->Items.push_back(Item(std::string(), false, tgt));
+ this->Items.emplace_back(std::string(), false, tgt);
// Also add the item the interface specifies to be used in its place.
std::string const& libName = tgt->GetImportedLibName(config);
if (!libName.empty()) {
- this->AddItem(libName, CM_NULLPTR);
+ this->AddItem(libName, nullptr);
}
+ } else if (tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) {
+ // Ignore object library!
+ // Its object-files should already have been extracted for linking.
} else {
// Decide whether to use an import library.
bool implib =
@@ -639,7 +635,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item,
}
} else {
// This is not a CMake target. Use the name given.
- if (cmSystemTools::FileIsFullPath(item.c_str())) {
+ if (cmSystemTools::FileIsFullPath(item)) {
if (cmSystemTools::FileIsDirectory(item)) {
// This is a directory.
this->AddDirectoryItem(item);
@@ -675,13 +671,13 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
} else {
// Skip items that are not full paths. We will not be able to
// reliably specify them.
- if (!cmSystemTools::FileIsFullPath(item.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(item)) {
return;
}
// Get the name of the library from the file name.
std::string file = cmSystemTools::GetFilenameName(item);
- if (!this->ExtractSharedLibraryName.find(file.c_str())) {
+ if (!this->ExtractSharedLibraryName.find(file)) {
// This is not the name of a shared library.
return;
}
@@ -710,7 +706,7 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
// Check if we need to include the dependent shared library in other
// path ordering.
- cmOrderDirectories* order = CM_NULLPTR;
+ cmOrderDirectories* order = nullptr;
if (this->SharedDependencyMode == SharedDepModeLibDir &&
!this->LinkWithRuntimePath /* AddLibraryRuntimeInfo adds it */) {
// Add the item to the linker search path.
@@ -722,7 +718,7 @@ void cmComputeLinkInformation::AddSharedDepItem(std::string const& item,
if (order) {
if (tgt) {
std::string soName = tgt->GetSOName(this->Config);
- const char* soname = soName.empty() ? CM_NULLPTR : soName.c_str();
+ const char* soname = soName.empty() ? nullptr : soName.c_str();
order->AddRuntimeLibrary(lib, soname);
} else {
order->AddRuntimeLibrary(lib);
@@ -741,9 +737,9 @@ void cmComputeLinkInformation::ComputeLinkTypeInfo()
this->LinkTypeEnabled = false;
// Lookup link type selection flags.
- const char* static_link_type_flag = CM_NULLPTR;
- const char* shared_link_type_flag = CM_NULLPTR;
- const char* target_type_str = CM_NULLPTR;
+ const char* static_link_type_flag = nullptr;
+ const char* shared_link_type_flag = nullptr;
+ const char* target_type_str = nullptr;
switch (this->Target->GetType()) {
case cmStateEnums::EXECUTABLE:
target_type_str = "EXE";
@@ -811,18 +807,16 @@ void cmComputeLinkInformation::ComputeItemParserInfo()
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);
+ for (std::string const& i : linkSuffixVec) {
+ 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);
+ for (std::string const& i : sharedSuffixVec) {
+ this->AddLinkExtension(i.c_str(), LinkShared);
}
}
@@ -840,9 +834,8 @@ void cmComputeLinkInformation::ComputeItemParserInfo()
// 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;
+ for (std::string const& p : this->LinkPrefixes) {
+ reg += p;
reg += "|";
}
reg += ")";
@@ -891,12 +884,12 @@ void cmComputeLinkInformation::AddLinkExtension(const char* e, LinkType type)
{
if (e && *e) {
if (type == LinkStatic) {
- this->StaticLinkExtensions.push_back(e);
+ this->StaticLinkExtensions.emplace_back(e);
}
if (type == LinkShared) {
- this->SharedLinkExtensions.push_back(e);
+ this->SharedLinkExtensions.emplace_back(e);
}
- this->LinkExtensions.push_back(e);
+ this->LinkExtensions.emplace_back(e);
}
}
@@ -906,8 +899,7 @@ std::string cmComputeLinkInformation::CreateExtensionRegex(
// 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) {
+ for (std::string const& i : exts) {
// Separate this choice from the previous one.
libext += sep;
sep = "|";
@@ -915,20 +907,18 @@ std::string cmComputeLinkInformation::CreateExtensionRegex(
// Store this extension choice with the "." escaped.
libext += "\\";
#if defined(_WIN32) && !defined(__CYGWIN__)
- libext += this->NoCaseExpression(i->c_str());
+ libext += this->NoCaseExpression(i.c_str());
#else
- libext += *i;
+ 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]+)?";
+ // Add an optional OpenBSD-style version or major.minor.version component.
+ if (this->OpenBSD || type == LinkShared) {
+ libext += "(\\.[0-9]+)*";
}
libext += "$";
@@ -963,10 +953,10 @@ void cmComputeLinkInformation::SetCurrentLinkType(LinkType lt)
if (this->LinkTypeEnabled) {
switch (this->CurrentLinkType) {
case LinkStatic:
- this->Items.push_back(Item(this->StaticLinkTypeFlag, false));
+ this->Items.emplace_back(this->StaticLinkTypeFlag, false);
break;
case LinkShared:
- this->Items.push_back(Item(this->SharedLinkTypeFlag, false));
+ this->Items.emplace_back(this->SharedLinkTypeFlag, false);
break;
default:
break;
@@ -1002,7 +992,7 @@ void cmComputeLinkInformation::AddTargetItem(std::string const& 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));
+ this->Items.emplace_back(this->LibLinkFileFlag, false);
}
// For compatibility with CMake 2.4 include the item's directory in
@@ -1014,7 +1004,7 @@ void cmComputeLinkInformation::AddTargetItem(std::string const& item,
}
// Now add the full path to the library.
- this->Items.push_back(Item(item, true, target));
+ this->Items.emplace_back(item, true, target);
}
void cmComputeLinkInformation::AddFullItem(std::string const& item)
@@ -1036,7 +1026,7 @@ void cmComputeLinkInformation::AddFullItem(std::string const& item)
(generator.find("Visual Studio") != std::string::npos ||
generator.find("Xcode") != std::string::npos)) {
std::string file = cmSystemTools::GetFilenameName(item);
- if (!this->ExtractAnyLibraryName.find(file.c_str())) {
+ if (!this->ExtractAnyLibraryName.find(file)) {
this->HandleBadFullItem(item, file);
return;
}
@@ -1069,11 +1059,11 @@ void cmComputeLinkInformation::AddFullItem(std::string const& 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));
+ this->Items.emplace_back(this->LibLinkFileFlag, false);
}
// Now add the full path to the library.
- this->Items.push_back(Item(item, true));
+ this->Items.emplace_back(item, true);
}
bool cmComputeLinkInformation::CheckImplicitDirItem(std::string const& item)
@@ -1160,7 +1150,7 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
this->SetCurrentLinkType(this->StartLinkType);
// Use the item verbatim.
- this->Items.push_back(Item(item, false));
+ this->Items.emplace_back(item, false);
return;
}
@@ -1232,7 +1222,7 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
std::string out = this->LibLinkFlag;
out += lib;
out += this->LibLinkSuffix;
- this->Items.push_back(Item(out, false));
+ this->Items.emplace_back(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
@@ -1243,11 +1233,11 @@ void cmComputeLinkInformation::AddUserItem(std::string const& item,
void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
{
// Try to separate the framework name and path.
- if (!this->SplitFramework.find(item.c_str())) {
+ if (!this->SplitFramework.find(item)) {
std::ostringstream e;
e << "Could not parse framework path \"" << item << "\" "
<< "linked by target " << this->Target->GetName() << ".";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return;
}
@@ -1267,16 +1257,16 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
this->AddLibraryRuntimeInfo(full_fw);
// Add the item using the -framework option.
- this->Items.push_back(Item("-framework", false));
+ this->Items.emplace_back("-framework", false);
cmOutputConverter converter(this->Makefile->GetStateSnapshot());
fw = converter.EscapeForShell(fw);
- this->Items.push_back(Item(fw, false));
+ this->Items.emplace_back(fw, false);
}
void cmComputeLinkInformation::AddDirectoryItem(std::string const& item)
{
if (this->Makefile->IsOn("APPLE") &&
- cmSystemTools::IsPathToFramework(item.c_str())) {
+ cmSystemTools::IsPathToFramework(item)) {
this->AddFrameworkItem(item);
} else {
this->DropDirectoryItem(item);
@@ -1292,7 +1282,7 @@ void cmComputeLinkInformation::DropDirectoryItem(std::string const& item)
<< "\" requests linking to directory \"" << item << "\". "
<< "Targets may link only to libraries. "
<< "CMake is dropping the item.";
- cmSystemTools::Message(e.str().c_str());
+ cmSystemTools::Message(e.str());
}
void cmComputeLinkInformation::ComputeFrameworkInfo()
@@ -1393,7 +1383,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item,
<< " " << item << "\n"
<< "which is a full-path but not a valid library file name.";
/* clang-format on */
- this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+ this->CMakeInstance->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
this->Target->GetBacktrace());
}
}
@@ -1412,7 +1402,7 @@ void cmComputeLinkInformation::HandleBadFullItem(std::string const& item,
<< " " << item << "\n"
<< "which is a full-path but not a valid library file name.";
/* clang-format on */
- this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->CMakeInstance->IssueMessage(MessageType::FATAL_ERROR, e.str(),
this->Target->GetBacktrace());
} break;
}
@@ -1435,7 +1425,7 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
"CMP0003-WARNING-GIVEN", "1");
std::ostringstream w;
this->PrintLinkPolicyDiagnosis(w);
- this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+ this->CMakeInstance->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
this->Target->GetBacktrace());
}
case cmPolicies::OLD:
@@ -1450,17 +1440,15 @@ bool cmComputeLinkInformation::FinishLinkerSearchDirectories()
std::ostringstream e;
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0003) << "\n";
this->PrintLinkPolicyDiagnosis(e);
- this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->CMakeInstance->IssueMessage(MessageType::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);
+ for (std::string const& i : this->OldLinkDirItems) {
+ this->OrderLinkerSearchPath->AddLinkLibrary(i);
}
return true;
}
@@ -1489,19 +1477,17 @@ void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os)
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) {
+ for (std::string const& i : this->OldUserFlagItems) {
// 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) {
+ if (!line.empty() && (line.size() + i.size() + 2) > max_size) {
os << line << "\n";
sep = " ";
- line = "";
+ line.clear();
}
line += sep;
- line += *i;
+ line += i;
// Convert to the other separator.
sep = ", ";
}
@@ -1513,11 +1499,9 @@ void cmComputeLinkInformation::PrintLinkPolicyDiagnosis(std::ostream& os)
// 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";
+ for (std::string const& i : this->OldLinkDirItems) {
+ if (emitted.insert(cmSystemTools::GetFilenamePath(i)).second) {
+ os << " " << i << "\n";
}
}
@@ -1544,9 +1528,8 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
// 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);
+ for (std::string const& i : implicitDirVec) {
+ this->ImplicitLinkDirs.insert(i + "/" + libraryArch);
}
}
@@ -1573,11 +1556,9 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
}
// Store implicit link libraries.
- for (std::vector<std::string>::const_iterator i = implicitLibVec.begin();
- i != implicitLibVec.end(); ++i) {
+ for (std::string const& item : implicitLibVec) {
// 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);
}
@@ -1591,7 +1572,7 @@ void cmComputeLinkInformation::LoadImplicitLinkInfo()
}
std::vector<std::string> const&
-cmComputeLinkInformation::GetRuntimeSearchPath()
+cmComputeLinkInformation::GetRuntimeSearchPath() const
{
return this->OrderRuntimeSearchPath->GetOrderedDirectories();
}
@@ -1623,7 +1604,7 @@ void cmComputeLinkInformation::AddLibraryRuntimeInfo(
// 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() ? CM_NULLPTR : soName.c_str();
+ const char* soname = soName.empty() ? nullptr : soName.c_str();
// Include this library in the runtime path ordering.
this->OrderRuntimeSearchPath->AddRuntimeLibrary(fullPath, soname);
@@ -1657,7 +1638,7 @@ void cmComputeLinkInformation::AddLibraryRuntimeInfo(
if (!is_shared_library) {
// On some platforms (AIX) a shared library may look static.
if (this->ArchivesMayBeShared) {
- if (this->ExtractStaticLibraryName.find(file.c_str())) {
+ if (this->ExtractStaticLibraryName.find(file)) {
// This is the name of a shared library or archive.
is_shared_library = true;
}
@@ -1694,16 +1675,15 @@ static void cmCLI_ExpandListUnique(const char* str,
{
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);
+ for (std::string const& i : tmp) {
+ if (emitted.insert(i).second) {
+ out.push_back(i);
}
}
}
void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
- bool for_install)
+ bool for_install) const
{
// Select whether to generate runtime search directories.
bool outputRuntime =
@@ -1724,6 +1704,14 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
!this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH") &&
this->Target->GetPropertyAsBool("INSTALL_RPATH_USE_LINK_PATH");
+ // Select whether to use $ORIGIN in RPATHs for artifacts in the build tree.
+ std::string const& originToken = this->Makefile->GetSafeDefinition(
+ "CMAKE_SHARED_LIBRARY_RPATH_ORIGIN_TOKEN");
+ std::string targetOutputDir = this->Target->GetDirectory(this->Config);
+ bool use_relative_build_rpath =
+ this->Target->GetPropertyAsBool("BUILD_RPATH_USE_ORIGIN") &&
+ !originToken.empty() && !targetOutputDir.empty();
+
// Construct the RPATH.
std::set<std::string> emitted;
if (use_install_rpath) {
@@ -1733,6 +1721,8 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
if (use_build_rpath) {
// Add directories explicitly specified by user
if (const char* build_rpath = this->Target->GetProperty("BUILD_RPATH")) {
+ // This will not resolve entries to use $ORIGIN, the user is expected to
+ // do that if necessary.
cmCLI_ExpandListUnique(build_rpath, runtimeDirs, emitted);
}
}
@@ -1746,16 +1736,17 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
}
const char* stagePath =
this->Makefile->GetDefinition("CMAKE_STAGING_PREFIX");
- const char* installPrefix =
+ std::string const& 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) {
+ std::string const& topBinaryDir =
+ this->CMakeInstance->GetHomeOutputDirectory();
+ for (std::string const& ri : rdirs) {
// 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;
+ std::string d = ri;
if (!rootPath.empty() && d.find(rootPath) == 0) {
d = d.substr(rootPath.size());
} else if (stagePath && *stagePath && d.find(stagePath) == 0) {
@@ -1764,20 +1755,31 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
d += "/";
d += suffix;
cmSystemTools::ConvertToUnixSlashes(d);
+ } else if (use_relative_build_rpath) {
+ // If expansion of the $ORIGIN token is supported and permitted per
+ // policy, use relative paths in the RPATH.
+ if (cmSystemTools::ComparePath(d, topBinaryDir) ||
+ cmSystemTools::IsSubDirectory(d, topBinaryDir)) {
+ d = cmSystemTools::RelativePath(targetOutputDir, d);
+ if (!d.empty()) {
+ d = originToken + "/" + d;
+ } else {
+ d = originToken;
+ }
+ }
}
if (emitted.insert(d).second) {
- runtimeDirs.push_back(d);
+ runtimeDirs.push_back(std::move(d));
}
} else if (use_link_rpath) {
// Do not add any path inside the source or build tree.
- const char* topSourceDir = this->CMakeInstance->GetHomeDirectory();
- const char* topBinaryDir =
- this->CMakeInstance->GetHomeOutputDirectory();
- if (!cmSystemTools::ComparePath(*ri, topSourceDir) &&
- !cmSystemTools::ComparePath(*ri, topBinaryDir) &&
- !cmSystemTools::IsSubDirectory(*ri, topSourceDir) &&
- !cmSystemTools::IsSubDirectory(*ri, topBinaryDir)) {
- std::string d = *ri;
+ std::string const& topSourceDir =
+ this->CMakeInstance->GetHomeDirectory();
+ if (!cmSystemTools::ComparePath(ri, topSourceDir) &&
+ !cmSystemTools::ComparePath(ri, topBinaryDir) &&
+ !cmSystemTools::IsSubDirectory(ri, topSourceDir) &&
+ !cmSystemTools::IsSubDirectory(ri, 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) {
@@ -1788,7 +1790,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
cmSystemTools::ConvertToUnixSlashes(d);
}
if (emitted.insert(d).second) {
- runtimeDirs.push_back(d);
+ runtimeDirs.push_back(std::move(d));
}
}
}
@@ -1800,12 +1802,11 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
{
cmGeneratorTarget::LinkClosure const* lc =
this->Target->GetLinkClosure(this->Config);
- for (std::vector<std::string>::const_iterator li = lc->Languages.begin();
- li != lc->Languages.end(); ++li) {
+ for (std::string const& li : lc->Languages) {
std::string useVar =
- "CMAKE_" + *li + "_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH";
+ "CMAKE_" + li + "_USE_IMPLICIT_LINK_DIRECTORIES_IN_RUNTIME_PATH";
if (this->Makefile->IsOn(useVar)) {
- std::string dirVar = "CMAKE_" + *li + "_IMPLICIT_LINK_DIRECTORIES";
+ std::string dirVar = "CMAKE_" + li + "_IMPLICIT_LINK_DIRECTORIES";
if (const char* dirs = this->Makefile->GetDefinition(dirVar)) {
cmCLI_ExpandListUnique(dirs, runtimeDirs, emitted);
}
@@ -1818,7 +1819,7 @@ void cmComputeLinkInformation::GetRPath(std::vector<std::string>& runtimeDirs,
cmCLI_ExpandListUnique(this->RuntimeAlways.c_str(), runtimeDirs, emitted);
}
-std::string cmComputeLinkInformation::GetRPathString(bool for_install)
+std::string cmComputeLinkInformation::GetRPathString(bool for_install) const
{
// Get the directories to use.
std::vector<std::string> runtimeDirs;
@@ -1846,7 +1847,7 @@ std::string cmComputeLinkInformation::GetRPathString(bool for_install)
return rpath;
}
-std::string cmComputeLinkInformation::GetChrpathString()
+std::string cmComputeLinkInformation::GetChrpathString() const
{
if (!this->RuntimeUseChrpath) {
return "";
diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h
index 00e3ad265..863639c6a 100644
--- a/Source/cmComputeLinkInformation.h
+++ b/Source/cmComputeLinkInformation.h
@@ -9,6 +9,7 @@
#include <iosfwd>
#include <set>
#include <string>
+#include <utility>
#include <vector>
class cmGeneratorTarget;
@@ -30,41 +31,36 @@ public:
struct Item
{
- Item()
- : Value()
- , IsPath(true)
- , Target(CM_NULLPTR)
- {
- }
- Item(std::string const& v, bool p,
- cmGeneratorTarget const* target = CM_NULLPTR)
- : Value(v)
+ Item() = default;
+ Item(std::string v, bool p, cmGeneratorTarget const* target = nullptr)
+ : Value(std::move(v))
, IsPath(p)
, Target(target)
{
}
std::string Value;
- bool IsPath;
- cmGeneratorTarget const* Target;
+ bool IsPath = true;
+ cmGeneratorTarget const* Target = nullptr;
};
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();
+ ItemVector const& GetItems() const;
+ std::vector<std::string> const& GetDirectories() const;
+ std::vector<std::string> const& GetDepends() const;
+ std::vector<std::string> const& GetFrameworkPaths() const;
std::string GetLinkLanguage() const { return this->LinkLanguage; }
- std::vector<std::string> const& GetRuntimeSearchPath();
+ std::vector<std::string> const& GetRuntimeSearchPath() const;
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<cmGeneratorTarget const*> const& GetSharedLibrariesLinked();
+ void GetRPath(std::vector<std::string>& runtimeDirs, bool for_install) const;
+ std::string GetRPathString(bool for_install) const;
+ std::string GetChrpathString() const;
+ std::set<cmGeneratorTarget const*> const& GetSharedLibrariesLinked() const;
std::string const& GetRPathLinkFlag() const { return this->RPathLinkFlag; }
- std::string GetRPathLinkString();
+ std::string GetRPathLinkString() const;
std::string GetConfig() const { return this->Config; }
+
private:
void AddItem(std::string const& item, const cmGeneratorTarget* tgt);
void AddSharedDepItem(std::string const& item, cmGeneratorTarget const* tgt);
@@ -78,13 +74,13 @@ private:
std::set<cmGeneratorTarget const*> SharedLibrariesLinked;
// Context information.
- cmGeneratorTarget const* Target;
- cmMakefile* Makefile;
- cmGlobalGenerator* GlobalGenerator;
- cmake* CMakeInstance;
+ cmGeneratorTarget const* const Target;
+ cmMakefile* const Makefile;
+ cmGlobalGenerator* const GlobalGenerator;
+ cmake* const CMakeInstance;
// Configuration information.
- std::string Config;
+ std::string const Config;
std::string LinkLanguage;
// Modes for dealing with dependent shared libraries.
diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx
index ff19eac63..01d4c07e0 100644
--- a/Source/cmComputeTargetDepends.cxx
+++ b/Source/cmComputeTargetDepends.cxx
@@ -6,9 +6,12 @@
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmLinkItem.h"
+#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmState.h"
#include "cmStateTypes.h"
@@ -22,8 +25,6 @@
#include <stdio.h>
#include <utility>
-class cmListFileBacktrace;
-
/*
This class is meant to analyze inter-target dependencies globally
@@ -103,9 +104,7 @@ cmComputeTargetDepends::cmComputeTargetDepends(cmGlobalGenerator* gg)
cm->GetState()->GetGlobalPropertyAsBool("GLOBAL_DEPENDS_NO_CYCLES");
}
-cmComputeTargetDepends::~cmComputeTargetDepends()
-{
-}
+cmComputeTargetDepends::~cmComputeTargetDepends() = default;
bool cmComputeTargetDepends::Compute()
{
@@ -148,10 +147,11 @@ void cmComputeTargetDepends::GetTargetDirectDepends(cmGeneratorTarget const* t,
// Get its final dependencies.
EdgeList const& nl = this->FinalGraph[i];
- for (EdgeList::const_iterator ni = nl.begin(); ni != nl.end(); ++ni) {
- cmGeneratorTarget const* dep = this->Targets[*ni];
+ for (cmGraphEdge const& ni : nl) {
+ cmGeneratorTarget const* dep = this->Targets[ni];
cmTargetDependSet::iterator di = deps.insert(dep).first;
- di->SetType(ni->IsStrong());
+ di->SetType(ni.IsStrong());
+ di->SetBacktrace(ni.GetBacktrace());
}
}
@@ -160,15 +160,13 @@ 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 std::vector<cmGeneratorTarget*> targets =
- lgens[i]->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- cmGeneratorTarget* gt = *ti;
+ for (cmLocalGenerator* lgen : lgens) {
+ const std::vector<cmGeneratorTarget*>& targets =
+ lgen->GetGeneratorTargets();
+ for (cmGeneratorTarget const* ti : targets) {
int index = static_cast<int>(this->Targets.size());
- this->TargetIndex[gt] = index;
- this->Targets.push_back(gt);
+ this->TargetIndex[ti] = index;
+ this->Targets.push_back(ti);
}
}
}
@@ -197,48 +195,48 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
// dependencies in all targets, because the generated build-systems can't
// deal with config-specific dependencies.
{
- std::set<std::string> emitted;
+ std::set<cmLinkItem> emitted;
std::vector<std::string> configs;
depender->Makefile->GetConfigurations(configs);
if (configs.empty()) {
- configs.push_back("");
+ configs.emplace_back();
}
- for (std::vector<std::string>::const_iterator it = configs.begin();
- it != configs.end(); ++it) {
+ for (std::string const& it : configs) {
std::vector<cmSourceFile const*> objectFiles;
- depender->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() != cmStateEnums::EXECUTABLE &&
- depender->GetType() != cmStateEnums::STATIC_LIBRARY &&
- depender->GetType() != cmStateEnums::SHARED_LIBRARY &&
- depender->GetType() != cmStateEnums::MODULE_LIBRARY) {
- this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR,
- "Only executables and non-OBJECT libraries may "
- "reference target objects.",
- depender->GetBacktrace());
- return;
+ depender->GetExternalObjects(objectFiles, it);
+ for (cmSourceFile const* o : objectFiles) {
+ std::string const& objLib = o->GetObjectLibrary();
+ if (!objLib.empty()) {
+ cmLinkItem const& objItem =
+ depender->ResolveLinkItem(objLib, cmListFileBacktrace());
+ if (emitted.insert(objItem).second) {
+ if (depender->GetType() != cmStateEnums::EXECUTABLE &&
+ depender->GetType() != cmStateEnums::STATIC_LIBRARY &&
+ depender->GetType() != cmStateEnums::SHARED_LIBRARY &&
+ depender->GetType() != cmStateEnums::MODULE_LIBRARY &&
+ depender->GetType() != cmStateEnums::OBJECT_LIBRARY) {
+ this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "Only executables and libraries may reference target objects.",
+ depender->GetBacktrace());
+ return;
+ }
+ const_cast<cmGeneratorTarget*>(depender)->Target->AddUtility(
+ objLib);
}
- const_cast<cmGeneratorTarget*>(depender)->Target->AddUtility(objLib);
}
}
- cmLinkImplementation const* impl = depender->GetLinkImplementation(*it);
+ cmLinkImplementation 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) {
+ emitted.insert(cmLinkItem(depender, cmListFileBacktrace()));
+ for (cmLinkImplItem const& lib : impl->Libraries) {
// 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, *it, emitted);
+ if (emitted.insert(lib).second) {
+ this->AddTargetDepend(depender_index, lib, true);
+ this->AddInterfaceDepends(depender_index, lib, it, emitted);
}
}
}
@@ -247,14 +245,13 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
// Loop over all utility dependencies.
{
std::set<cmLinkItem> const& tutils = depender->GetUtilityItems();
- std::set<std::string> emitted;
+ std::set<cmLinkItem> 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) {
+ emitted.insert(cmLinkItem(depender, cmListFileBacktrace()));
+ for (cmLinkItem const& litem : tutils) {
// Don't emit the same utility twice for this target.
- if (emitted.insert(*util).second) {
- this->AddTargetDepend(depender_index, *util, false);
+ if (emitted.insert(litem).second) {
+ this->AddTargetDepend(depender_index, litem, false);
}
}
}
@@ -262,18 +259,22 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index)
void cmComputeTargetDepends::AddInterfaceDepends(
int depender_index, const cmGeneratorTarget* dependee,
- const std::string& config, std::set<std::string>& emitted)
+ cmListFileBacktrace const& dependee_backtrace, const std::string& config,
+ std::set<cmLinkItem>& emitted)
{
cmGeneratorTarget const* depender = this->Targets[depender_index];
if (cmLinkInterface const* iface =
dependee->GetLinkInterface(config, depender)) {
- for (std::vector<cmLinkItem>::const_iterator lib =
- iface->Libraries.begin();
- lib != iface->Libraries.end(); ++lib) {
+ for (cmLinkItem const& lib : iface->Libraries) {
// 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, config, emitted);
+ if (emitted.insert(lib).second) {
+ // Inject the backtrace of the original link dependency whose
+ // link interface we are adding. This indicates the line of
+ // code in the project that caused this dependency to be added.
+ cmLinkItem libBT = lib;
+ libBT.Backtrace = dependee_backtrace;
+ this->AddTargetDepend(depender_index, libBT, true);
+ this->AddInterfaceDepends(depender_index, libBT, config, emitted);
}
}
}
@@ -281,7 +282,7 @@ void cmComputeTargetDepends::AddInterfaceDepends(
void cmComputeTargetDepends::AddInterfaceDepends(
int depender_index, cmLinkItem const& dependee_name,
- const std::string& config, std::set<std::string>& emitted)
+ const std::string& config, std::set<cmLinkItem>& emitted)
{
cmGeneratorTarget const* depender = this->Targets[depender_index];
cmGeneratorTarget const* dependee = dependee_name.Target;
@@ -290,13 +291,14 @@ void cmComputeTargetDepends::AddInterfaceDepends(
// within the project.
if (dependee && dependee->GetType() == cmStateEnums::EXECUTABLE &&
!dependee->IsExecutableWithExports()) {
- dependee = CM_NULLPTR;
+ dependee = nullptr;
}
if (dependee) {
// A target should not depend on itself.
- emitted.insert(depender->GetName());
- this->AddInterfaceDepends(depender_index, dependee, config, emitted);
+ emitted.insert(cmLinkItem(depender, cmListFileBacktrace()));
+ this->AddInterfaceDepends(depender_index, dependee,
+ dependee_name.Backtrace, config, emitted);
}
}
@@ -312,7 +314,7 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
if (!dependee && !linking &&
(depender->GetType() != cmStateEnums::GLOBAL_TARGET)) {
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
bool issueMessage = false;
std::ostringstream e;
switch (depender->GetPolicyStatusCMP0046()) {
@@ -325,7 +327,7 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
issueMessage = true;
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
}
if (issueMessage) {
cmake* cm = this->GlobalGenerator->GetCMakeInstance();
@@ -333,13 +335,7 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
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());
- }
+ cm->IssueMessage(messageType, e.str(), dependee_name.Backtrace);
}
}
@@ -348,27 +344,28 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
// within the project.
if (linking && dependee && dependee->GetType() == cmStateEnums::EXECUTABLE &&
!dependee->IsExecutableWithExports()) {
- dependee = CM_NULLPTR;
+ dependee = nullptr;
}
if (dependee) {
- this->AddTargetDepend(depender_index, dependee, linking);
+ this->AddTargetDepend(depender_index, dependee, dependee_name.Backtrace,
+ linking);
}
}
-void cmComputeTargetDepends::AddTargetDepend(int depender_index,
- const cmGeneratorTarget* dependee,
- bool linking)
+void cmComputeTargetDepends::AddTargetDepend(
+ int depender_index, cmGeneratorTarget const* dependee,
+ cmListFileBacktrace const& dependee_backtrace, bool linking)
{
if (dependee->IsImported() ||
dependee->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
// Skip IMPORTED and INTERFACE 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 (cmGeneratorTarget const* transitive_dependee = i->Target) {
- this->AddTargetDepend(depender_index, transitive_dependee, false);
+ for (cmLinkItem const& i : utils) {
+ if (cmGeneratorTarget const* transitive_dependee = i.Target) {
+ this->AddTargetDepend(depender_index, transitive_dependee, i.Backtrace,
+ false);
}
}
} else {
@@ -380,8 +377,8 @@ void cmComputeTargetDepends::AddTargetDepend(int depender_index,
int dependee_index = tii->second;
// Add this entry to the dependency graph.
- this->InitialGraph[depender_index].push_back(
- cmGraphEdge(dependee_index, !linking));
+ this->InitialGraph[depender_index].emplace_back(dependee_index, !linking,
+ dependee_backtrace);
}
}
@@ -395,11 +392,11 @@ void cmComputeTargetDepends::DisplayGraph(Graph const& graph,
cmGeneratorTarget 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;
+ for (cmGraphEdge const& ni : nl) {
+ int dependee_index = ni;
cmGeneratorTarget 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");
+ dependee->GetName().c_str(), ni.IsStrong() ? "strong" : "weak");
}
}
fprintf(stderr, "\n");
@@ -414,8 +411,7 @@ void cmComputeTargetDepends::DisplayComponents(
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;
+ for (int i : nl) {
fprintf(stderr, " contains target %d [%s]\n", i,
this->Targets[i]->GetName().c_str());
}
@@ -446,8 +442,8 @@ bool cmComputeTargetDepends::CheckComponents(
}
// 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() != cmStateEnums::STATIC_LIBRARY) {
+ for (int ni : nl) {
+ if (this->Targets[ni]->GetType() != cmStateEnums::STATIC_LIBRARY) {
this->ComplainAboutBadComponent(ccg, c);
return false;
}
@@ -466,9 +462,8 @@ void cmComputeTargetDepends::ComplainAboutBadComponent(
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) {
+ for (int i : cl) {
// Get the depender.
- int i = *ci;
cmGeneratorTarget const* depender = this->Targets[i];
// Describe the depender.
@@ -477,12 +472,12 @@ void cmComputeTargetDepends::ComplainAboutBadComponent(
// 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;
+ for (cmGraphEdge const& ni : nl) {
+ int j = ni;
if (cmap[j] == c) {
cmGeneratorTarget const* dependee = this->Targets[j];
e << " depends on \"" << dependee->GetName() << "\""
- << " (" << (ni->IsStrong() ? "strong" : "weak") << ")\n";
+ << " (" << (ni.IsStrong() ? "strong" : "weak") << ")\n";
}
}
}
@@ -499,7 +494,7 @@ void cmComputeTargetDepends::ComplainAboutBadComponent(
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());
+ cmSystemTools::Error(e.str());
}
bool cmComputeTargetDepends::IntraComponent(std::vector<int> const& cmap,
@@ -514,10 +509,10 @@ bool cmComputeTargetDepends::IntraComponent(std::vector<int> const& cmap,
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));
+ for (cmGraphEdge const& edge : el) {
+ int j = edge;
+ if (cmap[j] == c && edge.IsStrong()) {
+ this->FinalGraph[i].emplace_back(j, true, edge.GetBacktrace());
if (!this->IntraComponent(cmap, c, j, head, emitted, visited)) {
return false;
}
@@ -526,7 +521,7 @@ bool cmComputeTargetDepends::IntraComponent(std::vector<int> const& cmap,
// Prepend to a linear linked-list of intra-component edges.
if (*head >= 0) {
- this->FinalGraph[i].push_back(cmGraphEdge(*head, false));
+ this->FinalGraph[i].emplace_back(*head, false, cmListFileBacktrace());
} else {
this->ComponentTail[c] = i;
}
@@ -555,10 +550,9 @@ bool cmComputeTargetDepends::ComputeFinalDepends(
int head = -1;
std::set<int> emitted;
NodeList const& nl = components[c];
- for (NodeList::const_reverse_iterator ni = nl.rbegin(); ni != nl.rend();
- ++ni) {
+ for (int ni : cmReverseRange(nl)) {
std::set<int> visited;
- if (!this->IntraComponent(cmap, c, *ni, &head, emitted, visited)) {
+ if (!this->IntraComponent(cmap, c, ni, &head, emitted, visited)) {
// Cycle in add_dependencies within component!
this->ComplainAboutBadComponent(ccg, c, true);
return false;
@@ -573,11 +567,11 @@ bool cmComputeTargetDepends::ComputeFinalDepends(
++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;
+ for (cmGraphEdge const& ni : nl) {
+ 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()));
+ this->FinalGraph[depender_component_tail].emplace_back(
+ dependee_component_head, ni.IsStrong(), ni.GetBacktrace());
}
}
return true;
diff --git a/Source/cmComputeTargetDepends.h b/Source/cmComputeTargetDepends.h
index e93e376ce..3840bd752 100644
--- a/Source/cmComputeTargetDepends.h
+++ b/Source/cmComputeTargetDepends.h
@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmGraphAdjacencyList.h"
+#include "cmListFileCache.h"
#include <map>
#include <set>
@@ -47,15 +48,17 @@ private:
void AddTargetDepend(int depender_index, cmLinkItem const& dependee_name,
bool linking);
void AddTargetDepend(int depender_index, cmGeneratorTarget const* dependee,
+ cmListFileBacktrace const& dependee_backtrace,
bool linking);
bool ComputeFinalDepends(cmComputeComponentGraph const& ccg);
void AddInterfaceDepends(int depender_index, cmLinkItem const& dependee_name,
const std::string& config,
- std::set<std::string>& emitted);
+ std::set<cmLinkItem>& emitted);
void AddInterfaceDepends(int depender_index,
cmGeneratorTarget const* dependee,
+ cmListFileBacktrace const& dependee_backtrace,
const std::string& config,
- std::set<std::string>& emitted);
+ std::set<cmLinkItem>& emitted);
cmGlobalGenerator* GlobalGenerator;
bool DebugMode;
bool NoCycles;
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
index 2bacf7321..e7e91c1a8 100644
--- a/Source/cmConditionEvaluator.cxx
+++ b/Source/cmConditionEvaluator.cxx
@@ -2,18 +2,20 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmConditionEvaluator.h"
-#include "cmConfigure.h"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <utility>
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmState.h"
#include "cmSystemTools.h"
+#include "cmake.h"
class cmCommand;
class cmTest;
@@ -52,11 +54,11 @@ static std::string const keyVERSION_LESS = "VERSION_LESS";
static std::string const keyVERSION_LESS_EQUAL = "VERSION_LESS_EQUAL";
cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
- const cmListFileContext& context,
- const cmListFileBacktrace& bt)
+ cmListFileContext context,
+ cmListFileBacktrace bt)
: Makefile(makefile)
- , ExecutionContext(context)
- , Backtrace(bt)
+ , ExecutionContext(std::move(context))
+ , Backtrace(std::move(bt))
, Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012))
, Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054))
, Policy57Status(makefile.GetPolicyStatus(cmPolicies::CMP0057))
@@ -82,9 +84,9 @@ cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
bool cmConditionEvaluator::IsTrue(
const std::vector<cmExpandedCommandArgument>& args, std::string& errorString,
- cmake::MessageType& status)
+ MessageType& status)
{
- errorString = "";
+ errorString.clear();
// handle empty invocation
if (args.empty()) {
@@ -92,10 +94,7 @@ bool cmConditionEvaluator::IsTrue(
}
// store the reduced args in this vector
- cmArgumentList newArgs;
-
- // copy to the list structure
- newArgs.insert(newArgs.end(), args.begin(), args.end());
+ cmArgumentList newArgs(args.begin(), args.end());
// 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
@@ -124,12 +123,12 @@ bool cmConditionEvaluator::IsTrue(
// now at the end there should only be one argument left
if (newArgs.size() != 1) {
errorString = "Unknown arguments specified";
- status = cmake::FATAL_ERROR;
+ status = MessageType::FATAL_ERROR;
return false;
}
- return this->GetBooleanValueWithAutoDereference(*(newArgs.begin()),
- errorString, status, true);
+ return this->GetBooleanValueWithAutoDereference(newArgs.front(), errorString,
+ status, true);
}
//=========================================================================
@@ -139,7 +138,7 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted(
if ((this->Policy54Status != cmPolicies::WARN &&
this->Policy54Status != cmPolicies::OLD) &&
argument.WasQuoted()) {
- return CM_NULLPTR;
+ return nullptr;
}
const char* def = this->Makefile.GetDefinition(argument.GetValue());
@@ -156,7 +155,7 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted(
"Since the policy is not set the OLD behavior will be used.";
this->Makefile.GetCMakeInstance()->IssueMessage(
- cmake::AUTHOR_WARNING, e.str(), this->Backtrace);
+ MessageType::AUTHOR_WARNING, e.str(), this->Backtrace);
}
}
@@ -200,7 +199,7 @@ bool cmConditionEvaluator::IsKeyword(std::string const& keyword,
"Since the policy is not set the OLD behavior will be used.";
this->Makefile.GetCMakeInstance()->IssueMessage(
- cmake::AUTHOR_WARNING, e.str(), this->Backtrace);
+ MessageType::AUTHOR_WARNING, e.str(), this->Backtrace);
}
}
@@ -270,7 +269,7 @@ bool cmConditionEvaluator::GetBooleanValueOld(
// returns the resulting boolean value
bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
cmExpandedCommandArgument& newArg, std::string& errorString,
- cmake::MessageType& status, bool oneArg) const
+ MessageType& status, bool oneArg) const
{
// Use the policy if it is set.
if (this->Policy12Status == cmPolicies::NEW) {
@@ -289,7 +288,7 @@ bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
errorString = "An argument named \"" + newArg.GetValue() +
"\" appears in a conditional statement. " +
cmPolicies::GetPolicyWarning(cmPolicies::CMP0012);
- status = cmake::AUTHOR_WARNING;
+ status = MessageType::AUTHOR_WARNING;
CM_FALLTHROUGH;
case cmPolicies::OLD:
return oldResult;
@@ -298,7 +297,7 @@ bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
errorString = "An argument named \"" + newArg.GetValue() +
"\" appears in a conditional statement. " +
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0012);
- status = cmake::FATAL_ERROR;
+ status = MessageType::FATAL_ERROR;
}
case cmPolicies::NEW:
break;
@@ -363,7 +362,7 @@ void cmConditionEvaluator::HandleBinaryOp(bool value, int& reducible,
// level 0 processes parenthetical expressions
bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
std::string& errorString,
- cmake::MessageType& status)
+ MessageType& status)
{
int reducible;
do {
@@ -387,7 +386,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
}
if (depth) {
errorString = "mismatched parenthesis in condition";
- status = cmake::FATAL_ERROR;
+ status = MessageType::FATAL_ERROR;
return false;
}
// store the reduced args in this vector
@@ -396,7 +395,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
// copy to the list structure
cmArgumentList::iterator argP1 = arg;
argP1++;
- newArgs2.insert(newArgs2.end(), argP1, argClose);
+ cmAppend(newArgs2, argP1, argClose);
newArgs2.pop_back();
// now recursively invoke IsTrue to handle the values inside the
// parenthetical expression
@@ -420,7 +419,7 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
//=========================================================================
// level one handles most predicates except for NOT
bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
- cmake::MessageType&)
+ MessageType&)
{
int reducible;
do {
@@ -455,7 +454,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
if (this->IsKeyword(keyCOMMAND, *arg) && argP1 != newArgs.end()) {
cmCommand* command =
this->Makefile.GetState()->GetCommand(argP1->c_str());
- this->HandlePredicate(command != CM_NULLPTR, reducible, arg, newArgs,
+ this->HandlePredicate(command != nullptr, reducible, arg, newArgs,
argP1, argP2);
}
// does a policy exist
@@ -467,7 +466,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
// does a target exist
if (this->IsKeyword(keyTARGET, *arg) && argP1 != newArgs.end()) {
this->HandlePredicate(
- this->Makefile.FindTargetToUse(argP1->GetValue()) != CM_NULLPTR,
+ this->Makefile.FindTargetToUse(argP1->GetValue()) != nullptr,
reducible, arg, newArgs, argP1, argP2);
}
// does a test exist
@@ -475,8 +474,8 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
this->Policy64Status != cmPolicies::WARN) {
if (this->IsKeyword(keyTEST, *arg) && argP1 != newArgs.end()) {
const cmTest* haveTest = this->Makefile.GetTest(argP1->c_str());
- this->HandlePredicate(haveTest != CM_NULLPTR, reducible, arg,
- newArgs, argP1, argP2);
+ this->HandlePredicate(haveTest != nullptr, reducible, arg, newArgs,
+ argP1, argP2);
}
} else if (this->Policy64Status == cmPolicies::WARN &&
this->IsKeyword(keyTEST, *arg)) {
@@ -486,7 +485,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
"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());
+ this->Makefile.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
}
// is a variable defined
if (this->IsKeyword(keyDEFINED, *arg) && argP1 != newArgs.end()) {
@@ -495,7 +494,13 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
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::HasEnv(env.c_str());
+ bdef = cmSystemTools::HasEnv(env);
+ } else if (argP1len > 6 &&
+ argP1->GetValue().substr(0, 6) == "CACHE{" &&
+ argP1->GetValue().operator[](argP1len - 1) == '}') {
+ std::string cache = argP1->GetValue().substr(6, argP1len - 7);
+ bdef =
+ this->Makefile.GetState()->GetCacheEntryValue(cache) != nullptr;
} else {
bdef = this->Makefile.IsDefinitionSet(argP1->GetValue());
}
@@ -511,7 +516,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
// level two handles most binary operations except for AND OR
bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
std::string& errorString,
- cmake::MessageType& status)
+ MessageType& status)
{
int reducible;
std::string def_buf;
@@ -542,7 +547,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
std::ostringstream error;
error << "Regular expression \"" << rex << "\" cannot compile";
errorString = error.str();
- status = cmake::FATAL_ERROR;
+ status = MessageType::FATAL_ERROR;
return false;
}
if (regEntry.find(def)) {
@@ -677,7 +682,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
"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());
+ this->Makefile.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
}
}
@@ -691,7 +696,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
// level 3 handles NOT
bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs,
std::string& errorString,
- cmake::MessageType& status)
+ MessageType& status)
{
int reducible;
do {
@@ -717,7 +722,7 @@ bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs,
// level 4 handles AND OR
bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs,
std::string& errorString,
- cmake::MessageType& status)
+ MessageType& status)
{
int reducible;
bool lhs;
diff --git a/Source/cmConditionEvaluator.h b/Source/cmConditionEvaluator.h
index 50f4edc4f..59e1396f6 100644
--- a/Source/cmConditionEvaluator.h
+++ b/Source/cmConditionEvaluator.h
@@ -11,8 +11,8 @@
#include "cmExpandedCommandArgument.h"
#include "cmListFileCache.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
-#include "cmake.h"
class cmMakefile;
@@ -21,14 +21,14 @@ class cmConditionEvaluator
public:
typedef std::list<cmExpandedCommandArgument> cmArgumentList;
- cmConditionEvaluator(cmMakefile& makefile, cmListFileContext const& context,
- cmListFileBacktrace const& bt);
+ cmConditionEvaluator(cmMakefile& makefile, cmListFileContext context,
+ cmListFileBacktrace bt);
// 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);
+ std::string& errorString, MessageType& status);
private:
// Filter the given variable definition based on policy CMP0054.
@@ -48,7 +48,7 @@ private:
bool GetBooleanValueWithAutoDereference(cmExpandedCommandArgument& newArg,
std::string& errorString,
- cmake::MessageType& status,
+ MessageType& status,
bool oneArg = false) const;
void IncrementArguments(cmArgumentList& newArgs,
@@ -66,19 +66,18 @@ private:
cmArgumentList::iterator& argP2);
bool HandleLevel0(cmArgumentList& newArgs, std::string& errorString,
- cmake::MessageType& status);
+ MessageType& status);
- bool HandleLevel1(cmArgumentList& newArgs, std::string&,
- cmake::MessageType&);
+ bool HandleLevel1(cmArgumentList& newArgs, std::string&, MessageType&);
bool HandleLevel2(cmArgumentList& newArgs, std::string& errorString,
- cmake::MessageType& status);
+ MessageType& status);
bool HandleLevel3(cmArgumentList& newArgs, std::string& errorString,
- cmake::MessageType& status);
+ MessageType& status);
bool HandleLevel4(cmArgumentList& newArgs, std::string& errorString,
- cmake::MessageType& status);
+ MessageType& status);
cmMakefile& Makefile;
cmListFileContext ExecutionContext;
diff --git a/Source/cmConfigure.cmake.h.in b/Source/cmConfigure.cmake.h.in
index 524fdf808..19b1cd4e3 100644
--- a/Source/cmConfigure.cmake.h.in
+++ b/Source/cmConfigure.cmake.h.in
@@ -19,51 +19,11 @@
#cmakedefine HAVE_UNSETENV
#cmakedefine CMAKE_USE_ELF_PARSER
#cmakedefine CMAKE_USE_MACH_PARSER
-#cmakedefine CMAKE_USE_LIBUV
-#cmakedefine CMake_HAVE_CXX_AUTO_PTR
-#cmakedefine CMake_HAVE_CXX_EQ_DELETE
-#cmakedefine CMake_HAVE_CXX_FALLTHROUGH
-#cmakedefine CMake_HAVE_CXX_GNU_FALLTHROUGH
-#cmakedefine CMake_HAVE_CXX_ATTRIBUTE_FALLTHROUGH
#cmakedefine CMake_HAVE_CXX_MAKE_UNIQUE
-#cmakedefine CMake_HAVE_CXX_NULLPTR
-#cmakedefine CMake_HAVE_CXX_OVERRIDE
-#cmakedefine CMake_HAVE_CXX_UNIQUE_PTR
-#cmakedefine CMake_HAVE_CXX_UNORDERED_MAP
-#cmakedefine CMake_HAVE_CXX_UNORDERED_SET
+#define CMake_DEFAULT_RECURSION_LIMIT @CMake_DEFAULT_RECURSION_LIMIT@
#define CMAKE_BIN_DIR "/@CMAKE_BIN_DIR@"
#define CMAKE_DATA_DIR "/@CMAKE_DATA_DIR@"
-#ifdef CMake_HAVE_CXX_EQ_DELETE
-#define CM_EQ_DELETE = delete
-#else
-#define CM_EQ_DELETE
-#endif
-
-#if defined(CMake_HAVE_CXX_FALLTHROUGH)
-#define CM_FALLTHROUGH [[fallthrough]]
-#elif defined(CMake_HAVE_CXX_GNU_FALLTHROUGH)
-#define CM_FALLTHROUGH [[gnu::fallthrough]]
-elif defined(CMake_HAVE_CXX_ATTRIBUTE_FALLTHROUGH)
-#define CM_FALLTHROUGH __attribute__((fallthrough))
-#else
-#define CM_FALLTHROUGH
-#endif
-
-#ifdef CMake_HAVE_CXX_NULLPTR
-#define CM_NULLPTR nullptr
-#else
-#define CM_NULLPTR 0
-#endif
-
-#ifdef CMake_HAVE_CXX_OVERRIDE
-#define CM_OVERRIDE override
-#else
-#define CM_OVERRIDE
-#endif
-
-#define CM_DISABLE_COPY(Class) \
- Class(Class const&) CM_EQ_DELETE; \
- Class& operator=(Class const&) CM_EQ_DELETE;
+#define CM_FALLTHROUGH cmsys_FALLTHROUGH
#endif
diff --git a/Source/cmConfigureFileCommand.cxx b/Source/cmConfigureFileCommand.cxx
index 18005f27c..0917d1102 100644
--- a/Source/cmConfigureFileCommand.cxx
+++ b/Source/cmConfigureFileCommand.cxx
@@ -5,8 +5,8 @@
#include <sstream>
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -20,11 +20,8 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
}
std::string const& inFile = args[0];
- if (!cmSystemTools::FileIsFullPath(inFile)) {
- this->InputFile = this->Makefile->GetCurrentSourceDirectory();
- this->InputFile += "/";
- }
- this->InputFile += inFile;
+ this->InputFile = cmSystemTools::CollapseFullPath(
+ inFile, this->Makefile->GetCurrentSourceDirectory());
// If the input location is a directory, error out.
if (cmSystemTools::FileIsDirectory(this->InputFile)) {
@@ -39,11 +36,8 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
}
std::string const& outFile = args[1];
- if (!cmSystemTools::FileIsFullPath(outFile)) {
- this->OutputFile = this->Makefile->GetCurrentBinaryDirectory();
- this->OutputFile += "/";
- }
- this->OutputFile += outFile;
+ this->OutputFile = cmSystemTools::CollapseFullPath(
+ outFile, this->Makefile->GetCurrentBinaryDirectory());
// If the output location is already a directory put the file in it.
if (cmSystemTools::FileIsDirectory(this->OutputFile)) {
@@ -51,7 +45,7 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
this->OutputFile += cmSystemTools::GetFilenameName(inFile);
}
- if (!this->Makefile->CanIWriteThisFile(this->OutputFile.c_str())) {
+ if (!this->Makefile->CanIWriteThisFile(this->OutputFile)) {
std::string e = "attempted to configure a file: " + this->OutputFile +
" into a source directory.";
this->SetError(e);
@@ -95,7 +89,7 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
if (!unknown_args.empty()) {
std::string msg = "configure_file called with unknown argument(s):\n";
msg += unknown_args;
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg);
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, msg);
}
if (!this->ConfigureFile()) {
@@ -108,7 +102,7 @@ bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
int cmConfigureFileCommand::ConfigureFile()
{
- return this->Makefile->ConfigureFile(
- this->InputFile.c_str(), this->OutputFile.c_str(), this->CopyOnly,
- this->AtOnly, this->EscapeQuotes, this->NewLineStyle);
+ return this->Makefile->ConfigureFile(this->InputFile, this->OutputFile,
+ this->CopyOnly, this->AtOnly,
+ this->EscapeQuotes, this->NewLineStyle);
}
diff --git a/Source/cmConfigureFileCommand.h b/Source/cmConfigureFileCommand.h
index 6cebbd258..5603c505c 100644
--- a/Source/cmConfigureFileCommand.h
+++ b/Source/cmConfigureFileCommand.h
@@ -3,7 +3,7 @@
#ifndef cmConfigureFileCommand_h
#define cmConfigureFileCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,14 +16,14 @@ class cmExecutionStatus;
class cmConfigureFileCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmConfigureFileCommand; }
+ cmCommand* Clone() override { return new cmConfigureFileCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
int ConfigureFile();
@@ -32,9 +32,9 @@ private:
std::string InputFile;
std::string OutputFile;
- bool CopyOnly;
- bool EscapeQuotes;
- bool AtOnly;
+ bool CopyOnly = false;
+ bool EscapeQuotes = false;
+ bool AtOnly = false;
};
#endif
diff --git a/Source/cmContinueCommand.cxx b/Source/cmContinueCommand.cxx
index 2298a05c5..48f1f411b 100644
--- a/Source/cmContinueCommand.cxx
+++ b/Source/cmContinueCommand.cxx
@@ -4,15 +4,15 @@
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
-#include "cmake.h"
// cmContinueCommand
bool cmContinueCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
if (!this->Makefile->IsLoopBlock()) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"A CONTINUE command was found outside of a "
"proper FOREACH or WHILE loop scope.");
cmSystemTools::SetFatalErrorOccured();
@@ -22,7 +22,7 @@ bool cmContinueCommand::InitialPass(std::vector<std::string> const& args,
status.SetContinueInvoked();
if (!args.empty()) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"The CONTINUE command does not accept any "
"arguments.");
cmSystemTools::SetFatalErrorOccured();
diff --git a/Source/cmContinueCommand.h b/Source/cmContinueCommand.h
index 92bc68e85..d383d1d03 100644
--- a/Source/cmContinueCommand.h
+++ b/Source/cmContinueCommand.h
@@ -3,7 +3,7 @@
#ifndef cmContinueCommand_h
#define cmContinueCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmContinueCommand; }
+ cmCommand* Clone() override { return new cmContinueCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmConvertMSBuildXMLToJSON.py b/Source/cmConvertMSBuildXMLToJSON.py
index 93ab8a82f..02074ba65 100644
--- a/Source/cmConvertMSBuildXMLToJSON.py
+++ b/Source/cmConvertMSBuildXMLToJSON.py
@@ -96,7 +96,6 @@ def read_msbuild_json(path, values=[]):
return values
-
def main():
"""Script entrypoint."""
# Parse the arguments
@@ -213,6 +212,14 @@ def __find_and_remove_value(list, compare):
return found
+def __normalize_switch(switch, separator):
+ new = switch
+ if switch.startswith("/") or switch.startswith("-"):
+ new = switch[1:]
+ if new and separator:
+ new = new + separator
+ return new
+
###########################################################################################
# private xml functions
def __convert(root, tag, values, func):
@@ -257,6 +264,8 @@ def __convert_bool(node):
reverse_switch = __get_attribute(node, 'ReverseSwitch')
if reverse_switch:
+ __with_argument(node, converted)
+
converted_reverse = copy.deepcopy(converted)
converted_reverse['switch'] = reverse_switch
@@ -303,7 +312,11 @@ def __convert_node(node, default_value='', default_flags=vsflags()):
converted = {}
converted['name'] = name
- converted['switch'] = __get_attribute(node, 'Switch')
+
+ switch = __get_attribute(node, 'Switch')
+ separator = __get_attribute(node, 'Separator')
+ converted['switch'] = __normalize_switch(switch, separator)
+
converted['comment'] = __get_attribute(node, 'DisplayName')
converted['value'] = default_value
@@ -343,7 +356,7 @@ def __with_argument(node, value):
def __preprocess_arguments(root):
- """Preprocesses occurrances of Argument within the root.
+ """Preprocesses occurrences of Argument within the root.
Argument XML values reference other values within the document by name. The
referenced value does not contain a switch. This function will add the
@@ -435,7 +448,7 @@ def __write_json_file(path, values):
with open(path, 'w') as f:
json.dump(sorted_values, f, indent=2, separators=(',', ': '))
-
+ f.write("\n")
###########################################################################################
# private list helpers
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 9a4abf3ca..f12ef0b4a 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCoreTryCompile.h"
-#include "cmConfigure.h"
#include "cmsys/Directory.hxx"
#include <set>
#include <sstream>
@@ -14,26 +13,38 @@
#include "cmExportTryCompileFileGenerator.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmState.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmVersion.h"
+#include "cm_static_string_view.hxx"
#include "cmake.h"
static std::string const kCMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN =
"CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN";
static std::string const kCMAKE_C_COMPILER_TARGET = "CMAKE_C_COMPILER_TARGET";
+static std::string const kCMAKE_C_LINK_NO_PIE_SUPPORTED =
+ "CMAKE_C_LINK_NO_PIE_SUPPORTED";
+static std::string const kCMAKE_C_LINK_PIE_SUPPORTED =
+ "CMAKE_C_LINK_PIE_SUPPORTED";
static std::string const kCMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN =
"CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN";
static std::string const kCMAKE_CXX_COMPILER_TARGET =
"CMAKE_CXX_COMPILER_TARGET";
+static std::string const kCMAKE_CXX_LINK_NO_PIE_SUPPORTED =
+ "CMAKE_CXX_LINK_NO_PIE_SUPPORTED";
+static std::string const kCMAKE_CXX_LINK_PIE_SUPPORTED =
+ "CMAKE_CXX_LINK_PIE_SUPPORTED";
static std::string const kCMAKE_ENABLE_EXPORTS = "CMAKE_ENABLE_EXPORTS";
static std::string const kCMAKE_LINK_SEARCH_END_STATIC =
"CMAKE_LINK_SEARCH_END_STATIC";
static std::string const kCMAKE_LINK_SEARCH_START_STATIC =
"CMAKE_LINK_SEARCH_START_STATIC";
+static std::string const kCMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT =
+ "CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT";
static std::string const kCMAKE_OSX_ARCHITECTURES = "CMAKE_OSX_ARCHITECTURES";
static std::string const kCMAKE_OSX_DEPLOYMENT_TARGET =
"CMAKE_OSX_DEPLOYMENT_TARGET";
@@ -49,6 +60,13 @@ static std::string const kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES =
"CMAKE_TRY_COMPILE_PLATFORM_VARIABLES";
static std::string const kCMAKE_WARN_DEPRECATED = "CMAKE_WARN_DEPRECATED";
+/* GHS Multi platform variables */
+static std::set<std::string> ghs_platform_vars{
+ "GHS_TARGET_PLATFORM", "GHS_PRIMARY_TARGET", "GHS_TOOLSET_ROOT",
+ "GHS_OS_ROOT", "GHS_OS_DIR", "GHS_BSP_NAME",
+ "GHS_OS_DIR_OPTION"
+};
+
static void writeProperty(FILE* fout, std::string const& targetName,
std::string const& prop, std::string const& value)
{
@@ -72,7 +90,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
bool isTryRun)
{
this->BinaryDirectory = argv[1];
- this->OutputFile = "";
+ this->OutputFile.clear();
// which signature were we called with ?
this->SrcFileSignature = true;
@@ -83,17 +101,20 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
if (strcmp(tt, cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE)) ==
0) {
targetType = cmStateEnums::EXECUTABLE;
- } else if (strcmp(tt, cmState::GetTargetTypeName(
- cmStateEnums::STATIC_LIBRARY)) == 0) {
+ } else if (strcmp(tt,
+ cmState::GetTargetTypeName(
+ cmStateEnums::STATIC_LIBRARY)) == 0) {
targetType = cmStateEnums::STATIC_LIBRARY;
} else {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, std::string("Invalid value '") + tt +
+ MessageType::FATAL_ERROR,
+ std::string("Invalid value '") + tt +
"' for "
"CMAKE_TRY_COMPILE_TARGET_TYPE. Only "
"'" +
- cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE) + "' and "
- "'" +
+ cmState::GetTargetTypeName(cmStateEnums::EXECUTABLE) +
+ "' and "
+ "'" +
cmState::GetTargetTypeName(cmStateEnums::STATIC_LIBRARY) +
"' "
"are allowed.");
@@ -101,11 +122,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
}
}
- const char* sourceDirectory = argv[2].c_str();
- const char* projectName = CM_NULLPTR;
+ std::string sourceDirectory = argv[2];
+ std::string projectName;
std::string targetName;
std::vector<std::string> cmakeFlags(1, "CMAKE_FLAGS"); // fake argv[0]
std::vector<std::string> compileDefs;
+ std::string cmakeInternal;
std::string outputVariable;
std::string copyFile;
std::string copyFileError;
@@ -119,6 +141,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
std::string cxxExtensions;
std::string cudaExtensions;
std::vector<std::string> targets;
+ std::vector<std::string> linkOptions;
std::string libsToLink = " ";
bool useOldLinkLibs = true;
char targetNameBuf[64];
@@ -142,6 +165,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
DoingNone,
DoingCMakeFlags,
DoingCompileDefinitions,
+ DoingLinkOptions,
DoingLinkLibraries,
DoingOutputVariable,
DoingCopyFile,
@@ -155,7 +179,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
DoingCExtensions,
DoingCxxExtensions,
DoingCudaExtensions,
- DoingSources
+ DoingSources,
+ DoingCMakeInternal
};
Doing doing = useSources ? DoingSources : DoingNone;
for (size_t i = 3; i < argv.size(); ++i) {
@@ -163,6 +188,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
doing = DoingCMakeFlags;
} else if (argv[i] == "COMPILE_DEFINITIONS") {
doing = DoingCompileDefinitions;
+ } else if (argv[i] == "LINK_OPTIONS") {
+ doing = DoingLinkOptions;
} else if (argv[i] == "LINK_LIBRARIES") {
doing = DoingLinkLibraries;
useOldLinkLibs = false;
@@ -202,10 +229,14 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
} else if (argv[i] == "CUDA_EXTENSIONS") {
doing = DoingCudaExtensions;
didCudaExtensions = true;
+ } else if (argv[i] == "__CMAKE_INTERNAL") {
+ doing = DoingCMakeInternal;
} else if (doing == DoingCMakeFlags) {
cmakeFlags.push_back(argv[i]);
} else if (doing == DoingCompileDefinitions) {
- compileDefs.push_back(argv[i]);
+ cmSystemTools::ExpandListArgument(argv[i], compileDefs);
+ } else if (doing == DoingLinkOptions) {
+ linkOptions.push_back(argv[i]);
} else if (doing == DoingLinkLibraries) {
libsToLink += "\"" + cmSystemTools::TrimWhitespace(argv[i]) + "\" ";
if (cmTarget* tgt = this->Makefile->FindTargetToUse(argv[i])) {
@@ -222,11 +253,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
CM_FALLTHROUGH;
default:
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"Only libraries may be used as try_compile or try_run IMPORTED "
"LINK_LIBRARIES. Got " +
- std::string(tgt->GetName()) + " of "
- "type " +
+ std::string(tgt->GetName()) +
+ " of "
+ "type " +
cmState::GetTargetTypeName(tgt->GetType()) + ".");
return -1;
}
@@ -272,101 +304,106 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
doing = DoingNone;
} else if (doing == DoingSources) {
sources.push_back(argv[i]);
+ } else if (doing == DoingCMakeInternal) {
+ cmakeInternal = argv[i];
+ doing = DoingNone;
} else if (i == 3) {
this->SrcFileSignature = false;
- projectName = argv[i].c_str();
+ projectName = argv[i];
} else if (i == 4 && !this->SrcFileSignature) {
targetName = argv[i];
} else {
std::ostringstream m;
m << "try_compile given unknown argument \"" << argv[i] << "\".";
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m.str());
}
}
if (didCopyFile && copyFile.empty()) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"COPY_FILE must be followed by a file path");
return -1;
}
if (didCopyFileError && copyFileError.empty()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::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");
+ MessageType::FATAL_ERROR,
+ "COPY_FILE_ERROR may be used only with COPY_FILE");
return -1;
}
if (didOutputVariable && outputVariable.empty()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"OUTPUT_VARIABLE must be followed by a variable name");
return -1;
}
if (useSources && sources.empty()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"SOURCES must be followed by at least one source file");
return -1;
}
if (didCStandard && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, "C_STANDARD allowed only in source file signature.");
+ MessageType::FATAL_ERROR,
+ "C_STANDARD allowed only in source file signature.");
return -1;
}
if (didCxxStandard && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"CXX_STANDARD allowed only in source file signature.");
return -1;
}
if (didCudaStandard && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"CUDA_STANDARD allowed only in source file signature.");
return -1;
}
if (didCStandardRequired && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"C_STANDARD_REQUIRED allowed only in source file signature.");
return -1;
}
if (didCxxStandardRequired && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"CXX_STANDARD_REQUIRED allowed only in source file signature.");
return -1;
}
if (didCudaStandardRequired && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"CUDA_STANDARD_REQUIRED allowed only in source file signature.");
return -1;
}
if (didCExtensions && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"C_EXTENSIONS allowed only in source file signature.");
return -1;
}
if (didCxxExtensions && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"CXX_EXTENSIONS allowed only in source file signature.");
return -1;
}
if (didCudaExtensions && !this->SrcFileSignature) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"CUDA_EXTENSIONS allowed only in source file signature.");
return -1;
}
@@ -374,32 +411,32 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
// compute the binary dir when TRY_COMPILE is called with a src file
// signature
if (this->SrcFileSignature) {
- this->BinaryDirectory += cmake::GetCMakeFilesDirectory();
+ this->BinaryDirectory += "/CMakeFiles";
this->BinaryDirectory += "/CMakeTmp";
} else {
// only valid for srcfile signatures
if (!compileDefs.empty()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"COMPILE_DEFINITIONS specified on a srcdir type TRY_COMPILE");
return -1;
}
if (!copyFile.empty()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::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());
+ cmSystemTools::MakeDirectory(this->BinaryDirectory);
// do not allow recursive try Compiles
if (this->BinaryDirectory == this->Makefile->GetHomeOutputDirectory()) {
std::ostringstream e;
e << "Attempt at a recursive or nested TRY_COMPILE in directory\n"
<< " " << this->BinaryDirectory << "\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return -1;
}
@@ -418,23 +455,22 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
// Detect languages to enable.
cmGlobalGenerator* gg = this->Makefile->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);
+ for (std::string const& si : sources) {
+ std::string ext = cmSystemTools::GetFilenameLastExtension(si);
std::string lang = gg->GetLanguageFromExtension(ext.c_str());
if (!lang.empty()) {
testLangs.insert(lang);
} else {
std::ostringstream err;
err << "Unknown extension \"" << ext << "\" for file\n"
- << " " << *si << "\n"
+ << " " << si << "\n"
<< "try_compile() works only for enabled languages. "
<< "Currently these are:\n ";
std::vector<std::string> langs;
gg->GetEnabledLanguages(langs);
err << cmJoin(langs, " ");
err << "\nSee project() command to enable other languages.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, err.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err.str());
return -1;
}
}
@@ -444,7 +480,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
// we need to create a directory and CMakeLists file etc...
// first create the directories
- sourceDirectory = this->BinaryDirectory.c_str();
+ sourceDirectory = this->BinaryDirectory;
// now create a CMakeLists.txt file in that directory
FILE* fout = cmsys::SystemTools::Fopen(outFileName, "w");
@@ -455,7 +491,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
<< " " << outFileName << "\n"
<< cmSystemTools::GetLastSystemError();
/* clang-format on */
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return -1;
}
@@ -467,12 +503,18 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
fprintf(fout, "set(CMAKE_MODULE_PATH \"%s\")\n", def);
}
+ /* Set MSVC runtime library policy to match our selection. */
+ if (const char* msvcRuntimeLibraryDefault =
+ this->Makefile->GetDefinition(kCMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT)) {
+ fprintf(fout, "cmake_policy(SET CMP0091 %s)\n",
+ *msvcRuntimeLibraryDefault ? "NEW" : "OLD");
+ }
+
std::string projectLangs;
- for (std::set<std::string>::iterator li = testLangs.begin();
- li != testLangs.end(); ++li) {
- projectLangs += " " + *li;
+ for (std::string const& li : testLangs) {
+ projectLangs += " " + li;
std::string rulesOverrideBase = "CMAKE_USER_MAKE_RULES_OVERRIDE";
- std::string rulesOverrideLang = rulesOverrideBase + "_" + *li;
+ std::string rulesOverrideLang = rulesOverrideBase + "_" + li;
if (const char* rulesOverridePath =
this->Makefile->GetDefinition(rulesOverrideLang)) {
fprintf(fout, "set(%s \"%s\")\n", rulesOverrideLang.c_str(),
@@ -484,16 +526,24 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
}
}
fprintf(fout, "project(CMAKE_TRY_COMPILE%s)\n", projectLangs.c_str());
+ if (cmakeInternal == "ABI") {
+ // This is the ABI detection step, also used for implicit includes.
+ // Erase any include_directories() calls from the toolchain file so
+ // that we do not see them as implicit. Our ABI detection source
+ // does not include any system headers anyway.
+ fprintf(fout,
+ "set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES \"\")\n");
+ }
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";
+ for (std::string const& li : testLangs) {
+ std::string langFlags = "CMAKE_" + li + "_FLAGS";
const char* flags = this->Makefile->GetDefinition(langFlags);
- fprintf(fout, "set(CMAKE_%s_FLAGS %s)\n", li->c_str(),
+ fprintf(fout, "set(CMAKE_%s_FLAGS %s)\n", li.c_str(),
cmOutputConverter::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,
+ "set(CMAKE_%s_FLAGS \"${CMAKE_%s_FLAGS}"
+ " ${COMPILE_DEFINITIONS}\")\n",
+ li.c_str(), li.c_str());
}
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0066)) {
case cmPolicies::WARN:
@@ -507,7 +557,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
"(e.g. CMAKE_C_FLAGS_DEBUG) in the test project."
;
/* clang-format on */
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
case cmPolicies::OLD:
// OLD behavior is to do nothing.
@@ -515,7 +565,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0066));
CM_FALLTHROUGH;
case cmPolicies::NEW: {
@@ -523,9 +573,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
static std::string const cfgDefault = "DEBUG";
std::string const cfg =
!tcConfig.empty() ? cmSystemTools::UpperCase(tcConfig) : cfgDefault;
- for (std::set<std::string>::iterator li = testLangs.begin();
- li != testLangs.end(); ++li) {
- std::string const langFlagsCfg = "CMAKE_" + *li + "_FLAGS_" + cfg;
+ for (std::string const& li : testLangs) {
+ std::string const langFlagsCfg = "CMAKE_" + li + "_FLAGS_" + cfg;
const char* flagsCfg = this->Makefile->GetDefinition(langFlagsCfg);
fprintf(fout, "set(%s %s)\n", langFlagsCfg.c_str(),
cmOutputConverter::EscapeForCMake(flagsCfg ? flagsCfg : "")
@@ -545,7 +594,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
"in the test project."
;
/* clang-format on */
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
case cmPolicies::OLD:
// OLD behavior is to do nothing.
@@ -553,7 +602,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0056));
CM_FALLTHROUGH;
case cmPolicies::NEW:
@@ -568,14 +617,17 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
}
break;
}
- fprintf(fout, "set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS}"
- " ${EXE_LINKER_FLAGS}\")\n");
+ fprintf(fout,
+ "set(CMAKE_EXE_LINKER_FLAGS \"${CMAKE_EXE_LINKER_FLAGS}"
+ " ${EXE_LINKER_FLAGS}\")\n");
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.empty()) {
- fprintf(fout, "add_definitions(%s)\n", cmJoin(compileDefs, " ").c_str());
+ // Pass using bracket arguments to preserve content.
+ fprintf(fout, "add_definitions([==[%s]==])\n",
+ cmJoin(compileDefs, "]==] [==[").c_str());
}
/* Use a random file name to avoid rapid creation and deletion
@@ -585,12 +637,13 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
if (!targets.empty()) {
std::string fname = "/" + std::string(targetName) + "Targets.cmake";
- cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile);
+ cmExportTryCompileFileGenerator tcfg(gg, targets, this->Makefile,
+ testLangs);
tcfg.SetExportFile((this->BinaryDirectory + fname).c_str());
tcfg.SetConfig(tcConfig);
if (!tcfg.GenerateImportFile()) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"could not write export file.");
fclose(fout);
return -1;
@@ -617,6 +670,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
vars.insert(kCMAKE_SYSROOT_COMPILE);
vars.insert(kCMAKE_SYSROOT_LINK);
vars.insert(kCMAKE_WARN_DEPRECATED);
+ vars.emplace("CMAKE_MSVC_RUNTIME_LIBRARY"_s);
if (const char* varListStr = this->Makefile->GetDefinition(
kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES)) {
@@ -625,6 +679,16 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
vars.insert(varList.begin(), varList.end());
}
+ if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0083) ==
+ cmPolicies::NEW) {
+ // To ensure full support of PIE, propagate cache variables
+ // driving the link options
+ vars.insert(kCMAKE_C_LINK_PIE_SUPPORTED);
+ vars.insert(kCMAKE_C_LINK_NO_PIE_SUPPORTED);
+ vars.insert(kCMAKE_CXX_LINK_PIE_SUPPORTED);
+ vars.insert(kCMAKE_CXX_LINK_NO_PIE_SUPPORTED);
+ }
+
/* 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
@@ -636,15 +700,13 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES)) {
vars.erase(kCMAKE_OSX_ARCHITECTURES);
std::string flag = "-DCMAKE_OSX_ARCHITECTURES=" + std::string(tcArchs);
- cmakeFlags.push_back(flag);
+ cmakeFlags.push_back(std::move(flag));
}
- for (std::set<std::string>::iterator vi = vars.begin(); vi != vars.end();
- ++vi) {
- std::string const& var = *vi;
+ for (std::string const& var : vars) {
if (const char* val = this->Makefile->GetDefinition(var)) {
std::string flag = "-D" + var + "=" + val;
- cmakeFlags.push_back(flag);
+ cmakeFlags.push_back(std::move(flag));
}
}
}
@@ -656,6 +718,13 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
? "NEW"
: "OLD");
+ /* Set the appropriate policy information for PIE link flags */
+ fprintf(fout, "cmake_policy(SET CMP0083 %s)\n",
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0083) ==
+ cmPolicies::NEW
+ ? "NEW"
+ : "OLD");
+
if (targetType == cmStateEnums::EXECUTABLE) {
/* Put the executable at a known location (for COPY_FILE). */
fprintf(fout, "set(CMAKE_RUNTIME_OUTPUT_DIRECTORY \"%s\")\n",
@@ -670,13 +739,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
/* Create the actual static library. */
fprintf(fout, "add_library(%s STATIC", targetName.c_str());
}
- for (std::vector<std::string>::iterator si = sources.begin();
- si != sources.end(); ++si) {
- fprintf(fout, " \"%s\"", si->c_str());
+ for (std::string const& si : sources) {
+ fprintf(fout, " \"%s\"", si.c_str());
// Add dependencies on any non-temporary sources.
- if (si->find("CMakeTmp") == std::string::npos) {
- this->Makefile->AddCMakeDependFile(*si);
+ if (si.find("CMakeTmp") == std::string::npos) {
+ this->Makefile->AddCMakeDependFile(si);
}
}
fprintf(fout, ")\n");
@@ -704,7 +772,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0067));
case cmPolicies::NEW:
// NEW behavior is to honor the language standard variables.
@@ -763,11 +831,10 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
"is not honoring language standard variables in the test project:\n"
;
/* clang-format on */
- for (std::vector<std::string>::iterator vi = this->WarnCMP0067.begin();
- vi != this->WarnCMP0067.end(); ++vi) {
- w << " " << *vi << "\n";
+ for (std::string const& vi : this->WarnCMP0067) {
+ w << " " << vi << "\n";
}
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
if (testC) {
@@ -809,6 +876,23 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
}
}
+ if (!linkOptions.empty()) {
+ std::vector<std::string> options;
+ options.reserve(linkOptions.size());
+ for (const auto& option : linkOptions) {
+ options.emplace_back(cmOutputConverter::EscapeForCMake(option));
+ }
+
+ if (targetType == cmStateEnums::STATIC_LIBRARY) {
+ fprintf(fout,
+ "set_property(TARGET %s PROPERTY STATIC_LIBRARY_OPTIONS %s)\n",
+ targetName.c_str(), cmJoin(options, " ").c_str());
+ } else {
+ fprintf(fout, "target_link_options(%s PRIVATE %s)\n",
+ targetName.c_str(), cmJoin(options, " ").c_str());
+ }
+ }
+
if (useOldLinkLibs) {
fprintf(fout, "target_link_libraries(%s ${LINK_LIBRARIES})\n",
targetName.c_str());
@@ -820,13 +904,24 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
projectName = "CMAKE_TRY_COMPILE";
}
+ if (this->Makefile->GetState()->UseGhsMultiIDE()) {
+ // Forward the GHS variables to the inner project cache.
+ for (std::string const& var : ghs_platform_vars) {
+ if (const char* val = this->Makefile->GetDefinition(var)) {
+ std::string flag = "-D" + var + "=" + "'" + val + "'";
+ cmakeFlags.push_back(std::move(flag));
+ }
+ }
+ }
+
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);
+ this->SrcFileSignature, cmake::NO_BUILD_PARALLEL_LEVEL, &cmakeFlags,
+ output);
if (erroroc) {
cmSystemTools::SetErrorOccured();
}
@@ -855,10 +950,10 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
<< " '" << copyFile << "'\n";
/* clang-format on */
if (!this->FindErrorMessage.empty()) {
- emsg << this->FindErrorMessage.c_str();
+ emsg << this->FindErrorMessage;
}
if (copyFileError.empty()) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, emsg.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, emsg.str());
return -1;
}
copyFileErrorMessage = emsg.str();
@@ -873,17 +968,16 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
return res;
}
-void cmCoreTryCompile::CleanupFiles(const char* binDir)
+void cmCoreTryCompile::CleanupFiles(std::string const& binDir)
{
- if (!binDir) {
+ if (binDir.empty()) {
return;
}
- std::string bdir = binDir;
- if (bdir.find("CMakeTmp") == std::string::npos) {
+ if (binDir.find("CMakeTmp") == std::string::npos) {
cmSystemTools::Error(
"TRY_COMPILE attempt to remove -rf directory that does not contain "
- "CMakeTmp:",
+ "CMakeTmp:" +
binDir);
return;
}
@@ -898,7 +992,7 @@ void cmCoreTryCompile::CleanupFiles(const char* binDir)
std::string const fullPath =
std::string(binDir).append("/").append(fileName);
if (cmSystemTools::FileIsDirectory(fullPath)) {
- this->CleanupFiles(fullPath.c_str());
+ this->CleanupFiles(fullPath);
cmSystemTools::RemoveADirectory(fullPath);
} else {
#ifdef _WIN32
@@ -906,9 +1000,8 @@ void cmCoreTryCompile::CleanupFiles(const char* binDir)
// 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())) {
+ while (!cmSystemTools::RemoveFile(fullPath) && --retry.Count &&
+ cmSystemTools::FileExists(fullPath)) {
cmSystemTools::Delay(retry.Delay);
}
if (retry.Count == 0)
@@ -928,8 +1021,8 @@ void cmCoreTryCompile::CleanupFiles(const char* binDir)
void cmCoreTryCompile::FindOutputFile(const std::string& targetName,
cmStateEnums::TargetType targetType)
{
- this->FindErrorMessage = "";
- this->OutputFile = "";
+ this->FindErrorMessage.clear();
+ this->OutputFile.clear();
std::string tmpOutputFile = "/";
if (targetType == cmStateEnums::EXECUTABLE) {
tmpOutputFile += targetName;
@@ -947,7 +1040,7 @@ void cmCoreTryCompile::FindOutputFile(const std::string& targetName,
// 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("");
+ searchDirs.emplace_back();
const char* config =
this->Makefile->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
@@ -955,21 +1048,27 @@ void cmCoreTryCompile::FindOutputFile(const std::string& targetName,
if (config && config[0]) {
std::string tmp = "/";
tmp += config;
- searchDirs.push_back(tmp);
+ searchDirs.push_back(std::move(tmp));
}
- searchDirs.push_back("/Debug");
+ searchDirs.emplace_back("/Debug");
#if defined(__APPLE__)
- std::string app = "/Debug/" + targetName + ".app";
- searchDirs.push_back(app);
+ std::string app = "/" + targetName + ".app";
+ if (config && config[0]) {
+ std::string tmp = "/";
+ tmp += config + app;
+ searchDirs.push_back(std::move(tmp));
+ }
+ std::string tmp = "/Debug" + app;
+ searchDirs.emplace_back(std::move(tmp));
+ searchDirs.push_back(std::move(app));
#endif
- searchDirs.push_back("/Development");
+ searchDirs.emplace_back("/Development");
- for (std::vector<std::string>::const_iterator it = searchDirs.begin();
- it != searchDirs.end(); ++it) {
+ for (std::string const& sdir : searchDirs) {
std::string command = this->BinaryDirectory;
- command += *it;
+ command += sdir;
command += tmpOutputFile;
- if (cmSystemTools::FileExists(command.c_str())) {
+ if (cmSystemTools::FileExists(command)) {
this->OutputFile = cmSystemTools::CollapseFullPath(command);
return;
}
diff --git a/Source/cmCoreTryCompile.h b/Source/cmCoreTryCompile.h
index 365154dfb..ae714a63a 100644
--- a/Source/cmCoreTryCompile.h
+++ b/Source/cmCoreTryCompile.h
@@ -33,7 +33,7 @@ protected:
* This way we do not have to rely on the timing and
* dependencies of makefiles.
*/
- void CleanupFiles(const char* binDir);
+ void CleanupFiles(std::string const& binDir);
/**
* This tries to find the (executable) file created by
@@ -46,7 +46,7 @@ protected:
std::string BinaryDirectory;
std::string OutputFile;
std::string FindErrorMessage;
- bool SrcFileSignature;
+ bool SrcFileSignature = false;
private:
std::vector<std::string> WarnCMP0067;
diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx
index 69532e61b..b78493f99 100644
--- a/Source/cmCreateTestSourceList.cxx
+++ b/Source/cmCreateTestSourceList.cxx
@@ -136,8 +136,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& args,
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)) {
+ if (!this->Makefile->ConfigureFile(configFile, driver, false, true, false)) {
res = false;
}
diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h
index f1f1e4b8a..005b32c30 100644
--- a/Source/cmCreateTestSourceList.h
+++ b/Source/cmCreateTestSourceList.h
@@ -3,7 +3,7 @@
#ifndef cmCreateTestSourceList_h
#define cmCreateTestSourceList_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmCreateTestSourceList; }
+ cmCommand* Clone() override { return new cmCreateTestSourceList; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmCryptoHash.cxx b/Source/cmCryptoHash.cxx
index 7995b2cb3..d914eb142 100644
--- a/Source/cmCryptoHash.cxx
+++ b/Source/cmCryptoHash.cxx
@@ -2,11 +2,14 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCryptoHash.h"
+#include "cmAlgorithms.h"
#include "cm_kwiml.h"
#include "cm_rhash.h"
#include "cmsys/FStream.hxx"
#include <string.h>
+#include <memory> // IWYU pragma: keep
+
static unsigned int const cmCryptoHashAlgoToId[] = {
/* clang-format needs this comment to break after the opening brace */
RHASH_MD5, //
@@ -43,39 +46,39 @@ cmCryptoHash::~cmCryptoHash()
rhash_free(this->CTX);
}
-CM_AUTO_PTR<cmCryptoHash> cmCryptoHash::New(const char* algo)
+std::unique_ptr<cmCryptoHash> cmCryptoHash::New(const char* algo)
{
if (strcmp(algo, "MD5") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoMD5));
+ return cm::make_unique<cmCryptoHash>(AlgoMD5);
}
if (strcmp(algo, "SHA1") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA1));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA1);
}
if (strcmp(algo, "SHA224") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA224));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA224);
}
if (strcmp(algo, "SHA256") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA256));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA256);
}
if (strcmp(algo, "SHA384") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA384));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA384);
}
if (strcmp(algo, "SHA512") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA512));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA512);
}
if (strcmp(algo, "SHA3_224") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_224));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA3_224);
}
if (strcmp(algo, "SHA3_256") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_256));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA3_256);
}
if (strcmp(algo, "SHA3_384") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_384));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA3_384);
}
if (strcmp(algo, "SHA3_512") == 0) {
- return CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(AlgoSHA3_512));
+ return cm::make_unique<cmCryptoHash>(AlgoSHA3_512);
}
- return CM_AUTO_PTR<cmCryptoHash>(CM_NULLPTR);
+ return std::unique_ptr<cmCryptoHash>(nullptr);
}
bool cmCryptoHash::IntFromHexDigit(char input, char& output)
@@ -103,10 +106,9 @@ std::string cmCryptoHash::ByteHashToString(
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
std::string res;
- for (std::vector<unsigned char>::const_iterator vit = hash.begin();
- vit != hash.end(); ++vit) {
- res.push_back(hex[(*vit) >> 4]);
- res.push_back(hex[(*vit) & 0xF]);
+ for (unsigned char v : hash) {
+ res.push_back(hex[v >> 4]);
+ res.push_back(hex[v & 0xF]);
}
return res;
}
diff --git a/Source/cmCryptoHash.h b/Source/cmCryptoHash.h
index c380d85ff..b712f09da 100644
--- a/Source/cmCryptoHash.h
+++ b/Source/cmCryptoHash.h
@@ -3,21 +3,18 @@
#ifndef cmCryptoHash_h
#define cmCryptoHash_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include <memory> // IWYU pragma: keep
#include <stddef.h>
#include <string>
#include <vector>
-#include "cm_auto_ptr.hxx"
-
/**
* @brief Abstract base class for cryptographic hash generators
*/
class cmCryptoHash
{
- CM_DISABLE_COPY(cmCryptoHash)
-
public:
enum Algo
{
@@ -36,13 +33,16 @@ public:
cmCryptoHash(Algo algo);
~cmCryptoHash();
+ cmCryptoHash(cmCryptoHash const&) = delete;
+ cmCryptoHash& operator=(cmCryptoHash const&) = delete;
+
/// @brief Returns a new hash generator of the requested type
/// @arg algo Hash type name. Supported hash types are
/// MD5, SHA1, SHA224, SHA256, SHA384, SHA512,
/// SHA3_224, SHA3_256, SHA3_384, SHA3_512
/// @return A valid auto pointer if algo is supported or
/// an invalid/NULL pointer otherwise
- static CM_AUTO_PTR<cmCryptoHash> New(const char* algo);
+ static std::unique_ptr<cmCryptoHash> New(const char* algo);
/// @brief Converts a hex character to its binary value (4 bits)
/// @arg input Hex character [0-9a-fA-F].
diff --git a/Source/cmCurl.cxx b/Source/cmCurl.cxx
index 341b8c077..0004f666b 100644
--- a/Source/cmCurl.cxx
+++ b/Source/cmCurl.cxx
@@ -2,25 +2,25 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCurl.h"
-#include "cmThirdParty.h"
-
#if !defined(CMAKE_USE_SYSTEM_CURL) && !defined(_WIN32) && \
!defined(__APPLE__) && !defined(CURL_CA_BUNDLE) && !defined(CURL_CA_PATH)
-#define CMAKE_FIND_CAFILE
-#include "cmSystemTools.h"
+# define CMAKE_FIND_CAFILE
+# include "cmSystemTools.h"
#endif
// curl versions before 7.21.5 did not provide this error code
#if defined(LIBCURL_VERSION_NUM) && LIBCURL_VERSION_NUM < 0x071505
-#define CURLE_NOT_BUILT_IN 4
+# define CURLE_NOT_BUILT_IN 4
#endif
#define check_curl_result(result, errstr) \
- if ((result) != CURLE_OK && (result) != CURLE_NOT_BUILT_IN) { \
- e += e.empty() ? "" : "\n"; \
- e += (errstr); \
- e += ::curl_easy_strerror(result); \
- }
+ do { \
+ if ((result) != CURLE_OK && (result) != CURLE_NOT_BUILT_IN) { \
+ e += e.empty() ? "" : "\n"; \
+ e += (errstr); \
+ e += ::curl_easy_strerror(result); \
+ } \
+ } while (false)
std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile)
{
@@ -30,29 +30,67 @@ std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile)
check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
}
#ifdef CMAKE_FIND_CAFILE
-#define CMAKE_CAFILE_FEDORA "/etc/pki/tls/certs/ca-bundle.crt"
+# define CMAKE_CAFILE_FEDORA "/etc/pki/tls/certs/ca-bundle.crt"
else if (cmSystemTools::FileExists(CMAKE_CAFILE_FEDORA, true)) {
::CURLcode res =
::curl_easy_setopt(curl, CURLOPT_CAINFO, CMAKE_CAFILE_FEDORA);
check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
}
-#undef CMAKE_CAFILE_FEDORA
+# undef CMAKE_CAFILE_FEDORA
else {
-#define CMAKE_CAFILE_COMMON "/etc/ssl/certs/ca-certificates.crt"
+# define CMAKE_CAFILE_COMMON "/etc/ssl/certs/ca-certificates.crt"
if (cmSystemTools::FileExists(CMAKE_CAFILE_COMMON, true)) {
::CURLcode res =
::curl_easy_setopt(curl, CURLOPT_CAINFO, CMAKE_CAFILE_COMMON);
check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
}
-#undef CMAKE_CAFILE_COMMON
-#define CMAKE_CAPATH_COMMON "/etc/ssl/certs"
+# undef CMAKE_CAFILE_COMMON
+# define CMAKE_CAPATH_COMMON "/etc/ssl/certs"
if (cmSystemTools::FileIsDirectory(CMAKE_CAPATH_COMMON)) {
::CURLcode res =
::curl_easy_setopt(curl, CURLOPT_CAPATH, CMAKE_CAPATH_COMMON);
check_curl_result(res, "Unable to set TLS/SSL Verify CAPATH: ");
}
-#undef CMAKE_CAPATH_COMMON
+# undef CMAKE_CAPATH_COMMON
}
#endif
return e;
}
+
+std::string cmCurlSetNETRCOption(::CURL* curl, const std::string& netrc_level,
+ const std::string& netrc_file)
+{
+ std::string e;
+ CURL_NETRC_OPTION curl_netrc_level = CURL_NETRC_LAST;
+ ::CURLcode res;
+
+ if (!netrc_level.empty()) {
+ if (netrc_level == "OPTIONAL") {
+ curl_netrc_level = CURL_NETRC_OPTIONAL;
+ } else if (netrc_level == "REQUIRED") {
+ curl_netrc_level = CURL_NETRC_REQUIRED;
+ } else if (netrc_level == "IGNORED") {
+ curl_netrc_level = CURL_NETRC_IGNORED;
+ } else {
+ e = "NETRC accepts OPTIONAL, IGNORED or REQUIRED but got: ";
+ e += netrc_level;
+ return e;
+ }
+ }
+
+ if (curl_netrc_level != CURL_NETRC_LAST &&
+ curl_netrc_level != CURL_NETRC_IGNORED) {
+ res = ::curl_easy_setopt(curl, CURLOPT_NETRC, curl_netrc_level);
+ check_curl_result(res, "Unable to set netrc level: ");
+ if (!e.empty()) {
+ return e;
+ }
+
+ // check to see if a .netrc file has been specified
+ if (!netrc_file.empty()) {
+ res = ::curl_easy_setopt(curl, CURLOPT_NETRC_FILE, netrc_file.c_str());
+ check_curl_result(res, "Unable to set .netrc file path : ");
+ }
+ }
+ return e;
+}
diff --git a/Source/cmCurl.h b/Source/cmCurl.h
index a2fa4b1c0..fe7eb809f 100644
--- a/Source/cmCurl.h
+++ b/Source/cmCurl.h
@@ -3,11 +3,13 @@
#ifndef cmCurl_h
#define cmCurl_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cm_curl.h"
#include <string>
-std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile = CM_NULLPTR);
+std::string cmCurlSetCAInfo(::CURL* curl, const char* cafile = nullptr);
+std::string cmCurlSetNETRCOption(::CURL* curl, const std::string& netrc_level,
+ const std::string& netrc_file);
#endif
diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx
index 5e377b574..7402eeb37 100644
--- a/Source/cmCustomCommand.cxx
+++ b/Source/cmCustomCommand.cxx
@@ -2,38 +2,25 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCustomCommand.h"
+#include "cmAlgorithms.h"
#include "cmMakefile.h"
-#include "cmConfigure.h"
-
-cmCustomCommand::cmCustomCommand()
- : Backtrace()
-{
- this->HaveComment = false;
- this->EscapeOldStyle = true;
- this->EscapeAllowMakeVars = false;
- this->UsesTerminal = false;
- this->CommandExpandLists = false;
-}
+#include <utility>
cmCustomCommand::cmCustomCommand(cmMakefile const* mf,
- const std::vector<std::string>& outputs,
- const std::vector<std::string>& byproducts,
- const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines,
+ std::vector<std::string> outputs,
+ std::vector<std::string> byproducts,
+ std::vector<std::string> depends,
+ cmCustomCommandLines commandLines,
const char* comment,
const char* workingDirectory)
- : Outputs(outputs)
- , Byproducts(byproducts)
- , Depends(depends)
- , CommandLines(commandLines)
- , Backtrace()
+ : Outputs(std::move(outputs))
+ , Byproducts(std::move(byproducts))
+ , Depends(std::move(depends))
+ , CommandLines(std::move(commandLines))
, Comment(comment ? comment : "")
, WorkingDirectory(workingDirectory ? workingDirectory : "")
- , HaveComment(comment != CM_NULLPTR)
- , EscapeAllowMakeVars(false)
- , EscapeOldStyle(true)
- , CommandExpandLists(false)
+ , HaveComment(comment != nullptr)
{
if (mf) {
this->Backtrace = mf->GetBacktrace();
@@ -62,19 +49,18 @@ const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const
const char* cmCustomCommand::GetComment() const
{
- const char* no_comment = CM_NULLPTR;
+ const char* no_comment = nullptr;
return this->HaveComment ? this->Comment.c_str() : no_comment;
}
void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines)
{
- this->CommandLines.insert(this->CommandLines.end(), commandLines.begin(),
- commandLines.end());
+ cmAppend(this->CommandLines, commandLines);
}
void cmCustomCommand::AppendDepends(const std::vector<std::string>& depends)
{
- this->Depends.insert(this->Depends.end(), depends.begin(), depends.end());
+ cmAppend(this->Depends, depends);
}
bool cmCustomCommand::GetEscapeOldStyle() const
@@ -115,8 +101,7 @@ void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l)
void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
{
- this->ImplicitDepends.insert(this->ImplicitDepends.end(), l.begin(),
- l.end());
+ cmAppend(this->ImplicitDepends, l);
}
bool cmCustomCommand::GetUsesTerminal() const
@@ -148,3 +133,13 @@ void cmCustomCommand::SetDepfile(const std::string& depfile)
{
this->Depfile = depfile;
}
+
+const std::string& cmCustomCommand::GetJobPool() const
+{
+ return this->JobPool;
+}
+
+void cmCustomCommand::SetJobPool(const std::string& job_pool)
+{
+ this->JobPool = job_pool;
+}
diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h
index 9e82f2505..9a6f2390c 100644
--- a/Source/cmCustomCommand.h
+++ b/Source/cmCustomCommand.h
@@ -22,16 +22,12 @@ class cmMakefile;
class cmCustomCommand
{
public:
- /** Default and copy constructors for STL containers. */
- cmCustomCommand();
-
/** Main constructor specifies all information for the command. */
- cmCustomCommand(cmMakefile const* mf,
- const std::vector<std::string>& outputs,
- const std::vector<std::string>& byproducts,
- const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines,
- const char* comment, const char* workingDirectory);
+ cmCustomCommand(cmMakefile const* mf, std::vector<std::string> outputs,
+ std::vector<std::string> byproducts,
+ std::vector<std::string> depends,
+ cmCustomCommandLines commandLines, const char* comment,
+ const char* workingDirectory);
/** Get the output file produced by the command. */
const std::vector<std::string>& GetOutputs() const;
@@ -93,6 +89,10 @@ public:
const std::string& GetDepfile() const;
void SetDepfile(const std::string& depfile);
+ /** Set/Get the job_pool (used by the Ninja generator) */
+ const std::string& GetJobPool() const;
+ void SetJobPool(const std::string& job_pool);
+
private:
std::vector<std::string> Outputs;
std::vector<std::string> Byproducts;
@@ -103,11 +103,12 @@ private:
std::string Comment;
std::string WorkingDirectory;
std::string Depfile;
- bool HaveComment;
- bool EscapeAllowMakeVars;
- bool EscapeOldStyle;
- bool UsesTerminal;
- bool CommandExpandLists;
+ std::string JobPool;
+ bool HaveComment = false;
+ bool EscapeAllowMakeVars = false;
+ bool EscapeOldStyle = true;
+ bool UsesTerminal = false;
+ bool CommandExpandLists = false;
};
#endif
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index 67213ecaa..fe228ff2d 100644
--- a/Source/cmCustomCommandGenerator.cxx
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -2,48 +2,82 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCustomCommandGenerator.h"
+#include "cmAlgorithms.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
-#include "cmOutputConverter.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-#include "cmConfigure.h"
+#include <memory> // IWYU pragma: keep
+#include <stddef.h>
+#include <utility>
cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
- const std::string& config,
+ std::string config,
cmLocalGenerator* lg)
: CC(cc)
- , Config(config)
+ , Config(std::move(config))
, LG(lg)
, OldStyle(cc.GetEscapeOldStyle())
, MakeVars(cc.GetEscapeAllowMakeVars())
, GE(new cmGeneratorExpression(cc.GetBacktrace()))
- , DependsDone(false)
+ , EmulatorsWithArguments(cc.GetCommandLines().size())
{
const cmCustomCommandLines& cmdlines = this->CC.GetCommandLines();
- for (cmCustomCommandLines::const_iterator cmdline = cmdlines.begin();
- cmdline != cmdlines.end(); ++cmdline) {
+ for (cmCustomCommandLine const& cmdline : cmdlines) {
cmCustomCommandLine argv;
- for (cmCustomCommandLine::const_iterator clarg = cmdline->begin();
- clarg != cmdline->end(); ++clarg) {
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = this->GE->Parse(*clarg);
+ for (std::string const& clarg : cmdline) {
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ this->GE->Parse(clarg);
std::string parsed_arg = cge->Evaluate(this->LG, this->Config);
if (this->CC.GetCommandExpandLists()) {
- std::vector<std::string> ExpandedArg;
- cmSystemTools::ExpandListArgument(parsed_arg, ExpandedArg);
- argv.insert(argv.end(), ExpandedArg.begin(), ExpandedArg.end());
+ cmAppend(argv, cmSystemTools::ExpandedListArgument(parsed_arg));
} else {
- argv.push_back(parsed_arg);
+ argv.push_back(std::move(parsed_arg));
}
}
- this->CommandLines.push_back(argv);
+
+ // Later code assumes at least one entry exists, but expanding
+ // lists on an empty command may have left this empty.
+ // FIXME: Should we define behavior for removing empty commands?
+ if (argv.empty()) {
+ argv.push_back(std::string());
+ }
+
+ this->CommandLines.push_back(std::move(argv));
+ }
+
+ std::vector<std::string> depends = this->CC.GetDepends();
+ for (std::string const& d : depends) {
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = this->GE->Parse(d);
+ std::vector<std::string> result = cmSystemTools::ExpandedListArgument(
+ cge->Evaluate(this->LG, this->Config));
+ for (std::string& it : result) {
+ if (cmSystemTools::FileIsFullPath(it)) {
+ it = cmSystemTools::CollapseFullPath(it);
+ }
+ }
+ cmAppend(this->Depends, result);
+ }
+
+ const std::string& workingdirectory = this->CC.GetWorkingDirectory();
+ if (!workingdirectory.empty()) {
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ this->GE->Parse(workingdirectory);
+ this->WorkingDirectory = cge->Evaluate(this->LG, this->Config);
+ // Convert working directory to a full path.
+ if (!this->WorkingDirectory.empty()) {
+ std::string const& build_dir = this->LG->GetCurrentBinaryDirectory();
+ this->WorkingDirectory =
+ cmSystemTools::CollapseFullPath(this->WorkingDirectory, build_dir);
+ }
}
+
+ this->FillEmulatorsWithArguments();
}
cmCustomCommandGenerator::~cmCustomCommandGenerator()
@@ -56,19 +90,37 @@ unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const
return static_cast<unsigned int>(this->CC.GetCommandLines().size());
}
-const char* cmCustomCommandGenerator::GetCrossCompilingEmulator(
- unsigned int c) const
+void cmCustomCommandGenerator::FillEmulatorsWithArguments()
{
if (!this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING")) {
- return CM_NULLPTR;
+ return;
}
- std::string const& argv0 = this->CommandLines[c][0];
- cmGeneratorTarget* target = this->LG->FindGeneratorTargetToUse(argv0);
- if (target && target->GetType() == cmStateEnums::EXECUTABLE &&
- !target->IsImported()) {
- return target->GetProperty("CROSSCOMPILING_EMULATOR");
+
+ for (unsigned int c = 0; c < this->GetNumberOfCommands(); ++c) {
+ std::string const& argv0 = this->CommandLines[c][0];
+ cmGeneratorTarget* target = this->LG->FindGeneratorTargetToUse(argv0);
+ if (target && target->GetType() == cmStateEnums::EXECUTABLE &&
+ !target->IsImported()) {
+
+ const char* emulator_property =
+ target->GetProperty("CROSSCOMPILING_EMULATOR");
+ if (!emulator_property) {
+ continue;
+ }
+
+ cmSystemTools::ExpandListArgument(emulator_property,
+ this->EmulatorsWithArguments[c]);
+ }
}
- return CM_NULLPTR;
+}
+
+std::vector<std::string> cmCustomCommandGenerator::GetCrossCompilingEmulator(
+ unsigned int c) const
+{
+ if (c >= this->EmulatorsWithArguments.size()) {
+ return std::vector<std::string>();
+ }
+ return this->EmulatorsWithArguments[c];
}
const char* cmCustomCommandGenerator::GetArgv0Location(unsigned int c) const
@@ -81,13 +133,26 @@ const char* cmCustomCommandGenerator::GetArgv0Location(unsigned int c) const
!this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING"))) {
return target->GetLocation(this->Config);
}
- return CM_NULLPTR;
+ return nullptr;
+}
+
+bool cmCustomCommandGenerator::HasOnlyEmptyCommandLines() const
+{
+ for (size_t i = 0; i < this->CommandLines.size(); ++i) {
+ for (size_t j = 0; j < this->CommandLines[i].size(); ++j) {
+ if (!this->CommandLines[i][j].empty()) {
+ return false;
+ }
+ }
+ }
+ return true;
}
std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
{
- if (const char* emulator = this->GetCrossCompilingEmulator(c)) {
- return std::string(emulator);
+ std::vector<std::string> emulator = this->GetCrossCompilingEmulator(c);
+ if (!emulator.empty()) {
+ return emulator[0];
}
if (const char* location = this->GetArgv0Location(c)) {
return std::string(location);
@@ -125,14 +190,24 @@ void cmCustomCommandGenerator::AppendArguments(unsigned int c,
std::string& cmd) const
{
unsigned int offset = 1;
- if (this->GetCrossCompilingEmulator(c) != CM_NULLPTR) {
+ std::vector<std::string> emulator = this->GetCrossCompilingEmulator(c);
+ if (!emulator.empty()) {
+ for (unsigned j = 1; j < emulator.size(); ++j) {
+ cmd += " ";
+ if (this->OldStyle) {
+ cmd += escapeForShellOldStyle(emulator[j]);
+ } else {
+ cmd += this->LG->EscapeForShell(emulator[j], this->MakeVars);
+ }
+ }
+
offset = 0;
}
+
cmCustomCommandLine const& commandLine = this->CommandLines[c];
for (unsigned int j = offset; j < commandLine.size(); ++j) {
std::string arg;
- if (const char* location =
- j == 0 ? this->GetArgv0Location(c) : CM_NULLPTR) {
+ if (const char* location = j == 0 ? this->GetArgv0Location(c) : nullptr) {
// GetCommand returned the emulator instead of the argv0 location,
// so transform the latter now.
arg = location;
@@ -143,8 +218,7 @@ void cmCustomCommandGenerator::AppendArguments(unsigned int c,
if (this->OldStyle) {
cmd += escapeForShellOldStyle(arg);
} else {
- cmOutputConverter converter(this->LG->GetStateSnapshot());
- cmd += converter.EscapeForShell(arg, this->MakeVars);
+ cmd += this->LG->EscapeForShell(arg, this->MakeVars);
}
}
}
@@ -156,7 +230,7 @@ const char* cmCustomCommandGenerator::GetComment() const
std::string cmCustomCommandGenerator::GetWorkingDirectory() const
{
- return this->CC.GetWorkingDirectory();
+ return this->WorkingDirectory;
}
std::vector<std::string> const& cmCustomCommandGenerator::GetOutputs() const
@@ -171,23 +245,5 @@ std::vector<std::string> const& cmCustomCommandGenerator::GetByproducts() const
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) {
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = this->GE->Parse(*i);
- std::vector<std::string> result;
- cmSystemTools::ExpandListArgument(cge->Evaluate(this->LG, 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
index 0a2adb524..766f4b81d 100644
--- a/Source/cmCustomCommandGenerator.h
+++ b/Source/cmCustomCommandGenerator.h
@@ -21,17 +21,22 @@ class cmCustomCommandGenerator
bool OldStyle;
bool MakeVars;
cmGeneratorExpression* GE;
- mutable bool DependsDone;
- mutable std::vector<std::string> Depends;
cmCustomCommandLines CommandLines;
+ std::vector<std::vector<std::string>> EmulatorsWithArguments;
+ std::vector<std::string> Depends;
+ std::string WorkingDirectory;
- const char* GetCrossCompilingEmulator(unsigned int c) const;
+ void FillEmulatorsWithArguments();
+ std::vector<std::string> GetCrossCompilingEmulator(unsigned int c) const;
const char* GetArgv0Location(unsigned int c) const;
public:
- cmCustomCommandGenerator(cmCustomCommand const& cc,
- const std::string& config, cmLocalGenerator* lg);
+ cmCustomCommandGenerator(cmCustomCommand const& cc, std::string config,
+ cmLocalGenerator* lg);
~cmCustomCommandGenerator();
+ cmCustomCommandGenerator(const cmCustomCommandGenerator&) = delete;
+ cmCustomCommandGenerator& operator=(const cmCustomCommandGenerator&) =
+ delete;
cmCustomCommand const& GetCC() const { return this->CC; }
unsigned int GetNumberOfCommands() const;
std::string GetCommand(unsigned int c) const;
@@ -41,6 +46,7 @@ public:
std::vector<std::string> const& GetOutputs() const;
std::vector<std::string> const& GetByproducts() const;
std::vector<std::string> const& GetDepends() const;
+ bool HasOnlyEmptyCommandLines() const;
};
#endif
diff --git a/Source/cmDefinePropertyCommand.h b/Source/cmDefinePropertyCommand.h
index bc120c564..a9c185618 100644
--- a/Source/cmDefinePropertyCommand.h
+++ b/Source/cmDefinePropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmDefinesPropertyCommand_h
#define cmDefinesPropertyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,14 +15,14 @@ class cmExecutionStatus;
class cmDefinePropertyCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmDefinePropertyCommand; }
+ cmCommand* Clone() override { return new cmDefinePropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
std::string PropertyName;
diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 7aa7641e1..5fafaf943 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDefinitions.h"
-#include "cmConfigure.h"
#include <assert.h>
#include <set>
#include <utility>
@@ -31,11 +30,11 @@ cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key,
return begin->Map.insert(MapType::value_type(key, def)).first->second;
}
-const char* cmDefinitions::Get(const std::string& key, StackIter begin,
- StackIter end)
+const std::string* cmDefinitions::Get(const std::string& key, StackIter begin,
+ StackIter end)
{
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
- return def.Exists ? def.c_str() : CM_NULLPTR;
+ return def.Exists ? &def : nullptr;
}
void cmDefinitions::Raise(const std::string& key, StackIter begin,
@@ -67,10 +66,9 @@ std::vector<std::string> cmDefinitions::UnusedKeys() const
std::vector<std::string> keys;
keys.reserve(this->Map.size());
// Consider local definitions.
- for (MapType::const_iterator mi = this->Map.begin(); mi != this->Map.end();
- ++mi) {
- if (!mi->second.Used) {
- keys.push_back(mi->first);
+ for (auto const& mi : this->Map) {
+ if (!mi.second.Used) {
+ keys.push_back(mi.first);
}
}
return keys;
@@ -82,15 +80,14 @@ cmDefinitions cmDefinitions::MakeClosure(StackIter begin, StackIter end)
std::set<std::string> undefined;
for (StackIter it = begin; it != end; ++it) {
// Consider local definitions.
- for (MapType::const_iterator mi = it->Map.begin(); mi != it->Map.end();
- ++mi) {
+ for (auto const& mi : it->Map) {
// Use this key if it is not already set or unset.
- if (closure.Map.find(mi->first) == closure.Map.end() &&
- undefined.find(mi->first) == undefined.end()) {
- if (mi->second.Exists) {
- closure.Map.insert(*mi);
+ if (closure.Map.find(mi.first) == closure.Map.end() &&
+ undefined.find(mi.first) == undefined.end()) {
+ if (mi.second.Exists) {
+ closure.Map.insert(mi);
} else {
- undefined.insert(mi->first);
+ undefined.insert(mi.first);
}
}
}
@@ -106,11 +103,10 @@ std::vector<std::string> cmDefinitions::ClosureKeys(StackIter begin,
for (StackIter it = begin; it != end; ++it) {
defined.reserve(defined.size() + it->Map.size());
- for (MapType::const_iterator mi = it->Map.begin(); mi != it->Map.end();
- ++mi) {
+ for (auto const& mi : it->Map) {
// Use this key if it is not already set or unset.
- if (bound.insert(mi->first).second && mi->second.Exists) {
- defined.push_back(mi->first);
+ if (bound.insert(mi.first).second && mi.second.Exists) {
+ defined.push_back(mi.first);
}
}
}
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index ddb89188c..6c252bee5 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -6,10 +6,10 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
+#include <unordered_map>
#include <vector>
#include "cmLinkedTree.h"
-#include "cm_unordered_map.hxx"
/** \class cmDefinitions
* \brief Store a scope of variable definitions for CMake language.
@@ -23,8 +23,8 @@ class cmDefinitions
typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
public:
- static const char* Get(const std::string& key, StackIter begin,
- StackIter end);
+ static const std::string* Get(const std::string& key, StackIter begin,
+ StackIter end);
static void Raise(const std::string& key, StackIter begin, StackIter end);
@@ -47,30 +47,23 @@ private:
typedef std::string std_string;
public:
- Def()
- : std_string()
- , Exists(false)
- , Used(false)
- {
- }
+ Def() = default;
Def(const char* v)
: std_string(v ? v : "")
, Exists(v ? true : false)
- , Used(false)
{
}
Def(const std_string& v)
: std_string(v)
, Exists(true)
- , Used(false)
{
}
- bool Exists;
- bool Used;
+ bool Exists = false;
+ bool Used = false;
};
static Def NoDef;
- typedef CM_UNORDERED_MAP<std::string, Def> MapType;
+ typedef std::unordered_map<std::string, Def> MapType;
MapType Map;
static Def const& GetInternal(const std::string& key, StackIter begin,
diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx
index c898d12ba..ed76dbf47 100644
--- a/Source/cmDepends.cxx
+++ b/Source/cmDepends.cxx
@@ -2,63 +2,50 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDepends.h"
-#include "cmFileTimeComparison.h"
+#include "cmFileTime.h"
+#include "cmFileTimeCache.h"
#include "cmGeneratedFileStream.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
-#include "cmWorkingDirectory.h"
#include "cmsys/FStream.hxx"
#include <sstream>
-#include <string.h>
#include <utility>
-cmDepends::cmDepends(cmLocalGenerator* lg, const char* targetDir)
- : CompileDirectory()
- , LocalGenerator(lg)
- , Verbose(false)
- , FileComparison(CM_NULLPTR)
- , TargetDirectory(targetDir)
- , MaxPath(16384)
- , Dependee(new char[MaxPath])
- , Depender(new char[MaxPath])
+cmDepends::cmDepends(cmLocalGenerator* lg, std::string targetDir)
+ : LocalGenerator(lg)
+ , TargetDirectory(std::move(targetDir))
{
}
-cmDepends::~cmDepends()
-{
- delete[] this->Dependee;
- delete[] this->Depender;
-}
+cmDepends::~cmDepends() = default;
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::map<std::string, std::set<std::string>> dependencies;
+ {
+ // Lookup the set of sources to scan.
+ std::vector<std::string> pairs;
+ {
+ std::string const srcLang = "CMAKE_DEPENDS_CHECK_" + this->Language;
+ cmMakefile* mf = this->LocalGenerator->GetMakefile();
+ cmSystemTools::ExpandListArgument(mf->GetSafeDefinition(srcLang), pairs);
+ }
+ 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);
}
- 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) {
-
+ for (auto const& d : dependencies) {
// Write the dependencies for this pair.
- if (!this->WriteDependencies(it->second, it->first, makeDepends,
+ if (!this->WriteDependencies(d.second, d.first, makeDepends,
internalDepends)) {
return false;
}
@@ -72,32 +59,30 @@ bool cmDepends::Finalize(std::ostream& /*unused*/, std::ostream& /*unused*/)
return true;
}
-bool cmDepends::Check(const char* makeFile, const char* internalFile,
- std::map<std::string, DependencyVector>& validDeps)
+bool cmDepends::Check(const std::string& makeFile,
+ const std::string& internalFile,
+ DependencyMap& validDeps)
{
- // Dependency checks must be done in proper working directory.
- cmWorkingDirectory workdir(this->CompileDirectory);
-
// Check whether dependencies must be regenerated.
bool okay = true;
- cmsys::ifstream fin(internalFile);
+ cmsys::ifstream fin(internalFile.c_str());
if (!(fin && this->CheckDependencies(fin, internalFile, validDeps))) {
// Clear all dependencies so they will be regenerated.
this->Clear(makeFile);
cmSystemTools::RemoveFile(internalFile);
+ this->FileTimeCache->Remove(internalFile);
okay = false;
}
-
return okay;
}
-void cmDepends::Clear(const char* file)
+void cmDepends::Clear(const std::string& file)
{
// Print verbose output.
if (this->Verbose) {
std::ostringstream msg;
msg << "Clearing dependencies in \"" << file << "\"." << std::endl;
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
// Write an empty dependency file.
@@ -116,48 +101,62 @@ bool cmDepends::WriteDependencies(const std::set<std::string>& /*unused*/,
return false;
}
-bool cmDepends::CheckDependencies(
- std::istream& internalDepends, const char* internalDependsFileName,
- std::map<std::string, DependencyVector>& validDeps)
+bool cmDepends::CheckDependencies(std::istream& internalDepends,
+ const std::string& internalDependsFileName,
+ DependencyMap& validDeps)
{
+ // Read internal depends file time
+ cmFileTime internalDependsTime;
+ if (!this->FileTimeCache->Load(internalDependsFileName,
+ internalDependsTime)) {
+ return false;
+ }
+
// 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 = CM_NULLPTR;
- while (internalDepends.getline(this->Dependee, this->MaxPath)) {
- if (this->Dependee[0] == 0 || this->Dependee[0] == '#' ||
- this->Dependee[0] == '\r') {
+ std::string line;
+ line.reserve(1024);
+ std::string depender;
+ std::string dependee;
+ cmFileTime dependerTime;
+ cmFileTime dependeeTime;
+ std::vector<std::string>* currentDependencies = nullptr;
+
+ while (std::getline(internalDepends, line)) {
+ // Check if this an empty or a comment line
+ if (line.empty() || line.front() == '#') {
continue;
}
- size_t len = internalDepends.gcount() - 1;
- if (this->Dependee[len - 1] == '\r') {
- len--;
- this->Dependee[len] = 0;
+ // Drop carriage return character at the end
+ if (line.back() == '\r') {
+ line.pop_back();
+ if (line.empty()) {
+ continue;
+ }
}
- 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);
+ // Check if this a depender line
+ if (line.front() != ' ') {
+ depender = line;
+ dependerExists = this->FileTimeCache->Load(depender, dependerTime);
// 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];
+ currentDependencies = &validDeps[depender];
continue;
}
- /*
- // Parse the dependency line.
- if(!this->ParseDependency(line.c_str()))
- {
- continue;
- }
- */
+
+ // This is a dependee line
+ dependee = line.substr(1);
+
+ // Add dependee to depender's list
+ if (currentDependencies != nullptr) {
+ currentDependencies->push_back(dependee);
+ }
// Dependencies must be regenerated
// * if the dependee does not exist
@@ -165,13 +164,8 @@ bool cmDepends::CheckDependencies(
// * 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 != CM_NULLPTR) {
- currentDependencies->push_back(dependee);
- }
-
- if (!cmSystemTools::FileExists(dependee)) {
+ bool dependeeExists = this->FileTimeCache->Load(dependee, dependeeTime);
+ if (!dependeeExists) {
// The dependee does not exist.
regenerate = true;
@@ -180,61 +174,55 @@ bool cmDepends::CheckDependencies(
std::ostringstream msg;
msg << "Dependee \"" << dependee << "\" does not exist for depender \""
<< depender << "\"." << std::endl;
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.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) {
- std::ostringstream msg;
- msg << "Dependee \"" << dependee << "\" is newer than depender \""
- << depender << "\"." << std::endl;
- cmSystemTools::Stdout(msg.str().c_str());
- }
+ } else if (dependerExists) {
+ // The dependee and depender both exist. Compare file times.
+ if (dependerTime.Older(dependeeTime)) {
+ // The depender is older than the dependee.
+ regenerate = true;
+
+ // Print verbose output.
+ if (this->Verbose) {
+ std::ostringstream msg;
+ msg << "Dependee \"" << dependee << "\" is newer than depender \""
+ << depender << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.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) {
- std::ostringstream msg;
- msg << "Dependee \"" << dependee
- << "\" is newer than depends file \""
- << internalDependsFileName << "\"." << 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.
+ if (internalDependsTime.Older(dependeeTime)) {
+ // The depends-file is older than the dependee.
+ regenerate = true;
+
+ // Print verbose output.
+ if (this->Verbose) {
+ std::ostringstream msg;
+ msg << "Dependee \"" << dependee
+ << "\" is newer than depends file \"" << internalDependsFileName
+ << "\"." << std::endl;
+ cmSystemTools::Stdout(msg.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 != CM_NULLPTR) {
- validDeps.erase(this->Depender);
- currentDependencies = CM_NULLPTR;
+ if (currentDependencies != nullptr) {
+ validDeps.erase(depender);
+ currentDependencies = nullptr;
}
// Remove the depender to be sure it is rebuilt.
if (dependerExists) {
cmSystemTools::RemoveFile(depender);
+ this->FileTimeCache->Remove(depender);
dependerExists = false;
}
}
@@ -246,7 +234,7 @@ bool cmDepends::CheckDependencies(
void cmDepends::SetIncludePathFromLanguage(const std::string& lang)
{
// Look for the new per "TARGET_" variant first:
- const char* includePath = CM_NULLPTR;
+ const char* includePath = nullptr;
std::string includePathVar = "CMAKE_";
includePathVar += lang;
includePathVar += "_TARGET_INCLUDE_PATH";
diff --git a/Source/cmDepends.h b/Source/cmDepends.h
index b33feb902..b7475f0ae 100644
--- a/Source/cmDepends.h
+++ b/Source/cmDepends.h
@@ -3,16 +3,15 @@
#ifndef cmDepends_h
#define cmDepends_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
#include <set>
-#include <stddef.h>
#include <string>
#include <vector>
-class cmFileTimeComparison;
+class cmFileTimeCache;
class cmLocalGenerator;
/** \class cmDepends
@@ -24,15 +23,16 @@ class cmLocalGenerator;
*/
class cmDepends
{
- CM_DISABLE_COPY(cmDepends)
+public:
+ typedef std::map<std::string, std::vector<std::string>> DependencyMap;
public:
/** Instances need to know the build directory name and the relative
path from the build directory to the target file. */
- cmDepends(cmLocalGenerator* lg = CM_NULLPTR, const char* targetDir = "");
+ cmDepends(cmLocalGenerator* lg = nullptr, std::string targetDir = "");
- /** at what level will the compile be done from */
- void SetCompileDirectory(const char* dir) { this->CompileDirectory = dir; }
+ cmDepends(cmDepends const&) = delete;
+ cmDepends& operator=(cmDepends const&) = delete;
/** Set the local generator for the directory in which we are
scanning dependencies. This is not a full local generator; it
@@ -44,7 +44,10 @@ public:
void SetLanguage(const std::string& lang) { this->Language = lang; }
/** Set the target build directory. */
- void SetTargetDirectory(const char* dir) { this->TargetDirectory = dir; }
+ void SetTargetDirectory(const std::string& dir)
+ {
+ this->TargetDirectory = dir;
+ }
/** should this be verbose in its output */
void SetVerbose(bool verb) { this->Verbose = verb; }
@@ -55,26 +58,19 @@ public:
/** 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);
+ bool Check(const std::string& makeFile, const std::string& internalFile,
+ DependencyMap& validDeps);
/** Clear dependencies for the target file so they will be regenerated. */
- void Clear(const char* file);
+ void Clear(const std::string& file);
/** Set the file comparison object */
- void SetFileComparison(cmFileTimeComparison* fc)
- {
- this->FileComparison = fc;
- }
+ void SetFileTimeCache(cmFileTimeCache* fc) { this->FileTimeCache = fc; }
protected:
// Write dependencies for the target file to the given stream.
@@ -87,33 +83,26 @@ protected:
// 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);
+ virtual bool CheckDependencies(std::istream& internalDepends,
+ const std::string& internalDependsFileName,
+ DependencyMap& 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;
+ bool Verbose = false;
+ cmFileTimeCache* FileTimeCache = nullptr;
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;
diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx
index 2c464cc9c..dc49c18f8 100644
--- a/Source/cmDependsC.cxx
+++ b/Source/cmDependsC.cxx
@@ -6,7 +6,7 @@
#include <utility>
#include "cmAlgorithms.h"
-#include "cmFileTimeComparison.h"
+#include "cmFileTime.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
@@ -19,14 +19,10 @@
#define INCLUDE_REGEX_COMPLAIN_MARKER "#IncludeRegexComplain: "
#define INCLUDE_REGEX_TRANSFORM_MARKER "#IncludeRegexTransform: "
-cmDependsC::cmDependsC()
- : ValidDeps(CM_NULLPTR)
-{
-}
+cmDependsC::cmDependsC() = default;
-cmDependsC::cmDependsC(
- cmLocalGenerator* lg, const char* targetDir, const std::string& lang,
- const std::map<std::string, DependencyVector>* validDeps)
+cmDependsC::cmDependsC(cmLocalGenerator* lg, const std::string& targetDir,
+ const std::string& lang, const DependencyMap* validDeps)
: cmDepends(lg, targetDir)
, ValidDeps(validDeps)
{
@@ -54,8 +50,8 @@ cmDependsC::cmDependsC(
}
this->IncludeRegexLine.compile(INCLUDE_REGEX_LINE);
- this->IncludeRegexScan.compile(scanRegex.c_str());
- this->IncludeRegexComplain.compile(complainRegex.c_str());
+ this->IncludeRegexScan.compile(scanRegex);
+ this->IncludeRegexComplain.compile(complainRegex);
this->IncludeRegexLineString = INCLUDE_REGEX_LINE_MARKER INCLUDE_REGEX_LINE;
this->IncludeRegexScanString = INCLUDE_REGEX_SCAN_MARKER;
this->IncludeRegexScanString += scanRegex;
@@ -96,9 +92,16 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
std::set<std::string> dependencies;
bool haveDeps = false;
- if (this->ValidDeps != CM_NULLPTR) {
- std::map<std::string, DependencyVector>::const_iterator tmpIt =
- this->ValidDeps->find(obj);
+ std::string binDir = this->LocalGenerator->GetBinaryDirectory();
+
+ // Compute a path to the object file to write to the internal depend file.
+ // Any existing content of the internal depend file has already been
+ // loaded in ValidDeps with this path as a key.
+ std::string obj_i =
+ this->LocalGenerator->MaybeConvertToRelativePath(binDir, obj);
+
+ if (this->ValidDeps != nullptr) {
+ auto const tmpIt = this->ValidDeps->find(obj_i);
if (tmpIt != this->ValidDeps->end()) {
dependencies.insert(tmpIt->second.begin(), tmpIt->second.end());
haveDeps = true;
@@ -107,24 +110,17 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
if (!haveDeps) {
// Walk the dependency graph starting with the source file.
- int srcFiles = (int)sources.size();
+ int srcFiles = static_cast<int>(sources.size());
this->Encountered.clear();
- for (std::set<std::string>::const_iterator srcIt = sources.begin();
- srcIt != sources.end(); ++srcIt) {
+ for (std::string const& src : sources) {
UnscannedEntry root;
- root.FileName = *srcIt;
+ root.FileName = src;
this->Unscanned.push(root);
- this->Encountered.insert(*srcIt);
+ this->Encountered.insert(src);
}
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();
@@ -132,37 +128,32 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
// 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)) {
+ if ((srcFiles > 0) || cmSystemTools::FileIsFullPath(current.FileName)) {
+ if (cmSystemTools::FileExists(current.FileName, true)) {
fullName = current.FileName;
}
} else if (!current.QuotedLocation.empty() &&
- cmSystemTools::FileExists(current.QuotedLocation.c_str(),
- true)) {
+ cmSystemTools::FileExists(current.QuotedLocation, 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 =
+ auto 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) {
+ for (std::string const& iPath : this->IncludePath) {
// 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);
+ std::string tmpPath =
+ cmSystemTools::CollapseFullPath(current.FileName, iPath);
// Look for the file in this location.
- if (cmSystemTools::FileExists(tempPathStr.c_str(), true)) {
- fullName = tempPathStr;
- HeaderLocationCache[current.FileName] = fullName;
+ if (cmSystemTools::FileExists(tmpPath, true)) {
+ fullName = tmpPath;
+ this->HeaderLocationCache[current.FileName] = std::move(tmpPath);
break;
}
}
@@ -172,9 +163,8 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
// 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(),
- "\".");
+ this->IncludeRegexComplain.find(current.FileName)) {
+ cmSystemTools::Error("Cannot find file \"" + current.FileName + "\".");
return false;
}
@@ -184,18 +174,15 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
scanned.insert(fullName);
// Check whether this file is already in the cache
- std::map<std::string, cmIncludeLines*>::iterator fileIt =
- this->FileCache.find(fullName);
+ auto 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) ==
+ for (UnscannedEntry const& inc : fileIt->second->UnscannedEntries) {
+ if (this->Encountered.find(inc.FileName) ==
this->Encountered.end()) {
- this->Encountered.insert(incIt->FileName);
- this->Unscanned.push(*incIt);
+ this->Encountered.insert(inc.FileName);
+ this->Unscanned.push(inc);
}
}
} else {
@@ -213,7 +200,7 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
// 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);
+ this->Scan(fin, dir, fullName);
} else {
// Skip file with encoding we do not implement.
}
@@ -229,19 +216,16 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
// 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 binDir = this->LocalGenerator->GetBinaryDirectory();
- std::string obj_i = this->LocalGenerator->ConvertToRelativePath(binDir, obj);
- std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i.c_str());
+ std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i);
internalDepends << obj_i << std::endl;
- for (std::set<std::string>::const_iterator i = dependencies.begin();
- i != dependencies.end(); ++i) {
- makeDepends
- << obj_m << ": "
- << cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator->ConvertToRelativePath(binDir, *i).c_str())
- << std::endl;
- internalDepends << " " << *i << std::endl;
+ for (std::string const& dep : dependencies) {
+ makeDepends << obj_m << ": "
+ << cmSystemTools::ConvertToOutputPath(
+ this->LocalGenerator->MaybeConvertToRelativePath(binDir,
+ dep))
+ << std::endl;
+ internalDepends << " " << dep << std::endl;
}
makeDepends << std::endl;
@@ -259,24 +243,26 @@ void cmDependsC::ReadCacheFile()
}
std::string line;
- cmIncludeLines* cacheEntry = CM_NULLPTR;
+ cmIncludeLines* cacheEntry = nullptr;
bool haveFileName = false;
+ cmFileTime cacheFileTime;
+ bool const cacheFileTimeGood = cacheFileTime.Load(this->CacheFileName);
while (cmSystemTools::GetLineFromStream(fin, line)) {
if (line.empty()) {
- cacheEntry = CM_NULLPTR;
+ cacheEntry = nullptr;
haveFileName = false;
continue;
}
// the first line after an empty line is the name of the parsed file
if (!haveFileName) {
haveFileName = true;
- int newer = 0;
- cmFileTimeComparison comp;
- bool res = comp.FileTimeCompare(this->CacheFileName.c_str(),
- line.c_str(), &newer);
- if (res && newer == 1) // cache is newer than the parsed file
+ cmFileTime fileTime;
+ bool const res = cacheFileTimeGood && fileTime.Load(line);
+ bool const newer = res && cacheFileTime.Newer(fileTime);
+
+ if (res && newer) // cache is newer than the parsed file
{
cacheEntry = new cmIncludeLines;
this->FileCache[line] = cacheEntry;
@@ -302,14 +288,14 @@ void cmDependsC::ReadCacheFile()
}
}
}
- } else if (cacheEntry != CM_NULLPTR) {
+ } else if (cacheEntry != nullptr) {
UnscannedEntry entry;
entry.FileName = line;
if (cmSystemTools::GetLineFromStream(fin, line)) {
if (line != "-") {
entry.QuotedLocation = line;
}
- cacheEntry->UnscannedEntries.push_back(entry);
+ cacheEntry->UnscannedEntries.push_back(std::move(entry));
}
}
}
@@ -330,20 +316,16 @@ void cmDependsC::WriteCacheFile() const
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 << std::endl;
-
- for (std::vector<UnscannedEntry>::const_iterator incIt =
- fileIt->second->UnscannedEntries.begin();
- incIt != fileIt->second->UnscannedEntries.end(); ++incIt) {
- cacheOut << incIt->FileName << std::endl;
- if (incIt->QuotedLocation.empty()) {
+ for (auto const& fileIt : this->FileCache) {
+ if (fileIt.second->Used) {
+ cacheOut << fileIt.first << std::endl;
+
+ for (UnscannedEntry const& inc : fileIt.second->UnscannedEntries) {
+ cacheOut << inc.FileName << std::endl;
+ if (inc.QuotedLocation.empty()) {
cacheOut << "-" << std::endl;
} else {
- cacheOut << incIt->QuotedLocation << std::endl;
+ cacheOut << inc.QuotedLocation << std::endl;
}
}
cacheOut << std::endl;
@@ -351,7 +333,7 @@ void cmDependsC::WriteCacheFile() const
}
}
-void cmDependsC::Scan(std::istream& is, const char* directory,
+void cmDependsC::Scan(std::istream& is, const std::string& directory,
const std::string& fullName)
{
cmIncludeLines* newCacheEntry = new cmIncludeLines;
@@ -367,18 +349,18 @@ void cmDependsC::Scan(std::istream& is, const char* directory,
}
// Match include directives.
- if (this->IncludeRegexLine.find(line.c_str())) {
+ if (this->IncludeRegexLine.find(line)) {
// 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())) {
+ !cmSystemTools::FileIsFullPath(entry.FileName)) {
// 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);
+ cmSystemTools::CollapseFullPath(entry.FileName, directory);
}
// Queue the file if it has not yet been encountered and it
@@ -391,7 +373,7 @@ void cmDependsC::Scan(std::istream& is, const char* directory,
// 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())) {
+ if (this->IncludeRegexScan.find(entry.FileName)) {
newCacheEntry->UnscannedEntries.push_back(entry);
if (this->Encountered.find(entry.FileName) ==
this->Encountered.end()) {
@@ -411,9 +393,8 @@ void cmDependsC::SetupTransforms()
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);
+ for (std::string const& tr : transformRules) {
+ this->ParseTransform(tr);
}
this->IncludeRegexTransformString = INCLUDE_REGEX_TRANSFORM_MARKER;
@@ -422,24 +403,22 @@ void cmDependsC::SetupTransforms()
// 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) {
+ for (auto const& tr : this->TransformRules) {
xform += sep;
- xform += tri->first;
+ xform += tr.first;
sep = "|";
}
xform += ")[ \t]*\\(([^),]*)\\)";
- this->IncludeRegexTransform.compile(xform.c_str());
+ this->IncludeRegexTransform.compile(xform);
// 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) {
+ for (auto const& tr : this->TransformRules) {
this->IncludeRegexTransformString += " ";
- this->IncludeRegexTransformString += tri->first;
+ this->IncludeRegexTransformString += tr.first;
this->IncludeRegexTransformString += "(%)=";
- this->IncludeRegexTransformString += tri->second;
+ this->IncludeRegexTransformString += tr.second;
}
}
}
@@ -460,7 +439,7 @@ void cmDependsC::ParseTransform(std::string const& xform)
void cmDependsC::TransformLine(std::string& line)
{
// Check for a transform rule match. Return if none.
- if (!this->IncludeRegexTransform.find(line.c_str())) {
+ if (!this->IncludeRegexTransform.find(line)) {
return;
}
TransformRulesType::const_iterator tri =
@@ -472,11 +451,11 @@ void cmDependsC::TransformLine(std::string& line)
// 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 == '%') {
+ for (char c : tri->second) {
+ if (c == '%') {
newline += arg;
} else {
- newline += *c;
+ newline += c;
}
}
diff --git a/Source/cmDependsC.h b/Source/cmDependsC.h
index 250d40f8a..3fc839e43 100644
--- a/Source/cmDependsC.h
+++ b/Source/cmDependsC.h
@@ -3,7 +3,7 @@
#ifndef cmDependsC_h
#define cmDependsC_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmDepends.h"
@@ -22,27 +22,27 @@ class cmLocalGenerator;
*/
class cmDependsC : public cmDepends
{
- CM_DISABLE_COPY(cmDependsC)
-
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);
+ cmDependsC(cmLocalGenerator* lg, const std::string& targetDir,
+ const std::string& lang, const DependencyMap* validDeps);
/** Virtual destructor to cleanup subclasses properly. */
- ~cmDependsC() CM_OVERRIDE;
+ ~cmDependsC() override;
+
+ cmDependsC(cmDependsC const&) = delete;
+ cmDependsC& operator=(cmDependsC const&) = delete;
protected:
// Implement writing/checking methods required by superclass.
bool WriteDependencies(const std::set<std::string>& sources,
const std::string& obj, std::ostream& makeDepends,
- std::ostream& internalDepends) CM_OVERRIDE;
+ std::ostream& internalDepends) override;
// Method to scan a single file.
- void Scan(std::istream& is, const char* directory,
+ void Scan(std::istream& is, const std::string& directory,
const std::string& fullName);
// Regular expression to identify C preprocessor include directives.
@@ -75,16 +75,12 @@ public:
struct cmIncludeLines
{
- cmIncludeLines()
- : Used(false)
- {
- }
std::vector<UnscannedEntry> UnscannedEntries;
- bool Used;
+ bool Used = false;
};
protected:
- const std::map<std::string, DependencyVector>* ValidDeps;
+ const DependencyMap* ValidDeps = nullptr;
std::set<std::string> Encountered;
std::queue<UnscannedEntry> Unscanned;
diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx
index 8b05fab49..178e18b5f 100644
--- a/Source/cmDependsFortran.cxx
+++ b/Source/cmDependsFortran.cxx
@@ -7,9 +7,9 @@
#include <iostream>
#include <map>
#include <stdlib.h>
-#include <string.h>
#include <utility>
+#include "cmAlgorithms.h"
#include "cmFortranParser.h" /* Interface to parser object. */
#include "cmGeneratedFileStream.h"
#include "cmLocalGenerator.h"
@@ -23,6 +23,22 @@
// use lower case and some always use upper case. I do not know if any
// use the case from the source code.
+static void cmFortranModuleAppendUpperLower(std::string const& mod,
+ std::string& mod_upper,
+ std::string& mod_lower)
+{
+ std::string::size_type ext_len = 0;
+ if (cmHasLiteralSuffix(mod, ".mod")) {
+ ext_len = 4;
+ } else if (cmHasLiteralSuffix(mod, ".smod")) {
+ ext_len = 5;
+ }
+ std::string const& name = mod.substr(0, mod.size() - ext_len);
+ std::string const& ext = mod.substr(mod.size() - ext_len);
+ mod_upper += cmSystemTools::UpperCase(name) + ext;
+ mod_lower += mod;
+}
+
class cmDependsFortranInternals
{
public:
@@ -37,7 +53,8 @@ public:
typedef std::map<std::string, cmFortranSourceInfo> ObjectInfoMap;
ObjectInfoMap ObjectInfo;
- cmFortranSourceInfo& CreateObjectInfo(const char* obj, const char* src)
+ cmFortranSourceInfo& CreateObjectInfo(const std::string& obj,
+ const std::string& src)
{
std::map<std::string, cmFortranSourceInfo>::iterator i =
this->ObjectInfo.find(obj);
@@ -51,10 +68,7 @@ public:
}
};
-cmDependsFortran::cmDependsFortran()
- : Internal(CM_NULLPTR)
-{
-}
+cmDependsFortran::cmDependsFortran() = default;
cmDependsFortran::cmDependsFortran(cmLocalGenerator* lg)
: cmDepends(lg)
@@ -73,15 +87,17 @@ cmDependsFortran::cmDependsFortran(cmLocalGenerator* lg)
// 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;
+ for (std::string def : definitions) {
std::string::size_type assignment = def.find('=');
if (assignment != std::string::npos) {
- def = it->substr(0, assignment);
+ def = def.substr(0, assignment);
}
this->PPDefinitions.insert(def);
}
+
+ this->CompilerId = mf->GetSafeDefinition("CMAKE_Fortran_COMPILER_ID");
+ this->SModSep = mf->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_SEP");
+ this->SModExt = mf->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_EXT");
}
cmDependsFortran::~cmDependsFortran()
@@ -104,17 +120,19 @@ bool cmDependsFortran::WriteDependencies(const std::set<std::string>& sources,
return false;
}
+ cmFortranCompiler fc;
+ fc.Id = this->CompilerId;
+ fc.SModSep = this->SModSep;
+ fc.SModExt = this->SModExt;
+
bool okay = true;
- for (std::set<std::string>::const_iterator it = sources.begin();
- it != sources.end(); ++it) {
- const std::string& src = *it;
+ for (std::string const& src : sources) {
// Get the information object for this source.
- cmFortranSourceInfo& info =
- this->Internal->CreateObjectInfo(obj.c_str(), src.c_str());
+ cmFortranSourceInfo& info = this->Internal->CreateObjectInfo(obj, src);
// Create the parser object. The constructor takes info by reference,
// so we may look into the resulting objects later.
- cmFortranParser parser(this->IncludePath, this->PPDefinitions, info);
+ cmFortranParser parser(fc, this->IncludePath, this->PPDefinitions, info);
// Push on the starting file.
cmFortranParser_FilePush(&parser, src.c_str());
@@ -141,7 +159,7 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
this->LocateModules();
// Get the directory in which stamp files will be stored.
- const char* stamp_dir = this->TargetDirectory.c_str();
+ const std::string& stamp_dir = this->TargetDirectory;
// Get the directory in which module files will be created.
cmMakefile* mf = this->LocalGenerator->GetMakefile();
@@ -154,11 +172,9 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
// 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)) {
+ for (auto const& i : objInfo) {
+ if (!this->WriteDependenciesReal(i.first, i.second, mod_dir, stamp_dir,
+ makeDepends, internalDepends)) {
return false;
}
}
@@ -166,38 +182,33 @@ bool cmDependsFortran::Finalize(std::ostream& makeDepends,
// Store the list of modules provided by this target.
std::string fiName = this->TargetDirectory;
fiName += "/fortran.internal";
- cmGeneratedFileStream fiStream(fiName.c_str());
+ cmGeneratedFileStream fiStream(fiName);
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";
+ for (std::string const& i : provides) {
+ 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());
+ cmGeneratedFileStream fcStream(fcName);
fcStream << "# Remove fortran modules provided by this target.\n";
fcStream << "FILE(REMOVE";
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
- for (std::set<std::string>::const_iterator i = provides.begin();
- i != provides.end(); ++i) {
+ for (std::string const& i : provides) {
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";
+ cmFortranModuleAppendUpperLower(i, mod_upper, mod_lower);
std::string stamp = stamp_dir;
stamp += "/";
- stamp += *i;
- stamp += ".mod.stamp";
+ stamp += i;
+ stamp += ".stamp";
fcStream << "\n";
fcStream << " \""
<< this->MaybeConvertToRelativePath(currentBinDir, mod_lower)
@@ -219,16 +230,14 @@ 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) {
- cmFortranSourceInfo const& info = infoI->second;
+ for (auto const& infoI : objInfo) {
+ cmFortranSourceInfo const& info = infoI.second;
// Include this module in the set provided by this target.
this->Internal->TargetProvides.insert(info.Provides.begin(),
info.Provides.end());
- for (std::set<std::string>::const_iterator i = info.Requires.begin();
- i != info.Requires.end(); ++i) {
- this->Internal->TargetRequires[*i] = "";
+ for (std::string const& r : info.Requires) {
+ this->Internal->TargetRequires[r].clear();
}
}
@@ -247,29 +256,27 @@ void cmDependsFortran::LocateModules()
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);
+ for (std::string const& i : infoFiles) {
+ 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());
+ this->MatchRemoteModules(fin, targetDir);
}
}
}
void cmDependsFortran::MatchLocalModules()
{
- const char* stampDir = this->TargetDirectory.c_str();
+ std::string const& stampDir = this->TargetDirectory;
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);
+ for (std::string const& i : provides) {
+ this->ConsiderModule(i, stampDir);
}
}
void cmDependsFortran::MatchRemoteModules(std::istream& fin,
- const char* stampDir)
+ const std::string& stampDir)
{
std::string line;
bool doing_provides = false;
@@ -281,7 +288,14 @@ void cmDependsFortran::MatchRemoteModules(std::istream& fin,
if (line[0] == ' ') {
if (doing_provides) {
- this->ConsiderModule(line.c_str() + 1, stampDir);
+ std::string mod = line;
+ if (!cmHasLiteralSuffix(mod, ".mod") &&
+ !cmHasLiteralSuffix(mod, ".smod")) {
+ // Support fortran.internal files left by older versions of CMake.
+ // They do not include the ".mod" extension.
+ mod += ".mod";
+ }
+ this->ConsiderModule(mod.substr(1), stampDir);
}
} else if (line == "provides") {
doing_provides = true;
@@ -291,7 +305,8 @@ void cmDependsFortran::MatchRemoteModules(std::istream& fin,
}
}
-void cmDependsFortran::ConsiderModule(const char* name, const char* stampDir)
+void cmDependsFortran::ConsiderModule(const std::string& name,
+ const std::string& stampDir)
{
// Locate each required module.
typedef cmDependsFortranInternals::TargetRequiresMap TargetRequiresMap;
@@ -303,131 +318,109 @@ void cmDependsFortran::ConsiderModule(const char* name, const char* stampDir)
std::string stampFile = stampDir;
stampFile += "/";
stampFile += name;
- stampFile += ".mod.stamp";
+ stampFile += ".stamp";
required->second = stampFile;
}
}
-bool cmDependsFortran::WriteDependenciesReal(const char* obj,
+bool cmDependsFortran::WriteDependenciesReal(std::string const& obj,
cmFortranSourceInfo const& info,
std::string const& mod_dir,
- const char* stamp_dir,
+ std::string const& 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();
+ std::string const& src = info.Source;
// Write the include dependencies to the output stream.
std::string binDir = this->LocalGenerator->GetBinaryDirectory();
std::string obj_i = this->MaybeConvertToRelativePath(binDir, obj);
- std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i.c_str());
+ std::string obj_m = cmSystemTools::ConvertToOutputPath(obj_i);
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) {
+ for (std::string const& i : info.Includes) {
makeDepends << obj_m << ": "
<< cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(binDir, *i).c_str())
+ this->MaybeConvertToRelativePath(binDir, i))
<< std::endl;
- internalDepends << " " << *i << 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) {
+ for (std::string const& i : info.Requires) {
// Require only modules not provided in the same source.
- if (std::set<std::string>::const_iterator(info.Provides.find(*i)) !=
- info.Provides.end()) {
+ if (info.Provides.find(i) != info.Provides.cend()) {
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 = cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(binDir, proxy).c_str());
-
- // 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);
+ 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 = cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(binDir, required->second).c_str());
+ this->MaybeConvertToRelativePath(binDir, required->second));
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)) {
+ if (this->FindModule(i, module)) {
module = cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(binDir, module).c_str());
+ this->MaybeConvertToRelativePath(binDir, module));
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 = cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(binDir, proxy).c_str());
- 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) {
+ for (std::string const& i : info.Provides) {
// Include this module in the set provided by this target.
- this->Internal->TargetProvides.insert(*i);
+ 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 += i;
modFile = this->LocalGenerator->ConvertToOutputFormat(
this->MaybeConvertToRelativePath(binDir, modFile),
cmOutputConverter::SHELL);
std::string stampFile = stamp_dir;
stampFile += "/";
- stampFile += m;
- stampFile += ".mod.stamp";
- stampFile = this->LocalGenerator->ConvertToOutputFormat(
- this->MaybeConvertToRelativePath(binDir, stampFile),
- cmOutputConverter::SHELL);
+ stampFile += i;
+ stampFile += ".stamp";
+ stampFile = this->MaybeConvertToRelativePath(binDir, stampFile);
+ std::string const stampFileForShell =
+ this->LocalGenerator->ConvertToOutputFormat(stampFile,
+ cmOutputConverter::SHELL);
+ std::string const stampFileForMake =
+ cmSystemTools::ConvertToOutputPath(stampFile);
+
+ makeDepends << obj_m << ".provides.build"
+ << ": " << stampFileForMake << "\n";
+ // Note that when cmake_copy_f90_mod finds that a module file
+ // and the corresponding stamp file have no differences, the stamp
+ // file is not updated. In such case the stamp file will be always
+ // older than its prerequisite and trigger cmake_copy_f90_mod
+ // on each new build. This is expected behavior for incremental
+ // builds and can not be changed without preforming recursive make
+ // calls that would considerably slow down the building process.
+ makeDepends << stampFileForMake << ": " << obj_m << "\n";
makeDepends << "\t$(CMAKE_COMMAND) -E cmake_copy_f90_mod " << modFile
- << " " << stampFile;
+ << " " << stampFileForShell;
cmMakefile* mf = this->LocalGenerator->GetMakefile();
const char* cid = mf->GetDefinition("CMAKE_Fortran_COMPILER_ID");
if (cid && *cid) {
@@ -435,8 +428,8 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
}
makeDepends << "\n";
}
- // After copying the modules update the timestamp file so that
- // copying will not be done again until the source rebuilds.
+ makeDepends << obj_m << ".provides.build:\n";
+ // After copying the modules update the timestamp file.
makeDepends << "\t$(CMAKE_COMMAND) -E touch " << obj_m
<< ".provides.build\n";
@@ -445,7 +438,7 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
std::string driver = this->TargetDirectory;
driver += "/build";
driver = cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(binDir, driver).c_str());
+ this->MaybeConvertToRelativePath(binDir, driver));
makeDepends << driver << ": " << obj_m << ".provides.build\n";
}
@@ -455,29 +448,27 @@ bool cmDependsFortran::WriteDependenciesReal(const char* obj,
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";
+ std::string mod_upper;
+ std::string mod_lower;
+ cmFortranModuleAppendUpperLower(name, mod_upper, mod_lower);
// 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) {
+ for (std::string const& ip : this->IncludePath) {
// Try the lower-case name.
- fullName = *i;
+ fullName = ip;
fullName += "/";
fullName += mod_lower;
- if (cmSystemTools::FileExists(fullName.c_str(), true)) {
+ if (cmSystemTools::FileExists(fullName, true)) {
module = fullName;
return true;
}
// Try the upper-case name.
- fullName = *i;
+ fullName = ip;
fullName += "/";
fullName += mod_upper;
- if (cmSystemTools::FileExists(fullName.c_str(), true)) {
+ if (cmSystemTools::FileExists(fullName, true)) {
module = fullName;
return true;
}
@@ -503,20 +494,21 @@ bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
if (args.size() >= 5) {
compilerId = args[4];
}
+ if (!cmHasLiteralSuffix(mod, ".mod") && !cmHasLiteralSuffix(mod, ".smod")) {
+ // Support depend.make files left by older versions of CMake.
+ // They do not include the ".mod" extension.
+ mod += ".mod";
+ }
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())) {
+ cmFortranModuleAppendUpperLower(cmSystemTools::GetFilenameName(mod),
+ mod_upper, mod_lower);
+ if (cmSystemTools::FileExists(mod_upper, true)) {
+ if (cmDependsFortran::ModulesDiffer(mod_upper, stamp, compilerId)) {
if (!cmSystemTools::CopyFileAlways(mod_upper, stamp)) {
std::cerr << "Error copying Fortran module from \"" << mod_upper
<< "\" to \"" << stamp << "\".\n";
@@ -525,9 +517,8 @@ bool cmDependsFortran::CopyModule(const std::vector<std::string>& args)
}
return true;
}
- if (cmSystemTools::FileExists(mod_lower.c_str(), true)) {
- if (cmDependsFortran::ModulesDiffer(mod_lower.c_str(), stamp.c_str(),
- compilerId.c_str())) {
+ if (cmSystemTools::FileExists(mod_lower, true)) {
+ if (cmDependsFortran::ModulesDiffer(mod_lower, stamp, compilerId)) {
if (!cmSystemTools::CopyFileAlways(mod_lower, stamp)) {
std::cerr << "Error copying Fortran module from \"" << mod_lower
<< "\" to \"" << stamp << "\".\n";
@@ -594,9 +585,9 @@ static bool cmFortranStreamsDiffer(std::istream& ifs1, std::istream& ifs2)
return true;
}
-bool cmDependsFortran::ModulesDiffer(const char* modFile,
- const char* stampFile,
- const char* compilerId)
+bool cmDependsFortran::ModulesDiffer(const std::string& modFile,
+ const std::string& stampFile,
+ const std::string& compilerId)
{
/*
gnu >= 4.9:
@@ -616,7 +607,7 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
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
+ which is located some bytes in front of the absolute path to the source
file.
sun:
@@ -630,16 +621,17 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
* source is compiled twice
* -SunPro
*/
- if (strcmp(compilerId, "SunPro") == 0) {
+ if (compilerId == "SunPro") {
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);
+ cmsys::ifstream finModFile(modFile.c_str(), std::ios::in | std::ios::binary);
+ cmsys::ifstream finStampFile(stampFile.c_str(),
+ std::ios::in | std::ios::binary);
#else
- cmsys::ifstream finModFile(modFile);
- cmsys::ifstream finStampFile(stampFile);
+ cmsys::ifstream finModFile(modFile.c_str());
+ cmsys::ifstream finStampFile(stampFile.c_str());
#endif
if (!finModFile || !finStampFile) {
// At least one of the files does not exist. The modules differ.
@@ -654,7 +646,7 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
* Eat the stream content until all recompile only related changes
* are left behind.
*/
- if (strcmp(compilerId, "GNU") == 0) {
+ if (compilerId == "GNU") {
// 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.
@@ -677,7 +669,7 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
return true;
}
}
- } else if (strcmp(compilerId, "Intel") == 0) {
+ } else if (compilerId == "Intel") {
const char seq[2] = { '\n', '\0' };
const int seqlen = 2;
@@ -709,9 +701,9 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile,
std::string cmDependsFortran::MaybeConvertToRelativePath(
std::string const& base, std::string const& path)
{
- if (!cmOutputConverter::ContainedInDirectory(
- base, path, this->LocalGenerator->GetStateSnapshot().GetDirectory())) {
+ if (!this->LocalGenerator->GetStateSnapshot().GetDirectory().ContainsBoth(
+ base, path)) {
return path;
}
- return cmOutputConverter::ForceToRelativePath(base, path);
+ return cmSystemTools::ForceToRelativePath(base, path);
}
diff --git a/Source/cmDependsFortran.h b/Source/cmDependsFortran.h
index ec208af3a..04851152e 100644
--- a/Source/cmDependsFortran.h
+++ b/Source/cmDependsFortran.h
@@ -3,7 +3,7 @@
#ifndef cmFortran_h
#define cmFortran_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <set>
@@ -21,8 +21,6 @@ class cmLocalGenerator;
*/
class cmDependsFortran : public cmDepends
{
- CM_DISABLE_COPY(cmDependsFortran)
-
public:
/** Checking instances need to know the build directory name and the
relative path from the build directory to the target file. */
@@ -35,7 +33,10 @@ public:
cmDependsFortran(cmLocalGenerator* lg);
/** Virtual destructor to cleanup subclasses properly. */
- ~cmDependsFortran() CM_OVERRIDE;
+ ~cmDependsFortran() override;
+
+ cmDependsFortran(cmDependsFortran const&) = delete;
+ cmDependsFortran& operator=(cmDependsFortran const&) = delete;
/** Callback from build system after a .mod file has been generated
by a Fortran90 compiler to copy the .mod file to the
@@ -44,39 +45,46 @@ public:
/** 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);
+ static bool ModulesDiffer(const std::string& modFile,
+ const std::string& stampFile,
+ const std::string& compilerId);
protected:
// Finalize the dependency information for the target.
bool Finalize(std::ostream& makeDepends,
- std::ostream& internalDepends) CM_OVERRIDE;
+ std::ostream& internalDepends) override;
// 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);
+ void MatchRemoteModules(std::istream& fin, const std::string& stampDir);
+ void ConsiderModule(const std::string& name, const std::string& stampDir);
bool FindModule(std::string const& name, std::string& module);
// Implement writing/checking methods required by superclass.
bool WriteDependencies(const std::set<std::string>& sources,
const std::string& file, std::ostream& makeDepends,
- std::ostream& internalDepends) CM_OVERRIDE;
+ std::ostream& internalDepends) override;
- // Actually write the depenencies to the streams.
- bool WriteDependenciesReal(const char* obj, cmFortranSourceInfo const& info,
- std::string const& mod_dir, const char* stamp_dir,
+ // Actually write the dependencies to the streams.
+ bool WriteDependenciesReal(std::string const& obj,
+ cmFortranSourceInfo const& info,
+ std::string const& mod_dir,
+ std::string const& stamp_dir,
std::ostream& makeDepends,
std::ostream& internalDepends);
// The source file from which to start scanning.
std::string SourceFile;
+ std::string CompilerId;
+ std::string SModSep;
+ std::string SModExt;
+
std::set<std::string> PPDefinitions;
// Internal implementation details.
- cmDependsFortranInternals* Internal;
+ cmDependsFortranInternals* Internal = nullptr;
private:
std::string MaybeConvertToRelativePath(std::string const& base,
diff --git a/Source/cmDependsJava.cxx b/Source/cmDependsJava.cxx
index 29938ba36..b17b2ba74 100644
--- a/Source/cmDependsJava.cxx
+++ b/Source/cmDependsJava.cxx
@@ -4,13 +4,9 @@
#include "cmSystemTools.h"
-cmDependsJava::cmDependsJava()
-{
-}
+cmDependsJava::cmDependsJava() = default;
-cmDependsJava::~cmDependsJava()
-{
-}
+cmDependsJava::~cmDependsJava() = default;
bool cmDependsJava::WriteDependencies(const std::set<std::string>& sources,
const std::string& /*obj*/,
@@ -27,8 +23,8 @@ bool cmDependsJava::WriteDependencies(const std::set<std::string>& sources,
}
bool cmDependsJava::CheckDependencies(
- std::istream& /*internalDepends*/, const char* /*internalDependsFileName*/,
- std::map<std::string, DependencyVector>& /*validDeps*/)
+ std::istream& /*internalDepends*/,
+ const std::string& /*internalDependsFileName*/, DependencyMap& /*validDeps*/)
{
return true;
}
diff --git a/Source/cmDependsJava.h b/Source/cmDependsJava.h
index a07bf0979..dd671a1b6 100644
--- a/Source/cmDependsJava.h
+++ b/Source/cmDependsJava.h
@@ -3,12 +3,11 @@
#ifndef cmDependsJava_h
#define cmDependsJava_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmDepends.h"
#include <iosfwd>
-#include <map>
#include <set>
#include <string>
@@ -17,24 +16,25 @@
*/
class cmDependsJava : public cmDepends
{
- CM_DISABLE_COPY(cmDependsJava)
-
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. */
- ~cmDependsJava() CM_OVERRIDE;
+ ~cmDependsJava() override;
+
+ cmDependsJava(cmDependsJava const&) = delete;
+ cmDependsJava& operator=(cmDependsJava const&) = delete;
protected:
// Implement writing/checking methods required by superclass.
bool WriteDependencies(const std::set<std::string>& sources,
const std::string& file, std::ostream& makeDepends,
- std::ostream& internalDepends) CM_OVERRIDE;
- bool CheckDependencies(
- std::istream& internalDepends, const char* internalDependsFileName,
- std::map<std::string, DependencyVector>& validDeps) CM_OVERRIDE;
+ std::ostream& internalDepends) override;
+ bool CheckDependencies(std::istream& internalDepends,
+ const std::string& internalDependsFileName,
+ DependencyMap& validDeps) override;
};
#endif
diff --git a/Source/cmDependsJavaParserHelper.cxx b/Source/cmDependsJavaParserHelper.cxx
index 7bc91bfd4..12d875d6f 100644
--- a/Source/cmDependsJavaParserHelper.cxx
+++ b/Source/cmDependsJavaParserHelper.cxx
@@ -2,16 +2,16 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDependsJavaParserHelper.h"
-#include "cmConfigure.h"
-
#include "cmDependsJavaLexer.h"
#include "cmSystemTools.h"
+#include "cm_string_view.hxx"
#include "cmsys/FStream.hxx"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <utility>
int cmDependsJava_yyparse(yyscan_t yyscanner);
@@ -24,7 +24,7 @@ cmDependsJavaParserHelper::cmDependsJavaParserHelper()
CurrentClass tl;
tl.Name = "*";
- this->ClassStack.push_back(tl);
+ this->ClassStack.push_back(std::move(tl));
}
cmDependsJavaParserHelper::~cmDependsJavaParserHelper()
@@ -42,10 +42,8 @@ void cmDependsJavaParserHelper::CurrentClass::AddFileNamesForPrinting(
}
rname += this->Name;
files->push_back(rname);
- std::vector<CurrentClass>::const_iterator it;
- for (it = this->NestedClasses.begin(); it != this->NestedClasses.end();
- ++it) {
- it->AddFileNamesForPrinting(files, rname.c_str(), sep);
+ for (CurrentClass const& nc : this->NestedClasses) {
+ nc.AddFileNamesForPrinting(files, rname.c_str(), sep);
}
}
@@ -57,7 +55,7 @@ void cmDependsJavaParserHelper::DeallocateParserType(char** pt)
if (!*pt) {
return;
}
- *pt = CM_NULLPTR;
+ *pt = nullptr;
this->UnionsAvailable--;
}
@@ -66,25 +64,22 @@ 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) {
+ for (std::string const& cf : this->ClassesFound) {
+ if (cf == sclass) {
return;
}
}
- this->ClassesFound.push_back(sclass);
+ this->ClassesFound.emplace_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) {
+ for (std::string const& pi : this->PackagesImport) {
+ if (pi == sclass) {
return;
}
}
- this->PackagesImport.push_back(sclass);
+ this->PackagesImport.emplace_back(sclass);
}
void cmDependsJavaParserHelper::SafePrintMissing(const char* str, int line,
@@ -96,9 +91,9 @@ void cmDependsJavaParserHelper::SafePrintMissing(const char* str, int line,
for (cc = 0; cc < strlen(str); cc++) {
unsigned char ch = str[cc];
if (ch >= 32 && ch <= 126) {
- std::cout << (char)ch;
+ std::cout << static_cast<char>(ch);
} else {
- std::cout << "<" << (int)ch << ">";
+ std::cout << "<" << static_cast<int>(ch) << ">";
break;
}
}
@@ -158,15 +153,15 @@ void cmDependsJavaParserHelper::PrepareElement(
cmDependsJavaParserHelper::ParserType* me)
{
// Inititalize self
- me->str = CM_NULLPTR;
+ me->str = nullptr;
}
void cmDependsJavaParserHelper::AllocateParserType(
cmDependsJavaParserHelper::ParserType* pt, const char* str, int len)
{
- pt->str = CM_NULLPTR;
+ pt->str = nullptr;
if (len == 0) {
- len = (int)strlen(str);
+ len = static_cast<int>(strlen(str));
}
if (len == 0) {
return;
@@ -182,7 +177,7 @@ void cmDependsJavaParserHelper::StartClass(const char* cls)
{
CurrentClass cl;
cl.Name = cls;
- this->ClassStack.push_back(cl);
+ this->ClassStack.push_back(std::move(cl));
this->CurrentDepth++;
}
@@ -210,10 +205,8 @@ void cmDependsJavaParserHelper::PrintClasses()
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;
+ for (std::string const& f : this->GetFilesProduced()) {
+ std::cout << " " << f << ".class" << std::endl;
}
}
@@ -221,10 +214,8 @@ std::vector<std::string> cmDependsJavaParserHelper::GetFilesProduced()
{
std::vector<std::string> files;
CurrentClass const& toplevel = this->ClassStack.front();
- std::vector<CurrentClass>::const_iterator it;
- for (it = toplevel.NestedClasses.begin(); it != toplevel.NestedClasses.end();
- ++it) {
- it->AddFileNamesForPrinting(&files, CM_NULLPTR, "$");
+ for (CurrentClass const& nc : toplevel.NestedClasses) {
+ nc.AddFileNamesForPrinting(&files, nullptr, "$");
}
return files;
}
@@ -264,10 +255,8 @@ int cmDependsJavaParserHelper::ParseString(const char* str, int verb)
std::cout << std::endl;
std::cout << "Depends on:";
if (!this->ClassesFound.empty()) {
- std::vector<std::string>::iterator it;
- for (it = this->ClassesFound.begin(); it != this->ClassesFound.end();
- ++it) {
- std::cout << " " << *it;
+ for (std::string const& cf : this->ClassesFound) {
+ std::cout << " " << cf;
}
}
std::cout << std::endl;
@@ -284,9 +273,8 @@ int cmDependsJavaParserHelper::ParseString(const char* str, int verb)
void cmDependsJavaParserHelper::CleanupParser()
{
- std::vector<char*>::iterator it;
- for (it = this->Allocates.begin(); it != this->Allocates.end(); ++it) {
- delete[] * it;
+ for (char* allocate : this->Allocates) {
+ delete[] allocate;
}
this->Allocates.erase(this->Allocates.begin(), this->Allocates.end());
}
@@ -311,20 +299,16 @@ 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;
+ std::cerr << "String: ["
+ << cm::string_view{ this->InputBuffer }.substr(
+ this->InputBufferPos, 30)
+ << "]" << std::endl;
}
void cmDependsJavaParserHelper::UpdateCombine(const char* str1,
const char* str2)
{
- if (this->CurrentCombine == "" && str1 != CM_NULLPTR) {
+ if (this->CurrentCombine.empty() && str1 != nullptr) {
this->CurrentCombine = str1;
}
this->CurrentCombine += ".";
diff --git a/Source/cmDependsJavaParserHelper.h b/Source/cmDependsJavaParserHelper.h
index 0b445d924..a673b5bbb 100644
--- a/Source/cmDependsJavaParserHelper.h
+++ b/Source/cmDependsJavaParserHelper.h
@@ -24,6 +24,10 @@ public:
cmDependsJavaParserHelper();
~cmDependsJavaParserHelper();
+ cmDependsJavaParserHelper(const cmDependsJavaParserHelper&) = delete;
+ cmDependsJavaParserHelper& operator=(const cmDependsJavaParserHelper&) =
+ delete;
+
int ParseString(const char* str, int verb);
int ParseFile(const char* file);
diff --git a/Source/cmDisallowedCommand.cxx b/Source/cmDisallowedCommand.cxx
index ce1965d30..418d98c9f 100644
--- a/Source/cmDisallowedCommand.cxx
+++ b/Source/cmDisallowedCommand.cxx
@@ -3,7 +3,7 @@
#include "cmDisallowedCommand.h"
#include "cmMakefile.h"
-#include "cmake.h"
+#include "cmMessageType.h"
class cmExecutionStatus;
@@ -12,7 +12,7 @@ bool cmDisallowedCommand::InitialPass(std::vector<std::string> const& args,
{
switch (this->Makefile->GetPolicyStatus(this->Policy)) {
case cmPolicies::WARN:
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(this->Policy));
break;
case cmPolicies::OLD:
@@ -20,7 +20,7 @@ bool cmDisallowedCommand::InitialPass(std::vector<std::string> const& args,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, this->Message);
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, this->Message);
return true;
}
diff --git a/Source/cmDisallowedCommand.h b/Source/cmDisallowedCommand.h
index 0030116b8..d85c00f8c 100644
--- a/Source/cmDisallowedCommand.h
+++ b/Source/cmDisallowedCommand.h
@@ -3,7 +3,7 @@
#ifndef cmDisallowedCommand_h
#define cmDisallowedCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,23 +24,20 @@ public:
{
}
- ~cmDisallowedCommand() CM_OVERRIDE { delete this->Command; }
+ ~cmDisallowedCommand() override { delete this->Command; }
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
return new cmDisallowedCommand(this->Command->Clone(), this->Policy,
this->Message);
}
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
- void FinalPass() CM_OVERRIDE { this->Command->FinalPass(); }
+ void FinalPass() override { this->Command->FinalPass(); }
- bool HasFinalPass() const CM_OVERRIDE
- {
- return this->Command->HasFinalPass();
- }
+ bool HasFinalPass() const override { return this->Command->HasFinalPass(); }
private:
cmCommand* Command;
diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx
index c6286b35a..d4628fa7e 100644
--- a/Source/cmDocumentation.cxx
+++ b/Source/cmDocumentation.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDocumentation.h"
-#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
#include "cmDocumentationSection.h"
#include "cmRST.h"
@@ -41,12 +40,19 @@ static const char* cmDocumentationStandardOptions[][2] = {
{ "--help-variable-list [<f>]",
"List variables with help available and exit." },
{ "--help-variables [<f>]", "Print cmake-variables manual and exit." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, nullptr }
};
-static const char* cmDocumentationGeneratorsHeader[][2] = {
- { CM_NULLPTR, "The following generators are available on this platform:" },
- { CM_NULLPTR, CM_NULLPTR }
+static const char* cmDocumentationCPackGeneratorsHeader[][2] = {
+ { nullptr, "The following generators are available on this platform:" },
+ { nullptr, nullptr }
+};
+
+static const char* cmDocumentationCMakeGeneratorsHeader[][2] = {
+ { nullptr,
+ "The following generators are available on this platform (* marks "
+ "default):" },
+ { nullptr, nullptr }
};
cmDocumentation::cmDocumentation()
@@ -55,11 +61,6 @@ cmDocumentation::cmDocumentation()
this->ShowGenerators = true;
}
-cmDocumentation::~cmDocumentation()
-{
- cmDeleteAll(this->AllSections);
-}
-
bool cmDocumentation::PrintVersion(std::ostream& os)
{
/* clang-format off */
@@ -123,23 +124,21 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
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;
+ for (RequestedHelpItem const& rhi : this->RequestedHelpItems) {
+ this->CurrentArgument = rhi.Argument;
// If a file name was given, use it. Otherwise, default to the
// given stream.
cmsys::ofstream fout;
std::ostream* s = &os;
- if (!i->Filename.empty()) {
- fout.open(i->Filename.c_str());
+ if (!rhi.Filename.empty()) {
+ fout.open(rhi.Filename.c_str());
s = &fout;
} else if (++count > 1) {
os << "\n\n";
}
// Print this documentation type to the stream.
- if (!this->PrintDocumentation(i->HelpType, *s) || s->fail()) {
+ if (!this->PrintDocumentation(rhi.HelpType, *s) || s->fail()) {
result = false;
}
}
@@ -147,10 +146,12 @@ bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
}
#define GET_OPT_ARGUMENT(target) \
- if ((i + 1 < argc) && !this->IsOption(argv[i + 1])) { \
- (target) = argv[i + 1]; \
- i = i + 1; \
- };
+ do { \
+ if ((i + 1 < argc) && !this->IsOption(argv[i + 1])) { \
+ (target) = argv[i + 1]; \
+ i = i + 1; \
+ }; \
+ } while (false)
void cmDocumentation::WarnFormFromFilename(
cmDocumentation::RequestedHelpItem& request, bool& result)
@@ -176,20 +177,16 @@ void cmDocumentation::WarnFormFromFilename(
void cmDocumentation::addCommonStandardDocSections()
{
- cmDocumentationSection* sec;
-
- sec = new cmDocumentationSection("Options", "OPTIONS");
- sec->Append(cmDocumentationStandardOptions);
- this->AllSections["Options"] = sec;
+ cmDocumentationSection sec{ "Options" };
+ sec.Append(cmDocumentationStandardOptions);
+ this->AllSections.emplace("Options", std::move(sec));
}
void cmDocumentation::addCMakeStandardDocSections()
{
- cmDocumentationSection* sec;
-
- sec = new cmDocumentationSection("Generators", "GENERATORS");
- sec->Append(cmDocumentationGeneratorsHeader);
- this->AllSections["Generators"] = sec;
+ cmDocumentationSection sec{ "Generators" };
+ sec.Append(cmDocumentationCMakeGeneratorsHeader);
+ this->AllSections.emplace("Generators", std::move(sec));
}
void cmDocumentation::addCTestStandardDocSections()
@@ -201,11 +198,9 @@ void cmDocumentation::addCTestStandardDocSections()
void cmDocumentation::addCPackStandardDocSections()
{
- cmDocumentationSection* sec;
-
- sec = new cmDocumentationSection("Generators", "GENERATORS");
- sec->Append(cmDocumentationGeneratorsHeader);
- this->AllSections["Generators"] = sec;
+ cmDocumentationSection sec{ "Generators" };
+ sec.Append(cmDocumentationCPackGeneratorsHeader);
+ this->AllSections.emplace("Generators", std::move(sec));
}
bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
@@ -215,7 +210,7 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
if (argc == 1) {
RequestedHelpItem help;
help.HelpType = cmDocumentation::Usage;
- this->RequestedHelpItems.push_back(help);
+ this->RequestedHelpItems.push_back(std::move(help));
return true;
}
@@ -354,7 +349,7 @@ bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
if (help.HelpType != None) {
// This is a help option. See if there is a file name given.
result = true;
- this->RequestedHelpItems.push_back(help);
+ this->RequestedHelpItems.push_back(std::move(help));
}
}
return result;
@@ -366,93 +361,59 @@ void cmDocumentation::SetName(const std::string& name)
}
void cmDocumentation::SetSection(const char* name,
- cmDocumentationSection* section)
+ cmDocumentationSection section)
{
- if (this->AllSections.find(name) != this->AllSections.end()) {
- delete this->AllSections[name];
- }
- this->AllSections[name] = section;
+ this->SectionAtName(name) = std::move(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);
+ cmDocumentationSection sec{ name };
+ sec.Append(docs);
+ this->SetSection(name, std::move(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);
+ cmDocumentationSection sec{ name };
+ sec.Append(docs);
+ this->SetSection(name, std::move(sec));
}
void cmDocumentation::SetSections(
- std::map<std::string, cmDocumentationSection*>& sections)
+ 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);
+ for (auto& s : sections) {
+ this->SetSection(s.first.c_str(), std::move(s.second));
}
}
+cmDocumentationSection& cmDocumentation::SectionAtName(const char* name)
+{
+ return this->AllSections.emplace(name, cmDocumentationSection{ name })
+ .first->second;
+}
void cmDocumentation::PrependSection(const char* name, const char* docs[][2])
{
- cmDocumentationSection* sec = CM_NULLPTR;
- 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);
+ this->SectionAtName(name).Prepend(docs);
}
void cmDocumentation::PrependSection(const char* name,
std::vector<cmDocumentationEntry>& docs)
{
- cmDocumentationSection* sec = CM_NULLPTR;
- 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);
+ this->SectionAtName(name).Prepend(docs);
}
void cmDocumentation::AppendSection(const char* name, const char* docs[][2])
{
- cmDocumentationSection* sec = CM_NULLPTR;
- 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);
+ this->SectionAtName(name).Append(docs);
}
void cmDocumentation::AppendSection(const char* name,
std::vector<cmDocumentationEntry>& docs)
{
- cmDocumentationSection* sec = CM_NULLPTR;
- 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);
+ this->SectionAtName(name).Append(docs);
}
void cmDocumentation::AppendSection(const char* name,
@@ -489,10 +450,9 @@ 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) {
+ for (std::string const& f : files) {
std::string line;
- cmsys::ifstream fin(i->c_str());
+ cmsys::ifstream fin(f.c_str());
while (fin && cmSystemTools::GetLineFromStream(fin, line)) {
if (!line.empty() && (isalnum(line[0]) || line[0] == '<')) {
names.push_back(line);
@@ -501,9 +461,8 @@ void cmDocumentation::PrintNames(std::ostream& os, std::string const& pattern)
}
}
std::sort(names.begin(), names.end());
- for (std::vector<std::string>::iterator i = names.begin(); i != names.end();
- ++i) {
- os << *i << "\n";
+ for (std::string const& n : names) {
+ os << n << "\n";
}
}
@@ -514,9 +473,8 @@ bool cmDocumentation::PrintFiles(std::ostream& os, std::string const& pattern)
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;
+ for (std::string const& f : files) {
+ found = r.ProcessFile(f) || found;
}
return found;
}
@@ -586,15 +544,13 @@ 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);
+ for (std::string const& f : files) {
+ std::string module = cmSystemTools::GetFilenameName(f);
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";
+ for (std::string const& m : modules) {
+ os << m << "\n";
}
return true;
}
@@ -640,11 +596,10 @@ bool cmDocumentation::PrintHelpListPolicies(std::ostream& os)
bool cmDocumentation::PrintHelpListGenerators(std::ostream& os)
{
- std::map<std::string, cmDocumentationSection*>::iterator si;
- si = this->AllSections.find("Generators");
+ const auto si = this->AllSections.find("Generators");
if (si != this->AllSections.end()) {
this->Formatter.SetIndent(" ");
- this->Formatter.PrintSection(os, *si->second);
+ this->Formatter.PrintSection(os, si->second);
}
return true;
}
@@ -670,29 +625,27 @@ bool cmDocumentation::PrintHelpListVariables(std::ostream& os)
bool cmDocumentation::PrintUsage(std::ostream& os)
{
- std::map<std::string, cmDocumentationSection*>::iterator si;
- si = this->AllSections.find("Usage");
+ const auto si = this->AllSections.find("Usage");
if (si != this->AllSections.end()) {
- this->Formatter.PrintSection(os, *si->second);
+ 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");
+ auto si = this->AllSections.find("Usage");
if (si != this->AllSections.end()) {
- this->Formatter.PrintSection(os, *si->second);
+ this->Formatter.PrintSection(os, si->second);
}
si = this->AllSections.find("Options");
if (si != this->AllSections.end()) {
- this->Formatter.PrintSection(os, *si->second);
+ 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);
+ this->Formatter.PrintSection(os, si->second);
}
}
return true;
diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h
index 2866fef03..cf74b800d 100644
--- a/Source/cmDocumentation.h
+++ b/Source/cmDocumentation.h
@@ -3,16 +3,16 @@
#ifndef _cmDocumentation_h
#define _cmDocumentation_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmDocumentationFormatter.h"
+#include "cmDocumentationSection.h"
#include <iosfwd>
#include <map>
#include <string>
#include <vector>
-class cmDocumentationSection;
struct cmDocumentationEntry;
/** Class to generate documentation. */
@@ -21,8 +21,6 @@ class cmDocumentation : public cmDocumentationEnums
public:
cmDocumentation();
- ~cmDocumentation();
-
/**
* Check command line arguments for documentation options. Returns
* true if documentation options are found, and false otherwise.
@@ -32,7 +30,7 @@ public:
* help arguments.
*/
bool CheckOptions(int argc, const char* const* argv,
- const char* exitOpt = CM_NULLPTR);
+ const char* exitOpt = nullptr);
/**
* Print help requested on the command line. Call after
@@ -52,11 +50,11 @@ public:
/** 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, 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);
+ 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]);
@@ -110,17 +108,14 @@ private:
bool ShowGenerators;
std::string NameString;
- std::map<std::string, cmDocumentationSection*> AllSections;
+ std::map<std::string, cmDocumentationSection> AllSections;
+ cmDocumentationSection& SectionAtName(const char* name);
std::string CurrentArgument;
struct RequestedHelpItem
{
- RequestedHelpItem()
- : HelpType(None)
- {
- }
- cmDocumentationEnums::Type HelpType;
+ cmDocumentationEnums::Type HelpType = None;
std::string Filename;
std::string Argument;
};
diff --git a/Source/cmDocumentationEntry.h b/Source/cmDocumentationEntry.h
index ea43b88c3..afbca5e4b 100644
--- a/Source/cmDocumentationEntry.h
+++ b/Source/cmDocumentationEntry.h
@@ -12,7 +12,8 @@ struct cmDocumentationEntry
{
std::string Name;
std::string Brief;
- cmDocumentationEntry() {}
+ char CustomNamePrefix = ' ';
+ cmDocumentationEntry() = default;
cmDocumentationEntry(const char* doc[2])
{
if (doc[0]) {
diff --git a/Source/cmDocumentationFormatter.cxx b/Source/cmDocumentationFormatter.cxx
index 001826318..3e7f9897e 100644
--- a/Source/cmDocumentationFormatter.cxx
+++ b/Source/cmDocumentationFormatter.cxx
@@ -5,20 +5,15 @@
#include "cmDocumentationEntry.h"
#include "cmDocumentationSection.h"
+#include <iomanip>
#include <ostream>
#include <string.h>
#include <string>
#include <vector>
-cmDocumentationFormatter::cmDocumentationFormatter()
- : TextWidth(77)
- , TextIndent("")
-{
-}
+cmDocumentationFormatter::cmDocumentationFormatter() = default;
-cmDocumentationFormatter::~cmDocumentationFormatter()
-{
-}
+cmDocumentationFormatter::~cmDocumentationFormatter() = default;
void cmDocumentationFormatter::PrintFormatted(std::ostream& os,
const char* text)
@@ -90,7 +85,7 @@ void cmDocumentationFormatter::SetIndent(const char* indent)
void cmDocumentationFormatter::PrintColumn(std::ostream& os, const char* text)
{
- // Print text arranged in an indented column of fixed witdh.
+ // Print text arranged in an indented column of fixed width.
const char* l = text;
long column = 0;
bool newSentence = false;
@@ -168,26 +163,25 @@ void cmDocumentationFormatter::PrintSection(
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.empty()) {
- os << " " << op->Name;
+ for (cmDocumentationEntry const& entry : entries) {
+ if (!entry.Name.empty()) {
+ os << std::setw(2) << std::left << entry.CustomNamePrefix << entry.Name;
this->TextIndent = " ";
int align = static_cast<int>(strlen(this->TextIndent)) - 4;
- for (int i = static_cast<int>(op->Name.size()); i < align; ++i) {
+ for (int i = static_cast<int>(entry.Name.size()); i < align; ++i) {
os << " ";
}
- if (op->Name.size() > strlen(this->TextIndent) - 4) {
+ if (entry.Name.size() > strlen(this->TextIndent) - 4) {
os << "\n";
os.write(this->TextIndent, strlen(this->TextIndent) - 2);
}
os << "= ";
- this->PrintColumn(os, op->Brief.c_str());
+ this->PrintColumn(os, entry.Brief.c_str());
os << "\n";
} else {
os << "\n";
this->TextIndent = "";
- this->PrintFormatted(os, op->Brief.c_str());
+ this->PrintFormatted(os, entry.Brief.c_str());
}
}
os << "\n";
diff --git a/Source/cmDocumentationFormatter.h b/Source/cmDocumentationFormatter.h
index 1f04250c9..17b63dacc 100644
--- a/Source/cmDocumentationFormatter.h
+++ b/Source/cmDocumentationFormatter.h
@@ -59,8 +59,8 @@ public:
void SetIndent(const char* indent);
private:
- int TextWidth;
- const char* TextIndent;
+ int TextWidth = 77;
+ const char* TextIndent = "";
};
#endif
diff --git a/Source/cmDocumentationSection.cxx b/Source/cmDocumentationSection.cxx
index c47f33e4f..439da1bc1 100644
--- a/Source/cmDocumentationSection.cxx
+++ b/Source/cmDocumentationSection.cxx
@@ -6,7 +6,7 @@ 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]));
+ this->Entries.emplace_back(data[i][0], data[i][1]);
data += 1;
}
}
@@ -16,7 +16,7 @@ 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]));
+ tmp.emplace_back(data[i][0], data[i][1]);
data += 1;
}
this->Entries.insert(this->Entries.begin(), tmp.begin(), tmp.end());
@@ -24,5 +24,5 @@ void cmDocumentationSection::Prepend(const char* data[][2])
void cmDocumentationSection::Append(const char* n, const char* b)
{
- this->Entries.push_back(cmDocumentationEntry(n, b));
+ this->Entries.emplace_back(n, b);
}
diff --git a/Source/cmDocumentationSection.h b/Source/cmDocumentationSection.h
index d9e8187f8..19c7407b7 100644
--- a/Source/cmDocumentationSection.h
+++ b/Source/cmDocumentationSection.h
@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
#include <string>
@@ -19,7 +20,7 @@ class cmDocumentationSection
{
public:
/** Create a cmSection, with a special name for man-output mode. */
- cmDocumentationSection(const char* name, const char*)
+ explicit cmDocumentationSection(const char* name)
: Name(name)
{
}
@@ -46,7 +47,7 @@ public:
}
void Append(const std::vector<cmDocumentationEntry>& entries)
{
- this->Entries.insert(this->Entries.end(), entries.begin(), entries.end());
+ cmAppend(this->Entries, entries);
}
/** Append an entry to this section using NULL terminated chars */
diff --git a/Source/cmDynamicLoader.cxx b/Source/cmDynamicLoader.cxx
index 7fbe75c7b..0549cf916 100644
--- a/Source/cmDynamicLoader.cxx
+++ b/Source/cmDynamicLoader.cxx
@@ -22,11 +22,9 @@ private:
static cmDynamicLoaderCache* Instance;
};
-cmDynamicLoaderCache* cmDynamicLoaderCache::Instance = CM_NULLPTR;
+cmDynamicLoaderCache* cmDynamicLoaderCache::Instance = nullptr;
-cmDynamicLoaderCache::~cmDynamicLoaderCache()
-{
-}
+cmDynamicLoaderCache::~cmDynamicLoaderCache() = default;
void cmDynamicLoaderCache::CacheFile(const char* path,
cmsys::DynamicLoader::LibraryHandle p)
@@ -65,13 +63,11 @@ bool cmDynamicLoaderCache::FlushCache(const char* path)
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);
+ for (auto const& it : this->CacheMap) {
+ cmsys::DynamicLoader::CloseLibrary(it.second);
}
delete cmDynamicLoaderCache::Instance;
- cmDynamicLoaderCache::Instance = CM_NULLPTR;
+ cmDynamicLoaderCache::Instance = nullptr;
}
cmDynamicLoaderCache* cmDynamicLoaderCache::GetInstance()
diff --git a/Source/cmDynamicLoader.h b/Source/cmDynamicLoader.h
index 7c46dd5d4..4b89388e2 100644
--- a/Source/cmDynamicLoader.h
+++ b/Source/cmDynamicLoader.h
@@ -8,14 +8,12 @@
#ifndef cmDynamicLoader_h
#define cmDynamicLoader_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmsys/DynamicLoader.hxx" // IWYU pragma: export
class cmDynamicLoader
{
- CM_DISABLE_COPY(cmDynamicLoader)
-
public:
// Description:
// Load a dynamic library into the current process.
@@ -28,8 +26,8 @@ public:
static void FlushCache();
protected:
- cmDynamicLoader() {}
- ~cmDynamicLoader() {}
+ cmDynamicLoader() = default;
+ ~cmDynamicLoader() = default;
};
#endif
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index fc97bf3b3..222646365 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -2,10 +2,11 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmELF.h"
-#include "cm_auto_ptr.hxx"
+#include "cmAlgorithms.h"
#include "cm_kwiml.h"
#include "cmsys/FStream.hxx"
#include <map>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stddef.h>
#include <utility>
@@ -13,39 +14,39 @@
// Include the ELF format information system header.
#if defined(__OpenBSD__)
-#include <elf_abi.h>
-#include <stdint.h>
+# include <elf_abi.h>
+# include <stdint.h>
#elif defined(__HAIKU__)
-#include <elf32.h>
-#include <elf64.h>
+# 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
+# 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>
+# include <elf.h>
#endif
#if defined(__sun)
-#include <sys/link.h> // For dynamic section information
+# include <sys/link.h> // For dynamic section information
#endif
#ifdef _SCO_DS
-#include <link.h> // For DT_SONAME etc.
+# include <link.h> // For DT_SONAME etc.
#endif
#ifndef DT_RUNPATH
-#define DT_RUNPATH 29
+# define DT_RUNPATH 29
#endif
// Low-level byte swapping implementation.
@@ -108,7 +109,7 @@ public:
};
// Construct and take ownership of the file stream object.
- cmELFInternal(cmELF* external, CM_AUTO_PTR<cmsys::ifstream>& fin,
+ cmELFInternal(cmELF* external, std::unique_ptr<cmsys::ifstream>& fin,
ByteOrderType order)
: External(external)
, Stream(*fin.release())
@@ -162,6 +163,7 @@ public:
// Return the recorded ELF type.
cmELF::FileType GetFileType() const { return this->ELFType; }
+
protected:
// Data common to all ELF class implementations.
@@ -231,27 +233,27 @@ public:
typedef typename Types::tagtype tagtype;
// Construct with a stream and byte swap indicator.
- cmELFInternalImpl(cmELF* external, CM_AUTO_PTR<cmsys::ifstream>& fin,
+ cmELFInternalImpl(cmELF* external, std::unique_ptr<cmsys::ifstream>& fin,
ByteOrderType order);
// Return the number of sections as specified by the ELF header.
- unsigned int GetNumberOfSections() const CM_OVERRIDE
+ unsigned int GetNumberOfSections() const override
{
return static_cast<unsigned int>(this->ELFHeader.e_shnum);
}
// Get the file position of a dynamic section entry.
- unsigned long GetDynamicEntryPosition(int j) CM_OVERRIDE;
+ unsigned long GetDynamicEntryPosition(int j) override;
- cmELF::DynamicEntryList GetDynamicEntries() CM_OVERRIDE;
- std::vector<char> EncodeDynamicEntries(const cmELF::DynamicEntryList&)
- CM_OVERRIDE;
+ cmELF::DynamicEntryList GetDynamicEntries() override;
+ std::vector<char> EncodeDynamicEntries(
+ const cmELF::DynamicEntryList&) override;
// Lookup a string from the dynamic section with the given tag.
- StringEntry const* GetDynamicSectionString(unsigned int tag) CM_OVERRIDE;
+ StringEntry const* GetDynamicSectionString(unsigned int tag) override;
// Print information about the ELF file.
- void PrintInfo(std::ostream& os) const CM_OVERRIDE
+ void PrintInfo(std::ostream& os) const override
{
os << "ELF " << Types::GetName();
if (this->ByteOrder == ByteOrderMSB) {
@@ -424,9 +426,8 @@ private:
};
template <class Types>
-cmELFInternalImpl<Types>::cmELFInternalImpl(cmELF* external,
- CM_AUTO_PTR<cmsys::ifstream>& fin,
- ByteOrderType order)
+cmELFInternalImpl<Types>::cmELFInternalImpl(
+ cmELF* external, std::unique_ptr<cmsys::ifstream>& fin, ByteOrderType order)
: cmELFInternal(external, fin, order)
{
// Read the main header.
@@ -547,12 +548,8 @@ cmELF::DynamicEntryList cmELFInternalImpl<Types>::GetDynamicEntries()
// Copy into public array
result.reserve(this->DynamicSectionEntries.size());
- for (typename std::vector<ELF_Dyn>::iterator di =
- this->DynamicSectionEntries.begin();
- di != this->DynamicSectionEntries.end(); ++di) {
- ELF_Dyn& dyn = *di;
- result.push_back(
- std::pair<unsigned long, unsigned long>(dyn.d_tag, dyn.d_un.d_val));
+ for (ELF_Dyn& dyn : this->DynamicSectionEntries) {
+ result.emplace_back(dyn.d_tag, dyn.d_un.d_val);
}
return result;
@@ -565,19 +562,18 @@ std::vector<char> cmELFInternalImpl<Types>::EncodeDynamicEntries(
std::vector<char> result;
result.reserve(sizeof(ELF_Dyn) * entries.size());
- for (cmELF::DynamicEntryList::const_iterator it = entries.begin();
- it != entries.end(); it++) {
+ for (auto const& entry : entries) {
// Store the entry in an ELF_Dyn, byteswap it, then serialize to chars
ELF_Dyn dyn;
- dyn.d_tag = static_cast<tagtype>(it->first);
- dyn.d_un.d_val = static_cast<tagtype>(it->second);
+ dyn.d_tag = static_cast<tagtype>(entry.first);
+ dyn.d_un.d_val = static_cast<tagtype>(entry.second);
if (this->NeedSwap) {
ByteSwap(dyn);
}
char* pdyn = reinterpret_cast<char*>(&dyn);
- result.insert(result.end(), pdyn, pdyn + sizeof(ELF_Dyn));
+ cmAppend(result, pdyn, pdyn + sizeof(ELF_Dyn));
}
return result;
@@ -594,7 +590,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
if (dssi->second.Position > 0) {
return &dssi->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
// Create an entry for this tag. Assume it is missing until found.
@@ -605,14 +601,14 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
// Try reading the dynamic section.
if (!this->LoadDynamicSection()) {
- return CM_NULLPTR;
+ return nullptr;
}
// 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 CM_NULLPTR;
+ return nullptr;
}
ELF_Shdr const& strtab = this->SectionHeaders[sec.sh_link];
@@ -627,7 +623,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
if (dyn.d_un.d_val >= strtab.sh_size) {
this->SetErrorMessage("Section DYNAMIC references string beyond "
"the end of its string section.");
- return CM_NULLPTR;
+ return nullptr;
}
// Seek to the position reported by the entry.
@@ -656,7 +652,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
if (!this->Stream) {
this->SetErrorMessage("Dynamic section specifies unreadable RPATH.");
se.Value = "";
- return CM_NULLPTR;
+ return nullptr;
}
// The value has been read successfully. Report it.
@@ -667,7 +663,7 @@ cmELF::StringEntry const* cmELFInternalImpl<Types>::GetDynamicSectionString(
return &se;
}
}
- return CM_NULLPTR;
+ return nullptr;
}
//============================================================================
@@ -683,13 +679,13 @@ const long cmELF::TagMipsRldMapRel = 0;
#endif
cmELF::cmELF(const char* fname)
- : Internal(CM_NULLPTR)
+ : Internal(nullptr)
{
// Try to open the file.
- CM_AUTO_PTR<cmsys::ifstream> fin(new cmsys::ifstream(fname));
+ std::unique_ptr<cmsys::ifstream> fin(new cmsys::ifstream(fname));
// Quit now if the file could not be opened.
- if (!fin.get() || !*fin) {
+ if (!fin || !*fin) {
this->ErrorMessage = "Error opening input file.";
return;
}
@@ -811,7 +807,7 @@ cmELF::StringEntry const* cmELF::GetSOName()
this->Internal->GetFileType() == cmELF::FileTypeSharedLibrary) {
return this->Internal->GetSOName();
}
- return CM_NULLPTR;
+ return nullptr;
}
cmELF::StringEntry const* cmELF::GetRPath()
@@ -821,7 +817,7 @@ cmELF::StringEntry const* cmELF::GetRPath()
this->Internal->GetFileType() == cmELF::FileTypeSharedLibrary)) {
return this->Internal->GetRPath();
}
- return CM_NULLPTR;
+ return nullptr;
}
cmELF::StringEntry const* cmELF::GetRunPath()
@@ -831,7 +827,7 @@ cmELF::StringEntry const* cmELF::GetRunPath()
this->Internal->GetFileType() == cmELF::FileTypeSharedLibrary)) {
return this->Internal->GetRunPath();
}
- return CM_NULLPTR;
+ return nullptr;
}
void cmELF::PrintInfo(std::ostream& os) const
diff --git a/Source/cmELF.h b/Source/cmELF.h
index a6e407fe1..987f0c3a4 100644
--- a/Source/cmELF.h
+++ b/Source/cmELF.h
@@ -3,7 +3,7 @@
#ifndef cmELF_h
#define cmELF_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -11,7 +11,7 @@
#include <vector>
#if !defined(CMAKE_USE_ELF_PARSER)
-#error "This file may be included only if CMAKE_USE_ELF_PARSER is enabled."
+# error "This file may be included only if CMAKE_USE_ELF_PARSER is enabled."
#endif
class cmELFInternal;
@@ -28,11 +28,14 @@ public:
/** Destruct. */
~cmELF();
+ cmELF(const cmELF&) = delete;
+ cmELF& operator=(const cmELF&) = delete;
+
/** 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(); }
+ explicit operator bool() const { return this->Valid(); }
/** Enumeration of ELF file types. */
enum FileType
@@ -64,7 +67,7 @@ public:
};
/** Represent entire dynamic section header */
- typedef std::vector<std::pair<long, unsigned long> > DynamicEntryList;
+ typedef std::vector<std::pair<long, unsigned long>> DynamicEntryList;
/** Get the type of the file opened. */
FileType GetFileType() const;
diff --git a/Source/cmEnableLanguageCommand.cxx b/Source/cmEnableLanguageCommand.cxx
index c57b7b15c..ddd26de9e 100644
--- a/Source/cmEnableLanguageCommand.cxx
+++ b/Source/cmEnableLanguageCommand.cxx
@@ -16,12 +16,11 @@ bool cmEnableLanguageCommand::InitialPass(std::vector<std::string> const& args,
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") {
+ for (std::string const& it : args) {
+ if (it == "OPTIONAL") {
optional = true;
} else {
- languages.push_back(*it);
+ languages.push_back(it);
}
}
diff --git a/Source/cmEnableLanguageCommand.h b/Source/cmEnableLanguageCommand.h
index 33c1c22bf..97645a98c 100644
--- a/Source/cmEnableLanguageCommand.h
+++ b/Source/cmEnableLanguageCommand.h
@@ -3,7 +3,7 @@
#ifndef cmEnableLanguageCommand_h
#define cmEnableLanguageCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -26,14 +26,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmEnableLanguageCommand; }
+ cmCommand* Clone() override { return new cmEnableLanguageCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmEnableTestingCommand.h b/Source/cmEnableTestingCommand.h
index e24966221..88a17b9bf 100644
--- a/Source/cmEnableTestingCommand.h
+++ b/Source/cmEnableTestingCommand.h
@@ -3,7 +3,7 @@
#ifndef cmEnableTestingCommand_h
#define cmEnableTestingCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -31,14 +31,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmEnableTestingCommand; }
+ cmCommand* Clone() override { return new cmEnableTestingCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const&,
- cmExecutionStatus&) CM_OVERRIDE;
+ cmExecutionStatus&) override;
};
#endif
diff --git a/Source/cmExecProgramCommand.cxx b/Source/cmExecProgramCommand.cxx
index fcc3c45c6..4b559e71a 100644
--- a/Source/cmExecProgramCommand.cxx
+++ b/Source/cmExecProgramCommand.cxx
@@ -26,8 +26,8 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
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") {
+ for (std::string const& arg : args) {
+ if (arg == "OUTPUT_VARIABLE") {
count++;
doingargs = false;
havereturn_variable = false;
@@ -37,10 +37,10 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
this->SetError("called with incorrect number of arguments");
return false;
}
- output_variable = args[i];
+ output_variable = arg;
haveoutput_variable = false;
count++;
- } else if (args[i] == "RETURN_VALUE") {
+ } else if (arg == "RETURN_VALUE") {
count++;
doingargs = false;
haveoutput_variable = false;
@@ -50,16 +50,16 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
this->SetError("called with incorrect number of arguments");
return false;
}
- return_variable = args[i];
+ return_variable = arg;
havereturn_variable = false;
count++;
- } else if (args[i] == "ARGS") {
+ } else if (arg == "ARGS") {
count++;
havereturn_variable = false;
haveoutput_variable = false;
doingargs = true;
} else if (doingargs) {
- arguments += args[i];
+ arguments += arg;
arguments += " ";
count++;
}
@@ -67,7 +67,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
std::string command;
if (!arguments.empty()) {
- command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str());
+ command = cmSystemTools::ConvertToRunCommandPath(args[0]);
command += " ";
command += arguments;
} else {
@@ -81,12 +81,12 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
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,
+ cmSystemTools::MakeDirectory(args[1]);
+ result = cmExecProgramCommand::RunCommand(command, output, retVal,
args[1].c_str(), verbose);
} else {
- result = cmExecProgramCommand::RunCommand(command.c_str(), output, retVal,
- CM_NULLPTR, verbose);
+ result = cmExecProgramCommand::RunCommand(command, output, retVal, nullptr,
+ verbose);
}
if (!result) {
retVal = -1;
@@ -115,7 +115,7 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args,
return true;
}
-bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
+bool cmExecProgramCommand::RunCommand(std::string command, std::string& output,
int& retVal, const char* dir,
bool verbose, Encoding encoding)
{
@@ -128,12 +128,11 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
// 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] == '\"') {
+ if (!command.empty() && command[0] == '\"') {
// count the number of quotes
- for (const char* s = command; *s != 0; ++s) {
- if (*s == '\"') {
+ int count = 0;
+ for (char c : command) {
+ if (c == '\"') {
count++;
if (count > 2) {
break;
@@ -147,20 +146,21 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
if (count > 2) {
cmsys::RegularExpression quoted("^\"([^\"]*)\"[ \t](.*)");
if (quoted.find(command)) {
+ std::string shortCmd;
std::string cmd = quoted.match(1);
std::string args = quoted.match(2);
- if (!cmSystemTools::FileExists(cmd.c_str())) {
+ if (!cmSystemTools::FileExists(cmd)) {
shortCmd = cmd;
- } else if (!cmSystemTools::GetShortPath(cmd.c_str(), shortCmd)) {
- cmSystemTools::Error("GetShortPath failed for ", cmd.c_str());
+ } else if (!cmSystemTools::GetShortPath(cmd, shortCmd)) {
+ cmSystemTools::Error("GetShortPath failed for " + cmd);
return false;
}
shortCmd += " ";
shortCmd += args;
- command = shortCmd.c_str();
+ command = shortCmd;
} else {
- cmSystemTools::Error("Could not parse command line with quotes ",
+ cmSystemTools::Error("Could not parse command line with quotes " +
command);
}
}
@@ -182,7 +182,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
}
cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
- const char* cmd[] = { command, 0 };
+ const char* cmd[] = { command.c_str(), nullptr };
cmsysProcess_SetCommand(cp, cmd);
#else
std::string commandInDir;
@@ -194,10 +194,10 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
} else {
commandInDir = command;
}
-#ifndef __VMS
+# ifndef __VMS
commandInDir += " 2>&1";
-#endif
- command = commandInDir.c_str();
+# endif
+ command = commandInDir;
if (verbose) {
cmSystemTools::Stdout("running ");
cmSystemTools::Stdout(command);
@@ -205,7 +205,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
}
fflush(stdout);
fflush(stderr);
- const char* cmd[] = { "/bin/sh", "-c", command, CM_NULLPTR };
+ const char* cmd[] = { "/bin/sh", "-c", command.c_str(), nullptr };
cmsysProcess_SetCommand(cp, cmd);
#endif
@@ -217,11 +217,11 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
int p;
cmProcessOutput processOutput(encoding);
std::string strdata;
- while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
+ while ((p = cmsysProcess_WaitForData(cp, &data, &length, nullptr))) {
if (p == cmsysProcess_Pipe_STDOUT || p == cmsysProcess_Pipe_STDERR) {
if (verbose) {
processOutput.DecodeText(data, length, strdata);
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
}
output.append(data, length);
}
@@ -230,12 +230,12 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
if (verbose) {
processOutput.DecodeText(std::string(), strdata);
if (!strdata.empty()) {
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
}
}
// All output has been read. Wait for the process to exit.
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
processOutput.DecodeText(output, output);
// Check the result of running the process.
@@ -270,7 +270,7 @@ bool cmExecProgramCommand::RunCommand(const char* command, std::string& output,
}
msg += "\n";
if (verbose) {
- cmSystemTools::Stdout(msg.c_str());
+ cmSystemTools::Stdout(msg);
}
output += msg;
#else
diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h
index 6463c4db5..ae0fa9b84 100644
--- a/Source/cmExecProgramCommand.h
+++ b/Source/cmExecProgramCommand.h
@@ -3,7 +3,7 @@
#ifndef cmExecProgramCommand_h
#define cmExecProgramCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -27,19 +27,18 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmExecProgramCommand; }
+ cmCommand* Clone() override { return new cmExecProgramCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- static bool RunCommand(const char* command, std::string& output, int& retVal,
- const char* directory = CM_NULLPTR,
- bool verbose = true,
+ static bool RunCommand(std::string command, std::string& output, int& retVal,
+ const char* directory = nullptr, bool verbose = true,
Encoding encoding = cmProcessOutput::Auto);
};
diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx
index 8c10dbe29..494afbb55 100644
--- a/Source/cmExecuteProcessCommand.cxx
+++ b/Source/cmExecuteProcessCommand.cxx
@@ -2,12 +2,17 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExecuteProcessCommand.h"
+#include "cm_static_string_view.hxx"
#include "cmsys/Process.h"
+#include <algorithm>
#include <ctype.h> /* isspace */
-#include <sstream>
+#include <iostream>
#include <stdio.h>
+#include "cmAlgorithms.h"
+#include "cmArgumentParser.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmProcessOutput.h"
#include "cmSystemTools.h"
@@ -15,7 +20,7 @@ class cmExecutionStatus;
static bool cmExecuteProcessCommandIsWhitespace(char c)
{
- return (isspace((int)c) || c == '\n' || c == '\r');
+ return (isspace(static_cast<int>(c)) || c == '\n' || c == '\r');
}
void cmExecuteProcessCommandFixText(std::vector<char>& output,
@@ -31,164 +36,108 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
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;
- cmProcessOutput::Encoding encoding = cmProcessOutput::None;
- 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 (args[i] == "ENCODING") {
- doing_command = false;
- if (++i < args.size()) {
- encoding = cmProcessOutput::FindEncoding(args[i]);
- } else {
- this->SetError(" called with no value for ENCODING.");
- return false;
- }
- } else if (doing_command) {
- cmds[command_index].push_back(args[i].c_str());
- } else {
- std::ostringstream e;
- e << " given unknown argument \"" << args[i] << "\".";
- this->SetError(e.str());
- return false;
- }
+
+ struct Arguments
+ {
+ std::vector<std::vector<std::string>> Commands;
+ std::string OutputVariable;
+ std::string ErrorVariable;
+ std::string ResultVariable;
+ std::string ResultsVariable;
+ std::string WorkingDirectory;
+ std::string InputFile;
+ std::string OutputFile;
+ std::string ErrorFile;
+ std::string Timeout;
+ std::string CommandEcho;
+ bool OutputQuiet = false;
+ bool ErrorQuiet = false;
+ bool OutputStripTrailingWhitespace = false;
+ bool ErrorStripTrailingWhitespace = false;
+ std::string Encoding;
+ };
+
+ static auto const parser =
+ cmArgumentParser<Arguments>{}
+ .Bind("COMMAND"_s, &Arguments::Commands)
+ .Bind("COMMAND_ECHO"_s, &Arguments::CommandEcho)
+ .Bind("OUTPUT_VARIABLE"_s, &Arguments::OutputVariable)
+ .Bind("ERROR_VARIABLE"_s, &Arguments::ErrorVariable)
+ .Bind("RESULT_VARIABLE"_s, &Arguments::ResultVariable)
+ .Bind("RESULTS_VARIABLE"_s, &Arguments::ResultsVariable)
+ .Bind("WORKING_DIRECTORY"_s, &Arguments::WorkingDirectory)
+ .Bind("INPUT_FILE"_s, &Arguments::InputFile)
+ .Bind("OUTPUT_FILE"_s, &Arguments::OutputFile)
+ .Bind("ERROR_FILE"_s, &Arguments::ErrorFile)
+ .Bind("TIMEOUT"_s, &Arguments::Timeout)
+ .Bind("OUTPUT_QUIET"_s, &Arguments::OutputQuiet)
+ .Bind("ERROR_QUIET"_s, &Arguments::ErrorQuiet)
+ .Bind("OUTPUT_STRIP_TRAILING_WHITESPACE"_s,
+ &Arguments::OutputStripTrailingWhitespace)
+ .Bind("ERROR_STRIP_TRAILING_WHITESPACE"_s,
+ &Arguments::ErrorStripTrailingWhitespace)
+ .Bind("ENCODING"_s, &Arguments::Encoding);
+
+ std::vector<std::string> unparsedArguments;
+ std::vector<std::string> keywordsMissingValue;
+ Arguments const arguments =
+ parser.Parse(args, &unparsedArguments, &keywordsMissingValue);
+
+ if (!keywordsMissingValue.empty()) {
+ this->SetError(" called with no value for " +
+ keywordsMissingValue.front() + ".");
+ return false;
+ }
+ if (!unparsedArguments.empty()) {
+ this->SetError(" given unknown argument \"" + unparsedArguments.front() +
+ "\".");
+ 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);
+ if (!this->Makefile->CanIWriteThisFile(arguments.OutputFile)) {
+ this->SetError("attempted to output into a file: " + arguments.OutputFile +
+ " into a source directory.");
cmSystemTools::SetFatalErrorOccured();
return false;
}
// Check for commands given.
- if (cmds.empty()) {
+ if (arguments.Commands.empty()) {
this->SetError(" called with no COMMAND argument.");
return false;
}
- for (unsigned int i = 0; i < cmds.size(); ++i) {
- if (cmds[i].empty()) {
+ for (std::vector<std::string> const& cmd : arguments.Commands) {
+ if (cmd.empty()) {
this->SetError(" given COMMAND argument with no value.");
return false;
}
- // Add the null terminating pointer to the command argument list.
- cmds[i].push_back(CM_NULLPTR);
}
// Parse the timeout string.
double timeout = -1;
- if (!timeout_string.empty()) {
- if (sscanf(timeout_string.c_str(), "%lg", &timeout) != 1) {
+ if (!arguments.Timeout.empty()) {
+ if (sscanf(arguments.Timeout.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();
+ std::unique_ptr<cmsysProcess, void (*)(cmsysProcess*)> cp_ptr(
+ cmsysProcess_New(), cmsysProcess_Delete);
+ cmsysProcess* cp = cp_ptr.get();
// Set the command sequence.
- for (unsigned int i = 0; i < cmds.size(); ++i) {
- cmsysProcess_AddCommand(cp, &*cmds[i].begin());
+ for (std::vector<std::string> const& cmd : arguments.Commands) {
+ std::vector<const char*> argv(cmd.size() + 1);
+ std::transform(cmd.begin(), cmd.end(), argv.begin(),
+ [](std::string const& s) { return s.c_str(); });
+ argv.back() = nullptr;
+ cmsysProcess_AddCommand(cp, argv.data());
}
// Set the process working directory.
- if (!working_directory.empty()) {
- cmsysProcess_SetWorkingDirectory(cp, working_directory.c_str());
+ if (!arguments.WorkingDirectory.empty()) {
+ cmsysProcess_SetWorkingDirectory(cp, arguments.WorkingDirectory.c_str());
}
// Always hide the process window.
@@ -196,22 +145,24 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
// Check the output variables.
bool merge_output = false;
- if (!input_file.empty()) {
- cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDIN, input_file.c_str());
+ if (!arguments.InputFile.empty()) {
+ cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDIN,
+ arguments.InputFile.c_str());
}
- if (!output_file.empty()) {
+ if (!arguments.OutputFile.empty()) {
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDOUT,
- output_file.c_str());
+ arguments.OutputFile.c_str());
}
- if (!error_file.empty()) {
- if (error_file == output_file) {
+ if (!arguments.ErrorFile.empty()) {
+ if (arguments.ErrorFile == arguments.OutputFile) {
merge_output = true;
} else {
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDERR,
- error_file.c_str());
+ arguments.ErrorFile.c_str());
}
}
- if (!output_variable.empty() && output_variable == error_variable) {
+ if (!arguments.OutputVariable.empty() &&
+ arguments.OutputVariable == arguments.ErrorVariable) {
merge_output = true;
}
if (merge_output) {
@@ -223,6 +174,51 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
cmsysProcess_SetTimeout(cp, timeout);
}
+ bool echo_stdout = false;
+ bool echo_stderr = false;
+ bool echo_output_from_variable = true;
+ std::string echo_output =
+ this->Makefile->GetSafeDefinition("CMAKE_EXECUTE_PROCESS_COMMAND_ECHO");
+ if (!arguments.CommandEcho.empty()) {
+ echo_output_from_variable = false;
+ echo_output = arguments.CommandEcho;
+ }
+
+ if (!echo_output.empty()) {
+ if (echo_output == "STDERR") {
+ echo_stderr = true;
+ } else if (echo_output == "STDOUT") {
+ echo_stdout = true;
+ } else if (echo_output != "NONE") {
+ std::string error;
+ if (echo_output_from_variable) {
+ error = "CMAKE_EXECUTE_PROCESS_COMMAND_ECHO set to '";
+ } else {
+ error = " called with '";
+ }
+ error += echo_output;
+ error += "' expected STDERR|STDOUT|NONE";
+ if (!echo_output_from_variable) {
+ error += " for COMMAND_ECHO.";
+ }
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, error);
+ return true;
+ }
+ }
+ if (echo_stdout || echo_stderr) {
+ std::string command;
+ for (auto& cmd : arguments.Commands) {
+ command += "'";
+ command += cmJoin(cmd, "' '");
+ command += "'";
+ command += "\n";
+ }
+ if (echo_stdout) {
+ std::cout << command;
+ } else if (echo_stderr) {
+ std::cerr << command;
+ }
+ }
// Start the process.
cmsysProcess_Execute(cp);
@@ -232,82 +228,124 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
int length;
char* data;
int p;
- cmProcessOutput processOutput(encoding);
+ cmProcessOutput processOutput(
+ cmProcessOutput::FindEncoding(arguments.Encoding));
std::string strdata;
- while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
+ while ((p = cmsysProcess_WaitForData(cp, &data, &length, nullptr))) {
// Put the output in the right place.
- if (p == cmsysProcess_Pipe_STDOUT && !output_quiet) {
- if (output_variable.empty()) {
+ if (p == cmsysProcess_Pipe_STDOUT && !arguments.OutputQuiet) {
+ if (arguments.OutputVariable.empty()) {
processOutput.DecodeText(data, length, strdata, 1);
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
} else {
cmExecuteProcessCommandAppend(tempOutput, data, length);
}
- } else if (p == cmsysProcess_Pipe_STDERR && !error_quiet) {
- if (error_variable.empty()) {
+ } else if (p == cmsysProcess_Pipe_STDERR && !arguments.ErrorQuiet) {
+ if (arguments.ErrorVariable.empty()) {
processOutput.DecodeText(data, length, strdata, 2);
- cmSystemTools::Stderr(strdata.c_str(), strdata.size());
+ cmSystemTools::Stderr(strdata);
} else {
cmExecuteProcessCommandAppend(tempError, data, length);
}
}
}
- if (!output_quiet && output_variable.empty()) {
+ if (!arguments.OutputQuiet && arguments.OutputVariable.empty()) {
processOutput.DecodeText(std::string(), strdata, 1);
if (!strdata.empty()) {
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
}
}
- if (!error_quiet && error_variable.empty()) {
+ if (!arguments.ErrorQuiet && arguments.ErrorVariable.empty()) {
processOutput.DecodeText(std::string(), strdata, 2);
if (!strdata.empty()) {
- cmSystemTools::Stderr(strdata.c_str(), strdata.size());
+ cmSystemTools::Stderr(strdata);
}
}
// All output has been read. Wait for the process to exit.
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
processOutput.DecodeText(tempOutput, tempOutput);
processOutput.DecodeText(tempError, tempError);
// Fix the text in the output strings.
- cmExecuteProcessCommandFixText(tempOutput, output_strip_trailing_whitespace);
- cmExecuteProcessCommandFixText(tempError, error_strip_trailing_whitespace);
+ cmExecuteProcessCommandFixText(tempOutput,
+ arguments.OutputStripTrailingWhitespace);
+ cmExecuteProcessCommandFixText(tempError,
+ arguments.ErrorStripTrailingWhitespace);
// Store the output obtained.
- if (!output_variable.empty() && !tempOutput.empty()) {
- this->Makefile->AddDefinition(output_variable, &*tempOutput.begin());
+ if (!arguments.OutputVariable.empty() && !tempOutput.empty()) {
+ this->Makefile->AddDefinition(arguments.OutputVariable, tempOutput.data());
}
- if (!merge_output && !error_variable.empty() && !tempError.empty()) {
- this->Makefile->AddDefinition(error_variable, &*tempError.begin());
+ if (!merge_output && !arguments.ErrorVariable.empty() &&
+ !tempError.empty()) {
+ this->Makefile->AddDefinition(arguments.ErrorVariable, tempError.data());
}
// Store the result of running the process.
- if (!result_variable.empty()) {
+ if (!arguments.ResultVariable.empty()) {
switch (cmsysProcess_GetState(cp)) {
case cmsysProcess_State_Exited: {
int v = cmsysProcess_GetExitValue(cp);
- char buf[100];
+ char buf[16];
sprintf(buf, "%d", v);
- this->Makefile->AddDefinition(result_variable, buf);
+ this->Makefile->AddDefinition(arguments.ResultVariable, buf);
} break;
case cmsysProcess_State_Exception:
- this->Makefile->AddDefinition(result_variable,
+ this->Makefile->AddDefinition(arguments.ResultVariable,
cmsysProcess_GetExceptionString(cp));
break;
case cmsysProcess_State_Error:
- this->Makefile->AddDefinition(result_variable,
+ this->Makefile->AddDefinition(arguments.ResultVariable,
cmsysProcess_GetErrorString(cp));
break;
case cmsysProcess_State_Expired:
- this->Makefile->AddDefinition(result_variable,
+ this->Makefile->AddDefinition(arguments.ResultVariable,
+ "Process terminated due to timeout");
+ break;
+ }
+ }
+ // Store the result of running the processes.
+ if (!arguments.ResultsVariable.empty()) {
+ switch (cmsysProcess_GetState(cp)) {
+ case cmsysProcess_State_Exited: {
+ std::vector<std::string> res;
+ for (size_t i = 0; i < arguments.Commands.size(); ++i) {
+ switch (cmsysProcess_GetStateByIndex(cp, static_cast<int>(i))) {
+ case kwsysProcess_StateByIndex_Exited: {
+ int exitCode =
+ cmsysProcess_GetExitValueByIndex(cp, static_cast<int>(i));
+ char buf[16];
+ sprintf(buf, "%d", exitCode);
+ res.emplace_back(buf);
+ } break;
+ case kwsysProcess_StateByIndex_Exception:
+ res.emplace_back(cmsysProcess_GetExceptionStringByIndex(
+ cp, static_cast<int>(i)));
+ break;
+ case kwsysProcess_StateByIndex_Error:
+ default:
+ res.emplace_back("Error getting the child return code");
+ break;
+ }
+ }
+ this->Makefile->AddDefinition(arguments.ResultsVariable,
+ cmJoin(res, ";").c_str());
+ } break;
+ case cmsysProcess_State_Exception:
+ this->Makefile->AddDefinition(arguments.ResultsVariable,
+ cmsysProcess_GetExceptionString(cp));
+ break;
+ case cmsysProcess_State_Error:
+ this->Makefile->AddDefinition(arguments.ResultsVariable,
+ cmsysProcess_GetErrorString(cp));
+ break;
+ case cmsysProcess_State_Expired:
+ this->Makefile->AddDefinition(arguments.ResultsVariable,
"Process terminated due to timeout");
break;
}
}
-
- // Delete the process instance.
- cmsysProcess_Delete(cp);
return true;
}
@@ -355,5 +393,5 @@ void cmExecuteProcessCommandAppend(std::vector<char>& output, const char* data,
--length;
}
#endif
- output.insert(output.end(), data, data + length);
+ cmAppend(output, data, data + length);
}
diff --git a/Source/cmExecuteProcessCommand.h b/Source/cmExecuteProcessCommand.h
index 08fde0adc..b415deb58 100644
--- a/Source/cmExecuteProcessCommand.h
+++ b/Source/cmExecuteProcessCommand.h
@@ -3,7 +3,7 @@
#ifndef cmExecuteProcessCommand_h
#define cmExecuteProcessCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmExecuteProcessCommand; }
+ cmCommand* Clone() override { return new cmExecuteProcessCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmExecutionStatus.h b/Source/cmExecutionStatus.h
index ac5fe1d72..56199dd93 100644
--- a/Source/cmExecutionStatus.h
+++ b/Source/cmExecutionStatus.h
@@ -11,14 +11,6 @@
class cmExecutionStatus
{
public:
- cmExecutionStatus()
- : ReturnInvoked(false)
- , BreakInvoked(false)
- , ContinueInvoked(false)
- , NestedError(false)
- {
- }
-
void Clear()
{
this->ReturnInvoked = false;
@@ -40,10 +32,10 @@ public:
bool GetNestedError() const { return this->NestedError; }
private:
- bool ReturnInvoked;
- bool BreakInvoked;
- bool ContinueInvoked;
- bool NestedError;
+ bool ReturnInvoked = false;
+ bool BreakInvoked = false;
+ bool ContinueInvoked = false;
+ bool NestedError = false;
};
#endif
diff --git a/Source/cmExpandedCommandArgument.cxx b/Source/cmExpandedCommandArgument.cxx
index 0bea65fd0..43f648bc3 100644
--- a/Source/cmExpandedCommandArgument.cxx
+++ b/Source/cmExpandedCommandArgument.cxx
@@ -2,14 +2,13 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExpandedCommandArgument.h"
-cmExpandedCommandArgument::cmExpandedCommandArgument()
- : Quoted(false)
-{
-}
+#include <utility>
-cmExpandedCommandArgument::cmExpandedCommandArgument(std::string const& value,
+cmExpandedCommandArgument::cmExpandedCommandArgument() = default;
+
+cmExpandedCommandArgument::cmExpandedCommandArgument(std::string value,
bool quoted)
- : Value(value)
+ : Value(std::move(value))
, Quoted(quoted)
{
}
@@ -24,6 +23,11 @@ bool cmExpandedCommandArgument::WasQuoted() const
return this->Quoted;
}
+bool cmExpandedCommandArgument::operator==(const char* value) const
+{
+ return this->Value == value;
+}
+
bool cmExpandedCommandArgument::operator==(std::string const& value) const
{
return this->Value == value;
diff --git a/Source/cmExpandedCommandArgument.h b/Source/cmExpandedCommandArgument.h
index fe86528db..69d35debe 100644
--- a/Source/cmExpandedCommandArgument.h
+++ b/Source/cmExpandedCommandArgument.h
@@ -18,12 +18,13 @@ class cmExpandedCommandArgument
{
public:
cmExpandedCommandArgument();
- cmExpandedCommandArgument(std::string const& value, bool quoted);
+ cmExpandedCommandArgument(std::string value, bool quoted);
std::string const& GetValue() const;
bool WasQuoted() const;
+ bool operator==(const char* value) const;
bool operator==(std::string const& value) const;
bool empty() const;
@@ -32,7 +33,7 @@ public:
private:
std::string Value;
- bool Quoted;
+ bool Quoted = false;
};
#endif
diff --git a/Source/cmExportBuildAndroidMKGenerator.cxx b/Source/cmExportBuildAndroidMKGenerator.cxx
index b443fb0b4..ced27c91c 100644
--- a/Source/cmExportBuildAndroidMKGenerator.cxx
+++ b/Source/cmExportBuildAndroidMKGenerator.cxx
@@ -3,26 +3,24 @@
#include "cmExportBuildAndroidMKGenerator.h"
#include <algorithm>
-#include <map>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <utility>
-#include "cmGeneratorExpression.h"
+#include "cmAlgorithms.h"
#include "cmGeneratorTarget.h"
#include "cmLinkItem.h"
-#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator()
{
- this->LG = CM_NULLPTR;
- this->ExportSet = CM_NULLPTR;
+ this->LG = nullptr;
+ this->ExportSet = nullptr;
}
void cmExportBuildAndroidMKGenerator::GenerateImportHeaderCode(
@@ -41,7 +39,8 @@ void cmExportBuildAndroidMKGenerator::GenerateExpectedTargetsCode(
}
void cmExportBuildAndroidMKGenerator::GenerateImportTargetCode(
- std::ostream& os, const cmGeneratorTarget* target)
+ std::ostream& os, cmGeneratorTarget const* target,
+ cmStateEnums::TargetType /*targetType*/)
{
std::string targetName = this->Namespace;
targetName += target->GetExportName();
@@ -49,8 +48,7 @@ void cmExportBuildAndroidMKGenerator::GenerateImportTargetCode(
os << "LOCAL_MODULE := ";
os << targetName << "\n";
os << "LOCAL_SRC_FILES := ";
- std::string path =
- cmSystemTools::ConvertToOutputPath(target->GetFullPath().c_str());
+ std::string path = cmSystemTools::ConvertToOutputPath(target->GetFullPath());
os << path << "\n";
}
@@ -94,57 +92,45 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
}
w << " set to OLD for target " << target->Target->GetName() << ". "
<< "The export will only work with CMP0022 set to NEW.";
- target->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
if (!properties.empty()) {
os << "LOCAL_CPP_FEATURES := rtti exceptions\n";
- for (ImportPropertyMap::const_iterator pi = properties.begin();
- pi != properties.end(); ++pi) {
- if (pi->first == "INTERFACE_COMPILE_OPTIONS") {
+ for (auto const& property : properties) {
+ if (property.first == "INTERFACE_COMPILE_OPTIONS") {
os << "LOCAL_CPP_FEATURES += ";
- os << (pi->second) << "\n";
- } else if (pi->first == "INTERFACE_LINK_LIBRARIES") {
- // need to look at list in pi->second and see if static or shared
- // FindTargetToLink
- // target->GetLocalGenerator()->FindGeneratorTargetToUse()
- // then add to LOCAL_CPPFLAGS
- std::vector<std::string> libraries;
- cmSystemTools::ExpandListArgument(pi->second, libraries);
+ os << (property.second) << "\n";
+ } else if (property.first == "INTERFACE_LINK_LIBRARIES") {
std::string staticLibs;
std::string sharedLibs;
std::string ldlibs;
- for (std::vector<std::string>::iterator i = libraries.begin();
- i != libraries.end(); ++i) {
- cmGeneratorTarget* gt =
- target->GetLocalGenerator()->FindGeneratorTargetToUse(*i);
+ cmLinkInterfaceLibraries const* linkIFace =
+ target->GetLinkInterfaceLibraries(config, target, false);
+ for (cmLinkItem const& item : linkIFace->Libraries) {
+ cmGeneratorTarget const* gt = item.Target;
+ std::string const& lib = item.AsStr();
if (gt) {
if (gt->GetType() == cmStateEnums::SHARED_LIBRARY ||
gt->GetType() == cmStateEnums::MODULE_LIBRARY) {
- sharedLibs += " " + *i;
+ sharedLibs += " " + lib;
} else {
- staticLibs += " " + *i;
+ staticLibs += " " + lib;
}
} else {
- // evaluate any generator expressions with the current
- // build type of the makefile
- cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
- std::string evaluated =
- cge->Evaluate(target->GetLocalGenerator(), config);
bool relpath = false;
if (type == cmExportBuildAndroidMKGenerator::INSTALL) {
- relpath = i->substr(0, 3) == "../";
+ relpath = lib.substr(0, 3) == "../";
}
// check for full path or if it already has a -l, or
// in the case of an install check for relative paths
// if it is full or a link library then use string directly
- if (cmSystemTools::FileIsFullPath(evaluated) ||
- evaluated.substr(0, 2) == "-l" || relpath) {
- ldlibs += " " + evaluated;
+ if (cmSystemTools::FileIsFullPath(lib) ||
+ lib.substr(0, 2) == "-l" || relpath) {
+ ldlibs += " " + lib;
// if it is not a path and does not have a -l then add -l
- } else if (!evaluated.empty()) {
- ldlibs += " -l" + evaluated;
+ } else if (!lib.empty()) {
+ ldlibs += " -l" + lib;
}
}
}
@@ -157,20 +143,24 @@ void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
if (!ldlibs.empty()) {
os << "LOCAL_EXPORT_LDLIBS :=" << ldlibs << "\n";
}
- } else if (pi->first == "INTERFACE_INCLUDE_DIRECTORIES") {
- std::string includes = pi->second;
+ } else if (property.first == "INTERFACE_INCLUDE_DIRECTORIES") {
+ std::string includes = property.second;
std::vector<std::string> includeList;
cmSystemTools::ExpandListArgument(includes, includeList);
os << "LOCAL_EXPORT_C_INCLUDES := ";
std::string end;
- for (std::vector<std::string>::iterator i = includeList.begin();
- i != includeList.end(); ++i) {
- os << end << *i;
+ for (std::string const& i : includeList) {
+ os << end << i;
end = "\\\n";
}
os << "\n";
+ } else if (property.first == "INTERFACE_LINK_OPTIONS") {
+ os << "LOCAL_EXPORT_LDFLAGS := ";
+ std::vector<std::string> linkFlagsList;
+ cmSystemTools::ExpandListArgument(property.second, linkFlagsList);
+ os << cmJoin(linkFlagsList, " ") << "\n";
} else {
- os << "# " << pi->first << " " << (pi->second) << "\n";
+ os << "# " << property.first << " " << (property.second) << "\n";
}
}
}
diff --git a/Source/cmExportBuildAndroidMKGenerator.h b/Source/cmExportBuildAndroidMKGenerator.h
index d028ef48d..a9b6107f8 100644
--- a/Source/cmExportBuildAndroidMKGenerator.h
+++ b/Source/cmExportBuildAndroidMKGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmExportBuildAndroidMKGenerator_h
#define cmExportBuildAndroidMKGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -11,6 +11,7 @@
#include "cmExportBuildFileGenerator.h"
#include "cmExportFileGenerator.h"
+#include "cmStateTypes.h"
class cmGeneratorTarget;
@@ -42,25 +43,25 @@ public:
protected:
// Implement virtual methods from the superclass.
- void GeneratePolicyHeaderCode(std::ostream&) CM_OVERRIDE {}
- void GeneratePolicyFooterCode(std::ostream&) CM_OVERRIDE {}
+ void GeneratePolicyHeaderCode(std::ostream&) override {}
+ void GeneratePolicyFooterCode(std::ostream&) override {}
void GenerateImportHeaderCode(std::ostream& os,
- const std::string& config = "") CM_OVERRIDE;
- void GenerateImportFooterCode(std::ostream& os) CM_OVERRIDE;
- void GenerateImportTargetCode(std::ostream& os,
- const cmGeneratorTarget* target) CM_OVERRIDE;
+ const std::string& config = "") override;
+ void GenerateImportFooterCode(std::ostream& os) override;
+ void GenerateImportTargetCode(
+ std::ostream& os, cmGeneratorTarget const* target,
+ cmStateEnums::TargetType /*targetType*/) override;
void GenerateExpectedTargetsCode(
- std::ostream& os, const std::string& expectedTargets) CM_OVERRIDE;
- void GenerateImportPropertyCode(std::ostream& os, const std::string& config,
- cmGeneratorTarget const* target,
- ImportPropertyMap const& properties)
- CM_OVERRIDE;
+ std::ostream& os, const std::string& expectedTargets) override;
+ void GenerateImportPropertyCode(
+ std::ostream& os, const std::string& config,
+ cmGeneratorTarget const* target,
+ ImportPropertyMap const& properties) override;
void GenerateMissingTargetsCheckCode(
- std::ostream& os,
- const std::vector<std::string>& missingTargets) CM_OVERRIDE;
+ std::ostream& os, const std::vector<std::string>& missingTargets) override;
void GenerateInterfaceProperties(
cmGeneratorTarget const* target, std::ostream& os,
- const ImportPropertyMap& properties) CM_OVERRIDE;
+ const ImportPropertyMap& properties) override;
};
#endif
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index a1c424aca..012355b41 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -9,6 +9,7 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
@@ -26,8 +27,8 @@ class cmSourceFile;
cmExportBuildFileGenerator::cmExportBuildFileGenerator()
{
- this->LG = CM_NULLPTR;
- this->ExportSet = CM_NULLPTR;
+ this->LG = nullptr;
+ this->ExportSet = nullptr;
}
void cmExportBuildFileGenerator::Compute(cmLocalGenerator* lg)
@@ -45,9 +46,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
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) {
- cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(*tei);
+ for (std::string const& tei : targets) {
+ cmGeneratorTarget* te = this->LG->FindGeneratorTargetToUse(tei);
expectedTargets += sep + this->Namespace + te->GetExportName();
sep = " ";
if (this->ExportedTargets.insert(te).second) {
@@ -56,11 +56,11 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
std::ostringstream e;
e << "given target \"" << te->GetName() << "\" more than once.";
this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR, e.str(),
+ MessageType::FATAL_ERROR, e.str(),
this->LG->GetMakefile()->GetBacktrace());
return false;
}
- if (te->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ if (this->GetExportTargetType(te) == cmStateEnums::INTERFACE_LIBRARY) {
this->GenerateRequiredCMakeVersion(os, "3.0.0");
}
}
@@ -71,11 +71,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
std::vector<std::string> missingTargets;
// Create all the imported targets.
- for (std::vector<cmGeneratorTarget*>::const_iterator tei =
- this->Exports.begin();
- tei != this->Exports.end(); ++tei) {
- cmGeneratorTarget* gte = *tei;
- this->GenerateImportTargetCode(os, gte);
+ for (cmGeneratorTarget* gte : this->Exports) {
+ this->GenerateImportTargetCode(os, gte, this->GetExportTargetType(gte));
gte->Target->AppendBuildInterfaceIncludes();
@@ -99,8 +96,26 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", gte,
cmGeneratorExpression::BuildInterface,
properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_LINK_OPTIONS", gte,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_LINK_DIRECTORIES", gte,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_LINK_DEPENDS", gte,
+ cmGeneratorExpression::BuildInterface,
+ properties, missingTargets);
this->PopulateInterfaceProperty("INTERFACE_POSITION_INDEPENDENT_CODE", gte,
properties);
+
+ std::string errorMessage;
+ if (!this->PopulateExportProperties(gte, properties, errorMessage)) {
+ this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR, errorMessage,
+ this->LG->GetMakefile()->GetBacktrace());
+ return false;
+ }
+
const bool newCMP0022Behavior =
gte->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
gte->GetPolicyStatusCMP0022() != cmPolicies::OLD;
@@ -115,10 +130,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
}
// 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);
+ for (std::string const& c : this->Configurations) {
+ this->GenerateImportConfig(os, c, missingTargets);
}
this->GenerateMissingTargetsCheckCode(os, missingTargets);
@@ -130,19 +143,17 @@ void cmExportBuildFileGenerator::GenerateImportTargetsConfig(
std::ostream& os, const std::string& config, std::string const& suffix,
std::vector<std::string>& missingTargets)
{
- for (std::vector<cmGeneratorTarget*>::const_iterator tei =
- this->Exports.begin();
- tei != this->Exports.end(); ++tei) {
+ for (cmGeneratorTarget* target : this->Exports) {
// Collect import properties for this target.
- cmGeneratorTarget* target = *tei;
ImportPropertyMap properties;
- if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
+ if (this->GetExportTargetType(target) != cmStateEnums::INTERFACE_LIBRARY) {
this->SetImportLocationProperty(config, suffix, target, properties);
}
if (!properties.empty()) {
// Get the rest of the target details.
- if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
+ if (this->GetExportTargetType(target) !=
+ cmStateEnums::INTERFACE_LIBRARY) {
this->SetImportDetailProperties(config, suffix, target, properties,
missingTargets);
this->SetImportLinkInterface(config, suffix,
@@ -150,7 +161,7 @@ void cmExportBuildFileGenerator::GenerateImportTargetsConfig(
target, properties, missingTargets);
}
- // TOOD: PUBLIC_HEADER_LOCATION
+ // TODO: 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,
@@ -162,6 +173,21 @@ void cmExportBuildFileGenerator::GenerateImportTargetsConfig(
}
}
+cmStateEnums::TargetType cmExportBuildFileGenerator::GetExportTargetType(
+ cmGeneratorTarget const* target) const
+{
+ cmStateEnums::TargetType targetType = target->GetType();
+ // An object library exports as an interface library if we cannot
+ // tell clients where to find the objects. This is sufficient
+ // to support transitive usage requirements on other targets that
+ // use the object library.
+ if (targetType == cmStateEnums::OBJECT_LIBRARY &&
+ !this->LG->GetGlobalGenerator()->HasKnownObjectFileLocation(nullptr)) {
+ targetType = cmStateEnums::INTERFACE_LIBRARY;
+ }
+ return targetType;
+}
+
void cmExportBuildFileGenerator::SetExportSet(cmExportSet* exportSet)
{
this->ExportSet = exportSet;
@@ -184,10 +210,8 @@ void cmExportBuildFileGenerator::SetImportLocationProperty(
target->GetObjectSources(objectSources, config);
std::string const obj_dir = target->GetObjectDirectory(config);
std::vector<std::string> objects;
- for (std::vector<cmSourceFile const*>::const_iterator si =
- objectSources.begin();
- si != objectSources.end(); ++si) {
- const std::string& obj = target->GetObjectName(*si);
+ for (cmSourceFile const* sf : objectSources) {
+ const std::string& obj = target->GetObjectName(sf);
objects.push_back(obj_dir + obj);
}
@@ -210,13 +234,14 @@ void cmExportBuildFileGenerator::SetImportLocationProperty(
}
// Add the import library for windows DLLs.
- if (target->HasImportLibrary() &&
+ if (target->HasImportLibrary(config) &&
mf->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
std::string prop = "IMPORTED_IMPLIB";
prop += suffix;
std::string value =
target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact);
- target->GetImplibGNUtoMS(value, value, "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
+ target->GetImplibGNUtoMS(config, value, value,
+ "${CMAKE_IMPORT_LIBRARY_SUFFIX}");
properties[prop] = value;
}
}
@@ -233,13 +258,13 @@ void cmExportBuildFileGenerator::HandleMissingTarget(
dependee->GetLocalGenerator()->GetGlobalGenerator();
std::vector<std::string> namespaces = this->FindNamespaces(gg, name);
- int targetOccurrences = (int)namespaces.size();
+ int targetOccurrences = static_cast<int>(namespaces.size());
if (targetOccurrences == 1) {
std::string missingTarget = namespaces[0];
missingTarget += dependee->GetExportName();
link_libs += missingTarget;
- missingTargets.push_back(missingTarget);
+ missingTargets.push_back(std::move(missingTarget));
return;
}
// We are not appending, so all exported targets should be
@@ -256,10 +281,8 @@ 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)->TargetName);
+ for (cmTargetExport* te : *this->ExportSet->GetTargetExports()) {
+ targets.push_back(te->TargetName);
}
return;
}
@@ -274,10 +297,8 @@ std::vector<std::string> cmExportBuildFileGenerator::FindNamespaces(
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;
+ for (auto const& exp : exportSets) {
+ const cmExportBuildFileGenerator* exportSet = exp.second;
std::vector<std::string> targets;
exportSet->GetTargets(targets);
if (std::find(targets.begin(), targets.end(), name) != targets.end()) {
@@ -308,7 +329,8 @@ void cmExportBuildFileGenerator::ComplainAboutMissingTarget(
<< "consider using the APPEND option with multiple separate calls.";
this->LG->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR, e.str(), this->LG->GetMakefile()->GetBacktrace());
+ MessageType::FATAL_ERROR, e.str(),
+ this->LG->GetMakefile()->GetBacktrace());
}
std::string cmExportBuildFileGenerator::InstallNameDir(
diff --git a/Source/cmExportBuildFileGenerator.h b/Source/cmExportBuildFileGenerator.h
index 0556983ac..0a1e75582 100644
--- a/Source/cmExportBuildFileGenerator.h
+++ b/Source/cmExportBuildFileGenerator.h
@@ -3,9 +3,11 @@
#ifndef cmExportBuildFileGenerator_h
#define cmExportBuildFileGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmAlgorithms.h"
#include "cmExportFileGenerator.h"
+#include "cmStateTypes.h"
#include <iosfwd>
#include <string>
@@ -38,7 +40,7 @@ public:
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());
+ cmAppend(this->Targets, targets);
}
void SetExportSet(cmExportSet*);
@@ -49,14 +51,16 @@ public:
protected:
// Implement virtual methods from the superclass.
- bool GenerateMainFile(std::ostream& os) CM_OVERRIDE;
+ bool GenerateMainFile(std::ostream& os) override;
void GenerateImportTargetsConfig(
std::ostream& os, const std::string& config, std::string const& suffix,
- std::vector<std::string>& missingTargets) CM_OVERRIDE;
+ std::vector<std::string>& missingTargets) override;
+ cmStateEnums::TargetType GetExportTargetType(
+ cmGeneratorTarget const* target) const;
void HandleMissingTarget(std::string& link_libs,
std::vector<std::string>& missingTargets,
cmGeneratorTarget* depender,
- cmGeneratorTarget* dependee) CM_OVERRIDE;
+ cmGeneratorTarget* dependee) override;
void ComplainAboutMissingTarget(cmGeneratorTarget* depender,
cmGeneratorTarget* dependee,
@@ -69,7 +73,7 @@ protected:
ImportPropertyMap& properties);
std::string InstallNameDir(cmGeneratorTarget* target,
- const std::string& config) CM_OVERRIDE;
+ const std::string& config) override;
std::vector<std::string> FindNamespaces(cmGlobalGenerator* gg,
const std::string& name);
diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx
index 38cd511ea..a849aa246 100644
--- a/Source/cmExportCommand.cxx
+++ b/Source/cmExportCommand.cxx
@@ -2,43 +2,35 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExportCommand.h"
+#include "cm_static_string_view.hxx"
#include "cmsys/RegularExpression.hxx"
+
+#include <algorithm>
#include <map>
#include <sstream>
+#include <utility>
+#include "cmArgumentParser.h"
#include "cmExportBuildAndroidMKGenerator.h"
#include "cmExportBuildFileGenerator.h"
#include "cmExportSetMap.h"
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cmake.h"
+class cmExportSet;
class cmExecutionStatus;
#if defined(__HAIKU__)
-#include <FindDirectory.h>
-#include <StorageDefs.h>
+# 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)
- , AndroidMKFile(&Helper, "ANDROID_MK")
-{
- this->ExportSet = CM_NULLPTR;
-}
-
-// cmExportCommand
bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
@@ -50,50 +42,69 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
if (args[0] == "PACKAGE") {
return this->HandlePackage(args);
}
+
+ struct Arguments
+ {
+ std::string ExportSetName;
+ std::vector<std::string> Targets;
+ std::string Namespace;
+ std::string Filename;
+ std::string AndroidMKFile;
+ bool Append = false;
+ bool ExportOld = false;
+ };
+
+ auto parser = cmArgumentParser<Arguments>{}
+ .Bind("NAMESPACE"_s, &Arguments::Namespace)
+ .Bind("FILE"_s, &Arguments::Filename);
+
if (args[0] == "EXPORT") {
- this->ExportSetName.Follows(CM_NULLPTR);
- this->ArgumentGroup.Follows(&this->ExportSetName);
+ parser.Bind("EXPORT"_s, &Arguments::ExportSetName);
} else {
- this->Targets.Follows(CM_NULLPTR);
- this->ArgumentGroup.Follows(&this->Targets);
+ parser.Bind("TARGETS"_s, &Arguments::Targets);
+ parser.Bind("ANDROID_MK"_s, &Arguments::AndroidMKFile);
+ parser.Bind("APPEND"_s, &Arguments::Append);
+ parser.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, &Arguments::ExportOld);
}
std::vector<std::string> unknownArgs;
- this->Helper.Parse(&args, &unknownArgs);
+ std::vector<std::string> keywordsMissingValue;
+ Arguments const arguments =
+ parser.Parse(args, &unknownArgs, &keywordsMissingValue);
if (!unknownArgs.empty()) {
- this->SetError("Unknown arguments.");
+ this->SetError("Unknown argument: \"" + unknownArgs.front() + "\".");
return false;
}
std::string fname;
bool android = false;
- if (this->AndroidMKFile.WasFound()) {
- fname = this->AndroidMKFile.GetString();
+ if (!arguments.AndroidMKFile.empty()) {
+ fname = arguments.AndroidMKFile;
android = true;
}
- if (!this->Filename.WasFound() && fname.empty()) {
+ if (arguments.Filename.empty() && fname.empty()) {
if (args[0] != "EXPORT") {
this->SetError("FILE <filename> option missing.");
return false;
}
- fname = this->ExportSetName.GetString() + ".cmake";
+ fname = arguments.ExportSetName + ".cmake";
} else if (fname.empty()) {
// Make sure the file has a .cmake extension.
- if (cmSystemTools::GetFilenameLastExtension(this->Filename.GetCString()) !=
+ if (cmSystemTools::GetFilenameLastExtension(arguments.Filename) !=
".cmake") {
std::ostringstream e;
- e << "FILE option given filename \"" << this->Filename.GetString()
+ e << "FILE option given filename \"" << arguments.Filename
<< "\" which does not have an extension of \".cmake\".\n";
this->SetError(e.str());
return false;
}
- fname = this->Filename.GetString();
+ fname = arguments.Filename;
}
// Get the file to write.
- if (cmSystemTools::FileIsFullPath(fname.c_str())) {
- if (!this->Makefile->CanIWriteThisFile(fname.c_str())) {
+ if (cmSystemTools::FileIsFullPath(fname)) {
+ if (!this->Makefile->CanIWriteThisFile(fname)) {
std::ostringstream e;
e << "FILE option given filename \"" << fname
<< "\" which is in the source tree.\n";
@@ -110,70 +121,46 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
+ cmExportSet* ExportSet = nullptr;
if (args[0] == "EXPORT") {
- if (this->Append.IsEnabled()) {
- std::ostringstream e;
- e << "EXPORT signature does not recognise the APPEND option.";
- this->SetError(e.str());
- return false;
- }
-
- if (this->ExportOld.IsEnabled()) {
- std::ostringstream 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()) {
+ auto const it = setMap.find(arguments.ExportSetName);
+ if (it == setMap.end()) {
std::ostringstream e;
- e << "Export set \"" << setName << "\" not found.";
+ e << "Export set \"" << arguments.ExportSetName << "\" 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)) {
+ ExportSet = it->second;
+ } else if (!arguments.Targets.empty() ||
+ std::find(keywordsMissingValue.begin(),
+ keywordsMissingValue.end(),
+ "TARGETS") != keywordsMissingValue.end()) {
+ for (std::string const& currentTarget : arguments.Targets) {
+ if (this->Makefile->IsAlias(currentTarget)) {
std::ostringstream e;
- e << "given ALIAS target \"" << *currentTarget
+ 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() == cmStateEnums::OBJECT_LIBRARY) {
- std::string reason;
- if (!this->Makefile->GetGlobalGenerator()
- ->HasKnownObjectFileLocation(&reason)) {
- std::ostringstream e;
- e << "given OBJECT library \"" << *currentTarget
- << "\" which may not be exported" << reason << ".";
- this->SetError(e.str());
- return false;
- }
- }
+ if (cmTarget* target = gg->FindTarget(currentTarget)) {
if (target->GetType() == cmStateEnums::UTILITY) {
- this->SetError("given custom target \"" + *currentTarget +
+ this->SetError("given custom target \"" + currentTarget +
"\" which may not be exported.");
return false;
}
} else {
std::ostringstream e;
- e << "given target \"" << *currentTarget
+ e << "given target \"" << currentTarget
<< "\" which is not built by this project.";
this->SetError(e.str());
return false;
}
- targets.push_back(*currentTarget);
+ targets.push_back(currentTarget);
}
- if (this->Append.IsEnabled()) {
+ if (arguments.Append) {
if (cmExportBuildFileGenerator* ebfg =
gg->GetExportedTargetsFile(fname)) {
ebfg->AppendTargets(targets);
@@ -186,35 +173,33 @@ bool cmExportCommand::InitialPass(std::vector<std::string> const& args,
}
// Setup export file generation.
- cmExportBuildFileGenerator* ebfg = CM_NULLPTR;
+ cmExportBuildFileGenerator* ebfg = nullptr;
if (android) {
ebfg = new cmExportBuildAndroidMKGenerator;
} else {
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);
+ ebfg->SetNamespace(arguments.Namespace);
+ ebfg->SetAppendMode(arguments.Append);
+ if (ExportSet != nullptr) {
+ ebfg->SetExportSet(ExportSet);
} else {
ebfg->SetTargets(targets);
}
this->Makefile->AddExportBuildFileGenerator(ebfg);
- ebfg->SetExportOld(this->ExportOld.IsEnabled());
+ ebfg->SetExportOld(arguments.ExportOld);
// Compute the set of configurations exported.
std::vector<std::string> configurationTypes;
this->Makefile->GetConfigurations(configurationTypes);
if (configurationTypes.empty()) {
- configurationTypes.push_back("");
+ configurationTypes.emplace_back();
}
- for (std::vector<std::string>::const_iterator ci =
- configurationTypes.begin();
- ci != configurationTypes.end(); ++ci) {
- ebfg->AddConfiguration(*ci);
+ for (std::string const& ct : configurationTypes) {
+ ebfg->AddConfiguration(ct);
}
- if (this->ExportSet) {
+ if (ExportSet != nullptr) {
gg->AddBuildExportExportSet(ebfg);
} else {
gg->AddBuildExportSet(ebfg);
@@ -252,7 +237,7 @@ bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
}
const char* packageExpr = "^[A-Za-z0-9_.-]+$";
cmsys::RegularExpression packageRegex(packageExpr);
- if (!packageRegex.find(package.c_str())) {
+ if (!packageRegex.find(package)) {
std::ostringstream e;
e << "PACKAGE given invalid package name \"" << package << "\". "
<< "Package names must match \"" << packageExpr << "\".";
@@ -260,28 +245,41 @@ bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
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;
+ // CMP0090 decides both the default and what variable changes it.
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0090)) {
+ case cmPolicies::WARN:
+ case cmPolicies::OLD:
+ // Default is to export, but can be disabled.
+ if (this->Makefile->IsOn("CMAKE_EXPORT_NO_PACKAGE_REGISTRY")) {
+ return true;
+ }
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ // Default is to not export, but can be enabled.
+ if (!this->Makefile->IsOn("CMAKE_EXPORT_PACKAGE_REGISTRY")) {
+ return true;
+ }
+ break;
}
// 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->GetCurrentBinaryDirectory();
+ const std::string& outDir = this->Makefile->GetCurrentBinaryDirectory();
std::string hash = cmSystemTools::ComputeStringMD5(outDir);
#if defined(_WIN32) && !defined(__CYGWIN__)
- this->StorePackageRegistryWin(package, outDir, hash.c_str());
+ this->StorePackageRegistryWin(package, outDir.c_str(), hash.c_str());
#else
- this->StorePackageRegistryDir(package, outDir, hash.c_str());
+ this->StorePackageRegistryDir(package, outDir.c_str(), hash.c_str());
#endif
return true;
}
#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <windows.h>
+# include <windows.h>
void cmExportCommand::ReportRegistryError(std::string const& msg,
std::string const& key, long err)
@@ -296,7 +294,7 @@ void cmExportCommand::ReportRegistryError(std::string const& msg,
e << "Windows reported:\n"
<< " " << cmsys::Encoding::ToNarrow(winmsg);
}
- this->Makefile->IssueMessage(cmake::WARNING, e.str());
+ this->Makefile->IssueMessage(MessageType::WARNING, e.str());
}
void cmExportCommand::StorePackageRegistryWin(std::string const& package,
@@ -332,7 +330,7 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
const char* content,
const char* hash)
{
-#if defined(__HAIKU__)
+# if defined(__HAIKU__)
char dir[B_PATH_NAME_LENGTH];
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, dir, sizeof(dir)) !=
B_OK) {
@@ -341,7 +339,7 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
std::string fname = dir;
fname += "/cmake/packages/";
fname += package;
-#else
+# else
std::string fname;
if (!cmSystemTools::GetEnv("HOME", fname)) {
return;
@@ -349,12 +347,12 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
cmSystemTools::ConvertToUnixSlashes(fname);
fname += "/.cmake/packages/";
fname += package;
-#endif
- cmSystemTools::MakeDirectory(fname.c_str());
+# endif
+ cmSystemTools::MakeDirectory(fname);
fname += "/";
fname += hash;
- if (!cmSystemTools::FileExists(fname.c_str())) {
- cmGeneratedFileStream entry(fname.c_str(), true);
+ if (!cmSystemTools::FileExists(fname)) {
+ cmGeneratedFileStream entry(fname, true);
if (entry) {
entry << content << "\n";
} else {
@@ -364,7 +362,7 @@ void cmExportCommand::StorePackageRegistryDir(std::string const& package,
<< " " << fname << "\n"
<< cmSystemTools::GetLastSystemError() << "\n";
/* clang-format on */
- this->Makefile->IssueMessage(cmake::WARNING, e.str());
+ this->Makefile->IssueMessage(MessageType::WARNING, e.str());
}
}
}
diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h
index c47bc42b9..99f9932b9 100644
--- a/Source/cmExportCommand.h
+++ b/Source/cmExportCommand.h
@@ -3,55 +3,31 @@
#ifndef cmExportCommand_h
#define cmExportCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
#include "cmCommand.h"
-#include "cmCommandArgumentsHelper.h"
class cmExecutionStatus;
-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.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmExportCommand; }
+ cmCommand* Clone() override { return new cmExportCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- cmCommandArgumentsHelper Helper;
- cmCommandArgumentGroup ArgumentGroup;
- cmCAStringVector Targets;
- cmCAEnabler Append;
- cmCAString ExportSetName;
- cmCAString Namespace;
- cmCAString Filename;
- cmCAEnabler ExportOld;
- cmCAString AndroidMKFile;
-
- 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);
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 972f4b9d1..a12e0c48d 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -9,17 +9,19 @@
#include "cmLinkItem.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
+#include "cmProperty.h"
+#include "cmPropertyMap.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetExport.h"
-#include "cmake.h"
-#include "cm_auto_ptr.hxx"
#include "cmsys/FStream.hxx"
#include <assert.h>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <string.h>
#include <utility>
@@ -65,24 +67,24 @@ const char* cmExportFileGenerator::GetMainExportFileName() const
bool cmExportFileGenerator::GenerateImportFile()
{
// Open the output file to generate it.
- CM_AUTO_PTR<cmsys::ofstream> foutPtr;
+ std::unique_ptr<cmsys::ofstream> foutPtr;
if (this->AppendMode) {
// Open for append.
- CM_AUTO_PTR<cmsys::ofstream> ap(
- new cmsys::ofstream(this->MainImportFile.c_str(), std::ios::app));
- foutPtr = ap;
+ auto openmodeApp = std::ios::app;
+ foutPtr = cm::make_unique<cmsys::ofstream>(this->MainImportFile.c_str(),
+ openmodeApp);
} else {
// Generate atomically and with copy-if-different.
- CM_AUTO_PTR<cmGeneratedFileStream> ap(
- new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
+ std::unique_ptr<cmGeneratedFileStream> ap(
+ new cmGeneratedFileStream(this->MainImportFile, true));
ap->SetCopyIfDifferent(true);
- foutPtr = ap;
+ foutPtr = std::move(ap);
}
- if (!foutPtr.get() || !*foutPtr) {
+ if (!foutPtr || !*foutPtr) {
std::string se = cmSystemTools::GetLastSystemError();
std::ostringstream e;
e << "cannot write to file \"" << this->MainImportFile << "\": " << se;
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return false;
}
std::ostream& os = *foutPtr;
@@ -137,7 +139,7 @@ void cmExportFileGenerator::PopulateInterfaceProperty(
if (input) {
if (!*input) {
// Set to empty
- properties[outputName] = "";
+ properties[outputName].clear();
return;
}
@@ -184,7 +186,7 @@ bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
return false;
}
-static bool isSubDirectory(const char* a, const char* b)
+static bool isSubDirectory(std::string const& a, std::string const& b)
{
return (cmSystemTools::ComparePath(a, b) ||
cmSystemTools::IsSubDirectory(a, b));
@@ -194,31 +196,32 @@ static bool checkInterfaceDirs(const std::string& prepro,
cmGeneratorTarget* target,
const std::string& prop)
{
- const char* installDir =
+ std::string const& installDir =
target->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
- const char* topSourceDir = target->GetLocalGenerator()->GetSourceDirectory();
- const char* topBinaryDir = target->GetLocalGenerator()->GetBinaryDirectory();
+ std::string const& topSourceDir =
+ target->GetLocalGenerator()->GetSourceDirectory();
+ std::string const& topBinaryDir =
+ target->GetLocalGenerator()->GetBinaryDirectory();
std::vector<std::string> parts;
cmGeneratorExpression::Split(prepro, parts);
- const bool inSourceBuild = strcmp(topSourceDir, topBinaryDir) == 0;
+ const bool inSourceBuild = topSourceDir == topBinaryDir;
bool hadFatalError = false;
- for (std::vector<std::string>::iterator li = parts.begin();
- li != parts.end(); ++li) {
- size_t genexPos = cmGeneratorExpression::Find(*li);
+ for (std::string const& li : parts) {
+ size_t genexPos = cmGeneratorExpression::Find(li);
if (genexPos == 0) {
continue;
}
- cmake::MessageType messageType = cmake::FATAL_ERROR;
+ MessageType messageType = MessageType::FATAL_ERROR;
std::ostringstream e;
if (genexPos != std::string::npos) {
if (prop == "INTERFACE_INCLUDE_DIRECTORIES") {
switch (target->GetPolicyStatusCMP0041()) {
case cmPolicies::WARN:
- messageType = cmake::WARNING;
+ messageType = MessageType::WARNING;
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0041) << "\n";
break;
case cmPolicies::OLD:
@@ -233,20 +236,20 @@ static bool checkInterfaceDirs(const std::string& prepro,
hadFatalError = true;
}
}
- if (cmHasLiteralPrefix(li->c_str(), "${_IMPORT_PREFIX}")) {
+ if (cmHasLiteralPrefix(li, "${_IMPORT_PREFIX}")) {
continue;
}
- if (!cmSystemTools::FileIsFullPath(li->c_str())) {
+ if (!cmSystemTools::FileIsFullPath(li)) {
/* clang-format off */
e << "Target \"" << target->GetName() << "\" " << prop <<
" property contains relative path:\n"
- " \"" << *li << "\"";
+ " \"" << li << "\"";
/* clang-format on */
target->GetLocalGenerator()->IssueMessage(messageType, e.str());
}
- bool inBinary = isSubDirectory(li->c_str(), topBinaryDir);
- bool inSource = isSubDirectory(li->c_str(), topSourceDir);
- if (isSubDirectory(li->c_str(), installDir)) {
+ bool inBinary = isSubDirectory(li, topBinaryDir);
+ bool inSource = isSubDirectory(li, topSourceDir);
+ if (isSubDirectory(li, 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
@@ -261,18 +264,20 @@ static bool checkInterfaceDirs(const std::string& prepro,
case cmPolicies::WARN: {
std::ostringstream s;
s << cmPolicies::GetPolicyWarning(cmPolicies::CMP0052) << "\n";
- s << "Directory:\n \"" << *li
+ 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 "
+ << 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->GetLocalGenerator()->IssueMessage(cmake::AUTHOR_WARNING,
- s.str());
+ target->GetLocalGenerator()->IssueMessage(
+ MessageType::AUTHOR_WARNING, s.str());
CM_FALLTHROUGH;
}
case cmPolicies::OLD:
@@ -293,7 +298,7 @@ static bool checkInterfaceDirs(const std::string& prepro,
/* clang-format off */
e << "Target \"" << target->GetName() << "\" " << prop <<
" property contains path:\n"
- " \"" << *li << "\"\nwhich is prefixed in the build directory.";
+ " \"" << li << "\"\nwhich is prefixed in the build directory.";
/* clang-format on */
target->GetLocalGenerator()->IssueMessage(messageType, e.str());
}
@@ -302,7 +307,7 @@ static bool checkInterfaceDirs(const std::string& prepro,
e << "Target \"" << target->GetName() << "\" " << prop
<< " property contains path:\n"
" \""
- << *li << "\"\nwhich is prefixed in the source directory.";
+ << li << "\"\nwhich is prefixed in the source directory.";
target->GetLocalGenerator()->IssueMessage(messageType, e.str());
}
}
@@ -314,17 +319,16 @@ static void prefixItems(std::string& exportDirs)
{
std::vector<std::string> entries;
cmGeneratorExpression::Split(exportDirs, entries);
- exportDirs = "";
+ exportDirs.clear();
const char* sep = "";
- for (std::vector<std::string>::const_iterator ei = entries.begin();
- ei != entries.end(); ++ei) {
+ for (std::string const& e : entries) {
exportDirs += sep;
sep = ";";
- if (!cmSystemTools::FileIsFullPath(ei->c_str()) &&
- ei->find("${_IMPORT_PREFIX}") == std::string::npos) {
+ if (!cmSystemTools::FileIsFullPath(e) &&
+ e.find("${_IMPORT_PREFIX}") == std::string::npos) {
exportDirs += "${_IMPORT_PREFIX}/";
}
- exportDirs += *ei;
+ exportDirs += e;
}
}
@@ -343,7 +347,7 @@ void cmExportFileGenerator::PopulateSourcesInterface(
}
if (!*input) {
- properties[propName] = "";
+ properties[propName].clear();
return;
}
@@ -374,7 +378,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
std::string dirs = cmGeneratorExpression::Preprocess(
tei->InterfaceIncludeDirectories, preprocessRule, true);
this->ReplaceInstallPrefix(dirs);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
std::string exportDirs =
cge->Evaluate(target->GetLocalGenerator(), "", false, target);
@@ -387,7 +391,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
"depend on the configuration, policy values or the link interface "
"are "
"not supported. Consider using target_include_directories instead.";
- lg->IssueMessage(cmake::FATAL_ERROR, e.str());
+ lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
@@ -396,7 +400,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
}
if ((input && !*input) && exportDirs.empty()) {
// Set to empty
- properties[propName] = "";
+ properties[propName].clear();
return;
}
@@ -417,6 +421,68 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
}
}
+void cmExportFileGenerator::PopulateLinkDependsInterface(
+ cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
+{
+ cmGeneratorTarget* gt = tei->Target;
+ assert(preprocessRule == cmGeneratorExpression::InstallInterface);
+
+ const char* propName = "INTERFACE_LINK_DEPENDS";
+ const char* input = gt->GetProperty(propName);
+
+ if (!input) {
+ return;
+ }
+
+ if (!*input) {
+ properties[propName].clear();
+ return;
+ }
+
+ std::string prepro =
+ cmGeneratorExpression::Preprocess(input, preprocessRule, true);
+ if (!prepro.empty()) {
+ this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets);
+
+ if (!checkInterfaceDirs(prepro, gt, propName)) {
+ return;
+ }
+ properties[propName] = prepro;
+ }
+}
+
+void cmExportFileGenerator::PopulateLinkDirectoriesInterface(
+ cmTargetExport* tei, cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap& properties, std::vector<std::string>& missingTargets)
+{
+ cmGeneratorTarget* gt = tei->Target;
+ assert(preprocessRule == cmGeneratorExpression::InstallInterface);
+
+ const char* propName = "INTERFACE_LINK_DIRECTORIES";
+ const char* input = gt->GetProperty(propName);
+
+ if (!input) {
+ return;
+ }
+
+ if (!*input) {
+ properties[propName].clear();
+ return;
+ }
+
+ std::string prepro =
+ cmGeneratorExpression::Preprocess(input, preprocessRule, true);
+ if (!prepro.empty()) {
+ this->ResolveTargetsInGeneratorExpressions(prepro, gt, missingTargets);
+
+ if (!checkInterfaceDirs(prepro, gt, propName)) {
+ return;
+ }
+ properties[propName] = prepro;
+ }
+}
+
void cmExportFileGenerator::PopulateInterfaceProperty(
const std::string& propName, cmGeneratorTarget* target,
cmGeneratorExpression::PreprocessContext preprocessRule,
@@ -455,24 +521,23 @@ void getCompatibleInterfaceProperties(cmGeneratorTarget* target,
e << "Exporting the target \"" << target->GetName()
<< "\" is not "
"allowed since its linker language cannot be determined";
- lg->IssueMessage(cmake::FATAL_ERROR, e.str());
+ lg->IssueMessage(MessageType::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) {
+ for (auto const& dep : deps) {
+ if (!dep.Target) {
continue;
}
- getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_BOOL",
+ getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_BOOL",
ifaceProperties);
- getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_STRING",
+ getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_STRING",
ifaceProperties);
- getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
+ getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MIN",
ifaceProperties);
- getPropertyContents(li->Target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
+ getPropertyContents(dep.Target, "COMPATIBLE_INTERFACE_NUMBER_MAX",
ifaceProperties);
}
}
@@ -504,15 +569,13 @@ void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
std::vector<std::string> configNames;
gtarget->Target->GetMakefile()->GetConfigurations(configNames);
- for (std::vector<std::string>::const_iterator ci = configNames.begin();
- ci != configNames.end(); ++ci) {
- getCompatibleInterfaceProperties(gtarget, ifaceProperties, *ci);
+ for (std::string const& cn : configNames) {
+ getCompatibleInterfaceProperties(gtarget, ifaceProperties, cn);
}
}
- for (std::set<std::string>::const_iterator it = ifaceProperties.begin();
- it != ifaceProperties.end(); ++it) {
- this->PopulateInterfaceProperty("INTERFACE_" + *it, gtarget, properties);
+ for (std::string const& ip : ifaceProperties) {
+ this->PopulateInterfaceProperty("INTERFACE_" + ip, gtarget, properties);
}
}
@@ -524,10 +587,9 @@ void cmExportFileGenerator::GenerateInterfaceProperties(
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 << " " << cmExportFileGeneratorEscape(pi->second)
- << "\n";
+ for (auto const& property : properties) {
+ os << " " << property.first << " "
+ << cmExportFileGeneratorEscape(property.second) << "\n";
}
os << ")\n\n";
}
@@ -537,14 +599,17 @@ bool cmExportFileGenerator::AddTargetNamespace(
std::string& input, cmGeneratorTarget* target,
std::vector<std::string>& missingTargets)
{
- cmLocalGenerator* lg = target->GetLocalGenerator();
+ cmGeneratorTarget::TargetOrString resolved =
+ target->ResolveTargetReference(input);
- cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(input);
+ cmGeneratorTarget* tgt = resolved.Target;
if (!tgt) {
+ input = resolved.String;
return false;
}
if (tgt->IsImported()) {
+ input = tgt->GetName();
return true;
}
if (this->ExportedTargets.find(tgt) != this->ExportedTargets.end()) {
@@ -554,6 +619,8 @@ bool cmExportFileGenerator::AddTargetNamespace(
this->HandleMissingTarget(namespacedTarget, missingTargets, target, tgt);
if (!namespacedTarget.empty()) {
input = namespacedTarget;
+ } else {
+ input = tgt->GetName();
}
}
return true;
@@ -571,15 +638,14 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
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);
+ input.clear();
+ for (std::string& li : parts) {
+ if (cmGeneratorExpression::Find(li) == std::string::npos) {
+ this->AddTargetNamespace(li, target, missingTargets);
} else {
- this->ResolveTargetsInGeneratorExpression(*li, target, missingTargets);
+ this->ResolveTargetsInGeneratorExpression(li, target, missingTargets);
}
- input += sep + *li;
+ input += sep + li;
sep = ";";
}
}
@@ -599,7 +665,7 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
std::string::size_type commaPos = input.find(',', nameStartPos);
std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
if (commaPos == std::string::npos // Implied 'this' target
- || closePos == std::string::npos // Imcomplete expression.
+ || closePos == std::string::npos // Incomplete expression.
|| closePos < commaPos // Implied 'this' target
|| nextOpenPos < commaPos) // Non-literal
{
@@ -662,7 +728,8 @@ void cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
this->ReplaceInstallPrefix(input);
if (!errorString.empty()) {
- target->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, errorString);
+ target->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
+ errorString);
}
}
@@ -715,12 +782,12 @@ void cmExportFileGenerator::SetImportLinkInterface(
"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";
- lg->IssueMessage(cmake::FATAL_ERROR, e.str());
+ lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
if (!*propContent) {
- properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = "";
+ properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix].clear();
return;
}
@@ -781,6 +848,35 @@ void cmExportFileGenerator::SetImportDetailProperties(
properties[prop] = m.str();
}
}
+
+ // Add information if this target is a managed target
+ if (target->GetManagedType(config) !=
+ cmGeneratorTarget::ManagedType::Native) {
+ std::string prop = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
+ prop += suffix;
+ std::string propval;
+ if (auto* p = target->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
+ propval = p;
+ } else if (target->IsCSharpOnly()) {
+ // C# projects do not have the /clr flag, so we set the property
+ // here to mark the target as (only) managed (i.e. no .lib file
+ // to link to). Otherwise the COMMON_LANGUAGE_RUNTIME target
+ // property would have to be set manually for C# targets to make
+ // exporting/importing work.
+ propval = "CSharp";
+ }
+ properties[prop] = propval;
+ }
+}
+
+static std::string const& asString(std::string const& l)
+{
+ return l;
+}
+
+static std::string const& asString(cmLinkItem const& l)
+{
+ return l.AsStr();
}
template <typename T>
@@ -797,13 +893,12 @@ void cmExportFileGenerator::SetImportLinkProperty(
// 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) {
+ for (T const& l : entries) {
// Separate this from the previous entry.
link_entries += sep;
sep = ";";
- std::string temp = *li;
+ std::string temp = asString(l);
this->AddTargetNamespace(temp, target, missingTargets);
link_entries += temp;
}
@@ -908,8 +1003,10 @@ void cmExportFileGenerator::GenerateExpectedTargetsCode(
"\n\n";
/* clang-format on */
}
+
void cmExportFileGenerator::GenerateImportTargetCode(
- std::ostream& os, const cmGeneratorTarget* target)
+ std::ostream& os, cmGeneratorTarget const* target,
+ cmStateEnums::TargetType targetType)
{
// Construct the imported target name.
std::string targetName = this->Namespace;
@@ -918,7 +1015,7 @@ void cmExportFileGenerator::GenerateImportTargetCode(
// Create the imported target.
os << "# Create imported target " << targetName << "\n";
- switch (target->GetType()) {
+ switch (targetType) {
case cmStateEnums::EXECUTABLE:
os << "add_executable(" << targetName << " IMPORTED)\n";
break;
@@ -988,10 +1085,9 @@ void cmExportFileGenerator::GenerateImportPropertyCode(
}
os << ")\n";
os << "set_target_properties(" << targetName << " PROPERTIES\n";
- for (ImportPropertyMap::const_iterator pi = properties.begin();
- pi != properties.end(); ++pi) {
- os << " " << pi->first << " " << cmExportFileGeneratorEscape(pi->second)
- << "\n";
+ for (auto const& property : properties) {
+ os << " " << property.first << " "
+ << cmExportFileGeneratorEscape(property.second) << "\n";
}
os << " )\n"
<< "\n";
@@ -1015,9 +1111,9 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(
"foreach(_target ";
/* clang-format on */
std::set<std::string> emitted;
- for (unsigned int i = 0; i < missingTargets.size(); ++i) {
- if (emitted.insert(missingTargets[i]).second) {
- os << "\"" << missingTargets[i] << "\" ";
+ for (std::string const& missingTarget : missingTargets) {
+ if (emitted.insert(missingTarget).second) {
+ os << "\"" << missingTarget << "\" ";
}
}
/* clang-format off */
@@ -1094,9 +1190,8 @@ void cmExportFileGenerator::GenerateImportedFileChecksCode(
"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);
+ for (std::string const& li : importedLocations) {
+ ImportPropertyMap::const_iterator pi = properties.find(li);
if (pi != properties.end()) {
os << cmExportFileGeneratorEscape(pi->second) << " ";
}
@@ -1104,3 +1199,46 @@ void cmExportFileGenerator::GenerateImportedFileChecksCode(
os << ")\n\n";
}
+
+bool cmExportFileGenerator::PopulateExportProperties(
+ cmGeneratorTarget* gte, ImportPropertyMap& properties,
+ std::string& errorMessage)
+{
+ auto& targetProperties = gte->Target->GetProperties();
+ const auto& exportProperties = targetProperties.find("EXPORT_PROPERTIES");
+ if (exportProperties != targetProperties.end()) {
+ std::vector<std::string> propsToExport;
+ cmSystemTools::ExpandListArgument(exportProperties->second.GetValue(),
+ propsToExport);
+ for (auto& prop : propsToExport) {
+ /* Black list reserved properties */
+ if (cmSystemTools::StringStartsWith(prop, "IMPORTED_") ||
+ cmSystemTools::StringStartsWith(prop, "INTERFACE_")) {
+ std::ostringstream e;
+ e << "Target \"" << gte->Target->GetName() << "\" contains property \""
+ << prop << "\" in EXPORT_PROPERTIES but IMPORTED_* and INTERFACE_* "
+ << "properties are reserved.";
+ errorMessage = e.str();
+ return false;
+ }
+ auto propertyValue = targetProperties.GetPropertyValue(prop);
+ if (propertyValue == nullptr) {
+ // Asked to export a property that isn't defined on the target. Do not
+ // consider this an error, there's just nothing to export.
+ continue;
+ }
+ std::string evaluatedValue = cmGeneratorExpression::Preprocess(
+ propertyValue, cmGeneratorExpression::StripAllGeneratorExpressions);
+ if (evaluatedValue != propertyValue) {
+ std::ostringstream e;
+ e << "Target \"" << gte->Target->GetName() << "\" contains property \""
+ << prop << "\" in EXPORT_PROPERTIES but this property contains a "
+ << "generator expression. This is not allowed.";
+ errorMessage = e.str();
+ return false;
+ }
+ properties[prop] = propertyValue;
+ }
+ }
+ return true;
+}
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
index 985c8f6bc..747503e6d 100644
--- a/Source/cmExportFileGenerator.h
+++ b/Source/cmExportFileGenerator.h
@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmGeneratorExpression.h"
+#include "cmStateTypes.h"
#include "cmVersion.h"
#include "cmVersionConfig.h"
@@ -41,7 +42,7 @@ class cmExportFileGenerator
{
public:
cmExportFileGenerator();
- virtual ~cmExportFileGenerator() {}
+ virtual ~cmExportFileGenerator() = default;
/** Set the full path to the export file to generate. */
void SetExportFile(const char* mainFile);
@@ -76,7 +77,8 @@ protected:
virtual void GenerateImportFooterCode(std::ostream& os);
void GenerateImportVersionCode(std::ostream& os);
virtual void GenerateImportTargetCode(std::ostream& os,
- cmGeneratorTarget const* target);
+ cmGeneratorTarget const* target,
+ cmStateEnums::TargetType targetType);
virtual void GenerateImportPropertyCode(std::ostream& os,
const std::string& config,
cmGeneratorTarget const* target,
@@ -145,6 +147,14 @@ protected:
cmTargetExport* target,
cmGeneratorExpression::PreprocessContext preprocessRule,
ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
+ void PopulateLinkDirectoriesInterface(
+ cmTargetExport* target,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
+ void PopulateLinkDependsInterface(
+ cmTargetExport* target,
+ cmGeneratorExpression::PreprocessContext preprocessRule,
+ ImportPropertyMap& properties, std::vector<std::string>& missingTargets);
void SetImportLinkInterface(
const std::string& config, std::string const& suffix,
@@ -166,6 +176,10 @@ protected:
virtual void GenerateRequiredCMakeVersion(std::ostream& os,
const char* versionString);
+ bool PopulateExportProperties(cmGeneratorTarget* gte,
+ ImportPropertyMap& properties,
+ std::string& errorMessage);
+
// The namespace in which the exports are placed in the generated file.
std::string Namespace;
diff --git a/Source/cmExportInstallAndroidMKGenerator.cxx b/Source/cmExportInstallAndroidMKGenerator.cxx
index 9a1c647d3..9bc8089dc 100644
--- a/Source/cmExportInstallAndroidMKGenerator.cxx
+++ b/Source/cmExportInstallAndroidMKGenerator.cxx
@@ -34,11 +34,8 @@ void cmExportInstallAndroidMKGenerator::GenerateImportHeaderCode(
}
os << "_IMPORT_PREFIX := "
<< "$(LOCAL_PATH)" << path << "\n\n";
- for (std::vector<cmTargetExport*>::const_iterator tei =
- this->IEGen->GetExportSet()->GetTargetExports()->begin();
- tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei) {
+ for (cmTargetExport* te : *this->IEGen->GetExportSet()->GetTargetExports()) {
// Collect import properties for this target.
- cmTargetExport const* te = *tei;
if (te->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
@@ -58,7 +55,8 @@ void cmExportInstallAndroidMKGenerator::GenerateImportFooterCode(std::ostream&)
}
void cmExportInstallAndroidMKGenerator::GenerateImportTargetCode(
- std::ostream& os, const cmGeneratorTarget* target)
+ std::ostream& os, cmGeneratorTarget const* target,
+ cmStateEnums::TargetType /*targetType*/)
{
std::string targetName = this->Namespace;
targetName += target->GetExportName();
diff --git a/Source/cmExportInstallAndroidMKGenerator.h b/Source/cmExportInstallAndroidMKGenerator.h
index ebef78365..8883ffafb 100644
--- a/Source/cmExportInstallAndroidMKGenerator.h
+++ b/Source/cmExportInstallAndroidMKGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmExportInstallAndroidMKGenerator_h
#define cmExportInstallAndroidMKGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <set>
@@ -12,6 +12,7 @@
#include "cmExportFileGenerator.h"
#include "cmExportInstallFileGenerator.h"
+#include "cmStateTypes.h"
class cmGeneratorTarget;
class cmInstallExportGenerator;
@@ -22,7 +23,7 @@ class cmInstallExportGenerator;
* cmExportInstallAndroidMKGenerator generates files exporting targets from
* install an installation tree. The files are placed in a temporary
* location for installation by cmInstallExportGenerator. The file format
- * is for the ndk build system and is a makefile fragment specifing prebuilt
+ * is for the ndk build system and is a makefile fragment specifying prebuilt
* libraries to the ndk build system.
*
* This is used to implement the INSTALL(EXPORT_ANDROID_MK) command.
@@ -36,37 +37,37 @@ public:
protected:
// Implement virtual methods from the superclass.
- void GeneratePolicyHeaderCode(std::ostream&) CM_OVERRIDE {}
- void GeneratePolicyFooterCode(std::ostream&) CM_OVERRIDE {}
+ void GeneratePolicyHeaderCode(std::ostream&) override {}
+ void GeneratePolicyFooterCode(std::ostream&) override {}
void GenerateImportHeaderCode(std::ostream& os,
- const std::string& config = "") CM_OVERRIDE;
- void GenerateImportFooterCode(std::ostream& os) CM_OVERRIDE;
- void GenerateImportTargetCode(std::ostream& os,
- const cmGeneratorTarget* target) CM_OVERRIDE;
+ const std::string& config = "") override;
+ void GenerateImportFooterCode(std::ostream& os) override;
+ void GenerateImportTargetCode(
+ std::ostream& os, cmGeneratorTarget const* target,
+ cmStateEnums::TargetType /*targetType*/) override;
void GenerateExpectedTargetsCode(
- std::ostream& os, const std::string& expectedTargets) CM_OVERRIDE;
- void GenerateImportPropertyCode(std::ostream& os, const std::string& config,
- cmGeneratorTarget const* target,
- ImportPropertyMap const& properties)
- CM_OVERRIDE;
+ std::ostream& os, const std::string& expectedTargets) override;
+ void GenerateImportPropertyCode(
+ std::ostream& os, const std::string& config,
+ cmGeneratorTarget const* target,
+ ImportPropertyMap const& properties) override;
void GenerateMissingTargetsCheckCode(
- std::ostream& os,
- const std::vector<std::string>& missingTargets) CM_OVERRIDE;
+ std::ostream& os, const std::vector<std::string>& missingTargets) override;
void GenerateInterfaceProperties(
cmGeneratorTarget const* target, std::ostream& os,
- const ImportPropertyMap& properties) CM_OVERRIDE;
- void GenerateImportPrefix(std::ostream& os) CM_OVERRIDE;
- void LoadConfigFiles(std::ostream&) CM_OVERRIDE;
+ const ImportPropertyMap& properties) override;
+ void GenerateImportPrefix(std::ostream& os) override;
+ void LoadConfigFiles(std::ostream&) override;
void GenerateRequiredCMakeVersion(std::ostream& os,
- const char* versionString) CM_OVERRIDE;
- void CleanupTemporaryVariables(std::ostream&) CM_OVERRIDE;
- void GenerateImportedFileCheckLoop(std::ostream& os) CM_OVERRIDE;
+ const char* versionString) override;
+ void CleanupTemporaryVariables(std::ostream&) override;
+ void GenerateImportedFileCheckLoop(std::ostream& os) override;
void GenerateImportedFileChecksCode(
std::ostream& os, cmGeneratorTarget* target,
ImportPropertyMap const& properties,
- const std::set<std::string>& importedLocations) CM_OVERRIDE;
+ const std::set<std::string>& importedLocations) override;
bool GenerateImportFileConfig(const std::string& config,
- std::vector<std::string>&) CM_OVERRIDE;
+ std::vector<std::string>&) override;
};
#endif
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index 664a34276..f8bc0ab0b 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -42,14 +42,10 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
{
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();
+ for (cmTargetExport* te :
+ *this->IEGen->GetExportSet()->GetTargetExports()) {
+ expectedTargets += sep + this->Namespace + te->Target->GetExportName();
sep = " ";
- cmTargetExport* te = *tei;
if (this->ExportedTargets.insert(te->Target).second) {
allTargets.push_back(te);
} else {
@@ -58,7 +54,7 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
<< "\" ...) "
<< "includes target \"" << te->Target->GetName()
<< "\" more than once in the export set.";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return false;
}
}
@@ -76,22 +72,20 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
bool require3_1_0 = false;
bool requiresConfigFiles = false;
// Create all the imported targets.
- for (std::vector<cmTargetExport*>::const_iterator tei = allTargets.begin();
- tei != allTargets.end(); ++tei) {
- cmGeneratorTarget* gt = (*tei)->Target;
+ for (cmTargetExport* te : allTargets) {
+ cmGeneratorTarget* gt = te->Target;
+ cmStateEnums::TargetType targetType = this->GetExportTargetType(te);
requiresConfigFiles =
- requiresConfigFiles || gt->GetType() != cmStateEnums::INTERFACE_LIBRARY;
+ requiresConfigFiles || targetType != cmStateEnums::INTERFACE_LIBRARY;
- this->GenerateImportTargetCode(os, gt);
+ this->GenerateImportTargetCode(os, gt, targetType);
ImportPropertyMap properties;
this->PopulateIncludeDirectoriesInterface(
- *tei, cmGeneratorExpression::InstallInterface, properties,
- missingTargets);
- this->PopulateSourcesInterface(*tei,
- cmGeneratorExpression::InstallInterface,
+ te, cmGeneratorExpression::InstallInterface, properties, missingTargets);
+ this->PopulateSourcesInterface(te, cmGeneratorExpression::InstallInterface,
properties, missingTargets);
this->PopulateInterfaceProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", gt,
cmGeneratorExpression::InstallInterface,
@@ -108,6 +102,19 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
this->PopulateInterfaceProperty("INTERFACE_COMPILE_FEATURES", gt,
cmGeneratorExpression::InstallInterface,
properties, missingTargets);
+ this->PopulateInterfaceProperty("INTERFACE_LINK_OPTIONS", gt,
+ cmGeneratorExpression::InstallInterface,
+ properties, missingTargets);
+ this->PopulateLinkDirectoriesInterface(
+ te, cmGeneratorExpression::InstallInterface, properties, missingTargets);
+ this->PopulateLinkDependsInterface(
+ te, cmGeneratorExpression::InstallInterface, properties, missingTargets);
+
+ std::string errorMessage;
+ if (!this->PopulateExportProperties(gt, properties, errorMessage)) {
+ cmSystemTools::Error(errorMessage);
+ return false;
+ }
const bool newCMP0022Behavior =
gt->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
@@ -120,7 +127,7 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
require2_8_12 = true;
}
}
- if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ if (targetType == cmStateEnums::INTERFACE_LIBRARY) {
require3_0_0 = true;
}
if (gt->GetProperty("INTERFACE_SOURCES")) {
@@ -154,10 +161,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
// 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)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->GenerateImportFileConfig(c, missingTargets)) {
result = false;
}
}
@@ -193,12 +198,12 @@ void cmExportInstallFileGenerator::GenerateImportPrefix(std::ostream& os)
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(), "/libx32/") ||
- cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib/") ||
- cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib64/") ||
- cmHasLiteralPrefix(absDestS.c_str(), "/usr/libx32/")) {
+ if (cmHasLiteralPrefix(absDestS, "/lib/") ||
+ cmHasLiteralPrefix(absDestS, "/lib64/") ||
+ cmHasLiteralPrefix(absDestS, "/libx32/") ||
+ cmHasLiteralPrefix(absDestS, "/usr/lib/") ||
+ cmHasLiteralPrefix(absDestS, "/usr/lib64/") ||
+ cmHasLiteralPrefix(absDestS, "/usr/libx32/")) {
// Handle "/usr move" symlinks created by some Linux distros.
/* clang-format off */
os <<
@@ -284,12 +289,12 @@ bool cmExportInstallFileGenerator::GenerateImportFileConfig(
fileName += this->FileExt;
// Open the output file to generate it.
- cmGeneratedFileStream exportFileStream(fileName.c_str(), true);
+ cmGeneratedFileStream exportFileStream(fileName, true);
if (!exportFileStream) {
std::string se = cmSystemTools::GetLastSystemError();
std::ostringstream e;
e << "cannot write to file \"" << fileName << "\": " << se;
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return false;
}
std::ostream& os = exportFileStream;
@@ -314,12 +319,9 @@ void cmExportInstallFileGenerator::GenerateImportTargetsConfig(
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) {
+ for (cmTargetExport* te : *this->IEGen->GetExportSet()->GetTargetExports()) {
// Collect import properties for this target.
- cmTargetExport const* te = *tei;
- if (te->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ if (this->GetExportTargetType(te) == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
@@ -351,7 +353,7 @@ void cmExportInstallFileGenerator::GenerateImportTargetsConfig(
cmGeneratorExpression::InstallInterface,
gtgt, properties, missingTargets);
- // TOOD: PUBLIC_HEADER_LOCATION
+ // TODO: 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,
@@ -381,7 +383,7 @@ void cmExportInstallFileGenerator::SetImportLocationProperty(
// Construct the installed location of the target.
std::string dest = itgen->GetDestination(config);
std::string value;
- if (!cmSystemTools::FileIsFullPath(dest.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(dest)) {
// The target is installed relative to the installation prefix.
value = "${_IMPORT_PREFIX}/";
}
@@ -394,8 +396,8 @@ void cmExportInstallFileGenerator::SetImportLocationProperty(
prop += suffix;
// Append the installed file name.
- value += itgen->GetInstallFilename(target, config,
- cmInstallTargetGenerator::NameImplib);
+ value += cmInstallTargetGenerator::GetInstallFilename(
+ target, config, cmInstallTargetGenerator::NameImplib);
// Store the property.
properties[prop] = value;
@@ -409,9 +411,8 @@ void cmExportInstallFileGenerator::SetImportLocationProperty(
// IMPORTED_OBJECTS as a list of object files
std::vector<std::string> objects;
itgen->GetInstallObjectNames(config, objects);
- for (std::vector<std::string>::iterator i = objects.begin();
- i != objects.end(); ++i) {
- *i = value + *i;
+ for (std::string& obj : objects) {
+ obj = value + obj;
}
// Store the property.
@@ -424,12 +425,12 @@ void cmExportInstallFileGenerator::SetImportLocationProperty(
// Append the installed file name.
if (target->IsAppBundleOnApple()) {
- value += itgen->GetInstallFilename(target, config);
+ value += cmInstallTargetGenerator::GetInstallFilename(target, config);
value += ".app/Contents/MacOS/";
- value += itgen->GetInstallFilename(target, config);
+ value += cmInstallTargetGenerator::GetInstallFilename(target, config);
} else {
- value += itgen->GetInstallFilename(target, config,
- cmInstallTargetGenerator::NameReal);
+ value += cmInstallTargetGenerator::GetInstallFilename(
+ target, config, cmInstallTargetGenerator::NameReal);
}
// Store the property.
@@ -438,6 +439,19 @@ void cmExportInstallFileGenerator::SetImportLocationProperty(
}
}
+cmStateEnums::TargetType cmExportInstallFileGenerator::GetExportTargetType(
+ cmTargetExport const* targetExport) const
+{
+ cmStateEnums::TargetType targetType = targetExport->Target->GetType();
+ // An OBJECT library installed with no OBJECTS DESTINATION
+ // is transformed to an INTERFACE library.
+ if (targetType == cmStateEnums::OBJECT_LIBRARY &&
+ targetExport->ObjectsGenerator == nullptr) {
+ targetType = cmStateEnums::INTERFACE_LIBRARY;
+ }
+ return targetType;
+}
+
void cmExportInstallFileGenerator::HandleMissingTarget(
std::string& link_libs, std::vector<std::string>& missingTargets,
cmGeneratorTarget* depender, cmGeneratorTarget* dependee)
@@ -445,13 +459,13 @@ void cmExportInstallFileGenerator::HandleMissingTarget(
const std::string name = dependee->GetName();
cmGlobalGenerator* gg = dependee->GetLocalGenerator()->GetGlobalGenerator();
std::vector<std::string> namespaces = this->FindNamespaces(gg, name);
- int targetOccurrences = (int)namespaces.size();
+ int targetOccurrences = static_cast<int>(namespaces.size());
if (targetOccurrences == 1) {
std::string missingTarget = namespaces[0];
missingTarget += dependee->GetExportName();
link_libs += missingTarget;
- missingTargets.push_back(missingTarget);
+ missingTargets.push_back(std::move(missingTarget));
} else {
// All exported targets should be known here and should be unique.
// This is probably user-error.
@@ -465,15 +479,14 @@ std::vector<std::string> cmExportInstallFileGenerator::FindNamespaces(
std::vector<std::string> namespaces;
const cmExportSetMap& exportSets = gg->GetExportSets();
- for (cmExportSetMap::const_iterator expIt = exportSets.begin();
- expIt != exportSets.end(); ++expIt) {
- const cmExportSet* exportSet = expIt->second;
+ for (auto const& expIt : exportSets) {
+ 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]->TargetName) {
+ for (cmTargetExport* target : *targets) {
+ if (name == target->TargetName) {
containsTarget = true;
break;
}
@@ -482,8 +495,8 @@ std::vector<std::string> cmExportInstallFileGenerator::FindNamespaces(
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());
+ for (cmInstallExportGenerator const* install : *installs) {
+ namespaces.push_back(install->GetNamespace());
}
}
}
@@ -505,7 +518,7 @@ void cmExportInstallFileGenerator::ComplainAboutMissingTarget(
e << "that is not in this export set, but " << occurrences
<< " times in others.";
}
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
}
std::string cmExportInstallFileGenerator::InstallNameDir(
diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h
index 8fa9b7f88..cbd650767 100644
--- a/Source/cmExportInstallFileGenerator.h
+++ b/Source/cmExportInstallFileGenerator.h
@@ -3,9 +3,10 @@
#ifndef cmExportInstallFileGenerator_h
#define cmExportInstallFileGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmExportFileGenerator.h"
+#include "cmStateTypes.h"
#include <iosfwd>
#include <map>
@@ -17,6 +18,7 @@ class cmGeneratorTarget;
class cmGlobalGenerator;
class cmInstallExportGenerator;
class cmInstallTargetGenerator;
+class cmTargetExport;
/** \class cmExportInstallFileGenerator
* \brief Generate a file exporting targets from an install tree.
@@ -39,7 +41,7 @@ public:
files. */
cmExportInstallFileGenerator(cmInstallExportGenerator* iegen);
- /** Get the per-config file generated for each configuraiton. This
+ /** Get the per-config file generated for each configuration. This
maps from the configuration name to the file temporary location
for installation. */
std::map<std::string, std::string> const& GetConfigImportFiles()
@@ -53,16 +55,18 @@ public:
protected:
// Implement virtual methods from the superclass.
- bool GenerateMainFile(std::ostream& os) CM_OVERRIDE;
+ bool GenerateMainFile(std::ostream& os) override;
void GenerateImportTargetsConfig(
std::ostream& os, const std::string& config, std::string const& suffix,
- std::vector<std::string>& missingTargets) CM_OVERRIDE;
+ std::vector<std::string>& missingTargets) override;
+ cmStateEnums::TargetType GetExportTargetType(
+ cmTargetExport const* targetExport) const;
void HandleMissingTarget(std::string& link_libs,
std::vector<std::string>& missingTargets,
cmGeneratorTarget* depender,
- cmGeneratorTarget* dependee) CM_OVERRIDE;
+ cmGeneratorTarget* dependee) override;
- void ReplaceInstallPrefix(std::string& input) CM_OVERRIDE;
+ void ReplaceInstallPrefix(std::string& input) override;
void ComplainAboutMissingTarget(cmGeneratorTarget* depender,
cmGeneratorTarget* dependee,
@@ -91,7 +95,7 @@ protected:
std::set<std::string>& importedLocations);
std::string InstallNameDir(cmGeneratorTarget* target,
- const std::string& config) CM_OVERRIDE;
+ const std::string& config) override;
cmInstallExportGenerator* IEGen;
diff --git a/Source/cmExportLibraryDependenciesCommand.cxx b/Source/cmExportLibraryDependenciesCommand.cxx
index 69150aee4..b60a0533c 100644
--- a/Source/cmExportLibraryDependenciesCommand.cxx
+++ b/Source/cmExportLibraryDependenciesCommand.cxx
@@ -4,8 +4,10 @@
#include "cmsys/FStream.hxx"
#include <map>
+#include <memory> // IWYU pragma: keep
#include <utility>
+#include "cmAlgorithms.h"
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
@@ -13,8 +15,6 @@
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetLinkLibraryType.h"
-#include "cm_auto_ptr.hxx"
-#include "cm_unordered_map.hxx"
#include "cmake.h"
class cmExecutionStatus;
@@ -48,21 +48,21 @@ void cmExportLibraryDependenciesCommand::FinalPass()
void cmExportLibraryDependenciesCommand::ConstFinalPass() const
{
// Use copy-if-different if not appending.
- CM_AUTO_PTR<cmsys::ofstream> foutPtr;
+ std::unique_ptr<cmsys::ofstream> foutPtr;
if (this->Append) {
- CM_AUTO_PTR<cmsys::ofstream> ap(
- new cmsys::ofstream(this->Filename.c_str(), std::ios::app));
- foutPtr = ap;
+ const auto openmodeApp = std::ios::app;
+ foutPtr =
+ cm::make_unique<cmsys::ofstream>(this->Filename.c_str(), openmodeApp);
} else {
- CM_AUTO_PTR<cmGeneratedFileStream> ap(
- new cmGeneratedFileStream(this->Filename.c_str(), true));
+ std::unique_ptr<cmGeneratedFileStream> ap(
+ new cmGeneratedFileStream(this->Filename, true));
ap->SetCopyIfDifferent(true);
- foutPtr = ap;
+ foutPtr = std::move(ap);
}
std::ostream& fout = *foutPtr;
if (!fout) {
- cmSystemTools::Error("Error Writing ", this->Filename.c_str());
+ cmSystemTools::Error("Error Writing " + this->Filename);
cmSystemTools::ReportLastSystemError("");
return;
}
@@ -75,12 +75,10 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
std::map<std::string, std::string> libDepsOld;
std::map<std::string, std::string> libDepsNew;
std::map<std::string, std::string> libTypes;
- for (std::vector<cmMakefile*>::const_iterator i = locals.begin();
- i != locals.end(); ++i) {
- const cmTargets& tgts = (*i)->GetTargets();
- for (cmTargets::const_iterator l = tgts.begin(); l != tgts.end(); ++l) {
+ for (cmMakefile* local : locals) {
+ for (auto const& tgt : local->GetTargets()) {
// Get the current target.
- cmTarget const& target = l->second;
+ cmTarget const& target = tgt.second;
// Skip non-library targets.
if (target.GetType() < cmStateEnums::STATIC_LIBRARY ||
@@ -98,12 +96,11 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
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;
+ for (cmTarget::LibraryID const& li : libs) {
+ std::string ltVar = li.first;
ltVar += "_LINK_TYPE";
std::string ltValue;
- switch (li->second) {
+ switch (li.second) {
case GENERAL_LibraryType:
valueNew += "general;";
ltValue = "general";
@@ -117,7 +114,7 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
ltValue = "optimized";
break;
}
- std::string lib = li->first;
+ 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
@@ -150,26 +147,21 @@ void cmExportLibraryDependenciesCommand::ConstFinalPass() const
fout << "# Generated by CMake\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";
+ for (auto const& i : libDepsNew) {
+ 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 (auto const& i : libDepsOld) {
+ 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";
+ for (auto const& i : libTypes) {
+ if (i.second != "general") {
+ fout << " set(\"" << i.first << "\" \"" << i.second << "\")\n";
}
}
fout << "endif()\n";
diff --git a/Source/cmExportLibraryDependenciesCommand.h b/Source/cmExportLibraryDependenciesCommand.h
index 5559af94b..8414866a0 100644
--- a/Source/cmExportLibraryDependenciesCommand.h
+++ b/Source/cmExportLibraryDependenciesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmExportLibraryDependenciesCommand_h
#define cmExportLibraryDependenciesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,19 +15,19 @@ class cmExecutionStatus;
class cmExportLibraryDependenciesCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
return new cmExportLibraryDependenciesCommand;
}
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
- void FinalPass() CM_OVERRIDE;
- bool HasFinalPass() const CM_OVERRIDE { return true; }
+ void FinalPass() override;
+ bool HasFinalPass() const override { return true; }
private:
std::string Filename;
- bool Append;
+ bool Append = false;
void ConstFinalPass() const;
};
diff --git a/Source/cmExportSet.cxx b/Source/cmExportSet.cxx
index a93667994..a6fa186c7 100644
--- a/Source/cmExportSet.cxx
+++ b/Source/cmExportSet.cxx
@@ -13,9 +13,8 @@ cmExportSet::~cmExportSet()
void cmExportSet::Compute(cmLocalGenerator* lg)
{
- for (std::vector<cmTargetExport*>::iterator it = this->TargetExports.begin();
- it != this->TargetExports.end(); ++it) {
- (*it)->Target = lg->FindGeneratorTargetToUse((*it)->TargetName);
+ for (cmTargetExport* tgtExport : this->TargetExports) {
+ tgtExport->Target = lg->FindGeneratorTargetToUse(tgtExport->TargetName);
}
}
diff --git a/Source/cmExportSet.h b/Source/cmExportSet.h
index 58ad617d4..d654c1285 100644
--- a/Source/cmExportSet.h
+++ b/Source/cmExportSet.h
@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
+#include <utility>
#include <vector>
class cmInstallExportGenerator;
@@ -17,13 +18,16 @@ class cmExportSet
{
public:
/// Construct an empty export set named \a name
- cmExportSet(const std::string& name)
- : Name(name)
+ cmExportSet(std::string name)
+ : Name(std::move(name))
{
}
/// Destructor
~cmExportSet();
+ cmExportSet(const cmExportSet&) = delete;
+ cmExportSet& operator=(const cmExportSet&) = delete;
+
void Compute(cmLocalGenerator* lg);
void AddTargetExport(cmTargetExport* tgt);
diff --git a/Source/cmExportSetMap.cxx b/Source/cmExportSetMap.cxx
index 074082835..293e80cf9 100644
--- a/Source/cmExportSetMap.cxx
+++ b/Source/cmExportSetMap.cxx
@@ -23,6 +23,8 @@ void cmExportSetMap::clear()
this->derived::clear();
}
+cmExportSetMap::cmExportSetMap() = default;
+
cmExportSetMap::~cmExportSetMap()
{
this->clear();
diff --git a/Source/cmExportSetMap.h b/Source/cmExportSetMap.h
index 0f71c790c..385373240 100644
--- a/Source/cmExportSetMap.h
+++ b/Source/cmExportSetMap.h
@@ -25,8 +25,13 @@ public:
void clear();
+ cmExportSetMap();
+
/// Overloaded destructor deletes all member export sets.
~cmExportSetMap();
+
+ cmExportSetMap(const cmExportSetMap&) = delete;
+ cmExportSetMap& operator=(const cmExportSetMap&) = delete;
};
#endif
diff --git a/Source/cmExportTryCompileFileGenerator.cxx b/Source/cmExportTryCompileFileGenerator.cxx
index cd0a7e69a..c169032dd 100644
--- a/Source/cmExportTryCompileFileGenerator.cxx
+++ b/Source/cmExportTryCompileFileGenerator.cxx
@@ -11,14 +11,15 @@
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cm_auto_ptr.hxx"
#include <map>
+#include <memory> // IWYU pragma: keep
#include <utility>
cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(
cmGlobalGenerator* gg, const std::vector<std::string>& targets,
- cmMakefile* mf)
+ cmMakefile* mf, std::set<std::string> const& langs)
+ : Languages(langs.begin(), langs.end())
{
gg->CreateImportedGenerationObjects(mf, targets, this->Exports);
}
@@ -32,16 +33,18 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
this->Exports.pop_back();
if (emitted.insert(te).second) {
emittedDeps.insert(te);
- this->GenerateImportTargetCode(os, te);
+ this->GenerateImportTargetCode(os, te, te->GetType());
ImportPropertyMap properties;
+ for (std::string const& lang : this->Languages) {
#define FIND_TARGETS(PROPERTY) \
- this->FindTargets("INTERFACE_" #PROPERTY, te, emittedDeps);
+ this->FindTargets("INTERFACE_" #PROPERTY, te, lang, emittedDeps);
- CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
+ CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(FIND_TARGETS)
#undef FIND_TARGETS
+ }
this->PopulateProperties(te, properties, emittedDeps);
@@ -53,7 +56,7 @@ bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os)
std::string cmExportTryCompileFileGenerator::FindTargets(
const std::string& propName, cmGeneratorTarget const* tgt,
- std::set<cmGeneratorTarget const*>& emitted)
+ std::string const& language, std::set<cmGeneratorTarget const*>& emitted)
{
const char* prop = tgt->GetProperty(propName);
if (!prop) {
@@ -62,26 +65,24 @@ std::string cmExportTryCompileFileGenerator::FindTargets(
cmGeneratorExpression ge;
- cmGeneratorExpressionDAGChecker dagChecker(tgt->GetName(), propName,
- CM_NULLPTR, CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(tgt, propName, nullptr, nullptr);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
cmTarget dummyHead("try_compile_dummy_exe", cmStateEnums::EXECUTABLE,
cmTarget::VisibilityNormal, tgt->Target->GetMakefile());
cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator());
- std::string result = cge->Evaluate(tgt->GetLocalGenerator(), this->Config,
- false, &gDummyHead, tgt, &dagChecker);
+ std::string result =
+ cge->Evaluate(tgt->GetLocalGenerator(), this->Config, false, &gDummyHead,
+ tgt, &dagChecker, language);
const std::set<cmGeneratorTarget const*>& allTargets =
cge->GetAllTargetsSeen();
- for (std::set<cmGeneratorTarget const*>::const_iterator li =
- allTargets.begin();
- li != allTargets.end(); ++li) {
- if (emitted.insert(*li).second) {
- this->Exports.push_back(*li);
+ for (cmGeneratorTarget const* target : allTargets) {
+ if (emitted.insert(target).second) {
+ this->Exports.push_back(target);
}
}
return result;
@@ -92,22 +93,21 @@ void cmExportTryCompileFileGenerator::PopulateProperties(
std::set<cmGeneratorTarget const*>& emitted)
{
std::vector<std::string> props = target->GetPropertyKeys();
- for (std::vector<std::string>::const_iterator i = props.begin();
- i != props.end(); ++i) {
+ for (std::string const& p : props) {
- properties[*i] = target->GetProperty(*i);
+ properties[p] = target->GetProperty(p);
- if (i->find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 ||
- i->find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0 ||
- i->find("INTERFACE_LINK_LIBRARIES") == 0) {
- std::string evalResult = this->FindTargets(*i, target, emitted);
+ if (p.find("IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 ||
+ p.find("IMPORTED_LINK_DEPENDENT_LIBRARIES") == 0 ||
+ p.find("INTERFACE_LINK_LIBRARIES") == 0) {
+ std::string evalResult =
+ this->FindTargets(p, target, std::string(), emitted);
std::vector<std::string> depends;
cmSystemTools::ExpandListArgument(evalResult, depends);
- for (std::vector<std::string>::const_iterator li = depends.begin();
- li != depends.end(); ++li) {
+ for (std::string const& li : depends) {
cmGeneratorTarget* tgt =
- target->GetLocalGenerator()->FindGeneratorTargetToUse(*li);
+ target->GetLocalGenerator()->FindGeneratorTargetToUse(li);
if (tgt && emitted.insert(tgt).second) {
this->Exports.push_back(tgt);
}
diff --git a/Source/cmExportTryCompileFileGenerator.h b/Source/cmExportTryCompileFileGenerator.h
index 9671fac8f..2a2ba7e50 100644
--- a/Source/cmExportTryCompileFileGenerator.h
+++ b/Source/cmExportTryCompileFileGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmExportTryCompileFileGenerator_h
#define cmExportTryCompileFileGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmExportFileGenerator.h"
@@ -21,21 +21,23 @@ class cmExportTryCompileFileGenerator : public cmExportFileGenerator
public:
cmExportTryCompileFileGenerator(cmGlobalGenerator* gg,
std::vector<std::string> const& targets,
- cmMakefile* mf);
+ cmMakefile* mf,
+ std::set<std::string> const& langs);
/** Set the list of targets to export. */
void SetConfig(const std::string& config) { this->Config = config; }
+
protected:
// Implement virtual methods from the superclass.
- bool GenerateMainFile(std::ostream& os) CM_OVERRIDE;
+ bool GenerateMainFile(std::ostream& os) override;
void GenerateImportTargetsConfig(std::ostream&, const std::string&,
std::string const&,
- std::vector<std::string>&) CM_OVERRIDE
+ std::vector<std::string>&) override
{
}
void HandleMissingTarget(std::string&, std::vector<std::string>&,
- cmGeneratorTarget*, cmGeneratorTarget*) CM_OVERRIDE
+ cmGeneratorTarget*, cmGeneratorTarget*) override
{
}
@@ -44,15 +46,17 @@ protected:
std::set<const cmGeneratorTarget*>& emitted);
std::string InstallNameDir(cmGeneratorTarget* target,
- const std::string& config) CM_OVERRIDE;
+ const std::string& config) override;
private:
std::string FindTargets(const std::string& prop,
const cmGeneratorTarget* tgt,
+ std::string const& language,
std::set<const cmGeneratorTarget*>& emitted);
std::vector<cmGeneratorTarget const*> Exports;
std::string Config;
+ std::vector<std::string> Languages;
};
#endif
diff --git a/Source/cmExprParserHelper.cxx b/Source/cmExprParserHelper.cxx
index c3f026a4e..80c78a38c 100644
--- a/Source/cmExprParserHelper.cxx
+++ b/Source/cmExprParserHelper.cxx
@@ -2,25 +2,23 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExprParserHelper.h"
-#include "cmConfigure.h"
-
#include "cmExprLexer.h"
#include <iostream>
#include <sstream>
+#include <stdexcept>
+#include <utility>
int cmExpr_yyparse(yyscan_t yyscanner);
//
cmExprParserHelper::cmExprParserHelper()
{
this->FileLine = -1;
- this->FileName = CM_NULLPTR;
+ this->FileName = nullptr;
+ this->Result = 0;
}
-cmExprParserHelper::~cmExprParserHelper()
-{
- this->CleanupParser();
-}
+cmExprParserHelper::~cmExprParserHelper() = default;
int cmExprParserHelper::ParseString(const char* str, int verb)
{
@@ -39,16 +37,34 @@ int cmExprParserHelper::ParseString(const char* str, int verb)
yyscan_t yyscanner;
cmExpr_yylex_init(&yyscanner);
cmExpr_yyset_extra(this, yyscanner);
- int res = cmExpr_yyparse(yyscanner);
+
+ try {
+ int res = cmExpr_yyparse(yyscanner);
+ if (res != 0) {
+ std::string e = "cannot parse the expression: \"" + InputBuffer + "\": ";
+ e += ErrorString;
+ e += ".";
+ this->SetError(std::move(e));
+ }
+ } catch (std::runtime_error const& fail) {
+ std::string e =
+ "cannot evaluate the expression: \"" + InputBuffer + "\": ";
+ e += fail.what();
+ e += ".";
+ this->SetError(std::move(e));
+ } catch (std::out_of_range const&) {
+ std::string e = "cannot evaluate the expression: \"" + InputBuffer +
+ "\": a numeric value is out of range.";
+ this->SetError(std::move(e));
+ } catch (...) {
+ std::string e = "cannot parse the expression: \"" + InputBuffer + "\".";
+ this->SetError(std::move(e));
+ }
cmExpr_yylex_destroy(yyscanner);
- if (res != 0) {
- // str << "CAL_Parser returned: " << res << std::endl;
- // std::cerr << "When parsing: [" << str << "]" << std::endl;
+ if (!this->ErrorString.empty()) {
return 0;
}
- this->CleanupParser();
-
if (Verbose) {
std::cerr << "Expanding [" << str << "] produced: [" << this->Result << "]"
<< std::endl;
@@ -56,10 +72,6 @@ int cmExprParserHelper::ParseString(const char* str, int verb)
return 1;
}
-void cmExprParserHelper::CleanupParser()
-{
-}
-
int cmExprParserHelper::LexInput(char* buf, int maxlen)
{
// std::cout << "JPLexInput ";
@@ -87,7 +99,21 @@ void cmExprParserHelper::Error(const char* str)
this->ErrorString = ostr.str();
}
-void cmExprParserHelper::SetResult(int value)
+void cmExprParserHelper::UnexpectedChar(char c)
+{
+ unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
+ std::ostringstream ostr;
+ ostr << "Unexpected character in expression at position " << pos << ": " << c
+ << "\n";
+ this->WarningString += ostr.str();
+}
+
+void cmExprParserHelper::SetResult(KWIML_INT_int64_t value)
{
this->Result = value;
}
+
+void cmExprParserHelper::SetError(std::string errorString)
+{
+ this->ErrorString = std::move(errorString);
+}
diff --git a/Source/cmExprParserHelper.h b/Source/cmExprParserHelper.h
index dcdaca967..42c460acc 100644
--- a/Source/cmExprParserHelper.h
+++ b/Source/cmExprParserHelper.h
@@ -5,6 +5,8 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cm_kwiml.h"
+
#include <string>
#include <vector>
@@ -13,7 +15,7 @@ class cmExprParserHelper
public:
struct ParserType
{
- int Number;
+ KWIML_INT_int64_t Number;
};
cmExprParserHelper();
@@ -24,12 +26,16 @@ public:
int LexInput(char* buf, int maxlen);
void Error(const char* str);
- void SetResult(int value);
+ void SetResult(KWIML_INT_int64_t value);
- int GetResult() { return this->Result; }
+ KWIML_INT_int64_t GetResult() { return this->Result; }
const char* GetError() { return this->ErrorString.c_str(); }
+ void UnexpectedChar(char c);
+
+ std::string const& GetWarning() const { return this->WarningString; }
+
private:
std::string::size_type InputBufferPos;
std::string InputBuffer;
@@ -39,12 +45,13 @@ private:
void Print(const char* place, const char* str);
- void CleanupParser();
+ void SetError(std::string errorString);
- int Result;
+ KWIML_INT_int64_t Result;
const char* FileName;
long FileLine;
std::string ErrorString;
+ std::string WarningString;
};
#define YYSTYPE cmExprParserHelper::ParserType
diff --git a/Source/cmExternalMakefileProjectGenerator.cxx b/Source/cmExternalMakefileProjectGenerator.cxx
index 825ec654e..ac548112a 100644
--- a/Source/cmExternalMakefileProjectGenerator.cxx
+++ b/Source/cmExternalMakefileProjectGenerator.cxx
@@ -2,6 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExternalMakefileProjectGenerator.h"
+#include <utility>
+
class cmMakefile;
void cmExternalMakefileProjectGenerator::EnableLanguage(
@@ -24,19 +26,23 @@ std::string cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
return fullName;
}
-cmExternalMakefileProjectGeneratorFactory::
- cmExternalMakefileProjectGeneratorFactory(const std::string& n,
- const std::string& doc)
- : Name(n)
- , Documentation(doc)
+bool cmExternalMakefileProjectGenerator::Open(
+ const std::string& /*bindir*/, const std::string& /*projectName*/,
+ bool /*dryRun*/)
{
+ return false;
}
cmExternalMakefileProjectGeneratorFactory::
- ~cmExternalMakefileProjectGeneratorFactory()
+ cmExternalMakefileProjectGeneratorFactory(std::string n, std::string doc)
+ : Name(std::move(n))
+ , Documentation(std::move(doc))
{
}
+cmExternalMakefileProjectGeneratorFactory::
+ ~cmExternalMakefileProjectGeneratorFactory() = default;
+
std::string cmExternalMakefileProjectGeneratorFactory::GetName() const
{
return this->Name;
diff --git a/Source/cmExternalMakefileProjectGenerator.h b/Source/cmExternalMakefileProjectGenerator.h
index 6b8903790..a472a0691 100644
--- a/Source/cmExternalMakefileProjectGenerator.h
+++ b/Source/cmExternalMakefileProjectGenerator.h
@@ -17,7 +17,7 @@ class cmMakefile;
* 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.
+ * See cmExtraEclipseCDT4Generator 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
@@ -26,18 +26,18 @@ class cmMakefile;
class cmExternalMakefileProjectGenerator
{
public:
- virtual ~cmExternalMakefileProjectGenerator() {}
+ virtual ~cmExternalMakefileProjectGenerator() = default;
virtual void EnableLanguage(std::vector<std::string> const& languages,
cmMakefile*, bool optional);
- ///! set the global generator which will generate the makefiles
+ //! 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
+ //! Return the list of global generators supported by this extra generator
const std::vector<std::string>& GetSupportedGlobalGenerators() const
{
return this->SupportedGlobalGenerators;
@@ -49,17 +49,20 @@ public:
static std::string CreateFullGeneratorName(
const std::string& globalGenerator, const std::string& extraGenerator);
- ///! Generate the project files, the Makefiles have already been generated
+ //! Generate the project files, the Makefiles have already been generated
virtual void Generate() = 0;
void SetName(const std::string& n) { Name = n; }
std::string GetName() const { return Name; }
+ virtual bool Open(const std::string& bindir, const std::string& projectName,
+ bool dryRun);
+
protected:
- ///! Contains the names of the global generators support by this generator.
+ //! 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;
+ //! the global generator which creates the makefiles
+ const cmGlobalGenerator* GlobalGenerator = nullptr;
std::string Name;
};
@@ -67,8 +70,7 @@ protected:
class cmExternalMakefileProjectGeneratorFactory
{
public:
- cmExternalMakefileProjectGeneratorFactory(const std::string& n,
- const std::string& doc);
+ cmExternalMakefileProjectGeneratorFactory(std::string n, std::string doc);
virtual ~cmExternalMakefileProjectGeneratorFactory();
std::string GetName() const;
@@ -99,7 +101,7 @@ public:
}
cmExternalMakefileProjectGenerator* CreateExternalMakefileProjectGenerator()
- const CM_OVERRIDE
+ const override
{
T* p = new T;
p->SetName(GetName());
diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx
index 5b7b82762..f47744b60 100644
--- a/Source/cmExtraCodeBlocksGenerator.cxx
+++ b/Source/cmExtraCodeBlocksGenerator.cxx
@@ -4,7 +4,7 @@
#include <map>
#include <ostream>
-#include <string.h>
+#include <set>
#include <utility>
#include "cmAlgorithms.h"
@@ -13,6 +13,7 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
@@ -32,10 +33,7 @@ Discussion:
http://forums.codeblocks.org/index.php/topic,6789.0.html
*/
-cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator()
- : cmExternalMakefileProjectGenerator()
-{
-}
+cmExtraCodeBlocksGenerator::cmExtraCodeBlocksGenerator() = default;
cmExternalMakefileProjectGeneratorFactory*
cmExtraCodeBlocksGenerator::GetFactory()
@@ -62,11 +60,9 @@ cmExtraCodeBlocksGenerator::GetFactory()
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) {
+ for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
// create a project file
- this->CreateProjectFile(it->second);
+ this->CreateProjectFile(it.second);
}
}
@@ -95,7 +91,7 @@ struct Tree
{
std::string path; // only one component of the path
std::vector<Tree> folders;
- std::vector<std::string> files;
+ std::set<std::string> files;
void InsertPath(const std::vector<std::string>& splitted,
std::vector<std::string>::size_type start,
const std::string& fileName);
@@ -112,18 +108,17 @@ void Tree::InsertPath(const std::vector<std::string>& splitted,
const std::string& fileName)
{
if (start == splitted.size()) {
- files.push_back(fileName);
+ files.insert(fileName);
return;
}
- for (std::vector<Tree>::iterator it = folders.begin(); it != folders.end();
- ++it) {
- if ((*it).path == splitted[start]) {
+ for (Tree& folder : folders) {
+ if (folder.path == splitted[start]) {
if (start + 1 < splitted.size()) {
- it->InsertPath(splitted, start + 1, fileName);
+ folder.InsertPath(splitted, start + 1, fileName);
return;
}
// last part of splitted
- it->files.push_back(fileName);
+ folder.files.insert(fileName);
return;
}
}
@@ -136,7 +131,7 @@ void Tree::InsertPath(const std::vector<std::string>& splitted,
return;
}
// last part of splitted
- newFolder.files.push_back(fileName);
+ newFolder.files.insert(fileName);
folders.push_back(newFolder);
}
@@ -144,9 +139,8 @@ void Tree::BuildVirtualFolder(cmXMLWriter& xml) const
{
xml.StartElement("Option");
std::string virtualFolders = "CMake Files\\;";
- for (std::vector<Tree>::const_iterator it = folders.begin();
- it != folders.end(); ++it) {
- it->BuildVirtualFolderImpl(virtualFolders, "");
+ for (Tree const& folder : folders) {
+ folder.BuildVirtualFolderImpl(virtualFolders, "");
}
xml.Attribute("virtualFolders", virtualFolders);
xml.EndElement();
@@ -156,18 +150,16 @@ 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 + "\\");
+ for (Tree const& folder : folders) {
+ folder.BuildVirtualFolderImpl(virtualFolders, prefix + path + "\\");
}
}
void Tree::BuildUnit(cmXMLWriter& xml, const std::string& fsPath) const
{
- for (std::vector<std::string>::const_iterator it = files.begin();
- it != files.end(); ++it) {
+ for (std::string const& f : files) {
xml.StartElement("Unit");
- xml.Attribute("filename", fsPath + *it);
+ xml.Attribute("filename", fsPath + f);
xml.StartElement("Option");
xml.Attribute("virtualFolder", "CMake Files\\");
@@ -175,9 +167,8 @@ void Tree::BuildUnit(cmXMLWriter& xml, const std::string& fsPath) const
xml.EndElement();
}
- for (std::vector<Tree>::const_iterator it = folders.begin();
- it != folders.end(); ++it) {
- it->BuildUnitImpl(xml, "", fsPath);
+ for (Tree const& folder : folders) {
+ folder.BuildUnitImpl(xml, "", fsPath);
}
}
@@ -185,10 +176,9 @@ void Tree::BuildUnitImpl(cmXMLWriter& xml,
const std::string& virtualFolderPath,
const std::string& fsPath) const
{
- for (std::vector<std::string>::const_iterator it = files.begin();
- it != files.end(); ++it) {
+ for (std::string const& f : files) {
xml.StartElement("Unit");
- xml.Attribute("filename", fsPath + path + "/" + *it);
+ xml.Attribute("filename", fsPath + path + "/" + f);
xml.StartElement("Option");
xml.Attribute("virtualFolder",
@@ -197,10 +187,9 @@ void Tree::BuildUnitImpl(cmXMLWriter& xml,
xml.EndElement();
}
- for (std::vector<Tree>::const_iterator it = folders.begin();
- it != folders.end(); ++it) {
- it->BuildUnitImpl(xml, virtualFolderPath + path + "\\",
- fsPath + path + "/");
+ for (Tree const& folder : folders) {
+ folder.BuildUnitImpl(xml, virtualFolderPath + path + "\\",
+ fsPath + path + "/");
}
}
@@ -208,7 +197,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
{
const cmMakefile* mf = lgs[0]->GetMakefile();
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -216,29 +205,22 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
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) {
+ for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
// 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());
+ for (cmLocalGenerator* lg : it.second) {
+ cmAppend(listFiles, lg->GetMakefile()->GetListFiles());
}
// Convert
- for (std::vector<std::string>::const_iterator jt = listFiles.begin();
- jt != listFiles.end(); ++jt) {
+ for (std::string const& listFile : listFiles) {
// don't put cmake's own files into the project (#12110):
- if (jt->find(cmSystemTools::GetCMakeRoot()) == 0) {
+ if (listFile.find(cmSystemTools::GetCMakeRoot()) == 0) {
continue;
}
const std::string& relative = cmSystemTools::RelativePath(
- it->second[0]->GetSourceDirectory(), jt->c_str());
+ it.second[0]->GetSourceDirectory(), listFile);
std::vector<std::string> splitted;
cmSystemTools::SplitPath(relative, splitted, false);
// Split filename from path
@@ -248,7 +230,14 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// We don't want paths with CMakeFiles in them
// or do we?
// In speedcrunch those where purely internal
+ //
+ // Also we can disable external (outside the project) files by setting ON
+ // CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable.
+ const bool excludeExternal =
+ cmSystemTools::IsOn(it.second[0]->GetMakefile()->GetSafeDefinition(
+ "CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES"));
if (!splitted.empty() &&
+ (!excludeExternal || (relative.find("..") == std::string::npos)) &&
relative.find("CMakeFiles") == std::string::npos) {
tree.InsertPath(splitted, 1, fileName);
}
@@ -257,8 +246,8 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// figure out the compiler
std::string compiler = this->GetCBCompilerId(mf);
- std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
- const std::string makeArgs =
+ const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& makeArgs =
mf->GetSafeDefinition("CMAKE_CODEBLOCKS_MAKE_ARGUMENTS");
cmXMLWriter xml(fout);
@@ -289,25 +278,21 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
xml.StartElement("Build");
- this->AppendTarget(xml, "all", CM_NULLPTR, make.c_str(), lgs[0],
- compiler.c_str(), makeArgs);
+ this->AppendTarget(xml, "all", nullptr, make, lgs[0], compiler, makeArgs);
// 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++) {
- std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ti++) {
- std::string targetName = (*ti)->GetName();
- switch ((*ti)->GetType()) {
+ for (cmLocalGenerator* lg : lgs) {
+ const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ std::string targetName = target->GetName();
+ switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
// Only add the global targets from CMAKE_BINARY_DIR,
// not from the subdirs
- if (strcmp((*lg)->GetCurrentBinaryDirectory(),
- (*lg)->GetBinaryDirectory()) == 0) {
- this->AppendTarget(xml, targetName, CM_NULLPTR, make.c_str(), *lg,
- compiler.c_str(), makeArgs);
+ if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) {
+ this->AppendTarget(xml, targetName, nullptr, make, lg, compiler,
+ makeArgs);
}
} break;
case cmStateEnums::UTILITY:
@@ -322,21 +307,21 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
break;
}
- this->AppendTarget(xml, targetName, CM_NULLPTR, make.c_str(), *lg,
- compiler.c_str(), makeArgs);
+ this->AppendTarget(xml, targetName, nullptr, make, lg, compiler,
+ makeArgs);
break;
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: {
- cmGeneratorTarget* gt = *ti;
- this->AppendTarget(xml, targetName, gt, make.c_str(), *lg,
- compiler.c_str(), makeArgs);
+ cmGeneratorTarget* gt = target;
+ this->AppendTarget(xml, targetName, gt, make, lg, compiler,
+ makeArgs);
std::string fastTarget = targetName;
fastTarget += "/fast";
- this->AppendTarget(xml, fastTarget, gt, make.c_str(), *lg,
- compiler.c_str(), makeArgs);
+ this->AppendTarget(xml, fastTarget, gt, make, lg, compiler,
+ makeArgs);
} break;
default:
break;
@@ -347,22 +332,19 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
xml.EndElement(); // Build
// Collect all used source files in the project.
- // Keep a list of C/C++ source files which might have an acompanying header
+ // Keep a list of C/C++ source files which might have an accompanying header
// that should be looked for.
typedef std::map<std::string, CbpUnit> all_files_map_t;
all_files_map_t allFiles;
std::vector<std::string> cFiles;
- std::vector<std::string> const& srcExts =
- this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
+ auto cm = this->GlobalGenerator->GetCMakeInstance();
- for (std::vector<cmLocalGenerator*>::const_iterator lg = lgs.begin();
- lg != lgs.end(); lg++) {
- cmMakefile* makefile = (*lg)->GetMakefile();
- std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ti++) {
- switch ((*ti)->GetType()) {
+ for (cmLocalGenerator* lg : lgs) {
+ cmMakefile* makefile = lg->GetMakefile();
+ const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ switch (target->GetType()) {
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::SHARED_LIBRARY:
@@ -371,41 +353,46 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
case cmStateEnums::UTILITY: // can have sources since 2.6.3
{
std::vector<cmSourceFile*> sources;
- cmGeneratorTarget* gt = *ti;
+ cmGeneratorTarget* gt = target;
gt->GetSourceFiles(sources,
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
- for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
- si != sources.end(); si++) {
+ for (cmSourceFile* s : sources) {
// don't add source files from UTILITY target which have the
// GENERATED property set:
if (gt->GetType() == cmStateEnums::UTILITY &&
- (*si)->GetPropertyAsBool("GENERATED")) {
+ s->GetIsGenerated()) {
continue;
}
- // check whether it is a C/C++ implementation file
+ // check whether it is a C/C++/CUDA implementation file
bool isCFile = false;
- std::string lang = (*si)->GetLanguage();
- if (lang == "C" || lang == "CXX") {
- std::string const& srcext = (*si)->GetExtension();
- for (std::vector<std::string>::const_iterator ext =
- srcExts.begin();
- ext != srcExts.end(); ++ext) {
- if (srcext == *ext) {
- isCFile = true;
- break;
- }
- }
+ std::string lang = s->GetLanguage();
+ if (lang == "C" || lang == "CXX" || lang == "CUDA") {
+ std::string const& srcext = s->GetExtension();
+ isCFile = cm->IsSourceExtension(srcext);
}
- std::string const& fullPath = (*si)->GetFullPath();
+ std::string const& fullPath = s->GetFullPath();
+
+ // Check file position relative to project root dir.
+ const std::string relative =
+ cmSystemTools::RelativePath(lg->GetSourceDirectory(), fullPath);
+ // Do not add this file if it has ".." in relative path and
+ // if CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES variable is on.
+ const bool excludeExternal =
+ cmSystemTools::IsOn(lg->GetMakefile()->GetSafeDefinition(
+ "CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES"));
+ if (excludeExternal &&
+ (relative.find("..") != std::string::npos)) {
+ continue;
+ }
if (isCFile) {
cFiles.push_back(fullPath);
}
CbpUnit& cbpUnit = allFiles[fullPath];
- cbpUnit.Targets.push_back(*ti);
+ cbpUnit.Targets.push_back(target);
}
}
default: // intended fallthrough
@@ -422,27 +409,24 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
// C/C++ 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
+ // A very similar version of that code exists also in the CodeLite
// project generator.
- for (std::vector<std::string>::const_iterator sit = cFiles.begin();
- sit != cFiles.end(); ++sit) {
- std::string const& fileName = *sit;
+ for (std::string const& fileName : cFiles) {
std::string headerBasename = cmSystemTools::GetFilenamePath(fileName);
headerBasename += "/";
headerBasename += cmSystemTools::GetFilenameWithoutExtension(fileName);
// check if there's a matching header around
- for (std::vector<std::string>::const_iterator ext = headerExts.begin();
- ext != headerExts.end(); ++ext) {
+ for (std::string const& ext : headerExts) {
std::string hname = headerBasename;
hname += ".";
- hname += *ext;
+ hname += ext;
// if it's already in the set, don't check if it exists on disk
if (allFiles.find(hname) != allFiles.end()) {
break;
}
- if (cmSystemTools::FileExists(hname.c_str())) {
+ if (cmSystemTools::FileExists(hname)) {
allFiles[hname].Targets = allFiles[fileName].Targets;
break;
}
@@ -450,19 +434,16 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
}
// insert all source files in the CodeBlocks project
- for (all_files_map_t::const_iterator sit = allFiles.begin();
- sit != allFiles.end(); ++sit) {
- std::string const& unitFilename = sit->first;
- CbpUnit const& unit = sit->second;
+ for (auto const& s : allFiles) {
+ std::string const& unitFilename = s.first;
+ CbpUnit const& unit = s.second;
xml.StartElement("Unit");
xml.Attribute("filename", unitFilename);
- for (std::vector<const cmGeneratorTarget*>::const_iterator ti =
- unit.Targets.begin();
- ti != unit.Targets.end(); ++ti) {
+ for (cmGeneratorTarget const* tgt : unit.Targets) {
xml.StartElement("Option");
- xml.Attribute("target", (*ti)->GetName());
+ xml.Attribute("target", tgt->GetName());
xml.EndElement();
}
@@ -470,7 +451,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile(
}
// Add CMakeLists.txt
- tree.BuildUnit(xml, std::string(mf->GetHomeDirectory()) + "/");
+ tree.BuildUnit(xml, mf->GetHomeDirectory() + "/");
xml.EndElement(); // Project
xml.EndElement(); // CodeBlocks_project_file
@@ -490,7 +471,7 @@ std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
filename += "/";
filename += target->GetName();
filename += ".objlib";
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (fout) {
/* clang-format off */
fout << "# This is a dummy file for the OBJECT library "
@@ -505,8 +486,8 @@ std::string cmExtraCodeBlocksGenerator::CreateDummyTargetFile(
// Generate the xml code for one target.
void cmExtraCodeBlocksGenerator::AppendTarget(
cmXMLWriter& xml, const std::string& targetName, cmGeneratorTarget* target,
- const char* make, const cmLocalGenerator* lg, const char* compiler,
- const std::string& makeFlags)
+ const std::string& make, const cmLocalGenerator* lg,
+ const std::string& compiler, const std::string& makeFlags)
{
cmMakefile const* makefile = lg->GetMakefile();
std::string makefileName = lg->GetCurrentBinaryDirectory();
@@ -515,7 +496,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(
xml.StartElement("Target");
xml.Attribute("title", targetName);
- if (target != CM_NULLPTR) {
+ if (target != nullptr) {
int cbTargetType = this->GetCBTargetType(target);
std::string workingDir = lg->GetCurrentBinaryDirectory();
if (target->GetType() == cmStateEnums::EXECUTABLE) {
@@ -523,12 +504,12 @@ void cmExtraCodeBlocksGenerator::AppendTarget(
// set the working directory to this dir.
const char* runtimeOutputDir =
makefile->GetDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY");
- if (runtimeOutputDir != CM_NULLPTR) {
+ if (runtimeOutputDir != nullptr) {
workingDir = runtimeOutputDir;
} else {
const char* executableOutputDir =
makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
- if (executableOutputDir != CM_NULLPTR) {
+ if (executableOutputDir != nullptr) {
workingDir = executableOutputDir;
}
}
@@ -572,45 +553,40 @@ void cmExtraCodeBlocksGenerator::AppendTarget(
target->GetCompileDefinitions(cdefs, buildType, "C");
// Expand the list.
- for (std::vector<std::string>::const_iterator di = cdefs.begin();
- di != cdefs.end(); ++di) {
+ for (std::string const& d : cdefs) {
xml.StartElement("Add");
- xml.Attribute("option", "-D" + *di);
+ xml.Attribute("option", "-D" + d);
xml.EndElement();
}
// the include directories for this target
std::vector<std::string> allIncludeDirs;
-
- std::vector<std::string> includes;
- lg->GetIncludeDirectories(includes, target, "C", buildType);
-
- allIncludeDirs.insert(allIncludeDirs.end(), includes.begin(),
- includes.end());
+ {
+ std::vector<std::string> includes;
+ lg->GetIncludeDirectories(includes, target, "C", buildType);
+ cmAppend(allIncludeDirs, includes);
+ }
std::string systemIncludeDirs = makefile->GetSafeDefinition(
"CMAKE_EXTRA_GENERATOR_CXX_SYSTEM_INCLUDE_DIRS");
if (!systemIncludeDirs.empty()) {
- std::vector<std::string> dirs;
- cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
- allIncludeDirs.insert(allIncludeDirs.end(), dirs.begin(), dirs.end());
+ cmAppend(allIncludeDirs,
+ cmSystemTools::ExpandedListArgument(systemIncludeDirs));
}
systemIncludeDirs = makefile->GetSafeDefinition(
"CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS");
if (!systemIncludeDirs.empty()) {
- std::vector<std::string> dirs;
- cmSystemTools::ExpandListArgument(systemIncludeDirs, dirs);
- allIncludeDirs.insert(allIncludeDirs.end(), dirs.begin(), dirs.end());
+ cmAppend(allIncludeDirs,
+ cmSystemTools::ExpandedListArgument(systemIncludeDirs));
}
std::vector<std::string>::const_iterator end =
cmRemoveDuplicates(allIncludeDirs);
- for (std::vector<std::string>::const_iterator i = allIncludeDirs.begin();
- i != end; ++i) {
+ for (std::string const& str : cmMakeRange(allIncludeDirs.cbegin(), end)) {
xml.StartElement("Add");
- xml.Attribute("directory", *i);
+ xml.Attribute("directory", str);
xml.EndElement();
}
@@ -629,23 +605,25 @@ void cmExtraCodeBlocksGenerator::AppendTarget(
xml.StartElement("MakeCommands");
xml.StartElement("Build");
- xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
- targetName, makeFlags));
+ xml.Attribute(
+ "command",
+ this->BuildMakeCommand(make, makefileName, targetName, makeFlags));
xml.EndElement();
xml.StartElement("CompileFile");
- xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
- "\"$file\"", makeFlags));
+ xml.Attribute(
+ "command",
+ this->BuildMakeCommand(make, makefileName, "\"$file\"", makeFlags));
xml.EndElement();
xml.StartElement("Clean");
- xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
- "clean", makeFlags));
+ xml.Attribute(
+ "command", this->BuildMakeCommand(make, makefileName, "clean", makeFlags));
xml.EndElement();
xml.StartElement("DistClean");
- xml.Attribute("command", this->BuildMakeCommand(make, makefileName.c_str(),
- "clean", makeFlags));
+ xml.Attribute(
+ "command", this->BuildMakeCommand(make, makefileName, "clean", makeFlags));
xml.EndElement();
xml.EndElement(); // MakeCommands
@@ -655,6 +633,13 @@ void cmExtraCodeBlocksGenerator::AppendTarget(
// Translate the cmake compiler id into the CodeBlocks compiler id
std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
{
+ // allow the user to overwrite the detected compiler
+ std::string userCompiler =
+ mf->GetSafeDefinition("CMAKE_CODEBLOCKS_COMPILER_ID");
+ if (!userCompiler.empty()) {
+ return userCompiler;
+ }
+
// figure out which language to use
// for now care only for C, C++, and Fortran
@@ -670,7 +655,7 @@ std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf)
pureFortran = true;
}
- std::string compilerId = mf->GetSafeDefinition(compilerIdVar);
+ std::string const& compilerId = mf->GetSafeDefinition(compilerIdVar);
std::string compiler = "gcc"; // default to gcc
if (compilerId == "MSVC") {
if (mf->IsDefinitionSet("MSVC10")) {
@@ -732,8 +717,8 @@ int cmExtraCodeBlocksGenerator::GetCBTargetType(cmGeneratorTarget* target)
// 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,
- const std::string& makeFlags)
+ const std::string& make, const std::string& makefile,
+ const std::string& target, const std::string& makeFlags)
{
std::string command = make;
if (!makeFlags.empty()) {
@@ -754,7 +739,7 @@ std::string cmExtraCodeBlocksGenerator::BuildMakeCommand(
} else if (generator == "MinGW Makefiles") {
// no escaping of spaces in this case, see
// https://gitlab.kitware.com/cmake/cmake/issues/10014
- std::string makefileName = makefile;
+ std::string const& makefileName = makefile;
command += " -f \"";
command += makefileName;
command += "\" ";
diff --git a/Source/cmExtraCodeBlocksGenerator.h b/Source/cmExtraCodeBlocksGenerator.h
index 450a9d02c..173e28400 100644
--- a/Source/cmExtraCodeBlocksGenerator.h
+++ b/Source/cmExtraCodeBlocksGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmExtraCodeBlocksGenerator_h
#define cmExtraCodeBlocksGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmExternalMakefileProjectGenerator.h"
@@ -25,7 +25,7 @@ public:
static cmExternalMakefileProjectGeneratorFactory* GetFactory();
- void Generate() CM_OVERRIDE;
+ void Generate() override;
private:
struct CbpUnit
@@ -42,12 +42,13 @@ private:
std::string GetCBCompilerId(const cmMakefile* mf);
int GetCBTargetType(cmGeneratorTarget* target);
- std::string BuildMakeCommand(const std::string& make, const char* makefile,
+ std::string BuildMakeCommand(const std::string& make,
+ const std::string& makefile,
const std::string& target,
const std::string& makeFlags);
void AppendTarget(cmXMLWriter& xml, const std::string& targetName,
- cmGeneratorTarget* target, const char* make,
- const cmLocalGenerator* lg, const char* compiler,
+ cmGeneratorTarget* target, const std::string& make,
+ const cmLocalGenerator* lg, const std::string& compiler,
const std::string& makeFlags);
};
diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx
index b478f34fa..6fe8c147f 100644
--- a/Source/cmExtraCodeLiteGenerator.cxx
+++ b/Source/cmExtraCodeLiteGenerator.cxx
@@ -21,9 +21,7 @@
#include <utility>
cmExtraCodeLiteGenerator::cmExtraCodeLiteGenerator()
- : cmExternalMakefileProjectGenerator()
- , ConfigName("NoConfig")
- , CpuCount(2)
+ : ConfigName("NoConfig")
{
}
@@ -54,32 +52,29 @@ void cmExtraCodeLiteGenerator::Generate()
std::string workspaceFileName;
std::string workspaceSourcePath;
- const std::map<std::string, std::vector<cmLocalGenerator*> >& projectMap =
+ const std::map<std::string, std::vector<cmLocalGenerator*>>& projectMap =
this->GlobalGenerator->GetProjectMap();
// loop projects and locate the root project.
// and extract the information for creating the worspace
// root makefile
- for (std::map<std::string, std::vector<cmLocalGenerator*> >::const_iterator
- it = projectMap.begin();
- it != projectMap.end(); ++it) {
- const cmMakefile* mf = it->second[0]->GetMakefile();
+ for (auto const& it : projectMap) {
+ cmLocalGenerator* lg = it.second[0];
+ const cmMakefile* mf = lg->GetMakefile();
this->ConfigName = GetConfigurationName(mf);
- if (strcmp(it->second[0]->GetCurrentBinaryDirectory(),
- it->second[0]->GetBinaryDirectory()) == 0) {
- workspaceOutputDir = it->second[0]->GetCurrentBinaryDirectory();
- workspaceProjectName = it->second[0]->GetProjectName();
- workspaceSourcePath = it->second[0]->GetSourceDirectory();
+ if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) {
+ workspaceOutputDir = lg->GetCurrentBinaryDirectory();
+ workspaceProjectName = lg->GetProjectName();
+ workspaceSourcePath = lg->GetSourceDirectory();
workspaceFileName = workspaceOutputDir + "/";
workspaceFileName += workspaceProjectName + ".workspace";
- this->WorkspacePath = it->second[0]->GetCurrentBinaryDirectory();
- ;
+ this->WorkspacePath = lg->GetCurrentBinaryDirectory();
break;
}
}
- cmGeneratedFileStream fout(workspaceFileName.c_str());
+ cmGeneratedFileStream fout(workspaceFileName);
cmXMLWriter xml(fout);
xml.StartDocument("utf-8");
@@ -101,10 +96,9 @@ void cmExtraCodeLiteGenerator::Generate()
xml.Attribute("Name", this->ConfigName);
xml.Attribute("Selected", "yes");
- for (std::vector<std::string>::iterator it(ProjectNames.begin());
- it != ProjectNames.end(); it++) {
+ for (std::string const& it : ProjectNames) {
xml.StartElement("Project");
- xml.Attribute("Name", *it);
+ xml.Attribute("Name", it);
xml.Attribute("ConfigName", this->ConfigName);
xml.EndElement();
}
@@ -122,19 +116,16 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
// for each target in the workspace create a codelite project
const std::vector<cmLocalGenerator*>& lgs =
this->GlobalGenerator->GetLocalGenerators();
- for (std::vector<cmLocalGenerator*>::const_iterator lg(lgs.begin());
- lg != lgs.end(); lg++) {
- for (std::vector<cmGeneratorTarget*>::const_iterator lt =
- (*lg)->GetGeneratorTargets().begin();
- lt != (*lg)->GetGeneratorTargets().end(); lt++) {
- cmStateEnums::TargetType type = (*lt)->GetType();
- std::string outputDir = (*lg)->GetCurrentBinaryDirectory();
- std::string targetName = (*lt)->GetName();
+ for (cmLocalGenerator* lg : lgs) {
+ for (cmGeneratorTarget* lt : lg->GetGeneratorTargets()) {
+ cmStateEnums::TargetType type = lt->GetType();
+ std::string const& outputDir = lg->GetCurrentBinaryDirectory();
+ std::string targetName = lt->GetName();
std::string filename = outputDir + "/" + targetName + ".project";
retval.push_back(targetName);
// Make the project file relative to the workspace
- std::string relafilename = cmSystemTools::RelativePath(
- this->WorkspacePath.c_str(), filename.c_str());
+ std::string relafilename =
+ cmSystemTools::RelativePath(this->WorkspacePath, filename);
std::string visualname = targetName;
switch (type) {
case cmStateEnums::SHARED_LIBRARY:
@@ -149,7 +140,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByTarget(
xml->Attribute("Active", "No");
xml->EndElement();
- CreateNewProjectFile(*lt, filename);
+ CreateNewProjectFile(lt, filename);
break;
default:
break;
@@ -165,21 +156,18 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByProjectMaps(
{
std::vector<std::string> retval;
// 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++) {
+ for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
- std::string outputDir = it->second[0]->GetCurrentBinaryDirectory();
- std::string projectName = it->second[0]->GetProjectName();
+ std::string const& outputDir = it.second[0]->GetCurrentBinaryDirectory();
+ std::string projectName = it.second[0]->GetProjectName();
retval.push_back(projectName);
std::string filename = outputDir + "/" + projectName + ".project";
// Make the project file relative to the workspace
- filename = cmSystemTools::RelativePath(this->WorkspacePath.c_str(),
- filename.c_str());
+ filename = cmSystemTools::RelativePath(this->WorkspacePath, filename);
// create a project file
- this->CreateProjectFile(it->second);
+ this->CreateProjectFile(it.second);
xml->StartElement("Project");
xml->Attribute("Name", projectName);
xml->Attribute("Path", filename);
@@ -193,7 +181,7 @@ std::vector<std::string> cmExtraCodeLiteGenerator::CreateProjectsByProjectMaps(
void cmExtraCodeLiteGenerator::CreateProjectFile(
const std::vector<cmLocalGenerator*>& lgs)
{
- std::string outputDir = lgs[0]->GetCurrentBinaryDirectory();
+ std::string const& outputDir = lgs[0]->GetCurrentBinaryDirectory();
std::string projectName = lgs[0]->GetProjectName();
std::string filename = outputDir + "/";
@@ -206,9 +194,6 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles(
std::map<std::string, cmSourceFile*>& cFiles,
std::set<std::string>& otherFiles)
{
- const std::vector<std::string>& srcExts =
- this->GlobalGenerator->GetCMakeInstance()->GetSourceExtensions();
-
std::string projectType;
switch (gt->GetType()) {
case cmStateEnums::EXECUTABLE: {
@@ -235,27 +220,19 @@ std::string cmExtraCodeLiteGenerator::CollectSourceFiles(
std::vector<cmSourceFile*> sources;
gt->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 const& srcext = (*si)->GetExtension();
- for (std::vector<std::string>::const_iterator ext = srcExts.begin();
- ext != srcExts.end(); ++ext) {
- if (srcext == *ext) {
- isCFile = true;
- break;
- }
- }
- }
-
+ for (cmSourceFile* s : sources) {
+ // check whether it is a source or a include file
// then put it accordingly into one of the two containers
- if (isCFile) {
- cFiles[(*si)->GetFullPath()] = *si;
- } else {
- otherFiles.insert((*si)->GetFullPath());
+ switch (cmSystemTools::GetFileFormat(s->GetExtension())) {
+ case cmSystemTools::C_FILE_FORMAT:
+ case cmSystemTools::CXX_FILE_FORMAT:
+ case cmSystemTools::CUDA_FILE_FORMAT:
+ case cmSystemTools::FORTRAN_FILE_FORMAT: {
+ cFiles[s->GetFullPath()] = s;
+ } break;
+ default: {
+ otherFiles.insert(s->GetFullPath());
+ }
}
}
}
@@ -269,7 +246,7 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
const std::vector<cmLocalGenerator*>& lgs, const std::string& filename)
{
const cmMakefile* mf = lgs[0]->GetMakefile();
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -285,17 +262,15 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
// 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
+ // which may have an accompanying 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();
- std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ti++) {
- projectType = CollectSourceFiles(makefile, *ti, cFiles, otherFiles);
+ for (cmLocalGenerator* lg : lgs) {
+ cmMakefile* makefile = lg->GetMakefile();
+ const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ projectType = CollectSourceFiles(makefile, target, cFiles, otherFiles);
}
}
@@ -321,28 +296,25 @@ void cmExtraCodeLiteGenerator::FindMatchingHeaderfiles(
// 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
+ // A very similar version of that code exists also in the CodeBlocks
// project generator.
- for (std::map<std::string, cmSourceFile*>::const_iterator sit =
- cFiles.begin();
- sit != cFiles.end(); ++sit) {
- std::string headerBasename = cmSystemTools::GetFilenamePath(sit->first);
+ for (auto const& sit : cFiles) {
+ std::string headerBasename = cmSystemTools::GetFilenamePath(sit.first);
headerBasename += "/";
- headerBasename += cmSystemTools::GetFilenameWithoutExtension(sit->first);
+ headerBasename += cmSystemTools::GetFilenameWithoutExtension(sit.first);
// check if there's a matching header around
- for (std::vector<std::string>::const_iterator ext = headerExts.begin();
- ext != headerExts.end(); ++ext) {
+ for (std::string const& ext : headerExts) {
std::string hname = headerBasename;
hname += ".";
- hname += *ext;
+ 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())) {
+ if (cmSystemTools::FileExists(hname)) {
otherFiles.insert(hname);
break;
}
@@ -358,10 +330,8 @@ void cmExtraCodeLiteGenerator::CreateFoldersAndFiles(
std::vector<std::string> components;
size_t numOfEndEl = 0;
- for (std::set<std::string>::const_iterator it = cFiles.begin();
- it != cFiles.end(); ++it) {
- std::string frelapath =
- cmSystemTools::RelativePath(projectPath.c_str(), it->c_str());
+ for (std::string const& cFile : cFiles) {
+ std::string frelapath = cmSystemTools::RelativePath(projectPath, cFile);
cmsys::SystemTools::SplitPath(frelapath, components, false);
components.pop_back(); // erase last member -> it is file, not folder
components.erase(components.begin()); // erase "root"
@@ -423,10 +393,8 @@ void cmExtraCodeLiteGenerator::CreateFoldersAndFiles(
const std::string& projectPath)
{
std::set<std::string> s;
- for (std::map<std::string, cmSourceFile*>::const_iterator it =
- cFiles.begin();
- it != cFiles.end(); ++it) {
- s.insert(it->first);
+ for (auto const& it : cFiles) {
+ s.insert(it.first);
}
this->CreateFoldersAndFiles(s, xml, projectPath);
}
@@ -437,7 +405,6 @@ void cmExtraCodeLiteGenerator::CreateProjectSourceEntries(
const std::string& projectPath, const cmMakefile* mf,
const std::string& projectType, const std::string& targetName)
{
-
cmXMLWriter& xml(*_xml);
FindMatchingHeaderfiles(cFiles, otherFiles);
// Create 2 virtual folders: src and include
@@ -498,11 +465,14 @@ void cmExtraCodeLiteGenerator::CreateProjectSourceEntries(
xml.EndElement(); // ResourceCompiler
xml.StartElement("General");
- std::string outputPath = mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
+ std::string outputPath =
+ mf->GetSafeDefinition("CMAKE_RUNTIME_OUTPUT_DIRECTORY");
+ if (outputPath.empty()) {
+ outputPath = mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
+ }
std::string relapath;
if (!outputPath.empty()) {
- relapath = cmSystemTools::RelativePath(this->WorkspacePath.c_str(),
- outputPath.c_str());
+ relapath = cmSystemTools::RelativePath(projectPath, outputPath);
xml.Attribute("OutputFile", relapath + "/$(ProjectName)");
} else {
xml.Attribute("OutputFile", "$(IntermediateDirectory)/$(ProjectName)");
@@ -574,7 +544,7 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
const cmGeneratorTarget* gt, const std::string& filename)
{
const cmMakefile* mf = gt->Makefile;
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -598,7 +568,7 @@ void cmExtraCodeLiteGenerator::CreateNewProjectFile(
// 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
+ // which may have an accompanying header, one for all other files
std::string projectType;
std::map<std::string, cmSourceFile*> cFiles;
@@ -626,7 +596,7 @@ std::string cmExtraCodeLiteGenerator::GetCodeLiteCompilerName(
compilerIdVar = "CMAKE_C_COMPILER_ID";
}
- std::string compilerId = mf->GetSafeDefinition(compilerIdVar);
+ std::string const& compilerId = mf->GetSafeDefinition(compilerIdVar);
std::string compiler = "gnu g++"; // default to g++
// Since we need the compiler for parsing purposes only
@@ -658,14 +628,14 @@ std::string cmExtraCodeLiteGenerator::GetConfigurationName(
std::string cmExtraCodeLiteGenerator::GetBuildCommand(
const cmMakefile* mf, const std::string& targetName) const
{
- std::string generator = mf->GetSafeDefinition("CMAKE_GENERATOR");
- std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& generator = mf->GetSafeDefinition("CMAKE_GENERATOR");
+ const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::string buildCommand = make; // Default
std::ostringstream ss;
if (generator == "NMake Makefiles" || generator == "Ninja") {
ss << make;
} else if (generator == "MinGW Makefiles" || generator == "Unix Makefiles") {
- ss << make << " -j " << this->CpuCount;
+ ss << make << " -f$(ProjectPath)/Makefile -j " << this->CpuCount;
}
if (!targetName.empty()) {
ss << " " << targetName;
@@ -699,11 +669,15 @@ 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");
+ const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& generator = mf->GetSafeDefinition("CMAKE_GENERATOR");
if (generator == "Unix Makefiles" || generator == "MinGW Makefiles") {
std::ostringstream ss;
- ss << make << " -f$(ProjectPath)/Makefile $(CurrentFileName).cpp.o";
+#if defined(_WIN32)
+ ss << make << " -f$(ProjectPath)/Makefile -B $(CurrentFileFullName).obj";
+#else
+ ss << make << " -f$(ProjectPath)/Makefile -B $(CurrentFileFullName).o";
+#endif
buildCommand = ss.str();
}
return buildCommand;
diff --git a/Source/cmExtraCodeLiteGenerator.h b/Source/cmExtraCodeLiteGenerator.h
index de330988d..dea7ebc11 100644
--- a/Source/cmExtraCodeLiteGenerator.h
+++ b/Source/cmExtraCodeLiteGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalCodeLiteGenerator_h
#define cmGlobalCodeLiteGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmExternalMakefileProjectGenerator.h"
@@ -23,7 +23,7 @@ class cmExtraCodeLiteGenerator : public cmExternalMakefileProjectGenerator
protected:
std::string ConfigName;
std::string WorkspacePath;
- unsigned int CpuCount;
+ unsigned int CpuCount = 2;
protected:
std::string GetCodeLiteCompilerName(const cmMakefile* mf) const;
@@ -60,7 +60,7 @@ public:
static cmExternalMakefileProjectGeneratorFactory* GetFactory();
- void Generate() CM_OVERRIDE;
+ void Generate() override;
void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);
void CreateNewProjectFile(const std::vector<cmLocalGenerator*>& lgs,
diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx
index 2a6ce98a7..aece3bc57 100644
--- a/Source/cmExtraEclipseCDT4Generator.cxx
+++ b/Source/cmExtraEclipseCDT4Generator.cxx
@@ -16,6 +16,7 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSourceFile.h"
#include "cmSourceGroup.h"
#include "cmState.h"
@@ -42,7 +43,6 @@ void AppendDictionary(cmXMLWriter& xml, const char* key, T const& value)
}
cmExtraEclipseCDT4Generator::cmExtraEclipseCDT4Generator()
- : cmExternalMakefileProjectGenerator()
{
this->SupportsVirtualFolders = true;
this->GenerateLinkedResources = true;
@@ -78,16 +78,15 @@ void cmExtraEclipseCDT4Generator::EnableLanguage(
std::vector<std::string> const& languages, cmMakefile* /*unused*/,
bool /*optional*/)
{
- for (std::vector<std::string>::const_iterator lit = languages.begin();
- lit != languages.end(); ++lit) {
- if (*lit == "CXX") {
+ for (std::string const& l : languages) {
+ if (l == "CXX") {
this->Natures.insert("org.eclipse.cdt.core.ccnature");
this->Natures.insert("org.eclipse.cdt.core.cnature");
this->CXXEnabled = true;
- } else if (*lit == "C") {
+ } else if (l == "C") {
this->Natures.insert("org.eclipse.cdt.core.cnature");
this->CEnabled = true;
- } else if (*lit == "Java") {
+ } else if (l == "Java") {
this->Natures.insert("org.eclipse.jdt.core.javanature");
}
}
@@ -100,7 +99,7 @@ void cmExtraEclipseCDT4Generator::Generate()
std::string eclipseVersion = mf->GetSafeDefinition("CMAKE_ECLIPSE_VERSION");
cmsys::RegularExpression regex(".*([0-9]+\\.[0-9]+).*");
- if (regex.find(eclipseVersion.c_str())) {
+ if (regex.find(eclipseVersion)) {
unsigned int majorVersion = 0;
unsigned int minorVersion = 0;
int res =
@@ -136,7 +135,7 @@ void cmExtraEclipseCDT4Generator::Generate()
if (!this->GenerateSourceProject &&
(mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"))) {
mf->IssueMessage(
- cmake::WARNING,
+ MessageType::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.");
@@ -144,7 +143,7 @@ void cmExtraEclipseCDT4Generator::Generate()
if (cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
this->HomeDirectory)) {
- mf->IssueMessage(cmake::WARNING,
+ mf->IssueMessage(MessageType::WARNING,
"The build directory is a subdirectory "
"of the source directory.\n"
"This is not supported well by Eclipse. It is strongly "
@@ -173,12 +172,12 @@ void cmExtraEclipseCDT4Generator::CreateSourceProjectFile()
// set up the project name: <project>-Source@<baseSourcePathName>
cmLocalGenerator* lg = this->GlobalGenerator->GetLocalGenerators()[0];
- std::string name =
- this->GenerateProjectName(lg->GetProjectName(), "Source",
- this->GetPathBasename(this->HomeDirectory));
+ std::string name = cmExtraEclipseCDT4Generator::GenerateProjectName(
+ lg->GetProjectName(), "Source",
+ cmExtraEclipseCDT4Generator::GetPathBasename(this->HomeDirectory));
const std::string filename = this->HomeDirectory + "/.project";
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -217,31 +216,31 @@ void cmExtraEclipseCDT4Generator::AddEnvVar(std::ostream& out,
std::string cacheEntryName = "CMAKE_ECLIPSE_ENVVAR_";
cacheEntryName += envVar;
- const char* cacheValue =
+ const std::string* cacheValue =
lg->GetState()->GetInitializedCacheValue(cacheEntryName);
// now we have both, decide which one to use
std::string valueToUse;
- if (!envVarSet && cacheValue == CM_NULLPTR) {
+ if (!envVarSet && cacheValue == nullptr) {
// nothing known, do nothing
- valueToUse = "";
- } else if (envVarSet && cacheValue == CM_NULLPTR) {
+ valueToUse.clear();
+ } else if (envVarSet && cacheValue == nullptr) {
// 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(), cmStateEnums::STRING, true);
mf->GetCMakeInstance()->SaveCache(lg->GetBinaryDirectory());
- } else if (!envVarSet && cacheValue != CM_NULLPTR) {
+ } else if (!envVarSet && cacheValue != nullptr) {
// It is already in the cache, but not in the env, so use it from the cache
- valueToUse = cacheValue;
+ 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;
+ valueToUse = *cacheValue;
if (valueToUse.find(envVarValue) == std::string::npos) {
valueToUse = envVarValue;
mf->AddCacheDefinition(cacheEntryName, valueToUse.c_str(),
@@ -263,7 +262,7 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
const std::string filename = this->HomeOutputDirectory + "/.project";
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -279,10 +278,12 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
xml.StartDocument("UTF-8");
xml.StartElement("projectDescription");
- xml.Element("name", this->GenerateProjectName(
- lg->GetProjectName(),
- mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
- this->GetPathBasename(this->HomeOutputDirectory)));
+ xml.Element("name",
+ cmExtraEclipseCDT4Generator::GenerateProjectName(
+ lg->GetProjectName(),
+ mf->GetSafeDefinition("CMAKE_BUILD_TYPE"),
+ cmExtraEclipseCDT4Generator::GetPathBasename(
+ this->HomeOutputDirectory)));
xml.Element("comment", "");
xml.Element("projects", "");
@@ -303,16 +304,17 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
// set the make command
AppendDictionary(xml, "org.eclipse.cdt.make.core.enabledIncrementalBuild",
"true");
- AppendDictionary(
- xml, "org.eclipse.cdt.make.core.build.command",
- this->GetEclipsePath(mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM")));
+ AppendDictionary(xml, "org.eclipse.cdt.make.core.build.command",
+ cmExtraEclipseCDT4Generator::GetEclipsePath(
+ mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM")));
AppendDictionary(xml, "org.eclipse.cdt.make.core.contents",
"org.eclipse.cdt.make.core.activeConfigSettings");
AppendDictionary(xml, "org.eclipse.cdt.make.core.build.target.inc", "all");
AppendDictionary(xml, "org.eclipse.cdt.make.core.build.arguments",
mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS"));
- AppendDictionary(xml, "org.eclipse.cdt.make.core.buildLocation",
- this->GetEclipsePath(this->HomeOutputDirectory));
+ AppendDictionary(
+ xml, "org.eclipse.cdt.make.core.buildLocation",
+ cmExtraEclipseCDT4Generator::GetEclipsePath(this->HomeOutputDirectory));
AppendDictionary(xml, "org.eclipse.cdt.make.core.useDefaultBuildCmd",
"false");
@@ -342,8 +344,9 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
"clean");
AppendDictionary(xml, "org.eclipse.cdt.make.core.fullBuildTarget", "all");
AppendDictionary(xml, "org.eclipse.cdt.make.core.buildArguments", "");
- AppendDictionary(xml, "org.eclipse.cdt.make.core.build.location",
- this->GetEclipsePath(this->HomeOutputDirectory));
+ AppendDictionary(
+ xml, "org.eclipse.cdt.make.core.build.location",
+ cmExtraEclipseCDT4Generator::GetEclipsePath(this->HomeOutputDirectory));
AppendDictionary(xml, "org.eclipse.cdt.make.core.autoBuildTarget", "all");
// set error parsers
@@ -380,20 +383,17 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
xml.StartElement("natures");
xml.Element("nature", "org.eclipse.cdt.make.core.makeNature");
xml.Element("nature", "org.eclipse.cdt.make.core.ScannerConfigNature");
- ;
- for (std::set<std::string>::const_iterator nit = this->Natures.begin();
- nit != this->Natures.end(); ++nit) {
- xml.Element("nature", *nit);
+ for (std::string const& n : this->Natures) {
+ xml.Element("nature", n);
}
if (const char* extraNaturesProp =
mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_NATURES")) {
std::vector<std::string> extraNatures;
cmSystemTools::ExpandListArgument(extraNaturesProp, extraNatures);
- for (std::vector<std::string>::const_iterator nit = extraNatures.begin();
- nit != extraNatures.end(); ++nit) {
- xml.Element("nature", *nit);
+ for (std::string const& n : extraNatures) {
+ xml.Element("nature", n);
}
}
@@ -410,14 +410,16 @@ void cmExtraEclipseCDT4Generator::CreateProjectFile()
std::string sourceLinkedResourceName = "[Source directory]";
std::string linkSourceDirectory =
- this->GetEclipsePath(lg->GetCurrentSourceDirectory());
+ cmExtraEclipseCDT4Generator::GetEclipsePath(
+ lg->GetCurrentSourceDirectory());
// .project dir can't be subdir of a linked resource dir
if (!cmSystemTools::IsSubDirectory(this->HomeOutputDirectory,
linkSourceDirectory)) {
- this->AppendLinkedResource(xml, sourceLinkedResourceName,
- this->GetEclipsePath(linkSourceDirectory),
- LinkToFolder);
- this->SrcLinkedResources.push_back(sourceLinkedResourceName);
+ cmExtraEclipseCDT4Generator::AppendLinkedResource(
+ xml, sourceLinkedResourceName,
+ cmExtraEclipseCDT4Generator::GetEclipsePath(linkSourceDirectory),
+ LinkToFolder);
+ this->SrcLinkedResources.push_back(std::move(sourceLinkedResourceName));
}
}
@@ -435,32 +437,30 @@ void cmExtraEclipseCDT4Generator::WriteGroups(
std::vector<cmSourceGroup> const& sourceGroups, std::string& linkName,
cmXMLWriter& xml)
{
- for (std::vector<cmSourceGroup>::const_iterator sgIt = sourceGroups.begin();
- sgIt != sourceGroups.end(); ++sgIt) {
+ for (cmSourceGroup const& sg : sourceGroups) {
std::string linkName3 = linkName;
linkName3 += "/";
- linkName3 += sgIt->GetFullName();
+ linkName3 += sg.GetFullName();
std::replace(linkName3.begin(), linkName3.end(), '\\', '/');
- this->AppendLinkedResource(xml, linkName3, "virtual:/virtual",
- VirtualFolder);
- std::vector<cmSourceGroup> const& children = sgIt->GetGroupChildren();
+ cmExtraEclipseCDT4Generator::AppendLinkedResource(
+ xml, linkName3, "virtual:/virtual", VirtualFolder);
+ std::vector<cmSourceGroup> const& children = sg.GetGroupChildren();
if (!children.empty()) {
this->WriteGroups(children, linkName, xml);
}
- std::vector<const cmSourceFile*> sFiles = sgIt->GetSourceFiles();
- for (std::vector<const cmSourceFile*>::const_iterator fileIt =
- sFiles.begin();
- fileIt != sFiles.end(); ++fileIt) {
- std::string const& fullPath = (*fileIt)->GetFullPath();
+ std::vector<const cmSourceFile*> sFiles = sg.GetSourceFiles();
+ for (cmSourceFile const* file : sFiles) {
+ std::string const& fullPath = file->GetFullPath();
if (!cmSystemTools::FileIsDirectory(fullPath)) {
std::string linkName4 = linkName3;
linkName4 += "/";
linkName4 += cmSystemTools::GetFilenameName(fullPath);
- this->AppendLinkedResource(xml, linkName4,
- this->GetEclipsePath(fullPath), LinkToFile);
+ cmExtraEclipseCDT4Generator::AppendLinkedResource(
+ xml, linkName4,
+ cmExtraEclipseCDT4Generator::GetEclipsePath(fullPath), LinkToFile);
}
}
}
@@ -469,49 +469,45 @@ void cmExtraEclipseCDT4Generator::WriteGroups(
void cmExtraEclipseCDT4Generator::CreateLinksForTargets(cmXMLWriter& xml)
{
std::string linkName = "[Targets]";
- this->AppendLinkedResource(xml, linkName, "virtual:/virtual", VirtualFolder);
+ cmExtraEclipseCDT4Generator::AppendLinkedResource(
+ xml, 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 std::vector<cmGeneratorTarget*> targets =
- (*lgIt)->GetGeneratorTargets();
+ for (cmLocalGenerator* lg : this->GlobalGenerator->GetLocalGenerators()) {
+ cmMakefile* makefile = lg->GetMakefile();
+ const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
+ for (cmGeneratorTarget* target : targets) {
std::string linkName2 = linkName;
linkName2 += "/";
- switch ((*ti)->GetType()) {
+ switch (target->GetType()) {
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: {
const char* prefix =
- ((*ti)->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
- : "[lib] ");
+ (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
+ : "[lib] ");
linkName2 += prefix;
- linkName2 += (*ti)->GetName();
- this->AppendLinkedResource(xml, linkName2, "virtual:/virtual",
- VirtualFolder);
+ linkName2 += target->GetName();
+ cmExtraEclipseCDT4Generator::AppendLinkedResource(
+ xml, 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
- cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(*ti);
+ cmGeneratorTarget* gt = const_cast<cmGeneratorTarget*>(target);
std::vector<cmSourceFile*> files;
gt->GetSourceFiles(files,
makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
- for (std::vector<cmSourceFile*>::const_iterator sfIt = files.begin();
- sfIt != files.end(); sfIt++) {
+ for (cmSourceFile* sf : files) {
// Add the file to the list of sources.
- std::string const& source = (*sfIt)->GetFullPath();
+ std::string const& source = sf->GetFullPath();
cmSourceGroup* sourceGroup =
- makefile->FindSourceGroup(source.c_str(), sourceGroups);
- sourceGroup->AssignSource(*sfIt);
+ makefile->FindSourceGroup(source, sourceGroups);
+ sourceGroup->AssignSource(sf);
}
this->WriteGroups(sourceGroups, linkName2, xml);
@@ -533,23 +529,23 @@ void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects(
// for each sub project create a linked resource to the source dir
// - only if it is an out-of-source build
- this->AppendLinkedResource(xml, "[Subprojects]", "virtual:/virtual",
- VirtualFolder);
+ cmExtraEclipseCDT4Generator::AppendLinkedResource(
+ xml, "[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) {
+ for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
std::string linkSourceDirectory =
- this->GetEclipsePath(it->second[0]->GetCurrentSourceDirectory());
+ cmExtraEclipseCDT4Generator::GetEclipsePath(
+ it.second[0]->GetCurrentSourceDirectory());
// a linked resource must not point to a parent directory of .project or
// .project itself
if ((baseDir != linkSourceDirectory) &&
!cmSystemTools::IsSubDirectory(baseDir, linkSourceDirectory)) {
std::string linkName = "[Subprojects]/";
- linkName += it->first;
- this->AppendLinkedResource(xml, linkName,
- this->GetEclipsePath(linkSourceDirectory),
- LinkToFolder);
+ linkName += it.first;
+ cmExtraEclipseCDT4Generator::AppendLinkedResource(
+ xml, linkName,
+ cmExtraEclipseCDT4Generator::GetEclipsePath(linkSourceDirectory),
+ LinkToFolder);
// Don't add it to the srcLinkedResources, because listing multiple
// directories confuses the Eclipse indexer (#13596).
}
@@ -560,16 +556,15 @@ void cmExtraEclipseCDT4Generator::AppendIncludeDirectories(
cmXMLWriter& xml, 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);
+ for (std::string const& inc : includeDirs) {
+ if (!inc.empty()) {
+ std::string dir = cmSystemTools::CollapseFullPath(inc);
// 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())) {
+ if (frameworkRx.find(dir)) {
dir = frameworkRx.match(1);
}
@@ -596,7 +591,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
const std::string filename = this->HomeOutputDirectory + "/.cproject";
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -656,7 +651,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
xml.EndElement(); // extension
} else if (systemName == "Darwin") {
xml.StartElement("extension");
- xml.Attribute("id", this->SupportsMachO64Parser
+ xml.Attribute("id",
+ this->SupportsMachO64Parser
? "org.eclipse.cdt.core.MachO64"
: "org.eclipse.cdt.core.MachO");
xml.Attribute("point", "org.eclipse.cdt.core.BinaryParser");
@@ -712,19 +708,17 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
xml.EndElement();
}
- for (std::vector<std::string>::const_iterator it =
- this->SrcLinkedResources.begin();
- it != this->SrcLinkedResources.end(); ++it) {
+ for (std::string const& p : this->SrcLinkedResources) {
xml.StartElement("pathentry");
xml.Attribute("kind", "src");
- xml.Attribute("path", *it);
+ xml.Attribute("path", p);
xml.EndElement();
- // exlude source directory from output search path
+ // exclude source directory from output search path
// - only if not named the same as an output directory
if (!cmSystemTools::FileIsDirectory(
- std::string(this->HomeOutputDirectory + "/" + *it))) {
- excludeFromOut += *it + "/|";
+ std::string(this->HomeOutputDirectory + "/" + p))) {
+ excludeFromOut += p + "/|";
}
}
@@ -738,34 +732,31 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// 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) {
+ for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
if (const char* cdefs =
- (*it)->GetMakefile()->GetProperty("COMPILE_DEFINITIONS")) {
+ lgen->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) {
+ for (std::string const& d : defs) {
+ if (cmGeneratorExpression::Find(d) != std::string::npos) {
continue;
}
- std::string::size_type equals = di->find('=', 0);
- std::string::size_type enddef = di->length();
+ std::string::size_type equals = d.find('=', 0);
+ std::string::size_type enddef = d.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);
+ def = d.substr(0, equals);
+ val = d.substr(equals + 1, enddef - equals + 1);
} else {
// we have -DFOO
- def = *di;
+ def = d;
}
// insert the definition if not already added.
@@ -850,15 +841,16 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// include dirs
emmited.clear();
- for (std::vector<cmLocalGenerator*>::const_iterator it =
- this->GlobalGenerator->GetLocalGenerators().begin();
- it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) {
- std::vector<cmGeneratorTarget*> targets = (*it)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = targets.begin();
- l != targets.end(); ++l) {
+ for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
+ const std::vector<cmGeneratorTarget*>& targets =
+ lgen->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ continue;
+ }
std::vector<std::string> includeDirs;
std::string config = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
- (*it)->GetIncludeDirectories(includeDirs, *l, "C", config);
+ lgen->GetIncludeDirectories(includeDirs, target, "C", config);
this->AppendIncludeDirectories(xml, includeDirs, emmited);
}
}
@@ -889,8 +881,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
xml.Attribute("moduleId", "org.eclipse.cdt.make.core.buildtargets");
xml.StartElement("buildTargets");
emmited.clear();
- const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
- const std::string makeArgs =
+ const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& makeArgs =
mf->GetSafeDefinition("CMAKE_ECLIPSE_MAKE_ARGUMENTS");
cmGlobalGenerator* generator =
@@ -907,26 +899,24 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// 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 std::vector<cmGeneratorTarget*> targets =
- (*it)->GetGeneratorTargets();
- std::string subdir = (*it)->ConvertToRelativePath(
- this->HomeOutputDirectory, (*it)->GetCurrentBinaryDirectory());
+ for (cmLocalGenerator* lgen : this->GlobalGenerator->GetLocalGenerators()) {
+ const std::vector<cmGeneratorTarget*>& targets =
+ lgen->GetGeneratorTargets();
+ std::string subdir = lgen->MaybeConvertToRelativePath(
+ this->HomeOutputDirectory, lgen->GetCurrentBinaryDirectory());
if (subdir == ".") {
- subdir = "";
+ subdir.clear();
}
- for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- std::string targetName = (*ti)->GetName();
- switch ((*ti)->GetType()) {
+ for (cmGeneratorTarget* target : targets) {
+ std::string targetName = target->GetName();
+ switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
// Only add the global targets from CMAKE_BINARY_DIR,
// not from the subdirs
if (subdir.empty()) {
- this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
+ cmExtraEclipseCDT4Generator::AppendTarget(xml, targetName, make,
+ makeArgs, subdir, ": ");
}
} break;
case cmStateEnums::UTILITY:
@@ -941,7 +931,8 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
break;
}
- this->AppendTarget(xml, targetName, make, makeArgs, subdir, ": ");
+ cmExtraEclipseCDT4Generator::AppendTarget(xml, targetName, make,
+ makeArgs, subdir, ": ");
break;
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
@@ -949,12 +940,14 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: {
const char* prefix =
- ((*ti)->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
- : "[lib] ");
- this->AppendTarget(xml, targetName, make, makeArgs, subdir, prefix);
+ (target->GetType() == cmStateEnums::EXECUTABLE ? "[exe] "
+ : "[lib] ");
+ cmExtraEclipseCDT4Generator::AppendTarget(xml, targetName, make,
+ makeArgs, subdir, prefix);
std::string fastTarget = targetName;
fastTarget += "/fast";
- this->AppendTarget(xml, fastTarget, make, makeArgs, subdir, prefix);
+ cmExtraEclipseCDT4Generator::AppendTarget(xml, fastTarget, make,
+ makeArgs, subdir, prefix);
// Add Build and Clean targets in the virtual folder of targets:
if (this->SupportsVirtualFolders) {
@@ -962,24 +955,27 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
virtDir += prefix;
virtDir += targetName;
std::string buildArgs = "-C \"";
- buildArgs += (*it)->GetBinaryDirectory();
+ buildArgs += lgen->GetBinaryDirectory();
buildArgs += "\" ";
buildArgs += makeArgs;
- this->AppendTarget(xml, "Build", make, buildArgs, virtDir, "",
- targetName.c_str());
+ cmExtraEclipseCDT4Generator::AppendTarget(
+ xml, "Build", make, buildArgs, virtDir, "", targetName.c_str());
std::string cleanArgs = "-E chdir \"";
- cleanArgs += (*it)->GetCurrentBinaryDirectory();
+ cleanArgs += lgen->GetCurrentBinaryDirectory();
cleanArgs += "\" \"";
cleanArgs += cmSystemTools::GetCMakeCommand();
cleanArgs += "\" -P \"";
- cmGeneratorTarget* gt = *ti;
- cleanArgs += (*it)->GetTargetDirectory(gt);
+ cmGeneratorTarget* gt = target;
+ cleanArgs += lgen->GetTargetDirectory(gt);
cleanArgs += "/cmake_clean.cmake\"";
- this->AppendTarget(xml, "Clean", cmSystemTools::GetCMakeCommand(),
- cleanArgs, virtDir, "", "");
+ cmExtraEclipseCDT4Generator::AppendTarget(
+ xml, "Clean", cmSystemTools::GetCMakeCommand(), cleanArgs,
+ virtDir, "", "");
}
} break;
+ case cmStateEnums::INTERFACE_LIBRARY:
+ break;
default:
break;
}
@@ -987,33 +983,34 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
// insert the all and clean targets in every subdir
if (!allTarget.empty()) {
- this->AppendTarget(xml, allTarget, make, makeArgs, subdir, ": ");
+ cmExtraEclipseCDT4Generator::AppendTarget(xml, allTarget, make, makeArgs,
+ subdir, ": ");
}
if (!cleanTarget.empty()) {
- this->AppendTarget(xml, cleanTarget, make, makeArgs, subdir, ": ");
+ cmExtraEclipseCDT4Generator::AppendTarget(xml, 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) {
+ lg->GetIndividualFileTargets(objectFileTargets);
+ for (std::string const& f : objectFileTargets) {
const char* prefix = "[obj] ";
- if ((*fit)[fit->length() - 1] == 's') {
+ if (f.back() == 's') {
prefix = "[to asm] ";
- } else if ((*fit)[fit->length() - 1] == 'i') {
+ } else if (f.back() == 'i') {
prefix = "[pre] ";
}
- this->AppendTarget(xml, *fit, make, makeArgs, subdir, prefix);
+ cmExtraEclipseCDT4Generator::AppendTarget(xml, f, make, makeArgs, subdir,
+ prefix);
}
}
xml.EndElement(); // buildTargets
xml.EndElement(); // storageModule
- this->AppendStorageScanners(xml, *mf);
+ cmExtraEclipseCDT4Generator::AppendStorageScanners(xml, *mf);
xml.EndElement(); // cconfiguration
xml.EndElement(); // storageModule
@@ -1028,6 +1025,13 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const
xml.EndElement(); // project
xml.EndElement(); // storageModule
+
+ // Append additional cproject contents without applying any XML formatting
+ if (const char* extraCProjectContents =
+ mf->GetState()->GetGlobalProperty("ECLIPSE_EXTRA_CPROJECT_CONTENTS")) {
+ fout << extraCProjectContents;
+ }
+
xml.EndElement(); // cproject
}
@@ -1053,8 +1057,7 @@ std::string cmExtraEclipseCDT4Generator::GetPathBasename(
{
std::string outputBasename = path;
while (!outputBasename.empty() &&
- (outputBasename[outputBasename.size() - 1] == '/' ||
- outputBasename[outputBasename.size() - 1] == '\\')) {
+ (outputBasename.back() == '/' || outputBasename.back() == '\\')) {
outputBasename.resize(outputBasename.size() - 1);
}
std::string::size_type loc = outputBasename.find_last_of("/\\");
@@ -1076,7 +1079,8 @@ void cmExtraEclipseCDT4Generator::AppendStorageScanners(
cmXMLWriter& xml, 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");
+ const 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()) {
diff --git a/Source/cmExtraEclipseCDT4Generator.h b/Source/cmExtraEclipseCDT4Generator.h
index 1380d1867..5136660fa 100644
--- a/Source/cmExtraEclipseCDT4Generator.h
+++ b/Source/cmExtraEclipseCDT4Generator.h
@@ -3,7 +3,7 @@
#ifndef cmExtraEclipseCDT4Generator_h
#define cmExtraEclipseCDT4Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmExternalMakefileProjectGenerator.h"
@@ -35,9 +35,9 @@ public:
static cmExternalMakefileProjectGeneratorFactory* GetFactory();
void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
- bool optional) CM_OVERRIDE;
+ bool optional) override;
- void Generate() CM_OVERRIDE;
+ void Generate() override;
private:
// create .project file in the source tree
@@ -67,7 +67,7 @@ private:
const std::string& make,
const std::string& makeArguments,
const std::string& path, const char* prefix = "",
- const char* makeTarget = CM_NULLPTR);
+ const char* makeTarget = nullptr);
static void AppendScannerProfile(
cmXMLWriter& xml, const std::string& profileID, bool openActionEnabled,
const std::string& openActionFilePath, bool pParserEnabled,
diff --git a/Source/cmExtraKateGenerator.cxx b/Source/cmExtraKateGenerator.cxx
index 373043309..877f10969 100644
--- a/Source/cmExtraKateGenerator.cxx
+++ b/Source/cmExtraKateGenerator.cxx
@@ -16,10 +16,7 @@
#include <string.h>
#include <vector>
-cmExtraKateGenerator::cmExtraKateGenerator()
- : cmExternalMakefileProjectGenerator()
-{
-}
+cmExtraKateGenerator::cmExtraKateGenerator() = default;
cmExternalMakefileProjectGeneratorFactory* cmExtraKateGenerator::GetFactory()
{
@@ -58,7 +55,7 @@ void cmExtraKateGenerator::CreateKateProjectFile(
{
std::string filename = lg->GetBinaryDirectory();
filename += "/.kateproject";
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -78,15 +75,15 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
cmGeneratedFileStream& fout) const
{
cmMakefile const* mf = lg->GetMakefile();
- const std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
- const std::string makeArgs =
+ const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& makeArgs =
mf->GetSafeDefinition("CMAKE_KATE_MAKE_ARGUMENTS");
- const char* homeOutputDir = lg->GetBinaryDirectory();
+ std::string const& homeOutputDir = lg->GetBinaryDirectory();
/* clang-format off */
fout <<
"\t\"build\": {\n"
- "\t\t\"directory\": \"" << lg->GetBinaryDirectory() << "\",\n"
+ "\t\t\"directory\": \"" << homeOutputDir << "\",\n"
"\t\t\"default_target\": \"all\",\n"
"\t\t\"clean_target\": \"clean\",\n";
/* clang-format on */
@@ -112,18 +109,16 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
// 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 std::vector<cmGeneratorTarget*> targets =
- (*it)->GetGeneratorTargets();
- std::string currentDir = (*it)->GetCurrentBinaryDirectory();
- bool topLevel = (currentDir == (*it)->GetBinaryDirectory());
-
- for (std::vector<cmGeneratorTarget*>::const_iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- std::string targetName = (*ti)->GetName();
- switch ((*ti)->GetType()) {
+ for (cmLocalGenerator* localGen :
+ this->GlobalGenerator->GetLocalGenerators()) {
+ const std::vector<cmGeneratorTarget*>& targets =
+ localGen->GetGeneratorTargets();
+ std::string currentDir = localGen->GetCurrentBinaryDirectory();
+ bool topLevel = (currentDir == localGen->GetBinaryDirectory());
+
+ for (cmGeneratorTarget* target : targets) {
+ std::string const& targetName = target->GetName();
+ switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
bool insertTarget = false;
// Only add the global targets from CMAKE_BINARY_DIR,
@@ -134,10 +129,10 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
// this will not work within the IDE
if (targetName == "edit_cache") {
const char* editCommand =
- (*it)->GetMakefile()->GetDefinition("CMAKE_EDIT_COMMAND");
- if (editCommand == CM_NULLPTR) {
+ localGen->GetMakefile()->GetDefinition("CMAKE_EDIT_COMMAND");
+ if (editCommand == nullptr) {
insertTarget = false;
- } else if (strstr(editCommand, "ccmake") != CM_NULLPTR) {
+ } else if (strstr(editCommand, "ccmake") != nullptr) {
insertTarget = false;
}
}
@@ -183,12 +178,9 @@ void cmExtraKateGenerator::WriteTargets(const cmLocalGenerator* lg,
// 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);
+ localGen->GetIndividualFileTargets(objectFileTargets);
+ for (std::string const& f : objectFileTargets) {
+ this->AppendTarget(fout, f, make, makeArgs, currentDir, homeOutputDir);
}
}
@@ -200,13 +192,14 @@ void cmExtraKateGenerator::AppendTarget(cmGeneratedFileStream& fout,
const std::string& make,
const std::string& makeArgs,
const std::string& path,
- const char* homeOutputDir) const
+ const std::string& homeOutputDir) const
{
static char JsonSep = ' ';
- fout << "\t\t\t" << JsonSep << "{\"name\":\"" << target << "\", "
- "\"build_cmd\":\""
- << make << " -C \\\"" << (this->UseNinja ? homeOutputDir : path.c_str())
+ fout << "\t\t\t" << JsonSep << R"({"name":")" << target
+ << "\", "
+ "\"build_cmd\":\""
+ << make << " -C \\\"" << (this->UseNinja ? homeOutputDir : path)
<< "\\\" " << makeArgs << " " << target << "\"}\n";
JsonSep = ',';
@@ -219,7 +212,7 @@ void cmExtraKateGenerator::CreateDummyKateProjectFile(
filename += "/";
filename += this->ProjectName;
filename += ".kateproject";
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -233,14 +226,14 @@ std::string cmExtraKateGenerator::GenerateFilesString(
{
std::string s = lg->GetSourceDirectory();
s += "/.git";
- if (cmSystemTools::FileExists(s.c_str())) {
- return std::string("\"git\": 1 ");
+ if (cmSystemTools::FileExists(s)) {
+ return "\"git\": 1 ";
}
s = lg->GetSourceDirectory();
s += "/.svn";
- if (cmSystemTools::FileExists(s.c_str())) {
- return std::string("\"svn\": 1 ");
+ if (cmSystemTools::FileExists(s)) {
+ return "\"svn\": 1 ";
}
s = lg->GetSourceDirectory();
@@ -251,23 +244,19 @@ std::string cmExtraKateGenerator::GenerateFilesString(
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();
+ for (cmLocalGenerator* lgen : lgs) {
+ cmMakefile* makefile = lgen->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;
+ for (std::string const& listFile : listFiles) {
+ tmp = listFile;
{
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")) {
+ for (cmSourceFile* sf : sources) {
+ if (sf->GetIsGenerated()) {
continue;
}
@@ -278,11 +267,10 @@ std::string cmExtraKateGenerator::GenerateFilesString(
const char* sep = "";
tmp = "\"list\": [";
- for (std::set<std::string>::const_iterator it = files.begin();
- it != files.end(); ++it) {
+ for (std::string const& f : files) {
tmp += sep;
tmp += " \"";
- tmp += *it;
+ tmp += f;
tmp += "\"";
sep = ",";
}
@@ -303,8 +291,7 @@ std::string cmExtraKateGenerator::GetPathBasename(
{
std::string outputBasename = path;
while (!outputBasename.empty() &&
- (outputBasename[outputBasename.size() - 1] == '/' ||
- outputBasename[outputBasename.size() - 1] == '\\')) {
+ (outputBasename.back() == '/' || outputBasename.back() == '\\')) {
outputBasename.resize(outputBasename.size() - 1);
}
std::string::size_type loc = outputBasename.find_last_of("/\\");
diff --git a/Source/cmExtraKateGenerator.h b/Source/cmExtraKateGenerator.h
index 6b9c7af5c..a4355f00c 100644
--- a/Source/cmExtraKateGenerator.h
+++ b/Source/cmExtraKateGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmExtraKateGenerator_h
#define cmExtraKateGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmExternalMakefileProjectGenerator.h"
@@ -22,7 +22,7 @@ public:
static cmExternalMakefileProjectGeneratorFactory* GetFactory();
- void Generate() CM_OVERRIDE;
+ void Generate() override;
private:
void CreateKateProjectFile(const cmLocalGenerator* lg) const;
@@ -31,7 +31,8 @@ private:
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;
+ const std::string& path,
+ const std::string& homeOutputDir) const;
std::string GenerateFilesString(const cmLocalGenerator* lg) const;
std::string GetPathBasename(const std::string& path) const;
diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx
index 1fd1418de..71c8fcd58 100644
--- a/Source/cmExtraSublimeTextGenerator.cxx
+++ b/Source/cmExtraSublimeTextGenerator.cxx
@@ -14,6 +14,7 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSourceFile.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
@@ -55,7 +56,6 @@ cmExtraSublimeTextGenerator::GetFactory()
}
cmExtraSublimeTextGenerator::cmExtraSublimeTextGenerator()
- : cmExternalMakefileProjectGenerator()
{
this->ExcludeBuildFolder = false;
}
@@ -68,11 +68,9 @@ void cmExtraSublimeTextGenerator::Generate()
"CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS");
// 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) {
+ for (auto const& it : this->GlobalGenerator->GetProjectMap()) {
// create a project file
- this->CreateProjectFile(it->second);
+ this->CreateProjectFile(it.second);
}
}
@@ -93,7 +91,7 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile(
{
const cmMakefile* mf = lgs[0]->GetMakefile();
- cmGeneratedFileStream fout(filename.c_str());
+ cmGeneratedFileStream fout(filename);
if (!fout) {
return;
}
@@ -144,21 +142,20 @@ void cmExtraSublimeTextGenerator::CreateNewProjectFile(
fout << "\n\t{";
fout << "\n\t\t" << systemName << ":";
fout << "\n\t\t{";
- for (std::vector<std::string>::iterator i = tokens.begin();
- i != tokens.end(); ++i) {
- size_t const pos = i->find_first_of('=');
+ for (std::string const& t : tokens) {
+ size_t const pos = t.find_first_of('=');
if (pos != std::string::npos) {
- std::string varName = i->substr(0, pos);
- std::string varValue = i->substr(pos + 1);
+ std::string varName = t.substr(0, pos);
+ std::string varValue = t.substr(pos + 1);
fout << "\n\t\t\t\"" << varName << "\":\"" << varValue << "\"";
} else {
std::ostringstream e;
e << "Could not parse Env Vars specified in "
"\"CMAKE_SUBLIME_TEXT_2_ENV_SETTINGS\""
- << ", corrupted string " << *i;
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ << ", corrupted string " << t;
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
}
fout << "\n\t\t}";
@@ -171,31 +168,28 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
const std::vector<cmLocalGenerator*>& lgs, const cmMakefile* mf,
cmGeneratedFileStream& fout, MapSourceFileFlags& sourceFileFlags)
{
- std::string make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& make = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::string compiler;
if (!lgs.empty()) {
- this->AppendTarget(fout, "all", lgs[0], CM_NULLPTR, make.c_str(), mf,
+ this->AppendTarget(fout, "all", lgs[0], nullptr, make.c_str(), mf,
compiler.c_str(), sourceFileFlags, true);
- this->AppendTarget(fout, "clean", lgs[0], CM_NULLPTR, make.c_str(), mf,
+ this->AppendTarget(fout, "clean", lgs[0], nullptr, 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();
- std::vector<cmGeneratorTarget*> targets = (*lg)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ti++) {
- std::string targetName = (*ti)->GetName();
- switch ((*ti)->GetType()) {
+ for (cmLocalGenerator* lg : lgs) {
+ cmMakefile* makefile = lg->GetMakefile();
+ const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ std::string targetName = target->GetName();
+ switch (target->GetType()) {
case cmStateEnums::GLOBAL_TARGET: {
// Only add the global targets from CMAKE_BINARY_DIR,
// not from the subdirs
- if (strcmp((*lg)->GetCurrentBinaryDirectory(),
- (*lg)->GetBinaryDirectory()) == 0) {
- this->AppendTarget(fout, targetName, *lg, CM_NULLPTR, make.c_str(),
+ if (lg->GetCurrentBinaryDirectory() == lg->GetBinaryDirectory()) {
+ this->AppendTarget(fout, targetName, lg, nullptr, make.c_str(),
makefile, compiler.c_str(), sourceFileFlags,
false);
}
@@ -212,7 +206,7 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
break;
}
- this->AppendTarget(fout, targetName, *lg, CM_NULLPTR, make.c_str(),
+ this->AppendTarget(fout, targetName, lg, nullptr, make.c_str(),
makefile, compiler.c_str(), sourceFileFlags,
false);
break;
@@ -221,12 +215,12 @@ void cmExtraSublimeTextGenerator::AppendAllTargets(
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY: {
- this->AppendTarget(fout, targetName, *lg, *ti, make.c_str(),
+ this->AppendTarget(fout, targetName, lg, target, make.c_str(),
makefile, compiler.c_str(), sourceFileFlags,
false);
std::string fastTarget = targetName;
fastTarget += "/fast";
- this->AppendTarget(fout, fastTarget, *lg, *ti, make.c_str(),
+ this->AppendTarget(fout, fastTarget, lg, target, make.c_str(),
makefile, compiler.c_str(), sourceFileFlags,
false);
} break;
@@ -244,15 +238,11 @@ void cmExtraSublimeTextGenerator::AppendTarget(
MapSourceFileFlags& sourceFileFlags, bool firstTarget)
{
- if (target != CM_NULLPTR) {
+ if (target != nullptr) {
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;
+ for (cmSourceFile* sourceFile : sourceFiles) {
MapSourceFileFlags::iterator sourceFileFlagsIter =
sourceFileFlags.find(sourceFile->GetFullPath());
if (sourceFileFlagsIter == sourceFileFlags.end()) {
@@ -263,16 +253,20 @@ void cmExtraSublimeTextGenerator::AppendTarget(
.first;
}
std::vector<std::string>& flags = sourceFileFlagsIter->second;
- std::string flagsString = this->ComputeFlagsForObject(*iter, lg, target);
- std::string definesString = this->ComputeDefines(*iter, lg, target);
+ std::string flagsString =
+ this->ComputeFlagsForObject(sourceFile, lg, target);
+ std::string definesString = this->ComputeDefines(sourceFile, lg, target);
+ std::string includesString =
+ this->ComputeIncludes(sourceFile, lg, target);
flags.clear();
cmsys::RegularExpression flagRegex;
// Regular expression to extract compiler flags from a string
// https://gist.github.com/3944250
const char* regexString =
- "(^|[ ])-[DIOUWfgs][^= ]+(=\\\"[^\"]+\\\"|=[^\"][^ ]+)?";
+ R"((^|[ ])-[DIOUWfgs][^= ]+(=\"[^"]+\"|=[^"][^ ]+)?)";
flagRegex.compile(regexString);
- std::string workString = flagsString + " " + definesString;
+ std::string workString =
+ flagsString + " " + definesString + " " + includesString;
while (flagRegex.find(workString)) {
std::string::size_type start = flagRegex.start();
if (workString[start] == ' ') {
@@ -282,7 +276,7 @@ void cmExtraSublimeTextGenerator::AppendTarget(
if (flagRegex.end() < workString.size()) {
workString = workString.substr(flagRegex.end());
} else {
- workString = "";
+ workString.clear();
}
}
}
@@ -321,12 +315,12 @@ std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
std::string generator = this->GlobalGenerator->GetName();
if (generator == "NMake Makefiles") {
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
- command += ", \"/NOLOGO\", \"/f\", \"";
+ command += R"(, "/NOLOGO", "/f", ")";
command += makefileName + "\"";
command += ", \"" + target + "\"";
} else if (generator == "Ninja") {
std::string makefileName = cmSystemTools::ConvertToOutputPath(makefile);
- command += ", \"-f\", \"";
+ command += R"(, "-f", ")";
command += makefileName + "\"";
command += ", \"" + target + "\"";
} else {
@@ -338,7 +332,7 @@ std::string cmExtraSublimeTextGenerator::BuildMakeCommand(
} else {
makefileName = cmSystemTools::ConvertToOutputPath(makefile);
}
- command += ", \"-f\", \"";
+ command += R"(, "-f", ")";
command += makefileName + "\"";
command += ", \"" + target + "\"";
}
@@ -359,20 +353,19 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject(
lg->GetTargetCompileFlags(gtgt, config, language, flags);
- // 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);
+ // Add source file specific flags.
+ cmGeneratorExpressionInterpreter genexInterpreter(lg, config, gtgt,
+ language);
+
+ const std::string COMPILE_FLAGS("COMPILE_FLAGS");
+ if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
+ lg->AppendFlags(flags, genexInterpreter.Evaluate(cflags, COMPILE_FLAGS));
}
- // Add source file specific flags.
- if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) {
- cmGeneratorExpression ge;
- const char* processed = ge.Parse(cflags)->Evaluate(lg, config);
- lg->AppendFlags(flags, processed);
+ const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
+ if (const char* coptions = source->GetProperty(COMPILE_OPTIONS)) {
+ lg->AppendCompileOptions(
+ flags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
}
return flags;
@@ -388,19 +381,23 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines(
cmMakefile* makefile = lg->GetMakefile();
const std::string& language = source->GetLanguage();
const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
+ language);
- // 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->GetTargetDefines(target, config, language, defines);
+ const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
+ if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
+ lg->AppendDefines(
+ defines, genexInterpreter.Evaluate(compile_defs, COMPILE_DEFINITIONS));
}
- // Add preprocessor definitions for this target and configuration.
- lg->AddCompileDefinitions(defines, target, config, language);
- lg->AppendDefines(defines, source->GetProperty("COMPILE_DEFINITIONS"));
- {
- std::string defPropName = "COMPILE_DEFINITIONS_";
- defPropName += cmSystemTools::UpperCase(config);
- lg->AppendDefines(defines, source->GetProperty(defPropName));
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(config);
+ if (const char* config_compile_defs = source->GetProperty(defPropName)) {
+ lg->AppendDefines(
+ defines,
+ genexInterpreter.Evaluate(config_compile_defs, COMPILE_DEFINITIONS));
}
std::string definesString;
@@ -408,3 +405,54 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines(
return definesString;
}
+
+std::string cmExtraSublimeTextGenerator::ComputeIncludes(
+ cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* target)
+
+{
+ std::vector<std::string> includes;
+ cmMakefile* makefile = lg->GetMakefile();
+ const std::string& language = source->GetLanguage();
+ const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target,
+ language);
+
+ // Add include directories for this source file
+ const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
+ if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
+ lg->AppendIncludeDirectories(
+ includes, genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES),
+ *source);
+ }
+
+ // Add include directory flags.
+ lg->GetIncludeDirectories(includes, target, language, config);
+
+ std::string includesString =
+ lg->GetIncludeFlags(includes, target, language, true, false, config);
+
+ return includesString;
+}
+
+bool cmExtraSublimeTextGenerator::Open(const std::string& bindir,
+ const std::string& projectName,
+ bool dryRun)
+{
+ const char* sublExecutable =
+ this->GlobalGenerator->GetCMakeInstance()->GetCacheDefinition(
+ "CMAKE_SUBLIMETEXT_EXECUTABLE");
+ if (!sublExecutable) {
+ return false;
+ }
+ if (cmSystemTools::IsNOTFOUND(sublExecutable)) {
+ return false;
+ }
+
+ std::string filename = bindir + "/" + projectName + ".sublime-project";
+ if (dryRun) {
+ return cmSystemTools::FileExists(filename, true);
+ }
+
+ return cmSystemTools::RunSingleCommand(
+ { sublExecutable, "--project", filename });
+}
diff --git a/Source/cmExtraSublimeTextGenerator.h b/Source/cmExtraSublimeTextGenerator.h
index 9022d3754..bc158f6b4 100644
--- a/Source/cmExtraSublimeTextGenerator.h
+++ b/Source/cmExtraSublimeTextGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmExtraSublimeTextGenerator_h
#define cmExtraSublimeTextGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmExternalMakefileProjectGenerator.h"
@@ -24,10 +24,10 @@ class cmExtraSublimeTextGenerator : public cmExternalMakefileProjectGenerator
{
public:
static cmExternalMakefileProjectGeneratorFactory* GetFactory();
- typedef std::map<std::string, std::vector<std::string> > MapSourceFileFlags;
+ typedef std::map<std::string, std::vector<std::string>> MapSourceFileFlags;
cmExtraSublimeTextGenerator();
- void Generate() CM_OVERRIDE;
+ void Generate() override;
private:
void CreateProjectFile(const std::vector<cmLocalGenerator*>& lgs);
@@ -65,6 +65,12 @@ private:
std::string ComputeDefines(cmSourceFile* source, cmLocalGenerator* lg,
cmGeneratorTarget* gtgt);
+ std::string ComputeIncludes(cmSourceFile* source, cmLocalGenerator* lg,
+ cmGeneratorTarget* gtgt);
+
+ bool Open(const std::string& bindir, const std::string& projectName,
+ bool dryRun) override;
+
bool ExcludeBuildFolder;
std::string EnvSettings;
};
diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx
index ff78f52e3..89629c768 100644
--- a/Source/cmFLTKWrapUICommand.cxx
+++ b/Source/cmFLTKWrapUICommand.cxx
@@ -6,6 +6,7 @@
#include "cmCustomCommandLines.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmSystemTools.h"
@@ -23,7 +24,7 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args,
// what is the current source dir
std::string cdir = this->Makefile->GetCurrentSourceDirectory();
- const char* fluid_exe =
+ std::string const& fluid_exe =
this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
// get parameter for the command
@@ -40,18 +41,17 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args,
this->Makefile->AddIncludeDirectories(outputDirectories);
}
- for (std::vector<std::string>::const_iterator i = (args.begin() + 1);
- i != args.end(); i++) {
- cmSourceFile* curr = this->Makefile->GetSource(*i);
+ for (std::string const& arg : cmMakeRange(args).advance(1)) {
+ cmSourceFile* curr = this->Makefile->GetSource(arg);
// 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);
+ outName += cmSystemTools::GetFilenameWithoutExtension(arg);
std::string hname = outName;
hname += ".h";
- std::string origname = cdir + "/" + *i;
+ std::string origname = cdir + "/" + arg;
// add starting depends
std::vector<std::string> depends;
depends.push_back(origname);
@@ -72,8 +72,8 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args,
// Add command for generating the .h and .cxx files
std::string no_main_dependency;
- const char* no_comment = CM_NULLPTR;
- const char* no_working_dir = CM_NULLPTR;
+ const char* no_comment = nullptr;
+ const char* no_working_dir = nullptr;
this->Makefile->AddCustomCommandToOutput(
cxxres, depends, no_main_dependency, commandLines, no_comment,
no_working_dir);
@@ -117,7 +117,7 @@ void cmFLTKWrapUICommand::FinalPass()
msg += ". The problem was found while processing the source directory: ";
msg += this->Makefile->GetCurrentSourceDirectory();
msg += ". This FLTK_WRAP_UI call will be ignored.";
- cmSystemTools::Message(msg.c_str(), "Warning");
+ cmSystemTools::Message(msg, "Warning");
return;
}
}
diff --git a/Source/cmFLTKWrapUICommand.h b/Source/cmFLTKWrapUICommand.h
index d8045ab6a..044755e5b 100644
--- a/Source/cmFLTKWrapUICommand.h
+++ b/Source/cmFLTKWrapUICommand.h
@@ -3,7 +3,7 @@
#ifndef cmFLTKWrapUICommand_h
#define cmFLTKWrapUICommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFLTKWrapUICommand; }
+ cmCommand* Clone() override { return new cmFLTKWrapUICommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* This is called at the end after all the information
@@ -40,8 +40,8 @@ public:
* not implement this method. At this point, reading and
* writing to the cache can be done.
*/
- void FinalPass() CM_OVERRIDE;
- bool HasFinalPass() const CM_OVERRIDE { return true; }
+ void FinalPass() override;
+ bool HasFinalPass() const override { return true; }
private:
/**
diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx
index 5777fb204..7a3954e4d 100644
--- a/Source/cmFileCommand.cxx
+++ b/Source/cmFileCommand.cxx
@@ -3,78 +3,54 @@
#include "cmFileCommand.h"
#include "cm_kwiml.h"
-#include "cmsys/Directory.hxx"
+#include "cm_static_string_view.hxx"
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
-#include "cmsys/String.hxx"
+
#include <algorithm>
#include <assert.h>
+#include <cmath>
+#include <ctype.h>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
+#include <utility>
#include <vector>
#include "cmAlgorithms.h"
-#include "cmCommandArgumentsHelper.h"
+#include "cmArgumentParser.h"
#include "cmCryptoHash.h"
+#include "cmFileCopier.h"
+#include "cmFileInstaller.h"
#include "cmFileLockPool.h"
-#include "cmFileTimeComparison.h"
+#include "cmFileTimes.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmHexFileConverter.h"
-#include "cmInstallType.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
#include "cmTimestamp.h"
-#include "cm_auto_ptr.hxx"
#include "cm_sys_stat.h"
#include "cmake.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmCurl.h"
-#include "cmFileLockResult.h"
-#include "cm_curl.h"
+# include "cmCurl.h"
+# include "cmFileLockResult.h"
+# include "cm_curl.h"
#endif
#if defined(CMAKE_USE_ELF_PARSER)
-#include "cmELF.h"
+# include "cmELF.h"
#endif
#if defined(_WIN32)
-#include <windows.h>
-#endif
-
-class cmSystemToolsFileTime;
-
-// 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;
+# include <windows.h>
#endif
#if defined(_WIN32)
@@ -184,6 +160,12 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args,
if (subCommand == "TO_NATIVE_PATH") {
return this->HandleCMakePathCommand(args, true);
}
+ if (subCommand == "TOUCH") {
+ return this->HandleTouchCommand(args, true);
+ }
+ if (subCommand == "TOUCH_NOCREATE") {
+ return this->HandleTouchCommand(args, false);
+ }
if (subCommand == "TIMESTAMP") {
return this->HandleTimestampCommand(args);
}
@@ -193,6 +175,15 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args,
if (subCommand == "LOCK") {
return this->HandleLockCommand(args);
}
+ if (subCommand == "SIZE") {
+ return this->HandleSizeCommand(args);
+ }
+ if (subCommand == "READ_SYMLINK") {
+ return this->HandleReadSymlinkCommand(args);
+ }
+ if (subCommand == "CREATE_LINK") {
+ return this->HandleCreateLinkCommand(args);
+ }
std::string e = "does not recognize sub-command " + subCommand;
this->SetError(e);
@@ -207,14 +198,14 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
i++; // Get rid of subcommand
std::string fileName = *i;
- if (!cmsys::SystemTools::FileIsFullPath(i->c_str())) {
+ if (!cmsys::SystemTools::FileIsFullPath(*i)) {
fileName = this->Makefile->GetCurrentSourceDirectory();
fileName += "/" + *i;
}
i++;
- if (!this->Makefile->CanIWriteThisFile(fileName.c_str())) {
+ if (!this->Makefile->CanIWriteThisFile(fileName)) {
std::string e =
"attempted to write a file: " + fileName + " into a source directory.";
this->SetError(e);
@@ -222,19 +213,23 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
return false;
}
std::string dir = cmSystemTools::GetFilenamePath(fileName);
- cmSystemTools::MakeDirectory(dir.c_str());
+ cmSystemTools::MakeDirectory(dir);
mode_t mode = 0;
+ bool writable = false;
// Set permissions to writable
- if (cmSystemTools::GetPermissions(fileName.c_str(), mode)) {
- cmSystemTools::SetPermissions(fileName.c_str(),
+ if (cmSystemTools::GetPermissions(fileName, mode)) {
#if defined(_MSC_VER) || defined(__MINGW32__)
- mode | S_IWRITE
+ writable = (mode & S_IWRITE) != 0;
+ mode_t newMode = mode | S_IWRITE;
#else
- mode | S_IWUSR | S_IWGRP
+ writable = mode & S_IWUSR;
+ mode_t newMode = mode | S_IWUSR | S_IWGRP;
#endif
- );
+ if (!writable) {
+ cmSystemTools::SetPermissions(fileName, newMode);
+ }
}
// If GetPermissions fails, pretend like it is ok. File open will fail if
// the file is not writable
@@ -250,9 +245,17 @@ bool cmFileCommand::HandleWriteCommand(std::vector<std::string> const& args,
}
std::string message = cmJoin(cmMakeRange(i, args.end()), std::string());
file << message;
+ if (!file) {
+ std::string error = "write failed (";
+ error += cmSystemTools::GetLastSystemError();
+ error += "):\n ";
+ error += fileName;
+ this->SetError(error);
+ return false;
+ }
file.close();
- if (mode) {
- cmSystemTools::SetPermissions(fileName.c_str(), mode);
+ if (mode && !writable) {
+ cmSystemTools::SetPermissions(fileName, mode);
}
return true;
}
@@ -265,35 +268,34 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
return false;
}
- cmCommandArgumentsHelper argHelper;
- cmCommandArgumentGroup group;
+ std::string const& fileNameArg = args[1];
+ std::string const& variable = args[2];
- cmCAString readArg(&argHelper, "READ");
- cmCAString fileNameArg(&argHelper, CM_NULLPTR);
- cmCAString resultArg(&argHelper, CM_NULLPTR);
+ struct Arguments
+ {
+ std::string Offset;
+ std::string Limit;
+ bool Hex = false;
+ };
+
+ static auto const parser = cmArgumentParser<Arguments>{}
+ .Bind("OFFSET"_s, &Arguments::Offset)
+ .Bind("LIMIT"_s, &Arguments::Limit)
+ .Bind("HEX"_s, &Arguments::Hex);
- cmCAString offsetArg(&argHelper, "OFFSET", &group);
- cmCAString limitArg(&argHelper, "LIMIT", &group);
- cmCAEnabler hexOutputArg(&argHelper, "HEX", &group);
- readArg.Follows(CM_NULLPTR);
- fileNameArg.Follows(&readArg);
- resultArg.Follows(&fileNameArg);
- group.Follows(&resultArg);
- argHelper.Parse(&args, CM_NULLPTR);
+ Arguments const arguments = parser.Parse(cmMakeRange(args).advance(3));
- std::string fileName = fileNameArg.GetString();
- if (!cmsys::SystemTools::FileIsFullPath(fileName.c_str())) {
+ std::string fileName = fileNameArg;
+ if (!cmsys::SystemTools::FileIsFullPath(fileName)) {
fileName = this->Makefile->GetCurrentSourceDirectory();
- fileName += "/" + fileNameArg.GetString();
+ fileName += "/" + fileNameArg;
}
- 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));
+ cmsys::ifstream file(fileName.c_str(),
+ arguments.Hex ? (std::ios::binary | std::ios::in)
+ : std::ios::in);
#else
cmsys::ifstream file(fileName.c_str());
#endif
@@ -309,21 +311,21 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
// is there a limit?
long sizeLimit = -1;
- if (!limitArg.GetString().empty()) {
- sizeLimit = atoi(limitArg.GetCString());
+ if (!arguments.Limit.empty()) {
+ sizeLimit = atoi(arguments.Limit.c_str());
}
// is there an offset?
long offset = 0;
- if (!offsetArg.GetString().empty()) {
- offset = atoi(offsetArg.GetCString());
+ if (!arguments.Offset.empty()) {
+ offset = atoi(arguments.Offset.c_str());
}
file.seekg(offset, std::ios::beg); // explicit ios::beg for IBM VisualAge 6
std::string output;
- if (hexOutputArg.IsEnabled()) {
+ if (arguments.Hex) {
// Convert part of the file into hex code
char c;
while ((sizeLimit != 0) && (file.get(c))) {
@@ -337,8 +339,9 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args)
} else {
std::string line;
bool has_newline = false;
- while (sizeLimit != 0 && cmSystemTools::GetLineFromStream(
- file, line, &has_newline, sizeLimit)) {
+ while (
+ sizeLimit != 0 &&
+ cmSystemTools::GetLineFromStream(file, line, &has_newline, sizeLimit)) {
if (sizeLimit > 0) {
sizeLimit = sizeLimit - static_cast<long>(line.size());
if (has_newline) {
@@ -368,8 +371,8 @@ bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args)
return false;
}
- CM_AUTO_PTR<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str()));
- if (hash.get()) {
+ std::unique_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str()));
+ if (hash) {
std::string out = hash->HashFile(args[1]);
if (!out.empty()) {
this->Makefile->AddDefinition(args[2], out.c_str());
@@ -384,7 +387,7 @@ bool cmFileCommand::HandleHashCommand(std::vector<std::string> const& args)
#else
std::ostringstream e;
e << args[0] << " not available during bootstrap";
- this->SetError(e.str().c_str());
+ this->SetError(e.str());
return false;
#endif
}
@@ -398,7 +401,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
// Get the file to read.
std::string fileName = args[1];
- if (!cmsys::SystemTools::FileIsFullPath(fileName.c_str())) {
+ if (!cmsys::SystemTools::FileIsFullPath(fileName)) {
fileName = this->Makefile->GetCurrentSourceDirectory();
fileName += "/" + args[1];
}
@@ -514,7 +517,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
maxlen = len;
arg_mode = arg_none;
} else if (arg_mode == arg_regex) {
- if (!regex.compile(args[i].c_str())) {
+ if (!regex.compile(args[i])) {
std::ostringstream e;
e << "STRINGS option REGEX value \"" << args[i]
<< "\" could not be compiled.";
@@ -552,10 +555,9 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
if (hex_conversion_enabled) {
// TODO: should work without temp file, but just on a memory buffer
std::string binaryFileName = this->Makefile->GetCurrentBinaryDirectory();
- binaryFileName += cmake::GetCMakeFilesDirectory();
+ binaryFileName += "/CMakeFiles";
binaryFileName += "/FileCommandStringsBinaryFile";
- if (cmHexFileConverter::TryConvert(fileName.c_str(),
- binaryFileName.c_str())) {
+ if (cmHexFileConverter::TryConvert(fileName, binaryFileName)) {
fileName = binaryFileName;
}
}
@@ -617,8 +619,8 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
continue;
}
- if ((c >= 0x20 && c < 0x7F) || c == '\t' ||
- (c == '\n' && newline_consume)) {
+ if (c >= 0 && c <= 0xFF &&
+ (isprint(c) || 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...
@@ -626,7 +628,9 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
} else if (encoding == encoding_utf8) {
// 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 },
+ { 0xE0, 0xC0 },
+ { 0xF0, 0xE0 },
+ { 0xF8, 0xF0 },
};
// how many octets are there?
@@ -656,7 +660,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
c = current_str[current_str.size() - 1 - j];
fin.putback(static_cast<char>(c));
}
- current_str = "";
+ current_str.clear();
}
}
@@ -664,48 +668,48 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
// 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()))) {
+ if (s.length() >= minlen && (!have_regex || regex.find(s))) {
output_size += static_cast<int>(s.size()) + 1;
if (limit_output >= 0 && output_size >= limit_output) {
- s = "";
+ s.clear();
break;
}
strings.push_back(s);
}
// Reset the string to empty.
- s = "";
+ s.clear();
} 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.empty() &&
- (!have_regex || regex.find(s.c_str()))) {
+ (!have_regex || regex.find(s))) {
output_size += static_cast<int>(s.size()) + 1;
if (limit_output >= 0 && output_size >= limit_output) {
- s = "";
+ s.clear();
break;
}
strings.push_back(s);
}
// Reset the string to empty.
- s = "";
+ s.clear();
} 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()))) {
+ if (s.length() >= minlen && (!have_regex || regex.find(s))) {
output_size += static_cast<int>(s.size()) + 1;
if (limit_output >= 0 && output_size >= limit_output) {
- s = "";
+ s.clear();
break;
}
strings.push_back(s);
}
- s = "";
+ s.clear();
}
}
@@ -713,7 +717,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
// 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()))) {
+ s.length() >= minlen && (!have_regex || regex.find(s))) {
output_size += static_cast<int>(s.size()) + 1;
if (limit_output < 0 || output_size < limit_output) {
strings.push_back(s);
@@ -723,20 +727,18 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args)
// 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) {
+ for (std::string const& sr : strings) {
// 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] == ';') {
+ for (char i : sr) {
+ if (i == ';') {
output += '\\';
}
- output += sr[i];
+ output += i;
}
}
@@ -777,124 +779,158 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args,
}
}
- std::string output;
- bool first = true;
- for (; i != args.end(); ++i) {
+ std::vector<std::string> files;
+ bool configureDepends = false;
+ bool warnConfigureLate = false;
+ bool warnFollowedSymlinks = false;
+ const cmake::WorkingMode workingMode =
+ this->Makefile->GetCMakeInstance()->GetWorkingMode();
+ while (i != args.end()) {
if (*i == "LIST_DIRECTORIES") {
- ++i;
+ ++i; // skip LIST_DIRECTORIES
if (i != args.end()) {
- if (cmSystemTools::IsOn(i->c_str())) {
+ if (cmSystemTools::IsOn(*i)) {
g.SetListDirs(true);
g.SetRecurseListDirs(true);
- } else if (cmSystemTools::IsOff(i->c_str())) {
+ } else if (cmSystemTools::IsOff(*i)) {
g.SetListDirs(false);
g.SetRecurseListDirs(false);
} else {
this->SetError("LIST_DIRECTORIES missing bool value.");
return false;
}
+ ++i;
} else {
this->SetError("LIST_DIRECTORIES missing bool value.");
return false;
}
- continue;
- }
-
- 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;
+ } else if (*i == "FOLLOW_SYMLINKS") {
+ ++i; // skip FOLLOW_SYMLINKS
+ if (recurse) {
+ explicitFollowSymlinks = true;
+ g.RecurseThroughSymlinksOn();
+ if (i == args.end()) {
+ this->SetError(
+ "GLOB_RECURSE requires a glob expression after FOLLOW_SYMLINKS.");
+ return false;
+ }
}
- }
-
- if (*i == "RELATIVE") {
+ } else if (*i == "RELATIVE") {
++i; // skip RELATIVE
if (i == args.end()) {
- this->SetError("GLOB requires a directory after the RELATIVE tag");
+ 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");
+ this->SetError("GLOB requires a glob expression after the directory.");
return false;
}
- }
-
- cmsys::Glob::GlobMessages globMessages;
- if (!cmsys::SystemTools::FileIsFullPath(i->c_str())) {
- std::string expr = this->Makefile->GetCurrentSourceDirectory();
- // Handle script mode
- if (!expr.empty()) {
- expr += "/" + *i;
- g.FindFiles(expr, &globMessages);
- } else {
- g.FindFiles(*i, &globMessages);
+ } else if (*i == "CONFIGURE_DEPENDS") {
+ // Generated build system depends on glob results
+ if (!configureDepends && warnConfigureLate) {
+ this->Makefile->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ "CONFIGURE_DEPENDS flag was given after a glob expression was "
+ "already evaluated.");
+ }
+ if (workingMode != cmake::NORMAL_MODE) {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "CONFIGURE_DEPENDS is invalid for script and find package modes.");
+ return false;
+ }
+ configureDepends = true;
+ ++i;
+ if (i == args.end()) {
+ this->SetError(
+ "GLOB requires a glob expression after CONFIGURE_DEPENDS.");
+ return false;
}
} else {
- g.FindFiles(*i, &globMessages);
- }
-
- if (!globMessages.empty()) {
- bool shouldExit = false;
- for (cmsys::Glob::GlobMessagesIterator it = globMessages.begin();
- it != globMessages.end(); ++it) {
- if (it->type == cmsys::Glob::cyclicRecursion) {
- this->Makefile->IssueMessage(
- cmake::AUTHOR_WARNING,
- "Cyclic recursion detected while globbing for '" + *i + "':\n" +
- it->content);
+ std::string expr = *i;
+ if (!cmsys::SystemTools::FileIsFullPath(*i)) {
+ expr = this->Makefile->GetCurrentSourceDirectory();
+ // Handle script mode
+ if (!expr.empty()) {
+ expr += "/" + *i;
} else {
- this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, "Error has occurred while globbing for '" +
- *i + "' - " + it->content);
- shouldExit = true;
+ expr = *i;
}
}
- if (shouldExit) {
- return false;
+
+ cmsys::Glob::GlobMessages globMessages;
+ g.FindFiles(expr, &globMessages);
+
+ if (!globMessages.empty()) {
+ bool shouldExit = false;
+ for (cmsys::Glob::Message const& globMessage : globMessages) {
+ if (globMessage.type == cmsys::Glob::cyclicRecursion) {
+ this->Makefile->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ "Cyclic recursion detected while globbing for '" + *i + "':\n" +
+ globMessage.content);
+ } else {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "Error has occurred while globbing for '" + *i + "' - " +
+ globMessage.content);
+ shouldExit = true;
+ }
+ }
+ if (shouldExit) {
+ return false;
+ }
+ }
+
+ if (recurse && !explicitFollowSymlinks &&
+ g.GetFollowedSymlinkCount() != 0) {
+ warnFollowedSymlinks = true;
}
- }
- std::vector<std::string>::size_type cc;
- std::vector<std::string>& files = g.GetFiles();
- std::sort(files.begin(), files.end());
- for (cc = 0; cc < files.size(); cc++) {
- if (!first) {
- output += ";";
+ std::vector<std::string>& foundFiles = g.GetFiles();
+ cmAppend(files, foundFiles);
+
+ if (configureDepends) {
+ std::sort(foundFiles.begin(), foundFiles.end());
+ foundFiles.erase(std::unique(foundFiles.begin(), foundFiles.end()),
+ foundFiles.end());
+ this->Makefile->GetCMakeInstance()->AddGlobCacheEntry(
+ recurse, (recurse ? g.GetRecurseListDirs() : g.GetListDirs()),
+ (recurse ? g.GetRecurseThroughSymlinks() : false),
+ (g.GetRelative() ? g.GetRelative() : ""), expr, foundFiles, variable,
+ this->Makefile->GetBacktrace());
+ } else {
+ warnConfigureLate = true;
}
- output += files[cc];
- first = false;
+ ++i;
}
}
- if (recurse && !explicitFollowSymlinks) {
- switch (status) {
- case cmPolicies::REQUIRED_IF_USED:
- case cmPolicies::REQUIRED_ALWAYS:
- 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,
- cmPolicies::GetPolicyWarning(cmPolicies::CMP0009));
- }
- break;
- }
+ switch (status) {
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ 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 (warnFollowedSymlinks) {
+ this->Makefile->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0009));
+ }
+ break;
}
- this->Makefile->AddDefinition(variable, output.c_str());
+ std::sort(files.begin(), files.end());
+ files.erase(std::unique(files.begin(), files.end()), files.end());
+ this->Makefile->AddDefinition(variable, cmJoin(files, ";").c_str());
return true;
}
@@ -904,26 +940,24 @@ bool cmFileCommand::HandleMakeDirectoryCommand(
// 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())) {
+ for (std::string const& arg :
+ cmMakeRange(args).advance(1)) // Get rid of subcommand
+ {
+ const std::string* cdir = &arg;
+ if (!cmsys::SystemTools::FileIsFullPath(arg)) {
expr = this->Makefile->GetCurrentSourceDirectory();
- expr += "/" + *i;
+ expr += "/" + arg;
cdir = &expr;
}
- if (!this->Makefile->CanIWriteThisFile(cdir->c_str())) {
+ if (!this->Makefile->CanIWriteThisFile(*cdir)) {
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())) {
+ if (!cmSystemTools::MakeDirectory(*cdir)) {
std::string error = "problem creating directory: " + *cdir;
this->SetError(error);
return false;
@@ -932,6 +966,36 @@ bool cmFileCommand::HandleMakeDirectoryCommand(
return true;
}
+bool cmFileCommand::HandleTouchCommand(std::vector<std::string> const& args,
+ bool create)
+{
+ // File command has at least one argument
+ assert(args.size() > 1);
+
+ for (std::string const& arg :
+ cmMakeRange(args).advance(1)) // Get rid of subcommand
+ {
+ std::string tfile = arg;
+ if (!cmsys::SystemTools::FileIsFullPath(tfile)) {
+ tfile = this->Makefile->GetCurrentSourceDirectory();
+ tfile += "/" + arg;
+ }
+ if (!this->Makefile->CanIWriteThisFile(tfile)) {
+ std::string e =
+ "attempted to touch a file: " + tfile + " in a source directory.";
+ this->SetError(e);
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+ if (!cmSystemTools::Touch(tfile, create)) {
+ std::string error = "problem touching file: " + tfile;
+ this->SetError(error);
+ return false;
+ }
+ }
+ return true;
+}
+
bool cmFileCommand::HandleDifferentCommand(
std::vector<std::string> const& args)
{
@@ -940,9 +1004,9 @@ bool cmFileCommand::HandleDifferentCommand(
*/
// Evaluate arguments.
- const char* file_lhs = CM_NULLPTR;
- const char* file_rhs = CM_NULLPTR;
- const char* var = CM_NULLPTR;
+ const char* file_lhs = nullptr;
+ const char* file_rhs = nullptr;
+ const char* var = nullptr;
enum Doing
{
DoingNone,
@@ -986,1051 +1050,19 @@ bool cmFileCommand::HandleDifferentCommand(
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(CM_NULLPTR)
- , 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
- {
- 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)) {
- std::ostringstream 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 {
- std::ostringstream 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 match_properties);
- bool InstallDirectory(const char* source, const char* destination,
- MatchProperties 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.
- std::ostringstream 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::string FilesFromDir;
- std::vector<std::string> Files;
- int Doing;
-
- virtual bool Parse(std::vector<std::string> const& args);
- enum
- {
- DoingNone,
- DoingError,
- DoingDestination,
- DoingFilesFromDir,
- 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)
- {
- std::ostringstream 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)
- {
- std::ostringstream 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])) {
- std::ostringstream 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()) {
- std::ostringstream 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 == "FILES_FROM_DIR") {
- if (this->CurrentMatchRule) {
- this->NotAfterMatch(arg);
- } else {
- this->Doing = DoingFilesFromDir;
- }
- } 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:
- this->Files.push_back(arg);
- break;
- case DoingDestination:
- if (arg.empty() || cmSystemTools::FileIsFullPath(arg.c_str())) {
- this->Destination = arg;
- } else {
- this->Destination = this->Makefile->GetCurrentBinaryDirectory();
- this->Destination += "/" + arg;
- }
- this->Doing = DoingNone;
- break;
- case DoingFilesFromDir:
- if (cmSystemTools::FileIsFullPath(arg.c_str())) {
- this->FilesFromDir = arg;
- } else {
- this->FilesFromDir = this->Makefile->GetCurrentSourceDirectory();
- this->FilesFromDir += "/" + arg;
- }
- cmSystemTools::ConvertToUnixSlashes(this->FilesFromDir);
- 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 {
- std::ostringstream 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 {
- std::ostringstream 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;
- }
-
- for (std::vector<std::string>::const_iterator i = this->Files.begin();
- i != this->Files.end(); ++i) {
- std::string file;
- if (!i->empty() && !cmSystemTools::FileIsFullPath(*i)) {
- if (!this->FilesFromDir.empty()) {
- file = this->FilesFromDir;
- } else {
- file = this->Makefile->GetCurrentSourceDirectory();
- }
- file += "/";
- file += *i;
- } else if (!this->FilesFromDir.empty()) {
- this->FileCommand->SetError("option FILES_FROM_DIR requires all files "
- "to be specified as relative paths.");
- return false;
- } else {
- file = *i;
- }
-
- // Split the input file into its directory and name components.
- std::vector<std::string> fromPathComponents;
- cmSystemTools::SplitPath(file, 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;
- if (!this->FilesFromDir.empty()) {
- std::string dir = cmSystemTools::GetFilenamePath(*i);
- if (!dir.empty()) {
- toFile += "/";
- toFile += dir;
- }
- }
- 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) {
- std::ostringstream 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;
- }
- if (cmSystemTools::FileIsSymlink(fromFile)) {
- return this->InstallSymlink(fromFile, toFile);
- }
- if (cmSystemTools::FileIsDirectory(fromFile)) {
- return this->InstallDirectory(fromFile, toFile, match_properties);
- }
- 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)) {
- std::ostringstream 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 destination directory if it doesn't exist
- cmSystemTools::MakeDirectory(cmSystemTools::GetFilenamePath(toFile));
-
- // Create the symlink.
- if (!cmSystemTools::CreateSymlink(symlinkTarget, toFile)) {
- std::ostringstream 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 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)) {
- std::ostringstream 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)) {
- std::ostringstream 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 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)) {
- std::ostringstream 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)) {
- std::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.
- std::string install_always;
- if (cmSystemTools::GetEnv("CMAKE_INSTALL_ALWAYS", install_always)) {
- this->Always = cmSystemTools::IsOn(install_always.c_str());
- }
- // Get the current manifest.
- this->Manifest =
- this->Makefile->GetSafeDefinition("CMAKE_INSTALL_MANIFEST_FILES");
- }
- ~cmFileInstaller() CM_OVERRIDE
- {
- // 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)
- {
- if (!this->Manifest.empty()) {
- this->Manifest += ";";
- }
- this->Manifest += file.substr(this->DestDirLength);
- }
-
- std::string const& ToName(std::string const& fromName) CM_OVERRIDE
- {
- return this->Rename.empty() ? fromName : this->Rename;
- }
-
- void ReportCopy(const char* toFile, Type type, bool copy) CM_OVERRIDE
- {
- 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);
- }
- }
- bool ReportMissing(const char* fromFile) CM_OVERRIDE
- {
- return (this->Optional || this->cmFileCopier::ReportMissing(fromFile));
- }
- bool Install(const char* fromFile, const char* toFile) CM_OVERRIDE
- {
- // 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);
- }
-
- bool Parse(std::vector<std::string> const& args) CM_OVERRIDE;
- enum
- {
- DoingType = DoingLast1,
- DoingRename,
- DoingLast2
- };
- bool CheckKeyword(std::string const& arg) CM_OVERRIDE;
- bool CheckValue(std::string const& arg) CM_OVERRIDE;
- void DefaultFilePermissions() CM_OVERRIDE
- {
- 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;
- }
- CM_FALLTHROUGH;
- 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->FilesFromDir.empty()) {
- this->FileCommand->SetError("INSTALL option RENAME may not be "
- "combined with FILES_FROM_DIR.");
- return false;
- }
- 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") {
- std::ostringstream 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 {
- std::ostringstream 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;
- }
-
- std::string sdestdir;
- if (cmSystemTools::GetEnv("DESTDIR", sdestdir) && !sdestdir.empty()) {
- 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)) {
- 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 = CM_NULLPTR;
- const char* oldRPath = CM_NULLPTR;
- const char* newRPath = CM_NULLPTR;
+ std::string file;
+ const char* oldRPath = nullptr;
+ const char* newRPath = nullptr;
enum Doing
{
DoingNone,
@@ -2047,7 +1079,7 @@ bool cmFileCommand::HandleRPathChangeCommand(
} else if (args[i] == "FILE") {
doing = DoingFile;
} else if (doing == DoingFile) {
- file = args[i].c_str();
+ file = args[i];
doing = DoingNone;
} else if (doing == DoingOld) {
oldRPath = args[i].c_str();
@@ -2062,7 +1094,7 @@ bool cmFileCommand::HandleRPathChangeCommand(
return false;
}
}
- if (!file) {
+ if (file.empty()) {
this->SetError("RPATH_CHANGE not given FILE option.");
return false;
}
@@ -2081,8 +1113,7 @@ bool cmFileCommand::HandleRPathChangeCommand(
return false;
}
bool success = true;
- cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew();
- bool have_ft = cmSystemTools::FileTimeGet(file, ft);
+ cmFileTimes const ft(file);
std::string emsg;
bool changed;
if (!cmSystemTools::ChangeRPath(file, oldRPath, newRPath, &emsg, &changed)) {
@@ -2104,13 +1135,10 @@ bool cmFileCommand::HandleRPathChangeCommand(
message += "\" to \"";
message += newRPath;
message += "\"";
- this->Makefile->DisplayStatus(message.c_str(), -1);
- }
- if (have_ft) {
- cmSystemTools::FileTimeSet(file, ft);
+ this->Makefile->DisplayStatus(message, -1);
}
+ ft.Store(file);
}
- cmSystemTools::FileTimeDelete(ft);
return success;
}
@@ -2118,7 +1146,7 @@ bool cmFileCommand::HandleRPathRemoveCommand(
std::vector<std::string> const& args)
{
// Evaluate arguments.
- const char* file = CM_NULLPTR;
+ std::string file;
enum Doing
{
DoingNone,
@@ -2129,7 +1157,7 @@ bool cmFileCommand::HandleRPathRemoveCommand(
if (args[i] == "FILE") {
doing = DoingFile;
} else if (doing == DoingFile) {
- file = args[i].c_str();
+ file = args[i];
doing = DoingNone;
} else {
std::ostringstream e;
@@ -2138,7 +1166,7 @@ bool cmFileCommand::HandleRPathRemoveCommand(
return false;
}
}
- if (!file) {
+ if (file.empty()) {
this->SetError("RPATH_REMOVE not given FILE option.");
return false;
}
@@ -2149,8 +1177,7 @@ bool cmFileCommand::HandleRPathRemoveCommand(
return false;
}
bool success = true;
- cmSystemToolsFileTime* ft = cmSystemTools::FileTimeNew();
- bool have_ft = cmSystemTools::FileTimeGet(file, ft);
+ cmFileTimes const ft(file);
std::string emsg;
bool removed;
if (!cmSystemTools::RemoveRPath(file, &emsg, &removed)) {
@@ -2168,13 +1195,10 @@ bool cmFileCommand::HandleRPathRemoveCommand(
std::string message = "Removed runtime path from \"";
message += file;
message += "\"";
- this->Makefile->DisplayStatus(message.c_str(), -1);
- }
- if (have_ft) {
- cmSystemTools::FileTimeSet(file, ft);
+ this->Makefile->DisplayStatus(message, -1);
}
+ ft.Store(file);
}
- cmSystemTools::FileTimeDelete(ft);
return success;
}
@@ -2182,8 +1206,8 @@ bool cmFileCommand::HandleRPathCheckCommand(
std::vector<std::string> const& args)
{
// Evaluate arguments.
- const char* file = CM_NULLPTR;
- const char* rpath = CM_NULLPTR;
+ std::string file;
+ const char* rpath = nullptr;
enum Doing
{
DoingNone,
@@ -2197,7 +1221,7 @@ bool cmFileCommand::HandleRPathCheckCommand(
} else if (args[i] == "FILE") {
doing = DoingFile;
} else if (doing == DoingFile) {
- file = args[i].c_str();
+ file = args[i];
doing = DoingNone;
} else if (doing == DoingRPath) {
rpath = args[i].c_str();
@@ -2209,7 +1233,7 @@ bool cmFileCommand::HandleRPathCheckCommand(
return false;
}
}
- if (!file) {
+ if (file.empty()) {
this->SetError("RPATH_CHECK not given FILE option.");
return false;
}
@@ -2237,57 +1261,55 @@ bool cmFileCommand::HandleReadElfCommand(std::vector<std::string> const& args)
return false;
}
- cmCommandArgumentsHelper argHelper;
- cmCommandArgumentGroup group;
-
- cmCAString readArg(&argHelper, "READ_ELF");
- cmCAString fileNameArg(&argHelper, CM_NULLPTR);
+ std::string const& fileNameArg = args[1];
- cmCAString rpathArg(&argHelper, "RPATH", &group);
- cmCAString runpathArg(&argHelper, "RUNPATH", &group);
- cmCAString errorArg(&argHelper, "CAPTURE_ERROR", &group);
+ struct Arguments
+ {
+ std::string RPath;
+ std::string RunPath;
+ std::string Error;
+ };
- readArg.Follows(CM_NULLPTR);
- fileNameArg.Follows(&readArg);
- group.Follows(&fileNameArg);
- argHelper.Parse(&args, CM_NULLPTR);
+ static auto const parser = cmArgumentParser<Arguments>{}
+ .Bind("RPATH"_s, &Arguments::RPath)
+ .Bind("RUNPATH"_s, &Arguments::RunPath)
+ .Bind("CAPTURE_ERROR"_s, &Arguments::Error);
+ Arguments const arguments = parser.Parse(cmMakeRange(args).advance(2));
- if (!cmSystemTools::FileExists(fileNameArg.GetString(), true)) {
+ if (!cmSystemTools::FileExists(fileNameArg, true)) {
std::ostringstream e;
- e << "READ_ELF given FILE \"" << fileNameArg.GetString()
- << "\" that does not exist.";
+ e << "READ_ELF given FILE \"" << fileNameArg << "\" that does not exist.";
this->SetError(e.str());
return false;
}
#if defined(CMAKE_USE_ELF_PARSER)
- cmELF elf(fileNameArg.GetCString());
+ cmELF elf(fileNameArg.c_str());
- if (!rpathArg.GetString().empty()) {
+ if (!arguments.RPath.empty()) {
if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) {
std::string rpath(se_rpath->Value);
std::replace(rpath.begin(), rpath.end(), ':', ';');
- this->Makefile->AddDefinition(rpathArg.GetString(), rpath.c_str());
+ this->Makefile->AddDefinition(arguments.RPath, rpath.c_str());
}
}
- if (!runpathArg.GetString().empty()) {
+ if (!arguments.RunPath.empty()) {
if (cmELF::StringEntry const* se_runpath = elf.GetRunPath()) {
std::string runpath(se_runpath->Value);
std::replace(runpath.begin(), runpath.end(), ':', ';');
- this->Makefile->AddDefinition(runpathArg.GetString(), runpath.c_str());
+ this->Makefile->AddDefinition(arguments.RunPath, runpath.c_str());
}
}
return true;
#else
std::string error = "ELF parser not available on this platform.";
- if (errorArg.GetString().empty()) {
+ if (arguments.Error.empty()) {
this->SetError(error);
return false;
- } else {
- this->Makefile->AddDefinition(errorArg.GetString(), error.c_str());
- return true;
}
+ this->Makefile->AddDefinition(arguments.Error, error.c_str());
+ return true;
#endif
}
@@ -2309,22 +1331,21 @@ bool cmFileCommand::HandleRelativePathCommand(
const std::string& directoryName = args[2];
const std::string& fileName = args[3];
- if (!cmSystemTools::FileIsFullPath(directoryName.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(directoryName)) {
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())) {
+ if (!cmSystemTools::FileIsFullPath(fileName)) {
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());
+ std::string res = cmSystemTools::RelativePath(directoryName, fileName);
this->Makefile->AddDefinition(outVar, res.c_str());
return true;
}
@@ -2338,17 +1359,17 @@ bool cmFileCommand::HandleRename(std::vector<std::string> const& args)
// Compute full path for old and new names.
std::string oldname = args[1];
- if (!cmsys::SystemTools::FileIsFullPath(oldname.c_str())) {
+ if (!cmsys::SystemTools::FileIsFullPath(oldname)) {
oldname = this->Makefile->GetCurrentSourceDirectory();
oldname += "/" + args[1];
}
std::string newname = args[2];
- if (!cmsys::SystemTools::FileIsFullPath(newname.c_str())) {
+ if (!cmsys::SystemTools::FileIsFullPath(newname)) {
newname = this->Makefile->GetCurrentSourceDirectory();
newname += "/" + args[2];
}
- if (!cmSystemTools::RenameFile(oldname.c_str(), newname.c_str())) {
+ if (!cmSystemTools::RenameFile(oldname, newname)) {
std::string err = cmSystemTools::GetLastSystemError();
std::ostringstream e;
/* clang-format off */
@@ -2369,14 +1390,20 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
{
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())) {
+ for (std::string const& arg :
+ cmMakeRange(args).advance(1)) // Get rid of subcommand
+ {
+ std::string fileName = arg;
+ if (fileName.empty()) {
+ std::string const r = recurse ? "REMOVE_RECURSE" : "REMOVE";
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING,
+ "Ignoring empty file name in " + r + ".");
+ continue;
+ }
+ if (!cmsys::SystemTools::FileIsFullPath(fileName)) {
fileName = this->Makefile->GetCurrentSourceDirectory();
- fileName += "/" + *i;
+ fileName += "/" + arg;
}
if (cmSystemTools::FileIsDirectory(fileName) &&
@@ -2389,44 +1416,43 @@ bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
return true;
}
+namespace {
+std::string ToNativePath(const std::string& path)
+{
+ const auto& outPath = cmSystemTools::ConvertToOutputPath(path);
+ if (outPath.size() > 1 && outPath.front() == '\"' &&
+ outPath.back() == '\"') {
+ return outPath.substr(1, outPath.size() - 2);
+ }
+ return outPath;
+}
+
+std::string ToCMakePath(const std::string& path)
+{
+ auto temp = path;
+ cmSystemTools::ConvertToUnixSlashes(temp);
+ return temp;
+}
+}
+
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, 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;
+ std::vector<std::string> path = cmSystemTools::SplitString(args[1], pathSep);
- 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());
+ std::string value = cmJoin(
+ cmMakeRange(path).transform(nativePath ? ToNativePath : ToCMakePath), ";");
+ this->Makefile->AddDefinition(args[2], value.c_str());
return true;
}
@@ -2439,7 +1465,7 @@ namespace {
size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data)
{
- int realsize = (int)(size * nmemb);
+ int realsize = static_cast<int>(size * nmemb);
cmsys::ofstream* fout = static_cast<cmsys::ofstream*>(data);
const char* chPtr = static_cast<char*>(ptr);
fout->write(chPtr, realsize);
@@ -2449,24 +1475,23 @@ size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data)
size_t cmWriteToMemoryCallback(void* ptr, size_t size, size_t nmemb,
void* data)
{
- int realsize = (int)(size * nmemb);
- cmFileCommandVectorOfChar* vec =
- static_cast<cmFileCommandVectorOfChar*>(data);
+ int realsize = static_cast<int>(size * nmemb);
const char* chPtr = static_cast<char*>(ptr);
- vec->insert(vec->end(), chPtr, chPtr + realsize);
+ cmAppend(*static_cast<cmFileCommandVectorOfChar*>(data), chPtr,
+ chPtr + realsize);
return realsize;
}
size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr,
size_t size, void* data)
{
- cmFileCommandVectorOfChar* vec =
- static_cast<cmFileCommandVectorOfChar*>(data);
+ cmFileCommandVectorOfChar& vec =
+ *static_cast<cmFileCommandVectorOfChar*>(data);
switch (type) {
case CURLINFO_TEXT:
case CURLINFO_HEADER_IN:
case CURLINFO_HEADER_OUT:
- vec->insert(vec->end(), chPtr, chPtr + size);
+ cmAppend(vec, chPtr, chPtr + size);
break;
case CURLINFO_DATA_IN:
case CURLINFO_DATA_OUT:
@@ -2476,7 +1501,7 @@ size_t cmFileCommandCurlDebugCallback(CURL*, curl_infotype type, char* chPtr,
int n = sprintf(buf, "[%" KWIML_INT_PRIu64 " bytes data]\n",
static_cast<KWIML_INT_uint64_t>(size));
if (n > 0) {
- vec->insert(vec->end(), buf, buf + n);
+ cmAppend(vec, buf, buf + n);
}
} break;
default:
@@ -2497,10 +1522,10 @@ public:
bool UpdatePercentage(double value, double total, std::string& status)
{
- int OldPercentage = this->CurrentPercentage;
+ long OldPercentage = this->CurrentPercentage;
if (total > 0.0) {
- this->CurrentPercentage = static_cast<int>(value / total * 100.0 + 0.5);
+ this->CurrentPercentage = std::lround(value / total * 100.0);
if (this->CurrentPercentage > 100) {
// Avoid extra progress reports for unexpected data beyond total.
this->CurrentPercentage = 100;
@@ -2522,7 +1547,7 @@ public:
cmFileCommand* GetFileCommand() { return this->FileCommand; }
private:
- int CurrentPercentage;
+ long CurrentPercentage;
cmFileCommand* FileCommand;
std::string Text;
};
@@ -2539,7 +1564,7 @@ int cmFileDownloadProgressCallback(void* clientp, double dltotal, double dlnow,
if (helper->UpdatePercentage(dlnow, dltotal, status)) {
cmFileCommand* fc = helper->GetFileCommand();
cmMakefile* mf = fc->GetMakefile();
- mf->DisplayStatus(status.c_str(), -1);
+ mf->DisplayStatus(status, -1);
}
return 0;
@@ -2557,7 +1582,7 @@ int cmFileUploadProgressCallback(void* clientp, double dltotal, double dlnow,
if (helper->UpdatePercentage(ulnow, ultotal, status)) {
cmFileCommand* fc = helper->GetFileCommand();
cmMakefile* mf = fc->GetMakefile();
- mf->DisplayStatus(status.c_str(), -1);
+ mf->DisplayStatus(status, -1);
}
return 0;
@@ -2581,7 +1606,10 @@ public:
}
}
- void release() { this->Easy = CM_NULLPTR; }
+ cURLEasyGuard(const cURLEasyGuard&) = delete;
+ cURLEasyGuard& operator=(const cURLEasyGuard&) = delete;
+
+ void release() { this->Easy = nullptr; }
private:
::CURL* Easy;
@@ -2590,12 +1618,14 @@ private:
#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; \
- }
+ do { \
+ if (result != CURLE_OK) { \
+ std::string e(errstr); \
+ e += ::curl_easy_strerror(result); \
+ this->SetError(e); \
+ return false; \
+ } \
+ } while (false)
bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
{
@@ -2617,9 +1647,12 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
std::string statusVar;
bool tls_verify = this->Makefile->IsOn("CMAKE_TLS_VERIFY");
const char* cainfo = this->Makefile->GetDefinition("CMAKE_TLS_CAINFO");
+ std::string netrc_level = this->Makefile->GetSafeDefinition("CMAKE_NETRC");
+ std::string netrc_file =
+ this->Makefile->GetSafeDefinition("CMAKE_NETRC_FILE");
std::string expectedHash;
std::string hashMatchMSG;
- CM_AUTO_PTR<cmCryptoHash> hash;
+ std::unique_ptr<cmCryptoHash> hash;
bool showProgress = false;
std::string userpwd;
@@ -2659,7 +1692,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
} else if (*i == "TLS_VERIFY") {
++i;
if (i != args.end()) {
- tls_verify = cmSystemTools::IsOn(i->c_str());
+ tls_verify = cmSystemTools::IsOn(*i);
} else {
this->SetError("TLS_VERIFY missing bool value.");
return false;
@@ -2672,14 +1705,29 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
this->SetError("TLS_CAFILE missing file value.");
return false;
}
+ } else if (*i == "NETRC_FILE") {
+ ++i;
+ if (i != args.end()) {
+ netrc_file = *i;
+ } else {
+ this->SetError("DOWNLOAD missing file value for NETRC_FILE.");
+ return false;
+ }
+ } else if (*i == "NETRC") {
+ ++i;
+ if (i != args.end()) {
+ netrc_level = *i;
+ } else {
+ this->SetError("DOWNLOAD missing level value for NETRC.");
+ return false;
+ }
} else if (*i == "EXPECTED_MD5") {
++i;
if (i == args.end()) {
this->SetError("DOWNLOAD missing sum value for EXPECTED_MD5.");
return false;
}
- hash =
- CM_AUTO_PTR<cmCryptoHash>(new cmCryptoHash(cmCryptoHash::AlgoMD5));
+ hash = cm::make_unique<cmCryptoHash>(cmCryptoHash::AlgoMD5);
hashMatchMSG = "MD5 sum";
expectedHash = cmSystemTools::LowerCase(*i);
} else if (*i == "SHOW_PROGRESS") {
@@ -2700,8 +1748,8 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
}
std::string algo = i->substr(0, pos);
expectedHash = cmSystemTools::LowerCase(i->substr(pos + 1));
- hash = CM_AUTO_PTR<cmCryptoHash>(cmCryptoHash::New(algo.c_str()));
- if (!hash.get()) {
+ hash = std::unique_ptr<cmCryptoHash>(cmCryptoHash::New(algo.c_str()));
+ if (!hash) {
std::string err = "DOWNLOAD EXPECTED_HASH given unknown ALGO: ";
err += algo;
this->SetError(err);
@@ -2726,7 +1774,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
// Do not return error for compatibility reason.
std::string err = "Unexpected argument: ";
err += *i;
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, err);
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, err);
}
++i;
}
@@ -2734,7 +1782,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
// and the existing file already has the expected hash, then simply
// return.
//
- if (cmSystemTools::FileExists(file.c_str()) && hash.get()) {
+ if (cmSystemTools::FileExists(file) && hash.get()) {
std::string msg;
std::string actualHash = hash->HashFile(file);
if (actualHash == expectedHash) {
@@ -2743,7 +1791,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
msg += "\"";
if (!statusVar.empty()) {
std::ostringstream result;
- result << (int)0 << ";\"" << msg;
+ result << 0 << ";\"" << msg;
this->Makefile->AddDefinition(statusVar, result.str().c_str());
}
return true;
@@ -2753,8 +1801,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
// as we receive downloaded bits from curl...
//
std::string dir = cmSystemTools::GetFilenamePath(file);
- if (!cmSystemTools::FileExists(dir.c_str()) &&
- !cmSystemTools::MakeDirectory(dir.c_str())) {
+ if (!cmSystemTools::FileExists(dir) && !cmSystemTools::MakeDirectory(dir)) {
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.";
@@ -2768,9 +1815,9 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
return false;
}
-#if defined(_WIN32)
+# if defined(_WIN32)
url = fix_file_url_windows(url);
-#endif
+# endif
::CURL* curl;
::curl_global_init(CURL_GLOBAL_DEFAULT);
@@ -2814,12 +1861,22 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
return false;
}
+ // check to see if netrc parameters have been specified
+ // local command args takes precedence over CMAKE_NETRC*
+ netrc_level = cmSystemTools::UpperCase(netrc_level);
+ std::string const& netrc_option_err =
+ cmCurlSetNETRCOption(curl, netrc_level, netrc_file);
+ if (!netrc_option_err.empty()) {
+ this->SetError(netrc_option_err);
+ return false;
+ }
+
cmFileCommandVectorOfChar chunkDebug;
- res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&fout);
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fout);
check_curl_result(res, "DOWNLOAD cannot set write data: ");
- res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void*)&chunkDebug);
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
check_curl_result(res, "DOWNLOAD cannot set debug data: ");
res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
@@ -2866,10 +1923,9 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
check_curl_result(res, "DOWNLOAD cannot set user password: ");
}
- struct curl_slist* headers = CM_NULLPTR;
- for (std::vector<std::string>::const_iterator h = curl_headers.begin();
- h != curl_headers.end(); ++h) {
- headers = ::curl_slist_append(headers, h->c_str());
+ struct curl_slist* headers = nullptr;
+ for (std::string const& h : curl_headers) {
+ headers = ::curl_slist_append(headers, h.c_str());
}
::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
@@ -2883,7 +1939,8 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
if (!statusVar.empty()) {
std::ostringstream result;
- result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
+ result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res)
+ << "\"";
this->Makefile->AddDefinition(statusVar, result.str().c_str());
}
@@ -2896,7 +1953,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
// Verify MD5 sum if requested:
//
- if (hash.get()) {
+ if (hash) {
std::string actualHash = hash->HashFile(file);
if (actualHash.empty()) {
this->SetError("DOWNLOAD cannot compute hash on downloaded file");
@@ -2909,7 +1966,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
<< " for file: [" << file << "]" << std::endl
<< " expected hash: [" << expectedHash << "]" << std::endl
<< " actual hash: [" << actualHash << "]" << std::endl
- << " status: [" << (int)res << ";\""
+ << " status: [" << static_cast<int>(res) << ";\""
<< ::curl_easy_strerror(res) << "\"]" << std::endl;
if (!statusVar.empty() && res == 0) {
@@ -2926,7 +1983,7 @@ bool cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
if (!logVar.empty()) {
chunkDebug.push_back(0);
- this->Makefile->AddDefinition(logVar, &*chunkDebug.begin());
+ this->Makefile->AddDefinition(logVar, chunkDebug.data());
}
return true;
@@ -2956,6 +2013,9 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
std::string statusVar;
bool showProgress = false;
std::string userpwd;
+ std::string netrc_level = this->Makefile->GetSafeDefinition("CMAKE_NETRC");
+ std::string netrc_file =
+ this->Makefile->GetSafeDefinition("CMAKE_NETRC_FILE");
std::vector<std::string> curl_headers;
@@ -2992,6 +2052,22 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
statusVar = *i;
} else if (*i == "SHOW_PROGRESS") {
showProgress = true;
+ } else if (*i == "NETRC_FILE") {
+ ++i;
+ if (i != args.end()) {
+ netrc_file = *i;
+ } else {
+ this->SetError("UPLOAD missing file value for NETRC_FILE.");
+ return false;
+ }
+ } else if (*i == "NETRC") {
+ ++i;
+ if (i != args.end()) {
+ netrc_level = *i;
+ } else {
+ this->SetError("UPLOAD missing level value for NETRC.");
+ return false;
+ }
} else if (*i == "USERPWD") {
++i;
if (i == args.end()) {
@@ -3010,7 +2086,7 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
// Do not return error for compatibility reason.
std::string err = "Unexpected argument: ";
err += *i;
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, err);
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, err);
}
++i;
@@ -3028,9 +2104,9 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
unsigned long file_size = cmsys::SystemTools::FileLength(filename);
-#if defined(_WIN32)
+# if defined(_WIN32)
url = fix_file_url_windows(url);
-#endif
+# endif
::CURL* curl;
::curl_global_init(CURL_GLOBAL_DEFAULT);
@@ -3065,10 +2141,10 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
cmFileCommandVectorOfChar chunkResponse;
cmFileCommandVectorOfChar chunkDebug;
- res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunkResponse);
+ res = ::curl_easy_setopt(curl, CURLOPT_WRITEDATA, &chunkResponse);
check_curl_result(res, "UPLOAD cannot set write data: ");
- res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void*)&chunkDebug);
+ res = ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
check_curl_result(res, "UPLOAD cannot set debug data: ");
res = ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
@@ -3124,10 +2200,19 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
check_curl_result(res, "UPLOAD cannot set user password: ");
}
- struct curl_slist* headers = CM_NULLPTR;
- for (std::vector<std::string>::const_iterator h = curl_headers.begin();
- h != curl_headers.end(); ++h) {
- headers = ::curl_slist_append(headers, h->c_str());
+ // check to see if netrc parameters have been specified
+ // local command args takes precedence over CMAKE_NETRC*
+ netrc_level = cmSystemTools::UpperCase(netrc_level);
+ std::string const& netrc_option_err =
+ cmCurlSetNETRCOption(curl, netrc_level, netrc_file);
+ if (!netrc_option_err.empty()) {
+ this->SetError(netrc_option_err);
+ return false;
+ }
+
+ struct curl_slist* headers = nullptr;
+ for (std::string const& h : curl_headers) {
+ headers = ::curl_slist_append(headers, h.c_str());
}
::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
@@ -3141,14 +2226,15 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
if (!statusVar.empty()) {
std::ostringstream result;
- result << (int)res << ";\"" << ::curl_easy_strerror(res) << "\"";
+ result << static_cast<int>(res) << ";\"" << ::curl_easy_strerror(res)
+ << "\"";
this->Makefile->AddDefinition(statusVar, result.str().c_str());
}
::curl_global_cleanup();
fclose(fin);
- fin = CM_NULLPTR;
+ fin = nullptr;
if (!logVar.empty()) {
std::string log;
@@ -3156,14 +2242,14 @@ bool cmFileCommand::HandleUploadCommand(std::vector<std::string> const& args)
if (!chunkResponse.empty()) {
chunkResponse.push_back(0);
log += "Response:\n";
- log += &*chunkResponse.begin();
+ log += chunkResponse.data();
log += "\n";
}
if (!chunkDebug.empty()) {
chunkDebug.push_back(0);
log += "Debug:\n";
- log += &*chunkDebug.begin();
+ log += chunkDebug.data();
log += "\n";
}
@@ -3185,15 +2271,15 @@ void cmFileCommand::AddEvaluationFile(const std::string& inputName,
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression outputGe(lfbt);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> outputCge =
+ std::unique_ptr<cmCompiledGeneratorExpression> outputCge =
outputGe.Parse(outputExpr);
cmGeneratorExpression conditionGe(lfbt);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> conditionCge =
+ std::unique_ptr<cmCompiledGeneratorExpression> conditionCge =
conditionGe.Parse(condition);
- this->Makefile->AddEvaluationFile(inputName, outputCge, conditionCge,
- inputIsContent);
+ this->Makefile->AddEvaluationFile(inputName, std::move(outputCge),
+ std::move(conditionCge), inputIsContent);
}
bool cmFileCommand::HandleGenerateCommand(std::vector<std::string> const& args)
@@ -3254,7 +2340,8 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
// Parse arguments
if (args.size() < 2) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, "sub-command LOCK requires at least two arguments.");
+ MessageType::FATAL_ERROR,
+ "sub-command LOCK requires at least two arguments.");
return false;
}
@@ -3268,7 +2355,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
++i;
const char* merr = "expected FUNCTION, FILE or PROCESS after GUARD";
if (i >= args.size()) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, merr);
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, merr);
return false;
}
if (args[i] == "FUNCTION") {
@@ -3280,7 +2367,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
} else {
std::ostringstream e;
e << merr << ", but got:\n \"" << args[i] << "\".";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
@@ -3288,14 +2375,15 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
++i;
if (i >= args.size()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, "expected variable name after RESULT_VARIABLE");
+ MessageType::FATAL_ERROR,
+ "expected variable name after RESULT_VARIABLE");
return false;
}
resultVariable = args[i];
} else if (args[i] == "TIMEOUT") {
++i;
if (i >= args.size()) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"expected timeout value after TIMEOUT");
return false;
}
@@ -3304,7 +2392,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
scanned < 0) {
std::ostringstream e;
e << "TIMEOUT value \"" << args[i] << "\" is not an unsigned integer.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
timeout = static_cast<unsigned long>(scanned);
@@ -3312,7 +2400,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
std::ostringstream e;
e << "expected DIRECTORY, RELEASE, GUARD, RESULT_VARIABLE or TIMEOUT\n";
e << "but got: \"" << args[i] << "\".";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
}
@@ -3322,7 +2410,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
}
if (!cmsys::SystemTools::FileIsFullPath(path)) {
- path = this->Makefile->GetCurrentSourceDirectory() + ("/" + path);
+ path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
}
// Unify path (remove '//', '/../', ...)
@@ -3334,7 +2422,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
std::ostringstream e;
e << "directory\n \"" << parentDir << "\"\ncreation failed ";
e << "(check permissions).";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -3342,7 +2430,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
if (!file) {
std::ostringstream e;
e << "file\n \"" << path << "\"\ncreation failed (check permissions).";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -3377,7 +2465,7 @@ bool cmFileCommand::HandleLockCommand(std::vector<std::string> const& args)
if (resultVariable.empty() && !fileLockResult.IsOk()) {
std::ostringstream e;
e << "error locking file\n \"" << path << "\"\n" << result << ".";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -3436,3 +2524,169 @@ bool cmFileCommand::HandleTimestampCommand(
return true;
}
+
+bool cmFileCommand::HandleSizeCommand(std::vector<std::string> const& args)
+{
+ if (args.size() != 3) {
+ std::ostringstream e;
+ e << args[0] << " requires a file name and output variable";
+ this->SetError(e.str());
+ return false;
+ }
+
+ unsigned int argsIndex = 1;
+
+ const std::string& filename = args[argsIndex++];
+
+ const std::string& outputVariable = args[argsIndex++];
+
+ if (!cmSystemTools::FileExists(filename, true)) {
+ std::ostringstream e;
+ e << "SIZE requested of path that is not readable:\n " << filename;
+ this->SetError(e.str());
+ return false;
+ }
+
+ this->Makefile->AddDefinition(
+ outputVariable,
+ std::to_string(cmSystemTools::FileLength(filename)).c_str());
+
+ return true;
+}
+
+bool cmFileCommand::HandleReadSymlinkCommand(
+ std::vector<std::string> const& args)
+{
+ if (args.size() != 3) {
+ std::ostringstream e;
+ e << args[0] << " requires a file name and output variable";
+ this->SetError(e.str());
+ return false;
+ }
+
+ const std::string& filename = args[1];
+ const std::string& outputVariable = args[2];
+
+ std::string result;
+ if (!cmSystemTools::ReadSymlink(filename, result)) {
+ std::ostringstream e;
+ e << "READ_SYMLINK requested of path that is not a symlink:\n "
+ << filename;
+ this->SetError(e.str());
+ return false;
+ }
+
+ this->Makefile->AddDefinition(outputVariable, result.c_str());
+
+ return true;
+}
+
+bool cmFileCommand::HandleCreateLinkCommand(
+ std::vector<std::string> const& args)
+{
+ if (args.size() < 3) {
+ this->SetError("CREATE_LINK must be called with at least two additional "
+ "arguments");
+ return false;
+ }
+
+ std::string const& fileName = args[1];
+ std::string const& newFileName = args[2];
+
+ struct Arguments
+ {
+ std::string Result;
+ bool CopyOnError = false;
+ bool Symbolic = false;
+ };
+
+ static auto const parser =
+ cmArgumentParser<Arguments>{}
+ .Bind("RESULT"_s, &Arguments::Result)
+ .Bind("COPY_ON_ERROR"_s, &Arguments::CopyOnError)
+ .Bind("SYMBOLIC"_s, &Arguments::Symbolic);
+
+ std::vector<std::string> unconsumedArgs;
+ Arguments const arguments =
+ parser.Parse(cmMakeRange(args).advance(3), &unconsumedArgs);
+
+ if (!unconsumedArgs.empty()) {
+ this->SetError("unknown argument: \"" + unconsumedArgs.front() + '\"');
+ return false;
+ }
+
+ // The system error message generated in the operation.
+ std::string result;
+
+ // Check if the paths are distinct.
+ if (fileName == newFileName) {
+ result = "CREATE_LINK cannot use same file and newfile";
+ if (!arguments.Result.empty()) {
+ this->Makefile->AddDefinition(arguments.Result, result.c_str());
+ return true;
+ }
+ this->SetError(result);
+ return false;
+ }
+
+ // Hard link requires original file to exist.
+ if (!arguments.Symbolic && !cmSystemTools::FileExists(fileName)) {
+ result = "Cannot hard link \'" + fileName + "\' as it does not exist.";
+ if (!arguments.Result.empty()) {
+ this->Makefile->AddDefinition(arguments.Result, result.c_str());
+ return true;
+ }
+ this->SetError(result);
+ return false;
+ }
+
+ // Check if the new file already exists and remove it.
+ if ((cmSystemTools::FileExists(newFileName) ||
+ cmSystemTools::FileIsSymlink(newFileName)) &&
+ !cmSystemTools::RemoveFile(newFileName)) {
+ std::ostringstream e;
+ e << "Failed to create link '" << newFileName
+ << "' because existing path cannot be removed: "
+ << cmSystemTools::GetLastSystemError() << "\n";
+
+ if (!arguments.Result.empty()) {
+ this->Makefile->AddDefinition(arguments.Result, e.str().c_str());
+ return true;
+ }
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Whether the operation completed successfully.
+ bool completed = false;
+
+ // Check if the command requires a symbolic link.
+ if (arguments.Symbolic) {
+ completed = cmSystemTools::CreateSymlink(fileName, newFileName, &result);
+ } else {
+ completed = cmSystemTools::CreateLink(fileName, newFileName, &result);
+ }
+
+ // Check if copy-on-error is enabled in the arguments.
+ if (!completed && arguments.CopyOnError) {
+ completed = cmsys::SystemTools::CopyFileAlways(fileName, newFileName);
+ if (!completed) {
+ result = "Copy failed: " + cmSystemTools::GetLastSystemError();
+ }
+ }
+
+ // Check if the operation was successful.
+ if (completed) {
+ result = "0";
+ } else if (arguments.Result.empty()) {
+ // The operation failed and the result is not reported in a variable.
+ this->SetError(result);
+ return false;
+ }
+
+ if (!arguments.Result.empty()) {
+ this->Makefile->AddDefinition(arguments.Result, result.c_str());
+ }
+
+ return true;
+}
diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h
index d09ef42f1..12c511514 100644
--- a/Source/cmFileCommand.h
+++ b/Source/cmFileCommand.h
@@ -3,7 +3,7 @@
#ifndef cmFileCommand_h
#define cmFileCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -22,14 +22,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFileCommand; }
+ cmCommand* Clone() override { return new cmFileCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
bool HandleRename(std::vector<std::string> const& args);
@@ -39,6 +39,7 @@ protected:
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 HandleTouchCommand(std::vector<std::string> const& args, bool create);
bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
bool HandleRelativePathCommand(std::vector<std::string> const& args);
@@ -58,6 +59,9 @@ protected:
bool HandleTimestampCommand(std::vector<std::string> const& args);
bool HandleGenerateCommand(std::vector<std::string> const& args);
bool HandleLockCommand(std::vector<std::string> const& args);
+ bool HandleSizeCommand(std::vector<std::string> const& args);
+ bool HandleReadSymlinkCommand(std::vector<std::string> const& args);
+ bool HandleCreateLinkCommand(std::vector<std::string> const& args);
private:
void AddEvaluationFile(const std::string& inputName,
diff --git a/Source/cmFileLock.cxx b/Source/cmFileLock.cxx
index 786d6c63f..1e472da63 100644
--- a/Source/cmFileLock.cxx
+++ b/Source/cmFileLock.cxx
@@ -42,7 +42,7 @@ cmFileLockResult cmFileLock::Lock(const std::string& filename,
}
if (!result.IsOk()) {
- this->Filename = "";
+ this->Filename.clear();
}
return result;
@@ -54,7 +54,7 @@ bool cmFileLock::IsLocked(const std::string& filename) const
}
#if defined(_WIN32)
-#include "cmFileLockWin32.cxx"
+# include "cmFileLockWin32.cxx"
#else
-#include "cmFileLockUnix.cxx"
+# include "cmFileLockUnix.cxx"
#endif
diff --git a/Source/cmFileLock.h b/Source/cmFileLock.h
index ccef50816..2130d65db 100644
--- a/Source/cmFileLock.h
+++ b/Source/cmFileLock.h
@@ -3,46 +3,47 @@
#ifndef cmFileLock_h
#define cmFileLock_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#if defined(_WIN32)
-#include <windows.h> // HANDLE
+# include <windows.h> // HANDLE
#endif
class cmFileLockResult;
/**
- * @brief Cross-platform file locking.
- * @details Under the hood this class use 'fcntl' for Unix-like platforms and
- * 'LockFileEx'/'UnlockFileEx' for Win32 platform. Locks are exclusive and
- * advisory.
- */
+ * @brief Cross-platform file locking.
+ * @details Under the hood this class use 'fcntl' for Unix-like platforms and
+ * 'LockFileEx'/'UnlockFileEx' for Win32 platform. Locks are exclusive and
+ * advisory.
+ */
class cmFileLock
{
- CM_DISABLE_COPY(cmFileLock)
-
public:
cmFileLock();
~cmFileLock();
+ cmFileLock(cmFileLock const&) = delete;
+ cmFileLock& operator=(cmFileLock const&) = delete;
+
/**
- * @brief Lock the file.
- * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
- */
+ * @brief Lock the file.
+ * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
+ */
cmFileLockResult Lock(const std::string& filename, unsigned long timeoutSec);
/**
- * @brief Unlock the file.
- */
+ * @brief Unlock the file.
+ */
cmFileLockResult Release();
/**
- * @brief Check file is locked by this class.
- * @details This function helps to find double locks (deadlocks) and to do
- * explicit unlocks.
- */
+ * @brief Check file is locked by this class.
+ * @details This function helps to find double locks (deadlocks) and to do
+ * explicit unlocks.
+ */
bool IsLocked(const std::string& filename) const;
private:
@@ -51,14 +52,13 @@ private:
cmFileLockResult LockWithTimeout(unsigned long timeoutSec);
#if defined(_WIN32)
- typedef HANDLE FileId;
+ HANDLE File = INVALID_HANDLE_VALUE;
BOOL LockFile(DWORD flags);
#else
- typedef int FileId;
+ int File = -1;
int LockFile(int cmd, int type);
#endif
- FileId File;
std::string Filename;
};
diff --git a/Source/cmFileLockPool.cxx b/Source/cmFileLockPool.cxx
index 7b1564c34..d700a79c3 100644
--- a/Source/cmFileLockPool.cxx
+++ b/Source/cmFileLockPool.cxx
@@ -8,9 +8,7 @@
#include "cmFileLock.h"
#include "cmFileLockResult.h"
-cmFileLockPool::cmFileLockPool()
-{
-}
+cmFileLockPool::cmFileLockPool() = default;
cmFileLockPool::~cmFileLockPool()
{
@@ -75,16 +73,15 @@ cmFileLockResult cmFileLockPool::LockProcessScope(const std::string& filename,
cmFileLockResult cmFileLockPool::Release(const std::string& filename)
{
- for (It i = this->FunctionScopes.begin(); i != this->FunctionScopes.end();
- ++i) {
- const cmFileLockResult result = (*i)->Release(filename);
+ for (auto& funcScope : this->FunctionScopes) {
+ const cmFileLockResult result = funcScope->Release(filename);
if (!result.IsOk()) {
return result;
}
}
- for (It i = this->FileScopes.begin(); i != this->FileScopes.end(); ++i) {
- const cmFileLockResult result = (*i)->Release(filename);
+ for (auto& fileScope : this->FileScopes) {
+ const cmFileLockResult result = fileScope->Release(filename);
if (!result.IsOk()) {
return result;
}
@@ -95,16 +92,15 @@ cmFileLockResult cmFileLockPool::Release(const std::string& filename)
bool cmFileLockPool::IsAlreadyLocked(const std::string& filename) const
{
- for (CIt i = this->FunctionScopes.begin(); i != this->FunctionScopes.end();
- ++i) {
- const bool result = (*i)->IsAlreadyLocked(filename);
+ for (auto const& funcScope : this->FunctionScopes) {
+ const bool result = funcScope->IsAlreadyLocked(filename);
if (result) {
return true;
}
}
- for (CIt i = this->FileScopes.begin(); i != this->FileScopes.end(); ++i) {
- const bool result = (*i)->IsAlreadyLocked(filename);
+ for (auto const& fileScope : this->FileScopes) {
+ const bool result = fileScope->IsAlreadyLocked(filename);
if (result) {
return true;
}
@@ -113,9 +109,7 @@ bool cmFileLockPool::IsAlreadyLocked(const std::string& filename) const
return this->ProcessScope.IsAlreadyLocked(filename);
}
-cmFileLockPool::ScopePool::ScopePool()
-{
-}
+cmFileLockPool::ScopePool::ScopePool() = default;
cmFileLockPool::ScopePool::~ScopePool()
{
@@ -138,9 +132,9 @@ cmFileLockResult cmFileLockPool::ScopePool::Lock(const std::string& filename,
cmFileLockResult cmFileLockPool::ScopePool::Release(
const std::string& filename)
{
- for (It i = this->Locks.begin(); i != this->Locks.end(); ++i) {
- if ((*i)->IsLocked(filename)) {
- return (*i)->Release();
+ for (auto& lock : this->Locks) {
+ if (lock->IsLocked(filename)) {
+ return lock->Release();
}
}
return cmFileLockResult::MakeOk();
@@ -149,8 +143,8 @@ cmFileLockResult cmFileLockPool::ScopePool::Release(
bool cmFileLockPool::ScopePool::IsAlreadyLocked(
const std::string& filename) const
{
- for (CIt i = this->Locks.begin(); i != this->Locks.end(); ++i) {
- if ((*i)->IsLocked(filename)) {
+ for (auto const& lock : this->Locks) {
+ if (lock->IsLocked(filename)) {
return true;
}
}
diff --git a/Source/cmFileLockPool.h b/Source/cmFileLockPool.h
index c96a8c2f8..41203baac 100644
--- a/Source/cmFileLockPool.h
+++ b/Source/cmFileLockPool.h
@@ -3,7 +3,7 @@
#ifndef cmFileLockPool_h
#define cmFileLockPool_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -13,33 +13,34 @@ class cmFileLockResult;
class cmFileLockPool
{
- CM_DISABLE_COPY(cmFileLockPool)
-
public:
cmFileLockPool();
~cmFileLockPool();
+ cmFileLockPool(cmFileLockPool const&) = delete;
+ cmFileLockPool& operator=(cmFileLockPool const&) = delete;
+
//@{
/**
- * @brief Function scope control.
- */
+ * @brief Function scope control.
+ */
void PushFunctionScope();
void PopFunctionScope();
//@}
//@{
/**
- * @brief File scope control.
- */
+ * @brief File scope control.
+ */
void PushFileScope();
void PopFileScope();
//@}
//@{
/**
- * @brief Lock the file in given scope.
- * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
- */
+ * @brief Lock the file in given scope.
+ * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
+ */
cmFileLockResult LockFunctionScope(const std::string& filename,
unsigned long timeoutSec);
cmFileLockResult LockFileScope(const std::string& filename,
@@ -49,8 +50,8 @@ public:
//@}
/**
- * @brief Unlock the file explicitly.
- */
+ * @brief Unlock the file explicitly.
+ */
cmFileLockResult Release(const std::string& filename);
private:
@@ -58,12 +59,13 @@ private:
class ScopePool
{
- CM_DISABLE_COPY(ScopePool)
-
public:
ScopePool();
~ScopePool();
+ ScopePool(ScopePool const&) = delete;
+ ScopePool& operator=(ScopePool const&) = delete;
+
cmFileLockResult Lock(const std::string& filename,
unsigned long timeoutSec);
cmFileLockResult Release(const std::string& filename);
diff --git a/Source/cmFileLockResult.cxx b/Source/cmFileLockResult.cxx
index a040705e8..9ca5d8a06 100644
--- a/Source/cmFileLockResult.cxx
+++ b/Source/cmFileLockResult.cxx
@@ -5,6 +5,7 @@
#include <errno.h>
#include <string.h>
+#define WINMSG_BUF_LEN (1024)
cmFileLockResult cmFileLockResult::MakeOk()
{
return cmFileLockResult(OK, 0);
@@ -53,18 +54,12 @@ std::string cmFileLockResult::GetOutputMessage() const
case SYSTEM:
#if defined(_WIN32)
{
- char* errorText = NULL;
-
- // http://stackoverflow.com/a/455533/2288008
- DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS;
- ::FormatMessageA(flags, NULL, this->ErrorValue,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPSTR)&errorText, 0, NULL);
-
- if (errorText != NULL) {
- const std::string message = errorText;
- ::LocalFree(errorText);
+ char winmsg[WINMSG_BUF_LEN];
+ DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
+ if (FormatMessageA(flags, NULL, this->ErrorValue,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)winmsg, WINMSG_BUF_LEN, NULL)) {
+ const std::string message = winmsg;
return message;
} else {
return "Internal error (FormatMessageA failed)";
diff --git a/Source/cmFileLockResult.h b/Source/cmFileLockResult.h
index 4cedc0ae6..8b4929ae1 100644
--- a/Source/cmFileLockResult.h
+++ b/Source/cmFileLockResult.h
@@ -8,13 +8,13 @@
#include <string>
#if defined(_WIN32)
-#include <windows.h> // DWORD
+# include <windows.h> // DWORD
#endif
/**
- * @brief Result of the locking/unlocking file.
- * @note See @c cmFileLock
- */
+ * @brief Result of the locking/unlocking file.
+ * @note See @c cmFileLock
+ */
class cmFileLockResult
{
public:
@@ -25,33 +25,33 @@ public:
#endif
/**
- * @brief Successful lock/unlock.
- */
+ * @brief Successful lock/unlock.
+ */
static cmFileLockResult MakeOk();
/**
- * @brief Lock/Unlock failed. Read error/GetLastError.
- */
+ * @brief Lock/Unlock failed. Read error/GetLastError.
+ */
static cmFileLockResult MakeSystem();
/**
- * @brief Lock/Unlock failed. Timeout reached.
- */
+ * @brief Lock/Unlock failed. Timeout reached.
+ */
static cmFileLockResult MakeTimeout();
/**
- * @brief File already locked.
- */
+ * @brief File already locked.
+ */
static cmFileLockResult MakeAlreadyLocked();
/**
- * @brief Internal error.
- */
+ * @brief Internal error.
+ */
static cmFileLockResult MakeInternal();
/**
- * @brief Try to lock with function guard outside of the function
- */
+ * @brief Try to lock with function guard outside of the function
+ */
static cmFileLockResult MakeNoFunction();
bool IsOk() const;
diff --git a/Source/cmFileLockUnix.cxx b/Source/cmFileLockUnix.cxx
index 7353b01fc..1bf5013ad 100644
--- a/Source/cmFileLockUnix.cxx
+++ b/Source/cmFileLockUnix.cxx
@@ -8,10 +8,7 @@
#include <stdio.h> // SEEK_SET
#include <unistd.h>
-cmFileLock::cmFileLock()
- : File(-1)
-{
-}
+cmFileLock::cmFileLock() = default;
cmFileLockResult cmFileLock::Release()
{
diff --git a/Source/cmFileLockWin32.cxx b/Source/cmFileLockWin32.cxx
index 51ac24993..a61d360ab 100644
--- a/Source/cmFileLockWin32.cxx
+++ b/Source/cmFileLockWin32.cxx
@@ -6,7 +6,6 @@
#include <windows.h> // CreateFileW
cmFileLock::cmFileLock()
- : File(INVALID_HANDLE_VALUE)
{
}
diff --git a/Source/cmFileMonitor.cxx b/Source/cmFileMonitor.cxx
index 80275357c..56ee739b0 100644
--- a/Source/cmFileMonitor.cxx
+++ b/Source/cmFileMonitor.cxx
@@ -19,7 +19,6 @@ void on_fs_close(uv_handle_t* handle);
class cmIBaseWatcher
{
public:
- cmIBaseWatcher() = default;
virtual ~cmIBaseWatcher() = default;
virtual void Trigger(const std::string& pathSegment, int events,
@@ -49,8 +48,8 @@ public:
int status) const final
{
if (pathSegment.empty()) {
- for (const auto& i : this->Children) {
- i.second->Trigger(std::string(), events, status);
+ for (auto const& child : this->Children) {
+ child.second->Trigger(std::string(), events, status);
}
} else {
const auto i = this->Children.find(pathSegment);
@@ -62,24 +61,24 @@ public:
void StartWatching() override
{
- for (const auto& i : this->Children) {
- i.second->StartWatching();
+ for (auto const& child : this->Children) {
+ child.second->StartWatching();
}
}
void StopWatching() override
{
- for (const auto& i : this->Children) {
- i.second->StopWatching();
+ for (auto const& child : this->Children) {
+ child.second->StopWatching();
}
}
std::vector<std::string> WatchedFiles() const final
{
std::vector<std::string> result;
- for (const auto& i : this->Children) {
- for (const auto& j : i.second->WatchedFiles()) {
- result.push_back(j);
+ for (auto const& child : this->Children) {
+ for (std::string const& f : child.second->WatchedFiles()) {
+ result.push_back(f);
}
}
return result;
@@ -88,9 +87,9 @@ public:
std::vector<std::string> WatchedDirectories() const override
{
std::vector<std::string> result;
- for (const auto& i : this->Children) {
- for (const auto& j : i.second->WatchedDirectories()) {
- result.push_back(j);
+ for (auto const& child : this->Children) {
+ for (std::string const& dir : child.second->WatchedDirectories()) {
+ result.push_back(dir);
}
}
return result;
@@ -150,11 +149,6 @@ public:
p->AddChildWatcher(ps, this);
}
- ~cmRealDirectoryWatcher() override
- {
- // Handle is freed via uv_handle_close callback!
- }
-
void StartWatching() final
{
if (!this->Handle) {
@@ -171,7 +165,9 @@ public:
{
if (this->Handle) {
uv_fs_event_stop(this->Handle);
- uv_close(reinterpret_cast<uv_handle_t*>(this->Handle), &on_fs_close);
+ if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(this->Handle))) {
+ uv_close(reinterpret_cast<uv_handle_t*>(this->Handle), &on_fs_close);
+ }
this->Handle = nullptr;
}
cmVirtualDirectoryWatcher::StopWatching();
@@ -182,8 +178,9 @@ public:
std::vector<std::string> WatchedDirectories() const override
{
std::vector<std::string> result = { Path() };
- for (const auto& j : cmVirtualDirectoryWatcher::WatchedDirectories()) {
- result.push_back(j);
+ for (std::string const& dir :
+ cmVirtualDirectoryWatcher::WatchedDirectories()) {
+ result.push_back(dir);
}
return result;
}
@@ -265,7 +262,7 @@ public:
static_cast<void>(ps);
const std::string path = this->Path();
- for (const auto& cb : this->CbList) {
+ for (cmFileMonitor::Callback const& cb : this->CbList) {
cb(path, events, status);
}
}
@@ -309,9 +306,10 @@ cmFileMonitor::~cmFileMonitor()
void cmFileMonitor::MonitorPaths(const std::vector<std::string>& paths,
Callback const& cb)
{
- for (const auto& p : paths) {
+ for (std::string const& p : paths) {
std::vector<std::string> pathSegments;
cmsys::SystemTools::SplitPath(p, pathSegments, true);
+ const bool pathIsFile = !cmsys::SystemTools::FileIsDirectory(p);
const size_t segmentCount = pathSegments.size();
if (segmentCount < 2) { // Expect at least rootdir and filename
@@ -321,7 +319,7 @@ void cmFileMonitor::MonitorPaths(const std::vector<std::string>& paths,
for (size_t i = 0; i < segmentCount; ++i) {
assert(currentWatcher);
- const bool fileSegment = (i == segmentCount - 1);
+ const bool fileSegment = (i == segmentCount - 1 && pathIsFile);
const bool rootSegment = (i == 0);
assert(
!(fileSegment &&
diff --git a/Source/cmFileMonitor.h b/Source/cmFileMonitor.h
index d7ec92a17..7ffc9294e 100644
--- a/Source/cmFileMonitor.h
+++ b/Source/cmFileMonitor.h
@@ -2,7 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <functional>
#include <string>
@@ -14,12 +14,14 @@ class cmRootWatcher;
class cmFileMonitor
{
- CM_DISABLE_COPY(cmFileMonitor)
public:
cmFileMonitor(uv_loop_t* l);
~cmFileMonitor();
+ cmFileMonitor(cmFileMonitor const&) = delete;
+ cmFileMonitor& operator=(cmFileMonitor const&) = delete;
+
using Callback = std::function<void(const std::string&, int, int)>;
void MonitorPaths(const std::vector<std::string>& paths, Callback const& cb);
void StopMonitoring();
diff --git a/Source/cmFilePathChecksum.cxx b/Source/cmFilePathChecksum.cxx
index 62f52e590..47a223a20 100644
--- a/Source/cmFilePathChecksum.cxx
+++ b/Source/cmFilePathChecksum.cxx
@@ -9,14 +9,12 @@
#include <vector>
-cmFilePathChecksum::cmFilePathChecksum()
-{
-}
+cmFilePathChecksum::cmFilePathChecksum() = default;
-cmFilePathChecksum::cmFilePathChecksum(const std::string& currentSrcDir,
- const std::string& currentBinDir,
- const std::string& projectSrcDir,
- const std::string& projectBinDir)
+cmFilePathChecksum::cmFilePathChecksum(std::string const& currentSrcDir,
+ std::string const& currentBinDir,
+ std::string const& projectSrcDir,
+ std::string const& projectBinDir)
{
setupParentDirs(currentSrcDir, currentBinDir, projectSrcDir, projectBinDir);
}
@@ -29,36 +27,35 @@ cmFilePathChecksum::cmFilePathChecksum(cmMakefile* makefile)
makefile->GetHomeOutputDirectory());
}
-void cmFilePathChecksum::setupParentDirs(const std::string& currentSrcDir,
- const std::string& currentBinDir,
- const std::string& projectSrcDir,
- const std::string& projectBinDir)
+void cmFilePathChecksum::setupParentDirs(std::string const& currentSrcDir,
+ std::string const& currentBinDir,
+ std::string const& projectSrcDir,
+ std::string const& projectBinDir)
{
- parentDirs[0].first = cmsys::SystemTools::GetRealPath(currentSrcDir);
- parentDirs[1].first = cmsys::SystemTools::GetRealPath(currentBinDir);
- parentDirs[2].first = cmsys::SystemTools::GetRealPath(projectSrcDir);
- parentDirs[3].first = cmsys::SystemTools::GetRealPath(projectBinDir);
+ this->parentDirs[0].first = cmSystemTools::GetRealPath(currentSrcDir);
+ this->parentDirs[1].first = cmSystemTools::GetRealPath(currentBinDir);
+ this->parentDirs[2].first = cmSystemTools::GetRealPath(projectSrcDir);
+ this->parentDirs[3].first = cmSystemTools::GetRealPath(projectBinDir);
- parentDirs[0].second = "CurrentSource";
- parentDirs[1].second = "CurrentBinary";
- parentDirs[2].second = "ProjectSource";
- parentDirs[3].second = "ProjectBinary";
+ this->parentDirs[0].second = "CurrentSource";
+ this->parentDirs[1].second = "CurrentBinary";
+ this->parentDirs[2].second = "ProjectSource";
+ this->parentDirs[3].second = "ProjectBinary";
}
-std::string cmFilePathChecksum::get(const std::string& filePath) const
+std::string cmFilePathChecksum::get(std::string const& filePath) const
{
std::string relPath;
std::string relSeed;
{
- const std::string fileReal = cmsys::SystemTools::GetRealPath(filePath);
+ std::string const fileReal = cmSystemTools::GetRealPath(filePath);
std::string parentDir;
// Find closest project parent directory
- for (size_t ii = 0; ii != numParentDirs; ++ii) {
- const std::string& pDir = parentDirs[ii].first;
- if (!pDir.empty() &&
- cmsys::SystemTools::IsSubDirectory(fileReal, pDir)) {
- relSeed = parentDirs[ii].second;
- parentDir = pDir;
+ for (auto const& pDir : this->parentDirs) {
+ if (!pDir.first.empty() &&
+ cmsys::SystemTools::IsSubDirectory(fileReal, pDir.first)) {
+ parentDir = pDir.first;
+ relSeed = pDir.second;
break;
}
}
@@ -77,11 +74,11 @@ std::string cmFilePathChecksum::get(const std::string& filePath) const
cmCryptoHash(cmCryptoHash::AlgoSHA256).ByteHashString(relSeed + relPath);
// Convert binary checksum to string
- return cmBase32Encoder().encodeString(&hashBytes[0], hashBytes.size(),
+ return cmBase32Encoder().encodeString(hashBytes.data(), hashBytes.size(),
false);
}
-std::string cmFilePathChecksum::getPart(const std::string& filePath,
+std::string cmFilePathChecksum::getPart(std::string const& filePath,
size_t length) const
{
return get(filePath).substr(0, length);
diff --git a/Source/cmFilePathChecksum.h b/Source/cmFilePathChecksum.h
index 9d570eb4d..30881ce90 100644
--- a/Source/cmFilePathChecksum.h
+++ b/Source/cmFilePathChecksum.h
@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include <array>
#include <stddef.h>
#include <string>
#include <utility>
@@ -28,38 +29,36 @@ public:
/// @brief Parent directories are empty
cmFilePathChecksum();
- /// @brief Initilizes the parent directories manually
- cmFilePathChecksum(const std::string& currentSrcDir,
- const std::string& currentBinDir,
- const std::string& projectSrcDir,
- const std::string& projectBinDir);
+ /// @brief Initializes the parent directories manually
+ cmFilePathChecksum(std::string const& currentSrcDir,
+ std::string const& currentBinDir,
+ std::string const& projectSrcDir,
+ std::string const& projectBinDir);
- /// @brief Initilizes the parent directories from a makefile
+ /// @brief Initializes the parent directories from a makefile
cmFilePathChecksum(cmMakefile* makefile);
/// @brief Allows parent directories setup after construction
///
- void setupParentDirs(const std::string& currentSrcDir,
- const std::string& currentBinDir,
- const std::string& projectSrcDir,
- const std::string& projectBinDir);
+ void setupParentDirs(std::string const& currentSrcDir,
+ std::string const& currentBinDir,
+ std::string const& projectSrcDir,
+ std::string const& projectBinDir);
/* @brief Calculates the path checksum for the parent directory of a file
*
*/
- std::string get(const std::string& filePath) const;
+ std::string get(std::string const& filePath) const;
/* @brief Same as get() but returns only the first length characters
*
*/
- std::string getPart(const std::string& filePath,
+ std::string getPart(std::string const& filePath,
size_t length = partLengthDefault) const;
private:
- /// Size of the parent directory list
- static const size_t numParentDirs = 4;
/// List of (directory name, seed name) pairs
- std::pair<std::string, std::string> parentDirs[numParentDirs];
+ std::array<std::pair<std::string, std::string>, 4> parentDirs;
};
#endif
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index 10c6fe46f..42aff0438 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -2,15 +2,14 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFindBase.h"
-#include "cmConfigure.h"
#include <deque>
#include <iostream>
-#include <iterator>
#include <map>
#include <stddef.h>
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmSearchPath.h"
#include "cmState.h"
#include "cmStateTypes.h"
@@ -68,8 +67,6 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
}
this->AlreadyInCache = false;
- this->SelectDefaultNoPackageRootPath();
-
// Find the current root path mode.
this->SelectDefaultRootPathMode();
@@ -132,25 +129,24 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
this->VariableDocumentation += "the (unknown) library be found";
} else if (this->Names.size() == 1) {
this->VariableDocumentation +=
- "the " + this->Names[0] + " library be found";
+ "the " + this->Names.front() + " library be found";
} else {
this->VariableDocumentation += "one of the ";
this->VariableDocumentation +=
cmJoin(cmMakeRange(this->Names).retreat(1), ", ");
this->VariableDocumentation +=
- " or " + this->Names[this->Names.size() - 1] + " libraries be found";
+ " or " + this->Names.back() + " libraries be found";
}
}
// look for old style
// FIND_*(VAR name path1 path2 ...)
- if (!newStyle) {
+ if (!newStyle && !this->Names.empty()) {
// 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]);
- this->UserGuessArgs.insert(this->UserGuessArgs.end(),
- shortArgs.begin() + 1, shortArgs.end());
+ cmAppend(this->UserGuessArgs, shortArgs.begin() + 1, shortArgs.end());
}
this->ExpandPaths();
@@ -207,16 +203,10 @@ void cmFindBase::FillPackageRootPath()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot];
- // Add package specific search prefixes
- // NOTE: This should be using const_reverse_iterator but HP aCC and
- // Oracle sunCC both currently have standard library issues
- // with the reverse iterator APIs.
- for (std::deque<std::string>::reverse_iterator pkg =
- this->Makefile->FindPackageModuleStack.rbegin();
- pkg != this->Makefile->FindPackageModuleStack.rend(); ++pkg) {
- std::string varName = *pkg + "_ROOT";
- paths.AddCMakePrefixPath(varName);
- paths.AddEnvPrefixPath(varName);
+ // Add the PACKAGE_ROOT_PATH from each enclosing find_package call.
+ for (std::vector<std::string> const& pkgPaths :
+ cmReverseRange(this->Makefile->FindPackageRootPathStack)) {
+ paths.AddPrefixPaths(pkgPaths);
}
paths.AddSuffixes(this->SearchPathSuffixes);
@@ -226,8 +216,8 @@ void cmFindBase::FillCMakeVariablePath()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::CMake];
- // Add CMake varibles of the same name as the previous environment
- // varibles CMAKE_*_PATH to be used most of the time with -D
+ // Add CMake variables of the same name as the previous environment
+ // variables CMAKE_*_PATH to be used most of the time with -D
// command line options
std::string var = "CMAKE_";
var += this->CMakePathName;
@@ -281,10 +271,8 @@ void cmFindBase::FillUserHintsPath()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints];
- for (std::vector<std::string>::const_iterator p =
- this->UserHintsArgs.begin();
- p != this->UserHintsArgs.end(); ++p) {
- paths.AddUserPath(*p);
+ for (std::string const& p : this->UserHintsArgs) {
+ paths.AddUserPath(p);
}
paths.AddSuffixes(this->SearchPathSuffixes);
}
@@ -293,10 +281,8 @@ void cmFindBase::FillUserGuessPath()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess];
- for (std::vector<std::string>::const_iterator p =
- this->UserGuessArgs.begin();
- p != this->UserGuessArgs.end(); ++p) {
- paths.AddUserPath(*p);
+ for (std::string const& p : this->UserGuessArgs) {
+ paths.AddUserPath(p);
}
paths.AddSuffixes(this->SearchPathSuffixes);
}
@@ -335,7 +321,7 @@ bool cmFindBase::CheckForVariableInCache()
cmState* state = this->Makefile->GetState();
const char* cacheEntry = state->GetCacheEntryValue(this->VariableName);
bool found = !cmSystemTools::IsNOTFOUND(cacheValue);
- bool cached = cacheEntry != CM_NULLPTR;
+ bool cached = cacheEntry != nullptr;
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
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx
index 4ef0f3ec1..954558f4d 100644
--- a/Source/cmFindCommon.cxx
+++ b/Source/cmFindCommon.cxx
@@ -6,6 +6,7 @@
#include <string.h>
#include <utility>
+#include "cmAlgorithms.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
@@ -48,15 +49,13 @@ cmFindCommon::cmFindCommon()
this->InitializeSearchPathGroups();
}
-cmFindCommon::~cmFindCommon()
-{
-}
+cmFindCommon::~cmFindCommon() = default;
void cmFindCommon::InitializeSearchPathGroups()
{
std::vector<PathLabel>* labels;
- // Define the varoius different groups of path types
+ // Define the various different groups of path types
// All search paths
labels = &this->PathGroupLabelMap[PathGroup::All];
@@ -71,7 +70,7 @@ void cmFindCommon::InitializeSearchPathGroups()
// Define the search group order
this->PathGroupOrder.push_back(PathGroup::All);
- // Create the idividual labeld search paths
+ // Create the individual labeled search paths
this->LabeledPaths.insert(
std::make_pair(PathLabel::PackageRoot, cmSearchPath(this)));
this->LabeledPaths.insert(
@@ -88,13 +87,6 @@ void cmFindCommon::InitializeSearchPathGroups()
std::make_pair(PathLabel::Guess, cmSearchPath(this)));
}
-void cmFindCommon::SelectDefaultNoPackageRootPath()
-{
- if (!this->Makefile->IsOn("__UNDOCUMENTED_CMAKE_FIND_PACKAGE_ROOT")) {
- this->NoPackageRootPath = true;
- }
-}
-
void cmFindCommon::SelectDefaultRootPathMode()
{
// Check the policy variable for this find command type.
@@ -155,10 +147,9 @@ void cmFindCommon::SelectDefaultMacMode()
void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
{
#if 0
- for(std::vector<std::string>::const_iterator i = paths.begin();
- i != paths.end(); ++i)
+ for(std::string const& p : paths)
{
- fprintf(stderr, "[%s]\n", i->c_str());
+ fprintf(stderr, "[%s]\n", p.c_str());
}
#endif
// Short-circuit if there is nothing to do.
@@ -186,17 +177,16 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
cmSystemTools::ExpandListArgument(rootPath, roots);
}
if (sysrootCompile) {
- roots.push_back(sysrootCompile);
+ roots.emplace_back(sysrootCompile);
}
if (sysrootLink) {
- roots.push_back(sysrootLink);
+ roots.emplace_back(sysrootLink);
}
if (sysroot) {
- roots.push_back(sysroot);
+ roots.emplace_back(sysroot);
}
- for (std::vector<std::string>::iterator ri = roots.begin();
- ri != roots.end(); ++ri) {
- cmSystemTools::ConvertToUnixSlashes(*ri);
+ for (std::string& r : roots) {
+ cmSystemTools::ConvertToUnixSlashes(r);
}
const char* stagePrefix =
@@ -206,24 +196,22 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& 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) {
+ for (std::string const& r : roots) {
+ for (std::string const& up : unrootedPaths) {
// 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, *ri) ||
- (stagePrefix && cmSystemTools::IsSubDirectory(*ui, stagePrefix))) {
- rootedDir = *ui;
- } else if (!ui->empty() && (*ui)[0] != '~') {
+ if (cmSystemTools::IsSubDirectory(up, r) ||
+ (stagePrefix && cmSystemTools::IsSubDirectory(up, stagePrefix))) {
+ rootedDir = up;
+ } else if (!up.empty() && up[0] != '~') {
// Start with the new root.
- rootedDir = *ri;
+ rootedDir = r;
rootedDir += "/";
// Append the original path with its old root removed.
- rootedDir += cmSystemTools::SplitPathRootComponent(*ui);
+ rootedDir += cmSystemTools::SplitPathRootComponent(up);
}
// Store the new path.
@@ -234,7 +222,7 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths)
// If searching both rooted and unrooted paths add the original
// paths again.
if (this->FindRootPathMode == RootPathModeBoth) {
- paths.insert(paths.end(), unrootedPaths.begin(), unrootedPaths.end());
+ cmAppend(paths, unrootedPaths);
}
}
@@ -242,22 +230,21 @@ void cmFindCommon::GetIgnoredPaths(std::vector<std::string>& ignore)
{
// null-terminated list of paths.
static const char* paths[] = { "CMAKE_SYSTEM_IGNORE_PATH",
- "CMAKE_IGNORE_PATH", CM_NULLPTR };
+ "CMAKE_IGNORE_PATH", nullptr };
// 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 == CM_NULLPTR) || (strlen(ignorePath) == 0)) {
+ if ((ignorePath == nullptr) || (strlen(ignorePath) == 0)) {
continue;
}
cmSystemTools::ExpandListArgument(ignorePath, ignore);
}
- for (std::vector<std::string>::iterator i = ignore.begin();
- i != ignore.end(); ++i) {
- cmSystemTools::ConvertToUnixSlashes(*i);
+ for (std::string& i : ignore) {
+ cmSystemTools::ConvertToUnixSlashes(i);
}
}
@@ -305,13 +292,13 @@ void cmFindCommon::AddPathSuffix(std::string const& arg)
if (suffix.empty()) {
return;
}
- if (suffix[0] == '/') {
+ if (suffix.front() == '/') {
suffix = suffix.substr(1);
}
if (suffix.empty()) {
return;
}
- if (suffix[suffix.size() - 1] == '/') {
+ if (suffix.back() == '/') {
suffix = suffix.substr(0, suffix.size() - 1);
}
if (suffix.empty()) {
@@ -319,12 +306,12 @@ void cmFindCommon::AddPathSuffix(std::string const& arg)
}
// Store the suffix.
- this->SearchPathSuffixes.push_back(suffix);
+ this->SearchPathSuffixes.push_back(std::move(suffix));
}
void AddTrailingSlash(std::string& s)
{
- if (!s.empty() && *s.rbegin() != '/') {
+ if (!s.empty() && s.back() != '/') {
s += '/';
}
}
@@ -334,12 +321,11 @@ void cmFindCommon::ComputeFinalPaths()
std::set<std::string> ignored;
this->GetIgnoredPaths(ignored);
- // Combine the seperate path types, filtering out ignores
+ // Combine the separate path types, filtering out ignores
this->SearchPaths.clear();
std::vector<PathLabel>& allLabels = this->PathGroupLabelMap[PathGroup::All];
- for (std::vector<PathLabel>::const_iterator l = allLabels.begin();
- l != allLabels.end(); ++l) {
- this->LabeledPaths[*l].ExtractWithout(ignored, this->SearchPaths);
+ for (PathLabel const& l : allLabels) {
+ this->LabeledPaths[l].ExtractWithout(ignored, this->SearchPaths);
}
// Expand list of paths inside all search roots.
diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h
index 72dcd355d..89ff1741d 100644
--- a/Source/cmFindCommon.h
+++ b/Source/cmFindCommon.h
@@ -3,7 +3,7 @@
#ifndef cmFindCommon_h
#define cmFindCommon_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
#include <set>
@@ -25,7 +25,7 @@ class cmFindCommon : public cmCommand
{
public:
cmFindCommon();
- ~cmFindCommon() CM_OVERRIDE;
+ ~cmFindCommon() override;
protected:
friend class cmSearchPath;
@@ -84,9 +84,6 @@ protected:
/** Compute final search path list (reroot + trailing slash). */
void ComputeFinalPaths();
- /** Decide whether to enable the PACKAGE_ROOT search entries. */
- void SelectDefaultNoPackageRootPath();
-
/** Compute the current default root path mode. */
void SelectDefaultRootPathMode();
@@ -112,7 +109,7 @@ protected:
std::vector<std::string> SearchPathSuffixes;
- std::map<PathGroup, std::vector<PathLabel> > PathGroupLabelMap;
+ std::map<PathGroup, std::vector<PathLabel>> PathGroupLabelMap;
std::vector<PathGroup> PathGroupOrder;
std::map<std::string, PathLabel> PathLabelStringMap;
std::map<PathLabel, cmSearchPath> LabeledPaths;
diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h
index bf57fecd3..430944942 100644
--- a/Source/cmFindFileCommand.h
+++ b/Source/cmFindFileCommand.h
@@ -3,7 +3,7 @@
#ifndef cmFindFileCommand_h
#define cmFindFileCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmFindPathCommand.h"
@@ -24,7 +24,7 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFindFileCommand; }
+ cmCommand* Clone() override { return new cmFindFileCommand; }
};
#endif
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index a6b1a2155..73d602de7 100644
--- a/Source/cmFindLibraryCommand.cxx
+++ b/Source/cmFindLibraryCommand.cxx
@@ -7,6 +7,7 @@
#include <set>
#include <stdio.h>
#include <string.h>
+#include <utility>
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
@@ -68,8 +69,8 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn,
this->AddArchitecturePaths("x32");
}
- std::string library = this->FindLibrary();
- if (library != "") {
+ std::string const library = this->FindLibrary();
+ if (!library.empty()) {
// Save the value in the cache
this->Makefile->AddCacheDefinition(this->VariableName, library.c_str(),
this->VariableDocumentation.c_str(),
@@ -87,9 +88,8 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
{
std::vector<std::string> original;
original.swap(this->SearchPaths);
- for (std::vector<std::string>::const_iterator i = original.begin();
- i != original.end(); ++i) {
- this->AddArchitecturePath(*i, 0, suffix);
+ for (std::string const& o : original) {
+ this->AddArchitecturePath(o, 0, suffix);
}
}
@@ -151,7 +151,7 @@ void cmFindLibraryCommand::AddArchitecturePath(
if (use_dirX) {
dirX += "/";
- this->SearchPaths.push_back(dirX);
+ this->SearchPaths.push_back(std::move(dirX));
}
if (use_dir) {
@@ -199,13 +199,9 @@ struct cmFindLibraryHelper
// Current names under consideration.
struct Name
{
- bool TryRaw;
+ bool TryRaw = false;
std::string Raw;
cmsys::RegularExpression Regex;
- Name()
- : TryRaw(false)
- {
- }
};
std::vector<Name> Names;
@@ -237,9 +233,9 @@ cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf)
this->GG = this->Makefile->GetGlobalGenerator();
// Collect the list of library name prefixes/suffixes to try.
- const char* prefixes_list =
+ std::string const& prefixes_list =
this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
- const char* suffixes_list =
+ std::string const& suffixes_list =
this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_SUFFIXES");
cmSystemTools::ExpandListArgument(prefixes_list, this->Prefixes, true);
cmSystemTools::ExpandListArgument(suffixes_list, this->Suffixes, true);
@@ -254,15 +250,14 @@ cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf)
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;
+ for (char ch : in) {
if (ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '\\' ||
ch == '.' || ch == '*' || ch == '+' || ch == '?' || ch == '-' ||
ch == '^' || ch == '$') {
out += "\\";
}
#if defined(_WIN32) || defined(__APPLE__)
- out += tolower(ch);
+ out += static_cast<char>(tolower(ch));
#else
out += ch;
#endif
@@ -276,23 +271,20 @@ void cmFindLibraryHelper::RegexFromList(std::string& out,
// 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) {
+ for (std::string const& s : in) {
// Separate from previous item.
out += sep;
sep = "|";
// Append this item.
- this->RegexFromLiteral(out, *si);
+ this->RegexFromLiteral(out, s);
}
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;
+ for (std::string suffix : this->Suffixes) {
if (name.length() <= suffix.length()) {
continue;
}
@@ -328,7 +320,7 @@ void cmFindLibraryHelper::AddName(std::string const& name)
}
regex += "$";
entry.Regex.compile(regex.c_str());
- this->Names.push_back(entry);
+ this->Names.push_back(std::move(entry));
}
void cmFindLibraryHelper::SetName(std::string const& name)
@@ -339,9 +331,8 @@ void cmFindLibraryHelper::SetName(std::string const& name)
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)) {
+ for (Name& i : this->Names) {
+ if (this->CheckDirectoryForName(path, i)) {
return true;
}
}
@@ -359,7 +350,7 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path,
if (name.TryRaw) {
this->TestPath = path;
this->TestPath += name.Raw;
- if (cmSystemTools::FileExists(this->TestPath.c_str(), true)) {
+ if (cmSystemTools::FileExists(this->TestPath, true)) {
this->BestPath = cmSystemTools::CollapseFullPath(this->TestPath);
cmSystemTools::ConvertToUnixSlashes(this->BestPath);
return true;
@@ -376,9 +367,7 @@ bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path,
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;
+ for (std::string const& origName : files) {
#if defined(_WIN32) || defined(__APPLE__)
std::string testName = cmSystemTools::LowerCase(origName);
#else
@@ -430,14 +419,12 @@ 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);
+ for (std::string const& n : this->Names) {
+ helper.AddName(n);
}
// Search every directory.
- for (std::vector<std::string>::const_iterator p = this->SearchPaths.begin();
- p != this->SearchPaths.end(); ++p) {
- if (helper.CheckDirectory(*p)) {
+ for (std::string const& sp : this->SearchPaths) {
+ if (helper.CheckDirectory(sp)) {
return helper.BestPath;
}
}
@@ -449,16 +436,13 @@ 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) {
+ for (std::string const& n : this->Names) {
// Switch to searching for this name.
- helper.SetName(*ni);
+ helper.SetName(n);
// Search every directory.
- for (std::vector<std::string>::const_iterator p =
- this->SearchPaths.begin();
- p != this->SearchPaths.end(); ++p) {
- if (helper.CheckDirectory(*p)) {
+ for (std::string const& sp : this->SearchPaths) {
+ if (helper.CheckDirectory(sp)) {
return helper.BestPath;
}
}
@@ -479,12 +463,10 @@ 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;
+ for (std::string const& d : this->SearchPaths) {
+ for (std::string const& n : this->Names) {
+ fwPath = d;
+ fwPath += n;
fwPath += ".framework";
if (cmSystemTools::FileIsDirectory(fwPath)) {
return cmSystemTools::CollapseFullPath(fwPath);
@@ -500,13 +482,10 @@ 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;
+ for (std::string const& n : this->Names) {
+ for (std::string const& d : this->SearchPaths) {
+ fwPath = d;
+ fwPath += n;
fwPath += ".framework";
if (cmSystemTools::FileIsDirectory(fwPath)) {
return cmSystemTools::CollapseFullPath(fwPath);
diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h
index 9d38eab33..fb8a7002d 100644
--- a/Source/cmFindLibraryCommand.h
+++ b/Source/cmFindLibraryCommand.h
@@ -3,7 +3,7 @@
#ifndef cmFindLibraryCommand_h
#define cmFindLibraryCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -27,14 +27,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFindLibraryCommand; }
+ cmCommand* Clone() override { return new cmFindLibraryCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
void AddArchitecturePaths(const char* suffix);
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 7797700d6..171fa77dc 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -13,6 +13,7 @@
#include <deque>
#include <functional>
#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <string.h>
@@ -20,16 +21,17 @@
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmPolicies.h"
+#include "cmRange.h"
#include "cmSearchPath.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmVersion.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
#if defined(__HAIKU__)
-#include <FindDirectory.h>
-#include <StorageDefs.h>
+# include <FindDirectory.h>
+# include <StorageDefs.h>
#endif
class cmExecutionStatus;
@@ -94,6 +96,7 @@ cmFindPackageCommand::cmFindPackageCommand()
this->UseLib32Paths = false;
this->UseLib64Paths = false;
this->UseLibx32Paths = false;
+ this->UseRealPath = false;
this->PolicyScope = true;
this->VersionMajor = 0;
this->VersionMinor = 0;
@@ -110,6 +113,8 @@ cmFindPackageCommand::cmFindPackageCommand()
this->SortOrder = None;
this->SortDirection = Asc;
this->AppendSearchPathGroups();
+
+ this->DeprecatedFindModules["Qt"] = cmPolicies::CMP0084;
}
void cmFindPackageCommand::AppendSearchPathGroups()
@@ -192,6 +197,11 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
this->NoSystemRegistry = true;
}
+ // Check whether we should resolve symlinks when finding packages
+ if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS")) {
+ this->UseRealPath = true;
+ }
+
// Check if Sorting should be enabled
if (const char* so =
this->Makefile->GetDefinition("CMAKE_FIND_PACKAGE_SORT_ORDER")) {
@@ -209,8 +219,6 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
this->SortDirection = strcmp(sd, "ASC") == 0 ? Asc : Dec;
}
- this->SelectDefaultNoPackageRootPath();
-
// Find the current root path mode.
this->SelectDefaultRootPathMode();
@@ -225,7 +233,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
std::set<std::string> optionalComponents;
// Always search directly in a generated path.
- this->SearchPathSuffixes.push_back("");
+ this->SearchPathSuffixes.emplace_back();
// Parse the arguments.
enum Doing
@@ -338,7 +346,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
this->Configs.push_back(args[i]);
- } else if (!haveVersion && version.find(args[i].c_str())) {
+ } else if (!haveVersion && version.find(args[i])) {
haveVersion = true;
this->Version = args[i];
} else {
@@ -367,14 +375,12 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
if (!this->UseFindModules && !this->UseConfigFiles) {
std::ostringstream 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";
+ for (unsigned int si : moduleArgs) {
+ 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";
+ for (unsigned int si : configArgs) {
+ e << " " << args[si] << "\n";
}
e << "The options are incompatible.";
this->SetError(e.str());
@@ -385,7 +391,8 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
if (this->Version.empty() && this->VersionExact) {
this->VersionExact = false;
this->Makefile->IssueMessage(
- cmake::AUTHOR_WARNING, "Ignoring EXACT since no version is requested.");
+ MessageType::AUTHOR_WARNING,
+ "Ignoring EXACT since no version is requested.");
}
if (this->Version.empty() || components.empty()) {
@@ -456,58 +463,122 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
return true;
}
+ {
+ // Allocate a PACKAGE_ROOT_PATH for the current find_package call.
+ this->Makefile->FindPackageRootPathStack.emplace_back();
+ std::vector<std::string>& rootPaths =
+ this->Makefile->FindPackageRootPathStack.back();
+
+ // Add root paths from <PackageName>_ROOT CMake and environment variables,
+ // subject to CMP0074.
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0074)) {
+ case cmPolicies::WARN:
+ this->Makefile->MaybeWarnCMP0074(this->Name);
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ // OLD behavior is to ignore the <pkg>_ROOT variables.
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0074));
+ break;
+ case cmPolicies::NEW: {
+ // NEW behavior is to honor the <pkg>_ROOT variables.
+ std::string const rootVar = this->Name + "_ROOT";
+ if (const char* pkgRoot = this->Makefile->GetDefinition(rootVar)) {
+ cmSystemTools::ExpandListArgument(pkgRoot, rootPaths, false);
+ }
+ cmSystemTools::GetPath(rootPaths, rootVar.c_str());
+ } break;
+ }
+ }
+
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;
+ // See if there is a Find<PackageName>.cmake module.
+ bool loadedPackage = false;
+ if (this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) {
+ if (this->UseConfigFiles && this->FindPackageUsingConfigMode()) {
+ loadedPackage = true;
+ } else {
+ if (this->FindPackageUsingModuleMode()) {
+ loadedPackage = true;
+ } else {
+ // The package was not loaded. Report errors.
+ if (HandlePackageMode(HandlePackageModeType::Module)) {
+ loadedPackage = true;
+ }
+ }
}
- if (foundModule) {
- this->AppendSuccessInformation();
- return true;
+ } else {
+ if (this->UseFindModules && this->FindPackageUsingModuleMode()) {
+ loadedPackage = true;
+ } else {
+ // Handle CMAKE_FIND_PACKAGE_WARN_NO_MODULE (warn when CONFIG mode is
+ // implicitly assumed)
+ if (this->UseFindModules && this->UseConfigFiles &&
+ this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE")) {
+ std::ostringstream 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(MessageType::AUTHOR_WARNING, aw.str());
+ }
+
+ if (this->FindPackageUsingConfigMode()) {
+ loadedPackage = true;
+ }
}
}
- if (this->UseFindModules && this->UseConfigFiles &&
- this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE")) {
- std::ostringstream 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->AppendSuccessInformation();
+ return loadedPackage;
+}
+
+bool cmFindPackageCommand::FindPackageUsingModuleMode()
+{
+ bool foundModule = false;
+ if (!this->FindModule(foundModule)) {
+ return false;
+ }
+ return foundModule;
+}
+
+bool cmFindPackageCommand::FindPackageUsingConfigMode()
+{
this->Variable = this->Name;
this->Variable += "_DIR";
@@ -518,15 +589,14 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
// 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;
+ for (std::string const& n : this->Names) {
+ std::string config = n;
config += "Config.cmake";
this->Configs.push_back(config);
- config = cmSystemTools::LowerCase(*ni);
+ config = cmSystemTools::LowerCase(n);
config += "-config.cmake";
- this->Configs.push_back(config);
+ this->Configs.push_back(std::move(config));
}
}
@@ -540,9 +610,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args,
this->IgnoredPaths.insert(ignored.begin(), ignored.end());
// Find and load the package.
- bool result = this->HandlePackageMode();
- this->AppendSuccessInformation();
- return result;
+ return this->HandlePackageMode(HandlePackageModeType::Config);
}
void cmFindPackageCommand::SetModuleVariables(const std::string& components)
@@ -592,9 +660,6 @@ void cmFindPackageCommand::SetModuleVariables(const std::string& components)
exact += "_FIND_VERSION_EXACT";
this->AddFindDefinition(exact, this->VersionExact ? "1" : "0");
}
-
- // Push on to the pacakge stack
- this->Makefile->FindPackageModuleStack.push_back(this->Name);
}
void cmFindPackageCommand::AddFindDefinition(const std::string& var,
@@ -611,14 +676,12 @@ void cmFindPackageCommand::AddFindDefinition(const std::string& var,
void cmFindPackageCommand::RestoreFindDefinitions()
{
- for (std::map<std::string, OriginalDef>::iterator i =
- this->OriginalDefs.begin();
- i != this->OriginalDefs.end(); ++i) {
- OriginalDef const& od = i->second;
+ for (auto const& i : this->OriginalDefs) {
+ OriginalDef const& od = i.second;
if (od.exists) {
- this->Makefile->AddDefinition(i->first, od.value.c_str());
+ this->Makefile->AddDefinition(i.first, od.value.c_str());
} else {
- this->Makefile->RemoveDefinition(i->first);
+ this->Makefile->RemoveDefinition(i.first);
}
}
}
@@ -628,22 +691,46 @@ bool cmFindPackageCommand::FindModule(bool& found)
std::string module = "Find";
module += this->Name;
module += ".cmake";
- std::string mfile = this->Makefile->GetModulesFile(module.c_str());
+ bool system = false;
+ std::string mfile = this->Makefile->GetModulesFile(module, system);
if (!mfile.empty()) {
+ if (system) {
+ auto it = this->DeprecatedFindModules.find(this->Name);
+ if (it != this->DeprecatedFindModules.end()) {
+ cmPolicies::PolicyStatus status =
+ this->Makefile->GetPolicyStatus(it->second);
+ switch (status) {
+ case cmPolicies::WARN: {
+ std::ostringstream e;
+ e << cmPolicies::GetPolicyWarning(it->second) << "\n";
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
+ CM_FALLTHROUGH;
+ }
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ return true;
+ }
+ }
+ }
+
// 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);
+ bool result = this->ReadListFile(mfile, DoPolicyScope);
this->Makefile->RemoveDefinition(var);
return result;
}
return true;
}
-bool cmFindPackageCommand::HandlePackageMode()
+bool cmFindPackageCommand::HandlePackageMode(
+ HandlePackageModeType handlePackageModeType)
{
this->ConsideredConfigs.clear();
@@ -665,7 +752,7 @@ bool cmFindPackageCommand::HandlePackageMode()
cmSystemTools::ConvertToUnixSlashes(dir);
// Treat relative paths with respect to the current source dir.
- if (!cmSystemTools::FileIsFullPath(dir.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(dir)) {
dir = "/" + dir;
dir = this->Makefile->GetCurrentSourceDirectory() + dir;
}
@@ -686,7 +773,8 @@ bool cmFindPackageCommand::HandlePackageMode()
// Sanity check.
if (fileFound && this->FileFound.empty()) {
this->Makefile->IssueMessage(
- cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!");
+ MessageType::INTERNAL_ERROR,
+ "fileFound is true but FileFound is empty!");
fileFound = false;
}
}
@@ -718,7 +806,7 @@ bool cmFindPackageCommand::HandlePackageMode()
this->StoreVersionFound();
// Parse the configuration file.
- if (this->ReadListFile(this->FileFound.c_str(), DoPolicyScope)) {
+ if (this->ReadListFile(this->FileFound, DoPolicyScope)) {
// The package has been found.
found = true;
@@ -737,12 +825,20 @@ bool cmFindPackageCommand::HandlePackageMode()
}
}
+ if (this->UseFindModules && !found &&
+ handlePackageModeType == HandlePackageModeType::Config &&
+ this->Makefile->IsOn("CMAKE_FIND_PACKAGE_PREFER_CONFIG")) {
+ // Config mode failed. Allow Module case.
+ result = false;
+ }
+
// package not found
if (result && !found) {
// warn if package required or neither quiet nor in config mode
if (this->Required ||
- !(this->Quiet || (this->UseConfigFiles && !this->UseFindModules &&
- this->ConsideredConfigs.empty()))) {
+ !(this->Quiet ||
+ (this->UseConfigFiles && !this->UseFindModules &&
+ this->ConsideredConfigs.empty()))) {
// The variable is not set.
std::ostringstream e;
std::ostringstream aw;
@@ -768,10 +864,10 @@ bool cmFindPackageCommand::HandlePackageMode()
<< " requested version \"" << this->Version << "\".\n"
<< "The following configuration files were considered but not "
"accepted:\n";
- for (std::vector<ConfigFileInfo>::const_iterator i =
- this->ConsideredConfigs.begin();
- i != duplicate_end; ++i) {
- e << " " << i->filename << ", version: " << i->version << "\n";
+
+ for (ConfigFileInfo const& info :
+ cmMakeRange(this->ConsideredConfigs.cbegin(), duplicate_end)) {
+ e << " " << info.filename << ", version: " << info.version << "\n";
}
} else {
std::string requestedVersionString;
@@ -787,8 +883,9 @@ bool cmFindPackageCommand::HandlePackageMode()
<< ".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";
+ << this->Name
+ << "\", "
+ "but CMake did not find one.\n";
}
if (this->Configs.size() == 1) {
@@ -809,8 +906,9 @@ bool cmFindPackageCommand::HandlePackageMode()
<< "\" 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.";
+ << 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 "
@@ -834,14 +932,15 @@ bool cmFindPackageCommand::HandlePackageMode()
}
}
- this->Makefile->IssueMessage(
- this->Required ? cmake::FATAL_ERROR : cmake::WARNING, e.str());
+ this->Makefile->IssueMessage(this->Required ? MessageType::FATAL_ERROR
+ : MessageType::WARNING,
+ e.str());
if (this->Required) {
cmSystemTools::SetFatalErrorOccured();
}
if (!aw.str().empty()) {
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, aw.str());
}
}
// output result if in config mode but not in quiet mode
@@ -849,7 +948,7 @@ bool cmFindPackageCommand::HandlePackageMode()
std::ostringstream aw;
aw << "Could NOT find " << this->Name << " (missing: " << this->Name
<< "_DIR)";
- this->Makefile->DisplayStatus(aw.str().c_str(), -1);
+ this->Makefile->DisplayStatus(aw.str(), -1);
}
}
@@ -874,13 +973,11 @@ bool cmFindPackageCommand::HandlePackageMode()
std::string consideredVersions;
const char* sep = "";
- for (std::vector<ConfigFileInfo>::const_iterator i =
- this->ConsideredConfigs.begin();
- i != this->ConsideredConfigs.end(); ++i) {
+ for (ConfigFileInfo const& i : this->ConsideredConfigs) {
consideredConfigFiles += sep;
consideredVersions += sep;
- consideredConfigFiles += i->filename;
- consideredVersions += i->version;
+ consideredConfigFiles += i.filename;
+ consideredVersions += i.version;
sep = ";";
}
@@ -946,9 +1043,8 @@ bool cmFindPackageCommand::FindConfig()
bool cmFindPackageCommand::FindPrefixedConfig()
{
std::vector<std::string> const& prefixes = this->SearchPaths;
- for (std::vector<std::string>::const_iterator pi = prefixes.begin();
- pi != prefixes.end(); ++pi) {
- if (this->SearchPrefix(*pi)) {
+ for (std::string const& p : prefixes) {
+ if (this->SearchPrefix(p)) {
return true;
}
}
@@ -958,9 +1054,8 @@ bool cmFindPackageCommand::FindPrefixedConfig()
bool cmFindPackageCommand::FindFrameworkConfig()
{
std::vector<std::string> const& prefixes = this->SearchPaths;
- for (std::vector<std::string>::const_iterator i = prefixes.begin();
- i != prefixes.end(); ++i) {
- if (this->SearchFrameworkPrefix(*i)) {
+ for (std::string const& p : prefixes) {
+ if (this->SearchFrameworkPrefix(p)) {
return true;
}
}
@@ -970,16 +1065,16 @@ bool cmFindPackageCommand::FindFrameworkConfig()
bool cmFindPackageCommand::FindAppBundleConfig()
{
std::vector<std::string> const& prefixes = this->SearchPaths;
- for (std::vector<std::string>::const_iterator i = prefixes.begin();
- i != prefixes.end(); ++i) {
- if (this->SearchAppBundlePrefix(*i)) {
+ for (std::string const& p : prefixes) {
+ if (this->SearchAppBundlePrefix(p)) {
return true;
}
}
return false;
}
-bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr)
+bool cmFindPackageCommand::ReadListFile(const std::string& f,
+ PolicyScopeRule psr)
{
const bool noPolicyScope = !this->PolicyScope || psr == NoPolicyScope;
if (this->Makefile->ReadDependentFile(f, noPolicyScope)) {
@@ -1086,7 +1181,7 @@ void cmFindPackageCommand::AppendSuccessInformation()
this->RestoreFindDefinitions();
// Pop the package stack
- this->Makefile->FindPackageModuleStack.pop_back();
+ this->Makefile->FindPackageRootPathStack.pop_back();
}
void cmFindPackageCommand::ComputePrefixes()
@@ -1126,16 +1221,14 @@ void cmFindPackageCommand::FillPrefixesPackageRoot()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::PackageRoot];
- // Add package specific search prefixes
- // NOTE: This should be using const_reverse_iterator but HP aCC and
- // Oracle sunCC both currently have standard library issues
- // with the reverse iterator APIs.
- for (std::deque<std::string>::reverse_iterator pkg =
- this->Makefile->FindPackageModuleStack.rbegin();
- pkg != this->Makefile->FindPackageModuleStack.rend(); ++pkg) {
- std::string varName = *pkg + "_ROOT";
- paths.AddCMakePath(varName);
- paths.AddEnvPath(varName);
+ // Add the PACKAGE_ROOT_PATH from each enclosing find_package call.
+ for (std::deque<std::vector<std::string>>::const_reverse_iterator pkgPaths =
+ this->Makefile->FindPackageRootPathStack.rbegin();
+ pkgPaths != this->Makefile->FindPackageRootPathStack.rend();
+ ++pkgPaths) {
+ for (std::string const& path : *pkgPaths) {
+ paths.AddPath(path);
+ }
}
}
@@ -1171,14 +1264,12 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment()
// working directory.
std::vector<std::string> tmp;
cmSystemTools::GetPath(tmp);
- for (std::vector<std::string>::iterator i = tmp.begin(); i != tmp.end();
- ++i) {
+ for (std::string const& i : tmp) {
// If the path is a PREFIX/bin case then add its parent instead.
- if ((cmHasLiteralSuffix(*i, "/bin")) ||
- (cmHasLiteralSuffix(*i, "/sbin"))) {
- paths.AddPath(cmSystemTools::GetFilenamePath(*i));
+ if ((cmHasLiteralSuffix(i, "/bin")) || (cmHasLiteralSuffix(i, "/sbin"))) {
+ paths.AddPath(cmSystemTools::GetFilenamePath(i));
} else {
- paths.AddPath(*i);
+ paths.AddPath(i);
}
}
}
@@ -1220,14 +1311,14 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry()
}
#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <windows.h>
+# include <windows.h>
// 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
+# 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.
@@ -1296,9 +1387,8 @@ void cmFindPackageCommand::LoadPackageRegistryWin(bool user, unsigned int view,
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());
+ for (std::wstring const& v : bad) {
+ RegDeleteValueW(hKey, v.c_str());
}
RegCloseKey(hKey);
}
@@ -1319,7 +1409,10 @@ public:
cmSystemTools::RemoveFile(this->File);
}
}
- void Release() { this->File = CM_NULLPTR; }
+ cmFindPackageCommandHoldFile(const cmFindPackageCommandHoldFile&) = delete;
+ cmFindPackageCommandHoldFile& operator=(
+ const cmFindPackageCommandHoldFile&) = delete;
+ void Release() { this->File = nullptr; }
};
void cmFindPackageCommand::LoadPackageRegistryDir(std::string const& dir,
@@ -1359,10 +1452,10 @@ bool cmFindPackageCommand::CheckPackageRegistryEntry(const std::string& fname,
cmSearchPath& outPaths)
{
// Parse the content of one package registry entry.
- if (cmSystemTools::FileIsFullPath(fname.c_str())) {
+ if (cmSystemTools::FileIsFullPath(fname)) {
// The first line in the stream is the full path to a file or
// directory containing the package.
- if (cmSystemTools::FileExists(fname.c_str())) {
+ if (cmSystemTools::FileExists(fname)) {
// The path exists. Look for the package here.
if (!cmSystemTools::FileIsDirectory(fname)) {
outPaths.AddPath(cmSystemTools::GetFilenamePath(fname));
@@ -1395,10 +1488,8 @@ void cmFindPackageCommand::FillPrefixesUserGuess()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::Guess];
- for (std::vector<std::string>::const_iterator p =
- this->UserGuessArgs.begin();
- p != this->UserGuessArgs.end(); ++p) {
- paths.AddUserPath(*p);
+ for (std::string const& p : this->UserGuessArgs) {
+ paths.AddUserPath(p);
}
}
@@ -1406,24 +1497,20 @@ void cmFindPackageCommand::FillPrefixesUserHints()
{
cmSearchPath& paths = this->LabeledPaths[PathLabel::Hints];
- for (std::vector<std::string>::const_iterator p =
- this->UserHintsArgs.begin();
- p != this->UserHintsArgs.end(); ++p) {
- paths.AddUserPath(*p);
+ for (std::string const& p : this->UserHintsArgs) {
+ paths.AddUserPath(p);
}
}
bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
{
- assert(!dir.empty() && dir[dir.size() - 1] == '/');
+ assert(!dir.empty() && dir.back() == '/');
// Check each path suffix on this directory.
- for (std::vector<std::string>::const_iterator si =
- this->SearchPathSuffixes.begin();
- si != this->SearchPathSuffixes.end(); ++si) {
+ for (std::string const& s : this->SearchPathSuffixes) {
std::string d = dir;
- if (!si->empty()) {
- d += *si;
+ if (!s.empty()) {
+ d += s;
d += "/";
}
if (this->CheckDirectory(d)) {
@@ -1435,7 +1522,7 @@ bool cmFindPackageCommand::SearchDirectory(std::string const& dir)
bool cmFindPackageCommand::CheckDirectory(std::string const& dir)
{
- assert(!dir.empty() && dir[dir.size() - 1] == '/');
+ assert(!dir.empty() && dir.back() == '/');
// Look for the file in this directory.
std::string d = dir.substr(0, dir.size() - 1);
@@ -1454,16 +1541,18 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
return false;
}
- for (std::vector<std::string>::const_iterator ci = this->Configs.begin();
- ci != this->Configs.end(); ++ci) {
+ for (std::string const& c : this->Configs) {
file = dir;
file += "/";
- file += *ci;
+ file += c;
if (this->DebugMode) {
fprintf(stderr, "Checking file [%s]\n", file.c_str());
}
- if (cmSystemTools::FileExists(file.c_str(), true) &&
- this->CheckVersion(file)) {
+ if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) {
+ // Allow resolving symlinks when the config file is found through a link
+ if (this->UseRealPath) {
+ file = cmSystemTools::GetRealPath(file);
+ }
return true;
}
}
@@ -1483,7 +1572,7 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
// Look for foo-config-version.cmake
std::string version_file = version_file_base;
version_file += "-version.cmake";
- if (!haveResult && cmSystemTools::FileExists(version_file.c_str(), true)) {
+ if (!haveResult && cmSystemTools::FileExists(version_file, true)) {
result = this->CheckVersionFile(version_file, version);
haveResult = true;
}
@@ -1491,7 +1580,7 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
// Look for fooConfigVersion.cmake
version_file = version_file_base;
version_file += "Version.cmake";
- if (!haveResult && cmSystemTools::FileExists(version_file.c_str(), true)) {
+ if (!haveResult && cmSystemTools::FileExists(version_file, true)) {
result = this->CheckVersionFile(version_file, version);
haveResult = true;
}
@@ -1504,7 +1593,7 @@ bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
ConfigFileInfo configFileInfo;
configFileInfo.filename = config_file;
configFileInfo.version = version;
- this->ConsideredConfigs.push_back(configFileInfo);
+ this->ConsideredConfigs.push_back(std::move(configFileInfo));
return result;
}
@@ -1542,7 +1631,7 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
// 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)) {
+ if (this->ReadListFile(version_file, NoPolicyScope)) {
// Check the output variables.
bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT");
bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE");
@@ -1623,7 +1712,7 @@ void cmFindPackageCommand::StoreVersionFound()
class cmFileListGeneratorBase
{
public:
- virtual ~cmFileListGeneratorBase() {}
+ virtual ~cmFileListGeneratorBase() = default;
protected:
bool Consider(std::string const& fullPath, cmFileList& listing);
@@ -1631,21 +1720,16 @@ protected:
private:
bool Search(cmFileList&);
virtual bool Search(std::string const& parent, cmFileList&) = 0;
- virtual CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const = 0;
+ virtual std::unique_ptr<cmFileListGeneratorBase> Clone() const = 0;
friend class cmFileList;
cmFileListGeneratorBase* SetNext(cmFileListGeneratorBase const& next);
- CM_AUTO_PTR<cmFileListGeneratorBase> Next;
+ std::unique_ptr<cmFileListGeneratorBase> Next;
};
class cmFileList
{
public:
- cmFileList()
- : First()
- , Last(CM_NULLPTR)
- {
- }
- virtual ~cmFileList() {}
+ virtual ~cmFileList() = default;
cmFileList& operator/(cmFileListGeneratorBase const& rhs)
{
if (this->Last) {
@@ -1658,7 +1742,7 @@ public:
}
bool Search()
{
- if (this->First.get()) {
+ if (this->First) {
return this->First->Search(*this);
}
return false;
@@ -1667,22 +1751,21 @@ public:
private:
virtual bool Visit(std::string const& fullPath) = 0;
friend class cmFileListGeneratorBase;
- CM_AUTO_PTR<cmFileListGeneratorBase> First;
- cmFileListGeneratorBase* Last;
+ std::unique_ptr<cmFileListGeneratorBase> First;
+ cmFileListGeneratorBase* Last = nullptr;
};
class cmFindPackageFileList : public cmFileList
{
public:
cmFindPackageFileList(cmFindPackageCommand* fpc, bool use_suffixes = true)
- : cmFileList()
- , FPC(fpc)
+ : FPC(fpc)
, UseSuffixes(use_suffixes)
{
}
private:
- bool Visit(std::string const& fullPath) CM_OVERRIDE
+ bool Visit(std::string const& fullPath) override
{
if (this->UseSuffixes) {
return this->FPC->SearchDirectory(fullPath);
@@ -1708,7 +1791,7 @@ cmFileListGeneratorBase* cmFileListGeneratorBase::SetNext(
bool cmFileListGeneratorBase::Consider(std::string const& fullPath,
cmFileList& listing)
{
- if (this->Next.get()) {
+ if (this->Next) {
return this->Next->Search(fullPath + "/", listing);
}
return listing.Visit(fullPath + "/");
@@ -1717,27 +1800,25 @@ bool cmFileListGeneratorBase::Consider(std::string const& fullPath,
class cmFileListGeneratorFixed : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorFixed(std::string const& str)
- : cmFileListGeneratorBase()
- , String(str)
+ cmFileListGeneratorFixed(std::string str)
+ : String(std::move(str))
{
}
cmFileListGeneratorFixed(cmFileListGeneratorFixed const& r)
- : cmFileListGeneratorBase()
- , String(r.String)
+ : String(r.String)
{
}
private:
std::string String;
- bool Search(std::string const& parent, cmFileList& lister) CM_OVERRIDE
+ bool Search(std::string const& parent, cmFileList& lister) override
{
std::string fullPath = parent + this->String;
return this->Consider(fullPath, lister);
}
- CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const CM_OVERRIDE
+ std::unique_ptr<cmFileListGeneratorBase> Clone() const override
{
- CM_AUTO_PTR<cmFileListGeneratorBase> g(
+ std::unique_ptr<cmFileListGeneratorBase> g(
new cmFileListGeneratorFixed(*this));
return g;
}
@@ -1747,31 +1828,28 @@ class cmFileListGeneratorEnumerate : public cmFileListGeneratorBase
{
public:
cmFileListGeneratorEnumerate(std::vector<std::string> const& v)
- : cmFileListGeneratorBase()
- , Vector(v)
+ : Vector(v)
{
}
cmFileListGeneratorEnumerate(cmFileListGeneratorEnumerate const& r)
- : cmFileListGeneratorBase()
- , Vector(r.Vector)
+ : Vector(r.Vector)
{
}
private:
std::vector<std::string> const& Vector;
- bool Search(std::string const& parent, cmFileList& lister) CM_OVERRIDE
+ bool Search(std::string const& parent, cmFileList& lister) override
{
- for (std::vector<std::string>::const_iterator i = this->Vector.begin();
- i != this->Vector.end(); ++i) {
- if (this->Consider(parent + *i, lister)) {
+ for (std::string const& i : this->Vector) {
+ if (this->Consider(parent + i, lister)) {
return true;
}
}
return false;
}
- CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const CM_OVERRIDE
+ std::unique_ptr<cmFileListGeneratorBase> Clone() const override
{
- CM_AUTO_PTR<cmFileListGeneratorBase> g(
+ std::unique_ptr<cmFileListGeneratorBase> g(
new cmFileListGeneratorEnumerate(*this));
return g;
}
@@ -1783,14 +1861,12 @@ public:
cmFileListGeneratorProject(std::vector<std::string> const& names,
cmFindPackageCommand::SortOrderType so,
cmFindPackageCommand::SortDirectionType sd)
- : cmFileListGeneratorBase()
- , Names(names)
+ : Names(names)
{
this->SetSort(so, sd);
}
cmFileListGeneratorProject(cmFileListGeneratorProject const& r)
- : cmFileListGeneratorBase()
- , Names(r.Names)
+ : Names(r.Names)
{
this->SetSort(r.SortOrder, r.SortDirection);
}
@@ -1809,7 +1885,7 @@ protected:
private:
std::vector<std::string> const& Names;
- bool Search(std::string const& parent, cmFileList& lister) CM_OVERRIDE
+ bool Search(std::string const& parent, cmFileList& lister) override
{
// Construct a list of matches.
std::vector<std::string> matches;
@@ -1820,10 +1896,9 @@ private:
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::string const& n : this->Names) {
+ if (cmsysString_strncasecmp(fname, n.c_str(), n.length()) == 0) {
+ matches.emplace_back(fname);
}
}
}
@@ -1835,17 +1910,16 @@ private:
SortDirection);
}
- for (std::vector<std::string>::const_iterator i = matches.begin();
- i != matches.end(); ++i) {
- if (this->Consider(parent + *i, lister)) {
+ for (std::string const& i : matches) {
+ if (this->Consider(parent + i, lister)) {
return true;
}
}
return false;
}
- CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const CM_OVERRIDE
+ std::unique_ptr<cmFileListGeneratorBase> Clone() const override
{
- CM_AUTO_PTR<cmFileListGeneratorBase> g(
+ std::unique_ptr<cmFileListGeneratorBase> g(
new cmFileListGeneratorProject(*this));
return g;
}
@@ -1856,14 +1930,12 @@ class cmFileListGeneratorMacProject : public cmFileListGeneratorBase
public:
cmFileListGeneratorMacProject(std::vector<std::string> const& names,
const char* ext)
- : cmFileListGeneratorBase()
- , Names(names)
+ : Names(names)
, Extension(ext)
{
}
cmFileListGeneratorMacProject(cmFileListGeneratorMacProject const& r)
- : cmFileListGeneratorBase()
- , Names(r.Names)
+ : Names(r.Names)
, Extension(r.Extension)
{
}
@@ -1871,7 +1943,7 @@ public:
private:
std::vector<std::string> const& Names;
std::string Extension;
- bool Search(std::string const& parent, cmFileList& lister) CM_OVERRIDE
+ bool Search(std::string const& parent, cmFileList& lister) override
{
// Construct a list of matches.
std::vector<std::string> matches;
@@ -1882,27 +1954,24 @@ private:
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;
+ for (std::string name : this->Names) {
name += this->Extension;
if (cmsysString_strcasecmp(fname, name.c_str()) == 0) {
- matches.push_back(fname);
+ matches.emplace_back(fname);
}
}
}
- for (std::vector<std::string>::const_iterator i = matches.begin();
- i != matches.end(); ++i) {
- if (this->Consider(parent + *i, lister)) {
+ for (std::string const& i : matches) {
+ if (this->Consider(parent + i, lister)) {
return true;
}
}
return false;
}
- CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const CM_OVERRIDE
+ std::unique_ptr<cmFileListGeneratorBase> Clone() const override
{
- CM_AUTO_PTR<cmFileListGeneratorBase> g(
+ std::unique_ptr<cmFileListGeneratorBase> g(
new cmFileListGeneratorMacProject(*this));
return g;
}
@@ -1911,21 +1980,19 @@ private:
class cmFileListGeneratorCaseInsensitive : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorCaseInsensitive(std::string const& str)
- : cmFileListGeneratorBase()
- , String(str)
+ cmFileListGeneratorCaseInsensitive(std::string str)
+ : String(std::move(str))
{
}
cmFileListGeneratorCaseInsensitive(
cmFileListGeneratorCaseInsensitive const& r)
- : cmFileListGeneratorBase()
- , String(r.String)
+ : String(r.String)
{
}
private:
std::string String;
- bool Search(std::string const& parent, cmFileList& lister) CM_OVERRIDE
+ bool Search(std::string const& parent, cmFileList& lister) override
{
// Look for matching files.
std::vector<std::string> matches;
@@ -1944,9 +2011,9 @@ private:
}
return false;
}
- CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const CM_OVERRIDE
+ std::unique_ptr<cmFileListGeneratorBase> Clone() const override
{
- CM_AUTO_PTR<cmFileListGeneratorBase> g(
+ std::unique_ptr<cmFileListGeneratorBase> g(
new cmFileListGeneratorCaseInsensitive(*this));
return g;
}
@@ -1955,20 +2022,18 @@ private:
class cmFileListGeneratorGlob : public cmFileListGeneratorBase
{
public:
- cmFileListGeneratorGlob(std::string const& str)
- : cmFileListGeneratorBase()
- , Pattern(str)
+ cmFileListGeneratorGlob(std::string str)
+ : Pattern(std::move(str))
{
}
cmFileListGeneratorGlob(cmFileListGeneratorGlob const& r)
- : cmFileListGeneratorBase()
- , Pattern(r.Pattern)
+ : Pattern(r.Pattern)
{
}
private:
std::string Pattern;
- bool Search(std::string const& parent, cmFileList& lister) CM_OVERRIDE
+ bool Search(std::string const& parent, cmFileList& lister) override
{
// Glob the set of matching files.
std::string expr = parent;
@@ -1980,26 +2045,24 @@ private:
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)) {
- if (this->Consider(*fi, lister)) {
+ for (std::string const& f : files) {
+ if (cmSystemTools::FileIsDirectory(f)) {
+ if (this->Consider(f, lister)) {
return true;
}
}
}
return false;
}
- CM_AUTO_PTR<cmFileListGeneratorBase> Clone() const CM_OVERRIDE
+ std::unique_ptr<cmFileListGeneratorBase> Clone() const override
{
- CM_AUTO_PTR<cmFileListGeneratorBase> g(new cmFileListGeneratorGlob(*this));
- return g;
+ return cm::make_unique<cmFileListGeneratorGlob>(*this);
}
};
bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
{
- assert(!prefix_in.empty() && prefix_in[prefix_in.size() - 1] == '/');
+ assert(!prefix_in.empty() && prefix_in.back() == '/');
if (this->DebugMode) {
fprintf(stderr, "Checking prefix [%s]\n", prefix_in.c_str());
}
@@ -2057,18 +2120,18 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
common.push_back("lib/" + this->LibraryArchitecture);
}
if (this->UseLib32Paths) {
- common.push_back("lib32");
+ common.emplace_back("lib32");
}
if (this->UseLib64Paths) {
- common.push_back("lib64");
+ common.emplace_back("lib64");
}
if (this->UseLibx32Paths) {
- common.push_back("libx32");
+ common.emplace_back("libx32");
}
- common.push_back("lib");
- common.push_back("share");
+ common.emplace_back("lib");
+ common.emplace_back("share");
- // PREFIX/(lib/ARCH|lib|share)/cmake/(Foo|foo|FOO).*/
+ // PREFIX/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/
{
cmFindPackageFileList lister(this);
lister / cmFileListGeneratorFixed(prefix) /
@@ -2081,7 +2144,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
}
}
- // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/
+ // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/
{
cmFindPackageFileList lister(this);
lister / cmFileListGeneratorFixed(prefix) /
@@ -2093,7 +2156,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
}
}
- // PREFIX/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/(cmake|CMake)/
+ // PREFIX/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/
{
cmFindPackageFileList lister(this);
lister / cmFileListGeneratorFixed(prefix) /
@@ -2106,7 +2169,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
}
}
- // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib|share)/cmake/(Foo|foo|FOO).*/
+ // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/cmake/(Foo|foo|FOO).*/
{
cmFindPackageFileList lister(this);
lister / cmFileListGeneratorFixed(prefix) /
@@ -2121,7 +2184,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
}
}
- // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/
+ // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/
{
cmFindPackageFileList lister(this);
lister / cmFileListGeneratorFixed(prefix) /
@@ -2135,7 +2198,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
}
}
- // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib|share)/(Foo|foo|FOO).*/(cmake|CMake)/
+ // PREFIX/(Foo|foo|FOO).*/(lib/ARCH|lib*|share)/(Foo|foo|FOO).*/(cmake|CMake)/
{
cmFindPackageFileList lister(this);
lister / cmFileListGeneratorFixed(prefix) /
@@ -2155,7 +2218,7 @@ bool cmFindPackageCommand::SearchPrefix(std::string const& prefix_in)
bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
{
- assert(!prefix_in.empty() && prefix_in[prefix_in.size() - 1] == '/');
+ assert(!prefix_in.empty() && prefix_in.back() == '/');
if (this->DebugMode) {
fprintf(stderr, "Checking framework prefix [%s]\n", prefix_in.c_str());
}
@@ -2216,7 +2279,7 @@ bool cmFindPackageCommand::SearchFrameworkPrefix(std::string const& prefix_in)
bool cmFindPackageCommand::SearchAppBundlePrefix(std::string const& prefix_in)
{
- assert(!prefix_in.empty() && prefix_in[prefix_in.size() - 1] == '/');
+ assert(!prefix_in.empty() && prefix_in.back() == '/');
if (this->DebugMode) {
fprintf(stderr, "Checking bundle prefix [%s]\n", prefix_in.c_str());
}
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
index 99b0059ba..316ca0f3d 100644
--- a/Source/cmFindPackageCommand.h
+++ b/Source/cmFindPackageCommand.h
@@ -3,14 +3,28 @@
#ifndef cmFindPackageCommand_h
#define cmFindPackageCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmPolicies.h"
#include "cm_kwiml.h"
+#include <cstddef>
+#include <functional>
#include <map>
#include <set>
#include <string>
#include <vector>
+// IWYU insists we should forward-declare instead of including <functional>,
+// but we cannot forward-declare reliably because some C++ standard libraries
+// put the template in an inline namespace.
+#ifdef CMAKE_IWYU_FORWARD_STD_HASH
+/* clang-format off */
+namespace std {
+ template <class T> struct hash;
+}
+/* clang-format on */
+#endif
+
#include "cmFindCommon.h"
class cmCommand;
@@ -51,14 +65,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFindPackageCommand; }
+ cmCommand* Clone() override { return new cmFindPackageCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
class PathLabel : public cmFindCommon::PathLabel
@@ -76,6 +90,9 @@ private:
static PathLabel SystemRegistry;
};
+ bool FindPackageUsingModuleMode();
+ bool FindPackageUsingConfigMode();
+
// Add additional search path labels and groups not present in the
// parent class
void AppendSearchPathGroups();
@@ -86,7 +103,14 @@ private:
bool FindModule(bool& found);
void AddFindDefinition(const std::string& var, const char* val);
void RestoreFindDefinitions();
- bool HandlePackageMode();
+
+ enum /*class*/ HandlePackageModeType
+ {
+ Module,
+ Config
+ };
+ bool HandlePackageMode(HandlePackageModeType type);
+
bool FindConfig();
bool FindPrefixedConfig();
bool FindFrameworkConfig();
@@ -96,7 +120,7 @@ private:
NoPolicyScope,
DoPolicyScope
};
- bool ReadListFile(const char* f, PolicyScopeRule psr);
+ bool ReadListFile(const std::string& f, PolicyScopeRule psr);
void StoreVersionFound();
void ComputePrefixes();
@@ -135,6 +159,8 @@ private:
};
std::map<std::string, OriginalDef> OriginalDefs;
+ std::map<std::string, cmPolicies::PolicyID> DeprecatedFindModules;
+
std::string Name;
std::string Variable;
std::string Version;
@@ -162,6 +188,7 @@ private:
bool UseLib32Paths;
bool UseLib64Paths;
bool UseLibx32Paths;
+ bool UseRealPath;
bool PolicyScope;
std::string LibraryArchitecture;
std::vector<std::string> Names;
@@ -194,6 +221,24 @@ private:
}
};
std::vector<ConfigFileInfo> ConsideredConfigs;
+
+ friend struct std::hash<ConfigFileInfo>;
+};
+
+namespace std {
+
+template <>
+struct hash<cmFindPackageCommand::ConfigFileInfo>
+{
+ typedef cmFindPackageCommand::ConfigFileInfo argument_type;
+ typedef size_t result_type;
+
+ result_type operator()(argument_type const& s) const noexcept
+ {
+ result_type const h(std::hash<std::string>{}(s.filename));
+ return h;
+ }
};
+}
#endif
diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx
index d3541ca94..38ff2ed51 100644
--- a/Source/cmFindPathCommand.cxx
+++ b/Source/cmFindPathCommand.cxx
@@ -85,7 +85,7 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file,
// if the framework has a path in it then just use the filename
if (frameWorkName.find('/') != std::string::npos) {
fileName = file;
- frameWorkName = "";
+ frameWorkName.clear();
}
if (!frameWorkName.empty()) {
std::string fpath = dir;
@@ -94,7 +94,7 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file,
std::string intPath = fpath;
intPath += "/Headers/";
intPath += fileName;
- if (cmSystemTools::FileExists(intPath.c_str())) {
+ if (cmSystemTools::FileExists(intPath)) {
if (this->IncludeFileInPath) {
return intPath;
}
@@ -124,18 +124,15 @@ std::string cmFindPathCommand::FindHeaderInFramework(std::string const& file,
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())) {
+ for (std::string const& n : this->Names) {
+ for (std::string const& sp : this->SearchPaths) {
+ tryPath = sp;
+ tryPath += n;
+ if (cmSystemTools::FileExists(tryPath)) {
if (this->IncludeFileInPath) {
return tryPath;
}
- return *p;
+ return sp;
}
}
}
@@ -144,12 +141,9 @@ std::string cmFindPathCommand::FindNormalHeader()
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);
+ for (std::string const& n : this->Names) {
+ for (std::string const& sp : this->SearchPaths) {
+ std::string fwPath = this->FindHeaderInFramework(n, sp);
if (!fwPath.empty()) {
return fwPath;
}
diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h
index 3761145b2..cb0db4c46 100644
--- a/Source/cmFindPathCommand.h
+++ b/Source/cmFindPathCommand.h
@@ -3,7 +3,7 @@
#ifndef cmFindPathCommand_h
#define cmFindPathCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -27,14 +27,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFindPathCommand; }
+ cmCommand* Clone() override { return new cmFindPathCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
bool IncludeFileInPath;
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx
index 9327c1805..782f746ef 100644
--- a/Source/cmFindProgramCommand.cxx
+++ b/Source/cmFindProgramCommand.cxx
@@ -9,7 +9,7 @@
class cmExecutionStatus;
#if defined(__APPLE__)
-#include <CoreFoundation/CoreFoundation.h>
+# include <CoreFoundation/CoreFoundation.h>
#endif
struct cmFindProgramHelper
@@ -22,7 +22,7 @@ struct cmFindProgramHelper
this->Extensions.push_back(".exe");
#endif
// Consider original name with no extensions.
- this->Extensions.push_back("");
+ this->Extensions.emplace_back();
}
// List of valid extensions.
@@ -34,6 +34,9 @@ struct cmFindProgramHelper
// Current names under consideration.
std::vector<std::string> Names;
+ // Current name with extension under consideration.
+ std::string TestNameExt;
+
// Current full path under consideration.
std::string TestPath;
@@ -43,11 +46,23 @@ struct cmFindProgramHelper
this->Names.clear();
this->AddName(name);
}
+ bool CheckCompoundNames()
+ {
+ for (std::string const& n : this->Names) {
+ // Only perform search relative to current directory if the file name
+ // contains a directory separator.
+ if (n.find('/') != std::string::npos) {
+ if (this->CheckDirectoryForName("", n)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
bool CheckDirectory(std::string const& path)
{
- for (std::vector<std::string>::iterator i = this->Names.begin();
- i != this->Names.end(); ++i) {
- if (this->CheckDirectoryForName(path, *i)) {
+ for (std::string const& n : this->Names) {
+ if (this->CheckDirectoryForName(path, n)) {
return true;
}
}
@@ -55,16 +70,17 @@ struct cmFindProgramHelper
}
bool CheckDirectoryForName(std::string const& path, std::string const& name)
{
- for (std::vector<std::string>::iterator ext = this->Extensions.begin();
- ext != this->Extensions.end(); ++ext) {
- this->TestPath = path;
- this->TestPath += name;
- if (!ext->empty() && cmSystemTools::StringEndsWith(name, ext->c_str())) {
+ for (std::string const& ext : this->Extensions) {
+ if (!ext.empty() && cmSystemTools::StringEndsWith(name, ext.c_str())) {
continue;
}
- this->TestPath += *ext;
+ this->TestNameExt = name;
+ this->TestNameExt += ext;
+ this->TestPath =
+ cmSystemTools::CollapseFullPath(this->TestNameExt, path);
+
if (cmSystemTools::FileExists(this->TestPath, true)) {
- this->BestPath = cmSystemTools::CollapseFullPath(this->TestPath);
+ this->BestPath = this->TestPath;
return true;
}
}
@@ -99,8 +115,8 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn,
return true;
}
- std::string result = FindProgram();
- if (result != "") {
+ std::string const result = FindProgram();
+ if (!result.empty()) {
// Save the value in the cache
this->Makefile->AddCacheDefinition(this->VariableName, result.c_str(),
this->VariableDocumentation.c_str(),
@@ -143,20 +159,18 @@ std::string cmFindProgramCommand::FindNormalProgramNamesPerDir()
{
// Search for all names in each directory.
cmFindProgramHelper helper;
- for (std::vector<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni) {
- helper.AddName(*ni);
+ for (std::string const& n : this->Names) {
+ helper.AddName(n);
}
- // Check for the names themselves (e.g. absolute paths).
- if (helper.CheckDirectory(std::string())) {
+ // Check for the names themselves if they contain a directory separator.
+ if (helper.CheckCompoundNames()) {
return helper.BestPath;
}
// Search every directory.
- for (std::vector<std::string>::const_iterator p = this->SearchPaths.begin();
- p != this->SearchPaths.end(); ++p) {
- if (helper.CheckDirectory(*p)) {
+ for (std::string const& sp : this->SearchPaths) {
+ if (helper.CheckDirectory(sp)) {
return helper.BestPath;
}
}
@@ -168,21 +182,18 @@ std::string cmFindProgramCommand::FindNormalProgramDirsPerName()
{
// Search the entire path for each name.
cmFindProgramHelper helper;
- for (std::vector<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni) {
+ for (std::string const& n : this->Names) {
// Switch to searching for this name.
- helper.SetName(*ni);
+ helper.SetName(n);
- // Check for the name by itself (e.g. an absolute path).
- if (helper.CheckDirectory(std::string())) {
+ // Check for the names themselves if they contain a directory separator.
+ if (helper.CheckCompoundNames()) {
return helper.BestPath;
}
// Search every directory.
- for (std::vector<std::string>::const_iterator p =
- this->SearchPaths.begin();
- p != this->SearchPaths.end(); ++p) {
- if (helper.CheckDirectory(*p)) {
+ for (std::string const& sp : this->SearchPaths) {
+ if (helper.CheckDirectory(sp)) {
return helper.BestPath;
}
}
@@ -193,10 +204,9 @@ std::string cmFindProgramCommand::FindNormalProgramDirsPerName()
std::string cmFindProgramCommand::FindAppBundle()
{
- for (std::vector<std::string>::const_iterator name = this->Names.begin();
- name != this->Names.end(); ++name) {
+ for (std::string const& name : this->Names) {
- std::string appName = *name + std::string(".app");
+ std::string appName = name + std::string(".app");
std::string appPath =
cmSystemTools::FindDirectory(appName, this->SearchPaths, true);
@@ -237,7 +247,7 @@ std::string cmFindProgramCommand::GetBundleExecutable(
// returned executableURL is relative to <appbundle>/Contents/MacOS/
CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
- if (executableURL != NULL) {
+ if (executableURL != nullptr) {
const int MAX_OSX_PATH_SIZE = 1024;
char buffer[MAX_OSX_PATH_SIZE];
diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h
index b0cd42096..147936cc0 100644
--- a/Source/cmFindProgramCommand.h
+++ b/Source/cmFindProgramCommand.h
@@ -3,7 +3,7 @@
#ifndef cmFindProgramCommand_h
#define cmFindProgramCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -28,14 +28,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFindProgramCommand; }
+ cmCommand* Clone() override { return new cmFindProgramCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
std::string FindProgram();
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index 8346b2309..08003eb71 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -2,15 +2,17 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmForEachCommand.h"
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
+#include "cmAlgorithms.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
cmForEachFunctionBlocker::cmForEachFunctionBlocker(cmMakefile* mf)
: Makefile(mf)
@@ -28,15 +30,16 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
cmMakefile& mf,
cmExecutionStatus& inStatus)
{
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "foreach")) {
+ if (lff.Name.Lower == "foreach") {
// record the number of nested foreach commands
this->Depth++;
- } else if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endforeach")) {
+ } else if (lff.Name.Lower == "endforeach") {
// if this is the endofreach for this statement
if (!this->Depth) {
// Remove the function blocker for this scope or bail.
- CM_AUTO_PTR<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(this, lff));
- if (!fb.get()) {
+ std::unique_ptr<cmFunctionBlocker> fb(
+ mf.RemoveFunctionBlocker(this, lff));
+ if (!fb) {
return false;
}
@@ -46,17 +49,15 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
if (mf.GetDefinition(this->Args[0])) {
oldDef = mf.GetDefinition(this->Args[0]);
}
- std::vector<std::string>::const_iterator j = this->Args.begin();
- ++j;
- for (; j != this->Args.end(); ++j) {
+ for (std::string const& arg : cmMakeRange(this->Args).advance(1)) {
// set the variable to the loop value
- mf.AddDefinition(this->Args[0], j->c_str());
+ mf.AddDefinition(this->Args[0], arg.c_str());
// Invoke all the functions that were collected in the block.
cmExecutionStatus status;
- for (unsigned int c = 0; c < this->Functions.size(); ++c) {
+ for (cmListFileFunction const& func : this->Functions) {
status.Clear();
- mf.ExecuteCommand(this->Functions[c], status);
+ mf.ExecuteCommand(func, status);
if (status.GetReturnInvoked()) {
inStatus.SetReturnInvoked();
// restore the variable to its prior value
@@ -95,7 +96,7 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
bool cmForEachFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
cmMakefile& mf)
{
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endforeach")) {
+ if (lff.Name.Lower == "endforeach") {
std::vector<std::string> expandedArguments;
mf.ExpandArguments(lff.Arguments, expandedArguments);
// if the endforeach has arguments then make sure
@@ -120,7 +121,7 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& args,
}
// create a function blocker
- cmForEachFunctionBlocker* f = new cmForEachFunctionBlocker(this->Makefile);
+ auto f = cm::make_unique<cmForEachFunctionBlocker>(this->Makefile);
if (args.size() > 1) {
if (args[1] == "RANGE") {
int start = 0;
@@ -162,7 +163,7 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& args,
break;
}
sprintf(buffer, "%d", cc);
- range.push_back(buffer);
+ range.emplace_back(buffer);
if (cc == stop) {
break;
}
@@ -174,14 +175,14 @@ bool cmForEachCommand::InitialPass(std::vector<std::string> const& args,
} else {
f->Args = args;
}
- this->Makefile->AddFunctionBlocker(f);
+ this->Makefile->AddFunctionBlocker(f.release());
return true;
}
bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args)
{
- CM_AUTO_PTR<cmForEachFunctionBlocker> f(
+ std::unique_ptr<cmForEachFunctionBlocker> f(
new cmForEachFunctionBlocker(this->Makefile));
f->Args.push_back(args[0]);
@@ -208,12 +209,12 @@ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args)
std::ostringstream e;
e << "Unknown argument:\n"
<< " " << args[i] << "\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return true;
}
}
- this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass auto_ptr
+ this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass unique_ptr
return true;
}
diff --git a/Source/cmForEachCommand.h b/Source/cmForEachCommand.h
index 7c8a6d836..5131a4f18 100644
--- a/Source/cmForEachCommand.h
+++ b/Source/cmForEachCommand.h
@@ -3,7 +3,7 @@
#ifndef cmForEachCommand_h
#define cmForEachCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -19,10 +19,10 @@ class cmForEachFunctionBlocker : public cmFunctionBlocker
{
public:
cmForEachFunctionBlocker(cmMakefile* mf);
- ~cmForEachFunctionBlocker() CM_OVERRIDE;
+ ~cmForEachFunctionBlocker() override;
bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
- cmExecutionStatus&) CM_OVERRIDE;
- bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) CM_OVERRIDE;
+ cmExecutionStatus&) override;
+ bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) override;
std::vector<std::string> Args;
std::vector<cmListFileFunction> Functions;
@@ -39,14 +39,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmForEachCommand; }
+ cmCommand* Clone() override { return new cmForEachCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
bool HandleInMode(std::vector<std::string> const& args);
diff --git a/Source/cmFortranParser.h b/Source/cmFortranParser.h
index d8b002309..6a33be571 100644
--- a/Source/cmFortranParser.h
+++ b/Source/cmFortranParser.h
@@ -4,11 +4,12 @@
#define cmFortranParser_h
#if !defined(cmFortranLexer_cxx) && !defined(cmFortranParser_cxx)
-#include "cmConfigure.h"
+# include "cmConfigure.h" // IWYU pragma: keep
-#include <set>
-#include <string>
-#include <vector>
+# include <set>
+# include <string>
+# include <utility>
+# include <vector>
#endif
#include <stddef.h> /* size_t */
@@ -39,11 +40,19 @@ int cmFortranParser_GetOldStartcond(cmFortranParser* parser);
/* Callbacks for parser. */
void cmFortranParser_Error(cmFortranParser* parser, const char* message);
-void cmFortranParser_RuleUse(cmFortranParser* parser, const char* name);
+void cmFortranParser_RuleUse(cmFortranParser* parser, const char* module_name);
void cmFortranParser_RuleLineDirective(cmFortranParser* parser,
const char* filename);
void cmFortranParser_RuleInclude(cmFortranParser* parser, const char* name);
-void cmFortranParser_RuleModule(cmFortranParser* parser, const char* name);
+void cmFortranParser_RuleModule(cmFortranParser* parser,
+ const char* module_name);
+void cmFortranParser_RuleSubmodule(cmFortranParser* parser,
+ const char* module_name,
+ const char* submodule_name);
+void cmFortranParser_RuleSubmoduleNested(cmFortranParser* parser,
+ const char* module_name,
+ const char* submodule_name,
+ const char* nested_submodule_name);
void cmFortranParser_RuleDefine(cmFortranParser* parser, const char* name);
void cmFortranParser_RuleUndef(cmFortranParser* parser, const char* name);
void cmFortranParser_RuleIfdef(cmFortranParser* parser, const char* name);
@@ -65,20 +74,20 @@ struct cmFortran_yystype
#define YYSTYPE cmFortran_yystype
#define YYSTYPE_IS_DECLARED 1
#if !defined(cmFortranLexer_cxx)
-#define YY_NO_UNISTD_H
-#include "cmFortranLexer.h"
+# define YY_NO_UNISTD_H
+# include "cmFortranLexer.h"
#endif
#if !defined(cmFortranLexer_cxx)
-#if !defined(cmFortranParser_cxx)
-#undef YY_EXTRA_TYPE
-#undef YY_DECL
-#undef YYSTYPE
-#undef YYSTYPE_IS_DECLARED
-#endif
+# if !defined(cmFortranParser_cxx)
+# undef YY_EXTRA_TYPE
+# undef YY_DECL
+# undef YYSTYPE
+# undef YYSTYPE_IS_DECLARED
+# endif
#endif
#if !defined(cmFortranLexer_cxx) && !defined(cmFortranParser_cxx)
-#include <stack>
+# include <stack>
// Information about a single source file.
class cmFortranSourceInfo
@@ -106,10 +115,10 @@ int cmFortran_yyparse(yyscan_t);
// Define parser object internal structure.
struct cmFortranFile
{
- cmFortranFile(FILE* file, YY_BUFFER_STATE buffer, const std::string& dir)
+ cmFortranFile(FILE* file, YY_BUFFER_STATE buffer, std::string dir)
: File(file)
, Buffer(buffer)
- , Directory(dir)
+ , Directory(std::move(dir))
, LastCharWasNewline(false)
{
}
@@ -119,16 +128,32 @@ struct cmFortranFile
bool LastCharWasNewline;
};
+struct cmFortranCompiler
+{
+ std::string Id;
+ std::string SModSep;
+ std::string SModExt;
+};
+
struct cmFortranParser_s
{
- cmFortranParser_s(std::vector<std::string> const& includes,
- std::set<std::string> const& defines,
- cmFortranSourceInfo& info);
+ cmFortranParser_s(cmFortranCompiler fc, std::vector<std::string> includes,
+ std::set<std::string> defines, cmFortranSourceInfo& info);
~cmFortranParser_s();
+ cmFortranParser_s(const cmFortranParser_s&) = delete;
+ cmFortranParser_s& operator=(const cmFortranParser_s&) = delete;
+
bool FindIncludeFile(const char* dir, const char* includeName,
std::string& fileName);
+ std::string ModName(std::string const& mod_name) const;
+ std::string SModName(std::string const& mod_name,
+ std::string const& sub_name) const;
+
+ // What compiler.
+ cmFortranCompiler Compiler;
+
// The include file search path.
std::vector<std::string> IncludePath;
diff --git a/Source/cmFortranParserImpl.cxx b/Source/cmFortranParserImpl.cxx
index 4e23f3691..e8b1da83c 100644
--- a/Source/cmFortranParserImpl.cxx
+++ b/Source/cmFortranParserImpl.cxx
@@ -3,12 +3,12 @@
#include "cmFortranParser.h"
#include "cmSystemTools.h"
-#include "cmConfigure.h"
#include <assert.h>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
+#include <utility>
#include <vector>
bool cmFortranParser_s::FindIncludeFile(const char* dir,
@@ -18,25 +18,24 @@ bool cmFortranParser_s::FindIncludeFile(const char* dir,
// If the file is a full path, include it directly.
if (cmSystemTools::FileIsFullPath(includeName)) {
fileName = includeName;
- return cmSystemTools::FileExists(fileName.c_str(), true);
+ return cmSystemTools::FileExists(fileName, true);
}
// 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)) {
+ if (cmSystemTools::FileExists(fullName, 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;
+ for (std::string const& i : this->IncludePath) {
+ fullName = i;
fullName += "/";
fullName += includeName;
- if (cmSystemTools::FileExists(fullName.c_str(), true)) {
+ if (cmSystemTools::FileExists(fullName, true)) {
fileName = fullName;
return true;
}
@@ -44,11 +43,13 @@ bool cmFortranParser_s::FindIncludeFile(const char* dir,
return false;
}
-cmFortranParser_s::cmFortranParser_s(std::vector<std::string> const& includes,
- std::set<std::string> const& defines,
+cmFortranParser_s::cmFortranParser_s(cmFortranCompiler fc,
+ std::vector<std::string> includes,
+ std::set<std::string> defines,
cmFortranSourceInfo& info)
- : IncludePath(includes)
- , PPDefinitions(defines)
+ : Compiler(std::move(fc))
+ , IncludePath(std::move(includes))
+ , PPDefinitions(std::move(defines))
, Info(info)
{
this->InInterface = false;
@@ -61,7 +62,7 @@ cmFortranParser_s::cmFortranParser_s(std::vector<std::string> const& includes,
// 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 =
- cmFortran_yy_create_buffer(CM_NULLPTR, 4, this->Scanner);
+ cmFortran_yy_create_buffer(nullptr, 4, this->Scanner);
cmFortran_yy_switch_to_buffer(buffer, this->Scanner);
}
@@ -70,6 +71,23 @@ cmFortranParser_s::~cmFortranParser_s()
cmFortran_yylex_destroy(this->Scanner);
}
+std::string cmFortranParser_s::ModName(std::string const& mod_name) const
+{
+ return mod_name + ".mod";
+}
+
+std::string cmFortranParser_s::SModName(std::string const& mod_name,
+ std::string const& sub_name) const
+{
+ std::string const& SModExt =
+ this->Compiler.SModExt.empty() ? ".mod" : this->Compiler.SModExt;
+ // An empty separator means that the compiler does not use a prefix.
+ if (this->Compiler.SModSep.empty()) {
+ return sub_name + SModExt;
+ }
+ return mod_name + this->Compiler.SModSep + sub_name + SModExt;
+}
+
bool cmFortranParser_FilePush(cmFortranParser* parser, const char* fname)
{
// Open the new file and push it onto the stack. Save the old
@@ -79,7 +97,7 @@ bool cmFortranParser_FilePush(cmFortranParser* parser, const char* fname)
std::string dir = cmSystemTools::GetParentDirectory(fname);
cmFortranFile f(file, current, dir);
YY_BUFFER_STATE buffer =
- cmFortran_yy_create_buffer(CM_NULLPTR, 16384, parser->Scanner);
+ cmFortran_yy_create_buffer(nullptr, 16384, parser->Scanner);
cmFortran_yy_switch_to_buffer(buffer, parser->Scanner);
parser->FileStack.push(f);
return true;
@@ -121,14 +139,14 @@ int cmFortranParser_Input(cmFortranParser* parser, char* buffer,
n = 1;
ff.LastCharWasNewline = true;
}
- return (int)n;
+ return static_cast<int>(n);
}
return 0;
}
void cmFortranParser_StringStart(cmFortranParser* parser)
{
- parser->TokenString = "";
+ parser->TokenString.clear();
}
const char* cmFortranParser_StringEnd(cmFortranParser* parser)
@@ -170,11 +188,16 @@ void cmFortranParser_Error(cmFortranParser* parser, const char* msg)
parser->Error = msg ? msg : "unknown error";
}
-void cmFortranParser_RuleUse(cmFortranParser* parser, const char* name)
+void cmFortranParser_RuleUse(cmFortranParser* parser, const char* module_name)
{
- if (!parser->InPPFalseBranch) {
- parser->Info.Requires.insert(cmSystemTools::LowerCase(name));
+ if (parser->InPPFalseBranch) {
+ return;
}
+
+ // syntax: "use module_name"
+ // requires: "module_name.mod"
+ std::string const& mod_name = cmSystemTools::LowerCase(module_name);
+ parser->Info.Requires.insert(parser->ModName(mod_name));
}
void cmFortranParser_RuleLineDirective(cmFortranParser* parser,
@@ -227,11 +250,63 @@ void cmFortranParser_RuleInclude(cmFortranParser* parser, const char* name)
}
}
-void cmFortranParser_RuleModule(cmFortranParser* parser, const char* name)
+void cmFortranParser_RuleModule(cmFortranParser* parser,
+ const char* module_name)
+{
+ if (parser->InPPFalseBranch) {
+ return;
+ }
+
+ if (!parser->InInterface) {
+ // syntax: "module module_name"
+ // provides: "module_name.mod"
+ std::string const& mod_name = cmSystemTools::LowerCase(module_name);
+ parser->Info.Provides.insert(parser->ModName(mod_name));
+ }
+}
+
+void cmFortranParser_RuleSubmodule(cmFortranParser* parser,
+ const char* module_name,
+ const char* submodule_name)
{
- if (!parser->InPPFalseBranch && !parser->InInterface) {
- parser->Info.Provides.insert(cmSystemTools::LowerCase(name));
+ if (parser->InPPFalseBranch) {
+ return;
}
+
+ // syntax: "submodule (module_name) submodule_name"
+ // requires: "module_name.mod"
+ // provides: "module_name@submodule_name.smod"
+ //
+ // FIXME: Some compilers split the submodule part of a module into a
+ // separate "module_name.smod" file. Whether it is generated or
+ // not depends on conditions more subtle than we currently detect.
+ // For now we depend directly on "module_name.mod".
+
+ std::string const& mod_name = cmSystemTools::LowerCase(module_name);
+ std::string const& sub_name = cmSystemTools::LowerCase(submodule_name);
+ parser->Info.Requires.insert(parser->ModName(mod_name));
+ parser->Info.Provides.insert(parser->SModName(mod_name, sub_name));
+}
+
+void cmFortranParser_RuleSubmoduleNested(cmFortranParser* parser,
+ const char* module_name,
+ const char* submodule_name,
+ const char* nested_submodule_name)
+{
+ if (parser->InPPFalseBranch) {
+ return;
+ }
+
+ // syntax: "submodule (module_name:submodule_name) nested_submodule_name"
+ // requires: "module_name@submodule_name.smod"
+ // provides: "module_name@nested_submodule_name.smod"
+
+ std::string const& mod_name = cmSystemTools::LowerCase(module_name);
+ std::string const& sub_name = cmSystemTools::LowerCase(submodule_name);
+ std::string const& nest_name =
+ cmSystemTools::LowerCase(nested_submodule_name);
+ parser->Info.Requires.insert(parser->SModName(mod_name, sub_name));
+ parser->Info.Provides.insert(parser->SModName(mod_name, nest_name));
}
void cmFortranParser_RuleDefine(cmFortranParser* parser, const char* macro)
diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h
index b3450b3f2..cd6b05db4 100644
--- a/Source/cmFunctionBlocker.h
+++ b/Source/cmFunctionBlocker.h
@@ -26,7 +26,7 @@ public:
return false;
}
- virtual ~cmFunctionBlocker() {}
+ virtual ~cmFunctionBlocker() = default;
/** Set/Get the context in which this blocker is created. */
void SetStartingContext(cmListFileContext const& lfc)
diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx
index ee52bde37..9067a5f64 100644
--- a/Source/cmFunctionCommand.cxx
+++ b/Source/cmFunctionCommand.cxx
@@ -8,22 +8,17 @@
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmPolicies.h"
+#include "cmRange.h"
#include "cmState.h"
-#include "cmSystemTools.h"
// define the class for function commands
class cmFunctionHelperCommand : public cmCommand
{
public:
- cmFunctionHelperCommand() {}
-
- ///! clean up any memory allocated by the function
- ~cmFunctionHelperCommand() CM_OVERRIDE {}
-
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmFunctionHelperCommand* newC = new cmFunctionHelperCommand;
// we must copy when we clone
@@ -39,10 +34,10 @@ public:
* the CMakeLists.txt file.
*/
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
- cmExecutionStatus&) CM_OVERRIDE;
+ cmExecutionStatus&) override;
bool InitialPass(std::vector<std::string> const&,
- cmExecutionStatus&) CM_OVERRIDE
+ cmExecutionStatus&) override
{
return false;
}
@@ -104,9 +99,9 @@ bool cmFunctionHelperCommand::InvokeInitialPass(
// Invoke all the functions that were collected in the block.
// for each function
- for (unsigned int c = 0; c < this->Functions.size(); ++c) {
+ for (cmListFileFunction const& func : this->Functions) {
cmExecutionStatus status;
- if (!this->Makefile->ExecuteCommand(this->Functions[c], status) ||
+ if (!this->Makefile->ExecuteCommand(func, status) ||
status.GetNestedError()) {
// The error message should have already included the call stack
// so we do not need to report an error here.
@@ -128,9 +123,9 @@ bool cmFunctionFunctionBlocker::IsFunctionBlocked(
{
// 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")) {
+ if (lff.Name.Lower == "function") {
this->Depth++;
- } else if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endfunction")) {
+ } else if (lff.Name.Lower == "endfunction") {
// if this is the endfunction for this function then execute
if (!this->Depth) {
// create a new command and add it to cmake
@@ -157,7 +152,7 @@ bool cmFunctionFunctionBlocker::IsFunctionBlocked(
bool cmFunctionFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
cmMakefile& mf)
{
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endfunction")) {
+ if (lff.Name.Lower == "endfunction") {
std::vector<std::string> expandedArguments;
mf.ExpandArguments(lff.Arguments, expandedArguments,
this->GetStartingContext().FilePath.c_str());
@@ -182,7 +177,7 @@ bool cmFunctionCommand::InitialPass(std::vector<std::string> const& args,
// create a function blocker
cmFunctionFunctionBlocker* f = new cmFunctionFunctionBlocker();
- f->Args.insert(f->Args.end(), args.begin(), args.end());
+ cmAppend(f->Args, args);
this->Makefile->AddFunctionBlocker(f);
return true;
}
diff --git a/Source/cmFunctionCommand.h b/Source/cmFunctionCommand.h
index f26312632..8b37df032 100644
--- a/Source/cmFunctionCommand.h
+++ b/Source/cmFunctionCommand.h
@@ -3,7 +3,7 @@
#ifndef cmFunctionCommand_h
#define cmFunctionCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -18,15 +18,13 @@ class cmMakefile;
class cmFunctionFunctionBlocker : public cmFunctionBlocker
{
public:
- cmFunctionFunctionBlocker() { this->Depth = 0; }
- ~cmFunctionFunctionBlocker() CM_OVERRIDE {}
bool IsFunctionBlocked(const cmListFileFunction&, cmMakefile& mf,
- cmExecutionStatus&) CM_OVERRIDE;
- bool ShouldRemove(const cmListFileFunction&, cmMakefile& mf) CM_OVERRIDE;
+ cmExecutionStatus&) override;
+ bool ShouldRemove(const cmListFileFunction&, cmMakefile& mf) override;
std::vector<std::string> Args;
std::vector<cmListFileFunction> Functions;
- int Depth;
+ int Depth = 0;
};
/// Starts function() ... endfunction() block
@@ -36,14 +34,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmFunctionCommand; }
+ cmCommand* Clone() override { return new cmFunctionCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx
index 6aa593cc0..2f47788f8 100644
--- a/Source/cmGeneratedFileStream.cxx
+++ b/Source/cmGeneratedFileStream.cxx
@@ -7,13 +7,11 @@
#include "cmSystemTools.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cm_codecvt.hxx"
-#include "cm_zlib.h"
+# include "cm_codecvt.hxx"
+# include "cm_zlib.h"
#endif
cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding)
- : cmGeneratedFileStreamBase()
- , Stream()
{
#ifdef CMAKE_BUILD_WITH_CMAKE
if (encoding != codecvt::None) {
@@ -24,15 +22,14 @@ cmGeneratedFileStream::cmGeneratedFileStream(Encoding encoding)
#endif
}
-cmGeneratedFileStream::cmGeneratedFileStream(const char* name, bool quiet,
- Encoding encoding)
+cmGeneratedFileStream::cmGeneratedFileStream(std::string const& name,
+ bool quiet, Encoding encoding)
: 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::Error("Cannot open file for write: " + this->TempName);
cmSystemTools::ReportLastSystemError("");
}
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -54,7 +51,7 @@ cmGeneratedFileStream::~cmGeneratedFileStream()
this->Okay = !this->fail();
}
-cmGeneratedFileStream& cmGeneratedFileStream::Open(const char* name,
+cmGeneratedFileStream& cmGeneratedFileStream::Open(std::string const& name,
bool quiet, bool binaryFlag)
{
// Store the file name and construct the temporary file name.
@@ -70,8 +67,7 @@ cmGeneratedFileStream& cmGeneratedFileStream::Open(const char* name,
// Check if the file opened.
if (!*this && !quiet) {
- cmSystemTools::Error("Cannot open file for write: ",
- this->TempName.c_str());
+ cmSystemTools::Error("Cannot open file for write: " + this->TempName);
cmSystemTools::ReportLastSystemError("");
}
return *this;
@@ -104,23 +100,9 @@ void cmGeneratedFileStream::SetCompressionExtraExtension(bool ext)
this->CompressExtraExtension = ext;
}
-cmGeneratedFileStreamBase::cmGeneratedFileStreamBase()
- : Name()
- , TempName()
- , CopyIfDifferent(false)
- , Okay(false)
- , Compress(false)
- , CompressExtraExtension(true)
-{
-}
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase() = default;
-cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(const char* name)
- : Name()
- , TempName()
- , CopyIfDifferent(false)
- , Okay(false)
- , Compress(false)
- , CompressExtraExtension(true)
+cmGeneratedFileStreamBase::cmGeneratedFileStreamBase(std::string const& name)
{
this->Open(name);
}
@@ -130,7 +112,7 @@ cmGeneratedFileStreamBase::~cmGeneratedFileStreamBase()
this->Close();
}
-void cmGeneratedFileStreamBase::Open(const char* name)
+void cmGeneratedFileStreamBase::Open(std::string const& name)
{
// Save the original name of the file.
this->Name = name;
@@ -147,7 +129,7 @@ void cmGeneratedFileStreamBase::Open(const char* name)
cmSystemTools::RemoveFile(this->TempName);
std::string dir = cmSystemTools::GetFilenamePath(this->TempName);
- cmSystemTools::MakeDirectory(dir.c_str());
+ cmSystemTools::MakeDirectory(dir);
}
bool cmGeneratedFileStreamBase::Close()
@@ -168,12 +150,12 @@ bool cmGeneratedFileStreamBase::Close()
// 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());
+ if (this->CompressFile(this->TempName, gzname)) {
+ this->RenameFile(gzname, resname);
}
cmSystemTools::RemoveFile(gzname);
} else {
- this->RenameFile(this->TempName.c_str(), resname.c_str());
+ this->RenameFile(this->TempName, resname);
}
replaced = true;
@@ -188,10 +170,10 @@ bool cmGeneratedFileStreamBase::Close()
}
#ifdef CMAKE_BUILD_WITH_CMAKE
-int cmGeneratedFileStreamBase::CompressFile(const char* oldname,
- const char* newname)
+int cmGeneratedFileStreamBase::CompressFile(std::string const& oldname,
+ std::string const& newname)
{
- gzFile gf = gzopen(newname, "w");
+ gzFile gf = gzopen(newname.c_str(), "w");
if (!gf) {
return 0;
}
@@ -214,14 +196,15 @@ int cmGeneratedFileStreamBase::CompressFile(const char* oldname,
return 1;
}
#else
-int cmGeneratedFileStreamBase::CompressFile(const char*, const char*)
+int cmGeneratedFileStreamBase::CompressFile(std::string const&,
+ std::string const&)
{
return 0;
}
#endif
-int cmGeneratedFileStreamBase::RenameFile(const char* oldname,
- const char* newname)
+int cmGeneratedFileStreamBase::RenameFile(std::string const& oldname,
+ std::string const& newname)
{
return cmSystemTools::RenameFile(oldname, newname);
}
diff --git a/Source/cmGeneratedFileStream.h b/Source/cmGeneratedFileStream.h
index 56f9988ff..5b1eb5153 100644
--- a/Source/cmGeneratedFileStream.h
+++ b/Source/cmGeneratedFileStream.h
@@ -3,7 +3,7 @@
#ifndef cmGeneratedFileStream_h
#define cmGeneratedFileStream_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cm_codecvt.hxx"
#include "cmsys/FStream.hxx"
@@ -20,7 +20,7 @@ protected:
cmGeneratedFileStreamBase();
// This constructor prepares the temporary output file.
- cmGeneratedFileStreamBase(const char* name);
+ cmGeneratedFileStreamBase(std::string const& name);
// The destructor renames the temporary output file to the real name.
~cmGeneratedFileStreamBase();
@@ -29,14 +29,14 @@ protected:
// 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);
+ void Open(std::string const& name);
bool Close();
// Internal file replacement implementation.
- int RenameFile(const char* oldname, const char* newname);
+ int RenameFile(std::string const& oldname, std::string const& newname);
// Internal file compression implementation.
- int CompressFile(const char* oldname, const char* newname);
+ int CompressFile(std::string const& oldname, std::string const& newname);
// The name of the final destination file for the output.
std::string Name;
@@ -45,16 +45,16 @@ protected:
std::string TempName;
// Whether to do a copy-if-different.
- bool CopyIfDifferent;
+ bool CopyIfDifferent = false;
// Whether the real file stream was valid when it was closed.
- bool Okay;
+ bool Okay = false;
// Whether the destination file is compressed
- bool Compress;
+ bool Compress = false;
// Whether the destination file is compressed
- bool CompressExtraExtension;
+ bool CompressExtraExtension = true;
};
/** \class cmGeneratedFileStream
@@ -67,8 +67,9 @@ protected:
* contents have changed to prevent the file modification time from
* being updated.
*/
-class cmGeneratedFileStream : private cmGeneratedFileStreamBase,
- public cmsys::ofstream
+class cmGeneratedFileStream
+ : private cmGeneratedFileStreamBase
+ , public cmsys::ofstream
{
public:
typedef cmsys::ofstream Stream;
@@ -86,7 +87,7 @@ public:
* file cannot be opened an error message is produced unless the
* second argument is set to true.
*/
- cmGeneratedFileStream(const char* name, bool quiet = false,
+ cmGeneratedFileStream(std::string const& name, bool quiet = false,
Encoding encoding = codecvt::None);
/**
@@ -94,7 +95,9 @@ public:
* file was successfully written before allowing the original to be
* replaced.
*/
- ~cmGeneratedFileStream() CM_OVERRIDE;
+ ~cmGeneratedFileStream() override;
+
+ cmGeneratedFileStream(cmGeneratedFileStream const&) = delete;
/**
* Open an output file by name. This should be used only with a
@@ -102,13 +105,13 @@ public:
* 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,
+ cmGeneratedFileStream& Open(std::string const& 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
+ * destination file if the stream is still valid when this method
* is called.
*/
bool Close();
@@ -133,9 +136,6 @@ public:
* the output file to be changed during the use of cmGeneratedFileStream.
*/
void SetName(const std::string& fname);
-
-private:
- cmGeneratedFileStream(cmGeneratedFileStream const&); // not implemented
};
#endif
diff --git a/Source/cmGeneratorExpression.cxx b/Source/cmGeneratorExpression.cxx
index 00b5ff4ef..175a26d2e 100644
--- a/Source/cmGeneratorExpression.cxx
+++ b/Source/cmGeneratorExpression.cxx
@@ -3,41 +3,39 @@
#include "cmGeneratorExpression.h"
#include "cmsys/RegularExpression.hxx"
+#include <memory> // IWYU pragma: keep
#include <utility>
#include "assert.h"
#include "cmAlgorithms.h"
#include "cmGeneratorExpressionContext.h"
+#include "cmGeneratorExpressionDAGChecker.h"
#include "cmGeneratorExpressionEvaluator.h"
#include "cmGeneratorExpressionLexer.h"
#include "cmGeneratorExpressionParser.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-cmGeneratorExpression::cmGeneratorExpression(
- const cmListFileBacktrace& backtrace)
- : Backtrace(backtrace)
+cmGeneratorExpression::cmGeneratorExpression(cmListFileBacktrace backtrace)
+ : Backtrace(std::move(backtrace))
{
}
-CM_AUTO_PTR<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
+std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
std::string const& input)
{
- return CM_AUTO_PTR<cmCompiledGeneratorExpression>(
+ return std::unique_ptr<cmCompiledGeneratorExpression>(
new cmCompiledGeneratorExpression(this->Backtrace, input));
}
-CM_AUTO_PTR<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
+std::unique_ptr<cmCompiledGeneratorExpression> cmGeneratorExpression::Parse(
const char* input)
{
return this->Parse(std::string(input ? input : ""));
}
-cmGeneratorExpression::~cmGeneratorExpression()
-{
-}
+cmGeneratorExpression::~cmGeneratorExpression() = default;
-const char* cmCompiledGeneratorExpression::Evaluate(
+const std::string& cmCompiledGeneratorExpression::Evaluate(
cmLocalGenerator* lg, const std::string& config, bool quiet,
const cmGeneratorTarget* headTarget,
cmGeneratorExpressionDAGChecker* dagChecker,
@@ -47,7 +45,7 @@ const char* cmCompiledGeneratorExpression::Evaluate(
language);
}
-const char* cmCompiledGeneratorExpression::Evaluate(
+const std::string& cmCompiledGeneratorExpression::Evaluate(
cmLocalGenerator* lg, const std::string& config, bool quiet,
const cmGeneratorTarget* headTarget, const cmGeneratorTarget* currentTarget,
cmGeneratorExpressionDAGChecker* dagChecker,
@@ -60,28 +58,23 @@ const char* cmCompiledGeneratorExpression::Evaluate(
return this->EvaluateWithContext(context, dagChecker);
}
-const char* cmCompiledGeneratorExpression::EvaluateWithContext(
+const std::string& cmCompiledGeneratorExpression::EvaluateWithContext(
cmGeneratorExpressionContext& context,
cmGeneratorExpressionDAGChecker* dagChecker) const
{
if (!this->NeedsEvaluation) {
- return this->Input.c_str();
+ return this->Input;
}
- this->Output = "";
-
- std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it =
- this->Evaluators.begin();
- const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end =
- this->Evaluators.end();
+ this->Output.clear();
- for (; it != end; ++it) {
- this->Output += (*it)->Evaluate(&context, dagChecker);
+ for (const cmGeneratorExpressionEvaluator* it : this->Evaluators) {
+ this->Output += it->Evaluate(&context, dagChecker);
- this->SeenTargetProperties.insert(context.SeenTargetProperties.begin(),
- context.SeenTargetProperties.end());
+ this->SeenTargetProperties.insert(context.SeenTargetProperties.cbegin(),
+ context.SeenTargetProperties.cend());
if (context.HadError) {
- this->Output = "";
+ this->Output.clear();
break;
}
}
@@ -96,14 +89,13 @@ const char* cmCompiledGeneratorExpression::EvaluateWithContext(
this->DependTargets = context.DependTargets;
this->AllTargetsSeen = context.AllTargets;
- // TODO: Return a std::string from here instead?
- return this->Output.c_str();
+ return this->Output;
}
cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
- cmListFileBacktrace const& backtrace, const std::string& input)
- : Backtrace(backtrace)
- , Input(input)
+ cmListFileBacktrace backtrace, std::string input)
+ : Backtrace(std::move(backtrace))
+ , Input(std::move(input))
, HadContextSensitiveCondition(false)
, HadHeadSensitiveCondition(false)
, EvaluateForBuildsystem(false)
@@ -168,7 +160,7 @@ static std::string stripAllGeneratorExpressions(const std::string& input)
const char* c = input.c_str() + pos;
const char* const cStart = c;
for (; *c; ++c) {
- if (c[0] == '$' && c[1] == '<') {
+ if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) {
++nestingLevel;
++c;
continue;
@@ -199,15 +191,14 @@ static void prefixItems(const std::string& content, std::string& result,
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) {
+ for (std::string const& e : entries) {
result += sep;
sep = ";";
- if (!cmSystemTools::FileIsFullPath(ei->c_str()) &&
- cmGeneratorExpression::Find(*ei) != 0) {
+ if (!cmSystemTools::FileIsFullPath(e) &&
+ cmGeneratorExpression::Find(e) != 0) {
result += prefix;
}
- result += *ei;
+ result += e;
}
}
@@ -244,7 +235,7 @@ static std::string stripExportInterface(
const char* c = input.c_str() + pos;
const char* const cStart = c;
for (; *c; ++c) {
- if (c[0] == '$' && c[1] == '<') {
+ if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) {
++nestingLevel;
++c;
continue;
@@ -297,7 +288,7 @@ void cmGeneratorExpression::Split(const std::string& input,
std::string::size_type startPos = input.rfind(';', pos);
if (startPos == std::string::npos) {
preGenex = part;
- part = "";
+ part.clear();
} else if (startPos != pos - 1 && startPos >= lastPos) {
part = input.substr(lastPos, startPos - lastPos);
preGenex = input.substr(startPos + 1, pos - startPos - 1);
@@ -311,7 +302,7 @@ void cmGeneratorExpression::Split(const std::string& input,
const char* c = input.c_str() + pos;
const char* const cStart = c;
for (; *c; ++c) {
- if (c[0] == '$' && c[1] == '<') {
+ if (cmGeneratorExpression::StartsWithGeneratorExpression(c)) {
++nestingLevel;
++c;
continue;
@@ -379,10 +370,27 @@ void cmCompiledGeneratorExpression::GetMaxLanguageStandard(
const cmGeneratorTarget* tgt, std::map<std::string, std::string>& mapping)
{
typedef std::map<cmGeneratorTarget const*,
- std::map<std::string, std::string> >
+ std::map<std::string, std::string>>
MapType;
MapType::const_iterator it = this->MaxLanguageStandard.find(tgt);
if (it != this->MaxLanguageStandard.end()) {
mapping = it->second;
}
}
+
+const std::string& cmGeneratorExpressionInterpreter::Evaluate(
+ const char* expression, const std::string& property)
+{
+ this->CompiledGeneratorExpression =
+ this->GeneratorExpression.Parse(expression);
+
+ // Specify COMPILE_OPTIONS to DAGchecker, same semantic as COMPILE_FLAGS
+ cmGeneratorExpressionDAGChecker dagChecker(
+ this->HeadTarget,
+ property == "COMPILE_FLAGS" ? "COMPILE_OPTIONS" : property, nullptr,
+ nullptr);
+
+ return this->CompiledGeneratorExpression->Evaluate(
+ this->LocalGenerator, this->Config, false, this->HeadTarget, &dagChecker,
+ this->Language);
+}
diff --git a/Source/cmGeneratorExpression.h b/Source/cmGeneratorExpression.h
index 34516f5c5..fd36c4bcb 100644
--- a/Source/cmGeneratorExpression.h
+++ b/Source/cmGeneratorExpression.h
@@ -3,14 +3,15 @@
#ifndef cmGeneratorExpression_h
#define cmGeneratorExpression_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmListFileCache.h"
-#include "cm_auto_ptr.hxx"
#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <string>
+#include <utility>
#include <vector>
class cmCompiledGeneratorExpression;
@@ -31,16 +32,17 @@ struct cmGeneratorExpressionEvaluator;
*/
class cmGeneratorExpression
{
- CM_DISABLE_COPY(cmGeneratorExpression)
-
public:
/** Construct. */
- cmGeneratorExpression(
- cmListFileBacktrace const& backtrace = cmListFileBacktrace());
+ cmGeneratorExpression(cmListFileBacktrace backtrace = cmListFileBacktrace());
~cmGeneratorExpression();
- CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(std::string const& input);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> Parse(const char* input);
+ cmGeneratorExpression(cmGeneratorExpression const&) = delete;
+ cmGeneratorExpression& operator=(cmGeneratorExpression const&) = delete;
+
+ std::unique_ptr<cmCompiledGeneratorExpression> Parse(
+ std::string const& input);
+ std::unique_ptr<cmCompiledGeneratorExpression> Parse(const char* input);
enum PreprocessContext
{
@@ -62,25 +64,39 @@ public:
static std::string StripEmptyListElements(const std::string& input);
+ static inline bool StartsWithGeneratorExpression(const std::string& input)
+ {
+ return input.length() >= 2 && input[0] == '$' && input[1] == '<';
+ }
+ static inline bool StartsWithGeneratorExpression(const char* input)
+ {
+ return input != nullptr && input[0] == '$' && input[1] == '<';
+ }
+
private:
cmListFileBacktrace Backtrace;
};
class cmCompiledGeneratorExpression
{
- CM_DISABLE_COPY(cmCompiledGeneratorExpression)
-
public:
- const char* Evaluate(
+ ~cmCompiledGeneratorExpression();
+
+ cmCompiledGeneratorExpression(cmCompiledGeneratorExpression const&) = delete;
+ cmCompiledGeneratorExpression& operator=(
+ cmCompiledGeneratorExpression const&) = delete;
+
+ const std::string& Evaluate(
cmLocalGenerator* lg, const std::string& config, bool quiet = false,
- cmGeneratorTarget const* headTarget = CM_NULLPTR,
- cmGeneratorTarget const* currentTarget = CM_NULLPTR,
- cmGeneratorExpressionDAGChecker* dagChecker = CM_NULLPTR,
+ cmGeneratorTarget const* headTarget = nullptr,
+ cmGeneratorTarget const* currentTarget = nullptr,
+ cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
+ std::string const& language = std::string()) const;
+ const std::string& Evaluate(
+ cmLocalGenerator* lg, const std::string& config, bool quiet,
+ cmGeneratorTarget const* headTarget,
+ cmGeneratorExpressionDAGChecker* dagChecker,
std::string const& language = std::string()) const;
- const char* Evaluate(cmLocalGenerator* lg, const std::string& config,
- bool quiet, cmGeneratorTarget const* headTarget,
- cmGeneratorExpressionDAGChecker* dagChecker,
- std::string const& language = std::string()) const;
/** Get set of targets found during evaluations. */
std::set<cmGeneratorTarget*> const& GetTargets() const
@@ -98,8 +114,6 @@ public:
return this->AllTargetsSeen;
}
- ~cmCompiledGeneratorExpression();
-
std::string const& GetInput() const { return this->Input; }
cmListFileBacktrace GetBacktrace() const { return this->Backtrace; }
@@ -125,12 +139,12 @@ public:
std::map<std::string, std::string>& mapping);
private:
- const char* EvaluateWithContext(
+ const std::string& EvaluateWithContext(
cmGeneratorExpressionContext& context,
cmGeneratorExpressionDAGChecker* dagChecker) const;
- cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
- const std::string& input);
+ cmCompiledGeneratorExpression(cmListFileBacktrace backtrace,
+ std::string input);
friend class cmGeneratorExpression;
@@ -143,7 +157,7 @@ private:
mutable std::set<cmGeneratorTarget const*> AllTargetsSeen;
mutable std::set<std::string> SeenTargetProperties;
mutable std::map<cmGeneratorTarget const*,
- std::map<std::string, std::string> >
+ std::map<std::string, std::string>>
MaxLanguageStandard;
mutable std::string Output;
mutable bool HadContextSensitiveCondition;
@@ -152,4 +166,40 @@ private:
bool EvaluateForBuildsystem;
};
+class cmGeneratorExpressionInterpreter
+{
+public:
+ cmGeneratorExpressionInterpreter(cmLocalGenerator* localGenerator,
+ std::string config,
+ cmGeneratorTarget const* headTarget,
+ std::string lang = std::string())
+ : LocalGenerator(localGenerator)
+ , Config(std::move(config))
+ , HeadTarget(headTarget)
+ , Language(std::move(lang))
+ {
+ }
+
+ cmGeneratorExpressionInterpreter(cmGeneratorExpressionInterpreter const&) =
+ delete;
+ cmGeneratorExpressionInterpreter& operator=(
+ cmGeneratorExpressionInterpreter const&) = delete;
+
+ const std::string& Evaluate(const char* expression,
+ const std::string& property);
+ const std::string& Evaluate(const std::string& expression,
+ const std::string& property)
+ {
+ return this->Evaluate(expression.c_str(), property);
+ }
+
+protected:
+ cmGeneratorExpression GeneratorExpression;
+ std::unique_ptr<cmCompiledGeneratorExpression> CompiledGeneratorExpression;
+ cmLocalGenerator* LocalGenerator = nullptr;
+ std::string Config;
+ cmGeneratorTarget const* HeadTarget = nullptr;
+ std::string Language;
+};
+
#endif
diff --git a/Source/cmGeneratorExpressionContext.cxx b/Source/cmGeneratorExpressionContext.cxx
index a6dde5d39..6d973310c 100644
--- a/Source/cmGeneratorExpressionContext.cxx
+++ b/Source/cmGeneratorExpressionContext.cxx
@@ -2,15 +2,17 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGeneratorExpressionContext.h"
+#include <utility>
+
cmGeneratorExpressionContext::cmGeneratorExpressionContext(
- cmLocalGenerator* lg, std::string const& config, bool quiet,
+ cmLocalGenerator* lg, std::string config, bool quiet,
cmGeneratorTarget const* headTarget, const cmGeneratorTarget* currentTarget,
- bool evaluateForBuildsystem, cmListFileBacktrace const& backtrace,
- std::string const& language)
- : Backtrace(backtrace)
+ bool evaluateForBuildsystem, cmListFileBacktrace backtrace,
+ std::string language)
+ : Backtrace(std::move(backtrace))
, LG(lg)
- , Config(config)
- , Language(language)
+ , Config(std::move(config))
+ , Language(std::move(language))
, HeadTarget(headTarget)
, CurrentTarget(currentTarget)
, Quiet(quiet)
diff --git a/Source/cmGeneratorExpressionContext.h b/Source/cmGeneratorExpressionContext.h
index cf292dcef..6e076bf54 100644
--- a/Source/cmGeneratorExpressionContext.h
+++ b/Source/cmGeneratorExpressionContext.h
@@ -14,19 +14,19 @@ class cmLocalGenerator;
struct cmGeneratorExpressionContext
{
- cmGeneratorExpressionContext(cmLocalGenerator* lg, std::string const& config,
+ cmGeneratorExpressionContext(cmLocalGenerator* lg, std::string config,
bool quiet, const cmGeneratorTarget* headTarget,
cmGeneratorTarget const* currentTarget,
bool evaluateForBuildsystem,
- cmListFileBacktrace const& backtrace,
- std::string const& language);
+ cmListFileBacktrace backtrace,
+ std::string language);
cmListFileBacktrace Backtrace;
std::set<cmGeneratorTarget*> DependTargets;
std::set<cmGeneratorTarget const*> AllTargets;
std::set<std::string> SeenTargetProperties;
std::set<cmGeneratorTarget const*> SourceSensitiveTargets;
- std::map<cmGeneratorTarget const*, std::map<std::string, std::string> >
+ std::map<cmGeneratorTarget const*, std::map<std::string, std::string>>
MaxLanguageStandard;
cmLocalGenerator* LG;
std::string Config;
diff --git a/Source/cmGeneratorExpressionDAGChecker.cxx b/Source/cmGeneratorExpressionDAGChecker.cxx
index c0266311b..728f2a4fd 100644
--- a/Source/cmGeneratorExpressionDAGChecker.cxx
+++ b/Source/cmGeneratorExpressionDAGChecker.cxx
@@ -7,6 +7,7 @@
#include "cmGeneratorExpressionEvaluator.h"
#include "cmGeneratorTarget.h"
#include "cmLocalGenerator.h"
+#include "cmMessageType.h"
#include "cmake.h"
#include <sstream>
@@ -14,26 +15,26 @@
#include <utility>
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
- const cmListFileBacktrace& backtrace, const std::string& target,
- const std::string& property, const GeneratorExpressionContent* content,
+ cmListFileBacktrace backtrace, cmGeneratorTarget const* target,
+ std::string property, const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* parent)
: Parent(parent)
, Target(target)
- , Property(property)
+ , Property(std::move(property))
, Content(content)
- , Backtrace(backtrace)
+ , Backtrace(std::move(backtrace))
, TransitivePropertiesOnly(false)
{
Initialize();
}
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
- const std::string& target, const std::string& property,
+ cmGeneratorTarget const* target, std::string property,
const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* parent)
: Parent(parent)
, Target(target)
- , Property(property)
+ , Property(std::move(property))
, Content(content)
, Backtrace()
, TransitivePropertiesOnly(false)
@@ -55,11 +56,11 @@ void cmGeneratorExpressionDAGChecker::Initialize()
if (CheckResult == DAG &&
(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
- TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(clang-tidy)
+ TEST_TRANSITIVE_PROPERTY_METHOD) false)) // NOLINT(*)
#undef TEST_TRANSITIVE_PROPERTY_METHOD
{
- std::map<std::string, std::set<std::string> >::const_iterator it =
- top->Seen.find(this->Target);
+ std::map<cmGeneratorTarget const*, 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;
if (propSet.find(this->Property) != propSet.end()) {
@@ -99,8 +100,8 @@ void cmGeneratorExpressionDAGChecker::ReportError(
<< " " << expr << "\n"
<< "Self reference on target \"" << context->HeadTarget->GetName()
<< "\".\n";
- context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
- parent->Backtrace);
+ context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str(), parent->Backtrace);
return;
}
@@ -111,8 +112,8 @@ void cmGeneratorExpressionDAGChecker::ReportError(
<< " " << expr << "\n"
<< "Dependency loop found.";
/* clang-format on */
- context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
- context->Backtrace);
+ context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str(), context->Backtrace);
}
int loopStep = 1;
@@ -122,8 +123,8 @@ void cmGeneratorExpressionDAGChecker::ReportError(
<< " "
<< (parent->Content ? parent->Content->GetOriginalExpression() : expr)
<< "\n";
- context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
- parent->Backtrace);
+ context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str(), parent->Backtrace);
parent = parent->Parent;
++loopStep;
}
@@ -154,7 +155,26 @@ bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly()
return top->TransitivePropertiesOnly;
}
-bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char* tgt)
+bool cmGeneratorExpressionDAGChecker::EvaluatingGenexExpression()
+{
+ return this->Property.find("TARGET_GENEX_EVAL:") == 0 ||
+ this->Property.find("GENEX_EVAL:", 0) == 0;
+}
+
+bool cmGeneratorExpressionDAGChecker::EvaluatingPICExpression()
+{
+ const cmGeneratorExpressionDAGChecker* top = this;
+ const cmGeneratorExpressionDAGChecker* parent = this->Parent;
+ while (parent) {
+ top = parent;
+ parent = parent->Parent;
+ }
+
+ return top->Property == "INTERFACE_POSITION_INDEPENDENT_CODE";
+}
+
+bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(
+ cmGeneratorTarget const* tgt)
{
const cmGeneratorExpressionDAGChecker* top = this;
const cmGeneratorExpressionDAGChecker* parent = this->Parent;
@@ -177,7 +197,7 @@ bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char* tgt)
strcmp(prop, "INTERFACE_LINK_LIBRARIES") == 0;
}
-std::string cmGeneratorExpressionDAGChecker::TopTarget() const
+cmGeneratorTarget const* cmGeneratorExpressionDAGChecker::TopTarget() const
{
const cmGeneratorExpressionDAGChecker* top = this;
const cmGeneratorExpressionDAGChecker* parent = this->Parent;
diff --git a/Source/cmGeneratorExpressionDAGChecker.h b/Source/cmGeneratorExpressionDAGChecker.h
index 557a19220..e1fba5e5c 100644
--- a/Source/cmGeneratorExpressionDAGChecker.h
+++ b/Source/cmGeneratorExpressionDAGChecker.h
@@ -3,7 +3,7 @@
#ifndef cmGeneratorExpressionDAGChecker_h
#define cmGeneratorExpressionDAGChecker_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmListFileCache.h"
@@ -13,6 +13,7 @@
struct GeneratorExpressionContent;
struct cmGeneratorExpressionContext;
+class cmGeneratorTarget;
#define CM_SELECT_BOTH(F, A1, A2) F(A1, A2)
#define CM_SELECT_FIRST(F, A1, A2) F(A1)
@@ -25,7 +26,10 @@ struct cmGeneratorExpressionContext;
SELECT(F, EvaluatingCompileOptions, COMPILE_OPTIONS) \
SELECT(F, EvaluatingAutoUicOptions, AUTOUIC_OPTIONS) \
SELECT(F, EvaluatingSources, SOURCES) \
- SELECT(F, EvaluatingCompileFeatures, COMPILE_FEATURES)
+ SELECT(F, EvaluatingCompileFeatures, COMPILE_FEATURES) \
+ SELECT(F, EvaluatingLinkOptions, LINK_OPTIONS) \
+ SELECT(F, EvaluatingLinkDirectories, LINK_DIRECTORIES) \
+ SELECT(F, EvaluatingLinkDepends, LINK_DEPENDS)
#define CM_FOR_EACH_TRANSITIVE_PROPERTY(F) \
CM_FOR_EACH_TRANSITIVE_PROPERTY_IMPL(F, CM_SELECT_BOTH)
@@ -38,13 +42,13 @@ struct cmGeneratorExpressionContext;
struct cmGeneratorExpressionDAGChecker
{
- cmGeneratorExpressionDAGChecker(const cmListFileBacktrace& backtrace,
- const std::string& target,
- const std::string& property,
+ cmGeneratorExpressionDAGChecker(cmListFileBacktrace backtrace,
+ cmGeneratorTarget const* target,
+ std::string property,
const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* parent);
- cmGeneratorExpressionDAGChecker(const std::string& target,
- const std::string& property,
+ cmGeneratorExpressionDAGChecker(cmGeneratorTarget const* target,
+ std::string property,
const GeneratorExpressionContent* content,
cmGeneratorExpressionDAGChecker* parent);
@@ -61,7 +65,9 @@ struct cmGeneratorExpressionDAGChecker
void ReportError(cmGeneratorExpressionContext* context,
const std::string& expr);
- bool EvaluatingLinkLibraries(const char* tgt = CM_NULLPTR);
+ bool EvaluatingGenexExpression();
+ bool EvaluatingPICExpression();
+ bool EvaluatingLinkLibraries(cmGeneratorTarget const* tgt = nullptr);
#define DECLARE_TRANSITIVE_PROPERTY_METHOD(METHOD) bool METHOD() const;
@@ -72,7 +78,7 @@ struct cmGeneratorExpressionDAGChecker
bool GetTransitivePropertiesOnly();
void SetTransitivePropertiesOnly() { this->TransitivePropertiesOnly = true; }
- std::string TopTarget() const;
+ cmGeneratorTarget const* TopTarget() const;
private:
Result CheckGraph() const;
@@ -80,9 +86,9 @@ private:
private:
const cmGeneratorExpressionDAGChecker* const Parent;
- const std::string Target;
+ cmGeneratorTarget const* Target;
const std::string Property;
- std::map<std::string, std::set<std::string> > Seen;
+ std::map<cmGeneratorTarget const*, std::set<std::string>> Seen;
const GeneratorExpressionContent* const Content;
const cmListFileBacktrace Backtrace;
Result CheckResult;
diff --git a/Source/cmGeneratorExpressionEvaluationFile.cxx b/Source/cmGeneratorExpressionEvaluationFile.cxx
index 15264545b..326cb0e55 100644
--- a/Source/cmGeneratorExpressionEvaluationFile.cxx
+++ b/Source/cmGeneratorExpressionEvaluationFile.cxx
@@ -2,8 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGeneratorExpressionEvaluationFile.h"
-#include "cmConfigure.h"
#include "cmsys/FStream.hxx"
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <utility>
@@ -12,19 +12,21 @@
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSourceFile.h"
+#include "cmSourceFileLocationKind.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
cmGeneratorExpressionEvaluationFile::cmGeneratorExpressionEvaluationFile(
- const std::string& input,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> outputFileExpr,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent)
- : Input(input)
- , OutputFileExpr(outputFileExpr)
- , Condition(condition)
+ std::string input,
+ std::unique_ptr<cmCompiledGeneratorExpression> outputFileExpr,
+ std::unique_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent, cmPolicies::PolicyStatus policyStatusCMP0070)
+ : Input(std::move(input))
+ , OutputFileExpr(std::move(outputFileExpr))
+ , Condition(std::move(condition))
, InputIsContent(inputIsContent)
+ , PolicyStatusCMP0070(policyStatusCMP0070)
{
}
@@ -36,7 +38,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(
std::string rawCondition = this->Condition->GetInput();
if (!rawCondition.empty()) {
std::string condResult = this->Condition->Evaluate(
- lg, config, false, CM_NULLPTR, CM_NULLPTR, CM_NULLPTR, lang);
+ lg, config, false, nullptr, nullptr, nullptr, lang);
if (condResult == "0") {
return;
}
@@ -46,15 +48,21 @@ void cmGeneratorExpressionEvaluationFile::Generate(
<< "\" did "
"not evaluate to valid content. Got \""
<< condResult << "\".";
- lg->IssueMessage(cmake::FATAL_ERROR, e.str());
+ lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
}
- const std::string outputFileName = this->OutputFileExpr->Evaluate(
- lg, config, false, CM_NULLPTR, CM_NULLPTR, CM_NULLPTR, lang);
- const std::string outputContent = inputExpression->Evaluate(
- lg, config, false, CM_NULLPTR, CM_NULLPTR, CM_NULLPTR, lang);
+ std::string outputFileName = this->OutputFileExpr->Evaluate(
+ lg, config, false, nullptr, nullptr, nullptr, lang);
+ const std::string& outputContent = inputExpression->Evaluate(
+ lg, config, false, nullptr, nullptr, nullptr, lang);
+
+ if (cmSystemTools::FileIsFullPath(outputFileName)) {
+ outputFileName = cmSystemTools::CollapseFullPath(outputFileName);
+ } else {
+ outputFileName = this->FixRelativePath(outputFileName, PathForOutput, lg);
+ }
std::map<std::string, std::string>::iterator it =
outputFiles.find(outputFileName);
@@ -69,7 +77,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(
"This is generally caused by the content evaluating the "
"configuration type, language, or location of object files:\n "
<< outputFileName;
- lg->IssueMessage(cmake::FATAL_ERROR, e.str());
+ lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
@@ -77,7 +85,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(
this->Files.push_back(outputFileName);
outputFiles[outputFileName] = outputContent;
- cmGeneratedFileStream fout(outputFileName.c_str());
+ cmGeneratedFileStream fout(outputFileName);
fout.SetCopyIfDifferent(true);
fout << outputContent;
if (fout.Close() && perm) {
@@ -92,13 +100,19 @@ void cmGeneratorExpressionEvaluationFile::CreateOutputFile(
cmGlobalGenerator* gg = lg->GetGlobalGenerator();
gg->GetEnabledLanguages(enabledLanguages);
- for (std::vector<std::string>::const_iterator le = enabledLanguages.begin();
- le != enabledLanguages.end(); ++le) {
+ for (std::string const& le : enabledLanguages) {
std::string name = this->OutputFileExpr->Evaluate(
- lg, config, false, CM_NULLPTR, CM_NULLPTR, CM_NULLPTR, *le);
- cmSourceFile* sf = lg->GetMakefile()->GetOrCreateSource(name);
+ lg, config, false, nullptr, nullptr, nullptr, le);
+ cmSourceFile* sf = lg->GetMakefile()->GetOrCreateSource(
+ name, false, cmSourceFileLocationKind::Known);
+ // Tell TraceDependencies that the file is not expected to exist
+ // on disk yet. We generate it after that runs.
sf->SetProperty("GENERATED", "1");
+ // Tell the build system generators that there is no build rule
+ // to generate the file.
+ sf->SetProperty("__CMAKE_GENERATED_BY_CMAKE", "1");
+
gg->SetFilenameTargetDepends(
sf, this->OutputFileExpr->GetSourceSensitiveTargets());
}
@@ -111,13 +125,19 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg)
if (this->InputIsContent) {
inputContent = this->Input;
} else {
- lg->GetMakefile()->AddCMakeDependFile(this->Input);
- cmSystemTools::GetPermissions(this->Input.c_str(), perm);
- cmsys::ifstream fin(this->Input.c_str());
+ std::string inputFileName = this->Input;
+ if (cmSystemTools::FileIsFullPath(inputFileName)) {
+ inputFileName = cmSystemTools::CollapseFullPath(inputFileName);
+ } else {
+ inputFileName = this->FixRelativePath(inputFileName, PathForInput, lg);
+ }
+ lg->GetMakefile()->AddCMakeDependFile(inputFileName);
+ cmSystemTools::GetPermissions(inputFileName.c_str(), perm);
+ cmsys::ifstream fin(inputFileName.c_str());
if (!fin) {
std::ostringstream e;
- e << "Evaluation file \"" << this->Input << "\" cannot be read.";
- lg->IssueMessage(cmake::FATAL_ERROR, e.str());
+ e << "Evaluation file \"" << inputFileName << "\" cannot be read.";
+ lg->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
@@ -132,7 +152,7 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg)
cmListFileBacktrace lfbt = this->OutputFileExpr->GetBacktrace();
cmGeneratorExpression contentGE(lfbt);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> inputExpression =
+ std::unique_ptr<cmCompiledGeneratorExpression> inputExpression =
contentGE.Parse(inputContent);
std::map<std::string, std::string> outputFiles;
@@ -141,21 +161,73 @@ void cmGeneratorExpressionEvaluationFile::Generate(cmLocalGenerator* lg)
lg->GetMakefile()->GetConfigurations(allConfigs);
if (allConfigs.empty()) {
- allConfigs.push_back("");
+ allConfigs.emplace_back();
}
std::vector<std::string> enabledLanguages;
cmGlobalGenerator* gg = lg->GetGlobalGenerator();
gg->GetEnabledLanguages(enabledLanguages);
- for (std::vector<std::string>::const_iterator le = enabledLanguages.begin();
- le != enabledLanguages.end(); ++le) {
- for (std::vector<std::string>::const_iterator li = allConfigs.begin();
- li != allConfigs.end(); ++li) {
- this->Generate(lg, *li, *le, inputExpression.get(), outputFiles, perm);
+ for (std::string const& le : enabledLanguages) {
+ for (std::string const& li : allConfigs) {
+ this->Generate(lg, li, le, inputExpression.get(), outputFiles, perm);
if (cmSystemTools::GetFatalErrorOccured()) {
return;
}
}
}
}
+
+std::string cmGeneratorExpressionEvaluationFile::FixRelativePath(
+ std::string const& relativePath, PathRole role, cmLocalGenerator* lg)
+{
+ std::string resultPath;
+ switch (this->PolicyStatusCMP0070) {
+ case cmPolicies::WARN: {
+ std::string arg;
+ switch (role) {
+ case PathForInput:
+ arg = "INPUT";
+ break;
+ case PathForOutput:
+ arg = "OUTPUT";
+ break;
+ }
+ std::ostringstream w;
+ /* clang-format off */
+ w <<
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0070) << "\n"
+ "file(GENERATE) given relative " << arg << " path:\n"
+ " " << relativePath << "\n"
+ "This is not defined behavior unless CMP0070 is set to NEW. "
+ "For compatibility with older versions of CMake, the previous "
+ "undefined behavior will be used."
+ ;
+ /* clang-format on */
+ lg->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
+ }
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ // OLD behavior is to use the relative path unchanged,
+ // which ends up being used relative to the working dir.
+ resultPath = relativePath;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ // NEW behavior is to interpret the relative path with respect
+ // to the current source or binary directory.
+ switch (role) {
+ case PathForInput:
+ resultPath = cmSystemTools::CollapseFullPath(
+ relativePath, lg->GetCurrentSourceDirectory());
+ break;
+ case PathForOutput:
+ resultPath = cmSystemTools::CollapseFullPath(
+ relativePath, lg->GetCurrentBinaryDirectory());
+ break;
+ }
+ break;
+ }
+ return resultPath;
+}
diff --git a/Source/cmGeneratorExpressionEvaluationFile.h b/Source/cmGeneratorExpressionEvaluationFile.h
index 98727460e..89a239057 100644
--- a/Source/cmGeneratorExpressionEvaluationFile.h
+++ b/Source/cmGeneratorExpressionEvaluationFile.h
@@ -6,11 +6,12 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
+#include <memory> // IWYU pragma: keep
#include <string>
#include <vector>
#include "cmGeneratorExpression.h"
-#include "cm_auto_ptr.hxx"
+#include "cmPolicies.h"
#include "cm_sys_stat.h"
class cmLocalGenerator;
@@ -19,9 +20,10 @@ class cmGeneratorExpressionEvaluationFile
{
public:
cmGeneratorExpressionEvaluationFile(
- const std::string& input,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> outputFileExpr,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent);
+ std::string input,
+ std::unique_ptr<cmCompiledGeneratorExpression> outputFileExpr,
+ std::unique_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent, cmPolicies::PolicyStatus policyStatusCMP0070);
void Generate(cmLocalGenerator* lg);
@@ -35,12 +37,21 @@ private:
cmCompiledGeneratorExpression* inputExpression,
std::map<std::string, std::string>& outputFiles, mode_t perm);
+ enum PathRole
+ {
+ PathForInput,
+ PathForOutput
+ };
+ std::string FixRelativePath(std::string const& filePath, PathRole role,
+ cmLocalGenerator* lg);
+
private:
const std::string Input;
- const CM_AUTO_PTR<cmCompiledGeneratorExpression> OutputFileExpr;
- const CM_AUTO_PTR<cmCompiledGeneratorExpression> Condition;
+ const std::unique_ptr<cmCompiledGeneratorExpression> OutputFileExpr;
+ const std::unique_ptr<cmCompiledGeneratorExpression> Condition;
std::vector<std::string> Files;
const bool InputIsContent;
+ cmPolicies::PolicyStatus PolicyStatusCMP0070;
};
#endif
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index 6ce4a8e72..744201899 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -25,28 +25,25 @@ std::string GeneratorExpressionContent::ProcessArbitraryContent(
const cmGeneratorExpressionNode* node, const std::string& identifier,
cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagChecker,
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator
pit) const
{
std::string result;
const std::vector<
- std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator pend =
+ 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) {
+ for (cmGeneratorExpressionEvaluator* pExprEval : *pit) {
if (node->RequiresLiteralInput()) {
- if ((*it)->GetType() != cmGeneratorExpressionEvaluator::Text) {
- reportError(context, this->GetOriginalExpression(), "$<" +
- identifier + "> expression requires literal input.");
+ if (pExprEval->GetType() != cmGeneratorExpressionEvaluator::Text) {
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier +
+ "> expression requires literal input.");
return std::string();
}
}
- result += (*it)->Evaluate(context, dagChecker);
+ result += pExprEval->Evaluate(context, dagChecker);
if (context->HadError) {
return std::string();
}
@@ -69,12 +66,9 @@ std::string GeneratorExpressionContent::Evaluate(
{
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);
+ for (cmGeneratorExpressionEvaluator* pExprEval :
+ this->IdentifierChildren) {
+ identifier += pExprEval->Evaluate(context, dagChecker);
if (context->HadError) {
return std::string();
}
@@ -122,43 +116,39 @@ std::string GeneratorExpressionContent::EvaluateParameters(
{
const int numExpected = node->NumExpectedParameters();
{
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator
pit = this->ParamChildren.begin();
const std::vector<
- std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator pend =
+ 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);
+ parameters.push_back(this->ProcessArbitraryContent(
+ node, identifier, context, dagChecker, pit));
return std::string();
}
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);
+ for (cmGeneratorExpressionEvaluator* pExprEval : *pit) {
+ parameter += pExprEval->Evaluate(context, dagChecker);
if (context->HadError) {
return std::string();
}
}
- parameters.push_back(parameter);
+ parameters.push_back(std::move(parameter));
}
}
if ((numExpected > cmGeneratorExpressionNode::DynamicParameters &&
- (unsigned int)numExpected != parameters.size())) {
+ static_cast<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 +
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier +
"> expression requires "
"exactly one parameter.");
} else {
@@ -173,12 +163,18 @@ std::string GeneratorExpressionContent::EvaluateParameters(
if (numExpected == cmGeneratorExpressionNode::OneOrMoreParameters &&
parameters.empty()) {
- reportError(context, this->GetOriginalExpression(), "$<" + identifier +
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier +
"> expression requires at least one parameter.");
- }
- if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters &&
- parameters.size() > 1) {
- reportError(context, this->GetOriginalExpression(), "$<" + identifier +
+ } else if (numExpected == cmGeneratorExpressionNode::TwoOrMoreParameters &&
+ parameters.size() < 2) {
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier +
+ "> expression requires at least two parameters.");
+ } else if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters &&
+ parameters.size() > 1) {
+ reportError(context, this->GetOriginalExpression(),
+ "$<" + identifier +
"> expression requires one or zero parameters.");
}
return std::string();
@@ -188,5 +184,5 @@ GeneratorExpressionContent::~GeneratorExpressionContent()
{
cmDeleteAll(this->IdentifierChildren);
std::for_each(this->ParamChildren.begin(), this->ParamChildren.end(),
- cmDeleteAll<std::vector<cmGeneratorExpressionEvaluator*> >);
+ cmDeleteAll<std::vector<cmGeneratorExpressionEvaluator*>>);
}
diff --git a/Source/cmGeneratorExpressionEvaluator.h b/Source/cmGeneratorExpressionEvaluator.h
index a0a826ac6..453015262 100644
--- a/Source/cmGeneratorExpressionEvaluator.h
+++ b/Source/cmGeneratorExpressionEvaluator.h
@@ -3,10 +3,11 @@
#ifndef cmGeneratorExpressionEvaluator_h
#define cmGeneratorExpressionEvaluator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <stddef.h>
#include <string>
+#include <utility>
#include <vector>
struct cmGeneratorExpressionContext;
@@ -15,8 +16,13 @@ struct cmGeneratorExpressionNode;
struct cmGeneratorExpressionEvaluator
{
- cmGeneratorExpressionEvaluator() {}
- virtual ~cmGeneratorExpressionEvaluator() {}
+ cmGeneratorExpressionEvaluator() = default;
+ virtual ~cmGeneratorExpressionEvaluator() = default;
+
+ cmGeneratorExpressionEvaluator(cmGeneratorExpressionEvaluator const&) =
+ delete;
+ cmGeneratorExpressionEvaluator& operator=(
+ cmGeneratorExpressionEvaluator const&) = delete;
enum Type
{
@@ -28,9 +34,6 @@ struct cmGeneratorExpressionEvaluator
virtual std::string Evaluate(cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker*) const = 0;
-
-private:
- CM_DISABLE_COPY(cmGeneratorExpressionEvaluator)
};
struct TextContent : public cmGeneratorExpressionEvaluator
@@ -42,12 +45,12 @@ struct TextContent : public cmGeneratorExpressionEvaluator
}
std::string Evaluate(cmGeneratorExpressionContext*,
- cmGeneratorExpressionDAGChecker*) const CM_OVERRIDE
+ cmGeneratorExpressionDAGChecker*) const override
{
return std::string(this->Content, this->Length);
}
- Type GetType() const CM_OVERRIDE
+ Type GetType() const override
{
return cmGeneratorExpressionEvaluator::Text;
}
@@ -64,30 +67,29 @@ private:
struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
{
GeneratorExpressionContent(const char* startContent, size_t length);
- void SetIdentifier(
- std::vector<cmGeneratorExpressionEvaluator*> const& identifier)
+
+ void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
{
- this->IdentifierChildren = identifier;
+ this->IdentifierChildren = std::move(identifier);
}
void SetParameters(
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> > const&
- parameters)
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*>> parameters)
{
- this->ParamChildren = parameters;
+ this->ParamChildren = std::move(parameters);
}
- Type GetType() const CM_OVERRIDE
+ Type GetType() const override
{
return cmGeneratorExpressionEvaluator::Generator;
}
std::string Evaluate(cmGeneratorExpressionContext* context,
- cmGeneratorExpressionDAGChecker*) const CM_OVERRIDE;
+ cmGeneratorExpressionDAGChecker*) const override;
std::string GetOriginalExpression() const;
- ~GeneratorExpressionContent() CM_OVERRIDE;
+ ~GeneratorExpressionContent() override;
private:
std::string EvaluateParameters(const cmGeneratorExpressionNode* node,
@@ -100,12 +102,12 @@ private:
const cmGeneratorExpressionNode* node, const std::string& identifier,
cmGeneratorExpressionContext* context,
cmGeneratorExpressionDAGChecker* dagChecker,
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*>>::const_iterator
pit) const;
private:
std::vector<cmGeneratorExpressionEvaluator*> IdentifierChildren;
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> > ParamChildren;
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*>> ParamChildren;
const char* StartContent;
size_t ContentLength;
};
diff --git a/Source/cmGeneratorExpressionLexer.cxx b/Source/cmGeneratorExpressionLexer.cxx
index 931fd4d62..a7f090ac7 100644
--- a/Source/cmGeneratorExpressionLexer.cxx
+++ b/Source/cmGeneratorExpressionLexer.cxx
@@ -2,18 +2,13 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGeneratorExpressionLexer.h"
-cmGeneratorExpressionLexer::cmGeneratorExpressionLexer()
- : SawBeginExpression(false)
- , SawGeneratorExpression(false)
-{
-}
+cmGeneratorExpressionLexer::cmGeneratorExpressionLexer() = default;
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));
+ result.emplace_back(cmGeneratorExpressionToken::Text, upto, c - upto);
}
}
@@ -22,6 +17,12 @@ std::vector<cmGeneratorExpressionToken> cmGeneratorExpressionLexer::Tokenize(
{
std::vector<cmGeneratorExpressionToken> result;
+ if (input.find('$') == std::string::npos) {
+ result.emplace_back(cmGeneratorExpressionToken::Text, input.c_str(),
+ input.size());
+ return result;
+ }
+
const char* c = input.c_str();
const char* upto = c;
@@ -30,8 +31,8 @@ std::vector<cmGeneratorExpressionToken> cmGeneratorExpressionLexer::Tokenize(
case '$':
if (c[1] == '<') {
InsertText(upto, c, result);
- result.push_back(cmGeneratorExpressionToken(
- cmGeneratorExpressionToken::BeginExpression, c, 2));
+ result.emplace_back(cmGeneratorExpressionToken::BeginExpression, c,
+ 2);
upto = c + 2;
++c;
SawBeginExpression = true;
@@ -39,21 +40,18 @@ std::vector<cmGeneratorExpressionToken> cmGeneratorExpressionLexer::Tokenize(
break;
case '>':
InsertText(upto, c, result);
- result.push_back(cmGeneratorExpressionToken(
- cmGeneratorExpressionToken::EndExpression, c, 1));
+ result.emplace_back(cmGeneratorExpressionToken::EndExpression, c, 1);
upto = c + 1;
SawGeneratorExpression = SawBeginExpression;
break;
case ':':
InsertText(upto, c, result);
- result.push_back(cmGeneratorExpressionToken(
- cmGeneratorExpressionToken::ColonSeparator, c, 1));
+ result.emplace_back(cmGeneratorExpressionToken::ColonSeparator, c, 1);
upto = c + 1;
break;
case ',':
InsertText(upto, c, result);
- result.push_back(cmGeneratorExpressionToken(
- cmGeneratorExpressionToken::CommaSeparator, c, 1));
+ result.emplace_back(cmGeneratorExpressionToken::CommaSeparator, c, 1);
upto = c + 1;
break;
default:
diff --git a/Source/cmGeneratorExpressionLexer.h b/Source/cmGeneratorExpressionLexer.h
index e53f0b547..bf2430818 100644
--- a/Source/cmGeneratorExpressionLexer.h
+++ b/Source/cmGeneratorExpressionLexer.h
@@ -46,8 +46,8 @@ public:
}
private:
- bool SawBeginExpression;
- bool SawGeneratorExpression;
+ bool SawBeginExpression = false;
+ bool SawGeneratorExpression = false;
};
#endif
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index a57d2a0d8..a60c75cd9 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -12,21 +12,28 @@
#include "cmLinkItem.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
+#include "cmRange.h"
+#include "cmState.h"
+#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cm_auto_ptr.hxx"
+#include "cm_static_string_view.hxx"
+#include "cm_string_view.hxx"
#include "cmake.h"
-#include "cmConfigure.h"
#include "cmsys/RegularExpression.hxx"
#include "cmsys/String.h"
+
#include <algorithm>
#include <assert.h>
#include <errno.h>
+#include <iterator>
#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <sstream>
#include <stdlib.h>
@@ -40,7 +47,7 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
cmGeneratorExpressionDAGChecker* dagChecker)
{
cmGeneratorExpression ge(context->Backtrace);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
std::string result =
cge->Evaluate(lg, context->Config, context->Quiet, headTarget,
@@ -56,17 +63,17 @@ std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
static const struct ZeroNode : public cmGeneratorExpressionNode
{
- ZeroNode() {}
+ ZeroNode() {} // NOLINT(modernize-use-equals-default)
- bool GeneratesContent() const CM_OVERRIDE { return false; }
+ bool GeneratesContent() const override { return false; }
- bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
+ bool AcceptsArbitraryContentParameter() const override { return true; }
- std::string Evaluate(const std::vector<std::string>& /*parameters*/,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& /*parameters*/,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return std::string();
}
@@ -74,15 +81,15 @@ static const struct ZeroNode : public cmGeneratorExpressionNode
static const struct OneNode : public cmGeneratorExpressionNode
{
- OneNode() {}
+ OneNode() {} // NOLINT(modernize-use-equals-default)
- bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
+ bool AcceptsArbitraryContentParameter() const override { return true; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return parameters.front();
}
@@ -92,85 +99,89 @@ 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; \
- } \
- 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
+struct BooleanOpNode : public cmGeneratorExpressionNode
{
- NotNode() {}
+ BooleanOpNode(const char* op_, const char* successVal_,
+ const char* failureVal_)
+ : op(op_)
+ , successVal(successVal_)
+ , failureVal(failureVal_)
+ {
+ }
+
+ int NumExpectedParameters() const override { return OneOrMoreParameters; }
std::string Evaluate(const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ cmGeneratorExpressionDAGChecker*) const override
+ {
+ for (std::string const& param : parameters) {
+ if (param == this->failureVal) {
+ return this->failureVal;
+ }
+ if (param != this->successVal) {
+ std::ostringstream e;
+ e << "Parameters to $<" << this->op;
+ e << "> must resolve to either '0' or '1'.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return std::string();
+ }
+ }
+ return this->successVal;
+ }
+
+ const char *const op, *const successVal, *const failureVal;
+};
+
+static const BooleanOpNode andNode("AND", "1", "0"), orNode("OR", "0", "1");
+
+static const struct NotNode : public cmGeneratorExpressionNode
+{
+ NotNode() {} // NOLINT(modernize-use-equals-default)
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- if (*parameters.begin() != "0" && *parameters.begin() != "1") {
+ if (parameters.front() != "0" && parameters.front() != "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";
+ return parameters.front() == "0" ? "1" : "0";
}
} notNode;
static const struct BoolNode : public cmGeneratorExpressionNode
{
- BoolNode() {}
+ BoolNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 1; }
+ int NumExpectedParameters() const override { return 1; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0";
+ return !cmSystemTools::IsOff(parameters.front()) ? "1" : "0";
}
} boolNode;
static const struct IfNode : public cmGeneratorExpressionNode
{
- IfNode() {}
+ IfNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 3; }
+ int NumExpectedParameters() const override { return 3; }
std::string Evaluate(const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker*) const CM_OVERRIDE
+ cmGeneratorExpressionDAGChecker*) const override
{
if (parameters[0] != "1" && parameters[0] != "0") {
reportError(context, content->GetOriginalExpression(),
@@ -184,109 +195,379 @@ static const struct IfNode : public cmGeneratorExpressionNode
static const struct StrEqualNode : public cmGeneratorExpressionNode
{
- StrEqualNode() {}
+ StrEqualNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
+ int NumExpectedParameters() const override { return 2; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- return *parameters.begin() == parameters[1] ? "1" : "0";
+ return parameters.front() == parameters[1] ? "1" : "0";
}
} strEqualNode;
static const struct EqualNode : public cmGeneratorExpressionNode
{
- EqualNode() {}
+ EqualNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
+ int NumExpectedParameters() const override { return 2; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- char* pEnd;
+ long numbers[2];
+ for (int i = 0; i < 2; ++i) {
+ if (!ParameterToLong(parameters[i].c_str(), &numbers[i])) {
+ reportError(context, content->GetOriginalExpression(),
+ "$<EQUAL> parameter " + parameters[i] +
+ " is not a valid integer.");
+ return {};
+ }
+ }
+ return numbers[0] == numbers[1] ? "1" : "0";
+ }
- int base = 0;
- bool flipSign = false;
+ static bool ParameterToLong(const char* param, long* outResult)
+ {
+ const char isNegative = param[0] == '-';
- const char* lhs = parameters[0].c_str();
- if (cmHasLiteralPrefix(lhs, "0b") || cmHasLiteralPrefix(lhs, "0B")) {
+ int base = 0;
+ if (cmHasLiteralPrefix(param, "0b") || cmHasLiteralPrefix(param, "0B")) {
base = 2;
- lhs += 2;
- }
- if (cmHasLiteralPrefix(lhs, "-0b") || cmHasLiteralPrefix(lhs, "-0B")) {
+ param += 2;
+ } else if (cmHasLiteralPrefix(param, "-0b") ||
+ cmHasLiteralPrefix(param, "-0B") ||
+ cmHasLiteralPrefix(param, "+0b") ||
+ cmHasLiteralPrefix(param, "+0B")) {
base = 2;
- lhs += 3;
- flipSign = true;
+ param += 3;
}
- if (cmHasLiteralPrefix(lhs, "+0b") || cmHasLiteralPrefix(lhs, "+0B")) {
- base = 2;
- lhs += 3;
+
+ char* pEnd;
+ long result = strtol(param, &pEnd, base);
+ if (pEnd == param || *pEnd != '\0' || errno == ERANGE) {
+ return false;
+ }
+ if (isNegative && result > 0) {
+ result *= -1;
+ }
+ *outResult = result;
+ return true;
+ }
+} equalNode;
+
+static const struct InListNode : public cmGeneratorExpressionNode
+{
+ InListNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 2; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
+ {
+ std::vector<std::string> values, checkValues;
+ bool check = false;
+ switch (context->LG->GetPolicyStatus(cmPolicies::CMP0085)) {
+ case cmPolicies::WARN:
+ if (parameters.front().empty()) {
+ check = true;
+ cmSystemTools::ExpandListArgument(parameters[1], checkValues, true);
+ }
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ cmSystemTools::ExpandListArgument(parameters[1], values);
+ if (check && values != checkValues) {
+ std::ostringstream e;
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0085)
+ << "\nSearch Item:\n \"" << parameters.front()
+ << "\"\nList:\n \"" << parameters[1] << "\"\n";
+ context->LG->GetCMakeInstance()->IssueMessage(
+ MessageType ::AUTHOR_WARNING, e.str(), context->Backtrace);
+ return "0";
+ }
+ if (values.empty()) {
+ return "0";
+ }
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ cmSystemTools::ExpandListArgument(parameters[1], values, true);
+ break;
+ }
+
+ return std::find(values.cbegin(), values.cend(), parameters.front()) ==
+ values.cend()
+ ? "0"
+ : "1";
+ }
+} inListNode;
+
+static const struct FilterNode : public cmGeneratorExpressionNode
+{
+ FilterNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 3; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
+ {
+ if (parameters.size() != 3) {
+ reportError(context, content->GetOriginalExpression(),
+ "$<FILTER:...> expression requires three parameters");
+ return {};
+ }
+
+ if (parameters[1] != "INCLUDE" && parameters[1] != "EXCLUDE") {
+ reportError(
+ context, content->GetOriginalExpression(),
+ "$<FILTER:...> second parameter must be either INCLUDE or EXCLUDE");
+ return {};
+ }
+
+ const bool exclude = parameters[1] == "EXCLUDE";
+
+ cmsys::RegularExpression re;
+ if (!re.compile(parameters[2])) {
+ reportError(context, content->GetOriginalExpression(),
+ "$<FILTER:...> failed to compile regex");
+ return {};
+ }
+
+ std::vector<std::string> values, result;
+ cmSystemTools::ExpandListArgument(parameters.front(), values, true);
+
+ std::copy_if(values.cbegin(), values.cend(), std::back_inserter(result),
+ [&re, exclude](std::string const& input) {
+ return exclude ^ re.find(input);
+ });
+ return cmJoin(cmMakeRange(result.cbegin(), result.cend()), ";");
+ }
+} filterNode;
+
+static const struct RemoveDuplicatesNode : public cmGeneratorExpressionNode
+{
+ RemoveDuplicatesNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 1; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
+ {
+ if (parameters.size() != 1) {
+ reportError(
+ context, content->GetOriginalExpression(),
+ "$<REMOVE_DUPLICATES:...> expression requires one parameter");
}
- long lnum = strtol(lhs, &pEnd, base);
- if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
+ std::vector<std::string> values;
+ cmSystemTools::ExpandListArgument(parameters.front(), values, true);
+
+ auto valuesEnd = cmRemoveDuplicates(values);
+ auto valuesBegin = values.cbegin();
+ return cmJoin(cmMakeRange(valuesBegin, valuesEnd), ";");
+ }
+
+} removeDuplicatesNode;
+
+static const struct TargetExistsNode : public cmGeneratorExpressionNode
+{
+ TargetExistsNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 1; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
+ {
+ if (parameters.size() != 1) {
reportError(context, content->GetOriginalExpression(),
- "$<EQUAL> parameter " + parameters[0] +
- " is not a valid integer.");
+ "$<TARGET_EXISTS:...> expression requires one parameter");
return std::string();
}
- if (flipSign) {
- lnum = -lnum;
+ std::string targetName = parameters.front();
+ if (targetName.empty() ||
+ !cmGeneratorExpression::IsValidTargetName(targetName)) {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_EXISTS:tgt> expression requires a non-empty "
+ "valid target name.");
+ return std::string();
}
- base = 0;
- flipSign = false;
+ return context->LG->GetMakefile()->FindTargetToUse(targetName) ? "1" : "0";
+ }
+} targetExistsNode;
- const char* rhs = parameters[1].c_str();
- if (cmHasLiteralPrefix(rhs, "0b") || cmHasLiteralPrefix(rhs, "0B")) {
- base = 2;
- rhs += 2;
+static const struct TargetNameIfExistsNode : public cmGeneratorExpressionNode
+{
+ TargetNameIfExistsNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 1; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
+ {
+ if (parameters.size() != 1) {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_NAME_IF_EXISTS:...> expression requires one "
+ "parameter");
+ return std::string();
}
- if (cmHasLiteralPrefix(rhs, "-0b") || cmHasLiteralPrefix(rhs, "-0B")) {
- base = 2;
- rhs += 3;
- flipSign = true;
+
+ std::string targetName = parameters.front();
+ if (targetName.empty() ||
+ !cmGeneratorExpression::IsValidTargetName(targetName)) {
+ reportError(context, content->GetOriginalExpression(),
+ "$<TARGET_NAME_IF_EXISTS:tgt> expression requires a "
+ "non-empty valid target name.");
+ return std::string();
}
- if (cmHasLiteralPrefix(rhs, "+0b") || cmHasLiteralPrefix(rhs, "+0B")) {
- base = 2;
- rhs += 3;
+
+ return context->LG->GetMakefile()->FindTargetToUse(targetName)
+ ? targetName
+ : std::string();
+ }
+} targetNameIfExistsNode;
+
+struct GenexEvaluator : public cmGeneratorExpressionNode
+{
+ GenexEvaluator() {} // NOLINT(modernize-use-equals-default)
+
+protected:
+ std::string EvaluateExpression(
+ const std::string& genexOperator, const std::string& expression,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagCheckerParent) const
+ {
+ if (context->HeadTarget) {
+ cmGeneratorExpressionDAGChecker dagChecker(
+ context->Backtrace, context->HeadTarget,
+ genexOperator + ":" + expression, content, dagCheckerParent);
+ switch (dagChecker.Check()) {
+ case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
+ case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: {
+ dagChecker.ReportError(context, content->GetOriginalExpression());
+ return std::string();
+ }
+ case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
+ case cmGeneratorExpressionDAGChecker::DAG:
+ break;
+ }
+
+ return this->EvaluateDependentExpression(
+ expression, context->LG, context, context->HeadTarget,
+ context->CurrentTarget, &dagChecker);
}
- long rnum = strtol(rhs, &pEnd, base);
- if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
+ return this->EvaluateDependentExpression(
+ expression, context->LG, context, context->HeadTarget,
+ context->CurrentTarget, dagCheckerParent);
+ }
+};
+
+static const struct TargetGenexEvalNode : public GenexEvaluator
+{
+ TargetGenexEvalNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 2; }
+
+ bool AcceptsArbitraryContentParameter() const override { return true; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
+ {
+ const std::string& targetName = parameters.front();
+ if (targetName.empty() ||
+ !cmGeneratorExpression::IsValidTargetName(targetName)) {
reportError(context, content->GetOriginalExpression(),
- "$<EQUAL> parameter " + parameters[1] +
- " is not a valid integer.");
+ "$<TARGET_GENEX_EVAL:tgt, ...> expression requires a "
+ "non-empty valid target name.");
+ return std::string();
+ }
+
+ const auto* target = context->LG->FindGeneratorTargetToUse(targetName);
+ if (!target) {
+ std::ostringstream e;
+ e << "$<TARGET_GENEX_EVAL:tgt, ...> target \"" << targetName
+ << "\" not found.";
+ reportError(context, content->GetOriginalExpression(), e.str());
return std::string();
}
- if (flipSign) {
- rnum = -rnum;
+ const std::string& expression = parameters[1];
+ if (expression.empty()) {
+ return expression;
}
- return lnum == rnum ? "1" : "0";
+ cmGeneratorExpressionContext targetContext(
+ context->LG, context->Config, context->Quiet, target, target,
+ context->EvaluateForBuildsystem, context->Backtrace, context->Language);
+
+ return this->EvaluateExpression("TARGET_GENEX_EVAL", expression,
+ &targetContext, content, dagCheckerParent);
}
-} equalNode;
+} targetGenexEvalNode;
+
+static const struct GenexEvalNode : public GenexEvaluator
+{
+ GenexEvalNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 1; }
+
+ bool AcceptsArbitraryContentParameter() const override { return true; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
+ {
+ const std::string& expression = parameters[0];
+ if (expression.empty()) {
+ return expression;
+ }
+
+ return this->EvaluateExpression("GENEX_EVAL", expression, context, content,
+ dagCheckerParent);
+ }
+} genexEvalNode;
static const struct LowerCaseNode : public cmGeneratorExpressionNode
{
- LowerCaseNode() {}
+ LowerCaseNode() {} // NOLINT(modernize-use-equals-default)
- bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
+ bool AcceptsArbitraryContentParameter() const override { return true; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return cmSystemTools::LowerCase(parameters.front());
}
@@ -294,15 +575,15 @@ static const struct LowerCaseNode : public cmGeneratorExpressionNode
static const struct UpperCaseNode : public cmGeneratorExpressionNode
{
- UpperCaseNode() {}
+ UpperCaseNode() {} // NOLINT(modernize-use-equals-default)
- bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
+ bool AcceptsArbitraryContentParameter() const override { return true; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return cmSystemTools::UpperCase(parameters.front());
}
@@ -310,73 +591,66 @@ static const struct UpperCaseNode : public cmGeneratorExpressionNode
static const struct MakeCIdentifierNode : public cmGeneratorExpressionNode
{
- MakeCIdentifierNode() {}
+ MakeCIdentifierNode() {} // NOLINT(modernize-use-equals-default)
- bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
+ bool AcceptsArbitraryContentParameter() const override { return true; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return cmSystemTools::MakeCidentifier(parameters.front());
}
} makeCIdentifierNode;
-static const struct Angle_RNode : public cmGeneratorExpressionNode
+template <char C>
+struct CharacterNode : public cmGeneratorExpressionNode
{
- Angle_RNode() {}
+ CharacterNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 0; }
+ int NumExpectedParameters() const override { return 0; }
- std::string Evaluate(const std::vector<std::string>& /*parameters*/,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& /*parameters*/,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- return ">";
+ return { C };
}
-} angle_rNode;
+};
+static const CharacterNode<'>'> angle_rNode;
+static const CharacterNode<','> commaNode;
+static const CharacterNode<';'> semicolonNode;
-static const struct CommaNode : public cmGeneratorExpressionNode
+struct CompilerIdNode : public cmGeneratorExpressionNode
{
- CommaNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return 0; }
-
- std::string Evaluate(const std::vector<std::string>& /*parameters*/,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ CompilerIdNode(const char* compilerLang)
+ : CompilerLanguage(compilerLang)
{
- return ",";
}
-} commaNode;
-static const struct SemicolonNode : public cmGeneratorExpressionNode
-{
- SemicolonNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return 0; }
+ int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
- std::string Evaluate(const std::vector<std::string>& /*parameters*/,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
{
- return ";";
+ if (!context->HeadTarget) {
+ std::ostringstream e;
+ e << "$<" << this->CompilerLanguage
+ << "_COMPILER_ID> may only be used with binary targets. It may "
+ "not be used with add_custom_command or add_custom_target.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return {};
+ }
+ return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
+ this->CompilerLanguage);
}
-} semicolonNode;
-
-struct CompilerIdNode : public cmGeneratorExpressionNode
-{
- CompilerIdNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; }
std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
@@ -384,95 +658,82 @@ struct CompilerIdNode : public cmGeneratorExpressionNode
cmGeneratorExpressionDAGChecker* /*unused*/,
const std::string& lang) const
{
- const char* compilerId = context->LG->GetMakefile()->GetSafeDefinition(
- "CMAKE_" + lang + "_COMPILER_ID");
+ std::string const& compilerId =
+ context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang +
+ "_COMPILER_ID");
if (parameters.empty()) {
- 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();
+ return compilerId;
}
- if (!compilerId) {
+ if (compilerId.empty()) {
return parameters.front().empty() ? "1" : "0";
}
+ static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
- if (strcmp(parameters.begin()->c_str(), compilerId) == 0) {
- return "1";
- }
+ for (auto& param : parameters) {
- if (cmsysString_strcasecmp(parameters.begin()->c_str(), compilerId) == 0) {
- switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) {
- case cmPolicies::WARN: {
- std::ostringstream e;
- e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044);
- context->LG->GetCMakeInstance()->IssueMessage(
- cmake::AUTHOR_WARNING, e.str(), context->Backtrace);
- CM_FALLTHROUGH;
+ if (!compilerIdValidator.find(param)) {
+ reportError(context, content->GetOriginalExpression(),
+ "Expression syntax not recognized.");
+ return std::string();
+ }
+
+ if (strcmp(param.c_str(), compilerId.c_str()) == 0) {
+ return "1";
+ }
+
+ if (cmsysString_strcasecmp(param.c_str(), compilerId.c_str()) == 0) {
+ switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) {
+ case cmPolicies::WARN: {
+ std::ostringstream e;
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044);
+ context->LG->GetCMakeInstance()->IssueMessage(
+ MessageType::AUTHOR_WARNING, e.str(), context->Backtrace);
+ CM_FALLTHROUGH;
+ }
+ case cmPolicies::OLD:
+ return "1";
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ break;
}
- case cmPolicies::OLD:
- return "1";
- case cmPolicies::NEW:
- case cmPolicies::REQUIRED_ALWAYS:
- case cmPolicies::REQUIRED_IF_USED:
- break;
}
}
return "0";
}
+
+ const char* const CompilerLanguage;
};
-static const struct CCompilerIdNode : public CompilerIdNode
-{
- CCompilerIdNode() {}
+static const CompilerIdNode cCompilerIdNode("C"), cxxCompilerIdNode("CXX"),
+ cudaCompilerIdNode("CUDA"), fortranCompilerIdNode("Fortran");
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagChecker) const
- CM_OVERRIDE
+struct CompilerVersionNode : public cmGeneratorExpressionNode
+{
+ CompilerVersionNode(const char* compilerLang)
+ : CompilerLanguage(compilerLang)
{
- 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() {}
+ int NumExpectedParameters() const override { return OneOrZeroParameters; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagChecker) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
{
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();
+ std::ostringstream e;
+ e << "$<" << this->CompilerLanguage
+ << "_COMPILER_VERSION> may only be used with binary targets. It "
+ "may not be used with add_custom_command or add_custom_target.";
+ reportError(context, content->GetOriginalExpression(), e.str());
+ return {};
}
return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
- "CXX");
+ this->CompilerLanguage);
}
-} cxxCompilerIdNode;
-
-struct CompilerVersionNode : public cmGeneratorExpressionNode
-{
- CompilerVersionNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; }
std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
@@ -480,213 +741,103 @@ struct CompilerVersionNode : public cmGeneratorExpressionNode
cmGeneratorExpressionDAGChecker* /*unused*/,
const std::string& lang) const
{
- const char* compilerVersion =
+ std::string const& compilerVersion =
context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang +
"_COMPILER_VERSION");
if (parameters.empty()) {
- return compilerVersion ? compilerVersion : "";
+ return compilerVersion;
}
static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
- if (!compilerIdValidator.find(*parameters.begin())) {
+ if (!compilerIdValidator.find(parameters.front())) {
reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");
- return std::string();
+ return {};
}
- if (!compilerVersion) {
+ if (compilerVersion.empty()) {
return parameters.front().empty() ? "1" : "0";
}
return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
- parameters.begin()->c_str(),
- compilerVersion)
+ parameters.front().c_str(),
+ compilerVersion.c_str())
? "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
- CM_OVERRIDE
- {
- 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() {}
+ const char* const CompilerLanguage;
+};
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagChecker) const
- CM_OVERRIDE
- {
- 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;
+static const CompilerVersionNode cCompilerVersionNode("C"),
+ cxxCompilerVersionNode("CXX"), cudaCompilerVersionNode("CUDA"),
+ fortranCompilerVersionNode("Fortran");
struct PlatformIdNode : public cmGeneratorExpressionNode
{
- PlatformIdNode() {}
+ PlatformIdNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; }
+ int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- const char* platformId =
+ std::string const& platformId =
context->LG->GetMakefile()->GetSafeDefinition("CMAKE_SYSTEM_NAME");
if (parameters.empty()) {
- return platformId ? platformId : "";
+ return platformId;
}
- if (!platformId) {
+ if (platformId.empty()) {
return parameters.front().empty() ? "1" : "0";
}
- if (strcmp(parameters.begin()->c_str(), platformId) == 0) {
- return "1";
+ for (auto& param : parameters) {
+ if (param == platformId) {
+ return "1";
+ }
}
return "0";
}
} platformIdNode;
-static const struct VersionGreaterNode : public cmGeneratorExpressionNode
+template <cmSystemTools::CompareOp Op>
+struct VersionNode : public cmGeneratorExpressionNode
{
- VersionGreaterNode() {}
+ VersionNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
+ int NumExpectedParameters() const override { return 2; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER,
- parameters.front().c_str(),
+ return cmSystemTools::VersionCompare(Op, parameters.front().c_str(),
parameters[1].c_str())
? "1"
: "0";
}
-} versionGreaterNode;
-
-static const struct VersionGreaterEqNode : public cmGeneratorExpressionNode
-{
- VersionGreaterEqNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
-
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
- {
- return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
- parameters.front().c_str(),
- parameters[1].c_str())
- ? "1"
- : "0";
- }
-} versionGreaterEqNode;
-
-static const struct VersionLessNode : public cmGeneratorExpressionNode
-{
- VersionLessNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
-
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
- {
- return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
- parameters.front().c_str(),
- parameters[1].c_str())
- ? "1"
- : "0";
- }
-} versionLessNode;
-
-static const struct VersionLessEqNode : public cmGeneratorExpressionNode
-{
- VersionLessEqNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
-
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
- {
- return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS_EQUAL,
- parameters.front().c_str(),
- parameters[1].c_str())
- ? "1"
- : "0";
- }
-} versionLessEqNode;
-
-static const struct VersionEqualNode : public cmGeneratorExpressionNode
-{
- VersionEqualNode() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
+};
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
- {
- return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
- parameters.front().c_str(),
- parameters[1].c_str())
- ? "1"
- : "0";
- }
-} versionEqualNode;
+static const VersionNode<cmSystemTools::OP_GREATER> versionGreaterNode;
+static const VersionNode<cmSystemTools::OP_GREATER_EQUAL> versionGreaterEqNode;
+static const VersionNode<cmSystemTools::OP_LESS> versionLessNode;
+static const VersionNode<cmSystemTools::OP_LESS_EQUAL> versionLessEqNode;
+static const VersionNode<cmSystemTools::OP_EQUAL> versionEqualNode;
static const struct LinkOnlyNode : public cmGeneratorExpressionNode
{
- LinkOnlyNode() {}
+ LinkOnlyNode() {} // NOLINT(modernize-use-equals-default)
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagChecker) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
{
if (!dagChecker) {
reportError(context, content->GetOriginalExpression(),
@@ -702,15 +853,15 @@ static const struct LinkOnlyNode : public cmGeneratorExpressionNode
static const struct ConfigurationNode : public cmGeneratorExpressionNode
{
- ConfigurationNode() {}
+ ConfigurationNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 0; }
+ int NumExpectedParameters() const override { return 0; }
- std::string Evaluate(const std::vector<std::string>& /*parameters*/,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& /*parameters*/,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
context->HadContextSensitiveCondition = true;
return context->Config;
@@ -719,22 +870,21 @@ static const struct ConfigurationNode : public cmGeneratorExpressionNode
static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
{
- ConfigurationTestNode() {}
+ ConfigurationTestNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; }
+ int NumExpectedParameters() const override { return OneOrZeroParameters; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
if (parameters.empty()) {
- return configurationNode.Evaluate(parameters, context, content,
- CM_NULLPTR);
+ return configurationNode.Evaluate(parameters, context, content, nullptr);
}
static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
- if (!configValidator.find(*parameters.begin())) {
+ if (!configValidator.find(parameters.front())) {
reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");
return std::string();
@@ -744,14 +894,14 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
return parameters.front().empty() ? "1" : "0";
}
- if (cmsysString_strcasecmp(parameters.begin()->c_str(),
+ if (cmsysString_strcasecmp(parameters.front().c_str(),
context->Config.c_str()) == 0) {
return "1";
}
if (context->CurrentTarget && context->CurrentTarget->IsImported()) {
- const char* loc = CM_NULLPTR;
- const char* imp = CM_NULLPTR;
+ const char* loc = nullptr;
+ const char* imp = nullptr;
std::string suffix;
if (context->CurrentTarget->Target->GetMappedConfig(
context->Config, &loc, &imp, suffix)) {
@@ -779,17 +929,17 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
static const struct JoinNode : public cmGeneratorExpressionNode
{
- JoinNode() {}
+ JoinNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 2; }
+ int NumExpectedParameters() const override { return 2; }
- bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
+ bool AcceptsArbitraryContentParameter() const override { return true; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
std::vector<std::string> list;
cmSystemTools::ExpandListArgument(parameters.front(), list);
@@ -799,72 +949,99 @@ static const struct JoinNode : public cmGeneratorExpressionNode
static const struct CompileLanguageNode : public cmGeneratorExpressionNode
{
- CompileLanguageNode() {}
+ CompileLanguageNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; }
+ int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagChecker) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
if (context->Language.empty()) {
reportError(
context, content->GetOriginalExpression(),
"$<COMPILE_LANGUAGE:...> may only be used to specify include "
- "directories compile definitions, compile options and to evaluate "
+ "directories, compile definitions, compile options, and to evaluate "
"components of the file(GENERATE) command.");
return std::string();
}
- std::vector<std::string> enabledLanguages;
cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
- gg->GetEnabledLanguages(enabledLanguages);
- if (!parameters.empty() &&
- std::find(enabledLanguages.begin(), enabledLanguages.end(),
- parameters.front()) == enabledLanguages.end()) {
- reportError(context, content->GetOriginalExpression(),
- "$<COMPILE_LANGUAGE:...> Unknown language.");
- return std::string();
- }
std::string genName = gg->GetName();
- if (genName.find("Visual Studio") != std::string::npos) {
+ if (genName.find("Makefiles") == std::string::npos &&
+ genName.find("Ninja") == std::string::npos &&
+ genName.find("Visual Studio") == std::string::npos &&
+ genName.find("Xcode") == std::string::npos &&
+ genName.find("Watcom WMake") == std::string::npos) {
reportError(context, content->GetOriginalExpression(),
- "$<COMPILE_LANGUAGE:...> may not be used with Visual Studio "
- "generators.");
+ "$<COMPILE_LANGUAGE:...> not supported for this generator.");
return std::string();
}
- if (genName.find("Xcode") != std::string::npos) {
- if (dagChecker && (dagChecker->EvaluatingCompileDefinitions() ||
- dagChecker->EvaluatingIncludeDirectories())) {
- reportError(
- context, content->GetOriginalExpression(),
- "$<COMPILE_LANGUAGE:...> may only be used with COMPILE_OPTIONS "
- "with the Xcode generator.");
- return std::string();
- }
- } else {
- if (genName.find("Makefiles") == std::string::npos &&
- genName.find("Ninja") == std::string::npos &&
- genName.find("Watcom WMake") == std::string::npos) {
- reportError(
- context, content->GetOriginalExpression(),
- "$<COMPILE_LANGUAGE:...> not supported for this generator.");
- return std::string();
- }
- }
if (parameters.empty()) {
return context->Language;
}
- return context->Language == parameters.front() ? "1" : "0";
+
+ for (auto& param : parameters) {
+ if (context->Language == param) {
+ return "1";
+ }
+ }
+ return "0";
}
} languageNode;
+static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode
+{
+ CompileLanguageAndIdNode() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return TwoOrMoreParameters; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
+ {
+ if (!context->HeadTarget || context->Language.empty()) {
+ // reportError(context, content->GetOriginalExpression(), "");
+ reportError(
+ context, content->GetOriginalExpression(),
+ "$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets "
+ "to specify include directories, compile definitions, and compile "
+ "options. It may not be used with the add_custom_command, "
+ "add_custom_target, or file(GENERATE) commands.");
+ return std::string();
+ }
+ cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
+ std::string genName = gg->GetName();
+ if (genName.find("Makefiles") == std::string::npos &&
+ genName.find("Ninja") == std::string::npos &&
+ genName.find("Visual Studio") == std::string::npos &&
+ genName.find("Xcode") == std::string::npos &&
+ genName.find("Watcom WMake") == std::string::npos) {
+ reportError(
+ context, content->GetOriginalExpression(),
+ "$<COMPILE_LANG_AND_ID:lang,id> not supported for this generator.");
+ return std::string();
+ }
+
+ const std::string& lang = context->Language;
+ if (lang == parameters.front()) {
+ std::vector<std::string> idParameter((parameters.cbegin() + 1),
+ parameters.cend());
+ return CompilerIdNode{ lang.c_str() }.EvaluateWithLanguage(
+ idParameter, context, content, dagChecker, lang);
+ }
+ return "0";
+ }
+} languageAndIdNode;
+
#define TRANSITIVE_PROPERTY_NAME(PROPERTY) , "INTERFACE_" #PROPERTY
static const char* targetPropertyTransitiveWhitelist[] = {
- CM_NULLPTR CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
+ nullptr CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
};
#undef TRANSITIVE_PROPERTY_NAME
@@ -879,13 +1056,14 @@ std::string getLinkedTargetsContent(
std::string linkedTargetsContent;
std::string sep;
std::string depString;
- for (typename std::vector<T>::const_iterator it = libraries.begin();
- it != libraries.end(); ++it) {
+ for (T const& l : libraries) {
// 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() + "," +
+ if (l.Target && l.Target != target) {
+ std::string uniqueName =
+ target->GetGlobalGenerator()->IndexGeneratorTargetUniquely(l.Target);
+ depString += sep + "$<TARGET_PROPERTY:" + std::move(uniqueName) + "," +
interfacePropertyName + ">";
sep = ";";
}
@@ -903,77 +1081,59 @@ std::string getLinkedTargetsContent(
static const struct TargetPropertyNode : public cmGeneratorExpressionNode
{
- TargetPropertyNode() {}
+ TargetPropertyNode() {} // NOLINT(modernize-use-equals-default)
// This node handles errors on parameter count itself.
- int NumExpectedParameters() const CM_OVERRIDE { return OneOrMoreParameters; }
+ int NumExpectedParameters() const override { return OneOrMoreParameters; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagCheckerParent) const
- CM_OVERRIDE
+ static const char* GetErrorText(std::string const& targetName,
+ std::string const& propertyName)
{
- 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_]+$");
-
- cmGeneratorTarget const* target = context->HeadTarget;
- std::string propertyName = *parameters.begin();
-
- if (parameters.size() == 1) {
- context->HadHeadSensitiveCondition = true;
+ if (targetName.empty() && propertyName.empty()) {
+ return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
+ "target name and property name.";
}
- 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 (targetName.empty()) {
+ return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
+ "target name.";
}
-
- 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();
+ if (!cmGeneratorExpression::IsValidTargetName(targetName)) {
+ if (!propertyNameValidator.find(propertyName)) {
+ return "Target name and property name not supported.";
}
+ return "Target name not supported.";
+ }
+ return nullptr;
+ }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
+ {
+ static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
+
+ cmGeneratorTarget const* target = nullptr;
+ std::string targetName, propertyName;
- std::string targetName = parameters.front();
+ if (parameters.size() == 2) {
+ targetName = parameters[0];
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.");
+
+ if (const char* e = GetErrorText(targetName, propertyName)) {
+ reportError(context, content->GetOriginalExpression(), e);
return std::string();
}
- if (propertyName == "ALIASED_TARGET") {
+ if (propertyName == "ALIASED_TARGET"_s) {
if (context->LG->GetMakefile()->IsAlias(targetName)) {
if (cmGeneratorTarget* tgt =
context->LG->FindGeneratorTargetToUse(targetName)) {
return tgt->GetName();
}
}
- return "";
+ return std::string();
}
target = context->LG->FindGeneratorTargetToUse(targetName);
@@ -984,15 +1144,34 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
return std::string();
}
context->AllTargets.insert(target);
- }
- if (target == context->HeadTarget) {
+ } else if (parameters.size() == 1) {
+ target = context->HeadTarget;
+ propertyName = parameters[0];
+
// 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);
+
+ context->HadHeadSensitiveCondition = true;
+ if (!target) {
+ 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();
+ }
+ } else {
+ reportError(
+ context, content->GetOriginalExpression(),
+ "$<TARGET_PROPERTY:...> expression requires one or two parameters");
+ return std::string();
}
+
if (propertyName == "SOURCES") {
context->SourceSensitiveTargets.insert(target);
}
@@ -1026,9 +1205,8 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
return target->GetLinkerLanguage(context->Config);
}
- cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
- target->GetName(), propertyName,
- content, dagCheckerParent);
+ cmGeneratorExpressionDAGChecker dagChecker(
+ context->Backtrace, target, propertyName, content, dagCheckerParent);
switch (dagChecker.Check()) {
case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
@@ -1038,7 +1216,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
// No error. We just skip cyclic references.
return std::string();
case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
- for (size_t i = 1; i < cmArraySize(targetPropertyTransitiveWhitelist);
+ for (size_t i = 1; i < cm::size(targetPropertyTransitiveWhitelist);
++i) {
if (targetPropertyTransitiveWhitelist[i] == propertyName) {
// No error. We're not going to find anything new here.
@@ -1049,14 +1227,22 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
break;
}
- const char* prop = target->GetProperty(propertyName);
+ std::string prop;
+ bool haveProp = false;
+ if (const char* p = target->GetProperty(propertyName)) {
+ prop = p;
+ haveProp = true;
+ }
if (dagCheckerParent) {
- if (dagCheckerParent->EvaluatingLinkLibraries()) {
+ if (dagCheckerParent->EvaluatingGenexExpression() ||
+ dagCheckerParent->EvaluatingPICExpression()) {
+ // No check required.
+ } else if (dagCheckerParent->EvaluatingLinkLibraries()) {
#define TRANSITIVE_PROPERTY_COMPARE(PROPERTY) \
(#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) ||
if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(
- TRANSITIVE_PROPERTY_COMPARE) false) { // NOLINT(clang-tidy)
+ TRANSITIVE_PROPERTY_COMPARE) false) { // NOLINT(*)
reportError(
context, content->GetOriginalExpression(),
"$<TARGET_PROPERTY:...> expression in link libraries "
@@ -1066,7 +1252,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
}
#undef TRANSITIVE_PROPERTY_COMPARE
- if (!prop) {
+ if (!haveProp) {
return std::string();
}
} else {
@@ -1093,8 +1279,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
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_")) {
+ /* else */ if (cmHasLiteralPrefix(propertyName, "COMPILE_DEFINITIONS_")) {
cmPolicies::PolicyStatus polSt =
context->LG->GetPolicyStatus(cmPolicies::CMP0043);
if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
@@ -1123,7 +1308,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
}
}
- if (!prop) {
+ if (!haveProp) {
if (target->IsImported() ||
target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
return linkedTargetsContent;
@@ -1197,35 +1382,35 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
static const struct TargetNameNode : public cmGeneratorExpressionNode
{
- TargetNameNode() {}
+ TargetNameNode() {} // NOLINT(modernize-use-equals-default)
- bool GeneratesContent() const CM_OVERRIDE { return true; }
+ bool GeneratesContent() const override { return true; }
- bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
- bool RequiresLiteralInput() const CM_OVERRIDE { return true; }
+ bool AcceptsArbitraryContentParameter() const override { return true; }
+ bool RequiresLiteralInput() const override { return true; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* /*context*/,
- const GeneratorExpressionContent* /*content*/,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* /*context*/,
+ const GeneratorExpressionContent* /*content*/,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
return parameters.front();
}
- int NumExpectedParameters() const CM_OVERRIDE { return 1; }
+ int NumExpectedParameters() const override { return 1; }
} targetNameNode;
static const struct TargetObjectsNode : public cmGeneratorExpressionNode
{
- TargetObjectsNode() {}
+ TargetObjectsNode() {} // NOLINT(modernize-use-equals-default)
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
std::string tgtName = parameters.front();
cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName);
@@ -1236,10 +1421,16 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
reportError(context, content->GetOriginalExpression(), e.str());
return std::string();
}
- if (gt->GetType() != cmStateEnums::OBJECT_LIBRARY) {
+ cmStateEnums::TargetType type = gt->GetType();
+ if (type != cmStateEnums::EXECUTABLE &&
+ type != cmStateEnums::STATIC_LIBRARY &&
+ type != cmStateEnums::SHARED_LIBRARY &&
+ type != cmStateEnums::MODULE_LIBRARY &&
+ type != cmStateEnums::OBJECT_LIBRARY) {
std::ostringstream e;
e << "Objects of target \"" << tgtName
- << "\" referenced but is not an OBJECT library.";
+ << "\" referenced but is not an allowed library types (EXECUTABLE, "
+ << "STATIC, SHARED, MODULE, OBJECT).";
reportError(context, content->GetOriginalExpression(), e.str());
return std::string();
}
@@ -1250,8 +1441,9 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
std::ostringstream e;
e << "The evaluation of the TARGET_OBJECTS generator expression "
"is only suitable for consumption by CMake (limited"
- << reason << "). "
- "It is not suitable for writing out elsewhere.";
+ << reason
+ << "). "
+ "It is not suitable for writing out elsewhere.";
reportError(context, content->GetOriginalExpression(), e.str());
return std::string();
}
@@ -1260,8 +1452,8 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
std::vector<std::string> objects;
if (gt->IsImported()) {
- const char* loc = CM_NULLPTR;
- const char* imp = CM_NULLPTR;
+ const char* loc = nullptr;
+ const char* imp = nullptr;
std::string suffix;
if (gt->Target->GetMappedConfig(context->Config, &loc, &imp, suffix)) {
cmSystemTools::ExpandListArgument(loc, objects);
@@ -1283,17 +1475,15 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
context->HadContextSensitiveCondition = true;
}
- for (std::vector<std::string>::iterator oi = objects.begin();
- oi != objects.end(); ++oi) {
- *oi = obj_dir + *oi;
+ for (std::string& o : objects) {
+ o = obj_dir + o;
}
}
// Create the cmSourceFile instances in the referencing directory.
cmMakefile* mf = context->LG->GetMakefile();
- for (std::vector<std::string>::iterator oi = objects.begin();
- oi != objects.end(); ++oi) {
- mf->AddTargetObject(tgtName, *oi);
+ for (std::string& o : objects) {
+ mf->AddTargetObject(tgtName, o);
}
return cmJoin(objects, ";");
@@ -1302,15 +1492,15 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode
static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
{
- CompileFeaturesNode() {}
+ CompileFeaturesNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return OneOrMoreParameters; }
+ int NumExpectedParameters() const override { return OneOrMoreParameters; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagChecker) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
{
cmGeneratorTarget const* target = context->HeadTarget;
if (!target) {
@@ -1322,21 +1512,20 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
}
context->HadHeadSensitiveCondition = true;
- typedef std::map<std::string, std::vector<std::string> > LangMap;
+ 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) {
+ for (std::string const& p : parameters) {
std::string error;
std::string lang;
if (!context->LG->GetMakefile()->CompileFeatureKnown(
- context->HeadTarget->Target, *it, lang, &error)) {
+ context->HeadTarget->Target, p, lang, &error)) {
reportError(context, content->GetOriginalExpression(), error);
return std::string();
}
- testedFeatures[lang].push_back(*it);
+ testedFeatures[lang].push_back(p);
if (availableFeatures.find(lang) == availableFeatures.end()) {
const char* featuresKnown =
@@ -1352,15 +1541,13 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
- for (LangMap::const_iterator lit = testedFeatures.begin();
- lit != testedFeatures.end(); ++lit) {
+ for (auto const& lit : testedFeatures) {
std::vector<std::string> const& langAvailable =
- availableFeatures[lit->first];
+ availableFeatures[lit.first];
const char* standardDefault = context->LG->GetMakefile()->GetDefinition(
- "CMAKE_" + lit->first + "_STANDARD_DEFAULT");
- for (std::vector<std::string>::const_iterator it = lit->second.begin();
- it != lit->second.end(); ++it) {
- if (std::find(langAvailable.begin(), langAvailable.end(), *it) ==
+ "CMAKE_" + lit.first + "_STANDARD_DEFAULT");
+ for (std::string const& it : lit.second) {
+ if (std::find(langAvailable.begin(), langAvailable.end(), it) ==
langAvailable.end()) {
return "0";
}
@@ -1370,14 +1557,14 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
continue;
}
if (!context->LG->GetMakefile()->HaveStandardAvailable(
- target->Target, lit->first, *it)) {
+ target->Target, lit.first, it)) {
if (evalLL) {
- const char* l = target->GetProperty(lit->first + "_STANDARD");
+ const char* l = target->GetProperty(lit.first + "_STANDARD");
if (!l) {
l = standardDefault;
}
assert(l);
- context->MaxLanguageStandard[target][lit->first] = l;
+ context->MaxLanguageStandard[target][lit.first] = l;
} else {
return "0";
}
@@ -1389,10 +1576,10 @@ static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
} compileFeaturesNode;
static const char* targetPolicyWhitelist[] = {
- CM_NULLPTR
+ nullptr
#define TARGET_POLICY_STRING(POLICY) , #POLICY
- CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
+ CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
#undef TARGET_POLICY_STRING
};
@@ -1430,15 +1617,15 @@ cmPolicies::PolicyID policyForString(const char* policy_id)
static const struct TargetPolicyNode : public cmGeneratorExpressionNode
{
- TargetPolicyNode() {}
+ TargetPolicyNode() {} // NOLINT(modernize-use-equals-default)
- int NumExpectedParameters() const CM_OVERRIDE { return 1; }
+ int NumExpectedParameters() const override { return 1; }
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
if (!context->HeadTarget) {
reportError(
@@ -1451,14 +1638,14 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode
context->HadContextSensitiveCondition = true;
context->HadHeadSensitiveCondition = true;
- for (size_t i = 1; i < cmArraySize(targetPolicyWhitelist); ++i) {
+ for (size_t i = 1; i < cm::size(targetPolicyWhitelist); ++i) {
const char* policy = targetPolicyWhitelist[i];
if (parameters.front() == policy) {
cmLocalGenerator* lg = context->HeadTarget->GetLocalGenerator();
switch (statusForTarget(context->HeadTarget, policy)) {
case cmPolicies::WARN:
lg->IssueMessage(
- cmake::AUTHOR_WARNING,
+ MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(policyForString(policy)));
CM_FALLTHROUGH;
case cmPolicies::REQUIRED_IF_USED:
@@ -1483,7 +1670,7 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode
CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
#undef TARGET_POLICY_LIST_ITEM
- );
+ );
return std::string();
}
@@ -1491,16 +1678,16 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode
static const struct InstallPrefixNode : public cmGeneratorExpressionNode
{
- InstallPrefixNode() {}
+ InstallPrefixNode() {} // NOLINT(modernize-use-equals-default)
- bool GeneratesContent() const CM_OVERRIDE { return true; }
- int NumExpectedParameters() const CM_OVERRIDE { return 0; }
+ bool GeneratesContent() const override { return true; }
+ int NumExpectedParameters() const override { return 0; }
- std::string Evaluate(const std::vector<std::string>& /*parameters*/,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& /*parameters*/,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
reportError(context, content->GetOriginalExpression(),
"INSTALL_PREFIX is a marker for install(EXPORT) only. It "
@@ -1609,7 +1796,8 @@ struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
"executables with ENABLE_EXPORTS.");
return std::string();
}
- cmStateEnums::ArtifactType artifact = target->HasImportLibrary()
+ cmStateEnums::ArtifactType artifact =
+ target->HasImportLibrary(context->Config)
? cmStateEnums::ImportLibraryArtifact
: cmStateEnums::RuntimeBinaryArtifact;
return target->GetFullPath(context->Config, artifact);
@@ -1708,45 +1896,68 @@ struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
static std::string Get(const std::string& result) { return result; }
};
-template <typename ArtifactT, typename ComponentT>
-struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
+struct TargetArtifactBase : public cmGeneratorExpressionNode
{
- TargetFilesystemArtifact() {}
-
- int NumExpectedParameters() const CM_OVERRIDE { return 1; }
-
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* dagChecker) const
- CM_OVERRIDE
+ TargetArtifactBase() {} // NOLINT(modernize-use-equals-default)
+
+protected:
+ cmGeneratorTarget* GetTarget(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const
{
// Lookup the referenced target.
- std::string name = *parameters.begin();
+ std::string name = parameters.front();
if (!cmGeneratorExpression::IsValidTargetName(name)) {
::reportError(context, content->GetOriginalExpression(),
"Expression syntax not recognized.");
- return std::string();
+ return nullptr;
}
cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name);
if (!target) {
::reportError(context, content->GetOriginalExpression(),
"No target \"" + name + "\"");
- return std::string();
+ return nullptr;
}
if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY &&
target->GetType() != cmStateEnums::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(),
+ "Target \"" + name +
+ "\" is not an executable or library.");
+ return nullptr;
+ }
+ if (dagChecker &&
+ (dagChecker->EvaluatingLinkLibraries(target) ||
+ (dagChecker->EvaluatingSources() &&
+ target == dagChecker->TopTarget()))) {
::reportError(context, content->GetOriginalExpression(),
"Expressions which require the linker language may not "
"be used while evaluating link libraries");
+ return nullptr;
+ }
+
+ return target;
+ }
+};
+
+template <typename ArtifactT, typename ComponentT>
+struct TargetFilesystemArtifact : public TargetArtifactBase
+{
+ TargetFilesystemArtifact() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 1; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
+ {
+ cmGeneratorTarget* target =
+ this->GetTarget(parameters, context, content, dagChecker);
+ if (!target) {
return std::string();
}
context->DependTargets.insert(target);
@@ -1765,7 +1976,9 @@ struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
template <typename ArtifactT>
struct TargetFilesystemArtifactNodeGroup
{
- TargetFilesystemArtifactNodeGroup() {}
+ TargetFilesystemArtifactNodeGroup() // NOLINT(modernize-use-equals-default)
+ {
+ }
TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
@@ -1791,91 +2004,361 @@ static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
ArtifactPathTag>
targetBundleContentDirNode;
+//
+// To retrieve base name for various artifacts
+//
+template <typename ArtifactT>
+struct TargetOutputNameArtifactResultGetter
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content);
+};
+
+template <>
+struct TargetOutputNameArtifactResultGetter<ArtifactNameTag>
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* /*unused*/)
+ {
+ return target->GetOutputName(context->Config,
+ cmStateEnums::RuntimeBinaryArtifact) +
+ target->GetFilePostfix(context->Config);
+ }
+};
+
+template <>
+struct TargetOutputNameArtifactResultGetter<ArtifactLinkerTag>
+{
+ static std::string Get(cmGeneratorTarget* 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_BASE_NAME is allowed only for "
+ "libraries and executables with ENABLE_EXPORTS.");
+ return std::string();
+ }
+ cmStateEnums::ArtifactType artifact =
+ target->HasImportLibrary(context->Config)
+ ? cmStateEnums::ImportLibraryArtifact
+ : cmStateEnums::RuntimeBinaryArtifact;
+ return target->GetOutputName(context->Config, artifact) +
+ target->GetFilePostfix(context->Config);
+ }
+};
+
+template <>
+struct TargetOutputNameArtifactResultGetter<ArtifactPdbTag>
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content)
+ {
+ if (target->IsImported()) {
+ ::reportError(
+ context, content->GetOriginalExpression(),
+ "TARGET_PDB_FILE_BASE_NAME not allowed for IMPORTED targets.");
+ return std::string();
+ }
+
+ std::string language = target->GetLinkerLanguage(context->Config);
+
+ std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
+
+ if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
+ ::reportError(
+ context, content->GetOriginalExpression(),
+ "TARGET_PDB_FILE_BASE_NAME is not supported by the target linker.");
+ return std::string();
+ }
+
+ cmStateEnums::TargetType targetType = target->GetType();
+
+ if (targetType != cmStateEnums::SHARED_LIBRARY &&
+ targetType != cmStateEnums::MODULE_LIBRARY &&
+ targetType != cmStateEnums::EXECUTABLE) {
+ ::reportError(context, content->GetOriginalExpression(),
+ "TARGET_PDB_FILE_BASE_NAME is allowed only for "
+ "targets with linker created artifacts.");
+ return std::string();
+ }
+
+ return target->GetPDBOutputName(context->Config) +
+ target->GetFilePostfix(context->Config);
+ }
+};
+
+template <typename ArtifactT>
+struct TargetFileBaseNameArtifact : public TargetArtifactBase
+{
+ TargetFileBaseNameArtifact() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 1; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
+ {
+ cmGeneratorTarget* target =
+ this->GetTarget(parameters, context, content, dagChecker);
+ if (!target) {
+ return std::string();
+ }
+
+ std::string result = TargetOutputNameArtifactResultGetter<ArtifactT>::Get(
+ target, context, content);
+ if (context->HadError) {
+ return std::string();
+ }
+ return result;
+ }
+};
+
+static const TargetFileBaseNameArtifact<ArtifactNameTag>
+ targetFileBaseNameNode;
+static const TargetFileBaseNameArtifact<ArtifactLinkerTag>
+ targetLinkerFileBaseNameNode;
+static const TargetFileBaseNameArtifact<ArtifactPdbTag>
+ targetPdbFileBaseNameNode;
+
+class ArtifactFilePrefixTag;
+class ArtifactLinkerFilePrefixTag;
+class ArtifactFileSuffixTag;
+class ArtifactLinkerFileSuffixTag;
+
+template <typename ArtifactT>
+struct TargetFileArtifactResultGetter
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content);
+};
+
+template <>
+struct TargetFileArtifactResultGetter<ArtifactFilePrefixTag>
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent*)
+ {
+ return target->GetFilePrefix(context->Config);
+ }
+};
+template <>
+struct TargetFileArtifactResultGetter<ArtifactLinkerFilePrefixTag>
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content)
+ {
+ if (!target->IsLinkable()) {
+ ::reportError(context, content->GetOriginalExpression(),
+ "TARGET_LINKER_PREFIX is allowed only for libraries and "
+ "executables with ENABLE_EXPORTS.");
+ return std::string();
+ }
+
+ cmStateEnums::ArtifactType artifact =
+ target->HasImportLibrary(context->Config)
+ ? cmStateEnums::ImportLibraryArtifact
+ : cmStateEnums::RuntimeBinaryArtifact;
+
+ return target->GetFilePrefix(context->Config, artifact);
+ }
+};
+template <>
+struct TargetFileArtifactResultGetter<ArtifactFileSuffixTag>
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent*)
+ {
+ return target->GetFileSuffix(context->Config);
+ }
+};
+template <>
+struct TargetFileArtifactResultGetter<ArtifactLinkerFileSuffixTag>
+{
+ static std::string Get(cmGeneratorTarget* target,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content)
+ {
+ if (!target->IsLinkable()) {
+ ::reportError(context, content->GetOriginalExpression(),
+ "TARGET_LINKER_SUFFIX is allowed only for libraries and "
+ "executables with ENABLE_EXPORTS.");
+ return std::string();
+ }
+
+ cmStateEnums::ArtifactType artifact =
+ target->HasImportLibrary(context->Config)
+ ? cmStateEnums::ImportLibraryArtifact
+ : cmStateEnums::RuntimeBinaryArtifact;
+
+ return target->GetFileSuffix(context->Config, artifact);
+ }
+};
+
+template <typename ArtifactT>
+struct TargetFileArtifact : public TargetArtifactBase
+{
+ TargetFileArtifact() {} // NOLINT(modernize-use-equals-default)
+
+ int NumExpectedParameters() const override { return 1; }
+
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* dagChecker) const override
+ {
+ cmGeneratorTarget* target =
+ this->GetTarget(parameters, context, content, dagChecker);
+ if (!target) {
+ return std::string();
+ }
+
+ std::string result =
+ TargetFileArtifactResultGetter<ArtifactT>::Get(target, context, content);
+ if (context->HadError) {
+ return std::string();
+ }
+ return result;
+ }
+};
+
+static const TargetFileArtifact<ArtifactFilePrefixTag> targetFilePrefixNode;
+static const TargetFileArtifact<ArtifactLinkerFilePrefixTag>
+ targetLinkerFilePrefixNode;
+static const TargetFileArtifact<ArtifactFileSuffixTag> targetFileSuffixNode;
+static const TargetFileArtifact<ArtifactLinkerFileSuffixTag>
+ targetLinkerFileSuffixNode;
+
static const struct ShellPathNode : public cmGeneratorExpressionNode
{
- ShellPathNode() {}
+ ShellPathNode() {} // NOLINT(modernize-use-equals-default)
- std::string Evaluate(const std::vector<std::string>& parameters,
- cmGeneratorExpressionContext* context,
- const GeneratorExpressionContent* content,
- cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
- CM_OVERRIDE
+ std::string Evaluate(
+ const std::vector<std::string>& parameters,
+ cmGeneratorExpressionContext* context,
+ const GeneratorExpressionContent* content,
+ cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
{
- if (!cmSystemTools::FileIsFullPath(parameters.front())) {
+ std::vector<std::string> listIn;
+ cmSystemTools::ExpandListArgument(parameters.front(), listIn);
+ if (listIn.empty()) {
reportError(context, content->GetOriginalExpression(),
- "\"" + parameters.front() + "\" is not an absolute path.");
+ "\"\" is not an absolute path.");
return std::string();
}
- cmOutputConverter converter(context->LG->GetStateSnapshot());
- return converter.ConvertDirectorySeparatorsForShell(parameters.front());
+ cmStateSnapshot snapshot = context->LG->GetStateSnapshot();
+ cmOutputConverter converter(snapshot);
+ const char* separator = snapshot.GetState()->UseWindowsShell() ? ";" : ":";
+ std::vector<std::string> listOut;
+ listOut.reserve(listIn.size());
+ for (auto const& in : listIn) {
+ if (!cmSystemTools::FileIsFullPath(in)) {
+ reportError(context, content->GetOriginalExpression(),
+ "\"" + in + "\" is not an absolute path.");
+ return std::string();
+ }
+ listOut.emplace_back(converter.ConvertDirectorySeparatorsForShell(in));
+ }
+ return cmJoin(listOut, separator);
}
} shellPathNode;
const cmGeneratorExpressionNode* 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_GREATER_EQUAL"] = &versionGreaterEqNode;
- nodeMap["VERSION_LESS"] = &versionLessNode;
- nodeMap["VERSION_LESS_EQUAL"] = &versionLessEqNode;
- 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["TARGET_BUNDLE_DIR"] = &targetBundleDirNode;
- nodeMap["TARGET_BUNDLE_CONTENT_DIR"] = &targetBundleContentDirNode;
- nodeMap["STREQUAL"] = &strEqualNode;
- nodeMap["EQUAL"] = &equalNode;
- nodeMap["LOWER_CASE"] = &lowerCaseNode;
- nodeMap["UPPER_CASE"] = &upperCaseNode;
- nodeMap["MAKE_C_IDENTIFIER"] = &makeCIdentifierNode;
- nodeMap["BOOL"] = &boolNode;
- nodeMap["IF"] = &ifNode;
- 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["COMPILE_LANGUAGE"] = &languageNode;
- nodeMap["SHELL_PATH"] = &shellPathNode;
- }
- NodeMap::const_iterator i = nodeMap.find(identifier);
- if (i == nodeMap.end()) {
- return CM_NULLPTR;
- }
- return i->second;
+ static std::map<std::string, cmGeneratorExpressionNode const*> const nodeMap{
+ { "0", &zeroNode },
+ { "1", &oneNode },
+ { "AND", &andNode },
+ { "OR", &orNode },
+ { "NOT", &notNode },
+ { "C_COMPILER_ID", &cCompilerIdNode },
+ { "CXX_COMPILER_ID", &cxxCompilerIdNode },
+ { "CUDA_COMPILER_ID", &cudaCompilerIdNode },
+ { "Fortran_COMPILER_ID", &fortranCompilerIdNode },
+ { "VERSION_GREATER", &versionGreaterNode },
+ { "VERSION_GREATER_EQUAL", &versionGreaterEqNode },
+ { "VERSION_LESS", &versionLessNode },
+ { "VERSION_LESS_EQUAL", &versionLessEqNode },
+ { "VERSION_EQUAL", &versionEqualNode },
+ { "C_COMPILER_VERSION", &cCompilerVersionNode },
+ { "CXX_COMPILER_VERSION", &cxxCompilerVersionNode },
+ { "CUDA_COMPILER_VERSION", &cudaCompilerVersionNode },
+ { "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode },
+ { "PLATFORM_ID", &platformIdNode },
+ { "COMPILE_FEATURES", &compileFeaturesNode },
+ { "CONFIGURATION", &configurationNode },
+ { "CONFIG", &configurationTestNode },
+ { "TARGET_FILE", &targetNodeGroup.File },
+ { "TARGET_LINKER_FILE", &targetLinkerNodeGroup.File },
+ { "TARGET_SONAME_FILE", &targetSoNameNodeGroup.File },
+ { "TARGET_PDB_FILE", &targetPdbNodeGroup.File },
+ { "TARGET_FILE_BASE_NAME", &targetFileBaseNameNode },
+ { "TARGET_LINKER_FILE_BASE_NAME", &targetLinkerFileBaseNameNode },
+ { "TARGET_PDB_FILE_BASE_NAME", &targetPdbFileBaseNameNode },
+ { "TARGET_FILE_PREFIX", &targetFilePrefixNode },
+ { "TARGET_LINKER_FILE_PREFIX", &targetLinkerFilePrefixNode },
+ { "TARGET_FILE_SUFFIX", &targetFileSuffixNode },
+ { "TARGET_LINKER_FILE_SUFFIX", &targetLinkerFileSuffixNode },
+ { "TARGET_FILE_NAME", &targetNodeGroup.FileName },
+ { "TARGET_LINKER_FILE_NAME", &targetLinkerNodeGroup.FileName },
+ { "TARGET_SONAME_FILE_NAME", &targetSoNameNodeGroup.FileName },
+ { "TARGET_PDB_FILE_NAME", &targetPdbNodeGroup.FileName },
+ { "TARGET_FILE_DIR", &targetNodeGroup.FileDir },
+ { "TARGET_LINKER_FILE_DIR", &targetLinkerNodeGroup.FileDir },
+ { "TARGET_SONAME_FILE_DIR", &targetSoNameNodeGroup.FileDir },
+ { "TARGET_PDB_FILE_DIR", &targetPdbNodeGroup.FileDir },
+ { "TARGET_BUNDLE_DIR", &targetBundleDirNode },
+ { "TARGET_BUNDLE_CONTENT_DIR", &targetBundleContentDirNode },
+ { "STREQUAL", &strEqualNode },
+ { "EQUAL", &equalNode },
+ { "IN_LIST", &inListNode },
+ { "FILTER", &filterNode },
+ { "REMOVE_DUPLICATES", &removeDuplicatesNode },
+ { "LOWER_CASE", &lowerCaseNode },
+ { "UPPER_CASE", &upperCaseNode },
+ { "MAKE_C_IDENTIFIER", &makeCIdentifierNode },
+ { "BOOL", &boolNode },
+ { "IF", &ifNode },
+ { "ANGLE-R", &angle_rNode },
+ { "COMMA", &commaNode },
+ { "SEMICOLON", &semicolonNode },
+ { "TARGET_PROPERTY", &targetPropertyNode },
+ { "TARGET_NAME", &targetNameNode },
+ { "TARGET_OBJECTS", &targetObjectsNode },
+ { "TARGET_POLICY", &targetPolicyNode },
+ { "TARGET_EXISTS", &targetExistsNode },
+ { "TARGET_NAME_IF_EXISTS", &targetNameIfExistsNode },
+ { "TARGET_GENEX_EVAL", &targetGenexEvalNode },
+ { "GENEX_EVAL", &genexEvalNode },
+ { "BUILD_INTERFACE", &buildInterfaceNode },
+ { "INSTALL_INTERFACE", &installInterfaceNode },
+ { "INSTALL_PREFIX", &installPrefixNode },
+ { "JOIN", &joinNode },
+ { "LINK_ONLY", &linkOnlyNode },
+ { "COMPILE_LANG_AND_ID", &languageAndIdNode },
+ { "COMPILE_LANGUAGE", &languageNode },
+ { "SHELL_PATH", &shellPathNode }
+ };
+
+ {
+ auto itr = nodeMap.find(identifier);
+ if (itr != nodeMap.end()) {
+ return itr->second;
+ }
+ }
+ return nullptr;
}
void reportError(cmGeneratorExpressionContext* context,
@@ -1892,6 +2375,6 @@ void reportError(cmGeneratorExpressionContext* context,
<< " " << expr << "\n"
<< result;
/* clang-format on */
- context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
- context->Backtrace);
+ context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str(), context->Backtrace);
}
diff --git a/Source/cmGeneratorExpressionNode.h b/Source/cmGeneratorExpressionNode.h
index ece1c113c..7a369249f 100644
--- a/Source/cmGeneratorExpressionNode.h
+++ b/Source/cmGeneratorExpressionNode.h
@@ -20,9 +20,11 @@ struct cmGeneratorExpressionNode
{
DynamicParameters = 0,
OneOrMoreParameters = -1,
- OneOrZeroParameters = -2
+ TwoOrMoreParameters = -2,
+ ZeroOrMoreParameters = -3,
+ OneOrZeroParameters = -4
};
- virtual ~cmGeneratorExpressionNode() {}
+ virtual ~cmGeneratorExpressionNode() = default;
virtual bool GeneratesContent() const { return true; }
diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx
index c33349a63..304378dfe 100644
--- a/Source/cmGeneratorExpressionParser.cxx
+++ b/Source/cmGeneratorExpressionParser.cxx
@@ -2,14 +2,16 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGeneratorExpressionParser.h"
+#include "cmAlgorithms.h"
#include "cmGeneratorExpressionEvaluator.h"
#include <assert.h>
#include <stddef.h>
+#include <utility>
cmGeneratorExpressionParser::cmGeneratorExpressionParser(
- const std::vector<cmGeneratorExpressionToken>& tokens)
- : Tokens(tokens)
+ std::vector<cmGeneratorExpressionToken> tokens)
+ : Tokens(std::move(tokens))
, NestingLevel(0)
{
}
@@ -46,14 +48,14 @@ static void extendResult(
if (!result.empty() &&
(*(result.end() - 1))->GetType() ==
cmGeneratorExpressionEvaluator::Text &&
- (*contents.begin())->GetType() == cmGeneratorExpressionEvaluator::Text) {
+ contents.front()->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());
+ static_cast<TextContent*>(contents.front())->GetLength());
+ delete contents.front();
+ cmAppend(result, contents.begin() + 1, contents.end());
} else {
- result.insert(result.end(), contents.begin(), contents.end());
+ cmAppend(result, contents);
}
}
@@ -86,18 +88,18 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
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);
+ 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);
+ content->SetIdentifier(std::move(identifier));
result.push_back(content);
return;
}
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> > parameters;
+ std::vector<std::vector<cmGeneratorExpressionEvaluator*>> parameters;
std::vector<std::vector<cmGeneratorExpressionToken>::const_iterator>
commaTokens;
std::vector<cmGeneratorExpressionToken>::const_iterator colonToken;
@@ -198,8 +200,8 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
((this->it - 1)->Content - startToken->Content) + (this->it - 1)->Length;
GeneratorExpressionContent* content =
new GeneratorExpressionContent(startToken->Content, contentLength);
- content->SetIdentifier(identifier);
- content->SetParameters(parameters);
+ content->SetIdentifier(std::move(identifier));
+ content->SetParameters(std::move(parameters));
result.push_back(content);
}
diff --git a/Source/cmGeneratorExpressionParser.h b/Source/cmGeneratorExpressionParser.h
index 633381c8a..e663496da 100644
--- a/Source/cmGeneratorExpressionParser.h
+++ b/Source/cmGeneratorExpressionParser.h
@@ -13,8 +13,7 @@ struct cmGeneratorExpressionEvaluator;
struct cmGeneratorExpressionParser
{
- cmGeneratorExpressionParser(
- const std::vector<cmGeneratorExpressionToken>& tokens);
+ cmGeneratorExpressionParser(std::vector<cmGeneratorExpressionToken> tokens);
void Parse(std::vector<cmGeneratorExpressionEvaluator*>& result);
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index c9924f670..036a07d1c 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -7,11 +7,14 @@
#include <assert.h>
#include <errno.h>
#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <queue>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unordered_set>
+#include <utility>
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
@@ -23,7 +26,9 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPropertyMap.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmState.h"
@@ -31,8 +36,6 @@
#include "cmTarget.h"
#include "cmTargetLinkLibraryType.h"
#include "cmTargetPropertyComputer.h"
-#include "cm_auto_ptr.hxx"
-#include "cm_unordered_set.hxx"
#include "cmake.h"
class cmMessenger;
@@ -46,8 +49,9 @@ const char* cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
}
template <>
-const char* cmTargetPropertyComputer::ComputeLocationForBuild<
- cmGeneratorTarget>(cmGeneratorTarget const* tgt)
+const char*
+cmTargetPropertyComputer::ComputeLocationForBuild<cmGeneratorTarget>(
+ cmGeneratorTarget const* tgt)
{
return tgt->GetLocation("");
}
@@ -61,20 +65,137 @@ const char* cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
class cmGeneratorTarget::TargetPropertyEntry
{
+protected:
static cmLinkImplItem NoLinkImplItem;
public:
- TargetPropertyEntry(CM_AUTO_PTR<cmCompiledGeneratorExpression> cge,
- cmLinkImplItem const& item = NoLinkImplItem)
- : ge(cge)
- , LinkImplItem(item)
+ TargetPropertyEntry(cmLinkImplItem const& item)
+ : LinkImplItem(item)
{
}
- const CM_AUTO_PTR<cmCompiledGeneratorExpression> ge;
+ virtual ~TargetPropertyEntry() = default;
+
+ virtual const std::string& Evaluate(
+ cmLocalGenerator* lg, const std::string& config, bool quiet = false,
+ cmGeneratorTarget const* headTarget = nullptr,
+ cmGeneratorTarget const* currentTarget = nullptr,
+ cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
+ std::string const& language = std::string()) const = 0;
+ virtual const std::string& Evaluate(
+ cmLocalGenerator* lg, const std::string& config, bool quiet,
+ cmGeneratorTarget const* headTarget,
+ cmGeneratorExpressionDAGChecker* dagChecker,
+ std::string const& language = std::string()) const = 0;
+
+ virtual cmListFileBacktrace GetBacktrace() const = 0;
+ virtual std::string const& GetInput() const = 0;
+ virtual bool GetHadContextSensitiveCondition() const { return false; }
+
cmLinkImplItem const& LinkImplItem;
+
+private:
+ cmListFileBacktrace Backtrace;
};
cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
+class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry
+{
+public:
+ TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge,
+ cmLinkImplItem const& item = NoLinkImplItem)
+ : cmGeneratorTarget::TargetPropertyEntry(item)
+ , ge(std::move(cge))
+ {
+ }
+
+ const std::string& Evaluate(
+ cmLocalGenerator* lg, const std::string& config, bool quiet = false,
+ cmGeneratorTarget const* headTarget = nullptr,
+ cmGeneratorTarget const* currentTarget = nullptr,
+ cmGeneratorExpressionDAGChecker* dagChecker = nullptr,
+ std::string const& language = std::string()) const override
+ {
+ return this->ge->Evaluate(lg, config, quiet, headTarget, currentTarget,
+ dagChecker, language);
+ }
+ const std::string& Evaluate(
+ cmLocalGenerator* lg, const std::string& config, bool quiet,
+ cmGeneratorTarget const* headTarget,
+ cmGeneratorExpressionDAGChecker* dagChecker,
+ std::string const& language = std::string()) const override
+ {
+ return this->ge->Evaluate(lg, config, quiet, headTarget, dagChecker,
+ language);
+ }
+
+ cmListFileBacktrace GetBacktrace() const override
+ {
+ return this->ge->GetBacktrace();
+ }
+
+ std::string const& GetInput() const override { return this->ge->GetInput(); }
+
+ bool GetHadContextSensitiveCondition() const override
+ {
+ return this->ge->GetHadContextSensitiveCondition();
+ }
+
+private:
+ const std::unique_ptr<cmCompiledGeneratorExpression> ge;
+};
+
+class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry
+{
+public:
+ TargetPropertyEntryString(std::string propertyValue,
+ cmListFileBacktrace backtrace,
+ cmLinkImplItem const& item = NoLinkImplItem)
+ : cmGeneratorTarget::TargetPropertyEntry(item)
+ , PropertyValue(std::move(propertyValue))
+ , Backtrace(std::move(backtrace))
+ {
+ }
+
+ const std::string& Evaluate(cmLocalGenerator*, const std::string&, bool,
+ cmGeneratorTarget const*,
+ cmGeneratorTarget const*,
+ cmGeneratorExpressionDAGChecker*,
+ std::string const&) const override
+ {
+ return this->PropertyValue;
+ }
+ const std::string& Evaluate(cmLocalGenerator*, const std::string&, bool,
+ cmGeneratorTarget const*,
+ cmGeneratorExpressionDAGChecker*,
+ std::string const&) const override
+ {
+ return this->PropertyValue;
+ }
+
+ cmListFileBacktrace GetBacktrace() const override { return this->Backtrace; }
+ std::string const& GetInput() const override { return this->PropertyValue; }
+
+private:
+ std::string PropertyValue;
+ cmListFileBacktrace Backtrace;
+};
+
+cmGeneratorTarget::TargetPropertyEntry* CreateTargetPropertyEntry(
+ const std::string& propertyValue,
+ cmListFileBacktrace backtrace = cmListFileBacktrace(),
+ bool evaluateForBuildsystem = false)
+{
+ if (cmGeneratorExpression::Find(propertyValue) != std::string::npos) {
+ cmGeneratorExpression ge(std::move(backtrace));
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(propertyValue);
+ cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
+ return new TargetPropertyEntryGenex(std::move(cge));
+ }
+
+ return new TargetPropertyEntryString(propertyValue, backtrace);
+}
+
void CreatePropertyGeneratorExpressions(
cmStringRange entries, cmBacktraceRange backtraces,
std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
@@ -83,10 +204,8 @@ void CreatePropertyGeneratorExpressions(
std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
for (std::vector<std::string>::const_iterator it = entries.begin();
it != entries.end(); ++it, ++btIt) {
- cmGeneratorExpression ge(*btIt);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
- cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
- items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
+ items.push_back(
+ CreateTargetPropertyEntry(*it, *btIt, evaluateForBuildsystem));
}
}
@@ -100,6 +219,8 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
, DebugCompileOptionsDone(false)
, DebugCompileFeaturesDone(false)
, DebugCompileDefinitionsDone(false)
+ , DebugLinkOptionsDone(false)
+ , DebugLinkDirectoriesDone(false)
, DebugSourcesDone(false)
, LinkImplementationLanguageIsContextDependent(true)
, UtilityItemsDone(false)
@@ -126,15 +247,22 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
t->GetCompileDefinitionsBacktraces(),
this->CompileDefinitionsEntries);
+ CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(),
+ t->GetLinkOptionsBacktraces(),
+ this->LinkOptionsEntries);
+
+ CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(),
+ t->GetLinkDirectoriesBacktraces(),
+ this->LinkDirectoriesEntries);
+
CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
t->GetSourceBacktraces(),
this->SourceEntries, true);
this->DLLPlatform =
- (this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") ||
- this->Makefile->IsOn("MINGW"));
+ !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty();
- this->PolicyMap = t->PolicyMap;
+ this->PolicyMap = t->GetPolicyMap();
}
cmGeneratorTarget::~cmGeneratorTarget()
@@ -143,6 +271,8 @@ cmGeneratorTarget::~cmGeneratorTarget()
cmDeleteAll(this->CompileOptionsEntries);
cmDeleteAll(this->CompileFeaturesEntries);
cmDeleteAll(this->CompileDefinitionsEntries);
+ cmDeleteAll(this->LinkOptionsEntries);
+ cmDeleteAll(this->LinkDirectoriesEntries);
cmDeleteAll(this->SourceEntries);
cmDeleteAll(this->LinkInformation);
}
@@ -150,11 +280,8 @@ cmGeneratorTarget::~cmGeneratorTarget()
const char* cmGeneratorTarget::GetSourcesProperty() const
{
std::vector<std::string> values;
- for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
- it = this->SourceEntries.begin(),
- end = this->SourceEntries.end();
- it != end; ++it) {
- values.push_back((*it)->ge->GetInput());
+ for (TargetPropertyEntry* se : this->SourceEntries) {
+ values.push_back(se->GetInput());
}
static std::string value;
value.clear();
@@ -191,7 +318,7 @@ std::string cmGeneratorTarget::GetExportName() const
std::ostringstream e;
e << "EXPORT_NAME property \"" << exportName << "\" for \""
<< this->GetName() << "\": is not valid.";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return "";
}
return exportName;
@@ -204,18 +331,27 @@ const char* cmGeneratorTarget::GetProperty(const std::string& prop) const
if (!cmTargetPropertyComputer::PassesWhitelist(
this->GetType(), prop, this->Makefile->GetMessenger(),
this->GetBacktrace())) {
- return CM_NULLPTR;
+ return nullptr;
}
if (const char* result = cmTargetPropertyComputer::GetProperty(
this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
return result;
}
if (cmSystemTools::GetFatalErrorOccured()) {
- return CM_NULLPTR;
+ return nullptr;
}
return this->Target->GetProperty(prop);
}
+const char* cmGeneratorTarget::GetSafeProperty(const std::string& prop) const
+{
+ const char* ret = this->GetProperty(prop);
+ if (!ret) {
+ return "";
+ }
+ return ret;
+}
+
const char* cmGeneratorTarget::GetOutputTargetType(
cmStateEnums::ArtifactType artifact) const
{
@@ -242,13 +378,16 @@ const char* cmGeneratorTarget::GetOutputTargetType(
case cmStateEnums::MODULE_LIBRARY:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
- // Module import libraries are treated as archive targets.
+ // Module libraries are always treated as library targets.
return "LIBRARY";
case cmStateEnums::ImportLibraryArtifact:
- // Module libraries are always treated as library targets.
+ // Module import libraries are treated as archive targets.
return "ARCHIVE";
}
break;
+ case cmStateEnums::OBJECT_LIBRARY:
+ // Object libraries are always treated as object targets.
+ return "OBJECT";
case cmStateEnums::EXECUTABLE:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
@@ -296,12 +435,11 @@ std::string cmGeneratorTarget::GetOutputName(
props.push_back(configUpper + "_OUTPUT_NAME");
}
// OUTPUT_NAME
- props.push_back("OUTPUT_NAME");
+ props.emplace_back("OUTPUT_NAME");
std::string outName;
- for (std::vector<std::string>::const_iterator it = props.begin();
- it != props.end(); ++it) {
- if (const char* outNameProp = this->GetProperty(*it)) {
+ for (std::string const& p : props) {
+ if (const char* outNameProp = this->GetProperty(p)) {
outName = outNameProp;
break;
}
@@ -313,34 +451,182 @@ std::string cmGeneratorTarget::GetOutputName(
// Now evaluate genex and update the previously-prepared map entry.
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
i->second = cge->Evaluate(this->LocalGenerator, config);
} else if (i->second.empty()) {
// An empty map entry indicates we have been called recursively
// from the above block.
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
this->GetBacktrace());
}
return i->second;
}
-void cmGeneratorTarget::AddSourceCommon(const std::string& src)
+std::string cmGeneratorTarget::GetFilePrefix(
+ const std::string& config, cmStateEnums::ArtifactType artifact) const
+{
+ if (this->IsImported()) {
+ const char* prefix = this->GetFilePrefixInternal(artifact);
+
+ return prefix ? prefix : std::string();
+ }
+
+ std::string prefix, suffix, base;
+ this->GetFullNameInternal(config, artifact, prefix, base, suffix);
+ return prefix;
+}
+std::string cmGeneratorTarget::GetFileSuffix(
+ const std::string& config, cmStateEnums::ArtifactType artifact) const
+{
+ if (this->IsImported()) {
+ const char* suffix = this->GetFileSuffixInternal(artifact);
+
+ return suffix ? suffix : std::string();
+ }
+
+ std::string prefix, suffix, base;
+ this->GetFullNameInternal(config, artifact, prefix, base, suffix);
+ return suffix;
+}
+
+std::string cmGeneratorTarget::GetFilePostfix(const std::string& config) const
+{
+ const char* postfix = nullptr;
+ if (!config.empty()) {
+ std::string configProp = cmSystemTools::UpperCase(config);
+ configProp += "_POSTFIX";
+ postfix = this->GetProperty(configProp);
+ // Mac application bundles and frameworks have no postfix.
+ if (!this->IsImported() && postfix &&
+ (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
+ postfix = nullptr;
+ }
+ }
+ return postfix ? postfix : std::string();
+}
+
+const char* cmGeneratorTarget::GetFilePrefixInternal(
+ cmStateEnums::ArtifactType artifact, const std::string& language) const
+{
+ // no prefix for non-main target types.
+ if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
+ this->GetType() != cmStateEnums::SHARED_LIBRARY &&
+ this->GetType() != cmStateEnums::MODULE_LIBRARY &&
+ this->GetType() != cmStateEnums::EXECUTABLE) {
+ return nullptr;
+ }
+
+ const bool isImportedLibraryArtifact =
+ (artifact == cmStateEnums::ImportLibraryArtifact);
+
+ // Return an empty prefix for the import library if this platform
+ // does not support import libraries.
+ if (isImportedLibraryArtifact &&
+ !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
+ return nullptr;
+ }
+
+ // The implib option is only allowed for shared libraries, module
+ // libraries, and executables.
+ if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
+ this->GetType() != cmStateEnums::MODULE_LIBRARY &&
+ this->GetType() != cmStateEnums::EXECUTABLE) {
+ artifact = cmStateEnums::RuntimeBinaryArtifact;
+ }
+
+ // Compute prefix value.
+ const char* targetPrefix =
+ (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
+ : this->GetProperty("PREFIX"));
+
+ if (!targetPrefix) {
+ const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
+ if (!language.empty() && prefixVar && *prefixVar) {
+ std::string langPrefix = prefixVar + std::string("_") + language;
+ targetPrefix = this->Makefile->GetDefinition(langPrefix);
+ }
+
+ // if there is no prefix on the target nor specific language
+ // use the cmake definition.
+ if (!targetPrefix && prefixVar) {
+ targetPrefix = this->Makefile->GetDefinition(prefixVar);
+ }
+ }
+
+ return targetPrefix;
+}
+const char* cmGeneratorTarget::GetFileSuffixInternal(
+ cmStateEnums::ArtifactType artifact, const std::string& language) const
+{
+ // no suffix for non-main target types.
+ if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
+ this->GetType() != cmStateEnums::SHARED_LIBRARY &&
+ this->GetType() != cmStateEnums::MODULE_LIBRARY &&
+ this->GetType() != cmStateEnums::EXECUTABLE) {
+ return nullptr;
+ }
+
+ const bool isImportedLibraryArtifact =
+ (artifact == cmStateEnums::ImportLibraryArtifact);
+
+ // Return an empty suffix for the import library if this platform
+ // does not support import libraries.
+ if (isImportedLibraryArtifact &&
+ !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
+ return nullptr;
+ }
+
+ // The implib option is only allowed for shared libraries, module
+ // libraries, and executables.
+ if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
+ this->GetType() != cmStateEnums::MODULE_LIBRARY &&
+ this->GetType() != cmStateEnums::EXECUTABLE) {
+ artifact = cmStateEnums::RuntimeBinaryArtifact;
+ }
+
+ // Compute suffix value.
+ const char* targetSuffix =
+ (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
+ : this->GetProperty("SUFFIX"));
+
+ if (!targetSuffix) {
+ const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
+ if (!language.empty() && suffixVar && *suffixVar) {
+ std::string langSuffix = suffixVar + std::string("_") + language;
+ targetSuffix = this->Makefile->GetDefinition(langSuffix);
+ }
+
+ // if there is no suffix on the target nor specific language
+ // use the cmake definition.
+ if (!targetSuffix && suffixVar) {
+ targetSuffix = this->Makefile->GetDefinition(suffixVar);
+ }
+ }
+
+ return targetSuffix;
+}
+
+void cmGeneratorTarget::ClearSourcesCache()
{
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- cmGeneratorExpression ge(lfbt);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src);
- cge->SetEvaluateForBuildsystem(true);
- this->SourceEntries.push_back(new TargetPropertyEntry(cge));
this->KindedSourcesMap.clear();
this->LinkImplementationLanguageIsContextDependent = true;
+ this->Objects.clear();
+}
+
+void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
+{
+ this->SourceEntries.insert(
+ before ? this->SourceEntries.begin() : this->SourceEntries.end(),
+ CreateTargetPropertyEntry(src, this->Makefile->GetBacktrace(), true));
+ this->ClearSourcesCache();
}
-void cmGeneratorTarget::AddSource(const std::string& src)
+void cmGeneratorTarget::AddSource(const std::string& src, bool before)
{
- this->Target->AddSource(src);
- this->AddSourceCommon(src);
+ this->Target->AddSource(src, before);
+ this->AddSourceCommon(src, before);
}
void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
@@ -355,15 +641,10 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
bool before)
{
this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- cmGeneratorExpression ge(lfbt);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src);
- cge->SetEvaluateForBuildsystem(true);
- // Insert before begin/end
- std::vector<TargetPropertyEntry*>::iterator pos = before
- ? this->IncludeDirectoriesEntries.begin()
- : this->IncludeDirectoriesEntries.end();
- this->IncludeDirectoriesEntries.insert(pos, new TargetPropertyEntry(cge));
+ this->IncludeDirectoriesEntries.insert(
+ before ? this->IncludeDirectoriesEntries.begin()
+ : this->IncludeDirectoriesEntries.end(),
+ CreateTargetPropertyEntry(src, this->Makefile->GetBacktrace(), true));
}
std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
@@ -373,21 +654,22 @@ std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
if (i != this->SourceDepends.end()) {
return &i->second.Depends;
}
- return CM_NULLPTR;
+ return nullptr;
}
static void handleSystemIncludesDep(
cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
const std::string& config, cmGeneratorTarget const* headTarget,
cmGeneratorExpressionDAGChecker* dagChecker,
- std::vector<std::string>& result, bool excludeImported)
+ std::vector<std::string>& result, bool excludeImported,
+ std::string const& language)
{
if (const char* dirs =
depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
- dagChecker),
+ dagChecker, language),
result);
}
if (!depTgt->IsImported() || excludeImported) {
@@ -399,22 +681,21 @@ static void handleSystemIncludesDep(
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
- dagChecker),
+ dagChecker, language),
result);
}
}
/* clang-format off */
#define IMPLEMENT_VISIT(KIND) \
- { \
+ do { \
KindedSources const& kinded = this->GetKindedSources(config); \
- for (std::vector<SourceAndKind>::const_iterator \
- si = kinded.Sources.begin(); si != kinded.Sources.end(); ++si) { \
- if (si->Kind == KIND) { \
- data.push_back(si->Source); \
+ for (SourceAndKind const& s : kinded.Sources) { \
+ if (s.Kind == KIND) { \
+ data.push_back(s.Source.Value); \
} \
} \
- }
+ } while (false)
/* clang-format on */
void cmGeneratorTarget::GetObjectSources(
@@ -426,9 +707,8 @@ void cmGeneratorTarget::GetObjectSources(
return;
}
- for (std::vector<cmSourceFile const*>::const_iterator it = data.begin();
- it != data.end(); ++it) {
- this->Objects[*it];
+ for (cmSourceFile const* it : data) {
+ this->Objects[it];
}
this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
@@ -443,12 +723,11 @@ void cmGeneratorTarget::ComputeObjectMapping()
std::vector<std::string> configs;
this->Makefile->GetConfigurations(configs);
if (configs.empty()) {
- configs.push_back("");
+ configs.emplace_back();
}
- for (std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci) {
+ for (std::string const& c : configs) {
std::vector<cmSourceFile const*> sourceFiles;
- this->GetObjectSources(sourceFiles, *ci);
+ this->GetObjectSources(sourceFiles, c);
}
}
@@ -469,6 +748,25 @@ const char* cmGeneratorTarget::GetFeature(const std::string& feature,
return this->LocalGenerator->GetFeature(feature, config);
}
+const char* cmGeneratorTarget::GetLinkPIEProperty(
+ const std::string& config) const
+{
+ static std::string PICValue;
+
+ PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty(
+ "POSITION_INDEPENDENT_CODE", config);
+
+ if (PICValue == "(unset)") {
+ // POSITION_INDEPENDENT_CODE is not set
+ return nullptr;
+ }
+
+ auto status = this->GetPolicyStatusCMP0083();
+ return (status != cmPolicies::WARN && status != cmPolicies::OLD)
+ ? PICValue.c_str()
+ : nullptr;
+}
+
bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
std::string const& config) const
{
@@ -503,7 +801,7 @@ bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
<< "'" << this->GetName() << "'.";
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
- cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace());
+ MessageType::AUTHOR_WARNING, w.str(), this->GetBacktrace());
this->PolicyReportedCMP0069 = true;
}
@@ -511,7 +809,7 @@ bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
}
// Note: check consistency with messages from CheckIPOSupported
- const char* message = CM_NULLPTR;
+ const char* message = nullptr;
if (!this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_SUPPORTED_BY_CMAKE")) {
message = "CMake doesn't support IPO for current compiler";
} else if (!this->Makefile->IsOn("_CMAKE_" + lang +
@@ -534,7 +832,7 @@ bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
this->PolicyReportedCMP0069 = true;
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR, message, this->GetBacktrace());
+ MessageType::FATAL_ERROR, message, this->GetBacktrace());
return false;
}
@@ -553,7 +851,7 @@ const char* cmGeneratorTarget::GetCustomObjectExtension() const
extension = ".ptx";
return extension.c_str();
}
- return CM_NULLPTR;
+ return nullptr;
}
void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
@@ -648,12 +946,14 @@ std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
{
if (!this->UtilityItemsDone) {
this->UtilityItemsDone = true;
- std::set<std::string> const& utilities = this->GetUtilities();
- for (std::set<std::string>::const_iterator i = utilities.begin();
- i != utilities.end(); ++i) {
- cmGeneratorTarget* gt =
- this->LocalGenerator->FindGeneratorTargetToUse(*i);
- this->UtilityItems.insert(cmLinkItem(*i, gt));
+ std::set<BT<std::string>> const& utilities = this->GetUtilities();
+ for (BT<std::string> const& i : utilities) {
+ if (cmGeneratorTarget* gt =
+ this->LocalGenerator->FindGeneratorTargetToUse(i.Value)) {
+ this->UtilityItems.insert(cmLinkItem(gt, i.Backtrace));
+ } else {
+ this->UtilityItems.insert(cmLinkItem(i.Value, i.Backtrace));
+ }
}
}
return this->UtilityItems;
@@ -735,7 +1035,8 @@ const char* cmGeneratorTarget::GetLocationForBuild() const
}
bool cmGeneratorTarget::IsSystemIncludeDirectory(
- const std::string& dir, const std::string& config) const
+ const std::string& dir, const std::string& config,
+ const std::string& language) const
{
assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
std::string config_upper;
@@ -743,35 +1044,30 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
config_upper = cmSystemTools::UpperCase(config);
}
- typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
+ 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", CM_NULLPTR, CM_NULLPTR);
+ this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr);
bool excludeImported = this->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) {
+ for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
- ge.Parse(*it)->Evaluate(this->LocalGenerator, config, false, this,
- &dagChecker),
+ ge.Parse(it)->Evaluate(this->LocalGenerator, config, false, this,
+ &dagChecker, language),
result);
}
std::vector<cmGeneratorTarget const*> const& deps =
this->GetLinkImplementationClosure(config);
- for (std::vector<cmGeneratorTarget const *>::const_iterator
- li = deps.begin(),
- le = deps.end();
- li != le; ++li) {
- handleSystemIncludesDep(this->LocalGenerator, *li, config, this,
- &dagChecker, result, excludeImported);
+ for (cmGeneratorTarget const* dep : deps) {
+ handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
+ &dagChecker, result, excludeImported, language);
}
std::for_each(result.begin(), result.end(),
@@ -798,17 +1094,39 @@ static void AddInterfaceEntries(
{
if (cmLinkImplementationLibraries const* impl =
thisTarget->GetLinkImplementationLibraries(config)) {
- for (std::vector<cmLinkImplItem>::const_iterator
- it = impl->Libraries.begin(),
- end = impl->Libraries.end();
- it != end; ++it) {
- if (it->Target) {
- std::string genex = "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
- cmGeneratorExpression ge(it->Backtrace);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
+ for (cmLinkImplItem const& lib : impl->Libraries) {
+ if (lib.Target) {
+ std::string uniqueName =
+ thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
+ lib.Target);
+ std::string genex =
+ "$<TARGET_PROPERTY:" + std::move(uniqueName) + "," + prop + ">";
+ cmGeneratorExpression ge(lib.Backtrace);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
cge->SetEvaluateForBuildsystem(true);
- entries.push_back(
- new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
+ entries.push_back(new TargetPropertyEntryGenex(std::move(cge), lib));
+ }
+ }
+ }
+}
+
+static void AddObjectEntries(
+ cmGeneratorTarget const* thisTarget, std::string const& config,
+ std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
+{
+ if (cmLinkImplementationLibraries const* impl =
+ thisTarget->GetLinkImplementationLibraries(config)) {
+ for (cmLinkImplItem const& lib : impl->Libraries) {
+ if (lib.Target &&
+ lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
+ std::string uniqueName =
+ thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
+ lib.Target);
+ std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
+ cmGeneratorExpression ge(lib.Backtrace);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
+ cge->SetEvaluateForBuildsystem(true);
+ entries.push_back(new TargetPropertyEntryGenex(std::move(cge), lib));
}
}
}
@@ -817,7 +1135,8 @@ static void AddInterfaceEntries(
static bool processSources(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
- std::vector<std::string>& srcs, CM_UNORDERED_SET<std::string>& uniqueSrcs,
+ std::vector<BT<std::string>>& srcs,
+ std::unordered_set<std::string>& uniqueSrcs,
cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
bool debugSources)
{
@@ -825,61 +1144,51 @@ static bool processSources(
bool contextDependent = false;
- for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
- it = entries.begin(),
- end = entries.end();
- it != end; ++it) {
- cmLinkImplItem const& item = (*it)->LinkImplItem;
- std::string const& targetName = item;
+ for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
+ cmLinkImplItem const& item = entry->LinkImplItem;
+ std::string const& targetName = item.AsStr();
std::vector<std::string> entrySources;
- cmSystemTools::ExpandListArgument(
- (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt,
- dagChecker),
- entrySources);
+ cmSystemTools::ExpandListArgument(entry->Evaluate(tgt->GetLocalGenerator(),
+ config, false, tgt, tgt,
+ dagChecker),
+ entrySources);
- if ((*it)->ge->GetHadContextSensitiveCondition()) {
+ if (entry->GetHadContextSensitiveCondition()) {
contextDependent = true;
}
- for (std::vector<std::string>::iterator i = entrySources.begin();
- i != entrySources.end(); ++i) {
- std::string& src = *i;
+ for (std::string& src : entrySources) {
cmSourceFile* sf = mf->GetOrCreateSource(src);
std::string e;
std::string fullPath = sf->GetFullPath(&e);
if (fullPath.empty()) {
if (!e.empty()) {
cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
- cm->IssueMessage(cmake::FATAL_ERROR, e, tgt->GetBacktrace());
+ cm->IssueMessage(MessageType::FATAL_ERROR, e, tgt->GetBacktrace());
}
return contextDependent;
}
- if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str())) {
+ if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src)) {
std::ostringstream err;
if (!targetName.empty()) {
err << "Target \"" << targetName
- << "\" contains relative "
- "path in its INTERFACE_SOURCES:\n"
- " \""
+ << "\" contains relative path in its INTERFACE_SOURCES:\n \""
<< src << "\"";
} else {
- err << "Found relative path while evaluating sources of "
- "\""
+ err << "Found relative path while evaluating sources of \""
<< tgt->GetName() << "\":\n \"" << src << "\"\n";
}
- tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str());
+ tgt->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
+ err.str());
return contextDependent;
}
src = fullPath;
}
std::string usedSources;
- for (std::vector<std::string>::iterator li = entrySources.begin();
- li != entrySources.end(); ++li) {
- std::string src = *li;
-
+ for (std::string const& src : entrySources) {
if (uniqueSrcs.insert(src).second) {
- srcs.push_back(src);
+ srcs.emplace_back(src, entry->GetBacktrace());
if (debugSources) {
usedSources += " * " + src + "\n";
}
@@ -887,17 +1196,19 @@ static bool processSources(
}
if (!usedSources.empty()) {
tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
- cmake::LOG, std::string("Used sources for target ") + tgt->GetName() +
- ":\n" + usedSources,
- (*it)->ge->GetBacktrace());
+ MessageType::LOG,
+ std::string("Used sources for target ") + tgt->GetName() + ":\n" +
+ usedSources,
+ entry->GetBacktrace());
}
}
return contextDependent;
}
-void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
- const std::string& config) const
+std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
+ std::string const& config) const
{
+ std::vector<BT<std::string>> files;
assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
@@ -908,22 +1219,18 @@ void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
// behavior of CMP0024 and CMP0026 only.
cmStringRange sourceEntries = this->Target->GetSourceEntries();
- for (cmStringRange::const_iterator i = sourceEntries.begin();
- i != sourceEntries.end(); ++i) {
- std::string const& entry = *i;
-
+ for (std::string const& entry : sourceEntries) {
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] == '>') {
+ for (std::string const& item : items) {
+ if (cmHasLiteralPrefix(item, "$<TARGET_OBJECTS:") &&
+ item.back() == '>') {
continue;
}
- files.push_back(*li);
+ files.emplace_back(item);
}
}
- return;
+ return files;
}
std::vector<std::string> debugProperties;
@@ -941,36 +1248,57 @@ void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
this->DebugSourcesDone = true;
}
- cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES",
- CM_NULLPTR, CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr,
+ nullptr);
- CM_UNORDERED_SET<std::string> uniqueSrcs;
+ std::unordered_set<std::string> uniqueSrcs;
bool contextDependentDirectSources =
processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
config, debugSources);
+ // Collect INTERFACE_SOURCES of all direct link-dependencies.
std::vector<cmGeneratorTarget::TargetPropertyEntry*>
linkInterfaceSourcesEntries;
-
AddInterfaceEntries(this, config, "INTERFACE_SOURCES",
linkInterfaceSourcesEntries);
-
std::vector<std::string>::size_type numFilesBefore = files.size();
bool contextDependentInterfaceSources =
processSources(this, linkInterfaceSourcesEntries, files, uniqueSrcs,
&dagChecker, config, debugSources);
+ // Collect TARGET_OBJECTS of direct object link-dependencies.
+ std::vector<cmGeneratorTarget::TargetPropertyEntry*> linkObjectsEntries;
+ AddObjectEntries(this, config, linkObjectsEntries);
+ std::vector<std::string>::size_type numFilesBefore2 = files.size();
+ bool contextDependentObjects =
+ processSources(this, linkObjectsEntries, files, uniqueSrcs, &dagChecker,
+ config, debugSources);
+
if (!contextDependentDirectSources &&
- !(contextDependentInterfaceSources && numFilesBefore < files.size())) {
+ !(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
+ !(contextDependentObjects && numFilesBefore2 < files.size())) {
this->LinkImplementationLanguageIsContextDependent = false;
}
cmDeleteAll(linkInterfaceSourcesEntries);
+ cmDeleteAll(linkObjectsEntries);
+ return files;
}
void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
const std::string& config) const
{
+ std::vector<BT<cmSourceFile*>> tmp = this->GetSourceFiles(config);
+ files.reserve(tmp.size());
+ for (BT<cmSourceFile*>& v : tmp) {
+ files.push_back(v.Value);
+ }
+}
+
+std::vector<BT<cmSourceFile*>> cmGeneratorTarget::GetSourceFiles(
+ std::string const& config) const
+{
+ std::vector<BT<cmSourceFile*>> files;
if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
// Since we are still configuring not all sources may exist yet,
// so we need to avoid full source classification because that
@@ -978,38 +1306,49 @@ void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
// Since this is only for compatibility with old policies that
// projects should not depend on anymore, just compute the files
// without memoizing them.
- std::vector<std::string> srcs;
- this->GetSourceFiles(srcs, config);
+ std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(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);
+ for (BT<std::string> const& s : srcs) {
+ cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
if (emitted.insert(sf).second) {
- files.push_back(sf);
+ files.emplace_back(sf, s.Backtrace);
}
}
- return;
+ return files;
}
KindedSources const& kinded = this->GetKindedSources(config);
files.reserve(kinded.Sources.size());
- for (std::vector<SourceAndKind>::const_iterator si = kinded.Sources.begin();
- si != kinded.Sources.end(); ++si) {
- files.push_back(si->Source);
+ for (SourceAndKind const& si : kinded.Sources) {
+ files.push_back(si.Source);
}
+ return files;
}
void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
std::vector<cmSourceFile*>& files, const std::string& config) const
{
+ std::vector<BT<cmSourceFile*>> tmp =
+ this->GetSourceFilesWithoutObjectLibraries(config);
+ files.reserve(tmp.size());
+ for (BT<cmSourceFile*>& v : tmp) {
+ files.push_back(v.Value);
+ }
+}
+
+std::vector<BT<cmSourceFile*>>
+cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
+ std::string const& config) const
+{
+ std::vector<BT<cmSourceFile*>> files;
KindedSources const& kinded = this->GetKindedSources(config);
files.reserve(kinded.Sources.size());
- for (std::vector<SourceAndKind>::const_iterator si = kinded.Sources.begin();
- si != kinded.Sources.end(); ++si) {
- if (si->Source->GetObjectLibrary().empty()) {
- files.push_back(si->Source);
+ for (SourceAndKind const& si : kinded.Sources) {
+ if (si.Source.Value->GetObjectLibrary().empty()) {
+ files.push_back(si.Source);
}
}
+ return files;
}
cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
@@ -1031,7 +1370,7 @@ cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
<< "\" use a generator expression that depends on the "
"SOURCES themselves.";
this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
+ MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
static KindedSources empty;
return empty;
}
@@ -1049,17 +1388,15 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
std::string const& config) const
{
// Get the source file paths by string.
- std::vector<std::string> srcs;
- this->GetSourceFiles(srcs, config);
+ std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
cmsys::RegularExpression header_regex(CM_HEADER_REGEX);
std::vector<cmSourceFile*> badObjLib;
std::set<cmSourceFile*> emitted;
- for (std::vector<std::string>::const_iterator i = srcs.begin();
- i != srcs.end(); ++i) {
+ for (BT<std::string> const& s : srcs) {
// Create each source at most once.
- cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
+ cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
if (!emitted.insert(sf).second) {
continue;
}
@@ -1075,9 +1412,6 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
kind = SourceKindHeader;
} else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
kind = SourceKindExternalObject;
- if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- badObjLib.push_back(sf);
- }
} else if (!sf->GetLanguage().empty()) {
kind = SourceKindObjectSource;
} else if (ext == "def") {
@@ -1118,28 +1452,26 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
std::string cppFileName = xaml + ".cpp";
files.ExpectedXamlHeaders.insert(hFileName);
files.ExpectedXamlSources.insert(cppFileName);
- } else if (header_regex.find(sf->GetFullPath().c_str())) {
+ } else if (header_regex.find(sf->GetFullPath())) {
kind = SourceKindHeader;
} else {
kind = SourceKindExtra;
}
// Save this classified source file in the result vector.
- SourceAndKind entry = { sf, kind };
- files.Sources.push_back(entry);
+ files.Sources.push_back({ BT<cmSourceFile*>(sf, s.Backtrace), kind });
}
if (!badObjLib.empty()) {
std::ostringstream e;
e << "OBJECT library \"" << this->GetName() << "\" contains:\n";
- for (std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
- i != badObjLib.end(); ++i) {
- e << " " << (*i)->GetLocation().GetName() << "\n";
+ for (cmSourceFile* i : badObjLib) {
+ 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.";
this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
+ MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
}
}
@@ -1161,18 +1493,16 @@ void cmGeneratorTarget::ComputeAllConfigSources() const
for (size_t ci = 0; ci < configs.size(); ++ci) {
KindedSources const& sources = this->GetKindedSources(configs[ci]);
- for (std::vector<cmGeneratorTarget::SourceAndKind>::const_iterator si =
- sources.Sources.begin();
- si != sources.Sources.end(); ++si) {
+ for (SourceAndKind const& src : sources.Sources) {
std::map<cmSourceFile const*, size_t>::iterator mi =
- index.find(si->Source);
+ index.find(src.Source.Value);
if (mi == index.end()) {
AllConfigSource acs;
- acs.Source = si->Source;
- acs.Kind = si->Kind;
- this->AllConfigSources.push_back(acs);
+ acs.Source = src.Source.Value;
+ acs.Kind = src.Kind;
+ this->AllConfigSources.push_back(std::move(acs));
std::map<cmSourceFile const*, size_t>::value_type entry(
- si->Source, this->AllConfigSources.size() - 1);
+ src.Source.Value, this->AllConfigSources.size() - 1);
mi = index.insert(entry).first;
}
this->AllConfigSources[mi->second].Configs.push_back(ci);
@@ -1299,7 +1629,7 @@ bool cmGeneratorTarget::NeedRelinkBeforeInstall(
/* clang-format on */
cmake* cm = this->LocalGenerator->GetCMakeInstance();
- cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
+ cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
}
return have_rpath;
@@ -1430,7 +1760,7 @@ bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
w << " less than 10.5 or because CMake's platform configuration is";
w << " corrupt.";
cmake* cm = this->LocalGenerator->GetCMakeInstance();
- cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
+ cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
}
return true;
@@ -1525,13 +1855,7 @@ std::string cmGeneratorTarget::GetSOName(const std::string& config) const
return "";
}
// 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;
+ return this->GetLibraryNames(config).SharedObject;
}
static bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
@@ -1556,7 +1880,8 @@ std::string cmGeneratorTarget::GetAppBundleDirectory(
ext = "app";
}
fpath += ext;
- if (shouldAddContentLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
+ if (shouldAddContentLevel(level) &&
+ !this->Makefile->PlatformIsAppleEmbedded()) {
fpath += "/Contents";
if (shouldAddFullLevel(level)) {
fpath += "/MacOS";
@@ -1586,7 +1911,8 @@ std::string cmGeneratorTarget::GetCFBundleDirectory(
}
}
fpath += ext;
- if (shouldAddContentLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
+ if (shouldAddContentLevel(level) &&
+ !this->Makefile->PlatformIsAppleEmbedded()) {
fpath += "/Contents";
if (shouldAddFullLevel(level)) {
fpath += "/MacOS";
@@ -1606,7 +1932,8 @@ std::string cmGeneratorTarget::GetFrameworkDirectory(
ext = "framework";
}
fpath += ext;
- if (shouldAddFullLevel(level) && !this->Makefile->PlatformIsAppleIos()) {
+ if (shouldAddFullLevel(level) &&
+ !this->Makefile->PlatformIsAppleEmbedded()) {
fpath += "/Versions/";
fpath += this->GetFrameworkVersion();
}
@@ -1675,31 +2002,21 @@ cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
return this->Target->GetBacktrace();
}
-const std::vector<std::string>& cmGeneratorTarget::GetLinkDirectories() const
-{
- return this->Target->GetLinkDirectories();
-}
-
-const std::set<std::string>& cmGeneratorTarget::GetUtilities() const
+const std::set<BT<std::string>>& cmGeneratorTarget::GetUtilities() const
{
return this->Target->GetUtilities();
}
-const cmListFileBacktrace* cmGeneratorTarget::GetUtilityBacktrace(
- const std::string& u) const
-{
- return this->Target->GetUtilityBacktrace(u);
-}
-
bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
{
return this->GetType() == cmStateEnums::STATIC_LIBRARY ||
this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::MODULE_LIBRARY ||
+ this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
this->GetType() == cmStateEnums::EXECUTABLE;
}
-const char* cmGeneratorTarget::GetExportMacro() const
+const std::string* cmGeneratorTarget::GetExportMacro() const
{
// Define the symbol for targets that export symbols.
if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
@@ -1712,19 +2029,19 @@ const char* cmGeneratorTarget::GetExportMacro() const
in += "_EXPORTS";
this->ExportMacro = cmSystemTools::MakeCidentifier(in);
}
- return this->ExportMacro.c_str();
+ return &this->ExportMacro;
}
- return CM_NULLPTR;
+ return nullptr;
}
class cmTargetCollectLinkLanguages
{
public:
cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
- const std::string& config,
- CM_UNORDERED_SET<std::string>& languages,
+ std::string config,
+ std::unordered_set<std::string>& languages,
cmGeneratorTarget const* head)
- : Config(config)
+ : Config(std::move(config))
, Languages(languages)
, HeadTarget(head)
, Target(target)
@@ -1735,15 +2052,15 @@ public:
void Visit(cmLinkItem const& item)
{
if (!item.Target) {
- if (item.find("::") != std::string::npos) {
+ if (item.AsStr().find("::") != std::string::npos) {
bool noMessage = false;
- cmake::MessageType messageType = cmake::FATAL_ERROR;
+ MessageType messageType = MessageType::FATAL_ERROR;
std::ostringstream e;
switch (this->Target->GetLocalGenerator()->GetPolicyStatus(
cmPolicies::CMP0028)) {
case cmPolicies::WARN: {
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
- messageType = cmake::AUTHOR_WARNING;
+ messageType = MessageType::AUTHOR_WARNING;
} break;
case cmPolicies::OLD:
noMessage = true;
@@ -1756,7 +2073,7 @@ public:
if (!noMessage) {
e << "Target \"" << this->Target->GetName()
- << "\" links to target \"" << item
+ << "\" links to target \"" << item.AsStr()
<< "\" but the target was not found. Perhaps a find_package() "
"call is missing for an IMPORTED target, or an ALIAS target is "
"missing?";
@@ -1775,21 +2092,18 @@ public:
return;
}
- for (std::vector<std::string>::const_iterator li =
- iface->Languages.begin();
- li != iface->Languages.end(); ++li) {
- this->Languages.insert(*li);
+ for (std::string const& language : iface->Languages) {
+ this->Languages.insert(language);
}
- for (std::vector<cmLinkItem>::const_iterator li = iface->Libraries.begin();
- li != iface->Libraries.end(); ++li) {
- this->Visit(*li);
+ for (cmLinkItem const& lib : iface->Libraries) {
+ this->Visit(lib);
}
}
private:
std::string Config;
- CM_UNORDERED_SET<std::string>& Languages;
+ std::unordered_set<std::string>& Languages;
cmGeneratorTarget const* HeadTarget;
const cmGeneratorTarget* Target;
std::set<cmGeneratorTarget const*> Visited;
@@ -1844,13 +2158,12 @@ public:
e << "Target " << this->Target->GetName()
<< " contains multiple languages with the highest linker preference"
<< " (" << this->Preference << "):\n";
- for (std::set<std::string>::const_iterator li = this->Preferred.begin();
- li != this->Preferred.end(); ++li) {
- e << " " << *li << "\n";
+ for (std::string const& li : this->Preferred) {
+ e << " " << li << "\n";
}
e << "Set the LINKER_LANGUAGE property for this target.";
cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
- cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
this->Target->GetBacktrace());
}
return *this->Preferred.begin();
@@ -1861,26 +2174,22 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
LinkClosure& lc) const
{
// Get languages built in this target.
- CM_UNORDERED_SET<std::string> languages;
+ std::unordered_set<std::string> languages;
cmLinkImplementation const* impl = this->GetLinkImplementation(config);
assert(impl);
- for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
- li != impl->Languages.end(); ++li) {
- languages.insert(*li);
+ for (std::string const& li : impl->Languages) {
+ 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);
+ for (cmLinkImplItem const& lib : impl->Libraries) {
+ cll.Visit(lib);
}
// Store the transitive closure of languages.
- for (CM_UNORDERED_SET<std::string>::const_iterator li = languages.begin();
- li != languages.end(); ++li) {
- lc.Languages.push_back(*li);
+ for (std::string const& lang : languages) {
+ lc.Languages.push_back(lang);
}
// Choose the language whose linker should be used.
@@ -1893,18 +2202,16 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
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->c_str());
+ for (std::string const& l : impl->Languages) {
+ tsl.Consider(l.c_str());
}
// Now consider languages that propagate from linked targets.
- for (CM_UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
- sit != languages.end(); ++sit) {
+ for (std::string const& lang : languages) {
std::string propagates =
- "CMAKE_" + *sit + "_LINKER_PREFERENCE_PROPAGATES";
+ "CMAKE_" + lang + "_LINKER_PREFERENCE_PROPAGATES";
if (this->Makefile->IsOn(propagates)) {
- tsl.Consider(sit->c_str());
+ tsl.Consider(lang.c_str());
}
}
@@ -1973,7 +2280,7 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
{
// There is no compile information for imported targets.
if (this->IsImported()) {
- return CM_NULLPTR;
+ return nullptr;
}
if (this->GetType() > cmStateEnums::OBJECT_LIBRARY) {
@@ -1981,8 +2288,8 @@ cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
msg += this->GetName();
msg += " which has type ";
msg += cmState::GetTargetTypeName(this->GetType());
- this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
- return CM_NULLPTR;
+ this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
+ return nullptr;
}
// Lookup/compute/cache the compile information for this configuration.
@@ -2008,7 +2315,7 @@ cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
this->GetType() != cmStateEnums::MODULE_LIBRARY &&
!this->IsExecutableWithExports()) {
- return CM_NULLPTR;
+ return nullptr;
}
// Lookup/compute/cache the compile information for this configuration.
@@ -2034,8 +2341,13 @@ void cmGeneratorTarget::ComputeModuleDefinitionInfo(
info.WindowsExportAllSymbols =
this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS");
+#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
info.DefFileGenerated =
info.WindowsExportAllSymbols || info.Sources.size() > 1;
+#else
+ // Our __create_def helper is only available on Windows.
+ info.DefFileGenerated = false;
+#endif
if (info.DefFileGenerated) {
info.DefFile = this->ObjectDirectory /* has slash */ + "exports.def";
} else if (!info.Sources.empty()) {
@@ -2058,8 +2370,8 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
}
cmGeneratorExpression ge;
- cmGeneratorExpressionDAGChecker dagChecker(
- this->GetName(), "AUTOUIC_OPTIONS", CM_NULLPTR, CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(this, "AUTOUIC_OPTIONS", nullptr,
+ nullptr);
cmSystemTools::ExpandListArgument(
ge.Parse(prop)->Evaluate(this->LocalGenerator, config, false, this,
&dagChecker),
@@ -2076,10 +2388,8 @@ void processILibs(const std::string& config,
tgts.push_back(item.Target);
if (cmLinkInterfaceLibraries 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, gg, tgts, emitted);
+ for (cmLinkItem const& lib : iface->Libraries) {
+ processILibs(config, headTarget, lib, gg, tgts, emitted);
}
}
}
@@ -2097,10 +2407,8 @@ cmGeneratorTarget::GetLinkImplementationClosure(
cmLinkImplementationLibraries const* impl =
this->GetLinkImplementationLibraries(config);
- for (std::vector<cmLinkImplItem>::const_iterator it =
- impl->Libraries.begin();
- it != impl->Libraries.end(); ++it) {
- processILibs(config, this, *it,
+ for (cmLinkImplItem const& lib : impl->Libraries) {
+ processILibs(config, this, lib,
this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
}
}
@@ -2144,23 +2452,20 @@ cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
this->Makefile = target->Target->GetMakefile();
this->LocalGenerator = target->GetLocalGenerator();
this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
- this->CurrentEntry = CM_NULLPTR;
+ this->CurrentEntry = nullptr;
// Queue all the source files already specified for the target.
if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
std::vector<std::string> configs;
this->Makefile->GetConfigurations(configs);
if (configs.empty()) {
- configs.push_back("");
+ configs.emplace_back();
}
std::set<cmSourceFile*> emitted;
- for (std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci) {
+ for (std::string const& c : configs) {
std::vector<cmSourceFile*> sources;
- this->GeneratorTarget->GetSourceFiles(sources, *ci);
- for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
- si != sources.end(); ++si) {
- cmSourceFile* sf = *si;
+ this->GeneratorTarget->GetSourceFiles(sources, c);
+ for (cmSourceFile* sf : sources) {
const std::set<cmGeneratorTarget const*> tgts =
this->GlobalGenerator->GetFilenameTargetDepends(sf);
if (tgts.find(this->GeneratorTarget) != tgts.end()) {
@@ -2169,7 +2474,7 @@ cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
<< "\"\ndepends on the sources of a target it is used in. This "
"is a dependency loop and is not allowed.";
this->GeneratorTarget->LocalGenerator->IssueMessage(
- cmake::FATAL_ERROR, e.str());
+ MessageType::FATAL_ERROR, e.str());
return;
}
if (emitted.insert(sf).second &&
@@ -2199,10 +2504,9 @@ void cmTargetTraceDependencies::Trace()
if (const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) {
std::vector<std::string> objDeps;
cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
- for (std::vector<std::string>::iterator odi = objDeps.begin();
- odi != objDeps.end(); ++odi) {
- if (cmSystemTools::FileIsFullPath(*odi)) {
- *odi = cmSystemTools::CollapseFullPath(*odi);
+ for (std::string& objDep : objDeps) {
+ if (cmSystemTools::FileIsFullPath(objDep)) {
+ objDep = cmSystemTools::CollapseFullPath(objDep);
}
}
this->FollowNames(objDeps);
@@ -2211,7 +2515,7 @@ void cmTargetTraceDependencies::Trace()
// Queue the source needed to generate this file, if any.
this->FollowName(sf->GetFullPath());
- // Queue dependencies added programatically by commands.
+ // Queue dependencies added programmatically by commands.
this->FollowNames(sf->GetDepends());
// Queue custom command dependencies.
@@ -2219,7 +2523,7 @@ void cmTargetTraceDependencies::Trace()
this->CheckCustomCommand(*cc);
}
}
- this->CurrentEntry = CM_NULLPTR;
+ this->CurrentEntry = nullptr;
this->GeneratorTarget->AddTracedSources(this->NewSources);
}
@@ -2255,9 +2559,8 @@ void cmTargetTraceDependencies::FollowName(std::string const& name)
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);
+ for (std::string const& name : names) {
+ this->FollowName(name);
}
}
@@ -2281,7 +2584,7 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
// 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 (cmSystemTools::FileIsFullPath(dep)) {
if (t->GetType() >= cmStateEnums::EXECUTABLE &&
t->GetType() <= cmStateEnums::MODULE_LIBRARY) {
// This is really only for compatibility so we do not need to
@@ -2317,9 +2620,8 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
// Add target-level dependencies referenced by generator expressions.
std::set<cmGeneratorTarget*> targets;
- for (cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
- cit != cc.GetCommandLines().end(); ++cit) {
- std::string const& command = *cit->begin();
+ for (cmCustomCommandLine const& cCmdLine : cc.GetCommandLines()) {
+ std::string const& command = cCmdLine.front();
// Check for a target with this name.
if (cmGeneratorTarget* t =
this->LocalGenerator->FindGeneratorTargetToUse(command)) {
@@ -2333,18 +2635,16 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
}
// Check for target references in generator expressions.
- for (cmCustomCommandLine::const_iterator cli = cit->begin();
- cli != cit->end(); ++cli) {
- const CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*cli);
+ for (std::string const& cl : cCmdLine) {
+ const std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cl);
cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true);
std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
targets.insert(geTargets.begin(), geTargets.end());
}
}
- for (std::set<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- this->GeneratorTarget->Target->AddUtility((*ti)->GetName());
+ for (cmGeneratorTarget* target : targets) {
+ this->GeneratorTarget->Target->AddUtility(target->GetName());
}
// Queue the custom command dependencies.
@@ -2352,11 +2652,10 @@ void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
std::set<std::string> emitted;
this->Makefile->GetConfigurations(configs);
if (configs.empty()) {
- configs.push_back("");
+ configs.emplace_back();
}
- for (std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci) {
- this->FollowCommandDepends(cc, *ci, emitted);
+ for (std::string const& conf : configs) {
+ this->FollowCommandDepends(cc, conf, emitted);
}
}
@@ -2369,9 +2668,7 @@ void cmTargetTraceDependencies::FollowCommandDepends(
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;
+ for (std::string const& dep : depends) {
if (emitted.insert(dep).second) {
if (!this->IsUtility(dep)) {
// The dependency does not name a target and may be a file we
@@ -2385,9 +2682,8 @@ void cmTargetTraceDependencies::FollowCommandDepends(
void cmTargetTraceDependencies::CheckCustomCommands(
const std::vector<cmCustomCommand>& commands)
{
- for (std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
- cli != commands.end(); ++cli) {
- this->CheckCustomCommand(*cli);
+ for (cmCustomCommand const& command : commands) {
+ this->CheckCustomCommand(command);
}
}
@@ -2418,7 +2714,7 @@ std::string cmGeneratorTarget::GetCompilePDBDirectory(
void cmGeneratorTarget::GetAppleArchs(const std::string& config,
std::vector<std::string>& archVec) const
{
- const char* archs = CM_NULLPTR;
+ const char* archs = nullptr;
if (!config.empty()) {
std::string defVarName = "OSX_ARCHITECTURES_";
defVarName += cmSystemTools::UpperCase(config);
@@ -2470,38 +2766,34 @@ std::string cmGeneratorTarget::GetCreateRuleVariable(
static void processIncludeDirectories(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
- std::vector<std::string>& includes,
- CM_UNORDERED_SET<std::string>& uniqueIncludes,
+ std::vector<BT<std::string>>& includes,
+ std::unordered_set<std::string>& uniqueIncludes,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugIncludes, const std::string& language)
{
- for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
- it = entries.begin(),
- end = entries.end();
- it != end; ++it) {
- cmLinkImplItem const& item = (*it)->LinkImplItem;
- std::string const& targetName = item;
+ for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
+ cmLinkImplItem const& item = entry->LinkImplItem;
+ std::string const& targetName = item.AsStr();
bool const fromImported = item.Target && item.Target->IsImported();
bool const checkCMP0027 = item.FromGenex;
std::vector<std::string> entryIncludes;
- cmSystemTools::ExpandListArgument(
- (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
- dagChecker, language),
- entryIncludes);
+ cmSystemTools::ExpandListArgument(entry->Evaluate(tgt->GetLocalGenerator(),
+ config, false, tgt,
+ dagChecker, language),
+ entryIncludes);
std::string usedIncludes;
- for (std::vector<std::string>::iterator li = entryIncludes.begin();
- li != entryIncludes.end(); ++li) {
- if (fromImported && !cmSystemTools::FileExists(li->c_str())) {
+ for (std::string& entryInclude : entryIncludes) {
+ if (fromImported && !cmSystemTools::FileExists(entryInclude)) {
std::ostringstream e;
- cmake::MessageType messageType = cmake::FATAL_ERROR;
+ MessageType messageType = MessageType::FATAL_ERROR;
if (checkCMP0027) {
switch (tgt->GetPolicyStatusCMP0027()) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
CM_FALLTHROUGH;
case cmPolicies::OLD:
- messageType = cmake::AUTHOR_WARNING;
+ messageType = MessageType::AUTHOR_WARNING;
break;
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
@@ -2511,7 +2803,7 @@ static void processIncludeDirectories(
}
/* clang-format off */
e << "Imported target \"" << targetName << "\" includes "
- "non-existent path\n \"" << *li << "\"\nin its "
+ "non-existent path\n \"" << entryInclude << "\"\nin its "
"INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
"* The path was deleted, renamed, or moved to another "
"location.\n"
@@ -2524,21 +2816,21 @@ static void processIncludeDirectories(
return;
}
- if (!cmSystemTools::FileIsFullPath(li->c_str())) {
+ if (!cmSystemTools::FileIsFullPath(entryInclude)) {
std::ostringstream e;
bool noMessage = false;
- cmake::MessageType messageType = cmake::FATAL_ERROR;
+ MessageType messageType = MessageType::FATAL_ERROR;
if (!targetName.empty()) {
/* clang-format off */
e << "Target \"" << targetName << "\" contains relative "
"path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
- " \"" << *li << "\"";
+ " \"" << entryInclude << "\"";
/* clang-format on */
} else {
switch (tgt->GetPolicyStatusCMP0021()) {
case cmPolicies::WARN: {
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
- messageType = cmake::AUTHOR_WARNING;
+ messageType = MessageType::AUTHOR_WARNING;
} break;
case cmPolicies::OLD:
noMessage = true;
@@ -2550,23 +2842,23 @@ static void processIncludeDirectories(
}
e << "Found relative path while evaluating include directories of "
"\""
- << tgt->GetName() << "\":\n \"" << *li << "\"\n";
+ << tgt->GetName() << "\":\n \"" << entryInclude << "\"\n";
}
if (!noMessage) {
tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::FATAL_ERROR) {
return;
}
}
}
- if (!cmSystemTools::IsOff(li->c_str())) {
- cmSystemTools::ConvertToUnixSlashes(*li);
+ if (!cmSystemTools::IsOff(entryInclude)) {
+ cmSystemTools::ConvertToUnixSlashes(entryInclude);
}
- std::string inc = *li;
+ std::string inc = entryInclude;
if (uniqueIncludes.insert(inc).second) {
- includes.push_back(inc);
+ includes.emplace_back(inc, entry->GetBacktrace());
if (debugIncludes) {
usedIncludes += " * " + inc + "\n";
}
@@ -2574,21 +2866,22 @@ static void processIncludeDirectories(
}
if (!usedIncludes.empty()) {
tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
- cmake::LOG, std::string("Used includes for target ") + tgt->GetName() +
- ":\n" + usedIncludes,
- (*it)->ge->GetBacktrace());
+ MessageType::LOG,
+ std::string("Used includes for target ") + tgt->GetName() + ":\n" +
+ usedIncludes,
+ entry->GetBacktrace());
}
}
}
-std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
+std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
const std::string& config, const std::string& lang) const
{
- std::vector<std::string> includes;
- CM_UNORDERED_SET<std::string> uniqueIncludes;
+ std::vector<BT<std::string>> includes;
+ std::unordered_set<std::string> uniqueIncludes;
- cmGeneratorExpressionDAGChecker dagChecker(
- this->GetName(), "INCLUDE_DIRECTORIES", CM_NULLPTR, CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(this, "INCLUDE_DIRECTORIES",
+ nullptr, nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
@@ -2617,10 +2910,8 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
if (this->Makefile->IsOn("APPLE")) {
cmLinkImplementationLibraries const* impl =
this->GetLinkImplementationLibraries(config);
- for (std::vector<cmLinkImplItem>::const_iterator it =
- impl->Libraries.begin();
- it != impl->Libraries.end(); ++it) {
- std::string libDir = cmSystemTools::CollapseFullPath(*it);
+ for (cmLinkImplItem const& lib : impl->Libraries) {
+ std::string libDir = cmSystemTools::CollapseFullPath(lib.AsStr());
static cmsys::RegularExpression frameworkCheck(
"(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
@@ -2630,11 +2921,8 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
libDir = frameworkCheck.match(1);
- cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
- ge.Parse(libDir.c_str());
linkInterfaceIncludeDirectoriesEntries.push_back(
- new cmGeneratorTarget::TargetPropertyEntry(cge));
+ CreateTargetPropertyEntry(libDir));
}
}
@@ -2647,30 +2935,40 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
return includes;
}
-static void processCompileOptionsInternal(
+enum class OptionsParse
+{
+ None,
+ Shell
+};
+
+static void processOptionsInternal(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
- std::vector<std::string>& options,
- CM_UNORDERED_SET<std::string>& uniqueOptions,
+ std::vector<BT<std::string>>& options,
+ std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
- bool debugOptions, const char* logName, std::string const& language)
+ bool debugOptions, const char* logName, std::string const& language,
+ OptionsParse parse)
{
- for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
- it = entries.begin(),
- end = entries.end();
- it != end; ++it) {
+ for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
std::vector<std::string> entryOptions;
- cmSystemTools::ExpandListArgument(
- (*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
- dagChecker, language),
- entryOptions);
+ cmSystemTools::ExpandListArgument(entry->Evaluate(tgt->GetLocalGenerator(),
+ config, false, tgt,
+ dagChecker, language),
+ entryOptions);
std::string usedOptions;
- for (std::vector<std::string>::iterator li = entryOptions.begin();
- li != entryOptions.end(); ++li) {
- std::string const& opt = *li;
-
+ for (std::string const& opt : entryOptions) {
if (uniqueOptions.insert(opt).second) {
- options.push_back(opt);
+ if (parse == OptionsParse::Shell &&
+ cmHasLiteralPrefix(opt, "SHELL:")) {
+ std::vector<std::string> tmp;
+ cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
+ for (std::string& o : tmp) {
+ options.emplace_back(std::move(o), entry->GetBacktrace());
+ }
+ } else {
+ options.emplace_back(opt, entry->GetBacktrace());
+ }
if (debugOptions) {
usedOptions += " * " + opt + "\n";
}
@@ -2678,9 +2976,10 @@ static void processCompileOptionsInternal(
}
if (!usedOptions.empty()) {
tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
- cmake::LOG, std::string("Used compile ") + logName +
- std::string(" for target ") + tgt->GetName() + ":\n" + usedOptions,
- (*it)->ge->GetBacktrace());
+ MessageType::LOG,
+ std::string("Used ") + logName + std::string(" for target ") +
+ tgt->GetName() + ":\n" + usedOptions,
+ entry->GetBacktrace());
}
}
}
@@ -2688,24 +2987,35 @@ static void processCompileOptionsInternal(
static void processCompileOptions(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
- std::vector<std::string>& options,
- CM_UNORDERED_SET<std::string>& uniqueOptions,
+ std::vector<BT<std::string>>& options,
+ std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, std::string const& language)
{
- processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
- dagChecker, config, debugOptions, "options",
- language);
+ processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
+ config, debugOptions, "compile options", language,
+ OptionsParse::Shell);
}
void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
const std::string& config,
const std::string& language) const
{
- CM_UNORDERED_SET<std::string> uniqueOptions;
+ std::vector<BT<std::string>> tmp = this->GetCompileOptions(config, language);
+ result.reserve(tmp.size());
+ for (BT<std::string>& v : tmp) {
+ result.emplace_back(std::move(v.Value));
+ }
+}
+
+std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
+ std::string const& config, std::string const& language) const
+{
+ std::vector<BT<std::string>> result;
+ std::unordered_set<std::string> uniqueOptions;
- cmGeneratorExpressionDAGChecker dagChecker(
- this->GetName(), "COMPILE_OPTIONS", CM_NULLPTR, CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr,
+ nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
@@ -2737,28 +3047,40 @@ void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
language);
cmDeleteAll(linkInterfaceCompileOptionsEntries);
+ return result;
}
static void processCompileFeatures(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
- std::vector<std::string>& options,
- CM_UNORDERED_SET<std::string>& uniqueOptions,
+ std::vector<BT<std::string>>& options,
+ std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions)
{
- processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
- dagChecker, config, debugOptions, "features",
- std::string());
+ processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
+ config, debugOptions, "compile features",
+ std::string(), OptionsParse::None);
}
void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
const std::string& config) const
{
- CM_UNORDERED_SET<std::string> uniqueFeatures;
+ std::vector<BT<std::string>> tmp = this->GetCompileFeatures(config);
+ result.reserve(tmp.size());
+ for (BT<std::string>& v : tmp) {
+ result.emplace_back(std::move(v.Value));
+ }
+}
+
+std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
+ std::string const& config) const
+{
+ std::vector<BT<std::string>> result;
+ std::unordered_set<std::string> uniqueFeatures;
- cmGeneratorExpressionDAGChecker dagChecker(
- this->GetName(), "COMPILE_FEATURES", CM_NULLPTR, CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr,
+ nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
@@ -2787,29 +3109,42 @@ void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
uniqueFeatures, &dagChecker, config, debugFeatures);
cmDeleteAll(linkInterfaceCompileFeaturesEntries);
+ return result;
}
static void processCompileDefinitions(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
- std::vector<std::string>& options,
- CM_UNORDERED_SET<std::string>& uniqueOptions,
+ std::vector<BT<std::string>>& options,
+ std::unordered_set<std::string>& uniqueOptions,
cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
bool debugOptions, std::string const& language)
{
- processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
- dagChecker, config, debugOptions,
- "definitions", language);
+ processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
+ config, debugOptions, "compile definitions", language,
+ OptionsParse::None);
}
void cmGeneratorTarget::GetCompileDefinitions(
- std::vector<std::string>& list, const std::string& config,
+ std::vector<std::string>& result, const std::string& config,
const std::string& language) const
{
- CM_UNORDERED_SET<std::string> uniqueOptions;
+ std::vector<BT<std::string>> tmp =
+ this->GetCompileDefinitions(config, language);
+ result.reserve(tmp.size());
+ for (BT<std::string>& v : tmp) {
+ result.emplace_back(std::move(v.Value));
+ }
+}
- cmGeneratorExpressionDAGChecker dagChecker(
- this->GetName(), "COMPILE_DEFINITIONS", CM_NULLPTR, CM_NULLPTR);
+std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
+ std::string const& config, std::string const& language) const
+{
+ std::vector<BT<std::string>> list;
+ std::unordered_set<std::string> uniqueOptions;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_DEFINITIONS",
+ nullptr, nullptr);
std::vector<std::string> debugProperties;
const char* debugProp =
@@ -2843,15 +3178,13 @@ void cmGeneratorTarget::GetCompileDefinitions(
case cmPolicies::WARN: {
std::ostringstream e;
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
- this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
+ e.str());
CM_FALLTHROUGH;
}
case cmPolicies::OLD: {
- cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
- ge.Parse(configProp);
linkInterfaceCompileDefinitionsEntries.push_back(
- new cmGeneratorTarget::TargetPropertyEntry(cge));
+ CreateTargetPropertyEntry(configProp));
} break;
case cmPolicies::NEW:
case cmPolicies::REQUIRED_ALWAYS:
@@ -2866,6 +3199,411 @@ void cmGeneratorTarget::GetCompileDefinitions(
language);
cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
+ return list;
+}
+
+namespace {
+void processLinkOptions(
+ cmGeneratorTarget const* tgt,
+ const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
+ std::vector<BT<std::string>>& options,
+ std::unordered_set<std::string>& uniqueOptions,
+ cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
+ bool debugOptions, std::string const& language)
+{
+ processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
+ config, debugOptions, "link options", language,
+ OptionsParse::Shell);
+}
+}
+
+void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
+ const std::string& config,
+ const std::string& language) const
+{
+ std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
+ result.reserve(tmp.size());
+ for (BT<std::string>& v : tmp) {
+ result.emplace_back(std::move(v.Value));
+ }
+}
+
+std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
+ std::string const& config, std::string const& language) const
+{
+ std::vector<BT<std::string>> result;
+ std::unordered_set<std::string> uniqueOptions;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr,
+ nullptr);
+
+ std::vector<std::string> debugProperties;
+ const char* debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp) {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugOptions = !this->DebugLinkOptionsDone &&
+ std::find(debugProperties.begin(), debugProperties.end(),
+ "LINK_OPTIONS") != debugProperties.end();
+
+ if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
+ this->DebugLinkOptionsDone = true;
+ }
+
+ processLinkOptions(this, this->LinkOptionsEntries, result, uniqueOptions,
+ &dagChecker, config, debugOptions, language);
+
+ std::vector<cmGeneratorTarget::TargetPropertyEntry*>
+ linkInterfaceLinkOptionsEntries;
+
+ AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS",
+ linkInterfaceLinkOptionsEntries);
+
+ processLinkOptions(this, linkInterfaceLinkOptionsEntries, result,
+ uniqueOptions, &dagChecker, config, debugOptions,
+ language);
+
+ cmDeleteAll(linkInterfaceLinkOptionsEntries);
+
+ // Last step: replace "LINKER:" prefixed elements by
+ // actual linker wrapper
+ const std::string wrapper(this->Makefile->GetSafeDefinition(
+ "CMAKE_" + language + "_LINKER_WRAPPER_FLAG"));
+ std::vector<std::string> wrapperFlag;
+ cmSystemTools::ExpandListArgument(wrapper, wrapperFlag);
+ const std::string wrapperSep(this->Makefile->GetSafeDefinition(
+ "CMAKE_" + language + "_LINKER_WRAPPER_FLAG_SEP"));
+ bool concatFlagAndArgs = true;
+ if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
+ concatFlagAndArgs = false;
+ wrapperFlag.pop_back();
+ }
+
+ const std::string LINKER{ "LINKER:" };
+ const std::string SHELL{ "SHELL:" };
+ const std::string LINKER_SHELL = LINKER + SHELL;
+
+ std::vector<BT<std::string>>::iterator entry;
+ while ((entry = std::find_if(result.begin(), result.end(),
+ [&LINKER](BT<std::string> const& item) -> bool {
+ return item.Value.compare(0, LINKER.length(),
+ LINKER) == 0;
+ })) != result.end()) {
+ std::string value = std::move(entry->Value);
+ cmListFileBacktrace bt = std::move(entry->Backtrace);
+ entry = result.erase(entry);
+
+ std::vector<std::string> linkerOptions;
+ if (value.compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
+ cmSystemTools::ParseUnixCommandLine(
+ value.c_str() + LINKER_SHELL.length(), linkerOptions);
+ } else {
+ linkerOptions =
+ cmSystemTools::tokenize(value.substr(LINKER.length()), ",");
+ }
+
+ if (linkerOptions.empty() ||
+ (linkerOptions.size() == 1 && linkerOptions.front().empty())) {
+ continue;
+ }
+
+ // for now, raise an error if prefix SHELL: is part of arguments
+ if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
+ [&SHELL](const std::string& item) -> bool {
+ return item.find(SHELL) != std::string::npos;
+ }) != linkerOptions.end()) {
+ this->LocalGenerator->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
+ this->GetBacktrace());
+ return result;
+ }
+
+ std::vector<BT<std::string>> options;
+ if (wrapperFlag.empty()) {
+ // nothing specified, insert elements as is
+ options.reserve(linkerOptions.size());
+ for (std::string& o : linkerOptions) {
+ options.emplace_back(std::move(o), bt);
+ }
+ } else {
+ if (!wrapperSep.empty()) {
+ if (concatFlagAndArgs) {
+ // insert flag elements except last one
+ for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
+ options.emplace_back(*i, bt);
+ }
+ // concatenate last flag element and all LINKER list values
+ // in one option
+ options.emplace_back(
+ wrapperFlag.back() + cmJoin(linkerOptions, wrapperSep), bt);
+ } else {
+ for (std::string const& i : wrapperFlag) {
+ options.emplace_back(i, bt);
+ }
+ // concatenate all LINKER list values in one option
+ options.emplace_back(cmJoin(linkerOptions, wrapperSep), bt);
+ }
+ } else {
+ // prefix each element of LINKER list with wrapper
+ if (concatFlagAndArgs) {
+ std::transform(linkerOptions.begin(), linkerOptions.end(),
+ linkerOptions.begin(),
+ [&wrapperFlag](std::string const& o) -> std::string {
+ return wrapperFlag.back() + o;
+ });
+ }
+ for (std::string& o : linkerOptions) {
+ for (auto i = wrapperFlag.begin(),
+ e = concatFlagAndArgs ? wrapperFlag.end() - 1
+ : wrapperFlag.end();
+ i != e; ++i) {
+ options.emplace_back(*i, bt);
+ }
+ options.emplace_back(std::move(o), bt);
+ }
+ }
+ }
+ result.insert(entry, options.begin(), options.end());
+ }
+ return result;
+}
+
+namespace {
+void processStaticLibraryLinkOptions(
+ cmGeneratorTarget const* tgt,
+ const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
+ std::vector<BT<std::string>>& options,
+ std::unordered_set<std::string>& uniqueOptions,
+ cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
+ std::string const& language)
+{
+ processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
+ config, false, "static library link options",
+ language, OptionsParse::Shell);
+}
+}
+
+void cmGeneratorTarget::GetStaticLibraryLinkOptions(
+ std::vector<std::string>& result, const std::string& config,
+ const std::string& language) const
+{
+ std::vector<BT<std::string>> tmp =
+ this->GetStaticLibraryLinkOptions(config, language);
+ result.reserve(tmp.size());
+ for (BT<std::string>& v : tmp) {
+ result.emplace_back(std::move(v.Value));
+ }
+}
+
+std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
+ std::string const& config, std::string const& language) const
+{
+ std::vector<BT<std::string>> result;
+ std::vector<cmGeneratorTarget::TargetPropertyEntry*> entries;
+ std::unordered_set<std::string> uniqueOptions;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS",
+ nullptr, nullptr);
+
+ if (const char* linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
+ std::vector<std::string> options;
+ cmSystemTools::ExpandListArgument(linkOptions, options);
+ for (const auto& option : options) {
+ entries.push_back(CreateTargetPropertyEntry(option));
+ }
+ }
+ processStaticLibraryLinkOptions(this, entries, result, uniqueOptions,
+ &dagChecker, config, language);
+
+ cmDeleteAll(entries);
+ return result;
+}
+
+namespace {
+void processLinkDirectories(
+ cmGeneratorTarget const* tgt,
+ const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
+ std::vector<BT<std::string>>& directories,
+ std::unordered_set<std::string>& uniqueDirectories,
+ cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
+ bool debugDirectories, std::string const& language)
+{
+ for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
+ cmLinkImplItem const& item = entry->LinkImplItem;
+ std::string const& targetName = item.AsStr();
+
+ std::vector<std::string> entryDirectories;
+ cmSystemTools::ExpandListArgument(entry->Evaluate(tgt->GetLocalGenerator(),
+ config, false, tgt,
+ dagChecker, language),
+ entryDirectories);
+
+ std::string usedDirectories;
+ for (std::string& entryDirectory : entryDirectories) {
+ if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
+ std::ostringstream e;
+ bool noMessage = false;
+ MessageType messageType = MessageType::FATAL_ERROR;
+ if (!targetName.empty()) {
+ /* clang-format off */
+ e << "Target \"" << targetName << "\" contains relative "
+ "path in its INTERFACE_LINK_DIRECTORIES:\n"
+ " \"" << entryDirectory << "\"";
+ /* clang-format on */
+ } else {
+ switch (tgt->GetPolicyStatusCMP0081()) {
+ case cmPolicies::WARN: {
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
+ messageType = MessageType::AUTHOR_WARNING;
+ } break;
+ case cmPolicies::OLD:
+ noMessage = true;
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ // Issue the fatal message.
+ break;
+ }
+ e << "Found relative path while evaluating link directories of "
+ "\""
+ << tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
+ }
+ if (!noMessage) {
+ tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
+ if (messageType == MessageType::FATAL_ERROR) {
+ return;
+ }
+ }
+ }
+
+ // Sanitize the path the same way the link_directories command does
+ // in case projects set the LINK_DIRECTORIES property directly.
+ cmSystemTools::ConvertToUnixSlashes(entryDirectory);
+ if (uniqueDirectories.insert(entryDirectory).second) {
+ directories.emplace_back(entryDirectory);
+ if (debugDirectories) {
+ usedDirectories += " * " + entryDirectory + "\n";
+ }
+ }
+ }
+ if (!usedDirectories.empty()) {
+ tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
+ MessageType::LOG,
+ std::string("Used link directories for target ") + tgt->GetName() +
+ ":\n" + usedDirectories,
+ entry->GetBacktrace());
+ }
+ }
+}
+}
+
+void cmGeneratorTarget::GetLinkDirectories(std::vector<std::string>& result,
+ const std::string& config,
+ const std::string& language) const
+{
+ std::vector<BT<std::string>> tmp =
+ this->GetLinkDirectories(config, language);
+ result.reserve(tmp.size());
+ for (BT<std::string>& v : tmp) {
+ result.emplace_back(std::move(v.Value));
+ }
+}
+
+std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
+ std::string const& config, std::string const& language) const
+{
+ std::vector<BT<std::string>> result;
+ std::unordered_set<std::string> uniqueDirectories;
+
+ cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr,
+ nullptr);
+
+ std::vector<std::string> debugProperties;
+ const char* debugProp =
+ this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
+ if (debugProp) {
+ cmSystemTools::ExpandListArgument(debugProp, debugProperties);
+ }
+
+ bool debugDirectories = !this->DebugLinkDirectoriesDone &&
+ std::find(debugProperties.begin(), debugProperties.end(),
+ "LINK_DIRECTORIES") != debugProperties.end();
+
+ if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
+ this->DebugLinkDirectoriesDone = true;
+ }
+
+ processLinkDirectories(this, this->LinkDirectoriesEntries, result,
+ uniqueDirectories, &dagChecker, config,
+ debugDirectories, language);
+
+ std::vector<cmGeneratorTarget::TargetPropertyEntry*>
+ linkInterfaceLinkDirectoriesEntries;
+
+ AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES",
+ linkInterfaceLinkDirectoriesEntries);
+
+ processLinkDirectories(this, linkInterfaceLinkDirectoriesEntries, result,
+ uniqueDirectories, &dagChecker, config,
+ debugDirectories, language);
+
+ cmDeleteAll(linkInterfaceLinkDirectoriesEntries);
+ return result;
+}
+
+namespace {
+void processLinkDepends(
+ cmGeneratorTarget const* tgt,
+ const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
+ std::vector<BT<std::string>>& options,
+ std::unordered_set<std::string>& uniqueOptions,
+ cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
+ std::string const& language)
+{
+ processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
+ config, false, "link depends", language,
+ OptionsParse::None);
+}
+}
+
+void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
+ const std::string& config,
+ const std::string& language) const
+{
+ std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
+ result.reserve(tmp.size());
+ for (BT<std::string>& v : tmp) {
+ result.emplace_back(std::move(v.Value));
+ }
+}
+
+std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
+ std::string const& config, std::string const& language) const
+{
+ std::vector<BT<std::string>> result;
+ std::vector<cmGeneratorTarget::TargetPropertyEntry*> linkDependsEntries;
+ std::unordered_set<std::string> uniqueOptions;
+ cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr,
+ nullptr);
+
+ if (const char* linkDepends = this->GetProperty("LINK_DEPENDS")) {
+ std::vector<std::string> depends;
+ cmSystemTools::ExpandListArgument(linkDepends, depends);
+ for (const auto& depend : depends) {
+ linkDependsEntries.push_back(CreateTargetPropertyEntry(depend));
+ }
+ }
+ AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS",
+ linkDependsEntries);
+ processLinkDepends(this, linkDependsEntries, result, uniqueOptions,
+ &dagChecker, config, language);
+
+ cmDeleteAll(linkDependsEntries);
+ return result;
}
void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
@@ -2876,17 +3614,13 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
// Get the names.
- std::string name;
- std::string soName;
- std::string realName;
- std::string impName;
- std::string pdbName;
+ cmGeneratorTarget::Names targetNames;
if (this->GetType() == cmStateEnums::EXECUTABLE) {
- this->GetExecutableNames(name, realName, impName, pdbName, config);
+ targetNames = this->GetExecutableNames(config);
} else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::MODULE_LIBRARY) {
- this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
+ targetNames = this->GetLibraryNames(config);
} else {
return;
}
@@ -2897,45 +3631,43 @@ void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
// Add each name.
std::string f;
- if (!name.empty()) {
+ if (!targetNames.Output.empty()) {
f = dir;
f += "/";
- f += name;
+ f += targetNames.Output;
gg->AddToManifest(f);
}
- if (!soName.empty()) {
+ if (!targetNames.SharedObject.empty()) {
f = dir;
f += "/";
- f += soName;
+ f += targetNames.SharedObject;
gg->AddToManifest(f);
}
- if (!realName.empty()) {
+ if (!targetNames.Real.empty()) {
f = dir;
f += "/";
- f += realName;
+ f += targetNames.Real;
gg->AddToManifest(f);
}
- if (!pdbName.empty()) {
+ if (!targetNames.PDB.empty()) {
f = dir;
f += "/";
- f += pdbName;
+ f += targetNames.PDB;
gg->AddToManifest(f);
}
- if (!impName.empty()) {
+ if (!targetNames.ImportLibrary.empty()) {
f = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact);
f += "/";
- f += impName;
+ f += targetNames.ImportLibrary;
gg->AddToManifest(f);
}
}
bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) const
{
- std::vector<std::string> features;
- this->GetCompileFeatures(features, config);
- for (std::vector<std::string>::const_iterator it = features.begin();
- it != features.end(); ++it) {
- if (!this->Makefile->AddRequiredTargetFeature(this->Target, *it)) {
+ std::vector<BT<std::string>> features = this->GetCompileFeatures(config);
+ for (BT<std::string> const& f : features) {
+ if (!this->Makefile->AddRequiredTargetFeature(this->Target, f.Value)) {
return false;
}
}
@@ -2999,42 +3731,29 @@ std::string cmGeneratorTarget::NormalGetRealName(
if (this->IsImported()) {
std::string msg = "NormalGetRealName called on imported target: ";
msg += this->GetName();
- this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
+ this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
}
if (this->GetType() == cmStateEnums::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;
+ return this->GetExecutableNames(config).Real;
}
// 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;
-}
-
-void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
- std::string& realName,
- std::string& impName,
- std::string& pdbName,
- const std::string& config) const
+ return this->GetLibraryNames(config).Real;
+}
+
+cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames(
+ const std::string& config) const
{
+ cmGeneratorTarget::Names targetNames;
+
// 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->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
- return;
+ this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
}
// Check for library version properties.
@@ -3045,8 +3764,8 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
this->IsFrameworkOnApple()) {
// Versioning is supported only for shared libraries and modules,
// and then only when the platform supports an soname flag.
- version = CM_NULLPTR;
- soversion = CM_NULLPTR;
+ version = nullptr;
+ soversion = nullptr;
}
if (version && !soversion) {
// The soversion must be set if the library version is set. Use
@@ -3060,57 +3779,58 @@ void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
// Get the components of the library name.
std::string prefix;
- std::string base;
std::string suffix;
this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
- prefix, base, suffix);
+ prefix, targetNames.Base, suffix);
// The library name.
- name = prefix + base + suffix;
+ targetNames.Output = prefix + targetNames.Base + suffix;
if (this->IsFrameworkOnApple()) {
- realName = prefix;
- if (!this->Makefile->PlatformIsAppleIos()) {
- realName += "Versions/";
- realName += this->GetFrameworkVersion();
- realName += "/";
- }
- realName += base;
- soName = realName;
+ targetNames.Real = prefix;
+ if (!this->Makefile->PlatformIsAppleEmbedded()) {
+ targetNames.Real += "Versions/";
+ targetNames.Real += this->GetFrameworkVersion();
+ targetNames.Real += "/";
+ }
+ targetNames.Real += targetNames.Base;
+ targetNames.SharedObject = targetNames.Real;
} else {
// The library's soname.
- this->ComputeVersionedName(soName, prefix, base, suffix, name, soversion);
+ this->ComputeVersionedName(targetNames.SharedObject, prefix,
+ targetNames.Base, suffix, targetNames.Output,
+ soversion);
// The library's real name on disk.
- this->ComputeVersionedName(realName, prefix, base, suffix, name, version);
+ this->ComputeVersionedName(targetNames.Real, prefix, targetNames.Base,
+ suffix, targetNames.Output, version);
}
// The import library name.
if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::MODULE_LIBRARY) {
- impName =
+ targetNames.ImportLibrary =
this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
- } else {
- impName = "";
}
// The program database file name.
- pdbName = this->GetPDBName(config);
+ targetNames.PDB = this->GetPDBName(config);
+
+ return targetNames;
}
-void cmGeneratorTarget::GetExecutableNames(std::string& name,
- std::string& realName,
- std::string& impName,
- std::string& pdbName,
- const std::string& config) const
+cmGeneratorTarget::Names cmGeneratorTarget::GetExecutableNames(
+ const std::string& config) const
{
+ cmGeneratorTarget::Names targetNames;
+
// 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->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
+ this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
}
// This versioning is supported only for executables and then only
@@ -3122,40 +3842,41 @@ void cmGeneratorTarget::GetExecutableNames(std::string& name,
const char* version = this->GetProperty("VERSION");
if (this->GetType() != cmStateEnums::EXECUTABLE ||
this->Makefile->IsOn("XCODE")) {
- version = CM_NULLPTR;
+ version = nullptr;
}
#endif
// Get the components of the executable name.
std::string prefix;
- std::string base;
std::string suffix;
this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
- prefix, base, suffix);
+ prefix, targetNames.Base, suffix);
// The executable name.
- name = prefix + base + suffix;
+ targetNames.Output = prefix + targetNames.Base + suffix;
// The executable's real name on disk.
#if defined(__CYGWIN__)
- realName = prefix + base;
+ targetNames.Real = prefix + targetNames.Base;
#else
- realName = name;
+ targetNames.Real = targetNames.Output;
#endif
if (version) {
- realName += "-";
- realName += version;
+ targetNames.Real += "-";
+ targetNames.Real += version;
}
#if defined(__CYGWIN__)
- realName += suffix;
+ targetNames.Real += suffix;
#endif
// The import library name.
- impName =
+ targetNames.ImportLibrary =
this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
// The program database file name.
- pdbName = this->GetPDBName(config);
+ targetNames.PDB = this->GetPDBName(config);
+
+ return targetNames;
}
std::string cmGeneratorTarget::GetFullNameInternal(
@@ -3168,14 +3889,12 @@ std::string cmGeneratorTarget::GetFullNameInternal(
return prefix + base + suffix;
}
-const char* cmGeneratorTarget::ImportedGetLocation(
+std::string cmGeneratorTarget::ImportedGetLocation(
const std::string& config) const
{
- static std::string location;
assert(this->IsImported());
- location = this->Target->ImportedGetFullPath(
+ return this->Target->ImportedGetFullPath(
config, cmStateEnums::RuntimeBinaryArtifact);
- return location.c_str();
}
std::string cmGeneratorTarget::GetFullNameImported(
@@ -3194,9 +3913,9 @@ void cmGeneratorTarget::GetFullNameInternal(
this->GetType() != cmStateEnums::SHARED_LIBRARY &&
this->GetType() != cmStateEnums::MODULE_LIBRARY &&
this->GetType() != cmStateEnums::EXECUTABLE) {
- outPrefix = "";
+ outPrefix.clear();
outBase = this->GetName();
- outSuffix = "";
+ outSuffix.clear();
return;
}
@@ -3207,12 +3926,17 @@ void cmGeneratorTarget::GetFullNameInternal(
// does not support import libraries.
if (isImportedLibraryArtifact &&
!this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
- outPrefix = "";
- outBase = "";
- outSuffix = "";
+ outPrefix.clear();
+ outBase.clear();
+ outSuffix.clear();
return;
}
+ // retrieve prefix and suffix
+ std::string ll = this->GetLinkerLanguage(config);
+ const char* targetPrefix = this->GetFilePrefixInternal(artifact, ll);
+ const char* targetSuffix = this->GetFileSuffixInternal(artifact, ll);
+
// The implib option is only allowed for shared libraries, module
// libraries, and executables.
if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
@@ -3222,47 +3946,7 @@ void cmGeneratorTarget::GetFullNameInternal(
}
// Compute the full name for main target types.
- const char* targetPrefix =
- (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
- : this->GetProperty("PREFIX"));
- const char* targetSuffix =
- (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
- : this->GetProperty("SUFFIX"));
- const char* configPostfix = CM_NULLPTR;
- 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 = CM_NULLPTR;
- }
- }
- const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
- const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
-
- // 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);
- }
+ const std::string configPostfix = this->GetFilePostfix(config);
// frameworks have directory prefix but no suffix
std::string fw_prefix;
@@ -3270,14 +3954,14 @@ void cmGeneratorTarget::GetFullNameInternal(
fw_prefix = this->GetFrameworkDirectory(config, ContentLevel);
fw_prefix += "/";
targetPrefix = fw_prefix.c_str();
- targetSuffix = CM_NULLPTR;
+ targetSuffix = nullptr;
}
if (this->IsCFBundleOnApple()) {
fw_prefix = this->GetCFBundleDirectory(config, FullLevel);
fw_prefix += "/";
targetPrefix = fw_prefix.c_str();
- targetSuffix = CM_NULLPTR;
+ targetSuffix = nullptr;
}
// Begin the final name with the prefix.
@@ -3287,7 +3971,7 @@ void cmGeneratorTarget::GetFullNameInternal(
outBase += this->GetOutputName(config, artifact);
// Append the per-configuration postfix.
- outBase += configPostfix ? configPostfix : "";
+ outBase += configPostfix;
// Name shared libraries with their version number on some platforms.
if (const char* soversion = this->GetProperty("SOVERSION")) {
@@ -3309,6 +3993,31 @@ std::string cmGeneratorTarget::GetLinkerLanguage(
return this->GetLinkClosure(config)->LinkerLanguage;
}
+std::string cmGeneratorTarget::GetPDBOutputName(
+ const std::string& config) const
+{
+ std::string base =
+ this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
+
+ 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.emplace_back("PDB_NAME");
+
+ for (std::string const& p : props) {
+ if (const char* outName = this->GetProperty(p)) {
+ base = outName;
+ break;
+ }
+ }
+ return base;
+}
+
std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
{
std::string prefix;
@@ -3325,11 +4034,10 @@ std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
}
// PDB_NAME
- props.push_back("PDB_NAME");
+ props.emplace_back("PDB_NAME");
- for (std::vector<std::string>::const_iterator i = props.begin();
- i != props.end(); ++i) {
- if (const char* outName = this->GetProperty(*i)) {
+ for (std::string const& p : props) {
+ if (const char* outName = this->GetProperty(p)) {
base = outName;
break;
}
@@ -3346,6 +4054,13 @@ std::string cmGeneratorTarget::GetObjectDirectory(
// find and replace $(PROJECT_NAME) xcode placeholder
const std::string projectName = this->LocalGenerator->GetProjectName();
cmSystemTools::ReplaceString(obj_dir, "$(PROJECT_NAME)", projectName);
+ // Replace Xcode's placeholder for the object file directory since
+ // installation and export scripts need to know the real directory.
+ // Xcode has build-time settings (e.g. for sanitizers) that affect this,
+ // but we use the default here. Users that want to enable sanitizers
+ // will do so at the cost of object library installation and export.
+ cmSystemTools::ReplaceString(obj_dir, "$(OBJECT_FILE_DIR_normal:base)",
+ "Objects-normal");
#endif
return obj_dir;
}
@@ -3357,20 +4072,16 @@ void cmGeneratorTarget::GetTargetObjectNames(
this->GetObjectSources(objectSources, config);
std::map<cmSourceFile const*, std::string> mapping;
- for (std::vector<cmSourceFile const*>::const_iterator it =
- objectSources.begin();
- it != objectSources.end(); ++it) {
- mapping[*it];
+ for (cmSourceFile const* sf : objectSources) {
+ mapping[sf];
}
this->LocalGenerator->ComputeObjectFilenames(mapping, this);
- for (std::vector<cmSourceFile const*>::const_iterator it =
- objectSources.begin();
- it != objectSources.end(); ++it) {
+ for (cmSourceFile const* src : objectSources) {
// Find the object file name corresponding to this source file.
std::map<cmSourceFile const*, std::string>::const_iterator map_it =
- mapping.find(*it);
+ mapping.find(src);
// It must exist because we populated the mapping just above.
assert(!map_it->second.empty());
objects.push_back(map_it->second);
@@ -3382,8 +4093,9 @@ bool cmGeneratorTarget::StrictTargetComparison::operator()(
{
int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
if (nameResult == 0) {
- return strcmp(t1->GetLocalGenerator()->GetCurrentBinaryDirectory(),
- t2->GetLocalGenerator()->GetCurrentBinaryDirectory()) < 0;
+ return strcmp(
+ t1->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str(),
+ t2->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str()) < 0;
}
return nameResult < 0;
}
@@ -3433,9 +4145,8 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
if (const char* files = this->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)) {
+ for (std::string const& relFile : relFiles) {
+ if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
SourceFileFlags& flags = this->SourceFlagsMap[sf];
flags.MacFolder = "Headers";
flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
@@ -3448,9 +4159,8 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
if (const char* files = this->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)) {
+ for (std::string const& relFile : relFiles) {
+ if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
SourceFileFlags& flags = this->SourceFlagsMap[sf];
flags.MacFolder = "PrivateHeaders";
flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
@@ -3462,9 +4172,8 @@ void cmGeneratorTarget::ConstructSourceFileFlags() const
if (const char* files = this->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)) {
+ for (std::string const& relFile : relFiles) {
+ if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
SourceFileFlags& flags = this->SourceFlagsMap[sf];
flags.MacFolder = "";
if (!this->GlobalGenerator->ShouldStripResourcePath(this->Makefile)) {
@@ -3487,11 +4196,9 @@ cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
compat.PropsString.insert("AUTOUIC_OPTIONS");
std::vector<cmGeneratorTarget const*> const& deps =
this->GetLinkImplementationClosure(config);
- for (std::vector<cmGeneratorTarget const*>::const_iterator li =
- deps.begin();
- li != deps.end(); ++li) {
+ for (cmGeneratorTarget const* li : deps) {
#define CM_READ_COMPATIBLE_INTERFACE(X, x) \
- if (const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
+ if (const char* prop = li->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
std::vector<std::string> props; \
cmSystemTools::ExpandListArgument(prop, props); \
compat.Props##x.insert(props.begin(), props.end()); \
@@ -3581,7 +4288,7 @@ const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
case BoolType:
assert(false &&
"String compatibility check function called for boolean");
- return CM_NULLPTR;
+ return nullptr;
case StringType:
return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
case NumberMinType:
@@ -3590,7 +4297,7 @@ const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
}
assert(false && "Unreachable!");
- return CM_NULLPTR;
+ return nullptr;
}
template <typename PropertyType>
@@ -3611,24 +4318,24 @@ void checkPropertyConsistency(cmGeneratorTarget const* depender,
std::string pdir = cmSystemTools::GetCMakeRoot();
pdir += "/Help/prop_tgt/";
- for (std::vector<std::string>::iterator pi = props.begin();
- pi != props.end(); ++pi) {
- std::string pname = cmSystemTools::HelpFileName(*pi);
+ for (std::string const& p : props) {
+ std::string pname = cmSystemTools::HelpFileName(p);
std::string pfile = pdir + pname + ".rst";
- if (cmSystemTools::FileExists(pfile.c_str(), true)) {
+ if (cmSystemTools::FileExists(pfile, true)) {
std::ostringstream e;
- e << "Target \"" << dependee->GetName() << "\" has property \"" << *pi
+ e << "Target \"" << dependee->GetName() << "\" has property \"" << p
<< "\" listed in its " << propName
<< " property. "
"This is not allowed. Only user-defined properties may appear "
"listed in the "
<< propName << " property.";
- depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
+ depender->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str());
return;
}
- if (emitted.insert(*pi).second) {
- getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config, t,
- CM_NULLPTR);
+ if (emitted.insert(p).second) {
+ getLinkInterfaceDependentProperty<PropertyType>(depender, p, config, t,
+ nullptr);
if (cmSystemTools::GetErrorOccuredFlag()) {
return;
}
@@ -3691,40 +4398,39 @@ void cmGeneratorTarget::CheckPropertyCompatibility(
const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
std::set<std::string> emittedBools;
- static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
+ static const std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
std::set<std::string> emittedStrings;
- static std::string strString = "COMPATIBLE_INTERFACE_STRING";
+ static const std::string strString = "COMPATIBLE_INTERFACE_STRING";
std::set<std::string> emittedMinNumbers;
- static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
+ static const std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
std::set<std::string> emittedMaxNumbers;
- static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
+ static const std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
- for (cmComputeLinkInformation::ItemVector::const_iterator li = deps.begin();
- li != deps.end(); ++li) {
- if (!li->Target) {
+ for (auto const& dep : deps) {
+ if (!dep.Target) {
continue;
}
- checkPropertyConsistency<bool>(this, li->Target, strBool, emittedBools,
- config, BoolType, CM_NULLPTR);
+ checkPropertyConsistency<bool>(this, dep.Target, strBool, emittedBools,
+ config, BoolType, nullptr);
if (cmSystemTools::GetErrorOccuredFlag()) {
return;
}
- checkPropertyConsistency<const char*>(this, li->Target, strString,
+ checkPropertyConsistency<const char*>(this, dep.Target, strString,
emittedStrings, config, StringType,
- CM_NULLPTR);
+ nullptr);
if (cmSystemTools::GetErrorOccuredFlag()) {
return;
}
- checkPropertyConsistency<const char*>(this, li->Target, strNumMin,
+ checkPropertyConsistency<const char*>(this, dep.Target, strNumMin,
emittedMinNumbers, config,
- NumberMinType, CM_NULLPTR);
+ NumberMinType, nullptr);
if (cmSystemTools::GetErrorOccuredFlag()) {
return;
}
- checkPropertyConsistency<const char*>(this, li->Target, strNumMax,
+ checkPropertyConsistency<const char*>(this, dep.Target, strNumMax,
emittedMaxNumbers, config,
- NumberMaxType, CM_NULLPTR);
+ NumberMaxType, nullptr);
if (cmSystemTools::GetErrorOccuredFlag()) {
return;
}
@@ -3764,10 +4470,33 @@ void cmGeneratorTarget::CheckPropertyCompatibility(
"in a boolean interpretation, a numeric minimum, a numeric maximum "
"or a "
"string interpretation, but not a mixture.";
- this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
}
+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)";
+}
+template <>
+std::string valueAsString<std::string>(std::string value)
+{
+ return value;
+}
+template <>
+std::string valueAsString<std::nullptr_t>(std::nullptr_t /*unused*/)
+{
+ return "(unset)";
+}
+
std::string compatibilityType(CompatibleType t)
{
switch (t) {
@@ -3799,34 +4528,49 @@ std::string compatibilityAgree(CompatibleType t, bool dominant)
}
template <typename PropertyType>
-PropertyType getTypedProperty(cmGeneratorTarget const* tgt,
- const std::string& prop);
+PropertyType getTypedProperty(
+ cmGeneratorTarget const* tgt, const std::string& prop,
+ cmGeneratorExpressionInterpreter* genexInterpreter = nullptr);
template <>
bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
- const std::string& prop)
+ const std::string& prop,
+ cmGeneratorExpressionInterpreter* genexInterpreter)
{
- return tgt->GetPropertyAsBool(prop);
-}
+ if (genexInterpreter == nullptr) {
+ return tgt->GetPropertyAsBool(prop);
+ }
-template <>
-const char* getTypedProperty<const char*>(cmGeneratorTarget const* tgt,
- const std::string& prop)
-{
- return tgt->GetProperty(prop);
+ const char* value = tgt->GetProperty(prop);
+ return cmSystemTools::IsOn(genexInterpreter->Evaluate(value, prop));
}
-template <typename PropertyType>
-std::string valueAsString(PropertyType);
template <>
-std::string valueAsString<bool>(bool value)
+const char* getTypedProperty<const char*>(
+ cmGeneratorTarget const* tgt, const std::string& prop,
+ cmGeneratorExpressionInterpreter* genexInterpreter)
{
- return value ? "TRUE" : "FALSE";
+ const char* value = tgt->GetProperty(prop);
+
+ if (genexInterpreter == nullptr) {
+ return value;
+ }
+
+ return genexInterpreter->Evaluate(value, prop).c_str();
}
+
template <>
-std::string valueAsString<const char*>(const char* value)
+std::string getTypedProperty<std::string>(
+ cmGeneratorTarget const* tgt, const std::string& prop,
+ cmGeneratorExpressionInterpreter* genexInterpreter)
{
- return value ? value : "(unset)";
+ const char* value = tgt->GetProperty(prop);
+
+ if (genexInterpreter == nullptr) {
+ return valueAsString(value);
+ }
+
+ return genexInterpreter->Evaluate(value, prop);
}
template <typename PropertyType>
@@ -3841,6 +4585,11 @@ const char* impliedValue<const char*>(const char* /*unused*/)
{
return "";
}
+template <>
+std::string impliedValue<std::string>(std::string /*unused*/) // NOLINT(*)
+{
+ return std::string();
+}
template <typename PropertyType>
std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
@@ -3858,7 +4607,14 @@ 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 : CM_NULLPTR);
+ return std::make_pair(b, b ? lhs : nullptr);
+}
+
+std::pair<bool, std::string> consistentStringProperty(const std::string& lhs,
+ const std::string& rhs)
+{
+ const bool b = lhs == rhs;
+ return std::make_pair(b, b ? lhs : valueAsString(nullptr));
}
std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
@@ -3867,7 +4623,7 @@ std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
{
char* pEnd;
- const char* const null_ptr = CM_NULLPTR;
+ const char* const null_ptr = nullptr;
long lnum = strtol(lhs, &pEnd, 0);
if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
@@ -3900,12 +4656,13 @@ std::pair<bool, const char*> consistentProperty(const char* lhs,
return std::make_pair(true, lhs);
}
- const char* const null_ptr = CM_NULLPTR;
+ const char* const null_ptr = nullptr;
switch (t) {
- case BoolType:
- assert(false && "consistentProperty for strings called with BoolType");
- return std::pair<bool, const char*>(false, null_ptr);
+ case BoolType: {
+ bool same = cmSystemTools::IsOn(lhs) == cmSystemTools::IsOn(rhs);
+ return std::make_pair(same, same ? lhs : nullptr);
+ }
case StringType:
return consistentStringProperty(lhs, rhs);
case NumberMinType:
@@ -3916,6 +4673,40 @@ std::pair<bool, const char*> consistentProperty(const char* lhs,
return std::pair<bool, const char*>(false, null_ptr);
}
+std::pair<bool, std::string> consistentProperty(const std::string& lhs,
+ const std::string& rhs,
+ CompatibleType t)
+{
+ const std::string null_ptr = valueAsString(nullptr);
+
+ if (lhs == null_ptr && rhs == null_ptr) {
+ return std::make_pair(true, lhs);
+ }
+ if (lhs == null_ptr) {
+ return std::make_pair(true, rhs);
+ }
+ if (rhs == null_ptr) {
+ return std::make_pair(true, lhs);
+ }
+
+ switch (t) {
+ case BoolType: {
+ bool same = cmSystemTools::IsOn(lhs) == cmSystemTools::IsOn(rhs);
+ return std::make_pair(same, same ? lhs : null_ptr);
+ }
+ case StringType:
+ return consistentStringProperty(lhs, rhs);
+ case NumberMinType:
+ case NumberMaxType: {
+ auto value = consistentNumberProperty(lhs.c_str(), rhs.c_str(), t);
+ return std::make_pair(
+ value.first, value.first ? std::string(value.second) : null_ptr);
+ }
+ }
+ assert(false && "Unreachable!");
+ return std::pair<bool, std::string>(false, null_ptr);
+}
+
template <typename PropertyType>
PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
const std::string& p,
@@ -3925,6 +4716,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
PropertyType* /*unused*/)
{
PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
+
std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
const bool explicitlySet =
std::find(headPropKeys.begin(), headPropKeys.end(), p) !=
@@ -3954,22 +4746,24 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
}
std::string interfaceProperty = "INTERFACE_" + p;
- for (std::vector<cmGeneratorTarget const*>::const_iterator li = deps.begin();
- li != deps.end(); ++li) {
+ std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter(
+ p == "POSITION_INDEPENDENT_CODE" ? new cmGeneratorExpressionInterpreter(
+ tgt->GetLocalGenerator(), config, tgt)
+ : nullptr);
+
+ for (cmGeneratorTarget const* theTarget : deps) {
// 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.
- cmGeneratorTarget const* theTarget = *li;
-
std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
const bool ifaceIsSet = std::find(propKeys.begin(), propKeys.end(),
interfaceProperty) != propKeys.end();
- PropertyType ifacePropContent =
- getTypedProperty<PropertyType>(theTarget, interfaceProperty);
+ PropertyType ifacePropContent = getTypedProperty<PropertyType>(
+ theTarget, interfaceProperty, genexInterpreter.get());
std::string reportEntry;
if (ifaceIsSet) {
@@ -3991,10 +4785,11 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
e << "Property " << p << " on target \"" << tgt->GetName()
<< "\" does\nnot match the "
"INTERFACE_"
- << p << " property requirement\nof "
- "dependency \""
+ << p
+ << " property requirement\nof "
+ "dependency \""
<< theTarget->GetName() << "\".\n";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
break;
}
propContent = consistent.second;
@@ -4019,7 +4814,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
"already. The INTERFACE_"
<< p << " property on\ndependency \"" << theTarget->GetName()
<< "\" is in conflict.\n";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
break;
}
propContent = consistent.second;
@@ -4039,7 +4834,7 @@ PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
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());
+ cmSystemTools::Error(e.str());
break;
}
propContent = consistent.second;
@@ -4063,28 +4858,35 @@ bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
const std::string& p, const std::string& config) const
{
return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
- BoolType, CM_NULLPTR);
+ BoolType, nullptr);
+}
+
+std::string cmGeneratorTarget::GetLinkInterfaceDependentStringAsBoolProperty(
+ const std::string& p, const std::string& config) const
+{
+ return checkInterfacePropertyCompatibility<std::string>(
+ this, p, config, "FALSE", BoolType, nullptr);
}
const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
const std::string& p, const std::string& config) const
{
return checkInterfacePropertyCompatibility<const char*>(
- this, p, config, "empty", StringType, CM_NULLPTR);
+ this, p, config, "empty", StringType, nullptr);
}
const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
const std::string& p, const std::string& config) const
{
return checkInterfacePropertyCompatibility<const char*>(
- this, p, config, "empty", NumberMinType, CM_NULLPTR);
+ this, p, config, "empty", NumberMinType, nullptr);
}
const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
const std::string& p, const std::string& config) const
{
return checkInterfacePropertyCompatibility<const char*>(
- this, p, config, "empty", NumberMaxType, CM_NULLPTR);
+ this, p, config, "empty", NumberMaxType, nullptr);
}
cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
@@ -4099,7 +4901,7 @@ cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
new cmComputeLinkInformation(this, config);
if (!info || !info->Compute()) {
delete info;
- info = CM_NULLPTR;
+ info = nullptr;
}
// Store the information for this configuration.
@@ -4233,9 +5035,8 @@ std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
cmPropertyMap const& propsObject = this->Target->GetProperties();
std::vector<std::string> props;
props.reserve(propsObject.size());
- for (cmPropertyMap::const_iterator it = propsObject.begin();
- it != propsObject.end(); ++it) {
- props.push_back(it->first);
+ for (auto const& it : propsObject) {
+ props.push_back(it.first);
}
return props;
}
@@ -4269,19 +5070,20 @@ void cmGeneratorTarget::ReportPropertyOrigin(
areport += result;
areport += "\"):\n" + report;
- this->LocalGenerator->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
+ this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG,
+ areport);
}
void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
+ cmListFileBacktrace const& bt,
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);
+ for (std::string const& n : names) {
+ std::string name = this->CheckCMP0004(n);
if (name == this->GetName() || name.empty()) {
continue;
}
- items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
+ items.push_back(this->ResolveLinkItem(name, bt));
}
}
@@ -4291,20 +5093,19 @@ void cmGeneratorTarget::ExpandLinkItems(
std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition) const
{
cmGeneratorExpression ge;
- cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, CM_NULLPTR,
- CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
// 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;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(value);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator, config,
false, headTarget, this,
&dagChecker),
libs);
- this->LookupLinkItems(libs, items);
+ this->LookupLinkItems(libs, cge->GetBacktrace(), items);
hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
}
@@ -4320,7 +5121,7 @@ cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
// export symbols.
if (this->GetType() == cmStateEnums::EXECUTABLE &&
!this->IsExecutableWithExports()) {
- return CM_NULLPTR;
+ return nullptr;
}
// Lookup any existing link interface for this configuration.
@@ -4344,7 +5145,7 @@ cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
}
}
- return iface.Exists ? &iface : CM_NULLPTR;
+ return iface.Exists ? &iface : nullptr;
}
void cmGeneratorTarget::ComputeLinkInterface(
@@ -4357,22 +5158,18 @@ void cmGeneratorTarget::ComputeLinkInterface(
this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
// Shared libraries may have runtime implementation dependencies
// on other shared libraries that are not in the interface.
- CM_UNORDERED_SET<std::string> emitted;
- for (std::vector<cmLinkItem>::const_iterator li =
- iface.Libraries.begin();
- li != iface.Libraries.end(); ++li) {
- emitted.insert(*li);
+ std::set<cmLinkItem> emitted;
+ for (cmLinkItem const& lib : iface.Libraries) {
+ emitted.insert(lib);
}
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
cmLinkImplementation const* impl = this->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) {
+ for (cmLinkImplItem const& lib : impl->Libraries) {
+ if (emitted.insert(lib).second) {
+ if (lib.Target) {
// This is a runtime dependency on another shared library.
- if (li->Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
- iface.SharedDeps.push_back(*li);
+ if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
+ iface.SharedDeps.push_back(lib);
}
} else {
// TODO: Recognize shared library file names. Perhaps this
@@ -4436,7 +5233,7 @@ const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
// export symbols.
if (this->GetType() == cmStateEnums::EXECUTABLE &&
!this->IsExecutableWithExports()) {
- return CM_NULLPTR;
+ return nullptr;
}
// Lookup any existing link interface for this configuration.
@@ -4459,7 +5256,7 @@ const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
usage_requirements_only);
}
- return iface.Exists ? &iface : CM_NULLPTR;
+ return iface.Exists ? &iface : nullptr;
}
std::string cmGeneratorTarget::GetDirectory(
@@ -4494,7 +5291,7 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
{
// There is no output information for imported targets.
if (this->IsImported()) {
- return CM_NULLPTR;
+ return nullptr;
}
// Only libraries and executables have well-defined output files.
@@ -4503,8 +5300,8 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
msg += this->GetName();
msg += " which has type ";
msg += cmState::GetTargetTypeName(this->GetType());
- this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
- return CM_NULLPTR;
+ this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
+ return nullptr;
}
// Lookup/compute/cache the output information for this configuration.
@@ -4534,10 +5331,10 @@ cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
// An empty map entry indicates we have been called recursively
// from the above block.
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
this->GetBacktrace());
- return CM_NULLPTR;
+ return nullptr;
}
return &i->second;
}
@@ -4552,7 +5349,7 @@ bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
// Look for a target property defining the target output directory
// based on the target type.
std::string targetTypeName = this->GetOutputTargetType(artifact);
- const char* propertyName = CM_NULLPTR;
+ const char* propertyName = nullptr;
std::string propertyNameStr = targetTypeName;
if (!propertyNameStr.empty()) {
propertyNameStr += "_OUTPUT_DIRECTORY";
@@ -4561,7 +5358,7 @@ bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
// Check for a per-configuration output directory target property.
std::string configUpper = cmSystemTools::UpperCase(conf);
- const char* configProp = CM_NULLPTR;
+ const char* configProp = nullptr;
std::string configPropStr = targetTypeName;
if (!configPropStr.empty()) {
configPropStr += "_OUTPUT_DIRECTORY_";
@@ -4573,21 +5370,22 @@ bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
if (const char* config_outdir = this->GetProperty(configProp)) {
// Use the user-specified per-configuration output directory.
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(config_outdir);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(config_outdir);
out = cge->Evaluate(this->LocalGenerator, config);
// Skip per-configuration subdirectory.
- conf = "";
+ conf.clear();
} else if (const char* outdir = this->GetProperty(propertyName)) {
// Use the user-specified output directory.
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
out = cge->Evaluate(this->LocalGenerator, config);
// Skip per-configuration subdirectory if the value contained a
// generator expression.
if (out != outdir) {
- conf = "";
+ conf.clear();
}
} else if (this->GetType() == cmStateEnums::EXECUTABLE) {
// Lookup the output path for executables.
@@ -4629,7 +5427,7 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
{
// Look for a target property defining the target output directory
// based on the target type.
- const char* propertyName = CM_NULLPTR;
+ const char* propertyName = nullptr;
std::string propertyNameStr = kind;
if (!propertyNameStr.empty()) {
propertyNameStr += "_OUTPUT_DIRECTORY";
@@ -4639,7 +5437,7 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
// Check for a per-configuration output directory target property.
std::string configUpper = cmSystemTools::UpperCase(conf);
- const char* configProp = CM_NULLPTR;
+ const char* configProp = nullptr;
std::string configPropStr = kind;
if (!configPropStr.empty()) {
configPropStr += "_OUTPUT_DIRECTORY_";
@@ -4650,13 +5448,24 @@ bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
// Select an output directory.
if (const char* config_outdir = this->GetProperty(configProp)) {
// Use the user-specified per-configuration output directory.
- out = config_outdir;
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(config_outdir);
+ out = cge->Evaluate(this->LocalGenerator, config);
// Skip per-configuration subdirectory.
- conf = "";
+ conf.clear();
} else if (const char* outdir = this->GetProperty(propertyName)) {
// Use the user-specified output directory.
- out = outdir;
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
+ out = cge->Evaluate(this->LocalGenerator, config);
+
+ // Skip per-configuration subdirectory if the value contained a
+ // generator expression.
+ if (out != outdir) {
+ conf.clear();
+ }
}
if (out.empty()) {
return false;
@@ -4697,7 +5506,7 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
// An explicit list of interface libraries may be set for shared
// libraries and executables that export symbols.
- const char* explicitLibraries = CM_NULLPTR;
+ const char* explicitLibraries = nullptr;
std::string linkIfaceProp;
if (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
this->GetPolicyStatusCMP0022() != cmPolicies::WARN) {
@@ -4740,9 +5549,9 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
"INTERFACE_LINK_LIBRARIES:\n"
" " << newExplicitLibraries << "\n" <<
linkIfaceProp << ":\n"
- " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
+ " " << explicitLibraries << "\n";
/* clang-format on */
- this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
this->PolicyWarnedCMP0022 = true;
}
}
@@ -4811,7 +5620,8 @@ void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
"Link implementation:\n"
" " << oldLibraries << "\n";
/* clang-format on */
- this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
+ w.str());
this->PolicyWarnedCMP0022 = true;
}
}
@@ -4824,7 +5634,7 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
{
cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
if (!info) {
- return CM_NULLPTR;
+ return nullptr;
}
std::string CONFIG = cmSystemTools::UpperCase(config);
@@ -4849,7 +5659,7 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
iface.HadHeadSensitiveCondition);
std::vector<std::string> deps;
cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
- this->LookupLinkItems(deps, iface.SharedDeps);
+ this->LookupLinkItems(deps, cmListFileBacktrace(), iface.SharedDeps);
}
return &iface;
@@ -4860,7 +5670,7 @@ cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
{
// There is no imported information for non-imported targets.
if (!this->IsImported()) {
- return CM_NULLPTR;
+ return nullptr;
}
// Lookup/compute/cache the import information for this
@@ -4886,7 +5696,7 @@ cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
// If the location is empty then the target is not available for
// this configuration.
if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
- return CM_NULLPTR;
+ return nullptr;
}
// Return the import information.
@@ -4903,8 +5713,8 @@ void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
// Initialize members.
info.NoSOName = false;
- const char* loc = CM_NULLPTR;
- const char* imp = CM_NULLPTR;
+ const char* loc = nullptr;
+ const char* imp = nullptr;
std::string suffix;
if (!this->Target->GetMappedConfig(desired_config, &loc, &imp, suffix)) {
return;
@@ -5016,6 +5826,16 @@ void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
}
}
+ // Get information if target is managed assembly.
+ {
+ std::string linkProp = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
+ if (auto pc = this->GetProperty(linkProp + suffix)) {
+ info.Managed = this->CheckManagedType(pc);
+ } else if (auto p = this->GetProperty(linkProp)) {
+ info.Managed = this->CheckManagedType(p);
+ }
+ }
+
// Get the cyclic repetition count.
if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
@@ -5049,7 +5869,7 @@ const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
{
// There is no link implementation for imported targets.
if (this->IsImported()) {
- return CM_NULLPTR;
+ return nullptr;
}
std::string CONFIG = cmSystemTools::UpperCase(config);
@@ -5071,7 +5891,7 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles(
std::vector<std::string> configs;
this->Makefile->GetConfigurations(configs);
if (configs.empty()) {
- configs.push_back("");
+ configs.emplace_back();
}
std::vector<std::string>::const_iterator it = configs.begin();
@@ -5084,19 +5904,17 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles(
if (configFiles != files) {
std::string firstConfigFiles;
const char* sep = "";
- for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
- fi != files.end(); ++fi) {
+ for (cmSourceFile* f : files) {
firstConfigFiles += sep;
- firstConfigFiles += (*fi)->GetFullPath();
+ firstConfigFiles += f->GetFullPath();
sep = "\n ";
}
std::string thisConfigFiles;
sep = "";
- for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
- fi != configFiles.end(); ++fi) {
+ for (cmSourceFile* f : configFiles) {
thisConfigFiles += sep;
- thisConfigFiles += (*fi)->GetFullPath();
+ thisConfigFiles += f->GetFullPath();
sep = "\n ";
}
std::ostringstream e;
@@ -5111,7 +5929,7 @@ bool cmGeneratorTarget::GetConfigCommonSourceFiles(
"Config \"" << *it << "\":\n"
" " << thisConfigFiles << "\n";
/* clang-format on */
- this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
}
@@ -5127,17 +5945,12 @@ void cmGeneratorTarget::GetObjectLibrariesCMP0026(
// for TARGET_OBJECTS instead for backwards compatibility with OLD
// behavior of CMP0024 and CMP0026 only.
cmStringRange rng = this->Target->GetSourceEntries();
- for (std::vector<std::string>::const_iterator i = rng.begin();
- i != rng.end(); ++i) {
- std::string const& entry = *i;
-
+ for (std::string const& entry : rng) {
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);
+ for (std::string const& li : files) {
+ if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') {
+ std::string objLibName = li.substr(17, li.size() - 18);
if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
continue;
@@ -5174,7 +5987,8 @@ std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
<< "Target \"" << this->GetName() << "\" links to item \"" << item
<< "\" which has leading or trailing whitespace.";
- cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace());
+ cm->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
+ this->GetBacktrace());
}
case cmPolicies::OLD:
break;
@@ -5183,7 +5997,8 @@ std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
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());
+ cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
+ this->GetBacktrace());
} break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS: {
@@ -5191,7 +6006,8 @@ std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
<< "Target \"" << this->GetName() << "\" links to item \"" << item
<< "\" which has leading or trailing whitespace.";
- cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
+ cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
+ this->GetBacktrace());
} break;
}
}
@@ -5203,9 +6019,8 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
{
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();
+ for (cmSourceFile* src : sourceFiles) {
+ const std::string& lang = src->GetLanguage();
if (!lang.empty()) {
languages.insert(lang);
}
@@ -5217,28 +6032,46 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
std::vector<cmGeneratorTarget*> objectTargets;
this->GetObjectLibrariesCMP0026(objectTargets);
objectLibraries.reserve(objectTargets.size());
- for (std::vector<cmGeneratorTarget*>::const_iterator it =
- objectTargets.begin();
- it != objectTargets.end(); ++it) {
- objectLibraries.push_back(*it);
+ for (cmGeneratorTarget* gt : objectTargets) {
+ objectLibraries.push_back(gt);
}
} else {
this->GetExternalObjects(externalObjects, config);
- for (std::vector<cmSourceFile const*>::const_iterator i =
- externalObjects.begin();
- i != externalObjects.end(); ++i) {
- std::string objLib = (*i)->GetObjectLibrary();
+ for (cmSourceFile const* extObj : externalObjects) {
+ std::string objLib = extObj->GetObjectLibrary();
if (cmGeneratorTarget* tgt =
this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
- objectLibraries.push_back(tgt);
+ auto const objLibIt =
+ std::find_if(objectLibraries.cbegin(), objectLibraries.cend(),
+ [tgt](cmGeneratorTarget* t) { return t == tgt; });
+ if (objectLibraries.cend() == objLibIt) {
+ objectLibraries.push_back(tgt);
+ }
}
}
}
- for (std::vector<cmGeneratorTarget*>::const_iterator i =
- objectLibraries.begin();
- i != objectLibraries.end(); ++i) {
- (*i)->GetLanguages(languages, config);
+ for (cmGeneratorTarget* objLib : objectLibraries) {
+ objLib->GetLanguages(languages, config);
+ }
+}
+
+bool cmGeneratorTarget::IsCSharpOnly() const
+{
+ // Only certain target types may compile CSharp.
+ if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
+ this->GetType() != cmStateEnums::STATIC_LIBRARY &&
+ this->GetType() != cmStateEnums::EXECUTABLE) {
+ return false;
+ }
+ std::set<std::string> languages;
+ this->GetLanguages(languages, "");
+ // Consider an explicit linker language property, but *not* the
+ // computed linker language that may depend on linked targets.
+ const char* linkLang = this->GetProperty("LINKER_LANGUAGE");
+ if (linkLang && *linkLang) {
+ languages.insert(linkLang);
}
+ return languages.size() == 1 && languages.count("CSharp") > 0;
}
void cmGeneratorTarget::ComputeLinkImplementationLanguages(
@@ -5248,7 +6081,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLanguages(
std::set<std::string> languages;
// Get languages used in our source files.
this->GetLanguages(languages, config);
- // Copy the set of langauges to the link implementation.
+ // Copy the set of languages to the link implementation.
impl.Languages.insert(impl.Languages.begin(), languages.begin(),
languages.end());
}
@@ -5281,7 +6114,7 @@ cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
{
// There is no link implementation for imported targets.
if (this->IsImported()) {
- return CM_NULLPTR;
+ return nullptr;
}
// Populate the link implementation libraries for this configuration.
@@ -5321,30 +6154,29 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
end = entryRange.end();
le != end; ++le, ++btIt) {
std::vector<std::string> llibs;
- cmGeneratorExpressionDAGChecker dagChecker(
- this->GetName(), "LINK_LIBRARIES", CM_NULLPTR, CM_NULLPTR);
+ cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr,
+ nullptr);
cmGeneratorExpression ge(*btIt);
- CM_AUTO_PTR<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
- std::string const evaluated =
+ std::unique_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
+ std::string const& evaluated =
cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
cmSystemTools::ExpandListArgument(evaluated, llibs);
if (cge->GetHadHeadSensitiveCondition()) {
impl.HadHeadSensitiveCondition = true;
}
- for (std::vector<std::string>::const_iterator li = llibs.begin();
- li != llibs.end(); ++li) {
+ for (std::string const& lib : llibs) {
// Skip entries that resolve to the target itself or are empty.
- std::string name = this->CheckCMP0004(*li);
+ std::string name = this->CheckCMP0004(lib);
if (name == this->GetName() || name.empty()) {
if (name == this->GetName()) {
bool noMessage = false;
- cmake::MessageType messageType = cmake::FATAL_ERROR;
+ MessageType messageType = MessageType::FATAL_ERROR;
std::ostringstream e;
switch (this->GetPolicyStatusCMP0038()) {
case cmPolicies::WARN: {
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
- messageType = cmake::AUTHOR_WARNING;
+ messageType = MessageType::AUTHOR_WARNING;
} break;
case cmPolicies::OLD:
noMessage = true;
@@ -5359,7 +6191,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
e << "Target \"" << this->GetName() << "\" links to itself.";
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
messageType, e.str(), this->GetBacktrace());
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::FATAL_ERROR) {
return;
}
}
@@ -5368,15 +6200,14 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
}
// The entry is meant for this configuration.
- impl.Libraries.push_back(cmLinkImplItem(
- name, this->FindTargetToLink(name), *btIt, evaluated != *le));
+ impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt),
+ evaluated != *le);
}
std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
- for (std::set<std::string>::const_iterator it = seenProps.begin();
- it != seenProps.end(); ++it) {
- if (!this->GetProperty(*it)) {
- this->LinkImplicitNullProperties.insert(*it);
+ for (std::string const& sp : seenProps) {
+ if (!this->GetProperty(sp)) {
+ this->LinkImplicitNullProperties.insert(sp);
}
}
cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
@@ -5390,49 +6221,79 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
CMP0003_ComputeLinkType(config, debugConfigs);
cmTarget::LinkLibraryVectorType const& oldllibs =
this->Target->GetOriginalLinkLibraries();
- for (cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
- li != oldllibs.end(); ++li) {
- if (li->second != GENERAL_LibraryType && li->second != linkType) {
- std::string name = this->CheckCMP0004(li->first);
+ for (cmTarget::LibraryID const& oldllib : oldllibs) {
+ if (oldllib.second != GENERAL_LibraryType && oldllib.second != linkType) {
+ std::string name = this->CheckCMP0004(oldllib.first);
if (name == this->GetName() || name.empty()) {
continue;
}
// Support OLD behavior for CMP0003.
impl.WrongConfigLibraries.push_back(
- cmLinkItem(name, this->FindTargetToLink(name)));
+ this->ResolveLinkItem(name, cmListFileBacktrace()));
}
}
}
-cmGeneratorTarget* cmGeneratorTarget::FindTargetToLink(
+cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
std::string const& name) const
{
- cmGeneratorTarget* tgt =
- this->LocalGenerator->FindGeneratorTargetToUse(name);
+ cmLocalGenerator const* lg = this->LocalGenerator;
+ std::string const* lookupName = &name;
+
+ // When target_link_libraries() is called with a LHS target that is
+ // not created in the calling directory it adds a directory id suffix
+ // that we can use to look up the calling directory. It is that scope
+ // in which the item name is meaningful. This case is relatively rare
+ // so we allocate a separate string only when the directory id is present.
+ std::string::size_type pos = name.find(CMAKE_DIRECTORY_ID_SEP);
+ std::string plainName;
+ if (pos != std::string::npos) {
+ // We will look up the plain name without the directory id suffix.
+ plainName = name.substr(0, pos);
+
+ // We will look up in the scope of the directory id.
+ // If we do not recognize the id then leave the original
+ // syntax in place to produce an indicative error later.
+ cmDirectoryId const dirId =
+ name.substr(pos + sizeof(CMAKE_DIRECTORY_ID_SEP) - 1);
+ if (cmLocalGenerator const* otherLG =
+ this->GlobalGenerator->FindLocalGenerator(dirId)) {
+ lg = otherLG;
+ lookupName = &plainName;
+ }
+ }
+
+ TargetOrString resolved;
+
+ if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(*lookupName)) {
+ resolved.Target = tgt;
+ } else if (lookupName == &plainName) {
+ resolved.String = std::move(plainName);
+ } else {
+ resolved.String = name;
+ }
+
+ return resolved;
+}
+
+cmLinkItem cmGeneratorTarget::ResolveLinkItem(
+ std::string const& name, cmListFileBacktrace const& bt) const
+{
+ TargetOrString resolved = this->ResolveTargetReference(name);
+
+ if (!resolved.Target) {
+ return cmLinkItem(resolved.String, bt);
+ }
// 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() == cmStateEnums::EXECUTABLE &&
- !tgt->IsExecutableWithExports()) {
- tgt = CM_NULLPTR;
+ if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE &&
+ !resolved.Target->IsExecutableWithExports()) {
+ return cmLinkItem(resolved.Target->GetName(), bt);
}
- if (tgt && tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- std::ostringstream e;
- e << "Target \"" << this->GetName() << "\" links to "
- "OBJECT library \""
- << tgt->GetName()
- << "\" but this is not "
- "allowed. "
- "One may link only to STATIC or SHARED libraries, or to executables "
- "with the ENABLE_EXPORTS property set.";
- cmake* cm = this->LocalGenerator->GetCMakeInstance();
- cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
- tgt = CM_NULLPTR;
- }
-
- return tgt;
+ return cmLinkItem(resolved.Target, bt);
}
std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
@@ -5444,16 +6305,17 @@ std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
return "";
}
-bool cmGeneratorTarget::HasImplibGNUtoMS() const
+bool cmGeneratorTarget::HasImplibGNUtoMS(std::string const& config) const
{
- return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
+ return this->HasImportLibrary(config) && this->GetPropertyAsBool("GNUtoMS");
}
-bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& gnuName,
+bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& config,
+ std::string const& gnuName,
std::string& out,
const char* newExt) const
{
- if (this->HasImplibGNUtoMS() && gnuName.size() > 6 &&
+ if (this->HasImplibGNUtoMS(config) && gnuName.size() > 6 &&
gnuName.substr(gnuName.size() - 6) == ".dll.a") {
out = gnuName.substr(0, gnuName.size() - 6);
out += newExt ? newExt : ".lib";
@@ -5468,17 +6330,20 @@ bool cmGeneratorTarget::IsExecutableWithExports() const
this->GetPropertyAsBool("ENABLE_EXPORTS"));
}
-bool cmGeneratorTarget::HasImportLibrary() const
+bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
{
return (this->IsDLLPlatform() &&
(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
- this->IsExecutableWithExports()));
+ this->IsExecutableWithExports()) &&
+ // Assemblies which have only managed code do not have
+ // import libraries.
+ this->GetManagedType(config) != ManagedType::Managed);
}
std::string cmGeneratorTarget::GetSupportDirectory() const
{
std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
- dir += cmake::GetCMakeFilesDirectory();
+ dir += "/CMakeFiles";
dir += "/";
dir += this->GetName();
#if defined(__VMS)
@@ -5495,6 +6360,7 @@ bool cmGeneratorTarget::IsLinkable() const
this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::MODULE_LIBRARY ||
this->GetType() == cmStateEnums::UNKNOWN_LIBRARY ||
+ this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
this->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
this->IsExecutableWithExports());
}
@@ -5524,3 +6390,52 @@ bool cmGeneratorTarget::IsCFBundleOnApple() const
return (this->GetType() == cmStateEnums::MODULE_LIBRARY &&
this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE"));
}
+
+cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(
+ std::string const& propval) const
+{
+ // The type of the managed assembly (mixed unmanaged C++ and C++/CLI,
+ // or only C++/CLI) does only depend on whether the property is an empty
+ // string or contains any value at all. In Visual Studio generators
+ // this propval is prepended with /clr[:] which results in:
+ //
+ // 1. propval does not exist: no /clr flag, unmanaged target, has import
+ // lib
+ // 2. empty propval: add /clr as flag, mixed unmanaged/managed
+ // target, has import lib
+ // 3. any value (safe,pure): add /clr:[propval] as flag, target with
+ // managed code only, no import lib
+ return propval.empty() ? ManagedType::Mixed : ManagedType::Managed;
+}
+
+cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
+ const std::string& config) const
+{
+ // Only libraries and executables can be managed targets.
+ if (this->GetType() > cmStateEnums::SHARED_LIBRARY) {
+ return ManagedType::Undefined;
+ }
+
+ if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
+ return ManagedType::Native;
+ }
+
+ // Check imported target.
+ if (this->IsImported()) {
+ if (cmGeneratorTarget::ImportInfo const* info =
+ this->GetImportInfo(config)) {
+ return info->Managed;
+ }
+ return ManagedType::Undefined;
+ }
+
+ // Check for explicitly set clr target property.
+ if (auto* clr = this->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
+ return this->CheckManagedType(clr);
+ }
+
+ // C# targets are always managed. This language specific check
+ // is added to avoid that the COMMON_LANGUAGE_RUNTIME target property
+ // has to be set manually for C# targets.
+ return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native;
+}
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 52147e319..0e0ee6a6f 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -3,7 +3,7 @@
#ifndef cmGeneratorTarget_h
#define cmGeneratorTarget_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmLinkItem.h"
#include "cmListFileCache.h"
@@ -27,12 +27,13 @@ class cmTarget;
class cmGeneratorTarget
{
- CM_DISABLE_COPY(cmGeneratorTarget)
-
public:
cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg);
~cmGeneratorTarget();
+ cmGeneratorTarget(cmGeneratorTarget const&) = delete;
+ cmGeneratorTarget& operator=(cmGeneratorTarget const&) = delete;
+
cmLocalGenerator* GetLocalGenerator() const;
cmGlobalGenerator* GetGlobalGenerator() const;
@@ -68,12 +69,15 @@ public:
std::string GetExportName() const;
std::vector<std::string> GetPropertyKeys() const;
+ //! Might return a nullptr if the property is not set or invalid
const char* GetProperty(const std::string& prop) const;
+ //! Always returns a valid pointer
+ const char* GetSafeProperty(const std::string& prop) const;
bool GetPropertyAsBool(const std::string& prop) const;
void GetSourceFiles(std::vector<cmSourceFile*>& files,
const std::string& config) const;
- void GetSourceFilesWithoutObjectLibraries(std::vector<cmSourceFile*>& files,
- const std::string& config) const;
+ std::vector<BT<cmSourceFile*>> GetSourceFiles(
+ std::string const& config) const;
/** Source file kinds (classifications).
Generators use this to decide how to treat a source file. */
@@ -96,7 +100,7 @@ public:
/** A source file paired with a kind (classification). */
struct SourceAndKind
{
- cmSourceFile* Source;
+ BT<cmSourceFile*> Source;
SourceKind Kind;
};
@@ -107,11 +111,7 @@ public:
std::set<std::string> ExpectedResxHeaders;
std::set<std::string> ExpectedXamlHeaders;
std::set<std::string> ExpectedXamlSources;
- bool Initialized;
- KindedSources()
- : Initialized(false)
- {
- }
+ bool Initialized = false;
};
/** Get all sources needed for a configuration with kinds assigned. */
@@ -170,6 +170,8 @@ public:
const char* GetFeature(const std::string& feature,
const std::string& config) const;
+ const char* GetLinkPIEProperty(const std::string& config) const;
+
bool IsIPOEnabled(std::string const& lang, std::string const& config) const;
bool IsLinkInterfaceDependentBoolProperty(const std::string& p,
@@ -260,20 +262,17 @@ public:
BundleDirectoryLevel level) const;
/** Return the install name directory for the target in the
- * build tree. For example: "\@rpath/", "\@loader_path/",
- * or "/full/path/to/library". */
+ * 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/". */
+ * install tree. For example: "\@rpath/" or "\@loader_path/". */
std::string GetInstallNameDirForInstallTree() const;
cmListFileBacktrace GetBacktrace() const;
- const std::vector<std::string>& GetLinkDirectories() const;
-
- std::set<std::string> const& GetUtilities() const;
- cmListFileBacktrace const* GetUtilityBacktrace(const std::string& u) const;
+ std::set<BT<std::string>> const& GetUtilities() const;
bool LinkLanguagePropagatesToDependents() const
{
@@ -282,7 +281,7 @@ public:
/** Get the macro to define when building sources in this target.
If no macro should be defined null is returned. */
- const char* GetExportMacro() const;
+ const std::string* GetExportMacro() const;
/** Get the soname of the target. Allowed only for a shared library. */
std::string GetSOName(const std::string& config) const;
@@ -354,7 +353,15 @@ public:
cmOptionalLinkImplementation& impl,
const cmGeneratorTarget* head) const;
- cmGeneratorTarget* FindTargetToLink(std::string const& name) const;
+ struct TargetOrString
+ {
+ std::string String;
+ cmGeneratorTarget* Target = nullptr;
+ };
+ TargetOrString ResolveTargetReference(std::string const& name) const;
+
+ cmLinkItem ResolveLinkItem(std::string const& name,
+ cmListFileBacktrace const& bt) const;
// Compute the set of languages compiled by the target. This is
// computed every time it is called because the languages can change
@@ -364,6 +371,8 @@ public:
void GetLanguages(std::set<std::string>& languages,
std::string const& config) const;
+ bool IsCSharpOnly() const;
+
void GetObjectLibrariesCMP0026(
std::vector<cmGeneratorTarget*>& objlibs) const;
@@ -398,22 +407,53 @@ public:
std::string const& config) const;
/** Get the include directories for this target. */
- std::vector<std::string> GetIncludeDirectories(
+ std::vector<BT<std::string>> GetIncludeDirectories(
const std::string& config, const std::string& lang) const;
void GetCompileOptions(std::vector<std::string>& result,
const std::string& config,
const std::string& language) const;
+ std::vector<BT<std::string>> GetCompileOptions(
+ std::string const& config, std::string const& language) const;
void GetCompileFeatures(std::vector<std::string>& features,
const std::string& config) const;
+ std::vector<BT<std::string>> GetCompileFeatures(
+ std::string const& config) const;
void GetCompileDefinitions(std::vector<std::string>& result,
const std::string& config,
const std::string& language) const;
+ std::vector<BT<std::string>> GetCompileDefinitions(
+ std::string const& config, std::string const& language) const;
+
+ void GetLinkOptions(std::vector<std::string>& result,
+ const std::string& config,
+ const std::string& language) const;
+ std::vector<BT<std::string>> GetLinkOptions(
+ std::string const& config, std::string const& language) const;
+
+ void GetStaticLibraryLinkOptions(std::vector<std::string>& result,
+ const std::string& config,
+ const std::string& language) const;
+ std::vector<BT<std::string>> GetStaticLibraryLinkOptions(
+ std::string const& config, std::string const& language) const;
+
+ void GetLinkDirectories(std::vector<std::string>& result,
+ const std::string& config,
+ const std::string& language) const;
+ std::vector<BT<std::string>> GetLinkDirectories(
+ std::string const& config, std::string const& language) const;
+
+ void GetLinkDepends(std::vector<std::string>& result,
+ const std::string& config,
+ const std::string& language) const;
+ std::vector<BT<std::string>> GetLinkDepends(
+ std::string const& config, std::string const& language) const;
bool IsSystemIncludeDirectory(const std::string& dir,
- const std::string& config) const;
+ const std::string& config,
+ const std::string& language) const;
/** Add the target output files to the global generator manifest. */
void ComputeTargetManifest(const std::string& config) const;
@@ -463,6 +503,9 @@ public:
OutputInfo const* GetOutputInfo(const std::string& config) const;
+ // Get the target PDB base name.
+ std::string GetPDBOutputName(const std::string& config) const;
+
/** Get the name of the pdb file for the target. */
std::string GetPDBName(const std::string& config = "") const;
@@ -491,7 +534,24 @@ public:
std::string GetOutputName(const std::string& config,
cmStateEnums::ArtifactType artifact) const;
- void AddSource(const std::string& src);
+ /** Get target file prefix */
+ std::string GetFilePrefix(const std::string& config,
+ cmStateEnums::ArtifactType artifact =
+ cmStateEnums::RuntimeBinaryArtifact) const;
+ /** Get target file prefix */
+ std::string GetFileSuffix(const std::string& config,
+ cmStateEnums::ArtifactType artifact =
+ cmStateEnums::RuntimeBinaryArtifact) const;
+
+ /** Get target file postfix */
+ std::string GetFilePostfix(const std::string& config) const;
+
+ /** Clears cached meta data for local and external source files.
+ * The meta data will be recomputed on demand.
+ */
+ void ClearSourcesCache();
+
+ void AddSource(const std::string& src, bool before = false);
void AddTracedSources(std::vector<std::string> const& srcs);
/**
@@ -517,30 +577,31 @@ public:
};
struct SourceFileFlags
{
- SourceFileFlags()
- : Type(SourceFileTypeNormal)
- , MacFolder(CM_NULLPTR)
- {
- }
- SourceFileType Type;
- const char* MacFolder; // location inside Mac content folders
+ SourceFileType Type = SourceFileTypeNormal;
+ const char* MacFolder = nullptr; // location inside Mac content folders
};
void GetAutoUicOptions(std::vector<std::string>& result,
const std::string& config) const;
+ struct Names
+ {
+ std::string Base;
+ std::string Output;
+ std::string Real;
+ std::string ImportLibrary;
+ std::string PDB;
+ std::string SharedObject;
+ };
+
/** 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;
+ Names GetExecutableNames(const std::string& config) 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;
+ Names GetLibraryNames(const std::string& config) const;
/**
* Compute whether this target must be relinked before installing.
@@ -556,21 +617,21 @@ public:
pdb output directory is given. */
std::string GetPDBDirectory(const std::string& config) const;
- ///! Return the preferred linker language for this target
+ //! Return the preferred linker language for this target
std::string GetLinkerLanguage(const std::string& config) const;
/** Does this target have a GNU implib to convert to MS format? */
- bool HasImplibGNUtoMS() const;
+ bool HasImplibGNUtoMS(std::string const& config) 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 = CM_NULLPTR) const;
+ bool GetImplibGNUtoMS(std::string const& config, std::string const& gnuName,
+ std::string& out, const char* newExt = nullptr) const;
bool IsExecutableWithExports() const;
/** Return whether or not the target has a DLL import library. */
- bool HasImportLibrary() const;
+ bool HasImportLibrary(std::string const& config) const;
/** Get a build-tree directory in which to place target support files. */
std::string GetSupportDirectory() const;
@@ -591,6 +652,19 @@ public:
/** Return whether this target is a CFBundle (plugin) on Apple. */
bool IsCFBundleOnApple() const;
+ /** Assembly types. The order of the values of this enum is relevant
+ because of smaller/larger comparison operations! */
+ enum ManagedType
+ {
+ Undefined = 0, // target is no lib or executable
+ Native, // target compiles to unmanaged binary.
+ Mixed, // target compiles to mixed (managed and unmanaged) binary.
+ Managed // target compiles to managed binary.
+ };
+
+ /** Return the type of assembly this target compiles to. */
+ ManagedType GetManagedType(const std::string& config) const;
+
struct SourceFileFlags GetTargetSourceFileFlags(
const cmSourceFile* sf) const;
@@ -622,7 +696,7 @@ public:
no soname at all. */
bool IsImportedSharedLibWithoutSOName(const std::string& config) const;
- const char* ImportedGetLocation(const std::string& config) const;
+ std::string ImportedGetLocation(const std::string& config) const;
/** Get the target major and minor version numbers interpreted from
the VERSION property. Version 0 is returned if the property is
@@ -640,7 +714,7 @@ public:
const char* GetSourcesProperty() const;
private:
- void AddSourceCommon(const std::string& src);
+ void AddSourceCommon(const std::string& src, bool before = false);
std::string CreateFortranModuleDirectory(
std::string const& working_dir) const;
@@ -656,7 +730,7 @@ private:
SourceEntriesType SourceDepends;
mutable std::map<cmSourceFile const*, std::string> Objects;
std::set<cmSourceFile const*> ExplicitObjectName;
- mutable std::map<std::string, std::vector<std::string> > SystemIncludesCache;
+ mutable std::map<std::string, std::vector<std::string>> SystemIncludesCache;
mutable std::string ExportMacro;
@@ -666,6 +740,11 @@ private:
mutable std::map<std::string, bool> DebugCompatiblePropertiesDone;
+ const char* GetFilePrefixInternal(cmStateEnums::ArtifactType artifact,
+ const std::string& language = "") const;
+ const char* GetFileSuffixInternal(cmStateEnums::ArtifactType artifact,
+ const std::string& language = "") const;
+
std::string GetFullNameInternal(const std::string& config,
cmStateEnums::ArtifactType artifact) const;
void GetFullNameInternal(const std::string& config,
@@ -696,11 +775,7 @@ private:
struct CompatibleInterfaces : public CompatibleInterfacesBase
{
- CompatibleInterfaces()
- : Done(false)
- {
- }
- bool Done;
+ bool Done = false;
};
mutable std::map<std::string, CompatibleInterfaces> CompatibleInterfacesMap;
@@ -713,11 +788,7 @@ private:
struct LinkImplClosure : public std::vector<cmGeneratorTarget const*>
{
- LinkImplClosure()
- : Done(false)
- {
- }
- bool Done;
+ bool Done = false;
};
mutable std::map<std::string, LinkImplClosure> LinkImplClosureMap;
@@ -730,16 +801,15 @@ private:
cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap(
std::string const& config) const;
+ std::string GetLinkInterfaceDependentStringAsBoolProperty(
+ const std::string& p, const std::string& config) const;
+
// Cache import information from properties for each configuration.
struct ImportInfo
{
- ImportInfo()
- : NoSOName(false)
- , Multiplicity(0)
- {
- }
- bool NoSOName;
- unsigned int Multiplicity;
+ bool NoSOName = false;
+ ManagedType Managed = Native;
+ unsigned int Multiplicity = 0;
std::string Location;
std::string SOName;
std::string ImportLibrary;
@@ -776,6 +846,8 @@ private:
std::vector<TargetPropertyEntry*> CompileOptionsEntries;
std::vector<TargetPropertyEntry*> CompileFeaturesEntries;
std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
+ std::vector<TargetPropertyEntry*> LinkOptionsEntries;
+ std::vector<TargetPropertyEntry*> LinkDirectoriesEntries;
std::vector<TargetPropertyEntry*> SourceEntries;
mutable std::set<std::string> LinkImplicitNullProperties;
@@ -786,10 +858,15 @@ private:
std::vector<cmLinkItem>& items,
bool& hadHeadSensitiveCondition) const;
void LookupLinkItems(std::vector<std::string> const& names,
+ cmListFileBacktrace const& bt,
std::vector<cmLinkItem>& items) const;
- void GetSourceFiles(std::vector<std::string>& files,
- const std::string& config) const;
+ std::vector<BT<std::string>> GetSourceFilePaths(
+ std::string const& config) const;
+ std::vector<BT<cmSourceFile*>> GetSourceFilesWithoutObjectLibraries(
+ std::string const& config) const;
+ void GetSourceFilesWithoutObjectLibraries(std::vector<cmSourceFile*>& files,
+ const std::string& config) const;
struct HeadToLinkImplementationMap
: public std::map<cmGeneratorTarget const*, cmOptionalLinkImplementation>
@@ -824,6 +901,8 @@ private:
mutable bool DebugCompileOptionsDone;
mutable bool DebugCompileFeaturesDone;
mutable bool DebugCompileDefinitionsDone;
+ mutable bool DebugLinkOptionsDone;
+ mutable bool DebugLinkDirectoriesDone;
mutable bool DebugSourcesDone;
mutable bool LinkImplementationLanguageIsContextDependent;
mutable bool UtilityItemsDone;
@@ -832,6 +911,8 @@ private:
bool ComputePDBOutputDir(const std::string& kind, const std::string& config,
std::string& out) const;
+ ManagedType CheckManagedType(std::string const& propval) const;
+
public:
const std::vector<const cmGeneratorTarget*>& GetLinkImplementationClosure(
const std::string& config) const;
diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx
index 5ba3326cb..fc82feef5 100644
--- a/Source/cmGetCMakePropertyCommand.cxx
+++ b/Source/cmGetCMakePropertyCommand.cxx
@@ -37,7 +37,7 @@ bool cmGetCMakePropertyCommand::InitialPass(
this->Makefile->GetGlobalGenerator()->GetInstallComponents();
output = cmJoin(*components, ";");
} else {
- const char* prop = CM_NULLPTR;
+ const char* prop = nullptr;
if (!args[1].empty()) {
prop = this->Makefile->GetState()->GetGlobalProperty(args[1]);
}
diff --git a/Source/cmGetCMakePropertyCommand.h b/Source/cmGetCMakePropertyCommand.h
index 9dfc40fda..1f29c78dc 100644
--- a/Source/cmGetCMakePropertyCommand.h
+++ b/Source/cmGetCMakePropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmGetCMakePropertyCommand_h
#define cmGetCMakePropertyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,14 +15,14 @@ class cmExecutionStatus;
class cmGetCMakePropertyCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmGetCMakePropertyCommand; }
+ cmCommand* Clone() override { return new cmGetCMakePropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmGetDirectoryPropertyCommand.cxx b/Source/cmGetDirectoryPropertyCommand.cxx
index 1005b1543..a92eb7186 100644
--- a/Source/cmGetDirectoryPropertyCommand.cxx
+++ b/Source/cmGetDirectoryPropertyCommand.cxx
@@ -4,9 +4,9 @@
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmSystemTools.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -34,7 +34,7 @@ bool cmGetDirectoryPropertyCommand::InitialPass(
}
std::string sd = *i;
// make sure the start dir is a full path
- if (!cmSystemTools::FileIsFullPath(sd.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(sd)) {
sd = this->Makefile->GetCurrentSourceDirectory();
sd += "/";
sd += *i;
@@ -65,18 +65,18 @@ bool cmGetDirectoryPropertyCommand::InitialPass(
"providing the name of the variable to get.");
return false;
}
- std::string output = dir->GetSafeDefinition(*i);
+ std::string const& output = dir->GetSafeDefinition(*i);
this->Makefile->AddDefinition(variable, output.c_str());
return true;
}
- const char* prop = CM_NULLPTR;
+ const char* prop = nullptr;
if (!i->empty()) {
if (*i == "DEFINITIONS") {
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0059)) {
case cmPolicies::WARN:
this->Makefile->IssueMessage(
- cmake::AUTHOR_WARNING,
+ MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(cmPolicies::CMP0059));
CM_FALLTHROUGH;
case cmPolicies::OLD:
diff --git a/Source/cmGetDirectoryPropertyCommand.h b/Source/cmGetDirectoryPropertyCommand.h
index 7d9795065..02ea0566f 100644
--- a/Source/cmGetDirectoryPropertyCommand.h
+++ b/Source/cmGetDirectoryPropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmGetDirectoryPropertyCommand_h
#define cmGetDirectoryPropertyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,14 +15,14 @@ class cmExecutionStatus;
class cmGetDirectoryPropertyCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmGetDirectoryPropertyCommand; }
+ cmCommand* Clone() override { return new cmGetDirectoryPropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
void StoreResult(const std::string& variable, const char* prop);
diff --git a/Source/cmGetFilenameComponentCommand.cxx b/Source/cmGetFilenameComponentCommand.cxx
index c23684c22..163b4c8ab 100644
--- a/Source/cmGetFilenameComponentCommand.cxx
+++ b/Source/cmGetFilenameComponentCommand.cxx
@@ -19,8 +19,8 @@ bool cmGetFilenameComponentCommand::InitialPass(
// Check and see if the value has been stored in the cache
// already, if so use that value
- if (args.size() >= 4 && args[args.size() - 1] == "CACHE") {
- const char* cacheValue = this->Makefile->GetDefinition(args[0]);
+ if (args.size() >= 4 && args.back() == "CACHE") {
+ const char* cacheValue = this->Makefile->GetDefinition(args.front());
if (cacheValue && !cmSystemTools::IsNOTFOUND(cacheValue)) {
return true;
}
@@ -60,11 +60,38 @@ bool cmGetFilenameComponentCommand::InitialPass(
}
}
}
- cmSystemTools::SplitProgramFromArgs(filename, result, programArgs);
+
+ // First assume the path to the program was specified with no
+ // arguments and with no quoting or escaping for spaces.
+ // Only bother doing this if there is non-whitespace.
+ if (!cmSystemTools::TrimWhitespace(filename).empty()) {
+ result = cmSystemTools::FindProgram(filename);
+ }
+
+ // If that failed then assume a command-line string was given
+ // and split the program part from the rest of the arguments.
+ if (result.empty()) {
+ std::string program;
+ if (cmSystemTools::SplitProgramFromArgs(filename, program,
+ programArgs)) {
+ if (cmSystemTools::FileExists(program)) {
+ result = program;
+ } else {
+ result = cmSystemTools::FindProgram(program);
+ }
+ }
+ if (result.empty()) {
+ programArgs.clear();
+ }
+ }
} else if (args[2] == "EXT") {
result = cmSystemTools::GetFilenameExtension(filename);
} else if (args[2] == "NAME_WE") {
result = cmSystemTools::GetFilenameWithoutExtension(filename);
+ } else if (args[2] == "LAST_EXT") {
+ result = cmSystemTools::GetFilenameLastExtension(filename);
+ } else if (args[2] == "NAME_WLE") {
+ result = cmSystemTools::GetFilenameWithoutLastExtension(filename);
} else if (args[2] == "ABSOLUTE" || args[2] == "REALPATH") {
// If the path given is relative, evaluate it relative to the
// current source directory unless the user passes a different
@@ -90,20 +117,20 @@ bool cmGetFilenameComponentCommand::InitialPass(
return false;
}
- if (args.size() >= 4 && args[args.size() - 1] == "CACHE") {
+ if (args.size() >= 4 && args.back() == "CACHE") {
if (!programArgs.empty() && !storeArgs.empty()) {
this->Makefile->AddCacheDefinition(
storeArgs, programArgs.c_str(), "",
args[2] == "PATH" ? cmStateEnums::FILEPATH : cmStateEnums::STRING);
}
this->Makefile->AddCacheDefinition(
- args[0], result.c_str(), "",
+ args.front(), result.c_str(), "",
args[2] == "PATH" ? cmStateEnums::FILEPATH : cmStateEnums::STRING);
} else {
if (!programArgs.empty() && !storeArgs.empty()) {
this->Makefile->AddDefinition(storeArgs, programArgs.c_str());
}
- this->Makefile->AddDefinition(args[0], result.c_str());
+ this->Makefile->AddDefinition(args.front(), result.c_str());
}
return true;
diff --git a/Source/cmGetFilenameComponentCommand.h b/Source/cmGetFilenameComponentCommand.h
index c8a23c70e..8c266552c 100644
--- a/Source/cmGetFilenameComponentCommand.h
+++ b/Source/cmGetFilenameComponentCommand.h
@@ -3,7 +3,7 @@
#ifndef cmGetFilenameComponentCommand_h
#define cmGetFilenameComponentCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmGetFilenameComponentCommand; }
+ cmCommand* Clone() override { return new cmGetFilenameComponentCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx
index ddecdf621..039f43922 100644
--- a/Source/cmGetPropertyCommand.cxx
+++ b/Source/cmGetPropertyCommand.cxx
@@ -8,6 +8,7 @@
#include "cmInstalledFile.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmProperty.h"
#include "cmPropertyDefinition.h"
@@ -206,7 +207,7 @@ bool cmGetPropertyCommand::HandleDirectoryMode()
// Construct the directory name. Interpret relative paths with
// respect to the current directory.
std::string dir = this->Name;
- if (!cmSystemTools::FileIsFullPath(dir.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(dir)) {
dir = this->Makefile->GetCurrentSourceDirectory();
dir += "/";
dir += this->Name;
@@ -230,7 +231,7 @@ bool cmGetPropertyCommand::HandleDirectoryMode()
if (this->PropertyName == "DEFINITIONS") {
switch (mf->GetPolicyStatus(cmPolicies::CMP0059)) {
case cmPolicies::WARN:
- mf->IssueMessage(cmake::AUTHOR_WARNING,
+ mf->IssueMessage(MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(cmPolicies::CMP0059));
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -258,9 +259,9 @@ bool cmGetPropertyCommand::HandleTargetMode()
if (this->Makefile->IsAlias(this->Name)) {
return this->StoreResult(target->GetName().c_str());
}
- return this->StoreResult(CM_NULLPTR);
+ return this->StoreResult(nullptr);
}
- const char* prop_cstr = CM_NULLPTR;
+ const char* prop_cstr = nullptr;
cmListFileBacktrace bt = this->Makefile->GetBacktrace();
cmMessenger* messenger = this->Makefile->GetMessenger();
if (cmTargetPropertyComputer::PassesWhitelist(
@@ -333,7 +334,7 @@ bool cmGetPropertyCommand::HandleCacheMode()
return false;
}
- const char* value = CM_NULLPTR;
+ const char* value = nullptr;
if (this->Makefile->GetState()->GetCacheEntryValue(this->Name)) {
value = this->Makefile->GetState()->GetCacheEntryProperty(
this->Name, this->PropertyName);
@@ -357,7 +358,7 @@ bool cmGetPropertyCommand::HandleInstallMode()
std::string value;
bool isSet = file->GetProperty(this->PropertyName, value);
- return this->StoreResult(isSet ? value.c_str() : CM_NULLPTR);
+ return this->StoreResult(isSet ? value.c_str() : nullptr);
}
std::ostringstream e;
e << "given INSTALL name that could not be found or created: " << this->Name;
diff --git a/Source/cmGetPropertyCommand.h b/Source/cmGetPropertyCommand.h
index 649780168..c3f653e2e 100644
--- a/Source/cmGetPropertyCommand.h
+++ b/Source/cmGetPropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmGetPropertyCommand_h
#define cmGetPropertyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -17,14 +17,14 @@ class cmGetPropertyCommand : public cmCommand
public:
cmGetPropertyCommand();
- cmCommand* Clone() CM_OVERRIDE { return new cmGetPropertyCommand; }
+ cmCommand* Clone() override { return new cmGetPropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
enum OutType
diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx
index 1a5f08ef8..75879a553 100644
--- a/Source/cmGetSourceFilePropertyCommand.cxx
+++ b/Source/cmGetSourceFilePropertyCommand.cxx
@@ -28,7 +28,7 @@ bool cmGetSourceFilePropertyCommand::InitialPass(
this->Makefile->AddDefinition(var, sf->GetLanguage().c_str());
return true;
}
- const char* prop = CM_NULLPTR;
+ const char* prop = nullptr;
if (!args[2].empty()) {
prop = sf->GetPropertyForUser(args[2]);
}
diff --git a/Source/cmGetSourceFilePropertyCommand.h b/Source/cmGetSourceFilePropertyCommand.h
index e96bb29ed..43bc330a8 100644
--- a/Source/cmGetSourceFilePropertyCommand.h
+++ b/Source/cmGetSourceFilePropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmGetSourceFilePropertyCommand_h
#define cmGetSourceFilePropertyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,14 +15,14 @@ class cmExecutionStatus;
class cmGetSourceFilePropertyCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmGetSourceFilePropertyCommand; }
+ cmCommand* Clone() override { return new cmGetSourceFilePropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx
index 0910a5324..fc0e9c693 100644
--- a/Source/cmGetTargetPropertyCommand.cxx
+++ b/Source/cmGetTargetPropertyCommand.cxx
@@ -6,10 +6,10 @@
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmTarget.h"
#include "cmTargetPropertyComputer.h"
-#include "cmake.h"
class cmExecutionStatus;
class cmMessenger;
@@ -34,7 +34,7 @@ bool cmGetTargetPropertyCommand::InitialPass(
prop_exists = true;
}
} else if (!args[2].empty()) {
- const char* prop_cstr = CM_NULLPTR;
+ const char* prop_cstr = nullptr;
cmListFileBacktrace bt = this->Makefile->GetBacktrace();
cmMessenger* messenger = this->Makefile->GetMessenger();
if (cmTargetPropertyComputer::PassesWhitelist(tgt->GetType(), args[2],
@@ -52,7 +52,7 @@ bool cmGetTargetPropertyCommand::InitialPass(
} else {
bool issueMessage = false;
std::ostringstream e;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0045)) {
case cmPolicies::WARN:
issueMessage = true;
@@ -63,13 +63,13 @@ bool cmGetTargetPropertyCommand::InitialPass(
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
issueMessage = true;
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::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) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
diff --git a/Source/cmGetTargetPropertyCommand.h b/Source/cmGetTargetPropertyCommand.h
index 5de322563..63ee5fd9b 100644
--- a/Source/cmGetTargetPropertyCommand.h
+++ b/Source/cmGetTargetPropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmGetTargetPropertyCommand_h
#define cmGetTargetPropertyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,14 +15,14 @@ class cmExecutionStatus;
class cmGetTargetPropertyCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmGetTargetPropertyCommand; }
+ cmCommand* Clone() override { return new cmGetTargetPropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmGetTestPropertyCommand.cxx b/Source/cmGetTestPropertyCommand.cxx
index 6424515ec..0b0d6eb3d 100644
--- a/Source/cmGetTestPropertyCommand.cxx
+++ b/Source/cmGetTestPropertyCommand.cxx
@@ -20,7 +20,7 @@ bool cmGetTestPropertyCommand::InitialPass(
std::string const& var = args[2];
cmTest* test = this->Makefile->GetTest(testName);
if (test) {
- const char* prop = CM_NULLPTR;
+ const char* prop = nullptr;
if (!args[1].empty()) {
prop = test->GetProperty(args[1]);
}
diff --git a/Source/cmGetTestPropertyCommand.h b/Source/cmGetTestPropertyCommand.h
index b17e7a1cc..4a74f593f 100644
--- a/Source/cmGetTestPropertyCommand.h
+++ b/Source/cmGetTestPropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmGetTestPropertyCommand_h
#define cmGetTestPropertyCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,14 +15,14 @@ class cmExecutionStatus;
class cmGetTestPropertyCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmGetTestPropertyCommand; }
+ cmCommand* Clone() override { return new cmGetTestPropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmGhsMultiGpj.cxx b/Source/cmGhsMultiGpj.cxx
index f58cfc1e5..da27971de 100644
--- a/Source/cmGhsMultiGpj.cxx
+++ b/Source/cmGhsMultiGpj.cxx
@@ -2,33 +2,38 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGhsMultiGpj.h"
-#include "cmGeneratedFileStream.h"
+#include <ostream>
-void GhsMultiGpj::WriteGpjTag(Types const gpjType,
- cmGeneratedFileStream* const filestream)
+static const char* GHS_TAG[] = { "[INTEGRITY Application]",
+ "[Library]",
+ "[Project]",
+ "[Program]",
+ "[Reference]",
+ "[Subproject]",
+ "[Custom Target]" };
+
+const char* GhsMultiGpj::GetGpjTag(Types gpjType)
{
char const* tag;
switch (gpjType) {
case INTERGRITY_APPLICATION:
- tag = "INTEGRITY Application";
- break;
case LIBRARY:
- tag = "Library";
- break;
case PROJECT:
- tag = "Project";
- break;
case PROGRAM:
- tag = "Program";
- break;
case REFERENCE:
- tag = "Reference";
- break;
case SUBPROJECT:
- tag = "Subproject";
+ case CUSTOM_TARGET:
+ tag = GHS_TAG[gpjType];
break;
default:
tag = "";
}
- *filestream << "[" << tag << "]" << std::endl;
+ return tag;
+}
+
+void GhsMultiGpj::WriteGpjTag(Types gpjType, std::ostream& fout)
+{
+ char const* tag;
+ tag = GhsMultiGpj::GetGpjTag(gpjType);
+ fout << tag << std::endl;
}
diff --git a/Source/cmGhsMultiGpj.h b/Source/cmGhsMultiGpj.h
index 7bc7bfc46..e588150f4 100644
--- a/Source/cmGhsMultiGpj.h
+++ b/Source/cmGhsMultiGpj.h
@@ -3,9 +3,8 @@
#ifndef cmGhsMultiGpj_h
#define cmGhsMultiGpj_h
-#include "cmConfigure.h"
-
-class cmGeneratedFileStream;
+#include "cmConfigure.h" // IWYU pragma: keep
+#include <iosfwd>
class GhsMultiGpj
{
@@ -17,11 +16,13 @@ public:
PROJECT,
PROGRAM,
REFERENCE,
- SUBPROJECT
+ SUBPROJECT,
+ CUSTOM_TARGET
};
- static void WriteGpjTag(Types const gpjType,
- cmGeneratedFileStream* filestream);
+ static void WriteGpjTag(Types gpjType, std::ostream& fout);
+
+ static const char* GetGpjTag(Types gpjType);
};
#endif // ! cmGhsMultiGpjType_h
diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index 7032cd582..b80da7231 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -2,184 +2,147 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGhsMultiTargetGenerator.h"
+#include "cmCustomCommand.h"
+#include "cmCustomCommandGenerator.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGhsMultiGenerator.h"
#include "cmLinkLineComputer.h"
+#include "cmLocalGenerator.h"
#include "cmLocalGhsMultiGenerator.h"
#include "cmMakefile.h"
+#include "cmOutputConverter.h"
#include "cmSourceFile.h"
+#include "cmSourceFileLocation.h"
+#include "cmSourceGroup.h"
+#include "cmStateDirectory.h"
+#include "cmStateSnapshot.h"
+#include "cmStateTypes.h"
+#include "cmSystemTools.h"
#include "cmTarget.h"
-#include <assert.h>
-std::string const cmGhsMultiTargetGenerator::DDOption("-dynamic");
+#include <algorithm>
+#include <ostream>
+#include <set>
+#include <utility>
cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target)
: GeneratorTarget(target)
, LocalGenerator(
static_cast<cmLocalGhsMultiGenerator*>(target->GetLocalGenerator()))
, Makefile(target->Target->GetMakefile())
- , TargetGroup(DetermineIfTargetGroup(target))
- , DynamicDownload(false)
-{
- this->RelBuildFilePath = this->GetRelBuildFilePath(target);
-
- this->RelOutputFileName = this->RelBuildFilePath + target->GetName() + ".a";
-
- this->RelBuildFileName = this->RelBuildFilePath;
- this->RelBuildFileName += this->GetBuildFileName(target);
-
- std::string absPathToRoot = this->GetAbsPathToRoot(target);
- absPathToRoot = this->AddSlashIfNeededToPath(absPathToRoot);
- this->AbsBuildFilePath = absPathToRoot + this->RelBuildFilePath;
- this->AbsBuildFileName = absPathToRoot + this->RelBuildFileName;
- this->AbsOutputFileName = absPathToRoot + this->RelOutputFileName;
-}
-
-cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator()
-{
- cmDeleteAll(this->FolderBuildStreams);
-}
-
-std::string cmGhsMultiTargetGenerator::GetRelBuildFilePath(
- const cmGeneratorTarget* target)
-{
- std::string output = target->GetEffectiveFolderName();
- cmSystemTools::ConvertToUnixSlashes(output);
- if (!output.empty()) {
- output += "/";
+ , Name(target->GetName())
+#ifdef _WIN32
+ , CmdWindowsShell(true)
+#else
+ , CmdWindowsShell(false)
+#endif
+{
+ // Store the configuration name that is being used
+ if (const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) {
+ // Use the build type given by the user.
+ this->ConfigName = config;
+ } else {
+ // No configuration type given.
+ this->ConfigName.clear();
}
- output += target->GetName() + "/";
- return output;
}
-std::string cmGhsMultiTargetGenerator::GetAbsPathToRoot(
- const cmGeneratorTarget* target)
-{
- return target->GetLocalGenerator()->GetBinaryDirectory();
-}
-
-std::string cmGhsMultiTargetGenerator::GetAbsBuildFilePath(
- const cmGeneratorTarget* target)
-{
- std::string output;
- output = cmGhsMultiTargetGenerator::GetAbsPathToRoot(target);
- output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output);
- output += cmGhsMultiTargetGenerator::GetRelBuildFilePath(target);
- return output;
-}
-
-std::string cmGhsMultiTargetGenerator::GetRelBuildFileName(
- const cmGeneratorTarget* target)
-{
- std::string output;
- output = cmGhsMultiTargetGenerator::GetRelBuildFilePath(target);
- output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output);
- output += cmGhsMultiTargetGenerator::GetBuildFileName(target);
- return output;
-}
-
-std::string cmGhsMultiTargetGenerator::GetBuildFileName(
- const cmGeneratorTarget* target)
-{
- std::string output;
- output = target->GetName();
- output += cmGlobalGhsMultiGenerator::FILE_EXTENSION;
- return output;
-}
-
-std::string cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(
- std::string const& input)
-{
- std::string output(input);
- if (!cmHasLiteralSuffix(output, "/")) {
- output += "/";
- }
- return output;
-}
+cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator() = default;
void cmGhsMultiTargetGenerator::Generate()
{
- std::vector<cmSourceFile*> objectSources = this->GetSources();
- if (!objectSources.empty() && this->IncludeThisTarget()) {
- if (!cmSystemTools::FileExists(this->AbsBuildFilePath.c_str())) {
- cmSystemTools::MakeDirectory(this->AbsBuildFilePath.c_str());
+ // Determine type of target for this project
+ switch (this->GeneratorTarget->GetType()) {
+ case cmStateEnums::EXECUTABLE: {
+ // Get the name of the executable to generate.
+ this->TargetNameReal =
+ this->GeneratorTarget->GetExecutableNames(this->ConfigName).Real;
+ if (cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()) {
+ this->TagType = GhsMultiGpj::INTERGRITY_APPLICATION;
+ } else {
+ this->TagType = GhsMultiGpj::PROGRAM;
+ }
+ break;
}
- cmGlobalGhsMultiGenerator::Open(std::string(""), this->AbsBuildFileName,
- &this->FolderBuildStreams);
- cmGlobalGhsMultiGenerator::OpenBuildFileStream(
- this->GetFolderBuildStreams());
- std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
- if (0 == config.length()) {
- config = "RELEASE";
+ case cmStateEnums::STATIC_LIBRARY: {
+ this->TargetNameReal =
+ this->GeneratorTarget->GetLibraryNames(this->ConfigName).Real;
+ this->TagType = GhsMultiGpj::LIBRARY;
+ break;
}
- const std::string language(
- this->GeneratorTarget->GetLinkerLanguage(config));
- config = cmSystemTools::UpperCase(config);
- this->DynamicDownload = this->DetermineIfDynamicDownload(config, language);
- if (this->DynamicDownload) {
- *this->GetFolderBuildStreams() << "#component integrity_dynamic_download"
- << std::endl;
+ case cmStateEnums::SHARED_LIBRARY: {
+ std::string msg = "add_library(<name> SHARED ...) not supported: ";
+ msg += this->Name;
+ cmSystemTools::Message(msg);
+ return;
}
- GhsMultiGpj::WriteGpjTag(this->GetGpjTag(), this->GetFolderBuildStreams());
- cmGlobalGhsMultiGenerator::WriteDisclaimer(this->GetFolderBuildStreams());
-
- bool const notKernel = this->IsNotKernel(config, language);
- this->WriteTypeSpecifics(config, notKernel);
- this->SetCompilerFlags(config, language, notKernel);
- this->WriteCompilerFlags(config, language);
- this->WriteCompilerDefinitions(config, language);
- this->WriteIncludes(config, language);
- if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
- this->WriteTargetLinkLibraries(config, language);
+ case cmStateEnums::OBJECT_LIBRARY: {
+ this->TargetNameReal =
+ this->GeneratorTarget->GetLibraryNames(this->ConfigName).Real;
+ this->TagType = GhsMultiGpj::SUBPROJECT;
+ break;
}
- this->WriteCustomCommands();
-
- std::map<const cmSourceFile*, std::string> objectNames =
- cmGhsMultiTargetGenerator::GetObjectNames(
- &objectSources, this->LocalGenerator, this->GeneratorTarget);
-
- this->WriteSources(objectSources, objectNames);
+ case cmStateEnums::MODULE_LIBRARY: {
+ std::string msg = "add_library(<name> MODULE ...) not supported: ";
+ msg += this->Name;
+ cmSystemTools::Message(msg);
+ return;
+ }
+ case cmStateEnums::UTILITY: {
+ this->TargetNameReal = this->GeneratorTarget->GetName();
+ this->TagType = GhsMultiGpj::CUSTOM_TARGET;
+ break;
+ }
+ case cmStateEnums::GLOBAL_TARGET: {
+ this->TargetNameReal = this->GeneratorTarget->GetName();
+ if (this->TargetNameReal ==
+ this->GetGlobalGenerator()->GetInstallTargetName()) {
+ this->TagType = GhsMultiGpj::CUSTOM_TARGET;
+ } else {
+ return;
+ }
+ break;
+ }
+ default:
+ return;
}
-}
-bool cmGhsMultiTargetGenerator::IncludeThisTarget()
-{
- bool output = true;
- char const* excludeFromAll =
- this->GeneratorTarget->GetProperty("EXCLUDE_FROM_ALL");
- if (NULL != excludeFromAll && '1' == excludeFromAll[0] &&
- '\0' == excludeFromAll[1]) {
- output = false;
- }
- return output;
-}
+ // Tell the global generator the name of the project file
+ this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME",
+ this->Name.c_str());
+ this->GeneratorTarget->Target->SetProperty(
+ "GENERATOR_FILE_NAME_EXT", GhsMultiGpj::GetGpjTag(this->TagType));
-std::vector<cmSourceFile*> cmGhsMultiTargetGenerator::GetSources() const
-{
- std::vector<cmSourceFile*> output;
- std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
- this->GeneratorTarget->GetSourceFiles(output, config);
- return output;
+ this->GenerateTarget();
}
-GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag() const
+void cmGhsMultiTargetGenerator::GenerateTarget()
{
- return cmGhsMultiTargetGenerator::GetGpjTag(this->GeneratorTarget);
-}
+ // Open the target file in copy-if-different mode.
+ std::string fproj = this->LocalGenerator->GetCurrentBinaryDirectory();
+ fproj += "/";
+ fproj += this->Name;
+ fproj += cmGlobalGhsMultiGenerator::FILE_EXTENSION;
+ cmGeneratedFileStream fout(fproj);
+ fout.SetCopyIfDifferent(true);
-GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag(
- const cmGeneratorTarget* target)
-{
- GhsMultiGpj::Types output;
- if (cmGhsMultiTargetGenerator::DetermineIfTargetGroup(target)) {
- output = GhsMultiGpj::INTERGRITY_APPLICATION;
- } else if (target->GetType() == cmStateEnums::STATIC_LIBRARY) {
- output = GhsMultiGpj::LIBRARY;
- } else {
- output = GhsMultiGpj::PROGRAM;
+ this->GetGlobalGenerator()->WriteFileHeader(fout);
+ GhsMultiGpj::WriteGpjTag(this->TagType, fout);
+
+ if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
+ const std::string language(
+ this->GeneratorTarget->GetLinkerLanguage(this->ConfigName));
+ this->WriteTargetSpecifics(fout, this->ConfigName);
+ this->SetCompilerFlags(this->ConfigName, language);
+ this->WriteCompilerFlags(fout, this->ConfigName, language);
+ this->WriteCompilerDefinitions(fout, this->ConfigName, language);
+ this->WriteIncludes(fout, this->ConfigName, language);
+ this->WriteTargetLinkLine(fout, this->ConfigName);
+ this->WriteBuildEvents(fout);
}
- return output;
+ this->WriteSources(fout);
+ fout.Close();
}
cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator()
@@ -189,41 +152,28 @@ cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator()
this->LocalGenerator->GetGlobalGenerator());
}
-void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string& config,
- bool const notKernel)
+void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout,
+ const std::string& config)
{
- std::string outputDir(this->GetOutputDirectory(config));
- std::string outputFilename(this->GetOutputFilename(config));
-
- if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
- std::string const static_library_suffix =
- this->Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX");
- *this->GetFolderBuildStreams() << " -o \"" << outputDir
- << outputFilename << static_library_suffix
- << "\"" << std::endl;
- } else if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
- if (notKernel && !this->IsTargetGroup()) {
- *this->GetFolderBuildStreams() << " -relprog" << std::endl;
- }
- if (this->IsTargetGroup()) {
- *this->GetFolderBuildStreams()
- << " -o \"" << outputDir << outputFilename << ".elf\"" << std::endl;
- *this->GetFolderBuildStreams() << " :extraOutputFile=\"" << outputDir
- << outputFilename << ".elf.ael\""
- << std::endl;
- } else {
- std::string const executable_suffix =
- this->Makefile->GetSafeDefinition("CMAKE_EXECUTABLE_SUFFIX");
- *this->GetFolderBuildStreams() << " -o \"" << outputDir
- << outputFilename << executable_suffix
- << "\"" << std::endl;
- }
+ std::string outpath;
+ std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory();
+
+ if (this->TagType != GhsMultiGpj::SUBPROJECT) {
+ // set target binary file destination
+ outpath = this->GeneratorTarget->GetDirectory(config);
+ outpath =
+ this->LocalGenerator->MaybeConvertToRelativePath(rootpath, outpath);
+ fout << " :binDirRelative=\"" << outpath << "\"" << std::endl;
+ fout << " -o \"" << this->TargetNameReal << "\"" << std::endl;
}
+
+ // set target object file destination
+ outpath = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ fout << " :outputDirRelative=\"" << outpath << "\"" << std::endl;
}
void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config,
- const std::string& language,
- bool const notKernel)
+ const std::string& language)
{
std::map<std::string, std::string>::iterator i =
this->FlagsByLanguage.find(language);
@@ -231,14 +181,9 @@ void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config,
std::string flags;
const char* lang = language.c_str();
- if (notKernel) {
- this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
- lang, config);
- } else {
- this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
- lang + std::string("_GHS_KERNEL"),
- config);
- }
+ this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget, lang,
+ config);
+
this->LocalGenerator->AddCMP0018Flags(flags, this->GeneratorTarget, lang,
config);
this->LocalGenerator->AddVisibilityPresetFlags(
@@ -267,14 +212,9 @@ std::string cmGhsMultiTargetGenerator::GetDefines(const std::string& language,
if (i == this->DefinesByLanguage.end()) {
std::set<std::string> defines;
const char* lang = language.c_str();
- // Add the export symbol definition for shared library objects.
- if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
- this->LocalGenerator->AppendDefines(defines, exportMacro);
- }
-
// Add preprocessor definitions for this target and configuration.
- this->LocalGenerator->AddCompileDefinitions(defines, this->GeneratorTarget,
- config, language);
+ this->LocalGenerator->GetTargetDefines(this->GeneratorTarget, config,
+ language, defines);
std::string definesString;
this->LocalGenerator->JoinDefines(defines, definesString, lang);
@@ -286,376 +226,574 @@ std::string cmGhsMultiTargetGenerator::GetDefines(const std::string& language,
return i->second;
}
-void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::string const&,
+void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::ostream& fout,
+ std::string const&,
const std::string& language)
{
std::map<std::string, std::string>::iterator flagsByLangI =
this->FlagsByLanguage.find(language);
if (flagsByLangI != this->FlagsByLanguage.end()) {
if (!flagsByLangI->second.empty()) {
- *this->GetFolderBuildStreams() << " " << flagsByLangI->second
- << std::endl;
+ std::vector<std::string> ghsCompFlags =
+ cmSystemTools::ParseArguments(flagsByLangI->second);
+ for (auto& f : ghsCompFlags) {
+ fout << " " << f << std::endl;
+ }
}
}
}
void cmGhsMultiTargetGenerator::WriteCompilerDefinitions(
- const std::string& config, const std::string& language)
+ std::ostream& fout, const std::string& config, const std::string& language)
{
std::vector<std::string> compileDefinitions;
this->GeneratorTarget->GetCompileDefinitions(compileDefinitions, config,
language);
- for (std::vector<std::string>::const_iterator cdI =
- compileDefinitions.begin();
- cdI != compileDefinitions.end(); ++cdI) {
- *this->GetFolderBuildStreams() << " -D" << (*cdI) << std::endl;
+ for (std::string const& compileDefinition : compileDefinitions) {
+ fout << " -D" << compileDefinition << std::endl;
}
}
-void cmGhsMultiTargetGenerator::WriteIncludes(const std::string& config,
+void cmGhsMultiTargetGenerator::WriteIncludes(std::ostream& fout,
+ const std::string& config,
const std::string& language)
{
std::vector<std::string> includes;
this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
language, config);
- for (std::vector<std::string>::const_iterator includes_i = includes.begin();
- includes_i != includes.end(); ++includes_i) {
- *this->GetFolderBuildStreams() << " -I\"" << *includes_i << "\""
- << std::endl;
+ for (std::string const& include : includes) {
+ fout << " -I\"" << include << "\"" << std::endl;
}
}
-void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries(
- std::string const& config, std::string const& language)
+void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout,
+ std::string const& config)
{
- // library directories
- cmTargetDependSet tds =
- this->GetGlobalGenerator()->GetTargetDirectDepends(this->GeneratorTarget);
- for (cmTargetDependSet::iterator tdsI = tds.begin(); tdsI != tds.end();
- ++tdsI) {
- const cmGeneratorTarget* tg = *tdsI;
- *this->GetFolderBuildStreams() << " -L\"" << GetAbsBuildFilePath(tg)
- << "\"" << std::endl;
- }
- // library targets
- cmTarget::LinkLibraryVectorType llv =
- this->GeneratorTarget->Target->GetOriginalLinkLibraries();
- for (cmTarget::LinkLibraryVectorType::const_iterator llvI = llv.begin();
- llvI != llv.end(); ++llvI) {
- std::string libName = llvI->first;
- // if it is a user defined target get the full path to the lib
- cmTarget* tg(GetGlobalGenerator()->FindTarget(libName));
- if (NULL != tg) {
- libName = tg->GetName() + ".a";
- }
- *this->GetFolderBuildStreams() << " -l\"" << libName << "\""
- << std::endl;
+ if (this->TagType == GhsMultiGpj::INTERGRITY_APPLICATION) {
+ return;
}
- if (!this->TargetGroup) {
- std::string linkLibraries;
- std::string flags;
- std::string linkFlags;
- std::string frameworkPath;
- std::string linkPath;
- std::string createRule =
- this->GeneratorTarget->GetCreateRuleVariable(language, config);
- bool useWatcomQuote =
- this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE");
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
- this->GetGlobalGenerator()->CreateLinkLineComputer(
- this->LocalGenerator,
- this->LocalGenerator->GetStateSnapshot().GetDirectory()));
- linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
-
- this->LocalGenerator->GetTargetFlags(
- linkLineComputer.get(), config, linkLibraries, flags, linkFlags,
- frameworkPath, linkPath, this->GeneratorTarget);
- linkFlags = cmSystemTools::TrimWhitespace(linkFlags);
-
- if (!linkPath.empty()) {
- linkPath = " " + linkPath.substr(0U, linkPath.size() - 1U);
- *this->GetFolderBuildStreams() << linkPath;
- }
+ std::string linkLibraries;
+ std::string flags;
+ std::string linkFlags;
+ std::string frameworkPath;
+ std::string linkPath;
+
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
+ this->GetGlobalGenerator()->CreateLinkLineComputer(
+ this->LocalGenerator,
+ this->LocalGenerator->GetStateSnapshot().GetDirectory()));
+
+ this->LocalGenerator->GetTargetFlags(
+ linkLineComputer.get(), config, linkLibraries, flags, linkFlags,
+ frameworkPath, linkPath, this->GeneratorTarget);
+
+ // write out link options
+ std::vector<std::string> lopts = cmSystemTools::ParseArguments(linkFlags);
+ for (auto& l : lopts) {
+ fout << " " << l << std::endl;
+ }
- if (!linkFlags.empty()) {
- *this->GetFolderBuildStreams() << " " << linkFlags << std::endl;
- }
+ // write out link search paths
+ // must be quoted for paths that contain spaces
+ std::vector<std::string> lpath = cmSystemTools::ParseArguments(linkPath);
+ for (auto& l : lpath) {
+ fout << " -L\"" << l << "\"" << std::endl;
}
-}
-void cmGhsMultiTargetGenerator::WriteCustomCommands()
-{
- WriteCustomCommandsHelper(this->GeneratorTarget->GetPreBuildCommands(),
- cmTarget::PRE_BUILD);
- WriteCustomCommandsHelper(this->GeneratorTarget->GetPostBuildCommands(),
- cmTarget::POST_BUILD);
-}
+ // write out link libs
+ // must be quoted for filepaths that contains spaces
+ std::string cbd = this->LocalGenerator->GetCurrentBinaryDirectory();
-void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
- std::vector<cmCustomCommand> const& commandsSet,
- cmTarget::CustomCommandType const commandType)
-{
- for (std::vector<cmCustomCommand>::const_iterator commandsSetI =
- commandsSet.begin();
- commandsSetI != commandsSet.end(); ++commandsSetI) {
- cmCustomCommandLines const& commands = commandsSetI->GetCommandLines();
- for (cmCustomCommandLines::const_iterator commandI = commands.begin();
- commandI != commands.end(); ++commandI) {
- switch (commandType) {
- case cmTarget::PRE_BUILD:
- *this->GetFolderBuildStreams() << " :preexecShellSafe=";
- break;
- case cmTarget::POST_BUILD:
- *this->GetFolderBuildStreams() << " :postexecShellSafe=";
- break;
- default:
- assert("Only pre and post are supported");
- }
- cmCustomCommandLine const& command = *commandI;
- for (cmCustomCommandLine::const_iterator commandLineI = command.begin();
- commandLineI != command.end(); ++commandLineI) {
- std::string subCommandE =
- this->LocalGenerator->EscapeForShell(*commandLineI, true);
- if (!command.empty()) {
- *this->GetFolderBuildStreams()
- << (command.begin() == commandLineI ? "'" : " ");
- // Need to double escape backslashes
- cmSystemTools::ReplaceString(subCommandE, "\\", "\\\\");
- }
- *this->GetFolderBuildStreams() << subCommandE;
- }
- if (!command.empty()) {
- *this->GetFolderBuildStreams() << "'" << std::endl;
- }
+ std::vector<std::string> llibs =
+ cmSystemTools::ParseArguments(linkLibraries);
+ for (auto& l : llibs) {
+ if (l.compare(0, 2, "-l") == 0) {
+ fout << " \"" << l << "\"" << std::endl;
+ } else {
+ std::string rl = cmSystemTools::CollapseFullPath(l, cbd);
+ fout << " -l\"" << rl << "\"" << std::endl;
}
}
}
-std::map<const cmSourceFile*, std::string>
-cmGhsMultiTargetGenerator::GetObjectNames(
- std::vector<cmSourceFile*>* const objectSources,
- cmLocalGhsMultiGenerator* const localGhsMultiGenerator,
- cmGeneratorTarget* const generatorTarget)
+void cmGhsMultiTargetGenerator::WriteBuildEvents(std::ostream& fout)
{
- std::map<std::string, std::vector<cmSourceFile*> > filenameToSource;
- std::map<cmSourceFile*, std::string> sourceToFilename;
- for (std::vector<cmSourceFile*>::const_iterator sf = objectSources->begin();
- sf != objectSources->end(); ++sf) {
- const std::string filename =
- cmSystemTools::GetFilenameName((*sf)->GetFullPath());
- const std::string lower_filename = cmSystemTools::LowerCase(filename);
- filenameToSource[lower_filename].push_back(*sf);
- sourceToFilename[*sf] = lower_filename;
- }
-
- std::vector<cmSourceFile*> duplicateSources;
- for (std::map<std::string, std::vector<cmSourceFile*> >::const_iterator
- msvSourceI = filenameToSource.begin();
- msvSourceI != filenameToSource.end(); ++msvSourceI) {
- if (msvSourceI->second.size() > 1) {
- duplicateSources.insert(duplicateSources.end(),
- msvSourceI->second.begin(),
- msvSourceI->second.end());
- }
- }
-
- std::map<const cmSourceFile*, std::string> objectNamesCorrected;
+ this->WriteBuildEventsHelper(
+ fout, this->GeneratorTarget->GetPreBuildCommands(),
+ std::string("prebuild"), std::string("preexecShell"));
- for (std::vector<cmSourceFile*>::const_iterator sf =
- duplicateSources.begin();
- sf != duplicateSources.end(); ++sf) {
- std::string const longestObjectDirectory(
- cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
- localGhsMultiGenerator, generatorTarget, *sf));
- std::string objFilenameName =
- localGhsMultiGenerator->GetObjectFileNameWithoutTarget(
- **sf, longestObjectDirectory);
- cmsys::SystemTools::ReplaceString(objFilenameName, "/", "_");
- objectNamesCorrected[*sf] = objFilenameName;
+ if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
+ this->WriteBuildEventsHelper(
+ fout, this->GeneratorTarget->GetPreLinkCommands(),
+ std::string("prelink"), std::string("preexecShell"));
}
- return objectNamesCorrected;
+ this->WriteBuildEventsHelper(
+ fout, this->GeneratorTarget->GetPostBuildCommands(),
+ std::string("postbuild"), std::string("postexecShell"));
+}
+
+void cmGhsMultiTargetGenerator::WriteBuildEventsHelper(
+ std::ostream& fout, const std::vector<cmCustomCommand>& ccv,
+ std::string const& name, std::string const& cmd)
+{
+ int cmdcount = 0;
+
+ for (cmCustomCommand const& cc : ccv) {
+ cmCustomCommandGenerator ccg(cc, this->ConfigName, this->LocalGenerator);
+ // Open the filestream for this custom command
+ std::string fname = this->LocalGenerator->GetCurrentBinaryDirectory();
+ fname +=
+ "/" + this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ fname += "/" + this->Name + "_" + name;
+ fname += std::to_string(cmdcount++);
+ fname += this->CmdWindowsShell ? ".bat" : ".sh";
+ cmGeneratedFileStream f(fname);
+ f.SetCopyIfDifferent(true);
+ this->WriteCustomCommandsHelper(f, ccg);
+ f.Close();
+ if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
+ fout << " :" << cmd << "=\"" << fname << "\"" << std::endl;
+ } else {
+ fout << fname << std::endl;
+ fout << " :outputName=\"" << fname << ".rule\"" << std::endl;
+ }
+ for (auto& byp : ccg.GetByproducts()) {
+ fout << " :extraOutputFile=\"" << byp << "\"" << std::endl;
+ }
+ }
}
-void cmGhsMultiTargetGenerator::WriteSources(
- std::vector<cmSourceFile*> const& objectSources,
- std::map<const cmSourceFile*, std::string> const& objectNames)
+void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
+ std::ostream& fout, cmCustomCommandGenerator const& ccg)
{
- for (std::vector<cmSourceFile*>::const_iterator si = objectSources.begin();
- si != objectSources.end(); ++si) {
- std::vector<cmSourceGroup> sourceGroups(this->Makefile->GetSourceGroups());
- char const* sourceFullPath = (*si)->GetFullPath().c_str();
- cmSourceGroup* sourceGroup =
- this->Makefile->FindSourceGroup(sourceFullPath, sourceGroups);
- std::string sgPath(sourceGroup->GetFullName());
- cmSystemTools::ConvertToUnixSlashes(sgPath);
- cmGlobalGhsMultiGenerator::AddFilesUpToPath(
- this->GetFolderBuildStreams(), &this->FolderBuildStreams,
- this->LocalGenerator->GetBinaryDirectory(), sgPath,
- GhsMultiGpj::SUBPROJECT, this->RelBuildFilePath);
-
- std::string fullSourcePath((*si)->GetFullPath());
- if ((*si)->GetExtension() == "int" || (*si)->GetExtension() == "bsp") {
- *this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl;
- } else {
- // WORKAROUND: GHS MULTI needs the path to use backslashes without quotes
- // to open files in search as of version 6.1.6
- cmsys::SystemTools::ReplaceString(fullSourcePath, "/", "\\");
- *this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl;
- }
+ std::vector<std::string> cmdLines;
- if ("ld" != (*si)->GetExtension() && "int" != (*si)->GetExtension() &&
- "bsp" != (*si)->GetExtension()) {
- this->WriteObjectLangOverride(this->FolderBuildStreams[sgPath], (*si));
- if (objectNames.end() != objectNames.find(*si)) {
- *this->FolderBuildStreams[sgPath]
- << " -o \"" << objectNames.find(*si)->second << "\"" << std::endl;
+ // if the command specified a working directory use it.
+ std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
+ std::string currentBinDir = dir;
+ std::string workingDir = ccg.GetWorkingDirectory();
+ if (!workingDir.empty()) {
+ dir = workingDir;
+ }
+
+ // Line to check for error between commands.
+#ifdef _WIN32
+ std::string check_error = "if %errorlevel% neq 0 exit /b %errorlevel%";
+#else
+ std::string check_error = "if [[ $? -ne 0 ]]; then exit 1; fi";
+#endif
+
+#ifdef _WIN32
+ cmdLines.push_back("@echo off");
+#endif
+ // Echo the custom command's comment text.
+ const char* comment = ccg.GetComment();
+ if (comment && *comment) {
+ std::string echocmd = "echo ";
+ echocmd += comment;
+ cmdLines.push_back(std::move(echocmd));
+ }
+
+ // Switch to working directory
+ std::string cdCmd;
+#ifdef _WIN32
+ std::string cdStr = "cd /D ";
+#else
+ std::string cdStr = "cd ";
+#endif
+ cdCmd = cdStr +
+ this->LocalGenerator->ConvertToOutputFormat(dir, cmOutputConverter::SHELL);
+ cmdLines.push_back(std::move(cdCmd));
+
+ 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.empty()) {
+ // Use "call " before any invocations of .bat or .cmd files
+ // invoked as custom commands in the WindowsShell.
+ //
+ bool useCall = false;
+
+ if (this->CmdWindowsShell) {
+ std::string suffix;
+ if (cmd.size() > 4) {
+ suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size() - 4));
+ if (suffix == ".bat" || suffix == ".cmd") {
+ useCall = true;
+ }
+ }
}
- this->WriteObjectDir(this->FolderBuildStreams[sgPath],
- this->AbsBuildFilePath + sgPath);
+ 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('/') != std::string::npos;
+ if (workingDir.empty()) {
+ cmd =
+ this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, cmd);
+ }
+ bool has_slash = cmd.find('/') != std::string::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;
+ }
+ cmd = this->LocalGenerator->ConvertToOutputFormat(
+ cmd, cmOutputConverter::SHELL);
+ if (useCall) {
+ cmd = "call " + cmd;
+ }
+ ccg.AppendArguments(c, cmd);
+ cmdLines.push_back(std::move(cmd));
}
}
+
+ // push back the custom commands
+ for (auto const& c : cmdLines) {
+ fout << c << std::endl;
+ fout << check_error << std::endl;
+ }
}
-void cmGhsMultiTargetGenerator::WriteObjectLangOverride(
- cmGeneratedFileStream* fileStream, cmSourceFile* sourceFile)
+void cmGhsMultiTargetGenerator::WriteSourceProperty(
+ std::ostream& fout, const cmSourceFile* sf, std::string const& propName,
+ std::string const& propFlag)
{
- const char* rawLangProp = sourceFile->GetProperty("LANGUAGE");
- if (NULL != rawLangProp) {
- std::string sourceLangProp(rawLangProp);
- std::string extension(sourceFile->GetExtension());
- if ("CXX" == sourceLangProp && ("c" == extension || "C" == extension)) {
- *fileStream << " -dotciscxx" << std::endl;
+ const char* prop = sf->GetProperty(propName);
+ if (prop) {
+ std::vector<std::string> list;
+ cmSystemTools::ExpandListArgument(prop, list);
+ for (auto& p : list) {
+ fout << " " << propFlag << p << std::endl;
}
}
}
-void cmGhsMultiTargetGenerator::WriteObjectDir(
- cmGeneratedFileStream* fileStream, std::string const& dir)
+void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
{
- std::string workingDir(dir);
- cmSystemTools::ConvertToUnixSlashes(workingDir);
- if (!workingDir.empty()) {
- workingDir += "/";
+ /* vector of all sources for this target */
+ std::vector<cmSourceFile*> sources;
+ this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName);
+
+ /* vector of all groups defined for this target
+ * -- but the vector is not expanded with sub groups or in any useful order
+ */
+ std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
+
+ /* for each source file assign it to its group */
+ std::map<std::string, std::vector<cmSourceFile*>> groupFiles;
+ std::set<std::string> groupNames;
+ for (auto& sf : sources) {
+ cmSourceGroup* sourceGroup =
+ this->Makefile->FindSourceGroup(sf->GetFullPath(), sourceGroups);
+ std::string gn = sourceGroup->GetFullName();
+ groupFiles[gn].push_back(sf);
+ groupNames.insert(std::move(gn));
}
- workingDir += "Objs";
- *fileStream << " -object_dir=\"" << workingDir << "\"" << std::endl;
-}
-std::string cmGhsMultiTargetGenerator::GetOutputDirectory(
- const std::string& config) const
-{
- std::string outputDir(AbsBuildFilePath);
+ /* list of known groups and the order they are displayed in a project file */
+ const std::vector<std::string> standardGroups = {
+ "CMake Rules", "Header Files", "Source Files",
+ "Object Files", "Object Libraries", "Resources"
+ };
+
+ /* list of groups in the order they are displayed in a project file*/
+ std::vector<std::string> groupFilesList(groupFiles.size());
+
+ /* put the groups in the order they should be listed
+ * - standard groups first, and then everything else
+ * in the order used by std::map.
+ */
+ int i = 0;
+ for (const std::string& gn : standardGroups) {
+ auto n = groupNames.find(gn);
+ if (n != groupNames.end()) {
+ groupFilesList[i] = *n;
+ i += 1;
+ groupNames.erase(gn);
+ } else if (this->TagType == GhsMultiGpj::CUSTOM_TARGET &&
+ gn == "CMake Rules") {
+ /* make sure that rules folder always exists in case of custom targets
+ * that have no custom commands except for pre or post build events.
+ */
+ groupFilesList.resize(groupFilesList.size() + 1);
+ groupFilesList[i] = gn;
+ i += 1;
+ }
+ }
- const char* runtimeOutputProp =
- this->GeneratorTarget->GetProperty("RUNTIME_OUTPUT_DIRECTORY");
- if (NULL != runtimeOutputProp) {
- outputDir = runtimeOutputProp;
+ { /* catch-all group - is last item */
+ std::string gn;
+ auto n = groupNames.find(gn);
+ if (n != groupNames.end()) {
+ groupFilesList.back() = *n;
+ groupNames.erase(gn);
+ }
}
- std::string configCapped(cmSystemTools::UpperCase(config));
- const char* runtimeOutputSProp = this->GeneratorTarget->GetProperty(
- "RUNTIME_OUTPUT_DIRECTORY_" + configCapped);
- if (NULL != runtimeOutputSProp) {
- outputDir = runtimeOutputSProp;
+ for (auto& n : groupNames) {
+ groupFilesList[i] = n;
+ i += 1;
}
- cmSystemTools::ConvertToUnixSlashes(outputDir);
- if (!outputDir.empty()) {
- outputDir += "/";
+ /* sort the files within each group */
+ for (auto& n : groupFilesList) {
+ std::sort(groupFiles[n].begin(), groupFiles[n].end(),
+ [](cmSourceFile* l, cmSourceFile* r) {
+ return l->GetFullPath() < r->GetFullPath();
+ });
}
- return outputDir;
-}
+ /* list of open project files */
+ std::vector<cmGeneratedFileStream*> gfiles;
+
+ /* write files into the proper project file
+ * -- groups go into main project file
+ * unless NO_SOURCE_GROUP_FILE property or variable is set.
+ */
+ for (auto& sg : groupFilesList) {
+ std::ostream* fout;
+ bool useProjectFile =
+ cmSystemTools::IsOn(
+ this->GeneratorTarget->GetProperty("GHS_NO_SOURCE_GROUP_FILE")) ||
+ cmSystemTools::IsOn(
+ this->Makefile->GetDefinition("CMAKE_GHS_NO_SOURCE_GROUP_FILE"));
+ if (useProjectFile || sg.empty()) {
+ fout = &fout_proj;
+ } else {
+ // Open the filestream in copy-if-different mode.
+ std::string gname = sg;
+ cmsys::SystemTools::ReplaceString(gname, "\\", "_");
+ std::string lpath =
+ this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ lpath += "/";
+ lpath += gname;
+ lpath += cmGlobalGhsMultiGenerator::FILE_EXTENSION;
+ std::string fpath = this->LocalGenerator->GetCurrentBinaryDirectory();
+ fpath += "/";
+ fpath += lpath;
+ cmGeneratedFileStream* f = new cmGeneratedFileStream(fpath);
+ f->SetCopyIfDifferent(true);
+ gfiles.push_back(f);
+ fout = f;
+ this->GetGlobalGenerator()->WriteFileHeader(*f);
+ GhsMultiGpj::WriteGpjTag(GhsMultiGpj::SUBPROJECT, *f);
+ fout_proj << lpath << " ";
+ GhsMultiGpj::WriteGpjTag(GhsMultiGpj::SUBPROJECT, fout_proj);
+ }
-std::string cmGhsMultiTargetGenerator::GetOutputFilename(
- const std::string& config) const
-{
- std::string outputFilename(this->GeneratorTarget->GetName());
+ if (useProjectFile) {
+ if (sg.empty()) {
+ *fout << "{comment} Others" << std::endl;
+ } else {
+ *fout << "{comment} " << sg << std::endl;
+ }
+ } else if (sg.empty()) {
+ *fout << "{comment} Others" << std::endl;
+ }
- const char* outputNameProp =
- this->GeneratorTarget->GetProperty("OUTPUT_NAME");
- if (NULL != outputNameProp) {
- outputFilename = outputNameProp;
- }
+ if (sg != "CMake Rules") {
+ /* output rule for each source file */
+ for (const cmSourceFile* si : groupFiles[sg]) {
+ bool compile = true;
+ // Convert filename to native system
+ // WORKAROUND: GHS MULTI 6.1.4 and 6.1.6 are known to need backslash on
+ // windows when opening some files from the search window.
+ std::string fname(si->GetFullPath());
+ cmSystemTools::ConvertToOutputSlashes(fname);
+
+ /* For custom targets list any associated sources,
+ * comment out source code to prevent it from being
+ * compiled when processing this target.
+ * Otherwise, comment out any custom command (main) dependencies that
+ * are listed as source files to prevent them from being considered
+ * part of the build.
+ */
+ std::string comment;
+ if ((this->TagType == GhsMultiGpj::CUSTOM_TARGET &&
+ !si->GetLanguage().empty()) ||
+ si->GetCustomCommand()) {
+ comment = "{comment} ";
+ compile = false;
+ }
- std::string configCapped(cmSystemTools::UpperCase(config));
- const char* outputNameSProp =
- this->GeneratorTarget->GetProperty(configCapped + "_OUTPUT_NAME");
- if (NULL != outputNameSProp) {
- outputFilename = outputNameSProp;
+ *fout << comment << fname << std::endl;
+ if (compile) {
+ if ("ld" != si->GetExtension() && "int" != si->GetExtension() &&
+ "bsp" != si->GetExtension()) {
+ WriteObjectLangOverride(*fout, si);
+ }
+
+ this->WriteSourceProperty(*fout, si, "INCLUDE_DIRECTORIES", "-I");
+ this->WriteSourceProperty(*fout, si, "COMPILE_DEFINITIONS", "-D");
+ this->WriteSourceProperty(*fout, si, "COMPILE_OPTIONS", "");
+
+ /* to avoid clutter in the GUI only print out the objectName if it
+ * has been renamed */
+ std::string objectName = this->GeneratorTarget->GetObjectName(si);
+ if (!objectName.empty() &&
+ this->GeneratorTarget->HasExplicitObjectName(si)) {
+ *fout << " -o " << objectName << std::endl;
+ }
+ }
+ }
+ } else {
+ std::vector<cmSourceFile const*> customCommands;
+ if (ComputeCustomCommandOrder(customCommands)) {
+ std::string message = "The custom commands for target [" +
+ this->GeneratorTarget->GetName() + "] had a cycle.\n";
+ cmSystemTools::Error(message);
+ } else {
+ /* Custom targets do not have a dependency on SOURCES files.
+ * Therefore the dependency list may include SOURCES files after the
+ * custom target. Because nothing can depend on the custom target just
+ * move it to the last item.
+ */
+ for (auto sf = customCommands.begin(); sf != customCommands.end();
+ ++sf) {
+ if (((*sf)->GetLocation()).GetName() == this->Name + ".rule") {
+ std::rotate(sf, sf + 1, customCommands.end());
+ break;
+ }
+ }
+ int cmdcount = 0;
+ for (auto& sf : customCommands) {
+ const cmCustomCommand* cc = sf->GetCustomCommand();
+ cmCustomCommandGenerator ccg(*cc, this->ConfigName,
+ this->LocalGenerator);
+
+ // Open the filestream for this custom command
+ std::string fname =
+ this->LocalGenerator->GetCurrentBinaryDirectory();
+ fname += "/" +
+ this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ fname += "/" + this->Name + "_cc";
+ fname += std::to_string(cmdcount++) + "_";
+ fname += (sf->GetLocation()).GetName();
+ fname += this->CmdWindowsShell ? ".bat" : ".sh";
+ cmGeneratedFileStream f(fname);
+ f.SetCopyIfDifferent(true);
+ this->WriteCustomCommandsHelper(f, ccg);
+ f.Close();
+ this->WriteCustomCommandLine(*fout, fname, ccg);
+ }
+ }
+ if (this->TagType == GhsMultiGpj::CUSTOM_TARGET) {
+ this->WriteBuildEvents(*fout);
+ }
+ }
}
- return outputFilename;
+ for (cmGeneratedFileStream* f : gfiles) {
+ f->Close();
+ }
}
-std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
- cmLocalGhsMultiGenerator const* localGhsMultiGenerator,
- cmGeneratorTarget* const generatorTarget, cmSourceFile* const sourceFile)
-{
- std::string dir_max;
- dir_max +=
- localGhsMultiGenerator->GetMakefile()->GetCurrentBinaryDirectory();
- dir_max += "/";
- dir_max += generatorTarget->Target->GetName();
- dir_max += "/";
- std::vector<cmSourceGroup> sourceGroups(
- localGhsMultiGenerator->GetMakefile()->GetSourceGroups());
- char const* const sourceFullPath = sourceFile->GetFullPath().c_str();
- cmSourceGroup* sourceGroup =
- localGhsMultiGenerator->GetMakefile()->FindSourceGroup(sourceFullPath,
- sourceGroups);
- std::string const sgPath(sourceGroup->GetFullName());
- dir_max += sgPath;
- dir_max += "/Objs/libs/";
- dir_max += generatorTarget->Target->GetName();
- dir_max += "/";
- return dir_max;
+void cmGhsMultiTargetGenerator::WriteCustomCommandLine(
+ std::ostream& fout, std::string& fname, cmCustomCommandGenerator const& ccg)
+{
+ /* NOTE: Customization Files are not well documented. Testing showed
+ * that ":outputName=file" can only be used once per script. The
+ * script will only run if ":outputName=file" is missing or just run
+ * once if ":outputName=file" is not specified. If there are
+ * multiple outputs then the script needs to be listed multiple times
+ * for each output. Otherwise it won't rerun the script if one of
+ * the outputs is manually deleted.
+ */
+ bool specifyExtra = true;
+ for (auto& out : ccg.GetOutputs()) {
+ fout << fname << std::endl;
+ fout << " :outputName=\"" << out << "\"" << std::endl;
+ if (specifyExtra) {
+ for (auto& byp : ccg.GetByproducts()) {
+ fout << " :extraOutputFile=\"" << byp << "\"" << std::endl;
+ }
+ for (auto& dep : ccg.GetDepends()) {
+ fout << " :depends=\"" << dep << "\"" << std::endl;
+ }
+ specifyExtra = false;
+ }
+ }
}
-bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const& config,
- const std::string& language)
+void cmGhsMultiTargetGenerator::WriteObjectLangOverride(
+ std::ostream& fout, const cmSourceFile* sourceFile)
{
- bool output;
- std::vector<std::string> options;
- this->GeneratorTarget->GetCompileOptions(options, config, language);
- output =
- options.end() == std::find(options.begin(), options.end(), "-kernel");
- return output;
+ const char* rawLangProp = sourceFile->GetProperty("LANGUAGE");
+ if (nullptr != rawLangProp) {
+ std::string sourceLangProp(rawLangProp);
+ std::string const& extension = sourceFile->GetExtension();
+ if ("CXX" == sourceLangProp && ("c" == extension || "C" == extension)) {
+ fout << " -dotciscxx" << std::endl;
+ }
+ }
}
-bool cmGhsMultiTargetGenerator::DetermineIfTargetGroup(
- const cmGeneratorTarget* target)
+bool cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()
{
- bool output = false;
+ const char* p = this->GeneratorTarget->GetProperty("ghs_integrity_app");
+ if (p) {
+ return cmSystemTools::IsOn(
+ this->GeneratorTarget->GetProperty("ghs_integrity_app"));
+ }
std::vector<cmSourceFile*> sources;
- std::string config =
- target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
- target->GetSourceFiles(sources, config);
- for (std::vector<cmSourceFile*>::const_iterator sources_i = sources.begin();
- sources.end() != sources_i; ++sources_i) {
- if ("int" == (*sources_i)->GetExtension()) {
- output = true;
+ this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName);
+ for (auto& sf : sources) {
+ if ("int" == sf->GetExtension()) {
+ return true;
}
}
- return output;
+ return false;
}
-bool cmGhsMultiTargetGenerator::DetermineIfDynamicDownload(
- std::string const& config, const std::string& language)
+bool cmGhsMultiTargetGenerator::ComputeCustomCommandOrder(
+ std::vector<cmSourceFile const*>& order)
{
- std::vector<std::string> options;
- bool output = false;
- this->GeneratorTarget->GetCompileOptions(options, config, language);
- for (std::vector<std::string>::const_iterator options_i = options.begin();
- options_i != options.end(); ++options_i) {
- std::string option = *options_i;
- if (this->DDOption == option) {
- output = true;
+ std::set<cmSourceFile const*> temp;
+ std::set<cmSourceFile const*> perm;
+
+ // Collect all custom commands for this target
+ std::vector<cmSourceFile const*> customCommands;
+ this->GeneratorTarget->GetCustomCommands(customCommands, this->ConfigName);
+
+ for (cmSourceFile const* si : customCommands) {
+ bool r = VisitCustomCommand(temp, perm, order, si);
+ if (r) {
+ return r;
+ }
+ }
+ return false;
+}
+
+bool cmGhsMultiTargetGenerator::VisitCustomCommand(
+ std::set<cmSourceFile const*>& temp, std::set<cmSourceFile const*>& perm,
+ std::vector<cmSourceFile const*>& order, cmSourceFile const* si)
+{
+ /* check if permanent mark is set*/
+ if (perm.find(si) == perm.end()) {
+ /* set temporary mark; check if revisit*/
+ if (temp.insert(si).second) {
+ for (auto& di : si->GetCustomCommand()->GetDepends()) {
+ cmSourceFile const* sf = this->GeneratorTarget->GetLocalGenerator()
+ ->GetMakefile()
+ ->GetSourceFileWithOutput(di);
+ /* if sf exists then visit */
+ if (sf && this->VisitCustomCommand(temp, perm, order, sf)) {
+ return true;
+ }
+ }
+ /* mark as complete; insert into beginning of list*/
+ perm.insert(si);
+ order.push_back(si);
+ return false;
}
+ /* revisiting item - not a DAG */
+ return true;
}
- return output;
+ /* already complete */
+ return false;
}
diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h
index 2cdf68e11..a131567c8 100644
--- a/Source/cmGhsMultiTargetGenerator.h
+++ b/Source/cmGhsMultiTargetGenerator.h
@@ -5,10 +5,14 @@
#include "cmGhsMultiGpj.h"
-#include "cmTarget.h"
+#include <iosfwd>
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
class cmCustomCommand;
-class cmGeneratedFileStream;
+class cmCustomCommandGenerator;
class cmGeneratorTarget;
class cmGlobalGhsMultiGenerator;
class cmLocalGhsMultiGenerator;
@@ -24,97 +28,59 @@ public:
virtual void Generate();
- bool IncludeThisTarget();
- std::vector<cmSourceFile*> GetSources() const;
- GhsMultiGpj::Types GetGpjTag() const;
- static GhsMultiGpj::Types GetGpjTag(const cmGeneratorTarget* target);
- const char* GetAbsBuildFilePath() const
- {
- return this->AbsBuildFilePath.c_str();
- }
- const char* GetRelBuildFileName() const
- {
- return this->RelBuildFileName.c_str();
- }
- const char* GetAbsBuildFileName() const
- {
- return this->AbsBuildFileName.c_str();
- }
- const char* GetAbsOutputFileName() const
- {
- return this->AbsOutputFileName.c_str();
- }
-
- static std::string GetRelBuildFilePath(const cmGeneratorTarget* target);
- static std::string GetAbsPathToRoot(const cmGeneratorTarget* target);
- static std::string GetAbsBuildFilePath(const cmGeneratorTarget* target);
- static std::string GetRelBuildFileName(const cmGeneratorTarget* target);
- static std::string GetBuildFileName(const cmGeneratorTarget* target);
- static std::string AddSlashIfNeededToPath(std::string const& input);
-
private:
cmGlobalGhsMultiGenerator* GetGlobalGenerator() const;
- cmGeneratedFileStream* GetFolderBuildStreams()
- {
- return this->FolderBuildStreams[""];
- };
- bool IsTargetGroup() const { return this->TargetGroup; }
-
- void WriteTypeSpecifics(const std::string& config, bool notKernel);
- void WriteCompilerFlags(const std::string& config,
+
+ void GenerateTarget();
+
+ void WriteTargetSpecifics(std::ostream& fout, const std::string& config);
+
+ void WriteCompilerFlags(std::ostream& fout, const std::string& config,
const std::string& language);
- void WriteCompilerDefinitions(const std::string& config,
+ void WriteCompilerDefinitions(std::ostream& fout, const std::string& config,
const std::string& language);
- void SetCompilerFlags(std::string const& config, const std::string& language,
- bool const notKernel);
+ void SetCompilerFlags(std::string const& config,
+ const std::string& language);
+
std::string GetDefines(const std::string& langugae,
std::string const& config);
- void WriteIncludes(const std::string& config, const std::string& language);
- void WriteTargetLinkLibraries(std::string const& config,
- std::string const& language);
- void WriteCustomCommands();
- void WriteCustomCommandsHelper(
- std::vector<cmCustomCommand> const& commandsSet,
- cmTarget::CustomCommandType commandType);
- void WriteSources(
- std::vector<cmSourceFile*> const& objectSources,
- std::map<const cmSourceFile*, std::string> const& objectNames);
- static std::map<const cmSourceFile*, std::string> GetObjectNames(
- std::vector<cmSourceFile*>* objectSources,
- cmLocalGhsMultiGenerator* localGhsMultiGenerator,
- cmGeneratorTarget* generatorTarget);
- static void WriteObjectLangOverride(cmGeneratedFileStream* fileStream,
- cmSourceFile* sourceFile);
- static void WriteObjectDir(cmGeneratedFileStream* fileStream,
- std::string const& dir);
- std::string GetOutputDirectory(const std::string& config) const;
- std::string GetOutputFilename(const std::string& config) const;
- static std::string ComputeLongestObjectDirectory(
- cmLocalGhsMultiGenerator const* localGhsMultiGenerator,
- cmGeneratorTarget* generatorTarget, cmSourceFile* const sourceFile);
-
- bool IsNotKernel(std::string const& config, const std::string& language);
- static bool DetermineIfTargetGroup(const cmGeneratorTarget* target);
- bool DetermineIfDynamicDownload(std::string const& config,
- const std::string& language);
+ void WriteIncludes(std::ostream& fout, const std::string& config,
+ const std::string& language);
+ void WriteTargetLinkLine(std::ostream& fout, std::string const& config);
+ void WriteBuildEvents(std::ostream& fout);
+ void WriteBuildEventsHelper(std::ostream& fout,
+ const std::vector<cmCustomCommand>& ccv,
+ std::string const& name, std::string const& cmd);
+ void WriteCustomCommandsHelper(std::ostream& fout,
+ cmCustomCommandGenerator const& ccg);
+ void WriteCustomCommandLine(std::ostream& fout, std::string& fname,
+ cmCustomCommandGenerator const& ccg);
+ bool ComputeCustomCommandOrder(std::vector<cmSourceFile const*>& order);
+ bool VisitCustomCommand(std::set<cmSourceFile const*>& temp,
+ std::set<cmSourceFile const*>& perm,
+ std::vector<cmSourceFile const*>& order,
+ cmSourceFile const* sf);
+ void WriteSources(std::ostream& fout_proj);
+ void WriteSourceProperty(std::ostream& fout, const cmSourceFile* sf,
+ std::string const& propName,
+ std::string const& propFlag);
+ static void WriteObjectLangOverride(std::ostream& fout,
+ const cmSourceFile* sourceFile);
+ bool DetermineIfIntegrityApp();
cmGeneratorTarget* GeneratorTarget;
cmLocalGhsMultiGenerator* LocalGenerator;
cmMakefile* Makefile;
- std::string AbsBuildFilePath;
- std::string RelBuildFilePath;
- std::string AbsBuildFileName;
- std::string RelBuildFileName;
- std::string RelOutputFileName;
- std::string AbsOutputFileName;
- std::map<std::string, cmGeneratedFileStream*> FolderBuildStreams;
- bool TargetGroup;
- bool DynamicDownload;
- static std::string const DDOption;
std::map<std::string, std::string> FlagsByLanguage;
std::map<std::string, std::string> DefinesByLanguage;
+
+ std::string TargetNameReal;
+ GhsMultiGpj::Types TagType;
+ std::string const Name;
+ std::string ConfigName; /* CMAKE_BUILD_TYPE */
+ bool const CmdWindowsShell; /* custom commands run in cmd.exe or /bin/sh */
};
#endif // ! cmGhsMultiTargetGenerator_h
diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx
index d2372a766..51d681dee 100644
--- a/Source/cmGlobalBorlandMakefileGenerator.cxx
+++ b/Source/cmGlobalBorlandMakefileGenerator.cxx
@@ -5,6 +5,7 @@
#include "cmDocumentationEntry.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmState.h"
#include "cmake.h"
@@ -33,7 +34,7 @@ void cmGlobalBorlandMakefileGenerator::EnableLanguage(
this->cmGlobalUnixMakefileGenerator3::EnableLanguage(l, mf, optional);
}
-///! Create a local generator appropriate to this Global Generator
+//! Create a local generator appropriate to this Global Generator
cmLocalGenerator* cmGlobalBorlandMakefileGenerator::CreateLocalGenerator(
cmMakefile* mf)
{
@@ -51,3 +52,33 @@ void cmGlobalBorlandMakefileGenerator::GetDocumentation(
entry.Name = cmGlobalBorlandMakefileGenerator::GetActualName();
entry.Brief = "Generates Borland makefiles.";
}
+
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalBorlandMakefileGenerator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int /*jobs*/, bool verbose,
+ std::vector<std::string> const& makeOptions)
+{
+ return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
+ makeProgram, projectName, projectDir, targetNames, config, fast,
+ cmake::NO_BUILD_PARALLEL_LEVEL, verbose, makeOptions);
+}
+
+void cmGlobalBorlandMakefileGenerator::PrintBuildCommandAdvice(
+ std::ostream& os, int jobs) const
+{
+ if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
+ // Borland's make does not support parallel builds
+ // see http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Make
+
+ /* clang-format off */
+ os <<
+ "Warning: Borland's make does not support parallel builds. "
+ "Ignoring parallel build command line option.\n";
+ /* clang-format on */
+ }
+
+ this->cmGlobalUnixMakefileGenerator3::PrintBuildCommandAdvice(
+ os, cmake::NO_BUILD_PARALLEL_LEVEL);
+}
diff --git a/Source/cmGlobalBorlandMakefileGenerator.h b/Source/cmGlobalBorlandMakefileGenerator.h
index 5578d7646..ee7de70f6 100644
--- a/Source/cmGlobalBorlandMakefileGenerator.h
+++ b/Source/cmGlobalBorlandMakefileGenerator.h
@@ -5,6 +5,8 @@
#include "cmGlobalNMakeMakefileGenerator.h"
+#include <iosfwd>
+
/** \class cmGlobalBorlandMakefileGenerator
* \brief Write a Borland makefiles.
*
@@ -20,8 +22,8 @@ public:
cmGlobalBorlandMakefileGenerator>();
}
- ///! Get the name for the generator.
- virtual std::string GetName() const
+ //! Get the name for the generator.
+ std::string GetName() const override
{
return cmGlobalBorlandMakefileGenerator::GetActualName();
}
@@ -30,18 +32,28 @@ public:
/** Get the documentation entry for this generator. */
static void GetDocumentation(cmDocumentationEntry& entry);
- ///! Create a local generator appropriate to this Global Generator
- virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf);
+ //! Create a local generator appropriate to this Global Generator
+ cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
/**
* 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);
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
+
+ bool AllowNotParallel() const override { return false; }
+ bool AllowDeleteOnError() const override { return false; }
+
+protected:
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
- virtual bool AllowNotParallel() const { return false; }
- virtual bool AllowDeleteOnError() const { return false; }
+ void PrintBuildCommandAdvice(std::ostream& os, int jobs) const override;
};
#endif
diff --git a/Source/cmGlobalCommonGenerator.cxx b/Source/cmGlobalCommonGenerator.cxx
index 3b7de4b9c..bf992b48b 100644
--- a/Source/cmGlobalCommonGenerator.cxx
+++ b/Source/cmGlobalCommonGenerator.cxx
@@ -9,6 +9,4 @@ cmGlobalCommonGenerator::cmGlobalCommonGenerator(cmake* cm)
{
}
-cmGlobalCommonGenerator::~cmGlobalCommonGenerator()
-{
-}
+cmGlobalCommonGenerator::~cmGlobalCommonGenerator() = default;
diff --git a/Source/cmGlobalCommonGenerator.h b/Source/cmGlobalCommonGenerator.h
index f2ad059de..e19118b50 100644
--- a/Source/cmGlobalCommonGenerator.h
+++ b/Source/cmGlobalCommonGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalCommonGenerator_h
#define cmGlobalCommonGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmGlobalGenerator.h"
@@ -16,7 +16,7 @@ class cmGlobalCommonGenerator : public cmGlobalGenerator
{
public:
cmGlobalCommonGenerator(cmake* cm);
- ~cmGlobalCommonGenerator() CM_OVERRIDE;
+ ~cmGlobalCommonGenerator() override;
};
#endif
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 099f705f4..ea898e175 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -6,14 +6,15 @@
#include "cmsys/FStream.hxx"
#include <algorithm>
#include <assert.h>
+#include <cstring>
+#include <initializer_list>
#include <iterator>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <windows.h>
+# include <windows.h>
#endif
#include "cmAlgorithms.h"
@@ -21,6 +22,7 @@
#include "cmComputeTargetDepends.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
+#include "cmDuration.h"
#include "cmExportBuildFileGenerator.h"
#include "cmExternalMakefileProjectGenerator.h"
#include "cmGeneratedFileStream.h"
@@ -31,9 +33,9 @@
#include "cmLocalGenerator.h"
#include "cmMSVC60LinkLineComputer.h"
#include "cmMakefile.h"
-#include "cmOutputConverter.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
-#include "cmQtAutoGeneratorInitializer.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmState.h"
#include "cmStateDirectory.h"
@@ -43,13 +45,14 @@
#include "cmake.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmCryptoHash.h"
-#include "cm_jsoncpp_value.h"
-#include "cm_jsoncpp_writer.h"
+# include "cmCryptoHash.h"
+# include "cmQtAutoGenGlobalInitializer.h"
+# include "cm_jsoncpp_value.h"
+# include "cm_jsoncpp_writer.h"
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1800
-#define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
#endif
const std::string kCMAKE_PLATFORM_INFO_INITIALIZED =
@@ -62,8 +65,8 @@ bool cmTarget::StrictTargetComparison::operator()(cmTarget const* t1,
{
int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
if (nameResult == 0) {
- return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
- t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
+ return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory().c_str(),
+ t2->GetMakefile()->GetCurrentBinaryDirectory().c_str()) < 0;
}
return nameResult < 0;
}
@@ -87,15 +90,17 @@ cmGlobalGenerator::cmGlobalGenerator(cmake* cm)
this->InstallTargetEnabled = false;
// how long to let try compiles run
- this->TryCompileTimeout = 0;
+ this->TryCompileTimeout = cmDuration::zero();
- this->ExtraGenerator = CM_NULLPTR;
- this->CurrentMakefile = CM_NULLPTR;
- this->TryCompileOuterMakefile = CM_NULLPTR;
+ this->ExtraGenerator = nullptr;
+ this->CurrentConfigureMakefile = nullptr;
+ this->TryCompileOuterMakefile = nullptr;
this->ConfigureDoneCMP0026AndCMP0024 = false;
this->FirstTimeProgress = 0.0f;
+ this->RecursionDepth = 0;
+
cm->GetState()->SetIsGeneratorMultiConfig(false);
cm->GetState()->SetMinGWMake(false);
cm->GetState()->SetMSYSShell(false);
@@ -111,6 +116,35 @@ cmGlobalGenerator::~cmGlobalGenerator()
delete this->ExtraGenerator;
}
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+Json::Value cmGlobalGenerator::GetJson() const
+{
+ Json::Value generator = Json::objectValue;
+ generator["name"] = this->GetName();
+ return generator;
+}
+#endif
+
+bool cmGlobalGenerator::SetGeneratorInstance(std::string const& i,
+ cmMakefile* mf)
+{
+ if (i.empty()) {
+ return true;
+ }
+
+ std::ostringstream e;
+ /* clang-format off */
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "does not support instance specification, but instance\n"
+ " " << i << "\n"
+ "was specified.";
+ /* clang-format on */
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return false;
+}
+
bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p,
cmMakefile* mf)
{
@@ -127,7 +161,7 @@ bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p,
" " << p << "\n"
"was specified.";
/* clang-format on */
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
@@ -146,7 +180,7 @@ bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts,
" " << ts << "\n"
"was specified.";
/* clang-format on */
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
@@ -154,7 +188,7 @@ std::string cmGlobalGenerator::SelectMakeProgram(
const std::string& inMakeProgram, const std::string& makeDefault) const
{
std::string makeProgram = inMakeProgram;
- if (cmSystemTools::IsOff(makeProgram.c_str())) {
+ if (cmSystemTools::IsOff(makeProgram)) {
const char* makeProgramCSTR =
this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
if (cmSystemTools::IsOff(makeProgramCSTR)) {
@@ -162,7 +196,7 @@ std::string cmGlobalGenerator::SelectMakeProgram(
} else {
makeProgram = makeProgramCSTR;
}
- if (cmSystemTools::IsOff(makeProgram.c_str()) && !makeProgram.empty()) {
+ if (cmSystemTools::IsOff(makeProgram) && !makeProgram.empty()) {
makeProgram = "CMAKE_MAKE_PROGRAM-NOTFOUND";
}
}
@@ -179,11 +213,11 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang,
if (!mf->GetDefinition(langComp)) {
if (!optional) {
- cmSystemTools::Error(langComp.c_str(), " not set, after EnableLanguage");
+ cmSystemTools::Error(langComp + " not set, after EnableLanguage");
}
return;
}
- const char* name = mf->GetRequiredDefinition(langComp);
+ std::string const& name = mf->GetRequiredDefinition(langComp);
std::string path;
if (!cmSystemTools::FileIsFullPath(name)) {
path = cmSystemTools::FindProgram(name);
@@ -193,15 +227,15 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang,
if (!optional && (path.empty() || !cmSystemTools::FileExists(path))) {
return;
}
- const char* cname =
+ const std::string* cname =
this->GetCMakeInstance()->GetState()->GetInitializedCacheValue(langComp);
std::string changeVars;
if (cname && !optional) {
std::string cnameString;
- if (!cmSystemTools::FileIsFullPath(cname)) {
- cnameString = cmSystemTools::FindProgram(cname);
+ if (!cmSystemTools::FileIsFullPath(*cname)) {
+ cnameString = cmSystemTools::FindProgram(*cname);
} else {
- cnameString = cname;
+ cnameString = *cname;
}
std::string pathString = path;
// get rid of potentially multiple slashes:
@@ -217,7 +251,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang,
}
changeVars += langComp;
changeVars += ";";
- changeVars += cname;
+ changeVars += *cname;
this->GetCMakeInstance()->GetState()->SetGlobalProperty(
"__CMAKE_DELETE_CACHE_CHANGE_VARS_", changeVars.c_str());
}
@@ -238,21 +272,18 @@ void cmGlobalGenerator::AddBuildExportExportSet(
bool cmGlobalGenerator::GenerateImportFile(const std::string& file)
{
- std::map<std::string, cmExportBuildFileGenerator*>::iterator it =
- this->BuildExportSets.find(file);
+ auto const it = this->BuildExportSets.find(file);
if (it != this->BuildExportSets.end()) {
bool result = it->second->GenerateImportFile();
if (!this->ConfigureDoneCMP0026AndCMP0024) {
- for (std::vector<cmMakefile*>::const_iterator mit =
- this->Makefiles.begin();
- mit != this->Makefiles.end(); ++mit) {
- (*mit)->RemoveExportBuildFileGeneratorCMP0024(it->second);
+ for (cmMakefile* m : this->Makefiles) {
+ m->RemoveExportBuildFileGeneratorCMP0024(it->second);
}
}
delete it->second;
- it->second = CM_NULLPTR;
+ it->second = nullptr;
this->BuildExportSets.erase(it);
return result;
}
@@ -263,11 +294,79 @@ void cmGlobalGenerator::ForceLinkerLanguages()
{
}
+bool cmGlobalGenerator::CheckTargetsForMissingSources() const
+{
+ bool failed = false;
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (cmGeneratorTarget* target : localGen->GetGeneratorTargets()) {
+ if (target->GetType() == cmStateEnums::TargetType::GLOBAL_TARGET ||
+ target->GetType() == cmStateEnums::TargetType::INTERFACE_LIBRARY ||
+ target->GetType() == cmStateEnums::TargetType::UTILITY ||
+ cmSystemTools::IsOn(target->GetProperty("ghs_integrity_app"))) {
+ continue;
+ }
+
+ std::vector<std::string> configs;
+ target->Makefile->GetConfigurations(configs);
+ std::vector<cmSourceFile*> srcs;
+ if (configs.empty()) {
+ target->GetSourceFiles(srcs, "");
+ } else {
+ for (std::string const& config : configs) {
+ target->GetSourceFiles(srcs, config);
+ if (srcs.empty()) {
+ break;
+ }
+ }
+ }
+ if (srcs.empty()) {
+ std::ostringstream e;
+ e << "No SOURCES given to target: " << target->GetName();
+ this->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR, e.str(), target->GetBacktrace());
+ failed = true;
+ }
+ }
+ }
+ return failed;
+}
+
+bool cmGlobalGenerator::CheckTargetsForType() const
+{
+ if (!this->GetLanguageEnabled("Swift")) {
+ return false;
+ }
+ bool failed = false;
+ for (cmLocalGenerator* generator : this->LocalGenerators) {
+ for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) {
+ if (target->GetType() == cmStateEnums::EXECUTABLE &&
+ target->GetPropertyAsBool("WIN32_EXECUTABLE")) {
+ std::vector<std::string> configs;
+ target->Makefile->GetConfigurations(configs);
+ if (configs.empty()) {
+ configs.emplace_back();
+ }
+
+ for (std::string const& config : configs) {
+ if (target->GetLinkerLanguage(config) == "Swift") {
+ this->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "WIN32_EXECUTABLE property is not supported on Swift "
+ "executables",
+ target->GetBacktrace());
+ failed = true;
+ }
+ }
+ }
+ }
+ }
+ return failed;
+}
+
bool cmGlobalGenerator::IsExportedTargetsFile(
const std::string& filename) const
{
- const std::map<std::string, cmExportBuildFileGenerator*>::const_iterator it =
- this->BuildExportSets.find(filename);
+ auto const it = this->BuildExportSets.find(filename);
if (it == this->BuildExportSets.end()) {
return false;
}
@@ -286,10 +385,9 @@ bool cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
}
if (!mf->GetDefinition("CMAKE_MAKE_PROGRAM") ||
cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM"))) {
- std::string setMakeProgram =
- mf->GetModulesFile(this->FindMakeProgramFile.c_str());
+ std::string setMakeProgram = mf->GetModulesFile(this->FindMakeProgramFile);
if (!setMakeProgram.empty()) {
- mf->ReadListFile(setMakeProgram.c_str());
+ mf->ReadListFile(setMakeProgram);
}
}
if (!mf->GetDefinition("CMAKE_MAKE_PROGRAM") ||
@@ -298,7 +396,7 @@ bool cmGlobalGenerator::FindMakeProgram(cmMakefile* mf)
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::Error(err.str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -383,13 +481,13 @@ void cmGlobalGenerator::EnableLanguage(
}
std::set<std::string> cur_languages(languages.begin(), languages.end());
- for (std::set<std::string>::iterator li = cur_languages.begin();
- li != cur_languages.end(); ++li) {
- if (!this->LanguagesInProgress.insert(*li).second) {
+ for (std::string const& li : cur_languages) {
+ if (!this->LanguagesInProgress.insert(li).second) {
std::ostringstream e;
- e << "Language '" << *li << "' is currently being enabled. "
- "Recursive call not allowed.";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ e << "Language '" << li
+ << "' is currently being enabled. "
+ "Recursive call not allowed.";
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
return;
}
@@ -397,17 +495,15 @@ void cmGlobalGenerator::EnableLanguage(
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") {
+ for (std::string const& lang : languages) {
+ if (lang == "NONE") {
this->SetLanguageEnabled("NONE", mf);
} else {
- const char* lang = li->c_str();
if (this->LanguagesReady.find(lang) == this->LanguagesReady.end()) {
std::ostringstream e;
e << "The test project needs language " << lang
<< " which is not enabled.";
- this->TryCompileOuterMakefile->IssueMessage(cmake::FATAL_ERROR,
+ this->TryCompileOuterMakefile->IssueMessage(MessageType::FATAL_ERROR,
e.str());
cmSystemTools::SetFatalErrorOccured();
return;
@@ -420,7 +516,7 @@ void cmGlobalGenerator::EnableLanguage(
mf->AddDefinition("RUN_CONFIGURE", true);
std::string rootBin = this->CMakeInstance->GetHomeOutputDirectory();
- rootBin += cmake::GetCMakeFilesDirectory();
+ rootBin += "/CMakeFiles";
// If the configuration files path has been set,
// then we are in a try compile and need to copy the enable language
@@ -451,22 +547,13 @@ void cmGlobalGenerator::EnableLanguage(
"Platform information initialized", cmStateEnums::INTERNAL);
}
- // find and make sure CMAKE_MAKE_PROGRAM is defined
- if (!this->FindMakeProgram(mf)) {
- return;
- }
-
- if (!this->CheckLanguages(languages, mf)) {
- return;
- }
-
// 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(fpath.c_str());
+ if (cmSystemTools::FileExists(fpath)) {
+ mf->ReadListFile(fpath);
}
}
// Load the CMakeDetermineSystem.cmake file and find out
@@ -478,33 +565,50 @@ void cmGlobalGenerator::EnableLanguage(
ZeroMemory(&osviex, sizeof(osviex));
osviex.dwOSVersionInfoSize = sizeof(osviex);
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(push)
-#pragma warning(disable : 4996)
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning(push)
+# ifdef __INTEL_COMPILER
+# pragma warning(disable : 1478)
+# elif defined __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# else
+# pragma warning(disable : 4996)
+# endif
+# endif
GetVersionExW((OSVERSIONINFOW*)&osviex);
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(pop)
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# ifdef __clang__
+# pragma clang diagnostic pop
+# else
+# pragma warning(pop)
+# endif
+# endif
std::ostringstream windowsVersionString;
windowsVersionString << osviex.dwMajorVersion << "."
<< osviex.dwMinorVersion << "."
<< osviex.dwBuildNumber;
- 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(systemFile.c_str());
+ mf->ReadListFile(systemFile);
// load the CMakeSystem.cmake from the binary directory
// this file is configured by the CMakeDetermineSystem.cmake file
fpath = rootBin;
fpath += "/CMakeSystem.cmake";
- mf->ReadListFile(fpath.c_str());
+ mf->ReadListFile(fpath);
}
if (readCMakeSystem) {
+ // Tell the generator about the instance, if any.
+ std::string instance = mf->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE");
+ if (!this->SetGeneratorInstance(instance, mf)) {
+ cmSystemTools::SetFatalErrorOccured();
+ return;
+ }
+
// Tell the generator about the target system.
std::string system = mf->GetSafeDefinition("CMAKE_SYSTEM_NAME");
if (!this->SetSystemName(system, mf)) {
@@ -525,12 +629,23 @@ void cmGlobalGenerator::EnableLanguage(
cmSystemTools::SetFatalErrorOccured();
return;
}
+
+ // Find the native build tool for this generator.
+ if (!this->FindMakeProgram(mf)) {
+ return;
+ }
+ }
+
+ // Check that the languages are supported by the generator and its
+ // native build tool found above.
+ if (!this->CheckLanguages(languages, mf)) {
+ 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(fpath.c_str())) {
+ if (!mf->ReadListFile(fpath)) {
cmSystemTools::Error("Could not find cmake module file: "
"CMakeSystemSpecificInitialize.cmake");
}
@@ -542,11 +657,9 @@ void cmGlobalGenerator::EnableLanguage(
// 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();
+ for (std::string const& lang : languages) {
needSetLanguageEnabledMaps[lang] = false;
- if (*l == "NONE") {
+ if (lang == "NONE") {
this->SetLanguageEnabled("NONE", mf);
continue;
}
@@ -562,10 +675,9 @@ void cmGlobalGenerator::EnableLanguage(
// 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(fpath.c_str())) {
- cmSystemTools::Error("Could not find cmake module file: ",
- fpath.c_str());
+ if (cmSystemTools::FileExists(fpath)) {
+ if (!mf->ReadListFile(fpath)) {
+ cmSystemTools::Error("Could not find cmake module file: " + fpath);
}
// if this file was found then the language was already determined
// to be working
@@ -588,11 +700,10 @@ void cmGlobalGenerator::EnableLanguage(
std::string determineCompiler = "CMakeDetermine";
determineCompiler += lang;
determineCompiler += "Compiler.cmake";
- std::string determineFile =
- mf->GetModulesFile(determineCompiler.c_str());
- if (!mf->ReadListFile(determineFile.c_str())) {
- cmSystemTools::Error("Could not find cmake module file: ",
- determineCompiler.c_str());
+ std::string determineFile = mf->GetModulesFile(determineCompiler);
+ if (!mf->ReadListFile(determineFile)) {
+ cmSystemTools::Error("Could not find cmake module file: " +
+ determineCompiler);
}
if (cmSystemTools::GetFatalErrorOccured()) {
return;
@@ -610,8 +721,9 @@ void cmGlobalGenerator::EnableLanguage(
std::string compilerEnv = "CMAKE_";
compilerEnv += lang;
compilerEnv += "_COMPILER_ENV_VAR";
- std::string envVar = mf->GetRequiredDefinition(compilerEnv);
- std::string envVarValue = mf->GetRequiredDefinition(compilerName);
+ const std::string& envVar = mf->GetRequiredDefinition(compilerEnv);
+ const std::string& envVarValue =
+ mf->GetRequiredDefinition(compilerName);
std::string env = envVar;
env += "=";
env += envVarValue;
@@ -624,9 +736,8 @@ void cmGlobalGenerator::EnableLanguage(
fpath += "/CMake";
fpath += lang;
fpath += "Compiler.cmake";
- if (!mf->ReadListFile(fpath.c_str())) {
- cmSystemTools::Error("Could not find cmake module file: ",
- fpath.c_str());
+ if (!mf->ReadListFile(fpath)) {
+ cmSystemTools::Error("Could not find cmake module file: " + fpath);
}
this->SetLanguageEnabledFlag(lang, mf);
needSetLanguageEnabledMaps[lang] = true;
@@ -641,17 +752,15 @@ void cmGlobalGenerator::EnableLanguage(
// **** 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(fpath.c_str())) {
+ if (!mf->ReadListFile(fpath)) {
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") {
+ for (std::string const& lang : languages) {
+ if (lang == "NONE") {
this->SetLanguageEnabled("NONE", mf);
continue;
}
@@ -672,7 +781,7 @@ void cmGlobalGenerator::EnableLanguage(
"No " << compilerName << " could be found.\n"
;
/* clang-format on */
- } else if (strcmp(lang, "RC") != 0 && strcmp(lang, "ASM_MASM") != 0) {
+ } else if ((lang != "RC") && (lang != "ASM_MASM")) {
if (!cmSystemTools::FileIsFullPath(compilerFile)) {
/* clang-format off */
noCompiler <<
@@ -705,7 +814,7 @@ void cmGlobalGenerator::EnableLanguage(
if (!this->CMakeInstance->GetIsInTryCompile()) {
this->PrintCompilerAdvice(noCompiler, lang,
mf->GetDefinition(compilerEnv));
- mf->IssueMessage(cmake::FATAL_ERROR, noCompiler.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, noCompiler.str());
fatalError = true;
}
}
@@ -718,13 +827,12 @@ void cmGlobalGenerator::EnableLanguage(
fpath = "CMake";
fpath += lang;
fpath += "Information.cmake";
- std::string informationFile = mf->GetModulesFile(fpath.c_str());
+ std::string informationFile = mf->GetModulesFile(fpath);
if (informationFile.empty()) {
- cmSystemTools::Error("Could not find cmake module file: ",
- fpath.c_str());
- } else if (!mf->ReadListFile(informationFile.c_str())) {
- cmSystemTools::Error("Could not process cmake module file: ",
- informationFile.c_str());
+ cmSystemTools::Error("Could not find cmake module file: " + fpath);
+ } else if (!mf->ReadListFile(informationFile)) {
+ cmSystemTools::Error("Could not process cmake module file: " +
+ informationFile);
}
}
if (needSetLanguageEnabledMaps[lang]) {
@@ -742,10 +850,10 @@ void cmGlobalGenerator::EnableLanguage(
std::string testLang = "CMakeTest";
testLang += lang;
testLang += "Compiler.cmake";
- std::string ifpath = mf->GetModulesFile(testLang.c_str());
- if (!mf->ReadListFile(ifpath.c_str())) {
- cmSystemTools::Error("Could not find cmake module file: ",
- testLang.c_str());
+ std::string ifpath = mf->GetModulesFile(testLang);
+ if (!mf->ReadListFile(ifpath)) {
+ cmSystemTools::Error("Could not find cmake module file: " +
+ testLang);
}
std::string compilerWorks = "CMAKE_";
compilerWorks += lang;
@@ -766,10 +874,8 @@ void cmGlobalGenerator::EnableLanguage(
std::string sharedLibFlagsVar = "CMAKE_SHARED_LIBRARY_";
sharedLibFlagsVar += lang;
sharedLibFlagsVar += "_FLAGS";
- const char* sharedLibFlags = mf->GetSafeDefinition(sharedLibFlagsVar);
- if (sharedLibFlags) {
- this->LanguageToOriginalSharedLibFlags[lang] = sharedLibFlags;
- }
+ this->LanguageToOriginalSharedLibFlags[lang] =
+ mf->GetSafeDefinition(sharedLibFlagsVar);
// Translate compiler ids for compatibility.
this->CheckCompilerIdCompatibility(mf, lang);
@@ -782,8 +888,8 @@ void cmGlobalGenerator::EnableLanguage(
projectCompatibility += "/Modules/";
projectCompatibility += mf->GetSafeDefinition("PROJECT_NAME");
projectCompatibility += "Compatibility.cmake";
- if (cmSystemTools::FileExists(projectCompatibility.c_str())) {
- mf->ReadListFile(projectCompatibility.c_str());
+ if (cmSystemTools::FileExists(projectCompatibility)) {
+ mf->ReadListFile(projectCompatibility);
}
// Inform any extra generator of the new language.
if (this->ExtraGenerator) {
@@ -794,9 +900,8 @@ void cmGlobalGenerator::EnableLanguage(
cmSystemTools::SetFatalErrorOccured();
}
- for (std::set<std::string>::iterator li = cur_languages.begin();
- li != cur_languages.end(); ++li) {
- this->LanguagesInProgress.erase(*li);
+ for (std::string const& lang : cur_languages) {
+ this->LanguagesInProgress.erase(lang);
}
}
@@ -819,12 +924,9 @@ 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;
- }
+ std::string const compilerId = mf->GetSafeDefinition(compilerIdVar);
- if (strcmp(compilerId, "AppleClang") == 0) {
+ if (compilerId == "AppleClang") {
switch (mf->GetPolicyStatus(cmPolicies::CMP0025)) {
case cmPolicies::WARN:
if (!this->CMakeInstance->GetIsInTryCompile() &&
@@ -833,10 +935,10 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
/* clang-format off */
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0025) << "\n"
"Converting " << lang <<
- " compiler id \"AppleClang\" to \"Clang\" for compatibility."
+ R"( compiler id "AppleClang" to "Clang" for compatibility.)"
;
/* clang-format on */
- mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -846,7 +948,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
mf->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0025));
case cmPolicies::NEW:
// NEW behavior is to keep AppleClang.
@@ -854,7 +956,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
}
}
- if (strcmp(compilerId, "QCC") == 0) {
+ if (compilerId == "QCC") {
switch (mf->GetPolicyStatus(cmPolicies::CMP0047)) {
case cmPolicies::WARN:
if (!this->CMakeInstance->GetIsInTryCompile() &&
@@ -863,10 +965,10 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
/* clang-format off */
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0047) << "\n"
"Converting " << lang <<
- " compiler id \"QCC\" to \"GNU\" for compatibility."
+ R"( compiler id "QCC" to "GNU" for compatibility.)"
;
/* clang-format on */
- mf->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -881,7 +983,7 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
mf->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0047));
CM_FALLTHROUGH;
case cmPolicies::NEW:
@@ -889,6 +991,36 @@ void cmGlobalGenerator::CheckCompilerIdCompatibility(
break;
}
}
+
+ if (compilerId == "XLClang") {
+ switch (mf->GetPolicyStatus(cmPolicies::CMP0089)) {
+ case cmPolicies::WARN:
+ if (!this->CMakeInstance->GetIsInTryCompile() &&
+ mf->PolicyOptionalWarningEnabled("CMAKE_POLICY_WARNING_CMP0089")) {
+ std::ostringstream w;
+ /* clang-format off */
+ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0089) << "\n"
+ "Converting " << lang <<
+ R"( compiler id "XLClang" to "XL" for compatibility.)"
+ ;
+ /* clang-format on */
+ mf->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
+ }
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ // OLD behavior is to convert XLClang to XL.
+ mf->AddDefinition(compilerIdVar, "XL");
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ mf->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0089));
+ case cmPolicies::NEW:
+ // NEW behavior is to keep AppleClang.
+ break;
+ }
+ }
}
std::string cmGlobalGenerator::GetLanguageOutputExtension(
@@ -896,15 +1028,13 @@ std::string cmGlobalGenerator::GetLanguageOutputExtension(
{
const std::string& lang = source.GetLanguage();
if (!lang.empty()) {
- std::map<std::string, std::string>::const_iterator it =
- this->LanguageToOutputExtension.find(lang);
-
+ auto const 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
+ // output 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()) {
@@ -923,8 +1053,7 @@ std::string cmGlobalGenerator::GetLanguageFromExtension(const char* ext) const
if (ext && *ext == '.') {
++ext;
}
- std::map<std::string, std::string>::const_iterator it =
- this->ExtensionToLanguage.find(ext);
+ auto const it = this->ExtensionToLanguage.find(ext);
if (it != this->ExtensionToLanguage.end()) {
return it->second;
}
@@ -994,7 +1123,7 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
if (preference < 0) {
std::string msg = linkerPrefVar;
msg += " is negative, adjusting it to 0";
- cmSystemTools::Message(msg.c_str(), "Warning");
+ cmSystemTools::Message(msg, "Warning");
preference = 0;
}
@@ -1021,9 +1150,8 @@ void cmGlobalGenerator::SetLanguageEnabledMaps(const std::string& l,
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;
+ for (std::string const& i : extensionList) {
+ this->IgnoreExtensions[i] = true;
}
}
@@ -1032,12 +1160,11 @@ void cmGlobalGenerator::FillExtensionToLanguageMap(const std::string& l,
{
std::string extensionsVar = std::string("CMAKE_") + std::string(l) +
std::string("_SOURCE_FILE_EXTENSIONS");
- std::string exts = mf->GetSafeDefinition(extensionsVar);
+ const 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;
+ for (std::string const& i : extensionList) {
+ this->ExtensionToLanguage[i] = l;
}
}
@@ -1053,7 +1180,7 @@ bool cmGlobalGenerator::GlobalSettingIsOn(std::string const& name) const
return this->Makefiles[0]->IsOn(name);
}
-const char* cmGlobalGenerator::GetSafeGlobalSetting(
+std::string cmGlobalGenerator::GetSafeGlobalSetting(
std::string const& name) const
{
assert(!this->Makefiles.empty());
@@ -1075,17 +1202,19 @@ bool cmGlobalGenerator::GetLanguageEnabled(const std::string& l) const
void cmGlobalGenerator::ClearEnabledLanguages()
{
- return this->CMakeInstance->GetState()->ClearEnabledLanguages();
+ this->CMakeInstance->GetState()->ClearEnabledLanguages();
}
void cmGlobalGenerator::CreateLocalGenerators()
{
+ this->LocalGeneratorSearchIndex.clear();
cmDeleteAll(this->LocalGenerators);
this->LocalGenerators.clear();
this->LocalGenerators.reserve(this->Makefiles.size());
- for (std::vector<cmMakefile*>::const_iterator it = this->Makefiles.begin();
- it != this->Makefiles.end(); ++it) {
- this->LocalGenerators.push_back(this->CreateLocalGenerator(*it));
+ for (cmMakefile* m : this->Makefiles) {
+ cmLocalGenerator* lg = this->CreateLocalGenerator(m);
+ this->LocalGenerators.push_back(lg);
+ this->IndexLocalGenerator(lg);
}
}
@@ -1102,6 +1231,7 @@ void cmGlobalGenerator::Configure()
this->CMakeInstance->GetHomeOutputDirectory());
cmMakefile* dirMf = new cmMakefile(this, snapshot);
+ dirMf->SetRecursionDepth(this->RecursionDepth);
this->Makefiles.push_back(dirMf);
this->IndexMakefile(dirMf);
@@ -1116,16 +1246,16 @@ void cmGlobalGenerator::Configure()
this->ConfigureDoneCMP0026AndCMP0024 = true;
// Put a copy of each global target in every directory.
- std::vector<GlobalTargetInfo> globalTargets;
- this->CreateDefaultGlobalTargets(globalTargets);
-
- for (unsigned int i = 0; i < this->Makefiles.size(); ++i) {
- cmMakefile* mf = this->Makefiles[i];
- cmTargets* targets = &(mf->GetTargets());
- for (std::vector<GlobalTargetInfo>::iterator gti = globalTargets.begin();
- gti != globalTargets.end(); ++gti) {
- targets->insert(
- cmTargets::value_type(gti->Name, this->CreateGlobalTarget(*gti, mf)));
+ {
+ std::vector<GlobalTargetInfo> globalTargets;
+ this->CreateDefaultGlobalTargets(globalTargets);
+
+ for (cmMakefile* mf : this->Makefiles) {
+ auto& targets = mf->GetTargets();
+ for (GlobalTargetInfo const& globalTarget : globalTargets) {
+ targets.emplace(globalTarget.Name,
+ this->CreateGlobalTarget(globalTarget, mf));
+ }
}
}
@@ -1145,20 +1275,20 @@ void cmGlobalGenerator::Configure()
std::ostringstream msg;
if (cmSystemTools::GetErrorOccuredFlag()) {
msg << "Configuring incomplete, errors occurred!";
- const char* logs[] = { "CMakeOutput.log", "CMakeError.log", CM_NULLPTR };
+ const char* logs[] = { "CMakeOutput.log", "CMakeError.log", nullptr };
for (const char** log = logs; *log; ++log) {
std::string f = this->CMakeInstance->GetHomeOutputDirectory();
- f += this->CMakeInstance->GetCMakeFilesDirectory();
+ f += "/CMakeFiles";
f += "/";
f += *log;
- if (cmSystemTools::FileExists(f.c_str())) {
+ if (cmSystemTools::FileExists(f)) {
msg << "\nSee also \"" << f << "\".";
}
}
} else {
msg << "Configuring done";
}
- this->CMakeInstance->UpdateProgress(msg.str().c_str(), -1);
+ this->CMakeInstance->UpdateProgress(msg.str(), -1);
}
}
@@ -1174,13 +1304,12 @@ void cmGlobalGenerator::CreateImportedGenerationObjects(
std::vector<const cmGeneratorTarget*>& exports)
{
this->CreateGenerationObjects(ImportedOnly);
- std::vector<cmMakefile*>::iterator mfit =
+ auto const mfit =
std::find(this->Makefiles.begin(), this->Makefiles.end(), mf);
cmLocalGenerator* lg =
this->LocalGenerators[std::distance(this->Makefiles.begin(), mfit)];
- for (std::vector<std::string>::const_iterator it = targets.begin();
- it != targets.end(); ++it) {
- cmGeneratorTarget* gt = lg->FindGeneratorTargetToUse(*it);
+ for (std::string const& t : targets) {
+ cmGeneratorTarget* gt = lg->FindGeneratorTargetToUse(t);
if (gt) {
exports.push_back(gt);
}
@@ -1190,9 +1319,8 @@ void cmGlobalGenerator::CreateImportedGenerationObjects(
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() ? CM_NULLPTR : it->second;
+ auto const it = this->BuildExportSets.find(filename);
+ return it == this->BuildExportSets.end() ? nullptr : it->second;
}
void cmGlobalGenerator::AddCMP0042WarnTarget(const std::string& target)
@@ -1221,7 +1349,7 @@ bool cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const
<< "duplicate custom targets. "
<< "Consider using a Makefiles generator or fix the project to not "
<< "use duplicate target names.";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return false;
}
@@ -1230,10 +1358,8 @@ void cmGlobalGenerator::ComputeBuildFileGenerators()
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
std::vector<cmExportBuildFileGenerator*> gens =
this->Makefiles[i]->GetExportBuildFileGenerators();
- for (std::vector<cmExportBuildFileGenerator*>::const_iterator it =
- gens.begin();
- it != gens.end(); ++it) {
- (*it)->Compute(this->LocalGenerators[i]);
+ for (cmExportBuildFileGenerator* g : gens) {
+ g->Compute(this->LocalGenerators[i]);
}
}
}
@@ -1261,18 +1387,14 @@ bool cmGlobalGenerator::Compute()
// so create the map from project name to vector of local generators
this->FillProjectMap();
-#ifdef CMAKE_BUILD_WITH_CMAKE
- // Iterate through all targets and set up automoc for those which have
- // the AUTOMOC, AUTOUIC or AUTORCC property set
- std::vector<cmGeneratorTarget const*> autogenTargets =
- this->CreateQtAutoGeneratorsTargets();
-#endif
-
- unsigned int i;
+ // Iterate through all targets and set up AUTOMOC, AUTOUIC and AUTORCC
+ if (!this->QtAutoGen()) {
+ return false;
+ }
// Add generator specific helper commands
- for (i = 0; i < this->LocalGenerators.size(); ++i) {
- this->LocalGenerators[i]->AddHelperCommands();
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ localGen->AddHelperCommands();
}
// Finalize the set of compile features for each target.
@@ -1281,26 +1403,18 @@ bool cmGlobalGenerator::Compute()
// on the original cmTarget instance. It accumulates features
// across all configurations. Some refactoring is needed to
// compute a per-config resulta purely during generation.
- for (i = 0; i < this->LocalGenerators.size(); ++i) {
- if (!this->LocalGenerators[i]->ComputeTargetCompileFeatures()) {
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ if (!localGen->ComputeTargetCompileFeatures()) {
return false;
}
}
-#ifdef CMAKE_BUILD_WITH_CMAKE
- for (std::vector<cmGeneratorTarget const*>::iterator it =
- autogenTargets.begin();
- it != autogenTargets.end(); ++it) {
- cmQtAutoGeneratorInitializer::SetupAutoGenerateTarget(*it);
- }
-#endif
-
- for (i = 0; i < this->LocalGenerators.size(); ++i) {
- cmMakefile* mf = this->LocalGenerators[i]->GetMakefile();
- std::vector<cmInstallGenerator*>& gens = mf->GetInstallGenerators();
- for (std::vector<cmInstallGenerator*>::const_iterator git = gens.begin();
- git != gens.end(); ++git) {
- (*git)->Compute(this->LocalGenerators[i]);
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ cmMakefile* mf = localGen->GetMakefile();
+ for (cmInstallGenerator* g : mf->GetInstallGenerators()) {
+ if (!g->Compute(localGen)) {
+ return false;
+ }
}
}
@@ -1308,15 +1422,20 @@ bool cmGlobalGenerator::Compute()
// 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();
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ localGen->TraceDependencies();
+ }
+
+ // Make sure that all (non-imported) targets have source files added!
+ if (this->CheckTargetsForMissingSources()) {
+ return false;
}
this->ForceLinkerLanguages();
// Compute the manifest of main targets generated.
- for (i = 0; i < this->LocalGenerators.size(); ++i) {
- this->LocalGenerators[i]->ComputeTargetManifest();
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ localGen->ComputeTargetManifest();
}
// Compute the inter-target dependencies.
@@ -1324,8 +1443,12 @@ bool cmGlobalGenerator::Compute()
return false;
}
- for (i = 0; i < this->LocalGenerators.size(); ++i) {
- this->LocalGenerators[i]->ComputeHomeRelativeOutputPath();
+ if (this->CheckTargetsForType()) {
+ return false;
+ }
+
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ localGen->ComputeHomeRelativeOutputPath();
}
return true;
@@ -1349,22 +1472,21 @@ void cmGlobalGenerator::Generate()
}
this->LocalGenerators[i]->GenerateTestFiles();
this->CMakeInstance->UpdateProgress(
- "Generating", (static_cast<float>(i) + 1.0f) /
+ "Generating",
+ (static_cast<float>(i) + 1.0f) /
static_cast<float>(this->LocalGenerators.size()));
}
- this->SetCurrentMakefile(CM_NULLPTR);
+ this->SetCurrentMakefile(nullptr);
if (!this->GenerateCPackPropertiesFile()) {
this->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR, "Could not write CPack properties file.");
+ MessageType::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()) {
+ for (auto& buildExpSet : this->BuildExportSets) {
+ if (!buildExpSet.second->GenerateImportFile()) {
if (!cmSystemTools::GetErrorOccuredFlag()) {
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR,
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
"Could not write export file.");
}
return;
@@ -1375,7 +1497,7 @@ void cmGlobalGenerator::Generate()
this->WriteSummary();
- if (this->ExtraGenerator != CM_NULLPTR) {
+ if (this->ExtraGenerator != nullptr) {
this->ExtraGenerator->Generate();
}
@@ -1384,12 +1506,11 @@ void cmGlobalGenerator::Generate()
w << cmPolicies::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";
+ for (std::string const& t : this->CMP0042WarnTargets) {
+ w << " " << t << "\n";
}
- this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING,
+ w.str());
}
if (!this->CMP0068WarnTargets.empty()) {
@@ -1402,12 +1523,11 @@ void cmGlobalGenerator::Generate()
"settings:\n"
;
/* clang-format on */
- for (std::set<std::string>::iterator iter =
- this->CMP0068WarnTargets.begin();
- iter != this->CMP0068WarnTargets.end(); ++iter) {
- w << " " << *iter << "\n";
+ for (std::string const& t : this->CMP0068WarnTargets) {
+ w << " " << t << "\n";
}
- this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING,
+ w.str());
}
this->CMakeInstance->UpdateProgress("Generating done", -1);
@@ -1419,69 +1539,20 @@ bool cmGlobalGenerator::ComputeTargetDepends()
if (!ctd.Compute()) {
return false;
}
- std::vector<cmGeneratorTarget const*> const& targets = ctd.GetTargets();
- for (std::vector<cmGeneratorTarget const*>::const_iterator ti =
- targets.begin();
- ti != targets.end(); ++ti) {
- ctd.GetTargetDirectDepends(*ti, this->TargetDependencies[*ti]);
+ for (cmGeneratorTarget const* target : ctd.GetTargets()) {
+ ctd.GetTargetDirectDepends(target, this->TargetDependencies[target]);
}
return true;
}
-std::vector<const cmGeneratorTarget*>
-cmGlobalGenerator::CreateQtAutoGeneratorsTargets()
+bool cmGlobalGenerator::QtAutoGen()
{
- std::vector<const cmGeneratorTarget*> autogenTargets;
-
#ifdef CMAKE_BUILD_WITH_CMAKE
- for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
- std::vector<cmGeneratorTarget*> targets =
- this->LocalGenerators[i]->GetGeneratorTargets();
- std::vector<cmGeneratorTarget*> filteredTargets;
- filteredTargets.reserve(targets.size());
- for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- if ((*ti)->GetType() == cmStateEnums::GLOBAL_TARGET) {
- continue;
- }
- if ((*ti)->GetType() != cmStateEnums::EXECUTABLE &&
- (*ti)->GetType() != cmStateEnums::STATIC_LIBRARY &&
- (*ti)->GetType() != cmStateEnums::SHARED_LIBRARY &&
- (*ti)->GetType() != cmStateEnums::MODULE_LIBRARY &&
- (*ti)->GetType() != cmStateEnums::OBJECT_LIBRARY) {
- continue;
- }
- if ((!(*ti)->GetPropertyAsBool("AUTOMOC") &&
- !(*ti)->GetPropertyAsBool("AUTOUIC") &&
- !(*ti)->GetPropertyAsBool("AUTORCC")) ||
- (*ti)->IsImported()) {
- continue;
- }
- // don't do anything if there is no Qt4 or Qt5Core (which contains moc):
- cmMakefile* mf = (*ti)->Target->GetMakefile();
- std::string qtMajorVersion = mf->GetSafeDefinition("QT_VERSION_MAJOR");
- if (qtMajorVersion == "") {
- qtMajorVersion = mf->GetSafeDefinition("Qt5Core_VERSION_MAJOR");
- }
- if (qtMajorVersion != "4" && qtMajorVersion != "5") {
- continue;
- }
-
- cmGeneratorTarget* gt = *ti;
-
- cmQtAutoGeneratorInitializer::InitializeAutogenSources(gt);
- filteredTargets.push_back(gt);
- }
- for (std::vector<cmGeneratorTarget*>::iterator ti =
- filteredTargets.begin();
- ti != filteredTargets.end(); ++ti) {
- cmQtAutoGeneratorInitializer::InitializeAutogenTarget(
- this->LocalGenerators[i], *ti);
- autogenTargets.push_back(*ti);
- }
- }
+ cmQtAutoGenGlobalInitializer initializer(this->LocalGenerators);
+ return initializer.generate();
+#else
+ return true;
#endif
- return autogenTargets;
}
cmLinkLineComputer* cmGlobalGenerator::CreateLinkLineComputer(
@@ -1502,17 +1573,14 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
this->CMakeInstance->GetState()->GetEnabledLanguages();
// Construct per-target generator information.
- for (unsigned int i = 0; i < this->Makefiles.size(); ++i) {
- cmMakefile* mf = this->Makefiles[i];
-
+ for (cmMakefile* mf : this->Makefiles) {
const cmStringRange noconfig_compile_definitions =
mf->GetCompileDefinitionsEntries();
const cmBacktraceRange noconfig_compile_definitions_bts =
mf->GetCompileDefinitionsBacktraces();
- cmTargets& targets = mf->GetTargets();
- for (cmTargets::iterator ti = targets.begin(); ti != targets.end(); ++ti) {
- cmTarget* t = &ti->second;
+ for (auto& target : mf->GetTargets()) {
+ cmTarget* t = &target.second;
if (t->GetType() == cmStateEnums::GLOBAL_TARGET) {
continue;
}
@@ -1523,12 +1591,12 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
continue;
}
- cmBacktraceRange::const_iterator btIt =
- noconfig_compile_definitions_bts.begin();
- for (cmStringRange::const_iterator
- it = noconfig_compile_definitions.begin();
- it != noconfig_compile_definitions.end(); ++it, ++btIt) {
- t->InsertCompileDefinition(*it, *btIt);
+ {
+ auto btIt = noconfig_compile_definitions_bts.begin();
+ auto it = noconfig_compile_definitions.begin();
+ for (; it != noconfig_compile_definitions.end(); ++it, ++btIt) {
+ t->InsertCompileDefinition(*it, *btIt);
+ }
}
cmPolicies::PolicyStatus polSt =
@@ -1537,10 +1605,9 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
std::vector<std::string> configs;
mf->GetConfigurations(configs);
- for (std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci) {
+ for (std::string const& c : configs) {
std::string defPropName = "COMPILE_DEFINITIONS_";
- defPropName += cmSystemTools::UpperCase(*ci);
+ defPropName += cmSystemTools::UpperCase(c);
t->AppendProperty(defPropName, mf->GetProperty(defPropName));
}
}
@@ -1549,11 +1616,10 @@ void cmGlobalGenerator::FinalizeTargetCompileInfo()
// The standard include directories for each language
// should be treated as system include directories.
std::set<std::string> standardIncludesSet;
- for (std::vector<std::string>::const_iterator li = langs.begin();
- li != langs.end(); ++li) {
+ for (std::string const& li : langs) {
std::string const standardIncludesVar =
- "CMAKE_" + *li + "_STANDARD_INCLUDE_DIRECTORIES";
- std::string const standardIncludesStr =
+ "CMAKE_" + li + "_STANDARD_INCLUDE_DIRECTORIES";
+ std::string const& standardIncludesStr =
mf->GetSafeDefinition(standardIncludesVar);
std::vector<std::string> standardIncludesVec;
cmSystemTools::ExpandListArgument(standardIncludesStr,
@@ -1570,19 +1636,15 @@ void cmGlobalGenerator::CreateGeneratorTargets(
std::map<cmTarget*, cmGeneratorTarget*> const& importedMap)
{
if (targetTypes == AllTargets) {
- cmTargets& targets = mf->GetTargets();
- for (cmTargets::iterator ti = targets.begin(); ti != targets.end(); ++ti) {
- cmTarget* t = &ti->second;
+ for (auto& target : mf->GetTargets()) {
+ cmTarget* t = &target.second;
cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg);
lg->AddGeneratorTarget(gt);
}
}
- std::vector<cmTarget*> itgts = mf->GetImportedTargets();
-
- for (std::vector<cmTarget*>::const_iterator j = itgts.begin();
- j != itgts.end(); ++j) {
- lg->AddImportedGeneratorTarget(importedMap.find(*j)->second);
+ for (cmTarget* t : mf->GetImportedTargets()) {
+ lg->AddImportedGeneratorTarget(importedMap.find(t)->second);
}
}
@@ -1591,13 +1653,11 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes)
std::map<cmTarget*, cmGeneratorTarget*> importedMap;
for (unsigned int i = 0; i < this->Makefiles.size(); ++i) {
cmMakefile* mf = this->Makefiles[i];
- for (std::vector<cmTarget*>::const_iterator j =
- mf->GetOwnedImportedTargets().begin();
- j != mf->GetOwnedImportedTargets().end(); ++j) {
+ for (cmTarget* ownedImpTgt : mf->GetOwnedImportedTargets()) {
cmLocalGenerator* lg = this->LocalGenerators[i];
- cmGeneratorTarget* gt = new cmGeneratorTarget(*j, lg);
+ cmGeneratorTarget* gt = new cmGeneratorTarget(ownedImpTgt, lg);
lg->AddOwnedImportedGeneratorTarget(gt);
- importedMap[*j] = gt;
+ importedMap[ownedImpTgt] = gt;
}
}
@@ -1619,11 +1679,13 @@ void cmGlobalGenerator::ClearGeneratorMembers()
cmDeleteAll(this->LocalGenerators);
this->LocalGenerators.clear();
+ this->AliasTargets.clear();
this->ExportSets.clear();
this->TargetDependencies.clear();
this->TargetSearchIndex.clear();
this->GeneratorTargetSearchIndex.clear();
this->MakefileSearchIndex.clear();
+ this->LocalGeneratorSearchIndex.clear();
this->ProjectMap.clear();
this->RuleHashes.clear();
this->DirectoryContentMap.clear();
@@ -1643,31 +1705,28 @@ void cmGlobalGenerator::CheckTargetProperties()
cmState* state = this->GetCMakeInstance()->GetState();
for (unsigned int i = 0; i < this->Makefiles.size(); ++i) {
this->Makefiles[i]->ConfigureFinalPass();
- cmTargets& targets = this->Makefiles[i]->GetTargets();
- for (cmTargets::iterator l = targets.begin(); l != targets.end(); l++) {
- if (l->second.GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (auto const& target : this->Makefiles[i]->GetTargets()) {
+ if (target.second.GetType() == cmStateEnums::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);
+ for (auto const& lib : target.second.GetOriginalLinkLibraries()) {
+ if (lib.first.size() > 9 &&
+ cmSystemTools::IsNOTFOUND(lib.first.c_str())) {
+ std::string varName = lib.first.substr(0, lib.first.size() - 9);
if (state->GetCacheEntryPropertyAsBool(varName, "ADVANCED")) {
varName += " (ADVANCED)";
}
std::string text = notFoundMap[varName];
text += "\n linked by target \"";
- text += l->second.GetName();
+ text += target.second.GetName();
text += "\" in directory ";
text += this->Makefiles[i]->GetCurrentSourceDirectory();
notFoundMap[varName] = text;
}
}
std::vector<std::string> incs;
- const char* incDirProp = l->second.GetProperty("INCLUDE_DIRECTORIES");
+ const char* incDirProp =
+ target.second.GetProperty("INCLUDE_DIRECTORIES");
if (!incDirProp) {
continue;
}
@@ -1677,10 +1736,9 @@ void cmGlobalGenerator::CheckTargetProperties()
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);
+ for (std::string const& incDir : incs) {
+ if (incDir.size() > 9 && cmSystemTools::IsNOTFOUND(incDir.c_str())) {
+ std::string varName = incDir.substr(0, incDir.size() - 9);
if (state->GetCacheEntryPropertyAsBool(varName, "ADVANCED")) {
varName += " (ADVANCED)";
}
@@ -1692,29 +1750,28 @@ void cmGlobalGenerator::CheckTargetProperties()
}
}
this->CMakeInstance->UpdateProgress(
- "Configuring", 0.9f +
+ "Configuring",
+ 0.9f +
0.1f * (static_cast<float>(i) + 1.0f) /
static_cast<float>(this->Makefiles.size()));
}
if (!notFoundMap.empty()) {
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;
+ for (auto const& notFound : notFoundMap) {
+ notFoundVars += notFound.first;
+ notFoundVars += notFound.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());
+ "tested correctly in the CMake files:\n" +
+ notFoundVars);
}
}
-int cmGlobalGenerator::TryCompile(const std::string& srcdir,
+int cmGlobalGenerator::TryCompile(int jobs, const std::string& srcdir,
const std::string& bindir,
const std::string& projectName,
const std::string& target, bool fast,
@@ -1738,47 +1795,45 @@ int cmGlobalGenerator::TryCompile(const std::string& srcdir,
this->FirstTimeProgress);
}
- std::string newTarget;
+ std::vector<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
+ newTarget = { target };
}
std::string config =
mf->GetSafeDefinition("CMAKE_TRY_COMPILE_CONFIGURATION");
- return this->Build(srcdir, bindir, projectName, newTarget, output, "",
+ return this->Build(jobs, srcdir, bindir, projectName, newTarget, output, "",
config, false, fast, false, this->TryCompileTimeout);
}
-void cmGlobalGenerator::GenerateBuildCommand(
- std::vector<std::string>& makeCommand, const std::string& /*unused*/,
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalGenerator::GenerateBuildCommand(
const std::string& /*unused*/, const std::string& /*unused*/,
- const std::string& /*unused*/, const std::string& /*unused*/,
- bool /*unused*/, bool /*unused*/, std::vector<std::string> const& /*unused*/)
+ const std::string& /*unused*/, std::vector<std::string> const& /*unused*/,
+ const std::string& /*unused*/, bool /*unused*/, int /*unused*/,
+ bool /*unused*/, std::vector<std::string> const& /*unused*/)
+{
+ GeneratedMakeCommand makeCommand;
+ makeCommand.Add("cmGlobalGenerator::GenerateBuildCommand not implemented");
+ return { std::move(makeCommand) };
+}
+
+void cmGlobalGenerator::PrintBuildCommandAdvice(std::ostream& /*os*/,
+ int /*jobs*/) const
{
- makeCommand.push_back(
- "cmGlobalGenerator::GenerateBuildCommand not implemented");
+ // Subclasses override this method if they e.g want to give a warning that
+ // they do not support certain build command line options
}
-int cmGlobalGenerator::Build(const std::string& /*unused*/,
- 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,
- bool verbose, double timeout,
- cmSystemTools::OutputOption outputflag,
- std::vector<std::string> const& nativeOptions)
+int cmGlobalGenerator::Build(
+ int jobs, const std::string& /*unused*/, const std::string& bindir,
+ const std::string& projectName, const std::vector<std::string>& targets,
+ std::string& output, const std::string& makeCommandCSTR,
+ const std::string& config, bool clean, bool fast, bool verbose,
+ cmDuration timeout, cmSystemTools::OutputOption outputflag,
+ std::vector<std::string> const& nativeOptions)
{
+ bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
+
/**
* Run an executable command and put the stdout in output.
*/
@@ -1786,37 +1841,49 @@ int cmGlobalGenerator::Build(const std::string& /*unused*/,
output += "Change Dir: ";
output += bindir;
output += "\n";
+ if (workdir.Failed()) {
+ cmSystemTools::SetRunCommandHideConsole(hideconsole);
+ std::string err = "Failed to change directory: ";
+ err += std::strerror(workdir.GetLastResult());
+ cmSystemTools::Error(err);
+ output += err;
+ output += "\n";
+ return 1;
+ }
- int retVal;
- bool hideconsole = cmSystemTools::GetRunCommandHideConsole();
+ int retVal = 0;
cmSystemTools::SetRunCommandHideConsole(true);
std::string outputBuffer;
std::string* outputPtr = &outputBuffer;
- std::vector<std::string> makeCommand;
- this->GenerateBuildCommand(makeCommand, makeCommandCSTR, projectName, bindir,
- target, config, fast, verbose, nativeOptions);
+ std::vector<GeneratedMakeCommand> makeCommand =
+ this->GenerateBuildCommand(makeCommandCSTR, projectName, bindir, targets,
+ config, fast, jobs, verbose, nativeOptions);
- // Workaround to convince VCExpress.exe to produce output.
+ // Workaround to convince some commands to produce output.
if (outputflag == cmSystemTools::OUTPUT_PASSTHROUGH &&
- !makeCommand.empty() &&
- cmSystemTools::LowerCase(
- cmSystemTools::GetFilenameName(makeCommand[0])) == "vcexpress.exe") {
+ makeCommand.back().RequiresOutputForward) {
outputflag = cmSystemTools::OUTPUT_FORWARD;
}
// should we do a clean first?
if (clean) {
- std::vector<std::string> cleanCommand;
- this->GenerateBuildCommand(cleanCommand, makeCommandCSTR, projectName,
- bindir, "clean", config, fast, verbose);
+ std::vector<GeneratedMakeCommand> cleanCommand =
+ this->GenerateBuildCommand(makeCommandCSTR, projectName, bindir,
+ { "clean" }, config, fast, jobs, verbose);
output += "\nRun Clean Command:";
- output += cmSystemTools::PrintSingleCommand(cleanCommand);
+ output += cleanCommand.front().Printable();
output += "\n";
-
- if (!cmSystemTools::RunSingleCommand(cleanCommand, outputPtr, outputPtr,
- &retVal, CM_NULLPTR, outputflag,
- timeout)) {
+ if (cleanCommand.size() != 1) {
+ this->GetCMakeInstance()->IssueMessage(MessageType::INTERNAL_ERROR,
+ "The generator did not produce "
+ "exactly one command for the "
+ "'clean' target");
+ return 1;
+ }
+ if (!cmSystemTools::RunSingleCommand(cleanCommand.front().PrimaryCommand,
+ outputPtr, outputPtr, &retVal,
+ nullptr, outputflag, timeout)) {
cmSystemTools::SetRunCommandHideConsole(hideconsole);
cmSystemTools::Error("Generator: execution of make clean failed.");
output += *outputPtr;
@@ -1828,43 +1895,61 @@ int cmGlobalGenerator::Build(const std::string& /*unused*/,
}
// now build
- std::string makeCommandStr = cmSystemTools::PrintSingleCommand(makeCommand);
- output += "\nRun Build Command:";
- output += makeCommandStr;
- output += "\n";
+ std::string makeCommandStr;
+ output += "\nRun Build Command(s):";
- if (!cmSystemTools::RunSingleCommand(makeCommand, outputPtr, outputPtr,
- &retVal, CM_NULLPTR, 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";
+ for (auto command = makeCommand.begin(); command != makeCommand.end();
+ ++command) {
+ makeCommandStr = command->Printable();
+ if (command != makeCommand.end()) {
+ makeCommandStr += " && ";
+ }
- return 1;
+ output += makeCommandStr;
+ if (!cmSystemTools::RunSingleCommand(command->PrimaryCommand, outputPtr,
+ outputPtr, &retVal, nullptr,
+ outputflag, timeout)) {
+ cmSystemTools::SetRunCommandHideConsole(hideconsole);
+ cmSystemTools::Error(
+ "Generator: execution of make failed. Make command was: " +
+ makeCommandStr);
+ output += *outputPtr;
+ output += "\nGenerator: execution of make failed. Make command was: " +
+ makeCommandStr + "\n";
+
+ return 1;
+ }
+ output += *outputPtr;
}
- output += *outputPtr;
+ output += "\n";
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)) {
+ // The OpenWatcom tools do not return an error code when a link
+ // library is not found!
+ if (this->CMakeInstance->GetState()->UseWatcomWMake() && retVal == 0 &&
+ output.find("W1008: cannot open") != std::string::npos) {
retVal = 1;
}
return retVal;
}
+bool cmGlobalGenerator::Open(const std::string& bindir,
+ const std::string& projectName, bool dryRun)
+{
+ if (this->ExtraGenerator) {
+ return this->ExtraGenerator->Open(bindir, projectName, dryRun);
+ }
+
+ return false;
+}
+
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 = cmSystemTools::ConvertToOutputPath(makeCommand);
makeCommand += " --build .";
if (!config.empty()) {
makeCommand += " --config \"";
@@ -1899,7 +1984,7 @@ void cmGlobalGenerator::AddMakefile(cmMakefile* mf)
// update progress
// estimate how many lg there will be
- const char* numGenC =
+ const std::string* numGenC =
this->CMakeInstance->GetState()->GetInitializedCacheValue(
"CMAKE_NUMBER_OF_MAKEFILES");
@@ -1917,7 +2002,7 @@ void cmGlobalGenerator::AddMakefile(cmMakefile* mf)
return;
}
- int numGen = atoi(numGenC);
+ int numGen = atoi(numGenC->c_str());
float prog = 0.9f * static_cast<float>(this->Makefiles.size()) /
static_cast<float>(numGen);
if (prog > 0.9f) {
@@ -1926,9 +2011,9 @@ void cmGlobalGenerator::AddMakefile(cmMakefile* mf)
this->CMakeInstance->UpdateProgress("Configuring", prog);
}
-void cmGlobalGenerator::AddInstallComponent(const char* component)
+void cmGlobalGenerator::AddInstallComponent(const std::string& component)
{
- if (component && *component) {
+ if (!component.empty()) {
this->InstallComponents.insert(component);
}
}
@@ -1969,7 +2054,7 @@ void cmGlobalGenerator::SetConfiguredFilesPath(cmGlobalGenerator* gen)
this->ConfiguredFilesPath = gen->ConfiguredFilesPath;
} else {
this->ConfiguredFilesPath = gen->CMakeInstance->GetHomeOutputDirectory();
- this->ConfiguredFilesPath += cmake::GetCMakeFilesDirectory();
+ this->ConfiguredFilesPath += "/CMakeFiles";
}
}
@@ -2006,11 +2091,12 @@ bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
bool cmGlobalGenerator::IsExcluded(cmLocalGenerator* root,
cmGeneratorTarget* target) const
{
- if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
- target->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
- // This target is excluded from its directory.
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
return true;
}
+ if (const char* exclude = target->GetProperty("EXCLUDE_FROM_ALL")) {
+ return cmSystemTools::IsOn(exclude);
+ }
// This target is included in its directory. Check whether the
// directory is excluded.
return this->IsExcluded(root, target->GetLocalGenerator());
@@ -2024,8 +2110,7 @@ void cmGlobalGenerator::GetEnabledLanguages(
int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
{
- std::map<std::string, int>::const_iterator it =
- this->LanguageToLinkerPreference.find(lang);
+ auto const it = this->LanguageToLinkerPreference.find(lang);
if (it != this->LanguageToLinkerPreference.end()) {
return it->second;
}
@@ -2035,16 +2120,15 @@ int cmGlobalGenerator::GetLinkerPreference(const std::string& lang) const
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 (cmLocalGenerator* localGen : this->LocalGenerators) {
// for each local generator add all projects
- cmStateSnapshot snp = this->LocalGenerators[i]->GetStateSnapshot();
+ cmStateSnapshot snp = localGen->GetStateSnapshot();
std::string name;
do {
std::string snpProjName = snp.GetProjectName();
if (name != snpProjName) {
name = snpProjName;
- this->ProjectMap[name].push_back(this->LocalGenerators[i]);
+ this->ProjectMap[name].push_back(localGen);
}
snp = snp.GetBuildsystemDirectoryParent();
} while (snp.IsValid());
@@ -2053,26 +2137,21 @@ void cmGlobalGenerator::FillProjectMap()
cmMakefile* cmGlobalGenerator::FindMakefile(const std::string& start_dir) const
{
- MakefileMap::const_iterator i = this->MakefileSearchIndex.find(start_dir);
- if (i != this->MakefileSearchIndex.end()) {
- return i->second;
+ auto const it = this->MakefileSearchIndex.find(start_dir);
+ if (it != this->MakefileSearchIndex.end()) {
+ return it->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
-///! Find a local generator by its startdirectory
cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator(
- const std::string& start_dir) const
+ cmDirectoryId const& id) const
{
- for (std::vector<cmLocalGenerator*>::const_iterator it =
- this->LocalGenerators.begin();
- it != this->LocalGenerators.end(); ++it) {
- std::string sd = (*it)->GetCurrentSourceDirectory();
- if (sd == start_dir) {
- return *it;
- }
+ auto const it = this->LocalGeneratorSearchIndex.find(id.String);
+ if (it != this->LocalGeneratorSearchIndex.end()) {
+ return it->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
void cmGlobalGenerator::AddAlias(const std::string& name,
@@ -2100,6 +2179,31 @@ void cmGlobalGenerator::IndexGeneratorTarget(cmGeneratorTarget* gt)
}
}
+static char const hexDigits[] = "0123456789abcdef";
+
+std::string cmGlobalGenerator::IndexGeneratorTargetUniquely(
+ cmGeneratorTarget const* gt)
+{
+ // Use the pointer value to uniquely identify the target instance.
+ // Use a ":" prefix to avoid conflict with project-defined targets.
+ // We must satisfy cmGeneratorExpression::IsValidTargetName so use no
+ // other special characters.
+ char buf[1 + sizeof(gt) * 2];
+ char* b = buf;
+ *b++ = ':';
+ for (size_t i = 0; i < sizeof(gt); ++i) {
+ unsigned char const c = reinterpret_cast<unsigned char const*>(&gt)[i];
+ *b++ = hexDigits[(c & 0xf0) >> 4];
+ *b++ = hexDigits[(c & 0x0f)];
+ }
+ std::string id(buf, sizeof(buf));
+ // We internally index pointers to non-const generator targets
+ // but our callers only have pointers to const generator targets.
+ // They will give up non-const privileges when looking up anyway.
+ this->GeneratorTargetSearchIndex[id] = const_cast<cmGeneratorTarget*>(gt);
+ return id;
+}
+
void cmGlobalGenerator::IndexMakefile(cmMakefile* mf)
{
// FIXME: add_subdirectory supports multiple build directories
@@ -2111,32 +2215,36 @@ void cmGlobalGenerator::IndexMakefile(cmMakefile* mf)
MakefileMap::value_type(mf->GetCurrentSourceDirectory(), mf));
}
+void cmGlobalGenerator::IndexLocalGenerator(cmLocalGenerator* lg)
+{
+ cmDirectoryId id = lg->GetMakefile()->GetDirectoryId();
+ this->LocalGeneratorSearchIndex[id.String] = lg;
+}
+
cmTarget* cmGlobalGenerator::FindTargetImpl(std::string const& name) const
{
- TargetMap::const_iterator i = this->TargetSearchIndex.find(name);
- if (i != this->TargetSearchIndex.end()) {
- return i->second;
+ auto const it = this->TargetSearchIndex.find(name);
+ if (it != this->TargetSearchIndex.end()) {
+ return it->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTargetImpl(
std::string const& name) const
{
- GeneratorTargetMap::const_iterator i =
- this->GeneratorTargetSearchIndex.find(name);
- if (i != this->GeneratorTargetSearchIndex.end()) {
- return i->second;
+ auto const it = this->GeneratorTargetSearchIndex.find(name);
+ if (it != this->GeneratorTargetSearchIndex.end()) {
+ return it->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
cmTarget* cmGlobalGenerator::FindTarget(const std::string& name,
bool excludeAliases) const
{
if (!excludeAliases) {
- std::map<std::string, std::string>::const_iterator ai =
- this->AliasTargets.find(name);
+ auto const ai = this->AliasTargets.find(name);
if (ai != this->AliasTargets.end()) {
return this->FindTargetImpl(ai->second);
}
@@ -2147,8 +2255,7 @@ cmTarget* cmGlobalGenerator::FindTarget(const std::string& name,
cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTarget(
const std::string& name) const
{
- std::map<std::string, std::string>::const_iterator ai =
- this->AliasTargets.find(name);
+ auto const ai = this->AliasTargets.find(name);
if (ai != this->AliasTargets.end()) {
return this->FindGeneratorTargetImpl(ai->second);
}
@@ -2158,7 +2265,7 @@ cmGeneratorTarget* cmGlobalGenerator::FindGeneratorTarget(
bool cmGlobalGenerator::NameResolvesToFramework(
const std::string& libname) const
{
- if (cmSystemTools::IsPathToFramework(libname.c_str())) {
+ if (cmSystemTools::IsPathToFramework(libname)) {
return true;
}
@@ -2173,12 +2280,51 @@ bool cmGlobalGenerator::NameResolvesToFramework(
inline std::string removeQuotes(const std::string& s)
{
- if (s[0] == '\"' && s[s.size() - 1] == '\"') {
+ if (s.front() == '\"' && s.back() == '\"') {
return s.substr(1, s.size() - 2);
}
return s;
}
+bool cmGlobalGenerator::CheckCMP0037(std::string const& targetName,
+ std::string const& reason) const
+{
+ cmTarget* tgt = this->FindTarget(targetName);
+ if (!tgt) {
+ return true;
+ }
+ MessageType messageType = MessageType::AUTHOR_WARNING;
+ std::ostringstream e;
+ bool issueMessage = false;
+ switch (tgt->GetPolicyStatusCMP0037()) {
+ case cmPolicies::WARN:
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
+ issueMessage = true;
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = MessageType::FATAL_ERROR;
+ break;
+ }
+ if (issueMessage) {
+ e << "The target name \"" << targetName << "\" is reserved " << reason
+ << ".";
+ if (messageType == MessageType::AUTHOR_WARNING) {
+ e << " It may result in undefined behavior.";
+ }
+ this->GetCMakeInstance()->IssueMessage(messageType, e.str(),
+ tgt->GetBacktrace());
+ if (messageType == MessageType::FATAL_ERROR) {
+ return false;
+ }
+ }
+ return true;
+}
+
void cmGlobalGenerator::CreateDefaultGlobalTargets(
std::vector<GlobalTargetInfo>& targets)
{
@@ -2194,6 +2340,19 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
std::vector<GlobalTargetInfo>& targets)
{
cmMakefile* mf = this->Makefiles[0];
+ std::string configFile = mf->GetCurrentBinaryDirectory();
+ configFile += "/CPackConfig.cmake";
+ if (!cmSystemTools::FileExists(configFile)) {
+ return;
+ }
+
+ static const auto reservedTargets = { "package", "PACKAGE" };
+ for (auto const& target : reservedTargets) {
+ if (!this->CheckCMP0037(target, "when CPack packaging is enabled")) {
+ return;
+ }
+ }
+
const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
GlobalTargetInfo gti;
gti.Name = this->GetPackageTargetName();
@@ -2207,125 +2366,141 @@ void cmGlobalGenerator::AddGlobalTarget_Package(
singleLine.push_back(cmakeCfgIntDir);
}
singleLine.push_back("--config");
- std::string configFile = mf->GetCurrentBinaryDirectory();
- configFile += "/CPackConfig.cmake";
- std::string relConfigFile = "./CPackConfig.cmake";
- singleLine.push_back(relConfigFile);
- gti.CommandLines.push_back(singleLine);
+ singleLine.push_back("./CPackConfig.cmake");
+ gti.CommandLines.push_back(std::move(singleLine));
if (this->GetPreinstallTargetName()) {
- gti.Depends.push_back(this->GetPreinstallTargetName());
+ gti.Depends.emplace_back(this->GetPreinstallTargetName());
} else {
const char* noPackageAll =
mf->GetDefinition("CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY");
if (!noPackageAll || cmSystemTools::IsOff(noPackageAll)) {
- gti.Depends.push_back(this->GetAllTargetName());
+ gti.Depends.emplace_back(this->GetAllTargetName());
}
}
- if (cmSystemTools::FileExists(configFile.c_str())) {
- targets.push_back(gti);
- }
+ targets.push_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_PackageSource(
std::vector<GlobalTargetInfo>& targets)
{
- cmMakefile* mf = this->Makefiles[0];
const char* packageSourceTargetName = this->GetPackageSourceTargetName();
- if (packageSourceTargetName) {
- GlobalTargetInfo gti;
- gti.Name = packageSourceTargetName;
- gti.Message = "Run CPack packaging tool for source...";
- gti.WorkingDir = mf->GetCurrentBinaryDirectory();
- gti.UsesTerminal = true;
- cmCustomCommandLine singleLine;
- singleLine.push_back(cmSystemTools::GetCPackCommand());
- singleLine.push_back("--config");
- std::string configFile = mf->GetCurrentBinaryDirectory();
- configFile += "/CPackSourceConfig.cmake";
- std::string relConfigFile = "./CPackSourceConfig.cmake";
- singleLine.push_back(relConfigFile);
- if (cmSystemTools::FileExists(configFile.c_str())) {
- singleLine.push_back(configFile);
- gti.CommandLines.push_back(singleLine);
- targets.push_back(gti);
+ if (!packageSourceTargetName) {
+ return;
+ }
+
+ cmMakefile* mf = this->Makefiles[0];
+ std::string configFile = mf->GetCurrentBinaryDirectory();
+ configFile += "/CPackSourceConfig.cmake";
+ if (!cmSystemTools::FileExists(configFile)) {
+ return;
+ }
+
+ static const auto reservedTargets = { "package_source" };
+ for (auto const& target : reservedTargets) {
+ if (!this->CheckCMP0037(target,
+ "when CPack source packaging is enabled")) {
+ return;
}
}
+
+ GlobalTargetInfo gti;
+ gti.Name = packageSourceTargetName;
+ gti.Message = "Run CPack packaging tool for source...";
+ gti.WorkingDir = mf->GetCurrentBinaryDirectory();
+ gti.UsesTerminal = true;
+ cmCustomCommandLine singleLine;
+ singleLine.push_back(cmSystemTools::GetCPackCommand());
+ singleLine.push_back("--config");
+ singleLine.push_back("./CPackSourceConfig.cmake");
+ singleLine.push_back(std::move(configFile));
+ gti.CommandLines.push_back(std::move(singleLine));
+ targets.push_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_Test(
std::vector<GlobalTargetInfo>& targets)
{
cmMakefile* mf = this->Makefiles[0];
- const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
- if (mf->IsOn("CMAKE_TESTING_ENABLED")) {
- GlobalTargetInfo gti;
- gti.Name = this->GetTestTargetName();
- gti.Message = "Running tests...";
- gti.UsesTerminal = true;
- cmCustomCommandLine singleLine;
- 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)");
+ if (!mf->IsOn("CMAKE_TESTING_ENABLED")) {
+ return;
+ }
+
+ static const auto reservedTargets = { "test", "RUN_TESTS" };
+ for (auto const& target : reservedTargets) {
+ if (!this->CheckCMP0037(target, "when CTest testing is enabled")) {
+ return;
}
- gti.CommandLines.push_back(singleLine);
- targets.push_back(gti);
}
+
+ const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir();
+ GlobalTargetInfo gti;
+ gti.Name = this->GetTestTargetName();
+ gti.Message = "Running tests...";
+ gti.UsesTerminal = true;
+ cmCustomCommandLine singleLine;
+ 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)");
+ }
+ gti.CommandLines.push_back(std::move(singleLine));
+ targets.push_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_EditCache(
std::vector<GlobalTargetInfo>& targets)
{
const char* editCacheTargetName = this->GetEditCacheTargetName();
- if (editCacheTargetName) {
- GlobalTargetInfo gti;
- gti.Name = editCacheTargetName;
- cmCustomCommandLine singleLine;
-
- // 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)");
- gti.Message = "Running CMake cache editor...";
- gti.UsesTerminal = true;
- gti.CommandLines.push_back(singleLine);
- } else {
- singleLine.push_back(cmSystemTools::GetCMakeCommand());
- singleLine.push_back("-E");
- singleLine.push_back("echo");
- singleLine.push_back("No interactive CMake dialog available.");
- gti.Message = "No interactive CMake dialog available...";
- gti.UsesTerminal = false;
- gti.CommandLines.push_back(singleLine);
- }
+ if (!editCacheTargetName) {
+ return;
+ }
+ GlobalTargetInfo gti;
+ gti.Name = editCacheTargetName;
+ cmCustomCommandLine singleLine;
- targets.push_back(gti);
+ // 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(std::move(edit_cmd));
+ singleLine.push_back("-S$(CMAKE_SOURCE_DIR)");
+ singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
+ gti.Message = "Running CMake cache editor...";
+ gti.UsesTerminal = true;
+ } else {
+ singleLine.push_back(cmSystemTools::GetCMakeCommand());
+ singleLine.push_back("-E");
+ singleLine.push_back("echo");
+ singleLine.push_back("No interactive CMake dialog available.");
+ gti.Message = "No interactive CMake dialog available...";
+ gti.UsesTerminal = false;
}
+ gti.CommandLines.push_back(std::move(singleLine));
+
+ targets.push_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_RebuildCache(
std::vector<GlobalTargetInfo>& targets)
{
const char* rebuildCacheTargetName = this->GetRebuildCacheTargetName();
- if (rebuildCacheTargetName) {
- GlobalTargetInfo gti;
- gti.Name = rebuildCacheTargetName;
- gti.Message = "Running CMake to regenerate build system...";
- gti.UsesTerminal = true;
- cmCustomCommandLine singleLine;
- singleLine.push_back(cmSystemTools::GetCMakeCommand());
- singleLine.push_back("-H$(CMAKE_SOURCE_DIR)");
- singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
- gti.CommandLines.push_back(singleLine);
- targets.push_back(gti);
+ if (!rebuildCacheTargetName) {
+ return;
}
+ GlobalTargetInfo gti;
+ gti.Name = rebuildCacheTargetName;
+ gti.Message = "Running CMake to regenerate build system...";
+ gti.UsesTerminal = true;
+ cmCustomCommandLine singleLine;
+ singleLine.push_back(cmSystemTools::GetCMakeCommand());
+ singleLine.push_back("-S$(CMAKE_SOURCE_DIR)");
+ singleLine.push_back("-B$(CMAKE_BINARY_DIR)");
+ gti.CommandLines.push_back(std::move(singleLine));
+ targets.push_back(std::move(gti));
}
void cmGlobalGenerator::AddGlobalTarget_Install(
@@ -2336,8 +2511,9 @@ void cmGlobalGenerator::AddGlobalTarget_Install(
bool skipInstallRules = mf->IsOn("CMAKE_SKIP_INSTALL_RULES");
if (this->InstallTargetEnabled && skipInstallRules) {
this->CMakeInstance->IssueMessage(
- cmake::WARNING, "CMAKE_SKIP_INSTALL_RULES was enabled even though "
- "installation rules have been specified",
+ MessageType::WARNING,
+ "CMAKE_SKIP_INSTALL_RULES was enabled even though "
+ "installation rules have been specified",
mf->GetBacktrace());
} else if (this->InstallTargetEnabled && !skipInstallRules) {
if (!cmakeCfgIntDir || !*cmakeCfgIntDir || cmakeCfgIntDir[0] == '.') {
@@ -2353,7 +2529,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install(
gti.Name = "list_install_components";
gti.Message = ostr.str();
gti.UsesTerminal = false;
- targets.push_back(gti);
+ targets.push_back(std::move(gti));
}
std::string cmd = cmSystemTools::GetCMakeCommand();
GlobalTargetInfo gti;
@@ -2362,12 +2538,12 @@ void cmGlobalGenerator::AddGlobalTarget_Install(
gti.UsesTerminal = true;
cmCustomCommandLine singleLine;
if (this->GetPreinstallTargetName()) {
- gti.Depends.push_back(this->GetPreinstallTargetName());
+ gti.Depends.emplace_back(this->GetPreinstallTargetName());
} else {
const char* noall =
mf->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
if (!noall || cmSystemTools::IsOff(noall)) {
- gti.Depends.push_back(this->GetAllTargetName());
+ gti.Depends.emplace_back(this->GetAllTargetName());
}
}
if (mf->GetDefinition("CMake_BINARY_DIR") &&
@@ -2407,13 +2583,13 @@ void cmGlobalGenerator::AddGlobalTarget_Install(
localCmdLine.insert(localCmdLine.begin() + 1,
"-DCMAKE_INSTALL_LOCAL_ONLY=1");
- gti.CommandLines.push_back(localCmdLine);
+ gti.CommandLines.push_back(std::move(localCmdLine));
targets.push_back(gti);
}
// install_strip
const char* install_strip = this->GetInstallStripTargetName();
- if ((install_strip != CM_NULLPTR) && (mf->IsSet("CMAKE_STRIP"))) {
+ if ((install_strip != nullptr) && (mf->IsSet("CMAKE_STRIP"))) {
gti.Name = install_strip;
gti.Message = "Installing the project stripped...";
gti.UsesTerminal = true;
@@ -2423,7 +2599,7 @@ void cmGlobalGenerator::AddGlobalTarget_Install(
stripCmdLine.insert(stripCmdLine.begin() + 1,
"-DCMAKE_INSTALL_DO_STRIP=1");
- gti.CommandLines.push_back(stripCmdLine);
+ gti.CommandLines.push_back(std::move(stripCmdLine));
targets.push_back(gti);
}
}
@@ -2470,16 +2646,15 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti,
std::vector<std::string> no_byproducts;
std::vector<std::string> no_depends;
// Store the custom command in the target.
- cmCustomCommand cc(CM_NULLPTR, no_outputs, no_byproducts, no_depends,
- gti.CommandLines, CM_NULLPTR, gti.WorkingDir.c_str());
+ cmCustomCommand cc(nullptr, no_outputs, no_byproducts, no_depends,
+ gti.CommandLines, nullptr, gti.WorkingDir.c_str());
cc.SetUsesTerminal(gti.UsesTerminal);
target.AddPostBuildCommand(cc);
if (!gti.Message.empty()) {
target.SetProperty("EchoString", gti.Message.c_str());
}
- for (std::vector<std::string>::const_iterator dit = gti.Depends.begin();
- dit != gti.Depends.end(); ++dit) {
- target.AddUtility(*dit);
+ for (std::string const& d : gti.Depends) {
+ target.AddUtility(d);
}
// Organize in the "predefined targets" folder:
@@ -2498,22 +2673,20 @@ std::string cmGlobalGenerator::GenerateRuleFile(
ruleFile += ".rule";
const char* dir = this->GetCMakeCFGIntDir();
if (dir && dir[0] == '$') {
- cmSystemTools::ReplaceString(ruleFile, dir,
- cmake::GetCMakeFilesDirectory());
+ cmSystemTools::ReplaceString(ruleFile, dir, "/CMakeFiles");
}
return ruleFile;
}
bool cmGlobalGenerator::ShouldStripResourcePath(cmMakefile* mf) const
{
- return mf->PlatformIsAppleIos();
+ return mf->PlatformIsAppleEmbedded();
}
std::string cmGlobalGenerator::GetSharedLibFlagsForLanguage(
std::string const& l) const
{
- std::map<std::string, std::string>::const_iterator it =
- this->LanguageToOriginalSharedLibFlags.find(l);
+ auto const it = this->LanguageToOriginalSharedLibFlags.find(l);
if (it != this->LanguageToOriginalSharedLibFlags.end()) {
return it->second;
}
@@ -2542,21 +2715,20 @@ bool cmGlobalGenerator::IsReservedTarget(std::string const& name)
// 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"
- };
+ const char* reservedTargets[] = { "all", "ALL_BUILD", "help",
+ "install", "INSTALL", "preinstall",
+ "clean", "edit_cache", "rebuild_cache",
+ "ZERO_CHECK" };
- return std::find(cmArrayBegin(reservedTargets), cmArrayEnd(reservedTargets),
- name) != cmArrayEnd(reservedTargets);
+ return std::find(cm::cbegin(reservedTargets), cm::cend(reservedTargets),
+ name) != cm::cend(reservedTargets);
}
void cmGlobalGenerator::SetExternalMakefileProjectGenerator(
cmExternalMakefileProjectGenerator* extraGenerator)
{
this->ExtraGenerator = extraGenerator;
- if (this->ExtraGenerator != CM_NULLPTR) {
+ if (this->ExtraGenerator != nullptr) {
this->ExtraGenerator->SetGlobalGenerator(this);
}
}
@@ -2587,18 +2759,13 @@ void cmGlobalGenerator::GetTargetSets(TargetDependSet& projectTargets,
GeneratorVector const& generators)
{
// loop over all local generators
- for (std::vector<cmLocalGenerator*>::const_iterator i = generators.begin();
- i != generators.end(); ++i) {
+ for (cmLocalGenerator* generator : generators) {
// check to make sure generator is not excluded
- if (this->IsExcluded(root, *i)) {
+ if (this->IsExcluded(root, generator)) {
continue;
}
- // Get the targets in the makefile
- std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets();
- // loop over all the targets
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); ++l) {
- cmGeneratorTarget* target = *l;
+ // loop over all the generator targets in the makefile
+ for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) {
if (this->IsRootOnlyTarget(target) &&
target->GetLocalGenerator() != root) {
continue;
@@ -2624,9 +2791,8 @@ void cmGlobalGenerator::AddTargetDepends(cmGeneratorTarget const* target,
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) {
- this->AddTargetDepends(*i, projectTargets);
+ for (auto const& t : this->GetTargetDirectDepends(target)) {
+ this->AddTargetDepends(t, projectTargets);
}
}
}
@@ -2686,8 +2852,9 @@ void cmGlobalGenerator::AddRuleHash(const std::vector<std::string>& outputs,
}
// Shorten the output name (in expected use case).
- cmOutputConverter converter(this->GetMakefiles()[0]->GetStateSnapshot());
- std::string fname = converter.ConvertToRelativePath(
+ cmStateDirectory cmDir =
+ this->GetMakefiles()[0]->GetStateSnapshot().GetDirectory();
+ std::string fname = cmDir.ConvertToRelPathIfNotContained(
this->GetMakefiles()[0]->GetState()->GetBinaryDirectory(), outputs[0]);
// Associate the hash with this output.
@@ -2703,7 +2870,7 @@ void cmGlobalGenerator::CheckRuleHashes()
#if defined(CMAKE_BUILD_WITH_CMAKE)
std::string home = this->GetCMakeInstance()->GetHomeOutputDirectory();
std::string pfile = home;
- pfile += this->GetCMakeInstance()->GetCMakeFilesDirectory();
+ pfile += "/CMakeFiles";
pfile += "/CMakeRuleHashes.txt";
this->CheckRuleHashes(pfile, home);
this->WriteRuleHashes(pfile);
@@ -2736,14 +2903,13 @@ void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
fname = line.substr(33);
// Look for a hash for this file's rule.
- std::map<std::string, RuleHash>::const_iterator rhi =
- this->RuleHashes.find(fname);
+ auto const 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, home.c_str());
+ fname = cmSystemTools::CollapseFullPath(fname, home);
cmSystemTools::RemoveFile(fname);
}
} else {
@@ -2753,10 +2919,10 @@ void cmGlobalGenerator::CheckRuleHashes(std::string const& pfile,
// 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, home.c_str());
- if (cmSystemTools::FileExists(fpath.c_str())) {
+ std::string fpath = cmSystemTools::CollapseFullPath(fname, home);
+ if (cmSystemTools::FileExists(fpath)) {
RuleHash hash;
- strncpy(hash.Data, line.c_str(), 32);
+ memcpy(hash.Data, line.c_str(), 32);
this->RuleHashes[fname] = hash;
}
}
@@ -2769,13 +2935,11 @@ void cmGlobalGenerator::WriteRuleHashes(std::string const& pfile)
if (this->RuleHashes.empty()) {
cmSystemTools::RemoveFile(pfile);
} else {
- cmGeneratedFileStream fout(pfile.c_str());
+ cmGeneratedFileStream fout(pfile);
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";
+ for (auto const& rh : this->RuleHashes) {
+ fout.write(rh.second.Data, 32);
+ fout << " " << rh.first << "\n";
}
}
}
@@ -2784,20 +2948,17 @@ void cmGlobalGenerator::WriteSummary()
{
// Record all target directories in a central location.
std::string fname = this->CMakeInstance->GetHomeOutputDirectory();
- fname += cmake::GetCMakeFilesDirectory();
+ fname += "/CMakeFiles";
fname += "/TargetDirectories.txt";
- cmGeneratedFileStream fout(fname.c_str());
+ cmGeneratedFileStream fout(fname);
- for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
- std::vector<cmGeneratorTarget*> tgts =
- this->LocalGenerators[i]->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator it = tgts.begin();
- it != tgts.end(); ++it) {
- if ((*it)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (cmGeneratorTarget* tgt : lg->GetGeneratorTargets()) {
+ if (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- this->WriteSummary(*it);
- fout << (*it)->GetSupportDirectory() << "\n";
+ this->WriteSummary(tgt);
+ fout << tgt->GetSupportDirectory() << "\n";
}
}
}
@@ -2812,47 +2973,77 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
#ifdef CMAKE_BUILD_WITH_CMAKE
// Check whether labels are enabled for this target.
- if (const char* value = target->GetProperty("LABELS")) {
+ const char* targetLabels = target->GetProperty("LABELS");
+ const char* directoryLabels =
+ target->Target->GetMakefile()->GetProperty("LABELS");
+ const char* cmakeDirectoryLabels =
+ target->Target->GetMakefile()->GetDefinition("CMAKE_DIRECTORY_LABELS");
+ if (targetLabels || directoryLabels || cmakeDirectoryLabels) {
Json::Value lj_root(Json::objectValue);
Json::Value& lj_target = lj_root["target"] = Json::objectValue;
lj_target["name"] = target->GetName();
Json::Value& lj_target_labels = lj_target["labels"] = Json::arrayValue;
Json::Value& lj_sources = lj_root["sources"] = Json::arrayValue;
- cmSystemTools::MakeDirectory(dir.c_str());
- cmGeneratedFileStream fout(file.c_str());
+ cmSystemTools::MakeDirectory(dir);
+ cmGeneratedFileStream fout(file);
+
+ std::vector<std::string> labels;
// 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";
- lj_target_labels.append(*li);
+ if (targetLabels) {
+ cmSystemTools::ExpandListArgument(targetLabels, labels);
+ if (!labels.empty()) {
+ fout << "# Target labels\n";
+ for (std::string const& l : labels) {
+ fout << " " << l << "\n";
+ lj_target_labels.append(l);
+ }
}
}
+ // List directory labels
+ std::vector<std::string> directoryLabelsList;
+ std::vector<std::string> cmakeDirectoryLabelsList;
+
+ if (directoryLabels) {
+ cmSystemTools::ExpandListArgument(directoryLabels, directoryLabelsList);
+ }
+
+ if (cmakeDirectoryLabels) {
+ cmSystemTools::ExpandListArgument(cmakeDirectoryLabels,
+ cmakeDirectoryLabelsList);
+ }
+
+ if (!directoryLabelsList.empty() || !cmakeDirectoryLabelsList.empty()) {
+ fout << "# Directory labels\n";
+ }
+
+ for (std::string const& li : directoryLabelsList) {
+ fout << " " << li << "\n";
+ lj_target_labels.append(li);
+ }
+
+ for (std::string const& li : cmakeDirectoryLabelsList) {
+ fout << " " << li << "\n";
+ lj_target_labels.append(li);
+ }
+
// 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->Target->GetMakefile()->GetConfigurations(configs);
if (configs.empty()) {
- configs.push_back("");
+ configs.emplace_back();
}
- for (std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci) {
- target->GetSourceFiles(sources, *ci);
+ for (std::string const& c : configs) {
+ target->GetSourceFiles(sources, c);
}
- std::vector<cmSourceFile*>::const_iterator sourcesEnd =
- cmRemoveDuplicates(sources);
- for (std::vector<cmSourceFile*>::const_iterator si = sources.begin();
- si != sourcesEnd; ++si) {
+ auto const sourcesEnd = cmRemoveDuplicates(sources);
+ for (cmSourceFile* sf : cmMakeRange(sources.cbegin(), sourcesEnd)) {
Json::Value& lj_source = lj_sources.append(Json::objectValue);
- cmSourceFile* sf = *si;
std::string const& sfp = sf->GetFullPath();
fout << sfp << "\n";
lj_source["file"] = sfp;
@@ -2860,14 +3051,13 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
labels.clear();
Json::Value& lj_source_labels = lj_source["labels"] = Json::arrayValue;
cmSystemTools::ExpandListArgument(svalue, labels);
- for (std::vector<std::string>::const_iterator li = labels.begin();
- li != labels.end(); ++li) {
- fout << " " << *li << "\n";
- lj_source_labels.append(*li);
+ for (std::string const& label : labels) {
+ fout << " " << label << "\n";
+ lj_source_labels.append(label);
}
}
}
- cmGeneratedFileStream json_fout(json_file.c_str());
+ cmGeneratedFileStream json_fout(json_file);
json_fout << lj_root;
} else
#endif
@@ -2881,11 +3071,23 @@ void cmGlobalGenerator::WriteSummary(cmGeneratorTarget* target)
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.reserve(s.size());
+ for (char i : s) {
+ switch (i) {
+ case '"':
+ case '\\':
+ result += '\\';
+ result += i;
+ break;
+ case '\n':
+ result += "\\n";
+ break;
+ case '\t':
+ result += "\\t";
+ break;
+ default:
+ result += i;
}
- result += s[i];
}
return result;
}
@@ -2905,18 +3107,16 @@ cmGlobalGenerator::GetFilenameTargetDepends(cmSourceFile* sf) const
void cmGlobalGenerator::CreateEvaluationSourceFiles(
std::string const& config) const
{
- unsigned int i;
- for (i = 0; i < this->LocalGenerators.size(); ++i) {
- this->LocalGenerators[i]->CreateEvaluationFileOutputs(config);
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ localGen->CreateEvaluationFileOutputs(config);
}
}
void cmGlobalGenerator::ProcessEvaluationFiles()
{
std::vector<std::string> generatedFiles;
- unsigned int i;
- for (i = 0; i < this->LocalGenerators.size(); ++i) {
- this->LocalGenerators[i]->ProcessEvaluationFiles(generatedFiles);
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ localGen->ProcessEvaluationFiles(generatedFiles);
}
}
@@ -2940,16 +3140,15 @@ bool cmGlobalGenerator::GenerateCPackPropertiesFile()
std::string path = this->CMakeInstance->GetHomeOutputDirectory();
path += "/CPackProperties.cmake";
- if (!cmSystemTools::FileExists(path.c_str()) && installedFiles.empty()) {
+ if (!cmSystemTools::FileExists(path) && installedFiles.empty()) {
return true;
}
- cmGeneratedFileStream file(path.c_str());
+ cmGeneratedFileStream file(path);
file << "# CPack properties\n";
- for (cmake::InstalledFilesMap::const_iterator i = installedFiles.begin();
- i != installedFiles.end(); ++i) {
- cmInstalledFile const& installedFile = i->second;
+ for (auto const& i : installedFiles) {
+ cmInstalledFile const& installedFile = i.second;
cmCPackPropertiesGenerator cpackPropertiesGenerator(lg, installedFile,
configs);
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 871178be1..500853444 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -3,28 +3,34 @@
#ifndef cmGlobalGenerator_h
#define cmGlobalGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
#include <set>
#include <string>
+#include <unordered_map>
#include <utility>
#include <vector>
+#include "cmAlgorithms.h"
#include "cmCustomCommandLines.h"
+#include "cmDuration.h"
#include "cmExportSetMap.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetDepend.h"
#include "cm_codecvt.hxx"
-#include "cm_unordered_map.hxx"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmFileLockPool.h"
+# include "cmFileLockPool.h"
+# include "cm_jsoncpp_value.h"
#endif
+#define CMAKE_DIRECTORY_ID_SEP "::@"
+
+class cmDirectoryId;
class cmExportBuildFileGenerator;
class cmExternalMakefileProjectGenerator;
class cmGeneratorTarget;
@@ -36,6 +42,41 @@ class cmSourceFile;
class cmStateDirectory;
class cmake;
+namespace detail {
+inline void AppendStrs(std::vector<std::string>&)
+{
+}
+template <typename T, typename... Ts>
+inline void AppendStrs(std::vector<std::string>& command, T&& s, Ts&&... ts)
+{
+ command.emplace_back(std::forward<T>(s));
+ AppendStrs(command, std::forward<Ts>(ts)...);
+}
+
+struct GeneratedMakeCommand
+{
+ // Add each argument as a separate element to the vector
+ template <typename... T>
+ void Add(T&&... args)
+ {
+ // iterate the args and append each one
+ AppendStrs(PrimaryCommand, std::forward<T>(args)...);
+ }
+
+ // Add each value in the iterators as a separate element to the vector
+ void Add(std::vector<std::string>::const_iterator start,
+ std::vector<std::string>::const_iterator end)
+ {
+ cmAppend(PrimaryCommand, start, end);
+ }
+
+ std::string Printable() const { return cmJoin(PrimaryCommand, " "); }
+
+ std::vector<std::string> PrimaryCommand;
+ bool RequiresOutputForward = false;
+};
+}
+
/** \class cmGlobalGenerator
* \brief Responsible for overseeing the generation process for the entire tree
*
@@ -45,13 +86,13 @@ class cmake;
class cmGlobalGenerator
{
public:
- ///! Free any memory allocated with the GlobalGenerator
+ //! Free any memory allocated with the GlobalGenerator
cmGlobalGenerator(cmake* cm);
virtual ~cmGlobalGenerator();
virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf);
- ///! Get the name for this generator
+ //! Get the name for this generator
virtual std::string GetName() const { return "Generic"; }
/** Check whether the given name matches the current generator. */
@@ -66,9 +107,17 @@ public:
return codecvt::None;
}
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ /** Get a JSON object describing the generator. */
+ virtual Json::Value GetJson() const;
+#endif
+
/** Tell the generator about the target system. */
virtual bool SetSystemName(std::string const&, cmMakefile*) { return true; }
+ /** Set the generator-specific instance. Returns true if supported. */
+ virtual bool SetGeneratorInstance(std::string const& i, cmMakefile* mf);
+
/** Set the generator-specific platform name. Returns true if platform
is supported and false otherwise. */
virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
@@ -142,9 +191,10 @@ public:
* Try running cmake and building a file. This is used for dynamically
* 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, std::string& output, cmMakefile* mf);
+ int TryCompile(int jobs, 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
@@ -152,29 +202,41 @@ public:
* 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, bool verbose,
- 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,
- bool verbose,
+ int Build(
+ int jobs, const std::string& srcdir, const std::string& bindir,
+ const std::string& projectName,
+ std::vector<std::string> const& targetNames, std::string& output,
+ const std::string& makeProgram, const std::string& config, bool clean,
+ bool fast, bool verbose, cmDuration timeout,
+ cmSystemTools::OutputOption outputflag = cmSystemTools::OUTPUT_NONE,
+ std::vector<std::string> const& nativeOptions =
+ std::vector<std::string>());
+
+ /**
+ * Open a generated IDE project given the following information.
+ */
+ virtual bool Open(const std::string& bindir, const std::string& projectName,
+ bool dryRun);
+
+ struct GeneratedMakeCommand final : public detail::GeneratedMakeCommand
+ {
+ };
+
+ virtual std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
std::vector<std::string> const& makeOptions = std::vector<std::string>());
+ virtual void PrintBuildCommandAdvice(std::ostream& os, int jobs) const;
+
/** 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);
- ///! Get the CMake instance
+ //! Get the CMake instance
cmake* GetCMakeInstance() const { return this->CMakeInstance; }
void SetConfiguredFilesPath(cmGlobalGenerator* gen);
@@ -187,19 +249,25 @@ public:
return this->LocalGenerators;
}
- cmMakefile* GetCurrentMakefile() const { return this->CurrentMakefile; }
+ cmMakefile* GetCurrentMakefile() const
+ {
+ return this->CurrentConfigureMakefile;
+ }
- void SetCurrentMakefile(cmMakefile* mf) { this->CurrentMakefile = mf; }
+ void SetCurrentMakefile(cmMakefile* mf)
+ {
+ this->CurrentConfigureMakefile = mf;
+ }
void AddMakefile(cmMakefile* mf);
- ///! Set an generator for an "external makefile based project"
+ //! Set an generator for an "external makefile based project"
void SetExternalMakefileProjectGenerator(
cmExternalMakefileProjectGenerator* extraGenerator);
std::string GetExtraGeneratorName() const;
- void AddInstallComponent(const char* component);
+ void AddInstallComponent(const std::string& component);
const std::set<std::string>* GetInstallComponents() const
{
@@ -210,31 +278,31 @@ public:
const char* GetGlobalSetting(std::string const& name) const;
bool GlobalSettingIsOn(std::string const& name) const;
- const char* GetSafeGlobalSetting(std::string const& name) const;
+ std::string GetSafeGlobalSetting(std::string const& name) const;
/** Add a file to the manifest of generated targets for a configuration. */
void AddToManifest(std::string const& f);
void EnableInstallTarget();
- int TryCompileTimeout;
+ cmDuration TryCompileTimeout;
bool GetForceUnixPaths() const { return this->ForceUnixPaths; }
bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
- ///! return the language for the given extension
+ //! return the language for the given extension
std::string GetLanguageFromExtension(const char* ext) const;
- ///! is an extension to be ignored
+ //! is an extension to be ignored
bool IgnoreFile(const char* ext) const;
- ///! What is the preference for linkers and this language (None or Preferred)
+ //! 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?
+ //! What is the object file extension for a given source file?
std::string GetLanguageOutputExtension(cmSourceFile const&) const;
- ///! What is the configurations directory variable called?
+ //! What is the configurations directory variable called?
virtual const char* GetCMakeCFGIntDir() const { return "."; }
- ///! expand CFGIntDir for a configuration
+ //! expand CFGIntDir for a configuration
virtual std::string ExpandCFGIntDir(const std::string& str,
const std::string& config) const;
@@ -250,7 +318,7 @@ public:
*/
virtual bool FindMakeProgram(cmMakefile*);
- ///! Find a target by name by searching the local generators.
+ //! Find a target by name by searching the local generators.
cmTarget* FindTarget(const std::string& name,
bool excludeAliases = false) const;
@@ -264,8 +332,7 @@ public:
bool NameResolvesToFramework(const std::string& libname) const;
cmMakefile* FindMakefile(const std::string& start_dir) const;
- ///! Find a local generator by its startdirectory
- cmLocalGenerator* FindLocalGenerator(const std::string& start_dir) const;
+ cmLocalGenerator* FindLocalGenerator(cmDirectoryId const& id) const;
/** Append the subdirectory for the given configuration. If anything is
appended the given prefix and suffix will be appended around it, which
@@ -285,19 +352,23 @@ public:
void IndexTarget(cmTarget* t);
void IndexGeneratorTarget(cmGeneratorTarget* gt);
+ // Index the target using a name that is unique to that target
+ // even if other targets have the same name.
+ std::string IndexGeneratorTargetUniquely(cmGeneratorTarget const* gt);
+
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 CM_NULLPTR; }
- virtual const char* GetInstallStripTargetName() const { return CM_NULLPTR; }
- virtual const char* GetPreinstallTargetName() const { return CM_NULLPTR; }
+ virtual const char* GetInstallLocalTargetName() const { return nullptr; }
+ virtual const char* GetInstallStripTargetName() const { return nullptr; }
+ virtual const char* GetPreinstallTargetName() const { return nullptr; }
virtual const char* GetTestTargetName() const { return "RUN_TESTS"; }
virtual const char* GetPackageTargetName() const { return "PACKAGE"; }
- virtual const char* GetPackageSourceTargetName() const { return CM_NULLPTR; }
- virtual const char* GetEditCacheTargetName() const { return CM_NULLPTR; }
- virtual const char* GetRebuildCacheTargetName() const { return CM_NULLPTR; }
- virtual const char* GetCleanTargetName() const { return CM_NULLPTR; }
+ virtual const char* GetPackageSourceTargetName() const { return nullptr; }
+ virtual const char* GetEditCacheTargetName() const { return nullptr; }
+ virtual const char* GetRebuildCacheTargetName() const { return nullptr; }
+ virtual const char* GetCleanTargetName() const { return nullptr; }
// Lookup edit_cache target command preferred by this generator.
virtual std::string GetEditCacheCommand() const { return ""; }
@@ -310,7 +381,7 @@ public:
TargetDependSet const& GetTargetDirectDepends(
const cmGeneratorTarget* target);
- const std::map<std::string, std::vector<cmLocalGenerator*> >& GetProjectMap()
+ const std::map<std::string, std::vector<cmLocalGenerator*>>& GetProjectMap()
const
{
return this->ProjectMap;
@@ -333,6 +404,8 @@ public:
i.e. "Can I build Debug and Release in the same tree?" */
virtual bool IsMultiConfig() const { return false; }
+ virtual bool IsXcode() const { return false; }
+
/** Return true if we know the exact location of object files.
If false, store the reason in the given string.
This is meaningful only after EnableLanguage has been called. */
@@ -342,6 +415,10 @@ public:
virtual bool IsIPOSupported() const { return false; }
+ /** Return whether the generator can import external visual studio project
+ using INCLUDE_EXTERNAL_MSPROJECT */
+ virtual bool IsIncludeExternalMSProjectSupported() const { return false; }
+
/** Return whether the generator should use EFFECTIVE_PLATFORM_NAME. This is
relevant for mixed macOS and iOS builds. */
virtual bool UseEffectivePlatformName(cmMakefile*) const { return false; }
@@ -394,6 +471,8 @@ public:
std::string MakeSilentFlag;
+ int RecursionDepth;
+
protected:
typedef std::vector<cmLocalGenerator*> GeneratorVector;
// for a project collect all its targets by following depend
@@ -416,7 +495,9 @@ protected:
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const;
- std::vector<const cmGeneratorTarget*> CreateQtAutoGeneratorsTargets();
+ /// @brief Qt AUTOMOC/UIC/RCC target generation
+ /// @return true on success
+ bool QtAutoGen();
std::string SelectMakeProgram(const std::string& makeProgram,
const std::string& makeDefault = "") const;
@@ -438,11 +519,7 @@ protected:
cmCustomCommandLines CommandLines;
std::vector<std::string> Depends;
std::string WorkingDir;
- bool UsesTerminal;
- GlobalTargetInfo()
- : UsesTerminal(false)
- {
- }
+ bool UsesTerminal = false;
};
void CreateDefaultGlobalTargets(std::vector<GlobalTargetInfo>& targets);
@@ -460,9 +537,9 @@ protected:
cmake* CMakeInstance;
std::vector<cmMakefile*> Makefiles;
std::vector<cmLocalGenerator*> LocalGenerators;
- cmMakefile* CurrentMakefile;
+ cmMakefile* CurrentConfigureMakefile;
// map from project name to vector of local generators in that project
- std::map<std::string, std::vector<cmLocalGenerator*> > ProjectMap;
+ std::map<std::string, std::vector<cmLocalGenerator*>> ProjectMap;
// Set of named installation components requested by the project.
std::set<std::string> InstallComponents;
@@ -482,9 +559,11 @@ protected:
const char* GetPredefinedTargetsFolder();
private:
- typedef CM_UNORDERED_MAP<std::string, cmTarget*> TargetMap;
- typedef CM_UNORDERED_MAP<std::string, cmGeneratorTarget*> GeneratorTargetMap;
- typedef CM_UNORDERED_MAP<std::string, cmMakefile*> MakefileMap;
+ typedef std::unordered_map<std::string, cmTarget*> TargetMap;
+ typedef std::unordered_map<std::string, cmGeneratorTarget*>
+ GeneratorTargetMap;
+ typedef std::unordered_map<std::string, cmMakefile*> MakefileMap;
+ typedef std::unordered_map<std::string, cmLocalGenerator*> LocalGeneratorMap;
// Map efficiently from target name to cmTarget instance.
// Do not use this structure for looping over all targets.
// It contains both normal and globally visible imported targets.
@@ -496,6 +575,11 @@ private:
// It may not contain all of them (see note in IndexMakefile method).
MakefileMap MakefileSearchIndex;
+ // Map efficiently from source directory path to cmLocalGenerator instance.
+ // Do not use this structure for looping over all directories.
+ // Its order is not deterministic.
+ LocalGeneratorMap LocalGeneratorSearchIndex;
+
cmMakefile* TryCompileOuterMakefile;
// If you add a new map here, make sure it is copied
// in EnableLanguagesFromGenerator
@@ -524,6 +608,9 @@ private:
virtual void ForceLinkerLanguages();
+ bool CheckTargetsForMissingSources() const;
+ bool CheckTargetsForType() const;
+
void CreateLocalGenerators();
void CheckCompilerIdCompatibility(cmMakefile* mf,
@@ -548,20 +635,20 @@ private:
void ClearGeneratorMembers();
+ bool CheckCMP0037(std::string const& targetName,
+ std::string const& reason) const;
+
void IndexMakefile(cmMakefile* mf);
+ void IndexLocalGenerator(cmLocalGenerator* lg);
- virtual const char* GetBuildIgnoreErrorsFlag() const { return CM_NULLPTR; }
+ virtual const char* GetBuildIgnoreErrorsFlag() const { return nullptr; }
// Cache directory content and target files to be built.
struct DirectoryContent
{
- long LastDiskTime;
+ long LastDiskTime = -1;
std::set<std::string> All;
std::set<std::string> Generated;
- DirectoryContent()
- : LastDiskTime(-1)
- {
- }
};
std::map<std::string, DirectoryContent> DirectoryContentMap;
@@ -573,7 +660,7 @@ private:
// track targets to issue CMP0068 warning for.
std::set<std::string> CMP0068WarnTargets;
- mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*> >
+ mutable std::map<cmSourceFile*, std::set<cmGeneratorTarget const*>>
FilenameTargetDepends;
#if defined(CMAKE_BUILD_WITH_CMAKE)
diff --git a/Source/cmGlobalGeneratorFactory.h b/Source/cmGlobalGeneratorFactory.h
index d5a6db06e..bb5f74cca 100644
--- a/Source/cmGlobalGeneratorFactory.h
+++ b/Source/cmGlobalGeneratorFactory.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalGeneratorFactory_h
#define cmGlobalGeneratorFactory_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -20,7 +20,7 @@ struct cmDocumentationEntry;
class cmGlobalGeneratorFactory
{
public:
- virtual ~cmGlobalGeneratorFactory() {}
+ virtual ~cmGlobalGeneratorFactory() = default;
/** Create a GlobalGenerator */
virtual cmGlobalGenerator* CreateGlobalGenerator(const std::string& n,
@@ -30,13 +30,20 @@ public:
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;
+ virtual std::vector<std::string> GetGeneratorNames() const = 0;
+ virtual std::vector<std::string> GetGeneratorNamesWithPlatform() const = 0;
/** Determine whether or not this generator supports toolsets */
virtual bool SupportsToolset() const = 0;
/** Determine whether or not this generator supports platforms */
virtual bool SupportsPlatform() const = 0;
+
+ /** Get the list of supported platforms name for this generator */
+ virtual std::vector<std::string> GetKnownPlatforms() const = 0;
+
+ /** If the generator suports platforms, get its default. */
+ virtual std::string GetDefaultPlatformName() const = 0;
};
template <class T>
@@ -45,31 +52,46 @@ class cmGlobalGeneratorSimpleFactory : public cmGlobalGeneratorFactory
public:
/** Create a GlobalGenerator */
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE
+ cmake* cm) const override
{
if (name != T::GetActualName()) {
- return CM_NULLPTR;
+ return nullptr;
}
return new T(cm);
}
/** Get the documentation entry for this factory */
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
+ void GetDocumentation(cmDocumentationEntry& entry) const override
{
T::GetDocumentation(entry);
}
/** Get the names of the current registered generators */
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
+ std::vector<std::string> GetGeneratorNames() const override
{
+ std::vector<std::string> names;
names.push_back(T::GetActualName());
+ return names;
+ }
+ std::vector<std::string> GetGeneratorNamesWithPlatform() const override
+ {
+ return std::vector<std::string>();
}
/** Determine whether or not this generator supports toolsets */
- bool SupportsToolset() const CM_OVERRIDE { return T::SupportsToolset(); }
+ bool SupportsToolset() const override { return T::SupportsToolset(); }
/** Determine whether or not this generator supports platforms */
- bool SupportsPlatform() const CM_OVERRIDE { return T::SupportsPlatform(); }
+ bool SupportsPlatform() const override { return T::SupportsPlatform(); }
+
+ /** Get the list of supported platforms name for this generator */
+ std::vector<std::string> GetKnownPlatforms() const override
+ {
+ // default is no platform supported
+ return std::vector<std::string>();
+ }
+
+ std::string GetDefaultPlatformName() const override { return std::string(); }
};
#endif
diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx
index 42ab4d98a..b69dea038 100644
--- a/Source/cmGlobalGhsMultiGenerator.cxx
+++ b/Source/cmGlobalGhsMultiGenerator.cxx
@@ -2,31 +2,41 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGlobalGhsMultiGenerator.h"
-#include "cmsys/SystemTools.hxx"
-
-#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
-#include "cmGhsMultiTargetGenerator.h"
+#include "cmGhsMultiGpj.h"
+#include "cmLocalGenerator.h"
#include "cmLocalGhsMultiGenerator.h"
#include "cmMakefile.h"
+#include "cmState.h"
+#include "cmStateTypes.h"
+#include "cmSystemTools.h"
#include "cmVersion.h"
+#include "cmake.h"
+
+#include <algorithm>
+#include <map>
+#include <ostream>
+#include <string.h>
+#include <utility>
const char* cmGlobalGhsMultiGenerator::FILE_EXTENSION = ".gpj";
-const char* cmGlobalGhsMultiGenerator::DEFAULT_MAKE_PROGRAM = "gbuild";
+#ifdef __linux__
+const char* cmGlobalGhsMultiGenerator::DEFAULT_BUILD_PROGRAM = "gbuild";
+const char* cmGlobalGhsMultiGenerator::DEFAULT_TOOLSET_ROOT = "/usr/ghs";
+#elif defined(_WIN32)
+const char* cmGlobalGhsMultiGenerator::DEFAULT_BUILD_PROGRAM = "gbuild.exe";
+const char* cmGlobalGhsMultiGenerator::DEFAULT_TOOLSET_ROOT = "C:/ghs";
+#endif
cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake* cm)
: cmGlobalGenerator(cm)
- , OSDirRelative(false)
{
- this->GhsBuildCommandInitialized = false;
+ cm->GetState()->SetGhsMultiIDE(true);
}
-cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator()
-{
- cmDeleteAll(TargetFolderBuildStreams);
-}
+cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator() = default;
cmLocalGenerator* cmGlobalGhsMultiGenerator::CreateLocalGenerator(
cmMakefile* mf)
@@ -41,450 +51,704 @@ void cmGlobalGhsMultiGenerator::GetDocumentation(cmDocumentationEntry& entry)
"Generates Green Hills MULTI files (experimental, work-in-progress).";
}
-void cmGlobalGhsMultiGenerator::EnableLanguage(
- std::vector<std::string> const& l, cmMakefile* mf, bool optional)
+void cmGlobalGhsMultiGenerator::ComputeTargetObjectDirectory(
+ cmGeneratorTarget* gt) const
{
- mf->AddDefinition("CMAKE_SYSTEM_NAME", "GHS-MULTI");
- mf->AddDefinition("CMAKE_SYSTEM_PROCESSOR", "ARM");
-
- const std::string ghsCompRoot(GetCompRoot());
- mf->AddDefinition("GHS_COMP_ROOT", ghsCompRoot.c_str());
- std::string ghsCompRootStart =
- 0 == ghsCompRootStart.size() ? "" : ghsCompRoot + "/";
- mf->AddDefinition("CMAKE_C_COMPILER",
- std::string(ghsCompRootStart + "ccarm.exe").c_str());
- mf->AddDefinition("CMAKE_C_COMPILER_ID_RUN", "TRUE");
- mf->AddDefinition("CMAKE_C_COMPILER_ID", "GHS");
- mf->AddDefinition("CMAKE_C_COMPILER_FORCED", "TRUE");
-
- mf->AddDefinition("CMAKE_CXX_COMPILER",
- std::string(ghsCompRootStart + "cxarm.exe").c_str());
- mf->AddDefinition("CMAKE_CXX_COMPILER_ID_RUN", "TRUE");
- mf->AddDefinition("CMAKE_CXX_COMPILER_ID", "GHS");
- mf->AddDefinition("CMAKE_CXX_COMPILER_FORCED", "TRUE");
-
- if (!ghsCompRoot.empty()) {
- static const char* compPreFix = "comp_";
- std::string compFilename =
- cmsys::SystemTools::FindLastString(ghsCompRoot.c_str(), compPreFix);
- cmsys::SystemTools::ReplaceString(compFilename, compPreFix, "");
- mf->AddDefinition("CMAKE_SYSTEM_VERSION", compFilename.c_str());
+ // Compute full path to object file directory for this target.
+ std::string dir;
+ dir += gt->LocalGenerator->GetCurrentBinaryDirectory();
+ dir += "/";
+ dir += gt->LocalGenerator->GetTargetDirectory(gt);
+ dir += "/";
+ gt->ObjectDirectory = dir;
+}
+
+bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
+ cmMakefile* mf)
+{
+ std::string tsp; /* toolset path */
+
+ this->GetToolset(mf, tsp, ts);
+
+ /* no toolset was found */
+ if (tsp.empty()) {
+ return false;
+ }
+ if (ts.empty()) {
+ std::string message;
+ message =
+ "Green Hills MULTI: -T <toolset> not specified; defaulting to \"";
+ message += tsp;
+ message += "\"";
+ cmSystemTools::Message(message);
+
+ /* store the full toolset for later use
+ * -- already done if -T<toolset> was specified
+ */
+ mf->AddCacheDefinition("CMAKE_GENERATOR_TOOLSET", tsp.c_str(),
+ "Location of generator toolset.",
+ cmStateEnums::INTERNAL);
}
- mf->AddDefinition("GHSMULTI", "1"); // identifier for user CMake files
- this->cmGlobalGenerator::EnableLanguage(l, mf, optional);
+ /* set the build tool to use */
+ std::string gbuild(tsp + ((tsp.back() == '/') ? "" : "/") +
+ DEFAULT_BUILD_PROGRAM);
+ const char* prevTool = mf->GetDefinition("CMAKE_MAKE_PROGRAM");
+
+ /* check if the toolset changed from last generate */
+ if (prevTool != nullptr && (gbuild != prevTool)) {
+ std::string message = "toolset build tool: ";
+ message += gbuild;
+ message += "\nDoes not match the previously used build tool: ";
+ message += prevTool;
+ message += "\nEither remove the CMakeCache.txt file and CMakeFiles "
+ "directory or choose a different binary directory.";
+ cmSystemTools::Error(message);
+ return false;
+ }
+
+ /* store the toolset that is being used for this build */
+ mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", gbuild.c_str(),
+ "build program to use", cmStateEnums::INTERNAL, true);
+
+ mf->AddDefinition("CMAKE_SYSTEM_VERSION", tsp.c_str());
+
+ return true;
}
-bool cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile* mf)
+bool cmGlobalGhsMultiGenerator::SetGeneratorPlatform(std::string const& p,
+ cmMakefile* mf)
{
- // The GHS generator knows how to lookup its 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->GetGhsBuildCommand().c_str());
+ std::string arch;
+ if (p.empty()) {
+ cmSystemTools::Message(
+ "Green Hills MULTI: -A <arch> not specified; defaulting to \"arm\"");
+ arch = "arm";
+
+ /* store the platform name for later use
+ * -- already done if -A<arch> was specified
+ */
+ mf->AddCacheDefinition("CMAKE_GENERATOR_PLATFORM", arch.c_str(),
+ "Name of generator platform.",
+ cmStateEnums::INTERNAL);
+ } else {
+ arch = p;
}
+
+ /* check if OS location has been updated by platform scripts */
+ std::string platform = mf->GetSafeDefinition("GHS_TARGET_PLATFORM");
+ std::string osdir = mf->GetSafeDefinition("GHS_OS_DIR");
+ if (cmSystemTools::IsOff(osdir.c_str()) &&
+ platform.find("integrity") != std::string::npos) {
+ if (!this->CMakeInstance->GetIsInTryCompile()) {
+ /* required OS location is not found */
+ std::string m =
+ "Green Hills MULTI: GHS_OS_DIR not specified; No OS found in \"";
+ m += mf->GetSafeDefinition("GHS_OS_ROOT");
+ m += "\"";
+ cmSystemTools::Message(m);
+ }
+ osdir = "GHS_OS_DIR-NOT-SPECIFIED";
+ } else if (!this->CMakeInstance->GetIsInTryCompile() &&
+ cmSystemTools::IsOff(this->OsDir) &&
+ !cmSystemTools::IsOff(osdir)) {
+ /* OS location was updated by auto-selection */
+ std::string m = "Green Hills MULTI: GHS_OS_DIR not specified; found \"";
+ m += osdir;
+ m += "\"";
+ cmSystemTools::Message(m);
+ }
+ this->OsDir = osdir;
+
+ // Determine GHS_BSP_NAME
+ std::string bspName = mf->GetSafeDefinition("GHS_BSP_NAME");
+
+ if (cmSystemTools::IsOff(bspName.c_str()) &&
+ platform.find("integrity") != std::string::npos) {
+ bspName = "sim" + arch;
+ /* write back the calculate name for next time */
+ mf->AddCacheDefinition("GHS_BSP_NAME", bspName.c_str(),
+ "Name of GHS target platform.",
+ cmStateEnums::STRING, true);
+ std::string m =
+ "Green Hills MULTI: GHS_BSP_NAME not specified; defaulting to \"";
+ m += bspName;
+ m += "\"";
+ cmSystemTools::Message(m);
+ }
+
return true;
}
-std::string const& cmGlobalGhsMultiGenerator::GetGhsBuildCommand()
+void cmGlobalGhsMultiGenerator::EnableLanguage(
+ std::vector<std::string> const& l, cmMakefile* mf, bool optional)
{
- if (!this->GhsBuildCommandInitialized) {
- this->GhsBuildCommandInitialized = true;
- this->GhsBuildCommand = this->FindGhsBuildCommand();
+ mf->AddDefinition("CMAKE_SYSTEM_NAME", "GHS-MULTI");
+
+ mf->AddDefinition("GHSMULTI", "1"); // identifier for user CMake files
+
+ const char* tgtPlatform = mf->GetDefinition("GHS_TARGET_PLATFORM");
+ if (!tgtPlatform) {
+ cmSystemTools::Message("Green Hills MULTI: GHS_TARGET_PLATFORM not "
+ "specified; defaulting to \"integrity\"");
+ tgtPlatform = "integrity";
}
- return this->GhsBuildCommand;
+
+ /* store the platform name for later use */
+ mf->AddCacheDefinition("GHS_TARGET_PLATFORM", tgtPlatform,
+ "Name of GHS target platform.", cmStateEnums::STRING);
+
+ /* store original OS location */
+ this->OsDir = mf->GetSafeDefinition("GHS_OS_DIR");
+
+ this->cmGlobalGenerator::EnableLanguage(l, mf, optional);
}
-std::string cmGlobalGhsMultiGenerator::FindGhsBuildCommand()
+bool cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile* /*mf*/)
{
- std::vector<std::string> userPaths;
- userPaths.push_back(this->GetCompRoot());
- std::string makeProgram =
- cmSystemTools::FindProgram(DEFAULT_MAKE_PROGRAM, userPaths);
- if (makeProgram.empty()) {
- makeProgram = DEFAULT_MAKE_PROGRAM;
- }
- return makeProgram;
+ // The GHS generator only knows how to lookup its build tool
+ // during generation of the project files, but this
+ // can only be done after the toolset is specified.
+
+ return true;
}
-std::string cmGlobalGhsMultiGenerator::GetCompRoot()
+void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd,
+ const std::string& ts)
{
- std::string output;
-
- const std::vector<std::string> potentialDirsHardPaths(
- GetCompRootHardPaths());
- const std::vector<std::string> potentialDirsRegistry(GetCompRootRegistry());
-
- std::vector<std::string> potentialDirsComplete;
- potentialDirsComplete.insert(potentialDirsComplete.end(),
- potentialDirsHardPaths.begin(),
- potentialDirsHardPaths.end());
- potentialDirsComplete.insert(potentialDirsComplete.end(),
- potentialDirsRegistry.begin(),
- potentialDirsRegistry.end());
-
- // Use latest version
- std::string outputDirName;
- for (std::vector<std::string>::const_iterator potentialDirsCompleteIt =
- potentialDirsComplete.begin();
- potentialDirsCompleteIt != potentialDirsComplete.end();
- ++potentialDirsCompleteIt) {
- const std::string dirName(
- cmsys::SystemTools::GetFilenameName(*potentialDirsCompleteIt));
- if (dirName.compare(outputDirName) > 0) {
- output = *potentialDirsCompleteIt;
- outputDirName = dirName;
+ const char* ghsRoot = mf->GetDefinition("GHS_TOOLSET_ROOT");
+
+ if (!ghsRoot || ghsRoot[0] == '\0') {
+ ghsRoot = DEFAULT_TOOLSET_ROOT;
+ }
+ tsd = ghsRoot;
+
+ if (ts.empty()) {
+ std::vector<std::string> output;
+
+ // Use latest? version
+ if (tsd.back() != '/') {
+ tsd += "/";
+ }
+ cmSystemTools::Glob(tsd, "comp_[^;]+", output);
+
+ if (output.empty()) {
+ std::string msg =
+ "No GHS toolsets found in GHS_TOOLSET_ROOT \"" + tsd + "\".";
+ cmSystemTools::Error(msg);
+ tsd = "";
+ } else {
+ tsd += output.back();
+ }
+ } else {
+ std::string tryPath;
+ tryPath = cmSystemTools::CollapseFullPath(ts, tsd);
+ if (!cmSystemTools::FileExists(tryPath)) {
+ std::string msg = "GHS toolset \"" + tryPath + "\" not found.";
+ cmSystemTools::Error(msg);
+ tsd = "";
+ } else {
+ tsd = tryPath;
}
}
+}
- return output;
+void cmGlobalGhsMultiGenerator::WriteFileHeader(std::ostream& fout)
+{
+ fout << "#!gbuild" << std::endl;
+ fout << "#" << std::endl
+ << "# CMAKE generated file: DO NOT EDIT!" << std::endl
+ << "# Generated by \"" << GetActualName() << "\""
+ << " Generator, CMake Version " << cmVersion::GetMajorVersion() << "."
+ << cmVersion::GetMinorVersion() << std::endl
+ << "#" << std::endl
+ << std::endl;
}
-std::vector<std::string> cmGlobalGhsMultiGenerator::GetCompRootHardPaths()
+void cmGlobalGhsMultiGenerator::WriteCustomRuleBOD(std::ostream& fout)
{
- std::vector<std::string> output;
- cmSystemTools::Glob("C:/ghs", "comp_[^;]+", output);
- for (std::vector<std::string>::iterator outputIt = output.begin();
- outputIt != output.end(); ++outputIt) {
- *outputIt = "C:/ghs/" + *outputIt;
- }
- return output;
+ fout << "Commands {\n"
+ " Custom_Rule_Command {\n"
+ " name = \"Custom Rule Command\"\n"
+ " exec = \"";
+#ifdef _WIN32
+ fout << "cmd.exe";
+#else
+ fout << "/bin/sh";
+#endif
+ fout << "\"\n"
+ " options = {\"SpecialOptions\"}\n"
+ " }\n"
+ "}\n";
+
+ fout << "\n\n";
+ fout << "FileTypes {\n"
+ " CmakeRule {\n"
+ " name = \"Custom Rule\"\n"
+ " action = \"&Run\"\n"
+ " extensions = {\"";
+#ifdef _WIN32
+ fout << "bat";
+#else
+ fout << "sh";
+#endif
+ fout << "\"}\n"
+ " grepable = false\n"
+ " command = \"Custom Rule Command\"\n"
+ " commandLine = \"$COMMAND ";
+#ifdef _WIN32
+ fout << "/c";
+#endif
+ fout << " $INPUTFILE\"\n"
+ " progress = \"Processing Custom Rule\"\n"
+ " promoteToFirstPass = true\n"
+ " outputType = \"None\"\n"
+ " color = \"#800080\"\n"
+ " }\n"
+ "}\n";
}
-std::vector<std::string> cmGlobalGhsMultiGenerator::GetCompRootRegistry()
+void cmGlobalGhsMultiGenerator::WriteCustomTargetBOD(std::ostream& fout)
{
- std::vector<std::string> output(2);
- cmsys::SystemTools::ReadRegistryValue(
- "HKEY_LOCAL_"
- "MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\"
- "Windows\\CurrentVersion\\Uninstall\\"
- "GreenHillsSoftwared771f1b4;InstallLocation",
- output[0]);
- cmsys::SystemTools::ReadRegistryValue(
- "HKEY_LOCAL_"
- "MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\"
- "Windows\\CurrentVersion\\Uninstall\\"
- "GreenHillsSoftware9881cef6;InstallLocation",
- output[1]);
- return output;
+ fout << "FileTypes {\n"
+ " CmakeTarget {\n"
+ " name = \"Custom Target\"\n"
+ " action = \"&Execute\"\n"
+ " grepable = false\n"
+ " outputType = \"None\"\n"
+ " color = \"#800080\"\n"
+ " }\n"
+ "}\n";
}
-void cmGlobalGhsMultiGenerator::OpenBuildFileStream(
- std::string const& filepath, cmGeneratedFileStream** filestream)
+void cmGlobalGhsMultiGenerator::WriteTopLevelProject(std::ostream& fout,
+ cmLocalGenerator* root)
{
- // Get a stream where to generate things.
- if (NULL == *filestream) {
- *filestream = new cmGeneratedFileStream(filepath.c_str());
- if (NULL != *filestream) {
- OpenBuildFileStream(*filestream);
+ this->WriteFileHeader(fout);
+ this->WriteMacros(fout, root);
+ this->WriteHighLevelDirectives(root, fout);
+ GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, fout);
+
+ fout << "# Top Level Project File" << std::endl;
+
+ // Specify BSP option if supplied by user
+ const char* bspName =
+ this->GetCMakeInstance()->GetCacheDefinition("GHS_BSP_NAME");
+ if (!cmSystemTools::IsOff(bspName)) {
+ fout << " -bsp " << bspName << std::endl;
+ }
+
+ // Specify OS DIR if supplied by user
+ // -- not all platforms require this entry in the project file
+ if (!cmSystemTools::IsOff(this->OsDir.c_str())) {
+ const char* osDirOption =
+ this->GetCMakeInstance()->GetCacheDefinition("GHS_OS_DIR_OPTION");
+ std::replace(this->OsDir.begin(), this->OsDir.end(), '\\', '/');
+ fout << " ";
+ if (cmSystemTools::IsOff(osDirOption)) {
+ fout << "";
+ } else {
+ fout << osDirOption;
}
+ fout << "\"" << this->OsDir << "\"" << std::endl;
}
}
-void cmGlobalGhsMultiGenerator::OpenBuildFileStream(
- cmGeneratedFileStream* filestream)
+void cmGlobalGhsMultiGenerator::WriteSubProjects(std::ostream& fout,
+ std::string& all_target)
{
- *filestream << "#!gbuild" << std::endl;
+ fout << "CMakeFiles/" << all_target << " [Project]" << std::endl;
+ // All known targets
+ for (cmGeneratorTarget const* target : this->ProjectTargets) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
+ target->GetType() == cmStateEnums::MODULE_LIBRARY ||
+ target->GetType() == cmStateEnums::SHARED_LIBRARY ||
+ (target->GetType() == cmStateEnums::GLOBAL_TARGET &&
+ target->GetName() != GetInstallTargetName())) {
+ continue;
+ }
+ fout << "CMakeFiles/" << target->GetName() + ".tgt" + FILE_EXTENSION
+ << " [Project]" << std::endl;
+ }
}
-void cmGlobalGhsMultiGenerator::OpenBuildFileStream()
+void cmGlobalGhsMultiGenerator::WriteProjectLine(
+ std::ostream& fout, cmGeneratorTarget const* target, cmLocalGenerator* root,
+ std::string& rootBinaryDir)
{
- // Compute GHS MULTI's build file path.
- std::string buildFilePath =
- this->GetCMakeInstance()->GetHomeOutputDirectory();
- buildFilePath += "/";
- buildFilePath += "default";
- buildFilePath += FILE_EXTENSION;
-
- this->Open(std::string(""), buildFilePath, &this->TargetFolderBuildStreams);
- OpenBuildFileStream(GetBuildFileStream());
-
- char const* osDir =
- this->GetCMakeInstance()->GetCacheDefinition("GHS_OS_DIR");
- if (NULL == osDir) {
- osDir = "";
- cmSystemTools::Error("GHS_OS_DIR cache variable must be set");
- } else {
- this->GetCMakeInstance()->MarkCliAsUsed("GHS_OS_DIR");
- }
- std::string fOSDir(this->trimQuotes(osDir));
- std::replace(fOSDir.begin(), fOSDir.end(), '\\', '/');
- if (!fOSDir.empty() && ('c' == fOSDir[0] || 'C' == fOSDir[0])) {
- this->OSDirRelative = false;
- } else {
- this->OSDirRelative = true;
- }
+ const char* projName = target->GetProperty("GENERATOR_FILE_NAME");
+ const char* projType = target->GetProperty("GENERATOR_FILE_NAME_EXT");
+ if (projName && projType) {
+ cmLocalGenerator* lg = target->GetLocalGenerator();
+ std::string dir = lg->GetCurrentBinaryDirectory();
+ dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir);
+ if (dir == ".") {
+ dir.clear();
+ } else {
+ if (dir.back() != '/') {
+ dir += "/";
+ }
+ }
- char const* bspName =
- this->GetCMakeInstance()->GetCacheDefinition("GHS_BSP_NAME");
- if (NULL == bspName) {
- bspName = "";
- cmSystemTools::Error("GHS_BSP_NAME cache variable must be set");
+ std::string projFile = dir + projName + FILE_EXTENSION;
+ fout << projFile;
+ fout << " " << projType << std::endl;
} else {
- this->GetCMakeInstance()->MarkCliAsUsed("GHS_BSP_NAME");
+ /* Should never happen */
+ std::string message =
+ "The project file for target [" + target->GetName() + "] is missing.\n";
+ cmSystemTools::Error(message);
+ fout << "{comment} " << target->GetName() << " [missing project file]\n";
}
- std::string fBspName(this->trimQuotes(bspName));
- std::replace(fBspName.begin(), fBspName.end(), '\\', '/');
- this->WriteMacros();
- this->WriteHighLevelDirectives();
-
- GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, this->GetBuildFileStream());
- this->WriteDisclaimer(this->GetBuildFileStream());
- *this->GetBuildFileStream() << "# Top Level Project File" << std::endl;
- if (!fBspName.empty()) {
- *this->GetBuildFileStream() << " -bsp " << fBspName << std::endl;
+}
+
+void cmGlobalGhsMultiGenerator::WriteTargets(cmLocalGenerator* root)
+{
+ std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
+ rootBinaryDir += "/CMakeFiles";
+
+ // All known targets
+ for (cmGeneratorTarget const* target : this->ProjectTargets) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
+ target->GetType() == cmStateEnums::MODULE_LIBRARY ||
+ target->GetType() == cmStateEnums::SHARED_LIBRARY ||
+ (target->GetType() == cmStateEnums::GLOBAL_TARGET &&
+ target->GetName() != GetInstallTargetName())) {
+ continue;
+ }
+
+ // create target build file
+ std::string name = target->GetName() + ".tgt" + FILE_EXTENSION;
+ std::string fname = rootBinaryDir + "/" + name;
+ cmGeneratedFileStream fbld(fname);
+ fbld.SetCopyIfDifferent(true);
+ this->WriteFileHeader(fbld);
+ GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, fbld);
+ std::vector<cmGeneratorTarget const*> build;
+ if (ComputeTargetBuildOrder(target, build)) {
+ std::string message = "The inter-target dependency graph for target [" +
+ target->GetName() + "] had a cycle.\n";
+ cmSystemTools::Error(message);
+ } else {
+ for (auto& tgt : build) {
+ WriteProjectLine(fbld, tgt, root, rootBinaryDir);
+ }
+ }
+ fbld.Close();
}
- this->WriteCompilerOptions(fOSDir);
}
-void cmGlobalGhsMultiGenerator::CloseBuildFileStream(
- cmGeneratedFileStream** filestream)
+void cmGlobalGhsMultiGenerator::WriteAllTarget(
+ cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators,
+ std::string& all_target)
{
- if (filestream) {
- delete *filestream;
- *filestream = NULL;
+ this->ProjectTargets.clear();
+
+ // create target build file
+ all_target = root->GetProjectName() + "." + this->GetAllTargetName() +
+ ".tgt" + FILE_EXTENSION;
+ std::string fname =
+ root->GetCurrentBinaryDirectory() + "/CMakeFiles/" + all_target;
+ cmGeneratedFileStream fbld(fname);
+ fbld.SetCopyIfDifferent(true);
+ this->WriteFileHeader(fbld);
+ GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, fbld);
+
+ // 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 sortedProjectTargets(projectTargets, "");
+ std::vector<cmGeneratorTarget const*> defaultTargets;
+ for (cmGeneratorTarget const* t : sortedProjectTargets) {
+ /* save list of all targets in sorted order */
+ this->ProjectTargets.push_back(t);
+ }
+ for (cmGeneratorTarget const* t : sortedProjectTargets) {
+ if (t->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ continue;
+ }
+ if (!cmSystemTools::IsOn(t->GetProperty("EXCLUDE_FROM_ALL"))) {
+ defaultTargets.push_back(t);
+ }
+ }
+ std::vector<cmGeneratorTarget const*> build;
+ if (ComputeTargetBuildOrder(defaultTargets, build)) {
+ std::string message = "The inter-target dependency graph for project [" +
+ root->GetProjectName() + "] had a cycle.\n";
+ cmSystemTools::Error(message);
} else {
- cmSystemTools::Error("Build file stream was not open.");
+ // determine the targets for ALL target
+ std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
+ rootBinaryDir += "/CMakeFiles";
+ for (cmGeneratorTarget const* target : build) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
+ target->GetType() == cmStateEnums::MODULE_LIBRARY ||
+ target->GetType() == cmStateEnums::SHARED_LIBRARY) {
+ continue;
+ }
+ this->WriteProjectLine(fbld, target, root, rootBinaryDir);
+ }
}
+ fbld.Close();
}
void cmGlobalGhsMultiGenerator::Generate()
{
+ std::string fname;
+
+ // first do the superclass method
this->cmGlobalGenerator::Generate();
- if (!this->LocalGenerators.empty()) {
- this->OpenBuildFileStream();
+ // output top-level projects
+ for (auto& it : this->ProjectMap) {
+ this->OutputTopLevelProject(it.second[0], it.second);
+ }
- // Build all the folder build files
- for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
- cmLocalGhsMultiGenerator* lg =
- static_cast<cmLocalGhsMultiGenerator*>(this->LocalGenerators[i]);
- std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets();
- this->UpdateBuildFiles(tgts);
- }
+ // create custom rule BOD file
+ fname = this->GetCMakeInstance()->GetHomeOutputDirectory() +
+ "/CMakeFiles/custom_rule.bod";
+ cmGeneratedFileStream frule(fname);
+ frule.SetCopyIfDifferent(true);
+ this->WriteFileHeader(frule);
+ this->WriteCustomRuleBOD(frule);
+ frule.Close();
+
+ // create custom target BOD file
+ fname = this->GetCMakeInstance()->GetHomeOutputDirectory() +
+ "/CMakeFiles/custom_target.bod";
+ cmGeneratedFileStream ftarget(fname);
+ ftarget.SetCopyIfDifferent(true);
+ this->WriteFileHeader(ftarget);
+ this->WriteCustomTargetBOD(ftarget);
+ ftarget.Close();
+}
+
+void cmGlobalGhsMultiGenerator::OutputTopLevelProject(
+ cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
+{
+ std::string fname;
+ std::string all_target;
+
+ if (generators.empty()) {
+ return;
}
- cmDeleteAll(TargetFolderBuildStreams);
- this->TargetFolderBuildStreams.clear();
+ /* Name top-level projects as filename.top.gpj to avoid name clashes
+ * with target projects. This avoid the issue where the project has
+ * the same name as the executable target.
+ */
+ fname = root->GetCurrentBinaryDirectory();
+ fname += "/";
+ fname += root->GetProjectName();
+ fname += ".top";
+ fname += FILE_EXTENSION;
+
+ cmGeneratedFileStream top(fname);
+ top.SetCopyIfDifferent(true);
+ this->WriteTopLevelProject(top, root);
+
+ this->WriteAllTarget(root, generators, all_target);
+ this->WriteTargets(root);
+
+ this->WriteSubProjects(top, all_target);
+ top.Close();
}
-void cmGlobalGhsMultiGenerator::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*/,
- bool /*verbose*/, std::vector<std::string> const& makeOptions)
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalGhsMultiGenerator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& /*config*/, bool /*fast*/, int jobs, bool /*verbose*/,
+ std::vector<std::string> const& makeOptions)
{
- makeCommand.push_back(
- this->SelectMakeProgram(makeProgram, this->GetGhsBuildCommand()));
-
- makeCommand.insert(makeCommand.end(), makeOptions.begin(),
- makeOptions.end());
- if (!targetName.empty()) {
- if (targetName == "clean") {
- makeCommand.push_back("-clean");
+ GeneratedMakeCommand makeCommand = {};
+ std::string gbuild;
+ if (const char* gbuildCached =
+ this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM")) {
+ gbuild = gbuildCached;
+ }
+ makeCommand.Add(this->SelectMakeProgram(makeProgram, gbuild));
+
+ if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
+ makeCommand.Add("-parallel");
+ if (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
+ makeCommand.Add(std::to_string(jobs));
+ }
+ }
+
+ makeCommand.Add(makeOptions.begin(), makeOptions.end());
+
+ /* determine which top-project file to use */
+ std::string proj = projectName + ".top" + FILE_EXTENSION;
+ std::vector<std::string> files;
+ cmSystemTools::Glob(projectDir, ".*\\.top\\.gpj", files);
+ if (!files.empty()) {
+ /* if multiple top-projects are found in build directory
+ * then prefer projectName top-project.
+ */
+ auto p = std::find(files.begin(), files.end(), proj);
+ if (p == files.end()) {
+ proj = files.at(0);
+ }
+ }
+
+ makeCommand.Add("-top", proj);
+ if (!targetNames.empty()) {
+ if (std::find(targetNames.begin(), targetNames.end(), "clean") !=
+ targetNames.end()) {
+ makeCommand.Add("-clean");
} else {
- makeCommand.push_back(targetName);
+ for (const auto& tname : targetNames) {
+ if (!tname.empty()) {
+ makeCommand.Add(tname + ".tgt.gpj");
+ }
+ }
}
+ } else {
+ /* transform name to default build */;
+ std::string all = proj;
+ all.replace(all.end() - 7, all.end(),
+ std::string(this->GetAllTargetName()) + ".tgt.gpj");
+ makeCommand.Add(all);
}
+ return { makeCommand };
}
-void cmGlobalGhsMultiGenerator::WriteMacros()
+void cmGlobalGhsMultiGenerator::WriteMacros(std::ostream& fout,
+ cmLocalGenerator* root)
{
+ fout << "macro PROJ_NAME=" << root->GetProjectName() << std::endl;
char const* ghsGpjMacros =
this->GetCMakeInstance()->GetCacheDefinition("GHS_GPJ_MACROS");
- if (NULL != ghsGpjMacros) {
+ if (nullptr != ghsGpjMacros) {
std::vector<std::string> expandedList;
cmSystemTools::ExpandListArgument(std::string(ghsGpjMacros), expandedList);
- for (std::vector<std::string>::const_iterator expandedListI =
- expandedList.begin();
- expandedListI != expandedList.end(); ++expandedListI) {
- *this->GetBuildFileStream() << "macro " << *expandedListI << std::endl;
+ for (std::string const& arg : expandedList) {
+ fout << "macro " << arg << std::endl;
}
}
}
-void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives()
+void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives(
+ cmLocalGenerator* root, std::ostream& fout)
{
- *this->GetBuildFileStream() << "primaryTarget=arm_integrity.tgt"
- << std::endl;
+ /* set primary target */
+ std::string tgt;
+ const char* t =
+ this->GetCMakeInstance()->GetCacheDefinition("GHS_PRIMARY_TARGET");
+ if (t && *t != '\0') {
+ tgt = t;
+ this->GetCMakeInstance()->MarkCliAsUsed("GHS_PRIMARY_TARGET");
+ } else {
+ const char* a =
+ this->GetCMakeInstance()->GetCacheDefinition("CMAKE_GENERATOR_PLATFORM");
+ const char* p =
+ this->GetCMakeInstance()->GetCacheDefinition("GHS_TARGET_PLATFORM");
+ tgt = (a ? a : "");
+ tgt += "_";
+ tgt += (p ? p : "");
+ tgt += ".tgt";
+ }
+
+ fout << "primaryTarget=" << tgt << std::endl;
+ fout << "customization=" << root->GetBinaryDirectory()
+ << "/CMakeFiles/custom_rule.bod" << std::endl;
+ fout << "customization=" << root->GetBinaryDirectory()
+ << "/CMakeFiles/custom_target.bod" << std::endl;
+
char const* const customization =
this->GetCMakeInstance()->GetCacheDefinition("GHS_CUSTOMIZATION");
- if (NULL != customization && strlen(customization) > 0) {
- *this->GetBuildFileStream()
- << "customization=" << trimQuotes(customization) << std::endl;
+ if (nullptr != customization && strlen(customization) > 0) {
+ fout << "customization=" << this->TrimQuotes(customization) << std::endl;
this->GetCMakeInstance()->MarkCliAsUsed("GHS_CUSTOMIZATION");
}
}
-void cmGlobalGhsMultiGenerator::WriteCompilerOptions(std::string const& fOSDir)
+std::string cmGlobalGhsMultiGenerator::TrimQuotes(std::string const& str)
{
- *this->GetBuildFileStream() << " -os_dir=\"" << fOSDir << "\""
- << std::endl;
-}
-
-void cmGlobalGhsMultiGenerator::WriteDisclaimer(std::ostream* os)
-{
- (*os) << "#" << std::endl
- << "# CMAKE generated file: DO NOT EDIT!" << std::endl
- << "# Generated by \"" << GetActualName() << "\""
- << " Generator, CMake Version " << cmVersion::GetMajorVersion() << "."
- << cmVersion::GetMinorVersion() << std::endl
- << "#" << std::endl;
-}
-
-void cmGlobalGhsMultiGenerator::AddFilesUpToPath(
- cmGeneratedFileStream* mainBuildFile,
- std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
- char const* homeOutputDirectory, std::string const& path,
- GhsMultiGpj::Types projType, std::string const& relPath)
-{
- std::string workingPath(path);
- cmSystemTools::ConvertToUnixSlashes(workingPath);
- std::vector<cmsys::String> splitPath =
- cmSystemTools::SplitString(workingPath);
- std::string workingRelPath(relPath);
- cmSystemTools::ConvertToUnixSlashes(workingRelPath);
- if (!workingRelPath.empty()) {
- workingRelPath += "/";
- }
- std::string pathUpTo;
- for (std::vector<cmsys::String>::const_iterator splitPathI =
- splitPath.begin();
- splitPath.end() != splitPathI; ++splitPathI) {
- pathUpTo += *splitPathI;
- if (targetFolderBuildStreams->end() ==
- targetFolderBuildStreams->find(pathUpTo)) {
- AddFilesUpToPathNewBuildFile(
- mainBuildFile, targetFolderBuildStreams, homeOutputDirectory, pathUpTo,
- splitPath.begin() == splitPathI, workingRelPath, projType);
+ std::string result;
+ result.reserve(str.size());
+ for (const char* ch = str.c_str(); *ch != '\0'; ++ch) {
+ if (*ch != '"') {
+ result += *ch;
}
- AddFilesUpToPathAppendNextFile(targetFolderBuildStreams, pathUpTo,
- splitPathI, splitPath.end(), projType);
- pathUpTo += "/";
- }
-}
-
-void cmGlobalGhsMultiGenerator::Open(
- std::string const& mapKeyName, std::string const& fileName,
- std::map<std::string, cmGeneratedFileStream*>* fileMap)
-{
- if (fileMap->end() == fileMap->find(fileName)) {
- cmGeneratedFileStream* temp(new cmGeneratedFileStream);
- temp->open(fileName.c_str());
- (*fileMap)[mapKeyName] = temp;
}
+ return result;
}
-void cmGlobalGhsMultiGenerator::AddFilesUpToPathNewBuildFile(
- cmGeneratedFileStream* mainBuildFile,
- std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
- char const* homeOutputDirectory, std::string const& pathUpTo,
- bool const isFirst, std::string const& relPath,
- GhsMultiGpj::Types const projType)
+bool cmGlobalGhsMultiGenerator::TargetCompare::operator()(
+ cmGeneratorTarget const* l, cmGeneratorTarget const* r) const
{
- // create folders up to file path
- std::string absPath = std::string(homeOutputDirectory) + "/" + relPath;
- std::string newPath = absPath + pathUpTo;
- if (!cmSystemTools::FileExists(newPath.c_str())) {
- cmSystemTools::MakeDirectory(newPath.c_str());
+ // Make sure a given named target is ordered first,
+ // e.g. to set ALL_BUILD as the default active project.
+ // When the empty string is named this is a no-op.
+ if (r->GetName() == this->First) {
+ return false;
}
-
- // Write out to filename for first time
- std::string relFilename(GetFileNameFromPath(pathUpTo));
- std::string absFilename = absPath + relFilename;
- Open(pathUpTo, absFilename, targetFolderBuildStreams);
- OpenBuildFileStream((*targetFolderBuildStreams)[pathUpTo]);
- GhsMultiGpj::WriteGpjTag(projType, (*targetFolderBuildStreams)[pathUpTo]);
- WriteDisclaimer((*targetFolderBuildStreams)[pathUpTo]);
-
- // Add to main build file
- if (isFirst) {
- *mainBuildFile << relFilename << " ";
- GhsMultiGpj::WriteGpjTag(projType, mainBuildFile);
+ if (l->GetName() == this->First) {
+ return true;
}
+ return l->GetName() < r->GetName();
}
-void cmGlobalGhsMultiGenerator::AddFilesUpToPathAppendNextFile(
- std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
- std::string const& pathUpTo,
- std::vector<cmsys::String>::const_iterator splitPathI,
- std::vector<cmsys::String>::const_iterator end,
- GhsMultiGpj::Types const projType)
+cmGlobalGhsMultiGenerator::OrderedTargetDependSet::OrderedTargetDependSet(
+ TargetDependSet const& targets, std::string const& first)
+ : derived(TargetCompare(first))
{
- std::vector<cmsys::String>::const_iterator splitPathNextI = splitPathI + 1;
- if (end != splitPathNextI &&
- targetFolderBuildStreams->end() ==
- targetFolderBuildStreams->find(pathUpTo + "/" + *splitPathNextI)) {
- std::string nextFilename(*splitPathNextI);
- nextFilename = GetFileNameFromPath(nextFilename);
- *(*targetFolderBuildStreams)[pathUpTo] << nextFilename << " ";
- GhsMultiGpj::WriteGpjTag(projType, (*targetFolderBuildStreams)[pathUpTo]);
- }
+ this->insert(targets.begin(), targets.end());
}
-std::string cmGlobalGhsMultiGenerator::GetFileNameFromPath(
- std::string const& path)
+bool cmGlobalGhsMultiGenerator::ComputeTargetBuildOrder(
+ cmGeneratorTarget const* tgt, std::vector<cmGeneratorTarget const*>& build)
{
- std::string output(path);
- if (!path.empty()) {
- cmSystemTools::ConvertToUnixSlashes(output);
- std::vector<cmsys::String> splitPath = cmSystemTools::SplitString(output);
- output += "/" + splitPath.back() + FILE_EXTENSION;
- }
- return output;
+ std::vector<cmGeneratorTarget const*> t{ tgt };
+ return ComputeTargetBuildOrder(t, build);
}
-void cmGlobalGhsMultiGenerator::UpdateBuildFiles(
- std::vector<cmGeneratorTarget*> tgts)
+bool cmGlobalGhsMultiGenerator::ComputeTargetBuildOrder(
+ std::vector<cmGeneratorTarget const*>& tgt,
+ std::vector<cmGeneratorTarget const*>& build)
{
- for (std::vector<cmGeneratorTarget*>::iterator tgtsI = tgts.begin();
- tgtsI != tgts.end(); ++tgtsI) {
- const cmGeneratorTarget* tgt = *tgtsI;
- if (IsTgtForBuild(tgt)) {
- std::string folderName = tgt->GetEffectiveFolderName();
- if (this->TargetFolderBuildStreams.end() ==
- this->TargetFolderBuildStreams.find(folderName)) {
- this->AddFilesUpToPath(
- GetBuildFileStream(), &this->TargetFolderBuildStreams,
- this->GetCMakeInstance()->GetHomeOutputDirectory(), folderName,
- GhsMultiGpj::PROJECT);
- }
- std::vector<cmsys::String> splitPath = cmSystemTools::SplitString(
- cmGhsMultiTargetGenerator::GetRelBuildFileName(tgt));
- std::string foldNameRelBuildFile(*(splitPath.end() - 2) + "/" +
- splitPath.back());
- *this->TargetFolderBuildStreams[folderName] << foldNameRelBuildFile
- << " ";
- GhsMultiGpj::WriteGpjTag(cmGhsMultiTargetGenerator::GetGpjTag(tgt),
- this->TargetFolderBuildStreams[folderName]);
- }
- }
-}
+ std::set<cmGeneratorTarget const*> temp;
+ std::set<cmGeneratorTarget const*> perm;
-bool cmGlobalGhsMultiGenerator::IsTgtForBuild(const cmGeneratorTarget* tgt)
-{
- const std::string config =
- tgt->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
- std::vector<cmSourceFile*> tgtSources;
- tgt->GetSourceFiles(tgtSources, config);
- bool tgtInBuild = true;
- char const* excludeFromAll = tgt->GetProperty("EXCLUDE_FROM_ALL");
- if (NULL != excludeFromAll && '1' == excludeFromAll[0] &&
- '\0' == excludeFromAll[1]) {
- tgtInBuild = false;
+ for (auto ti : tgt) {
+ bool r = VisitTarget(temp, perm, build, ti);
+ if (r) {
+ return r;
+ }
}
- return !tgtSources.empty() && tgtInBuild;
+ return false;
}
-std::string cmGlobalGhsMultiGenerator::trimQuotes(std::string const& str)
+bool cmGlobalGhsMultiGenerator::VisitTarget(
+ std::set<cmGeneratorTarget const*>& temp,
+ std::set<cmGeneratorTarget const*>& perm,
+ std::vector<cmGeneratorTarget const*>& order, cmGeneratorTarget const* ti)
{
- std::string result;
- result.reserve(str.size());
- for (const char* ch = str.c_str(); *ch != '\0'; ++ch) {
- if (*ch != '"') {
- result += *ch;
+ /* check if permanent mark is set*/
+ if (perm.find(ti) == perm.end()) {
+ /* set temporary mark; check if revisit*/
+ if (temp.insert(ti).second) {
+ /* sort targets lexicographically to ensure that nodes are always visited
+ * in the same order */
+ OrderedTargetDependSet sortedTargets(this->GetTargetDirectDepends(ti),
+ "");
+ for (auto& di : sortedTargets) {
+ if (this->VisitTarget(temp, perm, order, di)) {
+ return true;
+ }
+ }
+ /* mark as complete; insert into beginning of list*/
+ perm.insert(ti);
+ order.push_back(ti);
+ return false;
}
+ /* revisiting item - not a DAG */
+ return true;
}
- return result;
+ /* already complete */
+ return false;
}
diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h
index 7b3eebbdf..98358c74d 100644
--- a/Source/cmGlobalGhsMultiGenerator.h
+++ b/Source/cmGlobalGhsMultiGenerator.h
@@ -5,33 +5,43 @@
#include "cmGlobalGenerator.h"
-#include "cmGhsMultiGpj.h"
#include "cmGlobalGeneratorFactory.h"
+#include "cmTargetDepend.h"
-class cmGeneratedFileStream;
+#include <iosfwd>
+#include <set>
+#include <string>
+#include <utility>
+#include <vector>
+
+class cmGeneratorTarget;
+class cmLocalGenerator;
+class cmMakefile;
+class cmake;
+struct cmDocumentationEntry;
class cmGlobalGhsMultiGenerator : public cmGlobalGenerator
{
public:
- /// The default name of GHS MULTI's build file. Typically: monolith.gpj.
+ // The default filename extension of GHS MULTI's build files.
static const char* FILE_EXTENSION;
cmGlobalGhsMultiGenerator(cmake* cm);
- ~cmGlobalGhsMultiGenerator();
+ ~cmGlobalGhsMultiGenerator() override;
static cmGlobalGeneratorFactory* NewFactory()
{
return new cmGlobalGeneratorSimpleFactory<cmGlobalGhsMultiGenerator>();
}
- ///! create the correct local generator
- virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf);
+ //! create the correct local generator
+ cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
/// @return the name of this generator.
static std::string GetActualName() { return "Green Hills MULTI"; }
- ///! Get the name for this generator
- virtual std::string GetName() const { return this->GetActualName(); }
+ //! Get the name for this generator
+ std::string GetName() const override { return GetActualName(); }
/// Overloaded methods. @see cmGlobalGenerator::GetDocumentation()
static void GetDocumentation(cmDocumentationEntry& entry);
@@ -40,94 +50,111 @@ public:
* Utilized by the generator factory to determine if this generator
* supports toolsets.
*/
- static bool SupportsToolset() { return false; }
+ static bool SupportsToolset() { return true; }
/**
* Utilized by the generator factory to determine if this generator
* supports platforms.
*/
- static bool SupportsPlatform() { return false; }
+ static bool SupportsPlatform() { return true; }
+
+ // Toolset / Platform Support
+ bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override;
+ bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
/**
- * 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 to determine system information such as shared library
+ * extension, pthreads, byte order etc.
+ */
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
/*
- * Determine what program to use for building the project.
- */
- bool FindMakeProgram(cmMakefile* mf) CM_OVERRIDE;
+ * Determine what program to use for building the project.
+ */
+ bool FindMakeProgram(cmMakefile* mf) override;
- cmGeneratedFileStream* GetBuildFileStream()
- {
- return this->TargetFolderBuildStreams[""];
- }
+ void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
+
+ // Write the common disclaimer text at the top of each build file.
+ void WriteFileHeader(std::ostream& fout);
- static void OpenBuildFileStream(std::string const& filepath,
- cmGeneratedFileStream** filestream);
- static void OpenBuildFileStream(cmGeneratedFileStream* filestream);
- static void CloseBuildFileStream(cmGeneratedFileStream** filestream);
- /// Write the common disclaimer text at the top of each build file.
- static void WriteDisclaimer(std::ostream* os);
- std::vector<std::string> GetLibDirs() { return this->LibDirs; }
-
- static void AddFilesUpToPath(
- cmGeneratedFileStream* mainBuildFile,
- std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
- char const* homeOutputDirectory, std::string const& path,
- GhsMultiGpj::Types projType, std::string const& relPath = "");
- static void Open(std::string const& mapKeyName, std::string const& fileName,
- std::map<std::string, cmGeneratedFileStream*>* fileMap);
-
- static std::string trimQuotes(std::string const& str);
- inline bool IsOSDirRelative() { return this->OSDirRelative; }
+ const char* GetInstallTargetName() const override { return "install"; }
protected:
- virtual void Generate();
- 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,
- bool verbose,
- std::vector<std::string> const& makeOptions = std::vector<std::string>());
+ void Generate() override;
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
private:
- std::string const& GetGhsBuildCommand();
- std::string FindGhsBuildCommand();
- std::string GetCompRoot();
- std::vector<std::string> GetCompRootHardPaths();
- std::vector<std::string> GetCompRootRegistry();
- void OpenBuildFileStream();
-
- void WriteMacros();
- void WriteHighLevelDirectives();
- void WriteCompilerOptions(std::string const& fOSDir);
-
- static void AddFilesUpToPathNewBuildFile(
- cmGeneratedFileStream* mainBuildFile,
- std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
- char const* homeOutputDirectory, std::string const& pathUpTo, bool isFirst,
- std::string const& relPath, GhsMultiGpj::Types projType);
- static void AddFilesUpToPathAppendNextFile(
- std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
- std::string const& pathUpTo,
- std::vector<cmsys::String>::const_iterator splitPathI,
- std::vector<cmsys::String>::const_iterator end,
- GhsMultiGpj::Types projType);
- static std::string GetFileNameFromPath(std::string const& path);
- void UpdateBuildFiles(std::vector<cmGeneratorTarget*> tgts);
- bool IsTgtForBuild(const cmGeneratorTarget* tgt);
-
- std::vector<cmGeneratedFileStream*> TargetSubProjects;
- std::map<std::string, cmGeneratedFileStream*> TargetFolderBuildStreams;
-
- std::vector<std::string> LibDirs;
-
- bool OSDirRelative;
- bool GhsBuildCommandInitialized;
- std::string GhsBuildCommand;
- static const char* DEFAULT_MAKE_PROGRAM;
+ void GetToolset(cmMakefile* mf, std::string& tsd, const std::string& ts);
+
+ /* top-level project */
+ void OutputTopLevelProject(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators);
+ void WriteTopLevelProject(std::ostream& fout, cmLocalGenerator* root);
+ void WriteMacros(std::ostream& fout, cmLocalGenerator* root);
+ void WriteHighLevelDirectives(cmLocalGenerator* root, std::ostream& fout);
+ void WriteSubProjects(std::ostream& fout, std::string& all_target);
+ void WriteTargets(cmLocalGenerator* root);
+ void WriteProjectLine(std::ostream& fout, cmGeneratorTarget const* target,
+ cmLocalGenerator* root, std::string& rootBinaryDir);
+ void WriteCustomRuleBOD(std::ostream& fout);
+ void WriteCustomTargetBOD(std::ostream& fout);
+ void WriteAllTarget(cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators,
+ std::string& all_target);
+
+ std::string TrimQuotes(std::string const& str);
+
+ std::string OsDir;
+ static const char* DEFAULT_BUILD_PROGRAM;
+ static const char* DEFAULT_TOOLSET_ROOT;
+
+ bool ComputeTargetBuildOrder(cmGeneratorTarget const* tgt,
+ std::vector<cmGeneratorTarget const*>& build);
+ bool ComputeTargetBuildOrder(std::vector<cmGeneratorTarget const*>& tgt,
+ std::vector<cmGeneratorTarget const*>& build);
+ bool VisitTarget(std::set<cmGeneratorTarget const*>& temp,
+ std::set<cmGeneratorTarget const*>& perm,
+ std::vector<cmGeneratorTarget const*>& order,
+ cmGeneratorTarget const* ti);
+
+ std::vector<cmGeneratorTarget const*> ProjectTargets;
+
+ // Target sorting
+ class TargetSet : public std::set<cmGeneratorTarget const*>
+ {
+ };
+ class TargetCompare
+ {
+ std::string First;
+
+ public:
+ TargetCompare(std::string first)
+ : First(std::move(first))
+ {
+ }
+ bool operator()(cmGeneratorTarget const* l,
+ cmGeneratorTarget const* r) const;
+ };
+ class OrderedTargetDependSet;
+};
+
+class cmGlobalGhsMultiGenerator::OrderedTargetDependSet
+ : public std::multiset<cmTargetDepend,
+ cmGlobalGhsMultiGenerator::TargetCompare>
+{
+ typedef std::multiset<cmTargetDepend,
+ cmGlobalGhsMultiGenerator::TargetCompare>
+ derived;
+
+public:
+ typedef cmGlobalGenerator::TargetDependSet TargetDependSet;
+ OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
};
#endif
diff --git a/Source/cmGlobalJOMMakefileGenerator.cxx b/Source/cmGlobalJOMMakefileGenerator.cxx
index 18c45e0d8..ff5428868 100644
--- a/Source/cmGlobalJOMMakefileGenerator.cxx
+++ b/Source/cmGlobalJOMMakefileGenerator.cxx
@@ -6,6 +6,7 @@
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
#include "cmState.h"
+#include "cmake.h"
cmGlobalJOMMakefileGenerator::cmGlobalJOMMakefileGenerator(cmake* cm)
: cmGlobalUnixMakefileGenerator3(cm)
@@ -52,3 +53,29 @@ void cmGlobalJOMMakefileGenerator::PrintCompilerAdvice(
}
this->cmGlobalUnixMakefileGenerator3::PrintCompilerAdvice(os, lang, envVar);
}
+
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalJOMMakefileGenerator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions)
+{
+ std::vector<std::string> jomMakeOptions;
+
+ // Since we have full control over the invocation of JOM, let us
+ // make it quiet.
+ jomMakeOptions.push_back(this->MakeSilentFlag);
+ cmAppend(jomMakeOptions, makeOptions);
+
+ // JOM does parallel builds by default, the -j is only needed if a specific
+ // number is given
+ // see https://github.com/qt-labs/jom/blob/v1.1.2/src/jomlib/options.cpp
+ if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
+ jobs = cmake::NO_BUILD_PARALLEL_LEVEL;
+ }
+
+ return cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
+ makeProgram, projectName, projectDir, targetNames, config, fast, jobs,
+ verbose, jomMakeOptions);
+}
diff --git a/Source/cmGlobalJOMMakefileGenerator.h b/Source/cmGlobalJOMMakefileGenerator.h
index 2e8ee2939..df3aec9b4 100644
--- a/Source/cmGlobalJOMMakefileGenerator.h
+++ b/Source/cmGlobalJOMMakefileGenerator.h
@@ -5,6 +5,8 @@
#include "cmGlobalUnixMakefileGenerator3.h"
+#include <iosfwd>
+
/** \class cmGlobalJOMMakefileGenerator
* \brief Write a JOM makefiles.
*
@@ -18,8 +20,8 @@ public:
{
return new cmGlobalGeneratorSimpleFactory<cmGlobalJOMMakefileGenerator>();
}
- ///! Get the name for the generator.
- virtual std::string GetName() const
+ //! Get the name for the generator.
+ std::string GetName() const override
{
return cmGlobalJOMMakefileGenerator::GetActualName();
}
@@ -34,12 +36,20 @@ public:
* 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);
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
+
+protected:
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
private:
void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
- const char* envVar) const;
+ const char* envVar) const override;
};
#endif
diff --git a/Source/cmGlobalMSYSMakefileGenerator.cxx b/Source/cmGlobalMSYSMakefileGenerator.cxx
index 3f223824a..7b5838909 100644
--- a/Source/cmGlobalMSYSMakefileGenerator.cxx
+++ b/Source/cmGlobalMSYSMakefileGenerator.cxx
@@ -7,6 +7,7 @@
#include "cmDocumentationEntry.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmState.h"
#include "cmake.h"
@@ -44,9 +45,10 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage(
std::vector<std::string> const& l, cmMakefile* mf, bool optional)
{
this->FindMakeProgram(mf);
- std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& makeProgram =
+ mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::vector<std::string> locations;
- std::string makeloc = cmSystemTools::GetProgramPath(makeProgram.c_str());
+ std::string makeloc = cmSystemTools::GetProgramPath(makeProgram);
locations.push_back(this->FindMinGW(makeloc));
locations.push_back(makeloc);
locations.push_back("/mingw/bin");
@@ -75,8 +77,8 @@ void cmGlobalMSYSMakefileGenerator::EnableLanguage(
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"));
+ "CMAKE_AR was not found, please set to archive program. " +
+ mf->GetSafeDefinition("CMAKE_AR"));
}
}
diff --git a/Source/cmGlobalMSYSMakefileGenerator.h b/Source/cmGlobalMSYSMakefileGenerator.h
index 23dbc5e31..d6e4847fe 100644
--- a/Source/cmGlobalMSYSMakefileGenerator.h
+++ b/Source/cmGlobalMSYSMakefileGenerator.h
@@ -19,7 +19,7 @@ public:
return new cmGlobalGeneratorSimpleFactory<cmGlobalMSYSMakefileGenerator>();
}
- ///! Get the name for the generator.
+ //! Get the name for the generator.
virtual std::string GetName() const
{
return cmGlobalMSYSMakefileGenerator::GetActualName();
diff --git a/Source/cmGlobalMinGWMakefileGenerator.cxx b/Source/cmGlobalMinGWMakefileGenerator.cxx
index 3c3a5d1dc..e218b4b95 100644
--- a/Source/cmGlobalMinGWMakefileGenerator.cxx
+++ b/Source/cmGlobalMinGWMakefileGenerator.cxx
@@ -6,6 +6,7 @@
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
#include "cmState.h"
+#include "cmake.h"
cmGlobalMinGWMakefileGenerator::cmGlobalMinGWMakefileGenerator(cmake* cm)
: cmGlobalUnixMakefileGenerator3(cm)
@@ -22,7 +23,8 @@ void cmGlobalMinGWMakefileGenerator::EnableLanguage(
std::vector<std::string> const& l, cmMakefile* mf, bool optional)
{
this->FindMakeProgram(mf);
- std::string makeProgram = mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
+ const std::string& makeProgram =
+ mf->GetRequiredDefinition("CMAKE_MAKE_PROGRAM");
std::vector<std::string> locations;
locations.push_back(cmSystemTools::GetProgramPath(makeProgram));
locations.push_back("/mingw/bin");
diff --git a/Source/cmGlobalMinGWMakefileGenerator.h b/Source/cmGlobalMinGWMakefileGenerator.h
index a994c9295..15297e3c7 100644
--- a/Source/cmGlobalMinGWMakefileGenerator.h
+++ b/Source/cmGlobalMinGWMakefileGenerator.h
@@ -19,7 +19,7 @@ public:
return new cmGlobalGeneratorSimpleFactory<
cmGlobalMinGWMakefileGenerator>();
}
- ///! Get the name for the generator.
+ //! Get the name for the generator.
virtual std::string GetName() const
{
return cmGlobalMinGWMakefileGenerator::GetActualName();
diff --git a/Source/cmGlobalNMakeMakefileGenerator.cxx b/Source/cmGlobalNMakeMakefileGenerator.cxx
index da683fb39..2273c00ac 100644
--- a/Source/cmGlobalNMakeMakefileGenerator.cxx
+++ b/Source/cmGlobalNMakeMakefileGenerator.cxx
@@ -6,6 +6,7 @@
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
#include "cmState.h"
+#include "cmake.h"
cmGlobalNMakeMakefileGenerator::cmGlobalNMakeMakefileGenerator(cmake* cm)
: cmGlobalUnixMakefileGenerator3(cm)
@@ -52,3 +53,40 @@ void cmGlobalNMakeMakefileGenerator::PrintCompilerAdvice(
}
this->cmGlobalUnixMakefileGenerator3::PrintCompilerAdvice(os, lang, envVar);
}
+
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalNMakeMakefileGenerator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int /*jobs*/, bool verbose,
+ std::vector<std::string> const& makeOptions)
+{
+ std::vector<std::string> nmakeMakeOptions;
+
+ // Since we have full control over the invocation of nmake, let us
+ // make it quiet.
+ nmakeMakeOptions.push_back(this->MakeSilentFlag);
+ cmAppend(nmakeMakeOptions, makeOptions);
+
+ return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
+ makeProgram, projectName, projectDir, targetNames, config, fast,
+ cmake::NO_BUILD_PARALLEL_LEVEL, verbose, nmakeMakeOptions);
+}
+
+void cmGlobalNMakeMakefileGenerator::PrintBuildCommandAdvice(std::ostream& os,
+ int jobs) const
+{
+ if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
+ // nmake does not support parallel build level
+ // see https://msdn.microsoft.com/en-us/library/afyyse50.aspx
+
+ /* clang-format off */
+ os <<
+ "Warning: NMake does not support parallel builds. "
+ "Ignoring parallel build command line option.\n";
+ /* clang-format on */
+ }
+
+ this->cmGlobalUnixMakefileGenerator3::PrintBuildCommandAdvice(
+ os, cmake::NO_BUILD_PARALLEL_LEVEL);
+}
diff --git a/Source/cmGlobalNMakeMakefileGenerator.h b/Source/cmGlobalNMakeMakefileGenerator.h
index 6eb21249d..2fdf1ce5d 100644
--- a/Source/cmGlobalNMakeMakefileGenerator.h
+++ b/Source/cmGlobalNMakeMakefileGenerator.h
@@ -5,6 +5,8 @@
#include "cmGlobalUnixMakefileGenerator3.h"
+#include <iosfwd>
+
/** \class cmGlobalNMakeMakefileGenerator
* \brief Write a NMake makefiles.
*
@@ -19,15 +21,15 @@ public:
return new cmGlobalGeneratorSimpleFactory<
cmGlobalNMakeMakefileGenerator>();
}
- ///! Get the name for the generator.
- virtual std::string GetName() const
+ //! Get the name for the generator.
+ std::string GetName() const override
{
return cmGlobalNMakeMakefileGenerator::GetActualName();
}
static std::string GetActualName() { return "NMake Makefiles"; }
/** Get encoding used by generator for makefile files */
- codecvt::Encoding GetMakefileEncoding() const CM_OVERRIDE
+ codecvt::Encoding GetMakefileEncoding() const override
{
return codecvt::ANSI;
}
@@ -39,12 +41,22 @@ public:
* 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);
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
+
+protected:
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
+
+ void PrintBuildCommandAdvice(std::ostream& os, int jobs) const override;
private:
void PrintCompilerAdvice(std::ostream& os, std::string const& lang,
- const char* envVar) const;
+ const char* envVar) const override;
};
#endif
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 2eef9e492..2d52356bc 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -8,8 +8,8 @@
#include "cmsys/FStream.hxx"
#include <algorithm>
#include <ctype.h>
-#include <functional>
#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
@@ -19,11 +19,14 @@
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpressionEvaluationFile.h"
#include "cmGeneratorTarget.h"
+#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmLocalNinjaGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmNinjaLinkLineComputer.h"
#include "cmOutputConverter.h"
+#include "cmRange.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
@@ -32,7 +35,6 @@
#include "cmTarget.h"
#include "cmTargetDepend.h"
#include "cmVersion.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
class cmLinkLineComputer;
@@ -90,43 +92,18 @@ std::string cmGlobalNinjaGenerator::EncodeRuleName(std::string const& name)
// Ninja rule names must match "[a-zA-Z0-9_.-]+". Use ".xx" to encode
// "." and all invalid characters as hexadecimal.
std::string encoded;
- for (std::string::const_iterator i = name.begin(); i != name.end(); ++i) {
- if (isalnum(*i) || *i == '_' || *i == '-') {
- encoded += *i;
+ for (char i : name) {
+ if (isalnum(i) || i == '_' || i == '-') {
+ encoded += i;
} else {
char buf[16];
- sprintf(buf, ".%02x", static_cast<unsigned int>(*i));
+ sprintf(buf, ".%02x", static_cast<unsigned int>(i));
encoded += buf;
}
}
return encoded;
}
-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;
- std::ostringstream names;
- names << "ident" << VarNum++;
- vars << names.str() << " = " << ident << "\n";
- return "$" + names.str();
- }
- std::string result = ident;
- cmSystemTools::ReplaceString(result, " ", "$ ");
- cmSystemTools::ReplaceString(result, ":", "$:");
- return result;
-}
-
std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string& lit)
{
std::string result = lit;
@@ -137,293 +114,256 @@ std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string& lit)
std::string cmGlobalNinjaGenerator::EncodePath(const std::string& path)
{
- std::string result = path; // NOLINT(clang-tidy)
+ std::string result = path;
#ifdef _WIN32
if (this->IsGCCOnWindows())
std::replace(result.begin(), result.end(), '\\', '/');
else
std::replace(result.begin(), result.end(), '/', '\\');
#endif
- return EncodeLiteral(result);
+ result = EncodeLiteral(result);
+ cmSystemTools::ReplaceString(result, " ", "$ ");
+ cmSystemTools::ReplaceString(result, ":", "$:");
+ return result;
}
-void cmGlobalNinjaGenerator::WriteBuild(
- std::ostream& os, const std::string& comment, const std::string& rule,
- const cmNinjaDeps& outputs, const cmNinjaDeps& implicitOuts,
- const cmNinjaDeps& explicitDeps, const cmNinjaDeps& implicitDeps,
- const cmNinjaDeps& orderOnlyDeps, const cmNinjaVars& variables,
- const std::string& rspfile, int cmdLineLimit, bool* usedResponseFile)
+void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os,
+ cmNinjaBuild const& build,
+ int cmdLineLimit,
+ bool* usedResponseFile)
{
// Make sure there is a rule.
- if (rule.empty()) {
- cmSystemTools::Error("No rule for WriteBuildStatement! called "
- "with comment: ",
- comment.c_str());
+ if (build.Rule.empty()) {
+ cmSystemTools::Error("No rule for WriteBuild! called with comment: " +
+ build.Comment);
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());
+ if (build.Outputs.empty()) {
+ cmSystemTools::Error(
+ "No output files for WriteBuild! called with comment: " + build.Comment);
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);
- }
+ cmGlobalNinjaGenerator::WriteComment(os, build.Comment);
- // Write implicit dependencies.
- if (!implicitDeps.empty()) {
- arguments += " |";
- for (cmNinjaDeps::const_iterator i = implicitDeps.begin();
- i != implicitDeps.end(); ++i) {
- arguments += " " + EncodeIdent(EncodePath(*i), os);
+ // Write output files.
+ std::string buildStr("build");
+ {
+ // Write explicit outputs
+ for (std::string const& output : build.Outputs) {
+ buildStr += " " + EncodePath(output);
+ if (this->ComputingUnknownDependencies) {
+ this->CombinedBuildOutputs.insert(output);
+ }
}
- }
-
- // Write order-only dependencies.
- if (!orderOnlyDeps.empty()) {
- arguments += " ||";
- for (cmNinjaDeps::const_iterator i = orderOnlyDeps.begin();
- i != orderOnlyDeps.end(); ++i) {
- arguments += " " + EncodeIdent(EncodePath(*i), os);
+ // Write implicit outputs
+ if (!build.ImplicitOuts.empty()) {
+ buildStr += " |";
+ for (std::string const& implicitOut : build.ImplicitOuts) {
+ buildStr += " " + EncodePath(implicitOut);
+ }
}
+ buildStr += ":";
+
+ // Write the rule.
+ buildStr += " ";
+ buildStr += build.Rule;
}
- arguments += "\n";
+ std::string arguments;
+ {
+ // TODO: Better formatting for when there are multiple input/output files.
- std::string build;
+ // Write explicit dependencies.
+ for (std::string const& explicitDep : build.ExplicitDeps) {
+ arguments += " " + EncodePath(explicitDep);
+ }
- // Write outputs files.
- build += "build";
- for (cmNinjaDeps::const_iterator i = outputs.begin(); i != outputs.end();
- ++i) {
- build += " " + EncodeIdent(EncodePath(*i), os);
- if (this->ComputingUnknownDependencies) {
- this->CombinedBuildOutputs.insert(*i);
+ // Write implicit dependencies.
+ if (!build.ImplicitDeps.empty()) {
+ arguments += " |";
+ for (std::string const& implicitDep : build.ImplicitDeps) {
+ arguments += " " + EncodePath(implicitDep);
+ }
}
- }
- if (!implicitOuts.empty()) {
- build += " |";
- for (cmNinjaDeps::const_iterator i = implicitOuts.begin();
- i != implicitOuts.end(); ++i) {
- build += " " + EncodeIdent(EncodePath(*i), os);
+
+ // Write order-only dependencies.
+ if (!build.OrderOnlyDeps.empty()) {
+ arguments += " ||";
+ for (std::string const& orderOnlyDep : build.OrderOnlyDeps) {
+ arguments += " " + EncodePath(orderOnlyDep);
+ }
}
- }
- build += ":";
- // Write the rule.
- build += " " + rule;
+ arguments += "\n";
+ }
// Write the variables bound to this build statement.
- std::ostringstream variable_assignments;
- for (cmNinjaVars::const_iterator i = variables.begin(); i != variables.end();
- ++i) {
- cmGlobalNinjaGenerator::WriteVariable(variable_assignments, i->first,
- i->second, "", 1);
- }
+ std::string assignments;
+ {
+ std::ostringstream variable_assignments;
+ for (auto const& variable : build.Variables) {
+ cmGlobalNinjaGenerator::WriteVariable(
+ variable_assignments, variable.first, variable.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;
- bool useResponseFile = false;
- if (cmdLineLimit < 0 ||
- (cmdLineLimit > 0 &&
- (args.size() + buildstr.size() + assignments.size() + 1000) >
- static_cast<size_t>(cmdLineLimit))) {
- variable_assignments.str(std::string());
- cmGlobalNinjaGenerator::WriteVariable(variable_assignments, "RSP_FILE",
- rspfile, "", 1);
- assignments += variable_assignments.str();
- useResponseFile = true;
- }
- if (usedResponseFile) {
- *usedResponseFile = useResponseFile;
+ // check if a response file rule should be used
+ assignments = variable_assignments.str();
+ bool useResponseFile = false;
+ if (cmdLineLimit < 0 ||
+ (cmdLineLimit > 0 &&
+ (arguments.size() + buildStr.size() + assignments.size() + 1000) >
+ static_cast<size_t>(cmdLineLimit))) {
+ variable_assignments.str(std::string());
+ cmGlobalNinjaGenerator::WriteVariable(variable_assignments, "RSP_FILE",
+ build.RspFile, "", 1);
+ assignments += variable_assignments.str();
+ useResponseFile = true;
+ }
+ if (usedResponseFile) {
+ *usedResponseFile = useResponseFile;
+ }
}
- 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,
- /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps,
- orderOnlyDeps, variables);
+ os << buildStr << arguments << assignments << "\n";
}
void cmGlobalNinjaGenerator::AddCustomCommandRule()
{
- this->AddRule("CUSTOM_COMMAND", "$COMMAND", "$DESC",
- "Rule for running custom commands.",
- /*depfile*/ "",
- /*deptype*/ "",
- /*rspfile*/ "",
- /*rspcontent*/ "",
- /*restat*/ "", // bound on each build statement as needed
- /*generator*/ false);
+ cmNinjaRule rule("CUSTOM_COMMAND");
+ rule.Command = "$COMMAND";
+ rule.Description = "$DESC";
+ rule.Comment = "Rule for running custom commands.";
+ this->AddRule(rule);
}
void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
const std::string& command, const std::string& description,
- const std::string& comment, const std::string& depfile, bool uses_terminal,
- bool restat, const cmNinjaDeps& outputs, const cmNinjaDeps& deps,
- const cmNinjaDeps& orderOnly)
+ const std::string& comment, const std::string& depfile,
+ const std::string& job_pool, bool uses_terminal, bool restat,
+ const cmNinjaDeps& outputs, const cmNinjaDeps& explicitDeps,
+ const cmNinjaDeps& orderOnlyDeps)
{
- std::string cmd = command; // NOLINT(clang-tidy)
-#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);
- if (restat) {
- vars["restat"] = "1";
- }
- if (uses_terminal && SupportsConsolePool()) {
- vars["pool"] = "console";
- }
- if (!depfile.empty()) {
- vars["depfile"] = depfile;
+ {
+ cmNinjaBuild build("CUSTOM_COMMAND");
+ build.Comment = comment;
+ build.Outputs = outputs;
+ build.ExplicitDeps = explicitDeps;
+ build.OrderOnlyDeps = orderOnlyDeps;
+
+ cmNinjaVars& vars = build.Variables;
+ {
+ std::string cmd = command; // NOLINT(*)
+#ifdef _WIN32
+ if (cmd.empty())
+ // TODO Shouldn't an empty command be handled by ninja?
+ cmd = "cmd.exe /c";
+#endif
+ vars["COMMAND"] = std::move(cmd);
+ }
+ vars["DESC"] = EncodeLiteral(description);
+ if (restat) {
+ vars["restat"] = "1";
+ }
+ if (uses_terminal && SupportsConsolePool()) {
+ vars["pool"] = "console";
+ } else if (!job_pool.empty()) {
+ vars["pool"] = job_pool;
+ }
+ if (!depfile.empty()) {
+ vars["depfile"] = depfile;
+ }
+ this->WriteBuild(*this->BuildFileStream, build);
}
- this->WriteBuild(*this->BuildFileStream, comment, "CUSTOM_COMMAND", outputs,
- /*implicitOuts=*/cmNinjaDeps(), deps, cmNinjaDeps(),
- orderOnly, vars);
if (this->ComputingUnknownDependencies) {
// 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(*i);
+ for (std::string const& dep : explicitDeps) {
+ this->CombinedCustomCommandExplicitDependencies.insert(dep);
}
}
}
void cmGlobalNinjaGenerator::AddMacOSXContentRule()
{
- cmLocalGenerator* lg = this->LocalGenerators[0];
-
- std::ostringstream cmd;
- cmd << lg->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(),
- cmOutputConverter::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*/ "",
- /*generator*/ false);
+ cmNinjaRule rule("COPY_OSX_CONTENT");
+ rule.Command = CMakeCmd() + " -E copy $in $out";
+ rule.Description = "Copying OS X Content $out";
+ rule.Comment = "Rule for copying OS X bundle content file.";
+ this->AddRule(rule);
}
-void cmGlobalNinjaGenerator::WriteMacOSXContentBuild(const std::string& input,
- const std::string& output)
+void cmGlobalNinjaGenerator::WriteMacOSXContentBuild(std::string input,
+ 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,
- /*implicitOuts=*/cmNinjaDeps(), deps, cmNinjaDeps(),
- cmNinjaDeps(), cmNinjaVars());
+ {
+ cmNinjaBuild build("COPY_OSX_CONTENT");
+ build.Outputs.push_back(std::move(output));
+ build.ExplicitDeps.push_back(std::move(input));
+ this->WriteBuild(*this->BuildFileStream, build);
+ }
}
-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,
- const std::string& restat, bool generator)
+void cmGlobalNinjaGenerator::WriteRule(std::ostream& os,
+ cmNinjaRule const& rule)
{
+ // -- Parameter checks
// Make sure the rule has a name.
- if (name.empty()) {
- cmSystemTools::Error("No name given for WriteRuleStatement! called "
- "with comment: ",
- comment.c_str());
+ if (rule.Name.empty()) {
+ cmSystemTools::Error("No name given for WriteRule! called with comment: " +
+ rule.Comment);
return;
}
// Make sure a command is given.
- if (command.empty()) {
- cmSystemTools::Error("No command given for WriteRuleStatement! called "
- "with comment: ",
- comment.c_str());
+ if (rule.Command.empty()) {
+ cmSystemTools::Error(
+ "No command given for WriteRule! called with comment: " + rule.Comment);
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";
+ // Make sure response file content is given
+ if (!rule.RspFile.empty() && rule.RspContent.empty()) {
+ cmSystemTools::Error("rspfile but no rspfile_content given for WriteRule! "
+ "called with comment: " +
+ rule.Comment);
+ return;
}
- // 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";
- }
+ // -- Write rule
+ // Write rule intro
+ cmGlobalNinjaGenerator::WriteComment(os, rule.Comment);
+ os << "rule " << rule.Name << '\n';
- if (!rspfile.empty()) {
- if (rspcontent.empty()) {
- cmSystemTools::Error("No rspfile_content given!", comment.c_str());
- return;
+ // Write rule key/value pairs
+ auto writeKV = [&os](const char* key, std::string const& value) {
+ if (!value.empty()) {
+ cmGlobalNinjaGenerator::Indent(os, 1);
+ os << key << " = " << value << '\n';
}
- cmGlobalNinjaGenerator::Indent(os, 1);
- os << "rspfile = " << rspfile << "\n";
- cmGlobalNinjaGenerator::Indent(os, 1);
- os << "rspfile_content = " << rspcontent << "\n";
- }
+ };
- if (!restat.empty()) {
- cmGlobalNinjaGenerator::Indent(os, 1);
- os << "restat = " << restat << "\n";
+ writeKV("depfile", rule.DepFile);
+ writeKV("deps", rule.DepType);
+ writeKV("command", rule.Command);
+ writeKV("description", rule.Description);
+ if (!rule.RspFile.empty()) {
+ writeKV("rspfile", rule.RspFile);
+ writeKV("rspfile_content", rule.RspContent);
}
-
- if (generator) {
- cmGlobalNinjaGenerator::Indent(os, 1);
- os << "generator = 1\n";
+ writeKV("restat", rule.Restat);
+ if (rule.Generator) {
+ writeKV("generator", "1");
}
- os << "\n";
+ // Finish rule
+ os << '\n';
}
void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
@@ -435,8 +375,8 @@ void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
// Make sure we have a name.
if (name.empty()) {
cmSystemTools::Error("No name given for WriteVariable! called "
- "with comment: ",
- comment.c_str());
+ "with comment: " +
+ comment);
return;
}
@@ -465,25 +405,21 @@ void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os,
{
cmGlobalNinjaGenerator::WriteComment(os, comment);
os << "default";
- for (cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end();
- ++i) {
- os << " " << *i;
+ for (std::string const& target : targets) {
+ os << " " << target;
}
os << "\n";
}
cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
: cmGlobalCommonGenerator(cm)
- , BuildFileStream(CM_NULLPTR)
- , RulesFileStream(CM_NULLPTR)
- , CompileCommandsStream(CM_NULLPTR)
- , Rules()
- , AllDependencies()
, UsingGCCOnWindows(false)
, ComputingUnknownDependencies(false)
, PolicyCMP0058(cmPolicies::WARN)
, NinjaSupportsConsolePool(false)
, NinjaSupportsImplicitOuts(false)
+ , NinjaSupportsManifestRestat(false)
+ , NinjaSupportsMultilineDepfile(false)
, NinjaSupportsDyndeps(0)
{
#ifdef _WIN32
@@ -532,12 +468,17 @@ void cmGlobalNinjaGenerator::Generate()
std::ostringstream msg;
msg << "The detected version of Ninja (" << this->NinjaVersion;
msg << ") is less than the version of Ninja required by CMake (";
- msg << this->RequiredNinjaVersion() << ").";
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str());
+ msg << cmGlobalNinjaGenerator::RequiredNinjaVersion() << ").";
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ msg.str());
+ return;
+ }
+ if (!this->OpenBuildFileStream()) {
+ return;
+ }
+ if (!this->OpenRulesFileStream()) {
return;
}
- this->OpenBuildFileStream();
- this->OpenRulesFileStream();
this->TargetDependsClosures.clear();
@@ -579,15 +520,16 @@ bool cmGlobalNinjaGenerator::FindMakeProgram(cmMakefile* mf)
this->NinjaCommand = ninjaCommand;
std::vector<std::string> command;
command.push_back(this->NinjaCommand);
- command.push_back("--version");
+ command.emplace_back("--version");
std::string version;
std::string error;
- if (!cmSystemTools::RunSingleCommand(command, &version, &error, CM_NULLPTR,
- CM_NULLPTR,
+ if (!cmSystemTools::RunSingleCommand(command, &version, &error, nullptr,
+ nullptr,
cmSystemTools::OUTPUT_NONE)) {
- mf->IssueMessage(cmake::FATAL_ERROR, "Running\n '" +
- cmJoin(command, "' '") + "'\n"
- "failed with:\n " +
+ mf->IssueMessage(MessageType::FATAL_ERROR,
+ "Running\n '" + cmJoin(command, "' '") +
+ "'\n"
+ "failed with:\n " +
error);
cmSystemTools::SetFatalErrorOccured();
return false;
@@ -605,14 +547,20 @@ void cmGlobalNinjaGenerator::CheckNinjaFeatures()
RequiredNinjaVersionForConsolePool().c_str());
this->NinjaSupportsImplicitOuts = !cmSystemTools::VersionCompare(
cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
- this->RequiredNinjaVersionForImplicitOuts().c_str());
+ cmGlobalNinjaGenerator::RequiredNinjaVersionForImplicitOuts().c_str());
+ this->NinjaSupportsManifestRestat = !cmSystemTools::VersionCompare(
+ cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
+ RequiredNinjaVersionForManifestRestat().c_str());
+ this->NinjaSupportsMultilineDepfile = !cmSystemTools::VersionCompare(
+ cmSystemTools::OP_LESS, this->NinjaVersion.c_str(),
+ RequiredNinjaVersionForMultilineDepfile().c_str());
{
// Our ninja branch adds ".dyndep-#" to its version number,
// where '#' is a feature-specific version number. Extract it.
static std::string const k_DYNDEP_ = ".dyndep-";
std::string::size_type pos = this->NinjaVersion.find(k_DYNDEP_);
if (pos != std::string::npos) {
- const char* fv = this->NinjaVersion.c_str() + pos + k_DYNDEP_.size();
+ const char* fv = &this->NinjaVersion[pos + k_DYNDEP_.size()];
cmSystemTools::StringToULong(fv, &this->NinjaSupportsDyndeps);
}
}
@@ -661,7 +609,7 @@ bool cmGlobalNinjaGenerator::CheckFortran(cmMakefile* mf) const
;
/* clang-format on */
}
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -670,21 +618,27 @@ void cmGlobalNinjaGenerator::EnableLanguage(
std::vector<std::string> const& langs, cmMakefile* mf, bool optional)
{
this->cmGlobalGenerator::EnableLanguage(langs, mf, optional);
- for (std::vector<std::string>::const_iterator l = langs.begin();
- l != langs.end(); ++l) {
- if (*l == "NONE") {
+ for (std::string const& l : langs) {
+ if (l == "NONE") {
continue;
}
- this->ResolveLanguageCompiler(*l, mf, optional);
+ this->ResolveLanguageCompiler(l, mf, optional);
}
#ifdef _WIN32
- if (strcmp(mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID"), "MSVC") != 0 &&
- strcmp(mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID"), "MSVC") != 0 &&
- (mf->IsOn("CMAKE_COMPILER_IS_MINGW") ||
- strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "GNU") == 0 ||
- strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "GNU") == 0 ||
- strcmp(mf->GetSafeDefinition("CMAKE_C_COMPILER_ID"), "Clang") == 0 ||
- strcmp(mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"), "Clang") == 0)) {
+ const bool clangGnuMode =
+ ((mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") &&
+ (mf->GetSafeDefinition("CMAKE_C_COMPILER_FRONTEND_VARIANT") == "GNU")) ||
+ ((mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang") &&
+ (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_FRONTEND_VARIANT") == "GNU"));
+
+ if (clangGnuMode ||
+ ((mf->GetSafeDefinition("CMAKE_C_SIMULATE_ID") != "MSVC") &&
+ (mf->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID") != "MSVC") &&
+ (mf->IsOn("CMAKE_COMPILER_IS_MINGW") ||
+ (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "GNU") ||
+ (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "GNU") ||
+ (mf->GetSafeDefinition("CMAKE_C_COMPILER_ID") == "Clang") ||
+ (mf->GetSafeDefinition("CMAKE_CXX_COMPILER_ID") == "Clang")))) {
this->UsingGCCOnWindows = true;
}
#endif
@@ -698,56 +652,52 @@ void cmGlobalNinjaGenerator::EnableLanguage(
// 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*/,
- bool verbose, std::vector<std::string> const& makeOptions)
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalNinjaGenerator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& /*projectName*/,
+ const std::string& /*projectDir*/,
+ std::vector<std::string> const& targetNames, const std::string& /*config*/,
+ bool /*fast*/, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions)
{
- makeCommand.push_back(this->SelectMakeProgram(makeProgram));
+ GeneratedMakeCommand makeCommand;
+ makeCommand.Add(this->SelectMakeProgram(makeProgram));
if (verbose) {
- makeCommand.push_back("-v");
+ makeCommand.Add("-v");
}
- 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);
+ if ((jobs != cmake::NO_BUILD_PARALLEL_LEVEL) &&
+ (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL)) {
+ makeCommand.Add("-j", std::to_string(jobs));
+ }
+
+ makeCommand.Add(makeOptions.begin(), makeOptions.end());
+ for (const auto& tname : targetNames) {
+ if (!tname.empty()) {
+ makeCommand.Add(tname);
}
}
+ return { std::move(makeCommand) };
}
// 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,
- const std::string& restat, bool generator)
+void cmGlobalNinjaGenerator::AddRule(cmNinjaRule const& rule)
{
// Do not add the same rule twice.
- if (this->HasRule(name)) {
+ if (!this->Rules.insert(rule.Name).second) {
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();
+ // Store command length
+ this->RuleCmdLength[rule.Name] = static_cast<int>(rule.Command.size());
+ // Write rule
+ cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream, rule);
}
bool cmGlobalNinjaGenerator::HasRule(const std::string& name)
{
- RulesSetType::const_iterator rule = this->Rules.find(name);
- return (rule != this->Rules.end());
+ return (this->Rules.find(name) != this->Rules.end());
}
// Private virtual overrides
@@ -773,7 +723,7 @@ void cmGlobalNinjaGenerator::ComputeTargetObjectDirectory(
// Private methods
-void cmGlobalNinjaGenerator::OpenBuildFileStream()
+bool cmGlobalNinjaGenerator::OpenBuildFileStream()
{
// Compute Ninja's build file path.
std::string buildFilePath =
@@ -783,12 +733,12 @@ void cmGlobalNinjaGenerator::OpenBuildFileStream()
// Get a stream where to generate things.
if (!this->BuildFileStream) {
- this->BuildFileStream = new cmGeneratedFileStream(
- buildFilePath.c_str(), false, this->GetMakefileEncoding());
- if (!this->BuildFileStream) {
+ this->BuildFileStream = cm::make_unique<cmGeneratedFileStream>(
+ buildFilePath, false, this->GetMakefileEncoding());
+ if (!(*this->BuildFileStream)) {
// An error message is generated by the constructor if it cannot
// open the file.
- return;
+ return false;
}
}
@@ -799,19 +749,20 @@ void cmGlobalNinjaGenerator::OpenBuildFileStream()
*this->BuildFileStream
<< "# This file contains all the build statements describing the\n"
<< "# compilation DAG.\n\n";
+
+ return true;
}
void cmGlobalNinjaGenerator::CloseBuildFileStream()
{
if (this->BuildFileStream) {
- delete this->BuildFileStream;
- this->BuildFileStream = CM_NULLPTR;
+ this->BuildFileStream.reset();
} else {
cmSystemTools::Error("Build file stream was not open.");
}
}
-void cmGlobalNinjaGenerator::OpenRulesFileStream()
+bool cmGlobalNinjaGenerator::OpenRulesFileStream()
{
// Compute Ninja's build file path.
std::string rulesFilePath =
@@ -821,12 +772,12 @@ void cmGlobalNinjaGenerator::OpenRulesFileStream()
// Get a stream where to generate things.
if (!this->RulesFileStream) {
- this->RulesFileStream = new cmGeneratedFileStream(
- rulesFilePath.c_str(), false, this->GetMakefileEncoding());
- if (!this->RulesFileStream) {
+ this->RulesFileStream = cm::make_unique<cmGeneratedFileStream>(
+ rulesFilePath, false, this->GetMakefileEncoding());
+ if (!(*this->RulesFileStream)) {
// An error message is generated by the constructor if it cannot
// open the file.
- return;
+ return false;
}
}
@@ -841,13 +792,13 @@ void cmGlobalNinjaGenerator::OpenRulesFileStream()
<< "# It is included in the main '" << NINJA_BUILD_FILE << "'.\n\n"
;
/* clang-format on */
+ return true;
}
void cmGlobalNinjaGenerator::CloseRulesFileStream()
{
if (this->RulesFileStream) {
- delete this->RulesFileStream;
- this->RulesFileStream = CM_NULLPTR;
+ this->RulesFileStream.reset();
} else {
cmSystemTools::Error("Rules file stream was not open.");
}
@@ -858,7 +809,7 @@ static void EnsureTrailingSlash(std::string& path)
if (path.empty()) {
return;
}
- std::string::value_type last = path[path.size() - 1];
+ std::string::value_type last = path.back();
#ifdef _WIN32
if (last != '\\') {
path += '\\';
@@ -870,18 +821,29 @@ static void EnsureTrailingSlash(std::string& path)
#endif
}
-std::string cmGlobalNinjaGenerator::ConvertToNinjaPath(
+std::string const& cmGlobalNinjaGenerator::ConvertToNinjaPath(
const std::string& path) const
{
+ auto const f = ConvertToNinjaPathCache.find(path);
+ if (f != ConvertToNinjaPathCache.end()) {
+ return f->second;
+ }
+
cmLocalNinjaGenerator* ng =
static_cast<cmLocalNinjaGenerator*>(this->LocalGenerators[0]);
- std::string convPath = ng->ConvertToRelativePath(
- this->LocalGenerators[0]->GetState()->GetBinaryDirectory(), path);
+ std::string const& bin_dir = ng->GetState()->GetBinaryDirectory();
+ std::string convPath = ng->MaybeConvertToRelativePath(bin_dir, path);
convPath = this->NinjaOutputPath(convPath);
#ifdef _WIN32
std::replace(convPath.begin(), convPath.end(), '/', '\\');
#endif
- return convPath;
+ return ConvertToNinjaPathCache.emplace(path, std::move(convPath))
+ .first->second;
+}
+
+void cmGlobalNinjaGenerator::AddAdditionalCleanFile(std::string fileName)
+{
+ this->AdditionalCleanFiles.emplace(std::move(fileName));
}
void cmGlobalNinjaGenerator::AddCXXCompileCommand(
@@ -899,25 +861,25 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand(
// Get a stream where to generate things.
this->CompileCommandsStream =
- new cmGeneratedFileStream(buildFilePath.c_str());
+ cm::make_unique<cmGeneratedFileStream>(buildFilePath);
*this->CompileCommandsStream << "[";
} else {
*this->CompileCommandsStream << "," << std::endl;
}
std::string sourceFileName = sourceFile;
- if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(sourceFileName)) {
sourceFileName = cmSystemTools::CollapseFullPath(
sourceFileName, this->GetCMakeInstance()->GetHomeOutputDirectory());
}
/* clang-format off */
*this->CompileCommandsStream << "\n{\n"
- << " \"directory\": \""
+ << R"( "directory": ")"
<< cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
- << " \"command\": \""
+ << R"( "command": ")"
<< cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
- << " \"file\": \""
+ << R"( "file": ")"
<< cmGlobalGenerator::EscapeJSON(sourceFileName) << "\"\n"
<< "}";
/* clang-format on */
@@ -927,8 +889,7 @@ void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
{
if (this->CompileCommandsStream) {
*this->CompileCommandsStream << "\n]";
- delete this->CompileCommandsStream;
- this->CompileCommandsStream = CM_NULLPTR;
+ this->CompileCommandsStream.reset();
}
}
@@ -952,15 +913,16 @@ void cmGlobalNinjaGenerator::AddDependencyToAll(const std::string& 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));
+ for (auto const& asd : this->AssumedSourceDependencies) {
+ cmNinjaDeps orderOnlyDeps;
+ std::copy(asd.second.begin(), asd.second.end(),
+ std::back_inserter(orderOnlyDeps));
WriteCustomCommandBuild(/*command=*/"", /*description=*/"",
"Assume dependencies for generated source file.",
- /*depfile*/ "", /*uses_terminal*/ false,
- /*restat*/ true, cmNinjaDeps(1, i->first), deps);
+ /*depfile*/ "", /*job_pool*/ "",
+ /*uses_terminal*/ false,
+ /*restat*/ true, cmNinjaDeps(1, asd.first),
+ cmNinjaDeps(), orderOnlyDeps);
}
}
@@ -1024,63 +986,72 @@ void cmGlobalNinjaGenerator::AppendTargetDepends(
{
if (target->GetType() == cmStateEnums::GLOBAL_TARGET) {
// These depend only on other CMake-provided targets, e.g. "all".
- std::set<std::string> const& utils = target->GetUtilities();
- for (std::set<std::string>::const_iterator i = utils.begin();
- i != utils.end(); ++i) {
+ for (BT<std::string> const& util : target->GetUtilities()) {
std::string d =
- target->GetLocalGenerator()->GetCurrentBinaryDirectory() +
- std::string("/") + *i;
+ target->GetLocalGenerator()->GetCurrentBinaryDirectory() + "/" +
+ util.Value;
outputs.push_back(this->ConvertToNinjaPath(d));
}
} else {
cmNinjaDeps outs;
- cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target);
- for (cmTargetDependSet::const_iterator i = targetDeps.begin();
- i != targetDeps.end(); ++i) {
- if ((*i)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (cmTargetDepend const& targetDep :
+ this->GetTargetDirectDepends(target)) {
+ if (targetDep->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- this->AppendTargetOutputs(*i, outs, depends);
+ this->AppendTargetOutputs(targetDep, outs, depends);
}
std::sort(outs.begin(), outs.end());
- outputs.insert(outputs.end(), outs.begin(), outs.end());
+ cmAppend(outputs, outs);
}
}
void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
cmGeneratorTarget const* target, cmNinjaDeps& outputs)
{
- TargetDependsClosureMap::iterator i =
- this->TargetDependsClosures.find(target);
- if (i == this->TargetDependsClosures.end()) {
- TargetDependsClosureMap::value_type e(
- target, std::set<cmGeneratorTarget const*>());
- i = this->TargetDependsClosures.insert(e).first;
- this->ComputeTargetDependsClosure(target, i->second);
- }
- std::set<cmGeneratorTarget const*> const& targets = i->second;
- cmNinjaDeps outs;
- for (std::set<cmGeneratorTarget const*>::const_iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- this->AppendTargetOutputs(*ti, outs);
- }
- std::sort(outs.begin(), outs.end());
- outputs.insert(outputs.end(), outs.begin(), outs.end());
+ cmNinjaOuts outs;
+ this->AppendTargetDependsClosure(target, outs, true);
+ cmAppend(outputs, outs);
}
-void cmGlobalNinjaGenerator::ComputeTargetDependsClosure(
- cmGeneratorTarget const* target, std::set<cmGeneratorTarget const*>& depends)
+void cmGlobalNinjaGenerator::AppendTargetDependsClosure(
+ cmGeneratorTarget const* target, cmNinjaOuts& outputs, bool omit_self)
{
- cmTargetDependSet const& targetDeps = this->GetTargetDirectDepends(target);
- for (cmTargetDependSet::const_iterator i = targetDeps.begin();
- i != targetDeps.end(); ++i) {
- if ((*i)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
- continue;
- }
- if (depends.insert(*i).second) {
- this->ComputeTargetDependsClosure(*i, depends);
+
+ // try to locate the target in the cache
+ auto find = this->TargetDependsClosures.lower_bound(target);
+
+ if (find == this->TargetDependsClosures.end() || find->first != target) {
+ // We now calculate the closure outputs by inspecting the dependent
+ // targets recursively.
+ // For that we have to distinguish between a local result set that is only
+ // relevant for filling the cache entries properly isolated and a global
+ // result set that is relevant for the result of the top level call to
+ // AppendTargetDependsClosure.
+ cmNinjaOuts this_outs; // this will be the new cache entry
+
+ for (auto const& dep_target : this->GetTargetDirectDepends(target)) {
+ if (dep_target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ continue;
+ }
+
+ // Collect the dependent targets for _this_ target
+ this->AppendTargetDependsClosure(dep_target, this_outs, false);
}
+ find = this->TargetDependsClosures.emplace_hint(find, target,
+ std::move(this_outs));
+ }
+
+ // now fill the outputs of the final result from the newly generated cache
+ // entry
+ outputs.insert(find->second.begin(), find->second.end());
+
+ // finally generate the outputs of the target itself, if applicable
+ cmNinjaDeps outs;
+ if (!omit_self) {
+ this->AppendTargetOutputs(target, outs);
}
+ outputs.insert(outs.begin(), outs.end());
}
void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
@@ -1091,8 +1062,8 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
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] = CM_NULLPTR;
+ for (std::string const& output : outputs) {
+ TargetAliases[output] = nullptr;
}
// Insert the alias into the map. If the alias was already present in the
@@ -1100,7 +1071,7 @@ void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias,
std::pair<TargetAliasMap::iterator, bool> newAlias =
TargetAliases.insert(std::make_pair(buildAlias, target));
if (newAlias.second && newAlias.first->second != target) {
- newAlias.first->second = CM_NULLPTR;
+ newAlias.first->second = nullptr;
}
}
@@ -1109,17 +1080,27 @@ 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) {
+ cmNinjaBuild build("phony");
+ build.Outputs.emplace_back("");
+ for (auto const& ta : TargetAliases) {
// Don't write ambiguous aliases.
- if (!i->second) {
+ if (!ta.second) {
continue;
}
- cmNinjaDeps deps;
- this->AppendTargetOutputs(i->second, deps);
+ // Don't write alias if there is a already a custom command with
+ // matching output
+ if (this->HasCustomCommandOutput(ta.first)) {
+ continue;
+ }
- this->WritePhonyBuild(os, "", cmNinjaDeps(1, i->first), deps);
+ // Outputs
+ build.Outputs[0] = ta.first;
+ // Explicit depdendencies
+ build.ExplicitDeps.clear();
+ this->AppendTargetOutputs(ta.second, build.ExplicitDeps);
+ // Write
+ this->WriteBuild(os, build);
}
}
@@ -1128,20 +1109,23 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
cmGlobalNinjaGenerator::WriteDivider(os);
os << "# Folder targets.\n\n";
+ std::string const& rootBinaryDir =
+ this->LocalGenerators[0]->GetBinaryDirectory();
+
std::map<std::string, cmNinjaDeps> targetsPerFolder;
- for (std::vector<cmLocalGenerator*>::const_iterator lgi =
- this->LocalGenerators.begin();
- lgi != this->LocalGenerators.end(); ++lgi) {
- cmLocalGenerator const* lg = *lgi;
- const std::string currentBinaryFolder(
+ for (cmLocalGenerator const* lg : this->LocalGenerators) {
+ std::string const& currentBinaryFolder(
lg->GetStateSnapshot().GetDirectory().GetCurrentBinary());
+
+ // Do not generate a rule for the root binary dir.
+ if (currentBinaryFolder == rootBinaryDir) {
+ continue;
+ }
+
// The directory-level rule should depend on the target-level rules
// for all targets in the directory.
- targetsPerFolder[currentBinaryFolder] = cmNinjaDeps();
- for (std::vector<cmGeneratorTarget*>::const_iterator ti =
- lg->GetGeneratorTargets().begin();
- ti != lg->GetGeneratorTargets().end(); ++ti) {
- cmGeneratorTarget const* gt = *ti;
+ cmNinjaDeps& folderTargets = targetsPerFolder[currentBinaryFolder];
+ for (auto gt : lg->GetGeneratorTargets()) {
cmStateEnums::TargetType const type = gt->GetType();
if ((type == cmStateEnums::EXECUTABLE ||
type == cmStateEnums::STATIC_LIBRARY ||
@@ -1150,43 +1134,34 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
type == cmStateEnums::OBJECT_LIBRARY ||
type == cmStateEnums::UTILITY) &&
!gt->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
- targetsPerFolder[currentBinaryFolder].push_back(gt->GetName());
+ folderTargets.push_back(gt->GetName());
}
}
// The directory-level rule should depend on the directory-level
// rules of the subdirectories.
- std::vector<cmStateSnapshot> const& children =
- lg->GetStateSnapshot().GetChildren();
- for (std::vector<cmStateSnapshot>::const_iterator stateIt =
- children.begin();
- stateIt != children.end(); ++stateIt) {
- std::string const currentBinaryDir =
- stateIt->GetDirectory().GetCurrentBinary();
-
- targetsPerFolder[currentBinaryFolder].push_back(
+ for (cmStateSnapshot const& state : lg->GetStateSnapshot().GetChildren()) {
+ std::string const& currentBinaryDir =
+ state.GetDirectory().GetCurrentBinary();
+ folderTargets.push_back(
this->ConvertToNinjaPath(currentBinaryDir + "/all"));
}
}
- std::string const rootBinaryDir =
- this->LocalGenerators[0]->GetBinaryDirectory();
- for (std::map<std::string, cmNinjaDeps>::const_iterator it =
- targetsPerFolder.begin();
- it != targetsPerFolder.end(); ++it) {
- cmGlobalNinjaGenerator::WriteDivider(os);
- std::string const& currentBinaryDir = it->first;
+ if (!targetsPerFolder.empty()) {
+ cmNinjaBuild build("phony");
+ build.Outputs.emplace_back("");
+ for (auto& it : targetsPerFolder) {
+ cmGlobalNinjaGenerator::WriteDivider(os);
+ std::string const& currentBinaryDir = it.first;
- // Do not generate a rule for the root binary dir.
- if (rootBinaryDir.length() >= currentBinaryDir.length()) {
- continue;
+ // Setup target
+ build.Comment = "Folder: " + currentBinaryDir;
+ build.Outputs[0] = this->ConvertToNinjaPath(currentBinaryDir + "/all");
+ build.ExplicitDeps = std::move(it.second);
+ // Write target
+ this->WriteBuild(os, build);
}
-
- std::string const comment = "Folder: " + currentBinaryDir;
- cmNinjaDeps output(1);
- output.push_back(this->ConvertToNinjaPath(currentBinaryDir + "/all"));
-
- this->WritePhonyBuild(os, comment, output, it->second);
}
}
@@ -1220,50 +1195,37 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
// get the list of files that cmake itself has generated as a
// product of configuration.
- for (std::vector<cmLocalGenerator*>::const_iterator i =
- this->LocalGenerators.begin();
- i != this->LocalGenerators.end(); ++i) {
+ for (cmLocalGenerator* lg : this->LocalGenerators) {
// 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(this->ConvertToNinjaPath(*j));
+ for (std::string const& file : lg->GetMakefile()->GetOutputFiles()) {
+ knownDependencies.insert(this->ConvertToNinjaPath(file));
}
- // 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(this->ConvertToNinjaPath(*j));
+ if (!this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) {
+ // get list files which are implicit dependencies as well and will be
+ // phony for rebuild manifest
+ for (std::string const& j : lg->GetMakefile()->GetListFiles()) {
+ knownDependencies.insert(this->ConvertToNinjaPath(j));
+ }
}
- std::vector<cmGeneratorExpressionEvaluationFile*> const& ef =
- (*i)->GetMakefile()->GetEvaluationFiles();
- for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
- ef.begin();
- li != ef.end(); ++li) {
+ for (cmGeneratorExpressionEvaluationFile* li :
+ lg->GetMakefile()->GetEvaluationFiles()) {
// get all the files created by generator expressions and convert them
// to ninja paths
- std::vector<std::string> evaluationFiles = (*li)->GetFiles();
- for (vect_it j = evaluationFiles.begin(); j != evaluationFiles.end();
- ++j) {
- knownDependencies.insert(this->ConvertToNinjaPath(*j));
+ for (std::string const& evaluationFile : li->GetFiles()) {
+ knownDependencies.insert(this->ConvertToNinjaPath(evaluationFile));
}
}
}
knownDependencies.insert(this->CMakeCacheFile);
- for (TargetAliasMap::const_iterator i = this->TargetAliases.begin();
- i != this->TargetAliases.end(); ++i) {
- knownDependencies.insert(this->ConvertToNinjaPath(i->first));
+ for (auto const& ta : this->TargetAliases) {
+ knownDependencies.insert(this->ConvertToNinjaPath(ta.first));
}
// 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(this->ConvertToNinjaPath(i->first));
+ for (auto const& i : this->AssumedSourceDependencies) {
+ knownDependencies.insert(this->ConvertToNinjaPath(i.first));
}
// now we difference with CombinedCustomCommandExplicitDependencies to find
@@ -1280,25 +1242,26 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
knownDependencies.begin(), knownDependencies.end(),
std::back_inserter(unknownExplicitDepends));
- std::string const rootBuildDirectory =
- this->GetCMakeInstance()->GetHomeOutputDirectory();
- bool const inSourceBuild =
- (rootBuildDirectory == this->GetCMakeInstance()->GetHomeDirectory());
std::vector<std::string> warnExplicitDepends;
- for (std::vector<std::string>::const_iterator i =
- unknownExplicitDepends.begin();
- i != unknownExplicitDepends.end(); ++i) {
- // verify the file is in the build directory
- std::string const absDepPath =
- cmSystemTools::CollapseFullPath(*i, rootBuildDirectory.c_str());
- bool const inBuildDir =
- cmSystemTools::IsSubDirectory(absDepPath, rootBuildDirectory);
- if (inBuildDir) {
- cmNinjaDeps deps(1, *i);
- this->WritePhonyBuild(os, "", deps, cmNinjaDeps());
- if (this->PolicyCMP0058 == cmPolicies::WARN && !inSourceBuild &&
- warnExplicitDepends.size() < 10) {
- warnExplicitDepends.push_back(*i);
+ if (!unknownExplicitDepends.empty()) {
+ cmake* cmk = this->GetCMakeInstance();
+ std::string const& buildRoot = cmk->GetHomeOutputDirectory();
+ bool const inSource = (buildRoot == cmk->GetHomeDirectory());
+ bool const warn = (!inSource && (this->PolicyCMP0058 == cmPolicies::WARN));
+ cmNinjaBuild build("phony");
+ build.Outputs.emplace_back("");
+ for (std::string const& ued : unknownExplicitDepends) {
+ // verify the file is in the build directory
+ std::string const absDepPath =
+ cmSystemTools::CollapseFullPath(ued, buildRoot);
+ if (cmSystemTools::IsSubDirectory(absDepPath, buildRoot)) {
+ // Generate phony build statement
+ build.Outputs[0] = ued;
+ this->WriteBuild(os, build);
+ // Add to warning on demand
+ if (warn && warnExplicitDepends.size() < 10) {
+ warnExplicitDepends.push_back(ued);
+ }
}
}
}
@@ -1320,7 +1283,8 @@ void cmGlobalNinjaGenerator::WriteUnknownExplicitDependencies(std::ostream& os)
"options to the custom commands that produce these files."
;
/* clang-format on */
- this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING,
+ w.str());
}
}
@@ -1338,79 +1302,140 @@ void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os)
void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
{
- cmNinjaDeps outputs;
- outputs.push_back(this->TargetAll);
-
- this->WritePhonyBuild(os, "The main all target.", outputs,
- this->AllDependencies);
+ cmNinjaBuild build("phony");
+ build.Comment = "The main all target.";
+ build.Outputs.push_back(this->TargetAll);
+ build.ExplicitDeps = this->AllDependencies;
+ this->WriteBuild(os, build);
if (!this->HasOutputPathPrefix()) {
- cmGlobalNinjaGenerator::WriteDefault(os, outputs,
+ cmGlobalNinjaGenerator::WriteDefault(os, build.Outputs,
"Make the all target the default.");
}
}
void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os)
{
+ if (this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) {
+ return;
+ }
cmLocalGenerator* lg = this->LocalGenerators[0];
- std::ostringstream cmd;
- cmd << lg->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(),
- cmOutputConverter::SHELL)
- << " -H"
- << lg->ConvertToOutputFormat(lg->GetSourceDirectory(),
- cmOutputConverter::SHELL)
- << " -B"
- << lg->ConvertToOutputFormat(lg->GetBinaryDirectory(),
- cmOutputConverter::SHELL);
- WriteRule(*this->RulesFileStream, "RERUN_CMAKE", cmd.str(),
- "Re-running CMake...", "Rule for re-running cmake.",
- /*depfile=*/"",
- /*deptype=*/"",
- /*rspfile=*/"",
- /*rspcontent*/ "",
- /*restat=*/"",
- /*generator=*/true);
-
- 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(this->ConvertToNinjaPath(*fi));
+ {
+ cmNinjaRule rule("RERUN_CMAKE");
+ rule.Command = CMakeCmd();
+ rule.Command += " -S";
+ rule.Command += lg->ConvertToOutputFormat(lg->GetSourceDirectory(),
+ cmOutputConverter::SHELL);
+ rule.Command += " -B";
+ rule.Command += lg->ConvertToOutputFormat(lg->GetBinaryDirectory(),
+ cmOutputConverter::SHELL);
+ rule.Description = "Re-running CMake...";
+ rule.Comment = "Rule for re-running cmake.";
+ rule.Generator = true;
+ WriteRule(*this->RulesFileStream, rule);
+ }
+
+ cmNinjaBuild reBuild("RERUN_CMAKE");
+ reBuild.Comment = "Re-run CMake if any of its inputs changed.";
+ reBuild.Outputs.push_back(this->NinjaOutputPath(NINJA_BUILD_FILE));
+
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ for (std::string const& fi : localGen->GetMakefile()->GetListFiles()) {
+ reBuild.ImplicitDeps.push_back(this->ConvertToNinjaPath(fi));
}
}
- implicitDeps.push_back(this->CMakeCacheFile);
+ reBuild.ImplicitDeps.push_back(this->CMakeCacheFile);
- 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 (SupportsConsolePool()) {
- variables["pool"] = "console";
+ reBuild.Variables["pool"] = "console";
}
- std::string const ninjaBuildFile = this->NinjaOutputPath(NINJA_BUILD_FILE);
- this->WriteBuild(os, "Re-run CMake if any of its inputs changed.",
- "RERUN_CMAKE",
- /*outputs=*/cmNinjaDeps(1, ninjaBuildFile),
- /*implicitOuts=*/cmNinjaDeps(),
- /*explicitDeps=*/cmNinjaDeps(), implicitDeps,
- /*orderOnlyDeps=*/cmNinjaDeps(), variables);
+ cmake* cm = this->GetCMakeInstance();
+ if (this->SupportsManifestRestat() && cm->DoWriteGlobVerifyTarget()) {
+ {
+ cmNinjaRule rule("VERIFY_GLOBS");
+ rule.Command = CMakeCmd();
+ rule.Command += " -P ";
+ rule.Command += lg->ConvertToOutputFormat(cm->GetGlobVerifyScript(),
+ cmOutputConverter::SHELL);
+ rule.Description = "Re-checking globbed directories...";
+ rule.Comment = "Rule for re-checking globbed directories.";
+ rule.Generator = true;
+ this->WriteRule(*this->RulesFileStream, rule);
+ }
+
+ cmNinjaBuild phonyBuild("phony");
+ phonyBuild.Comment = "Phony target to force glob verification run.";
+ phonyBuild.Outputs.push_back(cm->GetGlobVerifyScript() + "_force");
+ this->WriteBuild(os, phonyBuild);
- this->WritePhonyBuild(os, "A missing CMake input file is not an error.",
- implicitDeps, cmNinjaDeps());
+ reBuild.Variables["restat"] = "1";
+ std::string const verifyScriptFile =
+ this->NinjaOutputPath(cm->GetGlobVerifyScript());
+ std::string const verifyStampFile =
+ this->NinjaOutputPath(cm->GetGlobVerifyStamp());
+ {
+ cmNinjaBuild vgBuild("VERIFY_GLOBS");
+ vgBuild.Comment =
+ "Re-run CMake to check if globbed directories changed.";
+ vgBuild.Outputs.push_back(verifyStampFile);
+ vgBuild.ImplicitDeps = phonyBuild.Outputs;
+ vgBuild.Variables = reBuild.Variables;
+ this->WriteBuild(os, vgBuild);
+ }
+ reBuild.Variables.erase("restat");
+ reBuild.ImplicitDeps.push_back(verifyScriptFile);
+ reBuild.ExplicitDeps.push_back(verifyStampFile);
+ } else if (!this->SupportsManifestRestat() &&
+ cm->DoWriteGlobVerifyTarget()) {
+ std::ostringstream msg;
+ msg << "The detected version of Ninja:\n"
+ << " " << this->NinjaVersion << "\n"
+ << "is less than the version of Ninja required by CMake for adding "
+ "restat dependencies to the build.ninja manifest regeneration "
+ "target:\n"
+ << " "
+ << cmGlobalNinjaGenerator::RequiredNinjaVersionForManifestRestat()
+ << "\n";
+ msg << "Any pre-check scripts, such as those generated for file(GLOB "
+ "CONFIGURE_DEPENDS), will not be run by Ninja.";
+ this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING,
+ msg.str());
+ }
+
+ std::sort(reBuild.ImplicitDeps.begin(), reBuild.ImplicitDeps.end());
+ reBuild.ImplicitDeps.erase(
+ std::unique(reBuild.ImplicitDeps.begin(), reBuild.ImplicitDeps.end()),
+ reBuild.ImplicitDeps.end());
+
+ this->WriteBuild(os, reBuild);
+
+ {
+ cmNinjaBuild build("phony");
+ build.Comment = "A missing CMake input file is not an error.";
+ std::set_difference(std::make_move_iterator(reBuild.ImplicitDeps.begin()),
+ std::make_move_iterator(reBuild.ImplicitDeps.end()),
+ CustomCommandOutputs.begin(),
+ CustomCommandOutputs.end(),
+ std::back_inserter(build.Outputs));
+ this->WriteBuild(os, build);
+ }
+}
+
+std::string cmGlobalNinjaGenerator::CMakeCmd() const
+{
+ cmLocalGenerator* lgen = this->LocalGenerators.at(0);
+ return lgen->ConvertToOutputFormat(cmSystemTools::GetCMakeCommand(),
+ cmOutputConverter::SHELL);
}
-std::string cmGlobalNinjaGenerator::ninjaCmd() const
+std::string cmGlobalNinjaGenerator::NinjaCmd() const
{
cmLocalGenerator* lgen = this->LocalGenerators[0];
- if (lgen) {
+ if (lgen != nullptr) {
return lgen->ConvertToOutputFormat(this->NinjaCommand,
cmOutputConverter::SHELL);
}
@@ -1427,44 +1452,116 @@ bool cmGlobalNinjaGenerator::SupportsImplicitOuts() const
return this->NinjaSupportsImplicitOuts;
}
+bool cmGlobalNinjaGenerator::SupportsManifestRestat() const
+{
+ return this->NinjaSupportsManifestRestat;
+}
+
+bool cmGlobalNinjaGenerator::SupportsMultilineDepfile() const
+{
+ return this->NinjaSupportsMultilineDepfile;
+}
+
+bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os)
+{
+ cmLocalGenerator* lgr = this->LocalGenerators.at(0);
+ std::string cleanScriptRel = "CMakeFiles/clean_additional.cmake";
+ std::string cleanScriptAbs = lgr->GetBinaryDirectory();
+ cleanScriptAbs += '/';
+ cleanScriptAbs += cleanScriptRel;
+
+ // Check if there are additional files to clean
+ if (this->AdditionalCleanFiles.empty()) {
+ // Remove cmake clean script file if it exists
+ cmSystemTools::RemoveFile(cleanScriptAbs);
+ return false;
+ }
+
+ // Write cmake clean script file
+ {
+ cmGeneratedFileStream fout(cleanScriptAbs);
+ if (!fout) {
+ return false;
+ }
+ fout << "# Additional clean files\n\n";
+ fout << "file(REMOVE_RECURSE\n";
+ for (std::string const& acf : this->AdditionalCleanFiles) {
+ fout << " "
+ << cmOutputConverter::EscapeForCMake(ConvertToNinjaPath(acf))
+ << '\n';
+ }
+ fout << ")\n";
+ }
+ // Register clean script file
+ lgr->GetMakefile()->AddCMakeOutputFile(cleanScriptAbs);
+
+ // Write rule
+ {
+ cmNinjaRule rule("CLEAN_ADDITIONAL");
+ rule.Command = CMakeCmd();
+ rule.Command += " -P ";
+ rule.Command += lgr->ConvertToOutputFormat(
+ this->NinjaOutputPath(cleanScriptRel), cmOutputConverter::SHELL);
+ rule.Description = "Cleaning additional files...";
+ rule.Comment = "Rule for cleaning additional files.";
+ WriteRule(*this->RulesFileStream, rule);
+ }
+
+ // Write build
+ {
+ cmNinjaBuild build("CLEAN_ADDITIONAL");
+ build.Comment = "Clean additional files.";
+ build.Outputs.push_back(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+ WriteBuild(os, build);
+ }
+ // Return success
+ return true;
+}
+
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=*/"",
- /*generator=*/false);
- WriteBuild(os, "Clean all the built files.", "CLEAN",
- /*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("clean")),
- /*implicitOuts=*/cmNinjaDeps(),
- /*explicitDeps=*/cmNinjaDeps(),
- /*implicitDeps=*/cmNinjaDeps(),
- /*orderOnlyDeps=*/cmNinjaDeps(),
- /*variables=*/cmNinjaVars());
+ // -- Additional clean target
+ bool additionalFiles = WriteTargetCleanAdditional(os);
+
+ // -- Default clean target
+ // Write rule
+ {
+ cmNinjaRule rule("CLEAN");
+ rule.Command = NinjaCmd() + " -t clean";
+ rule.Description = "Cleaning all built files...";
+ rule.Comment = "Rule for cleaning all built files.";
+ WriteRule(*this->RulesFileStream, rule);
+ }
+
+ // Write build
+ {
+ cmNinjaBuild build("CLEAN");
+ build.Comment = "Clean all the built files.";
+ build.Outputs.push_back(this->NinjaOutputPath(this->GetCleanTargetName()));
+ if (additionalFiles) {
+ build.ExplicitDeps.push_back(
+ this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+ }
+ WriteBuild(os, build);
+ }
}
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=*/"",
- /*generator=*/false);
- WriteBuild(os, "Print all primary targets available.", "HELP",
- /*outputs=*/cmNinjaDeps(1, this->NinjaOutputPath("help")),
- /*implicitOuts=*/cmNinjaDeps(),
- /*explicitDeps=*/cmNinjaDeps(),
- /*implicitDeps=*/cmNinjaDeps(),
- /*orderOnlyDeps=*/cmNinjaDeps(),
- /*variables=*/cmNinjaVars());
+ {
+ cmNinjaRule rule("HELP");
+ rule.Command = NinjaCmd() + " -t targets";
+ rule.Description = "All primary targets available:";
+ rule.Comment = "Rule for printing all primary targets available.";
+ WriteRule(*this->RulesFileStream, rule);
+ }
+ {
+ cmNinjaBuild build("HELP");
+ build.Comment = "Print all primary targets available.";
+ build.Outputs.push_back(this->NinjaOutputPath("help"));
+ WriteBuild(os, build);
+ }
}
void cmGlobalNinjaGenerator::InitOutputPathPrefix()
@@ -1513,12 +1610,13 @@ Compilation of source files within a target is split into the following steps:
command = gfortran -cpp $DEFINES $INCLUDES $FLAGS -E $in -o $out &&
cmake -E cmake_ninja_depends \
--tdi=FortranDependInfo.json --pp=$out --dep=$DEP_FILE \
- --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE
+ --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE \
+ --lang=Fortran
- build src.f90-pp.f90 | src.f90-pp.f90.ddi: Fortran_PREPROCESS src.f90
+ build src.f90-pp.f90 | src.f90.o.ddi: Fortran_PREPROCESS src.f90
OBJ_FILE = src.f90.o
- DEP_FILE = src.f90-pp.f90.d
- DYNDEP_INTERMEDIATE_FILE = src.f90-pp.f90.ddi
+ DEP_FILE = src.f90.o.d
+ DYNDEP_INTERMEDIATE_FILE = src.f90.o.ddi
The ``cmake -E cmake_ninja_depends`` tool reads the preprocessed output
and generates the ninja depfile for preprocessor dependencies. It also
@@ -1532,9 +1630,9 @@ Compilation of source files within a target is split into the following steps:
rule Fortran_DYNDEP
command = cmake -E cmake_ninja_dyndep \
- --tdi=FortranDependInfo.json --dd=$out $in
+ --tdi=FortranDependInfo.json --lang=Fortran --dd=$out $in
- build Fortran.dd: Fortran_DYNDEP src1.f90-pp.f90.ddi src2.f90-pp.f90.ddi
+ build Fortran.dd: Fortran_DYNDEP src1.f90.o.ddi src2.f90.o.ddi
The ``cmake -E cmake_ninja_dyndep`` tool reads the "ddi" files from all
sources in the target and the ``FortranModules.json`` files from targets
@@ -1572,6 +1670,19 @@ Compilation of source files within a target is split into the following steps:
(because the latter consumes the module).
*/
+struct cmSourceInfo
+{
+ // 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;
+};
+
+static std::unique_ptr<cmSourceInfo> cmcmd_cmake_ninja_depends_fortran(
+ std::string const& arg_tdi, std::string const& arg_pp);
+
int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
std::vector<std::string>::const_iterator argEnd)
{
@@ -1580,8 +1691,8 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
std::string arg_dep;
std::string arg_obj;
std::string arg_ddi;
- for (std::vector<std::string>::const_iterator a = argBeg; a != argEnd; ++a) {
- std::string const& arg = *a;
+ std::string arg_lang;
+ for (std::string const& arg : cmMakeRange(argBeg, argEnd)) {
if (cmHasLiteralPrefix(arg, "--tdi=")) {
arg_tdi = arg.substr(6);
} else if (cmHasLiteralPrefix(arg, "--pp=")) {
@@ -1592,9 +1703,10 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
arg_obj = arg.substr(6);
} else if (cmHasLiteralPrefix(arg, "--ddi=")) {
arg_ddi = arg.substr(6);
+ } else if (cmHasLiteralPrefix(arg, "--lang=")) {
+ arg_lang = arg.substr(7);
} else {
- cmSystemTools::Error("-E cmake_ninja_depends unknown argument: ",
- arg.c_str());
+ cmSystemTools::Error("-E cmake_ninja_depends unknown argument: " + arg);
return 1;
}
}
@@ -1618,50 +1730,30 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
cmSystemTools::Error("-E cmake_ninja_depends requires value for --ddi=");
return 1;
}
-
- std::vector<std::string> includes;
- {
- Json::Value tdio;
- Json::Value const& tdi = tdio;
- {
- cmsys::ifstream tdif(arg_tdi.c_str(), std::ios::in | std::ios::binary);
- Json::Reader reader;
- if (!reader.parse(tdif, tdio, false)) {
- cmSystemTools::Error("-E cmake_ninja_depends failed to parse ",
- arg_tdi.c_str(),
- reader.getFormattedErrorMessages().c_str());
- return 1;
- }
- }
-
- Json::Value const& tdi_include_dirs = tdi["include-dirs"];
- if (tdi_include_dirs.isArray()) {
- for (Json::Value::const_iterator i = tdi_include_dirs.begin();
- i != tdi_include_dirs.end(); ++i) {
- includes.push_back(i->asString());
- }
- }
+ if (arg_lang.empty()) {
+ cmSystemTools::Error("-E cmake_ninja_depends requires value for --lang=");
+ return 1;
}
- cmFortranSourceInfo info;
- std::set<std::string> defines;
- cmFortranParser parser(includes, defines, info);
- if (!cmFortranParser_FilePush(&parser, arg_pp.c_str())) {
- cmSystemTools::Error("-E cmake_ninja_depends failed to open ",
- arg_pp.c_str());
+ std::unique_ptr<cmSourceInfo> info;
+ if (arg_lang == "Fortran") {
+ info = cmcmd_cmake_ninja_depends_fortran(arg_tdi, arg_pp);
+ } else {
+ cmSystemTools::Error("-E cmake_ninja_depends does not understand the " +
+ arg_lang + " language");
return 1;
}
- if (cmFortran_yyparse(parser.Scanner) != 0) {
- // Failed to parse the file.
+
+ if (!info) {
+ // The error message is already expected to have been output.
return 1;
}
{
- cmGeneratedFileStream depfile(arg_dep.c_str());
+ cmGeneratedFileStream depfile(arg_dep);
depfile << cmSystemTools::ConvertToUnixOutputPath(arg_pp) << ":";
- for (std::set<std::string>::iterator i = info.Includes.begin();
- i != info.Includes.end(); ++i) {
- depfile << " \\\n " << cmSystemTools::ConvertToUnixOutputPath(*i);
+ for (std::string const& include : info->Includes) {
+ depfile << " \\\n " << cmSystemTools::ConvertToUnixOutputPath(include);
}
depfile << "\n";
}
@@ -1670,30 +1762,81 @@ int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
ddi["object"] = arg_obj;
Json::Value& ddi_provides = ddi["provides"] = Json::arrayValue;
- for (std::set<std::string>::iterator i = info.Provides.begin();
- i != info.Provides.end(); ++i) {
- ddi_provides.append(*i);
+ for (std::string const& provide : info->Provides) {
+ ddi_provides.append(provide);
}
Json::Value& ddi_requires = ddi["requires"] = Json::arrayValue;
- for (std::set<std::string>::iterator i = info.Requires.begin();
- i != info.Requires.end(); ++i) {
+ for (std::string const& r : info->Requires) {
// Require modules not provided in the same source.
- if (!info.Provides.count(*i)) {
- ddi_requires.append(*i);
+ if (!info->Provides.count(r)) {
+ ddi_requires.append(r);
}
}
- cmGeneratedFileStream ddif(arg_ddi.c_str());
+ cmGeneratedFileStream ddif(arg_ddi);
ddif << ddi;
if (!ddif) {
- cmSystemTools::Error("-E cmake_ninja_depends failed to write ",
- arg_ddi.c_str());
+ cmSystemTools::Error("-E cmake_ninja_depends failed to write " + arg_ddi);
return 1;
}
return 0;
}
-struct cmFortranObjectInfo
+std::unique_ptr<cmSourceInfo> cmcmd_cmake_ninja_depends_fortran(
+ std::string const& arg_tdi, std::string const& arg_pp)
+{
+ cmFortranCompiler fc;
+ std::vector<std::string> includes;
+ {
+ Json::Value tdio;
+ Json::Value const& tdi = tdio;
+ {
+ cmsys::ifstream tdif(arg_tdi.c_str(), std::ios::in | std::ios::binary);
+ Json::Reader reader;
+ if (!reader.parse(tdif, tdio, false)) {
+ cmSystemTools::Error("-E cmake_ninja_depends failed to parse " +
+ arg_tdi + reader.getFormattedErrorMessages());
+ return nullptr;
+ }
+ }
+
+ Json::Value const& tdi_include_dirs = tdi["include-dirs"];
+ if (tdi_include_dirs.isArray()) {
+ for (auto const& tdi_include_dir : tdi_include_dirs) {
+ includes.push_back(tdi_include_dir.asString());
+ }
+ }
+
+ Json::Value const& tdi_compiler_id = tdi["compiler-id"];
+ fc.Id = tdi_compiler_id.asString();
+
+ Json::Value const& tdi_submodule_sep = tdi["submodule-sep"];
+ fc.SModSep = tdi_submodule_sep.asString();
+
+ Json::Value const& tdi_submodule_ext = tdi["submodule-ext"];
+ fc.SModExt = tdi_submodule_ext.asString();
+ }
+
+ cmFortranSourceInfo finfo;
+ std::set<std::string> defines;
+ cmFortranParser parser(fc, includes, defines, finfo);
+ if (!cmFortranParser_FilePush(&parser, arg_pp.c_str())) {
+ cmSystemTools::Error("-E cmake_ninja_depends failed to open " + arg_pp);
+ return nullptr;
+ }
+ if (cmFortran_yyparse(parser.Scanner) != 0) {
+ // Failed to parse the file.
+ return nullptr;
+ }
+
+ auto info = cm::make_unique<cmSourceInfo>();
+ info->Provides = finfo.Provides;
+ info->Requires = finfo.Requires;
+ info->Includes = finfo.Includes;
+ return info;
+}
+
+struct cmDyndepObjectInfo
{
std::string Object;
std::vector<std::string> Provides;
@@ -1705,7 +1848,8 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
std::string const& dir_cur_src, std::string const& dir_cur_bld,
std::string const& arg_dd, std::vector<std::string> const& arg_ddis,
std::string const& module_dir,
- std::vector<std::string> const& linked_target_dirs)
+ std::vector<std::string> const& linked_target_dirs,
+ std::string const& arg_lang)
{
// Setup path conversions.
{
@@ -1714,62 +1858,58 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
snapshot.GetDirectory().SetCurrentBinary(dir_cur_bld);
snapshot.GetDirectory().SetRelativePathTopSource(dir_top_src.c_str());
snapshot.GetDirectory().SetRelativePathTopBinary(dir_top_bld.c_str());
- CM_AUTO_PTR<cmMakefile> mfd(new cmMakefile(this, snapshot));
- CM_AUTO_PTR<cmLocalNinjaGenerator> lgd(static_cast<cmLocalNinjaGenerator*>(
- this->CreateLocalGenerator(mfd.get())));
+ auto mfd = cm::make_unique<cmMakefile>(this, snapshot);
+ std::unique_ptr<cmLocalNinjaGenerator> lgd(
+ static_cast<cmLocalNinjaGenerator*>(
+ this->CreateLocalGenerator(mfd.get())));
this->Makefiles.push_back(mfd.release());
this->LocalGenerators.push_back(lgd.release());
}
- std::vector<cmFortranObjectInfo> objects;
- for (std::vector<std::string>::const_iterator ddii = arg_ddis.begin();
- ddii != arg_ddis.end(); ++ddii) {
+ std::vector<cmDyndepObjectInfo> objects;
+ for (std::string const& arg_ddi : arg_ddis) {
// Load the ddi file and compute the module file paths it provides.
Json::Value ddio;
Json::Value const& ddi = ddio;
- cmsys::ifstream ddif(ddii->c_str(), std::ios::in | std::ios::binary);
+ cmsys::ifstream ddif(arg_ddi.c_str(), std::ios::in | std::ios::binary);
Json::Reader reader;
if (!reader.parse(ddif, ddio, false)) {
- cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse ",
- ddii->c_str(),
- reader.getFormattedErrorMessages().c_str());
+ cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse " + arg_ddi +
+ reader.getFormattedErrorMessages());
return false;
}
- cmFortranObjectInfo info;
+ cmDyndepObjectInfo info;
info.Object = ddi["object"].asString();
Json::Value const& ddi_provides = ddi["provides"];
if (ddi_provides.isArray()) {
- for (Json::Value::const_iterator i = ddi_provides.begin();
- i != ddi_provides.end(); ++i) {
- info.Provides.push_back(i->asString());
+ for (auto const& ddi_provide : ddi_provides) {
+ info.Provides.push_back(ddi_provide.asString());
}
}
Json::Value const& ddi_requires = ddi["requires"];
if (ddi_requires.isArray()) {
- for (Json::Value::const_iterator i = ddi_requires.begin();
- i != ddi_requires.end(); ++i) {
- info.Requires.push_back(i->asString());
+ for (auto const& ddi_require : ddi_requires) {
+ info.Requires.push_back(ddi_require.asString());
}
}
- objects.push_back(info);
+ objects.push_back(std::move(info));
}
// Map from module name to module file path, if known.
std::map<std::string, std::string> mod_files;
// Populate the module map with those provided by linked targets first.
- for (std::vector<std::string>::const_iterator di =
- linked_target_dirs.begin();
- di != linked_target_dirs.end(); ++di) {
- std::string const ltmn = *di + "/FortranModules.json";
+ for (std::string const& linked_target_dir : linked_target_dirs) {
+ std::string const ltmn =
+ linked_target_dir + "/" + arg_lang + "Modules.json";
Json::Value ltm;
cmsys::ifstream ltmf(ltmn.c_str(), std::ios::in | std::ios::binary);
Json::Reader reader;
if (ltmf && !reader.parse(ltmf, ltm, false)) {
- cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse ",
- di->c_str(),
- reader.getFormattedErrorMessages().c_str());
+ cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse " +
+ linked_target_dir +
+ reader.getFormattedErrorMessages());
return false;
}
if (ltm.isObject()) {
@@ -1783,55 +1923,47 @@ bool cmGlobalNinjaGenerator::WriteDyndepFile(
// We do this after loading the modules provided by linked targets
// in case we have one of the same name that must be preferred.
Json::Value tm = Json::objectValue;
- for (std::vector<cmFortranObjectInfo>::iterator oi = objects.begin();
- oi != objects.end(); ++oi) {
- for (std::vector<std::string>::iterator i = oi->Provides.begin();
- i != oi->Provides.end(); ++i) {
- std::string const mod = module_dir + *i + ".mod";
- mod_files[*i] = mod;
- tm[*i] = mod;
+ for (cmDyndepObjectInfo const& object : objects) {
+ for (std::string const& p : object.Provides) {
+ std::string const mod = module_dir + p;
+ mod_files[p] = mod;
+ tm[p] = mod;
}
}
- cmGeneratedFileStream ddf(arg_dd.c_str());
+ cmGeneratedFileStream ddf(arg_dd);
ddf << "ninja_dyndep_version = 1.0\n";
- for (std::vector<cmFortranObjectInfo>::iterator oi = objects.begin();
- oi != objects.end(); ++oi) {
- std::string const ddComment;
- std::string const ddRule = "dyndep";
- cmNinjaDeps ddOutputs;
- cmNinjaDeps ddImplicitOuts;
- cmNinjaDeps ddExplicitDeps;
- cmNinjaDeps ddImplicitDeps;
- cmNinjaDeps ddOrderOnlyDeps;
- cmNinjaVars ddVars;
-
- ddOutputs.push_back(oi->Object);
- for (std::vector<std::string>::iterator i = oi->Provides.begin();
- i != oi->Provides.end(); ++i) {
- ddImplicitOuts.push_back(this->ConvertToNinjaPath(mod_files[*i]));
- }
- for (std::vector<std::string>::iterator i = oi->Requires.begin();
- i != oi->Requires.end(); ++i) {
- std::map<std::string, std::string>::iterator m = mod_files.find(*i);
- if (m != mod_files.end()) {
- ddImplicitDeps.push_back(this->ConvertToNinjaPath(m->second));
+ {
+ cmNinjaBuild build("dyndep");
+ build.Outputs.emplace_back("");
+ for (cmDyndepObjectInfo const& object : objects) {
+ build.Outputs[0] = object.Object;
+ build.ImplicitOuts.clear();
+ for (std::string const& p : object.Provides) {
+ build.ImplicitOuts.push_back(this->ConvertToNinjaPath(mod_files[p]));
+ }
+ build.ImplicitDeps.clear();
+ for (std::string const& r : object.Requires) {
+ auto mit = mod_files.find(r);
+ if (mit != mod_files.end()) {
+ build.ImplicitDeps.push_back(this->ConvertToNinjaPath(mit->second));
+ }
+ }
+ build.Variables.clear();
+ if (!object.Provides.empty()) {
+ build.Variables.emplace("restat", "1");
}
- }
- if (!oi->Provides.empty()) {
- ddVars["restat"] = "1";
- }
- this->WriteBuild(ddf, ddComment, ddRule, ddOutputs, ddImplicitOuts,
- ddExplicitDeps, ddImplicitDeps, ddOrderOnlyDeps, ddVars);
+ this->WriteBuild(ddf, build);
+ }
}
// Store the map of modules provided by this target in a file for
// use by dependents that reference this target in linked-target-dirs.
std::string const target_mods_file =
- cmSystemTools::GetFilenamePath(arg_dd) + "/FortranModules.json";
- cmGeneratedFileStream tmf(target_mods_file.c_str());
+ cmSystemTools::GetFilenamePath(arg_dd) + "/" + arg_lang + "Modules.json";
+ cmGeneratedFileStream tmf(target_mods_file);
tmf << tm;
return true;
@@ -1844,21 +1976,21 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
cmSystemTools::HandleResponseFile(argBeg, argEnd);
std::string arg_dd;
+ std::string arg_lang;
std::string arg_tdi;
std::vector<std::string> arg_ddis;
- for (std::vector<std::string>::const_iterator a = arg_full.begin();
- a != arg_full.end(); ++a) {
- std::string const& arg = *a;
+ for (std::string const& arg : arg_full) {
if (cmHasLiteralPrefix(arg, "--tdi=")) {
arg_tdi = arg.substr(6);
+ } else if (cmHasLiteralPrefix(arg, "--lang=")) {
+ arg_lang = arg.substr(7);
} else if (cmHasLiteralPrefix(arg, "--dd=")) {
arg_dd = arg.substr(5);
} else if (!cmHasLiteralPrefix(arg, "--") &&
cmHasLiteralSuffix(arg, ".ddi")) {
arg_ddis.push_back(arg);
} else {
- cmSystemTools::Error("-E cmake_ninja_dyndep unknown argument: ",
- arg.c_str());
+ cmSystemTools::Error("-E cmake_ninja_dyndep unknown argument: " + arg);
return 1;
}
}
@@ -1866,6 +1998,10 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
cmSystemTools::Error("-E cmake_ninja_dyndep requires value for --tdi=");
return 1;
}
+ if (arg_lang.empty()) {
+ cmSystemTools::Error("-E cmake_ninja_dyndep requires value for --lang=");
+ return 1;
+ }
if (arg_dd.empty()) {
cmSystemTools::Error("-E cmake_ninja_dyndep requires value for --dd=");
return 1;
@@ -1877,9 +2013,8 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
cmsys::ifstream tdif(arg_tdi.c_str(), std::ios::in | std::ios::binary);
Json::Reader reader;
if (!reader.parse(tdif, tdio, false)) {
- cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse ",
- arg_tdi.c_str(),
- reader.getFormattedErrorMessages().c_str());
+ cmSystemTools::Error("-E cmake_ninja_dyndep failed to parse " + arg_tdi +
+ reader.getFormattedErrorMessages());
return 1;
}
}
@@ -1889,27 +2024,26 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
std::string const dir_top_bld = tdi["dir-top-bld"].asString();
std::string const dir_top_src = tdi["dir-top-src"].asString();
std::string module_dir = tdi["module-dir"].asString();
- if (!module_dir.empty()) {
+ if (!module_dir.empty() && !cmHasLiteralSuffix(module_dir, "/")) {
module_dir += "/";
}
std::vector<std::string> linked_target_dirs;
Json::Value const& tdi_linked_target_dirs = tdi["linked-target-dirs"];
if (tdi_linked_target_dirs.isArray()) {
- for (Json::Value::const_iterator i = tdi_linked_target_dirs.begin();
- i != tdi_linked_target_dirs.end(); ++i) {
- linked_target_dirs.push_back(i->asString());
+ for (auto const& tdi_linked_target_dir : tdi_linked_target_dirs) {
+ linked_target_dirs.push_back(tdi_linked_target_dir.asString());
}
}
- cmake cm(cmake::RoleInternal);
+ cmake cm(cmake::RoleInternal, cmState::Unknown);
cm.SetHomeDirectory(dir_top_src);
cm.SetHomeOutputDirectory(dir_top_bld);
- CM_AUTO_PTR<cmGlobalNinjaGenerator> ggd(
+ std::unique_ptr<cmGlobalNinjaGenerator> ggd(
static_cast<cmGlobalNinjaGenerator*>(cm.CreateGlobalGenerator("Ninja")));
- if (!ggd.get() ||
+ if (!ggd ||
!ggd->WriteDyndepFile(dir_top_src, dir_top_bld, dir_cur_src, dir_cur_bld,
- arg_dd, arg_ddis, module_dir,
- linked_target_dirs)) {
+ arg_dd, arg_ddis, module_dir, linked_target_dirs,
+ arg_lang)) {
return 1;
}
return 0;
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index b0008f74a..04d8e37ae 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -3,15 +3,19 @@
#ifndef cmGlobalNinjaGenerator_h
#define cmGlobalNinjaGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <string>
+#include <unordered_map>
+#include <unordered_set>
#include <utility>
#include <vector>
+#include "cmGeneratedFileStream.h"
#include "cmGlobalCommonGenerator.h"
#include "cmGlobalGenerator.h"
#include "cmGlobalGeneratorFactory.h"
@@ -20,7 +24,6 @@
#include "cm_codecvt.hxx"
class cmCustomCommand;
-class cmGeneratedFileStream;
class cmGeneratorTarget;
class cmLinkLineComputer;
class cmLocalGenerator;
@@ -40,8 +43,6 @@ struct cmDocumentationEntry;
* 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.
@@ -72,13 +73,12 @@ public:
static void WriteDivider(std::ostream& os);
static std::string EncodeRuleName(std::string const& name);
- static std::string EncodeIdent(const std::string& ident, std::ostream& vars);
static std::string EncodeLiteral(const std::string& lit);
std::string EncodePath(const std::string& path);
cmLinkLineComputer* CreateLinkLineComputer(
cmOutputConverter* outputConverter,
- cmStateDirectory const& stateDir) const CM_OVERRIDE;
+ cmStateDirectory const& stateDir) const override;
/**
* Write the given @a comment to the output stream @a os. It
@@ -98,57 +98,30 @@ public:
*/
static bool SupportsPlatform() { return false; }
- bool IsIPOSupported() const CM_OVERRIDE { return true; }
+ bool IsIPOSupported() const override { return true; }
/**
- * 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.
+ * Write a build statement @a build to @a os.
* @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& implicitOuts,
- const cmNinjaDeps& explicitDeps,
- const cmNinjaDeps& implicitDeps,
- const cmNinjaDeps& orderOnlyDeps,
- const cmNinjaVars& variables,
- const std::string& rspfile = std::string(),
- int cmdLineLimit = 0, bool* usedResponseFile = CM_NULLPTR);
+ void WriteBuild(std::ostream& os, cmNinjaBuild const& build,
+ int cmdLineLimit = 0, bool* usedResponseFile = nullptr);
- /**
- * 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 std::string& depfile, bool uses_terminal,
- bool restat, const cmNinjaDeps& outputs,
- const cmNinjaDeps& deps = cmNinjaDeps(),
- const cmNinjaDeps& orderOnly = cmNinjaDeps());
- void WriteMacOSXContentBuild(const std::string& input,
- const std::string& output);
+ void WriteCustomCommandBuild(
+ const std::string& command, const std::string& description,
+ const std::string& comment, const std::string& depfile,
+ const std::string& pool, bool uses_terminal, bool restat,
+ const cmNinjaDeps& outputs,
+ const cmNinjaDeps& explicitDeps = cmNinjaDeps(),
+ const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps());
+
+ void WriteMacOSXContentBuild(std::string input, 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.
+ * Write a rule statement to @a os.
* @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,
- const std::string& restat, bool generator);
+ static void WriteRule(std::ostream& os, cmNinjaRule const& rule);
/**
* Write a variable named @a name to @a os with value @a value and an
@@ -183,11 +156,9 @@ public:
return new cmGlobalGeneratorSimpleFactory<cmGlobalNinjaGenerator>();
}
- ~cmGlobalNinjaGenerator() CM_OVERRIDE {}
-
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) CM_OVERRIDE;
+ cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
- std::string GetName() const CM_OVERRIDE
+ std::string GetName() const override
{
return cmGlobalNinjaGenerator::GetActualName();
}
@@ -195,60 +166,55 @@ public:
static std::string GetActualName() { return "Ninja"; }
/** Get encoding used by generator for ninja files */
- codecvt::Encoding GetMakefileEncoding() const CM_OVERRIDE;
+ codecvt::Encoding GetMakefileEncoding() const override;
static void GetDocumentation(cmDocumentationEntry& entry);
void EnableLanguage(std::vector<std::string> const& languages,
- cmMakefile* mf, bool optional) CM_OVERRIDE;
+ cmMakefile* mf, bool optional) override;
- 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, bool verbose,
- std::vector<std::string> const& makeOptions =
- std::vector<std::string>()) CM_OVERRIDE;
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
// Setup target names
- const char* GetAllTargetName() const CM_OVERRIDE { return "all"; }
- const char* GetInstallTargetName() const CM_OVERRIDE { return "install"; }
- const char* GetInstallLocalTargetName() const CM_OVERRIDE
+ const char* GetAllTargetName() const override { return "all"; }
+ const char* GetInstallTargetName() const override { return "install"; }
+ const char* GetInstallLocalTargetName() const override
{
return "install/local";
}
- const char* GetInstallStripTargetName() const CM_OVERRIDE
+ const char* GetInstallStripTargetName() const override
{
return "install/strip";
}
- const char* GetTestTargetName() const CM_OVERRIDE { return "test"; }
- const char* GetPackageTargetName() const CM_OVERRIDE { return "package"; }
- const char* GetPackageSourceTargetName() const CM_OVERRIDE
+ const char* GetTestTargetName() const override { return "test"; }
+ const char* GetPackageTargetName() const override { return "package"; }
+ const char* GetPackageSourceTargetName() const override
{
return "package_source";
}
- const char* GetEditCacheTargetName() const CM_OVERRIDE
- {
- return "edit_cache";
- }
- const char* GetRebuildCacheTargetName() const CM_OVERRIDE
+ const char* GetEditCacheTargetName() const override { return "edit_cache"; }
+ const char* GetRebuildCacheTargetName() const override
{
return "rebuild_cache";
}
- const char* GetCleanTargetName() const CM_OVERRIDE { return "clean"; }
+ const char* GetCleanTargetName() const override { return "clean"; }
cmGeneratedFileStream* GetBuildFileStream() const
{
- return this->BuildFileStream;
+ return this->BuildFileStream.get();
}
cmGeneratedFileStream* GetRulesFileStream() const
{
- return this->RulesFileStream;
+ return this->RulesFileStream.get();
}
- std::string ConvertToNinjaPath(const std::string& path) const;
+ std::string const& ConvertToNinjaPath(const std::string& path) const;
struct MapToNinjaPathImpl
{
@@ -264,6 +230,13 @@ public:
};
MapToNinjaPathImpl MapToNinjaPath() { return MapToNinjaPathImpl(this); }
+ // -- Additional clean files
+ void AddAdditionalCleanFile(std::string fileName);
+ const char* GetAdditionalCleanTargetName() const
+ {
+ return "CMakeFiles/clean.additional";
+ }
+
void AddCXXCompileCommand(const std::string& commandLine,
const std::string& sourceFile);
@@ -272,11 +245,7 @@ public:
* 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,
- const std::string& restat, bool generator);
+ void AddRule(cmNinjaRule const& rule);
bool HasRule(const std::string& name);
@@ -323,6 +292,8 @@ public:
cmNinjaTargetDepends depends = DependOnTargetArtifact);
void AppendTargetDependsClosure(cmGeneratorTarget const* target,
cmNinjaDeps& outputs);
+ void AppendTargetDependsClosure(cmGeneratorTarget const* target,
+ cmNinjaOuts& outputs, bool omit_self);
void AddDependencyToAll(cmGeneratorTarget* target);
void AddDependencyToAll(const std::string& input);
@@ -340,14 +311,21 @@ public:
void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target);
- void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const CM_OVERRIDE;
+ void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
// Ninja generator uses 'deps' and 'msvc_deps_prefix' introduced in 1.3
static std::string RequiredNinjaVersion() { return "1.3"; }
static std::string RequiredNinjaVersionForConsolePool() { return "1.5"; }
static std::string RequiredNinjaVersionForImplicitOuts() { return "1.7"; }
+ static std::string RequiredNinjaVersionForManifestRestat() { return "1.8"; }
+ static std::string RequiredNinjaVersionForMultilineDepfile()
+ {
+ return "1.9";
+ }
bool SupportsConsolePool() const;
bool SupportsImplicitOuts() const;
+ bool SupportsManifestRestat() const;
+ bool SupportsMultilineDepfile() const;
std::string NinjaOutputPath(std::string const& path) const;
bool HasOutputPathPrefix() const { return !this->OutputPathPrefix.empty(); }
@@ -360,27 +338,28 @@ public:
std::string const& arg_dd,
std::vector<std::string> const& arg_ddis,
std::string const& module_dir,
- std::vector<std::string> const& linked_target_dirs);
+ std::vector<std::string> const& linked_target_dirs,
+ std::string const& arg_lang);
protected:
- void Generate() CM_OVERRIDE;
+ void Generate() override;
- bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const CM_OVERRIDE { return true; }
+ bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const override { return true; }
private:
- std::string GetEditCacheCommand() const CM_OVERRIDE;
- bool FindMakeProgram(cmMakefile* mf) CM_OVERRIDE;
+ std::string GetEditCacheCommand() const override;
+ bool FindMakeProgram(cmMakefile* mf) override;
void CheckNinjaFeatures();
bool CheckLanguages(std::vector<std::string> const& languages,
- cmMakefile* mf) const CM_OVERRIDE;
+ cmMakefile* mf) const override;
bool CheckFortran(cmMakefile* mf) const;
- void OpenBuildFileStream();
+ bool OpenBuildFileStream();
void CloseBuildFileStream();
void CloseCompileCommandsStream();
- void OpenRulesFileStream();
+ bool OpenRulesFileStream();
void CloseRulesFileStream();
/// Write the common disclaimer text at the top of each build file.
@@ -395,6 +374,7 @@ private:
void WriteBuiltinTargets(std::ostream& os);
void WriteTargetAll(std::ostream& os);
void WriteTargetRebuildManifest(std::ostream& os);
+ bool WriteTargetCleanAdditional(std::ostream& os);
void WriteTargetClean(std::ostream& os);
void WriteTargetHelp(std::ostream& os);
@@ -402,25 +382,22 @@ private:
cmGeneratorTarget const* target,
std::set<cmGeneratorTarget const*>& depends);
- std::string ninjaCmd() const;
+ std::string CMakeCmd() const;
+ std::string NinjaCmd() const;
/// The file containing the build statement. (the relationship of the
/// compilation DAG).
- cmGeneratedFileStream* BuildFileStream;
+ std::unique_ptr<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;
+ std::unique_ptr<cmGeneratedFileStream> RulesFileStream;
+ std::unique_ptr<cmGeneratedFileStream> CompileCommandsStream;
/// The set of rules added to the generated build system.
- RulesSetType Rules;
+ std::unordered_set<std::string> Rules;
/// Length of rule command, used by rsp file evaluation
- std::map<std::string, int> RuleCmdLength;
+ std::unordered_map<std::string, int> RuleCmdLength;
/// The set of dependencies to add to the "all" target.
cmNinjaDeps AllDependencies;
@@ -446,20 +423,22 @@ private:
std::set<std::string> CombinedBuildOutputs;
/// The mapping from source file to assumed dependencies.
- std::map<std::string, std::set<std::string> > AssumedSourceDependencies;
+ std::map<std::string, std::set<std::string>> AssumedSourceDependencies;
typedef std::map<std::string, cmGeneratorTarget*> TargetAliasMap;
TargetAliasMap TargetAliases;
- typedef std::map<cmGeneratorTarget const*,
- std::set<cmGeneratorTarget const*> >
- TargetDependsClosureMap;
- TargetDependsClosureMap TargetDependsClosures;
+ std::map<cmGeneratorTarget const*, cmNinjaOuts> TargetDependsClosures;
+
+ /// the local cache for calls to ConvertToNinjaPath
+ mutable std::unordered_map<std::string, std::string> ConvertToNinjaPathCache;
std::string NinjaCommand;
std::string NinjaVersion;
bool NinjaSupportsConsolePool;
bool NinjaSupportsImplicitOuts;
+ bool NinjaSupportsManifestRestat;
+ bool NinjaSupportsMultilineDepfile;
unsigned long NinjaSupportsDyndeps;
private:
@@ -468,6 +447,7 @@ private:
std::string OutputPathPrefix;
std::string TargetAll;
std::string CMakeCacheFile;
+ std::set<std::string> AdditionalCleanFiles;
};
#endif // ! cmGlobalNinjaGenerator_h
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index 23b3718dc..4eb2252e9 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -21,7 +21,6 @@
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cmTarget.h"
#include "cmTargetDepend.h"
#include "cmake.h"
@@ -38,7 +37,7 @@ cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3(cmake* cm)
#else
this->UseLinkScript = true;
#endif
- this->CommandDatabase = CM_NULLPTR;
+ this->CommandDatabase = nullptr;
this->IncludeDirective = "include";
this->DefineWindowsNULL = false;
@@ -50,16 +49,15 @@ 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") {
+ for (std::string const& language : languages) {
+ if (language == "NONE") {
continue;
}
- this->ResolveLanguageCompiler(*l, mf, optional);
+ this->ResolveLanguageCompiler(language, mf, optional);
}
}
-///! Create a local generator appropriate to this Global Generator
+//! Create a local generator appropriate to this Global Generator
cmLocalGenerator* cmGlobalUnixMakefileGenerator3::CreateLocalGenerator(
cmMakefile* mf)
{
@@ -130,9 +128,8 @@ void cmGlobalUnixMakefileGenerator3::Generate()
// initialize progress
unsigned long total = 0;
- for (ProgressMapType::const_iterator pmi = this->ProgressMap.begin();
- pmi != this->ProgressMap.end(); ++pmi) {
- total += pmi->second.NumberOfActions;
+ for (auto const& pmi : this->ProgressMap) {
+ total += pmi.second.NumberOfActions;
}
// write each target's progress.make this loop is done twice. Bascially the
@@ -143,17 +140,15 @@ void cmGlobalUnixMakefileGenerator3::Generate()
// 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 (auto& pmi : this->ProgressMap) {
+ pmi.second.WriteProgressVariables(total, current);
}
- for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
- cmLocalGenerator* lg = this->LocalGenerators[i];
+ for (cmLocalGenerator* lg : this->LocalGenerators) {
std::string markFileName = lg->GetCurrentBinaryDirectory();
markFileName += "/";
- markFileName += cmake::GetCMakeFilesDirectory();
+ markFileName += "/CMakeFiles";
markFileName += "/progress.marks";
- cmGeneratedFileStream markFile(markFileName.c_str());
+ cmGeneratedFileStream markFile(markFileName);
markFile << this->CountProgressMarksInAll(lg) << "\n";
}
@@ -161,10 +156,10 @@ void cmGlobalUnixMakefileGenerator3::Generate()
this->WriteMainMakefile2();
this->WriteMainCMakefile();
- if (this->CommandDatabase != CM_NULLPTR) {
+ if (this->CommandDatabase != nullptr) {
*this->CommandDatabase << std::endl << "]";
delete this->CommandDatabase;
- this->CommandDatabase = CM_NULLPTR;
+ this->CommandDatabase = nullptr;
}
}
@@ -172,24 +167,23 @@ void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
const std::string& sourceFile, const std::string& workingDirectory,
const std::string& compileCommand)
{
- if (this->CommandDatabase == CM_NULLPTR) {
+ if (this->CommandDatabase == nullptr) {
std::string commandDatabaseName =
- std::string(this->GetCMakeInstance()->GetHomeOutputDirectory()) +
+ this->GetCMakeInstance()->GetHomeOutputDirectory() +
"/compile_commands.json";
- this->CommandDatabase =
- new cmGeneratedFileStream(commandDatabaseName.c_str());
+ this->CommandDatabase = new cmGeneratedFileStream(commandDatabaseName);
*this->CommandDatabase << "[" << std::endl;
} else {
*this->CommandDatabase << "," << std::endl;
}
*this->CommandDatabase << "{" << std::endl
- << " \"directory\": \""
+ << R"( "directory": ")"
<< cmGlobalGenerator::EscapeJSON(workingDirectory)
<< "\"," << std::endl
- << " \"command\": \""
+ << R"( "command": ")"
<< cmGlobalGenerator::EscapeJSON(compileCommand)
<< "\"," << std::endl
- << " \"file\": \""
+ << R"( "file": ")"
<< cmGlobalGenerator::EscapeJSON(sourceFile) << "\""
<< std::endl
<< "}";
@@ -202,9 +196,9 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
// see if the build system must be regenerated.
std::string makefileName =
this->GetCMakeInstance()->GetHomeOutputDirectory();
- makefileName += cmake::GetCMakeFilesDirectory();
+ makefileName += "/CMakeFiles";
makefileName += "/Makefile2";
- cmGeneratedFileStream makefileStream(makefileName.c_str(), false,
+ cmGeneratedFileStream makefileStream(makefileName, false,
this->GetMakefileEncoding());
if (!makefileStream) {
return;
@@ -222,7 +216,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
// 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");
+ depends.emplace_back("all");
// Write the rule.
lg->WriteMakeRule(makefileStream,
@@ -234,7 +228,7 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
// The all and preinstall rules might never have any dependencies
// added to them.
- if (this->EmptyRuleHackDepends != "") {
+ if (!this->EmptyRuleHackDepends.empty()) {
depends.push_back(this->EmptyRuleHackDepends);
}
@@ -249,27 +243,30 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()
// 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);
+ // Write the target convenience rules
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ this->WriteConvenienceRules2(
+ makefileStream, static_cast<cmLocalUnixMakefileGenerator3*>(localGen));
}
- lg = static_cast<cmLocalUnixMakefileGenerator3*>(this->LocalGenerators[0]);
+ // Write special bottom targets
lg->WriteSpecialTargetsBottom(makefileStream);
}
void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
{
+ if (this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) {
+ return;
+ }
+
// 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 += "/CMakeFiles";
cmakefileName += "/Makefile.cmake";
- cmGeneratedFileStream cmakefileStream(cmakefileName.c_str());
+ cmGeneratedFileStream cmakefileStream(cmakefileName);
if (!cmakefileStream) {
return;
}
@@ -292,13 +289,17 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
// 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]);
-
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
// Get the list of files contributing to this generation step.
- lfiles.insert(lfiles.end(), lg->GetMakefile()->GetListFiles().begin(),
- lg->GetMakefile()->GetListFiles().end());
+ cmAppend(lfiles, localGen->GetMakefile()->GetListFiles());
}
+
+ cmake* cm = this->GetCMakeInstance();
+ if (cm->DoWriteGlobVerifyTarget()) {
+ lfiles.push_back(cm->GetGlobVerifyScript());
+ lfiles.push_back(cm->GetGlobVerifyStamp());
+ }
+
// 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.
@@ -316,25 +317,27 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
<< "# The top level Makefile was generated from the following files:\n"
<< "set(CMAKE_MAKEFILE_DEPENDS\n"
<< " \"CMakeCache.txt\"\n";
- for (std::vector<std::string>::const_iterator i = lfiles.begin();
- i != lfiles.end(); ++i) {
- cmakefileStream << " \"" << lg->ConvertToRelativePath(currentBinDir, *i)
+ for (std::string const& f : lfiles) {
+ cmakefileStream << " \""
+ << lg->MaybeConvertToRelativePath(currentBinDir, f)
<< "\"\n";
}
cmakefileStream << " )\n\n";
// Build the path to the cache check file.
std::string check = this->GetCMakeInstance()->GetHomeOutputDirectory();
- check += cmake::GetCMakeFilesDirectory();
+ check += "/CMakeFiles";
check += "/cmake.check_cache";
// Set the corresponding makefile in the cmake file.
cmakefileStream << "# The corresponding makefile is:\n"
<< "set(CMAKE_MAKEFILE_OUTPUTS\n"
<< " \""
- << lg->ConvertToRelativePath(currentBinDir, makefileName)
+ << lg->MaybeConvertToRelativePath(currentBinDir,
+ makefileName)
<< "\"\n"
- << " \"" << lg->ConvertToRelativePath(currentBinDir, check)
+ << " \""
+ << lg->MaybeConvertToRelativePath(currentBinDir, check)
<< "\"\n";
cmakefileStream << " )\n\n";
@@ -344,23 +347,21 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefile()
{
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->ConvertToRelativePath(binDir, *k)
+ for (std::string const& outfile : lg->GetMakefile()->GetOutputFiles()) {
+ cmakefileStream << " \""
+ << lg->MaybeConvertToRelativePath(binDir, outfile)
<< "\"\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]);
+ for (cmLocalGenerator* localGen : this->LocalGenerators) {
+ lg = static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
tmpStr = lg->GetCurrentBinaryDirectory();
- tmpStr += cmake::GetCMakeFilesDirectory();
+ tmpStr += "/CMakeFiles";
tmpStr += "/CMakeDirectoryInformation.cmake";
- cmakefileStream << " \"" << lg->ConvertToRelativePath(binDir, tmpStr)
+ cmakefileStream << " \""
+ << lg->MaybeConvertToRelativePath(binDir, tmpStr)
<< "\"\n";
}
cmakefileStream << " )\n\n";
@@ -379,19 +380,17 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules(
// 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 (cmLocalGenerator* lGenerator : lGenerators) {
+ lg = static_cast<cmLocalUnixMakefileGenerator3*>(lGenerator);
// for all of out targets
- std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); l++) {
- if (((*l)->GetType() == cmStateEnums::EXECUTABLE) ||
- ((*l)->GetType() == cmStateEnums::STATIC_LIBRARY) ||
- ((*l)->GetType() == cmStateEnums::SHARED_LIBRARY) ||
- ((*l)->GetType() == cmStateEnums::MODULE_LIBRARY) ||
- ((*l)->GetType() == cmStateEnums::OBJECT_LIBRARY) ||
- ((*l)->GetType() == cmStateEnums::UTILITY)) {
- cmGeneratorTarget* gt = *l;
+ for (cmGeneratorTarget* tgt : lg->GetGeneratorTargets()) {
+ if ((tgt->GetType() == cmStateEnums::EXECUTABLE) ||
+ (tgt->GetType() == cmStateEnums::STATIC_LIBRARY) ||
+ (tgt->GetType() == cmStateEnums::SHARED_LIBRARY) ||
+ (tgt->GetType() == cmStateEnums::MODULE_LIBRARY) ||
+ (tgt->GetType() == cmStateEnums::OBJECT_LIBRARY) ||
+ (tgt->GetType() == cmStateEnums::UTILITY)) {
+ cmGeneratorTarget* gt = tgt;
std::string tname = lg->GetRelativeTargetDirectory(gt);
tname += "/DependInfo.cmake";
cmSystemTools::ConvertToUnixSlashes(tname);
@@ -404,20 +403,18 @@ void cmGlobalUnixMakefileGenerator3::WriteMainCMakefileLanguageRules(
void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2(
std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg,
- const char* pass, bool check_all, bool check_relink)
+ const char* pass, bool check_all, bool check_relink,
+ std::vector<std::string> const& commands)
{
// Get the relative path to the subdirectory from the top.
std::string makeTarget = lg->GetCurrentBinaryDirectory();
- makeTarget += "/";
+ 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;
- std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = targets.begin();
- l != targets.end(); ++l) {
- cmGeneratorTarget* gtarget = *l;
+ for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) {
int type = gtarget->GetType();
if ((type == cmStateEnums::EXECUTABLE) ||
(type == cmStateEnums::STATIC_LIBRARY) ||
@@ -432,105 +429,129 @@ void cmGlobalUnixMakefileGenerator3::WriteDirectoryRule2(
std::string tname = lg->GetRelativeTargetDirectory(gtarget);
tname += "/";
tname += pass;
- depends.push_back(tname);
+ depends.push_back(std::move(tname));
}
}
}
// The directory-level rule should depend on the directory-level
// rules of the subdirectories.
- std::vector<cmStateSnapshot> children = lg->GetStateSnapshot().GetChildren();
- for (std::vector<cmStateSnapshot>::const_iterator ci = children.begin();
- ci != children.end(); ++ci) {
- std::string subdir = ci->GetDirectory().GetCurrentBinary();
- subdir += "/";
+ for (cmStateSnapshot const& c : lg->GetStateSnapshot().GetChildren()) {
+ std::string subdir = c.GetDirectory().GetCurrentBinary();
+ subdir += '/';
subdir += pass;
- depends.push_back(subdir);
+ depends.push_back(std::move(subdir));
}
// Work-around for makes that drop rules that have no dependencies
// or commands.
- if (depends.empty() && this->EmptyRuleHackDepends != "") {
+ if (depends.empty() && !this->EmptyRuleHackDepends.empty()) {
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);
+ std::string doc;
+ if (lg->IsRootMakefile()) {
+ doc = "The main recursive \"";
+ doc += pass;
+ doc += "\" target.";
+ } else {
+ doc = "Recursive \"";
+ doc += pass;
+ doc += "\" directory target.";
+ }
+ lg->WriteMakeRule(ruleFileStream, doc.c_str(), makeTarget, depends, commands,
+ true);
}
void cmGlobalUnixMakefileGenerator3::WriteDirectoryRules2(
std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3* lg)
{
- // Only subdirectories need these rules.
- if (lg->IsRootMakefile()) {
- return;
+ // Begin the directory-level rules section.
+ {
+ std::string dir =
+ cmSystemTools::ConvertToOutputPath(lg->MaybeConvertToRelativePath(
+ lg->GetBinaryDirectory(), lg->GetCurrentBinaryDirectory()));
+ lg->WriteDivider(ruleFileStream);
+ if (lg->IsRootMakefile()) {
+ ruleFileStream << "# Directory level rules for the build root directory";
+ } else {
+ ruleFileStream << "# Directory level rules for directory " << dir;
+ }
+ ruleFileStream << "\n\n";
}
- // Begin the directory-level rules section.
- std::string dir = cmSystemTools::ConvertToOutputPath(
- lg->ConvertToRelativePath(lg->GetBinaryDirectory(),
- lg->GetCurrentBinaryDirectory())
- .c_str());
- lg->WriteDivider(ruleFileStream);
- ruleFileStream << "# Directory level rules for directory " << dir << "\n\n";
+ if (!lg->IsRootMakefile()) {
+ // Write directory-level rules for "all".
+ this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false);
- // Write directory-level rules for "all".
- this->WriteDirectoryRule2(ruleFileStream, lg, "all", true, false);
+ // Write directory-level rules for "preinstall".
+ this->WriteDirectoryRule2(ruleFileStream, lg, "preinstall", true, true);
+ }
// 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);
+ {
+ std::vector<std::string> cmds;
+ lg->AppendDirectoryCleanCommand(cmds);
+ this->WriteDirectoryRule2(ruleFileStream, lg, "clean", false, false, cmds);
+ }
}
-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,
- bool /*verbose*/, std::vector<std::string> const& makeOptions)
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& /*projectName*/,
+ const std::string& /*projectDir*/,
+ std::vector<std::string> const& targetNames, const std::string& /*config*/,
+ bool fast, int jobs, bool verbose,
+ 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 (cmHasLiteralPrefix(this->GetName(), "NMake Makefiles")) {
- makeCommand.push_back("/NOLOGO");
- }
- makeCommand.insert(makeCommand.end(), makeOptions.begin(),
- makeOptions.end());
- if (!targetName.empty()) {
- cmMakefile* mf;
- if (!this->Makefiles.empty()) {
- mf = this->Makefiles[0];
- } else {
- cmStateSnapshot snapshot = this->CMakeInstance->GetCurrentSnapshot();
- snapshot.GetDirectory().SetCurrentSource(
- this->CMakeInstance->GetHomeDirectory());
- snapshot.GetDirectory().SetCurrentBinary(
- this->CMakeInstance->GetHomeOutputDirectory());
- snapshot.SetDefaultDefinitions();
- mf = new cmMakefile(this, snapshot);
+ std::unique_ptr<cmMakefile> mfu;
+ cmMakefile* mf;
+ if (!this->Makefiles.empty()) {
+ mf = this->Makefiles[0];
+ } else {
+ cmStateSnapshot snapshot = this->CMakeInstance->GetCurrentSnapshot();
+ snapshot.GetDirectory().SetCurrentSource(
+ this->CMakeInstance->GetHomeDirectory());
+ snapshot.GetDirectory().SetCurrentBinary(
+ this->CMakeInstance->GetHomeOutputDirectory());
+ snapshot.SetDefaultDefinitions();
+ mfu = cm::make_unique<cmMakefile>(this, snapshot);
+ mf = mfu.get();
+ }
+
+ GeneratedMakeCommand makeCommand;
+
+ // Make it possible to set verbosity also from command line
+ if (verbose) {
+ makeCommand.Add(cmSystemTools::GetCMakeCommand());
+ makeCommand.Add("-E");
+ makeCommand.Add("env");
+ makeCommand.Add("VERBOSE=1");
+ }
+ makeCommand.Add(this->SelectMakeProgram(makeProgram));
+
+ if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
+ makeCommand.Add("-j");
+ if (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
+ makeCommand.Add(std::to_string(jobs));
}
+ }
- std::string tname = targetName;
- if (fast) {
- tname += "/fast";
- }
- cmOutputConverter conv(mf->GetStateSnapshot());
- tname =
- conv.ConvertToRelativePath(mf->GetState()->GetBinaryDirectory(), tname);
- cmSystemTools::ConvertToOutputSlashes(tname);
- makeCommand.push_back(tname);
- if (this->Makefiles.empty()) {
- delete mf;
+ makeCommand.Add(makeOptions.begin(), makeOptions.end());
+ for (auto tname : targetNames) {
+ if (!tname.empty()) {
+ if (fast) {
+ tname += "/fast";
+ }
+ tname =
+ mf->GetStateSnapshot().GetDirectory().ConvertToRelPathIfNotContained(
+ mf->GetState()->GetBinaryDirectory(), tname);
+ cmSystemTools::ConvertToOutputSlashes(tname);
+ makeCommand.Add(std::move(tname));
}
}
+ return { std::move(makeCommand) };
}
void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
@@ -539,18 +560,17 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
std::vector<std::string> depends;
std::vector<std::string> commands;
- depends.push_back("cmake_check_build_system");
+ bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION");
+ if (regenerate) {
+ depends.emplace_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 (cmLocalGenerator* localGen : this->LocalGenerators) {
+ cmLocalUnixMakefileGenerator3* lg =
+ static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
// for each target Generate the rule files for each target.
- std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- cmGeneratorTarget* gtarget = *t;
+ for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) {
// Don't emit the same rule twice (e.g. two targets with the same
// simple name)
int type = gtarget->GetType();
@@ -571,11 +591,13 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
// Write the rule.
commands.clear();
- std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::string tmp = "CMakeFiles/";
tmp += "Makefile2";
- commands.push_back(lg->GetRecursiveMakeCall(tmp.c_str(), name));
+ commands.push_back(lg->GetRecursiveMakeCall(tmp, name));
depends.clear();
- depends.push_back("cmake_check_build_system");
+ if (regenerate) {
+ depends.emplace_back("cmake_check_build_system");
+ }
lg->WriteMakeRule(ruleFileStream, "Build rule for target.", name,
depends, commands, true);
@@ -591,7 +613,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
localName = name;
localName += "/fast";
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
+ lg->GetRecursiveMakeCall(makefileName, makeTargetName));
lg->WriteMakeRule(ruleFileStream, "fast build rule for target.",
localName, depends, commands, true);
@@ -605,7 +627,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules(
depends.clear();
commands.clear();
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
+ lg->GetRecursiveMakeCall(makefileName, makeTargetName));
lg->WriteMakeRule(ruleFileStream,
"Manual pre-install relink rule for target.",
localName, depends, commands, true);
@@ -626,29 +648,28 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
// write the directory level rules for this local gen
this->WriteDirectoryRules2(ruleFileStream, lg);
- depends.push_back("cmake_check_build_system");
+ bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION");
+ if (regenerate) {
+ depends.emplace_back("cmake_check_build_system");
+ }
// for each target Generate the rule files for each target.
- std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- cmGeneratorTarget* gtarget = *t;
+ for (cmGeneratorTarget* gtarget : lg->GetGeneratorTargets()) {
int type = gtarget->GetType();
std::string name = gtarget->GetName();
- if (!name.empty() && ((type == cmStateEnums::EXECUTABLE) ||
- (type == cmStateEnums::STATIC_LIBRARY) ||
- (type == cmStateEnums::SHARED_LIBRARY) ||
- (type == cmStateEnums::MODULE_LIBRARY) ||
- (type == cmStateEnums::OBJECT_LIBRARY) ||
- (type == cmStateEnums::UTILITY))) {
+ if (!name.empty() &&
+ ((type == cmStateEnums::EXECUTABLE) ||
+ (type == cmStateEnums::STATIC_LIBRARY) ||
+ (type == cmStateEnums::SHARED_LIBRARY) ||
+ (type == cmStateEnums::MODULE_LIBRARY) ||
+ (type == cmStateEnums::OBJECT_LIBRARY) ||
+ (type == cmStateEnums::UTILITY))) {
std::string makefileName;
// Add a rule to build the target by name.
localName = lg->GetRelativeTargetDirectory(gtarget);
makefileName = localName;
makefileName += "/build.make";
- bool needRequiresStep = this->NeedRequiresStep(gtarget);
-
lg->WriteDivider(ruleFileStream);
ruleFileStream << "# Target rules for target " << localName << "\n\n";
@@ -656,19 +677,12 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
makeTargetName = localName;
makeTargetName += "/depend";
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
+ lg->GetRecursiveMakeCall(makefileName, 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));
+ lg->GetRecursiveMakeCall(makefileName, makeTargetName));
// Write the rule.
localName += "/all";
@@ -676,15 +690,12 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
cmLocalUnixMakefileGenerator3::EchoProgress progress;
progress.Dir = lg->GetBinaryDirectory();
- progress.Dir += cmake::GetCMakeFilesDirectory();
+ progress.Dir += "/CMakeFiles";
{
std::ostringstream progressArg;
const char* sep = "";
- std::vector<unsigned long>& progFiles =
- this->ProgressMap[gtarget].Marks;
- for (std::vector<unsigned long>::iterator i = progFiles.begin();
- i != progFiles.end(); ++i) {
- progressArg << sep << *i;
+ for (unsigned long progFile : this->ProgressMap[gtarget].Marks) {
+ progressArg << sep << progFile;
sep = ",";
}
progress.Arg = progressArg.str();
@@ -731,9 +742,9 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
progCmd << " " << this->CountProgressMarksInTarget(gtarget, emitted);
commands.push_back(progCmd.str());
}
- std::string tmp = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::string tmp = "CMakeFiles/";
tmp += "Makefile2";
- commands.push_back(lg->GetRecursiveMakeCall(tmp.c_str(), localName));
+ commands.push_back(lg->GetRecursiveMakeCall(tmp, localName));
{
std::ostringstream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start "; // # 0
@@ -744,7 +755,9 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
commands.push_back(progCmd.str());
}
depends.clear();
- depends.push_back("cmake_check_build_system");
+ if (regenerate) {
+ depends.emplace_back("cmake_check_build_system");
+ }
localName = lg->GetRelativeTargetDirectory(gtarget);
localName += "/rule";
lg->WriteMakeRule(ruleFileStream,
@@ -764,8 +777,7 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
localName += "/preinstall";
depends.clear();
commands.clear();
- commands.push_back(
- lg->GetRecursiveMakeCall(makefileName.c_str(), localName));
+ commands.push_back(lg->GetRecursiveMakeCall(makefileName, localName));
lg->WriteMakeRule(ruleFileStream,
"Pre-install relink rule for target.", localName,
depends, commands, true);
@@ -786,32 +798,22 @@ void cmGlobalUnixMakefileGenerator3::WriteConvenienceRules2(
depends.clear();
commands.clear();
commands.push_back(
- lg->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
+ lg->GetRecursiveMakeCall(makefileName, 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);
}
}
}
-// Build a map that contains a the set of targets used by each local
+// Build a map that contains the set of targets used by each local
// generator directory level.
void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
{
this->DirectoryTargetsMap.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;
- std::vector<cmGeneratorTarget*> targets = lg->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::const_iterator t = targets.begin();
- t != targets.end(); ++t) {
- cmGeneratorTarget* gt = *t;
-
+ for (cmLocalGenerator* lg : this->LocalGenerators) {
+ for (cmGeneratorTarget* gt : lg->GetGeneratorTargets()) {
cmLocalGenerator* tlg = gt->GetLocalGenerator();
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
@@ -834,10 +836,8 @@ void cmGlobalUnixMakefileGenerator3::InitializeProgressMarks()
// 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(gt);
- for (TargetDependSet::const_iterator ti = tgtdeps.begin();
- ti != tgtdeps.end(); ++ti) {
- targetSet.insert(*ti);
+ for (cmTargetDepend const& tgtdep : this->GetTargetDirectDepends(gt)) {
+ targetSet.insert(tgtdep);
}
}
}
@@ -850,13 +850,11 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInTarget(
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() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (cmTargetDepend const& depend : this->GetTargetDirectDepends(target)) {
+ if (depend->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- count += this->CountProgressMarksInTarget(*di, emitted);
+ count += this->CountProgressMarksInTarget(depend, emitted);
}
}
return count;
@@ -867,11 +865,9 @@ size_t cmGlobalUnixMakefileGenerator3::CountProgressMarksInAll(
{
size_t count = 0;
std::set<cmGeneratorTarget const*> emitted;
- std::set<cmGeneratorTarget const*> const& targets =
- this->DirectoryTargetsMap[lg->GetStateSnapshot()];
- for (std::set<cmGeneratorTarget const*>::const_iterator t = targets.begin();
- t != targets.end(); ++t) {
- count += this->CountProgressMarksInTarget(*t, emitted);
+ for (cmGeneratorTarget const* target :
+ this->DirectoryTargetsMap[lg->GetStateSnapshot()]) {
+ count += this->CountProgressMarksInTarget(target, emitted);
}
return count;
}
@@ -887,7 +883,7 @@ void cmGlobalUnixMakefileGenerator3::RecordTargetProgress(
void cmGlobalUnixMakefileGenerator3::TargetProgress::WriteProgressVariables(
unsigned long total, unsigned long& current)
{
- cmGeneratedFileStream fout(this->VariableFile.c_str());
+ cmGeneratedFileStream fout(this->VariableFile);
for (unsigned long i = 1; i <= this->NumberOfActions; ++i) {
fout << "CMAKE_PROGRESS_" << i << " = ";
if (total <= 100) {
@@ -909,11 +905,9 @@ void cmGlobalUnixMakefileGenerator3::TargetProgress::WriteProgressVariables(
void cmGlobalUnixMakefileGenerator3::AppendGlobalTargetDepends(
std::vector<std::string>& depends, cmGeneratorTarget* target)
{
- TargetDependSet const& depends_set = this->GetTargetDirectDepends(target);
- for (TargetDependSet::const_iterator i = depends_set.begin();
- i != depends_set.end(); ++i) {
+ for (cmTargetDepend const& i : this->GetTargetDirectDepends(target)) {
// Create the target-level dependency.
- cmGeneratorTarget const* dep = *i;
+ cmGeneratorTarget const* dep = i;
if (dep->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
@@ -933,29 +927,27 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
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,
+ "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");
+ if (!this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) {
+ 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 (cmLocalGenerator* localGen : this->LocalGenerators) {
+ cmLocalUnixMakefileGenerator3* lg2 =
+ static_cast<cmLocalUnixMakefileGenerator3*>(localGen);
// for the passed in makefile or if this is the top Makefile wripte out
// the targets
if (lg2 == lg || lg->IsRootMakefile()) {
// for each target Generate the rule files for each target.
- std::vector<cmGeneratorTarget*> targets = lg2->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- cmGeneratorTarget* target = *t;
+ for (cmGeneratorTarget* target : lg2->GetGeneratorTargets()) {
cmStateEnums::TargetType type = target->GetType();
if ((type == cmStateEnums::EXECUTABLE) ||
(type == cmStateEnums::STATIC_LIBRARY) ||
@@ -974,33 +966,12 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule(
}
}
}
- std::vector<std::string> const& localHelp = lg->GetLocalHelp();
- for (std::vector<std::string>::const_iterator o = localHelp.begin();
- o != localHelp.end(); ++o) {
+ for (std::string const& o : lg->GetLocalHelp()) {
path = "... ";
- path += *o;
+ path += o;
lg->AppendEcho(commands, path);
}
lg->WriteMakeRule(ruleFileStream, "Help Target", "help", no_depends,
commands, true);
ruleFileStream << "\n\n";
}
-
-bool cmGlobalUnixMakefileGenerator3::NeedRequiresStep(
- const cmGeneratorTarget* target)
-{
- std::set<std::string> languages;
- target->GetLanguages(
- languages,
- target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
- for (std::set<std::string>::const_iterator l = languages.begin();
- l != languages.end(); ++l) {
- std::string var = "CMAKE_NEEDS_REQUIRES_STEP_";
- var += *l;
- var += "_FLAG";
- if (target->Target->GetMakefile()->GetDefinition(var)) {
- return true;
- }
- }
- return false;
-}
diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h
index a656102fb..287472c81 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.h
+++ b/Source/cmGlobalUnixMakefileGenerator3.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalUnixMakefileGenerator3_h
#define cmGlobalUnixMakefileGenerator3_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
@@ -67,8 +67,8 @@ public:
cmGlobalUnixMakefileGenerator3>();
}
- ///! Get the name for the generator.
- std::string GetName() const CM_OVERRIDE
+ //! Get the name for the generator.
+ std::string GetName() const override
{
return cmGlobalUnixMakefileGenerator3::GetActualName();
}
@@ -89,23 +89,23 @@ public:
/** Get the documentation entry for this generator. */
static void GetDocumentation(cmDocumentationEntry& entry);
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) CM_OVERRIDE;
+ cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
/**
* Try to determine system information such as shared library
* extension, pthreads, byte order etc.
*/
void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
- bool optional) CM_OVERRIDE;
+ bool optional) override;
- void Configure() CM_OVERRIDE;
+ void Configure() override;
/**
* 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 Generate() CM_OVERRIDE;
+ void Generate() override;
void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
std::vector<cmLocalGenerator*>&);
@@ -127,14 +127,12 @@ public:
std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
// change the build command for speed
- 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, bool verbose,
- std::vector<std::string> const& makeOptions =
- std::vector<std::string>()) CM_OVERRIDE;
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
/** Record per-target progress information. */
void RecordTargetProgress(cmMakefileTargetGenerator* tg);
@@ -149,9 +147,9 @@ public:
/** Does the make tool tolerate .DELETE_ON_ERROR? */
virtual bool AllowDeleteOnError() const { return true; }
- bool IsIPOSupported() const CM_OVERRIDE { return true; }
+ bool IsIPOSupported() const override { return true; }
- void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const CM_OVERRIDE;
+ void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
std::string IncludeDirective;
bool DefineWindowsNULL;
@@ -167,48 +165,40 @@ protected:
void WriteDirectoryRule2(std::ostream& ruleFileStream,
cmLocalUnixMakefileGenerator3* lg, const char* pass,
- bool check_all, bool check_relink);
+ bool check_all, bool check_relink,
+ std::vector<std::string> const& commands = {});
void WriteDirectoryRules2(std::ostream& ruleFileStream,
cmLocalUnixMakefileGenerator3* lg);
void AppendGlobalTargetDepends(std::vector<std::string>& depends,
cmGeneratorTarget* target);
- // does this generator need a requires step for any of its targets
- bool NeedRequiresStep(cmGeneratorTarget const*);
-
// Target name hooks for superclass.
- const char* GetAllTargetName() const CM_OVERRIDE { return "all"; }
- const char* GetInstallTargetName() const CM_OVERRIDE { return "install"; }
- const char* GetInstallLocalTargetName() const CM_OVERRIDE
+ const char* GetAllTargetName() const override { return "all"; }
+ const char* GetInstallTargetName() const override { return "install"; }
+ const char* GetInstallLocalTargetName() const override
{
return "install/local";
}
- const char* GetInstallStripTargetName() const CM_OVERRIDE
+ const char* GetInstallStripTargetName() const override
{
return "install/strip";
}
- const char* GetPreinstallTargetName() const CM_OVERRIDE
- {
- return "preinstall";
- }
- const char* GetTestTargetName() const CM_OVERRIDE { return "test"; }
- const char* GetPackageTargetName() const CM_OVERRIDE { return "package"; }
- const char* GetPackageSourceTargetName() const CM_OVERRIDE
+ const char* GetPreinstallTargetName() const override { return "preinstall"; }
+ const char* GetTestTargetName() const override { return "test"; }
+ const char* GetPackageTargetName() const override { return "package"; }
+ const char* GetPackageSourceTargetName() const override
{
return "package_source";
}
- const char* GetEditCacheTargetName() const CM_OVERRIDE
- {
- return "edit_cache";
- }
- const char* GetRebuildCacheTargetName() const CM_OVERRIDE
+ const char* GetEditCacheTargetName() const override { return "edit_cache"; }
+ const char* GetRebuildCacheTargetName() const override
{
return "rebuild_cache";
}
- const char* GetCleanTargetName() const CM_OVERRIDE { return "clean"; }
+ const char* GetCleanTargetName() const override { return "clean"; }
- bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const CM_OVERRIDE { return true; }
+ bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() const override { 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
@@ -225,11 +215,7 @@ protected:
// Store per-target progress counters.
struct TargetProgress
{
- TargetProgress()
- : NumberOfActions(0)
- {
- }
- unsigned long NumberOfActions;
+ unsigned long NumberOfActions = 0;
std::string VariableFile;
std::vector<unsigned long> Marks;
void WriteProgressVariables(unsigned long total, unsigned long& current);
@@ -247,13 +233,13 @@ protected:
cmGeneratedFileStream* CommandDatabase;
private:
- const char* GetBuildIgnoreErrorsFlag() const CM_OVERRIDE { return "-i"; }
- std::string GetEditCacheCommand() const CM_OVERRIDE;
+ const char* GetBuildIgnoreErrorsFlag() const override { return "-i"; }
+ std::string GetEditCacheCommand() const override;
std::map<cmStateSnapshot, std::set<cmGeneratorTarget const*>,
cmStateSnapshot::StrictWeakOrder>
DirectoryTargetsMap;
- void InitializeProgressMarks() CM_OVERRIDE;
+ void InitializeProgressMarks() override;
};
#endif
diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx
index 4fff11a9f..55374a48e 100644
--- a/Source/cmGlobalVisualStudio10Generator.cxx
+++ b/Source/cmGlobalVisualStudio10Generator.cxx
@@ -7,20 +7,13 @@
#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudio10Generator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSourceFile.h"
-#include "cmVS10CLFlagTable.h"
-#include "cmVS10CSharpFlagTable.h"
-#include "cmVS10CudaFlagTable.h"
-#include "cmVS10CudaHostFlagTable.h"
-#include "cmVS10LibFlagTable.h"
-#include "cmVS10LinkFlagTable.h"
-#include "cmVS10MASMFlagTable.h"
-#include "cmVS10NASMFlagTable.h"
-#include "cmVS10RCFlagTable.h"
#include "cmVersion.h"
#include "cmVisualStudioSlnData.h"
#include "cmVisualStudioSlnParser.h"
#include "cmXMLWriter.h"
+#include "cm_jsoncpp_reader.h"
#include "cmake.h"
#include "cmsys/FStream.hxx"
@@ -30,6 +23,7 @@
#include <algorithm>
static const char vs10generatorName[] = "Visual Studio 10 2010";
+static std::map<std::string, std::vector<cmIDEFlagTable>> loadedFlagJsonFiles;
// Map generator name without year to name with year.
static const char* cmVS10GenName(const std::string& name, std::string& genName)
@@ -51,7 +45,7 @@ class cmGlobalVisualStudio10Generator::Factory
{
public:
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE
+ cmake* cm) const override
{
std::string genName;
const char* p = cmVS10GenName(name, genName);
@@ -73,22 +67,41 @@ public:
return 0;
}
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
+ void GetDocumentation(cmDocumentationEntry& entry) const override
{
entry.Name = std::string(vs10generatorName) + " [arch]";
entry.Brief = "Generates Visual Studio 2010 project files. "
"Optional [arch] can be \"Win64\" or \"IA64\".";
}
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
+ std::vector<std::string> GetGeneratorNames() const override
{
+ std::vector<std::string> names;
names.push_back(vs10generatorName);
+ return names;
+ }
+
+ std::vector<std::string> GetGeneratorNamesWithPlatform() const override
+ {
+ std::vector<std::string> names;
names.push_back(vs10generatorName + std::string(" IA64"));
names.push_back(vs10generatorName + std::string(" Win64"));
+ return names;
+ }
+
+ bool SupportsToolset() const override { return true; }
+ bool SupportsPlatform() const override { return true; }
+
+ std::vector<std::string> GetKnownPlatforms() const override
+ {
+ std::vector<std::string> platforms;
+ platforms.emplace_back("x64");
+ platforms.emplace_back("Win32");
+ platforms.emplace_back("Itanium");
+ return platforms;
}
- bool SupportsToolset() const CM_OVERRIDE { return true; }
- bool SupportsPlatform() const CM_OVERRIDE { return true; }
+ std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory()
@@ -97,8 +110,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory()
}
cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
- cmake* cm, const std::string& name, const std::string& platformName)
- : cmGlobalVisualStudio8Generator(cm, name, platformName)
+ cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName)
+ : cmGlobalVisualStudio8Generator(cm, name, platformInGeneratorName)
{
std::string vc10Express;
this->ExpressEdition = cmSystemTools::ReadRegistryValue(
@@ -120,15 +134,16 @@ cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator(
this->DefaultPlatformToolset = "v100";
}
}
- this->DefaultClFlagTable = cmVS10CLFlagTable;
- this->DefaultCSharpFlagTable = cmVS10CSharpFlagTable;
- this->DefaultLibFlagTable = cmVS10LibFlagTable;
- this->DefaultLinkFlagTable = cmVS10LinkFlagTable;
- this->DefaultCudaFlagTable = cmVS10CudaFlagTable;
- this->DefaultCudaHostFlagTable = cmVS10CudaHostFlagTable;
- this->DefaultMasmFlagTable = cmVS10MASMFlagTable;
- this->DefaultNasmFlagTable = cmVS10NASMFlagTable;
- this->DefaultRcFlagTable = cmVS10RCFlagTable;
+ this->DefaultCLFlagTableName = "v10";
+ this->DefaultCSharpFlagTableName = "v10";
+ this->DefaultLibFlagTableName = "v10";
+ this->DefaultLinkFlagTableName = "v10";
+ this->DefaultCudaFlagTableName = "v10";
+ this->DefaultCudaHostFlagTableName = "v10";
+ this->DefaultMasmFlagTableName = "v10";
+ this->DefaultNasmFlagTableName = "v10";
+ this->DefaultRCFlagTableName = "v10";
+
this->Version = VS10;
this->PlatformToolsetNeedsDebugEnum = false;
}
@@ -184,7 +199,7 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
std::ostringstream e;
e << this->GetName() << " Windows CE version '" << this->SystemVersion
<< "' requires CMAKE_GENERATOR_TOOLSET to be set.";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
@@ -231,9 +246,73 @@ bool cmGlobalVisualStudio10Generator::SetGeneratorToolset(
}
}
+ if (!this->GeneratorToolsetVersion.empty() &&
+ this->GeneratorToolsetVersion != "Test Toolset Version") {
+ // If a specific minor version of the toolset was requested, verify that it
+ // is compatible to the major version and that is exists on disk.
+ // If not clear the value.
+ std::string version = this->GeneratorToolsetVersion;
+ cmsys::RegularExpression regex("[0-9][0-9]\\.[0-9][0-9]");
+ if (regex.find(version)) {
+ version = "v" + version.erase(2, 1);
+ } else {
+ // Version not recognized. Clear it.
+ version.clear();
+ }
+
+ if (version.find(this->GetPlatformToolsetString()) != 0) {
+ std::ostringstream e;
+ /* clang-format off */
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "given toolset and version specification\n"
+ " " << this->GetPlatformToolsetString() << ",version=" <<
+ this->GeneratorToolsetVersion << "\n"
+ "contains an invalid version specification."
+ ;
+ /* clang-format on */
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
+
+ // Clear the configured tool-set
+ this->GeneratorToolsetVersion.clear();
+ }
+
+ bool const isDefaultToolset =
+ this->IsDefaultToolset(this->GeneratorToolsetVersion);
+ if (isDefaultToolset) {
+ // If the given version is the default toolset, remove the setting
+ this->GeneratorToolsetVersion.clear();
+ } else {
+ std::string const toolsetPath = this->GetAuxiliaryToolset();
+ if (!toolsetPath.empty() && !cmSystemTools::FileExists(toolsetPath)) {
+
+ std::ostringstream e;
+ /* clang-format off */
+ e <<
+ "Generator\n"
+ " " << this->GetName() << "\n"
+ "given toolset and version specification\n"
+ " " << this->GetPlatformToolsetString() << ",version=" <<
+ this->GeneratorToolsetVersion << "\n"
+ "does not seem to be installed at\n" <<
+ " " << toolsetPath;
+ ;
+ /* clang-format on */
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
+
+ // Clear the configured tool-set
+ this->GeneratorToolsetVersion.clear();
+ }
+ }
+ }
+
if (const char* toolset = this->GetPlatformToolset()) {
mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET", toolset);
}
+ if (const char* version = this->GetPlatformToolsetVersion()) {
+ mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_VERSION", version);
+ }
if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) {
mf->AddDefinition("CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE", hostArch);
}
@@ -274,7 +353,7 @@ bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
"that contains a field after the first ',' with no '='."
;
/* clang-format on */
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
std::string const key = fi->substr(0, pos);
@@ -290,7 +369,7 @@ bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
"that contains duplicate field key '" << key << "'."
;
/* clang-format on */
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
if (!this->ProcessGeneratorToolsetField(key, value)) {
@@ -304,7 +383,7 @@ bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset(
"that contains invalid field '" << *fi << "'."
;
/* clang-format on */
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
}
@@ -319,6 +398,10 @@ bool cmGlobalVisualStudio10Generator::ProcessGeneratorToolsetField(
this->GeneratorToolsetCuda = value;
return true;
}
+ if (key == "version") {
+ this->GeneratorToolsetVersion = value;
+ return true;
+ }
return false;
}
@@ -344,16 +427,16 @@ bool cmGlobalVisualStudio10Generator::InitializeSystem(cmMakefile* mf)
return false;
}
} else if (this->SystemName == "Android") {
- if (this->DefaultPlatformName != "Win32") {
+ if (this->PlatformInGeneratorName) {
std::ostringstream e;
e << "CMAKE_SYSTEM_NAME is 'Android' but CMAKE_GENERATOR "
<< "specifies a platform too: '" << this->GetName() << "'";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
std::string v = this->GetInstalledNsightTegraVersion();
if (v.empty()) {
- mf->IssueMessage(cmake::FATAL_ERROR,
+ mf->IssueMessage(MessageType::FATAL_ERROR,
"CMAKE_SYSTEM_NAME is 'Android' but "
"'NVIDIA Nsight Tegra Visual Studio Edition' "
"is not installed.");
@@ -375,11 +458,11 @@ bool cmGlobalVisualStudio10Generator::InitializeWindows(cmMakefile*)
bool cmGlobalVisualStudio10Generator::InitializeWindowsCE(cmMakefile* mf)
{
- if (this->DefaultPlatformName != "Win32") {
+ if (this->PlatformInGeneratorName) {
std::ostringstream e;
e << "CMAKE_SYSTEM_NAME is 'WindowsCE' but CMAKE_GENERATOR "
<< "specifies a platform too: '" << this->GetName() << "'";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
@@ -392,7 +475,7 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsPhone(cmMakefile* mf)
{
std::ostringstream e;
e << this->GetName() << " does not support Windows Phone.";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
@@ -400,21 +483,21 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf)
{
std::ostringstream e;
e << this->GetName() << " does not support Windows Store.";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
bool cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset(
std::string& toolset) const
{
- toolset = "";
+ toolset.clear();
return false;
}
bool cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset(
std::string& toolset) const
{
- toolset = "";
+ toolset.clear();
return false;
}
@@ -426,17 +509,7 @@ std::string cmGlobalVisualStudio10Generator::SelectWindowsCEToolset() const
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
+//! Create a local generator appropriate to this Global Generator
cmLocalGenerator* cmGlobalVisualStudio10Generator::CreateLocalGenerator(
cmMakefile* mf)
{
@@ -471,19 +544,18 @@ void cmGlobalVisualStudio10Generator::Generate()
"To avoid this problem CMake must use a full path for this file "
"which then triggers the VS 10 property dialog bug.";
/* clang-format on */
- lg->IssueMessage(cmake::WARNING, e.str().c_str());
+ lg->IssueMessage(MessageType::WARNING, e.str().c_str());
}
}
void cmGlobalVisualStudio10Generator::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_NASM") {
+ for (std::string const& it : lang) {
+ if (it == "ASM_NASM") {
this->NasmEnabled = true;
}
- if (*it == "CUDA") {
+ if (it == "CUDA") {
this->CudaEnabled = true;
}
}
@@ -495,7 +567,7 @@ const char* cmGlobalVisualStudio10Generator::GetPlatformToolset() const
{
std::string const& toolset = this->GetPlatformToolsetString();
if (toolset.empty()) {
- return CM_NULLPTR;
+ return nullptr;
}
return toolset.c_str();
}
@@ -513,13 +585,48 @@ std::string const& cmGlobalVisualStudio10Generator::GetPlatformToolsetString()
return empty;
}
+const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetVersion() const
+{
+ std::string const& version = this->GetPlatformToolsetVersionString();
+ if (version.empty()) {
+ return nullptr;
+ }
+ return version.c_str();
+}
+
+std::string const&
+cmGlobalVisualStudio10Generator::GetPlatformToolsetVersionString() const
+{
+ if (!this->GeneratorToolsetVersion.empty()) {
+ return this->GeneratorToolsetVersion;
+ }
+ static std::string const empty;
+ return empty;
+}
+
const char*
cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitecture() const
{
+ std::string const& hostArch =
+ this->GetPlatformToolsetHostArchitectureString();
+ if (hostArch.empty()) {
+ return nullptr;
+ }
+ return hostArch.c_str();
+}
+
+std::string const&
+cmGlobalVisualStudio10Generator::GetPlatformToolsetHostArchitectureString()
+ const
+{
if (!this->GeneratorToolsetHostArchitecture.empty()) {
- return this->GeneratorToolsetHostArchitecture.c_str();
+ return this->GeneratorToolsetHostArchitecture;
+ }
+ if (!this->DefaultPlatformToolsetHostArchitecture.empty()) {
+ return this->DefaultPlatformToolsetHostArchitecture;
}
- return CM_NULLPTR;
+ static std::string const empty;
+ return empty;
}
const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
@@ -527,7 +634,7 @@ const char* cmGlobalVisualStudio10Generator::GetPlatformToolsetCuda() const
if (!this->GeneratorToolsetCuda.empty()) {
return this->GeneratorToolsetCuda.c_str();
}
- return CM_NULLPTR;
+ return nullptr;
}
std::string const&
@@ -536,6 +643,17 @@ cmGlobalVisualStudio10Generator::GetPlatformToolsetCudaString() const
return this->GeneratorToolsetCuda;
}
+bool cmGlobalVisualStudio10Generator::IsDefaultToolset(
+ const std::string&) const
+{
+ return true;
+}
+
+std::string cmGlobalVisualStudio10Generator::GetAuxiliaryToolset() const
+{
+ return {};
+}
+
bool cmGlobalVisualStudio10Generator::FindMakeProgram(cmMakefile* mf)
{
if (!this->cmGlobalVisualStudio8Generator::FindMakeProgram(mf)) {
@@ -604,7 +722,7 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
wd = this->ConfiguredFilesPath;
} else {
wd = this->GetCMakeInstance()->GetHomeOutputDirectory();
- wd += cmake::GetCMakeFilesDirectory();
+ wd += "/CMakeFiles";
}
wd += "/";
wd += cmVersion::GetCMakeVersion();
@@ -625,7 +743,7 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
// Prepare the work directory.
if (!cmSystemTools::MakeDirectory(wd)) {
std::string e = "Failed to make directory:\n " + wd;
- mf->IssueMessage(cmake::FATAL_ERROR, e.c_str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.c_str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -637,121 +755,88 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
cmsys::ofstream fout(vcxprojAbs.c_str());
cmXMLWriter xw(fout);
- /* clang-format off */
- xw.StartDocument();
- xw.StartElement("Project");
- xw.Attribute("DefaultTargets", "Build");
- xw.Attribute("ToolsVersion", "4.0");
- xw.Attribute("xmlns",
- "http://schemas.microsoft.com/developer/msbuild/2003");
- if (this->IsNsightTegra()) {
- xw.StartElement("PropertyGroup");
- xw.Attribute("Label", "NsightTegraProject");
- xw.StartElement("NsightTegraProjectRevisionNumber");
- xw.Content("6");
- xw.EndElement(); // NsightTegraProjectRevisionNumber
- xw.EndElement(); // PropertyGroup
- }
- xw.StartElement("ItemGroup");
- xw.Attribute("Label", "ProjectConfigurations");
- xw.StartElement("ProjectConfiguration");
- xw.Attribute("Include", "Debug|" + this->GetPlatformName());
- xw.StartElement("Configuration");
- xw.Content("Debug");
- xw.EndElement(); // Configuration
- xw.StartElement("Platform");
- xw.Content(this->GetPlatformName());
- xw.EndElement(); // Platform
- xw.EndElement(); // ProjectConfiguration
- xw.EndElement(); // ItemGroup
- xw.StartElement("PropertyGroup");
- xw.Attribute("Label", "Globals");
- xw.StartElement("ProjectGuid");
- xw.Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
- xw.EndElement(); // ProjectGuid
- xw.StartElement("Keyword");
- xw.Content("Win32Proj");
- xw.EndElement(); // Keyword
- xw.StartElement("Platform");
- xw.Content(this->GetPlatformName());
- xw.EndElement(); // Platform
- if (this->GetSystemName() == "WindowsPhone") {
- xw.StartElement("ApplicationType");
- xw.Content("Windows Phone");
- xw.EndElement(); // ApplicationType
- xw.StartElement("ApplicationTypeRevision");
- xw.Content(this->GetSystemVersion());
- xw.EndElement(); // ApplicationTypeRevision
- } else if (this->GetSystemName() == "WindowsStore") {
- xw.StartElement("ApplicationType");
- xw.Content("Windows Store");
- xw.EndElement(); // ApplicationType
- xw.StartElement("ApplicationTypeRevision");
- xw.Content(this->GetSystemVersion());
- xw.EndElement(); // ApplicationTypeRevision
- }
- if (!this->WindowsTargetPlatformVersion.empty()) {
- xw.StartElement("WindowsTargetPlatformVersion");
- xw.Content(this->WindowsTargetPlatformVersion);
- xw.EndElement(); // WindowsTargetPlatformVersion
- }
- if (this->GetPlatformName() == "ARM") {
- xw.StartElement("WindowsSDKDesktopARMSupport");
- xw.Content("true");
- xw.EndElement(); // WindowsSDKDesktopARMSupport
- }
- xw.EndElement(); // PropertyGroup
- xw.StartElement("Import");
- xw.Attribute("Project",
- "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
- xw.EndElement(); // Import
- if (!this->GeneratorToolsetHostArchitecture.empty()) {
- xw.StartElement("PropertyGroup");
- xw.StartElement("PreferredToolArchitecture");
- xw.Content(this->GeneratorToolsetHostArchitecture);
- xw.EndElement(); // PreferredToolArchitecture
- xw.EndElement(); // PropertyGroup
+ cmXMLDocument doc(xw);
+ cmXMLElement eprj(doc, "Project");
+ eprj.Attribute("DefaultTargets", "Build");
+ eprj.Attribute("ToolsVersion", "4.0");
+ eprj.Attribute("xmlns",
+ "http://schemas.microsoft.com/developer/msbuild/2003");
+ if (this->IsNsightTegra()) {
+ cmXMLElement epg(eprj, "PropertyGroup");
+ epg.Attribute("Label", "NsightTegraProject");
+ cmXMLElement(epg, "NsightTegraProjectRevisionNumber").Content("6");
+ }
+ {
+ cmXMLElement eig(eprj, "ItemGroup");
+ eig.Attribute("Label", "ProjectConfigurations");
+ cmXMLElement epc(eig, "ProjectConfiguration");
+ epc.Attribute("Include", "Debug|" + this->GetPlatformName());
+ cmXMLElement(epc, "Configuration").Content("Debug");
+ cmXMLElement(epc, "Platform").Content(this->GetPlatformName());
+ }
+ {
+ cmXMLElement epg(eprj, "PropertyGroup");
+ epg.Attribute("Label", "Globals");
+ cmXMLElement(epg, "ProjectGuid")
+ .Content("{F3FC6D86-508D-3FB1-96D2-995F08B142EC}");
+ cmXMLElement(epg, "Keyword").Content("Win32Proj");
+ cmXMLElement(epg, "Platform").Content(this->GetPlatformName());
+ if (this->GetSystemName() == "WindowsPhone") {
+ cmXMLElement(epg, "ApplicationType").Content("Windows Phone");
+ cmXMLElement(epg, "ApplicationTypeRevision")
+ .Content(this->GetApplicationTypeRevision());
+ } else if (this->GetSystemName() == "WindowsStore") {
+ cmXMLElement(epg, "ApplicationType").Content("Windows Store");
+ cmXMLElement(epg, "ApplicationTypeRevision")
+ .Content(this->GetApplicationTypeRevision());
+ }
+ if (!this->WindowsTargetPlatformVersion.empty()) {
+ cmXMLElement(epg, "WindowsTargetPlatformVersion")
+ .Content(this->WindowsTargetPlatformVersion);
+ }
+ if (this->GetPlatformName() == "ARM64") {
+ cmXMLElement(epg, "WindowsSDKDesktopARM64Support").Content("true");
+ } else if (this->GetPlatformName() == "ARM") {
+ cmXMLElement(epg, "WindowsSDKDesktopARMSupport").Content("true");
+ }
}
- xw.StartElement("PropertyGroup");
- xw.Attribute("Label", "Configuration");
- xw.StartElement("ConfigurationType");
+ cmXMLElement(eprj, "Import")
+ .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.Default.props");
+ if (const char* hostArch = this->GetPlatformToolsetHostArchitecture()) {
+ cmXMLElement epg(eprj, "PropertyGroup");
+ cmXMLElement(epg, "PreferredToolArchitecture").Content(hostArch);
+ }
+ {
+ cmXMLElement epg(eprj, "PropertyGroup");
+ epg.Attribute("Label", "Configuration");
+ {
+ cmXMLElement ect(epg, "ConfigurationType");
+ if (this->IsNsightTegra()) {
+ // Tegra-Android platform does not understand "Utility".
+ ect.Content("StaticLibrary");
+ } else {
+ ect.Content("Utility");
+ }
+ }
+ cmXMLElement(epg, "CharacterSet").Content("MultiByte");
if (this->IsNsightTegra()) {
- // Tegra-Android platform does not understand "Utility".
- xw.Content("StaticLibrary");
+ cmXMLElement(epg, "NdkToolchainVersion")
+ .Content(this->GetPlatformToolsetString());
} else {
- xw.Content("Utility");
+ cmXMLElement(epg, "PlatformToolset")
+ .Content(this->GetPlatformToolsetString());
}
- xw.EndElement(); // ConfigurationType
- xw.StartElement("CharacterSet");
- xw.Content("MultiByte");
- xw.EndElement(); // CharacterSet
- if (this->IsNsightTegra()) {
- xw.StartElement("NdkToolchainVersion");
- xw.Content(this->GetPlatformToolsetString());
- xw.EndElement(); // NdkToolchainVersion
- } else {
- xw.StartElement("PlatformToolset");
- xw.Content(this->GetPlatformToolsetString());
- xw.EndElement(); // PlatformToolset
- }
- xw.EndElement(); // PropertyGroup
- xw.StartElement("Import");
- xw.Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
- xw.EndElement(); // Import
- xw.StartElement("ItemDefinitionGroup");
- xw.StartElement("PostBuildEvent");
- xw.StartElement("Command");
- xw.Content("echo VCTargetsPath=$(VCTargetsPath)");
- xw.EndElement(); // Command
- xw.EndElement(); // PostBuildEvent
- xw.EndElement(); // ItemDefinitionGroup
- xw.StartElement("Import");
- xw.Attribute("Project",
- "$(VCTargetsPath)\\Microsoft.Cpp.targets");
- xw.EndElement(); // Import
- xw.EndElement(); // Project
- xw.EndDocument();
- /* clang-format on */
+ }
+ cmXMLElement(eprj, "Import")
+ .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.props");
+ {
+ cmXMLElement eidg(eprj, "ItemDefinitionGroup");
+ cmXMLElement epbe(eidg, "PostBuildEvent");
+ cmXMLElement(epbe, "Command")
+ .Content("echo VCTargetsPath=$(VCTargetsPath)");
+ }
+ cmXMLElement(eprj, "Import")
+ .Attribute("Project", "$(VCTargetsPath)\\Microsoft.Cpp.targets");
}
std::vector<std::string> cmd;
@@ -779,7 +864,7 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
if (ret != 0) {
e << "Exit code: " << ret << "\n";
}
- mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -793,12 +878,14 @@ bool cmGlobalVisualStudio10Generator::FindVCTargetsPath(cmMakefile* mf)
return true;
}
-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,
- bool verbose, std::vector<std::string> const& makeOptions)
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalVisualStudio10Generator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions)
{
+ std::vector<GeneratedMakeCommand> makeCommands;
// Select the caller- or user-preferred make program, else MSBuild.
std::string makeProgramSelected =
this->SelectMakeProgram(makeProgram, this->GetMSBuildCommand());
@@ -809,6 +896,10 @@ void cmGlobalVisualStudio10Generator::GenerateBuildCommand(
bool useDevEnv = (makeProgramLower.find("devenv") != std::string::npos ||
makeProgramLower.find("vcexpress") != std::string::npos);
+ // Workaround to convince VCExpress.exe to produce output.
+ const bool requiresOutputForward =
+ (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;
@@ -824,9 +915,11 @@ void cmGlobalVisualStudio10Generator::GenerateBuildCommand(
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();
+ for (cmSlnProjectEntry const& project : slnProjects) {
+ if (useDevEnv) {
+ break;
+ }
+ std::string proj = project.GetRelativePath();
if (proj.size() > 7 && proj.substr(proj.size() - 7) == ".vfproj") {
useDevEnv = true;
}
@@ -835,46 +928,71 @@ void cmGlobalVisualStudio10Generator::GenerateBuildCommand(
}
if (useDevEnv) {
// Use devenv to build solutions containing Intel Fortran projects.
- cmGlobalVisualStudio7Generator::GenerateBuildCommand(
- makeCommand, makeProgram, projectName, projectDir, targetName, config,
- fast, verbose, makeOptions);
- return;
+ return cmGlobalVisualStudio7Generator::GenerateBuildCommand(
+ makeProgram, projectName, projectDir, targetNames, config, fast, jobs,
+ verbose, makeOptions);
}
- 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";
+ std::vector<std::string> realTargetNames = targetNames;
+ if (targetNames.empty() ||
+ ((targetNames.size() == 1) && targetNames.front().empty())) {
+ realTargetNames = { "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);
+ for (const auto& tname : realTargetNames) {
+ // msbuild.exe CxxOnly.sln /t:Build /p:Configuration=Debug
+ // /target:ALL_BUILD
+ // /m
+ if (tname.empty()) {
+ continue;
+ }
+
+ GeneratedMakeCommand makeCommand;
+ makeCommand.RequiresOutputForward = requiresOutputForward;
+ makeCommand.Add(makeProgramSelected);
+
+ if (tname == "clean") {
+ makeCommand.Add(std::string(projectName) + ".sln");
+ makeCommand.Add("/t:Clean");
+ } else {
+ std::string targetProject(tname);
+ targetProject += ".vcxproj";
+ if (targetProject.find('/') == std::string::npos) {
+ // it might be in a subdir
+ if (cmSlnProjectEntry const* proj = slnData.GetProjectByName(tname)) {
+ targetProject = proj->GetRelativePath();
+ cmSystemTools::ConvertToUnixSlashes(targetProject);
+ }
}
+ makeCommand.Add(std::move(targetProject));
}
- makeCommand.push_back(targetProject);
- }
- std::string configArg = "/p:Configuration=";
- if (!config.empty()) {
- configArg += config;
- } else {
- configArg += "Debug";
+ std::string configArg = "/p:Configuration=";
+ if (!config.empty()) {
+ configArg += config;
+ } else {
+ configArg += "Debug";
+ }
+ makeCommand.Add(configArg);
+ makeCommand.Add(std::string("/p:Platform=") + this->GetPlatformName());
+ makeCommand.Add(std::string("/p:VisualStudioVersion=") +
+ this->GetIDEVersion());
+
+ if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
+ if (jobs == cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
+ makeCommand.Add("/m");
+ } else {
+ makeCommand.Add(std::string("/m:") + std::to_string(jobs));
+ }
+ // Having msbuild.exe and cl.exe using multiple jobs is discouraged
+ makeCommand.Add("/p:CL_MPCount=1");
+ }
+
+ // Respect the verbosity: 'n' normal will show build commands
+ // 'm' minimal only the build step's title
+ makeCommand.Add(std::string("/v:") + ((verbose) ? "n" : "m"));
+ makeCommand.Add(makeOptions.begin(), makeOptions.end());
+ makeCommands.emplace_back(std::move(makeCommand));
}
- makeCommand.push_back(configArg);
- makeCommand.push_back(std::string("/p:VisualStudioVersion=") +
- this->GetIDEVersion());
- makeCommand.insert(makeCommand.end(), makeOptions.begin(),
- makeOptions.end());
+ return makeCommands;
}
bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
@@ -899,7 +1017,7 @@ bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
winSDK_7_1)) {
std::ostringstream m;
m << "Found Windows SDK v7.1: " << winSDK_7_1;
- mf->DisplayStatus(m.str().c_str(), -1);
+ mf->DisplayStatus(m.str(), -1);
this->DefaultPlatformToolset = "Windows7.1SDK";
return true;
} else {
@@ -909,7 +1027,7 @@ bool cmGlobalVisualStudio10Generator::Find64BitTools(cmMakefile* mf)
<< "Install the Microsoft Windows SDK v7.1 to get 64-bit tools:\n"
<< " http://msdn.microsoft.com/en-us/windows/bb980924.aspx";
/* clang-format on */
- mf->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str());
cmSystemTools::SetFatalErrorOccured();
return false;
}
@@ -921,7 +1039,7 @@ std::string cmGlobalVisualStudio10Generator::GenerateRuleFile(
// 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 += "/CMakeFiles";
ruleDir += "/";
ruleDir += cmSystemTools::ComputeStringMD5(
cmSystemTools::GetFilenamePath(output).c_str());
@@ -936,7 +1054,7 @@ void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
std::string const& sfRel)
{
size_t len =
- (strlen(target->GetLocalGenerator()->GetCurrentBinaryDirectory()) + 1 +
+ (target->GetLocalGenerator()->GetCurrentBinaryDirectory().length() + 1 +
sfRel.length());
if (len > this->LongestSource.Length) {
this->LongestSource.Length = len;
@@ -946,6 +1064,34 @@ void cmGlobalVisualStudio10Generator::PathTooLong(cmGeneratorTarget* target,
}
}
+std::string cmGlobalVisualStudio10Generator::Encoding()
+{
+ return "utf-8";
+}
+
+const char* cmGlobalVisualStudio10Generator::GetToolsVersion() const
+{
+ switch (this->Version) {
+ case cmGlobalVisualStudioGenerator::VS9:
+ case cmGlobalVisualStudioGenerator::VS10:
+ case cmGlobalVisualStudioGenerator::VS11:
+ return "4.0";
+
+ // 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
+ case cmGlobalVisualStudioGenerator::VS12:
+ return "12.0";
+ case cmGlobalVisualStudioGenerator::VS14:
+ return "14.0";
+ case cmGlobalVisualStudioGenerator::VS15:
+ return "15.0";
+ case cmGlobalVisualStudioGenerator::VS16:
+ return "16.0";
+ }
+ return "";
+}
+
bool cmGlobalVisualStudio10Generator::IsNsightTegra() const
{
return !this->NsightTegraVersion.empty();
@@ -966,67 +1112,227 @@ std::string cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion()
return version;
}
+std::string cmGlobalVisualStudio10Generator::GetApplicationTypeRevision() const
+{
+ // Return the first two '.'-separated components of the Windows version.
+ std::string::size_type end1 = this->SystemVersion.find('.');
+ std::string::size_type end2 =
+ end1 == std::string::npos ? end1 : this->SystemVersion.find('.', end1 + 1);
+ return this->SystemVersion.substr(0, end2);
+}
+
+static std::string cmLoadFlagTableString(Json::Value entry, const char* field)
+{
+ if (entry.isMember(field)) {
+ auto string = entry[field];
+ if (string.isConvertibleTo(Json::ValueType::stringValue)) {
+ return string.asString();
+ }
+ }
+ return "";
+}
+
+static unsigned int cmLoadFlagTableSpecial(Json::Value entry,
+ const char* field)
+{
+ unsigned int value = 0;
+ if (entry.isMember(field)) {
+ auto specials = entry[field];
+ if (specials.isArray()) {
+ for (auto const& special : specials) {
+ std::string s = special.asString();
+ if (s == "UserValue") {
+ value |= cmIDEFlagTable::UserValue;
+ } else if (s == "UserIgnored") {
+ value |= cmIDEFlagTable::UserIgnored;
+ } else if (s == "UserRequired") {
+ value |= cmIDEFlagTable::UserRequired;
+ } else if (s == "Continue") {
+ value |= cmIDEFlagTable::Continue;
+ } else if (s == "SemicolonAppendable") {
+ value |= cmIDEFlagTable::SemicolonAppendable;
+ } else if (s == "UserFollowing") {
+ value |= cmIDEFlagTable::UserFollowing;
+ } else if (s == "CaseInsensitive") {
+ value |= cmIDEFlagTable::CaseInsensitive;
+ } else if (s == "SpaceAppendable") {
+ value |= cmIDEFlagTable::SpaceAppendable;
+ } else if (s == "CommaAppendable") {
+ value |= cmIDEFlagTable::CommaAppendable;
+ }
+ }
+ }
+ }
+ return value;
+}
+
+static cmIDEFlagTable const* cmLoadFlagTableJson(
+ std::string const& flagJsonPath)
+{
+ cmIDEFlagTable* ret = nullptr;
+ auto savedFlagIterator = loadedFlagJsonFiles.find(flagJsonPath);
+ if (savedFlagIterator != loadedFlagJsonFiles.end()) {
+ ret = savedFlagIterator->second.data();
+ } else {
+ Json::Reader reader;
+ cmsys::ifstream stream;
+
+ stream.open(flagJsonPath.c_str(), std::ios_base::in);
+ if (stream) {
+ Json::Value flags;
+ if (reader.parse(stream, flags, false) && flags.isArray()) {
+ std::vector<cmIDEFlagTable> flagTable;
+ for (auto const& flag : flags) {
+ cmIDEFlagTable flagEntry;
+ flagEntry.IDEName = cmLoadFlagTableString(flag, "name");
+ flagEntry.commandFlag = cmLoadFlagTableString(flag, "switch");
+ flagEntry.comment = cmLoadFlagTableString(flag, "comment");
+ flagEntry.value = cmLoadFlagTableString(flag, "value");
+ flagEntry.special = cmLoadFlagTableSpecial(flag, "flags");
+ flagTable.push_back(flagEntry);
+ }
+ cmIDEFlagTable endFlag{ "", "", "", "", 0 };
+ flagTable.push_back(endFlag);
+
+ loadedFlagJsonFiles[flagJsonPath] = flagTable;
+ ret = loadedFlagJsonFiles[flagJsonPath].data();
+ }
+ }
+ }
+ return ret;
+}
+
+static std::string cmGetFlagTableName(std::string const& toolsetName,
+ std::string const& table)
+{
+ return cmSystemTools::GetCMakeRoot() + "/Templates/MSBuild/FlagTables/" +
+ toolsetName + "_" + table + ".json";
+}
+
+cmIDEFlagTable const* cmGlobalVisualStudio10Generator::LoadFlagTable(
+ std::string const& optionsName, std::string const& toolsetName,
+ std::string const& defaultName, std::string const& table) const
+{
+ cmIDEFlagTable const* ret = nullptr;
+
+ std::string filename;
+ if (!optionsName.empty()) {
+ filename = cmGetFlagTableName(optionsName, table);
+ ret = cmLoadFlagTableJson(filename);
+ } else {
+ filename = cmGetFlagTableName(toolsetName, table);
+ if (cmSystemTools::FileExists(filename)) {
+ ret = cmLoadFlagTableJson(filename);
+ } else {
+ filename = cmGetFlagTableName(defaultName, table);
+ ret = cmLoadFlagTableJson(filename);
+ }
+ }
+
+ if (!ret) {
+ cmMakefile* mf = this->GetCurrentMakefile();
+
+ std::ostringstream e;
+ /* clang-format off */
+ e << "JSON flag table \"" << filename <<
+ "\" could not be loaded.\n";
+ /* clang-format on */
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str().c_str());
+ }
+ return ret;
+}
+
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetClFlagTable() const
{
- cmIDEFlagTable const* table = this->ToolsetOptions.GetClFlagTable(
+ std::string optionsName = this->ToolsetOptions.GetClFlagTableName(
this->GetPlatformName(), this->GetPlatformToolsetString());
-
- return (table != CM_NULLPTR) ? table : this->DefaultClFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultCLFlagTableName);
+ return LoadFlagTable(optionsName, toolsetName, defaultName, "CL");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCSharpFlagTable()
const
{
- cmIDEFlagTable const* table = this->ToolsetOptions.GetCSharpFlagTable(
+ std::string optionsName = this->ToolsetOptions.GetCSharpFlagTableName(
this->GetPlatformName(), this->GetPlatformToolsetString());
-
- return (table != CM_NULLPTR) ? table : this->DefaultCSharpFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultCSharpFlagTableName);
+ return LoadFlagTable(optionsName, toolsetName, defaultName, "CSharp");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetRcFlagTable() const
{
- cmIDEFlagTable const* table = this->ToolsetOptions.GetRcFlagTable(
+ std::string optionsName = this->ToolsetOptions.GetRcFlagTableName(
this->GetPlatformName(), this->GetPlatformToolsetString());
-
- return (table != CM_NULLPTR) ? table : this->DefaultRcFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultRCFlagTableName);
+ return LoadFlagTable(optionsName, toolsetName, defaultName, "RC");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLibFlagTable() const
{
- cmIDEFlagTable const* table = this->ToolsetOptions.GetLibFlagTable(
+ std::string optionsName = this->ToolsetOptions.GetLibFlagTableName(
this->GetPlatformName(), this->GetPlatformToolsetString());
-
- return (table != CM_NULLPTR) ? table : this->DefaultLibFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultLibFlagTableName);
+ return LoadFlagTable(optionsName, toolsetName, defaultName, "LIB");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetLinkFlagTable() const
{
- cmIDEFlagTable const* table = this->ToolsetOptions.GetLinkFlagTable(
+ std::string optionsName = this->ToolsetOptions.GetLinkFlagTableName(
this->GetPlatformName(), this->GetPlatformToolsetString());
-
- return (table != CM_NULLPTR) ? table : this->DefaultLinkFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultLinkFlagTableName);
+ return LoadFlagTable(optionsName, toolsetName, defaultName, "Link");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaFlagTable() const
{
- return this->DefaultCudaFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultCudaFlagTableName);
+ return LoadFlagTable("", toolsetName, defaultName, "Cuda");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetCudaHostFlagTable()
const
{
- return this->DefaultCudaHostFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultCudaHostFlagTableName);
+ return LoadFlagTable("", toolsetName, defaultName, "CudaHost");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetMasmFlagTable() const
{
- cmIDEFlagTable const* table = this->ToolsetOptions.GetMasmFlagTable(
+ std::string optionsName = this->ToolsetOptions.GetMasmFlagTableName(
this->GetPlatformName(), this->GetPlatformToolsetString());
-
- return (table != CM_NULLPTR) ? table : this->DefaultMasmFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultMasmFlagTableName);
+ return LoadFlagTable(optionsName, toolsetName, defaultName, "MASM");
}
cmIDEFlagTable const* cmGlobalVisualStudio10Generator::GetNasmFlagTable() const
{
- return this->DefaultNasmFlagTable;
+ std::string toolsetName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->GetPlatformToolsetString());
+ std::string defaultName = this->ToolsetOptions.GetToolsetName(
+ this->GetPlatformName(), this->DefaultNasmFlagTableName);
+ return LoadFlagTable("", toolsetName, defaultName, "NASM");
}
diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h
index 4a5c2454b..1d30cd6b3 100644
--- a/Source/cmGlobalVisualStudio10Generator.h
+++ b/Source/cmGlobalVisualStudio10Generator.h
@@ -14,33 +14,30 @@
class cmGlobalVisualStudio10Generator : public cmGlobalVisualStudio8Generator
{
public:
- cmGlobalVisualStudio10Generator(cmake* cm, const std::string& name,
- const std::string& platformName);
static cmGlobalGeneratorFactory* NewFactory();
- virtual bool MatchesGeneratorName(const std::string& name) const;
+ bool MatchesGeneratorName(const std::string& name) const override;
- 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);
+ bool SetSystemName(std::string const& s, cmMakefile* mf) override;
+ bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
+ bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override;
- 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,
- bool verbose,
- std::vector<std::string> const& makeOptions = std::vector<std::string>());
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
- ///! create the correct local generator
- virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf);
+ //! create the correct local generator
+ cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
/**
* 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);
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
bool IsCudaEnabled() const { return this->CudaEnabled; }
@@ -52,8 +49,13 @@ public:
const char* GetPlatformToolset() const;
std::string const& GetPlatformToolsetString() const;
+ /** The toolset version. */
+ const char* GetPlatformToolsetVersion() const;
+ std::string const& GetPlatformToolsetVersionString() const;
+
/** The toolset host architecture name (e.g. x64 for 64-bit host tools). */
const char* GetPlatformToolsetHostArchitecture() const;
+ std::string const& GetPlatformToolsetHostArchitectureString() const;
/** The cuda toolset version. */
const char* GetPlatformToolsetCuda() const;
@@ -79,7 +81,7 @@ public:
}
/** Return true if building for WindowsCE */
- bool TargetsWindowsCE() const { return this->SystemIsWindowsCE; }
+ bool TargetsWindowsCE() const override { return this->SystemIsWindowsCE; }
/** Return true if building for WindowsPhone */
bool TargetsWindowsPhone() const { return this->SystemIsWindowsPhone; }
@@ -87,21 +89,30 @@ public:
/** Return true if building for WindowsStore */
bool TargetsWindowsStore() const { return this->SystemIsWindowsStore; }
- virtual const char* GetCMakeCFGIntDir() const { return "$(Configuration)"; }
+ const char* GetCMakeCFGIntDir() const override { 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;
+ std::string GenerateRuleFile(std::string const& output) const override;
void PathTooLong(cmGeneratorTarget* target, cmSourceFile const* sf,
std::string const& sfRel);
- virtual const char* GetToolsVersion() { return "4.0"; }
+ std::string Encoding() override;
+ const char* GetToolsVersion() const;
+
+ virtual bool IsDefaultToolset(const std::string& version) const;
+ virtual std::string GetAuxiliaryToolset() const;
- bool FindMakeProgram(cmMakefile* mf) CM_OVERRIDE;
+ bool FindMakeProgram(cmMakefile* mf) override;
+
+ bool IsIPOSupported() const override { return true; }
static std::string GetInstalledNsightTegraVersion();
+ /** Return the first two components of CMAKE_SYSTEM_VERSION. */
+ std::string GetApplicationTypeRevision() const;
+
cmIDEFlagTable const* GetClFlagTable() const;
cmIDEFlagTable const* GetCSharpFlagTable() const;
cmIDEFlagTable const* GetRcFlagTable() const;
@@ -113,7 +124,10 @@ public:
cmIDEFlagTable const* GetNasmFlagTable() const;
protected:
- virtual void Generate();
+ cmGlobalVisualStudio10Generator(cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName);
+
+ void Generate() override;
virtual bool InitializeSystem(cmMakefile* mf);
virtual bool InitializeWindows(cmMakefile* mf);
virtual bool InitializeWindowsCE(cmMakefile* mf);
@@ -127,33 +141,40 @@ protected:
virtual bool SelectWindowsPhoneToolset(std::string& toolset) const;
virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
- virtual const char* GetIDEVersion() { return "10.0"; }
-
std::string const& GetMSBuildCommand();
+ cmIDEFlagTable const* LoadFlagTable(std::string const& optionsName,
+ std::string const& toolsetName,
+ std::string const& defaultName,
+ std::string const& table) const;
+
std::string GeneratorToolset;
+ std::string GeneratorToolsetVersion;
std::string GeneratorToolsetHostArchitecture;
std::string GeneratorToolsetCuda;
std::string DefaultPlatformToolset;
+ std::string DefaultPlatformToolsetHostArchitecture;
std::string WindowsTargetPlatformVersion;
std::string SystemName;
std::string SystemVersion;
std::string NsightTegraVersion;
- cmIDEFlagTable const* DefaultClFlagTable;
- cmIDEFlagTable const* DefaultCSharpFlagTable;
- cmIDEFlagTable const* DefaultLibFlagTable;
- cmIDEFlagTable const* DefaultLinkFlagTable;
- cmIDEFlagTable const* DefaultCudaFlagTable;
- cmIDEFlagTable const* DefaultCudaHostFlagTable;
- cmIDEFlagTable const* DefaultMasmFlagTable;
- cmIDEFlagTable const* DefaultNasmFlagTable;
- cmIDEFlagTable const* DefaultRcFlagTable;
+ std::string DefaultCLFlagTableName;
+ std::string DefaultCSharpFlagTableName;
+ std::string DefaultLibFlagTableName;
+ std::string DefaultLinkFlagTableName;
+ std::string DefaultCudaFlagTableName;
+ std::string DefaultCudaHostFlagTableName;
+ std::string DefaultMasmFlagTableName;
+ std::string DefaultNasmFlagTableName;
+ std::string DefaultRCFlagTableName;
bool SystemIsWindowsCE;
bool SystemIsWindowsPhone;
bool SystemIsWindowsStore;
private:
class Factory;
+ friend class Factory;
+
struct LongestSourcePath
{
LongestSourcePath()
@@ -173,8 +194,8 @@ private:
bool MSBuildCommandInitialized;
cmVisualStudio10ToolsetOptions ToolsetOptions;
virtual std::string FindMSBuildCommand();
- virtual std::string FindDevEnvCommand();
- virtual std::string GetVSMakeProgram() { return this->GetMSBuildCommand(); }
+ std::string FindDevEnvCommand() override;
+ std::string GetVSMakeProgram() override { return this->GetMSBuildCommand(); }
bool PlatformToolsetNeedsDebugEnum;
@@ -186,6 +207,6 @@ private:
bool CudaEnabled;
// We do not use the reload macros for VS >= 10.
- virtual std::string GetUserMacrosDirectory() { return ""; }
+ std::string GetUserMacrosDirectory() override { return ""; }
};
#endif
diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx
index d37d4b095..4b74ef1b2 100644
--- a/Source/cmGlobalVisualStudio11Generator.cxx
+++ b/Source/cmGlobalVisualStudio11Generator.cxx
@@ -6,12 +6,6 @@
#include "cmDocumentationEntry.h"
#include "cmLocalVisualStudio10Generator.h"
#include "cmMakefile.h"
-#include "cmVS11CLFlagTable.h"
-#include "cmVS11CSharpFlagTable.h"
-#include "cmVS11LibFlagTable.h"
-#include "cmVS11LinkFlagTable.h"
-#include "cmVS11MASMFlagTable.h"
-#include "cmVS11RCFlagTable.h"
static const char vs11generatorName[] = "Visual Studio 11 2012";
@@ -35,7 +29,7 @@ class cmGlobalVisualStudio11Generator::Factory
{
public:
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE
+ cmake* cm) const override
{
std::string genName;
const char* p = cmVS11GenName(name, genName);
@@ -68,29 +62,55 @@ public:
return ret;
}
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
+ void GetDocumentation(cmDocumentationEntry& entry) const override
{
entry.Name = std::string(vs11generatorName) + " [arch]";
entry.Brief = "Generates Visual Studio 2012 project files. "
"Optional [arch] can be \"Win64\" or \"ARM\".";
}
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
+ std::vector<std::string> GetGeneratorNames() const override
{
+ std::vector<std::string> names;
names.push_back(vs11generatorName);
+ return names;
+ }
+
+ std::vector<std::string> GetGeneratorNamesWithPlatform() const override
+ {
+ std::vector<std::string> names;
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);
+ for (std::string const& i : installedSDKs) {
+ names.push_back(std::string(vs11generatorName) + " " + i);
+ }
+
+ return names;
+ }
+
+ bool SupportsToolset() const override { return true; }
+ bool SupportsPlatform() const override { return true; }
+
+ std::vector<std::string> GetKnownPlatforms() const override
+ {
+ std::vector<std::string> platforms;
+ platforms.emplace_back("x64");
+ platforms.emplace_back("Win32");
+ platforms.emplace_back("ARM");
+
+ std::set<std::string> installedSDKs =
+ cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
+ for (std::string const& i : installedSDKs) {
+ platforms.emplace_back(i);
}
+
+ return platforms;
}
- bool SupportsToolset() const CM_OVERRIDE { return true; }
- bool SupportsPlatform() const CM_OVERRIDE { return true; }
+ std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
@@ -99,8 +119,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()
}
cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
- cmake* cm, const std::string& name, const std::string& platformName)
- : cmGlobalVisualStudio10Generator(cm, name, platformName)
+ cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName)
+ : cmGlobalVisualStudio10Generator(cm, name, platformInGeneratorName)
{
std::string vc11Express;
this->ExpressEdition = cmSystemTools::ReadRegistryValue(
@@ -108,12 +129,12 @@ cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator(
"ProductDir",
vc11Express, cmSystemTools::KeyWOW64_32);
this->DefaultPlatformToolset = "v110";
- this->DefaultClFlagTable = cmVS11CLFlagTable;
- this->DefaultCSharpFlagTable = cmVS11CSharpFlagTable;
- this->DefaultLibFlagTable = cmVS11LibFlagTable;
- this->DefaultLinkFlagTable = cmVS11LinkFlagTable;
- this->DefaultMasmFlagTable = cmVS11MASMFlagTable;
- this->DefaultRcFlagTable = cmVS11RCFlagTable;
+ this->DefaultCLFlagTableName = "v11";
+ this->DefaultCSharpFlagTableName = "v11";
+ this->DefaultLibFlagTableName = "v11";
+ this->DefaultLinkFlagTableName = "v11";
+ this->DefaultMasmFlagTableName = "v11";
+ this->DefaultRCFlagTableName = "v11";
this->Version = VS11;
}
@@ -139,7 +160,7 @@ bool cmGlobalVisualStudio11Generator::InitializeWindowsPhone(cmMakefile* mf)
<< "Desktop SDK as well as the Windows Phone '" << this->SystemVersion
<< "' SDK. Please make sure that you have both installed";
}
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
return true;
@@ -157,7 +178,7 @@ bool cmGlobalVisualStudio11Generator::InitializeWindowsStore(cmMakefile* mf)
<< "Desktop SDK as well as the Windows Store '" << this->SystemVersion
<< "' SDK. Please make sure that you have both installed";
}
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
return true;
@@ -195,17 +216,7 @@ bool cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset(
toolset);
}
-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";
- }
-}
-
-bool cmGlobalVisualStudio11Generator::UseFolderProperty()
+bool cmGlobalVisualStudio11Generator::UseFolderProperty() const
{
// Intentionally skip up to the top-level class implementation.
// Folders are not supported by the Express editions in VS10 and earlier,
@@ -224,33 +235,27 @@ cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs()
cmSystemTools::KeyWOW64_32);
std::set<std::string> ret;
- for (std::vector<std::string>::const_iterator i = subkeys.begin();
- i != subkeys.end(); ++i) {
+ for (std::string const& i : subkeys) {
std::string key = sdksKey;
key += '\\';
- key += *i;
+ key += i;
key += ';';
std::string path;
- if (cmSystemTools::ReadRegistryValue(key.c_str(), path,
+ if (cmSystemTools::ReadRegistryValue(key, path,
cmSystemTools::KeyWOW64_32) &&
!path.empty()) {
- ret.insert(*i);
+ ret.insert(i);
}
}
return ret;
}
-bool cmGlobalVisualStudio11Generator::NeedsDeploy(
- cmStateEnums::TargetType type) const
+bool cmGlobalVisualStudio11Generator::TargetSystemSupportsDeployment() const
{
- if ((type == cmStateEnums::EXECUTABLE ||
- type == cmStateEnums::SHARED_LIBRARY) &&
- (this->SystemIsWindowsPhone || this->SystemIsWindowsStore)) {
- return true;
- }
- return cmGlobalVisualStudio10Generator::NeedsDeploy(type);
+ return this->SystemIsWindowsPhone || this->SystemIsWindowsStore ||
+ cmGlobalVisualStudio10Generator::TargetSystemSupportsDeployment();
}
bool cmGlobalVisualStudio11Generator::IsWindowsDesktopToolsetInstalled() const
diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h
index b4b327d8a..f8cce1898 100644
--- a/Source/cmGlobalVisualStudio11Generator.h
+++ b/Source/cmGlobalVisualStudio11Generator.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalVisualStudio11Generator_h
#define cmGlobalVisualStudio11Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <set>
@@ -20,19 +20,18 @@ class cmake;
class cmGlobalVisualStudio11Generator : public cmGlobalVisualStudio10Generator
{
public:
- cmGlobalVisualStudio11Generator(cmake* cm, 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);
+ bool MatchesGeneratorName(const std::string& name) const override;
protected:
- virtual bool InitializeWindowsPhone(cmMakefile* mf);
- virtual bool InitializeWindowsStore(cmMakefile* mf);
- virtual bool SelectWindowsPhoneToolset(std::string& toolset) const;
- virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
+ cmGlobalVisualStudio11Generator(cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName);
+
+ bool InitializeWindowsPhone(cmMakefile* mf) override;
+ bool InitializeWindowsStore(cmMakefile* mf) override;
+ bool SelectWindowsPhoneToolset(std::string& toolset) const override;
+ bool SelectWindowsStoreToolset(std::string& toolset) const override;
// Used to verify that the Desktop toolset for the current generator is
// installed on the machine.
@@ -43,12 +42,11 @@ protected:
bool IsWindowsPhoneToolsetInstalled() const;
bool IsWindowsStoreToolsetInstalled() const;
- virtual const char* GetIDEVersion() { return "11.0"; }
- bool UseFolderProperty();
+ bool UseFolderProperty() const override;
static std::set<std::string> GetInstalledWindowsCESDKs();
- /** Return true if the configuration needs to be deployed */
- virtual bool NeedsDeploy(cmStateEnums::TargetType type) const;
+ /** Return true if target system supports debugging deployment. */
+ bool TargetSystemSupportsDeployment() const override;
private:
class Factory;
diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx
index de62ff0ac..d9702c9ee 100644
--- a/Source/cmGlobalVisualStudio12Generator.cxx
+++ b/Source/cmGlobalVisualStudio12Generator.cxx
@@ -6,12 +6,6 @@
#include "cmDocumentationEntry.h"
#include "cmLocalVisualStudio10Generator.h"
#include "cmMakefile.h"
-#include "cmVS12CLFlagTable.h"
-#include "cmVS12CSharpFlagTable.h"
-#include "cmVS12LibFlagTable.h"
-#include "cmVS12LinkFlagTable.h"
-#include "cmVS12MASMFlagTable.h"
-#include "cmVS12RCFlagTable.h"
static const char vs12generatorName[] = "Visual Studio 12 2013";
@@ -35,7 +29,7 @@ class cmGlobalVisualStudio12Generator::Factory
{
public:
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE
+ cmake* cm) const override
{
std::string genName;
const char* p = cmVS12GenName(name, genName);
@@ -57,22 +51,41 @@ public:
return 0;
}
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
+ void GetDocumentation(cmDocumentationEntry& entry) const override
{
entry.Name = std::string(vs12generatorName) + " [arch]";
entry.Brief = "Generates Visual Studio 2013 project files. "
"Optional [arch] can be \"Win64\" or \"ARM\".";
}
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
+ std::vector<std::string> GetGeneratorNames() const override
{
+ std::vector<std::string> names;
names.push_back(vs12generatorName);
+ return names;
+ }
+
+ std::vector<std::string> GetGeneratorNamesWithPlatform() const override
+ {
+ std::vector<std::string> names;
names.push_back(vs12generatorName + std::string(" ARM"));
names.push_back(vs12generatorName + std::string(" Win64"));
+ return names;
}
- bool SupportsToolset() const CM_OVERRIDE { return true; }
- bool SupportsPlatform() const CM_OVERRIDE { return true; }
+ bool SupportsToolset() const override { return true; }
+ bool SupportsPlatform() const override { return true; }
+
+ std::vector<std::string> GetKnownPlatforms() const override
+ {
+ std::vector<std::string> platforms;
+ platforms.emplace_back("x64");
+ platforms.emplace_back("Win32");
+ platforms.emplace_back("ARM");
+ return platforms;
+ }
+
+ std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory()
@@ -81,8 +94,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory()
}
cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator(
- cmake* cm, const std::string& name, const std::string& platformName)
- : cmGlobalVisualStudio11Generator(cm, name, platformName)
+ cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName)
+ : cmGlobalVisualStudio11Generator(cm, name, platformInGeneratorName)
{
std::string vc12Express;
this->ExpressEdition = cmSystemTools::ReadRegistryValue(
@@ -90,12 +104,12 @@ cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator(
"ProductDir",
vc12Express, cmSystemTools::KeyWOW64_32);
this->DefaultPlatformToolset = "v120";
- this->DefaultClFlagTable = cmVS12CLFlagTable;
- this->DefaultCSharpFlagTable = cmVS12CSharpFlagTable;
- this->DefaultLibFlagTable = cmVS12LibFlagTable;
- this->DefaultLinkFlagTable = cmVS12LinkFlagTable;
- this->DefaultMasmFlagTable = cmVS12MASMFlagTable;
- this->DefaultRcFlagTable = cmVS12RCFlagTable;
+ this->DefaultCLFlagTableName = "v12";
+ this->DefaultCSharpFlagTableName = "v12";
+ this->DefaultLibFlagTableName = "v12";
+ this->DefaultLinkFlagTableName = "v12";
+ this->DefaultMasmFlagTableName = "v12";
+ this->DefaultRCFlagTableName = "v12";
this->Version = VS12;
}
@@ -112,8 +126,8 @@ bool cmGlobalVisualStudio12Generator::MatchesGeneratorName(
bool cmGlobalVisualStudio12Generator::ProcessGeneratorToolsetField(
std::string const& key, std::string const& value)
{
- if (key == "host" && value == "x64") {
- this->GeneratorToolsetHostArchitecture = "x64";
+ if (key == "host" && (value == "x64" || value == "x86")) {
+ this->GeneratorToolsetHostArchitecture = value;
return true;
}
return this->cmGlobalVisualStudio11Generator::ProcessGeneratorToolsetField(
@@ -125,15 +139,16 @@ bool cmGlobalVisualStudio12Generator::InitializeWindowsPhone(cmMakefile* mf)
if (!this->SelectWindowsPhoneToolset(this->DefaultPlatformToolset)) {
std::ostringstream e;
if (this->DefaultPlatformToolset.empty()) {
- e << this->GetName() << " supports Windows Phone '8.0' and '8.1', but "
- "not '"
+ e << this->GetName()
+ << " supports Windows Phone '8.0' and '8.1', but "
+ "not '"
<< this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
} else {
e << "A Windows Phone component with CMake requires both the Windows "
<< "Desktop SDK as well as the Windows Phone '" << this->SystemVersion
<< "' SDK. Please make sure that you have both installed";
}
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
return true;
@@ -144,15 +159,16 @@ bool cmGlobalVisualStudio12Generator::InitializeWindowsStore(cmMakefile* mf)
if (!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset)) {
std::ostringstream e;
if (this->DefaultPlatformToolset.empty()) {
- e << this->GetName() << " supports Windows Store '8.0' and '8.1', but "
- "not '"
+ e << this->GetName()
+ << " supports Windows Store '8.0' and '8.1', but "
+ "not '"
<< this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
} else {
e << "A Windows Store component with CMake requires both the Windows "
<< "Desktop SDK as well as the Windows Store '" << this->SystemVersion
<< "' SDK. Please make sure that you have both installed";
}
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
return true;
@@ -190,16 +206,6 @@ bool cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset(
toolset);
}
-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";
- }
-}
-
bool cmGlobalVisualStudio12Generator::IsWindowsDesktopToolsetInstalled() const
{
const char desktop81Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h
index ebc95bb63..53b709157 100644
--- a/Source/cmGlobalVisualStudio12Generator.h
+++ b/Source/cmGlobalVisualStudio12Generator.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalVisualStudio12Generator_h
#define cmGlobalVisualStudio12Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -18,37 +18,33 @@ class cmake;
class cmGlobalVisualStudio12Generator : public cmGlobalVisualStudio11Generator
{
public:
- cmGlobalVisualStudio12Generator(cmake* cm, 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);
+ bool MatchesGeneratorName(const std::string& name) const override;
- // 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:
+ cmGlobalVisualStudio12Generator(cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName);
+
bool ProcessGeneratorToolsetField(std::string const& key,
- std::string const& value) CM_OVERRIDE;
+ std::string const& value) override;
- virtual bool InitializeWindowsPhone(cmMakefile* mf);
- virtual bool InitializeWindowsStore(cmMakefile* mf);
- virtual bool SelectWindowsPhoneToolset(std::string& toolset) const;
- virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
+ bool InitializeWindowsPhone(cmMakefile* mf) override;
+ bool InitializeWindowsStore(cmMakefile* mf) override;
+ bool SelectWindowsPhoneToolset(std::string& toolset) const override;
+ bool SelectWindowsStoreToolset(std::string& toolset) const override;
// Used to verify that the Desktop toolset for the current generator is
// installed on the machine.
- virtual bool IsWindowsDesktopToolsetInstalled() const;
+ bool IsWindowsDesktopToolsetInstalled() const override;
// These aren't virtual because we need to check if the selected version
// of the toolset is installed
bool IsWindowsPhoneToolsetInstalled() const;
bool IsWindowsStoreToolsetInstalled() const;
- virtual const char* GetIDEVersion() { return "12.0"; }
+
private:
class Factory;
+ friend class Factory;
};
#endif
diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx
index c8cf02cdd..6509b5616 100644
--- a/Source/cmGlobalVisualStudio14Generator.cxx
+++ b/Source/cmGlobalVisualStudio14Generator.cxx
@@ -6,12 +6,6 @@
#include "cmDocumentationEntry.h"
#include "cmLocalVisualStudio10Generator.h"
#include "cmMakefile.h"
-#include "cmVS140CLFlagTable.h"
-#include "cmVS140CSharpFlagTable.h"
-#include "cmVS140LinkFlagTable.h"
-#include "cmVS14LibFlagTable.h"
-#include "cmVS14MASMFlagTable.h"
-#include "cmVS14RCFlagTable.h"
static const char vs14generatorName[] = "Visual Studio 14 2015";
@@ -35,7 +29,7 @@ class cmGlobalVisualStudio14Generator::Factory
{
public:
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE
+ cmake* cm) const override
{
std::string genName;
const char* p = cmVS14GenName(name, genName);
@@ -57,22 +51,41 @@ public:
return 0;
}
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
+ void GetDocumentation(cmDocumentationEntry& entry) const override
{
entry.Name = std::string(vs14generatorName) + " [arch]";
entry.Brief = "Generates Visual Studio 2015 project files. "
"Optional [arch] can be \"Win64\" or \"ARM\".";
}
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
+ std::vector<std::string> GetGeneratorNames() const override
{
+ std::vector<std::string> names;
names.push_back(vs14generatorName);
+ return names;
+ }
+
+ std::vector<std::string> GetGeneratorNamesWithPlatform() const override
+ {
+ std::vector<std::string> names;
names.push_back(vs14generatorName + std::string(" ARM"));
names.push_back(vs14generatorName + std::string(" Win64"));
+ return names;
}
- bool SupportsToolset() const CM_OVERRIDE { return true; }
- bool SupportsPlatform() const CM_OVERRIDE { return true; }
+ bool SupportsToolset() const override { return true; }
+ bool SupportsPlatform() const override { return true; }
+
+ std::vector<std::string> GetKnownPlatforms() const override
+ {
+ std::vector<std::string> platforms;
+ platforms.emplace_back("x64");
+ platforms.emplace_back("Win32");
+ platforms.emplace_back("ARM");
+ return platforms;
+ }
+
+ std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory()
@@ -81,8 +94,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory()
}
cmGlobalVisualStudio14Generator::cmGlobalVisualStudio14Generator(
- cmake* cm, const std::string& name, const std::string& platformName)
- : cmGlobalVisualStudio12Generator(cm, name, platformName)
+ cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName)
+ : cmGlobalVisualStudio12Generator(cm, name, platformInGeneratorName)
{
std::string vc14Express;
this->ExpressEdition = cmSystemTools::ReadRegistryValue(
@@ -90,12 +104,12 @@ cmGlobalVisualStudio14Generator::cmGlobalVisualStudio14Generator(
"ProductDir",
vc14Express, cmSystemTools::KeyWOW64_32);
this->DefaultPlatformToolset = "v140";
- this->DefaultClFlagTable = cmVS140CLFlagTable;
- this->DefaultCSharpFlagTable = cmVS140CSharpFlagTable;
- this->DefaultLibFlagTable = cmVS14LibFlagTable;
- this->DefaultLinkFlagTable = cmVS140LinkFlagTable;
- this->DefaultMasmFlagTable = cmVS14MASMFlagTable;
- this->DefaultRcFlagTable = cmVS14RCFlagTable;
+ this->DefaultCLFlagTableName = "v140";
+ this->DefaultCSharpFlagTableName = "v140";
+ this->DefaultLibFlagTableName = "v14";
+ this->DefaultLinkFlagTableName = "v140";
+ this->DefaultMasmFlagTableName = "v14";
+ this->DefaultRCFlagTableName = "v14";
this->Version = VS14;
}
@@ -122,15 +136,16 @@ bool cmGlobalVisualStudio14Generator::InitializeWindowsStore(cmMakefile* mf)
std::ostringstream e;
if (!this->SelectWindowsStoreToolset(this->DefaultPlatformToolset)) {
if (this->DefaultPlatformToolset.empty()) {
- e << this->GetName() << " supports Windows Store '8.0', '8.1' and "
- "'10.0', but not '"
+ e << this->GetName()
+ << " supports Windows Store '8.0', '8.1' and "
+ "'10.0', but not '"
<< this->SystemVersion << "'. Check CMAKE_SYSTEM_VERSION.";
} else {
e << "A Windows Store component with CMake requires both the Windows "
<< "Desktop SDK as well as the Windows Store '" << this->SystemVersion
<< "' SDK. Please make sure that you have both installed";
}
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
if (cmHasLiteralPrefix(this->SystemVersion, "10.0")) {
@@ -143,17 +158,31 @@ bool cmGlobalVisualStudio14Generator::SelectWindows10SDK(cmMakefile* mf,
bool required)
{
// Find the default version of the Windows 10 SDK.
- this->WindowsTargetPlatformVersion = this->GetWindows10SDKVersion();
- if (required && this->WindowsTargetPlatformVersion.empty()) {
+ std::string const version = this->GetWindows10SDKVersion();
+ if (required && version.empty()) {
std::ostringstream e;
e << "Could not find an appropriate version of the Windows 10 SDK"
<< " installed on this machine";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
+ this->SetWindowsTargetPlatformVersion(version, mf);
+ return true;
+}
+
+void cmGlobalVisualStudio14Generator::SetWindowsTargetPlatformVersion(
+ std::string const& version, cmMakefile* mf)
+{
+ this->WindowsTargetPlatformVersion = version;
+ if (!cmSystemTools::VersionCompareEqual(this->WindowsTargetPlatformVersion,
+ this->SystemVersion)) {
+ std::ostringstream e;
+ e << "Selecting Windows SDK version " << this->WindowsTargetPlatformVersion
+ << " to target Windows " << this->SystemVersion << ".";
+ mf->DisplayStatus(e.str(), -1);
+ }
mf->AddDefinition("CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION",
this->WindowsTargetPlatformVersion.c_str());
- return true;
}
bool cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset(
@@ -172,17 +201,6 @@ bool cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset(
toolset);
}
-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";
- }
-}
-
bool cmGlobalVisualStudio14Generator::IsWindowsDesktopToolsetInstalled() const
{
const char desktop10Key[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"
@@ -204,6 +222,16 @@ bool cmGlobalVisualStudio14Generator::IsWindowsStoreToolsetInstalled() const
cmSystemTools::KeyWOW64_32);
}
+std::string cmGlobalVisualStudio14Generator::GetWindows10SDKMaxVersion() const
+{
+ // The last Windows 10 SDK version that VS 2015 can target is 10.0.14393.0.
+ //
+ // "VS 2015 Users: The Windows 10 SDK (15063, 16299, 17134, 17763) is
+ // officially only supported for VS 2017." From:
+ // https://blogs.msdn.microsoft.com/chuckw/2018/10/02/windows-10-october-2018-update/
+ return "10.0.14393.0";
+}
+
#if defined(_WIN32) && !defined(__CYGWIN__)
struct NoWindowsH
{
@@ -212,6 +240,20 @@ struct NoWindowsH
return !cmSystemTools::FileExists(p + "/um/windows.h", true);
}
};
+class WindowsSDKTooRecent
+{
+ std::string const& MaxVersion;
+
+public:
+ WindowsSDKTooRecent(std::string const& maxVersion)
+ : MaxVersion(maxVersion)
+ {
+ }
+ bool operator()(std::string const& v)
+ {
+ return cmSystemTools::VersionCompareGreater(v, MaxVersion);
+ }
+};
#endif
std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion()
@@ -250,9 +292,8 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion()
std::vector<std::string> sdks;
// Grab the paths of the different SDKs that are installed
- for (std::vector<std::string>::iterator i = win10Roots.begin();
- i != win10Roots.end(); ++i) {
- std::string path = *i + "/Include/*";
+ for (std::string const& i : win10Roots) {
+ std::string path = i + "/Include/*";
cmSystemTools::GlobDirs(path, sdks);
}
@@ -260,24 +301,28 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion()
// only the UCRT MSIs were installed for them.
cmEraseIf(sdks, NoWindowsH());
- if (!sdks.empty()) {
- // Only use the filename, which will be the SDK version.
- for (std::vector<std::string>::iterator i = sdks.begin(); i != sdks.end();
- ++i) {
- *i = cmSystemTools::GetFilenameName(*i);
- }
+ // Only use the filename, which will be the SDK version.
+ for (std::string& i : sdks) {
+ i = cmSystemTools::GetFilenameName(i);
+ }
- // Sort the results to make sure we select the most recent one.
- std::sort(sdks.begin(), sdks.end(), cmSystemTools::VersionCompareGreater);
+ // Skip SDKs that cannot be used with our toolset.
+ std::string maxVersion = this->GetWindows10SDKMaxVersion();
+ if (!maxVersion.empty()) {
+ cmEraseIf(sdks, WindowsSDKTooRecent(maxVersion));
+ }
+
+ // Sort the results to make sure we select the most recent one.
+ std::sort(sdks.begin(), sdks.end(), cmSystemTools::VersionCompareGreater);
- // Look for a SDK exactly matching the requested target version.
- for (std::vector<std::string>::iterator i = sdks.begin(); i != sdks.end();
- ++i) {
- if (cmSystemTools::VersionCompareEqual(*i, this->SystemVersion)) {
- return *i;
- }
+ // Look for a SDK exactly matching the requested target version.
+ for (std::string const& i : sdks) {
+ if (cmSystemTools::VersionCompareEqual(i, this->SystemVersion)) {
+ return i;
}
+ }
+ if (!sdks.empty()) {
// Use the latest Windows 10 SDK since the exact version is not available.
return sdks.at(0);
}
diff --git a/Source/cmGlobalVisualStudio14Generator.h b/Source/cmGlobalVisualStudio14Generator.h
index 0ce9a5641..6e12d3e2c 100644
--- a/Source/cmGlobalVisualStudio14Generator.h
+++ b/Source/cmGlobalVisualStudio14Generator.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalVisualStudio14Generator_h
#define cmGlobalVisualStudio14Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -18,34 +18,39 @@ class cmake;
class cmGlobalVisualStudio14Generator : public cmGlobalVisualStudio12Generator
{
public:
- cmGlobalVisualStudio14Generator(cmake* cm, 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);
+ bool MatchesGeneratorName(const std::string& name) const override;
- virtual const char* GetToolsVersion() { return "14.0"; }
protected:
- virtual bool InitializeWindows(cmMakefile* mf);
- virtual bool InitializeWindowsStore(cmMakefile* mf);
- virtual bool SelectWindowsStoreToolset(std::string& toolset) const;
+ cmGlobalVisualStudio14Generator(cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName);
+
+ bool InitializeWindows(cmMakefile* mf) override;
+ bool InitializeWindowsStore(cmMakefile* mf) override;
+ bool SelectWindowsStoreToolset(std::string& toolset) const override;
// These aren't virtual because we need to check if the selected version
// of the toolset is installed
bool IsWindowsStoreToolsetInstalled() const;
- virtual const char* GetIDEVersion() { return "14.0"; }
+ // Used to make sure that the Windows 10 SDK selected can work with the
+ // version of the toolset.
+ virtual std::string GetWindows10SDKMaxVersion() const;
+
virtual bool SelectWindows10SDK(cmMakefile* mf, bool required);
+ void SetWindowsTargetPlatformVersion(std::string const& version,
+ cmMakefile* mf);
+
// Used to verify that the Desktop toolset for the current generator is
// installed on the machine.
- virtual bool IsWindowsDesktopToolsetInstalled() const;
+ bool IsWindowsDesktopToolsetInstalled() const override;
std::string GetWindows10SDKVersion();
private:
class Factory;
+ friend class Factory;
};
#endif
diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx
index 3b45c902c..8e67fad89 100644
--- a/Source/cmGlobalVisualStudio71Generator.cxx
+++ b/Source/cmGlobalVisualStudio71Generator.cxx
@@ -6,7 +6,7 @@
#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudio7Generator.h"
#include "cmMakefile.h"
-#include "cmake.h"
+#include "cmMessageType.h"
cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator(
cmake* cm, const std::string& platformName)
@@ -76,9 +76,8 @@ void cmGlobalVisualStudio71Generator::WriteSolutionConfigurations(
std::ostream& fout, std::vector<std::string> const& configs)
{
fout << "\tGlobalSection(SolutionConfiguration) = preSolution\n";
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
- fout << "\t\t" << *i << " = " << *i << "\n";
+ for (std::string const& i : configs) {
+ fout << "\t\t" << i << " = " << i << "\n";
}
fout << "\tEndGlobalSection\n";
}
@@ -99,7 +98,7 @@ void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout,
ext = ".vfproj";
project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \"";
}
- if (this->TargetIsCSharpOnly(t)) {
+ if (t->IsCSharpOnly()) {
ext = ".csproj";
project = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"";
}
@@ -143,16 +142,14 @@ void cmGlobalVisualStudio71Generator::WriteProjectDepends(
cmGeneratorTarget 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();
+ for (std::string const& name : depends) {
std::string guid = this->GetGUID(name);
if (guid.empty()) {
std::string m = "Target: ";
m += target->GetName();
m += " depends on unknown target: ";
m += name;
- cmSystemTools::Error(m.c_str());
+ cmSystemTools::Error(m);
}
fout << "\t\t{" << guid << "} = {" << guid << "}\n";
}
@@ -162,7 +159,7 @@ void cmGlobalVisualStudio71Generator::WriteProjectDepends(
// 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)
+ const char* typeGuid, const std::set<BT<std::string>>& depends)
{
fout << "Project(\"{"
<< (typeGuid ? typeGuid : this->ExternalProjectType(location))
@@ -174,11 +171,11 @@ void cmGlobalVisualStudio71Generator::WriteExternalProject(
// 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->empty()) {
- fout << "\t\t{" << this->GetGUID(it->c_str()) << "} = {"
- << this->GetGUID(it->c_str()) << "}\n";
+ for (BT<std::string> const& it : depends) {
+ std::string const& dep = it.Value;
+ if (!dep.empty()) {
+ fout << "\t\t{" << this->GetGUID(dep) << "} = {" << this->GetGUID(dep)
+ << "}\n";
}
}
fout << "\tEndProjectSection\n";
@@ -198,32 +195,25 @@ void cmGlobalVisualStudio71Generator::WriteProjectConfigurations(
const std::string& platformName =
!platformMapping.empty() ? platformMapping : this->GetPlatformName();
std::string guid = this->GetGUID(name);
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
+ for (std::string const& i : configs) {
std::vector<std::string> mapConfig;
- const char* dstConfig = i->c_str();
+ const char* dstConfig = i.c_str();
if (target.GetProperty("EXTERNAL_MSPROJECT")) {
if (const char* m = target.GetProperty("MAP_IMPORTED_CONFIG_" +
- cmSystemTools::UpperCase(*i))) {
+ cmSystemTools::UpperCase(i))) {
cmSystemTools::ExpandListArgument(m, mapConfig);
if (!mapConfig.empty()) {
dstConfig = mapConfig[0].c_str();
}
}
}
- fout << "\t\t{" << guid << "}." << *i << ".ActiveCfg = " << dstConfig
- << "|" << platformName << std::endl;
+ fout << "\t\t{" << guid << "}." << i << ".ActiveCfg = " << dstConfig << "|"
+ << platformName << std::endl;
std::set<std::string>::const_iterator ci =
- configsPartOfDefaultBuild.find(*i);
+ configsPartOfDefaultBuild.find(i);
if (!(ci == configsPartOfDefaultBuild.end())) {
- fout << "\t\t{" << guid << "}." << *i << ".Build.0 = " << dstConfig
- << "|" << platformName << std::endl;
+ fout << "\t\t{" << guid << "}." << i << ".Build.0 = " << dstConfig << "|"
+ << 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";
-}
diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h
index 0ce02aa46..85755af60 100644
--- a/Source/cmGlobalVisualStudio71Generator.h
+++ b/Source/cmGlobalVisualStudio71Generator.h
@@ -17,28 +17,26 @@ public:
const std::string& platformName = "");
protected:
- virtual void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root,
- std::vector<cmLocalGenerator*>& generators);
+ void WriteSLNFile(std::ostream& fout, cmLocalGenerator* root,
+ std::vector<cmLocalGenerator*>& generators) override;
virtual void WriteSolutionConfigurations(
std::ostream& fout, std::vector<std::string> const& configs);
- virtual void WriteProject(std::ostream& fout, const std::string& name,
- const char* path, const cmGeneratorTarget* t);
- virtual void WriteProjectDepends(std::ostream& fout, const std::string& name,
- const char* path,
- cmGeneratorTarget const* t);
- virtual void WriteProjectConfigurations(
+ void WriteProject(std::ostream& fout, const std::string& name,
+ const char* path, const cmGeneratorTarget* t) override;
+ void WriteProjectDepends(std::ostream& fout, const std::string& name,
+ const char* path,
+ cmGeneratorTarget const* t) override;
+ void WriteProjectConfigurations(
std::ostream& fout, const std::string& name,
cmGeneratorTarget const& target, std::vector<std::string> const& configs,
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);
+ const std::string& platformMapping = "") override;
+ void WriteExternalProject(std::ostream& fout, const std::string& name,
+ const char* path, const char* typeGuid,
+ const std::set<BT<std::string>>& depends) override;
// Folders are not supported by VS 7.1.
- virtual bool UseFolderProperty() { return false; }
+ bool UseFolderProperty() const override { return false; }
std::string ProjectConfigurationSectionName;
};
diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx
index b155f5b55..8764ee439 100644
--- a/Source/cmGlobalVisualStudio7Generator.cxx
+++ b/Source/cmGlobalVisualStudio7Generator.cxx
@@ -6,6 +6,7 @@
#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudio7Generator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmState.h"
#include "cmUuid.h"
#include "cmake.h"
@@ -37,43 +38,35 @@ static cmVS7FlagTable cmVS7ExtraFlagTable[] = {
// and have EHa passed on the command line by leaving out the table
// entry.
- { 0, 0, 0, 0, 0 }
+ { "", "", "", "", 0 }
};
cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator(
- cmake* cm, const std::string& platformName)
- : cmGlobalVisualStudioGenerator(cm)
+ cmake* cm, std::string const& platformInGeneratorName)
+ : cmGlobalVisualStudioGenerator(cm, platformInGeneratorName)
{
- this->IntelProjectVersion = 0;
this->DevEnvCommandInitialized = false;
this->MasmEnabled = false;
this->NasmEnabled = false;
-
- if (platformName.empty()) {
- this->DefaultPlatformName = "Win32";
- } else {
- this->DefaultPlatformName = platformName;
- }
this->ExtraFlagTable = cmVS7ExtraFlagTable;
}
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()
+const std::string& cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
{
- if (!this->IntelProjectVersion) {
+ if (this->IntelProjectVersion.empty()) {
// 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::ReadRegistryValue(vskey, intelVersion,
cmSystemTools::KeyWOW64_32);
unsigned int intelVersionNumber = ~0u;
sscanf(intelVersion.c_str(), "%u", &intelVersionNumber);
@@ -86,7 +79,7 @@ const char* cmGlobalVisualStudio7Generator::GetIntelProjectVersion()
} else {
// Version <= 9: use ProductVersion from registry.
}
- this->IntelProjectVersion = strdup(intelVersion.c_str());
+ this->IntelProjectVersion = intelVersion;
}
return this->IntelProjectVersion;
}
@@ -106,7 +99,7 @@ void cmGlobalVisualStudio7Generator::EnableLanguage(
}
// Create list of configurations requested by user's cache, if any.
- this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
+ this->cmGlobalVisualStudioGenerator::EnableLanguage(lang, mf, optional);
// if this environment variable is set, then copy it to
// a static cache entry. It will be used by
@@ -195,11 +188,14 @@ const char* cmGlobalVisualStudio7Generator::ExternalProjectType(
}
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*/,
- bool /*verbose*/, std::vector<std::string> const& makeOptions)
+
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalVisualStudio7Generator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& /*projectDir*/,
+ std::vector<std::string> const& targetNames, const std::string& config,
+ bool /*fast*/, int /*jobs*/, bool /*verbose*/,
+ std::vector<std::string> const& makeOptions)
{
// Select the caller- or user-preferred make program, else devenv.
std::string makeProgramSelected =
@@ -214,38 +210,43 @@ void cmGlobalVisualStudio7Generator::GenerateBuildCommand(
makeProgramSelected = this->GetDevEnvCommand();
}
- makeCommand.push_back(makeProgramSelected);
+ // Workaround to convince VCExpress.exe to produce output.
+ const bool requiresOutputForward =
+ (makeProgramLower.find("vcexpress") != std::string::npos);
+ std::vector<GeneratedMakeCommand> makeCommands;
- makeCommand.push_back(std::string(projectName) + ".sln");
- std::string realTarget = targetName;
- bool clean = false;
- if (realTarget == "clean") {
- clean = true;
- realTarget = "ALL_BUILD";
+ std::vector<std::string> realTargetNames = targetNames;
+ if (targetNames.empty() ||
+ ((targetNames.size() == 1) && targetNames.front().empty())) {
+ realTargetNames = { "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());
+ for (const auto& tname : realTargetNames) {
+ std::string realTarget;
+ if (!tname.empty()) {
+ realTarget = tname;
+ } else {
+ continue;
+ }
+ bool clean = false;
+ if (realTarget == "clean") {
+ clean = true;
+ realTarget = "ALL_BUILD";
+ }
+ GeneratedMakeCommand makeCommand;
+ makeCommand.RequiresOutputForward = requiresOutputForward;
+ makeCommand.Add(makeProgramSelected);
+ makeCommand.Add(projectName + ".sln");
+ makeCommand.Add((clean ? "/clean" : "/build"));
+ makeCommand.Add((config.empty() ? "Debug" : config));
+ makeCommand.Add("/project");
+ makeCommand.Add(realTarget);
+ makeCommand.Add(makeOptions.begin(), makeOptions.end());
+ makeCommands.emplace_back(std::move(makeCommand));
+ }
+ return makeCommands;
}
-///! Create a local generator appropriate to this Global Generator
+//! Create a local generator appropriate to this Global Generator
cmLocalGenerator* cmGlobalVisualStudio7Generator::CreateLocalGenerator(
cmMakefile* mf)
{
@@ -254,34 +255,23 @@ cmLocalGenerator* cmGlobalVisualStudio7Generator::CreateLocalGenerator(
return lg;
}
-std::string const& cmGlobalVisualStudio7Generator::GetPlatformName() const
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+Json::Value cmGlobalVisualStudio7Generator::GetJson() const
{
- if (!this->GeneratorPlatform.empty()) {
- return this->GeneratorPlatform;
- }
- return this->DefaultPlatformName;
+ Json::Value generator = this->cmGlobalVisualStudioGenerator::GetJson();
+ generator["platform"] = this->GetPlatformName();
+ return generator;
}
+#endif
bool cmGlobalVisualStudio7Generator::SetSystemName(std::string const& s,
cmMakefile* mf)
{
mf->AddDefinition("CMAKE_VS_INTEL_Fortran_PROJECT_VERSION",
- this->GetIntelProjectVersion());
+ this->GetIntelProjectVersion().c_str());
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::Generate()
{
// first do the superclass method
@@ -294,19 +284,6 @@ void cmGlobalVisualStudio7Generator::Generate()
if (!cmSystemTools::GetErrorOccuredFlag()) {
this->CallVisualStudioMacro(MacroReload);
}
-
- if (this->Version == VS8 && !this->CMakeInstance->GetIsInTryCompile()) {
- const char* cmakeWarnVS8 =
- this->CMakeInstance->GetState()->GetCacheEntryValue("CMAKE_WARN_VS8");
- if (!cmakeWarnVS8 || !cmSystemTools::IsOff(cmakeWarnVS8)) {
- this->CMakeInstance->IssueMessage(
- cmake::WARNING,
- "The \"Visual Studio 8 2005\" generator is deprecated "
- "and will be removed in a future version of CMake."
- "\n"
- "Add CMAKE_WARN_VS8=OFF to the cache to disable this warning.");
- }
- }
}
void cmGlobalVisualStudio7Generator::OutputSLNFile(
@@ -334,9 +311,8 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile(
// 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);
+ for (auto& it : this->ProjectMap) {
+ this->OutputSLNFile(it.second[0], it.second);
}
}
@@ -346,9 +322,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
{
// loop over again and write out configurations for each target
// in the solution
- for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
- tt != projectTargets.end(); ++tt) {
- cmGeneratorTarget const* target = *tt;
+ for (cmGeneratorTarget const* target : projectTargets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
@@ -378,9 +352,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
VisualStudioFolders.clear();
std::string rootBinaryDir = root->GetCurrentBinaryDirectory();
- for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
- tt != projectTargets.end(); ++tt) {
- cmGeneratorTarget const* target = *tt;
+ for (cmGeneratorTarget const* target : projectTargets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
@@ -401,9 +373,9 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
if (vcprojName) {
cmLocalGenerator* lg = target->GetLocalGenerator();
std::string dir = lg->GetCurrentBinaryDirectory();
- dir = root->ConvertToRelativePath(rootBinaryDir, dir.c_str());
+ dir = root->MaybeConvertToRelativePath(rootBinaryDir, dir.c_str());
if (dir == ".") {
- dir = ""; // msbuild cannot handle ".\" prefix
+ dir.clear(); // msbuild cannot handle ".\" prefix
}
this->WriteProject(fout, vcprojName, dir.c_str(), target);
written = true;
@@ -415,24 +387,23 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
if (written && this->UseFolderProperty()) {
const std::string targetFolder = target->GetEffectiveFolderName();
if (!targetFolder.empty()) {
- std::vector<cmsys::String> tokens =
+ std::vector<std::string> tokens =
cmSystemTools::SplitString(targetFolder, '/', false);
- std::string cumulativePath = "";
+ std::string cumulativePath;
- for (std::vector<cmsys::String>::iterator iter = tokens.begin();
- iter != tokens.end(); ++iter) {
- if (!iter->size()) {
+ for (std::string const& iter : tokens) {
+ if (!iter.size()) {
continue;
}
if (cumulativePath.empty()) {
- cumulativePath = "CMAKE_FOLDER_GUID_" + *iter;
+ cumulativePath = "CMAKE_FOLDER_GUID_" + iter;
} else {
VisualStudioFolders[cumulativePath].insert(cumulativePath + "/" +
- *iter);
+ iter);
- cumulativePath = cumulativePath + "/" + *iter;
+ cumulativePath = cumulativePath + "/" + iter;
}
}
@@ -447,9 +418,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
void cmGlobalVisualStudio7Generator::WriteTargetDepends(
std::ostream& fout, OrderedTargetDependSet const& projectTargets)
{
- for (OrderedTargetDependSet::const_iterator tt = projectTargets.begin();
- tt != projectTargets.end(); ++tt) {
- cmGeneratorTarget const* target = *tt;
+ for (cmGeneratorTarget const* target : projectTargets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
@@ -467,11 +436,9 @@ 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());
+ for (auto const& iter : VisualStudioFolders) {
+ std::string fullName = iter.first;
+ std::string guid = this->GetGUID(fullName);
std::replace(fullName.begin(), fullName.end(), '/', '\\');
if (cmSystemTools::StringStartsWith(fullName.c_str(), prefix)) {
@@ -487,16 +454,13 @@ void cmGlobalVisualStudio7Generator::WriteFolders(std::ostream& fout)
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 (auto const& iter : VisualStudioFolders) {
+ std::string key(iter.first);
+ std::string guidParent(this->GetGUID(key));
- 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()));
+ for (std::string const& it : iter.second) {
+ std::string value(it);
+ std::string guid(this->GetGUID(value));
fout << "\t\t{" << guid << "} = {" << guidParent << "}\n";
}
@@ -525,11 +489,10 @@ void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections(
bool extensibilityAddInsOverridden = false;
const std::vector<std::string> propKeys =
root->GetMakefile()->GetPropertyKeys();
- for (std::vector<std::string>::const_iterator it = propKeys.begin();
- it != propKeys.end(); ++it) {
- if (it->find("VS_GLOBAL_SECTION_") == 0) {
+ for (std::string const& it : propKeys) {
+ if (it.find("VS_GLOBAL_SECTION_") == 0) {
std::string sectionType;
- std::string name = it->substr(18);
+ std::string name = it.substr(18);
if (name.find("PRE_") == 0) {
name = name.substr(4);
sectionType = "preSolution";
@@ -549,17 +512,15 @@ void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections(
}
fout << "\tGlobalSection(" << name << ") = " << sectionType << "\n";
std::vector<std::string> keyValuePairs;
- cmSystemTools::ExpandListArgument(
- root->GetMakefile()->GetProperty(it->c_str()), keyValuePairs);
- for (std::vector<std::string>::const_iterator itPair =
- keyValuePairs.begin();
- itPair != keyValuePairs.end(); ++itPair) {
- const std::string::size_type posEqual = itPair->find('=');
+ cmSystemTools::ExpandListArgument(root->GetMakefile()->GetProperty(it),
+ keyValuePairs);
+ for (std::string const& itPair : keyValuePairs) {
+ const std::string::size_type posEqual = itPair.find('=');
if (posEqual != std::string::npos) {
const std::string key =
- cmSystemTools::TrimWhitespace(itPair->substr(0, posEqual));
+ cmSystemTools::TrimWhitespace(itPair.substr(0, posEqual));
const std::string value =
- cmSystemTools::TrimWhitespace(itPair->substr(posEqual + 1));
+ cmSystemTools::TrimWhitespace(itPair.substr(posEqual + 1));
fout << "\t\t" << key << " = " << value << "\n";
if (key == "SolutionGuid") {
addGuid = false;
@@ -618,14 +579,13 @@ std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend(
"\t<Configurations>\n"
;
/* clang-format on */
- for (std::vector<std::string>::iterator i = configs.begin();
- i != configs.end(); ++i) {
+ for (std::string const& i : configs) {
/* clang-format off */
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\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"
@@ -653,7 +613,7 @@ std::string cmGlobalVisualStudio7Generator::GetGUID(std::string const& name)
{
std::string const& guidStoreName = name + "_GUID_CMAKE";
if (const char* storedGUID =
- this->CMakeInstance->GetCacheDefinition(guidStoreName.c_str())) {
+ this->CMakeInstance->GetCacheDefinition(guidStoreName)) {
return std::string(storedGUID);
}
// Compute a GUID that is deterministic but unique to the build tree.
@@ -696,23 +656,21 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
std::vector<std::string> targetNames;
targetNames.push_back("INSTALL");
targetNames.push_back("PACKAGE");
- for (std::vector<std::string>::const_iterator t = targetNames.begin();
- t != targetNames.end(); ++t) {
- // check if target <*t> is part of default build
- if (target->GetName() == *t) {
+ for (std::string const& t : targetNames) {
+ // check if target <t> is part of default build
+ if (target->GetName() == t) {
const std::string propertyName =
- "CMAKE_VS_INCLUDE_" + *t + "_TO_DEFAULT_BUILD";
- // inspect CMAKE_VS_INCLUDE_<*t>_TO_DEFAULT_BUILD properties
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
+ "CMAKE_VS_INCLUDE_" + t + "_TO_DEFAULT_BUILD";
+ // inspect CMAKE_VS_INCLUDE_<t>_TO_DEFAULT_BUILD properties
+ for (std::string const& i : configs) {
const char* propertyValue =
target->Target->GetMakefile()->GetDefinition(propertyName);
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(propertyValue);
if (cmSystemTools::IsOn(
- cge->Evaluate(target->GetLocalGenerator(), *i))) {
- activeConfigs.insert(*i);
+ cge->Evaluate(target->GetLocalGenerator(), i))) {
+ activeConfigs.insert(i);
}
}
}
@@ -724,12 +682,11 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
return activeConfigs;
}
// inspect EXCLUDE_FROM_DEFAULT_BUILD[_<CONFIG>] properties
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
+ for (std::string const& i : configs) {
const char* propertyValue =
- target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i->c_str());
+ target->GetFeature("EXCLUDE_FROM_DEFAULT_BUILD", i);
if (cmSystemTools::IsOff(propertyValue)) {
- activeConfigs.insert(*i);
+ activeConfigs.insert(i);
}
}
return activeConfigs;
@@ -738,9 +695,8 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(
bool cmGlobalVisualStudio7Generator::IsDependedOn(
OrderedTargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn)
{
- for (OrderedTargetDependSet::const_iterator l = projectTargets.begin();
- l != projectTargets.end(); ++l) {
- TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(*l);
+ for (cmTargetDepend const& l : projectTargets) {
+ TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(l);
if (tgtdeps.count(gtIn)) {
return true;
}
diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h
index 32a8d6056..f004afb9c 100644
--- a/Source/cmGlobalVisualStudio7Generator.h
+++ b/Source/cmGlobalVisualStudio7Generator.h
@@ -18,19 +18,16 @@ struct cmIDEFlagTable;
class cmGlobalVisualStudio7Generator : public cmGlobalVisualStudioGenerator
{
public:
- cmGlobalVisualStudio7Generator(cmake* cm,
- const std::string& platformName = "");
~cmGlobalVisualStudio7Generator();
- ///! Get the name for the platform.
- std::string const& GetPlatformName() const;
-
- ///! Create a local generator appropriate to this Global Generator
- virtual cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf);
+ //! Create a local generator appropriate to this Global Generator
+ cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
- virtual bool SetSystemName(std::string const& s, cmMakefile* mf);
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ Json::Value GetJson() const override;
+#endif
- virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+ bool SetSystemName(std::string const& s, cmMakefile* mf) override;
/**
* Utilized by the generator factory to determine if this generator
@@ -48,36 +45,36 @@ public:
* 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);
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
/**
* 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,
- bool verbose,
- std::vector<std::string> const& makeOptions = std::vector<std::string>());
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
/**
* Generate the DSW workspace file.
*/
virtual void OutputSLNFile();
- ///! Lookup a stored GUID or compute one deterministically.
+ //! Lookup a stored GUID or compute one deterministically.
std::string GetGUID(std::string const& 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);
+ void AppendDirectoryForConfig(const std::string& prefix,
+ const std::string& config,
+ const std::string& suffix,
+ std::string& dir) override;
- ///! What is the configurations directory variable called?
- virtual const char* GetCMakeCFGIntDir() const
+ //! What is the configurations directory variable called?
+ const char* GetCMakeCFGIntDir() const override
{
return "$(ConfigurationName)";
}
@@ -89,9 +86,9 @@ public:
return false;
}
- const char* GetIntelProjectVersion();
+ const std::string& GetIntelProjectVersion();
- bool FindMakeProgram(cmMakefile* mf) CM_OVERRIDE;
+ bool FindMakeProgram(cmMakefile* mf) override;
/** Is the Microsoft Assembler enabled? */
bool IsMasmEnabled() const { return this->MasmEnabled; }
@@ -103,8 +100,10 @@ public:
cmIDEFlagTable const* ExtraFlagTable;
protected:
- virtual void Generate();
- virtual const char* GetIDEVersion() = 0;
+ cmGlobalVisualStudio7Generator(cmake* cm,
+ std::string const& platformInGeneratorName);
+
+ void Generate() override;
std::string const& GetDevEnvCommand();
virtual std::string FindDevEnvCommand();
@@ -128,8 +127,7 @@ protected:
virtual void WriteSLNGlobalSections(std::ostream& fout,
cmLocalGenerator* root);
virtual void WriteSLNFooter(std::ostream& fout);
- virtual void WriteSLNHeader(std::ostream& fout) = 0;
- virtual std::string WriteUtilityDepend(const cmGeneratorTarget* target);
+ std::string WriteUtilityDepend(const cmGeneratorTarget* target) override;
virtual void WriteTargetsToSolution(
std::ostream& fout, cmLocalGenerator* root,
@@ -142,7 +140,7 @@ protected:
virtual void WriteExternalProject(
std::ostream& fout, const std::string& name, const char* path,
- const char* typeGuid, const std::set<std::string>& dependencies) = 0;
+ const char* typeGuid, const std::set<BT<std::string>>& dependencies) = 0;
std::string ConvertToSolutionPath(const char* path);
@@ -156,21 +154,19 @@ protected:
virtual void WriteFolders(std::ostream& fout);
virtual void WriteFoldersContent(std::ostream& fout);
- std::map<std::string, std::set<std::string> > VisualStudioFolders;
+ 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;
bool NasmEnabled;
private:
- char* IntelProjectVersion;
+ std::string IntelProjectVersion;
std::string DevEnvCommand;
bool DevEnvCommandInitialized;
- virtual std::string GetVSMakeProgram() { return this->GetDevEnvCommand(); }
+ std::string GetVSMakeProgram() override { return this->GetDevEnvCommand(); }
};
#define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK"
diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx
index f06a8a1c6..85ddc85b5 100644
--- a/Source/cmGlobalVisualStudio8Generator.cxx
+++ b/Source/cmGlobalVisualStudio8Generator.cxx
@@ -7,94 +7,19 @@
#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudio7Generator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSourceFile.h"
#include "cmVisualStudioWCEPlatformParser.h"
#include "cmake.h"
-static const char vs8generatorName[] = "Visual Studio 8 2005";
-
-class cmGlobalVisualStudio8Generator::Factory : public cmGlobalGeneratorFactory
-{
-public:
- cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE
- {
- 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(cm, name, "");
- }
-
- if (p[0] != ' ') {
- return 0;
- }
-
- ++p;
-
- if (!strcmp(p, "Win64")) {
- return new cmGlobalVisualStudio8Generator(cm, name, "x64");
- }
-
- cmVisualStudioWCEPlatformParser parser(p);
- parser.ParseVersion("8.0");
- if (!parser.Found()) {
- return 0;
- }
-
- cmGlobalVisualStudio8Generator* ret =
- new cmGlobalVisualStudio8Generator(cm, name, p);
- ret->WindowsCEVersion = parser.GetOSVersion();
- return ret;
- }
-
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
- {
- entry.Name = std::string(vs8generatorName) + " [arch]";
- entry.Brief = "Deprecated. Generates Visual Studio 2005 project files. "
- "Optional [arch] can be \"Win64\".";
- }
-
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
- {
- 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);
- }
- }
-
- bool SupportsToolset() const CM_OVERRIDE { return false; }
- bool SupportsPlatform() const CM_OVERRIDE { return true; }
-};
-
-cmGlobalGeneratorFactory* cmGlobalVisualStudio8Generator::NewFactory()
-{
- return new Factory;
-}
-
cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator(
- cmake* cm, const std::string& name, const std::string& platformName)
- : cmGlobalVisualStudio71Generator(cm, platformName)
+ cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName)
+ : cmGlobalVisualStudio71Generator(cm, platformInGeneratorName)
{
this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
this->Name = name;
this->ExtraFlagTable = this->GetExtraFlagTableVS8();
- this->Version = VS8;
- std::string vc8Express;
- this->ExpressEdition = cmSystemTools::ReadRegistryValue(
- "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\8.0\\Setup\\VC;"
- "ProductDir",
- vc8Express, cmSystemTools::KeyWOW64_32);
}
std::string cmGlobalVisualStudio8Generator::FindDevEnvCommand()
@@ -117,9 +42,8 @@ std::string cmGlobalVisualStudio8Generator::FindDevEnvCommand()
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") {
+ for (std::string const& it : lang) {
+ if (it == "ASM_MASM") {
this->MasmEnabled = true;
}
}
@@ -138,7 +62,7 @@ void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf)
bool cmGlobalVisualStudio8Generator::SetGeneratorPlatform(std::string const& p,
cmMakefile* mf)
{
- if (this->DefaultPlatformName == "Win32") {
+ if (!this->PlatformInGeneratorName) {
this->GeneratorPlatform = p;
return this->cmGlobalVisualStudio7Generator::SetGeneratorPlatform("", mf);
} else {
@@ -146,13 +70,6 @@ bool cmGlobalVisualStudio8Generator::SetGeneratorPlatform(std::string const& p,
}
}
-// 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";
-}
-
std::string cmGlobalVisualStudio8Generator::GetGenerateStampList()
{
return "generate.stamp.list";
@@ -163,71 +80,31 @@ void cmGlobalVisualStudio8Generator::Configure()
this->cmGlobalVisualStudio7Generator::Configure();
}
-bool cmGlobalVisualStudio8Generator::UseFolderProperty()
+bool cmGlobalVisualStudio8Generator::UseFolderProperty() const
{
return IsExpressEdition() ? false : cmGlobalGenerator::UseFolderProperty();
}
-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;
+ // Skip the target if no regeneration is to be done.
+ if (this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION")) {
+ return false;
+ }
+
+ const char* no_working_directory = nullptr;
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;
- }
-
cmCustomCommandLines noCommandLines;
- cmTarget* tgt =
- mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
- no_working_directory, no_depends, noCommandLines);
+ cmTarget* tgt = mf->AddUtilityCommand(
+ CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator,
+ false, no_working_directory, no_depends, noCommandLines);
cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg);
lg->AddGeneratorTarget(gt);
@@ -240,7 +117,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
// Create a list of all stamp files for this project.
std::vector<std::string> stamps;
- std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::string stampList = "CMakeFiles/";
stampList += cmGlobalVisualStudio8Generator::GetGenerateStampList();
{
std::string stampListFile =
@@ -249,12 +126,10 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
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()->GetCurrentBinaryDirectory();
+ for (cmLocalGenerator const* gi : generators) {
+ stampFile = gi->GetMakefile()->GetCurrentBinaryDirectory();
stampFile += "/";
- stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
+ stampFile += "CMakeFiles/";
stampFile += "generate.stamp";
fout << stampFile << "\n";
stamps.push_back(stampFile);
@@ -266,11 +141,33 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
// 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());
+ for (cmLocalGenerator* gen : generators) {
+ cmAppend(listFiles, gen->GetMakefile()->GetListFiles());
+ }
+
+ // Add a custom prebuild target to run the VerifyGlobs script.
+ cmake* cm = this->GetCMakeInstance();
+ if (cm->DoWriteGlobVerifyTarget()) {
+ cmCustomCommandLine verifyCommandLine;
+ verifyCommandLine.push_back(cmSystemTools::GetCMakeCommand());
+ verifyCommandLine.push_back("-P");
+ verifyCommandLine.push_back(cm->GetGlobVerifyScript());
+ cmCustomCommandLines verifyCommandLines;
+ verifyCommandLines.push_back(verifyCommandLine);
+ std::vector<std::string> byproducts;
+ byproducts.push_back(cm->GetGlobVerifyStamp());
+
+ mf->AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts,
+ no_depends, verifyCommandLines,
+ cmTarget::PRE_BUILD, "Checking File Globs",
+ no_working_directory, false);
+
+ // Ensure ZERO_CHECK always runs in Visual Studio using MSBuild,
+ // otherwise the prebuild command will not be run.
+ tgt->SetProperty("VS_GLOBAL_DisableFastUpToDateCheck", "true");
+ listFiles.push_back(cm->GetGlobVerifyStamp());
}
+
// 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 =
@@ -278,21 +175,19 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
listFiles.erase(new_end, listFiles.end());
// Create a rule to re-run CMake.
- std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
- stampName += "generate.stamp";
cmCustomCommandLine commandLine;
commandLine.push_back(cmSystemTools::GetCMakeCommand());
- std::string argH = "-H";
- argH += lg->GetSourceDirectory();
- commandLine.push_back(argH);
+ std::string argS = "-S";
+ argS += lg->GetSourceDirectory();
+ commandLine.push_back(argS);
std::string argB = "-B";
argB += lg->GetBinaryDirectory();
commandLine.push_back(argB);
commandLine.push_back("--check-stamp-list");
commandLine.push_back(stampList.c_str());
commandLine.push_back("--vs-solution-file");
- std::string const sln = std::string(lg->GetBinaryDirectory()) + "/" +
- lg->GetProjectName() + ".sln";
+ std::string const sln =
+ lg->GetBinaryDirectory() + "/" + lg->GetProjectName() + ".sln";
commandLine.push_back(sln);
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
@@ -301,14 +196,14 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
// 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 = "";
+ std::string no_main_dependency;
std::vector<std::string> no_byproducts;
if (cmSourceFile* file = mf->AddCustomCommandToOutput(
stamps, no_byproducts, listFiles, no_main_dependency, commandLines,
"Checking Build System", no_working_directory, true, false)) {
gt->AddSource(file->GetFullPath());
} else {
- cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
+ cmSystemTools::Error("Error adding rule for " + stamps[0]);
}
}
@@ -320,13 +215,12 @@ void cmGlobalVisualStudio8Generator::AddExtraIDETargets()
cmGlobalVisualStudio7Generator::AddExtraIDETargets();
if (this->AddCheckTarget()) {
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
- std::vector<cmGeneratorTarget*> tgts =
+ const std::vector<cmGeneratorTarget*>& tgts =
this->LocalGenerators[i]->GetGeneratorTargets();
// All targets depend on the build-system check target.
- for (std::vector<cmGeneratorTarget*>::iterator ti = tgts.begin();
- ti != tgts.end(); ++ti) {
- if ((*ti)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
- (*ti)->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
+ for (cmGeneratorTarget const* ti : tgts) {
+ if (ti->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
+ ti->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
}
}
}
@@ -337,10 +231,9 @@ void cmGlobalVisualStudio8Generator::WriteSolutionConfigurations(
std::ostream& fout, std::vector<std::string> const& configs)
{
fout << "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
- fout << "\t\t" << *i << "|" << this->GetPlatformName() << " = " << *i
- << "|" << this->GetPlatformName() << "\n";
+ for (std::string const& i : configs) {
+ fout << "\t\t" << i << "|" << this->GetPlatformName() << " = " << i << "|"
+ << this->GetPlatformName() << "\n";
}
fout << "\tEndGlobalSection\n";
}
@@ -352,35 +245,34 @@ void cmGlobalVisualStudio8Generator::WriteProjectConfigurations(
std::string const& platformMapping)
{
std::string guid = this->GetGUID(name);
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
+ for (std::string const& i : configs) {
std::vector<std::string> mapConfig;
- const char* dstConfig = i->c_str();
+ const char* dstConfig = i.c_str();
if (target.GetProperty("EXTERNAL_MSPROJECT")) {
if (const char* m = target.GetProperty("MAP_IMPORTED_CONFIG_" +
- cmSystemTools::UpperCase(*i))) {
+ cmSystemTools::UpperCase(i))) {
cmSystemTools::ExpandListArgument(m, mapConfig);
if (!mapConfig.empty()) {
dstConfig = mapConfig[0].c_str();
}
}
}
- fout << "\t\t{" << guid << "}." << *i << "|" << this->GetPlatformName()
+ fout << "\t\t{" << guid << "}." << i << "|" << this->GetPlatformName()
<< ".ActiveCfg = " << dstConfig << "|"
<< (!platformMapping.empty() ? platformMapping
: this->GetPlatformName())
<< "\n";
std::set<std::string>::const_iterator ci =
- configsPartOfDefaultBuild.find(*i);
+ configsPartOfDefaultBuild.find(i);
if (!(ci == configsPartOfDefaultBuild.end())) {
- fout << "\t\t{" << guid << "}." << *i << "|" << this->GetPlatformName()
+ fout << "\t\t{" << guid << "}." << i << "|" << this->GetPlatformName()
<< ".Build.0 = " << dstConfig << "|"
<< (!platformMapping.empty() ? platformMapping
: this->GetPlatformName())
<< "\n";
}
- if (this->NeedsDeploy(target.GetType())) {
- fout << "\t\t{" << guid << "}." << *i << "|" << this->GetPlatformName()
+ if (this->NeedsDeploy(target, dstConfig)) {
+ fout << "\t\t{" << guid << "}." << i << "|" << this->GetPlatformName()
<< ".Deploy.0 = " << dstConfig << "|"
<< (!platformMapping.empty() ? platformMapping
: this->GetPlatformName())
@@ -390,11 +282,32 @@ void cmGlobalVisualStudio8Generator::WriteProjectConfigurations(
}
bool cmGlobalVisualStudio8Generator::NeedsDeploy(
- cmStateEnums::TargetType type) const
+ cmGeneratorTarget const& target, const char* config) const
+{
+ cmStateEnums::TargetType type = target.GetType();
+ bool noDeploy = DeployInhibited(target, config);
+ return !noDeploy &&
+ (type == cmStateEnums::EXECUTABLE ||
+ type == cmStateEnums::SHARED_LIBRARY) &&
+ this->TargetSystemSupportsDeployment();
+}
+
+bool cmGlobalVisualStudio8Generator::DeployInhibited(
+ cmGeneratorTarget const& target, const char* config) const
+{
+ bool rVal = false;
+ if (const char* propStr = target.GetProperty("VS_NO_SOLUTION_DEPLOY")) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(propStr);
+ std::string prop = cge->Evaluate(target.LocalGenerator, config);
+ rVal = cmSystemTools::IsOn(prop);
+ }
+ return rVal;
+}
+
+bool cmGlobalVisualStudio8Generator::TargetSystemSupportsDeployment() const
{
- bool needsDeploy =
- (type == cmStateEnums::EXECUTABLE || type == cmStateEnums::SHARED_LIBRARY);
- return this->TargetsWindowsCE() && needsDeploy;
+ return this->TargetsWindowsCE();
}
bool cmGlobalVisualStudio8Generator::ComputeTargetDepends()
@@ -410,12 +323,11 @@ void cmGlobalVisualStudio8Generator::WriteProjectDepends(
{
TargetDependSet const& unordered = this->GetTargetDirectDepends(gt);
OrderedTargetDependSet depends(unordered, std::string());
- for (OrderedTargetDependSet::const_iterator i = depends.begin();
- i != depends.end(); ++i) {
- if ((*i)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (cmTargetDepend const& i : depends) {
+ if (i->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- std::string guid = this->GetGUID((*i)->GetName().c_str());
+ std::string guid = this->GetGUID(i->GetName());
fout << "\t\t{" << guid << "} = {" << guid << "}\n";
}
}
@@ -424,11 +336,9 @@ bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies(
cmGeneratorTarget* target)
{
// Look for utility dependencies that magically link.
- for (std::set<std::string>::const_iterator ui =
- target->GetUtilities().begin();
- ui != target->GetUtilities().end(); ++ui) {
+ for (BT<std::string> const& ui : target->GetUtilities()) {
if (cmGeneratorTarget* depTarget =
- target->GetLocalGenerator()->FindGeneratorTargetToUse(ui->c_str())) {
+ target->GetLocalGenerator()->FindGeneratorTargetToUse(ui.Value)) {
if (depTarget->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
depTarget->GetProperty("EXTERNAL_MSPROJECT")) {
// This utility dependency names an external .vcproj target.
@@ -473,7 +383,7 @@ static cmVS7FlagTable cmVS8ExtraFlagTable[] = {
{ "TreatWChar_tAsBuiltInType", "Zc:wchar_t-",
"wchar_t is not a built-in type", "false", 0 },
- { 0, 0, 0, 0, 0 }
+ { "", "", "", "", 0 }
};
cmIDEFlagTable const* cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8()
{
diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h
index 4723b83ba..352bc3c2b 100644
--- a/Source/cmGlobalVisualStudio8Generator.h
+++ b/Source/cmGlobalVisualStudio8Generator.h
@@ -13,89 +13,73 @@
class cmGlobalVisualStudio8Generator : public cmGlobalVisualStudio71Generator
{
public:
- cmGlobalVisualStudio8Generator(cmake* cm, 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 name for the generator.
+ std::string GetName() const override { return this->Name; }
/** Get the name of the main stamp list file. */
static std::string GetGenerateStampList();
- virtual void EnableLanguage(std::vector<std::string> const& languages,
- cmMakefile*, bool optional);
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
virtual void AddPlatformDefinitions(cmMakefile* mf);
- virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf);
+ bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
/**
* 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();
+ void Configure() override;
/** Return true if the target project file should have the option
LinkLibraryDependencies and link to .sln dependencies. */
- virtual bool NeedLinkLibraryDependencies(cmGeneratorTarget* target);
+ bool NeedLinkLibraryDependencies(cmGeneratorTarget* target) override;
/** Return true if building for Windows CE */
- virtual bool TargetsWindowsCE() const
+ bool TargetsWindowsCE() const override
{
return !this->WindowsCEVersion.empty();
}
- /** Is the installed VS an Express edition? */
- bool IsExpressEdition() const { return this->ExpressEdition; }
-
protected:
- virtual void AddExtraIDETargets();
- virtual const char* GetIDEVersion() { return "8.0"; }
+ cmGlobalVisualStudio8Generator(cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName);
+
+ void AddExtraIDETargets() override;
- virtual std::string FindDevEnvCommand();
+ std::string FindDevEnvCommand() override;
- virtual bool VSLinksDependencies() const { return false; }
+ bool VSLinksDependencies() const override { return false; }
bool AddCheckTarget();
/** Return true if the configuration needs to be deployed */
- virtual bool NeedsDeploy(cmStateEnums::TargetType type) const;
+ virtual bool NeedsDeploy(cmGeneratorTarget const& target,
+ const char* config) const;
+
+ /** Returns true if deployment has been disabled in cmake file. */
+ bool DeployInhibited(cmGeneratorTarget const& target,
+ const char* config) const;
+
+ /** Returns true if the target system support debugging deployment. */
+ virtual bool TargetSystemSupportsDeployment() const;
static cmIDEFlagTable const* GetExtraFlagTableVS8();
- virtual void WriteSLNHeader(std::ostream& fout);
- virtual void WriteSolutionConfigurations(
- std::ostream& fout, std::vector<std::string> const& configs);
- virtual void WriteProjectConfigurations(
+ void WriteSolutionConfigurations(
+ std::ostream& fout, std::vector<std::string> const& configs) override;
+ void WriteProjectConfigurations(
std::ostream& fout, const std::string& name,
cmGeneratorTarget const& target, std::vector<std::string> const& configs,
const std::set<std::string>& configsPartOfDefaultBuild,
- const std::string& platformMapping = "");
- virtual bool ComputeTargetDepends();
- virtual void WriteProjectDepends(std::ostream& fout, const std::string& name,
- const char* path,
- const cmGeneratorTarget* t);
+ const std::string& platformMapping = "") override;
+ bool ComputeTargetDepends() override;
+ void WriteProjectDepends(std::ostream& fout, const std::string& name,
+ const char* path,
+ const cmGeneratorTarget* t) override;
- bool UseFolderProperty();
+ bool UseFolderProperty() const override;
std::string Name;
std::string WindowsCEVersion;
- bool ExpressEdition;
-
-private:
- class Factory;
- friend class Factory;
};
#endif
diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx
index b1634e2ca..6e61d2681 100644
--- a/Source/cmGlobalVisualStudio9Generator.cxx
+++ b/Source/cmGlobalVisualStudio9Generator.cxx
@@ -5,8 +5,8 @@
#include "cmDocumentationEntry.h"
#include "cmLocalVisualStudio7Generator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmVisualStudioWCEPlatformParser.h"
-#include "cmake.h"
static const char vs9generatorName[] = "Visual Studio 9 2008";
@@ -14,7 +14,7 @@ class cmGlobalVisualStudio9Generator::Factory : public cmGlobalGeneratorFactory
{
public:
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE
+ cmake* cm) const override
{
if (strncmp(name.c_str(), vs9generatorName,
sizeof(vs9generatorName) - 1) != 0) {
@@ -52,31 +52,55 @@ public:
return ret;
}
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
+ void GetDocumentation(cmDocumentationEntry& entry) const override
{
entry.Name = std::string(vs9generatorName) + " [arch]";
entry.Brief = "Generates Visual Studio 2008 project files. "
"Optional [arch] can be \"Win64\" or \"IA64\".";
}
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
+ std::vector<std::string> GetGeneratorNames() const override
{
+ std::vector<std::string> names;
names.push_back(vs9generatorName);
+ return names;
+ }
+
+ std::vector<std::string> GetGeneratorNamesWithPlatform() const override
+ {
+ std::vector<std::string> names;
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);
+ for (std::string const& i : availablePlatforms) {
+ names.push_back("Visual Studio 9 2008 " + i);
}
+ return names;
}
- bool SupportsToolset() const CM_OVERRIDE { return false; }
- bool SupportsPlatform() const CM_OVERRIDE { return true; }
+ bool SupportsToolset() const override { return false; }
+ bool SupportsPlatform() const override { return true; }
+
+ std::vector<std::string> GetKnownPlatforms() const override
+ {
+ std::vector<std::string> platforms;
+ platforms.emplace_back("x64");
+ platforms.emplace_back("Win32");
+ platforms.emplace_back("Itanium");
+ cmVisualStudioWCEPlatformParser parser;
+ parser.ParseVersion("9.0");
+ const std::vector<std::string>& availablePlatforms =
+ parser.GetAvailablePlatforms();
+ for (std::string const& i : availablePlatforms) {
+ platforms.emplace_back(i);
+ }
+ return platforms;
+ }
+
+ std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory()
@@ -85,8 +109,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory()
}
cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator(
- cmake* cm, const std::string& name, const std::string& platformName)
- : cmGlobalVisualStudio8Generator(cm, name, platformName)
+ cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName)
+ : cmGlobalVisualStudio8Generator(cm, name, platformInGeneratorName)
{
this->Version = VS9;
std::string vc9Express;
@@ -96,12 +121,6 @@ cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator(
vc9Express, cmSystemTools::KeyWOW64_32);
}
-void cmGlobalVisualStudio9Generator::WriteSLNHeader(std::ostream& fout)
-{
- fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n";
- fout << "# Visual Studio 2008\n";
-}
-
std::string cmGlobalVisualStudio9Generator::GetUserMacrosDirectory()
{
std::string base;
diff --git a/Source/cmGlobalVisualStudio9Generator.h b/Source/cmGlobalVisualStudio9Generator.h
index fbc1f5d07..7bebfd65f 100644
--- a/Source/cmGlobalVisualStudio9Generator.h
+++ b/Source/cmGlobalVisualStudio9Generator.h
@@ -13,31 +13,25 @@
class cmGlobalVisualStudio9Generator : public cmGlobalVisualStudio8Generator
{
public:
- cmGlobalVisualStudio9Generator(cmake* cm, const std::string& name,
- const std::string& platformName);
static cmGlobalGeneratorFactory* NewFactory();
/**
- * 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();
+ std::string GetUserMacrosDirectory() override;
/**
* What is the reg key path to "vsmacros" for this version of Visual
* Studio?
*/
- virtual std::string GetUserMacrosRegKeyBase();
+ std::string GetUserMacrosRegKeyBase() override;
protected:
- virtual const char* GetIDEVersion() { return "9.0"; }
+ cmGlobalVisualStudio9Generator(cmake* cm, const std::string& name,
+ std::string const& platformInGeneratorName);
+
private:
class Factory;
friend class Factory;
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index bbff48eb6..cc97cef09 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -4,11 +4,15 @@
#include "cmGlobalVisualStudioGenerator.h"
#include "cmsys/Encoding.hxx"
+#include <future>
#include <iostream>
+#include <objbase.h>
+#include <shellapi.h>
#include <windows.h>
#include "cmAlgorithms.h"
#include "cmCallVisualStudioMacro.h"
+#include "cmCustomCommand.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudioGenerator.h"
@@ -16,13 +20,22 @@
#include "cmSourceFile.h"
#include "cmState.h"
#include "cmTarget.h"
+#include "cmake.h"
-cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(cmake* cm)
+cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator(
+ cmake* cm, std::string const& platformInGeneratorName)
: cmGlobalGenerator(cm)
{
cm->GetState()->SetIsGeneratorMultiConfig(true);
cm->GetState()->SetWindowsShell(true);
cm->GetState()->SetWindowsVSIDE(true);
+
+ if (platformInGeneratorName.empty()) {
+ this->DefaultPlatformName = "Win32";
+ } else {
+ this->DefaultPlatformName = platformInGeneratorName;
+ this->PlatformInGeneratorName = true;
+ }
}
cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator()
@@ -40,6 +53,116 @@ void cmGlobalVisualStudioGenerator::SetVersion(VSVersion v)
this->Version = v;
}
+void cmGlobalVisualStudioGenerator::EnableLanguage(
+ std::vector<std::string> const& lang, cmMakefile* mf, bool optional)
+{
+ mf->AddDefinition("CMAKE_VS_PLATFORM_NAME_DEFAULT",
+ this->DefaultPlatformName.c_str());
+ this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
+}
+
+bool cmGlobalVisualStudioGenerator::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->cmGlobalGenerator::SetGeneratorPlatform(p, mf);
+}
+
+std::string const& cmGlobalVisualStudioGenerator::GetPlatformName() const
+{
+ if (!this->GeneratorPlatform.empty()) {
+ return this->GeneratorPlatform;
+ }
+ return this->DefaultPlatformName;
+}
+
+const char* cmGlobalVisualStudioGenerator::GetIDEVersion() const
+{
+ switch (this->Version) {
+ case cmGlobalVisualStudioGenerator::VS9:
+ return "9.0";
+ case cmGlobalVisualStudioGenerator::VS10:
+ return "10.0";
+ case cmGlobalVisualStudioGenerator::VS11:
+ return "11.0";
+ case cmGlobalVisualStudioGenerator::VS12:
+ return "12.0";
+ case cmGlobalVisualStudioGenerator::VS14:
+ return "14.0";
+ case cmGlobalVisualStudioGenerator::VS15:
+ return "15.0";
+ case cmGlobalVisualStudioGenerator::VS16:
+ return "16.0";
+ }
+ return "";
+}
+
+void cmGlobalVisualStudioGenerator::WriteSLNHeader(std::ostream& fout)
+{
+ switch (this->Version) {
+ case cmGlobalVisualStudioGenerator::VS9:
+ fout << "Microsoft Visual Studio Solution File, Format Version 10.00\n";
+ fout << "# Visual Studio 2008\n";
+ break;
+ case cmGlobalVisualStudioGenerator::VS10:
+ 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";
+ }
+ break;
+ case cmGlobalVisualStudioGenerator::VS11:
+ 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";
+ }
+ break;
+ case cmGlobalVisualStudioGenerator::VS12:
+ 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";
+ }
+ break;
+ case cmGlobalVisualStudioGenerator::VS14:
+ // 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";
+ }
+ break;
+ case cmGlobalVisualStudioGenerator::VS15:
+ // Visual Studio 15 writes .sln format 12.00
+ fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
+ if (this->ExpressEdition) {
+ fout << "# Visual Studio Express 15 for Windows Desktop\n";
+ } else {
+ fout << "# Visual Studio 15\n";
+ }
+ break;
+ case cmGlobalVisualStudioGenerator::VS16:
+ // Visual Studio 16 writes .sln format 12.00
+ fout << "Microsoft Visual Studio Solution File, Format Version 12.00\n";
+ if (this->ExpressEdition) {
+ fout << "# Visual Studio Express 16 for Windows Desktop\n";
+ } else {
+ fout << "# Visual Studio 16\n";
+ }
+ break;
+ }
+}
+
std::string cmGlobalVisualStudioGenerator::GetRegistryBase()
{
return cmGlobalVisualStudioGenerator::GetRegistryBase(this->GetIDEVersion());
@@ -58,16 +181,15 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
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;
+ for (auto const& it : this->ProjectMap) {
+ std::vector<cmLocalGenerator*> const& gen = it.second;
// add the ALL_BUILD to the first local generator of each project
if (!gen.empty()) {
// 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");
+ "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, no_working_dir,
+ no_depends, no_commands, false, "Build all projects");
cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]);
gen[0]->AddGeneratorTarget(gt);
@@ -80,12 +202,8 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
}
// Now make all targets depend on the ALL_BUILD target
- for (std::vector<cmLocalGenerator*>::iterator i = gen.begin();
- i != gen.end(); ++i) {
- std::vector<cmGeneratorTarget*> targets = (*i)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- cmGeneratorTarget* tgt = *t;
+ for (cmLocalGenerator const* i : gen) {
+ for (cmGeneratorTarget* tgt : i->GetGeneratorTargets()) {
if (tgt->GetType() == cmStateEnums::GLOBAL_TARGET ||
tgt->IsImported()) {
continue;
@@ -101,15 +219,6 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets()
// 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();
- }
}
void cmGlobalVisualStudioGenerator::ComputeTargetObjectDirectory(
@@ -148,7 +257,7 @@ void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
{
std::string dir = this->GetUserMacrosDirectory();
- if (dir != "") {
+ if (!dir.empty()) {
std::string src = cmSystemTools::GetCMakeRoot();
src += "/Templates/" CMAKE_VSMACROS_FILENAME;
@@ -160,13 +269,12 @@ void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
// 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())) {
+ if (!cmSystemTools::FileTimeCompare(src, dst, &res) || res > 0) {
+ if (!cmSystemTools::CopyFileAlways(src, dst)) {
std::ostringstream oss;
oss << "Could not copy from: " << src << std::endl;
oss << " to: " << dst << std::endl;
- cmSystemTools::Message(oss.str().c_str(), "Warning");
+ cmSystemTools::Message(oss.str(), "Warning");
}
}
@@ -188,7 +296,7 @@ void cmGlobalVisualStudioGenerator::CallVisualStudioMacro(
// - the CMake vsmacros file is registered
// - there were .sln/.vcproj files changed during generation
//
- if (dir != "") {
+ if (!dir.empty()) {
std::string macrosFile = dir + "/CMakeMacros/" CMAKE_VSMACROS_FILENAME;
std::string nextSubkeyName;
if (cmSystemTools::FileExists(macrosFile.c_str()) &&
@@ -208,17 +316,7 @@ void cmGlobalVisualStudioGenerator::CallVisualStudioMacro(
std::vector<std::string> filenames;
this->GetFilesReplacedDuringGenerate(filenames);
if (!filenames.empty()) {
- // 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;
- }
+ std::string projects = cmJoin(filenames, ";");
cmCallVisualStudioMacro::CallMacro(
topLevelSlnName, CMAKE_VSMACROS_RELOAD_MACRONAME, projects,
this->GetCMakeInstance()->GetDebugOutput());
@@ -247,10 +345,9 @@ void cmGlobalVisualStudioGenerator::FillLinkClosure(
{
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);
+ for (cmTargetDepend const& di : depends) {
+ if (di.IsLink()) {
+ this->FillLinkClosure(di, linked);
}
}
}
@@ -259,7 +356,7 @@ void cmGlobalVisualStudioGenerator::FillLinkClosure(
cmGlobalVisualStudioGenerator::TargetSet const&
cmGlobalVisualStudioGenerator::GetTargetLinkClosure(cmGeneratorTarget* target)
{
- TargetSetMap::iterator i = this->TargetLinkClosure.find(target);
+ auto i = this->TargetLinkClosure.find(target);
if (i == this->TargetLinkClosure.end()) {
TargetSetMap::value_type entry(target, TargetSet());
i = this->TargetLinkClosure.insert(entry).first;
@@ -279,10 +376,9 @@ void cmGlobalVisualStudioGenerator::FollowLinkDepends(
// 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);
+ for (cmTargetDepend const& di : depends) {
+ if (di.IsLink()) {
+ this->FollowLinkDepends(di, linked);
}
}
}
@@ -293,15 +389,10 @@ 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) {
- std::vector<cmGeneratorTarget*> targets = (*i)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- this->ComputeVSTargetDepends(*ti);
+ for (auto const& it : this->ProjectMap) {
+ for (const cmLocalGenerator* i : it.second) {
+ for (cmGeneratorTarget* ti : i->GetGeneratorTargets()) {
+ this->ComputeVSTargetDepends(ti);
}
}
}
@@ -351,22 +442,18 @@ void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(
// due to behavior (2), but they do not really need to.
std::set<cmGeneratorTarget const*> linkDepends;
if (target->GetType() != cmStateEnums::STATIC_LIBRARY) {
- for (TargetDependSet::const_iterator di = depends.begin();
- di != depends.end(); ++di) {
- cmTargetDepend dep = *di;
- if (dep.IsLink()) {
- this->FollowLinkDepends(*di, linkDepends);
+ for (cmTargetDepend const& di : depends) {
+ if (di.IsLink()) {
+ this->FollowLinkDepends(di, linkDepends);
}
}
}
// Collect explicit util dependencies (add_dependencies).
std::set<cmGeneratorTarget const*> utilDepends;
- for (TargetDependSet::const_iterator di = depends.begin();
- di != depends.end(); ++di) {
- cmTargetDepend dep = *di;
- if (dep.IsUtil()) {
- this->FollowLinkDepends(*di, utilDepends);
+ for (cmTargetDepend const& di : depends) {
+ if (di.IsUtil()) {
+ this->FollowLinkDepends(di, utilDepends);
}
}
@@ -378,16 +465,12 @@ void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(
}
// Emit link dependencies.
- for (std::set<cmGeneratorTarget const*>::iterator di = linkDepends.begin();
- di != linkDepends.end(); ++di) {
- cmGeneratorTarget const* dep = *di;
+ for (cmGeneratorTarget const* dep : linkDepends) {
vsTargetDepend.insert(dep->GetName());
}
// Emit util dependencies. Possibly use intermediate targets.
- for (std::set<cmGeneratorTarget const*>::iterator di = utilDepends.begin();
- di != utilDepends.end(); ++di) {
- cmGeneratorTarget const* dgt = *di;
+ for (cmGeneratorTarget const* dgt : utilDepends) {
if (allowLinkable || !VSLinkable(dgt) || linked.count(dgt)) {
// Direct dependency allowed.
vsTargetDepend.insert(dgt->GetName());
@@ -413,7 +496,7 @@ bool cmGlobalVisualStudioGenerator::FindMakeProgram(cmMakefile* mf)
std::string cmGlobalVisualStudioGenerator::GetUtilityDepend(
cmGeneratorTarget const* target)
{
- UtilityDependsMap::iterator i = this->UtilityDepends.find(target);
+ auto i = this->UtilityDepends.find(target);
if (i == this->UtilityDepends.end()) {
std::string name = this->WriteUtilityDepend(target);
UtilityDependsMap::value_type entry(target, name);
@@ -432,7 +515,7 @@ std::string cmGlobalVisualStudioGenerator::GetStartupProjectName(
return startup;
} else {
root->GetMakefile()->IssueMessage(
- cmake::AUTHOR_WARNING,
+ MessageType::AUTHOR_WARNING,
"Directory property VS_STARTUP_PROJECT specifies target "
"'" +
startup + "' that does not exist. Ignoring.");
@@ -477,9 +560,9 @@ bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile,
lastWriteTime.dwHighDateTime = 0;
lastWriteTime.dwLowDateTime = 0;
- while (ERROR_SUCCESS == RegEnumKeyExW(hkey, index, subkeyname,
- &cch_subkeyname, 0, keyclass,
- &cch_keyclass, &lastWriteTime)) {
+ 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);
@@ -691,7 +774,7 @@ void RegisterVisualStudioMacros(const std::string& macrosFile,
<< "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");
+ cmSystemTools::Message(oss.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
@@ -722,7 +805,6 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
cmGeneratorTarget const* gt)
{
// 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;
@@ -730,65 +812,25 @@ bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(
return false;
}
}
+
// If there's only one source language, Fortran has to be used
// in order for the sources to compile.
- // Note: Via linker propagation, LINKER_LANGUAGE could become CXX in
- // this situation and mismatch from the actual language of the linker.
- gt->GetLanguages(languages, "");
- if (languages.size() == 1) {
- if (*languages.begin() == "Fortran") {
- return true;
- }
- }
-
- // In the case of mixed object files or sources mixed with objects,
- // decide the language based on the value of LINKER_LANGUAGE.
- // This will not make it possible to mix source files of different
- // languages, but object libraries will be linked together in the
- // same fashion as other generators do.
- if (gt->GetLinkerLanguage("") == "Fortran") {
- return true;
- }
-
- return false;
-}
-
-bool cmGlobalVisualStudioGenerator::TargetIsCSharpOnly(
- cmGeneratorTarget const* gt)
-{
- // check to see if this is a C# build
std::set<std::string> languages;
- {
- // Issue diagnostic if the source files depend on the config.
- std::vector<cmSourceFile*> sources;
- if (!gt->GetConfigCommonSourceFiles(sources)) {
- return false;
- }
- // Only "real" targets are allowed to be C# targets.
- if (gt->Target->GetType() > cmStateEnums::OBJECT_LIBRARY) {
- return false;
- }
- }
gt->GetLanguages(languages, "");
- if (languages.size() == 1) {
- if (*languages.begin() == "CSharp") {
- return true;
- }
+ // Consider an explicit linker language property, but *not* the
+ // computed linker language that may depend on linked targets.
+ // This allows the project to control the language choice in
+ // a target with none of its own sources, e.g. when also using
+ // object libraries.
+ const char* linkLang = gt->GetProperty("LINKER_LANGUAGE");
+ if (linkLang && *linkLang) {
+ languages.insert(linkLang);
}
- return false;
-}
-bool cmGlobalVisualStudioGenerator::TargetCanBeReferenced(
- cmGeneratorTarget const* gt)
-{
- if (this->TargetIsCSharpOnly(gt)) {
- return true;
- }
- if (gt->GetType() != cmStateEnums::SHARED_LIBRARY &&
- gt->GetType() != cmStateEnums::EXECUTABLE) {
- return false;
- }
- return true;
+ // Intel Fortran .vfproj files do support the resource compiler.
+ languages.erase("RC");
+
+ return languages.size() == 1 && *languages.begin() == "Fortran";
}
bool cmGlobalVisualStudioGenerator::TargetCompare::operator()(
@@ -817,9 +859,8 @@ cmGlobalVisualStudioGenerator::OrderedTargetDependSet::OrderedTargetDependSet(
TargetSet const& targets, std::string const& first)
: derived(TargetCompare(first))
{
- for (TargetSet::const_iterator it = targets.begin(); it != targets.end();
- ++it) {
- this->insert(*it);
+ for (cmGeneratorTarget const* it : targets) {
+ this->insert(it);
}
}
@@ -853,10 +894,8 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
std::vector<cmSourceFile const*> objectSources;
gt->GetObjectSources(objectSources, configName);
std::map<cmSourceFile const*, std::string> mapping;
- for (std::vector<cmSourceFile const*>::const_iterator it =
- objectSources.begin();
- it != objectSources.end(); ++it) {
- mapping[*it];
+ for (cmSourceFile const* it : objectSources) {
+ mapping[it];
}
gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);
std::string obj_dir = gt->ObjectDirectory;
@@ -875,34 +914,28 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
cmdl.push_back(objs_file);
cmGeneratedFileStream fout(objs_file.c_str());
if (!fout) {
- cmSystemTools::Error("could not open ", objs_file.c_str());
+ cmSystemTools::Error("could not open " + objs_file);
return;
}
if (mdi->WindowsExportAllSymbols) {
std::vector<std::string> objs;
- for (std::vector<cmSourceFile const*>::const_iterator it =
- objectSources.begin();
- it != objectSources.end(); ++it) {
+ for (cmSourceFile const* it : objectSources) {
// Find the object file name corresponding to this source file.
- std::map<cmSourceFile const*, std::string>::const_iterator map_it =
- mapping.find(*it);
// It must exist because we populated the mapping just above.
- assert(!map_it->second.empty());
- std::string objFile = obj_dir + map_it->second;
+ const auto& v = mapping[it];
+ assert(!v.empty());
+ std::string objFile = obj_dir + v;
objs.push_back(objFile);
}
std::vector<cmSourceFile const*> externalObjectSources;
gt->GetExternalObjects(externalObjectSources, configName);
- for (std::vector<cmSourceFile const*>::const_iterator it =
- externalObjectSources.begin();
- it != externalObjectSources.end(); ++it) {
- objs.push_back((*it)->GetFullPath());
+ for (cmSourceFile const* it : externalObjectSources) {
+ objs.push_back(it->GetFullPath());
}
- for (std::vector<std::string>::iterator it = objs.begin();
- it != objs.end(); ++it) {
- std::string objFile = *it;
+ for (std::string const& it : objs) {
+ std::string objFile = it;
// replace $(ConfigurationName) in the object names
cmSystemTools::ReplaceString(objFile, this->GetCMakeCFGIntDir(),
configName.c_str());
@@ -912,10 +945,8 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
}
}
- for (std::vector<cmSourceFile const*>::const_iterator i =
- mdi->Sources.begin();
- i != mdi->Sources.end(); ++i) {
- fout << (*i)->GetFullPath() << "\n";
+ for (cmSourceFile const* i : mdi->Sources) {
+ fout << i->GetFullPath() << "\n";
}
cmCustomCommandLines commandLines;
@@ -924,3 +955,34 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
commandLines, "Auto build dll exports", ".");
commands.push_back(command);
}
+
+static bool OpenSolution(std::string sln)
+{
+ HRESULT comInitialized =
+ CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
+ if (FAILED(comInitialized)) {
+ return false;
+ }
+
+ HINSTANCE hi =
+ ShellExecuteA(NULL, "open", sln.c_str(), NULL, NULL, SW_SHOWNORMAL);
+
+ CoUninitialize();
+
+ return reinterpret_cast<intptr_t>(hi) > 32;
+}
+
+bool cmGlobalVisualStudioGenerator::Open(const std::string& bindir,
+ const std::string& projectName,
+ bool dryRun)
+{
+ std::string sln = bindir + "/" + projectName + ".sln";
+
+ if (dryRun) {
+ return cmSystemTools::FileExists(sln, true);
+ }
+
+ sln = cmSystemTools::ConvertToOutputPath(sln);
+
+ return std::async(std::launch::async, OpenSolution, sln).get();
+}
diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h
index 3c43ccdd2..cbab3294d 100644
--- a/Source/cmGlobalVisualStudioGenerator.h
+++ b/Source/cmGlobalVisualStudioGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalVisualStudioGenerator_h
#define cmGlobalVisualStudioGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
@@ -32,22 +32,35 @@ public:
/** Known versions of Visual Studio. */
enum VSVersion
{
- VS8 = 80,
VS9 = 90,
VS10 = 100,
VS11 = 110,
VS12 = 120,
/* VS13 = 130 was skipped */
VS14 = 140,
- VS15 = 150
+ VS15 = 150,
+ VS16 = 160
};
- cmGlobalVisualStudioGenerator(cmake* cm);
virtual ~cmGlobalVisualStudioGenerator();
VSVersion GetVersion() const;
void SetVersion(VSVersion v);
+ /** Is the installed VS an Express edition? */
+ bool IsExpressEdition() const { return this->ExpressEdition; }
+
+ void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
+ bool optional) override;
+
+ bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
+
+ /**
+ * Get the name of the target platform (architecture) for which we generate.
+ * The names are as defined by VS, e.g. "Win32", "x64", "Itanium", "ARM".
+ */
+ std::string const& GetPlatformName() const;
+
/**
* Configure CMake's Visual Studio macros file into the user's Visual
* Studio macros directory.
@@ -82,12 +95,6 @@ public:
// return true if target is fortran only
bool TargetIsFortranOnly(const cmGeneratorTarget* gt);
- // return true if target is C# only
- static bool TargetIsCSharpOnly(cmGeneratorTarget const* gt);
-
- // return true if target can be referenced by C# targets
- bool TargetCanBeReferenced(cmGeneratorTarget const* gt);
-
/** Get the top-level registry key for this VS version. */
std::string GetRegistryBase();
@@ -96,11 +103,13 @@ public:
/** 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() const { return true; }
+ bool IsMultiConfig() const override { return true; }
/** Return true if building for Windows CE */
virtual bool TargetsWindowsCE() const { return false; }
+ bool IsIncludeExternalMSProjectSupported() const override { return true; }
+
class TargetSet : public std::set<cmGeneratorTarget const*>
{
};
@@ -118,12 +127,12 @@ public:
};
class OrderedTargetDependSet;
- bool FindMakeProgram(cmMakefile*) CM_OVERRIDE;
+ bool FindMakeProgram(cmMakefile*) override;
- virtual std::string ExpandCFGIntDir(const std::string& str,
- const std::string& config) const;
+ std::string ExpandCFGIntDir(const std::string& str,
+ const std::string& config) const override;
- void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const;
+ void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
std::string GetStartupProjectName(cmLocalGenerator const* root) const;
@@ -131,17 +140,25 @@ public:
std::vector<cmCustomCommand>& commands,
std::string const& configName);
+ bool Open(const std::string& bindir, const std::string& projectName,
+ bool dryRun) override;
+
protected:
- virtual void AddExtraIDETargets();
+ cmGlobalVisualStudioGenerator(cmake* cm,
+ std::string const& platformInGeneratorName);
+
+ void AddExtraIDETargets() override;
// 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;
+ const char* GetIDEVersion() const;
+
+ void WriteSLNHeader(std::ostream& fout);
- virtual bool ComputeTargetDepends();
+ bool ComputeTargetDepends() override;
class VSDependSet : public std::set<std::string>
{
};
@@ -161,11 +178,16 @@ protected:
protected:
VSVersion Version;
+ bool ExpressEdition;
+
+ std::string GeneratorPlatform;
+ std::string DefaultPlatformName;
+ bool PlatformInGeneratorName = false;
private:
virtual std::string GetVSMakeProgram() = 0;
void PrintCompilerAdvice(std::ostream&, std::string const&,
- const char*) const
+ const char*) const override
{
}
diff --git a/Source/cmGlobalWatcomWMakeGenerator.cxx b/Source/cmGlobalWatcomWMakeGenerator.cxx
index 94cdb3848..8a2738431 100644
--- a/Source/cmGlobalWatcomWMakeGenerator.cxx
+++ b/Source/cmGlobalWatcomWMakeGenerator.cxx
@@ -3,10 +3,13 @@
#include "cmGlobalWatcomWMakeGenerator.h"
#include "cmDocumentationEntry.h"
+#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmState.h"
#include "cmake.h"
+#include <ostream>
+
cmGlobalWatcomWMakeGenerator::cmGlobalWatcomWMakeGenerator(cmake* cm)
: cmGlobalUnixMakefileGenerator3(cm)
{
@@ -47,3 +50,32 @@ void cmGlobalWatcomWMakeGenerator::GetDocumentation(
entry.Name = cmGlobalWatcomWMakeGenerator::GetActualName();
entry.Brief = "Generates Watcom WMake makefiles.";
}
+
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalWatcomWMakeGenerator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int /*jobs*/, bool verbose,
+ std::vector<std::string> const& makeOptions)
+{
+ return this->cmGlobalUnixMakefileGenerator3::GenerateBuildCommand(
+ makeProgram, projectName, projectDir, targetNames, config, fast,
+ cmake::NO_BUILD_PARALLEL_LEVEL, verbose, makeOptions);
+}
+
+void cmGlobalWatcomWMakeGenerator::PrintBuildCommandAdvice(std::ostream& os,
+ int jobs) const
+{
+ if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
+ // wmake does not support parallel build level
+
+ /* clang-format off */
+ os <<
+ "Warning: Watcom's WMake does not support parallel builds. "
+ "Ignoring parallel build command line option.\n";
+ /* clang-format on */
+ }
+
+ this->cmGlobalUnixMakefileGenerator3::PrintBuildCommandAdvice(
+ os, cmake::NO_BUILD_PARALLEL_LEVEL);
+}
diff --git a/Source/cmGlobalWatcomWMakeGenerator.h b/Source/cmGlobalWatcomWMakeGenerator.h
index b2d6d5d71..3ca5e7d86 100644
--- a/Source/cmGlobalWatcomWMakeGenerator.h
+++ b/Source/cmGlobalWatcomWMakeGenerator.h
@@ -3,11 +3,12 @@
#ifndef cmGlobalWatcomWMakeGenerator_h
#define cmGlobalWatcomWMakeGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmGlobalGeneratorFactory.h"
#include "cmGlobalUnixMakefileGenerator3.h"
+#include <iosfwd>
#include <string>
#include <vector>
@@ -28,8 +29,8 @@ public:
{
return new cmGlobalGeneratorSimpleFactory<cmGlobalWatcomWMakeGenerator>();
}
- ///! Get the name for the generator.
- std::string GetName() const CM_OVERRIDE
+ //! Get the name for the generator.
+ std::string GetName() const override
{
return cmGlobalWatcomWMakeGenerator::GetActualName();
}
@@ -43,10 +44,20 @@ public:
* extension, pthreads, byte order etc.
*/
void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
- bool optional) CM_OVERRIDE;
+ bool optional) override;
- bool AllowNotParallel() const CM_OVERRIDE { return false; }
- bool AllowDeleteOnError() const CM_OVERRIDE { return false; }
+ bool AllowNotParallel() const override { return false; }
+ bool AllowDeleteOnError() const override { return false; }
+
+protected:
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
+
+ void PrintBuildCommandAdvice(std::ostream& os, int jobs) const override;
};
#endif
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index 903796123..9d725282b 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -5,11 +5,14 @@
#include "cmsys/RegularExpression.hxx"
#include <assert.h>
#include <iomanip>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <string.h>
+#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
+#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmDocumentationEntry.h"
#include "cmGeneratedFileStream.h"
@@ -19,6 +22,7 @@
#include "cmLocalGenerator.h"
#include "cmLocalXCodeGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmOutputConverter.h"
#include "cmSourceFile.h"
#include "cmSourceGroup.h"
@@ -29,13 +33,17 @@
#include "cmXCode21Object.h"
#include "cmXCodeObject.h"
#include "cmXCodeScheme.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
struct cmLinkImplementation;
+#if defined(CMAKE_BUILD_WITH_CMAKE) && defined(__APPLE__)
+# define HAVE_APPLICATION_SERVICES
+# include <ApplicationServices/ApplicationServices.h>
+#endif
+
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmXMLParser.h"
+# include "cmXMLParser.h"
// parse the xml file storing the installed version of Xcode on
// the machine
@@ -46,8 +54,11 @@ public:
: Version("1.5")
{
}
- void StartElement(const std::string&, const char**) { this->Data = ""; }
- void EndElement(const std::string& name)
+ void StartElement(const std::string&, const char**) override
+ {
+ this->Data = "";
+ }
+ void EndElement(const std::string& name) override
{
if (name == "key") {
this->Key = this->Data;
@@ -57,7 +68,7 @@ public:
}
}
}
- void CharacterDataHandler(const char* data, int length)
+ void CharacterDataHandler(const char* data, int length) override
{
this->Data.append(data, length);
}
@@ -79,7 +90,7 @@ class cmGlobalXCodeGenerator::BuildObjectListOrString
public:
BuildObjectListOrString(cmGlobalXCodeGenerator* gen, bool buildObjectList)
: Generator(gen)
- , Group(0)
+ , Group(nullptr)
, Empty(true)
{
if (buildObjectList) {
@@ -107,9 +118,8 @@ public:
{
if (this->Group) {
return this->Group;
- } else {
- return this->Generator->CreateString(this->String);
}
+ return this->Generator->CreateString(this->String);
}
};
@@ -117,20 +127,34 @@ class cmGlobalXCodeGenerator::Factory : public cmGlobalGeneratorFactory
{
public:
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name,
- cmake* cm) const CM_OVERRIDE;
+ cmake* cm) const override;
- void GetDocumentation(cmDocumentationEntry& entry) const CM_OVERRIDE
+ void GetDocumentation(cmDocumentationEntry& entry) const override
{
cmGlobalXCodeGenerator::GetDocumentation(entry);
}
- void GetGenerators(std::vector<std::string>& names) const CM_OVERRIDE
+ std::vector<std::string> GetGeneratorNames() const override
{
+ std::vector<std::string> names;
names.push_back(cmGlobalXCodeGenerator::GetActualName());
+ return names;
}
- bool SupportsToolset() const CM_OVERRIDE { return true; }
- bool SupportsPlatform() const CM_OVERRIDE { return false; }
+ std::vector<std::string> GetGeneratorNamesWithPlatform() const override
+ {
+ return std::vector<std::string>();
+ }
+
+ bool SupportsToolset() const override { return true; }
+ bool SupportsPlatform() const override { return false; }
+
+ std::vector<std::string> GetKnownPlatforms() const override
+ {
+ return std::vector<std::string>();
+ }
+
+ std::string GetDefaultPlatformName() const override { return std::string(); }
};
cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(
@@ -140,10 +164,10 @@ cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(
this->VersionString = version_string;
this->XcodeVersion = version_number;
- this->RootObject = 0;
- this->MainGroupChildren = 0;
- this->CurrentMakefile = 0;
- this->CurrentLocalGenerator = 0;
+ this->RootObject = nullptr;
+ this->MainGroupChildren = nullptr;
+ this->CurrentMakefile = nullptr;
+ this->CurrentLocalGenerator = nullptr;
this->XcodeBuildCommandInitialized = false;
this->ObjectDirArchDefault = "$(CURRENT_ARCH)";
@@ -160,21 +184,25 @@ cmGlobalGeneratorFactory* cmGlobalXCodeGenerator::NewFactory()
cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator(
const std::string& name, cmake* cm) const
{
- if (name != GetActualName())
- return 0;
+ if (name != GetActualName()) {
+ return nullptr;
+ }
#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, 0, cmSystemTools::OUTPUT_NONE) &&
- (pos = out.find(".app/"), pos != std::string::npos)) {
- versionFile = out.substr(0, pos + 5) + "Contents/version.plist";
+ bool commandResult = cmSystemTools::RunSingleCommand(
+ "xcode-select --print-path", &out, nullptr, nullptr, nullptr,
+ cmSystemTools::OUTPUT_NONE);
+ if (commandResult) {
+ std::string::size_type pos = out.find(".app/");
+ if (pos != std::string::npos) {
+ versionFile = out.substr(0, pos + 5) + "Contents/version.plist";
+ }
}
}
- if (!versionFile.empty() && cmSystemTools::FileExists(versionFile.c_str())) {
+ if (!versionFile.empty() && cmSystemTools::FileExists(versionFile)) {
parser.ParseFile(versionFile.c_str());
} else if (cmSystemTools::FileExists(
"/Applications/Xcode.app/Contents/version.plist")) {
@@ -190,14 +218,14 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::Factory::CreateGlobalGenerator(
sscanf(version_string.c_str(), "%u.%u", &v[0], &v[1]);
unsigned int version_number = 10 * v[0] + v[1];
- if (version_number < 30) {
- cm->IssueMessage(cmake::FATAL_ERROR,
+ if (version_number < 50) {
+ cm->IssueMessage(MessageType::FATAL_ERROR,
"Xcode " + version_string + " not supported.");
- return CM_NULLPTR;
+ return nullptr;
}
- CM_AUTO_PTR<cmGlobalXCodeGenerator> gg(
- new cmGlobalXCodeGenerator(cm, version_string, version_number));
+ auto gg = cm::make_unique<cmGlobalXCodeGenerator>(cm, version_string,
+ version_number);
return gg.release();
#else
std::cerr << "CMake should be built with cmake to use Xcode, "
@@ -229,16 +257,11 @@ std::string const& cmGlobalXCodeGenerator::GetXcodeBuildCommand()
std::string cmGlobalXCodeGenerator::FindXcodeBuildCommand()
{
- if (this->XcodeVersion >= 40) {
- std::string makeProgram = cmSystemTools::FindProgram("xcodebuild");
- if (makeProgram.empty()) {
- makeProgram = "xcodebuild";
- }
- return makeProgram;
- } else {
- // Use cmakexbuild wrapper to suppress environment dump from output.
- return cmSystemTools::GetCMakeCommand() + "xbuild";
+ std::string makeProgram = cmSystemTools::FindProgram("xcodebuild");
+ if (makeProgram.empty()) {
+ makeProgram = "xcodebuild";
}
+ return makeProgram;
}
bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts,
@@ -254,7 +277,7 @@ bool cmGlobalXCodeGenerator::SetGeneratorToolset(std::string const& ts,
" " << ts << "\n"
"that was specified.";
/* clang-format on */
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
this->GeneratorToolset = ts;
@@ -283,46 +306,90 @@ void cmGlobalXCodeGenerator::EnableLanguage(
this->ComputeArchitectures(mf);
}
-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*/,
- bool /*verbose*/, std::vector<std::string> const& makeOptions)
+bool cmGlobalXCodeGenerator::Open(const std::string& bindir,
+ const std::string& projectName, bool dryRun)
{
- // now build the test
- makeCommand.push_back(
- this->SelectMakeProgram(makeProgram, this->GetXcodeBuildCommand()));
+ bool ret = false;
- makeCommand.push_back("-project");
- std::string projectArg = projectName;
- projectArg += ".xcode";
- projectArg += "proj";
- makeCommand.push_back(projectArg);
+#ifdef HAVE_APPLICATION_SERVICES
+ std::string url = bindir + "/" + projectName + ".xcodeproj";
- bool clean = false;
- std::string realTarget = targetName;
- if (realTarget == "clean") {
- clean = true;
- realTarget = "ALL_BUILD";
+ if (dryRun) {
+ return cmSystemTools::FileExists(url, false);
}
- if (clean) {
- makeCommand.push_back("clean");
- } else {
- makeCommand.push_back("build");
+
+ CFStringRef cfStr = CFStringCreateWithCString(
+ kCFAllocatorDefault, url.c_str(), kCFStringEncodingUTF8);
+ if (cfStr) {
+ CFURLRef cfUrl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfStr,
+ kCFURLPOSIXPathStyle, true);
+ if (cfUrl) {
+ OSStatus err = LSOpenCFURLRef(cfUrl, nullptr);
+ ret = err == noErr;
+ CFRelease(cfUrl);
+ }
+ CFRelease(cfStr);
}
- makeCommand.push_back("-target");
- if (!realTarget.empty()) {
- makeCommand.push_back(realTarget);
+#endif
+
+ return ret;
+}
+
+std::vector<cmGlobalGenerator::GeneratedMakeCommand>
+cmGlobalXCodeGenerator::GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& /*projectDir*/,
+ std::vector<std::string> const& targetNames, const std::string& config,
+ bool /*fast*/, int jobs, bool /*verbose*/,
+ std::vector<std::string> const& makeOptions)
+{
+ GeneratedMakeCommand makeCommand;
+ // now build the test
+ makeCommand.Add(
+ this->SelectMakeProgram(makeProgram, this->GetXcodeBuildCommand()));
+
+ if (!projectName.empty()) {
+ makeCommand.Add("-project");
+ std::string projectArg = projectName;
+ projectArg += ".xcode";
+ projectArg += "proj";
+ makeCommand.Add(projectArg);
+ }
+ if (std::find(targetNames.begin(), targetNames.end(), "clean") !=
+ targetNames.end()) {
+ makeCommand.Add("clean");
+ makeCommand.Add("-target", "ALL_BUILD");
} else {
- makeCommand.push_back("ALL_BUILD");
+ makeCommand.Add("build");
+ if (targetNames.empty() ||
+ ((targetNames.size() == 1) && targetNames.front().empty())) {
+ makeCommand.Add("-target", "ALL_BUILD");
+ } else {
+ for (const auto& tname : targetNames) {
+ if (!tname.empty()) {
+ makeCommand.Add("-target", tname);
+ }
+ }
+ }
}
- makeCommand.push_back("-configuration");
- makeCommand.push_back(!config.empty() ? config : "Debug");
- makeCommand.insert(makeCommand.end(), makeOptions.begin(),
- makeOptions.end());
+
+ makeCommand.Add("-configuration", (config.empty() ? "Debug" : config));
+
+ if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
+ makeCommand.Add("-jobs");
+ if (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
+ makeCommand.Add(std::to_string(jobs));
+ }
+ }
+
+ if (this->XcodeVersion >= 70) {
+ makeCommand.Add("-hideShellScriptEnvironment");
+ }
+ makeCommand.Add(makeOptions.begin(), makeOptions.end());
+ return { std::move(makeCommand) };
}
-///! Create a local generator appropriate to this Global Generator
+//! Create a local generator appropriate to this Global Generator
cmLocalGenerator* cmGlobalXCodeGenerator::CreateLocalGenerator(cmMakefile* mf)
{
return new cmLocalXCodeGenerator(this, mf);
@@ -330,29 +397,72 @@ cmLocalGenerator* cmGlobalXCodeGenerator::CreateLocalGenerator(cmMakefile* mf)
void cmGlobalXCodeGenerator::AddExtraIDETargets()
{
- 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];
+ for (auto keyVal : this->ProjectMap) {
+ cmLocalGenerator* root = keyVal.second[0];
this->SetGenerationRoot(root);
// add ALL_BUILD, INSTALL, etc
- this->AddExtraTargets(root, it->second);
+ this->AddExtraTargets(root, keyVal.second);
}
}
+void cmGlobalXCodeGenerator::ComputeTargetOrder()
+{
+ size_t index = 0;
+ auto const& lgens = this->GetLocalGenerators();
+ for (cmLocalGenerator* lgen : lgens) {
+ auto const& targets = lgen->GetGeneratorTargets();
+ for (cmGeneratorTarget const* gt : targets) {
+ this->ComputeTargetOrder(gt, index);
+ }
+ }
+ assert(index == this->TargetOrderIndex.size());
+}
+
+void cmGlobalXCodeGenerator::ComputeTargetOrder(cmGeneratorTarget const* gt,
+ size_t& index)
+{
+ std::map<cmGeneratorTarget const*, size_t>::value_type value(gt, 0);
+ auto insertion = this->TargetOrderIndex.insert(value);
+ if (!insertion.second) {
+ return;
+ }
+ auto entry = insertion.first;
+
+ auto& deps = this->GetTargetDirectDepends(gt);
+ for (auto& d : deps) {
+ this->ComputeTargetOrder(d, index);
+ }
+
+ entry->second = index++;
+}
+
void cmGlobalXCodeGenerator::Generate()
{
this->cmGlobalGenerator::Generate();
if (cmSystemTools::GetErrorOccuredFlag()) {
return;
}
- std::map<std::string, std::vector<cmLocalGenerator*> >::iterator it;
- for (it = this->ProjectMap.begin(); it != this->ProjectMap.end(); ++it) {
- cmLocalGenerator* root = it->second[0];
+
+ this->ComputeTargetOrder();
+
+ for (auto keyVal : this->ProjectMap) {
+ cmLocalGenerator* root = keyVal.second[0];
+
+ bool generateTopLevelProjectOnly =
+ root->GetMakefile()->IsOn("CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY");
+
+ if (generateTopLevelProjectOnly) {
+ cmStateSnapshot snp = root->GetStateSnapshot();
+ if (snp.GetBuildsystemDirectoryParent().IsValid()) {
+ continue;
+ }
+ }
+
this->SetGenerationRoot(root);
// now create the project
- this->OutputXCodeProject(root, it->second);
+ this->OutputXCodeProject(root, keyVal.second);
}
}
@@ -369,7 +479,7 @@ void cmGlobalXCodeGenerator::SetGenerationRoot(cmLocalGenerator* root)
this->CurrentXCodeHackMakefile = root->GetCurrentBinaryDirectory();
this->CurrentXCodeHackMakefile += "/CMakeScripts";
- cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile.c_str());
+ cmSystemTools::MakeDirectory(this->CurrentXCodeHackMakefile);
this->CurrentXCodeHackMakefile += "/XCODE_DEPEND_HELPER.make";
}
@@ -384,6 +494,7 @@ std::string cmGlobalXCodeGenerator::PostBuildMakeTarget(
}
#define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK"
+#define OBJECT_LIBRARY_ARTIFACT_DIR std::string()
void cmGlobalXCodeGenerator::AddExtraTargets(
cmLocalGenerator* root, std::vector<cmLocalGenerator*>& gens)
@@ -391,21 +502,15 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
cmMakefile* mf = root->GetMakefile();
// Add ALL_BUILD
- const char* no_working_directory = 0;
+ const char* no_working_directory = nullptr;
std::vector<std::string> no_depends;
- cmTarget* allbuild =
- mf->AddUtilityCommand("ALL_BUILD", true, no_depends, no_working_directory,
- "echo", "Build all projects");
+ cmTarget* allbuild = mf->AddUtilityCommand(
+ "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, no_depends,
+ no_working_directory, "echo", "Build all projects");
cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root);
root->AddGeneratorTarget(allBuildGt);
- // Refer to the main build configuration file for easy editing.
- std::string listfile = root->GetCurrentSourceDirectory();
- listfile += "/";
- listfile += "CMakeLists.txt";
- allBuildGt->AddSource(listfile);
-
// Add XCODE depend helper
std::string dir = root->GetCurrentBinaryDirectory();
cmCustomCommandLine makeHelper;
@@ -414,18 +519,23 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
makeHelper.push_back(dir);
makeHelper.push_back("-f");
makeHelper.push_back(this->CurrentXCodeHackMakefile);
+ makeHelper.push_back("OBJDIR=$(OBJDIR)");
makeHelper.push_back(""); // placeholder, see below
// Add ZERO_CHECK
- bool regenerate = !mf->IsOn("CMAKE_SUPPRESS_REGENERATION");
- if (regenerate) {
+ bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION");
+ bool generateTopLevelProjectOnly =
+ mf->IsOn("CMAKE_XCODE_GENERATE_TOP_LEVEL_PROJECT_ONLY");
+ bool isTopLevel =
+ !root->GetStateSnapshot().GetBuildsystemDirectoryParent().IsValid();
+ if (regenerate && (isTopLevel || !generateTopLevelProjectOnly)) {
this->CreateReRunCMakeFile(root, gens);
std::string file =
- this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile.c_str());
+ this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile);
cmSystemTools::ReplaceString(file, "\\ ", " ");
- cmTarget* check =
- mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, no_depends,
- no_working_directory, "make", "-f", file.c_str());
+ cmTarget* check = mf->AddUtilityCommand(
+ CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator,
+ true, no_depends, no_working_directory, "make", "-f", file.c_str());
cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root);
root->AddGeneratorTarget(checkGt);
@@ -433,18 +543,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
// 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;
- }
-
- std::vector<cmGeneratorTarget*> tgts = lg->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); l++) {
- cmGeneratorTarget* target = *l;
-
+ for (auto& gen : gens) {
+ for (auto target : gen->GetGeneratorTargets()) {
if (target->GetType() == cmStateEnums::GLOBAL_TARGET) {
continue;
}
@@ -459,33 +559,21 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
// 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 (target->GetType() == cmStateEnums::OBJECT_LIBRARY ||
- (this->XcodeVersion < 50 &&
- (target->GetType() == cmStateEnums::EXECUTABLE ||
- target->GetType() == cmStateEnums::STATIC_LIBRARY ||
- target->GetType() == cmStateEnums::SHARED_LIBRARY ||
- target->GetType() == cmStateEnums::MODULE_LIBRARY))) {
- makeHelper[makeHelper.size() - 1] = // fill placeholder
+ if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
+ makeHelper.back() = // fill placeholder
this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)");
cmCustomCommandLines commandLines;
commandLines.push_back(makeHelper);
std::vector<std::string> no_byproducts;
- lg->GetMakefile()->AddCustomCommandToTarget(
+ gen->GetMakefile()->AddCustomCommandToTarget(
target->GetName(), no_byproducts, no_depends, commandLines,
cmTarget::POST_BUILD, "Depend check for xcode", dir.c_str(), true,
- false, "", false, cmMakefile::AcceptObjectLibraryCommands);
+ false, "", "", false, cmMakefile::AcceptObjectLibraryCommands);
}
- if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
- !target->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
+ if (!this->IsExcluded(gens[0], target)) {
allbuild->AddUtility(target->GetName());
}
-
- // Refer to the build configuration file for easy editing.
- listfile = lg->GetCurrentSourceDirectory();
- listfile += "/";
- listfile += "CMakeLists.txt";
- target->AddSource(listfile);
}
}
}
@@ -494,10 +582,8 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
cmLocalGenerator* root, std::vector<cmLocalGenerator*> const& gens)
{
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());
+ for (auto gen : gens) {
+ cmAppend(lfiles, gen->GetMakefile()->GetListFiles());
}
// sort the array
@@ -505,36 +591,55 @@ void cmGlobalXCodeGenerator::CreateReRunCMakeFile(
std::vector<std::string>::iterator new_end =
std::unique(lfiles.begin(), lfiles.end());
lfiles.erase(new_end, lfiles.end());
+
+ cmake* cm = this->GetCMakeInstance();
+ if (cm->DoWriteGlobVerifyTarget()) {
+ lfiles.emplace_back(cm->GetGlobVerifyStamp());
+ }
+
this->CurrentReRunCMakeMakefile = root->GetCurrentBinaryDirectory();
this->CurrentReRunCMakeMakefile += "/CMakeScripts";
- cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile.c_str());
+ cmSystemTools::MakeDirectory(this->CurrentReRunCMakeMakefile);
this->CurrentReRunCMakeMakefile += "/ReRunCMake.make";
- cmGeneratedFileStream makefileStream(
- this->CurrentReRunCMakeMakefile.c_str());
+ cmGeneratedFileStream makefileStream(this->CurrentReRunCMakeMakefile);
makefileStream.SetCopyIfDifferent(true);
makefileStream << "# Generated by CMake, DO NOT EDIT\n\n";
+ makefileStream << "TARGETS:= \n";
makefileStream << "empty:= \n";
makefileStream << "space:= $(empty) $(empty)\n";
makefileStream << "spaceplus:= $(empty)\\ $(empty)\n\n";
- for (std::vector<std::string>::const_iterator i = lfiles.begin();
- i != lfiles.end(); ++i) {
+ for (const auto& lfile : lfiles) {
makefileStream << "TARGETS += $(subst $(space),$(spaceplus),$(wildcard "
- << this->ConvertToRelativeForMake(i->c_str()) << "))\n";
+ << this->ConvertToRelativeForMake(lfile) << "))\n";
}
+ makefileStream << "\n";
std::string checkCache = root->GetBinaryDirectory();
checkCache += "/";
- checkCache += cmake::GetCMakeFilesDirectoryPostSlash();
+ checkCache += "CMakeFiles/";
checkCache += "cmake.check_cache";
- makefileStream << "\n"
- << this->ConvertToRelativeForMake(checkCache.c_str())
+ if (cm->DoWriteGlobVerifyTarget()) {
+ makefileStream << ".NOTPARALLEL:\n\n";
+ makefileStream << ".PHONY: all VERIFY_GLOBS\n\n";
+ makefileStream << "all: VERIFY_GLOBS "
+ << this->ConvertToRelativeForMake(checkCache) << "\n\n";
+ makefileStream << "VERIFY_GLOBS:\n";
+ makefileStream << "\t"
+ << this->ConvertToRelativeForMake(
+ cmSystemTools::GetCMakeCommand())
+ << " -P "
+ << this->ConvertToRelativeForMake(cm->GetGlobVerifyScript())
+ << "\n\n";
+ }
+
+ makefileStream << this->ConvertToRelativeForMake(checkCache)
<< ": $(TARGETS)\n";
makefileStream << "\t"
<< this->ConvertToRelativeForMake(
- cmSystemTools::GetCMakeCommand().c_str())
+ cmSystemTools::GetCMakeCommand())
<< " -H"
<< this->ConvertToRelativeForMake(root->GetSourceDirectory())
<< " -B"
@@ -556,8 +661,8 @@ void cmGlobalXCodeGenerator::SortXCodeObjects()
void cmGlobalXCodeGenerator::ClearXCodeObjects()
{
this->TargetDoneSet.clear();
- for (unsigned int i = 0; i < this->XCodeObjects.size(); ++i) {
- delete this->XCodeObjects[i];
+ for (auto& obj : this->XCodeObjects) {
+ delete obj;
}
this->XCodeObjects.clear();
this->XCodeObjectIDs.clear();
@@ -571,7 +676,7 @@ void cmGlobalXCodeGenerator::ClearXCodeObjects()
void cmGlobalXCodeGenerator::addObject(cmXCodeObject* obj)
{
if (obj->GetType() == cmXCodeObject::OBJECT) {
- std::string id = obj->GetId();
+ const std::string& id = obj->GetId();
// If this is a duplicate id, it's an error:
//
@@ -649,9 +754,58 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath(
return buildFile;
}
+class XCodeGeneratorExpressionInterpreter
+ : public cmGeneratorExpressionInterpreter
+{
+public:
+ XCodeGeneratorExpressionInterpreter(cmSourceFile* sourceFile,
+ cmLocalGenerator* localGenerator,
+ cmGeneratorTarget* headTarget,
+ const std::string& lang)
+ : cmGeneratorExpressionInterpreter(
+ localGenerator, "NO-PER-CONFIG-SUPPORT-IN-XCODE", headTarget, lang)
+ , SourceFile(sourceFile)
+ {
+ }
+
+ XCodeGeneratorExpressionInterpreter(
+ XCodeGeneratorExpressionInterpreter const&) = delete;
+ XCodeGeneratorExpressionInterpreter& operator=(
+ XCodeGeneratorExpressionInterpreter const&) = delete;
+
+ using cmGeneratorExpressionInterpreter::Evaluate;
+
+ const std::string& Evaluate(const char* expression,
+ const std::string& property)
+ {
+ const std::string& processed =
+ this->cmGeneratorExpressionInterpreter::Evaluate(expression, property);
+ if (this->CompiledGeneratorExpression->GetHadContextSensitiveCondition()) {
+ std::ostringstream e;
+ /* clang-format off */
+ e <<
+ "Xcode does not support per-config per-source " << property << ":\n"
+ " " << expression << "\n"
+ "specified for source:\n"
+ " " << this->SourceFile->GetFullPath() << "\n";
+ /* clang-format on */
+ this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ }
+
+ return processed;
+ }
+
+private:
+ cmSourceFile* SourceFile = nullptr;
+};
+
cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
cmLocalGenerator* lg, cmSourceFile* sf, cmGeneratorTarget* gtgt)
{
+ std::string lang = this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
+
+ XCodeGeneratorExpressionInterpreter genexInterpreter(sf, lg, gtgt, lang);
+
// Add flags from target and source file properties.
std::string flags;
const char* srcfmt = sf->GetProperty("Fortran_FORMAT");
@@ -665,29 +819,25 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
default:
break;
}
- if (const char* cflags = sf->GetProperty("COMPILE_FLAGS")) {
- cmGeneratorExpression ge;
- std::string configName = "NO-PER-CONFIG-SUPPORT-IN-XCODE";
- CM_AUTO_PTR<cmCompiledGeneratorExpression> compiledExpr = ge.Parse(cflags);
- const char* processed = compiledExpr->Evaluate(lg, configName);
- if (compiledExpr->GetHadContextSensitiveCondition()) {
- std::ostringstream e;
- /* clang-format off */
- e <<
- "Xcode does not support per-config per-source COMPILE_FLAGS:\n"
- " " << cflags << "\n"
- "specified for source:\n"
- " " << sf->GetFullPath() << "\n";
- /* clang-format on */
- lg->IssueMessage(cmake::FATAL_ERROR, e.str());
- }
- lg->AppendFlags(flags, processed);
+ const std::string COMPILE_FLAGS("COMPILE_FLAGS");
+ if (const char* cflags = sf->GetProperty(COMPILE_FLAGS)) {
+ lg->AppendFlags(flags, genexInterpreter.Evaluate(cflags, COMPILE_FLAGS));
+ }
+ const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
+ if (const char* coptions = sf->GetProperty(COMPILE_OPTIONS)) {
+ lg->AppendCompileOptions(
+ flags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
}
// Add per-source definitions.
BuildObjectListOrString flagsBuild(this, false);
- this->AppendDefines(flagsBuild, sf->GetProperty("COMPILE_DEFINITIONS"),
- true);
+ const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
+ if (const char* compile_defs = sf->GetProperty(COMPILE_DEFINITIONS)) {
+ this->AppendDefines(
+ flagsBuild,
+ genexInterpreter.Evaluate(compile_defs, COMPILE_DEFINITIONS).c_str(),
+ true);
+ }
if (!flagsBuild.IsEmpty()) {
if (!flags.empty()) {
flags += ' ';
@@ -695,7 +845,15 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
flags += flagsBuild.GetString();
}
- std::string lang = this->CurrentLocalGenerator->GetSourceFileLanguage(*sf);
+ // Add per-source include directories.
+ std::vector<std::string> includes;
+ const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
+ if (const char* cincludes = sf->GetProperty(INCLUDE_DIRECTORIES)) {
+ lg->AppendIncludeDirectories(
+ includes, genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES),
+ *sf);
+ }
+ lg->AppendFlags(flags, lg->GetIncludeFlags(includes, gtgt, lang, true));
cmXCodeObject* buildFile =
this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), gtgt, lang, sf);
@@ -728,9 +886,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
cmSystemTools::ExpandListArgument(extraFileAttributes, attributes);
// Store the attributes.
- for (std::vector<std::string>::const_iterator ai = attributes.begin();
- ai != attributes.end(); ++ai) {
- attrs->AddObject(this->CreateString(*ai));
+ for (const auto& attribute : attributes) {
+ attrs->AddObject(this->CreateString(attribute));
}
}
@@ -740,6 +897,19 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(
return buildFile;
}
+void cmGlobalXCodeGenerator::AddXCodeProjBuildRule(
+ cmGeneratorTarget* target, std::vector<cmSourceFile*>& sources) const
+{
+ std::string listfile =
+ target->GetLocalGenerator()->GetCurrentSourceDirectory();
+ listfile += "/CMakeLists.txt";
+ cmSourceFile* srcCMakeLists = target->Makefile->GetOrCreateSource(listfile);
+ if (std::find(sources.begin(), sources.end(), srcCMakeLists) ==
+ sources.end()) {
+ sources.push_back(srcCMakeLists);
+ }
+}
+
std::string GetSourcecodeValueFromFileExtension(const std::string& _ext,
const std::string& lang,
bool& keepLastKnownFileType)
@@ -852,11 +1022,10 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath(
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 path = this->RelativeToSource(fullpath);
std::string name = cmSystemTools::GetFilenameName(path);
const char* sourceTree =
- (cmSystemTools::FileIsFullPath(path.c_str()) ? "<absolute>"
- : "SOURCE_ROOT");
+ cmSystemTools::FileIsFullPath(path) ? "<absolute>" : "SOURCE_ROOT";
fileRef->AddAttribute("name", this->CreateString(name));
fileRef->AddAttribute("path", this->CreateString(path));
fileRef->AddAttribute("sourceTree", this->CreateString(sourceTree));
@@ -895,7 +1064,7 @@ void cmGlobalXCodeGenerator::SetCurrentLocalGenerator(cmLocalGenerator* gen)
this->CurrentConfigurationTypes.clear();
this->CurrentMakefile->GetConfigurations(this->CurrentConfigurationTypes);
if (this->CurrentConfigurationTypes.empty()) {
- this->CurrentConfigurationTypes.push_back("");
+ this->CurrentConfigurationTypes.emplace_back();
}
}
@@ -909,15 +1078,17 @@ struct cmSourceFilePathCompare
struct cmCompareTargets
{
- bool operator()(std::string const& a, std::string const& b) const
+ bool operator()(cmXCodeObject* l, cmXCodeObject* r) const
{
+ std::string const& a = l->GetTarget()->GetName();
+ std::string const& b = r->GetTarget()->GetName();
if (a == "ALL_BUILD") {
return true;
}
if (b == "ALL_BUILD") {
return false;
}
- return strcmp(a.c_str(), b.c_str()) < 0;
+ return a < b;
}
};
@@ -925,298 +1096,279 @@ bool cmGlobalXCodeGenerator::CreateXCodeTargets(
cmLocalGenerator* gen, std::vector<cmXCodeObject*>& targets)
{
this->SetCurrentLocalGenerator(gen);
- std::vector<cmGeneratorTarget*> tgts =
+ std::vector<cmGeneratorTarget*> gts =
this->CurrentLocalGenerator->GetGeneratorTargets();
- typedef std::map<std::string, cmGeneratorTarget*, cmCompareTargets>
- cmSortedTargets;
- cmSortedTargets sortedTargets;
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); l++) {
- sortedTargets[(*l)->GetName()] = *l;
+ std::sort(gts.begin(), gts.end(),
+ [this](cmGeneratorTarget const* l, cmGeneratorTarget const* r) {
+ return this->TargetOrderIndex[l] < this->TargetOrderIndex[r];
+ });
+ for (auto gtgt : gts) {
+ if (!this->CreateXCodeTarget(gtgt, targets)) {
+ return false;
+ }
}
- for (cmSortedTargets::iterator l = sortedTargets.begin();
- l != sortedTargets.end(); l++) {
- cmGeneratorTarget* gtgt = l->second;
-
- std::string targetName = gtgt->GetName();
+ std::sort(targets.begin(), targets.end(), cmCompareTargets());
+ return true;
+}
- // make sure ALL_BUILD, INSTALL, etc are only done once
- if (this->SpecialTargetEmitted(targetName)) {
- continue;
- }
+bool cmGlobalXCodeGenerator::CreateXCodeTarget(
+ cmGeneratorTarget* gtgt, std::vector<cmXCodeObject*>& targets)
+{
+ std::string targetName = gtgt->GetName();
- if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
- continue;
- }
+ // make sure ALL_BUILD, INSTALL, etc are only done once
+ if (this->SpecialTargetEmitted(targetName)) {
+ return true;
+ }
- if (gtgt->GetType() == cmStateEnums::UTILITY ||
- gtgt->GetType() == cmStateEnums::GLOBAL_TARGET) {
- cmXCodeObject* t = this->CreateUtilityTarget(gtgt);
- if (!t) {
- return false;
- }
- targets.push_back(t);
- continue;
- }
+ if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ return true;
+ }
- // organize the sources
- std::vector<cmSourceFile*> classes;
- if (!gtgt->GetConfigCommonSourceFiles(classes)) {
+ if (gtgt->GetType() == cmStateEnums::UTILITY ||
+ gtgt->GetType() == cmStateEnums::GLOBAL_TARGET) {
+ cmXCodeObject* t = this->CreateUtilityTarget(gtgt);
+ if (!t) {
return false;
}
- std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare());
+ targets.push_back(t);
+ return true;
+ }
- gtgt->ComputeObjectMapping();
+ // organize the sources
+ std::vector<cmSourceFile*> classes;
+ if (!gtgt->GetConfigCommonSourceFiles(classes)) {
+ return false;
+ }
- 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, gtgt);
- cmXCodeObject* fr = xsf->GetObject("fileRef");
- cmXCodeObject* filetype = fr->GetObject()->GetObject("explicitFileType");
+ // Add CMakeLists.txt file for user convenience.
+ this->AddXCodeProjBuildRule(gtgt, classes);
- cmGeneratorTarget::SourceFileFlags tsFlags =
- gtgt->GetTargetSourceFileFlags(*i);
+ // Add the Info.plist we are about to generate for an App Bundle.
+ if (gtgt->GetPropertyAsBool("MACOSX_BUNDLE")) {
+ std::string plist = this->ComputeInfoPListLocation(gtgt);
+ cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(plist, true);
+ classes.push_back(sf);
+ }
- 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);
- }
- }
- }
+ std::sort(classes.begin(), classes.end(), cmSourceFilePathCompare());
- 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<cmSourceFile const*> objs;
- gtgt->GetExternalObjects(objs, "");
- for (std::vector<cmSourceFile const*>::const_iterator oi = objs.begin();
- oi != objs.end(); ++oi) {
- if ((*oi)->GetObjectLibrary().empty()) {
- continue;
- }
- std::string const& obj = (*oi)->GetFullPath();
- cmXCodeObject* xsf =
- this->CreateXCodeSourceFileFromPath(obj, gtgt, "", 0);
- externalObjFiles.push_back(xsf);
- }
- }
+ gtgt->ComputeObjectMapping();
- // some build phases only apply to bundles and/or frameworks
- bool isFrameworkTarget = gtgt->IsFrameworkOnApple();
- bool isBundleTarget = gtgt->GetPropertyAsBool("MACOSX_BUNDLE");
- bool isCFBundleTarget = gtgt->IsCFBundleOnApple();
+ std::vector<cmXCodeObject*> externalObjFiles;
+ std::vector<cmXCodeObject*> headerFiles;
+ std::vector<cmXCodeObject*> resourceFiles;
+ std::vector<cmXCodeObject*> sourceFiles;
+ for (auto sourceFile : classes) {
+ cmXCodeObject* xsf = this->CreateXCodeSourceFile(
+ this->CurrentLocalGenerator, sourceFile, gtgt);
+ cmXCodeObject* fr = xsf->GetObject("fileRef");
+ cmXCodeObject* filetype = fr->GetObject()->GetObject("explicitFileType");
- cmXCodeObject* buildFiles = 0;
+ cmGeneratorTarget::SourceFileFlags tsFlags =
+ gtgt->GetTargetSourceFileFlags(sourceFile);
- // 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);
+ if (filetype && filetype->GetString() == "compiled.mach-o.objfile") {
+ if (sourceFile->GetObjectLibrary().empty()) {
+ externalObjFiles.push_back(xsf);
+ }
+ } else if (this->IsHeaderFile(sourceFile) ||
+ (tsFlags.Type ==
+ cmGeneratorTarget::SourceFileTypePrivateHeader) ||
+ (tsFlags.Type ==
+ cmGeneratorTarget::SourceFileTypePublicHeader)) {
+ headerFiles.push_back(xsf);
+ } else if (tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource) {
+ resourceFiles.push_back(xsf);
+ } else if (!sourceFile->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(*sourceFile)
+ .empty() &&
+ !this->IgnoreFile(sourceFile->GetExtension().c_str())) {
+ sourceFiles.push_back(xsf);
}
- 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",
+ // some build phases only apply to bundles and/or frameworks
+ bool isFrameworkTarget = gtgt->IsFrameworkOnApple();
+ bool isBundleTarget = gtgt->GetPropertyAsBool("MACOSX_BUNDLE");
+ bool isCFBundleTarget = gtgt->IsCFBundleOnApple();
+
+ cmXCodeObject* buildFiles = nullptr;
+
+ // create source build phase
+ cmXCodeObject* sourceBuildPhase = nullptr;
+ if (!sourceFiles.empty()) {
+ sourceBuildPhase = this->CreateObject(cmXCodeObject::PBXSourcesBuildPhase);
+ sourceBuildPhase->SetComment("Sources");
+ sourceBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ for (auto& sourceFile : sourceFiles) {
+ buildFiles->AddObject(sourceFile);
+ }
+ sourceBuildPhase->AddAttribute("files", buildFiles);
+ sourceBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ }
+
+ // create header build phase - only for framework targets
+ cmXCodeObject* headerBuildPhase = nullptr;
+ 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 (auto& headerFile : headerFiles) {
+ buildFiles->AddObject(headerFile);
+ }
+ headerBuildPhase->AddAttribute("files", buildFiles);
+ headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ }
+
+ // create resource build phase - only for framework or bundle targets
+ cmXCodeObject* resourceBuildPhase = nullptr;
+ 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 = headerFiles.begin();
- i != headerFiles.end(); ++i) {
- buildFiles->AddObject(*i);
- }
- headerBuildPhase->AddAttribute("files", buildFiles);
- headerBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
- this->CreateString("0"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ for (auto& resourceFile : resourceFiles) {
+ buildFiles->AddObject(resourceFile);
}
+ resourceBuildPhase->AddAttribute("files", buildFiles);
+ resourceBuildPhase->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);
+ // 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 (auto sourceFile : classes) {
+ cmGeneratorTarget::SourceFileFlags tsFlags =
+ gtgt->GetTargetSourceFileFlags(sourceFile);
+ if (tsFlags.Type == cmGeneratorTarget::SourceFileTypeMacContent) {
+ bundleFiles[tsFlags.MacFolder].push_back(sourceFile);
}
- 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);
+ }
+ for (auto keySources : bundleFiles) {
+ cmXCodeObject* copyFilesBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
+ copyFilesBuildPhase->SetComment("Copy files");
+ copyFilesBuildPhase->AddAttribute("buildActionMask",
+ this->CreateString("2147483647"));
+ copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
+ this->CreateString("6"));
+ std::ostringstream ostr;
+ if (gtgt->IsFrameworkOnApple()) {
+ // dstPath in frameworks is relative to Versions/<version>
+ ostr << keySources.first;
+ } else if (keySources.first != "MacOS") {
+ if (gtgt->Target->GetMakefile()->PlatformIsAppleEmbedded()) {
+ ostr << keySources.first;
+ } else {
+ // dstPath in bundles is relative to Contents/MacOS
+ ostr << "../" << keySources.first;
}
}
- 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"));
- std::ostringstream ostr;
- if (gtgt->IsFrameworkOnApple()) {
- // dstPath in frameworks is relative to Versions/<version>
- ostr << mit->first;
- } else if (mit->first != "MacOS") {
- if (gtgt->Target->GetMakefile()->PlatformIsAppleIos()) {
- ostr << mit->first;
- } else {
- // dstPath in bundles is relative to Contents/MacOS
- ostr << "../" << mit->first;
- }
- }
- copyFilesBuildPhase->AddAttribute("dstPath",
- this->CreateString(ostr.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, gtgt);
- buildFiles->AddObject(xsf);
- }
- contentBuildPhases.push_back(copyFilesBuildPhase);
+ copyFilesBuildPhase->AddAttribute("dstPath",
+ this->CreateString(ostr.str()));
+ copyFilesBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ buildFiles = this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ copyFilesBuildPhase->AddAttribute("files", buildFiles);
+ for (auto sourceFile : keySources.second) {
+ cmXCodeObject* xsf = this->CreateXCodeSourceFile(
+ this->CurrentLocalGenerator, sourceFile, gtgt);
+ buildFiles->AddObject(xsf);
}
+ contentBuildPhases.push_back(copyFilesBuildPhase);
}
+ }
- // create vector of "resource content file" build phases - only for
- // framework or bundle targets
- 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::SourceFileTypeDeepResource) {
- 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("7"));
- copyFilesBuildPhase->AddAttribute("dstPath",
- this->CreateString(mit->first));
- 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, gtgt);
- buildFiles->AddObject(xsf);
- }
- contentBuildPhases.push_back(copyFilesBuildPhase);
+ // create vector of "resource content file" build phases - only for
+ // framework or bundle targets
+ if (isFrameworkTarget || isBundleTarget || isCFBundleTarget) {
+ typedef std::map<std::string, std::vector<cmSourceFile*>>
+ mapOfVectorOfSourceFiles;
+ mapOfVectorOfSourceFiles bundleFiles;
+ for (auto sourceFile : classes) {
+ cmGeneratorTarget::SourceFileFlags tsFlags =
+ gtgt->GetTargetSourceFileFlags(sourceFile);
+ if (tsFlags.Type == cmGeneratorTarget::SourceFileTypeDeepResource) {
+ bundleFiles[tsFlags.MacFolder].push_back(sourceFile);
}
}
-
- // create framework build phase
- cmXCodeObject* frameworkBuildPhase = 0;
- if (!externalObjFiles.empty()) {
- frameworkBuildPhase =
- this->CreateObject(cmXCodeObject::PBXFrameworksBuildPhase);
- frameworkBuildPhase->SetComment("Frameworks");
- frameworkBuildPhase->AddAttribute("buildActionMask",
+ for (auto keySources : bundleFiles) {
+ cmXCodeObject* copyFilesBuildPhase =
+ this->CreateObject(cmXCodeObject::PBXCopyFilesBuildPhase);
+ copyFilesBuildPhase->SetComment("Copy files");
+ copyFilesBuildPhase->AddAttribute("buildActionMask",
this->CreateString("2147483647"));
+ copyFilesBuildPhase->AddAttribute("dstSubfolderSpec",
+ this->CreateString("7"));
+ copyFilesBuildPhase->AddAttribute("dstPath",
+ this->CreateString(keySources.first));
+ copyFilesBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
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);
+ copyFilesBuildPhase->AddAttribute("files", buildFiles);
+ for (auto sourceFile : keySources.second) {
+ cmXCodeObject* xsf = this->CreateXCodeSourceFile(
+ this->CurrentLocalGenerator, sourceFile, gtgt);
+ buildFiles->AddObject(xsf);
}
- frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
- this->CreateString("0"));
+ contentBuildPhases.push_back(copyFilesBuildPhase);
}
+ }
- // create list of build phases and create the Xcode target
- cmXCodeObject* buildPhases =
- this->CreateObject(cmXCodeObject::OBJECT_LIST);
+ // create framework build phase
+ cmXCodeObject* frameworkBuildPhase = nullptr;
+ 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 (auto& externalObjFile : externalObjFiles) {
+ buildFiles->AddObject(externalObjFile);
+ }
+ frameworkBuildPhase->AddAttribute("runOnlyForDeploymentPostprocessing",
+ this->CreateString("0"));
+ }
- this->CreateCustomCommands(buildPhases, sourceBuildPhase, headerBuildPhase,
- resourceBuildPhase, contentBuildPhases,
- frameworkBuildPhase, gtgt);
+ // create list of build phases and create the Xcode target
+ cmXCodeObject* buildPhases = this->CreateObject(cmXCodeObject::OBJECT_LIST);
- targets.push_back(this->CreateXCodeTarget(gtgt, buildPhases));
- }
+ this->CreateCustomCommands(buildPhases, sourceBuildPhase, headerBuildPhase,
+ resourceBuildPhase, contentBuildPhases,
+ frameworkBuildPhase, gtgt);
+
+ targets.push_back(this->CreateXCodeTarget(gtgt, buildPhases));
return true;
}
void cmGlobalXCodeGenerator::ForceLinkerLanguages()
{
- for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
- std::vector<cmGeneratorTarget*> tgts =
- this->LocalGenerators[i]->GetGeneratorTargets();
+ for (auto localGenerator : this->LocalGenerators) {
// All targets depend on the build-system check target.
- for (std::vector<cmGeneratorTarget*>::const_iterator ti = tgts.begin();
- ti != tgts.end(); ++ti) {
+ for (auto tgt : localGenerator->GetGeneratorTargets()) {
// This makes sure all targets link using the proper language.
- this->ForceLinkerLanguage(*ti);
+ this->ForceLinkerLanguage(tgt);
}
}
}
@@ -1236,10 +1388,9 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt)
}
// If the language is compiled as a source trust Xcode to link with it.
- cmLinkImplementation const* impl = gtgt->GetLinkImplementation("NOCONFIG");
- for (std::vector<std::string>::const_iterator li = impl->Languages.begin();
- li != impl->Languages.end(); ++li) {
- if (*li == llang) {
+ for (auto const& Language :
+ gtgt->GetLinkImplementation("NOCONFIG")->Languages) {
+ if (Language == llang) {
return;
}
}
@@ -1249,14 +1400,14 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmGeneratorTarget* gtgt)
// language.
cmMakefile* mf = gtgt->Target->GetMakefile();
std::string fname = gtgt->GetLocalGenerator()->GetCurrentBinaryDirectory();
- fname += cmake::GetCMakeFilesDirectory();
+ fname += "/CMakeFiles";
fname += "/";
fname += gtgt->GetName();
fname += "-CMakeForceLinker";
fname += ".";
fname += cmSystemTools::LowerCase(llang);
{
- cmGeneratedFileStream fout(fname.c_str());
+ cmGeneratedFileStream fout(fname);
fout << "\n";
}
if (cmSourceFile* sf = mf->GetOrCreateSource(fname)) {
@@ -1277,8 +1428,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateBuildPhase(
const char* name, const char* name2, cmGeneratorTarget* target,
const std::vector<cmCustomCommand>& commands)
{
- if (commands.size() == 0 && strcmp(name, "CMake ReRun") != 0) {
- return 0;
+ if (commands.empty() && strcmp(name, "CMake ReRun") != 0) {
+ return nullptr;
}
cmXCodeObject* buildPhase =
this->CreateObject(cmXCodeObject::PBXShellScriptBuildPhase);
@@ -1338,10 +1489,9 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(
}
// 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());
+ for (auto sourceFile : classes) {
+ if (sourceFile->GetCustomCommand()) {
+ commands.push_back(*sourceFile->GetCustomCommand());
}
}
// create prebuild phase
@@ -1373,10 +1523,8 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(
if (resourceBuildPhase) {
buildPhases->AddObject(resourceBuildPhase);
}
- std::vector<cmXCodeObject*>::iterator cit;
- for (cit = contentBuildPhases.begin(); cit != contentBuildPhases.end();
- ++cit) {
- buildPhases->AddObject(*cit);
+ for (auto obj : contentBuildPhases) {
+ buildPhases->AddObject(obj);
}
if (sourceBuildPhase) {
buildPhases->AddObject(sourceBuildPhase);
@@ -1438,7 +1586,7 @@ std::string cmGlobalXCodeGenerator::ExtractFlagRegex(const char* exp,
std::string::size_type offset = 0;
- while (regex.find(flags.c_str() + offset)) {
+ while (regex.find(&flags[offset])) {
const std::string::size_type startPos = offset + regex.start(matchIndex);
const std::string::size_type endPos = offset + regex.end(matchIndex);
const std::string::size_type size = endPos - startPos;
@@ -1465,7 +1613,7 @@ void cmGlobalXCodeGenerator::FilterConfigurationAttribute(
return;
}
- std::string::size_type endVariant = attribute.find("]", beginVariant + 9);
+ std::string::size_type endVariant = attribute.find(']', beginVariant + 9);
if (endVariant == std::string::npos) {
// There is no terminating bracket.
return;
@@ -1491,7 +1639,7 @@ void cmGlobalXCodeGenerator::AddCommandsToBuildPhase(
{
std::string dir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory();
dir += "/CMakeScripts";
- cmSystemTools::MakeDirectory(dir.c_str());
+ cmSystemTools::MakeDirectory(dir);
std::string makefile = dir;
makefile += "/";
makefile += target->GetName();
@@ -1499,21 +1647,18 @@ void cmGlobalXCodeGenerator::AddCommandsToBuildPhase(
makefile += name;
makefile += ".make";
- for (std::vector<std::string>::const_iterator currentConfig =
- this->CurrentConfigurationTypes.begin();
- currentConfig != this->CurrentConfigurationTypes.end();
- currentConfig++) {
+ for (const auto& currentConfig : this->CurrentConfigurationTypes) {
this->CreateCustomRulesMakefile(makefile.c_str(), target, commands,
- *currentConfig);
+ currentConfig);
}
std::string cdir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory();
- cdir = this->ConvertToRelativeForMake(cdir.c_str());
+ cdir = this->ConvertToRelativeForMake(cdir);
std::string makecmd = "make -C ";
makecmd += cdir;
makecmd += " -f ";
- makecmd +=
- this->ConvertToRelativeForMake((makefile + "$CONFIGURATION").c_str());
+ makecmd += this->ConvertToRelativeForMake((makefile + "$CONFIGURATION"));
+ makecmd += " OBJDIR=$(basename \"$OBJECT_FILE_DIR_normal\")";
makecmd += " all";
buildphase->AddAttribute("shellScript", this->CreateString(makecmd));
buildphase->AddAttribute("showEnvVarsInLog", this->CreateString("0"));
@@ -1525,7 +1670,7 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
{
std::string makefileName = makefileBasename;
makefileName += configName;
- cmGeneratedFileStream makefileStream(makefileName.c_str());
+ cmGeneratedFileStream makefileStream(makefileName);
if (!makefileStream) {
return;
}
@@ -1541,38 +1686,35 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
makefileStream << "all: ";
std::map<const cmCustomCommand*, std::string> tname;
int count = 0;
- for (std::vector<cmCustomCommand>::const_iterator i = commands.begin();
- i != commands.end(); ++i) {
- cmCustomCommandGenerator ccg(*i, configName, this->CurrentLocalGenerator);
+ for (auto const& command : commands) {
+ cmCustomCommandGenerator ccg(command, configName,
+ this->CurrentLocalGenerator);
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());
+ for (auto const& output : outputs) {
+ makefileStream << "\\\n\t" << this->ConvertToRelativeForMake(output);
}
} else {
std::ostringstream str;
str << "_buildpart_" << count++;
- tname[&ccg.GetCC()] = std::string(target->GetName()) + str.str();
+ tname[&ccg.GetCC()] = 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->CurrentLocalGenerator);
+ for (auto const& command : commands) {
+ cmCustomCommandGenerator ccg(command, configName,
+ this->CurrentLocalGenerator);
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
const char* sep = "";
- for (std::vector<std::string>::const_iterator oi = outputs.begin();
- oi != outputs.end(); ++oi) {
- makefileStream << sep << this->ConvertToRelativeForMake(oi->c_str());
+ for (auto const& output : outputs) {
+ makefileStream << sep << this->ConvertToRelativeForMake(output);
sep = " ";
}
makefileStream << ": ";
@@ -1580,14 +1722,11 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
// 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) {
+ for (auto const& d : ccg.GetDepends()) {
std::string dep;
- if (this->CurrentLocalGenerator->GetRealDependency(*d, configName,
+ if (this->CurrentLocalGenerator->GetRealDependency(d, configName,
dep)) {
- makefileStream << "\\\n"
- << this->ConvertToRelativeForMake(dep.c_str());
+ makefileStream << "\\\n" << this->ConvertToRelativeForMake(dep);
}
}
makefileStream << "\n";
@@ -1604,12 +1743,12 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
// Build the command line in a single string.
std::string cmd2 = ccg.GetCommand(c);
cmSystemTools::ReplaceString(cmd2, "/./", "/");
- cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
+ cmd2 = this->ConvertToRelativeForMake(cmd2);
std::string cmd;
std::string wd = ccg.GetWorkingDirectory();
if (!wd.empty()) {
cmd += "cd ";
- cmd += this->ConvertToRelativeForMake(wd.c_str());
+ cmd += this->ConvertToRelativeForMake(wd);
cmd += " && ";
}
cmd += cmd2;
@@ -1620,6 +1759,26 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
}
}
+void cmGlobalXCodeGenerator::AddPositionIndependentLinkAttribute(
+ cmGeneratorTarget* target, cmXCodeObject* buildSettings,
+ const std::string& configName)
+{
+ // For now, only EXECUTABLE is concerned
+ if (target->GetType() != cmStateEnums::EXECUTABLE) {
+ return;
+ }
+
+ const char* PICValue = target->GetLinkPIEProperty(configName);
+ if (PICValue == nullptr) {
+ // POSITION_INDEPENDENT_CODE is not set
+ return;
+ }
+
+ buildSettings->AddAttribute(
+ "LD_NO_PIE",
+ this->CreateString(cmSystemTools::IsOn(PICValue) ? "NO" : "YES"));
+}
+
void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
cmXCodeObject* buildSettings,
const std::string& configName)
@@ -1639,15 +1798,17 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
std::set<std::string> languages;
gtgt->GetLanguages(languages, configName);
std::map<std::string, std::string> cflags;
- for (std::set<std::string>::iterator li = languages.begin();
- li != languages.end(); ++li) {
- std::string const& lang = *li;
+ for (auto const& lang : languages) {
std::string& flags = cflags[lang];
// Add language-specific flags.
this->CurrentLocalGenerator->AddLanguageFlags(flags, gtgt, lang,
configName);
+ if (gtgt->IsIPOEnabled(lang, configName)) {
+ this->CurrentLocalGenerator->AppendFeatureOptions(flags, lang, "IPO");
+ }
+
// Add shared-library flags if needed.
this->CurrentLocalGenerator->AddCMP0018Flags(flags, gtgt, lang,
configName);
@@ -1661,10 +1822,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
std::string llang = gtgt->GetLinkerLanguage(configName);
if (binary && llang.empty()) {
cmSystemTools::Error(
- "CMake can not determine linker language for target: ",
- gtgt->GetName().c_str());
+ "CMake can not determine linker language for target: " +
+ gtgt->GetName());
return;
}
+ std::string const& langForPreprocessor = llang;
if (gtgt->IsIPOEnabled(llang, configName)) {
const char* ltoValue =
@@ -1672,6 +1834,9 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
buildSettings->AddAttribute("LLVM_LTO", this->CreateString(ltoValue));
}
+ // Handle PIE linker configuration
+ this->AddPositionIndependentLinkAttribute(gtgt, buildSettings, configName);
+
// Add define flags
this->CurrentLocalGenerator->AppendFlags(
defFlags, this->CurrentMakefile->GetDefineFlags());
@@ -1680,12 +1845,15 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
BuildObjectListOrString ppDefs(this, true);
this->AppendDefines(
ppDefs, "CMAKE_INTDIR=\"$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)\"");
- if (const char* exportMacro = gtgt->GetExportMacro()) {
+ if (const std::string* exportMacro = gtgt->GetExportMacro()) {
// Add the export symbol definition for shared library objects.
- this->AppendDefines(ppDefs, exportMacro);
+ this->AppendDefines(ppDefs, exportMacro->c_str());
}
std::vector<std::string> targetDefines;
- gtgt->GetCompileDefinitions(targetDefines, configName, "C");
+ if (!langForPreprocessor.empty()) {
+ gtgt->GetCompileDefinitions(targetDefines, configName,
+ langForPreprocessor);
+ }
this->AppendDefines(ppDefs, targetDefines);
buildSettings->AddAttribute("GCC_PREPROCESSOR_DEFINITIONS",
ppDefs.CreateList());
@@ -1707,7 +1875,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
if (gtgt->GetType() == cmStateEnums::OBJECT_LIBRARY ||
gtgt->GetType() == cmStateEnums::STATIC_LIBRARY) {
this->CurrentLocalGenerator->GetStaticLibraryFlags(
- extraLinkOptions, cmSystemTools::UpperCase(configName), gtgt);
+ extraLinkOptions, cmSystemTools::UpperCase(configName), llang, gtgt);
} else {
const char* targetLinkFlags = gtgt->GetProperty("LINK_FLAGS");
if (targetLinkFlags) {
@@ -1721,6 +1889,10 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
this->CurrentLocalGenerator->AppendFlags(extraLinkOptions, linkFlags);
}
}
+ std::vector<std::string> opts;
+ gtgt->GetLinkOptions(opts, configName, llang);
+ // LINK_OPTIONS are escaped.
+ this->CurrentLocalGenerator->AppendCompileOptions(extraLinkOptions, opts);
}
// Set target-specific architectures.
@@ -1737,9 +1909,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
} 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));
+ for (auto& arch : archs) {
+ archObjects->AddObject(this->CreateString(arch));
}
buildSettings->AddAttribute("ARCHS", archObjects);
}
@@ -1754,8 +1925,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
const char* version = gtgt->GetProperty("VERSION");
const char* soversion = gtgt->GetProperty("SOVERSION");
if (!gtgt->HasSOName(configName) || gtgt->IsFrameworkOnApple()) {
- version = 0;
- soversion = 0;
+ version = nullptr;
+ soversion = nullptr;
}
if (version && !soversion) {
soversion = version;
@@ -1799,8 +1970,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
pnbase = gtgt->GetName();
pnsuffix = ".a";
- std::string pncdir =
- this->GetObjectsNormalDirectory(this->CurrentProject, configName, gtgt);
+ std::string pncdir = this->GetObjectsDirectory(
+ this->CurrentProject, configName, gtgt, OBJECT_LIBRARY_ARTIFACT_DIR);
buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR",
this->CreateString(pncdir));
}
@@ -1827,7 +1998,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// so let it replace the framework name. This avoids creating
// a per-configuration Info.plist file.
this->CurrentLocalGenerator->GenerateFrameworkInfoPList(
- gtgt, "$(EXECUTABLE_NAME)", plist.c_str());
+ gtgt, "$(EXECUTABLE_NAME)", plist);
buildSettings->AddAttribute("INFOPLIST_FILE",
this->CreateString(plist));
buildSettings->AddAttribute("MACH_O_TYPE",
@@ -1868,7 +2039,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// a per-configuration Info.plist file. The cfbundle plist
// is very similar to the application bundle plist
this->CurrentLocalGenerator->GenerateAppleInfoPList(
- gtgt, "$(EXECUTABLE_NAME)", plist.c_str());
+ gtgt, "$(EXECUTABLE_NAME)", plist);
buildSettings->AddAttribute("INFOPLIST_FILE",
this->CreateString(plist));
} else {
@@ -1902,7 +2073,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// so let it replace the framework name. This avoids creating
// a per-configuration Info.plist file.
this->CurrentLocalGenerator->GenerateFrameworkInfoPList(
- gtgt, "$(EXECUTABLE_NAME)", plist.c_str());
+ gtgt, "$(EXECUTABLE_NAME)", plist);
buildSettings->AddAttribute("INFOPLIST_FILE",
this->CreateString(plist));
} else {
@@ -1940,7 +2111,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// so let it replace the executable name. This avoids creating
// a per-configuration Info.plist file.
this->CurrentLocalGenerator->GenerateAppleInfoPList(
- gtgt, "$(EXECUTABLE_NAME)", plist.c_str());
+ gtgt, "$(EXECUTABLE_NAME)", plist);
buildSettings->AddAttribute("INFOPLIST_FILE",
this->CreateString(plist));
}
@@ -1948,9 +2119,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
default:
break;
}
- if (this->XcodeVersion < 40) {
- buildSettings->AddAttribute("PREBINDING", this->CreateString("NO"));
- }
BuildObjectListOrString dirs(this, true);
BuildObjectListOrString fdirs(this, true);
@@ -1959,30 +2127,33 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
const bool emitSystemIncludes = this->XcodeVersion >= 83;
std::vector<std::string> includes;
- this->CurrentLocalGenerator->GetIncludeDirectories(includes, gtgt, "C",
- configName);
+ if (!langForPreprocessor.empty()) {
+ this->CurrentLocalGenerator->GetIncludeDirectories(
+ includes, gtgt, langForPreprocessor, 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)) {
- std::string frameworkDir = *i;
+ for (auto& include : includes) {
+ if (this->NameResolvesToFramework(include)) {
+ std::string frameworkDir = include;
frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
if (emitted.insert(frameworkDir).second) {
std::string incpath = this->XCodeEscapePath(frameworkDir);
if (emitSystemIncludes &&
- gtgt->IsSystemIncludeDirectory(frameworkDir, configName)) {
+ gtgt->IsSystemIncludeDirectory(frameworkDir, configName,
+ langForPreprocessor)) {
sysfdirs.Add(incpath);
} else {
fdirs.Add(incpath);
}
}
} else {
- std::string incpath = this->XCodeEscapePath(*i);
+ std::string incpath = this->XCodeEscapePath(include);
if (emitSystemIncludes &&
- gtgt->IsSystemIncludeDirectory(*i, configName)) {
+ gtgt->IsSystemIncludeDirectory(include, configName,
+ langForPreprocessor)) {
sysdirs.Add(incpath);
} else {
dirs.Add(incpath);
@@ -1991,13 +2162,12 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
}
// Add framework search paths needed for linking.
if (cmComputeLinkInformation* cli = gtgt->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) {
- std::string incpath = this->XCodeEscapePath(*fdi);
+ for (auto const& fwDir : cli->GetFrameworkPaths()) {
+ if (emitted.insert(fwDir).second) {
+ std::string incpath = this->XCodeEscapePath(fwDir);
if (emitSystemIncludes &&
- gtgt->IsSystemIncludeDirectory(*fdi, configName)) {
+ gtgt->IsSystemIncludeDirectory(fwDir, configName,
+ langForPreprocessor)) {
sysfdirs.Add(incpath);
} else {
fdirs.Add(incpath);
@@ -2025,27 +2195,25 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// system include directory awareness. We need to also keep on setting
// HEADER_SEARCH_PATHS to work around a missing compile options flag for
// GNU assembly files (#16449)
- for (std::set<std::string>::iterator li = languages.begin();
- li != languages.end(); ++li) {
+ for (auto const& language : languages) {
std::string includeFlags = this->CurrentLocalGenerator->GetIncludeFlags(
- includes, gtgt, *li, true, false, configName);
+ includes, gtgt, language, true, false, configName);
if (!includeFlags.empty()) {
- cflags[*li] += " " + includeFlags;
+ cflags[language] += " " + includeFlags;
}
}
}
bool same_gflags = true;
std::map<std::string, std::string> gflags;
- std::string const* last_gflag = 0;
+ std::string const* last_gflag = nullptr;
std::string optLevel = "0";
// Minimal map of flags to build settings.
- for (std::set<std::string>::iterator li = languages.begin();
- li != languages.end(); ++li) {
- std::string& flags = cflags[*li];
- std::string& gflag = gflags[*li];
+ for (auto const& language : languages) {
+ std::string& flags = cflags[language];
+ std::string& gflag = gflags[language];
std::string oflag =
this->ExtractFlagRegex("(^| )(-Ofast|-Os|-O[0-9]*)( |$)", 2, flags);
if (oflag.size() == 2) {
@@ -2070,16 +2238,31 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
if (!same_gflags) {
// We can't set the Xcode flag differently depending on the language,
// so put them back in this case.
- for (std::set<std::string>::iterator li = languages.begin();
- li != languages.end(); ++li) {
- cflags[*li] += " ";
- cflags[*li] += gflags[*li];
+ for (auto const& language : languages) {
+ cflags[language] += " ";
+ cflags[language] += gflags[language];
}
debugStr = "NO";
} else if (last_gflag && (last_gflag->empty() || *last_gflag == "-g0")) {
debugStr = "NO";
}
+ // extract C++ stdlib
+ for (auto const& language : languages) {
+ if (language != "CXX") {
+ continue;
+ }
+ std::string& flags = cflags[language];
+
+ auto stdlib =
+ this->ExtractFlagRegex("(^| )(-stdlib=[^ ]+)( |$)", 2, flags);
+ if (stdlib.size() > 8) {
+ const auto cxxLibrary = stdlib.substr(8);
+ buildSettings->AddAttribute("CLANG_CXX_LIBRARY",
+ this->CreateString(cxxLibrary));
+ }
+ }
+
buildSettings->AddAttribute("COMBINE_HIDPI_IMAGES",
this->CreateString("YES"));
buildSettings->AddAttribute("GCC_GENERATE_DEBUGGING_SYMBOLS",
@@ -2090,25 +2273,24 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
this->CreateString("NO"));
buildSettings->AddAttribute("GCC_INLINES_ARE_PRIVATE_EXTERN",
this->CreateString("NO"));
- for (std::set<std::string>::iterator li = languages.begin();
- li != languages.end(); ++li) {
- std::string flags = cflags[*li] + " " + defFlags;
- if (*li == "CXX") {
+ for (auto const& language : languages) {
+ std::string flags = cflags[language] + " " + defFlags;
+ if (language == "CXX") {
buildSettings->AddAttribute("OTHER_CPLUSPLUSFLAGS",
this->CreateString(flags));
- } else if (*li == "Fortran") {
+ } else if (language == "Fortran") {
buildSettings->AddAttribute("IFORT_OTHER_FLAGS",
this->CreateString(flags));
- } else if (*li == "C") {
+ } else if (language == "C") {
buildSettings->AddAttribute("OTHER_CFLAGS", this->CreateString(flags));
- } else if (*li == "Swift") {
+ } else if (language == "Swift") {
buildSettings->AddAttribute("OTHER_SWIFT_FLAGS",
this->CreateString(flags));
}
}
// Add Fortran source format attribute if property is set.
- const char* format = 0;
+ const char* format = nullptr;
const char* tgtfmt = gtgt->GetProperty("Fortran_FORMAT");
switch (cmOutputConverter::GetFortranFormat(tgtfmt)) {
case cmOutputConverter::FortranFormatFixed:
@@ -2162,9 +2344,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// 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;
+ for (auto runpath : runtimeDirs) {
runpath = this->ExpandCFGIntDir(runpath, configName);
if (unique_dirs.find(runpath) == unique_dirs.end()) {
@@ -2224,16 +2404,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt,
// put this last so it can override existing settings
// Convert "XCODE_ATTRIBUTE_*" properties directly.
{
- std::vector<std::string> const& props = gtgt->GetPropertyKeys();
- for (std::vector<std::string>::const_iterator i = props.begin();
- i != props.end(); ++i) {
- if (i->find("XCODE_ATTRIBUTE_") == 0) {
- std::string attribute = i->substr(16);
+ for (auto const& prop : gtgt->GetPropertyKeys()) {
+ if (prop.find("XCODE_ATTRIBUTE_") == 0) {
+ std::string attribute = prop.substr(16);
this->FilterConfigurationAttribute(configName, attribute);
if (!attribute.empty()) {
cmGeneratorExpression ge;
std::string processed =
- ge.Parse(gtgt->GetProperty(*i))
+ ge.Parse(gtgt->GetProperty(prop))
->Evaluate(this->CurrentLocalGenerator, configName);
buildSettings->AddAttribute(attribute,
this->CreateString(processed));
@@ -2268,8 +2446,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget(
target->SetComment(gtgt->GetName());
cmXCodeObject* buildPhases = this->CreateObject(cmXCodeObject::OBJECT_LIST);
std::vector<cmXCodeObject*> emptyContentVector;
- this->CreateCustomCommands(buildPhases, 0, 0, 0, emptyContentVector, 0,
- gtgt);
+ this->CreateCustomCommands(buildPhases, nullptr, nullptr, nullptr,
+ emptyContentVector, nullptr, gtgt);
target->AddAttribute("buildPhases", buildPhases);
this->AddConfigurations(target, gtgt);
cmXCodeObject* dependencies = this->CreateObject(cmXCodeObject::OBJECT_LIST);
@@ -2280,16 +2458,19 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget(
this->XCodeObjectMap[gtgt] = target;
// Add source files without build rules for editing convenience.
- if (gtgt->GetType() == cmStateEnums::UTILITY) {
+ if (gtgt->GetType() == cmStateEnums::UTILITY &&
+ gtgt->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
std::vector<cmSourceFile*> sources;
if (!gtgt->GetConfigCommonSourceFiles(sources)) {
- return 0;
+ return nullptr;
}
- for (std::vector<cmSourceFile*>::const_iterator i = sources.begin();
- i != sources.end(); ++i) {
- if (!(*i)->GetPropertyAsBool("GENERATED")) {
- this->CreateXCodeFileReference(*i, gtgt);
+ // Add CMakeLists.txt file for user convenience.
+ this->AddXCodeProjBuildRule(gtgt, sources);
+
+ for (auto sourceFile : sources) {
+ if (!sourceFile->GetIsGenerated()) {
+ this->CreateXCodeFileReference(sourceFile, gtgt);
}
}
}
@@ -2302,12 +2483,10 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateUtilityTarget(
std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
cmGeneratorTarget* gtgt)
{
- 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);
+ std::vector<std::string> const configVector =
+ cmSystemTools::ExpandedListArgument(
+ this->CurrentMakefile->GetRequiredDefinition(
+ "CMAKE_CONFIGURATION_TYPES"));
cmXCodeObject* configlist =
this->CreateObject(cmXCodeObject::XCConfigurationList);
cmXCodeObject* buildConfigurations =
@@ -2321,15 +2500,15 @@ std::string cmGlobalXCodeGenerator::AddConfigurations(cmXCodeObject* target,
configlist->SetComment(comment);
target->AddAttribute("buildConfigurationList",
this->CreateObjectReference(configlist));
- for (unsigned int i = 0; i < configVector.size(); ++i) {
+ for (auto const& i : configVector) {
cmXCodeObject* config =
this->CreateObject(cmXCodeObject::XCBuildConfiguration);
buildConfigurations->AddObject(config);
cmXCodeObject* buildSettings =
this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
- this->CreateBuildSettings(gtgt, buildSettings, configVector[i]);
- config->AddAttribute("name", this->CreateString(configVector[i]));
- config->SetComment(configVector[i]);
+ this->CreateBuildSettings(gtgt, buildSettings, i);
+ config->AddAttribute("name", this->CreateString(i));
+ config->SetComment(i);
config->AddAttribute("buildSettings", buildSettings);
}
if (!configVector.empty()) {
@@ -2349,9 +2528,8 @@ const char* cmGlobalXCodeGenerator::GetTargetLinkFlagsVar(
(target->GetType() == cmStateEnums::STATIC_LIBRARY ||
target->GetType() == cmStateEnums::OBJECT_LIBRARY)) {
return "OTHER_LIBTOOLFLAGS";
- } else {
- return "OTHER_LDFLAGS";
}
+ return "OTHER_LDFLAGS";
}
const char* cmGlobalXCodeGenerator::GetTargetFileType(
@@ -2368,12 +2546,13 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType(
return (target->GetPropertyAsBool("FRAMEWORK") ? "wrapper.framework"
: "archive.ar");
case cmStateEnums::MODULE_LIBRARY:
- if (target->IsXCTestOnApple())
+ if (target->IsXCTestOnApple()) {
return "wrapper.cfbundle";
- else if (target->IsCFBundleOnApple())
+ }
+ if (target->IsCFBundleOnApple()) {
return "wrapper.plug-in";
- else
- return "compiled.mach-o.executable";
+ }
+ return "compiled.mach-o.executable";
case cmStateEnums::SHARED_LIBRARY:
return (target->GetPropertyAsBool("FRAMEWORK")
? "wrapper.framework"
@@ -2383,7 +2562,7 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType(
default:
break;
}
- return 0;
+ return nullptr;
}
const char* cmGlobalXCodeGenerator::GetTargetProductType(
@@ -2401,12 +2580,13 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType(
? "com.apple.product-type.framework"
: "com.apple.product-type.library.static");
case cmStateEnums::MODULE_LIBRARY:
- if (target->IsXCTestOnApple())
+ if (target->IsXCTestOnApple()) {
return "com.apple.product-type.bundle.unit-test";
- else if (target->IsCFBundleOnApple())
+ } else if (target->IsCFBundleOnApple()) {
return "com.apple.product-type.bundle";
- else
+ } else {
return "com.apple.product-type.tool";
+ }
case cmStateEnums::SHARED_LIBRARY:
return (target->GetPropertyAsBool("FRAMEWORK")
? "com.apple.product-type.framework"
@@ -2418,14 +2598,14 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType(
default:
break;
}
- return 0;
+ return nullptr;
}
cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeTarget(
cmGeneratorTarget* gtgt, cmXCodeObject* buildPhases)
{
if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
- return 0;
+ return nullptr;
}
cmXCodeObject* target = this->CreateObject(cmXCodeObject::PBXNativeTarget);
target->AddAttribute("buildPhases", buildPhases);
@@ -2469,13 +2649,13 @@ cmXCodeObject* cmGlobalXCodeGenerator::FindXCodeTarget(
cmGeneratorTarget const* t)
{
if (!t) {
- return 0;
+ return nullptr;
}
std::map<cmGeneratorTarget const*, cmXCodeObject*>::const_iterator const i =
this->XCodeObjectMap.find(t);
if (i == this->XCodeObjectMap.end()) {
- return 0;
+ return nullptr;
}
return i->second;
}
@@ -2557,18 +2737,10 @@ void cmGlobalXCodeGenerator::AppendBuildSettingAttribute(
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");
+ for (auto obj : buildConfigs->GetObjectList()) {
+ if (configName.empty() ||
+ obj->GetObject("name")->GetString() == configName) {
+ cmXCodeObject* settings = obj->GetObject("buildSettings");
this->AppendOrAddBuildSetting(settings, attribute, value);
}
}
@@ -2586,35 +2758,27 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
}
// Add dependencies on other CMake targets.
- TargetDependSet const& deps = this->GetTargetDirectDepends(gt);
- for (TargetDependSet::const_iterator i = deps.begin(); i != deps.end();
- ++i) {
- if (cmXCodeObject* dptarget = this->FindXCodeTarget(*i)) {
+ for (const auto& dep : this->GetTargetDirectDepends(gt)) {
+ if (cmXCodeObject* dptarget = this->FindXCodeTarget(dep)) {
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) {
+ for (auto const& configName : this->CurrentConfigurationTypes) {
+ {
// Add object library contents as link flags.
std::string linkObjs;
const char* sep = "";
std::vector<cmSourceFile const*> objs;
gt->GetExternalObjects(objs, configName);
- for (std::vector<cmSourceFile const*>::const_iterator oi = objs.begin();
- oi != objs.end(); ++oi) {
- if ((*oi)->GetObjectLibrary().empty()) {
+ for (auto sourceFile : objs) {
+ if (sourceFile->GetObjectLibrary().empty()) {
continue;
}
linkObjs += sep;
sep = " ";
- linkObjs += this->XCodeEscapePath((*oi)->GetFullPath());
+ linkObjs += this->XCodeEscapePath(sourceFile->GetFullPath());
}
this->AppendBuildSettingAttribute(
target, this->GetTargetLinkFlagsVar(gt), linkObjs.c_str(), configName);
@@ -2634,28 +2798,22 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
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);
- }
+ for (auto const& libDep : cli.GetDepends()) {
+ target->AddDependLibrary(configName, libDep);
}
// 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") {
+ for (auto const& libDir : cli.GetDirectories()) {
+ if (!libDir.empty() && libDir != "/usr/lib") {
// Now add the same one but append
// $(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) to it:
linkDirs += " ";
linkDirs += this->XCodeEscapePath(
- *libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)");
+ libDir + "/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)");
linkDirs += " ";
- linkDirs += this->XCodeEscapePath(*libDir);
+ linkDirs += this->XCodeEscapePath(libDir);
}
}
this->AppendBuildSettingAttribute(target, "LIBRARY_SEARCH_PATHS",
@@ -2666,20 +2824,18 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
{
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) {
+ for (auto const& libName : cli.GetItems()) {
linkLibs += sep;
sep = " ";
- if (li->IsPath) {
- linkLibs += this->XCodeEscapePath(li->Value);
- } else if (!li->Target ||
- li->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
- linkLibs += li->Value;
+ if (libName.IsPath) {
+ linkLibs += this->XCodeEscapePath(libName.Value);
+ } else if (!libName.Target ||
+ libName.Target->GetType() !=
+ cmStateEnums::INTERFACE_LIBRARY) {
+ linkLibs += libName.Value;
}
- if (li->Target && !li->Target->IsImported()) {
- target->AddDependTarget(configName, li->Target->GetName());
+ if (libName.Target && !libName.Target->IsImported()) {
+ target->AddDependTarget(configName, libName.Target->GetName());
}
}
this->AppendBuildSettingAttribute(
@@ -2691,17 +2847,12 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
bool cmGlobalXCodeGenerator::CreateGroups(
std::vector<cmLocalGenerator*>& generators)
{
- for (std::vector<cmLocalGenerator*>::iterator i = generators.begin();
- i != generators.end(); ++i) {
- cmMakefile* mf = (*i)->GetMakefile();
+ for (auto& generator : generators) {
+ cmMakefile* mf = generator->GetMakefile();
std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
- std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); l++) {
- cmGeneratorTarget* gtgt = *l;
-
+ for (auto gtgt : generator->GetGeneratorTargets()) {
// Same skipping logic here as in CreateXCodeTargets so that we do not
- // end up with (empty anyhow) ALL_BUILD and XCODE_DEPEND_HELPER source
+ // end up with (empty anyhow) ZERO_CHECK, install, or test source
// groups:
//
if (gtgt->GetType() == cmStateEnums::GLOBAL_TARGET) {
@@ -2710,34 +2861,42 @@ bool cmGlobalXCodeGenerator::CreateGroups(
if (gtgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
-
- // add the soon to be generated Info.plist file as a source for a
- // MACOSX_BUNDLE file
- if (gtgt->GetPropertyAsBool("MACOSX_BUNDLE")) {
- std::string plist = this->ComputeInfoPListLocation(gtgt);
- mf->GetOrCreateSource(plist, true);
- gtgt->AddSource(plist);
+ if (gtgt->GetName() == CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
+ continue;
}
- std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
- gtgt->GetAllConfigSources();
+ auto addSourceToGroup = [this, mf, gtgt,
+ &sourceGroups](std::string const& source) {
+ cmSourceGroup* sourceGroup = mf->FindSourceGroup(source, sourceGroups);
+ cmXCodeObject* pbxgroup = this->CreateOrGetPBXGroup(gtgt, sourceGroup);
+ std::string key = GetGroupMapKeyFromPath(gtgt, source);
+ this->GroupMap[key] = pbxgroup;
+ };
// Put cmSourceFile instances in proper groups:
- for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si =
- sources.begin();
- si != sources.end(); ++si) {
- cmSourceFile const* sf = si->Source;
- if (this->XcodeVersion >= 50 && !sf->GetObjectLibrary().empty()) {
+ for (auto const& si : gtgt->GetAllConfigSources()) {
+ cmSourceFile const* sf = si.Source;
+ if (!sf->GetObjectLibrary().empty()) {
// Object library files go on the link line instead.
continue;
}
- // 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(gtgt, sourceGroup);
- std::string key = GetGroupMapKeyFromPath(gtgt, source);
- this->GroupMap[key] = pbxgroup;
+ addSourceToGroup(sf->GetFullPath());
+ }
+
+ // Add CMakeLists.txt file for user convenience.
+ {
+ std::string listfile =
+ gtgt->GetLocalGenerator()->GetCurrentSourceDirectory();
+ listfile += "/CMakeLists.txt";
+ cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(listfile);
+ addSourceToGroup(sf->GetFullPath());
+ }
+
+ // Add the Info.plist we are about to generate for an App Bundle.
+ if (gtgt->GetPropertyAsBool("MACOSX_BUNDLE")) {
+ std::string plist = this->ComputeInfoPListLocation(gtgt);
+ cmSourceFile* sf = gtgt->Makefile->GetOrCreateSource(plist, true);
+ addSourceToGroup(sf->GetFullPath());
}
}
}
@@ -2745,19 +2904,21 @@ bool cmGlobalXCodeGenerator::CreateGroups(
}
cmXCodeObject* cmGlobalXCodeGenerator::CreatePBXGroup(cmXCodeObject* parent,
- std::string name)
+ const std::string& name)
{
- cmXCodeObject* parentChildren = NULL;
- if (parent)
+ cmXCodeObject* parentChildren = nullptr;
+ 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));
group->AddAttribute("children", groupChildren);
group->AddAttribute("sourceTree", this->CreateString("<group>"));
- if (parentChildren)
+ if (parentChildren) {
parentChildren->AddObject(group);
+ }
return group;
}
@@ -2781,7 +2942,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(
}
it = this->TargetGroup.find(target);
- cmXCodeObject* tgroup = 0;
+ cmXCodeObject* tgroup = nullptr;
if (it != this->TargetGroup.end()) {
tgroup = it->second;
} else {
@@ -2811,24 +2972,23 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateOrGetPBXGroup(
// If it's the default source group (empty name) then put the source file
// directly in the tgroup...
//
- if (std::string(sg->GetFullName()) == "") {
+ if (sg->GetFullName().empty()) {
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(), "\\");
+ if (sg->GetFullName() != sg->GetName()) {
std::string curr_folder = target;
curr_folder += "/";
- for (std::vector<std::string>::size_type i = 0; i < folders.size(); i++) {
- curr_folder += folders[i];
+ for (auto const& folder :
+ cmSystemTools::tokenize(sg->GetFullName(), "\\")) {
+ curr_folder += folder;
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]);
+ cmXCodeObject* group = this->CreatePBXGroup(tgroup, folder);
this->GroupNameMap[curr_folder] = group;
tgroup = group;
} else {
@@ -2847,15 +3007,16 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
{
this->ClearXCodeObjects();
- this->RootObject = 0;
- this->MainGroupChildren = 0;
+ this->RootObject = nullptr;
+ this->MainGroupChildren = nullptr;
cmXCodeObject* group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
group->AddAttribute("COPY_PHASE_STRIP", this->CreateString("NO"));
cmXCodeObject* listObjs = this->CreateObject(cmXCodeObject::OBJECT_LIST);
- for (unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i) {
+ for (const std::string& CurrentConfigurationType :
+ this->CurrentConfigurationTypes) {
cmXCodeObject* buildStyle =
this->CreateObject(cmXCodeObject::PBXBuildStyle);
- const char* name = this->CurrentConfigurationTypes[i].c_str();
+ const std::string& name = CurrentConfigurationType;
buildStyle->AddAttribute("name", this->CreateString(name));
buildStyle->SetComment(name);
cmXCodeObject* sgroup = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
@@ -2888,7 +3049,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
std::string project_id = "PROJECT_";
project_id += root->GetProjectName();
this->RootObject->SetId(
- this->GetOrCreateId(project_id.c_str(), this->RootObject->GetId()));
+ this->GetOrCreateId(project_id, this->RootObject->GetId()));
group = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
this->RootObject->AddAttribute("mainGroup",
@@ -2904,15 +3065,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
v << std::setfill('0') << std::setw(4) << XcodeVersion * 10;
group->AddAttribute("LastUpgradeCheck", this->CreateString(v.str()));
this->RootObject->AddAttribute("attributes", group);
- if (this->XcodeVersion >= 32)
- this->RootObject->AddAttribute("compatibilityVersion",
- 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"));
+ this->RootObject->AddAttribute("compatibilityVersion",
+ this->CreateString("Xcode 3.2"));
// Point Xcode at the top of the source tree.
{
std::string pdir =
@@ -2924,12 +3078,11 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
this->CreateObject(cmXCodeObject::XCConfigurationList);
cmXCodeObject* buildConfigurations =
this->CreateObject(cmXCodeObject::OBJECT_LIST);
- typedef std::vector<std::pair<std::string, cmXCodeObject*> > Configs;
+ typedef std::vector<std::pair<std::string, cmXCodeObject*>> Configs;
Configs configs;
- const char* defaultConfigName = "Debug";
- for (unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i) {
- const char* name = this->CurrentConfigurationTypes[i].c_str();
- if (0 == i) {
+ std::string defaultConfigName;
+ for (const auto& name : this->CurrentConfigurationTypes) {
+ if (defaultConfigName.empty()) {
defaultConfigName = name;
}
cmXCodeObject* config =
@@ -2937,8 +3090,11 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
config->AddAttribute("name", this->CreateString(name));
configs.push_back(std::make_pair(name, config));
}
- for (Configs::iterator c = configs.begin(); c != configs.end(); ++c) {
- buildConfigurations->AddObject(c->second);
+ if (defaultConfigName.empty()) {
+ defaultConfigName = "Debug";
+ }
+ for (auto& config : configs) {
+ buildConfigurations->AddObject(config.second);
}
configlist->AddAttribute("buildConfigurations", buildConfigurations);
@@ -2971,7 +3127,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
buildSettings->AddAttribute("ARCHS", this->CreateString(archs));
}
if (deploymentTarget && *deploymentTarget) {
- buildSettings->AddAttribute("MACOSX_DEPLOYMENT_TARGET",
+ buildSettings->AddAttribute(GetDeploymentPlatform(root->GetMakefile()),
this->CreateString(deploymentTarget));
}
if (!this->GeneratorToolset.empty()) {
@@ -2983,6 +3139,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
if (const char* vers = this->CurrentMakefile->GetDefinition(
"CMAKE_Swift_LANGUAGE_VERSION")) {
swiftVersion = vers;
+ } else if (this->XcodeVersion >= 102) {
+ swiftVersion = "4.0";
} else if (this->XcodeVersion >= 83) {
swiftVersion = "3.0";
} else {
@@ -2996,53 +3154,46 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
symroot += "/build";
buildSettings->AddAttribute("SYMROOT", this->CreateString(symroot));
- for (Configs::iterator i = configs.begin(); i != configs.end(); ++i) {
+ for (auto& config : configs) {
cmXCodeObject* buildSettingsForCfg = this->CreateFlatClone(buildSettings);
// Put this last so it can override existing settings
// Convert "CMAKE_XCODE_ATTRIBUTE_*" variables directly.
- std::vector<std::string> vars = this->CurrentMakefile->GetDefinitions();
- for (std::vector<std::string>::const_iterator d = vars.begin();
- d != vars.end(); ++d) {
- if (d->find("CMAKE_XCODE_ATTRIBUTE_") == 0) {
- std::string attribute = d->substr(22);
- this->FilterConfigurationAttribute(i->first, attribute);
+ for (const auto& var : this->CurrentMakefile->GetDefinitions()) {
+ if (var.find("CMAKE_XCODE_ATTRIBUTE_") == 0) {
+ std::string attribute = var.substr(22);
+ this->FilterConfigurationAttribute(config.first, attribute);
if (!attribute.empty()) {
cmGeneratorExpression ge;
std::string processed =
- ge.Parse(this->CurrentMakefile->GetDefinition(*d))
- ->Evaluate(this->CurrentLocalGenerator, i->first);
+ ge.Parse(this->CurrentMakefile->GetDefinition(var))
+ ->Evaluate(this->CurrentLocalGenerator, config.first);
buildSettingsForCfg->AddAttribute(attribute,
this->CreateString(processed));
}
}
}
// store per-config buildSettings into configuration object
- i->second->AddAttribute("buildSettings", buildSettingsForCfg);
+ config.second->AddAttribute("buildSettings", buildSettingsForCfg);
}
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->CreateXCodeTargets(*i, targets)) {
+ for (auto& generator : generators) {
+ if (!this->CreateXCodeTargets(generator, targets)) {
return false;
}
}
// 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;
+ for (auto t : targets) {
this->AddDependAndLinkInformation(t);
}
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;
+ for (auto t : targets) {
allTargets->AddObject(t);
cmXCodeObject* productRef = t->GetObject("productReference");
if (productRef) {
@@ -3053,9 +3204,9 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
return true;
}
-std::string cmGlobalXCodeGenerator::GetObjectsNormalDirectory(
+std::string cmGlobalXCodeGenerator::GetObjectsDirectory(
const std::string& projName, const std::string& configName,
- const cmGeneratorTarget* t) const
+ const cmGeneratorTarget* t, const std::string& variant) const
{
std::string dir = t->GetLocalGenerator()->GetCurrentBinaryDirectory();
dir += "/";
@@ -3064,8 +3215,8 @@ std::string cmGlobalXCodeGenerator::GetObjectsNormalDirectory(
dir += configName;
dir += "/";
dir += t->GetName();
- dir += ".build/Objects-normal/";
-
+ dir += ".build/";
+ dir += variant;
return dir;
}
@@ -3082,8 +3233,13 @@ void cmGlobalXCodeGenerator::ComputeArchitectures(cmMakefile* mf)
if (this->Architectures.empty()) {
// With no ARCHS we use ONLY_ACTIVE_ARCH.
// Look up the arch that Xcode chooses in this case.
- if (const char* arch = mf->GetDefinition("CMAKE_XCODE_CURRENT_ARCH")) {
+ if (const char* arch = mf->GetDefinition("CMAKE_XCODE_ARCHS")) {
this->ObjectDirArchDefault = arch;
+ // We expect only one arch but choose the first just in case.
+ std::string::size_type pos = this->ObjectDirArchDefault.find(';');
+ if (pos != std::string::npos) {
+ this->ObjectDirArchDefault = this->ObjectDirArchDefault.substr(0, pos);
+ }
}
}
@@ -3104,10 +3260,9 @@ void cmGlobalXCodeGenerator::ComputeObjectDirArch(cmMakefile* mf)
void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
std::vector<cmXCodeObject*>& targets)
{
- cmGeneratedFileStream makefileStream(this->CurrentXCodeHackMakefile.c_str());
+ cmGeneratedFileStream makefileStream(this->CurrentXCodeHackMakefile);
if (!makefileStream) {
- cmSystemTools::Error("Could not create",
- this->CurrentXCodeHackMakefile.c_str());
+ cmSystemTools::Error("Could not create " + this->CurrentXCodeHackMakefile);
return;
}
makefileStream.SetCopyIfDifferent(true);
@@ -3131,13 +3286,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
"# link. This forces Xcode to relink the targets from scratch. It\n"
"# does not seem to check these dependencies itself.\n";
/* clang-format on */
- 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;
+ for (const auto& configName : this->CurrentConfigurationTypes) {
+ for (auto target : targets) {
cmGeneratorTarget* gt = target->GetTarget();
if (gt->GetType() == cmStateEnums::EXECUTABLE ||
@@ -3146,7 +3296,7 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
gt->GetType() == cmStateEnums::SHARED_LIBRARY ||
gt->GetType() == cmStateEnums::MODULE_LIBRARY) {
// Declare an entry point for the target post-build phase.
- makefileStream << this->PostBuildMakeTarget(gt->GetName(), *ct)
+ makefileStream << this->PostBuildMakeTarget(gt->GetName(), configName)
<< ":\n";
}
@@ -3155,26 +3305,23 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
gt->GetType() == cmStateEnums::SHARED_LIBRARY ||
gt->GetType() == cmStateEnums::MODULE_LIBRARY) {
std::string tfull = gt->GetFullPath(configName);
- std::string trel = this->ConvertToRelativeForMake(tfull.c_str());
+ std::string trel = this->ConvertToRelativeForMake(tfull);
// Add this target to the post-build phases of its dependencies.
std::map<std::string, cmXCodeObject::StringVec>::const_iterator y =
- target->GetDependTargets().find(*ct);
+ target->GetDependTargets().find(configName);
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";
+ for (auto const& deptgt : y->second) {
+ makefileStream << this->PostBuildMakeTarget(deptgt, configName)
+ << ": " << trel << "\n";
}
}
std::vector<cmGeneratorTarget*> objlibs;
gt->GetObjectLibrariesCMP0026(objlibs);
- for (std::vector<cmGeneratorTarget*>::const_iterator it =
- objlibs.begin();
- it != objlibs.end(); ++it) {
- makefileStream << this->PostBuildMakeTarget((*it)->GetName(), *ct)
+ for (auto objLib : objlibs) {
+ makefileStream << this->PostBuildMakeTarget(objLib->GetName(),
+ configName)
<< ": " << trel << "\n";
}
@@ -3183,29 +3330,26 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
// List dependencies if any exist.
std::map<std::string, cmXCodeObject::StringVec>::const_iterator x =
- target->GetDependLibraries().find(*ct);
+ target->GetDependLibraries().find(configName);
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) {
- std::string file = this->ConvertToRelativeForMake(d->c_str());
+ for (auto const& deplib : x->second) {
+ std::string file = this->ConvertToRelativeForMake(deplib);
makefileStream << "\\\n\t" << file;
dummyRules.insert(file);
}
}
- for (std::vector<cmGeneratorTarget*>::const_iterator it =
- objlibs.begin();
- it != objlibs.end(); ++it) {
+ for (auto objLib : objlibs) {
- const std::string objLibName = (*it)->GetName();
- std::string d = this->GetObjectsNormalDirectory(this->CurrentProject,
- configName, *it);
+ const std::string objLibName = objLib->GetName();
+ std::string d =
+ this->GetObjectsDirectory(this->CurrentProject, configName, objLib,
+ OBJECT_LIBRARY_ARTIFACT_DIR);
d += "lib";
d += objLibName;
d += ".a";
- std::string dependency = this->ConvertToRelativeForMake(d.c_str());
+ std::string dependency = this->ConvertToRelativeForMake(d);
makefileStream << "\\\n\t" << dependency;
dummyRules.insert(dependency);
}
@@ -3213,23 +3357,19 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
// 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";
+ << this->ConvertToRelativeForMake(tfull) << "\n";
// if building for more than one architecture
- // then remove those exectuables as well
+ // then remove those executables as well
if (this->Architectures.size() > 1) {
- std::string universal = this->GetObjectsNormalDirectory(
- this->CurrentProject, configName, gt);
- for (std::vector<std::string>::iterator arch =
- this->Architectures.begin();
- arch != this->Architectures.end(); ++arch) {
+ std::string universal = this->GetObjectsDirectory(
+ this->CurrentProject, configName, gt, "$(OBJDIR)/");
+ for (const auto& architecture : this->Architectures) {
std::string universalFile = universal;
- universalFile += *arch;
+ universalFile += architecture;
universalFile += "/";
universalFile += gt->GetFullName(configName);
makefileStream << "\t/bin/rm -f "
- << this->ConvertToRelativeForMake(
- universalFile.c_str())
+ << this->ConvertToRelativeForMake(universalFile)
<< "\n";
}
}
@@ -3241,26 +3381,17 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
makefileStream << "\n\n"
<< "# For each target create a dummy rule"
<< "so the target does not have to exist\n";
- for (std::set<std::string>::const_iterator it = dummyRules.begin();
- it != dummyRules.end(); ++it) {
- makefileStream << *it << ":\n";
+ for (auto const& dummyRule : dummyRules) {
+ makefileStream << dummyRule << ":\n";
}
}
void cmGlobalXCodeGenerator::OutputXCodeProject(
cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
{
- if (generators.size() == 0) {
+ if (generators.empty()) {
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;
- }
- }
-
if (!this->CreateXCodeObjects(root, generators)) {
return;
}
@@ -3268,24 +3399,17 @@ void cmGlobalXCodeGenerator::OutputXCodeProject(
xcodeDir += "/";
xcodeDir += root->GetProjectName();
xcodeDir += ".xcodeproj";
- cmSystemTools::MakeDirectory(xcodeDir.c_str());
+ cmSystemTools::MakeDirectory(xcodeDir);
std::string xcodeProjFile = xcodeDir + "/project.pbxproj";
- cmGeneratedFileStream fout(xcodeProjFile.c_str());
+ cmGeneratedFileStream fout(xcodeProjFile);
fout.SetCopyIfDifferent(true);
if (!fout) {
return;
}
this->WriteXCodePBXProj(fout, root, generators);
- // Since the lowest available Xcode version for testing was 7.0,
- // I'm setting this as a limit then
- if (this->XcodeVersion >= 70) {
- if (root->GetMakefile()->GetCMakeInstance()->GetIsInTryCompile() ||
- root->GetMakefile()->IsOn("CMAKE_XCODE_GENERATE_SCHEME")) {
- this->OutputXCodeSharedSchemes(xcodeDir);
- this->OutputXCodeWorkspaceSettings(xcodeDir);
- }
- }
+ bool hasGeneratedSchemes = this->OutputXCodeSharedSchemes(xcodeDir, root);
+ this->OutputXCodeWorkspaceSettings(xcodeDir, hasGeneratedSchemes);
this->ClearXCodeObjects();
@@ -3295,26 +3419,58 @@ void cmGlobalXCodeGenerator::OutputXCodeProject(
root->GetBinaryDirectory());
}
-void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes(
- const std::string& xcProjDir)
+bool cmGlobalXCodeGenerator::OutputXCodeSharedSchemes(
+ const std::string& xcProjDir, cmLocalGenerator* root)
{
- for (std::vector<cmXCodeObject*>::const_iterator i =
- this->XCodeObjects.begin();
- i != this->XCodeObjects.end(); ++i) {
- cmXCodeObject* obj = *i;
- if (obj->GetType() == cmXCodeObject::OBJECT &&
- (obj->GetIsA() == cmXCodeObject::PBXNativeTarget ||
- obj->GetIsA() == cmXCodeObject::PBXAggregateTarget)) {
- cmXCodeScheme schm(obj, this->CurrentConfigurationTypes,
- this->XcodeVersion);
- schm.WriteXCodeSharedScheme(xcProjDir,
- this->RelativeToSource(xcProjDir.c_str()));
+ // collect all tests for the targets
+ std::map<std::string, cmXCodeScheme::TestObjects> testables;
+
+ for (auto obj : this->XCodeObjects) {
+ if (obj->GetType() != cmXCodeObject::OBJECT ||
+ obj->GetIsA() != cmXCodeObject::PBXNativeTarget) {
+ continue;
}
+
+ if (!obj->GetTarget()->IsXCTestOnApple()) {
+ continue;
+ }
+
+ const char* testee = obj->GetTarget()->GetProperty("XCTEST_TESTEE");
+ if (!testee) {
+ continue;
+ }
+
+ testables[testee].push_back(obj);
}
+
+ // generate scheme
+ bool ret = false;
+
+ // Since the lowest available Xcode version for testing was 6.4,
+ // I'm setting this as a limit then
+ if (this->XcodeVersion >= 64) {
+ for (auto obj : this->XCodeObjects) {
+ if (obj->GetType() == cmXCodeObject::OBJECT &&
+ (obj->GetIsA() == cmXCodeObject::PBXNativeTarget ||
+ obj->GetIsA() == cmXCodeObject::PBXAggregateTarget) &&
+ (root->GetMakefile()->GetCMakeInstance()->GetIsInTryCompile() ||
+ obj->GetTarget()->GetPropertyAsBool("XCODE_GENERATE_SCHEME"))) {
+ const std::string& targetName = obj->GetTarget()->GetName();
+ cmXCodeScheme schm(obj, testables[targetName],
+ this->CurrentConfigurationTypes,
+ this->XcodeVersion);
+ schm.WriteXCodeSharedScheme(xcProjDir,
+ this->RelativeToSource(xcProjDir));
+ ret = true;
+ }
+ }
+ }
+
+ return ret;
}
void cmGlobalXCodeGenerator::OutputXCodeWorkspaceSettings(
- const std::string& xcProjDir)
+ const std::string& xcProjDir, bool hasGeneratedSchemes)
{
std::string xcodeSharedDataDir = xcProjDir;
xcodeSharedDataDir += "/project.xcworkspace/xcshareddata";
@@ -3323,7 +3479,7 @@ void cmGlobalXCodeGenerator::OutputXCodeWorkspaceSettings(
std::string workspaceSettingsFile = xcodeSharedDataDir;
workspaceSettingsFile += "/WorkspaceSettings.xcsettings";
- cmGeneratedFileStream fout(workspaceSettingsFile.c_str());
+ cmGeneratedFileStream fout(workspaceSettingsFile);
fout.SetCopyIfDifferent(true);
if (!fout) {
return;
@@ -3336,8 +3492,15 @@ void cmGlobalXCodeGenerator::OutputXCodeWorkspaceSettings(
xout.StartElement("plist");
xout.Attribute("version", "1.0");
xout.StartElement("dict");
- xout.Element("key", "IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
- xout.Element("false");
+ if (this->XcodeVersion >= 100) {
+ xout.Element("key", "BuildSystemType");
+ xout.Element("string", "Original");
+ }
+ if (hasGeneratedSchemes) {
+ xout.Element("key",
+ "IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
+ xout.Element("false");
+ }
xout.EndElement(); // dict
xout.EndElement(); // plist
xout.EndDocument();
@@ -3358,12 +3521,7 @@ void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
cmXCodeObject::Indent(1, fout);
fout << "};\n";
cmXCodeObject::Indent(1, fout);
- if (this->XcodeVersion >= 32)
- fout << "objectVersion = 46;\n";
- else if (this->XcodeVersion >= 31)
- fout << "objectVersion = 45;\n";
- else
- fout << "objectVersion = 44;\n";
+ fout << "objectVersion = 46;\n";
cmXCode21Object::PrintList(this->XCodeObjects, fout);
cmXCodeObject::Indent(1, fout);
fout << "rootObject = " << this->RootObject->GetId()
@@ -3402,22 +3560,23 @@ void cmGlobalXCodeGenerator::GetDocumentation(cmDocumentationEntry& entry)
entry.Brief = "Generate Xcode project files.";
}
-std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(const char* p)
+std::string cmGlobalXCodeGenerator::ConvertToRelativeForMake(
+ std::string const& p)
{
return cmSystemTools::ConvertToOutputPath(p);
}
-std::string cmGlobalXCodeGenerator::RelativeToSource(const char* p)
+std::string cmGlobalXCodeGenerator::RelativeToSource(const std::string& p)
{
// We force conversion because Xcode breakpoints do not work unless
// they are in a file named relative to the source tree.
- return cmOutputConverter::ForceToRelativePath(
+ return cmSystemTools::ForceToRelativePath(
cmSystemTools::JoinPath(this->ProjectSourceDirectoryComponents), p);
}
-std::string cmGlobalXCodeGenerator::RelativeToBinary(const char* p)
+std::string cmGlobalXCodeGenerator::RelativeToBinary(const std::string& p)
{
- return this->CurrentLocalGenerator->ConvertToRelativePath(
+ return this->CurrentLocalGenerator->MaybeConvertToRelativePath(
cmSystemTools::JoinPath(this->ProjectOutputDirectoryComponents), p);
}
@@ -3483,11 +3642,10 @@ void cmGlobalXCodeGenerator::AppendDefines(
{
// 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) {
+ for (auto const& define : defines) {
// Start with -D if requested.
def = dflag ? "-D" : "";
- def += *di;
+ def += define;
// Append the flag with needed escapes.
std::string tmp;
@@ -3497,7 +3655,7 @@ void cmGlobalXCodeGenerator::AppendDefines(
}
void cmGlobalXCodeGenerator::AppendFlag(std::string& flags,
- std::string const& flag)
+ std::string const& flag) const
{
// Short-circuit for an empty flag.
if (flag.empty()) {
@@ -3529,17 +3687,13 @@ void cmGlobalXCodeGenerator::AppendFlag(std::string& 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 == '\\') {
+ for (auto c : flag) {
+ if (c == '\'') {
+ flags += "'\\''";
+ } else if (c == '\\') {
flags += "\\\\";
} else {
- flags += *c;
+ flags += c;
}
}
@@ -3553,7 +3707,7 @@ std::string cmGlobalXCodeGenerator::ComputeInfoPListLocation(
cmGeneratorTarget* target)
{
std::string plist = target->GetLocalGenerator()->GetCurrentBinaryDirectory();
- plist += cmake::GetCMakeFilesDirectory();
+ plist += "/CMakeFiles";
plist += "/";
plist += target->GetName();
plist += ".dir/Info.plist";
@@ -3572,7 +3726,7 @@ bool cmGlobalXCodeGenerator::HasKnownObjectFileLocation(
std::string* reason) const
{
if (this->ObjectDirArch.find('$') != std::string::npos) {
- if (reason != CM_NULLPTR) {
+ if (reason != nullptr) {
*reason = " under Xcode with multiple architectures";
}
return false;
@@ -3587,7 +3741,7 @@ bool cmGlobalXCodeGenerator::UseEffectivePlatformName(cmMakefile* mf) const
"XCODE_EMIT_EFFECTIVE_PLATFORM_NAME");
if (!epnValue) {
- return mf->PlatformIsAppleIos();
+ return mf->PlatformIsAppleEmbedded();
}
return cmSystemTools::IsOn(epnValue);
@@ -3603,9 +3757,30 @@ void cmGlobalXCodeGenerator::ComputeTargetObjectDirectory(
cmGeneratorTarget* gt) const
{
std::string configName = this->GetCMakeCFGIntDir();
- std::string dir =
- this->GetObjectsNormalDirectory("$(PROJECT_NAME)", configName, gt);
+ std::string dir = this->GetObjectsDirectory(
+ "$(PROJECT_NAME)", configName, gt, "$(OBJECT_FILE_DIR_normal:base)/");
dir += this->ObjectDirArch;
dir += "/";
gt->ObjectDirectory = dir;
}
+
+std::string cmGlobalXCodeGenerator::GetDeploymentPlatform(const cmMakefile* mf)
+{
+ switch (mf->GetAppleSDKType()) {
+ case cmMakefile::AppleSDK::AppleTVOS:
+ case cmMakefile::AppleSDK::AppleTVSimulator:
+ return "TVOS_DEPLOYMENT_TARGET";
+
+ case cmMakefile::AppleSDK::IPhoneOS:
+ case cmMakefile::AppleSDK::IPhoneSimulator:
+ return "IPHONEOS_DEPLOYMENT_TARGET";
+
+ case cmMakefile::AppleSDK::WatchOS:
+ case cmMakefile::AppleSDK::WatchSimulator:
+ return "WATCHOS_DEPLOYMENT_TARGET";
+
+ case cmMakefile::AppleSDK::MacOS:
+ default:
+ return "MACOSX_DEPLOYMENT_TARGET";
+ }
+}
diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h
index e69793bcc..71446f997 100644
--- a/Source/cmGlobalXCodeGenerator.h
+++ b/Source/cmGlobalXCodeGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmGlobalXCodeGenerator_h
#define cmGlobalXCodeGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
@@ -36,8 +36,8 @@ public:
unsigned int version_number);
static cmGlobalGeneratorFactory* NewFactory();
- ///! Get the name for the generator.
- std::string GetName() const CM_OVERRIDE
+ //! Get the name for the generator.
+ std::string GetName() const override
{
return cmGlobalXCodeGenerator::GetActualName();
}
@@ -46,72 +46,82 @@ public:
/** Get the documentation entry for this generator. */
static void GetDocumentation(cmDocumentationEntry& entry);
- ///! Create a local generator appropriate to this Global Generator
- cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) CM_OVERRIDE;
+ //! Create a local generator appropriate to this Global Generator
+ cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
/**
* Try to determine system information such as shared library
* extension, pthreads, byte order etc.
*/
void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
- bool optional) CM_OVERRIDE;
+ bool optional) override;
+
+ /**
+ * Open a generated IDE project given the following information.
+ */
+ bool Open(const std::string& bindir, const std::string& projectName,
+ bool dryRun) override;
+
/**
* Try running cmake and building a file. This is used for dynalically
* loaded commands, not as part of the usual build process.
*/
- 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, bool verbose,
- std::vector<std::string> const& makeOptions =
- std::vector<std::string>()) CM_OVERRIDE;
+ std::vector<GeneratedMakeCommand> GenerateBuildCommand(
+ const std::string& makeProgram, const std::string& projectName,
+ const std::string& projectDir, std::vector<std::string> const& targetNames,
+ const std::string& config, bool fast, int jobs, bool verbose,
+ std::vector<std::string> const& makeOptions =
+ std::vector<std::string>()) override;
/** Append the subdirectory for the given configuration. */
void AppendDirectoryForConfig(const std::string& prefix,
const std::string& config,
const std::string& suffix,
- std::string& dir) CM_OVERRIDE;
+ std::string& dir) override;
- bool FindMakeProgram(cmMakefile*) CM_OVERRIDE;
+ bool FindMakeProgram(cmMakefile*) override;
- ///! What is the configurations directory variable called?
- const char* GetCMakeCFGIntDir() const CM_OVERRIDE;
- ///! expand CFGIntDir
+ //! What is the configurations directory variable called?
+ const char* GetCMakeCFGIntDir() const override;
+ //! expand CFGIntDir
std::string ExpandCFGIntDir(const std::string& str,
- const std::string& config) const CM_OVERRIDE;
+ const std::string& config) const override;
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?" */
- bool IsMultiConfig() const CM_OVERRIDE;
+ bool IsMultiConfig() const override;
+
+ bool IsXcode() const override { return true; }
- bool HasKnownObjectFileLocation(std::string* reason) const CM_OVERRIDE;
+ bool HasKnownObjectFileLocation(std::string* reason) const override;
- bool IsIPOSupported() const CM_OVERRIDE { return true; }
+ bool IsIPOSupported() const override { return true; }
- bool UseEffectivePlatformName(cmMakefile* mf) const CM_OVERRIDE;
+ bool UseEffectivePlatformName(cmMakefile* mf) const override;
- bool ShouldStripResourcePath(cmMakefile*) const CM_OVERRIDE;
+ bool ShouldStripResourcePath(cmMakefile*) const override;
- bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) CM_OVERRIDE;
- void AppendFlag(std::string& flags, std::string const& flag);
+ bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override;
+ void AppendFlag(std::string& flags, std::string const& flag) const;
protected:
- void AddExtraIDETargets() CM_OVERRIDE;
- void Generate() CM_OVERRIDE;
+ void AddExtraIDETargets() override;
+ void ComputeTargetOrder();
+ void ComputeTargetOrder(cmGeneratorTarget const* gt, size_t& index);
+ void Generate() override;
private:
cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt,
cmSourceGroup* sg);
- cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent, std::string name);
+ cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent,
+ const std::string& name);
bool CreateGroups(std::vector<cmLocalGenerator*>& generators);
std::string XCodeEscapePath(const std::string& p);
- std::string RelativeToSource(const char* p);
- std::string RelativeToBinary(const char* p);
- std::string ConvertToRelativeForMake(const char* p);
+ std::string RelativeToSource(const std::string& p);
+ std::string RelativeToBinary(const std::string& p);
+ std::string ConvertToRelativeForMake(std::string const& p);
void CreateCustomCommands(cmXCodeObject* buildPhases,
cmXCodeObject* sourceBuildPhase,
cmXCodeObject* headerBuildPhase,
@@ -144,7 +154,7 @@ private:
cmXCodeObject* CreateFlatClone(cmXCodeObject*);
cmXCodeObject* CreateXCodeTarget(cmGeneratorTarget* gtgt,
cmXCodeObject* buildPhases);
- void ForceLinkerLanguages() CM_OVERRIDE;
+ void ForceLinkerLanguages() override;
void ForceLinkerLanguage(cmGeneratorTarget* gtgt);
const char* GetTargetLinkFlagsVar(const cmGeneratorTarget* target) const;
const char* GetTargetFileType(cmGeneratorTarget* target);
@@ -158,6 +168,9 @@ private:
const std::string& configName);
cmXCodeObject* CreateUtilityTarget(cmGeneratorTarget* gtgt);
void AddDependAndLinkInformation(cmXCodeObject* target);
+ void AddPositionIndependentLinkAttribute(cmGeneratorTarget* target,
+ cmXCodeObject* buildSettings,
+ const std::string& configName);
void CreateBuildSettings(cmGeneratorTarget* gtgt,
cmXCodeObject* buildSettings,
const std::string& buildType);
@@ -174,8 +187,11 @@ private:
void OutputXCodeProject(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
// Write shared scheme files for all the native targets
- void OutputXCodeSharedSchemes(const std::string& xcProjDir);
- void OutputXCodeWorkspaceSettings(const std::string& xcProjDir);
+ // return true if any were written
+ bool OutputXCodeSharedSchemes(const std::string& xcProjDir,
+ cmLocalGenerator* root);
+ void OutputXCodeWorkspaceSettings(const std::string& xcProjDir,
+ bool hasGeneratedSchemes);
void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string& fullpath,
@@ -190,7 +206,11 @@ private:
cmGeneratorTarget* target);
cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, cmSourceFile* sf,
cmGeneratorTarget* gtgt);
+ void AddXCodeProjBuildRule(cmGeneratorTarget* target,
+ std::vector<cmSourceFile*>& sources) const;
bool CreateXCodeTargets(cmLocalGenerator* gen, std::vector<cmXCodeObject*>&);
+ bool CreateXCodeTarget(cmGeneratorTarget* gtgt,
+ std::vector<cmXCodeObject*>&);
bool IsHeaderFile(cmSourceFile*);
void AddDependTarget(cmXCodeObject* target, cmXCodeObject* dependTarget);
void CreateXCodeDependHackTarget(std::vector<cmXCodeObject*>& targets);
@@ -219,11 +239,11 @@ private:
std::vector<std::string> const& defines,
bool dflag = false);
- void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const CM_OVERRIDE;
+ void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
protected:
- const char* GetInstallTargetName() const CM_OVERRIDE { return "install"; }
- const char* GetPackageTargetName() const CM_OVERRIDE { return "package"; }
+ const char* GetInstallTargetName() const override { return "install"; }
+ const char* GetPackageTargetName() const override { return "package"; }
unsigned int XcodeVersion;
std::string VersionString;
@@ -238,13 +258,16 @@ private:
bool XcodeBuildCommandInitialized;
void PrintCompilerAdvice(std::ostream&, std::string const&,
- const char*) const CM_OVERRIDE
+ const char*) const override
{
}
- std::string GetObjectsNormalDirectory(const std::string& projName,
- const std::string& configName,
- const cmGeneratorTarget* t) const;
+ std::string GetObjectsDirectory(const std::string& projName,
+ const std::string& configName,
+ const cmGeneratorTarget* t,
+ const std::string& variant) const;
+
+ static std::string GetDeploymentPlatform(const cmMakefile* mf);
void ComputeArchitectures(cmMakefile* mf);
void ComputeObjectDirArch(cmMakefile* mf);
@@ -271,6 +294,7 @@ private:
std::string ObjectDirArchDefault;
std::string ObjectDirArch;
std::string GeneratorToolset;
+ std::map<cmGeneratorTarget const*, size_t> TargetOrderIndex;
};
#endif
diff --git a/Source/cmGraphAdjacencyList.h b/Source/cmGraphAdjacencyList.h
index 46cf87871..5ca9269ed 100644
--- a/Source/cmGraphAdjacencyList.h
+++ b/Source/cmGraphAdjacencyList.h
@@ -5,6 +5,9 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmListFileCache.h"
+
+#include <utility>
#include <vector>
/**
@@ -15,17 +18,22 @@
class cmGraphEdge
{
public:
- cmGraphEdge(int n = 0, bool s = true)
+ cmGraphEdge(int n, bool s, cmListFileBacktrace bt)
: Dest(n)
, Strong(s)
+ , Backtrace(std::move(bt))
{
}
operator int() const { return this->Dest; }
bool IsStrong() const { return this->Strong; }
+
+ cmListFileBacktrace const& GetBacktrace() const { return this->Backtrace; }
+
private:
int Dest;
bool Strong;
+ cmListFileBacktrace Backtrace;
};
struct cmGraphEdgeList : public std::vector<cmGraphEdge>
{
diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx
index 7e953cef1..a75d8a97a 100644
--- a/Source/cmGraphVizWriter.cxx
+++ b/Source/cmGraphVizWriter.cxx
@@ -2,8 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGraphVizWriter.h"
-#include "cmConfigure.h"
+#include <cstddef>
#include <iostream>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <utility>
@@ -12,13 +13,40 @@
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
-static const char* getShapeForTarget(const cmGeneratorTarget* target)
+namespace {
+enum LinkLibraryScopeType
+{
+ LLT_SCOPE_PUBLIC,
+ LLT_SCOPE_PRIVATE,
+ LLT_SCOPE_INTERFACE
+};
+
+const char* const GRAPHVIZ_PRIVATE_EDEGE_STYLE = "dashed";
+const char* const GRAPHVIZ_INTERFACE_EDEGE_STYLE = "dotted";
+
+std::string getLinkLibraryStyle(const LinkLibraryScopeType& type)
+{
+ std::string style;
+ switch (type) {
+ case LLT_SCOPE_PRIVATE:
+ style = "[style = " + std::string(GRAPHVIZ_PRIVATE_EDEGE_STYLE) + "]";
+ break;
+ case LLT_SCOPE_INTERFACE:
+ style = "[style = " + std::string(GRAPHVIZ_INTERFACE_EDEGE_STYLE) + "]";
+ break;
+ default:
+ break;
+ }
+ return style;
+}
+
+const char* getShapeForTarget(const cmGeneratorTarget* target)
{
if (!target) {
return "ellipse";
@@ -40,17 +68,101 @@ static const char* getShapeForTarget(const cmGeneratorTarget* target)
return "box";
}
-cmGraphVizWriter::cmGraphVizWriter(
- const std::vector<cmLocalGenerator*>& localGenerators)
+std::map<std::string, LinkLibraryScopeType> getScopedLinkLibrariesFromTarget(
+ cmTarget* Target, const cmGlobalGenerator* globalGenerator)
+{
+ char sep = ';';
+ std::map<std::string, LinkLibraryScopeType> tokens;
+ size_t start = 0, end = 0;
+
+ const char* pInterfaceLinkLibraries =
+ Target->GetProperty("INTERFACE_LINK_LIBRARIES");
+ const char* pLinkLibraries = Target->GetProperty("LINK_LIBRARIES");
+
+ if (!pInterfaceLinkLibraries && !pLinkLibraries) {
+ return tokens; // target is not linked against any other libraries
+ }
+
+ // make sure we don't touch a null-ptr
+ auto interfaceLinkLibraries =
+ std::string(pInterfaceLinkLibraries ? pInterfaceLinkLibraries : "");
+ auto linkLibraries = std::string(pLinkLibraries ? pLinkLibraries : "");
+
+ // first extract interfaceLinkLibraries
+ while (start < interfaceLinkLibraries.length()) {
+
+ if ((end = interfaceLinkLibraries.find(sep, start)) == std::string::npos) {
+ end = interfaceLinkLibraries.length();
+ }
+
+ std::string element = interfaceLinkLibraries.substr(start, end - start);
+ if (globalGenerator->IsAlias(element)) {
+ const auto tgt = globalGenerator->FindTarget(element);
+ if (tgt) {
+ element = tgt->GetName();
+ }
+ }
+
+ if (std::string::npos == element.find("$<LINK_ONLY:", 0)) {
+ // we assume first, that this library is an interface library.
+ // if we find it again in the linklibraries property, we promote it to an
+ // public library.
+ tokens[element] = LLT_SCOPE_INTERFACE;
+ } else {
+ // this is an private linked static library.
+ // we take care of this case in the second iterator.
+ }
+ start = end + 1;
+ }
+
+ // second extract linkLibraries
+ start = 0;
+ while (start < linkLibraries.length()) {
+
+ if ((end = linkLibraries.find(sep, start)) == std::string::npos) {
+ end = linkLibraries.length();
+ }
+
+ std::string element = linkLibraries.substr(start, end - start);
+ if (globalGenerator->IsAlias(element)) {
+ const auto tgt = globalGenerator->FindTarget(element);
+ if (tgt) {
+ element = tgt->GetName();
+ }
+ }
+
+ if (tokens.find(element) == tokens.end()) {
+ // this library is not found in interfaceLinkLibraries but in
+ // linkLibraries.
+ // this results in a private linked library.
+ tokens[element] = LLT_SCOPE_PRIVATE;
+ } else if (LLT_SCOPE_INTERFACE == tokens[element]) {
+ // this library is found in interfaceLinkLibraries and linkLibraries.
+ // this results in a public linked library.
+ tokens[element] = LLT_SCOPE_PUBLIC;
+ } else {
+ // private and public linked libraries should not be changed anymore.
+ }
+
+ start = end + 1;
+ }
+
+ return tokens;
+}
+}
+
+cmGraphVizWriter::cmGraphVizWriter(const cmGlobalGenerator* globalGenerator)
: GraphType("digraph")
, GraphName("GG")
, GraphHeader("node [\n fontsize = \"12\"\n];")
, GraphNodePrefix("node")
- , LocalGenerators(localGenerators)
+ , GlobalGenerator(globalGenerator)
+ , LocalGenerators(globalGenerator->GetLocalGenerators())
, GenerateForExecutables(true)
, GenerateForStaticLibs(true)
, GenerateForSharedLibs(true)
, GenerateForModuleLibs(true)
+ , GenerateForInterface(true)
, GenerateForExternals(true)
, GeneratePerTarget(true)
, GenerateDependers(true)
@@ -58,19 +170,19 @@ cmGraphVizWriter::cmGraphVizWriter(
{
}
-void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
- const char* fallbackSettingsFileName)
+void cmGraphVizWriter::ReadSettings(
+ const std::string& settingsFileName,
+ const std::string& fallbackSettingsFileName)
{
- cmake cm(cmake::RoleScript);
+ cmake cm(cmake::RoleScript, cmState::Unknown);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator ggi(&cm);
- CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&ggi, cm.GetCurrentSnapshot()));
- CM_AUTO_PTR<cmLocalGenerator> lg(ggi.CreateLocalGenerator(mf.get()));
-
- const char* inFileName = settingsFileName;
+ cmMakefile mf(&ggi, cm.GetCurrentSnapshot());
+ std::unique_ptr<cmLocalGenerator> lg(ggi.CreateLocalGenerator(&mf));
+ std::string inFileName = settingsFileName;
if (!cmSystemTools::FileExists(inFileName)) {
inFileName = fallbackSettingsFileName;
if (!cmSystemTools::FileExists(inFileName)) {
@@ -78,8 +190,8 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
}
}
- if (!mf->ReadListFile(inFileName)) {
- cmSystemTools::Error("Problem opening GraphViz options file: ",
+ if (!mf.ReadListFile(inFileName)) {
+ cmSystemTools::Error("Problem opening GraphViz options file: " +
inFileName);
return;
}
@@ -87,12 +199,12 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
std::cout << "Reading GraphViz options file: " << inFileName << std::endl;
#define __set_if_set(var, cmakeDefinition) \
- { \
- const char* value = mf->GetDefinition(cmakeDefinition); \
+ do { \
+ const char* value = mf.GetDefinition(cmakeDefinition); \
if (value) { \
(var) = value; \
} \
- }
+ } while (false)
__set_if_set(this->GraphType, "GRAPHVIZ_GRAPH_TYPE");
__set_if_set(this->GraphName, "GRAPHVIZ_GRAPH_NAME");
@@ -100,17 +212,18 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
__set_if_set(this->GraphNodePrefix, "GRAPHVIZ_NODE_PREFIX");
#define __set_bool_if_set(var, cmakeDefinition) \
- { \
- const char* value = mf->GetDefinition(cmakeDefinition); \
+ do { \
+ const char* value = mf.GetDefinition(cmakeDefinition); \
if (value) { \
- (var) = mf->IsOn(cmakeDefinition); \
+ (var) = mf.IsOn(cmakeDefinition); \
} \
- }
+ } while (false)
__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->GenerateForInterface, "GRAPHVIZ_INTERFACE");
__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");
@@ -123,23 +236,20 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName,
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);
+ for (std::string const& currentRegexString : ignoreTargetsRegExVector) {
cmsys::RegularExpression currentRegex;
- if (!currentRegex.compile(currentRegexString.c_str())) {
+ if (!currentRegex.compile(currentRegexString)) {
std::cerr << "Could not compile bad regex \"" << currentRegexString
<< "\"" << std::endl;
}
- this->TargetsToIgnoreRegex.push_back(currentRegex);
+ this->TargetsToIgnoreRegex.push_back(std::move(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)
+void cmGraphVizWriter::WriteTargetDependersFiles(const std::string& fileName)
{
if (!this->GenerateDependers) {
return;
@@ -147,23 +257,21 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
this->CollectTargetsAndLibs();
- for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
- this->TargetPtrs.begin();
- ptrIt != this->TargetPtrs.end(); ++ptrIt) {
- if (ptrIt->second == CM_NULLPTR) {
+ for (auto const& ptr : this->TargetPtrs) {
+ if (ptr.second == nullptr) {
continue;
}
- if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
+ if (!this->GenerateForTargetType(ptr.second->GetType())) {
continue;
}
std::string currentFilename = fileName;
currentFilename += ".";
- currentFilename += ptrIt->first;
+ currentFilename += ptr.first;
currentFilename += ".dependers";
- cmGeneratedFileStream str(currentFilename.c_str());
+ cmGeneratedFileStream str(currentFilename);
if (!str) {
return;
}
@@ -174,7 +282,7 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
std::cout << "Writing " << currentFilename << "..." << std::endl;
this->WriteHeader(str);
- this->WriteDependerConnections(ptrIt->first, insertedNodes,
+ this->WriteDependerConnections(ptr.first, insertedNodes,
insertedConnections, str);
this->WriteFooter(str);
@@ -183,7 +291,7 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName)
// Iterate over all targets and write for each one a graph which shows
// on which targets it depends.
-void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
+void cmGraphVizWriter::WritePerTargetFiles(const std::string& fileName)
{
if (!this->GeneratePerTarget) {
return;
@@ -191,14 +299,12 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
this->CollectTargetsAndLibs();
- for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
- this->TargetPtrs.begin();
- ptrIt != this->TargetPtrs.end(); ++ptrIt) {
- if (ptrIt->second == CM_NULLPTR) {
+ for (auto const& ptr : this->TargetPtrs) {
+ if (ptr.second == nullptr) {
continue;
}
- if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
+ if (!this->GenerateForTargetType(ptr.second->GetType())) {
continue;
}
@@ -207,8 +313,8 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
std::string currentFilename = fileName;
currentFilename += ".";
- currentFilename += ptrIt->first;
- cmGeneratedFileStream str(currentFilename.c_str());
+ currentFilename += ptr.first;
+ cmGeneratedFileStream str(currentFilename);
if (!str) {
return;
}
@@ -216,13 +322,12 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName)
std::cout << "Writing " << currentFilename << "..." << std::endl;
this->WriteHeader(str);
- this->WriteConnections(ptrIt->first, insertedNodes, insertedConnections,
- str);
+ this->WriteConnections(ptr.first, insertedNodes, insertedConnections, str);
this->WriteFooter(str);
}
}
-void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
+void cmGraphVizWriter::WriteGlobalFile(const std::string& fileName)
{
this->CollectTargetsAndLibs();
@@ -237,19 +342,16 @@ void cmGraphVizWriter::WriteGlobalFile(const char* fileName)
std::set<std::string> insertedConnections;
std::set<std::string> insertedNodes;
- for (std::map<std::string, const cmGeneratorTarget*>::const_iterator ptrIt =
- this->TargetPtrs.begin();
- ptrIt != this->TargetPtrs.end(); ++ptrIt) {
- if (ptrIt->second == CM_NULLPTR) {
+ for (auto const& ptr : this->TargetPtrs) {
+ if (ptr.second == nullptr) {
continue;
}
- if (!this->GenerateForTargetType(ptrIt->second->GetType())) {
+ if (!this->GenerateForTargetType(ptr.second->GetType())) {
continue;
}
- this->WriteConnections(ptrIt->first, insertedNodes, insertedConnections,
- str);
+ this->WriteConnections(ptr.first, insertedNodes, insertedConnections, str);
}
this->WriteFooter(str);
}
@@ -279,19 +381,18 @@ void cmGraphVizWriter::WriteConnections(
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
- if (targetPtrIt->second == CM_NULLPTR) // it's an external library
+ if (targetPtrIt->second == nullptr) // it's an external library
{
return;
}
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
+ std::map<std::string, LinkLibraryScopeType> ll =
+ getScopedLinkLibrariesFromTarget(targetPtrIt->second->Target,
+ GlobalGenerator);
- const cmTarget::LinkLibraryVectorType* ll =
- &(targetPtrIt->second->Target->GetOriginalLinkLibraries());
-
- for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
- llit != ll->end(); ++llit) {
- const char* libName = llit->first.c_str();
+ for (auto const& llit : ll) {
+ const std::string& libName = llit.first;
std::map<std::string, std::string>::const_iterator libNameIt =
this->TargetNamesNodes.find(libName);
@@ -310,6 +411,9 @@ void cmGraphVizWriter::WriteConnections(
insertedNodes, str);
str << " \"" << myNodeName << "\" -> \"" << libNameIt->second << "\"";
+
+ str << getLinkLibraryStyle(llit.second);
+
str << " // " << targetName << " -> " << libName << std::endl;
this->WriteConnections(libName, insertedNodes, insertedConnections, str);
}
@@ -330,7 +434,7 @@ void cmGraphVizWriter::WriteDependerConnections(
this->WriteNode(targetName, targetPtrIt->second, insertedNodes, str);
- if (targetPtrIt->second == CM_NULLPTR) // it's an external library
+ if (targetPtrIt->second == nullptr) // it's an external library
{
return;
}
@@ -338,29 +442,25 @@ void cmGraphVizWriter::WriteDependerConnections(
std::string myNodeName = this->TargetNamesNodes.find(targetName)->second;
// now search who links against me
- for (std::map<std::string, const cmGeneratorTarget*>::const_iterator
- dependerIt = this->TargetPtrs.begin();
- dependerIt != this->TargetPtrs.end(); ++dependerIt) {
- if (dependerIt->second == CM_NULLPTR) {
+ for (auto const& tptr : this->TargetPtrs) {
+ if (tptr.second == nullptr) {
continue;
}
- if (!this->GenerateForTargetType(dependerIt->second->GetType())) {
+ if (!this->GenerateForTargetType(tptr.second->GetType())) {
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->Target->GetOriginalLinkLibraries());
+ std::map<std::string, LinkLibraryScopeType> ll =
+ getScopedLinkLibrariesFromTarget(tptr.second->Target, GlobalGenerator);
- for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
- llit != ll->end(); ++llit) {
- std::string libName = llit->first;
- if (libName == targetName) {
+ for (auto const& llit : ll) {
+ if (llit.first == targetName) {
// So this target links against targetName.
std::map<std::string, std::string>::const_iterator dependerNodeNameIt =
- this->TargetNamesNodes.find(dependerIt->first);
+ this->TargetNamesNodes.find(tptr.first);
if (dependerNodeNameIt != this->TargetNamesNodes.end()) {
std::string connectionName = dependerNodeNameIt->second;
@@ -370,14 +470,13 @@ void cmGraphVizWriter::WriteDependerConnections(
if (insertedConnections.find(connectionName) ==
insertedConnections.end()) {
insertedConnections.insert(connectionName);
- this->WriteNode(dependerIt->first, dependerIt->second,
- insertedNodes, str);
+ this->WriteNode(tptr.first, tptr.second, insertedNodes, str);
str << " \"" << dependerNodeNameIt->second << "\" -> \""
<< myNodeName << "\"";
- str << " // " << targetName << " -> " << dependerIt->first
- << std::endl;
- this->WriteDependerConnections(dependerIt->first, insertedNodes,
+ str << " // " << targetName << " -> " << tptr.first << std::endl;
+ str << getLinkLibraryStyle(llit.second);
+ this->WriteDependerConnections(tptr.first, insertedNodes,
insertedConnections, str);
}
}
@@ -417,13 +516,10 @@ 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) {
- std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
- it != targets.end(); ++it) {
- const char* realTargetName = (*it)->GetName().c_str();
+ for (cmLocalGenerator* lg : this->LocalGenerators) {
+ const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ const std::string& realTargetName = target->GetName();
if (this->IgnoreThisTarget(realTargetName)) {
// Skip ignored targets
continue;
@@ -432,7 +528,7 @@ int cmGraphVizWriter::CollectAllTargets()
std::ostringstream ostr;
ostr << this->GraphNodePrefix << cnt++;
this->TargetNamesNodes[realTargetName] = ostr.str();
- this->TargetPtrs[realTargetName] = *it;
+ this->TargetPtrs[realTargetName] = target;
}
}
@@ -442,34 +538,37 @@ int cmGraphVizWriter::CollectAllTargets()
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) {
- std::vector<cmGeneratorTarget*> targets = (*lit)->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::const_iterator it = targets.begin();
- it != targets.end(); ++it) {
- const char* realTargetName = (*it)->GetName().c_str();
+ for (cmLocalGenerator* lg : this->LocalGenerators) {
+ const std::vector<cmGeneratorTarget*>& targets = lg->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ const std::string& realTargetName = target->GetName();
if (this->IgnoreThisTarget(realTargetName)) {
// Skip ignored targets
continue;
}
const cmTarget::LinkLibraryVectorType* ll =
- &((*it)->Target->GetOriginalLinkLibraries());
- for (cmTarget::LinkLibraryVectorType::const_iterator llit = ll->begin();
- llit != ll->end(); ++llit) {
- const char* libName = llit->first.c_str();
+ &(target->Target->GetOriginalLinkLibraries());
+ for (auto const& llit : *ll) {
+ std::string libName = llit.first;
if (this->IgnoreThisTarget(libName)) {
// Skip ignored targets
continue;
}
+ if (GlobalGenerator->IsAlias(libName)) {
+ const auto tgt = GlobalGenerator->FindTarget(libName);
+ if (tgt) {
+ libName = tgt->GetName();
+ }
+ }
+
std::map<std::string, const cmGeneratorTarget*>::const_iterator tarIt =
this->TargetPtrs.find(libName);
if (tarIt == this->TargetPtrs.end()) {
std::ostringstream ostr;
ostr << this->GraphNodePrefix << cnt++;
this->TargetNamesNodes[libName] = ostr.str();
- this->TargetPtrs[libName] = CM_NULLPTR;
+ this->TargetPtrs[libName] = nullptr;
// str << " \"" << ostr << "\" [ label=\"" << libName
// << "\" shape=\"ellipse\"];" << std::endl;
}
@@ -481,10 +580,7 @@ int cmGraphVizWriter::CollectAllExternalLibs(int 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;
+ for (cmsys::RegularExpression& regEx : this->TargetsToIgnoreRegex) {
if (regEx.is_valid()) {
if (regEx.find(name)) {
return true;
@@ -507,6 +603,8 @@ bool cmGraphVizWriter::GenerateForTargetType(
return this->GenerateForSharedLibs;
case cmStateEnums::MODULE_LIBRARY:
return this->GenerateForModuleLibs;
+ case cmStateEnums::INTERFACE_LIBRARY:
+ return this->GenerateForInterface;
default:
break;
}
diff --git a/Source/cmGraphVizWriter.h b/Source/cmGraphVizWriter.h
index 824999b96..768683a3b 100644
--- a/Source/cmGraphVizWriter.h
+++ b/Source/cmGraphVizWriter.h
@@ -16,21 +16,22 @@
class cmGeneratedFileStream;
class cmGeneratorTarget;
class cmLocalGenerator;
+class cmGlobalGenerator;
/** 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);
+ cmGraphVizWriter(const cmGlobalGenerator* globalGenerator);
- void ReadSettings(const char* settingsFileName,
- const char* fallbackSettingsFileName);
+ void ReadSettings(const std::string& settingsFileName,
+ const std::string& fallbackSettingsFileName);
- void WritePerTargetFiles(const char* fileName);
- void WriteTargetDependersFiles(const char* fileName);
+ void WritePerTargetFiles(const std::string& fileName);
+ void WriteTargetDependersFiles(const std::string& fileName);
- void WriteGlobalFile(const char* fileName);
+ void WriteGlobalFile(const std::string& fileName);
protected:
void CollectTargetsAndLibs();
@@ -69,6 +70,7 @@ protected:
std::vector<cmsys::RegularExpression> TargetsToIgnoreRegex;
+ const cmGlobalGenerator* GlobalGenerator;
const std::vector<cmLocalGenerator*>& LocalGenerators;
std::map<std::string, const cmGeneratorTarget*> TargetPtrs;
@@ -79,6 +81,7 @@ protected:
bool GenerateForStaticLibs;
bool GenerateForSharedLibs;
bool GenerateForModuleLibs;
+ bool GenerateForInterface;
bool GenerateForExternals;
bool GeneratePerTarget;
bool GenerateDependers;
diff --git a/Source/cmHexFileConverter.cxx b/Source/cmHexFileConverter.cxx
index 78dceb794..190f2e305 100644
--- a/Source/cmHexFileConverter.cxx
+++ b/Source/cmHexFileConverter.cxx
@@ -2,7 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmHexFileConverter.h"
-#include "cmConfigure.h"
+#include <ctype.h>
#include <stdio.h>
#include <string.h>
@@ -13,16 +13,9 @@
#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 == CM_NULLPTR) {
+ if (line == nullptr) {
return 0;
}
unsigned int length = static_cast<unsigned int>(strlen(line));
@@ -135,11 +128,11 @@ static bool ConvertIntelHexLine(const char* buf, FILE* outFile)
}
cmHexFileConverter::FileType cmHexFileConverter::DetermineFileType(
- const char* inFileName)
+ const std::string& inFileName)
{
char buf[1024];
FILE* inFile = cmsys::SystemTools::Fopen(inFileName, "rb");
- if (inFile == CM_NULLPTR) {
+ if (inFile == nullptr) {
return Binary;
}
@@ -170,15 +163,15 @@ cmHexFileConverter::FileType cmHexFileConverter::DetermineFileType(
}
for (unsigned int i = 1; i < slen; i++) {
- if (!cm_IsHexChar(buf[i])) {
+ if (!isxdigit(buf[i])) {
return Binary;
}
}
return type;
}
-bool cmHexFileConverter::TryConvert(const char* inFileName,
- const char* outFileName)
+bool cmHexFileConverter::TryConvert(const std::string& inFileName,
+ const std::string& outFileName)
{
FileType type = DetermineFileType(inFileName);
if (type == Binary) {
@@ -188,11 +181,11 @@ bool cmHexFileConverter::TryConvert(const char* inFileName,
// try to open the file
FILE* inFile = cmsys::SystemTools::Fopen(inFileName, "rb");
FILE* outFile = cmsys::SystemTools::Fopen(outFileName, "wb");
- if ((inFile == CM_NULLPTR) || (outFile == CM_NULLPTR)) {
- if (inFile != CM_NULLPTR) {
+ if ((inFile == nullptr) || (outFile == nullptr)) {
+ if (inFile != nullptr) {
fclose(inFile);
}
- if (outFile != CM_NULLPTR) {
+ if (outFile != nullptr) {
fclose(outFile);
}
return false;
@@ -201,7 +194,7 @@ bool cmHexFileConverter::TryConvert(const char* inFileName,
// convert them line by line
bool success = false;
char buf[1024];
- while (fgets(buf, 1024, inFile) != CM_NULLPTR) {
+ while (fgets(buf, 1024, inFile) != nullptr) {
if (type == MotorolaSrec) {
success = ConvertMotorolaSrecLine(buf, outFile);
} else if (type == IntelHex) {
diff --git a/Source/cmHexFileConverter.h b/Source/cmHexFileConverter.h
index 1050bc1b4..cb5de8f34 100644
--- a/Source/cmHexFileConverter.h
+++ b/Source/cmHexFileConverter.h
@@ -3,6 +3,9 @@
#ifndef cmHexFileConverter_h
#define cmHexFileConverter_h
+#include "cmConfigure.h" // IWYU pragma: keep
+#include <string>
+
/** \class cmHexFileConverter
* \brief Can detects Intel Hex and Motorola S-record files and convert them
* to binary files.
@@ -17,8 +20,9 @@ public:
IntelHex,
MotorolaSrec
};
- static FileType DetermineFileType(const char* inFileName);
- static bool TryConvert(const char* inFileName, const char* outFileName);
+ static FileType DetermineFileType(const std::string& inFileName);
+ static bool TryConvert(const std::string& inFileName,
+ const std::string& outFileName);
};
#endif
diff --git a/Source/cmIDEFlagTable.h b/Source/cmIDEFlagTable.h
index 152e293eb..ff93432cb 100644
--- a/Source/cmIDEFlagTable.h
+++ b/Source/cmIDEFlagTable.h
@@ -3,13 +3,15 @@
#ifndef cmIDEFlagTable_h
#define cmIDEFlagTable_h
+#include <string>
+
// 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
+ std::string IDEName; // name used in the IDE xml file
+ std::string commandFlag; // command line flag
+ std::string comment; // comment
+ std::string value; // string value
unsigned int special; // flags for special handling requests
enum
{
@@ -27,6 +29,9 @@ struct cmIDEFlagTable
SpaceAppendable = (1 << 7), // a flag that if specified multiple times
// should have its value appended to the
// old value with spaces
+ CommaAppendable = (1 << 8), // a flag that if specified multiple times
+ // should have its value appended to the
+ // old value with commas (e.g. C# /nowarn
UserValueIgnored = UserValue | UserIgnored,
UserValueRequired = UserValue | UserRequired
diff --git a/Source/cmIDEOptions.cxx b/Source/cmIDEOptions.cxx
index 5e872d2ff..7b992d743 100644
--- a/Source/cmIDEOptions.cxx
+++ b/Source/cmIDEOptions.cxx
@@ -6,6 +6,7 @@
#include <iterator>
#include <string.h>
+#include "cmAlgorithms.h"
#include "cmIDEFlagTable.h"
#include "cmSystemTools.h"
@@ -13,6 +14,7 @@ cmIDEOptions::cmIDEOptions()
{
this->DoingDefine = false;
this->AllowDefine = true;
+ this->DoingInclude = false;
this->AllowSlash = false;
this->DoingFollowing = 0;
for (int i = 0; i < FlagTableCount; ++i) {
@@ -24,7 +26,7 @@ cmIDEOptions::~cmIDEOptions()
{
}
-void cmIDEOptions::HandleFlag(const char* flag)
+void cmIDEOptions::HandleFlag(std::string const& flag)
{
// If the last option was -D then this option is the definition.
if (this->DoingDefine) {
@@ -33,6 +35,13 @@ void cmIDEOptions::HandleFlag(const char* flag)
return;
}
+ // If the last option was -I then this option is the include directory.
+ if (this->DoingInclude) {
+ this->DoingInclude = false;
+ this->Includes.push_back(flag);
+ return;
+ }
+
// If the last option expected a following value, this is it.
if (this->DoingFollowing) {
this->FlagMapUpdate(this->DoingFollowing, flag);
@@ -41,15 +50,27 @@ void cmIDEOptions::HandleFlag(const char* flag)
}
// Look for known arguments.
- if (flag[0] == '-' || (this->AllowSlash && flag[0] == '/')) {
+ size_t len = flag.length();
+ if (len > 0 && (flag[0] == '-' || (this->AllowSlash && flag[0] == '/'))) {
// Look for preprocessor definitions.
- if (this->AllowDefine && flag[1] == 'D') {
- if (flag[2] == '\0') {
+ if (this->AllowDefine && len > 1 && flag[1] == 'D') {
+ if (len <= 2) {
// The next argument will have the definition.
this->DoingDefine = true;
} else {
// Store this definition.
- this->Defines.push_back(flag + 2);
+ this->Defines.push_back(flag.substr(2));
+ }
+ return;
+ }
+ // Look for include directory.
+ if (this->AllowInclude && len > 1 && flag[1] == 'I') {
+ if (len <= 2) {
+ // The next argument will have the include directory.
+ this->DoingInclude = true;
+ } else {
+ // Store this include directory.
+ this->Includes.push_back(flag.substr(2));
}
return;
}
@@ -73,27 +94,28 @@ void cmIDEOptions::HandleFlag(const char* flag)
}
bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
- const char* flag, bool& flag_handled)
+ std::string const& flag, bool& flag_handled)
{
+ const char* pf = flag.c_str() + 1;
// Look for an entry in the flag table matching this flag.
- for (cmIDEFlagTable const* entry = table; entry->IDEName; ++entry) {
+ for (cmIDEFlagTable const* entry = table; !entry->IDEName.empty(); ++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 ||
+ int n = static_cast<int>(entry->commandFlag.length());
+ if ((strncmp(pf, entry->commandFlag.c_str(), n) == 0 ||
(entry->special & cmIDEFlagTable::CaseInsensitive &&
- cmsysString_strncasecmp(flag + 1, entry->commandFlag, n))) &&
+ cmsysString_strncasecmp(pf, entry->commandFlag.c_str(), n))) &&
(!(entry->special & cmIDEFlagTable::UserRequired) ||
- static_cast<int>(strlen(flag + 1)) > n)) {
- this->FlagMapUpdate(entry, flag + n + 1);
+ static_cast<int>(strlen(pf)) > n)) {
+ this->FlagMapUpdate(entry, std::string(pf + n));
entry_found = true;
}
- } else if (strcmp(flag + 1, entry->commandFlag) == 0 ||
+ } else if (strcmp(pf, entry->commandFlag.c_str()) == 0 ||
(entry->special & cmIDEFlagTable::CaseInsensitive &&
- cmsysString_strcasecmp(flag + 1, entry->commandFlag) == 0)) {
+ cmsysString_strcasecmp(pf, entry->commandFlag.c_str()) == 0)) {
if (entry->special & cmIDEFlagTable::UserFollowing) {
// This flag expects a value in the following argument.
this->DoingFollowing = entry;
@@ -118,7 +140,7 @@ bool cmIDEOptions::CheckFlagTable(cmIDEFlagTable const* table,
}
void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
- const char* new_value)
+ std::string const& new_value)
{
if (entry->special & cmIDEFlagTable::UserIgnored) {
// Ignore the user-specified value.
@@ -127,6 +149,8 @@ void cmIDEOptions::FlagMapUpdate(cmIDEFlagTable const* entry,
this->FlagMap[entry->IDEName].push_back(new_value);
} else if (entry->special & cmIDEFlagTable::SpaceAppendable) {
this->FlagMap[entry->IDEName].append_with_space(new_value);
+ } else if (entry->special & cmIDEFlagTable::CommaAppendable) {
+ this->FlagMap[entry->IDEName].append_with_comma(new_value);
} else {
// Use the user-specified value.
this->FlagMap[entry->IDEName] = new_value;
@@ -138,16 +162,16 @@ void cmIDEOptions::AddDefine(const std::string& def)
this->Defines.push_back(def);
}
-void cmIDEOptions::AddDefines(const char* defines)
+void cmIDEOptions::AddDefines(std::string const& defines)
{
- if (defines) {
+ if (!defines.empty()) {
// 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());
+ cmAppend(this->Defines, defines);
}
std::vector<std::string> const& cmIDEOptions::GetDefines() const
@@ -155,12 +179,34 @@ std::vector<std::string> const& cmIDEOptions::GetDefines() const
return this->Defines;
}
-void cmIDEOptions::AddFlag(const char* flag, const char* value)
+void cmIDEOptions::AddInclude(const std::string& include)
+{
+ this->Includes.push_back(include);
+}
+
+void cmIDEOptions::AddIncludes(std::string const& includes)
+{
+ if (!includes.empty()) {
+ // Expand the list of includes.
+ cmSystemTools::ExpandListArgument(includes, this->Includes);
+ }
+}
+void cmIDEOptions::AddIncludes(const std::vector<std::string>& includes)
+{
+ cmAppend(this->Includes, includes);
+}
+
+std::vector<std::string> const& cmIDEOptions::GetIncludes() const
+{
+ return this->Includes;
+}
+
+void cmIDEOptions::AddFlag(std::string const& flag, std::string const& value)
{
this->FlagMap[flag] = value;
}
-void cmIDEOptions::AddFlag(const char* flag,
+void cmIDEOptions::AddFlag(std::string const& flag,
std::vector<std::string> const& value)
{
this->FlagMap[flag] = value;
@@ -185,7 +231,7 @@ void cmIDEOptions::AppendFlagString(std::string const& flag,
this->FlagMap[flag].append_with_space(value);
}
-void cmIDEOptions::RemoveFlag(const char* flag)
+void cmIDEOptions::RemoveFlag(std::string const& flag)
{
this->FlagMap.erase(flag);
}
@@ -195,12 +241,13 @@ bool cmIDEOptions::HasFlag(std::string const& flag) const
return this->FlagMap.find(flag) != this->FlagMap.end();
}
-const char* cmIDEOptions::GetFlag(const char* flag)
+const char* cmIDEOptions::GetFlag(std::string const& flag) const
{
// 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) {
+ std::map<std::string, FlagValue>::const_iterator i =
+ this->FlagMap.find(flag);
+ if (i != this->FlagMap.cend() && i->second.size() == 1) {
return i->second[0].c_str();
}
- return 0;
+ return nullptr;
}
diff --git a/Source/cmIDEOptions.h b/Source/cmIDEOptions.h
index 19e96bd44..4a430732f 100644
--- a/Source/cmIDEOptions.h
+++ b/Source/cmIDEOptions.h
@@ -3,7 +3,7 @@
#ifndef cmIDEOptions_h
#define cmIDEOptions_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
#include <string>
@@ -20,21 +20,26 @@ public:
cmIDEOptions();
virtual ~cmIDEOptions();
- // Store definitions and flags.
+ // Store definitions, includes and flags.
void AddDefine(const std::string& define);
- void AddDefines(const char* defines);
+ void AddDefines(std::string const& defines);
void AddDefines(const std::vector<std::string>& defines);
std::vector<std::string> const& GetDefines() const;
- void AddFlag(const char* flag, const char* value);
- void AddFlag(const char* flag, std::vector<std::string> const& value);
+ void AddInclude(const std::string& includes);
+ void AddIncludes(std::string const& includes);
+ void AddIncludes(const std::vector<std::string>& includes);
+ std::vector<std::string> const& GetIncludes() const;
+
+ void AddFlag(std::string const& flag, std::string const& value);
+ void AddFlag(std::string const& 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 AppendFlagString(std::string const& flag, std::string const& value);
- void RemoveFlag(const char* flag);
+ void RemoveFlag(std::string const& flag);
bool HasFlag(std::string const& flag) const;
- const char* GetFlag(const char* flag);
+ const char* GetFlag(std::string const& flag) const;
protected:
// create a map of xml tags to the values they should have in the output
@@ -60,12 +65,22 @@ protected:
this->derived::operator=(r);
return *this;
}
+ FlagValue& append_with_comma(std::string const& r)
+ {
+ return append_with_separator(r, ',');
+ }
FlagValue& append_with_space(std::string const& r)
{
+ return append_with_separator(r, ' ');
+ }
+
+ private:
+ FlagValue& append_with_separator(std::string const& r, char separator)
+ {
this->resize(1);
std::string& l = this->operator[](0);
if (!l.empty()) {
- l += " ";
+ l += separator;
}
l += r;
return *this;
@@ -76,8 +91,13 @@ protected:
// Preprocessor definitions.
std::vector<std::string> Defines;
+ // Include directories.
+ std::vector<std::string> Includes;
+
bool DoingDefine;
bool AllowDefine;
+ bool DoingInclude;
+ bool AllowInclude;
bool AllowSlash;
cmIDEFlagTable const* DoingFollowing;
enum
@@ -85,11 +105,12 @@ protected:
FlagTableCount = 16
};
cmIDEFlagTable const* FlagTable[FlagTableCount];
- void HandleFlag(const char* flag);
- bool CheckFlagTable(cmIDEFlagTable const* table, const char* flag,
+ void HandleFlag(std::string const& flag);
+ bool CheckFlagTable(cmIDEFlagTable const* table, std::string const& flag,
bool& flag_handled);
- void FlagMapUpdate(cmIDEFlagTable const* entry, const char* new_value);
- virtual void StoreUnknownFlag(const char* flag) = 0;
+ void FlagMapUpdate(cmIDEFlagTable const* entry,
+ std::string const& new_value);
+ virtual void StoreUnknownFlag(std::string const& flag) = 0;
};
#endif
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index 0972664a2..d1f8f58e2 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -6,19 +6,20 @@
#include "cmExecutionStatus.h"
#include "cmExpandedCommandArgument.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmOutputConverter.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
+#include <memory> // IWYU pragma: keep
+
static std::string cmIfCommandError(
std::vector<cmExpandedCommandArgument> const& args)
{
std::string err = "given arguments:\n ";
- for (std::vector<cmExpandedCommandArgument>::const_iterator i = args.begin();
- i != args.end(); ++i) {
+ for (cmExpandedCommandArgument const& i : args) {
err += " ";
- err += cmOutputConverter::EscapeForCMake(i->GetValue());
+ err += cmOutputConverter::EscapeForCMake(i.GetValue());
}
err += "\n";
return err;
@@ -30,38 +31,37 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
cmExecutionStatus& inStatus)
{
// we start by recording all the functions
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "if")) {
+ if (lff.Name.Lower == "if") {
this->ScopeDepth++;
- } else if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endif")) {
+ } else if (lff.Name.Lower == "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.
- CM_AUTO_PTR<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(this, lff));
- if (!fb.get()) {
+ std::unique_ptr<cmFunctionBlocker> fb(
+ mf.RemoveFunctionBlocker(this, lff));
+ if (!fb) {
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) {
+ for (cmListFileFunction const& func : this->Functions) {
// keep track of scope depth
- if (!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(), "if")) {
+ if (func.Name.Lower == "if") {
scopeDepth++;
}
- if (!cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),
- "endif")) {
+ if (func.Name.Lower == "endif") {
scopeDepth--;
}
// watch for our state change
- if (scopeDepth == 0 &&
- !cmSystemTools::Strucmp(this->Functions[c].Name.c_str(), "else")) {
+ if (scopeDepth == 0 && func.Name.Lower == "else") {
if (this->ElseSeen) {
- cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
+ cmListFileBacktrace bt = mf.GetBacktrace(func);
mf.GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"A duplicate ELSE command was found inside an IF block.", bt);
cmSystemTools::SetFatalErrorOccured();
return true;
@@ -74,15 +74,13 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
// if trace is enabled, print a (trivially) evaluated "else"
// statement
if (!this->IsBlocking && mf.GetCMakeInstance()->GetTrace()) {
- mf.PrintCommandTrace(this->Functions[c]);
+ mf.PrintCommandTrace(func);
}
- } else if (scopeDepth == 0 &&
- !cmSystemTools::Strucmp(this->Functions[c].Name.c_str(),
- "elseif")) {
+ } else if (scopeDepth == 0 && func.Name.Lower == "elseif") {
if (this->ElseSeen) {
- cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
+ cmListFileBacktrace bt = mf.GetBacktrace(func);
mf.GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"An ELSEIF command was found after an ELSE command.", bt);
cmSystemTools::SetFatalErrorOccured();
return true;
@@ -93,23 +91,22 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
} else {
// if trace is enabled, print the evaluated "elseif" statement
if (mf.GetCMakeInstance()->GetTrace()) {
- mf.PrintCommandTrace(this->Functions[c]);
+ mf.PrintCommandTrace(func);
}
std::string errorString;
std::vector<cmExpandedCommandArgument> expandedArguments;
- mf.ExpandArguments(this->Functions[c].Arguments,
- expandedArguments);
+ mf.ExpandArguments(func.Arguments, expandedArguments);
- cmake::MessageType messType;
+ MessageType messType;
cmListFileContext conditionContext =
cmListFileContext::FromCommandContext(
- this->Functions[c], this->GetStartingContext().FilePath);
+ func, this->GetStartingContext().FilePath);
- cmConditionEvaluator conditionEvaluator(
- mf, conditionContext, mf.GetBacktrace(this->Functions[c]));
+ cmConditionEvaluator conditionEvaluator(mf, conditionContext,
+ mf.GetBacktrace(func));
bool isTrue = conditionEvaluator.IsTrue(expandedArguments,
errorString, messType);
@@ -117,9 +114,9 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
if (!errorString.empty()) {
std::string err = cmIfCommandError(expandedArguments);
err += errorString;
- cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
+ cmListFileBacktrace bt = mf.GetBacktrace(func);
mf.GetCMakeInstance()->IssueMessage(messType, err, bt);
- if (messType == cmake::FATAL_ERROR) {
+ if (messType == MessageType::FATAL_ERROR) {
cmSystemTools::SetFatalErrorOccured();
return true;
}
@@ -135,7 +132,7 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
// should we execute?
else if (!this->IsBlocking) {
status.Clear();
- mf.ExecuteCommand(this->Functions[c], status);
+ mf.ExecuteCommand(func, status);
if (status.GetReturnInvoked()) {
inStatus.SetReturnInvoked();
return true;
@@ -165,7 +162,7 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
cmMakefile&)
{
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endif")) {
+ if (lff.Name.Lower == "endif") {
// if the endif has arguments, then make sure
// they match the arguments of the matching if
if (lff.Arguments.empty() || lff.Arguments == this->Args) {
@@ -185,7 +182,7 @@ bool cmIfCommand::InvokeInitialPass(
std::vector<cmExpandedCommandArgument> expandedArguments;
this->Makefile->ExpandArguments(args, expandedArguments);
- cmake::MessageType status;
+ MessageType status;
cmConditionEvaluator conditionEvaluator(
*(this->Makefile), this->Makefile->GetExecutionContext(),
@@ -197,8 +194,8 @@ bool cmIfCommand::InvokeInitialPass(
if (!errorString.empty()) {
std::string err = "if " + cmIfCommandError(expandedArguments);
err += errorString;
- if (status == cmake::FATAL_ERROR) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, err);
+ if (status == MessageType::FATAL_ERROR) {
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err);
cmSystemTools::SetFatalErrorOccured();
return true;
}
diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h
index 5877a7d12..d34ed02c8 100644
--- a/Source/cmIfCommand.h
+++ b/Source/cmIfCommand.h
@@ -3,7 +3,7 @@
#ifndef cmIfCommand_h
#define cmIfCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -19,23 +19,16 @@ class cmMakefile;
class cmIfFunctionBlocker : public cmFunctionBlocker
{
public:
- cmIfFunctionBlocker()
- {
- this->HasRun = false;
- this->ElseSeen = false;
- this->ScopeDepth = 0;
- }
- ~cmIfFunctionBlocker() CM_OVERRIDE {}
bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
- cmExecutionStatus&) CM_OVERRIDE;
- bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) CM_OVERRIDE;
+ cmExecutionStatus&) override;
+ bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) override;
std::vector<cmListFileArgument> Args;
std::vector<cmListFileFunction> Functions;
bool IsBlocking;
- bool HasRun;
- bool ElseSeen;
- unsigned int ScopeDepth;
+ bool HasRun = false;
+ bool ElseSeen = false;
+ unsigned int ScopeDepth = 0;
};
/// Starts an if block
@@ -45,21 +38,21 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmIfCommand; }
+ cmCommand* Clone() override { return new cmIfCommand; }
/**
* This overrides the default InvokeInitialPass implementation.
* It records the arguments before expansion.
*/
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
- cmExecutionStatus&) CM_OVERRIDE;
+ cmExecutionStatus&) override;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const&,
- cmExecutionStatus&) CM_OVERRIDE
+ cmExecutionStatus&) override
{
return false;
}
diff --git a/Source/cmIncludeCommand.cxx b/Source/cmIncludeCommand.cxx
index 12e0c9ab3..0d608bb9d 100644
--- a/Source/cmIncludeCommand.cxx
+++ b/Source/cmIncludeCommand.cxx
@@ -6,9 +6,9 @@
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmSystemTools.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -58,16 +58,16 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args,
}
if (fname.empty()) {
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING,
"include() given empty file name (ignored).");
return true;
}
- if (!cmSystemTools::FileIsFullPath(fname.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(fname)) {
// Not a path. Maybe module.
std::string module = fname;
module += ".cmake";
- std::string mfile = this->Makefile->GetModulesFile(module.c_str());
+ std::string mfile = this->Makefile->GetModulesFile(module);
if (!mfile.empty()) {
fname = mfile;
}
@@ -78,9 +78,9 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args,
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
if (gg->IsExportedTargetsFile(fname_abs)) {
- const char* modal = CM_NULLPTR;
+ const char* modal = nullptr;
std::ostringstream e;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0024)) {
case cmPolicies::WARN:
@@ -92,17 +92,18 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args,
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
modal = "may";
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
}
if (modal) {
- e << "The file\n " << fname_abs << "\nwas generated by the export() "
- "command. It "
+ 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) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
@@ -112,15 +113,14 @@ bool cmIncludeCommand::InitialPass(std::vector<std::string> const& args,
std::string listFile = cmSystemTools::CollapseFullPath(
fname, this->Makefile->GetCurrentSourceDirectory());
- if (optional && !cmSystemTools::FileExists(listFile.c_str())) {
+ if (optional && !cmSystemTools::FileExists(listFile)) {
if (!resultVarName.empty()) {
this->Makefile->AddDefinition(resultVarName, "NOTFOUND");
}
return true;
}
- bool readit =
- this->Makefile->ReadDependentFile(listFile.c_str(), noPolicyScope);
+ bool readit = this->Makefile->ReadDependentFile(listFile, noPolicyScope);
// add the location of the included file if a result variable was given
if (!resultVarName.empty()) {
diff --git a/Source/cmIncludeCommand.h b/Source/cmIncludeCommand.h
index 16dda0ef5..3b843b206 100644
--- a/Source/cmIncludeCommand.h
+++ b/Source/cmIncludeCommand.h
@@ -3,7 +3,7 @@
#ifndef cmIncludeCommand_h
#define cmIncludeCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmIncludeCommand; }
+ cmCommand* Clone() override { return new cmIncludeCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmIncludeDirectoryCommand.cxx b/Source/cmIncludeDirectoryCommand.cxx
index b81f7cb2d..62e2abdcd 100644
--- a/Source/cmIncludeDirectoryCommand.cxx
+++ b/Source/cmIncludeDirectoryCommand.cxx
@@ -4,7 +4,10 @@
#include <algorithm>
#include <set>
+#include <utility>
+#include "cmAlgorithms.h"
+#include "cmGeneratorExpression.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
@@ -50,11 +53,9 @@ bool cmIncludeDirectoryCommand::InitialPass(
this->GetIncludes(*i, includes);
if (before) {
- beforeIncludes.insert(beforeIncludes.end(), includes.begin(),
- includes.end());
+ cmAppend(beforeIncludes, includes);
} else {
- afterIncludes.insert(afterIncludes.end(), includes.begin(),
- includes.end());
+ cmAppend(afterIncludes, includes);
}
if (system) {
systemIncludes.insert(includes.begin(), includes.end());
@@ -69,15 +70,10 @@ bool cmIncludeDirectoryCommand::InitialPass(
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:
+// and newlines etc like below:
//
// " /foo/bar
// /boo/hoo /dingle/berry "
@@ -97,7 +93,7 @@ void cmIncludeDirectoryCommand::GetIncludes(const std::string& arg,
std::string inc = arg.substr(lastPos, pos);
this->NormalizeInclude(inc);
if (!inc.empty()) {
- incs.push_back(inc);
+ incs.push_back(std::move(inc));
}
}
lastPos = pos + 1;
@@ -105,7 +101,7 @@ void cmIncludeDirectoryCommand::GetIncludes(const std::string& arg,
std::string inc = arg.substr(lastPos);
this->NormalizeInclude(inc);
if (!inc.empty()) {
- incs.push_back(inc);
+ incs.push_back(std::move(inc));
}
}
@@ -116,15 +112,15 @@ void cmIncludeDirectoryCommand::NormalizeInclude(std::string& inc)
if ((b != std::string::npos) && (e != std::string::npos)) {
inc.assign(inc, b, 1 + e - b); // copy the remaining substring
} else {
- inc = "";
+ inc.clear();
return;
}
- if (!cmSystemTools::IsOff(inc.c_str())) {
+ if (!cmSystemTools::IsOff(inc)) {
cmSystemTools::ConvertToUnixSlashes(inc);
- if (!cmSystemTools::FileIsFullPath(inc.c_str())) {
- if (!StartsWithGeneratorExpression(inc)) {
+ if (!cmSystemTools::FileIsFullPath(inc)) {
+ if (!cmGeneratorExpression::StartsWithGeneratorExpression(inc)) {
std::string tmp = this->Makefile->GetCurrentSourceDirectory();
tmp += "/";
tmp += inc;
diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h
index 12de698cb..01d98dbc0 100644
--- a/Source/cmIncludeDirectoryCommand.h
+++ b/Source/cmIncludeDirectoryCommand.h
@@ -3,7 +3,7 @@
#ifndef cmIncludeDirectoryCommand_h
#define cmIncludeDirectoryCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmIncludeDirectoryCommand; }
+ cmCommand* Clone() override { return new cmIncludeDirectoryCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
// used internally
diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx
index 03388c7e9..93134adb6 100644
--- a/Source/cmIncludeExternalMSProjectCommand.cxx
+++ b/Source/cmIncludeExternalMSProjectCommand.cxx
@@ -3,10 +3,12 @@
#include "cmIncludeExternalMSProjectCommand.h"
#ifdef _WIN32
-#include "cmMakefile.h"
-#include "cmStateTypes.h"
-#include "cmSystemTools.h"
-#include "cmTarget.h"
+# include "cmGlobalGenerator.h"
+# include "cmMakefile.h"
+# include "cmStateTypes.h"
+# include "cmSystemTools.h"
+# include "cmTarget.h"
+# include "cmake.h"
#endif
class cmExecutionStatus;
@@ -22,7 +24,9 @@ bool cmIncludeExternalMSProjectCommand::InitialPass(
}
// only compile this for win32 to avoid coverage errors
#ifdef _WIN32
- if (this->Makefile->GetDefinition("WIN32")) {
+ if (this->Makefile->GetDefinition("WIN32") ||
+ this->Makefile->GetGlobalGenerator()
+ ->IsIncludeExternalMSProjectSupported()) {
enum Doing
{
DoingNone,
@@ -81,19 +85,20 @@ bool cmIncludeExternalMSProjectCommand::InitialPass(
// Create a target instance for this utility.
cmTarget* target = this->Makefile->AddNewTarget(cmStateEnums::UTILITY,
utility_name.c_str());
+ if (this->Makefile->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
+ target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
+ }
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());
+ for (std::string const& d : depends) {
+ target->AddUtility(d.c_str());
}
}
#endif
diff --git a/Source/cmIncludeExternalMSProjectCommand.h b/Source/cmIncludeExternalMSProjectCommand.h
index 375646fa6..945acdc13 100644
--- a/Source/cmIncludeExternalMSProjectCommand.h
+++ b/Source/cmIncludeExternalMSProjectCommand.h
@@ -3,7 +3,7 @@
#ifndef cmIncludeExternalMSProjectCommand_h
#define cmIncludeExternalMSProjectCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,17 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
- {
- return new cmIncludeExternalMSProjectCommand;
- }
+ cmCommand* Clone() override { return new cmIncludeExternalMSProjectCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmIncludeRegularExpressionCommand.h b/Source/cmIncludeRegularExpressionCommand.h
index bac4b8fc3..8da991d08 100644
--- a/Source/cmIncludeRegularExpressionCommand.h
+++ b/Source/cmIncludeRegularExpressionCommand.h
@@ -3,7 +3,7 @@
#ifndef cmIncludeRegularExpressionCommand_h
#define cmIncludeRegularExpressionCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,17 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
- {
- return new cmIncludeRegularExpressionCommand;
- }
+ cmCommand* Clone() override { return new cmIncludeRegularExpressionCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx
index 294fb178d..c9e692333 100644
--- a/Source/cmInstallCommand.cxx
+++ b/Source/cmInstallCommand.cxx
@@ -2,12 +2,15 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallCommand.h"
+#include "cm_static_string_view.hxx"
#include "cmsys/Glob.hxx"
+#include <set>
#include <sstream>
#include <stddef.h>
+#include <utility>
#include "cmAlgorithms.h"
-#include "cmCommandArgumentsHelper.h"
+#include "cmArgumentParser.h"
#include "cmExportSet.h"
#include "cmExportSetMap.h"
#include "cmGeneratorExpression.h"
@@ -19,43 +22,73 @@
#include "cmInstallGenerator.h"
#include "cmInstallScriptGenerator.h"
#include "cmInstallTargetGenerator.h"
+#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetExport.h"
-#include "cmake.h"
class cmExecutionStatus;
static cmInstallTargetGenerator* CreateInstallTargetGenerator(
cmTarget& target, const cmInstallCommandArguments& args, bool impLib,
- bool forceOpt = false)
+ cmListFileBacktrace const& backtrace, const std::string& destination,
+ bool forceOpt = false, bool namelink = false)
{
cmInstallGenerator::MessageLevel message =
cmInstallGenerator::SelectMessageLevel(target.GetMakefile());
target.SetHaveInstallRule(true);
- return new cmInstallTargetGenerator(
- target.GetName(), args.GetDestination().c_str(), impLib,
- args.GetPermissions().c_str(), args.GetConfigurations(),
- args.GetComponent().c_str(), message, args.GetExcludeFromAll(),
- args.GetOptional() || forceOpt);
+ const char* component = namelink ? args.GetNamelinkComponent().c_str()
+ : args.GetComponent().c_str();
+ auto g = new cmInstallTargetGenerator(
+ target.GetName(), destination.c_str(), impLib,
+ args.GetPermissions().c_str(), args.GetConfigurations(), component,
+ message, args.GetExcludeFromAll(), args.GetOptional() || forceOpt,
+ backtrace);
+ target.AddInstallGenerator(g);
+ return g;
+}
+
+static cmInstallTargetGenerator* CreateInstallTargetGenerator(
+ cmTarget& target, const cmInstallCommandArguments& args, bool impLib,
+ cmListFileBacktrace const& backtrace, bool forceOpt = false,
+ bool namelink = false)
+{
+ return CreateInstallTargetGenerator(target, args, impLib, backtrace,
+ args.GetDestination(), forceOpt,
+ namelink);
}
static cmInstallFilesGenerator* CreateInstallFilesGenerator(
cmMakefile* mf, const std::vector<std::string>& absFiles,
- const cmInstallCommandArguments& args, bool programs)
+ const cmInstallCommandArguments& args, bool programs,
+ const std::string& destination)
{
cmInstallGenerator::MessageLevel message =
cmInstallGenerator::SelectMessageLevel(mf);
return new cmInstallFilesGenerator(
- absFiles, args.GetDestination().c_str(), programs,
- args.GetPermissions().c_str(), args.GetConfigurations(),
- args.GetComponent().c_str(), message, args.GetExcludeFromAll(),
- args.GetRename().c_str(), args.GetOptional());
+ absFiles, destination.c_str(), programs, args.GetPermissions().c_str(),
+ args.GetConfigurations(), args.GetComponent().c_str(), message,
+ args.GetExcludeFromAll(), args.GetRename().c_str(), args.GetOptional());
+}
+
+static cmInstallFilesGenerator* CreateInstallFilesGenerator(
+ cmMakefile* mf, const std::vector<std::string>& absFiles,
+ const cmInstallCommandArguments& args, bool programs)
+{
+ return CreateInstallFilesGenerator(mf, absFiles, args, programs,
+ args.GetDestination());
}
+static const std::set<std::string> allowedTypes{
+ "BIN", "SBIN", "LIB", "INCLUDE", "SYSCONF",
+ "SHAREDSTATE", "LOCALSTATE", "RUNSTATE", "DATA", "INFO",
+ "LOCALE", "MAN", "DOC",
+};
+
// cmInstallCommand
bool cmInstallCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
@@ -141,23 +174,23 @@ bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
// 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") {
+ for (std::string const& arg : args) {
+ if (arg == "SCRIPT") {
doing_script = true;
doing_code = false;
- } else if (args[i] == "CODE") {
+ } else if (arg == "CODE") {
doing_script = false;
doing_code = true;
- } else if (args[i] == "COMPONENT") {
+ } else if (arg == "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())) {
+ std::string script = arg;
+ if (!cmSystemTools::FileIsFullPath(script)) {
script = this->Makefile->GetCurrentSourceDirectory();
script += "/";
- script += args[i];
+ script += arg;
}
if (cmSystemTools::FileIsDirectory(script)) {
this->SetError("given a directory as value of SCRIPT argument.");
@@ -167,7 +200,7 @@ bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
script.c_str(), false, component.c_str(), exclude_from_all));
} else if (doing_code) {
doing_code = false;
- std::string const& code = args[i];
+ std::string const& code = arg;
this->Makefile->AddInstallGenerator(new cmInstallScriptGenerator(
code.c_str(), true, component.c_str(), exclude_from_all));
}
@@ -184,54 +217,56 @@ bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
// Tell the global generator about any installation component names
// specified.
- this->Makefile->GetGlobalGenerator()->AddInstallComponent(component.c_str());
+ this->Makefile->GetGlobalGenerator()->AddInstallComponent(component);
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, CM_NULLPTR);
- cmCAStringVector archiveArgVector(&argHelper, "ARCHIVE", &group);
- cmCAStringVector libraryArgVector(&argHelper, "LIBRARY", &group);
- cmCAStringVector runtimeArgVector(&argHelper, "RUNTIME", &group);
- cmCAStringVector objectArgVector(&argHelper, "OBJECTS", &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(CM_NULLPTR);
- group.Follows(&genericArgVector);
-
- argHelper.Parse(&args, CM_NULLPTR);
+ struct ArgVectors
+ {
+ std::vector<std::string> Archive;
+ std::vector<std::string> Library;
+ std::vector<std::string> Runtime;
+ std::vector<std::string> Object;
+ std::vector<std::string> Framework;
+ std::vector<std::string> Bundle;
+ std::vector<std::string> Includes;
+ std::vector<std::string> PrivateHeader;
+ std::vector<std::string> PublicHeader;
+ std::vector<std::string> Resource;
+ };
+
+ static auto const argHelper =
+ cmArgumentParser<ArgVectors>{}
+ .Bind("ARCHIVE"_s, &ArgVectors::Archive)
+ .Bind("LIBRARY"_s, &ArgVectors::Library)
+ .Bind("RUNTIME"_s, &ArgVectors::Runtime)
+ .Bind("OBJECTS"_s, &ArgVectors::Object)
+ .Bind("FRAMEWORK"_s, &ArgVectors::Framework)
+ .Bind("BUNDLE"_s, &ArgVectors::Bundle)
+ .Bind("INCLUDES"_s, &ArgVectors::Includes)
+ .Bind("PRIVATE_HEADER"_s, &ArgVectors::PrivateHeader)
+ .Bind("PUBLIC_HEADER"_s, &ArgVectors::PublicHeader)
+ .Bind("RESOURCE"_s, &ArgVectors::Resource);
+
+ std::vector<std::string> genericArgVector;
+ ArgVectors const argVectors = argHelper.Parse(args, &genericArgVector);
// 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> targetList;
+ std::string exports;
std::vector<std::string> unknownArgs;
cmInstallCommandArguments genericArgs(this->DefaultComponentName);
- cmCAStringVector targetList(&genericArgs.Parser, "TARGETS");
- cmCAString exports(&genericArgs.Parser, "EXPORT",
- &genericArgs.ArgumentGroup);
- targetList.Follows(CM_NULLPTR);
- genericArgs.ArgumentGroup.Follows(&targetList);
- genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs);
+ genericArgs.Bind("TARGETS"_s, targetList);
+ genericArgs.Bind("EXPORT"_s, exports);
+ genericArgs.Parse(genericArgVector, &unknownArgs);
bool success = genericArgs.Finalize();
cmInstallCommandArguments archiveArgs(this->DefaultComponentName);
@@ -247,16 +282,16 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// 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);
- objectArgs.Parse(&objectArgVector.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);
+ archiveArgs.Parse(argVectors.Archive, &unknownArgs);
+ libraryArgs.Parse(argVectors.Library, &unknownArgs);
+ runtimeArgs.Parse(argVectors.Runtime, &unknownArgs);
+ objectArgs.Parse(argVectors.Object, &unknownArgs);
+ frameworkArgs.Parse(argVectors.Framework, &unknownArgs);
+ bundleArgs.Parse(argVectors.Bundle, &unknownArgs);
+ privateHeaderArgs.Parse(argVectors.PrivateHeader, &unknownArgs);
+ publicHeaderArgs.Parse(argVectors.PublicHeader, &unknownArgs);
+ resourceArgs.Parse(argVectors.Resource, &unknownArgs);
+ includesArgs.Parse(&argVectors.Includes, &unknownArgs);
if (!unknownArgs.empty()) {
// Unknown argument.
@@ -311,11 +346,36 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
"The NAMELINK_SKIP option may be specified only following LIBRARY.");
return false;
}
+ if (archiveArgs.HasNamelinkComponent() ||
+ runtimeArgs.HasNamelinkComponent() ||
+ objectArgs.HasNamelinkComponent() ||
+ frameworkArgs.HasNamelinkComponent() ||
+ bundleArgs.HasNamelinkComponent() ||
+ privateHeaderArgs.HasNamelinkComponent() ||
+ publicHeaderArgs.HasNamelinkComponent() ||
+ resourceArgs.HasNamelinkComponent()) {
+ this->SetError(
+ "TARGETS given NAMELINK_COMPONENT option not in LIBRARY group. "
+ "The NAMELINK_COMPONENT 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;
}
+ if (!genericArgs.GetType().empty() || !archiveArgs.GetType().empty() ||
+ !libraryArgs.GetType().empty() || !runtimeArgs.GetType().empty() ||
+ !objectArgs.GetType().empty() || !frameworkArgs.GetType().empty() ||
+ !bundleArgs.GetType().empty() || !privateHeaderArgs.GetType().empty() ||
+ !publicHeaderArgs.GetType().empty() || !resourceArgs.GetType().empty()) {
+ std::ostringstream e;
+ e << "TARGETS given TYPE option. The TYPE option may only be specified in "
+ " install(FILES) and install(DIRECTORIES).";
+ this->SetError(e.str());
+ return false;
+ }
// Select the mode for installing symlinks to versioned shared libraries.
cmInstallTargetGenerator::NamelinkModeType namelinkMode =
@@ -327,28 +387,33 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
// Check if there is something to do.
- if (targetList.GetVector().empty()) {
+ if (targetList.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"));
+ !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty();
- for (std::vector<std::string>::const_iterator targetIt =
- targetList.GetVector().begin();
- targetIt != targetList.GetVector().end(); ++targetIt) {
+ for (std::string const& tgt : targetList) {
- if (this->Makefile->IsAlias(*targetIt)) {
+ if (this->Makefile->IsAlias(tgt)) {
std::ostringstream e;
- e << "TARGETS given target \"" << (*targetIt) << "\" which is an alias.";
+ e << "TARGETS given target \"" << tgt << "\" which is an alias.";
this->SetError(e.str());
return false;
}
// Lookup this target in the current directory.
- if (cmTarget* target =
- this->Makefile->FindLocalNonAliasTarget(*targetIt)) {
+ cmTarget* target = this->Makefile->FindLocalNonAliasTarget(tgt);
+ if (!target) {
+ // If no local target has been found, find it in the global scope.
+ cmTarget* const global_target =
+ this->Makefile->GetGlobalGenerator()->FindTarget(tgt, true);
+ if (global_target && !global_target->IsImported()) {
+ target = global_target;
+ }
+ }
+ if (target) {
// Found the target. Check its type.
if (target->GetType() != cmStateEnums::EXECUTABLE &&
target->GetType() != cmStateEnums::STATIC_LIBRARY &&
@@ -357,29 +422,17 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
target->GetType() != cmStateEnums::OBJECT_LIBRARY &&
target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
std::ostringstream e;
- e << "TARGETS given target \"" << (*targetIt)
+ e << "TARGETS given target \"" << tgt
<< "\" which is not an executable, library, or module.";
this->SetError(e.str());
return false;
}
- if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- std::string reason;
- if (!this->Makefile->GetGlobalGenerator()->HasKnownObjectFileLocation(
- &reason)) {
- std::ostringstream e;
- e << "TARGETS given OBJECT library \"" << (*targetIt)
- << "\" which may not be installed" << reason << ".";
- 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.
std::ostringstream e;
- e << "TARGETS given target \"" << (*targetIt)
- << "\" which does not exist in this directory.";
+ e << "TARGETS given target \"" << tgt << "\" which does not exist.";
this->SetError(e.str());
return false;
}
@@ -389,6 +442,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// any files of the given type.
bool installsArchive = false;
bool installsLibrary = false;
+ bool installsNamelink = false;
bool installsRuntime = false;
bool installsObject = false;
bool installsFramework = false;
@@ -398,19 +452,19 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
bool installsResource = false;
// Generate install script code to install the given targets.
- for (std::vector<cmTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
+ for (cmTarget* ti : targets) {
// Handle each target type.
- cmTarget& target = *(*ti);
- cmInstallTargetGenerator* archiveGenerator = CM_NULLPTR;
- cmInstallTargetGenerator* libraryGenerator = CM_NULLPTR;
- cmInstallTargetGenerator* runtimeGenerator = CM_NULLPTR;
- cmInstallTargetGenerator* objectGenerator = CM_NULLPTR;
- cmInstallTargetGenerator* frameworkGenerator = CM_NULLPTR;
- cmInstallTargetGenerator* bundleGenerator = CM_NULLPTR;
- cmInstallFilesGenerator* privateHeaderGenerator = CM_NULLPTR;
- cmInstallFilesGenerator* publicHeaderGenerator = CM_NULLPTR;
- cmInstallFilesGenerator* resourceGenerator = CM_NULLPTR;
+ cmTarget& target = *ti;
+ cmInstallTargetGenerator* archiveGenerator = nullptr;
+ cmInstallTargetGenerator* libraryGenerator = nullptr;
+ cmInstallTargetGenerator* namelinkGenerator = nullptr;
+ cmInstallTargetGenerator* runtimeGenerator = nullptr;
+ cmInstallTargetGenerator* objectGenerator = nullptr;
+ cmInstallTargetGenerator* frameworkGenerator = nullptr;
+ cmInstallTargetGenerator* bundleGenerator = nullptr;
+ cmInstallFilesGenerator* privateHeaderGenerator = nullptr;
+ cmInstallFilesGenerator* publicHeaderGenerator = nullptr;
+ cmInstallFilesGenerator* resourceGenerator = nullptr;
// Track whether this is a namelink-only rule.
bool namelinkOnly = false;
@@ -429,18 +483,21 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// This is a DLL platform.
if (!archiveArgs.GetDestination().empty()) {
// The import library uses the ARCHIVE properties.
- archiveGenerator =
- CreateInstallTargetGenerator(target, archiveArgs, true);
+ archiveGenerator = CreateInstallTargetGenerator(
+ target, archiveArgs, true, this->Makefile->GetBacktrace());
}
if (!runtimeArgs.GetDestination().empty()) {
// The DLL uses the RUNTIME properties.
- runtimeGenerator =
- CreateInstallTargetGenerator(target, runtimeArgs, false);
+ runtimeGenerator = CreateInstallTargetGenerator(
+ target, runtimeArgs, false, this->Makefile->GetBacktrace());
}
- if ((archiveGenerator == CM_NULLPTR) &&
- (runtimeGenerator == CM_NULLPTR)) {
- this->SetError("Library TARGETS given no DESTINATION!");
- return false;
+ if ((archiveGenerator == nullptr) && (runtimeGenerator == nullptr)) {
+ archiveGenerator = CreateInstallTargetGenerator(
+ target, archiveArgs, true, this->Makefile->GetBacktrace(),
+ this->GetArchiveDestination(nullptr));
+ runtimeGenerator = CreateInstallTargetGenerator(
+ target, runtimeArgs, false, this->Makefile->GetBacktrace(),
+ this->GetRuntimeDestination(nullptr));
}
} else {
// This is a non-DLL platform.
@@ -454,8 +511,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Use the FRAMEWORK properties.
if (!frameworkArgs.GetDestination().empty()) {
- frameworkGenerator =
- CreateInstallTargetGenerator(target, frameworkArgs, false);
+ frameworkGenerator = CreateInstallTargetGenerator(
+ target, frameworkArgs, false, this->Makefile->GetBacktrace());
} else {
std::ostringstream e;
e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
@@ -466,20 +523,22 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
} 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 {
- std::ostringstream e;
- e << "TARGETS given no LIBRARY DESTINATION for shared library "
- "target \""
- << target.GetName() << "\".";
- this->SetError(e.str());
- return false;
+ if (namelinkMode != cmInstallTargetGenerator::NamelinkModeOnly) {
+ libraryGenerator = CreateInstallTargetGenerator(
+ target, libraryArgs, false, this->Makefile->GetBacktrace(),
+ this->GetLibraryDestination(&libraryArgs));
+ libraryGenerator->SetNamelinkMode(
+ cmInstallTargetGenerator::NamelinkModeSkip);
}
+ if (namelinkMode != cmInstallTargetGenerator::NamelinkModeSkip) {
+ namelinkGenerator = CreateInstallTargetGenerator(
+ target, libraryArgs, false, this->Makefile->GetBacktrace(),
+ this->GetLibraryDestination(&libraryArgs), false, true);
+ namelinkGenerator->SetNamelinkMode(
+ cmInstallTargetGenerator::NamelinkModeOnly);
+ }
+ namelinkOnly =
+ (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
}
}
} break;
@@ -494,8 +553,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Use the FRAMEWORK properties.
if (!frameworkArgs.GetDestination().empty()) {
- frameworkGenerator =
- CreateInstallTargetGenerator(target, frameworkArgs, false);
+ frameworkGenerator = CreateInstallTargetGenerator(
+ target, frameworkArgs, false, this->Makefile->GetBacktrace());
} else {
std::ostringstream e;
e << "TARGETS given no FRAMEWORK DESTINATION for static library "
@@ -506,24 +565,16 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
} else {
// Static libraries use ARCHIVE properties.
- if (!archiveArgs.GetDestination().empty()) {
- archiveGenerator =
- CreateInstallTargetGenerator(target, archiveArgs, false);
- } else {
- std::ostringstream e;
- e << "TARGETS given no ARCHIVE DESTINATION for static library "
- "target \""
- << target.GetName() << "\".";
- this->SetError(e.str());
- return false;
- }
+ archiveGenerator = CreateInstallTargetGenerator(
+ target, archiveArgs, false, this->Makefile->GetBacktrace(),
+ this->GetArchiveDestination(&archiveArgs));
}
} break;
case cmStateEnums::MODULE_LIBRARY: {
// Modules use LIBRARY properties.
if (!libraryArgs.GetDestination().empty()) {
- libraryGenerator =
- CreateInstallTargetGenerator(target, libraryArgs, false);
+ libraryGenerator = CreateInstallTargetGenerator(
+ target, libraryArgs, false, this->Makefile->GetBacktrace());
libraryGenerator->SetNamelinkMode(namelinkMode);
namelinkOnly =
(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
@@ -538,30 +589,38 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
case cmStateEnums::OBJECT_LIBRARY: {
// Objects use OBJECT properties.
if (!objectArgs.GetDestination().empty()) {
- objectGenerator =
- CreateInstallTargetGenerator(target, objectArgs, false);
+ // Verify that we know where the objects are to install them.
+ std::string reason;
+ if (!this->Makefile->GetGlobalGenerator()
+ ->HasKnownObjectFileLocation(&reason)) {
+ std::ostringstream e;
+ e << "TARGETS given OBJECT library \"" << target.GetName()
+ << "\" whose objects may not be installed" << reason << ".";
+ this->SetError(e.str());
+ return false;
+ }
+
+ objectGenerator = CreateInstallTargetGenerator(
+ target, objectArgs, false, this->Makefile->GetBacktrace());
} else {
- std::ostringstream e;
- e << "TARGETS given no OBJECTS DESTINATION for object library "
- "target \""
- << target.GetName() << "\".";
- this->SetError(e.str());
- return false;
+ // Installing an OBJECT library without a destination transforms
+ // it to an INTERFACE library. It installs no files but can be
+ // exported.
}
} break;
case cmStateEnums::EXECUTABLE: {
if (target.IsAppBundleOnApple()) {
// Application bundles use the BUNDLE properties.
if (!bundleArgs.GetDestination().empty()) {
- bundleGenerator =
- CreateInstallTargetGenerator(target, bundleArgs, false);
+ bundleGenerator = CreateInstallTargetGenerator(
+ target, bundleArgs, false, this->Makefile->GetBacktrace());
} 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);
+ bundleGenerator = CreateInstallTargetGenerator(
+ target, runtimeArgs, false, this->Makefile->GetBacktrace());
} else if (failure) {
return false;
}
@@ -576,17 +635,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
} else {
// Executables use the RUNTIME properties.
- if (!runtimeArgs.GetDestination().empty()) {
- runtimeGenerator =
- CreateInstallTargetGenerator(target, runtimeArgs, false);
- } else {
- std::ostringstream e;
- e << "TARGETS given no RUNTIME DESTINATION for executable "
- "target \""
- << target.GetName() << "\".";
- this->SetError(e.str());
- return false;
- }
+ runtimeGenerator = CreateInstallTargetGenerator(
+ target, runtimeArgs, false, this->Makefile->GetBacktrace(),
+ this->GetRuntimeDestination(&runtimeArgs));
}
// On DLL platforms an executable may also have an import
@@ -595,8 +646,8 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
if (dll_platform && !archiveArgs.GetDestination().empty() &&
target.IsExecutableWithExports()) {
// The import library uses the ARCHIVE properties.
- archiveGenerator =
- CreateInstallTargetGenerator(target, archiveArgs, true, true);
+ archiveGenerator = CreateInstallTargetGenerator(
+ target, archiveArgs, true, this->Makefile->GetBacktrace(), true);
}
} break;
case cmStateEnums::INTERFACE_LIBRARY:
@@ -617,8 +668,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// generators for them.
bool createInstallGeneratorsForTargetFileSets = true;
- if (target.IsFrameworkOnApple() ||
- target.GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ if (target.IsFrameworkOnApple()) {
createInstallGeneratorsForTargetFileSets = false;
}
@@ -633,15 +683,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
// Create the files install generator.
- if (!privateHeaderArgs.GetDestination().empty()) {
- privateHeaderGenerator = CreateInstallFilesGenerator(
- this->Makefile, absFiles, privateHeaderArgs, false);
- } else {
- std::ostringstream e;
- e << "INSTALL TARGETS - target " << target.GetName() << " has "
- << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
- cmSystemTools::Message(e.str().c_str(), "Warning");
- }
+ privateHeaderGenerator = CreateInstallFilesGenerator(
+ this->Makefile, absFiles, privateHeaderArgs, false,
+ this->GetIncludeDestination(&privateHeaderArgs));
}
files = target.GetProperty("PUBLIC_HEADER");
@@ -654,15 +698,9 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
}
// Create the files install generator.
- if (!publicHeaderArgs.GetDestination().empty()) {
- publicHeaderGenerator = CreateInstallFilesGenerator(
- this->Makefile, absFiles, publicHeaderArgs, false);
- } else {
- std::ostringstream e;
- e << "INSTALL TARGETS - target " << target.GetName() << " has "
- << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
- cmSystemTools::Message(e.str().c_str(), "Warning");
- }
+ publicHeaderGenerator = CreateInstallFilesGenerator(
+ this->Makefile, absFiles, publicHeaderArgs, false,
+ this->GetIncludeDestination(&publicHeaderArgs));
}
files = target.GetProperty("RESOURCE");
@@ -682,26 +720,28 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
std::ostringstream e;
e << "INSTALL TARGETS - target " << target.GetName() << " has "
<< "RESOURCE files but no RESOURCE DESTINATION.";
- cmSystemTools::Message(e.str().c_str(), "Warning");
+ cmSystemTools::Message(e.str(), "Warning");
}
}
}
// Keep track of whether we're installing anything in each category
- installsArchive = installsArchive || archiveGenerator != CM_NULLPTR;
- installsLibrary = installsLibrary || libraryGenerator != CM_NULLPTR;
- installsRuntime = installsRuntime || runtimeGenerator != CM_NULLPTR;
- installsObject = installsObject || objectGenerator != CM_NULLPTR;
- installsFramework = installsFramework || frameworkGenerator != CM_NULLPTR;
- installsBundle = installsBundle || bundleGenerator != CM_NULLPTR;
+ installsArchive = installsArchive || archiveGenerator != nullptr;
+ installsLibrary = installsLibrary || libraryGenerator != nullptr;
+ installsNamelink = installsNamelink || namelinkGenerator != nullptr;
+ installsRuntime = installsRuntime || runtimeGenerator != nullptr;
+ installsObject = installsObject || objectGenerator != nullptr;
+ installsFramework = installsFramework || frameworkGenerator != nullptr;
+ installsBundle = installsBundle || bundleGenerator != nullptr;
installsPrivateHeader =
- installsPrivateHeader || privateHeaderGenerator != CM_NULLPTR;
+ installsPrivateHeader || privateHeaderGenerator != nullptr;
installsPublicHeader =
- installsPublicHeader || publicHeaderGenerator != CM_NULLPTR;
+ installsPublicHeader || publicHeaderGenerator != nullptr;
installsResource = installsResource || resourceGenerator;
this->Makefile->AddInstallGenerator(archiveGenerator);
this->Makefile->AddInstallGenerator(libraryGenerator);
+ this->Makefile->AddInstallGenerator(namelinkGenerator);
this->Makefile->AddInstallGenerator(runtimeGenerator);
this->Makefile->AddInstallGenerator(objectGenerator);
this->Makefile->AddInstallGenerator(frameworkGenerator);
@@ -712,7 +752,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// Add this install rule to an export if one was specified and
// this is not a namelink-only rule.
- if (!exports.GetString().empty() && !namelinkOnly) {
+ if (!exports.empty() && !namelinkOnly) {
cmTargetExport* te = new cmTargetExport;
te->TargetName = target.GetName();
te->ArchiveGenerator = archiveGenerator;
@@ -723,7 +763,7 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
te->RuntimeGenerator = runtimeGenerator;
te->ObjectsGenerator = objectGenerator;
this->Makefile->GetGlobalGenerator()
- ->GetExportSets()[exports.GetString()]
+ ->GetExportSets()[exports]
->AddTargetExport(te);
te->InterfaceIncludeDirectories =
@@ -735,39 +775,43 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
// specified
if (installsArchive) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- archiveArgs.GetComponent().c_str());
+ archiveArgs.GetComponent());
}
if (installsLibrary) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- libraryArgs.GetComponent().c_str());
+ libraryArgs.GetComponent());
+ }
+ if (installsNamelink) {
+ this->Makefile->GetGlobalGenerator()->AddInstallComponent(
+ libraryArgs.GetNamelinkComponent());
}
if (installsRuntime) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- runtimeArgs.GetComponent().c_str());
+ runtimeArgs.GetComponent());
}
if (installsObject) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- objectArgs.GetComponent().c_str());
+ objectArgs.GetComponent());
}
if (installsFramework) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- frameworkArgs.GetComponent().c_str());
+ frameworkArgs.GetComponent());
}
if (installsBundle) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- bundleArgs.GetComponent().c_str());
+ bundleArgs.GetComponent());
}
if (installsPrivateHeader) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- privateHeaderArgs.GetComponent().c_str());
+ privateHeaderArgs.GetComponent());
}
if (installsPublicHeader) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- publicHeaderArgs.GetComponent().c_str());
+ publicHeaderArgs.GetComponent());
}
if (installsResource) {
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- resourceArgs.GetComponent().c_str());
+ resourceArgs.GetComponent());
}
return true;
@@ -778,11 +822,10 @@ 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(CM_NULLPTR);
- ica.ArgumentGroup.Follows(&files);
+ std::vector<std::string> files;
+ ica.Bind(programs ? "PROGRAMS"_s : "FILES"_s, files);
std::vector<std::string> unknownArgs;
- ica.Parse(&args, &unknownArgs);
+ ica.Parse(args, &unknownArgs);
if (!unknownArgs.empty()) {
// Unknown argument.
@@ -792,7 +835,15 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
return false;
}
- const std::vector<std::string>& filesVector = files.GetVector();
+ std::string type = ica.GetType();
+ if (!type.empty() && allowedTypes.count(type) == 0) {
+ std::ostringstream e;
+ e << args[0] << " given non-type \"" << type << "\" with TYPE argument.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ const std::vector<std::string>& filesVector = files;
// Check if there is something to do.
if (filesVector.empty()) {
@@ -816,12 +867,11 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
this->Makefile->GetPolicyStatus(cmPolicies::CMP0062);
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
- for (std::vector<std::string>::const_iterator fileIt = filesVector.begin();
- fileIt != filesVector.end(); ++fileIt) {
- if (gg->IsExportedTargetsFile(*fileIt)) {
- const char* modal = CM_NULLPTR;
+ for (std::string const& file : filesVector) {
+ if (gg->IsExportedTargetsFile(file)) {
+ const char* modal = nullptr;
std::ostringstream e;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (status) {
case cmPolicies::WARN:
@@ -833,16 +883,18 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
modal = "may";
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
}
if (modal) {
- e << "The file\n " << *fileIt << "\nwas generated by the export() "
- "command. It "
- << modal << " not be installed with the "
- "install() command. Use the install(EXPORT) mechanism "
- "instead. See the cmake-packages(7) manual for more.\n";
+ e << "The file\n " << file
+ << "\nwas generated by the export() "
+ "command. It "
+ << modal
+ << " not be installed with the "
+ "install() command. Use the install(EXPORT) mechanism "
+ "instead. See the cmake-packages(7) manual for more.\n";
this->Makefile->IssueMessage(messageType, e.str());
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
@@ -853,7 +905,17 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
return false;
}
- if (ica.GetDestination().empty()) {
+ if (!type.empty() && !ica.GetDestination().empty()) {
+ std::ostringstream e;
+ e << args[0]
+ << " given both TYPE and DESTINATION arguments. You may only specify "
+ "one.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ std::string destination = this->GetDestinationForType(&ica, type);
+ if (destination.empty()) {
// A destination is required.
std::ostringstream e;
e << args[0] << " given no DESTINATION!";
@@ -862,13 +924,13 @@ bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
}
// Create the files install generator.
- this->Makefile->AddInstallGenerator(
- CreateInstallFilesGenerator(this->Makefile, absFiles, ica, programs));
+ this->Makefile->AddInstallGenerator(CreateInstallFilesGenerator(
+ this->Makefile, absFiles, ica, programs, destination));
// Tell the global generator about any installation component names
// specified.
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
- ica.GetComponent().c_str());
+ ica.GetComponent());
return true;
}
@@ -887,7 +949,8 @@ bool cmInstallCommand::HandleDirectoryMode(
DoingPermsDir,
DoingPermsMatch,
DoingConfigurations,
- DoingComponent
+ DoingComponent,
+ DoingType
};
Doing doing = DoingDirs;
bool in_match_mode = false;
@@ -895,12 +958,13 @@ bool cmInstallCommand::HandleDirectoryMode(
bool exclude_from_all = false;
bool message_never = false;
std::vector<std::string> dirs;
- const char* destination = CM_NULLPTR;
+ const char* destination = nullptr;
std::string permissions_file;
std::string permissions_dir;
std::vector<std::string> configurations;
std::string component = this->DefaultComponentName;
std::string literal_args;
+ std::string type;
for (unsigned int i = 1; i < args.size(); ++i) {
if (args[i] == "DESTINATION") {
if (in_match_mode) {
@@ -913,6 +977,17 @@ bool cmInstallCommand::HandleDirectoryMode(
// Switch to setting the destination property.
doing = DoingDestination;
+ } else if (args[i] == "TYPE") {
+ if (in_match_mode) {
+ std::ostringstream e;
+ e << args[0] << " does not allow \"" << args[i]
+ << "\" after PATTERN or REGEX.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ // Switch to setting the type.
+ doing = DoingType;
} else if (args[i] == "OPTIONAL") {
if (in_match_mode) {
std::ostringstream e;
@@ -1050,14 +1125,14 @@ bool cmInstallCommand::HandleDirectoryMode(
// Convert this directory to a full path.
std::string dir = args[i];
std::string::size_type gpos = cmGeneratorExpression::Find(dir);
- if (gpos != 0 && !cmSystemTools::FileIsFullPath(dir.c_str())) {
+ if (gpos != 0 && !cmSystemTools::FileIsFullPath(dir)) {
dir = this->Makefile->GetCurrentSourceDirectory();
dir += "/";
dir += args[i];
}
// Make sure the name is a directory.
- if (cmSystemTools::FileExists(dir.c_str()) &&
+ if (cmSystemTools::FileExists(dir) &&
!cmSystemTools::FileIsDirectory(dir)) {
std::ostringstream e;
e << args[0] << " given non-directory \"" << args[i]
@@ -1067,12 +1142,23 @@ bool cmInstallCommand::HandleDirectoryMode(
}
// Store the directory for installation.
- dirs.push_back(dir);
+ dirs.push_back(std::move(dir));
} else if (doing == DoingConfigurations) {
configurations.push_back(args[i]);
} else if (doing == DoingDestination) {
destination = args[i].c_str();
doing = DoingNone;
+ } else if (doing == DoingType) {
+ if (allowedTypes.count(args[i]) == 0) {
+ std::ostringstream e;
+ e << args[0] << " given non-type \"" << args[i]
+ << "\" with TYPE argument.";
+ this->SetError(e.str());
+ return false;
+ }
+
+ type = args[i];
+ 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
@@ -1139,17 +1225,29 @@ bool cmInstallCommand::HandleDirectoryMode(
// Support installing an empty directory.
if (dirs.empty() && destination) {
- dirs.push_back("");
+ dirs.emplace_back();
}
// Check if there is something to do.
if (dirs.empty()) {
return true;
}
+ std::string destinationStr;
if (!destination) {
- // A destination is required.
+ if (type.empty()) {
+ // A destination is required.
+ std::ostringstream e;
+ e << args[0] << " given no DESTINATION!";
+ this->SetError(e.str());
+ return false;
+ }
+ destinationStr = this->GetDestinationForType(nullptr, type);
+ destination = destinationStr.c_str();
+ } else if (!type.empty()) {
std::ostringstream e;
- e << args[0] << " given no DESTINATION!";
+ e << args[0]
+ << " given both TYPE and DESTINATION arguments. You may only specify "
+ "one.";
this->SetError(e.str());
return false;
}
@@ -1165,7 +1263,7 @@ bool cmInstallCommand::HandleDirectoryMode(
// Tell the global generator about any installation component names
// specified.
- this->Makefile->GetGlobalGenerator()->AddInstallComponent(component.c_str());
+ this->Makefile->GetGlobalGenerator()->AddInstallComponent(component);
return true;
}
@@ -1176,16 +1274,19 @@ bool cmInstallCommand::HandleExportAndroidMKMode(
#ifdef CMAKE_BUILD_WITH_CMAKE
// This is the EXPORT mode.
cmInstallCommandArguments ica(this->DefaultComponentName);
- cmCAString exp(&ica.Parser, "EXPORT_ANDROID_MK");
- 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(CM_NULLPTR);
-
- ica.ArgumentGroup.Follows(&exp);
+
+ std::string exp;
+ std::string name_space;
+ bool exportOld = false;
+ std::string filename;
+
+ ica.Bind("EXPORT_ANDROID_MK"_s, exp);
+ ica.Bind("NAMESPACE"_s, name_space);
+ ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
+ ica.Bind("FILE"_s, filename);
+
std::vector<std::string> unknownArgs;
- ica.Parse(&args, &unknownArgs);
+ ica.Parse(args, &unknownArgs);
if (!unknownArgs.empty()) {
// Unknown argument.
@@ -1209,7 +1310,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode(
}
// Check the file name.
- std::string fname = filename.GetString();
+ std::string fname = filename;
if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e;
e << args[0] << " given invalid export file name \"" << fname << "\". "
@@ -1230,7 +1331,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode(
}
if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e;
- e << args[0] << " given export name \"" << exp.GetString() << "\". "
+ e << args[0] << " given export name \"" << exp << "\". "
<< "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.";
@@ -1243,7 +1344,7 @@ bool cmInstallCommand::HandleExportAndroidMKMode(
}
cmExportSet* exportSet =
- this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()];
+ this->Makefile->GetGlobalGenerator()->GetExportSets()[exp];
cmInstallGenerator::MessageLevel message =
cmInstallGenerator::SelectMessageLevel(this->Makefile);
@@ -1252,8 +1353,8 @@ bool cmInstallCommand::HandleExportAndroidMKMode(
cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
ica.GetConfigurations(), ica.GetComponent().c_str(), message,
- ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(),
- exportOld.IsEnabled(), true);
+ ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld,
+ true);
this->Makefile->AddInstallGenerator(exportGenerator);
return true;
@@ -1268,16 +1369,19 @@ 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(CM_NULLPTR);
-
- ica.ArgumentGroup.Follows(&exp);
+
+ std::string exp;
+ std::string name_space;
+ bool exportOld = false;
+ std::string filename;
+
+ ica.Bind("EXPORT"_s, exp);
+ ica.Bind("NAMESPACE"_s, name_space);
+ ica.Bind("EXPORT_LINK_INTERFACE_LIBRARIES"_s, exportOld);
+ ica.Bind("FILE"_s, filename);
+
std::vector<std::string> unknownArgs;
- ica.Parse(&args, &unknownArgs);
+ ica.Parse(args, &unknownArgs);
if (!unknownArgs.empty()) {
// Unknown argument.
@@ -1301,7 +1405,7 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
}
// Check the file name.
- std::string fname = filename.GetString();
+ std::string fname = filename;
if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e;
e << args[0] << " given invalid export file name \"" << fname << "\". "
@@ -1323,12 +1427,12 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
// Construct the file name.
if (fname.empty()) {
- fname = exp.GetString();
+ fname = exp;
fname += ".cmake";
if (fname.find_first_of(":/\\") != std::string::npos) {
std::ostringstream e;
- e << args[0] << " given export name \"" << exp.GetString() << "\". "
+ e << args[0] << " given export name \"" << exp << "\". "
<< "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.";
@@ -1338,12 +1442,9 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
}
cmExportSet* exportSet =
- this->Makefile->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;
+ this->Makefile->GetGlobalGenerator()->GetExportSets()[exp];
+ if (exportOld) {
+ for (cmTargetExport* te : *exportSet->GetTargetExports()) {
cmTarget* tgt =
this->Makefile->GetGlobalGenerator()->FindTarget(te->TargetName);
const bool newCMP0022Behavior =
@@ -1369,8 +1470,8 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator(
exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(),
ica.GetConfigurations(), ica.GetComponent().c_str(), message,
- ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(),
- exportOld.IsEnabled(), false);
+ ica.GetExcludeFromAll(), fname.c_str(), name_space.c_str(), exportOld,
+ false);
this->Makefile->AddInstallGenerator(exportGenerator);
return true;
@@ -1380,25 +1481,24 @@ 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);
+ for (std::string const& relFile : relFiles) {
+ std::string file = relFile;
std::string::size_type gpos = cmGeneratorExpression::Find(file);
- if (gpos != 0 && !cmSystemTools::FileIsFullPath(file.c_str())) {
+ if (gpos != 0 && !cmSystemTools::FileIsFullPath(file)) {
file = this->Makefile->GetCurrentSourceDirectory();
file += "/";
- file += *fileIt;
+ file += relFile;
}
// Make sure the file is not a directory.
if (gpos == std::string::npos && cmSystemTools::FileIsDirectory(file)) {
std::ostringstream e;
- e << modeName << " given directory \"" << (*fileIt) << "\" to install.";
+ e << modeName << " given directory \"" << relFile << "\" to install.";
this->SetError(e.str());
return false;
}
// Store the file for installation.
- absFiles.push_back(file);
+ absFiles.push_back(std::move(file));
}
return true;
}
@@ -1408,7 +1508,7 @@ bool cmInstallCommand::CheckCMP0006(bool& failure)
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0006)) {
case cmPolicies::WARN:
this->Makefile->IssueMessage(
- cmake::AUTHOR_WARNING,
+ MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(cmPolicies::CMP0006));
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -1421,9 +1521,169 @@ bool cmInstallCommand::CheckCMP0006(bool& failure)
case cmPolicies::REQUIRED_ALWAYS:
failure = true;
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0006));
break;
}
return false;
}
+
+std::string cmInstallCommand::GetDestination(
+ const cmInstallCommandArguments* args, const std::string& varName,
+ const std::string& guess)
+{
+ if (args && !args->GetDestination().empty()) {
+ return args->GetDestination();
+ }
+ std::string val = this->Makefile->GetSafeDefinition(varName);
+ if (!val.empty()) {
+ return val;
+ }
+ return guess;
+}
+
+std::string cmInstallCommand::GetRuntimeDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_BINDIR", "bin");
+}
+
+std::string cmInstallCommand::GetSbinDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_SBINDIR", "sbin");
+}
+
+std::string cmInstallCommand::GetArchiveDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
+}
+
+std::string cmInstallCommand::GetLibraryDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_LIBDIR", "lib");
+}
+
+std::string cmInstallCommand::GetIncludeDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_INCLUDEDIR", "include");
+}
+
+std::string cmInstallCommand::GetSysconfDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_SYSCONFDIR", "etc");
+}
+
+std::string cmInstallCommand::GetSharedStateDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_SHAREDSTATEDIR", "com");
+}
+
+std::string cmInstallCommand::GetLocalStateDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_LOCALSTATEDIR", "var");
+}
+
+std::string cmInstallCommand::GetRunStateDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_RUNSTATEDIR",
+ this->GetLocalStateDestination(nullptr) +
+ "/run");
+}
+
+std::string cmInstallCommand::GetDataRootDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_DATAROOTDIR", "share");
+}
+
+std::string cmInstallCommand::GetDataDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_DATADIR",
+ this->GetDataRootDestination(nullptr));
+}
+
+std::string cmInstallCommand::GetInfoDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_INFODIR",
+ this->GetDataRootDestination(nullptr) + "/info");
+}
+
+std::string cmInstallCommand::GetLocaleDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_LOCALEDIR",
+ this->GetDataRootDestination(nullptr) +
+ "/locale");
+}
+
+std::string cmInstallCommand::GetManDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_MANDIR",
+ this->GetDataRootDestination(nullptr) + "/man");
+}
+
+std::string cmInstallCommand::GetDocDestination(
+ const cmInstallCommandArguments* args)
+{
+ return this->GetDestination(args, "CMAKE_INSTALL_DOCDIR",
+ this->GetDataRootDestination(nullptr) + "/doc");
+}
+
+std::string cmInstallCommand::GetDestinationForType(
+ const cmInstallCommandArguments* args, const std::string& type)
+{
+ if (args && !args->GetDestination().empty()) {
+ return args->GetDestination();
+ }
+ if (type == "BIN") {
+ return this->GetRuntimeDestination(nullptr);
+ }
+ if (type == "SBIN") {
+ return this->GetSbinDestination(nullptr);
+ }
+ if (type == "SYSCONF") {
+ return this->GetSysconfDestination(nullptr);
+ }
+ if (type == "SHAREDSTATE") {
+ return this->GetSharedStateDestination(nullptr);
+ }
+ if (type == "LOCALSTATE") {
+ return this->GetLocalStateDestination(nullptr);
+ }
+ if (type == "RUNSTATE") {
+ return this->GetRunStateDestination(nullptr);
+ }
+ if (type == "LIB") {
+ return this->GetLibraryDestination(nullptr);
+ }
+ if (type == "INCLUDE") {
+ return this->GetIncludeDestination(nullptr);
+ }
+ if (type == "DATA") {
+ return this->GetDataDestination(nullptr);
+ }
+ if (type == "INFO") {
+ return this->GetInfoDestination(nullptr);
+ }
+ if (type == "LOCALE") {
+ return this->GetLocaleDestination(nullptr);
+ }
+ if (type == "MAN") {
+ return this->GetManDestination(nullptr);
+ }
+ if (type == "DOC") {
+ return this->GetDocDestination(nullptr);
+ }
+ return "";
+}
diff --git a/Source/cmInstallCommand.h b/Source/cmInstallCommand.h
index f5d1f9265..202c43810 100644
--- a/Source/cmInstallCommand.h
+++ b/Source/cmInstallCommand.h
@@ -3,7 +3,7 @@
#ifndef cmInstallCommand_h
#define cmInstallCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -11,6 +11,7 @@
#include "cmCommand.h"
class cmExecutionStatus;
+class cmInstallCommandArguments;
/** \class cmInstallCommand
* \brief Specifies where to install some files
@@ -24,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmInstallCommand; }
+ cmCommand* Clone() override { return new cmInstallCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
bool HandleScriptMode(std::vector<std::string> const& args);
@@ -45,6 +46,27 @@ private:
std::vector<std::string>& absFiles);
bool CheckCMP0006(bool& failure);
+ std::string GetDestination(const cmInstallCommandArguments* args,
+ const std::string& varName,
+ const std::string& guess);
+ std::string GetRuntimeDestination(const cmInstallCommandArguments* args);
+ std::string GetSbinDestination(const cmInstallCommandArguments* args);
+ std::string GetArchiveDestination(const cmInstallCommandArguments* args);
+ std::string GetLibraryDestination(const cmInstallCommandArguments* args);
+ std::string GetIncludeDestination(const cmInstallCommandArguments* args);
+ std::string GetSysconfDestination(const cmInstallCommandArguments* args);
+ std::string GetSharedStateDestination(const cmInstallCommandArguments* args);
+ std::string GetLocalStateDestination(const cmInstallCommandArguments* args);
+ std::string GetRunStateDestination(const cmInstallCommandArguments* args);
+ std::string GetDataRootDestination(const cmInstallCommandArguments* args);
+ std::string GetDataDestination(const cmInstallCommandArguments* args);
+ std::string GetInfoDestination(const cmInstallCommandArguments* args);
+ std::string GetLocaleDestination(const cmInstallCommandArguments* args);
+ std::string GetManDestination(const cmInstallCommandArguments* args);
+ std::string GetDocDestination(const cmInstallCommandArguments* args);
+ std::string GetDestinationForType(const cmInstallCommandArguments* args,
+ const std::string& type);
+
std::string DefaultComponentName;
};
diff --git a/Source/cmInstallCommandArguments.cxx b/Source/cmInstallCommandArguments.cxx
index b73414dd0..8b33782ae 100644
--- a/Source/cmInstallCommandArguments.cxx
+++ b/Source/cmInstallCommandArguments.cxx
@@ -2,35 +2,36 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallCommandArguments.h"
-#include "cmConfigure.h"
-
+#include "cmRange.h"
#include "cmSystemTools.h"
+#include "cm_static_string_view.hxx"
+
+#include <utility>
// 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", CM_NULLPTR
+ "WORLD_EXECUTE", "SETUID", "SETGID", nullptr
};
const std::string cmInstallCommandArguments::EmptyString;
cmInstallCommandArguments::cmInstallCommandArguments(
- const std::string& defaultComponent)
- : Parser()
- , ArgumentGroup()
- , Destination(&Parser, "DESTINATION", &ArgumentGroup)
- , Component(&Parser, "COMPONENT", &ArgumentGroup)
- , ExcludeFromAll(&Parser, "EXCLUDE_FROM_ALL", &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(CM_NULLPTR)
- , DefaultComponentName(defaultComponent)
-{
+ std::string defaultComponent)
+ : DefaultComponentName(std::move(defaultComponent))
+{
+ this->Bind("DESTINATION"_s, this->Destination);
+ this->Bind("COMPONENT"_s, this->Component);
+ this->Bind("NAMELINK_COMPONENT"_s, this->NamelinkComponent);
+ this->Bind("EXCLUDE_FROM_ALL"_s, this->ExcludeFromAll);
+ this->Bind("RENAME"_s, this->Rename);
+ this->Bind("PERMISSIONS"_s, this->Permissions);
+ this->Bind("CONFIGURATIONS"_s, this->Configurations);
+ this->Bind("OPTIONAL"_s, this->Optional);
+ this->Bind("NAMELINK_ONLY"_s, this->NamelinkOnly);
+ this->Bind("NAMELINK_SKIP"_s, this->NamelinkSkip);
+ this->Bind("TYPE"_s, this->Type);
}
const std::string& cmInstallCommandArguments::GetDestination() const
@@ -38,18 +39,18 @@ const std::string& cmInstallCommandArguments::GetDestination() const
if (!this->DestinationString.empty()) {
return this->DestinationString;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetDestination();
}
- return this->EmptyString;
+ return EmptyString;
}
const std::string& cmInstallCommandArguments::GetComponent() const
{
- if (!this->Component.GetString().empty()) {
- return this->Component.GetString();
+ if (!this->Component.empty()) {
+ return this->Component;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetComponent();
}
if (!this->DefaultComponentName.empty()) {
@@ -59,15 +60,23 @@ const std::string& cmInstallCommandArguments::GetComponent() const
return unspecifiedComponent;
}
+const std::string& cmInstallCommandArguments::GetNamelinkComponent() const
+{
+ if (!this->NamelinkComponent.empty()) {
+ return this->NamelinkComponent;
+ }
+ return this->GetComponent();
+}
+
const std::string& cmInstallCommandArguments::GetRename() const
{
- if (!this->Rename.GetString().empty()) {
- return this->Rename.GetString();
+ if (!this->Rename.empty()) {
+ return this->Rename;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetRename();
}
- return this->EmptyString;
+ return EmptyString;
}
const std::string& cmInstallCommandArguments::GetPermissions() const
@@ -75,18 +84,18 @@ const std::string& cmInstallCommandArguments::GetPermissions() const
if (!this->PermissionsString.empty()) {
return this->PermissionsString;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetPermissions();
}
- return this->EmptyString;
+ return EmptyString;
}
bool cmInstallCommandArguments::GetOptional() const
{
- if (this->Optional.IsEnabled()) {
+ if (this->Optional) {
return true;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetOptional();
}
return false;
@@ -94,10 +103,10 @@ bool cmInstallCommandArguments::GetOptional() const
bool cmInstallCommandArguments::GetExcludeFromAll() const
{
- if (this->ExcludeFromAll.IsEnabled()) {
+ if (this->ExcludeFromAll) {
return true;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetExcludeFromAll();
}
return false;
@@ -105,10 +114,10 @@ bool cmInstallCommandArguments::GetExcludeFromAll() const
bool cmInstallCommandArguments::GetNamelinkOnly() const
{
- if (this->NamelinkOnly.IsEnabled()) {
+ if (this->NamelinkOnly) {
return true;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetNamelinkOnly();
}
return false;
@@ -116,25 +125,41 @@ bool cmInstallCommandArguments::GetNamelinkOnly() const
bool cmInstallCommandArguments::GetNamelinkSkip() const
{
- if (this->NamelinkSkip.IsEnabled()) {
+ if (this->NamelinkSkip) {
return true;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetNamelinkSkip();
}
return false;
}
+bool cmInstallCommandArguments::HasNamelinkComponent() const
+{
+ if (!this->NamelinkComponent.empty()) {
+ return true;
+ }
+ if (this->GenericArguments != nullptr) {
+ return this->GenericArguments->HasNamelinkComponent();
+ }
+ return false;
+}
+
+const std::string& cmInstallCommandArguments::GetType() const
+{
+ return this->Type;
+}
+
const std::vector<std::string>& cmInstallCommandArguments::GetConfigurations()
const
{
- if (!this->Configurations.GetVector().empty()) {
- return this->Configurations.GetVector();
+ if (!this->Configurations.empty()) {
+ return this->Configurations;
}
- if (this->GenericArguments != CM_NULLPTR) {
+ if (this->GenericArguments != nullptr) {
return this->GenericArguments->GetConfigurations();
}
- return this->Configurations.GetVector();
+ return this->Configurations;
}
bool cmInstallCommandArguments::Finalize()
@@ -142,24 +167,17 @@ bool cmInstallCommandArguments::Finalize()
if (!this->CheckPermissions()) {
return false;
}
- this->DestinationString = this->Destination.GetString();
+ this->DestinationString = this->Destination;
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)) {
+ this->PermissionsString.clear();
+ for (std::string const& perm : this->Permissions) {
+ if (!cmInstallCommandArguments::CheckPermissions(
+ perm, this->PermissionsString)) {
return false;
}
}
@@ -183,9 +201,7 @@ bool cmInstallCommandArguments::CheckPermissions(
return false;
}
-cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument()
-{
-}
+cmInstallCommandIncludesArgument::cmInstallCommandIncludesArgument() = default;
const std::vector<std::string>&
cmInstallCommandIncludesArgument::GetIncludeDirs() const
@@ -199,11 +215,8 @@ void cmInstallCommandIncludesArgument::Parse(
if (args->empty()) {
return;
}
- std::vector<std::string>::const_iterator it = args->begin();
- ++it;
- for (; it != args->end(); ++it) {
- std::string dir = *it;
+ for (std::string dir : cmMakeRange(*args).advance(1)) {
cmSystemTools::ConvertToUnixSlashes(dir);
- this->IncludeDirs.push_back(dir);
+ this->IncludeDirs.push_back(std::move(dir));
}
}
diff --git a/Source/cmInstallCommandArguments.h b/Source/cmInstallCommandArguments.h
index a576e7202..5d2ee0ab4 100644
--- a/Source/cmInstallCommandArguments.h
+++ b/Source/cmInstallCommandArguments.h
@@ -8,24 +8,23 @@
#include <string>
#include <vector>
-#include "cmCommandArgumentsHelper.h"
+#include "cmArgumentParser.h"
-class cmInstallCommandArguments
+class cmInstallCommandArguments : public cmArgumentParser<void>
{
public:
- cmInstallCommandArguments(const std::string& defaultComponent);
+ cmInstallCommandArguments(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& GetNamelinkComponent() const;
bool GetExcludeFromAll() const;
const std::string& GetRename() const;
const std::string& GetPermissions() const;
@@ -33,30 +32,28 @@ public:
bool GetOptional() const;
bool GetNamelinkOnly() const;
bool GetNamelinkSkip() const;
+ bool HasNamelinkComponent() const;
+ const std::string& GetType() 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;
- cmCAEnabler ExcludeFromAll;
- cmCAString Rename;
- cmCAStringVector Permissions;
- cmCAStringVector Configurations;
- cmCAEnabler Optional;
- cmCAEnabler NamelinkOnly;
- cmCAEnabler NamelinkSkip;
+ std::string Destination;
+ std::string Component;
+ std::string NamelinkComponent;
+ bool ExcludeFromAll = false;
+ std::string Rename;
+ std::vector<std::string> Permissions;
+ std::vector<std::string> Configurations;
+ bool Optional = false;
+ bool NamelinkOnly = false;
+ bool NamelinkSkip = false;
+ std::string Type;
std::string DestinationString;
std::string PermissionsString;
- cmInstallCommandArguments* GenericArguments;
+ cmInstallCommandArguments* GenericArguments = nullptr;
static const char* PermissionsTable[];
static const std::string EmptyString;
std::string DefaultComponentName;
diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx
index 54ad85c3b..14288f6d2 100644
--- a/Source/cmInstallDirectoryGenerator.cxx
+++ b/Source/cmInstallDirectoryGenerator.cxx
@@ -7,7 +7,8 @@
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
+
+#include <memory> // IWYU pragma: keep
cmInstallDirectoryGenerator::cmInstallDirectoryGenerator(
std::vector<std::string> const& dirs, const char* dest,
@@ -17,7 +18,7 @@ cmInstallDirectoryGenerator::cmInstallDirectoryGenerator(
bool optional)
: cmInstallGenerator(dest, configurations, component, message,
exclude_from_all)
- , LocalGenerator(CM_NULLPTR)
+ , LocalGenerator(nullptr)
, Directories(dirs)
, FilePermissions(file_permissions)
, DirPermissions(dir_permissions)
@@ -30,21 +31,22 @@ cmInstallDirectoryGenerator::cmInstallDirectoryGenerator(
}
// We need per-config actions if any directories have generator expressions.
- for (std::vector<std::string>::const_iterator i = dirs.begin();
- !this->ActionsPerConfig && i != dirs.end(); ++i) {
- if (cmGeneratorExpression::Find(*i) != std::string::npos) {
- this->ActionsPerConfig = true;
+ if (!this->ActionsPerConfig) {
+ for (std::string const& dir : dirs) {
+ if (cmGeneratorExpression::Find(dir) != std::string::npos) {
+ this->ActionsPerConfig = true;
+ break;
+ }
}
}
}
-cmInstallDirectoryGenerator::~cmInstallDirectoryGenerator()
-{
-}
+cmInstallDirectoryGenerator::~cmInstallDirectoryGenerator() = default;
-void cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg)
+bool cmInstallDirectoryGenerator::Compute(cmLocalGenerator* lg)
{
- LocalGenerator = lg;
+ this->LocalGenerator = lg;
+ return true;
}
void cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os,
@@ -62,19 +64,17 @@ void cmInstallDirectoryGenerator::GenerateScriptForConfig(
{
std::vector<std::string> dirs;
cmGeneratorExpression ge;
- for (std::vector<std::string>::const_iterator i = this->Directories.begin();
- i != this->Directories.end(); ++i) {
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
+ for (std::string const& d : this->Directories) {
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(d);
cmSystemTools::ExpandListArgument(
cge->Evaluate(this->LocalGenerator, config), dirs);
}
// Make sure all dirs have absolute paths.
cmMakefile const& mf = *this->LocalGenerator->GetMakefile();
- for (std::vector<std::string>::iterator i = dirs.begin(); i != dirs.end();
- ++i) {
- if (!cmSystemTools::FileIsFullPath(i->c_str())) {
- *i = std::string(mf.GetCurrentSourceDirectory()) + "/" + *i;
+ for (std::string& d : dirs) {
+ if (!cmSystemTools::FileIsFullPath(d)) {
+ d = mf.GetCurrentSourceDirectory() + "/" + d;
}
}
@@ -86,7 +86,7 @@ void cmInstallDirectoryGenerator::AddDirectoryInstallRule(
std::vector<std::string> const& dirs)
{
// Write code to install the directories.
- const char* no_rename = CM_NULLPTR;
+ const char* no_rename = nullptr;
this->AddInstallRule(os, this->GetDestination(config),
cmInstallType_DIRECTORY, dirs, this->Optional,
this->FilePermissions.c_str(),
diff --git a/Source/cmInstallDirectoryGenerator.h b/Source/cmInstallDirectoryGenerator.h
index aa2cbc690..e30849f83 100644
--- a/Source/cmInstallDirectoryGenerator.h
+++ b/Source/cmInstallDirectoryGenerator.h
@@ -6,7 +6,7 @@
#include "cmInstallGenerator.h"
#include "cmScriptGenerator.h"
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -27,16 +27,16 @@ public:
const char* component, MessageLevel message,
bool exclude_from_all, const char* literal_args,
bool optional = false);
- ~cmInstallDirectoryGenerator() CM_OVERRIDE;
+ ~cmInstallDirectoryGenerator() override;
- void Compute(cmLocalGenerator* lg) CM_OVERRIDE;
+ bool Compute(cmLocalGenerator* lg) override;
std::string GetDestination(std::string const& config) const;
protected:
- void GenerateScriptActions(std::ostream& os, Indent indent) CM_OVERRIDE;
+ void GenerateScriptActions(std::ostream& os, Indent indent) override;
void GenerateScriptForConfig(std::ostream& os, const std::string& config,
- Indent indent) CM_OVERRIDE;
+ Indent indent) override;
void AddDirectoryInstallRule(std::ostream& os, const std::string& config,
Indent indent,
std::vector<std::string> const& dirs);
diff --git a/Source/cmInstallExportAndroidMKGenerator.cxx b/Source/cmInstallExportAndroidMKGenerator.cxx
index 8eeaa9c7c..55d368507 100644
--- a/Source/cmInstallExportAndroidMKGenerator.cxx
+++ b/Source/cmInstallExportAndroidMKGenerator.cxx
@@ -13,7 +13,7 @@
#include "cmInstallTargetGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
-#include "cmake.h"
+#include "cmMessageType.h"
cmInstallExportAndroidMKGenerator::cmInstallExportAndroidMKGenerator(
cmExportSet* exportSet, const char* destination,
@@ -30,10 +30,11 @@ cmInstallExportAndroidMKGenerator::~cmInstallExportAndroidMKGenerator()
{
}
-void cmInstallExportAndroidMKGenerator::Compute(cmLocalGenerator* lg)
+bool cmInstallExportAndroidMKGenerator::Compute(cmLocalGenerator* lg)
{
this->LocalGenerator = lg;
this->ExportSet->Compute(lg);
+ return true;
}
void cmInstallExportAndroidMKGenerator::GenerateScript(std::ostream& os)
@@ -43,7 +44,7 @@ void cmInstallExportAndroidMKGenerator::GenerateScript(std::ostream& os)
std::ostringstream e;
e << "INSTALL(EXPORT) given unknown export \"" << ExportSet->GetName()
<< "\"";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return;
}
@@ -67,10 +68,8 @@ void cmInstallExportAndroidMKGenerator::GenerateScript(std::ostream& os)
this->EFGen->AddConfiguration("");
}
} else {
- for (std::vector<std::string>::const_iterator ci =
- this->ConfigurationTypes->begin();
- ci != this->ConfigurationTypes->end(); ++ci) {
- this->EFGen->AddConfiguration(*ci);
+ for (std::string const& config : this->ConfigurationTypes) {
+ this->EFGen->AddConfiguration(config);
}
}
this->EFGen->GenerateImportFile();
@@ -88,15 +87,13 @@ void cmInstallExportAndroidMKGenerator::GenerateScriptConfigs(
// 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);
+ for (auto const& pair : this->EFGen->GetConfigImportFiles()) {
+ files.push_back(pair.second);
+ std::string config_test = this->CreateConfigTest(pair.first);
os << indent << "if(" << config_test << ")\n";
this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
- false, this->FilePermissions.c_str(), CM_NULLPTR,
- CM_NULLPTR, CM_NULLPTR, indent.Next());
+ false, this->FilePermissions.c_str(), nullptr,
+ nullptr, nullptr, indent.Next());
os << indent << "endif()\n";
files.clear();
}
@@ -135,6 +132,6 @@ void cmInstallExportAndroidMKGenerator::GenerateScriptActions(
std::vector<std::string> files;
files.push_back(this->MainImportFile);
this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
- false, this->FilePermissions.c_str(), CM_NULLPTR,
- CM_NULLPTR, CM_NULLPTR, indent);
+ false, this->FilePermissions.c_str(), nullptr, nullptr,
+ nullptr, indent);
}
diff --git a/Source/cmInstallExportAndroidMKGenerator.h b/Source/cmInstallExportAndroidMKGenerator.h
index 189084a1a..a92ff27f1 100644
--- a/Source/cmInstallExportAndroidMKGenerator.h
+++ b/Source/cmInstallExportAndroidMKGenerator.h
@@ -24,7 +24,7 @@ public:
const char* name_space, bool exportOld);
~cmInstallExportAndroidMKGenerator();
- void Compute(cmLocalGenerator* lg);
+ bool Compute(cmLocalGenerator* lg) override;
protected:
virtual void GenerateScript(std::ostream& os);
diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx
index b176e85c5..f5bedabc4 100644
--- a/Source/cmInstallExportGenerator.cxx
+++ b/Source/cmInstallExportGenerator.cxx
@@ -8,14 +8,13 @@
#include <utility>
#ifdef CMAKE_BUILD_WITH_CMAKE
-#include "cmExportInstallAndroidMKGenerator.h"
+# include "cmExportInstallAndroidMKGenerator.h"
#endif
#include "cmExportInstallFileGenerator.h"
#include "cmExportSet.h"
#include "cmInstallType.h"
#include "cmLocalGenerator.h"
#include "cmSystemTools.h"
-#include "cmake.h"
cmInstallExportGenerator::cmInstallExportGenerator(
cmExportSet* exportSet, const char* destination,
@@ -29,7 +28,7 @@ cmInstallExportGenerator::cmInstallExportGenerator(
, FileName(filename)
, Namespace(name_space)
, ExportOld(exportOld)
- , LocalGenerator(CM_NULLPTR)
+ , LocalGenerator(nullptr)
{
if (android) {
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -46,10 +45,11 @@ cmInstallExportGenerator::~cmInstallExportGenerator()
delete this->EFGen;
}
-void cmInstallExportGenerator::Compute(cmLocalGenerator* lg)
+bool cmInstallExportGenerator::Compute(cmLocalGenerator* lg)
{
this->LocalGenerator = lg;
this->ExportSet->Compute(lg);
+ return true;
}
void cmInstallExportGenerator::ComputeTempDir()
@@ -57,7 +57,7 @@ void cmInstallExportGenerator::ComputeTempDir()
// Choose a temporary directory in which to generate the import
// files to be installed.
this->TempDir = this->LocalGenerator->GetCurrentBinaryDirectory();
- this->TempDir += cmake::GetCMakeFilesDirectory();
+ this->TempDir += "/CMakeFiles";
this->TempDir += "/Export";
if (this->Destination.empty()) {
return;
@@ -111,11 +111,9 @@ size_t cmInstallExportGenerator::GetMaxConfigLength() const
len = this->ConfigurationName.size();
}
} else {
- for (std::vector<std::string>::const_iterator ci =
- this->ConfigurationTypes->begin();
- ci != this->ConfigurationTypes->end(); ++ci) {
- if (ci->size() > len) {
- len = ci->size();
+ for (std::string const& c : *this->ConfigurationTypes) {
+ if (c.size() > len) {
+ len = c.size();
}
}
}
@@ -129,13 +127,13 @@ void cmInstallExportGenerator::GenerateScript(std::ostream& os)
std::ostringstream e;
e << "INSTALL(EXPORT) given unknown export \"" << ExportSet->GetName()
<< "\"";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return;
}
// Create the temporary directory in which to store the files.
this->ComputeTempDir();
- cmSystemTools::MakeDirectory(this->TempDir.c_str());
+ cmSystemTools::MakeDirectory(this->TempDir);
// Construct a temporary location for the file.
this->MainImportFile = this->TempDir;
@@ -153,10 +151,8 @@ void cmInstallExportGenerator::GenerateScript(std::ostream& os)
this->EFGen->AddConfiguration("");
}
} else {
- for (std::vector<std::string>::const_iterator ci =
- this->ConfigurationTypes->begin();
- ci != this->ConfigurationTypes->end(); ++ci) {
- this->EFGen->AddConfiguration(*ci);
+ for (std::string const& c : *this->ConfigurationTypes) {
+ this->EFGen->AddConfiguration(c);
}
}
this->EFGen->GenerateImportFile();
@@ -174,15 +170,13 @@ void cmInstallExportGenerator::GenerateScriptConfigs(std::ostream& os,
// 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);
+ for (auto const& i : this->EFGen->GetConfigImportFiles()) {
+ files.push_back(i.second);
+ std::string config_test = this->CreateConfigTest(i.first);
os << indent << "if(" << config_test << ")\n";
this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
- false, this->FilePermissions.c_str(), CM_NULLPTR,
- CM_NULLPTR, CM_NULLPTR, indent.Next());
+ false, this->FilePermissions.c_str(), nullptr,
+ nullptr, nullptr, indent.Next());
os << indent << "endif()\n";
files.clear();
}
@@ -209,7 +203,7 @@ void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os,
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
+ os << indentNNN << R"(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";
@@ -221,6 +215,6 @@ void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os,
std::vector<std::string> files;
files.push_back(this->MainImportFile);
this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
- false, this->FilePermissions.c_str(), CM_NULLPTR,
- CM_NULLPTR, CM_NULLPTR, indent);
+ false, this->FilePermissions.c_str(), nullptr, nullptr,
+ nullptr, indent);
}
diff --git a/Source/cmInstallExportGenerator.h b/Source/cmInstallExportGenerator.h
index 047e6b3cd..c4d252c47 100644
--- a/Source/cmInstallExportGenerator.h
+++ b/Source/cmInstallExportGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmInstallExportGenerator_h
#define cmInstallExportGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmInstallGenerator.h"
#include "cmScriptGenerator.h"
@@ -30,11 +30,11 @@ public:
bool exclude_from_all, const char* filename,
const char* name_space, bool exportOld,
bool android);
- ~cmInstallExportGenerator() CM_OVERRIDE;
+ ~cmInstallExportGenerator() override;
cmExportSet* GetExportSet() { return this->ExportSet; }
- void Compute(cmLocalGenerator* lg) CM_OVERRIDE;
+ bool Compute(cmLocalGenerator* lg) override;
cmLocalGenerator* GetLocalGenerator() const { return this->LocalGenerator; }
@@ -43,9 +43,9 @@ public:
std::string const& GetDestination() const { return this->Destination; }
protected:
- void GenerateScript(std::ostream& os) CM_OVERRIDE;
- void GenerateScriptConfigs(std::ostream& os, Indent indent) CM_OVERRIDE;
- void GenerateScriptActions(std::ostream& os, Indent indent) CM_OVERRIDE;
+ void GenerateScript(std::ostream& os) override;
+ void GenerateScriptConfigs(std::ostream& os, Indent indent) override;
+ void GenerateScriptActions(std::ostream& os, Indent indent) override;
void GenerateImportFile(cmExportSet const* exportSet);
void GenerateImportFile(const char* config, cmExportSet const* exportSet);
void ComputeTempDir();
diff --git a/Source/cmInstallFilesCommand.cxx b/Source/cmInstallFilesCommand.cxx
index 4a3b620af..efbcb6713 100644
--- a/Source/cmInstallFilesCommand.cxx
+++ b/Source/cmInstallFilesCommand.cxx
@@ -2,11 +2,13 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallFilesCommand.h"
+#include "cmAlgorithms.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmInstallFilesGenerator.h"
#include "cmInstallGenerator.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
class cmExecutionStatus;
@@ -27,17 +29,14 @@ bool cmInstallFilesCommand::InitialPass(std::vector<std::string> const& args,
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) {
+ for (std::string const& arg : cmMakeRange(args).advance(2)) {
// Find the source location for each file listed.
- std::string f = this->FindInstallSource(s->c_str());
- this->Files.push_back(f);
+ this->Files.push_back(this->FindInstallSource(arg.c_str()));
}
this->CreateInstallGenerator();
} else {
this->IsFilesForm = false;
- this->FinalArgs.insert(this->FinalArgs.end(), args.begin() + 1,
- args.end());
+ cmAppend(this->FinalArgs, args.begin() + 1, args.end());
}
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
@@ -138,11 +137,11 @@ std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
ts += "/";
ts += name;
- if (cmSystemTools::FileExists(tb.c_str())) {
+ if (cmSystemTools::FileExists(tb)) {
// The file exists in the binary tree. Use it.
return tb;
}
- if (cmSystemTools::FileExists(ts.c_str())) {
+ if (cmSystemTools::FileExists(ts)) {
// The file exists in the source tree. Use it.
return ts;
}
diff --git a/Source/cmInstallFilesCommand.h b/Source/cmInstallFilesCommand.h
index b3c27b827..a52f45e05 100644
--- a/Source/cmInstallFilesCommand.h
+++ b/Source/cmInstallFilesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmInstallFilesCommand_h
#define cmInstallFilesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmInstallFilesCommand; }
+ cmCommand* Clone() override { return new cmInstallFilesCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* This is called at the end after all the information
@@ -39,8 +39,8 @@ public:
* not implement this method. At this point, reading and
* writing to the cache can be done.
*/
- void FinalPass() CM_OVERRIDE;
- bool HasFinalPass() const CM_OVERRIDE { return !this->IsFilesForm; }
+ void FinalPass() override;
+ bool HasFinalPass() const override { return !this->IsFilesForm; }
protected:
void CreateInstallGenerator() const;
@@ -48,7 +48,7 @@ protected:
private:
std::vector<std::string> FinalArgs;
- bool IsFilesForm;
+ bool IsFilesForm = false;
std::string Destination;
std::vector<std::string> Files;
};
diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx
index 6323a9189..2ed9f734d 100644
--- a/Source/cmInstallFilesGenerator.cxx
+++ b/Source/cmInstallFilesGenerator.cxx
@@ -5,7 +5,8 @@
#include "cmGeneratorExpression.h"
#include "cmInstallType.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
+
+#include <memory> // IWYU pragma: keep
class cmLocalGenerator;
@@ -16,7 +17,7 @@ cmInstallFilesGenerator::cmInstallFilesGenerator(
const char* rename, bool optional)
: cmInstallGenerator(dest, configurations, component, message,
exclude_from_all)
- , LocalGenerator(CM_NULLPTR)
+ , LocalGenerator(nullptr)
, Files(files)
, FilePermissions(file_permissions)
, Rename(rename)
@@ -28,22 +29,23 @@ cmInstallFilesGenerator::cmInstallFilesGenerator(
this->ActionsPerConfig = true;
}
- // 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;
+ // We need per-config actions if any directories have generator expressions.
+ if (!this->ActionsPerConfig) {
+ for (std::string const& file : files) {
+ if (cmGeneratorExpression::Find(file) != std::string::npos) {
+ this->ActionsPerConfig = true;
+ break;
+ }
}
}
}
-cmInstallFilesGenerator::~cmInstallFilesGenerator()
-{
-}
+cmInstallFilesGenerator::~cmInstallFilesGenerator() = default;
-void cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
+bool cmInstallFilesGenerator::Compute(cmLocalGenerator* lg)
{
this->LocalGenerator = lg;
+ return true;
}
std::string cmInstallFilesGenerator::GetDestination(
@@ -58,12 +60,12 @@ void cmInstallFilesGenerator::AddFilesInstallRule(
std::vector<std::string> const& files)
{
// Write code to install the files.
- const char* no_dir_permissions = CM_NULLPTR;
+ const char* no_dir_permissions = nullptr;
this->AddInstallRule(
os, this->GetDestination(config),
(this->Programs ? cmInstallType_PROGRAMS : cmInstallType_FILES), files,
this->Optional, this->FilePermissions.c_str(), no_dir_permissions,
- this->Rename.c_str(), CM_NULLPTR, indent);
+ this->Rename.c_str(), nullptr, indent);
}
void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os,
@@ -81,9 +83,8 @@ void cmInstallFilesGenerator::GenerateScriptForConfig(
{
std::vector<std::string> files;
cmGeneratorExpression ge;
- for (std::vector<std::string>::const_iterator i = this->Files.begin();
- i != this->Files.end(); ++i) {
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*i);
+ for (std::string const& f : this->Files) {
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(f);
cmSystemTools::ExpandListArgument(
cge->Evaluate(this->LocalGenerator, config), files);
}
diff --git a/Source/cmInstallFilesGenerator.h b/Source/cmInstallFilesGenerator.h
index 62b57f9c7..ac462d46f 100644
--- a/Source/cmInstallFilesGenerator.h
+++ b/Source/cmInstallFilesGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmInstallFilesGenerator_h
#define cmInstallFilesGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmInstallGenerator.h"
#include "cmScriptGenerator.h"
@@ -27,16 +27,16 @@ public:
const char* component, MessageLevel message,
bool exclude_from_all, const char* rename,
bool optional = false);
- ~cmInstallFilesGenerator() CM_OVERRIDE;
+ ~cmInstallFilesGenerator() override;
- void Compute(cmLocalGenerator* lg) CM_OVERRIDE;
+ bool Compute(cmLocalGenerator* lg) override;
std::string GetDestination(std::string const& config) const;
protected:
- void GenerateScriptActions(std::ostream& os, Indent indent) CM_OVERRIDE;
+ void GenerateScriptActions(std::ostream& os, Indent indent) override;
void GenerateScriptForConfig(std::ostream& os, const std::string& config,
- Indent indent) CM_OVERRIDE;
+ Indent indent) override;
void AddFilesInstallRule(std::ostream& os, std::string const& config,
Indent indent,
std::vector<std::string> const& files);
diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx
index 13b588efb..2ffca30f6 100644
--- a/Source/cmInstallGenerator.cxx
+++ b/Source/cmInstallGenerator.cxx
@@ -18,8 +18,19 @@ cmInstallGenerator::cmInstallGenerator(
{
}
-cmInstallGenerator::~cmInstallGenerator()
+cmInstallGenerator::~cmInstallGenerator() = default;
+
+bool cmInstallGenerator::HaveInstall()
{
+ return true;
+}
+
+void cmInstallGenerator::CheckCMP0082(bool& haveSubdirectoryInstall,
+ bool& haveInstallAfterSubdirectory)
+{
+ if (haveSubdirectoryInstall) {
+ haveInstallAfterSubdirectory = true;
+ }
}
void cmInstallGenerator::AddInstallRule(
@@ -55,20 +66,21 @@ void cmInstallGenerator::AddInstallRule(
break;
}
os << indent;
- if (cmSystemTools::FileIsFullPath(dest.c_str())) {
+ if (cmSystemTools::FileIsFullPath(dest)) {
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()) {
+ bool firstIteration = true;
+ for (std::string const& file : files) {
+ if (!firstIteration) {
os << ";";
}
os << dest << "/";
if (rename && *rename) {
os << rename;
} else {
- os << cmSystemTools::GetFilenameName(*fi);
+ os << cmSystemTools::GetFilenameName(file);
}
+ firstIteration = false;
}
os << "\")\n";
os << indent << "if(CMAKE_WARN_ON_ABSOLUTE_INSTALL_DESTINATION)\n";
@@ -113,9 +125,8 @@ void cmInstallGenerator::AddInstallRule(
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 << "\"";
+ for (std::string const& f : files) {
+ os << "\n" << indent << " \"" << f << "\"";
}
os << "\n" << indent << " ";
if (!(literal_args && *literal_args)) {
@@ -131,9 +142,9 @@ void cmInstallGenerator::AddInstallRule(
std::string cmInstallGenerator::CreateComponentTest(const char* component,
bool exclude_from_all)
{
- std::string result = "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
+ std::string result = R"("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "x)";
result += component;
- result += "\"";
+ result += "x\"";
if (!exclude_from_all) {
result += " OR NOT CMAKE_INSTALL_COMPONENT";
}
@@ -166,7 +177,7 @@ std::string cmInstallGenerator::ConvertToAbsoluteDestination(
std::string const& dest) const
{
std::string result;
- if (!dest.empty() && !cmSystemTools::FileIsFullPath(dest.c_str())) {
+ if (!dest.empty() && !cmSystemTools::FileIsFullPath(dest)) {
result = "${CMAKE_INSTALL_PREFIX}/";
}
result += dest;
diff --git a/Source/cmInstallGenerator.h b/Source/cmInstallGenerator.h
index 8f8701f1a..dbe707d1d 100644
--- a/Source/cmInstallGenerator.h
+++ b/Source/cmInstallGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmInstallGenerator_h
#define cmInstallGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmInstallType.h"
#include "cmScriptGenerator.h"
@@ -21,8 +21,6 @@ class cmMakefile;
*/
class cmInstallGenerator : public cmScriptGenerator
{
- CM_DISABLE_COPY(cmInstallGenerator)
-
public:
enum MessageLevel
{
@@ -36,14 +34,21 @@ public:
std::vector<std::string> const& configurations,
const char* component, MessageLevel message,
bool exclude_from_all);
- ~cmInstallGenerator() CM_OVERRIDE;
+ ~cmInstallGenerator() override;
+
+ cmInstallGenerator(cmInstallGenerator const&) = delete;
+ cmInstallGenerator& operator=(cmInstallGenerator const&) = delete;
+
+ virtual bool HaveInstall();
+ virtual void CheckCMP0082(bool& haveSubdirectoryInstall,
+ bool& haveInstallAfterSubdirectory);
void AddInstallRule(
std::ostream& os, std::string const& dest, cmInstallType type,
std::vector<std::string> const& files, bool optional = false,
- const char* permissions_file = CM_NULLPTR,
- const char* permissions_dir = CM_NULLPTR, const char* rename = CM_NULLPTR,
- const char* literal_args = CM_NULLPTR, Indent indent = Indent());
+ const char* permissions_file = nullptr,
+ const char* permissions_dir = nullptr, const char* rename = nullptr,
+ const char* literal_args = nullptr, Indent indent = Indent());
/** Get the install destination as it should appear in the
installation script. */
@@ -55,10 +60,10 @@ public:
/** Select message level from CMAKE_INSTALL_MESSAGE or 'never'. */
static MessageLevel SelectMessageLevel(cmMakefile* mf, bool never = false);
- virtual void Compute(cmLocalGenerator*) {}
+ virtual bool Compute(cmLocalGenerator*) { return true; }
protected:
- void GenerateScript(std::ostream& os) CM_OVERRIDE;
+ void GenerateScript(std::ostream& os) override;
std::string CreateComponentTest(const char* component,
bool exclude_from_all);
diff --git a/Source/cmInstallProgramsCommand.cxx b/Source/cmInstallProgramsCommand.cxx
index 5ee81fbf6..a58f87578 100644
--- a/Source/cmInstallProgramsCommand.cxx
+++ b/Source/cmInstallProgramsCommand.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallProgramsCommand.h"
+#include "cmAlgorithms.h"
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmInstallFilesGenerator.h"
@@ -25,7 +26,7 @@ bool cmInstallProgramsCommand::InitialPass(
this->Destination = args[0];
- this->FinalArgs.insert(this->FinalArgs.end(), args.begin() + 1, args.end());
+ cmAppend(this->FinalArgs, args.begin() + 1, args.end());
this->Makefile->GetGlobalGenerator()->AddInstallComponent(
this->Makefile->GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
@@ -109,11 +110,11 @@ std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const
ts += "/";
ts += name;
- if (cmSystemTools::FileExists(tb.c_str())) {
+ if (cmSystemTools::FileExists(tb)) {
// The file exists in the binary tree. Use it.
return tb;
}
- if (cmSystemTools::FileExists(ts.c_str())) {
+ if (cmSystemTools::FileExists(ts)) {
// The file exists in the source tree. Use it.
return ts;
}
diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h
index 242fb953d..5c705ebf6 100644
--- a/Source/cmInstallProgramsCommand.h
+++ b/Source/cmInstallProgramsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmInstallProgramsCommand_h
#define cmInstallProgramsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmInstallProgramsCommand; }
+ cmCommand* Clone() override { return new cmInstallProgramsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* This is called at the end after all the information
@@ -39,9 +39,9 @@ public:
* not implement this method. At this point, reading and
* writing to the cache can be done.
*/
- void FinalPass() CM_OVERRIDE;
+ void FinalPass() override;
- bool HasFinalPass() const CM_OVERRIDE { return true; }
+ bool HasFinalPass() const override { return true; }
protected:
std::string FindInstallSource(const char* name) const;
diff --git a/Source/cmInstallScriptGenerator.cxx b/Source/cmInstallScriptGenerator.cxx
index b39a622f5..5832d27e6 100644
--- a/Source/cmInstallScriptGenerator.cxx
+++ b/Source/cmInstallScriptGenerator.cxx
@@ -2,38 +2,88 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallScriptGenerator.h"
-#include "cmScriptGenerator.h"
-
#include <ostream>
#include <vector>
+#include "cmGeneratorExpression.h"
+#include "cmLocalGenerator.h"
+#include "cmMessageType.h"
+#include "cmPolicies.h"
+#include "cmScriptGenerator.h"
+
cmInstallScriptGenerator::cmInstallScriptGenerator(const char* script,
bool code,
const char* component,
bool exclude_from_all)
- : cmInstallGenerator(CM_NULLPTR, std::vector<std::string>(), component,
+ : cmInstallGenerator(nullptr, std::vector<std::string>(), component,
MessageDefault, exclude_from_all)
, Script(script)
, Code(code)
+ , AllowGenex(false)
{
+ // We need per-config actions if the script has generator expressions.
+ if (cmGeneratorExpression::Find(Script) != std::string::npos) {
+ this->ActionsPerConfig = true;
+ }
}
-cmInstallScriptGenerator::~cmInstallScriptGenerator()
+cmInstallScriptGenerator::~cmInstallScriptGenerator() = default;
+
+bool cmInstallScriptGenerator::Compute(cmLocalGenerator* lg)
{
+ this->LocalGenerator = lg;
+
+ if (this->ActionsPerConfig) {
+ switch (this->LocalGenerator->GetPolicyStatus(cmPolicies::CMP0087)) {
+ case cmPolicies::WARN:
+ this->LocalGenerator->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ cmPolicies::GetPolicyWarning(cmPolicies::CMP0087));
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ this->AllowGenex = true;
+ break;
+ }
+ }
+
+ return true;
}
-void cmInstallScriptGenerator::GenerateScript(std::ostream& os)
+void cmInstallScriptGenerator::AddScriptInstallRule(std::ostream& os,
+ Indent indent,
+ std::string const& script)
{
- Indent indent;
- std::string component_test =
- this->CreateComponentTest(this->Component.c_str(), this->ExcludeFromAll);
- os << indent << "if(" << component_test << ")\n";
-
if (this->Code) {
- os << indent.Next() << this->Script << "\n";
+ os << indent << script << "\n";
} else {
- os << indent.Next() << "include(\"" << this->Script << "\")\n";
+ os << indent << "include(\"" << script << "\")\n";
}
+}
- os << indent << "endif()\n\n";
+void cmInstallScriptGenerator::GenerateScriptActions(std::ostream& os,
+ Indent indent)
+{
+ if (this->AllowGenex && this->ActionsPerConfig) {
+ this->cmInstallGenerator::GenerateScriptActions(os, indent);
+ } else {
+ this->AddScriptInstallRule(os, indent, this->Script);
+ }
+}
+
+void cmInstallScriptGenerator::GenerateScriptForConfig(
+ std::ostream& os, const std::string& config, Indent indent)
+{
+ if (this->AllowGenex) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(this->Script);
+ this->AddScriptInstallRule(os, indent,
+ cge->Evaluate(this->LocalGenerator, config));
+ } else {
+ this->AddScriptInstallRule(os, indent, this->Script);
+ }
}
diff --git a/Source/cmInstallScriptGenerator.h b/Source/cmInstallScriptGenerator.h
index e183999d0..6af737113 100644
--- a/Source/cmInstallScriptGenerator.h
+++ b/Source/cmInstallScriptGenerator.h
@@ -3,13 +3,16 @@
#ifndef cmInstallScriptGenerator_h
#define cmInstallScriptGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmInstallGenerator.h"
+#include "cmScriptGenerator.h"
#include <iosfwd>
#include <string>
+class cmLocalGenerator;
+
/** \class cmInstallScriptGenerator
* \brief Generate target installation rules.
*/
@@ -18,12 +21,21 @@ class cmInstallScriptGenerator : public cmInstallGenerator
public:
cmInstallScriptGenerator(const char* script, bool code,
const char* component, bool exclude_from_all);
- ~cmInstallScriptGenerator() CM_OVERRIDE;
+ ~cmInstallScriptGenerator() override;
+
+ bool Compute(cmLocalGenerator* lg) override;
protected:
- void GenerateScript(std::ostream& os) CM_OVERRIDE;
+ void GenerateScriptActions(std::ostream& os, Indent indent) override;
+ void GenerateScriptForConfig(std::ostream& os, const std::string& config,
+ Indent indent) override;
+ void AddScriptInstallRule(std::ostream& os, Indent indent,
+ std::string const& script);
+
std::string Script;
bool Code;
+ cmLocalGenerator* LocalGenerator;
+ bool AllowGenex;
};
#endif
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx
index 84d6f7ac9..7c5a55bb6 100644
--- a/Source/cmInstallTargetGenerator.cxx
+++ b/Source/cmInstallTargetGenerator.cxx
@@ -15,47 +15,31 @@
#include "cmInstallType.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmake.h"
cmInstallTargetGenerator::cmInstallTargetGenerator(
- const std::string& targetName, const char* dest, bool implib,
+ std::string targetName, const char* dest, bool implib,
const char* file_permissions, std::vector<std::string> const& configurations,
const char* component, MessageLevel message, bool exclude_from_all,
- bool optional)
+ bool optional, cmListFileBacktrace backtrace)
: cmInstallGenerator(dest, configurations, component, message,
exclude_from_all)
- , TargetName(targetName)
- , Target(CM_NULLPTR)
+ , TargetName(std::move(targetName))
+ , Target(nullptr)
, FilePermissions(file_permissions)
, ImportLibrary(implib)
, Optional(optional)
+ , Backtrace(std::move(backtrace))
{
this->ActionsPerConfig = true;
this->NamelinkMode = NamelinkModeNone;
}
-cmInstallTargetGenerator::~cmInstallTargetGenerator()
-{
-}
-
-void cmInstallTargetGenerator::GenerateScript(std::ostream& os)
-{
- // Warn if installing an exclude-from-all target.
- if (this->Target->GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
- std::ostringstream 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);
-}
+cmInstallTargetGenerator::~cmInstallTargetGenerator() = default;
void cmInstallTargetGenerator::GenerateScriptForConfig(
std::ostream& os, const std::string& config, Indent indent)
@@ -90,7 +74,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
case cmStateEnums::GLOBAL_TARGET:
case cmStateEnums::UNKNOWN_LIBRARY:
this->Target->GetLocalGenerator()->IssueMessage(
- cmake::INTERNAL_ERROR,
+ MessageType::INTERNAL_ERROR,
"cmInstallTargetGenerator created with non-installable target.");
return;
}
@@ -100,7 +84,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
if (this->Target->NeedRelinkBeforeInstall(config)) {
fromDirConfig =
this->Target->GetLocalGenerator()->GetCurrentBinaryDirectory();
- fromDirConfig += cmake::GetCMakeFilesDirectory();
+ fromDirConfig += "/CMakeFiles";
fromDirConfig += "/CMakeRelink.dir/";
} else {
cmStateEnums::ArtifactType artifact = this->ImportLibrary
@@ -123,19 +107,15 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
// 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);
+ cmGeneratorTarget::Names targetNames =
+ this->Target->GetExecutableNames(config);
if (this->ImportLibrary) {
- std::string from1 = fromDirConfig + targetNameImport;
- std::string to1 = toDir + targetNameImport;
- filesFrom.push_back(from1);
- filesTo.push_back(to1);
+ std::string from1 = fromDirConfig + targetNames.ImportLibrary;
+ std::string to1 = toDir + targetNames.ImportLibrary;
+ filesFrom.push_back(std::move(from1));
+ filesTo.push_back(std::move(to1));
std::string targetNameImportLib;
- if (this->Target->GetImplibGNUtoMS(targetNameImport,
+ if (this->Target->GetImplibGNUtoMS(config, targetNames.ImportLibrary,
targetNameImportLib)) {
filesFrom.push_back(fromDirConfig + targetNameImportLib);
filesTo.push_back(toDir + targetNameImportLib);
@@ -144,8 +124,8 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
// An import library looks like a static library.
type = cmInstallType_STATIC_LIBRARY;
} else {
- std::string from1 = fromDirConfig + targetName;
- std::string to1 = toDir + targetName;
+ std::string from1 = fromDirConfig + targetNames.Output;
+ std::string to1 = toDir + targetNames.Output;
// Handle OSX Bundles.
if (this->Target->IsAppBundleOnApple()) {
@@ -167,41 +147,36 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
to1 += ".";
to1 += ext;
to1 += "/";
- if (!mf->PlatformIsAppleIos()) {
+ if (!mf->PlatformIsAppleEmbedded()) {
to1 += "Contents/MacOS/";
}
- to1 += targetName;
+ to1 += targetNames.Output;
} 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);
+ if (targetNames.Real != targetNames.Output) {
+ std::string from2 = fromDirConfig + targetNames.Real;
+ std::string to2 = toDir += targetNames.Real;
+ filesFrom.push_back(std::move(from2));
+ filesTo.push_back(std::move(to2));
}
}
- filesFrom.push_back(from1);
- filesTo.push_back(to1);
+ filesFrom.push_back(std::move(from1));
+ filesTo.push_back(std::move(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);
+ cmGeneratorTarget::Names targetNames =
+ this->Target->GetLibraryNames(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 from1 = fromDirConfig + targetNames.ImportLibrary;
+ std::string to1 = toDir + targetNames.ImportLibrary;
+ filesFrom.push_back(std::move(from1));
+ filesTo.push_back(std::move(to1));
std::string targetNameImportLib;
- if (this->Target->GetImplibGNUtoMS(targetNameImport,
+ if (this->Target->GetImplibGNUtoMS(config, targetNames.ImportLibrary,
targetNameImportLib)) {
filesFrom.push_back(fromDirConfig + targetNameImportLib);
filesTo.push_back(toDir + targetNameImportLib);
@@ -210,56 +185,84 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
// 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);
+ // FIXME: In principle we should be able to
+ // assert(this->NamelinkMode == NamelinkModeNone);
+ // but since the current install() command implementation checks
+ // the FRAMEWORK property immediately instead of delaying until
+ // generate time, it is possible for project code to set the
+ // property after calling install(). In such a case, the install()
+ // command will use the LIBRARY code path and create two install
+ // generators, one for the namelink component (NamelinkModeOnly)
+ // and one for the primary artifact component (NamelinkModeSkip).
+ // Historically this was not diagnosed and resulted in silent
+ // installation of a framework to the LIBRARY destination.
+ // Retain that behavior and warn about the case.
+ switch (this->NamelinkMode) {
+ case NamelinkModeNone:
+ // Normal case.
+ break;
+ case NamelinkModeOnly:
+ // Assume the NamelinkModeSkip instance will warn and install.
+ return;
+ case NamelinkModeSkip: {
+ std::string e = "Target '" + this->Target->GetName() +
+ "' was changed to a FRAMEWORK sometime after install(). "
+ "This may result in the wrong install DESTINATION. "
+ "Set the FRAMEWORK property earlier.";
+ this->Target->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
+ MessageType::AUTHOR_WARNING, e, this->GetBacktrace());
+ } break;
+ }
// Install the whole framework directory.
type = cmInstallType_DIRECTORY;
literal_args += " USE_SOURCE_PERMISSIONS";
- std::string from1 = fromDirConfig + targetName;
+ std::string from1 = fromDirConfig + targetNames.Output;
from1 = cmSystemTools::GetFilenamePath(from1);
// Tweaks apply to the binary inside the bundle.
- std::string to1 = toDir + targetNameReal;
+ std::string to1 = toDir + targetNames.Real;
- filesFrom.push_back(from1);
- filesTo.push_back(to1);
+ filesFrom.push_back(std::move(from1));
+ filesTo.push_back(std::move(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 targetNameBase =
+ targetNames.Output.substr(0, targetNames.Output.find('/'));
std::string from1 = fromDirConfig + targetNameBase;
- std::string to1 = toDir + targetName;
+ std::string to1 = toDir + targetNames.Output;
- filesFrom.push_back(from1);
- filesTo.push_back(to1);
+ filesFrom.push_back(std::move(from1));
+ filesTo.push_back(std::move(to1));
} else {
bool haveNamelink = false;
// Library link name.
- std::string fromName = fromDirConfig + targetName;
- std::string toName = toDir + targetName;
+ std::string fromName = fromDirConfig + targetNames.Output;
+ std::string toName = toDir + targetNames.Output;
// Library interface name.
std::string fromSOName;
std::string toSOName;
- if (targetNameSO != targetName) {
+ if (targetNames.SharedObject != targetNames.Output) {
haveNamelink = true;
- fromSOName = fromDirConfig + targetNameSO;
- toSOName = toDir + targetNameSO;
+ fromSOName = fromDirConfig + targetNames.SharedObject;
+ toSOName = toDir + targetNames.SharedObject;
}
// Library implementation name.
std::string fromRealName;
std::string toRealName;
- if (targetNameReal != targetName && targetNameReal != targetNameSO) {
+ if (targetNames.Real != targetNames.Output &&
+ targetNames.Real != targetNames.SharedObject) {
haveNamelink = true;
- fromRealName = fromDirConfig + targetNameReal;
- toRealName = toDir + targetNameReal;
+ fromRealName = fromDirConfig + targetNames.Real;
+ toRealName = toDir + targetNames.Real;
}
// Add the names based on the current namelink mode.
@@ -312,8 +315,8 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
&cmInstallTargetGenerator::PreReplacementTweaks);
// Write code to install the target file.
- const char* no_dir_permissions = CM_NULLPTR;
- const char* no_rename = CM_NULLPTR;
+ const char* no_dir_permissions = nullptr;
+ const char* no_rename = nullptr;
bool optional = this->Optional || this->ImportLibrary;
this->AddInstallRule(os, this->GetDestination(config), type, filesFrom,
optional, this->FilePermissions.c_str(),
@@ -351,8 +354,8 @@ void cmInstallTargetGenerator::GenerateScriptForConfigObjectLibrary(
std::string const obj_dir = this->Target->GetObjectDirectory(config);
std::string const literal_args = " FILES_FROM_DIR \"" + obj_dir + "\"";
- const char* no_dir_permissions = CM_NULLPTR;
- const char* no_rename = CM_NULLPTR;
+ const char* no_dir_permissions = nullptr;
+ const char* no_rename = nullptr;
this->AddInstallRule(os, dest, cmInstallType_FILES, objects, this->Optional,
this->FilePermissions.c_str(), no_dir_permissions,
no_rename, literal_args.c_str(), indent);
@@ -362,9 +365,8 @@ void cmInstallTargetGenerator::GetInstallObjectNames(
std::string const& config, std::vector<std::string>& objects) const
{
this->Target->GetTargetObjectNames(config, objects);
- for (std::vector<std::string>::iterator i = objects.begin();
- i != objects.end(); ++i) {
- *i = computeInstallObjectDir(this->Target, config) + "/" + *i;
+ for (std::string& o : objects) {
+ o = computeInstallObjectDir(this->Target, config) + "/" + o;
}
}
@@ -391,57 +393,54 @@ std::string cmInstallTargetGenerator::GetInstallFilename(
std::string fname;
// Compute the name of the library.
if (target->GetType() == cmStateEnums::EXECUTABLE) {
- std::string targetName;
- std::string targetNameReal;
- std::string targetNameImport;
- std::string targetNamePDB;
- target->GetExecutableNames(targetName, targetNameReal, targetNameImport,
- targetNamePDB, config);
+ cmGeneratorTarget::Names targetNames = target->GetExecutableNames(config);
if (nameType == NameImplib) {
// Use the import library name.
- if (!target->GetImplibGNUtoMS(targetNameImport, fname,
+ if (!target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, fname,
"${CMAKE_IMPORT_LIBRARY_SUFFIX}")) {
- fname = targetNameImport;
+ fname = targetNames.ImportLibrary;
}
} else if (nameType == NameReal) {
// Use the canonical name.
- fname = targetNameReal;
+ fname = targetNames.Real;
} else {
// Use the canonical name.
- fname = targetName;
+ fname = targetNames.Output;
}
} else {
- std::string targetName;
- std::string targetNameSO;
- std::string targetNameReal;
- std::string targetNameImport;
- std::string targetNamePDB;
- target->GetLibraryNames(targetName, targetNameSO, targetNameReal,
- targetNameImport, targetNamePDB, config);
+ cmGeneratorTarget::Names targetNames = target->GetLibraryNames(config);
if (nameType == NameImplib) {
// Use the import library name.
- if (!target->GetImplibGNUtoMS(targetNameImport, fname,
+ if (!target->GetImplibGNUtoMS(config, targetNames.ImportLibrary, fname,
"${CMAKE_IMPORT_LIBRARY_SUFFIX}")) {
- fname = targetNameImport;
+ fname = targetNames.ImportLibrary;
}
} else if (nameType == NameSO) {
// Use the soname.
- fname = targetNameSO;
+ fname = targetNames.SharedObject;
} else if (nameType == NameReal) {
// Use the real name.
- fname = targetNameReal;
+ fname = targetNames.Real;
} else {
// Use the canonical name.
- fname = targetName;
+ fname = targetNames.Output;
}
}
return fname;
}
-void cmInstallTargetGenerator::Compute(cmLocalGenerator* lg)
+bool cmInstallTargetGenerator::Compute(cmLocalGenerator* lg)
{
+ // Lookup this target in the current directory.
this->Target = lg->FindLocalNonAliasGeneratorTarget(this->TargetName);
+ if (!this->Target) {
+ // If no local target has been found, find it in the global scope.
+ this->Target =
+ lg->GetGlobalGenerator()->FindGeneratorTarget(this->TargetName);
+ }
+
+ return true;
}
void cmInstallTargetGenerator::AddTweak(std::ostream& os, Indent indent,
@@ -476,9 +475,8 @@ void cmInstallTargetGenerator::AddTweak(std::ostream& os, Indent indent,
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";
+ for (std::string const& f : files) {
+ os << indent2 << "\"" << this->GetDestDirPath(f) << "\"\n";
}
os << indent2 << ")\n";
os << tws;
@@ -546,11 +544,7 @@ void cmInstallTargetGenerator::AddInstallNamePatchRule(
this->Target->GetLinkInformation(config)) {
std::set<cmGeneratorTarget const*> const& sharedLibs =
cli->GetSharedLibrariesLinked();
- for (std::set<cmGeneratorTarget const*>::const_iterator j =
- sharedLibs.begin();
- j != sharedLibs.end(); ++j) {
- cmGeneratorTarget const* tgt = *j;
-
+ for (cmGeneratorTarget const* tgt : sharedLibs) {
// The install_name of an imported target does not change.
if (tgt->IsImported()) {
continue;
@@ -609,12 +603,9 @@ void cmInstallTargetGenerator::AddInstallNamePatchRule(
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) {
+ for (auto const& i : install_name_remap) {
os << "\n"
- << indent << " -change \"" << i->first << "\" \"" << i->second
- << "\"";
+ << indent << " -change \"" << i.first << "\" \"" << i.second << "\"";
}
os << "\n" << indent << " \"" << toDestDirPath << "\")\n";
}
@@ -697,15 +688,14 @@ void cmInstallTargetGenerator::AddChrpathPatchRule(
<< "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());
+ mf->IssueMessage(MessageType::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) {
+ for (std::string const& i : oldRuntimeDirs) {
std::string runpath =
- mf->GetGlobalGenerator()->ExpandCFGIntDir(*i, config);
+ mf->GetGlobalGenerator()->ExpandCFGIntDir(i, config);
if (runpaths.find(runpath) == runpaths.end()) {
runpaths.insert(runpath);
@@ -717,10 +707,9 @@ void cmInstallTargetGenerator::AddChrpathPatchRule(
}
runpaths.clear();
- for (std::vector<std::string>::const_iterator i = newRuntimeDirs.begin();
- i != newRuntimeDirs.end(); ++i) {
+ for (std::string const& i : newRuntimeDirs) {
std::string runpath =
- mf->GetGlobalGenerator()->ExpandCFGIntDir(*i, config);
+ mf->GetGlobalGenerator()->ExpandCFGIntDir(i, config);
if (runpaths.find(runpath) == runpaths.end()) {
os << indent << "execute_process(COMMAND " << installNameTool
@@ -771,10 +760,22 @@ void cmInstallTargetGenerator::AddStripRule(std::ostream& os, Indent indent,
return;
}
+ std::string stripArgs;
+
+ // macOS 'strip' is picky, executables need '-u -r' and dylibs need '-x'.
+ if (this->Target->Target->GetMakefile()->IsOn("APPLE")) {
+ if (this->Target->GetType() == cmStateEnums::SHARED_LIBRARY ||
+ this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) {
+ stripArgs = "-x ";
+ } else if (this->Target->GetType() == cmStateEnums::EXECUTABLE) {
+ stripArgs = "-u -r ";
+ }
+ }
+
os << indent << "if(CMAKE_INSTALL_DO_STRIP)\n";
os << indent << " execute_process(COMMAND \""
<< this->Target->Target->GetMakefile()->GetDefinition("CMAKE_STRIP")
- << "\" \"" << toDestDirPath << "\")\n";
+ << "\" " << stripArgs << "\"" << toDestDirPath << "\")\n";
os << indent << "endif()\n";
}
@@ -792,7 +793,7 @@ void cmInstallTargetGenerator::AddRanlibRule(std::ostream& os, Indent indent,
return;
}
- std::string ranlib =
+ const std::string& ranlib =
this->Target->Target->GetMakefile()->GetRequiredDefinition("CMAKE_RANLIB");
if (ranlib.empty()) {
return;
@@ -807,7 +808,7 @@ void cmInstallTargetGenerator::AddUniversalInstallRule(
{
cmMakefile const* mf = this->Target->Target->GetMakefile();
- if (!mf->PlatformIsAppleIos() || !mf->IsOn("XCODE")) {
+ if (!mf->PlatformIsAppleEmbedded() || !mf->IsOn("XCODE")) {
return;
}
diff --git a/Source/cmInstallTargetGenerator.h b/Source/cmInstallTargetGenerator.h
index cf2de58f9..ed3ab5246 100644
--- a/Source/cmInstallTargetGenerator.h
+++ b/Source/cmInstallTargetGenerator.h
@@ -3,9 +3,10 @@
#ifndef cmInstallTargetGenerator_h
#define cmInstallTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmInstallGenerator.h"
+#include "cmListFileCache.h"
#include "cmScriptGenerator.h"
#include <iosfwd>
@@ -21,12 +22,13 @@ class cmLocalGenerator;
class cmInstallTargetGenerator : public cmInstallGenerator
{
public:
- cmInstallTargetGenerator(std::string const& targetName, const char* dest,
- bool implib, const char* file_permissions,
- std::vector<std::string> const& configurations,
- const char* component, MessageLevel message,
- bool exclude_from_all, bool optional);
- ~cmInstallTargetGenerator() CM_OVERRIDE;
+ cmInstallTargetGenerator(
+ std::string targetName, const char* dest, bool implib,
+ const char* file_permissions,
+ std::vector<std::string> const& configurations, const char* component,
+ MessageLevel message, bool exclude_from_all, bool optional,
+ cmListFileBacktrace backtrace = cmListFileBacktrace());
+ ~cmInstallTargetGenerator() override;
/** Select the policy for installing shared library linkable name
symlinks. */
@@ -56,7 +58,7 @@ public:
const std::string& config,
NameType nameType = NameNormal);
- void Compute(cmLocalGenerator* lg) CM_OVERRIDE;
+ bool Compute(cmLocalGenerator* lg) override;
cmGeneratorTarget* GetTarget() const { return this->Target; }
@@ -64,10 +66,11 @@ public:
std::string GetDestination(std::string const& config) const;
+ cmListFileBacktrace const& GetBacktrace() const { return this->Backtrace; }
+
protected:
- void GenerateScript(std::ostream& os) CM_OVERRIDE;
void GenerateScriptForConfig(std::ostream& os, const std::string& config,
- Indent indent) CM_OVERRIDE;
+ Indent indent) override;
void GenerateScriptForConfigObjectLibrary(std::ostream& os,
const std::string& config,
Indent indent);
@@ -108,6 +111,7 @@ protected:
NamelinkModeType NamelinkMode;
bool ImportLibrary;
bool Optional;
+ cmListFileBacktrace Backtrace;
};
#endif
diff --git a/Source/cmInstallTargetsCommand.cxx b/Source/cmInstallTargetsCommand.cxx
index e00eba012..ef07e2cf4 100644
--- a/Source/cmInstallTargetsCommand.cxx
+++ b/Source/cmInstallTargetsCommand.cxx
@@ -2,12 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmInstallTargetsCommand.h"
+#include <unordered_map>
#include <utility>
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmTarget.h"
-#include "cm_unordered_map.hxx"
class cmExecutionStatus;
@@ -23,7 +23,7 @@ bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args,
// Enable the install target.
this->Makefile->GetGlobalGenerator()->EnableInstallTarget();
- cmTargets& tgts = this->Makefile->GetTargets();
+ cmMakefile::cmTargetMap& tgts = this->Makefile->GetTargets();
std::vector<std::string>::const_iterator s = args.begin();
++s;
std::string runtime_dir = "/bin";
@@ -38,10 +38,10 @@ bool cmInstallTargetsCommand::InitialPass(std::vector<std::string> const& args,
runtime_dir = *s;
} else {
- cmTargets::iterator ti = tgts.find(*s);
+ cmMakefile::cmTargetMap::iterator ti = tgts.find(*s);
if (ti != tgts.end()) {
- ti->second.SetInstallPath(args[0].c_str());
- ti->second.SetRuntimeInstallPath(runtime_dir.c_str());
+ ti->second.SetInstallPath(args[0]);
+ ti->second.SetRuntimeInstallPath(runtime_dir);
ti->second.SetHaveInstallRule(true);
} else {
std::string str = "Cannot find target: \"" + *s + "\" to install.";
diff --git a/Source/cmInstallTargetsCommand.h b/Source/cmInstallTargetsCommand.h
index cc8484365..9950fb7db 100644
--- a/Source/cmInstallTargetsCommand.h
+++ b/Source/cmInstallTargetsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmInstallTargetsCommand_h
#define cmInstallTargetsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmInstallTargetsCommand; }
+ cmCommand* Clone() override { return new cmInstallTargetsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmInstalledFile.cxx b/Source/cmInstalledFile.cxx
index d51fd8d74..537b4ecec 100644
--- a/Source/cmInstalledFile.cxx
+++ b/Source/cmInstalledFile.cxx
@@ -7,24 +7,16 @@
#include "cmMakefile.h"
#include "cmSystemTools.h"
-#include "cmConfigure.h"
#include <utility>
-cmInstalledFile::cmInstalledFile()
- : NameExpression(CM_NULLPTR)
-{
-}
+cmInstalledFile::cmInstalledFile() = default;
cmInstalledFile::~cmInstalledFile()
{
- if (NameExpression) {
- delete NameExpression;
- }
+ delete NameExpression;
}
-cmInstalledFile::Property::Property()
-{
-}
+cmInstalledFile::Property::Property() = default;
cmInstalledFile::Property::~Property()
{
@@ -91,11 +83,9 @@ bool cmInstalledFile::GetProperty(const std::string& prop,
std::string output;
std::string separator;
- for (ExpressionVectorType::const_iterator j =
- property.ValueExpressions.begin();
- j != property.ValueExpressions.end(); ++j) {
+ for (auto ve : property.ValueExpressions) {
output += separator;
- output += (*j)->GetInput();
+ output += ve->GetInput();
separator = ";";
}
@@ -107,7 +97,7 @@ bool cmInstalledFile::GetPropertyAsBool(const std::string& prop) const
{
std::string value;
bool isSet = this->GetProperty(prop, value);
- return isSet && cmSystemTools::IsOn(value.c_str());
+ return isSet && cmSystemTools::IsOn(value);
}
void cmInstalledFile::GetPropertyAsList(const std::string& prop,
diff --git a/Source/cmInstalledFile.h b/Source/cmInstalledFile.h
index fbf754ffd..b7d602ef4 100644
--- a/Source/cmInstalledFile.h
+++ b/Source/cmInstalledFile.h
@@ -6,9 +6,9 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmGeneratorExpression.h"
-#include "cm_auto_ptr.hxx"
#include <map>
+#include <memory> // IWYU pragma: keep
#include <string>
#include <vector>
@@ -22,7 +22,7 @@ class cmMakefile;
class cmInstalledFile
{
public:
- typedef CM_AUTO_PTR<cmCompiledGeneratorExpression>
+ typedef std::unique_ptr<cmCompiledGeneratorExpression>
CompiledGeneratorExpressionPtrType;
typedef std::vector<cmCompiledGeneratorExpression*> ExpressionVectorType;
@@ -32,6 +32,9 @@ public:
Property();
~Property();
+ Property(const Property&) = delete;
+ Property& operator=(const Property&) = delete;
+
ExpressionVectorType ValueExpressions;
};
@@ -41,6 +44,9 @@ public:
~cmInstalledFile();
+ cmInstalledFile(const cmInstalledFile&) = delete;
+ cmInstalledFile& operator=(const cmInstalledFile&) = delete;
+
void RemoveProperty(const std::string& prop);
void SetProperty(cmMakefile const* mf, const std::string& prop,
@@ -68,7 +74,7 @@ public:
private:
std::string Name;
- cmCompiledGeneratorExpression* NameExpression;
+ cmCompiledGeneratorExpression* NameExpression = nullptr;
PropertyMapType Properties;
};
diff --git a/Source/cmLinkDirectoriesCommand.cxx b/Source/cmLinkDirectoriesCommand.cxx
index 9b0c28817..785097745 100644
--- a/Source/cmLinkDirectoriesCommand.cxx
+++ b/Source/cmLinkDirectoriesCommand.cxx
@@ -4,10 +4,12 @@
#include <sstream>
+#include "cmAlgorithms.h"
+#include "cmGeneratorExpression.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmSystemTools.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -19,18 +21,34 @@ bool cmLinkDirectoriesCommand::InitialPass(
return true;
}
- for (std::vector<std::string>::const_iterator i = args.begin();
- i != args.end(); ++i) {
- this->AddLinkDir(*i);
+ bool before = this->Makefile->IsOn("CMAKE_LINK_DIRECTORIES_BEFORE");
+
+ auto i = args.cbegin();
+ if ((*i) == "BEFORE") {
+ before = true;
+ ++i;
+ } else if ((*i) == "AFTER") {
+ before = false;
+ ++i;
+ }
+
+ std::vector<std::string> directories;
+ for (; i != args.cend(); ++i) {
+ this->AddLinkDir(*i, directories);
}
+
+ this->Makefile->AddLinkDirectory(cmJoin(directories, ";"), before);
+
return true;
}
-void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir)
+void cmLinkDirectoriesCommand::AddLinkDir(
+ std::string const& dir, std::vector<std::string>& directories)
{
std::string unixPath = dir;
cmSystemTools::ConvertToUnixSlashes(unixPath);
- if (!cmSystemTools::FileIsFullPath(unixPath.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(unixPath) &&
+ !cmGeneratorExpression::StartsWithGeneratorExpression(unixPath)) {
bool convertToAbsolute = false;
std::ostringstream e;
/* clang-format off */
@@ -41,14 +59,15 @@ void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir)
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0015);
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
+ break;
case cmPolicies::OLD:
// OLD behavior does not convert
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0015);
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
CM_FALLTHROUGH;
case cmPolicies::NEW:
// NEW behavior converts
@@ -62,5 +81,5 @@ void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir)
unixPath = tmp;
}
}
- this->Makefile->AppendProperty("LINK_DIRECTORIES", unixPath.c_str());
+ directories.push_back(unixPath);
}
diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h
index b64e48d70..ae4fb7f5f 100644
--- a/Source/cmLinkDirectoriesCommand.h
+++ b/Source/cmLinkDirectoriesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmLinkDirectoriesCommand_h
#define cmLinkDirectoriesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -26,17 +26,18 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmLinkDirectoriesCommand; }
+ cmCommand* Clone() override { return new cmLinkDirectoriesCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- void AddLinkDir(std::string const& dir);
+ void AddLinkDir(std::string const& dir,
+ std::vector<std::string>& directories);
};
#endif
diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h
index f0fded21f..5b635b5b3 100644
--- a/Source/cmLinkItem.h
+++ b/Source/cmLinkItem.h
@@ -3,10 +3,11 @@
#ifndef cmLinkItem_h
#define cmLinkItem_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <algorithm>
#include <map>
+#include <ostream>
#include <string>
#include <vector>
@@ -17,42 +18,28 @@
class cmGeneratorTarget;
// Basic information about each link item.
-class cmLinkItem : public std::string
+class cmLinkItem
{
- typedef std::string std_string;
+ std::string String;
public:
- cmLinkItem()
- : std_string()
- , Target(CM_NULLPTR)
- {
- }
- cmLinkItem(const std_string& n, cmGeneratorTarget const* t)
- : std_string(n)
- , Target(t)
- {
- }
- cmGeneratorTarget const* Target;
+ cmLinkItem();
+ cmLinkItem(std::string s, cmListFileBacktrace bt);
+ cmLinkItem(cmGeneratorTarget const* t, cmListFileBacktrace bt);
+ std::string const& AsStr() const;
+ cmGeneratorTarget const* Target = nullptr;
+ cmListFileBacktrace Backtrace;
+ friend bool operator<(cmLinkItem const& l, cmLinkItem const& r);
+ friend bool operator==(cmLinkItem const& l, cmLinkItem const& r);
+ friend std::ostream& operator<<(std::ostream& os, cmLinkItem const& item);
};
class cmLinkImplItem : public cmLinkItem
{
public:
- cmLinkImplItem()
- : cmLinkItem()
- , Backtrace()
- , FromGenex(false)
- {
- }
- cmLinkImplItem(std::string const& n, cmGeneratorTarget const* t,
- cmListFileBacktrace const& bt, bool fromGenex)
- : cmLinkItem(n, t)
- , Backtrace(bt)
- , FromGenex(fromGenex)
- {
- }
- cmListFileBacktrace Backtrace;
- bool FromGenex;
+ cmLinkImplItem();
+ cmLinkImplItem(cmLinkItem item, bool fromGenex);
+ bool FromGenex = false;
};
/** The link implementation specifies the direct library
@@ -83,36 +70,22 @@ struct cmLinkInterface : public cmLinkInterfaceLibraries
// Number of repetitions of a strongly connected component of two
// or more static libraries.
- unsigned int Multiplicity;
+ unsigned int Multiplicity = 0;
// Libraries listed for other configurations.
// Needed only for OLD behavior of CMP0003.
std::vector<cmLinkItem> WrongConfigLibraries;
- bool ImplementationIsInterface;
-
- cmLinkInterface()
- : Multiplicity(0)
- , ImplementationIsInterface(false)
- {
- }
+ bool ImplementationIsInterface = false;
};
struct cmOptionalLinkInterface : public cmLinkInterface
{
- cmOptionalLinkInterface()
- : LibrariesDone(false)
- , AllDone(false)
- , Exists(false)
- , HadHeadSensitiveCondition(false)
- , ExplicitLibraries(CM_NULLPTR)
- {
- }
- bool LibrariesDone;
- bool AllDone;
- bool Exists;
- bool HadHeadSensitiveCondition;
- const char* ExplicitLibraries;
+ bool LibrariesDone = false;
+ bool AllDone = false;
+ bool Exists = false;
+ bool HadHeadSensitiveCondition = false;
+ const char* ExplicitLibraries = nullptr;
};
struct cmHeadToLinkInterfaceMap
@@ -129,15 +102,9 @@ struct cmLinkImplementation : public cmLinkImplementationLibraries
// Cache link implementation computation from each configuration.
struct cmOptionalLinkImplementation : public cmLinkImplementation
{
- cmOptionalLinkImplementation()
- : LibrariesDone(false)
- , LanguagesDone(false)
- , HadHeadSensitiveCondition(false)
- {
- }
- bool LibrariesDone;
- bool LanguagesDone;
- bool HadHeadSensitiveCondition;
+ bool LibrariesDone = false;
+ bool LanguagesDone = false;
+ bool HadHeadSensitiveCondition = false;
};
/** Compute the link type to use for the given configuration. */
diff --git a/Source/cmLinkLibrariesCommand.cxx b/Source/cmLinkLibrariesCommand.cxx
index 708ec8c00..13f6baef3 100644
--- a/Source/cmLinkLibrariesCommand.cxx
+++ b/Source/cmLinkLibrariesCommand.cxx
@@ -13,7 +13,7 @@ bool cmLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args,
if (args.empty()) {
return true;
}
- // add libraries, nothe that there is an optional prefix
+ // add libraries, note 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) {
diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h
index f1b3a6816..af25fba4a 100644
--- a/Source/cmLinkLibrariesCommand.h
+++ b/Source/cmLinkLibrariesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmLinkLibrariesCommand_h
#define cmLinkLibrariesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmLinkLibrariesCommand; }
+ cmCommand* Clone() override { return new cmLinkLibrariesCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmLinkLineComputer.cxx b/Source/cmLinkLineComputer.cxx
index c0f702e25..469faca88 100644
--- a/Source/cmLinkLineComputer.cxx
+++ b/Source/cmLinkLineComputer.cxx
@@ -11,6 +11,7 @@
#include "cmOutputConverter.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
+#include "cmSystemTools.h"
cmLinkLineComputer::cmLinkLineComputer(cmOutputConverter* outputConverter,
cmStateDirectory const& stateDir)
@@ -22,9 +23,7 @@ cmLinkLineComputer::cmLinkLineComputer(cmOutputConverter* outputConverter,
{
}
-cmLinkLineComputer::~cmLinkLineComputer()
-{
-}
+cmLinkLineComputer::~cmLinkLineComputer() = default;
void cmLinkLineComputer::SetUseWatcomQuote(bool useWatcomQuote)
{
@@ -46,9 +45,8 @@ std::string cmLinkLineComputer::ConvertToLinkReference(
{
std::string relLib = lib;
- if (cmOutputConverter::ContainedInDirectory(
- this->StateDir.GetCurrentBinary(), lib, this->StateDir)) {
- relLib = cmOutputConverter::ForceToRelativePath(
+ if (this->StateDir.ContainsBoth(this->StateDir.GetCurrentBinary(), lib)) {
+ relLib = cmSystemTools::ForceToRelativePath(
this->StateDir.GetCurrentBinary(), lib);
}
return relLib;
@@ -59,17 +57,16 @@ std::string cmLinkLineComputer::ComputeLinkLibs(cmComputeLinkInformation& cli)
std::string linkLibs;
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() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (auto const& item : items) {
+ if (item.Target &&
+ item.Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- if (li->IsPath) {
+ if (item.IsPath) {
linkLibs +=
- this->ConvertToOutputFormat(this->ConvertToLinkReference(li->Value));
+ this->ConvertToOutputFormat(this->ConvertToLinkReference(item.Value));
} else {
- linkLibs += li->Value;
+ linkLibs += item.Value;
}
linkLibs += " ";
}
@@ -102,15 +99,34 @@ std::string cmLinkLineComputer::ComputeLinkPath(
std::string const& libPathTerminator)
{
std::string linkPath;
- 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);
- linkPath += " " + libPathFlag;
- linkPath += libpath;
- linkPath += libPathTerminator;
- linkPath += " ";
+
+ if (cli.GetLinkLanguage() == "Swift") {
+ for (const cmComputeLinkInformation::Item& item : cli.GetItems()) {
+ const cmGeneratorTarget* target = item.Target;
+ if (!target) {
+ continue;
+ }
+
+ if (target->GetType() == cmStateEnums::STATIC_LIBRARY ||
+ target->GetType() == cmStateEnums::SHARED_LIBRARY) {
+ cmStateEnums::ArtifactType type = cmStateEnums::RuntimeBinaryArtifact;
+ if (target->GetType() == cmStateEnums::SHARED_LIBRARY &&
+ target->IsDLLPlatform()) {
+ type = cmStateEnums::ImportLibraryArtifact;
+ }
+
+ linkPath += " " + libPathFlag +
+ item.Target->GetDirectory(cli.GetConfig(), type) +
+ libPathTerminator + " ";
+ }
+ }
}
+
+ for (std::string const& libDir : cli.GetDirectories()) {
+ linkPath += " " + libPathFlag + this->ConvertToOutputForExisting(libDir) +
+ libPathTerminator + " ";
+ }
+
return linkPath;
}
@@ -123,10 +139,9 @@ std::string cmLinkLineComputer::ComputeRPath(cmComputeLinkInformation& cli)
std::vector<std::string> runtimeDirs;
cli.GetRPath(runtimeDirs, this->Relink);
- for (std::vector<std::string>::iterator ri = runtimeDirs.begin();
- ri != runtimeDirs.end(); ++ri) {
+ for (std::string const& rd : runtimeDirs) {
rpath += cli.GetRuntimeFlag();
- rpath += this->ConvertToOutputFormat(*ri);
+ rpath += this->ConvertToOutputFormat(rd);
rpath += " ";
}
} else {
@@ -150,10 +165,9 @@ std::string cmLinkLineComputer::ComputeFrameworkPath(
std::string frameworkPath;
if (!fwSearchFlag.empty()) {
std::vector<std::string> const& fwDirs = cli.GetFrameworkPaths();
- for (std::vector<std::string>::const_iterator fdi = fwDirs.begin();
- fdi != fwDirs.end(); ++fdi) {
+ for (std::string const& fd : fwDirs) {
frameworkPath += fwSearchFlag;
- frameworkPath += this->ConvertToOutputFormat(*fdi);
+ frameworkPath += this->ConvertToOutputFormat(fd);
frameworkPath += " ";
}
}
diff --git a/Source/cmLinkLineComputer.h b/Source/cmLinkLineComputer.h
index d33e8d1ff..2355c3270 100644
--- a/Source/cmLinkLineComputer.h
+++ b/Source/cmLinkLineComputer.h
@@ -4,7 +4,7 @@
#ifndef cmLinkLineComputer_h
#define cmLinkLineComputer_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -16,13 +16,14 @@ class cmOutputConverter;
class cmLinkLineComputer
{
- CM_DISABLE_COPY(cmLinkLineComputer)
-
public:
cmLinkLineComputer(cmOutputConverter* outputConverter,
cmStateDirectory const& stateDir);
virtual ~cmLinkLineComputer();
+ cmLinkLineComputer(cmLinkLineComputer const&) = delete;
+ cmLinkLineComputer& operator=(cmLinkLineComputer const&) = delete;
+
void SetUseWatcomQuote(bool useWatcomQuote);
void SetForResponse(bool forResponse);
void SetRelink(bool relink);
diff --git a/Source/cmLinkLineDeviceComputer.cxx b/Source/cmLinkLineDeviceComputer.cxx
index 942e9b92c..8d2add635 100644
--- a/Source/cmLinkLineDeviceComputer.cxx
+++ b/Source/cmLinkLineDeviceComputer.cxx
@@ -3,14 +3,21 @@
#include "cmLinkLineDeviceComputer.h"
+#include <algorithm>
#include <set>
#include <sstream>
+#include <utility>
#include <vector>
+#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
#include "cmGeneratorTarget.h"
-#include "cmGlobalNinjaGenerator.h"
+#include "cmGlobalGenerator.h"
+#include "cmLocalGenerator.h"
+#include "cmStateDirectory.h"
+#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
+#include "cmSystemTools.h"
class cmOutputConverter;
@@ -20,8 +27,45 @@ cmLinkLineDeviceComputer::cmLinkLineDeviceComputer(
{
}
-cmLinkLineDeviceComputer::~cmLinkLineDeviceComputer()
+cmLinkLineDeviceComputer::~cmLinkLineDeviceComputer() = default;
+
+static bool cmLinkItemValidForDevice(std::string const& item)
{
+ // Valid items are:
+ // * Non-flags (does not start in '-')
+ // * Specific flags --library, --library-path, -l, -L
+ // For example:
+ // * 'cublas_device' => pass-along
+ // * '--library pthread' => pass-along
+ // * '-lpthread' => pass-along
+ // * '-pthread' => drop
+ // * '-a' => drop
+ // * '-framework Name' (as one string) => drop
+ return (!cmHasLiteralPrefix(item, "-") || //
+ cmHasLiteralPrefix(item, "-l") || //
+ cmHasLiteralPrefix(item, "-L") || //
+ cmHasLiteralPrefix(item, "--library"));
+}
+
+bool cmLinkLineDeviceComputer::ComputeRequiresDeviceLinking(
+ cmComputeLinkInformation& cli)
+{
+ // Determine if this item might requires device linking.
+ // For this we only consider targets
+ typedef cmComputeLinkInformation::ItemVector ItemVector;
+ ItemVector const& items = cli.GetItems();
+ std::string config = cli.GetConfig();
+ for (auto const& item : items) {
+ if (item.Target &&
+ item.Target->GetType() == cmStateEnums::STATIC_LIBRARY) {
+ if ((!item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS")) &&
+ item.Target->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
+ // this dependency requires us to device link it
+ return true;
+ }
+ }
+ }
+ return false;
}
std::string cmLinkLineDeviceComputer::ComputeLinkLibraries(
@@ -29,49 +73,63 @@ std::string cmLinkLineDeviceComputer::ComputeLinkLibraries(
{
// Write the library flags to the build rule.
std::ostringstream fout;
+
+ // Generate the unique set of link items when device linking.
+ // The nvcc device linker is designed so that each static library
+ // with device symbols only needs to be listed once as it doesn't
+ // care about link order.
+ std::set<std::string> emitted;
typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector const& items = cli.GetItems();
std::string config = cli.GetConfig();
- for (ItemVector::const_iterator li = items.begin(); li != items.end();
- ++li) {
- if (!li->Target) {
+ bool skipItemAfterFramework = false;
+ for (auto const& item : items) {
+ if (skipItemAfterFramework) {
+ skipItemAfterFramework = false;
continue;
}
- bool skippable = false;
- switch (li->Target->GetType()) {
- case cmStateEnums::SHARED_LIBRARY:
- case cmStateEnums::MODULE_LIBRARY:
- case cmStateEnums::INTERFACE_LIBRARY:
- skippable = true;
- break;
- case cmStateEnums::STATIC_LIBRARY:
- // If a static library is resolving its device linking, it should
- // be removed for other device linking
- skippable =
- li->Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS");
- break;
- default:
- break;
- }
-
- if (skippable) {
- continue;
+ if (item.Target) {
+ bool skip = false;
+ switch (item.Target->GetType()) {
+ case cmStateEnums::MODULE_LIBRARY:
+ case cmStateEnums::INTERFACE_LIBRARY:
+ skip = true;
+ break;
+ case cmStateEnums::STATIC_LIBRARY:
+ skip = item.Target->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS");
+ break;
+ default:
+ break;
+ }
+ if (skip) {
+ continue;
+ }
}
- std::set<std::string> langs;
- li->Target->GetLanguages(langs, config);
- if (langs.count("CUDA") == 0) {
+ std::string out;
+ if (item.IsPath) {
+ // nvcc understands absolute paths to libraries ending in '.a' or '.lib'.
+ // These should be passed to nvlink. Other extensions need to be left
+ // out because nvlink may not understand or need them. Even though it
+ // can tolerate '.so' or '.dylib' it cannot tolerate '.so.1'.
+ if (cmHasLiteralSuffix(item.Value, ".a") ||
+ cmHasLiteralSuffix(item.Value, ".lib")) {
+ out += this->ConvertToOutputFormat(
+ this->ConvertToLinkReference(item.Value));
+ }
+ } else if (item.Value == "-framework") {
+ // This is the first part of '-framework Name' where the framework
+ // name is specified as a following item. Ignore both.
+ skipItemAfterFramework = true;
continue;
+ } else if (cmLinkItemValidForDevice(item.Value)) {
+ out += item.Value;
}
- if (li->IsPath) {
- fout << this->ConvertToOutputFormat(
- this->ConvertToLinkReference(li->Value));
- } else {
- fout << li->Value;
+ if (emitted.insert(out).second) {
+ fout << out << " ";
}
- fout << " ";
}
if (!stdLibString.empty()) {
@@ -87,16 +145,58 @@ std::string cmLinkLineDeviceComputer::GetLinkerLanguage(cmGeneratorTarget*,
return "CUDA";
}
-cmNinjaLinkLineDeviceComputer::cmNinjaLinkLineDeviceComputer(
- cmOutputConverter* outputConverter, cmStateDirectory const& stateDir,
- cmGlobalNinjaGenerator const* gg)
- : cmLinkLineDeviceComputer(outputConverter, stateDir)
- , GG(gg)
+bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg,
+ const std::string& config)
{
-}
+ if (!target.GetGlobalGenerator()->GetLanguageEnabled("CUDA")) {
+ return false;
+ }
-std::string cmNinjaLinkLineDeviceComputer::ConvertToLinkReference(
- std::string const& lib) const
-{
- return GG->ConvertToNinjaPath(lib);
+ if (target.GetType() == cmStateEnums::OBJECT_LIBRARY) {
+ return false;
+ }
+
+ if (const char* resolveDeviceSymbols =
+ target.GetProperty("CUDA_RESOLVE_DEVICE_SYMBOLS")) {
+ // If CUDA_RESOLVE_DEVICE_SYMBOLS has been explicitly set we need
+ // to honor the value no matter what it is.
+ return cmSystemTools::IsOn(resolveDeviceSymbols);
+ }
+
+ if (const char* separableCompilation =
+ target.GetProperty("CUDA_SEPARABLE_COMPILATION")) {
+ if (cmSystemTools::IsOn(separableCompilation)) {
+ bool doDeviceLinking = false;
+ switch (target.GetType()) {
+ case cmStateEnums::SHARED_LIBRARY:
+ case cmStateEnums::MODULE_LIBRARY:
+ case cmStateEnums::EXECUTABLE:
+ doDeviceLinking = true;
+ break;
+ default:
+ break;
+ }
+ return doDeviceLinking;
+ }
+ }
+
+ // Determine if we have any dependencies that require
+ // us to do a device link step
+ const std::string cuda_lang("CUDA");
+ cmGeneratorTarget::LinkClosure const* closure =
+ target.GetLinkClosure(config);
+
+ bool closureHasCUDA =
+ (std::find(closure->Languages.begin(), closure->Languages.end(),
+ cuda_lang) != closure->Languages.end());
+ if (closureHasCUDA) {
+ cmComputeLinkInformation* pcli = target.GetLinkInformation(config);
+ if (pcli) {
+ cmLinkLineDeviceComputer deviceLinkComputer(
+ &lg, lg.GetStateSnapshot().GetDirectory());
+ return deviceLinkComputer.ComputeRequiresDeviceLinking(*pcli);
+ }
+ return true;
+ }
+ return false;
}
diff --git a/Source/cmLinkLineDeviceComputer.h b/Source/cmLinkLineDeviceComputer.h
index c3fac6182..0ea5f69e7 100644
--- a/Source/cmLinkLineDeviceComputer.h
+++ b/Source/cmLinkLineDeviceComputer.h
@@ -4,7 +4,7 @@
#ifndef cmLinkLineDeviceComputer_h
#define cmLinkLineDeviceComputer_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -12,41 +12,31 @@
class cmComputeLinkInformation;
class cmGeneratorTarget;
-class cmGlobalNinjaGenerator;
+class cmLocalGenerator;
class cmOutputConverter;
class cmStateDirectory;
class cmLinkLineDeviceComputer : public cmLinkLineComputer
{
- CM_DISABLE_COPY(cmLinkLineDeviceComputer)
-
public:
cmLinkLineDeviceComputer(cmOutputConverter* outputConverter,
cmStateDirectory const& stateDir);
- ~cmLinkLineDeviceComputer() CM_OVERRIDE;
+ ~cmLinkLineDeviceComputer() override;
+
+ cmLinkLineDeviceComputer(cmLinkLineDeviceComputer const&) = delete;
+ cmLinkLineDeviceComputer& operator=(cmLinkLineDeviceComputer const&) =
+ delete;
+
+ bool ComputeRequiresDeviceLinking(cmComputeLinkInformation& cli);
std::string ComputeLinkLibraries(cmComputeLinkInformation& cli,
- std::string const& stdLibString)
- CM_OVERRIDE;
+ std::string const& stdLibString) override;
std::string GetLinkerLanguage(cmGeneratorTarget* target,
- std::string const& config) CM_OVERRIDE;
+ std::string const& config) override;
};
-class cmNinjaLinkLineDeviceComputer : public cmLinkLineDeviceComputer
-{
- CM_DISABLE_COPY(cmNinjaLinkLineDeviceComputer)
-
-public:
- cmNinjaLinkLineDeviceComputer(cmOutputConverter* outputConverter,
- cmStateDirectory const& stateDir,
- cmGlobalNinjaGenerator const* gg);
-
- std::string ConvertToLinkReference(std::string const& input) const
- CM_OVERRIDE;
-
-private:
- cmGlobalNinjaGenerator const* GG;
-};
+bool requireDeviceLinking(cmGeneratorTarget& target, cmLocalGenerator& lg,
+ const std::string& config);
#endif
diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h
index 55592cb35..099fb6d11 100644
--- a/Source/cmLinkedTree.h
+++ b/Source/cmLinkedTree.h
@@ -3,10 +3,9 @@
#ifndef cmLinkedTree_h
#define cmLinkedTree_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <assert.h>
-#include <iterator>
#include <vector>
/**
@@ -33,7 +32,7 @@ class cmLinkedTree
typedef T& ReferenceType;
public:
- class iterator : public std::iterator<std::forward_iterator_tag, T>
+ class iterator
{
friend class cmLinkedTree;
cmLinkedTree* Tree;
@@ -49,7 +48,7 @@ public:
public:
iterator()
- : Tree(CM_NULLPTR)
+ : Tree(nullptr)
, Position(0)
{
}
@@ -137,7 +136,7 @@ public:
iterator Push(iterator it) { return Push_impl(it, T()); }
- iterator Push(iterator it, T t) { return Push_impl(it, t); }
+ iterator Push(iterator it, T t) { return Push_impl(it, std::move(t)); }
bool IsLast(iterator it) { return it.Position == this->Data.size(); }
@@ -177,12 +176,12 @@ private:
T* GetPointer(PositionType pos) { return &this->Data[pos]; }
- iterator Push_impl(iterator it, T t)
+ iterator Push_impl(iterator it, T&& t)
{
assert(this->UpPositions.size() == this->Data.size());
assert(it.Position <= this->UpPositions.size());
this->UpPositions.push_back(it.Position);
- this->Data.push_back(t);
+ this->Data.push_back(std::move(t));
return iterator(this, this->UpPositions.size());
}
diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx
index 0542c4fce..1b01ea202 100644
--- a/Source/cmListCommand.cxx
+++ b/Source/cmListCommand.cxx
@@ -5,16 +5,23 @@
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <assert.h>
+#include <functional>
#include <iterator>
+#include <set>
#include <sstream>
+#include <stdexcept>
#include <stdio.h>
#include <stdlib.h> // required for atoi
+#include <utility>
#include "cmAlgorithms.h"
+#include "cmGeneratorExpression.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
+#include "cmRange.h"
+#include "cmStringReplaceHelper.h"
#include "cmSystemTools.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -36,12 +43,24 @@ bool cmListCommand::InitialPass(std::vector<std::string> const& args,
if (subCommand == "APPEND") {
return this->HandleAppendCommand(args);
}
+ if (subCommand == "PREPEND") {
+ return this->HandlePrependCommand(args);
+ }
+ if (subCommand == "POP_BACK") {
+ return this->HandlePopBackCommand(args);
+ }
+ if (subCommand == "POP_FRONT") {
+ return this->HandlePopFrontCommand(args);
+ }
if (subCommand == "FIND") {
return this->HandleFindCommand(args);
}
if (subCommand == "INSERT") {
return this->HandleInsertCommand(args);
}
+ if (subCommand == "JOIN") {
+ return this->HandleJoinCommand(args);
+ }
if (subCommand == "REMOVE_AT") {
return this->HandleRemoveAtCommand(args);
}
@@ -51,9 +70,15 @@ bool cmListCommand::InitialPass(std::vector<std::string> const& args,
if (subCommand == "REMOVE_DUPLICATES") {
return this->HandleRemoveDuplicatesCommand(args);
}
+ if (subCommand == "TRANSFORM") {
+ return this->HandleTransformCommand(args);
+ }
if (subCommand == "SORT") {
return this->HandleSortCommand(args);
}
+ if (subCommand == "SUBLIST") {
+ return this->HandleSublistCommand(args);
+ }
if (subCommand == "REVERSE") {
return this->HandleReverseCommand(args);
}
@@ -108,7 +133,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list,
warn += " List has value = [";
warn += listString;
warn += "].";
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, warn);
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, warn);
return true;
}
case cmPolicies::OLD:
@@ -123,7 +148,7 @@ bool cmListCommand::GetList(std::vector<std::string>& list,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0007));
return false;
}
@@ -138,7 +163,7 @@ bool cmListCommand::HandleLengthCommand(std::vector<std::string> const& args)
}
const std::string& listName = args[1];
- const std::string& variableName = args[args.size() - 1];
+ const std::string& variableName = args.back();
std::vector<std::string> varArgsExpanded;
// do not check the return value here
// if the list var is not found varArgsExpanded will have size 0
@@ -160,7 +185,7 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
}
const std::string& listName = args[1];
- const std::string& variableName = args[args.size() - 1];
+ const std::string& variableName = args.back();
// expand the variable
std::vector<std::string> varArgsExpanded;
if (!this->GetList(varArgsExpanded, listName)) {
@@ -182,9 +207,9 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args)
value += sep;
sep = ";";
if (item < 0) {
- item = (int)nitem + item;
+ item = static_cast<int>(nitem) + item;
}
- if (item < 0 || nitem <= (size_t)item) {
+ if (item < 0 || nitem <= static_cast<size_t>(item)) {
std::ostringstream str;
str << "index: " << item << " out of range (-" << nitem << ", "
<< nitem - 1 << ")";
@@ -207,20 +232,141 @@ bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args)
return true;
}
- const std::string& listName = args[1];
+ std::string const& listName = args[1];
// expand the variable
std::string listString;
this->GetListString(listString, listName);
- if (!listString.empty() && !args.empty()) {
- listString += ";";
+ // If `listString` or `args` is empty, no need to append `;`,
+ // then index is going to be `1` and points to the end-of-string ";"
+ auto const offset =
+ std::string::size_type(listString.empty() || args.empty());
+ listString += &";"[offset] + cmJoin(cmMakeRange(args).advance(2), ";");
+
+ this->Makefile->AddDefinition(listName, listString.c_str());
+ return true;
+}
+
+bool cmListCommand::HandlePrependCommand(std::vector<std::string> const& args)
+{
+ assert(args.size() >= 2);
+
+ // Skip if nothing to prepend.
+ if (args.size() < 3) {
+ return true;
}
- listString += cmJoin(cmMakeRange(args).advance(2), ";");
+
+ std::string const& listName = args[1];
+ // expand the variable
+ std::string listString;
+ this->GetListString(listString, listName);
+
+ // If `listString` or `args` is empty, no need to append `;`,
+ // then `offset` is going to be `1` and points to the end-of-string ";"
+ auto const offset =
+ std::string::size_type(listString.empty() || args.empty());
+ listString.insert(0,
+ cmJoin(cmMakeRange(args).advance(2), ";") + &";"[offset]);
this->Makefile->AddDefinition(listName, listString.c_str());
return true;
}
+bool cmListCommand::HandlePopBackCommand(std::vector<std::string> const& args)
+{
+ assert(args.size() >= 2);
+
+ auto ai = args.cbegin();
+ ++ai; // Skip subcommand name
+ std::string const& listName = *ai++;
+ std::vector<std::string> varArgsExpanded;
+ if (!this->GetList(varArgsExpanded, listName)) {
+ // Can't get the list definition... undefine any vars given after.
+ for (; ai != args.cend(); ++ai) {
+ this->Makefile->RemoveDefinition(*ai);
+ }
+ return true;
+ }
+
+ if (!varArgsExpanded.empty()) {
+ if (ai == args.cend()) {
+ // No variables are given... Just remove one element.
+ varArgsExpanded.pop_back();
+ } else {
+ // Ok, assign elements to be removed to the given variables
+ for (; !varArgsExpanded.empty() && ai != args.cend(); ++ai) {
+ assert(!ai->empty());
+ this->Makefile->AddDefinition(*ai, varArgsExpanded.back().c_str());
+ varArgsExpanded.pop_back();
+ }
+ // Undefine the rest variables if the list gets empty earlier...
+ for (; ai != args.cend(); ++ai) {
+ this->Makefile->RemoveDefinition(*ai);
+ }
+ }
+
+ this->Makefile->AddDefinition(listName,
+ cmJoin(varArgsExpanded, ";").c_str());
+
+ } else if (ai !=
+ args.cend()) { // The list is empty, but some args were given
+ // Need to *undefine* 'em all, cuz there are no items to assign...
+ for (; ai != args.cend(); ++ai) {
+ this->Makefile->RemoveDefinition(*ai);
+ }
+ }
+
+ return true;
+}
+
+bool cmListCommand::HandlePopFrontCommand(std::vector<std::string> const& args)
+{
+ assert(args.size() >= 2);
+
+ auto ai = args.cbegin();
+ ++ai; // Skip subcommand name
+ std::string const& listName = *ai++;
+ std::vector<std::string> varArgsExpanded;
+ if (!this->GetList(varArgsExpanded, listName)) {
+ // Can't get the list definition... undefine any vars given after.
+ for (; ai != args.cend(); ++ai) {
+ this->Makefile->RemoveDefinition(*ai);
+ }
+ return true;
+ }
+
+ if (!varArgsExpanded.empty()) {
+ if (ai == args.cend()) {
+ // No variables are given... Just remove one element.
+ varArgsExpanded.erase(varArgsExpanded.begin());
+ } else {
+ // Ok, assign elements to be removed to the given variables
+ auto vi = varArgsExpanded.begin();
+ for (; vi != varArgsExpanded.end() && ai != args.cend(); ++ai, ++vi) {
+ assert(!ai->empty());
+ this->Makefile->AddDefinition(*ai, vi->c_str());
+ }
+ varArgsExpanded.erase(varArgsExpanded.begin(), vi);
+ // Undefine the rest variables if the list gets empty earlier...
+ for (; ai != args.cend(); ++ai) {
+ this->Makefile->RemoveDefinition(*ai);
+ }
+ }
+
+ this->Makefile->AddDefinition(listName,
+ cmJoin(varArgsExpanded, ";").c_str());
+
+ } else if (ai !=
+ args.cend()) { // The list is empty, but some args were given
+ // Need to *undefine* 'em all, cuz there are no items to assign...
+ for (; ai != args.cend(); ++ai) {
+ this->Makefile->RemoveDefinition(*ai);
+ }
+ }
+
+ return true;
+}
+
bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args)
{
if (args.size() != 4) {
@@ -229,7 +375,7 @@ bool cmListCommand::HandleFindCommand(std::vector<std::string> const& args)
}
const std::string& listName = args[1];
- const std::string& variableName = args[args.size() - 1];
+ const std::string& variableName = args.back();
// expand the variable
std::vector<std::string> varArgsExpanded;
if (!this->GetList(varArgsExpanded, listName)) {
@@ -273,14 +419,12 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
if (!varArgsExpanded.empty()) {
size_t nitem = varArgsExpanded.size();
if (item < 0) {
- item = (int)nitem + item;
+ item = static_cast<int>(nitem) + item;
}
- if (item < 0 || nitem <= (size_t)item) {
+ if (item < 0 || nitem < static_cast<size_t>(item)) {
std::ostringstream str;
str << "index: " << item << " out of range (-" << varArgsExpanded.size()
- << ", "
- << (varArgsExpanded.empty() ? 0 : (varArgsExpanded.size() - 1))
- << ")";
+ << ", " << varArgsExpanded.size() << ")";
this->SetError(str.str());
return false;
}
@@ -294,6 +438,34 @@ bool cmListCommand::HandleInsertCommand(std::vector<std::string> const& args)
return true;
}
+bool cmListCommand::HandleJoinCommand(std::vector<std::string> const& args)
+{
+ if (args.size() != 4) {
+ std::ostringstream error;
+ error << "sub-command JOIN requires three arguments (" << args.size() - 1
+ << " found).";
+ this->SetError(error.str());
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ const std::string& glue = args[2];
+ const std::string& variableName = args[3];
+
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if (!this->GetList(varArgsExpanded, listName)) {
+ this->Makefile->AddDefinition(variableName, "");
+ return true;
+ }
+
+ std::string value =
+ cmJoin(cmMakeRange(varArgsExpanded.begin(), varArgsExpanded.end()), glue);
+
+ this->Makefile->AddDefinition(variableName, value.c_str());
+ return true;
+}
+
bool cmListCommand::HandleRemoveItemCommand(
std::vector<std::string> const& args)
{
@@ -306,8 +478,7 @@ bool cmListCommand::HandleRemoveItemCommand(
// 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;
+ return true;
}
std::vector<std::string> remove(args.begin() + 2, args.end());
@@ -336,8 +507,7 @@ bool cmListCommand::HandleReverseCommand(std::vector<std::string> const& args)
// 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;
+ return true;
}
std::string value = cmJoin(cmReverseRange(varArgsExpanded), ";");
@@ -359,9 +529,7 @@ bool cmListCommand::HandleRemoveDuplicatesCommand(
// 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;
+ return true;
}
std::vector<std::string>::const_iterator argsEnd =
@@ -373,29 +541,815 @@ bool cmListCommand::HandleRemoveDuplicatesCommand(
return true;
}
+// Helpers for list(TRANSFORM <list> ...)
+namespace {
+using transform_type = std::function<std::string(const std::string&)>;
+
+class transform_error : public std::runtime_error
+{
+public:
+ transform_error(const std::string& error)
+ : std::runtime_error(error)
+ {
+ }
+};
+
+class TransformSelector
+{
+public:
+ virtual ~TransformSelector() = default;
+
+ std::string Tag;
+
+ virtual bool Validate(std::size_t count = 0) = 0;
+
+ virtual bool InSelection(const std::string&) = 0;
+
+ virtual void Transform(std::vector<std::string>& list,
+ const transform_type& transform)
+ {
+ std::transform(list.begin(), list.end(), list.begin(), transform);
+ }
+
+protected:
+ TransformSelector(std::string&& tag)
+ : Tag(std::move(tag))
+ {
+ }
+};
+class TransformNoSelector : public TransformSelector
+{
+public:
+ TransformNoSelector()
+ : TransformSelector("NO SELECTOR")
+ {
+ }
+
+ bool Validate(std::size_t) override { return true; }
+
+ bool InSelection(const std::string&) override { return true; }
+};
+class TransformSelectorRegex : public TransformSelector
+{
+public:
+ TransformSelectorRegex(const std::string& regex)
+ : TransformSelector("REGEX")
+ , Regex(regex)
+ {
+ }
+
+ bool Validate(std::size_t) override { return this->Regex.is_valid(); }
+
+ bool InSelection(const std::string& value) override
+ {
+ return this->Regex.find(value);
+ }
+
+ cmsys::RegularExpression Regex;
+};
+class TransformSelectorIndexes : public TransformSelector
+{
+public:
+ std::vector<int> Indexes;
+
+ bool InSelection(const std::string&) override { return true; }
+
+ void Transform(std::vector<std::string>& list,
+ const transform_type& transform) override
+ {
+ this->Validate(list.size());
+
+ for (auto index : this->Indexes) {
+ list[index] = transform(list[index]);
+ }
+ }
+
+protected:
+ TransformSelectorIndexes(std::string&& tag)
+ : TransformSelector(std::move(tag))
+ {
+ }
+ TransformSelectorIndexes(std::string&& tag, std::vector<int>&& indexes)
+ : TransformSelector(std::move(tag))
+ , Indexes(indexes)
+ {
+ }
+
+ int NormalizeIndex(int index, std::size_t count)
+ {
+ if (index < 0) {
+ index = static_cast<int>(count) + index;
+ }
+ if (index < 0 || count <= static_cast<std::size_t>(index)) {
+ std::ostringstream str;
+ str << "sub-command TRANSFORM, selector " << this->Tag
+ << ", index: " << index << " out of range (-" << count << ", "
+ << count - 1 << ").";
+ throw transform_error(str.str());
+ }
+ return index;
+ }
+};
+class TransformSelectorAt : public TransformSelectorIndexes
+{
+public:
+ TransformSelectorAt(std::vector<int>&& indexes)
+ : TransformSelectorIndexes("AT", std::move(indexes))
+ {
+ }
+
+ bool Validate(std::size_t count) override
+ {
+ decltype(Indexes) indexes;
+
+ for (auto index : Indexes) {
+ indexes.push_back(this->NormalizeIndex(index, count));
+ }
+ this->Indexes = std::move(indexes);
+
+ return true;
+ }
+};
+class TransformSelectorFor : public TransformSelectorIndexes
+{
+public:
+ TransformSelectorFor(int start, int stop, int step)
+ : TransformSelectorIndexes("FOR")
+ , Start(start)
+ , Stop(stop)
+ , Step(step)
+ {
+ }
+
+ bool Validate(std::size_t count) override
+ {
+ this->Start = this->NormalizeIndex(this->Start, count);
+ this->Stop = this->NormalizeIndex(this->Stop, count);
+
+ // compute indexes
+ auto size = (this->Stop - this->Start + 1) / this->Step;
+ if ((this->Stop - this->Start + 1) % this->Step != 0) {
+ size += 1;
+ }
+
+ this->Indexes.resize(size);
+ auto start = this->Start, step = this->Step;
+ std::generate(this->Indexes.begin(), this->Indexes.end(),
+ [&start, step]() -> int {
+ auto r = start;
+ start += step;
+ return r;
+ });
+
+ return true;
+ }
+
+private:
+ int Start, Stop, Step;
+};
+
+class TransformAction
+{
+public:
+ virtual ~TransformAction() = default;
+
+ virtual std::string Transform(const std::string& input) = 0;
+};
+class TransformReplace : public TransformAction
+{
+public:
+ TransformReplace(const std::vector<std::string>& arguments,
+ cmMakefile* makefile)
+ : ReplaceHelper(arguments[0], arguments[1], makefile)
+ {
+ makefile->ClearMatches();
+
+ if (!this->ReplaceHelper.IsRegularExpressionValid()) {
+ std::ostringstream error;
+ error
+ << "sub-command TRANSFORM, action REPLACE: Failed to compile regex \""
+ << arguments[0] << "\".";
+ throw transform_error(error.str());
+ }
+ if (!this->ReplaceHelper.IsReplaceExpressionValid()) {
+ std::ostringstream error;
+ error << "sub-command TRANSFORM, action REPLACE: "
+ << this->ReplaceHelper.GetError() << ".";
+ throw transform_error(error.str());
+ }
+ }
+
+ std::string Transform(const std::string& input) override
+ {
+ // Scan through the input for all matches.
+ std::string output;
+
+ if (!this->ReplaceHelper.Replace(input, output)) {
+ std::ostringstream error;
+ error << "sub-command TRANSFORM, action REPLACE: "
+ << this->ReplaceHelper.GetError() << ".";
+ throw transform_error(error.str());
+ }
+
+ return output;
+ }
+
+private:
+ cmStringReplaceHelper ReplaceHelper;
+};
+}
+
+bool cmListCommand::HandleTransformCommand(
+ std::vector<std::string> const& args)
+{
+ if (args.size() < 3) {
+ this->SetError(
+ "sub-command TRANSFORM requires an action to be specified.");
+ return false;
+ }
+
+ // Structure collecting all elements of the command
+ struct Command
+ {
+ Command(const std::string& listName)
+ : ListName(listName)
+ , OutputName(listName)
+ {
+ }
+
+ std::string Name;
+ std::string ListName;
+ std::vector<std::string> Arguments;
+ std::unique_ptr<TransformAction> Action;
+ std::unique_ptr<TransformSelector> Selector;
+ std::string OutputName;
+ } command(args[1]);
+
+ // Descriptor of action
+ // Arity: number of arguments required for the action
+ // Transform: lambda function implementing the action
+ struct ActionDescriptor
+ {
+ ActionDescriptor(std::string name)
+ : Name(std::move(name))
+ {
+ }
+ ActionDescriptor(std::string name, int arity, transform_type transform)
+ : Name(std::move(name))
+ , Arity(arity)
+#if defined(__GNUC__) && __GNUC__ == 6 && defined(__aarch64__)
+ // std::function move constructor miscompiles on this architecture
+ , Transform(transform)
+#else
+ , Transform(std::move(transform))
+#endif
+ {
+ }
+
+ operator const std::string&() const { return Name; }
+
+ std::string Name;
+ int Arity = 0;
+ transform_type Transform;
+ };
+
+ // Build a set of supported actions.
+ std::set<ActionDescriptor,
+ std::function<bool(const std::string&, const std::string&)>>
+ descriptors(
+ [](const std::string& x, const std::string& y) { return x < y; });
+ descriptors = { { "APPEND", 1,
+ [&command](const std::string& s) -> std::string {
+ if (command.Selector->InSelection(s)) {
+ return s + command.Arguments[0];
+ }
+
+ return s;
+ } },
+ { "PREPEND", 1,
+ [&command](const std::string& s) -> std::string {
+ if (command.Selector->InSelection(s)) {
+ return command.Arguments[0] + s;
+ }
+
+ return s;
+ } },
+ { "TOUPPER", 0,
+ [&command](const std::string& s) -> std::string {
+ if (command.Selector->InSelection(s)) {
+ return cmSystemTools::UpperCase(s);
+ }
+
+ return s;
+ } },
+ { "TOLOWER", 0,
+ [&command](const std::string& s) -> std::string {
+ if (command.Selector->InSelection(s)) {
+ return cmSystemTools::LowerCase(s);
+ }
+
+ return s;
+ } },
+ { "STRIP", 0,
+ [&command](const std::string& s) -> std::string {
+ if (command.Selector->InSelection(s)) {
+ return cmSystemTools::TrimWhitespace(s);
+ }
+
+ return s;
+ } },
+ { "GENEX_STRIP", 0,
+ [&command](const std::string& s) -> std::string {
+ if (command.Selector->InSelection(s)) {
+ return cmGeneratorExpression::Preprocess(
+ s,
+ cmGeneratorExpression::StripAllGeneratorExpressions);
+ }
+
+ return s;
+ } },
+ { "REPLACE", 2,
+ [&command](const std::string& s) -> std::string {
+ if (command.Selector->InSelection(s)) {
+ return command.Action->Transform(s);
+ }
+
+ return s;
+ } } };
+
+ using size_type = std::vector<std::string>::size_type;
+ size_type index = 2;
+
+ // Parse all possible function parameters
+ auto descriptor = descriptors.find(args[index]);
+
+ if (descriptor == descriptors.end()) {
+ std::ostringstream error;
+ error << " sub-command TRANSFORM, " << args[index] << " invalid action.";
+ this->SetError(error.str());
+ return false;
+ }
+
+ // Action arguments
+ index += 1;
+ if (args.size() < index + descriptor->Arity) {
+ std::ostringstream error;
+ error << "sub-command TRANSFORM, action " << descriptor->Name
+ << " expects " << descriptor->Arity << " argument(s).";
+ this->SetError(error.str());
+ return false;
+ }
+
+ command.Name = descriptor->Name;
+ index += descriptor->Arity;
+ if (descriptor->Arity > 0) {
+ command.Arguments =
+ std::vector<std::string>(args.begin() + 3, args.begin() + index);
+ }
+
+ if (command.Name == "REPLACE") {
+ try {
+ command.Action =
+ cm::make_unique<TransformReplace>(command.Arguments, this->Makefile);
+ } catch (const transform_error& e) {
+ this->SetError(e.what());
+ return false;
+ }
+ }
+
+ const std::string REGEX{ "REGEX" }, AT{ "AT" }, FOR{ "FOR" },
+ OUTPUT_VARIABLE{ "OUTPUT_VARIABLE" };
+
+ // handle optional arguments
+ while (args.size() > index) {
+ if ((args[index] == REGEX || args[index] == AT || args[index] == FOR) &&
+ command.Selector) {
+ std::ostringstream error;
+ error << "sub-command TRANSFORM, selector already specified ("
+ << command.Selector->Tag << ").";
+ this->SetError(error.str());
+ return false;
+ }
+
+ // REGEX selector
+ if (args[index] == REGEX) {
+ if (args.size() == ++index) {
+ this->SetError("sub-command TRANSFORM, selector REGEX expects "
+ "'regular expression' argument.");
+ return false;
+ }
+
+ command.Selector = cm::make_unique<TransformSelectorRegex>(args[index]);
+ if (!command.Selector->Validate()) {
+ std::ostringstream error;
+ error << "sub-command TRANSFORM, selector REGEX failed to compile "
+ "regex \"";
+ error << args[index] << "\".";
+ this->SetError(error.str());
+ return false;
+ }
+
+ index += 1;
+ continue;
+ }
+
+ // AT selector
+ if (args[index] == AT) {
+ // get all specified indexes
+ std::vector<int> indexes;
+ while (args.size() > ++index) {
+ std::size_t pos;
+ int value;
+
+ try {
+ value = std::stoi(args[index], &pos);
+ if (pos != args[index].length()) {
+ // this is not a number, stop processing
+ break;
+ }
+ indexes.push_back(value);
+ } catch (const std::invalid_argument&) {
+ // this is not a number, stop processing
+ break;
+ }
+ }
+
+ if (indexes.empty()) {
+ this->SetError(
+ "sub-command TRANSFORM, selector AT expects at least one "
+ "numeric value.");
+ return false;
+ }
+
+ command.Selector =
+ cm::make_unique<TransformSelectorAt>(std::move(indexes));
+
+ continue;
+ }
+
+ // FOR selector
+ if (args[index] == FOR) {
+ if (args.size() <= ++index + 1) {
+ this->SetError("sub-command TRANSFORM, selector FOR expects, at least,"
+ " two arguments.");
+ return false;
+ }
+
+ int start = 0, stop = 0, step = 1;
+ bool valid = true;
+ try {
+ std::size_t pos;
+
+ start = std::stoi(args[index], &pos);
+ if (pos != args[index].length()) {
+ // this is not a number
+ valid = false;
+ } else {
+ stop = std::stoi(args[++index], &pos);
+ if (pos != args[index].length()) {
+ // this is not a number
+ valid = false;
+ }
+ }
+ } catch (const std::invalid_argument&) {
+ // this is not numbers
+ valid = false;
+ }
+ if (!valid) {
+ this->SetError("sub-command TRANSFORM, selector FOR expects, "
+ "at least, two numeric values.");
+ return false;
+ }
+ // try to read a third numeric value for step
+ if (args.size() > ++index) {
+ try {
+ std::size_t pos;
+
+ step = std::stoi(args[index], &pos);
+ if (pos != args[index].length()) {
+ // this is not a number
+ step = 1;
+ } else {
+ index += 1;
+ }
+ } catch (const std::invalid_argument&) {
+ // this is not number, ignore exception
+ }
+ }
+
+ if (step < 0) {
+ this->SetError("sub-command TRANSFORM, selector FOR expects "
+ "non negative numeric value for <step>.");
+ }
+
+ command.Selector =
+ cm::make_unique<TransformSelectorFor>(start, stop, step);
+
+ continue;
+ }
+
+ // output variable
+ if (args[index] == OUTPUT_VARIABLE) {
+ if (args.size() == ++index) {
+ this->SetError("sub-command TRANSFORM, OUTPUT_VARIABLE "
+ "expects variable name argument.");
+ return false;
+ }
+
+ command.OutputName = args[index++];
+ continue;
+ }
+
+ std::ostringstream error;
+ error << "sub-command TRANSFORM, '"
+ << cmJoin(cmMakeRange(args).advance(index), " ")
+ << "': unexpected argument(s).";
+ this->SetError(error.str());
+ return false;
+ }
+
+ // expand the list variable
+ std::vector<std::string> varArgsExpanded;
+ if (!this->GetList(varArgsExpanded, command.ListName)) {
+ this->Makefile->AddDefinition(command.OutputName, "");
+ return true;
+ }
+
+ if (!command.Selector) {
+ // no selector specified, apply transformation to all elements
+ command.Selector = cm::make_unique<TransformNoSelector>();
+ }
+
+ try {
+ command.Selector->Transform(varArgsExpanded, descriptor->Transform);
+ } catch (const transform_error& e) {
+ this->SetError(e.what());
+ return false;
+ }
+
+ this->Makefile->AddDefinition(command.OutputName,
+ cmJoin(varArgsExpanded, ";").c_str());
+
+ return true;
+}
+
+class cmStringSorter
+{
+public:
+ enum class Order
+ {
+ UNINITIALIZED,
+ ASCENDING,
+ DESCENDING,
+ };
+
+ enum class Compare
+ {
+ UNINITIALIZED,
+ STRING,
+ FILE_BASENAME,
+ };
+ enum class CaseSensitivity
+ {
+ UNINITIALIZED,
+ SENSITIVE,
+ INSENSITIVE,
+ };
+
+protected:
+ typedef std::string (*StringFilter)(const std::string& in);
+ StringFilter GetCompareFilter(Compare compare)
+ {
+ return (compare == Compare::FILE_BASENAME) ? cmSystemTools::GetFilenameName
+ : nullptr;
+ }
+
+ StringFilter GetCaseFilter(CaseSensitivity sensitivity)
+ {
+ return (sensitivity == CaseSensitivity::INSENSITIVE)
+ ? cmSystemTools::LowerCase
+ : nullptr;
+ }
+
+public:
+ cmStringSorter(Compare compare, CaseSensitivity caseSensitivity,
+ Order desc = Order::ASCENDING)
+ : filters{ GetCompareFilter(compare), GetCaseFilter(caseSensitivity) }
+ , descending(desc == Order::DESCENDING)
+ {
+ }
+
+ std::string ApplyFilter(const std::string& argument)
+ {
+ std::string result = argument;
+ for (auto filter : filters) {
+ if (filter != nullptr) {
+ result = filter(result);
+ }
+ }
+ return result;
+ }
+
+ bool operator()(const std::string& a, const std::string& b)
+ {
+ std::string af = ApplyFilter(a);
+ std::string bf = ApplyFilter(b);
+ bool result;
+ if (descending) {
+ result = bf < af;
+ } else {
+ result = af < bf;
+ }
+ return result;
+ }
+
+protected:
+ StringFilter filters[2] = { nullptr, nullptr };
+ bool descending;
+};
+
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.");
+ if (args.size() > 8) {
+ this->SetError("sub-command SORT only takes up to six arguments.");
return false;
}
+ auto sortCompare = cmStringSorter::Compare::UNINITIALIZED;
+ auto sortCaseSensitivity = cmStringSorter::CaseSensitivity::UNINITIALIZED;
+ auto sortOrder = cmStringSorter::Order::UNINITIALIZED;
+
+ size_t argumentIndex = 2;
+ const std::string messageHint = "sub-command SORT ";
+
+ while (argumentIndex < args.size()) {
+ const std::string option = args[argumentIndex++];
+ if (option == "COMPARE") {
+ if (sortCompare != cmStringSorter::Compare::UNINITIALIZED) {
+ std::string error = messageHint + "option \"" + option +
+ "\" has been specified multiple times.";
+ this->SetError(error);
+ return false;
+ }
+ if (argumentIndex < args.size()) {
+ const std::string argument = args[argumentIndex++];
+ if (argument == "STRING") {
+ sortCompare = cmStringSorter::Compare::STRING;
+ } else if (argument == "FILE_BASENAME") {
+ sortCompare = cmStringSorter::Compare::FILE_BASENAME;
+ } else {
+ std::string error = messageHint + "value \"" + argument +
+ "\" for option \"" + option + "\" is invalid.";
+ this->SetError(error);
+ return false;
+ }
+ } else {
+ std::string error =
+ messageHint + "missing argument for option \"" + option + "\".";
+ this->SetError(error);
+ return false;
+ }
+ } else if (option == "CASE") {
+ if (sortCaseSensitivity !=
+ cmStringSorter::CaseSensitivity::UNINITIALIZED) {
+ std::string error = messageHint + "option \"" + option +
+ "\" has been specified multiple times.";
+ this->SetError(error);
+ return false;
+ }
+ if (argumentIndex < args.size()) {
+ const std::string argument = args[argumentIndex++];
+ if (argument == "SENSITIVE") {
+ sortCaseSensitivity = cmStringSorter::CaseSensitivity::SENSITIVE;
+ } else if (argument == "INSENSITIVE") {
+ sortCaseSensitivity = cmStringSorter::CaseSensitivity::INSENSITIVE;
+ } else {
+ std::string error = messageHint + "value \"" + argument +
+ "\" for option \"" + option + "\" is invalid.";
+ this->SetError(error);
+ return false;
+ }
+ } else {
+ std::string error =
+ messageHint + "missing argument for option \"" + option + "\".";
+ this->SetError(error);
+ return false;
+ }
+ } else if (option == "ORDER") {
+
+ if (sortOrder != cmStringSorter::Order::UNINITIALIZED) {
+ std::string error = messageHint + "option \"" + option +
+ "\" has been specified multiple times.";
+ this->SetError(error);
+ return false;
+ }
+ if (argumentIndex < args.size()) {
+ const std::string argument = args[argumentIndex++];
+ if (argument == "ASCENDING") {
+ sortOrder = cmStringSorter::Order::ASCENDING;
+ } else if (argument == "DESCENDING") {
+ sortOrder = cmStringSorter::Order::DESCENDING;
+ } else {
+ std::string error = messageHint + "value \"" + argument +
+ "\" for option \"" + option + "\" is invalid.";
+ this->SetError(error);
+ return false;
+ }
+ } else {
+ std::string error =
+ messageHint + "missing argument for option \"" + option + "\".";
+ this->SetError(error);
+ return false;
+ }
+ } else {
+ std::string error =
+ messageHint + "option \"" + option + "\" is unknown.";
+ this->SetError(error);
+ return false;
+ }
+ }
+ // set Default Values if Option is not given
+ if (sortCompare == cmStringSorter::Compare::UNINITIALIZED) {
+ sortCompare = cmStringSorter::Compare::STRING;
+ }
+ if (sortCaseSensitivity == cmStringSorter::CaseSensitivity::UNINITIALIZED) {
+ sortCaseSensitivity = cmStringSorter::CaseSensitivity::SENSITIVE;
+ }
+ if (sortOrder == cmStringSorter::Order::UNINITIALIZED) {
+ sortOrder = cmStringSorter::Order::ASCENDING;
+ }
+
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;
+ return true;
}
- std::sort(varArgsExpanded.begin(), varArgsExpanded.end());
+ if ((sortCompare == cmStringSorter::Compare::STRING) &&
+ (sortCaseSensitivity == cmStringSorter::CaseSensitivity::SENSITIVE) &&
+ (sortOrder == cmStringSorter::Order::ASCENDING)) {
+ std::sort(varArgsExpanded.begin(), varArgsExpanded.end());
+ } else {
+ cmStringSorter sorter(sortCompare, sortCaseSensitivity, sortOrder);
+ std::sort(varArgsExpanded.begin(), varArgsExpanded.end(), sorter);
+ }
std::string value = cmJoin(varArgsExpanded, ";");
this->Makefile->AddDefinition(listName, value.c_str());
return true;
}
+bool cmListCommand::HandleSublistCommand(std::vector<std::string> const& args)
+{
+ if (args.size() != 5) {
+ std::ostringstream error;
+ error << "sub-command SUBLIST requires four arguments (" << args.size() - 1
+ << " found).";
+ this->SetError(error.str());
+ return false;
+ }
+
+ const std::string& listName = args[1];
+ const std::string& variableName = args.back();
+
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if (!this->GetList(varArgsExpanded, listName) || varArgsExpanded.empty()) {
+ this->Makefile->AddDefinition(variableName, "");
+ return true;
+ }
+
+ const int start = atoi(args[2].c_str());
+ const int length = atoi(args[3].c_str());
+
+ using size_type = decltype(varArgsExpanded)::size_type;
+
+ if (start < 0 || size_type(start) >= varArgsExpanded.size()) {
+ std::ostringstream error;
+ error << "begin index: " << start << " is out of range 0 - "
+ << varArgsExpanded.size() - 1;
+ this->SetError(error.str());
+ return false;
+ }
+ if (length < -1) {
+ std::ostringstream error;
+ error << "length: " << length << " should be -1 or greater";
+ this->SetError(error.str());
+ return false;
+ }
+
+ const size_type end =
+ (length == -1 || size_type(start + length) > varArgsExpanded.size())
+ ? varArgsExpanded.size()
+ : size_type(start + length);
+ std::vector<std::string> sublist(varArgsExpanded.begin() + start,
+ varArgsExpanded.begin() + end);
+ this->Makefile->AddDefinition(variableName, cmJoin(sublist, ";").c_str());
+ return true;
+}
+
bool cmListCommand::HandleRemoveAtCommand(std::vector<std::string> const& args)
{
if (args.size() < 3) {
@@ -407,13 +1361,17 @@ bool cmListCommand::HandleRemoveAtCommand(std::vector<std::string> const& args)
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");
+ if (!this->GetList(varArgsExpanded, listName) || varArgsExpanded.empty()) {
+ std::ostringstream str;
+ str << "index: ";
+ for (size_t i = 1; i < args.size(); ++i) {
+ str << args[i];
+ if (i != args.size() - 1) {
+ str << ", ";
+ }
+ }
+ str << " out of range (0, 0)";
+ this->SetError(str.str());
return false;
}
@@ -423,9 +1381,9 @@ bool cmListCommand::HandleRemoveAtCommand(std::vector<std::string> const& args)
for (cc = 2; cc < args.size(); ++cc) {
int item = atoi(args[cc].c_str());
if (item < 0) {
- item = (int)nitem + item;
+ item = static_cast<int>(nitem) + item;
}
- if (item < 0 || nitem <= (size_t)item) {
+ if (item < 0 || nitem <= static_cast<size_t>(item)) {
std::ostringstream str;
str << "index: " << item << " out of range (-" << nitem << ", "
<< nitem - 1 << ")";
@@ -466,14 +1424,6 @@ bool cmListCommand::HandleFilterCommand(std::vector<std::string> const& args)
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 FILTER requires list to be present.");
- return false;
- }
-
const std::string& op = args[2];
bool includeMatches;
if (op == "INCLUDE") {
@@ -485,6 +1435,13 @@ bool cmListCommand::HandleFilterCommand(std::vector<std::string> const& args)
return false;
}
+ const std::string& listName = args[1];
+ // expand the variable
+ std::vector<std::string> varArgsExpanded;
+ if (!this->GetList(varArgsExpanded, listName)) {
+ return true;
+ }
+
const std::string& mode = args[3];
if (mode == "REGEX") {
if (args.size() != 5) {
diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h
index 7789f7df1..ea3d64399 100644
--- a/Source/cmListCommand.h
+++ b/Source/cmListCommand.h
@@ -3,7 +3,7 @@
#ifndef cmListCommand_h
#define cmListCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -22,25 +22,31 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmListCommand; }
+ cmCommand* Clone() override { return new cmListCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
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 HandlePrependCommand(std::vector<std::string> const& args);
+ bool HandlePopBackCommand(std::vector<std::string> const& args);
+ bool HandlePopFrontCommand(std::vector<std::string> const& args);
bool HandleFindCommand(std::vector<std::string> const& args);
bool HandleInsertCommand(std::vector<std::string> const& args);
+ bool HandleJoinCommand(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 HandleTransformCommand(std::vector<std::string> const& args);
bool HandleSortCommand(std::vector<std::string> const& args);
+ bool HandleSublistCommand(std::vector<std::string> const& args);
bool HandleReverseCommand(std::vector<std::string> const& args);
bool HandleFilterCommand(std::vector<std::string> const& args);
bool FilterRegex(std::vector<std::string> const& args, bool includeMatches,
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index 0c73cd725..df0d00c59 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -3,22 +3,32 @@
#include "cmListFileCache.h"
#include "cmListFileLexer.h"
+#include "cmMessageType.h"
#include "cmMessenger.h"
-#include "cmOutputConverter.h"
#include "cmState.h"
+#include "cmStateDirectory.h"
#include "cmSystemTools.h"
-#include "cmake.h"
-#include "cmConfigure.h"
-#include <algorithm>
#include <assert.h>
+#include <memory>
#include <sstream>
+#include <utility>
+
+cmCommandContext::cmCommandName& cmCommandContext::cmCommandName::operator=(
+ std::string const& name)
+{
+ this->Original = name;
+ this->Lower = cmSystemTools::LowerCase(name);
+ return *this;
+}
struct cmListFileParser
{
- cmListFileParser(cmListFile* lf, cmListFileBacktrace const& lfbt,
+ cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
cmMessenger* messenger, const char* filename);
~cmListFileParser();
+ cmListFileParser(const cmListFileParser&) = delete;
+ cmListFileParser& operator=(const cmListFileParser&) = delete;
void IssueFileOpenError(std::string const& text) const;
void IssueError(std::string const& text) const;
bool ParseFile();
@@ -39,12 +49,11 @@ struct cmListFileParser
} Separation;
};
-cmListFileParser::cmListFileParser(cmListFile* lf,
- cmListFileBacktrace const& lfbt,
+cmListFileParser::cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
cmMessenger* messenger,
const char* filename)
: ListFile(lf)
- , Backtrace(lfbt)
+ , Backtrace(std::move(lfbt))
, Messenger(messenger)
, FileName(filename)
, Lexer(cmListFileLexer_New())
@@ -58,7 +67,8 @@ cmListFileParser::~cmListFileParser()
void cmListFileParser::IssueFileOpenError(const std::string& text) const
{
- this->Messenger->IssueMessage(cmake::FATAL_ERROR, text, this->Backtrace);
+ this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text,
+ this->Backtrace);
}
void cmListFileParser::IssueError(const std::string& text) const
@@ -68,7 +78,7 @@ void cmListFileParser::IssueError(const std::string& text) const
lfc.Line = cmListFileLexer_GetCurrentLine(this->Lexer);
cmListFileBacktrace lfbt = this->Backtrace;
lfbt = lfbt.Push(lfc);
- this->Messenger->IssueMessage(cmake::FATAL_ERROR, text, lfbt);
+ this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text, lfbt);
cmSystemTools::SetFatalErrorOccured();
}
@@ -82,7 +92,7 @@ bool cmListFileParser::ParseFile()
}
if (bom == cmListFileLexer_BOM_Broken) {
- cmListFileLexer_SetFileName(this->Lexer, CM_NULLPTR, CM_NULLPTR);
+ cmListFileLexer_SetFileName(this->Lexer, nullptr, nullptr);
this->IssueFileOpenError("Error while reading Byte-Order-Mark. "
"File not seekable?");
return false;
@@ -90,7 +100,7 @@ bool cmListFileParser::ParseFile()
// Verify the Byte-Order-Mark, if any.
if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) {
- cmListFileLexer_SetFileName(this->Lexer, CM_NULLPTR, CM_NULLPTR);
+ cmListFileLexer_SetFileName(this->Lexer, nullptr, nullptr);
this->IssueFileOpenError(
"File starts with a Byte-Order-Mark that is not UTF-8.");
return false;
@@ -182,11 +192,9 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
}
// Arguments.
- unsigned long lastLine;
unsigned long parenDepth = 0;
this->Separation = SeparationOkay;
- while ((lastLine = cmListFileLexer_GetCurrentLine(this->Lexer),
- token = cmListFileLexer_Scan(this->Lexer))) {
+ while ((token = cmListFileLexer_Scan(this->Lexer))) {
if (token->type == cmListFileLexer_Token_Space ||
token->type == cmListFileLexer_Token_Newline) {
this->Separation = SeparationOkay;
@@ -241,20 +249,19 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
std::ostringstream error;
cmListFileContext lfc;
lfc.FilePath = this->FileName;
- lfc.Line = lastLine;
+ lfc.Line = line;
cmListFileBacktrace lfbt = this->Backtrace;
lfbt = lfbt.Push(lfc);
error << "Parse error. Function missing ending \")\". "
<< "End of file reached.";
- this->Messenger->IssueMessage(cmake::FATAL_ERROR, error.str(), lfbt);
+ this->Messenger->IssueMessage(MessageType::FATAL_ERROR, error.str(), lfbt);
return false;
}
bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
cmListFileArgument::Delimiter delim)
{
- cmListFileArgument a(token->text, delim, token->line);
- this->Function.Arguments.push_back(a);
+ this->Function.Arguments.emplace_back(token->text, delim, token->line);
if (this->Separation == SeparationOkay) {
return true;
}
@@ -272,98 +279,73 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
<< "Argument not separated from preceding token by whitespace.";
/* clang-format on */
if (isError) {
- this->Messenger->IssueMessage(cmake::FATAL_ERROR, m.str(), lfbt);
+ this->Messenger->IssueMessage(MessageType::FATAL_ERROR, m.str(), lfbt);
return false;
}
- this->Messenger->IssueMessage(cmake::AUTHOR_WARNING, m.str(), lfbt);
+ this->Messenger->IssueMessage(MessageType::AUTHOR_WARNING, m.str(), lfbt);
return true;
}
-struct cmListFileBacktrace::Entry : public cmListFileContext
+// We hold either the bottom scope of a directory or a call/file context.
+// Discriminate these cases via the parent pointer.
+struct cmListFileBacktrace::Entry
{
- Entry(cmListFileContext const& lfc, Entry* up)
- : cmListFileContext(lfc)
- , Up(up)
- , RefCount(0)
+ Entry(cmStateSnapshot bottom)
+ : Bottom(bottom)
{
- if (this->Up) {
- this->Up->Ref();
- }
}
- ~Entry()
+
+ Entry(std::shared_ptr<Entry const> parent, cmListFileContext lfc)
+ : Context(std::move(lfc))
+ , Parent(std::move(parent))
{
- if (this->Up) {
- this->Up->Unref();
- }
}
- void Ref() { ++this->RefCount; }
- void Unref()
+
+ ~Entry()
{
- if (--this->RefCount == 0) {
- delete this;
+ if (this->Parent) {
+ this->Context.~cmListFileContext();
+ } else {
+ this->Bottom.~cmStateSnapshot();
}
}
- Entry* Up;
- unsigned int RefCount;
-};
-cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& bottom,
- Entry* up,
- cmListFileContext const& lfc)
- : Bottom(bottom)
- , Cur(new Entry(lfc, up))
-{
- assert(this->Bottom.IsValid());
- this->Cur->Ref();
-}
+ bool IsBottom() const { return !this->Parent; }
-cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& bottom,
- Entry* cur)
- : Bottom(bottom)
- , Cur(cur)
-{
- if (this->Cur) {
- assert(this->Bottom.IsValid());
- this->Cur->Ref();
- }
-}
-
-cmListFileBacktrace::cmListFileBacktrace()
- : Bottom()
- , Cur(CM_NULLPTR)
-{
-}
+ union
+ {
+ cmStateSnapshot Bottom;
+ cmListFileContext Context;
+ };
+ std::shared_ptr<Entry const> Parent;
+};
cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& snapshot)
- : Bottom(snapshot.GetCallStackBottom())
- , Cur(CM_NULLPTR)
+ : TopEntry(std::make_shared<Entry const>(snapshot.GetCallStackBottom()))
{
}
-cmListFileBacktrace::cmListFileBacktrace(cmListFileBacktrace const& r)
- : Bottom(r.Bottom)
- , Cur(r.Cur)
+cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> parent,
+ cmListFileContext const& lfc)
+ : TopEntry(std::make_shared<Entry const>(std::move(parent), lfc))
{
- if (this->Cur) {
- assert(this->Bottom.IsValid());
- this->Cur->Ref();
- }
}
-cmListFileBacktrace& cmListFileBacktrace::operator=(
- cmListFileBacktrace const& r)
+cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> top)
+ : TopEntry(std::move(top))
{
- cmListFileBacktrace tmp(r);
- std::swap(this->Cur, tmp.Cur);
- std::swap(this->Bottom, tmp.Bottom);
- return *this;
}
-cmListFileBacktrace::~cmListFileBacktrace()
+cmStateSnapshot cmListFileBacktrace::GetBottom() const
{
- if (this->Cur) {
- this->Cur->Unref();
+ cmStateSnapshot bottom;
+ if (Entry const* cur = this->TopEntry.get()) {
+ while (Entry const* parent = cur->Parent.get()) {
+ cur = parent;
+ }
+ bottom = cur->Bottom;
}
+ return bottom;
}
cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const
@@ -374,54 +356,60 @@ cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const
// skipped during call stack printing.
cmListFileContext lfc;
lfc.FilePath = file;
- return cmListFileBacktrace(this->Bottom, this->Cur, lfc);
+ return this->Push(lfc);
}
cmListFileBacktrace cmListFileBacktrace::Push(
cmListFileContext const& lfc) const
{
- return cmListFileBacktrace(this->Bottom, this->Cur, lfc);
+ assert(this->TopEntry);
+ assert(!this->TopEntry->IsBottom() || this->TopEntry->Bottom.IsValid());
+ return cmListFileBacktrace(this->TopEntry, lfc);
}
cmListFileBacktrace cmListFileBacktrace::Pop() const
{
- assert(this->Cur);
- return cmListFileBacktrace(this->Bottom, this->Cur->Up);
+ assert(this->TopEntry);
+ assert(!this->TopEntry->IsBottom());
+ return cmListFileBacktrace(this->TopEntry->Parent);
}
cmListFileContext const& cmListFileBacktrace::Top() const
{
- if (this->Cur) {
- return *this->Cur;
- }
- static cmListFileContext const empty;
- return empty;
+ assert(this->TopEntry);
+ assert(!this->TopEntry->IsBottom());
+ return this->TopEntry->Context;
}
void cmListFileBacktrace::PrintTitle(std::ostream& out) const
{
- if (!this->Cur) {
+ // The title exists only if we have a call on top of the bottom.
+ if (!this->TopEntry || this->TopEntry->IsBottom()) {
return;
}
- cmOutputConverter converter(this->Bottom);
- cmListFileContext lfc = *this->Cur;
- if (!this->Bottom.GetState()->GetIsInTryCompile()) {
- lfc.FilePath = converter.ConvertToRelativePath(
- this->Bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
+ cmListFileContext lfc = this->TopEntry->Context;
+ cmStateSnapshot bottom = this->GetBottom();
+ if (!bottom.GetState()->GetIsInTryCompile()) {
+ lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained(
+ bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
}
out << (lfc.Line ? " at " : " in ") << lfc;
}
void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
{
- if (!this->Cur || !this->Cur->Up) {
+ // The call stack exists only if we have at least two calls on top
+ // of the bottom.
+ if (!this->TopEntry || this->TopEntry->IsBottom() ||
+ this->TopEntry->Parent->IsBottom()) {
return;
}
bool first = true;
- cmOutputConverter converter(this->Bottom);
- for (Entry* i = this->Cur->Up; i; i = i->Up) {
- if (i->Name.empty()) {
+ cmStateSnapshot bottom = this->GetBottom();
+ for (Entry const* cur = this->TopEntry->Parent.get(); !cur->IsBottom();
+ cur = cur->Parent.get()) {
+ if (cur->Context.Name.empty()) {
// Skip this whole-file scope. When we get here we already will
// have printed a more-specific context within the file.
continue;
@@ -430,15 +418,31 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
first = false;
out << "Call Stack (most recent call first):\n";
}
- cmListFileContext lfc = *i;
- if (!this->Bottom.GetState()->GetIsInTryCompile()) {
- lfc.FilePath = converter.ConvertToRelativePath(
- this->Bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
+ cmListFileContext lfc = cur->Context;
+ if (!bottom.GetState()->GetIsInTryCompile()) {
+ lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained(
+ bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
}
out << " " << lfc << "\n";
}
}
+size_t cmListFileBacktrace::Depth() const
+{
+ size_t depth = 0;
+ if (Entry const* cur = this->TopEntry.get()) {
+ for (; !cur->IsBottom(); cur = cur->Parent.get()) {
+ ++depth;
+ }
+ }
+ return depth;
+}
+
+bool cmListFileBacktrace::Empty() const
+{
+ return !this->TopEntry || this->TopEntry->IsBottom();
+}
+
std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
{
os << lfc.FilePath;
@@ -468,3 +472,21 @@ bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs)
{
return !(lhs == rhs);
}
+
+std::ostream& operator<<(std::ostream& os, BT<std::string> const& s)
+{
+ return os << s.Value;
+}
+
+std::vector<BT<std::string>> ExpandListWithBacktrace(
+ std::string const& list, cmListFileBacktrace const& bt)
+{
+ std::vector<BT<std::string>> result;
+ std::vector<std::string> tmp;
+ cmSystemTools::ExpandListArgument(list, tmp);
+ result.reserve(tmp.size());
+ for (std::string& i : tmp) {
+ result.emplace_back(std::move(i), bt);
+ }
+ return result;
+}
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
index 349ddef91..945741540 100644
--- a/Source/cmListFileCache.h
+++ b/Source/cmListFileCache.h
@@ -6,7 +6,10 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
+#include <memory> // IWYU pragma: keep
+#include <stddef.h>
#include <string>
+#include <utility>
#include <vector>
#include "cmStateSnapshot.h"
@@ -22,11 +25,19 @@ class cmMessenger;
struct cmCommandContext
{
- std::string Name;
- long Line;
- cmCommandContext()
- : Name()
- , Line(0)
+ struct cmCommandName
+ {
+ std::string Lower;
+ std::string Original;
+ cmCommandName() = default;
+ cmCommandName(std::string const& name) { *this = name; }
+ cmCommandName& operator=(std::string const& name);
+ } Name;
+ long Line = 0;
+ cmCommandContext() = default;
+ cmCommandContext(const char* name, int line)
+ : Name(name)
+ , Line(line)
{
}
};
@@ -39,14 +50,9 @@ struct cmListFileArgument
Quoted,
Bracket
};
- cmListFileArgument()
- : Value()
- , Delim(Unquoted)
- , Line(0)
- {
- }
- cmListFileArgument(const std::string& v, Delimiter d, long line)
- : Value(v)
+ cmListFileArgument() = default;
+ cmListFileArgument(std::string v, Delimiter d, long line)
+ : Value(std::move(v))
, Delim(d)
, Line(line)
{
@@ -57,8 +63,8 @@ struct cmListFileArgument
}
bool operator!=(const cmListFileArgument& r) const { return !(*this == r); }
std::string Value;
- Delimiter Delim;
- long Line;
+ Delimiter Delim = Unquoted;
+ long Line = 0;
};
class cmListFileContext
@@ -66,13 +72,7 @@ class cmListFileContext
public:
std::string Name;
std::string FilePath;
- long Line;
- cmListFileContext()
- : Name()
- , FilePath()
- , Line(0)
- {
- }
+ long Line = 0;
static cmListFileContext FromCommandContext(cmCommandContext const& lfcc,
std::string const& fileName)
@@ -80,7 +80,7 @@ public:
cmListFileContext lfc;
lfc.FilePath = fileName;
lfc.Line = lfcc.Line;
- lfc.Name = lfcc.Name;
+ lfc.Name = lfcc.Name.Original;
return lfc;
}
};
@@ -103,18 +103,13 @@ public:
// Default-constructed backtrace may not be used until after
// set via assignment from a backtrace constructed with a
// valid snapshot.
- cmListFileBacktrace();
+ cmListFileBacktrace() = default;
// Construct an empty backtrace whose bottom sits in the directory
// indicated by the given valid snapshot.
cmListFileBacktrace(cmStateSnapshot const& snapshot);
- // Backtraces may be copied and assigned as values.
- cmListFileBacktrace(cmListFileBacktrace const& r);
- cmListFileBacktrace& operator=(cmListFileBacktrace const& r);
- ~cmListFileBacktrace();
-
- cmStateSnapshot GetBottom() const { return this->Bottom; }
+ cmStateSnapshot GetBottom() const;
// Get a backtrace with the given file scope added to the top.
// May not be called until after construction with a valid snapshot.
@@ -129,7 +124,7 @@ public:
cmListFileBacktrace Pop() const;
// Get the context at the top of the backtrace.
- // Returns an empty context if the backtrace is empty.
+ // This may be called only if Empty() would return false.
cmListFileContext const& Top() const;
// Print the top of the backtrace.
@@ -138,16 +133,52 @@ public:
// Print the call stack below the top of the backtrace.
void PrintCallStack(std::ostream& out) const;
+ // Get the number of 'frames' in this backtrace
+ size_t Depth() const;
+
+ // Return true if this backtrace is empty.
+ bool Empty() const;
+
private:
struct Entry;
-
- cmStateSnapshot Bottom;
- Entry* Cur;
- cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* up,
+ std::shared_ptr<Entry const> TopEntry;
+ cmListFileBacktrace(std::shared_ptr<Entry const> parent,
cmListFileContext const& lfc);
- cmListFileBacktrace(cmStateSnapshot const& bottom, Entry* cur);
+ cmListFileBacktrace(std::shared_ptr<Entry const> top);
};
+// Wrap type T as a value with a backtrace. For purposes of
+// ordering and equality comparison, only the original value is
+// used. The backtrace is considered incidental.
+template <typename T>
+class BT
+{
+public:
+ BT(T v = T(), cmListFileBacktrace bt = cmListFileBacktrace())
+ : Value(std::move(v))
+ , Backtrace(std::move(bt))
+ {
+ }
+ T Value;
+ cmListFileBacktrace Backtrace;
+ friend bool operator==(BT<T> const& l, BT<T> const& r)
+ {
+ return l.Value == r.Value;
+ }
+ friend bool operator<(BT<T> const& l, BT<T> const& r)
+ {
+ return l.Value < r.Value;
+ }
+ friend bool operator==(BT<T> const& l, T const& r) { return l.Value == r; }
+ friend bool operator==(T const& l, BT<T> const& r) { return l == r.Value; }
+};
+
+std::ostream& operator<<(std::ostream& os, BT<std::string> const& s);
+
+std::vector<BT<std::string>> ExpandListWithBacktrace(
+ std::string const& list,
+ cmListFileBacktrace const& bt = cmListFileBacktrace());
+
struct cmListFile
{
bool ParseFile(const char* path, cmMessenger* messenger,
diff --git a/Source/cmListFileLexer.h b/Source/cmListFileLexer.h
index f243010ad..8962396fd 100644
--- a/Source/cmListFileLexer.h
+++ b/Source/cmListFileLexer.h
@@ -3,7 +3,8 @@
#ifndef cmListFileLexer_h
#define cmListFileLexer_h
-typedef enum cmListFileLexer_Type_e {
+typedef enum cmListFileLexer_Type_e
+{
cmListFileLexer_Token_None,
cmListFileLexer_Token_Space,
cmListFileLexer_Token_Newline,
diff --git a/Source/cmLoadCacheCommand.cxx b/Source/cmLoadCacheCommand.cxx
index 00a30bf0e..b1fee8dc6 100644
--- a/Source/cmLoadCacheCommand.cxx
+++ b/Source/cmLoadCacheCommand.cxx
@@ -27,17 +27,16 @@ bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args,
// 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++) {
+ for (std::string const& arg : args) {
if (excludeFiles) {
- excludes.insert(args[i]);
+ excludes.insert(arg);
}
- if (args[i] == "EXCLUDE") {
+ if (arg == "EXCLUDE") {
excludeFiles = true;
}
- if (excludeFiles && (args[i] == "INCLUDE_INTERNALS")) {
+ if (excludeFiles && (arg == "INCLUDE_INTERNALS")) {
break;
}
}
@@ -48,25 +47,25 @@ bool cmLoadCacheCommand::InitialPass(std::vector<std::string> const& args,
bool includeFiles = false;
std::set<std::string> includes;
- for (i = 0; i < args.size(); i++) {
+ for (std::string const& arg : args) {
if (includeFiles) {
- includes.insert(args[i]);
+ includes.insert(arg);
}
- if (args[i] == "INCLUDE_INTERNALS") {
+ if (arg == "INCLUDE_INTERNALS") {
includeFiles = true;
}
- if (includeFiles && (args[i] == "EXCLUDE")) {
+ if (includeFiles && (arg == "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")) {
+ for (std::string const& arg : args) {
+ if ((arg == "EXCLUDE") || (arg == "INCLUDE_INTERNALS")) {
break;
}
- this->Makefile->GetCMakeInstance()->LoadCache(args[i], false, excludes,
+ this->Makefile->GetCMakeInstance()->LoadCache(arg, false, excludes,
includes);
}
@@ -83,7 +82,7 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
// Make sure the cache file exists.
std::string cacheFile = args[0] + "/CMakeCache.txt";
- if (!cmSystemTools::FileExists(cacheFile.c_str())) {
+ if (!cmSystemTools::FileExists(cacheFile)) {
std::string e = "Cannot load cache file from " + cacheFile;
this->SetError(e);
return false;
@@ -125,7 +124,7 @@ bool cmLoadCacheCommand::ReadWithPrefix(std::vector<std::string> const& args)
if (i != end) {
// Completed a line.
this->CheckLine(line.c_str());
- line = "";
+ line.clear();
// Skip the newline character.
++i;
diff --git a/Source/cmLoadCacheCommand.h b/Source/cmLoadCacheCommand.h
index 1a8a0fc4c..e0f6e4f48 100644
--- a/Source/cmLoadCacheCommand.h
+++ b/Source/cmLoadCacheCommand.h
@@ -3,7 +3,7 @@
#ifndef cmLoadCacheCommand_h
#define cmLoadCacheCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <string>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmLoadCacheCommand; }
+ cmCommand* Clone() override { return new cmLoadCacheCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
std::set<std::string> VariablesToRead;
diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx
index 92a32a147..69751b62b 100644
--- a/Source/cmLoadCommandCommand.cxx
+++ b/Source/cmLoadCommandCommand.cxx
@@ -18,7 +18,7 @@
class cmExecutionStatus;
#ifdef __QNX__
-#include <malloc.h> /* for malloc/free on QNX */
+# include <malloc.h> /* for malloc/free on QNX */
#endif
extern "C" void TrapsForSignalsCFunction(int sig);
@@ -33,13 +33,13 @@ public:
this->info.CAPI = &cmStaticCAPI;
}
- ///! clean up any memory allocated by the plugin
- ~cmLoadedCommand() CM_OVERRIDE;
+ //! clean up any memory allocated by the plugin
+ ~cmLoadedCommand() override;
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmLoadedCommand* newC = new cmLoadedCommand;
// we must copy when we clone
@@ -52,7 +52,7 @@ public:
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus&) CM_OVERRIDE;
+ cmExecutionStatus&) override;
/**
* This is called at the end after all the information
@@ -60,10 +60,10 @@ public:
* not implement this method. At this point, reading and
* writing to the cache can be done.
*/
- void FinalPass() CM_OVERRIDE;
- bool HasFinalPass() const CM_OVERRIDE
+ void FinalPass() override;
+ bool HasFinalPass() const override
{
- return this->info.FinalPass != CM_NULLPTR;
+ return this->info.FinalPass != nullptr;
}
static const char* LastName;
@@ -86,11 +86,11 @@ public:
#endif
signal(SIGILL, TrapsForSignalsCFunction);
} else {
- signal(SIGSEGV, CM_NULLPTR);
+ signal(SIGSEGV, nullptr);
#ifdef SIGBUS
- signal(SIGBUS, CM_NULLPTR);
+ signal(SIGBUS, nullptr);
#endif
- signal(SIGILL, CM_NULLPTR);
+ signal(SIGILL, nullptr);
}
}
@@ -102,7 +102,7 @@ extern "C" void TrapsForSignalsCFunction(int sig)
cmLoadedCommand::TrapsForSignals(sig);
}
-const char* cmLoadedCommand::LastName = CM_NULLPTR;
+const char* cmLoadedCommand::LastName = nullptr;
bool cmLoadedCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
@@ -118,17 +118,16 @@ bool cmLoadedCommand::InitialPass(std::vector<std::string> const& args,
// create argc and argv and then invoke the command
int argc = static_cast<int>(args.size());
- char** argv = CM_NULLPTR;
+ char** argv = nullptr;
if (argc) {
- argv = (char**)malloc(argc * sizeof(char*));
+ argv = static_cast<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);
+ int result = info.InitialPass(&info, this->Makefile, argc, argv);
cmLoadedCommand::InstallSignalHandlers(info.Name, 1);
cmFreeArguments(argc, argv);
@@ -147,7 +146,7 @@ void cmLoadedCommand::FinalPass()
{
if (this->info.FinalPass) {
cmLoadedCommand::InstallSignalHandlers(info.Name);
- this->info.FinalPass((void*)&this->info, (void*)this->Makefile);
+ this->info.FinalPass(&this->info, this->Makefile);
cmLoadedCommand::InstallSignalHandlers(info.Name, 1);
}
}
@@ -156,7 +155,7 @@ cmLoadedCommand::~cmLoadedCommand()
{
if (this->info.Destructor) {
cmLoadedCommand::InstallSignalHandlers(info.Name);
- this->info.Destructor((void*)&this->info);
+ this->info.Destructor(&this->info);
cmLoadedCommand::InstallSignalHandlers(info.Name, 1);
}
if (this->info.Error) {
@@ -198,7 +197,7 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args,
// Try to find the program.
std::string fullPath = cmSystemTools::FindFile(moduleName, path);
- if (fullPath == "") {
+ if (fullPath.empty()) {
std::ostringstream e;
e << "Attempt to load command failed from file \"" << moduleName << "\"";
this->SetError(e.str());
@@ -225,14 +224,13 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> const& args,
// find the init function
std::string initFuncName = args[0] + "Init";
- CM_INIT_FUNCTION initFunction =
- (CM_INIT_FUNCTION)cmsys::DynamicLoader::GetSymbolAddress(lib,
- initFuncName);
+ CM_INIT_FUNCTION initFunction = reinterpret_cast<CM_INIT_FUNCTION>(
+ cmsys::DynamicLoader::GetSymbolAddress(lib, initFuncName));
if (!initFunction) {
initFuncName = "_";
initFuncName += args[0];
initFuncName += "Init";
- initFunction = (CM_INIT_FUNCTION)(
+ initFunction = reinterpret_cast<CM_INIT_FUNCTION>(
cmsys::DynamicLoader::GetSymbolAddress(lib, initFuncName));
}
// if the symbol is found call it to set the name on the
diff --git a/Source/cmLoadCommandCommand.h b/Source/cmLoadCommandCommand.h
index 030786e3d..021e6c7bb 100644
--- a/Source/cmLoadCommandCommand.h
+++ b/Source/cmLoadCommandCommand.h
@@ -3,7 +3,7 @@
#ifndef cmLoadCommandCommand_h
#define cmLoadCommandCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,9 +15,9 @@ class cmExecutionStatus;
class cmLoadCommandCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmLoadCommandCommand; }
+ cmCommand* Clone() override { return new cmLoadCommandCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmLocalCommonGenerator.cxx b/Source/cmLocalCommonGenerator.cxx
index 6524db401..75ad2a658 100644
--- a/Source/cmLocalCommonGenerator.cxx
+++ b/Source/cmLocalCommonGenerator.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLocalCommonGenerator.h"
+#include <utility>
#include <vector>
#include "cmGeneratorTarget.h"
@@ -11,10 +12,9 @@
class cmGlobalGenerator;
cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg,
- cmMakefile* mf,
- std::string const& wd)
+ cmMakefile* mf, std::string wd)
: cmLocalGenerator(gg, mf)
- , WorkingDirectory(wd)
+ , WorkingDirectory(std::move(wd))
{
// Store the configuration name that will be generated.
if (const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) {
@@ -22,13 +22,11 @@ cmLocalCommonGenerator::cmLocalCommonGenerator(cmGlobalGenerator* gg,
this->ConfigName = config;
} else {
// No configuration type given.
- this->ConfigName = "";
+ this->ConfigName.clear();
}
}
-cmLocalCommonGenerator::~cmLocalCommonGenerator()
-{
-}
+cmLocalCommonGenerator::~cmLocalCommonGenerator() = default;
std::string cmLocalCommonGenerator::GetTargetFortranFlags(
cmGeneratorTarget const* target, std::string const& config)
@@ -46,16 +44,15 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags(
target->GetFortranModuleDirectory(this->WorkingDirectory);
if (!mod_dir.empty()) {
mod_dir = this->ConvertToOutputFormat(
- this->ConvertToRelativePath(this->WorkingDirectory, mod_dir),
+ this->MaybeConvertToRelativePath(this->WorkingDirectory, mod_dir),
cmOutputConverter::SHELL);
} else {
mod_dir =
this->Makefile->GetSafeDefinition("CMAKE_Fortran_MODDIR_DEFAULT");
}
if (!mod_dir.empty()) {
- const char* moddir_flag =
+ std::string modflag =
this->Makefile->GetRequiredDefinition("CMAKE_Fortran_MODDIR_FLAG");
- std::string modflag = moddir_flag;
modflag += mod_dir;
this->AppendFlags(flags, modflag);
}
@@ -67,13 +64,26 @@ std::string cmLocalCommonGenerator::GetTargetFortranFlags(
this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) {
std::vector<std::string> includes;
this->GetIncludeDirectories(includes, target, "C", config);
- for (std::vector<std::string>::const_iterator idi = includes.begin();
- idi != includes.end(); ++idi) {
+ for (std::string const& id : includes) {
std::string flg = modpath_flag;
- flg += this->ConvertToOutputFormat(*idi, cmOutputConverter::SHELL);
+ flg += this->ConvertToOutputFormat(id, cmOutputConverter::SHELL);
this->AppendFlags(flags, flg);
}
}
return flags;
}
+
+void cmLocalCommonGenerator::ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt)
+{
+ // Determine if these object files should use a custom extension
+ char const* custom_ext = gt->GetCustomObjectExtension();
+ for (auto& si : mapping) {
+ cmSourceFile const* sf = si.first;
+ bool keptSourceExtension;
+ si.second = this->GetObjectFileNameWithoutTarget(
+ *sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
+ }
+}
diff --git a/Source/cmLocalCommonGenerator.h b/Source/cmLocalCommonGenerator.h
index a5afcd87d..abebbc2a7 100644
--- a/Source/cmLocalCommonGenerator.h
+++ b/Source/cmLocalCommonGenerator.h
@@ -3,8 +3,9 @@
#ifndef cmLocalCommonGenerator_h
#define cmLocalCommonGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include <map>
#include <string>
#include "cmLocalGenerator.h"
@@ -12,6 +13,7 @@
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
+class cmSourceFile;
/** \class cmLocalCommonGenerator
* \brief Common infrastructure for Makefile and Ninja local generators.
@@ -20,15 +22,19 @@ class cmLocalCommonGenerator : public cmLocalGenerator
{
public:
cmLocalCommonGenerator(cmGlobalGenerator* gg, cmMakefile* mf,
- std::string const& wd);
- ~cmLocalCommonGenerator() CM_OVERRIDE;
+ std::string wd);
+ ~cmLocalCommonGenerator() override;
std::string const& GetConfigName() { return this->ConfigName; }
std::string GetWorkingDirectory() const { return this->WorkingDirectory; }
std::string GetTargetFortranFlags(cmGeneratorTarget const* target,
- std::string const& config) CM_OVERRIDE;
+ std::string const& config) override;
+
+ void ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt = nullptr) override;
protected:
std::string WorkingDirectory;
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 6ce31c5ea..3abf2ddda 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -6,6 +6,7 @@
#include "cmComputeLinkInformation.h"
#include "cmCustomCommandGenerator.h"
#include "cmGeneratedFileStream.h"
+#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionEvaluationFile.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
@@ -16,6 +17,7 @@
#include "cmMakefile.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
+#include "cmSourceFileLocation.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateTypes.h"
@@ -26,22 +28,24 @@
#include "cmake.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#define CM_LG_ENCODE_OBJECT_NAMES
-#include "cmCryptoHash.h"
+# define CM_LG_ENCODE_OBJECT_NAMES
+# include "cmCryptoHash.h"
#endif
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <assert.h>
+#include <initializer_list>
#include <iterator>
#include <sstream>
#include <stdio.h>
#include <string.h>
+#include <unordered_set>
#include <utility>
#if defined(__HAIKU__)
-#include <FindDirectory.h>
-#include <StorageDefs.h>
+# include <FindDirectory.h>
+# include <StorageDefs.h>
#endif
// List of variables that are replaced when
@@ -49,24 +53,23 @@
// 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_CUDA_HOST_COMPILER",
- "CMAKE_CUDA_HOST_LINK_LAUNCHER",
- "CMAKE_CL_SHOWINCLUDES_PREFIX"
-};
+static auto 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_MT",
+ "CMAKE_CUDA_HOST_COMPILER",
+ "CMAKE_CUDA_HOST_LINK_LAUNCHER",
+ "CMAKE_CL_SHOWINCLUDES_PREFIX" };
cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
: cmOutputConverter(makefile->GetStateSnapshot())
@@ -85,6 +88,19 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
this->ComputeObjectMaxPath();
+ // Canonicalize entries of the CPATH environment variable the same
+ // way detection of CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES does.
+ {
+ std::vector<std::string> cpath;
+ cmSystemTools::GetPath(cpath, "CPATH");
+ for (std::string& cp : cpath) {
+ if (cmSystemTools::FileIsFullPath(cp)) {
+ cp = cmSystemTools::CollapseFullPath(cp);
+ this->EnvCPATH.emplace(std::move(cp));
+ }
+ }
+ }
+
std::vector<std::string> enabledLanguages =
this->GetState()->GetEnabledLanguages();
@@ -102,9 +118,7 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
this->LinkerSysroot = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
}
- for (std::vector<std::string>::iterator i = enabledLanguages.begin();
- i != enabledLanguages.end(); ++i) {
- std::string const& lang = *i;
+ for (std::string const& lang : enabledLanguages) {
if (lang == "NONE") {
continue;
}
@@ -137,15 +151,13 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
this->VariableMappings[compilerOptionSysroot] =
this->Makefile->GetSafeDefinition(compilerOptionSysroot);
- for (const char* const* replaceIter = cmArrayBegin(ruleReplaceVars);
- replaceIter != cmArrayEnd(ruleReplaceVars); ++replaceIter) {
- std::string actualReplace = *replaceIter;
- if (actualReplace.find("${LANG}") != std::string::npos) {
- cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
+ for (std::string replaceVar : ruleReplaceVars) {
+ if (replaceVar.find("${LANG}") != std::string::npos) {
+ cmSystemTools::ReplaceString(replaceVar, "${LANG}", lang);
}
- this->VariableMappings[actualReplace] =
- this->Makefile->GetSafeDefinition(actualReplace);
+ this->VariableMappings[replaceVar] =
+ this->Makefile->GetSafeDefinition(replaceVar);
}
}
}
@@ -164,7 +176,7 @@ cmLocalGenerator::~cmLocalGenerator()
cmDeleteAll(this->OwnedImportedGeneratorTargets);
}
-void cmLocalGenerator::IssueMessage(cmake::MessageType t,
+void cmLocalGenerator::IssueMessage(MessageType t,
std::string const& text) const
{
this->GetCMakeInstance()->IssueMessage(t, text, this->DirectoryBacktrace);
@@ -189,38 +201,71 @@ void cmLocalGenerator::ComputeObjectMaxPath()
w << "CMAKE_OBJECT_PATH_MAX is set to " << pmax
<< ", which is less than the minimum of 128. "
<< "The value will be ignored.";
- this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
} else {
std::ostringstream w;
w << "CMAKE_OBJECT_PATH_MAX is set to \"" << plen
<< "\", which fails to parse as a positive integer. "
<< "The value will be ignored.";
- this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
}
this->ObjectMaxPathViolations.clear();
}
+static void MoveSystemIncludesToEnd(std::vector<std::string>& includeDirs,
+ const std::string& config,
+ const std::string& lang,
+ const cmGeneratorTarget* target)
+{
+ if (!target) {
+ return;
+ }
+
+ std::stable_sort(
+ includeDirs.begin(), includeDirs.end(),
+ [&target, &config, &lang](std::string const& a, std::string const& b) {
+ return !target->IsSystemIncludeDirectory(a, config, lang) &&
+ target->IsSystemIncludeDirectory(b, config, lang);
+ });
+}
+
+static void MoveSystemIncludesToEnd(std::vector<BT<std::string>>& includeDirs,
+ const std::string& config,
+ const std::string& lang,
+ const cmGeneratorTarget* target)
+{
+ if (!target) {
+ return;
+ }
+
+ std::stable_sort(includeDirs.begin(), includeDirs.end(),
+ [target, &config, &lang](BT<std::string> const& a,
+ BT<std::string> const& b) {
+ return !target->IsSystemIncludeDirectory(a.Value, config,
+ lang) &&
+ target->IsSystemIncludeDirectory(b.Value, config, lang);
+ });
+}
+
void cmLocalGenerator::TraceDependencies()
{
std::vector<std::string> configs;
this->Makefile->GetConfigurations(configs);
if (configs.empty()) {
- configs.push_back("");
+ configs.emplace_back();
}
- for (std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci) {
- this->GlobalGenerator->CreateEvaluationSourceFiles(*ci);
+ for (std::string const& c : configs) {
+ this->GlobalGenerator->CreateEvaluationSourceFiles(c);
}
// Generate the rule files for each target.
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- (*t)->TraceDependencies();
+ target->TraceDependencies();
}
}
@@ -239,7 +284,7 @@ void cmLocalGenerator::GenerateTestFiles()
file += "/";
file += "CTestTestfile.cmake";
- cmGeneratedFileStream fout(file.c_str());
+ cmGeneratedFileStream fout(file);
fout.SetCopyIfDifferent(true);
fout << "# CMake generated Testfile for " << std::endl
@@ -259,50 +304,73 @@ void cmLocalGenerator::GenerateTestFiles()
fout << "include(\"" << testIncludeFile << "\")" << std::endl;
}
+ const char* testIncludeFiles =
+ this->Makefile->GetProperty("TEST_INCLUDE_FILES");
+ if (testIncludeFiles) {
+ std::vector<std::string> includesList;
+ cmSystemTools::ExpandListArgument(testIncludeFiles, includesList);
+ for (std::string const& i : includesList) {
+ fout << "include(\"" << i << "\")" << 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)->Compute(this);
- (*gi)->Generate(fout, config, configurationTypes);
+ for (cmTestGenerator* tester : testers) {
+ tester->Compute(this);
+ tester->Generate(fout, config, configurationTypes);
}
typedef std::vector<cmStateSnapshot> vec_t;
vec_t const& children = this->Makefile->GetStateSnapshot().GetChildren();
std::string parentBinDir = this->GetCurrentBinaryDirectory();
- for (vec_t::const_iterator i = children.begin(); i != children.end(); ++i) {
+ for (cmStateSnapshot const& i : children) {
// TODO: Use add_subdirectory instead?
- std::string outP = i->GetDirectory().GetCurrentBinary();
- outP = this->ConvertToRelativePath(parentBinDir, outP);
+ std::string outP = i.GetDirectory().GetCurrentBinary();
+ outP = this->MaybeConvertToRelativePath(parentBinDir, outP);
outP = cmOutputConverter::EscapeForCMake(outP);
fout << "subdirs(" << outP << ")" << std::endl;
}
+
+ // Add directory labels property
+ const char* directoryLabels =
+ this->Makefile->GetDefinition("CMAKE_DIRECTORY_LABELS");
+ const char* labels = this->Makefile->GetProperty("LABELS");
+
+ if (labels || directoryLabels) {
+ fout << "set_directory_properties(PROPERTIES LABELS ";
+ if (labels) {
+ fout << cmOutputConverter::EscapeForCMake(labels);
+ }
+ if (labels && directoryLabels) {
+ fout << ";";
+ }
+ if (directoryLabels) {
+ fout << cmOutputConverter::EscapeForCMake(directoryLabels);
+ }
+ fout << ")" << std::endl;
+ }
}
void cmLocalGenerator::CreateEvaluationFileOutputs(std::string const& config)
{
std::vector<cmGeneratorExpressionEvaluationFile*> ef =
this->Makefile->GetEvaluationFiles();
- for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
- ef.begin();
- li != ef.end(); ++li) {
- (*li)->CreateOutputFile(this, config);
+ for (cmGeneratorExpressionEvaluationFile* geef : ef) {
+ geef->CreateOutputFile(this, config);
}
}
void cmLocalGenerator::ProcessEvaluationFiles(
std::vector<std::string>& generatedFiles)
{
- std::vector<cmGeneratorExpressionEvaluationFile*> ef =
- this->Makefile->GetEvaluationFiles();
- for (std::vector<cmGeneratorExpressionEvaluationFile*>::const_iterator li =
- ef.begin();
- li != ef.end(); ++li) {
- (*li)->Generate(this);
+ for (cmGeneratorExpressionEvaluationFile* geef :
+ this->Makefile->GetEvaluationFiles()) {
+ geef->Generate(this);
if (cmSystemTools::GetFatalErrorOccured()) {
return;
}
- std::vector<std::string> files = (*li)->GetFiles();
+ std::vector<std::string> files = geef->GetFiles();
std::sort(files.begin(), files.end());
std::vector<std::string> intersection;
@@ -311,15 +379,15 @@ void cmLocalGenerator::ProcessEvaluationFiles(
std::back_inserter(intersection));
if (!intersection.empty()) {
cmSystemTools::Error("Files to be generated by multiple different "
- "commands: ",
- cmWrap('"', intersection, '"', " ").c_str());
+ "commands: " +
+ cmWrap('"', intersection, '"', " "));
return;
}
- generatedFiles.insert(generatedFiles.end(), files.begin(), files.end());
- std::vector<std::string>::iterator newIt =
- generatedFiles.end() - files.size();
- std::inplace_merge(generatedFiles.begin(), newIt, generatedFiles.end());
+ cmAppend(generatedFiles, files);
+ std::inplace_merge(generatedFiles.begin(),
+ generatedFiles.end() - files.size(),
+ generatedFiles.end());
}
}
@@ -327,6 +395,7 @@ 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) {
@@ -370,12 +439,11 @@ void cmLocalGenerator::GenerateInstallRules()
// Choose a default install configuration.
std::string default_config = config;
const char* default_order[] = { "RELEASE", "MINSIZEREL", "RELWITHDEBINFO",
- "DEBUG", CM_NULLPTR };
+ "DEBUG", nullptr };
for (const char** c = default_order; *c && default_config.empty(); ++c) {
- for (std::vector<std::string>::iterator i = configurationTypes.begin();
- i != configurationTypes.end(); ++i) {
- if (cmSystemTools::UpperCase(*i) == *c) {
- default_config = *i;
+ for (std::string const& configurationType : configurationTypes) {
+ if (cmSystemTools::UpperCase(configurationType) == *c) {
+ default_config = configurationType;
}
}
}
@@ -391,7 +459,7 @@ void cmLocalGenerator::GenerateInstallRules()
toplevel_install = 1;
}
file += "/cmake_install.cmake";
- cmGeneratedFileStream fout(file.c_str());
+ cmGeneratedFileStream fout(file);
fout.SetCopyIfDifferent(true);
// Write the header.
@@ -402,7 +470,7 @@ void cmLocalGenerator::GenerateInstallRules()
<< "if(NOT DEFINED CMAKE_INSTALL_PREFIX)" << std::endl
<< " set(CMAKE_INSTALL_PREFIX \"" << prefix << "\")" << std::endl
<< "endif()" << std::endl
- << "string(REGEX REPLACE \"/$\" \"\" CMAKE_INSTALL_PREFIX "
+ << R"(string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX )"
<< "\"${CMAKE_INSTALL_PREFIX}\")" << std::endl
<< std::endl;
@@ -451,35 +519,90 @@ void cmLocalGenerator::GenerateInstallRules()
/* clang-format on */
}
+ // Copy cmake cross compile state to install code.
+ if (const char* crosscompiling =
+ this->Makefile->GetDefinition("CMAKE_CROSSCOMPILING")) {
+ /* clang-format off */
+ fout <<
+ "# Is this installation the result of a crosscompile?\n"
+ "if(NOT DEFINED CMAKE_CROSSCOMPILING)\n"
+ " set(CMAKE_CROSSCOMPILING \"" << crosscompiling << "\")\n"
+ "endif()\n"
+ "\n";
+ /* clang-format on */
+ }
+
+ // Write default directory permissions.
+ if (const char* defaultDirPermissions = this->Makefile->GetDefinition(
+ "CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS")) {
+ /* clang-format off */
+ fout <<
+ "# Set default install directory permissions.\n"
+ "if(NOT DEFINED CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS)\n"
+ " set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS \""
+ << defaultDirPermissions << "\")\n"
+ "endif()\n"
+ "\n";
+ /* clang-format on */
+ }
+
// Ask each install generator to write its code.
+ cmPolicies::PolicyStatus status = this->GetPolicyStatus(cmPolicies::CMP0082);
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);
+ bool haveSubdirectoryInstall = false;
+ bool haveInstallAfterSubdirectory = false;
+ if (status == cmPolicies::WARN) {
+ for (cmInstallGenerator* installer : installers) {
+ installer->CheckCMP0082(haveSubdirectoryInstall,
+ haveInstallAfterSubdirectory);
+ installer->Generate(fout, config, configurationTypes);
+ }
+ } else {
+ for (cmInstallGenerator* installer : installers) {
+ installer->Generate(fout, config, configurationTypes);
+ }
}
// Write rules from old-style specification stored in targets.
this->GenerateTargetInstallRules(fout, config, configurationTypes);
// Include install scripts from subdirectories.
- std::vector<cmStateSnapshot> children =
- this->Makefile->GetStateSnapshot().GetChildren();
- if (!children.empty()) {
- fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
- fout << " # Include the install script for each subdirectory.\n";
- for (std::vector<cmStateSnapshot>::const_iterator ci = children.begin();
- ci != children.end(); ++ci) {
- if (!ci->GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
- std::string odir = ci->GetDirectory().GetCurrentBinary();
- cmSystemTools::ConvertToUnixSlashes(odir);
- fout << " include(\"" << odir << "/cmake_install.cmake\")"
- << std::endl;
+ switch (status) {
+ case cmPolicies::WARN:
+ if (haveInstallAfterSubdirectory &&
+ this->Makefile->PolicyOptionalWarningEnabled(
+ "CMAKE_POLICY_WARNING_CMP0082")) {
+ std::ostringstream e;
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0082) << "\n";
+ this->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
}
- }
- fout << "\n";
- fout << "endif()\n\n";
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD: {
+ std::vector<cmStateSnapshot> children =
+ this->Makefile->GetStateSnapshot().GetChildren();
+ if (!children.empty()) {
+ fout << "if(NOT CMAKE_INSTALL_LOCAL_ONLY)\n";
+ fout << " # Include the install script for each subdirectory.\n";
+ for (cmStateSnapshot const& c : children) {
+ if (!c.GetDirectory().GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
+ std::string odir = c.GetDirectory().GetCurrentBinary();
+ cmSystemTools::ConvertToUnixSlashes(odir);
+ fout << " include(\"" << odir << "/cmake_install.cmake\")"
+ << std::endl;
+ }
+ }
+ fout << "\n";
+ fout << "endif()\n\n";
+ }
+ } break;
+
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::NEW:
+ // NEW behavior is handled in
+ // cmInstallSubdirectoryGenerator::GenerateScript()
+ break;
}
// Record the install manifest.
@@ -504,12 +627,13 @@ void cmLocalGenerator::GenerateInstallRules()
void cmLocalGenerator::AddGeneratorTarget(cmGeneratorTarget* gt)
{
this->GeneratorTargets.push_back(gt);
+ this->GeneratorTargetSearchIndex.emplace(gt->GetName(), gt);
this->GlobalGenerator->IndexGeneratorTarget(gt);
}
void cmLocalGenerator::AddImportedGeneratorTarget(cmGeneratorTarget* gt)
{
- this->ImportedGeneratorTargets.push_back(gt);
+ this->ImportedGeneratorTargets.emplace(gt->GetName(), gt);
this->GlobalGenerator->IndexGeneratorTarget(gt);
}
@@ -518,32 +642,15 @@ void cmLocalGenerator::AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt)
this->OwnedImportedGeneratorTargets.push_back(gt);
}
-struct NamedGeneratorTargetFinder
-{
- NamedGeneratorTargetFinder(std::string const& name)
- : Name(name)
- {
- }
-
- bool operator()(cmGeneratorTarget* tgt)
- {
- return tgt->GetName() == this->Name;
- }
-
-private:
- std::string Name;
-};
-
cmGeneratorTarget* cmLocalGenerator::FindLocalNonAliasGeneratorTarget(
const std::string& name) const
{
- std::vector<cmGeneratorTarget*>::const_iterator ti =
- std::find_if(this->GeneratorTargets.begin(), this->GeneratorTargets.end(),
- NamedGeneratorTargetFinder(name));
- if (ti != this->GeneratorTargets.end()) {
- return *ti;
+ GeneratorTargetMap::const_iterator ti =
+ this->GeneratorTargetSearchIndex.find(name);
+ if (ti != this->GeneratorTargetSearchIndex.end()) {
+ return ti->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
void cmLocalGenerator::ComputeTargetManifest()
@@ -552,21 +659,17 @@ void cmLocalGenerator::ComputeTargetManifest()
std::vector<std::string> configNames;
this->Makefile->GetConfigurations(configNames);
if (configNames.empty()) {
- configNames.push_back("");
+ configNames.emplace_back();
}
// Add our targets to the manifest for each configuration.
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- cmGeneratorTarget* target = *t;
+ const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- for (std::vector<std::string>::iterator ci = configNames.begin();
- ci != configNames.end(); ++ci) {
- const char* config = ci->c_str();
- target->ComputeTargetManifest(config);
+ for (std::string const& c : configNames) {
+ target->ComputeTargetManifest(c);
}
}
}
@@ -577,17 +680,14 @@ bool cmLocalGenerator::ComputeTargetCompileFeatures()
std::vector<std::string> configNames;
this->Makefile->GetConfigurations(configNames);
if (configNames.empty()) {
- configNames.push_back("");
+ configNames.emplace_back();
}
// Process compile features of all targets.
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- cmGeneratorTarget* target = *t;
- for (std::vector<std::string>::iterator ci = configNames.begin();
- ci != configNames.end(); ++ci) {
- if (!target->ComputeCompileFeatures(*ci)) {
+ const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
+ for (cmGeneratorTarget* target : targets) {
+ for (std::string const& c : configNames) {
+ if (!target->ComputeCompileFeatures(c)) {
return false;
}
}
@@ -628,7 +728,7 @@ std::string cmLocalGenerator::ConvertToIncludeReference(
}
std::string cmLocalGenerator::GetIncludeFlags(
- const std::vector<std::string>& includes, cmGeneratorTarget* target,
+ const std::vector<std::string>& includeDirs, cmGeneratorTarget* target,
const std::string& lang, bool forceFullPaths, bool forResponseFile,
const std::string& config)
{
@@ -636,12 +736,15 @@ std::string cmLocalGenerator::GetIncludeFlags(
return "";
}
+ std::vector<std::string> includes = includeDirs;
+ MoveSystemIncludesToEnd(includes, config, lang, target);
+
OutputFormat shellFormat = forResponseFile ? RESPONSE : SHELL;
std::ostringstream includeFlags;
std::string flagVar = "CMAKE_INCLUDE_FLAG_";
flagVar += lang;
- const char* includeFlag = this->Makefile->GetSafeDefinition(flagVar);
+ std::string const& includeFlag = this->Makefile->GetSafeDefinition(flagVar);
flagVar = "CMAKE_INCLUDE_FLAG_SEP_";
flagVar += lang;
const char* sep = this->Makefile->GetDefinition(flagVar);
@@ -663,7 +766,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
// normal flag is repeated for each directory.
std::string sysFlagVar = "CMAKE_INCLUDE_SYSTEM_FLAG_";
sysFlagVar += lang;
- const char* sysIncludeFlag = CM_NULLPTR;
+ const char* sysIncludeFlag = nullptr;
if (repeatFlag) {
sysIncludeFlag = this->Makefile->GetDefinition(sysFlagVar);
}
@@ -684,16 +787,15 @@ std::string cmLocalGenerator::GetIncludeFlags(
#ifdef __APPLE__
emitted.insert("/System/Library/Frameworks");
#endif
- std::vector<std::string>::const_iterator i;
- for (i = includes.begin(); i != includes.end(); ++i) {
+ for (std::string const& i : includes) {
if (fwSearchFlag && *fwSearchFlag && this->Makefile->IsOn("APPLE") &&
- cmSystemTools::IsPathToFramework(i->c_str())) {
- std::string frameworkDir = *i;
+ cmSystemTools::IsPathToFramework(i)) {
+ std::string frameworkDir = i;
frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
if (emitted.insert(frameworkDir).second) {
if (sysFwSearchFlag && target &&
- target->IsSystemIncludeDirectory(*i, config)) {
+ target->IsSystemIncludeDirectory(i, config, lang)) {
includeFlags << sysFwSearchFlag;
} else {
includeFlags << fwSearchFlag;
@@ -706,7 +808,7 @@ std::string cmLocalGenerator::GetIncludeFlags(
if (!flagUsed || repeatFlag) {
if (sysIncludeFlag && target &&
- target->IsSystemIncludeDirectory(*i, config)) {
+ target->IsSystemIncludeDirectory(i, config, lang)) {
includeFlags << sysIncludeFlag;
} else {
includeFlags << includeFlag;
@@ -714,34 +816,24 @@ std::string cmLocalGenerator::GetIncludeFlags(
flagUsed = true;
}
std::string includePath =
- this->ConvertToIncludeReference(*i, shellFormat, forceFullPaths);
- if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
+ this->ConvertToIncludeReference(i, shellFormat, forceFullPaths);
+ if (quotePaths && !includePath.empty() && includePath.front() != '\"') {
includeFlags << "\"";
}
includeFlags << includePath;
- if (quotePaths && !includePath.empty() && includePath[0] != '\"') {
+ if (quotePaths && !includePath.empty() && includePath.front() != '\"') {
includeFlags << "\"";
}
includeFlags << sep;
}
std::string flags = includeFlags.str();
// remove trailing separators
- if ((sep[0] != ' ') && !flags.empty() && flags[flags.size() - 1] == sep[0]) {
- flags[flags.size() - 1] = ' ';
+ if ((sep[0] != ' ') && !flags.empty() && flags.back() == sep[0]) {
+ flags.back() = ' ';
}
return flags;
}
-void cmLocalGenerator::AddCompileDefinitions(std::set<std::string>& defines,
- cmGeneratorTarget const* target,
- const std::string& config,
- const std::string& lang) const
-{
- std::vector<std::string> targetDefines;
- target->GetCompileDefinitions(targetDefines, config, lang);
- this->AppendDefines(defines, targetDefines);
-}
-
void cmLocalGenerator::AddCompileOptions(std::string& flags,
cmGeneratorTarget* target,
const std::string& lang,
@@ -752,20 +844,14 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags,
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, lang);
- 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);
- }
- }
+ // (Re-)Escape these flags. COMPILE_FLAGS were already parsed
+ // as a command line above, and COMPILE_OPTIONS are escaped.
+ this->AppendCompileOptions(flags, opts, langFlagRegexStr);
} else {
// Use all flags.
if (const char* targetFlags = target->GetProperty("COMPILE_FLAGS")) {
@@ -774,52 +860,83 @@ void cmLocalGenerator::AddCompileOptions(std::string& flags,
}
std::vector<std::string> opts;
target->GetCompileOptions(opts, config, lang);
- for (std::vector<std::string>::const_iterator i = opts.begin();
- i != opts.end(); ++i) {
- // COMPILE_OPTIONS are escaped.
- this->AppendFlagEscape(flags, *i);
- }
+ // COMPILE_OPTIONS are escaped.
+ this->AppendCompileOptions(flags, opts);
}
- 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");
+ for (auto const& it : target->GetMaxLanguageStandards()) {
+ const char* standard = target->GetProperty(it.first + "_STANDARD");
if (!standard) {
continue;
}
- if (this->Makefile->IsLaterStandard(it->first, standard, it->second)) {
+ if (this->Makefile->IsLaterStandard(it.first, standard, it.second)) {
std::ostringstream 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
+ << 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
+ << 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->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
}
this->AddCompilerRequirementFlag(flags, target, lang);
+
+ // Add compile flag for the MSVC compiler only.
+ cmMakefile* mf = this->GetMakefile();
+ if (const char* jmc =
+ mf->GetDefinition("CMAKE_" + lang + "_COMPILE_OPTIONS_JMC")) {
+
+ // Handle Just My Code debugging flags, /JMC.
+ // If the target is a Managed C++ one, /JMC is not compatible.
+ if (target->GetManagedType(config) !=
+ cmGeneratorTarget::ManagedType::Managed) {
+ // add /JMC flags if target property VS_JUST_MY_CODE_DEBUGGING is set
+ // to ON
+ if (char const* jmcExprGen =
+ target->GetProperty("VS_JUST_MY_CODE_DEBUGGING")) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(jmcExprGen);
+ std::string isJMCEnabled = cge->Evaluate(this, config);
+ if (cmSystemTools::IsOn(isJMCEnabled)) {
+ std::vector<std::string> optVec;
+ cmSystemTools::ExpandListArgument(jmc, optVec);
+ this->AppendCompileOptions(flags, optVec);
+ }
+ }
+ }
+ }
}
-void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
- cmGeneratorTarget const* target,
- const std::string& lang,
- const std::string& config,
- bool stripImplicitInclDirs) const
+std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
+ cmGeneratorTarget const* target, std::string const& lang,
+ std::string const& config, bool stripImplicitDirs,
+ bool appendAllImplicitDirs) const
{
- // 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;
+ std::vector<BT<std::string>> result;
+ // Do not repeat an include path.
+ std::set<std::string> emitted;
+
+ auto emitDir = [&result, &emitted](std::string const& dir) {
+ if (emitted.insert(dir).second) {
+ result.emplace_back(dir);
+ }
+ };
+
+ auto emitBT = [&result, &emitted](BT<std::string> const& dir) {
+ if (emitted.insert(dir.Value).second) {
+ result.emplace_back(dir);
+ }
+ };
// When automatic include directories are requested for a build then
// include the source and binary directories at the beginning of the
@@ -829,117 +946,188 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
// 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) {
- std::string binDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
- if (emitted.find(binDir) == emitted.end()) {
- dirs.push_back(binDir);
- emitted.insert(binDir);
- }
- }
- if (includeSourceDir) {
- std::string srcDir = this->StateSnapshot.GetDirectory().GetCurrentSource();
- if (emitted.find(srcDir) == emitted.end()) {
- dirs.push_back(srcDir);
- emitted.insert(srcDir);
- }
+ // Current binary directory
+ emitDir(this->StateSnapshot.GetDirectory().GetCurrentBinary());
+ // Current source directory
+ emitDir(this->StateSnapshot.GetDirectory().GetCurrentSource());
}
if (!target) {
- return;
+ return result;
}
- std::string rootPath;
- if (const char* sysrootCompile =
- this->Makefile->GetDefinition("CMAKE_SYSROOT_COMPILE")) {
- rootPath = sysrootCompile;
- } else {
- rootPath = this->Makefile->GetSafeDefinition("CMAKE_SYSROOT");
+ // Standard include directories to be added unconditionally at the end.
+ // These are intended to simulate additional implicit include directories.
+ std::vector<std::string> userStandardDirs;
+ {
+ std::string key = "CMAKE_";
+ key += lang;
+ key += "_STANDARD_INCLUDE_DIRECTORIES";
+ std::string const value = this->Makefile->GetSafeDefinition(key);
+ cmSystemTools::ExpandListArgument(value, userStandardDirs);
+ for (std::string& usd : userStandardDirs) {
+ cmSystemTools::ConvertToUnixSlashes(usd);
+ }
}
+ // Implicit include directories
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);
+ std::set<std::string> implicitSet;
+ // Include directories to be excluded as if they were implicit.
+ std::set<std::string> implicitExclude;
+ {
+ // Raw list of implicit include directories
+ // Start with "standard" directories that we unconditionally add below.
+ std::vector<std::string> impDirVec = userStandardDirs;
+
+ // Load implicit include directories for this language.
+ // We ignore this for Fortran because:
+ // * There are no standard library headers to avoid overriding.
+ // * Compilers like gfortran do not search their own implicit include
+ // directories for modules ('.mod' files).
+ if (lang != "Fortran") {
+ std::string key = "CMAKE_";
+ key += lang;
+ key += "_IMPLICIT_INCLUDE_DIRECTORIES";
+ if (const char* value = this->Makefile->GetDefinition(key)) {
+ size_t const impDirVecOldSize = impDirVec.size();
+ cmSystemTools::ExpandListArgument(value, impDirVec);
+ // FIXME: Use cmRange with 'advance()' when it supports non-const.
+ for (size_t i = impDirVecOldSize; i < impDirVec.size(); ++i) {
+ cmSystemTools::ConvertToUnixSlashes(impDirVec[i]);
+ }
+ }
+ }
+
+ // The Platform/UnixPaths module used to hard-code /usr/include for C, CXX,
+ // and CUDA in CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES, but those
+ // variables are now computed. On macOS the /usr/include directory is
+ // inside the platform SDK so the computed value does not contain it
+ // directly. In this case adding -I/usr/include can hide SDK headers so we
+ // must still exclude it.
+ if ((lang == "C" || lang == "CXX" || lang == "CUDA") &&
+ std::find(impDirVec.begin(), impDirVec.end(), "/usr/include") ==
+ impDirVec.end() &&
+ std::find_if(impDirVec.begin(), impDirVec.end(),
+ [](std::string const& d) {
+ return cmHasLiteralSuffix(d, "/usr/include");
+ }) != impDirVec.end()) {
+ // Only exclude this hard coded path for backwards compatibility.
+ implicitExclude.emplace("/usr/include");
+ }
+
+ for (std::string const& i : impDirVec) {
+ if (implicitSet.insert(i).second) {
+ implicitDirs.emplace_back(i);
}
}
}
- // Get the target-specific include directories.
- std::vector<std::string> includes;
+ // Checks if this is not an excluded (implicit) include directory.
+ auto notExcluded = [this, &implicitSet, &implicitExclude,
+ &lang](std::string const& dir) {
+ return (
+ // Do not exclude directories that are not in an excluded set.
+ ((implicitSet.find(dir) == implicitSet.end()) &&
+ (implicitExclude.find(dir) == implicitExclude.end()))
+ // Do not exclude entries of the CPATH environment variable even though
+ // they are implicitly searched by the compiler. They are meant to be
+ // user-specified directories that can be re-ordered or converted to
+ // -isystem without breaking real compiler builtin headers.
+ || ((lang == "C" || lang == "CXX") &&
+ (this->EnvCPATH.find(dir) != this->EnvCPATH.end())));
+ };
- includes = target->GetIncludeDirectories(config, lang);
+ // Get the target-specific include directories.
+ std::vector<BT<std::string>> userDirs =
+ target->GetIncludeDirectories(config, lang);
// 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->GetState()->GetSourceDirectory();
- const char* topBinaryDir = this->GetState()->GetBinaryDirectory();
- for (std::vector<std::string>::const_iterator i = includes.begin();
- i != includes.end(); ++i) {
+ std::string const &topSourceDir = this->GetState()->GetSourceDirectory(),
+ &topBinaryDir = this->GetState()->GetBinaryDirectory();
+ for (BT<std::string> const& udr : userDirs) {
// Emit this directory only if it is a subdirectory of the
// top-level source or binary tree.
- if (cmSystemTools::ComparePath(*i, topSourceDir) ||
- cmSystemTools::ComparePath(*i, topBinaryDir) ||
- cmSystemTools::IsSubDirectory(*i, topSourceDir) ||
- cmSystemTools::IsSubDirectory(*i, topBinaryDir)) {
- if (emitted.insert(*i).second) {
- dirs.push_back(*i);
+ if (cmSystemTools::ComparePath(udr.Value, topSourceDir) ||
+ cmSystemTools::ComparePath(udr.Value, topBinaryDir) ||
+ cmSystemTools::IsSubDirectory(udr.Value, topSourceDir) ||
+ cmSystemTools::IsSubDirectory(udr.Value, topBinaryDir)) {
+ if (notExcluded(udr.Value)) {
+ emitBT(udr);
}
}
}
}
- // 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);
+ // Emit remaining non implicit user direcories.
+ for (BT<std::string> const& udr : userDirs) {
+ if (notExcluded(udr.Value)) {
+ emitBT(udr);
}
}
- // Add standard include directories for this language.
- // We do not filter out implicit directories here.
- std::string const standardIncludesVar =
- "CMAKE_" + lang + "_STANDARD_INCLUDE_DIRECTORIES";
- std::string const standardIncludes =
- this->Makefile->GetSafeDefinition(standardIncludesVar);
- std::vector<std::string>::size_type const before = includes.size();
- cmSystemTools::ExpandListArgument(standardIncludes, includes);
- for (std::vector<std::string>::iterator i = includes.begin() + before;
- i != includes.end(); ++i) {
- cmSystemTools::ConvertToUnixSlashes(*i);
- dirs.push_back(*i);
+ // Sort result
+ MoveSystemIncludesToEnd(result, config, lang, target);
+
+ // Append standard include directories for this language.
+ userDirs.reserve(userDirs.size() + userStandardDirs.size());
+ for (std::string& usd : userStandardDirs) {
+ emitDir(usd);
+ userDirs.emplace_back(std::move(usd));
}
- 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);
+ // Append compiler implicit include directories
+ if (!stripImplicitDirs) {
+ // Append implicit directories that were requested by the user only
+ for (BT<std::string> const& udr : userDirs) {
+ if (implicitSet.find(udr.Value) != implicitSet.end()) {
+ emitBT(udr);
+ }
+ }
+ // Append remaining implicit directories (on demand)
+ if (appendAllImplicitDirs) {
+ for (std::string& imd : implicitDirs) {
+ emitDir(imd);
+ }
}
}
+
+ return result;
+}
+
+void cmLocalGenerator::GetIncludeDirectoriesImplicit(
+ std::vector<std::string>& dirs, cmGeneratorTarget const* target,
+ const std::string& lang, const std::string& config, bool stripImplicitDirs,
+ bool appendAllImplicitDirs) const
+{
+ std::vector<BT<std::string>> tmp = this->GetIncludeDirectoriesImplicit(
+ target, lang, config, stripImplicitDirs, appendAllImplicitDirs);
+ dirs.reserve(dirs.size() + tmp.size());
+ for (BT<std::string>& v : tmp) {
+ dirs.emplace_back(std::move(v.Value));
+ }
+}
+
+std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectories(
+ cmGeneratorTarget const* target, std::string const& lang,
+ std::string const& config) const
+{
+ return this->GetIncludeDirectoriesImplicit(target, lang, config);
+}
+
+void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
+ cmGeneratorTarget const* target,
+ const std::string& lang,
+ const std::string& config) const
+{
+ this->GetIncludeDirectoriesImplicit(dirs, target, lang, config);
}
void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
std::string const& config,
+ std::string const& linkLanguage,
cmGeneratorTarget* target)
{
this->AppendFlags(
@@ -953,6 +1141,11 @@ void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
std::string name = "STATIC_LIBRARY_FLAGS_" + config;
this->AppendFlags(flags, target->GetProperty(name));
}
+
+ std::vector<std::string> options;
+ target->GetStaticLibraryLinkOptions(options, config, linkLanguage);
+ // STATIC_LIBRARY_OPTIONS are escaped.
+ this->AppendCompileOptions(flags, options);
}
void cmLocalGenerator::GetTargetFlags(
@@ -970,38 +1163,40 @@ void cmLocalGenerator::GetTargetFlags(
switch (target->GetType()) {
case cmStateEnums::STATIC_LIBRARY:
- this->GetStaticLibraryFlags(linkFlags, buildType, target);
+ this->GetStaticLibraryFlags(linkFlags, buildType, linkLanguage, target);
break;
case cmStateEnums::MODULE_LIBRARY:
libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
CM_FALLTHROUGH;
case cmStateEnums::SHARED_LIBRARY: {
- linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
- linkFlags += " ";
- if (!buildType.empty()) {
- std::string build = libraryLinkVariable;
- build += "_";
- build += buildType;
- linkFlags += this->Makefile->GetSafeDefinition(build);
+ if (linkLanguage != "Swift") {
+ linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable);
linkFlags += " ";
- }
- if (this->Makefile->IsOn("WIN32") &&
- !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) {
- std::vector<cmSourceFile*> sources;
- target->GetSourceFiles(sources, buildType);
- std::string defFlag =
- this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
- for (std::vector<cmSourceFile*>::const_iterator i = sources.begin();
- i != sources.end(); ++i) {
- cmSourceFile* sf = *i;
- if (sf->GetExtension() == "def") {
- linkFlags += defFlag;
- linkFlags += this->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(sf->GetFullPath()), SHELL);
- 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);
+ std::string defFlag =
+ this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG");
+ for (cmSourceFile* sf : sources) {
+ if (sf->GetExtension() == "def") {
+ linkFlags += defFlag;
+ linkFlags += this->ConvertToOutputFormat(
+ cmSystemTools::CollapseFullPath(sf->GetFullPath()), SHELL);
+ linkFlags += " ";
+ }
}
}
}
+
const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
if (targetLinkFlags) {
linkFlags += targetLinkFlags;
@@ -1016,31 +1211,60 @@ void cmLocalGenerator::GetTargetFlags(
linkFlags += " ";
}
}
+
+ std::vector<std::string> opts;
+ target->GetLinkOptions(opts, config, linkLanguage);
+ // LINK_OPTIONS are escaped.
+ this->AppendCompileOptions(linkFlags, opts);
if (pcli) {
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath);
}
} break;
case cmStateEnums::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);
+ if (linkLanguage != "Swift") {
+ 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 += " ";
+ }
+ if (linkLanguage.empty()) {
+ cmSystemTools::Error(
+ "CMake can not determine linker language for target: " +
+ target->GetName());
+ return;
+ }
+
+ 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->IsExecutableWithExports()) {
+ std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
+ exportFlagVar += linkLanguage;
+ exportFlagVar += "_FLAG";
+
+ linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar);
+ linkFlags += " ";
+ }
}
- if (linkLanguage.empty()) {
- cmSystemTools::Error(
- "CMake can not determine linker language for target: ",
- target->GetName().c_str());
- return;
- }
+
this->AddLanguageFlagsForLinking(flags, target, linkLanguage, buildType);
if (pcli) {
this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
frameworkPath, linkPath);
}
+
if (cmSystemTools::IsOn(
this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) {
std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") +
@@ -1048,23 +1272,6 @@ void cmLocalGenerator::GetTargetFlags(
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->IsExecutableWithExports()) {
- std::string exportFlagVar = "CMAKE_EXE_EXPORTS_";
- exportFlagVar += linkLanguage;
- exportFlagVar += "_FLAG";
-
- linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar);
- linkFlags += " ";
- }
std::string cmp0065Flags =
this->GetLinkLibsCMP0065(linkLanguage, *target);
@@ -1087,11 +1294,18 @@ void cmLocalGenerator::GetTargetFlags(
linkFlags += " ";
}
}
+
+ std::vector<std::string> opts;
+ target->GetLinkOptions(opts, config, linkLanguage);
+ // LINK_OPTIONS are escaped.
+ this->AppendCompileOptions(linkFlags, opts);
} break;
default:
break;
}
+ this->AppendPositionIndependentLinkerFlags(linkFlags, target, config,
+ linkLanguage);
this->AppendIPOLinkerFlags(linkFlags, target, config, linkLanguage);
}
@@ -1105,6 +1319,10 @@ void cmLocalGenerator::GetTargetCompileFlags(cmGeneratorTarget* target,
// Add language-specific flags.
this->AddLanguageFlags(flags, target, lang, config);
+ if (target->IsIPOEnabled(lang, config)) {
+ this->AppendFeatureOptions(flags, lang, "IPO");
+ }
+
this->AddArchitectureFlags(flags, target, lang, config);
if (lang == "Fortran") {
@@ -1144,10 +1362,9 @@ static std::string GetFrameworkFlags(const std::string& lang,
lg->GetIncludeDirectories(includes, target, "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 (lg->GetGlobalGenerator()->NameResolvesToFramework(*i)) {
- std::string frameworkDir = *i;
+ for (std::string const& include : includes) {
+ if (lg->GetGlobalGenerator()->NameResolvesToFramework(include)) {
+ std::string frameworkDir = include;
frameworkDir += "/../";
frameworkDir = cmSystemTools::CollapseFullPath(frameworkDir);
emitted.insert(frameworkDir);
@@ -1157,11 +1374,11 @@ static std::string GetFrameworkFlags(const std::string& lang,
std::string flags;
if (cmComputeLinkInformation* cli = target->GetLinkInformation(config)) {
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) {
+ for (std::string const& framework : frameworks) {
+ if (emitted.insert(framework).second) {
flags += fwSearchFlag;
- flags += lg->ConvertToOutputFormat(*i, cmOutputConverter::SHELL);
+ flags +=
+ lg->ConvertToOutputFormat(framework, cmOutputConverter::SHELL);
flags += " ";
}
}
@@ -1181,13 +1398,29 @@ void cmLocalGenerator::GetTargetDefines(cmGeneratorTarget const* target,
std::string const& lang,
std::set<std::string>& defines) const
{
+ std::set<BT<std::string>> tmp = this->GetTargetDefines(target, config, lang);
+ for (BT<std::string> const& v : tmp) {
+ defines.emplace(v.Value);
+ }
+}
+
+std::set<BT<std::string>> cmLocalGenerator::GetTargetDefines(
+ cmGeneratorTarget const* target, std::string const& config,
+ std::string const& lang) const
+{
+ std::set<BT<std::string>> defines;
+
// Add the export symbol definition for shared library objects.
- if (const char* exportMacro = target->GetExportMacro()) {
- this->AppendDefines(defines, exportMacro);
+ if (const std::string* exportMacro = target->GetExportMacro()) {
+ this->AppendDefines(defines, *exportMacro);
}
// Add preprocessor definitions for this target and configuration.
- this->AddCompileDefinitions(defines, target, config, lang);
+ std::vector<BT<std::string>> targetDefines =
+ target->GetCompileDefinitions(config, lang);
+ this->AppendDefines(defines, targetDefines);
+
+ return defines;
}
std::string cmLocalGenerator::GetTargetFortranFlags(
@@ -1211,10 +1444,23 @@ void cmLocalGenerator::OutputLinkLibraries(
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");
+ std::string libPathFlag;
+ if (const char* value = this->Makefile->GetDefinition(
+ "CMAKE_" + cli.GetLinkLanguage() + "_LIBRARY_PATH_FLAG")) {
+ libPathFlag = value;
+ } else {
+ libPathFlag =
+ this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_FLAG");
+ }
+
+ std::string libPathTerminator;
+ if (const char* value = this->Makefile->GetDefinition(
+ "CMAKE_" + cli.GetLinkLanguage() + "_LIBRARY_PATH_TERMINATOR")) {
+ libPathTerminator = value;
+ } else {
+ libPathTerminator =
+ this->Makefile->GetRequiredDefinition("CMAKE_LIBRARY_PATH_TERMINATOR");
+ }
// Add standard libraries for this language.
std::string standardLibsVar = "CMAKE_";
@@ -1261,7 +1507,7 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065(
"additional flags may be added to export symbols on all "
"executables regardless of their ENABLE_EXPORTS property.";
/* clang-format on */
- this->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -1271,7 +1517,7 @@ std::string cmLocalGenerator::GetLinkLibsCMP0065(
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
this->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065));
CM_FALLTHROUGH;
case cmPolicies::NEW:
@@ -1295,13 +1541,13 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
const std::string& lang,
const std::string& config)
{
- // Only add Mac OS X specific flags on Darwin platforms (OSX and iphone):
+ // Only add macOS specific flags on Darwin platforms (macOS and iOS):
if (this->Makefile->IsOn("APPLE") && 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 = CM_NULLPTR;
+ sysroot = nullptr;
}
std::string sysrootFlagVar =
std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
@@ -1314,10 +1560,9 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
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) {
+ for (std::string const& arch : archs) {
flags += " -arch ";
- flags += *i;
+ flags += arch;
}
}
@@ -1348,8 +1593,39 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
flagsVar += "_FLAGS";
this->AddConfigVariableFlags(flags, flagsVar, config);
- if (target->IsIPOEnabled(lang, config)) {
- this->AppendFeatureOptions(flags, lang, "IPO");
+ // Add MSVC runtime library flags. This is activated by the presence
+ // of a default selection whether or not it is overridden by a property.
+ const char* msvcRuntimeLibraryDefault =
+ this->Makefile->GetDefinition("CMAKE_MSVC_RUNTIME_LIBRARY_DEFAULT");
+ if (msvcRuntimeLibraryDefault && *msvcRuntimeLibraryDefault) {
+ const char* msvcRuntimeLibraryValue =
+ target->GetProperty("MSVC_RUNTIME_LIBRARY");
+ if (!msvcRuntimeLibraryValue) {
+ msvcRuntimeLibraryValue = msvcRuntimeLibraryDefault;
+ }
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(msvcRuntimeLibraryValue);
+ std::string const msvcRuntimeLibrary =
+ cge->Evaluate(this, config, false, target);
+ if (!msvcRuntimeLibrary.empty()) {
+ if (const char* msvcRuntimeLibraryOptions =
+ this->Makefile->GetDefinition(
+ "CMAKE_" + lang + "_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_" +
+ msvcRuntimeLibrary)) {
+ this->AppendCompileOptions(flags, msvcRuntimeLibraryOptions);
+ } else if ((this->Makefile->GetSafeDefinition(
+ "CMAKE_" + lang + "_COMPILER_ID") == "MSVC" ||
+ this->Makefile->GetSafeDefinition(
+ "CMAKE_" + lang + "_SIMULATE_ID") == "MSVC") &&
+ !cmSystemTools::GetErrorOccuredFlag()) {
+ // The compiler uses the MSVC ABI so it needs a known runtime library.
+ this->IssueMessage(MessageType::FATAL_ERROR,
+ "MSVC_RUNTIME_LIBRARY value '" +
+ msvcRuntimeLibrary + "' not known for this " +
+ lang + " compiler.");
+ }
+ }
}
}
@@ -1367,16 +1643,19 @@ void cmLocalGenerator::AddLanguageFlagsForLinking(
}
this->AddLanguageFlags(flags, target, lang, config);
+
+ if (target->IsIPOEnabled(lang, config)) {
+ this->AppendFeatureOptions(flags, lang, "IPO");
+ }
}
cmGeneratorTarget* cmLocalGenerator::FindGeneratorTargetToUse(
const std::string& name) const
{
- std::vector<cmGeneratorTarget*>::const_iterator imported = std::find_if(
- this->ImportedGeneratorTargets.begin(),
- this->ImportedGeneratorTargets.end(), NamedGeneratorTargetFinder(name));
+ GeneratorTargetMap::const_iterator imported =
+ this->ImportedGeneratorTargets.find(name);
if (imported != this->ImportedGeneratorTargets.end()) {
- return *imported;
+ return imported->second;
}
if (cmGeneratorTarget* t = this->FindLocalNonAliasGeneratorTarget(name)) {
@@ -1399,7 +1678,7 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
// If the input name is the empty string, there is no real
// dependency. Short-circuit the other checks:
- if (name == "") {
+ if (name.empty()) {
return false;
}
@@ -1411,7 +1690,7 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
if (cmGeneratorTarget* target = this->FindGeneratorTargetToUse(name)) {
// make sure it is not just a coincidence that the target name
// found is part of the inName
- if (cmSystemTools::FileIsFullPath(inName.c_str())) {
+ if (cmSystemTools::FileIsFullPath(inName)) {
std::string tLocation;
if (target->GetType() >= cmStateEnums::EXECUTABLE &&
target->GetType() <= cmStateEnums::MODULE_LIBRARY) {
@@ -1455,7 +1734,7 @@ bool cmLocalGenerator::GetRealDependency(const std::string& inName,
}
// The name was not that of a CMake target. It must name a file.
- if (cmSystemTools::FileIsFullPath(inName.c_str())) {
+ if (cmSystemTools::FileIsFullPath(inName)) {
// This is a full path. Return it as given.
dep = inName;
return true;
@@ -1502,20 +1781,34 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
// This compiler has no notion of language standard levels.
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";
}
}
+ std::string stdProp = lang + "_STANDARD";
+ const char* standardProp = target->GetProperty(stdProp);
+ if (!standardProp) {
+ if (ext) {
+ // No language standard is specified and extensions are not disabled.
+ // Check if this compiler needs a flag to enable extensions.
+ std::string const option_flag =
+ "CMAKE_" + lang + "_EXTENSION_COMPILE_OPTION";
+ if (const char* opt =
+ target->Target->GetMakefile()->GetDefinition(option_flag)) {
+ std::vector<std::string> optVec;
+ cmSystemTools::ExpandListArgument(opt, optVec);
+ for (std::string const& i : optVec) {
+ this->AppendFlagEscape(flags, i);
+ }
+ }
+ }
+ return;
+ }
+
+ std::string const type = ext ? "EXTENSION" : "STANDARD";
if (target->GetPropertyAsBool(lang + "_STANDARD_REQUIRED")) {
std::string option_flag =
@@ -1525,38 +1818,40 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
target->Target->GetMakefile()->GetDefinition(option_flag);
if (!opt) {
std::ostringstream e;
- e << "Target \"" << target->GetName() << "\" requires the language "
- "dialect \""
+ 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->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
} else {
std::vector<std::string> optVec;
cmSystemTools::ExpandListArgument(opt, optVec);
- for (size_t i = 0; i < optVec.size(); ++i) {
- this->AppendFlagEscape(flags, optVec[i]);
+ for (std::string const& i : optVec) {
+ this->AppendFlagEscape(flags, i);
}
}
return;
}
- static std::map<std::string, std::vector<std::string> > langStdMap;
+ static std::map<std::string, std::vector<std::string>> langStdMap;
if (langStdMap.empty()) {
// Maintain sorted order, most recent first.
- langStdMap["CXX"].push_back("17");
- langStdMap["CXX"].push_back("14");
- langStdMap["CXX"].push_back("11");
- langStdMap["CXX"].push_back("98");
+ langStdMap["CXX"].emplace_back("20");
+ langStdMap["CXX"].emplace_back("17");
+ langStdMap["CXX"].emplace_back("14");
+ langStdMap["CXX"].emplace_back("11");
+ langStdMap["CXX"].emplace_back("98");
- langStdMap["C"].push_back("11");
- langStdMap["C"].push_back("99");
- langStdMap["C"].push_back("90");
+ langStdMap["C"].emplace_back("11");
+ langStdMap["C"].emplace_back("99");
+ langStdMap["C"].emplace_back("90");
- langStdMap["CUDA"].push_back("14");
- langStdMap["CUDA"].push_back("11");
- langStdMap["CUDA"].push_back("98");
+ langStdMap["CUDA"].emplace_back("14");
+ langStdMap["CUDA"].emplace_back("11");
+ langStdMap["CUDA"].emplace_back("98");
}
std::string standard(standardProp);
@@ -1569,7 +1864,7 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
std::string e =
lang + "_STANDARD is set to invalid value '" + standard + "'";
this->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR, e, target->GetBacktrace());
+ MessageType::FATAL_ERROR, e, target->GetBacktrace());
return;
}
@@ -1579,26 +1874,31 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
std::string e = "CMAKE_" + lang +
"_STANDARD_DEFAULT is set to invalid value '" + std::string(defaultStd) +
"'";
- this->IssueMessage(cmake::INTERNAL_ERROR, e);
+ this->IssueMessage(MessageType::INTERNAL_ERROR, e);
return;
}
- // Greater or equal because the standards are stored in
- // backward chronological order.
+ // If the standard requested is older than the compiler's default
+ // then we need to use a flag to change it. The comparison is
+ // greater-or-equal because the standards are stored in backward
+ // chronological order.
if (stdIt >= defaultStdIt) {
std::string option_flag =
"CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
- const char* opt =
+ std::string const& opt =
target->Target->GetMakefile()->GetRequiredDefinition(option_flag);
std::vector<std::string> optVec;
cmSystemTools::ExpandListArgument(opt, optVec);
- for (size_t i = 0; i < optVec.size(); ++i) {
- this->AppendFlagEscape(flags, optVec[i]);
+ for (std::string const& i : optVec) {
+ this->AppendFlagEscape(flags, i);
}
return;
}
+ // The standard requested is at least as new as the compiler's default,
+ // and the standard request is not required. Decay to the newest standard
+ // for which a flag is defined.
for (; stdIt < defaultStdIt; ++stdIt) {
std::string option_flag =
"CMAKE_" + lang + *stdIt + "_" + type + "_COMPILE_OPTION";
@@ -1607,8 +1907,8 @@ void cmLocalGenerator::AddCompilerRequirementFlag(
target->Target->GetMakefile()->GetDefinition(option_flag)) {
std::vector<std::string> optVec;
cmSystemTools::ExpandListArgument(opt, optVec);
- for (size_t i = 0; i < optVec.size(); ++i) {
- this->AppendFlagEscape(flags, optVec[i]);
+ for (std::string const& i : optVec) {
+ this->AppendFlagEscape(flags, i);
}
return;
}
@@ -1640,8 +1940,10 @@ static void AddVisibilityCompileOption(std::string& flags,
strcmp(prop, "protected") != 0 && strcmp(prop, "internal") != 0) {
std::ostringstream e;
e << "Target " << target->GetName() << " uses unsupported value \"" << prop
- << "\" for " << flagDefine << ".";
- cmSystemTools::Error(e.str().c_str());
+ << "\" for " << flagDefine << "."
+ << " The supported values are: default, hidden, protected, and "
+ "internal.";
+ cmSystemTools::Error(e.str());
return;
}
std::string option = std::string(opt) + prop;
@@ -1679,7 +1981,7 @@ void cmLocalGenerator::AddVisibilityPresetFlags(
}
std::string warnCMP0063;
- std::string* pWarnCMP0063 = CM_NULLPTR;
+ std::string* pWarnCMP0063 = nullptr;
if (target->GetType() != cmStateEnums::SHARED_LIBRARY &&
target->GetType() != cmStateEnums::MODULE_LIBRARY &&
!target->IsExecutableWithExports()) {
@@ -1712,7 +2014,7 @@ void cmLocalGenerator::AddVisibilityPresetFlags(
"For compatibility CMake is not honoring them for this target.";
/* clang-format on */
target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
- cmake::AUTHOR_WARNING, w.str(), target->GetBacktrace());
+ MessageType::AUTHOR_WARNING, w.str(), target->GetBacktrace());
}
}
@@ -1755,9 +2057,9 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
std::string flagsVar = "CMAKE_SHARED_LIBRARY_";
flagsVar += lang;
flagsVar += "_FLAGS";
- const char* flags = this->Makefile->GetSafeDefinition(flagsVar);
+ std::string const& flags = this->Makefile->GetSafeDefinition(flagsVar);
- if (flags && flags != originalFlags) {
+ if (flags != originalFlags) {
switch (this->GetPolicyStatus(cmPolicies::CMP0018)) {
case cmPolicies::WARN: {
std::ostringstream e;
@@ -1771,7 +2073,7 @@ bool cmLocalGenerator::GetShouldUseOldFlags(bool shared,
<< flagsVar << " was removed.\n"
<< cmPolicies::GetPolicyWarning(cmPolicies::CMP0018);
- this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
CM_FALLTHROUGH;
}
case cmPolicies::OLD:
@@ -1790,7 +2092,7 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
std::string const& lang,
int targetType)
{
- const char* picFlags = CM_NULLPTR;
+ std::string picFlags;
if (targetType == cmStateEnums::EXECUTABLE) {
std::string flagsVar = "CMAKE_";
@@ -1798,18 +2100,17 @@ void cmLocalGenerator::AddPositionIndependentFlags(std::string& flags,
flagsVar += "_COMPILE_OPTIONS_PIE";
picFlags = this->Makefile->GetSafeDefinition(flagsVar);
}
- if (!picFlags) {
+ if (picFlags.empty()) {
std::string flagsVar = "CMAKE_";
flagsVar += lang;
flagsVar += "_COMPILE_OPTIONS_PIC";
picFlags = this->Makefile->GetSafeDefinition(flagsVar);
}
- if (picFlags) {
+ if (!picFlags.empty()) {
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);
+ for (std::string const& o : options) {
+ this->AppendFlagEscape(flags, o);
}
}
}
@@ -1830,7 +2131,7 @@ void cmLocalGenerator::AddConfigVariableFlags(std::string& flags,
}
void cmLocalGenerator::AppendFlags(std::string& flags,
- const std::string& newFlags)
+ const std::string& newFlags) const
{
if (!newFlags.empty()) {
if (!flags.empty()) {
@@ -1840,7 +2141,8 @@ void cmLocalGenerator::AppendFlags(std::string& flags,
}
}
-void cmLocalGenerator::AppendFlags(std::string& flags, const char* newFlags)
+void cmLocalGenerator::AppendFlags(std::string& flags,
+ const char* newFlags) const
{
if (newFlags && *newFlags) {
this->AppendFlags(flags, std::string(newFlags));
@@ -1848,7 +2150,7 @@ void cmLocalGenerator::AppendFlags(std::string& flags, const char* newFlags)
}
void cmLocalGenerator::AppendFlagEscape(std::string& flags,
- const std::string& rawFlag)
+ const std::string& rawFlag) const
{
this->AppendFlags(flags, this->EscapeForShell(rawFlag));
}
@@ -1873,43 +2175,166 @@ void cmLocalGenerator::AppendIPOLinkerFlags(std::string& flags,
const std::string name = "CMAKE_" + lang + "_LINK_OPTIONS_IPO";
const char* rawFlagsList = this->Makefile->GetDefinition(name);
- if (rawFlagsList == CM_NULLPTR) {
+ if (rawFlagsList == nullptr) {
return;
}
std::vector<std::string> flagsList;
cmSystemTools::ExpandListArgument(rawFlagsList, flagsList);
- for (std::vector<std::string>::const_iterator oi = flagsList.begin();
- oi != flagsList.end(); ++oi) {
- this->AppendFlagEscape(flags, *oi);
+ for (std::string const& o : flagsList) {
+ this->AppendFlagEscape(flags, o);
+ }
+}
+
+void cmLocalGenerator::AppendPositionIndependentLinkerFlags(
+ std::string& flags, cmGeneratorTarget* target, const std::string& config,
+ const std::string& lang)
+{
+ // For now, only EXECUTABLE is concerned
+ if (target->GetType() != cmStateEnums::EXECUTABLE) {
+ return;
+ }
+
+ const char* PICValue = target->GetLinkPIEProperty(config);
+ if (PICValue == nullptr) {
+ // POSITION_INDEPENDENT_CODE is not set
+ return;
+ }
+
+ const std::string mode = cmSystemTools::IsOn(PICValue) ? "PIE" : "NO_PIE";
+
+ std::string supported = "CMAKE_" + lang + "_LINK_" + mode + "_SUPPORTED";
+ if (cmSystemTools::IsOff(this->Makefile->GetDefinition(supported))) {
+ return;
+ }
+
+ std::string name = "CMAKE_" + lang + "_LINK_OPTIONS_" + mode;
+
+ auto pieFlags = this->Makefile->GetSafeDefinition(name);
+ if (pieFlags.empty()) {
+ return;
+ }
+
+ std::vector<std::string> flagsList;
+ cmSystemTools::ExpandListArgument(pieFlags, flagsList);
+ for (const auto& flag : flagsList) {
+ this->AppendFlagEscape(flags, flag);
+ }
+}
+
+void cmLocalGenerator::AppendCompileOptions(std::string& options,
+ const char* options_list,
+ const char* regex) const
+{
+ // Short-circuit if there are no options.
+ if (!options_list) {
+ return;
+ }
+
+ // Expand the list of options.
+ std::vector<std::string> options_vec;
+ cmSystemTools::ExpandListArgument(options_list, options_vec);
+ this->AppendCompileOptions(options, options_vec, regex);
+}
+
+void cmLocalGenerator::AppendCompileOptions(
+ std::string& options, const std::vector<std::string>& options_vec,
+ const char* regex) const
+{
+ if (regex != nullptr) {
+ // Filter flags upon specified reges.
+ cmsys::RegularExpression r(regex);
+
+ for (std::string const& opt : options_vec) {
+ if (r.find(opt)) {
+ this->AppendFlagEscape(options, opt);
+ }
+ }
+ } else {
+ for (std::string const& opt : options_vec) {
+ this->AppendFlagEscape(options, opt);
+ }
+ }
+}
+
+void cmLocalGenerator::AppendIncludeDirectories(
+ std::vector<std::string>& includes, const char* includes_list,
+ const cmSourceFile& sourceFile) const
+{
+ // Short-circuit if there are no includes.
+ if (!includes_list) {
+ return;
+ }
+
+ // Expand the list of includes.
+ std::vector<std::string> includes_vec;
+ cmSystemTools::ExpandListArgument(includes_list, includes_vec);
+ this->AppendIncludeDirectories(includes, includes_vec, sourceFile);
+}
+
+void cmLocalGenerator::AppendIncludeDirectories(
+ std::vector<std::string>& includes,
+ const std::vector<std::string>& includes_vec,
+ const cmSourceFile& sourceFile) const
+{
+ std::unordered_set<std::string> uniqueIncludes;
+
+ for (const std::string& include : includes_vec) {
+ if (!cmSystemTools::FileIsFullPath(include)) {
+ std::ostringstream e;
+ e << "Found relative path while evaluating include directories of "
+ "\""
+ << sourceFile.GetLocation().GetName() << "\":\n \"" << include
+ << "\"\n";
+
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return;
+ }
+
+ std::string inc = include;
+
+ if (!cmSystemTools::IsOff(inc)) {
+ cmSystemTools::ConvertToUnixSlashes(inc);
+ }
+
+ if (uniqueIncludes.insert(inc).second) {
+ includes.push_back(std::move(inc));
+ }
}
}
void cmLocalGenerator::AppendDefines(std::set<std::string>& defines,
- const char* defines_list) const
+ std::string const& defines_list) const
+{
+ std::set<BT<std::string>> tmp;
+ this->AppendDefines(tmp, ExpandListWithBacktrace(defines_list));
+ for (BT<std::string> const& i : tmp) {
+ defines.emplace(i.Value);
+ }
+}
+
+void cmLocalGenerator::AppendDefines(std::set<BT<std::string>>& defines,
+ std::string const& defines_list) const
{
// Short-circuit if there are no definitions.
- if (!defines_list) {
+ if (defines_list.empty()) {
return;
}
// Expand the list of definitions.
- std::vector<std::string> defines_vec;
- cmSystemTools::ExpandListArgument(defines_list, defines_vec);
- this->AppendDefines(defines, defines_vec);
+ this->AppendDefines(defines, ExpandListWithBacktrace(defines_list));
}
void cmLocalGenerator::AppendDefines(
- std::set<std::string>& defines,
- const std::vector<std::string>& defines_vec) const
+ std::set<BT<std::string>>& defines,
+ const std::vector<BT<std::string>>& defines_vec) const
{
- for (std::vector<std::string>::const_iterator di = defines_vec.begin();
- di != defines_vec.end(); ++di) {
+ for (BT<std::string> const& d : defines_vec) {
// Skip unsupported definitions.
- if (!this->CheckDefinition(*di)) {
+ if (!this->CheckDefinition(d.Value)) {
continue;
}
- defines.insert(*di);
+ defines.insert(d);
}
}
@@ -1928,11 +2353,8 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
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) {
+ for (std::string const& define : defines) {
// Append the definition with proper escaping.
std::string def = dflag;
if (this->GetState()->UseWatcomWMake()) {
@@ -1946,7 +2368,7 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
// 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) {
+ for (const char* c = define.c_str(); *c; ++c) {
if (*c == '$' || *c == '#') {
def += '$';
}
@@ -1955,11 +2377,11 @@ void cmLocalGenerator::JoinDefines(const std::set<std::string>& defines,
} else {
// Make the definition appear properly on the command line. Use
// -DNAME="value" instead of -D"NAME=value" for historical reasons.
- std::string::size_type eq = defineIt->find("=");
- def += defineIt->substr(0, eq);
+ std::string::size_type eq = define.find('=');
+ def += define.substr(0, eq);
if (eq != std::string::npos) {
def += "=";
- def += this->EscapeForShell(defineIt->c_str() + eq + 1, true);
+ def += this->EscapeForShell(define.substr(eq + 1), true);
}
}
definesString += itemSeparator;
@@ -1979,9 +2401,8 @@ void cmLocalGenerator::AppendFeatureOptions(std::string& flags,
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);
+ for (std::string const& o : options) {
+ this->AppendFlagEscape(flags, o);
}
}
}
@@ -2003,7 +2424,7 @@ const char* cmLocalGenerator::GetFeature(const std::string& feature,
}
snp = snp.GetBuildsystemDirectoryParent();
}
- return CM_NULLPTR;
+ return nullptr;
}
std::string cmLocalGenerator::GetProjectName() const
@@ -2025,10 +2446,9 @@ std::string cmLocalGenerator::ConstructComment(
comment = "Generating ";
const char* sep = "";
std::string currentBinaryDir = this->GetCurrentBinaryDirectory();
- for (std::vector<std::string>::const_iterator o = ccg.GetOutputs().begin();
- o != ccg.GetOutputs().end(); ++o) {
+ for (std::string const& o : ccg.GetOutputs()) {
comment += sep;
- comment += this->ConvertToRelativePath(currentBinaryDir, *o);
+ comment += this->MaybeConvertToRelativePath(currentBinaryDir, o);
sep = ", ";
}
return comment;
@@ -2058,37 +2478,36 @@ void cmLocalGenerator::GenerateTargetInstallRules(
{
// Convert the old-style install specification from each target to
// an install generator and run it.
- std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); ++l) {
- if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
+ for (cmGeneratorTarget* l : tgts) {
+ if (l->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
// Include the user-specified pre-install script for this target.
- if (const char* preinstall = (*l)->GetProperty("PRE_INSTALL_SCRIPT")) {
- cmInstallScriptGenerator g(preinstall, false, CM_NULLPTR, false);
+ if (const char* preinstall = l->GetProperty("PRE_INSTALL_SCRIPT")) {
+ cmInstallScriptGenerator g(preinstall, false, nullptr, false);
g.Generate(os, config, configurationTypes);
}
// Install this target if a destination is given.
- if ((*l)->Target->GetInstallPath() != "") {
+ if (!l->Target->GetInstallPath().empty()) {
// 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)->Target->GetInstallPath().substr(1);
+ std::string destination = l->Target->GetInstallPath().substr(1);
cmSystemTools::ConvertToUnixSlashes(destination);
if (destination.empty()) {
destination = ".";
}
// Generate the proper install generator for this target type.
- switch ((*l)->GetType()) {
+ switch (l->GetType()) {
case cmStateEnums::EXECUTABLE:
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::MODULE_LIBRARY: {
// Use a target install generator.
- cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
+ cmInstallTargetGeneratorLocal g(this, l->GetName(),
destination.c_str(), false);
g.Generate(os, config, configurationTypes);
} break;
@@ -2097,18 +2516,18 @@ void cmLocalGenerator::GenerateTargetInstallRules(
// Special code to handle DLL. Install the import library
// to the normal destination and the DLL to the runtime
// destination.
- cmInstallTargetGeneratorLocal g1(this, (*l)->GetName(),
+ cmInstallTargetGeneratorLocal g1(this, l->GetName(),
destination.c_str(), true);
g1.Generate(os, config, configurationTypes);
// We also skip over the leading slash given by the user.
- destination = (*l)->Target->GetRuntimeInstallPath().substr(1);
+ destination = l->Target->GetRuntimeInstallPath().substr(1);
cmSystemTools::ConvertToUnixSlashes(destination);
- cmInstallTargetGeneratorLocal g2(this, (*l)->GetName(),
+ cmInstallTargetGeneratorLocal g2(this, l->GetName(),
destination.c_str(), false);
g2.Generate(os, config, configurationTypes);
#else
// Use a target install generator.
- cmInstallTargetGeneratorLocal g(this, (*l)->GetName(),
+ cmInstallTargetGeneratorLocal g(this, l->GetName(),
destination.c_str(), false);
g.Generate(os, config, configurationTypes);
#endif
@@ -2119,8 +2538,8 @@ void cmLocalGenerator::GenerateTargetInstallRules(
}
// Include the user-specified post-install script for this target.
- if (const char* postinstall = (*l)->GetProperty("POST_INSTALL_SCRIPT")) {
- cmInstallScriptGenerator g(postinstall, false, CM_NULLPTR, false);
+ if (const char* postinstall = l->GetProperty("POST_INSTALL_SCRIPT")) {
+ cmInstallScriptGenerator g(postinstall, false, nullptr, false);
g.Generate(os, config, configurationTypes);
}
}
@@ -2235,7 +2654,7 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(
<< "cannot be safely placed under this directory. "
<< "The build may not work correctly.";
/* clang-format on */
- this->IssueMessage(cmake::WARNING, m.str());
+ this->IssueMessage(MessageType::WARNING, m.str());
}
}
#else
@@ -2286,17 +2705,17 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
std::string const& fullPath = source.GetFullPath();
// Try referencing the source relative to the source tree.
- std::string relFromSource =
- this->ConvertToRelativePath(this->GetCurrentSourceDirectory(), fullPath);
+ std::string relFromSource = this->MaybeConvertToRelativePath(
+ this->GetCurrentSourceDirectory(), fullPath);
assert(!relFromSource.empty());
- bool relSource = !cmSystemTools::FileIsFullPath(relFromSource.c_str());
+ bool relSource = !cmSystemTools::FileIsFullPath(relFromSource);
bool subSource = relSource && relFromSource[0] != '.';
// Try referencing the source relative to the binary tree.
- std::string relFromBinary =
- this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), fullPath);
+ std::string relFromBinary = this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), fullPath);
assert(!relFromBinary.empty());
- bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary.c_str());
+ bool relBinary = !cmSystemTools::FileIsFullPath(relFromBinary);
bool subBinary = relBinary && relFromBinary[0] != '.';
// Select a nice-looking reference to the source file to construct
@@ -2315,7 +2734,7 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget(
// 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 (cmSystemTools::FileIsFullPath(objectName)) {
if (this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) {
objectName = cmSystemTools::GetFilenameName(source.GetFullPath());
}
@@ -2373,26 +2792,33 @@ cmake* cmLocalGenerator::GetCMakeInstance() const
return this->GlobalGenerator->GetCMakeInstance();
}
-const char* cmLocalGenerator::GetSourceDirectory() const
+std::string const& cmLocalGenerator::GetSourceDirectory() const
{
return this->GetCMakeInstance()->GetHomeDirectory();
}
-const char* cmLocalGenerator::GetBinaryDirectory() const
+std::string const& cmLocalGenerator::GetBinaryDirectory() const
{
return this->GetCMakeInstance()->GetHomeOutputDirectory();
}
-const char* cmLocalGenerator::GetCurrentBinaryDirectory() const
+std::string const& cmLocalGenerator::GetCurrentBinaryDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentBinary();
}
-const char* cmLocalGenerator::GetCurrentSourceDirectory() const
+std::string const& cmLocalGenerator::GetCurrentSourceDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentSource();
}
+std::string cmLocalGenerator::MaybeConvertToRelativePath(
+ std::string const& local_path, std::string const& remote_path) const
+{
+ return this->StateSnapshot.GetDirectory().ConvertToRelPathIfNotContained(
+ local_path, remote_path);
+}
+
std::string cmLocalGenerator::GetTargetDirectory(
const cmGeneratorTarget* /*unused*/) const
{
@@ -2479,7 +2905,7 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
<< "CMake is dropping a preprocessor definition: " << define << "\n"
<< "Consider defining the macro in a (configured) header file.\n";
/* clang-format on */
- cmSystemTools::Message(e.str().c_str());
+ cmSystemTools::Message(e.str());
return false;
}
}
@@ -2494,7 +2920,7 @@ bool cmLocalGenerator::CheckDefinition(std::string const& define) const
<< "CMake is dropping a preprocessor definition: " << define << "\n"
<< "Consider defining the macro in a (configured) header file.\n";
/* clang-format on */
- cmSystemTools::Message(e.str().c_str());
+ cmSystemTools::Message(e.str());
return false;
}
@@ -2512,22 +2938,22 @@ static void cmLGInfoProp(cmMakefile* mf, cmGeneratorTarget* target,
void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
const std::string& targetName,
- const char* fname)
+ const std::string& 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 (!cmSystemTools::FileIsFullPath(inFile)) {
+ std::string inMod = this->Makefile->GetModulesFile(inFile);
if (!inMod.empty()) {
inFile = inMod;
}
}
- if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
+ if (!cmSystemTools::FileExists(inFile, true)) {
std::ostringstream e;
e << "Target " << target->GetName() << " Info.plist template \"" << inFile
<< "\" could not be found.";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return;
}
@@ -2546,26 +2972,27 @@ void cmLocalGenerator::GenerateAppleInfoPList(cmGeneratorTarget* target,
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->ConfigureFile(inFile, fname, false, false, false);
}
void cmLocalGenerator::GenerateFrameworkInfoPList(
- cmGeneratorTarget* target, const std::string& targetName, const char* fname)
+ cmGeneratorTarget* target, const std::string& targetName,
+ const std::string& 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 (!cmSystemTools::FileIsFullPath(inFile)) {
+ std::string inMod = this->Makefile->GetModulesFile(inFile);
if (!inMod.empty()) {
inFile = inMod;
}
}
- if (!cmSystemTools::FileExists(inFile.c_str(), true)) {
+ if (!cmSystemTools::FileExists(inFile, true)) {
std::ostringstream e;
e << "Target " << target->GetName() << " Info.plist template \"" << inFile
<< "\" could not be found.";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return;
}
@@ -2580,5 +3007,5 @@ void cmLocalGenerator::GenerateFrameworkInfoPList(
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->ConfigureFile(inFile, fname, false, false, false);
}
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index 9f78be465..f0c6806fb 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -3,20 +3,21 @@
#ifndef cmLocalGenerator_h
#define cmLocalGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cm_kwiml.h"
#include <iosfwd>
#include <map>
#include <set>
#include <string>
+#include <unordered_map>
#include <vector>
#include "cmListFileCache.h"
+#include "cmMessageType.h"
#include "cmOutputConverter.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
-#include "cmake.h"
class cmComputeLinkInformation;
class cmCustomCommandGenerator;
@@ -27,6 +28,7 @@ class cmMakefile;
class cmRulePlaceholderExpander;
class cmSourceFile;
class cmState;
+class cmake;
/** \class cmLocalGenerator
* \brief Create required build files for a directory.
@@ -74,13 +76,13 @@ public:
bool IsRootMakefile() const;
- ///! Get the makefile for this generator
+ //! Get the makefile for this generator
cmMakefile* GetMakefile() { return this->Makefile; }
- ///! Get the makefile for this generator, const version
+ //! Get the makefile for this generator, const version
const cmMakefile* GetMakefile() const { return this->Makefile; }
- ///! Get the GlobalGenerator this is associated with
+ //! Get the GlobalGenerator this is associated with
cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
const cmGlobalGenerator* GetGlobalGenerator() const
{
@@ -116,15 +118,20 @@ public:
void AddCompilerRequirementFlag(std::string& flags,
cmGeneratorTarget const* target,
const std::string& lang);
- ///! Append flags to a string.
- virtual void AppendFlags(std::string& flags, const std::string& newFlags);
- virtual void AppendFlags(std::string& flags, const char* newFlags);
+ //! Append flags to a string.
+ virtual void AppendFlags(std::string& flags,
+ const std::string& newFlags) const;
+ virtual void AppendFlags(std::string& flags, const char* newFlags) const;
virtual void AppendFlagEscape(std::string& flags,
- const std::string& rawFlag);
+ const std::string& rawFlag) const;
void AppendIPOLinkerFlags(std::string& flags, cmGeneratorTarget* target,
const std::string& config,
const std::string& lang);
- ///! Get the include flags for the current makefile and language
+ void AppendPositionIndependentLinkerFlags(std::string& flags,
+ cmGeneratorTarget* target,
+ const std::string& config,
+ const std::string& lang);
+ //! 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,
@@ -137,11 +144,6 @@ public:
return this->GeneratorTargets;
}
- const std::vector<cmGeneratorTarget*>& GetImportedGeneratorTargets() const
- {
- return this->ImportedGeneratorTargets;
- }
-
void AddGeneratorTarget(cmGeneratorTarget* gt);
void AddImportedGeneratorTarget(cmGeneratorTarget* gt);
void AddOwnedImportedGeneratorTarget(cmGeneratorTarget* gt);
@@ -151,18 +153,48 @@ public:
cmGeneratorTarget* FindGeneratorTargetToUse(const std::string& name) const;
/**
+ * Process a list of include directories
+ */
+ void AppendIncludeDirectories(std::vector<std::string>& includes,
+ const char* includes_list,
+ const cmSourceFile& sourceFile) const;
+ void AppendIncludeDirectories(std::vector<std::string>& includes,
+ std::string const& includes_list,
+ const cmSourceFile& sourceFile) const
+ {
+ this->AppendIncludeDirectories(includes, includes_list.c_str(),
+ sourceFile);
+ }
+ void AppendIncludeDirectories(std::vector<std::string>& includes,
+ const std::vector<std::string>& includes_vec,
+ const cmSourceFile& sourceFile) const;
+
+ /**
* Encode a list of preprocessor definitions for the compiler
* command line.
*/
void AppendDefines(std::set<std::string>& defines,
- const char* defines_list) const;
- void AppendDefines(std::set<std::string>& defines,
- std::string const& defines_list) const
+ std::string const& defines_list) const;
+ void AppendDefines(std::set<BT<std::string>>& defines,
+ std::string const& defines_list) const;
+ void AppendDefines(std::set<BT<std::string>>& defines,
+ const std::vector<BT<std::string>>& defines_vec) const;
+
+ /**
+ * Encode a list of compile options for the compiler
+ * command line.
+ */
+ void AppendCompileOptions(std::string& options, const char* options_list,
+ const char* regex = nullptr) const;
+ void AppendCompileOptions(std::string& options,
+ std::string const& options_list,
+ const char* regex = nullptr) const
{
- this->AppendDefines(defines, defines_list.c_str());
+ this->AppendCompileOptions(options, options_list.c_str(), regex);
}
- void AppendDefines(std::set<std::string>& defines,
- const std::vector<std::string>& defines_vec) const;
+ void AppendCompileOptions(std::string& options,
+ const std::vector<std::string>& options_vec,
+ const char* regex = nullptr) const;
/**
* Join a set of defines into a definesString with a space separator.
@@ -201,24 +233,54 @@ public:
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*/)
+ virtual bool UpdateDependencies(const std::string& /* tgtInfo */,
+ bool /*verbose*/, bool /*color*/)
{
return true;
}
- /** Get the include flags for the current makefile and language. */
+ /** @brief Get the include directories for the current makefile and language
+ * and optional the compiler implicit include directories.
+ *
+ * @arg stripImplicitDirs Strip all directories found in
+ * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES from the result.
+ * @arg appendAllImplicitDirs Append all directories found in
+ * CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES to the result.
+ */
+ std::vector<BT<std::string>> GetIncludeDirectoriesImplicit(
+ cmGeneratorTarget const* target, std::string const& lang = "C",
+ std::string const& config = "", bool stripImplicitDirs = true,
+ bool appendAllImplicitDirs = false) const;
+
+ /** @brief Get the include directories for the current makefile and language
+ * and optional the compiler implicit include directories.
+ *
+ * @arg dirs Directories are appended to this list
+ */
+ void GetIncludeDirectoriesImplicit(std::vector<std::string>& dirs,
+ cmGeneratorTarget const* target,
+ const std::string& lang = "C",
+ const std::string& config = "",
+ bool stripImplicitDirs = true,
+ bool appendAllImplicitDirs = false) const;
+
+ /** @brief Get the include directories for the current makefile and language.
+ * @arg dirs Include directories are appended to this list
+ */
void GetIncludeDirectories(std::vector<std::string>& dirs,
cmGeneratorTarget const* target,
const std::string& lang = "C",
- const std::string& config = "",
- bool stripImplicitInclDirs = true) const;
+ const std::string& config = "") const;
+
+ /** @brief Get the include directories for the current makefile and language.
+ * @return The include directory list
+ */
+ std::vector<BT<std::string>> GetIncludeDirectories(
+ cmGeneratorTarget const* target, std::string const& lang = "C",
+ std::string const& config = "") const;
+
void AddCompileOptions(std::string& flags, cmGeneratorTarget* target,
const std::string& lang, const std::string& config);
- void AddCompileDefinitions(std::set<std::string>& defines,
- cmGeneratorTarget const* target,
- const std::string& config,
- const std::string& lang) const;
std::string GetProjectName() const;
@@ -257,36 +319,47 @@ public:
cmake* GetCMakeInstance() const;
- const char* GetSourceDirectory() const;
- const char* GetBinaryDirectory() const;
+ std::string const& GetSourceDirectory() const;
+ std::string const& GetBinaryDirectory() const;
- const char* GetCurrentBinaryDirectory() const;
- const char* GetCurrentSourceDirectory() const;
+ std::string const& GetCurrentBinaryDirectory() const;
+ std::string const& GetCurrentSourceDirectory() const;
/**
- * Generate a Mac OS X application bundle Info.plist file.
+ * Convert the given remote path to a relative path with respect to
+ * the given local path. Both paths must use forward slashes and not
+ * already be escaped or quoted.
+ * The conversion is skipped if the paths are not both in the source
+ * or both in the binary tree.
+ */
+ std::string MaybeConvertToRelativePath(std::string const& local_path,
+ std::string const& remote_path) const;
+
+ /**
+ * Generate a macOS application bundle Info.plist file.
*/
void GenerateAppleInfoPList(cmGeneratorTarget* target,
const std::string& targetName,
- const char* fname);
+ const std::string& fname);
/**
- * Generate a Mac OS X framework Info.plist file.
+ * Generate a macOS framework Info.plist file.
*/
void GenerateFrameworkInfoPList(cmGeneratorTarget* target,
const std::string& targetName,
- const char* fname);
+ const std::string& 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 = CM_NULLPTR,
- char const* customOutputExtension = CM_NULLPTR);
+ bool* hasSourceExtension = nullptr,
+ char const* customOutputExtension = nullptr);
/** Fill out the static linker flags for the given target. */
void GetStaticLibraryFlags(std::string& flags, std::string const& config,
+ std::string const& linkLanguage,
cmGeneratorTarget* target);
/** Fill out these strings for the given target. Libraries to link,
@@ -299,6 +372,9 @@ public:
void GetTargetDefines(cmGeneratorTarget const* target,
std::string const& config, std::string const& lang,
std::set<std::string>& defines) const;
+ std::set<BT<std::string>> GetTargetDefines(cmGeneratorTarget const* target,
+ std::string const& config,
+ std::string const& lang) const;
void GetTargetCompileFlags(cmGeneratorTarget* target,
std::string const& config,
std::string const& lang, std::string& flags);
@@ -311,14 +387,14 @@ public:
virtual void ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
- cmGeneratorTarget const* gt = CM_NULLPTR);
+ cmGeneratorTarget const* gt = nullptr);
bool IsWindowsShell() const;
bool IsWatcomWMake() const;
bool IsMinGWMake() const;
bool IsNMake() const;
- void IssueMessage(cmake::MessageType t, std::string const& text) const;
+ void IssueMessage(MessageType t, std::string const& text) const;
void CreateEvaluationFileOutputs(const std::string& config);
void ProcessEvaluationFiles(std::vector<std::string>& generatedFiles);
@@ -327,7 +403,7 @@ public:
const std::string& prop);
protected:
- ///! put all the libraries for a target on into the given stream
+ //! put all the libraries for a target on into the given stream
void OutputLinkLibraries(cmComputeLinkInformation* pcli,
cmLinkLineComputer* linkLineComputer,
std::string& linkLibraries,
@@ -353,9 +429,15 @@ protected:
std::string::size_type ObjectPathMax;
std::set<std::string> ObjectMaxPathViolations;
- std::set<cmGeneratorTarget const*> WarnCMP0063;
+ std::set<std::string> EnvCPATH;
+
+ typedef std::unordered_map<std::string, cmGeneratorTarget*>
+ GeneratorTargetMap;
+ GeneratorTargetMap GeneratorTargetSearchIndex;
std::vector<cmGeneratorTarget*> GeneratorTargets;
- std::vector<cmGeneratorTarget*> ImportedGeneratorTargets;
+
+ std::set<cmGeneratorTarget const*> WarnCMP0063;
+ GeneratorTargetMap ImportedGeneratorTargets;
std::vector<cmGeneratorTarget*> OwnedImportedGeneratorTargets;
std::map<std::string, std::string> AliasTargets;
diff --git a/Source/cmLocalGhsMultiGenerator.cxx b/Source/cmLocalGhsMultiGenerator.cxx
index 5f37af528..bf25f98ea 100644
--- a/Source/cmLocalGhsMultiGenerator.cxx
+++ b/Source/cmLocalGhsMultiGenerator.cxx
@@ -2,11 +2,15 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLocalGhsMultiGenerator.h"
-#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmGhsMultiTargetGenerator.h"
-#include "cmGlobalGhsMultiGenerator.h"
-#include "cmMakefile.h"
+#include "cmGlobalGenerator.h"
+#include "cmSourceFile.h"
+#include "cmStateTypes.h"
+#include "cmSystemTools.h"
+
+#include <algorithm>
+#include <utility>
cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg,
cmMakefile* mf)
@@ -14,20 +18,84 @@ cmLocalGhsMultiGenerator::cmLocalGhsMultiGenerator(cmGlobalGenerator* gg,
{
}
-cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator()
+cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() = default;
+
+std::string cmLocalGhsMultiGenerator::GetTargetDirectory(
+ cmGeneratorTarget const* target) const
{
+ std::string dir;
+ dir += target->GetName();
+ dir += ".dir";
+ return dir;
+}
+
+void cmLocalGhsMultiGenerator::GenerateTargetsDepthFirst(
+ cmGeneratorTarget* target, std::vector<cmGeneratorTarget*>& remaining)
+{
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ return;
+ }
+ // Find this target in the list of remaining targets.
+ auto it = std::find(remaining.begin(), remaining.end(), target);
+ if (it == remaining.end()) {
+ // This target was already handled.
+ return;
+ }
+ // Remove this target from the list of remaining targets because
+ // we are handling it now.
+ *it = nullptr;
+
+ cmGhsMultiTargetGenerator tg(target);
+ tg.Generate();
}
void cmLocalGhsMultiGenerator::Generate()
{
- std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+ std::vector<cmGeneratorTarget*> remaining = this->GetGeneratorTargets();
+ for (auto& t : remaining) {
+ if (t) {
+ GenerateTargetsDepthFirst(t, remaining);
+ }
+ }
+}
+
+void cmLocalGhsMultiGenerator::ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt)
+{
+ std::string dir_max;
+ dir_max += this->GetCurrentBinaryDirectory();
+ dir_max += "/";
+ dir_max += this->GetTargetDirectory(gt);
+ dir_max += "/";
+
+ // Count the number of object files with each name. Note that
+ // filesystem may not be case sensitive.
+ std::map<std::string, int> counts;
+
+ for (auto const& si : mapping) {
+ cmSourceFile const* sf = si.first;
+ std::string objectNameLower = cmSystemTools::LowerCase(
+ cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
+ objectNameLower += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
+ counts[objectNameLower] += 1;
+ }
+
+ // For all source files producing duplicate names we need unique
+ // object name computation.
+ for (auto& si : mapping) {
+ cmSourceFile const* sf = si.first;
+ std::string objectName =
+ cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
+ objectName += this->GlobalGenerator->GetLanguageOutputExtension(*sf);
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); ++l) {
- if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
- continue;
+ if (counts[cmSystemTools::LowerCase(objectName)] > 1) {
+ const_cast<cmGeneratorTarget*>(gt)->AddExplicitObjectName(sf);
+ bool keptSourceExtension;
+ objectName = this->GetObjectFileNameWithoutTarget(*sf, dir_max,
+ &keptSourceExtension);
+ cmsys::SystemTools::ReplaceString(objectName, "/", "_");
}
- cmGhsMultiTargetGenerator tg(*l);
- tg.Generate();
+ si.second = objectName;
}
}
diff --git a/Source/cmLocalGhsMultiGenerator.h b/Source/cmLocalGhsMultiGenerator.h
index aa842d74b..b6ccd0815 100644
--- a/Source/cmLocalGhsMultiGenerator.h
+++ b/Source/cmLocalGhsMultiGenerator.h
@@ -5,7 +5,14 @@
#include "cmLocalGenerator.h"
-class cmGeneratedFileStream;
+#include <map>
+#include <string>
+#include <vector>
+
+class cmGeneratorTarget;
+class cmGlobalGenerator;
+class cmMakefile;
+class cmSourceFile;
/** \class cmLocalGhsMultiGenerator
* \brief Write Green Hills MULTI project files.
@@ -18,12 +25,23 @@ class cmLocalGhsMultiGenerator : public cmLocalGenerator
public:
cmLocalGhsMultiGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
- virtual ~cmLocalGhsMultiGenerator();
+ ~cmLocalGhsMultiGenerator() override;
/**
* Generate the makefile for this directory.
*/
- virtual void Generate();
+ void Generate() override;
+
+ std::string GetTargetDirectory(
+ cmGeneratorTarget const* target) const override;
+
+ void ComputeObjectFilenames(
+ std::map<cmSourceFile const*, std::string>& mapping,
+ cmGeneratorTarget const* gt = nullptr) override;
+
+private:
+ void GenerateTargetsDepthFirst(cmGeneratorTarget* target,
+ std::vector<cmGeneratorTarget*>& remaining);
};
#endif
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx
index 266710cb1..90666fc18 100644
--- a/Source/cmLocalNinjaGenerator.cxx
+++ b/Source/cmLocalNinjaGenerator.cxx
@@ -5,16 +5,20 @@
#include <algorithm>
#include <assert.h>
#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <utility>
+#include "cmCryptoHash.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmGeneratedFileStream.h"
+#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmGlobalNinjaGenerator.h"
+#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmNinjaTargetGenerator.h"
#include "cmRulePlaceholderExpander.h"
@@ -22,8 +26,8 @@
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
+#include "cmsys/FStream.hxx"
cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
cmMakefile* mf)
@@ -38,24 +42,21 @@ cmRulePlaceholderExpander*
cmLocalNinjaGenerator::CreateRulePlaceholderExpander() const
{
cmRulePlaceholderExpander* ret =
- new cmRulePlaceholderExpander(this->Compilers, this->VariableMappings,
- this->CompilerSysroot, this->LinkerSysroot);
+ this->cmLocalGenerator::CreateRulePlaceholderExpander();
ret->SetTargetImpLib("$TARGET_IMPLIB");
return ret;
}
-cmLocalNinjaGenerator::~cmLocalNinjaGenerator()
-{
-}
+cmLocalNinjaGenerator::~cmLocalNinjaGenerator() = default;
void cmLocalNinjaGenerator::Generate()
{
// Compute the path to use when referencing the current output
// directory from the top output directory.
- this->HomeRelativeOutputPath = this->ConvertToRelativePath(
+ this->HomeRelativeOutputPath = this->MaybeConvertToRelativePath(
this->GetBinaryDirectory(), this->GetCurrentBinaryDirectory());
if (this->HomeRelativeOutputPath == ".") {
- this->HomeRelativeOutputPath = "";
+ this->HomeRelativeOutputPath.clear();
}
this->WriteProcessedMakefile(this->GetBuildFileStream());
@@ -69,42 +70,41 @@ void cmLocalNinjaGenerator::Generate()
this->WritePools(this->GetRulesFileStream());
- const std::string showIncludesPrefix =
+ 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";
+ this->GetRulesFileStream()
+ << "msvc_deps_prefix = " << showIncludesPrefix << "\n\n";
}
}
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (cmGeneratorTarget* target : this->GetGeneratorTargets()) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(*t);
+ auto tg = cmNinjaTargetGenerator::New(target);
if (tg) {
tg->Generate();
// Add the target to "all" if required.
if (!this->GetGlobalNinjaGenerator()->IsExcluded(
- this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0], *t)) {
- this->GetGlobalNinjaGenerator()->AddDependencyToAll(*t);
+ this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
+ target)) {
+ this->GetGlobalNinjaGenerator()->AddDependencyToAll(target);
}
- delete tg;
}
}
this->WriteCustomCommandBuildStatements();
+ this->AdditionalCleanFiles();
}
// TODO: Picked up from cmLocalUnixMakefileGenerator3. Refactor it.
std::string cmLocalNinjaGenerator::GetTargetDirectory(
cmGeneratorTarget const* target) const
{
- std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::string dir = "CMakeFiles/";
dir += target->GetName();
#if defined(__VMS)
dir += "_dir";
@@ -139,7 +139,8 @@ std::string cmLocalNinjaGenerator::ConvertToIncludeReference(
format);
}
return this->ConvertToOutputFormat(
- this->ConvertToRelativePath(this->GetBinaryDirectory(), path), format);
+ this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), path),
+ format);
}
// Private methods.
@@ -186,13 +187,22 @@ void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os)
void cmLocalNinjaGenerator::WriteNinjaRequiredVersion(std::ostream& os)
{
// Default required version
- std::string requiredVersion =
- this->GetGlobalNinjaGenerator()->RequiredNinjaVersion();
+ std::string requiredVersion = cmGlobalNinjaGenerator::RequiredNinjaVersion();
// Ninja generator uses the 'console' pool if available (>= 1.5)
if (this->GetGlobalNinjaGenerator()->SupportsConsolePool()) {
requiredVersion =
- this->GetGlobalNinjaGenerator()->RequiredNinjaVersionForConsolePool();
+ cmGlobalNinjaGenerator::RequiredNinjaVersionForConsolePool();
+ }
+
+ // The Ninja generator writes rules which require support for restat
+ // when rebuilding build.ninja manifest (>= 1.8)
+ if (this->GetGlobalNinjaGenerator()->SupportsManifestRestat() &&
+ this->GetCMakeInstance()->DoWriteGlobVerifyTarget() &&
+ !this->GetGlobalNinjaGenerator()->GlobalSettingIsOn(
+ "CMAKE_SUPPRESS_REGENERATION")) {
+ requiredVersion =
+ cmGlobalNinjaGenerator::RequiredNinjaVersionForManifestRestat();
}
cmGlobalNinjaGenerator::WriteComment(
@@ -207,13 +217,15 @@ void cmLocalNinjaGenerator::WritePools(std::ostream& os)
const char* jobpools =
this->GetCMakeInstance()->GetState()->GetGlobalProperty("JOB_POOLS");
+ if (!jobpools) {
+ jobpools = this->GetMakefile()->GetDefinition("CMAKE_JOB_POOLS");
+ }
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) {
- std::string const& pool = pools[i];
+ for (std::string const& pool : pools) {
const std::string::size_type eq = pool.find('=');
unsigned int jobs;
if (eq != std::string::npos &&
@@ -222,8 +234,8 @@ void cmLocalNinjaGenerator::WritePools(std::ostream& os)
os << " depth = " << jobs << std::endl;
os << std::endl;
} else {
- cmSystemTools::Error("Invalid pool defined by property 'JOB_POOLS': ",
- pool.c_str());
+ cmSystemTools::Error("Invalid pool defined by property 'JOB_POOLS': " +
+ pool);
}
}
}
@@ -237,29 +249,12 @@ void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os)
cmGlobalNinjaGenerator* ng = this->GetGlobalNinjaGenerator();
std::string const ninjaRulesFile =
ng->NinjaOutputPath(cmGlobalNinjaGenerator::NINJA_RULES_FILE);
- std::string const rulesFilePath =
- ng->EncodeIdent(ng->EncodePath(ninjaRulesFile), os);
+ std::string const rulesFilePath = ng->EncodePath(ninjaRulesFile);
cmGlobalNinjaGenerator::WriteInclude(os, rulesFilePath,
"Include rules file.");
os << "\n";
}
-void cmLocalNinjaGenerator::ComputeObjectFilenames(
- std::map<cmSourceFile const*, std::string>& mapping,
- cmGeneratorTarget const* gt)
-{
- // Determine if these object files should use a custom extension
- char const* custom_ext = gt->GetCustomObjectExtension();
- for (std::map<cmSourceFile const*, std::string>::iterator si =
- mapping.begin();
- si != mapping.end(); ++si) {
- cmSourceFile const* sf = si->first;
- bool keptSourceExtension;
- si->second = this->GetObjectFileNameWithoutTarget(
- *sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
- }
-}
-
void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os)
{
cmGlobalNinjaGenerator::WriteDivider(os);
@@ -290,19 +285,73 @@ void cmLocalNinjaGenerator::AppendTargetDepends(cmGeneratorTarget* target,
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) {
+ for (std::string const& i : ccg.GetDepends()) {
std::string dep;
- if (this->GetRealDependency(*i, this->GetConfigName(), dep)) {
+ if (this->GetRealDependency(i, this->GetConfigName(), dep)) {
ninjaDeps.push_back(
this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(dep));
}
}
}
+std::string cmLocalNinjaGenerator::WriteCommandScript(
+ std::vector<std::string> const& cmdLines, std::string const& customStep,
+ cmGeneratorTarget const* target) const
+{
+ std::string scriptPath;
+ if (target) {
+ scriptPath = target->GetSupportDirectory();
+ } else {
+ scriptPath = this->GetCurrentBinaryDirectory();
+ scriptPath += "/CMakeFiles";
+ }
+ cmSystemTools::MakeDirectory(scriptPath);
+ scriptPath += '/';
+ scriptPath += customStep;
+#ifdef _WIN32
+ scriptPath += ".bat";
+#else
+ scriptPath += ".sh";
+#endif
+
+ cmsys::ofstream script(scriptPath.c_str());
+
+#ifdef _WIN32
+ script << "@echo off\n";
+ int line = 1;
+#else
+ script << "set -e\n\n";
+#endif
+
+ for (auto const& i : cmdLines) {
+ std::string cmd = i;
+ // The command line was built assuming it would be written to
+ // the build.ninja file, so it uses '$$' for '$'. Remove this
+ // for the raw shell script.
+ cmSystemTools::ReplaceString(cmd, "$$", "$");
+#ifdef _WIN32
+ script << cmd << " || (set FAIL_LINE=" << ++line << "& goto :ABORT)"
+ << '\n';
+#else
+ script << cmd << '\n';
+#endif
+ }
+
+#ifdef _WIN32
+ script << "goto :EOF\n\n"
+ ":ABORT\n"
+ "set ERROR_CODE=%ERRORLEVEL%\n"
+ "echo Batch file failed at line %FAIL_LINE% "
+ "with errorcode %ERRORLEVEL%\n"
+ "exit /b %ERROR_CODE%";
+#endif
+
+ return scriptPath;
+}
+
std::string cmLocalNinjaGenerator::BuildCommandLine(
- const std::vector<std::string>& cmdLines)
+ std::vector<std::string> const& cmdLines, std::string const& customStep,
+ cmGeneratorTarget const* target) const
{
// If we have no commands but we need to build a command anyway, use noop.
// This happens when building a POST_BUILD value for link targets that
@@ -311,6 +360,35 @@ std::string cmLocalNinjaGenerator::BuildCommandLine(
return cmGlobalNinjaGenerator::SHELL_NOOP;
}
+ // If this is a custom step then we will have no '$VAR' ninja placeholders.
+ // This means we can deal with long command sequences by writing to a script.
+ // Do this if the command lines are on the scale of the OS limit.
+ if (!customStep.empty()) {
+ size_t cmdLinesTotal = 0;
+ for (std::string const& cmd : cmdLines) {
+ cmdLinesTotal += cmd.length() + 6;
+ }
+ if (cmdLinesTotal > cmSystemTools::CalculateCommandLineLengthLimit() / 2) {
+ std::string const scriptPath =
+ this->WriteCommandScript(cmdLines, customStep, target);
+ std::string cmd
+#ifndef _WIN32
+ = "/bin/sh "
+#endif
+ ;
+ cmd += this->ConvertToOutputFormat(
+ this->GetGlobalNinjaGenerator()->ConvertToNinjaPath(scriptPath),
+ cmOutputConverter::SHELL);
+
+ // Add an unused argument based on script content so that Ninja
+ // knows when the command lines change.
+ cmd += " ";
+ cmCryptoHash hash(cmCryptoHash::AlgoSHA256);
+ cmd += hash.HashFile(scriptPath).substr(0, 16);
+ return cmd;
+ }
+ }
+
std::ostringstream cmd;
for (std::vector<std::string>::const_iterator li = cmdLines.begin();
li != cmdLines.end(); ++li)
@@ -378,7 +456,8 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(
void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
cmCustomCommand const* cc, const cmNinjaDeps& orderOnlyDeps)
{
- if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc)) {
+ cmGlobalNinjaGenerator* gg = this->GetGlobalNinjaGenerator();
+ if (gg->SeenCustomCommand(cc)) {
return;
}
@@ -386,46 +465,56 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
const std::vector<std::string>& outputs = ccg.GetOutputs();
const std::vector<std::string>& byproducts = ccg.GetByproducts();
- cmNinjaDeps ninjaOutputs(outputs.size() + byproducts.size()), ninjaDeps;
bool symbolic = false;
- for (std::vector<std::string>::const_iterator o = outputs.begin();
- !symbolic && o != outputs.end(); ++o) {
- if (cmSourceFile* sf = this->Makefile->GetSource(*o)) {
- symbolic = sf->GetPropertyAsBool("SYMBOLIC");
+ for (std::string const& output : outputs) {
+ if (cmSourceFile* sf = this->Makefile->GetSource(output)) {
+ if (sf->GetPropertyAsBool("SYMBOLIC")) {
+ symbolic = true;
+ break;
+ }
}
}
#if 0
-#error TODO: Once CC in an ExternalProject target must provide the \
+# error TODO: Once CC in an ExternalProject target must provide the \
file of each imported target that has an add_dependencies pointing \
at us. How to know which ExternalProject step actually provides it?
#endif
+ cmNinjaDeps ninjaOutputs(outputs.size() + byproducts.size());
std::transform(outputs.begin(), outputs.end(), ninjaOutputs.begin(),
- this->GetGlobalNinjaGenerator()->MapToNinjaPath());
+ gg->MapToNinjaPath());
std::transform(byproducts.begin(), byproducts.end(),
- ninjaOutputs.begin() + outputs.size(),
- this->GetGlobalNinjaGenerator()->MapToNinjaPath());
- this->AppendCustomCommandDeps(ccg, ninjaDeps);
+ ninjaOutputs.begin() + outputs.size(), gg->MapToNinjaPath());
- for (cmNinjaDeps::iterator i = ninjaOutputs.begin(); i != ninjaOutputs.end();
- ++i) {
- this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(*i);
+ for (std::string const& ninjaOutput : ninjaOutputs) {
+ gg->SeenCustomCommandOutput(ninjaOutput);
}
+ cmNinjaDeps ninjaDeps;
+ this->AppendCustomCommandDeps(ccg, ninjaDeps);
+
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());
+ cmNinjaBuild build("phony");
+ build.Comment = "Phony custom command for " + ninjaOutputs[0];
+ build.Outputs = std::move(ninjaOutputs);
+ build.ExplicitDeps = std::move(ninjaDeps);
+ build.OrderOnlyDeps = orderOnlyDeps;
+ gg->WriteBuild(this->GetBuildFileStream(), build);
} else {
- this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild(
- this->BuildCommandLine(cmdLines), this->ConstructComment(ccg),
- "Custom command for " + ninjaOutputs[0], cc->GetDepfile(),
- cc->GetUsesTerminal(),
+ std::string customStep = cmSystemTools::GetFilenameName(ninjaOutputs[0]);
+ // Hash full path to make unique.
+ customStep += '-';
+ cmCryptoHash hash(cmCryptoHash::AlgoSHA256);
+ customStep += hash.HashString(ninjaOutputs[0]).substr(0, 7);
+
+ gg->WriteCustomCommandBuild(
+ this->BuildCommandLine(cmdLines, customStep),
+ this->ConstructComment(ccg), "Custom command for " + ninjaOutputs[0],
+ cc->GetDepfile(), cc->GetJobPool(), cc->GetUsesTerminal(),
/*restat*/ !symbolic || !byproducts.empty(), ninjaOutputs, ninjaDeps,
orderOnlyDeps);
}
@@ -445,10 +534,9 @@ void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc,
void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements()
{
- for (std::vector<cmCustomCommand const*>::iterator vi =
- this->CustomCommands.begin();
- vi != this->CustomCommands.end(); ++vi) {
- CustomCommandTargetMap::iterator i = this->CustomCommandTargets.find(*vi);
+ for (cmCustomCommand const* customCommand : this->CustomCommands) {
+ CustomCommandTargetMap::iterator i =
+ this->CustomCommandTargets.find(customCommand);
assert(i != this->CustomCommandTargets.end());
// A custom command may appear on multiple targets. However, some build
@@ -492,8 +580,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
return std::string();
}
- // Expand rules in the empty string. It may insert the launcher and
- // perform replacements.
+ // Expand rule variables referenced in the given launcher command.
cmRulePlaceholderExpander::RuleVariables vars;
std::string output;
@@ -501,19 +588,17 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
if (!outputs.empty()) {
output = outputs[0];
if (ccg.GetWorkingDirectory().empty()) {
- output =
- this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), output);
+ output = this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), output);
}
output = this->ConvertToOutputFormat(output, cmOutputConverter::SHELL);
}
vars.Output = output.c_str();
- std::string launcher = property_value;
- launcher += " ";
-
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->CreateRulePlaceholderExpander());
+ std::string launcher = property_value;
rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars);
if (!launcher.empty()) {
launcher += " ";
@@ -521,3 +606,26 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
return launcher;
}
+
+void cmLocalNinjaGenerator::AdditionalCleanFiles()
+{
+ if (const char* prop_value =
+ this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
+ std::vector<std::string> cleanFiles;
+ {
+ cmGeneratorExpression ge;
+ auto cge = ge.Parse(prop_value);
+ cmSystemTools::ExpandListArgument(
+ cge->Evaluate(this,
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")),
+ cleanFiles);
+ }
+ std::string const& binaryDir = this->GetCurrentBinaryDirectory();
+ cmGlobalNinjaGenerator* gg = this->GetGlobalNinjaGenerator();
+ for (std::string const& cleanFile : cleanFiles) {
+ // Support relative paths
+ gg->AddAdditionalCleanFile(
+ cmSystemTools::CollapseFullPath(cleanFile, binaryDir));
+ }
+ }
+}
diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h
index a45e01851..3a30bbb7b 100644
--- a/Source/cmLocalNinjaGenerator.h
+++ b/Source/cmLocalNinjaGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmLocalNinjaGenerator_h
#define cmLocalNinjaGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
@@ -23,7 +23,6 @@ class cmGlobalGenerator;
class cmGlobalNinjaGenerator;
class cmMakefile;
class cmRulePlaceholderExpander;
-class cmSourceFile;
class cmake;
/**
@@ -38,14 +37,14 @@ class cmLocalNinjaGenerator : public cmLocalCommonGenerator
public:
cmLocalNinjaGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
- ~cmLocalNinjaGenerator() CM_OVERRIDE;
+ ~cmLocalNinjaGenerator() override;
- void Generate() CM_OVERRIDE;
+ void Generate() override;
- cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const CM_OVERRIDE;
+ cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const override;
- std::string GetTargetDirectory(cmGeneratorTarget const* target) const
- CM_OVERRIDE;
+ std::string GetTargetDirectory(
+ cmGeneratorTarget const* target) const override;
const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
@@ -60,7 +59,10 @@ public:
return this->HomeRelativeOutputPath;
}
- std::string BuildCommandLine(const std::vector<std::string>& cmdLines);
+ std::string BuildCommandLine(
+ std::vector<std::string> const& cmdLines,
+ std::string const& customStep = std::string(),
+ cmGeneratorTarget const* target = nullptr) const;
void AppendTargetOutputs(cmGeneratorTarget* target, cmNinjaDeps& outputs);
void AppendTargetDepends(
@@ -74,15 +76,11 @@ public:
void AppendCustomCommandDeps(cmCustomCommandGenerator const& ccg,
cmNinjaDeps& ninjaDeps);
- void ComputeObjectFilenames(
- std::map<cmSourceFile const*, std::string>& mapping,
- cmGeneratorTarget const* gt = CM_NULLPTR) CM_OVERRIDE;
-
protected:
std::string ConvertToIncludeReference(
std::string const& path,
cmOutputConverter::OutputFormat format = cmOutputConverter::SHELL,
- bool forceFullPaths = false) CM_OVERRIDE;
+ bool forceFullPaths = false) override;
private:
cmGeneratedFileStream& GetBuildFileStream() const;
@@ -103,9 +101,15 @@ private:
std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
+ std::string WriteCommandScript(std::vector<std::string> const& cmdLines,
+ std::string const& customStep,
+ cmGeneratorTarget const* target) const;
+
+ void AdditionalCleanFiles();
+
std::string HomeRelativeOutputPath;
- typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*> >
+ typedef std::map<cmCustomCommand const*, std::set<cmGeneratorTarget*>>
CustomCommandTargetMap;
CustomCommandTargetMap CustomCommandTargets;
std::vector<cmCustomCommand const*> CustomCommands;
diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx
index 9b9d22cf5..c392e9787 100644
--- a/Source/cmLocalUnixMakefileGenerator3.cxx
+++ b/Source/cmLocalUnixMakefileGenerator3.cxx
@@ -5,23 +5,26 @@
#include "cmsys/FStream.hxx"
#include "cmsys/Terminal.h"
#include <algorithm>
-#include <functional>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <utility>
#include "cmAlgorithms.h"
-#include "cmCustomCommand.h"
+#include "cmCustomCommand.h" // IWYU pragma: keep
#include "cmCustomCommandGenerator.h"
-#include "cmFileTimeComparison.h"
+#include "cmFileTimeCache.h"
#include "cmGeneratedFileStream.h"
+#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmMakefileTargetGenerator.h"
#include "cmOutputConverter.h"
+#include "cmRange.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
#include "cmState.h"
@@ -30,15 +33,14 @@
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.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 "cmDependsFortran.h"
+# include "cmDependsJava.h"
#endif
// Escape special characters in Makefile dependency lines
@@ -99,9 +101,7 @@ cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3(
this->BorlandMakeCurlyHack = false;
}
-cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3()
-{
-}
+cmLocalUnixMakefileGenerator3::~cmLocalUnixMakefileGenerator3() = default;
void cmLocalUnixMakefileGenerator3::Generate()
{
@@ -116,17 +116,15 @@ void cmLocalUnixMakefileGenerator3::Generate()
this->Makefile->IsOn("CMAKE_SKIP_ASSEMBLY_SOURCE_RULES");
// Generate the rule files for each target.
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
cmGlobalUnixMakefileGenerator3* gg =
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- if ((*t)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (cmGeneratorTarget* target : this->GetGeneratorTargets()) {
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- CM_AUTO_PTR<cmMakefileTargetGenerator> tg(
- cmMakefileTargetGenerator::New(*t));
- if (tg.get()) {
+ std::unique_ptr<cmMakefileTargetGenerator> tg(
+ cmMakefileTargetGenerator::New(target));
+ if (tg) {
tg->WriteRuleFiles();
gg->RecordTargetProgress(tg.get());
}
@@ -146,36 +144,17 @@ void cmLocalUnixMakefileGenerator3::ComputeHomeRelativeOutputPath()
this->HomeRelativeOutputPath = this->MaybeConvertToRelativePath(
this->GetBinaryDirectory(), this->GetCurrentBinaryDirectory());
if (this->HomeRelativeOutputPath == ".") {
- this->HomeRelativeOutputPath = "";
+ this->HomeRelativeOutputPath.clear();
}
if (!this->HomeRelativeOutputPath.empty()) {
this->HomeRelativeOutputPath += "/";
}
}
-void cmLocalUnixMakefileGenerator3::ComputeObjectFilenames(
- std::map<cmSourceFile const*, std::string>& mapping,
- cmGeneratorTarget const* gt)
-{
- // Determine if these object files should use a custom extension
- char const* custom_ext = gt->GetCustomObjectExtension();
- for (std::map<cmSourceFile const*, std::string>::iterator si =
- mapping.begin();
- si != mapping.end(); ++si) {
- cmSourceFile const* sf = si->first;
- bool keptSourceExtension;
- si->second = this->GetObjectFileNameWithoutTarget(
- *sf, gt->ObjectDirectory, &keptSourceExtension, custom_ext);
- }
-}
-
void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
std::map<std::string, LocalObjectInfo>& localObjectFiles)
{
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator ti = targets.begin();
- ti != targets.end(); ++ti) {
- cmGeneratorTarget* gt = *ti;
+ for (cmGeneratorTarget* gt : this->GetGeneratorTargets()) {
if (gt->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
@@ -189,18 +168,16 @@ void cmLocalUnixMakefileGenerator3::GetLocalObjectFiles(
dir += this->GetTargetDirectory(gt);
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;
+ for (cmSourceFile const* sf : objectSources) {
bool hasSourceExtension = true;
std::string objectName =
this->GetObjectFileNameWithoutTarget(*sf, dir, &hasSourceExtension);
- if (cmSystemTools::FileIsFullPath(objectName.c_str())) {
+ if (cmSystemTools::FileIsFullPath(objectName)) {
objectName = cmSystemTools::GetFilenameName(objectName);
}
LocalObjectInfo& info = localObjectFiles[objectName];
info.HasSourceExtension = hasSourceExtension;
- info.push_back(LocalObjectEntry(gt, sf->GetLanguage()));
+ info.emplace_back(gt, sf->GetLanguage());
}
}
}
@@ -210,18 +187,16 @@ void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets(
{
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) {
+ for (auto const& localObjectFile : localObjectFiles) {
+ targets.push_back(localObjectFile.first);
+
+ std::string::size_type dot_pos = localObjectFile.first.rfind(".");
+ std::string base = localObjectFile.first.substr(0, dot_pos);
+ if (localObjectFile.second.HasPreprocessRule) {
targets.push_back(base + ".i");
}
- if (lo->second.HasAssembleRule) {
+ if (localObjectFile.second.HasAssembleRule) {
targets.push_back(base + ".s");
}
}
@@ -236,8 +211,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
// rules may depend on this file itself.
std::string ruleFileNameFull = this->ConvertToFullPath(ruleFileName);
cmGeneratedFileStream ruleFileStream(
- ruleFileNameFull.c_str(), false,
- this->GlobalGenerator->GetMakefileEncoding());
+ ruleFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding());
if (!ruleFileStream) {
return;
}
@@ -270,23 +244,20 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
// 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) {
+ for (auto& localObjectFile : localObjectFiles) {
// Add a convenience rule for building the object file.
- this->WriteObjectConvenienceRule(ruleFileStream,
- "target to build an object file",
- lo->first.c_str(), lo->second);
+ this->WriteObjectConvenienceRule(
+ ruleFileStream, "target to build an object file", localObjectFile.first,
+ localObjectFile.second);
// Check whether preprocessing and assembly rules make sense.
// They make sense only for C and C++ sources.
bool lang_has_preprocessor = false;
bool lang_has_assembly = false;
- for (std::vector<LocalObjectEntry>::const_iterator ei = lo->second.begin();
- ei != lo->second.end(); ++ei) {
- if (ei->Language == "C" || ei->Language == "CXX" ||
- ei->Language == "CUDA" || ei->Language == "Fortran") {
+ for (LocalObjectEntry const& entry : localObjectFile.second) {
+ if (entry.Language == "C" || entry.Language == "CXX" ||
+ entry.Language == "CUDA" || entry.Language == "Fortran") {
// Right now, C, C++, Fortran and CUDA have both a preprocessor and the
// ability to generate assembly code
lang_has_preprocessor = true;
@@ -297,21 +268,21 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
// Add convenience rules for preprocessed and assembly files.
if (lang_has_preprocessor && do_preprocess_rules) {
- std::string::size_type dot_pos = lo->first.rfind(".");
- std::string base = lo->first.substr(0, dot_pos);
+ std::string::size_type dot_pos = localObjectFile.first.rfind(".");
+ std::string base = localObjectFile.first.substr(0, dot_pos);
this->WriteObjectConvenienceRule(ruleFileStream,
"target to preprocess a source file",
- (base + ".i").c_str(), lo->second);
- lo->second.HasPreprocessRule = true;
+ (base + ".i"), localObjectFile.second);
+ localObjectFile.second.HasPreprocessRule = true;
}
if (lang_has_assembly && do_assembly_rules) {
- std::string::size_type dot_pos = lo->first.rfind(".");
- std::string base = lo->first.substr(0, dot_pos);
+ std::string::size_type dot_pos = localObjectFile.first.rfind(".");
+ std::string base = localObjectFile.first.substr(0, dot_pos);
this->WriteObjectConvenienceRule(
ruleFileStream, "target to generate assembly for a file",
- (base + ".s").c_str(), lo->second);
- lo->second.HasAssembleRule = true;
+ (base + ".s"), localObjectFile.second);
+ localObjectFile.second.HasAssembleRule = true;
}
}
@@ -326,7 +297,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
}
void cmLocalUnixMakefileGenerator3::WriteObjectConvenienceRule(
- std::ostream& ruleFileStream, const char* comment, const char* output,
+ std::ostream& ruleFileStream, const char* comment, const std::string& output,
LocalObjectInfo const& info)
{
// If the rule includes the source file extension then create a
@@ -346,24 +317,23 @@ void cmLocalUnixMakefileGenerator3::WriteObjectConvenienceRule(
// Add a rule to drive the rule below.
std::vector<std::string> depends;
- depends.push_back(output);
+ depends.emplace_back(output);
std::vector<std::string> no_commands;
- this->WriteMakeRule(ruleFileStream, CM_NULLPTR, outNoExt, depends,
+ this->WriteMakeRule(ruleFileStream, nullptr, 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);
+ for (LocalObjectEntry const& t : info) {
+ 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->GetRecursiveMakeCall(tgtMakefileName, targetName));
}
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
@@ -382,54 +352,51 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
// for each target we just provide a rule to cd up to the top and do a make
// on the target
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
std::string localName;
- for (std::vector<cmGeneratorTarget*>::iterator t = targets.begin();
- t != targets.end(); ++t) {
- if (((*t)->GetType() == cmStateEnums::EXECUTABLE) ||
- ((*t)->GetType() == cmStateEnums::STATIC_LIBRARY) ||
- ((*t)->GetType() == cmStateEnums::SHARED_LIBRARY) ||
- ((*t)->GetType() == cmStateEnums::MODULE_LIBRARY) ||
- ((*t)->GetType() == cmStateEnums::OBJECT_LIBRARY) ||
- ((*t)->GetType() == cmStateEnums::UTILITY)) {
- emitted.insert((*t)->GetName());
+ for (cmGeneratorTarget* target : this->GetGeneratorTargets()) {
+ if ((target->GetType() == cmStateEnums::EXECUTABLE) ||
+ (target->GetType() == cmStateEnums::STATIC_LIBRARY) ||
+ (target->GetType() == cmStateEnums::SHARED_LIBRARY) ||
+ (target->GetType() == cmStateEnums::MODULE_LIBRARY) ||
+ (target->GetType() == cmStateEnums::OBJECT_LIBRARY) ||
+ (target->GetType() == cmStateEnums::UTILITY)) {
+ emitted.insert(target->GetName());
// for subdirs add a rule to build this specific target by name.
- localName = this->GetRelativeTargetDirectory(*t);
+ localName = this->GetRelativeTargetDirectory(target);
localName += "/rule";
commands.clear();
depends.clear();
// Build the target for this pass.
- std::string makefile2 = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::string makefile2 = "CMakeFiles/";
makefile2 += "Makefile2";
- commands.push_back(
- this->GetRecursiveMakeCall(makefile2.c_str(), localName));
+ commands.push_back(this->GetRecursiveMakeCall(makefile2, localName));
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
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)->GetName()) {
+ if (localName != target->GetName()) {
commands.clear();
depends.push_back(localName);
this->WriteMakeRule(ruleFileStream, "Convenience name for target.",
- (*t)->GetName(), depends, commands, true);
+ target->GetName(), depends, commands, true);
}
// Add a fast rule to build the target
- std::string makefileName = this->GetRelativeTargetDirectory(*t);
+ std::string makefileName = this->GetRelativeTargetDirectory(target);
makefileName += "/build.make";
// make sure the makefile name is suitable for a makefile
- std::string makeTargetName = this->GetRelativeTargetDirectory(*t);
+ std::string makeTargetName = this->GetRelativeTargetDirectory(target);
makeTargetName += "/build";
- localName = (*t)->GetName();
+ localName = target->GetName();
localName += "/fast";
depends.clear();
commands.clear();
commands.push_back(
- this->GetRecursiveMakeCall(makefileName.c_str(), makeTargetName));
+ this->GetRecursiveMakeCall(makefileName, makeTargetName));
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
this->WriteMakeRule(ruleFileStream, "fast build rule for target.",
@@ -437,15 +404,15 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
// Add a local name for the rule to relink the target before
// installation.
- if ((*t)->NeedRelinkBeforeInstall(this->ConfigName)) {
- makeTargetName = this->GetRelativeTargetDirectory(*t);
+ if (target->NeedRelinkBeforeInstall(this->ConfigName)) {
+ makeTargetName = this->GetRelativeTargetDirectory(target);
makeTargetName += "/preinstall";
- localName = (*t)->GetName();
+ localName = target->GetName();
localName += "/preinstall";
depends.clear();
commands.clear();
commands.push_back(
- this->GetRecursiveMakeCall(makefile2.c_str(), makeTargetName));
+ this->GetRecursiveMakeCall(makefile2, makeTargetName));
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
this->WriteMakeRule(ruleFileStream,
@@ -459,11 +426,11 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefileTargets(
void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
{
std::string infoFileName = this->GetCurrentBinaryDirectory();
- infoFileName += cmake::GetCMakeFilesDirectory();
+ infoFileName += "/CMakeFiles";
infoFileName += "/CMakeDirectoryInformation.cmake";
// Open the output file.
- cmGeneratedFileStream infoFileStream(infoFileName.c_str());
+ cmGeneratedFileStream infoFileStream(infoFileName);
if (!infoFileStream) {
return;
}
@@ -500,12 +467,12 @@ void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile()
<< "# 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());
+ cmLocalUnixMakefileGenerator3::WriteCMakeArgument(
+ infoFileStream, this->Makefile->GetIncludeRegularExpression());
infoFileStream << ")\n";
infoFileStream << "set(CMAKE_C_INCLUDE_REGEX_COMPLAIN ";
- this->WriteCMakeArgument(infoFileStream,
- this->Makefile->GetComplainRegularExpression());
+ cmLocalUnixMakefileGenerator3::WriteCMakeArgument(
+ infoFileStream, this->Makefile->GetComplainRegularExpression());
infoFileStream << ")\n";
infoFileStream
<< "set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})\n";
@@ -534,8 +501,11 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule(
{
// Make sure there is a target.
if (target.empty()) {
- cmSystemTools::Error("No target for WriteMakeRule! called with comment: ",
- comment);
+ std::string err("No target for WriteMakeRule! called with comment: ");
+ if (comment) {
+ err += comment;
+ }
+ cmSystemTools::Error(err);
return;
}
@@ -555,8 +525,7 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule(
// Construct the left hand side of the rule.
std::string tgt = cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), target)
- .c_str());
+ this->MaybeConvertToRelativePath(this->GetBinaryDirectory(), target));
const char* space = "";
if (tgt.size() == 1) {
@@ -581,11 +550,10 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule(
// Split dependencies into multiple rule lines. This allows for
// very long dependency lists even on older make implementations.
std::string binDir = this->GetBinaryDirectory();
- for (std::vector<std::string>::const_iterator dep = depends.begin();
- dep != depends.end(); ++dep) {
- replace = *dep;
+ for (std::string const& depend : depends) {
+ replace = depend;
replace = cmSystemTools::ConvertToOutputPath(
- this->MaybeConvertToRelativePath(binDir, replace).c_str());
+ this->MaybeConvertToRelativePath(binDir, replace));
os << cmMakeSafe(tgt) << space << ": " << cmMakeSafe(replace) << "\n";
}
}
@@ -605,7 +573,7 @@ void cmLocalUnixMakefileGenerator3::WriteMakeRule(
std::string cmLocalUnixMakefileGenerator3::MaybeConvertWatcomShellCommand(
std::string const& cmd)
{
- if (this->IsWatcomWMake() && cmSystemTools::FileIsFullPath(cmd.c_str()) &&
+ if (this->IsWatcomWMake() && cmSystemTools::FileIsFullPath(cmd) &&
cmd.find_first_of("( )") != std::string::npos) {
// On Watcom WMake use the windows short path for the command
// name. This is needed to avoid funny quoting problems on
@@ -717,8 +685,8 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop(
}
// 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, CM_NULLPTR, ".SUFFIXES", depends,
+ depends.emplace_back(".hpux_make_needs_suffix_list");
+ this->WriteMakeRule(makefileStream, nullptr, ".SUFFIXES", depends,
no_commands, false);
if (this->IsWatcomWMake()) {
// Switch on WMake feature, if an error or interrupt occurs during
@@ -767,11 +735,11 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsTop(
static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator);
std::string hack = gg->GetEmptyRuleHackDepends();
if (!hack.empty()) {
- no_depends.push_back(hack);
+ no_depends.push_back(std::move(hack));
}
std::string hack_cmd = gg->GetEmptyRuleHackCommand();
if (!hack_cmd.empty()) {
- no_commands.push_back(hack_cmd);
+ no_commands.push_back(std::move(hack_cmd));
}
// Special symbolic target that never exists to force dependers to
@@ -792,31 +760,40 @@ void cmLocalUnixMakefileGenerator3::WriteSpecialTargetsBottom(
// Write special "cmake_check_build_system" target to run cmake with
// the --check-build-system flag.
- {
+ if (!this->GlobalGenerator->GlobalSettingIsOn(
+ "CMAKE_SUPPRESS_REGENERATION")) {
// Build command to run CMake to check if anything needs regenerating.
- std::string cmakefileName = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::vector<std::string> commands;
+ cmake* cm = this->GlobalGenerator->GetCMakeInstance();
+ if (cm->DoWriteGlobVerifyTarget()) {
+ std::string rescanRule = "$(CMAKE_COMMAND) -P ";
+ rescanRule += this->ConvertToOutputFormat(cm->GetGlobVerifyScript(),
+ cmOutputConverter::SHELL);
+ commands.push_back(rescanRule);
+ }
+ std::string cmakefileName = "CMakeFiles/";
cmakefileName += "Makefile.cmake";
std::string runRule =
- "$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
+ "$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
runRule += " --check-build-system ";
runRule +=
this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL);
runRule += " 0";
std::vector<std::string> no_depends;
- std::vector<std::string> commands;
- commands.push_back(runRule);
+ commands.push_back(std::move(runRule));
if (!this->IsRootMakefile()) {
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
}
- 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);
+ 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);
}
}
@@ -847,8 +824,8 @@ std::string cmLocalUnixMakefileGenerator3::GetRelativeTargetDirectory(
return dir;
}
-void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
- const std::string& newFlags)
+void cmLocalUnixMakefileGenerator3::AppendFlags(
+ std::string& flags, const std::string& newFlags) const
{
if (this->IsWatcomWMake() && !newFlags.empty()) {
std::string newf = newFlags;
@@ -862,7 +839,7 @@ void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
}
void cmLocalUnixMakefileGenerator3::AppendFlags(std::string& flags,
- const char* newFlags)
+ const char* newFlags) const
{
this->cmLocalGenerator::AppendFlags(flags, newFlags);
}
@@ -875,7 +852,7 @@ void cmLocalUnixMakefileGenerator3::AppendRuleDepend(
const char* nodep =
this->Makefile->GetDefinition("CMAKE_SKIP_RULE_DEPENDENCY");
if (!nodep || cmSystemTools::IsOff(nodep)) {
- depends.push_back(ruleFileName);
+ depends.emplace_back(ruleFileName);
}
}
@@ -885,16 +862,15 @@ void cmLocalUnixMakefileGenerator3::AppendRuleDepends(
// 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());
+ cmAppend(depends, ruleFiles);
}
}
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->ConfigName, this);
+ for (cmCustomCommand const& cc : ccs) {
+ cmCustomCommandGenerator ccg(cc, this->ConfigName, this);
this->AppendCustomDepend(depends, ccg);
}
}
@@ -902,12 +878,11 @@ void cmLocalUnixMakefileGenerator3::AppendCustomDepends(
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) {
+ for (std::string const& d : ccg.GetDepends()) {
// Lookup the real name of the dependency in case it is a CMake target.
std::string dep;
- if (this->GetRealDependency(*d, this->ConfigName, dep)) {
- depends.push_back(dep);
+ if (this->GetRealDependency(d, this->ConfigName, dep)) {
+ depends.push_back(std::move(dep));
}
}
}
@@ -916,9 +891,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommands(
std::vector<std::string>& commands, const std::vector<cmCustomCommand>& ccs,
cmGeneratorTarget* target, std::string const& relative)
{
- for (std::vector<cmCustomCommand>::const_iterator i = ccs.begin();
- i != ccs.end(); ++i) {
- cmCustomCommandGenerator ccg(*i, this->ConfigName, this);
+ for (cmCustomCommand const& cc : ccs) {
+ cmCustomCommandGenerator ccg(cc, this->ConfigName, this);
this->AppendCustomCommand(commands, ccg, target, relative, true);
}
}
@@ -950,7 +924,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
*content << dir;
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->CreateRulePlaceholderExpander());
// Add each command line to the set of commands.
@@ -994,8 +968,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
// Short-circuit if there is no launcher.
const char* val = this->GetRuleLauncher(target, "RULE_LAUNCH_CUSTOM");
if (val && *val) {
- // Expand rules in the empty string. It may insert the launcher and
- // perform replacements.
+ // Expand rule variables referenced in the given launcher command.
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = target->GetName().c_str();
vars.CMTargetType = cmState::GetTargetTypeName(target->GetType());
@@ -1013,7 +986,6 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
vars.Output = output.c_str();
launcher = val;
- launcher += " ";
rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars);
if (!launcher.empty()) {
launcher += " ";
@@ -1057,19 +1029,19 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
cmd = "echo >nul && " + cmd;
}
}
- commands1.push_back(cmd);
+ commands1.push_back(std::move(cmd));
}
}
// Setup the proper working directory for the commands.
- this->CreateCDCommand(commands1, dir.c_str(), relative);
+ this->CreateCDCommand(commands1, dir, relative);
// push back the custom commands
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
}
void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
- std::vector<std::string>& commands, const std::vector<std::string>& files,
+ std::vector<std::string>& commands, const std::set<std::string>& files,
cmGeneratorTarget* target, const char* filename)
{
std::string currentBinDir = this->GetCurrentBinaryDirectory();
@@ -1085,23 +1057,24 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
std::string cleanfilePath = cmSystemTools::CollapseFullPath(cleanfile);
cmsys::ofstream fout(cleanfilePath.c_str());
if (!fout) {
- cmSystemTools::Error("Could not create ", cleanfilePath.c_str());
+ cmSystemTools::Error("Could not create " + cleanfilePath);
}
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->MaybeConvertToRelativePath(currentBinDir, *f);
+ for (std::string const& file : files) {
+ std::string fc = this->MaybeConvertToRelativePath(currentBinDir, file);
fout << " " << cmOutputConverter::EscapeForCMake(fc) << "\n";
}
fout << ")\n";
}
- std::string remove = "$(CMAKE_COMMAND) -P ";
- remove += this->ConvertToOutputFormat(
- this->MaybeConvertToRelativePath(this->GetCurrentBinaryDirectory(),
- cleanfile),
- cmOutputConverter::SHELL);
- commands.push_back(remove);
+ {
+ std::string remove = "$(CMAKE_COMMAND) -P ";
+ remove += this->ConvertToOutputFormat(
+ this->MaybeConvertToRelativePath(this->GetCurrentBinaryDirectory(),
+ cleanfile),
+ cmOutputConverter::SHELL);
+ commands.push_back(std::move(remove));
+ }
// For the main clean rule add per-language cleaning.
if (!filename) {
@@ -1120,6 +1093,56 @@ void cmLocalUnixMakefileGenerator3::AppendCleanCommand(
}
}
+void cmLocalUnixMakefileGenerator3::AppendDirectoryCleanCommand(
+ std::vector<std::string>& commands)
+{
+ std::vector<std::string> cleanFiles;
+ // Look for additional files registered for cleaning in this directory.
+ if (const char* prop_value =
+ this->Makefile->GetProperty("ADDITIONAL_CLEAN_FILES")) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop_value);
+ cmSystemTools::ExpandListArgument(
+ cge->Evaluate(this,
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")),
+ cleanFiles);
+ }
+ if (cleanFiles.empty()) {
+ return;
+ }
+
+ cmLocalGenerator* rootLG =
+ this->GetGlobalGenerator()->GetLocalGenerators().at(0);
+ std::string const& binaryDir = rootLG->GetCurrentBinaryDirectory();
+ std::string const& currentBinaryDir = this->GetCurrentBinaryDirectory();
+ std::string cleanfile = currentBinaryDir;
+ cleanfile += "/CMakeFiles/cmake_directory_clean.cmake";
+ // Write clean script
+ {
+ std::string cleanfilePath = cmSystemTools::CollapseFullPath(cleanfile);
+ cmsys::ofstream fout(cleanfilePath.c_str());
+ if (!fout) {
+ cmSystemTools::Error("Could not create " + cleanfilePath);
+ return;
+ }
+ fout << "file(REMOVE_RECURSE\n";
+ for (std::string const& cfl : cleanFiles) {
+ std::string fc = rootLG->MaybeConvertToRelativePath(
+ binaryDir, cmSystemTools::CollapseFullPath(cfl, currentBinaryDir));
+ fout << " " << cmOutputConverter::EscapeForCMake(fc) << "\n";
+ }
+ fout << ")\n";
+ }
+ // Create command
+ {
+ std::string remove = "$(CMAKE_COMMAND) -P ";
+ remove += this->ConvertToOutputFormat(
+ rootLG->MaybeConvertToRelativePath(binaryDir, cleanfile),
+ cmOutputConverter::SHELL);
+ commands.push_back(std::move(remove));
+ }
+}
+
void cmLocalUnixMakefileGenerator3::AppendEcho(
std::vector<std::string>& commands, std::string const& text, EchoColor color,
EchoProgress const* progress)
@@ -1179,14 +1202,14 @@ void cmLocalUnixMakefileGenerator3::AppendEcho(
}
cmd += this->EscapeForShell(line);
}
- commands.push_back(cmd);
+ commands.push_back(std::move(cmd));
}
- // Reset the line to emtpy.
- line = "";
+ // Reset the line to empty.
+ line.clear();
// Progress appears only on first line.
- progress = CM_NULLPTR;
+ progress = nullptr;
// Terminate on end-of-string.
if (*c == '\0') {
@@ -1281,9 +1304,8 @@ std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable(
return ret;
}
-bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
- bool verbose,
- bool color)
+bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
+ const std::string& tgtInfo, bool verbose, bool color)
{
// read in the target info file
if (!this->Makefile->ReadListFile(tgtInfo) ||
@@ -1294,26 +1316,25 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
// 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";
+ std::string const targetDir = cmSystemTools::GetFilenamePath(tgtInfo);
+ std::string const internalDependFile = targetDir + "/depend.internal";
+ std::string const dependFile = targetDir + "/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();
+ cmFileTimeCache* ftc =
+ this->GlobalGenerator->GetCMakeInstance()->GetFileTimeCache();
{
int result;
- if (!ftc->FileTimeCompare(internalDependFile.c_str(), tgtInfo, &result) ||
- result < 0) {
+ if (!ftc->Compare(internalDependFile, tgtInfo, &result) || result < 0) {
if (verbose) {
std::ostringstream msg;
msg << "Dependee \"" << tgtInfo << "\" is newer than depender \""
<< internalDependFile << "\"." << std::endl;
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
needRescanDependInfo = true;
}
@@ -1322,19 +1343,18 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
// If the directory information is newer than depend.internal, include dirs
// may have changed. In this case discard all old dependencies.
bool needRescanDirInfo = false;
- std::string dirInfoFile = this->GetCurrentBinaryDirectory();
- dirInfoFile += cmake::GetCMakeFilesDirectory();
- dirInfoFile += "/CMakeDirectoryInformation.cmake";
{
+ std::string dirInfoFile = this->GetCurrentBinaryDirectory();
+ dirInfoFile += "/CMakeFiles";
+ dirInfoFile += "/CMakeDirectoryInformation.cmake";
int result;
- if (!ftc->FileTimeCompare(internalDependFile.c_str(), dirInfoFile.c_str(),
- &result) ||
+ if (!ftc->Compare(internalDependFile, dirInfoFile, &result) ||
result < 0) {
if (verbose) {
std::ostringstream msg;
msg << "Dependee \"" << dirInfoFile << "\" is newer than depender \""
<< internalDependFile << "\"." << std::endl;
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
needRescanDirInfo = true;
}
@@ -1344,12 +1364,12 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
// 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;
+ cmDepends::DependencyMap validDependencies;
bool needRescanDependencies = false;
if (!needRescanDirInfo) {
cmDependsC checker;
checker.SetVerbose(verbose);
- checker.SetFileComparison(ftc);
+ checker.SetFileTimeCache(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.
@@ -1360,13 +1380,13 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
// 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);
+ needRescanDependencies =
+ !checker.Check(dependFile, internalDependFile, validDependencies);
}
if (needRescanDependInfo || needRescanDirInfo || needRescanDependencies) {
// The dependencies must be regenerated.
- std::string targetName = cmSystemTools::GetFilenameName(dir);
+ std::string targetName = cmSystemTools::GetFilenameName(targetDir);
targetName = targetName.substr(0, targetName.length() - 4);
std::string message = "Scanning dependencies of target ";
message += targetName;
@@ -1374,7 +1394,8 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
cmsysTerminal_Color_ForegroundBold,
message.c_str(), true, color);
- return this->ScanDependencies(dir.c_str(), validDependencies);
+ return this->ScanDependencies(targetDir, dependFile, internalDependFile,
+ validDependencies);
}
// The dependencies are already up-to-date.
@@ -1382,18 +1403,20 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo,
}
bool cmLocalUnixMakefileGenerator3::ScanDependencies(
- const char* targetDir,
- std::map<std::string, cmDepends::DependencyVector>& validDeps)
+ std::string const& targetDir, std::string const& dependFile,
+ std::string const& internalDependFile, cmDepends::DependencyMap& validDeps)
{
// Read the directory information file.
cmMakefile* mf = this->Makefile;
bool haveDirectoryInfo = false;
- std::string dirInfoFile = this->GetCurrentBinaryDirectory();
- dirInfoFile += cmake::GetCMakeFilesDirectory();
- dirInfoFile += "/CMakeDirectoryInformation.cmake";
- if (mf->ReadListFile(dirInfoFile.c_str()) &&
- !cmSystemTools::GetErrorOccuredFlag()) {
- haveDirectoryInfo = true;
+ {
+ std::string dirInfoFile = this->GetCurrentBinaryDirectory();
+ dirInfoFile += "/CMakeFiles";
+ dirInfoFile += "/CMakeDirectoryInformation.cmake";
+ if (mf->ReadListFile(dirInfoFile) &&
+ !cmSystemTools::GetErrorOccuredFlag()) {
+ haveDirectoryInfo = true;
+ }
}
// Lookup useful directory information.
@@ -1420,16 +1443,10 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
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(), false,
- this->GlobalGenerator->GetMakefileEncoding());
+ dependFile, false, this->GlobalGenerator->GetMakefileEncoding());
ruleFileStream.SetCopyIfDifferent(true);
if (!ruleFileStream) {
return false;
@@ -1438,11 +1455,8 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
// 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(), false,
- this->GlobalGenerator->GetMakefileEncoding());
+ internalDependFile, false, this->GlobalGenerator->GetMakefileEncoding());
if (!internalRuleFileStream) {
return false;
}
@@ -1451,39 +1465,35 @@ bool cmLocalUnixMakefileGenerator3::ScanDependencies(
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) {
+ cmSystemTools::ExpandListArgument(
+ mf->GetSafeDefinition("CMAKE_DEPENDS_LANGUAGES"), langs);
+ for (std::string const& lang : langs) {
// construct the checker
- std::string lang = *li;
-
// Create the scanner for this language
- cmDepends* scanner = CM_NULLPTR;
+ std::unique_ptr<cmDepends> scanner;
if (lang == "C" || lang == "CXX" || lang == "RC" || lang == "ASM" ||
lang == "CUDA") {
// TODO: Handle RC (resource files) dependencies correctly.
- scanner = new cmDependsC(this, targetDir, lang, &validDeps);
+ scanner = cm::make_unique<cmDependsC>(this, targetDir, lang, &validDeps);
}
#ifdef CMAKE_BUILD_WITH_CMAKE
else if (lang == "Fortran") {
- scanner = new cmDependsFortran(this);
+ ruleFileStream << "# Note that incremental build could trigger "
+ << "a call to cmake_copy_f90_mod on each re-build\n";
+ scanner = cm::make_unique<cmDependsFortran>(this);
} else if (lang == "Java") {
- scanner = new cmDependsJava();
+ scanner = cm::make_unique<cmDependsJava>();
}
#endif
if (scanner) {
scanner->SetLocalGenerator(this);
- scanner->SetFileComparison(
- this->GlobalGenerator->GetCMakeInstance()->GetFileComparison());
+ scanner->SetFileTimeCache(
+ this->GlobalGenerator->GetCMakeInstance()->GetFileTimeCache());
scanner->SetLanguage(lang);
- scanner->SetTargetDirectory(dir.c_str());
+ scanner->SetTargetDirectory(targetDir);
scanner->Write(ruleFileStream, internalRuleFileStream);
-
- // free the scanner for this language
- delete scanner;
}
}
@@ -1510,14 +1520,14 @@ void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose)
// 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 (cmSystemTools::FileExists(dependee) &&
+ !cmSystemTools::FileExists(depender)) {
if (verbose) {
std::ostringstream msg;
msg << "Deleting primary custom command output \"" << dependee
<< "\" because another output \"" << depender
<< "\" does not exist." << std::endl;
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
cmSystemTools::RemoveFile(dependee);
}
@@ -1535,7 +1545,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
// 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");
+ depends.emplace_back("all");
// Write the rule.
this->WriteMakeRule(ruleFileStream,
@@ -1548,9 +1558,10 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
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.",
+ this->WriteMakeRule(ruleFileStream,
+ "Allow only one \"make -f "
+ "Makefile2\" at a time, but pass "
+ "parallelism.",
".NOTPARALLEL", no_depends, no_commands, false);
}
}
@@ -1562,26 +1573,25 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
this->WriteDivider(ruleFileStream);
ruleFileStream << "# Targets provided globally by CMake.\n"
<< "\n";
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- std::vector<cmGeneratorTarget*>::iterator glIt;
- for (glIt = targets.begin(); glIt != targets.end(); ++glIt) {
- if ((*glIt)->GetType() == cmStateEnums::GLOBAL_TARGET) {
+ const std::vector<cmGeneratorTarget*>& targets = this->GetGeneratorTargets();
+ for (cmGeneratorTarget* gt : targets) {
+ if (gt->GetType() == cmStateEnums::GLOBAL_TARGET) {
std::string targetString =
- "Special rule for the target " + (*glIt)->GetName();
+ "Special rule for the target " + gt->GetName();
std::vector<std::string> commands;
std::vector<std::string> depends;
- const char* text = (*glIt)->GetProperty("EchoString");
+ const char* text = gt->GetProperty("EchoString");
if (!text) {
text = "Running external command ...";
}
- depends.insert(depends.end(), (*glIt)->GetUtilities().begin(),
- (*glIt)->GetUtilities().end());
+ depends.reserve(gt->GetUtilities().size());
+ for (BT<std::string> const& u : gt->GetUtilities()) {
+ depends.push_back(u.Value);
+ }
this->AppendEcho(commands, text,
cmLocalUnixMakefileGenerator3::EchoGlobal);
- cmGeneratorTarget* gt = *glIt;
-
// Global targets store their rules in pre- and post-build commands.
this->AppendCustomDepends(depends, gt->GetPreBuildCommands());
this->AppendCustomDepends(depends, gt->GetPostBuildCommands());
@@ -1599,7 +1609,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
(targetName == "install/strip")) {
// Provide a fast install target that does not depend on all
// but has the same command.
- depends.push_back("preinstall/fast");
+ depends.emplace_back("preinstall/fast");
} else {
// Just forward to the real target so at least it will work.
depends.push_back(targetName);
@@ -1618,17 +1628,21 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
std::string recursiveTarget = this->GetCurrentBinaryDirectory();
recursiveTarget += "/all";
- depends.push_back("cmake_check_build_system");
+ bool regenerate =
+ !this->GlobalGenerator->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION");
+ if (regenerate) {
+ depends.emplace_back("cmake_check_build_system");
+ }
std::string progressDir = this->GetBinaryDirectory();
- progressDir += cmake::GetCMakeFilesDirectory();
+ progressDir += "/CMakeFiles";
{
std::ostringstream progCmd;
progCmd << "$(CMAKE_COMMAND) -E cmake_progress_start ";
progCmd << this->ConvertToOutputFormat(
cmSystemTools::CollapseFullPath(progressDir), cmOutputConverter::SHELL);
- std::string progressFile = cmake::GetCMakeFilesDirectory();
+ std::string progressFile = "/CMakeFiles";
progressFile += "/progress.marks";
std::string progressFileNameFull = this->ConvertToFullPath(progressFile);
progCmd << " "
@@ -1637,10 +1651,9 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
cmOutputConverter::SHELL);
commands.push_back(progCmd.str());
}
- std::string mf2Dir = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::string mf2Dir = "CMakeFiles/";
mf2Dir += "Makefile2";
- commands.push_back(
- this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
+ commands.push_back(this->GetRecursiveMakeCall(mf2Dir, recursiveTarget));
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
{
@@ -1659,15 +1672,14 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
recursiveTarget += "/clean";
commands.clear();
depends.clear();
- commands.push_back(
- this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
+ commands.push_back(this->GetRecursiveMakeCall(mf2Dir, recursiveTarget));
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
this->WriteMakeRule(ruleFileStream, "The main clean target", "clean",
depends, commands, true);
commands.clear();
depends.clear();
- depends.push_back("clean");
+ depends.emplace_back("clean");
this->WriteMakeRule(ruleFileStream, "The main clean target", "clean/fast",
depends, commands, true);
@@ -1680,13 +1692,12 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
this->Makefile->GetDefinition("CMAKE_SKIP_INSTALL_ALL_DEPENDENCY");
if (!noall || cmSystemTools::IsOff(noall)) {
// Drive the build before installing.
- depends.push_back("all");
- } else {
+ depends.emplace_back("all");
+ } else if (regenerate) {
// At least make sure the build system is up to date.
- depends.push_back("cmake_check_build_system");
+ depends.emplace_back("cmake_check_build_system");
}
- commands.push_back(
- this->GetRecursiveMakeCall(mf2Dir.c_str(), recursiveTarget));
+ commands.push_back(this->GetRecursiveMakeCall(mf2Dir, recursiveTarget));
this->CreateCDCommand(commands, this->GetBinaryDirectory(),
this->GetCurrentBinaryDirectory());
this->WriteMakeRule(ruleFileStream, "Prepare targets for installation.",
@@ -1695,22 +1706,33 @@ void cmLocalUnixMakefileGenerator3::WriteLocalAllRules(
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->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL);
- runRule += " 1";
- commands.push_back(runRule);
- this->CreateCDCommand(commands, this->GetBinaryDirectory(),
- this->GetCurrentBinaryDirectory());
- this->WriteMakeRule(ruleFileStream, "clear depends", "depend", depends,
- commands, true);
+ if (regenerate) {
+ // write the depend rule, really a recompute depends rule
+ depends.clear();
+ commands.clear();
+ cmake* cm = this->GlobalGenerator->GetCMakeInstance();
+ if (cm->DoWriteGlobVerifyTarget()) {
+ std::string rescanRule = "$(CMAKE_COMMAND) -P ";
+ rescanRule += this->ConvertToOutputFormat(cm->GetGlobVerifyScript(),
+ cmOutputConverter::SHELL);
+ commands.push_back(rescanRule);
+ }
+ std::string cmakefileName = "CMakeFiles/";
+ cmakefileName += "Makefile.cmake";
+ {
+ std::string runRule =
+ "$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)";
+ runRule += " --check-build-system ";
+ runRule +=
+ this->ConvertToOutputFormat(cmakefileName, cmOutputConverter::SHELL);
+ runRule += " 1";
+ commands.push_back(std::move(runRule));
+ }
+ this->CreateCDCommand(commands, this->GetBinaryDirectory(),
+ this->GetCurrentBinaryDirectory());
+ this->WriteMakeRule(ruleFileStream, "clear depends", "depend", depends,
+ commands, true);
+ }
}
void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
@@ -1728,13 +1750,12 @@ void cmLocalUnixMakefileGenerator3::ClearDependencies(cmMakefile* mf,
// 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);
+ for (std::string const& file : files) {
+ std::string dir = cmSystemTools::GetFilenamePath(file);
// Clear the implicit dependency makefile.
std::string dependFile = dir + "/depend.make";
- clearer.Clear(dependFile.c_str());
+ clearer.Clear(dependFile);
// Remove the internal dependency check file to force
// regeneration.
@@ -1751,9 +1772,9 @@ class NotInProjectDir
{
public:
// Constructor with the source and binary directory's path
- NotInProjectDir(const std::string& sourceDir, const std::string& binaryDir)
- : SourceDir(sourceDir)
- , BinaryDir(binaryDir)
+ NotInProjectDir(std::string sourceDir, std::string binaryDir)
+ : SourceDir(std::move(sourceDir))
+ , BinaryDir(std::move(binaryDir))
{
}
@@ -1802,54 +1823,62 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
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";
+ for (auto const& implicitLang : implicitLangs) {
+ cmakefileStream << " \"" << implicitLang.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 (auto const& implicitLang : implicitLangs) {
+ cmakefileStream << "set(CMAKE_DEPENDS_CHECK_" << implicitLang.first
+ << "\n";
+ ImplicitDependFileMap const& implicitPairs = implicitLang.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";
+ for (auto const& implicitPair : implicitPairs) {
+ for (auto const& di : implicitPair.second) {
+ cmakefileStream << " \"" << di << "\" ";
+ cmakefileStream << "\"" << implicitPair.first << "\"\n";
}
}
cmakefileStream << " )\n";
// Tell the dependency scanner what compiler is used.
std::string cidVar = "CMAKE_";
- cidVar += l->first;
+ cidVar += implicitLang.first;
cidVar += "_COMPILER_ID";
const char* cid = this->Makefile->GetDefinition(cidVar);
if (cid && *cid) {
- cmakefileStream << "set(CMAKE_" << l->first << "_COMPILER_ID \"" << cid
+ cmakefileStream << "set(CMAKE_" << implicitLang.first
+ << "_COMPILER_ID \"" << cid << "\")\n";
+ }
+
+ if (implicitLang.first == "Fortran") {
+ std::string smodSep =
+ this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_SEP");
+ std::string smodExt =
+ this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_EXT");
+ cmakefileStream << "set(CMAKE_Fortran_SUBMODULE_SEP \"" << smodSep
+ << "\")\n";
+ cmakefileStream << "set(CMAKE_Fortran_SUBMODULE_EXT \"" << smodExt
<< "\")\n";
}
// Build a list of preprocessor definitions for the target.
std::set<std::string> defines;
- this->AddCompileDefinitions(defines, target, this->ConfigName, l->first);
+ this->GetTargetDefines(target, this->ConfigName, implicitLang.first,
+ defines);
if (!defines.empty()) {
/* clang-format off */
cmakefileStream
<< "\n"
<< "# Preprocessor definitions for this target.\n"
- << "set(CMAKE_TARGET_DEFINITIONS_" << l->first << "\n";
+ << "set(CMAKE_TARGET_DEFINITIONS_" << implicitLang.first << "\n";
/* clang-format on */
- for (std::set<std::string>::const_iterator di = defines.begin();
- di != defines.end(); ++di) {
- cmakefileStream << " " << cmOutputConverter::EscapeForCMake(*di)
+ for (std::string const& define : defines) {
+ cmakefileStream << " " << cmOutputConverter::EscapeForCMake(define)
<< "\n";
}
cmakefileStream << " )\n";
@@ -1858,21 +1887,21 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
// Target-specific include directories:
cmakefileStream << "\n"
<< "# The include file search paths:\n";
- cmakefileStream << "set(CMAKE_" << l->first << "_TARGET_INCLUDE_PATH\n";
+ cmakefileStream << "set(CMAKE_" << implicitLang.first
+ << "_TARGET_INCLUDE_PATH\n";
std::vector<std::string> includes;
const std::string& config =
this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
- this->GetIncludeDirectories(includes, target, l->first, config);
+ this->GetIncludeDirectories(includes, target, implicitLang.first, config);
std::string binaryDir = this->GetState()->GetBinaryDirectory();
if (this->Makefile->IsOn("CMAKE_DEPENDS_IN_PROJECT_ONLY")) {
- const char* sourceDir = this->GetState()->GetSourceDirectory();
+ std::string const& sourceDir = this->GetState()->GetSourceDirectory();
cmEraseIf(includes, ::NotInProjectDir(sourceDir, binaryDir));
}
- for (std::vector<std::string>::iterator i = includes.begin();
- i != includes.end(); ++i) {
+ for (std::string const& include : includes) {
cmakefileStream << " \""
- << this->MaybeConvertToRelativePath(binaryDir, *i)
+ << this->MaybeConvertToRelativePath(binaryDir, include)
<< "\"\n";
}
cmakefileStream << " )\n";
@@ -1891,10 +1920,8 @@ void cmLocalUnixMakefileGenerator3::WriteDependLanguageInfo(
}
if (!transformRules.empty()) {
cmakefileStream << "set(CMAKE_INCLUDE_TRANSFORMS\n";
- for (std::vector<std::string>::const_iterator tri = transformRules.begin();
- tri != transformRules.end(); ++tri) {
- cmakefileStream << " " << cmOutputConverter::EscapeForCMake(*tri)
- << "\n";
+ for (std::string const& tr : transformRules) {
+ cmakefileStream << " " << cmOutputConverter::EscapeForCMake(tr) << "\n";
}
cmakefileStream << " )\n";
}
@@ -1909,7 +1936,7 @@ void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os)
}
std::string cmLocalUnixMakefileGenerator3::GetRecursiveMakeCall(
- const char* makefile, const std::string& tgt)
+ const std::string& makefile, const std::string& tgt)
{
// Call make on the given file.
std::string cmd;
@@ -1979,7 +2006,7 @@ void cmLocalUnixMakefileGenerator3::WriteCMakeArgument(std::ostream& os,
}
std::string cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(
- const char* p, bool useWatcomQuote)
+ const std::string& p, bool useWatcomQuote)
{
// Split the path into its components.
std::vector<std::string> components;
@@ -2004,10 +2031,9 @@ std::string cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(
#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 = '\\';
+ for (char& i : components[0]) {
+ if (i == '/') {
+ i = '\\';
}
}
}
@@ -2047,7 +2073,7 @@ std::string cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(
std::string cmLocalUnixMakefileGenerator3::GetTargetDirectory(
cmGeneratorTarget const* target) const
{
- std::string dir = cmake::GetCMakeFilesDirectoryPostSlash();
+ std::string dir = "CMakeFiles/";
dir += target->GetName();
#if defined(__VMS)
dir += "_dir";
@@ -2064,14 +2090,14 @@ cmLocalUnixMakefileGenerator3::GetImplicitDepends(const cmGeneratorTarget* tgt)
}
void cmLocalUnixMakefileGenerator3::AddImplicitDepends(
- const cmGeneratorTarget* tgt, const std::string& lang, const char* obj,
- const char* src)
+ const cmGeneratorTarget* tgt, const std::string& lang,
+ const std::string& obj, const std::string& src)
{
this->ImplicitDepends[tgt->GetName()][lang][obj].push_back(src);
}
void cmLocalUnixMakefileGenerator3::CreateCDCommand(
- std::vector<std::string>& commands, const char* tgtDir,
+ std::vector<std::string>& commands, std::string const& tgtDir,
std::string const& relDir)
{
// do we need to cd?
@@ -2098,7 +2124,7 @@ void cmLocalUnixMakefileGenerator3::CreateCDCommand(
// Change back to the starting directory.
cmd = cd_cmd;
cmd += this->ConvertToOutputForExisting(relDir);
- commands.push_back(cmd);
+ commands.push_back(std::move(cmd));
} else {
// On UNIX we must construct a single shell command to change
// directory and build because make resets the directory between
@@ -2106,16 +2132,6 @@ void cmLocalUnixMakefileGenerator3::CreateCDCommand(
std::string outputForExisting = this->ConvertToOutputForExisting(tgtDir);
std::string prefix = cd_cmd + outputForExisting + " && ";
std::transform(commands.begin(), commands.end(), commands.begin(),
- std::bind1st(std::plus<std::string>(), prefix));
- }
-}
-
-std::string cmLocalUnixMakefileGenerator3::MaybeConvertToRelativePath(
- std::string const& base, std::string const& path)
-{
- if (!cmOutputConverter::ContainedInDirectory(
- base, path, this->GetStateSnapshot().GetDirectory())) {
- return path;
+ [&prefix](std::string const& s) { return prefix + s; });
}
- return cmOutputConverter::ForceToRelativePath(base, path);
}
diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h
index f64409cba..c8e4b0e97 100644
--- a/Source/cmLocalUnixMakefileGenerator3.h
+++ b/Source/cmLocalUnixMakefileGenerator3.h
@@ -3,7 +3,7 @@
#ifndef cmLocalUnixMakefileGenerator3_h
#define cmLocalUnixMakefileGenerator3_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmDepends.h"
#include "cmLocalCommonGenerator.h"
@@ -12,6 +12,7 @@
#include <map>
#include <set>
#include <string>
+#include <utility>
#include <vector>
class cmCustomCommand;
@@ -19,7 +20,6 @@ class cmCustomCommandGenerator;
class cmGeneratorTarget;
class cmGlobalGenerator;
class cmMakefile;
-class cmSourceFile;
/** \class cmLocalUnixMakefileGenerator3
* \brief Write a LocalUnix makefiles.
@@ -31,14 +31,14 @@ class cmLocalUnixMakefileGenerator3 : public cmLocalCommonGenerator
{
public:
cmLocalUnixMakefileGenerator3(cmGlobalGenerator* gg, cmMakefile* mf);
- ~cmLocalUnixMakefileGenerator3() CM_OVERRIDE;
+ ~cmLocalUnixMakefileGenerator3() override;
- void ComputeHomeRelativeOutputPath() CM_OVERRIDE;
+ void ComputeHomeRelativeOutputPath() override;
/**
* Generate the makefile for this directory.
*/
- void Generate() CM_OVERRIDE;
+ void Generate() override;
// this returns the relative path between the HomeOutputDirectory and this
// local generators StartOutputDirectory
@@ -84,13 +84,13 @@ public:
void WriteDivider(std::ostream& os);
/** used to create a recursive make call */
- std::string GetRecursiveMakeCall(const char* makefile,
+ std::string GetRecursiveMakeCall(const std::string& makefile,
const std::string& tgt);
// append flags to a string
void AppendFlags(std::string& flags,
- const std::string& newFlags) CM_OVERRIDE;
- void AppendFlags(std::string& flags, const char* newFlags) CM_OVERRIDE;
+ const std::string& newFlags) const override;
+ void AppendFlags(std::string& flags, const char* newFlags) const override;
// append an echo command
enum EchoColor
@@ -108,20 +108,20 @@ public:
std::string Arg;
};
void AppendEcho(std::vector<std::string>& commands, std::string const& text,
- EchoColor color = EchoNormal,
- EchoProgress const* = CM_NULLPTR);
+ EchoColor color = EchoNormal, EchoProgress const* = nullptr);
/** Get whether the makefile is to have color. */
bool GetColorMakefile() const { return this->ColorMakefile; }
- std::string GetTargetDirectory(cmGeneratorTarget const* target) const
- CM_OVERRIDE;
+ std::string GetTargetDirectory(
+ cmGeneratorTarget const* target) const override;
// create a command that cds to the start dir then runs the commands
void CreateCDCommand(std::vector<std::string>& commands,
- const char* targetDir, std::string const& relDir);
+ std::string const& targetDir,
+ std::string const& relDir);
- static std::string ConvertToQuotedOutputPath(const char* p,
+ static std::string ConvertToQuotedOutputPath(const std::string& p,
bool useWatcomQuote);
std::string CreateMakeVariable(const std::string& sin,
@@ -129,11 +129,11 @@ public:
/** Called from command-line hook to bring dependencies up to date
for a target. */
- bool UpdateDependencies(const char* tgtInfo, bool verbose,
- bool color) CM_OVERRIDE;
+ bool UpdateDependencies(const std::string& tgtInfo, bool verbose,
+ bool color) override;
/** Called from command-line hook to clear dependencies. */
- void ClearDependencies(cmMakefile* mf, bool verbose) CM_OVERRIDE;
+ void ClearDependencies(cmMakefile* mf, bool verbose) override;
/** write some extra rules such as make test etc */
void WriteSpecialTargetsTop(std::ostream& makefileStream);
@@ -143,8 +143,7 @@ public:
// 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 ImplicitDependFileMap : public cmDepends::DependencyMap
{
};
struct ImplicitDependLanguageMap
@@ -159,8 +158,8 @@ public:
cmGeneratorTarget const* tgt);
void AddImplicitDepends(cmGeneratorTarget const* tgt,
- const std::string& lang, const char* obj,
- const char* src);
+ const std::string& lang, const std::string& obj,
+ const std::string& src);
// write the target rules for the local Makefile into the stream
void WriteLocalAllRules(std::ostream& ruleFileStream);
@@ -184,9 +183,6 @@ public:
// Eclipse generator.
void GetIndividualFileTargets(std::vector<std::string>& targets);
- std::string MaybeConvertToRelativePath(std::string const& base,
- std::string const& path);
-
protected:
void WriteLocalMakefile();
@@ -201,9 +197,6 @@ protected:
void WriteDependLanguageInfo(std::ostream& cmakefileStream,
cmGeneratorTarget* 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);
@@ -212,15 +205,6 @@ protected:
const std::string& realTarget,
const std::string& helpTarget);
- void WriteTargetDependRule(std::ostream& ruleFileStream,
- cmGeneratorTarget* target);
- void WriteTargetCleanRule(std::ostream& ruleFileStream,
- cmGeneratorTarget* target,
- const std::vector<std::string>& files);
- void WriteTargetRequiresRule(std::ostream& ruleFileStream,
- cmGeneratorTarget* target,
- const std::vector<std::string>& objects);
-
void AppendRuleDepend(std::vector<std::string>& depends,
const char* ruleFileName);
void AppendRuleDepends(std::vector<std::string>& depends,
@@ -238,25 +222,23 @@ protected:
cmGeneratorTarget* target,
std::string const& relative,
bool echo_comment = false,
- std::ostream* content = CM_NULLPTR);
+ std::ostream* content = nullptr);
void AppendCleanCommand(std::vector<std::string>& commands,
- const std::vector<std::string>& files,
+ const std::set<std::string>& files,
cmGeneratorTarget* target,
- const char* filename = CM_NULLPTR);
-
- // Helper methods for dependeny updates.
- bool ScanDependencies(
- const char* targetDir,
- std::map<std::string, cmDepends::DependencyVector>& validDeps);
+ const char* filename = nullptr);
+ void AppendDirectoryCleanCommand(std::vector<std::string>& commands);
+
+ // Helper methods for dependency updates.
+ bool ScanDependencies(std::string const& targetDir,
+ std::string const& dependFile,
+ std::string const& internalDependFile,
+ cmDepends::DependencyMap& validDeps);
void CheckMultipleOutputs(bool verbose);
private:
std::string MaybeConvertWatcomShellCommand(std::string const& cmd);
- void ComputeObjectFilenames(
- std::map<cmSourceFile const*, std::string>& mapping,
- cmGeneratorTarget const* gt = CM_NULLPTR) CM_OVERRIDE;
-
friend class cmMakefileTargetGenerator;
friend class cmMakefileExecutableTargetGenerator;
friend class cmMakefileLibraryTargetGenerator;
@@ -269,36 +251,27 @@ private:
struct LocalObjectEntry
{
- cmGeneratorTarget* Target;
+ cmGeneratorTarget* Target = nullptr;
std::string Language;
- LocalObjectEntry()
- : Target(CM_NULLPTR)
- , Language()
- {
- }
- LocalObjectEntry(cmGeneratorTarget* t, const std::string& lang)
+ LocalObjectEntry() = default;
+ LocalObjectEntry(cmGeneratorTarget* t, std::string lang)
: Target(t)
- , Language(lang)
+ , Language(std::move(lang))
{
}
};
struct LocalObjectInfo : public std::vector<LocalObjectEntry>
{
- bool HasSourceExtension;
- bool HasPreprocessRule;
- bool HasAssembleRule;
- LocalObjectInfo()
- : HasSourceExtension(false)
- , HasPreprocessRule(false)
- , HasAssembleRule(false)
- {
- }
+ bool HasSourceExtension = false;
+ bool HasPreprocessRule = false;
+ bool HasAssembleRule = false;
};
void GetLocalObjectFiles(
std::map<std::string, LocalObjectInfo>& localObjectFiles);
void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
- const char* comment, const char* output,
+ const char* comment,
+ const std::string& output,
LocalObjectInfo const& info);
std::vector<std::string> LocalHelp;
diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx
index 85d4a73b7..d45c3356d 100644
--- a/Source/cmLocalVisualStudio10Generator.cxx
+++ b/Source/cmLocalVisualStudio10Generator.cxx
@@ -7,6 +7,7 @@
#include "cmMakefile.h"
#include "cmVisualStudio10TargetGenerator.h"
#include "cmXMLParser.h"
+#include "cmake.h"
#include "cm_expat.h"
@@ -17,7 +18,12 @@ public:
virtual void CharacterDataHandler(const char* data, int length)
{
if (this->DoGUID) {
- this->GUID.assign(data + 1, length - 2);
+ if (data[0] == '{') {
+ // remove surrounding curly brackets
+ this->GUID.assign(data + 1, length - 2);
+ } else {
+ this->GUID.assign(data, length);
+ }
this->DoGUID = false;
}
}
@@ -57,23 +63,48 @@ cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
{
}
-void cmLocalVisualStudio10Generator::Generate()
+void cmLocalVisualStudio10Generator::GenerateTargetsDepthFirst(
+ cmGeneratorTarget* target, std::vector<cmGeneratorTarget*>& remaining)
{
+ if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ return;
+ }
+ // Find this target in the list of remaining targets.
+ auto it = std::find(remaining.begin(), remaining.end(), target);
+ if (it == remaining.end()) {
+ // This target was already handled.
+ return;
+ }
+ // Remove this target from the list of remaining targets because
+ // we are handling it now.
+ *it = nullptr;
+ auto& deps = this->GlobalGenerator->GetTargetDirectDepends(target);
+ for (auto& d : deps) {
+ // FIXME: Revise CreateSingleVCProj so we do not have to drop `const` here.
+ auto dependee = const_cast<cmGeneratorTarget*>(&*d);
+ GenerateTargetsDepthFirst(dependee, remaining);
+ // Take the union of visited source files of custom commands
+ auto visited = GetSourcesVisited(dependee);
+ GetSourcesVisited(target).insert(visited.begin(), visited.end());
+ }
+ if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
+ ->TargetIsFortranOnly(target)) {
+ this->CreateSingleVCProj(target->GetName(), target);
+ } else {
+ cmVisualStudio10TargetGenerator tg(
+ target,
+ static_cast<cmGlobalVisualStudio10Generator*>(
+ this->GetGlobalGenerator()));
+ tg.Generate();
+ }
+}
- std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); ++l) {
- if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
- continue;
- }
- if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
- ->TargetIsFortranOnly(*l)) {
- this->CreateSingleVCProj((*l)->GetName().c_str(), *l);
- } else {
- cmVisualStudio10TargetGenerator tg(
- *l, static_cast<cmGlobalVisualStudio10Generator*>(
- this->GetGlobalGenerator()));
- tg.Generate();
+void cmLocalVisualStudio10Generator::Generate()
+{
+ std::vector<cmGeneratorTarget*> remaining = this->GetGeneratorTargets();
+ for (auto& t : remaining) {
+ if (t) {
+ GenerateTargetsDepthFirst(t, remaining);
}
}
this->WriteStampFiles();
diff --git a/Source/cmLocalVisualStudio10Generator.h b/Source/cmLocalVisualStudio10Generator.h
index e57dd8f20..5c6400e9f 100644
--- a/Source/cmLocalVisualStudio10Generator.h
+++ b/Source/cmLocalVisualStudio10Generator.h
@@ -3,7 +3,7 @@
#ifndef cmLocalVisualStudio10Generator_h
#define cmLocalVisualStudio10Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -21,7 +21,7 @@ class cmMakefile;
class cmLocalVisualStudio10Generator : public cmLocalVisualStudio7Generator
{
public:
- ///! Set cache only and recurse to false by default.
+ //! Set cache only and recurse to false by default.
cmLocalVisualStudio10Generator(cmGlobalGenerator* gg, cmMakefile* mf);
virtual ~cmLocalVisualStudio10Generator();
@@ -29,14 +29,23 @@ public:
/**
* Generate the makefile for this directory.
*/
- virtual void Generate();
- virtual void ReadAndStoreExternalGUID(const std::string& name,
- const char* path);
+ void Generate() override;
+ void ReadAndStoreExternalGUID(const std::string& name,
+ const char* path) override;
+
+ std::set<cmSourceFile const*>& GetSourcesVisited(cmGeneratorTarget* target)
+ {
+ return SourcesVisited[target];
+ };
protected:
- virtual const char* ReportErrorLabel() const;
- virtual bool CustomCommandUseLocal() const { return true; }
+ const char* ReportErrorLabel() const override;
+ bool CustomCommandUseLocal() const override { return true; }
private:
+ void GenerateTargetsDepthFirst(cmGeneratorTarget* target,
+ std::vector<cmGeneratorTarget*>& remaining);
+
+ std::map<cmGeneratorTarget*, std::set<cmSourceFile const*>> SourcesVisited;
};
#endif
diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx
index dd08e5bdb..82a117060 100644
--- a/Source/cmLocalVisualStudio7Generator.cxx
+++ b/Source/cmLocalVisualStudio7Generator.cxx
@@ -2,10 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLocalVisualStudio7Generator.h"
+#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalVisualStudio7Generator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSourceFile.h"
#include "cmSystemTools.h"
#include "cmXMLParser.h"
@@ -36,16 +38,14 @@ private:
cmLocalVisualStudio7Generator* LocalGenerator;
};
-extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
-
-static void cmConvertToWindowsSlash(std::string& s)
+class cmLocalVisualStudio7Generator::AllConfigSources
{
- std::string::size_type pos = 0;
- while ((pos = s.find('/', pos)) != std::string::npos) {
- s[pos] = '\\';
- pos++;
- }
-}
+public:
+ std::vector<cmGeneratorTarget::AllConfigSource> Sources;
+ std::map<cmSourceFile const*, size_t> Index;
+};
+
+extern cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[];
cmLocalVisualStudio7Generator::cmLocalVisualStudio7Generator(
cmGlobalGenerator* gg, cmMakefile* mf)
@@ -62,15 +62,14 @@ cmLocalVisualStudio7Generator::~cmLocalVisualStudio7Generator()
void cmLocalVisualStudio7Generator::AddHelperCommands()
{
// Now create GUIDs for targets
- std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); ++l) {
- if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
+ for (cmGeneratorTarget const* l : tgts) {
+ if (l->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
- const char* path = (*l)->GetProperty("EXTERNAL_MSPROJECT");
+ const char* path = l->GetProperty("EXTERNAL_MSPROJECT");
if (path) {
- this->ReadAndStoreExternalGUID((*l)->GetName().c_str(), path);
+ this->ReadAndStoreExternalGUID(l->GetName(), path);
}
}
@@ -83,53 +82,34 @@ void cmLocalVisualStudio7Generator::Generate()
this->WriteStampFiles();
}
-void cmLocalVisualStudio7Generator::AddCMakeListsRules()
-{
- // 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.
- std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); ++l) {
- if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) {
- continue;
- }
- if ((*l)->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
- (*l)->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.
- std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); l++) {
- if ((*l)->GetType() == cmStateEnums::GLOBAL_TARGET) {
+ const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
+ for (cmGeneratorTarget* l : tgts) {
+ if (l->GetType() == cmStateEnums::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 no_main_dependency;
std::string force = this->GetCurrentBinaryDirectory();
- force += cmake::GetCMakeFilesDirectory();
+ force += "/CMakeFiles";
force += "/";
- force += (*l)->GetName();
+ force += l->GetName();
force += "_force";
+ if (cmSourceFile* sf = this->Makefile->GetOrCreateSource(
+ force, true, cmSourceFileLocationKind::Known)) {
+ sf->SetProperty("SYMBOLIC", "1");
+ }
if (cmSourceFile* file = this->Makefile->AddCustomCommandToOutput(
force.c_str(), no_depends, no_main_dependency, force_commands, " ",
0, true)) {
- (*l)->AddSource(file->GetFullPath());
+ l->AddSource(file->GetFullPath());
}
}
}
@@ -141,27 +121,25 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
void cmLocalVisualStudio7Generator::WriteProjectFiles()
{
// If not an in source build, then create the output directory
- if (strcmp(this->GetCurrentBinaryDirectory(), this->GetSourceDirectory()) !=
- 0) {
+ if (this->GetCurrentBinaryDirectory() != this->GetSourceDirectory()) {
if (!cmSystemTools::MakeDirectory(this->GetCurrentBinaryDirectory())) {
- cmSystemTools::Error("Error creating directory ",
+ cmSystemTools::Error("Error creating directory " +
this->GetCurrentBinaryDirectory());
}
}
// Get the set of targets in this directory.
- std::vector<cmGeneratorTarget*> tgts = this->GetGeneratorTargets();
+ const std::vector<cmGeneratorTarget*>& tgts = this->GetGeneratorTargets();
// Create the project file for each target.
- for (std::vector<cmGeneratorTarget*>::iterator l = tgts.begin();
- l != tgts.end(); l++) {
- if ((*l)->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ for (cmGeneratorTarget* l : tgts) {
+ if (l->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
continue;
}
// INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
// so don't build a projectfile for it
- if (!(*l)->GetProperty("EXTERNAL_MSPROJECT")) {
- this->CreateSingleVCProj((*l)->GetName().c_str(), *l);
+ if (!l->GetProperty("EXTERNAL_MSPROJECT")) {
+ this->CreateSingleVCProj(l->GetName(), l);
}
}
}
@@ -171,7 +149,7 @@ void cmLocalVisualStudio7Generator::WriteStampFiles()
// Touch a timestamp file used to determine when the project file is
// out of date.
std::string stampName = this->GetCurrentBinaryDirectory();
- stampName += cmake::GetCMakeFilesDirectory();
+ stampName += "/CMakeFiles";
cmSystemTools::MakeDirectory(stampName.c_str());
stampName += "/";
stampName += "generate.stamp";
@@ -188,10 +166,21 @@ void cmLocalVisualStudio7Generator::WriteStampFiles()
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;
+
+ std::vector<std::string> listFiles(this->Makefile->GetListFiles());
+ cmake* cm = this->GlobalGenerator->GetCMakeInstance();
+ if (cm->DoWriteGlobVerifyTarget()) {
+ listFiles.push_back(cm->GetGlobVerifyStamp());
+ }
+
+ // 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());
+
+ for (const std::string& lf : listFiles) {
+ depFile << lf << "\n";
}
}
@@ -238,23 +227,46 @@ void cmLocalVisualStudio7Generator::CreateSingleVCProj(
cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
{
+ if (this->GlobalGenerator->GlobalSettingIsOn(
+ "CMAKE_SUPPRESS_REGENERATION")) {
+ return nullptr;
+ }
+
+ std::string makefileIn = this->GetCurrentSourceDirectory();
+ makefileIn += "/";
+ makefileIn += "CMakeLists.txt";
+ makefileIn = cmSystemTools::CollapseFullPath(makefileIn);
+ if (cmSourceFile* file = this->Makefile->GetSource(makefileIn)) {
+ if (file->GetCustomCommand()) {
+ return file;
+ }
+ }
+ if (!cmSystemTools::FileExists(makefileIn)) {
+ return nullptr;
+ }
+
+ std::vector<std::string> listFiles = this->Makefile->GetListFiles();
+ cmake* cm = this->GlobalGenerator->GetCMakeInstance();
+ if (cm->DoWriteGlobVerifyTarget()) {
+ listFiles.push_back(cm->GetGlobVerifyStamp());
+ }
+
+ // 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());
+
std::string stampName = this->GetCurrentBinaryDirectory();
stampName += "/";
- stampName += cmake::GetCMakeFilesDirectoryPostSlash();
+ stampName += "CMakeFiles/";
stampName += "generate.stamp";
cmCustomCommandLine commandLine;
commandLine.push_back(cmSystemTools::GetCMakeCommand());
- std::string makefileIn = this->GetCurrentSourceDirectory();
- 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 = "-S";
args += this->GetSourceDirectory();
commandLine.push_back(args);
args = "-B";
@@ -262,22 +274,22 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
commandLine.push_back(args);
commandLine.push_back("--check-stamp-file");
commandLine.push_back(stampName);
-
- std::vector<std::string> const& listFiles = this->Makefile->GetListFiles();
-
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
const char* no_working_directory = 0;
std::string fullpathStampName =
cmSystemTools::CollapseFullPath(stampName.c_str());
this->Makefile->AddCustomCommandToOutput(
- fullpathStampName.c_str(), listFiles, makefileIn.c_str(), commandLines,
- comment.c_str(), no_working_directory, true, false);
+ fullpathStampName, listFiles, makefileIn, commandLines, comment.c_str(),
+ no_working_directory, true, false);
if (cmSourceFile* file = this->Makefile->GetSource(makefileIn.c_str())) {
+ // Finalize the source file path now since we're adding this after
+ // the generator validated all project-named sources.
+ file->GetFullPath();
return file;
} else {
- cmSystemTools::Error("Error adding rule for ", makefileIn.c_str());
- return 0;
+ cmSystemTools::Error("Error adding rule for " + makefileIn);
+ return nullptr;
}
}
@@ -286,9 +298,8 @@ void cmLocalVisualStudio7Generator::WriteConfigurations(
const std::string& libName, cmGeneratorTarget* target)
{
fout << "\t<Configurations>\n";
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
- this->WriteConfiguration(fout, i->c_str(), libName, target);
+ for (std::string const& config : configs) {
+ this->WriteConfiguration(fout, config.c_str(), libName, target);
}
fout << "\t</Configurations>\n";
}
@@ -356,7 +367,7 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranFlagTable[] = {
{ "EnableRecursion", "recursive", "", "true", 0 },
{ "ReentrantCode", "reentrancy", "", "true", 0 },
// done up to Language
- { 0, 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
@@ -466,7 +477,7 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] = {
{ "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 }
+ { "", "", "", "", 0 }
};
cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] = {
@@ -525,12 +536,13 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorLinkFlagTable[] = {
{ "TargetMachine", "MACHINE:SH5", "Machine SH5", "15", 0 },
{ "TargetMachine", "MACHINE:THUMB", "Machine THUMB", "16", 0 },
{ "TargetMachine", "MACHINE:X64", "Machine x64", "17", 0 },
+ { "TargetMachine", "MACHINE:ARM64", "Machine ARM64", "18", 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 }
+ { "", "", "", "", 0 }
};
cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] = {
@@ -538,7 +550,7 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] = {
"linkIncrementalNo", 0 },
{ "LinkIncremental", "INCREMENTAL:YES", "link incremental",
"linkIncrementalYes", 0 },
- { 0, 0, 0, 0, 0 }
+ { "", "", "", "", 0 }
};
// Helper class to write build event <Tool .../> elements.
@@ -561,9 +573,8 @@ public:
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);
+ for (cmCustomCommand const& command : ccs) {
+ this->Write(command);
}
}
void Write(cmCustomCommand const& cc)
@@ -616,6 +627,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
switch (target->GetType()) {
case cmStateEnums::OBJECT_LIBRARY:
targetBuilds = false; // no manifest tool for object library
+ CM_FALLTHROUGH;
case cmStateEnums::STATIC_LIBRARY:
projectType = "typeStaticLibrary";
configType = "4";
@@ -631,6 +643,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
case cmStateEnums::UTILITY:
case cmStateEnums::GLOBAL_TARGET:
configType = "10";
+ CM_FALLTHROUGH;
default:
targetBuilds = false;
break;
@@ -639,26 +652,21 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
configType = projectType;
}
std::string flags;
- if (strcmp(configType, "10") != 0) {
+ std::string langForClCompile;
+ if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
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());
+ "CMake can not determine linker language for target: " +
+ target->GetName());
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());
+ langForClCompile = linkLanguage;
+ if (langForClCompile == "C" || langForClCompile == "CXX" ||
+ langForClCompile == "Fortran") {
+ this->AddLanguageFlags(flags, target, langForClCompile, configName);
}
// set the correct language
if (linkLanguage == "C") {
@@ -669,7 +677,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
}
// Add the target-specific flags.
- this->AddCompileOptions(flags, target, linkLanguage, configName);
+ this->AddCompileOptions(flags, target, langForClCompile, configName);
// Check IPO related warning/error.
target->IsIPOEnabled(linkLanguage, configName);
@@ -699,14 +707,20 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
}
Options targetOptions(this, t, table, gg->ExtraFlagTable);
targetOptions.FixExceptionHandlingDefault();
- std::string asmLocation = configName + "/";
- targetOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
- targetOptions.Parse(flags.c_str());
- targetOptions.Parse(defineFlags.c_str());
+ targetOptions.AddFlag("AssemblerListingLocation", "$(IntDir)\\");
+ targetOptions.Parse(flags);
+ targetOptions.Parse(defineFlags);
targetOptions.ParseFinish();
- std::vector<std::string> targetDefines;
- target->GetCompileDefinitions(targetDefines, configName, "CXX");
- targetOptions.AddDefines(targetDefines);
+ if (!langForClCompile.empty()) {
+ std::vector<std::string> targetDefines;
+ target->GetCompileDefinitions(targetDefines, configName, langForClCompile);
+ targetOptions.AddDefines(targetDefines);
+
+ std::vector<std::string> targetIncludes;
+ this->GetIncludeDirectories(targetIncludes, target, langForClCompile,
+ configName);
+ targetOptions.AddIncludes(targetIncludes);
+ }
targetOptions.SetVerboseMakefile(
this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
@@ -717,8 +731,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
targetOptions.AddDefine(configDefine);
// Add the export symbol definition for shared library objects.
- if (const char* exportMacro = target->GetExportMacro()) {
- targetOptions.AddDefine(exportMacro);
+ if (const std::string* exportMacro = target->GetExportMacro()) {
+ targetOptions.AddDefine(*exportMacro);
}
// The intermediate directory name consists of a directory for the
@@ -784,8 +798,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
target->GetProperty("Fortran_MODULE_DIRECTORY");
std::string modDir;
if (target_mod_dir) {
- modDir = this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(),
- target_mod_dir);
+ modDir = this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), target_mod_dir);
} else {
modDir = ".";
}
@@ -793,26 +807,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
<< this->ConvertToXMLOutputPath(modDir.c_str())
<< "\\$(ConfigurationName)\"\n";
}
- fout << "\t\t\t\tAdditionalIncludeDirectories=\"";
- std::vector<std::string> includes;
- this->GetIncludeDirectories(includes, target, "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");
+ targetOptions.OutputAdditionalIncludeDirectories(
+ fout, 4, this->FortranProject ? "Fortran" : langForClCompile);
+ targetOptions.OutputFlagMap(fout, 4);
+ targetOptions.OutputPreprocessorDefinitions(fout, 4, langForClCompile);
fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
if (target->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
// Specify the compiler program database file if configured.
@@ -829,21 +827,12 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
fout <<
"\t\t\t<Tool\n"
"\t\t\t\tName=\"MASM\"\n"
- "\t\t\t\tIncludePaths=\""
;
/* clang-format on */
- 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";
+ targetOptions.OutputAdditionalIncludeDirectories(fout, 4, "ASM_MASM");
// Use same preprocessor definitions as VCCLCompilerTool.
- targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n",
- "ASM_MASM");
- masmOptions.OutputFlagMap(fout, "\t\t\t\t");
+ targetOptions.OutputPreprocessorDefinitions(fout, 4, "ASM_MASM");
+ masmOptions.OutputFlagMap(fout, 4);
/* clang-format off */
fout <<
"\t\t\t\tObjectFile=\"$(IntDir)\\\"\n"
@@ -859,27 +848,17 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
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 << ";";
- }
+ fout << "\t\t\t<Tool\n\t\t\t\tName=\"" << tool << "\"\n";
+ targetOptions.OutputAdditionalIncludeDirectories(fout, 4, "RC");
// add the -D flags to the RC tool
- fout << "\"";
- targetOptions.OutputPreprocessorDefinitions(fout, "\n\t\t\t\t", "", "RC");
- fout << "/>\n";
+ targetOptions.OutputPreprocessorDefinitions(fout, 4, "RC");
+ fout << "\t\t\t/>\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";
+ targetOptions.OutputAdditionalIncludeDirectories(fout, 4, "MIDL");
fout << "\t\t\t\tMkTypLibCompatible=\"false\"\n";
if (gg->GetPlatformName() == "x64") {
fout << "\t\t\t\tTargetEnvironment=\"3\"\n";
@@ -913,10 +892,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(
target->GetManifests(manifest_srcs, configName);
if (!manifest_srcs.empty()) {
fout << "\n\t\t\t\tAdditionalManifestFiles=\"";
- for (std::vector<cmSourceFile const*>::const_iterator mi =
- manifest_srcs.begin();
- mi != manifest_srcs.end(); ++mi) {
- std::string m = (*mi)->GetFullPath();
+ for (cmSourceFile const* manifest : manifest_srcs) {
+ std::string m = manifest->GetFullPath();
fout << this->ConvertToXMLOutputPath(m.c_str()) << ";";
}
fout << "\"";
@@ -947,9 +924,8 @@ std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags(
std::string extraLinkOptionsBuildTypeDef =
rootLinkerFlags + "_" + configTypeUpper;
- std::string extraLinkOptionsBuildType =
- this->Makefile->GetRequiredDefinition(
- extraLinkOptionsBuildTypeDef.c_str());
+ const std::string& extraLinkOptionsBuildType =
+ this->Makefile->GetRequiredDefinition(extraLinkOptionsBuildTypeDef);
return extraLinkOptionsBuildType;
}
@@ -964,21 +940,18 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
std::string extraLinkOptions;
if (target->GetType() == cmStateEnums::EXECUTABLE) {
extraLinkOptions =
- this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") +
- std::string(" ") +
+ this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS") + " " +
GetBuildTypeLinkerFlags("CMAKE_EXE_LINKER_FLAGS", configName);
}
if (target->GetType() == cmStateEnums::SHARED_LIBRARY) {
extraLinkOptions =
this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS") +
- std::string(" ") +
- GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
+ " " + GetBuildTypeLinkerFlags("CMAKE_SHARED_LINKER_FLAGS", configName);
}
if (target->GetType() == cmStateEnums::MODULE_LIBRARY) {
extraLinkOptions =
this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS") +
- std::string(" ") +
- GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
+ " " + GetBuildTypeLinkerFlags("CMAKE_MODULE_LINKER_FLAGS", configName);
}
const char* targetLinkFlags = target->GetProperty("LINK_FLAGS");
@@ -994,19 +967,26 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
extraLinkOptions += " ";
extraLinkOptions += targetLinkFlags;
}
+
+ std::vector<std::string> opts;
+ target->GetLinkOptions(opts, configName,
+ target->GetLinkerLanguage(configName));
+ // LINK_OPTIONS are escaped.
+ this->AppendCompileOptions(extraLinkOptions, opts);
+
Options linkOptions(this, Options::Linker);
if (this->FortranProject) {
linkOptions.AddTable(cmLocalVisualStudio7GeneratorFortranLinkFlagTable);
}
linkOptions.AddTable(cmLocalVisualStudio7GeneratorLinkFlagTable);
- linkOptions.Parse(extraLinkOptions.c_str());
+ linkOptions.Parse(extraLinkOptions);
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
target->GetModuleDefinitionInfo(configName);
if (mdi && !mdi->DefFile.empty()) {
std::string defFile =
this->ConvertToOutputFormat(mdi->DefFile, cmOutputConverter::SHELL);
- linkOptions.AddFlag("ModuleDefinitionFile", defFile.c_str());
+ linkOptions.AddFlag("ModuleDefinitionFile", defFile);
}
switch (target->GetType()) {
@@ -1048,7 +1028,9 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
}
}
std::string libflags;
- this->GetStaticLibraryFlags(libflags, configTypeUpper, target);
+ this->GetStaticLibraryFlags(libflags, configTypeUpper,
+ target->GetLinkerLanguage(configName),
+ target);
if (!libflags.empty()) {
fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
}
@@ -1058,13 +1040,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
}
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::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);
+ cmGeneratorTarget::Names targetNames =
+ target->GetLibraryNames(configName);
// Compute the link library and directory information.
cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
@@ -1091,7 +1068,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
// 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());
+ << this->Makefile->GetSafeDefinition(standardLibsVar);
if (this->FortranProject) {
this->Internal->OutputObjects(fout, target, configName, " ");
}
@@ -1100,17 +1077,17 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "\"\n";
temp = target->GetDirectory(configName);
temp += "/";
- temp += targetNameFull;
+ temp += targetNames.Output;
fout << "\t\t\t\tOutputFile=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
this->WriteTargetVersionAttribute(fout, target);
- linkOptions.OutputFlagMap(fout, "\t\t\t\t");
+ linkOptions.OutputFlagMap(fout, 4);
fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
this->OutputLibraryDirectories(fout, cli.GetDirectories());
fout << "\"\n";
temp = target->GetPDBDirectory(configName);
temp += "/";
- temp += targetNamePDB;
+ temp += targetNames.PDB;
fout << "\t\t\t\tProgramDatabaseFile=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
if (targetOptions.IsDebug()) {
@@ -1133,7 +1110,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
temp =
target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
temp += "/";
- temp += targetNameImport;
+ temp += targetNames.ImportLibrary;
fout << "\t\t\t\tImportLibrary=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"";
if (this->FortranProject) {
@@ -1142,12 +1119,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "/>\n";
} break;
case cmStateEnums::EXECUTABLE: {
- std::string targetName;
- std::string targetNameFull;
- std::string targetNameImport;
- std::string targetNamePDB;
- target->GetExecutableNames(targetName, targetNameFull, targetNameImport,
- targetNamePDB, configName);
+ cmGeneratorTarget::Names targetNames =
+ target->GetExecutableNames(configName);
// Compute the link library and directory information.
cmComputeLinkInformation* pcli = target->GetLinkInformation(configName);
@@ -1176,7 +1149,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
// 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());
+ << this->Makefile->GetSafeDefinition(standardLibsVar);
if (this->FortranProject) {
this->Internal->OutputObjects(fout, target, configName, " ");
}
@@ -1185,18 +1158,18 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
fout << "\"\n";
temp = target->GetDirectory(configName);
temp += "/";
- temp += targetNameFull;
+ temp += targetNames.Output;
fout << "\t\t\t\tOutputFile=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
this->WriteTargetVersionAttribute(fout, target);
- linkOptions.OutputFlagMap(fout, "\t\t\t\t");
+ linkOptions.OutputFlagMap(fout, 4);
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";
+ fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/"
+ << targetNames.PDB << "\"\n";
if (targetOptions.IsDebug()) {
fout << "\t\t\t\tGenerateDebugInformation=\"true\"\n";
}
@@ -1231,7 +1204,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
temp =
target->GetDirectory(configName, cmStateEnums::ImportLibraryArtifact);
temp += "/";
- temp += targetNameImport;
+ temp += targetNames.ImportLibrary;
fout << "\t\t\t\tImportLibrary=\""
<< this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"/>\n";
break;
@@ -1243,30 +1216,56 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(
}
}
+static 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;
+}
+
+static std::string GetEscapedPropertyIfValueNotNULL(const char* propertyValue)
+{
+ return propertyValue == nullptr
+ ? std::string()
+ : cmLocalVisualStudio7GeneratorEscapeForXML(propertyValue);
+}
+
void cmLocalVisualStudio7Generator::OutputDeploymentDebuggerTool(
std::ostream& fout, std::string const& config, cmGeneratorTarget* target)
{
if (this->WindowsCEProject) {
- if (const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY")) {
- /* clang-format off */
- fout <<
- "\t\t\t<DeploymentTool\n"
- "\t\t\t\tForceDirty=\"-1\"\n"
- "\t\t\t\tRemoteDirectory=\"" << this->EscapeForXML(dir) << "\"\n"
- "\t\t\t\tRegisterOutput=\"0\"\n"
- "\t\t\t\tAdditionalFiles=\"\"/>\n"
- ;
- /* clang-format on */
+ const char* dir = target->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY");
+ const char* additionalFiles =
+ target->GetProperty("DEPLOYMENT_ADDITIONAL_FILES");
+
+ if (dir == nullptr && additionalFiles == nullptr) {
+ return;
+ }
+
+ fout << "\t\t\t<DeploymentTool\n"
+ "\t\t\t\tForceDirty=\"-1\"\n"
+ "\t\t\t\tRemoteDirectory=\""
+ << GetEscapedPropertyIfValueNotNULL(dir)
+ << "\"\n"
+ "\t\t\t\tRegisterOutput=\"0\"\n"
+ "\t\t\t\tAdditionalFiles=\""
+ << GetEscapedPropertyIfValueNotNULL(additionalFiles) << "\"/>\n";
+
+ if (dir != nullptr) {
std::string const exe =
dir + std::string("\\") + target->GetFullName(config);
- /* clang-format off */
- fout <<
- "\t\t\t<DebuggerTool\n"
- "\t\t\t\tRemoteExecutable=\"" << this->EscapeForXML(exe) << "\"\n"
- "\t\t\t\tArguments=\"\"\n"
- "\t\t\t/>\n"
- ;
- /* clang-format on */
+
+ fout << "\t\t\t<DebuggerTool\n"
+ "\t\t\t\tRemoteExecutable=\""
+ << this->EscapeForXML(exe)
+ << "\"\n"
+ "\t\t\t\tArguments=\"\"\n"
+ "\t\t\t/>\n";
}
}
}
@@ -1285,14 +1284,14 @@ void cmLocalVisualStudio7GeneratorInternals::OutputLibraries(
{
cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
std::string currentBinDir = lg->GetCurrentBinaryDirectory();
- for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
- if (l->IsPath) {
+ for (auto const& lib : libs) {
+ if (lib.IsPath) {
std::string rel =
- lg->ConvertToRelativePath(currentBinDir, l->Value.c_str());
+ lg->MaybeConvertToRelativePath(currentBinDir, lib.Value.c_str());
fout << lg->ConvertToXMLOutputPath(rel.c_str()) << " ";
- } else if (!l->Target ||
- l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
- fout << l->Value << " ";
+ } else if (!lib.Target ||
+ lib.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
+ fout << lib.Value << " ";
}
}
}
@@ -1310,11 +1309,10 @@ void cmLocalVisualStudio7GeneratorInternals::OutputObjects(
gt->GetExternalObjects(objs, configName);
const char* sep = isep ? isep : "";
- for (std::vector<cmSourceFile const*>::const_iterator i = objs.begin();
- i != objs.end(); ++i) {
- if (!(*i)->GetObjectLibrary().empty()) {
- std::string const& objFile = (*i)->GetFullPath();
- std::string rel = lg->ConvertToRelativePath(currentBinDir, objFile);
+ for (cmSourceFile const* obj : objs) {
+ if (!obj->GetObjectLibrary().empty()) {
+ std::string const& objFile = obj->GetFullPath();
+ std::string rel = lg->MaybeConvertToRelativePath(currentBinDir, objFile);
fout << sep << lg->ConvertToXMLOutputPath(rel.c_str());
sep = " ";
}
@@ -1326,11 +1324,9 @@ void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
{
const char* comma = "";
std::string currentBinDir = this->GetCurrentBinaryDirectory();
- for (std::vector<std::string>::const_iterator d = dirs.begin();
- d != dirs.end(); ++d) {
+ for (std::string dir : dirs) {
// Remove any trailing slash and skip empty paths.
- std::string dir = *d;
- if (dir[dir.size() - 1] == '/') {
+ if (dir.back() == '/') {
dir = dir.substr(0, dir.size() - 1);
}
if (dir.empty()) {
@@ -1340,7 +1336,7 @@ void cmLocalVisualStudio7Generator::OutputLibraryDirectories(
// Switch to a relative path specification if it is shorter.
if (cmSystemTools::FileIsFullPath(dir.c_str())) {
std::string rel =
- this->ConvertToRelativePath(currentBinDir, dir.c_str());
+ this->MaybeConvertToRelativePath(currentBinDir, dir.c_str());
if (rel.size() < dir.size()) {
dir = rel;
}
@@ -1366,13 +1362,37 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
// We may be modifying the source groups temporarily, so make a copy.
std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
- std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
- target->GetAllConfigSources();
- std::map<cmSourceFile const*, size_t> sourcesIndex;
+ AllConfigSources sources;
+ sources.Sources = target->GetAllConfigSources();
+
+ // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
+ if (target->GetType() != cmStateEnums::GLOBAL_TARGET &&
+ target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
+ if (cmSourceFile const* sf = this->CreateVCProjBuildRule()) {
+ cmGeneratorTarget::AllConfigSource acs;
+ acs.Source = sf;
+ acs.Kind = cmGeneratorTarget::SourceKindCustomCommand;
+ for (size_t ci = 0; ci < configs.size(); ++ci) {
+ acs.Configs.push_back(ci);
+ }
+ bool haveCMakeLists = false;
+ for (cmGeneratorTarget::AllConfigSource& si : sources.Sources) {
+ if (si.Source == sf) {
+ haveCMakeLists = true;
+ // Replace the explicit source reference with our generated one.
+ si = acs;
+ break;
+ }
+ }
+ if (!haveCMakeLists) {
+ sources.Sources.emplace_back(std::move(acs));
+ }
+ }
+ }
- for (size_t si = 0; si < sources.size(); ++si) {
- cmSourceFile const* sf = sources[si].Source;
- sourcesIndex[sf] = si;
+ for (size_t si = 0; si < sources.Sources.size(); ++si) {
+ cmSourceFile const* sf = sources.Sources[si].Source;
+ sources.Index[sf] = si;
if (!sf->GetObjectLibrary().empty()) {
if (this->FortranProject) {
// Intel Fortran does not support per-config source locations
@@ -1384,7 +1404,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
// Add the file to the list of sources.
std::string const source = sf->GetFullPath();
cmSourceGroup* sourceGroup =
- this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
+ this->Makefile->FindSourceGroup(source, sourceGroups);
sourceGroup->AssignSource(sf);
}
@@ -1398,7 +1418,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
// 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, sourcesIndex);
+ this->WriteGroup(&sg, target, fout, libName, configs, sources);
}
fout << "\t</Files>\n";
@@ -1414,6 +1434,7 @@ struct cmLVS7GFileConfig
std::string CompileDefs;
std::string CompileDefsConfig;
std::string AdditionalDeps;
+ std::string IncludeDirs;
bool ExcludedFromBuild;
};
@@ -1440,19 +1461,36 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
// Compute per-source, per-config information.
size_t ci = 0;
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i, ++ci) {
- std::string configUpper = cmSystemTools::UpperCase(*i);
+ for (std::string const& config : configs) {
+ std::string configUpper = cmSystemTools::UpperCase(config);
cmLVS7GFileConfig fc;
+
+ std::string lang =
+ lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
+ const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
+ bool needForceLang = false;
+ // source file does not match its extension language
+ if (lang != sourceLang) {
+ needForceLang = true;
+ lang = sourceLang;
+ }
+
+ cmGeneratorExpressionInterpreter genexInterpreter(lg, config, gt, lang);
+
bool needfc = false;
if (!objectName.empty()) {
fc.ObjectName = objectName;
needfc = true;
}
- if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
- cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags);
- fc.CompileFlags = cge->Evaluate(lg, *i);
+ const std::string COMPILE_FLAGS("COMPILE_FLAGS");
+ if (const char* cflags = sf.GetProperty(COMPILE_FLAGS)) {
+ fc.CompileFlags = genexInterpreter.Evaluate(cflags, COMPILE_FLAGS);
+ needfc = true;
+ }
+ const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
+ if (const char* coptions = sf.GetProperty(COMPILE_OPTIONS)) {
+ lg->AppendCompileOptions(
+ fc.CompileFlags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
needfc = true;
}
if (lg->FortranProject) {
@@ -1470,14 +1508,22 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
break;
}
}
- if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
- fc.CompileDefs = cdefs;
+ const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
+ if (const char* cdefs = sf.GetProperty(COMPILE_DEFINITIONS)) {
+ fc.CompileDefs = genexInterpreter.Evaluate(cdefs, COMPILE_DEFINITIONS);
needfc = true;
}
std::string defPropName = "COMPILE_DEFINITIONS_";
defPropName += configUpper;
- if (const char* ccdefs = sf.GetProperty(defPropName.c_str())) {
- fc.CompileDefsConfig = ccdefs;
+ if (const char* ccdefs = sf.GetProperty(defPropName)) {
+ fc.CompileDefsConfig =
+ genexInterpreter.Evaluate(ccdefs, COMPILE_DEFINITIONS);
+ needfc = true;
+ }
+
+ const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
+ if (const char* cincs = sf.GetProperty(INCLUDE_DIRECTORIES)) {
+ fc.IncludeDirs = genexInterpreter.Evaluate(cincs, INCLUDE_DIRECTORIES);
needfc = true;
}
@@ -1495,16 +1541,7 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
}
}
- std::string lang =
- lg->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
- const std::string& sourceLang = lg->GetSourceFileLanguage(sf);
- const std::string& linkLanguage = gt->GetLinkerLanguage(i->c_str());
- bool needForceLang = false;
- // source file does not match its extension language
- if (lang != sourceLang) {
- needForceLang = true;
- lang = sourceLang;
- }
+ const std::string& linkLanguage = gt->GetLinkerLanguage(config.c_str());
// If HEADER_FILE_ONLY is set, we must suppress this generation in
// the project file
fc.ExcludedFromBuild = sf.GetPropertyAsBool("HEADER_FILE_ONLY") ||
@@ -1529,8 +1566,9 @@ cmLocalVisualStudio7GeneratorFCInfo::cmLocalVisualStudio7GeneratorFCInfo(
}
if (needfc) {
- this->FileConfigMap[*i] = fc;
+ this->FileConfigMap[config] = fc;
}
+ ++ci;
}
}
@@ -1565,7 +1603,7 @@ std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory(
bool cmLocalVisualStudio7Generator::WriteGroup(
const cmSourceGroup* sg, cmGeneratorTarget* target, std::ostream& fout,
const std::string& libName, std::vector<std::string> const& configs,
- std::map<cmSourceFile const*, size_t> const& sourcesIndex)
+ AllConfigSources const& sources)
{
cmGlobalVisualStudio7Generator* gg =
static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator);
@@ -1577,7 +1615,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
std::ostringstream tmpOut;
for (unsigned int i = 0; i < children.size(); ++i) {
if (this->WriteGroup(&children[i], target, tmpOut, libName, configs,
- sourcesIndex)) {
+ sources)) {
hasChildrenWithSources = true;
}
}
@@ -1588,28 +1626,24 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
}
// If the group has a name, write the header.
- std::string name = sg->GetName();
- if (name != "") {
+ std::string const& name = sg->GetName();
+ if (!name.empty()) {
this->WriteVCProjBeginGroup(fout, name.c_str(), "");
}
- std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
- target->GetAllConfigSources();
-
// Loop through each source in the source group.
- for (std::vector<const cmSourceFile*>::const_iterator sf =
- sourceFiles.begin();
- sf != sourceFiles.end(); ++sf) {
- std::string source = (*sf)->GetFullPath();
+ for (const cmSourceFile* sf : sourceFiles) {
+ std::string source = sf->GetFullPath();
if (source != libName || target->GetType() == cmStateEnums::UTILITY ||
target->GetType() == cmStateEnums::GLOBAL_TARGET) {
// Look up the source kind and configs.
std::map<cmSourceFile const*, size_t>::const_iterator map_it =
- sourcesIndex.find(*sf);
+ sources.Index.find(sf);
// The map entry must exist because we populated it earlier.
- assert(map_it != sourcesIndex.end());
- cmGeneratorTarget::AllConfigSource const& acs = sources[map_it->second];
+ assert(map_it != sources.Index.end());
+ cmGeneratorTarget::AllConfigSource const& acs =
+ sources.Sources[map_it->second];
FCInfo fcinfo(this, target, acs, configs);
@@ -1618,16 +1652,16 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
// 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()) {
+ if (cmCustomCommand const* command = sf->GetCustomCommand()) {
this->WriteCustomRule(fout, configs, source.c_str(), *command, fcinfo);
} else if (!fcinfo.FileConfigMap.empty()) {
const char* aCompilerTool = "VCCLCompilerTool";
- const char* ppLang = "CXX";
+ std::string ppLang = "CXX";
if (this->FortranProject) {
aCompilerTool = "VFFortranCompilerTool";
}
- std::string const& lang = (*sf)->GetLanguage();
- std::string ext = (*sf)->GetExtension();
+ std::string const& lang = sf->GetLanguage();
+ std::string ext = sf->GetExtension();
ext = cmSystemTools::LowerCase(ext);
if (ext == "idl") {
aCompilerTool = "VCMIDLTool";
@@ -1655,12 +1689,10 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
if (acs.Kind == cmGeneratorTarget::SourceKindExternalObject) {
aCompilerTool = "VCCustomBuildTool";
}
- for (std::map<std::string, cmLVS7GFileConfig>::const_iterator fci =
- fcinfo.FileConfigMap.begin();
- fci != fcinfo.FileConfigMap.end(); ++fci) {
- cmLVS7GFileConfig const& fc = fci->second;
+ for (auto const& fci : fcinfo.FileConfigMap) {
+ cmLVS7GFileConfig const& fc = fci.second;
fout << "\t\t\t\t<FileConfiguration\n"
- << "\t\t\t\t\tName=\"" << fci->first << "|"
+ << "\t\t\t\t\tName=\"" << fci.first << "|"
<< gg->GetPlatformName() << "\"";
if (fc.ExcludedFromBuild) {
fout << " ExcludedFromBuild=\"true\"";
@@ -1669,7 +1701,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
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()) {
+ !fc.CompileDefsConfig.empty() || !fc.IncludeDirs.empty()) {
Options::Tool tool = Options::Compiler;
cmVS7FlagTable const* table =
cmLocalVisualStudio7GeneratorFlagTable;
@@ -1678,12 +1710,18 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
table = cmLocalVisualStudio7GeneratorFortranFlagTable;
}
Options fileOptions(this, tool, table, gg->ExtraFlagTable);
- fileOptions.Parse(fc.CompileFlags.c_str());
- fileOptions.AddDefines(fc.CompileDefs.c_str());
- fileOptions.AddDefines(fc.CompileDefsConfig.c_str());
- fileOptions.OutputFlagMap(fout, "\t\t\t\t\t");
- fileOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t\t", "\n",
- ppLang);
+ fileOptions.Parse(fc.CompileFlags);
+ fileOptions.AddDefines(fc.CompileDefs);
+ fileOptions.AddDefines(fc.CompileDefsConfig);
+ // validate source level include directories
+ std::vector<std::string> includes;
+ this->AppendIncludeDirectories(includes, fc.IncludeDirs, *sf);
+ fileOptions.AddIncludes(includes);
+ fileOptions.OutputFlagMap(fout, 5);
+ fileOptions.OutputAdditionalIncludeDirectories(
+ fout, 5,
+ ppLang == "CXX" && this->FortranProject ? "Fortran" : ppLang);
+ fileOptions.OutputPreprocessorDefinitions(fout, 5, ppLang);
}
if (!fc.AdditionalDeps.empty()) {
fout << "\t\t\t\t\tAdditionalDependencies=\"" << fc.AdditionalDeps
@@ -1707,7 +1745,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup(
}
// If the group has a name, write the footer.
- if (name != "") {
+ if (!name.empty()) {
this->WriteVCProjEndGroup(fout);
}
@@ -1730,12 +1768,11 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
if (this->FortranProject) {
customTool = "VFCustomBuildTool";
}
- for (std::vector<std::string>::const_iterator i = configs.begin();
- i != configs.end(); ++i) {
- cmCustomCommandGenerator ccg(command, *i, this);
- cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[*i];
+ for (std::string const& config : configs) {
+ cmCustomCommandGenerator ccg(command, config, this);
+ cmLVS7GFileConfig const& fc = fcinfo.FileConfigMap[config];
fout << "\t\t\t\t<FileConfiguration\n";
- fout << "\t\t\t\t\tName=\"" << *i << "|" << gg->GetPlatformName()
+ fout << "\t\t\t\t\tName=\"" << config << "|" << gg->GetPlatformName()
<< "\">\n";
if (!fc.CompileFlags.empty()) {
fout << "\t\t\t\t\t<Tool\n"
@@ -1747,7 +1784,7 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
std::string comment = this->ConstructComment(ccg);
std::string script = this->ConstructScript(ccg);
if (this->FortranProject) {
- cmSystemTools::ReplaceString(script, "$(Configuration)", i->c_str());
+ cmSystemTools::ReplaceString(script, "$(Configuration)", config.c_str());
}
/* clang-format off */
fout << "\t\t\t\t\t<Tool\n"
@@ -1768,12 +1805,10 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
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) {
+ for (std::string const& d : ccg.GetDepends()) {
// 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)) {
+ if (this->GetRealDependency(d.c_str(), config.c_str(), dep)) {
fout << this->ConvertToXMLOutputPath(dep.c_str()) << ";";
}
}
@@ -1785,10 +1820,8 @@ void cmLocalVisualStudio7Generator::WriteCustomRule(
} 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());
+ for (std::string const& output : ccg.GetOutputs()) {
+ fout << sep << this->ConvertToXMLOutputPathSingle(output.c_str());
sep = ";";
}
}
@@ -1847,7 +1880,7 @@ void cmLocalVisualStudio7Generator::OutputTargetRules(
if (!addedPrelink) {
event.Write(target->GetPreLinkCommands());
}
- CM_AUTO_PTR<cmCustomCommand> pcc(
+ std::unique_ptr<cmCustomCommand> pcc(
this->MaybeCreateImplibDir(target, configName, this->FortranProject));
if (pcc.get()) {
event.Write(*pcc);
@@ -1999,16 +2032,14 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter(
{
fout << "\t<Globals>\n";
- std::vector<std::string> const& props = target->GetPropertyKeys();
- for (std::vector<std::string>::const_iterator i = props.begin();
- i != props.end(); ++i) {
- if (i->find("VS_GLOBAL_") == 0) {
- std::string name = i->substr(10);
- if (name != "") {
+ for (std::string const& key : target->GetPropertyKeys()) {
+ if (key.find("VS_GLOBAL_") == 0) {
+ std::string name = key.substr(10);
+ if (!name.empty()) {
/* clang-format off */
fout << "\t\t<Global\n"
<< "\t\t\tName=\"" << name << "\"\n"
- << "\t\t\tValue=\"" << target->GetProperty(*i) << "\"\n"
+ << "\t\t\tValue=\"" << target->GetProperty(key) << "\"\n"
<< "\t\t/>\n";
/* clang-format on */
}
@@ -2019,17 +2050,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFooter(
<< "</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);
@@ -2059,6 +2079,19 @@ std::string cmLocalVisualStudio7Generator::ConvertToXMLOutputPathSingle(
return ret;
}
+void cmVS7GeneratorOptions::OutputFlag(std::ostream& fout, int indent,
+ const char* flag,
+ const std::string& content)
+{
+ fout.fill('\t');
+ fout.width(indent);
+ // write an empty string to get the fill level indent to print
+ fout << "";
+ fout << flag << "=\"";
+ fout << cmLocalVisualStudio7GeneratorEscapeForXML(content);
+ fout << "\"\n";
+}
+
// This class is used to parse an existing vs 7 project
// and extract the GUID
class cmVS7XMLParser : public cmXMLParser
@@ -2077,9 +2110,12 @@ public:
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);
+ if (this->GUID[0] == '{') {
+ // remove surrounding curly brackets
+ this->GUID = this->GUID.substr(1, this->GUID.size() - 2);
+ }
} else {
- this->GUID = "";
+ this->GUID.clear();
}
return;
}
diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h
index 89a3ee353..ce8eceb7e 100644
--- a/Source/cmLocalVisualStudio7Generator.h
+++ b/Source/cmLocalVisualStudio7Generator.h
@@ -3,7 +3,7 @@
#ifndef cmLocalVisualStudio7Generator_h
#define cmLocalVisualStudio7Generator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -21,6 +21,19 @@ class cmMakefile;
class cmSourceFile;
class cmSourceGroup;
+class cmVS7GeneratorOptions : public cmVisualStudioGeneratorOptions
+{
+public:
+ cmVS7GeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool,
+ cmVS7FlagTable const* table = nullptr,
+ cmVS7FlagTable const* extraTable = nullptr)
+ : cmVisualStudioGeneratorOptions(lg, tool, table, extraTable)
+ {
+ }
+ void OutputFlag(std::ostream& fout, int indent, const char* tag,
+ const std::string& content) override;
+};
+
/** \class cmLocalVisualStudio7Generator
* \brief Write Visual Studio .NET project files.
*
@@ -30,17 +43,17 @@ class cmSourceGroup;
class cmLocalVisualStudio7Generator : public cmLocalVisualStudioGenerator
{
public:
- ///! Set cache only and recurse to false by default.
+ //! Set cache only and recurse to false by default.
cmLocalVisualStudio7Generator(cmGlobalGenerator* gg, cmMakefile* mf);
virtual ~cmLocalVisualStudio7Generator();
- virtual void AddHelperCommands();
+ void AddHelperCommands() override;
/**
* Generate the makefile for this directory.
*/
- virtual void Generate();
+ void Generate() override;
enum BuildType
{
@@ -56,22 +69,21 @@ public:
*/
void SetBuildType(BuildType, const std::string& name);
- virtual std::string GetTargetDirectory(
- cmGeneratorTarget const* target) const;
+ std::string GetTargetDirectory(
+ cmGeneratorTarget const* target) const override;
cmSourceFile* CreateVCProjBuildRule();
void WriteStampFiles();
- virtual std::string ComputeLongestObjectDirectory(
- cmGeneratorTarget const*) const;
+ std::string ComputeLongestObjectDirectory(
+ cmGeneratorTarget const*) const override;
virtual void ReadAndStoreExternalGUID(const std::string& name,
const char* path);
- virtual void AddCMakeListsRules();
protected:
void CreateSingleVCProj(const std::string& lname, cmGeneratorTarget* tgt);
private:
- typedef cmVisualStudioGeneratorOptions Options;
+ typedef cmVS7GeneratorOptions Options;
typedef cmLocalVisualStudio7GeneratorFCInfo FCInfo;
std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags,
const std::string& configName);
@@ -117,10 +129,11 @@ private:
FCInfo& fcinfo);
void WriteTargetVersionAttribute(std::ostream& fout, cmGeneratorTarget* gt);
+ class AllConfigSources;
bool WriteGroup(const cmSourceGroup* sg, cmGeneratorTarget* target,
std::ostream& fout, const std::string& libName,
std::vector<std::string> const& configs,
- std::map<cmSourceFile const*, size_t> const& sourcesIndex);
+ AllConfigSources const& sources);
friend class cmLocalVisualStudio7GeneratorFCInfo;
friend class cmLocalVisualStudio7GeneratorInternals;
diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx
index 41025af6c..f3f2042ec 100644
--- a/Source/cmLocalVisualStudioGenerator.cxx
+++ b/Source/cmLocalVisualStudioGenerator.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmLocalVisualStudioGenerator.h"
+#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
@@ -39,10 +40,8 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
// 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;
+ for (auto const& si : mapping) {
+ cmSourceFile const* sf = si.first;
std::string objectNameLower = cmSystemTools::LowerCase(
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()));
if (custom_ext) {
@@ -57,10 +56,8 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
// 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;
+ for (auto& si : mapping) {
+ cmSourceFile const* sf = si.first;
std::string objectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
if (custom_ext) {
@@ -74,16 +71,16 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames(
objectName = this->GetObjectFileNameWithoutTarget(
*sf, dir_max, &keptSourceExtension, custom_ext);
}
- si->second = objectName;
+ si.second = objectName;
}
}
-CM_AUTO_PTR<cmCustomCommand>
+std::unique_ptr<cmCustomCommand>
cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target,
const std::string& config,
bool isFortran)
{
- CM_AUTO_PTR<cmCustomCommand> pcc;
+ std::unique_ptr<cmCustomCommand> pcc;
// If an executable exports symbols then VS wants to create an
// import library but forgets to create the output directory.
@@ -135,7 +132,7 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
std::string workingDirectory = ccg.GetWorkingDirectory();
// Avoid leading or trailing newlines.
- std::string newline = "";
+ std::string newline;
// Line to check for error between commands.
std::string check_error = newline_text;
@@ -191,13 +188,17 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
// Write each command on a single line.
for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) {
+ // Add this command line.
+ std::string cmd = ccg.GetCommand(c);
+
+ if (cmd.empty()) {
+ continue;
+ }
+
// 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.
//
@@ -210,9 +211,10 @@ std::string cmLocalVisualStudioGenerator::ConstructScript(
}
if (workingDirectory.empty()) {
- script += this->ConvertToOutputFormat(
- this->ConvertToRelativePath(this->GetCurrentBinaryDirectory(), cmd),
- cmOutputConverter::SHELL);
+ script +=
+ this->ConvertToOutputFormat(this->MaybeConvertToRelativePath(
+ this->GetCurrentBinaryDirectory(), cmd),
+ cmOutputConverter::SHELL);
} else {
script += this->ConvertToOutputFormat(cmd.c_str(), SHELL);
}
diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h
index 85fb8a511..3fdafd2b2 100644
--- a/Source/cmLocalVisualStudioGenerator.h
+++ b/Source/cmLocalVisualStudioGenerator.h
@@ -3,15 +3,14 @@
#ifndef cmLocalVisualStudioGenerator_h
#define cmLocalVisualStudioGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
-#include <memory>
+#include <memory> // IWYU pragma: keep
#include <string>
#include "cmGlobalVisualStudioGenerator.h"
#include "cmLocalGenerator.h"
-#include "cm_auto_ptr.hxx"
class cmCustomCommand;
class cmCustomCommandGenerator;
@@ -45,20 +44,17 @@ public:
virtual std::string ComputeLongestObjectDirectory(
cmGeneratorTarget const*) const = 0;
- virtual void AddCMakeListsRules() = 0;
-
- virtual void ComputeObjectFilenames(
+ void ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
- cmGeneratorTarget const* = 0);
+ cmGeneratorTarget const* = 0) override;
protected:
virtual const char* ReportErrorLabel() const;
virtual bool CustomCommandUseLocal() const { return false; }
/** Construct a custom command to make exe import lib dir. */
- CM_AUTO_PTR<cmCustomCommand> MaybeCreateImplibDir(cmGeneratorTarget* target,
- const std::string& config,
- bool isFortran);
+ std::unique_ptr<cmCustomCommand> MaybeCreateImplibDir(
+ cmGeneratorTarget* target, const std::string& config, bool isFortran);
};
#endif
diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx
index 739ef4367..9c36627b5 100644
--- a/Source/cmLocalXCodeGenerator.cxx
+++ b/Source/cmLocalXCodeGenerator.cxx
@@ -19,9 +19,7 @@ cmLocalXCodeGenerator::cmLocalXCodeGenerator(cmGlobalGenerator* gg,
this->EmitUniversalBinaryFlags = false;
}
-cmLocalXCodeGenerator::~cmLocalXCodeGenerator()
-{
-}
+cmLocalXCodeGenerator::~cmLocalXCodeGenerator() = default;
std::string cmLocalXCodeGenerator::GetTargetDirectory(
cmGeneratorTarget const*) const
@@ -31,10 +29,10 @@ std::string cmLocalXCodeGenerator::GetTargetDirectory(
}
void cmLocalXCodeGenerator::AppendFlagEscape(std::string& flags,
- const std::string& rawFlag)
+ const std::string& rawFlag) const
{
- cmGlobalXCodeGenerator* gg =
- static_cast<cmGlobalXCodeGenerator*>(this->GlobalGenerator);
+ const cmGlobalXCodeGenerator* gg =
+ static_cast<const cmGlobalXCodeGenerator*>(this->GlobalGenerator);
gg->AppendFlag(flags, rawFlag);
}
@@ -42,10 +40,8 @@ void cmLocalXCodeGenerator::Generate()
{
cmLocalGenerator::Generate();
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator iter = targets.begin();
- iter != targets.end(); ++iter) {
- (*iter)->HasMacOSXRpathInstallNameDir("");
+ for (auto target : this->GetGeneratorTargets()) {
+ target->HasMacOSXRpathInstallNameDir("");
}
}
@@ -53,10 +49,8 @@ void cmLocalXCodeGenerator::GenerateInstallRules()
{
cmLocalGenerator::GenerateInstallRules();
- std::vector<cmGeneratorTarget*> targets = this->GetGeneratorTargets();
- for (std::vector<cmGeneratorTarget*>::iterator iter = targets.begin();
- iter != targets.end(); ++iter) {
- (*iter)->HasMacOSXRpathInstallNameDir("");
+ for (auto target : this->GetGeneratorTargets()) {
+ target->HasMacOSXRpathInstallNameDir("");
}
}
@@ -69,10 +63,8 @@ void cmLocalXCodeGenerator::ComputeObjectFilenames(
// 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;
+ for (auto& si : mapping) {
+ cmSourceFile const* sf = si.first;
std::string objectName =
cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath());
objectName += ".o";
@@ -82,6 +74,6 @@ void cmLocalXCodeGenerator::ComputeObjectFilenames(
if (2 == counts[objectNameLower]) {
// TODO: emit warning about duplicate name?
}
- si->second = objectName;
+ si.second = objectName;
}
}
diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h
index 4ca02a9d0..42de20b47 100644
--- a/Source/cmLocalXCodeGenerator.h
+++ b/Source/cmLocalXCodeGenerator.h
@@ -24,19 +24,19 @@ class cmSourceFile;
class cmLocalXCodeGenerator : public cmLocalGenerator
{
public:
- ///! Set cache only and recurse to false by default.
+ //! Set cache only and recurse to false by default.
cmLocalXCodeGenerator(cmGlobalGenerator* gg, cmMakefile* mf);
- virtual ~cmLocalXCodeGenerator();
- virtual std::string GetTargetDirectory(
- cmGeneratorTarget const* target) const;
- virtual void AppendFlagEscape(std::string& flags,
- const std::string& rawFlag);
- virtual void Generate();
+ ~cmLocalXCodeGenerator() override;
+ std::string GetTargetDirectory(
+ cmGeneratorTarget const* target) const override;
+ void AppendFlagEscape(std::string& flags,
+ const std::string& rawFlag) const override;
+ void Generate() override;
virtual void GenerateInstallRules();
- virtual void ComputeObjectFilenames(
+ void ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping,
- cmGeneratorTarget const* gt = 0);
+ cmGeneratorTarget const* gt = nullptr) override;
private:
};
diff --git a/Source/cmLocale.h b/Source/cmLocale.h
index 9f90a3a99..3580ec812 100644
--- a/Source/cmLocale.h
+++ b/Source/cmLocale.h
@@ -3,23 +3,25 @@
#ifndef cmLocale_h
#define cmLocale_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <locale.h>
#include <string>
class cmLocaleRAII
{
- CM_DISABLE_COPY(cmLocaleRAII)
-
public:
cmLocaleRAII()
- : OldLocale(setlocale(LC_CTYPE, CM_NULLPTR))
+ : OldLocale(setlocale(LC_CTYPE, nullptr))
{
setlocale(LC_CTYPE, "");
}
+
~cmLocaleRAII() { setlocale(LC_CTYPE, this->OldLocale.c_str()); }
+ cmLocaleRAII(cmLocaleRAII const&) = delete;
+ cmLocaleRAII& operator=(cmLocaleRAII const&) = delete;
+
private:
std::string OldLocale;
};
diff --git a/Source/cmMSVC60LinkLineComputer.cxx b/Source/cmMSVC60LinkLineComputer.cxx
index 5298d1a79..74c94351c 100644
--- a/Source/cmMSVC60LinkLineComputer.cxx
+++ b/Source/cmMSVC60LinkLineComputer.cxx
@@ -4,7 +4,7 @@
#include "cmMSVC60LinkLineComputer.h"
#if defined(_WIN32) && !defined(__CYGWIN__)
-#include "cmSystemTools.h"
+# include "cmSystemTools.h"
#endif
class cmOutputConverter;
diff --git a/Source/cmMSVC60LinkLineComputer.h b/Source/cmMSVC60LinkLineComputer.h
index f2892d53f..d767914b9 100644
--- a/Source/cmMSVC60LinkLineComputer.h
+++ b/Source/cmMSVC60LinkLineComputer.h
@@ -4,7 +4,7 @@
#ifndef cmMSVC60LinkLineComputer_h
#define cmMSVC60LinkLineComputer_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -15,14 +15,15 @@ class cmStateDirectory;
class cmMSVC60LinkLineComputer : public cmLinkLineComputer
{
- CM_DISABLE_COPY(cmMSVC60LinkLineComputer)
-
public:
cmMSVC60LinkLineComputer(cmOutputConverter* outputConverter,
cmStateDirectory const& stateDir);
- std::string ConvertToLinkReference(std::string const& input) const
- CM_OVERRIDE;
+ cmMSVC60LinkLineComputer(cmMSVC60LinkLineComputer const&) = delete;
+ cmMSVC60LinkLineComputer& operator=(cmMSVC60LinkLineComputer const&) =
+ delete;
+
+ std::string ConvertToLinkReference(std::string const& input) const override;
};
#endif
diff --git a/Source/cmMachO.cxx b/Source/cmMachO.cxx
index a4350f7ce..d4af1e0f3 100644
--- a/Source/cmMachO.cxx
+++ b/Source/cmMachO.cxx
@@ -52,10 +52,7 @@ bool peek(cmsys::ifstream& fin, T& v)
template <typename T>
bool read(cmsys::ifstream& fin, T& v)
{
- if (!fin.read(reinterpret_cast<char*>(&v), sizeof(T))) {
- return false;
- }
- return true;
+ return !!fin.read(reinterpret_cast<char*>(&v), sizeof(T));
}
// read from the file and fill multiple data structures where
@@ -67,10 +64,7 @@ bool read(cmsys::ifstream& fin, std::vector<T>& v)
if (v.empty()) {
return true;
}
- if (!fin.read(reinterpret_cast<char*>(&v[0]), sizeof(T) * v.size())) {
- return false;
- }
- return true;
+ return !!fin.read(reinterpret_cast<char*>(&v[0]), sizeof(T) * v.size());
}
}
@@ -97,7 +91,7 @@ public:
: Swap(_swap)
{
}
- virtual ~cmMachOHeaderAndLoadCommands() {}
+ virtual ~cmMachOHeaderAndLoadCommands() = default;
virtual bool read_mach_o(cmsys::ifstream& fin) = 0;
@@ -134,7 +128,7 @@ public:
: cmMachOHeaderAndLoadCommands(_swap)
{
}
- bool read_mach_o(cmsys::ifstream& fin)
+ bool read_mach_o(cmsys::ifstream& fin) override
{
if (!read(fin, this->Header)) {
return false;
@@ -251,8 +245,7 @@ cmMachOInternal::cmMachOInternal(const char* fname)
}
// parse each Mach-O file
- for (size_t i = 0; i < this->FatArchs.size(); i++) {
- const fat_arch& arch = this->FatArchs[i];
+ for (const auto& arch : this->FatArchs) {
if (!this->read_mach_o(OSSwapBigToHostInt32(arch.offset))) {
return;
}
@@ -265,8 +258,8 @@ cmMachOInternal::cmMachOInternal(const char* fname)
cmMachOInternal::~cmMachOInternal()
{
- for (size_t i = 0; i < this->MachOList.size(); i++) {
- delete this->MachOList[i];
+ for (auto& i : this->MachOList) {
+ delete i;
}
}
@@ -283,7 +276,7 @@ bool cmMachOInternal::read_mach_o(uint32_t file_offset)
return false;
}
- cmMachOHeaderAndLoadCommands* f = NULL;
+ cmMachOHeaderAndLoadCommands* f = nullptr;
if (magic == MH_CIGAM || magic == MH_MAGIC) {
bool swap = false;
if (magic == MH_CIGAM) {
@@ -313,7 +306,7 @@ bool cmMachOInternal::read_mach_o(uint32_t file_offset)
// External class implementation.
cmMachO::cmMachO(const char* fname)
- : Internal(0)
+ : Internal(nullptr)
{
this->Internal = new cmMachOInternal(fname);
}
diff --git a/Source/cmMachO.h b/Source/cmMachO.h
index 42745cf60..5482465d3 100644
--- a/Source/cmMachO.h
+++ b/Source/cmMachO.h
@@ -3,13 +3,13 @@
#ifndef cmMachO_h
#define cmMachO_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
#if !defined(CMAKE_USE_MACH_PARSER)
-#error "This file may be included only if CMAKE_USE_MACH_PARSER is enabled."
+# error "This file may be included only if CMAKE_USE_MACH_PARSER is enabled."
#endif
class cmMachOInternal;
@@ -30,7 +30,7 @@ public:
std::string const& GetErrorMessage() const;
/** Boolean conversion. True if the Mach-O file is valid. */
- operator bool() const { return this->Valid(); }
+ explicit operator bool() const { return this->Valid(); }
/** Get Install name from binary **/
bool GetInstallName(std::string& install_name);
diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx
index a6a9ea316..e9c6aea73 100644
--- a/Source/cmMacroCommand.cxx
+++ b/Source/cmMacroCommand.cxx
@@ -4,11 +4,13 @@
#include <sstream>
#include <stdio.h>
+#include <utility>
#include "cmAlgorithms.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmPolicies.h"
+#include "cmRange.h"
#include "cmState.h"
#include "cmSystemTools.h"
@@ -16,15 +18,10 @@
class cmMacroHelperCommand : public cmCommand
{
public:
- cmMacroHelperCommand() {}
-
- ///! clean up any memory allocated by the macro
- ~cmMacroHelperCommand() CM_OVERRIDE {}
-
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
cmMacroHelperCommand* newC = new cmMacroHelperCommand;
// we must copy when we clone
@@ -40,10 +37,10 @@ public:
* the CMakeLists.txt file.
*/
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
- cmExecutionStatus&) CM_OVERRIDE;
+ cmExecutionStatus&) override;
bool InitialPass(std::vector<std::string> const&,
- cmExecutionStatus&) CM_OVERRIDE
+ cmExecutionStatus&) override
{
return false;
}
@@ -92,26 +89,24 @@ bool cmMacroHelperCommand::InvokeInitialPass(
argVs.reserve(expandedArgs.size());
char argvName[60];
for (unsigned int j = 0; j < expandedArgs.size(); ++j) {
- sprintf(argvName, "${ARGV%i}", j);
- argVs.push_back(argvName);
+ sprintf(argvName, "${ARGV%u}", j);
+ argVs.emplace_back(argvName);
}
// 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) {
+ for (cmListFileFunction const& func : this->Functions) {
// 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.Line = this->Functions[c].Line;
+ newLFF.Arguments.reserve(func.Arguments.size());
+ newLFF.Name = func.Name;
+ newLFF.Line = func.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) {
+ for (cmListFileArgument const& k : func.Arguments) {
cmListFileArgument arg;
- arg.Value = k->Value;
- if (k->Delim != cmListFileArgument::Bracket) {
+ arg.Value = k.Value;
+ if (k.Delim != cmListFileArgument::Bracket) {
// replace formal arguments
for (unsigned int j = 0; j < variables.size(); ++j) {
cmSystemTools::ReplaceString(arg.Value, variables[j],
@@ -131,9 +126,9 @@ bool cmMacroHelperCommand::InvokeInitialPass(
}
}
}
- arg.Delim = k->Delim;
- arg.Line = k->Line;
- newLFF.Arguments.push_back(arg);
+ arg.Delim = k.Delim;
+ arg.Line = k.Line;
+ newLFF.Arguments.push_back(std::move(arg));
}
cmExecutionStatus status;
if (!this->Makefile->ExecuteCommand(newLFF, status) ||
@@ -162,9 +157,9 @@ bool cmMacroFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
{
// 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")) {
+ if (lff.Name.Lower == "macro") {
this->Depth++;
- } else if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endmacro")) {
+ } else if (lff.Name.Lower == "endmacro") {
// if this is the endmacro for this macro then execute
if (!this->Depth) {
mf.AppendProperty("MACROS", this->Args[0].c_str());
@@ -192,7 +187,7 @@ bool cmMacroFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
bool cmMacroFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
cmMakefile& mf)
{
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endmacro")) {
+ if (lff.Name.Lower == "endmacro") {
std::vector<std::string> expandedArguments;
mf.ExpandArguments(lff.Arguments, expandedArguments,
this->GetStartingContext().FilePath.c_str());
@@ -217,7 +212,7 @@ bool cmMacroCommand::InitialPass(std::vector<std::string> const& args,
// create a function blocker
cmMacroFunctionBlocker* f = new cmMacroFunctionBlocker();
- f->Args.insert(f->Args.end(), args.begin(), args.end());
+ cmAppend(f->Args, args);
this->Makefile->AddFunctionBlocker(f);
return true;
}
diff --git a/Source/cmMacroCommand.h b/Source/cmMacroCommand.h
index 0d35fe06e..b54ed6605 100644
--- a/Source/cmMacroCommand.h
+++ b/Source/cmMacroCommand.h
@@ -3,7 +3,7 @@
#ifndef cmMacroCommand_h
#define cmMacroCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -18,15 +18,13 @@ class cmMakefile;
class cmMacroFunctionBlocker : public cmFunctionBlocker
{
public:
- cmMacroFunctionBlocker() { this->Depth = 0; }
- ~cmMacroFunctionBlocker() CM_OVERRIDE {}
bool IsFunctionBlocked(const cmListFileFunction&, cmMakefile& mf,
- cmExecutionStatus&) CM_OVERRIDE;
- bool ShouldRemove(const cmListFileFunction&, cmMakefile& mf) CM_OVERRIDE;
+ cmExecutionStatus&) override;
+ bool ShouldRemove(const cmListFileFunction&, cmMakefile& mf) override;
std::vector<std::string> Args;
std::vector<cmListFileFunction> Functions;
- int Depth;
+ int Depth = 0;
};
/// Starts macro() ... endmacro() block
@@ -36,14 +34,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmMacroCommand; }
+ cmCommand* Clone() override { return new cmMacroCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmMakeDirectoryCommand.cxx b/Source/cmMakeDirectoryCommand.cxx
index 06e295bc0..aff4ca650 100644
--- a/Source/cmMakeDirectoryCommand.cxx
+++ b/Source/cmMakeDirectoryCommand.cxx
@@ -15,13 +15,13 @@ bool cmMakeDirectoryCommand::InitialPass(std::vector<std::string> const& args,
this->SetError("called with incorrect number of arguments");
return false;
}
- if (!this->Makefile->CanIWriteThisFile(args[0].c_str())) {
+ if (!this->Makefile->CanIWriteThisFile(args[0])) {
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());
+ cmSystemTools::MakeDirectory(args[0]);
return true;
}
diff --git a/Source/cmMakeDirectoryCommand.h b/Source/cmMakeDirectoryCommand.h
index af72eab96..d2637f388 100644
--- a/Source/cmMakeDirectoryCommand.h
+++ b/Source/cmMakeDirectoryCommand.h
@@ -3,7 +3,7 @@
#ifndef cmMakeDirectoryCommand_h
#define cmMakeDirectoryCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -27,14 +27,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmMakeDirectoryCommand; }
+ cmCommand* Clone() override { return new cmMakeDirectoryCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 608b18a46..3f8bd4e41 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -6,10 +6,13 @@
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <assert.h>
+#include <cstring>
#include <ctype.h>
+#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <sstream>
+#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <utility>
#include "cmAlgorithms.h"
@@ -18,14 +21,17 @@
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
#include "cmExecutionStatus.h"
-#include "cmExpandedCommandArgument.h"
+#include "cmExpandedCommandArgument.h" // IWYU pragma: keep
#include "cmFileLockPool.h"
#include "cmFunctionBlocker.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionEvaluationFile.h"
#include "cmGlobalGenerator.h"
#include "cmInstallGenerator.h" // IWYU pragma: keep
+#include "cmInstallSubdirectoryGenerator.h"
#include "cmListFileCache.h"
+#include "cmMessageType.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmState.h"
@@ -37,16 +43,22 @@
#include "cmTestGenerator.h" // IWYU pragma: keep
#include "cmVersion.h"
#include "cmWorkingDirectory.h"
-#include "cm_auto_ptr.hxx"
#include "cm_sys_stat.h"
#include "cmake.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+
#ifdef CMAKE_BUILD_WITH_CMAKE
-#include "cmVariableWatch.h"
+# include "cmVariableWatch.h"
#endif
class cmMessenger;
+cmDirectoryId::cmDirectoryId(std::string s)
+ : String(std::move(s))
+{
+}
+
// default is not to be building executables
cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
cmStateSnapshot const& snapshot)
@@ -59,21 +71,22 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused();
this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
- this->SuppressWatches = false;
+ this->SuppressSideEffects = false;
// Setup the default include complaint regular expression (match nothing).
this->ComplainFileRegularExpression = "^$";
this->DefineFlags = " ";
- this->cmDefineRegex.compile("#cmakedefine[ \t]+([A-Za-z_0-9]*)");
- this->cmDefine01Regex.compile("#cmakedefine01[ \t]+([A-Za-z_0-9]*)");
+ this->cmDefineRegex.compile("#([ \t]*)cmakedefine[ \t]+([A-Za-z_0-9]*)");
+ this->cmDefine01Regex.compile("#([ \t]*)cmakedefine01[ \t]+([A-Za-z_0-9]*)");
this->cmAtVarRegex.compile("(@[A-Za-z_0-9/.+-]+@)");
this->cmNamedCurly.compile("^[A-Za-z0-9/_.+-]+{");
this->StateSnapshot =
this->StateSnapshot.GetState()->CreatePolicyScopeSnapshot(
this->StateSnapshot);
+ this->RecursionDepth = 0;
// Enter a policy level for this directory.
this->PushPolicy();
@@ -87,17 +100,14 @@ cmMakefile::cmMakefile(cmGlobalGenerator* globalGenerator,
#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("Source Files", CM_SOURCE_REGEX);
this->AddSourceGroup("Header Files", CM_HEADER_REGEX);
this->AddSourceGroup("CMake Rules", "\\.rule$");
- this->AddSourceGroup("Resources", "\\.plist$");
+ this->AddSourceGroup("Resources", CM_RESOURCE_REGEX);
this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$");
this->ObjectLibrariesSourceGroupIndex = this->SourceGroups.size();
- this->SourceGroups.push_back(
- cmSourceGroup("Object Libraries", "^MATCH_NO_SOURCES$"));
+ this->SourceGroups.emplace_back("Object Libraries", "^MATCH_NO_SOURCES$");
#endif
}
@@ -113,17 +123,90 @@ cmMakefile::~cmMakefile()
cmDeleteAll(this->EvaluationFiles);
}
-void cmMakefile::IssueMessage(cmake::MessageType t,
- std::string const& text) const
+cmDirectoryId cmMakefile::GetDirectoryId() const
+{
+ // Use the instance pointer value to uniquely identify this directory.
+ // If we ever need to expose this to CMake language code we should
+ // add a read-only property in cmMakefile::GetProperty.
+ char buf[32];
+ sprintf(buf, "<%p>",
+ static_cast<void const*>(this)); // cast avoids format warning
+ return std::string(buf);
+}
+
+void cmMakefile::IssueMessage(MessageType t, std::string const& text) const
{
if (!this->ExecutionStatusStack.empty()) {
- if ((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR)) {
+ if ((t == MessageType::FATAL_ERROR) ||
+ (t == MessageType::INTERNAL_ERROR)) {
this->ExecutionStatusStack.back()->SetNestedError();
}
}
this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace());
}
+bool cmMakefile::CheckCMP0037(std::string const& targetName,
+ cmStateEnums::TargetType targetType) const
+{
+ MessageType messageType = MessageType::AUTHOR_WARNING;
+ std::ostringstream e;
+ bool issueMessage = false;
+ switch (this->GetPolicyStatus(cmPolicies::CMP0037)) {
+ case cmPolicies::WARN:
+ if (targetType != cmStateEnums::INTERFACE_LIBRARY) {
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0037) << "\n";
+ issueMessage = true;
+ }
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ issueMessage = true;
+ messageType = MessageType::FATAL_ERROR;
+ break;
+ }
+ 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->IssueMessage(messageType, e.str());
+
+ if (messageType == MessageType::FATAL_ERROR) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void cmMakefile::MaybeWarnCMP0074(std::string const& pkg)
+{
+ // Warn if a <pkg>_ROOT variable we may use is set.
+ std::string const varName = pkg + "_ROOT";
+ const char* var = this->GetDefinition(varName);
+ std::string env;
+ cmSystemTools::GetEnv(varName, env);
+
+ bool const haveVar = var && *var;
+ bool const haveEnv = !env.empty();
+ if ((haveVar || haveEnv) && this->WarnedCMP0074.insert(varName).second) {
+ std::ostringstream w;
+ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0074) << "\n";
+ if (haveVar) {
+ w << "CMake variable " << varName << " is set to:\n"
+ << " " << var << "\n";
+ }
+ if (haveEnv) {
+ w << "Environment variable " << varName << " is set to:\n"
+ << " " << env << "\n";
+ }
+ w << "For compatibility, CMake is ignoring the variable.";
+ this->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
+ }
+}
+
cmStringRange cmMakefile::GetIncludeDirectoriesEntries() const
{
return this->StateSnapshot.GetDirectory().GetIncludeDirectoriesEntries();
@@ -156,6 +239,27 @@ cmBacktraceRange cmMakefile::GetCompileDefinitionsBacktraces() const
.GetCompileDefinitionsEntryBacktraces();
}
+cmStringRange cmMakefile::GetLinkOptionsEntries() const
+{
+ return this->StateSnapshot.GetDirectory().GetLinkOptionsEntries();
+}
+
+cmBacktraceRange cmMakefile::GetLinkOptionsBacktraces() const
+{
+ return this->StateSnapshot.GetDirectory().GetLinkOptionsEntryBacktraces();
+}
+
+cmStringRange cmMakefile::GetLinkDirectoriesEntries() const
+{
+ return this->StateSnapshot.GetDirectory().GetLinkDirectoriesEntries();
+}
+
+cmBacktraceRange cmMakefile::GetLinkDirectoriesBacktraces() const
+{
+ return this->StateSnapshot.GetDirectory()
+ .GetLinkDirectoriesEntryBacktraces();
+}
+
cmListFileBacktrace cmMakefile::GetBacktrace() const
{
return this->Backtrace;
@@ -164,7 +268,7 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
cmListFileBacktrace cmMakefile::GetBacktrace(cmCommandContext const& cc) const
{
cmListFileContext lfc;
- lfc.Name = cc.Name;
+ lfc.Name = cc.Name.Original;
lfc.Line = cc.Line;
lfc.FilePath = this->StateSnapshot.GetExecutionListFile();
return this->Backtrace.Push(lfc);
@@ -189,13 +293,14 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
std::string const& only_filename = cmSystemTools::GetFilenameName(full_path);
bool trace = trace_only_this_files.empty();
if (!trace) {
- for (std::vector<std::string>::const_iterator i =
- trace_only_this_files.begin();
- !trace && i != trace_only_this_files.end(); ++i) {
- std::string::size_type const pos = full_path.rfind(*i);
+ for (std::string const& file : trace_only_this_files) {
+ std::string::size_type const pos = full_path.rfind(file);
trace = (pos != std::string::npos) &&
- ((pos + i->size()) == full_path.size()) &&
- (only_filename == cmSystemTools::GetFilenameName(*i));
+ ((pos + file.size()) == full_path.size()) &&
+ (only_filename == cmSystemTools::GetFilenameName(file));
+ if (trace) {
+ break;
+ }
}
// Do nothing if current file wasn't requested for trace...
if (!trace) {
@@ -205,23 +310,21 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
std::ostringstream msg;
msg << full_path << "(" << lff.Line << "): ";
- msg << lff.Name << "(";
+ msg << lff.Name.Original << "(";
bool expand = this->GetCMakeInstance()->GetTraceExpand();
std::string temp;
- for (std::vector<cmListFileArgument>::const_iterator i =
- lff.Arguments.begin();
- i != lff.Arguments.end(); ++i) {
+ for (cmListFileArgument const& arg : lff.Arguments) {
if (expand) {
- temp = i->Value;
+ temp = arg.Value;
this->ExpandVariablesInString(temp);
msg << temp;
} else {
- msg << i->Value;
+ msg << arg.Value;
}
msg << " ";
}
msg << ")";
- cmSystemTools::Message(msg.str().c_str());
+ cmSystemTools::Message(msg.str());
}
// Helper class to make sure the call stack is valid.
@@ -235,15 +338,20 @@ public:
cmListFileContext const& lfc = cmListFileContext::FromCommandContext(
cc, this->Makefile->StateSnapshot.GetExecutionListFile());
this->Makefile->Backtrace = this->Makefile->Backtrace.Push(lfc);
+ ++this->Makefile->RecursionDepth;
this->Makefile->ExecutionStatusStack.push_back(&status);
}
~cmMakefileCall()
{
this->Makefile->ExecutionStatusStack.pop_back();
+ --this->Makefile->RecursionDepth;
this->Makefile->Backtrace = this->Makefile->Backtrace.Pop();
}
+ cmMakefileCall(const cmMakefileCall&) = delete;
+ cmMakefileCall& operator=(const cmMakefileCall&) = delete;
+
private:
cmMakefile* Makefile;
};
@@ -259,16 +367,33 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
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);
+ // Check for maximum recursion depth.
+ int depth = CMake_DEFAULT_RECURSION_LIMIT;
+ const char* depthStr = this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH");
+ if (depthStr) {
+ std::istringstream s(depthStr);
+ int d;
+ if (s >> d) {
+ depth = d;
+ }
+ }
+ if (this->RecursionDepth > depth) {
+ std::ostringstream e;
+ e << "Maximum recursion depth of " << depth << " exceeded";
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ cmSystemTools::SetFatalErrorOccured();
+ return false;
+ }
+
// Lookup the command prototype.
- if (cmCommand* proto = this->GetState()->GetCommand(name)) {
+ if (cmCommand* proto =
+ this->GetState()->GetCommandByExactName(lff.Name.Lower)) {
// Clone the prototype.
- CM_AUTO_PTR<cmCommand> pcmd(proto->Clone());
+ std::unique_ptr<cmCommand> pcmd(proto->Clone());
pcmd->SetMakefile(this);
// Decide whether to invoke the command.
@@ -283,8 +408,9 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
if (!invokeSucceeded || hadNestedError) {
if (!hadNestedError) {
// The command invocation requested that we report an error.
- std::string const error = name + " " + pcmd->GetError();
- this->IssueMessage(cmake::FATAL_ERROR, error);
+ std::string const error =
+ std::string(lff.Name.Original) + " " + pcmd->GetError();
+ this->IssueMessage(MessageType::FATAL_ERROR, error);
}
result = false;
if (this->GetCMakeInstance()->GetWorkingMode() != cmake::NORMAL_MODE) {
@@ -298,9 +424,9 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
} else {
if (!cmSystemTools::GetFatalErrorOccured()) {
std::string error = "Unknown CMake command \"";
- error += lff.Name;
+ error += lff.Name.Original;
error += "\".";
- this->IssueMessage(cmake::FATAL_ERROR, error);
+ this->IssueMessage(MessageType::FATAL_ERROR, error);
result = false;
cmSystemTools::SetFatalErrorOccured();
}
@@ -317,6 +443,9 @@ public:
~IncludeScope();
void Quiet() { this->ReportError = false; }
+ IncludeScope(const IncludeScope&) = delete;
+ IncludeScope& operator=(const IncludeScope&) = delete;
+
private:
cmMakefile* Makefile;
bool NoPolicyScope;
@@ -412,7 +541,7 @@ void cmMakefile::IncludeScope::EnforceCMP0011()
<< "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());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
break;
case cmPolicies::REQUIRED_IF_USED:
@@ -424,7 +553,7 @@ void cmMakefile::IncludeScope::EnforceCMP0011()
<< this->Makefile->GetExecutionFilePath() << "\n"
<< "affects policy settings, so it requires this policy to be set.";
/* clang-format on */
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
} break;
case cmPolicies::OLD:
case cmPolicies::NEW:
@@ -435,7 +564,8 @@ void cmMakefile::IncludeScope::EnforceCMP0011()
}
}
-bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope)
+bool cmMakefile::ReadDependentFile(const std::string& filename,
+ bool noPolicyScope)
{
this->AddDefinition("CMAKE_PARENT_LIST_FILE",
this->GetDefinition("CMAKE_CURRENT_LIST_FILE"));
@@ -483,12 +613,15 @@ public:
void Quiet() { this->ReportError = false; }
+ ListFileScope(const ListFileScope&) = delete;
+ ListFileScope& operator=(const ListFileScope&) = delete;
+
private:
cmMakefile* Makefile;
bool ReportError;
};
-bool cmMakefile::ReadListFile(const char* filename)
+bool cmMakefile::ReadListFile(const std::string& filename)
{
std::string filenametoread = cmSystemTools::CollapseFullPath(
filename, this->GetCurrentSourceDirectory());
@@ -566,9 +699,9 @@ void cmMakefile::EnforceDirectoryLevelRules() const
<< "\"cmake --help-policy CMP0000\".";
switch (this->GetPolicyStatus(cmPolicies::CMP0000)) {
case cmPolicies::WARN:
- // Warn because the user did not provide a mimimum required
+ // Warn because the user did not provide a minimum required
// version.
- this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
+ this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING,
msg.str(), this->Backtrace);
case cmPolicies::OLD:
// OLD behavior is to use policy version 2.4 set in
@@ -578,8 +711,8 @@ void cmMakefile::EnforceDirectoryLevelRules() const
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
// NEW behavior is to issue an error.
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, msg.str(),
- this->Backtrace);
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ msg.str(), this->Backtrace);
cmSystemTools::SetFatalErrorOccured();
return;
}
@@ -588,11 +721,13 @@ void cmMakefile::EnforceDirectoryLevelRules() const
void cmMakefile::AddEvaluationFile(
const std::string& inputFile,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> outputName,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> condition, bool inputIsContent)
+ std::unique_ptr<cmCompiledGeneratorExpression> outputName,
+ std::unique_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent)
{
this->EvaluationFiles.push_back(new cmGeneratorExpressionEvaluationFile(
- inputFile, outputName, condition, inputIsContent));
+ inputFile, std::move(outputName), std::move(condition), inputIsContent,
+ this->GetPolicyStatus(cmPolicies::CMP0070)));
}
std::vector<cmGeneratorExpressionEvaluationFile*>
@@ -629,7 +764,7 @@ struct file_not_persistent
bool operator()(const std::string& path) const
{
return !(path.find("CMakeTmp") == std::string::npos &&
- cmSystemTools::FileExists(path.c_str()));
+ cmSystemTools::FileExists(path));
}
};
}
@@ -641,9 +776,8 @@ void cmMakefile::FinalPass()
// 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();
+ for (cmCommand* fpCommand : this->FinalPassCommands) {
+ fpCommand->FinalPass();
}
// go through all configured files and see which ones still exist.
@@ -666,7 +800,7 @@ void cmMakefile::ConfigureFinalPass()
if (oldValue &&
cmSystemTools::VersionCompare(cmSystemTools::OP_LESS, oldValue, "2.4")) {
this->GetCMakeInstance()->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::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 "
@@ -680,14 +814,14 @@ void cmMakefile::AddCustomCommandToTarget(
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
const char* comment, const char* workingDir, bool escapeOldStyle,
- bool uses_terminal, const std::string& depfile, bool command_expand_lists,
- ObjectLibraryCommands objLibraryCommands)
+ bool uses_terminal, const std::string& depfile, const std::string& job_pool,
+ bool command_expand_lists, ObjectLibraryCommands objLibraryCommands)
{
// Find the target to which to add the custom command.
- cmTargets::iterator ti = this->Targets.find(target);
+ cmTargetMap::iterator ti = this->Targets.find(target);
if (ti == this->Targets.end()) {
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
bool issueMessage = false;
std::ostringstream e;
switch (this->GetPolicyStatus(cmPolicies::CMP0040)) {
@@ -700,7 +834,7 @@ void cmMakefile::AddCustomCommandToTarget(
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
issueMessage = true;
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
}
if (issueMessage) {
@@ -721,28 +855,28 @@ void cmMakefile::AddCustomCommandToTarget(
return;
}
+ cmTarget& t = ti->second;
if (objLibraryCommands == RejectObjectLibraryCommands &&
- ti->second.GetType() == cmStateEnums::OBJECT_LIBRARY) {
+ t.GetType() == cmStateEnums::OBJECT_LIBRARY) {
std::ostringstream 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());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
- if (ti->second.GetType() == cmStateEnums::INTERFACE_LIBRARY) {
+ if (t.GetType() == cmStateEnums::INTERFACE_LIBRARY) {
std::ostringstream 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());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
// Always create the byproduct sources and mark them generated.
- for (std::vector<std::string>::const_iterator o = byproducts.begin();
- o != byproducts.end(); ++o) {
- if (cmSourceFile* out = this->GetOrCreateSource(*o, true)) {
+ for (std::string const& o : byproducts) {
+ if (cmSourceFile* out = this->GetOrCreateSource(o, true)) {
out->SetProperty("GENERATED", "1");
}
}
@@ -756,15 +890,16 @@ void cmMakefile::AddCustomCommandToTarget(
cc.SetUsesTerminal(uses_terminal);
cc.SetCommandExpandLists(command_expand_lists);
cc.SetDepfile(depfile);
+ cc.SetJobPool(job_pool);
switch (type) {
case cmTarget::PRE_BUILD:
- ti->second.AddPreBuildCommand(cc);
+ t.AddPreBuildCommand(cc);
break;
case cmTarget::PRE_LINK:
- ti->second.AddPreLinkCommand(cc);
+ t.AddPreLinkCommand(cc);
break;
case cmTarget::POST_BUILD:
- ti->second.AddPostBuildCommand(cc);
+ t.AddPostBuildCommand(cc);
break;
}
}
@@ -775,28 +910,27 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
const std::vector<std::string>& depends, const std::string& main_dependency,
const cmCustomCommandLines& commandLines, const char* comment,
const char* workingDir, bool replace, bool escapeOldStyle,
- bool uses_terminal, bool command_expand_lists, const std::string& depfile)
+ bool uses_terminal, bool command_expand_lists, const std::string& depfile,
+ const std::string& job_pool)
{
// Make sure there is at least one output.
if (outputs.empty()) {
cmSystemTools::Error("Attempt to add a custom rule with no output!");
- return CM_NULLPTR;
+ return nullptr;
}
// Validate custom commands. TODO: More strict?
- for (cmCustomCommandLines::const_iterator i = commandLines.begin();
- i != commandLines.end(); ++i) {
- cmCustomCommandLine const& cl = *i;
+ for (cmCustomCommandLine const& cl : commandLines) {
if (!cl.empty() && !cl[0].empty() && cl[0][0] == '"') {
std::ostringstream e;
e << "COMMAND may not contain literal quotes:\n " << cl[0] << "\n";
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
- return CM_NULLPTR;
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return nullptr;
}
}
// Choose a source file on which to store the custom command.
- cmSourceFile* file = CM_NULLPTR;
+ cmSourceFile* file = nullptr;
if (!commandLines.empty() && !main_dependency.empty()) {
// The main dependency was specified. Use it unless a different
// custom command already used it.
@@ -810,7 +944,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
}
// The existing custom command is different. We need to
// generate a rule file for this new command.
- file = CM_NULLPTR;
+ file = nullptr;
} else if (!file) {
file = this->CreateSource(main_dependency);
}
@@ -824,34 +958,34 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
std::string outName = gg->GenerateRuleFile(outputs[0]);
// Check if the rule file already exists.
- file = this->GetSource(outName);
+ file = this->GetSource(outName, cmSourceFileLocationKind::Known);
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.");
+ cmSystemTools::Error("Attempt to add a custom rule to output \"" +
+ outName + "\" which already has a custom rule.");
}
return file;
}
// Create a cmSourceFile for the rule file.
if (!file) {
- file = this->CreateSource(outName, true);
+ file =
+ this->CreateSource(outName, true, cmSourceFileLocationKind::Known);
}
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)) {
+ for (std::string const& o : outputs) {
+ if (cmSourceFile* out =
+ this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) {
out->SetProperty("GENERATED", "1");
}
}
- for (std::vector<std::string>::const_iterator o = byproducts.begin();
- o != byproducts.end(); ++o) {
- if (cmSourceFile* out = this->GetOrCreateSource(*o, true)) {
+ for (std::string const& o : byproducts) {
+ if (cmSourceFile* out =
+ this->GetOrCreateSource(o, true, cmSourceFileLocationKind::Known)) {
out->SetProperty("GENERATED", "1");
}
}
@@ -871,6 +1005,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
cc->SetUsesTerminal(uses_terminal);
cc->SetCommandExpandLists(command_expand_lists);
cc->SetDepfile(depfile);
+ cc->SetJobPool(job_pool);
file->SetCustomCommand(cc);
this->UpdateOutputToSourceMap(outputs, file);
}
@@ -880,9 +1015,8 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
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);
+ for (std::string const& o : outputs) {
+ this->UpdateOutputToSourceMap(o, source);
}
}
@@ -909,7 +1043,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
const std::string& main_dependency, const cmCustomCommandLines& commandLines,
const char* comment, const char* workingDir, bool replace,
bool escapeOldStyle, bool uses_terminal, bool command_expand_lists,
- const std::string& depfile)
+ const std::string& depfile, const std::string& job_pool)
{
std::vector<std::string> outputs;
outputs.push_back(output);
@@ -917,7 +1051,7 @@ cmSourceFile* cmMakefile::AddCustomCommandToOutput(
return this->AddCustomCommandToOutput(
outputs, no_byproducts, depends, main_dependency, commandLines, comment,
workingDir, replace, escapeOldStyle, uses_terminal, command_expand_lists,
- depfile);
+ depfile, job_pool);
}
void cmMakefile::AddCustomCommandOldStyle(
@@ -934,45 +1068,44 @@ void cmMakefile::AddCustomCommandOldStyle(
std::vector<std::string> no_byproducts;
this->AddCustomCommandToTarget(target, no_byproducts, depends,
commandLines, cmTarget::POST_BUILD, comment,
- CM_NULLPTR);
+ nullptr);
return;
}
// Each output must get its own copy of this rule.
- cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|m|mm|"
+ cmsys::RegularExpression sourceFiles("\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|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) {
+ for (std::string const& oi : outputs) {
// Get the name of this output.
- const char* output = oi->c_str();
+ 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, CM_NULLPTR);
+ commandLines, comment, nullptr);
} 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, CM_NULLPTR);
+ commandLines, comment, nullptr);
}
// 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")) {
- cmTargets::iterator ti = this->Targets.find(target);
+ cmTargetMap::iterator ti = this->Targets.find(target);
if (ti != this->Targets.end()) {
ti->second.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());
+ "that does not exist yet for target " +
+ target);
return;
}
}
@@ -980,7 +1113,7 @@ void cmMakefile::AddCustomCommandOldStyle(
}
cmTarget* cmMakefile::AddUtilityCommand(
- const std::string& utilityName, bool excludeFromAll,
+ const std::string& utilityName, TargetOrigin origin, 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)
@@ -1001,35 +1134,38 @@ cmTarget* cmMakefile::AddUtilityCommand(
commandLine.push_back(arg4);
}
cmCustomCommandLines commandLines;
- commandLines.push_back(commandLine);
+ commandLines.push_back(std::move(commandLine));
// Call the real signature of this method.
- return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
- depends, commandLines);
+ return this->AddUtilityCommand(utilityName, origin, excludeFromAll,
+ workingDirectory, depends, commandLines);
}
cmTarget* cmMakefile::AddUtilityCommand(
- const std::string& utilityName, bool excludeFromAll,
+ const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle,
- const char* comment, bool uses_terminal, bool command_expand_lists)
+ const char* comment, bool uses_terminal, bool command_expand_lists,
+ const std::string& job_pool)
{
std::vector<std::string> no_byproducts;
- return this->AddUtilityCommand(utilityName, excludeFromAll, workingDirectory,
- no_byproducts, depends, commandLines,
- escapeOldStyle, comment, uses_terminal,
- command_expand_lists);
+ return this->AddUtilityCommand(
+ utilityName, origin, excludeFromAll, workingDirectory, no_byproducts,
+ depends, commandLines, escapeOldStyle, comment, uses_terminal,
+ command_expand_lists, job_pool);
}
cmTarget* cmMakefile::AddUtilityCommand(
- const std::string& utilityName, bool excludeFromAll,
+ const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle,
- const char* comment, bool uses_terminal, bool command_expand_lists)
+ const char* comment, bool uses_terminal, bool command_expand_lists,
+ const std::string& job_pool)
{
// Create a target instance for this utility.
cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName);
+ target->SetIsGeneratorProvided(origin == TargetOrigin::Generator);
if (excludeFromAll) {
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
@@ -1041,7 +1177,7 @@ cmTarget* cmMakefile::AddUtilityCommand(
// Store the custom command in the target.
if (!commandLines.empty() || !depends.empty()) {
std::string force = this->GetCurrentBinaryDirectory();
- force += cmake::GetCMakeFilesDirectory();
+ force += "/CMakeFiles";
force += "/";
force += utilityName;
std::vector<std::string> forced;
@@ -1051,21 +1187,20 @@ cmTarget* cmMakefile::AddUtilityCommand(
this->AddCustomCommandToOutput(
forced, byproducts, depends, no_main_dependency, commandLines, comment,
workingDirectory, no_replace, escapeOldStyle, uses_terminal,
- command_expand_lists);
+ command_expand_lists, /*depfile=*/"", job_pool);
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());
+ cmSystemTools::Error("Could not get source file entry for " + force);
}
// Always create the byproduct sources and mark them generated.
- for (std::vector<std::string>::const_iterator o = byproducts.begin();
- o != byproducts.end(); ++o) {
- if (cmSourceFile* out = this->GetOrCreateSource(*o, true)) {
+ for (std::string const& byproduct : byproducts) {
+ if (cmSourceFile* out = this->GetOrCreateSource(
+ byproduct, true, cmSourceFileLocationKind::Known)) {
out->SetProperty("GENERATED", "1");
}
}
@@ -1073,57 +1208,38 @@ cmTarget* cmMakefile::AddUtilityCommand(
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)
+static void s_AddDefineFlag(std::string const& flag, std::string& dflags)
{
// remove any \n\r
std::string::size_type initSize = dflags.size();
- dflags += std::string(" ") + flag;
+ dflags += ' ';
+ dflags += flag;
std::string::iterator flagStart = dflags.begin() + initSize + 1;
std::replace(flagStart, dflags.end(), '\n', ' ');
std::replace(flagStart, dflags.end(), '\r', ' ');
}
-void cmMakefile::RemoveDefineFlag(const char* flag)
+void cmMakefile::AddDefineFlag(std::string const& flag)
{
- // Check the length of the flag to remove.
- std::string::size_type len = strlen(flag);
- if (len < 1) {
+ if (flag.empty()) {
return;
}
// Update the string used for the old DEFINITIONS property.
- this->RemoveDefineFlag(flag, len, this->DefineFlagsOrig);
+ s_AddDefineFlag(flag, this->DefineFlagsOrig);
// If this is really a definition, update COMPILE_DEFINITIONS.
- if (this->ParseDefineFlag(flag, true)) {
+ if (this->ParseDefineFlag(flag, false)) {
return;
}
- // Remove this flag that does not look like a definition.
- this->RemoveDefineFlag(flag, len, this->DefineFlags);
+ // Add this flag that does not look like a definition.
+ s_AddDefineFlag(flag, this->DefineFlags);
}
-void cmMakefile::RemoveDefineFlag(const char* flag, std::string::size_type len,
- std::string& dflags)
+static void s_RemoveDefineFlag(std::string const& flag, std::string& dflags)
{
+ std::string::size_type const len = flag.length();
// 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);
@@ -1138,9 +1254,50 @@ void cmMakefile::RemoveDefineFlag(const char* flag, std::string::size_type len,
}
}
-void cmMakefile::AddCompileOption(const char* option)
+void cmMakefile::RemoveDefineFlag(std::string const& flag)
{
- this->AppendProperty("COMPILE_OPTIONS", option);
+ // Check the length of the flag to remove.
+ if (flag.empty()) {
+ return;
+ }
+
+ // Update the string used for the old DEFINITIONS property.
+ s_RemoveDefineFlag(flag, 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.
+ s_RemoveDefineFlag(flag, this->DefineFlags);
+}
+
+void cmMakefile::AddCompileDefinition(std::string const& option)
+{
+ this->AppendProperty("COMPILE_DEFINITIONS", option.c_str());
+}
+
+void cmMakefile::AddCompileOption(std::string const& option)
+{
+ this->AppendProperty("COMPILE_OPTIONS", option.c_str());
+}
+
+void cmMakefile::AddLinkOption(std::string const& option)
+{
+ this->AppendProperty("LINK_OPTIONS", option.c_str());
+}
+
+void cmMakefile::AddLinkDirectory(std::string const& directory, bool before)
+{
+ cmListFileBacktrace lfbt = this->GetBacktrace();
+ if (before) {
+ this->StateSnapshot.GetDirectory().PrependLinkDirectoriesEntry(directory,
+ lfbt);
+ } else {
+ this->StateSnapshot.GetDirectory().AppendLinkDirectoriesEntry(directory,
+ lfbt);
+ }
}
bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
@@ -1149,18 +1306,18 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
static cmsys::RegularExpression valid("^[-/]D[A-Za-z_][A-Za-z0-9_]*(=.*)?$");
// Make sure the definition matches.
- if (!valid.find(def.c_str())) {
+ if (!valid.find(def)) {
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())) {
+ if (!trivial.find(def)) {
// This definition has a non-trivial value.
switch (this->GetPolicyStatus(cmPolicies::CMP0005)) {
case cmPolicies::WARN:
- this->IssueMessage(cmake::AUTHOR_WARNING,
+ this->IssueMessage(MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(cmPolicies::CMP0005));
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -1170,7 +1327,7 @@ bool cmMakefile::ParseDefineFlag(std::string const& def, bool remove)
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
this->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0005));
return false;
case cmPolicies::NEW:
@@ -1227,22 +1384,20 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
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) {
+ for (std::string const& config : configs) {
std::string defPropName = "COMPILE_DEFINITIONS_";
- defPropName += cmSystemTools::UpperCase(*ci);
+ defPropName += cmSystemTools::UpperCase(config);
const char* prop = parent->GetProperty(defPropName);
this->SetProperty(defPropName, prop);
}
}
+ // labels
+ this->SetProperty("LABELS", parent->GetProperty("LABELS"));
+
// link libraries
this->SetProperty("LINK_LIBRARIES", parent->GetProperty("LINK_LIBRARIES"));
- // link directories
- this->SetProperty("LINK_DIRECTORIES",
- parent->GetProperty("LINK_DIRECTORIES"));
-
// the initial project name
this->StateSnapshot.SetProjectName(parent->StateSnapshot.GetProjectName());
@@ -1251,6 +1406,9 @@ void cmMakefile::InitializeFromParent(cmMakefile* parent)
// Imported targets.
this->ImportedTargets = parent->ImportedTargets;
+
+ // Recursion depth.
+ this->RecursionDepth = parent->RecursionDepth;
}
void cmMakefile::PushFunctionScope(std::string const& fileName,
@@ -1352,6 +1510,9 @@ public:
void Quiet() { this->ReportError = false; }
+ BuildsystemFileScope(const BuildsystemFileScope&) = delete;
+ BuildsystemFileScope& operator=(const BuildsystemFileScope&) = delete;
+
private:
cmMakefile* Makefile;
cmGlobalGenerator* GG;
@@ -1375,10 +1536,10 @@ void cmMakefile::Configure()
// make sure the CMakeFiles dir is there
std::string filesDir = this->StateSnapshot.GetDirectory().GetCurrentBinary();
- filesDir += cmake::GetCMakeFilesDirectory();
- cmSystemTools::MakeDirectory(filesDir.c_str());
+ filesDir += "/CMakeFiles";
+ cmSystemTools::MakeDirectory(filesDir);
- assert(cmSystemTools::FileExists(currentStart.c_str(), true));
+ assert(cmSystemTools::FileExists(currentStart, true));
this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str());
cmListFile listFile;
@@ -1389,10 +1550,8 @@ void cmMakefile::Configure()
if (this->IsRootMakefile()) {
bool hasVersion = false;
// search for the right policy command
- for (std::vector<cmListFileFunction>::iterator i =
- listFile.Functions.begin();
- i != listFile.Functions.end(); ++i) {
- if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required") {
+ for (cmListFileFunction const& func : listFile.Functions) {
+ if (func.Name.Lower == "cmake_minimum_required") {
hasVersion = true;
break;
}
@@ -1418,11 +1577,8 @@ void cmMakefile::Configure()
allowedCommands.insert("option");
allowedCommands.insert("message");
isProblem = false;
- for (std::vector<cmListFileFunction>::iterator i =
- listFile.Functions.begin();
- i != listFile.Functions.end(); ++i) {
- std::string name = cmSystemTools::LowerCase(i->Name);
- if (allowedCommands.find(name) == allowedCommands.end()) {
+ for (cmListFileFunction const& func : listFile.Functions) {
+ if (allowedCommands.find(func.Name.Lower) == allowedCommands.end()) {
isProblem = true;
break;
}
@@ -1435,25 +1591,35 @@ void cmMakefile::Configure()
this->SetCheckCMP0000(true);
// Implicitly set the version for the user.
- this->SetPolicyVersion("2.4");
+ this->SetPolicyVersion("2.4", std::string());
}
}
bool hasProject = false;
// search for a project command
- for (std::vector<cmListFileFunction>::iterator i =
- listFile.Functions.begin();
- i != listFile.Functions.end(); ++i) {
- if (cmSystemTools::LowerCase(i->Name) == "project") {
+ for (cmListFileFunction const& func : listFile.Functions) {
+ if (func.Name.Lower == "project") {
hasProject = true;
break;
}
}
// if no project command is found, add one
if (!hasProject) {
+ this->GetCMakeInstance()->IssueMessage(
+ MessageType::AUTHOR_WARNING,
+ "No project() command is present. The top-level CMakeLists.txt "
+ "file must contain a literal, direct call to the project() command. "
+ "Add a line of code such as\n"
+ " project(ProjectName)\n"
+ "near the top of the file, but after cmake_minimum_required().\n"
+ "CMake is pretending there is a \"project(Project)\" command on "
+ "the first line.",
+ this->Backtrace);
cmListFileFunction project;
- project.Name = "PROJECT";
- cmListFileArgument prj("Project", cmListFileArgument::Unquoted, 0);
- project.Arguments.push_back(prj);
+ project.Name.Lower = "project";
+ project.Arguments.emplace_back("Project", cmListFileArgument::Unquoted,
+ 0);
+ project.Arguments.emplace_back("__CMAKE_INJECTED_PROJECT_COMMAND__",
+ cmListFileArgument::Unquoted, 0);
listFile.Functions.insert(listFile.Functions.begin(), project);
}
}
@@ -1483,7 +1649,7 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf)
if (this->GetCMakeInstance()->GetDebugOutput()) {
std::string msg = " Entering ";
msg += currentStart;
- cmSystemTools::Message(msg.c_str());
+ cmSystemTools::Message(msg);
}
std::string const currentStartFile = currentStart + "/CMakeLists.txt";
@@ -1506,7 +1672,7 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf)
<< "\n"
<< cmPolicies::GetPolicyWarning(cmPolicies::CMP0014);
/* clang-format on */
- this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
case cmPolicies::OLD:
// OLD behavior does not warn.
break;
@@ -1516,7 +1682,7 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf)
CM_FALLTHROUGH;
case cmPolicies::NEW:
// NEW behavior prints the error.
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
return;
}
@@ -1526,7 +1692,7 @@ void cmMakefile::ConfigureSubDirectory(cmMakefile* mf)
if (this->GetCMakeInstance()->GetDebugOutput()) {
std::string msg = " Returning to ";
msg += this->GetCurrentSourceDirectory();
- cmSystemTools::Message(msg.c_str());
+ cmSystemTools::Message(msg);
}
}
@@ -1545,7 +1711,7 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
newSnapshot.GetDirectory().SetCurrentSource(srcPath);
newSnapshot.GetDirectory().SetCurrentBinary(binPath);
- cmSystemTools::MakeDirectory(binPath.c_str());
+ cmSystemTools::MakeDirectory(binPath);
cmMakefile* subMf = new cmMakefile(this->GlobalGenerator, newSnapshot);
this->GetGlobalGenerator()->AddMakefile(subMf);
@@ -1559,14 +1725,17 @@ void cmMakefile::AddSubDirectory(const std::string& srcPath,
} else {
this->UnConfiguredDirectories.push_back(subMf);
}
+
+ this->AddInstallGenerator(new cmInstallSubdirectoryGenerator(
+ subMf, binPath.c_str(), excludeFromAll));
}
-const char* cmMakefile::GetCurrentSourceDirectory() const
+const std::string& cmMakefile::GetCurrentSourceDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentSource();
}
-const char* cmMakefile::GetCurrentBinaryDirectory() const
+const std::string& cmMakefile::GetCurrentBinaryDirectory() const
{
return this->StateSnapshot.GetDirectory().GetCurrentBinary();
}
@@ -1575,9 +1744,8 @@ std::vector<cmTarget*> cmMakefile::GetImportedTargets() const
{
std::vector<cmTarget*> tgts;
tgts.reserve(this->ImportedTargets.size());
- for (TargetMap::const_iterator it = this->ImportedTargets.begin();
- it != this->ImportedTargets.end(); ++it) {
- tgts.push_back(it->second);
+ for (auto const& impTarget : this->ImportedTargets) {
+ tgts.push_back(impTarget.second);
}
return tgts;
}
@@ -1600,9 +1768,8 @@ void cmMakefile::AddIncludeDirectories(const std::vector<std::string>& incs,
}
// Property on each target:
- for (cmTargets::iterator l = this->Targets.begin(); l != this->Targets.end();
- ++l) {
- cmTarget& t = l->second;
+ for (auto& target : this->Targets) {
+ cmTarget& t = target.second;
t.InsertInclude(entryString, lfbt, before);
}
}
@@ -1615,9 +1782,8 @@ void cmMakefile::AddSystemIncludeDirectories(const std::set<std::string>& incs)
this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
- for (cmTargets::iterator l = this->Targets.begin(); l != this->Targets.end();
- ++l) {
- cmTarget& t = l->second;
+ for (auto& target : this->Targets) {
+ cmTarget& t = target.second;
t.AddSystemIncludeDirectories(incs);
}
}
@@ -1647,16 +1813,18 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
cmStateEnums::CacheEntryType type,
bool force)
{
- const char* existingValue = this->GetState()->GetInitializedCacheValue(name);
+ const std::string* existingValue =
+ this->GetState()->GetInitializedCacheValue(name);
// must be outside the following if() to keep it alive long enough
std::string nvalue;
- if (existingValue && (this->GetState()->GetCacheEntryType(name) ==
- cmStateEnums::UNINITIALIZED)) {
+ if (existingValue &&
+ (this->GetState()->GetCacheEntryType(name) ==
+ cmStateEnums::UNINITIALIZED)) {
// 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) {
- value = existingValue;
+ value = existingValue->c_str();
}
if (type == cmStateEnums::PATH || type == cmStateEnums::FILEPATH) {
std::vector<std::string>::size_type cc;
@@ -1664,9 +1832,9 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
nvalue = value ? value : "";
cmSystemTools::ExpandListArgument(nvalue, files);
- nvalue = "";
+ nvalue.clear();
for (cc = 0; cc < files.size(); cc++) {
- if (!cmSystemTools::IsOff(files[cc].c_str())) {
+ if (!cmSystemTools::IsOff(files[cc])) {
files[cc] = cmSystemTools::CollapseFullPath(files[cc]);
}
if (cc > 0) {
@@ -1676,7 +1844,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
}
this->GetCMakeInstance()->AddCacheEntry(name, nvalue.c_str(), doc, type);
- nvalue = this->GetState()->GetInitializedCacheValue(name);
+ nvalue = *this->GetState()->GetInitializedCacheValue(name);
value = nvalue.c_str();
}
}
@@ -1707,10 +1875,8 @@ void cmMakefile::CheckForUnusedVariables() const
if (!this->WarnUnused) {
return;
}
- const std::vector<std::string>& unused = this->StateSnapshot.UnusedKeys();
- std::vector<std::string>::const_iterator it = unused.begin();
- for (; it != unused.end(); ++it) {
- this->LogUnused("out of scope", *it);
+ for (const std::string& key : this->StateSnapshot.UnusedKeys()) {
+ this->LogUnused("out of scope", key);
}
}
@@ -1724,6 +1890,23 @@ bool cmMakefile::VariableInitialized(const std::string& var) const
return this->StateSnapshot.IsInitialized(var);
}
+void cmMakefile::MaybeWarnUninitialized(std::string const& variable,
+ const char* sourceFilename) const
+{
+ // 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(variable)) {
+ if (this->CheckSystemVars ||
+ (sourceFilename && this->IsProjectFile(sourceFilename))) {
+ std::ostringstream msg;
+ msg << "uninitialized variable \'" << variable << "\'";
+ this->IssueMessage(MessageType::AUTHOR_WARNING, msg.str());
+ }
+ }
+}
+
void cmMakefile::LogUnused(const char* reason, const std::string& name) const
{
if (this->WarnUnused) {
@@ -1735,14 +1918,10 @@ void cmMakefile::LogUnused(const char* reason, const std::string& name) const
path += "/CMakeLists.txt";
}
- if (this->CheckSystemVars ||
- cmSystemTools::IsSubDirectory(path, this->GetHomeDirectory()) ||
- (cmSystemTools::IsSubDirectory(path, this->GetHomeOutputDirectory()) &&
- !cmSystemTools::IsSubDirectory(path,
- cmake::GetCMakeFilesDirectory()))) {
+ if (this->CheckSystemVars || this->IsProjectFile(path.c_str())) {
std::ostringstream msg;
msg << "unused variable (" << reason << ") \'" << name << "\'";
- this->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, msg.str());
}
}
}
@@ -1757,7 +1936,7 @@ void cmMakefile::RemoveDefinition(const std::string& name)
cmVariableWatch* vv = this->GetVariableWatch();
if (vv) {
vv->VariableAccessed(name, cmVariableWatch::VARIABLE_REMOVED_ACCESS,
- CM_NULLPTR, this);
+ nullptr, this);
}
#endif
}
@@ -1782,20 +1961,6 @@ void cmMakefile::AddGlobalLinkInformation(cmTarget& target)
return;
default:;
}
- if (const char* linkDirsProp = this->GetProperty("LINK_DIRECTORIES")) {
- std::vector<std::string> linkDirs;
- cmSystemTools::ExpandListArgument(linkDirsProp, linkDirs);
-
- for (std::vector<std::string>::iterator j = linkDirs.begin();
- j != linkDirs.end(); ++j) {
- std::string newdir = *j;
- // remove trailing slashes
- if (*j->rbegin() == '/') {
- newdir = j->substr(0, j->size() - 1);
- }
- target.AddLinkDirectory(*j);
- }
- }
if (const char* linkLibsProp = this->GetProperty("LINK_LIBRARIES")) {
std::vector<std::string> linkLibs;
@@ -1844,7 +2009,7 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname,
// Clear its dependencies. Otherwise, dependencies might persist
// over changes in CMakeLists.txt, making the information stale and
// hence useless.
- target->ClearDependencyInformation(*this, lname);
+ target->ClearDependencyInformation(*this);
if (excludeFromAll) {
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
@@ -1853,7 +2018,7 @@ cmTarget* cmMakefile::AddLibrary(const std::string& lname,
return target;
}
-cmTarget* cmMakefile::AddExecutable(const char* exeName,
+cmTarget* cmMakefile::AddExecutable(const std::string& exeName,
const std::vector<std::string>& srcs,
bool excludeFromAll)
{
@@ -1869,10 +2034,9 @@ cmTarget* cmMakefile::AddExecutable(const char* exeName,
cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type,
const std::string& name)
{
- cmTargets::iterator it =
+ cmTargetMap::iterator it =
this->Targets
- .insert(cmTargets::value_type(
- name, cmTarget(name, type, cmTarget::VisibilityNormal, this)))
+ .emplace(name, cmTarget(name, type, cmTarget::VisibilityNormal, this))
.first;
this->GetGlobalGenerator()->IndexTarget(&it->second);
this->GetStateSnapshot().GetDirectory().AddNormalTargetName(name);
@@ -1886,29 +2050,26 @@ cmSourceFile* cmMakefile::LinearGetSourceFileWithOutput(
// 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) {
+ for (cmSourceFile* src : this->SourceFiles) {
// does this source file have a custom command?
- if ((*i)->GetCustomCommand()) {
+ if (src->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;
+ src->GetCustomCommand()->GetOutputs();
+ for (std::string const& output : outputs) {
+ out = output;
std::string::size_type pos = out.rfind(name);
// If the output matches exactly
if (pos != std::string::npos && pos == out.size() - name.size() &&
(pos == 0 || out[pos - 1] == '/')) {
- return *i;
+ return src;
}
}
}
}
// otherwise return NULL
- return CM_NULLPTR;
+ return nullptr;
}
cmSourceFile* cmMakefile::GetSourceFileWithOutput(
@@ -1916,7 +2077,7 @@ cmSourceFile* cmMakefile::GetSourceFileWithOutput(
{
// 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())) {
+ if (!cmSystemTools::FileIsFullPath(name)) {
return this->LinearGetSourceFileWithOutput(name);
}
// Otherwise we use an efficient lookup map.
@@ -1924,31 +2085,29 @@ cmSourceFile* cmMakefile::GetSourceFileWithOutput(
if (o != this->OutputToSource.end()) {
return (*o).second;
}
- return CM_NULLPTR;
+ return nullptr;
}
#if defined(CMAKE_BUILD_WITH_CMAKE)
cmSourceGroup* cmMakefile::GetSourceGroup(
const std::vector<std::string>& name) const
{
- cmSourceGroup* sg = CM_NULLPTR;
+ cmSourceGroup* sg = nullptr;
// first look for source group starting with the same as the one we want
- for (std::vector<cmSourceGroup>::const_iterator sgIt =
- this->SourceGroups.begin();
- sgIt != this->SourceGroups.end(); ++sgIt) {
- std::string sgName = sgIt->GetName();
+ for (cmSourceGroup const& srcGroup : this->SourceGroups) {
+ std::string const& sgName = srcGroup.GetName();
if (sgName == name[0]) {
- sg = const_cast<cmSourceGroup*>(&(*sgIt));
+ sg = const_cast<cmSourceGroup*>(&srcGroup);
break;
}
}
- if (sg != CM_NULLPTR) {
+ if (sg != nullptr) {
// 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 == CM_NULLPTR) {
+ sg = sg->LookupChild(name[i]);
+ if (sg == nullptr) {
break;
}
}
@@ -1966,14 +2125,14 @@ void cmMakefile::AddSourceGroup(const std::string& name, const char* regex)
void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
const char* regex)
{
- cmSourceGroup* sg = CM_NULLPTR;
+ cmSourceGroup* sg = nullptr;
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 != CM_NULLPTR) {
+ if (sg != nullptr) {
break;
}
}
@@ -1991,7 +2150,7 @@ void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
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));
+ this->SourceGroups.emplace_back(name[0], regex);
sg = this->GetSourceGroup(currentName);
i = 0; // last component found
}
@@ -2001,14 +2160,65 @@ void cmMakefile::AddSourceGroup(const std::vector<std::string>& name,
}
// build the whole source group path
for (++i; i <= lastElement; ++i) {
- sg->AddChild(
- cmSourceGroup(name[i].c_str(), CM_NULLPTR, sg->GetFullName()));
- sg = sg->LookupChild(name[i].c_str());
+ sg->AddChild(cmSourceGroup(name[i], nullptr, sg->GetFullName().c_str()));
+ sg = sg->LookupChild(name[i]);
}
sg->SetGroupRegex(regex);
}
+cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(
+ const std::vector<std::string>& folders)
+{
+ cmSourceGroup* sg = this->GetSourceGroup(folders);
+ if (sg == nullptr) {
+ this->AddSourceGroup(folders);
+ sg = this->GetSourceGroup(folders);
+ }
+ return sg;
+}
+
+cmSourceGroup* cmMakefile::GetOrCreateSourceGroup(const std::string& name)
+{
+ const char* delimiter = this->GetDefinition("SOURCE_GROUP_DELIMITER");
+ if (delimiter == nullptr) {
+ delimiter = "\\";
+ }
+ return this->GetOrCreateSourceGroup(
+ cmSystemTools::tokenize(name, delimiter));
+}
+
+/**
+ * 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 std::string& 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.data();
+}
#endif
static bool mightExpandVariablesCMP0019(const char* s)
@@ -2041,9 +2251,8 @@ void cmMakefile::ExpandVariablesCMP0019()
}
// Also for each target's INCLUDE_DIRECTORIES property:
- for (cmTargets::iterator l = this->Targets.begin(); l != this->Targets.end();
- ++l) {
- cmTarget& t = l->second;
+ for (auto& target : this->Targets) {
+ cmTarget& t = target.second;
if (t.GetType() == cmStateEnums::INTERFACE_LIBRARY ||
t.GetType() == cmStateEnums::GLOBAL_TARGET) {
continue;
@@ -2117,8 +2326,8 @@ void cmMakefile::ExpandVariablesCMP0019()
<< "The following variable evaluations were encountered:\n"
<< w.str();
/* clang-format on */
- this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, m.str(),
- this->Backtrace);
+ this->GetCMakeInstance()->IssueMessage(MessageType::AUTHOR_WARNING,
+ m.str(), this->Backtrace);
}
}
@@ -2179,25 +2388,38 @@ bool cmMakefile::PlatformIsx32() const
return false;
}
-bool cmMakefile::PlatformIsAppleIos() const
+cmMakefile::AppleSDK cmMakefile::GetAppleSDKType() const
{
std::string sdkRoot;
sdkRoot = this->GetSafeDefinition("CMAKE_OSX_SYSROOT");
sdkRoot = cmSystemTools::LowerCase(sdkRoot);
- const std::string embedded[] = {
- "appletvos", "appletvsimulator", "iphoneos",
- "iphonesimulator", "watchos", "watchsimulator",
+ struct
+ {
+ std::string name;
+ AppleSDK sdk;
+ } const sdkDatabase[]{
+ { "appletvos", AppleSDK::AppleTVOS },
+ { "appletvsimulator", AppleSDK::AppleTVSimulator },
+ { "iphoneos", AppleSDK::IPhoneOS },
+ { "iphonesimulator", AppleSDK::IPhoneSimulator },
+ { "watchos", AppleSDK::WatchOS },
+ { "watchsimulator", AppleSDK::WatchSimulator },
};
- for (size_t i = 0; i < sizeof(embedded) / sizeof(embedded[0]); ++i) {
- if (sdkRoot.find(embedded[i]) == 0 ||
- sdkRoot.find(std::string("/") + embedded[i]) != std::string::npos) {
- return true;
+ for (auto const& entry : sdkDatabase) {
+ if (sdkRoot.find(entry.name) == 0 ||
+ sdkRoot.find(std::string("/") + entry.name) != std::string::npos) {
+ return entry.sdk;
}
}
- return false;
+ return AppleSDK::MacOS;
+}
+
+bool cmMakefile::PlatformIsAppleEmbedded() const
+{
+ return GetAppleSDKType() != AppleSDK::MacOS;
}
const char* cmMakefile::GetSONameFlag(const std::string& language) const
@@ -2211,7 +2433,7 @@ const char* cmMakefile::GetSONameFlag(const std::string& language) const
return GetDefinition(name);
}
-bool cmMakefile::CanIWriteThisFile(const char* fileName) const
+bool cmMakefile::CanIWriteThisFile(std::string const& fileName) const
{
if (!this->IsOn("CMAKE_DISABLE_SOURCE_CHANGES")) {
return true;
@@ -2223,24 +2445,28 @@ bool cmMakefile::CanIWriteThisFile(const char* fileName) const
}
return !cmSystemTools::IsSubDirectory(fileName, this->GetHomeDirectory()) ||
- cmSystemTools::IsSubDirectory(fileName, this->GetHomeOutputDirectory());
+ cmSystemTools::IsSubDirectory(fileName, this->GetHomeOutputDirectory()) ||
+ cmSystemTools::SameFile(fileName, this->GetHomeOutputDirectory());
}
-const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
+const std::string& cmMakefile::GetRequiredDefinition(
+ const std::string& name) const
{
- const char* ret = this->GetDefinition(name);
- if (!ret) {
+ static std::string const empty;
+ const std::string* def = GetDef(name);
+ if (!def) {
cmSystemTools::Error("Error required internal CMake variable not "
- "set, cmake may not be built correctly.\n",
- "Missing variable is:\n", name.c_str());
- return "";
+ "set, cmake may not be built correctly.\n"
+ "Missing variable is:\n" +
+ name);
+ return empty;
}
- return ret;
+ return *def;
}
bool cmMakefile::IsDefinitionSet(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
+ const std::string* def = this->StateSnapshot.GetDefinition(name);
if (!def) {
def = this->GetState()->GetInitializedCacheValue(name);
}
@@ -2248,26 +2474,27 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
if (cmVariableWatch* vv = this->GetVariableWatch()) {
if (!def) {
vv->VariableAccessed(
- name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS, def, this);
+ name, cmVariableWatch::UNKNOWN_VARIABLE_DEFINED_ACCESS, nullptr, this);
}
}
#endif
- return def != CM_NULLPTR;
+ return def != nullptr;
}
-const char* cmMakefile::GetDefinition(const std::string& name) const
+const std::string* cmMakefile::GetDef(const std::string& name) const
{
- const char* def = this->StateSnapshot.GetDefinition(name);
+ const std::string* def = this->StateSnapshot.GetDefinition(name);
if (!def) {
def = this->GetState()->GetInitializedCacheValue(name);
}
#ifdef CMAKE_BUILD_WITH_CMAKE
cmVariableWatch* vv = this->GetVariableWatch();
- if (vv && !this->SuppressWatches) {
- bool const watch_function_executed = vv->VariableAccessed(
- name, def ? cmVariableWatch::VARIABLE_READ_ACCESS
- : cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS,
- def, this);
+ if (vv && !this->SuppressSideEffects) {
+ bool const watch_function_executed =
+ vv->VariableAccessed(name,
+ def ? cmVariableWatch::VARIABLE_READ_ACCESS
+ : cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS,
+ (def ? def->c_str() : nullptr), this);
if (watch_function_executed) {
// A callback was executed and may have caused re-allocation of the
@@ -2283,35 +2510,45 @@ const char* cmMakefile::GetDefinition(const std::string& name) const
return def;
}
-const char* cmMakefile::GetSafeDefinition(const std::string& def) const
+const char* cmMakefile::GetDefinition(const std::string& name) const
{
- const char* ret = this->GetDefinition(def);
- if (!ret) {
- return "";
+ const std::string* def = GetDef(name);
+ if (!def) {
+ return nullptr;
}
- return ret;
+ return def->c_str();
+}
+
+const std::string& cmMakefile::GetSafeDefinition(const std::string& name) const
+{
+ static std::string const empty;
+ const std::string* def = GetDef(name);
+ if (!def) {
+ return empty;
+ }
+ return *def;
}
std::vector<std::string> cmMakefile::GetDefinitions() const
{
std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
- std::vector<std::string> cacheKeys = this->GetState()->GetCacheEntryKeys();
- res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
+ cmAppend(res, this->GetState()->GetCacheEntryKeys());
std::sort(res.begin(), res.end());
return res;
}
-const char* cmMakefile::ExpandVariablesInString(std::string& source) const
+const std::string& cmMakefile::ExpandVariablesInString(
+ std::string& source) const
{
return this->ExpandVariablesInString(source, false, false);
}
-const char* cmMakefile::ExpandVariablesInString(
+const std::string& 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;
+ MessageType mtype = MessageType::LOG;
std::string errorstr;
std::string original;
@@ -2319,16 +2556,16 @@ const char* cmMakefile::ExpandVariablesInString(
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,
+ this->IssueMessage(MessageType::INTERNAL_ERROR,
"ExpandVariablesInString @ONLY called "
"on something with escapes.");
- return source.c_str();
+ return source;
}
// Variables used in the WARN case.
std::string newResult;
std::string newErrorstr;
- cmake::MessageType newError = cmake::LOG;
+ MessageType newError = MessageType::LOG;
switch (this->GetPolicyStatus(cmPolicies::CMP0053)) {
case cmPolicies::WARN: {
@@ -2338,11 +2575,11 @@ const char* cmMakefile::ExpandVariablesInString(
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;
+ this->SuppressSideEffects = true;
+ newError = ExpandVariablesInStringNew(newErrorstr, newResult,
+ escapeQuotes, noEscapes, atOnly,
+ filename, line, replaceAt);
+ this->SuppressSideEffects = false;
CM_FALLTHROUGH;
}
case cmPolicies::OLD:
@@ -2354,15 +2591,15 @@ const char* cmMakefile::ExpandVariablesInString(
case cmPolicies::REQUIRED_ALWAYS:
// Messaging here would be *very* verbose.
case cmPolicies::NEW:
- mtype = ExpandVariablesInStringNew(errorstr, source, escapeQuotes,
- noEscapes, atOnly, filename, line,
- removeEmpty, replaceAt);
+ mtype =
+ ExpandVariablesInStringNew(errorstr, source, escapeQuotes, noEscapes,
+ atOnly, filename, line, replaceAt);
break;
}
// If it's an error in either case, just report the error...
- if (mtype != cmake::LOG) {
- if (mtype == cmake::FATAL_ERROR) {
+ if (mtype != MessageType::LOG) {
+ if (mtype == MessageType::FATAL_ERROR) {
cmSystemTools::SetFatalErrorOccured();
}
this->IssueMessage(mtype, errorstr);
@@ -2401,20 +2638,20 @@ const char* cmMakefile::ExpandVariablesInString(
msg +=
"Using the old result for compatibility since the policy is not set.";
- this->IssueMessage(cmake::AUTHOR_WARNING, msg);
+ this->IssueMessage(MessageType::AUTHOR_WARNING, msg);
}
- return source.c_str();
+ return source;
}
-cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
+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("$@\\") == std::string::npos) {
- return cmake::LOG;
+ return MessageType::LOG;
}
// Special-case the @ONLY mode.
@@ -2423,7 +2660,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
std::string input = source;
// Start with empty output.
- source = "";
+ source.clear();
// Look for one @VAR@ at a time.
const char* in = input.c_str();
@@ -2453,7 +2690,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
// Append the rest of the unchanged part of the string.
source.append(in);
- return cmake::LOG;
+ return MessageType::LOG;
}
// This method replaces ${VAR} and @VAR@ where VAR is looked up
@@ -2470,7 +2707,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
parser.SetRemoveEmpty(removeEmpty);
int res = parser.ParseString(source.c_str(), 0);
const char* emsg = parser.GetError();
- cmake::MessageType mtype = cmake::LOG;
+ MessageType mtype = MessageType::LOG;
if (res && !emsg[0]) {
source = parser.GetResult();
} else {
@@ -2493,7 +2730,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
// parser reported an error message without failing because the
// helper implementation is unhappy, which has always reported an
// error.
- mtype = cmake::FATAL_ERROR;
+ mtype = MessageType::FATAL_ERROR;
if (!res) {
// This is a real argument parsing error. Use policy CMP0010 to
// decide whether it is an error.
@@ -2503,7 +2740,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
CM_FALLTHROUGH;
case cmPolicies::OLD:
// OLD behavior is to just warn and continue.
- mtype = cmake::AUTHOR_WARNING;
+ mtype = MessageType::AUTHOR_WARNING;
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
@@ -2519,22 +2756,39 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringOld(
return mtype;
}
-typedef enum { NORMAL, ENVIRONMENT, CACHE } t_domain;
+typedef enum
+{
+ NORMAL,
+ ENVIRONMENT,
+ CACHE
+} t_domain;
struct t_lookup
{
- t_lookup()
- : domain(NORMAL)
- , loc(0)
- {
- }
- t_domain domain;
- size_t loc;
+ t_domain domain = NORMAL;
+ size_t loc = 0;
};
-cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
+bool cmMakefile::IsProjectFile(const char* filename) const
+{
+ return cmSystemTools::IsSubDirectory(filename, this->GetHomeDirectory()) ||
+ (cmSystemTools::IsSubDirectory(filename, this->GetHomeOutputDirectory()) &&
+ !cmSystemTools::IsSubDirectory(filename, "/CMakeFiles"));
+}
+
+int cmMakefile::GetRecursionDepth() const
+{
+ return this->RecursionDepth;
+}
+
+void cmMakefile::SetRecursionDepth(int recursionDepth)
+{
+ this->RecursionDepth = recursionDepth;
+}
+
+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
+ 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.
@@ -2548,10 +2802,11 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
std::vector<t_lookup> openstack;
bool error = false;
bool done = false;
- cmake::MessageType mtype = cmake::LOG;
+ MessageType mtype = MessageType::LOG;
cmState* state = this->GetCMakeInstance()->GetState();
+ static const std::string lineVar = "CMAKE_CURRENT_LIST_LINE";
do {
char inc = *in;
switch (inc) {
@@ -2561,10 +2816,9 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
openstack.pop_back();
result.append(last, in - last);
std::string const& lookup = result.substr(var.loc);
- const char* value = CM_NULLPTR;
+ const char* value = nullptr;
std::string varresult;
std::string svalue;
- static const std::string lineVar = "CMAKE_CURRENT_LIST_LINE";
switch (var.domain) {
case NORMAL:
if (filename && lookup == lineVar) {
@@ -2591,22 +2845,8 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
} 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())) {
- std::ostringstream msg;
- msg << "uninitialized variable \'" << lookup << "\'";
- this->IssueMessage(cmake::AUTHOR_WARNING, msg.str());
- }
- }
+ } else if (!this->SuppressSideEffects) {
+ this->MaybeWarnUninitialized(lookup, filename);
}
result.replace(var.loc, result.size() - var.loc, varresult);
// Start looking from here on out.
@@ -2617,7 +2857,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
if (!atOnly) {
t_lookup lookup;
const char* next = in + 1;
- const char* start = CM_NULLPTR;
+ const char* start = nullptr;
char nextc = *next;
if (nextc == '{') {
// Looking for a variable.
@@ -2641,7 +2881,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
std::string(next, this->cmNamedCurly.end()) +
"{} is not supported. Only ${}, $ENV{}, "
"and $CACHE{} are allowed.";
- mtype = cmake::FATAL_ERROR;
+ mtype = MessageType::FATAL_ERROR;
error = true;
}
}
@@ -2707,11 +2947,25 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
const char* nextAt = strchr(in + 1, '@');
if (nextAt && nextAt != in + 1 &&
nextAt ==
- in + 1 + strspn(in + 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789/_.+-")) {
+ in + 1 +
+ strspn(in + 1,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789/_.+-")) {
std::string variable(in + 1, nextAt - in - 1);
- std::string varresult = this->GetSafeDefinition(variable);
+
+ std::string varresult;
+ if (filename && variable == lineVar) {
+ varresult = std::to_string(line);
+ } else {
+ const std::string* def = this->GetDef(variable);
+ if (def) {
+ varresult = *def;
+ } else if (!this->SuppressSideEffects) {
+ this->MaybeWarnUninitialized(variable, filename);
+ }
+ }
+
if (escapeQuotes) {
varresult = cmSystemTools::EscapeQuotes(varresult);
}
@@ -2735,7 +2989,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
errorstr += "\') in a variable name: "
"'" +
result.substr(openstack.back().loc) + "'";
- mtype = cmake::FATAL_ERROR;
+ mtype = MessageType::FATAL_ERROR;
error = true;
}
break;
@@ -2766,7 +3020,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
emsg << "when parsing string\n"
<< " " << source << "\n";
emsg << errorstr;
- mtype = cmake::FATAL_ERROR;
+ mtype = MessageType::FATAL_ERROR;
errorstr = emsg.str();
} else {
// Append the rest of the unchanged part of the string.
@@ -2817,40 +3071,6 @@ std::string cmMakefile::GetConfigurations(std::vector<std::string>& configs,
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)
{
@@ -2861,10 +3081,8 @@ bool cmMakefile::IsFunctionBlocked(const cmListFileFunction& lff,
// 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)) {
+ for (cmFunctionBlocker* pos : cmReverseRange(this->FunctionBlockers)) {
+ if (pos->IsFunctionBlocked(lff, *this, status)) {
return true;
}
}
@@ -2883,7 +3101,7 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError)
FunctionBlockersType::size_type barrier =
this->FunctionBlockerBarriers.back();
while (this->FunctionBlockers.size() > barrier) {
- CM_AUTO_PTR<cmFunctionBlocker> fb(this->FunctionBlockers.back());
+ std::unique_ptr<cmFunctionBlocker> fb(this->FunctionBlockers.back());
this->FunctionBlockers.pop_back();
if (reportError) {
// Report the context in which the unclosed block was opened.
@@ -2894,7 +3112,7 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError)
<< " " << lfc << "\n"
<< "is not closed.";
/* clang-format on */
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
reportError = false;
}
}
@@ -2948,23 +3166,22 @@ bool cmMakefile::ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
if (!filename) {
filename = efp.c_str();
}
- std::vector<cmListFileArgument>::const_iterator i;
std::string value;
outArgs.reserve(inArgs.size());
- for (i = inArgs.begin(); i != inArgs.end(); ++i) {
+ for (cmListFileArgument const& i : inArgs) {
// No expansion in a bracket argument.
- if (i->Delim == cmListFileArgument::Bracket) {
- outArgs.push_back(i->Value);
+ 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, filename,
- i->Line, false, false);
+ value = i.Value;
+ this->ExpandVariablesInString(value, false, false, false, filename, 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) {
+ if (i.Delim == cmListFileArgument::Quoted) {
outArgs.push_back(value);
} else {
cmSystemTools::ExpandListArgument(value, outArgs);
@@ -2981,29 +3198,28 @@ bool cmMakefile::ExpandArguments(
if (!filename) {
filename = efp.c_str();
}
- std::vector<cmListFileArgument>::const_iterator i;
std::string value;
outArgs.reserve(inArgs.size());
- for (i = inArgs.begin(); i != inArgs.end(); ++i) {
+ for (cmListFileArgument const& i : inArgs) {
// No expansion in a bracket argument.
- if (i->Delim == cmListFileArgument::Bracket) {
- outArgs.push_back(cmExpandedCommandArgument(i->Value, true));
+ if (i.Delim == cmListFileArgument::Bracket) {
+ outArgs.emplace_back(i.Value, true);
continue;
}
// Expand the variables in the argument.
- value = i->Value;
- this->ExpandVariablesInString(value, false, false, false, filename,
- i->Line, false, false);
+ value = i.Value;
+ this->ExpandVariablesInString(value, false, false, false, filename, 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));
+ if (i.Delim == cmListFileArgument::Quoted) {
+ outArgs.emplace_back(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));
+ for (std::string const& stringArg : stringArgs) {
+ outArgs.emplace_back(stringArg, false);
}
}
}
@@ -3020,7 +3236,7 @@ void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb)
this->FunctionBlockers.push_back(fb);
}
-CM_AUTO_PTR<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker(
+std::unique_ptr<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker(
cmFunctionBlocker* fb, const cmListFileFunction& lff)
{
// Find the function blocker stack barrier for the current scope.
@@ -3049,30 +3265,30 @@ CM_AUTO_PTR<cmFunctionBlocker> cmMakefile::RemoveFunctionBlocker(
<< " " << closingContext << "\n"
<< "with mis-matching arguments.";
/* clang-format on */
- this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
}
cmFunctionBlocker* b = *pos;
this->FunctionBlockers.erase(pos);
- return CM_AUTO_PTR<cmFunctionBlocker>(b);
+ return std::unique_ptr<cmFunctionBlocker>(b);
}
}
- return CM_AUTO_PTR<cmFunctionBlocker>();
+ return std::unique_ptr<cmFunctionBlocker>();
}
-const char* cmMakefile::GetHomeDirectory() const
+std::string const& cmMakefile::GetHomeDirectory() const
{
return this->GetCMakeInstance()->GetHomeDirectory();
}
-const char* cmMakefile::GetHomeOutputDirectory() const
+std::string const& cmMakefile::GetHomeOutputDirectory() const
{
return this->GetCMakeInstance()->GetHomeOutputDirectory();
}
-void cmMakefile::SetScriptModeFile(const char* scriptfile)
+void cmMakefile::SetScriptModeFile(std::string const& scriptfile)
{
- this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile);
+ this->AddDefinition("CMAKE_SCRIPT_MODE_FILE", scriptfile.c_str());
}
void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
@@ -3090,38 +3306,65 @@ void cmMakefile::SetArgcArgv(const std::vector<std::string>& args)
}
}
-cmSourceFile* cmMakefile::GetSource(const std::string& sourceName) const
+cmSourceFile* cmMakefile::GetSource(const std::string& sourceName,
+ cmSourceFileLocationKind kind) 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;
+ // First check "Known" paths (avoids the creation of cmSourceFileLocation)
+ if (kind == cmSourceFileLocationKind::Known) {
+ auto sfsi = this->KnownFileSearchIndex.find(sourceName);
+ if (sfsi != this->KnownFileSearchIndex.end()) {
+ return sfsi->second;
+ }
+ }
+
+ cmSourceFileLocation sfl(this, sourceName, kind);
+ auto name = this->GetCMakeInstance()->StripExtension(sfl.GetName());
+#if defined(_WIN32) || defined(__APPLE__)
+ name = cmSystemTools::LowerCase(name);
+#endif
+ auto sfsi = this->SourceFileSearchIndex.find(name);
+ if (sfsi != this->SourceFileSearchIndex.end()) {
+ for (auto sf : sfsi->second) {
+ if (sf->Matches(sfl)) {
+ return sf;
+ }
}
}
- return CM_NULLPTR;
+ return nullptr;
}
cmSourceFile* cmMakefile::CreateSource(const std::string& sourceName,
- bool generated)
+ bool generated,
+ cmSourceFileLocationKind kind)
{
- cmSourceFile* sf = new cmSourceFile(this, sourceName);
+ cmSourceFile* sf = new cmSourceFile(this, sourceName, kind);
if (generated) {
sf->SetProperty("GENERATED", "1");
}
this->SourceFiles.push_back(sf);
+
+ auto name =
+ this->GetCMakeInstance()->StripExtension(sf->GetLocation().GetName());
+#if defined(_WIN32) || defined(__APPLE__)
+ name = cmSystemTools::LowerCase(name);
+#endif
+ this->SourceFileSearchIndex[name].push_back(sf);
+ // for "Known" paths add direct lookup (used for faster lookup in GetSource)
+ if (kind == cmSourceFileLocationKind::Known) {
+ this->KnownFileSearchIndex[sourceName] = sf;
+ }
+
return sf;
}
cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName,
- bool generated)
+ bool generated,
+ cmSourceFileLocationKind kind)
{
- if (cmSourceFile* esf = this->GetSource(sourceName)) {
+ if (cmSourceFile* esf = this->GetSource(sourceName, kind)) {
return esf;
}
- return this->CreateSource(sourceName, generated);
+ return this->CreateSource(sourceName, generated, kind);
}
void cmMakefile::AddTargetObject(std::string const& tgtName,
@@ -3147,12 +3390,11 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const& lang,
std::vector<std::string> langs;
std::vector<std::string> langsRC;
langs.reserve(lang.size());
- for (std::vector<std::string>::const_iterator i = lang.begin();
- i != lang.end(); ++i) {
- if (*i == "RC") {
- langsRC.push_back(*i);
+ for (std::string const& i : lang) {
+ if (i == "RC") {
+ langsRC.push_back(i);
} else {
- langs.push_back(*i);
+ langs.push_back(i);
}
}
if (!langs.empty()) {
@@ -3166,42 +3408,53 @@ void cmMakefile::EnableLanguage(std::vector<std::string> const& lang,
int cmMakefile::TryCompile(const std::string& srcdir,
const std::string& bindir,
const std::string& projectName,
- const std::string& targetName, bool fast,
+ const std::string& targetName, bool fast, int jobs,
const std::vector<std::string>* cmakeArgs,
std::string& output)
{
this->IsSourceFileTryCompile = fast;
// does the binary directory exist ? If not create it...
if (!cmSystemTools::FileIsDirectory(bindir)) {
- cmSystemTools::MakeDirectory(bindir.c_str());
+ cmSystemTools::MakeDirectory(bindir);
}
// change to the tests directory and run cmake
// use the cmake object instead of calling cmake
cmWorkingDirectory workdir(bindir);
+ if (workdir.Failed()) {
+ this->IssueMessage(MessageType::FATAL_ERROR,
+ "Failed to set working directory to " + bindir + " : " +
+ std::strerror(workdir.GetLastResult()));
+ cmSystemTools::SetFatalErrorOccured();
+ this->IsSourceFileTryCompile = false;
+ return 1;
+ }
// 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
- cmake cm(cmake::RoleProject);
+ cmake cm(cmake::RoleProject, cmState::Project);
cm.SetIsInTryCompile(true);
cmGlobalGenerator* gg =
cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName());
if (!gg) {
- this->IssueMessage(cmake::INTERNAL_ERROR, "Global generator '" +
+ this->IssueMessage(MessageType::INTERNAL_ERROR,
+ "Global generator '" +
this->GetGlobalGenerator()->GetName() +
"' could not be created.");
cmSystemTools::SetFatalErrorOccured();
this->IsSourceFileTryCompile = false;
return 1;
}
+ gg->RecursionDepth = this->RecursionDepth;
cm.SetGlobalGenerator(gg);
// do a configure
cm.SetHomeDirectory(srcdir);
cm.SetHomeOutputDirectory(bindir);
- cm.SetGeneratorPlatform(this->GetCMakeInstance()->GetGeneratorPlatform());
- cm.SetGeneratorToolset(this->GetCMakeInstance()->GetGeneratorToolset());
+ cm.SetGeneratorInstance(this->GetSafeDefinition("CMAKE_GENERATOR_INSTANCE"));
+ cm.SetGeneratorPlatform(this->GetSafeDefinition("CMAKE_GENERATOR_PLATFORM"));
+ cm.SetGeneratorToolset(this->GetSafeDefinition("CMAKE_GENERATOR_TOOLSET"));
cm.LoadCache();
if (!gg->IsMultiConfig()) {
if (const char* config =
@@ -3213,6 +3466,12 @@ int cmMakefile::TryCompile(const std::string& srcdir,
cmStateEnums::STRING);
}
}
+ const char* recursionDepth =
+ this->GetDefinition("CMAKE_MAXIMUM_RECURSION_DEPTH");
+ if (recursionDepth) {
+ cm.AddCacheEntry("CMAKE_MAXIMUM_RECURSION_DEPTH", recursionDepth,
+ "Maximum recursion depth", cmStateEnums::STRING);
+ }
// if cmake args were provided then pass them in
if (cmakeArgs) {
// FIXME: Workaround to ignore unused CLI variables in try-compile.
@@ -3252,7 +3511,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
cmStateEnums::INTERNAL);
}
if (cm.Configure() != 0) {
- this->IssueMessage(cmake::FATAL_ERROR,
+ this->IssueMessage(MessageType::FATAL_ERROR,
"Failed to configure test project build system.");
cmSystemTools::SetFatalErrorOccured();
this->IsSourceFileTryCompile = false;
@@ -3260,7 +3519,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
}
if (cm.Generate() != 0) {
- this->IssueMessage(cmake::FATAL_ERROR,
+ this->IssueMessage(MessageType::FATAL_ERROR,
"Failed to generate test project build system.");
cmSystemTools::SetFatalErrorOccured();
this->IsSourceFileTryCompile = false;
@@ -3269,7 +3528,7 @@ int cmMakefile::TryCompile(const std::string& srcdir,
// finally call the generator to actually build the resulting project
int ret = this->GetGlobalGenerator()->TryCompile(
- srcdir, bindir, projectName, targetName, fast, output, this);
+ jobs, srcdir, bindir, projectName, targetName, fast, output, this);
this->IsSourceFileTryCompile = false;
return ret;
@@ -3302,7 +3561,7 @@ cmVariableWatch* cmMakefile::GetVariableWatch() const
this->GetCMakeInstance()->GetVariableWatch()) {
return this->GetCMakeInstance()->GetVariableWatch();
}
- return CM_NULLPTR;
+ return nullptr;
}
#endif
@@ -3311,7 +3570,7 @@ cmState* cmMakefile::GetState() const
return this->GetCMakeInstance()->GetState();
}
-void cmMakefile::DisplayStatus(const char* message, float s) const
+void cmMakefile::DisplayStatus(const std::string& message, float s) const
{
cmake* cm = this->GetCMakeInstance();
if (cm->GetWorkingMode() == cmake::FIND_PACKAGE_MODE) {
@@ -3322,7 +3581,8 @@ void cmMakefile::DisplayStatus(const char* message, float s) const
cm->UpdateProgress(message, s);
}
-std::string cmMakefile::GetModulesFile(const char* filename) const
+std::string cmMakefile::GetModulesFile(const std::string& filename,
+ bool& system) const
{
std::string result;
@@ -3346,13 +3606,11 @@ std::string cmMakefile::GetModulesFile(const char* filename) const
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;
+ for (std::string itempl : modulePath) {
cmSystemTools::ConvertToUnixSlashes(itempl);
itempl += "/";
itempl += filename;
- if (cmSystemTools::FileExists(itempl.c_str())) {
+ if (cmSystemTools::FileExists(itempl)) {
moduleInCMakeModulePath = itempl;
break;
}
@@ -3364,15 +3622,17 @@ std::string cmMakefile::GetModulesFile(const char* filename) const
moduleInCMakeRoot += "/Modules/";
moduleInCMakeRoot += filename;
cmSystemTools::ConvertToUnixSlashes(moduleInCMakeRoot);
- if (!cmSystemTools::FileExists(moduleInCMakeRoot.c_str())) {
- moduleInCMakeRoot = "";
+ if (!cmSystemTools::FileExists(moduleInCMakeRoot)) {
+ moduleInCMakeRoot.clear();
}
// 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.
+ system = false;
result = moduleInCMakeModulePath;
if (result.empty()) {
+ system = true;
result = moduleInCMakeRoot;
}
@@ -3391,15 +3651,17 @@ std::string cmMakefile::GetModulesFile(const char* filename) const
<< cmPolicies::GetPolicyWarning(cmPolicies::CMP0017);
/* clang-format on */
- this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
CM_FALLTHROUGH;
}
case cmPolicies::OLD:
+ system = false;
result = moduleInCMakeModulePath;
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
+ system = true;
result = moduleInCMakeRoot;
break;
}
@@ -3432,18 +3694,22 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output,
// Replace #cmakedefine instances.
if (this->cmDefineRegex.find(line)) {
- const char* def = this->GetDefinition(this->cmDefineRegex.match(1));
+ const char* def = this->GetDefinition(this->cmDefineRegex.match(2));
if (!cmSystemTools::IsOff(def)) {
- cmSystemTools::ReplaceString(line, "#cmakedefine", "#define");
+ const std::string indentation = this->cmDefineRegex.match(1);
+ cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine",
+ "#" + indentation + "define");
output += line;
} else {
output += "/* #undef ";
- output += this->cmDefineRegex.match(1);
+ output += this->cmDefineRegex.match(2);
output += " */";
}
} else if (this->cmDefine01Regex.find(line)) {
- const char* def = this->GetDefinition(this->cmDefine01Regex.match(1));
- cmSystemTools::ReplaceString(line, "#cmakedefine01", "#define");
+ const std::string indentation = this->cmDefine01Regex.match(1);
+ const char* def = this->GetDefinition(this->cmDefine01Regex.match(2));
+ cmSystemTools::ReplaceString(line, "#" + indentation + "cmakedefine01",
+ "#" + indentation + "define");
output += line;
if (!cmSystemTools::IsOff(def)) {
output += " 1";
@@ -3463,26 +3729,34 @@ void cmMakefile::ConfigureString(const std::string& input, std::string& output,
}
// Perform variable replacements.
- this->ExpandVariablesInString(output, escapeQuotes, true, atOnly, CM_NULLPTR,
- -1, true, true);
+ const char* filename = nullptr;
+ long lineNumber = -1;
+ if (!this->Backtrace.Empty()) {
+ const auto& currentTrace = this->Backtrace.Top();
+ filename = currentTrace.FilePath.c_str();
+ lineNumber = currentTrace.Line;
+ }
+ this->ExpandVariablesInString(output, escapeQuotes, true, atOnly, filename,
+ lineNumber, true, true);
}
-int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
- bool copyonly, bool atOnly, bool escapeQuotes,
+int cmMakefile::ConfigureFile(const std::string& infile,
+ const std::string& outfile, bool copyonly,
+ bool atOnly, bool escapeQuotes,
cmNewLineStyle newLine)
{
int res = 1;
if (!this->CanIWriteThisFile(outfile)) {
- cmSystemTools::Error("Attempt to write file: ", 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.");
+ cmSystemTools::Error("File " + infile + " does not exist.");
return 0;
}
std::string soutfile = outfile;
- std::string sinfile = infile;
+ const std::string& sinfile = infile;
this->AddCMakeDependFile(sinfile);
cmSystemTools::ConvertToUnixSlashes(soutfile);
@@ -3492,16 +3766,15 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
this->AddCMakeOutputFile(soutfile);
mode_t perm = 0;
- cmSystemTools::GetPermissions(sinfile.c_str(), perm);
+ cmSystemTools::GetPermissions(sinfile, 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());
+ cmSystemTools::MakeDirectory(path);
}
if (copyonly) {
- if (!cmSystemTools::CopyFileIfDifferent(sinfile.c_str(),
- soutfile.c_str())) {
+ if (!cmSystemTools::CopyFileIfDifferent(sinfile, soutfile)) {
return 0;
}
} else {
@@ -3517,15 +3790,15 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
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::Error("Could not open file for write in copy operation " +
+ tempOutputFile);
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());
+ cmSystemTools::Error("Could not open file for read in copy operation " +
+ sinfile);
return 0;
}
@@ -3534,7 +3807,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
std::ostringstream e;
e << "File starts with a Byte-Order-Mark that is not UTF-8:\n "
<< sinfile;
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
return 0;
}
// rewind to copy BOM to output file
@@ -3545,18 +3818,17 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
std::string inLine;
std::string outLine;
while (cmSystemTools::GetLineFromStream(fin, inLine)) {
- outLine = "";
+ outLine.clear();
this->ConfigureString(inLine, outLine, atOnly, escapeQuotes);
fout << outLine << newLineCharacters;
}
// close the files before attempting to copy
fin.close();
fout.close();
- if (!cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
- soutfile.c_str())) {
+ if (!cmSystemTools::CopyFileIfDifferent(tempOutputFile, soutfile)) {
res = 0;
} else {
- cmSystemTools::SetPermissions(soutfile.c_str(), perm);
+ cmSystemTools::SetPermissions(soutfile, perm);
}
cmSystemTools::RemoveFile(tempOutputFile);
}
@@ -3579,6 +3851,20 @@ void cmMakefile::AppendProperty(const std::string& prop, const char* value,
const char* cmMakefile::GetProperty(const std::string& prop) const
{
+ // Check for computed properties.
+ static std::string output;
+ if (prop == "TESTS") {
+ std::vector<std::string> keys;
+ // get list of keys
+ std::transform(this->Tests.begin(), this->Tests.end(),
+ std::back_inserter(keys),
+ [](decltype(this->Tests)::value_type const& pair) {
+ return pair.first;
+ });
+ output = cmJoin(keys, ";");
+ return output.c_str();
+ }
+
return this->StateSnapshot.GetDirectory().GetProperty(prop);
}
@@ -3599,11 +3885,11 @@ std::vector<std::string> cmMakefile::GetPropertyKeys() const
cmTarget* cmMakefile::FindLocalNonAliasTarget(const std::string& name) const
{
- cmTargets::iterator i = this->Targets.find(name);
+ cmTargetMap::iterator i = this->Targets.find(name);
if (i != this->Targets.end()) {
return &i->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
cmTest* cmMakefile::CreateTest(const std::string& testName)
@@ -3625,7 +3911,17 @@ cmTest* cmMakefile::GetTest(const std::string& testName) const
if (mi != this->Tests.end()) {
return mi->second;
}
- return CM_NULLPTR;
+ return nullptr;
+}
+
+void cmMakefile::GetTests(const std::string& config,
+ std::vector<cmTest*>& tests)
+{
+ for (auto generator : this->GetTestGenerators()) {
+ if (generator->TestsForConfig(config)) {
+ tests.push_back(generator->GetTest());
+ }
+ }
}
void cmMakefile::AddCMakeDependFilesFromUser()
@@ -3634,14 +3930,13 @@ void cmMakefile::AddCMakeDependFilesFromUser()
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);
+ for (std::string const& dep : deps) {
+ if (cmSystemTools::FileIsFullPath(dep)) {
+ this->AddCMakeDependFile(dep);
} else {
std::string f = this->GetCurrentSourceDirectory();
f += "/";
- f += *i;
+ f += dep;
this->AddCMakeDependFile(f);
}
}
@@ -3708,8 +4003,17 @@ void cmMakefile::RaiseScope(const std::string& var, const char* varDef)
if (!this->StateSnapshot.RaiseScope(var, varDef)) {
std::ostringstream m;
m << "Cannot set \"" << var << "\": current scope has no parent.";
- this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, m.str());
+ return;
}
+
+#ifdef CMAKE_BUILD_WITH_CMAKE
+ cmVariableWatch* vv = this->GetVariableWatch();
+ if (vv) {
+ vv->VariableAccessed(var, cmVariableWatch::VARIABLE_MODIFIED_ACCESS,
+ varDef, this);
+ }
+#endif
}
cmTarget* cmMakefile::AddImportedTarget(const std::string& name,
@@ -3717,9 +4021,10 @@ cmTarget* cmMakefile::AddImportedTarget(const std::string& name,
bool global)
{
// Create the target.
- CM_AUTO_PTR<cmTarget> target(
- new cmTarget(name, type, global ? cmTarget::VisibilityImportedGlobally
- : cmTarget::VisibilityImported,
+ std::unique_ptr<cmTarget> target(
+ new cmTarget(name, type,
+ global ? cmTarget::VisibilityImportedGlobally
+ : cmTarget::VisibilityImported,
this));
// Add to the set of available imported targets.
@@ -3783,7 +4088,7 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
// target names must be globally unique
switch (this->GetPolicyStatus(cmPolicies::CMP0002)) {
case cmPolicies::WARN:
- this->IssueMessage(cmake::AUTHOR_WARNING,
+ this->IssueMessage(MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(cmPolicies::CMP0002));
CM_FALLTHROUGH;
case cmPolicies::OLD:
@@ -3791,7 +4096,7 @@ bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
this->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0002));
return true;
case cmPolicies::NEW:
@@ -3870,7 +4175,7 @@ bool cmMakefile::EnforceUniqueDir(const std::string& srcPath,
<< "to work accidentally and is being allowed for "
<< "compatibility.";
/* clang-format on */
- this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ this->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
CM_FALLTHROUGH;
case cmPolicies::OLD:
// OLD behavior does not warn.
@@ -3889,23 +4194,13 @@ bool cmMakefile::EnforceUniqueDir(const std::string& srcPath,
<< " " << srcPath << "\n"
<< "Specify a unique binary directory name.";
/* clang-format on */
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::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 const 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",
@@ -3960,10 +4255,10 @@ const char* cmMakefile::GetDefineFlagsCMP0059() const
return this->DefineFlagsOrig.c_str();
}
-cmPolicies::PolicyStatus cmMakefile::GetPolicyStatus(
- cmPolicies::PolicyID id) const
+cmPolicies::PolicyStatus cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id,
+ bool parent_scope) const
{
- return this->StateSnapshot.GetPolicy(id);
+ return this->StateSnapshot.GetPolicy(id, parent_scope);
}
bool cmMakefile::PolicyOptionalWarningEnabled(std::string const& var)
@@ -3984,7 +4279,7 @@ bool cmMakefile::SetPolicy(const char* id, cmPolicies::PolicyStatus status)
if (!cmPolicies::GetPolicyID(id, /* out */ pid)) {
std::ostringstream e;
e << "Policy \"" << id << "\" is not known to this version of CMake.";
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
return this->SetPolicy(pid, status);
@@ -3997,14 +4292,18 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
if (status != cmPolicies::NEW &&
cmPolicies::GetPolicyStatus(id) == cmPolicies::REQUIRED_ALWAYS) {
std::string msg = cmPolicies::GetRequiredAlwaysPolicyError(id);
- this->IssueMessage(cmake::FATAL_ERROR, msg);
+ this->IssueMessage(MessageType::FATAL_ERROR, msg);
return false;
}
// Deprecate old policies, especially those that require a lot
// of code to maintain the old behavior.
- if (status == cmPolicies::OLD && id <= cmPolicies::CMP0036) {
- this->IssueMessage(cmake::DEPRECATION_WARNING,
+ if (status == cmPolicies::OLD && id <= cmPolicies::CMP0066 &&
+ !(this->GetCMakeInstance()->GetIsInTryCompile() &&
+ (
+ // Policies set by cmCoreTryCompile::TryCompileCode.
+ id == cmPolicies::CMP0065))) {
+ this->IssueMessage(MessageType::DEPRECATION_WARNING,
cmPolicies::GetPolicyDeprecatedWarning(id));
}
@@ -4031,7 +4330,7 @@ void cmMakefile::PushPolicy(bool weak, cmPolicies::PolicyMap const& pm)
void cmMakefile::PopPolicy()
{
if (!this->StateSnapshot.PopPolicy()) {
- this->IssueMessage(cmake::FATAL_ERROR,
+ this->IssueMessage(MessageType::FATAL_ERROR,
"cmake_policy POP without matching PUSH");
}
}
@@ -4043,7 +4342,7 @@ void cmMakefile::PopSnapshot(bool reportError)
// reject any still-open nested policy scopes with an error.
while (!this->StateSnapshot.CanPopPolicyScope()) {
if (reportError) {
- this->IssueMessage(cmake::FATAL_ERROR,
+ this->IssueMessage(MessageType::FATAL_ERROR,
"cmake_policy PUSH without matching POP");
reportError = false;
}
@@ -4054,9 +4353,10 @@ void cmMakefile::PopSnapshot(bool reportError)
assert(this->StateSnapshot.IsValid());
}
-bool cmMakefile::SetPolicyVersion(const char* version)
+bool cmMakefile::SetPolicyVersion(std::string const& version_min,
+ std::string const& version_max)
{
- return cmPolicies::ApplyPolicyVersion(this, version);
+ return cmPolicies::ApplyPolicyVersion(this, version_min, version_max);
}
bool cmMakefile::HasCMP0054AlreadyBeenReported(
@@ -4093,15 +4393,15 @@ bool cmMakefile::IgnoreErrorsCMP0061() const
}
#define FEATURE_STRING(F) , #F
-static const char* const C_FEATURES[] = { CM_NULLPTR FOR_EACH_C_FEATURE(
+static const char* const C_FEATURES[] = { nullptr FOR_EACH_C_FEATURE(
FEATURE_STRING) };
-static const char* const CXX_FEATURES[] = { CM_NULLPTR FOR_EACH_CXX_FEATURE(
+static const char* const CXX_FEATURES[] = { nullptr 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", "17" };
+static const char* const CXX_STANDARDS[] = { "98", "11", "14", "17", "20" };
bool cmMakefile::AddRequiredTargetFeature(cmTarget* target,
const std::string& feature,
@@ -4135,7 +4435,7 @@ bool cmMakefile::AddRequiredTargetFeature(cmTarget* target,
if (error) {
*error = e.str();
} else {
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(),
this->Backtrace);
}
return false;
@@ -4156,15 +4456,15 @@ bool cmMakefile::CompileFeatureKnown(cmTarget const* target,
assert(cmGeneratorExpression::Find(feature) == std::string::npos);
bool isCFeature =
- std::find_if(cmArrayBegin(C_FEATURES) + 1, cmArrayEnd(C_FEATURES),
- cmStrCmp(feature)) != cmArrayEnd(C_FEATURES);
+ std::find_if(cm::cbegin(C_FEATURES) + 1, cm::cend(C_FEATURES),
+ cmStrCmp(feature)) != cm::cend(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);
+ std::find_if(cm::cbegin(CXX_FEATURES) + 1, cm::cend(CXX_FEATURES),
+ cmStrCmp(feature)) != cm::cend(CXX_FEATURES);
if (isCxxFeature) {
lang = "CXX";
return true;
@@ -4175,13 +4475,14 @@ bool cmMakefile::CompileFeatureKnown(cmTarget const* target,
} else {
e << "Specified";
}
- e << " unknown feature \"" << feature << "\" for "
- "target \""
+ e << " unknown feature \"" << feature
+ << "\" for "
+ "target \""
<< target->GetName() << "\".";
if (error) {
*error = e.str();
} else {
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(),
this->Backtrace);
}
return false;
@@ -4201,10 +4502,10 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang,
if (error) {
*error = e.str();
} else {
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(),
this->Backtrace);
}
- return CM_NULLPTR;
+ return nullptr;
}
const char* featuresKnown =
@@ -4224,10 +4525,10 @@ const char* cmMakefile::CompileFeaturesAvailable(const std::string& lang,
if (error) {
*error = e.str();
} else {
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(),
this->Backtrace);
}
- return CM_NULLPTR;
+ return nullptr;
}
return featuresKnown;
}
@@ -4249,17 +4550,17 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target,
std::ostringstream e;
e << "CMAKE_C_STANDARD_DEFAULT is not set. COMPILE_FEATURES support "
"not fully configured for this compiler.";
- this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
+ this->IssueMessage(MessageType::INTERNAL_ERROR, e.str());
// Return true so the caller does not try to lookup the default standard.
return true;
}
- if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
- cmStrCmp(defaultCStandard)) == cmArrayEnd(C_STANDARDS)) {
+ if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS),
+ cmStrCmp(defaultCStandard)) == cm::cend(C_STANDARDS)) {
std::ostringstream e;
e << "The CMAKE_C_STANDARD_DEFAULT variable contains an "
"invalid value: \""
<< defaultCStandard << "\".";
- this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
+ this->IssueMessage(MessageType::INTERNAL_ERROR, e.str());
return false;
}
@@ -4274,33 +4575,33 @@ bool cmMakefile::HaveCStandardAvailable(cmTarget const* target,
existingCStandard = defaultCStandard;
}
- if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
- cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS)) {
+ if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS),
+ cmStrCmp(existingCStandard)) == cm::cend(C_STANDARDS)) {
std::ostringstream e;
e << "The C_STANDARD property on target \"" << target->GetName()
<< "\" contained an invalid value: \"" << existingCStandard << "\".";
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
const char* const* existingCIt = existingCStandard
- ? std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
+ ? std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS),
cmStrCmp(existingCStandard))
- : cmArrayEnd(C_STANDARDS);
+ : cm::cend(C_STANDARDS);
if (needC11 && existingCStandard &&
- existingCIt < std::find_if(cmArrayBegin(C_STANDARDS),
- cmArrayEnd(C_STANDARDS), cmStrCmp("11"))) {
+ existingCIt < std::find_if(cm::cbegin(C_STANDARDS),
+ cm::cend(C_STANDARDS), cmStrCmp("11"))) {
return false;
}
if (needC99 && existingCStandard &&
- existingCIt < std::find_if(cmArrayBegin(C_STANDARDS),
- cmArrayEnd(C_STANDARDS), cmStrCmp("99"))) {
+ existingCIt < std::find_if(cm::cbegin(C_STANDARDS),
+ cm::cend(C_STANDARDS), cmStrCmp("99"))) {
return false;
}
if (needC90 && existingCStandard &&
- existingCIt < std::find_if(cmArrayBegin(C_STANDARDS),
- cmArrayEnd(C_STANDARDS), cmStrCmp("90"))) {
+ existingCIt < std::find_if(cm::cbegin(C_STANDARDS),
+ cm::cend(C_STANDARDS), cmStrCmp("90"))) {
return false;
}
return true;
@@ -4312,16 +4613,16 @@ bool cmMakefile::IsLaterStandard(std::string const& lang,
{
if (lang == "C") {
const char* const* rhsIt = std::find_if(
- cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS), cmStrCmp(rhs));
+ cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS), cmStrCmp(rhs));
- return std::find_if(rhsIt, cmArrayEnd(C_STANDARDS), cmStrCmp(lhs)) !=
- cmArrayEnd(C_STANDARDS);
+ return std::find_if(rhsIt, cm::cend(C_STANDARDS), cmStrCmp(lhs)) !=
+ cm::cend(C_STANDARDS);
}
const char* const* rhsIt = std::find_if(
- cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS), cmStrCmp(rhs));
+ cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS), cmStrCmp(rhs));
- return std::find_if(rhsIt, cmArrayEnd(CXX_STANDARDS), cmStrCmp(lhs)) !=
- cmArrayEnd(CXX_STANDARDS);
+ return std::find_if(rhsIt, cm::cend(CXX_STANDARDS), cmStrCmp(lhs)) !=
+ cm::cend(CXX_STANDARDS);
}
bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target,
@@ -4333,18 +4634,17 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target,
std::ostringstream e;
e << "CMAKE_CXX_STANDARD_DEFAULT is not set. COMPILE_FEATURES support "
"not fully configured for this compiler.";
- this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
+ this->IssueMessage(MessageType::INTERNAL_ERROR, e.str());
// Return true so the caller does not try to lookup the default standard.
return true;
}
- if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
- cmStrCmp(defaultCxxStandard)) ==
- cmArrayEnd(CXX_STANDARDS)) {
+ if (std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS),
+ cmStrCmp(defaultCxxStandard)) == cm::cend(CXX_STANDARDS)) {
std::ostringstream e;
e << "The CMAKE_CXX_STANDARD_DEFAULT variable contains an "
"invalid value: \""
<< defaultCxxStandard << "\".";
- this->IssueMessage(cmake::INTERNAL_ERROR, e.str());
+ this->IssueMessage(MessageType::INTERNAL_ERROR, e.str());
return false;
}
@@ -4352,47 +4652,43 @@ bool cmMakefile::HaveCxxStandardAvailable(cmTarget const* target,
bool needCxx11 = false;
bool needCxx14 = false;
bool needCxx17 = false;
+ bool needCxx20 = false;
this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14,
- needCxx17);
+ needCxx17, needCxx20);
const char* existingCxxStandard = target->GetProperty("CXX_STANDARD");
if (!existingCxxStandard) {
existingCxxStandard = defaultCxxStandard;
}
- if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
- cmStrCmp(existingCxxStandard)) ==
- cmArrayEnd(CXX_STANDARDS)) {
+ const char* const* existingCxxLevel =
+ std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard));
+ if (existingCxxLevel == cm::cend(CXX_STANDARDS)) {
std::ostringstream e;
e << "The CXX_STANDARD property on target \"" << target->GetName()
<< "\" contained an invalid value: \"" << existingCxxStandard << "\".";
- this->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->IssueMessage(MessageType::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);
+ /* clang-format off */
+ const char* const* needCxxLevel =
+ needCxx20 ? &CXX_STANDARDS[4]
+ : needCxx17 ? &CXX_STANDARDS[3]
+ : needCxx14 ? &CXX_STANDARDS[2]
+ : needCxx11 ? &CXX_STANDARDS[1]
+ : needCxx98 ? &CXX_STANDARDS[0]
+ : nullptr;
+ /* clang-format on */
- if (needCxx11 &&
- existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS),
- cmArrayEnd(CXX_STANDARDS),
- cmStrCmp("11"))) {
- return false;
- }
- if (needCxx98 &&
- existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS),
- cmArrayEnd(CXX_STANDARDS),
- cmStrCmp("98"))) {
- return false;
- }
- return true;
+ return !needCxxLevel || needCxxLevel <= existingCxxLevel;
}
void cmMakefile::CheckNeededCxxLanguage(const std::string& feature,
bool& needCxx98, bool& needCxx11,
- bool& needCxx14, bool& needCxx17) const
+ bool& needCxx14, bool& needCxx17,
+ bool& needCxx20) const
{
if (const char* propCxx98 =
this->GetDefinition("CMAKE_CXX98_COMPILE_FEATURES")) {
@@ -4418,6 +4714,12 @@ void cmMakefile::CheckNeededCxxLanguage(const std::string& feature,
cmSystemTools::ExpandListArgument(propCxx17, props);
needCxx17 = std::find(props.begin(), props.end(), feature) != props.end();
}
+ if (const char* propCxx20 =
+ this->GetDefinition("CMAKE_CXX20_COMPILE_FEATURES")) {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(propCxx20, props);
+ needCxx20 = std::find(props.begin(), props.end(), feature) != props.end();
+ }
}
bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target,
@@ -4428,72 +4730,83 @@ bool cmMakefile::AddRequiredTargetCxxFeature(cmTarget* target,
bool needCxx11 = false;
bool needCxx14 = false;
bool needCxx17 = false;
+ bool needCxx20 = false;
this->CheckNeededCxxLanguage(feature, needCxx98, needCxx11, needCxx14,
- needCxx17);
+ needCxx17, needCxx20);
const char* existingCxxStandard = target->GetProperty("CXX_STANDARD");
+ if (existingCxxStandard == nullptr) {
+ const char* defaultCxxStandard =
+ this->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT");
+ if (defaultCxxStandard && *defaultCxxStandard) {
+ existingCxxStandard = defaultCxxStandard;
+ }
+ }
+ const char* const* existingCxxLevel = nullptr;
if (existingCxxStandard) {
- if (std::find_if(cmArrayBegin(CXX_STANDARDS), cmArrayEnd(CXX_STANDARDS),
- cmStrCmp(existingCxxStandard)) ==
- cmArrayEnd(CXX_STANDARDS)) {
+ existingCxxLevel =
+ std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS),
+ cmStrCmp(existingCxxStandard));
+ if (existingCxxLevel == cm::cend(CXX_STANDARDS)) {
std::ostringstream e;
e << "The CXX_STANDARD property on target \"" << target->GetName()
<< "\" contained an invalid value: \"" << existingCxxStandard << "\".";
if (error) {
*error = e.str();
} else {
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
- this->Backtrace);
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str(), this->Backtrace);
+ }
+ return false;
+ }
+ }
+
+ const char* existingCudaStandard = target->GetProperty("CUDA_STANDARD");
+ const char* const* existingCudaLevel = nullptr;
+ if (existingCudaStandard) {
+ existingCudaLevel =
+ std::find_if(cm::cbegin(CXX_STANDARDS), cm::cend(CXX_STANDARDS),
+ cmStrCmp(existingCudaStandard));
+ if (existingCudaLevel == cm::cend(CXX_STANDARDS)) {
+ std::ostringstream e;
+ e << "The CUDA_STANDARD property on target \"" << target->GetName()
+ << "\" contained an invalid value: \"" << existingCudaStandard
+ << "\".";
+ if (error) {
+ *error = e.str();
+ } else {
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str(), this->Backtrace);
}
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;
- bool setCxx17 = needCxx17 && !existingCxxStandard;
-
- if (needCxx17 && existingCxxStandard &&
- existingCxxIt < std::find_if(cmArrayBegin(CXX_STANDARDS),
- cmArrayEnd(CXX_STANDARDS),
- cmStrCmp("17"))) {
- setCxx17 = true;
- } else 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 (setCxx17) {
- target->SetProperty("CXX_STANDARD", "17");
- target->SetProperty("CUDA_STANDARD", "17");
- } else if (setCxx14) {
- target->SetProperty("CXX_STANDARD", "14");
- target->SetProperty("CUDA_STANDARD", "14");
- } else if (setCxx11) {
- target->SetProperty("CXX_STANDARD", "11");
- target->SetProperty("CUDA_STANDARD", "11");
- } else if (setCxx98) {
- target->SetProperty("CXX_STANDARD", "98");
- target->SetProperty("CUDA_STANDARD", "98");
+
+ /* clang-format off */
+ const char* const* needCxxLevel =
+ needCxx20 ? &CXX_STANDARDS[4]
+ : needCxx17 ? &CXX_STANDARDS[3]
+ : needCxx14 ? &CXX_STANDARDS[2]
+ : needCxx11 ? &CXX_STANDARDS[1]
+ : needCxx98 ? &CXX_STANDARDS[0]
+ : nullptr;
+ /* clang-format on */
+
+ if (needCxxLevel) {
+ // Ensure the C++ language level is high enough to support
+ // the needed C++ features.
+ if (!existingCxxLevel || existingCxxLevel < needCxxLevel) {
+ target->SetProperty("CXX_STANDARD", *needCxxLevel);
+ }
+
+ // Ensure the CUDA language level is high enough to support
+ // the needed C++ features.
+ if (!existingCudaLevel || existingCudaLevel < needCxxLevel) {
+ target->SetProperty("CUDA_STANDARD", *needCxxLevel);
+ }
}
+
return true;
}
@@ -4532,42 +4845,49 @@ bool cmMakefile::AddRequiredTargetCFeature(cmTarget* target,
this->CheckNeededCLanguage(feature, needC90, needC99, needC11);
const char* existingCStandard = target->GetProperty("C_STANDARD");
+ if (existingCStandard == nullptr) {
+ const char* defaultCStandard =
+ this->GetDefinition("CMAKE_C_STANDARD_DEFAULT");
+ if (defaultCStandard && *defaultCStandard) {
+ existingCStandard = defaultCStandard;
+ }
+ }
if (existingCStandard) {
- if (std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
- cmStrCmp(existingCStandard)) == cmArrayEnd(C_STANDARDS)) {
+ if (std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS),
+ cmStrCmp(existingCStandard)) == cm::cend(C_STANDARDS)) {
std::ostringstream e;
e << "The C_STANDARD property on target \"" << target->GetName()
<< "\" contained an invalid value: \"" << existingCStandard << "\".";
if (error) {
*error = e.str();
} else {
- this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
- this->Backtrace);
+ this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
+ e.str(), this->Backtrace);
}
return false;
}
}
const char* const* existingCIt = existingCStandard
- ? std::find_if(cmArrayBegin(C_STANDARDS), cmArrayEnd(C_STANDARDS),
+ ? std::find_if(cm::cbegin(C_STANDARDS), cm::cend(C_STANDARDS),
cmStrCmp(existingCStandard))
- : cmArrayEnd(C_STANDARDS);
+ : cm::cend(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"))) {
+ existingCIt < std::find_if(cm::cbegin(C_STANDARDS),
+ cm::cend(C_STANDARDS), cmStrCmp("11"))) {
setC11 = true;
} else if (needC99 && existingCStandard &&
- existingCIt < std::find_if(cmArrayBegin(C_STANDARDS),
- cmArrayEnd(C_STANDARDS),
+ existingCIt < std::find_if(cm::cbegin(C_STANDARDS),
+ cm::cend(C_STANDARDS),
cmStrCmp("99"))) {
setC99 = true;
} else if (needC90 && existingCStandard &&
- existingCIt < std::find_if(cmArrayBegin(C_STANDARDS),
- cmArrayEnd(C_STANDARDS),
+ existingCIt < std::find_if(cm::cbegin(C_STANDARDS),
+ cm::cend(C_STANDARDS),
cmStrCmp("90"))) {
setC90 = true;
}
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index e65ba468f..d22334751 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -3,30 +3,31 @@
#ifndef cmMakefile_h
#define cmMakefile_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmsys/RegularExpression.hxx"
#include <deque>
#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <stack>
#include <stddef.h>
#include <string>
+#include <unordered_map>
#include <vector>
#include "cmAlgorithms.h"
#include "cmListFileCache.h"
+#include "cmMessageType.h"
#include "cmNewLineStyle.h"
#include "cmPolicies.h"
+#include "cmSourceFileLocationKind.h"
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmTarget.h"
-#include "cm_auto_ptr.hxx"
-#include "cm_unordered_map.hxx"
-#include "cmake.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmSourceGroup.h"
+# include "cmSourceGroup.h"
#endif
class cmCommand;
@@ -45,6 +46,15 @@ class cmState;
class cmTest;
class cmTestGenerator;
class cmVariableWatch;
+class cmake;
+
+/** A type-safe wrapper for a string representing a directory id. */
+class cmDirectoryId
+{
+public:
+ cmDirectoryId(std::string s);
+ std::string String;
+};
/** \class cmMakefile
* \brief Process the input CMakeLists.txt file.
@@ -55,8 +65,6 @@ class cmVariableWatch;
*/
class cmMakefile
{
- CM_DISABLE_COPY(cmMakefile)
-
public:
/* Mark a variable as used */
void MarkVariableAsUsed(const std::string& var);
@@ -74,11 +82,15 @@ public:
*/
~cmMakefile();
- bool ReadListFile(const char* filename);
+ cmMakefile(cmMakefile const&) = delete;
+ cmMakefile& operator=(cmMakefile const&) = delete;
+
+ cmDirectoryId GetDirectoryId() const;
- bool ReadDependentFile(const char* filename, bool noPolicyScope = true);
+ bool ReadListFile(const std::string& filename);
- bool ProcessBuildsystemFile(const char* filename);
+ bool ReadDependentFile(const std::string& filename,
+ bool noPolicyScope = true);
/**
* Add a function blocker to this makefile
@@ -92,7 +104,7 @@ public:
* Remove the function blocker whose scope ends with the given command.
* This returns ownership of the function blocker object.
*/
- CM_AUTO_PTR<cmFunctionBlocker> RemoveFunctionBlocker(
+ std::unique_ptr<cmFunctionBlocker> RemoveFunctionBlocker(
cmFunctionBlocker* fb, const cmListFileFunction& lff);
/**
@@ -101,7 +113,8 @@ public:
*/
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,
+ bool fast, int jobs,
+ const std::vector<std::string>* cmakeArgs,
std::string& output);
bool GetIsSourceFileTryCompile() const;
@@ -137,7 +150,7 @@ public:
const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type,
const char* comment, const char* workingDir, bool escapeOldStyle = true,
bool uses_terminal = false, const std::string& depfile = "",
- bool command_expand_lists = false,
+ const std::string& job_pool = "", bool command_expand_lists = false,
ObjectLibraryCommands objLibraryCommands = RejectObjectLibraryCommands);
cmSourceFile* AddCustomCommandToOutput(
const std::vector<std::string>& outputs,
@@ -147,14 +160,14 @@ public:
const cmCustomCommandLines& commandLines, const char* comment,
const char* workingDir, bool replace = false, bool escapeOldStyle = true,
bool uses_terminal = false, bool command_expand_lists = false,
- const std::string& depfile = "");
+ const std::string& depfile = "", const std::string& job_pool = "");
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,
bool uses_terminal = false, bool command_expand_lists = false,
- const std::string& depfile = "");
+ const std::string& depfile = "", const std::string& job_pool = "");
void AddCustomCommandOldStyle(const std::string& target,
const std::vector<std::string>& outputs,
const std::vector<std::string>& depends,
@@ -165,9 +178,12 @@ public:
/**
* Add a define flag to the build.
*/
- void AddDefineFlag(const char* definition);
- void RemoveDefineFlag(const char* definition);
- void AddCompileOption(const char* option);
+ void AddDefineFlag(std::string const& definition);
+ void RemoveDefineFlag(std::string const& definition);
+ void AddCompileDefinition(std::string const& definition);
+ void AddCompileOption(std::string const& option);
+ void AddLinkOption(std::string const& option);
+ void AddLinkDirectory(std::string const& directory, bool before = false);
/** Create a new imported target with the name and type given. */
cmTarget* AddImportedTarget(const std::string& name,
@@ -179,33 +195,42 @@ public:
/**
* Add an executable to the build.
*/
- cmTarget* AddExecutable(const char* exename,
+ cmTarget* AddExecutable(const std::string& exename,
const std::vector<std::string>& srcs,
bool excludeFromAll = false);
+ /** Where the target originated from. */
+ enum class TargetOrigin
+ {
+ Project,
+ Generator
+ };
+
/**
- * Add a utility to the build. A utiltity target is a command that
+ * Add a utility to the build. A utility target is a command that
* is run every time the target is built.
*/
+ cmTarget* AddUtilityCommand(const std::string& utilityName,
+ TargetOrigin origin, bool excludeFromAll,
+ const std::vector<std::string>& depends,
+ const char* workingDirectory,
+ const char* command, const char* arg1 = nullptr,
+ const char* arg2 = nullptr,
+ const char* arg3 = nullptr,
+ const char* arg4 = nullptr);
cmTarget* AddUtilityCommand(
- const std::string& utilityName, bool excludeFromAll,
- const std::vector<std::string>& depends, const char* workingDirectory,
- const char* command, const char* arg1 = CM_NULLPTR,
- const char* arg2 = CM_NULLPTR, const char* arg3 = CM_NULLPTR,
- const char* arg4 = CM_NULLPTR);
- cmTarget* AddUtilityCommand(
- const std::string& utilityName, bool excludeFromAll,
+ const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
- const char* comment = CM_NULLPTR, bool uses_terminal = false,
- bool command_expand_lists = false);
+ const char* comment = nullptr, bool uses_terminal = false,
+ bool command_expand_lists = false, const std::string& job_pool = "");
cmTarget* AddUtilityCommand(
- const std::string& utilityName, bool excludeFromAll,
+ const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& byproducts,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
- const char* comment = CM_NULLPTR, bool uses_terminal = false,
- bool command_expand_lists = false);
+ const char* comment = nullptr, bool uses_terminal = false,
+ bool command_expand_lists = false, const std::string& job_pool = "");
/**
* Add a subdirectory to the build.
@@ -232,7 +257,7 @@ public:
* 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.
+ //! Add a definition to this makefile and the global cmake cache.
void AddCacheDefinition(const std::string& name, const char* value,
const char* doc, cmStateEnums::CacheEntryType type,
bool force = false);
@@ -247,7 +272,7 @@ public:
* for cache entries, and will only affect the current makefile.
*/
void RemoveDefinition(const std::string& name);
- ///! Remove a definition from the cache.
+ //! Remove a definition from the cache.
void RemoveCacheDefinition(const std::string& name);
/**
@@ -268,29 +293,16 @@ public:
bool excludeFromAll = false);
void AddAlias(const std::string& libname, const std::string& 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 = CM_NULLPTR);
-
- /**
- * 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 = CM_NULLPTR);
-
-#endif
-
//@{
/**
- * Set, Push, Pop policy values for CMake.
- */
+ * 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);
+ cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id,
+ bool parent_scope = false) const;
+ bool SetPolicyVersion(std::string const& version_min,
+ std::string const& version_max);
void RecordPolicies(cmPolicies::PolicyMap& pm);
//@}
@@ -301,6 +313,9 @@ public:
PolicyPushPop(cmMakefile* m);
~PolicyPushPop();
+ PolicyPushPop(const PolicyPushPop&) = delete;
+ PolicyPushPop& operator=(const PolicyPushPop&) = delete;
+
private:
cmMakefile* Makefile;
};
@@ -314,21 +329,21 @@ public:
bool IgnoreErrorsCMP0061() const;
- const char* GetHomeDirectory() const;
- const char* GetHomeOutputDirectory() const;
+ std::string const& GetHomeDirectory() const;
+ std::string const& GetHomeOutputDirectory() const;
/**
* Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
*/
- void SetScriptModeFile(const char* scriptfile);
+ void SetScriptModeFile(std::string const& scriptfile);
/**
* Set CMAKE_ARGC, CMAKE_ARGV0 ... variables.
*/
void SetArgcArgv(const std::vector<std::string>& args);
- const char* GetCurrentSourceDirectory() const;
- const char* GetCurrentBinaryDirectory() const;
+ std::string const& GetCurrentSourceDirectory() const;
+ std::string const& GetCurrentBinaryDirectory() const;
//@}
@@ -358,14 +373,13 @@ public:
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; }
+ // -- List of targets
+ typedef std::unordered_map<std::string, cmTarget> cmTargetMap;
+ /** Get the target map */
+ cmTargetMap& GetTargets() { return this->Targets; }
+ /** Get the target map - const version */
+ cmTargetMap const& GetTargets() const { return this->Targets; }
+
const std::vector<cmTarget*>& GetOwnedImportedTargets() const
{
return this->ImportedTargetsOwned;
@@ -393,22 +407,26 @@ public:
/** 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;
+ cmSourceFile* GetSource(
+ const std::string& sourceName,
+ cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous) 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);
+ cmSourceFile* CreateSource(
+ const std::string& sourceName, bool generated = false,
+ cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
/** 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);
+ cmSourceFile* GetOrCreateSource(
+ const std::string& sourceName, bool generated = false,
+ cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
void AddTargetObject(std::string const& tgtName, std::string const& objFile);
@@ -418,8 +436,9 @@ public:
* 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;
+ const std::string* GetDef(const std::string&) const;
+ const std::string& GetSafeDefinition(const std::string&) const;
+ const std::string& GetRequiredDefinition(const std::string& name) const;
bool IsDefinitionSet(const std::string&) const;
/**
* Get the list of all variables in the current space. If argument
@@ -445,8 +464,23 @@ public:
/** Return whether the target platform is x32. */
bool PlatformIsx32() const;
+ /** Apple SDK Type */
+ enum class AppleSDK
+ {
+ MacOS,
+ IPhoneOS,
+ IPhoneSimulator,
+ AppleTVOS,
+ AppleTVSimulator,
+ WatchOS,
+ WatchSimulator,
+ };
+
+ /** What SDK type points CMAKE_OSX_SYSROOT to? */
+ AppleSDK GetAppleSDKType() const;
+
/** Return whether the target platform is Apple iOS. */
- bool PlatformIsAppleIos() const;
+ bool PlatformIsAppleEmbedded() const;
/** Retrieve soname flag for the specified language if supported */
const char* GetSONameFlag(const std::string& language) const;
@@ -459,7 +493,7 @@ public:
/**
* Make sure CMake can write this file
*/
- bool CanIWriteThisFile(const char* fileName) const;
+ bool CanIWriteThisFile(std::string const& fileName) const;
#if defined(CMAKE_BUILD_WITH_CMAKE)
/**
@@ -474,6 +508,36 @@ public:
* Get the source group
*/
cmSourceGroup* GetSourceGroup(const std::vector<std::string>& name) const;
+
+ /**
+ * Add a root source group for consideration when adding a new source.
+ */
+ void AddSourceGroup(const std::string& name, const char* regex = nullptr);
+
+ /**
+ * 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 = nullptr);
+
+ /**
+ * Get and existing or create a new source group.
+ */
+ cmSourceGroup* GetOrCreateSourceGroup(
+ const std::vector<std::string>& folders);
+
+ /**
+ * Get and existing or create a new source group.
+ * The name will be tokenized.
+ */
+ cmSourceGroup* GetOrCreateSourceGroup(const std::string& name);
+
+ /**
+ * find what source group this source is in
+ */
+ cmSourceGroup* FindSourceGroup(const std::string& source,
+ std::vector<cmSourceGroup>& groups) const;
#endif
/**
@@ -483,7 +547,7 @@ public:
{
return this->ListFiles;
}
- ///! When the file changes cmake will be re-run from the build system.
+ //! When the file changes cmake will be re-run from the build system.
void AddCMakeDependFile(const std::string& file)
{
this->ListFiles.push_back(file);
@@ -518,12 +582,11 @@ public:
* 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 = CM_NULLPTR,
- long line = -1, bool removeEmpty = false,
- bool replaceAt = false) const;
+ const std::string& ExpandVariablesInString(std::string& source) const;
+ const std::string& ExpandVariablesInString(
+ std::string& source, bool escapeQuotes, bool noEscapes,
+ bool atOnly = false, const char* filename = nullptr, long line = -1,
+ bool removeEmpty = false, bool replaceAt = false) const;
/**
* Remove any remaining variables in the string. Anything with ${var} or
@@ -544,20 +607,12 @@ public:
bool atOnly, bool escapeQuotes) const;
/**
- * Copy file but change lines acording to ConfigureString
+ * Copy file but change lines according to ConfigureString
*/
- int ConfigureFile(const char* infile, const char* outfile, bool copyonly,
- bool atOnly, bool escapeQuotes,
+ int ConfigureFile(const std::string& infile, const std::string& outfile,
+ bool copyonly, bool atOnly, bool escapeQuotes,
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
*/
@@ -570,7 +625,7 @@ public:
bool ExecuteCommand(const cmListFileFunction& lff,
cmExecutionStatus& status);
- ///! Enable support for named language, if nil then all languages are
+ //! Enable support for named language, if nil then all languages are
/// enabled.
void EnableLanguage(std::vector<std::string> const& languages,
bool optional);
@@ -585,8 +640,8 @@ public:
cmVariableWatch* GetVariableWatch() const;
#endif
- ///! Display progress or status message.
- void DisplayStatus(const char*, float) const;
+ //! Display progress or status message.
+ void DisplayStatus(const std::string&, float) const;
/**
* Expand the given list file arguments into the full set after
@@ -594,11 +649,11 @@ public:
*/
bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
std::vector<std::string>& outArgs,
- const char* filename = CM_NULLPTR) const;
+ const char* filename = nullptr) const;
bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
std::vector<cmExpandedCommandArgument>& outArgs,
- const char* filename = CM_NULLPTR) const;
+ const char* filename = nullptr) const;
/**
* Get the instance
@@ -614,7 +669,6 @@ public:
{
return this->SourceFiles;
}
- std::vector<cmSourceFile*>& GetSourceFiles() { return this->SourceFiles; }
/**
* Is there a source file that has the provided source file as an output?
@@ -622,7 +676,7 @@ public:
*/
cmSourceFile* GetSourceFileWithOutput(const std::string& outName) const;
- ///! Add a new cmTest to the list of tests for this makefile.
+ //! 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
@@ -631,11 +685,22 @@ public:
cmTest* GetTest(const std::string& testName) const;
/**
+ * Get all tests that run under the given configuration.
+ */
+ void GetTests(const std::string& config, std::vector<cmTest*>& tests);
+
+ /**
* Return a location of a file in cmake or custom modules directory
*/
- std::string GetModulesFile(const char* name) const;
+ std::string GetModulesFile(const std::string& name) const
+ {
+ bool system;
+ return this->GetModulesFile(name, system);
+ }
+
+ std::string GetModulesFile(const std::string& name, bool& system) const;
- ///! Set/Get a property of this directory
+ //! 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);
@@ -644,7 +709,7 @@ public:
bool GetPropertyAsBool(const std::string& prop) const;
std::vector<std::string> GetPropertyKeys() const;
- ///! Initialize a makefile from its parent
+ //! Initialize a makefile from its parent
void InitializeFromParent(cmMakefile* parent);
void AddInstallGenerator(cmInstallGenerator* g)
@@ -657,6 +722,10 @@ public:
{
return this->InstallGenerators;
}
+ const std::vector<cmInstallGenerator*>& GetInstallGenerators() const
+ {
+ return this->InstallGenerators;
+ }
void AddTestGenerator(cmTestGenerator* g)
{
@@ -676,7 +745,11 @@ public:
cmPolicies::PolicyMap const& pm);
~FunctionPushPop();
+ FunctionPushPop(const FunctionPushPop&) = delete;
+ FunctionPushPop& operator=(const FunctionPushPop&) = delete;
+
void Quiet() { this->ReportError = false; }
+
private:
cmMakefile* Makefile;
bool ReportError;
@@ -689,7 +762,11 @@ public:
cmPolicies::PolicyMap const& pm);
~MacroPushPop();
+ MacroPushPop(const MacroPushPop&) = delete;
+ MacroPushPop& operator=(const MacroPushPop&) = delete;
+
void Quiet() { this->ReportError = false; }
+
private:
cmMakefile* Makefile;
bool ReportError;
@@ -712,32 +789,40 @@ public:
/** Helper class to push and pop scopes automatically. */
class ScopePushPop
{
- CM_DISABLE_COPY(ScopePushPop)
public:
ScopePushPop(cmMakefile* m)
: Makefile(m)
{
this->Makefile->PushScope();
}
+
~ScopePushPop() { this->Makefile->PopScope(); }
+
+ ScopePushPop(ScopePushPop const&) = delete;
+ ScopePushPop& operator=(ScopePushPop const&) = delete;
+
private:
cmMakefile* Makefile;
};
- void IssueMessage(cmake::MessageType t, std::string const& text) const;
+ void IssueMessage(MessageType t, std::string const& text) const;
/** Set whether or not to report a CMP0000 violation. */
void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
+ bool CheckCMP0037(std::string const& targetName,
+ cmStateEnums::TargetType targetType) const;
+
cmStringRange GetIncludeDirectoriesEntries() const;
cmBacktraceRange GetIncludeDirectoriesBacktraces() const;
cmStringRange GetCompileOptionsEntries() const;
cmBacktraceRange GetCompileOptionsBacktraces() const;
cmStringRange GetCompileDefinitionsEntries() const;
cmBacktraceRange GetCompileDefinitionsBacktraces() const;
-
- void AddQtUiFileWithOptions(cmSourceFile* sf);
- std::vector<cmSourceFile*> GetQtUiFilesWithOptions() const;
+ cmStringRange GetLinkOptionsEntries() const;
+ cmBacktraceRange GetLinkOptionsBacktraces() const;
+ cmStringRange GetLinkDirectoriesEntries() const;
+ cmBacktraceRange GetLinkDirectoriesBacktraces() const;
std::set<std::string> const& GetSystemIncludeDirectories() const
{
@@ -747,7 +832,7 @@ public:
bool PolicyOptionalWarningEnabled(std::string const& var);
bool AddRequiredTargetFeature(cmTarget* target, const std::string& feature,
- std::string* error = CM_NULLPTR) const;
+ std::string* error = nullptr) const;
bool CompileFeatureKnown(cmTarget const* target, const std::string& feature,
std::string& lang, std::string* error) const;
@@ -776,10 +861,11 @@ public:
void EnforceDirectoryLevelRules() const;
- void AddEvaluationFile(const std::string& inputFile,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> outputName,
- CM_AUTO_PTR<cmCompiledGeneratorExpression> condition,
- bool inputIsContent);
+ void AddEvaluationFile(
+ const std::string& inputFile,
+ std::unique_ptr<cmCompiledGeneratorExpression> outputName,
+ std::unique_ptr<cmCompiledGeneratorExpression> condition,
+ bool inputIsContent);
std::vector<cmGeneratorExpressionEvaluationFile*> GetEvaluationFiles() const;
std::vector<cmExportBuildFileGenerator*> GetExportBuildFileGenerators()
@@ -787,9 +873,17 @@ public:
void RemoveExportBuildFileGeneratorCMP0024(cmExportBuildFileGenerator* gen);
void AddExportBuildFileGenerator(cmExportBuildFileGenerator* gen);
- // Maintain a stack of pacakge names to determine the depth of find modules
- // we are currently being called with
- std::deque<std::string> FindPackageModuleStack;
+ // Maintain a stack of package roots to allow nested PACKAGE_ROOT_PATH
+ // searches
+ std::deque<std::vector<std::string>> FindPackageRootPathStack;
+
+ void MaybeWarnCMP0074(std::string const& pkg);
+ void MaybeWarnUninitialized(std::string const& variable,
+ const char* sourceFilename) const;
+ bool IsProjectFile(const char* filename) const;
+
+ int GetRecursionDepth() const;
+ void SetRecursionDepth(int recursionDepth);
protected:
// add link libraries and directories to the target
@@ -801,9 +895,23 @@ protected:
mutable std::set<cmListFileContext> CMP0054ReportedIds;
// libraries, classes, and executables
- mutable cmTargets Targets;
+ mutable cmTargetMap Targets;
std::map<std::string, std::string> AliasTargets;
- std::vector<cmSourceFile*> SourceFiles;
+
+ typedef std::vector<cmSourceFile*> SourceFileVec;
+ SourceFileVec SourceFiles;
+
+ // Because cmSourceFile names are compared in a fuzzy way (see
+ // cmSourceFileLocation::Match()) we can't have a straight mapping from
+ // filename to cmSourceFile. To make lookups more efficient we store the
+ // Name portion of the cmSourceFileLocation and then compare on the list of
+ // cmSourceFiles that might match that name. Note that on platforms which
+ // have a case-insensitive filesystem we store the key in all lowercase.
+ typedef std::unordered_map<std::string, SourceFileVec> SourceFileMap;
+ SourceFileMap SourceFileSearchIndex;
+
+ // For "Known" paths we can store a direct filename to cmSourceFile map
+ std::unordered_map<std::string, cmSourceFile*> KnownFileSearchIndex;
// Tests
std::map<std::string, cmTest*> Tests;
@@ -822,8 +930,6 @@ protected:
std::string DefineFlags;
// 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)
@@ -839,6 +945,7 @@ protected:
private:
cmStateSnapshot StateSnapshot;
cmListFileBacktrace Backtrace;
+ int RecursionDepth;
void ReadListFile(cmListFile const& listFile,
const std::string& filenametoread);
@@ -871,7 +978,7 @@ private:
friend class cmParseFileScope;
std::vector<cmTarget*> ImportedTargetsOwned;
- typedef CM_UNORDERED_MAP<std::string, cmTarget*> TargetMap;
+ typedef std::unordered_map<std::string, cmTarget*> TargetMap;
TargetMap ImportedTargets;
// Internal policy stack management.
@@ -891,15 +998,18 @@ private:
friend class BuildsystemFileScope;
// 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;
+ 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;
+ MessageType ExpandVariablesInStringNew(std::string& errorstr,
+ std::string& source,
+ bool escapeQuotes, bool noEscapes,
+ bool atOnly, const char* filename,
+ long line, bool replaceAt) const;
/**
* Old version of GetSourceFileWithOutput(const std::string&) kept for
* backward-compatibility. It implements a linear search and support
@@ -909,7 +1019,7 @@ private:
cmSourceFile* LinearGetSourceFileWithOutput(const std::string& cname) const;
// A map for fast output to input look up.
- typedef CM_UNORDERED_MAP<std::string, cmSourceFile*> OutputToSourceMap;
+ typedef std::unordered_map<std::string, cmSourceFile*> OutputToSourceMap;
OutputToSourceMap OutputToSource;
void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
@@ -917,20 +1027,18 @@ private:
void UpdateOutputToSourceMap(std::string const& output,
cmSourceFile* source);
- std::vector<cmSourceFile*> QtUiFilesWithOptions;
-
bool AddRequiredTargetCFeature(cmTarget* target, const std::string& feature,
- std::string* error = CM_NULLPTR) const;
+ std::string* error = nullptr) const;
bool AddRequiredTargetCxxFeature(cmTarget* target,
const std::string& feature,
- std::string* error = CM_NULLPTR) const;
+ std::string* error = nullptr) 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,
- bool& needCxx17) const;
+ bool& needCxx17, bool& needCxx20) const;
bool HaveCStandardAvailable(cmTarget const* target,
const std::string& feature) const;
@@ -943,8 +1051,9 @@ private:
bool WarnUnused;
bool CheckSystemVars;
bool CheckCMP0000;
+ std::set<std::string> WarnedCMP0074;
bool IsSourceFileTryCompile;
- mutable bool SuppressWatches;
+ mutable bool SuppressSideEffects;
};
#endif
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 359b9fdbb..6b9b9c7f1 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -2,11 +2,14 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmMakefileExecutableTargetGenerator.h"
-#include <algorithm>
+#include <memory> // IWYU pragma: keep
+#include <set>
#include <sstream>
#include <string>
+#include <utility>
#include <vector>
+#include "cmAlgorithms.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalUnixMakefileGenerator3.h"
@@ -23,27 +26,22 @@
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
cmMakefileExecutableTargetGenerator::cmMakefileExecutableTargetGenerator(
cmGeneratorTarget* target)
: cmMakefileTargetGenerator(target)
{
this->CustomCommandDriver = OnDepends;
- this->GeneratorTarget->GetExecutableNames(
- this->TargetNameOut, this->TargetNameReal, this->TargetNameImport,
- this->TargetNamePDB, this->ConfigName);
+ this->TargetNames =
+ this->GeneratorTarget->GetExecutableNames(this->ConfigName);
this->OSXBundleGenerator =
- new cmOSXBundleGenerator(target, this->ConfigName);
+ cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
-cmMakefileExecutableTargetGenerator::~cmMakefileExecutableTargetGenerator()
-{
- delete this->OSXBundleGenerator;
-}
+cmMakefileExecutableTargetGenerator::~cmMakefileExecutableTargetGenerator() =
+ default;
void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
{
@@ -69,9 +67,6 @@ void cmMakefileExecutableTargetGenerator::WriteRuleFiles()
this->WriteExecutableRule(true);
}
- // Write the requires target.
- this->WriteTargetRequiresRules();
-
// Write clean target
this->WriteTargetCleanRules();
@@ -87,28 +82,23 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
bool relink)
{
#ifdef CMAKE_BUILD_WITH_CMAKE
- const std::string cuda_lang("CUDA");
- cmGeneratorTarget::LinkClosure const* closure =
- this->GeneratorTarget->GetLinkClosure(this->ConfigName);
-
- const bool hasCUDA =
- (std::find(closure->Languages.begin(), closure->Languages.end(),
- cuda_lang) != closure->Languages.end());
- if (!hasCUDA) {
+ const bool requiresDeviceLinking = requireDeviceLinking(
+ *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ if (!requiresDeviceLinking) {
return;
}
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 = "CUDA";
- std::string const objExt =
+ std::string const& objExt =
this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION");
+ // Build list of dependencies.
+ std::vector<std::string> depends;
+ this->AppendLinkDepends(depends, linkLanguage);
+
// Get the name of the device object to generate.
std::string const targetOutputReal =
this->GeneratorTarget->ObjectDirectory + "cmake_device_link" + objExt;
@@ -157,12 +147,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
linkLanguage, this->ConfigName);
// Add target-specific linker flags.
- this->LocalGenerator->AppendFlags(
- linkFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- std::string linkFlagsConfig = "LINK_FLAGS_";
- linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
- this->LocalGenerator->AppendFlags(
- linkFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
+ this->GetTargetLinkFlags(linkFlags, linkLanguage);
// Construct a list of files associated with this executable that
// may need to be cleaned.
@@ -193,7 +178,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
// Set path conversion for link script shells.
this->LocalGenerator->SetLinkScriptShell(useLinkScript);
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
new cmLinkLineDeviceComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
@@ -251,16 +236,15 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
launcher += " ";
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
// Expand placeholders in the commands.
rulePlaceholderExpander->SetTargetImpLib(targetOutputReal);
- for (std::vector<std::string>::iterator i = real_link_commands.begin();
- i != real_link_commands.end(); ++i) {
- *i = launcher + *i;
- rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, *i,
- vars);
+ for (std::string& real_link_command : real_link_commands) {
+ real_link_command = launcher + real_link_command;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
+ real_link_command, vars);
}
// Restore path conversion to normal shells.
@@ -280,11 +264,11 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
this->LocalGenerator->CreateCDCommand(
commands1, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
commands1.clear();
// Write the build rule.
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
targetOutputReal, depends, commands,
false);
@@ -292,8 +276,7 @@ void cmMakefileExecutableTargetGenerator::WriteDeviceExecutableRule(
this->WriteTargetDriverRule(targetOutputReal, relink);
// Clean all the possible executable names and symlinks.
- this->CleanFiles.insert(this->CleanFiles.end(), exeCleanFiles.begin(),
- exeCleanFiles.end());
+ this->CleanFiles.insert(exeCleanFiles.begin(), exeCleanFiles.end());
#else
static_cast<void>(relink);
#endif
@@ -303,61 +286,49 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
{
std::vector<std::string> commands;
- // Build list of dependencies.
- std::vector<std::string> depends;
- this->AppendLinkDepends(depends);
- if (!this->DeviceLinkObject.empty()) {
- depends.push_back(this->DeviceLinkObject);
- }
-
// Get the name of the executable to generate.
- std::string targetName;
- std::string targetNameReal;
- std::string targetNameImport;
- std::string targetNamePDB;
- this->GeneratorTarget->GetExecutableNames(targetName, targetNameReal,
- targetNameImport, targetNamePDB,
- this->ConfigName);
+ cmGeneratorTarget::Names targetNames =
+ this->GeneratorTarget->GetExecutableNames(this->ConfigName);
// Construct the full path version of the names.
std::string outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
if (this->GeneratorTarget->IsAppBundleOnApple()) {
- this->OSXBundleGenerator->CreateAppBundle(targetName, outpath);
+ this->OSXBundleGenerator->CreateAppBundle(targetNames.Output, outpath);
}
outpath += "/";
std::string outpathImp;
if (relink) {
outpath = this->Makefile->GetCurrentBinaryDirectory();
- outpath += cmake::GetCMakeFilesDirectory();
+ outpath += "/CMakeFiles";
outpath += "/CMakeRelink.dir";
- cmSystemTools::MakeDirectory(outpath.c_str());
+ cmSystemTools::MakeDirectory(outpath);
outpath += "/";
- if (!targetNameImport.empty()) {
+ if (!targetNames.ImportLibrary.empty()) {
outpathImp = outpath;
}
} else {
- cmSystemTools::MakeDirectory(outpath.c_str());
- if (!targetNameImport.empty()) {
+ cmSystemTools::MakeDirectory(outpath);
+ if (!targetNames.ImportLibrary.empty()) {
outpathImp = this->GeneratorTarget->GetDirectory(
this->ConfigName, cmStateEnums::ImportLibraryArtifact);
- cmSystemTools::MakeDirectory(outpathImp.c_str());
+ cmSystemTools::MakeDirectory(outpathImp);
outpathImp += "/";
}
}
std::string compilePdbOutputPath =
this->GeneratorTarget->GetCompilePDBDirectory(this->ConfigName);
- cmSystemTools::MakeDirectory(compilePdbOutputPath.c_str());
+ cmSystemTools::MakeDirectory(compilePdbOutputPath);
std::string pdbOutputPath =
this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
- cmSystemTools::MakeDirectory(pdbOutputPath.c_str());
+ cmSystemTools::MakeDirectory(pdbOutputPath);
pdbOutputPath += "/";
- std::string targetFullPath = outpath + targetName;
- std::string targetFullPathReal = outpath + targetNameReal;
- std::string targetFullPathPDB = pdbOutputPath + targetNamePDB;
- std::string targetFullPathImport = outpathImp + targetNameImport;
+ std::string targetFullPath = outpath + targetNames.Output;
+ std::string targetFullPathReal = outpath + targetNames.Real;
+ std::string targetFullPathPDB = pdbOutputPath + targetNames.PDB;
+ std::string targetFullPathImport = outpathImp + targetNames.ImportLibrary;
std::string targetOutPathPDB = this->LocalGenerator->ConvertToOutputFormat(
targetFullPathPDB, cmOutputConverter::SHELL);
// Convert to the output path to use in constructing commands.
@@ -382,11 +353,18 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Make sure we have a link language.
if (linkLanguage.empty()) {
- cmSystemTools::Error("Cannot determine link language for target \"",
- this->GeneratorTarget->GetName().c_str(), "\".");
+ cmSystemTools::Error("Cannot determine link language for target \"" +
+ this->GeneratorTarget->GetName() + "\".");
return;
}
+ // Build list of dependencies.
+ std::vector<std::string> depends;
+ this->AppendLinkDepends(depends, linkLanguage);
+ if (!this->DeviceLinkObject.empty()) {
+ depends.push_back(this->DeviceLinkObject);
+ }
+
this->NumberOfProgressActions++;
if (!this->NoRuleMessages) {
cmLocalUnixMakefileGenerator3::EchoProgress progress;
@@ -441,15 +419,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
linkLanguage, this->ConfigName);
// Add target-specific linker flags.
- this->LocalGenerator->AppendFlags(
- linkFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- std::string linkFlagsConfig = "LINK_FLAGS_";
- linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
- this->LocalGenerator->AppendFlags(
- linkFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
+ this->GetTargetLinkFlags(linkFlags, linkLanguage);
{
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
@@ -470,19 +443,19 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// clean set just in case.
exeCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(),
- (targetFullPath + ".manifest").c_str()));
+ targetFullPath + ".manifest"));
#endif
- if (targetNameReal != targetName) {
+ if (this->TargetNames.Real != this->TargetNames.Output) {
exeCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal));
}
- if (!targetNameImport.empty()) {
+ if (!this->TargetNames.ImportLibrary.empty()) {
exeCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(),
targetFullPathImport));
std::string implib;
- if (this->GeneratorTarget->GetImplibGNUtoMS(targetFullPathImport,
- implib)) {
+ if (this->GeneratorTarget->GetImplibGNUtoMS(
+ this->ConfigName, targetFullPathImport, implib)) {
exeCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), implib));
}
@@ -491,7 +464,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// 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->LocalGenerator->MaybeConvertToRelativePath(
+ this->CleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathPDB));
// Add the pre-build and pre-link rules building but not when relinking.
@@ -539,7 +512,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Set path conversion for link script shells.
this->LocalGenerator->SetLinkScriptShell(useLinkScript);
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
@@ -619,9 +592,9 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
if (this->GeneratorTarget->GetPropertyAsBool("LINK_WHAT_YOU_USE")) {
std::string cmakeCommand = this->LocalGenerator->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
- cmakeCommand += " -E __run_iwyu --lwyu=";
+ cmakeCommand += " -E __run_co_compile --lwyu=";
cmakeCommand += targetOutPathReal;
- real_link_commands.push_back(cmakeCommand);
+ real_link_commands.push_back(std::move(cmakeCommand));
}
std::string launcher;
@@ -633,16 +606,15 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
launcher += " ";
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
// Expand placeholders in the commands.
rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport);
- for (std::vector<std::string>::iterator i = real_link_commands.begin();
- i != real_link_commands.end(); ++i) {
- *i = launcher + *i;
- rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, *i,
- vars);
+ for (std::string& real_link_command : real_link_commands) {
+ real_link_command = launcher + real_link_command;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
+ real_link_command, vars);
}
// Restore path conversion to normal shells.
@@ -662,7 +634,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
this->LocalGenerator->CreateCDCommand(
commands1, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
commands1.clear();
// Add a rule to create necessary symlinks for the library.
@@ -671,11 +643,11 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
symlink += targetOutPathReal;
symlink += " ";
symlink += targetOutPath;
- commands1.push_back(symlink);
+ commands1.push_back(std::move(symlink));
this->LocalGenerator->CreateCDCommand(
commands1, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
commands1.clear();
}
@@ -687,7 +659,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
}
// Write the build rule.
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
targetFullPathReal, depends, commands,
false);
@@ -698,7 +670,7 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
depends.clear();
commands.clear();
depends.push_back(targetFullPathReal);
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
targetFullPath, depends, commands,
false);
}
@@ -707,6 +679,5 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
this->WriteTargetDriverRule(targetFullPath, relink);
// Clean all the possible executable names and symlinks.
- this->CleanFiles.insert(this->CleanFiles.end(), exeCleanFiles.begin(),
- exeCleanFiles.end());
+ this->CleanFiles.insert(exeCleanFiles.begin(), exeCleanFiles.end());
}
diff --git a/Source/cmMakefileExecutableTargetGenerator.h b/Source/cmMakefileExecutableTargetGenerator.h
index 01aa6270c..b9bbe8667 100644
--- a/Source/cmMakefileExecutableTargetGenerator.h
+++ b/Source/cmMakefileExecutableTargetGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmMakefileExecutableTargetGenerator_h
#define cmMakefileExecutableTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -15,11 +15,11 @@ class cmMakefileExecutableTargetGenerator : public cmMakefileTargetGenerator
{
public:
cmMakefileExecutableTargetGenerator(cmGeneratorTarget* target);
- ~cmMakefileExecutableTargetGenerator() CM_OVERRIDE;
+ ~cmMakefileExecutableTargetGenerator() override;
/* the main entry point for this class. Writes the Makefiles associated
with this target */
- void WriteRuleFiles() CM_OVERRIDE;
+ void WriteRuleFiles() override;
protected:
virtual void WriteExecutableRule(bool relink);
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index 3d1594bdb..b9f7c6d13 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -2,10 +2,14 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmMakefileLibraryTargetGenerator.h"
-#include <algorithm>
+#include <memory> // IWYU pragma: keep
+#include <set>
#include <sstream>
+#include <stddef.h>
+#include <utility>
#include <vector>
+#include "cmAlgorithms.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalUnixMakefileGenerator3.h"
@@ -22,8 +26,6 @@
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator(
cmGeneratorTarget* target)
@@ -31,20 +33,17 @@ cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator(
{
this->CustomCommandDriver = OnDepends;
if (this->GeneratorTarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
- this->GeneratorTarget->GetLibraryNames(
- this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
- this->TargetNameImport, this->TargetNamePDB, this->ConfigName);
+ this->TargetNames =
+ this->GeneratorTarget->GetLibraryNames(this->ConfigName);
}
this->OSXBundleGenerator =
- new cmOSXBundleGenerator(target, this->ConfigName);
+ cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
-cmMakefileLibraryTargetGenerator::~cmMakefileLibraryTargetGenerator()
-{
- delete this->OSXBundleGenerator;
-}
+cmMakefileLibraryTargetGenerator::~cmMakefileLibraryTargetGenerator() =
+ default;
void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
{
@@ -89,9 +88,6 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
break;
}
- // Write the requires target.
- this->WriteTargetRequiresRules();
-
// Write clean target
this->WriteTargetCleanRules();
@@ -117,7 +113,7 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
this->AppendObjectDepends(depends);
// Write the rule.
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
this->GeneratorTarget->GetName(),
depends, commands, true);
@@ -127,22 +123,11 @@ void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
{
- const std::string cuda_lang("CUDA");
- cmGeneratorTarget::LinkClosure const* closure =
- this->GeneratorTarget->GetLinkClosure(this->ConfigName);
-
- const bool hasCUDA =
- (std::find(closure->Languages.begin(), closure->Languages.end(),
- cuda_lang) != closure->Languages.end());
-
- const bool resolveDeviceSymbols =
- this->GeneratorTarget->GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS");
- if (hasCUDA && resolveDeviceSymbols) {
+ const bool requiresDeviceLinking = requireDeviceLinking(
+ *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ if (requiresDeviceLinking) {
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
- std::string extraFlags;
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- this->WriteDeviceLibraryRules(linkRuleVar, extraFlags, false);
+ this->WriteDeviceLibraryRules(linkRuleVar, false);
}
std::string linkLanguage =
@@ -153,7 +138,7 @@ void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
std::string extraFlags;
this->LocalGenerator->GetStaticLibraryFlags(
- extraFlags, cmSystemTools::UpperCase(this->ConfigName),
+ extraFlags, cmSystemTools::UpperCase(this->ConfigName), linkLanguage,
this->GeneratorTarget);
this->WriteLibraryRules(linkRuleVar, extraFlags, false);
}
@@ -166,19 +151,11 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
}
if (!relink) {
- const std::string cuda_lang("CUDA");
- cmGeneratorTarget::LinkClosure const* closure =
- this->GeneratorTarget->GetLinkClosure(this->ConfigName);
-
- const bool hasCUDA =
- (std::find(closure->Languages.begin(), closure->Languages.end(),
- cuda_lang) != closure->Languages.end());
- if (hasCUDA) {
+ const bool requiresDeviceLinking = requireDeviceLinking(
+ *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ if (requiresDeviceLinking) {
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
- std::string extraFlags;
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- this->WriteDeviceLibraryRules(linkRuleVar, extraFlags, relink);
+ this->WriteDeviceLibraryRules(linkRuleVar, relink);
}
}
@@ -189,17 +166,11 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
linkRuleVar += "_CREATE_SHARED_LIBRARY";
std::string extraFlags;
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- std::string linkFlagsConfig = "LINK_FLAGS_";
- linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
-
+ this->GetTargetLinkFlags(extraFlags, linkLanguage);
this->LocalGenerator->AddConfigVariableFlags(
extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName);
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
@@ -214,21 +185,12 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
{
-
if (!relink) {
- const std::string cuda_lang("CUDA");
- cmGeneratorTarget::LinkClosure const* closure =
- this->GeneratorTarget->GetLinkClosure(this->ConfigName);
-
- const bool hasCUDA =
- (std::find(closure->Languages.begin(), closure->Languages.end(),
- cuda_lang) != closure->Languages.end());
- if (hasCUDA) {
+ const bool requiresDeviceLinking = requireDeviceLinking(
+ *this->GeneratorTarget, *this->LocalGenerator, this->ConfigName);
+ if (requiresDeviceLinking) {
std::string linkRuleVar = "CMAKE_CUDA_DEVICE_LINK_LIBRARY";
- std::string extraFlags;
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- this->WriteDeviceLibraryRules(linkRuleVar, extraFlags, relink);
+ this->WriteDeviceLibraryRules(linkRuleVar, relink);
}
}
@@ -239,16 +201,11 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
linkRuleVar += "_CREATE_SHARED_MODULE";
std::string extraFlags;
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- std::string linkFlagsConfig = "LINK_FLAGS_";
- linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
+ this->GetTargetLinkFlags(extraFlags, linkLanguage);
this->LocalGenerator->AddConfigVariableFlags(
extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName);
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
@@ -267,12 +224,7 @@ void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
linkRuleVar += "_CREATE_MACOSX_FRAMEWORK";
std::string extraFlags;
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
- std::string linkFlagsConfig = "LINK_FLAGS_";
- linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
- this->LocalGenerator->AppendFlags(
- extraFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
+ this->GetTargetLinkFlags(extraFlags, linkLanguage);
this->LocalGenerator->AddConfigVariableFlags(
extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->ConfigName);
@@ -280,25 +232,25 @@ void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
}
void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
- const std::string& linkRuleVar, const std::string& extraFlags, bool relink)
+ const std::string& linkRuleVar, bool relink)
{
#ifdef CMAKE_BUILD_WITH_CMAKE
// 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 = "CUDA";
std::string const objExt =
this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION");
+ // Build list of dependencies.
+ std::vector<std::string> depends;
+ this->AppendLinkDepends(depends, linkLanguage);
+
// Create set of linking flags.
std::string linkFlags;
- this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
+ this->GetTargetLinkFlags(linkFlags, linkLanguage);
// Get the name of the device object to generate.
std::string const targetOutputReal =
@@ -320,8 +272,8 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress);
}
// Clean files associated with this library.
- std::vector<std::string> libCleanFiles;
- libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
+ std::set<std::string> libCleanFiles;
+ libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetOutputReal));
// Determine whether a link script will be used.
@@ -348,7 +300,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
std::string linkLibs;
if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) {
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
new cmLinkLineDeviceComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
@@ -410,7 +362,7 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
launcher += " ";
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
// Construct the main link rule and expand placeholders.
@@ -419,18 +371,16 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
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) {
- *i = launcher + *i;
- rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, *i,
- vars);
+ for (std::string& real_link_command : real_link_commands) {
+ real_link_command = launcher + real_link_command;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
+ real_link_command, vars);
}
// Restore path conversion to normal shells.
this->LocalGenerator->SetLinkScriptShell(false);
// Clean all the possible library names and symlinks.
- this->CleanFiles.insert(this->CleanFiles.end(), libCleanFiles.begin(),
- libCleanFiles.end());
+ this->CleanFiles.insert(libCleanFiles.begin(), libCleanFiles.end());
}
std::vector<std::string> commands1;
@@ -447,21 +397,20 @@ void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
this->LocalGenerator->CreateCDCommand(
commands1, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
commands1.clear();
// Compute the list of outputs.
std::vector<std::string> outputs(1, targetOutputReal);
// Write the build rule.
- this->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, outputs, depends,
+ this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs, depends,
commands, false);
// Write the main driver rule to build everything in this target.
this->WriteTargetDriverRule(targetOutputReal, relink);
#else
static_cast<void>(linkRuleVar);
- static_cast<void>(extraFlags);
static_cast<void>(relink);
#endif
}
@@ -473,24 +422,24 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// code duplication.
std::vector<std::string> commands;
- // Build list of dependencies.
- std::vector<std::string> depends;
- this->AppendLinkDepends(depends);
- if (!this->DeviceLinkObject.empty()) {
- depends.push_back(this->DeviceLinkObject);
- }
-
// Get the language to use for linking this library.
std::string linkLanguage =
this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
// Make sure we have a link language.
if (linkLanguage.empty()) {
- cmSystemTools::Error("Cannot determine link language for target \"",
- this->GeneratorTarget->GetName().c_str(), "\".");
+ cmSystemTools::Error("Cannot determine link language for target \"" +
+ this->GeneratorTarget->GetName() + "\".");
return;
}
+ // Build list of dependencies.
+ std::vector<std::string> depends;
+ this->AppendLinkDepends(depends, linkLanguage);
+ if (!this->DeviceLinkObject.empty()) {
+ depends.push_back(this->DeviceLinkObject);
+ }
+
// Create set of linking flags.
std::string linkFlags;
this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
@@ -505,61 +454,57 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
}
// Construct the name of the library.
- std::string targetName;
- std::string targetNameSO;
- std::string targetNameReal;
- std::string targetNameImport;
- std::string targetNamePDB;
- this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO,
- targetNameReal, targetNameImport,
- targetNamePDB, this->ConfigName);
+ this->GeneratorTarget->GetLibraryNames(this->ConfigName);
// Construct the full path version of the names.
std::string outpath;
std::string outpathImp;
if (this->GeneratorTarget->IsFrameworkOnApple()) {
outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
- this->OSXBundleGenerator->CreateFramework(targetName, outpath);
+ this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output,
+ outpath);
outpath += "/";
} else if (this->GeneratorTarget->IsCFBundleOnApple()) {
outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
- this->OSXBundleGenerator->CreateCFBundle(targetName, outpath);
+ this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output,
+ outpath);
outpath += "/";
} else if (relink) {
outpath = this->Makefile->GetCurrentBinaryDirectory();
- outpath += cmake::GetCMakeFilesDirectory();
+ outpath += "/CMakeFiles";
outpath += "/CMakeRelink.dir";
- cmSystemTools::MakeDirectory(outpath.c_str());
+ cmSystemTools::MakeDirectory(outpath);
outpath += "/";
- if (!targetNameImport.empty()) {
+ if (!this->TargetNames.ImportLibrary.empty()) {
outpathImp = outpath;
}
} else {
outpath = this->GeneratorTarget->GetDirectory(this->ConfigName);
- cmSystemTools::MakeDirectory(outpath.c_str());
+ cmSystemTools::MakeDirectory(outpath);
outpath += "/";
- if (!targetNameImport.empty()) {
+ if (!this->TargetNames.ImportLibrary.empty()) {
outpathImp = this->GeneratorTarget->GetDirectory(
this->ConfigName, cmStateEnums::ImportLibraryArtifact);
- cmSystemTools::MakeDirectory(outpathImp.c_str());
+ cmSystemTools::MakeDirectory(outpathImp);
outpathImp += "/";
}
}
std::string compilePdbOutputPath =
this->GeneratorTarget->GetCompilePDBDirectory(this->ConfigName);
- cmSystemTools::MakeDirectory(compilePdbOutputPath.c_str());
+ cmSystemTools::MakeDirectory(compilePdbOutputPath);
std::string pdbOutputPath =
this->GeneratorTarget->GetPDBDirectory(this->ConfigName);
- cmSystemTools::MakeDirectory(pdbOutputPath.c_str());
+ cmSystemTools::MakeDirectory(pdbOutputPath);
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;
+ std::string targetFullPath = outpath + this->TargetNames.Output;
+ std::string targetFullPathPDB = pdbOutputPath + this->TargetNames.PDB;
+ std::string targetFullPathSO = outpath + this->TargetNames.SharedObject;
+ std::string targetFullPathReal = outpath + this->TargetNames.Real;
+ std::string targetFullPathImport =
+ outpathImp + this->TargetNames.ImportLibrary;
// Construct the output path version of the names for use in command
// arguments.
@@ -615,8 +560,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
}
// Clean files associated with this library.
- std::vector<std::string> libCleanFiles;
- libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
+ std::set<std::string> libCleanFiles;
+ libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal));
std::vector<std::string> commands1;
@@ -628,26 +573,27 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
this->LocalGenerator->CreateCDCommand(
commands1, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
commands1.clear();
}
- if (targetName != targetNameReal) {
- libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
+ if (this->TargetNames.Output != this->TargetNames.Real) {
+ libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPath));
}
- if (targetNameSO != targetNameReal && targetNameSO != targetName) {
- libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
+ if (this->TargetNames.SharedObject != this->TargetNames.Real &&
+ this->TargetNames.SharedObject != this->TargetNames.Output) {
+ libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathSO));
}
- if (!targetNameImport.empty()) {
- libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
+ if (!this->TargetNames.ImportLibrary.empty()) {
+ libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(),
targetFullPathImport));
std::string implib;
- if (this->GeneratorTarget->GetImplibGNUtoMS(targetFullPathImport,
- implib)) {
- libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
+ if (this->GeneratorTarget->GetImplibGNUtoMS(
+ this->ConfigName, targetFullPathImport, implib)) {
+ libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), implib));
}
}
@@ -655,16 +601,16 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// 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->LocalGenerator->MaybeConvertToRelativePath(
+ this->CleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathPDB));
#ifdef _WIN32
// There may be a manifest file for this target. Add it to the
// clean set just in case.
if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) {
- libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
+ libCleanFiles.insert(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(),
- (targetFullPath + ".manifest").c_str()));
+ targetFullPath + ".manifest"));
}
#endif
@@ -736,10 +682,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// 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;
+ // Limit the length of individual object lists to less than half of
+ // the command line length limit (leaving half for other flags).
+ // This may result in several calls to the archiver.
+ if (size_t limit = cmSystemTools::CalculateCommandLineLengthLimit()) {
+ archiveCommandLimit = limit / 2;
+ } else {
+ archiveCommandLimit = 8000;
+ }
}
// Expand the rule variables.
@@ -755,7 +705,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
std::string linkLibs;
if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) {
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
@@ -832,7 +782,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
vars.ObjectsQuoted = buildObjs.c_str();
if (this->GeneratorTarget->HasSOName(this->ConfigName)) {
vars.SONameFlag = this->Makefile->GetSONameFlag(linkLanguage);
- vars.TargetSOName = targetNameSO.c_str();
+ vars.TargetSOName = this->TargetNames.SharedObject.c_str();
}
vars.LinkFlags = linkFlags.c_str();
@@ -874,7 +824,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
launcher += " ";
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
// Construct the main link rule and expand placeholders.
rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport);
@@ -897,38 +847,32 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
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 = launcher + *i;
+ for (std::string const& acc : archiveCreateCommands) {
+ std::string cmd = launcher + acc;
rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
cmd, vars);
- real_link_commands.push_back(cmd);
+ real_link_commands.push_back(std::move(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 = launcher + *i;
+ for (std::string const& aac : archiveAppendCommands) {
+ std::string cmd = launcher + aac;
rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
cmd, vars);
- real_link_commands.push_back(cmd);
+ real_link_commands.push_back(std::move(cmd));
}
}
// Finish the archive.
vars.Objects = "";
- for (std::vector<std::string>::const_iterator i =
- archiveFinishCommands.begin();
- i != archiveFinishCommands.end(); ++i) {
- std::string cmd = launcher + *i;
+ for (std::string const& afc : archiveFinishCommands) {
+ std::string cmd = launcher + afc;
rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, cmd,
vars);
// If there is no ranlib the command will be ":". Skip it.
if (!cmd.empty() && cmd[0] != ':') {
- real_link_commands.push_back(cmd);
+ real_link_commands.push_back(std::move(cmd));
}
}
} else {
@@ -939,17 +883,16 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
(this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY)) {
std::string cmakeCommand = this->LocalGenerator->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
- cmakeCommand += " -E __run_iwyu --lwyu=";
+ cmakeCommand += " -E __run_co_compile --lwyu=";
cmakeCommand += targetOutPathReal;
- real_link_commands.push_back(cmakeCommand);
+ real_link_commands.push_back(std::move(cmakeCommand));
}
// Expand placeholders.
- for (std::vector<std::string>::iterator i = real_link_commands.begin();
- i != real_link_commands.end(); ++i) {
- *i = launcher + *i;
- rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, *i,
- vars);
+ for (std::string& real_link_command : real_link_commands) {
+ real_link_command = launcher + real_link_command;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
+ real_link_command, vars);
}
}
@@ -970,7 +913,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
this->LocalGenerator->CreateCDCommand(
commands1, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
commands1.clear();
// Add a rule to create necessary symlinks for the library.
@@ -983,11 +926,11 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
symlink += targetOutPathSO;
symlink += " ";
symlink += targetOutPath;
- commands1.push_back(symlink);
+ commands1.push_back(std::move(symlink));
this->LocalGenerator->CreateCDCommand(
commands1, this->Makefile->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), commands1.begin(), commands1.end());
+ cmAppend(commands, commands1);
commands1.clear();
}
@@ -1000,21 +943,21 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Compute the list of outputs.
std::vector<std::string> outputs(1, targetFullPathReal);
- if (targetNameSO != targetNameReal) {
+ if (this->TargetNames.SharedObject != this->TargetNames.Real) {
outputs.push_back(targetFullPathSO);
}
- if (targetName != targetNameSO && targetName != targetNameReal) {
+ if (this->TargetNames.Output != this->TargetNames.SharedObject &&
+ this->TargetNames.Output != this->TargetNames.Real) {
outputs.push_back(targetFullPath);
}
// Write the build rule.
- this->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, outputs, depends,
+ this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs, depends,
commands, false);
// 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());
+ this->CleanFiles.insert(libCleanFiles.begin(), libCleanFiles.end());
}
diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h
index da1d8b65c..35e43277d 100644
--- a/Source/cmMakefileLibraryTargetGenerator.h
+++ b/Source/cmMakefileLibraryTargetGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmMakefileLibraryTargetGenerator_h
#define cmMakefileLibraryTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmMakefileTargetGenerator.h"
@@ -15,11 +15,11 @@ class cmMakefileLibraryTargetGenerator : public cmMakefileTargetGenerator
{
public:
cmMakefileLibraryTargetGenerator(cmGeneratorTarget* target);
- ~cmMakefileLibraryTargetGenerator() CM_OVERRIDE;
+ ~cmMakefileLibraryTargetGenerator() override;
/* the main entry point for this class. Writes the Makefiles associated
with this target */
- void WriteRuleFiles() CM_OVERRIDE;
+ void WriteRuleFiles() override;
protected:
void WriteObjectLibraryRules();
@@ -27,8 +27,7 @@ protected:
void WriteSharedLibraryRules(bool relink);
void WriteModuleLibraryRules(bool relink);
- void WriteDeviceLibraryRules(const std::string& linkRule,
- const std::string& extraFlags, bool relink);
+ void WriteDeviceLibraryRules(const std::string& linkRule, bool relink);
void WriteLibraryRules(const std::string& linkRule,
const std::string& extraFlags, bool relink);
// MacOSX Framework support methods
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx
index a4511b63b..b3bab4b08 100644
--- a/Source/cmMakefileTargetGenerator.cxx
+++ b/Source/cmMakefileTargetGenerator.cxx
@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmMakefileTargetGenerator.h"
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <utility>
@@ -20,6 +21,7 @@
#include "cmMakefileLibraryTargetGenerator.h"
#include "cmMakefileUtilityTargetGenerator.h"
#include "cmOutputConverter.h"
+#include "cmRange.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
#include "cmState.h"
@@ -27,17 +29,16 @@
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmGeneratorTarget* target)
: cmCommonTargetGenerator(target)
- , OSXBundleGenerator(CM_NULLPTR)
- , MacOSXContentGenerator(CM_NULLPTR)
+ , OSXBundleGenerator(nullptr)
+ , MacOSXContentGenerator(nullptr)
{
- this->BuildFileStream = CM_NULLPTR;
- this->InfoFileStream = CM_NULLPTR;
- this->FlagFileStream = CM_NULLPTR;
+ this->BuildFileStream = nullptr;
+ this->InfoFileStream = nullptr;
+ this->FlagFileStream = nullptr;
this->CustomCommandDriver = OnBuild;
this->LocalGenerator =
static_cast<cmLocalUnixMakefileGenerator3*>(target->GetLocalGenerator());
@@ -60,7 +61,7 @@ cmMakefileTargetGenerator::~cmMakefileTargetGenerator()
cmMakefileTargetGenerator* cmMakefileTargetGenerator::New(
cmGeneratorTarget* tgt)
{
- cmMakefileTargetGenerator* result = CM_NULLPTR;
+ cmMakefileTargetGenerator* result = nullptr;
switch (tgt->GetType()) {
case cmStateEnums::EXECUTABLE:
@@ -82,6 +83,26 @@ cmMakefileTargetGenerator* cmMakefileTargetGenerator::New(
return result;
}
+void cmMakefileTargetGenerator::GetTargetLinkFlags(
+ std::string& flags, const std::string& linkLanguage)
+{
+ this->LocalGenerator->AppendFlags(
+ flags, this->GeneratorTarget->GetProperty("LINK_FLAGS"));
+
+ std::string linkFlagsConfig = "LINK_FLAGS_";
+ linkFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
+ this->LocalGenerator->AppendFlags(
+ flags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
+
+ std::vector<std::string> opts;
+ this->GeneratorTarget->GetLinkOptions(opts, this->ConfigName, linkLanguage);
+ // LINK_OPTIONS are escaped.
+ this->LocalGenerator->AppendCompileOptions(flags, opts);
+
+ this->LocalGenerator->AppendPositionIndependentLinkerFlags(
+ flags, this->GeneratorTarget, this->ConfigName, linkLanguage);
+}
+
void cmMakefileTargetGenerator::CreateRuleFile()
{
// Create a directory for this target.
@@ -89,7 +110,7 @@ void cmMakefileTargetGenerator::CreateRuleFile()
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
this->TargetBuildDirectoryFull =
this->LocalGenerator->ConvertToFullPath(this->TargetBuildDirectory);
- cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull.c_str());
+ cmSystemTools::MakeDirectory(this->TargetBuildDirectoryFull);
// Construct the rule file name.
this->BuildFileName = this->TargetBuildDirectory;
@@ -107,7 +128,7 @@ void cmMakefileTargetGenerator::CreateRuleFile()
// 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(), false,
+ new cmGeneratedFileStream(this->BuildFileNameFull, false,
this->GlobalGenerator->GetMakefileEncoding());
this->BuildFileStream->SetCopyIfDifferent(true);
if (!this->BuildFileStream) {
@@ -126,21 +147,41 @@ void cmMakefileTargetGenerator::CreateRuleFile()
void cmMakefileTargetGenerator::WriteTargetBuildRules()
{
+ // -- Write the custom commands for this target
+
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")) {
+ // Evaluates generator expressions and expands prop_value
+ auto evaluatedFiles =
+ [this, &config](const char* prop_value) -> std::vector<std::string> {
+ std::vector<std::string> files;
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
- ge.Parse(additional_clean_files);
-
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop_value);
cmSystemTools::ExpandListArgument(
cge->Evaluate(this->LocalGenerator, config, false, this->GeneratorTarget,
- CM_NULLPTR, CM_NULLPTR),
- this->CleanFiles);
+ nullptr, nullptr),
+ files);
+ return files;
+ };
+
+ // Look for additional files registered for cleaning in this directory.
+ if (const char* prop_value =
+ this->Makefile->GetProperty("ADDITIONAL_MAKE_CLEAN_FILES")) {
+ std::vector<std::string> const files = evaluatedFiles(prop_value);
+ this->CleanFiles.insert(files.begin(), files.end());
+ }
+
+ // Look for additional files registered for cleaning in this target.
+ if (const char* prop_value =
+ this->GeneratorTarget->GetProperty("ADDITIONAL_CLEAN_FILES")) {
+ std::vector<std::string> const files = evaluatedFiles(prop_value);
+ // For relative path support
+ std::string const& binaryDir =
+ this->LocalGenerator->GetCurrentBinaryDirectory();
+ for (std::string const& cfl : files) {
+ this->CleanFiles.insert(cmSystemTools::CollapseFullPath(cfl, binaryDir));
+ }
}
// add custom commands to the clean rules?
@@ -153,18 +194,41 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
this->GeneratorTarget->GetCustomCommands(customCommands, config);
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
- for (std::vector<cmSourceFile const*>::const_iterator si =
- customCommands.begin();
- si != customCommands.end(); ++si) {
- cmCustomCommandGenerator ccg(*(*si)->GetCustomCommand(), this->ConfigName,
+ for (cmSourceFile const* sf : customCommands) {
+ cmCustomCommandGenerator ccg(*sf->GetCustomCommand(), this->ConfigName,
this->LocalGenerator);
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->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, *o));
+ for (std::string const& output : outputs) {
+ this->CleanFiles.insert(
+ this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir,
+ output));
+ }
+ const std::vector<std::string>& byproducts = ccg.GetByproducts();
+ for (std::string const& byproduct : byproducts) {
+ this->CleanFiles.insert(
+ this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir,
+ byproduct));
+ }
+ }
+ }
+
+ // Add byproducts from build events to the clean rules
+ if (clean) {
+ std::vector<cmCustomCommand> buildEventCommands =
+ this->GeneratorTarget->GetPreBuildCommands();
+
+ cmAppend(buildEventCommands, this->GeneratorTarget->GetPreLinkCommands());
+ cmAppend(buildEventCommands,
+ this->GeneratorTarget->GetPostBuildCommands());
+
+ for (const auto& be : buildEventCommands) {
+ const std::vector<std::string>& byproducts = be.GetByproducts();
+ for (std::string const& byproduct : byproducts) {
+ this->CleanFiles.insert(
+ this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir,
+ byproduct));
}
}
}
@@ -178,18 +242,14 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules()
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());
+ for (cmSourceFile const* sf : externalObjects) {
+ this->ExternalObjects.push_back(sf->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) {
+ for (cmSourceFile const* sf : objectSources) {
// Generate this object file's rule file.
- this->WriteObjectRuleFiles(**si);
+ this->WriteObjectRuleFiles(*sf);
}
}
@@ -206,10 +266,8 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
<< "# Include any dependencies generated for this target.\n"
<< this->GlobalGenerator->IncludeDirective << " " << root
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator
- ->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(), dependFileNameFull)
- .c_str())
+ this->LocalGenerator->MaybeConvertToRelativePath(
+ this->LocalGenerator->GetBinaryDirectory(), dependFileNameFull))
<< "\n\n";
if (!this->NoRuleMessages) {
@@ -218,20 +276,17 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
<< "# Include the progress variables for this target.\n"
<< this->GlobalGenerator->IncludeDirective << " " << root
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator
- ->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(),
- this->ProgressFileNameFull)
- .c_str())
+ this->LocalGenerator->MaybeConvertToRelativePath(
+ this->LocalGenerator->GetBinaryDirectory(),
+ this->ProgressFileNameFull))
<< "\n\n";
}
// make sure the depend file exists
- if (!cmSystemTools::FileExists(dependFileNameFull.c_str())) {
+ if (!cmSystemTools::FileExists(dependFileNameFull)) {
// Write an empty dependency file.
cmGeneratedFileStream depFileStream(
- dependFileNameFull.c_str(), false,
- this->GlobalGenerator->GetMakefileEncoding());
+ dependFileNameFull, false, this->GlobalGenerator->GetMakefileEncoding());
depFileStream << "# Empty dependencies file for "
<< this->GeneratorTarget->GetName() << ".\n"
<< "# This may be replaced when dependencies are built."
@@ -243,7 +298,7 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
this->FlagFileNameFull = this->TargetBuildDirectoryFull;
this->FlagFileNameFull += "/flags.make";
this->FlagFileStream =
- new cmGeneratedFileStream(this->FlagFileNameFull.c_str(), false,
+ new cmGeneratedFileStream(this->FlagFileNameFull, false,
this->GlobalGenerator->GetMakefileEncoding());
this->FlagFileStream->SetCopyIfDifferent(true);
if (!this->FlagFileStream) {
@@ -256,11 +311,8 @@ void cmMakefileTargetGenerator::WriteCommonCodeRules()
<< "# Include the compile flags for this target's objects.\n"
<< this->GlobalGenerator->IncludeDirective << " " << root
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator
- ->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(),
- this->FlagFileNameFull)
- .c_str())
+ this->LocalGenerator->MaybeConvertToRelativePath(
+ this->LocalGenerator->GetBinaryDirectory(), this->FlagFileNameFull))
<< "\n\n";
}
@@ -272,28 +324,26 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
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) {
+ for (std::string const& language : languages) {
std::string compiler = "CMAKE_";
- compiler += *l;
+ compiler += language;
compiler += "_COMPILER";
- *this->FlagFileStream << "# compile " << *l << " with "
+ *this->FlagFileStream << "# compile " << language << " 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);
- std::string includes = this->GetIncludes(*l);
+ for (std::string const& language : languages) {
+ std::string flags = this->GetFlags(language);
+ std::string defines = this->GetDefines(language);
+ std::string includes = this->GetIncludes(language);
// Escape comment characters so they do not terminate assignment.
cmSystemTools::ReplaceString(flags, "#", "\\#");
cmSystemTools::ReplaceString(defines, "#", "\\#");
cmSystemTools::ReplaceString(includes, "#", "\\#");
- *this->FlagFileStream << *l << "_FLAGS = " << flags << "\n\n";
- *this->FlagFileStream << *l << "_DEFINES = " << defines << "\n\n";
- *this->FlagFileStream << *l << "_INCLUDES = " << includes << "\n\n";
+ *this->FlagFileStream << language << "_FLAGS = " << flags << "\n\n";
+ *this->FlagFileStream << language << "_DEFINES = " << defines << "\n\n";
+ *this->FlagFileStream << language << "_INCLUDES = " << includes << "\n\n";
}
}
@@ -315,7 +365,7 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
std::string output = macdir;
output += "/";
output += cmSystemTools::GetFilenameName(input);
- this->Generator->CleanFiles.push_back(
+ this->Generator->CleanFiles.insert(
this->Generator->LocalGenerator->MaybeConvertToRelativePath(
this->Generator->LocalGenerator->GetCurrentBinaryDirectory(), output));
output = this->Generator->LocalGenerator->MaybeConvertToRelativePath(
@@ -335,9 +385,9 @@ void cmMakefileTargetGenerator::MacOSXContentGeneratorType::operator()(
copyCommand += " ";
copyCommand += this->Generator->LocalGenerator->ConvertToOutputFormat(
output, cmOutputConverter::SHELL);
- commands.push_back(copyCommand);
+ commands.push_back(std::move(copyCommand));
this->Generator->LocalGenerator->WriteMakeRule(
- *this->Generator->BuildFileStream, CM_NULLPTR, output, depends, commands,
+ *this->Generator->BuildFileStream, nullptr, output, depends, commands,
false);
this->Generator->ExtraFiles.insert(output);
}
@@ -369,19 +419,18 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
err << "Warning: Source file \"" << source.GetFullPath()
<< "\" is listed multiple times for target \""
<< this->GeneratorTarget->GetName() << "\".";
- cmSystemTools::Message(err.str().c_str(), "Warning");
+ cmSystemTools::Message(err.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());
+ cmSystemTools::MakeDirectory(this->LocalGenerator->ConvertToFullPath(dir));
// Save this in the target's list of object files.
this->Objects.push_back(obj);
- this->CleanFiles.push_back(obj);
+ this->CleanFiles.insert(obj);
// TODO: Remove
// std::string relativeObj
@@ -402,8 +451,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
objFullPath = cmSystemTools::CollapseFullPath(objFullPath);
std::string srcFullPath =
cmSystemTools::CollapseFullPath(source.GetFullPath());
- this->LocalGenerator->AddImplicitDepends(
- this->GeneratorTarget, lang, objFullPath.c_str(), srcFullPath.c_str());
+ this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, lang,
+ objFullPath, srcFullPath);
}
void cmMakefileTargetGenerator::WriteObjectBuildFile(
@@ -433,6 +482,8 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
std::string config = this->LocalGenerator->GetConfigName();
std::string configUpper = cmSystemTools::UpperCase(config);
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, config, this->GeneratorTarget, lang);
// Add Fortran format flags.
if (lang == "Fortran") {
@@ -440,34 +491,62 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
}
// Add flags from source file properties.
- if (const char* cflags = source.GetProperty("COMPILE_FLAGS")) {
- cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags);
- const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config,
- false, this->GeneratorTarget);
+ const std::string COMPILE_FLAGS("COMPILE_FLAGS");
+ if (const char* cflags = source.GetProperty(COMPILE_FLAGS)) {
+ const std::string& evaluatedFlags =
+ genexInterpreter.Evaluate(cflags, COMPILE_FLAGS);
this->LocalGenerator->AppendFlags(flags, evaluatedFlags);
*this->FlagFileStream << "# Custom flags: " << relativeObj
<< "_FLAGS = " << evaluatedFlags << "\n"
<< "\n";
}
+ const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
+ if (const char* coptions = source.GetProperty(COMPILE_OPTIONS)) {
+ const std::string& evaluatedOptions =
+ genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS);
+ this->LocalGenerator->AppendCompileOptions(flags, evaluatedOptions);
+ *this->FlagFileStream << "# Custom options: " << relativeObj
+ << "_OPTIONS = " << evaluatedOptions << "\n"
+ << "\n";
+ }
+
+ // Add include directories from source file properties.
+ std::vector<std::string> includes;
+
+ const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
+ if (const char* cincludes = source.GetProperty(INCLUDE_DIRECTORIES)) {
+ const std::string& evaluatedIncludes =
+ genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES);
+ this->LocalGenerator->AppendIncludeDirectories(includes, evaluatedIncludes,
+ source);
+ *this->FlagFileStream << "# Custom include directories: " << relativeObj
+ << "_INCLUDE_DIRECTORIES = " << evaluatedIncludes
+ << "\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);
+ // Add source-specific preprocessor definitions.
+ const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
+ if (const char* compile_defs = source.GetProperty(COMPILE_DEFINITIONS)) {
+ const std::string& evaluatedDefs =
+ genexInterpreter.Evaluate(compile_defs, COMPILE_DEFINITIONS);
+ this->LocalGenerator->AppendDefines(defines, evaluatedDefs);
*this->FlagFileStream << "# Custom defines: " << relativeObj
- << "_DEFINES = " << compile_defs << "\n"
+ << "_DEFINES = " << evaluatedDefs << "\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);
+ const std::string& evaluatedDefs =
+ genexInterpreter.Evaluate(config_compile_defs, COMPILE_DEFINITIONS);
+ this->LocalGenerator->AppendDefines(defines, evaluatedDefs);
*this->FlagFileStream << "# Custom defines: " << relativeObj << "_DEFINES_"
- << configUpper << " = " << config_compile_defs
- << "\n"
+ << configUpper << " = " << evaluatedDefs << "\n"
<< "\n";
}
@@ -530,7 +609,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
// mingw32-make incorrectly interprets 'a\ b c' as 'a b' and 'c'
// (but 'a\ b "c"' as 'a\', 'b', and 'c'!). Workaround this by
// avoiding a trailing backslash in the argument.
- targetOutPathCompilePDB[targetOutPathCompilePDB.size() - 1] = '/';
+ targetOutPathCompilePDB.back() = '/';
}
}
cmRulePlaceholderExpander::RuleVariables vars;
@@ -567,7 +646,10 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
vars.Defines = definesString.c_str();
- std::string const includesString = "$(" + lang + "_INCLUDES)";
+ std::string includesString = this->LocalGenerator->GetIncludeFlags(
+ includes, this->GeneratorTarget, lang, true, false, config);
+ this->LocalGenerator->AppendFlags(includesString,
+ "$(" + lang + "_INCLUDES)");
vars.Includes = includesString.c_str();
// At the moment, it is assumed that C, C++, Fortran, and CUDA have both
@@ -578,7 +660,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
bool const lang_has_assembly = lang_has_preprocessor;
bool const lang_can_export_cmds = lang_has_preprocessor;
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
// Construct the compile rules.
@@ -588,19 +670,20 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
std::string cmdVar;
if (this->GeneratorTarget->GetPropertyAsBool(
"CUDA_SEPARABLE_COMPILATION")) {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION";
} else if (this->GeneratorTarget->GetPropertyAsBool(
"CUDA_PTX_COMPILATION")) {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_PTX_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION";
} else {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION";
}
- std::string compileRule = this->Makefile->GetRequiredDefinition(cmdVar);
+ const std::string& compileRule =
+ this->Makefile->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
} else {
- const std::string cmdVar =
- std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
- std::string compileRule = this->Makefile->GetRequiredDefinition(cmdVar);
+ const std::string cmdVar = "CMAKE_" + lang + "_COMPILE_OBJECT";
+ const std::string& compileRule =
+ this->Makefile->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileRule, compileCommands);
}
@@ -621,10 +704,34 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
std::string langIncludes = std::string("$(") + lang + "_INCLUDES)";
compileCommand.replace(compileCommand.find(langIncludes),
langIncludes.size(), this->GetIncludes(lang));
+
+ const char* eliminate[] = {
+ this->Makefile->GetDefinition("CMAKE_START_TEMP_FILE"),
+ this->Makefile->GetDefinition("CMAKE_END_TEMP_FILE")
+ };
+ for (const char* el : eliminate) {
+ if (el) {
+ cmSystemTools::ReplaceString(compileCommand, el, "");
+ }
+ }
+
this->GlobalGenerator->AddCXXCompileCommand(
source.GetFullPath(), workingDirectory, compileCommand);
}
+ // See if we need to use a compiler launcher like ccache or distcc
+ std::string compilerLauncher;
+ if (!compileCommands.empty() &&
+ (lang == "C" || lang == "CXX" || lang == "Fortran" ||
+ lang == "CUDA")) {
+ std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
+ const char* clauncher =
+ this->GeneratorTarget->GetProperty(clauncher_prop);
+ if (clauncher && *clauncher) {
+ compilerLauncher = clauncher;
+ }
+ }
+
// Maybe insert an include-what-you-use runner.
if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) {
std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
@@ -633,8 +740,18 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
std::string const cpplint_prop = lang + "_CPPLINT";
const char* cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
- if ((iwyu && *iwyu) || (tidy && *tidy) || (cpplint && *cpplint)) {
- std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_iwyu";
+ std::string const cppcheck_prop = lang + "_CPPCHECK";
+ const char* cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
+ if ((iwyu && *iwyu) || (tidy && *tidy) || (cpplint && *cpplint) ||
+ (cppcheck && *cppcheck)) {
+ std::string run_iwyu = "$(CMAKE_COMMAND) -E __run_co_compile";
+ if (!compilerLauncher.empty()) {
+ // In __run_co_compile case the launcher command is supplied
+ // via --launcher=<maybe-list> and consumed
+ run_iwyu += " --launcher=";
+ run_iwyu += this->LocalGenerator->EscapeForShell(compilerLauncher);
+ compilerLauncher.clear();
+ }
if (iwyu && *iwyu) {
run_iwyu += " --iwyu=";
run_iwyu += this->LocalGenerator->EscapeForShell(iwyu);
@@ -647,7 +764,12 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
run_iwyu += " --cpplint=";
run_iwyu += this->LocalGenerator->EscapeForShell(cpplint);
}
- if ((tidy && *tidy) || (cpplint && *cpplint)) {
+ if (cppcheck && *cppcheck) {
+ run_iwyu += " --cppcheck=";
+ run_iwyu += this->LocalGenerator->EscapeForShell(cppcheck);
+ }
+ if ((tidy && *tidy) || (cpplint && *cpplint) ||
+ (cppcheck && *cppcheck)) {
run_iwyu += " --source=";
run_iwyu += sourceFile;
}
@@ -656,22 +778,19 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
}
}
- // Maybe insert a compiler launcher like ccache or distcc
- if (!compileCommands.empty() && (lang == "C" || lang == "CXX")) {
- std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
- const char* clauncher =
- this->GeneratorTarget->GetProperty(clauncher_prop);
- if (clauncher && *clauncher) {
- std::vector<std::string> launcher_cmd;
- cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
- for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
- e = launcher_cmd.end();
- i != e; ++i) {
- *i = this->LocalGenerator->EscapeForShell(*i);
+ // If compiler launcher was specified and not consumed above, it
+ // goes to the beginning of the command line.
+ if (!compileCommands.empty() && !compilerLauncher.empty()) {
+ std::vector<std::string> args;
+ cmSystemTools::ExpandListArgument(compilerLauncher, args, true);
+ if (!args.empty()) {
+ args[0] = this->LocalGenerator->ConvertToOutputFormat(
+ args[0], cmOutputConverter::SHELL);
+ for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
+ i = this->LocalGenerator->EscapeForShell(i);
}
- std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
- compileCommands.front().insert(0, run_launcher);
}
+ compileCommands.front().insert(0, cmJoin(args, " ") + " ");
}
std::string launcher;
@@ -685,19 +804,17 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
}
// Expand placeholders in the commands.
- for (std::vector<std::string>::iterator i = compileCommands.begin();
- i != compileCommands.end(); ++i) {
- *i = launcher + *i;
- rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, *i,
- vars);
+ for (std::string& compileCommand : compileCommands) {
+ compileCommand = launcher + compileCommand;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
+ compileCommand, vars);
}
// Change the command working directory to the local build tree.
this->LocalGenerator->CreateCDCommand(
compileCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), compileCommands.begin(),
- compileCommands.end());
+ cmAppend(commands, compileCommands);
}
// Check for extra outputs created by the compilation.
@@ -705,12 +822,11 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
if (const char* extra_outputs_str = source.GetProperty("OBJECT_OUTPUTS")) {
// Register these as extra files to clean.
cmSystemTools::ExpandListArgument(extra_outputs_str, outputs);
- this->CleanFiles.insert(this->CleanFiles.end(), outputs.begin() + 1,
- outputs.end());
+ this->CleanFiles.insert(outputs.begin() + 1, outputs.end());
}
// Write the rule.
- this->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR, outputs, depends,
+ this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs, depends,
commands);
bool do_preprocess_rules = lang_has_preprocessor &&
@@ -719,7 +835,7 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
lang_has_assembly && this->LocalGenerator->GetCreateAssemblySourceRules();
if (do_preprocess_rules || do_assembly_rules) {
std::vector<std::string> force_depends;
- force_depends.push_back("cmake_force");
+ force_depends.emplace_back("cmake_force");
std::string::size_type dot_pos = relativeObj.rfind('.');
std::string relativeObjBase = relativeObj.substr(0, dot_pos);
dot_pos = obj.rfind('.');
@@ -750,26 +866,24 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
vars.PreprocessedSource = shellObjI.c_str();
// Expand placeholders in the commands.
- for (std::vector<std::string>::iterator i = preprocessCommands.begin();
- i != preprocessCommands.end(); ++i) {
+ for (std::string& preprocessCommand : preprocessCommands) {
// no launcher for preprocessor commands
- rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
- *i, vars);
+ rulePlaceholderExpander->ExpandRuleVariables(
+ this->LocalGenerator, preprocessCommand, vars);
}
this->LocalGenerator->CreateCDCommand(
preprocessCommands,
this->LocalGenerator->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), preprocessCommands.begin(),
- preprocessCommands.end());
+ cmAppend(commands, preprocessCommands);
} else {
std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
cmd += preprocessRuleVar;
- commands.push_back(cmd);
+ commands.push_back(std::move(cmd));
}
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
relativeObjI, force_depends,
commands, false);
}
@@ -799,89 +913,27 @@ void cmMakefileTargetGenerator::WriteObjectBuildFile(
vars.AssemblySource = shellObjS.c_str();
// Expand placeholders in the commands.
- for (std::vector<std::string>::iterator i = assemblyCommands.begin();
- i != assemblyCommands.end(); ++i) {
+ for (std::string& assemblyCommand : assemblyCommands) {
// no launcher for assembly commands
rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
- *i, vars);
+ assemblyCommand, vars);
}
this->LocalGenerator->CreateCDCommand(
assemblyCommands, this->LocalGenerator->GetCurrentBinaryDirectory(),
this->LocalGenerator->GetBinaryDirectory());
- commands.insert(commands.end(), assemblyCommands.begin(),
- assemblyCommands.end());
+ cmAppend(commands, assemblyCommands);
} else {
std::string cmd = "$(CMAKE_COMMAND) -E cmake_unimplemented_variable ";
cmd += assemblyRuleVar;
- commands.push_back(cmd);
+ commands.push_back(std::move(cmd));
}
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
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, CM_NULLPTR,
- 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->GeneratorTarget);
- 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, CM_NULLPTR,
- 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, CM_NULLPTR, 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->GeneratorTarget);
- 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, CM_NULLPTR,
- depTarget, depends, no_commands, true);
}
void cmMakefileTargetGenerator::WriteTargetCleanRules()
@@ -902,7 +954,7 @@ void cmMakefileTargetGenerator::WriteTargetCleanRules()
this->LocalGenerator->GetBinaryDirectory());
// Write the rule.
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
cleanTarget, depends, commands, true);
}
@@ -939,18 +991,17 @@ bool cmMakefileTargetGenerator::WriteMakeRule(
// For multiple outputs, make the extra ones depend on the first one.
std::vector<std::string> const output_depends(1, outputs[0]);
std::string binDir = this->LocalGenerator->GetBinaryDirectory();
- for (std::vector<std::string>::const_iterator o = outputs.begin() + 1;
- o != outputs.end(); ++o) {
+ for (std::string const& output : cmMakeRange(outputs).advance(1)) {
// Touch the extra output so "make" knows that it was updated,
- // but only if the output was acually created.
+ // but only if the output was actually created.
std::string const out = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->MaybeConvertToRelativePath(binDir, *o),
+ this->LocalGenerator->MaybeConvertToRelativePath(binDir, output),
cmOutputConverter::SHELL);
std::vector<std::string> output_commands;
bool o_symbolic = false;
if (need_symbolic) {
- if (cmSourceFile* sf = this->Makefile->GetSource(*o)) {
+ if (cmSourceFile* sf = this->Makefile->GetSource(output)) {
o_symbolic = sf->GetPropertyAsBool("SYMBOLIC");
}
}
@@ -959,13 +1010,13 @@ bool cmMakefileTargetGenerator::WriteMakeRule(
if (!o_symbolic) {
output_commands.push_back("@$(CMAKE_COMMAND) -E touch_nocreate " + out);
}
- this->LocalGenerator->WriteMakeRule(os, CM_NULLPTR, *o, output_depends,
+ this->LocalGenerator->WriteMakeRule(os, nullptr, output, output_depends,
output_commands, o_symbolic, in_help);
if (!o_symbolic) {
// At build time, remove the first output if this one does not exist
// so that "make" will rerun the real commands that create this one.
- MultipleOutputPairsType::value_type p(*o, outputs[0]);
+ MultipleOutputPairsType::value_type p(output, outputs[0]);
this->MultipleOutputPairs.insert(p);
}
}
@@ -981,8 +1032,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
this->InfoFileNameFull += "/DependInfo.cmake";
this->InfoFileNameFull =
this->LocalGenerator->ConvertToFullPath(this->InfoFileNameFull);
- this->InfoFileStream =
- new cmGeneratedFileStream(this->InfoFileNameFull.c_str());
+ this->InfoFileStream = new cmGeneratedFileStream(this->InfoFileNameFull);
this->InfoFileStream->SetCopyIfDifferent(true);
if (!*this->InfoFileStream) {
return;
@@ -998,12 +1048,10 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
<< "# Pairs of files generated by the same build rule.\n"
<< "set(CMAKE_MULTIPLE_OUTPUT_PAIRS\n";
/* clang-format on */
- for (MultipleOutputPairsType::const_iterator pi =
- this->MultipleOutputPairs.begin();
- pi != this->MultipleOutputPairs.end(); ++pi) {
+ for (auto const& pi : this->MultipleOutputPairs) {
*this->InfoFileStream
- << " " << cmOutputConverter::EscapeForCMake(pi->first) << " "
- << cmOutputConverter::EscapeForCMake(pi->second) << "\n";
+ << " " << cmOutputConverter::EscapeForCMake(pi.first) << " "
+ << cmOutputConverter::EscapeForCMake(pi.second) << "\n";
}
*this->InfoFileStream << " )\n\n";
}
@@ -1017,9 +1065,8 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
<< "set(CMAKE_TARGET_LINKED_INFO_FILES\n";
/* clang-format on */
std::vector<std::string> dirs = this->GetLinkedTargetDirectories();
- for (std::vector<std::string>::iterator i = dirs.begin(); i != dirs.end();
- ++i) {
- *this->InfoFileStream << " \"" << *i << "/DependInfo.cmake\"\n";
+ for (std::string const& d : dirs) {
+ *this->InfoFileStream << " \"" << d << "/DependInfo.cmake\"\n";
}
*this->InfoFileStream << " )\n";
}
@@ -1055,10 +1102,11 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
// 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->ConvertToOutputFormat(
- cmSystemTools::CollapseFullPath(
- this->LocalGenerator->GetBinaryDirectory()),
- cmOutputConverter::SHELL))
+ depCmd << "cd "
+ << (this->LocalGenerator->ConvertToOutputFormat(
+ cmSystemTools::CollapseFullPath(
+ this->LocalGenerator->GetBinaryDirectory()),
+ cmOutputConverter::SHELL))
<< " && ";
#endif
// Generate a call this signature:
@@ -1106,7 +1154,7 @@ void cmMakefileTargetGenerator::WriteTargetDependRules()
}
// Write the rule.
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
depTarget, depends, commands, true);
}
@@ -1117,13 +1165,11 @@ void cmMakefileTargetGenerator::DriveCustomCommands(
std::vector<cmSourceFile*> sources;
this->GeneratorTarget->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()) {
+ for (cmSourceFile* source : sources) {
+ if (cmCustomCommand* cc = source->GetCustomCommand()) {
cmCustomCommandGenerator ccg(*cc, this->ConfigName,
this->LocalGenerator);
- const std::vector<std::string>& outputs = ccg.GetOutputs();
- depends.insert(depends.end(), outputs.begin(), outputs.end());
+ cmAppend(depends, ccg.GetOutputs());
}
}
}
@@ -1169,8 +1215,8 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile(
// Write the rule.
const std::vector<std::string>& outputs = ccg.GetOutputs();
- bool symbolic = this->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
- outputs, depends, commands);
+ bool symbolic = this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs,
+ depends, commands);
// If the rule has changed make sure the output is rebuilt.
if (!symbolic) {
@@ -1178,14 +1224,11 @@ void cmMakefileTargetGenerator::GenerateCustomRuleFile(
}
// Setup implicit dependency scanning.
- for (cmCustomCommand::ImplicitDependsList::const_iterator idi =
- ccg.GetCC().GetImplicitDepends().begin();
- idi != ccg.GetCC().GetImplicitDepends().end(); ++idi) {
+ for (auto const& idi : ccg.GetCC().GetImplicitDepends()) {
std::string objFullPath = cmSystemTools::CollapseFullPath(outputs[0]);
- std::string srcFullPath = cmSystemTools::CollapseFullPath(idi->second);
- this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, idi->first,
- objFullPath.c_str(),
- srcFullPath.c_str());
+ std::string srcFullPath = cmSystemTools::CollapseFullPath(idi.second);
+ this->LocalGenerator->AddImplicitDepends(this->GeneratorTarget, idi.first,
+ objFullPath, srcFullPath);
}
}
@@ -1193,7 +1236,7 @@ void cmMakefileTargetGenerator::MakeEchoProgress(
cmLocalUnixMakefileGenerator3::EchoProgress& progress) const
{
progress.Dir = this->LocalGenerator->GetBinaryDirectory();
- progress.Dir += cmake::GetCMakeFilesDirectory();
+ progress.Dir += "/CMakeFiles";
std::ostringstream progressArg;
progressArg << "$(CMAKE_PROGRESS_" << this->NumberOfProgressActions << ")";
progress.Arg = progressArg.str();
@@ -1216,11 +1259,11 @@ void cmMakefileTargetGenerator::WriteObjectsVariable(
if (!lineContinue) {
lineContinue = "\\";
}
- for (std::vector<std::string>::const_iterator i = this->Objects.begin();
- i != this->Objects.end(); ++i) {
+ for (std::string const& obj : this->Objects) {
*this->BuildFileStream << " " << lineContinue << "\n";
- *this->BuildFileStream << this->LocalGenerator->ConvertToQuotedOutputPath(
- i->c_str(), useWatcomQuote);
+ *this->BuildFileStream
+ << cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(
+ obj, useWatcomQuote);
}
*this->BuildFileStream << "\n";
@@ -1237,14 +1280,13 @@ void cmMakefileTargetGenerator::WriteObjectsVariable(
/* clang-format on */
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
- for (std::vector<std::string>::const_iterator i =
- this->ExternalObjects.begin();
- i != this->ExternalObjects.end(); ++i) {
+ for (std::string const& obj : this->ExternalObjects) {
object =
- this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, *i);
+ this->LocalGenerator->MaybeConvertToRelativePath(currentBinDir, obj);
*this->BuildFileStream << " " << lineContinue << "\n";
- *this->BuildFileStream << this->LocalGenerator->ConvertToQuotedOutputPath(
- i->c_str(), useWatcomQuote);
+ *this->BuildFileStream
+ << cmLocalUnixMakefileGenerator3::ConvertToQuotedOutputPath(
+ obj, useWatcomQuote);
}
*this->BuildFileStream << "\n"
<< "\n";
@@ -1275,7 +1317,7 @@ public:
(this->CurrentString.length() + 1 + this->NextObject.length() >
this->LengthLimit)) {
this->Strings.push_back(this->CurrentString);
- this->CurrentString = "";
+ this->CurrentString.clear();
this->Space = "";
}
@@ -1291,11 +1333,10 @@ public:
private:
std::string MaybeConvertToRelativePath(std::string const& obj)
{
- if (!cmOutputConverter::ContainedInDirectory(
- this->StateDir.GetCurrentBinary(), obj, this->StateDir)) {
+ if (!this->StateDir.ContainsBoth(this->StateDir.GetCurrentBinary(), obj)) {
return obj;
}
- return cmOutputConverter::ForceToRelativePath(
+ return cmSystemTools::ForceToRelativePath(
this->StateDir.GetCurrentBinary(), obj);
}
@@ -1314,14 +1355,11 @@ void cmMakefileTargetGenerator::WriteObjectsStrings(
cmMakefileTargetGeneratorObjectStrings helper(
objStrings, this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory(), limit);
- for (std::vector<std::string>::const_iterator i = this->Objects.begin();
- i != this->Objects.end(); ++i) {
- helper.Feed(*i);
+ for (std::string const& obj : this->Objects) {
+ helper.Feed(obj);
}
- for (std::vector<std::string>::const_iterator i =
- this->ExternalObjects.begin();
- i != this->ExternalObjects.end(); ++i) {
- helper.Feed(*i);
+ for (std::string const& obj : this->ExternalObjects) {
+ helper.Feed(obj);
}
helper.Done();
}
@@ -1341,7 +1379,7 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(
std::vector<std::string> depends;
depends.push_back(main_output);
- const char* comment = CM_NULLPTR;
+ const char* comment = nullptr;
if (relink) {
// Setup the comment for the preinstall driver.
comment = "Rule to relink during preinstall.";
@@ -1355,8 +1393,7 @@ void cmMakefileTargetGenerator::WriteTargetDriverRule(
}
// Make sure the extra files are built.
- depends.insert(depends.end(), this->ExtraFiles.begin(),
- this->ExtraFiles.end());
+ cmAppend(depends, this->ExtraFiles);
}
// Write the driver rule.
@@ -1375,11 +1412,10 @@ void cmMakefileTargetGenerator::AppendTargetDepends(
}
// Loop over all library dependencies.
- const char* cfg = this->LocalGenerator->GetConfigName().c_str();
+ const std::string& cfg = this->LocalGenerator->GetConfigName();
if (cmComputeLinkInformation* cli =
this->GeneratorTarget->GetLinkInformation(cfg)) {
- std::vector<std::string> const& libDeps = cli->GetDepends();
- depends.insert(depends.end(), libDeps.begin(), libDeps.end());
+ cmAppend(depends, cli->GetDepends());
}
}
@@ -1387,18 +1423,16 @@ 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);
+ std::string const& relPath =
+ this->LocalGenerator->GetHomeRelativeOutputPath();
+ for (std::string const& obj : this->Objects) {
+ std::string objTarget = relPath;
+ objTarget += obj;
+ depends.push_back(std::move(objTarget));
}
// Add dependencies on the external object files.
- depends.insert(depends.end(), this->ExternalObjects.begin(),
- this->ExternalObjects.end());
+ cmAppend(depends, this->ExternalObjects);
// Add a dependency on the rule file itself.
this->LocalGenerator->AppendRuleDepend(depends,
@@ -1406,7 +1440,7 @@ void cmMakefileTargetGenerator::AppendObjectDepends(
}
void cmMakefileTargetGenerator::AppendLinkDepends(
- std::vector<std::string>& depends)
+ std::vector<std::string>& depends, const std::string& linkLanguage)
{
this->AppendObjectDepends(depends);
@@ -1417,33 +1451,28 @@ void cmMakefileTargetGenerator::AppendLinkDepends(
if (cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
this->GeneratorTarget->GetModuleDefinitionInfo(
this->GetConfigName())) {
- for (std::vector<cmSourceFile const*>::const_iterator i =
- mdi->Sources.begin();
- i != mdi->Sources.end(); ++i) {
- depends.push_back((*i)->GetFullPath());
+ for (cmSourceFile const* src : mdi->Sources) {
+ depends.push_back(src->GetFullPath());
}
}
// Add a dependency on user-specified manifest files, if any.
std::vector<cmSourceFile const*> manifest_srcs;
this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
- for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
- mi != manifest_srcs.end(); ++mi) {
- depends.push_back((*mi)->GetFullPath());
+ for (cmSourceFile const* manifest_src : manifest_srcs) {
+ depends.push_back(manifest_src->GetFullPath());
}
// Add user-specified dependencies.
- if (const char* linkDepends =
- this->GeneratorTarget->GetProperty("LINK_DEPENDS")) {
- cmSystemTools::ExpandListArgument(linkDepends, depends);
- }
+ this->GeneratorTarget->GetLinkDepends(depends, this->ConfigName,
+ linkLanguage);
}
std::string cmMakefileTargetGenerator::GetLinkRule(
const std::string& linkRuleVar)
{
std::string linkRule = this->Makefile->GetRequiredDefinition(linkRuleVar);
- if (this->GeneratorTarget->HasImplibGNUtoMS()) {
+ if (this->GeneratorTarget->HasImplibGNUtoMS(this->ConfigName)) {
std::string ruleVar = "CMAKE_";
ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
ruleVar += "_GNUtoMS_RULE";
@@ -1470,14 +1499,13 @@ void cmMakefileTargetGenerator::CreateLinkScript(
std::string linkScriptName = this->TargetBuildDirectoryFull;
linkScriptName += "/";
linkScriptName += name;
- cmGeneratedFileStream linkScriptStream(linkScriptName.c_str());
+ cmGeneratedFileStream linkScriptStream(linkScriptName);
linkScriptStream.SetCopyIfDifferent(true);
- for (std::vector<std::string>::const_iterator cmd = link_commands.begin();
- cmd != link_commands.end(); ++cmd) {
+ for (std::string const& link_command : link_commands) {
// Do not write out empty commands or commands beginning in the
// shell no-op ":".
- if (!cmd->empty() && (*cmd)[0] != ':') {
- linkScriptStream << *cmd << "\n";
+ if (!link_command.empty() && link_command[0] != ':') {
+ linkScriptStream << link_command << "\n";
}
}
@@ -1488,8 +1516,8 @@ void cmMakefileTargetGenerator::CreateLinkScript(
this->LocalGenerator->GetCurrentBinaryDirectory(), linkScriptName),
cmOutputConverter::SHELL);
link_command += " --verbose=$(VERBOSE)";
- makefile_commands.push_back(link_command);
- makefile_depends.push_back(linkScriptName);
+ makefile_commands.push_back(std::move(link_command));
+ makefile_depends.push_back(std::move(linkScriptName));
}
bool cmMakefileTargetGenerator::CheckUseResponseFileForObjects(
@@ -1512,14 +1540,11 @@ bool cmMakefileTargetGenerator::CheckUseResponseFileForObjects(
// actual list will likely be much shorter than this. However, in the
// worst case all objects will remain as absolute paths.
size_t length = 0;
- for (std::vector<std::string>::const_iterator i = this->Objects.begin();
- i != this->Objects.end(); ++i) {
- length += i->size() + 3;
+ for (std::string const& obj : this->Objects) {
+ length += obj.size() + 3;
}
- for (std::vector<std::string>::const_iterator i =
- this->ExternalObjects.begin();
- i != this->ExternalObjects.end(); ++i) {
- length += i->size() + 3;
+ for (std::string const& ext_obj : this->ExternalObjects) {
+ length += ext_obj.size() + 3;
}
// We need to guarantee room for both objects and libraries, so
@@ -1558,13 +1583,13 @@ std::string cmMakefileTargetGenerator::CreateResponseFile(
std::string responseFileNameFull = this->TargetBuildDirectoryFull;
responseFileNameFull += "/";
responseFileNameFull += name;
- cmGeneratedFileStream responseStream(responseFileNameFull.c_str());
+ cmGeneratedFileStream responseStream(responseFileNameFull);
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);
+ makefile_depends.push_back(std::move(responseFileNameFull));
// Construct the name to be used on the command line.
std::string responseFileName = this->TargetBuildDirectory;
@@ -1590,7 +1615,8 @@ void cmMakefileTargetGenerator::CreateLinkLibs(
{
std::string frameworkPath;
std::string linkPath;
- std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ const std::string& config =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
cmComputeLinkInformation* pcli =
this->GeneratorTarget->GetLinkInformation(config);
this->LocalGenerator->OutputLinkLibraries(pcli, linkLineComputer, linkLibs,
@@ -1703,10 +1729,17 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags,
}
if (useResponseFile) {
+ std::string const responseFlagVar =
+ "CMAKE_" + lang + "_RESPONSE_FILE_FLAG";
+ std::string responseFlag =
+ this->Makefile->GetSafeDefinition(responseFlagVar);
+ if (responseFlag.empty()) {
+ responseFlag = "@";
+ }
std::string name = "includes_";
name += lang;
name += ".rsp";
- std::string arg = "@" +
+ std::string arg = std::move(responseFlag) +
this->CreateResponseFile(name.c_str(), includeFlags,
this->FlagFileDepends[lang]);
this->LocalGenerator->AppendFlags(flags, arg);
@@ -1739,25 +1772,20 @@ void cmMakefileTargetGenerator::GenDefFile(
cmOutputConverter::SHELL);
real_link_commands.insert(real_link_commands.begin(), cmd);
// create a list of obj files for the -E __create_def to read
- cmGeneratedFileStream fout(objlist_file.c_str());
+ cmGeneratedFileStream fout(objlist_file);
if (mdi->WindowsExportAllSymbols) {
- for (std::vector<std::string>::const_iterator i = this->Objects.begin();
- i != this->Objects.end(); ++i) {
- if (cmHasLiteralSuffix(*i, ".obj")) {
- fout << *i << "\n";
+ for (std::string const& obj : this->Objects) {
+ if (cmHasLiteralSuffix(obj, ".obj")) {
+ fout << obj << "\n";
}
}
- for (std::vector<std::string>::const_iterator i =
- this->ExternalObjects.begin();
- i != this->ExternalObjects.end(); ++i) {
- fout << *i << "\n";
+ for (std::string const& obj : this->ExternalObjects) {
+ fout << obj << "\n";
}
}
- for (std::vector<cmSourceFile const*>::const_iterator i =
- mdi->Sources.begin();
- i != mdi->Sources.end(); ++i) {
- fout << (*i)->GetFullPath() << "\n";
+ for (cmSourceFile const* src : mdi->Sources) {
+ fout << src->GetFullPath() << "\n";
}
}
diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h
index 92c9f60b0..c570a7ccf 100644
--- a/Source/cmMakefileTargetGenerator.h
+++ b/Source/cmMakefileTargetGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmMakefileTargetGenerator_h
#define cmMakefileTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
@@ -12,12 +12,12 @@
#include <vector>
#include "cmCommonTargetGenerator.h"
+#include "cmGeneratorTarget.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmOSXBundleGenerator.h"
class cmCustomCommandGenerator;
class cmGeneratedFileStream;
-class cmGeneratorTarget;
class cmGlobalUnixMakefileGenerator3;
class cmLinkLineComputer;
class cmOutputConverter;
@@ -33,7 +33,7 @@ class cmMakefileTargetGenerator : public cmCommonTargetGenerator
public:
// constructor to set the ivars
cmMakefileTargetGenerator(cmGeneratorTarget* target);
- ~cmMakefileTargetGenerator() CM_OVERRIDE;
+ ~cmMakefileTargetGenerator() override;
// construct using this factory call
static cmMakefileTargetGenerator* New(cmGeneratorTarget* tgt);
@@ -52,6 +52,8 @@ public:
cmGeneratorTarget* GetGeneratorTarget() { return this->GeneratorTarget; }
protected:
+ void GetTargetLinkFlags(std::string& flags, const std::string& linkLanguage);
+
// create the file and directory etc
void CreateRuleFile();
@@ -63,16 +65,13 @@ protected:
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.
+ // write rules for macOS Application Bundle content.
struct MacOSXContentGeneratorType
: cmOSXBundleGenerator::MacOSXContentGeneratorType
{
@@ -81,8 +80,7 @@ protected:
{
}
- void operator()(cmSourceFile const& source,
- const char* pkgloc) CM_OVERRIDE;
+ void operator()(cmSourceFile const& source, const char* pkgloc) override;
private:
cmMakefileTargetGenerator* Generator;
@@ -130,7 +128,8 @@ protected:
void AppendObjectDepends(std::vector<std::string>& depends);
// Append link rule dependencies (objects, etc.).
- void AppendLinkDepends(std::vector<std::string>& depends);
+ void AppendLinkDepends(std::vector<std::string>& depends,
+ const std::string& linkLanguage);
// Lookup the link rule for this target.
std::string GetLinkRule(const std::string& linkRuleVar);
@@ -168,8 +167,7 @@ protected:
/** Add commands for generate def files */
void GenDefFile(std::vector<std::string>& real_link_commands);
- void AddIncludeFlags(std::string& flags,
- const std::string& lang) CM_OVERRIDE;
+ void AddIncludeFlags(std::string& flags, const std::string& lang) override;
virtual void CloseFileStreams();
cmLocalUnixMakefileGenerator3* LocalGenerator;
@@ -212,7 +210,7 @@ protected:
cmGeneratedFileStream* InfoFileStream;
// files to clean
- std::vector<std::string> CleanFiles;
+ std::set<std::string> CleanFiles;
// objects used by this target
std::vector<std::string> Objects;
@@ -233,15 +231,11 @@ protected:
bool in_help = false);
// Target name info.
- std::string TargetNameOut;
- std::string TargetNameSO;
- std::string TargetNameReal;
- std::string TargetNameImport;
- std::string TargetNamePDB;
+ cmGeneratorTarget::Names TargetNames;
- // Mac OS X content info.
+ // macOS content info.
std::set<std::string> MacContentFolders;
- cmOSXBundleGenerator* OSXBundleGenerator;
+ std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator;
MacOSXContentGeneratorType* MacOSXContentGenerator;
};
diff --git a/Source/cmMakefileUtilityTargetGenerator.cxx b/Source/cmMakefileUtilityTargetGenerator.cxx
index a7c5d27f2..42369954c 100644
--- a/Source/cmMakefileUtilityTargetGenerator.cxx
+++ b/Source/cmMakefileUtilityTargetGenerator.cxx
@@ -4,8 +4,10 @@
#include <ostream>
#include <string>
+#include <utility>
#include <vector>
+#include "cmAlgorithms.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalUnixMakefileGenerator3.h"
@@ -20,14 +22,12 @@ cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator(
{
this->CustomCommandDriver = OnUtility;
this->OSXBundleGenerator =
- new cmOSXBundleGenerator(target, this->ConfigName);
+ cm::make_unique<cmOSXBundleGenerator>(target, this->ConfigName);
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
-cmMakefileUtilityTargetGenerator::~cmMakefileUtilityTargetGenerator()
-{
- delete this->OSXBundleGenerator;
-}
+cmMakefileUtilityTargetGenerator::~cmMakefileUtilityTargetGenerator() =
+ default;
void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
{
@@ -45,11 +45,9 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
<< "# Include the progress variables for this target.\n"
<< this->GlobalGenerator->IncludeDirective << " " << root
<< cmSystemTools::ConvertToOutputPath(
- this->LocalGenerator
- ->MaybeConvertToRelativePath(
- this->LocalGenerator->GetBinaryDirectory(),
- this->ProgressFileNameFull)
- .c_str())
+ this->LocalGenerator->MaybeConvertToRelativePath(
+ this->LocalGenerator->GetBinaryDirectory(),
+ this->ProgressFileNameFull))
<< "\n\n";
}
@@ -90,12 +88,12 @@ void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
if (depends.empty() && commands.empty()) {
std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
if (!hack.empty()) {
- depends.push_back(hack);
+ depends.push_back(std::move(hack));
}
}
// Write the rule.
- this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
+ this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
this->GeneratorTarget->GetName(),
depends, commands, true);
diff --git a/Source/cmMakefileUtilityTargetGenerator.h b/Source/cmMakefileUtilityTargetGenerator.h
index 8df5dd46f..be243a7f5 100644
--- a/Source/cmMakefileUtilityTargetGenerator.h
+++ b/Source/cmMakefileUtilityTargetGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmMakefileUtilityTargetGenerator_h
#define cmMakefileUtilityTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmMakefileTargetGenerator.h"
@@ -13,11 +13,11 @@ class cmMakefileUtilityTargetGenerator : public cmMakefileTargetGenerator
{
public:
cmMakefileUtilityTargetGenerator(cmGeneratorTarget* target);
- ~cmMakefileUtilityTargetGenerator() CM_OVERRIDE;
+ ~cmMakefileUtilityTargetGenerator() override;
/* the main entry point for this class. Writes the Makefiles associated
with this target */
- void WriteRuleFiles() CM_OVERRIDE;
+ void WriteRuleFiles() override;
protected:
};
diff --git a/Source/cmMarkAsAdvancedCommand.cxx b/Source/cmMarkAsAdvancedCommand.cxx
index 14fd96f08..45c59b999 100644
--- a/Source/cmMarkAsAdvancedCommand.cxx
+++ b/Source/cmMarkAsAdvancedCommand.cxx
@@ -34,7 +34,7 @@ bool cmMarkAsAdvancedCommand::InitialPass(std::vector<std::string> const& args,
cmState* state = this->Makefile->GetState();
if (!state->GetCacheEntryValue(variable)) {
this->Makefile->GetCMakeInstance()->AddCacheEntry(
- variable, CM_NULLPTR, CM_NULLPTR, cmStateEnums::UNINITIALIZED);
+ variable, nullptr, nullptr, cmStateEnums::UNINITIALIZED);
overwrite = true;
}
if (!state->GetCacheEntryValue(variable)) {
diff --git a/Source/cmMarkAsAdvancedCommand.h b/Source/cmMarkAsAdvancedCommand.h
index a7791a932..5dd198f62 100644
--- a/Source/cmMarkAsAdvancedCommand.h
+++ b/Source/cmMarkAsAdvancedCommand.h
@@ -3,7 +3,7 @@
#ifndef cmMarkAsAdvancedCommand_h
#define cmMarkAsAdvancedCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmMarkAsAdvancedCommand; }
+ cmCommand* Clone() override { return new cmMarkAsAdvancedCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmMathCommand.cxx b/Source/cmMathCommand.cxx
index c1cd1b6c2..48b9a27ad 100644
--- a/Source/cmMathCommand.cxx
+++ b/Source/cmMathCommand.cxx
@@ -2,10 +2,12 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmMathCommand.h"
-#include <stdio.h>
-
#include "cmExprParserHelper.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cm_kwiml.h"
+
+#include <stdio.h>
class cmExecutionStatus;
@@ -27,24 +29,83 @@ bool cmMathCommand::InitialPass(std::vector<std::string> const& args,
bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args)
{
- if (args.size() != 3) {
+ if ((args.size() != 3) && (args.size() != 5)) {
this->SetError("EXPR called with incorrect arguments.");
return false;
}
+ enum class NumericFormat
+ {
+ UNINITIALIZED,
+ DECIMAL,
+ HEXADECIMAL,
+ };
+
const std::string& outputVariable = args[1];
const std::string& expression = args[2];
+ size_t argumentIndex = 3;
+ NumericFormat outputFormat = NumericFormat::UNINITIALIZED;
+
+ this->Makefile->AddDefinition(outputVariable, "ERROR");
+
+ if (argumentIndex < args.size()) {
+ const std::string messageHint = "sub-command EXPR ";
+ const std::string option = args[argumentIndex++];
+ if (option == "OUTPUT_FORMAT") {
+ if (argumentIndex < args.size()) {
+ const std::string argument = args[argumentIndex++];
+ if (argument == "DECIMAL") {
+ outputFormat = NumericFormat::DECIMAL;
+ } else if (argument == "HEXADECIMAL") {
+ outputFormat = NumericFormat::HEXADECIMAL;
+ } else {
+ std::string error = messageHint + "value \"" + argument +
+ "\" for option \"" + option + "\" is invalid.";
+ this->SetError(error);
+ return false;
+ }
+ } else {
+ std::string error =
+ messageHint + "missing argument for option \"" + option + "\".";
+ this->SetError(error);
+ return false;
+ }
+ } else {
+ std::string error =
+ messageHint + "option \"" + option + "\" is unknown.";
+ this->SetError(error);
+ return false;
+ }
+ }
+
+ if (outputFormat == NumericFormat::UNINITIALIZED) {
+ outputFormat = NumericFormat::DECIMAL;
+ }
cmExprParserHelper helper;
if (!helper.ParseString(expression.c_str(), 0)) {
- std::string e = "cannot parse the expression: \"" + expression + "\": ";
- e += helper.GetError();
- this->SetError(e);
+ this->SetError(helper.GetError());
return false;
}
char buffer[1024];
- sprintf(buffer, "%d", helper.GetResult());
+ const char* fmt;
+ switch (outputFormat) {
+ case NumericFormat::HEXADECIMAL:
+ fmt = "0x%" KWIML_INT_PRIx64;
+ break;
+ case NumericFormat::DECIMAL:
+ CM_FALLTHROUGH;
+ default:
+ fmt = "%" KWIML_INT_PRId64;
+ break;
+ }
+ sprintf(buffer, fmt, helper.GetResult());
+
+ std::string const& w = helper.GetWarning();
+ if (!w.empty()) {
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w);
+ }
this->Makefile->AddDefinition(outputVariable, buffer);
return true;
diff --git a/Source/cmMathCommand.h b/Source/cmMathCommand.h
index 67dbdda37..0c6c76bb1 100644
--- a/Source/cmMathCommand.h
+++ b/Source/cmMathCommand.h
@@ -3,7 +3,7 @@
#ifndef cmMathCommand_h
#define cmMathCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -19,14 +19,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmMathCommand; }
+ cmCommand* Clone() override { return new cmMathCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
bool HandleExprCommand(std::vector<std::string> const& args);
diff --git a/Source/cmMessageCommand.cxx b/Source/cmMessageCommand.cxx
index 43fb5f54c..5320ec570 100644
--- a/Source/cmMessageCommand.cxx
+++ b/Source/cmMessageCommand.cxx
@@ -4,10 +4,14 @@
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmMessenger.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
#include "cmake.h"
+#include <cassert>
+
class cmExecutionStatus;
// cmLibraryCommand
@@ -18,59 +22,98 @@ bool cmMessageCommand::InitialPass(std::vector<std::string> const& args,
this->SetError("called with incorrect number of arguments");
return false;
}
- std::vector<std::string>::const_iterator i = args.begin();
+ auto i = args.cbegin();
- cmake::MessageType type = cmake::MESSAGE;
- bool status = false;
- bool fatal = false;
+ auto type = MessageType::MESSAGE;
+ auto status = false;
+ auto fatal = false;
+ auto level = cmake::LogLevel::LOG_UNDEFINED;
if (*i == "SEND_ERROR") {
- type = cmake::FATAL_ERROR;
+ type = MessageType::FATAL_ERROR;
+ level = cmake::LogLevel::LOG_ERROR;
++i;
} else if (*i == "FATAL_ERROR") {
fatal = true;
- type = cmake::FATAL_ERROR;
+ type = MessageType::FATAL_ERROR;
+ level = cmake::LogLevel::LOG_ERROR;
++i;
} else if (*i == "WARNING") {
- type = cmake::WARNING;
+ type = MessageType::WARNING;
+ level = cmake::LogLevel::LOG_WARNING;
++i;
} else if (*i == "AUTHOR_WARNING") {
if (this->Makefile->IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") &&
!this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS")) {
fatal = true;
- type = cmake::AUTHOR_ERROR;
+ type = MessageType::AUTHOR_ERROR;
+ level = cmake::LogLevel::LOG_ERROR;
} else if (!this->Makefile->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) {
- type = cmake::AUTHOR_WARNING;
+ type = MessageType::AUTHOR_WARNING;
+ level = cmake::LogLevel::LOG_WARNING;
} else {
return true;
}
++i;
} else if (*i == "STATUS") {
status = true;
+ level = cmake::LogLevel::LOG_STATUS;
+ ++i;
+ } else if (*i == "VERBOSE") {
+ status = true;
+ level = cmake::LogLevel::LOG_VERBOSE;
+ ++i;
+ } else if (*i == "DEBUG") {
+ status = true;
+ level = cmake::LogLevel::LOG_DEBUG;
+ ++i;
+ } else if (*i == "TRACE") {
+ status = true;
+ level = cmake::LogLevel::LOG_TRACE;
++i;
} else if (*i == "DEPRECATION") {
if (this->Makefile->IsOn("CMAKE_ERROR_DEPRECATED")) {
fatal = true;
- type = cmake::DEPRECATION_ERROR;
+ type = MessageType::DEPRECATION_ERROR;
+ level = cmake::LogLevel::LOG_ERROR;
} else if ((!this->Makefile->IsSet("CMAKE_WARN_DEPRECATED") ||
this->Makefile->IsOn("CMAKE_WARN_DEPRECATED"))) {
- type = cmake::DEPRECATION_WARNING;
+ type = MessageType::DEPRECATION_WARNING;
+ level = cmake::LogLevel::LOG_WARNING;
} else {
return true;
}
++i;
+ } else if (*i == "NOTICE") {
+ // `NOTICE` message type is going to be output to stderr
+ level = cmake::LogLevel::LOG_NOTICE;
+ ++i;
+ } else {
+ // Messages w/o any type are `NOTICE`s
+ level = cmake::LogLevel::LOG_NOTICE;
+ }
+ assert("Message log level expected to be set" &&
+ level != cmake::LogLevel::LOG_UNDEFINED);
+
+ auto desiredLevel = this->Makefile->GetCMakeInstance()->GetLogLevel();
+ assert("Expected a valid log level here" &&
+ desiredLevel != cmake::LogLevel::LOG_UNDEFINED);
+
+ if (desiredLevel < level) {
+ // Suppress the message
+ return true;
}
- std::string message = cmJoin(cmMakeRange(i, args.end()), std::string());
+ auto message = cmJoin(cmMakeRange(i, args.cend()), "");
- if (type != cmake::MESSAGE) {
- // we've overriden the message type, above, so display it directly
+ if (type != MessageType::MESSAGE) {
+ // we've overridden the message type, above, so display it directly
cmMessenger* m = this->Makefile->GetMessenger();
m->DisplayMessage(type, message, this->Makefile->GetBacktrace());
} else {
if (status) {
- this->Makefile->DisplayStatus(message.c_str(), -1);
+ this->Makefile->DisplayStatus(message, -1);
} else {
- cmSystemTools::Message(message.c_str());
+ cmSystemTools::Message(message);
}
}
if (fatal) {
diff --git a/Source/cmMessageCommand.h b/Source/cmMessageCommand.h
index 96939e514..819ebdacf 100644
--- a/Source/cmMessageCommand.h
+++ b/Source/cmMessageCommand.h
@@ -3,7 +3,7 @@
#ifndef cmMessageCommand_h
#define cmMessageCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -22,14 +22,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmMessageCommand; }
+ cmCommand* Clone() override { return new cmMessageCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx
index 3ae5bc5c2..1d790e2e8 100644
--- a/Source/cmMessenger.cxx
+++ b/Source/cmMessenger.cxx
@@ -4,56 +4,55 @@
#include "cmAlgorithms.h"
#include "cmDocumentationFormatter.h"
-#include "cmState.h"
#include "cmSystemTools.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmsys/SystemInformation.hxx"
+# include "cmsys/SystemInformation.hxx"
#endif
#include <sstream>
-cmake::MessageType cmMessenger::ConvertMessageType(cmake::MessageType t) const
+MessageType cmMessenger::ConvertMessageType(MessageType t) const
{
bool warningsAsErrors;
- if (t == cmake::AUTHOR_WARNING || t == cmake::AUTHOR_ERROR) {
+ if (t == MessageType::AUTHOR_WARNING || t == MessageType::AUTHOR_ERROR) {
warningsAsErrors = this->GetDevWarningsAsErrors();
- if (warningsAsErrors && t == cmake::AUTHOR_WARNING) {
- t = cmake::AUTHOR_ERROR;
- } else if (!warningsAsErrors && t == cmake::AUTHOR_ERROR) {
- t = cmake::AUTHOR_WARNING;
+ if (warningsAsErrors && t == MessageType::AUTHOR_WARNING) {
+ t = MessageType::AUTHOR_ERROR;
+ } else if (!warningsAsErrors && t == MessageType::AUTHOR_ERROR) {
+ t = MessageType::AUTHOR_WARNING;
}
- } else if (t == cmake::DEPRECATION_WARNING ||
- t == cmake::DEPRECATION_ERROR) {
+ } else if (t == MessageType::DEPRECATION_WARNING ||
+ t == MessageType::DEPRECATION_ERROR) {
warningsAsErrors = this->GetDeprecatedWarningsAsErrors();
- if (warningsAsErrors && t == cmake::DEPRECATION_WARNING) {
- t = cmake::DEPRECATION_ERROR;
- } else if (!warningsAsErrors && t == cmake::DEPRECATION_ERROR) {
- t = cmake::DEPRECATION_WARNING;
+ if (warningsAsErrors && t == MessageType::DEPRECATION_WARNING) {
+ t = MessageType::DEPRECATION_ERROR;
+ } else if (!warningsAsErrors && t == MessageType::DEPRECATION_ERROR) {
+ t = MessageType::DEPRECATION_WARNING;
}
}
return t;
}
-bool cmMessenger::IsMessageTypeVisible(cmake::MessageType t) const
+bool cmMessenger::IsMessageTypeVisible(MessageType t) const
{
bool isVisible = true;
- if (t == cmake::DEPRECATION_ERROR) {
+ if (t == MessageType::DEPRECATION_ERROR) {
if (!this->GetDeprecatedWarningsAsErrors()) {
isVisible = false;
}
- } else if (t == cmake::DEPRECATION_WARNING) {
+ } else if (t == MessageType::DEPRECATION_WARNING) {
if (this->GetSuppressDeprecatedWarnings()) {
isVisible = false;
}
- } else if (t == cmake::AUTHOR_ERROR) {
+ } else if (t == MessageType::AUTHOR_ERROR) {
if (!this->GetDevWarningsAsErrors()) {
isVisible = false;
}
- } else if (t == cmake::AUTHOR_WARNING) {
+ } else if (t == MessageType::AUTHOR_WARNING) {
if (this->GetSuppressDevWarnings()) {
isVisible = false;
}
@@ -62,22 +61,22 @@ bool cmMessenger::IsMessageTypeVisible(cmake::MessageType t) const
return isVisible;
}
-static bool printMessagePreamble(cmake::MessageType t, std::ostream& msg)
+static bool printMessagePreamble(MessageType t, std::ostream& msg)
{
// Construct the message header.
- if (t == cmake::FATAL_ERROR) {
+ if (t == MessageType::FATAL_ERROR) {
msg << "CMake Error";
- } else if (t == cmake::INTERNAL_ERROR) {
+ } else if (t == MessageType::INTERNAL_ERROR) {
msg << "CMake Internal Error (please report a bug)";
- } else if (t == cmake::LOG) {
+ } else if (t == MessageType::LOG) {
msg << "CMake Debug Log";
- } else if (t == cmake::DEPRECATION_ERROR) {
+ } else if (t == MessageType::DEPRECATION_ERROR) {
msg << "CMake Deprecation Error";
- } else if (t == cmake::DEPRECATION_WARNING) {
+ } else if (t == MessageType::DEPRECATION_WARNING) {
msg << "CMake Deprecation Warning";
- } else if (t == cmake::AUTHOR_WARNING) {
+ } else if (t == MessageType::AUTHOR_WARNING) {
msg << "CMake Warning (dev)";
- } else if (t == cmake::AUTHOR_ERROR) {
+ } else if (t == MessageType::AUTHOR_ERROR) {
msg << "CMake Error (dev)";
} else {
msg << "CMake Warning";
@@ -93,13 +92,13 @@ void printMessageText(std::ostream& msg, std::string const& text)
formatter.PrintFormatted(msg, text.c_str());
}
-void displayMessage(cmake::MessageType t, std::ostringstream& msg)
+void displayMessage(MessageType t, std::ostringstream& msg)
{
// Add a note about warning suppression.
- if (t == cmake::AUTHOR_WARNING) {
+ if (t == MessageType::AUTHOR_WARNING) {
msg << "This warning is for project developers. Use -Wno-dev to suppress "
"it.";
- } else if (t == cmake::AUTHOR_ERROR) {
+ } else if (t == MessageType::AUTHOR_ERROR) {
msg << "This error is for project developers. Use -Wno-error=dev to "
"suppress "
"it.";
@@ -110,7 +109,7 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
#if defined(CMAKE_BUILD_WITH_CMAKE)
// Add a C++ stack trace to internal errors.
- if (t == cmake::INTERNAL_ERROR) {
+ if (t == MessageType::INTERNAL_ERROR) {
std::string stack = cmsys::SystemInformation::GetProgramStack(0, 0);
if (!stack.empty()) {
if (cmHasLiteralPrefix(stack, "WARNING:")) {
@@ -122,27 +121,22 @@ void displayMessage(cmake::MessageType t, std::ostringstream& msg)
#endif
// Output the message.
- if (t == cmake::FATAL_ERROR || t == cmake::INTERNAL_ERROR ||
- t == cmake::DEPRECATION_ERROR || t == cmake::AUTHOR_ERROR) {
+ if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR ||
+ t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) {
cmSystemTools::SetErrorOccured();
- cmSystemTools::Message(msg.str().c_str(), "Error");
+ cmSystemTools::Message(msg.str(), "Error");
} else {
- cmSystemTools::Message(msg.str().c_str(), "Warning");
+ cmSystemTools::Message(msg.str(), "Warning");
}
}
-cmMessenger::cmMessenger(cmState* state)
- : State(state)
-{
-}
-
-void cmMessenger::IssueMessage(cmake::MessageType t, const std::string& text,
+void cmMessenger::IssueMessage(MessageType t, const std::string& text,
const cmListFileBacktrace& backtrace) const
{
bool force = false;
if (!force) {
// override the message type, if needed, for warnings and errors
- cmake::MessageType override = this->ConvertMessageType(t);
+ MessageType override = this->ConvertMessageType(t);
if (override != t) {
t = override;
force = true;
@@ -155,7 +149,7 @@ void cmMessenger::IssueMessage(cmake::MessageType t, const std::string& text,
this->DisplayMessage(t, text, backtrace);
}
-void cmMessenger::DisplayMessage(cmake::MessageType t, const std::string& text,
+void cmMessenger::DisplayMessage(MessageType t, const std::string& text,
const cmListFileBacktrace& backtrace) const
{
std::ostringstream msg;
@@ -173,31 +167,3 @@ void cmMessenger::DisplayMessage(cmake::MessageType t, const std::string& text,
displayMessage(t, msg);
}
-
-bool cmMessenger::GetSuppressDevWarnings() const
-{
- const char* cacheEntryValue =
- this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
- return cmSystemTools::IsOn(cacheEntryValue);
-}
-
-bool cmMessenger::GetSuppressDeprecatedWarnings() const
-{
- const char* cacheEntryValue =
- this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
- return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
-}
-
-bool cmMessenger::GetDevWarningsAsErrors() const
-{
- const char* cacheEntryValue =
- this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS");
- return cacheEntryValue && cmSystemTools::IsOff(cacheEntryValue);
-}
-
-bool cmMessenger::GetDeprecatedWarningsAsErrors() const
-{
- const char* cacheEntryValue =
- this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
- return cmSystemTools::IsOn(cacheEntryValue);
-}
diff --git a/Source/cmMessenger.h b/Source/cmMessenger.h
index 4aafbd40b..cf15adfc1 100644
--- a/Source/cmMessenger.h
+++ b/Source/cmMessenger.h
@@ -6,34 +6,56 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include "cmListFileCache.h"
-#include "cmake.h"
+#include "cmMessageType.h"
#include <string>
-class cmState;
-
class cmMessenger
{
public:
- cmMessenger(cmState* state);
-
void IssueMessage(
- cmake::MessageType t, std::string const& text,
+ MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
- void DisplayMessage(cmake::MessageType t, std::string const& text,
+ void DisplayMessage(MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace) const;
- bool GetSuppressDevWarnings() const;
- bool GetSuppressDeprecatedWarnings() const;
- bool GetDevWarningsAsErrors() const;
- bool GetDeprecatedWarningsAsErrors() const;
+ void SetSuppressDevWarnings(bool suppress)
+ {
+ this->SuppressDevWarnings = suppress;
+ }
+ void SetSuppressDeprecatedWarnings(bool suppress)
+ {
+ this->SuppressDeprecatedWarnings = suppress;
+ }
+ void SetDevWarningsAsErrors(bool error)
+ {
+ this->DevWarningsAsErrors = error;
+ }
+ void SetDeprecatedWarningsAsErrors(bool error)
+ {
+ this->DeprecatedWarningsAsErrors = error;
+ }
+
+ bool GetSuppressDevWarnings() const { return this->SuppressDevWarnings; }
+ bool GetSuppressDeprecatedWarnings() const
+ {
+ return this->SuppressDeprecatedWarnings;
+ }
+ bool GetDevWarningsAsErrors() const { return this->DevWarningsAsErrors; }
+ bool GetDeprecatedWarningsAsErrors() const
+ {
+ return this->DeprecatedWarningsAsErrors;
+ }
private:
- bool IsMessageTypeVisible(cmake::MessageType t) const;
- cmake::MessageType ConvertMessageType(cmake::MessageType t) const;
+ bool IsMessageTypeVisible(MessageType t) const;
+ MessageType ConvertMessageType(MessageType t) const;
- cmState* State;
+ bool SuppressDevWarnings = false;
+ bool SuppressDeprecatedWarnings = false;
+ bool DevWarningsAsErrors = false;
+ bool DeprecatedWarningsAsErrors = false;
};
#endif
diff --git a/Source/cmNewLineStyle.cxx b/Source/cmNewLineStyle.cxx
index 5500eba65..3f6523e09 100644
--- a/Source/cmNewLineStyle.cxx
+++ b/Source/cmNewLineStyle.cxx
@@ -4,10 +4,7 @@
#include <stddef.h>
-cmNewLineStyle::cmNewLineStyle()
- : NewLineStyle(Invalid)
-{
-}
+cmNewLineStyle::cmNewLineStyle() = default;
bool cmNewLineStyle::IsValid() const
{
diff --git a/Source/cmNewLineStyle.h b/Source/cmNewLineStyle.h
index 397cd2c50..f1a7bc6e0 100644
--- a/Source/cmNewLineStyle.h
+++ b/Source/cmNewLineStyle.h
@@ -33,7 +33,7 @@ public:
const std::string GetCharacters() const;
private:
- Style NewLineStyle;
+ Style NewLineStyle = Invalid;
};
#endif
diff --git a/Source/cmNinjaLinkLineComputer.h b/Source/cmNinjaLinkLineComputer.h
index 13f05a838..b2b2e84e1 100644
--- a/Source/cmNinjaLinkLineComputer.h
+++ b/Source/cmNinjaLinkLineComputer.h
@@ -4,7 +4,7 @@
#ifndef cmNinjaLinkLineComputer_h
#define cmNinjaLinkLineComputer_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
@@ -16,15 +16,15 @@ class cmStateDirectory;
class cmNinjaLinkLineComputer : public cmLinkLineComputer
{
- CM_DISABLE_COPY(cmNinjaLinkLineComputer)
-
public:
cmNinjaLinkLineComputer(cmOutputConverter* outputConverter,
cmStateDirectory const& stateDir,
cmGlobalNinjaGenerator const* gg);
- std::string ConvertToLinkReference(std::string const& input) const
- CM_OVERRIDE;
+ cmNinjaLinkLineComputer(cmNinjaLinkLineComputer const&) = delete;
+ cmNinjaLinkLineComputer& operator=(cmNinjaLinkLineComputer const&) = delete;
+
+ std::string ConvertToLinkReference(std::string const& input) const override;
private:
cmGlobalNinjaGenerator const* GG;
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index 14a4ef824..b7b822ab1 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -6,11 +6,13 @@
#include <assert.h>
#include <iterator>
#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <sstream>
+#include <utility>
#include "cmAlgorithms.h"
-#include "cmCustomCommand.h"
+#include "cmCustomCommand.h" // IWYU pragma: keep
#include "cmCustomCommandGenerator.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
@@ -20,6 +22,7 @@
#include "cmLocalGenerator.h"
#include "cmLocalNinjaGenerator.h"
#include "cmMakefile.h"
+#include "cmNinjaLinkLineDeviceComputer.h"
#include "cmNinjaTypes.h"
#include "cmOSXBundleGenerator.h"
#include "cmOutputConverter.h"
@@ -30,29 +33,18 @@
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
cmGeneratorTarget* target)
: cmNinjaTargetGenerator(target)
- , TargetNameOut()
- , TargetNameSO()
- , TargetNameReal()
- , TargetNameImport()
- , TargetNamePDB()
, TargetLinkLanguage("")
- , DeviceLinkObject()
{
this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName());
if (target->GetType() == cmStateEnums::EXECUTABLE) {
- this->GetGeneratorTarget()->GetExecutableNames(
- this->TargetNameOut, this->TargetNameReal, this->TargetNameImport,
- this->TargetNamePDB, GetLocalGenerator()->GetConfigName());
+ this->TargetNames = this->GetGeneratorTarget()->GetExecutableNames(
+ GetLocalGenerator()->GetConfigName());
} else {
- this->GetGeneratorTarget()->GetLibraryNames(
- this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
- this->TargetNameImport, this->TargetNamePDB,
+ this->TargetNames = this->GetGeneratorTarget()->GetLibraryNames(
GetLocalGenerator()->GetConfigName());
}
@@ -63,21 +55,18 @@ cmNinjaNormalTargetGenerator::cmNinjaNormalTargetGenerator(
}
this->OSXBundleGenerator =
- new cmOSXBundleGenerator(target, this->GetConfigName());
+ cm::make_unique<cmOSXBundleGenerator>(target, this->GetConfigName());
this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
}
-cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator()
-{
- delete this->OSXBundleGenerator;
-}
+cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() = default;
void cmNinjaNormalTargetGenerator::Generate()
{
if (this->TargetLinkLanguage.empty()) {
cmSystemTools::Error("CMake can not determine linker language for "
- "target: ",
- this->GetGeneratorTarget()->GetName().c_str());
+ "target: " +
+ this->GetGeneratorTarget()->GetName());
return;
}
@@ -95,6 +84,9 @@ void cmNinjaNormalTargetGenerator::Generate()
this->WriteDeviceLinkStatement();
this->WriteLinkStatement();
}
+
+ // Find ADDITIONAL_CLEAN_FILES
+ this->AdditionalCleanFiles();
}
void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
@@ -112,17 +104,14 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
std::vector<cmSourceFile const*> sourceFiles;
this->GetGeneratorTarget()->GetObjectSources(
sourceFiles, this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
- for (std::vector<cmSourceFile const*>::const_iterator i =
- sourceFiles.begin();
- i != sourceFiles.end(); ++i) {
- const std::string& lang = (*i)->GetLanguage();
+ for (cmSourceFile const* sf : sourceFiles) {
+ std::string const lang = sf->GetLanguage();
if (!lang.empty()) {
languages.insert(lang);
}
}
- for (std::set<std::string>::const_iterator l = languages.begin();
- l != languages.end(); ++l) {
- this->WriteLanguageRules(*l);
+ for (std::string const& language : languages) {
+ this->WriteLanguageRules(language);
}
}
@@ -142,7 +131,7 @@ const char* cmNinjaNormalTargetGenerator::GetVisibleTypeName() const
case cmStateEnums::EXECUTABLE:
return "executable";
default:
- return CM_NULLPTR;
+ return nullptr;
}
}
@@ -150,16 +139,18 @@ std::string cmNinjaNormalTargetGenerator::LanguageLinkerRule() const
{
return this->TargetLinkLanguage + "_" +
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) +
- "_LINKER__" + cmGlobalNinjaGenerator::EncodeRuleName(
- this->GetGeneratorTarget()->GetName());
+ "_LINKER__" +
+ cmGlobalNinjaGenerator::EncodeRuleName(
+ this->GetGeneratorTarget()->GetName());
}
std::string cmNinjaNormalTargetGenerator::LanguageLinkerDeviceRule() const
{
return this->TargetLinkLanguage + "_" +
cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()) +
- "_DEVICE_LINKER__" + cmGlobalNinjaGenerator::EncodeRuleName(
- this->GetGeneratorTarget()->GetName());
+ "_DEVICE_LINKER__" +
+ cmGlobalNinjaGenerator::EncodeRuleName(
+ this->GetGeneratorTarget()->GetName());
}
struct cmNinjaRemoveNoOpCommands
@@ -172,13 +163,8 @@ struct cmNinjaRemoveNoOpCommands
void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
{
- cmStateEnums::TargetType targetType = this->GetGeneratorTarget()->GetType();
- std::string ruleName = this->LanguageLinkerDeviceRule();
- // Select whether to use a response file for objects.
- std::string rspfile;
- std::string rspcontent;
-
- if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
+ cmNinjaRule rule(this->LanguageLinkerDeviceRule());
+ if (!this->GetGlobalGenerator()->HasRule(rule.Name)) {
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
vars.CMTargetType =
@@ -186,32 +172,24 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
vars.Language = "CUDA";
- std::string responseFlag;
- if (!useResponseFile) {
+ // build response file name
+ std::string responseFlag = this->GetMakefile()->GetSafeDefinition(
+ "CMAKE_CUDA_RESPONSE_FILE_LINK_FLAG");
+
+ if (!useResponseFile || responseFlag.empty()) {
vars.Objects = "$in";
- vars.LinkLibraries = "$LINK_LIBRARIES";
+ 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;
+ rule.RspFile = "$RSP_FILE";
+ responseFlag += rule.RspFile;
// build response file content
if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
- rspcontent = "$in";
+ rule.RspContent = "$in";
} else {
- rspcontent = "$in_newline";
+ rule.RspContent = "$in_newline";
}
- rspcontent += " $LINK_LIBRARIES";
+ rule.RspContent += " $LINK_LIBRARIES";
vars.Objects = responseFlag.c_str();
vars.LinkLibraries = "";
}
@@ -230,7 +208,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
vars.Manifests = "$MANIFESTS";
std::string langFlags;
- if (targetType != cmStateEnums::EXECUTABLE) {
+ if (this->GetGeneratorTarget()->GetType() != cmStateEnums::EXECUTABLE) {
langFlags += "$LANGUAGE_COMPILE_FLAGS $ARCH_FLAGS";
vars.LanguageCompileFlags = langFlags.c_str();
}
@@ -243,84 +221,98 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRule(bool useResponseFile)
launcher += " ";
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
// Rule for linking library/executable.
std::vector<std::string> linkCmds = this->ComputeDeviceLinkCmd();
- for (std::vector<std::string>::iterator i = linkCmds.begin();
- i != linkCmds.end(); ++i) {
- *i = launcher + *i;
+ for (std::string& linkCmd : linkCmds) {
+ linkCmd = launcher + linkCmd;
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
- *i, vars);
+ linkCmd, vars);
}
// If there is no ranlib the command will be ":". Skip it.
cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands());
- std::string linkCmd =
- this->GetLocalGenerator()->BuildCommandLine(linkCmds);
+ rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds);
// Write the linker rule with response file if needed.
- std::ostringstream comment;
- comment << "Rule for linking " << this->TargetLinkLanguage << " "
- << this->GetVisibleTypeName() << ".";
- std::ostringstream description;
- description << "Linking " << this->TargetLinkLanguage << " "
- << this->GetVisibleTypeName() << " $TARGET_FILE";
- this->GetGlobalGenerator()->AddRule(ruleName, linkCmd, description.str(),
- comment.str(),
- /*depfile*/ "",
- /*deptype*/ "", rspfile, rspcontent,
- /*restat*/ "$RESTAT",
- /*generator*/ false);
+ rule.Comment = "Rule for linking ";
+ rule.Comment += this->TargetLinkLanguage;
+ rule.Comment += " ";
+ rule.Comment += this->GetVisibleTypeName();
+ rule.Comment += ".";
+ rule.Description = "Linking ";
+ rule.Description += this->TargetLinkLanguage;
+ rule.Description += " ";
+ rule.Description += this->GetVisibleTypeName();
+ rule.Description += " $TARGET_FILE";
+ rule.Restat = "$RESTAT";
+
+ this->GetGlobalGenerator()->AddRule(rule);
}
}
void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
{
cmStateEnums::TargetType targetType = this->GetGeneratorTarget()->GetType();
- std::string ruleName = this->LanguageLinkerRule();
-
- // Select whether to use a response file for objects.
- std::string rspfile;
- std::string rspcontent;
- if (!this->GetGlobalGenerator()->HasRule(ruleName)) {
+ std::string linkRuleName = this->LanguageLinkerRule();
+ if (!this->GetGlobalGenerator()->HasRule(linkRuleName)) {
+ cmNinjaRule rule(std::move(linkRuleName));
cmRulePlaceholderExpander::RuleVariables vars;
vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str();
- vars.CMTargetType =
- cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType());
+ vars.CMTargetType = cmState::GetTargetTypeName(targetType);
vars.Language = this->TargetLinkLanguage.c_str();
+ if (this->TargetLinkLanguage == "Swift") {
+ vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME";
+ vars.SwiftModule = "$SWIFT_MODULE";
+ vars.SwiftModuleName = "$SWIFT_MODULE_NAME";
+ vars.SwiftOutputFileMap = "$SWIFT_OUTPUT_FILE_MAP";
+ vars.SwiftSources = "$SWIFT_SOURCES";
+
+ vars.Defines = "$DEFINES";
+ vars.Flags = "$FLAGS";
+ vars.Includes = "$INCLUDES";
+ }
+
std::string responseFlag;
- if (!useResponseFile) {
+
+ 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 if (this->TargetLinkLanguage != "CUDA") {
+ responseFlag = "@";
+ }
+
+ if (!useResponseFile || responseFlag.empty()) {
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;
+ rule.RspFile = "$RSP_FILE";
+ responseFlag += rule.RspFile;
// build response file content
if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
- rspcontent = "$in";
+ rule.RspContent = "$in";
} else {
- rspcontent = "$in_newline";
+ rule.RspContent = "$in_newline";
+ }
+ rule.RspContent += " $LINK_PATH $LINK_LIBRARIES";
+ if (this->TargetLinkLanguage == "Swift") {
+ vars.SwiftSources = responseFlag.c_str();
+ } else {
+ vars.Objects = responseFlag.c_str();
}
- rspcontent += " $LINK_PATH $LINK_LIBRARIES";
- vars.Objects = responseFlag.c_str();
vars.LinkLibraries = "";
}
@@ -368,72 +360,67 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile)
launcher += " ";
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
// 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) {
- *i = launcher + *i;
+ for (std::string& linkCmd : linkCmds) {
+ linkCmd = launcher + linkCmd;
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
- *i, vars);
+ linkCmd, vars);
}
// If there is no ranlib the command will be ":". Skip it.
cmEraseIf(linkCmds, cmNinjaRemoveNoOpCommands());
linkCmds.insert(linkCmds.begin(), "$PRE_LINK");
- linkCmds.push_back("$POST_BUILD");
- std::string linkCmd =
- this->GetLocalGenerator()->BuildCommandLine(linkCmds);
+ linkCmds.emplace_back("$POST_BUILD");
+ rule.Command = this->GetLocalGenerator()->BuildCommandLine(linkCmds);
// Write the linker rule with response file if needed.
- std::ostringstream comment;
- comment << "Rule for linking " << this->TargetLinkLanguage << " "
- << this->GetVisibleTypeName() << ".";
- std::ostringstream description;
- description << "Linking " << this->TargetLinkLanguage << " "
- << this->GetVisibleTypeName() << " $TARGET_FILE";
- this->GetGlobalGenerator()->AddRule(ruleName, linkCmd, description.str(),
- comment.str(),
- /*depfile*/ "",
- /*deptype*/ "", rspfile, rspcontent,
- /*restat*/ "$RESTAT",
- /*generator*/ false);
+ rule.Comment = "Rule for linking ";
+ rule.Comment += this->TargetLinkLanguage;
+ rule.Comment += " ";
+ rule.Comment += this->GetVisibleTypeName();
+ rule.Comment += ".";
+ rule.Description = "Linking ";
+ rule.Description += this->TargetLinkLanguage;
+ rule.Description += " ";
+ rule.Description += this->GetVisibleTypeName();
+ rule.Description += " $TARGET_FILE";
+ rule.Restat = "$RESTAT";
+ this->GetGlobalGenerator()->AddRule(rule);
}
- if (this->TargetNameOut != this->TargetNameReal &&
+ if (this->TargetNames.Output != this->TargetNames.Real &&
!this->GetGeneratorTarget()->IsFrameworkOnApple()) {
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
if (targetType == cmStateEnums::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*/ "",
- /*generator*/ false);
+ cmNinjaRule rule("CMAKE_SYMLINK_EXECUTABLE");
+ {
+ std::vector<std::string> cmd;
+ cmd.push_back(cmakeCommand + " -E cmake_symlink_executable $in $out");
+ cmd.emplace_back("$POST_BUILD");
+ rule.Command = this->GetLocalGenerator()->BuildCommandLine(cmd);
+ }
+ rule.Description = "Creating executable symlink $out";
+ rule.Comment = "Rule for creating executable symlink.";
+ this->GetGlobalGenerator()->AddRule(rule);
} 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*/ "",
- /*generator*/ false);
+ cmNinjaRule rule("CMAKE_SYMLINK_LIBRARY");
+ {
+ std::vector<std::string> cmd;
+ cmd.push_back(cmakeCommand +
+ " -E cmake_symlink_library $in $SONAME $out");
+ cmd.emplace_back("$POST_BUILD");
+ rule.Command = this->GetLocalGenerator()->BuildCommandLine(cmd);
+ }
+ rule.Description = "Creating library symlink $out";
+ rule.Comment = "Rule for creating library symlink.";
+ this->GetGlobalGenerator()->AddRule(rule);
}
}
}
@@ -477,21 +464,28 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
this->TargetLinkLanguage, this->GetConfigName());
const char* linkCmd = mf->GetDefinition(linkCmdVar);
if (linkCmd) {
- cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
+ std::string linkCmdStr = linkCmd;
+ if (this->GetGeneratorTarget()->HasImplibGNUtoMS(this->ConfigName)) {
+ std::string ruleVar = "CMAKE_";
+ ruleVar += this->GeneratorTarget->GetLinkerLanguage(this->ConfigName);
+ ruleVar += "_GNUtoMS_RULE";
+ if (const char* rule = this->Makefile->GetDefinition(ruleVar)) {
+ linkCmdStr += rule;
+ }
+ }
+ cmSystemTools::ExpandListArgument(linkCmdStr, linkCmds);
if (this->GetGeneratorTarget()->GetPropertyAsBool("LINK_WHAT_YOU_USE")) {
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
- cmakeCommand += " -E __run_iwyu --lwyu=";
+ cmakeCommand += " -E __run_co_compile --lwyu=";
cmGeneratorTarget& gt = *this->GetGeneratorTarget();
const std::string cfgName = this->GetConfigName();
- std::string targetOutput = ConvertToNinjaPath(gt.GetFullPath(cfgName));
std::string targetOutputReal = this->ConvertToNinjaPath(
gt.GetFullPath(cfgName, cmStateEnums::RuntimeBinaryArtifact,
/*realname=*/true));
cmakeCommand += targetOutputReal;
- cmakeCommand += " || true";
- linkCmds.push_back(cmakeCommand);
+ linkCmds.push_back(std::move(cmakeCommand));
}
return linkCmds;
}
@@ -514,7 +508,7 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
linkCmdVar, this->TargetLinkLanguage, this->GetConfigName());
- const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar);
+ std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
}
{
@@ -525,9 +519,23 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
linkCmdVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
linkCmdVar, this->TargetLinkLanguage, this->GetConfigName());
- const char* linkCmd = mf->GetRequiredDefinition(linkCmdVar);
+ std::string const& linkCmd = mf->GetRequiredDefinition(linkCmdVar);
cmSystemTools::ExpandListArgument(linkCmd, linkCmds);
}
+#ifdef __APPLE__
+ // On macOS ranlib truncates the fractional part of the static archive
+ // file modification time. If the archive and at least one contained
+ // object file were created within the same second this will make look
+ // the archive older than the object file. On subsequent ninja runs this
+ // leads to re-achiving and updating dependent targets.
+ // As a work-around we touch the archive after ranlib (see #19222).
+ {
+ std::string cmakeCommand =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
+ linkCmds.push_back(cmakeCommand + " -E touch $TARGET_FILE");
+ }
+#endif
return linkCmds;
}
case cmStateEnums::SHARED_LIBRARY:
@@ -542,33 +550,16 @@ std::vector<std::string> cmNinjaNormalTargetGenerator::ComputeLinkCmd()
void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
{
- cmGeneratorTarget& genTarget = *this->GetGeneratorTarget();
-
- // determine if we need to do any device linking for this target
- const std::string cuda_lang("CUDA");
- cmGeneratorTarget::LinkClosure const* closure =
- genTarget.GetLinkClosure(this->GetConfigName());
-
- const bool hasCUDA =
- (std::find(closure->Languages.begin(), closure->Languages.end(),
- cuda_lang) != closure->Languages.end());
-
- bool shouldHaveDeviceLinking = false;
- switch (genTarget.GetType()) {
- case cmStateEnums::SHARED_LIBRARY:
- case cmStateEnums::MODULE_LIBRARY:
- case cmStateEnums::EXECUTABLE:
- shouldHaveDeviceLinking = true;
- break;
- case cmStateEnums::STATIC_LIBRARY:
- shouldHaveDeviceLinking =
- genTarget.GetPropertyAsBool("CUDA_RESOLVE_DEVICE_SYMBOLS");
- break;
- default:
- break;
+ cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
+ if (!globalGen->GetLanguageEnabled("CUDA")) {
+ return;
}
- if (!(shouldHaveDeviceLinking && hasCUDA)) {
+ cmGeneratorTarget* genTarget = this->GetGeneratorTarget();
+
+ bool requiresDeviceLinking = requireDeviceLinking(
+ *this->GeneratorTarget, *this->GetLocalGenerator(), this->ConfigName);
+ if (!requiresDeviceLinking) {
return;
}
@@ -577,44 +568,44 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// First and very important step is to make sure while inside this
// step our link language is set to CUDA
std::string cudaLinkLanguage = "CUDA";
- std::string const objExt =
+ std::string const& objExt =
this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION");
std::string const cfgName = this->GetConfigName();
std::string const targetOutputReal = ConvertToNinjaPath(
- genTarget.ObjectDirectory + "cmake_device_link" + objExt);
+ genTarget->ObjectDirectory + "cmake_device_link" + objExt);
std::string const targetOutputImplib = ConvertToNinjaPath(
- genTarget.GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
+ genTarget->GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
this->DeviceLinkObject = targetOutputReal;
// Write comments.
cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
- const cmStateEnums::TargetType targetType = genTarget.GetType();
+ const cmStateEnums::TargetType targetType = genTarget->GetType();
this->GetBuildFileStream() << "# Device Link build statements for "
<< cmState::GetTargetTypeName(targetType)
<< " target " << this->GetTargetName() << "\n\n";
// Compute the comment.
- std::ostringstream comment;
- comment << "Link the " << this->GetVisibleTypeName() << " "
- << targetOutputReal;
+ cmNinjaBuild build(this->LanguageLinkerDeviceRule());
+ build.Comment = "Link the ";
+ build.Comment += this->GetVisibleTypeName();
+ build.Comment += " ";
+ build.Comment += targetOutputReal;
- cmNinjaDeps emptyDeps;
- cmNinjaVars vars;
+ cmNinjaVars& vars = build.Variables;
// Compute outputs.
- cmNinjaDeps outputs;
- outputs.push_back(targetOutputReal);
+ build.Outputs.push_back(targetOutputReal);
// Compute specific libraries to link with.
- cmNinjaDeps explicitDeps = this->GetObjects();
- cmNinjaDeps implicitDeps = this->ComputeLinkDeps();
+ build.ExplicitDeps = this->GetObjects();
+ build.ImplicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage);
std::string frameworkPath;
std::string linkPath;
- std::string createRule = genTarget.GetCreateRuleVariable(
+ std::string createRule = genTarget->GetCreateRuleVariable(
this->TargetLinkLanguage, this->GetConfigName());
const bool useWatcomQuote =
this->GetMakefile()->IsOn(createRule + "_USE_WATCOM_QUOTE");
@@ -623,18 +614,18 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
vars["TARGET_FILE"] =
localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL);
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
new cmNinjaLinkLineDeviceComputer(
this->GetLocalGenerator(),
this->GetLocalGenerator()->GetStateSnapshot().GetDirectory(),
- this->GetGlobalGenerator()));
+ globalGen));
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
localGen.GetTargetFlags(
linkLineComputer.get(), this->GetConfigName(), vars["LINK_LIBRARIES"],
- vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath, &genTarget);
+ vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath, genTarget);
- this->addPoolNinjaVariable("JOB_POOL_LINK", &genTarget, vars);
+ this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, vars);
vars["LINK_FLAGS"] =
cmGlobalNinjaGenerator::EncodeLiteral(vars["LINK_FLAGS"]);
@@ -648,21 +639,21 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
// code between the Makefile executable and library generators.
if (targetType == cmStateEnums::EXECUTABLE) {
std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, &genTarget, cudaLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, cfgName);
vars["FLAGS"] = t;
} else {
std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, &genTarget, cudaLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, genTarget, cudaLinkLanguage, cfgName);
vars["ARCH_FLAGS"] = t;
- t = "";
- localGen.AddLanguageFlagsForLinking(t, &genTarget, cudaLinkLanguage,
+ t.clear();
+ localGen.AddLanguageFlagsForLinking(t, genTarget, cudaLinkLanguage,
cfgName);
vars["LANGUAGE_COMPILE_FLAGS"] = t;
}
- if (this->GetGeneratorTarget()->HasSOName(cfgName)) {
+ if (genTarget->HasSOName(cfgName)) {
vars["SONAME_FLAG"] =
this->GetMakefile()->GetSONameFlag(this->TargetLinkLanguage);
- vars["SONAME"] = this->TargetNameSO;
+ vars["SONAME"] = this->TargetNames.SharedObject;
if (targetType == cmStateEnums::SHARED_LIBRARY) {
std::string install_dir =
this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName);
@@ -673,16 +664,11 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
}
}
- cmNinjaDeps byproducts;
-
- if (!this->TargetNameImport.empty()) {
+ if (!this->TargetNames.ImportLibrary.empty()) {
const std::string impLibPath = localGen.ConvertToOutputFormat(
targetOutputImplib, cmOutputConverter::SHELL);
vars["TARGET_IMPLIB"] = impLibPath;
EnsureParentDirectoryExists(impLibPath);
- if (genTarget.HasImportLibrary()) {
- byproducts.push_back(targetOutputImplib);
- }
}
const std::string objPath = GetGeneratorTarget()->GetSupportDirectory();
@@ -692,7 +678,7 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
this->SetMsvcTargetPdbVariable(vars);
- if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
+ if (globalGen->IsGCCOnWindows()) {
// 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(), '\\', '/');
@@ -700,143 +686,188 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkStatement()
std::replace(link_path.begin(), link_path.end(), '\\', '/');
}
- const std::vector<cmCustomCommand>* cmdLists[3] = {
- &genTarget.GetPreBuildCommands(), &genTarget.GetPreLinkCommands(),
- &genTarget.GetPostBuildCommands()
- };
-
- std::vector<std::string> preLinkCmdLines, postBuildCmdLines;
- vars["PRE_LINK"] = localGen.BuildCommandLine(preLinkCmdLines);
- vars["POST_BUILD"] = localGen.BuildCommandLine(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, this->GetLocalGenerator());
- localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
- std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
- std::transform(ccByproducts.begin(), ccByproducts.end(),
- std::back_inserter(byproducts), MapToNinjaPath());
- }
- }
-
- cmGlobalNinjaGenerator& globalGen = *this->GetGlobalGenerator();
-
// Device linking currently doesn't support response files so
// do not check if the user has explicitly forced a response file.
int const commandLineLengthLimit =
static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
- globalGen.GetRuleCmdLength(this->LanguageLinkerDeviceRule());
+ globalGen->GetRuleCmdLength(this->LanguageLinkerDeviceRule());
- const std::string rspfile =
- std::string(cmake::GetCMakeFilesDirectoryPostSlash()) +
- genTarget.GetName() + ".rsp";
+ build.RspFile = this->ConvertToNinjaPath(std::string("CMakeFiles/") +
+ genTarget->GetName() + ".rsp");
// Gather order-only dependencies.
- cmNinjaDeps orderOnlyDeps;
this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
- orderOnlyDeps);
+ build.OrderOnlyDeps);
// Write the build statement for this target.
bool usedResponseFile = false;
- globalGen.WriteBuild(this->GetBuildFileStream(), comment.str(),
- this->LanguageLinkerDeviceRule(), outputs,
- /*implicitOuts=*/cmNinjaDeps(), explicitDeps,
- implicitDeps, orderOnlyDeps, vars, rspfile,
- commandLineLengthLimit, &usedResponseFile);
+ globalGen->WriteBuild(this->GetBuildFileStream(), build,
+ commandLineLengthLimit, &usedResponseFile);
this->WriteDeviceLinkRule(usedResponseFile);
}
void cmNinjaNormalTargetGenerator::WriteLinkStatement()
{
- cmGeneratorTarget& gt = *this->GetGeneratorTarget();
+ cmMakefile* mf = this->GetMakefile();
+ cmGlobalNinjaGenerator* globalGen = this->GetGlobalGenerator();
+ cmGeneratorTarget* gt = this->GetGeneratorTarget();
+
const std::string cfgName = this->GetConfigName();
- std::string targetOutput = ConvertToNinjaPath(gt.GetFullPath(cfgName));
+ std::string targetOutput = ConvertToNinjaPath(gt->GetFullPath(cfgName));
std::string targetOutputReal = ConvertToNinjaPath(
- gt.GetFullPath(cfgName, cmStateEnums::RuntimeBinaryArtifact,
- /*realname=*/true));
+ gt->GetFullPath(cfgName, cmStateEnums::RuntimeBinaryArtifact,
+ /*realname=*/true));
std::string targetOutputImplib = ConvertToNinjaPath(
- gt.GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
+ gt->GetFullPath(cfgName, cmStateEnums::ImportLibraryArtifact));
- if (gt.IsAppBundleOnApple()) {
+ if (gt->IsAppBundleOnApple()) {
// Create the app bundle
- std::string outpath = gt.GetDirectory(cfgName);
- this->OSXBundleGenerator->CreateAppBundle(this->TargetNameOut, outpath);
+ std::string outpath = gt->GetDirectory(cfgName);
+ this->OSXBundleGenerator->CreateAppBundle(this->TargetNames.Output,
+ outpath);
// Calculate the output path
targetOutput = outpath;
targetOutput += "/";
- targetOutput += this->TargetNameOut;
+ targetOutput += this->TargetNames.Output;
targetOutput = this->ConvertToNinjaPath(targetOutput);
targetOutputReal = outpath;
targetOutputReal += "/";
- targetOutputReal += this->TargetNameReal;
+ targetOutputReal += this->TargetNames.Real;
targetOutputReal = this->ConvertToNinjaPath(targetOutputReal);
- } else if (gt.IsFrameworkOnApple()) {
+ } else if (gt->IsFrameworkOnApple()) {
// Create the library framework.
- this->OSXBundleGenerator->CreateFramework(this->TargetNameOut,
- gt.GetDirectory(cfgName));
- } else if (gt.IsCFBundleOnApple()) {
+ this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output,
+ gt->GetDirectory(cfgName));
+ } else if (gt->IsCFBundleOnApple()) {
// Create the core foundation bundle.
- this->OSXBundleGenerator->CreateCFBundle(this->TargetNameOut,
- gt.GetDirectory(cfgName));
+ this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output,
+ gt->GetDirectory(cfgName));
}
// Write comments.
cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream());
- const cmStateEnums::TargetType targetType = gt.GetType();
- this->GetBuildFileStream() << "# Link build statements for "
- << cmState::GetTargetTypeName(targetType)
- << " target " << this->GetTargetName() << "\n\n";
+ const cmStateEnums::TargetType targetType = gt->GetType();
+ this->GetBuildFileStream()
+ << "# Link build statements for " << cmState::GetTargetTypeName(targetType)
+ << " target " << this->GetTargetName() << "\n\n";
- cmNinjaDeps emptyDeps;
- cmNinjaVars vars;
+ cmNinjaBuild linkBuild(this->LanguageLinkerRule());
+ cmNinjaVars& vars = linkBuild.Variables;
// Compute the comment.
- std::ostringstream comment;
- comment << "Link the " << this->GetVisibleTypeName() << " "
- << targetOutputReal;
+ linkBuild.Comment = "Link the ";
+ linkBuild.Comment += this->GetVisibleTypeName();
+ linkBuild.Comment += " ";
+ linkBuild.Comment += targetOutputReal;
// Compute outputs.
- cmNinjaDeps outputs;
- outputs.push_back(targetOutputReal);
+ linkBuild.Outputs.push_back(targetOutputReal);
+
+ if (this->TargetLinkLanguage == "Swift") {
+ vars["SWIFT_LIBRARY_NAME"] = [this]() -> std::string {
+ cmGeneratorTarget::Names targetNames =
+ this->GetGeneratorTarget()->GetLibraryNames(this->GetConfigName());
+ return targetNames.Base;
+ }();
+
+ vars["SWIFT_MODULE_NAME"] = [gt]() -> std::string {
+ if (const char* name = gt->GetProperty("Swift_MODULE_NAME")) {
+ return name;
+ }
+ return gt->GetName();
+ }();
+
+ vars["SWIFT_MODULE"] = [this](const std::string& module) -> std::string {
+ std::string directory =
+ this->GetLocalGenerator()->GetCurrentBinaryDirectory();
+ if (const char* prop = this->GetGeneratorTarget()->GetProperty(
+ "Swift_MODULE_DIRECTORY")) {
+ directory = prop;
+ }
+
+ std::string name = module + ".swiftmodule";
+ if (const char* prop =
+ this->GetGeneratorTarget()->GetProperty("Swift_MODULE")) {
+ name = prop;
+ }
+
+ return this->GetLocalGenerator()->ConvertToOutputFormat(
+ this->ConvertToNinjaPath(directory + "/" + name),
+ cmOutputConverter::SHELL);
+ }(vars["SWIFT_MODULE_NAME"]);
+
+ vars["SWIFT_OUTPUT_FILE_MAP"] =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ this->ConvertToNinjaPath(gt->GetSupportDirectory() +
+ "/output-file-map.json"),
+ cmOutputConverter::SHELL);
+
+ vars["SWIFT_SOURCES"] = [this]() -> std::string {
+ std::vector<cmSourceFile const*> sources;
+ std::stringstream oss;
+
+ this->GetGeneratorTarget()->GetObjectSources(sources,
+ this->GetConfigName());
+ cmLocalGenerator const* LocalGen = this->GetLocalGenerator();
+ for (const auto& source : sources) {
+ oss << " "
+ << LocalGen->ConvertToOutputFormat(
+ this->ConvertToNinjaPath(this->GetSourceFilePath(source)),
+ cmOutputConverter::SHELL);
+ }
+ return oss.str();
+ }();
+
+ // Since we do not perform object builds, compute the
+ // defines/flags/includes here so that they can be passed along
+ // appropriately.
+ vars["DEFINES"] = this->GetDefines("Swift");
+ vars["FLAGS"] = this->GetFlags("Swift");
+ vars["INCLUDES"] = this->GetIncludes("Swift");
+ }
// Compute specific libraries to link with.
- cmNinjaDeps explicitDeps = this->GetObjects();
- cmNinjaDeps implicitDeps = this->ComputeLinkDeps();
+ if (this->TargetLinkLanguage == "Swift") {
+ std::vector<cmSourceFile const*> sources;
+ gt->GetObjectSources(sources, this->GetConfigName());
+ for (const auto& source : sources) {
+ linkBuild.Outputs.push_back(
+ this->ConvertToNinjaPath(this->GetObjectFilePath(source)));
+ linkBuild.ExplicitDeps.push_back(
+ this->ConvertToNinjaPath(this->GetSourceFilePath(source)));
+ }
- if (!this->DeviceLinkObject.empty()) {
- explicitDeps.push_back(this->DeviceLinkObject);
+ linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]);
+ } else {
+ linkBuild.ExplicitDeps = this->GetObjects();
}
+ linkBuild.ImplicitDeps = this->ComputeLinkDeps(this->TargetLinkLanguage);
- cmMakefile* mf = this->GetMakefile();
+ if (!this->DeviceLinkObject.empty()) {
+ linkBuild.ExplicitDeps.push_back(this->DeviceLinkObject);
+ }
std::string frameworkPath;
std::string linkPath;
- cmGeneratorTarget& genTarget = *this->GetGeneratorTarget();
- std::string createRule = genTarget.GetCreateRuleVariable(
- this->TargetLinkLanguage, this->GetConfigName());
+ std::string createRule =
+ gt->GetCreateRuleVariable(this->TargetLinkLanguage, this->GetConfigName());
bool useWatcomQuote = mf->IsOn(createRule + "_USE_WATCOM_QUOTE");
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
vars["TARGET_FILE"] =
localGen.ConvertToOutputFormat(targetOutputReal, cmOutputConverter::SHELL);
- CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
- this->GetGlobalGenerator()->CreateLinkLineComputer(
+ std::unique_ptr<cmLinkLineComputer> linkLineComputer(
+ globalGen->CreateLinkLineComputer(
this->GetLocalGenerator(),
this->GetLocalGenerator()->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
- localGen.GetTargetFlags(
- linkLineComputer.get(), this->GetConfigName(), vars["LINK_LIBRARIES"],
- vars["FLAGS"], vars["LINK_FLAGS"], frameworkPath, linkPath, &genTarget);
+ localGen.GetTargetFlags(linkLineComputer.get(), this->GetConfigName(),
+ vars["LINK_LIBRARIES"], vars["FLAGS"],
+ vars["LINK_FLAGS"], frameworkPath, linkPath, gt);
// Add OS X version flags, if any.
if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
@@ -847,7 +878,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
"CURRENT", false);
}
- this->addPoolNinjaVariable("JOB_POOL_LINK", &gt, vars);
+ this->addPoolNinjaVariable("JOB_POOL_LINK", gt, vars);
this->AddModuleDefinitionFlag(linkLineComputer.get(), vars["LINK_FLAGS"]);
vars["LINK_FLAGS"] =
@@ -857,7 +888,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
vars["LINK_PATH"] = frameworkPath + linkPath;
std::string lwyuFlags;
- if (genTarget.GetPropertyAsBool("LINK_WHAT_YOU_USE")) {
+ if (gt->GetPropertyAsBool("LINK_WHAT_YOU_USE")) {
lwyuFlags = " -Wl,--no-as-needed";
}
@@ -866,25 +897,23 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// code between the Makefile executable and library generators.
if (targetType == cmStateEnums::EXECUTABLE) {
std::string t = vars["FLAGS"];
- localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, gt, TargetLinkLanguage, cfgName);
t += lwyuFlags;
vars["FLAGS"] = t;
} else {
std::string t = vars["ARCH_FLAGS"];
- localGen.AddArchitectureFlags(t, &genTarget, TargetLinkLanguage, cfgName);
+ localGen.AddArchitectureFlags(t, gt, TargetLinkLanguage, cfgName);
vars["ARCH_FLAGS"] = t;
- t = "";
+ t.clear();
t += lwyuFlags;
- localGen.AddLanguageFlagsForLinking(t, &genTarget, TargetLinkLanguage,
- cfgName);
+ localGen.AddLanguageFlagsForLinking(t, gt, TargetLinkLanguage, cfgName);
vars["LANGUAGE_COMPILE_FLAGS"] = t;
}
- if (this->GetGeneratorTarget()->HasSOName(cfgName)) {
+ if (gt->HasSOName(cfgName)) {
vars["SONAME_FLAG"] = mf->GetSONameFlag(this->TargetLinkLanguage);
- vars["SONAME"] = this->TargetNameSO;
+ vars["SONAME"] = this->TargetNames.SharedObject;
if (targetType == cmStateEnums::SHARED_LIBRARY) {
- std::string install_dir =
- this->GetGeneratorTarget()->GetInstallNameDirForBuildTree(cfgName);
+ std::string install_dir = gt->GetInstallNameDirForBuildTree(cfgName);
if (!install_dir.empty()) {
vars["INSTALLNAME_DIR"] = localGen.ConvertToOutputFormat(
install_dir, cmOutputConverter::SHELL);
@@ -894,12 +923,12 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
cmNinjaDeps byproducts;
- if (!this->TargetNameImport.empty()) {
+ if (!this->TargetNames.ImportLibrary.empty()) {
const std::string impLibPath = localGen.ConvertToOutputFormat(
targetOutputImplib, cmOutputConverter::SHELL);
vars["TARGET_IMPLIB"] = impLibPath;
EnsureParentDirectoryExists(impLibPath);
- if (genTarget.HasImportLibrary()) {
+ if (gt->HasImportLibrary(cfgName)) {
byproducts.push_back(targetOutputImplib);
}
}
@@ -910,7 +939,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
std::string prefix;
std::string base;
std::string suffix;
- this->GetGeneratorTarget()->GetFullNameComponents(prefix, base, suffix);
+ gt->GetFullNameComponents(prefix, base, suffix);
std::string dbg_suffix = ".dbg";
// TODO: Where to document?
if (mf->GetDefinition("CMAKE_DEBUG_SYMBOL_SUFFIX")) {
@@ -919,12 +948,12 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
vars["TARGET_PDB"] = base + suffix + dbg_suffix;
}
- const std::string objPath = GetGeneratorTarget()->GetSupportDirectory();
+ const std::string objPath = gt->GetSupportDirectory();
vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
this->ConvertToNinjaPath(objPath), cmOutputConverter::SHELL);
EnsureDirectoryExists(objPath);
- if (this->GetGlobalGenerator()->IsGCCOnWindows()) {
+ if (globalGen->IsGCCOnWindows()) {
// 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(), '\\', '/');
@@ -933,8 +962,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
const std::vector<cmCustomCommand>* cmdLists[3] = {
- &gt.GetPreBuildCommands(), &gt.GetPreLinkCommands(),
- &gt.GetPostBuildCommands()
+ &gt->GetPreBuildCommands(), &gt->GetPreLinkCommands(),
+ &gt->GetPostBuildCommands()
};
std::vector<std::string> preLinkCmdLines, postBuildCmdLines;
@@ -943,10 +972,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
&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, this->GetLocalGenerator());
+ for (cmCustomCommand const& cc : *cmdLists[i]) {
+ cmCustomCommandGenerator ccg(cc, cfgName, this->GetLocalGenerator());
localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
std::transform(ccByproducts.begin(), ccByproducts.end(),
@@ -956,7 +983,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
// maybe create .def file from list of objects
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
- gt.GetModuleDefinitionInfo(this->GetConfigName());
+ gt->GetModuleDefinitionInfo(this->GetConfigName());
if (mdi && mdi->DefFileGenerated) {
std::string cmakeCommand =
this->GetLocalGenerator()->ConvertToOutputFormat(
@@ -969,129 +996,132 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
std::string obj_list_file = mdi->DefFile + ".objs";
cmd += this->GetLocalGenerator()->ConvertToOutputFormat(
obj_list_file, cmOutputConverter::SHELL);
- preLinkCmdLines.push_back(cmd);
+ preLinkCmdLines.push_back(std::move(cmd));
// create a list of obj files for the -E __create_def to read
- cmGeneratedFileStream fout(obj_list_file.c_str());
+ cmGeneratedFileStream fout(obj_list_file);
if (mdi->WindowsExportAllSymbols) {
cmNinjaDeps objs = this->GetObjects();
- for (cmNinjaDeps::iterator i = objs.begin(); i != objs.end(); ++i) {
- if (cmHasLiteralSuffix(*i, ".obj")) {
- fout << *i << "\n";
+ for (std::string const& obj : objs) {
+ if (cmHasLiteralSuffix(obj, ".obj")) {
+ fout << obj << "\n";
}
}
}
- for (std::vector<cmSourceFile const*>::const_iterator i =
- mdi->Sources.begin();
- i != mdi->Sources.end(); ++i) {
- fout << (*i)->GetFullPath() << "\n";
+ for (cmSourceFile const* src : mdi->Sources) {
+ fout << src->GetFullPath() << "\n";
}
}
// If we have any PRE_LINK commands, we need to go back to CMAKE_BINARY_DIR
- // for
- // the link commands.
+ // for the link commands.
if (!preLinkCmdLines.empty()) {
const std::string homeOutDir = localGen.ConvertToOutputFormat(
localGen.GetBinaryDirectory(), cmOutputConverter::SHELL);
preLinkCmdLines.push_back("cd " + homeOutDir);
}
- vars["PRE_LINK"] = localGen.BuildCommandLine(preLinkCmdLines);
- std::string postBuildCmdLine = localGen.BuildCommandLine(postBuildCmdLines);
+ vars["PRE_LINK"] = localGen.BuildCommandLine(preLinkCmdLines, "pre-link",
+ this->GeneratorTarget);
+ std::string postBuildCmdLine = localGen.BuildCommandLine(
+ postBuildCmdLines, "post-build", this->GeneratorTarget);
cmNinjaVars symlinkVars;
bool const symlinkNeeded =
- (targetOutput != targetOutputReal && !gt.IsFrameworkOnApple());
+ (targetOutput != targetOutputReal && !gt->IsFrameworkOnApple());
if (!symlinkNeeded) {
vars["POST_BUILD"] = postBuildCmdLine;
} else {
vars["POST_BUILD"] = cmGlobalNinjaGenerator::SHELL_NOOP;
symlinkVars["POST_BUILD"] = postBuildCmdLine;
}
- cmGlobalNinjaGenerator& globalGen = *this->GetGlobalGenerator();
+
+ 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);
bool const lang_supports_response =
- !(this->TargetLinkLanguage == "RC" || this->TargetLinkLanguage == "CUDA");
+ !(this->TargetLinkLanguage == "RC" ||
+ (this->TargetLinkLanguage == "CUDA" && !flag));
int commandLineLengthLimit = -1;
if (!lang_supports_response || !this->ForceResponseFile()) {
commandLineLengthLimit =
static_cast<int>(cmSystemTools::CalculateCommandLineLengthLimit()) -
- globalGen.GetRuleCmdLength(this->LanguageLinkerRule());
+ globalGen->GetRuleCmdLength(linkBuild.Rule);
}
- const std::string rspfile =
- std::string(cmake::GetCMakeFilesDirectoryPostSlash()) + gt.GetName() +
- ".rsp";
+ linkBuild.RspFile = this->ConvertToNinjaPath(std::string("CMakeFiles/") +
+ gt->GetName() + ".rsp");
// Gather order-only dependencies.
- cmNinjaDeps orderOnlyDeps;
- this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
- orderOnlyDeps);
+ this->GetLocalGenerator()->AppendTargetDepends(gt, linkBuild.OrderOnlyDeps);
// Ninja should restat after linking if and only if there are byproducts.
vars["RESTAT"] = byproducts.empty() ? "" : "1";
- for (cmNinjaDeps::const_iterator oi = byproducts.begin(),
- oe = byproducts.end();
- oi != oe; ++oi) {
- this->GetGlobalGenerator()->SeenCustomCommandOutput(*oi);
- outputs.push_back(*oi);
+ for (std::string const& o : byproducts) {
+ globalGen->SeenCustomCommandOutput(o);
+ linkBuild.Outputs.push_back(o);
}
// Write the build statement for this target.
bool usedResponseFile = false;
- globalGen.WriteBuild(this->GetBuildFileStream(), comment.str(),
- this->LanguageLinkerRule(), outputs,
- /*implicitOuts=*/cmNinjaDeps(), explicitDeps,
- implicitDeps, orderOnlyDeps, vars, rspfile,
- commandLineLengthLimit, &usedResponseFile);
+ globalGen->WriteBuild(this->GetBuildFileStream(), linkBuild,
+ commandLineLengthLimit, &usedResponseFile);
this->WriteLinkRule(usedResponseFile);
if (symlinkNeeded) {
if (targetType == cmStateEnums::EXECUTABLE) {
- globalGen.WriteBuild(
- this->GetBuildFileStream(),
- "Create executable symlink " + targetOutput,
- "CMAKE_SYMLINK_EXECUTABLE", cmNinjaDeps(1, targetOutput),
- /*implicitOuts=*/cmNinjaDeps(), cmNinjaDeps(1, targetOutputReal),
- emptyDeps, emptyDeps, symlinkVars);
+ cmNinjaBuild build("CMAKE_SYMLINK_EXECUTABLE");
+ build.Comment = "Create executable symlink " + targetOutput;
+ build.Outputs.push_back(targetOutput);
+ build.ExplicitDeps.push_back(targetOutputReal);
+ build.Variables = std::move(symlinkVars);
+ globalGen->WriteBuild(this->GetBuildFileStream(), build);
} else {
- cmNinjaDeps symlinks;
- std::string const soName =
- this->ConvertToNinjaPath(this->GetTargetFilePath(this->TargetNameSO));
+ cmNinjaBuild build("CMAKE_SYMLINK_LIBRARY");
+ build.Comment = "Create library symlink " + targetOutput;
+
+ std::string const soName = this->ConvertToNinjaPath(
+ this->GetTargetFilePath(this->TargetNames.SharedObject));
// If one link has to be created.
if (targetOutputReal == soName || targetOutput == soName) {
- symlinkVars["SONAME"] = soName;
+ symlinkVars["SONAME"] =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ soName, cmOutputConverter::SHELL);
} else {
- symlinkVars["SONAME"] = "";
- symlinks.push_back(soName);
+ symlinkVars["SONAME"].clear();
+ build.Outputs.push_back(soName);
}
- symlinks.push_back(targetOutput);
- globalGen.WriteBuild(
- this->GetBuildFileStream(), "Create library symlink " + targetOutput,
- "CMAKE_SYMLINK_LIBRARY", symlinks,
- /*implicitOuts=*/cmNinjaDeps(), cmNinjaDeps(1, targetOutputReal),
- emptyDeps, emptyDeps, symlinkVars);
+ build.Outputs.push_back(targetOutput);
+ build.ExplicitDeps.push_back(targetOutputReal);
+ build.Variables = std::move(symlinkVars);
+
+ globalGen->WriteBuild(this->GetBuildFileStream(), build);
}
}
// Add aliases for the file name and the target name.
- globalGen.AddTargetAlias(this->TargetNameOut, &gt);
- globalGen.AddTargetAlias(this->GetTargetName(), &gt);
+ globalGen->AddTargetAlias(this->TargetNames.Output, gt);
+ globalGen->AddTargetAlias(this->GetTargetName(), gt);
}
void cmNinjaNormalTargetGenerator::WriteObjectLibStatement()
{
// Write a phony output that depends on all object files.
- cmNinjaDeps outputs;
- this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
- outputs);
- cmNinjaDeps depends = this->GetObjects();
- this->GetGlobalGenerator()->WritePhonyBuild(
- this->GetBuildFileStream(), "Object library " + this->GetTargetName(),
- outputs, depends);
+ {
+ cmNinjaBuild build("phony");
+ build.Comment = "Object library " + this->GetTargetName();
+ this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
+ build.Outputs);
+ build.ExplicitDeps = this->GetObjects();
+ this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
+ }
// Add aliases for the target name.
this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h
index 677b1c666..14991a286 100644
--- a/Source/cmNinjaNormalTargetGenerator.h
+++ b/Source/cmNinjaNormalTargetGenerator.h
@@ -3,22 +3,21 @@
#ifndef cmNinjaNormalTargetGenerator_h
#define cmNinjaNormalTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmGeneratorTarget.h"
#include "cmNinjaTargetGenerator.h"
#include <string>
#include <vector>
-class cmGeneratorTarget;
-
class cmNinjaNormalTargetGenerator : public cmNinjaTargetGenerator
{
public:
cmNinjaNormalTargetGenerator(cmGeneratorTarget* target);
- ~cmNinjaNormalTargetGenerator() CM_OVERRIDE;
+ ~cmNinjaNormalTargetGenerator() override;
- void Generate() CM_OVERRIDE;
+ void Generate() override;
private:
std::string LanguageLinkerRule() const;
@@ -40,11 +39,7 @@ private:
private:
// Target name info.
- std::string TargetNameOut;
- std::string TargetNameSO;
- std::string TargetNameReal;
- std::string TargetNameImport;
- std::string TargetNamePDB;
+ cmGeneratorTarget::Names TargetNames;
std::string TargetLinkLanguage;
std::string DeviceLinkObject;
};
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index d38dbcb09..2139a452d 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -8,8 +8,9 @@
#include <assert.h>
#include <iterator>
#include <map>
-#include <sstream>
-#include <string.h>
+#include <memory> // IWYU pragma: keep
+#include <ostream>
+#include <utility>
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
@@ -24,15 +25,16 @@
#include "cmNinjaNormalTargetGenerator.h"
#include "cmNinjaUtilityTargetGenerator.h"
#include "cmOutputConverter.h"
+#include "cmRange.h"
#include "cmRulePlaceholderExpander.h"
#include "cmSourceFile.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
-cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target)
+std::unique_ptr<cmNinjaTargetGenerator> cmNinjaTargetGenerator::New(
+ cmGeneratorTarget* target)
{
switch (target->GetType()) {
case cmStateEnums::EXECUTABLE:
@@ -40,33 +42,28 @@ cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target)
case cmStateEnums::STATIC_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
case cmStateEnums::OBJECT_LIBRARY:
- return new cmNinjaNormalTargetGenerator(target);
+ return cm::make_unique<cmNinjaNormalTargetGenerator>(target);
case cmStateEnums::UTILITY:
case cmStateEnums::GLOBAL_TARGET:
- return new cmNinjaUtilityTargetGenerator(target);
+ return cm::make_unique<cmNinjaUtilityTargetGenerator>(target);
default:
- return CM_NULLPTR;
+ return std::unique_ptr<cmNinjaTargetGenerator>();
}
}
cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
: cmCommonTargetGenerator(target)
- , MacOSXContentGenerator(CM_NULLPTR)
- , OSXBundleGenerator(CM_NULLPTR)
- , MacContentFolders()
+ , MacOSXContentGenerator(nullptr)
+ , OSXBundleGenerator(nullptr)
, LocalGenerator(
static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator()))
- , Objects()
{
- MacOSXContentGenerator = new MacOSXContentGeneratorType(this);
+ MacOSXContentGenerator = cm::make_unique<MacOSXContentGeneratorType>(this);
}
-cmNinjaTargetGenerator::~cmNinjaTargetGenerator()
-{
- delete this->MacOSXContentGenerator;
-}
+cmNinjaTargetGenerator::~cmNinjaTargetGenerator() = default;
cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const
{
@@ -103,6 +100,12 @@ bool cmNinjaTargetGenerator::NeedExplicitPreprocessing(
return lang == "Fortran";
}
+bool cmNinjaTargetGenerator::UsePreprocessedSource(
+ std::string const& lang) const
+{
+ return lang == "Fortran";
+}
+
std::string cmNinjaTargetGenerator::LanguageDyndepRule(
const std::string& lang) const
{
@@ -135,13 +138,20 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
}
// Add source file specific flags.
- if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) {
- std::string config = this->LocalGenerator->GetConfigName();
- cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags);
- const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config,
- false, this->GeneratorTarget);
- this->LocalGenerator->AppendFlags(flags, evaluatedFlags);
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, this->LocalGenerator->GetConfigName(),
+ this->GeneratorTarget, language);
+
+ const std::string COMPILE_FLAGS("COMPILE_FLAGS");
+ if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
+ this->LocalGenerator->AppendFlags(
+ flags, genexInterpreter.Evaluate(cflags, COMPILE_FLAGS));
+ }
+
+ const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
+ if (const char* coptions = source->GetProperty(COMPILE_OPTIONS)) {
+ this->LocalGenerator->AppendCompileOptions(
+ flags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
}
return flags;
@@ -167,9 +177,28 @@ void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags,
bool cmNinjaTargetGenerator::NeedDepTypeMSVC(const std::string& lang) const
{
- return strcmp(this->GetMakefile()->GetSafeDefinition("CMAKE_NINJA_DEPTYPE_" +
- lang),
- "msvc") == 0;
+ std::string const& deptype =
+ this->GetMakefile()->GetSafeDefinition("CMAKE_NINJA_DEPTYPE_" + lang);
+ if (deptype == "msvc") {
+ return true;
+ }
+ if (deptype == "intel") {
+ // Ninja does not really define "intel", but we use it to switch based
+ // on whether this environment supports "gcc" or "msvc" deptype.
+ if (!this->GetGlobalGenerator()->SupportsMultilineDepfile()) {
+ // This ninja version is too old to support the Intel depfile format.
+ // Fall back to msvc deptype.
+ return true;
+ }
+ if ((this->Makefile->GetHomeDirectory().find(' ') != std::string::npos) ||
+ (this->Makefile->GetHomeOutputDirectory().find(' ') !=
+ std::string::npos)) {
+ // The Intel compiler does not properly escape spaces in a depfile.
+ // Fall back to msvc deptype.
+ return true;
+ }
+ }
+ return false;
}
// TODO: Refactor with
@@ -178,13 +207,22 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
const std::string& language)
{
std::set<std::string> defines;
- 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));
+ const std::string config = this->LocalGenerator->GetConfigName();
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, config, this->GeneratorTarget, language);
+
+ const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
+ if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
+ this->LocalGenerator->AppendDefines(
+ defines, genexInterpreter.Evaluate(compile_defs, COMPILE_DEFINITIONS));
+ }
+
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(config);
+ if (const char* config_compile_defs = source->GetProperty(defPropName)) {
+ this->LocalGenerator->AppendDefines(
+ defines,
+ genexInterpreter.Evaluate(config_compile_defs, COMPILE_DEFINITIONS));
}
std::string definesString = this->GetDefines(language);
@@ -193,7 +231,31 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
return definesString;
}
-cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
+std::string cmNinjaTargetGenerator::ComputeIncludes(
+ cmSourceFile const* source, const std::string& language)
+{
+ std::vector<std::string> includes;
+ const std::string config = this->LocalGenerator->GetConfigName();
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, config, this->GeneratorTarget, language);
+
+ const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
+ if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
+ this->LocalGenerator->AppendIncludeDirectories(
+ includes, genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES),
+ *source);
+ }
+
+ std::string includesString = this->LocalGenerator->GetIncludeFlags(
+ includes, this->GeneratorTarget, language, true, false, config);
+ this->LocalGenerator->AppendFlags(includesString,
+ this->GetIncludes(language));
+
+ return includesString;
+}
+
+cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps(
+ const std::string& linkLanguage) const
{
// Static libraries never depend on other targets for linking.
if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
@@ -215,29 +277,24 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
if (cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
this->GeneratorTarget->GetModuleDefinitionInfo(
this->GetConfigName())) {
- for (std::vector<cmSourceFile const*>::const_iterator i =
- mdi->Sources.begin();
- i != mdi->Sources.end(); ++i) {
- result.push_back(this->ConvertToNinjaPath((*i)->GetFullPath()));
+ for (cmSourceFile const* src : mdi->Sources) {
+ result.push_back(this->ConvertToNinjaPath(src->GetFullPath()));
}
}
// Add a dependency on user-specified manifest files, if any.
std::vector<cmSourceFile const*> manifest_srcs;
this->GeneratorTarget->GetManifests(manifest_srcs, this->ConfigName);
- for (std::vector<cmSourceFile const*>::iterator mi = manifest_srcs.begin();
- mi != manifest_srcs.end(); ++mi) {
- result.push_back(this->ConvertToNinjaPath((*mi)->GetFullPath()));
+ for (cmSourceFile const* manifest_src : manifest_srcs) {
+ result.push_back(this->ConvertToNinjaPath(manifest_src->GetFullPath()));
}
// Add user-specified dependencies.
- if (const char* linkDepends =
- this->GeneratorTarget->GetProperty("LINK_DEPENDS")) {
- std::vector<std::string> linkDeps;
- cmSystemTools::ExpandListArgument(linkDepends, linkDeps);
- std::transform(linkDeps.begin(), linkDeps.end(),
- std::back_inserter(result), MapToNinjaPath());
- }
+ std::vector<std::string> linkDeps;
+ this->GeneratorTarget->GetLinkDepends(linkDeps, this->ConfigName,
+ linkLanguage);
+ std::transform(linkDeps.begin(), linkDeps.end(), std::back_inserter(result),
+ MapToNinjaPath());
return result;
}
@@ -406,67 +463,19 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
cmMakefile* mf = this->GetMakefile();
std::string flags = "$FLAGS";
- std::string rspfile;
- std::string rspcontent;
- std::string responseFlag;
- bool const lang_supports_response = !(lang == "RC" || lang == "CUDA");
+ std::string responseFlag;
+ bool const lang_supports_response = lang != "RC";
if (lang_supports_response && this->ForceResponseFile()) {
- rspfile = "$RSP_FILE";
- responseFlag = "@" + rspfile;
- rspcontent = " $DEFINES $INCLUDES $FLAGS";
- flags = responseFlag;
- vars.Defines = "";
- vars.Includes = "";
- }
-
- // Tell ninja dependency format so all deps can be loaded into a database
- std::string deptype;
- std::string depfile;
- std::string cldeps;
- if (explicitPP) {
- // The explicit preprocessing step will handle dependency scanning.
- } else if (this->NeedDepTypeMSVC(lang)) {
- deptype = "msvc";
- depfile = "";
- flags += " /showIncludes";
- } else if (mf->IsOn("CMAKE_NINJA_CMCLDEPS_" + lang)) {
- // For the MS resource compiler we need cmcldeps, but skip dependencies
- // for source-file try_compile cases because they are always fresh.
- if (!mf->GetIsSourceFileTryCompile()) {
- 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 += cmSystemTools::GetCMClDepsCommand();
- cldeps += "\" " + lang + " " + vars.Source + " \"$DEP_FILE\" $out \"";
- cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
- cldeps += "\" \"" + cl + "\" ";
- }
- } 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;
+ std::string const responseFlagVar =
+ "CMAKE_" + lang + "_RESPONSE_FILE_FLAG";
+ responseFlag = this->Makefile->GetSafeDefinition(responseFlagVar);
+ if (responseFlag.empty() && lang != "CUDA") {
+ responseFlag = "@";
}
}
- vars.Flags = flags.c_str();
- vars.DependencyFile = depfile.c_str();
-
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat(
@@ -481,15 +490,15 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
launcher += " ";
}
- if (explicitPP) {
- // Lookup the explicit preprocessing rule.
- std::string const ppVar = "CMAKE_" + lang + "_PREPROCESS_SOURCE";
- std::string const ppCmd =
- this->GetMakefile()->GetRequiredDefinition(ppVar);
+ std::string const cmakeCmd =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
+ if (explicitPP) {
+ cmNinjaRule rule(this->LanguagePreprocessRule(lang));
// Explicit preprocessing always uses a depfile.
- std::string const ppDeptype; // no deps= for multiple outputs
- std::string const ppDepfile = "$DEP_FILE";
+ rule.DepType = ""; // no deps= for multiple outputs
+ rule.DepFile = "$DEP_FILE";
cmRulePlaceholderExpander::RuleVariables ppVars;
ppVars.CMTargetName = vars.CMTargetName;
@@ -497,7 +506,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
ppVars.Language = vars.Language;
ppVars.Object = "$out"; // for RULE_LAUNCH_COMPILE
ppVars.PreprocessedSource = "$out";
- ppVars.DependencyFile = ppDepfile.c_str();
+ ppVars.DependencyFile = rule.DepFile.c_str();
// Preprocessing uses the original source,
// compilation uses preprocessed output.
@@ -505,7 +514,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
vars.Source = "$in";
// Preprocessing and compilation use the same flags.
- ppVars.Flags = vars.Flags;
+ std::string ppFlags = flags;
// Move preprocessor definitions to the preprocessor rule.
ppVars.Defines = vars.Defines;
@@ -515,106 +524,184 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
// compilation rule still needs them for the INCLUDE directive.
ppVars.Includes = vars.Includes;
+ // If using a response file, move defines, includes, and flags into it.
+ if (!responseFlag.empty()) {
+ rule.RspFile = "$RSP_FILE";
+ rule.RspContent = " ";
+ rule.RspContent += ppVars.Defines;
+ rule.RspContent += " ";
+ rule.RspContent += ppVars.Includes;
+ rule.RspContent += " ";
+ rule.RspContent += ppFlags;
+ ppFlags = responseFlag + rule.RspFile;
+ ppVars.Defines = "";
+ ppVars.Includes = "";
+ }
+
+ ppVars.Flags = ppFlags.c_str();
+
// Rule for preprocessing source file.
std::vector<std::string> ppCmds;
- cmSystemTools::ExpandListArgument(ppCmd, ppCmds);
+ {
+ // Lookup the explicit preprocessing rule.
+ std::string ppVar = "CMAKE_" + lang;
+ ppVar += "_PREPROCESS_SOURCE";
+ cmSystemTools::ExpandListArgument(
+ this->GetMakefile()->GetRequiredDefinition(ppVar), ppCmds);
+ }
- for (std::vector<std::string>::iterator i = ppCmds.begin();
- i != ppCmds.end(); ++i) {
- *i = launcher + *i;
+ for (std::string& i : ppCmds) {
+ i = launcher + i;
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
- *i, ppVars);
+ i, ppVars);
}
// Run CMake dependency scanner on preprocessed output.
- std::string const cmake = this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
- ppCmds.push_back(
- cmake + " -E cmake_ninja_depends"
- " --tdi=" +
- tdi + " --pp=$out"
- " --dep=$DEP_FILE" +
- (needDyndep ? " --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE" : ""));
-
- std::string const ppCmdLine =
- this->GetLocalGenerator()->BuildCommandLine(ppCmds);
+ {
+ std::string ccmd = cmakeCmd;
+ ccmd += " -E cmake_ninja_depends --tdi=";
+ ccmd += tdi;
+ ccmd += " --lang=";
+ ccmd += lang;
+ ccmd += " --pp=$out --dep=$DEP_FILE";
+ if (needDyndep) {
+ ccmd += " --obj=$OBJ_FILE --ddi=$DYNDEP_INTERMEDIATE_FILE";
+ }
+ ppCmds.emplace_back(std::move(ccmd));
+ }
+ rule.Command = this->GetLocalGenerator()->BuildCommandLine(ppCmds);
// Write the rule for preprocessing file of the given language.
- std::ostringstream ppComment;
- ppComment << "Rule for preprocessing " << lang << " files.";
- std::ostringstream ppDesc;
- ppDesc << "Building " << lang << " preprocessed $out";
- this->GetGlobalGenerator()->AddRule(this->LanguagePreprocessRule(lang),
- ppCmdLine, ppDesc.str(),
- ppComment.str(), ppDepfile, ppDeptype,
- /*rspfile*/ "",
- /*rspcontent*/ "",
- /*restat*/ "",
- /*generator*/ false);
+ rule.Comment = "Rule for preprocessing ";
+ rule.Comment += lang;
+ rule.Comment += " files.";
+ rule.Description = "Building ";
+ rule.Description += lang;
+ rule.Description += " preprocessed $out";
+ this->GetGlobalGenerator()->AddRule(rule);
}
if (needDyndep) {
// Write the rule for ninja dyndep file generation.
- std::vector<std::string> ddCmds;
-
-#ifdef _WIN32
- // Windows command line length is limited -> use response file for dyndep
- // rules
- std::string ddRspFile = "$out.rsp";
- std::string ddRspContent = "$in";
- std::string ddInput = "@" + ddRspFile;
-#else
- std::string ddRspFile;
- std::string ddRspContent;
- std::string ddInput = "$in";
-#endif
+ cmNinjaRule rule(this->LanguageDyndepRule(lang));
+ // Command line length is almost always limited -> use response file for
+ // dyndep rules
+ rule.RspFile = "$out.rsp";
+ rule.RspContent = "$in";
+
+ // Run CMake dependency scanner on the source file (using the preprocessed
+ // source if that was performed).
+ {
+ std::vector<std::string> ddCmds;
+ {
+ std::string ccmd = cmakeCmd;
+ ccmd += " -E cmake_ninja_dyndep --tdi=";
+ ccmd += tdi;
+ ccmd += " --lang=";
+ ccmd += lang;
+ ccmd += " --dd=$out ";
+ ccmd += "@";
+ ccmd += rule.RspFile;
+ ddCmds.emplace_back(std::move(ccmd));
+ }
+ rule.Command = this->GetLocalGenerator()->BuildCommandLine(ddCmds);
+ }
+ rule.Comment = "Rule to generate ninja dyndep files for ";
+ rule.Comment += lang;
+ rule.Comment += ".";
+ rule.Description = "Generating ";
+ rule.Description += lang;
+ rule.Description += " dyndep file $out";
+ this->GetGlobalGenerator()->AddRule(rule);
+ }
- // Run CMake dependency scanner on preprocessed output.
- std::string const cmake = this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
- ddCmds.push_back(cmake + " -E cmake_ninja_dyndep"
- " --tdi=" +
- tdi + " --dd=$out"
- " " +
- ddInput);
-
- std::string const ddCmdLine =
- this->GetLocalGenerator()->BuildCommandLine(ddCmds);
-
- std::ostringstream ddComment;
- ddComment << "Rule to generate ninja dyndep files for " << lang << ".";
- std::ostringstream ddDesc;
- ddDesc << "Generating " << lang << " dyndep file $out";
- this->GetGlobalGenerator()->AddRule(
- this->LanguageDyndepRule(lang), ddCmdLine, ddDesc.str(), ddComment.str(),
- /*depfile*/ "",
- /*deps*/ "", ddRspFile, ddRspContent,
- /*restat*/ "",
- /*generator*/ false);
+ cmNinjaRule rule(this->LanguageCompilerRule(lang));
+ // If using a response file, move defines, includes, and flags into it.
+ if (!responseFlag.empty()) {
+ rule.RspFile = "$RSP_FILE";
+ rule.RspContent = " ";
+ rule.RspContent += vars.Defines;
+ rule.RspContent += " ";
+ rule.RspContent += vars.Includes;
+ rule.RspContent += " ";
+ rule.RspContent += flags;
+ flags = responseFlag + rule.RspFile;
+ vars.Defines = "";
+ vars.Includes = "";
}
+ // Tell ninja dependency format so all deps can be loaded into a database
+ std::string cldeps;
+ if (explicitPP) {
+ // The explicit preprocessing step will handle dependency scanning.
+ } else if (this->NeedDepTypeMSVC(lang)) {
+ rule.DepType = "msvc";
+ rule.DepFile.clear();
+ flags += " /showIncludes";
+ } else if (mf->IsOn("CMAKE_NINJA_CMCLDEPS_" + lang)) {
+ // For the MS resource compiler we need cmcldeps, but skip dependencies
+ // for source-file try_compile cases because they are always fresh.
+ if (!mf->GetIsSourceFileTryCompile()) {
+ rule.DepType = "gcc";
+ rule.DepFile = "$DEP_FILE";
+ const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER")
+ ? mf->GetSafeDefinition("CMAKE_C_COMPILER")
+ : mf->GetSafeDefinition("CMAKE_CXX_COMPILER");
+ cldeps = "\"";
+ cldeps += cmSystemTools::GetCMClDepsCommand();
+ cldeps += "\" " + lang + " " + vars.Source + " $DEP_FILE $out \"";
+ cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX");
+ cldeps += "\" \"" + cl + "\" ";
+ }
+ } else {
+ rule.DepType = "gcc";
+ rule.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 = rule.DepFile.c_str();
+
// Rule for compiling object file.
std::vector<std::string> compileCmds;
if (lang == "CUDA") {
std::string cmdVar;
if (this->GeneratorTarget->GetPropertyAsBool(
"CUDA_SEPARABLE_COMPILATION")) {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION";
} else if (this->GeneratorTarget->GetPropertyAsBool(
"CUDA_PTX_COMPILATION")) {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_PTX_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION";
} else {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION";
}
- std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
+ const std::string& compileCmd = mf->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
} else {
- const std::string cmdVar =
- std::string("CMAKE_") + lang + "_COMPILE_OBJECT";
- std::string compileCmd = mf->GetRequiredDefinition(cmdVar);
+ const std::string cmdVar = "CMAKE_" + lang + "_COMPILE_OBJECT";
+ const std::string& compileCmd = mf->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
}
+ // See if we need to use a compiler launcher like ccache or distcc
+ std::string compilerLauncher;
+ if (!compileCmds.empty() &&
+ (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA")) {
+ std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
+ const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
+ if (clauncher && *clauncher) {
+ compilerLauncher = clauncher;
+ }
+ }
+
// Maybe insert an include-what-you-use runner.
if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) {
std::string const iwyu_prop = lang + "_INCLUDE_WHAT_YOU_USE";
@@ -623,10 +710,19 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
const char* tidy = this->GeneratorTarget->GetProperty(tidy_prop);
std::string const cpplint_prop = lang + "_CPPLINT";
const char* cpplint = this->GeneratorTarget->GetProperty(cpplint_prop);
- if ((iwyu && *iwyu) || (tidy && *tidy) || (cpplint && *cpplint)) {
- std::string run_iwyu = this->GetLocalGenerator()->ConvertToOutputFormat(
- cmSystemTools::GetCMakeCommand(), cmOutputConverter::SHELL);
- run_iwyu += " -E __run_iwyu";
+ std::string const cppcheck_prop = lang + "_CPPCHECK";
+ const char* cppcheck = this->GeneratorTarget->GetProperty(cppcheck_prop);
+ if ((iwyu && *iwyu) || (tidy && *tidy) || (cpplint && *cpplint) ||
+ (cppcheck && *cppcheck)) {
+ std::string run_iwyu = cmakeCmd;
+ run_iwyu += " -E __run_co_compile";
+ if (!compilerLauncher.empty()) {
+ // In __run_co_compile case the launcher command is supplied
+ // via --launcher=<maybe-list> and consumed
+ run_iwyu += " --launcher=";
+ run_iwyu += this->LocalGenerator->EscapeForShell(compilerLauncher);
+ compilerLauncher.clear();
+ }
if (iwyu && *iwyu) {
run_iwyu += " --iwyu=";
run_iwyu += this->GetLocalGenerator()->EscapeForShell(iwyu);
@@ -639,7 +735,12 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
run_iwyu += " --cpplint=";
run_iwyu += this->GetLocalGenerator()->EscapeForShell(cpplint);
}
- if ((tidy && *tidy) || (cpplint && *cpplint)) {
+ if (cppcheck && *cppcheck) {
+ run_iwyu += " --cppcheck=";
+ run_iwyu += this->GetLocalGenerator()->EscapeForShell(cppcheck);
+ }
+ if ((tidy && *tidy) || (cpplint && *cpplint) ||
+ (cppcheck && *cppcheck)) {
run_iwyu += " --source=$in";
}
run_iwyu += " -- ";
@@ -647,47 +748,41 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
}
}
- // Maybe insert a compiler launcher like ccache or distcc
- if (!compileCmds.empty() && (lang == "C" || lang == "CXX")) {
- std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
- const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
- if (clauncher && *clauncher) {
- std::vector<std::string> launcher_cmd;
- cmSystemTools::ExpandListArgument(clauncher, launcher_cmd, true);
- for (std::vector<std::string>::iterator i = launcher_cmd.begin(),
- e = launcher_cmd.end();
- i != e; ++i) {
- *i = this->LocalGenerator->EscapeForShell(*i);
+ // If compiler launcher was specified and not consumed above, it
+ // goes to the beginning of the command line.
+ if (!compileCmds.empty() && !compilerLauncher.empty()) {
+ std::vector<std::string> args;
+ cmSystemTools::ExpandListArgument(compilerLauncher, args, true);
+ if (!args.empty()) {
+ args[0] = this->LocalGenerator->ConvertToOutputFormat(
+ args[0], cmOutputConverter::SHELL);
+ for (std::string& i : cmMakeRange(args.begin() + 1, args.end())) {
+ i = this->LocalGenerator->EscapeForShell(i);
}
- std::string const& run_launcher = cmJoin(launcher_cmd, " ") + " ";
- compileCmds.front().insert(0, run_launcher);
}
+ compileCmds.front().insert(0, cmJoin(args, " ") + " ");
}
if (!compileCmds.empty()) {
compileCmds.front().insert(0, cldeps);
}
- for (std::vector<std::string>::iterator i = compileCmds.begin();
- i != compileCmds.end(); ++i) {
- *i = launcher + *i;
- rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i,
+ for (std::string& i : compileCmds) {
+ i = launcher + i;
+ rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), i,
vars);
}
- std::string cmdLine =
- this->GetLocalGenerator()->BuildCommandLine(compileCmds);
+ rule.Command = this->GetLocalGenerator()->BuildCommandLine(compileCmds);
// Write the rule for compiling file of the given language.
- std::ostringstream comment;
- comment << "Rule for compiling " << lang << " files.";
- std::ostringstream description;
- description << "Building " << lang << " object $out";
- this->GetGlobalGenerator()->AddRule(
- this->LanguageCompilerRule(lang), cmdLine, description.str(),
- comment.str(), depfile, deptype, rspfile, rspcontent,
- /*restat*/ "",
- /*generator*/ false);
+ rule.Comment = "Rule for compiling ";
+ rule.Comment += lang;
+ rule.Comment += " files.";
+ rule.Description = "Building ";
+ rule.Description += lang;
+ rule.Description += " object $out";
+ this->GetGlobalGenerator()->AddRule(rule);
}
void cmNinjaTargetGenerator::WriteObjectBuildStatements()
@@ -699,109 +794,141 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements()
<< cmState::GetTargetTypeName(this->GetGeneratorTarget()->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->GetGeneratorTarget());
- // Record the custom commands for this target. The container is used
- // in WriteObjectBuildStatement when called in a loop below.
- this->CustomCommands.push_back(cc);
+ const std::string& config =
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ {
+ std::vector<cmSourceFile const*> customCommands;
+ this->GeneratorTarget->GetCustomCommands(customCommands, config);
+ for (cmSourceFile const* sf : customCommands) {
+ cmCustomCommand const* cc = sf->GetCustomCommand();
+ this->GetLocalGenerator()->AddCustomCommandTarget(
+ cc, this->GetGeneratorTarget());
+ // Record the custom commands for this target. The container is used
+ // in WriteObjectBuildStatement when called in a loop below.
+ this->CustomCommands.push_back(cc);
+ }
}
- 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));
+ {
+ std::vector<cmSourceFile const*> headerSources;
+ this->GeneratorTarget->GetHeaderSources(headerSources, config);
+ this->OSXBundleGenerator->GenerateMacOSXContentStatements(
+ headerSources, this->MacOSXContentGenerator.get());
}
-
- cmNinjaDeps orderOnlyDeps;
- this->GetLocalGenerator()->AppendTargetDepends(
- this->GeneratorTarget, orderOnlyDeps, DependOnTargetOrdering);
-
- // Add order-only dependencies on other files associated with the target.
- orderOnlyDeps.insert(orderOnlyDeps.end(), this->ExtraFiles.begin(),
- this->ExtraFiles.end());
-
- // 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->GetLocalGenerator());
- const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
- const std::vector<std::string>& ccbyproducts = ccg.GetByproducts();
- std::transform(ccoutputs.begin(), ccoutputs.end(),
- std::back_inserter(orderOnlyDeps), MapToNinjaPath());
- std::transform(ccbyproducts.begin(), ccbyproducts.end(),
- std::back_inserter(orderOnlyDeps), MapToNinjaPath());
+ {
+ std::vector<cmSourceFile const*> extraSources;
+ this->GeneratorTarget->GetExtraSources(extraSources, config);
+ this->OSXBundleGenerator->GenerateMacOSXContentStatements(
+ extraSources, this->MacOSXContentGenerator.get());
+ }
+ {
+ std::vector<cmSourceFile const*> externalObjects;
+ this->GeneratorTarget->GetExternalObjects(externalObjects, config);
+ for (cmSourceFile const* sf : externalObjects) {
+ this->Objects.push_back(this->GetSourceFilePath(sf));
+ }
}
-
- std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end());
- orderOnlyDeps.erase(std::unique(orderOnlyDeps.begin(), orderOnlyDeps.end()),
- orderOnlyDeps.end());
{
- cmNinjaDeps orderOnlyTarget;
- orderOnlyTarget.push_back(this->OrderDependsTargetForTarget());
- this->GetGlobalGenerator()->WritePhonyBuild(
- this->GetBuildFileStream(),
- "Order-only phony target for " + this->GetTargetName(), orderOnlyTarget,
- cmNinjaDeps(), cmNinjaDeps(), orderOnlyDeps);
+ cmNinjaBuild build("phony");
+ build.Comment = "Order-only phony target for " + this->GetTargetName();
+ build.Outputs.push_back(this->OrderDependsTargetForTarget());
+
+ cmNinjaDeps& orderOnlyDeps = build.OrderOnlyDeps;
+ this->GetLocalGenerator()->AppendTargetDepends(
+ this->GeneratorTarget, orderOnlyDeps, DependOnTargetOrdering);
+
+ // Add order-only dependencies on other files associated with the target.
+ cmAppend(orderOnlyDeps, this->ExtraFiles);
+
+ // Add order-only dependencies on custom command outputs.
+ for (cmCustomCommand const* cc : this->CustomCommands) {
+ cmCustomCommandGenerator ccg(*cc, this->GetConfigName(),
+ this->GetLocalGenerator());
+ const std::vector<std::string>& ccoutputs = ccg.GetOutputs();
+ const std::vector<std::string>& ccbyproducts = ccg.GetByproducts();
+ std::transform(ccoutputs.begin(), ccoutputs.end(),
+ std::back_inserter(orderOnlyDeps), MapToNinjaPath());
+ std::transform(ccbyproducts.begin(), ccbyproducts.end(),
+ std::back_inserter(orderOnlyDeps), MapToNinjaPath());
+ }
+
+ std::sort(orderOnlyDeps.begin(), orderOnlyDeps.end());
+ orderOnlyDeps.erase(
+ std::unique(orderOnlyDeps.begin(), orderOnlyDeps.end()),
+ orderOnlyDeps.end());
+
+ // The phony target must depend on at least one input or ninja will explain
+ // that "output ... of phony edge with no inputs doesn't exist" and
+ // consider the phony output "dirty".
+ if (orderOnlyDeps.empty()) {
+ // Any path that always exists will work here. It would be nice to
+ // use just "." but that is not supported by Ninja < 1.7.
+ std::string tgtDir;
+ tgtDir += this->LocalGenerator->GetCurrentBinaryDirectory();
+ tgtDir += "/";
+ tgtDir +=
+ this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
+ orderOnlyDeps.push_back(this->ConvertToNinjaPath(tgtDir));
+ }
+
+ this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
}
- 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);
+
+ {
+ std::vector<cmSourceFile const*> objectSources;
+ this->GeneratorTarget->GetObjectSources(objectSources, config);
+ for (cmSourceFile const* sf : objectSources) {
+ this->WriteObjectBuildStatement(sf);
+ }
}
- if (!this->DDIFiles.empty()) {
- std::string const ddComment;
- std::string const ddRule = this->LanguageDyndepRule("Fortran");
- cmNinjaDeps ddOutputs;
- cmNinjaDeps ddImplicitOuts;
- cmNinjaDeps const& ddExplicitDeps = this->DDIFiles;
- cmNinjaDeps ddImplicitDeps;
- cmNinjaDeps ddOrderOnlyDeps;
- cmNinjaVars ddVars;
+ for (auto const& langDDIFiles : this->DDIFiles) {
+ std::string const& language = langDDIFiles.first;
+ cmNinjaDeps const& ddiFiles = langDDIFiles.second;
- this->WriteTargetDependInfo("Fortran");
+ cmNinjaBuild build(this->LanguageDyndepRule(language));
+ build.Outputs.push_back(this->GetDyndepFilePath(language));
+ build.ExplicitDeps = ddiFiles;
- ddOutputs.push_back(this->GetDyndepFilePath("Fortran"));
+ this->WriteTargetDependInfo(language);
// Make sure dyndep files for all our dependencies have already
- // been generated so that the 'FortranModules.json' files they
+ // been generated so that the '<LANG>Modules.json' files they
// produced as side-effects are available for us to read.
- // Ideally we should depend on the 'FortranModules.json' files
+ // Ideally we should depend on the '<LANG>Modules.json' files
// from our dependencies directly, but we don't know which of
// our dependencies produces them. Fixing this will require
// refactoring the Ninja generator to generate targets in
// dependency order so that we can collect the needed information.
this->GetLocalGenerator()->AppendTargetDepends(
- this->GeneratorTarget, ddOrderOnlyDeps, DependOnTargetArtifact);
+ this->GeneratorTarget, build.OrderOnlyDeps, DependOnTargetArtifact);
- this->GetGlobalGenerator()->WriteBuild(
- this->GetBuildFileStream(), ddComment, ddRule, ddOutputs, ddImplicitOuts,
- ddExplicitDeps, ddImplicitDeps, ddOrderOnlyDeps, ddVars);
+ this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
}
this->GetBuildFileStream() << "\n";
+
+ if (!this->SwiftOutputMap.empty()) {
+ std::string const mapFilePath = this->ConvertToNinjaPath(
+ this->GeneratorTarget->GetSupportDirectory() + "/output-file-map.json");
+ std::string const targetSwiftDepsPath = [this]() -> std::string {
+ cmGeneratorTarget const* target = this->GeneratorTarget;
+ if (const char* name = target->GetProperty("Swift_DEPENDENCIES_FILE")) {
+ return name;
+ }
+ return this->ConvertToNinjaPath(target->GetSupportDirectory() + "/" +
+ target->GetName() + ".swiftdeps");
+ }();
+
+ // build the global target dependencies
+ // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps
+ Json::Value deps(Json::objectValue);
+ deps["swift-dependencies"] = targetSwiftDepsPath;
+ this->SwiftOutputMap[""] = deps;
+
+ cmGeneratedFileStream output(mapFilePath);
+ output << this->SwiftOutputMap;
+ }
}
void cmNinjaTargetGenerator::WriteObjectBuildStatement(
@@ -817,55 +944,82 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
std::string const objectFileDir =
cmSystemTools::GetFilenamePath(objectFileName);
- cmNinjaVars vars;
+ std::string cmakeVarLang = "CMAKE_";
+ cmakeVarLang += language;
+
+ // build response file name
+ std::string cmakeLinkVar = cmakeVarLang + "_RESPONSE_FILE_FLAG";
+
+ const char* flag = GetMakefile()->GetDefinition(cmakeLinkVar);
+
+ bool const lang_supports_response =
+ !(language == "RC" || (language == "CUDA" && !flag));
+ int const commandLineLengthLimit =
+ ((lang_supports_response && this->ForceResponseFile())) ? -1 : 0;
+
+ cmNinjaBuild objBuild(this->LanguageCompilerRule(language));
+ cmNinjaVars& vars = objBuild.Variables;
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
vars["DEFINES"] = this->ComputeDefines(source, language);
- vars["INCLUDES"] = this->GetIncludes(language);
+ vars["INCLUDES"] = this->ComputeIncludes(source, language);
+
if (!this->NeedDepTypeMSVC(language)) {
- vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- objectFileName + ".d", cmOutputConverter::SHELL);
+ bool replaceExt(false);
+ if (!language.empty()) {
+ std::string repVar = "CMAKE_";
+ repVar += language;
+ repVar += "_DEPFILE_EXTENSION_REPLACE";
+ replaceExt = this->Makefile->IsOn(repVar);
+ }
+ if (!replaceExt) {
+ // use original code
+ vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
+ objectFileName + ".d", cmOutputConverter::SHELL);
+ } else {
+ // Replace the original source file extension with the
+ // depend file extension.
+ std::string dependFileName =
+ cmSystemTools::GetFilenameWithoutLastExtension(objectFileName) + ".d";
+ vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
+ objectFileDir + "/" + dependFileName, cmOutputConverter::SHELL);
+ }
}
this->ExportObjectCompileCommand(
language, sourceFileName, objectDir, objectFileName, objectFileDir,
vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"]);
- std::string comment;
- std::string rule = this->LanguageCompilerRule(language);
-
- cmNinjaDeps outputs;
- outputs.push_back(objectFileName);
+ objBuild.Outputs.push_back(objectFileName);
// Add this object to the list of object files.
this->Objects.push_back(objectFileName);
- cmNinjaDeps explicitDeps;
- explicitDeps.push_back(sourceFileName);
+ objBuild.ExplicitDeps.push_back(sourceFileName);
- cmNinjaDeps implicitDeps;
if (const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) {
- std::vector<std::string> depList;
- cmSystemTools::ExpandListArgument(objectDeps, depList);
- for (std::vector<std::string>::iterator odi = depList.begin();
- odi != depList.end(); ++odi) {
- if (cmSystemTools::FileIsFullPath(*odi)) {
- *odi = cmSystemTools::CollapseFullPath(*odi);
+ std::vector<std::string> depList =
+ cmSystemTools::ExpandedListArgument(objectDeps);
+ for (std::string& odi : depList) {
+ if (cmSystemTools::FileIsFullPath(odi)) {
+ odi = cmSystemTools::CollapseFullPath(odi);
}
}
std::transform(depList.begin(), depList.end(),
- std::back_inserter(implicitDeps), MapToNinjaPath());
+ std::back_inserter(objBuild.ImplicitDeps),
+ MapToNinjaPath());
}
- cmNinjaDeps orderOnlyDeps;
- orderOnlyDeps.push_back(this->OrderDependsTargetForTarget());
+ objBuild.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() &&
+ if (source->GetIsGenerated() &&
+ !source->GetPropertyAsBool("__CMAKE_GENERATED_BY_CMAKE") &&
+ !source->GetCustomCommand() &&
!this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) {
- this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName,
- orderOnlyDeps);
+ this->GetGlobalGenerator()->AddAssumedSourceDependencies(
+ sourceFileName, objBuild.OrderOnlyDeps);
}
// For some cases we need to generate a ninja dyndep file.
@@ -874,80 +1028,101 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
// For some cases we do an explicit preprocessor invocation.
bool const explicitPP = this->NeedExplicitPreprocessing(language);
if (explicitPP) {
- std::string const ppComment;
- std::string const ppRule = this->LanguagePreprocessRule(language);
- cmNinjaDeps ppOutputs;
- cmNinjaDeps ppImplicitOuts;
- cmNinjaDeps ppExplicitDeps;
- cmNinjaDeps ppImplicitDeps;
- cmNinjaDeps ppOrderOnlyDeps;
- cmNinjaVars ppVars;
+ cmNinjaBuild ppBuild(this->LanguagePreprocessRule(language));
std::string const ppFileName =
this->ConvertToNinjaPath(this->GetPreprocessedFilePath(source));
- ppOutputs.push_back(ppFileName);
+ ppBuild.Outputs.push_back(ppFileName);
- // Move compilation dependencies to the preprocessing build statement.
- std::swap(ppExplicitDeps, explicitDeps);
- std::swap(ppImplicitDeps, implicitDeps);
- std::swap(ppOrderOnlyDeps, orderOnlyDeps);
- std::swap(ppVars["IN_ABS"], vars["IN_ABS"]);
+ ppBuild.RspFile = ppFileName + ".rsp";
- // The actual compilation will now use the preprocessed source.
- explicitDeps.push_back(ppFileName);
+ bool const compilePP = this->UsePreprocessedSource(language);
+ if (compilePP) {
+ // Move compilation dependencies to the preprocessing build statement.
+ std::swap(ppBuild.ExplicitDeps, objBuild.ExplicitDeps);
+ std::swap(ppBuild.ImplicitDeps, objBuild.ImplicitDeps);
+ std::swap(ppBuild.OrderOnlyDeps, objBuild.OrderOnlyDeps);
+ std::swap(ppBuild.Variables["IN_ABS"], vars["IN_ABS"]);
- // Preprocessing and compilation use the same flags.
- ppVars["FLAGS"] = vars["FLAGS"];
+ // The actual compilation will now use the preprocessed source.
+ objBuild.ExplicitDeps.push_back(ppFileName);
+ } else {
+ // Copy compilation dependencies to the preprocessing build statement.
+ ppBuild.ExplicitDeps = objBuild.ExplicitDeps;
+ ppBuild.ImplicitDeps = objBuild.ImplicitDeps;
+ ppBuild.OrderOnlyDeps = objBuild.OrderOnlyDeps;
+ ppBuild.Variables["IN_ABS"] = vars["IN_ABS"];
+ }
+
+ // Preprocessing and compilation generally use the same flags.
+ ppBuild.Variables["FLAGS"] = vars["FLAGS"];
- // Move preprocessor definitions to the preprocessor build statement.
- std::swap(ppVars["DEFINES"], vars["DEFINES"]);
+ if (compilePP) {
+ // In case compilation requires flags that are incompatible with
+ // preprocessing, include them here.
+ std::string const& postFlag = this->Makefile->GetSafeDefinition(
+ "CMAKE_" + language + "_POSTPROCESS_FLAG");
+ this->LocalGenerator->AppendFlags(vars["FLAGS"], postFlag);
+ }
+
+ if (compilePP) {
+ // Move preprocessor definitions to the preprocessor build statement.
+ std::swap(ppBuild.Variables["DEFINES"], vars["DEFINES"]);
+ } else {
+ // Copy preprocessor definitions to the preprocessor build statement.
+ ppBuild.Variables["DEFINES"] = vars["DEFINES"];
+ }
// Copy include directories to the preprocessor build statement. The
// Fortran compilation build statement still needs them for the INCLUDE
// directive.
- ppVars["INCLUDES"] = vars["INCLUDES"];
+ ppBuild.Variables["INCLUDES"] = vars["INCLUDES"];
- // Prepend source file's original directory as an include directory
- // so e.g. Fortran INCLUDE statements can look for files in it.
- std::vector<std::string> sourceDirectory;
- sourceDirectory.push_back(
- cmSystemTools::GetParentDirectory(source->GetFullPath()));
+ if (compilePP) {
+ // Prepend source file's original directory as an include directory
+ // so e.g. Fortran INCLUDE statements can look for files in it.
+ std::vector<std::string> sourceDirectory;
+ sourceDirectory.push_back(
+ cmSystemTools::GetParentDirectory(source->GetFullPath()));
- std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags(
- sourceDirectory, this->GeneratorTarget, language, false, false,
- this->GetConfigName());
+ std::string sourceDirectoryFlag = this->LocalGenerator->GetIncludeFlags(
+ sourceDirectory, this->GeneratorTarget, language, false, false,
+ this->GetConfigName());
- vars["INCLUDES"] = sourceDirectoryFlag + " " + vars["INCLUDES"];
+ vars["INCLUDES"] = sourceDirectoryFlag + " " + vars["INCLUDES"];
+ }
// Explicit preprocessing always uses a depfile.
- ppVars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- ppFileName + ".d", cmOutputConverter::SHELL);
- // The actual compilation does not need a depfile because it
- // depends on the already-preprocessed source.
- vars.erase("DEP_FILE");
+ ppBuild.Variables["DEP_FILE"] =
+ this->GetLocalGenerator()->ConvertToOutputFormat(
+ objectFileName + ".pp.d", cmOutputConverter::SHELL);
+ if (compilePP) {
+ // The actual compilation does not need a depfile because it
+ // depends on the already-preprocessed source.
+ vars.erase("DEP_FILE");
+ }
if (needDyndep) {
// Tell dependency scanner the object file that will result from
- // compiling the preprocessed source.
- ppVars["OBJ_FILE"] = objectFileName;
+ // compiling the source.
+ ppBuild.Variables["OBJ_FILE"] = objectFileName;
// Tell dependency scanner where to store dyndep intermediate results.
- std::string const ddiFile = ppFileName + ".ddi";
- ppVars["DYNDEP_INTERMEDIATE_FILE"] = ddiFile;
- ppImplicitOuts.push_back(ddiFile);
- this->DDIFiles.push_back(ddiFile);
+ std::string const ddiFile = objectFileName + ".ddi";
+ ppBuild.Variables["DYNDEP_INTERMEDIATE_FILE"] = ddiFile;
+ ppBuild.ImplicitOuts.push_back(ddiFile);
+ this->DDIFiles[language].push_back(ddiFile);
}
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
- ppVars);
+ ppBuild.Variables);
- this->GetGlobalGenerator()->WriteBuild(
- this->GetBuildFileStream(), ppComment, ppRule, ppOutputs, ppImplicitOuts,
- ppExplicitDeps, ppImplicitDeps, ppOrderOnlyDeps, ppVars);
+ this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), ppBuild,
+ commandLineLengthLimit);
}
if (needDyndep) {
std::string const dyndep = this->GetDyndepFilePath(language);
- orderOnlyDeps.push_back(dyndep);
+ objBuild.OrderOnlyDeps.push_back(dyndep);
vars["dyndep"] = dyndep;
}
@@ -963,25 +1138,23 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
this->SetMsvcTargetPdbVariable(vars);
- bool const lang_supports_response =
- !(language == "RC" || language == "CUDA");
- int const commandLineLengthLimit =
- ((lang_supports_response && this->ForceResponseFile())) ? -1 : 0;
- std::string const rspfile = objectFileName + ".rsp";
+ objBuild.RspFile = objectFileName + ".rsp";
- this->GetGlobalGenerator()->WriteBuild(
- this->GetBuildFileStream(), comment, rule, outputs,
- /*implicitOuts=*/cmNinjaDeps(), explicitDeps, implicitDeps, orderOnlyDeps,
- vars, rspfile, commandLineLengthLimit);
+ if (language == "Swift") {
+ this->EmitSwiftDependencyInfo(source);
+ } else {
+ this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
+ objBuild, commandLineLengthLimit);
+ }
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);
+ cmNinjaBuild build("phony");
+ build.Comment = "Additional output files.";
+ build.Outputs = cmSystemTools::ExpandedListArgument(objectOutputs);
+ std::transform(build.Outputs.begin(), build.Outputs.end(),
+ build.Outputs.begin(), MapToNinjaPath());
+ build.ExplicitDeps = objBuild.Outputs;
+ this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(), build);
}
}
@@ -999,6 +1172,10 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang)
mod_dir = this->Makefile->GetCurrentBinaryDirectory();
}
tdi["module-dir"] = mod_dir;
+ tdi["submodule-sep"] =
+ this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_SEP");
+ tdi["submodule-ext"] =
+ this->Makefile->GetSafeDefinition("CMAKE_Fortran_SUBMODULE_EXT");
}
tdi["dir-cur-bld"] = this->Makefile->GetCurrentBinaryDirectory();
@@ -1010,26 +1187,69 @@ void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang)
std::vector<std::string> includes;
this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
lang, this->GetConfigName());
- for (std::vector<std::string>::iterator i = includes.begin();
- i != includes.end(); ++i) {
+ for (std::string const& i : includes) {
// Convert the include directories the same way we do for -I flags.
// See upstream ninja issue 1251.
- tdi_include_dirs.append(this->ConvertToNinjaPath(*i));
+ tdi_include_dirs.append(this->ConvertToNinjaPath(i));
}
Json::Value& tdi_linked_target_dirs = tdi["linked-target-dirs"] =
Json::arrayValue;
- std::vector<std::string> linked = this->GetLinkedTargetDirectories();
- for (std::vector<std::string>::iterator i = linked.begin();
- i != linked.end(); ++i) {
- tdi_linked_target_dirs.append(*i);
+ for (std::string const& l : this->GetLinkedTargetDirectories()) {
+ tdi_linked_target_dirs.append(l);
}
std::string const tdin = this->GetTargetDependInfoPath(lang);
- cmGeneratedFileStream tdif(tdin.c_str());
+ cmGeneratedFileStream tdif(tdin);
tdif << tdi;
}
+void cmNinjaTargetGenerator::EmitSwiftDependencyInfo(
+ cmSourceFile const* source)
+{
+ std::string const sourceFilePath =
+ this->ConvertToNinjaPath(this->GetSourceFilePath(source));
+ std::string const objectFilePath =
+ this->ConvertToNinjaPath(this->GetObjectFilePath(source));
+ std::string const swiftDepsPath = [source, objectFilePath]() -> std::string {
+ if (const char* name = source->GetProperty("Swift_DEPENDENCIES_FILE")) {
+ return name;
+ }
+ return objectFilePath + ".swiftdeps";
+ }();
+ std::string const swiftDiaPath = [source, objectFilePath]() -> std::string {
+ if (const char* name = source->GetProperty("Swift_DIAGNOSTICS_FILE")) {
+ return name;
+ }
+ return objectFilePath + ".dia";
+ }();
+ std::string const makeDepsPath = [this, source]() -> std::string {
+ cmLocalNinjaGenerator const* local = this->GetLocalGenerator();
+ std::string const objectFileName =
+ this->ConvertToNinjaPath(this->GetObjectFilePath(source));
+ std::string const objectFileDir =
+ cmSystemTools::GetFilenamePath(objectFileName);
+
+ if (this->Makefile->IsOn("CMAKE_Swift_DEPFLE_EXTNSION_REPLACE")) {
+ std::string dependFileName =
+ cmSystemTools::GetFilenameWithoutLastExtension(objectFileName) + ".d";
+ return local->ConvertToOutputFormat(objectFileDir + "/" + dependFileName,
+ cmOutputConverter::SHELL);
+ }
+ return local->ConvertToOutputFormat(objectFileName + ".d",
+ cmOutputConverter::SHELL);
+ }();
+
+ // build the source file mapping
+ // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps
+ Json::Value entry = Json::Value(Json::objectValue);
+ entry["object"] = objectFilePath;
+ entry["dependencies"] = makeDepsPath;
+ entry["swift-dependencies"] = swiftDepsPath;
+ entry["diagnostics"] = swiftDiaPath;
+ SwiftOutputMap[sourceFilePath] = entry;
+}
+
void cmNinjaTargetGenerator::ExportObjectCompileCommand(
std::string const& language, std::string const& sourceFileName,
std::string const& objectDir, std::string const& objectFileName,
@@ -1045,11 +1265,12 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
std::string escapedSourceFileName = sourceFileName;
- if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str())) {
- escapedSourceFileName = cmSystemTools::CollapseFullPath(
- escapedSourceFileName, this->GetGlobalGenerator()
- ->GetCMakeInstance()
- ->GetHomeOutputDirectory());
+ if (!cmSystemTools::FileIsFullPath(sourceFileName)) {
+ escapedSourceFileName =
+ cmSystemTools::CollapseFullPath(escapedSourceFileName,
+ this->GetGlobalGenerator()
+ ->GetCMakeInstance()
+ ->GetHomeOutputDirectory());
}
escapedSourceFileName = this->LocalGenerator->ConvertToOutputFormat(
@@ -1069,31 +1290,29 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
std::string cmdVar;
if (this->GeneratorTarget->GetPropertyAsBool(
"CUDA_SEPARABLE_COMPILATION")) {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION";
} else if (this->GeneratorTarget->GetPropertyAsBool(
"CUDA_PTX_COMPILATION")) {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_PTX_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION";
} else {
- cmdVar = std::string("CMAKE_CUDA_COMPILE_WHOLE_COMPILATION");
+ cmdVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION";
}
- std::string compileCmd =
+ const std::string& compileCmd =
this->GetMakefile()->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
} else {
- const std::string cmdVar =
- std::string("CMAKE_") + language + "_COMPILE_OBJECT";
- std::string compileCmd =
+ const std::string cmdVar = "CMAKE_" + language + "_COMPILE_OBJECT";
+ const std::string& compileCmd =
this->GetMakefile()->GetRequiredDefinition(cmdVar);
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
}
- CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
- for (std::vector<std::string>::iterator i = compileCmds.begin();
- i != compileCmds.end(); ++i) {
+ for (std::string& i : compileCmds) {
// no launcher for CMAKE_EXPORT_COMPILE_COMMANDS
- rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i,
+ rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), i,
compileObjectVars);
}
@@ -1103,19 +1322,43 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, sourceFileName);
}
+void cmNinjaTargetGenerator::AdditionalCleanFiles()
+{
+ if (const char* prop_value =
+ this->GeneratorTarget->GetProperty("ADDITIONAL_CLEAN_FILES")) {
+ cmLocalNinjaGenerator* lg = this->LocalGenerator;
+ std::vector<std::string> cleanFiles;
+ {
+ cmGeneratorExpression ge;
+ auto cge = ge.Parse(prop_value);
+ cmSystemTools::ExpandListArgument(
+ cge->Evaluate(lg,
+ this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"),
+ false, this->GeneratorTarget, nullptr, nullptr),
+ cleanFiles);
+ }
+ std::string const& binaryDir = lg->GetCurrentBinaryDirectory();
+ cmGlobalNinjaGenerator* gg = lg->GetGlobalNinjaGenerator();
+ for (std::string const& cleanFile : cleanFiles) {
+ // Support relative paths
+ gg->AddAdditionalCleanFile(
+ cmSystemTools::CollapseFullPath(cleanFile, binaryDir));
+ }
+ }
+}
+
void cmNinjaTargetGenerator::EnsureDirectoryExists(
const std::string& path) const
{
- if (cmSystemTools::FileIsFullPath(path.c_str())) {
- cmSystemTools::MakeDirectory(path.c_str());
+ if (cmSystemTools::FileIsFullPath(path)) {
+ cmSystemTools::MakeDirectory(path);
} else {
cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
- std::string fullPath =
- std::string(gg->GetCMakeInstance()->GetHomeOutputDirectory());
+ std::string fullPath = gg->GetCMakeInstance()->GetHomeOutputDirectory();
// Also ensures their is a trailing slash.
gg->StripNinjaOutputPathPrefixAsSuffix(fullPath);
fullPath += path;
- cmSystemTools::MakeDirectory(fullPath.c_str());
+ cmSystemTools::MakeDirectory(fullPath);
}
}
@@ -1151,7 +1394,7 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
output);
// Add as a dependency to the target so that it gets called.
- this->Generator->ExtraFiles.push_back(output);
+ this->Generator->ExtraFiles.push_back(std::move(output));
}
void cmNinjaTargetGenerator::addPoolNinjaVariable(
diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h
index 5eb7a9a49..3055e18c3 100644
--- a/Source/cmNinjaTargetGenerator.h
+++ b/Source/cmNinjaTargetGenerator.h
@@ -3,13 +3,17 @@
#ifndef cmNinjaTargetGenerator_h
#define cmNinjaTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+
+#include "cm_jsoncpp_value.h"
#include "cmCommonTargetGenerator.h"
#include "cmGlobalNinjaGenerator.h"
#include "cmNinjaTypes.h"
#include "cmOSXBundleGenerator.h"
+#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <string>
#include <vector>
@@ -25,13 +29,14 @@ class cmNinjaTargetGenerator : public cmCommonTargetGenerator
{
public:
/// Create a cmNinjaTargetGenerator according to the @a target's type.
- static cmNinjaTargetGenerator* New(cmGeneratorTarget* target);
+ static std::unique_ptr<cmNinjaTargetGenerator> New(
+ cmGeneratorTarget* target);
/// Build a NinjaTargetGenerator.
cmNinjaTargetGenerator(cmGeneratorTarget* target);
/// Destructor.
- ~cmNinjaTargetGenerator() CM_OVERRIDE;
+ ~cmNinjaTargetGenerator() override;
virtual void Generate() = 0;
@@ -64,6 +69,7 @@ protected:
bool NeedExplicitPreprocessing(std::string const& lang) const;
std::string LanguageDyndepRule(std::string const& lang) const;
bool NeedDyndep(std::string const& lang) const;
+ bool UsePreprocessedSource(std::string const& lang) const;
std::string OrderDependsTargetForTarget();
@@ -77,12 +83,14 @@ protected:
std::string ComputeFlagsForObject(cmSourceFile const* source,
const std::string& language);
- void AddIncludeFlags(std::string& flags,
- std::string const& lang) CM_OVERRIDE;
+ void AddIncludeFlags(std::string& flags, std::string const& lang) override;
std::string ComputeDefines(cmSourceFile const* source,
const std::string& language);
+ std::string ComputeIncludes(cmSourceFile const* source,
+ const std::string& language);
+
std::string ConvertToNinjaPath(const std::string& path) const
{
return this->GetGlobalGenerator()->ConvertToNinjaPath(path);
@@ -93,7 +101,7 @@ protected:
}
/// @return the list of link dependency for the given target @a target.
- cmNinjaDeps ComputeLinkDeps() const;
+ cmNinjaDeps ComputeLinkDeps(const std::string& linkLanguage) const;
/// @return the source file path for the given @a source.
std::string GetSourceFilePath(cmSourceFile const* source) const;
@@ -122,18 +130,22 @@ protected:
void WriteObjectBuildStatement(cmSourceFile const* source);
void WriteTargetDependInfo(std::string const& lang);
+ void EmitSwiftDependencyInfo(cmSourceFile const* source);
+
void ExportObjectCompileCommand(
std::string const& language, std::string const& sourceFileName,
std::string const& objectDir, std::string const& objectFileName,
std::string const& objectFileDir, std::string const& flags,
std::string const& defines, std::string const& includes);
+ void AdditionalCleanFiles();
+
cmNinjaDeps GetObjects() const { return this->Objects; }
void EnsureDirectoryExists(const std::string& dir) const;
void EnsureParentDirectoryExists(const std::string& path) const;
- // write rules for Mac OS X Application Bundle content.
+ // write rules for macOS Application Bundle content.
struct MacOSXContentGeneratorType
: cmOSXBundleGenerator::MacOSXContentGeneratorType
{
@@ -142,17 +154,16 @@ protected:
{
}
- void operator()(cmSourceFile const& source,
- const char* pkgloc) CM_OVERRIDE;
+ void operator()(cmSourceFile const& source, const char* pkgloc) override;
private:
cmNinjaTargetGenerator* Generator;
};
friend struct MacOSXContentGeneratorType;
- MacOSXContentGeneratorType* MacOSXContentGenerator;
+ std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
// Properly initialized by sub-classes.
- cmOSXBundleGenerator* OSXBundleGenerator;
+ std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator;
std::set<std::string> MacContentFolders;
void addPoolNinjaVariable(const std::string& pool_property,
@@ -164,7 +175,10 @@ private:
cmLocalNinjaGenerator* LocalGenerator;
/// List of object files for this target.
cmNinjaDeps Objects;
- cmNinjaDeps DDIFiles; // TODO: Make per-language.
+ // Fortran Support
+ std::map<std::string, cmNinjaDeps> DDIFiles;
+ // Swift Support
+ Json::Value SwiftOutputMap;
std::vector<cmCustomCommand const*> CustomCommands;
cmNinjaDeps ExtraFiles;
};
diff --git a/Source/cmNinjaTypes.h b/Source/cmNinjaTypes.h
index ec435d9dd..52c05b62c 100644
--- a/Source/cmNinjaTypes.h
+++ b/Source/cmNinjaTypes.h
@@ -6,7 +6,9 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
+#include <set>
#include <string>
+#include <utility>
#include <vector>
enum cmNinjaTargetDepends
@@ -16,6 +18,47 @@ enum cmNinjaTargetDepends
};
typedef std::vector<std::string> cmNinjaDeps;
+typedef std::set<std::string> cmNinjaOuts;
typedef std::map<std::string, std::string> cmNinjaVars;
+class cmNinjaRule
+{
+public:
+ cmNinjaRule(std::string name)
+ : Name(std::move(name))
+ {
+ }
+
+ std::string Name;
+ std::string Command;
+ std::string Description;
+ std::string Comment;
+ std::string DepFile;
+ std::string DepType;
+ std::string RspFile;
+ std::string RspContent;
+ std::string Restat;
+ bool Generator = false;
+};
+
+class cmNinjaBuild
+{
+public:
+ cmNinjaBuild() = default;
+ cmNinjaBuild(std::string rule)
+ : Rule(std::move(rule))
+ {
+ }
+
+ std::string Comment;
+ std::string Rule;
+ cmNinjaDeps Outputs;
+ cmNinjaDeps ImplicitOuts;
+ cmNinjaDeps ExplicitDeps;
+ cmNinjaDeps ImplicitDeps;
+ cmNinjaDeps OrderOnlyDeps;
+ cmNinjaVars Variables;
+ std::string RspFile;
+};
+
#endif // ! cmNinjaTypes_h
diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx
index 500ff4a45..e774b53b5 100644
--- a/Source/cmNinjaUtilityTargetGenerator.cxx
+++ b/Source/cmNinjaUtilityTargetGenerator.cxx
@@ -14,11 +14,12 @@
#include "cmSourceFile.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cmake.h"
#include <algorithm>
+#include <array>
#include <iterator>
#include <string>
+#include <utility>
#include <vector>
cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(
@@ -27,83 +28,78 @@ cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(
{
}
-cmNinjaUtilityTargetGenerator::~cmNinjaUtilityTargetGenerator()
-{
-}
+cmNinjaUtilityTargetGenerator::~cmNinjaUtilityTargetGenerator() = default;
void cmNinjaUtilityTargetGenerator::Generate()
{
- std::string utilCommandName =
- this->GetLocalGenerator()->GetCurrentBinaryDirectory();
- utilCommandName += cmake::GetCMakeFilesDirectory();
+ cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
+ cmLocalNinjaGenerator* lg = this->GetLocalGenerator();
+ cmGeneratorTarget* genTarget = this->GetGeneratorTarget();
+
+ std::string utilCommandName = lg->GetCurrentBinaryDirectory();
+ utilCommandName += "/CMakeFiles";
utilCommandName += "/";
utilCommandName += this->GetTargetName() + ".util";
utilCommandName = this->ConvertToNinjaPath(utilCommandName);
+ cmNinjaBuild phonyBuild("phony");
std::vector<std::string> commands;
- cmNinjaDeps deps, outputs, util_outputs(1, utilCommandName);
-
- const std::vector<cmCustomCommand>* cmdLists[2] = {
- &this->GetGeneratorTarget()->GetPreBuildCommands(),
- &this->GetGeneratorTarget()->GetPostBuildCommands()
- };
+ cmNinjaDeps deps, util_outputs(1, utilCommandName);
bool uses_terminal = false;
-
- 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->GetLocalGenerator());
- this->GetLocalGenerator()->AppendCustomCommandDeps(ccg, deps);
- this->GetLocalGenerator()->AppendCustomCommandLines(ccg, commands);
- std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
- std::transform(ccByproducts.begin(), ccByproducts.end(),
- std::back_inserter(util_outputs), MapToNinjaPath());
- if (ci->GetUsesTerminal()) {
- uses_terminal = true;
+ {
+ std::array<std::vector<cmCustomCommand> const*, 2> const cmdLists = {
+ { &genTarget->GetPreBuildCommands(), &genTarget->GetPostBuildCommands() }
+ };
+
+ for (std::vector<cmCustomCommand> const* cmdList : cmdLists) {
+ for (cmCustomCommand const& ci : *cmdList) {
+ cmCustomCommandGenerator ccg(ci, this->GetConfigName(), lg);
+ lg->AppendCustomCommandDeps(ccg, deps);
+ lg->AppendCustomCommandLines(ccg, commands);
+ std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
+ std::transform(ccByproducts.begin(), ccByproducts.end(),
+ std::back_inserter(util_outputs), MapToNinjaPath());
+ if (ci.GetUsesTerminal()) {
+ uses_terminal = true;
+ }
}
}
}
- std::vector<cmSourceFile*> sources;
- std::string config =
- this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
- this->GetGeneratorTarget()->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->GetLocalGenerator());
- this->GetLocalGenerator()->AddCustomCommandTarget(
- cc, this->GetGeneratorTarget());
-
- // Depend on all custom command outputs.
- const std::vector<std::string>& ccOutputs = ccg.GetOutputs();
- const std::vector<std::string>& ccByproducts = ccg.GetByproducts();
- std::transform(ccOutputs.begin(), ccOutputs.end(),
- std::back_inserter(deps), MapToNinjaPath());
- std::transform(ccByproducts.begin(), ccByproducts.end(),
- std::back_inserter(deps), MapToNinjaPath());
+ {
+ std::string const& config =
+ this->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
+ std::vector<cmSourceFile*> sources;
+ genTarget->GetSourceFiles(sources, config);
+ for (cmSourceFile const* source : sources) {
+ if (cmCustomCommand const* cc = source->GetCustomCommand()) {
+ cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), lg);
+ lg->AddCustomCommandTarget(cc, genTarget);
+
+ // Depend on all custom command outputs.
+ const std::vector<std::string>& ccOutputs = ccg.GetOutputs();
+ const std::vector<std::string>& ccByproducts = ccg.GetByproducts();
+ std::transform(ccOutputs.begin(), ccOutputs.end(),
+ std::back_inserter(deps), MapToNinjaPath());
+ std::transform(ccByproducts.begin(), ccByproducts.end(),
+ std::back_inserter(deps), MapToNinjaPath());
+ }
}
}
- this->GetLocalGenerator()->AppendTargetOutputs(this->GetGeneratorTarget(),
- outputs);
- this->GetLocalGenerator()->AppendTargetDepends(this->GetGeneratorTarget(),
- deps);
+ lg->AppendTargetOutputs(genTarget, phonyBuild.Outputs);
+ lg->AppendTargetDepends(genTarget, deps);
if (commands.empty()) {
- this->GetGlobalGenerator()->WritePhonyBuild(
- this->GetBuildFileStream(),
- "Utility command for " + this->GetTargetName(), outputs, deps);
+ phonyBuild.Comment = "Utility command for " + this->GetTargetName();
+ phonyBuild.ExplicitDeps = std::move(deps);
+ gg->WriteBuild(this->GetBuildFileStream(), phonyBuild);
} else {
std::string command =
- this->GetLocalGenerator()->BuildCommandLine(commands);
- const char* echoStr =
- this->GetGeneratorTarget()->GetProperty("EchoString");
+ lg->BuildCommandLine(commands, "utility", this->GeneratorTarget);
std::string desc;
+ const char* echoStr = genTarget->GetProperty("EchoString");
if (echoStr) {
desc = echoStr;
} else {
@@ -114,45 +110,38 @@ void cmNinjaUtilityTargetGenerator::Generate()
// makefile vars.
cmSystemTools::ReplaceString(
command, "$(CMAKE_SOURCE_DIR)",
- this->GetLocalGenerator()
- ->ConvertToOutputFormat(
- this->GetLocalGenerator()->GetSourceDirectory(),
- cmOutputConverter::SHELL)
- .c_str());
+ lg->ConvertToOutputFormat(lg->GetSourceDirectory(),
+ cmOutputConverter::SHELL));
cmSystemTools::ReplaceString(
command, "$(CMAKE_BINARY_DIR)",
- this->GetLocalGenerator()
- ->ConvertToOutputFormat(
- this->GetLocalGenerator()->GetBinaryDirectory(),
- cmOutputConverter::SHELL)
- .c_str());
+ lg->ConvertToOutputFormat(lg->GetBinaryDirectory(),
+ cmOutputConverter::SHELL));
cmSystemTools::ReplaceString(command, "$(ARGS)", "");
if (command.find('$') != std::string::npos) {
return;
}
- for (cmNinjaDeps::const_iterator oi = util_outputs.begin(),
- oe = util_outputs.end();
- oi != oe; ++oi) {
- this->GetGlobalGenerator()->SeenCustomCommandOutput(*oi);
+ for (std::string const& util_output : util_outputs) {
+ gg->SeenCustomCommandOutput(util_output);
}
- this->GetGlobalGenerator()->WriteCustomCommandBuild(
- command, desc, "Utility command for " + this->GetTargetName(),
- /*depfile*/ "", uses_terminal,
- /*restat*/ true, util_outputs, deps);
+ gg->WriteCustomCommandBuild(command, desc,
+ "Utility command for " + this->GetTargetName(),
+ /*depfile*/ "", /*job_pool*/ "", uses_terminal,
+ /*restat*/ true, util_outputs, deps);
- this->GetGlobalGenerator()->WritePhonyBuild(
- this->GetBuildFileStream(), "", outputs,
- cmNinjaDeps(1, utilCommandName));
+ phonyBuild.ExplicitDeps.push_back(utilCommandName);
+ gg->WriteBuild(this->GetBuildFileStream(), phonyBuild);
}
+ // Find ADDITIONAL_CLEAN_FILES
+ this->AdditionalCleanFiles();
+
// Add an alias for the logical target name regardless of what directory
// contains it. Skip this for GLOBAL_TARGET because they are meant to
// be per-directory and have one at the top-level anyway.
- if (this->GetGeneratorTarget()->GetType() != cmStateEnums::GLOBAL_TARGET) {
- this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(),
- this->GetGeneratorTarget());
+ if (genTarget->GetType() != cmStateEnums::GLOBAL_TARGET) {
+ gg->AddTargetAlias(this->GetTargetName(), genTarget);
}
}
diff --git a/Source/cmNinjaUtilityTargetGenerator.h b/Source/cmNinjaUtilityTargetGenerator.h
index 9256e369c..01cc4595f 100644
--- a/Source/cmNinjaUtilityTargetGenerator.h
+++ b/Source/cmNinjaUtilityTargetGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmNinjaUtilityTargetGenerator_h
#define cmNinjaUtilityTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmNinjaTargetGenerator.h"
@@ -13,9 +13,9 @@ class cmNinjaUtilityTargetGenerator : public cmNinjaTargetGenerator
{
public:
cmNinjaUtilityTargetGenerator(cmGeneratorTarget* target);
- ~cmNinjaUtilityTargetGenerator() CM_OVERRIDE;
+ ~cmNinjaUtilityTargetGenerator() override;
- void Generate() CM_OVERRIDE;
+ void Generate() override;
};
#endif // ! cmNinjaUtilityTargetGenerator_h
diff --git a/Source/cmOSXBundleGenerator.cxx b/Source/cmOSXBundleGenerator.cxx
index beddc6e6d..47a8df4ef 100644
--- a/Source/cmOSXBundleGenerator.cxx
+++ b/Source/cmOSXBundleGenerator.cxx
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmOSXBundleGenerator.h"
-#include "cmConfigure.h"
-
#include "cmGeneratorTarget.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
@@ -12,16 +10,17 @@
#include "cmTarget.h"
#include <cassert>
+#include <utility>
class cmSourceFile;
cmOSXBundleGenerator::cmOSXBundleGenerator(cmGeneratorTarget* target,
- const std::string& configName)
+ std::string configName)
: GT(target)
, Makefile(target->Target->GetMakefile())
, LocalGenerator(target->GetLocalGenerator())
- , ConfigName(configName)
- , MacContentFolders(CM_NULLPTR)
+ , ConfigName(std::move(configName))
+ , MacContentFolders(nullptr)
{
if (this->MustSkip()) {
return;
@@ -45,7 +44,7 @@ void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName,
out += "/";
out += this->GT->GetAppBundleDirectory(this->ConfigName,
cmGeneratorTarget::FullLevel);
- cmSystemTools::MakeDirectory(out.c_str());
+ cmSystemTools::MakeDirectory(out);
this->Makefile->AddCMakeOutputFile(out);
// Configure the Info.plist file. Note that it needs the executable name
@@ -55,8 +54,7 @@ void cmOSXBundleGenerator::CreateAppBundle(const std::string& targetName,
plist += this->GT->GetAppBundleDirectory(this->ConfigName,
cmGeneratorTarget::ContentLevel);
plist += "/Info.plist";
- this->LocalGenerator->GenerateAppleInfoPList(this->GT, targetName,
- plist.c_str());
+ this->LocalGenerator->GenerateAppleInfoPList(this->GT, targetName, plist);
this->Makefile->AddCMakeOutputFile(plist);
outpath = out;
}
@@ -84,18 +82,17 @@ void cmOSXBundleGenerator::CreateFramework(const std::string& targetName,
// Configure the Info.plist file
std::string plist = newoutpath;
- if (!this->Makefile->PlatformIsAppleIos()) {
+ if (!this->Makefile->PlatformIsAppleEmbedded()) {
// Put the Info.plist file into the Resources directory.
this->MacContentFolders->insert("Resources");
plist += "/Resources";
}
plist += "/Info.plist";
std::string name = cmSystemTools::GetFilenameName(targetName);
- this->LocalGenerator->GenerateFrameworkInfoPList(this->GT, name,
- plist.c_str());
+ this->LocalGenerator->GenerateFrameworkInfoPList(this->GT, name, plist);
// Generate Versions directory only for MacOSX frameworks
- if (this->Makefile->PlatformIsAppleIos()) {
+ if (this->Makefile->PlatformIsAppleEmbedded()) {
return;
}
@@ -107,10 +104,10 @@ void cmOSXBundleGenerator::CreateFramework(const std::string& targetName,
// Make foo.framework/Versions
std::string versions = contentdir;
versions += "Versions";
- cmSystemTools::MakeDirectory(versions.c_str());
+ cmSystemTools::MakeDirectory(versions);
// Make foo.framework/Versions/version
- cmSystemTools::MakeDirectory(newoutpath.c_str());
+ cmSystemTools::MakeDirectory(newoutpath);
// Current -> version
oldName = frameworkVersion;
@@ -175,7 +172,7 @@ void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName,
out += "/";
out += this->GT->GetCFBundleDirectory(this->ConfigName,
cmGeneratorTarget::FullLevel);
- cmSystemTools::MakeDirectory(out.c_str());
+ cmSystemTools::MakeDirectory(out);
this->Makefile->AddCMakeOutputFile(out);
// Configure the Info.plist file. Note that it needs the executable name
@@ -185,7 +182,7 @@ void cmOSXBundleGenerator::CreateCFBundle(const std::string& targetName,
cmGeneratorTarget::ContentLevel);
plist += "/Info.plist";
std::string name = cmSystemTools::GetFilenameName(targetName);
- this->LocalGenerator->GenerateAppleInfoPList(this->GT, name, plist.c_str());
+ this->LocalGenerator->GenerateAppleInfoPList(this->GT, name, plist);
this->Makefile->AddCMakeOutputFile(plist);
}
@@ -197,12 +194,11 @@ void cmOSXBundleGenerator::GenerateMacOSXContentStatements(
return;
}
- for (std::vector<cmSourceFile const*>::const_iterator si = sources.begin();
- si != sources.end(); ++si) {
+ for (cmSourceFile const* source : sources) {
cmGeneratorTarget::SourceFileFlags tsFlags =
- this->GT->GetTargetSourceFileFlags(*si);
+ this->GT->GetTargetSourceFileFlags(source);
if (tsFlags.Type != cmGeneratorTarget::SourceFileTypeNormal) {
- (*generator)(**si, tsFlags.MacFolder);
+ (*generator)(*source, tsFlags.MacFolder);
}
}
}
@@ -216,7 +212,7 @@ std::string cmOSXBundleGenerator::InitMacOSXContentDirectory(
this->ConfigName, cmStateEnums::RuntimeBinaryArtifact);
macdir += "/";
macdir += pkgloc;
- cmSystemTools::MakeDirectory(macdir.c_str());
+ cmSystemTools::MakeDirectory(macdir);
// Record use of this content location. Only the first level
// directory is needed.
diff --git a/Source/cmOSXBundleGenerator.h b/Source/cmOSXBundleGenerator.h
index be7e932f9..3dea6cc8a 100644
--- a/Source/cmOSXBundleGenerator.h
+++ b/Source/cmOSXBundleGenerator.h
@@ -17,8 +17,7 @@ class cmSourceFile;
class cmOSXBundleGenerator
{
public:
- cmOSXBundleGenerator(cmGeneratorTarget* target,
- const std::string& configName);
+ cmOSXBundleGenerator(cmGeneratorTarget* target, std::string configName);
// create an app bundle at a given root, and return
// the directory within the bundle that contains the executable
@@ -32,7 +31,7 @@ public:
struct MacOSXContentGeneratorType
{
- virtual ~MacOSXContentGeneratorType() {}
+ virtual ~MacOSXContentGeneratorType() = default;
virtual void operator()(cmSourceFile const& source,
const char* pkgloc) = 0;
};
diff --git a/Source/cmOptionCommand.cxx b/Source/cmOptionCommand.cxx
index 00a2d2bce..52f63a379 100644
--- a/Source/cmOptionCommand.cxx
+++ b/Source/cmOptionCommand.cxx
@@ -2,9 +2,14 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmOptionCommand.h"
+#include <sstream>
+
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmPolicies.h"
#include "cmState.h"
+#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
@@ -14,19 +19,7 @@ class cmExecutionStatus;
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;
- }
- }
+ const bool argError = (args.size() < 2) || (args.size() > 3);
if (argError) {
std::string m = "called with incorrect number of arguments: ";
m += cmJoin(args, " ");
@@ -34,23 +27,62 @@ bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
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
+ // Determine the state of the option policy
+ bool checkAndWarn = false;
+ {
+ auto status = this->Makefile->GetPolicyStatus(cmPolicies::CMP0077);
+ const auto* existsBeforeSet =
+ this->Makefile->GetStateSnapshot().GetDefinition(args[0]);
+ switch (status) {
+ case cmPolicies::WARN:
+ checkAndWarn = (existsBeforeSet != nullptr);
+ break;
+ case cmPolicies::OLD:
+ // OLD behavior does not warn.
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW: {
+ // See if a local variable with this name already exists.
+ // If so we ignore the option command.
+ if (existsBeforeSet) {
+ return true;
+ }
+ } break;
+ }
+ }
+
+ // See if a cache variable with this name already exists
+ // If so just make sure the doc state is correct
cmState* state = this->Makefile->GetState();
const char* existingValue = state->GetCacheEntryValue(args[0]);
- if (existingValue) {
- if (state->GetCacheEntryType(args[0]) != cmStateEnums::UNINITIALIZED) {
- state->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
- return true;
- }
- initialValue = existingValue;
+ if (existingValue &&
+ (state->GetCacheEntryType(args[0]) != cmStateEnums::UNINITIALIZED)) {
+ state->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
+ return true;
}
+
+ // Nothing in the cache so add it
+ std::string initialValue = existingValue ? existingValue : "Off";
if (args.size() == 3) {
initialValue = args[2];
}
- bool init = cmSystemTools::IsOn(initialValue.c_str());
+ bool init = cmSystemTools::IsOn(initialValue);
this->Makefile->AddCacheDefinition(args[0], init ? "ON" : "OFF",
args[1].c_str(), cmStateEnums::BOOL);
+
+ if (checkAndWarn) {
+ const auto* existsAfterSet =
+ this->Makefile->GetStateSnapshot().GetDefinition(args[0]);
+ if (!existsAfterSet) {
+ std::ostringstream w;
+ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0077)
+ << "\n"
+ "For compatibility with older versions of CMake, option "
+ "is clearing the normal variable '"
+ << args[0] << "'.";
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
+ }
+ }
return true;
}
diff --git a/Source/cmOptionCommand.h b/Source/cmOptionCommand.h
index 634e3a824..34e0e6f01 100644
--- a/Source/cmOptionCommand.h
+++ b/Source/cmOptionCommand.h
@@ -3,7 +3,7 @@
#ifndef cmOptionCommand_h
#define cmOptionCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmOptionCommand; }
+ cmCommand* Clone() override { return new cmOptionCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmOrderDirectories.cxx b/Source/cmOrderDirectories.cxx
index 333e3134c..585db423e 100644
--- a/Source/cmOrderDirectories.cxx
+++ b/Source/cmOrderDirectories.cxx
@@ -5,6 +5,7 @@
#include "cmAlgorithms.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmake.h"
@@ -47,7 +48,7 @@ public:
this->FileName = cmSystemTools::GetFilenameName(file);
}
}
- virtual ~cmOrderDirectoriesConstraint() {}
+ virtual ~cmOrderDirectoriesConstraint() = default;
void AddDirectory()
{
@@ -75,9 +76,8 @@ public:
void FindImplicitConflicts(std::ostringstream& w)
{
bool first = true;
- for (unsigned int i = 0; i < this->OD->OriginalDirectories.size(); ++i) {
+ for (std::string const& dir : this->OD->OriginalDirectories) {
// 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) &&
@@ -119,7 +119,7 @@ bool cmOrderDirectoriesConstraint::FileMayConflict(std::string const& dir,
std::string file = dir;
file += "/";
file += name;
- if (cmSystemTools::FileExists(file.c_str(), true)) {
+ if (cmSystemTools::FileExists(file, 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, file);
@@ -150,7 +150,7 @@ public:
}
}
- void Report(std::ostream& e) CM_OVERRIDE
+ void Report(std::ostream& e) override
{
e << "runtime library [";
if (this->SOName.empty()) {
@@ -161,7 +161,7 @@ public:
e << "]";
}
- bool FindConflict(std::string const& dir) CM_OVERRIDE;
+ bool FindConflict(std::string const& dir) override;
private:
// The soname of the shared library if it is known.
@@ -187,7 +187,7 @@ bool cmOrderDirectoriesConstraintSOName::FindConflict(std::string const& dir)
// 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];
+ ++base.back();
std::set<std::string>::const_iterator last = files.upper_bound(base);
if (first != last) {
return true;
@@ -205,12 +205,12 @@ public:
{
}
- void Report(std::ostream& e) CM_OVERRIDE
+ void Report(std::ostream& e) override
{
e << "link library [" << this->FileName << "]";
}
- bool FindConflict(std::string const& dir) CM_OVERRIDE;
+ bool FindConflict(std::string const& dir) override;
};
bool cmOrderDirectoriesConstraintLibrary::FindConflict(std::string const& dir)
@@ -226,12 +226,10 @@ bool cmOrderDirectoriesConstraintLibrary::FindConflict(std::string const& dir)
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) {
+ for (std::string const& LinkExtension : this->OD->LinkExtensions) {
+ if (LinkExtension != ext) {
std::string fname = lib;
- fname += *i;
+ fname += LinkExtension;
if (this->FileMayConflict(dir, fname)) {
return true;
}
@@ -331,24 +329,21 @@ void cmOrderDirectories::AddLinkLibrary(std::string const& fullPath)
void cmOrderDirectories::AddUserDirectories(
std::vector<std::string> const& extra)
{
- this->UserDirectories.insert(this->UserDirectories.end(), extra.begin(),
- extra.end());
+ cmAppend(this->UserDirectories, extra);
}
void cmOrderDirectories::AddLanguageDirectories(
std::vector<std::string> const& dirs)
{
- this->LanguageDirectories.insert(this->LanguageDirectories.end(),
- dirs.begin(), dirs.end());
+ cmAppend(this->LanguageDirectories, dirs);
}
void cmOrderDirectories::SetImplicitDirectories(
std::set<std::string> const& implicitDirs)
{
this->ImplicitDirectories.clear();
- for (std::set<std::string>::const_iterator i = implicitDirs.begin();
- i != implicitDirs.end(); ++i) {
- this->ImplicitDirectories.insert(this->GetRealPath(*i));
+ for (std::string const& implicitDir : implicitDirs) {
+ this->ImplicitDirectories.insert(this->GetRealPath(implicitDir));
}
}
@@ -375,8 +370,8 @@ void cmOrderDirectories::CollectOriginalDirectories()
this->AddOriginalDirectories(this->UserDirectories);
// Add directories containing constraints.
- for (unsigned int i = 0; i < this->ConstraintEntries.size(); ++i) {
- this->ConstraintEntries[i]->AddDirectory();
+ for (cmOrderDirectoriesConstraint* entry : this->ConstraintEntries) {
+ entry->AddDirectory();
}
// Add language runtime directories last.
@@ -400,20 +395,19 @@ int cmOrderDirectories::AddOriginalDirectory(std::string const& dir)
void cmOrderDirectories::AddOriginalDirectories(
std::vector<std::string> const& dirs)
{
- for (std::vector<std::string>::const_iterator di = dirs.begin();
- di != dirs.end(); ++di) {
+ for (std::string const& dir : dirs) {
// We never explicitly specify implicit link directories.
- if (this->IsImplicitDirectory(*di)) {
+ if (this->IsImplicitDirectory(dir)) {
continue;
}
// Skip the empty string.
- if (di->empty()) {
+ if (dir.empty()) {
continue;
}
// Add this directory.
- this->AddOriginalDirectory(*di);
+ this->AddOriginalDirectory(dir);
}
}
@@ -442,16 +436,15 @@ void cmOrderDirectories::FindConflicts()
}
// Clean up the conflict graph representation.
- for (std::vector<ConflictList>::iterator i = this->ConflictGraph.begin();
- i != this->ConflictGraph.end(); ++i) {
+ for (ConflictList& cl : this->ConflictGraph) {
// 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());
+ std::sort(cl.begin(), cl.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());
+ std::unique(cl.begin(), cl.end(), cmOrderDirectoriesCompare());
+ cl.erase(last, cl.end());
}
// Check items in implicit link directories.
@@ -463,12 +456,12 @@ void cmOrderDirectories::FindImplicitConflicts()
// Check for items in implicit link directories that have conflicts
// in the explicit directories.
std::ostringstream conflicts;
- for (unsigned int i = 0; i < this->ImplicitDirEntries.size(); ++i) {
- this->ImplicitDirEntries[i]->FindImplicitConflicts(conflicts);
+ for (cmOrderDirectoriesConstraint* entry : this->ImplicitDirEntries) {
+ entry->FindImplicitConflicts(conflicts);
}
// Skip warning if there were no conflicts.
- std::string text = conflicts.str();
+ std::string const text = conflicts.str();
if (text.empty()) {
return;
}
@@ -481,7 +474,7 @@ void cmOrderDirectories::FindImplicitConflicts()
<< " 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());
+ MessageType::WARNING, w.str(), this->Target->GetBacktrace());
}
void cmOrderDirectories::OrderDirectories()
@@ -515,8 +508,8 @@ void cmOrderDirectories::VisitDirectory(unsigned int i)
// 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);
+ for (ConflictPair const& j : clist) {
+ this->VisitDirectory(j.first);
}
// Now that all directories required to come before this one have
@@ -542,16 +535,15 @@ void cmOrderDirectories::DiagnoseCycle()
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);
+ for (ConflictPair const& j : clist) {
+ 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());
+ MessageType::WARNING, e.str(), this->Target->GetBacktrace());
}
bool cmOrderDirectories::IsSameDirectory(std::string const& l,
diff --git a/Source/cmOrderDirectories.h b/Source/cmOrderDirectories.h
index 3a0637afb..23e61d678 100644
--- a/Source/cmOrderDirectories.h
+++ b/Source/cmOrderDirectories.h
@@ -3,7 +3,7 @@
#ifndef cmOrderDirectories_h
#define cmOrderDirectories_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmsys/RegularExpression.hxx"
#include <map>
@@ -25,8 +25,10 @@ public:
cmOrderDirectories(cmGlobalGenerator* gg, cmGeneratorTarget const* target,
const char* purpose);
~cmOrderDirectories();
+ cmOrderDirectories(const cmOrderDirectories&) = delete;
+ cmOrderDirectories& operator=(const cmOrderDirectories&) = delete;
void AddRuntimeLibrary(std::string const& fullPath,
- const char* soname = CM_NULLPTR);
+ const char* soname = nullptr);
void AddLinkLibrary(std::string const& fullPath);
void AddUserDirectories(std::vector<std::string> const& extra);
void AddLanguageDirectories(std::vector<std::string> const& dirs);
diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx
index 14c986dd8..7d88b088e 100644
--- a/Source/cmOutputConverter.cxx
+++ b/Source/cmOutputConverter.cxx
@@ -6,12 +6,10 @@
#include <assert.h>
#include <ctype.h>
#include <set>
-#include <sstream>
+#include <string.h>
#include <vector>
-#include "cmAlgorithms.h"
#include "cmState.h"
-#include "cmStateDirectory.h"
#include "cmSystemTools.h"
cmOutputConverter::cmOutputConverter(cmStateSnapshot const& snapshot)
@@ -29,7 +27,7 @@ std::string cmOutputConverter::ConvertToOutputForExisting(
// space.
if (this->GetState()->UseWindowsShell() &&
remote.find(' ') != std::string::npos &&
- cmSystemTools::FileExists(remote.c_str())) {
+ cmSystemTools::FileExists(remote)) {
std::string tmp;
if (cmSystemTools::GetShortPath(remote, tmp)) {
return this->ConvertToOutputFormat(tmp, format);
@@ -73,121 +71,6 @@ std::string cmOutputConverter::ConvertDirectorySeparatorsForShell(
return result;
}
-static bool cmOutputConverterNotAbove(const char* a, const char* b)
-{
- return (cmSystemTools::ComparePath(a, b) ||
- cmSystemTools::IsSubDirectory(a, b));
-}
-
-bool cmOutputConverter::ContainedInDirectory(std::string const& local_path,
- std::string const& remote_path,
- cmStateDirectory const& directory)
-{
- const std::string relativePathTopBinary =
- directory.GetRelativePathTopBinary();
- const std::string relativePathTopSource =
- directory.GetRelativePathTopSource();
-
- const bool bothInBinary =
- cmOutputConverterNotAbove(local_path.c_str(),
- relativePathTopBinary.c_str()) &&
- cmOutputConverterNotAbove(remote_path.c_str(),
- relativePathTopBinary.c_str());
-
- const bool bothInSource =
- cmOutputConverterNotAbove(local_path.c_str(),
- relativePathTopSource.c_str()) &&
- cmOutputConverterNotAbove(remote_path.c_str(),
- relativePathTopSource.c_str());
-
- return bothInSource || bothInBinary;
-}
-
-std::string cmOutputConverter::ConvertToRelativePath(
- std::string const& local_path, std::string const& remote_path) const
-{
- if (!ContainedInDirectory(local_path, remote_path,
- this->StateSnapshot.GetDirectory())) {
- return remote_path;
- }
-
- return this->ForceToRelativePath(local_path, remote_path);
-}
-
-std::string cmOutputConverter::ForceToRelativePath(
- std::string const& local_path, std::string const& remote_path)
-{
- // The paths should never be quoted.
- assert(local_path[0] != '\"');
- assert(remote_path[0] != '\"');
-
- // The local path should never have a trailing slash.
- assert(local_path.empty() || local_path[local_path.size() - 1] != '/');
-
- // If the path is already relative then just return the path.
- if (!cmSystemTools::FileIsFullPath(remote_path.c_str())) {
- return remote_path;
- }
-
- // Identify the longest shared path component between the remote
- // path and the local path.
- std::vector<std::string> local;
- cmSystemTools::SplitPath(local_path, local);
- std::vector<std::string> remote;
- cmSystemTools::SplitPath(remote_path, remote);
- unsigned int common = 0;
- while (common < remote.size() && common < local.size() &&
- cmSystemTools::ComparePath(remote[common], local[common])) {
- ++common;
- }
-
- // If no part of the path is in common then return the full path.
- if (common == 0) {
- return remote_path;
- }
-
- // 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].empty() &&
- 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.
-
- if (!relative.empty() && !remote.empty()) {
- relative += "/";
- }
- relative += cmJoin(cmMakeRange(remote).advance(common), "/");
-
- // Finally return the path.
- return relative;
-}
-
static bool cmOutputConverterIsShellOperator(const std::string& str)
{
static std::set<std::string> shellOperators;
@@ -285,12 +168,11 @@ cmOutputConverter::FortranFormat cmOutputConverter::GetFortranFormat(
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") {
+ for (std::string const& fi : fmt) {
+ if (fi == "FIXED") {
format = FortranFormatFixed;
}
- if (*fi == "FREE") {
+ if (fi == "FREE") {
format = FortranFormatFree;
}
}
@@ -342,12 +224,13 @@ redirection character (for example, ^>, ^<, or ^| ). If you need to
use the caret character itself (^), use two in a row (^^).
*/
-int cmOutputConverter::Shell__CharIsWhitespace(char c)
+/* Some helpers to identify character classes */
+static int Shell__CharIsWhitespace(char c)
{
return ((c == ' ') || (c == '\t'));
}
-int cmOutputConverter::Shell__CharNeedsQuotesOnUnix(char c)
+static int Shell__CharNeedsQuotesOnUnix(char c)
{
return ((c == '\'') || (c == '`') || (c == ';') || (c == '#') ||
(c == '&') || (c == '$') || (c == '(') || (c == ')') || (c == '~') ||
@@ -355,12 +238,17 @@ int cmOutputConverter::Shell__CharNeedsQuotesOnUnix(char c)
(c == '\\'));
}
-int cmOutputConverter::Shell__CharNeedsQuotesOnWindows(char c)
+static int Shell__CharNeedsQuotesOnWindows(char c)
{
return ((c == '\'') || (c == '#') || (c == '&') || (c == '<') ||
(c == '>') || (c == '|') || (c == '^'));
}
+static int Shell__CharIsMakeVariableName(char c)
+{
+ return c && (c == '_' || isalpha((static_cast<int>(c))));
+}
+
int cmOutputConverter::Shell__CharNeedsQuotes(char c, int flags)
{
/* On Windows the built-in command shell echo never needs quotes. */
@@ -387,11 +275,6 @@ int cmOutputConverter::Shell__CharNeedsQuotes(char c, int flags)
return 0;
}
-int cmOutputConverter::Shell__CharIsMakeVariableName(char c)
-{
- return c && (c == '_' || isalpha(((int)c)));
-}
-
const char* cmOutputConverter::Shell__SkipMakeVariables(const char* c)
{
while (*c == '$' && *(c + 1) == '(') {
@@ -482,7 +365,9 @@ int cmOutputConverter::Shell__ArgumentNeedsQuotes(const char* in, int flags)
std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
{
- std::ostringstream out;
+ /* Output will be at least as long as input string. */
+ std::string out;
+ out.reserve(strlen(in));
/* String iterator. */
const char* c;
@@ -496,11 +381,11 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
/* Add the opening quote for this argument. */
if (flags & Shell_Flag_WatcomQuote) {
if (flags & Shell_Flag_IsUnix) {
- out << '"';
+ out += '"';
}
- out << '\'';
+ out += '\'';
} else {
- out << '"';
+ out += '"';
}
}
@@ -512,7 +397,7 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
if (skip != c) {
/* Copy to the end of the make variable references. */
while (c != skip) {
- out << *c++;
+ out += *c++;
}
/* The make variable reference eliminates any escaping needed
@@ -532,7 +417,7 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
quoted argument. */
if (*c == '\\' || *c == '"' || *c == '`' || *c == '$') {
/* This character needs a backslash to escape it. */
- out << '\\';
+ out += '\\';
}
} else if (flags & Shell_Flag_EchoWindows) {
/* On Windows the built-in command shell echo never needs escaping. */
@@ -546,11 +431,11 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
backslashes. */
while (windows_backslashes > 0) {
--windows_backslashes;
- out << '\\';
+ out += '\\';
}
/* Add the backslash to escape the double-quote. */
- out << '\\';
+ out += '\\';
} else {
/* We encountered a normal character. This eliminates any
escaping needed for preceding backslashes. */
@@ -563,7 +448,7 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
if (flags & 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 & 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
@@ -571,30 +456,30 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
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 += "\"$\"";
} else {
/* Otherwise a dollar is written just $. */
- out << '$';
+ out += '$';
}
} else if (*c == '#') {
if ((flags & Shell_Flag_Make) && (flags & 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 << '#';
+ out += '#';
}
} else if (*c == '%') {
if ((flags & Shell_Flag_VSIDE) ||
((flags & Shell_Flag_Make) &&
((flags & Shell_Flag_MinGWMake) || (flags & 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 << '%';
+ out += '%';
}
} else if (*c == ';') {
if (flags & Shell_Flag_VSIDE) {
@@ -603,14 +488,14 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
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 += "\";\"";
} else {
/* Otherwise a semicolon is written just ;. */
- out << ';';
+ out += ';';
}
} else {
/* Store this character. */
- out << *c;
+ out += *c;
}
}
@@ -618,19 +503,19 @@ std::string cmOutputConverter::Shell__GetArgument(const char* in, int flags)
/* Add enough backslashes to escape any trailing ones. */
while (windows_backslashes > 0) {
--windows_backslashes;
- out << '\\';
+ out += '\\';
}
/* Add the closing quote for this argument. */
if (flags & Shell_Flag_WatcomQuote) {
- out << '\'';
+ out += '\'';
if (flags & Shell_Flag_IsUnix) {
- out << '"';
+ out += '"';
}
} else {
- out << '"';
+ out += '"';
}
}
- return out.str();
+ return out;
}
diff --git a/Source/cmOutputConverter.h b/Source/cmOutputConverter.h
index ae15055ed..deca767c6 100644
--- a/Source/cmOutputConverter.h
+++ b/Source/cmOutputConverter.h
@@ -10,7 +10,6 @@
#include "cmStateSnapshot.h"
class cmState;
-class cmStateDirectory;
class cmOutputConverter
{
@@ -28,7 +27,7 @@ public:
std::string ConvertDirectorySeparatorsForShell(
const std::string& source) const;
- ///! for existing files convert to output path and short path if spaces
+ //! for existing files convert to output path and short path if spaces
std::string ConvertToOutputForExisting(const std::string& remote,
OutputFormat format = SHELL) const;
@@ -92,36 +91,10 @@ public:
};
static FortranFormat GetFortranFormat(const char* value);
- static bool ContainedInDirectory(std::string const& local_path,
- std::string const& remote_path,
- cmStateDirectory const& directory);
-
- /**
- * Convert the given remote path to a relative path with respect to
- * the given local path. Both paths must use forward slashes and not
- * already be escaped or quoted.
- * The conversion is skipped if the paths are not both in the source
- * or both in the binary tree.
- */
- std::string ConvertToRelativePath(std::string const& local_path,
- std::string const& remote_path) const;
-
- /**
- * Convert the given remote path to a relative path with respect to
- * the given local path. Both paths must use forward slashes and not
- * already be escaped or quoted.
- */
- static std::string ForceToRelativePath(std::string const& local_path,
- std::string const& remote_path);
-
private:
cmState* GetState() const;
- static int Shell__CharIsWhitespace(char c);
- static int Shell__CharNeedsQuotesOnUnix(char c);
- static int Shell__CharNeedsQuotesOnWindows(char c);
static int Shell__CharNeedsQuotes(char c, int flags);
- static int Shell__CharIsMakeVariableName(char c);
static const char* Shell__SkipMakeVariables(const char* c);
static int Shell__ArgumentNeedsQuotes(const char* in, int flags);
static std::string Shell__GetArgument(const char* in, int flags);
diff --git a/Source/cmOutputRequiredFilesCommand.cxx b/Source/cmOutputRequiredFilesCommand.cxx
index 2339d6876..f3276ecd6 100644
--- a/Source/cmOutputRequiredFilesCommand.cxx
+++ b/Source/cmOutputRequiredFilesCommand.cxx
@@ -13,7 +13,6 @@
#include "cmSourceFile.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cm_unordered_map.hxx"
class cmExecutionStatus;
@@ -29,11 +28,7 @@ public:
* Construct with dependency generation marked not done; instance
* not placed in cmMakefile's list.
*/
- cmDependInformation()
- : DependDone(false)
- , SourceFile(CM_NULLPTR)
- {
- }
+ cmDependInformation() = default;
/**
* The set of files on which this one depends.
@@ -45,13 +40,13 @@ public:
* This flag indicates whether dependency checking has been
* performed for this file.
*/
- bool DependDone;
+ bool DependDone = false;
/**
* If this object corresponds to a cmSourceFile instance, this points
* to it.
*/
- const cmSourceFile* SourceFile;
+ const cmSourceFile* SourceFile = nullptr;
/**
* Full path to this file.
@@ -97,6 +92,9 @@ public:
*/
~cmLBDepend() { cmDeleteAll(this->DependInformationMap); }
+ cmLBDepend(const cmLBDepend&) = delete;
+ cmLBDepend& operator=(const cmLBDepend&) = delete;
+
/**
* Set the makefile that is used as a source of classes.
*/
@@ -113,9 +111,9 @@ public:
// 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");
+ for (auto const& target : this->Makefile->GetTargets()) {
+ const char* incDirProp =
+ target.second.GetProperty("INCLUDE_DIRECTORIES");
if (!incDirProp) {
continue;
}
@@ -126,9 +124,7 @@ public:
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;
+ for (std::string& path : includes) {
this->Makefile->ExpandVariablesInString(path);
if (uniqueIncludes.insert(path).second) {
orderedAndUniqueIncludes.push_back(path);
@@ -136,10 +132,8 @@ public:
}
}
- for (std::vector<std::string>::const_iterator it =
- orderedAndUniqueIncludes.begin();
- it != orderedAndUniqueIncludes.end(); ++it) {
- this->AddSearchPath(*it);
+ for (std::string const& inc : orderedAndUniqueIncludes) {
+ this->AddSearchPath(inc);
}
}
@@ -157,7 +151,7 @@ public:
*/
const cmDependInformation* FindDependencies(const char* file)
{
- cmDependInformation* info = this->GetDependInformation(file, CM_NULLPTR);
+ cmDependInformation* info = this->GetDependInformation(file, nullptr);
this->GenerateDependInformation(info);
return info;
}
@@ -171,13 +165,13 @@ protected:
{
cmsys::ifstream fin(info->FullPath.c_str());
if (!fin) {
- cmSystemTools::Error("error can not open ", info->FullPath.c_str());
+ cmSystemTools::Error("error can not open " + info->FullPath);
return;
}
std::string line;
while (cmSystemTools::GetLineFromStream(fin, line)) {
- if (cmHasLiteralPrefix(line.c_str(), "#include")) {
+ if (cmHasLiteralPrefix(line, "#include")) {
// if it is an include line then create a string class
size_t qstart = line.find('\"', 8);
size_t qend;
@@ -186,7 +180,7 @@ protected:
qstart = line.find('<', 8);
// if a < is not found then move on
if (qstart == std::string::npos) {
- cmSystemTools::Error("unknown include directive ", line.c_str());
+ cmSystemTools::Error("unknown include directive " + line);
continue;
}
qend = line.find('>', qstart + 1);
@@ -202,7 +196,7 @@ protected:
message += includeFile;
message += " for file ";
message += info->FullPath;
- cmSystemTools::Error(message.c_str(), CM_NULLPTR);
+ cmSystemTools::Error(message);
}
continue;
}
@@ -217,63 +211,51 @@ protected:
cxxFile = root + ".cxx";
bool found = false;
// try jumping to .cxx .cpp and .c in order
- if (cmSystemTools::FileExists(cxxFile.c_str())) {
+ if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
- for (std::vector<std::string>::iterator i =
- this->IncludeDirectories.begin();
- i != this->IncludeDirectories.end(); ++i) {
- std::string path = *i;
+ for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
- if (cmSystemTools::FileExists(path.c_str())) {
+ if (cmSystemTools::FileExists(path)) {
found = true;
}
}
if (!found) {
cxxFile = root + ".cpp";
- if (cmSystemTools::FileExists(cxxFile.c_str())) {
+ if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
- for (std::vector<std::string>::iterator i =
- this->IncludeDirectories.begin();
- i != this->IncludeDirectories.end(); ++i) {
- std::string path = *i;
+ for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
- if (cmSystemTools::FileExists(path.c_str())) {
+ if (cmSystemTools::FileExists(path)) {
found = true;
}
}
}
if (!found) {
cxxFile = root + ".c";
- if (cmSystemTools::FileExists(cxxFile.c_str())) {
+ if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
- for (std::vector<std::string>::iterator i =
- this->IncludeDirectories.begin();
- i != this->IncludeDirectories.end(); ++i) {
- std::string path = *i;
+ for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
- if (cmSystemTools::FileExists(path.c_str())) {
+ if (cmSystemTools::FileExists(path)) {
found = true;
}
}
}
if (!found) {
cxxFile = root + ".txx";
- if (cmSystemTools::FileExists(cxxFile.c_str())) {
+ if (cmSystemTools::FileExists(cxxFile)) {
found = true;
}
- for (std::vector<std::string>::iterator i =
- this->IncludeDirectories.begin();
- i != this->IncludeDirectories.end(); ++i) {
- std::string path = *i;
+ for (std::string path : this->IncludeDirectories) {
path = path + "/";
path = path + cxxFile;
- if (cmSystemTools::FileExists(path.c_str())) {
+ if (cmSystemTools::FileExists(path)) {
found = true;
}
}
@@ -310,8 +292,8 @@ protected:
// Make sure we don't visit the same file more than once.
info->DependDone = true;
- const char* path = info->FullPath.c_str();
- if (!path) {
+ const std::string& path = info->FullPath;
+ if (path.empty()) {
cmSystemTools::Error(
"Attempt to find dependencies for file without path!");
return;
@@ -328,7 +310,7 @@ protected:
// See if the cmSourceFile for it has any files specified as
// dependency hints.
- if (info->SourceFile != CM_NULLPTR) {
+ if (info->SourceFile != nullptr) {
// Get the cmSourceFile corresponding to this.
const cmSourceFile& cFile = *(info->SourceFile);
@@ -337,10 +319,8 @@ protected:
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());
+ for (std::string const& file : cFile.GetDepends()) {
+ this->AddDependency(info, file.c_str());
}
// Found dependency information. We are done.
@@ -357,11 +337,8 @@ protected:
found = true;
} else {
// try to guess which include path to use
- for (std::vector<std::string>::iterator t =
- this->IncludeDirectories.begin();
- t != this->IncludeDirectories.end(); ++t) {
- std::string incpath = *t;
- if (!incpath.empty() && incpath[incpath.size() - 1] != '/') {
+ for (std::string incpath : this->IncludeDirectories) {
+ if (!incpath.empty() && incpath.back() != '/') {
incpath = incpath + "/";
}
incpath = incpath + path;
@@ -377,13 +354,12 @@ protected:
if (!found) {
// Couldn't find any dependency information.
- if (this->ComplainFileRegularExpression.find(
- info->IncludeName.c_str())) {
- cmSystemTools::Error("error cannot find dependencies for ", path);
+ if (this->ComplainFileRegularExpression.find(info->IncludeName)) {
+ 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 = "";
+ info->FullPath.clear();
}
}
}
@@ -442,15 +418,12 @@ protected:
return fp;
}
- for (std::vector<std::string>::iterator i =
- this->IncludeDirectories.begin();
- i != this->IncludeDirectories.end(); ++i) {
- std::string path = *i;
- if (!path.empty() && path[path.size() - 1] != '/') {
+ for (std::string path : this->IncludeDirectories) {
+ if (!path.empty() && path.back() != '/') {
path = path + "/";
}
path = path + fname;
- if (cmSystemTools::FileExists(path.c_str(), true) &&
+ if (cmSystemTools::FileExists(path, true) &&
!cmSystemTools::FileIsDirectory(path)) {
std::string fp = cmSystemTools::CollapseFullPath(path);
this->DirectoryToFileToPathMap[extraPath ? extraPath : ""][fname] = fp;
@@ -460,11 +433,11 @@ protected:
if (extraPath) {
std::string path = extraPath;
- if (!path.empty() && path[path.size() - 1] != '/') {
+ if (!path.empty() && path.back() != '/') {
path = path + "/";
}
path = path + fname;
- if (cmSystemTools::FileExists(path.c_str(), true) &&
+ if (cmSystemTools::FileExists(path, true) &&
!cmSystemTools::FileIsDirectory(path)) {
std::string fp = cmSystemTools::CollapseFullPath(path);
this->DirectoryToFileToPathMap[extraPath][fname] = fp;
@@ -532,19 +505,17 @@ void cmOutputRequiredFilesCommand::ListDependencies(
// 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;
+ for (cmDependInformation* d : info->DependencySet) {
+ if (visited->find(d) == visited->end()) {
+ if (!info->FullPath.empty()) {
+ 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());
+ fprintf(fout, "%s\n", d->FullPath.c_str());
}
}
- this->ListDependencies(*d, fout, visited);
+ this->ListDependencies(d, fout, visited);
}
}
}
diff --git a/Source/cmOutputRequiredFilesCommand.h b/Source/cmOutputRequiredFilesCommand.h
index d20bfbdc1..09e622b41 100644
--- a/Source/cmOutputRequiredFilesCommand.h
+++ b/Source/cmOutputRequiredFilesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmOutputRequiredFilesCommand_h
#define cmOutputRequiredFilesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <stdio.h>
@@ -18,9 +18,9 @@ class cmExecutionStatus;
class cmOutputRequiredFilesCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmOutputRequiredFilesCommand; }
+ cmCommand* Clone() override { return new cmOutputRequiredFilesCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
void ListDependencies(cmDependInformation const* info, FILE* fout,
std::set<cmDependInformation const*>* visited);
diff --git a/Source/cmParseArgumentsCommand.cxx b/Source/cmParseArgumentsCommand.cxx
index d75ee8e86..521343203 100644
--- a/Source/cmParseArgumentsCommand.cxx
+++ b/Source/cmParseArgumentsCommand.cxx
@@ -5,29 +5,107 @@
#include <map>
#include <set>
#include <sstream>
-#include <stddef.h>
#include <utility>
#include "cmAlgorithms.h"
+#include "cmArgumentParser.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
-#include "cmake.h"
+#include "cm_string_view.hxx"
class cmExecutionStatus;
-static std::string escape_arg(const std::string& arg)
+static std::string EscapeArg(const std::string& arg)
{
// replace ";" with "\;" so output argument lists will split correctly
std::string escapedArg;
- for (size_t i = 0; i < arg.size(); ++i) {
- if (arg[i] == ';') {
+ for (char i : arg) {
+ if (i == ';') {
escapedArg += '\\';
}
- escapedArg += arg[i];
+ escapedArg += i;
}
return escapedArg;
}
+static std::string JoinList(std::vector<std::string> const& arg, bool escape)
+{
+ return escape ? cmJoin(cmMakeRange(arg).transform(EscapeArg), ";")
+ : cmJoin(cmMakeRange(arg), ";");
+}
+
+namespace {
+
+typedef std::map<std::string, bool> options_map;
+typedef std::map<std::string, std::string> single_map;
+typedef std::map<std::string, std::vector<std::string>> multi_map;
+typedef std::set<std::string> options_set;
+
+struct UserArgumentParser : public cmArgumentParser<void>
+{
+ template <typename T, typename H>
+ void Bind(std::vector<std::string> const& names,
+ std::map<std::string, T>& ref, H duplicateKey)
+ {
+ for (std::string const& key : names) {
+ auto const it = ref.emplace(key, T{}).first;
+ bool const inserted = this->cmArgumentParser<void>::Bind(
+ cm::string_view(it->first), it->second);
+ if (!inserted) {
+ duplicateKey(key);
+ }
+ }
+ }
+};
+
+} // namespace
+
+static void PassParsedArguments(
+ const std::string& prefix, cmMakefile& makefile, const options_map& options,
+ const single_map& singleValArgs, const multi_map& multiValArgs,
+ const std::vector<std::string>& unparsed,
+ const options_set& keywordsMissingValues, bool parseFromArgV)
+{
+ for (auto const& iter : options) {
+ makefile.AddDefinition(prefix + iter.first,
+ iter.second ? "TRUE" : "FALSE");
+ }
+
+ for (auto const& iter : singleValArgs) {
+ if (!iter.second.empty()) {
+ makefile.AddDefinition(prefix + iter.first, iter.second.c_str());
+ } else {
+ makefile.RemoveDefinition(prefix + iter.first);
+ }
+ }
+
+ for (auto const& iter : multiValArgs) {
+ if (!iter.second.empty()) {
+ makefile.AddDefinition(prefix + iter.first,
+ JoinList(iter.second, parseFromArgV).c_str());
+ } else {
+ makefile.RemoveDefinition(prefix + iter.first);
+ }
+ }
+
+ if (!unparsed.empty()) {
+ makefile.AddDefinition(prefix + "UNPARSED_ARGUMENTS",
+ JoinList(unparsed, parseFromArgV).c_str());
+ } else {
+ makefile.RemoveDefinition(prefix + "UNPARSED_ARGUMENTS");
+ }
+
+ if (!keywordsMissingValues.empty()) {
+ makefile.AddDefinition(
+ prefix + "KEYWORDS_MISSING_VALUES",
+ cmJoin(cmMakeRange(keywordsMissingValues), ";").c_str());
+ } else {
+ makefile.RemoveDefinition(prefix + "KEYWORDS_MISSING_VALUES");
+ }
+}
+
bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
@@ -47,7 +125,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
if (*argIter == "PARSE_ARGV") {
if (args.size() != 6) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"PARSE_ARGV must be called with exactly 6 arguments.");
cmSystemTools::SetFatalErrorOccured();
return true;
@@ -55,8 +133,8 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
parseFromArgV = true;
argIter++; // move past PARSE_ARGV
if (!cmSystemTools::StringToULong(argIter->c_str(), &argvStart)) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, "PARSE_ARGV index '" +
- *argIter +
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ "PARSE_ARGV index '" + *argIter +
"' is not an unsigned integer");
cmSystemTools::SetFatalErrorOccured();
return true;
@@ -66,65 +144,36 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
// the first argument is the prefix
const std::string prefix = (*argIter++) + "_";
+ UserArgumentParser parser;
+
// define the result maps holding key/value pairs for
// options, single values and multi values
- typedef std::map<std::string, bool> options_map;
- typedef std::map<std::string, std::string> single_map;
- typedef std::map<std::string, std::vector<std::string> > multi_map;
options_map options;
- single_map single;
- multi_map multi;
+ single_map singleValArgs;
+ multi_map multiValArgs;
// anything else is put into a vector of unparsed strings
std::vector<std::string> unparsed;
- // remember already defined keywords
- std::set<std::string> used_keywords;
- const std::string dup_warning = "keyword defined more than once: ";
+ auto const duplicateKey = [this](std::string const& key) {
+ this->GetMakefile()->IssueMessage(
+ MessageType::WARNING, "keyword defined more than once: " + key);
+ };
// the second argument is a (cmake) list of options without argument
std::vector<std::string> list;
cmSystemTools::ExpandListArgument(*argIter++, list);
- for (std::vector<std::string>::const_iterator iter = list.begin(),
- end = list.end();
- iter != end; ++iter) {
- if (!used_keywords.insert(*iter).second) {
- this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + *iter);
- }
- options[*iter]; // default initialize
- }
+ parser.Bind(list, options, duplicateKey);
// the third argument is a (cmake) list of single argument options
list.clear();
cmSystemTools::ExpandListArgument(*argIter++, list);
- for (std::vector<std::string>::const_iterator iter = list.begin(),
- end = list.end();
- iter != end; ++iter) {
- if (!used_keywords.insert(*iter).second) {
- this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + *iter);
- }
- single[*iter]; // default initialize
- }
+ parser.Bind(list, singleValArgs, duplicateKey);
// the fourth argument is a (cmake) list of multi argument options
list.clear();
cmSystemTools::ExpandListArgument(*argIter++, list);
- for (std::vector<std::string>::const_iterator iter = list.begin(),
- end = list.end();
- iter != end; ++iter) {
- if (!used_keywords.insert(*iter).second) {
- this->GetMakefile()->IssueMessage(cmake::WARNING, dup_warning + *iter);
- }
- multi[*iter]; // default initialize
- }
-
- enum insideValues
- {
- NONE,
- SINGLE,
- MULTI
- } insideValues = NONE;
- std::string currentArgName;
+ parser.Bind(list, multiValArgs, duplicateKey);
list.clear();
if (!parseFromArgV) {
@@ -138,7 +187,7 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
std::string argc = this->Makefile->GetSafeDefinition("ARGC");
unsigned long count;
if (!cmSystemTools::StringToULong(argc.c_str(), &count)) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"PARSE_ARGV called with ARGC='" + argc +
"' that is not an unsigned integer");
cmSystemTools::SetFatalErrorOccured();
@@ -149,96 +198,24 @@ bool cmParseArgumentsCommand::InitialPass(std::vector<std::string> const& args,
argName << "ARGV" << i;
const char* arg = this->Makefile->GetDefinition(argName.str());
if (!arg) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"PARSE_ARGV called with " +
argName.str() + " not set");
cmSystemTools::SetFatalErrorOccured();
return true;
}
- list.push_back(arg);
- }
- }
-
- // iterate over the arguments list and fill in the values where applicable
- for (argIter = list.begin(), argEnd = list.end(); argIter != argEnd;
- ++argIter) {
- const options_map::iterator optIter = options.find(*argIter);
- if (optIter != options.end()) {
- insideValues = NONE;
- optIter->second = true;
- continue;
- }
-
- const single_map::iterator singleIter = single.find(*argIter);
- if (singleIter != single.end()) {
- insideValues = SINGLE;
- currentArgName = *argIter;
- continue;
- }
-
- const multi_map::iterator multiIter = multi.find(*argIter);
- if (multiIter != multi.end()) {
- insideValues = MULTI;
- currentArgName = *argIter;
- continue;
- }
-
- switch (insideValues) {
- case SINGLE:
- single[currentArgName] = *argIter;
- insideValues = NONE;
- break;
- case MULTI:
- if (parseFromArgV) {
- multi[currentArgName].push_back(escape_arg(*argIter));
- } else {
- multi[currentArgName].push_back(*argIter);
- }
- break;
- default:
- if (parseFromArgV) {
- unparsed.push_back(escape_arg(*argIter));
- } else {
- unparsed.push_back(*argIter);
- }
- break;
+ list.emplace_back(arg);
}
}
- // now iterate over the collected values and update their definition
- // within the current scope. undefine if necessary.
+ std::vector<std::string> keywordsMissingValues;
- for (options_map::const_iterator iter = options.begin(), end = options.end();
- iter != end; ++iter) {
- this->Makefile->AddDefinition(prefix + iter->first,
- iter->second ? "TRUE" : "FALSE");
- }
- for (single_map::const_iterator iter = single.begin(), end = single.end();
- iter != end; ++iter) {
- if (!iter->second.empty()) {
- this->Makefile->AddDefinition(prefix + iter->first,
- iter->second.c_str());
- } else {
- this->Makefile->RemoveDefinition(prefix + iter->first);
- }
- }
+ parser.Parse(list, &unparsed, &keywordsMissingValues);
- for (multi_map::const_iterator iter = multi.begin(), end = multi.end();
- iter != end; ++iter) {
- if (!iter->second.empty()) {
- this->Makefile->AddDefinition(
- prefix + iter->first, cmJoin(cmMakeRange(iter->second), ";").c_str());
- } else {
- this->Makefile->RemoveDefinition(prefix + iter->first);
- }
- }
-
- if (!unparsed.empty()) {
- this->Makefile->AddDefinition(prefix + "UNPARSED_ARGUMENTS",
- cmJoin(cmMakeRange(unparsed), ";").c_str());
- } else {
- this->Makefile->RemoveDefinition(prefix + "UNPARSED_ARGUMENTS");
- }
+ PassParsedArguments(
+ prefix, *this->Makefile, options, singleValArgs, multiValArgs, unparsed,
+ options_set(keywordsMissingValues.begin(), keywordsMissingValues.end()),
+ parseFromArgV);
return true;
}
diff --git a/Source/cmParseArgumentsCommand.h b/Source/cmParseArgumentsCommand.h
index 359fb85b9..b8ba61d21 100644
--- a/Source/cmParseArgumentsCommand.h
+++ b/Source/cmParseArgumentsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmParseArgumentsCommand_h
#define cmParseArgumentsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -21,14 +21,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmParseArgumentsCommand; }
+ cmCommand* Clone() override { return new cmParseArgumentsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmPathLabel.cxx b/Source/cmPathLabel.cxx
index 30ba08151..fb8135101 100644
--- a/Source/cmPathLabel.cxx
+++ b/Source/cmPathLabel.cxx
@@ -2,15 +2,15 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmPathLabel.h"
-#include <stddef.h>
+#include <utility>
-cmPathLabel::cmPathLabel(const std::string& label)
- : Label(label)
+cmPathLabel::cmPathLabel(std::string label)
+ : Label(std::move(label))
, Hash(0)
{
// Use a Jenkins one-at-a-time hash with under/over-flow protection
- for (size_t i = 0; i < this->Label.size(); ++i) {
- this->Hash += this->Label[i];
+ for (char i : this->Label) {
+ this->Hash += i;
this->Hash += ((this->Hash & 0x003FFFFF) << 10);
this->Hash ^= ((this->Hash & 0xFFFFFFC0) >> 6);
}
diff --git a/Source/cmPathLabel.h b/Source/cmPathLabel.h
index 97551fb46..55dffabe0 100644
--- a/Source/cmPathLabel.h
+++ b/Source/cmPathLabel.h
@@ -17,7 +17,7 @@
class cmPathLabel
{
public:
- cmPathLabel(const std::string& label);
+ cmPathLabel(std::string label);
// The comparison operators are only for quick sorting and searching and
// in no way imply any lexicographical order of the label
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index da3edd427..ec4013629 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -2,13 +2,12 @@
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
-#include "cmake.h"
-#include "cmConfigure.h"
#include <assert.h>
#include <ctype.h>
#include <sstream>
@@ -62,9 +61,9 @@ static const char* idToString(cmPolicies::PolicyID id)
CM_FOR_EACH_POLICY_ID(POLICY_CASE)
#undef POLICY_CASE
case cmPolicies::CMPCOUNT:
- return CM_NULLPTR;
+ return nullptr;
}
- return CM_NULLPTR;
+ return nullptr;
}
static const char* idToVersion(cmPolicies::PolicyID id)
@@ -76,9 +75,9 @@ static const char* idToVersion(cmPolicies::PolicyID id)
CM_FOR_EACH_POLICY_ID_VERSION(POLICY_CASE)
#undef POLICY_CASE
case cmPolicies::CMPCOUNT:
- return CM_NULLPTR;
+ return nullptr;
}
- return CM_NULLPTR;
+ return nullptr;
}
static bool isPolicyNewerThan(cmPolicies::PolicyID id, unsigned int majorV,
@@ -108,9 +107,9 @@ const char* idToShortDescription(cmPolicies::PolicyID id)
CM_FOR_EACH_POLICY_ID_DOC(POLICY_CASE)
#undef POLICY_CASE
case cmPolicies::CMPCOUNT:
- return CM_NULLPTR;
+ return nullptr;
}
- return CM_NULLPTR;
+ return nullptr;
}
static void DiagnoseAncientPolicies(
@@ -121,67 +120,61 @@ static void DiagnoseAncientPolicies(
e << "The project requests behavior compatible with CMake version \""
<< majorVer << "." << minorVer << "." << patchVer
<< "\", which requires the OLD behavior for some policies:\n";
- for (std::vector<cmPolicies::PolicyID>::const_iterator i = ancient.begin();
- i != ancient.end(); ++i) {
- e << " " << idToString(*i) << ": " << idToShortDescription(*i) << "\n";
+ for (cmPolicies::PolicyID i : ancient) {
+ e << " " << idToString(i) << ": " << idToShortDescription(i) << "\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());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
cmPolicies::PolicyStatus* defaultSetting)
{
std::string defaultVar = "CMAKE_POLICY_DEFAULT_" + policy;
- std::string defaultValue = mf->GetSafeDefinition(defaultVar);
+ std::string const& defaultValue = mf->GetSafeDefinition(defaultVar);
if (defaultValue == "NEW") {
*defaultSetting = cmPolicies::NEW;
} else if (defaultValue == "OLD") {
*defaultSetting = cmPolicies::OLD;
- } else if (defaultValue == "") {
+ } else if (defaultValue.empty()) {
*defaultSetting = cmPolicies::WARN;
} else {
std::ostringstream e;
e << defaultVar << " has value \"" << defaultValue
- << "\" but must be \"OLD\", \"NEW\", or \"\" (empty).";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ << R"(" but must be "OLD", "NEW", or "" (empty).)";
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
return true;
}
-bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, const char* version)
+bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
+ std::string const& version_min,
+ std::string const& version_max)
{
- 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) {
+ // Parse components of the minimum version.
+ unsigned int minMajor = 2;
+ unsigned int minMinor = 0;
+ unsigned int minPatch = 0;
+ unsigned int minTweak = 0;
+ if (sscanf(version_min.c_str(), "%u.%u.%u.%u", &minMajor, &minMinor,
+ &minPatch, &minTweak) < 2) {
std::ostringstream e;
- e << "Invalid policy version value \"" << ver << "\". "
+ e << "Invalid policy version value \"" << version_min << "\". "
<< "A numeric major.minor[.patch[.tweak]] must be given.";
- mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ mf->IssueMessage(MessageType::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)) {
+ if (minMajor < 2 || (minMajor == 2 && minMinor < 4)) {
mf->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::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.");
@@ -190,26 +183,72 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, const char* version)
// 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())) {
+ if (minMajor > cmVersion::GetMajorVersion() ||
+ (minMajor == cmVersion::GetMajorVersion() &&
+ minMinor > cmVersion::GetMinorVersion()) ||
+ (minMajor == cmVersion::GetMajorVersion() &&
+ minMinor == cmVersion::GetMinorVersion() &&
+ minPatch > cmVersion::GetPatchVersion()) ||
+ (minMajor == cmVersion::GetMajorVersion() &&
+ minMinor == cmVersion::GetMinorVersion() &&
+ minPatch == cmVersion::GetPatchVersion() &&
+ minTweak > cmVersion::GetTweakVersion())) {
std::ostringstream e;
e << "An attempt was made to set the policy version of CMake to \""
- << version << "\" which is greater than this version of CMake. "
+ << version_min << "\" 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());
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
return false;
}
+ unsigned int polMajor = minMajor;
+ unsigned int polMinor = minMinor;
+ unsigned int polPatch = minPatch;
+
+ if (!version_max.empty()) {
+ // Parse components of the maximum version.
+ unsigned int maxMajor = 0;
+ unsigned int maxMinor = 0;
+ unsigned int maxPatch = 0;
+ unsigned int maxTweak = 0;
+ if (sscanf(version_max.c_str(), "%u.%u.%u.%u", &maxMajor, &maxMinor,
+ &maxPatch, &maxTweak) < 2) {
+ std::ostringstream e;
+ e << "Invalid policy max version value \"" << version_max << "\". "
+ << "A numeric major.minor[.patch[.tweak]] must be given.";
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ // It is an error if the min version is greater than the max version.
+ if (minMajor > maxMajor || (minMajor == maxMajor && minMinor > maxMinor) ||
+ (minMajor == maxMajor && minMinor == maxMinor &&
+ minPatch > maxPatch) ||
+ (minMajor == maxMajor && minMinor == maxMinor &&
+ minPatch == maxPatch && minTweak > maxTweak)) {
+ std::ostringstream e;
+ e << "Policy VERSION range \"" << version_min << "..." << version_max
+ << "\""
+ << " specifies a larger minimum than maximum.";
+ mf->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ // Use the max version as the policy version.
+ polMajor = maxMajor;
+ polMinor = maxMinor;
+ polPatch = maxPatch;
+ }
+
+ return cmPolicies::ApplyPolicyVersion(mf, polMajor, polMinor, polPatch);
+}
+
+bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
+ unsigned int minorVer,
+ unsigned int patchVer)
+{
// now loop over all the policies and set them as appropriate
std::vector<cmPolicies::PolicyID> ancientPolicies;
for (PolicyID pid = cmPolicies::CMP0000; pid != cmPolicies::CMPCOUNT;
@@ -260,18 +299,21 @@ bool cmPolicies::GetPolicyID(const char* id, cmPolicies::PolicyID& pid)
return stringToId(id, pid);
}
-///! return a warning string for a given policy
+//! return a warning string for a given policy
std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id)
{
std::ostringstream msg;
- msg << "Policy " << idToString(id) << " is not set: "
- ""
- << idToShortDescription(id) << " "
- "Run \"cmake --help-policy "
- << idToString(id) << "\" for "
- "policy details. "
- "Use the cmake_policy command to set the policy "
- "and suppress this warning.";
+ msg << "Policy " << idToString(id)
+ << " is not set: "
+ ""
+ << idToShortDescription(id)
+ << " "
+ "Run \"cmake --help-policy "
+ << idToString(id)
+ << "\" for "
+ "policy details. "
+ "Use the cmake_policy command to set the policy "
+ "and suppress this warning.";
return msg.str();
}
@@ -291,30 +333,33 @@ std::string cmPolicies::GetPolicyDeprecatedWarning(cmPolicies::PolicyID id)
return msg.str();
}
-///! return an error string for when a required policy is unspecified
+//! return an error string for when a required policy is unspecified
std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id)
{
std::ostringstream error;
- error << "Policy " << idToString(id) << " is not set to NEW: "
- ""
- << idToShortDescription(id) << " "
- "Run \"cmake --help-policy "
+ error << "Policy " << idToString(id)
+ << " is not set to NEW: "
+ ""
+ << idToShortDescription(id)
+ << " "
+ "Run \"cmake --help-policy "
<< idToString(id)
<< "\" 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 "
- << idToString(id) << " NEW)\n"
- "or by upgrading all policies with the code\n"
- " cmake_policy(VERSION "
+ << idToString(id)
+ << " NEW)\n"
+ "or by upgrading all policies with the code\n"
+ " cmake_policy(VERSION "
<< idToVersion(id)
<< ") # or later\n"
"Run \"cmake --help-command cmake_policy\" for more information.";
return error.str();
}
-///! Get the default status for a policy
+//! Get the default status for a policy
cmPolicies::PolicyStatus cmPolicies::GetPolicyStatus(
cmPolicies::PolicyID /*unused*/)
{
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 69cbc1844..b70511980 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -126,7 +126,7 @@ class cmMakefile;
3, 0, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0040, \
"The target in the TARGET signature of add_custom_command() must " \
- "exist.", \
+ "exist and must be defined in the current directory.", \
3, 0, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0041, \
"Error on relative include with generator expression.", 3, 0, 0, \
@@ -155,8 +155,9 @@ class cmMakefile;
3, 0, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0051, "List TARGET_OBJECTS in SOURCES target property.", \
3, 1, 0, cmPolicies::WARN) \
- SELECT(POLICY, CMP0052, "Reject source and build dirs in installed " \
- "INTERFACE_INCLUDE_DIRECTORIES.", \
+ SELECT(POLICY, CMP0052, \
+ "Reject source and build dirs in installed " \
+ "INTERFACE_INCLUDE_DIRECTORIES.", \
3, 1, 0, cmPolicies::WARN) \
SELECT(POLICY, CMP0053, \
"Simplify variable reference and escape sequence evaluation.", 3, 1, \
@@ -206,7 +207,79 @@ class cmMakefile;
cmPolicies::WARN) \
SELECT(POLICY, CMP0069, \
"INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.", 3, 9, 0, \
- cmPolicies::WARN)
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0070, \
+ "Define file(GENERATE) behavior for relative paths.", 3, 10, 0, \
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0071, "Let AUTOMOC and AUTOUIC process GENERATED files.", \
+ 3, 10, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0072, \
+ "FindOpenGL prefers GLVND by default when available.", 3, 11, 0, \
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0073, \
+ "Do not produce legacy _LIB_DEPENDS cache entries.", 3, 12, 0, \
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0074, "find_package uses <PackageName>_ROOT variables.", \
+ 3, 12, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0075, \
+ "Include file check macros honor CMAKE_REQUIRED_LIBRARIES.", 3, 12, \
+ 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0076, \
+ "target_sources() command converts relative paths to absolute.", 3, \
+ 13, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0077, "option() honors normal variables.", 3, 13, 0, \
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0078, "UseSWIG generates standard target names.", 3, 13, \
+ 0, cmPolicies::WARN) \
+ SELECT( \
+ POLICY, CMP0079, \
+ "target_link_libraries allows use with targets in other directories.", 3, \
+ 13, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0080, \
+ "BundleUtilities cannot be included at configure time.", 3, 13, 0, \
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0081, \
+ "Relative paths not allowed in LINK_DIRECTORIES target property.", \
+ 3, 13, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0082, \
+ "Install rules from add_subdirectory() are interleaved with those " \
+ "in caller.", \
+ 3, 14, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0083, "Add PIE options when linking executable.", 3, 14, \
+ 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0084, \
+ "The FindQt module does not exist for find_package().", 3, 14, 0, \
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0085, "$<IN_LIST:...> handles empty list items.", 3, 14, \
+ 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0086, \
+ "UseSWIG honors SWIG_MODULE_NAME via -module flag.", 3, 14, 0, \
+ cmPolicies::WARN) \
+ SELECT(POLICY, CMP0087, \
+ "Install CODE|SCRIPT allow the use of generator " \
+ "expressions.", \
+ 3, 14, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0088, \
+ "FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.", \
+ 3, 14, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0089, \
+ "Compiler id for IBM Clang-based XL compilers is now XLClang.", 3, \
+ 15, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0090, \
+ "export(PACKAGE) does not populate package registry by default.", 3, \
+ 15, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0091, \
+ "MSVC runtime library flags are selected by an abstraction.", 3, 15, \
+ 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0092, \
+ "MSVC warning flags are not in CMAKE_<LANG>_FLAGS by default.", 3, \
+ 15, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0093, "FindBoost reports Boost_VERSION in x.y.z format.", \
+ 3, 15, 0, cmPolicies::WARN) \
+ SELECT(POLICY, CMP0094, \
+ "FindPython3, FindPython2 and FindPyton use " \
+ "LOCATION for lookup strategy.", \
+ 3, 15, 0, cmPolicies::WARN)
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
#define CM_FOR_EACH_POLICY_ID(POLICY) \
@@ -220,6 +293,7 @@ class cmMakefile;
F(CMP0021) \
F(CMP0022) \
F(CMP0027) \
+ F(CMP0037) \
F(CMP0038) \
F(CMP0041) \
F(CMP0042) \
@@ -229,14 +303,16 @@ class cmMakefile;
F(CMP0063) \
F(CMP0065) \
F(CMP0068) \
- F(CMP0069)
+ F(CMP0069) \
+ F(CMP0073) \
+ F(CMP0076) \
+ F(CMP0081) \
+ F(CMP0083)
/** \class cmPolicies
* \brief Handles changes in CMake behavior and policies
*
- * See the cmake wiki section on
- * <a href="https://cmake.org/Wiki/CMake/Policies">policies</a>
- * for an overview of this class's purpose
+ * See the cmake-policies(7) manual for an overview of this class's purpose.
*/
class cmPolicies
{
@@ -268,23 +344,27 @@ public:
CMPCOUNT
};
- ///! convert a string policy ID into a number
+ //! convert a string policy ID into a number
static bool GetPolicyID(const char* id, /* out */ cmPolicies::PolicyID& pid);
- ///! Get the default status for a policy
+ //! Get the default status for a policy
static cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
- ///! Set a policy level for this listfile
- static bool ApplyPolicyVersion(cmMakefile* mf, const char* version);
+ //! Set a policy level for this listfile
+ static bool ApplyPolicyVersion(cmMakefile* mf,
+ std::string const& version_min,
+ std::string const& version_max);
+ static bool ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
+ unsigned int minorVer, unsigned int patchVer);
- ///! return a warning string for a given policy
+ //! return a warning string for a given policy
static std::string GetPolicyWarning(cmPolicies::PolicyID id);
static std::string GetPolicyDeprecatedWarning(cmPolicies::PolicyID id);
- ///! return an error string for when a required policy is unspecified
+ //! return an error string for when a required policy is unspecified
static std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
- ///! return an error string for when a required policy is unspecified
+ //! return an error string for when a required policy is unspecified
static std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
/** Represent a set of policy values. */
diff --git a/Source/cmProcessOutput.cxx b/Source/cmProcessOutput.cxx
index 617e1ca7d..e80ea5c8d 100644
--- a/Source/cmProcessOutput.cxx
+++ b/Source/cmProcessOutput.cxx
@@ -4,7 +4,7 @@
#include "cmProcessOutput.h"
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
unsigned int cmProcessOutput::defaultCodepage =
KWSYS_ENCODING_DEFAULT_CODEPAGE;
#endif
@@ -13,7 +13,7 @@ cmProcessOutput::Encoding cmProcessOutput::FindEncoding(
std::string const& name)
{
Encoding encoding = Auto;
- if (name == "UTF8") {
+ if ((name == "UTF8") || (name == "UTF-8")) {
encoding = UTF8;
} else if (name == "NONE") {
encoding = None;
@@ -48,9 +48,7 @@ cmProcessOutput::cmProcessOutput(Encoding encoding, unsigned int maxSize)
#endif
}
-cmProcessOutput::~cmProcessOutput()
-{
-}
+cmProcessOutput::~cmProcessOutput() = default;
bool cmProcessOutput::DecodeText(std::string raw, std::string& decoded,
size_t id)
diff --git a/Source/cmProcessOutput.h b/Source/cmProcessOutput.h
index b5ec4a8be..400354c84 100644
--- a/Source/cmProcessOutput.h
+++ b/Source/cmProcessOutput.h
@@ -28,10 +28,10 @@ public:
};
/**
- * Find encoding enum value for given encoding \a name.
- * \param name a encoding name.
- * \return encoding enum value or Auto if \a name was not found.
- */
+ * Find encoding enum value for given encoding \a name.
+ * \param name a encoding name.
+ * \return encoding enum value or Auto if \a name was not found.
+ */
static Encoding FindEncoding(std::string const& name);
/// The code page that is used as internal encoding to which we will encode.
diff --git a/Source/cmProcessTools.cxx b/Source/cmProcessTools.cxx
index de7b06126..a2bc16ffb 100644
--- a/Source/cmProcessTools.cxx
+++ b/Source/cmProcessTools.cxx
@@ -10,22 +10,22 @@ void cmProcessTools::RunProcess(struct cmsysProcess_s* cp, OutputParser* out,
OutputParser* err, Encoding encoding)
{
cmsysProcess_Execute(cp);
- char* data = CM_NULLPTR;
+ char* data = nullptr;
int length = 0;
int p;
cmProcessOutput processOutput(encoding);
std::string strdata;
while ((out || err) &&
- (p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
+ (p = cmsysProcess_WaitForData(cp, &data, &length, nullptr))) {
if (out && p == cmsysProcess_Pipe_STDOUT) {
processOutput.DecodeText(data, length, strdata, 1);
if (!out->Process(strdata.c_str(), int(strdata.size()))) {
- out = CM_NULLPTR;
+ out = nullptr;
}
} else if (err && p == cmsysProcess_Pipe_STDERR) {
processOutput.DecodeText(data, length, strdata, 2);
if (!err->Process(strdata.c_str(), int(strdata.size()))) {
- err = CM_NULLPTR;
+ err = nullptr;
}
}
}
@@ -38,17 +38,14 @@ void cmProcessTools::RunProcess(struct cmsysProcess_s* cp, OutputParser* out,
if (err) {
processOutput.DecodeText(std::string(), strdata, 2);
if (!strdata.empty()) {
- out->Process(strdata.c_str(), int(strdata.size()));
+ err->Process(strdata.c_str(), int(strdata.size()));
}
}
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
}
cmProcessTools::LineParser::LineParser(char sep, bool ignoreCR)
- : Log(CM_NULLPTR)
- , Prefix(CM_NULLPTR)
- , Separator(sep)
- , LineEnd('\0')
+ : Separator(sep)
, IgnoreCR(ignoreCR)
{
}
@@ -73,11 +70,11 @@ bool cmProcessTools::LineParser::ProcessChunk(const char* first, int length)
// Hand this line to the subclass implementation.
if (!this->ProcessLine()) {
- this->Line = "";
+ this->Line.clear();
return false;
}
- this->Line = "";
+ this->Line.clear();
} else if (*c != '\r' || !this->IgnoreCR) {
// Append this character to the line under construction.
this->Line.append(1, *c);
diff --git a/Source/cmProcessTools.h b/Source/cmProcessTools.h
index e7d9a10eb..76163167a 100644
--- a/Source/cmProcessTools.h
+++ b/Source/cmProcessTools.h
@@ -3,7 +3,7 @@
#ifndef cmProcessTools_h
#define cmProcessTools_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmProcessOutput.h"
#include <iosfwd>
@@ -34,7 +34,8 @@ public:
return this->Process(data, static_cast<int>(strlen(data)));
}
- virtual ~OutputParser() {}
+ virtual ~OutputParser() = default;
+
protected:
/** Implement in a subclass to process a chunk of data. It should
return true only if it is interested in more data. */
@@ -53,13 +54,13 @@ public:
void SetLog(std::ostream* log, const char* prefix);
protected:
- std::ostream* Log;
- const char* Prefix;
+ std::ostream* Log = nullptr;
+ const char* Prefix = nullptr;
std::string Line;
char Separator;
- char LineEnd;
+ char LineEnd = '\0';
bool IgnoreCR;
- bool ProcessChunk(const char* data, int length) CM_OVERRIDE;
+ bool ProcessChunk(const char* data, int length) override;
/** Implement in a subclass to process one line of input. It
should return true only if it is interested in more data. */
@@ -70,18 +71,18 @@ public:
class OutputLogger : public LineParser
{
public:
- OutputLogger(std::ostream& log, const char* prefix = CM_NULLPTR)
+ OutputLogger(std::ostream& log, const char* prefix = nullptr)
{
this->SetLog(&log, prefix);
}
private:
- bool ProcessLine() CM_OVERRIDE { return true; }
+ bool ProcessLine() override { return true; }
};
/** Run a process and send output to given parsers. */
static void RunProcess(struct cmsysProcess_s* cp, OutputParser* out,
- OutputParser* err = CM_NULLPTR,
+ OutputParser* err = nullptr,
Encoding encoding = cmProcessOutput::Auto);
};
diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx
index d72c7909c..8615ecc8d 100644
--- a/Source/cmProjectCommand.cxx
+++ b/Source/cmProjectCommand.cxx
@@ -3,14 +3,16 @@
#include "cmProjectCommand.h"
#include "cmsys/RegularExpression.hxx"
+#include <functional>
#include <sstream>
#include <stdio.h>
+#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -23,6 +25,10 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
+ if (!this->IncludeByVariable("CMAKE_PROJECT_INCLUDE_BEFORE")) {
+ return false;
+ }
+
std::string const& projectName = args[0];
this->Makefile->SetProjectName(projectName);
@@ -33,19 +39,19 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
srcdir += "_SOURCE_DIR";
this->Makefile->AddCacheDefinition(
- bindir, this->Makefile->GetCurrentBinaryDirectory(),
+ bindir, this->Makefile->GetCurrentBinaryDirectory().c_str(),
"Value Computed by CMake", cmStateEnums::STATIC);
this->Makefile->AddCacheDefinition(
- srcdir, this->Makefile->GetCurrentSourceDirectory(),
+ srcdir, this->Makefile->GetCurrentSourceDirectory().c_str(),
"Value Computed by CMake", cmStateEnums::STATIC);
bindir = "PROJECT_BINARY_DIR";
srcdir = "PROJECT_SOURCE_DIR";
- this->Makefile->AddDefinition(bindir,
- this->Makefile->GetCurrentBinaryDirectory());
- this->Makefile->AddDefinition(srcdir,
- this->Makefile->GetCurrentSourceDirectory());
+ this->Makefile->AddDefinition(
+ bindir, this->Makefile->GetCurrentBinaryDirectory().c_str());
+ this->Makefile->AddDefinition(
+ srcdir, this->Makefile->GetCurrentSourceDirectory().c_str());
this->Makefile->AddDefinition("PROJECT_NAME", projectName.c_str());
@@ -66,12 +72,20 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
bool haveVersion = false;
bool haveLanguages = false;
bool haveDescription = false;
+ bool haveHomepage = false;
+ bool injectedProjectCommand = false;
std::string version;
std::string description;
+ std::string homepage;
std::vector<std::string> languages;
+ std::function<void()> missedValueReporter;
+ auto resetReporter = [&missedValueReporter]() {
+ missedValueReporter = std::function<void()>();
+ };
enum Doing
{
DoingDescription,
+ DoingHomepage,
DoingLanguages,
DoingVersion
};
@@ -80,51 +94,115 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
if (args[i] == "LANGUAGES") {
if (haveLanguages) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, "LANGUAGES may be specified at most once.");
+ MessageType::FATAL_ERROR,
+ "LANGUAGES may be specified at most once.");
cmSystemTools::SetFatalErrorOccured();
return true;
}
haveLanguages = true;
+ if (missedValueReporter) {
+ missedValueReporter();
+ }
doing = DoingLanguages;
+ if (!languages.empty()) {
+ std::string msg =
+ "the following parameters must be specified after LANGUAGES "
+ "keyword: ";
+ msg += cmJoin(languages, ", ");
+ msg += '.';
+ this->Makefile->IssueMessage(MessageType::WARNING, msg);
+ }
} else if (args[i] == "VERSION") {
if (haveVersion) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"VERSION may be specified at most once.");
cmSystemTools::SetFatalErrorOccured();
return true;
}
haveVersion = true;
+ if (missedValueReporter) {
+ missedValueReporter();
+ }
doing = DoingVersion;
+ missedValueReporter = [this, &resetReporter]() {
+ this->Makefile->IssueMessage(
+ MessageType::WARNING,
+ "VERSION keyword not followed by a value or was followed by a "
+ "value that expanded to nothing.");
+ resetReporter();
+ };
} else if (args[i] == "DESCRIPTION") {
if (haveDescription) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, "DESCRITPION may be specified at most once.");
+ MessageType::FATAL_ERROR,
+ "DESCRIPTION may be specified at most once.");
cmSystemTools::SetFatalErrorOccured();
return true;
}
haveDescription = true;
+ if (missedValueReporter) {
+ missedValueReporter();
+ }
doing = DoingDescription;
+ missedValueReporter = [this, &resetReporter]() {
+ this->Makefile->IssueMessage(
+ MessageType::WARNING,
+ "DESCRIPTION keyword not followed by a value or was followed "
+ "by a value that expanded to nothing.");
+ resetReporter();
+ };
+ } else if (args[i] == "HOMEPAGE_URL") {
+ if (haveHomepage) {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "HOMEPAGE_URL may be specified at most once.");
+ cmSystemTools::SetFatalErrorOccured();
+ return true;
+ }
+ haveHomepage = true;
+ doing = DoingHomepage;
+ missedValueReporter = [this, &resetReporter]() {
+ this->Makefile->IssueMessage(
+ MessageType::WARNING,
+ "HOMEPAGE_URL keyword not followed by a value or was followed "
+ "by a value that expanded to nothing.");
+ resetReporter();
+ };
+ } else if (i == 1 && args[i] == "__CMAKE_INJECTED_PROJECT_COMMAND__") {
+ injectedProjectCommand = true;
} else if (doing == DoingVersion) {
doing = DoingLanguages;
version = args[i];
+ resetReporter();
} else if (doing == DoingDescription) {
doing = DoingLanguages;
description = args[i];
+ resetReporter();
+ } else if (doing == DoingHomepage) {
+ doing = DoingLanguages;
+ homepage = args[i];
+ resetReporter();
} else // doing == DoingLanguages
{
languages.push_back(args[i]);
}
}
- if (haveVersion && !haveLanguages && !languages.empty()) {
+ if (missedValueReporter) {
+ missedValueReporter();
+ }
+
+ if ((haveVersion || haveDescription || haveHomepage) && !haveLanguages &&
+ !languages.empty()) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
- "project with VERSION must use LANGUAGES before language names.");
+ MessageType::FATAL_ERROR,
+ "project with VERSION, DESCRIPTION or HOMEPAGE_URL must "
+ "use LANGUAGES before language names.");
cmSystemTools::SetFatalErrorOccured();
return true;
}
if (haveLanguages && languages.empty()) {
- languages.push_back("NONE");
+ languages.emplace_back("NONE");
}
cmPolicies::PolicyStatus cmp0048 =
@@ -133,17 +211,17 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
// Set project VERSION variables to given values
if (cmp0048 == cmPolicies::OLD || cmp0048 == cmPolicies::WARN) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::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]+)?)?)?)?$");
+ R"(^([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);
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
cmSystemTools::SetFatalErrorOccured();
return true;
}
@@ -181,29 +259,43 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
vv = projectName + "_VERSION_TWEAK";
this->Makefile->AddDefinition("PROJECT_VERSION_TWEAK", vb[3]);
this->Makefile->AddDefinition(vv, vb[3]);
+ // Also, try set top level variables
+ TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION", vs.c_str());
+ TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MAJOR", vb[0]);
+ TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_MINOR", vb[1]);
+ TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_PATCH", vb[2]);
+ TopLevelCMakeVarCondSet("CMAKE_PROJECT_VERSION_TWEAK", 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.emplace_back("PROJECT_VERSION");
+ vv.emplace_back("PROJECT_VERSION_MAJOR");
+ vv.emplace_back("PROJECT_VERSION_MINOR");
+ vv.emplace_back("PROJECT_VERSION_PATCH");
+ vv.emplace_back("PROJECT_VERSION_TWEAK");
vv.push_back(projectName + "_VERSION");
vv.push_back(projectName + "_VERSION_MAJOR");
vv.push_back(projectName + "_VERSION_MINOR");
vv.push_back(projectName + "_VERSION_PATCH");
vv.push_back(projectName + "_VERSION_TWEAK");
+ if (this->Makefile->IsRootMakefile()) {
+ vv.emplace_back("CMAKE_PROJECT_VERSION");
+ vv.emplace_back("CMAKE_PROJECT_VERSION_MAJOR");
+ vv.emplace_back("CMAKE_PROJECT_VERSION_MINOR");
+ vv.emplace_back("CMAKE_PROJECT_VERSION_PATCH");
+ vv.emplace_back("CMAKE_PROJECT_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);
+ for (std::string const& i : vv) {
+ const char* v = this->Makefile->GetDefinition(i);
if (v && *v) {
if (cmp0048 == cmPolicies::WARN) {
- vw += "\n ";
- vw += *i;
+ if (!injectedProjectCommand) {
+ vw += "\n ";
+ vw += i;
+ }
} else {
- this->Makefile->AddDefinition(*i, "");
+ this->Makefile->AddDefinition(i, "");
}
}
}
@@ -211,43 +303,72 @@ bool cmProjectCommand::InitialPass(std::vector<std::string> const& args,
std::ostringstream w;
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0048)
<< "\nThe following variable(s) would be set to empty:" << vw;
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
}
- if (haveDescription) {
- this->Makefile->AddDefinition("PROJECT_DESCRIPTION", description.c_str());
- // Set the CMAKE_PROJECT_DESCRIPTION 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.
- if (!this->Makefile->GetDefinition("CMAKE_PROJECT_DESCRIPTION") ||
- (this->Makefile->IsRootMakefile())) {
- this->Makefile->AddDefinition("CMAKE_PROJECT_DESCRIPTION",
- description.c_str());
- this->Makefile->AddCacheDefinition(
- "CMAKE_PROJECT_DESCRIPTION", description.c_str(),
- "Value Computed by CMake", cmStateEnums::STATIC);
- }
- }
+ this->Makefile->AddDefinition("PROJECT_DESCRIPTION", description.c_str());
+ this->Makefile->AddDefinition(projectName + "_DESCRIPTION",
+ description.c_str());
+ TopLevelCMakeVarCondSet("CMAKE_PROJECT_DESCRIPTION", description.c_str());
+
+ this->Makefile->AddDefinition("PROJECT_HOMEPAGE_URL", homepage.c_str());
+ this->Makefile->AddDefinition(projectName + "_HOMEPAGE_URL",
+ homepage.c_str());
+ TopLevelCMakeVarCondSet("CMAKE_PROJECT_HOMEPAGE_URL", homepage.c_str());
if (languages.empty()) {
// if no language is specified do c and c++
- languages.push_back("C");
- languages.push_back("CXX");
+ languages.emplace_back("C");
+ languages.emplace_back("CXX");
}
this->Makefile->EnableLanguage(languages, false);
- std::string extraInclude = "CMAKE_PROJECT_" + projectName + "_INCLUDE";
- const char* include = this->Makefile->GetDefinition(extraInclude);
- if (include) {
- bool readit = this->Makefile->ReadDependentFile(include);
- if (!readit && !cmSystemTools::GetFatalErrorOccured()) {
- std::string m = "could not find file:\n"
- " ";
- m += include;
- this->SetError(m);
- return false;
- }
+
+ if (!this->IncludeByVariable("CMAKE_PROJECT_INCLUDE")) {
+ return false;
+ }
+
+ if (!this->IncludeByVariable("CMAKE_PROJECT_" + projectName + "_INCLUDE")) {
+ return false;
}
+
return true;
}
+
+bool cmProjectCommand::IncludeByVariable(const std::string& variable)
+{
+ const char* include = this->Makefile->GetDefinition(variable);
+ if (!include) {
+ return true;
+ }
+
+ const bool readit = this->Makefile->ReadDependentFile(include);
+ if (readit) {
+ return true;
+ }
+
+ if (cmSystemTools::GetFatalErrorOccured()) {
+ return true;
+ }
+
+ std::string m = "could not find file:\n"
+ " ";
+ m += include;
+ this->SetError(m);
+ return false;
+}
+
+void cmProjectCommand::TopLevelCMakeVarCondSet(const char* const name,
+ const char* const value)
+{
+ // Set the CMAKE_PROJECT_XXX 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.
+ if (!this->Makefile->GetDefinition(name) ||
+ (this->Makefile->IsRootMakefile())) {
+ this->Makefile->AddDefinition(name, value);
+ this->Makefile->AddCacheDefinition(name, value, "Value Computed by CMake",
+ cmStateEnums::STATIC);
+ }
+}
diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h
index 3c579ac9d..f1d03e71d 100644
--- a/Source/cmProjectCommand.h
+++ b/Source/cmProjectCommand.h
@@ -3,7 +3,7 @@
#ifndef cmProjectCommand_h
#define cmProjectCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -26,14 +26,18 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmProjectCommand; }
+ cmCommand* Clone() override { return new cmProjectCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
+
+private:
+ bool IncludeByVariable(const std::string& variable);
+ void TopLevelCMakeVarCondSet(const char* name, const char* value);
};
#endif
diff --git a/Source/cmProperty.cxx b/Source/cmProperty.cxx
index 222afb497..27f0ecd71 100644
--- a/Source/cmProperty.cxx
+++ b/Source/cmProperty.cxx
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmProperty.h"
-#include "cmConfigure.h"
-
void cmProperty::Set(const char* value)
{
this->Value = value;
@@ -24,5 +22,5 @@ const char* cmProperty::GetValue() const
if (this->ValueHasBeenSet) {
return this->Value.c_str();
}
- return CM_NULLPTR;
+ return nullptr;
}
diff --git a/Source/cmPropertyMap.cxx b/Source/cmPropertyMap.cxx
index 1e089d1c8..3f6d7c8a9 100644
--- a/Source/cmPropertyMap.cxx
+++ b/Source/cmPropertyMap.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmPropertyMap.h"
-#include "cmConfigure.h"
#include <algorithm>
#include <assert.h>
#include <utility>
@@ -22,9 +21,8 @@ cmProperty* cmPropertyMap::GetOrCreateProperty(const std::string& name)
std::vector<std::string> cmPropertyMap::GetPropertyList() const
{
std::vector<std::string> keyList;
- for (cmPropertyMap::const_iterator i = this->begin(), e = this->end();
- i != e; ++i) {
- keyList.push_back(i->first);
+ for (auto const& i : *this) {
+ keyList.push_back(i.first);
}
std::sort(keyList.begin(), keyList.end());
return keyList;
@@ -59,7 +57,7 @@ const char* cmPropertyMap::GetPropertyValue(const std::string& name) const
cmPropertyMap::const_iterator it = this->find(name);
if (it == this->end()) {
- return CM_NULLPTR;
+ return nullptr;
}
return it->second.GetValue();
}
diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx
index de9e54505..9a764c678 100644
--- a/Source/cmQTWrapCPPCommand.cxx
+++ b/Source/cmQTWrapCPPCommand.cxx
@@ -4,9 +4,12 @@
#include "cmCustomCommandLines.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmSystemTools.h"
+#include <utility>
+
class cmExecutionStatus;
// cmQTWrapCPPCommand
@@ -19,7 +22,7 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
}
// Get the moc executable to run in the custom command.
- const char* moc_exe =
+ std::string const& moc_exe =
this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
// Get the variable holding the list of sources.
@@ -27,13 +30,13 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList);
// Create a rule for all sources listed.
- for (std::vector<std::string>::const_iterator j = (args.begin() + 2);
- j != args.end(); ++j) {
- cmSourceFile* curr = this->Makefile->GetSource(*j);
+ for (std::string const& arg : cmMakeRange(args).advance(2)) {
+ cmSourceFile* curr = this->Makefile->GetSource(arg);
// 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 srcName =
+ cmSystemTools::GetFilenameWithoutLastExtension(arg);
std::string newName = this->Makefile->GetCurrentBinaryDirectory();
newName += "/moc_";
newName += srcName;
@@ -45,16 +48,16 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
// Compute the name of the header from which to generate the file.
std::string hname;
- if (cmSystemTools::FileIsFullPath(j->c_str())) {
- hname = *j;
+ if (cmSystemTools::FileIsFullPath(arg)) {
+ hname = arg;
} else {
- if (curr && curr->GetPropertyAsBool("GENERATED")) {
+ if (curr && curr->GetIsGenerated()) {
hname = this->Makefile->GetCurrentBinaryDirectory();
} else {
hname = this->Makefile->GetCurrentSourceDirectory();
}
hname += "/";
- hname += *j;
+ hname += arg;
}
// Append the generated source file to the list.
@@ -71,14 +74,14 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
commandLine.push_back(hname);
cmCustomCommandLines commandLines;
- commandLines.push_back(commandLine);
+ commandLines.push_back(std::move(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 = CM_NULLPTR;
+ const char* no_working_dir = nullptr;
this->Makefile->AddCustomCommandToOutput(
newName, depends, no_main_dependency, commandLines, "Qt Wrapped File",
no_working_dir);
diff --git a/Source/cmQTWrapCPPCommand.h b/Source/cmQTWrapCPPCommand.h
index ad1ccf38d..c1dcd545e 100644
--- a/Source/cmQTWrapCPPCommand.h
+++ b/Source/cmQTWrapCPPCommand.h
@@ -3,7 +3,7 @@
#ifndef cmQTWrapCPPCommand_h
#define cmQTWrapCPPCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmQTWrapCPPCommand; }
+ cmCommand* Clone() override { return new cmQTWrapCPPCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx
index d3c663176..2223e2d82 100644
--- a/Source/cmQTWrapUICommand.cxx
+++ b/Source/cmQTWrapUICommand.cxx
@@ -4,9 +4,12 @@
#include "cmCustomCommandLines.h"
#include "cmMakefile.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmSystemTools.h"
+#include <utility>
+
class cmExecutionStatus;
// cmQTWrapUICommand
@@ -19,9 +22,9 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
}
// Get the uic and moc executables to run in the custom commands.
- const char* uic_exe =
+ std::string const& uic_exe =
this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
- const char* moc_exe =
+ std::string const& moc_exe =
this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
// Get the variable holding the list of sources.
@@ -31,13 +34,13 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList);
// Create rules for all sources listed.
- for (std::vector<std::string>::const_iterator j = (args.begin() + 3);
- j != args.end(); ++j) {
- cmSourceFile* curr = this->Makefile->GetSource(*j);
+ for (std::string const& arg : cmMakeRange(args).advance(3)) {
+ cmSourceFile* curr = this->Makefile->GetSource(arg);
// 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 srcName =
+ cmSystemTools::GetFilenameWithoutLastExtension(arg);
std::string hName = this->Makefile->GetCurrentBinaryDirectory();
hName += "/";
hName += srcName;
@@ -53,16 +56,16 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
// Compute the name of the ui file from which to generate others.
std::string uiName;
- if (cmSystemTools::FileIsFullPath(j->c_str())) {
- uiName = *j;
+ if (cmSystemTools::FileIsFullPath(arg)) {
+ uiName = arg;
} else {
- if (curr && curr->GetPropertyAsBool("GENERATED")) {
+ if (curr && curr->GetIsGenerated()) {
uiName = this->Makefile->GetCurrentBinaryDirectory();
} else {
uiName = this->Makefile->GetCurrentSourceDirectory();
}
uiName += "/";
- uiName += *j;
+ uiName += arg;
}
// create the list of headers
@@ -86,7 +89,7 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
hCommand.push_back(hName);
hCommand.push_back(uiName);
cmCustomCommandLines hCommandLines;
- hCommandLines.push_back(hCommand);
+ hCommandLines.push_back(std::move(hCommand));
cmCustomCommandLine cxxCommand;
cxxCommand.push_back(uic_exe);
@@ -96,7 +99,7 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
cxxCommand.push_back(cxxName);
cxxCommand.push_back(uiName);
cmCustomCommandLines cxxCommandLines;
- cxxCommandLines.push_back(cxxCommand);
+ cxxCommandLines.push_back(std::move(cxxCommand));
cmCustomCommandLine mocCommand;
mocCommand.push_back(moc_exe);
@@ -104,13 +107,13 @@ bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
mocCommand.push_back(mocName);
mocCommand.push_back(hName);
cmCustomCommandLines mocCommandLines;
- mocCommandLines.push_back(mocCommand);
+ mocCommandLines.push_back(std::move(mocCommand));
std::vector<std::string> depends;
depends.push_back(uiName);
std::string no_main_dependency;
- const char* no_comment = CM_NULLPTR;
- const char* no_working_dir = CM_NULLPTR;
+ const char* no_comment = nullptr;
+ const char* no_working_dir = nullptr;
this->Makefile->AddCustomCommandToOutput(
hName, depends, no_main_dependency, hCommandLines, no_comment,
no_working_dir);
diff --git a/Source/cmQTWrapUICommand.h b/Source/cmQTWrapUICommand.h
index ac7ab01c7..15cab406f 100644
--- a/Source/cmQTWrapUICommand.h
+++ b/Source/cmQTWrapUICommand.h
@@ -3,7 +3,7 @@
#ifndef cmQTWrapUICommand_h
#define cmQTWrapUICommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmQTWrapUICommand; }
+ cmCommand* Clone() override { return new cmQTWrapUICommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
index 5364f76f4..2064275e7 100644
--- a/Source/cmRST.cxx
+++ b/Source/cmRST.cxx
@@ -3,6 +3,7 @@
#include "cmRST.h"
#include "cmAlgorithms.h"
+#include "cmRange.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
@@ -13,9 +14,9 @@
#include <stddef.h>
#include <utility>
-cmRST::cmRST(std::ostream& os, std::string const& docroot)
+cmRST::cmRST(std::ostream& os, std::string docroot)
: OS(os)
- , DocRoot(docroot)
+ , DocRoot(std::move(docroot))
, IncludeDepth(0)
, OutputLinePending(false)
, LastLineEndedInColonColon(false)
@@ -32,13 +33,15 @@ cmRST::cmRST(std::ostream& os, std::string const& docroot)
, TocTreeDirective("^.. toctree::[ \t]*(.*)$")
, ProductionListDirective("^.. productionlist::[ \t]*(.*)$")
, NoteDirective("^.. note::[ \t]*(.*)$")
- , ModuleRST("^#\\[(=*)\\[\\.rst:$")
+ , ModuleRST(R"(^#\[(=*)\[\.rst:$)")
, CMakeRole("(:cmake)?:("
- "command|generator|variable|module|policy|"
+ "command|cpack_gen|generator|variable|envvar|module|policy|"
"prop_cache|prop_dir|prop_gbl|prop_inst|prop_sf|"
"prop_test|prop_tgt|"
"manual"
"):`(<*([^`<]|[^` \t]<)*)([ \t]+<[^`]*>)?`")
+ , InlineLink("`(<*([^`<]|[^` \t]<)*)([ \t]+<[^`]*>)?`_")
+ , InlineLiteral("``([^`]*)``")
, Substitution("(^|[^A-Za-z0-9_])"
"((\\|[^| \t\r\n]([^|\r\n]*[^| \t\r\n])?\\|)(__|_|))"
"([^A-Za-z0-9_]|$)")
@@ -86,7 +89,7 @@ void cmRST::ProcessModule(std::istream& is)
if (line[0] != '#') {
this->ProcessLine(line.substr(0, pos));
}
- rst = "";
+ rst.clear();
this->Reset();
this->OutputLinePending = true;
}
@@ -101,7 +104,7 @@ void cmRST::ProcessModule(std::istream& is)
this->ProcessLine(line.substr(2));
continue;
}
- rst = "";
+ rst.clear();
this->Reset();
this->OutputLinePending = true;
}
@@ -120,7 +123,7 @@ void cmRST::ProcessModule(std::istream& is)
void cmRST::Reset()
{
if (!this->MarkupLines.empty()) {
- this->UnindentLines(this->MarkupLines);
+ cmRST::UnindentLines(this->MarkupLines);
}
switch (this->Directive) {
case DirectiveNone:
@@ -152,8 +155,9 @@ void cmRST::ProcessLine(std::string const& line)
this->LastLineEndedInColonColon = false;
// A line starting in .. is an explicit markup start.
- if (line == ".." || (line.size() >= 3 && line[0] == '.' && line[1] == '.' &&
- isspace(line[2]))) {
+ if (line == ".." ||
+ (line.size() >= 3 && line[0] == '.' && line[1] == '.' &&
+ isspace(line[2]))) {
this->Reset();
this->Markup =
(line.find_first_not_of(" \t", 2) == std::string::npos ? MarkupEmpty
@@ -175,7 +179,7 @@ void cmRST::ProcessLine(std::string const& 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("");
+ this->MarkupLines.emplace_back();
} else if (this->ReplaceDirective.find(line)) {
// Record the replace directive content.
this->Directive = DirectiveReplace;
@@ -218,15 +222,14 @@ void cmRST::ProcessLine(std::string const& line)
// Record the literal lines to output after whole block.
this->Markup = MarkupNormal;
this->Directive = DirectiveLiteralBlock;
- this->MarkupLines.push_back("");
+ this->MarkupLines.emplace_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] == ':');
+ (line.size() >= 2 && line[line.size() - 2] == ':' && line.back() == ':');
}
}
@@ -245,18 +248,62 @@ void cmRST::OutputLine(std::string const& line_in, bool inlineMarkup)
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("()") == std::string::npos) {
- text += "()";
+ for (;;) {
+ std::string::size_type* first = nullptr;
+ std::string::size_type role_start = std::string::npos;
+ std::string::size_type link_start = std::string::npos;
+ std::string::size_type lit_start = std::string::npos;
+ if (this->CMakeRole.find(line.c_str() + pos)) {
+ role_start = this->CMakeRole.start();
+ first = &role_start;
+ }
+ if (this->InlineLiteral.find(line.c_str() + pos)) {
+ lit_start = this->InlineLiteral.start();
+ if (!first || lit_start < *first) {
+ first = &lit_start;
+ }
+ }
+ if (this->InlineLink.find(line.c_str() + pos)) {
+ link_start = this->InlineLink.start();
+ if (!first || link_start < *first) {
+ first = &link_start;
+ }
+ }
+ if (first == &role_start) {
+ this->OS << line.substr(pos, role_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("()") == std::string::npos) {
+ text += "()";
+ }
+ this->OS << "``" << text << "``";
+ pos += this->CMakeRole.end();
+ } else if (first == &lit_start) {
+ this->OS << line.substr(pos, lit_start);
+ std::string text = this->InlineLiteral.match(1);
+ pos += this->InlineLiteral.end();
+ this->OS << "``" << text << "``";
+ } else if (first == &link_start) {
+ this->OS << line.substr(pos, link_start);
+ std::string text = this->InlineLink.match(1);
+ bool escaped = false;
+ for (char c : text) {
+ if (escaped) {
+ escaped = false;
+ this->OS << c;
+ } else if (c == '\\') {
+ escaped = true;
+ } else {
+ this->OS << c;
+ }
+ }
+ pos += this->InlineLink.end();
+ } else {
+ break;
}
- this->OS << "``" << text << "``";
- pos += this->CMakeRole.end();
}
this->OS << line.substr(pos) << "\n";
} else {
@@ -292,9 +339,7 @@ std::string cmRST::ReplaceSubstitutions(std::string const& line)
void cmRST::OutputMarkupLines(bool inlineMarkup)
{
- for (std::vector<std::string>::iterator i = this->MarkupLines.begin();
- i != this->MarkupLines.end(); ++i) {
- std::string line = *i;
+ for (auto line : this->MarkupLines) {
if (!line.empty()) {
line = " " + line;
}
@@ -347,15 +392,13 @@ void cmRST::ProcessDirectiveReplace()
// Record markup lines as replacement text.
std::string& replacement = this->Replace[this->ReplaceName];
replacement += cmJoin(this->MarkupLines, " ");
- this->ReplaceName = "";
+ this->ReplaceName.clear();
}
void cmRST::ProcessDirectiveTocTree()
{
// Process documents referenced by toctree directive.
- for (std::vector<std::string>::iterator i = this->MarkupLines.begin();
- i != this->MarkupLines.end(); ++i) {
- std::string const& line = *i;
+ for (std::string const& line : this->MarkupLines) {
if (!line.empty() && line[0] != ':') {
if (this->TocTreeLink.find(line)) {
std::string const& link = this->TocTreeLink.match(1);
@@ -414,6 +457,12 @@ void cmRST::UnindentLines(std::vector<std::string>& lines)
size_t trailingEmpty =
std::distance(rit, cmFindNot(cmReverseRange(lines), std::string()));
+ if ((leadingEmpty + trailingEmpty) >= lines.size()) {
+ // All lines are empty. The markup block is empty. Leave only one.
+ lines.resize(1);
+ return;
+ }
+
std::vector<std::string>::iterator contentEnd = cmRotate(
lines.begin(), lines.begin() + leadingEmpty, lines.end() - trailingEmpty);
lines.erase(contentEnd, lines.end());
diff --git a/Source/cmRST.h b/Source/cmRST.h
index d1a8e2711..d8d2a0bab 100644
--- a/Source/cmRST.h
+++ b/Source/cmRST.h
@@ -25,7 +25,7 @@
class cmRST
{
public:
- cmRST(std::ostream& os, std::string const& docroot);
+ cmRST(std::ostream& os, std::string docroot);
bool ProcessFile(std::string const& fname, bool isModule = false);
private:
@@ -85,6 +85,8 @@ private:
cmsys::RegularExpression NoteDirective;
cmsys::RegularExpression ModuleRST;
cmsys::RegularExpression CMakeRole;
+ cmsys::RegularExpression InlineLink;
+ cmsys::RegularExpression InlineLiteral;
cmsys::RegularExpression Substitution;
cmsys::RegularExpression TocTreeLink;
diff --git a/Source/cmRemoveCommand.cxx b/Source/cmRemoveCommand.cxx
index 1db84414a..a64ad8c7d 100644
--- a/Source/cmRemoveCommand.cxx
+++ b/Source/cmRemoveCommand.cxx
@@ -25,22 +25,20 @@ bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args,
}
// expand the variable
- std::vector<std::string> varArgsExpanded;
- cmSystemTools::ExpandListArgument(cacheValue, varArgsExpanded);
+ std::vector<std::string> const varArgsExpanded =
+ cmSystemTools::ExpandedListArgument(cacheValue);
// expand the args
// check for REMOVE(VAR v1 v2 ... vn)
- std::vector<std::string> argsExpanded;
- std::vector<std::string> temp;
- temp.insert(temp.end(), args.begin() + 1, args.end());
- cmSystemTools::ExpandList(temp, argsExpanded);
+ std::vector<std::string> const argsExpanded =
+ cmSystemTools::ExpandedLists(args.begin() + 1, args.end());
// now create the new value
std::string value;
- for (unsigned int j = 0; j < varArgsExpanded.size(); ++j) {
+ for (std::string const& varArgExpanded : varArgsExpanded) {
int found = 0;
- for (unsigned int k = 0; k < argsExpanded.size(); ++k) {
- if (varArgsExpanded[j] == argsExpanded[k]) {
+ for (std::string const& argExpanded : argsExpanded) {
+ if (varArgExpanded == argExpanded) {
found = 1;
break;
}
@@ -49,7 +47,7 @@ bool cmRemoveCommand::InitialPass(std::vector<std::string> const& args,
if (!value.empty()) {
value += ";";
}
- value += varArgsExpanded[j];
+ value += varArgExpanded;
}
}
diff --git a/Source/cmRemoveCommand.h b/Source/cmRemoveCommand.h
index f2e89f6e1..7b118497b 100644
--- a/Source/cmRemoveCommand.h
+++ b/Source/cmRemoveCommand.h
@@ -3,7 +3,7 @@
#ifndef cmRemoveCommand_h
#define cmRemoveCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmRemoveCommand; }
+ cmCommand* Clone() override { return new cmRemoveCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmRemoveDefinitionsCommand.cxx b/Source/cmRemoveDefinitionsCommand.cxx
index f5fe2dfb7..8d3f6889e 100644
--- a/Source/cmRemoveDefinitionsCommand.cxx
+++ b/Source/cmRemoveDefinitionsCommand.cxx
@@ -15,9 +15,8 @@ bool cmRemoveDefinitionsCommand::InitialPass(
return true;
}
- for (std::vector<std::string>::const_iterator i = args.begin();
- i != args.end(); ++i) {
- this->Makefile->RemoveDefineFlag(i->c_str());
+ for (std::string const& i : args) {
+ this->Makefile->RemoveDefineFlag(i);
}
return true;
}
diff --git a/Source/cmRemoveDefinitionsCommand.h b/Source/cmRemoveDefinitionsCommand.h
index 9a9a5d535..a5cb2044d 100644
--- a/Source/cmRemoveDefinitionsCommand.h
+++ b/Source/cmRemoveDefinitionsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmRemoveDefinitionsCommand_h
#define cmRemoveDefinitionsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmRemoveDefinitionsCommand; }
+ cmCommand* Clone() override { return new cmRemoveDefinitionsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmReturnCommand.h b/Source/cmReturnCommand.h
index 87900e7e9..ef3961459 100644
--- a/Source/cmReturnCommand.h
+++ b/Source/cmReturnCommand.h
@@ -3,7 +3,7 @@
#ifndef cmReturnCommand_h
#define cmReturnCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmReturnCommand; }
+ cmCommand* Clone() override { return new cmReturnCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmRulePlaceholderExpander.cxx b/Source/cmRulePlaceholderExpander.cxx
index a71861af7..33389cad5 100644
--- a/Source/cmRulePlaceholderExpander.cxx
+++ b/Source/cmRulePlaceholderExpander.cxx
@@ -10,13 +10,13 @@
#include "cmSystemTools.h"
cmRulePlaceholderExpander::cmRulePlaceholderExpander(
- std::map<std::string, std::string> const& compilers,
- std::map<std::string, std::string> const& variableMappings,
- std::string const& compilerSysroot, std::string const& linkerSysroot)
- : Compilers(compilers)
- , VariableMappings(variableMappings)
- , CompilerSysroot(compilerSysroot)
- , LinkerSysroot(linkerSysroot)
+ std::map<std::string, std::string> compilers,
+ std::map<std::string, std::string> variableMappings,
+ std::string compilerSysroot, std::string linkerSysroot)
+ : Compilers(std::move(compilers))
+ , VariableMappings(std::move(variableMappings))
+ , CompilerSysroot(std::move(compilerSysroot))
+ , LinkerSysroot(std::move(linkerSysroot))
{
}
@@ -91,6 +91,31 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable(
if (replaceValues.Includes && variable == "INCLUDES") {
return replaceValues.Includes;
}
+ if (replaceValues.SwiftLibraryName) {
+ if (variable == "SWIFT_LIBRARY_NAME") {
+ return replaceValues.SwiftLibraryName;
+ }
+ }
+ if (replaceValues.SwiftModule) {
+ if (variable == "SWIFT_MODULE") {
+ return replaceValues.SwiftModule;
+ }
+ }
+ if (replaceValues.SwiftModuleName) {
+ if (variable == "SWIFT_MODULE_NAME") {
+ return replaceValues.SwiftModuleName;
+ }
+ }
+ if (replaceValues.SwiftOutputFileMap) {
+ if (variable == "SWIFT_OUTPUT_FILE_MAP") {
+ return replaceValues.SwiftOutputFileMap;
+ }
+ }
+ if (replaceValues.SwiftSources) {
+ if (variable == "SWIFT_SOURCES") {
+ return replaceValues.SwiftSources;
+ }
+ }
if (replaceValues.TargetPDB) {
if (variable == "TARGET_PDB") {
return replaceValues.TargetPDB;
@@ -110,7 +135,7 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable(
if (replaceValues.Target) {
if (variable == "TARGET_QUOTED") {
std::string targetQuoted = replaceValues.Target;
- if (!targetQuoted.empty() && targetQuoted[0] != '\"') {
+ if (!targetQuoted.empty() && targetQuoted.front() != '\"') {
targetQuoted = '\"';
targetQuoted += replaceValues.Target;
targetQuoted += '\"';
@@ -120,7 +145,7 @@ std::string cmRulePlaceholderExpander::ExpandRuleVariable(
if (variable == "TARGET_UNQUOTED") {
std::string unquoted = replaceValues.Target;
std::string::size_type sz = unquoted.size();
- if (sz > 2 && unquoted[0] == '\"' && unquoted[sz - 1] == '\"') {
+ if (sz > 2 && unquoted.front() == '\"' && unquoted.back() == '\"') {
unquoted = unquoted.substr(1, sz - 2);
}
return unquoted;
diff --git a/Source/cmRulePlaceholderExpander.h b/Source/cmRulePlaceholderExpander.h
index 7b19210d3..8f361967b 100644
--- a/Source/cmRulePlaceholderExpander.h
+++ b/Source/cmRulePlaceholderExpander.h
@@ -15,16 +15,16 @@ class cmRulePlaceholderExpander
{
public:
cmRulePlaceholderExpander(
- std::map<std::string, std::string> const& compilers,
- std::map<std::string, std::string> const& variableMappings,
- std::string const& compilerSysroot, std::string const& linkerSysroot);
+ std::map<std::string, std::string> compilers,
+ std::map<std::string, std::string> variableMappings,
+ std::string compilerSysroot, std::string linkerSysroot);
void SetTargetImpLib(std::string const& targetImpLib)
{
this->TargetImpLib = targetImpLib;
}
- // Create a struct to hold the varibles passed into
+ // Create a struct to hold the variables passed into
// ExpandRuleVariables
struct RuleVariables
{
@@ -58,6 +58,11 @@ public:
const char* Includes;
const char* DependencyFile;
const char* FilterPrefix;
+ const char* SwiftLibraryName;
+ const char* SwiftModule;
+ const char* SwiftModuleName;
+ const char* SwiftOutputFileMap;
+ const char* SwiftSources;
};
// Expand rule variables in CMake of the type found in language rules
diff --git a/Source/cmScriptGenerator.cxx b/Source/cmScriptGenerator.cxx
index 753a1ba6f..9182b4165 100644
--- a/Source/cmScriptGenerator.cxx
+++ b/Source/cmScriptGenerator.cxx
@@ -4,20 +4,19 @@
#include "cmSystemTools.h"
-cmScriptGenerator::cmScriptGenerator(
- const std::string& config_var,
- std::vector<std::string> const& configurations)
- : RuntimeConfigVariable(config_var)
- , Configurations(configurations)
+#include <utility>
+
+cmScriptGenerator::cmScriptGenerator(std::string config_var,
+ std::vector<std::string> configurations)
+ : RuntimeConfigVariable(std::move(config_var))
+ , Configurations(std::move(configurations))
, ConfigurationName("")
- , ConfigurationTypes(CM_NULLPTR)
+ , ConfigurationTypes(nullptr)
, ActionsPerConfig(false)
{
}
-cmScriptGenerator::~cmScriptGenerator()
-{
-}
+cmScriptGenerator::~cmScriptGenerator() = default;
void cmScriptGenerator::Generate(
std::ostream& os, const std::string& config,
@@ -26,8 +25,8 @@ void cmScriptGenerator::Generate(
this->ConfigurationName = config;
this->ConfigurationTypes = &configurationTypes;
this->GenerateScript(os);
- this->ConfigurationName = "";
- this->ConfigurationTypes = CM_NULLPTR;
+ this->ConfigurationName.clear();
+ this->ConfigurationTypes = nullptr;
}
static void cmScriptGeneratorEncodeConfig(const std::string& config,
@@ -69,11 +68,10 @@ std::string cmScriptGenerator::CreateConfigTest(
result += this->RuntimeConfigVariable;
result += "}\" MATCHES \"^(";
const char* sep = "";
- for (std::vector<std::string>::const_iterator ci = configs.begin();
- ci != configs.end(); ++ci) {
+ for (std::string const& config : configs) {
result += sep;
sep = "|";
- cmScriptGeneratorEncodeConfig(*ci, result);
+ cmScriptGeneratorEncodeConfig(config, result);
}
result += ")$\"";
return result;
@@ -123,10 +121,8 @@ bool cmScriptGenerator::GeneratesForConfig(const std::string& config)
// 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) {
+ for (std::string const& cfg : this->Configurations) {
+ if (cmSystemTools::UpperCase(cfg) == config_upper) {
return true;
}
}
@@ -163,15 +159,12 @@ void cmScriptGenerator::GenerateScriptActionsPerConfig(std::ostream& os,
// 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)) {
+ for (std::string const& cfgType : *this->ConfigurationTypes) {
+ if (this->GeneratesForConfig(cfgType)) {
// Generate a per-configuration block.
- std::string config_test = this->CreateConfigTest(config);
+ std::string config_test = this->CreateConfigTest(cfgType);
os << indent << (first ? "if(" : "elseif(") << config_test << ")\n";
- this->GenerateScriptForConfig(os, config, indent.Next());
+ this->GenerateScriptForConfig(os, cfgType, indent.Next());
first = false;
}
}
diff --git a/Source/cmScriptGenerator.h b/Source/cmScriptGenerator.h
index d0879c687..e334d5bad 100644
--- a/Source/cmScriptGenerator.h
+++ b/Source/cmScriptGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmScriptGenerator_h
#define cmScriptGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <ostream>
#include <string>
@@ -12,10 +12,7 @@
class cmScriptGeneratorIndent
{
public:
- cmScriptGeneratorIndent()
- : Level(0)
- {
- }
+ cmScriptGeneratorIndent() = default;
cmScriptGeneratorIndent(int level)
: Level(level)
{
@@ -32,7 +29,7 @@ public:
}
private:
- int Level;
+ int Level = 0;
};
inline std::ostream& operator<<(std::ostream& os,
cmScriptGeneratorIndent indent)
@@ -47,13 +44,14 @@ inline std::ostream& operator<<(std::ostream& os,
*/
class cmScriptGenerator
{
- CM_DISABLE_COPY(cmScriptGenerator)
-
public:
- cmScriptGenerator(const std::string& config_var,
- std::vector<std::string> const& configurations);
+ cmScriptGenerator(std::string config_var,
+ std::vector<std::string> configurations);
virtual ~cmScriptGenerator();
+ cmScriptGenerator(cmScriptGenerator const&) = delete;
+ cmScriptGenerator& operator=(cmScriptGenerator const&) = delete;
+
void Generate(std::ostream& os, const std::string& config,
std::vector<std::string> const& configurationTypes);
diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx
index 0df6e0c06..f98984ed6 100644
--- a/Source/cmSearchPath.cxx
+++ b/Source/cmSearchPath.cxx
@@ -16,9 +16,7 @@ cmSearchPath::cmSearchPath(cmFindCommon* findCmd)
{
}
-cmSearchPath::~cmSearchPath()
-{
-}
+cmSearchPath::~cmSearchPath() = default;
void cmSearchPath::ExtractWithout(const std::set<std::string>& ignore,
std::vector<std::string>& outPaths,
@@ -27,10 +25,9 @@ void cmSearchPath::ExtractWithout(const std::set<std::string>& ignore,
if (clear) {
outPaths.clear();
}
- for (std::vector<std::string>::const_iterator p = this->Paths.begin();
- p != this->Paths.end(); ++p) {
- if (ignore.count(*p) == 0) {
- outPaths.push_back(*p);
+ for (std::string const& path : this->Paths) {
+ if (ignore.count(path) == 0) {
+ outPaths.push_back(path);
}
}
}
@@ -42,7 +39,7 @@ void cmSearchPath::AddPath(const std::string& path)
void cmSearchPath::AddUserPath(const std::string& path)
{
- assert(this->FC != CM_NULLPTR);
+ assert(this->FC != nullptr);
std::vector<std::string> outPaths;
@@ -69,25 +66,24 @@ void cmSearchPath::AddUserPath(const std::string& path)
}
// Process them all from the current directory
- for (std::vector<std::string>::const_iterator p = outPaths.begin();
- p != outPaths.end(); ++p) {
- this->AddPathInternal(*p, this->FC->Makefile->GetCurrentSourceDirectory());
+ for (std::string const& p : outPaths) {
+ this->AddPathInternal(
+ p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}
void cmSearchPath::AddCMakePath(const std::string& variable)
{
- assert(this->FC != CM_NULLPTR);
+ assert(this->FC != nullptr);
// Get a path from a CMake variable.
if (const char* value = this->FC->Makefile->GetDefinition(variable)) {
std::vector<std::string> expanded;
cmSystemTools::ExpandListArgument(value, expanded);
- for (std::vector<std::string>::const_iterator p = expanded.begin();
- p != expanded.end(); ++p) {
- this->AddPathInternal(*p,
- this->FC->Makefile->GetCurrentSourceDirectory());
+ for (std::string const& p : expanded) {
+ this->AddPathInternal(
+ p, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}
}
@@ -96,23 +92,22 @@ void cmSearchPath::AddEnvPath(const std::string& variable)
{
std::vector<std::string> expanded;
cmSystemTools::GetPath(expanded, variable.c_str());
- for (std::vector<std::string>::const_iterator p = expanded.begin();
- p != expanded.end(); ++p) {
- this->AddPathInternal(*p);
+ for (std::string const& p : expanded) {
+ this->AddPathInternal(p);
}
}
void cmSearchPath::AddCMakePrefixPath(const std::string& variable)
{
- assert(this->FC != CM_NULLPTR);
+ assert(this->FC != nullptr);
// Get a path from a CMake variable.
if (const char* value = this->FC->Makefile->GetDefinition(variable)) {
std::vector<std::string> expanded;
cmSystemTools::ExpandListArgument(value, expanded);
- this->AddPrefixPaths(expanded,
- this->FC->Makefile->GetCurrentSourceDirectory());
+ this->AddPrefixPaths(
+ expanded, this->FC->Makefile->GetCurrentSourceDirectory().c_str());
}
}
@@ -142,33 +137,31 @@ void cmSearchPath::AddSuffixes(const std::vector<std::string>& suffixes)
inPaths.swap(this->Paths);
this->Paths.reserve(inPaths.size() * (suffixes.size() + 1));
- for (std::vector<std::string>::iterator ip = inPaths.begin();
- ip != inPaths.end(); ++ip) {
- cmSystemTools::ConvertToUnixSlashes(*ip);
+ for (std::string& inPath : inPaths) {
+ cmSystemTools::ConvertToUnixSlashes(inPath);
// 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 = *ip;
- if (!p.empty() && *p.rbegin() != '/') {
+ std::string p = inPath;
+ if (!p.empty() && p.back() != '/') {
p += "/";
}
// Combine with all the suffixes
- for (std::vector<std::string>::const_iterator s = suffixes.begin();
- s != suffixes.end(); ++s) {
- this->Paths.push_back(p + *s);
+ for (std::string const& suffix : suffixes) {
+ this->Paths.push_back(p + suffix);
}
// And now the original w/o any suffix
- this->Paths.push_back(*ip);
+ this->Paths.push_back(std::move(inPath));
}
}
void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
const char* base)
{
- assert(this->FC != CM_NULLPTR);
+ assert(this->FC != nullptr);
// default for programs
std::string subdir = "bin";
@@ -178,13 +171,12 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
} else if (this->FC->CMakePathName == "LIBRARY") {
subdir = "lib";
} else if (this->FC->CMakePathName == "FRAMEWORK") {
- subdir = ""; // ? what to do for frameworks ?
+ subdir.clear(); // ? what to do for frameworks ?
}
- for (std::vector<std::string>::const_iterator p = paths.begin();
- p != paths.end(); ++p) {
- std::string dir = *p;
- if (!subdir.empty() && !dir.empty() && *dir.rbegin() != '/') {
+ for (std::string const& path : paths) {
+ std::string dir = path;
+ if (!subdir.empty() && !dir.empty() && dir.back() != '/') {
dir += "/";
}
if (subdir == "include" || subdir == "lib") {
@@ -201,15 +193,15 @@ void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
if (subdir == "bin") {
this->AddPathInternal(dir + "sbin", base);
}
- if (!subdir.empty() && *p != "/") {
- this->AddPathInternal(*p, base);
+ if (!subdir.empty() && path != "/") {
+ this->AddPathInternal(path, base);
}
}
}
void cmSearchPath::AddPathInternal(const std::string& path, const char* base)
{
- assert(this->FC != CM_NULLPTR);
+ assert(this->FC != nullptr);
std::string collapsed = cmSystemTools::CollapseFullPath(path, base);
@@ -219,6 +211,6 @@ void cmSearchPath::AddPathInternal(const std::string& path, const char* base)
// Insert the path if has not already been emitted.
if (this->FC->SearchPathsEmitted.insert(collapsed).second) {
- this->Paths.push_back(collapsed);
+ this->Paths.push_back(std::move(collapsed));
}
}
diff --git a/Source/cmSearchPath.h b/Source/cmSearchPath.h
index 932022aa1..2a576ed59 100644
--- a/Source/cmSearchPath.h
+++ b/Source/cmSearchPath.h
@@ -3,7 +3,7 @@
#ifndef cmSearchPath_h
#define cmSearchPath_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <string>
@@ -23,7 +23,7 @@ public:
// cmSearchPath must be initialized from a valid pointer. The only reason
// for the default is to allow it to be easily used in stl containers.
// Attempting to initialize with a NULL value will fail an assertion
- cmSearchPath(cmFindCommon* findCmd = CM_NULLPTR);
+ cmSearchPath(cmFindCommon* findCmd = nullptr);
~cmSearchPath();
const std::vector<std::string>& GetPaths() const { return this->Paths; }
@@ -39,11 +39,11 @@ public:
void AddCMakePrefixPath(const std::string& variable);
void AddEnvPrefixPath(const std::string& variable, bool stripBin = false);
void AddSuffixes(const std::vector<std::string>& suffixes);
+ void AddPrefixPaths(const std::vector<std::string>& paths,
+ const char* base = nullptr);
protected:
- void AddPrefixPaths(const std::vector<std::string>& paths,
- const char* base = CM_NULLPTR);
- void AddPathInternal(const std::string& path, const char* base = CM_NULLPTR);
+ void AddPathInternal(const std::string& path, const char* base = nullptr);
cmFindCommon* FC;
std::vector<std::string> Paths;
diff --git a/Source/cmSeparateArgumentsCommand.cxx b/Source/cmSeparateArgumentsCommand.cxx
index 7b222a041..28cbdc0ad 100644
--- a/Source/cmSeparateArgumentsCommand.cxx
+++ b/Source/cmSeparateArgumentsCommand.cxx
@@ -36,29 +36,29 @@ bool cmSeparateArgumentsCommand::InitialPass(
DoingCommand
};
Doing doing = DoingVariable;
- for (unsigned int i = 0; i < args.size(); ++i) {
+ for (std::string const& arg : args) {
if (doing == DoingVariable) {
- var = args[i];
+ var = arg;
doing = DoingMode;
- } else if (doing == DoingMode && args[i] == "NATIVE_COMMAND") {
+ } else if (doing == DoingMode && arg == "NATIVE_COMMAND") {
#ifdef _WIN32
mode = ModeWindows;
#else
mode = ModeUnix;
#endif
doing = DoingCommand;
- } else if (doing == DoingMode && args[i] == "UNIX_COMMAND") {
+ } else if (doing == DoingMode && arg == "UNIX_COMMAND") {
mode = ModeUnix;
doing = DoingCommand;
- } else if (doing == DoingMode && args[i] == "WINDOWS_COMMAND") {
+ } else if (doing == DoingMode && arg == "WINDOWS_COMMAND") {
mode = ModeWindows;
doing = DoingCommand;
} else if (doing == DoingCommand) {
- command = args[i];
+ command = arg;
doing = DoingNone;
} else {
std::ostringstream e;
- e << "given unknown argument " << args[i];
+ e << "given unknown argument " << arg;
this->SetError(e.str());
return false;
}
@@ -84,19 +84,17 @@ bool cmSeparateArgumentsCommand::InitialPass(
// 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) {
+ for (std::string const& vi : vec) {
// Separate from the previous argument.
value += sep;
sep = ";";
// Preserve semicolons.
- for (std::string::const_iterator si = vi->begin(); si != vi->end();
- ++si) {
- if (*si == ';') {
+ for (char si : vi) {
+ if (si == ';') {
value += '\\';
}
- value += *si;
+ value += si;
}
}
this->Makefile->AddDefinition(var, value.c_str());
diff --git a/Source/cmSeparateArgumentsCommand.h b/Source/cmSeparateArgumentsCommand.h
index 6bf8549cf..988ad23ae 100644
--- a/Source/cmSeparateArgumentsCommand.h
+++ b/Source/cmSeparateArgumentsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSeparateArgumentsCommand_h
#define cmSeparateArgumentsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmSeparateArgumentsCommand; }
+ cmCommand* Clone() override { return new cmSeparateArgumentsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx
index 7fc6ed755..1903fd917 100644
--- a/Source/cmServer.cxx
+++ b/Source/cmServer.cxx
@@ -2,7 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmServer.h"
-#include "cmServerConnection.h"
+#include "cmAlgorithms.h"
+#include "cmConnection.h"
+#include "cmFileMonitor.h"
+#include "cmJsonObjectDictionary.h"
#include "cmServerDictionary.h"
#include "cmServerProtocol.h"
#include "cmSystemTools.h"
@@ -14,8 +17,26 @@
#include <algorithm>
#include <cassert>
#include <cstdint>
+#include <iostream>
+#include <memory>
+#include <mutex>
#include <utility>
+void on_signal(uv_signal_t* signal, int signum)
+{
+ auto conn = static_cast<cmServerBase*>(signal->data);
+ conn->OnSignal(signum);
+}
+
+static void on_walk_to_shutdown(uv_handle_t* handle, void* arg)
+{
+ (void)arg;
+ assert(uv_is_closing(handle));
+ if (!uv_is_closing(handle)) {
+ uv_close(handle, &cmEventBasedConnection::on_close);
+ }
+}
+
class cmServer::DebugInfo
{
public:
@@ -30,76 +51,73 @@ public:
uint64_t StartTime;
};
-cmServer::cmServer(cmServerConnection* conn, bool supportExperimental)
- : Connection(conn)
+cmServer::cmServer(cmConnection* conn, bool supportExperimental)
+ : cmServerBase(conn)
, SupportExperimental(supportExperimental)
{
- this->Connection->SetServer(this);
// Register supported protocols:
- this->RegisterProtocol(new cmServerProtocol1_0);
+ this->RegisterProtocol(new cmServerProtocol1);
}
cmServer::~cmServer()
{
- if (!this->Protocol) { // Server was never fully started!
- return;
- }
+ Close();
for (cmServerProtocol* p : this->SupportedProtocols) {
delete p;
}
-
- delete this->Connection;
}
-void cmServer::PopOne()
+void cmServer::ProcessRequest(cmConnection* connection,
+ const std::string& input)
{
- if (this->Queue.empty()) {
- return;
- }
-
Json::Reader reader;
Json::Value value;
- const std::string input = this->Queue.front();
- this->Queue.erase(this->Queue.begin());
-
if (!reader.parse(input, value)) {
- this->WriteParseError("Failed to parse JSON input.");
+ this->WriteParseError(connection, "Failed to parse JSON input.");
return;
}
std::unique_ptr<DebugInfo> debug;
Json::Value debugValue = value["debug"];
if (!debugValue.isNull()) {
- debug = std::make_unique<DebugInfo>();
+ debug = cm::make_unique<DebugInfo>();
debug->OutputFile = debugValue["dumpToFile"].asString();
debug->PrintStatistics = debugValue["showStats"].asBool();
}
- const cmServerRequest request(this, value[kTYPE_KEY].asString(),
+ const cmServerRequest request(this, connection, value[kTYPE_KEY].asString(),
value[kCOOKIE_KEY].asString(), value);
- if (request.Type == "") {
+ if (request.Type.empty()) {
cmServerResponse response(request);
response.SetError("No type given in request.");
- this->WriteResponse(response, nullptr);
+ this->WriteResponse(connection, response, nullptr);
return;
}
- cmSystemTools::SetMessageCallback(reportMessage,
- const_cast<cmServerRequest*>(&request));
+ cmSystemTools::SetMessageCallback(
+ [&request](const std::string& msg, const char* title) {
+ reportMessage(msg, title, request);
+ });
+
if (this->Protocol) {
this->Protocol->CMakeInstance()->SetProgressCallback(
- reportProgress, const_cast<cmServerRequest*>(&request));
- this->WriteResponse(this->Protocol->Process(request), debug.get());
+ [&request](const std::string& msg, float prog) {
+ reportProgress(msg, prog, request);
+ });
+ this->WriteResponse(connection, this->Protocol->Process(request),
+ debug.get());
} else {
- this->WriteResponse(this->SetProtocolVersion(request), debug.get());
+ this->WriteResponse(connection, this->SetProtocolVersion(request),
+ debug.get());
}
}
void cmServer::RegisterProtocol(cmServerProtocol* protocol)
{
if (protocol->IsExperimental() && !this->SupportExperimental) {
+ delete protocol;
return;
}
auto version = protocol->ProtocolVersion();
@@ -115,7 +133,7 @@ void cmServer::RegisterProtocol(cmServerProtocol* protocol)
}
}
-void cmServer::PrintHello() const
+void cmServer::PrintHello(cmConnection* connection) const
{
Json::Value hello = Json::objectValue;
hello[kTYPE_KEY] = "hello";
@@ -134,37 +152,27 @@ void cmServer::PrintHello() const
protocolVersions.append(tmp);
}
- this->WriteJsonObject(hello, nullptr);
-}
-
-void cmServer::QueueRequest(const std::string& request)
-{
- this->Queue.push_back(request);
- this->PopOne();
+ this->WriteJsonObject(connection, hello, nullptr);
}
-void cmServer::reportProgress(const char* msg, float progress, void* data)
+void cmServer::reportProgress(const std::string& msg, float progress,
+ const cmServerRequest& request)
{
- const cmServerRequest* request = static_cast<const cmServerRequest*>(data);
- assert(request);
if (progress < 0.0f || progress > 1.0f) {
- request->ReportMessage(msg, "");
+ request.ReportMessage(msg, "");
} else {
- request->ReportProgress(0, static_cast<int>(progress * 1000), 1000, msg);
+ request.ReportProgress(0, static_cast<int>(progress * 1000), 1000, msg);
}
}
-void cmServer::reportMessage(const char* msg, const char* title,
- bool& /* cancel */, void* data)
+void cmServer::reportMessage(const std::string& msg, const char* title,
+ const cmServerRequest& request)
{
- const cmServerRequest* request = static_cast<const cmServerRequest*>(data);
- assert(request);
- assert(msg);
std::string titleString;
if (title) {
titleString = title;
}
- request->ReportMessage(std::string(msg), titleString);
+ request.ReportMessage(msg, titleString);
}
cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)
@@ -209,14 +217,14 @@ cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)
}
this->Protocol =
- this->FindMatchingProtocol(this->SupportedProtocols, major, minor);
+ cmServer::FindMatchingProtocol(this->SupportedProtocols, major, minor);
if (!this->Protocol) {
return request.ReportError("Protocol version not supported.");
}
std::string errorMessage;
if (!this->Protocol->Activate(this, request, &errorMessage)) {
- this->Protocol = CM_NULLPTR;
+ this->Protocol = nullptr;
return request.ReportError("Failed to activate protocol version: " +
errorMessage);
}
@@ -232,17 +240,27 @@ bool cmServer::Serve(std::string* errorMessage)
}
assert(!this->Protocol);
- return Connection->ProcessEvents(errorMessage);
+ return cmServerBase::Serve(errorMessage);
}
cmFileMonitor* cmServer::FileMonitor() const
{
- return Connection->FileMonitor();
+ return fileMonitor.get();
}
void cmServer::WriteJsonObject(const Json::Value& jsonValue,
const DebugInfo* debug) const
{
+ cm::shared_lock<cm::shared_mutex> lock(ConnectionsMutex);
+ for (auto& connection : this->Connections) {
+ WriteJsonObject(connection.get(), jsonValue, debug);
+ }
+}
+
+void cmServer::WriteJsonObject(cmConnection* connection,
+ const Json::Value& jsonValue,
+ const DebugInfo* debug) const
+{
Json::FastWriter writer;
auto beforeJson = uv_hrtime();
@@ -272,8 +290,7 @@ void cmServer::WriteJsonObject(const Json::Value& jsonValue,
}
}
- Connection->WriteData(std::string("\n") + kSTART_MAGIC + std::string("\n") +
- result + kEND_MAGIC + std::string("\n"));
+ connection->WriteData(result);
}
cmServerProtocol* cmServer::FindMatchingProtocol(
@@ -311,7 +328,7 @@ void cmServer::WriteProgress(const cmServerRequest& request, int min,
obj[kPROGRESS_MAXIMUM_KEY] = max;
obj[kPROGRESS_CURRENT_KEY] = current;
- this->WriteJsonObject(obj, nullptr);
+ this->WriteJsonObject(request.Connection, obj, nullptr);
}
void cmServer::WriteMessage(const cmServerRequest& request,
@@ -331,10 +348,11 @@ void cmServer::WriteMessage(const cmServerRequest& request,
obj[kTITLE_KEY] = title;
}
- WriteJsonObject(obj, nullptr);
+ WriteJsonObject(request.Connection, obj, nullptr);
}
-void cmServer::WriteParseError(const std::string& message) const
+void cmServer::WriteParseError(cmConnection* connection,
+ const std::string& message) const
{
Json::Value obj = Json::objectValue;
obj[kTYPE_KEY] = kERROR_TYPE;
@@ -342,7 +360,7 @@ void cmServer::WriteParseError(const std::string& message) const
obj[kREPLY_TO_KEY] = "";
obj[kCOOKIE_KEY] = "";
- this->WriteJsonObject(obj, nullptr);
+ this->WriteJsonObject(connection, obj, nullptr);
}
void cmServer::WriteSignal(const std::string& name,
@@ -358,7 +376,8 @@ void cmServer::WriteSignal(const std::string& name,
WriteJsonObject(obj, nullptr);
}
-void cmServer::WriteResponse(const cmServerResponse& response,
+void cmServer::WriteResponse(cmConnection* connection,
+ const cmServerResponse& response,
const DebugInfo* debug) const
{
assert(response.IsComplete());
@@ -371,5 +390,180 @@ void cmServer::WriteResponse(const cmServerResponse& response,
obj[kERROR_MESSAGE_KEY] = response.ErrorMessage();
}
- this->WriteJsonObject(obj, debug);
+ this->WriteJsonObject(connection, obj, debug);
+}
+
+void cmServer::OnConnected(cmConnection* connection)
+{
+ PrintHello(connection);
+}
+
+void cmServer::OnServeStart()
+{
+ cmServerBase::OnServeStart();
+ fileMonitor = std::make_shared<cmFileMonitor>(GetLoop());
+}
+
+void cmServer::StartShutDown()
+{
+ if (fileMonitor) {
+ fileMonitor->StopMonitoring();
+ fileMonitor.reset();
+ }
+ cmServerBase::StartShutDown();
+}
+
+static void __start_thread(void* arg)
+{
+ auto server = static_cast<cmServerBase*>(arg);
+ std::string error;
+ bool success = server->Serve(&error);
+ if (!success || !error.empty()) {
+ std::cerr << "Error during serve: " << error << std::endl;
+ }
+}
+
+bool cmServerBase::StartServeThread()
+{
+ ServeThreadRunning = true;
+ uv_thread_create(&ServeThread, __start_thread, this);
+ return true;
+}
+
+static void __shutdownThread(uv_async_t* arg)
+{
+ auto server = static_cast<cmServerBase*>(arg->data);
+ server->StartShutDown();
+}
+
+bool cmServerBase::Serve(std::string* errorMessage)
+{
+#ifndef NDEBUG
+ uv_thread_t blank_thread_t = {};
+ assert(uv_thread_equal(&blank_thread_t, &ServeThreadId));
+ ServeThreadId = uv_thread_self();
+#endif
+
+ errorMessage->clear();
+
+ ShutdownSignal.init(Loop, __shutdownThread, this);
+
+ SIGINTHandler.init(Loop, this);
+ SIGHUPHandler.init(Loop, this);
+
+ SIGINTHandler.start(&on_signal, SIGINT);
+ SIGHUPHandler.start(&on_signal, SIGHUP);
+
+ OnServeStart();
+
+ {
+ cm::shared_lock<cm::shared_mutex> lock(ConnectionsMutex);
+ for (auto& connection : Connections) {
+ if (!connection->OnServeStart(errorMessage)) {
+ return false;
+ }
+ }
+ }
+
+ if (uv_run(&Loop, UV_RUN_DEFAULT) != 0) {
+ // It is important we don't ever let the event loop exit with open handles
+ // at best this is a memory leak, but it can also introduce race conditions
+ // which can hang the program.
+ assert(false && "Event loop stopped in unclean state.");
+
+ *errorMessage = "Internal Error: Event loop stopped in unclean state.";
+ return false;
+ }
+
+ return true;
+}
+
+void cmServerBase::OnConnected(cmConnection*)
+{
+}
+
+void cmServerBase::OnServeStart()
+{
+}
+
+void cmServerBase::StartShutDown()
+{
+ ShutdownSignal.reset();
+ SIGINTHandler.reset();
+ SIGHUPHandler.reset();
+
+ {
+ std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
+ for (auto& connection : Connections) {
+ connection->OnConnectionShuttingDown();
+ }
+ Connections.clear();
+ }
+
+ uv_walk(&Loop, on_walk_to_shutdown, nullptr);
+}
+
+bool cmServerBase::OnSignal(int signum)
+{
+ (void)signum;
+ StartShutDown();
+ return true;
+}
+
+cmServerBase::cmServerBase(cmConnection* connection)
+{
+ auto err = uv_loop_init(&Loop);
+ (void)err;
+ Loop.data = this;
+ assert(err == 0);
+
+ AddNewConnection(connection);
+}
+
+void cmServerBase::Close()
+{
+ if (Loop.data) {
+ if (ServeThreadRunning) {
+ this->ShutdownSignal.send();
+ uv_thread_join(&ServeThread);
+ }
+
+ uv_loop_close(&Loop);
+ Loop.data = nullptr;
+ }
+}
+cmServerBase::~cmServerBase()
+{
+ Close();
+}
+
+void cmServerBase::AddNewConnection(cmConnection* ownedConnection)
+{
+ {
+ std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
+ Connections.emplace_back(ownedConnection);
+ }
+ ownedConnection->SetServer(this);
+}
+
+uv_loop_t* cmServerBase::GetLoop()
+{
+ return &Loop;
+}
+
+void cmServerBase::OnDisconnect(cmConnection* pConnection)
+{
+ auto pred = [pConnection](const std::unique_ptr<cmConnection>& m) {
+ return m.get() == pConnection;
+ };
+ {
+ std::unique_lock<cm::shared_mutex> lock(ConnectionsMutex);
+ Connections.erase(
+ std::remove_if(Connections.begin(), Connections.end(), pred),
+ Connections.end());
+ }
+
+ if (Connections.empty()) {
+ this->ShutdownSignal.send();
+ }
}
diff --git a/Source/cmServer.h b/Source/cmServer.h
index b8140504c..aba4924c9 100644
--- a/Source/cmServer.h
+++ b/Source/cmServer.h
@@ -2,31 +2,102 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cm_jsoncpp_value.h"
+#include "cm_thread.hxx"
#include "cm_uv.h"
+#include "cmUVHandlePtr.h"
+
+#include <memory> // IWYU pragma: keep
#include <string>
#include <vector>
+class cmConnection;
class cmFileMonitor;
-class cmServerConnection;
class cmServerProtocol;
class cmServerRequest;
class cmServerResponse;
-class cmServer
+/***
+ * This essentially hold and manages a libuv event queue and responds to
+ * messages
+ * on any of its connections.
+ */
+class cmServerBase
{
- CM_DISABLE_COPY(cmServer)
+public:
+ cmServerBase(cmConnection* connection);
+ virtual ~cmServerBase();
+
+ virtual void AddNewConnection(cmConnection* ownedConnection);
+
+ /***
+ * The main override responsible for tailoring behavior towards
+ * whatever the given server is supposed to do
+ *
+ * This should almost always be called by the given connections
+ * directly.
+ *
+ * @param connection The connection the request was received on
+ * @param request The actual request
+ */
+ virtual void ProcessRequest(cmConnection* connection,
+ const std::string& request) = 0;
+ virtual void OnConnected(cmConnection* connection);
+
+ /***
+ * Start a dedicated thread. If this is used to start the server, it will
+ * join on the
+ * servers dtor.
+ */
+ virtual bool StartServeThread();
+ virtual bool Serve(std::string* errorMessage);
+
+ virtual void OnServeStart();
+ virtual void StartShutDown();
+
+ virtual bool OnSignal(int signum);
+ uv_loop_t* GetLoop();
+ void Close();
+ void OnDisconnect(cmConnection* pConnection);
+
+protected:
+ mutable cm::shared_mutex ConnectionsMutex;
+ std::vector<std::unique_ptr<cmConnection>> Connections;
+
+ bool ServeThreadRunning = false;
+ uv_thread_t ServeThread;
+ cm::uv_async_ptr ShutdownSignal;
+#ifndef NDEBUG
+public:
+ // When the server starts it will mark down it's current thread ID,
+ // which is useful in other contexts to just assert that operations
+ // are performed on that same thread.
+ uv_thread_t ServeThreadId = {};
+
+protected:
+#endif
+
+ uv_loop_t Loop;
+
+ cm::uv_signal_ptr SIGINTHandler;
+ cm::uv_signal_ptr SIGHUPHandler;
+};
+class cmServer : public cmServerBase
+{
public:
class DebugInfo;
- cmServer(cmServerConnection* conn, bool supportExperimental);
- ~cmServer();
+ cmServer(cmConnection* conn, bool supportExperimental);
+ ~cmServer() override;
+
+ cmServer(cmServer const&) = delete;
+ cmServer& operator=(cmServer const&) = delete;
- bool Serve(std::string* errorMessage);
+ bool Serve(std::string* errorMessage) override;
cmFileMonitor* FileMonitor() const;
@@ -34,60 +105,56 @@ private:
void RegisterProtocol(cmServerProtocol* protocol);
// Callbacks from cmServerConnection:
- void PopOne();
- void QueueRequest(const std::string& request);
- static void reportProgress(const char* msg, float progress, void* data);
- static void reportMessage(const char* msg, const char* title, bool& cancel,
- void* data);
+ void ProcessRequest(cmConnection* connection,
+ const std::string& request) override;
+ std::shared_ptr<cmFileMonitor> fileMonitor;
+
+public:
+ void OnServeStart() override;
+
+ void StartShutDown() override;
+
+public:
+ void OnConnected(cmConnection* connection) override;
+
+private:
+ static void reportProgress(const std::string& msg, float progress,
+ const cmServerRequest& request);
+ static void reportMessage(const std::string& msg, const char* title,
+ const cmServerRequest& request);
// Handle requests:
cmServerResponse SetProtocolVersion(const cmServerRequest& request);
- void PrintHello() const;
+ void PrintHello(cmConnection* connection) const;
// Write responses:
void WriteProgress(const cmServerRequest& request, int min, int current,
int max, const std::string& message) const;
void WriteMessage(const cmServerRequest& request, const std::string& message,
const std::string& title) const;
- void WriteResponse(const cmServerResponse& response,
+ void WriteResponse(cmConnection* connection,
+ const cmServerResponse& response,
const DebugInfo* debug) const;
- void WriteParseError(const std::string& message) const;
+ void WriteParseError(cmConnection* connection,
+ const std::string& message) const;
void WriteSignal(const std::string& name, const Json::Value& obj) const;
void WriteJsonObject(Json::Value const& jsonValue,
const DebugInfo* debug) const;
+ void WriteJsonObject(cmConnection* connection, Json::Value const& jsonValue,
+ const DebugInfo* debug) const;
+
static cmServerProtocol* FindMatchingProtocol(
const std::vector<cmServerProtocol*>& protocols, int major, int minor);
- cmServerConnection* Connection = nullptr;
const bool SupportExperimental;
cmServerProtocol* Protocol = nullptr;
std::vector<cmServerProtocol*> SupportedProtocols;
- std::vector<std::string> Queue;
-
- std::string DataBuffer;
- std::string JsonData;
-
- uv_loop_t* Loop = nullptr;
-
- typedef union
- {
- uv_tty_t tty;
- uv_pipe_t pipe;
- } InOutUnion;
-
- InOutUnion Input;
- InOutUnion Output;
- uv_stream_t* InputStream = nullptr;
- uv_stream_t* OutputStream = nullptr;
-
- mutable bool Writing = false;
- friend class cmServerConnection;
friend class cmServerProtocol;
friend class cmServerRequest;
};
diff --git a/Source/cmServerConnection.cxx b/Source/cmServerConnection.cxx
index 36312edf4..a878890da 100644
--- a/Source/cmServerConnection.cxx
+++ b/Source/cmServerConnection.cxx
@@ -2,376 +2,162 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmServerConnection.h"
-#include "cmFileMonitor.h"
+#include "cmConfigure.h"
#include "cmServer.h"
#include "cmServerDictionary.h"
+#include "cm_uv.h"
-#include <assert.h>
-#include <string.h>
+#ifdef _WIN32
+# include "io.h"
+#else
+# include <unistd.h>
+#endif
+#include <cassert>
+#include <utility>
-namespace {
-
-struct write_req_t
-{
- uv_write_t req;
- uv_buf_t buf;
-};
-
-void on_alloc_buffer(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf)
+cmStdIoConnection::cmStdIoConnection(
+ cmConnectionBufferStrategy* bufferStrategy)
+ : cmEventBasedConnection(bufferStrategy)
{
- (void)(handle);
- char* rawBuffer = new char[suggested_size];
- *buf = uv_buf_init(rawBuffer, static_cast<unsigned int>(suggested_size));
}
-void on_read(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf)
+cm::uv_stream_ptr cmStdIoConnection::SetupStream(int file_id)
{
- auto conn = reinterpret_cast<cmServerConnection*>(stream->data);
- if (nread >= 0) {
- conn->ReadData(std::string(buf->base, buf->base + nread));
- } else {
- conn->TriggerShutdown();
+ switch (uv_guess_handle(file_id)) {
+ case UV_TTY: {
+ cm::uv_tty_ptr tty;
+ tty.init(*this->Server->GetLoop(), file_id, file_id == 0,
+ static_cast<cmEventBasedConnection*>(this));
+ uv_tty_set_mode(tty, UV_TTY_MODE_NORMAL);
+ return { std::move(tty) };
+ }
+ case UV_FILE:
+ if (file_id == 0) {
+ return nullptr;
+ }
+ // Intentional fallthrough; stdin can _not_ be treated as a named
+ // pipe, however stdout can be.
+ CM_FALLTHROUGH;
+ case UV_NAMED_PIPE: {
+ cm::uv_pipe_ptr pipe;
+ pipe.init(*this->Server->GetLoop(), 0,
+ static_cast<cmEventBasedConnection*>(this));
+ uv_pipe_open(pipe, file_id);
+ return { std::move(pipe) };
+ }
+ default:
+ assert(false && "Unable to determine stream type");
+ return nullptr;
}
-
- delete[](buf->base);
}
-void on_write(uv_write_t* req, int status)
+void cmStdIoConnection::SetServer(cmServerBase* s)
{
- (void)(status);
- auto conn = reinterpret_cast<cmServerConnection*>(req->data);
-
- // Free req and buffer
- write_req_t* wr = reinterpret_cast<write_req_t*>(req);
- delete[](wr->buf.base);
- delete wr;
+ cmConnection::SetServer(s);
+ if (!s) {
+ return;
+ }
- conn->ProcessNextRequest();
+ this->ReadStream = SetupStream(0);
+ this->WriteStream = SetupStream(1);
}
-void on_new_connection(uv_stream_t* stream, int status)
+void shutdown_connection(uv_prepare_t* prepare)
{
- (void)(status);
- auto conn = reinterpret_cast<cmServerConnection*>(stream->data);
- conn->Connect(stream);
-}
+ cmStdIoConnection* connection =
+ static_cast<cmStdIoConnection*>(prepare->data);
-void on_signal(uv_signal_t* signal, int signum)
-{
- auto conn = reinterpret_cast<cmServerConnection*>(signal->data);
- (void)(signum);
- conn->TriggerShutdown();
-}
-
-void on_signal_close(uv_handle_t* handle)
-{
- delete reinterpret_cast<uv_signal_t*>(handle);
+ if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(prepare))) {
+ uv_close(reinterpret_cast<uv_handle_t*>(prepare),
+ &cmEventBasedConnection::on_close_delete<uv_prepare_t>);
+ }
+ connection->OnDisconnect(0);
}
-void on_pipe_close(uv_handle_t* handle)
+bool cmStdIoConnection::OnServeStart(std::string* pString)
{
- delete reinterpret_cast<uv_pipe_t*>(handle);
-}
+ Server->OnConnected(this);
+ if (this->ReadStream.get()) {
+ uv_read_start(this->ReadStream, on_alloc_buffer, on_read);
+ } else if (uv_guess_handle(0) == UV_FILE) {
+ char buffer[1024];
+ while (auto len = read(0, buffer, sizeof(buffer))) {
+ ReadData(std::string(buffer, buffer + len));
+ }
-void on_tty_close(uv_handle_t* handle)
-{
- delete reinterpret_cast<uv_tty_t*>(handle);
+ // We can't start the disconnect from here, add a prepare hook to do that
+ // for us
+ auto prepare = new uv_prepare_t();
+ prepare->data = this;
+ uv_prepare_init(Server->GetLoop(), prepare);
+ uv_prepare_start(prepare, shutdown_connection);
+ }
+ return cmConnection::OnServeStart(pString);
}
-} // namespace
-
-class LoopGuard
+bool cmStdIoConnection::OnConnectionShuttingDown()
{
-public:
- LoopGuard(cmServerConnection* connection)
- : Connection(connection)
- {
- this->Connection->mLoop = uv_default_loop();
- if (!this->Connection->mLoop) {
- return;
- }
- this->Connection->mFileMonitor =
- new cmFileMonitor(this->Connection->mLoop);
+ if (ReadStream.get()) {
+ uv_read_stop(ReadStream);
+ ReadStream->data = nullptr;
}
- ~LoopGuard()
- {
- if (!this->Connection->mLoop) {
- return;
- }
+ this->ReadStream.reset();
- if (this->Connection->mFileMonitor) {
- delete this->Connection->mFileMonitor;
- }
- uv_loop_close(this->Connection->mLoop);
- this->Connection->mLoop = nullptr;
- }
+ cmEventBasedConnection::OnConnectionShuttingDown();
-private:
- cmServerConnection* Connection;
-};
+ return true;
+}
-cmServerConnection::cmServerConnection()
+cmServerPipeConnection::cmServerPipeConnection(const std::string& name)
+ : cmPipeConnection(name, new cmServerBufferStrategy)
{
}
-cmServerConnection::~cmServerConnection()
+cmServerStdIoConnection::cmServerStdIoConnection()
+ : cmStdIoConnection(new cmServerBufferStrategy)
{
}
-void cmServerConnection::SetServer(cmServer* s)
+cmConnectionBufferStrategy::~cmConnectionBufferStrategy() = default;
+
+void cmConnectionBufferStrategy::clear()
{
- this->Server = s;
}
-bool cmServerConnection::ProcessEvents(std::string* errorMessage)
+std::string cmServerBufferStrategy::BufferOutMessage(
+ const std::string& rawBuffer) const
{
- assert(this->Server);
- errorMessage->clear();
-
- this->RawReadBuffer.clear();
- this->RequestBuffer.clear();
-
- LoopGuard guard(this);
- (void)(guard);
- if (!this->mLoop) {
- *errorMessage = "Internal Error: Failed to create event loop.";
- return false;
- }
-
- this->SIGINTHandler = new uv_signal_t;
- uv_signal_init(this->mLoop, this->SIGINTHandler);
- this->SIGINTHandler->data = static_cast<void*>(this);
- uv_signal_start(this->SIGINTHandler, &on_signal, SIGINT);
-
- this->SIGHUPHandler = new uv_signal_t;
- uv_signal_init(this->mLoop, this->SIGHUPHandler);
- this->SIGHUPHandler->data = static_cast<void*>(this);
- uv_signal_start(this->SIGHUPHandler, &on_signal, SIGHUP);
-
- if (!DoSetup(errorMessage)) {
- return false;
- }
-
- if (uv_run(this->mLoop, UV_RUN_DEFAULT) != 0) {
- *errorMessage = "Internal Error: Event loop stopped in unclean state.";
- return false;
- }
-
- // These need to be cleaned up by now:
- assert(!this->ReadStream);
- assert(!this->WriteStream);
-
- this->RawReadBuffer.clear();
- this->RequestBuffer.clear();
-
- return true;
+ return std::string("\n") + kSTART_MAGIC + std::string("\n") + rawBuffer +
+ kEND_MAGIC + std::string("\n");
}
-void cmServerConnection::ReadData(const std::string& data)
+std::string cmServerBufferStrategy::BufferMessage(std::string& RawReadBuffer)
{
- this->RawReadBuffer += data;
-
for (;;) {
- auto needle = this->RawReadBuffer.find('\n');
+ auto needle = RawReadBuffer.find('\n');
if (needle == std::string::npos) {
- return;
+ return "";
}
- std::string line = this->RawReadBuffer.substr(0, needle);
+ std::string line = RawReadBuffer.substr(0, needle);
const auto ls = line.size();
if (ls > 1 && line.at(ls - 1) == '\r') {
line.erase(ls - 1, 1);
}
- this->RawReadBuffer.erase(this->RawReadBuffer.begin(),
- this->RawReadBuffer.begin() +
- static_cast<long>(needle) + 1);
+ RawReadBuffer.erase(RawReadBuffer.begin(),
+ RawReadBuffer.begin() + static_cast<long>(needle) + 1);
if (line == kSTART_MAGIC) {
- this->RequestBuffer.clear();
+ RequestBuffer.clear();
continue;
}
if (line == kEND_MAGIC) {
- this->Server->QueueRequest(this->RequestBuffer);
- this->RequestBuffer.clear();
- } else {
- this->RequestBuffer += line;
- this->RequestBuffer += "\n";
+ std::string rtn;
+ rtn.swap(this->RequestBuffer);
+ return rtn;
}
- }
-}
-
-void cmServerConnection::TriggerShutdown()
-{
- this->FileMonitor()->StopMonitoring();
-
- uv_signal_stop(this->SIGINTHandler);
- uv_signal_stop(this->SIGHUPHandler);
-
- uv_close(reinterpret_cast<uv_handle_t*>(this->SIGINTHandler),
- &on_signal_close); // delete handle
- uv_close(reinterpret_cast<uv_handle_t*>(this->SIGHUPHandler),
- &on_signal_close); // delete handle
-
- this->SIGINTHandler = nullptr;
- this->SIGHUPHandler = nullptr;
-
- this->TearDown();
-}
-
-void cmServerConnection::WriteData(const std::string& data)
-{
- assert(this->WriteStream);
- auto ds = data.size();
-
- write_req_t* req = new write_req_t;
- req->req.data = this;
- req->buf = uv_buf_init(new char[ds], static_cast<unsigned int>(ds));
- memcpy(req->buf.base, data.c_str(), ds);
-
- uv_write(reinterpret_cast<uv_write_t*>(req),
- static_cast<uv_stream_t*>(this->WriteStream), &req->buf, 1,
- on_write);
-}
-
-void cmServerConnection::ProcessNextRequest()
-{
- Server->PopOne();
-}
-
-void cmServerConnection::SendGreetings()
-{
- Server->PrintHello();
-}
-
-cmServerStdIoConnection::cmServerStdIoConnection()
-{
- this->Input.tty = nullptr;
- this->Output.tty = nullptr;
-}
-
-bool cmServerStdIoConnection::DoSetup(std::string* errorMessage)
-{
- (void)(errorMessage);
-
- if (uv_guess_handle(1) == UV_TTY) {
- usesTty = true;
- this->Input.tty = new uv_tty_t;
- uv_tty_init(this->Loop(), this->Input.tty, 0, 1);
- uv_tty_set_mode(this->Input.tty, UV_TTY_MODE_NORMAL);
- Input.tty->data = this;
- this->ReadStream = reinterpret_cast<uv_stream_t*>(this->Input.tty);
-
- this->Output.tty = new uv_tty_t;
- uv_tty_init(this->Loop(), this->Output.tty, 1, 0);
- uv_tty_set_mode(this->Output.tty, UV_TTY_MODE_NORMAL);
- Output.tty->data = this;
- this->WriteStream = reinterpret_cast<uv_stream_t*>(this->Output.tty);
- } else {
- usesTty = false;
- this->Input.pipe = new uv_pipe_t;
- uv_pipe_init(this->Loop(), this->Input.pipe, 0);
- uv_pipe_open(this->Input.pipe, 0);
- Input.pipe->data = this;
- this->ReadStream = reinterpret_cast<uv_stream_t*>(this->Input.pipe);
-
- this->Output.pipe = new uv_pipe_t;
- uv_pipe_init(this->Loop(), this->Output.pipe, 0);
- uv_pipe_open(this->Output.pipe, 1);
- Output.pipe->data = this;
- this->WriteStream = reinterpret_cast<uv_stream_t*>(this->Output.pipe);
+ this->RequestBuffer += line;
+ this->RequestBuffer += "\n";
}
-
- SendGreetings();
- uv_read_start(this->ReadStream, on_alloc_buffer, on_read);
-
- return true;
-}
-
-void cmServerStdIoConnection::TearDown()
-{
- if (usesTty) {
- uv_close(reinterpret_cast<uv_handle_t*>(this->Input.tty), &on_tty_close);
- uv_close(reinterpret_cast<uv_handle_t*>(this->Output.tty), &on_tty_close);
- this->Input.tty = nullptr;
- this->Output.tty = nullptr;
- } else {
- uv_close(reinterpret_cast<uv_handle_t*>(this->Input.pipe), &on_pipe_close);
- uv_close(reinterpret_cast<uv_handle_t*>(this->Output.pipe),
- &on_pipe_close);
- this->Input.pipe = nullptr;
- this->Input.pipe = nullptr;
- }
- this->ReadStream = nullptr;
- this->WriteStream = nullptr;
-}
-
-cmServerPipeConnection::cmServerPipeConnection(const std::string& name)
- : PipeName(name)
-{
-}
-
-bool cmServerPipeConnection::DoSetup(std::string* errorMessage)
-{
- this->ServerPipe = new uv_pipe_t;
- uv_pipe_init(this->Loop(), this->ServerPipe, 0);
- this->ServerPipe->data = this;
-
- int r;
- if ((r = uv_pipe_bind(this->ServerPipe, this->PipeName.c_str())) != 0) {
- *errorMessage = std::string("Internal Error with ") + this->PipeName +
- ": " + uv_err_name(r);
- return false;
- }
- auto serverStream = reinterpret_cast<uv_stream_t*>(this->ServerPipe);
- if ((r = uv_listen(serverStream, 1, on_new_connection)) != 0) {
- *errorMessage = std::string("Internal Error listening on ") +
- this->PipeName + ": " + uv_err_name(r);
- return false;
- }
-
- return true;
-}
-
-void cmServerPipeConnection::TearDown()
-{
- if (this->ClientPipe) {
- uv_close(reinterpret_cast<uv_handle_t*>(this->ClientPipe), &on_pipe_close);
- this->WriteStream->data = nullptr;
- }
- uv_close(reinterpret_cast<uv_handle_t*>(this->ServerPipe), &on_pipe_close);
-
- this->ClientPipe = nullptr;
- this->ServerPipe = nullptr;
- this->WriteStream = nullptr;
- this->ReadStream = nullptr;
-}
-
-void cmServerPipeConnection::Connect(uv_stream_t* server)
-{
- if (this->ClientPipe) {
- // Accept and close all pipes but the first:
- uv_pipe_t* rejectPipe = new uv_pipe_t;
-
- uv_pipe_init(this->Loop(), rejectPipe, 0);
- auto rejecter = reinterpret_cast<uv_stream_t*>(rejectPipe);
- uv_accept(server, rejecter);
- uv_close(reinterpret_cast<uv_handle_t*>(rejecter), &on_pipe_close);
- return;
- }
-
- this->ClientPipe = new uv_pipe_t;
- uv_pipe_init(this->Loop(), this->ClientPipe, 0);
- this->ClientPipe->data = this;
- auto client = reinterpret_cast<uv_stream_t*>(this->ClientPipe);
- if (uv_accept(server, client) != 0) {
- uv_close(reinterpret_cast<uv_handle_t*>(client), nullptr);
- return;
- }
- this->ReadStream = client;
- this->WriteStream = client;
-
- uv_read_start(this->ReadStream, on_alloc_buffer, on_read);
-
- this->SendGreetings();
}
diff --git a/Source/cmServerConnection.h b/Source/cmServerConnection.h
index b96bf3c54..a70edb4b5 100644
--- a/Source/cmServerConnection.h
+++ b/Source/cmServerConnection.h
@@ -2,94 +2,66 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
-#include "cmConfigure.h"
-
-#include "cm_uv.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
-class cmFileMonitor;
-class cmServer;
+#include "cmConnection.h"
+#include "cmPipeConnection.h"
+#include "cmUVHandlePtr.h"
-class cmServerConnection
-{
- CM_DISABLE_COPY(cmServerConnection)
+class cmServerBase;
+/***
+ * This connection buffer strategy accepts messages in the form of
+ * [== "CMake Server" ==[
+{
+ ... some JSON message ...
+}
+]== "CMake Server" ==]
+ * and only passes on the core json; it discards the envelope.
+ */
+class cmServerBufferStrategy : public cmConnectionBufferStrategy
+{
public:
- cmServerConnection();
- virtual ~cmServerConnection();
-
- void SetServer(cmServer* s);
-
- bool ProcessEvents(std::string* errorMessage);
-
- void ReadData(const std::string& data);
- void TriggerShutdown();
- void WriteData(const std::string& data);
- void ProcessNextRequest();
+ std::string BufferMessage(std::string& rawBuffer) override;
+ std::string BufferOutMessage(const std::string& rawBuffer) const override;
- virtual void Connect(uv_stream_t* server) { (void)(server); }
-
- cmFileMonitor* FileMonitor() const { return this->mFileMonitor; }
-
-protected:
- virtual bool DoSetup(std::string* errorMessage) = 0;
- virtual void TearDown() = 0;
+private:
+ std::string RequestBuffer;
+};
- void SendGreetings();
+/***
+ * Generic connection over std io interfaces -- tty
+ */
+class cmStdIoConnection : public cmEventBasedConnection
+{
+public:
+ cmStdIoConnection(cmConnectionBufferStrategy* bufferStrategy);
- uv_loop_t* Loop() const { return mLoop; }
+ void SetServer(cmServerBase* s) override;
-protected:
- std::string RawReadBuffer;
- std::string RequestBuffer;
+ bool OnConnectionShuttingDown() override;
- uv_stream_t* ReadStream = nullptr;
- uv_stream_t* WriteStream = nullptr;
+ bool OnServeStart(std::string* pString) override;
private:
- uv_loop_t* mLoop = nullptr;
- cmFileMonitor* mFileMonitor = nullptr;
- cmServer* Server = nullptr;
- uv_signal_t* SIGINTHandler = nullptr;
- uv_signal_t* SIGHUPHandler = nullptr;
-
- friend class LoopGuard;
+ cm::uv_stream_ptr SetupStream(int file_id);
+ cm::uv_stream_ptr ReadStream;
};
-class cmServerStdIoConnection : public cmServerConnection
+/***
+ * These specific connections use the cmake server
+ * buffering strategy.
+ */
+class cmServerStdIoConnection : public cmStdIoConnection
{
public:
cmServerStdIoConnection();
- bool DoSetup(std::string* errorMessage) override;
-
- void TearDown() override;
-
-private:
- typedef union
- {
- uv_tty_t* tty;
- uv_pipe_t* pipe;
- } InOutUnion;
-
- bool usesTty = false;
-
- InOutUnion Input;
- InOutUnion Output;
};
-class cmServerPipeConnection : public cmServerConnection
+class cmServerPipeConnection : public cmPipeConnection
{
public:
cmServerPipeConnection(const std::string& name);
- bool DoSetup(std::string* errorMessage) override;
-
- void TearDown() override;
-
- void Connect(uv_stream_t* server) override;
-
-private:
- const std::string PipeName;
- uv_pipe_t* ServerPipe = nullptr;
- uv_pipe_t* ClientPipe = nullptr;
};
diff --git a/Source/cmServerDictionary.h b/Source/cmServerDictionary.h
index e6a7ae6ca..961e4b7ea 100644
--- a/Source/cmServerDictionary.h
+++ b/Source/cmServerDictionary.h
@@ -23,66 +23,37 @@ static const std::string kPROGRESS_TYPE = "progress";
static const std::string kREPLY_TYPE = "reply";
static const std::string kSET_GLOBAL_SETTINGS_TYPE = "setGlobalSettings";
static const std::string kSIGNAL_TYPE = "signal";
+static const std::string kCTEST_INFO_TYPE = "ctestInfo";
-static const std::string kARTIFACTS_KEY = "artifacts";
-static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory";
static const std::string kBUILD_FILES_KEY = "buildFiles";
static const std::string kCACHE_ARGUMENTS_KEY = "cacheArguments";
static const std::string kCACHE_KEY = "cache";
static const std::string kCAPABILITIES_KEY = "capabilities";
static const std::string kCHECK_SYSTEM_VARS_KEY = "checkSystemVars";
static const std::string kCMAKE_ROOT_DIRECTORY_KEY = "cmakeRootDirectory";
-static const std::string kCOMPILE_FLAGS_KEY = "compileFlags";
-static const std::string kCONFIGURATIONS_KEY = "configurations";
static const std::string kCOOKIE_KEY = "cookie";
static const std::string kDEBUG_OUTPUT_KEY = "debugOutput";
-static const std::string kDEFINES_KEY = "defines";
static const std::string kERROR_MESSAGE_KEY = "errorMessage";
static const std::string kEXTRA_GENERATOR_KEY = "extraGenerator";
-static const std::string kFILE_GROUPS_KEY = "fileGroups";
-static const std::string kFRAMEWORK_PATH_KEY = "frameworkPath";
-static const std::string kFULL_NAME_KEY = "fullName";
static const std::string kGENERATOR_KEY = "generator";
-static const std::string kINCLUDE_PATH_KEY = "includePath";
-static const std::string kIS_CMAKE_KEY = "isCMake";
static const std::string kIS_EXPERIMENTAL_KEY = "isExperimental";
-static const std::string kIS_GENERATED_KEY = "isGenerated";
-static const std::string kIS_SYSTEM_KEY = "isSystem";
-static const std::string kIS_TEMPORARY_KEY = "isTemporary";
-static const std::string kKEY_KEY = "key";
static const std::string kKEYS_KEY = "keys";
-static const std::string kLANGUAGE_KEY = "language";
-static const std::string kLINKER_LANGUAGE_KEY = "linkerLanguage";
-static const std::string kLINK_FLAGS_KEY = "linkFlags";
-static const std::string kLINK_LANGUAGE_FLAGS_KEY = "linkLanguageFlags";
-static const std::string kLINK_LIBRARIES_KEY = "linkLibraries";
-static const std::string kLINK_PATH_KEY = "linkPath";
static const std::string kMAJOR_KEY = "major";
static const std::string kMESSAGE_KEY = "message";
static const std::string kMINOR_KEY = "minor";
-static const std::string kNAME_KEY = "name";
-static const std::string kPATH_KEY = "path";
static const std::string kPLATFORM_KEY = "platform";
static const std::string kPROGRESS_CURRENT_KEY = "progressCurrent";
static const std::string kPROGRESS_MAXIMUM_KEY = "progressMaximum";
static const std::string kPROGRESS_MESSAGE_KEY = "progressMessage";
static const std::string kPROGRESS_MINIMUM_KEY = "progressMinimum";
-static const std::string kPROJECTS_KEY = "projects";
-static const std::string kPROPERTIES_KEY = "properties";
static const std::string kPROTOCOL_VERSION_KEY = "protocolVersion";
static const std::string kREPLY_TO_KEY = "inReplyTo";
-static const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory";
-static const std::string kSOURCES_KEY = "sources";
static const std::string kSUPPORTED_PROTOCOL_VERSIONS =
"supportedProtocolVersions";
-static const std::string kSYSROOT_KEY = "sysroot";
-static const std::string kTARGETS_KEY = "targets";
static const std::string kTITLE_KEY = "title";
static const std::string kTOOLSET_KEY = "toolset";
static const std::string kTRACE_EXPAND_KEY = "traceExpand";
static const std::string kTRACE_KEY = "trace";
-static const std::string kTYPE_KEY = "type";
-static const std::string kVALUE_KEY = "value";
static const std::string kWARN_UNINITIALIZED_KEY = "warnUninitialized";
static const std::string kWARN_UNUSED_CLI_KEY = "warnUnusedCli";
static const std::string kWARN_UNUSED_KEY = "warnUnused";
diff --git a/Source/cmServerProtocol.cxx b/Source/cmServerProtocol.cxx
index c5b7f6064..558391f30 100644
--- a/Source/cmServerProtocol.cxx
+++ b/Source/cmServerProtocol.cxx
@@ -2,34 +2,26 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmServerProtocol.h"
+#include "cmAlgorithms.h"
#include "cmExternalMakefileProjectGenerator.h"
#include "cmFileMonitor.h"
-#include "cmGeneratorExpression.h"
-#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
-#include "cmLinkLineComputer.h"
-#include "cmLocalGenerator.h"
-#include "cmMakefile.h"
+#include "cmJsonObjectDictionary.h"
+#include "cmJsonObjects.h"
+#include "cmMessageType.h"
#include "cmServer.h"
#include "cmServerDictionary.h"
-#include "cmSourceFile.h"
#include "cmState.h"
-#include "cmStateDirectory.h"
-#include "cmStateSnapshot.h"
-#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cm_uv.h"
#include "cmake.h"
#include <algorithm>
#include <cassert>
-#include <cstddef>
#include <functional>
-#include <limits>
-#include <map>
-#include <set>
+#include <memory>
#include <string>
-#include <unordered_map>
+#include <utility>
#include <vector>
// Get rid of some windows macros:
@@ -37,99 +29,23 @@
namespace {
-std::vector<std::string> getConfigurations(const cmake* cm)
-{
- std::vector<std::string> configurations;
- auto makefiles = cm->GetGlobalGenerator()->GetMakefiles();
- if (makefiles.empty()) {
- return configurations;
- }
-
- makefiles[0]->GetConfigurations(configurations);
- if (configurations.empty()) {
- configurations.push_back("");
- }
- return configurations;
-}
-
-bool hasString(const Json::Value& v, const std::string& s)
-{
- return !v.isNull() &&
- std::any_of(v.begin(), v.end(),
- [s](const Json::Value& i) { return i.asString() == s; });
-}
-
-template <class T>
-Json::Value fromStringList(const T& in)
-{
- Json::Value result = Json::arrayValue;
- for (const std::string& i : in) {
- result.append(i);
- }
- return result;
-}
-
std::vector<std::string> toStringList(const Json::Value& in)
{
std::vector<std::string> result;
- for (const auto& it : in) {
+ for (auto const& it : in) {
result.push_back(it.asString());
}
return result;
}
-void getCMakeInputs(const cmGlobalGenerator* gg, const std::string& sourceDir,
- const std::string& buildDir,
- std::vector<std::string>* internalFiles,
- std::vector<std::string>* explicitFiles,
- std::vector<std::string>* tmpFiles)
-{
- const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot() + '/';
- std::vector<cmMakefile*> const& makefiles = gg->GetMakefiles();
- for (auto it = makefiles.begin(); it != makefiles.end(); ++it) {
- const std::vector<std::string> listFiles = (*it)->GetListFiles();
-
- for (auto jt = listFiles.begin(); jt != listFiles.end(); ++jt) {
-
- const std::string startOfFile = jt->substr(0, cmakeRootDir.size());
- const bool isInternal = (startOfFile == cmakeRootDir);
- const bool isTemporary = !isInternal && (jt->find(buildDir + '/') == 0);
-
- std::string toAdd = *jt;
- if (!sourceDir.empty()) {
- const std::string& relative =
- cmSystemTools::RelativePath(sourceDir.c_str(), jt->c_str());
- if (toAdd.size() > relative.size()) {
- toAdd = relative;
- }
- }
-
- if (isInternal) {
- if (internalFiles) {
- internalFiles->push_back(toAdd);
- }
- } else {
- if (isTemporary) {
- if (tmpFiles) {
- tmpFiles->push_back(toAdd);
- }
- } else {
- if (explicitFiles) {
- explicitFiles->push_back(toAdd);
- }
- }
- }
- }
- }
-}
-
} // namespace
-cmServerRequest::cmServerRequest(cmServer* server, const std::string& t,
- const std::string& c, const Json::Value& d)
- : Type(t)
- , Cookie(c)
- , Data(d)
+cmServerRequest::cmServerRequest(cmServer* server, cmConnection* connection,
+ std::string t, std::string c, Json::Value d)
+ : Type(std::move(t))
+ , Cookie(std::move(c))
+ , Data(std::move(d))
+ , Connection(connection)
, m_Server(server)
{
}
@@ -215,10 +131,11 @@ bool cmServerProtocol::Activate(cmServer* server,
{
assert(server);
this->m_Server = server;
- this->m_CMakeInstance = std::make_unique<cmake>(cmake::RoleProject);
+ this->m_CMakeInstance =
+ cm::make_unique<cmake>(cmake::RoleProject, cmState::Project);
const bool result = this->DoActivate(request, errorMessage);
if (!result) {
- this->m_CMakeInstance = CM_NULLPTR;
+ this->m_CMakeInstance = nullptr;
}
return result;
}
@@ -247,9 +164,9 @@ bool cmServerProtocol::DoActivate(const cmServerRequest& /*request*/,
return true;
}
-std::pair<int, int> cmServerProtocol1_0::ProtocolVersion() const
+std::pair<int, int> cmServerProtocol1::ProtocolVersion() const
{
- return std::make_pair(1, 0);
+ return std::make_pair(1, 2);
}
static void setErrorMessage(std::string* errorMessage, const std::string& text)
@@ -259,11 +176,15 @@ static void setErrorMessage(std::string* errorMessage, const std::string& text)
}
}
-static bool testHomeDirectory(cmState* state, std::string& value,
- std::string* errorMessage)
+static bool getOrTestHomeDirectory(cmState* state, std::string& value,
+ std::string* errorMessage)
{
const std::string cachedValue =
std::string(state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"));
+ if (value.empty()) {
+ value = cachedValue;
+ return true;
+ }
const std::string suffix = "/CMakeLists.txt";
const std::string cachedValueCML = cachedValue + suffix;
const std::string valueCML = value + suffix;
@@ -274,44 +195,53 @@ static bool testHomeDirectory(cmState* state, std::string& value,
"source directory value."));
return false;
}
- if (value.empty()) {
- value = cachedValue;
- }
return true;
}
-static bool testValue(cmState* state, const std::string& key,
- std::string& value, const std::string& keyDescription,
- std::string* errorMessage)
+static bool getOrTestValue(cmState* state, const std::string& key,
+ std::string& value,
+ const std::string& keyDescription,
+ std::string* errorMessage)
{
const char* entry = state->GetCacheEntryValue(key);
const std::string cachedValue =
entry == nullptr ? std::string() : std::string(entry);
- if (!cachedValue.empty() && !value.empty() && cachedValue != value) {
- setErrorMessage(errorMessage, std::string("\"") + key +
+ if (value.empty()) {
+ value = cachedValue;
+ }
+ if (!cachedValue.empty() && cachedValue != value) {
+ setErrorMessage(errorMessage,
+ std::string("\"") + key +
"\" is set but incompatible with configured " +
keyDescription + " value.");
return false;
}
- if (value.empty()) {
- value = cachedValue;
- }
return true;
}
-bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
- std::string* errorMessage)
+bool cmServerProtocol1::DoActivate(const cmServerRequest& request,
+ std::string* errorMessage)
{
std::string sourceDirectory = request.Data[kSOURCE_DIRECTORY_KEY].asString();
- const std::string buildDirectory =
- request.Data[kBUILD_DIRECTORY_KEY].asString();
+ std::string buildDirectory = request.Data[kBUILD_DIRECTORY_KEY].asString();
std::string generator = request.Data[kGENERATOR_KEY].asString();
std::string extraGenerator = request.Data[kEXTRA_GENERATOR_KEY].asString();
std::string toolset = request.Data[kTOOLSET_KEY].asString();
std::string platform = request.Data[kPLATFORM_KEY].asString();
+ // normalize source and build directory
+ if (!sourceDirectory.empty()) {
+ sourceDirectory = cmSystemTools::CollapseFullPath(sourceDirectory);
+ cmSystemTools::ConvertToUnixSlashes(sourceDirectory);
+ }
+ if (!buildDirectory.empty()) {
+ buildDirectory = cmSystemTools::CollapseFullPath(buildDirectory);
+ cmSystemTools::ConvertToUnixSlashes(buildDirectory);
+ }
+
if (buildDirectory.empty()) {
- setErrorMessage(errorMessage, std::string("\"") + kBUILD_DIRECTORY_KEY +
+ setErrorMessage(errorMessage,
+ std::string("\"") + kBUILD_DIRECTORY_KEY +
"\" is missing.");
return false;
}
@@ -319,58 +249,62 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
cmake* cm = CMakeInstance();
if (cmSystemTools::PathExists(buildDirectory)) {
if (!cmSystemTools::FileIsDirectory(buildDirectory)) {
- setErrorMessage(errorMessage, std::string("\"") + kBUILD_DIRECTORY_KEY +
+ setErrorMessage(errorMessage,
+ std::string("\"") + kBUILD_DIRECTORY_KEY +
"\" exists but is not a directory.");
return false;
}
- const std::string cachePath = cm->FindCacheFile(buildDirectory);
+ const std::string cachePath = cmake::FindCacheFile(buildDirectory);
if (cm->LoadCache(cachePath)) {
cmState* state = cm->GetState();
// Check generator:
- if (!testValue(state, "CMAKE_GENERATOR", generator, "generator",
- errorMessage)) {
+ if (!getOrTestValue(state, "CMAKE_GENERATOR", generator, "generator",
+ errorMessage)) {
return false;
}
// check extra generator:
- if (!testValue(state, "CMAKE_EXTRA_GENERATOR", extraGenerator,
- "extra generator", errorMessage)) {
+ if (!getOrTestValue(state, "CMAKE_EXTRA_GENERATOR", extraGenerator,
+ "extra generator", errorMessage)) {
return false;
}
// check sourcedir:
- if (!testHomeDirectory(state, sourceDirectory, errorMessage)) {
+ if (!getOrTestHomeDirectory(state, sourceDirectory, errorMessage)) {
return false;
}
// check toolset:
- if (!testValue(state, "CMAKE_GENERATOR_TOOLSET", toolset, "toolset",
- errorMessage)) {
+ if (!getOrTestValue(state, "CMAKE_GENERATOR_TOOLSET", toolset, "toolset",
+ errorMessage)) {
return false;
}
// check platform:
- if (!testValue(state, "CMAKE_GENERATOR_PLATFORM", platform, "platform",
- errorMessage)) {
+ if (!getOrTestValue(state, "CMAKE_GENERATOR_PLATFORM", platform,
+ "platform", errorMessage)) {
return false;
}
}
}
if (sourceDirectory.empty()) {
- setErrorMessage(errorMessage, std::string("\"") + kSOURCE_DIRECTORY_KEY +
+ setErrorMessage(errorMessage,
+ std::string("\"") + kSOURCE_DIRECTORY_KEY +
"\" is unset but required.");
return false;
}
if (!cmSystemTools::FileIsDirectory(sourceDirectory)) {
- setErrorMessage(errorMessage, std::string("\"") + kSOURCE_DIRECTORY_KEY +
+ setErrorMessage(errorMessage,
+ std::string("\"") + kSOURCE_DIRECTORY_KEY +
"\" is not a directory.");
return false;
}
if (generator.empty()) {
- setErrorMessage(errorMessage, std::string("\"") + kGENERATOR_KEY +
+ setErrorMessage(errorMessage,
+ std::string("\"") + kGENERATOR_KEY +
"\" is unset but required.");
return false;
}
@@ -382,7 +316,8 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
return info.name == generator;
});
if (baseIt == generators.end()) {
- setErrorMessage(errorMessage, std::string("Generator \"") + generator +
+ setErrorMessage(errorMessage,
+ std::string("Generator \"") + generator +
"\" not supported.");
return false;
}
@@ -419,8 +354,8 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
return true;
}
-void cmServerProtocol1_0::HandleCMakeFileChanges(const std::string& path,
- int event, int status)
+void cmServerProtocol1::HandleCMakeFileChanges(const std::string& path,
+ int event, int status)
{
assert(status == 0);
static_cast<void>(status);
@@ -443,7 +378,7 @@ void cmServerProtocol1_0::HandleCMakeFileChanges(const std::string& path,
SendSignal(kFILE_CHANGE_SIGNAL, obj);
}
-const cmServerResponse cmServerProtocol1_0::Process(
+const cmServerResponse cmServerProtocol1::Process(
const cmServerRequest& request)
{
assert(this->m_State >= STATE_ACTIVE);
@@ -472,22 +407,21 @@ const cmServerResponse cmServerProtocol1_0::Process(
if (request.Type == kSET_GLOBAL_SETTINGS_TYPE) {
return this->ProcessSetGlobalSettings(request);
}
+ if (request.Type == kCTEST_INFO_TYPE) {
+ return this->ProcessCTests(request);
+ }
return request.ReportError("Unknown command!");
}
-bool cmServerProtocol1_0::IsExperimental() const
+bool cmServerProtocol1::IsExperimental() const
{
return true;
}
-cmServerResponse cmServerProtocol1_0::ProcessCache(
+cmServerResponse cmServerProtocol1::ProcessCache(
const cmServerRequest& request)
{
- if (this->m_State < STATE_CONFIGURED) {
- return request.ReportError("This project was not configured yet.");
- }
-
cmState* state = this->CMakeInstance()->GetState();
Json::Value result = Json::objectValue;
@@ -499,14 +433,14 @@ cmServerResponse cmServerProtocol1_0::ProcessCache(
if (keys.empty()) {
keys = allKeys;
} else {
- for (const auto& i : keys) {
+ for (auto const& i : keys) {
if (std::find(allKeys.begin(), allKeys.end(), i) == allKeys.end()) {
return request.ReportError("Key \"" + i + "\" not found in cache.");
}
}
}
std::sort(keys.begin(), keys.end());
- for (const auto& key : keys) {
+ for (auto const& key : keys) {
Json::Value entry = Json::objectValue;
entry[kKEY_KEY] = key;
entry[kTYPE_KEY] =
@@ -515,7 +449,7 @@ cmServerResponse cmServerProtocol1_0::ProcessCache(
Json::Value props = Json::objectValue;
bool haveProperties = false;
- for (const auto& prop : state->GetCacheEntryPropertyList(key)) {
+ for (auto const& prop : state->GetCacheEntryPropertyList(key)) {
haveProperties = true;
props[prop] = state->GetCacheEntryProperty(key, prop);
}
@@ -530,7 +464,7 @@ cmServerResponse cmServerProtocol1_0::ProcessCache(
return request.Reply(result);
}
-cmServerResponse cmServerProtocol1_0::ProcessCMakeInputs(
+cmServerResponse cmServerProtocol1::ProcessCMakeInputs(
const cmServerRequest& request)
{
if (this->m_State < STATE_CONFIGURED) {
@@ -538,398 +472,27 @@ cmServerResponse cmServerProtocol1_0::ProcessCMakeInputs(
}
const cmake* cm = this->CMakeInstance();
- const cmGlobalGenerator* gg = cm->GetGlobalGenerator();
const std::string cmakeRootDir = cmSystemTools::GetCMakeRoot();
- const std::string buildDir = cm->GetHomeOutputDirectory();
- const std::string sourceDir = cm->GetHomeDirectory();
+ const std::string& sourceDir = cm->GetHomeDirectory();
Json::Value result = Json::objectValue;
result[kSOURCE_DIRECTORY_KEY] = sourceDir;
result[kCMAKE_ROOT_DIRECTORY_KEY] = cmakeRootDir;
-
- std::vector<std::string> internalFiles;
- std::vector<std::string> explicitFiles;
- std::vector<std::string> tmpFiles;
- getCMakeInputs(gg, sourceDir, buildDir, &internalFiles, &explicitFiles,
- &tmpFiles);
-
- Json::Value array = Json::arrayValue;
-
- Json::Value tmp = Json::objectValue;
- tmp[kIS_CMAKE_KEY] = true;
- tmp[kIS_TEMPORARY_KEY] = false;
- tmp[kSOURCES_KEY] = fromStringList(internalFiles);
- array.append(tmp);
-
- tmp = Json::objectValue;
- tmp[kIS_CMAKE_KEY] = false;
- tmp[kIS_TEMPORARY_KEY] = false;
- tmp[kSOURCES_KEY] = fromStringList(explicitFiles);
- array.append(tmp);
-
- tmp = Json::objectValue;
- tmp[kIS_CMAKE_KEY] = false;
- tmp[kIS_TEMPORARY_KEY] = true;
- tmp[kSOURCES_KEY] = fromStringList(tmpFiles);
- array.append(tmp);
-
- result[kBUILD_FILES_KEY] = array;
-
+ result[kBUILD_FILES_KEY] = cmDumpCMakeInputs(cm);
return request.Reply(result);
}
-class LanguageData
-{
-public:
- bool operator==(const LanguageData& other) const;
-
- void SetDefines(const std::set<std::string>& defines);
-
- bool IsGenerated = false;
- std::string Language;
- std::string Flags;
- std::vector<std::string> Defines;
- std::vector<std::pair<std::string, bool> > IncludePathList;
-};
-
-bool LanguageData::operator==(const LanguageData& other) const
-{
- return Language == other.Language && Defines == other.Defines &&
- Flags == other.Flags && IncludePathList == other.IncludePathList &&
- IsGenerated == other.IsGenerated;
-}
-
-void LanguageData::SetDefines(const std::set<std::string>& defines)
-{
- std::vector<std::string> result;
- for (const auto& i : defines) {
- result.push_back(i);
- }
- std::sort(result.begin(), result.end());
- Defines = result;
-}
-
-namespace std {
-
-template <>
-struct hash<LanguageData>
-{
- std::size_t operator()(const LanguageData& in) const
- {
- using std::hash;
- size_t result =
- hash<std::string>()(in.Language) ^ hash<std::string>()(in.Flags);
- for (const auto& i : in.IncludePathList) {
- result = result ^ (hash<std::string>()(i.first) ^
- (i.second ? std::numeric_limits<size_t>::max() : 0));
- }
- for (const auto& i : in.Defines) {
- result = result ^ hash<std::string>()(i);
- }
- result =
- result ^ (in.IsGenerated ? std::numeric_limits<size_t>::max() : 0);
- return result;
- }
-};
-
-} // namespace std
-
-static Json::Value DumpSourceFileGroup(const LanguageData& data,
- const std::vector<std::string>& files,
- const std::string& baseDir)
-{
- Json::Value result = Json::objectValue;
-
- if (!data.Language.empty()) {
- result[kLANGUAGE_KEY] = data.Language;
- if (!data.Flags.empty()) {
- result[kCOMPILE_FLAGS_KEY] = data.Flags;
- }
- if (!data.IncludePathList.empty()) {
- Json::Value includes = Json::arrayValue;
- for (const auto& i : data.IncludePathList) {
- Json::Value tmp = Json::objectValue;
- tmp[kPATH_KEY] = i.first;
- if (i.second) {
- tmp[kIS_SYSTEM_KEY] = i.second;
- }
- includes.append(tmp);
- }
- result[kINCLUDE_PATH_KEY] = includes;
- }
- if (!data.Defines.empty()) {
- result[kDEFINES_KEY] = fromStringList(data.Defines);
- }
- }
-
- result[kIS_GENERATED_KEY] = data.IsGenerated;
-
- Json::Value sourcesValue = Json::arrayValue;
- for (const auto& i : files) {
- const std::string relPath =
- cmSystemTools::RelativePath(baseDir.c_str(), i.c_str());
- sourcesValue.append(relPath.size() < i.size() ? relPath : i);
- }
-
- result[kSOURCES_KEY] = sourcesValue;
- return result;
-}
-
-static Json::Value DumpSourceFilesList(
- cmGeneratorTarget* target, const std::string& config,
- const std::map<std::string, LanguageData>& languageDataMap)
-{
- // Collect sourcefile groups:
-
- std::vector<cmSourceFile*> files;
- target->GetSourceFiles(files, config);
-
- std::unordered_map<LanguageData, std::vector<std::string> > fileGroups;
- for (cmSourceFile* file : files) {
- LanguageData fileData;
- fileData.Language = file->GetLanguage();
- if (!fileData.Language.empty()) {
- const LanguageData& ld = languageDataMap.at(fileData.Language);
- cmLocalGenerator* lg = target->GetLocalGenerator();
-
- std::string compileFlags = ld.Flags;
- if (const char* cflags = file->GetProperty("COMPILE_FLAGS")) {
- cmGeneratorExpression ge;
- auto cge = ge.Parse(cflags);
- const char* processed =
- cge->Evaluate(target->GetLocalGenerator(), config);
- lg->AppendFlags(compileFlags, processed);
- }
- fileData.Flags = compileFlags;
-
- fileData.IncludePathList = ld.IncludePathList;
-
- std::set<std::string> defines;
- lg->AppendDefines(defines, file->GetProperty("COMPILE_DEFINITIONS"));
- const std::string defPropName =
- "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
- lg->AppendDefines(defines, file->GetProperty(defPropName));
- defines.insert(ld.Defines.begin(), ld.Defines.end());
-
- fileData.SetDefines(defines);
- }
-
- fileData.IsGenerated = file->GetPropertyAsBool("GENERATED");
- std::vector<std::string>& groupFileList = fileGroups[fileData];
- groupFileList.push_back(file->GetFullPath());
- }
-
- const std::string baseDir = target->Makefile->GetCurrentSourceDirectory();
- Json::Value result = Json::arrayValue;
- for (auto it = fileGroups.begin(); it != fileGroups.end(); ++it) {
- Json::Value group = DumpSourceFileGroup(it->first, it->second, baseDir);
- if (!group.isNull()) {
- result.append(group);
- }
- }
-
- return result;
-}
-
-static Json::Value DumpTarget(cmGeneratorTarget* target,
- const std::string& config)
-{
- cmLocalGenerator* lg = target->GetLocalGenerator();
- const cmState* state = lg->GetState();
-
- const cmStateEnums::TargetType type = target->GetType();
- const std::string typeName = state->GetTargetTypeName(type);
-
- Json::Value ttl = Json::arrayValue;
- ttl.append("EXECUTABLE");
- ttl.append("STATIC_LIBRARY");
- ttl.append("SHARED_LIBRARY");
- ttl.append("MODULE_LIBRARY");
- ttl.append("OBJECT_LIBRARY");
- ttl.append("UTILITY");
- ttl.append("INTERFACE_LIBRARY");
-
- if (!hasString(ttl, typeName) || target->IsImported()) {
- return Json::Value();
- }
-
- Json::Value result = Json::objectValue;
- result[kNAME_KEY] = target->GetName();
- result[kTYPE_KEY] = typeName;
- result[kSOURCE_DIRECTORY_KEY] = lg->GetCurrentSourceDirectory();
- result[kBUILD_DIRECTORY_KEY] = lg->GetCurrentBinaryDirectory();
-
- if (type == cmStateEnums::INTERFACE_LIBRARY) {
- return result;
- }
-
- result[kFULL_NAME_KEY] = target->GetFullName(config);
-
- if (target->HaveWellDefinedOutputFiles()) {
- Json::Value artifacts = Json::arrayValue;
- artifacts.append(
- target->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact));
- if (target->IsDLLPlatform()) {
- artifacts.append(
- target->GetFullPath(config, cmStateEnums::ImportLibraryArtifact));
- const cmGeneratorTarget::OutputInfo* output =
- target->GetOutputInfo(config);
- if (output && !output->PdbDir.empty()) {
- artifacts.append(output->PdbDir + '/' + target->GetPDBName(config));
- }
- }
- result[kARTIFACTS_KEY] = artifacts;
-
- result[kLINKER_LANGUAGE_KEY] = target->GetLinkerLanguage(config);
-
- std::string linkLibs;
- std::string linkFlags;
- std::string linkLanguageFlags;
- std::string frameworkPath;
- std::string linkPath;
- cmLinkLineComputer linkLineComputer(lg,
- lg->GetStateSnapshot().GetDirectory());
- lg->GetTargetFlags(&linkLineComputer, config, linkLibs, linkLanguageFlags,
- linkFlags, frameworkPath, linkPath, target);
-
- linkLibs = cmSystemTools::TrimWhitespace(linkLibs);
- linkFlags = cmSystemTools::TrimWhitespace(linkFlags);
- linkLanguageFlags = cmSystemTools::TrimWhitespace(linkLanguageFlags);
- frameworkPath = cmSystemTools::TrimWhitespace(frameworkPath);
- linkPath = cmSystemTools::TrimWhitespace(linkPath);
-
- if (!cmSystemTools::TrimWhitespace(linkLibs).empty()) {
- result[kLINK_LIBRARIES_KEY] = linkLibs;
- }
- if (!cmSystemTools::TrimWhitespace(linkFlags).empty()) {
- result[kLINK_FLAGS_KEY] = linkFlags;
- }
- if (!cmSystemTools::TrimWhitespace(linkLanguageFlags).empty()) {
- result[kLINK_LANGUAGE_FLAGS_KEY] = linkLanguageFlags;
- }
- if (!frameworkPath.empty()) {
- result[kFRAMEWORK_PATH_KEY] = frameworkPath;
- }
- if (!linkPath.empty()) {
- result[kLINK_PATH_KEY] = linkPath;
- }
- const std::string sysroot =
- lg->GetMakefile()->GetSafeDefinition("CMAKE_SYSROOT");
- if (!sysroot.empty()) {
- result[kSYSROOT_KEY] = sysroot;
- }
- }
-
- std::set<std::string> languages;
- target->GetLanguages(languages, config);
- std::map<std::string, LanguageData> languageDataMap;
- for (const auto& lang : languages) {
- LanguageData& ld = languageDataMap[lang];
- ld.Language = lang;
- lg->GetTargetCompileFlags(target, config, lang, ld.Flags);
- std::set<std::string> defines;
- lg->GetTargetDefines(target, config, lang, defines);
- ld.SetDefines(defines);
- std::vector<std::string> includePathList;
- lg->GetIncludeDirectories(includePathList, target, lang, config, true);
- for (auto i : includePathList) {
- ld.IncludePathList.push_back(
- std::make_pair(i, target->IsSystemIncludeDirectory(i, config)));
- }
- }
-
- Json::Value sourceGroupsValue =
- DumpSourceFilesList(target, config, languageDataMap);
- if (!sourceGroupsValue.empty()) {
- result[kFILE_GROUPS_KEY] = sourceGroupsValue;
- }
-
- return result;
-}
-
-static Json::Value DumpTargetsList(
- const std::vector<cmLocalGenerator*>& generators, const std::string& config)
-{
- Json::Value result = Json::arrayValue;
-
- std::vector<cmGeneratorTarget*> targetList;
- for (const auto& lgIt : generators) {
- auto list = lgIt->GetGeneratorTargets();
- targetList.insert(targetList.end(), list.begin(), list.end());
- }
- std::sort(targetList.begin(), targetList.end());
-
- for (cmGeneratorTarget* target : targetList) {
- Json::Value tmp = DumpTarget(target, config);
- if (!tmp.isNull()) {
- result.append(tmp);
- }
- }
-
- return result;
-}
-
-static Json::Value DumpProjectList(const cmake* cm, std::string const& config)
-{
- Json::Value result = Json::arrayValue;
-
- auto globalGen = cm->GetGlobalGenerator();
-
- for (const auto& projectIt : globalGen->GetProjectMap()) {
- Json::Value pObj = Json::objectValue;
- pObj[kNAME_KEY] = projectIt.first;
-
- // All Projects must have at least one local generator
- assert(!projectIt.second.empty());
- const cmLocalGenerator* lg = projectIt.second.at(0);
-
- // Project structure information:
- const cmMakefile* mf = lg->GetMakefile();
- pObj[kSOURCE_DIRECTORY_KEY] = mf->GetCurrentSourceDirectory();
- pObj[kBUILD_DIRECTORY_KEY] = mf->GetCurrentBinaryDirectory();
- pObj[kTARGETS_KEY] = DumpTargetsList(projectIt.second, config);
-
- result.append(pObj);
- }
-
- return result;
-}
-
-static Json::Value DumpConfiguration(const cmake* cm,
- const std::string& config)
-{
- Json::Value result = Json::objectValue;
- result[kNAME_KEY] = config;
-
- result[kPROJECTS_KEY] = DumpProjectList(cm, config);
-
- return result;
-}
-
-static Json::Value DumpConfigurationsList(const cmake* cm)
-{
- Json::Value result = Json::arrayValue;
-
- for (const std::string& c : getConfigurations(cm)) {
- result.append(DumpConfiguration(cm, c));
- }
-
- return result;
-}
-
-cmServerResponse cmServerProtocol1_0::ProcessCodeModel(
+cmServerResponse cmServerProtocol1::ProcessCodeModel(
const cmServerRequest& request)
{
if (this->m_State != STATE_COMPUTED) {
return request.ReportError("No build system was generated yet.");
}
- Json::Value result = Json::objectValue;
- result[kCONFIGURATIONS_KEY] = DumpConfigurationsList(this->CMakeInstance());
- return request.Reply(result);
+ return request.Reply(cmDumpCodeModel(this->CMakeInstance()));
}
-cmServerResponse cmServerProtocol1_0::ProcessCompute(
+cmServerResponse cmServerProtocol1::ProcessCompute(
const cmServerRequest& request)
{
if (this->m_State > STATE_CONFIGURED) {
@@ -949,7 +512,7 @@ cmServerResponse cmServerProtocol1_0::ProcessCompute(
return request.Reply(Json::Value());
}
-cmServerResponse cmServerProtocol1_0::ProcessConfigure(
+cmServerResponse cmServerProtocol1::ProcessConfigure(
const cmServerRequest& request)
{
if (this->m_State == STATE_INACTIVE) {
@@ -973,12 +536,12 @@ cmServerResponse cmServerProtocol1_0::ProcessConfigure(
if (passedArgs.isString()) {
cacheArgs.push_back(passedArgs.asString());
} else if (passedArgs.isArray()) {
- for (auto i = passedArgs.begin(); i != passedArgs.end(); ++i) {
- if (!i->isString()) {
+ for (auto const& arg : passedArgs) {
+ if (!arg.isString()) {
cacheArgumentsError = true;
break;
}
- cacheArgs.push_back(i->asString());
+ cacheArgs.push_back(arg.asString());
}
} else {
cacheArgumentsError = true;
@@ -1000,20 +563,20 @@ cmServerResponse cmServerProtocol1_0::ProcessConfigure(
if (cm->LoadCache(buildDir)) {
// build directory has been set up before
- const char* cachedSourceDir =
+ const std::string* cachedSourceDir =
cm->GetState()->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
if (!cachedSourceDir) {
return request.ReportError("No CMAKE_HOME_DIRECTORY found in cache.");
}
if (sourceDir.empty()) {
- sourceDir = std::string(cachedSourceDir);
+ sourceDir = *cachedSourceDir;
cm->SetHomeDirectory(sourceDir);
}
- const char* cachedGenerator =
+ const std::string* cachedGenerator =
cm->GetState()->GetInitializedCacheValue("CMAKE_GENERATOR");
if (cachedGenerator) {
- if (gg && gg->GetName() != cachedGenerator) {
+ if (gg && gg->GetName() != *cachedGenerator) {
return request.ReportError("Configured generator does not match with "
"CMAKE_GENERATOR found in cache.");
}
@@ -1038,12 +601,17 @@ cmServerResponse cmServerProtocol1_0::ProcessConfigure(
}
int ret = cm->Configure();
+ cm->IssueMessage(
+ MessageType::DEPRECATION_WARNING,
+ "The 'cmake-server(7)' is deprecated. "
+ "Please port clients to use the 'cmake-file-api(7)' instead.");
if (ret < 0) {
return request.ReportError("Configuration failed.");
}
std::vector<std::string> toWatchList;
- getCMakeInputs(gg, std::string(), buildDir, nullptr, &toWatchList, nullptr);
+ cmGetCMakeInputs(gg, std::string(), buildDir, nullptr, &toWatchList,
+ nullptr);
FileMonitor()->MonitorPaths(toWatchList,
[this](const std::string& p, int e, int s) {
@@ -1055,14 +623,14 @@ cmServerResponse cmServerProtocol1_0::ProcessConfigure(
return request.Reply(Json::Value());
}
-cmServerResponse cmServerProtocol1_0::ProcessGlobalSettings(
+cmServerResponse cmServerProtocol1::ProcessGlobalSettings(
const cmServerRequest& request)
{
cmake* cm = this->CMakeInstance();
Json::Value obj = Json::objectValue;
// Capabilities information:
- obj[kCAPABILITIES_KEY] = cm->ReportCapabilitiesJson(true);
+ obj[kCAPABILITIES_KEY] = cm->ReportCapabilitiesJson();
obj[kDEBUG_OUTPUT_KEY] = cm->GetDebugOutput();
obj[kTRACE_KEY] = cm->GetTrace();
@@ -1091,7 +659,7 @@ static void setBool(const cmServerRequest& request, const std::string& key,
setter(request.Data[key].asBool());
}
-cmServerResponse cmServerProtocol1_0::ProcessSetGlobalSettings(
+cmServerResponse cmServerProtocol1::ProcessSetGlobalSettings(
const cmServerRequest& request)
{
const std::vector<std::string> boolValues = {
@@ -1099,7 +667,7 @@ cmServerResponse cmServerProtocol1_0::ProcessSetGlobalSettings(
kWARN_UNINITIALIZED_KEY, kWARN_UNUSED_KEY, kWARN_UNUSED_CLI_KEY,
kCHECK_SYSTEM_VARS_KEY
};
- for (const auto& i : boolValues) {
+ for (std::string const& i : boolValues) {
if (!request.Data[i].isNull() && !request.Data[i].isBool()) {
return request.ReportError("\"" + i +
"\" must be unset or a bool value.");
@@ -1123,17 +691,17 @@ cmServerResponse cmServerProtocol1_0::ProcessSetGlobalSettings(
return request.Reply(Json::Value());
}
-cmServerResponse cmServerProtocol1_0::ProcessFileSystemWatchers(
+cmServerResponse cmServerProtocol1::ProcessFileSystemWatchers(
const cmServerRequest& request)
{
const cmFileMonitor* const fm = FileMonitor();
Json::Value result = Json::objectValue;
Json::Value files = Json::arrayValue;
- for (const auto& f : fm->WatchedFiles()) {
+ for (auto const& f : fm->WatchedFiles()) {
files.append(f);
}
Json::Value directories = Json::arrayValue;
- for (const auto& d : fm->WatchedDirectories()) {
+ for (auto const& d : fm->WatchedDirectories()) {
directories.append(d);
}
result[kWATCHED_FILES_KEY] = files;
@@ -1142,20 +710,30 @@ cmServerResponse cmServerProtocol1_0::ProcessFileSystemWatchers(
return request.Reply(result);
}
-cmServerProtocol1_0::GeneratorInformation::GeneratorInformation(
- const std::string& generatorName, const std::string& extraGeneratorName,
- const std::string& toolset, const std::string& platform,
- const std::string& sourceDirectory, const std::string& buildDirectory)
- : GeneratorName(generatorName)
- , ExtraGeneratorName(extraGeneratorName)
- , Toolset(toolset)
- , Platform(platform)
- , SourceDirectory(sourceDirectory)
- , BuildDirectory(buildDirectory)
+cmServerResponse cmServerProtocol1::ProcessCTests(
+ const cmServerRequest& request)
+{
+ if (this->m_State < STATE_COMPUTED) {
+ return request.ReportError("This instance was not yet computed.");
+ }
+
+ return request.Reply(cmDumpCTestInfo(this->CMakeInstance()));
+}
+
+cmServerProtocol1::GeneratorInformation::GeneratorInformation(
+ std::string generatorName, std::string extraGeneratorName,
+ std::string toolset, std::string platform, std::string sourceDirectory,
+ std::string buildDirectory)
+ : GeneratorName(std::move(generatorName))
+ , ExtraGeneratorName(std::move(extraGeneratorName))
+ , Toolset(std::move(toolset))
+ , Platform(std::move(platform))
+ , SourceDirectory(std::move(sourceDirectory))
+ , BuildDirectory(std::move(buildDirectory))
{
}
-void cmServerProtocol1_0::GeneratorInformation::SetupGenerator(
+void cmServerProtocol1::GeneratorInformation::SetupGenerator(
cmake* cm, std::string* errorMessage)
{
const std::string fullGeneratorName =
diff --git a/Source/cmServerProtocol.h b/Source/cmServerProtocol.h
index 83b3d58de..2f55a208f 100644
--- a/Source/cmServerProtocol.h
+++ b/Source/cmServerProtocol.h
@@ -2,7 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cm_jsoncpp_value.h"
#include "cmake.h"
@@ -11,6 +11,7 @@
#include <string>
#include <utility>
+class cmConnection;
class cmFileMonitor;
class cmServer;
class cmServerRequest;
@@ -52,10 +53,11 @@ public:
const std::string Type;
const std::string Cookie;
const Json::Value Data;
+ cmConnection* Connection;
private:
- cmServerRequest(cmServer* server, const std::string& t, const std::string& c,
- const Json::Value& d);
+ cmServerRequest(cmServer* server, cmConnection* connection, std::string t,
+ std::string c, Json::Value d);
void ReportProgress(int min, int current, int max,
const std::string& message) const;
@@ -69,12 +71,13 @@ private:
class cmServerProtocol
{
- CM_DISABLE_COPY(cmServerProtocol)
-
public:
cmServerProtocol() = default;
virtual ~cmServerProtocol() = default;
+ cmServerProtocol(cmServerProtocol const&) = delete;
+ cmServerProtocol& operator=(cmServerProtocol const&) = delete;
+
virtual std::pair<int, int> ProtocolVersion() const = 0;
virtual bool IsExperimental() const = 0;
virtual const cmServerResponse Process(const cmServerRequest& request) = 0;
@@ -98,7 +101,7 @@ private:
friend class cmServer;
};
-class cmServerProtocol1_0 : public cmServerProtocol
+class cmServerProtocol1 : public cmServerProtocol
{
public:
std::pair<int, int> ProtocolVersion() const override;
@@ -120,6 +123,7 @@ private:
cmServerResponse ProcessGlobalSettings(const cmServerRequest& request);
cmServerResponse ProcessSetGlobalSettings(const cmServerRequest& request);
cmServerResponse ProcessFileSystemWatchers(const cmServerRequest& request);
+ cmServerResponse ProcessCTests(const cmServerRequest& request);
enum State
{
@@ -136,12 +140,10 @@ private:
{
public:
GeneratorInformation() = default;
- GeneratorInformation(const std::string& generatorName,
- const std::string& extraGeneratorName,
- const std::string& toolset,
- const std::string& platform,
- const std::string& sourceDirectory,
- const std::string& buildDirectory);
+ GeneratorInformation(std::string generatorName,
+ std::string extraGeneratorName, std::string toolset,
+ std::string platform, std::string sourceDirectory,
+ std::string buildDirectory);
void SetupGenerator(cmake* cm, std::string* errorMessage);
diff --git a/Source/cmSetCommand.cxx b/Source/cmSetCommand.cxx
index 820e7f695..41555e8e3 100644
--- a/Source/cmSetCommand.cxx
+++ b/Source/cmSetCommand.cxx
@@ -2,10 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSetCommand.h"
-#include <string.h>
-
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmRange.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
@@ -22,19 +22,15 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
}
// watch for ENV signatures
- const char* variable = args[0].c_str(); // VAR is always first
- if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5) {
+ auto const& variable = args[0]; // VAR is always first
+ if (cmHasLiteralPrefix(variable, "ENV{") && variable.size() > 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 += "=";
+ auto const& varName = variable.substr(4, variable.size() - 5);
+ std::string putEnvArg = varName + "=";
// what is the current value if any
std::string currValue;
const bool currValueSet = cmSystemTools::GetEnv(varName, currValue);
- delete[] varName;
// will it be set to something, then set it
if (args.size() > 1 && !args[1].empty()) {
@@ -43,6 +39,14 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
putEnvArg += args[1];
cmSystemTools::PutEnv(putEnvArg);
}
+ // if there's extra arguments, warn user
+ // that they are ignored by this command.
+ if (args.size() > 2) {
+ std::string m = "Only the first value argument is used when setting "
+ "an environment variable. Argument '" +
+ args[2] + "' and later are unused.";
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
+ }
return true;
}
@@ -60,8 +64,8 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
}
// SET (VAR PARENT_SCOPE) // Removes the definition of VAR
// in the parent scope.
- if (args.size() == 2 && args[args.size() - 1] == "PARENT_SCOPE") {
- this->Makefile->RaiseScope(variable, CM_NULLPTR);
+ if (args.size() == 2 && args.back() == "PARENT_SCOPE") {
+ this->Makefile->RaiseScope(variable, nullptr);
return true;
}
@@ -75,17 +79,17 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
bool force = false; // optional
bool parentScope = false;
cmStateEnums::CacheEntryType type =
- cmStateEnums::STRING; // required if cache
- const char* docstring = CM_NULLPTR; // required if cache
+ cmStateEnums::STRING; // required if cache
+ const char* docstring = nullptr; // required if cache
unsigned int ignoreLastArgs = 0;
// look for PARENT_SCOPE argument
- if (args.size() > 1 && args[args.size() - 1] == "PARENT_SCOPE") {
+ if (args.size() > 1 && args.back() == "PARENT_SCOPE") {
parentScope = true;
ignoreLastArgs++;
} else {
// look for FORCE argument
- if (args.size() > 4 && args[args.size() - 1] == "FORCE") {
+ if (args.size() > 4 && args.back() == "FORCE") {
force = true;
ignoreLastArgs++;
}
@@ -109,7 +113,7 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
// 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") ||
+ if ((args.back() == "CACHE") ||
(args.size() > 1 && args[args.size() - 2] == "CACHE") ||
(force && !cache)) {
this->SetError("given invalid arguments for CACHE mode.");
@@ -118,7 +122,15 @@ bool cmSetCommand::InitialPass(std::vector<std::string> const& args,
if (cache) {
std::string::size_type cacheStart = args.size() - 3 - (force ? 1 : 0);
- type = cmState::StringToCacheEntryType(args[cacheStart + 1].c_str());
+ if (!cmState::StringToCacheEntryType(args[cacheStart + 1].c_str(), type)) {
+ std::string m = "implicitly converting '" + args[cacheStart + 1] +
+ "' to 'STRING' type.";
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, m);
+ // Setting this may not be required, since it's
+ // initialized as a string. Keeping this here to
+ // ensure that the type is actually converting to a string.
+ type = cmStateEnums::STRING;
+ }
docstring = args[cacheStart + 2].c_str();
}
diff --git a/Source/cmSetCommand.h b/Source/cmSetCommand.h
index c0858b15b..76e3eae9b 100644
--- a/Source/cmSetCommand.h
+++ b/Source/cmSetCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSetCommand_h
#define cmSetCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmSetCommand; }
+ cmCommand* Clone() override { return new cmSetCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmSetDirectoryPropertiesCommand.h b/Source/cmSetDirectoryPropertiesCommand.h
index 8832b3389..473347c1a 100644
--- a/Source/cmSetDirectoryPropertiesCommand.h
+++ b/Source/cmSetDirectoryPropertiesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSetDirectoryPropertiesCommand_h
#define cmSetDirectoryPropertiesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,17 +16,14 @@ class cmMakefile;
class cmSetDirectoryPropertiesCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE
- {
- return new cmSetDirectoryPropertiesCommand;
- }
+ cmCommand* Clone() override { return new cmSetDirectoryPropertiesCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* Static entry point for use by other commands
diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx
index b57f62a50..e9343c7db 100644
--- a/Source/cmSetPropertyCommand.cxx
+++ b/Source/cmSetPropertyCommand.cxx
@@ -8,6 +8,7 @@
#include "cmInstalledFile.h"
#include "cmMakefile.h"
#include "cmProperty.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmState.h"
#include "cmSystemTools.h"
@@ -33,25 +34,25 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args,
}
// Get the scope on which to set the property.
- std::vector<std::string>::const_iterator arg = args.begin();
+ std::string const& scopeName = args.front();
cmProperty::ScopeType scope;
- if (*arg == "GLOBAL") {
+ if (scopeName == "GLOBAL") {
scope = cmProperty::GLOBAL;
- } else if (*arg == "DIRECTORY") {
+ } else if (scopeName == "DIRECTORY") {
scope = cmProperty::DIRECTORY;
- } else if (*arg == "TARGET") {
+ } else if (scopeName == "TARGET") {
scope = cmProperty::TARGET;
- } else if (*arg == "SOURCE") {
+ } else if (scopeName == "SOURCE") {
scope = cmProperty::SOURCE_FILE;
- } else if (*arg == "TEST") {
+ } else if (scopeName == "TEST") {
scope = cmProperty::TEST;
- } else if (*arg == "CACHE") {
+ } else if (scopeName == "CACHE") {
scope = cmProperty::CACHE;
- } else if (*arg == "INSTALL") {
+ } else if (scopeName == "INSTALL") {
scope = cmProperty::INSTALL;
} else {
std::ostringstream e;
- e << "given invalid scope " << *arg << ". "
+ e << "given invalid scope " << scopeName << ". "
<< "Valid scopes are GLOBAL, DIRECTORY, "
"TARGET, SOURCE, TEST, CACHE, INSTALL.";
this->SetError(e.str());
@@ -68,32 +69,32 @@ bool cmSetPropertyCommand::InitialPass(std::vector<std::string> const& args,
};
Doing doing = DoingNames;
const char* sep = "";
- for (++arg; arg != args.end(); ++arg) {
- if (*arg == "PROPERTY") {
+ for (std::string const& arg : cmMakeRange(args).advance(1)) {
+ if (arg == "PROPERTY") {
doing = DoingProperty;
- } else if (*arg == "APPEND") {
+ } else if (arg == "APPEND") {
doing = DoingNone;
this->AppendMode = true;
this->Remove = false;
this->AppendAsString = false;
- } else if (*arg == "APPEND_STRING") {
+ } else if (arg == "APPEND_STRING") {
doing = DoingNone;
this->AppendMode = true;
this->Remove = false;
this->AppendAsString = true;
} else if (doing == DoingNames) {
- this->Names.insert(*arg);
+ this->Names.insert(arg);
} else if (doing == DoingProperty) {
- this->PropertyName = *arg;
+ this->PropertyName = arg;
doing = DoingValues;
} else if (doing == DoingValues) {
this->PropertyValue += sep;
sep = ";";
- this->PropertyValue += *arg;
+ this->PropertyValue += arg;
this->Remove = false;
} else {
std::ostringstream e;
- e << "given invalid argument \"" << *arg << "\".";
+ e << "given invalid argument \"" << arg << "\".";
this->SetError(e.str());
return false;
}
@@ -141,7 +142,7 @@ bool cmSetPropertyCommand::HandleGlobalMode()
std::string const& name = this->PropertyName;
const char* value = this->PropertyValue.c_str();
if (this->Remove) {
- value = CM_NULLPTR;
+ value = nullptr;
}
if (this->AppendMode) {
cm->AppendProperty(name, value ? value : "", this->AppendAsString);
@@ -167,7 +168,7 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
// 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())) {
+ if (!cmSystemTools::FileIsFullPath(dir)) {
dir = this->Makefile->GetCurrentSourceDirectory();
dir += "/";
dir += *this->Names.begin();
@@ -191,7 +192,7 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
std::string const& name = this->PropertyName;
const char* value = this->PropertyValue.c_str();
if (this->Remove) {
- value = CM_NULLPTR;
+ value = nullptr;
}
if (this->AppendMode) {
mf->AppendProperty(name, value ? value : "", this->AppendAsString);
@@ -204,20 +205,19 @@ bool cmSetPropertyCommand::HandleDirectoryMode()
bool cmSetPropertyCommand::HandleTargetMode()
{
- for (std::set<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni) {
- if (this->Makefile->IsAlias(*ni)) {
+ for (std::string const& name : this->Names) {
+ if (this->Makefile->IsAlias(name)) {
this->SetError("can not be used on an ALIAS target.");
return false;
}
- if (cmTarget* target = this->Makefile->FindTargetToUse(*ni)) {
+ if (cmTarget* target = this->Makefile->FindTargetToUse(name)) {
// Handle the current target.
if (!this->HandleTarget(target)) {
return false;
}
} else {
std::ostringstream e;
- e << "could not find TARGET " << *ni
+ e << "could not find TARGET " << name
<< ". Perhaps it has not yet been created.";
this->SetError(e.str());
return false;
@@ -232,7 +232,7 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target)
std::string const& name = this->PropertyName;
const char* value = this->PropertyValue.c_str();
if (this->Remove) {
- value = CM_NULLPTR;
+ value = nullptr;
}
if (this->AppendMode) {
target->AppendProperty(name, value, this->AppendAsString);
@@ -248,16 +248,15 @@ bool cmSetPropertyCommand::HandleTarget(cmTarget* target)
bool cmSetPropertyCommand::HandleSourceMode()
{
- for (std::set<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni) {
+ for (std::string const& name : this->Names) {
// Get the source file.
- if (cmSourceFile* sf = this->Makefile->GetOrCreateSource(*ni)) {
+ if (cmSourceFile* sf = this->Makefile->GetOrCreateSource(name)) {
if (!this->HandleSource(sf)) {
return false;
}
} else {
std::ostringstream e;
- e << "given SOURCE name that could not be found or created: " << *ni;
+ e << "given SOURCE name that could not be found or created: " << name;
this->SetError(e.str());
return false;
}
@@ -271,7 +270,7 @@ bool cmSetPropertyCommand::HandleSource(cmSourceFile* sf)
std::string const& name = this->PropertyName;
const char* value = this->PropertyValue.c_str();
if (this->Remove) {
- value = CM_NULLPTR;
+ value = nullptr;
}
if (this->AppendMode) {
@@ -303,9 +302,8 @@ bool cmSetPropertyCommand::HandleTestMode()
if (!this->Names.empty()) {
std::ostringstream 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";
+ for (std::string const& name : this->Names) {
+ e << " " << name << "\n";
}
this->SetError(e.str());
return false;
@@ -319,7 +317,7 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test)
std::string const& name = this->PropertyName;
const char* value = this->PropertyValue.c_str();
if (this->Remove) {
- value = CM_NULLPTR;
+ value = nullptr;
}
if (this->AppendMode) {
test->AppendProperty(name, value, this->AppendAsString);
@@ -333,11 +331,11 @@ bool cmSetPropertyCommand::HandleTest(cmTest* test)
bool cmSetPropertyCommand::HandleCacheMode()
{
if (this->PropertyName == "ADVANCED") {
- if (!this->Remove && !cmSystemTools::IsOn(this->PropertyValue.c_str()) &&
- !cmSystemTools::IsOff(this->PropertyValue.c_str())) {
+ if (!this->Remove && !cmSystemTools::IsOn(this->PropertyValue) &&
+ !cmSystemTools::IsOff(this->PropertyValue)) {
std::ostringstream e;
e << "given non-boolean value \"" << this->PropertyValue
- << "\" for CACHE property \"ADVANCED\". ";
+ << R"(" for CACHE property "ADVANCED". )";
this->SetError(e.str());
return false;
}
@@ -359,19 +357,18 @@ bool cmSetPropertyCommand::HandleCacheMode()
return false;
}
- for (std::set<std::string>::const_iterator ni = this->Names.begin();
- ni != this->Names.end(); ++ni) {
+ for (std::string const& name : this->Names) {
// Get the source file.
cmMakefile* mf = this->GetMakefile();
cmake* cm = mf->GetCMakeInstance();
- const char* existingValue = cm->GetState()->GetCacheEntryValue(*ni);
+ const char* existingValue = cm->GetState()->GetCacheEntryValue(name);
if (existingValue) {
- if (!this->HandleCacheEntry(*ni)) {
+ if (!this->HandleCacheEntry(name)) {
return false;
}
} else {
std::ostringstream e;
- e << "could not find CACHE variable " << *ni
+ e << "could not find CACHE variable " << name
<< ". Perhaps it has not yet been created.";
this->SetError(e.str());
return false;
@@ -403,16 +400,15 @@ bool cmSetPropertyCommand::HandleInstallMode()
{
cmake* cm = this->Makefile->GetCMakeInstance();
- for (std::set<std::string>::const_iterator i = this->Names.begin();
- i != this->Names.end(); ++i) {
+ for (std::string const& name : this->Names) {
if (cmInstalledFile* file =
- cm->GetOrCreateInstalledFile(this->Makefile, *i)) {
+ cm->GetOrCreateInstalledFile(this->Makefile, name)) {
if (!this->HandleInstall(file)) {
return false;
}
} else {
std::ostringstream e;
- e << "given INSTALL name that could not be found or created: " << *i;
+ e << "given INSTALL name that could not be found or created: " << name;
this->SetError(e.str());
return false;
}
diff --git a/Source/cmSetPropertyCommand.h b/Source/cmSetPropertyCommand.h
index 08158244a..f1126bb7e 100644
--- a/Source/cmSetPropertyCommand.h
+++ b/Source/cmSetPropertyCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSetsPropertiesCommand_h
#define cmSetsPropertiesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <string>
@@ -22,14 +22,14 @@ class cmSetPropertyCommand : public cmCommand
public:
cmSetPropertyCommand();
- cmCommand* Clone() CM_OVERRIDE { return new cmSetPropertyCommand; }
+ cmCommand* Clone() override { return new cmSetPropertyCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
std::set<std::string> Names;
diff --git a/Source/cmSetSourceFilesPropertiesCommand.cxx b/Source/cmSetSourceFilesPropertiesCommand.cxx
index 33e1b2e06..9388e7ccf 100644
--- a/Source/cmSetSourceFilesPropertiesCommand.cxx
+++ b/Source/cmSetSourceFilesPropertiesCommand.cxx
@@ -53,17 +53,17 @@ bool cmSetSourceFilesPropertiesCommand::RunCommand(
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");
+ propertyPairs.emplace_back("ABSTRACT");
+ propertyPairs.emplace_back("1");
} else if (*j == "WRAP_EXCLUDE") {
- propertyPairs.push_back("WRAP_EXCLUDE");
- propertyPairs.push_back("1");
+ propertyPairs.emplace_back("WRAP_EXCLUDE");
+ propertyPairs.emplace_back("1");
} else if (*j == "GENERATED") {
generated = true;
- propertyPairs.push_back("GENERATED");
- propertyPairs.push_back("1");
+ propertyPairs.emplace_back("GENERATED");
+ propertyPairs.emplace_back("1");
} else if (*j == "COMPILE_FLAGS") {
- propertyPairs.push_back("COMPILE_FLAGS");
+ propertyPairs.emplace_back("COMPILE_FLAGS");
++j;
if (j == propend) {
errors = "called with incorrect number of arguments "
@@ -72,7 +72,7 @@ bool cmSetSourceFilesPropertiesCommand::RunCommand(
}
propertyPairs.push_back(*j);
} else if (*j == "OBJECT_DEPENDS") {
- propertyPairs.push_back("OBJECT_DEPENDS");
+ propertyPairs.emplace_back("OBJECT_DEPENDS");
++j;
if (j == propend) {
errors = "called with incorrect number of arguments "
@@ -87,7 +87,7 @@ bool cmSetSourceFilesPropertiesCommand::RunCommand(
propertyPairs.push_back(*j);
if (*j == "GENERATED") {
++j;
- if (j != propend && cmSystemTools::IsOn(j->c_str())) {
+ if (j != propend && cmSystemTools::IsOn(*j)) {
generated = true;
}
} else {
diff --git a/Source/cmSetSourceFilesPropertiesCommand.h b/Source/cmSetSourceFilesPropertiesCommand.h
index 2e22dc9ef..afb19f6e6 100644
--- a/Source/cmSetSourceFilesPropertiesCommand.h
+++ b/Source/cmSetSourceFilesPropertiesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSetSourceFilesPropertiesCommand_h
#define cmSetSourceFilesPropertiesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,17 +16,14 @@ class cmMakefile;
class cmSetSourceFilesPropertiesCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE
- {
- return new cmSetSourceFilesPropertiesCommand;
- }
+ cmCommand* Clone() override { return new cmSetSourceFilesPropertiesCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
static bool RunCommand(cmMakefile* mf,
std::vector<std::string>::const_iterator filebeg,
diff --git a/Source/cmSetTargetPropertiesCommand.cxx b/Source/cmSetTargetPropertiesCommand.cxx
index 642591337..1dc7e69a3 100644
--- a/Source/cmSetTargetPropertiesCommand.cxx
+++ b/Source/cmSetTargetPropertiesCommand.cxx
@@ -4,6 +4,7 @@
#include <iterator>
+#include "cmAlgorithms.h"
#include "cmMakefile.h"
#include "cmTarget.h"
@@ -30,7 +31,7 @@ bool cmSetTargetPropertiesCommand::InitialPass(
this->SetError("called with incorrect number of arguments.");
return false;
}
- propertyPairs.insert(propertyPairs.end(), j, args.end());
+ cmAppend(propertyPairs, j, args.end());
break;
}
numFiles++;
diff --git a/Source/cmSetTargetPropertiesCommand.h b/Source/cmSetTargetPropertiesCommand.h
index 425618157..c9755da91 100644
--- a/Source/cmSetTargetPropertiesCommand.h
+++ b/Source/cmSetTargetPropertiesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSetTargetsPropertiesCommand_h
#define cmSetTargetsPropertiesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,14 +16,14 @@ class cmMakefile;
class cmSetTargetPropertiesCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmSetTargetPropertiesCommand; }
+ cmCommand* Clone() override { return new cmSetTargetPropertiesCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/**
* Used by this command and cmSetPropertiesCommand
diff --git a/Source/cmSetTestsPropertiesCommand.cxx b/Source/cmSetTestsPropertiesCommand.cxx
index e27c675c6..cc9587ca6 100644
--- a/Source/cmSetTestsPropertiesCommand.cxx
+++ b/Source/cmSetTestsPropertiesCommand.cxx
@@ -4,6 +4,7 @@
#include <iterator>
+#include "cmAlgorithms.h"
#include "cmMakefile.h"
#include "cmTest.h"
@@ -30,7 +31,7 @@ bool cmSetTestsPropertiesCommand::InitialPass(
this->SetError("called with incorrect number of arguments.");
return false;
}
- propertyPairs.insert(propertyPairs.end(), j, args.end());
+ cmAppend(propertyPairs, j, args.end());
break;
}
numFiles++;
diff --git a/Source/cmSetTestsPropertiesCommand.h b/Source/cmSetTestsPropertiesCommand.h
index 90f004c34..84b2645b3 100644
--- a/Source/cmSetTestsPropertiesCommand.h
+++ b/Source/cmSetTestsPropertiesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSetTestsPropertiesCommand_h
#define cmSetTestsPropertiesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,14 +16,14 @@ class cmMakefile;
class cmSetTestsPropertiesCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmSetTestsPropertiesCommand; }
+ cmCommand* Clone() override { return new cmSetTestsPropertiesCommand; }
/**
* This is called when the command is first encountered in
* the input file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
static bool SetOneTest(const std::string& tname,
std::vector<std::string>& propertyPairs,
diff --git a/Source/cmSiteNameCommand.cxx b/Source/cmSiteNameCommand.cxx
index 7eace268f..9f041bc5f 100644
--- a/Source/cmSiteNameCommand.cxx
+++ b/Source/cmSiteNameCommand.cxx
@@ -19,12 +19,12 @@ bool cmSiteNameCommand::InitialPass(std::vector<std::string> const& args,
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");
+ paths.emplace_back("/usr/bsd");
+ paths.emplace_back("/usr/sbin");
+ paths.emplace_back("/usr/bin");
+ paths.emplace_back("/bin");
+ paths.emplace_back("/sbin");
+ paths.emplace_back("/usr/local/bin");
const char* cacheValue = this->Makefile->GetDefinition(args[0]);
if (cacheValue) {
@@ -50,11 +50,10 @@ bool cmSiteNameCommand::InitialPass(std::vector<std::string> const& args,
}
#else
// try to find the hostname for this computer
- if (!cmSystemTools::IsOff(hostname_cmd.c_str())) {
+ if (!cmSystemTools::IsOff(hostname_cmd)) {
std::string host;
- cmSystemTools::RunSingleCommand(hostname_cmd.c_str(), &host, CM_NULLPTR,
- CM_NULLPTR, CM_NULLPTR,
- cmSystemTools::OUTPUT_NONE);
+ cmSystemTools::RunSingleCommand(hostname_cmd, &host, nullptr, nullptr,
+ nullptr, cmSystemTools::OUTPUT_NONE);
// got the hostname
if (!host.empty()) {
diff --git a/Source/cmSiteNameCommand.h b/Source/cmSiteNameCommand.h
index 6c65480ed..2d8dc1768 100644
--- a/Source/cmSiteNameCommand.h
+++ b/Source/cmSiteNameCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSiteNameCommand_h
#define cmSiteNameCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmSiteNameCommand; }
+ cmCommand* Clone() override { return new cmSiteNameCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx
index 5c4f18b40..d05fb68d9 100644
--- a/Source/cmSourceFile.cxx
+++ b/Source/cmSourceFile.cxx
@@ -2,28 +2,27 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSourceFile.h"
-#include <sstream>
+#include <array>
+#include <utility>
#include "cmCustomCommand.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmProperty.h"
#include "cmState.h"
#include "cmSystemTools.h"
#include "cmake.h"
-cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name)
- : Location(mf, name)
+cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name,
+ cmSourceFileLocationKind kind)
+ : Location(mf, name, kind)
{
- this->CustomCommand = CM_NULLPTR;
- this->FindFullPathFailed = false;
- this->IsUiFile = (".ui" == cmSystemTools::GetFilenameLastExtension(
- this->Location.GetName()));
}
cmSourceFile::~cmSourceFile()
{
- this->SetCustomCommand(CM_NULLPTR);
+ this->SetCustomCommand(nullptr);
}
std::string const& cmSourceFile::GetExtension() const
@@ -32,6 +31,8 @@ std::string const& cmSourceFile::GetExtension() const
}
const std::string cmSourceFile::propLANGUAGE = "LANGUAGE";
+const std::string cmSourceFile::propLOCATION = "LOCATION";
+const std::string cmSourceFile::propGENERATED = "GENERATED";
void cmSourceFile::SetObjectLibrary(std::string const& objlib)
{
@@ -112,95 +113,88 @@ std::string const& cmSourceFile::GetFullPath() const
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")) {
+ // If the file is generated compute the location without checking on disk.
+ if (this->GetIsGenerated()) {
// 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();
+ this->FullPath = this->Location.GetFullPath();
return true;
}
- // The file is not generated. It must exist on disk.
- cmMakefile const* mf = this->Location.GetMakefile();
- const char* tryDirs[3] = { CM_NULLPTR, CM_NULLPTR, CM_NULLPTR };
- if (this->Location.DirectoryIsAmbiguous()) {
- tryDirs[0] = mf->GetCurrentSourceDirectory();
- tryDirs[1] = mf->GetCurrentBinaryDirectory();
- } else {
- tryDirs[0] = "";
+ // If this method has already failed once do not try again.
+ if (this->FindFullPathFailed) {
+ return false;
}
- const std::vector<std::string>& srcExts =
- mf->GetCMakeInstance()->GetSourceExtensions();
- std::vector<std::string> hdrExts =
- mf->GetCMakeInstance()->GetHeaderExtensions();
- for (const char* const* di = tryDirs; *di; ++di) {
- std::string tryPath = this->Location.GetDirectory();
- if (!tryPath.empty()) {
- tryPath += "/";
- }
- tryPath += this->Location.GetName();
- tryPath = cmSystemTools::CollapseFullPath(tryPath, *di);
- if (this->TryFullPath(tryPath, "")) {
+
+ // The file is not generated. It must exist on disk.
+ cmMakefile const* makefile = this->Location.GetMakefile();
+ // Location path
+ std::string const lPath = this->Location.GetFullPath();
+ // List of extension lists
+ std::array<std::vector<std::string> const*, 2> const extsLists = {
+ { &makefile->GetCMakeInstance()->GetSourceExtensions(),
+ &makefile->GetCMakeInstance()->GetHeaderExtensions() }
+ };
+
+ // Tries to find the file in a given directory
+ auto findInDir = [this, &extsLists, &lPath](std::string const& dir) -> bool {
+ // Compute full path
+ std::string const fullPath = cmSystemTools::CollapseFullPath(lPath, dir);
+ // Try full path
+ if (cmSystemTools::FileExists(fullPath)) {
+ this->FullPath = fullPath;
return true;
}
- for (std::vector<std::string>::const_iterator ei = srcExts.begin();
- ei != srcExts.end(); ++ei) {
- if (this->TryFullPath(tryPath, *ei)) {
- return true;
+ // Try full path with extension
+ for (auto exts : extsLists) {
+ for (std::string const& ext : *exts) {
+ if (!ext.empty()) {
+ std::string extPath = fullPath;
+ extPath += '.';
+ extPath += ext;
+ if (cmSystemTools::FileExists(extPath)) {
+ this->FullPath = extPath;
+ return true;
+ }
+ }
}
}
- for (std::vector<std::string>::const_iterator ei = hdrExts.begin();
- ei != hdrExts.end(); ++ei) {
- if (this->TryFullPath(tryPath, *ei)) {
- return true;
- }
+ // File not found
+ return false;
+ };
+
+ // Try to find the file in various directories
+ if (this->Location.DirectoryIsAmbiguous()) {
+ if (findInDir(makefile->GetCurrentSourceDirectory()) ||
+ findInDir(makefile->GetCurrentBinaryDirectory())) {
+ return true;
+ }
+ } else {
+ if (findInDir({})) {
+ return true;
}
}
- std::ostringstream 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;
+ // Compose error
+ std::string err;
+ err += "Cannot find source file:\n ";
+ err += lPath;
+ err += "\nTried extensions";
+ for (auto exts : extsLists) {
+ for (std::string const& ext : *exts) {
+ err += " .";
+ err += ext;
+ }
}
- if (error) {
- *error = e.str();
+ if (error != nullptr) {
+ *error = std::move(err);
} else {
- this->Location.GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
+ makefile->IssueMessage(MessageType::FATAL_ERROR, err);
}
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;
- }
+ // File not found
return false;
}
@@ -246,11 +240,9 @@ void cmSourceFile::SetProperty(const std::string& prop, const char* value)
{
this->Properties.SetProperty(prop, value);
- if (this->IsUiFile) {
- cmMakefile const* mf = this->Location.GetMakefile();
- if (prop == "AUTOUIC_OPTIONS") {
- const_cast<cmMakefile*>(mf)->AddQtUiFileWithOptions(this);
- }
+ // Update IsGenerated flag
+ if (prop == propGENERATED) {
+ this->IsGenerated = cmSystemTools::IsOn(value);
}
}
@@ -258,6 +250,11 @@ void cmSourceFile::AppendProperty(const std::string& prop, const char* value,
bool asString)
{
this->Properties.AppendProperty(prop, value, asString);
+
+ // Update IsGenerated flag
+ if (prop == propGENERATED) {
+ this->IsGenerated = this->GetPropertyAsBool(propGENERATED);
+ }
}
const char* cmSourceFile::GetPropertyForUser(const std::string& prop)
@@ -276,7 +273,7 @@ const char* cmSourceFile::GetPropertyForUser(const std::string& prop)
// 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") {
+ if (prop == propLOCATION) {
// Commit to a location.
this->GetFullPath();
}
@@ -288,9 +285,9 @@ const char* cmSourceFile::GetPropertyForUser(const std::string& prop)
const char* cmSourceFile::GetProperty(const std::string& prop) const
{
// Check for computed properties.
- if (prop == "LOCATION") {
+ if (prop == propLOCATION) {
if (this->FullPath.empty()) {
- return CM_NULLPTR;
+ return nullptr;
}
return this->FullPath.c_str();
}
@@ -308,6 +305,15 @@ const char* cmSourceFile::GetProperty(const std::string& prop) const
return retVal;
}
+const char* cmSourceFile::GetSafeProperty(const std::string& prop) const
+{
+ const char* ret = this->GetProperty(prop);
+ if (!ret) {
+ return "";
+ }
+ return ret;
+}
+
bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const
{
return cmSystemTools::IsOn(this->GetProperty(prop));
diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h
index 0be659c5f..edad4c7b5 100644
--- a/Source/cmSourceFile.h
+++ b/Source/cmSourceFile.h
@@ -3,10 +3,11 @@
#ifndef cmSourceFile_h
#define cmSourceFile_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmPropertyMap.h"
#include "cmSourceFileLocation.h"
+#include "cmSourceFileLocationKind.h"
#include <string>
#include <vector>
@@ -27,10 +28,15 @@ public:
* Construct with the makefile storing the source and the initial
* name referencing it.
*/
- cmSourceFile(cmMakefile* mf, const std::string& name);
+ cmSourceFile(
+ cmMakefile* mf, const std::string& name,
+ cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
~cmSourceFile();
+ cmSourceFile(const cmSourceFile&) = delete;
+ cmSourceFile& operator=(const cmSourceFile&) = delete;
+
/**
* Get the list of the custom commands for this source file
*/
@@ -38,17 +44,24 @@ public:
cmCustomCommand const* GetCustomCommand() const;
void SetCustomCommand(cmCustomCommand* cc);
- ///! Set/Get a property of this source file
+ //! 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);
+ //! Might return a nullptr if the property is not set or invalid
const char* GetProperty(const std::string& prop) const;
+ //! Always returns a valid pointer
+ const char* GetSafeProperty(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);
+ //! Checks is the GENERATED property is set and true
+ /// @return Equivalent to GetPropertyAsBool("GENERATED")
+ bool GetIsGenerated() const { return this->IsGenerated; }
+
/**
* 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.
@@ -57,7 +70,7 @@ public:
* horrible interface, but is necessary for backwards
* compatibility).
*/
- std::string const& GetFullPath(std::string* error = CM_NULLPTR);
+ std::string const& GetFullPath(std::string* error = nullptr);
std::string const& GetFullPath() const;
/**
@@ -100,24 +113,32 @@ public:
private:
cmSourceFileLocation Location;
cmPropertyMap Properties;
- cmCustomCommand* CustomCommand;
+ cmCustomCommand* CustomCommand = nullptr;
std::string Extension;
std::string Language;
std::string FullPath;
std::string ObjectLibrary;
std::vector<std::string> Depends;
- bool FindFullPathFailed;
- bool IsUiFile;
+ bool FindFullPathFailed = false;
+ bool IsGenerated = false;
bool FindFullPath(std::string* error);
- bool TryFullPath(const std::string& path, const std::string& ext);
void CheckExtension();
void CheckLanguage(std::string const& ext);
static const std::string propLANGUAGE;
+ static const std::string propLOCATION;
+ static const std::string propGENERATED;
};
// TODO: Factor out into platform information modules.
#define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"
+#define CM_SOURCE_REGEX \
+ "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|cu|f|f90|for|fpp|ftn|m|mm|rc|def|r|odl|idl|" \
+ "hpj" \
+ "|bat)$"
+
+#define CM_RESOURCE_REGEX "\\.(pdf|plist|png|jpeg|jpg|storyboard|xcassets)$"
+
#endif
diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx
index 86711d784..acacba26c 100644
--- a/Source/cmSourceFileLocation.cxx
+++ b/Source/cmSourceFileLocation.cxx
@@ -2,24 +2,16 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSourceFileLocation.h"
-#include "cmConfigure.h"
-
#include "cmAlgorithms.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmake.h"
-#include <algorithm>
#include <assert.h>
-#include <vector>
-cmSourceFileLocation::cmSourceFileLocation()
- : Makefile(CM_NULLPTR)
- , AmbiguousDirectory(true)
- , AmbiguousExtension(true)
-{
-}
+cmSourceFileLocation::cmSourceFileLocation() = default;
cmSourceFileLocation::cmSourceFileLocation(const cmSourceFileLocation& loc)
: Makefile(loc.Makefile)
@@ -30,33 +22,34 @@ cmSourceFileLocation::cmSourceFileLocation(const cmSourceFileLocation& loc)
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)
+ const std::string& name,
+ cmSourceFileLocationKind kind)
: Makefile(mf)
{
- this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name.c_str());
+ this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name);
this->AmbiguousExtension = true;
this->Directory = cmSystemTools::GetFilenamePath(name);
- if (cmSystemTools::FileIsFullPath(this->Directory.c_str())) {
+ if (cmSystemTools::FileIsFullPath(this->Directory)) {
this->Directory = cmSystemTools::CollapseFullPath(this->Directory);
}
this->Name = cmSystemTools::GetFilenameName(name);
- this->UpdateExtension(name);
+ if (kind == cmSourceFileLocationKind::Known) {
+ this->DirectoryUseSource();
+ this->AmbiguousExtension = false;
+ } else {
+ this->UpdateExtension(name);
+ }
+}
+
+std::string cmSourceFileLocation::GetFullPath() const
+{
+ std::string path = this->GetDirectory();
+ if (!path.empty()) {
+ path += '/';
+ }
+ path += this->GetName();
+ return path;
}
void cmSourceFileLocation::Update(cmSourceFileLocation const& loc)
@@ -103,13 +96,9 @@ void cmSourceFileLocation::UpdateExtension(const std::string& name)
// The global generator checks extensions of enabled languages.
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
cmMakefile const* mf = this->Makefile;
- const std::vector<std::string>& srcExts =
- mf->GetCMakeInstance()->GetSourceExtensions();
- const std::vector<std::string>& hdrExts =
- mf->GetCMakeInstance()->GetHeaderExtensions();
+ auto cm = mf->GetCMakeInstance();
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()) {
+ cm->IsSourceExtension(ext) || cm->IsHeaderExtension(ext)) {
// This is a known extension. Use the given filename with extension.
this->Name = cmSystemTools::GetFilenameName(name);
this->AmbiguousExtension = false;
@@ -129,7 +118,7 @@ void cmSourceFileLocation::UpdateExtension(const std::string& name)
tryPath += "/";
}
tryPath += this->Name;
- if (cmSystemTools::FileExists(tryPath.c_str(), true)) {
+ if (cmSystemTools::FileExists(tryPath, true)) {
// We found a source file named by the user on disk. Trust it's
// extension.
this->Name = cmSystemTools::GetFilenameName(name);
@@ -166,14 +155,8 @@ bool cmSourceFileLocation::MatchesAmbiguousExtension(
// 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->GetCMakeInstance()->GetSourceExtensions();
- if (std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) {
- return true;
- }
- std::vector<std::string> hdrExts =
- mf->GetCMakeInstance()->GetHeaderExtensions();
- return std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end();
+ auto cm = mf->GetCMakeInstance();
+ return cm->IsSourceExtension(ext) || cm->IsHeaderExtension(ext);
}
bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
@@ -220,7 +203,7 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
// This can occur when referencing a source file from a different
// directory. This is not yet allowed.
this->Makefile->IssueMessage(
- cmake::INTERNAL_ERROR,
+ MessageType::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.");
@@ -228,18 +211,18 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc)
}
} else if (this->AmbiguousDirectory) {
// Compare possible directory combinations.
- std::string const& srcDir = cmSystemTools::CollapseFullPath(
+ std::string const srcDir = cmSystemTools::CollapseFullPath(
this->Directory, this->Makefile->GetCurrentSourceDirectory());
- std::string const& binDir = cmSystemTools::CollapseFullPath(
+ std::string const binDir = cmSystemTools::CollapseFullPath(
this->Directory, this->Makefile->GetCurrentBinaryDirectory());
if (srcDir != loc.Directory && binDir != loc.Directory) {
return false;
}
} else if (loc.AmbiguousDirectory) {
// Compare possible directory combinations.
- std::string const& srcDir = cmSystemTools::CollapseFullPath(
+ std::string const srcDir = cmSystemTools::CollapseFullPath(
loc.Directory, loc.Makefile->GetCurrentSourceDirectory());
- std::string const& binDir = cmSystemTools::CollapseFullPath(
+ std::string const binDir = cmSystemTools::CollapseFullPath(
loc.Directory, loc.Makefile->GetCurrentBinaryDirectory());
if (srcDir != this->Directory && binDir != this->Directory) {
return false;
diff --git a/Source/cmSourceFileLocation.h b/Source/cmSourceFileLocation.h
index 6dbc2daed..87040b882 100644
--- a/Source/cmSourceFileLocation.h
+++ b/Source/cmSourceFileLocation.h
@@ -7,6 +7,8 @@
#include <string>
+#include "cmSourceFileLocationKind.h"
+
class cmMakefile;
/** \class cmSourceFileLocation
@@ -26,10 +28,13 @@ 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(
+ cmMakefile const* mf, const std::string& name,
+ cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous);
cmSourceFileLocation();
cmSourceFileLocation(const cmSourceFileLocation& loc);
- cmSourceFileLocation& operator=(const cmSourceFileLocation& loc);
+
+ cmSourceFileLocation& operator=(cmSourceFileLocation const&) = delete;
/**
* Return whether the given source file location could refers to the
@@ -39,12 +44,12 @@ public:
bool Matches(cmSourceFileLocation const& loc);
/**
- * Explicity state that the source file is located in the source tree.
+ * Explicitly 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.
+ * Explicitly state that the source file is located in the build tree.
*/
void DirectoryUseBinary();
@@ -75,13 +80,19 @@ public:
const std::string& GetName() const { return this->Name; }
/**
+ * Get the full file path composed of GetDirectory() and GetName().
+ */
+ std::string GetFullPath() const;
+
+ /**
* 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;
+ cmMakefile const* const Makefile = nullptr;
+ bool AmbiguousDirectory = true;
+ bool AmbiguousExtension = true;
std::string Directory;
std::string Name;
diff --git a/Source/cmSourceGroup.cxx b/Source/cmSourceGroup.cxx
index 104e959a9..7e1e836a0 100644
--- a/Source/cmSourceGroup.cxx
+++ b/Source/cmSourceGroup.cxx
@@ -2,15 +2,17 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSourceGroup.h"
+#include <utility>
+
class cmSourceGroupInternals
{
public:
std::vector<cmSourceGroup> GroupChildren;
};
-cmSourceGroup::cmSourceGroup(const char* name, const char* regex,
+cmSourceGroup::cmSourceGroup(std::string name, const char* regex,
const char* parentName)
- : Name(name)
+ : Name(std::move(name))
{
this->Internal = new cmSourceGroupInternals;
this->SetGroupRegex(regex);
@@ -60,24 +62,24 @@ void cmSourceGroup::AddGroupFile(const std::string& name)
this->GroupFiles.insert(name);
}
-const char* cmSourceGroup::GetName() const
+std::string const& cmSourceGroup::GetName() const
{
- return this->Name.c_str();
+ return this->Name;
}
-const char* cmSourceGroup::GetFullName() const
+std::string const& cmSourceGroup::GetFullName() const
{
- return this->FullName.c_str();
+ return this->FullName;
}
-bool cmSourceGroup::MatchesRegex(const char* name)
+bool cmSourceGroup::MatchesRegex(const std::string& name)
{
return this->GroupRegex.find(name);
}
-bool cmSourceGroup::MatchesFiles(const char* name)
+bool cmSourceGroup::MatchesFiles(const std::string& name) const
{
- return this->GroupFiles.find(name) != this->GroupFiles.end();
+ return this->GroupFiles.find(name) != this->GroupFiles.cend();
}
void cmSourceGroup::AssignSource(const cmSourceFile* sf)
@@ -95,58 +97,37 @@ void cmSourceGroup::AddChild(cmSourceGroup const& child)
this->Internal->GroupChildren.push_back(child);
}
-cmSourceGroup* cmSourceGroup::LookupChild(const char* name) const
+cmSourceGroup* cmSourceGroup::LookupChild(const std::string& name)
{
- // 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();
-
+ for (cmSourceGroup& group : this->Internal->GroupChildren) {
// look if descenened is the one were looking for
- if (sgName == name) {
- return const_cast<cmSourceGroup*>(&(*iter)); // if it so return it
+ if (group.GetName() == name) {
+ return (&group); // if it so return it
}
}
// if no child with this name was found return NULL
- return CM_NULLPTR;
+ return nullptr;
}
-cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const char* name)
+cmSourceGroup* cmSourceGroup::MatchChildrenFiles(const std::string& 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);
+ for (cmSourceGroup& group : this->Internal->GroupChildren) {
+ cmSourceGroup* result = group.MatchChildrenFiles(name);
if (result) {
return result;
}
}
- return CM_NULLPTR;
+ return nullptr;
}
-cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const char* name)
+cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const std::string& 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);
+ for (cmSourceGroup& group : this->Internal->GroupChildren) {
+ cmSourceGroup* result = group.MatchChildrenRegex(name);
if (result) {
return result;
}
@@ -155,7 +136,7 @@ cmSourceGroup* cmSourceGroup::MatchChildrenRegex(const char* name)
return this;
}
- return CM_NULLPTR;
+ return nullptr;
}
std::vector<cmSourceGroup> const& cmSourceGroup::GetGroupChildren() const
diff --git a/Source/cmSourceGroup.h b/Source/cmSourceGroup.h
index 97affed6e..7c6549446 100644
--- a/Source/cmSourceGroup.h
+++ b/Source/cmSourceGroup.h
@@ -3,7 +3,7 @@
#ifndef cmSourceGroup_h
#define cmSourceGroup_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmsys/RegularExpression.hxx"
#include <set>
@@ -26,8 +26,8 @@ class cmSourceGroupInternals;
class cmSourceGroup
{
public:
- cmSourceGroup(const char* name, const char* regex,
- const char* parentName = CM_NULLPTR);
+ cmSourceGroup(std::string name, const char* regex,
+ const char* parentName = nullptr);
cmSourceGroup(cmSourceGroup const& r);
~cmSourceGroup();
cmSourceGroup& operator=(cmSourceGroup const&);
@@ -50,38 +50,38 @@ public:
/**
* Looks up child and returns it
*/
- cmSourceGroup* LookupChild(const char* name) const;
+ cmSourceGroup* LookupChild(const std::string& name);
/**
* Get the name of this group.
*/
- const char* GetName() const;
+ std::string const& GetName() const;
/**
* Get the full path name for group.
*/
- const char* GetFullName() const;
+ std::string const& GetFullName() const;
/**
* Check if the given name matches this group's regex.
*/
- bool MatchesRegex(const char* name);
+ bool MatchesRegex(const std::string& name);
/**
* Check if the given name matches this group's explicit file list.
*/
- bool MatchesFiles(const char* name);
+ bool MatchesFiles(const std::string& name) const;
/**
* Check if the given name matches this group's explicit file list
* in children.
*/
- cmSourceGroup* MatchChildrenFiles(const char* name);
+ cmSourceGroup* MatchChildrenFiles(const std::string& name);
/**
* Check if the given name matches this group's regex in children.
*/
- cmSourceGroup* MatchChildrenRegex(const char* name);
+ cmSourceGroup* MatchChildrenRegex(const std::string& name);
/**
* Assign the given source file to this group. Used only by
diff --git a/Source/cmSourceGroupCommand.cxx b/Source/cmSourceGroupCommand.cxx
index a966300c0..04b4d72ec 100644
--- a/Source/cmSourceGroupCommand.cxx
+++ b/Source/cmSourceGroupCommand.cxx
@@ -2,19 +2,21 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmSourceGroupCommand.h"
+#include <algorithm>
#include <set>
-#include <sstream>
#include <stddef.h>
+#include <utility>
#include "cmMakefile.h"
#include "cmSourceGroup.h"
#include "cmSystemTools.h"
namespace {
-const size_t RootIndex = 1;
-const size_t FilesWithoutPrefixKeywordIndex = 2;
-const size_t FilesWithPrefixKeywordIndex = 4;
-const size_t PrefixKeywordIndex = 2;
+const std::string kTreeOptionName = "TREE";
+const std::string kPrefixOptionName = "PREFIX";
+const std::string kFilesOptionName = "FILES";
+const std::string kRegexOptionName = "REGULAR_EXPRESSION";
+const std::string kSourceGroupOptionName = "<sg_name>";
std::vector<std::string> tokenizePath(const std::string& path)
{
@@ -26,7 +28,7 @@ std::string getFullFilePath(const std::string& currentPath,
{
std::string fullPath = path;
- if (!cmSystemTools::FileIsFullPath(path.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(path)) {
fullPath = currentPath;
fullPath += "/";
fullPath += path;
@@ -41,8 +43,8 @@ std::set<std::string> getSourceGroupFilesPaths(
std::set<std::string> ret;
const std::string::size_type rootLength = root.length();
- for (size_t i = 0; i < files.size(); ++i) {
- ret.insert(files[i].substr(rootLength + 1)); // +1 to also omnit last '/'
+ for (std::string const& file : files) {
+ ret.insert(file.substr(rootLength + 1)); // +1 to also omnit last '/'
}
return ret;
@@ -51,9 +53,9 @@ std::set<std::string> getSourceGroupFilesPaths(
bool rootIsPrefix(const std::string& root,
const std::vector<std::string>& files, std::string& error)
{
- for (size_t i = 0; i < files.size(); ++i) {
- if (!cmSystemTools::StringStartsWith(files[i], root.c_str())) {
- error = "ROOT: " + root + " is not a prefix of file: " + files[i];
+ for (std::string const& file : files) {
+ if (!cmSystemTools::StringStartsWith(file, root.c_str())) {
+ error = "ROOT: " + root + " is not a prefix of file: " + file;
return false;
}
}
@@ -61,41 +63,20 @@ bool rootIsPrefix(const std::string& root,
return true;
}
-cmSourceGroup* addSourceGroup(const std::vector<std::string>& tokenizedPath,
- cmMakefile& makefile)
-{
- cmSourceGroup* sg;
-
- sg = makefile.GetSourceGroup(tokenizedPath);
- if (!sg) {
- makefile.AddSourceGroup(tokenizedPath);
- sg = makefile.GetSourceGroup(tokenizedPath);
- if (!sg) {
- return CM_NULLPTR;
- }
- }
-
- return sg;
-}
-
-std::string prepareFilePathForTree(const std::string& path,
- const std::string& currentSourceDir)
-{
- if (!cmSystemTools::FileIsFullPath(path)) {
- return cmSystemTools::CollapseFullPath(currentSourceDir + "/" + path);
- }
- return cmSystemTools::CollapseFullPath(path);
-}
-
std::vector<std::string> prepareFilesPathsForTree(
- std::vector<std::string>::const_iterator begin,
- std::vector<std::string>::const_iterator end,
+ const std::vector<std::string>& filesPaths,
const std::string& currentSourceDir)
{
std::vector<std::string> prepared;
-
- for (; begin != end; ++begin) {
- prepared.push_back(prepareFilePathForTree(*begin, currentSourceDir));
+ prepared.reserve(filesPaths.size());
+
+ for (auto const& filePath : filesPaths) {
+ std::string fullPath =
+ cmSystemTools::CollapseFullPath(filePath, currentSourceDir);
+ // If provided file path is actually not a file, silently ignore it.
+ if (cmSystemTools::FileExists(fullPath, /*isFile=*/true)) {
+ prepared.emplace_back(std::move(fullPath));
+ }
}
return prepared;
@@ -108,26 +89,29 @@ bool addFilesToItsSourceGroups(const std::string& root,
{
cmSourceGroup* sg;
- for (std::set<std::string>::const_iterator it = sgFilesPaths.begin();
- it != sgFilesPaths.end(); ++it) {
+ for (std::string const& sgFilesPath : sgFilesPaths) {
std::vector<std::string> tokenizedPath;
if (!prefix.empty()) {
- tokenizedPath = tokenizePath(prefix + '/' + *it);
+ tokenizedPath = tokenizePath(prefix + '/' + sgFilesPath);
} else {
- tokenizedPath = tokenizePath(*it);
+ tokenizedPath = tokenizePath(sgFilesPath);
}
- if (tokenizedPath.size() > 1) {
+ if (!tokenizedPath.empty()) {
tokenizedPath.pop_back();
- sg = addSourceGroup(tokenizedPath, makefile);
+ if (tokenizedPath.empty()) {
+ tokenizedPath.emplace_back();
+ }
+
+ sg = makefile.GetOrCreateSourceGroup(tokenizedPath);
if (!sg) {
- errorMsg = "Could not create source group for file: " + *it;
+ errorMsg = "Could not create source group for file: " + sgFilesPath;
return false;
}
- const std::string fullPath = getFullFilePath(root, *it);
+ const std::string fullPath = getFullFilePath(root, sgFilesPath);
sg->AddGroupFile(fullPath);
}
}
@@ -139,6 +123,57 @@ bool addFilesToItsSourceGroups(const std::string& root,
class cmExecutionStatus;
// cmSourceGroupCommand
+cmSourceGroupCommand::ExpectedOptions
+cmSourceGroupCommand::getExpectedOptions() const
+{
+ ExpectedOptions options;
+
+ options.push_back(kTreeOptionName);
+ options.push_back(kPrefixOptionName);
+ options.push_back(kFilesOptionName);
+ options.push_back(kRegexOptionName);
+
+ return options;
+}
+
+bool cmSourceGroupCommand::isExpectedOption(
+ const std::string& argument, const ExpectedOptions& expectedOptions)
+{
+ return std::find(expectedOptions.begin(), expectedOptions.end(), argument) !=
+ expectedOptions.end();
+}
+
+void cmSourceGroupCommand::parseArguments(
+ const std::vector<std::string>& args,
+ cmSourceGroupCommand::ParsedArguments& parsedArguments)
+{
+ const ExpectedOptions expectedOptions = getExpectedOptions();
+ size_t i = 0;
+
+ // at this point we know that args vector is not empty
+
+ // if first argument is not one of expected options it's source group name
+ if (!isExpectedOption(args[0], expectedOptions)) {
+ // get source group name and go to next argument
+ parsedArguments[kSourceGroupOptionName].push_back(args[0]);
+ ++i;
+ }
+
+ for (; i < args.size();) {
+ // get current option and increment index to go to next argument
+ const std::string& currentOption = args[i++];
+
+ // create current option entry in parsed arguments
+ std::vector<std::string>& currentOptionArguments =
+ parsedArguments[currentOption];
+
+ // collect option arguments while we won't find another expected option
+ while (i < args.size() && !isExpectedOption(args[i], expectedOptions)) {
+ currentOptionArguments.push_back(args[i++]);
+ }
+ }
+}
+
bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
@@ -147,127 +182,94 @@ bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
- if (args[0] == "TREE") {
- std::string error;
+ // If only two arguments are given, the pre-1.8 version of the
+ // command is being invoked.
+ if (args.size() == 2 && args[1] != "FILES") {
+ cmSourceGroup* sg = this->Makefile->GetOrCreateSourceGroup(args[0]);
- if (!processTree(args, error)) {
- this->SetError(error);
+ if (!sg) {
+ this->SetError("Could not create or find source group");
return false;
}
+ sg->SetGroupRegex(args[1].c_str());
return true;
}
- std::string delimiter = "\\";
- if (this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER")) {
- delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
- }
+ ParsedArguments parsedArguments;
+ std::string errorMsg;
- std::vector<std::string> folders =
- cmSystemTools::tokenize(args[0], delimiter);
+ parseArguments(args, parsedArguments);
- cmSourceGroup* sg = CM_NULLPTR;
- 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");
+ if (!checkArgumentsPreconditions(parsedArguments, errorMsg)) {
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())) {
+ if (parsedArguments.find(kTreeOptionName) != parsedArguments.end()) {
+ if (!processTree(parsedArguments, errorMsg)) {
+ this->SetError(errorMsg);
+ return false;
+ }
+ } else {
+ if (parsedArguments.find(kSourceGroupOptionName) ==
+ parsedArguments.end()) {
+ this->SetError("Missing source group name.");
+ return false;
+ }
+
+ cmSourceGroup* sg = this->Makefile->GetOrCreateSourceGroup(args[0]);
+
+ if (!sg) {
+ this->SetError("Could not create or find source group");
+ return false;
+ }
+
+ // handle regex
+ if (parsedArguments.find(kRegexOptionName) != parsedArguments.end()) {
+ const std::string& sgRegex = parsedArguments[kRegexOptionName].front();
+ sg->SetGroupRegex(sgRegex.c_str());
+ }
+
+ // handle files
+ const std::vector<std::string>& filesArguments =
+ parsedArguments[kFilesOptionName];
+ for (auto const& filesArg : filesArguments) {
+ std::string src = filesArg;
+ if (!cmSystemTools::FileIsFullPath(src)) {
src = this->Makefile->GetCurrentSourceDirectory();
src += "/";
- src += args[i];
+ src += filesArg;
}
src = cmSystemTools::CollapseFullPath(src);
sg->AddGroupFile(src);
- } else {
- std::ostringstream err;
- err << "Unknown argument \"" << args[i] << "\". "
- << "Perhaps the FILES keyword is missing.\n";
- this->SetError(err.str());
- return false;
}
}
return true;
}
-bool cmSourceGroupCommand::checkTreeArgumentsPreconditions(
- const std::vector<std::string>& args, std::string& errorMsg) const
+bool cmSourceGroupCommand::checkArgumentsPreconditions(
+ const ParsedArguments& parsedArguments, std::string& errorMsg) const
{
- if (args.size() == 1) {
- errorMsg = "TREE argument given without a root.";
- return false;
- }
-
- if (args.size() < 3) {
- errorMsg = "Missing FILES arguments.";
- return false;
- }
-
- if (args[FilesWithoutPrefixKeywordIndex] != "FILES" &&
- args[PrefixKeywordIndex] != "PREFIX") {
- errorMsg = "Unknown argument \"" + args[2] +
- "\". Perhaps the FILES keyword is missing.\n";
- return false;
- }
-
- if (args[PrefixKeywordIndex] == "PREFIX" &&
- (args.size() < 5 || args[FilesWithPrefixKeywordIndex] != "FILES")) {
- errorMsg = "Missing FILES arguments.";
- return false;
- }
-
- return true;
+ return checkSingleParameterArgumentPreconditions(
+ kPrefixOptionName, parsedArguments, errorMsg) &&
+ checkSingleParameterArgumentPreconditions(kTreeOptionName, parsedArguments,
+ errorMsg) &&
+ checkSingleParameterArgumentPreconditions(kRegexOptionName,
+ parsedArguments, errorMsg);
}
-bool cmSourceGroupCommand::processTree(const std::vector<std::string>& args,
+bool cmSourceGroupCommand::processTree(ParsedArguments& parsedArguments,
std::string& errorMsg)
{
- if (!checkTreeArgumentsPreconditions(args, errorMsg)) {
- return false;
- }
-
- const std::string root = cmSystemTools::CollapseFullPath(args[RootIndex]);
- std::string prefix;
- size_t filesBegin = FilesWithoutPrefixKeywordIndex + 1;
- if (args[PrefixKeywordIndex] == "PREFIX") {
- prefix = args[PrefixKeywordIndex + 1];
- filesBegin = FilesWithPrefixKeywordIndex + 1;
- }
+ const std::string root =
+ cmSystemTools::CollapseFullPath(parsedArguments[kTreeOptionName].front());
+ std::string prefix = parsedArguments[kPrefixOptionName].empty()
+ ? ""
+ : parsedArguments[kPrefixOptionName].front();
const std::vector<std::string> filesVector =
- prepareFilesPathsForTree(args.begin() + filesBegin, args.end(),
+ prepareFilesPathsForTree(parsedArguments[kFilesOptionName],
this->Makefile->GetCurrentSourceDirectory());
if (!rootIsPrefix(root, filesVector, errorMsg)) {
@@ -277,9 +279,27 @@ bool cmSourceGroupCommand::processTree(const std::vector<std::string>& args,
std::set<std::string> sourceGroupPaths =
getSourceGroupFilesPaths(root, filesVector);
- if (!addFilesToItsSourceGroups(root, sourceGroupPaths, prefix,
- *(this->Makefile), errorMsg)) {
- return false;
+ return addFilesToItsSourceGroups(root, sourceGroupPaths, prefix,
+ *(this->Makefile), errorMsg);
+}
+
+bool cmSourceGroupCommand::checkSingleParameterArgumentPreconditions(
+ const std::string& argument, const ParsedArguments& parsedArguments,
+ std::string& errorMsg) const
+{
+ ParsedArguments::const_iterator foundArgument =
+ parsedArguments.find(argument);
+ if (foundArgument != parsedArguments.end()) {
+ const std::vector<std::string>& optionArguments = foundArgument->second;
+
+ if (optionArguments.empty()) {
+ errorMsg = argument + " argument given without an argument.";
+ return false;
+ }
+ if (optionArguments.size() > 1) {
+ errorMsg = "too many arguments passed to " + argument + ".";
+ return false;
+ }
}
return true;
diff --git a/Source/cmSourceGroupCommand.h b/Source/cmSourceGroupCommand.h
index 7d56b0d65..ec5ad329a 100644
--- a/Source/cmSourceGroupCommand.h
+++ b/Source/cmSourceGroupCommand.h
@@ -3,8 +3,9 @@
#ifndef cmSourceGroupCommand_h
#define cmSourceGroupCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include <map>
#include <string>
#include <vector>
@@ -24,20 +25,34 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmSourceGroupCommand; }
+ cmCommand* Clone() override { return new cmSourceGroupCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- bool processTree(const std::vector<std::string>& args,
- std::string& errorMsg);
- bool checkTreeArgumentsPreconditions(const std::vector<std::string>& args,
- std::string& errorMsg) const;
+ typedef std::map<std::string, std::vector<std::string>> ParsedArguments;
+ typedef std::vector<std::string> ExpectedOptions;
+
+ ExpectedOptions getExpectedOptions() const;
+
+ bool isExpectedOption(const std::string& argument,
+ const ExpectedOptions& expectedOptions);
+
+ void parseArguments(const std::vector<std::string>& args,
+ cmSourceGroupCommand::ParsedArguments& parsedArguments);
+
+ bool processTree(ParsedArguments& parsedArguments, std::string& errorMsg);
+
+ bool checkArgumentsPreconditions(const ParsedArguments& parsedArguments,
+ std::string& errorMsg) const;
+ bool checkSingleParameterArgumentPreconditions(
+ const std::string& argument, const ParsedArguments& parsedArguments,
+ std::string& errorMsg) const;
};
#endif
diff --git a/Source/cmStandardLexer.h b/Source/cmStandardLexer.h
index c9f42e4ce..13f7622a7 100644
--- a/Source/cmStandardLexer.h
+++ b/Source/cmStandardLexer.h
@@ -3,45 +3,45 @@
#ifndef cmStandardLexer_h
#define cmStandardLexer_h
-#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmsys/Configure.h" // IWYU pragma: keep
/* Disable some warnings. */
#if defined(_MSC_VER)
-#pragma warning(disable : 4018)
-#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)
+# pragma warning(disable : 4018)
+# 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(__GNUC__) && !defined(__INTEL_COMPILER)
-#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
-#pragma GCC diagnostic ignored "-Wconversion"
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 403
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
+# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
+# pragma GCC diagnostic ignored "-Wconversion"
+# pragma GCC diagnostic ignored "-Wsign-compare"
+# endif
+# if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 403
+# pragma GCC diagnostic ignored "-Wsign-conversion"
+# endif
#endif
/* Make sure isatty is available. */
#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <io.h>
-#if defined(_MSC_VER)
-#define isatty _isatty
-#endif
+# include <io.h>
+# if defined(_MSC_VER)
+# define isatty _isatty
+# endif
#else
-#include <unistd.h> // IWYU pragma: export
+# include <unistd.h> // IWYU pragma: export
#endif
/* Make sure malloc and free are available on QNX. */
#ifdef __QNX__
-#include <malloc.h>
+# include <malloc.h>
#endif
/* Disable features we do not need. */
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 92e47f748..fa7df0b2c 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -13,6 +13,7 @@
#include "cmCommand.h"
#include "cmDefinitions.h"
#include "cmDisallowedCommand.h"
+#include "cmGlobVerificationManager.h"
#include "cmListFileCache.h"
#include "cmStatePrivate.h"
#include "cmStateSnapshot.h"
@@ -21,21 +22,15 @@
#include "cmake.h"
cmState::cmState()
- : IsInTryCompile(false)
- , IsGeneratorMultiConfig(false)
- , WindowsShell(false)
- , WindowsVSIDE(false)
- , WatcomWMake(false)
- , MinGWMake(false)
- , NMake(false)
- , MSYSShell(false)
{
this->CacheManager = new cmCacheManager;
+ this->GlobVerificationManager = new cmGlobVerificationManager;
}
cmState::~cmState()
{
delete this->CacheManager;
+ delete this->GlobVerificationManager;
cmDeleteAll(this->BuiltinCommands);
cmDeleteAll(this->ScriptedCommands);
}
@@ -63,12 +58,12 @@ const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType)
return "UNKNOWN_LIBRARY";
}
assert(false && "Unexpected target type");
- return CM_NULLPTR;
+ return nullptr;
}
const char* cmCacheEntryTypes[] = { "BOOL", "PATH", "FILEPATH",
"STRING", "INTERNAL", "STATIC",
- "UNINITIALIZED", CM_NULLPTR };
+ "UNINITIALIZED", nullptr };
const char* cmState::CacheEntryTypeToString(cmStateEnums::CacheEntryType type)
{
@@ -80,20 +75,29 @@ const char* cmState::CacheEntryTypeToString(cmStateEnums::CacheEntryType type)
cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(const char* s)
{
+ cmStateEnums::CacheEntryType type = cmStateEnums::STRING;
+ StringToCacheEntryType(s, type);
+ return type;
+}
+
+bool cmState::StringToCacheEntryType(const char* s,
+ cmStateEnums::CacheEntryType& type)
+{
int i = 0;
while (cmCacheEntryTypes[i]) {
if (strcmp(s, cmCacheEntryTypes[i]) == 0) {
- return static_cast<cmStateEnums::CacheEntryType>(i);
+ type = static_cast<cmStateEnums::CacheEntryType>(i);
+ return true;
}
++i;
}
- return cmStateEnums::STRING;
+ return false;
}
bool cmState::IsCacheEntryType(std::string const& key)
{
for (int i = 0; cmCacheEntryTypes[i]; ++i) {
- if (strcmp(key.c_str(), cmCacheEntryTypes[i]) == 0) {
+ if (key == cmCacheEntryTypes[i]) {
return true;
}
}
@@ -107,9 +111,9 @@ bool cmState::LoadCache(const std::string& path, bool internal,
return this->CacheManager->LoadCache(path, internal, excludes, includes);
}
-bool cmState::SaveCache(const std::string& path)
+bool cmState::SaveCache(const std::string& path, cmMessenger* messenger)
{
- return this->CacheManager->SaveCache(path);
+ return this->CacheManager->SaveCache(path, messenger);
}
bool cmState::DeleteCache(const std::string& path)
@@ -132,12 +136,13 @@ const char* cmState::GetCacheEntryValue(std::string const& key) const
{
cmCacheManager::CacheEntry* e = this->CacheManager->GetCacheEntry(key);
if (!e) {
- return CM_NULLPTR;
+ return nullptr;
}
return e->Value.c_str();
}
-const char* cmState::GetInitializedCacheValue(std::string const& key) const
+const std::string* cmState::GetInitializedCacheValue(
+ std::string const& key) const
{
return this->CacheManager->GetInitializedCacheValue(key);
}
@@ -188,7 +193,7 @@ const char* cmState::GetCacheEntryProperty(std::string const& key,
cmCacheManager::CacheIterator it =
this->CacheManager->GetCacheIterator(key.c_str());
if (!it.PropertyExists(propertyName)) {
- return CM_NULLPTR;
+ return nullptr;
}
return it.GetProperty(propertyName);
}
@@ -207,6 +212,39 @@ void cmState::AddCacheEntry(const std::string& key, const char* value,
this->CacheManager->AddCacheEntry(key, value, helpString, type);
}
+bool cmState::DoWriteGlobVerifyTarget() const
+{
+ return this->GlobVerificationManager->DoWriteVerifyTarget();
+}
+
+std::string const& cmState::GetGlobVerifyScript() const
+{
+ return this->GlobVerificationManager->GetVerifyScript();
+}
+
+std::string const& cmState::GetGlobVerifyStamp() const
+{
+ return this->GlobVerificationManager->GetVerifyStamp();
+}
+
+bool cmState::SaveVerificationScript(const std::string& path)
+{
+ return this->GlobVerificationManager->SaveVerificationScript(path);
+}
+
+void cmState::AddGlobCacheEntry(bool recurse, bool listDirectories,
+ bool followSymlinks,
+ const std::string& relative,
+ const std::string& expression,
+ const std::vector<std::string>& files,
+ const std::string& variable,
+ cmListFileBacktrace const& backtrace)
+{
+ this->GlobVerificationManager->AddCacheEntry(
+ recurse, listDirectories, followSymlinks, relative, expression, files,
+ variable, backtrace);
+}
+
void cmState::RemoveCacheEntry(std::string const& key)
{
this->CacheManager->RemoveCacheEntry(key);
@@ -224,13 +262,14 @@ void cmState::RemoveCacheEntryProperty(std::string const& key,
std::string const& propertyName)
{
this->CacheManager->GetCacheIterator(key.c_str())
- .SetProperty(propertyName, (void*)CM_NULLPTR);
+ .SetProperty(propertyName, nullptr);
}
cmStateSnapshot cmState::Reset()
{
this->GlobalProperties.clear();
this->PropertyDefinitions.clear();
+ this->GlobVerificationManager->Reset();
cmStateDetail::PositionType pos = this->SnapshotData.Truncate();
this->ExecutionListFiles.Truncate();
@@ -244,6 +283,10 @@ cmStateSnapshot cmState::Reset()
it->CompileDefinitionsBacktraces.clear();
it->CompileOptions.clear();
it->CompileOptionsBacktraces.clear();
+ it->LinkOptions.clear();
+ it->LinkOptionsBacktraces.clear();
+ it->LinkDirectories.clear();
+ it->LinkDirectoriesBacktraces.clear();
it->DirectoryEnd = pos;
it->NormalTargetNames.clear();
it->Properties.clear();
@@ -259,9 +302,9 @@ cmStateSnapshot cmState::Reset()
{
std::string srcDir =
- cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
+ *cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
std::string binDir =
- cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
+ *cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
this->VarTree.Clear();
pos->Vars = this->VarTree.Push(this->VarTree.Root());
pos->Parent = this->VarTree.Root();
@@ -303,7 +346,7 @@ cmPropertyDefinition const* cmState::GetPropertyDefinition(
this->PropertyDefinitions.find(scope)->second;
return &defs.find(name)->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
bool cmState::IsPropertyDefined(const std::string& name,
@@ -426,17 +469,21 @@ void cmState::AddScriptedCommand(std::string const& name, cmCommand* command)
cmCommand* cmState::GetCommand(std::string const& name) const
{
- std::string sName = cmSystemTools::LowerCase(name);
+ return GetCommandByExactName(cmSystemTools::LowerCase(name));
+}
+
+cmCommand* cmState::GetCommandByExactName(std::string const& name) const
+{
std::map<std::string, cmCommand*>::const_iterator pos;
- pos = this->ScriptedCommands.find(sName);
+ pos = this->ScriptedCommands.find(name);
if (pos != this->ScriptedCommands.end()) {
return pos->second;
}
- pos = this->BuiltinCommands.find(sName);
+ pos = this->BuiltinCommands.find(name);
if (pos != this->BuiltinCommands.end()) {
return pos->second;
}
- return CM_NULLPTR;
+ return nullptr;
}
std::vector<std::string> cmState::GetCommandNames() const
@@ -444,15 +491,11 @@ std::vector<std::string> cmState::GetCommandNames() const
std::vector<std::string> commandNames;
commandNames.reserve(this->BuiltinCommands.size() +
this->ScriptedCommands.size());
- for (std::map<std::string, cmCommand*>::const_iterator cmds =
- this->BuiltinCommands.begin();
- cmds != this->BuiltinCommands.end(); ++cmds) {
- commandNames.push_back(cmds->first);
+ for (auto const& bc : this->BuiltinCommands) {
+ commandNames.push_back(bc.first);
}
- for (std::map<std::string, cmCommand*>::const_iterator cmds =
- this->ScriptedCommands.begin();
- cmds != this->ScriptedCommands.end(); ++cmds) {
- commandNames.push_back(cmds->first);
+ for (auto const& sc : this->ScriptedCommands) {
+ commandNames.push_back(sc.first);
}
std::sort(commandNames.begin(), commandNames.end());
commandNames.erase(std::unique(commandNames.begin(), commandNames.end()),
@@ -460,6 +503,16 @@ std::vector<std::string> cmState::GetCommandNames() const
return commandNames;
}
+void cmState::RemoveBuiltinCommand(std::string const& name)
+{
+ assert(name == cmSystemTools::LowerCase(name));
+ std::map<std::string, cmCommand*>::iterator i =
+ this->BuiltinCommands.find(name);
+ assert(i != this->BuiltinCommands.end());
+ delete i->second;
+ this->BuiltinCommands.erase(i);
+}
+
void cmState::RemoveUserDefinedCommands()
{
cmDeleteAll(this->ScriptedCommands);
@@ -495,14 +548,36 @@ const char* cmState::GetGlobalProperty(const std::string& prop)
std::string langs;
langs = cmJoin(this->EnabledLanguages, ";");
this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
+ } else if (prop == "CMAKE_ROLE") {
+ std::string mode = this->GetModeString();
+ this->SetGlobalProperty("CMAKE_ROLE", mode.c_str());
}
#define STRING_LIST_ELEMENT(F) ";" #F
if (prop == "CMAKE_C_KNOWN_FEATURES") {
- return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
+ return &FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT)[1];
+ }
+ if (prop == "CMAKE_C90_KNOWN_FEATURES") {
+ return &FOR_EACH_C90_FEATURE(STRING_LIST_ELEMENT)[1];
+ }
+ if (prop == "CMAKE_C99_KNOWN_FEATURES") {
+ return &FOR_EACH_C99_FEATURE(STRING_LIST_ELEMENT)[1];
+ }
+ if (prop == "CMAKE_C11_KNOWN_FEATURES") {
+ return &FOR_EACH_C11_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
- return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
+ return &FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT)[1];
+ }
+ if (prop == "CMAKE_CXX98_KNOWN_FEATURES") {
+ return &FOR_EACH_CXX98_FEATURE(STRING_LIST_ELEMENT)[1];
+ }
+ if (prop == "CMAKE_CXX11_KNOWN_FEATURES") {
+ return &FOR_EACH_CXX11_FEATURE(STRING_LIST_ELEMENT)[1];
+ }
+ if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
+ return &FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1];
}
+
#undef STRING_LIST_ELEMENT
return this->GlobalProperties.GetPropertyValue(prop);
}
@@ -518,9 +593,9 @@ void cmState::SetSourceDirectory(std::string const& sourceDirectory)
cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
}
-const char* cmState::GetSourceDirectory() const
+std::string const& cmState::GetSourceDirectory() const
{
- return this->SourceDirectory.c_str();
+ return this->SourceDirectory;
}
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
@@ -549,6 +624,16 @@ bool cmState::UseWindowsVSIDE() const
return this->WindowsVSIDE;
}
+void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
+{
+ this->GhsMultiIDE = ghsMultiIDE;
+}
+
+bool cmState::UseGhsMultiIDE() const
+{
+ return this->GhsMultiIDE;
+}
+
void cmState::SetWatcomWMake(bool watcomWMake)
{
this->WatcomWMake = watcomWMake;
@@ -599,9 +684,43 @@ unsigned int cmState::GetCacheMinorVersion() const
return this->CacheManager->GetCacheMinorVersion();
}
-const char* cmState::GetBinaryDirectory() const
+cmState::Mode cmState::GetMode() const
+{
+ return this->CurrentMode;
+}
+
+std::string cmState::GetModeString() const
+{
+ return ModeToString(this->CurrentMode);
+}
+
+void cmState::SetMode(cmState::Mode mode)
+{
+ this->CurrentMode = mode;
+}
+
+std::string cmState::ModeToString(cmState::Mode mode)
+{
+ switch (mode) {
+ case Project:
+ return "PROJECT";
+ case Script:
+ return "SCRIPT";
+ case FindPackage:
+ return "FIND_PACKAGE";
+ case CTest:
+ return "CTEST";
+ case CPack:
+ return "CPACK";
+ case Unknown:
+ return "UNKNOWN";
+ }
+ return "UNKNOWN";
+}
+
+std::string const& cmState::GetBinaryDirectory() const
{
- return this->BinaryDirectory.c_str();
+ return this->BinaryDirectory;
}
cmStateSnapshot cmState::CreateBaseSnapshot()
@@ -619,6 +738,8 @@ cmStateSnapshot cmState::CreateBaseSnapshot()
pos->IncludeDirectoryPosition = 0;
pos->CompileDefinitionsPosition = 0;
pos->CompileOptionsPosition = 0;
+ pos->LinkOptionsPosition = 0;
+ pos->LinkDirectoriesPosition = 0;
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->Policies = this->PolicyStack.Root();
pos->PolicyRoot = this->PolicyStack.Root();
@@ -770,6 +891,10 @@ cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
prevPos->BuildSystemDirectory->CompileDefinitions.size();
prevPos->CompileOptionsPosition =
prevPos->BuildSystemDirectory->CompileOptions.size();
+ prevPos->LinkOptionsPosition =
+ prevPos->BuildSystemDirectory->LinkOptions.size();
+ prevPos->LinkDirectoriesPosition =
+ prevPos->BuildSystemDirectory->LinkDirectories.size();
prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
@@ -809,8 +934,8 @@ static bool ParseEntryWithoutType(const std::string& entry, std::string& var,
// 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] == '\'') {
+ if (flag && value.size() >= 2 && value.front() == '\'' &&
+ value.back() == '\'') {
value = value.substr(1, value.size() - 2);
}
@@ -842,8 +967,8 @@ bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
// 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] == '\'') {
+ if (flag && value.size() >= 2 && value.front() == '\'' &&
+ value.back() == '\'') {
value = value.substr(1, value.size() - 2);
}
diff --git a/Source/cmState.h b/Source/cmState.h
index e03ad8981..6abe71c0b 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -12,6 +12,7 @@
#include "cmDefinitions.h"
#include "cmLinkedTree.h"
+#include "cmListFileCache.h"
#include "cmPolicies.h"
#include "cmProperty.h"
#include "cmPropertyDefinitionMap.h"
@@ -21,8 +22,10 @@
class cmCacheManager;
class cmCommand;
+class cmGlobVerificationManager;
class cmPropertyDefinition;
class cmStateSnapshot;
+class cmMessenger;
class cmState
{
@@ -32,6 +35,19 @@ public:
cmState();
~cmState();
+ cmState(const cmState&) = delete;
+ cmState& operator=(const cmState&) = delete;
+
+ enum Mode
+ {
+ Unknown,
+ Project,
+ Script,
+ FindPackage,
+ CTest,
+ CPack,
+ };
+
static const char* GetTargetTypeName(cmStateEnums::TargetType targetType);
cmStateSnapshot CreateBaseSnapshot();
@@ -52,6 +68,8 @@ public:
cmStateSnapshot Pop(cmStateSnapshot const& originSnapshot);
static cmStateEnums::CacheEntryType StringToCacheEntryType(const char*);
+ static bool StringToCacheEntryType(const char*,
+ cmStateEnums::CacheEntryType& type);
static const char* CacheEntryTypeToString(cmStateEnums::CacheEntryType);
static bool IsCacheEntryType(std::string const& key);
@@ -59,13 +77,13 @@ public:
std::set<std::string>& excludes,
std::set<std::string>& includes);
- bool SaveCache(const std::string& path);
+ bool SaveCache(const std::string& path, cmMessenger* messenger);
bool DeleteCache(const std::string& path);
std::vector<std::string> GetCacheEntryKeys() const;
const char* GetCacheEntryValue(std::string const& key) const;
- const char* GetInitializedCacheValue(std::string const& key) const;
+ const std::string* GetInitializedCacheValue(std::string const& key) const;
cmStateEnums::CacheEntryType GetCacheEntryType(std::string const& key) const;
void SetCacheEntryValue(std::string const& key, std::string const& value);
void SetCacheValue(std::string const& key, std::string const& value);
@@ -89,7 +107,7 @@ public:
void RemoveCacheEntryProperty(std::string const& key,
std::string const& propertyName);
- ///! Break up a line like VAR:type="value" into var, type and value
+ //! Break up a line like VAR:type="value" into var, type and value
static bool ParseCacheEntry(const std::string& entry, std::string& var,
std::string& value,
cmStateEnums::CacheEntryType& type);
@@ -122,12 +140,17 @@ public:
bool GetIsGeneratorMultiConfig() const;
void SetIsGeneratorMultiConfig(bool b);
+ // Returns a command from its name, case insensitive, or nullptr
cmCommand* GetCommand(std::string const& name) const;
+ // Returns a command from its name, or nullptr
+ cmCommand* GetCommandByExactName(std::string const& name) const;
+
void AddBuiltinCommand(std::string const& name, cmCommand* command);
void AddDisallowedCommand(std::string const& name, cmCommand* command,
cmPolicies::PolicyID policy, const char* message);
void AddUnexpectedCommand(std::string const& name, const char* error);
void AddScriptedCommand(std::string const& name, cmCommand* command);
+ void RemoveBuiltinCommand(std::string const& name);
void RemoveUserDefinedCommands();
std::vector<std::string> GetCommandNames() const;
@@ -137,15 +160,17 @@ public:
const char* GetGlobalProperty(const std::string& prop);
bool GetGlobalPropertyAsBool(const std::string& prop);
- const char* GetSourceDirectory() const;
+ std::string const& GetSourceDirectory() const;
void SetSourceDirectory(std::string const& sourceDirectory);
- const char* GetBinaryDirectory() const;
+ std::string const& GetBinaryDirectory() const;
void SetBinaryDirectory(std::string const& binaryDirectory);
void SetWindowsShell(bool windowsShell);
bool UseWindowsShell() const;
void SetWindowsVSIDE(bool windowsVSIDE);
bool UseWindowsVSIDE() const;
+ void SetGhsMultiIDE(bool ghsMultiIDE);
+ bool UseGhsMultiIDE() const;
void SetWatcomWMake(bool watcomWMake);
bool UseWatcomWMake() const;
void SetMinGWMake(bool minGWMake);
@@ -158,18 +183,36 @@ public:
unsigned int GetCacheMajorVersion() const;
unsigned int GetCacheMinorVersion() const;
+ Mode GetMode() const;
+ std::string GetModeString() const;
+ void SetMode(Mode mode);
+
+ static std::string ModeToString(Mode mode);
+
private:
friend class cmake;
void AddCacheEntry(const std::string& key, const char* value,
const char* helpString,
cmStateEnums::CacheEntryType type);
+ bool DoWriteGlobVerifyTarget() const;
+ std::string const& GetGlobVerifyScript() const;
+ std::string const& GetGlobVerifyStamp() const;
+ bool SaveVerificationScript(const std::string& path);
+ void AddGlobCacheEntry(bool recurse, bool listDirectories,
+ bool followSymlinks, const std::string& relative,
+ const std::string& expression,
+ const std::vector<std::string>& files,
+ const std::string& variable,
+ cmListFileBacktrace const& bt);
+
std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
std::vector<std::string> EnabledLanguages;
std::map<std::string, cmCommand*> BuiltinCommands;
std::map<std::string, cmCommand*> ScriptedCommands;
cmPropertyMap GlobalProperties;
cmCacheManager* CacheManager;
+ cmGlobVerificationManager* GlobVerificationManager;
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>
BuildsystemDirectory;
@@ -182,14 +225,16 @@ private:
std::string SourceDirectory;
std::string BinaryDirectory;
- bool IsInTryCompile;
- bool IsGeneratorMultiConfig;
- bool WindowsShell;
- bool WindowsVSIDE;
- bool WatcomWMake;
- bool MinGWMake;
- bool NMake;
- bool MSYSShell;
+ bool IsInTryCompile = false;
+ bool IsGeneratorMultiConfig = false;
+ bool WindowsShell = false;
+ bool WindowsVSIDE = false;
+ bool GhsMultiIDE = false;
+ bool WatcomWMake = false;
+ bool MinGWMake = false;
+ bool NMake = false;
+ bool MSYSShell = false;
+ Mode CurrentMode = Unknown;
};
#endif
diff --git a/Source/cmStateDirectory.cxx b/Source/cmStateDirectory.cxx
index 46a185848..182d3fe73 100644
--- a/Source/cmStateDirectory.cxx
+++ b/Source/cmStateDirectory.cxx
@@ -6,11 +6,12 @@
#include <algorithm>
#include <assert.h>
#include <iterator>
-#include <map>
#include <utility>
+#include "cmAlgorithms.h"
#include "cmProperty.h"
#include "cmPropertyMap.h"
+#include "cmRange.h"
#include "cmState.h"
#include "cmStatePrivate.h"
#include "cmStateTypes.h"
@@ -41,9 +42,8 @@ void cmStateDirectory::ComputeRelativePathTopSource()
std::string result = snapshots.front().GetDirectory().GetCurrentSource();
- for (std::vector<cmStateSnapshot>::const_iterator it = snapshots.begin() + 1;
- it != snapshots.end(); ++it) {
- std::string currentSource = it->GetDirectory().GetCurrentSource();
+ for (cmStateSnapshot const& snp : cmMakeRange(snapshots).advance(1)) {
+ std::string currentSource = snp.GetDirectory().GetCurrentSource();
if (cmSystemTools::IsSubDirectory(result, currentSource)) {
result = currentSource;
}
@@ -67,9 +67,8 @@ void cmStateDirectory::ComputeRelativePathTopBinary()
std::string result = snapshots.front().GetDirectory().GetCurrentBinary();
- for (std::vector<cmStateSnapshot>::const_iterator it = snapshots.begin() + 1;
- it != snapshots.end(); ++it) {
- std::string currentBinary = it->GetDirectory().GetCurrentBinary();
+ for (cmStateSnapshot const& snp : cmMakeRange(snapshots).advance(1)) {
+ std::string currentBinary = snp.GetDirectory().GetCurrentBinary();
if (cmSystemTools::IsSubDirectory(result, currentBinary)) {
result = currentBinary;
}
@@ -81,13 +80,13 @@ void cmStateDirectory::ComputeRelativePathTopBinary()
if (result.size() < 2 || result.substr(0, 2) != "//") {
this->DirectoryState->RelativePathTopBinary = result;
} else {
- this->DirectoryState->RelativePathTopBinary = "";
+ this->DirectoryState->RelativePathTopBinary.clear();
}
}
-const char* cmStateDirectory::GetCurrentSource() const
+std::string const& cmStateDirectory::GetCurrentSource() const
{
- return this->DirectoryState->Location.c_str();
+ return this->DirectoryState->Location;
}
void cmStateDirectory::SetCurrentSource(std::string const& dir)
@@ -102,9 +101,9 @@ void cmStateDirectory::SetCurrentSource(std::string const& dir)
this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc);
}
-const char* cmStateDirectory::GetCurrentBinary() const
+std::string const& cmStateDirectory::GetCurrentBinary() const
{
- return this->DirectoryState->OutputLocation.c_str();
+ return this->DirectoryState->OutputLocation;
}
void cmStateDirectory::SetCurrentBinary(std::string const& dir)
@@ -119,14 +118,14 @@ void cmStateDirectory::SetCurrentBinary(std::string const& dir)
this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc);
}
-const char* cmStateDirectory::GetRelativePathTopSource() const
+std::string const& cmStateDirectory::GetRelativePathTopSource() const
{
- return this->DirectoryState->RelativePathTopSource.c_str();
+ return this->DirectoryState->RelativePathTopSource;
}
-const char* cmStateDirectory::GetRelativePathTopBinary() const
+std::string const& cmStateDirectory::GetRelativePathTopBinary() const
{
- return this->DirectoryState->RelativePathTopBinary.c_str();
+ return this->DirectoryState->RelativePathTopBinary;
}
void cmStateDirectory::SetRelativePathTopSource(const char* dir)
@@ -139,6 +138,32 @@ void cmStateDirectory::SetRelativePathTopBinary(const char* dir)
this->DirectoryState->RelativePathTopBinary = dir;
}
+bool cmStateDirectory::ContainsBoth(std::string const& local_path,
+ std::string const& remote_path) const
+{
+ auto PathEqOrSubDir = [](std::string const& a, std::string const& b) {
+ return (cmSystemTools::ComparePath(a, b) ||
+ cmSystemTools::IsSubDirectory(a, b));
+ };
+
+ bool bothInBinary = PathEqOrSubDir(local_path, GetRelativePathTopBinary()) &&
+ PathEqOrSubDir(remote_path, GetRelativePathTopBinary());
+
+ bool bothInSource = PathEqOrSubDir(local_path, GetRelativePathTopSource()) &&
+ PathEqOrSubDir(remote_path, GetRelativePathTopSource());
+
+ return bothInBinary || bothInSource;
+}
+
+std::string cmStateDirectory::ConvertToRelPathIfNotContained(
+ std::string const& local_path, std::string const& remote_path) const
+{
+ if (!this->ContainsBoth(local_path, remote_path)) {
+ return remote_path;
+ }
+ return cmSystemTools::ForceToRelativePath(local_path, remote_path);
+}
+
cmStateDirectory::cmStateDirectory(
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator iter,
const cmStateSnapshot& snapshot)
@@ -361,6 +386,106 @@ void cmStateDirectory::ClearCompileOptions()
this->Snapshot_.Position->CompileOptionsPosition);
}
+cmStringRange cmStateDirectory::GetLinkOptionsEntries() const
+{
+ return GetPropertyContent(this->DirectoryState->LinkOptions,
+ this->Snapshot_.Position->LinkOptionsPosition);
+}
+
+cmBacktraceRange cmStateDirectory::GetLinkOptionsEntryBacktraces() const
+{
+ return GetPropertyBacktraces(this->DirectoryState->LinkOptions,
+ this->DirectoryState->LinkOptionsBacktraces,
+ this->Snapshot_.Position->LinkOptionsPosition);
+}
+
+void cmStateDirectory::AppendLinkOptionsEntry(const std::string& vec,
+ const cmListFileBacktrace& lfbt)
+{
+ AppendEntry(this->DirectoryState->LinkOptions,
+ this->DirectoryState->LinkOptionsBacktraces,
+ this->Snapshot_.Position->LinkOptionsPosition, vec, lfbt);
+}
+
+void cmStateDirectory::SetLinkOptions(const std::string& vec,
+ const cmListFileBacktrace& lfbt)
+{
+ SetContent(this->DirectoryState->LinkOptions,
+ this->DirectoryState->LinkOptionsBacktraces,
+ this->Snapshot_.Position->LinkOptionsPosition, vec, lfbt);
+}
+
+void cmStateDirectory::ClearLinkOptions()
+{
+ ClearContent(this->DirectoryState->LinkOptions,
+ this->DirectoryState->LinkOptionsBacktraces,
+ this->Snapshot_.Position->LinkOptionsPosition);
+}
+
+cmStringRange cmStateDirectory::GetLinkDirectoriesEntries() const
+{
+ return GetPropertyContent(this->DirectoryState->LinkDirectories,
+ this->Snapshot_.Position->LinkDirectoriesPosition);
+}
+
+cmBacktraceRange cmStateDirectory::GetLinkDirectoriesEntryBacktraces() const
+{
+ return GetPropertyBacktraces(
+ this->DirectoryState->LinkDirectories,
+ this->DirectoryState->LinkDirectoriesBacktraces,
+ this->Snapshot_.Position->LinkDirectoriesPosition);
+}
+
+void cmStateDirectory::AppendLinkDirectoriesEntry(
+ const std::string& vec, const cmListFileBacktrace& lfbt)
+{
+ AppendEntry(this->DirectoryState->LinkDirectories,
+ this->DirectoryState->LinkDirectoriesBacktraces,
+ this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt);
+}
+void cmStateDirectory::PrependLinkDirectoriesEntry(
+ const std::string& vec, const cmListFileBacktrace& lfbt)
+{
+ std::vector<std::string>::iterator entryEnd =
+ this->DirectoryState->LinkDirectories.begin() +
+ this->Snapshot_.Position->LinkDirectoriesPosition;
+
+ std::vector<std::string>::reverse_iterator rend =
+ this->DirectoryState->LinkDirectories.rend();
+ std::vector<std::string>::reverse_iterator rbegin =
+ cmMakeReverseIterator(entryEnd);
+ rbegin = std::find(rbegin, rend, cmPropertySentinal);
+
+ std::vector<std::string>::iterator entryIt = rbegin.base();
+ std::vector<std::string>::iterator entryBegin =
+ this->DirectoryState->LinkDirectories.begin();
+
+ std::vector<cmListFileBacktrace>::iterator btIt =
+ this->DirectoryState->LinkDirectoriesBacktraces.begin() +
+ std::distance(entryBegin, entryIt);
+
+ this->DirectoryState->LinkDirectories.insert(entryIt, vec);
+ this->DirectoryState->LinkDirectoriesBacktraces.insert(btIt, lfbt);
+
+ this->Snapshot_.Position->LinkDirectoriesPosition =
+ this->DirectoryState->LinkDirectories.size();
+}
+
+void cmStateDirectory::SetLinkDirectories(const std::string& vec,
+ const cmListFileBacktrace& lfbt)
+{
+ SetContent(this->DirectoryState->LinkDirectories,
+ this->DirectoryState->LinkDirectoriesBacktraces,
+ this->Snapshot_.Position->LinkDirectoriesPosition, vec, lfbt);
+}
+
+void cmStateDirectory::ClearLinkDirectories()
+{
+ ClearContent(this->DirectoryState->LinkDirectories,
+ this->DirectoryState->LinkDirectoriesBacktraces,
+ this->Snapshot_.Position->LinkDirectoriesPosition);
+}
+
void cmStateDirectory::SetProperty(const std::string& prop, const char* value,
cmListFileBacktrace const& lfbt)
{
@@ -388,6 +513,22 @@ void cmStateDirectory::SetProperty(const std::string& prop, const char* value,
this->SetCompileDefinitions(value, lfbt);
return;
}
+ if (prop == "LINK_OPTIONS") {
+ if (!value) {
+ this->ClearLinkOptions();
+ return;
+ }
+ this->SetLinkOptions(value, lfbt);
+ return;
+ }
+ if (prop == "LINK_DIRECTORIES") {
+ if (!value) {
+ this->ClearLinkDirectories();
+ return;
+ }
+ this->SetLinkDirectories(value, lfbt);
+ return;
+ }
this->DirectoryState->Properties.SetProperty(prop, value);
}
@@ -408,6 +549,14 @@ void cmStateDirectory::AppendProperty(const std::string& prop,
this->AppendCompileDefinitionsEntry(value, lfbt);
return;
}
+ if (prop == "LINK_OPTIONS") {
+ this->AppendLinkOptionsEntry(value, lfbt);
+ return;
+ }
+ if (prop == "LINK_DIRECTORIES") {
+ this->AppendLinkDirectoriesEntry(value, lfbt);
+ return;
+ }
this->DirectoryState->Properties.AppendProperty(prop, value, asString);
}
@@ -423,11 +572,11 @@ const char* cmStateDirectory::GetProperty(const std::string& prop,
bool chain) const
{
static std::string output;
- output = "";
+ output.clear();
if (prop == "PARENT_DIRECTORY") {
cmStateSnapshot parent = this->Snapshot_.GetBuildsystemDirectoryParent();
if (parent.IsValid()) {
- return parent.GetDirectory().GetCurrentSource();
+ return parent.GetDirectory().GetCurrentSource().c_str();
}
return "";
}
@@ -443,9 +592,9 @@ const char* cmStateDirectory::GetProperty(const std::string& prop,
std::vector<std::string> child_dirs;
std::vector<cmStateSnapshot> const& children =
this->DirectoryState->Children;
- for (std::vector<cmStateSnapshot>::const_iterator ci = children.begin();
- ci != children.end(); ++ci) {
- child_dirs.push_back(ci->GetDirectory().GetCurrentSource());
+ child_dirs.reserve(children.size());
+ for (cmStateSnapshot const& ci : children) {
+ child_dirs.push_back(ci.GetDirectory().GetCurrentSource());
}
output = cmJoin(child_dirs, ";");
return output.c_str();
@@ -472,9 +621,7 @@ const char* cmStateDirectory::GetProperty(const std::string& prop,
}
if (prop == "VARIABLES") {
std::vector<std::string> res = this->Snapshot_.ClosureKeys();
- std::vector<std::string> cacheKeys =
- this->Snapshot_.State->GetCacheEntryKeys();
- res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
+ cmAppend(res, this->Snapshot_.State->GetCacheEntryKeys());
std::sort(res.begin(), res.end());
output = cmJoin(res, ";");
return output.c_str();
@@ -491,6 +638,14 @@ const char* cmStateDirectory::GetProperty(const std::string& prop,
output = cmJoin(this->GetCompileDefinitionsEntries(), ";");
return output.c_str();
}
+ if (prop == "LINK_OPTIONS") {
+ output = cmJoin(this->GetLinkOptionsEntries(), ";");
+ return output.c_str();
+ }
+ if (prop == "LINK_DIRECTORIES") {
+ output = cmJoin(this->GetLinkDirectoriesEntries(), ";");
+ return output.c_str();
+ }
const char* retVal = this->DirectoryState->Properties.GetPropertyValue(prop);
if (!retVal && chain) {
@@ -514,10 +669,8 @@ std::vector<std::string> cmStateDirectory::GetPropertyKeys() const
{
std::vector<std::string> keys;
keys.reserve(this->DirectoryState->Properties.size());
- for (cmPropertyMap::const_iterator it =
- this->DirectoryState->Properties.begin();
- it != this->DirectoryState->Properties.end(); ++it) {
- keys.push_back(it->first);
+ for (auto const& it : this->DirectoryState->Properties) {
+ keys.push_back(it.first);
}
return keys;
}
diff --git a/Source/cmStateDirectory.h b/Source/cmStateDirectory.h
index 79bb36943..69565940d 100644
--- a/Source/cmStateDirectory.h
+++ b/Source/cmStateDirectory.h
@@ -22,16 +22,22 @@ class cmStateDirectory
cmStateSnapshot const& snapshot);
public:
- const char* GetCurrentSource() const;
+ std::string const& GetCurrentSource() const;
void SetCurrentSource(std::string const& dir);
- const char* GetCurrentBinary() const;
+ std::string const& GetCurrentBinary() const;
void SetCurrentBinary(std::string const& dir);
- const char* GetRelativePathTopSource() const;
- const char* GetRelativePathTopBinary() const;
+ std::string const& GetRelativePathTopSource() const;
+ std::string const& GetRelativePathTopBinary() const;
void SetRelativePathTopSource(const char* dir);
void SetRelativePathTopBinary(const char* dir);
+ bool ContainsBoth(std::string const& local_path,
+ std::string const& remote_path) const;
+
+ std::string ConvertToRelPathIfNotContained(
+ std::string const& local_path, std::string const& remote_path) const;
+
cmStringRange GetIncludeDirectoriesEntries() const;
cmBacktraceRange GetIncludeDirectoriesEntryBacktraces() const;
void AppendIncludeDirectoriesEntry(std::string const& vec,
@@ -58,6 +64,23 @@ public:
cmListFileBacktrace const& lfbt);
void ClearCompileOptions();
+ cmStringRange GetLinkOptionsEntries() const;
+ cmBacktraceRange GetLinkOptionsEntryBacktraces() const;
+ void AppendLinkOptionsEntry(std::string const& vec,
+ cmListFileBacktrace const& lfbt);
+ void PrependLinkDirectoriesEntry(std::string const& vec,
+ cmListFileBacktrace const& lfbt);
+ void SetLinkOptions(std::string const& vec, cmListFileBacktrace const& lfbt);
+ void ClearLinkOptions();
+
+ cmStringRange GetLinkDirectoriesEntries() const;
+ cmBacktraceRange GetLinkDirectoriesEntryBacktraces() const;
+ void AppendLinkDirectoriesEntry(std::string const& vec,
+ cmListFileBacktrace const& lfbt);
+ void SetLinkDirectories(std::string const& vec,
+ cmListFileBacktrace const& lfbt);
+ void ClearLinkDirectories();
+
void SetProperty(const std::string& prop, const char* value,
cmListFileBacktrace const& lfbt);
void AppendProperty(const std::string& prop, const char* value,
diff --git a/Source/cmStatePrivate.h b/Source/cmStatePrivate.h
index f36ee37ea..ec0ed6c93 100644
--- a/Source/cmStatePrivate.h
+++ b/Source/cmStatePrivate.h
@@ -42,14 +42,15 @@ struct cmStateDetail::SnapshotDataType
std::vector<std::string>::size_type IncludeDirectoryPosition;
std::vector<std::string>::size_type CompileDefinitionsPosition;
std::vector<std::string>::size_type CompileOptionsPosition;
+ std::vector<std::string>::size_type LinkOptionsPosition;
+ std::vector<std::string>::size_type LinkDirectoriesPosition;
};
struct cmStateDetail::PolicyStackEntry : public cmPolicies::PolicyMap
{
typedef cmPolicies::PolicyMap derived;
PolicyStackEntry(bool w = false)
- : derived()
- , Weak(w)
+ : Weak(w)
{
}
PolicyStackEntry(derived const& d, bool w)
@@ -84,6 +85,12 @@ struct cmStateDetail::BuildsystemDirectoryStateType
std::vector<std::string> CompileOptions;
std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
+ std::vector<std::string> LinkOptions;
+ std::vector<cmListFileBacktrace> LinkOptionsBacktraces;
+
+ std::vector<std::string> LinkDirectories;
+ std::vector<cmListFileBacktrace> LinkDirectoriesBacktraces;
+
std::vector<std::string> NormalTargetNames;
std::string ProjectName;
diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx
index 77413c7b5..63bec710b 100644
--- a/Source/cmStateSnapshot.cxx
+++ b/Source/cmStateSnapshot.cxx
@@ -6,7 +6,7 @@
#include <algorithm>
#include <assert.h>
#include <iterator>
-#include <stdio.h>
+#include <string>
#include "cmAlgorithms.h"
#include "cmDefinitions.h"
@@ -16,19 +16,17 @@
#include "cmStateDirectory.h"
#include "cmStatePrivate.h"
#include "cmVersion.h"
-#include "cmake.h"
#if !defined(_WIN32)
-#include <sys/utsname.h>
+# include <sys/utsname.h>
#endif
#if defined(__CYGWIN__)
-#include "cmSystemTools.h"
+# include "cmSystemTools.h"
#endif
cmStateSnapshot::cmStateSnapshot(cmState* state)
: State(state)
- , Position()
{
}
@@ -66,6 +64,12 @@ bool cmStateSnapshot::IsValid() const
: false;
}
+cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectory() const
+{
+ return cmStateSnapshot(this->State,
+ this->Position->BuildSystemDirectory->DirectoryEnd);
+}
+
cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectoryParent() const
{
cmStateSnapshot snapshot;
@@ -160,8 +164,8 @@ void cmStateSnapshot::SetPolicy(cmPolicies::PolicyID id,
}
}
-cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(
- cmPolicies::PolicyID id) const
+cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(cmPolicies::PolicyID id,
+ bool parent_scope) const
{
cmPolicies::PolicyStatus status = cmPolicies::GetPolicyStatus(id);
@@ -180,6 +184,10 @@ cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(
cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator root =
dir->DirectoryEnd->PolicyRoot;
for (; leaf != root; ++leaf) {
+ if (parent_scope) {
+ parent_scope = false;
+ continue;
+ }
if (leaf->IsDefined(id)) {
status = leaf->Get(id);
return status;
@@ -200,7 +208,8 @@ bool cmStateSnapshot::HasDefinedPolicyCMP0011()
return !this->Position->Policies->IsEmpty();
}
-const char* cmStateSnapshot::GetDefinition(std::string const& name) const
+std::string const* cmStateSnapshot::GetDefinition(
+ std::string const& name) const
{
assert(this->Position->Vars.IsValid());
return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root);
@@ -220,7 +229,7 @@ void cmStateSnapshot::SetDefinition(std::string const& name,
void cmStateSnapshot::RemoveDefinition(std::string const& name)
{
- this->Position->Vars->Set(name, CM_NULLPTR);
+ this->Position->Vars->Set(name, nullptr);
}
std::vector<std::string> cmStateSnapshot::UnusedKeys() const
@@ -328,19 +337,17 @@ void cmStateSnapshot::SetDefaultDefinitions()
this->SetDefinition("CMAKE_HOST_SOLARIS", "1");
#endif
- char temp[1024];
- sprintf(temp, "%d", cmVersion::GetMinorVersion());
- this->SetDefinition("CMAKE_MINOR_VERSION", temp);
- sprintf(temp, "%d", cmVersion::GetMajorVersion());
- this->SetDefinition("CMAKE_MAJOR_VERSION", temp);
- sprintf(temp, "%d", cmVersion::GetPatchVersion());
- this->SetDefinition("CMAKE_PATCH_VERSION", temp);
- sprintf(temp, "%d", cmVersion::GetTweakVersion());
- this->SetDefinition("CMAKE_TWEAK_VERSION", temp);
+ this->SetDefinition("CMAKE_MAJOR_VERSION",
+ std::to_string(cmVersion::GetMajorVersion()));
+ this->SetDefinition("CMAKE_MINOR_VERSION",
+ std::to_string(cmVersion::GetMinorVersion()));
+ this->SetDefinition("CMAKE_PATCH_VERSION",
+ std::to_string(cmVersion::GetPatchVersion()));
+ this->SetDefinition("CMAKE_TWEAK_VERSION",
+ std::to_string(cmVersion::GetTweakVersion()));
this->SetDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
- this->SetDefinition("CMAKE_FILES_DIRECTORY",
- cmake::GetCMakeFilesDirectory());
+ this->SetDefinition("CMAKE_FILES_DIRECTORY", "/CMakeFiles");
// Setup the default include file regular expression (match everything).
this->Position->BuildSystemDirectory->Properties.SetProperty(
@@ -386,6 +393,26 @@ void cmStateSnapshot::InitializeFromParent()
parent->BuildSystemDirectory->CompileOptionsBacktraces,
this->Position->BuildSystemDirectory->CompileOptionsBacktraces,
this->Position->CompileOptionsPosition);
+
+ InitializeContentFromParent(
+ parent->BuildSystemDirectory->LinkOptions,
+ this->Position->BuildSystemDirectory->LinkOptions,
+ parent->BuildSystemDirectory->LinkOptionsBacktraces,
+ this->Position->BuildSystemDirectory->LinkOptionsBacktraces,
+ this->Position->LinkOptionsPosition);
+
+ InitializeContentFromParent(
+ parent->BuildSystemDirectory->LinkDirectories,
+ this->Position->BuildSystemDirectory->LinkDirectories,
+ parent->BuildSystemDirectory->LinkDirectoriesBacktraces,
+ this->Position->BuildSystemDirectory->LinkDirectoriesBacktraces,
+ this->Position->LinkDirectoriesPosition);
+
+ const char* include_regex =
+ parent->BuildSystemDirectory->Properties.GetPropertyValue(
+ "INCLUDE_REGULAR_EXPRESSION");
+ this->Position->BuildSystemDirectory->Properties.SetProperty(
+ "INCLUDE_REGULAR_EXPRESSION", include_regex);
}
cmState* cmStateSnapshot::GetState() const
@@ -410,8 +437,8 @@ std::string cmStateSnapshot::GetProjectName() const
void cmStateSnapshot::InitializeFromParent_ForSubdirsCommand()
{
- std::string currentSrcDir = this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
- std::string currentBinDir = this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
+ std::string currentSrcDir = *this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
+ std::string currentBinDir = *this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
this->InitializeFromParent();
this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h
index 6293803b9..c315f4851 100644
--- a/Source/cmStateSnapshot.h
+++ b/Source/cmStateSnapshot.h
@@ -19,10 +19,10 @@ class cmStateDirectory;
class cmStateSnapshot
{
public:
- cmStateSnapshot(cmState* state = CM_NULLPTR);
+ cmStateSnapshot(cmState* state = nullptr);
cmStateSnapshot(cmState* state, cmStateDetail::PositionType position);
- const char* GetDefinition(std::string const& name) const;
+ std::string const* GetDefinition(std::string const& name) const;
bool IsInitialized(std::string const& name) const;
void SetDefinition(std::string const& name, std::string const& value);
void RemoveDefinition(std::string const& name);
@@ -37,13 +37,15 @@ public:
std::vector<cmStateSnapshot> GetChildren();
bool IsValid() const;
+ cmStateSnapshot GetBuildsystemDirectory() const;
cmStateSnapshot GetBuildsystemDirectoryParent() const;
cmStateSnapshot GetCallStackParent() const;
cmStateSnapshot GetCallStackBottom() const;
cmStateEnums::SnapshotType GetType() const;
void SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
- cmPolicies::PolicyStatus GetPolicy(cmPolicies::PolicyID id) const;
+ cmPolicies::PolicyStatus GetPolicy(cmPolicies::PolicyID id,
+ bool parent_scope = false) const;
bool HasDefinedPolicyCMP0011();
void PushPolicy(cmPolicies::PolicyMap const& entry, bool weak);
bool PopPolicy();
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 7a097ba21..998f90415 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -1,9 +1,14 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
+#define _SCL_SECURE_NO_WARNINGS
+
#include "cmStringCommand.h"
#include "cmsys/RegularExpression.hxx"
+#include <algorithm>
#include <ctype.h>
+#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
@@ -12,10 +17,12 @@
#include "cmCryptoHash.h"
#include "cmGeneratorExpression.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmRange.h"
+#include "cmStringReplaceHelper.h"
#include "cmSystemTools.h"
#include "cmTimestamp.h"
#include "cmUuid.h"
-#include "cm_auto_ptr.hxx"
class cmExecutionStatus;
@@ -62,15 +69,24 @@ bool cmStringCommand::InitialPass(std::vector<std::string> const& args,
if (subCommand == "APPEND") {
return this->HandleAppendCommand(args);
}
+ if (subCommand == "PREPEND") {
+ return this->HandlePrependCommand(args);
+ }
if (subCommand == "CONCAT") {
return this->HandleConcatCommand(args);
}
+ if (subCommand == "JOIN") {
+ return this->HandleJoinCommand(args);
+ }
if (subCommand == "SUBSTRING") {
return this->HandleSubstringCommand(args);
}
if (subCommand == "STRIP") {
return this->HandleStripCommand(args);
}
+ if (subCommand == "REPEAT") {
+ return this->HandleRepeatCommand(args);
+ }
if (subCommand == "RANDOM") {
return this->HandleRandomCommand(args);
}
@@ -105,8 +121,8 @@ bool cmStringCommand::HandleHashCommand(std::vector<std::string> const& args)
return false;
}
- CM_AUTO_PTR<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str()));
- if (hash.get()) {
+ std::unique_ptr<cmCryptoHash> hash(cmCryptoHash::New(args[0].c_str()));
+ if (hash) {
std::string out = hash->HashString(args[2]);
this->Makefile->AddDefinition(args[1], out.c_str());
return true;
@@ -149,7 +165,7 @@ bool cmStringCommand::HandleAsciiCommand(std::vector<std::string> const& args)
return false;
}
std::string::size_type cc;
- std::string const& outvar = args[args.size() - 1];
+ std::string const& outvar = args.back();
std::string output;
for (cc = 1; cc < args.size() - 1; cc++) {
int ch = atoi(args[cc].c_str());
@@ -266,7 +282,7 @@ bool cmStringCommand::RegexMatch(std::vector<std::string> const& args)
// Scan through the input for all matches.
std::string output;
- if (re.find(input.c_str())) {
+ if (re.find(input)) {
this->Makefile->StoreMatches(re);
std::string::size_type l = re.start();
std::string::size_type r = re.end();
@@ -309,6 +325,7 @@ bool cmStringCommand::RegexMatchAll(std::vector<std::string> const& args)
std::string output;
const char* p = input.c_str();
while (re.find(p)) {
+ this->Makefile->ClearMatches();
this->Makefile->StoreMatches(re);
std::string::size_type l = re.start();
std::string::size_type r = re.end();
@@ -337,46 +354,17 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
std::string const& regex = args[2];
std::string const& replace = args[3];
std::string const& outvar = args[4];
+ cmStringReplaceHelper replaceHelper(regex, replace, this->Makefile);
- // 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;
+ if (!replaceHelper.IsReplaceExpressionValid()) {
+ this->SetError(
+ "sub-command REGEX, mode REPLACE: " + replaceHelper.GetError() + ".");
+ return false;
}
this->Makefile->ClearMatches();
- // Compile the regular expression.
- cmsys::RegularExpression re;
- if (!re.compile(regex.c_str())) {
+
+ if (!replaceHelper.IsRegularExpressionValid()) {
std::string e =
"sub-command REGEX, mode REPLACE failed to compile regex \"" + regex +
"\".";
@@ -385,59 +373,16 @@ bool cmStringCommand::RegexReplace(std::vector<std::string> const& args)
}
// Concatenate all the last arguments together.
- std::string input = cmJoin(cmMakeRange(args).advance(5), std::string());
-
- // Scan through the input for all matches.
+ const std::string input =
+ cmJoin(cmMakeRange(args).advance(5), std::string());
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;
+ if (!replaceHelper.Replace(input, output)) {
+ this->SetError(
+ "sub-command REGEX, mode REPLACE: " + replaceHelper.GetError() + ".");
+ return false;
}
- // 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;
@@ -641,6 +586,30 @@ bool cmStringCommand::HandleAppendCommand(std::vector<std::string> const& args)
return true;
}
+bool cmStringCommand::HandlePrependCommand(
+ std::vector<std::string> const& args)
+{
+ if (args.size() < 2) {
+ this->SetError("sub-command PREPEND requires at least one argument.");
+ return false;
+ }
+
+ // Skip if nothing to prepend.
+ if (args.size() < 3) {
+ return true;
+ }
+
+ const std::string& variable = args[1];
+
+ std::string value = cmJoin(cmMakeRange(args).advance(2), std::string());
+ const char* oldValue = this->Makefile->GetDefinition(variable);
+ if (oldValue) {
+ value += oldValue;
+ }
+ this->Makefile->AddDefinition(variable, value.c_str());
+ return true;
+}
+
bool cmStringCommand::HandleConcatCommand(std::vector<std::string> const& args)
{
if (args.size() < 2) {
@@ -648,8 +617,26 @@ bool cmStringCommand::HandleConcatCommand(std::vector<std::string> const& args)
return false;
}
- std::string const& variableName = args[1];
- std::string value = cmJoin(cmMakeRange(args).advance(2), std::string());
+ return this->joinImpl(args, std::string(), 1);
+}
+
+bool cmStringCommand::HandleJoinCommand(std::vector<std::string> const& args)
+{
+ if (args.size() < 3) {
+ this->SetError("sub-command JOIN requires at least two arguments.");
+ return false;
+ }
+
+ return this->joinImpl(args, args[1], 2);
+}
+
+bool cmStringCommand::joinImpl(std::vector<std::string> const& args,
+ std::string const& glue, const size_t varIdx)
+{
+ std::string const& variableName = args[varIdx];
+ // NOTE Items to concat/join placed right after the variable for
+ // both `CONCAT` and `JOIN` sub-commands.
+ std::string value = cmJoin(cmMakeRange(args).advance(varIdx + 1), glue);
this->Makefile->AddDefinition(variableName, value.c_str());
return true;
@@ -730,6 +717,59 @@ bool cmStringCommand::HandleStripCommand(std::vector<std::string> const& args)
return true;
}
+bool cmStringCommand::HandleRepeatCommand(std::vector<std::string> const& args)
+{
+ // `string(REPEAT "<str>" <times> OUTPUT_VARIABLE)`
+ enum ArgPos : std::size_t
+ {
+ SUB_COMMAND,
+ VALUE,
+ TIMES,
+ OUTPUT_VARIABLE,
+ TOTAL_ARGS
+ };
+
+ if (args.size() != ArgPos::TOTAL_ARGS) {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "sub-command REPEAT requires three arguments.");
+ return true;
+ }
+
+ unsigned long times;
+ if (!cmSystemTools::StringToULong(args[ArgPos::TIMES].c_str(), &times)) {
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ "repeat count is not a positive number.");
+ return true;
+ }
+
+ const auto& stringValue = args[ArgPos::VALUE];
+ const auto& variableName = args[ArgPos::OUTPUT_VARIABLE];
+ const auto inStringLength = stringValue.size();
+
+ std::string result;
+ switch (inStringLength) {
+ case 0u:
+ // Nothing to do for zero length input strings
+ break;
+ case 1u:
+ // NOTE If the string to repeat consists of the only character,
+ // use the appropriate constructor.
+ result = std::string(times, stringValue[0]);
+ break;
+ default:
+ result = std::string(inStringLength * times, char{});
+ for (auto i = 0u; i < times; ++i) {
+ std::copy(cm::cbegin(stringValue), cm::cend(stringValue),
+ &result[i * inStringLength]);
+ }
+ break;
+ }
+
+ this->Makefile->AddDefinition(variableName, result.c_str());
+ return true;
+}
+
bool cmStringCommand::HandleRandomCommand(std::vector<std::string> const& args)
{
if (args.size() < 2 || args.size() == 3 || args.size() == 5) {
@@ -777,7 +817,7 @@ bool cmStringCommand::HandleRandomCommand(std::vector<std::string> const& args)
this->SetError("sub-command RANDOM invoked with bad length.");
return false;
}
- const std::string& variableName = args[args.size() - 1];
+ const std::string& variableName = args.back();
std::vector<char> result;
@@ -787,14 +827,13 @@ bool cmStringCommand::HandleRandomCommand(std::vector<std::string> const& args)
}
const char* alphaPtr = alphabet.c_str();
- int cc;
- for (cc = 0; cc < length; cc++) {
- int idx = (int)(sizeofAlphabet * rand() / (RAND_MAX + 1.0));
+ for (int cc = 0; cc < length; cc++) {
+ int idx = static_cast<int>(sizeofAlphabet * rand() / (RAND_MAX + 1.0));
result.push_back(*(alphaPtr + idx));
}
result.push_back(0);
- this->Makefile->AddDefinition(variableName, &*result.begin());
+ this->Makefile->AddDefinition(variableName, result.data());
return true;
}
diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h
index 88015ad5e..acde60549 100644
--- a/Source/cmStringCommand.h
+++ b/Source/cmStringCommand.h
@@ -3,8 +3,9 @@
#ifndef cmStringCommand_h
#define cmStringCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include <cstddef>
#include <string>
#include <vector>
@@ -22,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmStringCommand; }
+ cmCommand* Clone() override { return new cmStringCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
bool HandleConfigureCommand(std::vector<std::string> const& args);
@@ -46,8 +47,11 @@ protected:
bool HandleLengthCommand(std::vector<std::string> const& args);
bool HandleSubstringCommand(std::vector<std::string> const& args);
bool HandleAppendCommand(std::vector<std::string> const& args);
+ bool HandlePrependCommand(std::vector<std::string> const& args);
bool HandleConcatCommand(std::vector<std::string> const& args);
+ bool HandleJoinCommand(std::vector<std::string> const& args);
bool HandleStripCommand(std::vector<std::string> const& args);
+ bool HandleRepeatCommand(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);
@@ -55,28 +59,8 @@ protected:
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;
- };
+ bool joinImpl(std::vector<std::string> const& args, std::string const& glue,
+ size_t varIdx);
};
#endif
diff --git a/Source/cmSubdirCommand.cxx b/Source/cmSubdirCommand.cxx
index 3727dfa25..9d36228d2 100644
--- a/Source/cmSubdirCommand.cxx
+++ b/Source/cmSubdirCommand.cxx
@@ -18,36 +18,34 @@ bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args,
bool res = true;
bool excludeFromAll = false;
- for (std::vector<std::string>::const_iterator i = args.begin();
- i != args.end(); ++i) {
- if (*i == "EXCLUDE_FROM_ALL") {
+ for (std::string const& i : args) {
+ if (i == "EXCLUDE_FROM_ALL") {
excludeFromAll = true;
continue;
}
- if (*i == "PREORDER") {
+ if (i == "PREORDER") {
// Ignored
continue;
}
// if they specified a relative path then compute the full
std::string srcPath =
- std::string(this->Makefile->GetCurrentSourceDirectory()) + "/" + *i;
+ this->Makefile->GetCurrentSourceDirectory() + "/" + i;
if (cmSystemTools::FileIsDirectory(srcPath)) {
std::string binPath =
- std::string(this->Makefile->GetCurrentBinaryDirectory()) + "/" + *i;
+ this->Makefile->GetCurrentBinaryDirectory() + "/" + i;
this->Makefile->AddSubDirectory(srcPath, binPath, excludeFromAll, false);
}
// otherwise it is a full path
- else if (cmSystemTools::FileIsDirectory(*i)) {
+ else if (cmSystemTools::FileIsDirectory(i)) {
// 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->GetCurrentBinaryDirectory()) + "/" +
- cmSystemTools::GetFilenameName(*i);
- this->Makefile->AddSubDirectory(*i, binPath, excludeFromAll, false);
+ std::string binPath = this->Makefile->GetCurrentBinaryDirectory() + "/" +
+ cmSystemTools::GetFilenameName(i);
+ this->Makefile->AddSubDirectory(i, binPath, excludeFromAll, false);
} else {
std::string error = "Incorrect SUBDIRS command. Directory: ";
- error += *i + " does not exist.";
+ error += i + " does not exist.";
this->SetError(error);
res = false;
}
diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h
index a2af0fd58..adab75711 100644
--- a/Source/cmSubdirCommand.h
+++ b/Source/cmSubdirCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSubdirCommand_h
#define cmSubdirCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -25,14 +25,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmSubdirCommand; }
+ cmCommand* Clone() override { return new cmSubdirCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmSubdirDependsCommand.h b/Source/cmSubdirDependsCommand.h
index d8ea9284f..2db28c66c 100644
--- a/Source/cmSubdirDependsCommand.h
+++ b/Source/cmSubdirDependsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmSubdirDependsCommand_h
#define cmSubdirDependsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,9 +15,9 @@ class cmExecutionStatus;
class cmSubdirDependsCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmSubdirDependsCommand; }
+ cmCommand* Clone() override { return new cmSubdirDependsCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index f7192e0b6..15014811e 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -3,28 +3,33 @@
#include "cmSystemTools.h"
#include "cmAlgorithms.h"
+#include "cmDuration.h"
#include "cmProcessOutput.h"
-#include "cm_sys_stat.h"
+#include "cmRange.h"
+#include "cm_uv.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmArchiveWrite.h"
-#include "cmLocale.h"
-#include "cm_libarchive.h"
-#ifndef __LA_INT64_T
-#define __LA_INT64_T la_int64_t
-#endif
+# include "cmArchiveWrite.h"
+# include "cmLocale.h"
+# include "cm_libarchive.h"
+# ifndef __LA_INT64_T
+# define __LA_INT64_T la_int64_t
+# endif
+# ifndef __LA_SSIZE_T
+# define __LA_SSIZE_T la_ssize_t
+# endif
#endif
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmCryptoHash.h"
+# include "cmCryptoHash.h"
#endif
#if defined(CMAKE_USE_ELF_PARSER)
-#include "cmELF.h"
+# include "cmELF.h"
#endif
#if defined(CMAKE_USE_MACH_PARSER)
-#include "cmMachO.h"
+# include "cmMachO.h"
#endif
#include "cmsys/Directory.hxx"
@@ -37,129 +42,96 @@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
+#include <fcntl.h>
#include <iostream>
-#include <set>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <utility>
+#include <vector>
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
// include wincrypt.h after windows.h
-#include <wincrypt.h>
+# include <wincrypt.h>
#else
-#include <sys/time.h>
-#include <unistd.h>
-#include <utime.h>
+# include <sys/time.h>
+# include <unistd.h>
#endif
#if defined(_WIN32) && \
(defined(_MSC_VER) || defined(__WATCOMC__) || defined(__MINGW32__))
-#include <io.h>
+# include <io.h>
#endif
#if defined(__APPLE__)
-#include <mach-o/dyld.h>
+# include <mach-o/dyld.h>
#endif
#ifdef __QNX__
-#include <malloc.h> /* for malloc/free on QNX */
+# include <malloc.h> /* for malloc/free on QNX */
#endif
+namespace {
+
+cmSystemTools::InterruptCallback s_InterruptCallback;
+cmSystemTools::MessageCallback s_MessageCallback;
+cmSystemTools::OutputCallback s_StderrCallback;
+cmSystemTools::OutputCallback s_StdoutCallback;
+
+} // namespace
+
static bool cm_isspace(char c)
{
return ((c & 0x80) == 0) && isspace(c);
}
-class cmSystemToolsFileTime
-{
-public:
-#if defined(_WIN32) && !defined(__CYGWIN__)
- FILETIME timeCreation;
- FILETIME timeLastAccess;
- FILETIME timeLastWrite;
-#else
- struct utimbuf timeBuf;
-#endif
-};
-
#if !defined(HAVE_ENVIRON_NOT_REQUIRE_PROTOTYPE)
// For GetEnvironmentVariables
-#if defined(_WIN32)
+# if defined(_WIN32)
extern __declspec(dllimport) char** environ;
-#else
+# else
extern char** environ;
-#endif
+# endif
#endif
#if defined(CMAKE_BUILD_WITH_CMAKE)
static std::string cm_archive_entry_pathname(struct archive_entry* entry)
{
-#if cmsys_STL_HAS_WSTRING
+# if cmsys_STL_HAS_WSTRING
return cmsys::Encoding::ToNarrow(archive_entry_pathname_w(entry));
-#else
+# else
return archive_entry_pathname(entry);
-#endif
+# endif
}
static int cm_archive_read_open_file(struct archive* a, const char* file,
int block_size)
{
-#if cmsys_STL_HAS_WSTRING
+# 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
+# else
return archive_read_open_filename(a, file, block_size);
-#endif
+# 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>
+# include <crt_externs.h>
-#define environ (*_NSGetEnviron())
+# 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__)
@@ -240,99 +212,66 @@ std::string cmSystemTools::TrimWhitespace(const std::string& s)
return std::string(start, stop + 1);
}
-void cmSystemTools::Error(const char* m1, const char* m2, const char* m3,
- const char* m4)
+void cmSystemTools::Error(const std::string& m)
{
- std::string message = "CMake Error: ";
- if (m1) {
- message += m1;
- }
- if (m2) {
- message += m2;
- }
- if (m3) {
- message += m3;
- }
- if (m4) {
- message += m4;
- }
+ std::string message = "CMake Error: " + m;
cmSystemTools::s_ErrorOccured = true;
- cmSystemTools::Message(message.c_str(), "Error");
+ cmSystemTools::Message(message, "Error");
}
-void cmSystemTools::SetInterruptCallback(InterruptCallback f, void* clientData)
+void cmSystemTools::SetInterruptCallback(InterruptCallback f)
{
- s_InterruptCallback = f;
- s_InterruptCallbackClientData = clientData;
+ s_InterruptCallback = std::move(f);
}
bool cmSystemTools::GetInterruptFlag()
{
if (s_InterruptCallback) {
- return (*s_InterruptCallback)(s_InterruptCallbackClientData);
+ return s_InterruptCallback();
}
return false;
}
-void cmSystemTools::SetMessageCallback(MessageCallback f, void* clientData)
+void cmSystemTools::SetMessageCallback(MessageCallback f)
{
- s_MessageCallback = f;
- s_MessageCallbackClientData = clientData;
+ s_MessageCallback = std::move(f);
}
-void cmSystemTools::SetStdoutCallback(OutputCallback f, void* clientData)
+void cmSystemTools::SetStdoutCallback(OutputCallback f)
{
- s_StdoutCallback = f;
- s_StdoutCallbackClientData = clientData;
+ s_StdoutCallback = std::move(f);
}
-void cmSystemTools::SetStderrCallback(OutputCallback f, void* clientData)
+void cmSystemTools::SetStderrCallback(OutputCallback f)
{
- s_StderrCallback = f;
- s_StderrCallbackClientData = clientData;
+ s_StderrCallback = std::move(f);
}
-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)
+void cmSystemTools::Stderr(const std::string& s)
{
if (s_StderrCallback) {
- (*s_StderrCallback)(s, length, s_StderrCallbackClientData);
+ s_StderrCallback(s);
} else {
- std::cerr.write(s, length);
- std::cerr.flush();
+ std::cerr << s << std::flush;
}
}
-void cmSystemTools::Stdout(const char* s, size_t length)
+void cmSystemTools::Stdout(const std::string& s)
{
if (s_StdoutCallback) {
- (*s_StdoutCallback)(s, length, s_StdoutCallbackClientData);
+ s_StdoutCallback(s);
} else {
- std::cout.write(s, length);
- std::cout.flush();
+ std::cout << s << std::flush;
}
}
-void cmSystemTools::Message(const char* m1, const char* title)
+void cmSystemTools::Message(const std::string& m, const char* title)
{
- if (s_DisableMessages) {
- return;
- }
if (s_MessageCallback) {
- (*s_MessageCallback)(m1, title, s_DisableMessages,
- s_MessageCallbackClientData);
- return;
+ s_MessageCallback(m, title);
+ } else {
+ std::cerr << m << std::endl;
}
- std::cerr << m1 << std::endl << std::flush;
}
void cmSystemTools::ReportLastSystemError(const char* msg)
@@ -340,7 +279,7 @@ void cmSystemTools::ReportLastSystemError(const char* msg)
std::string m = msg;
m += ": System Error: ";
m += Superclass::GetLastSystemError();
- cmSystemTools::Error(m.c_str());
+ cmSystemTools::Error(m);
}
bool cmSystemTools::IsInternallyOn(const char* val)
@@ -353,8 +292,8 @@ bool cmSystemTools::IsInternallyOn(const char* val)
return false;
}
- for (std::string::iterator c = v.begin(); c != v.end(); c++) {
- *c = static_cast<char>(toupper(*c));
+ for (char& c : v) {
+ c = static_cast<char>(toupper(c));
}
return v == "I_ON";
}
@@ -364,24 +303,36 @@ bool cmSystemTools::IsOn(const char* val)
if (!val) {
return false;
}
- size_t len = strlen(val);
- if (len > 4) {
- return false;
+ /* clang-format off */
+ // "1"
+ if (val[0] == '1' && val[1] == '\0') {
+ return true;
}
- std::string 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");
+ // "ON"
+ if ((val[0] == 'O' || val[0] == 'o') &&
+ (val[1] == 'N' || val[1] == 'n') && val[2] == '\0') {
+ return true;
+ }
+ // "Y", "YES"
+ if ((val[0] == 'Y' || val[0] == 'y') && (val[1] == '\0' || (
+ (val[1] == 'E' || val[1] == 'e') &&
+ (val[2] == 'S' || val[2] == 's') && val[3] == '\0'))) {
+ return true;
}
- for (std::string::iterator c = v.begin(); c != v.end(); c++) {
- *c = static_cast<char>(toupper(*c));
+ // "TRUE"
+ if ((val[0] == 'T' || val[0] == 't') &&
+ (val[1] == 'R' || val[1] == 'r') &&
+ (val[2] == 'U' || val[2] == 'u') &&
+ (val[3] == 'E' || val[3] == 'e') && val[4] == '\0') {
+ return true;
}
- return (onValues.count(v) > 0);
+ /* clang-format on */
+ return false;
+}
+
+bool cmSystemTools::IsOn(const std::string& val)
+{
+ return cmSystemTools::IsOn(val.c_str());
}
bool cmSystemTools::IsNOTFOUND(const char* val)
@@ -394,30 +345,50 @@ bool cmSystemTools::IsNOTFOUND(const char* val)
bool cmSystemTools::IsOff(const char* val)
{
- if (!val || !*val) {
+ // ""
+ if (!val || val[0] == '\0') {
return true;
}
- size_t len = strlen(val);
- // Try and avoid toupper() for large strings.
- if (len > 6) {
- return cmSystemTools::IsNOTFOUND(val);
+ /* clang-format off */
+ // "0"
+ if (val[0] == '0' && val[1] == '\0') {
+ return true;
}
-
- 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");
+ // "OFF"
+ if ((val[0] == 'O' || val[0] == 'o') &&
+ (val[1] == 'F' || val[1] == 'f') &&
+ (val[2] == 'F' || val[2] == 'f') && val[3] == '\0') {
+ return true;
}
- // Try and avoid toupper().
- std::string v(val, len);
- for (std::string::iterator c = v.begin(); c != v.end(); c++) {
- *c = static_cast<char>(toupper(*c));
+ // "N", "NO"
+ if ((val[0] == 'N' || val[0] == 'n') && (val[1] == '\0' || (
+ (val[1] == 'O' || val[1] == 'o') && val[2] == '\0'))) {
+ return true;
}
- return (offValues.count(v) > 0);
+ // "FALSE"
+ if ((val[0] == 'F' || val[0] == 'f') &&
+ (val[1] == 'A' || val[1] == 'a') &&
+ (val[2] == 'L' || val[2] == 'l') &&
+ (val[3] == 'S' || val[3] == 's') &&
+ (val[4] == 'E' || val[4] == 'e') && val[5] == '\0') {
+ return true;
+ }
+ // "IGNORE"
+ if ((val[0] == 'I' || val[0] == 'i') &&
+ (val[1] == 'G' || val[1] == 'g') &&
+ (val[2] == 'N' || val[2] == 'n') &&
+ (val[3] == 'O' || val[3] == 'o') &&
+ (val[4] == 'R' || val[4] == 'r') &&
+ (val[5] == 'E' || val[5] == 'e') && val[6] == '\0') {
+ return true;
+ }
+ /* clang-format on */
+ return cmSystemTools::IsNOTFOUND(val);
+}
+
+bool cmSystemTools::IsOff(const std::string& val)
+{
+ return cmSystemTools::IsOff(val.c_str());
}
void cmSystemTools::ParseWindowsCommandLine(const char* command,
@@ -458,7 +429,7 @@ void cmSystemTools::ParseWindowsCommandLine(const char* command,
arg.append(1, *c);
} else if (in_argument) {
args.push_back(arg);
- arg = "";
+ arg.clear();
in_argument = false;
}
} else {
@@ -489,10 +460,12 @@ public:
}
free(this->ArgV);
}
+ cmSystemToolsArgV(const cmSystemToolsArgV&) = delete;
+ cmSystemToolsArgV& operator=(const cmSystemToolsArgV&) = delete;
void Store(std::vector<std::string>& args) const
{
for (char** arg = this->ArgV; arg && *arg; ++arg) {
- args.push_back(*arg);
+ args.emplace_back(*arg);
}
}
};
@@ -501,7 +474,7 @@ void cmSystemTools::ParseUnixCommandLine(const char* command,
std::vector<std::string>& args)
{
// Invoke the underlying parser.
- cmSystemToolsArgV argv = cmsysSystem_Parse_CommandForUnix(command, 0);
+ cmSystemToolsArgV argv(cmsysSystem_Parse_CommandForUnix(command, 0));
argv.Store(args);
}
@@ -510,8 +483,7 @@ std::vector<std::string> cmSystemTools::HandleResponseFile(
std::vector<std::string>::const_iterator argEnd)
{
std::vector<std::string> arg_full;
- for (std::vector<std::string>::const_iterator a = argBeg; a != argEnd; ++a) {
- std::string const& arg = *a;
+ for (std::string const& arg : cmMakeRange(argBeg, argEnd)) {
if (cmHasLiteralPrefix(arg, "@")) {
cmsys::ifstream responseFile(arg.substr(1).c_str(), std::ios::in);
if (!responseFile) {
@@ -519,7 +491,7 @@ std::vector<std::string> cmSystemTools::HandleResponseFile(
error += cmSystemTools::GetLastSystemError();
error += "):\n ";
error += arg.substr(1);
- cmSystemTools::Error(error.c_str());
+ cmSystemTools::Error(error);
} else {
std::string line;
cmSystemTools::GetLineFromStream(responseFile, line);
@@ -529,7 +501,7 @@ std::vector<std::string> cmSystemTools::HandleResponseFile(
#else
cmSystemTools::ParseUnixCommandLine(line.c_str(), args2);
#endif
- arg_full.insert(arg_full.end(), args2.begin(), args2.end());
+ cmAppend(arg_full, args2);
}
} else {
arg_full.push_back(arg);
@@ -538,19 +510,21 @@ std::vector<std::string> cmSystemTools::HandleResponseFile(
return arg_full;
}
-std::vector<std::string> cmSystemTools::ParseArguments(const char* command)
+std::vector<std::string> cmSystemTools::ParseArguments(const std::string& cmd)
{
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] == '\\')) {
+ const char* command = cmd.c_str();
+ if (command[0] && command[1] &&
+ ((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.
@@ -559,7 +533,7 @@ std::vector<std::string> cmSystemTools::ParseArguments(const char* command)
while (*c == ' ' || *c == '\t') {
++c;
}
- arg = "";
+ arg.clear();
if (*c == '"') {
// Parse a quoted argument.
++c;
@@ -603,6 +577,56 @@ std::vector<std::string> cmSystemTools::ParseArguments(const char* command)
return args;
}
+bool cmSystemTools::SplitProgramFromArgs(std::string const& command,
+ std::string& program,
+ std::string& args)
+{
+ const char* c = command.c_str();
+
+ // Skip leading whitespace.
+ while (isspace(static_cast<unsigned char>(*c))) {
+ ++c;
+ }
+
+ // Parse one command-line element up to an unquoted space.
+ bool in_escape = false;
+ bool in_double = false;
+ bool in_single = false;
+ for (; *c; ++c) {
+ if (in_single) {
+ if (*c == '\'') {
+ in_single = false;
+ } else {
+ program += *c;
+ }
+ } else if (in_escape) {
+ in_escape = false;
+ program += *c;
+ } else if (*c == '\\') {
+ in_escape = true;
+ } else if (in_double) {
+ if (*c == '"') {
+ in_double = false;
+ } else {
+ program += *c;
+ }
+ } else if (*c == '"') {
+ in_double = true;
+ } else if (*c == '\'') {
+ in_single = true;
+ } else if (isspace(static_cast<unsigned char>(*c))) {
+ break;
+ } else {
+ program += *c;
+ }
+ }
+
+ // The remainder of the command line holds unparsed arguments.
+ args = c;
+
+ return !in_single && !in_escape && !in_double;
+}
+
size_t cmSystemTools::CalculateCommandLineLengthLimit()
{
size_t sz =
@@ -633,11 +657,11 @@ size_t cmSystemTools::CalculateCommandLineLengthLimit()
// We estimate the size of the environment block to be 1000.
// This isn't accurate at all, but leaves some headroom.
szArgMax = szArgMax < 1000 ? 0 : szArgMax - 1000;
-#if defined(_WIN32) || defined(__linux)
+# if defined(_WIN32) || defined(__linux)
sz = std::min(sz, static_cast<size_t>(szArgMax));
-#else
+# else
sz = static_cast<size_t>(szArgMax);
-#endif
+# endif
}
#endif
return sz;
@@ -647,17 +671,17 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
std::string* captureStdOut,
std::string* captureStdErr, int* retVal,
const char* dir, OutputOption outputflag,
- double timeout, Encoding encoding)
+ cmDuration timeout, Encoding encoding)
{
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.reserve(command.size() + 1);
+ for (std::string const& cmd : command) {
+ argv.push_back(cmd.c_str());
}
- argv.push_back(CM_NULLPTR);
+ argv.push_back(nullptr);
cmsysProcess* cp = cmsysProcess_New();
- cmsysProcess_SetCommand(cp, &*argv.begin());
+ cmsysProcess_SetCommand(cp, argv.data());
cmsysProcess_SetWorkingDirectory(cp, dir);
if (cmSystemTools::GetRunCommandHideConsole()) {
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
@@ -666,16 +690,16 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
if (outputflag == OUTPUT_PASSTHROUGH) {
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
- captureStdOut = CM_NULLPTR;
- captureStdErr = CM_NULLPTR;
+ captureStdOut = nullptr;
+ captureStdErr = nullptr;
} else if (outputflag == OUTPUT_MERGE ||
(captureStdErr && captureStdErr == captureStdOut)) {
cmsysProcess_SetOption(cp, cmsysProcess_Option_MergeOutput, 1);
- captureStdErr = CM_NULLPTR;
+ captureStdErr = nullptr;
}
assert(!captureStdErr || captureStdErr != captureStdOut);
- cmsysProcess_SetTimeout(cp, timeout);
+ cmsysProcess_SetTimeout(cp, timeout.count());
cmsysProcess_Execute(cp);
std::vector<char> tempStdOut;
@@ -687,7 +711,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
std::string strdata;
if (outputflag != OUTPUT_PASSTHROUGH &&
(captureStdOut || captureStdErr || outputflag != OUTPUT_NONE)) {
- while ((pipe = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) >
+ while ((pipe = cmsysProcess_WaitForData(cp, &data, &length, nullptr)) >
0) {
// Translate NULL characters in the output into valid text.
for (int i = 0; i < length; ++i) {
@@ -699,18 +723,18 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
if (pipe == cmsysProcess_Pipe_STDOUT) {
if (outputflag != OUTPUT_NONE) {
processOutput.DecodeText(data, length, strdata, 1);
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
}
if (captureStdOut) {
- tempStdOut.insert(tempStdOut.end(), data, data + length);
+ cmAppend(tempStdOut, data, data + length);
}
} else if (pipe == cmsysProcess_Pipe_STDERR) {
if (outputflag != OUTPUT_NONE) {
processOutput.DecodeText(data, length, strdata, 2);
- cmSystemTools::Stderr(strdata.c_str(), strdata.size());
+ cmSystemTools::Stderr(strdata);
}
if (captureStdErr) {
- tempStdErr.insert(tempStdErr.end(), data, data + length);
+ cmAppend(tempStdErr, data, data + length);
}
}
}
@@ -718,16 +742,16 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
if (outputflag != OUTPUT_NONE) {
processOutput.DecodeText(std::string(), strdata, 1);
if (!strdata.empty()) {
- cmSystemTools::Stdout(strdata.c_str(), strdata.size());
+ cmSystemTools::Stdout(strdata);
}
processOutput.DecodeText(std::string(), strdata, 2);
if (!strdata.empty()) {
- cmSystemTools::Stderr(strdata.c_str(), strdata.size());
+ cmSystemTools::Stderr(strdata);
}
}
}
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
if (captureStdOut) {
captureStdOut->assign(tempStdOut.begin(), tempStdOut.end());
@@ -754,6 +778,8 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
}
if (captureStdErr) {
captureStdErr->append(exception_str, strlen(exception_str));
+ } else if (captureStdOut) {
+ captureStdOut->append(exception_str, strlen(exception_str));
}
result = false;
} else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Error) {
@@ -763,6 +789,8 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
}
if (captureStdErr) {
captureStdErr->append(error_str, strlen(error_str));
+ } else if (captureStdOut) {
+ captureStdOut->append(error_str, strlen(error_str));
}
result = false;
} else if (cmsysProcess_GetState(cp) == cmsysProcess_State_Expired) {
@@ -780,11 +808,11 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command,
return result;
}
-bool cmSystemTools::RunSingleCommand(const char* command,
+bool cmSystemTools::RunSingleCommand(const std::string& command,
std::string* captureStdOut,
std::string* captureStdErr, int* retVal,
const char* dir, OutputOption outputflag,
- double timeout)
+ cmDuration timeout)
{
if (s_DisableRunCommandOutput) {
outputflag = OUTPUT_NONE;
@@ -810,25 +838,24 @@ std::string cmSystemTools::PrintSingleCommand(
}
bool cmSystemTools::DoesFileExistWithExtensions(
- const char* name, const std::vector<std::string>& headerExts)
+ const std::string& name, const std::vector<std::string>& headerExts)
{
std::string hname;
- for (std::vector<std::string>::const_iterator ext = headerExts.begin();
- ext != headerExts.end(); ++ext) {
+ for (std::string const& headerExt : headerExts) {
hname = name;
hname += ".";
- hname += *ext;
- if (cmSystemTools::FileExists(hname.c_str())) {
+ hname += headerExt;
+ if (cmSystemTools::FileExists(hname)) {
return true;
}
}
return false;
}
-std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
- const char* directory,
- const char* toplevel)
+std::string cmSystemTools::FileExistsInParentDirectories(
+ const std::string& fname, const std::string& directory,
+ const std::string& toplevel)
{
std::string file = fname;
cmSystemTools::ConvertToUnixSlashes(file);
@@ -837,10 +864,10 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
std::string prevDir;
while (dir != prevDir) {
std::string path = dir + "/" + file;
- if (cmSystemTools::FileExists(path.c_str())) {
+ if (cmSystemTools::FileExists(path)) {
return path;
}
- if (dir.size() < strlen(toplevel)) {
+ if (dir.size() < toplevel.size()) {
break;
}
prevDir = dir;
@@ -849,17 +876,6 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
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()
{
@@ -892,12 +908,65 @@ cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry()
}
#endif
-bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
+std::string cmSystemTools::GetRealPathResolvingWindowsSubst(
+ const std::string& path, std::string* errorMessage)
{
#ifdef _WIN32
-#ifndef INVALID_FILE_ATTRIBUTES
-#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+ // uv_fs_realpath uses Windows Vista API so fallback to kwsys if not found
+ std::string resolved_path;
+ uv_fs_t req;
+ int err = uv_fs_realpath(NULL, &req, path.c_str(), NULL);
+ if (!err) {
+ resolved_path = std::string((char*)req.ptr);
+ cmSystemTools::ConvertToUnixSlashes(resolved_path);
+ // Normalize to upper-case drive letter as GetActualCaseForPath does.
+ if (resolved_path.size() > 1 && resolved_path[1] == ':') {
+ resolved_path[0] = toupper(resolved_path[0]);
+ }
+ } else if (err == UV_ENOSYS) {
+ resolved_path = cmsys::SystemTools::GetRealPath(path, errorMessage);
+ } else if (errorMessage) {
+ LPSTR message = NULL;
+ DWORD size = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&message, 0,
+ NULL);
+ *errorMessage = std::string(message, size);
+ LocalFree(message);
+
+ resolved_path = "";
+ } else {
+ resolved_path = path;
+ }
+ return resolved_path;
+#else
+ return cmsys::SystemTools::GetRealPath(path, errorMessage);
#endif
+}
+
+void cmSystemTools::InitializeLibUV()
+{
+#if defined(_WIN32)
+ // Perform libuv one-time initialization now, and then un-do its
+ // global _fmode setting so that using libuv does not change the
+ // default file text/binary mode. See libuv issue 840.
+ uv_loop_close(uv_default_loop());
+# ifdef _MSC_VER
+ _set_fmode(_O_TEXT);
+# else
+ _fmode = _O_TEXT;
+# endif
+#endif
+}
+
+bool cmSystemTools::RenameFile(const std::string& oldname,
+ const std::string& 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
@@ -930,23 +999,21 @@ bool cmSystemTools::RenameFile(const char* oldname, const char* newname)
return retry.Count > 0;
#else
/* On UNIX we have an OS-provided call to do this atomically. */
- return rename(oldname, newname) == 0;
+ return rename(oldname.c_str(), newname.c_str()) == 0;
#endif
}
-bool cmSystemTools::ComputeFileMD5(const std::string& source, char* md5out)
+std::string cmSystemTools::ComputeFileHash(const std::string& source,
+ cmCryptoHash::Algo algo)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
- cmCryptoHash md5(cmCryptoHash::AlgoMD5);
- std::string const str = md5.HashFile(source);
- strncpy(md5out, str.c_str(), 32);
- return !str.empty();
+ cmCryptoHash hash(algo);
+ return hash.HashFile(source);
#else
(void)source;
- (void)md5out;
- cmSystemTools::Message("md5sum not supported in bootstrapping mode",
+ cmSystemTools::Message("hashsum not supported in bootstrapping mode",
"Error");
- return false;
+ return std::string();
#endif
}
@@ -1050,7 +1117,7 @@ void cmSystemTools::Glob(const std::string& directory,
for (i = 0; i < numf; i++) {
std::string fname = d.GetFile(i);
if (reg.find(fname)) {
- files.push_back(fname);
+ files.push_back(std::move(fname));
}
}
}
@@ -1084,17 +1151,8 @@ void cmSystemTools::GlobDirs(const std::string& path,
}
}
-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,
+ std::vector<std::string>& argsOut,
bool emptyArgs)
{
// If argument is empty, it is an empty list.
@@ -1103,7 +1161,7 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
}
// if there are no ; in the name then just copy the current string
if (arg.find(';') == std::string::npos) {
- newargs.push_back(arg);
+ argsOut.push_back(arg);
return;
}
std::string newArg;
@@ -1137,8 +1195,8 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
last = c + 1;
if (!newArg.empty() || emptyArgs) {
// Add the last argument if the string is not empty.
- newargs.push_back(newArg);
- newArg = "";
+ argsOut.push_back(newArg);
+ newArg.clear();
}
}
} break;
@@ -1150,16 +1208,24 @@ void cmSystemTools::ExpandListArgument(const std::string& arg,
newArg.append(last);
if (!newArg.empty() || emptyArgs) {
// Add the last argument if the string is not empty.
- newargs.push_back(newArg);
+ argsOut.push_back(newArg);
}
}
+std::vector<std::string> cmSystemTools::ExpandedListArgument(
+ const std::string& arg, bool emptyArgs)
+{
+ std::vector<std::string> argsOut;
+ ExpandListArgument(arg, argsOut, emptyArgs);
+ return argsOut;
+}
+
bool cmSystemTools::SimpleGlob(const std::string& glob,
std::vector<std::string>& files,
int type /* = 0 */)
{
files.clear();
- if (glob[glob.size() - 1] != '*') {
+ if (glob.back() != '*') {
return false;
}
std::string path = cmSystemTools::GetFilenamePath(glob);
@@ -1176,7 +1242,7 @@ bool cmSystemTools::SimpleGlob(const std::string& glob,
if ((std::string(d.GetFile(i)) != ".") &&
(std::string(d.GetFile(i)) != "..")) {
std::string fname = path;
- if (path[path.size() - 1] != '/') {
+ if (path.back() != '/') {
fname += "/";
}
fname += d.GetFile(i);
@@ -1198,13 +1264,11 @@ bool cmSystemTools::SimpleGlob(const std::string& glob,
return res;
}
-cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext)
+cmSystemTools::FileFormat cmSystemTools::GetFileFormat(std::string const& ext)
{
- if (!cext || *cext == 0) {
+ if (ext.empty()) {
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;
}
@@ -1222,6 +1286,9 @@ cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext)
if (ext == "java" || ext == ".java") {
return cmSystemTools::JAVA_FILE_FORMAT;
}
+ if (ext == "cu" || ext == ".cu") {
+ return cmSystemTools::CUDA_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" ||
@@ -1256,15 +1323,7 @@ cmSystemTools::FileFormat cmSystemTools::GetFileFormat(const char* cext)
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);
- l.insert(l.end(), temp.begin(), temp.end());
- return res;
-}
-
-std::string cmSystemTools::ConvertToOutputPath(const char* path)
+std::string cmSystemTools::ConvertToOutputPath(std::string const& path)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
if (s_ForceUnixPaths) {
@@ -1291,7 +1350,7 @@ void cmSystemTools::ConvertToOutputSlashes(std::string& path)
#endif
}
-std::string cmSystemTools::ConvertToRunCommandPath(const char* path)
+std::string cmSystemTools::ConvertToRunCommandPath(const std::string& path)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
return cmSystemTools::ConvertToWindowsOutputPath(path);
@@ -1301,60 +1360,105 @@ std::string cmSystemTools::ConvertToRunCommandPath(const char* path)
}
// compute the relative path from here to there
-std::string cmSystemTools::RelativePath(const char* local, const char* remote)
+std::string cmSystemTools::RelativePath(std::string const& local,
+ std::string const& remote)
{
if (!cmSystemTools::FileIsFullPath(local)) {
- cmSystemTools::Error("RelativePath must be passed a full path to 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);
+ 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)
+std::string cmSystemTools::ForceToRelativePath(std::string const& local_path,
+ std::string const& remote_path)
{
- if (dir.empty() || dir == ".") {
- return file;
+ // The paths should never be quoted.
+ assert(local_path.front() != '\"');
+ assert(remote_path.front() != '\"');
+
+ // The local path should never have a trailing slash.
+ assert(local_path.empty() || local_path.back() != '/');
+
+ // If the path is already relative then just return the path.
+ if (!cmSystemTools::FileIsFullPath(remote_path)) {
+ return remote_path;
+ }
+
+ // Identify the longest shared path component between the remote
+ // path and the local path.
+ std::vector<std::string> local;
+ cmSystemTools::SplitPath(local_path, local);
+ std::vector<std::string> remote;
+ cmSystemTools::SplitPath(remote_path, remote);
+ unsigned int common = 0;
+ while (common < remote.size() && common < local.size() &&
+ cmSystemTools::ComparePath(remote[common], local[common])) {
+ ++common;
}
- std::vector<std::string> dirComponents;
- std::vector<std::string> fileComponents;
- cmSystemTools::SplitPath(dir, dirComponents);
- cmSystemTools::SplitPath(file, fileComponents);
+ // If no part of the path is in common then return the full path.
+ if (common == 0) {
+ return remote_path;
+ }
- if (fileComponents.empty()) {
- return dir;
+ // If the entire path is in common then just return a ".".
+ if (common == remote.size() && common == local.size()) {
+ return ".";
}
- if (fileComponents[0] != "") {
- // File is not a relative path.
- return file;
+
+ // If the entire path is in common except for a trailing slash then
+ // just return a "./".
+ if (common + 1 == remote.size() && remote[common].empty() &&
+ 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 += "/";
+ }
}
- 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.
+ // 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.
+
+ if (!relative.empty() && !remote.empty()) {
+ relative += "/";
}
+ relative += cmJoin(cmMakeRange(remote).advance(common), "/");
- dirComponents.insert(dirComponents.end(), i, fileComponents.end());
- return cmSystemTools::JoinPath(dirComponents);
+ // Finally return the path.
+ return relative;
}
#ifdef CMAKE_BUILD_WITH_CMAKE
bool cmSystemTools::UnsetEnv(const char* value)
{
-#if !defined(HAVE_UNSETENV)
+# if !defined(HAVE_UNSETENV)
std::string var = value;
var += "=";
return cmSystemTools::PutEnv(var.c_str());
-#else
+# else
unsetenv(value);
return true;
-#endif
+# endif
}
std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
@@ -1362,16 +1466,15 @@ std::vector<std::string> cmSystemTools::GetEnvironmentVariables()
std::vector<std::string> env;
int cc;
for (cc = 0; environ[cc]; ++cc) {
- env.push_back(environ[cc]);
+ env.emplace_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);
+ for (std::string const& eit : env) {
+ cmSystemTools::PutEnv(eit);
}
}
@@ -1384,10 +1487,7 @@ 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);
-
+ for (std::string var : currentEnv) {
std::string::size_type pos = var.find('=');
if (pos != std::string::npos) {
var = var.substr(0, pos);
@@ -1404,7 +1504,7 @@ cmSystemTools::SaveRestoreEnvironment::~SaveRestoreEnvironment()
void cmSystemTools::EnableVSConsoleOutput()
{
#ifdef _WIN32
- // Visual Studio 8 2005 (devenv.exe or VCExpress.exe) will not
+ // Visual Studio tools like devenv may 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
@@ -1413,23 +1513,23 @@ void cmSystemTools::EnableVSConsoleOutput()
// output and allow it to be captured on the fly.
cmSystemTools::PutEnv("vsconsoleoutput=1");
-#ifdef CMAKE_BUILD_WITH_CMAKE
+# 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
#endif
}
-bool cmSystemTools::IsPathToFramework(const char* path)
+bool cmSystemTools::IsPathToFramework(const std::string& path)
{
return (cmSystemTools::FileIsFullPath(path) &&
cmHasLiteralSuffix(path, ".framework"));
}
-bool cmSystemTools::CreateTar(const char* outFileName,
+bool cmSystemTools::CreateTar(const std::string& outFileName,
const std::vector<std::string>& files,
cmTarCompression compressType, bool verbose,
std::string const& mtime,
@@ -1437,13 +1537,13 @@ bool cmSystemTools::CreateTar(const char* outFileName,
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
- cmsys::ofstream fout(outFileName, std::ios::out | std::ios::binary);
+ cmsys::ofstream fout(outFileName.c_str(), std::ios::out | std::ios::binary);
if (!fout) {
std::string e = "Cannot open output file \"";
e += outFileName;
e += "\": ";
e += cmSystemTools::GetLastSystemError();
- cmSystemTools::Error(e.c_str());
+ cmSystemTools::Error(e);
return false;
}
cmArchiveWrite::Compress compress = cmArchiveWrite::CompressNone;
@@ -1457,6 +1557,9 @@ bool cmSystemTools::CreateTar(const char* outFileName,
case TarCompressXZ:
compress = cmArchiveWrite::CompressXZ;
break;
+ case TarCompressZstd:
+ compress = cmArchiveWrite::CompressZstd;
+ break;
case TarCompressNone:
compress = cmArchiveWrite::CompressNone;
break;
@@ -1466,22 +1569,18 @@ bool cmSystemTools::CreateTar(const char* outFileName,
a.SetMTime(mtime);
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())) {
+ bool tarCreatedSuccessfully = true;
+ for (auto path : files) {
+ if (cmSystemTools::FileIsFullPath(path)) {
// Get the relative path to the file.
- path = cmSystemTools::RelativePath(cwd.c_str(), path.c_str());
+ path = cmSystemTools::RelativePath(cwd, path);
}
if (!a.Add(path)) {
- break;
+ cmSystemTools::Error(a.GetError());
+ tarCreatedSuccessfully = false;
}
}
- if (!a) {
- cmSystemTools::Error(a.GetError().c_str());
- return false;
- }
- return true;
+ return tarCreatedSuccessfully;
#else
(void)outFileName;
(void)files;
@@ -1492,8 +1591,8 @@ bool cmSystemTools::CreateTar(const char* outFileName,
#if defined(CMAKE_BUILD_WITH_CMAKE)
namespace {
-#define BSDTAR_FILESIZE_PRINTF "%lu"
-#define BSDTAR_FILESIZE_TYPE unsigned long
+# define BSDTAR_FILESIZE_PRINTF "%lu"
+# define BSDTAR_FILESIZE_TYPE unsigned long
void list_item_verbose(FILE* out, struct archive_entry* entry)
{
char tmp[100];
@@ -1520,22 +1619,22 @@ void list_item_verbose(FILE* out, struct archive_entry* entry)
/* Use uname if it's present, else uid. */
p = archive_entry_uname(entry);
- if ((p == CM_NULLPTR) || (*p == '\0')) {
- sprintf(tmp, "%lu ", (unsigned long)archive_entry_uid(entry));
+ if ((p == nullptr) || (*p == '\0')) {
+ sprintf(tmp, "%lu ", static_cast<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);
+ fprintf(out, "%-*s ", static_cast<int>(u_width), p);
/* Use gname if it's present, else gid. */
p = archive_entry_gname(entry);
- if (p != CM_NULLPTR && p[0] != '\0') {
+ if (p != nullptr && p[0] != '\0') {
fprintf(out, "%s", p);
w = strlen(p);
} else {
- sprintf(tmp, "%lu", (unsigned long)archive_entry_gid(entry));
+ sprintf(tmp, "%lu", static_cast<unsigned long>(archive_entry_gid(entry)));
w = strlen(tmp);
fprintf(out, "%s", tmp);
}
@@ -1547,8 +1646,9 @@ void list_item_verbose(FILE* out, struct archive_entry* entry)
*/
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));
+ unsigned long rdevmajor = archive_entry_rdevmajor(entry);
+ unsigned long rdevminor = archive_entry_rdevminor(entry);
+ sprintf(tmp, "%lu,%lu", rdevmajor, rdevminor);
} else {
/*
* Note the use of platform-dependent macros to format
@@ -1556,22 +1656,22 @@ void list_item_verbose(FILE* out, struct archive_entry* entry)
* corresponding type for the cast.
*/
sprintf(tmp, BSDTAR_FILESIZE_PRINTF,
- (BSDTAR_FILESIZE_TYPE)archive_entry_size(entry));
+ static_cast<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);
+ fprintf(out, "%*s", static_cast<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__)
+# 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
+# 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 {
@@ -1592,38 +1692,77 @@ void list_item_verbose(FILE* out, struct archive_entry* entry)
fflush(out);
}
-long copy_data(struct archive* ar, struct archive* aw)
+void ArchiveError(const char* m1, struct archive* a)
+{
+ std::string message(m1);
+ const char* m2 = archive_error_string(a);
+ if (m2) {
+ message += m2;
+ }
+ cmSystemTools::Error(message);
+}
+
+bool la_diagnostic(struct archive* ar, __LA_SSIZE_T r)
+{
+ // See archive.h definition of ARCHIVE_OK for return values.
+
+ if (r >= ARCHIVE_OK) {
+ return true;
+ }
+
+ if (r >= ARCHIVE_WARN) {
+ const char* warn = archive_error_string(ar);
+ if (!warn) {
+ warn = "unknown warning";
+ }
+ std::cerr << "cmake -E tar: warning: " << warn << '\n';
+ return true;
+ }
+
+ // Error.
+ const char* err = archive_error_string(ar);
+ if (!err) {
+ err = "unknown error";
+ }
+ std::cerr << "cmake -E tar: error: " << err << '\n';
+ return false;
+}
+
+// Return 'true' on success
+bool 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
+# if defined(ARCHIVE_VERSION_NUMBER) && ARCHIVE_VERSION_NUMBER >= 3000000
__LA_INT64_T offset;
-#else
+# else
off_t offset;
-#endif
+# endif
for (;;) {
+ // See archive.h definition of ARCHIVE_OK for return values.
r = archive_read_data_block(ar, &buff, &size, &offset);
if (r == ARCHIVE_EOF) {
- return (ARCHIVE_OK);
+ return true;
}
- if (r != ARCHIVE_OK) {
- return (r);
+ if (!la_diagnostic(ar, r)) {
+ return false;
}
- 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);
+ // See archive.h definition of ARCHIVE_OK for return values.
+ __LA_SSIZE_T const w = archive_write_data_block(aw, buff, size, offset);
+ if (!la_diagnostic(ar, w)) {
+ return false;
}
}
-#if !defined(__clang__) && !defined(__HP_aCC)
- return r; /* this should not happen but it quiets some compilers */
-#endif
+# if !defined(__clang__) && !defined(__HP_aCC)
+ return false; /* this should not happen but it quiets some compilers */
+# endif
}
-bool extract_tar(const char* outFileName, bool verbose, bool extract)
+bool extract_tar(const std::string& outFileName,
+ const std::vector<std::string>& files, bool verbose,
+ bool extract)
{
cmLocaleRAII localeRAII;
static_cast<void>(localeRAII);
@@ -1632,10 +1771,24 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract)
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
struct archive_entry* entry;
- int r = cm_archive_read_open_file(a, outFileName, 10240);
+
+ struct archive* matching = archive_match_new();
+ if (matching == nullptr) {
+ cmSystemTools::Error("Out of memory");
+ return false;
+ }
+
+ for (const auto& filename : files) {
+ if (archive_match_include_pattern(matching, filename.c_str()) !=
+ ARCHIVE_OK) {
+ cmSystemTools::Error("Failed to add to inclusion list: " + filename);
+ return false;
+ }
+ }
+
+ int r = cm_archive_read_open_file(a, outFileName.c_str(), 10240);
if (r) {
- cmSystemTools::Error("Problem with archive_read_open_file(): ",
- archive_error_string(a));
+ ArchiveError("Problem with archive_read_open_file(): ", a);
archive_write_free(ext);
archive_read_close(a);
return false;
@@ -1646,56 +1799,80 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract)
break;
}
if (r != ARCHIVE_OK) {
- cmSystemTools::Error("Problem with archive_read_next_header(): ",
- archive_error_string(a));
+ ArchiveError("Problem with archive_read_next_header(): ", a);
break;
}
+
+ if (archive_match_excluded(matching, entry)) {
+ continue;
+ }
+
if (verbose) {
if (extract) {
cmSystemTools::Stdout("x ");
- cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str());
+ cmSystemTools::Stdout(cm_archive_entry_pathname(entry));
} else {
list_item_verbose(stdout, entry);
}
cmSystemTools::Stdout("\n");
} else if (!extract) {
- cmSystemTools::Stdout(cm_archive_entry_pathname(entry).c_str());
+ cmSystemTools::Stdout(cm_archive_entry_pathname(entry));
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));
+ ArchiveError("Problem with archive_write_disk_set_options(): ", ext);
break;
}
r = archive_write_header(ext, entry);
if (r == ARCHIVE_OK) {
- copy_data(a, ext);
+ if (!copy_data(a, ext)) {
+ break;
+ }
r = archive_write_finish_entry(ext);
if (r != ARCHIVE_OK) {
- cmSystemTools::Error("Problem with archive_write_finish_entry(): ",
- archive_error_string(ext));
+ ArchiveError("Problem with archive_write_finish_entry(): ", ext);
break;
}
}
-#ifdef _WIN32
+# 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
+# endif
else {
- cmSystemTools::Error("Problem with archive_write_header(): ",
- archive_error_string(ext));
- cmSystemTools::Error("Current file: ",
- cm_archive_entry_pathname(entry).c_str());
+ ArchiveError("Problem with archive_write_header(): ", ext);
+ cmSystemTools::Error("Current file: " +
+ cm_archive_entry_pathname(entry));
break;
}
}
}
+
+ bool error_occured = false;
+ if (matching != nullptr) {
+ const char* p;
+ int ar;
+
+ while ((ar = archive_match_path_unmatched_inclusions_next(matching, &p)) ==
+ ARCHIVE_OK) {
+ cmSystemTools::Error("tar: " + std::string(p) +
+ ": Not found in archive");
+ error_occured = true;
+ }
+ if (error_occured) {
+ return false;
+ }
+ if (ar == ARCHIVE_FATAL) {
+ cmSystemTools::Error("tar: Out of memory");
+ return false;
+ }
+ }
+ archive_match_free(matching);
archive_write_free(ext);
archive_read_close(a);
archive_read_free(a);
@@ -1704,33 +1881,39 @@ bool extract_tar(const char* outFileName, bool verbose, bool extract)
}
#endif
-bool cmSystemTools::ExtractTar(const char* outFileName, bool verbose)
+bool cmSystemTools::ExtractTar(const std::string& outFileName,
+ const std::vector<std::string>& files,
+ bool verbose)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
- return extract_tar(outFileName, verbose, true);
+ return extract_tar(outFileName, files, verbose, true);
#else
(void)outFileName;
+ (void)files;
(void)verbose;
return false;
#endif
}
-bool cmSystemTools::ListTar(const char* outFileName, bool verbose)
+bool cmSystemTools::ListTar(const std::string& outFileName,
+ const std::vector<std::string>& files,
+ bool verbose)
{
#if defined(CMAKE_BUILD_WITH_CMAKE)
- return extract_tar(outFileName, verbose, false);
+ return extract_tar(outFileName, files, verbose, false);
#else
(void)outFileName;
+ (void)files;
(void)verbose;
return false;
#endif
}
int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line,
- double timeout, std::vector<char>& out,
+ cmDuration timeout, std::vector<char>& out,
std::vector<char>& err)
{
- line = "";
+ line.clear();
std::vector<char>::iterator outiter = out.begin();
std::vector<char>::iterator erriter = err.begin();
cmProcessOutput processOutput;
@@ -1775,7 +1958,9 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line,
// No newlines found. Wait for more data from the process.
int length;
char* data;
- int pipe = cmsysProcess_WaitForData(process, &data, &length, &timeout);
+ double timeoutAsDbl = timeout.count();
+ int pipe =
+ cmsysProcess_WaitForData(process, &data, &length, &timeoutAsDbl);
if (pipe == cmsysProcess_Pipe_Timeout) {
// Timeout has been exceeded.
return pipe;
@@ -1784,26 +1969,26 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line,
processOutput.DecodeText(data, length, strdata, 1);
// Append to the stdout buffer.
std::vector<char>::size_type size = out.size();
- out.insert(out.end(), strdata.begin(), strdata.end());
+ cmAppend(out, strdata);
outiter = out.begin() + size;
} else if (pipe == cmsysProcess_Pipe_STDERR) {
processOutput.DecodeText(data, length, strdata, 2);
// Append to the stderr buffer.
std::vector<char>::size_type size = err.size();
- err.insert(err.end(), strdata.begin(), strdata.end());
+ cmAppend(err, strdata);
erriter = err.begin() + size;
} else if (pipe == cmsysProcess_Pipe_None) {
// Both stdout and stderr pipes have broken. Return leftover data.
processOutput.DecodeText(std::string(), strdata, 1);
if (!strdata.empty()) {
std::vector<char>::size_type size = out.size();
- out.insert(out.end(), strdata.begin(), strdata.end());
+ cmAppend(out, strdata);
outiter = out.begin() + size;
}
processOutput.DecodeText(std::string(), strdata, 2);
if (!strdata.empty()) {
std::vector<char>::size_type size = err.size();
- err.insert(err.end(), strdata.begin(), strdata.end());
+ cmAppend(err, strdata);
erriter = err.begin() + size;
}
if (!out.empty()) {
@@ -1821,6 +2006,71 @@ int cmSystemTools::WaitForLine(cmsysProcess* process, std::string& line,
}
}
+#ifdef _WIN32
+static void EnsureStdPipe(DWORD fd)
+{
+ if (GetStdHandle(fd) != INVALID_HANDLE_VALUE) {
+ return;
+ }
+ SECURITY_ATTRIBUTES sa;
+ sa.nLength = sizeof(sa);
+ sa.lpSecurityDescriptor = NULL;
+ sa.bInheritHandle = TRUE;
+
+ HANDLE h = CreateFileW(
+ L"NUL",
+ fd == STD_INPUT_HANDLE ? FILE_GENERIC_READ
+ : FILE_GENERIC_WRITE | FILE_READ_ATTRIBUTES,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, OPEN_EXISTING, 0, NULL);
+
+ if (h == INVALID_HANDLE_VALUE) {
+ LPSTR message = NULL;
+ DWORD size = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&message, 0, NULL);
+ std::string msg = std::string(message, size);
+ LocalFree(message);
+ std::cerr << "failed to open NUL for missing stdio pipe: " << msg;
+ abort();
+ }
+
+ SetStdHandle(fd, h);
+}
+
+void cmSystemTools::EnsureStdPipes()
+{
+ EnsureStdPipe(STD_INPUT_HANDLE);
+ EnsureStdPipe(STD_OUTPUT_HANDLE);
+ EnsureStdPipe(STD_ERROR_HANDLE);
+}
+#else
+static void EnsureStdPipe(int fd)
+{
+ if (fcntl(fd, F_GETFD) != -1 || errno != EBADF) {
+ return;
+ }
+
+ int f = open("/dev/null", fd == STDIN_FILENO ? O_RDONLY : O_WRONLY);
+ if (f == -1) {
+ perror("failed to open /dev/null for missing stdio pipe");
+ abort();
+ }
+ if (f != fd) {
+ dup2(f, fd);
+ close(f);
+ }
+}
+
+void cmSystemTools::EnsureStdPipes()
+{
+ EnsureStdPipe(STDIN_FILENO);
+ EnsureStdPipe(STDOUT_FILENO);
+ EnsureStdPipe(STDERR_FILENO);
+}
+#endif
+
void cmSystemTools::DoNotInheritStdPipes()
{
#ifdef _WIN32
@@ -1848,92 +2098,10 @@ void cmSystemTools::DoNotInheritStdPipes()
#endif
}
-bool cmSystemTools::CopyFileTime(const char* fromFile, const char* toFile)
-{
-#if defined(_WIN32) && !defined(__CYGWIN__)
- cmSystemToolsWindowsHandle hFrom = CreateFileW(
- SystemTools::ConvertToWindowsExtendedPath(fromFile).c_str(), GENERIC_READ,
- FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
- cmSystemToolsWindowsHandle hTo = CreateFileW(
- SystemTools::ConvertToWindowsExtendedPath(toFile).c_str(),
- FILE_WRITE_ATTRIBUTES, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
- if (!hFrom || !hTo) {
- return false;
- }
- FILETIME timeCreation;
- FILETIME timeLastAccess;
- FILETIME timeLastWrite;
- if (!GetFileTime(hFrom, &timeCreation, &timeLastAccess, &timeLastWrite)) {
- return false;
- }
- return SetFileTime(hTo, &timeCreation, &timeLastAccess, &timeLastWrite) != 0;
-#else
- struct stat fromStat;
- if (stat(fromFile, &fromStat) < 0) {
- return false;
- }
-
- struct utimbuf buf;
- buf.actime = fromStat.st_atime;
- buf.modtime = fromStat.st_mtime;
- return utime(toFile, &buf) >= 0;
-#endif
-}
-
-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(
- SystemTools::ConvertToWindowsExtendedPath(fname).c_str(), GENERIC_READ,
- FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 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(
- SystemTools::ConvertToWindowsExtendedPath(fname).c_str(),
- FILE_WRITE_ATTRIBUTES, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
- if (!h) {
- return false;
- }
- return SetFileTime(h, &t->timeCreation, &t->timeLastAccess,
- &t->timeLastWrite) != 0;
-#else
- return utime(fname, &t->timeBuf) >= 0;
-#endif
-}
-
#ifdef _WIN32
-#ifndef CRYPT_SILENT
-#define CRYPT_SILENT 0x40 /* Not defined by VS 6 version of header. */
-#endif
+# 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;
@@ -1973,7 +2141,7 @@ unsigned int cmSystemTools::RandomSeed()
// Try using a real random source.
cmsys::ifstream fin;
- fin.rdbuf()->pubsetbuf(CM_NULLPTR, 0); // Unbuffered read.
+ fin.rdbuf()->pubsetbuf(nullptr, 0); // Unbuffered read.
fin.open("/dev/urandom");
if (fin.good() && fin.read(seed.bytes, sizeof(seed)) &&
fin.gcount() == sizeof(seed)) {
@@ -1982,7 +2150,7 @@ unsigned int cmSystemTools::RandomSeed()
// Fall back to the time and pid.
struct timeval t;
- gettimeofday(&t, CM_NULLPTR);
+ gettimeofday(&t, nullptr);
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);
@@ -2006,21 +2174,26 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
(void)argv0; // ignore this on windows
wchar_t modulepath[_MAX_PATH];
::GetModuleFileNameW(NULL, modulepath, sizeof(modulepath));
- exe_dir =
- cmSystemTools::GetFilenamePath(cmsys::Encoding::ToNarrow(modulepath));
+ std::string path = cmsys::Encoding::ToNarrow(modulepath);
+ std::string realPath =
+ cmSystemTools::GetRealPathResolvingWindowsSubst(path, NULL);
+ if (realPath.empty()) {
+ realPath = path;
+ }
+ exe_dir = cmSystemTools::GetFilenamePath(realPath);
#elif defined(__APPLE__)
(void)argv0; // ignore this on OS X
-#define CM_EXE_PATH_LOCAL_SIZE 16384
+# 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)
+# 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
+# else
uint32_t exe_path_size = CM_EXE_PATH_LOCAL_SIZE;
-#endif
-#undef 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);
+ exe_path = static_cast<char*>(malloc(exe_path_size));
_NSGetExecutablePath(exe_path, &exe_path_size);
}
exe_dir =
@@ -2069,20 +2242,20 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
cmSystemToolsCMakeGUICommand = exe_dir;
cmSystemToolsCMakeGUICommand += "/cmake-gui";
cmSystemToolsCMakeGUICommand += cmSystemTools::GetExecutableExtension();
- if (!cmSystemTools::FileExists(cmSystemToolsCMakeGUICommand.c_str())) {
- cmSystemToolsCMakeGUICommand = "";
+ if (!cmSystemTools::FileExists(cmSystemToolsCMakeGUICommand)) {
+ cmSystemToolsCMakeGUICommand.clear();
}
cmSystemToolsCMakeCursesCommand = exe_dir;
cmSystemToolsCMakeCursesCommand += "/ccmake";
cmSystemToolsCMakeCursesCommand += cmSystemTools::GetExecutableExtension();
- if (!cmSystemTools::FileExists(cmSystemToolsCMakeCursesCommand.c_str())) {
- cmSystemToolsCMakeCursesCommand = "";
+ if (!cmSystemTools::FileExists(cmSystemToolsCMakeCursesCommand)) {
+ cmSystemToolsCMakeCursesCommand.clear();
}
cmSystemToolsCMClDepsCommand = exe_dir;
cmSystemToolsCMClDepsCommand += "/cmcldeps";
cmSystemToolsCMClDepsCommand += cmSystemTools::GetExecutableExtension();
- if (!cmSystemTools::FileExists(cmSystemToolsCMClDepsCommand.c_str())) {
- cmSystemToolsCMClDepsCommand = "";
+ if (!cmSystemTools::FileExists(cmSystemToolsCMClDepsCommand)) {
+ cmSystemToolsCMClDepsCommand.clear();
}
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -2096,7 +2269,7 @@ void cmSystemTools::FindCMakeResources(const char* argv0)
}
if (cmSystemToolsCMakeRoot.empty() ||
!cmSystemTools::FileExists(
- (cmSystemToolsCMakeRoot + "/Modules/CMake.cmake").c_str())) {
+ (cmSystemToolsCMakeRoot + "/Modules/CMake.cmake"))) {
// Build tree has "<build>/bin[/<config>]/cmake" and
// "<build>/CMakeFiles/CMakeSourceDir.txt".
std::string dir = cmSystemTools::GetFilenamePath(exe_dir);
@@ -2280,12 +2453,12 @@ struct cmSystemToolsRPathInfo
};
#endif
+#if defined(CMAKE_USE_ELF_PARSER)
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;
}
@@ -2298,8 +2471,8 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
// Get the RPATH and RUNPATH entries from it.
int se_count = 0;
- cmELF::StringEntry const* se[2] = { CM_NULLPTR, CM_NULLPTR };
- const char* se_name[2] = { CM_NULLPTR, CM_NULLPTR };
+ cmELF::StringEntry const* se[2] = { nullptr, nullptr };
+ const char* se_name[2] = { nullptr, nullptr };
if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) {
se[se_count] = se_rpath;
se_name[se_count] = "RPATH";
@@ -2451,15 +2624,16 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
*changed = true;
}
return true;
+}
#else
- (void)file;
- (void)oldRPath;
- (void)newRPath;
- (void)emsg;
- (void)changed;
+bool cmSystemTools::ChangeRPath(std::string const& /*file*/,
+ std::string const& /*oldRPath*/,
+ std::string const& /*newRPath*/,
+ std::string* /*emsg*/, bool* /*changed*/)
+{
return false;
-#endif
}
+#endif
bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op,
const char* lhss, const char* rhss)
@@ -2593,10 +2767,10 @@ int cmSystemTools::strverscmp(std::string const& lhs, std::string const& rhs)
return cm_strverscmp(lhs.c_str(), rhs.c_str());
}
+#if defined(CMAKE_USE_ELF_PARSER)
bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
bool* removed)
{
-#if defined(CMAKE_USE_ELF_PARSER)
if (removed) {
*removed = false;
}
@@ -2612,7 +2786,7 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
// 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] = { CM_NULLPTR, CM_NULLPTR };
+ cmELF::StringEntry const* se[2] = { nullptr, nullptr };
if (cmELF::StringEntry const* se_rpath = elf.GetRPath()) {
se[se_count++] = se_rpath;
}
@@ -2666,11 +2840,11 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
// contain the location of the linker map, however on MIPS the
// .dynamic section is always read-only so this is not possible. MIPS
// objects instead contain a DT_MIPS_RLD_MAP tag which contains the
- // address where the dyanmic linker will write to (an indirect
+ // address where the dynamic linker will write to (an indirect
// version of DT_DEBUG). Since this doesn't work when using PIE, a
// relative equivalent was created - DT_MIPS_RLD_MAP_REL. Since this
// version contains a relative offset, moving it changes the
- // calculated address. This may cause the dyanmic linker to write
+ // calculated address. This may cause the dynamic linker to write
// into memory it should not be changing.
//
// To fix this, we adjust the value of DT_MIPS_RLD_MAP_REL here. If
@@ -2734,13 +2908,14 @@ bool cmSystemTools::RemoveRPath(std::string const& file, std::string* emsg,
*removed = true;
}
return true;
+}
#else
- (void)file;
- (void)emsg;
- (void)removed;
+bool cmSystemTools::RemoveRPath(std::string const& /*file*/,
+ std::string* /*emsg*/, bool* /*removed*/)
+{
return false;
-#endif
}
+#endif
bool cmSystemTools::CheckRPath(std::string const& file,
std::string const& newRPath)
@@ -2774,7 +2949,7 @@ bool cmSystemTools::CheckRPath(std::string const& file,
#endif
}
-bool cmSystemTools::RepeatedRemoveDirectory(const char* dir)
+bool cmSystemTools::RepeatedRemoveDirectory(const std::string& dir)
{
// Windows sometimes locks files temporarily so try a few times.
for (int i = 0; i < 10; ++i) {
@@ -2806,7 +2981,7 @@ std::vector<std::string> cmSystemTools::tokenize(const std::string& str,
} while (tokend != std::string::npos);
if (tokens.empty()) {
- tokens.push_back("");
+ tokens.emplace_back();
}
return tokens;
}
@@ -2823,6 +2998,89 @@ bool cmSystemTools::StringToULong(const char* str, unsigned long* value)
{
errno = 0;
char* endp;
+ while (isspace(*str)) {
+ ++str;
+ }
+ if (*str == '-') {
+ return false;
+ }
*value = strtoul(str, &endp, 10);
return (*endp == '\0') && (endp != str) && (errno == 0);
}
+
+std::string cmSystemTools::EncodeURL(std::string const& in, bool escapeSlashes)
+{
+ std::string out;
+ for (char c : in) {
+ char hexCh[4] = { 0, 0, 0, 0 };
+ hexCh[0] = c;
+ switch (c) {
+ case '+':
+ case '?':
+ case '\\':
+ case '&':
+ case ' ':
+ case '=':
+ case '%':
+ sprintf(hexCh, "%%%02X", static_cast<int>(c));
+ break;
+ case '/':
+ if (escapeSlashes) {
+ strcpy(hexCh, "%2F");
+ }
+ break;
+ default:
+ break;
+ }
+ out.append(hexCh);
+ }
+ return out;
+}
+
+bool cmSystemTools::CreateSymlink(const std::string& origName,
+ const std::string& newName,
+ std::string* errorMessage)
+{
+ uv_fs_t req;
+ int flags = 0;
+#if defined(_WIN32)
+ if (cmsys::SystemTools::FileIsDirectory(origName)) {
+ flags |= UV_FS_SYMLINK_DIR;
+ }
+#endif
+ int err = uv_fs_symlink(nullptr, &req, origName.c_str(), newName.c_str(),
+ flags, nullptr);
+ if (err) {
+ std::string e =
+ "failed to create symbolic link '" + newName + "': " + uv_strerror(err);
+ if (errorMessage) {
+ *errorMessage = std::move(e);
+ } else {
+ cmSystemTools::Error(e);
+ }
+ return false;
+ }
+
+ return true;
+}
+
+bool cmSystemTools::CreateLink(const std::string& origName,
+ const std::string& newName,
+ std::string* errorMessage)
+{
+ uv_fs_t req;
+ int err =
+ uv_fs_link(nullptr, &req, origName.c_str(), newName.c_str(), nullptr);
+ if (err) {
+ std::string e =
+ "failed to create link '" + newName + "': " + uv_strerror(err);
+ if (errorMessage) {
+ *errorMessage = std::move(e);
+ } else {
+ cmSystemTools::Error(e);
+ }
+ return false;
+ }
+
+ return true;
+}
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 9de796728..016c2665f 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -3,17 +3,18 @@
#ifndef cmSystemTools_h
#define cmSystemTools_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmCryptoHash.h"
+#include "cmDuration.h"
#include "cmProcessOutput.h"
#include "cmsys/Process.h"
#include "cmsys/SystemTools.hxx" // IWYU pragma: export
+#include <functional>
#include <stddef.h>
#include <string>
#include <vector>
-class cmSystemToolsFileTime;
-
/** \class cmSystemTools
* \brief A collection of useful functions for CMake.
*
@@ -26,23 +27,56 @@ public:
typedef cmsys::SystemTools Superclass;
typedef cmProcessOutput::Encoding Encoding;
- /** 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.
+ /**
+ * Expand the ; separated string @a arg into multiple arguments.
+ * All found arguments are appended to @a argsOut.
*/
- 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);
/**
+ * Expand out any arguments in the string range [@a first, @a last) that have
+ * ; separated strings into multiple arguments. All found arguments are
+ * appended to @a argsOut.
+ */
+ template <class InputIt>
+ static void ExpandLists(InputIt first, InputIt last,
+ std::vector<std::string>& argsOut)
+ {
+ for (; first != last; ++first) {
+ cmSystemTools::ExpandListArgument(*first, argsOut);
+ }
+ }
+
+ /**
+ * Same as ExpandListArgument but a new vector is created containing
+ * the expanded arguments from the string @a arg.
+ */
+ static std::vector<std::string> ExpandedListArgument(const std::string& arg,
+ bool emptyArgs = false);
+
+ /**
+ * Same as ExpandList but a new vector is created containing the expanded
+ * versions of all arguments in the string range [@a first, @a last).
+ */
+ template <class InputIt>
+ static std::vector<std::string> ExpandedLists(InputIt first, InputIt last)
+ {
+ std::vector<std::string> argsOut;
+ for (; first != last; ++first) {
+ cmSystemTools::ExpandListArgument(*first, argsOut);
+ }
+ return argsOut;
+ }
+
+ /**
* Look for and replace registry values in a string
*/
static void ExpandRegistryValues(std::string& source,
KeyWOW64 view = KeyWOW64_Default);
- ///! Escape quotes in a string.
+ //! Escape quotes in a string.
static std::string EscapeQuotes(const std::string& str);
/** Map help document name to file name. */
@@ -53,63 +87,57 @@ public:
*/
static std::string TrimWhitespace(const std::string& s);
- typedef void (*MessageCallback)(const char*, const char*, bool&, void*);
+ using MessageCallback = std::function<void(const std::string&, const char*)>;
/**
* 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).
+ * title as a const char*.
*/
- static void SetMessageCallback(MessageCallback f,
- void* clientData = CM_NULLPTR);
+ static void SetMessageCallback(MessageCallback f);
/**
* Display an error message.
*/
- static void Error(const char* m, const char* m2 = CM_NULLPTR,
- const char* m3 = CM_NULLPTR, const char* m4 = CM_NULLPTR);
+ static void Error(const std::string& m);
/**
* Display a message.
*/
- static void Message(const char* m, const char* title = CM_NULLPTR);
+ static void Message(const std::string& m, const char* title = nullptr);
- typedef void (*OutputCallback)(const char*, size_t length, void*);
+ using OutputCallback = std::function<void(std::string const&)>;
- ///! 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 = CM_NULLPTR);
+ //! Send a string to stdout
+ static void Stdout(const std::string& s);
+ static void SetStdoutCallback(OutputCallback f);
- ///! 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 = CM_NULLPTR);
+ //! Send a string to stderr
+ static void Stderr(const std::string& s);
+ static void SetStderrCallback(OutputCallback f);
- typedef bool (*InterruptCallback)(void*);
- static void SetInterruptCallback(InterruptCallback f,
- void* clientData = CM_NULLPTR);
+ using InterruptCallback = std::function<bool()>;
+ static void SetInterruptCallback(InterruptCallback f);
static bool GetInterruptFlag();
- ///! Return true if there was an error at any point.
+ //! 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.
+ //! 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.
+ //! Return true if there was an error at any point.
static bool GetFatalErrorOccured()
{
return cmSystemTools::s_FatalErrorOccured || GetInterruptFlag();
}
- ///! Set the error occurred flag and fatal error back to false
+ //! Set the error occurred flag and fatal error back to false
static void ResetErrorOccuredFlag()
{
cmSystemTools::s_FatalErrorOccured = false;
@@ -127,6 +155,7 @@ public:
* as ifdef.
*/
static bool IsOn(const char* val);
+ static bool IsOn(const std::string& val);
/**
* does a string indicate a false or off value ? Note that this is
@@ -136,23 +165,24 @@ public:
* NOTFOUND, *-NOTFOUND or IGNORE will cause IsOff to return true.
*/
static bool IsOff(const char* val);
+ static bool IsOff(const std::string& val);
- ///! Return true if value is NOTFOUND or ends in -NOTFOUND.
+ //! 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);
+ //! Return true if the path is a framework
+ static bool IsPathToFramework(const std::string& value);
static bool DoesFileExistWithExtensions(
- const char* name, const std::vector<std::string>& sourceExts);
+ const std::string& 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 std::string FileExistsInParentDirectories(
+ const std::string& fname, const std::string& directory,
+ const std::string& toplevel);
static void Glob(const std::string& directory, const std::string& regexp,
std::vector<std::string>& files);
@@ -166,26 +196,24 @@ public:
* 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.
+ * files only. This method returns true if search was successful.
*/
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);
+ static bool RenameFile(const std::string& oldname,
+ const std::string& newname);
- ///! Compute the md5sum of a file
- static bool ComputeFileMD5(const std::string& source, char* md5out);
+ //! Compute the hash of a file
+ static std::string ComputeFileHash(const std::string& source,
+ cmCryptoHash::Algo algo);
/** Compute the md5sum of a string. */
static std::string ComputeStringMD5(const std::string& input);
- ///! Get the SHA thumbprint for a certificate file
+ //! Get the SHA thumbprint for a certificate file
static std::string ComputeCertificateThumbprint(const std::string& source);
/**
@@ -217,25 +245,25 @@ public:
OUTPUT_FORWARD,
OUTPUT_PASSTHROUGH
};
- static bool RunSingleCommand(const char* command,
- std::string* captureStdOut = CM_NULLPTR,
- std::string* captureStdErr = CM_NULLPTR,
- int* retVal = CM_NULLPTR,
- const char* dir = CM_NULLPTR,
+ static bool RunSingleCommand(const std::string& command,
+ std::string* captureStdOut = nullptr,
+ std::string* captureStdErr = nullptr,
+ int* retVal = nullptr,
+ const char* dir = nullptr,
OutputOption outputflag = OUTPUT_MERGE,
- double timeout = 0.0);
+ cmDuration timeout = cmDuration::zero());
/**
* 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()]
+ * be in command[1]...command[command.size()]
*/
static bool RunSingleCommand(std::vector<std::string> const& command,
- std::string* captureStdOut = CM_NULLPTR,
- std::string* captureStdErr = CM_NULLPTR,
- int* retVal = CM_NULLPTR,
- const char* dir = CM_NULLPTR,
+ std::string* captureStdOut = nullptr,
+ std::string* captureStdErr = nullptr,
+ int* retVal = nullptr,
+ const char* dir = nullptr,
OutputOption outputflag = OUTPUT_MERGE,
- double timeout = 0.0,
+ cmDuration timeout = cmDuration::zero(),
Encoding encoding = cmProcessOutput::Auto);
static std::string PrintSingleCommand(std::vector<std::string> const&);
@@ -243,7 +271,7 @@ public:
/**
* Parse arguments out of a single string command
*/
- static std::vector<std::string> ParseArguments(const char* command);
+ static std::vector<std::string> ParseArguments(const std::string& command);
/** Parse arguments out of a windows command line string. */
static void ParseWindowsCommandLine(const char* command,
@@ -253,6 +281,11 @@ public:
static void ParseUnixCommandLine(const char* command,
std::vector<std::string>& args);
+ /** Split a command-line string into the parsed command and the unparsed
+ arguments. Returns false on unfinished quoting or escaping. */
+ static bool SplitProgramFromArgs(std::string const& command,
+ std::string& program, std::string& args);
+
/**
* Handle response file in an argument list and return a new argument list
* **/
@@ -262,8 +295,6 @@ public:
static size_t CalculateCommandLineLengthLimit();
- 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; }
@@ -278,6 +309,7 @@ public:
CXX_FILE_FORMAT,
FORTRAN_FILE_FORMAT,
JAVA_FILE_FORMAT,
+ CUDA_FILE_FORMAT,
HEADER_FILE_FORMAT,
RESOURCE_FILE_FORMAT,
DEFINITION_FILE_FORMAT,
@@ -321,10 +353,10 @@ public:
/**
* Determine the file type based on the extension
*/
- static FileFormat GetFileFormat(const char* ext);
+ static FileFormat GetFileFormat(std::string const& ext);
/** Windows if this is true, the CreateProcess in RunCommand will
- * not show new consol windows when running programs.
+ * not show new console windows when running programs.
*/
static void SetRunCommandHideConsole(bool v) { s_RunCommandHideConsole = v; }
static bool GetRunCommandHideConsole() { return s_RunCommandHideConsole; }
@@ -335,23 +367,20 @@ public:
/** a general output handler for cmsysProcess */
static int WaitForLine(cmsysProcess* process, std::string& line,
- double timeout, std::vector<char>& out,
+ cmDuration 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 std::string ConvertToOutputPath(std::string const& 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);
+ static std::string ConvertToRunCommandPath(const std::string& path);
/** compute the relative path from local to remote. local must
be a directory. remote can be a file or a directory.
@@ -361,13 +390,16 @@ public:
/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);
+ static std::string RelativePath(std::string const& local,
+ std::string const& remote);
- /** Joins two paths while collapsing x/../ parts
- * For example CollapseCombinedPath("a/b/c", "../../d") results in "a/d"
+ /**
+ * Convert the given remote path to a relative path with respect to
+ * the given local path. Both paths must use forward slashes and not
+ * already be escaped or quoted.
*/
- static std::string CollapseCombinedPath(std::string const& dir,
- std::string const& file);
+ static std::string ForceToRelativePath(std::string const& local_path,
+ std::string const& remote_path);
#ifdef CMAKE_BUILD_WITH_CMAKE
/** Remove an environment variable */
@@ -386,11 +418,13 @@ public:
original environment. */
class SaveRestoreEnvironment
{
- CM_DISABLE_COPY(SaveRestoreEnvironment)
public:
SaveRestoreEnvironment();
~SaveRestoreEnvironment();
+ SaveRestoreEnvironment(SaveRestoreEnvironment const&) = delete;
+ SaveRestoreEnvironment& operator=(SaveRestoreEnvironment const&) = delete;
+
private:
std::vector<std::string> Env;
};
@@ -399,21 +433,33 @@ public:
/** Setup the environment to enable VS 8 IDE output. */
static void EnableVSConsoleOutput();
+ enum cmTarAction
+ {
+ TarActionCreate,
+ TarActionList,
+ TarActionExtract,
+ TarActionNone
+ };
+
/** Create tar */
enum cmTarCompression
{
TarCompressGZip,
TarCompressBZip2,
TarCompressXZ,
+ TarCompressZstd,
TarCompressNone
};
- static bool ListTar(const char* outFileName, bool verbose);
- static bool CreateTar(const char* outFileName,
+
+ static bool ListTar(const std::string& outFileName,
+ const std::vector<std::string>& files, bool verbose);
+ static bool CreateTar(const std::string& outFileName,
const std::vector<std::string>& files,
cmTarCompression compressType, bool verbose,
std::string const& mtime = std::string(),
std::string const& format = std::string());
- static bool ExtractTar(const char* inFileName, bool verbose);
+ static bool ExtractTar(const std::string& inFileName,
+ const std::vector<std::string>& files, 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
@@ -421,15 +467,7 @@ public:
// 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);
+ static void EnsureStdPipes();
/** Random seed generation. */
static unsigned int RandomSeed();
@@ -461,20 +499,19 @@ public:
/** 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 = CM_NULLPTR,
- bool* changed = CM_NULLPTR);
+ std::string* emsg = nullptr,
+ bool* changed = nullptr);
/** Try to remove the RPATH from an ELF binary. */
- static bool RemoveRPath(std::string const& file,
- std::string* emsg = CM_NULLPTR,
- bool* removed = CM_NULLPTR);
+ static bool RemoveRPath(std::string const& file, std::string* emsg = nullptr,
+ bool* removed = nullptr);
/** 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);
+ static bool RepeatedRemoveDirectory(const std::string& dir);
/** Tokenize a string */
static std::vector<std::string> tokenize(const std::string& str,
@@ -484,6 +521,10 @@ public:
static bool StringToLong(const char* str, long* value);
static bool StringToULong(const char* str, unsigned long* value);
+ /** Encode a string as a URL. */
+ static std::string EncodeURL(std::string const& in,
+ bool escapeSlashes = true);
+
#ifdef _WIN32
struct WindowsFileRetry
{
@@ -492,21 +533,34 @@ public:
};
static WindowsFileRetry GetWindowsFileRetry();
#endif
+
+ /** Get the real path for a given path, removing all symlinks.
+ This variant of GetRealPath also works on Windows but will
+ resolve subst drives too. */
+ static std::string GetRealPathResolvingWindowsSubst(
+ const std::string& path, std::string* errorMessage = nullptr);
+
+ /** Perform one-time initialization of libuv. */
+ static void InitializeLibUV();
+
+ /** Create a symbolic link if the platform supports it. Returns whether
+ creation succeeded. */
+ static bool CreateSymlink(const std::string& origName,
+ const std::string& newName,
+ std::string* errorMessage = nullptr);
+
+ /** Create a hard link if the platform supports it. Returns whether
+ creation succeeded. */
+ static bool CreateLink(const std::string& origName,
+ const std::string& newName,
+ std::string* errorMessage = nullptr);
+
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
index c95a3ca2c..98c66da2c 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -5,28 +5,33 @@
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <assert.h>
-#include <map>
+#include <initializer_list>
+#include <iterator>
#include <set>
#include <sstream>
#include <string.h>
+#include <unordered_set>
#include "cmAlgorithms.h"
+#include "cmCustomCommand.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmMessenger.h"
-#include "cmOutputConverter.h"
#include "cmProperty.h"
+#include "cmPropertyMap.h"
+#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
+#include "cmSourceFileLocationKind.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmTargetPropertyComputer.h"
-#include "cm_unordered_set.hxx"
#include "cmake.h"
template <>
@@ -75,34 +80,30 @@ const char* cmTargetPropertyComputer::GetSources<cmTarget>(
{
cmStringRange entries = tgt->GetSourceEntries();
if (entries.empty()) {
- return CM_NULLPTR;
+ return nullptr;
}
std::ostringstream ss;
const char* sep = "";
- for (std::vector<std::string>::const_iterator i = entries.begin();
- i != entries.end(); ++i) {
- std::string const& entry = *i;
-
+ for (std::string const& entry : entries) {
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);
+ for (std::string const& file : files) {
+ if (cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") &&
+ file.back() == '>') {
+ std::string objLibName = file.substr(17, file.size() - 18);
if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
ss << sep;
sep = ";";
- ss << *li;
+ ss << file;
continue;
}
bool addContent = false;
bool noMessage = true;
std::ostringstream e;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (context.GetBottom().GetPolicy(cmPolicies::CMP0051)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
@@ -116,28 +117,25 @@ const char* cmTargetPropertyComputer::GetSources<cmTarget>(
}
if (!noMessage) {
e << "Target \"" << tgt->GetName()
- << "\" 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.";
+ << "\" 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.";
messenger->IssueMessage(messageType, e.str(), context);
}
if (addContent) {
ss << sep;
sep = ";";
- ss << *li;
+ ss << file;
}
- } else if (cmGeneratorExpression::Find(*li) == std::string::npos) {
+ } else if (cmGeneratorExpression::Find(file) == std::string::npos) {
ss << sep;
sep = ";";
- ss << *li;
+ ss << file;
} else {
- cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(*li);
+ cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(file);
// Construct what is known about this source file location.
cmSourceFileLocation const& location = sf->GetLocation();
std::string sname = location.GetDirectory();
@@ -161,6 +159,27 @@ const char* cmTargetPropertyComputer::GetSources<cmTarget>(
class cmTargetInternals
{
public:
+ cmStateEnums::TargetType TargetType;
+ cmMakefile* Makefile;
+ cmPolicies::PolicyMap PolicyMap;
+ std::string Name;
+ std::string InstallPath;
+ std::string RuntimeInstallPath;
+ cmPropertyMap Properties;
+ bool IsGeneratorProvided;
+ bool HaveInstallRule;
+ bool DLLPlatform;
+ bool IsAndroid;
+ bool IsImportedTarget;
+ bool ImportedGloballyVisible;
+ bool BuildInterfaceIncludesAppended;
+ std::set<BT<std::string>> Utilities;
+ std::vector<cmCustomCommand> PreBuildCommands;
+ std::vector<cmCustomCommand> PreLinkCommands;
+ std::vector<cmCustomCommand> PostBuildCommands;
+ std::vector<cmInstallTargetGenerator*> InstallGenerators;
+ std::set<std::string> SystemIncludeDirectories;
+ cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
std::vector<std::string> IncludeDirectoriesEntries;
std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
std::vector<std::string> CompileOptionsEntries;
@@ -171,145 +190,199 @@ public:
std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
std::vector<std::string> SourceEntries;
std::vector<cmListFileBacktrace> SourceBacktraces;
+ std::vector<std::string> LinkOptionsEntries;
+ std::vector<cmListFileBacktrace> LinkOptionsBacktraces;
+ std::vector<std::string> LinkDirectoriesEntries;
+ std::vector<cmListFileBacktrace> LinkDirectoriesBacktraces;
std::vector<std::string> LinkImplementationPropertyEntries;
std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
+ std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>>
+ TLLCommands;
+ cmListFileBacktrace Backtrace;
+
+public:
+ bool CheckImportedLibName(std::string const& prop,
+ std::string const& value) const;
+
+ std::string ProcessSourceItemCMP0049(const std::string& s);
};
cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
Visibility vis, cmMakefile* mf)
+ : impl(cm::make_unique<cmTargetInternals>())
{
assert(mf);
- this->Name = name;
- this->TargetTypeValue = type;
- this->Makefile = mf;
- this->HaveInstallRule = false;
- this->DLLPlatform = false;
- this->IsAndroid = false;
- this->IsImportedTarget =
+ impl->TargetType = type;
+ impl->Makefile = mf;
+ impl->Name = name;
+ impl->IsGeneratorProvided = false;
+ impl->HaveInstallRule = false;
+ impl->DLLPlatform = false;
+ impl->IsAndroid = false;
+ impl->IsImportedTarget =
(vis == VisibilityImported || vis == VisibilityImportedGlobally);
- this->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
- this->BuildInterfaceIncludesAppended = false;
-
- // only add dependency information for library targets
- if (this->TargetTypeValue >= cmStateEnums::STATIC_LIBRARY &&
- this->TargetTypeValue <= cmStateEnums::MODULE_LIBRARY) {
- this->RecordDependencies = true;
- } else {
- this->RecordDependencies = false;
- }
+ impl->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
+ impl->BuildInterfaceIncludesAppended = false;
// Check whether this is a DLL platform.
- this->DLLPlatform =
- (this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") ||
- this->Makefile->IsOn("MINGW"));
+ impl->DLLPlatform =
+ !impl->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty();
// Check whether we are targeting an Android platform.
- this->IsAndroid =
- strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
- "Android") == 0;
+ impl->IsAndroid =
+ (impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Android");
+
+ std::string gKey;
+ gKey.reserve(128);
+ gKey += "CMAKE_";
+ auto InitProperty = [this, mf, &gKey](const std::string& property,
+ const char* default_value) {
+ // Replace everything after "CMAKE_"
+ gKey.replace(gKey.begin() + 6, gKey.end(), property);
+ if (const char* value = mf->GetDefinition(gKey)) {
+ this->SetProperty(property, value);
+ } else if (default_value) {
+ this->SetProperty(property, default_value);
+ }
+ };
// Setup default property values.
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
this->GetType() != cmStateEnums::UTILITY) {
- this->SetPropertyDefault("ANDROID_API", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_API_MIN", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_ARCH", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_STL_TYPE", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_PROCESS_MAX", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_PROGUARD", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", CM_NULLPTR);
- this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", CM_NULLPTR);
- this->SetPropertyDefault("BUILD_RPATH", CM_NULLPTR);
- this->SetPropertyDefault("INSTALL_NAME_DIR", CM_NULLPTR);
- this->SetPropertyDefault("INSTALL_RPATH", "");
- this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
- this->SetPropertyDefault("INTERPROCEDURAL_OPTIMIZATION", CM_NULLPTR);
- this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
- this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
- this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", CM_NULLPTR);
- this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", CM_NULLPTR);
- this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", CM_NULLPTR);
- this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", CM_NULLPTR);
- this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", CM_NULLPTR);
- this->SetPropertyDefault("Fortran_FORMAT", CM_NULLPTR);
- this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", CM_NULLPTR);
- this->SetPropertyDefault("GNUtoMS", CM_NULLPTR);
- this->SetPropertyDefault("OSX_ARCHITECTURES", CM_NULLPTR);
- this->SetPropertyDefault("IOS_INSTALL_COMBINED", CM_NULLPTR);
- this->SetPropertyDefault("AUTOMOC", CM_NULLPTR);
- this->SetPropertyDefault("AUTOUIC", CM_NULLPTR);
- this->SetPropertyDefault("AUTORCC", CM_NULLPTR);
- this->SetPropertyDefault("AUTOMOC_DEPEND_FILTERS", CM_NULLPTR);
- this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", CM_NULLPTR);
- this->SetPropertyDefault("AUTOUIC_OPTIONS", CM_NULLPTR);
- this->SetPropertyDefault("AUTOUIC_SEARCH_PATHS", CM_NULLPTR);
- this->SetPropertyDefault("AUTORCC_OPTIONS", CM_NULLPTR);
- this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", CM_NULLPTR);
- this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", CM_NULLPTR);
- this->SetPropertyDefault("WIN32_EXECUTABLE", CM_NULLPTR);
- this->SetPropertyDefault("MACOSX_BUNDLE", CM_NULLPTR);
- this->SetPropertyDefault("MACOSX_RPATH", CM_NULLPTR);
- this->SetPropertyDefault("BUILD_WITH_INSTALL_NAME_DIR", CM_NULLPTR);
- this->SetPropertyDefault("C_CLANG_TIDY", CM_NULLPTR);
- this->SetPropertyDefault("C_COMPILER_LAUNCHER", CM_NULLPTR);
- this->SetPropertyDefault("C_CPPLINT", CM_NULLPTR);
- this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", CM_NULLPTR);
- this->SetPropertyDefault("LINK_WHAT_YOU_USE", CM_NULLPTR);
- this->SetPropertyDefault("C_STANDARD", CM_NULLPTR);
- this->SetPropertyDefault("C_STANDARD_REQUIRED", CM_NULLPTR);
- this->SetPropertyDefault("C_EXTENSIONS", CM_NULLPTR);
- this->SetPropertyDefault("CXX_CLANG_TIDY", CM_NULLPTR);
- this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", CM_NULLPTR);
- this->SetPropertyDefault("CXX_CPPLINT", CM_NULLPTR);
- this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", CM_NULLPTR);
- this->SetPropertyDefault("CXX_STANDARD", CM_NULLPTR);
- this->SetPropertyDefault("CXX_STANDARD_REQUIRED", CM_NULLPTR);
- this->SetPropertyDefault("CXX_EXTENSIONS", CM_NULLPTR);
- this->SetPropertyDefault("CUDA_STANDARD", CM_NULLPTR);
- this->SetPropertyDefault("CUDA_STANDARD_REQUIRED", CM_NULLPTR);
- this->SetPropertyDefault("CUDA_EXTENSIONS", CM_NULLPTR);
- this->SetPropertyDefault("LINK_SEARCH_START_STATIC", CM_NULLPTR);
- this->SetPropertyDefault("LINK_SEARCH_END_STATIC", CM_NULLPTR);
+ InitProperty("ANDROID_API", nullptr);
+ InitProperty("ANDROID_API_MIN", nullptr);
+ InitProperty("ANDROID_ARCH", nullptr);
+ InitProperty("ANDROID_STL_TYPE", nullptr);
+ InitProperty("ANDROID_SKIP_ANT_STEP", nullptr);
+ InitProperty("ANDROID_PROCESS_MAX", nullptr);
+ InitProperty("ANDROID_PROGUARD", nullptr);
+ InitProperty("ANDROID_PROGUARD_CONFIG_PATH", nullptr);
+ InitProperty("ANDROID_SECURE_PROPS_PATH", nullptr);
+ InitProperty("ANDROID_NATIVE_LIB_DIRECTORIES", nullptr);
+ InitProperty("ANDROID_NATIVE_LIB_DEPENDENCIES", nullptr);
+ InitProperty("ANDROID_JAVA_SOURCE_DIR", nullptr);
+ InitProperty("ANDROID_JAR_DIRECTORIES", nullptr);
+ InitProperty("ANDROID_JAR_DEPENDENCIES", nullptr);
+ InitProperty("ANDROID_ASSETS_DIRECTORIES", nullptr);
+ InitProperty("ANDROID_ANT_ADDITIONAL_OPTIONS", nullptr);
+ InitProperty("BUILD_RPATH", nullptr);
+ InitProperty("BUILD_RPATH_USE_ORIGIN", nullptr);
+ InitProperty("INSTALL_NAME_DIR", nullptr);
+ InitProperty("INSTALL_RPATH", "");
+ InitProperty("INSTALL_RPATH_USE_LINK_PATH", "OFF");
+ InitProperty("INTERPROCEDURAL_OPTIMIZATION", nullptr);
+ InitProperty("SKIP_BUILD_RPATH", "OFF");
+ InitProperty("BUILD_WITH_INSTALL_RPATH", "OFF");
+ InitProperty("ARCHIVE_OUTPUT_DIRECTORY", nullptr);
+ InitProperty("LIBRARY_OUTPUT_DIRECTORY", nullptr);
+ InitProperty("RUNTIME_OUTPUT_DIRECTORY", nullptr);
+ InitProperty("PDB_OUTPUT_DIRECTORY", nullptr);
+ InitProperty("COMPILE_PDB_OUTPUT_DIRECTORY", nullptr);
+ InitProperty("FRAMEWORK", nullptr);
+ InitProperty("Fortran_FORMAT", nullptr);
+ InitProperty("Fortran_MODULE_DIRECTORY", nullptr);
+ InitProperty("Fortran_COMPILER_LAUNCHER", nullptr);
+ InitProperty("GNUtoMS", nullptr);
+ InitProperty("OSX_ARCHITECTURES", nullptr);
+ InitProperty("IOS_INSTALL_COMBINED", nullptr);
+ InitProperty("AUTOMOC", nullptr);
+ InitProperty("AUTOUIC", nullptr);
+ InitProperty("AUTORCC", nullptr);
+ InitProperty("AUTOGEN_ORIGIN_DEPENDS", nullptr);
+ InitProperty("AUTOGEN_PARALLEL", nullptr);
+ InitProperty("AUTOMOC_COMPILER_PREDEFINES", nullptr);
+ InitProperty("AUTOMOC_DEPEND_FILTERS", nullptr);
+ InitProperty("AUTOMOC_MACRO_NAMES", nullptr);
+ InitProperty("AUTOMOC_MOC_OPTIONS", nullptr);
+ InitProperty("AUTOUIC_OPTIONS", nullptr);
+ InitProperty("AUTOUIC_SEARCH_PATHS", nullptr);
+ InitProperty("AUTORCC_OPTIONS", nullptr);
+ InitProperty("LINK_DEPENDS_NO_SHARED", nullptr);
+ InitProperty("LINK_INTERFACE_LIBRARIES", nullptr);
+ InitProperty("MSVC_RUNTIME_LIBRARY", nullptr);
+ InitProperty("WIN32_EXECUTABLE", nullptr);
+ InitProperty("MACOSX_BUNDLE", nullptr);
+ InitProperty("MACOSX_RPATH", nullptr);
+ InitProperty("NO_SYSTEM_FROM_IMPORTED", nullptr);
+ InitProperty("BUILD_WITH_INSTALL_NAME_DIR", nullptr);
+ InitProperty("C_CLANG_TIDY", nullptr);
+ InitProperty("C_COMPILER_LAUNCHER", nullptr);
+ InitProperty("C_CPPLINT", nullptr);
+ InitProperty("C_CPPCHECK", nullptr);
+ InitProperty("C_INCLUDE_WHAT_YOU_USE", nullptr);
+ InitProperty("LINK_WHAT_YOU_USE", nullptr);
+ InitProperty("C_STANDARD", nullptr);
+ InitProperty("C_STANDARD_REQUIRED", nullptr);
+ InitProperty("C_EXTENSIONS", nullptr);
+ InitProperty("CXX_CLANG_TIDY", nullptr);
+ InitProperty("CXX_COMPILER_LAUNCHER", nullptr);
+ InitProperty("CXX_CPPLINT", nullptr);
+ InitProperty("CXX_CPPCHECK", nullptr);
+ InitProperty("CXX_INCLUDE_WHAT_YOU_USE", nullptr);
+ InitProperty("CXX_STANDARD", nullptr);
+ InitProperty("CXX_STANDARD_REQUIRED", nullptr);
+ InitProperty("CXX_EXTENSIONS", nullptr);
+ InitProperty("CUDA_STANDARD", nullptr);
+ InitProperty("CUDA_STANDARD_REQUIRED", nullptr);
+ InitProperty("CUDA_EXTENSIONS", nullptr);
+ InitProperty("CUDA_COMPILER_LAUNCHER", nullptr);
+ InitProperty("CUDA_SEPARABLE_COMPILATION", nullptr);
+ InitProperty("LINK_SEARCH_START_STATIC", nullptr);
+ InitProperty("LINK_SEARCH_END_STATIC", nullptr);
+ InitProperty("FOLDER", nullptr);
+ InitProperty("Swift_MODULE_DIRECTORY", nullptr);
+ InitProperty("VS_JUST_MY_CODE_DEBUGGING", nullptr);
+#ifdef __APPLE__
+ if (this->GetGlobalGenerator()->IsXcode()) {
+ InitProperty("XCODE_SCHEME_ADDRESS_SANITIZER", nullptr);
+ InitProperty("XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN", nullptr);
+ InitProperty("XCODE_SCHEME_THREAD_SANITIZER", nullptr);
+ InitProperty("XCODE_SCHEME_THREAD_SANITIZER_STOP", nullptr);
+ InitProperty("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER", nullptr);
+ InitProperty("XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP", nullptr);
+ InitProperty("XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER", nullptr);
+ InitProperty("XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP", nullptr);
+ InitProperty("XCODE_SCHEME_MALLOC_SCRIBBLE", nullptr);
+ InitProperty("XCODE_SCHEME_MALLOC_GUARD_EDGES", nullptr);
+ InitProperty("XCODE_SCHEME_GUARD_MALLOC", nullptr);
+ InitProperty("XCODE_SCHEME_ZOMBIE_OBJECTS", nullptr);
+ InitProperty("XCODE_SCHEME_MALLOC_STACK", nullptr);
+ InitProperty("XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE", nullptr);
+ InitProperty("XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS", nullptr);
+ }
+#endif
}
- if (this->GetType() != cmStateEnums::UTILITY) {
- this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", CM_NULLPTR);
+ if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
+ if (this->GetGlobalGenerator()->IsXcode()) {
+ InitProperty("XCODE_GENERATE_SCHEME", nullptr);
+ }
}
- // Collect the set of configuration types.
- std::vector<std::string> configNames;
- mf->GetConfigurations(configNames);
-
// Setup per-configuration property default values.
if (this->GetType() != cmStateEnums::UTILITY) {
- const char* configProps[] = {
+ static const auto configProps = {
/* clang-format needs this comment to break after the opening brace */
"ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_",
"RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_",
"COMPILE_PDB_OUTPUT_DIRECTORY_", "MAP_IMPORTED_CONFIG_",
- "INTERPROCEDURAL_OPTIMIZATION_", CM_NULLPTR
+ "INTERPROCEDURAL_OPTIMIZATION_"
};
- 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) {
+ // Collect the set of configuration types.
+ std::vector<std::string> configNames;
+ mf->GetConfigurations(configNames);
+ for (std::string const& configName : configNames) {
+ std::string configUpper = cmSystemTools::UpperCase(configName);
+ for (auto const& prop : configProps) {
// Interface libraries have no output locations, so honor only
// the configuration map.
- if (this->TargetTypeValue == cmStateEnums::INTERFACE_LIBRARY &&
- strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0) {
+ if (impl->TargetType == cmStateEnums::INTERFACE_LIBRARY &&
+ strcmp(prop, "MAP_IMPORTED_CONFIG_") != 0) {
continue;
}
- std::string property = *p;
+ std::string property = prop;
property += configUpper;
- this->SetPropertyDefault(property, CM_NULLPTR);
+ InitProperty(property, nullptr);
}
// Initialize per-configuration name postfix property from the
@@ -317,125 +390,171 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
// compatibility with previous CMake versions in which executables
// did not support this variable. Projects may still specify the
// property directly.
- if (this->TargetTypeValue != cmStateEnums::EXECUTABLE &&
- this->TargetTypeValue != cmStateEnums::INTERFACE_LIBRARY) {
- std::string property = cmSystemTools::UpperCase(*ci);
+ if (impl->TargetType != cmStateEnums::EXECUTABLE &&
+ impl->TargetType != cmStateEnums::INTERFACE_LIBRARY) {
+ std::string property = cmSystemTools::UpperCase(configName);
property += "_POSTFIX";
- this->SetPropertyDefault(property, CM_NULLPTR);
+ InitProperty(property, nullptr);
}
}
}
// Save the backtrace of target construction.
- this->Backtrace = this->Makefile->GetBacktrace();
+ impl->Backtrace = impl->Makefile->GetBacktrace();
if (!this->IsImported()) {
// Initialize the INCLUDE_DIRECTORIES property based on the current value
// of the same directory property:
- const cmStringRange parentIncludes =
- this->Makefile->GetIncludeDirectoriesEntries();
- const cmBacktraceRange parentIncludesBts =
- this->Makefile->GetIncludeDirectoriesBacktraces();
-
- this->Internal->IncludeDirectoriesEntries.insert(
- this->Internal->IncludeDirectoriesEntries.end(), parentIncludes.begin(),
- parentIncludes.end());
- this->Internal->IncludeDirectoriesBacktraces.insert(
- this->Internal->IncludeDirectoriesBacktraces.end(),
- parentIncludesBts.begin(), parentIncludesBts.end());
-
- const std::set<std::string> parentSystemIncludes =
- this->Makefile->GetSystemIncludeDirectories();
+ cmAppend(impl->IncludeDirectoriesEntries,
+ impl->Makefile->GetIncludeDirectoriesEntries());
+ cmAppend(impl->IncludeDirectoriesBacktraces,
+ impl->Makefile->GetIncludeDirectoriesBacktraces());
+
+ {
+ auto const& sysInc = impl->Makefile->GetSystemIncludeDirectories();
+ impl->SystemIncludeDirectories.insert(sysInc.begin(), sysInc.end());
+ }
- this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
- parentSystemIncludes.end());
+ cmAppend(impl->CompileOptionsEntries,
+ impl->Makefile->GetCompileOptionsEntries());
+ cmAppend(impl->CompileOptionsBacktraces,
+ impl->Makefile->GetCompileOptionsBacktraces());
- const cmStringRange parentOptions =
- this->Makefile->GetCompileOptionsEntries();
- const cmBacktraceRange parentOptionsBts =
- this->Makefile->GetCompileOptionsBacktraces();
+ cmAppend(impl->LinkOptionsEntries,
+ impl->Makefile->GetLinkOptionsEntries());
+ cmAppend(impl->LinkOptionsBacktraces,
+ impl->Makefile->GetLinkOptionsBacktraces());
- this->Internal->CompileOptionsEntries.insert(
- this->Internal->CompileOptionsEntries.end(), parentOptions.begin(),
- parentOptions.end());
- this->Internal->CompileOptionsBacktraces.insert(
- this->Internal->CompileOptionsBacktraces.end(), parentOptionsBts.begin(),
- parentOptionsBts.end());
+ cmAppend(impl->LinkDirectoriesEntries,
+ impl->Makefile->GetLinkDirectoriesEntries());
+ cmAppend(impl->LinkDirectoriesBacktraces,
+ impl->Makefile->GetLinkDirectoriesBacktraces());
}
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
this->GetType() != cmStateEnums::UTILITY) {
- this->SetPropertyDefault("C_VISIBILITY_PRESET", CM_NULLPTR);
- this->SetPropertyDefault("CXX_VISIBILITY_PRESET", CM_NULLPTR);
- this->SetPropertyDefault("CUDA_VISIBILITY_PRESET", CM_NULLPTR);
- this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", CM_NULLPTR);
+ InitProperty("C_VISIBILITY_PRESET", nullptr);
+ InitProperty("CXX_VISIBILITY_PRESET", nullptr);
+ InitProperty("CUDA_VISIBILITY_PRESET", nullptr);
+ InitProperty("VISIBILITY_INLINES_HIDDEN", nullptr);
}
- if (this->TargetTypeValue == cmStateEnums::EXECUTABLE) {
- this->SetPropertyDefault("ANDROID_GUI", CM_NULLPTR);
- this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", CM_NULLPTR);
- this->SetPropertyDefault("ENABLE_EXPORTS", CM_NULLPTR);
+ if (impl->TargetType == cmStateEnums::EXECUTABLE) {
+ InitProperty("ANDROID_GUI", nullptr);
+ InitProperty("CROSSCOMPILING_EMULATOR", nullptr);
+ InitProperty("ENABLE_EXPORTS", nullptr);
}
- if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY ||
- this->TargetTypeValue == cmStateEnums::MODULE_LIBRARY) {
+ if (impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
+ impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
}
- if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY ||
- this->TargetTypeValue == cmStateEnums::EXECUTABLE) {
- this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", CM_NULLPTR);
+ if (impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
+ impl->TargetType == cmStateEnums::EXECUTABLE) {
+ InitProperty("WINDOWS_EXPORT_ALL_SYMBOLS", nullptr);
}
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
this->GetType() != cmStateEnums::UTILITY) {
- this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", CM_NULLPTR);
+ InitProperty("POSITION_INDEPENDENT_CODE", nullptr);
}
// Record current policies for later use.
- this->Makefile->RecordPolicies(this->PolicyMap);
+ impl->Makefile->RecordPolicies(impl->PolicyMap);
- if (this->TargetTypeValue == cmStateEnums::INTERFACE_LIBRARY) {
+ if (impl->TargetType == cmStateEnums::INTERFACE_LIBRARY) {
// This policy is checked in a few conditions. The properties relevant
// to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
// targets,
// so ensure that the conditions don't lead to nonsense.
- this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
+ impl->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
}
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
this->GetType() != cmStateEnums::UTILITY) {
- this->SetPropertyDefault("JOB_POOL_COMPILE", CM_NULLPTR);
- this->SetPropertyDefault("JOB_POOL_LINK", CM_NULLPTR);
+ InitProperty("JOB_POOL_COMPILE", nullptr);
+ InitProperty("JOB_POOL_LINK", nullptr);
+ }
+
+ if (impl->TargetType <= cmStateEnums::UTILITY) {
+ InitProperty("DOTNET_TARGET_FRAMEWORK_VERSION", nullptr);
+ }
+
+ if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
+ this->GetType() != cmStateEnums::UTILITY) {
+
+ // check for "CMAKE_VS_GLOBALS" variable and set up target properties
+ // if any
+ const char* globals = mf->GetDefinition("CMAKE_VS_GLOBALS");
+ if (globals) {
+ const std::string genName = mf->GetGlobalGenerator()->GetName();
+ if (cmHasLiteralPrefix(genName, "Visual Studio")) {
+ std::vector<std::string> props;
+ cmSystemTools::ExpandListArgument(globals, props);
+ const std::string vsGlobal = "VS_GLOBAL_";
+ for (const std::string& i : props) {
+ // split NAME=VALUE
+ const std::string::size_type assignment = i.find('=');
+ if (assignment != std::string::npos) {
+ const std::string propName = vsGlobal + i.substr(0, assignment);
+ const std::string propValue = i.substr(assignment + 1);
+ InitProperty(propName, propValue.c_str());
+ }
+ }
+ }
+ }
}
}
-cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
+cmTarget::cmTarget(cmTarget&&) noexcept = default;
+cmTarget::~cmTarget() = default;
+
+cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default;
+
+cmStateEnums::TargetType cmTarget::GetType() const
{
- return this->GetMakefile()->GetGlobalGenerator();
+ return impl->TargetType;
}
-void cmTarget::AddUtility(const std::string& u, cmMakefile* makefile)
+cmMakefile* cmTarget::GetMakefile() const
{
- if (this->Utilities.insert(u).second && makefile) {
- this->UtilityBacktraces.insert(
- std::make_pair(u, makefile->GetBacktrace()));
- }
+ return impl->Makefile;
}
-cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
- const std::string& u) const
+cmPolicies::PolicyMap const& cmTarget::GetPolicyMap() const
{
- std::map<std::string, cmListFileBacktrace>::const_iterator i =
- this->UtilityBacktraces.find(u);
- if (i == this->UtilityBacktraces.end()) {
- return CM_NULLPTR;
- }
+ return impl->PolicyMap;
+}
+
+const std::string& cmTarget::GetName() const
+{
+ return impl->Name;
+}
- return &i->second;
+cmPolicies::PolicyStatus cmTarget::GetPolicyStatus(
+ cmPolicies::PolicyID policy) const
+{
+ return impl->PolicyMap.Get(policy);
+}
+
+cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
+{
+ return impl->Makefile->GetGlobalGenerator();
+}
+
+void cmTarget::AddUtility(std::string const& name, cmMakefile* mf)
+{
+ impl->Utilities.insert(
+ BT<std::string>(name, mf ? mf->GetBacktrace() : cmListFileBacktrace()));
+}
+
+std::set<BT<std::string>> const& cmTarget::GetUtilities() const
+{
+ return impl->Utilities;
}
cmListFileBacktrace const& cmTarget::GetBacktrace() const
{
- return this->Backtrace;
+ return impl->Backtrace;
}
bool cmTarget::IsExecutableWithExports() const
@@ -444,34 +563,57 @@ bool cmTarget::IsExecutableWithExports() const
this->GetPropertyAsBool("ENABLE_EXPORTS"));
}
-bool cmTarget::HasImportLibrary() const
-{
- return (this->DLLPlatform &&
- (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
- this->IsExecutableWithExports()));
-}
-
bool cmTarget::IsFrameworkOnApple() const
{
return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
- this->Makefile->IsOn("APPLE") &&
+ impl->Makefile->IsOn("APPLE") &&
this->GetPropertyAsBool("FRAMEWORK"));
}
bool cmTarget::IsAppBundleOnApple() const
{
return (this->GetType() == cmStateEnums::EXECUTABLE &&
- this->Makefile->IsOn("APPLE") &&
+ impl->Makefile->IsOn("APPLE") &&
this->GetPropertyAsBool("MACOSX_BUNDLE"));
}
+std::vector<cmCustomCommand> const& cmTarget::GetPreBuildCommands() const
+{
+ return impl->PreBuildCommands;
+}
+
+void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd)
+{
+ impl->PreBuildCommands.push_back(cmd);
+}
+
+std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const
+{
+ return impl->PreLinkCommands;
+}
+
+void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd)
+{
+ impl->PreLinkCommands.push_back(cmd);
+}
+
+std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const
+{
+ return impl->PostBuildCommands;
+}
+
+void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd)
+{
+ impl->PostBuildCommands.push_back(cmd);
+}
+
void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
{
if (!srcs.empty()) {
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->SourceEntries.push_back(cmJoin(srcs, ";"));
- this->Internal->SourceBacktraces.push_back(lfbt);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->SourceEntries.push_back(cmJoin(srcs, ";"));
+ impl->SourceBacktraces.push_back(lfbt);
}
}
@@ -479,42 +621,38 @@ 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] == '<')) {
+ for (auto filename : srcs) {
+ if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) {
if (!filename.empty()) {
- filename = this->ProcessSourceItemCMP0049(filename);
+ filename = impl->ProcessSourceItemCMP0049(filename);
if (filename.empty()) {
return;
}
}
- this->Makefile->GetOrCreateSource(filename);
+ impl->Makefile->GetOrCreateSource(filename);
}
srcFiles += sep;
srcFiles += filename;
sep = ";";
}
if (!srcFiles.empty()) {
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->SourceEntries.push_back(srcFiles);
- this->Internal->SourceBacktraces.push_back(lfbt);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->SourceEntries.push_back(std::move(srcFiles));
+ impl->SourceBacktraces.push_back(lfbt);
}
}
-std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
+std::string cmTargetInternals::ProcessSourceItemCMP0049(const std::string& s)
{
std::string src = s;
- // For backwards compatibility replace varibles in source names.
+ // For backwards compatibility replace variables in source names.
// This should eventually be removed.
this->Makefile->ExpandVariablesInString(src);
if (src != s) {
std::ostringstream e;
bool noMessage = false;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
@@ -525,15 +663,15 @@ std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
}
if (!noMessage) {
e << "Legacy variable expansion in source file \"" << s
- << "\" expanded to \"" << src << "\" in target \"" << this->GetName()
+ << "\" expanded to \"" << src << "\" in target \"" << this->Name
<< "\". This behavior will be removed in a "
"future version of CMake.";
this->Makefile->IssueMessage(messageType, e.str());
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::FATAL_ERROR) {
return "";
}
}
@@ -543,9 +681,9 @@ std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
{
- std::string src = this->ProcessSourceItemCMP0049(s);
+ std::string src = impl->ProcessSourceItemCMP0049(s);
if (!s.empty() && src.empty()) {
- return CM_NULLPTR;
+ return nullptr;
}
return this->AddSource(src);
}
@@ -595,8 +733,9 @@ public:
{
std::vector<std::string> files;
cmSystemTools::ExpandListArgument(entry, files);
- std::vector<cmSourceFileLocation> locations(files.size());
- std::transform(files.begin(), files.end(), locations.begin(),
+ std::vector<cmSourceFileLocation> locations;
+ locations.reserve(files.size());
+ std::transform(files.begin(), files.end(), std::back_inserter(locations),
CreateLocation(this->Needle.GetMakefile()));
return std::find_if(locations.begin(), locations.end(),
@@ -604,57 +743,32 @@ public:
}
};
-cmSourceFile* cmTarget::AddSource(const std::string& src)
+cmSourceFile* cmTarget::AddSource(const std::string& src, bool before)
{
- cmSourceFileLocation sfl(this->Makefile, src);
- if (std::find_if(this->Internal->SourceEntries.begin(),
- this->Internal->SourceEntries.end(),
+ cmSourceFileLocation sfl(impl->Makefile, src,
+ cmSourceFileLocationKind::Known);
+ if (std::find_if(impl->SourceEntries.begin(), impl->SourceEntries.end(),
TargetPropertyEntryFinder(sfl)) ==
- this->Internal->SourceEntries.end()) {
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->SourceEntries.push_back(src);
- this->Internal->SourceBacktraces.push_back(lfbt);
+ impl->SourceEntries.end()) {
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->SourceEntries.insert(
+ before ? impl->SourceEntries.begin() : impl->SourceEntries.end(), src);
+ impl->SourceBacktraces.insert(before ? impl->SourceBacktraces.begin()
+ : impl->SourceBacktraces.end(),
+ lfbt);
}
if (cmGeneratorExpression::Find(src) != std::string::npos) {
- return CM_NULLPTR;
+ return nullptr;
}
- return this->Makefile->GetOrCreateSource(src);
+ return impl->Makefile->GetOrCreateSource(src, false,
+ cmSourceFileLocationKind::Known);
}
-void cmTarget::AddLinkDirectory(const std::string& d)
+void cmTarget::ClearDependencyInformation(cmMakefile& mf)
{
- // 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;
-}
-
-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;
+ std::string depname = this->GetName();
depname += "_LIB_DEPENDS";
- if (this->RecordDependencies) {
- mf.AddCacheDefinition(depname, "", "Dependencies for target",
- cmStateEnums::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());
- }
- }
+ mf.RemoveCacheDefinition(depname);
}
std::string cmTarget::GetDebugGeneratorExpressions(
@@ -666,15 +780,13 @@ std::string cmTarget::GetDebugGeneratorExpressions(
// Get the list of configurations considered to be DEBUG.
std::vector<std::string> debugConfigs =
- this->Makefile->GetCMakeInstance()->GetDebugConfigs();
+ impl->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 + ">";
+ for (std::string const& conf : cmMakeRange(debugConfigs).advance(1)) {
+ configString += ",$<CONFIG:" + conf + ">";
}
configString = "$<OR:" + configString + ">";
}
@@ -694,13 +806,13 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
cmListFileContext const& lfc)
{
bool ret = true;
- if (!this->TLLCommands.empty()) {
- if (this->TLLCommands.back().first != signature) {
+ if (!impl->TLLCommands.empty()) {
+ if (impl->TLLCommands.back().first != signature) {
ret = false;
}
}
- if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc) {
- this->TLLCommands.push_back(std::make_pair(signature, lfc));
+ if (impl->TLLCommands.empty() || impl->TLLCommands.back().second != lfc) {
+ impl->TLLCommands.emplace_back(signature, lfc);
}
return ret;
}
@@ -710,47 +822,108 @@ void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
const char* sigString =
(sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
s << "The uses of the " << sigString << " signature are here:\n";
- typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
- cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
- for (Container::const_iterator it = this->TLLCommands.begin();
- it != this->TLLCommands.end(); ++it) {
- if (it->first == sig) {
- cmListFileContext lfc = it->second;
- lfc.FilePath = converter.ConvertToRelativePath(
- this->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
+ cmStateDirectory cmDir = impl->Makefile->GetStateSnapshot().GetDirectory();
+ for (auto const& cmd : impl->TLLCommands) {
+ if (cmd.first == sig) {
+ cmListFileContext lfc = cmd.second;
+ lfc.FilePath = cmDir.ConvertToRelPathIfNotContained(
+ impl->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
s << " * " << lfc << std::endl;
}
}
}
+std::string const& cmTarget::GetInstallPath() const
+{
+ return impl->InstallPath;
+}
+
+void cmTarget::SetInstallPath(std::string const& name)
+{
+ impl->InstallPath = name;
+}
+
+std::string const& cmTarget::GetRuntimeInstallPath() const
+{
+ return impl->RuntimeInstallPath;
+}
+
+void cmTarget::SetRuntimeInstallPath(std::string const& name)
+{
+ impl->RuntimeInstallPath = name;
+}
+
+bool cmTarget::GetHaveInstallRule() const
+{
+ return impl->HaveInstallRule;
+}
+
+void cmTarget::SetHaveInstallRule(bool hir)
+{
+ impl->HaveInstallRule = hir;
+}
+
+void cmTarget::AddInstallGenerator(cmInstallTargetGenerator* g)
+{
+ impl->InstallGenerators.emplace_back(g);
+}
+
+std::vector<cmInstallTargetGenerator*> const& cmTarget::GetInstallGenerators()
+ const
+{
+ return impl->InstallGenerators;
+}
+
+bool cmTarget::GetIsGeneratorProvided() const
+{
+ return impl->IsGeneratorProvided;
+}
+
+void cmTarget::SetIsGeneratorProvided(bool igp)
+{
+ impl->IsGeneratorProvided = igp;
+}
+
+cmTarget::LinkLibraryVectorType const& cmTarget::GetOriginalLinkLibraries()
+ const
+{
+ return impl->OriginalLinkLibraries;
+}
+
void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib,
cmTargetLinkLibraryType llt)
{
- cmTarget* tgt = this->Makefile->FindTargetToUse(lib);
+ this->AddLinkLibrary(mf, lib, lib, llt);
+}
+
+void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
+ std::string const& libRef,
+ cmTargetLinkLibraryType llt)
+{
+ cmTarget* tgt = mf.FindTargetToUse(lib);
{
const bool isNonImportedTarget = tgt && !tgt->IsImported();
const std::string libName =
(isNonImportedTarget && llt != GENERAL_LibraryType)
- ? targetNameGenex(lib)
- : lib;
+ ? targetNameGenex(libRef)
+ : libRef;
this->AppendProperty(
"LINK_LIBRARIES",
this->GetDebugGeneratorExpressions(libName, llt).c_str());
}
- if (cmGeneratorExpression::Find(lib) != std::string::npos ||
- (tgt && tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) ||
- (this->Name == lib)) {
+ if (cmGeneratorExpression::Find(lib) != std::string::npos || lib != libRef ||
+ (tgt &&
+ (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
+ tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) ||
+ (impl->Name == lib)) {
return;
}
- cmTarget::LibraryID tmp;
- tmp.first = lib;
- tmp.second = llt;
- this->OriginalLinkLibraries.push_back(tmp);
+ impl->OriginalLinkLibraries.emplace_back(lib, llt);
- // Add the explicit dependency information for this target. This is
+ // Add the explicit dependency information for libraries. 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.
@@ -758,8 +931,11 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib,
// 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 = this->Name;
+ if (impl->TargetType >= cmStateEnums::STATIC_LIBRARY &&
+ impl->TargetType <= cmStateEnums::MODULE_LIBRARY &&
+ (this->GetPolicyStatusCMP0073() == cmPolicies::OLD ||
+ this->GetPolicyStatusCMP0073() == cmPolicies::WARN)) {
+ std::string targetEntry = impl->Name;
targetEntry += "_LIB_DEPENDS";
std::string dependencies;
const char* old_val = mf.GetDefinition(targetEntry);
@@ -787,170 +963,247 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib,
void cmTarget::AddSystemIncludeDirectories(const std::set<std::string>& incs)
{
- this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
+ impl->SystemIncludeDirectories.insert(incs.begin(), incs.end());
+}
+
+std::set<std::string> const& cmTarget::GetSystemIncludeDirectories() const
+{
+ return impl->SystemIncludeDirectories;
}
cmStringRange cmTarget::GetIncludeDirectoriesEntries() const
{
- return cmMakeRange(this->Internal->IncludeDirectoriesEntries);
+ return cmMakeRange(impl->IncludeDirectoriesEntries);
}
cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
{
- return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces);
+ return cmMakeRange(impl->IncludeDirectoriesBacktraces);
}
cmStringRange cmTarget::GetCompileOptionsEntries() const
{
- return cmMakeRange(this->Internal->CompileOptionsEntries);
+ return cmMakeRange(impl->CompileOptionsEntries);
}
cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
{
- return cmMakeRange(this->Internal->CompileOptionsBacktraces);
+ return cmMakeRange(impl->CompileOptionsBacktraces);
}
cmStringRange cmTarget::GetCompileFeaturesEntries() const
{
- return cmMakeRange(this->Internal->CompileFeaturesEntries);
+ return cmMakeRange(impl->CompileFeaturesEntries);
}
cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const
{
- return cmMakeRange(this->Internal->CompileFeaturesBacktraces);
+ return cmMakeRange(impl->CompileFeaturesBacktraces);
}
cmStringRange cmTarget::GetCompileDefinitionsEntries() const
{
- return cmMakeRange(this->Internal->CompileDefinitionsEntries);
+ return cmMakeRange(impl->CompileDefinitionsEntries);
}
cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
{
- return cmMakeRange(this->Internal->CompileDefinitionsBacktraces);
+ return cmMakeRange(impl->CompileDefinitionsBacktraces);
}
cmStringRange cmTarget::GetSourceEntries() const
{
- return cmMakeRange(this->Internal->SourceEntries);
+ return cmMakeRange(impl->SourceEntries);
}
cmBacktraceRange cmTarget::GetSourceBacktraces() const
{
- return cmMakeRange(this->Internal->SourceBacktraces);
+ return cmMakeRange(impl->SourceBacktraces);
+}
+
+cmStringRange cmTarget::GetLinkOptionsEntries() const
+{
+ return cmMakeRange(impl->LinkOptionsEntries);
+}
+
+cmBacktraceRange cmTarget::GetLinkOptionsBacktraces() const
+{
+ return cmMakeRange(impl->LinkOptionsBacktraces);
+}
+
+cmStringRange cmTarget::GetLinkDirectoriesEntries() const
+{
+ return cmMakeRange(impl->LinkDirectoriesEntries);
+}
+
+cmBacktraceRange cmTarget::GetLinkDirectoriesBacktraces() const
+{
+ return cmMakeRange(impl->LinkDirectoriesBacktraces);
}
cmStringRange cmTarget::GetLinkImplementationEntries() const
{
- return cmMakeRange(this->Internal->LinkImplementationPropertyEntries);
+ return cmMakeRange(impl->LinkImplementationPropertyEntries);
}
cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
{
- return cmMakeRange(this->Internal->LinkImplementationPropertyBacktraces);
+ return cmMakeRange(impl->LinkImplementationPropertyBacktraces);
}
void cmTarget::SetProperty(const std::string& prop, const char* value)
{
if (!cmTargetPropertyComputer::PassesWhitelist(
- this->GetType(), prop, this->Makefile->GetMessenger(),
- this->Makefile->GetBacktrace())) {
+ this->GetType(), prop, impl->Makefile->GetMessenger(),
+ impl->Makefile->GetBacktrace())) {
return;
}
- if (prop == "MANUALLY_ADDED_DEPENDENCIES") {
+#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
+ MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
+ MAKE_STATIC_PROP(COMPILE_FEATURES);
+ MAKE_STATIC_PROP(COMPILE_OPTIONS);
+ MAKE_STATIC_PROP(CUDA_PTX_COMPILATION);
+ MAKE_STATIC_PROP(EXPORT_NAME);
+ MAKE_STATIC_PROP(IMPORTED_GLOBAL);
+ MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
+ MAKE_STATIC_PROP(LINK_OPTIONS);
+ MAKE_STATIC_PROP(LINK_DIRECTORIES);
+ MAKE_STATIC_PROP(LINK_LIBRARIES);
+ MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES);
+ MAKE_STATIC_PROP(NAME);
+ MAKE_STATIC_PROP(SOURCES);
+ MAKE_STATIC_PROP(TYPE);
+#undef MAKE_STATIC_PROP
+ if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
std::ostringstream e;
e << "MANUALLY_ADDED_DEPENDENCIES property is read-only\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
- if (prop == "NAME") {
+ if (prop == propNAME) {
std::ostringstream e;
e << "NAME property is read-only\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
- if (prop == "TYPE") {
+ if (prop == propTYPE) {
std::ostringstream e;
e << "TYPE property is read-only\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
- if (prop == "EXPORT_NAME" && this->IsImported()) {
+ if (prop == propEXPORT_NAME && this->IsImported()) {
std::ostringstream e;
e << "EXPORT_NAME property can't be set on imported targets (\""
- << this->Name << "\")\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ << impl->Name << "\")\n";
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
- if (prop == "SOURCES" && this->IsImported()) {
+ if (prop == propSOURCES && this->IsImported()) {
std::ostringstream e;
- e << "SOURCES property can't be set on imported targets (\"" << this->Name
+ e << "SOURCES property can't be set on imported targets (\"" << impl->Name
<< "\")\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return;
+ }
+ if (prop == propIMPORTED_GLOBAL && !this->IsImported()) {
+ std::ostringstream e;
+ e << "IMPORTED_GLOBAL property can't be set on non-imported targets (\""
+ << impl->Name << "\")\n";
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
- if (prop == "INCLUDE_DIRECTORIES") {
- this->Internal->IncludeDirectoriesEntries.clear();
- this->Internal->IncludeDirectoriesBacktraces.clear();
+ if (prop == propINCLUDE_DIRECTORIES) {
+ impl->IncludeDirectoriesEntries.clear();
+ impl->IncludeDirectoriesBacktraces.clear();
if (value) {
- this->Internal->IncludeDirectoriesEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
+ impl->IncludeDirectoriesEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->IncludeDirectoriesBacktraces.push_back(lfbt);
}
- } else if (prop == "COMPILE_OPTIONS") {
- this->Internal->CompileOptionsEntries.clear();
- this->Internal->CompileOptionsBacktraces.clear();
+ } else if (prop == propCOMPILE_OPTIONS) {
+ impl->CompileOptionsEntries.clear();
+ impl->CompileOptionsBacktraces.clear();
if (value) {
- this->Internal->CompileOptionsEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->CompileOptionsBacktraces.push_back(lfbt);
+ impl->CompileOptionsEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->CompileOptionsBacktraces.push_back(lfbt);
}
- } else if (prop == "COMPILE_FEATURES") {
- this->Internal->CompileFeaturesEntries.clear();
- this->Internal->CompileFeaturesBacktraces.clear();
+ } else if (prop == propCOMPILE_FEATURES) {
+ impl->CompileFeaturesEntries.clear();
+ impl->CompileFeaturesBacktraces.clear();
if (value) {
- this->Internal->CompileFeaturesEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
+ impl->CompileFeaturesEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->CompileFeaturesBacktraces.push_back(lfbt);
}
- } else if (prop == "COMPILE_DEFINITIONS") {
- this->Internal->CompileDefinitionsEntries.clear();
- this->Internal->CompileDefinitionsBacktraces.clear();
+ } else if (prop == propCOMPILE_DEFINITIONS) {
+ impl->CompileDefinitionsEntries.clear();
+ impl->CompileDefinitionsBacktraces.clear();
if (value) {
- this->Internal->CompileDefinitionsEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
+ impl->CompileDefinitionsEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->CompileDefinitionsBacktraces.push_back(lfbt);
}
- } else if (prop == "LINK_LIBRARIES") {
- this->Internal->LinkImplementationPropertyEntries.clear();
- this->Internal->LinkImplementationPropertyBacktraces.clear();
+ } else if (prop == propLINK_OPTIONS) {
+ impl->LinkOptionsEntries.clear();
+ impl->LinkOptionsBacktraces.clear();
if (value) {
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->LinkImplementationPropertyEntries.push_back(value);
- this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
+ impl->LinkOptionsEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->LinkOptionsBacktraces.push_back(lfbt);
}
- } else if (prop == "SOURCES") {
- this->Internal->SourceEntries.clear();
- this->Internal->SourceBacktraces.clear();
+ } else if (prop == propLINK_DIRECTORIES) {
+ impl->LinkDirectoriesEntries.clear();
+ impl->LinkDirectoriesBacktraces.clear();
if (value) {
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->SourceEntries.push_back(value);
- this->Internal->SourceBacktraces.push_back(lfbt);
+ impl->LinkDirectoriesEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->LinkDirectoriesBacktraces.push_back(lfbt);
+ }
+ } else if (prop == propLINK_LIBRARIES) {
+ impl->LinkImplementationPropertyEntries.clear();
+ impl->LinkImplementationPropertyBacktraces.clear();
+ if (value) {
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->LinkImplementationPropertyEntries.emplace_back(value);
+ impl->LinkImplementationPropertyBacktraces.push_back(lfbt);
+ }
+ } else if (prop == propSOURCES) {
+ impl->SourceEntries.clear();
+ impl->SourceBacktraces.clear();
+ if (value) {
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->SourceEntries.emplace_back(value);
+ impl->SourceBacktraces.push_back(lfbt);
+ }
+ } else if (prop == propIMPORTED_GLOBAL) {
+ if (!cmSystemTools::IsOn(value)) {
+ std::ostringstream e;
+ e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\""
+ << impl->Name << "\")\n";
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return;
+ }
+ /* no need to change anything if value does not change */
+ if (!impl->ImportedGloballyVisible) {
+ impl->ImportedGloballyVisible = true;
+ this->GetGlobalGenerator()->IndexTarget(this);
}
} else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
- !this->CheckImportedLibName(prop, value ? value : "")) {
+ !impl->CheckImportedLibName(prop, value ? value : "")) {
/* error was reported by check method */
- } else if (prop == "CUDA_PTX_COMPILATION" &&
+ } else if (prop == propCUDA_PTX_COMPILATION &&
this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
std::ostringstream e;
e << "CUDA_PTX_COMPILATION property can only be applied to OBJECT "
"targets (\""
- << this->Name << "\")\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ << impl->Name << "\")\n";
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
} else {
- this->Properties.SetProperty(prop, value);
+ impl->Properties.SetProperty(prop, value);
}
}
@@ -958,69 +1211,89 @@ void cmTarget::AppendProperty(const std::string& prop, const char* value,
bool asString)
{
if (!cmTargetPropertyComputer::PassesWhitelist(
- this->GetType(), prop, this->Makefile->GetMessenger(),
- this->Makefile->GetBacktrace())) {
+ this->GetType(), prop, impl->Makefile->GetMessenger(),
+ impl->Makefile->GetBacktrace())) {
return;
}
if (prop == "NAME") {
std::ostringstream e;
e << "NAME property is read-only\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
if (prop == "EXPORT_NAME" && this->IsImported()) {
std::ostringstream e;
e << "EXPORT_NAME property can't be set on imported targets (\""
- << this->Name << "\")\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ << impl->Name << "\")\n";
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
if (prop == "SOURCES" && this->IsImported()) {
std::ostringstream e;
- e << "SOURCES property can't be set on imported targets (\"" << this->Name
+ e << "SOURCES property can't be set on imported targets (\"" << impl->Name
<< "\")\n";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return;
+ }
+ if (prop == "IMPORTED_GLOBAL") {
+ std::ostringstream e;
+ e << "IMPORTED_GLOBAL property can't be appended, only set on imported "
+ "targets (\""
+ << impl->Name << "\")\n";
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
return;
}
if (prop == "INCLUDE_DIRECTORIES") {
if (value && *value) {
- this->Internal->IncludeDirectoriesEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
+ impl->IncludeDirectoriesEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->IncludeDirectoriesBacktraces.push_back(lfbt);
}
} else if (prop == "COMPILE_OPTIONS") {
if (value && *value) {
- this->Internal->CompileOptionsEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->CompileOptionsBacktraces.push_back(lfbt);
+ impl->CompileOptionsEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->CompileOptionsBacktraces.push_back(lfbt);
}
} else if (prop == "COMPILE_FEATURES") {
if (value && *value) {
- this->Internal->CompileFeaturesEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
+ impl->CompileFeaturesEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->CompileFeaturesBacktraces.push_back(lfbt);
}
} else if (prop == "COMPILE_DEFINITIONS") {
if (value && *value) {
- this->Internal->CompileDefinitionsEntries.push_back(value);
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
+ impl->CompileDefinitionsEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->CompileDefinitionsBacktraces.push_back(lfbt);
+ }
+ } else if (prop == "LINK_OPTIONS") {
+ if (value && *value) {
+ impl->LinkOptionsEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->LinkOptionsBacktraces.push_back(lfbt);
+ }
+ } else if (prop == "LINK_DIRECTORIES") {
+ if (value && *value) {
+ impl->LinkDirectoriesEntries.emplace_back(value);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->LinkDirectoriesBacktraces.push_back(lfbt);
}
} else if (prop == "LINK_LIBRARIES") {
if (value && *value) {
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->LinkImplementationPropertyEntries.push_back(value);
- this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->LinkImplementationPropertyEntries.emplace_back(value);
+ impl->LinkImplementationPropertyBacktraces.push_back(lfbt);
}
} else if (prop == "SOURCES") {
- cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
- this->Internal->SourceEntries.push_back(value);
- this->Internal->SourceBacktraces.push_back(lfbt);
+ cmListFileBacktrace lfbt = impl->Makefile->GetBacktrace();
+ impl->SourceEntries.emplace_back(value);
+ impl->SourceBacktraces.push_back(lfbt);
} else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
prop + " property may not be APPENDed.");
} else {
- this->Properties.AppendProperty(prop, value, asString);
+ impl->Properties.AppendProperty(prop, value, asString);
}
}
@@ -1033,16 +1306,17 @@ void cmTarget::AppendBuildInterfaceIncludes()
!this->IsExecutableWithExports()) {
return;
}
- if (this->BuildInterfaceIncludesAppended) {
+ if (impl->BuildInterfaceIncludesAppended) {
return;
}
- this->BuildInterfaceIncludesAppended = true;
+ impl->BuildInterfaceIncludesAppended = true;
- if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
- const char* binDir = this->Makefile->GetCurrentBinaryDirectory();
- const char* srcDir = this->Makefile->GetCurrentSourceDirectory();
- const std::string dirs = std::string(binDir ? binDir : "") +
- std::string(binDir ? ";" : "") + std::string(srcDir ? srcDir : "");
+ if (impl->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
+ std::string dirs = impl->Makefile->GetCurrentBinaryDirectory();
+ if (!dirs.empty()) {
+ dirs += ';';
+ }
+ dirs += impl->Makefile->GetCurrentSourceDirectory();
if (!dirs.empty()) {
this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
("$<BUILD_INTERFACE:" + dirs + ">").c_str());
@@ -1054,37 +1328,66 @@ void cmTarget::InsertInclude(std::string const& entry,
cmListFileBacktrace const& bt, bool before)
{
std::vector<std::string>::iterator position = before
- ? this->Internal->IncludeDirectoriesEntries.begin()
- : this->Internal->IncludeDirectoriesEntries.end();
+ ? impl->IncludeDirectoriesEntries.begin()
+ : impl->IncludeDirectoriesEntries.end();
std::vector<cmListFileBacktrace>::iterator btPosition = before
- ? this->Internal->IncludeDirectoriesBacktraces.begin()
- : this->Internal->IncludeDirectoriesBacktraces.end();
+ ? impl->IncludeDirectoriesBacktraces.begin()
+ : impl->IncludeDirectoriesBacktraces.end();
- this->Internal->IncludeDirectoriesEntries.insert(position, entry);
- this->Internal->IncludeDirectoriesBacktraces.insert(btPosition, bt);
+ impl->IncludeDirectoriesEntries.insert(position, entry);
+ impl->IncludeDirectoriesBacktraces.insert(btPosition, bt);
}
void cmTarget::InsertCompileOption(std::string const& entry,
cmListFileBacktrace const& bt, bool before)
{
std::vector<std::string>::iterator position = before
- ? this->Internal->CompileOptionsEntries.begin()
- : this->Internal->CompileOptionsEntries.end();
+ ? impl->CompileOptionsEntries.begin()
+ : impl->CompileOptionsEntries.end();
std::vector<cmListFileBacktrace>::iterator btPosition = before
- ? this->Internal->CompileOptionsBacktraces.begin()
- : this->Internal->CompileOptionsBacktraces.end();
+ ? impl->CompileOptionsBacktraces.begin()
+ : impl->CompileOptionsBacktraces.end();
- this->Internal->CompileOptionsEntries.insert(position, entry);
- this->Internal->CompileOptionsBacktraces.insert(btPosition, bt);
+ impl->CompileOptionsEntries.insert(position, entry);
+ impl->CompileOptionsBacktraces.insert(btPosition, bt);
}
void cmTarget::InsertCompileDefinition(std::string const& entry,
cmListFileBacktrace const& bt)
{
- this->Internal->CompileDefinitionsEntries.push_back(entry);
- this->Internal->CompileDefinitionsBacktraces.push_back(bt);
+ impl->CompileDefinitionsEntries.push_back(entry);
+ impl->CompileDefinitionsBacktraces.push_back(bt);
+}
+
+void cmTarget::InsertLinkOption(std::string const& entry,
+ cmListFileBacktrace const& bt, bool before)
+{
+ std::vector<std::string>::iterator position =
+ before ? impl->LinkOptionsEntries.begin() : impl->LinkOptionsEntries.end();
+
+ std::vector<cmListFileBacktrace>::iterator btPosition = before
+ ? impl->LinkOptionsBacktraces.begin()
+ : impl->LinkOptionsBacktraces.end();
+
+ impl->LinkOptionsEntries.insert(position, entry);
+ impl->LinkOptionsBacktraces.insert(btPosition, bt);
+}
+
+void cmTarget::InsertLinkDirectory(std::string const& entry,
+ cmListFileBacktrace const& bt, bool before)
+{
+ std::vector<std::string>::iterator position = before
+ ? impl->LinkDirectoriesEntries.begin()
+ : impl->LinkDirectoriesEntries.end();
+
+ std::vector<cmListFileBacktrace>::iterator btPosition = before
+ ? impl->LinkDirectoriesBacktraces.begin()
+ : impl->LinkDirectoriesBacktraces.end();
+
+ impl->LinkDirectoriesEntries.insert(position, entry);
+ impl->LinkDirectoriesBacktraces.insert(btPosition, bt);
}
static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
@@ -1123,7 +1426,7 @@ static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
<< "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
<< "properties accordingly.";
}
- context->IssueMessage(cmake::FATAL_ERROR, e.str());
+ context->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
@@ -1145,7 +1448,22 @@ static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
"property may contain configuration-sensitive generator-expressions "
"which may be used to specify per-configuration rules.";
- context->IssueMessage(cmake::FATAL_ERROR, e.str());
+ context->IssueMessage(MessageType::FATAL_ERROR, e.str());
+}
+
+static void cmTargetCheckIMPORTED_GLOBAL(const cmTarget* target,
+ cmMakefile* context)
+{
+ std::vector<cmTarget*> targets = context->GetOwnedImportedTargets();
+ std::vector<cmTarget*>::const_iterator it =
+ std::find(targets.begin(), targets.end(), target);
+ if (it == targets.end()) {
+ std::ostringstream e;
+ e << "Attempt to promote imported target \"" << target->GetName()
+ << "\" to global scope (by setting IMPORTED_GLOBAL) "
+ "which is not built in this directory.";
+ context->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ }
}
void cmTarget::CheckProperty(const std::string& prop,
@@ -1162,11 +1480,16 @@ void cmTarget::CheckProperty(const std::string& prop,
cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
}
}
- if (cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES")) {
+ if (prop == "INTERFACE_LINK_LIBRARIES") {
if (const char* value = this->GetProperty(prop)) {
cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
}
}
+ if (prop == "IMPORTED_GLOBAL") {
+ if (this->IsImported()) {
+ cmTargetCheckIMPORTED_GLOBAL(this, context);
+ }
+ }
}
const char* cmTarget::GetComputedProperty(
@@ -1178,7 +1501,7 @@ const char* cmTarget::GetComputedProperty(
const char* cmTarget::GetProperty(const std::string& prop) const
{
- static CM_UNORDERED_SET<std::string> specialProps;
+ static std::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);
@@ -1186,7 +1509,10 @@ const char* cmTarget::GetProperty(const std::string& prop) const
MAKE_STATIC_PROP(COMPILE_FEATURES);
MAKE_STATIC_PROP(COMPILE_OPTIONS);
MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
+ MAKE_STATIC_PROP(LINK_OPTIONS);
+ MAKE_STATIC_PROP(LINK_DIRECTORIES);
MAKE_STATIC_PROP(IMPORTED);
+ MAKE_STATIC_PROP(IMPORTED_GLOBAL);
MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES);
MAKE_STATIC_PROP(NAME);
MAKE_STATIC_PROP(BINARY_DIR);
@@ -1200,7 +1526,10 @@ const char* cmTarget::GetProperty(const std::string& prop) const
specialProps.insert(propCOMPILE_FEATURES);
specialProps.insert(propCOMPILE_OPTIONS);
specialProps.insert(propCOMPILE_DEFINITIONS);
+ specialProps.insert(propLINK_OPTIONS);
+ specialProps.insert(propLINK_DIRECTORIES);
specialProps.insert(propIMPORTED);
+ specialProps.insert(propIMPORTED_GLOBAL);
specialProps.insert(propMANUALLY_ADDED_DEPENDENCIES);
specialProps.insert(propNAME);
specialProps.insert(propBINARY_DIR);
@@ -1209,12 +1538,12 @@ const char* cmTarget::GetProperty(const std::string& prop) const
}
if (specialProps.count(prop)) {
if (prop == propLINK_LIBRARIES) {
- if (this->Internal->LinkImplementationPropertyEntries.empty()) {
- return CM_NULLPTR;
+ if (impl->LinkImplementationPropertyEntries.empty()) {
+ return nullptr;
}
static std::string output;
- output = cmJoin(this->Internal->LinkImplementationPropertyEntries, ";");
+ output = cmJoin(impl->LinkImplementationPropertyEntries, ";");
return output.c_str();
}
// the type property returns what type the target is
@@ -1222,87 +1551,133 @@ const char* cmTarget::GetProperty(const std::string& prop) const
return cmState::GetTargetTypeName(this->GetType());
}
if (prop == propINCLUDE_DIRECTORIES) {
- if (this->Internal->IncludeDirectoriesEntries.empty()) {
- return CM_NULLPTR;
+ if (impl->IncludeDirectoriesEntries.empty()) {
+ return nullptr;
}
static std::string output;
- output = cmJoin(this->Internal->IncludeDirectoriesEntries, ";");
+ output = cmJoin(impl->IncludeDirectoriesEntries, ";");
return output.c_str();
}
if (prop == propCOMPILE_FEATURES) {
- if (this->Internal->CompileFeaturesEntries.empty()) {
- return CM_NULLPTR;
+ if (impl->CompileFeaturesEntries.empty()) {
+ return nullptr;
}
static std::string output;
- output = cmJoin(this->Internal->CompileFeaturesEntries, ";");
+ output = cmJoin(impl->CompileFeaturesEntries, ";");
return output.c_str();
}
if (prop == propCOMPILE_OPTIONS) {
- if (this->Internal->CompileOptionsEntries.empty()) {
- return CM_NULLPTR;
+ if (impl->CompileOptionsEntries.empty()) {
+ return nullptr;
}
static std::string output;
- output = cmJoin(this->Internal->CompileOptionsEntries, ";");
+ output = cmJoin(impl->CompileOptionsEntries, ";");
return output.c_str();
}
if (prop == propCOMPILE_DEFINITIONS) {
- if (this->Internal->CompileDefinitionsEntries.empty()) {
- return CM_NULLPTR;
+ if (impl->CompileDefinitionsEntries.empty()) {
+ return nullptr;
}
static std::string output;
- output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
+ output = cmJoin(impl->CompileDefinitionsEntries, ";");
+ return output.c_str();
+ }
+ if (prop == propLINK_OPTIONS) {
+ if (impl->LinkOptionsEntries.empty()) {
+ return nullptr;
+ }
+
+ static std::string output;
+ output = cmJoin(impl->LinkOptionsEntries, ";");
+ return output.c_str();
+ }
+ if (prop == propLINK_DIRECTORIES) {
+ if (impl->LinkDirectoriesEntries.empty()) {
+ return nullptr;
+ }
+
+ static std::string output;
+ output = cmJoin(impl->LinkDirectoriesEntries, ";");
+
return output.c_str();
}
if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
- if (this->Utilities.empty()) {
- return CM_NULLPTR;
+ if (impl->Utilities.empty()) {
+ return nullptr;
}
static std::string output;
- output = cmJoin(this->Utilities, ";");
+ output = cmJoin(impl->Utilities, ";");
return output.c_str();
}
if (prop == propIMPORTED) {
return this->IsImported() ? "TRUE" : "FALSE";
}
+ if (prop == propIMPORTED_GLOBAL) {
+ return this->IsImportedGloballyVisible() ? "TRUE" : "FALSE";
+ }
if (prop == propNAME) {
return this->GetName().c_str();
}
if (prop == propBINARY_DIR) {
- return this->GetMakefile()
- ->GetStateSnapshot()
+ return impl->Makefile->GetStateSnapshot()
.GetDirectory()
- .GetCurrentBinary();
+ .GetCurrentBinary()
+ .c_str();
}
if (prop == propSOURCE_DIR) {
- return this->GetMakefile()
- ->GetStateSnapshot()
+ return impl->Makefile->GetStateSnapshot()
.GetDirectory()
- .GetCurrentSource();
+ .GetCurrentSource()
+ .c_str();
}
}
- const char* retVal = this->Properties.GetPropertyValue(prop);
+ const char* retVal = impl->Properties.GetPropertyValue(prop);
if (!retVal) {
- const bool chain = this->GetMakefile()->GetState()->IsPropertyChained(
- prop, cmProperty::TARGET);
+ const bool chain =
+ impl->Makefile->GetState()->IsPropertyChained(prop, cmProperty::TARGET);
if (chain) {
- return this->Makefile->GetStateSnapshot().GetDirectory().GetProperty(
+ return impl->Makefile->GetStateSnapshot().GetDirectory().GetProperty(
prop, chain);
}
}
return retVal;
}
+const char* cmTarget::GetSafeProperty(const std::string& prop) const
+{
+ const char* ret = this->GetProperty(prop);
+ if (!ret) {
+ return "";
+ }
+ return ret;
+}
+
bool cmTarget::GetPropertyAsBool(const std::string& prop) const
{
return cmSystemTools::IsOn(this->GetProperty(prop));
}
+cmPropertyMap const& cmTarget::GetProperties() const
+{
+ return impl->Properties;
+}
+
+bool cmTarget::IsImported() const
+{
+ return impl->IsImportedTarget;
+}
+
+bool cmTarget::IsImportedGloballyVisible() const
+{
+ return impl->ImportedGloballyVisible;
+}
+
const char* cmTarget::GetSuffixVariableInternal(
cmStateEnums::ArtifactType artifact) const
{
@@ -1330,7 +1705,7 @@ const char* cmTarget::GetSuffixVariableInternal(
case cmStateEnums::RuntimeBinaryArtifact:
// Android GUI application packages store the native
// binary as a shared library.
- return (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
+ return (impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
? "CMAKE_SHARED_LIBRARY_SUFFIX"
: "CMAKE_EXECUTABLE_SUFFIX");
case cmStateEnums::ImportLibraryArtifact:
@@ -1370,7 +1745,7 @@ const char* cmTarget::GetPrefixVariableInternal(
case cmStateEnums::RuntimeBinaryArtifact:
// Android GUI application packages store the native
// binary as a shared library.
- return (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
+ return (impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
? "CMAKE_SHARED_LIBRARY_PREFIX"
: "");
case cmStateEnums::ImportLibraryArtifact:
@@ -1397,8 +1772,8 @@ std::string cmTarget::ImportedGetFullPath(
std::string result;
- const char* loc = CM_NULLPTR;
- const char* imp = CM_NULLPTR;
+ const char* loc = nullptr;
+ const char* imp = nullptr;
std::string suffix;
if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
@@ -1444,42 +1819,30 @@ std::string cmTarget::ImportedGetFullPath(
return result;
}
-void cmTarget::SetPropertyDefault(const std::string& property,
- const char* default_value)
+bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
+ std::string const& value) const
{
- // 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::CheckImportedLibName(std::string const& prop,
- std::string const& value) const
-{
- if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY ||
- !this->IsImported()) {
+ if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
+ !this->IsImportedTarget) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, prop +
+ MessageType::FATAL_ERROR,
+ prop +
" property may be set only on imported INTERFACE library targets.");
return false;
}
if (!value.empty()) {
if (value[0] == '-') {
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, prop +
- " property value\n " + value +
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ prop + " property value\n " + value +
"\nmay not start with '-'.");
return false;
}
std::string::size_type bad = value.find_first_of(":/\\;");
if (bad != std::string::npos) {
- this->Makefile->IssueMessage(
- cmake::FATAL_ERROR, prop + " property value\n " + value +
- "\nmay not contain '" + value.substr(bad, 1) + "'.");
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
+ prop + " property value\n " + value +
+ "\nmay not contain '" +
+ value.substr(bad, 1) + "'.");
return false;
}
}
@@ -1520,7 +1883,9 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config,
// If we needed to find one of the mapped configurations but did not
// On a DLL platform there may be only IMPORTED_IMPLIB for a shared
// library or an executable with exports.
- bool allowImp = this->HasImportLibrary();
+ bool allowImp = (impl->DLLPlatform &&
+ (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
+ this->IsExecutableWithExports()));
// If a mapping was found, check its configurations.
for (std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
@@ -1535,7 +1900,7 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config,
}
// If it was found, set the suffix.
if (*loc || *imp) {
- suffix = "";
+ suffix.clear();
}
} else {
std::string mcUpper = cmSystemTools::UpperCase(*mci);
@@ -1582,7 +1947,7 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config,
// configurations and no exact match.
if (!*loc && !*imp) {
// The suffix computed above is not useful.
- suffix = "";
+ suffix.clear();
// Look for a configuration-less location. This may be set by
// manually-written code.
@@ -1623,37 +1988,3 @@ bool cmTarget::GetMappedConfig(std::string const& desired_config,
return true;
}
-
-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()
-{
- 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
index 1f00c0155..2bd9e6db6 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -6,45 +6,31 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
-#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <string>
#include <utility>
#include <vector>
#include "cmAlgorithms.h"
-#include "cmCustomCommand.h"
#include "cmListFileCache.h"
#include "cmPolicies.h"
-#include "cmPropertyMap.h"
#include "cmStateTypes.h"
#include "cmTargetLinkLibraryType.h"
-#include "cm_unordered_map.hxx"
+class cmCustomCommand;
class cmGlobalGenerator;
+class cmInstallTargetGenerator;
class cmMakefile;
class cmMessenger;
+class cmPropertyMap;
class cmSourceFile;
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.
+ * cmTarget represents a target loaded from a makefile.
*/
class cmTarget
{
@@ -56,9 +42,6 @@ public:
VisibilityImportedGlobally
};
- cmTarget(std::string const& name, cmStateEnums::TargetType type,
- Visibility vis, cmMakefile* mf);
-
enum CustomCommandType
{
PRE_BUILD,
@@ -66,81 +49,75 @@ public:
POST_BUILD
};
- /**
- * Return the type of target.
- */
- cmStateEnums::TargetType GetType() const { return this->TargetTypeValue; }
+ cmTarget(std::string const& name, cmStateEnums::TargetType type,
+ Visibility vis, cmMakefile* mf);
+
+ cmTarget(cmTarget const&) = delete;
+ cmTarget(cmTarget&&) noexcept;
+ ~cmTarget();
+
+ cmTarget& operator=(cmTarget const&) = delete;
+ cmTarget& operator=(cmTarget&&) noexcept;
+
+ //! Return the type of target.
+ cmStateEnums::TargetType GetType() const;
+
+ //! Get the cmMakefile that owns this target.
+ cmMakefile* GetMakefile() const;
+ //! Return the global generator.
cmGlobalGenerator* GetGlobalGenerator() const;
- ///! Set/Get the name of the target
- const std::string& GetName() const { return this->Name; }
+ //! Set/Get the name of the target
+ const std::string& GetName() const;
- /** Get the cmMakefile that owns this target. */
- cmMakefile* GetMakefile() const { return this->Makefile; }
+ //! Get the policy map
+ cmPolicies::PolicyMap const& GetPolicyMap() const;
+
+ //! Get policy status
+ cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID policy) const;
#define DECLARE_TARGET_POLICY(POLICY) \
cmPolicies::PolicyStatus GetPolicyStatus##POLICY() const \
{ \
- return this->PolicyMap.Get(cmPolicies::POLICY); \
+ return this->GetPolicyStatus(cmPolicies::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 PRE_BUILD custom commands for this target
+ std::vector<cmCustomCommand> const& GetPreBuildCommands() const;
+ void AddPreBuildCommand(cmCustomCommand const& cmd);
- /**
- * Add sources to the target.
- */
+ //! Get the list of the PRE_LINK custom commands for this target
+ std::vector<cmCustomCommand> const& GetPreLinkCommands() const;
+ void AddPreLinkCommand(cmCustomCommand const& cmd);
+
+ //! Get the list of the POST_BUILD custom commands for this target
+ std::vector<cmCustomCommand> const& GetPostBuildCommands() const;
+ void AddPostBuildCommand(cmCustomCommand const& cmd);
+
+ //! 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);
+ cmSourceFile* AddSource(const std::string& src, bool before = false);
- //* how we identify a library, by name and type
+ //! how we identify a library, by name and type
typedef std::pair<std::string, cmTargetLinkLibraryType> LibraryID;
-
typedef std::vector<LibraryID> LinkLibraryVectorType;
- const LinkLibraryVectorType& GetOriginalLinkLibraries() const
- {
- return this->OriginalLinkLibraries;
- }
+ LinkLibraryVectorType const& GetOriginalLinkLibraries() const;
- /**
- * Clear the dependency information recorded for this target, if any.
- */
- void ClearDependencyInformation(cmMakefile& mf, const std::string& target);
+ //! Clear the dependency information recorded for this target, if any.
+ void ClearDependencyInformation(cmMakefile& mf);
void AddLinkLibrary(cmMakefile& mf, const std::string& lib,
cmTargetLinkLibraryType llt);
+ void AddLinkLibrary(cmMakefile& mf, std::string const& lib,
+ std::string const& libRef, cmTargetLinkLibraryType llt);
+
enum TLLSignature
{
KeywordTLLSignature,
@@ -150,80 +127,76 @@ public:
cmListFileContext const& lfc);
void GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const;
- 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; }
+ std::string const& GetInstallPath() const;
+ void SetInstallPath(std::string const& 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;
- }
+ std::string const& GetRuntimeInstallPath() const;
+ void SetRuntimeInstallPath(std::string const& 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; }
+ bool GetHaveInstallRule() const;
+ void SetHaveInstallRule(bool hir);
- /** Add a utility on which this project depends. A utility is an executable
+ void AddInstallGenerator(cmInstallTargetGenerator* g);
+ std::vector<cmInstallTargetGenerator*> const& GetInstallGenerators() const;
+
+ /**
+ * Get/Set whether this target was auto-created by a generator.
+ */
+ bool GetIsGeneratorProvided() const;
+ void SetIsGeneratorProvided(bool igp);
+
+ /**
+ * 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 = CM_NULLPTR);
- ///! Get the utilities used by this target
- std::set<std::string> const& GetUtilities() const { return this->Utilities; }
- cmListFileBacktrace const* GetUtilityBacktrace(const std::string& u) const;
+ void AddUtility(std::string const& name, cmMakefile* mf = nullptr);
+ //! Get the utilities used by this target
+ std::set<BT<std::string>> const& GetUtilities() const;
- ///! Set/Get a property of this target file
+ //! 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);
+ //! Might return a nullptr if the property is not set or invalid
const char* GetProperty(const std::string& prop) const;
+ //! Always returns a valid pointer
+ const char* GetSafeProperty(const std::string& prop) const;
bool GetPropertyAsBool(const std::string& prop) const;
void CheckProperty(const std::string& prop, cmMakefile* context) const;
const char* GetComputedProperty(const std::string& prop,
cmMessenger* messenger,
cmListFileBacktrace const& context) const;
+ //! Get all properties
+ cmPropertyMap const& GetProperties() const;
- bool IsImported() const { return this->IsImportedTarget; }
- bool IsImportedGloballyVisible() const
- {
- return this->ImportedGloballyVisible;
- }
-
- // Get the properties
- cmPropertyMap const& GetProperties() const { return this->Properties; }
+ bool IsImported() const;
+ bool IsImportedGloballyVisible() const;
bool GetMappedConfig(std::string const& desired_config, const char** loc,
const char** imp, std::string& suffix) const;
- /** Return whether this target is an executable with symbol exports
- enabled. */
+ //! Return whether this target is an executable with symbol exports enabled.
bool IsExecutableWithExports() const;
- /** Return whether this target is a shared library Framework on
- Apple. */
+ //! Return whether this target is a shared library Framework on Apple.
bool IsFrameworkOnApple() const;
- /** Return whether this target is an executable Bundle on Apple. */
+ //! Return whether this target is an executable Bundle on Apple.
bool IsAppBundleOnApple() const;
- /** Get a backtrace from the creation of the target. */
+ //! Get a backtrace from the creation of the target.
cmListFileBacktrace const& GetBacktrace() const;
void InsertInclude(std::string const& entry, cmListFileBacktrace const& bt,
@@ -232,17 +205,18 @@ public:
cmListFileBacktrace const& bt, bool before = false);
void InsertCompileDefinition(std::string const& entry,
cmListFileBacktrace const& bt);
+ void InsertLinkOption(std::string const& entry,
+ cmListFileBacktrace const& bt, bool before = false);
+ void InsertLinkDirectory(std::string const& entry,
+ cmListFileBacktrace const& bt, bool before = false);
void AppendBuildInterfaceIncludes();
std::string GetDebugGeneratorExpressions(const std::string& value,
cmTargetLinkLibraryType llt) const;
- void AddSystemIncludeDirectories(const std::set<std::string>& incs);
- std::set<std::string> const& GetSystemIncludeDirectories() const
- {
- return this->SystemIncludeDirectories;
- }
+ void AddSystemIncludeDirectories(std::set<std::string> const& incs);
+ std::set<std::string> const& GetSystemIncludeDirectories() const;
cmStringRange GetIncludeDirectoriesEntries() const;
cmBacktraceRange GetIncludeDirectoriesBacktraces() const;
@@ -258,78 +232,35 @@ public:
cmStringRange GetSourceEntries() const;
cmBacktraceRange GetSourceBacktraces() const;
+
+ cmStringRange GetLinkOptionsEntries() const;
+ cmBacktraceRange GetLinkOptionsBacktraces() const;
+
+ cmStringRange GetLinkDirectoriesEntries() const;
+ cmBacktraceRange GetLinkDirectoriesBacktraces() const;
+
cmStringRange GetLinkImplementationEntries() const;
cmBacktraceRange GetLinkImplementationBacktraces() const;
+ std::string ImportedGetFullPath(const std::string& config,
+ cmStateEnums::ArtifactType artifact) const;
+
struct StrictTargetComparison
{
bool operator()(cmTarget const* t1, cmTarget const* t2) const;
};
- std::string ImportedGetFullPath(const std::string& config,
- cmStateEnums::ArtifactType artifact) const;
-
private:
+ // Internal representation details.
+ friend class cmGeneratorTarget;
+
const char* GetSuffixVariableInternal(
cmStateEnums::ArtifactType artifact) const;
const char* GetPrefixVariableInternal(
cmStateEnums::ArtifactType artifact) 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);
-
- bool CheckImportedLibName(std::string const& prop,
- std::string const& value) const;
-
private:
- cmPropertyMap Properties;
- std::set<std::string> SystemIncludeDirectories;
- std::set<std::string> LinkDirectoriesEmmitted;
- std::set<std::string> Utilities;
- std::map<std::string, cmListFileBacktrace> UtilityBacktraces;
- cmPolicies::PolicyMap PolicyMap;
- std::string Name;
- std::string InstallPath;
- std::string RuntimeInstallPath;
- std::vector<std::string> LinkDirectories;
- std::vector<cmCustomCommand> PreBuildCommands;
- std::vector<cmCustomCommand> PreLinkCommands;
- std::vector<cmCustomCommand> PostBuildCommands;
- std::vector<std::pair<TLLSignature, cmListFileContext> > TLLCommands;
- LinkLibraryVectorType OriginalLinkLibraries;
- cmMakefile* Makefile;
- cmTargetInternalPointer Internal;
- cmStateEnums::TargetType TargetTypeValue;
- bool HaveInstallRule;
- bool RecordDependencies;
- bool DLLPlatform;
- bool IsAndroid;
- bool IsImportedTarget;
- bool ImportedGloballyVisible;
- bool BuildInterfaceIncludesAppended;
-
- std::string ProcessSourceItemCMP0049(const std::string& s);
-
- /** Return whether or not the target has a DLL import library. */
- bool HasImportLibrary() const;
-
- // Internal representation details.
- friend class cmTargetInternals;
- friend class cmGeneratorTarget;
- friend class cmTargetTraceDependencies;
-
- cmListFileBacktrace Backtrace;
-};
-
-typedef CM_UNORDERED_MAP<std::string, cmTarget> cmTargets;
-
-class cmTargetSet : public std::set<std::string>
-{
-};
-class cmTargetManifest : public std::map<std::string, cmTargetSet>
-{
+ std::unique_ptr<cmTargetInternals> impl;
};
#endif
diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx
index 008d1a210..c4dc8383b 100644
--- a/Source/cmTargetCompileDefinitionsCommand.cxx
+++ b/Source/cmTargetCompileDefinitionsCommand.cxx
@@ -6,8 +6,8 @@
#include "cmAlgorithms.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -17,15 +17,6 @@ bool cmTargetCompileDefinitionsCommand::InitialPass(
return this->HandleArguments(args, "COMPILE_DEFINITIONS");
}
-void cmTargetCompileDefinitionsCommand::HandleImportedTarget(
- const std::string& tgt)
-{
- std::ostringstream 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)
{
@@ -33,7 +24,7 @@ void cmTargetCompileDefinitionsCommand::HandleMissingTarget(
e << "Cannot specify compile definitions for target \"" << name
<< "\" "
"which is not built by this project.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
std::string cmTargetCompileDefinitionsCommand::Join(
@@ -41,12 +32,11 @@ std::string cmTargetCompileDefinitionsCommand::Join(
{
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);
+ for (std::string const& it : content) {
+ if (cmHasLiteralPrefix(it, "-D")) {
+ defs += sep + it.substr(2);
} else {
- defs += sep + *it;
+ defs += sep + it;
}
sep = ";";
}
@@ -57,5 +47,5 @@ bool cmTargetCompileDefinitionsCommand::HandleDirectContent(
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
{
tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str());
- return true;
+ return true; // Successfully handled.
}
diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h
index 11abf571c..d41483a1d 100644
--- a/Source/cmTargetCompileDefinitionsCommand.h
+++ b/Source/cmTargetCompileDefinitionsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTargetCompileDefinitionsCommand_h
#define cmTargetCompileDefinitionsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -20,26 +20,22 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
- {
- return new cmTargetCompileDefinitionsCommand;
- }
+ cmCommand* Clone() override { return new cmTargetCompileDefinitionsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- void HandleImportedTarget(const std::string& tgt) CM_OVERRIDE;
- void HandleMissingTarget(const std::string& name) CM_OVERRIDE;
+ void HandleMissingTarget(const std::string& name) override;
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
- bool prepend, bool system) CM_OVERRIDE;
- std::string Join(const std::vector<std::string>& content) CM_OVERRIDE;
+ bool prepend, bool system) override;
+ std::string Join(const std::vector<std::string>& content) override;
};
#endif
diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx
index 1b6c00887..c9e394b1c 100644
--- a/Source/cmTargetCompileFeaturesCommand.cxx
+++ b/Source/cmTargetCompileFeaturesCommand.cxx
@@ -6,7 +6,7 @@
#include "cmAlgorithms.h"
#include "cmMakefile.h"
-#include "cmake.h"
+#include "cmMessageType.h"
class cmExecutionStatus;
class cmTarget;
@@ -17,15 +17,6 @@ bool cmTargetCompileFeaturesCommand::InitialPass(
return this->HandleArguments(args, "COMPILE_FEATURES", NO_FLAGS);
}
-void cmTargetCompileFeaturesCommand::HandleImportedTarget(
- const std::string& tgt)
-{
- std::ostringstream 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)
{
@@ -33,7 +24,7 @@ void cmTargetCompileFeaturesCommand::HandleMissingTarget(
e << "Cannot specify compile features for target \"" << name
<< "\" "
"which is not built by this project.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
std::string cmTargetCompileFeaturesCommand::Join(
@@ -45,13 +36,12 @@ std::string cmTargetCompileFeaturesCommand::Join(
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) {
+ for (std::string const& it : content) {
std::string error;
- if (!this->Makefile->AddRequiredTargetFeature(tgt, *it, &error)) {
+ if (!this->Makefile->AddRequiredTargetFeature(tgt, it, &error)) {
this->SetError(error);
- return false;
+ return false; // Not (successfully) handled.
}
}
- return true;
+ return true; // Successfully handled.
}
diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h
index 990868004..45240a5a1 100644
--- a/Source/cmTargetCompileFeaturesCommand.h
+++ b/Source/cmTargetCompileFeaturesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTargetCompileFeaturesCommand_h
#define cmTargetCompileFeaturesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,19 +16,18 @@ class cmTarget;
class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase
{
- cmCommand* Clone() CM_OVERRIDE { return new cmTargetCompileFeaturesCommand; }
+ cmCommand* Clone() override { return new cmTargetCompileFeaturesCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- void HandleImportedTarget(const std::string& tgt) CM_OVERRIDE;
- void HandleMissingTarget(const std::string& name) CM_OVERRIDE;
+ void HandleMissingTarget(const std::string& name) override;
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
- bool prepend, bool system) CM_OVERRIDE;
- std::string Join(const std::vector<std::string>& content) CM_OVERRIDE;
+ bool prepend, bool system) override;
+ std::string Join(const std::vector<std::string>& content) override;
};
#endif
diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx
index 1b4056d76..8b4763a8c 100644
--- a/Source/cmTargetCompileOptionsCommand.cxx
+++ b/Source/cmTargetCompileOptionsCommand.cxx
@@ -7,8 +7,8 @@
#include "cmAlgorithms.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -18,22 +18,13 @@ bool cmTargetCompileOptionsCommand::InitialPass(
return this->HandleArguments(args, "COMPILE_OPTIONS", PROCESS_BEFORE);
}
-void cmTargetCompileOptionsCommand::HandleImportedTarget(
- const std::string& tgt)
-{
- std::ostringstream 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)
{
std::ostringstream e;
e << "Cannot specify compile options for target \"" << name
- << "\" "
- "which is not built by this project.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ << "\" which is not built by this project.";
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
std::string cmTargetCompileOptionsCommand::Join(
@@ -47,5 +38,5 @@ bool cmTargetCompileOptionsCommand::HandleDirectContent(
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
tgt->InsertCompileOption(this->Join(content), lfbt);
- return true;
+ return true; // Successfully handled.
}
diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h
index b5408f7cb..6fb151a9d 100644
--- a/Source/cmTargetCompileOptionsCommand.h
+++ b/Source/cmTargetCompileOptionsCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTargetCompileOptionsCommand_h
#define cmTargetCompileOptionsCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -20,23 +20,22 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmTargetCompileOptionsCommand; }
+ cmCommand* Clone() override { return new cmTargetCompileOptionsCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- void HandleImportedTarget(const std::string& tgt) CM_OVERRIDE;
- void HandleMissingTarget(const std::string& name) CM_OVERRIDE;
+ void HandleMissingTarget(const std::string& name) override;
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
- bool prepend, bool system) CM_OVERRIDE;
- std::string Join(const std::vector<std::string>& content) CM_OVERRIDE;
+ bool prepend, bool system) override;
+ std::string Join(const std::vector<std::string>& content) override;
};
#endif
diff --git a/Source/cmTargetDepend.h b/Source/cmTargetDepend.h
index daa902ecf..5ea008523 100644
--- a/Source/cmTargetDepend.h
+++ b/Source/cmTargetDepend.h
@@ -16,9 +16,10 @@ class cmTargetDepend
cmGeneratorTarget const* Target;
// The set order depends only on the Target, so we use
- // mutable members to acheive a map with set syntax.
+ // mutable members to achieve a map with set syntax.
mutable bool Link;
mutable bool Util;
+ mutable cmListFileBacktrace Backtrace;
public:
cmTargetDepend(cmGeneratorTarget const* t)
@@ -42,8 +43,13 @@ public:
this->Link = true;
}
}
+ void SetBacktrace(cmListFileBacktrace const& bt) const
+ {
+ this->Backtrace = bt;
+ }
bool IsLink() const { return this->Link; }
bool IsUtil() const { return this->Util; }
+ cmListFileBacktrace const& GetBacktrace() const { return this->Backtrace; }
};
/** Unordered set of (direct) dependencies of a target. */
diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx
index 65a31490f..d6918c09b 100644
--- a/Source/cmTargetIncludeDirectoriesCommand.cxx
+++ b/Source/cmTargetIncludeDirectoriesCommand.cxx
@@ -8,9 +8,9 @@
#include "cmGeneratorExpression.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -21,23 +21,13 @@ bool cmTargetIncludeDirectoriesCommand::InitialPass(
ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM));
}
-void cmTargetIncludeDirectoriesCommand::HandleImportedTarget(
- const std::string& tgt)
-{
- std::ostringstream 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)
{
std::ostringstream e;
e << "Cannot specify include directories for target \"" << name
- << "\" "
- "which is not built by this project.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ << "\" which is not built by this project.";
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
std::string cmTargetIncludeDirectoriesCommand::Join(
@@ -45,15 +35,13 @@ std::string cmTargetIncludeDirectoriesCommand::Join(
{
std::string dirs;
std::string sep;
- std::string prefix =
- this->Makefile->GetCurrentSourceDirectory() + 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;
+ std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/";
+ for (std::string const& it : content) {
+ if (cmSystemTools::FileIsFullPath(it) ||
+ cmGeneratorExpression::Find(it) == 0) {
+ dirs += sep + it;
} else {
- dirs += sep + prefix + *it;
+ dirs += sep + prefix + it;
}
sep = ";";
}
@@ -67,21 +55,19 @@ bool cmTargetIncludeDirectoriesCommand::HandleDirectContent(
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
tgt->InsertInclude(this->Join(content), lfbt, prepend);
if (system) {
- std::string prefix =
- this->Makefile->GetCurrentSourceDirectory() + std::string("/");
+ std::string prefix = this->Makefile->GetCurrentSourceDirectory() + "/";
std::set<std::string> sdirs;
- for (std::vector<std::string>::const_iterator it = content.begin();
- it != content.end(); ++it) {
- if (cmSystemTools::FileIsFullPath(it->c_str()) ||
- cmGeneratorExpression::Find(*it) == 0) {
- sdirs.insert(*it);
+ for (std::string const& it : content) {
+ if (cmSystemTools::FileIsFullPath(it) ||
+ cmGeneratorExpression::Find(it) == 0) {
+ sdirs.insert(it);
} else {
- sdirs.insert(prefix + *it);
+ sdirs.insert(prefix + it);
}
}
tgt->AddSystemIncludeDirectories(sdirs);
}
- return true;
+ return true; // Successfully handled.
}
void cmTargetIncludeDirectoriesCommand::HandleInterfaceContent(
diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h
index 374a867dc..57bf8fcf3 100644
--- a/Source/cmTargetIncludeDirectoriesCommand.h
+++ b/Source/cmTargetIncludeDirectoriesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTargetIncludeDirectoriesCommand_h
#define cmTargetIncludeDirectoriesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -20,30 +20,26 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE
- {
- return new cmTargetIncludeDirectoriesCommand;
- }
+ cmCommand* Clone() override { return new cmTargetIncludeDirectoriesCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
- void HandleImportedTarget(const std::string& tgt) CM_OVERRIDE;
- void HandleMissingTarget(const std::string& name) CM_OVERRIDE;
+ void HandleMissingTarget(const std::string& name) override;
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
- bool prepend, bool system) CM_OVERRIDE;
+ bool prepend, bool system) override;
void HandleInterfaceContent(cmTarget* tgt,
const std::vector<std::string>& content,
- bool prepend, bool system) CM_OVERRIDE;
+ bool prepend, bool system) override;
- std::string Join(const std::vector<std::string>& content) CM_OVERRIDE;
+ std::string Join(const std::vector<std::string>& content) override;
};
#endif
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index e17303645..3883b5228 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -8,6 +8,7 @@
#include "cmGeneratorExpression.h"
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmState.h"
#include "cmStateTypes.h"
@@ -25,22 +26,33 @@ const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] = {
bool cmTargetLinkLibrariesCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
- // must have one argument
+ // Must have at least one argument.
if (args.empty()) {
this->SetError("called with incorrect number of arguments");
return false;
}
-
+ // Alias targets cannot be on the LHS of this command.
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
+ const std::vector<cmTarget*>& importedTargets =
+ this->Makefile->GetOwnedImportedTargets();
+ for (cmTarget* importedTarget : importedTargets) {
+ if (importedTarget->GetName() == args[0]) {
+ this->Target = importedTarget;
+ break;
+ }
+ }
+ }
+ if (!this->Target) {
+ MessageType t = MessageType::FATAL_ERROR; // fail by default
std::ostringstream e;
e << "Cannot specify link libraries for target \"" << args[0] << "\" "
<< "which is not built by this project.";
@@ -49,7 +61,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
if (args.size() < 2) {
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0016)) {
case cmPolicies::WARN:
- t = cmake::AUTHOR_WARNING;
+ t = MessageType::AUTHOR_WARNING;
// Print the warning.
e << "\n"
<< "CMake does not support this but it used to work accidentally "
@@ -58,7 +70,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
<< cmPolicies::GetPolicyWarning(cmPolicies::CMP0016);
break;
case cmPolicies::OLD: // OLD behavior does not warn.
- t = cmake::MESSAGE;
+ t = MessageType::MESSAGE;
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
@@ -68,14 +80,13 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
break;
}
}
-
- // now actually print the message
+ // Now actually print the message.
switch (t) {
- case cmake::AUTHOR_WARNING:
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
+ case MessageType::AUTHOR_WARNING:
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
break;
- case cmake::FATAL_ERROR:
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ case MessageType::FATAL_ERROR:
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
break;
default:
@@ -84,19 +95,11 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
return true;
}
- if (this->Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
- std::ostringstream e;
- e << "Object library target \"" << args[0] << "\" "
- << "may not link to anything.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
- cmSystemTools::SetFatalErrorOccured();
- return true;
- }
-
+ // Having a UTILITY library on the LHS is a bug.
if (this->Target->GetType() == cmStateEnums::UTILITY) {
std::ostringstream e;
- const char* modal = CM_NULLPTR;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ const char* modal = nullptr;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0039)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0039) << "\n";
@@ -107,19 +110,19 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
modal = "must";
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::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) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
}
- // but we might not have any libs after variable expansion
+ // But we might not have any libs after variable expansion.
if (args.size() < 2) {
return true;
}
@@ -132,14 +135,14 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
// 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
+ // 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,
+ MessageType::FATAL_ERROR,
"The LINK_INTERFACE_LIBRARIES option must appear as the second "
"argument, just after the target name.");
return true;
@@ -150,8 +153,9 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
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.");
+ MessageType::FATAL_ERROR,
+ "The INTERFACE, PUBLIC or PRIVATE option must appear as the second "
+ "argument, just after the target name.");
return true;
}
this->CurrentProcessingState = ProcessingKeywordLinkInterface;
@@ -160,7 +164,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
this->CurrentProcessingState != ProcessingPlainPrivateInterface &&
this->CurrentProcessingState != ProcessingPlainPublicInterface) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
"argument, just after the target name.");
return true;
@@ -172,8 +176,8 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
this->CurrentProcessingState != ProcessingKeywordPublicInterface &&
this->CurrentProcessingState != ProcessingKeywordLinkInterface) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
- "The PUBLIC or PRIVATE option must appear as the second "
+ MessageType::FATAL_ERROR,
+ "The INTERFACE, PUBLIC or PRIVATE option must appear as the second "
"argument, just after the target name.");
return true;
}
@@ -183,7 +187,7 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
this->CurrentProcessingState != ProcessingPlainPublicInterface &&
this->CurrentProcessingState != ProcessingPlainPrivateInterface) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
"argument, just after the target name.");
return true;
@@ -195,8 +199,8 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
this->CurrentProcessingState != ProcessingKeywordPublicInterface &&
this->CurrentProcessingState != ProcessingKeywordLinkInterface) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
- "The PUBLIC or PRIVATE option must appear as the second "
+ MessageType::FATAL_ERROR,
+ "The INTERFACE, PUBLIC or PRIVATE option must appear as the second "
"argument, just after the target name.");
return true;
}
@@ -228,8 +232,8 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
} 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
+ // and not use the lookup. As there may be the case where someone has
+ // specified 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 = GENERAL_LibraryType;
@@ -253,9 +257,9 @@ bool cmTargetLinkLibrariesCommand::InitialPass(
// Make sure the last argument was not a library type specifier.
if (haveLLT) {
std::ostringstream e;
- e << "The \"" << this->LinkLibraryTypeNames[llt]
+ e << "The \"" << cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[llt]
<< "\" argument must be followed by a library.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
}
@@ -281,11 +285,13 @@ void cmTargetLinkLibrariesCommand::LinkLibraryTypeSpecifierWarning(int left,
int right)
{
std::ostringstream w;
- w << "Link library type specifier \"" << this->LinkLibraryTypeNames[left]
- << "\" is followed by specifier \"" << this->LinkLibraryTypeNames[right]
+ w << "Link library type specifier \""
+ << cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[left]
+ << "\" is followed by specifier \""
+ << cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[right]
<< "\" instead of a library name. "
<< "The first specifier will be ignored.";
- this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
}
bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
@@ -294,11 +300,19 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY &&
this->CurrentProcessingState != ProcessingKeywordLinkInterface) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"INTERFACE library can only be used with the INTERFACE keyword of "
"target_link_libraries");
return false;
}
+ if (this->Target->IsImported() &&
+ this->CurrentProcessingState != ProcessingKeywordLinkInterface) {
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ "IMPORTED library can only be used with the INTERFACE keyword of "
+ "target_link_libraries");
+ return false;
+ }
cmTarget::TLLSignature sig =
(this->CurrentProcessingState == ProcessingPlainPrivateInterface ||
@@ -311,8 +325,8 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
if (!this->Target->PushTLLCommandTrace(
sig, this->Makefile->GetExecutionContext())) {
std::ostringstream e;
- const char* modal = CM_NULLPTR;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ const char* modal = nullptr;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0023)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0023) << "\n";
@@ -323,7 +337,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
modal = "must";
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
}
if (modal) {
@@ -331,122 +345,180 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
// 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";
+ 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) {
+ if (messageType == MessageType::FATAL_ERROR) {
return false;
}
}
}
- // Handle normal case first.
+ bool warnRemoteInterface = false;
+ bool rejectRemoteLinking = false;
+ bool encodeRemoteReference = false;
+ if (this->Makefile != this->Target->GetMakefile()) {
+ // The LHS target was created in another directory.
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0079)) {
+ case cmPolicies::WARN:
+ warnRemoteInterface = true;
+ CM_FALLTHROUGH;
+ case cmPolicies::OLD:
+ rejectRemoteLinking = true;
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ encodeRemoteReference = true;
+ break;
+ }
+ }
+
+ std::string libRef;
+ if (encodeRemoteReference && !cmSystemTools::FileIsFullPath(lib)) {
+ // This is a library name added by a caller that is not in the
+ // same directory as the target was created. Add a suffix to
+ // the name to tell ResolveLinkItem to look up the name in the
+ // caller's directory.
+ cmDirectoryId const dirId = this->Makefile->GetDirectoryId();
+ libRef = lib + CMAKE_DIRECTORY_ID_SEP + dirId.String;
+ } else {
+ // This is an absolute path or a library name added by a caller
+ // in the same directory as the target was created. We can use
+ // the original name directly.
+ libRef = lib;
+ }
+
+ // Handle normal case where the command was called with another keyword than
+ // INTERFACE / LINK_INTERFACE_LIBRARIES or none at all. (The "LINK_LIBRARIES"
+ // property of the target on the LHS shall be populated.)
if (this->CurrentProcessingState != ProcessingKeywordLinkInterface &&
this->CurrentProcessingState != ProcessingPlainLinkInterface) {
- cmTarget* t =
- this->Makefile->FindLocalNonAliasTarget(this->Target->GetName());
- if (!t) {
+ if (rejectRemoteLinking) {
std::ostringstream e;
e << "Attempt to add link library \"" << lib << "\" to target \""
<< this->Target->GetName()
- << "\" which is not built in this directory.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
- } else {
+ << "\" which is not built in this directory.\n"
+ << "This is allowed only when policy CMP0079 is set to NEW.";
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ return false;
+ }
- cmTarget* tgt = this->Makefile->GetGlobalGenerator()->FindTarget(lib);
-
- if (tgt && (tgt->GetType() != cmStateEnums::STATIC_LIBRARY) &&
- (tgt->GetType() != cmStateEnums::SHARED_LIBRARY) &&
- (tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) &&
- !tgt->IsExecutableWithExports()) {
- std::ostringstream e;
- e << "Target \"" << lib << "\" of type "
- << cmState::GetTargetTypeName(tgt->GetType())
- << " may not be linked into another target. "
- << "One may link only to STATIC or SHARED libraries, or "
- << "to executables with the ENABLE_EXPORTS property set.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
- }
+ cmTarget* tgt = this->Makefile->GetGlobalGenerator()->FindTarget(lib);
- this->Target->AddLinkLibrary(*this->Makefile, lib, llt);
+ if (tgt && (tgt->GetType() != cmStateEnums::STATIC_LIBRARY) &&
+ (tgt->GetType() != cmStateEnums::SHARED_LIBRARY) &&
+ (tgt->GetType() != cmStateEnums::UNKNOWN_LIBRARY) &&
+ (tgt->GetType() != cmStateEnums::OBJECT_LIBRARY) &&
+ (tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) &&
+ !tgt->IsExecutableWithExports()) {
+ std::ostringstream e;
+ e << "Target \"" << lib << "\" of type "
+ << cmState::GetTargetTypeName(tgt->GetType())
+ << " may not be linked into another target. One may link only to "
+ "INTERFACE, OBJECT, STATIC or SHARED libraries, or to executables "
+ "with the ENABLE_EXPORTS property set.";
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
- if (this->CurrentProcessingState == ProcessingLinkLibraries) {
- this->Target->AppendProperty(
- "INTERFACE_LINK_LIBRARIES",
- this->Target->GetDebugGeneratorExpressions(lib, llt).c_str());
- return true;
- }
- if (this->CurrentProcessingState != ProcessingKeywordPublicInterface &&
- this->CurrentProcessingState != ProcessingPlainPublicInterface) {
- if (this->Target->GetType() == cmStateEnums::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());
+ this->Target->AddLinkLibrary(*this->Makefile, lib, libRef, llt);
+ }
+
+ if (warnRemoteInterface) {
+ std::ostringstream w;
+ /* clang-format off */
+ w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0079) << "\n"
+ "Target\n " << this->Target->GetName() << "\nis not created in this "
+ "directory. For compatibility with older versions of CMake, link "
+ "library\n " << lib << "\nwill be looked up in the directory in "
+ "which the target was created rather than in this calling "
+ "directory.";
+ /* clang-format on */
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
+ }
+
+ // Handle (additional) case where the command was called with PRIVATE /
+ // LINK_PRIVATE and stop its processing. (The "INTERFACE_LINK_LIBRARIES"
+ // property of the target on the LHS shall only be populated if it is a
+ // STATIC library.)
+ if (this->CurrentProcessingState == ProcessingKeywordPrivateInterface ||
+ this->CurrentProcessingState == ProcessingPlainPrivateInterface) {
+ if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY ||
+ this->Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
+ std::string configLib =
+ this->Target->GetDebugGeneratorExpressions(libRef, llt);
+ if (cmGeneratorExpression::IsValidTargetName(lib) ||
+ cmGeneratorExpression::Find(lib) != std::string::npos) {
+ configLib = "$<LINK_ONLY:" + configLib + ">";
}
- // Not a 'public' or 'interface' library. Do not add to interface
- // property.
- return true;
+ this->Target->AppendProperty("INTERFACE_LINK_LIBRARIES",
+ configLib.c_str());
}
+ return true;
}
+ // Handle general case where the command was called with another keyword than
+ // PRIVATE / LINK_PRIVATE or none at all. (The "INTERFACE_LINK_LIBRARIES"
+ // property of the target on the LHS shall be populated.)
this->Target->AppendProperty(
"INTERFACE_LINK_LIBRARIES",
- this->Target->GetDebugGeneratorExpressions(lib, llt).c_str());
+ this->Target->GetDebugGeneratorExpressions(libRef, llt).c_str());
+ // Stop processing if called without any keyword.
+ if (this->CurrentProcessingState == ProcessingLinkLibraries) {
+ return true;
+ }
+ // Stop processing if policy CMP0022 is set to NEW.
const cmPolicies::PolicyStatus policy22Status =
this->Target->GetPolicyStatusCMP0022();
-
if (policy22Status != cmPolicies::OLD &&
policy22Status != cmPolicies::WARN) {
return true;
}
-
+ // Stop processing if called with an INTERFACE library on the LHS.
if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
return true;
}
- // Get the list of configurations considered to be DEBUG.
- std::vector<std::string> debugConfigs =
- this->Makefile->GetCMakeInstance()->GetDebugConfigs();
- std::string prop;
-
- // Include this library in the link interface for the target.
- if (llt == DEBUG_LibraryType || llt == GENERAL_LibraryType) {
- // 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());
+ // Handle (additional) backward-compatibility case where the command was
+ // called with PUBLIC / INTERFACE / LINK_PUBLIC / LINK_INTERFACE_LIBRARIES.
+ // (The policy CMP0022 is not set to NEW.)
+ {
+ // Get the list of configurations considered to be DEBUG.
+ std::vector<std::string> debugConfigs =
+ this->Makefile->GetCMakeInstance()->GetDebugConfigs();
+ std::string prop;
+
+ // Include this library in the link interface for the target.
+ if (llt == DEBUG_LibraryType || llt == GENERAL_LibraryType) {
+ // Put in the DEBUG configuration interfaces.
+ for (std::string const& dc : debugConfigs) {
+ prop = "LINK_INTERFACE_LIBRARIES_";
+ prop += dc;
+ this->Target->AppendProperty(prop, libRef.c_str());
+ }
}
- }
- if (llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType) {
- // 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, "");
+ if (llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType) {
+ // Put in the non-DEBUG configuration interfaces.
+ this->Target->AppendProperty("LINK_INTERFACE_LIBRARIES", libRef.c_str());
+
+ // Make sure the DEBUG configuration interfaces exist so that the
+ // general one will not be used as a fall-back.
+ for (std::string const& dc : debugConfigs) {
+ prop = "LINK_INTERFACE_LIBRARIES_";
+ prop += dc;
+ if (!this->Target->GetProperty(prop)) {
+ this->Target->SetProperty(prop, "");
+ }
}
}
}
diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h
index 3fd20accd..54f8cf4b8 100644
--- a/Source/cmTargetLinkLibrariesCommand.h
+++ b/Source/cmTargetLinkLibrariesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTargetLinkLibrariesCommand_h
#define cmTargetLinkLibrariesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -20,6 +20,9 @@ class cmTarget;
* 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).
+ *
+ * Additionally, it allows to propagate usage-requirements (including link
+ * libraries) from one target into another.
*/
class cmTargetLinkLibrariesCommand : public cmCommand
{
@@ -27,20 +30,20 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmTargetLinkLibrariesCommand; }
+ cmCommand* Clone() override { return new cmTargetLinkLibrariesCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
void LinkLibraryTypeSpecifierWarning(int left, int right);
static const char* LinkLibraryTypeNames[3];
- cmTarget* Target;
+ cmTarget* Target = nullptr;
enum ProcessingState
{
ProcessingLinkLibraries,
@@ -52,7 +55,7 @@ private:
ProcessingKeywordPrivateInterface
};
- ProcessingState CurrentProcessingState;
+ ProcessingState CurrentProcessingState = ProcessingLinkLibraries;
bool HandleLibrary(const std::string& lib, cmTargetLinkLibraryType llt);
};
diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx
index 45fe430c1..1b8ee812f 100644
--- a/Source/cmTargetPropCommandBase.cxx
+++ b/Source/cmTargetPropCommandBase.cxx
@@ -17,11 +17,11 @@ bool cmTargetPropCommandBase::HandleArguments(
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;
}
+ // Lookup the target for which property-values are specified.
this->Target =
this->Makefile->GetCMakeInstance()->GetGlobalGenerator()->FindTarget(
args[0]);
@@ -85,18 +85,6 @@ bool cmTargetPropCommandBase::ProcessContentArgs(
return false;
}
- if (this->Target->IsImported()) {
- this->HandleImportedTarget(args[0]);
- return false;
- }
-
- if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY &&
- scope != "INTERFACE") {
- this->SetError("may only be set INTERFACE properties on INTERFACE "
- "targets");
- return false;
- }
-
++argIndex;
std::vector<std::string> content;
@@ -104,10 +92,21 @@ bool cmTargetPropCommandBase::ProcessContentArgs(
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);
+ break;
}
content.push_back(args[i]);
}
+ if (!content.empty()) {
+ if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY &&
+ scope != "INTERFACE") {
+ this->SetError("may only set INTERFACE properties on INTERFACE targets");
+ return false;
+ }
+ if (this->Target->IsImported() && scope != "INTERFACE") {
+ this->SetError("may only set INTERFACE properties on IMPORTED targets");
+ return false;
+ }
+ }
return this->PopulateTargetProperies(scope, content, prepend, system);
}
@@ -115,6 +114,9 @@ bool cmTargetPropCommandBase::PopulateTargetProperies(
const std::string& scope, const std::vector<std::string>& content,
bool prepend, bool system)
{
+ if (content.empty()) {
+ return true;
+ }
if (scope == "PRIVATE" || scope == "PUBLIC") {
if (!this->HandleDirectContent(this->Target, content, prepend, system)) {
return false;
diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h
index 46a2f6b07..943285df1 100644
--- a/Source/cmTargetPropCommandBase.h
+++ b/Source/cmTargetPropCommandBase.h
@@ -28,14 +28,13 @@ public:
protected:
std::string Property;
- cmTarget* Target;
+ cmTarget* Target = nullptr;
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,
diff --git a/Source/cmTargetPropertyComputer.cxx b/Source/cmTargetPropertyComputer.cxx
index a57bc5aea..3f763afaf 100644
--- a/Source/cmTargetPropertyComputer.cxx
+++ b/Source/cmTargetPropertyComputer.cxx
@@ -3,21 +3,22 @@
#include "cmTargetPropertyComputer.h"
+#include <cctype>
#include <sstream>
+#include <unordered_set>
+#include "cmMessageType.h"
#include "cmMessenger.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
-#include "cm_unordered_set.hxx"
-#include "cmake.h"
bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
std::string const& tgtName, cmMessenger* messenger,
cmListFileBacktrace const& context)
{
std::ostringstream e;
- const char* modal = CM_NULLPTR;
- cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+ const char* modal = nullptr;
+ MessageType messageType = MessageType::AUTHOR_WARNING;
switch (context.GetBottom().GetPolicy(cmPolicies::CMP0026)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
@@ -28,7 +29,7 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
modal = "may";
- messageType = cmake::FATAL_ERROR;
+ messageType = MessageType::FATAL_ERROR;
}
if (modal) {
@@ -40,7 +41,7 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
messenger->IssueMessage(messageType, e.str(), context);
}
- return messageType != cmake::FATAL_ERROR;
+ return messageType != MessageType::FATAL_ERROR;
}
bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
@@ -49,15 +50,26 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
if (cmHasLiteralPrefix(prop, "INTERFACE_")) {
return true;
}
- static CM_UNORDERED_SET<std::string> builtIns;
+ if (cmHasLiteralPrefix(prop, "_")) {
+ return true;
+ }
+ if (std::islower(prop[0])) {
+ return true;
+ }
+ static std::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("EXPORT_PROPERTIES");
builtIns.insert("IMPORTED");
+ builtIns.insert("IMPORTED_GLOBAL");
+ builtIns.insert("MANUALLY_ADDED_DEPENDENCIES");
builtIns.insert("NAME");
+ builtIns.insert("PRIVATE_HEADER");
+ builtIns.insert("PUBLIC_HEADER");
builtIns.insert("TYPE");
}
@@ -66,12 +78,19 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
}
if (prop == "IMPORTED_CONFIGURATIONS" || prop == "IMPORTED_LIBNAME" ||
- prop == "NO_SYSTEM_FROM_IMPORTED" ||
cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME_") ||
cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_")) {
return true;
}
+ // This property should not be allowed but was incorrectly added in
+ // CMake 3.8. We can't remove it from the whitelist without breaking
+ // projects that try to set it. One day we could warn about this, but
+ // for now silently accept it.
+ if (prop == "NO_SYSTEM_FROM_IMPORTED") {
+ return true;
+ }
+
return false;
}
@@ -85,7 +104,7 @@ bool cmTargetPropertyComputer::PassesWhitelist(
e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
"The property \""
<< prop << "\" is not allowed.";
- messenger->IssueMessage(cmake::FATAL_ERROR, e.str(), context);
+ messenger->IssueMessage(MessageType::FATAL_ERROR, e.str(), context);
return false;
}
return true;
diff --git a/Source/cmTargetPropertyComputer.h b/Source/cmTargetPropertyComputer.h
index 94688e313..efbf95f7f 100644
--- a/Source/cmTargetPropertyComputer.h
+++ b/Source/cmTargetPropertyComputer.h
@@ -26,12 +26,12 @@ public:
return loc;
}
if (cmSystemTools::GetFatalErrorOccured()) {
- return CM_NULLPTR;
+ return nullptr;
}
if (prop == "SOURCES") {
return GetSources(tgt, messenger, context);
}
- return CM_NULLPTR;
+ return nullptr;
}
static bool WhiteListedInterfaceProperty(const std::string& prop);
@@ -69,7 +69,7 @@ private:
if (!tgt->IsImported() &&
!HandleLocationPropertyPolicy(tgt->GetName(), messenger,
context)) {
- return CM_NULLPTR;
+ return nullptr;
}
return ComputeLocationForBuild(tgt);
}
@@ -79,9 +79,9 @@ private:
if (!tgt->IsImported() &&
!HandleLocationPropertyPolicy(tgt->GetName(), messenger,
context)) {
- return CM_NULLPTR;
+ return nullptr;
}
- const char* configName = prop.c_str() + 9;
+ std::string configName = prop.substr(9);
return ComputeLocation(tgt, configName);
}
@@ -93,13 +93,13 @@ private:
if (!tgt->IsImported() &&
!HandleLocationPropertyPolicy(tgt->GetName(), messenger,
context)) {
- return CM_NULLPTR;
+ return nullptr;
}
return ComputeLocation(tgt, configName);
}
}
}
- return CM_NULLPTR;
+ return nullptr;
}
template <typename Target>
diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx
index 058659a52..11e288fe6 100644
--- a/Source/cmTargetSourcesCommand.cxx
+++ b/Source/cmTargetSourcesCommand.cxx
@@ -5,9 +5,12 @@
#include <sstream>
#include "cmAlgorithms.h"
+#include "cmGeneratorExpression.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmPolicies.h"
+#include "cmSystemTools.h"
#include "cmTarget.h"
-#include "cmake.h"
class cmExecutionStatus;
@@ -17,11 +20,12 @@ bool cmTargetSourcesCommand::InitialPass(std::vector<std::string> const& args,
return this->HandleArguments(args, "SOURCES");
}
-void cmTargetSourcesCommand::HandleImportedTarget(const std::string& tgt)
+void cmTargetSourcesCommand::HandleInterfaceContent(
+ cmTarget* tgt, const std::vector<std::string>& content, bool prepend,
+ bool system)
{
- std::ostringstream e;
- e << "Cannot specify sources for imported target \"" << tgt << "\".";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ cmTargetPropCommandBase::HandleInterfaceContent(
+ tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system);
}
void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name)
@@ -30,7 +34,7 @@ void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name)
e << "Cannot specify sources for target \"" << name
<< "\" "
"which is not built by this project.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+ this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
}
std::string cmTargetSourcesCommand::Join(
@@ -42,6 +46,79 @@ std::string cmTargetSourcesCommand::Join(
bool cmTargetSourcesCommand::HandleDirectContent(
cmTarget* tgt, const std::vector<std::string>& content, bool, bool)
{
- tgt->AppendProperty("SOURCES", this->Join(content).c_str());
- return true;
+ tgt->AppendProperty(
+ "SOURCES",
+ this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str());
+ return true; // Successfully handled.
+}
+
+std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent(
+ cmTarget* tgt, const std::vector<std::string>& content,
+ bool isInterfaceContent)
+{
+ // Skip conversion in case old behavior has been explicitly requested
+ if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076) ==
+ cmPolicies::OLD) {
+ return content;
+ }
+
+ bool changedPath = false;
+ std::vector<std::string> absoluteContent;
+ absoluteContent.reserve(content.size());
+ for (std::string const& src : content) {
+ std::string absoluteSrc;
+ if (cmSystemTools::FileIsFullPath(src) ||
+ cmGeneratorExpression::Find(src) == 0 ||
+ (!isInterfaceContent &&
+ (this->Makefile->GetCurrentSourceDirectory() ==
+ tgt->GetMakefile()->GetCurrentSourceDirectory()))) {
+ absoluteSrc = src;
+ } else {
+ changedPath = true;
+ absoluteSrc = this->Makefile->GetCurrentSourceDirectory();
+ absoluteSrc += "/";
+ absoluteSrc += src;
+ }
+ absoluteContent.push_back(absoluteSrc);
+ }
+
+ if (!changedPath) {
+ return content;
+ }
+
+ bool issueMessage = true;
+ bool useAbsoluteContent = false;
+ std::ostringstream e;
+ switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0076)) {
+ case cmPolicies::WARN:
+ e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0076) << "\n";
+ break;
+ case cmPolicies::OLD:
+ issueMessage = false;
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ this->Makefile->IssueMessage(
+ MessageType::FATAL_ERROR,
+ cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0076));
+ break;
+ case cmPolicies::NEW: {
+ issueMessage = false;
+ useAbsoluteContent = true;
+ break;
+ }
+ }
+
+ if (issueMessage) {
+ if (isInterfaceContent) {
+ e << "An interface source of target \"" << tgt->GetName()
+ << "\" has a relative path.";
+ } else {
+ e << "A private source from a directory other than that of target \""
+ << tgt->GetName() << "\" has a relative path.";
+ }
+ this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
+ }
+
+ return useAbsoluteContent ? absoluteContent : content;
}
diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h
index 09ba72915..b01e3ca25 100644
--- a/Source/cmTargetSourcesCommand.h
+++ b/Source/cmTargetSourcesCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTargetSourcesCommand_h
#define cmTargetSourcesCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -20,24 +20,32 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmTargetSourcesCommand; }
+ cmCommand* Clone() override { return new cmTargetSourcesCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
+
+protected:
+ void HandleInterfaceContent(cmTarget* tgt,
+ const std::vector<std::string>& content,
+ bool prepend, bool system) override;
private:
- void HandleImportedTarget(const std::string& tgt) CM_OVERRIDE;
- void HandleMissingTarget(const std::string& name) CM_OVERRIDE;
+ void HandleMissingTarget(const std::string& name) override;
bool HandleDirectContent(cmTarget* tgt,
const std::vector<std::string>& content,
- bool prepend, bool system) CM_OVERRIDE;
+ bool prepend, bool system) override;
+
+ std::string Join(const std::vector<std::string>& content) override;
- std::string Join(const std::vector<std::string>& content) CM_OVERRIDE;
+ std::vector<std::string> ConvertToAbsoluteContent(
+ cmTarget* tgt, const std::vector<std::string>& content,
+ bool isInterfaceContent);
};
#endif
diff --git a/Source/cmTest.cxx b/Source/cmTest.cxx
index 4d0cbaafc..7d45cf5e3 100644
--- a/Source/cmTest.cxx
+++ b/Source/cmTest.cxx
@@ -14,9 +14,7 @@ cmTest::cmTest(cmMakefile* mf)
this->OldStyle = true;
}
-cmTest::~cmTest()
-{
-}
+cmTest::~cmTest() = default;
cmListFileBacktrace const& cmTest::GetBacktrace() const
{
diff --git a/Source/cmTest.h b/Source/cmTest.h
index d4839d171..88dc73089 100644
--- a/Source/cmTest.h
+++ b/Source/cmTest.h
@@ -26,14 +26,14 @@ public:
cmTest(cmMakefile* mf);
~cmTest();
- ///! Set the test name
+ //! 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; }
- ///! Set/Get a property of this source file
+ //! 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);
diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx
index be4b37847..571cd0909 100644
--- a/Source/cmTestGenerator.cxx
+++ b/Source/cmTestGenerator.cxx
@@ -2,16 +2,17 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTestGenerator.h"
-#include <map>
#include <ostream>
#include <utility>
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
+#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmOutputConverter.h"
#include "cmProperty.h"
#include "cmPropertyMap.h"
+#include "cmRange.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTest.h"
@@ -23,18 +24,26 @@ cmTestGenerator::cmTestGenerator(
{
this->ActionsPerConfig = !test->GetOldStyle();
this->TestGenerated = false;
- this->LG = CM_NULLPTR;
+ this->LG = nullptr;
}
-cmTestGenerator::~cmTestGenerator()
-{
-}
+cmTestGenerator::~cmTestGenerator() = default;
void cmTestGenerator::Compute(cmLocalGenerator* lg)
{
this->LG = lg;
}
+bool cmTestGenerator::TestsForConfig(const std::string& config)
+{
+ return this->GeneratesForConfig(config);
+}
+
+cmTest* cmTestGenerator::GetTest() const
+{
+ return this->Test;
+}
+
void cmTestGenerator::GenerateScriptConfigs(std::ostream& os, Indent indent)
{
// Create the tests.
@@ -80,30 +89,28 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
// Prepend with the emulator when cross compiling if required.
const char* emulator = target->GetProperty("CROSSCOMPILING_EMULATOR");
- if (emulator != CM_NULLPTR) {
+ if (emulator != nullptr && *emulator) {
std::vector<std::string> emulatorWithArgs;
cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs);
std::string emulatorExe(emulatorWithArgs[0]);
cmSystemTools::ConvertToUnixSlashes(emulatorExe);
os << cmOutputConverter::EscapeForCMake(emulatorExe) << " ";
- for (std::vector<std::string>::const_iterator ei =
- emulatorWithArgs.begin() + 1;
- ei != emulatorWithArgs.end(); ++ei) {
- os << cmOutputConverter::EscapeForCMake(*ei) << " ";
+ for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) {
+ os << cmOutputConverter::EscapeForCMake(arg) << " ";
}
}
} else {
// Use the command name given.
- exe = ge.Parse(exe.c_str())->Evaluate(this->LG, config);
+ exe = ge.Parse(exe)->Evaluate(this->LG, config);
cmSystemTools::ConvertToUnixSlashes(exe);
}
// Generate the command line with full escapes.
os << cmOutputConverter::EscapeForCMake(exe);
- for (std::vector<std::string>::const_iterator ci = command.begin() + 1;
- ci != command.end(); ++ci) {
- os << " " << cmOutputConverter::EscapeForCMake(
- ge.Parse(*ci)->Evaluate(this->LG, config));
+ for (std::string const& arg : cmMakeRange(command).advance(1)) {
+ os << " "
+ << cmOutputConverter::EscapeForCMake(
+ ge.Parse(arg)->Evaluate(this->LG, config));
}
// Finish the test command.
@@ -111,16 +118,15 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
// 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 << " "
- << cmOutputConverter::EscapeForCMake(
- ge.Parse(i->second.GetValue())->Evaluate(this->LG, config));
- }
- os << ")" << std::endl;
+ os << indent << "set_tests_properties(" << this->Test->GetName()
+ << " PROPERTIES ";
+ for (auto const& i : pm) {
+ os << " " << i.first << " "
+ << cmOutputConverter::EscapeForCMake(
+ ge.Parse(i.second.GetValue())->Evaluate(this->LG, config));
}
+ this->GenerateInternalProperties(os);
+ os << ")" << std::endl;
}
void cmTestGenerator::GenerateScriptNoConfig(std::ostream& os, Indent indent)
@@ -149,20 +155,18 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent)
fout << "add_test(";
fout << this->Test->GetName() << " \"" << exe << "\"";
- for (std::vector<std::string>::const_iterator argit = command.begin() + 1;
- argit != command.end(); ++argit) {
+ for (std::string const& arg : cmMakeRange(command).advance(1)) {
// 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) {
+ for (char c : arg) {
// 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 == '"')) {
+ if (c == '"') {
fout << '\\';
}
- fout << *c;
+ fout << c;
}
fout << "\"";
}
@@ -170,13 +174,37 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent)
// Output properties for the test.
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 << " "
- << cmOutputConverter::EscapeForCMake(i->second.GetValue());
+ fout << indent << "set_tests_properties(" << this->Test->GetName()
+ << " PROPERTIES ";
+ for (auto const& i : pm) {
+ fout << " " << i.first << " "
+ << cmOutputConverter::EscapeForCMake(i.second.GetValue());
+ }
+ this->GenerateInternalProperties(fout);
+ fout << ")" << std::endl;
+}
+
+void cmTestGenerator::GenerateInternalProperties(std::ostream& os)
+{
+ cmListFileBacktrace bt = this->Test->GetBacktrace();
+ if (bt.Empty()) {
+ return;
+ }
+
+ os << " "
+ << "_BACKTRACE_TRIPLES"
+ << " \"";
+
+ bool prependTripleSeparator = false;
+ while (!bt.Empty()) {
+ const auto& entry = bt.Top();
+ if (prependTripleSeparator) {
+ os << ";";
}
- fout << ")" << std::endl;
+ os << entry.FilePath << ";" << entry.Line << ";" << entry.Name;
+ bt = bt.Pop();
+ prependTripleSeparator = true;
}
+
+ os << "\"";
}
diff --git a/Source/cmTestGenerator.h b/Source/cmTestGenerator.h
index b2273050f..8b9cf78a1 100644
--- a/Source/cmTestGenerator.h
+++ b/Source/cmTestGenerator.h
@@ -3,7 +3,7 @@
#ifndef cmTestGenerator_h
#define cmTestGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmScriptGenerator.h"
@@ -20,23 +20,32 @@ class cmTest;
*/
class cmTestGenerator : public cmScriptGenerator
{
- CM_DISABLE_COPY(cmTestGenerator)
-
public:
cmTestGenerator(cmTest* test,
std::vector<std::string> const& configurations =
std::vector<std::string>());
- ~cmTestGenerator() CM_OVERRIDE;
+ ~cmTestGenerator() override;
+
+ cmTestGenerator(cmTestGenerator const&) = delete;
+ cmTestGenerator& operator=(cmTestGenerator const&) = delete;
void Compute(cmLocalGenerator* lg);
+ /** Test if this generator installs the test for a given configuration. */
+ bool TestsForConfig(const std::string& config);
+
+ cmTest* GetTest() const;
+
+private:
+ void GenerateInternalProperties(std::ostream& os);
+
protected:
- void GenerateScriptConfigs(std::ostream& os, Indent indent) CM_OVERRIDE;
- void GenerateScriptActions(std::ostream& os, Indent indent) CM_OVERRIDE;
+ void GenerateScriptConfigs(std::ostream& os, Indent indent) override;
+ void GenerateScriptActions(std::ostream& os, Indent indent) override;
void GenerateScriptForConfig(std::ostream& os, const std::string& config,
- Indent indent) CM_OVERRIDE;
- void GenerateScriptNoConfig(std::ostream& os, Indent indent) CM_OVERRIDE;
- bool NeedsScriptNoConfig() const CM_OVERRIDE;
+ Indent indent) override;
+ void GenerateScriptNoConfig(std::ostream& os, Indent indent) override;
+ bool NeedsScriptNoConfig() const override;
void GenerateOldStyle(std::ostream& os, Indent indent);
cmLocalGenerator* LG;
diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx
index 4b9718847..da5d21ebb 100644
--- a/Source/cmTimestamp.cxx
+++ b/Source/cmTimestamp.cxx
@@ -2,7 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTimestamp.h"
-#include "cmConfigure.h"
#include <cstring>
#include <sstream>
#include <stdlib.h>
@@ -12,7 +11,7 @@
std::string cmTimestamp::CurrentTime(const std::string& formatString,
bool utcFlag)
{
- time_t currentTimeT = time(CM_NULLPTR);
+ time_t currentTimeT = time(nullptr);
std::string source_date_epoch;
cmSystemTools::GetEnv("SOURCE_DATE_EPOCH", source_date_epoch);
if (!source_date_epoch.empty()) {
@@ -34,11 +33,14 @@ std::string cmTimestamp::FileModificationTime(const char* path,
const std::string& formatString,
bool utcFlag)
{
- if (!cmsys::SystemTools::FileExists(path)) {
+ std::string real_path =
+ cmSystemTools::GetRealPathResolvingWindowsSubst(path);
+
+ if (!cmsys::SystemTools::FileExists(real_path)) {
return std::string();
}
- time_t mtime = cmsys::SystemTools::ModifiedTime(path);
+ time_t mtime = cmsys::SystemTools::ModifiedTime(real_path);
return CreateTimestampFromTimeT(mtime, formatString, utcFlag);
}
@@ -56,14 +58,14 @@ std::string cmTimestamp::CreateTimestampFromTimeT(time_t timeT,
struct tm timeStruct;
memset(&timeStruct, 0, sizeof(timeStruct));
- struct tm* ptr = (struct tm*)CM_NULLPTR;
+ struct tm* ptr = nullptr;
if (utcFlag) {
ptr = gmtime(&timeT);
} else {
ptr = localtime(&timeT);
}
- if (ptr == CM_NULLPTR) {
+ if (ptr == nullptr) {
return std::string();
}
@@ -94,7 +96,7 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const
// From Linux timegm() manpage.
std::string tz_old;
- cmSystemTools::GetEnv("TZ", tz_old);
+ bool const tz_was_set = cmSystemTools::GetEnv("TZ", tz_old);
tz_old = "TZ=" + tz_old;
// The standard says that "TZ=" or "TZ=[UNRECOGNIZED_TZ]" means UTC.
@@ -107,7 +109,17 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const
time_t result = mktime(&tm);
+# ifdef CMAKE_BUILD_WITH_CMAKE
+ if (tz_was_set) {
+ cmSystemTools::PutEnv(tz_old);
+ } else {
+ cmSystemTools::UnsetEnv("TZ");
+ }
+# else
+ // No UnsetEnv during bootstrap. This is good enough for CMake itself.
cmSystemTools::PutEnv(tz_old);
+ static_cast<void>(tz_was_set);
+# endif
tzset();
@@ -124,7 +136,9 @@ std::string cmTimestamp::AddTimestampComponent(char flag,
switch (flag) {
case 'a':
+ case 'A':
case 'b':
+ case 'B':
case 'd':
case 'H':
case 'I':
@@ -150,7 +164,7 @@ std::string cmTimestamp::AddTimestampComponent(char flag,
if (unixEpoch == -1) {
cmSystemTools::Error(
"Error generating UNIX epoch in "
- "STRING(TIMESTAMP ...). Please, file a bug report aginst CMake");
+ "STRING(TIMESTAMP ...). Please, file a bug report against CMake");
return std::string();
}
diff --git a/Source/cmTimestamp.h b/Source/cmTimestamp.h
index 8dd499a3e..d5fbdfd67 100644
--- a/Source/cmTimestamp.h
+++ b/Source/cmTimestamp.h
@@ -15,20 +15,18 @@
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:
- time_t CreateUtcTimeTFromTm(struct tm& timeStruct) const;
-
std::string CreateTimestampFromTimeT(time_t timeT, std::string formatString,
bool utcFlag) const;
+private:
+ time_t CreateUtcTimeTFromTm(struct tm& timeStruct) const;
+
std::string AddTimestampComponent(char flag, struct tm& timeStruct,
time_t timeT) const;
};
diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx
index b6bfbfa69..05b3f0587 100644
--- a/Source/cmTryCompileCommand.cxx
+++ b/Source/cmTryCompileCommand.cxx
@@ -3,6 +3,7 @@
#include "cmTryCompileCommand.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmake.h"
class cmExecutionStatus;
@@ -18,7 +19,7 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& argv,
if (this->Makefile->GetCMakeInstance()->GetWorkingMode() ==
cmake::FIND_PACKAGE_MODE) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"The TRY_COMPILE() command is not supported in --find-package mode.");
return false;
}
@@ -28,7 +29,7 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& 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());
+ this->CleanupFiles(this->BinaryDirectory);
}
}
return true;
diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h
index 483654822..82378780e 100644
--- a/Source/cmTryCompileCommand.h
+++ b/Source/cmTryCompileCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTryCompileCommand_h
#define cmTryCompileCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,7 +16,7 @@ class cmExecutionStatus;
/** \class cmTryCompileCommand
* \brief Specifies where to install some files
*
- * cmTryCompileCommand is used to test if soucre code can be compiled
+ * cmTryCompileCommand is used to test if source code can be compiled
*/
class cmTryCompileCommand : public cmCoreTryCompile
{
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmTryCompileCommand; }
+ cmCommand* Clone() override { return new cmTryCompileCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx
index 07e20e62f..a92c2a05c 100644
--- a/Source/cmTryRunCommand.cxx
+++ b/Source/cmTryRunCommand.cxx
@@ -4,9 +4,11 @@
#include "cmsys/FStream.hxx"
#include <stdio.h>
-#include <string.h>
+#include "cmDuration.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmRange.h"
#include "cmState.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
@@ -25,7 +27,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
if (this->Makefile->GetCMakeInstance()->GetWorkingMode() ==
cmake::FIND_PACKAGE_MODE) {
this->Makefile->IssueMessage(
- cmake::FATAL_ERROR,
+ MessageType::FATAL_ERROR,
"The TRY_RUN() command is not supported in --find-package mode.");
return false;
}
@@ -33,11 +35,11 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
// 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 = "";
+ this->CompileResultVariable.clear();
+ this->RunResultVariable.clear();
+ this->OutputVariable.clear();
+ this->RunOutputVariable.clear();
+ this->CompileOutputVariable.clear();
std::string runArgs;
unsigned int i;
@@ -45,7 +47,8 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
if (argv[i] == "ARGS") {
++i;
while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" &&
- argv[i] != "CMAKE_FLAGS" && argv[i] != "LINK_LIBRARIES") {
+ argv[i] != "CMAKE_FLAGS" && argv[i] != "LINK_OPTIONS" &&
+ argv[i] != "LINK_LIBRARIES") {
runArgs += " ";
runArgs += argv[i];
++i;
@@ -99,11 +102,11 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
bool captureRunOutput = false;
if (!this->OutputVariable.empty()) {
captureRunOutput = true;
- tryCompile.push_back("OUTPUT_VARIABLE");
+ tryCompile.emplace_back("OUTPUT_VARIABLE");
tryCompile.push_back(this->OutputVariable);
}
if (!this->CompileOutputVariable.empty()) {
- tryCompile.push_back("OUTPUT_VARIABLE");
+ tryCompile.emplace_back("OUTPUT_VARIABLE");
tryCompile.push_back(this->CompileOutputVariable);
}
if (!this->RunOutputVariable.empty()) {
@@ -119,15 +122,14 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
// now try running the command if it compiled
if (!res) {
if (this->OutputFile.empty()) {
- cmSystemTools::Error(this->FindErrorMessage.c_str());
+ cmSystemTools::Error(this->FindErrorMessage);
} else {
// "run" it and capture the output
std::string runOutputContents;
if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING") &&
!this->Makefile->IsDefinitionSet("CMAKE_CROSSCOMPILING_EMULATOR")) {
- this->DoNotRunExecutable(runArgs, argv[3], captureRunOutput
- ? &runOutputContents
- : CM_NULLPTR);
+ this->DoNotRunExecutable(
+ runArgs, argv[3], captureRunOutput ? &runOutputContents : nullptr);
} else {
this->RunExecutable(runArgs, &runOutputContents);
}
@@ -144,7 +146,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
const char* compileOutput =
this->Makefile->GetDefinition(this->OutputVariable);
if (compileOutput) {
- runOutputContents = std::string(compileOutput) + runOutputContents;
+ runOutputContents = compileOutput + runOutputContents;
}
this->Makefile->AddDefinition(this->OutputVariable,
runOutputContents.c_str());
@@ -154,7 +156,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
// if we created a directory etc, then cleanup after ourselves
if (!this->Makefile->GetCMakeInstance()->GetDebugTryCompile()) {
- this->CleanupFiles(this->BinaryDirectory.c_str());
+ this->CleanupFiles(this->BinaryDirectory);
}
return true;
}
@@ -165,40 +167,38 @@ void cmTryRunCommand::RunExecutable(const std::string& runArgs,
int retVal = -1;
std::string finalCommand;
- const std::string emulator =
+ const std::string& emulator =
this->Makefile->GetSafeDefinition("CMAKE_CROSSCOMPILING_EMULATOR");
if (!emulator.empty()) {
std::vector<std::string> emulatorWithArgs;
cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs);
finalCommand +=
- cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0].c_str());
+ cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0]);
finalCommand += " ";
- for (std::vector<std::string>::const_iterator ei =
- emulatorWithArgs.begin() + 1;
- ei != emulatorWithArgs.end(); ++ei) {
+ for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) {
finalCommand += "\"";
- finalCommand += *ei;
+ finalCommand += arg;
finalCommand += "\"";
finalCommand += " ";
}
}
- finalCommand +=
- cmSystemTools::ConvertToRunCommandPath(this->OutputFile.c_str());
+ finalCommand += cmSystemTools::ConvertToRunCommandPath(this->OutputFile);
if (!runArgs.empty()) {
finalCommand += runArgs;
}
- int timeout = 0;
bool worked = cmSystemTools::RunSingleCommand(
- finalCommand.c_str(), out, out, &retVal, CM_NULLPTR,
- cmSystemTools::OUTPUT_NONE, timeout);
+ finalCommand, out, out, &retVal, nullptr, cmSystemTools::OUTPUT_NONE,
+ cmDuration::zero());
// set the run var
- char retChar[1000];
+ char retChar[16];
+ const char* retStr;
if (worked) {
sprintf(retChar, "%i", retVal);
+ retStr = retChar;
} else {
- strcpy(retChar, "FAILED_TO_RUN");
+ retStr = "FAILED_TO_RUN";
}
- this->Makefile->AddCacheDefinition(this->RunResultVariable, retChar,
+ this->Makefile->AddCacheDefinition(this->RunResultVariable, retStr,
"Result of TRY_RUN",
cmStateEnums::INTERNAL);
}
@@ -215,7 +215,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
// 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 += "/CMakeFiles";
copyDest += "/";
copyDest += cmSystemTools::GetFilenameWithoutExtension(this->OutputFile);
copyDest += "-";
@@ -233,7 +233,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
this->RunResultVariable + "__TRYRUN_OUTPUT";
bool error = false;
- if (this->Makefile->GetDefinition(this->RunResultVariable) == CM_NULLPTR) {
+ if (!this->Makefile->GetDefinition(this->RunResultVariable)) {
// if the variables doesn't exist, create it with a helpful error text
// and mark it as advanced
std::string comment;
@@ -255,8 +255,8 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
}
// is the output from the executable used ?
- if (out != CM_NULLPTR) {
- if (this->Makefile->GetDefinition(internalRunOutputName) == CM_NULLPTR) {
+ if (out) {
+ if (!this->Makefile->GetDefinition(internalRunOutputName)) {
// if the variables doesn't exist, create it with a helpful error text
// and mark it as advanced
std::string comment;
@@ -304,7 +304,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
comment += " to\n"
" the exit code (in many cases 0 for success), otherwise "
"enter \"FAILED_TO_RUN\".\n";
- if (out != CM_NULLPTR) {
+ if (out) {
comment += internalRunOutputName;
comment +=
"\n contains the text the executable "
@@ -335,7 +335,7 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
<< this->Makefile->GetDefinition(this->RunResultVariable)
<< "\"\n CACHE STRING \"Result from TRY_RUN\" FORCE)\n\n";
- if (out != CM_NULLPTR) {
+ if (out) {
file << "set( " << internalRunOutputName << " \n \""
<< this->Makefile->GetDefinition(internalRunOutputName)
<< "\"\n CACHE STRING \"Output from TRY_RUN\" FORCE)\n\n";
@@ -348,15 +348,15 @@ void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
"please set the following cache variables "
"appropriately:\n";
errorMessage += " " + this->RunResultVariable + " (advanced)\n";
- if (out != CM_NULLPTR) {
+ if (out) {
errorMessage += " " + internalRunOutputName + " (advanced)\n";
}
errorMessage += detailsString;
- cmSystemTools::Error(errorMessage.c_str());
+ cmSystemTools::Error(errorMessage);
return;
}
- if (out != CM_NULLPTR) {
+ if (out) {
(*out) = this->Makefile->GetDefinition(internalRunOutputName);
}
}
diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h
index c27b026ad..c54622c63 100644
--- a/Source/cmTryRunCommand.h
+++ b/Source/cmTryRunCommand.h
@@ -3,7 +3,7 @@
#ifndef cmTryRunCommand_h
#define cmTryRunCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -16,7 +16,7 @@ class cmExecutionStatus;
/** \class cmTryRunCommand
* \brief Specifies where to install some files
*
- * cmTryRunCommand is used to test if soucre code can be compiled
+ * cmTryRunCommand is used to test if source code can be compiled
*/
class cmTryRunCommand : public cmCoreTryCompile
{
@@ -24,14 +24,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmTryRunCommand; }
+ cmCommand* Clone() override { return new cmTryRunCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
void RunExecutable(const std::string& runArgs,
diff --git a/Source/cmUnexpectedCommand.h b/Source/cmUnexpectedCommand.h
index 995d8a5d6..33d6bdc2c 100644
--- a/Source/cmUnexpectedCommand.h
+++ b/Source/cmUnexpectedCommand.h
@@ -3,9 +3,10 @@
#ifndef cmUnexpectedCommand_h
#define cmUnexpectedCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
+#include <utility>
#include <vector>
#include "cmCommand.h"
@@ -15,19 +16,19 @@ class cmExecutionStatus;
class cmUnexpectedCommand : public cmCommand
{
public:
- cmUnexpectedCommand(std::string const& name, const char* error)
- : Name(name)
+ cmUnexpectedCommand(std::string name, const char* error)
+ : Name(std::move(name))
, Error(error)
{
}
- cmCommand* Clone() CM_OVERRIDE
+ cmCommand* Clone() override
{
return new cmUnexpectedCommand(this->Name, this->Error);
}
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
private:
std::string Name;
diff --git a/Source/cmUnsetCommand.cxx b/Source/cmUnsetCommand.cxx
index 31525ba4a..cfaa1fd27 100644
--- a/Source/cmUnsetCommand.cxx
+++ b/Source/cmUnsetCommand.cxx
@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmUnsetCommand.h"
-#include <string.h>
-
#include "cmAlgorithms.h"
#include "cmMakefile.h"
#include "cmSystemTools.h"
@@ -19,19 +17,16 @@ bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
return false;
}
- const char* variable = args[0].c_str();
+ auto const& variable = args[0];
// unset(ENV{VAR})
- if (cmHasLiteralPrefix(variable, "ENV{") && strlen(variable) > 5) {
+ if (cmHasLiteralPrefix(variable, "ENV{") && variable.size() > 5) {
// what is the variable name
- char* envVarName = new char[strlen(variable)];
- strncpy(envVarName, variable + 4, strlen(variable) - 5);
- envVarName[strlen(variable) - 5] = '\0';
+ auto const& envVarName = variable.substr(4, variable.size() - 5);
#ifdef CMAKE_BUILD_WITH_CMAKE
- cmSystemTools::UnsetEnv(envVarName);
+ cmSystemTools::UnsetEnv(envVarName.c_str());
#endif
- delete[] envVarName;
return true;
}
// unset(VAR)
@@ -46,7 +41,7 @@ bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
}
// unset(VAR PARENT_SCOPE)
if ((args.size() == 2) && (args[1] == "PARENT_SCOPE")) {
- this->Makefile->RaiseScope(variable, CM_NULLPTR);
+ this->Makefile->RaiseScope(variable, nullptr);
return true;
}
// ERROR: second argument isn't CACHE or PARENT_SCOPE
diff --git a/Source/cmUnsetCommand.h b/Source/cmUnsetCommand.h
index 2a1f3f0a6..4e1208a45 100644
--- a/Source/cmUnsetCommand.h
+++ b/Source/cmUnsetCommand.h
@@ -3,7 +3,7 @@
#ifndef cmUnsetCommand_h
#define cmUnsetCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -23,14 +23,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmUnsetCommand; }
+ cmCommand* Clone() override { return new cmUnsetCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmUseMangledMesaCommand.cxx b/Source/cmUseMangledMesaCommand.cxx
index 07095b137..43581947c 100644
--- a/Source/cmUseMangledMesaCommand.cxx
+++ b/Source/cmUseMangledMesaCommand.cxx
@@ -13,44 +13,43 @@ bool cmUseMangledMesaCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
// expected two arguments:
- // arguement one: the full path to gl_mangle.h
- // arguement two : directory for output of edited headers
+ // argument one: the full path to gl_mangle.h
+ // argument 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();
+ const std::string& inputDir = args[0];
std::string glh = inputDir;
glh += "/";
glh += "gl.h";
- if (!cmSystemTools::FileExists(glh.c_str())) {
+ if (!cmSystemTools::FileExists(glh)) {
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();
+ const std::string& destDir = args[1];
std::vector<std::string> files;
cmSystemTools::Glob(inputDir, "\\.h$", files);
if (files.empty()) {
- cmSystemTools::Error("Could not open Mesa Directory ", inputDir);
+ 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) {
+ for (std::string const& f : files) {
std::string path = inputDir;
path += "/";
- path += *i;
- this->CopyAndFullPathMesaHeader(path.c_str(), destDir);
+ path += f;
+ this->CopyAndFullPathMesaHeader(path, destDir);
}
return true;
}
-void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source,
- const char* outdir)
+void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(
+ const std::string& source, const std::string& outdir)
{
std::string dir, file;
cmSystemTools::SplitProgramPath(source, dir, file);
@@ -61,14 +60,14 @@ void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source,
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::Error("Could not open file for write in copy operation: " +
+ tempOutputFile + outdir);
cmSystemTools::ReportLastSystemError("");
return;
}
- cmsys::ifstream fin(source);
+ cmsys::ifstream fin(source.c_str());
if (!fin) {
- cmSystemTools::Error("Could not open file for read in copy operation",
+ cmSystemTools::Error("Could not open file for read in copy operation" +
source);
return;
}
@@ -79,16 +78,16 @@ void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source,
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)(/|\\\\)([^<\"]+)");
+ cmsys::RegularExpression glDirLine(R"((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())) {
+ if (includeLine.find(inLine)) {
std::string includeFile = includeLine.match(1);
- if (glDirLine.find(includeFile.c_str())) {
+ if (glDirLine.find(includeFile)) {
std::string gfile = glDirLine.match(3);
fout << "#include \"" << outdir << "/" << gfile << "\"\n";
- } else if (glLine.find(includeFile.c_str())) {
+ } else if (glLine.find(includeFile)) {
fout << "#include \"" << outdir << "/" << includeLine.match(1)
<< "\"\n";
} else {
@@ -101,6 +100,6 @@ void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source,
// close the files before attempting to copy
fin.close();
fout.close();
- cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), outFile.c_str());
+ cmSystemTools::CopyFileIfDifferent(tempOutputFile, outFile);
cmSystemTools::RemoveFile(tempOutputFile);
}
diff --git a/Source/cmUseMangledMesaCommand.h b/Source/cmUseMangledMesaCommand.h
index 511882989..e2f1d9b90 100644
--- a/Source/cmUseMangledMesaCommand.h
+++ b/Source/cmUseMangledMesaCommand.h
@@ -3,7 +3,7 @@
#ifndef cmUseMangledMesaCommand_h
#define cmUseMangledMesaCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,12 +15,13 @@ class cmExecutionStatus;
class cmUseMangledMesaCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmUseMangledMesaCommand; }
+ cmCommand* Clone() override { return new cmUseMangledMesaCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
protected:
- void CopyAndFullPathMesaHeader(const char* source, const char* outdir);
+ void CopyAndFullPathMesaHeader(const std::string& source,
+ const std::string& outdir);
};
#endif
diff --git a/Source/cmUtilitySourceCommand.cxx b/Source/cmUtilitySourceCommand.cxx
index eabd7ef31..b59a587cd 100644
--- a/Source/cmUtilitySourceCommand.cxx
+++ b/Source/cmUtilitySourceCommand.cxx
@@ -28,27 +28,27 @@ bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args,
// 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 =
+ std::string const& intDir =
this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
bool haveCacheValue = false;
if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING")) {
- haveCacheValue = (cacheValue != CM_NULLPTR);
+ haveCacheValue = (cacheValue != nullptr);
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");
+ cmSystemTools::Message(msg, "Warning");
}
} else {
cmState* state = this->Makefile->GetState();
- haveCacheValue =
- (cacheValue && (strstr(cacheValue, "(IntDir)") == CM_NULLPTR ||
- (intDir && strcmp(intDir, "$(IntDir)") == 0)) &&
- (state->GetCacheMajorVersion() != 0 &&
- state->GetCacheMinorVersion() != 0));
+ haveCacheValue = (cacheValue &&
+ (strstr(cacheValue, "(IntDir)") == nullptr ||
+ (intDir == "$(IntDir)")) &&
+ (state->GetCacheMajorVersion() != 0 &&
+ state->GetCacheMinorVersion() != 0));
}
if (haveCacheValue) {
@@ -66,20 +66,20 @@ bool cmUtilitySourceCommand::InitialPass(std::vector<std::string> const& args,
utilitySource = utilitySource + "/" + relativeSource;
// If the directory doesn't exist, the source has not been included.
- if (!cmSystemTools::FileExists(utilitySource.c_str())) {
+ if (!cmSystemTools::FileExists(utilitySource)) {
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())) {
+ if (!cmSystemTools::FileExists(file)) {
return true;
}
}
// The source exists.
- std::string cmakeCFGout =
+ const std::string& cmakeCFGout =
this->Makefile->GetRequiredDefinition("CMAKE_CFG_INTDIR");
std::string utilityDirectory = this->Makefile->GetCurrentBinaryDirectory();
std::string exePath;
diff --git a/Source/cmUtilitySourceCommand.h b/Source/cmUtilitySourceCommand.h
index a95b48d6a..165eceff6 100644
--- a/Source/cmUtilitySourceCommand.h
+++ b/Source/cmUtilitySourceCommand.h
@@ -3,7 +3,7 @@
#ifndef cmUtilitySourceCommand_h
#define cmUtilitySourceCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,9 +15,9 @@ class cmExecutionStatus;
class cmUtilitySourceCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmUtilitySourceCommand; }
+ cmCommand* Clone() override { return new cmUtilitySourceCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmUtils.hxx b/Source/cmUtils.hxx
index c5c767c02..a7a3e81f6 100644
--- a/Source/cmUtils.hxx
+++ b/Source/cmUtils.hxx
@@ -7,7 +7,7 @@
// 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).
+// (which is set by the Eclipse generator).
inline bool isCMakeVerbose()
{
return (cmSystemTools::HasEnv("VERBOSE") &&
diff --git a/Source/cmUuid.cxx b/Source/cmUuid.cxx
index 201e1ccef..51ecbd180 100644
--- a/Source/cmUuid.cxx
+++ b/Source/cmUuid.cxx
@@ -4,16 +4,10 @@
#include "cmCryptoHash.h"
+#include <array>
#include <string.h>
-cmUuid::cmUuid()
-{
- Groups.push_back(4);
- Groups.push_back(2);
- Groups.push_back(2);
- Groups.push_back(2);
- Groups.push_back(6);
-}
+static const std::array<int, 5> kUuidGroups = { { 4, 2, 2, 2, 6 } };
std::string cmUuid::FromMd5(std::vector<unsigned char> const& uuidNamespace,
std::string const& name) const
@@ -83,11 +77,11 @@ bool cmUuid::StringToBinary(std::string const& input,
return false;
}
size_t index = 0;
- for (size_t i = 0; i < this->Groups.size(); ++i) {
+ for (size_t i = 0; i < kUuidGroups.size(); ++i) {
if (i != 0 && input[index++] != '-') {
return false;
}
- size_t digits = this->Groups[i] * 2;
+ size_t digits = kUuidGroups[i] * 2;
if (!StringToBinaryImpl(input.substr(index, digits), output)) {
return false;
}
@@ -103,12 +97,12 @@ 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) {
+ for (size_t i = 0; i < kUuidGroups.size(); ++i) {
if (i != 0) {
output += '-';
}
- size_t bytes = this->Groups[i];
+ size_t bytes = kUuidGroups[i];
for (size_t j = 0; j < bytes; ++j) {
unsigned char byte = input[inputIndex++];
output += this->ByteToHex(byte);
diff --git a/Source/cmUuid.h b/Source/cmUuid.h
index 158ce6ee4..7de20dd29 100644
--- a/Source/cmUuid.h
+++ b/Source/cmUuid.h
@@ -15,8 +15,6 @@
class cmUuid
{
public:
- cmUuid();
-
std::string FromMd5(std::vector<unsigned char> const& uuidNamespace,
std::string const& name) const;
@@ -42,8 +40,6 @@ private:
std::string BinaryToString(const unsigned char* input) const;
bool IntFromHexDigit(char input, char& output) const;
-
- std::vector<int> Groups;
};
#endif
diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx
index 7168f266c..c78361e26 100644
--- a/Source/cmVSSetupHelper.cxx
+++ b/Source/cmVSSetupHelper.cxx
@@ -1,10 +1,13 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmVSSetupHelper.h"
+
#include "cmSystemTools.h"
+#include "cmsys/Encoding.hxx"
+#include "cmsys/FStream.hxx"
#ifndef VSSetupConstants
-#define VSSetupConstants
+# define VSSetupConstants
/* clang-format off */
const IID IID_ISetupConfiguration = {
0x42843719, 0xDB4C, 0x46C2,
@@ -41,16 +44,22 @@ const CLSID CLSID_SetupConfiguration = {
/* clang-format on */
#endif
-const WCHAR* VCToolsetComponent =
- L"Microsoft.VisualStudio.Component.VC.Tools.x86.x64";
const WCHAR* Win10SDKComponent =
L"Microsoft.VisualStudio.Component.Windows10SDK";
const WCHAR* Win81SDKComponent =
L"Microsoft.VisualStudio.Component.Windows81SDK";
const WCHAR* ComponentType = L"Component";
-cmVSSetupAPIHelper::cmVSSetupAPIHelper()
- : setupConfig(NULL)
+std::string VSInstanceInfo::GetInstallLocation() const
+{
+ std::string loc = cmsys::Encoding::ToNarrow(this->VSInstallLocation);
+ cmSystemTools::ConvertToUnixSlashes(loc);
+ return loc;
+}
+
+cmVSSetupAPIHelper::cmVSSetupAPIHelper(unsigned int version)
+ : Version(version)
+ , setupConfig(NULL)
, setupConfig2(NULL)
, setupHelper(NULL)
, initializationFailure(false)
@@ -72,7 +81,15 @@ cmVSSetupAPIHelper::~cmVSSetupAPIHelper()
CoUninitialize();
}
-bool cmVSSetupAPIHelper::IsVS2017Installed()
+bool cmVSSetupAPIHelper::SetVSInstance(std::string const& vsInstallLocation)
+{
+ this->SpecifiedVSInstallLocation = vsInstallLocation;
+ cmSystemTools::ConvertToUnixSlashes(this->SpecifiedVSInstallLocation);
+ chosenInstanceInfo = VSInstanceInfo();
+ return this->EnumerateAndChooseVSInstance();
+}
+
+bool cmVSSetupAPIHelper::IsVSInstalled()
{
return this->EnumerateAndChooseVSInstance();
}
@@ -90,11 +107,11 @@ bool cmVSSetupAPIHelper::IsWin81SDKInstalled()
}
bool cmVSSetupAPIHelper::CheckInstalledComponent(
- SmartCOMPtr<ISetupPackageReference> package, bool& bVCToolset,
- bool& bWin10SDK, bool& bWin81SDK)
+ SmartCOMPtr<ISetupPackageReference> package, bool& bWin10SDK,
+ bool& bWin81SDK)
{
bool ret = false;
- bVCToolset = bWin10SDK = bWin81SDK = false;
+ bWin10SDK = bWin81SDK = false;
SmartBSTR bstrId;
if (FAILED(package->GetId(&bstrId))) {
return ret;
@@ -107,11 +124,6 @@ bool cmVSSetupAPIHelper::CheckInstalledComponent(
std::wstring id = std::wstring(bstrId);
std::wstring type = std::wstring(bstrType);
- if (id.compare(VCToolsetComponent) == 0 &&
- type.compare(ComponentType) == 0) {
- bVCToolset = true;
- ret = true;
- }
// Checks for any version of Win10 SDK. The version is appended at the end of
// the
@@ -135,7 +147,6 @@ bool cmVSSetupAPIHelper::CheckInstalledComponent(
bool cmVSSetupAPIHelper::GetVSInstanceInfo(
SmartCOMPtr<ISetupInstance2> pInstance, VSInstanceInfo& vsInstanceInfo)
{
- bool isVCToolSetInstalled = false;
if (pInstance == NULL)
return false;
@@ -174,6 +185,24 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo(
}
}
+ // Check if a compiler is installed with this instance.
+ {
+ std::string const vcRoot = vsInstanceInfo.GetInstallLocation();
+ std::string vcToolsVersionFile =
+ vcRoot + "/VC/Auxiliary/Build/Microsoft.VCToolsVersion.default.txt";
+ std::string vcToolsVersion;
+ cmsys::ifstream fin(vcToolsVersionFile.c_str());
+ if (!fin || !cmSystemTools::GetLineFromStream(fin, vcToolsVersion)) {
+ return false;
+ }
+ vcToolsVersion = cmSystemTools::TrimWhitespace(vcToolsVersion);
+ std::string const vcToolsDir = vcRoot + "/VC/Tools/MSVC/" + vcToolsVersion;
+ if (!cmSystemTools::FileIsDirectory(vcToolsDir)) {
+ return false;
+ }
+ vsInstanceInfo.VCToolsetVersion = vcToolsVersion;
+ }
+
// Reboot may have been required before the product package was registered
// (last).
if ((eRegistered & state) == eRegistered) {
@@ -199,12 +228,11 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo(
package == NULL)
continue;
- bool vcToolsetInstalled = false, win10SDKInstalled = false,
- win81SDkInstalled = false;
- bool ret = CheckInstalledComponent(package, vcToolsetInstalled,
- win10SDKInstalled, win81SDkInstalled);
+ bool win10SDKInstalled = false;
+ bool win81SDkInstalled = false;
+ bool ret =
+ CheckInstalledComponent(package, win10SDKInstalled, win81SDkInstalled);
if (ret) {
- isVCToolSetInstalled |= vcToolsetInstalled;
vsInstanceInfo.IsWin10SDKInstalled |= win10SDKInstalled;
vsInstanceInfo.IsWin81SDKInstalled |= win81SDkInstalled;
}
@@ -213,23 +241,46 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo(
SafeArrayDestroy(lpsaPackages);
}
- return isVCToolSetInstalled;
+ return true;
}
bool cmVSSetupAPIHelper::GetVSInstanceInfo(std::string& vsInstallLocation)
{
- vsInstallLocation = "";
+ vsInstallLocation.clear();
bool isInstalled = this->EnumerateAndChooseVSInstance();
if (isInstalled) {
- std::string str(chosenInstanceInfo.VSInstallLocation.begin(),
- chosenInstanceInfo.VSInstallLocation.end());
- vsInstallLocation = str;
+ vsInstallLocation = chosenInstanceInfo.GetInstallLocation();
}
return isInstalled;
}
+bool cmVSSetupAPIHelper::GetVCToolsetVersion(std::string& vsToolsetVersion)
+{
+ vsToolsetVersion.clear();
+ bool isInstalled = this->EnumerateAndChooseVSInstance();
+
+ if (isInstalled) {
+ vsToolsetVersion = chosenInstanceInfo.VCToolsetVersion;
+ }
+
+ return isInstalled && !vsToolsetVersion.empty();
+}
+
+bool cmVSSetupAPIHelper::IsEWDKEnabled()
+{
+ std::string envEnterpriseWDK, envDisableRegistryUse;
+ cmSystemTools::GetEnv("EnterpriseWDK", envEnterpriseWDK);
+ cmSystemTools::GetEnv("DisableRegistryUse", envDisableRegistryUse);
+ if (!cmSystemTools::Strucmp(envEnterpriseWDK.c_str(), "True") &&
+ !cmSystemTools::Strucmp(envDisableRegistryUse.c_str(), "True")) {
+ return true;
+ }
+
+ return false;
+}
+
bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
{
bool isVSInstanceExists = false;
@@ -237,25 +288,38 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
return true;
}
+ if (this->IsEWDKEnabled()) {
+ std::string envWindowsSdkDir81, envVSVersion, envVsInstallDir;
+
+ cmSystemTools::GetEnv("WindowsSdkDir_81", envWindowsSdkDir81);
+ cmSystemTools::GetEnv("VisualStudioVersion", envVSVersion);
+ cmSystemTools::GetEnv("VSINSTALLDIR", envVsInstallDir);
+ if (envVSVersion.empty() || envVsInstallDir.empty())
+ return false;
+
+ chosenInstanceInfo.VSInstallLocation =
+ std::wstring(envVsInstallDir.begin(), envVsInstallDir.end());
+ chosenInstanceInfo.Version =
+ std::wstring(envVSVersion.begin(), envVSVersion.end());
+ chosenInstanceInfo.VCToolsetVersion = envVSVersion;
+ chosenInstanceInfo.ullVersion = std::stoi(envVSVersion);
+ chosenInstanceInfo.IsWin10SDKInstalled = true;
+ chosenInstanceInfo.IsWin81SDKInstalled = !envWindowsSdkDir81.empty();
+ return true;
+ }
+
if (initializationFailure || setupConfig == NULL || setupConfig2 == NULL ||
setupHelper == NULL)
return false;
std::string envVSCommonToolsDir;
+ std::string envVSCommonToolsDirEnvName =
+ "VS" + std::to_string(this->Version) + "0COMNTOOLS";
- // FIXME: When we support VS versions beyond 2017, the version
- // to choose will be passed in by the caller. We need to map that
- // to a per-version name of this environment variable.
- if (cmSystemTools::GetEnv("VS150COMNTOOLS", envVSCommonToolsDir)) {
+ if (cmSystemTools::GetEnv(envVSCommonToolsDirEnvName.c_str(),
+ envVSCommonToolsDir)) {
cmSystemTools::ConvertToUnixSlashes(envVSCommonToolsDir);
}
- // FIXME: If the environment variable value changes between runs
- // of CMake within a given build tree the results are not defined.
- // Instead we should save a CMAKE_GENERATOR_INSTANCE value in the cache
- // (similar to CMAKE_GENERATOR_TOOLSET) to hold it persistently.
- // Unfortunately doing so will require refactoring elsewhere in
- // order to make sure the value is available in time to create
- // the generator.
std::vector<VSInstanceInfo> vecVSInstances;
SmartCOMPtr<IEnumSetupInstances> enumInstances = NULL;
@@ -265,6 +329,8 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
return false;
}
+ std::wstring const wantVersion = std::to_wstring(this->Version) + L'.';
+
SmartCOMPtr<ISetupInstance> instance;
while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) {
SmartCOMPtr<ISetupInstance2> instance2 = NULL;
@@ -280,18 +346,35 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance()
instance = instance2 = NULL;
if (isInstalled) {
- if (!envVSCommonToolsDir.empty()) {
- std::string currentVSLocation(instanceInfo.VSInstallLocation.begin(),
- instanceInfo.VSInstallLocation.end());
- cmSystemTools::ConvertToUnixSlashes(currentVSLocation);
- currentVSLocation += "/Common7/Tools";
+ // We are looking for a specific major version.
+ if (instanceInfo.Version.size() < wantVersion.size() ||
+ instanceInfo.Version.substr(0, wantVersion.size()) != wantVersion) {
+ continue;
+ }
+
+ if (!this->SpecifiedVSInstallLocation.empty()) {
+ // We are looking for a specific instance.
+ std::string currentVSLocation = instanceInfo.GetInstallLocation();
if (cmSystemTools::ComparePath(currentVSLocation,
- envVSCommonToolsDir)) {
+ this->SpecifiedVSInstallLocation)) {
chosenInstanceInfo = instanceInfo;
return true;
}
+ } else {
+ // We are not looking for a specific instance.
+ // If we've been given a hint then use it.
+ if (!envVSCommonToolsDir.empty()) {
+ std::string currentVSLocation = instanceInfo.GetInstallLocation();
+ currentVSLocation += "/Common7/Tools";
+ if (cmSystemTools::ComparePath(currentVSLocation,
+ envVSCommonToolsDir)) {
+ chosenInstanceInfo = instanceInfo;
+ return true;
+ }
+ }
+ // Otherwise, add this to the list of candidates.
+ vecVSInstances.push_back(instanceInfo);
}
- vecVSInstances.push_back(instanceInfo);
}
}
diff --git a/Source/cmVSSetupHelper.h b/Source/cmVSSetupHelper.h
index d2f514c63..1bda54a47 100644
--- a/Source/cmVSSetupHelper.h
+++ b/Source/cmVSSetupHelper.h
@@ -4,7 +4,7 @@
#define cmVSSetupHelper_h
#ifndef NOMINMAX
-#define NOMINMAX // Undefine min and max defined by windows.h
+# define NOMINMAX // Undefine min and max defined by windows.h
#endif
// Published by Visual Studio Setup team
@@ -97,6 +97,7 @@ public:
operator BSTR() const { return str; }
BSTR* operator&() throw() { return &str; }
~SmartBSTR() throw() { ::SysFreeString(str); }
+
private:
BSTR str;
};
@@ -106,26 +107,25 @@ struct VSInstanceInfo
std::wstring InstanceId;
std::wstring VSInstallLocation;
std::wstring Version;
- ULONGLONG ullVersion;
- bool IsWin10SDKInstalled;
- bool IsWin81SDKInstalled;
+ std::string VCToolsetVersion;
+ ULONGLONG ullVersion = 0;
+ bool IsWin10SDKInstalled = false;
+ bool IsWin81SDKInstalled = false;
- VSInstanceInfo()
- {
- InstanceId = VSInstallLocation = Version = L"";
- ullVersion = 0;
- IsWin10SDKInstalled = IsWin81SDKInstalled = false;
- }
+ std::string GetInstallLocation() const;
};
class cmVSSetupAPIHelper
{
public:
- cmVSSetupAPIHelper();
+ cmVSSetupAPIHelper(unsigned int version);
~cmVSSetupAPIHelper();
- bool IsVS2017Installed();
+ bool SetVSInstance(std::string const& vsInstallLocation);
+
+ bool IsVSInstalled();
bool GetVSInstanceInfo(std::string& vsInstallLocation);
+ bool GetVCToolsetVersion(std::string& vsToolsetVersion);
bool IsWin10SDKInstalled();
bool IsWin81SDKInstalled();
@@ -134,11 +134,12 @@ private:
bool GetVSInstanceInfo(SmartCOMPtr<ISetupInstance2> instance2,
VSInstanceInfo& vsInstanceInfo);
bool CheckInstalledComponent(SmartCOMPtr<ISetupPackageReference> package,
- bool& bVCToolset, bool& bWin10SDK,
- bool& bWin81SDK);
+ bool& bWin10SDK, bool& bWin81SDK);
int ChooseVSInstance(const std::vector<VSInstanceInfo>& vecVSInstances);
bool EnumerateAndChooseVSInstance();
+ unsigned int Version;
+
// COM ptrs to query about VS instances
SmartCOMPtr<ISetupConfiguration> setupConfig;
SmartCOMPtr<ISetupConfiguration2> setupConfig2;
@@ -149,6 +150,9 @@ private:
HRESULT comInitialized;
// current best instance of VS selected
VSInstanceInfo chosenInstanceInfo;
+ bool IsEWDKEnabled();
+
+ std::string SpecifiedVSInstallLocation;
};
#endif
diff --git a/Source/cmVariableRequiresCommand.cxx b/Source/cmVariableRequiresCommand.cxx
index 06ca53c0a..c02157ad1 100644
--- a/Source/cmVariableRequiresCommand.cxx
+++ b/Source/cmVariableRequiresCommand.cxx
@@ -57,7 +57,7 @@ bool cmVariableRequiresCommand::InitialPass(
"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());
+ cmSystemTools::Error(message);
}
return true;
diff --git a/Source/cmVariableRequiresCommand.h b/Source/cmVariableRequiresCommand.h
index 9808d5f0c..94970c584 100644
--- a/Source/cmVariableRequiresCommand.h
+++ b/Source/cmVariableRequiresCommand.h
@@ -3,7 +3,7 @@
#ifndef cmVariableRequiresCommand_h
#define cmVariableRequiresCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -15,9 +15,9 @@ class cmExecutionStatus;
class cmVariableRequiresCommand : public cmCommand
{
public:
- cmCommand* Clone() CM_OVERRIDE { return new cmVariableRequiresCommand; }
+ cmCommand* Clone() override { return new cmVariableRequiresCommand; }
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx
index 419e1a411..3df142099 100644
--- a/Source/cmVariableWatch.cxx
+++ b/Source/cmVariableWatch.cxx
@@ -2,11 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmVariableWatch.h"
-#include "cmAlgorithms.h"
-
-#include "cm_auto_ptr.hxx"
-#include <algorithm>
+#include <memory>
#include <utility>
+#include <vector>
static const char* const cmVariableWatchAccessStrings[] = {
"READ_ACCESS", "UNKNOWN_READ_ACCESS", "UNKNOWN_DEFINED_ACCESS",
@@ -21,41 +19,27 @@ const char* cmVariableWatch::GetAccessAsString(int access_type)
return cmVariableWatchAccessStrings[access_type];
}
-cmVariableWatch::cmVariableWatch()
-{
-}
+cmVariableWatch::cmVariableWatch() = default;
-template <typename C>
-void deleteAllSecond(typename C::value_type it)
-{
- cmDeleteAll(it.second);
-}
-
-cmVariableWatch::~cmVariableWatch()
-{
- std::for_each(this->WatchMap.begin(), this->WatchMap.end(),
- deleteAllSecond<cmVariableWatch::StringToVectorOfPairs>);
-}
+cmVariableWatch::~cmVariableWatch() = default;
bool cmVariableWatch::AddWatch(const std::string& variable, WatchMethod method,
void* client_data /*=0*/,
DeleteData delete_data /*=0*/)
{
- CM_AUTO_PTR<cmVariableWatch::Pair> p(new cmVariableWatch::Pair);
+ auto p = std::make_shared<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];
+ cmVariableWatch::VectorOfPairs& vp = this->WatchMap[variable];
+ for (auto& pair : vp) {
if (pair->Method == method && client_data &&
client_data == pair->ClientData) {
// Callback already exists
return false;
}
}
- vp->push_back(p.release());
+ vp.push_back(std::move(p));
return true;
}
@@ -72,7 +56,6 @@ void cmVariableWatch::RemoveWatch(const std::string& variable,
// 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;
}
@@ -86,10 +69,17 @@ bool cmVariableWatch::VariableAccessed(const std::string& variable,
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);
+ // The strategy here is to copy the list of callbacks, and ignore
+ // new callbacks that existing ones may add.
+ std::vector<std::weak_ptr<Pair>> vp(mit->second.begin(),
+ mit->second.end());
+ for (auto& weak_it : vp) {
+ // In the case where a callback was removed, the weak_ptr will not be
+ // lockable, and so this ensures we don't attempt to call into freed
+ // memory
+ if (auto it = weak_it.lock()) {
+ it->Method(variable, access_type, it->ClientData, newValue, mf);
+ }
}
return true;
}
diff --git a/Source/cmVariableWatch.h b/Source/cmVariableWatch.h
index a575afe9d..123010179 100644
--- a/Source/cmVariableWatch.h
+++ b/Source/cmVariableWatch.h
@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
+#include <memory> // IWYU pragma: keep
#include <string>
#include <vector>
@@ -31,10 +32,9 @@ public:
* Add watch to the variable
*/
bool AddWatch(const std::string& variable, WatchMethod method,
- void* client_data = CM_NULLPTR,
- DeleteData delete_data = CM_NULLPTR);
+ void* client_data = nullptr, DeleteData delete_data = nullptr);
void RemoveWatch(const std::string& variable, WatchMethod method,
- void* client_data = CM_NULLPTR);
+ void* client_data = nullptr);
/**
* This method is called when variable is accessed
@@ -63,24 +63,21 @@ public:
protected:
struct Pair
{
- WatchMethod Method;
- void* ClientData;
- DeleteData DeleteDataCall;
- Pair()
- : Method(CM_NULLPTR)
- , ClientData(CM_NULLPTR)
- , DeleteDataCall(CM_NULLPTR)
- {
- }
+ WatchMethod Method = nullptr;
+ void* ClientData = nullptr;
+ DeleteData DeleteDataCall = nullptr;
~Pair()
{
if (this->DeleteDataCall && this->ClientData) {
this->DeleteDataCall(this->ClientData);
}
}
+ Pair() = default;
+ Pair(const Pair&) = delete;
+ Pair& operator=(const Pair&) = delete;
};
- typedef std::vector<Pair*> VectorOfPairs;
+ typedef std::vector<std::shared_ptr<Pair>> VectorOfPairs;
typedef std::map<std::string, VectorOfPairs> StringToVectorOfPairs;
StringToVectorOfPairs WatchMap;
diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx
index 281850ecc..5fe55bd53 100644
--- a/Source/cmVariableWatchCommand.cxx
+++ b/Source/cmVariableWatchCommand.cxx
@@ -7,6 +7,7 @@
#include "cmExecutionStatus.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmVariableWatch.h"
#include "cmake.h"
@@ -43,16 +44,14 @@ static void cmVariableWatchCommandVariableAccessed(const std::string& variable,
std::string stack = makefile->GetProperty("LISTFILE_STACK");
if (!data->Command.empty()) {
newLFF.Arguments.clear();
- newLFF.Arguments.push_back(
- cmListFileArgument(variable, cmListFileArgument::Quoted, 9999));
- newLFF.Arguments.push_back(
- cmListFileArgument(accessString, cmListFileArgument::Quoted, 9999));
- newLFF.Arguments.push_back(cmListFileArgument(
- newValue ? newValue : "", cmListFileArgument::Quoted, 9999));
- newLFF.Arguments.push_back(
- cmListFileArgument(currentListFile, cmListFileArgument::Quoted, 9999));
- newLFF.Arguments.push_back(
- cmListFileArgument(stack, cmListFileArgument::Quoted, 9999));
+ newLFF.Arguments.emplace_back(variable, cmListFileArgument::Quoted, 9999);
+ newLFF.Arguments.emplace_back(accessString, cmListFileArgument::Quoted,
+ 9999);
+ newLFF.Arguments.emplace_back(newValue ? newValue : "",
+ cmListFileArgument::Quoted, 9999);
+ newLFF.Arguments.emplace_back(currentListFile, cmListFileArgument::Quoted,
+ 9999);
+ newLFF.Arguments.emplace_back(stack, cmListFileArgument::Quoted, 9999);
newLFF.Name = data->Command;
newLFF.Line = 9999;
cmExecutionStatus status;
@@ -61,7 +60,7 @@ static void cmVariableWatchCommandVariableAccessed(const std::string& variable,
error << "Error in cmake code at\nUnknown:0:\n"
<< "A command failed during the invocation of callback \""
<< data->Command << "\".";
- cmSystemTools::Error(error.str().c_str());
+ cmSystemTools::Error(error.str());
data->InCallback = false;
return;
}
@@ -72,7 +71,7 @@ static void cmVariableWatchCommandVariableAccessed(const std::string& variable,
msg << "Variable \"" << variable << "\" was accessed using "
<< accessString << " with value \"" << (newValue ? newValue : "")
<< "\".";
- makefile->IssueMessage(cmake::LOG, msg.str());
+ makefile->IssueMessage(MessageType::LOG, msg.str());
}
data->InCallback = false;
@@ -85,17 +84,13 @@ static void deleteVariableWatchCallbackData(void* client_data)
delete data;
}
-cmVariableWatchCommand::cmVariableWatchCommand()
-{
-}
+cmVariableWatchCommand::cmVariableWatchCommand() = default;
cmVariableWatchCommand::~cmVariableWatchCommand()
{
- std::set<std::string>::const_iterator it;
- for (it = this->WatchedVariables.begin(); it != this->WatchedVariables.end();
- ++it) {
+ for (std::string const& wv : this->WatchedVariables) {
this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch(
- *it, cmVariableWatchCommandVariableAccessed);
+ wv, cmVariableWatchCommandVariableAccessed);
}
}
diff --git a/Source/cmVariableWatchCommand.h b/Source/cmVariableWatchCommand.h
index 9f0439175..6a8115d74 100644
--- a/Source/cmVariableWatchCommand.h
+++ b/Source/cmVariableWatchCommand.h
@@ -3,7 +3,7 @@
#ifndef cmVariableWatchCommand_h
#define cmVariableWatchCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <string>
@@ -23,24 +23,24 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmVariableWatchCommand; }
+ cmCommand* Clone() override { return new cmVariableWatchCommand; }
//! Default constructor
cmVariableWatchCommand();
//! Destructor.
- ~cmVariableWatchCommand() CM_OVERRIDE;
+ ~cmVariableWatchCommand() override;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
/** This command does not really have a final pass but it needs to
stay alive since it owns variable watch callback information. */
- bool HasFinalPass() const CM_OVERRIDE { return true; }
+ bool HasFinalPass() const override { return true; }
protected:
std::set<std::string> WatchedVariables;
diff --git a/Source/cmVersionMacros.h b/Source/cmVersionMacros.h
index 1b617bd2b..e8ac4f862 100644
--- a/Source/cmVersionMacros.h
+++ b/Source/cmVersionMacros.h
@@ -7,7 +7,7 @@
#define CMake_VERSION_PATCH_IS_RELEASE(patch) ((patch) < 20000000)
#if CMake_VERSION_PATCH_IS_RELEASE(CMake_VERSION_PATCH)
-#define CMake_VERSION_IS_RELEASE 1
+# define CMake_VERSION_IS_RELEASE 1
#endif
#endif
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index dee153f6b..7a901763e 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -4,18 +4,25 @@
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
+#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmGeneratedFileStream.h"
+#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalVisualStudio10Generator.h"
-#include "cmLocalVisualStudio7Generator.h"
+#include "cmLinkLineDeviceComputer.h"
+#include "cmLocalVisualStudio10Generator.h"
#include "cmMakefile.h"
#include "cmSourceFile.h"
#include "cmSystemTools.h"
#include "cmVisualStudioGeneratorOptions.h"
#include "windows.h"
-#include "cm_auto_ptr.hxx"
+#include <iterator>
+#include <memory> // IWYU pragma: keep
+#include <set>
+
+static void ConvertToWindowsSlash(std::string& s);
static std::string cmVS10EscapeXML(std::string arg)
{
@@ -25,14 +32,157 @@ static std::string cmVS10EscapeXML(std::string arg)
return arg;
}
+static std::string cmVS10EscapeAttr(std::string arg)
+{
+ cmSystemTools::ReplaceString(arg, "&", "&amp;");
+ cmSystemTools::ReplaceString(arg, "<", "&lt;");
+ cmSystemTools::ReplaceString(arg, ">", "&gt;");
+ cmSystemTools::ReplaceString(arg, "\"", "&quot;");
+ cmSystemTools::ReplaceString(arg, "\n", "&#10;");
+ return arg;
+}
+
+struct cmVisualStudio10TargetGenerator::Elem
+{
+ std::ostream& S;
+ const int Indent;
+ bool HasElements = false;
+ bool HasContent = false;
+ std::string Tag;
+
+ Elem(std::ostream& s, const char* tag)
+ : S(s)
+ , Indent(0)
+ , Tag(tag)
+ {
+ this->StartElement();
+ }
+ Elem(const Elem&) = delete;
+ Elem(Elem& par, const char* tag)
+ : S(par.S)
+ , Indent(par.Indent + 1)
+ , Tag(tag)
+ {
+ par.SetHasElements();
+ this->StartElement();
+ }
+ void SetHasElements()
+ {
+ if (!HasElements) {
+ this->S << ">\n";
+ HasElements = true;
+ }
+ }
+ std::ostream& WriteString(const char* line);
+ void StartElement() { this->WriteString("<") << this->Tag; }
+ void Element(const char* tag, const std::string& val)
+ {
+ Elem(*this, tag).Content(val);
+ }
+ Elem& Attribute(const char* an, const std::string& av)
+ {
+ this->S << " " << an << "=\"" << cmVS10EscapeAttr(av) << "\"";
+ return *this;
+ }
+ void Content(const std::string& val)
+ {
+ if (!this->HasContent) {
+ this->S << ">";
+ this->HasContent = true;
+ }
+ this->S << cmVS10EscapeXML(val);
+ }
+ ~Elem()
+ {
+ // Do not emit element which has not been started
+ if (Tag.empty()) {
+ return;
+ }
+
+ if (HasElements) {
+ this->WriteString("</") << this->Tag << ">";
+ if (this->Indent > 0) {
+ this->S << '\n';
+ } else {
+ // special case: don't print EOL at EOF
+ }
+ } else if (HasContent) {
+ this->S << "</" << this->Tag << ">\n";
+ } else {
+ this->S << " />\n";
+ }
+ }
+
+ void WritePlatformConfigTag(const char* tag, const std::string& cond,
+ const std::string& content);
+};
+
+class cmVS10GeneratorOptions : public cmVisualStudioGeneratorOptions
+{
+public:
+ typedef cmVisualStudio10TargetGenerator::Elem Elem;
+ cmVS10GeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool,
+ cmVS7FlagTable const* table,
+ cmVisualStudio10TargetGenerator* g = nullptr)
+ : cmVisualStudioGeneratorOptions(lg, tool, table)
+ , TargetGenerator(g)
+ {
+ }
+
+ void OutputFlag(std::ostream& /*fout*/, int /*indent*/, const char* tag,
+ const std::string& content) override
+ {
+ if (!this->GetConfiguration().empty()) {
+ // if there are configuration specific flags, then
+ // use the configuration specific tag for PreprocessorDefinitions
+ const std::string cond =
+ this->TargetGenerator->CalcCondition(this->GetConfiguration());
+ this->Parent->WritePlatformConfigTag(tag, cond, content);
+ } else {
+ this->Parent->Element(tag, content);
+ }
+ }
+
+private:
+ cmVisualStudio10TargetGenerator* const TargetGenerator;
+ Elem* Parent = nullptr;
+ friend cmVisualStudio10TargetGenerator::OptionsHelper;
+};
+
+struct cmVisualStudio10TargetGenerator::OptionsHelper
+{
+ cmVS10GeneratorOptions& O;
+ OptionsHelper(cmVS10GeneratorOptions& o, Elem& e)
+ : O(o)
+ {
+ O.Parent = &e;
+ }
+ ~OptionsHelper() { O.Parent = nullptr; }
+
+ void OutputPreprocessorDefinitions(const std::string& lang)
+ {
+ O.OutputPreprocessorDefinitions(O.Parent->S, O.Parent->Indent + 1, lang);
+ }
+ void OutputAdditionalIncludeDirectories(const std::string& lang)
+ {
+ O.OutputAdditionalIncludeDirectories(O.Parent->S, O.Parent->Indent + 1,
+ lang);
+ }
+ void OutputFlagMap() { O.OutputFlagMap(O.Parent->S, O.Parent->Indent + 1); }
+ void PrependInheritedString(std::string const& key)
+ {
+ O.PrependInheritedString(key);
+ }
+};
+
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) {
+ for (char c : comment) {
+ switch (c) {
case '\r':
break;
case '\n':
@@ -45,8 +195,9 @@ static std::string cmVS10EscapeComment(std::string comment)
case '>': /* no break */
case '^':
echoable += '^'; /* no break */
+ CM_FALLTHROUGH;
default:
- echoable += *c;
+ echoable += c;
break;
}
}
@@ -63,7 +214,7 @@ static std::string computeProjectFileExtension(cmGeneratorTarget const* t)
{
std::string res;
res = ".vcxproj";
- if (cmGlobalVisualStudioGenerator::TargetIsCSharpOnly(t)) {
+ if (t->IsCSharpOnly()) {
res = ".csproj";
}
return res;
@@ -71,16 +222,16 @@ static std::string computeProjectFileExtension(cmGeneratorTarget const* t)
cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
cmGeneratorTarget* target, cmGlobalVisualStudio10Generator* gg)
+ : GeneratorTarget(target)
+ , Makefile(target->Target->GetMakefile())
+ , Platform(gg->GetPlatformName())
+ , Name(target->GetName())
+ , GUID(gg->GetGUID(this->Name))
+ , GlobalGenerator(gg)
+ , LocalGenerator(
+ (cmLocalVisualStudio10Generator*)target->GetLocalGenerator())
{
- this->GlobalGenerator = gg;
- this->GeneratorTarget = target;
- this->Makefile = target->Target->GetMakefile();
this->Makefile->GetConfigurations(this->Configurations);
- this->LocalGenerator =
- (cmLocalVisualStudio7Generator*)this->GeneratorTarget->GetLocalGenerator();
- this->Name = this->GeneratorTarget->GetName();
- this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
- this->Platform = gg->GetPlatformName();
this->NsightTegra = gg->IsNsightTegra();
for (int i = 0; i < 4; ++i) {
this->NsightTegraVersion[i] = 0;
@@ -91,84 +242,50 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator(
this->MSTools = !this->NsightTegra;
this->Managed = false;
this->TargetCompileAsWinRT = false;
- this->BuildFileStream = 0;
this->IsMissingFiles = false;
this->DefaultArtifactDir =
- this->LocalGenerator->GetCurrentBinaryDirectory() + std::string("/") +
+ this->LocalGenerator->GetCurrentBinaryDirectory() + "/" +
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
- this->InSourceBuild =
- (strcmp(this->Makefile->GetCurrentSourceDirectory(),
- this->Makefile->GetCurrentBinaryDirectory()) == 0);
+ this->InSourceBuild = (this->Makefile->GetCurrentSourceDirectory() ==
+ this->Makefile->GetCurrentBinaryDirectory());
}
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;
- }
- for (OptionsMap::iterator i = this->CudaOptions.begin();
- i != this->CudaOptions.end(); ++i) {
- delete i->second;
- }
- for (OptionsMap::iterator i = this->CudaLinkOptions.begin();
- i != this->CudaLinkOptions.end(); ++i) {
- delete i->second;
- }
- if (!this->BuildFileStream) {
- return;
- }
- if (this->BuildFileStream->Close()) {
- this->GlobalGenerator->FileReplacedDuringGenerate(this->PathToProjectFile);
- }
- delete this->BuildFileStream;
}
-void cmVisualStudio10TargetGenerator::WritePlatformConfigTag(
- const char* tag, const std::string& config, int indentLevel,
- const char* attribute, const char* end, std::ostream* stream)
-
+std::string cmVisualStudio10TargetGenerator::CalcCondition(
+ const std::string& config) const
{
- if (!stream) {
- stream = this->BuildFileStream;
- }
- stream->fill(' ');
- stream->width(indentLevel * 2);
- (*stream) << ""; // applies indentation
- (*stream) << "<" << tag << " Condition=\"";
- (*stream) << "'$(Configuration)|$(Platform)'=='";
- (*stream) << config << "|" << this->Platform;
- (*stream) << "'";
+ std::ostringstream oss;
+ oss << "'$(Configuration)|$(Platform)'=='";
+ oss << config << "|" << this->Platform;
+ oss << "'";
// handle special case for 32 bit C# targets
- if (csproj == this->ProjectType && this->Platform == "Win32") {
- (*stream) << " Or ";
- (*stream) << "'$(Configuration)|$(Platform)'=='";
- (*stream) << config << "|x86";
- (*stream) << "'";
- }
- (*stream) << "\"";
- if (attribute) {
- (*stream) << attribute;
- }
- // close the tag
- (*stream) << ">";
- if (end) {
- (*stream) << end;
+ if (this->ProjectType == csproj && this->Platform == "Win32") {
+ oss << " Or ";
+ oss << "'$(Configuration)|$(Platform)'=='";
+ oss << config << "|x86";
+ oss << "'";
}
+ return oss.str();
}
-void cmVisualStudio10TargetGenerator::WriteString(const char* line,
- int indentLevel)
+void cmVisualStudio10TargetGenerator::Elem::WritePlatformConfigTag(
+ const char* tag, const std::string& cond, const std::string& content)
{
- this->BuildFileStream->fill(' ');
- this->BuildFileStream->width(indentLevel * 2);
+ Elem(*this, tag).Attribute("Condition", cond).Content(content);
+}
+
+std::ostream& cmVisualStudio10TargetGenerator::Elem::WriteString(
+ const char* line)
+{
+ this->S.fill(' ');
+ this->S.width(this->Indent * 2);
// write an empty string to get the fill level indent to print
- (*this->BuildFileStream) << "";
- (*this->BuildFileStream) << line;
+ this->S << "";
+ this->S << line;
+ return this->S;
}
#define VS10_CXX_DEFAULT_PROPS "$(VCTargetsPath)\\Microsoft.Cpp.Default.props"
@@ -185,6 +302,11 @@ void cmVisualStudio10TargetGenerator::WriteString(const char* line,
"$(UserRootDir)\\Microsoft.CSharp.$(Platform).user.props"
#define VS10_CSharp_TARGETS "$(MSBuildToolsPath)\\Microsoft.CSharp.targets"
+#define VS10_CSharp_NETCF_TARGETS \
+ "$(MSBuildExtensionsPath)\\Microsoft\\$(TargetFrameworkIdentifier)\\" \
+ "$(TargetFrameworkTargetsVersion)\\Microsoft.$(TargetFrameworkIdentifier)" \
+ ".CSharp.targets"
+
void cmVisualStudio10TargetGenerator::Generate()
{
// do not generate external ms projects
@@ -192,20 +314,29 @@ void cmVisualStudio10TargetGenerator::Generate()
this->GeneratorTarget->GetProperty("EXTERNAL_MSPROJECT")) {
return;
}
- this->ProjectFileExtension =
+ const std::string ProjectFileExtension =
computeProjectFileExtension(this->GeneratorTarget);
- if (this->ProjectFileExtension == ".vcxproj") {
+ if (ProjectFileExtension == ".vcxproj") {
this->ProjectType = vcxproj;
this->Managed = false;
- } else if (this->ProjectFileExtension == ".csproj") {
+ } else if (ProjectFileExtension == ".csproj") {
+ if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
+ std::string message = "The C# target \"" +
+ this->GeneratorTarget->GetName() +
+ "\" is of type STATIC_LIBRARY. This is discouraged (and may be "
+ "disabled in future). Make it a SHARED library instead.";
+ this->Makefile->IssueMessage(MessageType::DEPRECATION_WARNING, message);
+ }
this->ProjectType = csproj;
this->Managed = true;
}
// Tell the global generator the name of the project file
this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME",
this->Name.c_str());
- this->GeneratorTarget->Target->SetProperty(
- "GENERATOR_FILE_NAME_EXT", this->ProjectFileExtension.c_str());
+ this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
+ ProjectFileExtension.c_str());
+ this->DotNetHintReferences.clear();
+ this->AdditionalUsingDirectories.clear();
if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
if (!this->ComputeClOptions()) {
return;
@@ -235,415 +366,468 @@ void cmVisualStudio10TargetGenerator::Generate()
std::string path = this->LocalGenerator->GetCurrentBinaryDirectory();
path += "/";
path += this->Name;
- path += this->ProjectFileExtension;
- this->BuildFileStream = new cmGeneratedFileStream(path.c_str());
- this->PathToProjectFile = path;
- this->BuildFileStream->SetCopyIfDifferent(true);
+ path += ProjectFileExtension;
+ cmGeneratedFileStream BuildFileStream(path);
+ const std::string PathToProjectFile = path;
+ BuildFileStream.SetCopyIfDifferent(true);
// Write the encoding header into the file
char magic[] = { char(0xEF), char(0xBB), char(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);
- const int nsightTegraMajorVersion = this->NsightTegraVersion[0];
- const int nsightTegraMinorVersion = this->NsightTegraVersion[1];
- if (nsightTegraMajorVersion >= 2) {
- this->WriteString("<NsightTegraProjectRevisionNumber>", 2);
- if (nsightTegraMajorVersion > 3 ||
- (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1)) {
- (*this->BuildFileStream) << "11";
+ BuildFileStream.write(magic, 3);
+ BuildFileStream << "<?xml version=\"1.0\" encoding=\""
+ << this->GlobalGenerator->Encoding() << "\"?>"
+ << "\n";
+ {
+ Elem e0(BuildFileStream, "Project");
+ e0.Attribute("DefaultTargets", "Build");
+ const char* toolsVersion = this->GlobalGenerator->GetToolsVersion();
+ if (this->GlobalGenerator->GetVersion() ==
+ cmGlobalVisualStudioGenerator::VS12 &&
+ this->GlobalGenerator->TargetsWindowsCE()) {
+ toolsVersion = "4.0";
+ }
+ e0.Attribute("ToolsVersion", toolsVersion);
+ e0.Attribute("xmlns",
+ "http://schemas.microsoft.com/developer/msbuild/2003");
+
+ if (this->NsightTegra) {
+ Elem e1(e0, "PropertyGroup");
+ e1.Attribute("Label", "NsightTegraProject");
+ const unsigned int nsightTegraMajorVersion = this->NsightTegraVersion[0];
+ const unsigned int nsightTegraMinorVersion = this->NsightTegraVersion[1];
+ if (nsightTegraMajorVersion >= 2) {
+ if (nsightTegraMajorVersion > 3 ||
+ (nsightTegraMajorVersion == 3 && nsightTegraMinorVersion >= 1)) {
+ e1.Element("NsightTegraProjectRevisionNumber", "11");
+ } else {
+ // Nsight Tegra 2.0 uses project revision 9.
+ e1.Element("NsightTegraProjectRevisionNumber", "9");
+ }
+ // Tell newer versions to upgrade silently when loading.
+ e1.Element("NsightTegraUpgradeOnceWithoutPrompt", "true");
} else {
- // Nsight Tegra 2.0 uses project revision 9.
- (*this->BuildFileStream) << "9";
+ // Require Nsight Tegra 1.6 for JCompile support.
+ e1.Element("NsightTegraProjectRevisionNumber", "7");
}
- (*this->BuildFileStream) << "</NsightTegraProjectRevisionNumber>\n";
- // 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);
- }
- if (const char* hostArch =
- this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) {
- this->WriteString("<PropertyGroup>\n", 1);
- this->WriteString("<PreferredToolArchitecture>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(hostArch)
- << "</PreferredToolArchitecture>\n";
- this->WriteString("</PropertyGroup>\n", 1);
- }
+ if (const char* hostArch =
+ this->GlobalGenerator->GetPlatformToolsetHostArchitecture()) {
+ Elem e1(e0, "PropertyGroup");
+ e1.Element("PreferredToolArchitecture", hostArch);
+ }
- if (csproj != this->ProjectType) {
- this->WriteProjectConfigurations();
- }
- this->WriteString("<PropertyGroup Label=\"Globals\">\n", 1);
- this->WriteString("<ProjectGuid>", 2);
- (*this->BuildFileStream) << "{" << this->GUID << "}</ProjectGuid>\n";
+ if (this->ProjectType != csproj) {
+ this->WriteProjectConfigurations(e0);
+ }
- if (this->MSTools &&
- this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) {
- this->WriteApplicationTypeSettings();
- this->VerifyNecessaryFiles();
- }
+ {
+ Elem e1(e0, "PropertyGroup");
+ e1.Attribute("Label", "Globals");
+ e1.Element("ProjectGuid", "{" + this->GUID + "}");
+
+ if (this->MSTools &&
+ this->GeneratorTarget->GetType() <= cmStateEnums::GLOBAL_TARGET) {
+ this->WriteApplicationTypeSettings(e1);
+ this->VerifyNecessaryFiles();
+ }
- const char* vsProjectTypes =
- this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
- if (vsProjectTypes) {
- std::string tagName = "ProjectTypes";
- if (csproj == this->ProjectType) {
- tagName = "ProjectTypeGuids";
- }
- this->WriteString("", 2);
- (*this->BuildFileStream) << "<" << tagName << ">"
- << cmVS10EscapeXML(vsProjectTypes) << "</"
- << tagName << ">\n";
- }
+ const char* vsProjectTypes =
+ this->GeneratorTarget->GetProperty("VS_GLOBAL_PROJECT_TYPES");
+ if (vsProjectTypes) {
+ const char* tagName = "ProjectTypes";
+ if (this->ProjectType == csproj) {
+ tagName = "ProjectTypeGuids";
+ }
+ e1.Element(tagName, vsProjectTypes);
+ }
- const char* vsProjectName =
- this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
- const char* vsLocalPath =
- this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH");
- const char* vsProvider =
- this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER");
+ const char* vsProjectName =
+ this->GeneratorTarget->GetProperty("VS_SCC_PROJECTNAME");
+ const char* vsLocalPath =
+ this->GeneratorTarget->GetProperty("VS_SCC_LOCALPATH");
+ const char* vsProvider =
+ this->GeneratorTarget->GetProperty("VS_SCC_PROVIDER");
+
+ if (vsProjectName && vsLocalPath && vsProvider) {
+ e1.Element("SccProjectName", vsProjectName);
+ e1.Element("SccLocalPath", vsLocalPath);
+ e1.Element("SccProvider", vsProvider);
+
+ const char* vsAuxPath =
+ this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH");
+ if (vsAuxPath) {
+ e1.Element("SccAuxPath", vsAuxPath);
+ }
+ }
- 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";
+ if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
+ e1.Element("WinMDAssembly", "true");
+ }
- const char* vsAuxPath =
- this->GeneratorTarget->GetProperty("VS_SCC_AUXPATH");
- if (vsAuxPath) {
- this->WriteString("<SccAuxPath>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(vsAuxPath)
- << "</SccAuxPath>\n";
- }
- }
+ const char* vsGlobalKeyword =
+ this->GeneratorTarget->GetProperty("VS_GLOBAL_KEYWORD");
+ if (!vsGlobalKeyword) {
+ e1.Element("Keyword", "Win32Proj");
+ } else {
+ e1.Element("Keyword", vsGlobalKeyword);
+ }
- if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
- this->WriteString("<WinMDAssembly>true</WinMDAssembly>\n", 2);
- }
+ const char* vsGlobalRootNamespace =
+ this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE");
+ if (vsGlobalRootNamespace) {
+ e1.Element("RootNamespace", vsGlobalRootNamespace);
+ }
- const char* vsGlobalKeyword =
- this->GeneratorTarget->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->GeneratorTarget->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->GeneratorTarget->GetProperty("PROJECT_LABEL");
- if (!projLabel) {
- projLabel = this->Name.c_str();
- }
- this->WriteString("<ProjectName>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(projLabel) << "</ProjectName>\n";
- if (const char* targetFrameworkVersion = this->GeneratorTarget->GetProperty(
- "VS_DOTNET_TARGET_FRAMEWORK_VERSION")) {
- this->WriteString("<TargetFrameworkVersion>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(targetFrameworkVersion)
- << "</TargetFrameworkVersion>\n";
- }
-
- // Disable the project upgrade prompt that is displayed the first time a
- // project using an older toolset version is opened in a newer version of
- // the IDE (respected by VS 2013 and above).
- if (this->GlobalGenerator->GetVersion() >=
- cmGlobalVisualStudioGenerator::VS12) {
- this->WriteString("<VCProjectUpgraderObjectName>NoUpgrade"
- "</VCProjectUpgraderObjectName>\n",
- 2);
- }
-
- std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
- for (std::vector<std::string>::const_iterator keyIt = keys.begin();
- keyIt != keys.end(); ++keyIt) {
- static const char* prefix = "VS_GLOBAL_";
- if (keyIt->find(prefix) != 0)
- continue;
- std::string globalKey = keyIt->substr(strlen(prefix));
- // Skip invalid or separately-handled properties.
- if (globalKey == "" || globalKey == "PROJECT_TYPES" ||
- globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
- continue;
+ e1.Element("Platform", this->Platform);
+ const char* projLabel =
+ this->GeneratorTarget->GetProperty("PROJECT_LABEL");
+ if (!projLabel) {
+ projLabel = this->Name.c_str();
+ }
+ e1.Element("ProjectName", projLabel);
+ {
+ // TODO: add deprecation warning for VS_* property?
+ const char* targetFrameworkVersion =
+ this->GeneratorTarget->GetProperty(
+ "VS_DOTNET_TARGET_FRAMEWORK_VERSION");
+ if (!targetFrameworkVersion) {
+ targetFrameworkVersion = this->GeneratorTarget->GetProperty(
+ "DOTNET_TARGET_FRAMEWORK_VERSION");
+ }
+ if (!targetFrameworkVersion && this->ProjectType == csproj &&
+ this->GlobalGenerator->TargetsWindowsCE() &&
+ this->GlobalGenerator->GetVersion() ==
+ cmGlobalVisualStudioGenerator::VS12) {
+ // VS12 .NETCF default to .NET framework 3.9
+ targetFrameworkVersion = "v3.9";
+ }
+ if (targetFrameworkVersion) {
+ e1.Element("TargetFrameworkVersion", targetFrameworkVersion);
+ }
+ if (this->ProjectType == csproj &&
+ this->GlobalGenerator->TargetsWindowsCE()) {
+ const char* targetFrameworkId = this->GeneratorTarget->GetProperty(
+ "VS_TARGET_FRAMEWORK_IDENTIFIER");
+ if (!targetFrameworkId) {
+ targetFrameworkId = "WindowsEmbeddedCompact";
+ }
+ e1.Element("TargetFrameworkIdentifier", targetFrameworkId);
+ const char* targetFrameworkVer = this->GeneratorTarget->GetProperty(
+ "VS_TARGET_FRAMEWORKS_TARGET_VERSION");
+ if (!targetFrameworkVer) {
+ targetFrameworkVer = "v8.0";
+ }
+ e1.Element("TargetFrameworkTargetsVersion", targetFrameworkVer);
+ }
+ }
+
+ // Disable the project upgrade prompt that is displayed the first time a
+ // project using an older toolset version is opened in a newer version of
+ // the IDE (respected by VS 2013 and above).
+ if (this->GlobalGenerator->GetVersion() >=
+ cmGlobalVisualStudioGenerator::VS12) {
+ e1.Element("VCProjectUpgraderObjectName", "NoUpgrade");
+ }
+
+ std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys();
+ for (std::string const& keyIt : keys) {
+ static const char* prefix = "VS_GLOBAL_";
+ if (keyIt.find(prefix) != 0)
+ continue;
+ std::string globalKey = keyIt.substr(strlen(prefix));
+ // Skip invalid or separately-handled properties.
+ if (globalKey.empty() || globalKey == "PROJECT_TYPES" ||
+ globalKey == "ROOTNAMESPACE" || globalKey == "KEYWORD") {
+ continue;
+ }
+ const char* value = this->GeneratorTarget->GetProperty(keyIt);
+ if (!value)
+ continue;
+ e1.Element(globalKey.c_str(), value);
+ }
+
+ if (this->Managed) {
+ std::string outputType;
+ switch (this->GeneratorTarget->GetType()) {
+ case cmStateEnums::OBJECT_LIBRARY:
+ case cmStateEnums::STATIC_LIBRARY:
+ case cmStateEnums::SHARED_LIBRARY:
+ outputType = "Library";
+ break;
+ case cmStateEnums::MODULE_LIBRARY:
+ outputType = "Module";
+ break;
+ case cmStateEnums::EXECUTABLE:
+ if (this->GeneratorTarget->Target->GetPropertyAsBool(
+ "WIN32_EXECUTABLE")) {
+ outputType = "WinExe";
+ } else {
+ outputType = "Exe";
+ }
+ break;
+ case cmStateEnums::UTILITY:
+ case cmStateEnums::GLOBAL_TARGET:
+ outputType = "Utility";
+ break;
+ case cmStateEnums::UNKNOWN_LIBRARY:
+ case cmStateEnums::INTERFACE_LIBRARY:
+ break;
+ }
+ e1.Element("OutputType", outputType);
+ e1.Element("AppDesignerFolder", "Properties");
+ }
}
- const char* value = this->GeneratorTarget->GetProperty(keyIt->c_str());
- if (!value)
- continue;
- this->WriteString("<", 2);
- (*this->BuildFileStream) << globalKey << ">" << cmVS10EscapeXML(value)
- << "</" << globalKey << ">\n";
- }
- if (this->Managed) {
- std::string outputType = "<OutputType>";
- switch (this->GeneratorTarget->GetType()) {
- case cmStateEnums::OBJECT_LIBRARY:
- case cmStateEnums::STATIC_LIBRARY:
- case cmStateEnums::SHARED_LIBRARY:
- outputType += "Library";
- break;
- case cmStateEnums::MODULE_LIBRARY:
- outputType += "Module";
- break;
- case cmStateEnums::EXECUTABLE:
- if (this->GeneratorTarget->Target->GetPropertyAsBool(
- "WIN32_EXECUTABLE")) {
- outputType += "WinExe";
- } else {
- outputType += "Exe";
+ switch (this->ProjectType) {
+ case vcxproj:
+ if (this->GlobalGenerator->GetPlatformToolsetVersion()) {
+ Elem(e0, "Import")
+ .Attribute("Project",
+ this->GlobalGenerator->GetAuxiliaryToolset());
}
+ Elem(e0, "Import").Attribute("Project", VS10_CXX_DEFAULT_PROPS);
break;
- case cmStateEnums::UTILITY:
- case cmStateEnums::GLOBAL_TARGET:
- outputType += "Utility";
- break;
- case cmStateEnums::UNKNOWN_LIBRARY:
- case cmStateEnums::INTERFACE_LIBRARY:
+ case csproj:
+ Elem(e0, "Import")
+ .Attribute("Project", VS10_CSharp_DEFAULT_PROPS)
+ .Attribute("Condition", "Exists('" VS10_CSharp_DEFAULT_PROPS "')");
break;
}
- outputType += "</OutputType>\n";
- this->WriteString(outputType.c_str(), 2);
- this->WriteString("<AppDesignerFolder>Properties</AppDesignerFolder>\n",
- 2);
- }
- this->WriteString("</PropertyGroup>\n", 1);
+ this->WriteProjectConfigurationValues(e0);
- switch (this->ProjectType) {
- case vcxproj:
- this->WriteString("<Import Project=\"" VS10_CXX_DEFAULT_PROPS "\" />\n",
- 1);
- break;
- case csproj:
- this->WriteString("<Import Project=\"" VS10_CSharp_DEFAULT_PROPS "\" "
- "Condition=\"Exists('" VS10_CSharp_DEFAULT_PROPS "')\""
- "/>\n",
- 1);
- break;
- }
+ if (this->ProjectType == vcxproj) {
+ Elem(e0, "Import").Attribute("Project", VS10_CXX_PROPS);
+ }
+ {
+ Elem e1(e0, "ImportGroup");
+ e1.Attribute("Label", "ExtensionSettings");
+ e1.SetHasElements();
+
+ if (this->GlobalGenerator->IsCudaEnabled()) {
+ Elem(e1, "Import")
+ .Attribute("Project",
+ "$(VCTargetsPath)\\BuildCustomizations\\CUDA " +
+ this->GlobalGenerator->GetPlatformToolsetCudaString() +
+ ".props");
+ }
+ if (this->GlobalGenerator->IsMasmEnabled()) {
+ Elem(e1, "Import")
+ .Attribute("Project",
+ "$(VCTargetsPath)\\BuildCustomizations\\masm.props");
+ }
+ if (this->GlobalGenerator->IsNasmEnabled()) {
+ // Always search in the standard modules location.
+ std::string propsTemplate =
+ GetCMakeFilePath("Templates/MSBuild/nasm.props.in");
+
+ std::string propsLocal;
+ propsLocal += this->DefaultArtifactDir;
+ propsLocal += "\\nasm.props";
+ ConvertToWindowsSlash(propsLocal);
+ this->Makefile->ConfigureFile(propsTemplate, propsLocal, false, true,
+ true);
+ Elem(e1, "Import").Attribute("Project", propsLocal);
+ }
+ }
+ {
+ Elem e1(e0, "ImportGroup");
+ e1.Attribute("Label", "PropertySheets");
+ std::string props;
+ switch (this->ProjectType) {
+ case vcxproj:
+ props = VS10_CXX_USER_PROPS;
+ break;
+ case csproj:
+ props = VS10_CSharp_USER_PROPS;
+ break;
+ }
+ if (const char* p =
+ this->GeneratorTarget->GetProperty("VS_USER_PROPS")) {
+ props = p;
+ }
+ if (!props.empty()) {
+ ConvertToWindowsSlash(props);
+ Elem(e1, "Import")
+ .Attribute("Project", props)
+ .Attribute("Condition", "exists('" + props + "')")
+ .Attribute("Label", "LocalAppDataPlatform");
+ }
- this->WriteProjectConfigurationValues();
-
- if (vcxproj == this->ProjectType) {
- this->WriteString("<Import Project=\"" VS10_CXX_PROPS "\" />\n", 1);
- }
- this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1);
- if (this->GlobalGenerator->IsCudaEnabled()) {
- this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
- "BuildCustomizations\\CUDA ",
- 2);
- (*this->BuildFileStream)
- << cmVS10EscapeXML(this->GlobalGenerator->GetPlatformToolsetCudaString())
- << ".props\" />\n";
- }
- if (this->GlobalGenerator->IsMasmEnabled()) {
- this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
- "BuildCustomizations\\masm.props\" />\n",
- 2);
- }
- if (this->GlobalGenerator->IsNasmEnabled()) {
- // Always search in the standard modules location.
- std::string propsTemplate =
- GetCMakeFilePath("Templates/MSBuild/nasm.props.in");
-
- std::string propsLocal;
- propsLocal += this->DefaultArtifactDir;
- propsLocal += "\\nasm.props";
- this->ConvertToWindowsSlash(propsLocal);
- this->Makefile->ConfigureFile(propsTemplate.c_str(), propsLocal.c_str(),
- false, true, true);
- std::string import = std::string("<Import Project=\"") +
- cmVS10EscapeXML(propsLocal) + "\" />\n";
- this->WriteString(import.c_str(), 2);
- }
- this->WriteString("</ImportGroup>\n", 1);
- this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1);
- {
- std::string props;
+ this->WritePlatformExtensions(e1);
+ }
+ Elem(e0, "PropertyGroup").Attribute("Label", "UserMacros");
+ this->WriteWinRTPackageCertificateKeyFile(e0);
+ this->WritePathAndIncrementalLinkOptions(e0);
+ this->WriteCEDebugProjectConfigurationValues(e0);
+ this->WriteItemDefinitionGroups(e0);
+ this->WriteCustomCommands(e0);
+ this->WriteAllSources(e0);
+ this->WriteDotNetReferences(e0);
+ this->WritePackageReferences(e0);
+ this->WriteImports(e0);
+ this->WriteEmbeddedResourceGroup(e0);
+ this->WriteXamlFilesGroup(e0);
+ this->WriteWinRTReferences(e0);
+ this->WriteProjectReferences(e0);
+ this->WriteSDKReferences(e0);
switch (this->ProjectType) {
case vcxproj:
- props = VS10_CXX_USER_PROPS;
+ Elem(e0, "Import").Attribute("Project", VS10_CXX_TARGETS);
break;
case csproj:
- props = VS10_CSharp_USER_PROPS;
+ if (this->GlobalGenerator->TargetsWindowsCE()) {
+ Elem(e0, "Import").Attribute("Project", VS10_CSharp_NETCF_TARGETS);
+ } else {
+ Elem(e0, "Import").Attribute("Project", VS10_CSharp_TARGETS);
+ }
break;
}
- if (const char* p = this->GeneratorTarget->GetProperty("VS_USER_PROPS")) {
- props = p;
- }
- if (!props.empty()) {
- this->ConvertToWindowsSlash(props);
- this->WriteString("", 2);
- (*this->BuildFileStream)
- << "<Import Project=\"" << cmVS10EscapeXML(props) << "\""
- << " Condition=\"exists('" << cmVS10EscapeXML(props) << "')\""
- << " Label=\"LocalAppDataPlatform\" />\n";
- }
- }
- this->WritePlatformExtensions();
- 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->WriteXamlFilesGroup();
- this->WriteWinRTReferences();
- this->WriteProjectReferences();
- this->WriteSDKReferences();
- switch (this->ProjectType) {
- case vcxproj:
- this->WriteString("<Import Project=\"" VS10_CXX_TARGETS "\" />\n", 1);
- break;
- case csproj:
- this->WriteString("<Import Project=\"" VS10_CSharp_TARGETS "\" />\n", 1);
- break;
+
+ this->WriteTargetSpecificReferences(e0);
+ {
+ Elem e1(e0, "ImportGroup");
+ e1.Attribute("Label", "ExtensionTargets");
+ e1.SetHasElements();
+ this->WriteTargetsFileReferences(e1);
+ if (this->GlobalGenerator->IsCudaEnabled()) {
+ Elem(e1, "Import")
+ .Attribute("Project",
+ "$(VCTargetsPath)\\BuildCustomizations\\CUDA " +
+ this->GlobalGenerator->GetPlatformToolsetCudaString() +
+ ".targets");
+ }
+ if (this->GlobalGenerator->IsMasmEnabled()) {
+ Elem(e1, "Import")
+ .Attribute("Project",
+ "$(VCTargetsPath)\\BuildCustomizations\\masm.targets");
+ }
+ if (this->GlobalGenerator->IsNasmEnabled()) {
+ std::string nasmTargets =
+ GetCMakeFilePath("Templates/MSBuild/nasm.targets");
+ Elem(e1, "Import").Attribute("Project", nasmTargets);
+ }
+ }
+ if (this->ProjectType == csproj) {
+ for (std::string const& c : this->Configurations) {
+ Elem e1(e0, "PropertyGroup");
+ e1.Attribute("Condition", "'$(Configuration)' == '" + c + "'");
+ e1.SetHasElements();
+ this->WriteEvents(e1, c);
+ }
+ // make sure custom commands are executed before build (if necessary)
+ {
+ Elem e1(e0, "PropertyGroup");
+ std::ostringstream oss;
+ oss << "\n";
+ for (std::string const& i : this->CSharpCustomCommandNames) {
+ oss << " " << i << ";\n";
+ }
+ oss << " "
+ << "$(BuildDependsOn)\n";
+ e1.Element("BuildDependsOn", oss.str());
+ }
+ }
+ }
+
+ if (BuildFileStream.Close()) {
+ this->GlobalGenerator->FileReplacedDuringGenerate(PathToProjectFile);
}
- this->WriteTargetSpecificReferences();
- this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1);
- this->WriteTargetsFileReferences();
- if (this->GlobalGenerator->IsCudaEnabled()) {
- this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
- "BuildCustomizations\\CUDA ",
- 2);
- (*this->BuildFileStream)
- << cmVS10EscapeXML(this->GlobalGenerator->GetPlatformToolsetCudaString())
- << ".targets\" />\n";
- }
- if (this->GlobalGenerator->IsMasmEnabled()) {
- this->WriteString("<Import Project=\"$(VCTargetsPath)\\"
- "BuildCustomizations\\masm.targets\" />\n",
- 2);
- }
- if (this->GlobalGenerator->IsNasmEnabled()) {
- std::string nasmTargets =
- GetCMakeFilePath("Templates/MSBuild/nasm.targets");
- std::string import = "<Import Project=\"";
- import += cmVS10EscapeXML(nasmTargets) + "\" />\n";
- this->WriteString(import.c_str(), 2);
- }
- this->WriteString("</ImportGroup>\n", 1);
- if (csproj == this->ProjectType) {
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- this->WriteString("<PropertyGroup Condition=\"'$(Configuration)' == '",
- 1);
- (*this->BuildFileStream) << *i << "'\">\n";
- this->WriteEvents(*i);
- this->WriteString("</PropertyGroup>\n", 1);
- }
- }
- this->WriteString("</Project>", 0);
// The groups are stored in a separate file for VS 10
this->WriteGroups();
}
-void cmVisualStudio10TargetGenerator::WriteDotNetReferences()
+void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
+{
+ std::vector<std::string> packageReferences;
+ if (const char* vsPackageReferences =
+ this->GeneratorTarget->GetProperty("VS_PACKAGE_REFERENCES")) {
+ cmSystemTools::ExpandListArgument(vsPackageReferences, packageReferences);
+ }
+ if (!packageReferences.empty()) {
+ Elem e1(e0, "ItemGroup");
+ for (std::string const& ri : packageReferences) {
+ size_t versionIndex = ri.find_last_of('_');
+ if (versionIndex != std::string::npos) {
+ WritePackageReference(e1, ri.substr(0, versionIndex),
+ ri.substr(versionIndex + 1));
+ }
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WritePackageReference(
+ Elem& e1, std::string const& ref, std::string const& version)
+{
+ Elem e2(e1, "PackageReference");
+ e2.Attribute("Include", ref);
+ e2.Attribute("Version", version);
+}
+
+void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0)
{
std::vector<std::string> references;
- typedef std::pair<std::string, std::string> HintReference;
- std::vector<HintReference> hintReferences;
if (const char* vsDotNetReferences =
this->GeneratorTarget->GetProperty("VS_DOTNET_REFERENCES")) {
cmSystemTools::ExpandListArgument(vsDotNetReferences, references);
}
cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
- for (cmPropertyMap::const_iterator i = props.begin(); i != props.end();
- ++i) {
- if (i->first.find("VS_DOTNET_REFERENCE_") == 0) {
- std::string name = i->first.substr(20);
- if (name != "") {
- std::string path = i->second.GetValue();
+ for (auto const& i : props) {
+ if (i.first.find("VS_DOTNET_REFERENCE_") == 0) {
+ std::string name = i.first.substr(20);
+ if (!name.empty()) {
+ std::string path = i.second.GetValue();
if (!cmsys::SystemTools::FileIsFullPath(path)) {
- path = std::string(this->GeneratorTarget->Target->GetMakefile()
- ->GetCurrentSourceDirectory()) +
- "/" + path;
+ path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
}
- this->ConvertToWindowsSlash(path);
- hintReferences.push_back(HintReference(name, path));
+ ConvertToWindowsSlash(path);
+ this->DotNetHintReferences[""].push_back(
+ DotNetHintReference(name, path));
}
}
}
- if (!references.empty() || !hintReferences.empty()) {
- this->WriteString("<ItemGroup>\n", 1);
- for (std::vector<std::string>::iterator ri = references.begin();
- ri != references.end(); ++ri) {
+ if (!references.empty() || !this->DotNetHintReferences.empty()) {
+ Elem e1(e0, "ItemGroup");
+ for (std::string const& ri : references) {
// if the entry from VS_DOTNET_REFERENCES is an existing file, generate
// a new hint-reference and name it from the filename
- if (cmsys::SystemTools::FileExists(*ri, true)) {
+ if (cmsys::SystemTools::FileExists(ri, true)) {
std::string name =
- cmsys::SystemTools::GetFilenameWithoutExtension(*ri);
- std::string path = *ri;
- this->ConvertToWindowsSlash(path);
- hintReferences.push_back(HintReference(name, path));
+ cmsys::SystemTools::GetFilenameWithoutLastExtension(ri);
+ std::string path = ri;
+ ConvertToWindowsSlash(path);
+ this->DotNetHintReferences[""].push_back(
+ DotNetHintReference(name, path));
} else {
- this->WriteDotNetReference(*ri, "");
+ this->WriteDotNetReference(e1, ri, "", "");
}
}
- for (std::vector<std::pair<std::string, std::string> >::const_iterator i =
- hintReferences.begin();
- i != hintReferences.end(); ++i) {
- this->WriteDotNetReference(i->first, i->second);
+ for (const auto& h : this->DotNetHintReferences) {
+ // DotNetHintReferences is also populated from AddLibraries().
+ // The configuration specific hint references are added there.
+ for (const auto& i : h.second) {
+ this->WriteDotNetReference(e1, i.first, i.second, h.first);
+ }
}
- this->WriteString("</ItemGroup>\n", 1);
}
}
void cmVisualStudio10TargetGenerator::WriteDotNetReference(
- std::string const& ref, std::string const& hint)
+ Elem& e1, std::string const& ref, std::string const& hint,
+ std::string const& config)
{
- this->WriteString("<Reference Include=\"", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(ref) << "\">\n";
- this->WriteString("<CopyLocalSatelliteAssemblies>true"
- "</CopyLocalSatelliteAssemblies>\n",
- 3);
- this->WriteString("<ReferenceOutputAssembly>true"
- "</ReferenceOutputAssembly>\n",
- 3);
+ Elem e2(e1, "Reference");
+ // If 'config' is not empty, the reference is only added for the given
+ // configuration. This is used when referencing imported managed assemblies.
+ // See also cmVisualStudio10TargetGenerator::AddLibraries().
+ if (!config.empty()) {
+ e2.Attribute("Condition", this->CalcCondition(config));
+ }
+ e2.Attribute("Include", ref);
+ e2.Element("CopyLocalSatelliteAssemblies", "true");
+ e2.Element("ReferenceOutputAssembly", "true");
if (!hint.empty()) {
const char* privateReference = "True";
if (const char* value = this->GeneratorTarget->GetProperty(
@@ -652,63 +836,97 @@ void cmVisualStudio10TargetGenerator::WriteDotNetReference(
privateReference = "False";
}
}
- this->WriteString("<Private>", 3);
- (*this->BuildFileStream) << privateReference << "</Private>\n";
- this->WriteString("<HintPath>", 3);
- (*this->BuildFileStream) << hint << "</HintPath>\n";
+ e2.Element("Private", privateReference);
+ e2.Element("HintPath", hint);
+ }
+ this->WriteDotNetReferenceCustomTags(e2, ref);
+}
+
+void cmVisualStudio10TargetGenerator::WriteImports(Elem& e0)
+{
+ const char* imports =
+ this->GeneratorTarget->Target->GetProperty("VS_PROJECT_IMPORT");
+ if (imports) {
+ std::vector<std::string> argsSplit;
+ cmSystemTools::ExpandListArgument(std::string(imports), argsSplit, false);
+ for (auto& path : argsSplit) {
+ if (!cmsys::SystemTools::FileIsFullPath(path)) {
+ path = this->Makefile->GetCurrentSourceDirectory() + "/" + path;
+ }
+ ConvertToWindowsSlash(path);
+ Elem e1(e0, "Import");
+ e1.Attribute("Project", path);
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteDotNetReferenceCustomTags(
+ Elem& e2, std::string const& ref)
+{
+
+ static const std::string refpropPrefix = "VS_DOTNET_REFERENCEPROP_";
+ static const std::string refpropInfix = "_TAG_";
+ const std::string refPropFullPrefix = refpropPrefix + ref + refpropInfix;
+ typedef std::map<std::string, std::string> CustomTags;
+ CustomTags tags;
+ cmPropertyMap const& props = this->GeneratorTarget->Target->GetProperties();
+ for (const auto& i : props) {
+ if (i.first.find(refPropFullPrefix) == 0) {
+ std::string refTag = i.first.substr(refPropFullPrefix.length());
+ std::string refVal = i.second.GetValue();
+ if (!refTag.empty() && !refVal.empty()) {
+ tags[refTag] = refVal;
+ }
+ }
+ }
+ for (auto const& tag : tags) {
+ e2.Element(tag.first.c_str(), tag.second);
}
- this->WriteString("</Reference>\n", 2);
}
-void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
+void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0)
{
std::vector<cmSourceFile const*> resxObjs;
this->GeneratorTarget->GetResxSources(resxObjs, "");
if (!resxObjs.empty()) {
- this->WriteString("<ItemGroup>\n", 1);
+ Elem e1(e0, "ItemGroup");
std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
- this->ConvertToWindowsSlash(srcDir);
- 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);
+ ConvertToWindowsSlash(srcDir);
+ for (cmSourceFile const* oi : resxObjs) {
+ std::string obj = oi->GetFullPath();
+ ConvertToWindowsSlash(obj);
bool useRelativePath = false;
- if (csproj == this->ProjectType && this->InSourceBuild) {
+ if (this->ProjectType == csproj && this->InSourceBuild) {
// If we do an in-source build and the resource file is in a
// subdirectory
// of the .csproj file, we have to use relative pathnames, otherwise
// visual studio does not show the file in the IDE. Sorry.
if (obj.find(srcDir) == 0) {
obj = this->ConvertPath(obj, true);
- this->ConvertToWindowsSlash(obj);
+ ConvertToWindowsSlash(obj);
useRelativePath = true;
}
}
- (*this->BuildFileStream) << obj << "\">\n";
+ Elem e2(e1, "EmbeddedResource");
+ e2.Attribute("Include", obj);
- if (csproj != this->ProjectType) {
- this->WriteString("<DependentUpon>", 3);
+ if (this->ProjectType != csproj) {
std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h";
- (*this->BuildFileStream) << hFileName << "</DependentUpon>\n";
+ e2.Element("DependentUpon", hFileName);
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- this->WritePlatformConfigTag("LogicalName", i->c_str(), 3);
+ for (std::string const& c : this->Configurations) {
+ std::string s;
if (this->GeneratorTarget->GetProperty("VS_GLOBAL_ROOTNAMESPACE") ||
// Handle variant of VS_GLOBAL_<variable> for RootNamespace.
this->GeneratorTarget->GetProperty("VS_GLOBAL_RootNamespace")) {
- (*this->BuildFileStream) << "$(RootNamespace).";
+ s = "$(RootNamespace).";
}
- (*this->BuildFileStream) << "%(Filename)";
- (*this->BuildFileStream) << ".resources";
- (*this->BuildFileStream) << "</LogicalName>\n";
+ s += "%(Filename).resources";
+ e2.WritePlatformConfigTag("LogicalName", this->CalcCondition(c), s);
}
} else {
std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
- this->ConvertToWindowsSlash(binDir);
+ ConvertToWindowsSlash(binDir);
// If the resource was NOT added using a relative path (which should
// be the default), we have to provide a link here
if (!useRelativePath) {
@@ -721,25 +939,21 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
link = cmsys::SystemTools::GetFilenameName(obj);
}
if (!link.empty()) {
- this->WriteString("<Link>", 3);
- (*this->BuildFileStream) << link << "</Link>\n";
+ e2.Element("Link", link);
}
}
// Determine if this is a generated resource from a .Designer.cs file
std::string designerResource =
- cmSystemTools::GetFilenamePath((*oi)->GetFullPath()) + "/" +
- cmSystemTools::GetFilenameWithoutLastExtension(
- (*oi)->GetFullPath()) +
+ cmSystemTools::GetFilenamePath(oi->GetFullPath()) + "/" +
+ cmSystemTools::GetFilenameWithoutLastExtension(oi->GetFullPath()) +
".Designer.cs";
if (cmsys::SystemTools::FileExists(designerResource)) {
std::string generator = "PublicResXFileCodeGenerator";
- if (const char* g = (*oi)->GetProperty("VS_RESOURCE_GENERATOR")) {
+ if (const char* g = oi->GetProperty("VS_RESOURCE_GENERATOR")) {
generator = g;
}
if (!generator.empty()) {
- this->WriteString("<Generator>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(generator)
- << "</Generator>\n";
+ e2.Element("Generator", generator);
if (designerResource.find(srcDir) == 0) {
designerResource = designerResource.substr(srcDir.length() + 1);
} else if (designerResource.find(binDir) == 0) {
@@ -748,60 +962,53 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup()
designerResource =
cmsys::SystemTools::GetFilenameName(designerResource);
}
- this->ConvertToWindowsSlash(designerResource);
- this->WriteString("<LastGenOutput>", 3);
- (*this->BuildFileStream) << designerResource
- << "</LastGenOutput>\n";
+ ConvertToWindowsSlash(designerResource);
+ e2.Element("LastGenOutput", designerResource);
}
}
- const cmPropertyMap& props = (*oi)->GetProperties();
- for (cmPropertyMap::const_iterator p = props.begin(); p != props.end();
- ++p) {
+ const cmPropertyMap& props = oi->GetProperties();
+ for (const auto& p : props) {
static const std::string propNamePrefix = "VS_CSHARP_";
- if (p->first.find(propNamePrefix.c_str()) == 0) {
- std::string tagName = p->first.substr(propNamePrefix.length());
+ if (p.first.find(propNamePrefix) == 0) {
+ std::string tagName = p.first.substr(propNamePrefix.length());
if (!tagName.empty()) {
- std::string value = props.GetPropertyValue(p->first);
+ std::string value = props.GetPropertyValue(p.first);
if (!value.empty()) {
- this->WriteString("<", 3);
- (*this->BuildFileStream) << tagName << ">";
- (*this->BuildFileStream) << cmVS10EscapeXML(value);
- (*this->BuildFileStream) << "</" << tagName << ">\n";
+ e2.Element(tagName.c_str(), value);
}
}
}
}
}
-
- this->WriteString("</EmbeddedResource>\n", 2);
}
- this->WriteString("</ItemGroup>\n", 1);
}
}
-void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup()
+void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup(Elem& e0)
{
std::vector<cmSourceFile const*> xamlObjs;
this->GeneratorTarget->GetXamlSources(xamlObjs, "");
if (!xamlObjs.empty()) {
- this->WriteString("<ItemGroup>\n", 1);
- for (std::vector<cmSourceFile const*>::const_iterator oi =
- xamlObjs.begin();
- oi != xamlObjs.end(); ++oi) {
- std::string obj = (*oi)->GetFullPath();
- std::string xamlType;
- const char* xamlTypeProperty = (*oi)->GetProperty("VS_XAML_TYPE");
+ Elem e1(e0, "ItemGroup");
+ for (cmSourceFile const* oi : xamlObjs) {
+ std::string obj = oi->GetFullPath();
+ const char* xamlType;
+ const char* xamlTypeProperty = oi->GetProperty("VS_XAML_TYPE");
if (xamlTypeProperty) {
xamlType = xamlTypeProperty;
} else {
xamlType = "Page";
}
- this->WriteSource(xamlType, *oi, ">\n");
- if (csproj == this->ProjectType && !this->InSourceBuild) {
+ Elem e2(e1, xamlType);
+ this->WriteSource(e2, oi);
+ e2.SetHasElements();
+ if (this->ProjectType == csproj && !this->InSourceBuild) {
// add <Link> tag to written XAML source if necessary
- const std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
- const std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
+ const std::string& srcDir =
+ this->Makefile->GetCurrentSourceDirectory();
+ const std::string& binDir =
+ this->Makefile->GetCurrentBinaryDirectory();
std::string link;
if (obj.find(srcDir) == 0) {
link = obj.substr(srcDir.length() + 1);
@@ -811,59 +1018,52 @@ void cmVisualStudio10TargetGenerator::WriteXamlFilesGroup()
link = cmsys::SystemTools::GetFilenameName(obj);
}
if (!link.empty()) {
- this->ConvertToWindowsSlash(link);
- this->WriteString("<Link>", 3);
- (*this->BuildFileStream) << link << "</Link>\n";
+ ConvertToWindowsSlash(link);
+ e2.Element("Link", link);
}
}
- this->WriteString("<SubType>Designer</SubType>\n", 3);
- this->WriteString("</", 2);
- (*this->BuildFileStream) << xamlType << ">\n";
+ e2.Element("SubType", "Designer");
}
- this->WriteString("</ItemGroup>\n", 1);
}
}
-void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences()
+void cmVisualStudio10TargetGenerator::WriteTargetSpecificReferences(Elem& e0)
{
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);
+ Elem(e0, "Import")
+ .Attribute("Project",
+ "$(MSBuildExtensionsPath)\\Microsoft\\WindowsPhone\\v"
+ "$(TargetPlatformVersion)\\Microsoft.Cpp.WindowsPhone."
+ "$(TargetPlatformVersion).targets");
}
}
}
-void cmVisualStudio10TargetGenerator::WriteTargetsFileReferences()
+void cmVisualStudio10TargetGenerator::WriteTargetsFileReferences(Elem& e1)
{
- for (std::vector<TargetsFileAndConfigs>::iterator i =
- this->TargetsFileAndConfigsVec.begin();
- i != this->TargetsFileAndConfigsVec.end(); ++i) {
- TargetsFileAndConfigs const& tac = *i;
- this->WriteString("<Import Project=\"", 3);
- (*this->BuildFileStream) << tac.File << "\" ";
- (*this->BuildFileStream) << "Condition=\"";
- (*this->BuildFileStream) << "Exists('" << tac.File << "')";
+ for (TargetsFileAndConfigs const& tac : this->TargetsFileAndConfigsVec) {
+ std::ostringstream oss;
+ oss << "Exists('" << tac.File << "')";
if (!tac.Configs.empty()) {
- (*this->BuildFileStream) << " And (";
+ oss << " And (";
for (size_t j = 0; j < tac.Configs.size(); ++j) {
if (j > 0) {
- (*this->BuildFileStream) << " Or ";
+ oss << " Or ";
}
- (*this->BuildFileStream) << "'$(Configuration)'=='" << tac.Configs[j]
- << "'";
+ oss << "'$(Configuration)'=='" << tac.Configs[j] << "'";
}
- (*this->BuildFileStream) << ")";
+ oss << ")";
}
- (*this->BuildFileStream) << "\" />\n";
+
+ Elem(e1, "Import")
+ .Attribute("Project", tac.File)
+ .Attribute("Condition", oss.str());
}
}
-void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
+void cmVisualStudio10TargetGenerator::WriteWinRTReferences(Elem& e0)
{
std::vector<std::string> references;
if (const char* vsWinRTReferences =
@@ -877,77 +1077,67 @@ void cmVisualStudio10TargetGenerator::WriteWinRTReferences()
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);
+ Elem e1(e0, "ItemGroup");
+ for (std::string const& ri : references) {
+ Elem e2(e1, "Reference");
+ e2.Attribute("Include", ri);
+ e2.Element("IsWinMDFile", "true");
}
- this->WriteString("</ItemGroup>\n", 1);
}
}
// ConfigurationType Application, Utility StaticLibrary DynamicLibrary
-void cmVisualStudio10TargetGenerator::WriteProjectConfigurations()
+void cmVisualStudio10TargetGenerator::WriteProjectConfigurations(Elem& e0)
{
- this->WriteString("<ItemGroup Label=\"ProjectConfigurations\">\n", 1);
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.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);
+ Elem e1(e0, "ItemGroup");
+ e1.Attribute("Label", "ProjectConfigurations");
+ for (std::string const& c : this->Configurations) {
+ Elem e2(e1, "ProjectConfiguration");
+ e2.Attribute("Include", c + "|" + this->Platform);
+ e2.Element("Configuration", c);
+ e2.Element("Platform", this->Platform);
+ }
}
-void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
+void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues(Elem& e0)
{
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- this->WritePlatformConfigTag("PropertyGroup", i->c_str(), 1,
- " Label=\"Configuration\"", "\n");
-
- if (csproj != this->ProjectType) {
- std::string configType = "<ConfigurationType>";
+ for (std::string const& c : this->Configurations) {
+ Elem e1(e0, "PropertyGroup");
+ e1.Attribute("Condition", this->CalcCondition(c));
+ e1.Attribute("Label", "Configuration");
+
+ if (this->ProjectType != csproj) {
+ std::string configType;
if (const char* vsConfigurationType =
this->GeneratorTarget->GetProperty("VS_CONFIGURATION_TYPE")) {
- configType += cmVS10EscapeXML(vsConfigurationType);
+ configType = vsConfigurationType;
} else {
switch (this->GeneratorTarget->GetType()) {
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
- configType += "DynamicLibrary";
+ configType = "DynamicLibrary";
break;
case cmStateEnums::OBJECT_LIBRARY:
case cmStateEnums::STATIC_LIBRARY:
- configType += "StaticLibrary";
+ configType = "StaticLibrary";
break;
case cmStateEnums::EXECUTABLE:
if (this->NsightTegra &&
!this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
// Android executables are .so too.
- configType += "DynamicLibrary";
+ configType = "DynamicLibrary";
} else {
- configType += "Application";
+ configType = "Application";
}
break;
case cmStateEnums::UTILITY:
case cmStateEnums::GLOBAL_TARGET:
if (this->NsightTegra) {
// Tegra-Android platform does not understand "Utility".
- configType += "StaticLibrary";
+ configType = "StaticLibrary";
} else {
- configType += "Utility";
+ configType = "Utility";
}
break;
case cmStateEnums::UNKNOWN_LIBRARY:
@@ -955,32 +1145,52 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues()
break;
}
}
- configType += "</ConfigurationType>\n";
- this->WriteString(configType.c_str(), 2);
+ e1.Element("ConfigurationType", configType);
}
if (this->MSTools) {
if (!this->Managed) {
- this->WriteMSToolConfigurationValues(*i);
+ this->WriteMSToolConfigurationValues(e1, c);
} else {
- this->WriteMSToolConfigurationValuesManaged(*i);
+ this->WriteMSToolConfigurationValuesManaged(e1, c);
}
} else if (this->NsightTegra) {
- this->WriteNsightTegraConfigurationValues(*i);
+ this->WriteNsightTegraConfigurationValues(e1, c);
}
+ }
+}
- this->WriteString("</PropertyGroup>\n", 1);
+void cmVisualStudio10TargetGenerator::WriteCEDebugProjectConfigurationValues(
+ Elem& e0)
+{
+ if (!this->GlobalGenerator->TargetsWindowsCE()) {
+ return;
+ }
+ const char* additionalFiles =
+ this->GeneratorTarget->GetProperty("DEPLOYMENT_ADDITIONAL_FILES");
+ const char* remoteDirectory =
+ this->GeneratorTarget->GetProperty("DEPLOYMENT_REMOTE_DIRECTORY");
+ if (!(additionalFiles || remoteDirectory)) {
+ return;
+ }
+ for (std::string const& c : this->Configurations) {
+ Elem e1(e0, "PropertyGroup");
+ e1.Attribute("Condition", this->CalcCondition(c));
+
+ if (remoteDirectory) {
+ e1.Element("RemoteDirectory", remoteDirectory);
+ }
+ if (additionalFiles) {
+ e1.Element("CEAdditionalFiles", additionalFiles);
+ }
}
}
void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
- std::string const& config)
+ Elem& e1, std::string const& config)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- const char* mfcFlag =
- this->GeneratorTarget->Target->GetMakefile()->GetDefinition(
- "CMAKE_MFC_FLAG");
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ const char* mfcFlag = this->Makefile->GetDefinition("CMAKE_MFC_FLAG");
if (mfcFlag) {
std::string const mfcFlagValue = mfcFlag;
@@ -992,9 +1202,7 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
useOfMfcValue = "Dynamic";
}
}
- std::string mfcLine = "<UseOfMfc>";
- mfcLine += useOfMfcValue + "</UseOfMfc>\n";
- this->WriteString(mfcLine.c_str(), 2);
+ e1.Element("UseOfMfc", useOfMfcValue);
}
if ((this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY &&
@@ -1003,58 +1211,59 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValues(
this->GlobalGenerator->TargetsWindowsPhone() ||
this->GlobalGenerator->TargetsWindowsStore() ||
this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
- this->WriteString("<CharacterSet>Unicode</CharacterSet>\n", 2);
+ e1.Element("CharacterSet", "Unicode");
} else if (this->GeneratorTarget->GetType() <=
- cmStateEnums::MODULE_LIBRARY &&
+ cmStateEnums::OBJECT_LIBRARY &&
this->ClOptions[config]->UsingSBCS()) {
- this->WriteString("<CharacterSet>NotSet</CharacterSet>\n", 2);
+ e1.Element("CharacterSet", "NotSet");
} else {
- this->WriteString("<CharacterSet>MultiByte</CharacterSet>\n", 2);
+ e1.Element("CharacterSet", "MultiByte");
}
if (const char* toolset = gg->GetPlatformToolset()) {
- std::string pts = "<PlatformToolset>";
- pts += toolset;
- pts += "</PlatformToolset>\n";
- this->WriteString(pts.c_str(), 2);
+ e1.Element("PlatformToolset", toolset);
}
if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) {
- this->WriteString("<WindowsAppContainer>true"
- "</WindowsAppContainer>\n",
- 2);
+ e1.Element("WindowsAppContainer", "true");
+ }
+ if (this->IPOEnabledConfigurations.count(config) > 0) {
+ e1.Element("WholeProgramOptimization", "true");
+ }
+ {
+ auto s = this->SpectreMitigation.find(config);
+ if (s != this->SpectreMitigation.end()) {
+ e1.Element("SpectreMitigation", s->second);
+ }
}
}
void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
- std::string const& config)
+ Elem& e1, std::string const& config)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+ if (this->GeneratorTarget->GetType() > cmStateEnums::OBJECT_LIBRARY) {
+ return;
+ }
+
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
Options& o = *(this->ClOptions[config]);
if (o.IsDebug()) {
- this->WriteString("<DebugSymbols>true</DebugSymbols>\n", 2);
- this->WriteString("<DefineDebug>true</DefineDebug>\n", 2);
+ e1.Element("DebugSymbols", "true");
+ e1.Element("DefineDebug", "true");
}
- std::string outDir =
- this->GeneratorTarget->GetDirectory(config.c_str()) + "/";
- this->ConvertToWindowsSlash(outDir);
- this->WriteString("<OutputPath>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(outDir) << "</OutputPath>\n";
+ std::string outDir = this->GeneratorTarget->GetDirectory(config) + "/";
+ ConvertToWindowsSlash(outDir);
+ e1.Element("OutputPath", outDir);
if (o.HasFlag("Platform")) {
- this->WriteString("<PlatformTarget>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(o.GetFlag("Platform"))
- << "</PlatformTarget>\n";
+ e1.Element("PlatformTarget", o.GetFlag("Platform"));
o.RemoveFlag("Platform");
}
if (const char* toolset = gg->GetPlatformToolset()) {
- this->WriteString("<PlatformToolset>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(toolset)
- << "</PlatformToolset>\n";
+ e1.Element("PlatformToolset", toolset);
}
std::string postfixName = cmSystemTools::UpperCase(config);
@@ -1064,100 +1273,96 @@ void cmVisualStudio10TargetGenerator::WriteMSToolConfigurationValuesManaged(
if (const char* postfix = this->GeneratorTarget->GetProperty(postfixName)) {
assemblyName += postfix;
}
- this->WriteString("<AssemblyName>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(assemblyName)
- << "</AssemblyName>\n";
+ e1.Element("AssemblyName", assemblyName);
if (cmStateEnums::EXECUTABLE == this->GeneratorTarget->GetType()) {
- this->WriteString("<StartAction>Program</StartAction>\n", 2);
- this->WriteString("<StartProgram>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(outDir)
- << cmVS10EscapeXML(assemblyName)
- << ".exe</StartProgram>\n";
+ e1.Element("StartAction", "Program");
+ e1.Element("StartProgram", outDir + assemblyName + ".exe");
}
- o.OutputFlagMap(*this->BuildFileStream, " ");
+ OptionsHelper oh(o, e1);
+ oh.OutputFlagMap();
}
//----------------------------------------------------------------------------
void cmVisualStudio10TargetGenerator::WriteNsightTegraConfigurationValues(
- std::string const&)
+ Elem& e1, std::string const&)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
const char* toolset = gg->GetPlatformToolset();
- std::string ntv = "<NdkToolchainVersion>";
- ntv += toolset ? toolset : "Default";
- ntv += "</NdkToolchainVersion>\n";
- this->WriteString(ntv.c_str(), 2);
+ e1.Element("NdkToolchainVersion", toolset ? toolset : "Default");
if (const char* minApi =
this->GeneratorTarget->GetProperty("ANDROID_API_MIN")) {
- this->WriteString("<AndroidMinAPI>", 2);
- (*this->BuildFileStream) << "android-" << cmVS10EscapeXML(minApi)
- << "</AndroidMinAPI>\n";
+ e1.Element("AndroidMinAPI", "android-" + std::string(minApi));
}
if (const char* api = this->GeneratorTarget->GetProperty("ANDROID_API")) {
- this->WriteString("<AndroidTargetAPI>", 2);
- (*this->BuildFileStream) << "android-" << cmVS10EscapeXML(api)
- << "</AndroidTargetAPI>\n";
+ e1.Element("AndroidTargetAPI", "android-" + std::string(api));
}
if (const char* cpuArch =
this->GeneratorTarget->GetProperty("ANDROID_ARCH")) {
- this->WriteString("<AndroidArch>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(cpuArch) << "</AndroidArch>\n";
+ e1.Element("AndroidArch", cpuArch);
}
if (const char* stlType =
this->GeneratorTarget->GetProperty("ANDROID_STL_TYPE")) {
- this->WriteString("<AndroidStlType>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(stlType)
- << "</AndroidStlType>\n";
+ e1.Element("AndroidStlType", stlType);
}
}
-void cmVisualStudio10TargetGenerator::WriteCustomCommands()
+void cmVisualStudio10TargetGenerator::WriteCustomCommands(Elem& e0)
{
- this->SourcesVisited.clear();
+ this->CSharpCustomCommandNames.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);
+ for (cmSourceFile const* si : customCommands) {
+ this->WriteCustomCommand(e0, si);
+ }
+
+ // Add CMakeLists.txt file with rule to re-run CMake for user convenience.
+ if (this->GeneratorTarget->GetType() != cmStateEnums::GLOBAL_TARGET &&
+ this->GeneratorTarget->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) {
+ if (cmSourceFile const* sf =
+ this->LocalGenerator->CreateVCProjBuildRule()) {
+ // Write directly rather than through WriteCustomCommand because
+ // we do not want the de-duplication and it has no dependencies.
+ if (cmCustomCommand const* command = sf->GetCustomCommand()) {
+ this->WriteCustomRule(e0, sf, *command);
+ }
+ }
}
}
void cmVisualStudio10TargetGenerator::WriteCustomCommand(
- cmSourceFile const* sf)
+ Elem& e0, cmSourceFile const* sf)
{
- if (this->SourcesVisited.insert(sf).second) {
+ if (this->LocalGenerator->GetSourcesVisited(this->GeneratorTarget)
+ .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);
+ for (cmSourceFile const* di : *depends) {
+ this->WriteCustomCommand(e0, di);
}
}
if (cmCustomCommand const* command = sf->GetCustomCommand()) {
- this->WriteString("<ItemGroup>\n", 1);
- this->WriteCustomRule(sf, *command);
- this->WriteString("</ItemGroup>\n", 1);
+ // C# projects write their <Target> within WriteCustomRule()
+ this->WriteCustomRule(e0, sf, *command);
}
}
}
void cmVisualStudio10TargetGenerator::WriteCustomRule(
- cmSourceFile const* source, cmCustomCommand const& command)
+ Elem& e0, 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())) {
+ if (!cmSystemTools::FileExists(sourcePath)) {
// Make sure the path exists for the file
std::string path = cmSystemTools::GetFilenamePath(sourcePath);
- cmSystemTools::MakeDirectory(path.c_str());
+ cmSystemTools::MakeDirectory(path);
cmsys::ofstream fout(sourcePath.c_str());
if (fout) {
fout << "# generated from CMake\n";
@@ -1170,57 +1375,136 @@ void cmVisualStudio10TargetGenerator::WriteCustomRule(
std::string error = "Could not create file: [";
error += sourcePath;
error += "] ";
- cmSystemTools::Error(error.c_str(),
- cmSystemTools::GetLastSystemError().c_str());
+ cmSystemTools::Error(error + cmSystemTools::GetLastSystemError());
}
}
}
cmLocalVisualStudio7Generator* lg = this->LocalGenerator;
- this->WriteSource("CustomBuild", source, ">\n");
-
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- cmCustomCommandGenerator ccg(command, *i, this->LocalGenerator);
+ std::unique_ptr<Elem> spe1;
+ std::unique_ptr<Elem> spe2;
+ if (this->ProjectType != csproj) {
+ spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
+ spe2 = cm::make_unique<Elem>(*spe1, "CustomBuild");
+ this->WriteSource(*spe2, source);
+ spe2->SetHasElements();
+ } else {
+ Elem e1(e0, "ItemGroup");
+ Elem e2(e1, "None");
+ std::string link;
+ this->GetCSharpSourceLink(source, link);
+ this->WriteSource(e2, source);
+ e2.SetHasElements();
+ if (!link.empty()) {
+ e2.Element("Link", link);
+ }
+ }
+ for (std::string const& c : this->Configurations) {
+ cmCustomCommandGenerator ccg(command, c, lg);
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);
+ std::string script = lg->ConstructScript(ccg);
+ // input files for custom command
+ std::stringstream additional_inputs;
+ {
+ const char* sep = "";
+ if (this->ProjectType == csproj) {
+ // csproj files do not attach the command to a specific file
+ // so the primary input must be listed explicitly.
+ additional_inputs << source->GetFullPath();
+ sep = ";";
+ }
+
+ // Avoid listing an input more than once.
+ std::set<std::string> unique_inputs;
+ // The source is either implicit an input or has been added above.
+ unique_inputs.insert(source->GetFullPath());
+
+ for (std::string const& d : ccg.GetDepends()) {
+ std::string dep;
+ if (lg->GetRealDependency(d, c, dep)) {
+ if (!unique_inputs.insert(dep).second) {
+ // already listed
+ continue;
+ }
+ ConvertToWindowsSlash(dep);
+ additional_inputs << sep << dep;
+ sep = ";";
+ }
+ }
+ if (this->ProjectType != csproj) {
+ additional_inputs << sep << "%(AdditionalInputs)";
+ }
+ }
+ // output files for custom command
+ std::stringstream outputs;
+ bool symbolic = false;
+ {
+ const char* sep = "";
+ for (std::string const& o : ccg.GetOutputs()) {
+ std::string out = o;
+ ConvertToWindowsSlash(out);
+ outputs << sep << out;
+ sep = ";";
+ if (!symbolic) {
+ if (cmSourceFile* sf = this->Makefile->GetSource(
+ o, cmSourceFileLocationKind::Known)) {
+ symbolic = sf->GetPropertyAsBool("SYMBOLIC");
+ }
+ }
}
}
- (*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() >
- cmGlobalVisualStudioGenerator::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);
+ if (this->ProjectType == csproj) {
+ std::string name = "CustomCommand_" + c + "_" +
+ cmSystemTools::ComputeStringMD5(sourcePath);
+ this->WriteCustomRuleCSharp(e0, c, name, script, additional_inputs.str(),
+ outputs.str(), comment);
+ } else {
+ this->WriteCustomRuleCpp(*spe2, c, script, additional_inputs.str(),
+ outputs.str(), comment, symbolic);
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteCustomRuleCpp(
+ Elem& e2, std::string const& config, std::string const& script,
+ std::string const& additional_inputs, std::string const& outputs,
+ std::string const& comment, bool symbolic)
+{
+ const std::string cond = this->CalcCondition(config);
+ e2.WritePlatformConfigTag("Message", cond, comment);
+ e2.WritePlatformConfigTag("Command", cond, script);
+ e2.WritePlatformConfigTag("AdditionalInputs", cond, additional_inputs);
+ e2.WritePlatformConfigTag("Outputs", cond, outputs);
+ if (this->LocalGenerator->GetVersion() >
+ cmGlobalVisualStudioGenerator::VS10) {
+ // VS >= 11 let us turn off linking of custom command outputs.
+ e2.WritePlatformConfigTag("LinkObjects", cond, "false");
+ }
+ if (symbolic &&
+ this->LocalGenerator->GetVersion() >=
+ cmGlobalVisualStudioGenerator::VS16) {
+ // VS >= 16.4 warn if outputs are not created, but one of our
+ // outputs is marked SYMBOLIC and not expected to be created.
+ e2.WritePlatformConfigTag("VerifyInputsAndOutputsExist", cond, "false");
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteCustomRuleCSharp(
+ Elem& e0, std::string const& config, std::string const& name,
+ std::string const& script, std::string const& inputs,
+ std::string const& outputs, std::string const& comment)
+{
+ this->CSharpCustomCommandNames.insert(name);
+ Elem e1(e0, "Target");
+ e1.Attribute("Condition", this->CalcCondition(config));
+ e1.S << "\n Name=\"" << name << "\"";
+ e1.S << "\n Inputs=\"" << cmVS10EscapeAttr(inputs) << "\"";
+ e1.S << "\n Outputs=\"" << cmVS10EscapeAttr(outputs) << "\"";
+ if (!comment.empty()) {
+ Elem(e1, "Exec").Attribute("Command", "echo " + comment);
+ }
+ Elem(e1, "Exec").Attribute("Command", script);
}
std::string cmVisualStudio10TargetGenerator::ConvertPath(
@@ -1228,22 +1512,23 @@ std::string cmVisualStudio10TargetGenerator::ConvertPath(
{
return forceRelative
? cmSystemTools::RelativePath(
- this->LocalGenerator->GetCurrentBinaryDirectory(), path.c_str())
- : path.c_str();
+ this->LocalGenerator->GetCurrentBinaryDirectory(), path)
+ : path;
}
-void cmVisualStudio10TargetGenerator::ConvertToWindowsSlash(std::string& s)
+static void 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++;
+ for (auto& ch : s) {
+ if (ch == '/') {
+ ch = '\\';
+ }
}
}
+
void cmVisualStudio10TargetGenerator::WriteGroups()
{
- if (csproj == this->ProjectType) {
+ if (this->ProjectType == csproj) {
return;
}
@@ -1253,13 +1538,19 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
this->GeneratorTarget->GetAllConfigSources();
- std::set<cmSourceGroup*> groupsUsed;
- for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si =
- sources.begin();
- si != sources.end(); ++si) {
- std::string const& source = si->Source->GetFullPath();
+ std::set<cmSourceGroup const*> groupsUsed;
+ for (cmGeneratorTarget::AllConfigSource const& si : sources) {
+ std::string const& source = si.Source->GetFullPath();
+ cmSourceGroup* sourceGroup =
+ this->Makefile->FindSourceGroup(source, sourceGroups);
+ groupsUsed.insert(sourceGroup);
+ }
+
+ if (cmSourceFile const* srcCMakeLists =
+ this->LocalGenerator->CreateVCProjBuildRule()) {
+ std::string const& source = srcCMakeLists->GetFullPath();
cmSourceGroup* sourceGroup =
- this->Makefile->FindSourceGroup(source.c_str(), sourceGroups);
+ this->Makefile->FindSourceGroup(source, sourceGroups);
groupsUsed.insert(sourceGroup);
}
@@ -1271,114 +1562,97 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
path += this->Name;
path += computeProjectFileExtension(this->GeneratorTarget);
path += ".filters";
- cmGeneratedFileStream fout(path.c_str());
+ cmGeneratedFileStream fout(path);
fout.SetCopyIfDifferent(true);
char magic[] = { char(0xEF), char(0xBB), char(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);
+
+ fout << "<?xml version=\"1.0\" encoding=\""
+ << this->GlobalGenerator->Encoding() << "\"?>"
+ << "\n";
+ {
+ Elem e0(fout, "Project");
+ e0.Attribute("ToolsVersion", this->GlobalGenerator->GetToolsVersion());
+ e0.Attribute("xmlns",
+ "http://schemas.microsoft.com/developer/msbuild/2003");
+
+ for (auto const& ti : this->Tools) {
+ this->WriteGroupSources(e0, ti.first, ti.second, sourceGroups);
+ }
+
+ // Added files are images and the manifest.
+ if (!this->AddedFiles.empty()) {
+ Elem e1(e0, "ItemGroup");
+ e1.SetHasElements();
+ for (std::string const& oi : this->AddedFiles) {
+ std::string fileName =
+ cmSystemTools::LowerCase(cmSystemTools::GetFilenameName(oi));
+ if (fileName == "wmappmanifest.xml") {
+ Elem e2(e1, "XML");
+ e2.Attribute("Include", oi);
+ e2.Element("Filter", "Resource Files");
+ } else if (cmSystemTools::GetFilenameExtension(fileName) ==
+ ".appxmanifest") {
+ Elem e2(e1, "AppxManifest");
+ e2.Attribute("Include", oi);
+ e2.Element("Filter", "Resource Files");
+ } else if (cmSystemTools::GetFilenameExtension(fileName) == ".pfx") {
+ Elem e2(e1, "None");
+ e2.Attribute("Include", oi);
+ e2.Element("Filter", "Resource Files");
+ } else {
+ Elem e2(e1, "Image");
+ e2.Attribute("Include", oi);
+ e2.Element("Filter", "Resource Files");
+ }
}
}
- 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);
- }
-
- 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->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->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;
+ std::vector<cmSourceFile const*> resxObjs;
+ this->GeneratorTarget->GetResxSources(resxObjs, "");
+ if (!resxObjs.empty()) {
+ Elem e1(e0, "ItemGroup");
+ for (cmSourceFile const* oi : resxObjs) {
+ std::string obj = oi->GetFullPath();
+ ConvertToWindowsSlash(obj);
+ Elem e2(e1, "EmbeddedResource");
+ e2.Attribute("Include", obj);
+ e2.Element("Filter", "Resource Files");
+ }
+ }
+ {
+ Elem e1(e0, "ItemGroup");
+ e1.SetHasElements();
+ std::vector<cmSourceGroup const*> groupsVec(groupsUsed.begin(),
+ groupsUsed.end());
+ std::sort(groupsVec.begin(), groupsVec.end(),
+ [](cmSourceGroup const* l, cmSourceGroup const* r) {
+ return l->GetFullName() < r->GetFullName();
+ });
+ for (cmSourceGroup const* sg : groupsVec) {
+ std::string const& name = sg->GetFullName();
+ if (!name.empty()) {
+ std::string guidName = "SG_Filter_" + name;
+ std::string guid = this->GlobalGenerator->GetGUID(guidName);
+ Elem e2(e1, "Filter");
+ e2.Attribute("Include", name);
+ e2.Element("UniqueIdentifier", "{" + guid + "}");
+ }
+ }
+
+ if (!resxObjs.empty() || !this->AddedFiles.empty()) {
+ std::string guidName = "SG_Filter_Resource Files";
+ std::string guid = this->GlobalGenerator->GetGUID(guidName);
+ Elem e2(e1, "Filter");
+ e2.Attribute("Include", "Resource Files");
+ e2.Element("UniqueIdentifier", "{" + guid + "}");
+ e2.Element("Extensions",
+ "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;"
+ "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms");
+ }
+ }
+ }
+ fout << '\n';
if (fout.Close()) {
this->GlobalGenerator->FileReplacedDuringGenerate(path);
@@ -1387,29 +1661,26 @@ void cmVisualStudio10TargetGenerator::WriteGroups()
// Add to groupsUsed empty source groups that have non-empty children.
void cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
- std::set<cmSourceGroup*>& groupsUsed,
+ std::set<cmSourceGroup const*>& 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();
+ for (cmSourceGroup const& current : allGroups) {
+ 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()) {
+ if (groupsUsed.count(&current) > 0) {
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();
+ auto child_it = children.begin();
while (child_it != children.end()) {
- cmSourceGroup* child_ptr = const_cast<cmSourceGroup*>(&(*child_it));
- if (groupsUsed.find(child_ptr) != groupsUsed.end()) {
+ if (groupsUsed.count(&(*child_it)) > 0) {
break; // found a child that was already added => add current group too
}
child_it++;
@@ -1419,65 +1690,60 @@ void cmVisualStudio10TargetGenerator::AddMissingSourceGroups(
continue; // no descendants have source files => ignore this group
}
- groupsUsed.insert(current_ptr);
+ groupsUsed.insert(&current);
}
}
void cmVisualStudio10TargetGenerator::WriteGroupSources(
- const char* name, ToolSources const& sources,
+ Elem& e0, std::string const& 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;
+ Elem e1(e0, "ItemGroup");
+ e1.SetHasElements();
+ for (ToolSource const& s : sources) {
+ 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->Makefile->FindSourceGroup(source, sourceGroups);
+ std::string const& filter = sourceGroup->GetFullName();
+ std::string path = this->ConvertPath(source, s.RelativePath);
+ ConvertToWindowsSlash(path);
+ Elem e2(e1, name.c_str());
+ e2.Attribute("Include", path);
+ if (!filter.empty()) {
+ e2.Element("Filter", filter);
}
}
- this->WriteString("</ItemGroup>\n", 1);
}
-void cmVisualStudio10TargetGenerator::WriteHeaderSource(cmSourceFile const* sf)
+void cmVisualStudio10TargetGenerator::WriteHeaderSource(Elem& e1,
+ cmSourceFile const* sf)
{
std::string const& fileName = sf->GetFullPath();
+ Elem e2(e1, "ClInclude");
+ this->WriteSource(e2, sf);
if (this->IsResxHeader(fileName)) {
- this->WriteSource("ClInclude", sf, ">\n");
- this->WriteString("<FileType>CppForm</FileType>\n", 3);
- this->WriteString("</ClInclude>\n", 2);
+ e2.Element("FileType", "CppForm");
} else if (this->IsXamlHeader(fileName)) {
- this->WriteSource("ClInclude", sf, ">\n");
- this->WriteString("<DependentUpon>", 3);
std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
- (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
- this->WriteString("</ClInclude>\n", 2);
- } else {
- this->WriteSource("ClInclude", sf);
+ e2.Element("DependentUpon", xamlFileName);
}
}
-void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
+void cmVisualStudio10TargetGenerator::WriteExtraSource(Elem& e1,
+ cmSourceFile const* sf)
{
bool toolHasSettings = false;
- std::string tool = "None";
+ const char* tool = "None";
std::string shaderType;
std::string shaderEntryPoint;
std::string shaderModel;
std::string shaderAdditionalFlags;
+ std::string shaderDisableOptimizations;
+ std::string shaderEnableDebug;
+ std::string shaderObjectFileName;
+ std::string outputHeaderFile;
+ std::string variableName;
std::string settingsGenerator;
std::string settingsLastGenOutput;
std::string sourceLink;
@@ -1485,7 +1751,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
std::string copyToOutDir;
std::string includeInVsix;
std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
- if (csproj == this->ProjectType) {
+ if (this->ProjectType == csproj) {
// EVERY extra source file must have a <Link>, otherwise it might not
// be visible in Visual Studio at all. The path relative to current
// source- or binary-dir is used within the link, if the file is
@@ -1498,7 +1764,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
std::string srcDir = this->Makefile->GetCurrentSourceDirectory();
std::string binDir = this->Makefile->GetCurrentBinaryDirectory();
if (fullFileName.find(binDir) != std::string::npos) {
- sourceLink = "";
+ sourceLink.clear();
} else if (fullFileName.find(srcDir) != std::string::npos) {
sourceLink = fullFileName.substr(srcDir.length() + 1);
} else {
@@ -1506,7 +1772,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
sourceLink = cmsys::SystemTools::GetFilenameName(fullFileName);
}
if (!sourceLink.empty()) {
- this->ConvertToWindowsSlash(sourceLink);
+ ConvertToWindowsSlash(sourceLink);
}
}
}
@@ -1527,11 +1793,35 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
shaderModel = sm;
toolHasSettings = true;
}
+ // Figure out which output header file to use if any
+ if (const char* ohf = sf->GetProperty("VS_SHADER_OUTPUT_HEADER_FILE")) {
+ outputHeaderFile = ohf;
+ toolHasSettings = true;
+ }
+ // Figure out which variable name to use if any
+ if (const char* vn = sf->GetProperty("VS_SHADER_VARIABLE_NAME")) {
+ variableName = vn;
+ toolHasSettings = true;
+ }
// Figure out if there's any additional flags to use
if (const char* saf = sf->GetProperty("VS_SHADER_FLAGS")) {
shaderAdditionalFlags = saf;
toolHasSettings = true;
}
+ // Figure out if debug information should be generated
+ if (const char* sed = sf->GetProperty("VS_SHADER_ENABLE_DEBUG")) {
+ shaderEnableDebug = sed;
+ toolHasSettings = true;
+ }
+ // Figure out if optimizations should be disabled
+ if (const char* sdo = sf->GetProperty("VS_SHADER_DISABLE_OPTIMIZATIONS")) {
+ shaderDisableOptimizations = sdo;
+ toolHasSettings = true;
+ }
+ if (const char* sofn = sf->GetProperty("VS_SHADER_OBJECT_FILE_NAME")) {
+ shaderObjectFileName = sofn;
+ toolHasSettings = true;
+ }
} else if (ext == "jpg" || ext == "png") {
tool = "Image";
} else if (ext == "resw") {
@@ -1541,12 +1831,8 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
} else if (ext == "natvis") {
tool = "Natvis";
} else if (ext == "settings") {
- // remove path to current source dir (if files are in current source dir)
- if (!sourceLink.empty()) {
- settingsLastGenOutput = sourceLink;
- } else {
- settingsLastGenOutput = sf->GetFullPath();
- }
+ settingsLastGenOutput =
+ cmsys::SystemTools::GetFilenameName(sf->GetFullPath());
std::size_t pos = settingsLastGenOutput.find(".settings");
settingsLastGenOutput.replace(pos, 9, ".Designer.cs");
settingsGenerator = "SettingsSingleFileGenerator";
@@ -1555,6 +1841,7 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
subType = "Designer";
}
if (const char* c = sf->GetProperty("VS_COPY_TO_OUT_DIR")) {
+ tool = "Content";
copyToOutDir = c;
toolHasSettings = true;
}
@@ -1564,6 +1851,10 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
toolHasSettings = true;
}
+ // Collect VS_CSHARP_* property values (if some are set)
+ std::map<std::string, std::string> sourceFileTags;
+ this->GetCSharpSourceProperties(sf, sourceFileTags);
+
if (this->NsightTegra) {
// Nsight Tegra needs specific file types to check up-to-dateness.
std::string name = cmSystemTools::LowerCase(sf->GetLocation().GetName());
@@ -1599,98 +1890,128 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource(cmSourceFile const* sf)
}
}
+ Elem e2(e1, tool);
+ this->WriteSource(e2, sf);
if (toolHasSettings) {
- this->WriteSource(tool, sf, ">\n");
+ e2.SetHasElements();
if (!deployContent.empty()) {
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(deployContent);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(deployContent);
// Deployment location cannot be set on a configuration basis
if (!deployLocation.empty()) {
- this->WriteString("<Link>", 3);
- (*this->BuildFileStream) << deployLocation
- << "\\%(FileName)%(Extension)";
- this->WriteString("</Link>\n", 0);
+ e2.Element("Link", deployLocation + "\\%(FileName)%(Extension)");
}
for (size_t i = 0; i != this->Configurations.size(); ++i) {
- if (0 == strcmp(cge->Evaluate(this->LocalGenerator,
- this->Configurations[i]),
- "1")) {
- this->WriteString("<DeploymentContent Condition=\""
- "'$(Configuration)|$(Platform)'=='",
- 3);
- (*this->BuildFileStream) << this->Configurations[i] << "|"
- << this->Platform << "'\">true";
- this->WriteString("</DeploymentContent>\n", 0);
+ if (cge->Evaluate(this->LocalGenerator, this->Configurations[i]) ==
+ "1") {
+ e2.WritePlatformConfigTag("DeploymentContent",
+ "'$(Configuration)|$(Platform)'=='" +
+ this->Configurations[i] + "|" +
+ this->Platform + "'",
+ "true");
} else {
- this->WriteString("<ExcludedFromBuild Condition=\""
- "'$(Configuration)|$(Platform)'=='",
- 3);
- (*this->BuildFileStream) << this->Configurations[i] << "|"
- << this->Platform << "'\">true";
- this->WriteString("</ExcludedFromBuild>\n", 0);
+ e2.WritePlatformConfigTag("ExcludedFromBuild",
+ "'$(Configuration)|$(Platform)'=='" +
+ this->Configurations[i] + "|" +
+ this->Platform + "'",
+ "true");
}
}
}
if (!shaderType.empty()) {
- this->WriteString("<ShaderType>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(shaderType)
- << "</ShaderType>\n";
+ e2.Element("ShaderType", shaderType);
}
if (!shaderEntryPoint.empty()) {
- this->WriteString("<EntryPointName>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(shaderEntryPoint)
- << "</EntryPointName>\n";
+ e2.Element("EntryPointName", shaderEntryPoint);
}
if (!shaderModel.empty()) {
- this->WriteString("<ShaderModel>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(shaderModel)
- << "</ShaderModel>\n";
+ e2.Element("ShaderModel", shaderModel);
+ }
+ if (!outputHeaderFile.empty()) {
+ for (size_t i = 0; i != this->Configurations.size(); ++i) {
+ e2.WritePlatformConfigTag("HeaderFileOutput",
+ "'$(Configuration)|$(Platform)'=='" +
+ this->Configurations[i] + "|" +
+ this->Platform + "'",
+ outputHeaderFile);
+ }
+ }
+ if (!variableName.empty()) {
+ for (size_t i = 0; i != this->Configurations.size(); ++i) {
+ e2.WritePlatformConfigTag("VariableName",
+ "'$(Configuration)|$(Platform)'=='" +
+ this->Configurations[i] + "|" +
+ this->Platform + "'",
+ variableName);
+ }
+ }
+ if (!shaderEnableDebug.empty()) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(shaderEnableDebug);
+
+ for (size_t i = 0; i != this->Configurations.size(); ++i) {
+ const std::string& enableDebug =
+ cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
+ if (!enableDebug.empty()) {
+ e2.WritePlatformConfigTag(
+ "EnableDebuggingInformation",
+ "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
+ "|" + this->Platform + "'",
+ cmSystemTools::IsOn(enableDebug) ? "true" : "false");
+ }
+ }
+ }
+ if (!shaderDisableOptimizations.empty()) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(shaderDisableOptimizations);
+
+ for (size_t i = 0; i != this->Configurations.size(); ++i) {
+ const std::string& disableOptimizations =
+ cge->Evaluate(this->LocalGenerator, this->Configurations[i]);
+ if (!disableOptimizations.empty()) {
+ e2.WritePlatformConfigTag(
+ "DisableOptimizations",
+ "'$(Configuration)|$(Platform)'=='" + this->Configurations[i] +
+ "|" + this->Platform + "'",
+ (cmSystemTools::IsOn(disableOptimizations) ? "true" : "false"));
+ }
+ }
+ }
+ if (!shaderObjectFileName.empty()) {
+ e2.Element("ObjectFileOutput", shaderObjectFileName);
}
if (!shaderAdditionalFlags.empty()) {
- this->WriteString("<AdditionalOptions>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(shaderAdditionalFlags)
- << "</AdditionalOptions>\n";
+ e2.Element("AdditionalOptions", shaderAdditionalFlags);
}
if (!settingsGenerator.empty()) {
- this->WriteString("<Generator>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(settingsGenerator)
- << "</Generator>\n";
+ e2.Element("Generator", settingsGenerator);
}
if (!settingsLastGenOutput.empty()) {
- this->WriteString("<LastGenOutput>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(settingsLastGenOutput)
- << "</LastGenOutput>\n";
+ e2.Element("LastGenOutput", settingsLastGenOutput);
}
if (!sourceLink.empty()) {
- this->WriteString("<Link>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(sourceLink) << "</Link>\n";
+ e2.Element("Link", sourceLink);
}
if (!subType.empty()) {
- this->WriteString("<SubType>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(subType) << "</SubType>\n";
+ e2.Element("SubType", subType);
}
if (!copyToOutDir.empty()) {
- this->WriteString("<CopyToOutputDirectory>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(copyToOutDir)
- << "</CopyToOutputDirectory>\n";
+ e2.Element("CopyToOutputDirectory", copyToOutDir);
}
if (!includeInVsix.empty()) {
- this->WriteString("<IncludeInVSIX>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(includeInVsix)
- << "</IncludeInVSIX>\n";
+ e2.Element("IncludeInVSIX", includeInVsix);
}
-
- this->WriteString("</", 2);
- (*this->BuildFileStream) << tool << ">\n";
- } else {
- this->WriteSource(tool, sf);
+ // write source file specific tags
+ this->WriteCSharpSourceProperties(e2, sourceFileTags);
}
}
-void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool,
- cmSourceFile const* sf,
- const char* end)
+void cmVisualStudio10TargetGenerator::WriteSource(Elem& e2,
+ cmSourceFile const* sf)
{
// Visual Studio tools append relative paths to the current dir, as in:
//
@@ -1704,7 +2025,7 @@ void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool,
std::string sourceFile = this->ConvertPath(sf->GetFullPath(), forceRelative);
if (this->LocalGenerator->GetVersion() ==
cmGlobalVisualStudioGenerator::VS10 &&
- cmSystemTools::FileIsFullPath(sourceFile.c_str())) {
+ cmSystemTools::FileIsFullPath(sourceFile)) {
// 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
@@ -1716,7 +2037,7 @@ void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool,
std::string sourceRel = this->ConvertPath(sf->GetFullPath(), true);
size_t const maxLen = 250;
if (sf->GetCustomCommand() ||
- ((strlen(this->LocalGenerator->GetCurrentBinaryDirectory()) + 1 +
+ ((this->LocalGenerator->GetCurrentBinaryDirectory().length() + 1 +
sourceRel.length()) <= maxLen)) {
forceRelative = true;
sourceFile = sourceRel;
@@ -1724,22 +2045,20 @@ void cmVisualStudio10TargetGenerator::WriteSource(std::string const& tool,
this->GlobalGenerator->PathTooLong(this->GeneratorTarget, sf, sourceRel);
}
}
- this->ConvertToWindowsSlash(sourceFile);
- this->WriteString("<", 2);
- (*this->BuildFileStream) << tool << " Include=\""
- << cmVS10EscapeXML(sourceFile) << "\""
- << (end ? end : " />\n");
+ ConvertToWindowsSlash(sourceFile);
+ e2.Attribute("Include", sourceFile);
ToolSource toolSource = { sf, forceRelative };
- this->Tools[tool].push_back(toolSource);
+ this->Tools[e2.Tag].push_back(toolSource);
}
-void cmVisualStudio10TargetGenerator::WriteAllSources()
+void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0)
{
if (this->GeneratorTarget->GetType() > cmStateEnums::UTILITY) {
return;
}
- this->WriteString("<ItemGroup>\n", 1);
+ Elem e1(e0, "ItemGroup");
+ e1.SetHasElements();
std::vector<size_t> all_configs;
for (size_t ci = 0; ci < this->Configurations.size(); ++ci) {
@@ -1749,11 +2068,16 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
std::vector<cmGeneratorTarget::AllConfigSource> const& sources =
this->GeneratorTarget->GetAllConfigSources();
- for (std::vector<cmGeneratorTarget::AllConfigSource>::const_iterator si =
- sources.begin();
- si != sources.end(); ++si) {
- std::string tool;
- switch (si->Kind) {
+ cmSourceFile const* srcCMakeLists =
+ this->LocalGenerator->CreateVCProjBuildRule();
+
+ for (cmGeneratorTarget::AllConfigSource const& si : sources) {
+ if (si.Source == srcCMakeLists) {
+ // Skip explicit reference to CMakeLists.txt source.
+ continue;
+ }
+ const char* tool = nullptr;
+ switch (si.Kind) {
case cmGeneratorTarget::SourceKindAppManifest:
tool = "AppxManifest";
break;
@@ -1772,17 +2096,17 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
// then vs10 will use it in the build, and we have to list it as
// None instead of Object.
std::vector<cmSourceFile*> const* d =
- this->GeneratorTarget->GetSourceDepends(si->Source);
+ this->GeneratorTarget->GetSourceDepends(si.Source);
if (d && !d->empty()) {
tool = "None";
}
}
break;
case cmGeneratorTarget::SourceKindExtra:
- this->WriteExtraSource(si->Source);
+ this->WriteExtraSource(e1, si.Source);
break;
case cmGeneratorTarget::SourceKindHeader:
- this->WriteHeaderSource(si->Source);
+ this->WriteHeaderSource(e1, si.Source);
break;
case cmGeneratorTarget::SourceKindIDL:
tool = "Midl";
@@ -1794,7 +2118,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
tool = "None";
break;
case cmGeneratorTarget::SourceKindObjectSource: {
- const std::string& lang = si->Source->GetLanguage();
+ const std::string& lang = si.Source->GetLanguage();
if (lang == "C" || lang == "CXX") {
tool = "ClCompile";
} else if (lang == "ASM_MASM" &&
@@ -1821,51 +2145,32 @@ void cmVisualStudio10TargetGenerator::WriteAllSources()
break;
}
- if (!tool.empty()) {
+ if (tool) {
// Compute set of configurations to exclude, if any.
- std::vector<size_t> const& include_configs = si->Configs;
+ std::vector<size_t> const& include_configs = si.Configs;
std::vector<size_t> exclude_configs;
std::set_difference(all_configs.begin(), all_configs.end(),
include_configs.begin(), include_configs.end(),
std::back_inserter(exclude_configs));
- if (si->Kind == cmGeneratorTarget::SourceKindObjectSource) {
- // FIXME: refactor generation to avoid tracking XML syntax state.
- this->WriteSource(tool, si->Source, " ");
- bool have_nested = this->OutputSourceSpecificFlags(si->Source);
- if (!exclude_configs.empty()) {
- if (!have_nested) {
- (*this->BuildFileStream) << ">\n";
- }
- this->WriteExcludeFromBuild(exclude_configs);
- have_nested = true;
- }
- if (have_nested) {
- this->WriteString("</", 2);
- (*this->BuildFileStream) << tool << ">\n";
- } else {
- (*this->BuildFileStream) << " />\n";
- }
- } else if (!exclude_configs.empty()) {
- this->WriteSource(tool, si->Source, ">\n");
- this->WriteExcludeFromBuild(exclude_configs);
- this->WriteString("</", 2);
- (*this->BuildFileStream) << tool << ">\n";
- } else {
- this->WriteSource(tool, si->Source);
+ Elem e2(e1, tool);
+ this->WriteSource(e2, si.Source);
+ if (si.Kind == cmGeneratorTarget::SourceKindObjectSource) {
+ this->OutputSourceSpecificFlags(e2, si.Source);
+ }
+ if (!exclude_configs.empty()) {
+ this->WriteExcludeFromBuild(e2, exclude_configs);
}
}
}
if (this->IsMissingFiles) {
- this->WriteMissingFiles();
+ this->WriteMissingFiles(e1);
}
-
- this->WriteString("</ItemGroup>\n", 1);
}
-bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
- cmSourceFile const* source)
+void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
+ Elem& e2, cmSourceFile const* source)
{
cmSourceFile const& sf = *source;
@@ -1875,17 +2180,32 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
}
std::string flags;
bool configDependentFlags = false;
+ std::string options;
+ bool configDependentOptions = false;
std::string defines;
+ bool configDependentDefines = false;
+ std::string includes;
+ bool configDependentIncludes = false;
if (const char* cflags = sf.GetProperty("COMPILE_FLAGS")) {
-
- if (cmGeneratorExpression::Find(cflags) != std::string::npos) {
- configDependentFlags = true;
- }
+ configDependentFlags =
+ cmGeneratorExpression::Find(cflags) != std::string::npos;
flags += cflags;
}
+ if (const char* coptions = sf.GetProperty("COMPILE_OPTIONS")) {
+ configDependentOptions =
+ cmGeneratorExpression::Find(coptions) != std::string::npos;
+ options += coptions;
+ }
if (const char* cdefs = sf.GetProperty("COMPILE_DEFINITIONS")) {
+ configDependentDefines =
+ cmGeneratorExpression::Find(cdefs) != std::string::npos;
defines += cdefs;
}
+ if (const char* cincludes = sf.GetProperty("INCLUDE_DIRECTORIES")) {
+ configDependentIncludes =
+ cmGeneratorExpression::Find(cincludes) != std::string::npos;
+ includes += cincludes;
+ }
std::string lang =
this->GlobalGenerator->GetLanguageFromExtension(sf.GetExtension().c_str());
std::string sourceLang = this->LocalGenerator->GetSourceFileLanguage(sf);
@@ -1910,41 +2230,34 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
}
}
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.empty()) {
- (*this->BuildFileStream) << firstString;
- firstString = "";
- hasFlags = true;
- this->WriteString("<ObjectFileName>", 3);
- (*this->BuildFileStream) << "$(IntDir)/" << objectName
- << "</ObjectFileName>\n";
- }
- for (std::vector<std::string>::const_iterator config =
- this->Configurations.begin();
- config != this->Configurations.end(); ++config) {
- std::string configUpper = cmSystemTools::UpperCase(*config);
+ if (lang == "CUDA") {
+ e2.Element("CompileOut", "$(IntDir)/" + objectName);
+ } else {
+ e2.Element("ObjectFileName", "$(IntDir)/" + objectName);
+ }
+ }
+ for (std::string const& config : this->Configurations) {
+ 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 (const char* ccdefs = sf.GetProperty(defPropName)) {
if (!configDefines.empty()) {
configDefines += ";";
}
+ configDependentDefines |=
+ cmGeneratorExpression::Find(ccdefs) != std::string::npos;
configDefines += ccdefs;
}
// if we have flags or defines for this config then
// use them
- if (!flags.empty() || configDependentFlags || !configDefines.empty() ||
- compileAs || noWinRT) {
- (*this->BuildFileStream) << firstString;
- firstString = ""; // only do firstString once
- hasFlags = true;
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- cmIDEFlagTable const* flagtable = CM_NULLPTR;
+ if (!flags.empty() || !options.empty() || !configDefines.empty() ||
+ !includes.empty() || compileAs || noWinRT) {
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ cmIDEFlagTable const* flagtable = nullptr;
const std::string& srclang = source->GetLanguage();
if (srclang == "C" || srclang == "CXX") {
flagtable = gg->GetClFlagTable();
@@ -1959,9 +2272,11 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
} else if (srclang == "CSharp") {
flagtable = gg->GetCSharpFlagTable();
}
- cmVisualStudioGeneratorOptions clOptions(
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, config, this->GeneratorTarget, lang);
+ cmVS10GeneratorOptions clOptions(
this->LocalGenerator, cmVisualStudioGeneratorOptions::Compiler,
- flagtable, 0, this);
+ flagtable, this);
if (compileAs) {
clOptions.AddFlag("CompileAs", compileAs);
}
@@ -1969,127 +2284,159 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
clOptions.AddFlag("CompileAsWinRT", "false");
}
if (configDependentFlags) {
- cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(flags);
- std::string evaluatedFlags =
- cge->Evaluate(this->LocalGenerator, *config);
- clOptions.Parse(evaluatedFlags.c_str());
+ clOptions.Parse(genexInterpreter.Evaluate(flags, "COMPILE_FLAGS"));
} else {
- clOptions.Parse(flags.c_str());
+ clOptions.Parse(flags);
}
- if (clOptions.HasFlag("AdditionalIncludeDirectories")) {
- clOptions.AppendFlag("AdditionalIncludeDirectories",
- "%(AdditionalIncludeDirectories)");
+ if (!options.empty()) {
+ std::string expandedOptions;
+ if (configDependentOptions) {
+ this->LocalGenerator->AppendCompileOptions(
+ expandedOptions,
+ genexInterpreter.Evaluate(options, "COMPILE_OPTIONS"));
+ } else {
+ this->LocalGenerator->AppendCompileOptions(expandedOptions, options);
+ }
+ clOptions.Parse(expandedOptions);
}
if (clOptions.HasFlag("DisableSpecificWarnings")) {
clOptions.AppendFlag("DisableSpecificWarnings",
"%(DisableSpecificWarnings)");
}
- clOptions.AddDefines(configDefines.c_str());
- clOptions.SetConfiguration((*config).c_str());
- clOptions.PrependInheritedString("AdditionalOptions");
- clOptions.OutputFlagMap(*this->BuildFileStream, " ");
- clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
- "\n", lang);
+ if (configDependentDefines) {
+ clOptions.AddDefines(
+ genexInterpreter.Evaluate(configDefines, "COMPILE_DEFINITIONS"));
+ } else {
+ clOptions.AddDefines(configDefines);
+ }
+ std::vector<std::string> includeList;
+ if (configDependentIncludes) {
+ this->LocalGenerator->AppendIncludeDirectories(
+ includeList,
+ genexInterpreter.Evaluate(includes, "INCLUDE_DIRECTORIES"), *source);
+ } else {
+ this->LocalGenerator->AppendIncludeDirectories(includeList, includes,
+ *source);
+ }
+ clOptions.AddIncludes(includeList);
+ clOptions.SetConfiguration(config);
+ OptionsHelper oh(clOptions, e2);
+ oh.PrependInheritedString("AdditionalOptions");
+ oh.OutputAdditionalIncludeDirectories(lang);
+ oh.OutputFlagMap();
+ oh.OutputPreprocessorDefinitions(lang);
}
}
if (this->IsXamlSource(source->GetFullPath())) {
- (*this->BuildFileStream) << firstString;
- firstString = ""; // only do firstString once
- hasFlags = true;
- this->WriteString("<DependentUpon>", 3);
const std::string& fileName = source->GetFullPath();
std::string xamlFileName = fileName.substr(0, fileName.find_last_of("."));
- (*this->BuildFileStream) << xamlFileName << "</DependentUpon>\n";
+ e2.Element("DependentUpon", xamlFileName);
}
- if (csproj == this->ProjectType) {
+ if (this->ProjectType == csproj) {
std::string f = source->GetFullPath();
typedef std::map<std::string, std::string> CsPropMap;
CsPropMap sourceFileTags;
// set <Link> tag if necessary
- if (!this->InSourceBuild) {
- const std::string stripFromPath =
- this->Makefile->GetCurrentSourceDirectory();
- if (f.find(stripFromPath) != std::string::npos) {
- std::string link = f.substr(stripFromPath.length() + 1);
- this->ConvertToWindowsSlash(link);
- sourceFileTags["Link"] = link;
- }
- }
- const cmPropertyMap& props = sf.GetProperties();
- for (cmPropertyMap::const_iterator p = props.begin(); p != props.end();
- ++p) {
- static const std::string propNamePrefix = "VS_CSHARP_";
- if (p->first.find(propNamePrefix.c_str()) == 0) {
- std::string tagName = p->first.substr(propNamePrefix.length());
- if (!tagName.empty()) {
- const std::string val = props.GetPropertyValue(p->first);
- if (!val.empty()) {
- sourceFileTags[tagName] = val;
- } else {
- sourceFileTags.erase(tagName);
- }
- }
- }
+ std::string link;
+ this->GetCSharpSourceLink(source, link);
+ if (!link.empty()) {
+ sourceFileTags["Link"] = link;
}
+ this->GetCSharpSourceProperties(&sf, sourceFileTags);
// write source file specific tags
if (!sourceFileTags.empty()) {
- hasFlags = true;
- (*this->BuildFileStream) << firstString;
- firstString = "";
- for (CsPropMap::const_iterator i = sourceFileTags.begin();
- i != sourceFileTags.end(); ++i) {
- this->WriteString("<", 3);
- (*this->BuildFileStream)
- << i->first << ">" << cmVS10EscapeXML(i->second) << "</" << i->first
- << ">\n";
- }
+ this->WriteCSharpSourceProperties(e2, sourceFileTags);
}
}
-
- return hasFlags;
}
void cmVisualStudio10TargetGenerator::WriteExcludeFromBuild(
- std::vector<size_t> const& exclude_configs)
+ Elem& e2, std::vector<size_t> const& exclude_configs)
{
- for (std::vector<size_t>::const_iterator ci = exclude_configs.begin();
- ci != exclude_configs.end(); ++ci) {
- this->WriteString("", 3);
- (*this->BuildFileStream)
- << "<ExcludedFromBuild Condition=\"'$(Configuration)|$(Platform)'=='"
- << cmVS10EscapeXML(this->Configurations[*ci]) << "|"
- << cmVS10EscapeXML(this->Platform) << "'\">true</ExcludedFromBuild>\n";
+ for (size_t ci : exclude_configs) {
+ e2.WritePlatformConfigTag("ExcludedFromBuild",
+ "'$(Configuration)|$(Platform)'=='" +
+ this->Configurations[ci] + "|" +
+ this->Platform + "'",
+ "true");
}
}
-void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
+void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions(
+ Elem& e0)
{
cmStateEnums::TargetType ttype = this->GeneratorTarget->GetType();
if (ttype > cmStateEnums::GLOBAL_TARGET) {
return;
}
- if (csproj == this->ProjectType) {
+ if (this->ProjectType == csproj) {
return;
}
- this->WriteString("<PropertyGroup>\n", 1);
- this->WriteString("<_ProjectFileVersion>10.0.20506.1"
- "</_ProjectFileVersion>\n",
- 2);
- for (std::vector<std::string>::const_iterator config =
- this->Configurations.begin();
- config != this->Configurations.end(); ++config) {
+ Elem e1(e0, "PropertyGroup");
+ e1.Element("_ProjectFileVersion", "10.0.20506.1");
+ for (std::string const& config : this->Configurations) {
+ const std::string cond = this->CalcCondition(config);
+
+ if (ttype <= cmStateEnums::UTILITY) {
+ if (const char* workingDir = this->GeneratorTarget->GetProperty(
+ "VS_DEBUGGER_WORKING_DIRECTORY")) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(workingDir);
+ std::string genWorkingDir =
+ cge->Evaluate(this->LocalGenerator, config);
+
+ e1.WritePlatformConfigTag("LocalDebuggerWorkingDirectory", cond,
+ genWorkingDir);
+ }
+
+ if (const char* environment =
+ this->GeneratorTarget->GetProperty("VS_DEBUGGER_ENVIRONMENT")) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(environment);
+ std::string genEnvironment =
+ cge->Evaluate(this->LocalGenerator, config);
+
+ e1.WritePlatformConfigTag("LocalDebuggerEnvironment", cond,
+ genEnvironment);
+ }
+
+ if (const char* debuggerCommand =
+ this->GeneratorTarget->GetProperty("VS_DEBUGGER_COMMAND")) {
+
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(debuggerCommand);
+ std::string genDebuggerCommand =
+ cge->Evaluate(this->LocalGenerator, config);
+
+ e1.WritePlatformConfigTag("LocalDebuggerCommand", cond,
+ genDebuggerCommand);
+ }
+
+ if (const char* commandArguments = this->GeneratorTarget->GetProperty(
+ "VS_DEBUGGER_COMMAND_ARGUMENTS")) {
+ cmGeneratorExpression ge;
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
+ ge.Parse(commandArguments);
+ std::string genCommandArguments =
+ cge->Evaluate(this->LocalGenerator, config);
+
+ e1.WritePlatformConfigTag("LocalDebuggerCommandArguments", cond,
+ genCommandArguments);
+ }
+ }
+
if (ttype >= cmStateEnums::UTILITY) {
- this->WritePlatformConfigTag("IntDir", config->c_str(), 2);
- *this->BuildFileStream
- << "$(Platform)\\$(Configuration)\\$(ProjectName)\\"
- << "</IntDir>\n";
+ e1.WritePlatformConfigTag(
+ "IntDir", cond, "$(Platform)\\$(Configuration)\\$(ProjectName)\\");
} else {
std::string intermediateDir =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
intermediateDir += "/";
- intermediateDir += *config;
+ intermediateDir += config;
intermediateDir += "/";
std::string outDir;
std::string targetNameFull;
@@ -2098,31 +2445,57 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
targetNameFull = this->GeneratorTarget->GetName();
targetNameFull += ".lib";
} else {
- outDir = this->GeneratorTarget->GetDirectory(config->c_str()) + "/";
- targetNameFull = this->GeneratorTarget->GetFullName(config->c_str());
+ outDir = this->GeneratorTarget->GetDirectory(config) + "/";
+ targetNameFull = this->GeneratorTarget->GetFullName(config);
}
- this->ConvertToWindowsSlash(intermediateDir);
- this->ConvertToWindowsSlash(outDir);
+ ConvertToWindowsSlash(intermediateDir);
+ ConvertToWindowsSlash(outDir);
- this->WritePlatformConfigTag("OutDir", config->c_str(), 2);
- *this->BuildFileStream << cmVS10EscapeXML(outDir) << "</OutDir>\n";
+ e1.WritePlatformConfigTag("OutDir", cond, outDir);
- this->WritePlatformConfigTag("IntDir", config->c_str(), 2);
- *this->BuildFileStream << cmVS10EscapeXML(intermediateDir)
- << "</IntDir>\n";
+ e1.WritePlatformConfigTag("IntDir", cond, intermediateDir);
- if (const char* workingDir = this->GeneratorTarget->GetProperty(
- "VS_DEBUGGER_WORKING_DIRECTORY")) {
- this->WritePlatformConfigTag("LocalDebuggerWorkingDirectory",
- config->c_str(), 2);
- *this->BuildFileStream << cmVS10EscapeXML(workingDir)
- << "</LocalDebuggerWorkingDirectory>\n";
+ if (const char* sdkExecutableDirectories = this->Makefile->GetDefinition(
+ "CMAKE_VS_SDK_EXECUTABLE_DIRECTORIES")) {
+ e1.WritePlatformConfigTag("ExecutablePath", cond,
+ sdkExecutableDirectories);
+ }
+
+ if (const char* sdkIncludeDirectories = this->Makefile->GetDefinition(
+ "CMAKE_VS_SDK_INCLUDE_DIRECTORIES")) {
+ e1.WritePlatformConfigTag("IncludePath", cond, sdkIncludeDirectories);
+ }
+
+ if (const char* sdkReferenceDirectories = this->Makefile->GetDefinition(
+ "CMAKE_VS_SDK_REFERENCE_DIRECTORIES")) {
+ e1.WritePlatformConfigTag("ReferencePath", cond,
+ sdkReferenceDirectories);
+ }
+
+ if (const char* sdkLibraryDirectories = this->Makefile->GetDefinition(
+ "CMAKE_VS_SDK_LIBRARY_DIRECTORIES")) {
+ e1.WritePlatformConfigTag("LibraryPath", cond, sdkLibraryDirectories);
+ }
+
+ if (const char* sdkLibraryWDirectories = this->Makefile->GetDefinition(
+ "CMAKE_VS_SDK_LIBRARY_WINRT_DIRECTORIES")) {
+ e1.WritePlatformConfigTag("LibraryWPath", cond,
+ sdkLibraryWDirectories);
+ }
+
+ if (const char* sdkSourceDirectories =
+ this->Makefile->GetDefinition("CMAKE_VS_SDK_SOURCE_DIRECTORIES")) {
+ e1.WritePlatformConfigTag("SourcePath", cond, sdkSourceDirectories);
+ }
+
+ if (const char* sdkExcludeDirectories = this->Makefile->GetDefinition(
+ "CMAKE_VS_SDK_EXCLUDE_DIRECTORIES")) {
+ e1.WritePlatformConfigTag("ExcludePath", cond, sdkExcludeDirectories);
}
std::string name =
cmSystemTools::GetFilenameWithoutLastExtension(targetNameFull);
- this->WritePlatformConfigTag("TargetName", config->c_str(), 2);
- *this->BuildFileStream << cmVS10EscapeXML(name) << "</TargetName>\n";
+ e1.WritePlatformConfigTag("TargetName", cond, name);
std::string ext =
cmSystemTools::GetFilenameLastExtension(targetNameFull);
@@ -2131,22 +2504,20 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions()
// A single "." appears to be treated as an empty extension.
ext = ".";
}
- this->WritePlatformConfigTag("TargetExt", config->c_str(), 2);
- *this->BuildFileStream << cmVS10EscapeXML(ext) << "</TargetExt>\n";
+ e1.WritePlatformConfigTag("TargetExt", cond, ext);
- this->OutputLinkIncremental(*config);
+ this->OutputLinkIncremental(e1, config);
}
}
- this->WriteString("</PropertyGroup>\n", 1);
}
void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
- std::string const& configName)
+ Elem& e1, std::string const& configName)
{
if (!this->MSTools) {
return;
}
- if (csproj == this->ProjectType) {
+ if (this->ProjectType == csproj) {
return;
}
// static libraries and things greater than modules do not need
@@ -2156,17 +2527,18 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
return;
}
Options& linkOptions = *(this->LinkOptions[configName]);
+ const std::string cond = this->CalcCondition(configName);
- const char* incremental = linkOptions.GetFlag("LinkIncremental");
- this->WritePlatformConfigTag("LinkIncremental", configName.c_str(), 2);
- *this->BuildFileStream << (incremental ? incremental : "true")
- << "</LinkIncremental>\n";
+ if (this->IPOEnabledConfigurations.count(configName) == 0) {
+ const char* incremental = linkOptions.GetFlag("LinkIncremental");
+ e1.WritePlatformConfigTag("LinkIncremental", cond,
+ (incremental ? incremental : "true"));
+ }
linkOptions.RemoveFlag("LinkIncremental");
const char* manifest = linkOptions.GetFlag("GenerateManifest");
- this->WritePlatformConfigTag("GenerateManifest", configName.c_str(), 2);
- *this->BuildFileStream << (manifest ? manifest : "true")
- << "</GenerateManifest>\n";
+ e1.WritePlatformConfigTag("GenerateManifest", cond,
+ (manifest ? manifest : "true"));
linkOptions.RemoveFlag("GenerateManifest");
// Some link options belong here. Use them now and remove them so that
@@ -2175,19 +2547,28 @@ void cmVisualStudio10TargetGenerator::OutputLinkIncremental(
for (const char** f = flags; *f; ++f) {
const char* flag = *f;
if (const char* value = linkOptions.GetFlag(flag)) {
- this->WritePlatformConfigTag(flag, configName.c_str(), 2);
- *this->BuildFileStream << value << "</" << flag << ">\n";
+ e1.WritePlatformConfigTag(flag, cond, value);
linkOptions.RemoveFlag(flag);
}
}
}
+std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes(
+ std::string const& config, std::string const& lang) const
+{
+ std::vector<std::string> includes;
+ this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
+ lang, config);
+ for (std::string& i : includes) {
+ ConvertToWindowsSlash(i);
+ }
+ return includes;
+}
+
bool cmVisualStudio10TargetGenerator::ComputeClOptions()
{
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeClOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeClOptions(c)) {
return false;
}
}
@@ -2201,62 +2582,52 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
// copied from cmLocalVisualStudio7Generator.cxx 805
// TODO: Integrate code below with cmLocalVisualStudio7Generator.
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- CM_AUTO_PTR<Options> pOptions;
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ std::unique_ptr<Options> pOptions;
switch (this->ProjectType) {
case vcxproj:
- pOptions = CM_AUTO_PTR<Options>(new Options(
- this->LocalGenerator, Options::Compiler, gg->GetClFlagTable()));
+ pOptions = cm::make_unique<Options>(
+ this->LocalGenerator, Options::Compiler, gg->GetClFlagTable());
break;
case csproj:
- pOptions = CM_AUTO_PTR<Options>(new Options(this->LocalGenerator,
- Options::CSharpCompiler,
- gg->GetCSharpFlagTable()));
+ pOptions =
+ cm::make_unique<Options>(this->LocalGenerator, Options::CSharpCompiler,
+ gg->GetCSharpFlagTable());
break;
}
Options& clOptions = *pOptions;
std::string flags;
const std::string& linkLanguage =
- this->GeneratorTarget->GetLinkerLanguage(configName.c_str());
+ this->GeneratorTarget->GetLinkerLanguage(configName);
if (linkLanguage.empty()) {
cmSystemTools::Error(
- "CMake can not determine linker language for target: ",
- this->Name.c_str());
+ "CMake can not determine linker language for target: " + this->Name);
return false;
}
// Choose a language whose flags to use for ClCompile.
- static const char* clLangs[] = { "CXX", "C", "Fortran", "CSharp" };
+ static const char* clLangs[] = { "CXX", "C", "Fortran" };
std::string langForClCompile;
- if (std::find(cmArrayBegin(clLangs), cmArrayEnd(clLangs), linkLanguage) !=
- cmArrayEnd(clLangs)) {
+ if (this->ProjectType == csproj) {
+ langForClCompile = "CSharp";
+ } else if (std::find(cm::cbegin(clLangs), cm::cend(clLangs), linkLanguage) !=
+ cm::cend(clLangs)) {
langForClCompile = linkLanguage;
} else {
std::set<std::string> languages;
this->GeneratorTarget->GetLanguages(languages, configName);
- for (const char* const* l = cmArrayBegin(clLangs);
- l != cmArrayEnd(clLangs); ++l) {
- if (languages.find(*l) != languages.end()) {
- langForClCompile = *l;
+ for (const char* l : clLangs) {
+ if (languages.count(l)) {
+ langForClCompile = l;
break;
}
}
}
+ this->LangForClCompile = langForClCompile;
if (!langForClCompile.empty()) {
- std::string baseFlagVar = "CMAKE_";
- baseFlagVar += langForClCompile;
- baseFlagVar += "_FLAGS";
- flags =
- this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
- baseFlagVar.c_str());
- std::string flagVar =
- baseFlagVar + std::string("_") + cmSystemTools::UpperCase(configName);
- flags += " ";
- flags +=
- this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
- flagVar.c_str());
+ this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
+ langForClCompile, configName);
this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget,
langForClCompile, configName);
}
@@ -2268,34 +2639,85 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
clOptions.AddFlag("CompileAs", "CompileAsCpp");
}
- // Check IPO related warning/error.
- this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName);
+ // Put the IPO enabled configurations into a set.
+ if (this->GeneratorTarget->IsIPOEnabled(linkLanguage, configName)) {
+ this->IPOEnabledConfigurations.insert(configName);
+ }
// Get preprocessor definitions for this directory.
- std::string defineFlags =
- this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
+ std::string defineFlags = this->Makefile->GetDefineFlags();
if (this->MSTools) {
- if (vcxproj == this->ProjectType) {
+ if (this->ProjectType == vcxproj) {
clOptions.FixExceptionHandlingDefault();
+ if (this->GlobalGenerator->GetVersion() >=
+ cmGlobalVisualStudioGenerator::VS15) {
+ // Toolsets that come with VS 2017 may now enable UseFullPaths
+ // by default and there is no negative /FC option that projects
+ // can use to switch it back. Older toolsets disable this by
+ // default anyway so this will not hurt them. If the project
+ // is using an explicit /FC option then parsing flags will
+ // replace this setting with "true" below.
+ clOptions.AddFlag("UseFullPaths", "false");
+ }
clOptions.AddFlag("PrecompiledHeader", "NotUsing");
- std::string asmLocation = configName + "/";
- clOptions.AddFlag("AssemblerListingLocation", asmLocation.c_str());
+ clOptions.AddFlag("AssemblerListingLocation", "$(IntDir)");
}
}
- clOptions.Parse(flags.c_str());
- clOptions.Parse(defineFlags.c_str());
+
+ // check for managed C++ assembly compiler flag. This overrides any
+ // /clr* compiler flags which may be defined in the flags variable(s).
+ if (this->ProjectType != csproj) {
+ // Warn if /clr was added manually. This should not be done
+ // anymore, because cmGeneratorTarget may not be aware that the
+ // target uses C++/CLI.
+ if (flags.find("/clr") != std::string::npos ||
+ defineFlags.find("/clr") != std::string::npos) {
+ if (configName == this->Configurations[0]) {
+ std::string message = "For the target \"" +
+ this->GeneratorTarget->GetName() +
+ "\" the /clr compiler flag was added manually. " +
+ "Set usage of C++/CLI by setting COMMON_LANGUAGE_RUNTIME "
+ "target property.";
+ this->Makefile->IssueMessage(MessageType::WARNING, message);
+ }
+ }
+ if (auto* clr =
+ this->GeneratorTarget->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
+ std::string clrString = clr;
+ if (!clrString.empty()) {
+ clrString = ":" + clrString;
+ }
+ flags += " /clr" + clrString;
+ }
+ }
+
+ clOptions.Parse(flags);
+ clOptions.Parse(defineFlags);
std::vector<std::string> targetDefines;
switch (this->ProjectType) {
case vcxproj:
- this->GeneratorTarget->GetCompileDefinitions(targetDefines,
- configName.c_str(), "CXX");
+ if (!langForClCompile.empty()) {
+ this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
+ langForClCompile);
+ }
break;
case csproj:
- this->GeneratorTarget->GetCompileDefinitions(
- targetDefines, configName.c_str(), "CSharp");
+ this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
+ "CSharp");
break;
}
clOptions.AddDefines(targetDefines);
+
+ if (this->ProjectType == csproj) {
+ clOptions.AppendFlag("DefineConstants", targetDefines);
+ }
+
+ // Get includes for this target
+ if (!this->LangForClCompile.empty()) {
+ clOptions.AddIncludes(
+ this->GetIncludes(configName, this->LangForClCompile));
+ }
+
if (this->MSTools) {
clOptions.SetVerboseMakefile(
this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE"));
@@ -2306,13 +2728,16 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
configDefine += configName;
configDefine += "\"";
clOptions.AddDefine(configDefine);
- if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
- clOptions.AddDefine(exportMacro);
+ if (const std::string* exportMacro =
+ this->GeneratorTarget->GetExportMacro()) {
+ clOptions.AddDefine(*exportMacro);
}
if (this->MSTools) {
- // If we have the VS_WINRT_COMPONENT set then force Compile as WinRT.
- if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT")) {
+ // If we have the VS_WINRT_COMPONENT or CMAKE_VS_WINRT_BY_DEFAULT
+ // set then force Compile as WinRT.
+ if (this->GeneratorTarget->GetPropertyAsBool("VS_WINRT_COMPONENT") ||
+ this->Makefile->IsOn("CMAKE_VS_WINRT_BY_DEFAULT")) {
clOptions.AddFlag("CompileAsWinRT", "true");
// For WinRT components, add the _WINRT_DLL define to produce a lib
if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
@@ -2332,85 +2757,106 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions(
}
}
- if (csproj != this->ProjectType && clOptions.IsManaged()) {
+ if (this->ProjectType != csproj && clOptions.IsManaged()) {
this->Managed = true;
std::string managedType = clOptions.GetFlag("CompileAsManaged");
- if (managedType == "Safe") {
+ if (managedType == "Safe" || managedType == "Pure") {
// force empty calling convention if safe clr is used
clOptions.AddFlag("CallingConvention", "");
}
+ // The default values of these flags are incompatible to
+ // managed assemblies. We have to force valid values if
+ // the target is a managed C++ target.
+ clOptions.AddFlag("ExceptionHandling", "Async");
+ clOptions.AddFlag("BasicRuntimeChecks", "Default");
+ }
+ if (this->ProjectType == csproj) {
+ // /nowin32manifest overrides /win32manifest: parameter
+ if (clOptions.HasFlag("NoWin32Manifest")) {
+ clOptions.RemoveFlag("ApplicationManifest");
+ }
}
- this->ClOptions[configName] = pOptions.release();
+ if (const char* s = clOptions.GetFlag("SpectreMitigation")) {
+ this->SpectreMitigation[configName] = s;
+ clOptions.RemoveFlag("SpectreMitigation");
+ }
+
+ this->ClOptions[configName] = std::move(pOptions);
return true;
}
void cmVisualStudio10TargetGenerator::WriteClOptions(
- std::string const& configName, std::vector<std::string> const& includes)
+ Elem& e1, std::string const& configName)
{
Options& clOptions = *(this->ClOptions[configName]);
if (this->ProjectType == csproj) {
return;
}
- this->WriteString("<ClCompile>\n", 2);
- clOptions.PrependInheritedString("AdditionalOptions");
- clOptions.AppendFlag("AdditionalIncludeDirectories", includes);
- clOptions.AppendFlag("AdditionalIncludeDirectories",
- "%(AdditionalIncludeDirectories)");
- clOptions.OutputFlagMap(*this->BuildFileStream, " ");
- clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
- "\n", "CXX");
+ Elem e2(e1, "ClCompile");
+ OptionsHelper oh(clOptions, e2);
+ oh.PrependInheritedString("AdditionalOptions");
+ oh.OutputAdditionalIncludeDirectories(this->LangForClCompile);
+ oh.OutputFlagMap();
+ oh.OutputPreprocessorDefinitions(this->LangForClCompile);
if (this->NsightTegra) {
if (const char* processMax =
this->GeneratorTarget->GetProperty("ANDROID_PROCESS_MAX")) {
- this->WriteString("<ProcessMax>", 3);
- *this->BuildFileStream << cmVS10EscapeXML(processMax)
- << "</ProcessMax>\n";
+ e2.Element("ProcessMax", processMax);
}
}
if (this->MSTools) {
- cmsys::RegularExpression clangToolset(
- "(v[0-9]+_clang_.*|LLVM-vs[0-9]+.*)");
+ cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*");
const char* toolset = this->GlobalGenerator->GetPlatformToolset();
if (toolset && clangToolset.find(toolset)) {
- this->WriteString("<ObjectFileName>"
- "$(IntDir)%(filename).obj"
- "</ObjectFileName>\n",
- 3);
+ e2.Element("ObjectFileName", "$(IntDir)%(filename).obj");
} else {
- this->WriteString("<ObjectFileName>$(IntDir)</ObjectFileName>\n", 3);
+ e2.Element("ObjectFileName", "$(IntDir)");
}
// If not in debug mode, write the DebugInformationFormat field
- // without value so PDBs don't get generated uselessly.
+ // without value so PDBs don't get generated uselessly. Each tag
+ // goes on its own line because Visual Studio corrects it this
+ // way when saving the project after CMake generates it.
if (!clOptions.IsDebug()) {
- this->WriteString("<DebugInformationFormat>"
- "</DebugInformationFormat>\n",
- 3);
+ Elem e3(e2, "DebugInformationFormat");
+ e3.SetHasElements();
}
// Specify the compiler program database file if configured.
- std::string pdb =
- this->GeneratorTarget->GetCompilePDBPath(configName.c_str());
+ std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
if (!pdb.empty()) {
- this->ConvertToWindowsSlash(pdb);
- this->WriteString("<ProgramDataBaseFileName>", 3);
- *this->BuildFileStream << cmVS10EscapeXML(pdb)
- << "</ProgramDataBaseFileName>\n";
+ if (this->GlobalGenerator->IsCudaEnabled()) {
+ // CUDA does not quote paths with spaces correctly when forwarding
+ // this to the host compiler. Use a relative path to avoid spaces.
+ // FIXME: We can likely do this even when CUDA is not involved,
+ // but for now we will make a minimal change.
+ pdb = this->ConvertPath(pdb, true);
+ }
+ ConvertToWindowsSlash(pdb);
+ e2.Element("ProgramDataBaseFileName", pdb);
}
- }
- this->WriteString("</ClCompile>\n", 2);
+ // add AdditionalUsingDirectories
+ if (this->AdditionalUsingDirectories.count(configName) > 0) {
+ std::string dirs;
+ for (auto u : this->AdditionalUsingDirectories[configName]) {
+ if (!dirs.empty()) {
+ dirs.append(";");
+ }
+ dirs.append(u);
+ }
+ e2.Element("AdditionalUsingDirectories", dirs);
+ }
+ }
}
bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
{
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeRcOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeRcOptions(c)) {
return false;
}
}
@@ -2420,47 +2866,42 @@ bool cmVisualStudio10TargetGenerator::ComputeRcOptions()
bool cmVisualStudio10TargetGenerator::ComputeRcOptions(
std::string const& configName)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- CM_AUTO_PTR<Options> pOptions(new Options(
- this->LocalGenerator, Options::ResourceCompiler, gg->GetRcFlagTable()));
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ auto pOptions = cm::make_unique<Options>(
+ this->LocalGenerator, Options::ResourceCompiler, gg->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));
+ std::string rcConfigFlagsVar = "CMAKE_RC_FLAGS_" + CONFIG;
+ std::string flags = this->Makefile->GetSafeDefinition("CMAKE_RC_FLAGS") +
+ " " + this->Makefile->GetSafeDefinition(rcConfigFlagsVar);
- rcOptions.Parse(flags.c_str());
+ rcOptions.Parse(flags);
// For historical reasons, add the C preprocessor defines to RC.
Options& clOptions = *(this->ClOptions[configName]);
rcOptions.AddDefines(clOptions.GetDefines());
- this->RcOptions[configName] = pOptions.release();
+ // Get includes for this target
+ rcOptions.AddIncludes(this->GetIncludes(configName, "RC"));
+
+ this->RcOptions[configName] = std::move(pOptions);
return true;
}
void cmVisualStudio10TargetGenerator::WriteRCOptions(
- std::string const& configName, std::vector<std::string> const& includes)
+ Elem& e1, std::string const& configName)
{
if (!this->MSTools) {
return;
}
- this->WriteString("<ResourceCompile>\n", 2);
+ Elem e2(e1, "ResourceCompile");
- Options& rcOptions = *(this->RcOptions[configName]);
- rcOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
- "\n", "RC");
- rcOptions.AppendFlag("AdditionalIncludeDirectories", includes);
- rcOptions.AppendFlag("AdditionalIncludeDirectories",
- "%(AdditionalIncludeDirectories)");
+ OptionsHelper rcOptions(*(this->RcOptions[configName]), e2);
+ rcOptions.OutputPreprocessorDefinitions("RC");
+ rcOptions.OutputAdditionalIncludeDirectories("RC");
rcOptions.PrependInheritedString("AdditionalOptions");
- rcOptions.OutputFlagMap(*this->BuildFileStream, " ");
-
- this->WriteString("</ResourceCompile>\n", 2);
+ rcOptions.OutputFlagMap();
}
bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
@@ -2468,10 +2909,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
if (!this->GlobalGenerator->IsCudaEnabled()) {
return true;
}
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeCudaOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeCudaOptions(c)) {
return false;
}
}
@@ -2481,30 +2920,37 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions()
bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
std::string const& configName)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- CM_AUTO_PTR<Options> pOptions(new Options(
- this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()));
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ auto pOptions = cm::make_unique<Options>(
+ this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
Options& cudaOptions = *pOptions;
// Get compile flags for CUDA in this directory.
- std::string CONFIG = cmSystemTools::UpperCase(configName);
- std::string configFlagsVar = std::string("CMAKE_CUDA_FLAGS_") + CONFIG;
- std::string flags =
- std::string(this->Makefile->GetSafeDefinition("CMAKE_CUDA_FLAGS")) +
- std::string(" ") +
- std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
+ std::string flags;
+ this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget, "CUDA",
+ configName);
this->LocalGenerator->AddCompileOptions(flags, this->GeneratorTarget, "CUDA",
configName);
// Get preprocessor definitions for this directory.
- std::string defineFlags =
- this->GeneratorTarget->Target->GetMakefile()->GetDefineFlags();
+ std::string defineFlags = this->Makefile->GetDefineFlags();
- cudaOptions.Parse(flags.c_str());
- cudaOptions.Parse(defineFlags.c_str());
+ cudaOptions.Parse(flags);
+ cudaOptions.Parse(defineFlags);
cudaOptions.ParseFinish();
+ // If we haven't explicitly enabled GPU debug information
+ // explicitly disable it
+ if (!cudaOptions.HasFlag("GPUDebugInfo")) {
+ cudaOptions.AddFlag("GPUDebugInfo", "false");
+ }
+
+ // The extension on object libraries the CUDA gives isn't
+ // consistent with how MSVC generates object libraries for C+, so set
+ // the default to not have any extension
+ cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).obj");
+
+ bool notPtx = true;
if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
} else if (this->GeneratorTarget->GetPropertyAsBool(
@@ -2513,6 +2959,41 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
// We drop the %(Extension) component as CMake expects all PTX files
// to not have the source file extension at all
cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).ptx");
+ notPtx = false;
+ }
+
+ if (notPtx &&
+ cmSystemTools::VersionCompareGreaterEq(
+ "8.0", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
+ // Explicitly state that we want this file to be treated as a
+ // CUDA file no matter what the file extensions is
+ // This is only needed for < CUDA 9
+ cudaOptions.AppendFlagString("AdditionalOptions", "-x cu");
+ }
+
+ // Specify the compiler program database file if configured.
+ std::string pdb = this->GeneratorTarget->GetCompilePDBPath(configName);
+ if (!pdb.empty()) {
+ // CUDA does not make the directory if it is non-standard.
+ std::string const pdbDir = cmSystemTools::GetFilenamePath(pdb);
+ cmSystemTools::MakeDirectory(pdbDir);
+ if (cmSystemTools::VersionCompareGreaterEq(
+ "9.2", this->GlobalGenerator->GetPlatformToolsetCudaString())) {
+ // CUDA does not have a field for this and does not honor the
+ // ProgramDataBaseFileName field in ClCompile. Work around this
+ // limitation by creating the directory and passing the flag ourselves.
+ pdb = this->ConvertPath(pdb, true);
+ ConvertToWindowsSlash(pdb);
+ std::string const clFd = "-Xcompiler=\"-Fd\\\"" + pdb + "\\\"\"";
+ cudaOptions.AppendFlagString("AdditionalOptions", clFd);
+ }
+ }
+
+ // CUDA automatically passes the proper '--machine' flag to nvcc
+ // for the current architecture, but does not reflect this default
+ // in the user-visible IDE settings. Set it explicitly.
+ if (this->Platform == "x64") {
+ cudaOptions.AddFlag("TargetMachinePlatform", "64");
}
// Convert the host compiler options to the toolset's abstractions
@@ -2535,8 +3016,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
cudaOptions.FixCudaCodeGeneration();
std::vector<std::string> targetDefines;
- this->GeneratorTarget->GetCompileDefinitions(targetDefines,
- configName.c_str(), "CUDA");
+ this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName,
+ "CUDA");
cudaOptions.AddDefines(targetDefines);
// Add a definition for the configuration name.
@@ -2544,31 +3025,32 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
configDefine += configName;
configDefine += "\"";
cudaOptions.AddDefine(configDefine);
- if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
- cudaOptions.AddDefine(exportMacro);
+ if (const std::string* exportMacro =
+ this->GeneratorTarget->GetExportMacro()) {
+ cudaOptions.AddDefine(*exportMacro);
}
- this->CudaOptions[configName] = pOptions.release();
+ // Get includes for this target
+ cudaOptions.AddIncludes(this->GetIncludes(configName, "CUDA"));
+ cudaOptions.AddFlag("UseHostInclude", "false");
+
+ this->CudaOptions[configName] = std::move(pOptions);
return true;
}
void cmVisualStudio10TargetGenerator::WriteCudaOptions(
- std::string const& configName, std::vector<std::string> const& includes)
+ Elem& e1, std::string const& configName)
{
if (!this->MSTools || !this->GlobalGenerator->IsCudaEnabled()) {
return;
}
- this->WriteString("<CudaCompile>\n", 2);
+ Elem e2(e1, "CudaCompile");
- Options& cudaOptions = *(this->CudaOptions[configName]);
- cudaOptions.AppendFlag("Include", includes);
- cudaOptions.AppendFlag("Include", "%(Include)");
- cudaOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
- "\n", "CUDA");
+ OptionsHelper cudaOptions(*(this->CudaOptions[configName]), e2);
+ cudaOptions.OutputAdditionalIncludeDirectories("CUDA");
+ cudaOptions.OutputPreprocessorDefinitions("CUDA");
cudaOptions.PrependInheritedString("AdditionalOptions");
- cudaOptions.OutputFlagMap(*this->BuildFileStream, " ");
-
- this->WriteString("</CudaCompile>\n", 2);
+ cudaOptions.OutputFlagMap();
}
bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
@@ -2576,10 +3058,8 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
if (!this->GlobalGenerator->IsCudaEnabled()) {
return true;
}
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeCudaLinkOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeCudaLinkOptions(c)) {
return false;
}
}
@@ -2589,27 +3069,14 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions()
bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
std::string const& configName)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- CM_AUTO_PTR<Options> pOptions(new Options(
- this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable()));
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ auto pOptions = cm::make_unique<Options>(
+ this->LocalGenerator, Options::CudaCompiler, gg->GetCudaFlagTable());
Options& cudaLinkOptions = *pOptions;
// Determine if we need to do a device link
- bool doDeviceLinking = false;
- switch (this->GeneratorTarget->GetType()) {
- case cmStateEnums::SHARED_LIBRARY:
- case cmStateEnums::MODULE_LIBRARY:
- case cmStateEnums::EXECUTABLE:
- doDeviceLinking = true;
- break;
- case cmStateEnums::STATIC_LIBRARY:
- doDeviceLinking = this->GeneratorTarget->GetPropertyAsBool(
- "CUDA_RESOLVE_DEVICE_SYMBOLS");
- break;
- default:
- break;
- }
+ const bool doDeviceLinking = requireDeviceLinking(
+ *this->GeneratorTarget, *this->LocalGenerator, configName);
cudaLinkOptions.AddFlag("PerformDeviceLink",
doDeviceLinking ? "true" : "false");
@@ -2621,12 +3088,12 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions(
"-Wno-deprecated-gpu-targets");
}
- this->CudaLinkOptions[configName] = pOptions.release();
+ this->CudaLinkOptions[configName] = std::move(pOptions);
return true;
}
void cmVisualStudio10TargetGenerator::WriteCudaLinkOptions(
- std::string const& configName)
+ Elem& e1, std::string const& configName)
{
if (this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
return;
@@ -2636,10 +3103,9 @@ void cmVisualStudio10TargetGenerator::WriteCudaLinkOptions(
return;
}
- this->WriteString("<CudaLink>\n", 2);
- Options& cudaLinkOptions = *(this->CudaLinkOptions[configName]);
- cudaLinkOptions.OutputFlagMap(*this->BuildFileStream, " ");
- this->WriteString("</CudaLink>\n", 2);
+ Elem e2(e1, "CudaLink");
+ OptionsHelper cudaLinkOptions(*(this->CudaLinkOptions[configName]), e2);
+ cudaLinkOptions.OutputFlagMap();
}
bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
@@ -2647,10 +3113,8 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
if (!this->GlobalGenerator->IsMasmEnabled()) {
return true;
}
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeMasmOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeMasmOptions(c)) {
return false;
}
}
@@ -2660,44 +3124,40 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions()
bool cmVisualStudio10TargetGenerator::ComputeMasmOptions(
std::string const& configName)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- CM_AUTO_PTR<Options> pOptions(new Options(
- this->LocalGenerator, Options::MasmCompiler, gg->GetMasmFlagTable()));
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ auto pOptions = cm::make_unique<Options>(
+ this->LocalGenerator, Options::MasmCompiler, gg->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();
+ std::string flags;
+ this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
+ "ASM_MASM", configName);
+
+ masmOptions.Parse(flags);
+
+ // Get includes for this target
+ masmOptions.AddIncludes(this->GetIncludes(configName, "ASM_MASM"));
+
+ this->MasmOptions[configName] = std::move(pOptions);
return true;
}
void cmVisualStudio10TargetGenerator::WriteMasmOptions(
- std::string const& configName, std::vector<std::string> const& includes)
+ Elem& e1, std::string const& configName)
{
if (!this->MSTools || !this->GlobalGenerator->IsMasmEnabled()) {
return;
}
- this->WriteString("<MASM>\n", 2);
+ Elem e2(e1, "MASM");
// Preprocessor definitions and includes are shared with clOptions.
- Options& clOptions = *(this->ClOptions[configName]);
- clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
- "\n", "ASM_MASM");
+ OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
+ clOptions.OutputPreprocessorDefinitions("ASM_MASM");
- Options& masmOptions = *(this->MasmOptions[configName]);
- masmOptions.AppendFlag("IncludePaths", includes);
- masmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
+ OptionsHelper masmOptions(*(this->MasmOptions[configName]), e2);
+ masmOptions.OutputAdditionalIncludeDirectories("ASM_MASM");
masmOptions.PrependInheritedString("AdditionalOptions");
- masmOptions.OutputFlagMap(*this->BuildFileStream, " ");
-
- this->WriteString("</MASM>\n", 2);
+ masmOptions.OutputFlagMap();
}
bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
@@ -2705,10 +3165,8 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
if (!this->GlobalGenerator->IsNasmEnabled()) {
return true;
}
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeNasmOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeNasmOptions(c)) {
return false;
}
}
@@ -2718,74 +3176,71 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions()
bool cmVisualStudio10TargetGenerator::ComputeNasmOptions(
std::string const& configName)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- CM_AUTO_PTR<Options> pOptions(new Options(
- this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable()));
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ auto pOptions = cm::make_unique<Options>(
+ this->LocalGenerator, Options::NasmCompiler, gg->GetNasmFlagTable());
Options& nasmOptions = *pOptions;
- std::string CONFIG = cmSystemTools::UpperCase(configName);
- std::string configFlagsVar = std::string("CMAKE_ASM_NASM_FLAGS_") + CONFIG;
- std::string flags =
- std::string(this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_FLAGS")) +
- std::string(" -f") + std::string(this->Makefile->GetSafeDefinition(
- "CMAKE_ASM_NASM_OBJECT_FORMAT")) +
- std::string(" ") +
- std::string(this->Makefile->GetSafeDefinition(configFlagsVar));
- nasmOptions.Parse(flags.c_str());
- this->NasmOptions[configName] = pOptions.release();
+ std::string flags;
+ this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
+ "ASM_NASM", configName);
+ flags += " -f";
+ flags += this->Makefile->GetSafeDefinition("CMAKE_ASM_NASM_OBJECT_FORMAT");
+ nasmOptions.Parse(flags);
+
+ // Get includes for this target
+ nasmOptions.AddIncludes(this->GetIncludes(configName, "ASM_NASM"));
+
+ this->NasmOptions[configName] = std::move(pOptions);
return true;
}
void cmVisualStudio10TargetGenerator::WriteNasmOptions(
- std::string const& configName, std::vector<std::string> includes)
+ Elem& e1, std::string const& configName)
{
if (!this->GlobalGenerator->IsNasmEnabled()) {
return;
}
- this->WriteString("<NASM>\n", 2);
+ Elem e2(e1, "NASM");
- Options& nasmOptions = *(this->NasmOptions[configName]);
- for (size_t i = 0; i < includes.size(); i++) {
- includes[i] += "\\";
- }
-
- nasmOptions.AppendFlag("IncludePaths", includes);
- nasmOptions.AppendFlag("IncludePaths", "%(IncludePaths)");
- nasmOptions.OutputFlagMap(*this->BuildFileStream, " ");
+ std::vector<std::string> includes =
+ this->GetIncludes(configName, "ASM_NASM");
+ OptionsHelper nasmOptions(*(this->NasmOptions[configName]), e2);
+ nasmOptions.OutputAdditionalIncludeDirectories("ASM_NASM");
+ nasmOptions.OutputFlagMap();
nasmOptions.PrependInheritedString("AdditionalOptions");
- nasmOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
- "\n", "ASM_NASM");
+ nasmOptions.OutputPreprocessorDefinitions("ASM_NASM");
// Preprocessor definitions and includes are shared with clOptions.
- Options& clOptions = *(this->ClOptions[configName]);
- clOptions.OutputPreprocessorDefinitions(*this->BuildFileStream, " ",
- "\n", "ASM_NASM");
-
- this->WriteString("</NASM>\n", 2);
+ OptionsHelper clOptions(*(this->ClOptions[configName]), e2);
+ clOptions.OutputPreprocessorDefinitions("ASM_NASM");
}
void cmVisualStudio10TargetGenerator::WriteLibOptions(
- std::string const& config)
+ Elem& e1, std::string const& config)
{
if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY &&
this->GeneratorTarget->GetType() != cmStateEnums::OBJECT_LIBRARY) {
return;
}
+
+ const std::string& linkLanguage =
+ this->GeneratorTarget->GetLinkClosure(config)->LinkerLanguage;
+
std::string libflags;
this->LocalGenerator->GetStaticLibraryFlags(
- libflags, cmSystemTools::UpperCase(config), this->GeneratorTarget);
+ libflags, cmSystemTools::UpperCase(config), linkLanguage,
+ this->GeneratorTarget);
if (!libflags.empty()) {
- this->WriteString("<Lib>\n", 2);
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- cmVisualStudioGeneratorOptions libOptions(
- this->LocalGenerator, cmVisualStudioGeneratorOptions::Linker,
- gg->GetLibFlagTable(), 0, this);
- libOptions.Parse(libflags.c_str());
- libOptions.PrependInheritedString("AdditionalOptions");
- libOptions.OutputFlagMap(*this->BuildFileStream, " ");
- this->WriteString("</Lib>\n", 2);
+ Elem e2(e1, "Lib");
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ cmVS10GeneratorOptions libOptions(this->LocalGenerator,
+ cmVisualStudioGeneratorOptions::Linker,
+ gg->GetLibFlagTable(), this);
+ libOptions.Parse(libflags);
+ OptionsHelper oh(libOptions, e2);
+ oh.PrependInheritedString("AdditionalOptions");
+ oh.OutputFlagMap();
}
// We cannot generate metadata for static libraries. WindowsPhone
@@ -2793,16 +3248,13 @@ void cmVisualStudio10TargetGenerator::WriteLibOptions(
// 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);
+ Elem e2(e1, "Link");
+ e2.Element("GenerateWindowsMetadata", "false");
}
}
void cmVisualStudio10TargetGenerator::WriteManifestOptions(
- std::string const& config)
+ Elem& e1, std::string const& config)
{
if (this->GeneratorTarget->GetType() != cmStateEnums::EXECUTABLE &&
this->GeneratorTarget->GetType() != cmStateEnums::SHARED_LIBRARY &&
@@ -2813,22 +3265,19 @@ void cmVisualStudio10TargetGenerator::WriteManifestOptions(
std::vector<cmSourceFile const*> manifest_srcs;
this->GeneratorTarget->GetManifests(manifest_srcs, config);
if (!manifest_srcs.empty()) {
- this->WriteString("<Manifest>\n", 2);
- this->WriteString("<AdditionalManifestFiles>", 3);
- for (std::vector<cmSourceFile const*>::const_iterator mi =
- manifest_srcs.begin();
- mi != manifest_srcs.end(); ++mi) {
- std::string m = this->ConvertPath((*mi)->GetFullPath(), false);
- this->ConvertToWindowsSlash(m);
- (*this->BuildFileStream) << m << ";";
- }
- (*this->BuildFileStream) << "</AdditionalManifestFiles>\n";
- this->WriteString("</Manifest>\n", 2);
+ std::ostringstream oss;
+ for (cmSourceFile const* mi : manifest_srcs) {
+ std::string m = this->ConvertPath(mi->GetFullPath(), false);
+ ConvertToWindowsSlash(m);
+ oss << m << ";";
+ }
+ Elem e2(e1, "Manifest");
+ e2.Element("AdditionalManifestFiles", oss.str());
}
}
void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
- std::string const& configName)
+ Elem& e1, std::string const& configName)
{
// Look through the sources for AndroidManifest.xml and use
// its location as the root source directory.
@@ -2836,123 +3285,98 @@ void cmVisualStudio10TargetGenerator::WriteAntBuildOptions(
{
std::vector<cmSourceFile const*> extraSources;
this->GeneratorTarget->GetExtraSources(extraSources, "");
- for (std::vector<cmSourceFile const*>::const_iterator si =
- extraSources.begin();
- si != extraSources.end(); ++si) {
+ for (cmSourceFile const* si : extraSources) {
if ("androidmanifest.xml" ==
- cmSystemTools::LowerCase((*si)->GetLocation().GetName())) {
- rootDir = (*si)->GetLocation().GetDirectory();
+ cmSystemTools::LowerCase(si->GetLocation().GetName())) {
+ rootDir = si->GetLocation().GetDirectory();
break;
}
}
}
// Tell MSBuild to launch Ant.
+ Elem e2(e1, "AntBuild");
{
std::string antBuildPath = rootDir;
- this->WriteString("<AntBuild>\n", 2);
- this->WriteString("<AntBuildPath>", 3);
- this->ConvertToWindowsSlash(antBuildPath);
- (*this->BuildFileStream) << cmVS10EscapeXML(antBuildPath)
- << "</AntBuildPath>\n";
+ ConvertToWindowsSlash(antBuildPath);
+ e2.Element("AntBuildPath", antBuildPath);
}
if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_SKIP_ANT_STEP")) {
- this->WriteString("<SkipAntStep>true</SkipAntStep>\n", 3);
+ e2.Element("SkipAntStep", "true");
}
if (this->GeneratorTarget->GetPropertyAsBool("ANDROID_PROGUARD")) {
- this->WriteString("<EnableProGuard>true</EnableProGuard>\n", 3);
+ e2.Element("EnableProGuard", "true");
}
if (const char* proGuardConfigLocation =
this->GeneratorTarget->GetProperty("ANDROID_PROGUARD_CONFIG_PATH")) {
- this->WriteString("<ProGuardConfigLocation>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(proGuardConfigLocation)
- << "</ProGuardConfigLocation>\n";
+ e2.Element("ProGuardConfigLocation", proGuardConfigLocation);
}
if (const char* securePropertiesLocation =
this->GeneratorTarget->GetProperty("ANDROID_SECURE_PROPS_PATH")) {
- this->WriteString("<SecurePropertiesLocation>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(securePropertiesLocation)
- << "</SecurePropertiesLocation>\n";
+ e2.Element("SecurePropertiesLocation", securePropertiesLocation);
}
if (const char* nativeLibDirectoriesExpression =
this->GeneratorTarget->GetProperty("ANDROID_NATIVE_LIB_DIRECTORIES")) {
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(nativeLibDirectoriesExpression);
std::string nativeLibDirs =
cge->Evaluate(this->LocalGenerator, configName);
- this->WriteString("<NativeLibDirectories>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDirs)
- << "</NativeLibDirectories>\n";
+ e2.Element("NativeLibDirectories", nativeLibDirs);
}
if (const char* nativeLibDependenciesExpression =
this->GeneratorTarget->GetProperty(
"ANDROID_NATIVE_LIB_DEPENDENCIES")) {
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(nativeLibDependenciesExpression);
std::string nativeLibDeps =
cge->Evaluate(this->LocalGenerator, configName);
- this->WriteString("<NativeLibDependencies>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(nativeLibDeps)
- << "</NativeLibDependencies>\n";
+ e2.Element("NativeLibDependencies", nativeLibDeps);
}
if (const char* javaSourceDir =
this->GeneratorTarget->GetProperty("ANDROID_JAVA_SOURCE_DIR")) {
- this->WriteString("<JavaSourceDir>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(javaSourceDir)
- << "</JavaSourceDir>\n";
+ e2.Element("JavaSourceDir", javaSourceDir);
}
if (const char* jarDirectoriesExpression =
this->GeneratorTarget->GetProperty("ANDROID_JAR_DIRECTORIES")) {
cmGeneratorExpression ge;
- CM_AUTO_PTR<cmCompiledGeneratorExpression> cge =
+ std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(jarDirectoriesExpression);
std::string jarDirectories =
cge->Evaluate(this->LocalGenerator, configName);
- this->WriteString("<JarDirectories>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(jarDirectories)
- << "</JarDirectories>\n";
+ e2.Element("JarDirectories", jarDirectories);
}
if (const char* jarDeps =
this->GeneratorTarget->GetProperty("ANDROID_JAR_DEPENDENCIES")) {
- this->WriteString("<JarDependencies>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(jarDeps)
- << "</JarDependencies>\n";
+ e2.Element("JarDependencies", jarDeps);
}
if (const char* assetsDirectories =
this->GeneratorTarget->GetProperty("ANDROID_ASSETS_DIRECTORIES")) {
- this->WriteString("<AssetsDirectories>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(assetsDirectories)
- << "</AssetsDirectories>\n";
+ e2.Element("AssetsDirectories", assetsDirectories);
}
{
std::string manifest_xml = rootDir + "/AndroidManifest.xml";
- this->ConvertToWindowsSlash(manifest_xml);
- this->WriteString("<AndroidManifestLocation>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(manifest_xml)
- << "</AndroidManifestLocation>\n";
+ ConvertToWindowsSlash(manifest_xml);
+ e2.Element("AndroidManifestLocation", manifest_xml);
}
if (const char* antAdditionalOptions =
this->GeneratorTarget->GetProperty("ANDROID_ANT_ADDITIONAL_OPTIONS")) {
- this->WriteString("<AdditionalOptions>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(antAdditionalOptions)
- << " %(AdditionalOptions)</AdditionalOptions>\n";
+ e2.Element("AdditionalOptions",
+ std::string(antAdditionalOptions) + " %(AdditionalOptions)");
}
-
- this->WriteString("</AntBuild>\n", 2);
}
bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
@@ -2960,10 +3384,8 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeLinkOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeLinkOptions(c)) {
return false;
}
}
@@ -2974,10 +3396,9 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions()
bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
std::string const& config)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
- CM_AUTO_PTR<Options> pOptions(new Options(
- this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), 0, this));
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
+ auto pOptions = cm::make_unique<Options>(
+ this->LocalGenerator, Options::Linker, gg->GetLinkFlagTable(), this);
Options& linkOptions = *pOptions;
cmGeneratorTarget::LinkClosure const* linkClosure =
@@ -2986,8 +3407,7 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
const std::string& linkLanguage = linkClosure->LinkerLanguage;
if (linkLanguage.empty()) {
cmSystemTools::Error(
- "CMake can not determine linker language for target: ",
- this->Name.c_str());
+ "CMake can not determine linker language for target: " + this->Name);
return false;
}
@@ -3005,12 +3425,10 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
linkFlagVarBase += linkType;
linkFlagVarBase += "_LINKER_FLAGS";
flags += " ";
- flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
- linkFlagVarBase.c_str());
+ flags += this->Makefile->GetRequiredDefinition(linkFlagVarBase);
std::string linkFlagVar = linkFlagVarBase + "_" + CONFIG;
flags += " ";
- flags += this->GeneratorTarget->Target->GetMakefile()->GetRequiredDefinition(
- linkFlagVar.c_str());
+ flags += this->Makefile->GetRequiredDefinition(linkFlagVar);
const char* targetLinkFlags =
this->GeneratorTarget->GetProperty("LINK_FLAGS");
if (targetLinkFlags) {
@@ -3020,31 +3438,39 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
std::string flagsProp = "LINK_FLAGS_";
flagsProp += CONFIG;
if (const char* flagsConfig =
- this->GeneratorTarget->GetProperty(flagsProp.c_str())) {
+ this->GeneratorTarget->GetProperty(flagsProp)) {
flags += " ";
flags += flagsConfig;
}
+ std::vector<std::string> opts;
+ this->GeneratorTarget->GetLinkOptions(opts, config, linkLanguage);
+ // LINK_OPTIONS are escaped.
+ this->LocalGenerator->AppendCompileOptions(flags, opts);
+
cmComputeLinkInformation* pcli =
- this->GeneratorTarget->GetLinkInformation(config.c_str());
+ this->GeneratorTarget->GetLinkInformation(config);
if (!pcli) {
cmSystemTools::Error(
- "CMake can not compute cmComputeLinkInformation for target: ",
- this->Name.c_str());
+ "CMake can not compute cmComputeLinkInformation for target: " +
+ this->Name);
return false;
}
cmComputeLinkInformation& cli = *pcli;
std::vector<std::string> libVec;
std::vector<std::string> vsTargetVec;
- this->AddLibraries(cli, libVec, vsTargetVec);
+ this->AddLibraries(cli, libVec, vsTargetVec, config);
if (std::find(linkClosure->Languages.begin(), linkClosure->Languages.end(),
- "CUDA") != linkClosure->Languages.end()) {
+ "CUDA") != linkClosure->Languages.end() &&
+ this->CudaOptions[config] != nullptr) {
switch (this->CudaOptions[config]->GetCudaRuntime()) {
case cmVisualStudioGeneratorOptions::CudaRuntimeStatic:
+ libVec.push_back("cudadevrt.lib");
libVec.push_back("cudart_static.lib");
break;
case cmVisualStudioGeneratorOptions::CudaRuntimeShared:
+ libVec.push_back("cudadevrt.lib");
libVec.push_back("cudart.lib");
break;
case cmVisualStudioGeneratorOptions::CudaRuntimeNone:
@@ -3054,47 +3480,34 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
std::string standardLibsVar = "CMAKE_";
standardLibsVar += linkLanguage;
standardLibsVar += "_STANDARD_LIBRARIES";
- std::string const libs =
- this->Makefile->GetSafeDefinition(standardLibsVar.c_str());
+ std::string const& libs = this->Makefile->GetSafeDefinition(standardLibsVar);
cmSystemTools::ParseWindowsCommandLine(libs.c_str(), libVec);
linkOptions.AddFlag("AdditionalDependencies", libVec);
// Populate TargetsFileAndConfigsVec
- for (std::vector<std::string>::iterator ti = vsTargetVec.begin();
- ti != vsTargetVec.end(); ++ti) {
- this->AddTargetsFileAndConfigPair(*ti, config);
+ for (std::string const& ti : vsTargetVec) {
+ this->AddTargetsFileAndConfigPair(ti, config);
}
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) {
+ for (std::string const& d : ldirs) {
// first just full path
- linkDirs.push_back(*d);
+ linkDirs.push_back(d);
// next path with configuration type Debug, Release, etc
- linkDirs.push_back(*d + "/$(Configuration)");
+ 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;
+ cmGeneratorTarget::Names targetNames;
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
- this->GeneratorTarget->GetExecutableNames(targetName, targetNameFull,
- targetNameImport, targetNamePDB,
- config.c_str());
+ targetNames = this->GeneratorTarget->GetExecutableNames(config);
} else {
- this->GeneratorTarget->GetLibraryNames(targetName, targetNameSO,
- targetNameFull, targetNameImport,
- targetNamePDB, config.c_str());
+ targetNames = this->GeneratorTarget->GetLibraryNames(config);
}
if (this->MSTools) {
- linkOptions.AddFlag("Version", "");
-
if (this->GeneratorTarget->GetPropertyAsBool("WIN32_EXECUTABLE")) {
if (this->GlobalGenerator->TargetsWindowsCE()) {
linkOptions.AddFlag("SubSystem", "WindowsCE");
@@ -3130,16 +3543,16 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
linkOptions.AddFlag("GenerateDebugInformation", "false");
- std::string pdb = this->GeneratorTarget->GetPDBDirectory(config.c_str());
+ std::string pdb = this->GeneratorTarget->GetPDBDirectory(config);
pdb += "/";
- pdb += targetNamePDB;
+ pdb += targetNames.PDB;
std::string imLib = this->GeneratorTarget->GetDirectory(
- config.c_str(), cmStateEnums::ImportLibraryArtifact);
+ config, cmStateEnums::ImportLibraryArtifact);
imLib += "/";
- imLib += targetNameImport;
+ imLib += targetNames.ImportLibrary;
- linkOptions.AddFlag("ImportLibrary", imLib.c_str());
- linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str());
+ linkOptions.AddFlag("ImportLibrary", imLib);
+ linkOptions.AddFlag("ProgramDataBaseFile", pdb);
// A Windows Runtime component uses internal .NET metadata,
// so does not have an import library.
@@ -3160,16 +3573,17 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries", "ole32.lib");
}
} else if (this->NsightTegra) {
- linkOptions.AddFlag("SoName", targetNameSO.c_str());
+ linkOptions.AddFlag("SoName", targetNames.SharedObject);
}
- linkOptions.Parse(flags.c_str());
+ linkOptions.Parse(flags);
+ linkOptions.FixManifestUACFlags();
if (this->MSTools) {
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
this->GeneratorTarget->GetModuleDefinitionInfo(config);
if (mdi && !mdi->DefFile.empty()) {
- linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile.c_str());
+ linkOptions.AddFlag("ModuleDefinitionFile", mdi->DefFile);
}
linkOptions.AppendFlag("IgnoreSpecificDefaultLibraries",
"%(IgnoreSpecificDefaultLibraries)");
@@ -3187,17 +3601,24 @@ bool cmVisualStudio10TargetGenerator::ComputeLinkOptions(
}
}
- this->LinkOptions[config] = pOptions.release();
+ // Managed code cannot be linked with /DEBUG:FASTLINK
+ if (this->Managed) {
+ if (const char* debug = linkOptions.GetFlag("GenerateDebugInformation")) {
+ if (strcmp(debug, "DebugFastLink") == 0) {
+ linkOptions.AddFlag("GenerateDebugInformation", "Debug");
+ }
+ }
+ }
+
+ this->LinkOptions[config] = std::move(pOptions);
return true;
}
bool cmVisualStudio10TargetGenerator::ComputeLibOptions()
{
if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.end(); ++i) {
- if (!this->ComputeLibOptions(*i)) {
+ for (std::string const& c : this->Configurations) {
+ if (!this->ComputeLibOptions(c)) {
return false;
}
}
@@ -3209,11 +3630,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
std::string const& config)
{
cmComputeLinkInformation* pcli =
- this->GeneratorTarget->GetLinkInformation(config.c_str());
+ this->GeneratorTarget->GetLinkInformation(config);
if (!pcli) {
cmSystemTools::Error(
- "CMake can not compute cmComputeLinkInformation for target: ",
- this->Name.c_str());
+ "CMake can not compute cmComputeLinkInformation for target: " +
+ this->Name);
return false;
}
@@ -3222,11 +3643,11 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
const ItemVector& libs = cli.GetItems();
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
- for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
- if (l->IsPath && cmVS10IsTargetsFile(l->Value)) {
- std::string path = this->LocalGenerator->ConvertToRelativePath(
- currentBinDir, l->Value.c_str());
- this->ConvertToWindowsSlash(path);
+ for (cmComputeLinkInformation::Item const& l : libs) {
+ if (l.IsPath && cmVS10IsTargetsFile(l.Value)) {
+ std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
+ currentBinDir, l.Value);
+ ConvertToWindowsSlash(path);
this->AddTargetsFileAndConfigPair(path, config);
}
}
@@ -3235,52 +3656,90 @@ bool cmVisualStudio10TargetGenerator::ComputeLibOptions(
}
void cmVisualStudio10TargetGenerator::WriteLinkOptions(
- std::string const& config)
+ Elem& e1, std::string const& config)
{
if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY ||
this->GeneratorTarget->GetType() > cmStateEnums::MODULE_LIBRARY) {
return;
}
- if (csproj == this->ProjectType) {
+ if (this->ProjectType == csproj) {
return;
}
- Options& linkOptions = *(this->LinkOptions[config]);
- this->WriteString("<Link>\n", 2);
- linkOptions.PrependInheritedString("AdditionalOptions");
- linkOptions.OutputFlagMap(*this->BuildFileStream, " ");
+ {
+ Elem e2(e1, "Link");
+ OptionsHelper linkOptions(*(this->LinkOptions[config]), e2);
+ linkOptions.PrependInheritedString("AdditionalOptions");
+ linkOptions.OutputFlagMap();
+ }
- this->WriteString("</Link>\n", 2);
if (!this->GlobalGenerator->NeedLinkLibraryDependencies(
this->GeneratorTarget)) {
- this->WriteString("<ProjectReference>\n", 2);
- this->WriteString(
- "<LinkLibraryDependencies>false</LinkLibraryDependencies>\n", 3);
- this->WriteString("</ProjectReference>\n", 2);
+ Elem e2(e1, "ProjectReference");
+ e2.Element("LinkLibraryDependencies", "false");
}
}
void cmVisualStudio10TargetGenerator::AddLibraries(
- cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
- std::vector<std::string>& vsTargetVec)
+ const cmComputeLinkInformation& cli, std::vector<std::string>& libVec,
+ std::vector<std::string>& vsTargetVec, const std::string& config)
{
typedef cmComputeLinkInformation::ItemVector ItemVector;
ItemVector const& libs = cli.GetItems();
std::string currentBinDir =
this->LocalGenerator->GetCurrentBinaryDirectory();
- for (ItemVector::const_iterator l = libs.begin(); l != libs.end(); ++l) {
- if (l->IsPath) {
- std::string path = this->LocalGenerator->ConvertToRelativePath(
- currentBinDir, l->Value.c_str());
- this->ConvertToWindowsSlash(path);
- if (cmVS10IsTargetsFile(l->Value)) {
+ for (cmComputeLinkInformation::Item const& l : libs) {
+ if (l.Target) {
+ auto managedType = l.Target->GetManagedType(config);
+ if (managedType != cmGeneratorTarget::ManagedType::Native &&
+ this->GeneratorTarget->GetManagedType(config) !=
+ cmGeneratorTarget::ManagedType::Native &&
+ l.Target->IsImported()) {
+ auto location = l.Target->GetFullPath(config);
+ if (!location.empty()) {
+ ConvertToWindowsSlash(location);
+ switch (this->ProjectType) {
+ case csproj:
+ // If the target we want to "link" to is an imported managed
+ // target and this is a C# project, we add a hint reference. This
+ // reference is written to project file in
+ // WriteDotNetReferences().
+ this->DotNetHintReferences[config].push_back(
+ DotNetHintReference(l.Target->GetName(), location));
+ break;
+ case vcxproj:
+ // Add path of assembly to list of using-directories, so the
+ // managed assembly can be used by '#using <assembly.dll>' in
+ // code.
+ this->AdditionalUsingDirectories[config].insert(
+ cmSystemTools::GetFilenamePath(location));
+ break;
+ }
+ }
+ }
+ // Do not allow C# targets to be added to the LIB listing. LIB files are
+ // used for linking C++ dependencies. C# libraries do not have lib files.
+ // Instead, they compile down to C# reference libraries (DLL files). The
+ // `<ProjectReference>` elements added to the vcxproj are enough for the
+ // IDE to deduce the DLL file required by other C# projects that need its
+ // reference library.
+ if (managedType == cmGeneratorTarget::ManagedType::Managed) {
+ continue;
+ }
+ }
+
+ if (l.IsPath) {
+ std::string path = this->LocalGenerator->MaybeConvertToRelativePath(
+ currentBinDir, l.Value);
+ ConvertToWindowsSlash(path);
+ if (cmVS10IsTargetsFile(l.Value)) {
vsTargetVec.push_back(path);
} else {
libVec.push_back(path);
}
- } else if (!l->Target ||
- l->Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
- libVec.push_back(l->Value);
+ } else if (!l.Target ||
+ l.Target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
+ libVec.push_back(l.Value);
}
}
}
@@ -3288,13 +3747,11 @@ void cmVisualStudio10TargetGenerator::AddLibraries(
void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
std::string const& targetsFile, std::string const& config)
{
- for (std::vector<TargetsFileAndConfigs>::iterator i =
- this->TargetsFileAndConfigsVec.begin();
- i != this->TargetsFileAndConfigsVec.end(); ++i) {
- if (cmSystemTools::ComparePath(targetsFile, i->File)) {
- if (std::find(i->Configs.begin(), i->Configs.end(), config) ==
- i->Configs.end()) {
- i->Configs.push_back(config);
+ for (TargetsFileAndConfigs& i : this->TargetsFileAndConfigsVec) {
+ if (cmSystemTools::ComparePath(targetsFile, i.File)) {
+ if (std::find(i.Configs.begin(), i.Configs.end(), config) ==
+ i.Configs.end()) {
+ i.Configs.push_back(config);
}
return;
}
@@ -3306,12 +3763,12 @@ void cmVisualStudio10TargetGenerator::AddTargetsFileAndConfigPair(
}
void cmVisualStudio10TargetGenerator::WriteMidlOptions(
- std::string const& /*config*/, std::vector<std::string> const& includes)
+ Elem& e1, std::string const& configName)
{
if (!this->MSTools) {
return;
}
- if (csproj == this->ProjectType) {
+ if (this->ProjectType == csproj) {
return;
}
@@ -3330,74 +3787,64 @@ void cmVisualStudio10TargetGenerator::WriteMidlOptions(
// 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>$(ProjectDir)/$(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);
+ std::vector<std::string> const includes =
+ this->GetIncludes(configName, "MIDL");
+ std::ostringstream oss;
+ for (std::string const& i : includes) {
+ oss << i << ";";
+ }
+ oss << "%(AdditionalIncludeDirectories)";
+
+ Elem e2(e1, "Midl");
+ e2.Element("AdditionalIncludeDirectories", oss.str());
+ e2.Element("OutputDirectory", "$(ProjectDir)/$(IntDir)");
+ e2.Element("HeaderFileName", "%(Filename).h");
+ e2.Element("TypeLibraryName", "%(Filename).tlb");
+ e2.Element("InterfaceIdentifierFileName", "%(Filename)_i.c");
+ e2.Element("ProxyFileName", "%(Filename)_p.c");
}
-void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups()
+void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups(Elem& e0)
{
- for (std::vector<std::string>::const_iterator i =
- this->Configurations.begin();
- i != this->Configurations.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";
+ if (this->ProjectType == csproj) {
+ return;
+ }
+ for (const std::string& c : this->Configurations) {
+ Elem e1(e0, "ItemDefinitionGroup");
+ e1.Attribute("Condition", this->CalcCondition(c));
+
// output cl compile flags <ClCompile></ClCompile>
if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
- this->WriteClOptions(*i, includes);
+ this->WriteClOptions(e1, c);
// output rc compile flags <ResourceCompile></ResourceCompile>
- this->WriteRCOptions(*i, includes);
- this->WriteCudaOptions(*i, includes);
- this->WriteMasmOptions(*i, includes);
- this->WriteNasmOptions(*i, includes);
+ this->WriteRCOptions(e1, c);
+ this->WriteCudaOptions(e1, c);
+ this->WriteMasmOptions(e1, c);
+ this->WriteNasmOptions(e1, c);
}
// output midl flags <Midl></Midl>
- this->WriteMidlOptions(*i, includes);
+ this->WriteMidlOptions(e1, c);
// write events
- if (csproj != this->ProjectType) {
- this->WriteEvents(*i);
+ if (this->ProjectType != csproj) {
+ this->WriteEvents(e1, c);
}
// output link flags <Link></Link>
- this->WriteLinkOptions(*i);
- this->WriteCudaLinkOptions(*i);
+ this->WriteLinkOptions(e1, c);
+ this->WriteCudaLinkOptions(e1, c);
// output lib flags <Lib></Lib>
- this->WriteLibOptions(*i);
+ this->WriteLibOptions(e1, c);
// output manifest flags <Manifest></Manifest>
- this->WriteManifestOptions(*i);
+ this->WriteManifestOptions(e1, c);
if (this->NsightTegra &&
this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE &&
this->GeneratorTarget->GetPropertyAsBool("ANDROID_GUI")) {
- this->WriteAntBuildOptions(*i);
+ this->WriteAntBuildOptions(e1, c);
}
- this->WriteString("</ItemDefinitionGroup>\n", 1);
}
}
void cmVisualStudio10TargetGenerator::WriteEvents(
- std::string const& configName)
+ Elem& e1, std::string const& configName)
{
bool addedPrelink = false;
cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
@@ -3408,80 +3855,76 @@ void cmVisualStudio10TargetGenerator::WriteEvents(
this->GeneratorTarget->GetPreLinkCommands();
this->GlobalGenerator->AddSymbolExportCommand(this->GeneratorTarget,
commands, configName);
- this->WriteEvent("PreLinkEvent", commands, configName);
+ this->WriteEvent(e1, "PreLinkEvent", commands, configName);
}
if (!addedPrelink) {
- this->WriteEvent("PreLinkEvent",
+ this->WriteEvent(e1, "PreLinkEvent",
this->GeneratorTarget->GetPreLinkCommands(), configName);
}
- this->WriteEvent("PreBuildEvent",
+ this->WriteEvent(e1, "PreBuildEvent",
this->GeneratorTarget->GetPreBuildCommands(), configName);
- this->WriteEvent("PostBuildEvent",
+ this->WriteEvent(e1, "PostBuildEvent",
this->GeneratorTarget->GetPostBuildCommands(), configName);
}
void cmVisualStudio10TargetGenerator::WriteEvent(
- const char* name, std::vector<cmCustomCommand> const& commands,
+ Elem& e1, const char* name, std::vector<cmCustomCommand> const& commands,
std::string const& configName)
{
if (commands.empty()) {
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->LocalGenerator);
- comment += pre;
- comment += lg->ConstructComment(ccg);
- script += pre;
- pre = "\n";
- script += cmVS10EscapeXML(lg->ConstructScript(ccg));
+ for (cmCustomCommand const& cc : commands) {
+ cmCustomCommandGenerator ccg(cc, configName, lg);
+ if (!ccg.HasOnlyEmptyCommandLines()) {
+ comment += pre;
+ comment += lg->ConstructComment(ccg);
+ script += pre;
+ pre = "\n";
+ script += lg->ConstructScript(ccg);
+ }
}
comment = cmVS10EscapeComment(comment);
- if (csproj != this->ProjectType) {
- this->WriteString("<Message>", 3);
- (*this->BuildFileStream) << cmVS10EscapeXML(comment) << "</Message>\n";
- this->WriteString("<Command>", 3);
+ if (this->ProjectType != csproj) {
+ Elem e2(e1, name);
+ e2.Element("Message", comment);
+ e2.Element("Command", script);
} else {
- if (!comment.empty()) {
- (*this->BuildFileStream) << "echo " << cmVS10EscapeXML(comment) << "\n";
+ std::string strippedComment = comment;
+ strippedComment.erase(
+ std::remove(strippedComment.begin(), strippedComment.end(), '\t'),
+ strippedComment.end());
+ std::ostringstream oss;
+ if (!comment.empty() && !strippedComment.empty()) {
+ oss << "echo " << comment << "\n";
}
+ oss << script << "\n";
+ e1.Element(name, oss.str());
}
- (*this->BuildFileStream) << script;
- if (csproj != this->ProjectType) {
- (*this->BuildFileStream) << "</Command>";
- }
- (*this->BuildFileStream) << "\n";
- this->WriteString("</", 2);
- (*this->BuildFileStream) << name << ">\n";
}
-void cmVisualStudio10TargetGenerator::WriteProjectReferences()
+void cmVisualStudio10TargetGenerator::WriteProjectReferences(Elem& e0)
{
cmGlobalGenerator::TargetDependSet const& unordered =
this->GlobalGenerator->GetTargetDirectDepends(this->GeneratorTarget);
typedef cmGlobalVisualStudioGenerator::OrderedTargetDependSet
OrderedTargetDependSet;
OrderedTargetDependSet depends(unordered, CMAKE_CHECK_BUILD_SYSTEM_TARGET);
- this->WriteString("<ItemGroup>\n", 1);
- for (OrderedTargetDependSet::const_iterator i = depends.begin();
- i != depends.end(); ++i) {
- cmGeneratorTarget const* dt = *i;
+ Elem e1(e0, "ItemGroup");
+ e1.SetHasElements();
+ for (cmGeneratorTarget const* dt : depends) {
if (dt->GetType() == cmStateEnums::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)) {
+ if (this->GlobalGenerator->TargetIsFortranOnly(dt)) {
continue;
}
- this->WriteString("<ProjectReference Include=\"", 2);
cmLocalGenerator* lg = dt->GetLocalGenerator();
std::string name = dt->GetName();
std::string path;
@@ -3494,27 +3937,46 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
path += dt->GetName();
path += computeProjectFileExtension(dt);
}
- this->ConvertToWindowsSlash(path);
- (*this->BuildFileStream) << cmVS10EscapeXML(path) << "\">\n";
- this->WriteString("<Project>", 3);
- (*this->BuildFileStream)
- << "{" << this->GlobalGenerator->GetGUID(name.c_str()) << "}";
- (*this->BuildFileStream) << "</Project>\n";
- this->WriteString("<Name>", 3);
- (*this->BuildFileStream) << name << "</Name>\n";
- if (csproj == this->ProjectType) {
- if (!static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
- ->TargetCanBeReferenced(dt)) {
- this->WriteString(
- "<ReferenceOutputAssembly>false</ReferenceOutputAssembly>\n", 3);
+ ConvertToWindowsSlash(path);
+ Elem e2(e1, "ProjectReference");
+ e2.Attribute("Include", path);
+ e2.Element("Project", "{" + this->GlobalGenerator->GetGUID(name) + "}");
+ e2.Element("Name", name);
+ this->WriteDotNetReferenceCustomTags(e2, name);
+
+ // If the dependency target is not managed (compiled with /clr or
+ // C# target) and not a WinRT component we cannot reference it and
+ // have to set 'ReferenceOutputAssembly' to false.
+ auto referenceNotManaged =
+ dt->GetManagedType("") < cmGeneratorTarget::ManagedType::Mixed;
+ // Workaround to check for manually set /clr flags.
+ if (referenceNotManaged) {
+ if (const auto* flags = dt->GetProperty("COMPILE_OPTIONS")) {
+ std::string flagsStr = flags;
+ if (flagsStr.find("clr") != std::string::npos) {
+ // There is a warning already issued when building the flags.
+ referenceNotManaged = false;
+ }
}
}
- this->WriteString("</ProjectReference>\n", 2);
+ // Workaround for static library C# targets
+ if (referenceNotManaged && dt->GetType() == cmStateEnums::STATIC_LIBRARY) {
+ referenceNotManaged = !dt->IsCSharpOnly();
+ }
+
+ // Referencing WinRT components is okay.
+ if (referenceNotManaged) {
+ referenceNotManaged = !dt->GetPropertyAsBool("VS_WINRT_COMPONENT");
+ }
+
+ if (referenceNotManaged) {
+ e2.Element("ReferenceOutputAssembly", "false");
+ e2.Element("CopyToOutputDirectory", "Never");
+ }
}
- this->WriteString("</ItemGroup>\n", 1);
}
-void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
+void cmVisualStudio10TargetGenerator::WritePlatformExtensions(Elem& e1)
{
// This only applies to Windows 10 apps
if (this->GlobalGenerator->TargetsWindowsStore() &&
@@ -3522,53 +3984,44 @@ void cmVisualStudio10TargetGenerator::WritePlatformExtensions()
const char* desktopExtensionsVersion =
this->GeneratorTarget->GetProperty("VS_DESKTOP_EXTENSIONS_VERSION");
if (desktopExtensionsVersion) {
- this->WriteSinglePlatformExtension("WindowsDesktop",
+ this->WriteSinglePlatformExtension(e1, "WindowsDesktop",
desktopExtensionsVersion);
}
const char* mobileExtensionsVersion =
this->GeneratorTarget->GetProperty("VS_MOBILE_EXTENSIONS_VERSION");
if (mobileExtensionsVersion) {
- this->WriteSinglePlatformExtension("WindowsMobile",
+ this->WriteSinglePlatformExtension(e1, "WindowsMobile",
mobileExtensionsVersion);
}
}
}
void cmVisualStudio10TargetGenerator::WriteSinglePlatformExtension(
- std::string const& extension, std::string const& version)
+ Elem& e1, std::string const& extension, std::string const& version)
{
- this->WriteString("<Import Project=", 2);
- (*this->BuildFileStream)
- << "\"$([Microsoft.Build.Utilities.ToolLocationHelper]"
- << "::GetPlatformExtensionSDKLocation(`" << extension
- << ", Version=" << version
- << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
- << "$(ExtensionSDKDirectoryRoot), null))"
- << "\\DesignTime\\CommonConfiguration\\Neutral\\" << extension
- << ".props\" "
- << "Condition=\"exists('$("
- << "[Microsoft.Build.Utilities.ToolLocationHelper]"
- << "::GetPlatformExtensionSDKLocation(`" << extension
- << ", Version=" << version
- << "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
- << "$(ExtensionSDKDirectoryRoot), null))"
- << "\\DesignTime\\CommonConfiguration\\Neutral\\" << extension
- << ".props')\" />\n";
+ const std::string s = "$([Microsoft.Build.Utilities.ToolLocationHelper]"
+ "::GetPlatformExtensionSDKLocation(`" +
+ extension + ", Version=" + version +
+ "`, $(TargetPlatformIdentifier), $(TargetPlatformVersion), null, "
+ "$(ExtensionSDKDirectoryRoot), null))"
+ "\\DesignTime\\CommonConfiguration\\Neutral\\" +
+ extension + ".props";
+
+ Elem e2(e1, "Import");
+ e2.Attribute("Project", s);
+ e2.Attribute("Condition", "exists('" + s + "')");
}
-void cmVisualStudio10TargetGenerator::WriteSDKReferences()
+void cmVisualStudio10TargetGenerator::WriteSDKReferences(Elem& e0)
{
std::vector<std::string> sdkReferences;
- bool hasWrittenItemGroup = false;
+ std::unique_ptr<Elem> spe1;
if (const char* vsSDKReferences =
this->GeneratorTarget->GetProperty("VS_SDK_REFERENCES")) {
cmSystemTools::ExpandListArgument(vsSDKReferences, sdkReferences);
- this->WriteString("<ItemGroup>\n", 1);
- hasWrittenItemGroup = true;
- for (std::vector<std::string>::iterator ri = sdkReferences.begin();
- ri != sdkReferences.end(); ++ri) {
- this->WriteString("<SDKReference Include=\"", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\"/>\n";
+ spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
+ for (std::string const& ri : sdkReferences) {
+ Elem(*spe1, "SDKReference").Attribute("Include", ri);
}
}
@@ -3584,38 +4037,34 @@ void cmVisualStudio10TargetGenerator::WriteSDKReferences()
if (desktopExtensionsVersion || mobileExtensionsVersion ||
iotExtensionsVersion) {
- if (!hasWrittenItemGroup) {
- this->WriteString("<ItemGroup>\n", 1);
- hasWrittenItemGroup = true;
+ if (!spe1) {
+ spe1 = cm::make_unique<Elem>(e0, "ItemGroup");
}
if (desktopExtensionsVersion) {
- this->WriteSingleSDKReference("WindowsDesktop",
+ this->WriteSingleSDKReference(*spe1, "WindowsDesktop",
desktopExtensionsVersion);
}
if (mobileExtensionsVersion) {
- this->WriteSingleSDKReference("WindowsMobile",
+ this->WriteSingleSDKReference(*spe1, "WindowsMobile",
mobileExtensionsVersion);
}
if (iotExtensionsVersion) {
- this->WriteSingleSDKReference("WindowsIoT", iotExtensionsVersion);
+ this->WriteSingleSDKReference(*spe1, "WindowsIoT",
+ iotExtensionsVersion);
}
}
-
- if (hasWrittenItemGroup) {
- this->WriteString("</ItemGroup>\n", 1);
- }
}
}
void cmVisualStudio10TargetGenerator::WriteSingleSDKReference(
- std::string const& extension, std::string const& version)
+ Elem& e1, std::string const& extension, std::string const& version)
{
- this->WriteString("<SDKReference Include=\"", 2);
- (*this->BuildFileStream) << extension << ", Version=" << version
- << "\" />\n";
+ Elem(e1, "SDKReference")
+ .Attribute("Include", extension + ", Version=" + version);
}
-void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
+void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile(
+ Elem& e0)
{
if ((this->GlobalGenerator->TargetsWindowsStore() ||
this->GlobalGenerator->TargetsWindowsPhone()) &&
@@ -3623,11 +4072,9 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
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);
+ for (cmSourceFile const* si : certificates) {
+ pfxFile = this->ConvertPath(si->GetFullPath(), false);
+ ConvertToWindowsSlash(pfxFile);
break;
}
@@ -3637,16 +4084,13 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
// Move the manifest to a project directory to avoid clashes
std::string artifactDir =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
- this->ConvertToWindowsSlash(artifactDir);
- this->WriteString("<PropertyGroup>\n", 1);
- this->WriteString("<AppxPackageArtifactsDir>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(artifactDir)
- << "\\</AppxPackageArtifactsDir>\n";
- this->WriteString("<ProjectPriFullPath>", 2);
+ ConvertToWindowsSlash(artifactDir);
+ Elem e1(e0, "PropertyGroup");
+ e1.Element("AppxPackageArtifactsDir", artifactDir + "\\");
std::string resourcePriFile =
this->DefaultArtifactDir + "/resources.pri";
- this->ConvertToWindowsSlash(resourcePriFile);
- (*this->BuildFileStream) << resourcePriFile << "</ProjectPriFullPath>\n";
+ ConvertToWindowsSlash(resourcePriFile);
+ e1.Element("ProjectPriFullPath", resourcePriFile);
// If we are missing files and we don't have a certificate and
// aren't targeting WP8.0, add a default certificate
@@ -3656,32 +4100,23 @@ void cmVisualStudio10TargetGenerator::WriteWinRTPackageCertificateKeyFile()
pfxFile = this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
cmSystemTools::CopyAFile(templateFolder + "/Windows_TemporaryKey.pfx",
pfxFile, false);
- this->ConvertToWindowsSlash(pfxFile);
+ ConvertToWindowsSlash(pfxFile);
this->AddedFiles.push_back(pfxFile);
+ this->AddedDefaultCertificate = true;
}
- this->WriteString("<", 2);
- (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
- << "</PackageCertificateKeyFile>\n";
+ e1.Element("PackageCertificateKeyFile", pfxFile);
std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
if (!thumb.empty()) {
- this->WriteString("<PackageCertificateThumbprint>", 2);
- (*this->BuildFileStream) << thumb
- << "</PackageCertificateThumbprint>\n";
+ e1.Element("PackageCertificateThumbprint", thumb);
}
- this->WriteString("</PropertyGroup>\n", 1);
} else if (!pfxFile.empty()) {
- this->WriteString("<PropertyGroup>\n", 1);
- this->WriteString("<", 2);
- (*this->BuildFileStream) << "PackageCertificateKeyFile>" << pfxFile
- << "</PackageCertificateKeyFile>\n";
+ Elem e1(e0, "PropertyGroup");
+ e1.Element("PackageCertificateKeyFile", pfxFile);
std::string thumb = cmSystemTools::ComputeCertificateThumbprint(pfxFile);
if (!thumb.empty()) {
- this->WriteString("<PackageCertificateThumbprint>", 2);
- (*this->BuildFileStream) << thumb
- << "</PackageCertificateThumbprint>\n";
+ e1.Element("PackageCertificateThumbprint", thumb);
}
- this->WriteString("</PropertyGroup>\n", 1);
}
}
}
@@ -3691,10 +4126,7 @@ bool cmVisualStudio10TargetGenerator::IsResxHeader(
{
std::set<std::string> expectedResxHeaders;
this->GeneratorTarget->GetExpectedResxHeaders(expectedResxHeaders, "");
-
- std::set<std::string>::const_iterator it =
- expectedResxHeaders.find(headerFile);
- return it != expectedResxHeaders.end();
+ return expectedResxHeaders.count(headerFile) > 0;
}
bool cmVisualStudio10TargetGenerator::IsXamlHeader(
@@ -3702,10 +4134,7 @@ bool cmVisualStudio10TargetGenerator::IsXamlHeader(
{
std::set<std::string> expectedXamlHeaders;
this->GeneratorTarget->GetExpectedXamlHeaders(expectedXamlHeaders, "");
-
- std::set<std::string>::const_iterator it =
- expectedXamlHeaders.find(headerFile);
- return it != expectedXamlHeaders.end();
+ return expectedXamlHeaders.count(headerFile) > 0;
}
bool cmVisualStudio10TargetGenerator::IsXamlSource(
@@ -3713,60 +4142,40 @@ bool cmVisualStudio10TargetGenerator::IsXamlSource(
{
std::set<std::string> expectedXamlSources;
this->GeneratorTarget->GetExpectedXamlSources(expectedXamlSources, "");
-
- std::set<std::string>::const_iterator it =
- expectedXamlSources.find(sourceFile);
- return it != expectedXamlSources.end();
+ return expectedXamlSources.count(sourceFile) > 0;
}
-void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
+void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings(Elem& e1)
{
- cmGlobalVisualStudio10Generator* gg =
- static_cast<cmGlobalVisualStudio10Generator*>(this->GlobalGenerator);
+ cmGlobalVisualStudio10Generator* gg = this->GlobalGenerator;
bool isAppContainer = false;
bool const isWindowsPhone = this->GlobalGenerator->TargetsWindowsPhone();
bool const isWindowsStore = this->GlobalGenerator->TargetsWindowsStore();
- std::string const& v = this->GlobalGenerator->GetSystemVersion();
+ std::string const& rev = this->GlobalGenerator->GetApplicationTypeRevision();
if (isWindowsPhone || isWindowsStore) {
- this->WriteString("<ApplicationType>", 2);
- (*this->BuildFileStream)
- << (isWindowsPhone ? "Windows Phone" : "Windows Store")
- << "</ApplicationType>\n";
- this->WriteString("<DefaultLanguage>en-US"
- "</DefaultLanguage>\n",
- 2);
- if (cmHasLiteralPrefix(v, "10.0")) {
- this->WriteString("<ApplicationTypeRevision>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML("10.0")
- << "</ApplicationTypeRevision>\n";
+ e1.Element("ApplicationType",
+ (isWindowsPhone ? "Windows Phone" : "Windows Store"));
+ e1.Element("DefaultLanguage", "en-US");
+ if (rev == "10.0") {
+ e1.Element("ApplicationTypeRevision", rev);
// Visual Studio 14.0 is necessary for building 10.0 apps
- this->WriteString("<MinimumVisualStudioVersion>14.0"
- "</MinimumVisualStudioVersion>\n",
- 2);
+ e1.Element("MinimumVisualStudioVersion", "14.0");
if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
isAppContainer = true;
}
- } else if (v == "8.1") {
- this->WriteString("<ApplicationTypeRevision>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(v)
- << "</ApplicationTypeRevision>\n";
+ } else if (rev == "8.1") {
+ e1.Element("ApplicationTypeRevision", rev);
// Visual Studio 12.0 is necessary for building 8.1 apps
- this->WriteString("<MinimumVisualStudioVersion>12.0"
- "</MinimumVisualStudioVersion>\n",
- 2);
+ e1.Element("MinimumVisualStudioVersion", "12.0");
if (this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
isAppContainer = true;
}
- } else if (v == "8.0") {
- this->WriteString("<ApplicationTypeRevision>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(v)
- << "</ApplicationTypeRevision>\n";
+ } else if (rev == "8.0") {
+ e1.Element("ApplicationTypeRevision", rev);
// Visual Studio 11.0 is necessary for building 8.0 apps
- this->WriteString("<MinimumVisualStudioVersion>11.0"
- "</MinimumVisualStudioVersion>\n",
- 2);
+ e1.Element("MinimumVisualStudioVersion", "11.0");
if (isWindowsStore &&
this->GeneratorTarget->GetType() < cmStateEnums::UTILITY) {
@@ -3774,48 +4183,38 @@ void cmVisualStudio10TargetGenerator::WriteApplicationTypeSettings()
} else if (isWindowsPhone &&
this->GeneratorTarget->GetType() ==
cmStateEnums::EXECUTABLE) {
- this->WriteString("<XapOutputs>true</XapOutputs>\n", 2);
- this->WriteString("<XapFilename>", 2);
- (*this->BuildFileStream)
- << cmVS10EscapeXML(this->Name.c_str())
- << "_$(Configuration)_$(Platform).xap</XapFilename>\n";
+ e1.Element("XapOutputs", "true");
+ e1.Element("XapFilename",
+ this->Name + "_$(Configuration)_$(Platform).xap");
}
}
}
if (isAppContainer) {
- this->WriteString("<AppContainerApplication>true"
- "</AppContainerApplication>\n",
- 2);
+ e1.Element("AppContainerApplication", "true");
+ } else if (this->Platform == "ARM64") {
+ e1.Element("WindowsSDKDesktopARM64Support", "true");
} else if (this->Platform == "ARM") {
- this->WriteString("<WindowsSDKDesktopARMSupport>true"
- "</WindowsSDKDesktopARMSupport>\n",
- 2);
+ e1.Element("WindowsSDKDesktopARMSupport", "true");
}
std::string const& targetPlatformVersion =
gg->GetWindowsTargetPlatformVersion();
if (!targetPlatformVersion.empty()) {
- this->WriteString("<WindowsTargetPlatformVersion>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
- << "</WindowsTargetPlatformVersion>\n";
+ e1.Element("WindowsTargetPlatformVersion", targetPlatformVersion);
}
const char* targetPlatformMinVersion = this->GeneratorTarget->GetProperty(
"VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION");
if (targetPlatformMinVersion) {
- this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformMinVersion)
- << "</WindowsTargetPlatformMinVersion>\n";
- } else if (isWindowsStore && cmHasLiteralPrefix(v, "10.0")) {
+ e1.Element("WindowsTargetPlatformMinVersion", targetPlatformMinVersion);
+ } else if (isWindowsStore && rev == "10.0") {
// If the min version is not set, then use the TargetPlatformVersion
if (!targetPlatformVersion.empty()) {
- this->WriteString("<WindowsTargetPlatformMinVersion>", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(targetPlatformVersion)
- << "</WindowsTargetPlatformMinVersion>\n";
+ e1.Element("WindowsTargetPlatformMinVersion", targetPlatformVersion);
}
}
// Added IoT Startup Task support
if (this->GeneratorTarget->GetPropertyAsBool("VS_IOT_STARTUP_TASK")) {
- this->WriteString("<ContainsStartupTask>true</ContainsStartupTask>\n", 2);
+ e1.Element("ContainsStartupTask", "true");
}
}
@@ -3834,12 +4233,10 @@ void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
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) {
+ for (cmSourceFile const* si : extraSources) {
// Need to do a lowercase comparison on the filename
if ("wmappmanifest.xml" ==
- cmSystemTools::LowerCase((*si)->GetLocation().GetName())) {
+ cmSystemTools::LowerCase(si->GetLocation().GetName())) {
foundManifest = true;
break;
}
@@ -3865,27 +4262,27 @@ void cmVisualStudio10TargetGenerator::VerifyNecessaryFiles()
}
}
-void cmVisualStudio10TargetGenerator::WriteMissingFiles()
+void cmVisualStudio10TargetGenerator::WriteMissingFiles(Elem& e1)
{
std::string const& v = this->GlobalGenerator->GetSystemVersion();
if (this->GlobalGenerator->TargetsWindowsPhone()) {
if (v == "8.0") {
- this->WriteMissingFilesWP80();
+ this->WriteMissingFilesWP80(e1);
} else if (v == "8.1") {
- this->WriteMissingFilesWP81();
+ this->WriteMissingFilesWP81(e1);
}
} else if (this->GlobalGenerator->TargetsWindowsStore()) {
if (v == "8.0") {
- this->WriteMissingFilesWS80();
+ this->WriteMissingFilesWS80(e1);
} else if (v == "8.1") {
- this->WriteMissingFilesWS81();
+ this->WriteMissingFilesWS81(e1);
} else if (cmHasLiteralPrefix(v, "10.0")) {
- this->WriteMissingFilesWS10_0();
+ this->WriteMissingFilesWS10_0(e1);
}
}
}
-void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80(Elem& e1)
{
std::string templateFolder =
cmSystemTools::GetCMakeRoot() + "/Templates/Windows";
@@ -3894,16 +4291,15 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
// this can cause an overwrite problem if projects aren't organized in
// folders
std::string manifestFile =
- this->LocalGenerator->GetCurrentBinaryDirectory() +
- std::string("/WMAppManifest.xml");
+ this->LocalGenerator->GetCurrentBinaryDirectory() + "/WMAppManifest.xml";
std::string artifactDir =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
- this->ConvertToWindowsSlash(artifactDir);
+ ConvertToWindowsSlash(artifactDir);
std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
std::string targetNameXML =
cmVS10EscapeXML(this->GeneratorTarget->GetName());
- cmGeneratedFileStream fout(manifestFile.c_str());
+ cmGeneratedFileStream fout(manifestFile);
fout.SetCopyIfDifferent(true);
/* clang-format off */
@@ -3945,50 +4341,48 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP80()
/* clang-format on */
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);
+ ConvertToWindowsSlash(sourceFile);
+ {
+ Elem e2(e1, "Xml");
+ e2.Attribute("Include", sourceFile);
+ e2.Element("SubType", "Designer");
+ }
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";
+ ConvertToWindowsSlash(smallLogo);
+ Elem(e1, "Image").Attribute("Include", smallLogo);
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";
+ ConvertToWindowsSlash(logo);
+ Elem(e1, "Image").Attribute("Include", logo);
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";
+ ConvertToWindowsSlash(applicationIcon);
+ Elem(e1, "Image").Attribute("Include", applicationIcon);
this->AddedFiles.push_back(applicationIcon);
}
-void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81(Elem& e1)
{
std::string manifestFile =
this->DefaultArtifactDir + "/package.appxManifest";
std::string artifactDir =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
- this->ConvertToWindowsSlash(artifactDir);
+ ConvertToWindowsSlash(artifactDir);
std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
std::string targetNameXML =
cmVS10EscapeXML(this->GeneratorTarget->GetName());
- cmGeneratedFileStream fout(manifestFile.c_str());
+ cmGeneratedFileStream fout(manifestFile);
fout.SetCopyIfDifferent(true);
/* clang-format off */
@@ -4037,21 +4431,21 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWP81()
"</Package>\n";
/* clang-format on */
- this->WriteCommonMissingFiles(manifestFile);
+ this->WriteCommonMissingFiles(e1, manifestFile);
}
-void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80(Elem& e1)
{
std::string manifestFile =
this->DefaultArtifactDir + "/package.appxManifest";
std::string artifactDir =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
- this->ConvertToWindowsSlash(artifactDir);
+ ConvertToWindowsSlash(artifactDir);
std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
std::string targetNameXML =
cmVS10EscapeXML(this->GeneratorTarget->GetName());
- cmGeneratedFileStream fout(manifestFile.c_str());
+ cmGeneratedFileStream fout(manifestFile);
fout.SetCopyIfDifferent(true);
/* clang-format off */
@@ -4092,21 +4486,21 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS80()
"</Package>\n";
/* clang-format on */
- this->WriteCommonMissingFiles(manifestFile);
+ this->WriteCommonMissingFiles(e1, manifestFile);
}
-void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81(Elem& e1)
{
std::string manifestFile =
this->DefaultArtifactDir + "/package.appxManifest";
std::string artifactDir =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
- this->ConvertToWindowsSlash(artifactDir);
+ ConvertToWindowsSlash(artifactDir);
std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
std::string targetNameXML =
cmVS10EscapeXML(this->GeneratorTarget->GetName());
- cmGeneratedFileStream fout(manifestFile.c_str());
+ cmGeneratedFileStream fout(manifestFile);
fout.SetCopyIfDifferent(true);
/* clang-format off */
@@ -4152,21 +4546,21 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS81()
"</Package>\n";
/* clang-format on */
- this->WriteCommonMissingFiles(manifestFile);
+ this->WriteCommonMissingFiles(e1, manifestFile);
}
-void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
+void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0(Elem& e1)
{
std::string manifestFile =
this->DefaultArtifactDir + "/package.appxManifest";
std::string artifactDir =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
- this->ConvertToWindowsSlash(artifactDir);
+ ConvertToWindowsSlash(artifactDir);
std::string artifactDirXML = cmVS10EscapeXML(artifactDir);
std::string targetNameXML =
cmVS10EscapeXML(this->GeneratorTarget->GetName());
- cmGeneratedFileStream fout(manifestFile.c_str());
+ cmGeneratedFileStream fout(manifestFile);
fout.SetCopyIfDifferent(true);
/* clang-format off */
@@ -4213,67 +4607,65 @@ void cmVisualStudio10TargetGenerator::WriteMissingFilesWS10_0()
"</Package>\n";
/* clang-format on */
- this->WriteCommonMissingFiles(manifestFile);
+ this->WriteCommonMissingFiles(e1, manifestFile);
}
void cmVisualStudio10TargetGenerator::WriteCommonMissingFiles(
- const std::string& manifestFile)
+ Elem& e1, 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);
+ ConvertToWindowsSlash(sourceFile);
+ {
+ Elem e2(e1, "AppxManifest");
+ e2.Attribute("Include", sourceFile);
+ e2.Element("SubType", "Designer");
+ }
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";
+ ConvertToWindowsSlash(smallLogo);
+ Elem(e1, "Image").Attribute("Include", smallLogo);
this->AddedFiles.push_back(smallLogo);
std::string smallLogo44 = this->DefaultArtifactDir + "/SmallLogo44x44.png";
cmSystemTools::CopyAFile(templateFolder + "/SmallLogo44x44.png", smallLogo44,
false);
- this->ConvertToWindowsSlash(smallLogo44);
- this->WriteString("<Image Include=\"", 2);
- (*this->BuildFileStream) << cmVS10EscapeXML(smallLogo44) << "\" />\n";
+ ConvertToWindowsSlash(smallLogo44);
+ Elem(e1, "Image").Attribute("Include", smallLogo44);
this->AddedFiles.push_back(smallLogo44);
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";
+ ConvertToWindowsSlash(logo);
+ Elem(e1, "Image").Attribute("Include", logo);
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";
+ ConvertToWindowsSlash(storeLogo);
+ Elem(e1, "Image").Attribute("Include", storeLogo);
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";
+ ConvertToWindowsSlash(splashScreen);
+ Elem(e1, "Image").Attribute("Include", splashScreen);
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";
+ if (this->AddedDefaultCertificate) {
+ // This file has already been added to the build so don't copy it
+ std::string keyFile =
+ this->DefaultArtifactDir + "/Windows_TemporaryKey.pfx";
+ ConvertToWindowsSlash(keyFile);
+ Elem(e1, "None").Attribute("Include", keyFile);
+ }
}
bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
@@ -4296,13 +4688,63 @@ bool cmVisualStudio10TargetGenerator::ForceOld(const std::string& source) const
return true;
}
+void cmVisualStudio10TargetGenerator::GetCSharpSourceProperties(
+ cmSourceFile const* sf, std::map<std::string, std::string>& tags)
+{
+ if (this->ProjectType == csproj) {
+ const cmPropertyMap& props = sf->GetProperties();
+ for (auto const& p : props) {
+ static const std::string propNamePrefix = "VS_CSHARP_";
+ if (p.first.find(propNamePrefix) == 0) {
+ std::string tagName = p.first.substr(propNamePrefix.length());
+ if (!tagName.empty()) {
+ const std::string val = props.GetPropertyValue(p.first);
+ if (!val.empty()) {
+ tags[tagName] = val;
+ } else {
+ tags.erase(tagName);
+ }
+ }
+ }
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WriteCSharpSourceProperties(
+ Elem& e2, const std::map<std::string, std::string>& tags)
+{
+ for (const auto& i : tags) {
+ e2.Element(i.first.c_str(), i.second);
+ }
+}
+
+void cmVisualStudio10TargetGenerator::GetCSharpSourceLink(
+ cmSourceFile const* sf, std::string& link)
+{
+ std::string const& sourceFilePath = sf->GetFullPath();
+ std::string const& binaryDir = LocalGenerator->GetCurrentBinaryDirectory();
+
+ if (!cmSystemTools::IsSubDirectory(sourceFilePath, binaryDir)) {
+ const std::string& stripFromPath =
+ this->Makefile->GetCurrentSourceDirectory();
+ if (sourceFilePath.find(stripFromPath) == 0) {
+ if (const char* l = sf->GetProperty("VS_CSHARP_Link")) {
+ link = l;
+ } else {
+ link = sourceFilePath.substr(stripFromPath.length() + 1);
+ }
+ ConvertToWindowsSlash(link);
+ }
+ }
+}
+
std::string cmVisualStudio10TargetGenerator::GetCMakeFilePath(
const char* relativeFilePath) const
{
// Always search in the standard modules location.
std::string path = cmSystemTools::GetCMakeRoot() + "/";
path += relativeFilePath;
- this->ConvertToWindowsSlash(path);
+ ConvertToWindowsSlash(path);
return path;
}
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index 61066158c..d453d1a13 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -3,10 +3,11 @@
#ifndef cmVisualStudioTargetGenerator_h
#define cmVisualStudioTargetGenerator_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
+#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -16,11 +17,11 @@ class cmCustomCommand;
class cmGeneratedFileStream;
class cmGeneratorTarget;
class cmGlobalVisualStudio10Generator;
-class cmLocalVisualStudio7Generator;
+class cmLocalVisualStudio10Generator;
class cmMakefile;
class cmSourceFile;
class cmSourceGroup;
-class cmVisualStudioGeneratorOptions;
+class cmVS10GeneratorOptions;
class cmVisualStudio10TargetGenerator
{
@@ -28,11 +29,13 @@ public:
cmVisualStudio10TargetGenerator(cmGeneratorTarget* target,
cmGlobalVisualStudio10Generator* gg);
~cmVisualStudio10TargetGenerator();
+
+ cmVisualStudio10TargetGenerator(cmVisualStudio10TargetGenerator const&) =
+ delete;
+ cmVisualStudio10TargetGenerator& operator=(
+ cmVisualStudio10TargetGenerator const&) = delete;
+
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
@@ -50,102 +53,124 @@ private:
std::vector<std::string> Configs;
};
+ struct Elem;
+ struct OptionsHelper;
+
std::string ConvertPath(std::string const& path, bool forceRelative);
- static void ConvertToWindowsSlash(std::string& s);
- void WriteString(const char* line, int indentLevel);
- void WriteProjectConfigurations();
- void WriteProjectConfigurationValues();
- void WriteMSToolConfigurationValues(std::string const& config);
- void WriteMSToolConfigurationValuesManaged(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 WriteExcludeFromBuild(std::vector<size_t> const& exclude_configs);
- void WriteAllSources();
- void WriteDotNetReferences();
- void WriteDotNetReference(std::string const& ref, std::string const& hint);
- void WriteEmbeddedResourceGroup();
- void WriteWinRTReferences();
- void WriteWinRTPackageCertificateKeyFile();
- void WriteXamlFilesGroup();
- void WritePathAndIncrementalLinkOptions();
- void WriteItemDefinitionGroups();
+ std::string CalcCondition(const std::string& config) const;
+ void WriteProjectConfigurations(Elem& e0);
+ void WriteProjectConfigurationValues(Elem& e0);
+ void WriteMSToolConfigurationValues(Elem& e1, std::string const& config);
+ void WriteCEDebugProjectConfigurationValues(Elem& e0);
+ void WriteMSToolConfigurationValuesManaged(Elem& e1,
+ std::string const& config);
+ void WriteHeaderSource(Elem& e1, cmSourceFile const* sf);
+ void WriteExtraSource(Elem& e1, cmSourceFile const* sf);
+ void WriteNsightTegraConfigurationValues(Elem& e1,
+ std::string const& config);
+ void WriteSource(Elem& e2, cmSourceFile const* sf);
+ void WriteExcludeFromBuild(Elem& e2,
+ std::vector<size_t> const& exclude_configs);
+ void WriteAllSources(Elem& e0);
+ void WritePackageReferences(Elem& e0);
+ void WritePackageReference(Elem& e1, std::string const& ref,
+ std::string const& version);
+ void WriteDotNetReferences(Elem& e0);
+ void WriteDotNetReference(Elem& e1, std::string const& ref,
+ std::string const& hint,
+ std::string const& config);
+ void WriteImports(Elem& e0);
+ void WriteDotNetReferenceCustomTags(Elem& e2, std::string const& ref);
+ void WriteEmbeddedResourceGroup(Elem& e0);
+ void WriteWinRTReferences(Elem& e0);
+ void WriteWinRTPackageCertificateKeyFile(Elem& e0);
+ void WriteXamlFilesGroup(Elem& e0);
+ void WritePathAndIncrementalLinkOptions(Elem& e0);
+ void WriteItemDefinitionGroups(Elem& e0);
void VerifyNecessaryFiles();
- void WriteMissingFiles();
- void WriteMissingFilesWP80();
- void WriteMissingFilesWP81();
- void WriteMissingFilesWS80();
- void WriteMissingFilesWS81();
- void WriteMissingFilesWS10_0();
- void WritePlatformExtensions();
- void WriteSinglePlatformExtension(std::string const& extension,
+ void WriteMissingFiles(Elem& e1);
+ void WriteMissingFilesWP80(Elem& e1);
+ void WriteMissingFilesWP81(Elem& e1);
+ void WriteMissingFilesWS80(Elem& e1);
+ void WriteMissingFilesWS81(Elem& e1);
+ void WriteMissingFilesWS10_0(Elem& e1);
+ void WritePlatformExtensions(Elem& e1);
+ void WriteSinglePlatformExtension(Elem& e1, std::string const& extension,
std::string const& version);
- void WriteSDKReferences();
- void WriteSingleSDKReference(std::string const& extension,
+ void WriteSDKReferences(Elem& e0);
+ void WriteSingleSDKReference(Elem& e1, std::string const& extension,
std::string const& version);
- void WriteCommonMissingFiles(const std::string& manifestFile);
- void WriteTargetSpecificReferences();
- void WriteTargetsFileReferences();
+ void WriteCommonMissingFiles(Elem& e1, const std::string& manifestFile);
+ void WriteTargetSpecificReferences(Elem& e0);
+ void WriteTargetsFileReferences(Elem& e1);
+
+ std::vector<std::string> GetIncludes(std::string const& config,
+ std::string const& lang) const;
bool ComputeClOptions();
bool ComputeClOptions(std::string const& configName);
- void WriteClOptions(std::string const& config,
- std::vector<std::string> const& includes);
+ void WriteClOptions(Elem& e1, std::string const& config);
bool ComputeRcOptions();
bool ComputeRcOptions(std::string const& config);
- void WriteRCOptions(std::string const& config,
- std::vector<std::string> const& includes);
+ void WriteRCOptions(Elem& e1, std::string const& config);
bool ComputeCudaOptions();
bool ComputeCudaOptions(std::string const& config);
- void WriteCudaOptions(std::string const& config,
- std::vector<std::string> const& includes);
+ void WriteCudaOptions(Elem& e1, std::string const& config);
bool ComputeCudaLinkOptions();
bool ComputeCudaLinkOptions(std::string const& config);
- void WriteCudaLinkOptions(std::string const& config);
+ void WriteCudaLinkOptions(Elem& e1, std::string const& config);
bool ComputeMasmOptions();
bool ComputeMasmOptions(std::string const& config);
- void WriteMasmOptions(std::string const& config,
- std::vector<std::string> const& includes);
+ void WriteMasmOptions(Elem& e1, std::string const& config);
bool ComputeNasmOptions();
bool ComputeNasmOptions(std::string const& config);
- void WriteNasmOptions(std::string const& config,
- std::vector<std::string> includes);
+ void WriteNasmOptions(Elem& e1, std::string const& config);
bool ComputeLinkOptions();
bool ComputeLinkOptions(std::string const& config);
bool ComputeLibOptions();
bool ComputeLibOptions(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,
+ void WriteLinkOptions(Elem& e1, std::string const& config);
+ void WriteMidlOptions(Elem& e1, std::string const& config);
+ void WriteAntBuildOptions(Elem& e1, std::string const& config);
+ void OutputLinkIncremental(Elem& e1, std::string const& configName);
+ void WriteCustomRule(Elem& e0, cmSourceFile const* source,
cmCustomCommand const& command);
- void WriteCustomCommands();
- void WriteCustomCommand(cmSourceFile const* sf);
+ void WriteCustomRuleCpp(Elem& e2, std::string const& config,
+ std::string const& script,
+ std::string const& additional_inputs,
+ std::string const& outputs,
+ std::string const& comment, bool symbolic);
+ void WriteCustomRuleCSharp(Elem& e0, std::string const& config,
+ std::string const& commandName,
+ std::string const& script,
+ std::string const& inputs,
+ std::string const& outputs,
+ std::string const& comment);
+ void WriteCustomCommands(Elem& e0);
+ void WriteCustomCommand(Elem& e0, cmSourceFile const* sf);
void WriteGroups();
- void WriteProjectReferences();
- void WriteApplicationTypeSettings();
- bool OutputSourceSpecificFlags(cmSourceFile const* source);
- void AddLibraries(cmComputeLinkInformation& cli,
+ void WriteProjectReferences(Elem& e0);
+ void WriteApplicationTypeSettings(Elem& e1);
+ void OutputSourceSpecificFlags(Elem& e2, cmSourceFile const* source);
+ void AddLibraries(const cmComputeLinkInformation& cli,
std::vector<std::string>& libVec,
- std::vector<std::string>& vsTargetVec);
+ std::vector<std::string>& vsTargetVec,
+ const std::string& config);
void AddTargetsFileAndConfigPair(std::string const& targetsFile,
std::string const& config);
- void WriteLibOptions(std::string const& config);
- void WriteManifestOptions(std::string const& config);
- void WriteEvents(std::string const& configName);
- void WriteEvent(const char* name,
+ void WriteLibOptions(Elem& e1, std::string const& config);
+ void WriteManifestOptions(Elem& e1, std::string const& config);
+ void WriteEvents(Elem& e1, std::string const& configName);
+ void WriteEvent(Elem& e1, const char* name,
std::vector<cmCustomCommand> const& commands,
std::string const& configName);
- void WriteGroupSources(const char* name, ToolSources const& sources,
+ void WriteGroupSources(Elem& e0, std::string const& name,
+ ToolSources const& sources,
std::vector<cmSourceGroup>&);
- void AddMissingSourceGroups(std::set<cmSourceGroup*>& groupsUsed,
+ void AddMissingSourceGroups(std::set<cmSourceGroup const*>& groupsUsed,
const std::vector<cmSourceGroup>& allGroups);
bool IsResxHeader(const std::string& headerFile);
bool IsXamlHeader(const std::string& headerFile);
@@ -153,9 +178,16 @@ private:
bool ForceOld(const std::string& source) const;
+ void GetCSharpSourceProperties(cmSourceFile const* sf,
+ std::map<std::string, std::string>& tags);
+ void WriteCSharpSourceProperties(
+ Elem& e2, const std::map<std::string, std::string>& tags);
+ void GetCSharpSourceLink(cmSourceFile const* sf, std::string& link);
+
private:
- typedef cmVisualStudioGeneratorOptions Options;
- typedef std::map<std::string, Options*> OptionsMap;
+ friend class cmVS10GeneratorOptions;
+ typedef cmVS10GeneratorOptions Options;
+ typedef std::map<std::string, std::unique_ptr<Options>> OptionsMap;
OptionsMap ClOptions;
OptionsMap RcOptions;
OptionsMap CudaOptions;
@@ -163,8 +195,7 @@ private:
OptionsMap MasmOptions;
OptionsMap NasmOptions;
OptionsMap LinkOptions;
- std::string PathToProjectFile;
- std::string ProjectFileExtension;
+ std::string LangForClCompile;
enum VsProjectType
{
vcxproj,
@@ -173,23 +204,34 @@ private:
bool InSourceBuild;
std::vector<std::string> Configurations;
std::vector<TargetsFileAndConfigs> TargetsFileAndConfigsVec;
- cmGeneratorTarget* GeneratorTarget;
- cmMakefile* Makefile;
- std::string Platform;
- std::string GUID;
- std::string Name;
+ cmGeneratorTarget* const GeneratorTarget;
+ cmMakefile* const Makefile;
+ std::string const Platform;
+ std::string const Name;
+ std::string const GUID;
bool MSTools;
bool Managed;
bool NsightTegra;
- int NsightTegraVersion[4];
+ unsigned int NsightTegraVersion[4];
bool TargetCompileAsWinRT;
- cmGlobalVisualStudio10Generator* GlobalGenerator;
- cmGeneratedFileStream* BuildFileStream;
- cmLocalVisualStudio7Generator* LocalGenerator;
- std::set<cmSourceFile const*> SourcesVisited;
+ std::set<std::string> IPOEnabledConfigurations;
+ std::map<std::string, std::string> SpectreMitigation;
+ cmGlobalVisualStudio10Generator* const GlobalGenerator;
+ cmLocalVisualStudio10Generator* const LocalGenerator;
+ std::set<std::string> CSharpCustomCommandNames;
bool IsMissingFiles;
std::vector<std::string> AddedFiles;
std::string DefaultArtifactDir;
+ bool AddedDefaultCertificate = false;
+ // managed C++/C# relevant members
+ typedef std::pair<std::string, std::string> DotNetHintReference;
+ typedef std::vector<DotNetHintReference> DotNetHintReferenceList;
+ typedef std::map<std::string, DotNetHintReferenceList>
+ DotNetHintReferenceMap;
+ DotNetHintReferenceMap DotNetHintReferences;
+ typedef std::set<std::string> UsingDirectories;
+ typedef std::map<std::string, UsingDirectories> UsingDirectoriesMap;
+ UsingDirectoriesMap AdditionalUsingDirectories;
typedef std::map<std::string, ToolSources> ToolSourceMap;
ToolSourceMap Tools;
diff --git a/Source/cmVisualStudio10ToolsetOptions.cxx b/Source/cmVisualStudio10ToolsetOptions.cxx
index 9a1d95078..7fc33e63e 100644
--- a/Source/cmVisualStudio10ToolsetOptions.cxx
+++ b/Source/cmVisualStudio10ToolsetOptions.cxx
@@ -6,145 +6,126 @@
#include "cmIDEFlagTable.h"
#include "cmVisualStudioGeneratorOptions.h"
-#include "cmVS10CLFlagTable.h"
-#include "cmVS10CSharpFlagTable.h"
-#include "cmVS10LibFlagTable.h"
-#include "cmVS10LinkFlagTable.h"
-#include "cmVS10MASMFlagTable.h"
-#include "cmVS10RCFlagTable.h"
-#include "cmVS11CLFlagTable.h"
-#include "cmVS11CSharpFlagTable.h"
-#include "cmVS11LibFlagTable.h"
-#include "cmVS11LinkFlagTable.h"
-#include "cmVS11MASMFlagTable.h"
-#include "cmVS11RCFlagTable.h"
-#include "cmVS12CLFlagTable.h"
-#include "cmVS12CSharpFlagTable.h"
-#include "cmVS12LibFlagTable.h"
-#include "cmVS12LinkFlagTable.h"
-#include "cmVS12MASMFlagTable.h"
-#include "cmVS12RCFlagTable.h"
-#include "cmVS140CLFlagTable.h"
-#include "cmVS140CSharpFlagTable.h"
-#include "cmVS140LinkFlagTable.h"
-#include "cmVS141CLFlagTable.h"
-#include "cmVS141CSharpFlagTable.h"
-#include "cmVS141LinkFlagTable.h"
-#include "cmVS14LibFlagTable.h"
-#include "cmVS14MASMFlagTable.h"
-#include "cmVS14RCFlagTable.h"
-
-cmIDEFlagTable const* cmVisualStudio10ToolsetOptions::GetClFlagTable(
+std::string cmVisualStudio10ToolsetOptions::GetClFlagTableName(
std::string const& name, std::string const& toolset) const
{
std::string const useToolset = this->GetToolsetName(name, toolset);
- if (toolset == "v141") {
- return cmVS141CLFlagTable;
+ if (toolset == "v142") {
+ return "v142";
+ } else if (toolset == "v141") {
+ return "v141";
} else if (useToolset == "v140") {
- return cmVS140CLFlagTable;
+ return "v140";
} else if (useToolset == "v120") {
- return cmVS12CLFlagTable;
+ return "v12";
} else if (useToolset == "v110") {
- return cmVS11CLFlagTable;
+ return "v11";
} else if (useToolset == "v100") {
- return cmVS10CLFlagTable;
+ return "v10";
} else {
- return 0;
+ return "";
}
}
-cmIDEFlagTable const* cmVisualStudio10ToolsetOptions::GetCSharpFlagTable(
+std::string cmVisualStudio10ToolsetOptions::GetCSharpFlagTableName(
std::string const& name, std::string const& toolset) const
{
std::string const useToolset = this->GetToolsetName(name, toolset);
- if ((useToolset == "v141")) {
- return cmVS141CSharpFlagTable;
+ if (useToolset == "v142") {
+ return "v142";
+ } else if (useToolset == "v141") {
+ return "v141";
} else if (useToolset == "v140") {
- return cmVS140CSharpFlagTable;
+ return "v140";
} else if (useToolset == "v120") {
- return cmVS12CSharpFlagTable;
+ return "v12";
} else if (useToolset == "v110") {
- return cmVS11CSharpFlagTable;
+ return "v11";
} else if (useToolset == "v100") {
- return cmVS10CSharpFlagTable;
+ return "v10";
} else {
- return 0;
+ return "";
}
}
-cmIDEFlagTable const* cmVisualStudio10ToolsetOptions::GetRcFlagTable(
+std::string cmVisualStudio10ToolsetOptions::GetRcFlagTableName(
std::string const& name, std::string const& toolset) const
{
std::string const useToolset = this->GetToolsetName(name, toolset);
- if ((useToolset == "v140") || (useToolset == "v141")) {
- return cmVS14RCFlagTable;
+ if ((useToolset == "v140") || (useToolset == "v141") ||
+ (useToolset == "v142")) {
+ return "v14";
} else if (useToolset == "v120") {
- return cmVS12RCFlagTable;
+ return "v12";
} else if (useToolset == "v110") {
- return cmVS11RCFlagTable;
+ return "v11";
} else if (useToolset == "v100") {
- return cmVS10RCFlagTable;
+ return "v10";
} else {
- return 0;
+ return "";
}
}
-cmIDEFlagTable const* cmVisualStudio10ToolsetOptions::GetLibFlagTable(
+std::string cmVisualStudio10ToolsetOptions::GetLibFlagTableName(
std::string const& name, std::string const& toolset) const
{
std::string const useToolset = this->GetToolsetName(name, toolset);
- if ((useToolset == "v140") || (useToolset == "v141")) {
- return cmVS14LibFlagTable;
+ if ((useToolset == "v140") || (useToolset == "v141") ||
+ (useToolset == "v142")) {
+ return "v14";
} else if (useToolset == "v120") {
- return cmVS12LibFlagTable;
+ return "v12";
} else if (useToolset == "v110") {
- return cmVS11LibFlagTable;
+ return "v11";
} else if (useToolset == "v100") {
- return cmVS10LibFlagTable;
+ return "v10";
} else {
- return 0;
+ return "";
}
}
-cmIDEFlagTable const* cmVisualStudio10ToolsetOptions::GetLinkFlagTable(
+std::string cmVisualStudio10ToolsetOptions::GetLinkFlagTableName(
std::string const& name, std::string const& toolset) const
{
std::string const useToolset = this->GetToolsetName(name, toolset);
- if (useToolset == "v141") {
- return cmVS141LinkFlagTable;
+ if (useToolset == "v142") {
+ return "v142";
+ } else if (useToolset == "v141") {
+ return "v141";
} else if (useToolset == "v140") {
- return cmVS140LinkFlagTable;
+ return "v140";
} else if (useToolset == "v120") {
- return cmVS12LinkFlagTable;
+ return "v12";
} else if (useToolset == "v110") {
- return cmVS11LinkFlagTable;
+ return "v11";
} else if (useToolset == "v100") {
- return cmVS10LinkFlagTable;
+ return "v10";
} else {
- return 0;
+ return "";
}
}
-cmIDEFlagTable const* cmVisualStudio10ToolsetOptions::GetMasmFlagTable(
+std::string cmVisualStudio10ToolsetOptions::GetMasmFlagTableName(
std::string const& name, std::string const& toolset) const
{
std::string const useToolset = this->GetToolsetName(name, toolset);
- if ((useToolset == "v140") || (useToolset == "v141")) {
- return cmVS14MASMFlagTable;
+ if ((useToolset == "v140") || (useToolset == "v141") ||
+ (useToolset == "v142")) {
+ return "v14";
} else if (useToolset == "v120") {
- return cmVS12MASMFlagTable;
+ return "v12";
} else if (useToolset == "v110") {
- return cmVS11MASMFlagTable;
+ return "v11";
} else if (useToolset == "v100") {
- return cmVS10MASMFlagTable;
+ return "v10";
} else {
- return 0;
+ return "";
}
}
diff --git a/Source/cmVisualStudio10ToolsetOptions.h b/Source/cmVisualStudio10ToolsetOptions.h
index 4233337ba..875a35b24 100644
--- a/Source/cmVisualStudio10ToolsetOptions.h
+++ b/Source/cmVisualStudio10ToolsetOptions.h
@@ -3,12 +3,10 @@
#ifndef cmVisualStudio10ToolsetOptions_h
#define cmVisualStudio10ToolsetOptions_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
-struct cmIDEFlagTable;
-
/** \class cmVisualStudio10ToolsetOptions
* \brief Retrieves toolset options for MSBuild.
*
@@ -17,20 +15,18 @@ struct cmIDEFlagTable;
class cmVisualStudio10ToolsetOptions
{
public:
- cmIDEFlagTable const* GetClFlagTable(std::string const& name,
- std::string const& toolset) const;
- cmIDEFlagTable const* GetCSharpFlagTable(std::string const& name,
- std::string const& toolset) const;
- cmIDEFlagTable const* GetRcFlagTable(std::string const& name,
- std::string const& toolset) const;
- cmIDEFlagTable const* GetLibFlagTable(std::string const& name,
- std::string const& toolset) const;
- cmIDEFlagTable const* GetLinkFlagTable(std::string const& name,
- std::string const& toolset) const;
- cmIDEFlagTable const* GetMasmFlagTable(std::string const& name,
- std::string const& toolset) const;
-
-private:
+ std::string GetClFlagTableName(std::string const& name,
+ std::string const& toolset) const;
+ std::string GetCSharpFlagTableName(std::string const& name,
+ std::string const& toolset) const;
+ std::string GetRcFlagTableName(std::string const& name,
+ std::string const& toolset) const;
+ std::string GetLibFlagTableName(std::string const& name,
+ std::string const& toolset) const;
+ std::string GetLinkFlagTableName(std::string const& name,
+ std::string const& toolset) const;
+ std::string GetMasmFlagTableName(std::string const& name,
+ std::string const& toolset) const;
std::string GetToolsetName(std::string const& name,
std::string const& toolset) const;
};
diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx
index 1f808c8b2..e1b0c70b6 100644
--- a/Source/cmVisualStudioGeneratorOptions.cxx
+++ b/Source/cmVisualStudioGeneratorOptions.cxx
@@ -4,58 +4,19 @@
#include "cmLocalVisualStudioGenerator.h"
#include "cmOutputConverter.h"
#include "cmSystemTools.h"
-#include "cmVisualStudio10TargetGenerator.h"
-static std::string cmVisualStudio10GeneratorOptionsEscapeForXML(
- std::string ret)
+static void cmVS10EscapeForMSBuild(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,
- cmVisualStudio10TargetGenerator* g)
- : cmIDEOptions()
- , LocalGenerator(lg)
- , Version(lg->GetVersion())
- , CurrentTool(tool)
- , TargetGenerator(g)
-{
- // 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;
-
- this->UnknownFlagField = "AdditionalOptions";
}
cmVisualStudioGeneratorOptions::cmVisualStudioGeneratorOptions(
cmLocalVisualStudioGenerator* lg, Tool tool, cmVS7FlagTable const* table,
- cmVS7FlagTable const* extraTable, cmVisualStudio10TargetGenerator* g)
+ cmVS7FlagTable const* extraTable)
: cmIDEOptions()
, LocalGenerator(lg)
, Version(lg->GetVersion())
, CurrentTool(tool)
- , TargetGenerator(g)
{
// Store the given flag tables.
this->AddTable(table);
@@ -64,6 +25,9 @@ cmVisualStudioGeneratorOptions::cmVisualStudioGeneratorOptions(
// Preprocessor definitions are not allowed for linker tools.
this->AllowDefine = (tool != Linker);
+ // include directories are not allowed for linker tools.
+ this->AllowInclude = (tool != Linker);
+
// Slash options are allowed for VS.
this->AllowSlash = true;
@@ -89,7 +53,7 @@ void cmVisualStudioGeneratorOptions::AddTable(cmVS7FlagTable const* table)
void cmVisualStudioGeneratorOptions::ClearTables()
{
for (int i = 0; i < FlagTableCount; ++i) {
- this->FlagTable[i] = CM_NULLPTR;
+ this->FlagTable[i] = nullptr;
}
}
@@ -106,6 +70,7 @@ void cmVisualStudioGeneratorOptions::FixExceptionHandlingDefault()
case cmGlobalVisualStudioGenerator::VS12:
case cmGlobalVisualStudioGenerator::VS14:
case cmGlobalVisualStudioGenerator::VS15:
+ case cmGlobalVisualStudioGenerator::VS16:
// 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
@@ -163,10 +128,9 @@ bool cmVisualStudioGeneratorOptions::IsManaged() const
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") {
+ // Look for a _UNICODE definition.
+ for (std::string const& di : this->Defines) {
+ if (di == "_UNICODE") {
return true;
}
}
@@ -174,10 +138,9 @@ bool cmVisualStudioGeneratorOptions::UsingUnicode() const
}
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") {
+ // Look for a _SBCS definition.
+ for (std::string const& di : this->Defines) {
+ if (di == "_SBCS") {
return true;
}
}
@@ -239,35 +202,113 @@ void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration()
// It translates to -arch=<virtual> -code=<real>.
cmSystemTools::ReplaceString(arch_name, "sm_", "compute_");
}
- for (std::vector<std::string>::iterator ci = codes.begin();
- ci != codes.end(); ++ci) {
- std::string entry = arch_name + "," + *ci;
+ for (std::string const& c : codes) {
+ std::string entry = arch_name + "," + c;
result.push_back(entry);
}
}
- // Now add entries for the -gencode=<arch>,<code> pairs.
- for (std::vector<std::string>::iterator ei = gencode.begin();
- ei != gencode.end(); ++ei) {
- std::string entry = *ei;
+ // Now add entries for the following signatures:
+ // -gencode=<arch>,<code>
+ // -gencode=<arch>,[<code1>,<code2>]
+ // -gencode=<arch>,"<code1>,<code2>"
+ for (std::string const& e : gencode) {
+ std::string entry = e;
cmSystemTools::ReplaceString(entry, "arch=", "");
cmSystemTools::ReplaceString(entry, "code=", "");
- result.push_back(entry);
+ cmSystemTools::ReplaceString(entry, "[", "");
+ cmSystemTools::ReplaceString(entry, "]", "");
+ cmSystemTools::ReplaceString(entry, "\"", "");
+
+ std::vector<std::string> codes = cmSystemTools::tokenize(entry, ",");
+ if (codes.size() >= 2) {
+ auto gencode_arch = cm::cbegin(codes);
+ for (auto ci = gencode_arch + 1; ci != cm::cend(codes); ++ci) {
+ std::string code_entry = *gencode_arch + "," + *ci;
+ result.push_back(code_entry);
+ }
+ }
+ }
+}
+
+void cmVisualStudioGeneratorOptions::FixManifestUACFlags()
+{
+ static std::string const ENABLE_UAC = "EnableUAC";
+ if (!HasFlag(ENABLE_UAC)) {
+ return;
+ }
+
+ const std::string uacFlag = GetFlag(ENABLE_UAC);
+ std::vector<std::string> subOptions;
+ cmsys::SystemTools::Split(uacFlag, subOptions, ' ');
+ if (subOptions.empty()) {
+ AddFlag(ENABLE_UAC, "true");
+ return;
+ }
+
+ if (subOptions.size() == 1 && subOptions[0] == "NO") {
+ AddFlag(ENABLE_UAC, "false");
+ return;
+ }
+
+ std::map<std::string, std::string> uacMap;
+ uacMap["level"] = "UACExecutionLevel";
+ uacMap["uiAccess"] = "UACUIAccess";
+
+ std::map<std::string, std::string> uacExecuteLevelMap;
+ uacExecuteLevelMap["asInvoker"] = "AsInvoker";
+ uacExecuteLevelMap["highestAvailable"] = "HighestAvailable";
+ uacExecuteLevelMap["requireAdministrator"] = "RequireAdministrator";
+
+ for (std::string const& subopt : subOptions) {
+ std::vector<std::string> keyValue;
+ cmsys::SystemTools::Split(subopt, keyValue, '=');
+ if (keyValue.size() != 2 || (uacMap.find(keyValue[0]) == uacMap.end())) {
+ // ignore none key=value option or unknown flags
+ continue;
+ }
+
+ if (keyValue[1].front() == '\'' && keyValue[1].back() == '\'') {
+ keyValue[1] =
+ keyValue[1].substr(1, std::max(0, cm::isize(keyValue[1]) - 2));
+ }
+
+ if (keyValue[0] == "level") {
+ if (uacExecuteLevelMap.find(keyValue[1]) == uacExecuteLevelMap.end()) {
+ // unknown level value
+ continue;
+ }
+
+ AddFlag(uacMap[keyValue[0]], uacExecuteLevelMap[keyValue[1]]);
+ continue;
+ }
+
+ if (keyValue[0] == "uiAccess") {
+ if (keyValue[1] != "true" && keyValue[1] != "false") {
+ // unknown uiAccess value
+ continue;
+ }
+ AddFlag(uacMap[keyValue[0]], keyValue[1]);
+ continue;
+ }
+
+ // unknown sub option
}
+
+ AddFlag(ENABLE_UAC, "true");
}
-void cmVisualStudioGeneratorOptions::Parse(const char* flags)
+void cmVisualStudioGeneratorOptions::Parse(const std::string& 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);
+ cmSystemTools::ParseWindowsCommandLine(flags.c_str(), 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());
+ for (std::string const& ai : args) {
+ this->HandleFlag(ai);
}
}
@@ -326,26 +367,26 @@ void cmVisualStudioGeneratorOptions::Reparse(std::string const& key)
std::string const original = i->second[0];
i->second[0] = "";
this->UnknownFlagField = key;
- this->Parse(original.c_str());
+ this->Parse(original);
}
-void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
+void cmVisualStudioGeneratorOptions::StoreUnknownFlag(std::string const& flag)
{
// Look for Intel Fortran flags that do not map well in the flag table.
if (this->CurrentTool == FortranCompiler) {
- if (strcmp(flag, "/dbglibs") == 0) {
+ if (flag == "/dbglibs" || flag == "-dbglibs") {
this->FortranRuntimeDebug = true;
return;
}
- if (strcmp(flag, "/threads") == 0) {
+ if (flag == "/threads" || flag == "-threads") {
this->FortranRuntimeMT = true;
return;
}
- if (strcmp(flag, "/libs:dll") == 0) {
+ if (flag == "/libs:dll" || flag == "-libs:dll") {
this->FortranRuntimeDLL = true;
return;
}
- if (strcmp(flag, "/libs:static") == 0) {
+ if (flag == "/libs:static" || flag == "-libs:static") {
this->FortranRuntimeDLL = false;
return;
}
@@ -353,7 +394,8 @@ void cmVisualStudioGeneratorOptions::StoreUnknownFlag(const char* flag)
// This option is not known. Store it in the output flags.
std::string const opts = cmOutputConverter::EscapeWindowsShellArgument(
- flag, cmOutputConverter::Shell_Flag_AllowMakeVariables |
+ flag.c_str(),
+ cmOutputConverter::Shell_Flag_AllowMakeVariables |
cmOutputConverter::Shell_Flag_VSIDE);
this->AppendFlagString(this->UnknownFlagField, opts);
}
@@ -370,14 +412,19 @@ cmIDEOptions::FlagValue cmVisualStudioGeneratorOptions::TakeFlag(
return value;
}
-void cmVisualStudioGeneratorOptions::SetConfiguration(const char* config)
+void cmVisualStudioGeneratorOptions::SetConfiguration(
+ const std::string& config)
{
this->Configuration = config;
}
+const std::string& cmVisualStudioGeneratorOptions::GetConfiguration() const
+{
+ return this->Configuration;
+}
+
void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions(
- std::ostream& fout, const char* prefix, const char* suffix,
- const std::string& lang)
+ std::ostream& fout, int indent, const std::string& lang)
{
if (this->Defines.empty()) {
return;
@@ -386,84 +433,99 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions(
if (lang == "CUDA") {
tag = "Defines";
}
- if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
- // if there are configuration specific flags, then
- // use the configuration specific tag for PreprocessorDefinitions
- if (!this->Configuration.empty()) {
- fout << prefix;
- this->TargetGenerator->WritePlatformConfigTag(
- tag, this->Configuration.c_str(), 0, 0, 0, &fout);
- } else {
- fout << prefix << "<" << tag << ">";
- }
- } else {
- fout << prefix << tag << "=\"";
- }
+
+ std::ostringstream oss;
const char* sep = "";
std::vector<std::string>::const_iterator de =
cmRemoveDuplicates(this->Defines);
- for (std::vector<std::string>::const_iterator di = this->Defines.begin();
- di != de; ++di) {
+ for (std::string const& di : cmMakeRange(this->Defines.cbegin(), de)) {
// Escape the definition for the compiler.
std::string define;
if (this->Version < cmGlobalVisualStudioGenerator::VS10) {
- define = this->LocalGenerator->EscapeForShell(di->c_str(), true);
+ define = this->LocalGenerator->EscapeForShell(di, true);
} else {
- define = *di;
+ define = di;
}
- // Escape this flag for the IDE.
+ // Escape this flag for the MSBuild.
if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
- define = cmVisualStudio10GeneratorOptionsEscapeForXML(define);
-
+ cmVS10EscapeForMSBuild(define);
if (lang == "RC") {
cmSystemTools::ReplaceString(define, "\"", "\\\"");
}
- } else {
- define = cmVisualStudioGeneratorOptionsEscapeForXML(define);
}
// Store the flag in the project file.
- fout << sep << define;
+ oss << sep << define;
sep = ";";
}
if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
- fout << ";%(" << tag << ")</" << tag << ">" << suffix;
- } else {
- fout << "\"" << suffix;
+ oss << ";%(" << tag << ")";
}
+
+ this->OutputFlag(fout, indent, tag, oss.str());
}
-void cmVisualStudioGeneratorOptions::OutputFlagMap(std::ostream& fout,
- const char* indent)
+void cmVisualStudioGeneratorOptions::OutputAdditionalIncludeDirectories(
+ std::ostream& fout, int indent, const std::string& lang)
{
- if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
- for (std::map<std::string, FlagValue>::iterator m = this->FlagMap.begin();
- m != this->FlagMap.end(); ++m) {
- fout << indent;
- if (!this->Configuration.empty()) {
- 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";
+ if (this->Includes.empty()) {
+ return;
+ }
+
+ const char* tag = "AdditionalIncludeDirectories";
+ if (lang == "CUDA") {
+ tag = "Include";
+ } else if (lang == "ASM_MASM" || lang == "ASM_NASM") {
+ tag = "IncludePaths";
+ }
+
+ std::ostringstream oss;
+ const char* sep = "";
+ for (std::string include : this->Includes) {
+ // first convert all of the slashes
+ std::string::size_type pos = 0;
+ while ((pos = include.find('/', pos)) != std::string::npos) {
+ include[pos] = '\\';
+ pos++;
+ }
+
+ if (lang == "ASM_NASM") {
+ include += "\\";
+ }
+
+ // Escape this include for the MSBuild.
+ if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
+ cmVS10EscapeForMSBuild(include);
+ }
+ oss << sep << include;
+ sep = ";";
+
+ if (lang == "Fortran") {
+ include += "/$(ConfigurationName)";
+ oss << sep << include;
}
- } 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 = ";";
+ }
+
+ if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
+ oss << sep << "%(" << tag << ")";
+ }
+
+ this->OutputFlag(fout, indent, tag, oss.str());
+}
+
+void cmVisualStudioGeneratorOptions::OutputFlagMap(std::ostream& fout,
+ int indent)
+{
+ for (auto const& m : this->FlagMap) {
+ std::ostringstream oss;
+ const char* sep = "";
+ for (std::string i : m.second) {
+ if (this->Version >= cmGlobalVisualStudioGenerator::VS10) {
+ cmVS10EscapeForMSBuild(i);
}
- fout << "\"\n";
+ oss << sep << i;
+ sep = ";";
}
+
+ this->OutputFlag(fout, indent, m.first.c_str(), oss.str());
}
}
diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h
index 44d271908..a30a67fc2 100644
--- a/Source/cmVisualStudioGeneratorOptions.h
+++ b/Source/cmVisualStudioGeneratorOptions.h
@@ -3,7 +3,7 @@
#ifndef cmVisualStudioGeneratorOptions_h
#define cmVisualStudioGeneratorOptions_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
@@ -16,8 +16,6 @@ class cmLocalVisualStudioGenerator;
typedef cmIDEFlagTable cmVS7FlagTable;
-class cmVisualStudio10TargetGenerator;
-
class cmVisualStudioGeneratorOptions : public cmIDEOptions
{
public:
@@ -34,12 +32,8 @@ public:
CSharpCompiler
};
cmVisualStudioGeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool,
- cmVS7FlagTable const* table,
- cmVS7FlagTable const* extraTable = 0,
- cmVisualStudio10TargetGenerator* g = 0);
-
- cmVisualStudioGeneratorOptions(cmLocalVisualStudioGenerator* lg, Tool tool,
- cmVisualStudio10TargetGenerator* g = 0);
+ cmVS7FlagTable const* table = nullptr,
+ cmVS7FlagTable const* extraTable = nullptr);
// Add a table of flags.
void AddTable(cmVS7FlagTable const* table);
@@ -48,7 +42,7 @@ public:
void ClearTables();
// Store options from command line flags.
- void Parse(const char* flags);
+ void Parse(const std::string& flags);
void ParseFinish();
void PrependInheritedString(std::string const& key);
@@ -77,15 +71,23 @@ public:
void FixCudaCodeGeneration();
+ void FixManifestUACFlags();
+
bool IsDebug() const;
bool IsWinRt() const;
bool IsManaged() const;
// Write options to output.
- void OutputPreprocessorDefinitions(std::ostream& fout, const char* prefix,
- const char* suffix,
+ void OutputPreprocessorDefinitions(std::ostream& fout, int indent,
const std::string& lang);
- void OutputFlagMap(std::ostream& fout, const char* indent);
- void SetConfiguration(const char* config);
+ void OutputAdditionalIncludeDirectories(std::ostream& fout, int indent,
+ const std::string& lang);
+ void OutputFlagMap(std::ostream& fout, int indent);
+ void SetConfiguration(const std::string& config);
+ const std::string& GetConfiguration() const;
+
+protected:
+ virtual void OutputFlag(std::ostream& fout, int indent, const char* tag,
+ const std::string& content) = 0;
private:
cmLocalVisualStudioGenerator* LocalGenerator;
@@ -93,7 +95,6 @@ private:
std::string Configuration;
Tool CurrentTool;
- cmVisualStudio10TargetGenerator* TargetGenerator;
bool FortranRuntimeDebug;
bool FortranRuntimeDLL;
@@ -101,7 +102,7 @@ private:
std::string UnknownFlagField;
- virtual void StoreUnknownFlag(const char* flag);
+ void StoreUnknownFlag(std::string const& flag) override;
FlagValue TakeFlag(std::string const& key);
};
diff --git a/Source/cmVisualStudioSlnData.h b/Source/cmVisualStudioSlnData.h
index e12047fb5..9c1dffc05 100644
--- a/Source/cmVisualStudioSlnData.h
+++ b/Source/cmVisualStudioSlnData.h
@@ -3,7 +3,7 @@
#ifndef cmVisualStudioSlnData_h
#define cmVisualStudioSlnData_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
#include <string>
diff --git a/Source/cmVisualStudioSlnParser.cxx b/Source/cmVisualStudioSlnParser.cxx
index 1a32abacf..93532765f 100644
--- a/Source/cmVisualStudioSlnParser.cxx
+++ b/Source/cmVisualStudioSlnParser.cxx
@@ -329,7 +329,7 @@ bool cmVisualStudioSlnParser::State::Process(
case FileStateIgnore:
if (line.GetTag() == this->EndIgnoreTag) {
this->Stack.pop();
- this->EndIgnoreTag = "";
+ this->EndIgnoreTag.clear();
}
break;
default:
@@ -602,8 +602,8 @@ bool cmVisualStudioSlnParser::ParseTag(const std::string& fullTag,
}
const std::string& arg = cmSystemTools::TrimWhitespace(
fullTag.substr(idxLeftParen + 1, idxRightParen - idxLeftParen - 1));
- if (arg[0] == '"') {
- if (arg[arg.size() - 1] != '"') {
+ if (arg.front() == '"') {
+ if (arg.back() != '"') {
this->LastResult.SetError(ResultErrorInputStructure,
state.GetCurrentLine());
return false;
@@ -620,7 +620,7 @@ bool cmVisualStudioSlnParser::ParseValue(const std::string& value,
const std::string& trimmed = cmSystemTools::TrimWhitespace(value);
if (trimmed.empty())
parsedLine.AddValue(trimmed);
- else if (trimmed[0] == '"' && trimmed[trimmed.size() - 1] == '"')
+ else if (trimmed.front() == '"' && trimmed.back() == '"')
parsedLine.AddQuotedValue(trimmed.substr(1, trimmed.size() - 2));
else
parsedLine.AddValue(trimmed);
diff --git a/Source/cmVisualStudioSlnParser.h b/Source/cmVisualStudioSlnParser.h
index d51732407..d6345a84d 100644
--- a/Source/cmVisualStudioSlnParser.h
+++ b/Source/cmVisualStudioSlnParser.h
@@ -3,7 +3,7 @@
#ifndef cmVisualStudioSlnParser_h
#define cmVisualStudioSlnParser_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <bitset>
#include <iosfwd>
diff --git a/Source/cmVisualStudioWCEPlatformParser.cxx b/Source/cmVisualStudioWCEPlatformParser.cxx
index fc64d0fb0..3b113aadb 100644
--- a/Source/cmVisualStudioWCEPlatformParser.cxx
+++ b/Source/cmVisualStudioWCEPlatformParser.cxx
@@ -56,12 +56,12 @@ void cmVisualStudioWCEPlatformParser::StartElement(const std::string& name,
return;
}
- this->CharacterData = "";
+ this->CharacterData.clear();
if (name == "PlatformData") {
- this->PlatformName = "";
- this->OSMajorVersion = "";
- this->OSMinorVersion = "";
+ this->PlatformName.clear();
+ this->OSMajorVersion.clear();
+ this->OSMinorVersion.clear();
this->Macros.clear();
}
diff --git a/Source/cmVisualStudioWCEPlatformParser.h b/Source/cmVisualStudioWCEPlatformParser.h
index 75c3d1a39..c19691aa2 100644
--- a/Source/cmVisualStudioWCEPlatformParser.h
+++ b/Source/cmVisualStudioWCEPlatformParser.h
@@ -3,7 +3,7 @@
#ifndef cmVisualStudioWCEPlatformParser_h
#define cmVisualStudioWCEPlatformParser_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <map>
#include <stddef.h>
diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx
index 24d7bf1bf..a01fa6f1c 100644
--- a/Source/cmWhileCommand.cxx
+++ b/Source/cmWhileCommand.cxx
@@ -6,9 +6,10 @@
#include "cmExecutionStatus.h"
#include "cmExpandedCommandArgument.h"
#include "cmMakefile.h"
+#include "cmMessageType.h"
#include "cmSystemTools.h"
-#include "cm_auto_ptr.hxx"
-#include "cmake.h"
+
+#include <memory> // IWYU pragma: keep
cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf)
: Makefile(mf)
@@ -27,15 +28,16 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
cmExecutionStatus& inStatus)
{
// at end of for each execute recorded commands
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "while")) {
+ if (lff.Name.Lower == "while") {
// record the number of while commands past this one
this->Depth++;
- } else if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endwhile")) {
+ } else if (lff.Name.Lower == "endwhile") {
// if this is the endwhile for this while loop then execute
if (!this->Depth) {
// Remove the function blocker for this scope or bail.
- CM_AUTO_PTR<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(this, lff));
- if (!fb.get()) {
+ std::unique_ptr<cmFunctionBlocker> fb(
+ mf.RemoveFunctionBlocker(this, lff));
+ if (!fb) {
return false;
}
@@ -43,7 +45,7 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
std::vector<cmExpandedCommandArgument> expandedArguments;
mf.ExpandArguments(this->Args, expandedArguments);
- cmake::MessageType messageType;
+ MessageType messageType;
cmListFileContext execContext = this->GetStartingContext();
@@ -60,27 +62,26 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
while (isTrue) {
if (!errorString.empty()) {
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 ? "\"" : "");
+ for (cmListFileArgument const& arg : this->Args) {
+ err += (arg.Delim ? "\"" : "");
+ err += arg.Value;
+ err += (arg.Delim ? "\"" : "");
err += " ";
}
err += "(";
err += errorString;
err += ").";
mf.IssueMessage(messageType, err);
- if (messageType == cmake::FATAL_ERROR) {
+ if (messageType == MessageType::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) {
+ for (cmListFileFunction const& fn : this->Functions) {
cmExecutionStatus status;
- mf.ExecuteCommand(this->Functions[c], status);
+ mf.ExecuteCommand(fn, status);
if (status.GetReturnInvoked()) {
inStatus.SetReturnInvoked();
return true;
@@ -116,7 +117,7 @@ bool cmWhileFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
bool cmWhileFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
cmMakefile&)
{
- if (!cmSystemTools::Strucmp(lff.Name.c_str(), "endwhile")) {
+ if (lff.Name.Lower == "endwhile") {
// if the endwhile has arguments, then make sure
// they match the arguments of the matching while
if (lff.Arguments.empty() || lff.Arguments == this->Args) {
diff --git a/Source/cmWhileCommand.h b/Source/cmWhileCommand.h
index a95e4c30c..6f6d40549 100644
--- a/Source/cmWhileCommand.h
+++ b/Source/cmWhileCommand.h
@@ -3,7 +3,7 @@
#ifndef cmWhileCommand_h
#define cmWhileCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -19,10 +19,10 @@ class cmWhileFunctionBlocker : public cmFunctionBlocker
{
public:
cmWhileFunctionBlocker(cmMakefile* mf);
- ~cmWhileFunctionBlocker() CM_OVERRIDE;
+ ~cmWhileFunctionBlocker() override;
bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
- cmExecutionStatus&) CM_OVERRIDE;
- bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) CM_OVERRIDE;
+ cmExecutionStatus&) override;
+ bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) override;
std::vector<cmListFileArgument> Args;
std::vector<cmListFileFunction> Functions;
@@ -39,21 +39,21 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmWhileCommand; }
+ cmCommand* Clone() override { return new cmWhileCommand; }
/**
* This overrides the default InvokeInitialPass implementation.
* It records the arguments before expansion.
*/
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
- cmExecutionStatus&) CM_OVERRIDE;
+ cmExecutionStatus&) override;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const&,
- cmExecutionStatus&) CM_OVERRIDE
+ cmExecutionStatus&) override
{
return false;
}
diff --git a/Source/cmWorkingDirectory.cxx b/Source/cmWorkingDirectory.cxx
index 99c9ba86a..816f1044c 100644
--- a/Source/cmWorkingDirectory.cxx
+++ b/Source/cmWorkingDirectory.cxx
@@ -4,10 +4,12 @@
#include "cmSystemTools.h"
+#include <cerrno>
+
cmWorkingDirectory::cmWorkingDirectory(std::string const& newdir)
{
this->OldDir = cmSystemTools::GetCurrentWorkingDirectory();
- cmSystemTools::ChangeDirectory(newdir);
+ this->SetDirectory(newdir);
}
cmWorkingDirectory::~cmWorkingDirectory()
@@ -15,10 +17,20 @@ cmWorkingDirectory::~cmWorkingDirectory()
this->Pop();
}
+bool cmWorkingDirectory::SetDirectory(std::string const& newdir)
+{
+ if (cmSystemTools::ChangeDirectory(newdir) == 0) {
+ this->ResultCode = 0;
+ return true;
+ }
+ this->ResultCode = errno;
+ return false;
+}
+
void cmWorkingDirectory::Pop()
{
if (!this->OldDir.empty()) {
- cmSystemTools::ChangeDirectory(this->OldDir);
+ this->SetDirectory(this->OldDir);
this->OldDir.clear();
}
}
diff --git a/Source/cmWorkingDirectory.h b/Source/cmWorkingDirectory.h
index aff926755..d4a164de6 100644
--- a/Source/cmWorkingDirectory.h
+++ b/Source/cmWorkingDirectory.h
@@ -9,6 +9,12 @@
/** \class cmWorkingDirectory
* \brief An RAII class to manipulate the working directory.
+ *
+ * The current working directory is set to the location given to the
+ * constructor. The working directory can be changed again as needed
+ * by calling SetDirectory(). When the object is destroyed, the destructor
+ * will restore the working directory to what it was when the object was
+ * created, regardless of any calls to SetDirectory() in the meantime.
*/
class cmWorkingDirectory
{
@@ -16,10 +22,24 @@ public:
cmWorkingDirectory(std::string const& newdir);
~cmWorkingDirectory();
+ cmWorkingDirectory(const cmWorkingDirectory&) = delete;
+ cmWorkingDirectory& operator=(const cmWorkingDirectory&) = delete;
+
+ bool SetDirectory(std::string const& newdir);
void Pop();
+ bool Failed() const { return ResultCode != 0; }
+
+ /** \return 0 if the last attempt to set the working directory was
+ * successful. If it failed, the value returned will be the
+ * \c errno value associated with the failure. A description
+ * of the error code can be obtained by passing the result
+ * to \c std::strerror().
+ */
+ int GetLastResult() const { return ResultCode; }
private:
std::string OldDir;
+ int ResultCode;
};
#endif
diff --git a/Source/cmWriteFileCommand.cxx b/Source/cmWriteFileCommand.cxx
index fc5fd2111..49dbf1a19 100644
--- a/Source/cmWriteFileCommand.cxx
+++ b/Source/cmWriteFileCommand.cxx
@@ -33,7 +33,7 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args,
}
}
- if (!this->Makefile->CanIWriteThisFile(fileName.c_str())) {
+ if (!this->Makefile->CanIWriteThisFile(fileName)) {
std::string e =
"attempted to write a file: " + fileName + " into a source directory.";
this->SetError(e);
@@ -42,19 +42,23 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args,
}
std::string dir = cmSystemTools::GetFilenamePath(fileName);
- cmSystemTools::MakeDirectory(dir.c_str());
+ cmSystemTools::MakeDirectory(dir);
mode_t mode = 0;
+ bool writable = false;
// 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
+ writable = (mode & S_IWRITE) != 0;
+ mode_t newMode = mode | S_IWRITE;
#else
- mode | S_IWUSR | S_IWGRP
+ writable = mode & S_IWUSR;
+ mode_t newMode = mode | S_IWUSR | S_IWGRP;
#endif
- );
+ if (!writable) {
+ cmSystemTools::SetPermissions(fileName.c_str(), newMode);
+ }
}
// If GetPermissions fails, pretend like it is ok. File open will fail if
// the file is not writable
@@ -69,7 +73,7 @@ bool cmWriteFileCommand::InitialPass(std::vector<std::string> const& args,
}
file << message << std::endl;
file.close();
- if (mode) {
+ if (mode && !writable) {
cmSystemTools::SetPermissions(fileName.c_str(), mode);
}
diff --git a/Source/cmWriteFileCommand.h b/Source/cmWriteFileCommand.h
index 19922cdf3..9028f84aa 100644
--- a/Source/cmWriteFileCommand.h
+++ b/Source/cmWriteFileCommand.h
@@ -3,7 +3,7 @@
#ifndef cmWriteFileCommand_h
#define cmWriteFileCommand_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
@@ -22,14 +22,14 @@ public:
/**
* This is a virtual constructor for the command.
*/
- cmCommand* Clone() CM_OVERRIDE { return new cmWriteFileCommand; }
+ cmCommand* Clone() override { return new cmWriteFileCommand; }
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) CM_OVERRIDE;
+ cmExecutionStatus& status) override;
};
#endif
diff --git a/Source/cmXCode21Object.cxx b/Source/cmXCode21Object.cxx
index 719e62765..a9bb2ef54 100644
--- a/Source/cmXCode21Object.cxx
+++ b/Source/cmXCode21Object.cxx
@@ -34,9 +34,7 @@ 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;
+ for (auto obj : v) {
if (obj->GetType() == OBJECT && obj->GetIsA() == t) {
hasOne = true;
break;
@@ -46,9 +44,7 @@ void cmXCode21Object::PrintList(std::vector<cmXCodeObject*> const& v,
return;
}
out << "\n/* Begin " << PBXTypeNames[t] << " section */\n";
- for (std::vector<cmXCodeObject*>::const_iterator i = v.begin(); i != v.end();
- ++i) {
- cmXCodeObject* obj = *i;
+ for (auto obj : v) {
if (obj->GetType() == OBJECT && obj->GetIsA() == t) {
obj->Print(out);
}
diff --git a/Source/cmXCode21Object.h b/Source/cmXCode21Object.h
index bcd8d93e1..8e4b80fc1 100644
--- a/Source/cmXCode21Object.h
+++ b/Source/cmXCode21Object.h
@@ -14,7 +14,7 @@ class cmXCode21Object : public cmXCodeObject
{
public:
cmXCode21Object(PBXType ptype, Type type);
- virtual void PrintComment(std::ostream&);
+ void PrintComment(std::ostream&) override;
static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out,
PBXType t);
static void PrintList(std::vector<cmXCodeObject*> const&, std::ostream& out);
diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx
index 0def8c321..1747c9c99 100644
--- a/Source/cmXCodeObject.cxx
+++ b/Source/cmXCodeObject.cxx
@@ -42,8 +42,8 @@ cmXCodeObject::~cmXCodeObject()
cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
{
this->Version = 15;
- this->Target = 0;
- this->Object = 0;
+ this->Target = nullptr;
+ this->Object = nullptr;
this->IsA = ptype;
@@ -71,7 +71,7 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type)
this->TypeValue = type;
if (this->TypeValue == OBJECT) {
- this->AddAttribute("isa", 0);
+ this->AddAttribute("isa", nullptr);
}
}
@@ -86,7 +86,7 @@ bool cmXCodeObject::IsEmpty() const
return this->ObjectAttributes.empty();
case OBJECT_REF:
case OBJECT:
- return this->Object == 0;
+ return this->Object == nullptr;
}
return true; // unreachable, but quiets warnings
}
@@ -115,23 +115,23 @@ void cmXCodeObject::Print(std::ostream& 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) {
- if (i->first == "isa")
+ for (const auto& keyVal : this->ObjectAttributes) {
+ if (keyVal.first == "isa") {
continue;
+ }
- PrintAttribute(out, 3, separator, indentFactor, i->first, i->second, this);
+ PrintAttribute(out, 3, separator, indentFactor, keyVal.first,
+ keyVal.second, this);
}
cmXCodeObject::Indent(2 * indentFactor, out);
out << "};\n";
}
-void cmXCodeObject::PrintAttribute(std::ostream& out, const int level,
- const std::string separator,
- const int factor, const std::string& name,
+void cmXCodeObject::PrintAttribute(std::ostream& out, int level,
+ const std::string& separator, int factor,
+ const std::string& name,
const cmXCodeObject* object,
const cmXCodeObject* parent)
{
@@ -166,11 +166,9 @@ void cmXCodeObject::PrintAttribute(std::ostream& out, const int level,
if (separator == "\n") {
out << separator;
}
- std::map<std::string, cmXCodeObject*>::const_iterator i;
- for (i = object->ObjectAttributes.begin();
- i != object->ObjectAttributes.end(); ++i) {
- PrintAttribute(out, (level + 1) * factor, separator, factor, i->first,
- i->second, object);
+ for (const auto& keyVal : object->ObjectAttributes) {
+ PrintAttribute(out, (level + 1) * factor, separator, factor,
+ keyVal.first, keyVal.second, object);
}
cmXCodeObject::Indent(level * factor, out);
out << "};" << separator;
@@ -203,9 +201,9 @@ void cmXCodeObject::PrintList(std::vector<cmXCodeObject*> const& objs,
{
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);
+ for (auto obj : objs) {
+ if (obj->TypeValue == OBJECT) {
+ obj->Print(out);
}
}
cmXCodeObject::Indent(1, out);
@@ -220,7 +218,7 @@ void cmXCodeObject::CopyAttributes(cmXCodeObject* copy)
this->Object = copy->Object;
}
-void cmXCodeObject::PrintString(std::ostream& os, std::string String)
+void cmXCodeObject::PrintString(std::ostream& os, const std::string& String)
{
// The string needs to be quoted if it contains any characters
// considered special by the Xcode project file parser.
@@ -233,13 +231,12 @@ void cmXCodeObject::PrintString(std::ostream& os, std::string String)
// Print the string, quoted and escaped as necessary.
os << quote;
- for (std::string::const_iterator i = String.begin(); i != String.end();
- ++i) {
- if (*i == '"' || *i == '\\') {
+ for (auto c : String) {
+ if (c == '"' || c == '\\') {
// Escape double-quotes and backslashes.
os << '\\';
}
- os << *i;
+ os << c;
}
os << quote;
}
diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h
index b92e6e33e..51e5d36d2 100644
--- a/Source/cmXCodeObject.h
+++ b/Source/cmXCodeObject.h
@@ -94,8 +94,8 @@ public:
}
static void Indent(int level, std::ostream& out);
void Print(std::ostream& out);
- void PrintAttribute(std::ostream& out, const int level,
- const std::string separator, const int factor,
+ void PrintAttribute(std::ostream& out, int level,
+ const std::string& separator, int factor,
const std::string& name, const cmXCodeObject* object,
const cmXCodeObject* parent);
virtual void PrintComment(std::ostream&) {}
@@ -114,19 +114,17 @@ public:
if (i != this->ObjectAttributes.end()) {
return i->second;
}
- return 0;
+ return nullptr;
}
// search the attribute list for an object of the specified type
cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const
{
- for (std::vector<cmXCodeObject*>::const_iterator i = this->List.begin();
- i != this->List.end(); ++i) {
- cmXCodeObject* o = *i;
+ for (auto o : this->List) {
if (o->IsA == t) {
return o;
}
}
- return 0;
+ return nullptr;
}
void CopyAttributes(cmXCodeObject*);
@@ -152,7 +150,7 @@ public:
return this->List;
}
void SetComment(const std::string& c) { this->Comment = c; }
- static void PrintString(std::ostream& os, std::string String);
+ static void PrintString(std::ostream& os, const std::string& String);
protected:
void PrintString(std::ostream& os) const;
diff --git a/Source/cmXCodeScheme.cxx b/Source/cmXCodeScheme.cxx
index 5c22531d4..c33bb7e8f 100644
--- a/Source/cmXCodeScheme.cxx
+++ b/Source/cmXCodeScheme.cxx
@@ -5,18 +5,18 @@
#include <iomanip>
#include <iostream>
#include <sstream>
+#include <utility>
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmXMLSafe.h"
-cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj,
+cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj, TestObjects tests,
const std::vector<std::string>& configList,
unsigned int xcVersion)
: Target(xcObj)
+ , Tests(std::move(tests))
, TargetName(xcObj->GetTarget()->GetName())
- , BuildableName(xcObj->GetTarget()->GetFullName())
- , TargetId(xcObj->GetId())
, ConfigList(configList)
, XcodeVersion(xcVersion)
{
@@ -36,7 +36,7 @@ void cmXCodeScheme::WriteXCodeSharedScheme(const std::string& xcProjDir,
xcodeSchemeFile += this->TargetName;
xcodeSchemeFile += ".xcscheme";
- cmGeneratedFileStream fout(xcodeSchemeFile.c_str());
+ cmGeneratedFileStream fout(xcodeSchemeFile);
fout.SetCopyIfDifferent(true);
if (!fout) {
return;
@@ -58,7 +58,7 @@ void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
xout.Attribute("version", "1.3");
WriteBuildAction(xout, container);
- WriteTestAction(xout, FindConfiguration("Debug"));
+ WriteTestAction(xout, FindConfiguration("Debug"), container);
WriteLaunchAction(xout, FindConfiguration("Debug"), container);
WriteProfileAction(xout, FindConfiguration("Release"));
WriteAnalyzeAction(xout, FindConfiguration("Debug"));
@@ -84,14 +84,7 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
xout.Attribute("buildForArchiving", "YES");
xout.Attribute("buildForAnalyzing", "YES");
- xout.StartElement("BuildableReference");
- xout.BreakAttributes();
- xout.Attribute("BuildableIdentifier", "primary");
- xout.Attribute("BlueprintIdentifier", this->TargetId);
- xout.Attribute("BuildableName", this->BuildableName);
- xout.Attribute("BlueprintName", this->TargetName);
- xout.Attribute("ReferencedContainer", "container:" + container);
- xout.EndElement();
+ WriteBuildableReference(xout, this->Target, container);
xout.EndElement(); // BuildActionEntry
xout.EndElement(); // BuildActionEntries
@@ -99,7 +92,8 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
}
void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
- std::string configuration)
+ const std::string& configuration,
+ const std::string& container)
{
xout.StartElement("TestAction");
xout.BreakAttributes();
@@ -111,8 +105,21 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
xout.StartElement("Testables");
+ for (auto test : this->Tests) {
+ xout.StartElement("TestableReference");
+ xout.BreakAttributes();
+ xout.Attribute("skipped", "NO");
+ WriteBuildableReference(xout, test, container);
+ xout.EndElement(); // TestableReference
+ }
xout.EndElement();
+ if (IsTestable()) {
+ xout.StartElement("MacroExpansion");
+ WriteBuildableReference(xout, this->Target, container);
+ xout.EndElement(); // MacroExpansion
+ }
+
xout.StartElement("AdditionalOptions");
xout.EndElement();
@@ -120,7 +127,7 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
}
void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
- std::string configuration,
+ const std::string& configuration,
const std::string& container)
{
xout.StartElement("LaunchAction");
@@ -137,6 +144,46 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
xout.Attribute("debugServiceExtension", "internal");
xout.Attribute("allowLocationSimulation", "YES");
+ // Diagnostics tab begin
+
+ bool useAddressSanitizer = WriteLaunchActionAttribute(
+ xout, "enableAddressSanitizer",
+ "XCODE_SCHEME_ADDRESS_SANITIZER"); // not allowed with
+ // enableThreadSanitizer=YES
+ WriteLaunchActionAttribute(
+ xout, "enableASanStackUseAfterReturn",
+ "XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN");
+
+ bool useThreadSanitizer = false;
+ if (!useAddressSanitizer) {
+ useThreadSanitizer = WriteLaunchActionAttribute(
+ xout, "enableThreadSanitizer",
+ "XCODE_SCHEME_THREAD_SANITIZER"); // not allowed with
+ // enableAddressSanitizer=YES
+ }
+
+ WriteLaunchActionAttribute(xout, "stopOnEveryThreadSanitizerIssue",
+ "XCODE_SCHEME_THREAD_SANITIZER_STOP");
+
+ WriteLaunchActionAttribute(xout, "enableUBSanitizer",
+ "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER");
+ WriteLaunchActionAttribute(
+ xout, "stopOnEveryUBSanitizerIssue",
+ "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP");
+
+ WriteLaunchActionAttribute(
+ xout, "disableMainThreadChecker",
+ "XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER"); // negative enabled!
+ WriteLaunchActionAttribute(xout, "stopOnEveryMainThreadCheckerIssue",
+ "XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP");
+
+ if (this->Target->GetTarget()->GetPropertyAsBool(
+ "XCODE_SCHEME_DEBUG_AS_ROOT")) {
+ xout.Attribute("debugAsWhichUser", "root");
+ }
+
+ // Diagnostics tab end
+
if (IsExecutable(this->Target)) {
xout.StartElement("BuildableProductRunnable");
xout.BreakAttributes();
@@ -146,25 +193,150 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
xout.StartElement("MacroExpansion");
}
- xout.StartElement("BuildableReference");
- xout.BreakAttributes();
- xout.Attribute("BuildableIdentifier", "primary");
- xout.Attribute("BlueprintIdentifier", this->TargetId);
- xout.Attribute("BuildableName", this->BuildableName);
- xout.Attribute("BlueprintName", this->TargetName);
- xout.Attribute("ReferencedContainer", "container:" + container);
- xout.EndElement();
+ WriteBuildableReference(xout, this->Target, container);
xout.EndElement(); // MacroExpansion
+ // Info tab begin
+
+ if (const char* exe =
+ this->Target->GetTarget()->GetProperty("XCODE_SCHEME_EXECUTABLE")) {
+
+ xout.StartElement("PathRunnable");
+ xout.BreakAttributes();
+
+ xout.Attribute("runnableDebuggingMode", "0");
+ xout.Attribute("FilePath", exe);
+
+ xout.EndElement(); // PathRunnable
+ }
+
+ // Info tab end
+
+ // Arguments tab begin
+
+ if (const char* argList =
+ this->Target->GetTarget()->GetProperty("XCODE_SCHEME_ARGUMENTS")) {
+ std::vector<std::string> arguments;
+ cmSystemTools::ExpandListArgument(argList, arguments);
+ if (!arguments.empty()) {
+ xout.StartElement("CommandLineArguments");
+
+ for (auto const& argument : arguments) {
+ xout.StartElement("CommandLineArgument");
+ xout.BreakAttributes();
+
+ xout.Attribute("argument", argument);
+ xout.Attribute("isEnabled", "YES");
+
+ xout.EndElement(); // CommandLineArgument
+ }
+
+ xout.EndElement(); // CommandLineArguments
+ }
+ }
+
+ if (const char* envList =
+ this->Target->GetTarget()->GetProperty("XCODE_SCHEME_ENVIRONMENT")) {
+ std::vector<std::string> envs;
+ cmSystemTools::ExpandListArgument(envList, envs);
+ if (!envs.empty()) {
+ xout.StartElement("EnvironmentVariables");
+
+ for (auto env : envs) {
+
+ xout.StartElement("EnvironmentVariable");
+ xout.BreakAttributes();
+
+ std::string envValue;
+ const auto p = env.find_first_of('=');
+ if (p != std::string::npos) {
+ envValue = env.substr(p + 1);
+ env.resize(p);
+ }
+
+ xout.Attribute("key", env);
+ xout.Attribute("value", envValue);
+ xout.Attribute("isEnabled", "YES");
+
+ xout.EndElement(); // EnvironmentVariable
+ }
+
+ xout.EndElement(); // EnvironmentVariables
+ }
+ }
+
+ // Arguments tab end
+
xout.StartElement("AdditionalOptions");
+
+ if (!useThreadSanitizer) {
+ WriteLaunchActionAdditionalOption(xout, "MallocScribble", "",
+ "XCODE_SCHEME_MALLOC_SCRIBBLE");
+ }
+
+ if (!useThreadSanitizer && !useAddressSanitizer) {
+ WriteLaunchActionAdditionalOption(xout, "MallocGuardEdges", "",
+ "XCODE_SCHEME_MALLOC_GUARD_EDGES");
+ }
+
+ if (!useThreadSanitizer && !useAddressSanitizer) {
+ WriteLaunchActionAdditionalOption(xout, "DYLD_INSERT_LIBRARIES",
+ "/usr/lib/libgmalloc.dylib",
+ "XCODE_SCHEME_GUARD_MALLOC");
+ }
+
+ WriteLaunchActionAdditionalOption(xout, "NSZombieEnabled", "YES",
+ "XCODE_SCHEME_ZOMBIE_OBJECTS");
+
+ if (!useThreadSanitizer && !useAddressSanitizer) {
+ WriteLaunchActionAdditionalOption(xout, "MallocStackLogging", "",
+ "XCODE_SCHEME_MALLOC_STACK");
+ }
+
+ WriteLaunchActionAdditionalOption(xout, "DYLD_PRINT_APIS", "",
+ "XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE");
+
+ WriteLaunchActionAdditionalOption(xout, "DYLD_PRINT_LIBRARIES", "",
+ "XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS");
+
xout.EndElement();
xout.EndElement(); // LaunchAction
}
+bool cmXCodeScheme::WriteLaunchActionAttribute(cmXMLWriter& xout,
+ const std::string& attrName,
+ const std::string& varName)
+{
+ if (Target->GetTarget()->GetPropertyAsBool(varName)) {
+ xout.Attribute(attrName.c_str(), "YES");
+ return true;
+ }
+ return false;
+}
+
+bool cmXCodeScheme::WriteLaunchActionAdditionalOption(
+ cmXMLWriter& xout, const std::string& key, const std::string& value,
+ const std::string& varName)
+{
+ if (Target->GetTarget()->GetPropertyAsBool(varName)) {
+ xout.StartElement("AdditionalOption");
+ xout.BreakAttributes();
+
+ xout.Attribute("key", key);
+ xout.Attribute("value", value);
+ xout.Attribute("isEnabled", "YES");
+
+ xout.EndElement(); // AdditionalOption
+
+ return true;
+ }
+ return false;
+}
+
void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout,
- std::string configuration)
+ const std::string& configuration)
{
xout.StartElement("ProfileAction");
xout.BreakAttributes();
@@ -177,7 +349,7 @@ void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout,
}
void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout,
- std::string configuration)
+ const std::string& configuration)
{
xout.StartElement("AnalyzeAction");
xout.BreakAttributes();
@@ -186,7 +358,7 @@ void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout,
}
void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout,
- std::string configuration)
+ const std::string& configuration)
{
xout.StartElement("ArchiveAction");
xout.BreakAttributes();
@@ -195,6 +367,20 @@ void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout,
xout.EndElement();
}
+void cmXCodeScheme::WriteBuildableReference(cmXMLWriter& xout,
+ const cmXCodeObject* xcObj,
+ const std::string& container)
+{
+ xout.StartElement("BuildableReference");
+ xout.BreakAttributes();
+ xout.Attribute("BuildableIdentifier", "primary");
+ xout.Attribute("BlueprintIdentifier", xcObj->GetId());
+ xout.Attribute("BuildableName", xcObj->GetTarget()->GetFullName());
+ xout.Attribute("BlueprintName", xcObj->GetTarget()->GetName());
+ xout.Attribute("ReferencedContainer", "container:" + container);
+ xout.EndElement();
+}
+
std::string cmXCodeScheme::WriteVersionString()
{
std::ostringstream v;
@@ -209,12 +395,18 @@ std::string cmXCodeScheme::FindConfiguration(const std::string& name)
//
if (std::find(this->ConfigList.begin(), this->ConfigList.end(), name) ==
this->ConfigList.end() &&
- this->ConfigList.size() > 0)
+ !this->ConfigList.empty()) {
return this->ConfigList[0];
+ }
return name;
}
+bool cmXCodeScheme::IsTestable() const
+{
+ return !this->Tests.empty() || IsExecutable(this->Target);
+}
+
bool cmXCodeScheme::IsExecutable(const cmXCodeObject* target)
{
cmGeneratorTarget* gt = target->GetTarget();
diff --git a/Source/cmXCodeScheme.h b/Source/cmXCodeScheme.h
index 379afed42..8c4712359 100644
--- a/Source/cmXCodeScheme.h
+++ b/Source/cmXCodeScheme.h
@@ -5,6 +5,8 @@
#include "cmConfigure.h" // IWYU pragma: keep
+#include <vector>
+
#include "cmGlobalXCodeGenerator.h"
#include "cmSystemTools.h"
#include "cmXCodeObject.h"
@@ -16,7 +18,9 @@
class cmXCodeScheme
{
public:
- cmXCodeScheme(cmXCodeObject* xcObj,
+ typedef std::vector<const cmXCodeObject*> TestObjects;
+
+ cmXCodeScheme(cmXCodeObject* xcObj, TestObjects tests,
const std::vector<std::string>& configList,
unsigned int xcVersion);
@@ -25,25 +29,40 @@ public:
private:
const cmXCodeObject* const Target;
+ const TestObjects Tests;
const std::string& TargetName;
- const std::string BuildableName;
- const std::string& TargetId;
const std::vector<std::string>& ConfigList;
const unsigned int XcodeVersion;
void WriteXCodeXCScheme(std::ostream& fout, const std::string& container);
void WriteBuildAction(cmXMLWriter& xout, const std::string& container);
- void WriteTestAction(cmXMLWriter& xout, std::string configuration);
- void WriteLaunchAction(cmXMLWriter& xout, std::string configuration,
+ void WriteTestAction(cmXMLWriter& xout, const std::string& configuration,
+ const std::string& container);
+ void WriteLaunchAction(cmXMLWriter& xout, const std::string& configuration,
const std::string& container);
- void WriteProfileAction(cmXMLWriter& xout, std::string configuration);
- void WriteAnalyzeAction(cmXMLWriter& xout, std::string configuration);
- void WriteArchiveAction(cmXMLWriter& xout, std::string configuration);
+
+ bool WriteLaunchActionAttribute(cmXMLWriter& xout,
+ const std::string& attrName,
+ const std::string& varName);
+
+ bool WriteLaunchActionAdditionalOption(cmXMLWriter& xout,
+ const std::string& attrName,
+ const std::string& value,
+ const std::string& varName);
+
+ void WriteProfileAction(cmXMLWriter& xout, const std::string& configuration);
+ void WriteAnalyzeAction(cmXMLWriter& xout, const std::string& configuration);
+ void WriteArchiveAction(cmXMLWriter& xout, const std::string& configuration);
+
+ void WriteBuildableReference(cmXMLWriter& xout, const cmXCodeObject* xcObj,
+ const std::string& container);
std::string WriteVersionString();
std::string FindConfiguration(const std::string& name);
+ bool IsTestable() const;
+
static bool IsExecutable(const cmXCodeObject* target);
};
diff --git a/Source/cmXMLParser.cxx b/Source/cmXMLParser.cxx
index 18afbf370..4c6c35acc 100644
--- a/Source/cmXMLParser.cxx
+++ b/Source/cmXMLParser.cxx
@@ -11,10 +11,10 @@
cmXMLParser::cmXMLParser()
{
- this->Parser = CM_NULLPTR;
+ this->Parser = nullptr;
this->ParseError = 0;
- this->ReportCallback = CM_NULLPTR;
- this->ReportCallbackData = CM_NULLPTR;
+ this->ReportCallback = nullptr;
+ this->ReportCallbackData = nullptr;
}
cmXMLParser::~cmXMLParser()
@@ -26,7 +26,7 @@ cmXMLParser::~cmXMLParser()
int cmXMLParser::Parse(const char* string)
{
- return (int)this->InitializeParser() &&
+ return this->InitializeParser() &&
this->ParseChunk(string, strlen(string)) && this->CleanupParser();
}
@@ -55,7 +55,7 @@ int cmXMLParser::InitializeParser()
}
// Create the expat XML parser.
- this->Parser = XML_ParserCreate(CM_NULLPTR);
+ this->Parser = XML_ParserCreate(nullptr);
XML_SetElementHandler(static_cast<XML_Parser>(this->Parser),
&cmXMLParserStartElement, &cmXMLParserEndElement);
XML_SetCharacterDataHandler(static_cast<XML_Parser>(this->Parser),
@@ -99,7 +99,7 @@ int cmXMLParser::CleanupParser()
// Clean up the parser.
XML_ParserFree(static_cast<XML_Parser>(this->Parser));
- this->Parser = CM_NULLPTR;
+ this->Parser = nullptr;
return result;
}
@@ -156,7 +156,7 @@ const char* cmXMLParser::FindAttribute(const char** atts,
}
}
}
- return CM_NULLPTR;
+ return nullptr;
}
void cmXMLParserStartElement(void* parser, const char* name, const char** atts)
@@ -186,8 +186,8 @@ void cmXMLParserCharacterDataHandler(void* parser, const char* data,
void cmXMLParser::ReportXmlParseError()
{
XML_Parser parser = static_cast<XML_Parser>(this->Parser);
- this->ReportError(XML_GetCurrentLineNumber(parser),
- XML_GetCurrentColumnNumber(parser),
+ this->ReportError(static_cast<int>(XML_GetCurrentLineNumber(parser)),
+ static_cast<int>(XML_GetCurrentColumnNumber(parser)),
XML_ErrorString(XML_GetErrorCode(parser)));
}
diff --git a/Source/cmXMLWriter.cxx b/Source/cmXMLWriter.cxx
index 3cbc70dbd..f1ce60814 100644
--- a/Source/cmXMLWriter.cxx
+++ b/Source/cmXMLWriter.cxx
@@ -9,6 +9,7 @@ cmXMLWriter::cmXMLWriter(std::ostream& output, std::size_t level)
: Output(output)
, IndentationElement(1, '\t')
, Level(level)
+ , Indent(0)
, ElementOpen(false)
, BreakAttrib(false)
, IsContent(false)
@@ -17,37 +18,39 @@ cmXMLWriter::cmXMLWriter(std::ostream& output, std::size_t level)
cmXMLWriter::~cmXMLWriter()
{
- assert(this->Elements.empty());
+ assert(this->Indent == 0);
}
void cmXMLWriter::StartDocument(const char* encoding)
{
- this->Output << "<?xml version=\"1.0\" encoding=\"" << encoding << "\"?>";
+ this->Output << R"(<?xml version="1.0" encoding=")" << encoding << "\"?>";
}
void cmXMLWriter::EndDocument()
{
- assert(this->Elements.empty());
+ assert(this->Indent == 0);
this->Output << '\n';
}
void cmXMLWriter::StartElement(std::string const& name)
{
this->CloseStartElement();
- this->ConditionalLineBreak(!this->IsContent, this->Elements.size());
+ this->ConditionalLineBreak(!this->IsContent);
this->Output << '<' << name;
this->Elements.push(name);
+ ++this->Indent;
this->ElementOpen = true;
this->BreakAttrib = false;
}
void cmXMLWriter::EndElement()
{
- assert(!this->Elements.empty());
+ assert(this->Indent > 0);
+ --this->Indent;
if (this->ElementOpen) {
this->Output << "/>";
} else {
- this->ConditionalLineBreak(!this->IsContent, this->Elements.size() - 1);
+ this->ConditionalLineBreak(!this->IsContent);
this->IsContent = false;
this->Output << "</" << this->Elements.top() << '>';
}
@@ -58,7 +61,7 @@ void cmXMLWriter::EndElement()
void cmXMLWriter::Element(const char* name)
{
this->CloseStartElement();
- this->ConditionalLineBreak(!this->IsContent, this->Elements.size());
+ this->ConditionalLineBreak(!this->IsContent);
this->Output << '<' << name << "/>";
}
@@ -70,7 +73,7 @@ void cmXMLWriter::BreakAttributes()
void cmXMLWriter::Comment(const char* comment)
{
this->CloseStartElement();
- this->ConditionalLineBreak(!this->IsContent, this->Elements.size());
+ this->ConditionalLineBreak(!this->IsContent);
this->Output << "<!-- " << comment << " -->";
}
@@ -83,14 +86,14 @@ void cmXMLWriter::CData(std::string const& data)
void cmXMLWriter::Doctype(const char* doctype)
{
this->CloseStartElement();
- this->ConditionalLineBreak(!this->IsContent, this->Elements.size());
+ this->ConditionalLineBreak(!this->IsContent);
this->Output << "<!DOCTYPE " << doctype << ">";
}
void cmXMLWriter::ProcessingInstruction(const char* target, const char* data)
{
this->CloseStartElement();
- this->ConditionalLineBreak(!this->IsContent, this->Elements.size());
+ this->ConditionalLineBreak(!this->IsContent);
this->Output << "<?" << target << ' ' << data << "?>";
}
@@ -106,11 +109,11 @@ void cmXMLWriter::SetIndentationElement(std::string const& element)
this->IndentationElement = element;
}
-void cmXMLWriter::ConditionalLineBreak(bool condition, std::size_t indent)
+void cmXMLWriter::ConditionalLineBreak(bool condition)
{
if (condition) {
this->Output << '\n';
- for (std::size_t i = 0; i < indent + this->Level; ++i) {
+ for (std::size_t i = 0; i < this->Indent + this->Level; ++i) {
this->Output << this->IndentationElement;
}
}
@@ -119,7 +122,7 @@ void cmXMLWriter::ConditionalLineBreak(bool condition, std::size_t indent)
void cmXMLWriter::PreAttribute()
{
assert(this->ElementOpen);
- this->ConditionalLineBreak(this->BreakAttrib, this->Elements.size());
+ this->ConditionalLineBreak(this->BreakAttrib);
if (!this->BreakAttrib) {
this->Output << ' ';
}
@@ -134,7 +137,7 @@ void cmXMLWriter::PreContent()
void cmXMLWriter::CloseStartElement()
{
if (this->ElementOpen) {
- this->ConditionalLineBreak(this->BreakAttrib, this->Elements.size());
+ this->ConditionalLineBreak(this->BreakAttrib);
this->Output << '>';
this->ElementOpen = false;
}
diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h
index ed76a88c7..512e1031d 100644
--- a/Source/cmXMLWriter.h
+++ b/Source/cmXMLWriter.h
@@ -3,10 +3,12 @@
#ifndef cmXMLWiter_h
#define cmXMLWiter_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmXMLSafe.h"
+#include <chrono>
+#include <ctime>
#include <ostream>
#include <stack>
#include <string>
@@ -14,12 +16,13 @@
class cmXMLWriter
{
- CM_DISABLE_COPY(cmXMLWriter)
-
public:
cmXMLWriter(std::ostream& output, std::size_t level = 0);
~cmXMLWriter();
+ cmXMLWriter(cmXMLWriter const&) = delete;
+ cmXMLWriter& operator=(cmXMLWriter const&) = delete;
+
void StartDocument(const char* encoding = "UTF-8");
void EndDocument();
@@ -65,7 +68,7 @@ public:
void SetIndentationElement(std::string const& element);
private:
- void ConditionalLineBreak(bool condition, std::size_t indent);
+ void ConditionalLineBreak(bool condition);
void PreAttribute();
void PreContent();
@@ -99,6 +102,22 @@ private:
return cmXMLSafe(value).Quotes(false);
}
+ /*
+ * Convert a std::chrono::system::time_point to the number of seconds since
+ * the UN*X epoch.
+ *
+ * It would be tempting to convert a time_point to number of seconds by
+ * using time_since_epoch(). Unfortunately the C++11 standard does not
+ * specify what the epoch of the system_clock must be.
+ * Therefore we must assume it is an arbitrary point in time. Instead of this
+ * method, it is recommended to convert it by means of the to_time_t method.
+ */
+ static std::time_t SafeContent(
+ std::chrono::system_clock::time_point const& value)
+ {
+ return std::chrono::system_clock::to_time_t(value);
+ }
+
template <typename T>
static T SafeContent(T value)
{
@@ -107,12 +126,77 @@ private:
private:
std::ostream& Output;
- std::stack<std::string, std::vector<std::string> > Elements;
+ std::stack<std::string, std::vector<std::string>> Elements;
std::string IndentationElement;
std::size_t Level;
+ std::size_t Indent;
bool ElementOpen;
bool BreakAttrib;
bool IsContent;
};
+class cmXMLElement; // IWYU pragma: keep
+
+class cmXMLDocument
+{
+public:
+ cmXMLDocument(cmXMLWriter& xml)
+ : xmlwr(xml)
+ {
+ xmlwr.StartDocument();
+ }
+ ~cmXMLDocument() { xmlwr.EndDocument(); }
+ cmXMLDocument(const cmXMLDocument&) = delete;
+ cmXMLDocument& operator=(const cmXMLDocument&) = delete;
+
+private:
+ friend class cmXMLElement;
+ cmXMLWriter& xmlwr;
+};
+
+class cmXMLElement
+{
+public:
+ cmXMLElement(cmXMLWriter& xml, const char* tag)
+ : xmlwr(xml)
+ {
+ xmlwr.StartElement(tag);
+ }
+ cmXMLElement(cmXMLElement& par, const char* tag)
+ : xmlwr(par.xmlwr)
+ {
+ xmlwr.StartElement(tag);
+ }
+ cmXMLElement(cmXMLDocument& doc, const char* tag)
+ : xmlwr(doc.xmlwr)
+ {
+ xmlwr.StartElement(tag);
+ }
+ ~cmXMLElement() { xmlwr.EndElement(); }
+
+ cmXMLElement(const cmXMLElement&) = delete;
+ cmXMLElement& operator=(const cmXMLElement&) = delete;
+
+ template <typename T>
+ cmXMLElement& Attribute(const char* name, T const& value)
+ {
+ xmlwr.Attribute(name, value);
+ return *this;
+ }
+ template <typename T>
+ void Content(T const& content)
+ {
+ xmlwr.Content(content);
+ }
+ template <typename T>
+ void Element(std::string const& name, T const& value)
+ {
+ xmlwr.Element(name, value);
+ }
+ void Comment(const char* comment) { xmlwr.Comment(comment); }
+
+private:
+ cmXMLWriter& xmlwr;
+};
+
#endif
diff --git a/Source/cm_codecvt.cxx b/Source/cm_codecvt.cxx
index cf55741a7..821c112b3 100644
--- a/Source/cm_codecvt.cxx
+++ b/Source/cm_codecvt.cxx
@@ -3,11 +3,11 @@
#include "cm_codecvt.hxx"
#if defined(_WIN32)
-#include <assert.h>
-#include <string.h>
-#include <windows.h>
-#undef max
-#include "cmsys/Encoding.hxx"
+# include <assert.h>
+# include <string.h>
+# include <windows.h>
+# undef max
+# include "cmsys/Encoding.hxx"
#endif
#if defined(_WIN32)
@@ -38,12 +38,12 @@ codecvt::codecvt(Encoding e)
}
}
-codecvt::~codecvt(){};
+codecvt::~codecvt() = default;
bool codecvt::do_always_noconv() const throw()
{
return m_noconv;
-};
+}
std::codecvt_base::result codecvt::do_out(mbstate_t& state, const char* from,
const char* from_end,
@@ -122,7 +122,7 @@ std::codecvt_base::result codecvt::do_out(mbstate_t& state, const char* from,
static_cast<void>(to_next);
return std::codecvt_base::noconv;
#endif
-};
+}
std::codecvt_base::result codecvt::do_unshift(mbstate_t& state, char* to,
char* to_end,
@@ -143,7 +143,7 @@ std::codecvt_base::result codecvt::do_unshift(mbstate_t& state, char* to,
static_cast<void>(to_end);
return std::codecvt_base::ok;
#endif
-};
+}
#if defined(_WIN32)
std::codecvt_base::result codecvt::Decode(mbstate_t& state, int size,
@@ -235,9 +235,9 @@ void codecvt::BufferPartial(mbstate_t& state, int size,
int codecvt::do_max_length() const throw()
{
return 4;
-};
+}
int codecvt::do_encoding() const throw()
{
return 0;
-};
+}
diff --git a/Source/cm_codecvt.hxx b/Source/cm_codecvt.hxx
index 30c6d5407..2df39614c 100644
--- a/Source/cm_codecvt.hxx
+++ b/Source/cm_codecvt.hxx
@@ -3,7 +3,7 @@
#ifndef cm_codecvt_hxx
#define cm_codecvt_hxx
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
#include <locale>
#include <wchar.h>
@@ -23,15 +23,15 @@ public:
codecvt(Encoding e);
protected:
- ~codecvt() CM_OVERRIDE;
- bool do_always_noconv() const throw() CM_OVERRIDE;
+ ~codecvt() override;
+ bool do_always_noconv() const throw() override;
result do_out(mbstate_t& state, const char* from, const char* from_end,
const char*& from_next, char* to, char* to_end,
- char*& to_next) const CM_OVERRIDE;
+ char*& to_next) const override;
result do_unshift(mbstate_t& state, char* to, char*,
- char*& to_next) const CM_OVERRIDE;
- int do_max_length() const throw() CM_OVERRIDE;
- int do_encoding() const throw() CM_OVERRIDE;
+ char*& to_next) const override;
+ int do_max_length() const throw() override;
+ int do_encoding() const throw() override;
private:
// The mbstate_t argument to do_out and do_unshift is responsible
@@ -52,13 +52,13 @@ private:
};
bool m_noconv;
-#if defined(_WIN32)
+# if defined(_WIN32)
unsigned int m_codepage;
result Decode(mbstate_t& state, int need, const char*& from_next,
char*& to_next, char* to_end) const;
result DecodePartial(mbstate_t& state, char*& to_next, char* to_end) const;
void BufferPartial(mbstate_t& state, int need, const char*& from_next) const;
-#endif
+# endif
#endif
};
diff --git a/Source/cm_sys_stat.h b/Source/cm_sys_stat.h
index 26e4baa03..796f027c1 100644
--- a/Source/cm_sys_stat.h
+++ b/Source/cm_sys_stat.h
@@ -7,6 +7,11 @@
typedef unsigned short mode_t;
#endif
+#if defined(WIN32)
+typedef unsigned short uid_t;
+typedef unsigned short gid_t;
+#endif
+
#include <sys/types.h>
// include sys/stat.h after sys/types.h
#include <sys/stat.h>
diff --git a/Source/cm_utf8.c b/Source/cm_utf8.c
index 52af4a6f4..62e7e8c8c 100644
--- a/Source/cm_utf8.c
+++ b/Source/cm_utf8.c
@@ -2,6 +2,8 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cm_utf8.h"
+#include <string.h>
+
/*
RFC 3629
07-bit: 0xxxxxxx
@@ -71,7 +73,34 @@ const char* cm_utf8_decode_character(const char* first, const char* last,
return 0;
}
+ /* UTF-16 surrogate halves. */
+ if (0xD800 <= uc && uc <= 0xDFFF) {
+ return 0;
+ }
+
+ /* Invalid codepoints. */
+ if (0x10FFFF < uc) {
+ return 0;
+ }
+
*pc = uc;
return first;
}
}
+
+int cm_utf8_is_valid(const char* s)
+{
+ if (!s) {
+ return 0;
+ }
+
+ const char* last = s + strlen(s);
+ const char* pos = s;
+ unsigned int pc;
+
+ while (pos != last && (pos = cm_utf8_decode_character(pos, last, &pc))) {
+ /* Nothing to do. */
+ }
+
+ return pos == last;
+}
diff --git a/Source/cm_utf8.h b/Source/cm_utf8.h
index fcb43e0e4..27dc5591f 100644
--- a/Source/cm_utf8.h
+++ b/Source/cm_utf8.h
@@ -13,6 +13,10 @@ extern "C" {
const char* cm_utf8_decode_character(const char* first, const char* last,
unsigned int* pc);
+/** Returns whether a C string is a sequence of valid UTF-8 encoded Unicode
+ codepoints. Returns non-zero on success. */
+int cm_utf8_is_valid(const char* s);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 689439378..3772f0998 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -7,8 +7,9 @@
#include "cmDocumentation.h"
#include "cmDocumentationEntry.h"
#include "cmDocumentationFormatter.h"
+#include "cmDuration.h"
#include "cmExternalMakefileProjectGenerator.h"
-#include "cmFileTimeComparison.h"
+#include "cmFileTimeCache.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmGlobalGeneratorFactory.h"
@@ -24,109 +25,102 @@
#include "cmUtils.hxx"
#include "cmVersionConfig.h"
#include "cmWorkingDirectory.h"
-#include "cm_auto_ptr.hxx"
#include "cm_sys_stat.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cm_jsoncpp_writer.h"
+# include "cm_jsoncpp_writer.h"
-#include "cmGraphVizWriter.h"
-#include "cmVariableWatch.h"
-#include "cm_unordered_map.hxx"
+# include "cmFileAPI.h"
+# include "cmGraphVizWriter.h"
+# include "cmVariableWatch.h"
+# include <unordered_map>
#endif
-// 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
+# define CMAKE_USE_ECLIPSE
#endif
#if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
-#define CMAKE_BOOT_MINGW
+# define CMAKE_BOOT_MINGW
#endif
// include the generator
#if defined(_WIN32) && !defined(__CYGWIN__)
-#if !defined(CMAKE_BOOT_MINGW)
-#include "cmGlobalBorlandMakefileGenerator.h"
-#include "cmGlobalGhsMultiGenerator.h"
-#include "cmGlobalJOMMakefileGenerator.h"
-#include "cmGlobalNMakeMakefileGenerator.h"
-#include "cmGlobalVisualStudio10Generator.h"
-#include "cmGlobalVisualStudio11Generator.h"
-#include "cmGlobalVisualStudio12Generator.h"
-#include "cmGlobalVisualStudio14Generator.h"
-#include "cmGlobalVisualStudio15Generator.h"
-#include "cmGlobalVisualStudio8Generator.h"
-#include "cmGlobalVisualStudio9Generator.h"
-#include "cmVSSetupHelper.h"
-
-#define CMAKE_HAVE_VS_GENERATORS
-#endif
-#include "cmGlobalMSYSMakefileGenerator.h"
-#include "cmGlobalMinGWMakefileGenerator.h"
+# if !defined(CMAKE_BOOT_MINGW)
+# include "cmGlobalBorlandMakefileGenerator.h"
+# include "cmGlobalJOMMakefileGenerator.h"
+# include "cmGlobalNMakeMakefileGenerator.h"
+# include "cmGlobalVisualStudio10Generator.h"
+# include "cmGlobalVisualStudio11Generator.h"
+# include "cmGlobalVisualStudio12Generator.h"
+# include "cmGlobalVisualStudio14Generator.h"
+# include "cmGlobalVisualStudio9Generator.h"
+# include "cmGlobalVisualStudioVersionedGenerator.h"
+# include "cmVSSetupHelper.h"
+
+# define CMAKE_HAVE_VS_GENERATORS
+# endif
+# include "cmGlobalMSYSMakefileGenerator.h"
+# include "cmGlobalMinGWMakefileGenerator.h"
#else
#endif
#if defined(CMAKE_USE_WMAKE)
-#include "cmGlobalWatcomWMakeGenerator.h"
+# include "cmGlobalWatcomWMakeGenerator.h"
#endif
#include "cmGlobalUnixMakefileGenerator3.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmGlobalNinjaGenerator.h"
+# include "cmGlobalNinjaGenerator.h"
#endif
#include "cmExtraCodeLiteGenerator.h"
#if !defined(CMAKE_BOOT_MINGW)
-#include "cmExtraCodeBlocksGenerator.h"
+# include "cmExtraCodeBlocksGenerator.h"
#endif
#include "cmExtraKateGenerator.h"
#include "cmExtraSublimeTextGenerator.h"
-#ifdef CMAKE_USE_KDEVELOP
-#include "cmGlobalKdevelopGenerator.h"
+#ifdef CMAKE_USE_ECLIPSE
+# include "cmExtraEclipseCDT4Generator.h"
#endif
-#ifdef CMAKE_USE_ECLIPSE
-#include "cmExtraEclipseCDT4Generator.h"
+#if defined(__linux__) || defined(_WIN32)
+# include "cmGlobalGhsMultiGenerator.h"
#endif
#if defined(__APPLE__)
-#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmGlobalXCodeGenerator.h"
+# if defined(CMAKE_BUILD_WITH_CMAKE)
+# include "cmGlobalXCodeGenerator.h"
-#define CMAKE_USE_XCODE 1
-#endif
-#include <sys/resource.h>
-#include <sys/time.h>
+# define CMAKE_USE_XCODE 1
+# endif
+# include <sys/resource.h>
+# include <sys/time.h>
#endif
#include "cmsys/FStream.hxx"
#include "cmsys/Glob.hxx"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
+#include <cstring>
+#include <initializer_list>
#include <iostream>
+#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <utility>
namespace {
#if defined(CMAKE_BUILD_WITH_CMAKE)
-typedef CM_UNORDERED_MAP<std::string, Json::Value> JsonValueMapType;
+typedef std::unordered_map<std::string, Json::Value> JsonValueMapType;
#endif
} // namespace
-static bool cmakeCheckStampFile(const char* stampName, bool verbose = true);
-static bool cmakeCheckStampList(const char* stampList, bool verbose = true);
+static bool cmakeCheckStampFile(const std::string& stampName);
+static bool cmakeCheckStampList(const std::string& stampList);
void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/,
void* ctx, const char* /*unused*/,
@@ -136,7 +130,7 @@ void cmWarnUnusedCliWarning(const std::string& variable, int /*unused*/,
cm->MarkCliAsUsed(variable);
}
-cmake::cmake(Role role)
+cmake::cmake(Role role, cmState::Mode mode)
{
this->Trace = false;
this->TraceExpand = false;
@@ -147,11 +141,12 @@ cmake::cmake(Role role)
this->DebugOutput = false;
this->DebugTryCompile = false;
this->ClearBuildSystem = false;
- this->FileComparison = new cmFileTimeComparison;
+ this->FileTimeCache = new cmFileTimeCache;
this->State = new cmState;
+ this->State->SetMode(mode);
this->CurrentSnapshot = this->State->CreateBaseSnapshot();
- this->Messenger = new cmMessenger(this->State);
+ this->Messenger = new cmMessenger;
#ifdef __APPLE__
struct rlimit rlp;
@@ -163,9 +158,10 @@ cmake::cmake(Role role)
}
#endif
- this->GlobalGenerator = CM_NULLPTR;
- this->ProgressCallback = CM_NULLPTR;
- this->ProgressCallbackClientData = CM_NULLPTR;
+ this->GlobalGenerator = nullptr;
+ this->GeneratorInstanceSet = false;
+ this->GeneratorPlatformSet = false;
+ this->GeneratorToolsetSet = false;
this->CurrentWorkingMode = NORMAL_MODE;
#ifdef CMAKE_BUILD_WITH_CMAKE
@@ -181,6 +177,10 @@ cmake::cmake(Role role)
this->AddProjectCommands();
}
+ if (mode == cmState::Project) {
+ this->LoadEnvironmentPresets();
+ }
+
// Make sure we can capture the build tool output.
cmSystemTools::EnableVSConsoleOutput();
@@ -188,25 +188,36 @@ cmake::cmake(Role role)
// 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->SourceFileExtensions.emplace_back("c");
+ this->SourceFileExtensions.emplace_back("C");
+
+ this->SourceFileExtensions.emplace_back("c++");
+ this->SourceFileExtensions.emplace_back("cc");
+ this->SourceFileExtensions.emplace_back("cpp");
+ this->SourceFileExtensions.emplace_back("cxx");
+ this->SourceFileExtensions.emplace_back("cu");
+ this->SourceFileExtensions.emplace_back("m");
+ this->SourceFileExtensions.emplace_back("M");
+ this->SourceFileExtensions.emplace_back("mm");
+
+ std::copy(this->SourceFileExtensions.begin(),
+ this->SourceFileExtensions.end(),
+ std::inserter(this->SourceFileExtensionsSet,
+ this->SourceFileExtensionsSet.end()));
+
+ this->HeaderFileExtensions.emplace_back("h");
+ this->HeaderFileExtensions.emplace_back("hh");
+ this->HeaderFileExtensions.emplace_back("h++");
+ this->HeaderFileExtensions.emplace_back("hm");
+ this->HeaderFileExtensions.emplace_back("hpp");
+ this->HeaderFileExtensions.emplace_back("hxx");
+ this->HeaderFileExtensions.emplace_back("in");
+ this->HeaderFileExtensions.emplace_back("txx");
+
+ std::copy(this->HeaderFileExtensions.begin(),
+ this->HeaderFileExtensions.end(),
+ std::inserter(this->HeaderFileExtensionsSet,
+ this->HeaderFileExtensionsSet.end()));
}
cmake::~cmake()
@@ -215,20 +226,18 @@ cmake::~cmake()
delete this->Messenger;
if (this->GlobalGenerator) {
delete this->GlobalGenerator;
- this->GlobalGenerator = CM_NULLPTR;
+ this->GlobalGenerator = nullptr;
}
cmDeleteAll(this->Generators);
#ifdef CMAKE_BUILD_WITH_CMAKE
delete this->VariableWatch;
#endif
- delete this->FileComparison;
+ delete this->FileTimeCache;
}
#if defined(CMAKE_BUILD_WITH_CMAKE)
-Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const
+Json::Value cmake::ReportVersionJson() const
{
- Json::Value obj = Json::objectValue;
- // Version information:
Json::Value version = Json::objectValue;
version["string"] = CMake_VERSION;
version["major"] = CMake_VERSION_MAJOR;
@@ -236,53 +245,58 @@ Json::Value cmake::ReportCapabilitiesJson(bool haveServerMode) const
version["suffix"] = CMake_VERSION_SUFFIX;
version["isDirty"] = (CMake_VERSION_IS_DIRTY == 1);
version["patch"] = CMake_VERSION_PATCH;
+ return version;
+}
- obj["version"] = version;
+Json::Value cmake::ReportCapabilitiesJson() const
+{
+ Json::Value obj = Json::objectValue;
+
+ // Version information:
+ obj["version"] = this->ReportVersionJson();
// Generators:
std::vector<cmake::GeneratorInfo> generatorInfoList;
this->GetRegisteredGenerators(generatorInfoList);
JsonValueMapType generatorMap;
- for (std::vector<cmake::GeneratorInfo>::const_iterator i =
- generatorInfoList.begin();
- i != generatorInfoList.end(); ++i) {
- if (i->isAlias) { // skip aliases, they are there for compatibility reasons
+ for (cmake::GeneratorInfo const& gi : generatorInfoList) {
+ if (gi.isAlias) { // skip aliases, they are there for compatibility reasons
// only
continue;
}
- if (i->extraName.empty()) {
+ if (gi.extraName.empty()) {
Json::Value gen = Json::objectValue;
- gen["name"] = i->name;
- gen["toolsetSupport"] = i->supportsToolset;
- gen["platformSupport"] = i->supportsPlatform;
+ gen["name"] = gi.name;
+ gen["toolsetSupport"] = gi.supportsToolset;
+ gen["platformSupport"] = gi.supportsPlatform;
gen["extraGenerators"] = Json::arrayValue;
- generatorMap[i->name] = gen;
+ generatorMap[gi.name] = gen;
} else {
- Json::Value& gen = generatorMap[i->baseName];
- gen["extraGenerators"].append(i->extraName);
+ Json::Value& gen = generatorMap[gi.baseName];
+ gen["extraGenerators"].append(gi.extraName);
}
}
Json::Value generators = Json::arrayValue;
- for (JsonValueMapType::const_iterator i = generatorMap.begin();
- i != generatorMap.end(); ++i) {
- generators.append(i->second);
+ for (auto const& i : generatorMap) {
+ generators.append(i.second);
}
obj["generators"] = generators;
- obj["serverMode"] = haveServerMode;
+ obj["fileApi"] = cmFileAPI::ReportCapabilities();
+ obj["serverMode"] = true;
return obj;
}
#endif
-std::string cmake::ReportCapabilities(bool haveServerMode) const
+std::string cmake::ReportCapabilities() const
{
std::string result;
#if defined(CMAKE_BUILD_WITH_CMAKE)
Json::FastWriter writer;
- result = writer.write(this->ReportCapabilitiesJson(haveServerMode));
+ result = writer.write(this->ReportCapabilitiesJson());
#else
result = "Not supported";
#endif
@@ -322,9 +336,10 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
bool haveValue = false;
std::string cachedValue;
if (this->WarnUnusedCli) {
- if (const char* v = this->State->GetInitializedCacheValue(var)) {
+ if (const std::string* v =
+ this->State->GetInitializedCacheValue(var)) {
haveValue = true;
- cachedValue = v;
+ cachedValue = *v;
}
}
@@ -334,7 +349,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
if (this->WarnUnusedCli) {
if (!haveValue ||
- cachedValue != this->State->GetInitializedCacheValue(var)) {
+ cachedValue != *this->State->GetInitializedCacheValue(var)) {
this->WatchUnusedCli(var);
}
}
@@ -407,21 +422,18 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
// removed
std::vector<std::string> entriesToDelete;
std::vector<std::string> cacheKeys = this->State->GetCacheEntryKeys();
- for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it) {
- cmStateEnums::CacheEntryType t = this->State->GetCacheEntryType(*it);
+ for (std::string const& ck : cacheKeys) {
+ cmStateEnums::CacheEntryType t = this->State->GetCacheEntryType(ck);
if (t != cmStateEnums::STATIC) {
- if (regex.find(it->c_str())) {
- entriesToDelete.push_back(*it);
+ if (regex.find(ck)) {
+ entriesToDelete.push_back(ck);
}
}
}
// now remove them from the cache
- for (std::vector<std::string>::const_iterator currentEntry =
- entriesToDelete.begin();
- currentEntry != entriesToDelete.end(); ++currentEntry) {
- this->State->RemoveCacheEntry(*currentEntry);
+ for (std::string const& currentEntry : entriesToDelete) {
+ this->State->RemoveCacheEntry(currentEntry);
}
} else if (arg.find("-C", 0) == 0) {
std::string path = arg.substr(2);
@@ -435,7 +447,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
}
}
std::cout << "loading initial cache file " << path << "\n";
- this->ReadListFile(args, path.c_str());
+ this->ReadListFile(args, path);
} else if (arg.find("-P", 0) == 0) {
i++;
if (i >= args.size()) {
@@ -449,7 +461,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
}
// Register fake project commands that hint misuse in script mode.
GetProjectCommandsInScriptMode(this->State);
- this->ReadListFile(args, path.c_str());
+ this->ReadListFile(args, path);
} else if (arg.find("--find-package", 0) == 0) {
findPackageMode = true;
}
@@ -463,7 +475,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
}
void cmake::ReadListFile(const std::vector<std::string>& args,
- const char* path)
+ const std::string& path)
{
// if a generator was not yet created, temporarily create one
cmGlobalGenerator* gg = this->GetGlobalGenerator();
@@ -476,7 +488,7 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
}
// read in the list file to fill the cache
- if (path) {
+ if (!path.empty()) {
this->CurrentSnapshot = this->State->Reset();
std::string homeDir = this->GetHomeDirectory();
std::string homeOutputDir = this->GetHomeOutputDirectory();
@@ -488,16 +500,16 @@ void cmake::ReadListFile(const std::vector<std::string>& args,
snapshot.GetDirectory().SetCurrentSource(
cmSystemTools::GetCurrentWorkingDirectory());
snapshot.SetDefaultDefinitions();
- CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(gg, snapshot));
+ cmMakefile mf(gg, snapshot);
if (this->GetWorkingMode() != NORMAL_MODE) {
std::string file(cmSystemTools::CollapseFullPath(path));
cmSystemTools::ConvertToUnixSlashes(file);
- mf->SetScriptModeFile(file.c_str());
+ mf.SetScriptModeFile(file);
- mf->SetArgcArgv(args);
+ mf.SetArgcArgv(args);
}
- if (!mf->ReadListFile(path)) {
- cmSystemTools::Error("Error processing file: ", path);
+ if (!mf.ReadListFile(path)) {
+ cmSystemTools::Error("Error processing file: " + path);
}
this->SetHomeDirectory(homeDir);
this->SetHomeOutputDirectory(homeOutputDir);
@@ -531,7 +543,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
mf->SetArgcArgv(args);
std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake");
- mf->ReadListFile(systemFile.c_str());
+ mf->ReadListFile(systemFile);
std::string language = mf->GetSafeDefinition("LANGUAGE");
std::string mode = mf->GetSafeDefinition("MODE");
@@ -555,7 +567,7 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
gg->CreateGenerationObjects();
cmLocalGenerator* lg = gg->LocalGenerators[0];
std::string includeFlags =
- lg->GetIncludeFlags(includeDirs, CM_NULLPTR, language);
+ lg->GetIncludeFlags(includeDirs, nullptr, language);
std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
printf("%s %s\n", includeFlags.c_str(), definitions.c_str());
@@ -568,9 +580,8 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
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) {
- tgt->AddLinkLibrary(*mf, *libIt, GENERAL_LibraryType);
+ for (std::string const& lib : libList) {
+ tgt->AddLinkLibrary(*mf, lib, GENERAL_LibraryType);
}
std::string buildType = mf->GetSafeDefinition("CMAKE_BUILD_TYPE");
@@ -609,28 +620,77 @@ bool cmake::FindPackage(const std::vector<std::string>& args)
return packageFound;
}
+void cmake::LoadEnvironmentPresets()
+{
+ std::string envGenVar;
+ bool hasEnvironmentGenerator = false;
+ if (cmSystemTools::GetEnv("CMAKE_GENERATOR", envGenVar)) {
+ hasEnvironmentGenerator = true;
+ this->EnvironmentGenerator = envGenVar;
+ }
+
+ auto readGeneratorVar = [&](std::string name, std::string& key) {
+ std::string varValue;
+ if (cmSystemTools::GetEnv(name, varValue)) {
+ if (hasEnvironmentGenerator) {
+ key = varValue;
+ } else if (!this->GetIsInTryCompile()) {
+ std::string message = "Warning: Environment variable ";
+ message += name;
+ message += " will be ignored, because CMAKE_GENERATOR ";
+ message += "is not set.";
+ cmSystemTools::Message(message, "Warning");
+ }
+ }
+ };
+
+ readGeneratorVar("CMAKE_GENERATOR_INSTANCE", this->GeneratorInstance);
+ readGeneratorVar("CMAKE_GENERATOR_PLATFORM", this->GeneratorPlatform);
+ readGeneratorVar("CMAKE_GENERATOR_TOOLSET", this->GeneratorToolset);
+}
+
// Parse the args
-void cmake::SetArgs(const std::vector<std::string>& args,
- bool directoriesSetBefore)
+void cmake::SetArgs(const std::vector<std::string>& args)
{
- bool directoriesSet = directoriesSetBefore;
bool haveToolset = false;
bool havePlatform = false;
for (unsigned int i = 1; i < args.size(); ++i) {
std::string const& arg = args[i];
- if (arg.find("-H", 0) == 0) {
- directoriesSet = true;
+ if (arg.find("-H", 0) == 0 || arg.find("-S", 0) == 0) {
std::string path = arg.substr(2);
+ if (path.empty()) {
+ ++i;
+ if (i >= args.size()) {
+ cmSystemTools::Error("No source directory specified for -S");
+ return;
+ }
+ path = args[i];
+ if (path[0] == '-') {
+ cmSystemTools::Error("No source directory specified for -S");
+ return;
+ }
+ }
+
path = cmSystemTools::CollapseFullPath(path);
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);
+ if (path.empty()) {
+ ++i;
+ if (i >= args.size()) {
+ cmSystemTools::Error("No build directory specified for -B");
+ return;
+ }
+ path = args[i];
+ if (path[0] == '-') {
+ cmSystemTools::Error("No build directory specified for -B");
+ return;
+ }
+ }
+
path = cmSystemTools::CollapseFullPath(path);
cmSystemTools::ConvertToUnixSlashes(path);
this->SetHomeOutputDirectory(path);
@@ -653,10 +713,25 @@ void cmake::SetArgs(const std::vector<std::string>& args,
#endif
else if (arg.find("-D", 0) == 0) {
// skip for now
+ // in case '-D var=val' is given, also skip the next
+ // in case '-Dvar=val' is given, don't skip the next
+ if (arg.size() == 2) {
+ ++i;
+ }
} else if (arg.find("-U", 0) == 0) {
// skip for now
+ // in case '-U var' is given, also skip the next
+ // in case '-Uvar' is given, don't skip the next
+ if (arg.size() == 2) {
+ ++i;
+ }
} else if (arg.find("-C", 0) == 0) {
// skip for now
+ // in case '-C path' is given, also skip the next
+ // in case '-Cpath' is given, don't skip the next
+ if (arg.size() == 2) {
+ ++i;
+ }
} else if (arg.find("-P", 0) == 0) {
// skip for now
i++;
@@ -672,6 +747,7 @@ void cmake::SetArgs(const std::vector<std::string>& args,
this->GraphVizFile = path;
if (this->GraphVizFile.empty()) {
cmSystemTools::Error("No file specified for --graphviz");
+ return;
}
} else if (arg.find("--debug-trycompile", 0) == 0) {
std::cout << "debug trycompile on\n";
@@ -679,6 +755,14 @@ void cmake::SetArgs(const std::vector<std::string>& args,
} else if (arg.find("--debug-output", 0) == 0) {
std::cout << "Running with debug output on.\n";
this->SetDebugOutputOn(true);
+ } else if (arg.find("--loglevel=", 0) == 0) {
+ const auto logLevel =
+ StringToLogLevel(arg.substr(sizeof("--loglevel=") - 1));
+ if (logLevel == LogLevel::LOG_UNDEFINED) {
+ cmSystemTools::Error("Invalid level specified for --loglevel");
+ return;
+ }
+ this->SetLogLevel(logLevel);
} else if (arg.find("--trace-expand", 0) == 0) {
std::cout << "Running with expanded trace output on.\n";
this->SetTrace(true);
@@ -720,7 +804,7 @@ void cmake::SetArgs(const std::vector<std::string>& args,
cmSystemTools::Error("Multiple -A options not allowed");
return;
}
- this->GeneratorPlatform = value;
+ this->SetGeneratorPlatform(value);
havePlatform = true;
} else if (arg.find("-T", 0) == 0) {
std::string value = arg.substr(2);
@@ -736,7 +820,7 @@ void cmake::SetArgs(const std::vector<std::string>& args,
cmSystemTools::Error("Multiple -T options not allowed");
return;
}
- this->GeneratorToolset = value;
+ this->SetGeneratorToolset(value);
haveToolset = true;
} else if (arg.find("-G", 0) == 0) {
std::string value = arg.substr(2);
@@ -751,26 +835,74 @@ void cmake::SetArgs(const std::vector<std::string>& args,
}
cmGlobalGenerator* gen = this->CreateGlobalGenerator(value);
if (!gen) {
- cmSystemTools::Error("Could not create named generator ",
- value.c_str());
+ std::string kdevError;
+ if (value.find("KDevelop3", 0) != std::string::npos) {
+ kdevError = "\nThe KDevelop3 generator is not supported anymore.";
+ }
+
+ cmSystemTools::Error("Could not create named generator " + value +
+ kdevError);
this->PrintGeneratorList();
- } else {
- this->SetGlobalGenerator(gen);
+ return;
}
+ this->SetGlobalGenerator(gen);
}
- // no option assume it is the path to the source
+ // no option assume it is the path to the source or an existing build
else {
- directoriesSet = true;
- this->SetDirectoriesFromFile(arg.c_str());
+ this->SetDirectoriesFromFile(arg);
+ }
+ // Empty instance, platform and toolset if only a generator is specified
+ if (this->GlobalGenerator) {
+ this->GeneratorInstance = "";
+ if (!this->GeneratorPlatformSet) {
+ this->GeneratorPlatform = "";
+ }
+ if (!this->GeneratorToolsetSet) {
+ this->GeneratorToolset = "";
+ }
}
}
- if (!directoriesSet) {
- this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
+
+ const bool haveSourceDir = !this->GetHomeDirectory().empty();
+ const bool haveBinaryDir = !this->GetHomeOutputDirectory().empty();
+
+ if (this->CurrentWorkingMode == cmake::NORMAL_MODE && !haveSourceDir &&
+ !haveBinaryDir) {
+ this->IssueMessage(
+ MessageType::WARNING,
+ "No source or binary directory provided. Both will be assumed to be "
+ "the same as the current working directory, but note that this "
+ "warning will become a fatal error in future CMake releases.");
+ }
+
+ if (!haveSourceDir) {
this->SetHomeDirectory(cmSystemTools::GetCurrentWorkingDirectory());
}
+ if (!haveBinaryDir) {
+ this->SetHomeOutputDirectory(cmSystemTools::GetCurrentWorkingDirectory());
+ }
+}
+
+cmake::LogLevel cmake::StringToLogLevel(const std::string& levelStr)
+{
+ using LevelsPair = std::pair<std::string, LogLevel>;
+ static const std::vector<LevelsPair> levels = {
+ { "error", LogLevel::LOG_ERROR }, { "warning", LogLevel::LOG_WARNING },
+ { "notice", LogLevel::LOG_NOTICE }, { "status", LogLevel::LOG_STATUS },
+ { "verbose", LogLevel::LOG_VERBOSE }, { "debug", LogLevel::LOG_DEBUG },
+ { "trace", LogLevel::LOG_TRACE }
+ };
+
+ const auto levelStrLowCase = cmSystemTools::LowerCase(levelStr);
+
+ const auto it = std::find_if(levels.cbegin(), levels.cend(),
+ [&levelStrLowCase](const LevelsPair& p) {
+ return p.first == levelStrLowCase;
+ });
+ return (it != levels.cend()) ? it->second : LogLevel::LOG_UNDEFINED;
}
-void cmake::SetDirectoriesFromFile(const char* arg)
+void cmake::SetDirectoriesFromFile(const std::string& arg)
{
// Check if the argument refers to a CMakeCache.txt or
// CMakeLists.txt file.
@@ -784,10 +916,10 @@ void cmake::SetDirectoriesFromFile(const char* arg)
cacheFile += "/CMakeCache.txt";
std::string listFile = path;
listFile += "/CMakeLists.txt";
- if (cmSystemTools::FileExists(cacheFile.c_str())) {
+ if (cmSystemTools::FileExists(cacheFile)) {
cachePath = path;
}
- if (cmSystemTools::FileExists(listFile.c_str())) {
+ if (cmSystemTools::FileExists(listFile)) {
listPath = path;
}
} else if (cmSystemTools::FileExists(arg)) {
@@ -837,20 +969,27 @@ void cmake::SetDirectoriesFromFile(const char* arg)
this->SetHomeOutputDirectory(listPath);
} else {
// Source directory given on command line. Use current working
- // directory as build tree.
- std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
- this->SetHomeOutputDirectory(cwd);
+ // directory as build tree if -B hasn't been given already
+ if (this->GetHomeOutputDirectory().empty()) {
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ this->SetHomeOutputDirectory(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->SetHomeOutputDirectory(cwd);
+ if (this->GetHomeDirectory().empty()) {
+ // We didn't find a CMakeLists.txt and it wasn't specified
+ // with -S. Assume it is the path to the source tree
+ std::string full = cmSystemTools::CollapseFullPath(arg);
+ this->SetHomeDirectory(full);
+ }
+ if (this->GetHomeOutputDirectory().empty()) {
+ // We didn't find a CMakeCache.txt and it wasn't specified
+ // with -B. Assume the current working directory as the build tree.
+ std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
+ this->SetHomeOutputDirectory(cwd);
+ }
}
// at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
@@ -870,13 +1009,13 @@ int cmake::AddCMakePaths()
"Path to cpack program executable.", cmStateEnums::INTERNAL);
#endif
if (!cmSystemTools::FileExists(
- (cmSystemTools::GetCMakeRoot() + "/Modules/CMake.cmake").c_str())) {
+ (cmSystemTools::GetCMakeRoot() + "/Modules/CMake.cmake"))) {
// 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());
+ "Modules directory not found in\n" +
+ cmSystemTools::GetCMakeRoot());
return 0;
}
this->AddCacheEntry("CMAKE_ROOT", cmSystemTools::GetCMakeRoot().c_str(),
@@ -893,66 +1032,61 @@ void cmake::AddDefaultExtraGenerators()
this->ExtraGenerators.push_back(cmExtraSublimeTextGenerator::GetFactory());
this->ExtraGenerators.push_back(cmExtraKateGenerator::GetFactory());
-#ifdef CMAKE_USE_ECLIPSE
+# ifdef CMAKE_USE_ECLIPSE
this->ExtraGenerators.push_back(cmExtraEclipseCDT4Generator::GetFactory());
-#endif
+# endif
-#ifdef CMAKE_USE_KDEVELOP
- this->ExtraGenerators.push_back(cmGlobalKdevelopGenerator::GetFactory());
-#endif
#endif
}
-void cmake::GetRegisteredGenerators(
- std::vector<GeneratorInfo>& generators) const
+void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
+ bool includeNamesWithPlatform) const
{
- for (RegisteredGeneratorsVector::const_iterator i = this->Generators.begin(),
- e = this->Generators.end();
- i != e; ++i) {
- std::vector<std::string> names;
- (*i)->GetGenerators(names);
+ for (cmGlobalGeneratorFactory* gen : this->Generators) {
+ std::vector<std::string> names = gen->GetGeneratorNames();
+
+ if (includeNamesWithPlatform) {
+ cmAppend(names, gen->GetGeneratorNamesWithPlatform());
+ }
- for (size_t j = 0; j < names.size(); ++j) {
+ for (std::string const& name : names) {
GeneratorInfo info;
- info.supportsToolset = (*i)->SupportsToolset();
- info.supportsPlatform = (*i)->SupportsPlatform();
- info.name = names[j];
- info.baseName = names[j];
+ info.supportsToolset = gen->SupportsToolset();
+ info.supportsPlatform = gen->SupportsPlatform();
+ info.supportedPlatforms = gen->GetKnownPlatforms();
+ info.defaultPlatform = gen->GetDefaultPlatformName();
+ info.name = name;
+ info.baseName = name;
info.isAlias = false;
- generators.push_back(info);
+ generators.push_back(std::move(info));
}
}
- for (RegisteredExtraGeneratorsVector::const_iterator
- i = this->ExtraGenerators.begin(),
- e = this->ExtraGenerators.end();
- i != e; ++i) {
+ for (cmExternalMakefileProjectGeneratorFactory* eg : this->ExtraGenerators) {
const std::vector<std::string> genList =
- (*i)->GetSupportedGlobalGenerators();
- for (std::vector<std::string>::const_iterator gen = genList.begin();
- gen != genList.end(); ++gen) {
+ eg->GetSupportedGlobalGenerators();
+ for (std::string const& gen : genList) {
GeneratorInfo info;
info.name = cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
- *gen, (*i)->GetName());
- info.baseName = *gen;
- info.extraName = (*i)->GetName();
+ gen, eg->GetName());
+ info.baseName = gen;
+ info.extraName = eg->GetName();
info.supportsPlatform = false;
info.supportsToolset = false;
info.isAlias = false;
- generators.push_back(info);
+ generators.push_back(std::move(info));
}
- for (std::vector<std::string>::const_iterator a = (*i)->Aliases.begin();
- a != (*i)->Aliases.end(); ++a) {
+ for (std::string const& a : eg->Aliases) {
GeneratorInfo info;
- info.name = *a;
+ info.name = a;
if (!genList.empty()) {
info.baseName = genList.at(0);
}
- info.extraName = (*i)->GetName();
+ info.extraName = eg->GetName();
info.supportsPlatform = false;
info.supportsToolset = false;
info.isAlias = true;
- generators.push_back(info);
+ generators.push_back(std::move(info));
}
}
}
@@ -962,28 +1096,24 @@ createExtraGenerator(
const std::vector<cmExternalMakefileProjectGeneratorFactory*>& in,
const std::string& name)
{
- for (std::vector<cmExternalMakefileProjectGeneratorFactory*>::const_iterator
- i = in.begin();
- i != in.end(); ++i) {
+ for (cmExternalMakefileProjectGeneratorFactory* i : in) {
const std::vector<std::string> generators =
- (*i)->GetSupportedGlobalGenerators();
- if ((*i)->GetName() == name) { // Match aliases
- return std::make_pair((*i)->CreateExternalMakefileProjectGenerator(),
+ i->GetSupportedGlobalGenerators();
+ if (i->GetName() == name) { // Match aliases
+ return std::make_pair(i->CreateExternalMakefileProjectGenerator(),
generators.at(0));
}
- for (std::vector<std::string>::const_iterator g = generators.begin();
- g != generators.end(); ++g) {
+ for (std::string const& g : generators) {
const std::string fullName =
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
- *g, (*i)->GetName());
+ g, i->GetName());
if (fullName == name) {
- return std::make_pair((*i)->CreateExternalMakefileProjectGenerator(),
- *g);
+ return std::make_pair(i->CreateExternalMakefileProjectGenerator(), g);
}
}
}
return std::make_pair(
- static_cast<cmExternalMakefileProjectGenerator*>(CM_NULLPTR), name);
+ static_cast<cmExternalMakefileProjectGenerator*>(nullptr), name);
}
cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
@@ -993,10 +1123,9 @@ cmGlobalGenerator* cmake::CreateGlobalGenerator(const std::string& gname)
cmExternalMakefileProjectGenerator* extraGenerator = extra.first;
const std::string name = extra.second;
- cmGlobalGenerator* generator = CM_NULLPTR;
- for (RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
- i != this->Generators.end(); ++i) {
- generator = (*i)->CreateGlobalGenerator(name, this);
+ cmGlobalGenerator* generator = nullptr;
+ for (cmGlobalGeneratorFactory* g : this->Generators) {
+ generator = g->CreateGlobalGenerator(name, this);
if (generator) {
break;
}
@@ -1019,7 +1148,7 @@ void cmake::SetHomeDirectory(const std::string& dir)
}
}
-const char* cmake::GetHomeDirectory() const
+std::string const& cmake::GetHomeDirectory() const
{
return this->State->GetSourceDirectory();
}
@@ -1032,7 +1161,7 @@ void cmake::SetHomeOutputDirectory(const std::string& dir)
}
}
-const char* cmake::GetHomeOutputDirectory() const
+std::string const& cmake::GetHomeOutputDirectory() const
{
return this->State->GetBinaryDirectory();
}
@@ -1043,14 +1172,14 @@ std::string cmake::FindCacheFile(const std::string& binaryDir)
cmSystemTools::ConvertToUnixSlashes(cachePath);
std::string cacheFile = cachePath;
cacheFile += "/CMakeCache.txt";
- if (!cmSystemTools::FileExists(cacheFile.c_str())) {
+ if (!cmSystemTools::FileExists(cacheFile)) {
// search in parent directories for cache
std::string cmakeFiles = cachePath;
cmakeFiles += "/CMakeFiles";
- if (cmSystemTools::FileExists(cmakeFiles.c_str())) {
+ if (cmSystemTools::FileExists(cmakeFiles)) {
std::string cachePathFound =
cmSystemTools::FileExistsInParentDirectories("CMakeCache.txt",
- cachePath.c_str(), "/");
+ cachePath, "/");
if (!cachePathFound.empty()) {
cachePath = cmSystemTools::GetFilenamePath(cachePathFound);
}
@@ -1091,10 +1220,10 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator* gg)
// Save the environment variables CXX and CC
if (!cmSystemTools::GetEnv("CXX", this->CXXEnvironment)) {
- this->CXXEnvironment = "";
+ this->CXXEnvironment.clear();
}
if (!cmSystemTools::GetEnv("CC", this->CCEnvironment)) {
- this->CCEnvironment = "";
+ this->CCEnvironment.clear();
}
}
@@ -1103,7 +1232,7 @@ int cmake::DoPreConfigureChecks()
// Make sure the Source directory contains a CMakeLists.txt file.
std::string srcList = this->GetHomeDirectory();
srcList += "/CMakeLists.txt";
- if (!cmSystemTools::FileExists(srcList.c_str())) {
+ if (!cmSystemTools::FileExists(srcList)) {
std::ostringstream err;
if (cmSystemTools::FileIsDirectory(this->GetHomeDirectory())) {
err << "The source directory \"" << this->GetHomeDirectory()
@@ -1117,14 +1246,14 @@ int cmake::DoPreConfigureChecks()
}
err << "Specify --help for usage, or press the help button on the CMake "
"GUI.";
- cmSystemTools::Error(err.str().c_str());
+ cmSystemTools::Error(err.str());
return -2;
}
// do a sanity check on some values
if (this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY")) {
std::string cacheStart =
- this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
+ *this->State->GetInitializedCacheValue("CMAKE_HOME_DIRECTORY");
cacheStart += "/CMakeLists.txt";
std::string currentStart = this->GetHomeDirectory();
currentStart += "/CMakeLists.txt";
@@ -1135,7 +1264,7 @@ int cmake::DoPreConfigureChecks()
message += cacheStart;
message += "\" used to generate cache. ";
message += "Re-run cmake with a different source directory.";
- cmSystemTools::Error(message.c_str());
+ cmSystemTools::Error(message);
return -2;
}
} else {
@@ -1184,7 +1313,7 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
save.help = help;
}
}
- saved.push_back(save);
+ saved.push_back(std::move(save));
}
// remove the cache
@@ -1192,11 +1321,10 @@ int cmake::HandleDeleteCacheVariables(const std::string& var)
// 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);
+ for (SaveCacheEntry const& i : saved) {
+ this->AddCacheEntry(i.key, i.value.c_str(), i.help.c_str(), i.type);
}
- cmSystemTools::Message(warning.str().c_str());
+ cmSystemTools::Message(warning.str());
// avoid reconfigure if there were errors
if (!cmSystemTools::GetErrorOccuredFlag()) {
// re-run configure
@@ -1265,6 +1393,23 @@ int cmake::Configure()
}
}
+ // Cache variables may have already been set by a previous invocation,
+ // so we cannot rely on command line options alone. Always ensure our
+ // messenger is in sync with the cache.
+ const char* value = this->State->GetCacheEntryValue("CMAKE_WARN_DEPRECATED");
+ this->Messenger->SetSuppressDeprecatedWarnings(value &&
+ cmSystemTools::IsOff(value));
+
+ value = this->State->GetCacheEntryValue("CMAKE_ERROR_DEPRECATED");
+ this->Messenger->SetDeprecatedWarningsAsErrors(cmSystemTools::IsOn(value));
+
+ value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
+ this->Messenger->SetSuppressDevWarnings(cmSystemTools::IsOn(value));
+
+ value = this->State->GetCacheEntryValue("CMAKE_SUPPRESS_DEVELOPER_ERRORS");
+ this->Messenger->SetDevWarningsAsErrors(value &&
+ cmSystemTools::IsOff(value));
+
int ret = this->ActualConfigure();
const char* delCacheVars =
this->State->GetGlobalProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
@@ -1280,16 +1425,13 @@ int cmake::ActualConfigure()
this->UpdateConversionPathTable();
this->CleanupCommandsAndMacros();
- int res = 0;
- if (this->GetWorkingMode() == NORMAL_MODE) {
- res = this->DoPreConfigureChecks();
- }
+ int res = this->DoPreConfigureChecks();
if (res < 0) {
return -2;
}
if (!res) {
this->AddCacheEntry(
- "CMAKE_HOME_DIRECTORY", this->GetHomeDirectory(),
+ "CMAKE_HOME_DIRECTORY", this->GetHomeDirectory().c_str(),
"Source directory with the top level CMakeLists.txt file for this "
"project",
cmStateEnums::INTERNAL);
@@ -1297,14 +1439,14 @@ int cmake::ActualConfigure()
// no generator specified on the command line
if (!this->GlobalGenerator) {
- const char* genName =
+ const std::string* genName =
this->State->GetInitializedCacheValue("CMAKE_GENERATOR");
- const char* extraGenName =
+ const std::string* extraGenName =
this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
if (genName) {
std::string fullName =
cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
- genName, extraGenName ? extraGenName : "");
+ *genName, extraGenName ? *extraGenName : "");
this->GlobalGenerator = this->CreateGlobalGenerator(fullName);
}
if (this->GlobalGenerator) {
@@ -1322,17 +1464,17 @@ int cmake::ActualConfigure()
}
}
- const char* genName =
+ const std::string* genName =
this->State->GetInitializedCacheValue("CMAKE_GENERATOR");
if (genName) {
- if (!this->GlobalGenerator->MatchesGeneratorName(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 += *genName;
message += "\nEither remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.";
- cmSystemTools::Error(message.c_str());
+ cmSystemTools::Error(message);
return -2;
}
}
@@ -1346,18 +1488,35 @@ int cmake::ActualConfigure()
cmStateEnums::INTERNAL);
}
- if (const char* platformName =
+ if (const std::string* instance =
+ this->State->GetInitializedCacheValue("CMAKE_GENERATOR_INSTANCE")) {
+ if (this->GeneratorInstanceSet && this->GeneratorInstance != *instance) {
+ std::string message = "Error: generator instance: ";
+ message += this->GeneratorInstance;
+ message += "\nDoes not match the instance used previously: ";
+ message += *instance;
+ message += "\nEither remove the CMakeCache.txt file and CMakeFiles "
+ "directory or choose a different binary directory.";
+ cmSystemTools::Error(message);
+ return -2;
+ }
+ } else {
+ this->AddCacheEntry(
+ "CMAKE_GENERATOR_INSTANCE", this->GeneratorInstance.c_str(),
+ "Generator instance identifier.", cmStateEnums::INTERNAL);
+ }
+
+ if (const std::string* platformName =
this->State->GetInitializedCacheValue("CMAKE_GENERATOR_PLATFORM")) {
- if (this->GeneratorPlatform.empty()) {
- this->GeneratorPlatform = platformName;
- } else if (this->GeneratorPlatform != platformName) {
+ if (this->GeneratorPlatformSet &&
+ this->GeneratorPlatform != *platformName) {
std::string message = "Error: generator platform: ";
message += this->GeneratorPlatform;
message += "\nDoes not match the platform used previously: ";
- message += platformName;
+ message += *platformName;
message += "\nEither remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.";
- cmSystemTools::Error(message.c_str());
+ cmSystemTools::Error(message);
return -2;
}
} else {
@@ -1366,18 +1525,16 @@ int cmake::ActualConfigure()
"Name of generator platform.", cmStateEnums::INTERNAL);
}
- if (const char* tsName =
+ if (const std::string* tsName =
this->State->GetInitializedCacheValue("CMAKE_GENERATOR_TOOLSET")) {
- if (this->GeneratorToolset.empty()) {
- this->GeneratorToolset = tsName;
- } else if (this->GeneratorToolset != tsName) {
+ if (this->GeneratorToolsetSet && this->GeneratorToolset != *tsName) {
std::string message = "Error: generator toolset: ";
message += this->GeneratorToolset;
message += "\nDoes not match the toolset used previously: ";
- message += tsName;
+ message += *tsName;
message += "\nEither remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory.";
- cmSystemTools::Error(message.c_str());
+ cmSystemTools::Error(message);
return -2;
}
} else {
@@ -1396,6 +1553,11 @@ int cmake::ActualConfigure()
this->TruncateOutputLog("CMakeError.log");
}
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ this->FileAPI = cm::make_unique<cmFileAPI>(this);
+ this->FileAPI->ReadQueries();
+#endif
+
// actually do the configure
this->GlobalGenerator->Configure();
// Before saving the cache
@@ -1433,18 +1595,26 @@ int cmake::ActualConfigure()
"CMakeLists.txt ?");
}
- // only save the cache if there were no fatal errors
- if (this->GetWorkingMode() == NORMAL_MODE) {
- this->SaveCache(this->GetHomeOutputDirectory());
- }
+ this->State->SaveVerificationScript(this->GetHomeOutputDirectory());
+ this->SaveCache(this->GetHomeOutputDirectory());
if (cmSystemTools::GetErrorOccuredFlag()) {
return -1;
}
return 0;
}
-void cmake::CreateDefaultGlobalGenerator()
+std::unique_ptr<cmGlobalGenerator> cmake::EvaluateDefaultGlobalGenerator()
{
+ if (!this->EnvironmentGenerator.empty()) {
+ cmGlobalGenerator* gen =
+ this->CreateGlobalGenerator(this->EnvironmentGenerator);
+ if (!gen) {
+ cmSystemTools::Error("CMAKE_GENERATOR was set but the specified "
+ "generator doesn't exist. Using CMake default.");
+ } else {
+ return std::unique_ptr<cmGlobalGenerator>(gen);
+ }
+ }
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
std::string found;
// Try to find the newest VS installed on the computer and
@@ -1460,28 +1630,27 @@ void cmake::CreateDefaultGlobalGenerator()
const char* GeneratorName;
};
static VSVersionedGenerator const vsGenerators[] = {
- { "15.0", "Visual Studio 15 2017" }, //
{ "14.0", "Visual Studio 14 2015" }, //
{ "12.0", "Visual Studio 12 2013" }, //
{ "11.0", "Visual Studio 11 2012" }, //
{ "10.0", "Visual Studio 10 2010" }, //
- { "9.0", "Visual Studio 9 2008" }, //
- { "8.0", "Visual Studio 8 2005" }
+ { "9.0", "Visual Studio 9 2008" }
};
static const char* const vsEntries[] = {
"\\Setup\\VC;ProductDir", //
";InstallDir" //
};
- cmVSSetupAPIHelper vsSetupAPIHelper;
- if (vsSetupAPIHelper.IsVS2017Installed()) {
+ if (cmVSSetupAPIHelper(16).IsVSInstalled()) {
+ found = "Visual Studio 16 2019";
+ } else if (cmVSSetupAPIHelper(15).IsVSInstalled()) {
found = "Visual Studio 15 2017";
} else {
- for (VSVersionedGenerator const* g = cmArrayBegin(vsGenerators);
- found.empty() && g != cmArrayEnd(vsGenerators); ++g) {
- for (const char* const* v = cmArrayBegin(vsVariants);
- found.empty() && v != cmArrayEnd(vsVariants); ++v) {
- for (const char* const* e = cmArrayBegin(vsEntries);
- found.empty() && e != cmArrayEnd(vsEntries); ++e) {
+ for (VSVersionedGenerator const* g = cm::cbegin(vsGenerators);
+ found.empty() && g != cm::cend(vsGenerators); ++g) {
+ for (const char* const* v = cm::cbegin(vsVariants);
+ found.empty() && v != cm::cend(vsVariants); ++v) {
+ for (const char* const* e = cm::cbegin(vsEntries);
+ found.empty() && e != cm::cend(vsEntries); ++e) {
std::string const reg = vsregBase + *v + g->MSVersion + *e;
std::string dir;
if (cmSystemTools::ReadRegistryValue(reg, dir,
@@ -1497,11 +1666,20 @@ void cmake::CreateDefaultGlobalGenerator()
if (!gen) {
gen = new cmGlobalNMakeMakefileGenerator(this);
}
- this->SetGlobalGenerator(gen);
- std::cout << "-- Building for: " << gen->GetName() << "\n";
+ return std::unique_ptr<cmGlobalGenerator>(gen);
#else
- this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3(this));
+ return cm::make_unique<cmGlobalUnixMakefileGenerator3>(this);
+#endif
+}
+
+void cmake::CreateDefaultGlobalGenerator()
+{
+ auto gen = this->EvaluateDefaultGlobalGenerator();
+#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
+ // This print could be unified for all platforms
+ std::cout << "-- Building for: " << gen->GetName() << "\n";
#endif
+ this->SetGlobalGenerator(gen.release());
}
void cmake::PreLoadCMakeFiles()
@@ -1510,15 +1688,15 @@ void cmake::PreLoadCMakeFiles()
std::string pre_load = this->GetHomeDirectory();
if (!pre_load.empty()) {
pre_load += "/PreLoad.cmake";
- if (cmSystemTools::FileExists(pre_load.c_str())) {
- this->ReadListFile(args, pre_load.c_str());
+ if (cmSystemTools::FileExists(pre_load)) {
+ this->ReadListFile(args, pre_load);
}
}
pre_load = this->GetHomeOutputDirectory();
if (!pre_load.empty()) {
pre_load += "/PreLoad.cmake";
- if (cmSystemTools::FileExists(pre_load.c_str())) {
- this->ReadListFile(args, pre_load.c_str());
+ if (cmSystemTools::FileExists(pre_load)) {
+ this->ReadListFile(args, pre_load);
}
}
}
@@ -1534,13 +1712,13 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
// 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())) {
+ cmakeCheckStampList(this->CheckStampList)) {
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())) {
+ cmakeCheckStampFile(this->CheckStampFile)) {
return 0;
}
@@ -1590,7 +1768,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
}
int ret = this->Configure();
- if (ret || this->GetWorkingMode() != NORMAL_MODE) {
+ if (ret) {
#if defined(CMAKE_HAVE_VS_GENERATORS)
if (!this->VSSolutionFile.empty() && this->GlobalGenerator) {
// CMake is running to regenerate a Visual Studio build tree
@@ -1608,9 +1786,14 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
return ret;
}
ret = this->Generate();
+ if (ret) {
+ cmSystemTools::Message("CMake Generate step failed. "
+ "Build files cannot be regenerated correctly.");
+ return ret;
+ }
std::string message = "Build files have been written to: ";
message += this->GetHomeOutputDirectory();
- this->UpdateProgress(message.c_str(), -1);
+ this->UpdateProgress(message, -1);
return ret;
}
@@ -1625,7 +1808,7 @@ int cmake::Generate()
this->GlobalGenerator->Generate();
if (!this->GraphVizFile.empty()) {
std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
- this->GenerateGraphViz(this->GraphVizFile.c_str());
+ this->GenerateGraphViz(this->GraphVizFile);
}
if (this->WarnUnusedCli) {
this->RunCheckForUnusedVariables();
@@ -1636,9 +1819,12 @@ int cmake::Generate()
// 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->SaveCache(this->GetHomeOutputDirectory());
- }
+ this->SaveCache(this->GetHomeOutputDirectory());
+
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ this->FileAPI->WriteReplies();
+#endif
+
return 0;
}
@@ -1648,11 +1834,66 @@ void cmake::AddCacheEntry(const std::string& key, const char* value,
this->State->AddCacheEntry(key, value, helpString,
cmStateEnums::CacheEntryType(type));
this->UnwatchUnusedCli(key);
+
+ if (key == "CMAKE_WARN_DEPRECATED") {
+ this->Messenger->SetSuppressDeprecatedWarnings(
+ value && cmSystemTools::IsOff(value));
+ } else if (key == "CMAKE_ERROR_DEPRECATED") {
+ this->Messenger->SetDeprecatedWarningsAsErrors(cmSystemTools::IsOn(value));
+ } else if (key == "CMAKE_SUPPRESS_DEVELOPER_WARNINGS") {
+ this->Messenger->SetSuppressDevWarnings(cmSystemTools::IsOn(value));
+ } else if (key == "CMAKE_SUPPRESS_DEVELOPER_ERRORS") {
+ this->Messenger->SetDevWarningsAsErrors(value &&
+ cmSystemTools::IsOff(value));
+ }
+}
+
+bool cmake::DoWriteGlobVerifyTarget() const
+{
+ return this->State->DoWriteGlobVerifyTarget();
+}
+
+std::string const& cmake::GetGlobVerifyScript() const
+{
+ return this->State->GetGlobVerifyScript();
+}
+
+std::string const& cmake::GetGlobVerifyStamp() const
+{
+ return this->State->GetGlobVerifyStamp();
+}
+
+void cmake::AddGlobCacheEntry(bool recurse, bool listDirectories,
+ bool followSymlinks, const std::string& relative,
+ const std::string& expression,
+ const std::vector<std::string>& files,
+ const std::string& variable,
+ cmListFileBacktrace const& backtrace)
+{
+ this->State->AddGlobCacheEntry(recurse, listDirectories, followSymlinks,
+ relative, expression, files, variable,
+ backtrace);
+}
+
+std::string cmake::StripExtension(const std::string& file) const
+{
+ auto dotpos = file.rfind('.');
+ if (dotpos != std::string::npos) {
+ auto ext = file.substr(dotpos + 1);
+#if defined(_WIN32) || defined(__APPLE__)
+ ext = cmSystemTools::LowerCase(ext);
+#endif
+ if (this->IsSourceExtension(ext) || this->IsHeaderExtension(ext)) {
+ return file.substr(0, dotpos);
+ }
+ }
+ return file;
}
const char* cmake::GetCacheDefinition(const std::string& name) const
{
- return this->State->GetInitializedCacheValue(name);
+ const std::string* p = this->State->GetInitializedCacheValue(name);
+ return p ? p->c_str() : nullptr;
}
void cmake::AddScriptingCommands()
@@ -1668,24 +1909,28 @@ void cmake::AddProjectCommands()
void cmake::AddDefaultGenerators()
{
#if defined(_WIN32) && !defined(__CYGWIN__)
-#if !defined(CMAKE_BOOT_MINGW)
- this->Generators.push_back(cmGlobalVisualStudio15Generator::NewFactory());
+# if !defined(CMAKE_BOOT_MINGW)
+ this->Generators.push_back(
+ cmGlobalVisualStudioVersionedGenerator::NewFactory16());
+ this->Generators.push_back(
+ cmGlobalVisualStudioVersionedGenerator::NewFactory15());
this->Generators.push_back(cmGlobalVisualStudio14Generator::NewFactory());
this->Generators.push_back(cmGlobalVisualStudio12Generator::NewFactory());
this->Generators.push_back(cmGlobalVisualStudio11Generator::NewFactory());
this->Generators.push_back(cmGlobalVisualStudio10Generator::NewFactory());
this->Generators.push_back(cmGlobalVisualStudio9Generator::NewFactory());
- this->Generators.push_back(cmGlobalVisualStudio8Generator::NewFactory());
this->Generators.push_back(cmGlobalBorlandMakefileGenerator::NewFactory());
this->Generators.push_back(cmGlobalNMakeMakefileGenerator::NewFactory());
this->Generators.push_back(cmGlobalJOMMakefileGenerator::NewFactory());
- this->Generators.push_back(cmGlobalGhsMultiGenerator::NewFactory());
-#endif
+# endif
this->Generators.push_back(cmGlobalMSYSMakefileGenerator::NewFactory());
this->Generators.push_back(cmGlobalMinGWMakefileGenerator::NewFactory());
#endif
this->Generators.push_back(cmGlobalUnixMakefileGenerator3::NewFactory());
#if defined(CMAKE_BUILD_WITH_CMAKE)
+# if defined(__linux__) || defined(_WIN32)
+ this->Generators.push_back(cmGlobalGhsMultiGenerator::NewFactory());
+# endif
this->Generators.push_back(cmGlobalNinjaGenerator::NewFactory());
#endif
#if defined(CMAKE_USE_WMAKE)
@@ -1710,7 +1955,7 @@ int cmake::LoadCache()
// 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())) {
+ if (cmSystemTools::FileExists(cacheFile)) {
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 "
@@ -1737,25 +1982,23 @@ bool cmake::LoadCache(const std::string& path, bool internal,
std::set<std::string>& includes)
{
bool result = this->State->LoadCache(path, internal, excludes, includes);
- static const char* entries[] = { "CMAKE_CACHE_MAJOR_VERSION",
- "CMAKE_CACHE_MINOR_VERSION" };
- for (const char* const* nameIt = cmArrayBegin(entries);
- nameIt != cmArrayEnd(entries); ++nameIt) {
- this->UnwatchUnusedCli(*nameIt);
+ static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION",
+ "CMAKE_CACHE_MINOR_VERSION" };
+ for (auto const& entry : entries) {
+ this->UnwatchUnusedCli(entry);
}
return result;
}
bool cmake::SaveCache(const std::string& path)
{
- bool result = this->State->SaveCache(path);
- static const char* entries[] = { "CMAKE_CACHE_MAJOR_VERSION",
- "CMAKE_CACHE_MINOR_VERSION",
- "CMAKE_CACHE_PATCH_VERSION",
- "CMAKE_CACHEFILE_DIR" };
- for (const char* const* nameIt = cmArrayBegin(entries);
- nameIt != cmArrayEnd(entries); ++nameIt) {
- this->UnwatchUnusedCli(*nameIt);
+ bool result = this->State->SaveCache(path, this->GetMessenger());
+ static const auto entries = { "CMAKE_CACHE_MAJOR_VERSION",
+ "CMAKE_CACHE_MINOR_VERSION",
+ "CMAKE_CACHE_PATCH_VERSION",
+ "CMAKE_CACHEFILE_DIR" };
+ for (auto const& entry : entries) {
+ this->UnwatchUnusedCli(entry);
}
return result;
}
@@ -1765,17 +2008,15 @@ bool cmake::DeleteCache(const std::string& path)
return this->State->DeleteCache(path);
}
-void cmake::SetProgressCallback(ProgressCallbackType f, void* cd)
+void cmake::SetProgressCallback(ProgressCallbackType f)
{
- this->ProgressCallback = f;
- this->ProgressCallbackClientData = cd;
+ this->ProgressCallback = std::move(f);
}
-void cmake::UpdateProgress(const char* msg, float prog)
+void cmake::UpdateProgress(const std::string& msg, float prog)
{
if (this->ProgressCallback && !this->State->GetIsInTryCompile()) {
- (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
- return;
+ this->ProgressCallback(msg, prog);
}
}
@@ -1789,49 +2030,66 @@ void cmake::SetIsInTryCompile(bool b)
this->State->SetIsInTryCompile(b);
}
-void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
+void cmake::AppendGlobalGeneratorsDocumentation(
+ std::vector<cmDocumentationEntry>& v)
{
- for (RegisteredGeneratorsVector::const_iterator i = this->Generators.begin();
- i != this->Generators.end(); ++i) {
+ const auto defaultGenerator = this->EvaluateDefaultGlobalGenerator();
+ const std::string defaultName = defaultGenerator->GetName();
+ bool foundDefaultOne = false;
+
+ for (cmGlobalGeneratorFactory* g : this->Generators) {
cmDocumentationEntry e;
- (*i)->GetDocumentation(e);
- v.push_back(e);
+ g->GetDocumentation(e);
+ if (!foundDefaultOne &&
+ cmSystemTools::StringStartsWith(e.Name, defaultName.c_str())) {
+ e.CustomNamePrefix = '*';
+ foundDefaultOne = true;
+ }
+ v.push_back(std::move(e));
}
- for (RegisteredExtraGeneratorsVector::const_iterator i =
- this->ExtraGenerators.begin();
- i != this->ExtraGenerators.end(); ++i) {
- const std::string doc = (*i)->GetDocumentation();
- const std::string name = (*i)->GetName();
+}
+
+void cmake::AppendExtraGeneratorsDocumentation(
+ std::vector<cmDocumentationEntry>& v)
+{
+ for (cmExternalMakefileProjectGeneratorFactory* eg : this->ExtraGenerators) {
+ const std::string doc = eg->GetDocumentation();
+ const std::string name = eg->GetName();
// Aliases:
- for (std::vector<std::string>::const_iterator a = (*i)->Aliases.begin();
- a != (*i)->Aliases.end(); ++a) {
+ for (std::string const& a : eg->Aliases) {
cmDocumentationEntry e;
- e.Name = *a;
+ e.Name = a;
e.Brief = doc;
- v.push_back(e);
+ v.push_back(std::move(e));
}
// Full names:
const std::vector<std::string> generators =
- (*i)->GetSupportedGlobalGenerators();
- for (std::vector<std::string>::const_iterator g = generators.begin();
- g != generators.end(); ++g) {
+ eg->GetSupportedGlobalGenerators();
+ for (std::string const& g : generators) {
cmDocumentationEntry e;
e.Name =
- cmExternalMakefileProjectGenerator::CreateFullGeneratorName(*g, name);
+ cmExternalMakefileProjectGenerator::CreateFullGeneratorName(g, name);
e.Brief = doc;
- v.push_back(e);
+ v.push_back(std::move(e));
}
}
}
+std::vector<cmDocumentationEntry> cmake::GetGeneratorsDocumentation()
+{
+ std::vector<cmDocumentationEntry> v;
+ this->AppendGlobalGeneratorsDocumentation(v);
+ this->AppendExtraGeneratorsDocumentation(v);
+ return v;
+}
+
void cmake::PrintGeneratorList()
{
#ifdef CMAKE_BUILD_WITH_CMAKE
cmDocumentation doc;
- std::vector<cmDocumentationEntry> generators;
- this->GetGeneratorDocumentation(generators);
+ auto generators = this->GetGeneratorsDocumentation();
doc.AppendSection("Generators", generators);
std::cerr << "\n";
doc.PrintDocumentation(cmDocumentation::ListGenerators, std::cerr);
@@ -1841,13 +2099,13 @@ void cmake::PrintGeneratorList()
void cmake::UpdateConversionPathTable()
{
// Update the path conversion table with any specified file:
- const char* tablepath =
+ const std::string* tablepath =
this->State->GetInitializedCacheValue("CMAKE_PATH_TRANSLATION_FILE");
if (tablepath) {
- cmsys::ifstream table(tablepath);
+ cmsys::ifstream table(tablepath->c_str());
if (!table) {
- cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
+ cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to " + *tablepath +
". CMake can not open file.");
cmSystemTools::ReportLastSystemError("CMake can not open file.");
} else {
@@ -1876,37 +2134,38 @@ int cmake::CheckBuildSystem()
if (verbose) {
std::ostringstream msg;
msg << "Re-run cmake no build system arguments\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
return 1;
}
// If the file provided does not exist, we have to rerun.
- if (!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str())) {
+ if (!cmSystemTools::FileExists(this->CheckBuildSystemArgument)) {
if (verbose) {
std::ostringstream msg;
msg << "Re-run cmake missing file: " << this->CheckBuildSystemArgument
<< "\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
return 1;
}
// Read the rerun check file and use it to decide whether to do the
// global generate.
- cmake cm(RoleScript); // Actually, all we need is the `set` command.
+ // Actually, all we need is the `set` command.
+ cmake cm(RoleScript, cmState::Unknown);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
- CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
- if (!mf->ReadListFile(this->CheckBuildSystemArgument.c_str()) ||
+ cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+ if (!mf.ReadListFile(this->CheckBuildSystemArgument) ||
cmSystemTools::GetErrorOccuredFlag()) {
if (verbose) {
std::ostringstream msg;
msg << "Re-run cmake error reading : " << this->CheckBuildSystemArgument
<< "\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
// There was an error reading the file. Just rerun.
return 1;
@@ -1914,35 +2173,33 @@ int cmake::CheckBuildSystem()
if (this->ClearBuildSystem) {
// Get the generator used for this build system.
- const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
+ 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.
- CM_AUTO_PTR<cmGlobalGenerator> ggd(this->CreateGlobalGenerator(genName));
- if (ggd.get()) {
+ std::unique_ptr<cmGlobalGenerator> ggd(
+ this->CreateGlobalGenerator(genName));
+ if (ggd) {
cm.GetCurrentSnapshot().SetDefaultDefinitions();
- CM_AUTO_PTR<cmMakefile> mfd(
- new cmMakefile(ggd.get(), cm.GetCurrentSnapshot()));
- CM_AUTO_PTR<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(mfd.get()));
- lgd->ClearDependencies(mfd.get(), verbose);
+ cmMakefile mfd(ggd.get(), cm.GetCurrentSnapshot());
+ std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mfd));
+ lgd->ClearDependencies(&mfd, 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")) {
+ 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))) {
+ for (std::string const& p : products) {
+ if (!(cmSystemTools::FileExists(p) || cmSystemTools::FileIsSymlink(p))) {
if (verbose) {
std::ostringstream msg;
- msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ msg << "Re-run cmake, missing byproduct: " << p << "\n";
+ cmSystemTools::Stdout(msg.str());
}
return 1;
}
@@ -1951,8 +2208,8 @@ int cmake::CheckBuildSystem()
// 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");
+ 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);
@@ -1963,7 +2220,7 @@ int cmake::CheckBuildSystem()
std::ostringstream msg;
msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
"or CMAKE_MAKEFILE_OUTPUTS :\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
return 1;
}
@@ -1973,8 +2230,7 @@ int cmake::CheckBuildSystem()
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 (this->FileTimeCache->Compare(dep_newest, *dep, &result)) {
if (result < 0) {
dep_newest = *dep;
}
@@ -1982,7 +2238,7 @@ int cmake::CheckBuildSystem()
if (verbose) {
std::ostringstream msg;
msg << "Re-run cmake: build system dependency is missing\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
return 1;
}
@@ -1993,8 +2249,7 @@ int cmake::CheckBuildSystem()
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 (this->FileTimeCache->Compare(out_oldest, *out, &result)) {
if (result > 0) {
out_oldest = *out;
}
@@ -2002,7 +2257,7 @@ int cmake::CheckBuildSystem()
if (verbose) {
std::ostringstream msg;
msg << "Re-run cmake: build system output is missing\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
return 1;
}
@@ -2011,14 +2266,13 @@ int cmake::CheckBuildSystem()
// 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) ||
+ if (!this->FileTimeCache->Compare(out_oldest, dep_newest, &result) ||
result < 0) {
if (verbose) {
std::ostringstream msg;
msg << "Re-run cmake file: " << out_oldest
<< " older than: " << dep_newest << "\n";
- cmSystemTools::Stdout(msg.str().c_str());
+ cmSystemTools::Stdout(msg.str());
}
return 1;
}
@@ -2051,7 +2305,7 @@ void cmake::TruncateOutputLog(const char* fname)
inline std::string removeQuotes(const std::string& s)
{
- if (s[0] == '\"' && s[s.size() - 1] == '\"') {
+ if (s.front() == '\"' && s.back() == '\"') {
return s.substr(1, s.size() - 2);
}
return s;
@@ -2062,22 +2316,20 @@ void cmake::MarkCliAsUsed(const std::string& variable)
this->UsedCliVariables[variable] = true;
}
-void cmake::GenerateGraphViz(const char* fileName) const
+void cmake::GenerateGraphViz(const std::string& fileName) const
{
#ifdef CMAKE_BUILD_WITH_CMAKE
- CM_AUTO_PTR<cmGraphVizWriter> gvWriter(
- new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
+ cmGraphVizWriter gvWriter(this->GetGlobalGenerator());
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);
+ gvWriter.ReadSettings(settingsFile, fallbackSettingsFile);
+ gvWriter.WritePerTargetFiles(fileName);
+ gvWriter.WriteTargetDependersFiles(fileName);
+ gvWriter.WriteGlobalFile(fileName);
#endif
}
@@ -2127,7 +2379,7 @@ cmInstalledFile const* cmake::GetInstalledFile(const std::string& name) const
cmInstalledFile const& file = i->second;
return &file;
}
- return CM_NULLPTR;
+ return nullptr;
}
int cmake::GetSystemInformation(std::vector<std::string>& args)
@@ -2137,7 +2389,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
std::string destPath = cwd + "/__cmake_systeminformation";
cmSystemTools::RemoveADirectory(destPath);
- if (!cmSystemTools::MakeDirectory(destPath.c_str())) {
+ if (!cmSystemTools::MakeDirectory(destPath)) {
std::cerr << "Error: --system-information must be run from a "
"writable directory!\n";
return 1;
@@ -2160,8 +2412,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
}
cmGlobalGenerator* gen = this->CreateGlobalGenerator(value);
if (!gen) {
- cmSystemTools::Error("Could not create named generator ",
- value.c_str());
+ cmSystemTools::Error("Could not create named generator " + value);
this->PrintGeneratorList();
} else {
this->SetGlobalGenerator(gen);
@@ -2169,7 +2420,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
}
// no option assume it is the output file
else {
- if (!cmSystemTools::FileIsFullPath(arg.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(arg)) {
resultFile = cwd;
resultFile += "/";
}
@@ -2188,7 +2439,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
outFile += "/CMakeLists.txt";
// Copy file
- if (!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str())) {
+ if (!cmsys::SystemTools::CopyFileAlways(inFile, outFile)) {
std::cerr << "Error copying file \"" << inFile << "\" to \"" << outFile
<< "\".\n";
return 1;
@@ -2203,12 +2454,19 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
{
// now run cmake on the CMakeLists file
cmWorkingDirectory workdir(destPath);
+ if (workdir.Failed()) {
+ // We created the directory and we were able to copy the CMakeLists.txt
+ // file to it, so we wouldn't expect to get here unless the default
+ // permissions are questionable or some other process has deleted the
+ // directory
+ std::cerr << "Failed to change to directory " << destPath << " : "
+ << std::strerror(workdir.GetLastResult()) << std::endl;
+ return 1;
+ }
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);
+ args2.push_back("-DRESULT_FILE=" + resultFile);
int res = this->Run(args2, false);
if (res != 0) {
@@ -2239,7 +2497,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
return 0;
}
-static bool cmakeCheckStampFile(const char* stampName, bool verbose)
+static bool cmakeCheckStampFile(const std::string& stampName)
{
// The stamp file does not exist. Use the stamp dependencies to
// determine whether it is really out of date. This works in
@@ -2262,21 +2520,22 @@ static bool cmakeCheckStampFile(const char* stampName, bool verbose)
}
// Compare the stamp dependencies against the dependency file itself.
- cmFileTimeComparison ftc;
- std::string dep;
- while (cmSystemTools::GetLineFromStream(fin, dep)) {
- int result;
- if (!dep.empty() && 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;
+ {
+ cmFileTimeCache ftc;
+ std::string dep;
+ while (cmSystemTools::GetLineFromStream(fin, dep)) {
+ int result;
+ if (!dep.empty() && dep[0] != '#' &&
+ (!ftc.Compare(stampDepends, dep, &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;
+ }
}
}
@@ -2284,30 +2543,23 @@ static bool cmakeCheckStampFile(const char* stampName, bool verbose)
// by the VS IDE due to a "rebuild" request. Restore it atomically.
std::ostringstream stampTempStream;
stampTempStream << stampName << ".tmp" << cmSystemTools::RandomSeed();
- std::string stampTempString = stampTempStream.str();
- const char* stampTemp = stampTempString.c_str();
+ std::string stampTemp = stampTempStream.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);
+ cmsys::ofstream stamp(stampTemp.c_str());
stamp << "# CMake generation timestamp file for this directory.\n";
}
if (cmSystemTools::RenameFile(stampTemp, stampName)) {
- if (verbose) {
- // 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";
- }
+ // CMake does not need to re-run because the stamp file is up-to-date.
return true;
}
cmSystemTools::RemoveFile(stampTemp);
- cmSystemTools::Error("Cannot restore timestamp ", stampName);
+ cmSystemTools::Error("Cannot restore timestamp " + stampName);
return false;
}
-static bool cmakeCheckStampList(const char* stampList, bool verbose)
+static bool cmakeCheckStampList(const std::string& stampList)
{
// If the stamp list does not exist CMake must rerun to generate it.
if (!cmSystemTools::FileExists(stampList)) {
@@ -2315,7 +2567,7 @@ static bool cmakeCheckStampList(const char* stampList, bool verbose)
<< "is missing.\n";
return false;
}
- cmsys::ifstream fin(stampList);
+ cmsys::ifstream fin(stampList.c_str());
if (!fin) {
std::cout << "CMake is re-running because generate.stamp.list "
<< "could not be read.\n";
@@ -2325,14 +2577,14 @@ static bool cmakeCheckStampList(const char* stampList, bool verbose)
// Check each stamp.
std::string stampName;
while (cmSystemTools::GetLineFromStream(fin, stampName)) {
- if (!cmakeCheckStampFile(stampName.c_str(), verbose)) {
+ if (!cmakeCheckStampFile(stampName)) {
return false;
}
}
return true;
}
-void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
+void cmake::IssueMessage(MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace) const
{
this->Messenger->IssueMessage(t, text, backtrace);
@@ -2350,7 +2602,7 @@ std::vector<std::string> cmake::GetDebugConfigs()
}
// If no configurations were specified, use a default list.
if (configs.empty()) {
- configs.push_back("DEBUG");
+ configs.emplace_back("DEBUG");
}
return configs;
}
@@ -2360,9 +2612,11 @@ cmMessenger* cmake::GetMessenger() const
return this->Messenger;
}
-int cmake::Build(const std::string& dir, const std::string& target,
+int cmake::Build(int jobs, const std::string& dir,
+ const std::vector<std::string>& targets,
const std::string& config,
- const std::vector<std::string>& nativeOptions, bool clean)
+ const std::vector<std::string>& nativeOptions, bool clean,
+ bool verbose)
{
this->SetHomeDirectory("");
@@ -2383,13 +2637,29 @@ int cmake::Build(const std::string& dir, const std::string& target,
std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
return 1;
}
- CM_AUTO_PTR<cmGlobalGenerator> gen(
- this->CreateGlobalGenerator(cachedGenerator));
- if (!gen.get()) {
+ cmGlobalGenerator* gen = this->CreateGlobalGenerator(cachedGenerator);
+ if (!gen) {
std::cerr << "Error: could create CMAKE_GENERATOR \"" << cachedGenerator
<< "\"\n";
return 1;
}
+ this->SetGlobalGenerator(gen);
+ const char* cachedGeneratorInstance =
+ this->State->GetCacheEntryValue("CMAKE_GENERATOR_INSTANCE");
+ if (cachedGeneratorInstance) {
+ cmMakefile mf(gen, this->GetCurrentSnapshot());
+ if (!gen->SetGeneratorInstance(cachedGeneratorInstance, &mf)) {
+ return 1;
+ }
+ }
+ const char* cachedGeneratorPlatform =
+ this->State->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM");
+ if (cachedGeneratorPlatform) {
+ cmMakefile mf(gen, this->GetCurrentSnapshot());
+ if (!gen->SetGeneratorPlatform(cachedGeneratorPlatform, &mf)) {
+ return 1;
+ }
+ }
std::string output;
std::string projName;
const char* cachedProjectName =
@@ -2399,11 +2669,11 @@ int cmake::Build(const std::string& dir, const std::string& target,
return 1;
}
projName = cachedProjectName;
- bool verbose = false;
+
const char* cachedVerbose =
this->State->GetCacheEntryValue("CMAKE_VERBOSE_MAKEFILE");
- if (cachedVerbose) {
- verbose = cmSystemTools::IsOn(cachedVerbose);
+ if (cmSystemTools::IsOn(cachedVerbose)) {
+ verbose = true;
}
#ifdef CMAKE_HAVE_VS_GENERATORS
@@ -2411,48 +2681,103 @@ int cmake::Build(const std::string& dir, const std::string& target,
// actually starting the build. If not done separately from the build
// itself, there is the risk of building an out-of-date solution file due
// to limitations of the underlying build system.
- std::string const stampList = cachePath + "/" +
- GetCMakeFilesDirectoryPostSlash() +
- cmGlobalVisualStudio8Generator::GetGenerateStampList();
+ std::string const stampList = cachePath + "/" + "CMakeFiles/" +
+ cmGlobalVisualStudio9Generator::GetGenerateStampList();
// Note that the stampList file only exists for VS generators.
- if (cmSystemTools::FileExists(stampList.c_str()) &&
- !cmakeCheckStampList(stampList.c_str(), false)) {
-
- // Correctly initialize the home (=source) and home output (=binary)
- // directories, which is required for running the generation step.
- std::string homeOrig = this->GetHomeDirectory();
- std::string homeOutputOrig = this->GetHomeOutputDirectory();
- this->SetDirectoriesFromFile(cachePath.c_str());
+ if (cmSystemTools::FileExists(stampList)) {
+ // Check if running for Visual Studio 9 - we need to explicitly run
+ // the glob verification script before starting the build
this->AddScriptingCommands();
- this->AddProjectCommands();
-
- int ret = this->Configure();
- if (ret) {
- cmSystemTools::Message("CMake Configure step failed. "
- "Build files cannot be regenerated correctly.");
- return ret;
- }
- ret = this->Generate();
- if (ret) {
- cmSystemTools::Message("CMake Generate step failed. "
- "Build files cannot be regenerated correctly.");
- return ret;
+ if (this->GlobalGenerator->MatchesGeneratorName("Visual Studio 9 2008")) {
+ std::string const globVerifyScript =
+ cachePath + "/" + "CMakeFiles/" + "VerifyGlobs.cmake";
+ if (cmSystemTools::FileExists(globVerifyScript)) {
+ std::vector<std::string> args;
+ this->ReadListFile(args, globVerifyScript);
+ }
}
- std::string message = "Build files have been written to: ";
- message += this->GetHomeOutputDirectory();
- this->UpdateProgress(message.c_str(), -1);
- // Restore the previously set directories to their original value.
- this->SetHomeDirectory(homeOrig);
- this->SetHomeOutputDirectory(homeOutputOrig);
+ if (!cmakeCheckStampList(stampList)) {
+ // Correctly initialize the home (=source) and home output (=binary)
+ // directories, which is required for running the generation step.
+ std::string homeOrig = this->GetHomeDirectory();
+ std::string homeOutputOrig = this->GetHomeOutputDirectory();
+ this->SetDirectoriesFromFile(cachePath);
+
+ this->AddProjectCommands();
+
+ int ret = this->Configure();
+ if (ret) {
+ cmSystemTools::Message("CMake Configure step failed. "
+ "Build files cannot be regenerated correctly.");
+ return ret;
+ }
+ ret = this->Generate();
+ if (ret) {
+ cmSystemTools::Message("CMake Generate step failed. "
+ "Build files cannot be regenerated correctly.");
+ return ret;
+ }
+ std::string message = "Build files have been written to: ";
+ message += this->GetHomeOutputDirectory();
+ this->UpdateProgress(message, -1);
+
+ // Restore the previously set directories to their original value.
+ this->SetHomeDirectory(homeOrig);
+ this->SetHomeOutputDirectory(homeOutputOrig);
+ }
}
#endif
- return gen->Build("", dir, projName, target, output, "", config, clean,
- false, verbose, 0, cmSystemTools::OUTPUT_PASSTHROUGH,
- nativeOptions);
+ gen->PrintBuildCommandAdvice(std::cerr, jobs);
+ return gen->Build(jobs, "", dir, projName, targets, output, "", config,
+ clean, false, verbose, cmDuration::zero(),
+ cmSystemTools::OUTPUT_PASSTHROUGH, nativeOptions);
+}
+
+bool cmake::Open(const std::string& dir, bool dryRun)
+{
+ this->SetHomeDirectory("");
+ this->SetHomeOutputDirectory("");
+ if (!cmSystemTools::FileIsDirectory(dir)) {
+ std::cerr << "Error: " << dir << " is not a directory\n";
+ return false;
+ }
+
+ std::string cachePath = FindCacheFile(dir);
+ if (!this->LoadCache(cachePath)) {
+ std::cerr << "Error: could not load cache\n";
+ return false;
+ }
+ const char* genName = this->State->GetCacheEntryValue("CMAKE_GENERATOR");
+ if (!genName) {
+ std::cerr << "Error: could not find CMAKE_GENERATOR in Cache\n";
+ return false;
+ }
+ const std::string* extraGenName =
+ this->State->GetInitializedCacheValue("CMAKE_EXTRA_GENERATOR");
+ std::string fullName =
+ cmExternalMakefileProjectGenerator::CreateFullGeneratorName(
+ genName, extraGenName ? *extraGenName : "");
+
+ std::unique_ptr<cmGlobalGenerator> gen(
+ this->CreateGlobalGenerator(fullName));
+ if (!gen) {
+ std::cerr << "Error: could create CMAKE_GENERATOR \"" << fullName
+ << "\"\n";
+ return false;
+ }
+
+ const char* cachedProjectName =
+ this->State->GetCacheEntryValue("CMAKE_PROJECT_NAME");
+ if (!cachedProjectName) {
+ std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
+ return false;
+ }
+
+ return gen->Open(dir, cachedProjectName, dryRun);
}
void cmake::WatchUnusedCli(const std::string& var)
@@ -2479,16 +2804,14 @@ void cmake::RunCheckForUnusedVariables()
bool haveUnused = false;
std::ostringstream 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) {
+ for (auto const& it : this->UsedCliVariables) {
+ if (!it.second) {
haveUnused = true;
- msg << "\n " << it->first;
+ msg << "\n " << it.first;
}
}
if (haveUnused) {
- this->IssueMessage(cmake::WARNING, msg.str());
+ this->IssueMessage(MessageType::WARNING, msg.str());
}
#endif
}
diff --git a/Source/cmake.h b/Source/cmake.h
index 4ddacf701..fa4409aeb 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -3,29 +3,34 @@
#ifndef cmake_h
#define cmake_h
-#include "cmConfigure.h"
+#include "cmConfigure.h" // IWYU pragma: keep
+#include <functional>
#include <map>
+#include <memory> // IWYU pragma: keep
#include <set>
#include <string>
+#include <unordered_set>
#include <vector>
#include "cmInstalledFile.h"
#include "cmListFileCache.h"
+#include "cmMessageType.h"
+#include "cmState.h"
#include "cmStateSnapshot.h"
#include "cmStateTypes.h"
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cm_jsoncpp_value.h"
+# include "cm_jsoncpp_value.h"
#endif
class cmExternalMakefileProjectGeneratorFactory;
-class cmFileTimeComparison;
+class cmFileAPI;
+class cmFileTimeCache;
class cmGlobalGenerator;
class cmGlobalGeneratorFactory;
class cmMakefile;
class cmMessenger;
-class cmState;
class cmVariableWatch;
struct cmDocumentationEntry;
@@ -55,8 +60,6 @@ struct cmDocumentationEntry;
class cmake
{
- CM_DISABLE_COPY(cmake)
-
public:
enum Role
{
@@ -65,19 +68,6 @@ public:
RoleProject // all commands
};
- enum MessageType
- {
- AUTHOR_WARNING,
- AUTHOR_ERROR,
- FATAL_ERROR,
- INTERNAL_ERROR,
- MESSAGE,
- WARNING,
- LOG,
- DEPRECATION_ERROR,
- DEPRECATION_WARNING
- };
-
enum DiagLevel
{
DIAG_IGNORE,
@@ -106,6 +96,19 @@ public:
FIND_PACKAGE_MODE
};
+ /** \brief Define log level constants. */
+ enum LogLevel
+ {
+ LOG_UNDEFINED,
+ LOG_ERROR,
+ LOG_WARNING,
+ LOG_NOTICE,
+ LOG_STATUS,
+ LOG_VERBOSE,
+ LOG_DEBUG,
+ LOG_TRACE
+ };
+
struct GeneratorInfo
{
std::string name;
@@ -113,26 +116,29 @@ public:
std::string extraName;
bool supportsToolset;
bool supportsPlatform;
+ std::vector<std::string> supportedPlatforms;
+ std::string defaultPlatform;
bool isAlias;
};
typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
+ static const int NO_BUILD_PARALLEL_LEVEL = -1;
+ static const int DEFAULT_BUILD_PARALLEL_LEVEL = 0;
+
/// Default constructor
- cmake(Role role);
+ cmake(Role role, cmState::Mode mode);
/// Destructor
~cmake();
+ cmake(cmake const&) = delete;
+ cmake& operator=(cmake const&) = delete;
+
#if defined(CMAKE_BUILD_WITH_CMAKE)
- Json::Value ReportCapabilitiesJson(bool haveServerMode) const;
+ Json::Value ReportVersionJson() const;
+ Json::Value ReportCapabilitiesJson() const;
#endif
- std::string ReportCapabilities(bool haveServerMode) const;
-
- static const char* GetCMakeFilesDirectory() { return "/CMakeFiles"; }
- static const char* GetCMakeFilesDirectoryPostSlash()
- {
- return "CMakeFiles/";
- }
+ std::string ReportCapabilities() const;
//@{
/**
@@ -141,9 +147,9 @@ public:
* path-to-source cmake was run with.
*/
void SetHomeDirectory(const std::string& dir);
- const char* GetHomeDirectory() const;
+ std::string const& GetHomeDirectory() const;
void SetHomeOutputDirectory(const std::string& dir);
- const char* GetHomeOutputDirectory() const;
+ std::string const& GetHomeOutputDirectory() const;
//@}
/**
@@ -169,7 +175,7 @@ public:
int Configure();
int ActualConfigure();
- ///! Break up a line like VAR:type="value" into var, type and value
+ //! Break up a line like VAR:type="value" into var, type and value
static bool ParseCacheEntry(const std::string& entry, std::string& var,
std::string& value,
cmStateEnums::CacheEntryType& type);
@@ -183,84 +189,110 @@ public:
bool DeleteCache(const std::string& path);
void PreLoadCMakeFiles();
- ///! Create a GlobalGenerator
+ //! Create a GlobalGenerator
cmGlobalGenerator* CreateGlobalGenerator(const std::string& name);
- ///! Return the global generator assigned to this instance of cmake
+ //! 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
+ //! Return the global generator assigned to this instance of cmake, const
const cmGlobalGenerator* GetGlobalGenerator() const
{
return this->GlobalGenerator;
}
- ///! Return the full path to where the CMakeCache.txt file should be.
+ //! Return the full path to where the CMakeCache.txt file should be.
static std::string FindCacheFile(const std::string& binaryDir);
- ///! Return the global generator assigned to this instance of cmake
+ //! 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<GeneratorInfo>& generators) const;
+ //! Get the names of the current registered generators
+ void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
+ bool includeNamesWithPlatform = true) const;
- ///! Set the name of the selected generator-specific platform.
- void SetGeneratorPlatform(std::string const& ts)
+ //! Set the name of the selected generator-specific instance.
+ void SetGeneratorInstance(std::string const& instance)
{
- this->GeneratorPlatform = ts;
+ this->GeneratorInstance = instance;
+ this->GeneratorInstanceSet = true;
}
- ///! Get the name of the selected generator-specific platform.
- std::string const& GetGeneratorPlatform() const
+ //! Set the name of the selected generator-specific platform.
+ void SetGeneratorPlatform(std::string const& ts)
{
- return this->GeneratorPlatform;
+ this->GeneratorPlatform = ts;
+ this->GeneratorPlatformSet = true;
}
- ///! Set the name of the selected generator-specific toolset.
+ //! Set the name of the selected generator-specific toolset.
void SetGeneratorToolset(std::string const& ts)
{
this->GeneratorToolset = ts;
+ this->GeneratorToolsetSet = true;
}
- ///! Get the name of the selected generator-specific toolset.
- std::string const& GetGeneratorToolset() const
+ const std::vector<std::string>& GetSourceExtensions() const
{
- return this->GeneratorToolset;
+ return this->SourceFileExtensions;
}
- const std::vector<std::string>& GetSourceExtensions() const
+ bool IsSourceExtension(const std::string& ext) const
{
- return this->SourceFileExtensions;
+ return this->SourceFileExtensionsSet.find(ext) !=
+ this->SourceFileExtensionsSet.end();
}
+
const std::vector<std::string>& GetHeaderExtensions() const
{
return this->HeaderFileExtensions;
}
+ bool IsHeaderExtension(const std::string& ext) const
+ {
+ return this->HeaderFileExtensionsSet.find(ext) !=
+ this->HeaderFileExtensionsSet.end();
+ }
+
+ // Strips the extension (if present and known) from a filename
+ std::string StripExtension(const std::string& file) const;
+
/**
* Given a variable name, return its value (as a string).
*/
const char* GetCacheDefinition(const std::string&) const;
- ///! Add an entry into the cache
+ //! Add an entry into the cache
void AddCacheEntry(const std::string& key, const char* value,
const char* helpString, int type);
+ bool DoWriteGlobVerifyTarget() const;
+ std::string const& GetGlobVerifyScript() const;
+ std::string const& GetGlobVerifyStamp() const;
+ void AddGlobCacheEntry(bool recurse, bool listDirectories,
+ bool followSymlinks, const std::string& relative,
+ const std::string& expression,
+ const std::vector<std::string>& files,
+ const std::string& variable,
+ cmListFileBacktrace const& bt);
+
/**
* Get the system information and write it to the file specified
*/
int GetSystemInformation(std::vector<std::string>&);
- ///! Parse command line arguments
- void SetArgs(const std::vector<std::string>&,
- bool directoriesSetBefore = false);
+ //! Parse environment variables
+ void LoadEnvironmentPresets();
+
+ //! Parse command line arguments
+ void SetArgs(const std::vector<std::string>& args);
- ///! Is this cmake running as a result of a TRY_COMPILE command
+ //! Is this cmake running as a result of a TRY_COMPILE command
bool GetIsInTryCompile() const;
void SetIsInTryCompile(bool b);
- ///! Parse command line arguments that might set cache values
+ //! 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*);
+ using ProgressCallbackType = std::function<void(const std::string&, float)>;
/**
* Set the function used by GUIs to receive progress updates
* Function gets passed: message as a const char*, a progress
@@ -268,25 +300,26 @@ public:
* number provided may be negative in cases where a message is
* to be displayed without any progress percentage.
*/
- void SetProgressCallback(ProgressCallbackType f,
- void* clientData = CM_NULLPTR);
+ void SetProgressCallback(ProgressCallbackType f);
- ///! this is called by generators to update the progress
- void UpdateProgress(const char* msg, float prog);
+ //! this is called by generators to update the progress
+ void UpdateProgress(const std::string& msg, float prog);
- ///! Get the variable watch object
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ //! Get the variable watch object
cmVariableWatch* GetVariableWatch() { return this->VariableWatch; }
+#endif
- void GetGeneratorDocumentation(std::vector<cmDocumentationEntry>&);
+ std::vector<cmDocumentationEntry> GetGeneratorsDocumentation();
- ///! Set/Get a property of this target file
+ //! 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);
bool GetPropertyAsBool(const std::string& prop);
- ///! Get or create an cmInstalledFile instance and return a pointer to it
+ //! Get or create an cmInstalledFile instance and return a pointer to it
cmInstalledFile* GetOrCreateInstalledFile(cmMakefile* mf,
const std::string& name);
@@ -297,13 +330,13 @@ public:
return this->InstalledFiles;
}
- ///! Do all the checks before running configure
+ //! 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
+ //! Debug the try compile stuff by not deleting the files
bool GetDebugTryCompile() { return this->DebugTryCompile; }
void DebugTryCompileOn() { this->DebugTryCompile = true; }
@@ -315,7 +348,12 @@ public:
/**
* Get the file comparison class
*/
- cmFileTimeComparison* GetFileComparison() { return this->FileComparison; }
+ cmFileTimeCache* GetFileTimeCache() { return this->FileTimeCache; }
+
+ // Get the selected log level for `message()` commands during the cmake run.
+ LogLevel GetLogLevel() const { return this->MessageLogLevel; }
+ void SetLogLevel(LogLevel level) { this->MessageLogLevel = level; }
+ static LogLevel StringToLogLevel(const std::string& levelStr);
// Do we want debug output during the cmake run.
bool GetDebugOutput() { return this->DebugOutput; }
@@ -406,13 +444,17 @@ public:
/** Display a message to the user. */
void IssueMessage(
- cmake::MessageType t, std::string const& text,
+ MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace = cmListFileBacktrace()) const;
- ///! 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);
+ //! run the --build option
+ int Build(int jobs, const std::string& dir,
+ const std::vector<std::string>& targets, const std::string& config,
+ const std::vector<std::string>& nativeOptions, bool clean,
+ bool verbose);
+
+ //! run the --open option
+ bool Open(const std::string& dir, bool dryRun);
void UnwatchUnusedCli(const std::string& var);
void WatchUnusedCli(const std::string& var);
@@ -426,7 +468,6 @@ public:
protected:
void RunCheckForUnusedVariables();
- void InitializeProperties();
int HandleDeleteCacheVariables(const std::string& var);
typedef std::vector<cmGlobalGeneratorFactory*> RegisteredGeneratorsVector;
@@ -441,14 +482,19 @@ protected:
cmGlobalGenerator* GlobalGenerator;
std::map<std::string, DiagLevel> DiagLevels;
+ std::string GeneratorInstance;
std::string GeneratorPlatform;
std::string GeneratorToolset;
+ bool GeneratorInstanceSet;
+ bool GeneratorPlatformSet;
+ bool GeneratorToolsetSet;
- ///! read in a cmake list file to initialize the cache
- void ReadListFile(const std::vector<std::string>& args, const char* path);
+ //! read in a cmake list file to initialize the cache
+ void ReadListFile(const std::vector<std::string>& args,
+ const std::string& path);
bool FindPackage(const std::vector<std::string>& args);
- ///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
+ //! 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);
@@ -458,20 +504,16 @@ protected:
*/
int CheckBuildSystem();
- void SetDirectoriesFromFile(const char* arg);
+ void SetDirectoriesFromFile(const std::string& 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;
+ void GenerateGraphViz(const std::string& fileName) const;
private:
ProgressCallbackType ProgressCallback;
- void* ProgressCallbackClientData;
- bool InTryCompile;
WorkingMode CurrentWorkingMode;
bool DebugOutput;
bool Trace;
@@ -488,43 +530,47 @@ private:
std::string CheckStampFile;
std::string CheckStampList;
std::string VSSolutionFile;
+ std::string EnvironmentGenerator;
std::vector<std::string> SourceFileExtensions;
+ std::unordered_set<std::string> SourceFileExtensionsSet;
std::vector<std::string> HeaderFileExtensions;
+ std::unordered_set<std::string> HeaderFileExtensionsSet;
bool ClearBuildSystem;
bool DebugTryCompile;
- cmFileTimeComparison* FileComparison;
+ cmFileTimeCache* FileTimeCache;
std::string GraphVizFile;
InstalledFilesMap InstalledFiles;
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ cmVariableWatch* VariableWatch;
+ std::unique_ptr<cmFileAPI> FileAPI;
+#endif
+
cmState* State;
cmStateSnapshot CurrentSnapshot;
cmMessenger* Messenger;
std::vector<std::string> TraceOnlyThisSources;
+ LogLevel MessageLogLevel = LogLevel::LOG_STATUS;
+
void UpdateConversionPathTable();
// Print a list of valid generators to stderr.
void PrintGeneratorList();
+ std::unique_ptr<cmGlobalGenerator> EvaluateDefaultGlobalGenerator();
void CreateDefaultGlobalGenerator();
- /**
- * Convert a message type between a warning and an error, based on the state
- * of the error output CMake variables, in the cache.
- */
- cmake::MessageType ConvertMessageType(cmake::MessageType t) const;
-
- /*
- * Check if messages of this type should be output, based on the state of the
- * warning and error output CMake variables, in the cache.
- */
- bool IsMessageTypeVisible(cmake::MessageType t) const;
+ void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
+ void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&);
};
#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." }, \
+ { "-S <path-to-source>", "Explicitly specify a source directory." }, \
+ { "-B <path-to-build>", "Explicitly specify a build directory." }, \
+ { "-C <initial-cache>", "Pre-load a script to populate the cache." }, \
+ { "-D <var>[:<type>]=<value>", "Create or update a cmake cache entry." }, \
{ "-U <globbing_expr>", "Remove matching entries from CMake cache." }, \
{ "-G <generator-name>", "Specify a build system generator." }, \
{ "-T <toolset-name>", \
@@ -537,46 +583,47 @@ private:
{ "-Wno-error=dev", "Make developer warnings not errors." }, \
{ "-Wdeprecated", "Enable deprecation warnings." }, \
{ "-Wno-deprecated", "Suppress deprecation warnings." }, \
- { "-Werror=deprecated", "Make deprecated macro and function warnings " \
- "errors." }, \
+ { "-Werror=deprecated", \
+ "Make deprecated macro and function warnings " \
+ "errors." }, \
{ \
- "-Wno-error=deprecated", "Make deprecated macro and function warnings " \
- "not errors." \
+ "-Wno-error=deprecated", \
+ "Make deprecated macro and function warnings " \
+ "not errors." \
}
+#define FOR_EACH_C90_FEATURE(F) F(c_function_prototypes)
+
+#define FOR_EACH_C99_FEATURE(F) \
+ F(c_restrict) \
+ F(c_variadic_macros)
+
+#define FOR_EACH_C11_FEATURE(F) F(c_static_assert)
+
#define FOR_EACH_C_FEATURE(F) \
F(c_std_90) \
F(c_std_99) \
F(c_std_11) \
- F(c_function_prototypes) \
- F(c_restrict) \
- F(c_static_assert) \
- F(c_variadic_macros)
+ FOR_EACH_C90_FEATURE(F) \
+ FOR_EACH_C99_FEATURE(F) \
+ FOR_EACH_C11_FEATURE(F)
-#define FOR_EACH_CXX_FEATURE(F) \
- F(cxx_std_98) \
- F(cxx_std_11) \
- F(cxx_std_14) \
- F(cxx_std_17) \
- F(cxx_aggregate_default_initializers) \
+#define FOR_EACH_CXX98_FEATURE(F) F(cxx_template_template_parameters)
+
+#define FOR_EACH_CXX11_FEATURE(F) \
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) \
@@ -584,11 +631,9 @@ private:
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) \
@@ -598,22 +643,41 @@ private:
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)
+#define FOR_EACH_CXX14_FEATURE(F) \
+ F(cxx_aggregate_default_initializers) \
+ F(cxx_attribute_deprecated) \
+ F(cxx_binary_literals) \
+ F(cxx_contextual_conversions) \
+ F(cxx_decltype_auto) \
+ F(cxx_digit_separators) \
+ F(cxx_generic_lambdas) \
+ F(cxx_lambda_init_captures) \
+ F(cxx_relaxed_constexpr) \
+ F(cxx_return_type_deduction) \
+ F(cxx_variable_templates)
+
+#define FOR_EACH_CXX_FEATURE(F) \
+ F(cxx_std_98) \
+ F(cxx_std_11) \
+ F(cxx_std_14) \
+ F(cxx_std_17) \
+ F(cxx_std_20) \
+ FOR_EACH_CXX98_FEATURE(F) \
+ FOR_EACH_CXX11_FEATURE(F) \
+ FOR_EACH_CXX14_FEATURE(F)
+
#endif
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index da1fe6d64..a6348b39e 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -1,9 +1,8 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
-#include "cmConfigure.h"
#include "cmAlgorithms.h"
-#include "cmDocumentationEntry.h"
+#include "cmDocumentationEntry.h" // IWYU pragma: keep
#include "cmGlobalGenerator.h"
#include "cmMakefile.h"
#include "cmState.h"
@@ -13,71 +12,95 @@
#include "cmcmd.h"
#ifdef CMAKE_BUILD_WITH_CMAKE
-#include "cmDocumentation.h"
-#include "cmDynamicLoader.h"
+# include "cmDocumentation.h"
+# include "cmDynamicLoader.h"
#endif
+#include "cm_uv.h"
+
#include "cmsys/Encoding.hxx"
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmsys/ConsoleBuf.hxx"
+# include "cmsys/ConsoleBuf.hxx"
#endif
+
+#include <cassert>
+#include <climits>
+#include <ctype.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
-#ifdef CMAKE_USE_LIBUV
-#ifdef _WIN32
-#include <fcntl.h> /* _O_TEXT */
-#include <stdlib.h> /* _set_fmode, _fmode */
-#endif
-#include "cm_uv.h"
-#endif
-
#ifdef CMAKE_BUILD_WITH_CMAKE
static const char* cmDocumentationName[][2] = {
- { CM_NULLPTR, " cmake - Cross-Platform Makefile Generator." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, " cmake - Cross-Platform Makefile Generator." },
+ { nullptr, nullptr }
};
static const char* cmDocumentationUsage[][2] = {
- { CM_NULLPTR, " cmake [options] <path-to-source>\n"
- " cmake [options] <path-to-existing-build>" },
- { CM_NULLPTR,
+ { nullptr,
+ " cmake [options] <path-to-source>\n"
+ " cmake [options] <path-to-existing-build>\n"
+ " cmake [options] -S <path-to-source> -B <path-to-build>" },
+ { nullptr,
"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." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, nullptr }
};
static const char* cmDocumentationUsageNote[][2] = {
- { CM_NULLPTR, "Run 'cmake --help' for more information." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, "Run 'cmake --help' for more information." },
+ { nullptr, nullptr }
};
-#define CMAKE_BUILD_OPTIONS \
- " <dir> = Project binary directory to be built.\n" \
- " --target <tgt> = Build <tgt> instead of default targets.\n" \
- " May only be specified once.\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"
+# define CMAKE_BUILD_OPTIONS \
+ " <dir> = Project binary directory to be built.\n" \
+ " --parallel [<jobs>], -j [<jobs>]\n" \
+ " = Build in parallel using the given number of jobs. \n" \
+ " If <jobs> is omitted the native build tool's \n" \
+ " default number is used.\n" \
+ " The CMAKE_BUILD_PARALLEL_LEVEL environment " \
+ "variable\n" \
+ " specifies a default parallel level when this " \
+ "option\n" \
+ " is not given.\n" \
+ " --target <tgt>..., -t <tgt>... \n" \
+ " = 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" \
+ " --verbose, -v = Enable verbose output - if supported - including\n" \
+ " the build commands to be executed. \n" \
+ " -- = Pass remaining options to the native tool.\n"
+
+# define CMAKE_INSTALL_OPTIONS \
+ " <dir> = Project binary directory to install.\n" \
+ " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \
+ " --component <comp> = Component-based install. Only install <comp>.\n" \
+ " --prefix <prefix> = The installation prefix CMAKE_INSTALL_PREFIX.\n" \
+ " --strip = Performing install/strip.\n" \
+ " -v --verbose = Enable verbose output.\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." },
+ { "--install <dir>", "Install a CMake-generated project binary tree." },
+ { "--open <dir>", "Open generated project in the associated application." },
{ "-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." },
+ { "--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." },
+ { "--loglevel=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>",
+ "Set the verbosity of messages from CMake files." },
+ { "--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." },
{ "--trace-expand", "Put cmake in trace mode with variable expansion." },
@@ -86,9 +109,10 @@ static const char* cmDocumentationOptions[][2] = {
{ "--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." },
- { CM_NULLPTR, CM_NULLPTR }
+ { "--check-system-vars",
+ "Find problems with variable usage in system "
+ "files." },
+ { nullptr, nullptr }
};
#endif
@@ -97,30 +121,31 @@ static int do_command(int ac, char const* const* av)
{
std::vector<std::string> args;
args.reserve(ac - 1);
- args.push_back(av[0]);
- args.insert(args.end(), av + 2, av + ac);
+ args.emplace_back(av[0]);
+ cmAppend(args, av + 2, av + ac);
return cmcmd::ExecuteCMakeCommand(args);
}
int do_cmake(int ac, char const* const* av);
static int do_build(int ac, char const* const* av);
+static int do_install(int ac, char const* const* av);
+static int do_open(int ac, char const* const* av);
-static cmMakefile* cmakemainGetMakefile(void* clientdata)
+static cmMakefile* cmakemainGetMakefile(cmake* cm)
{
- cmake* cm = (cmake*)clientdata;
if (cm && cm->GetDebugOutput()) {
cmGlobalGenerator* gg = cm->GetGlobalGenerator();
if (gg) {
return gg->GetCurrentMakefile();
}
}
- return CM_NULLPTR;
+ return nullptr;
}
-static std::string cmakemainGetStack(void* clientdata)
+static std::string cmakemainGetStack(cmake* cm)
{
std::string msg;
- cmMakefile* mf = cmakemainGetMakefile(clientdata);
+ cmMakefile* mf = cmakemainGetMakefile(cm);
if (mf) {
msg = mf->FormatListFileStack();
if (!msg.empty()) {
@@ -131,28 +156,27 @@ static std::string cmakemainGetStack(void* clientdata)
return msg;
}
-static void cmakemainMessageCallback(const char* m, const char* /*unused*/,
- bool& /*unused*/, void* clientdata)
+static void cmakemainMessageCallback(const std::string& m,
+ const char* /*unused*/, cmake* cm)
{
- std::cerr << m << cmakemainGetStack(clientdata) << std::endl << std::flush;
+ std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush;
}
-static void cmakemainProgressCallback(const char* m, float prog,
- void* clientdata)
+static void cmakemainProgressCallback(const std::string& m, float prog,
+ cmake* cm)
{
- cmMakefile* mf = cmakemainGetMakefile(clientdata);
+ cmMakefile* mf = cmakemainGetMakefile(cm);
std::string dir;
- if ((mf) && (strstr(m, "Configuring") == m) && (prog < 0)) {
+ if (mf && cmHasLiteralPrefix(m, "Configuring") && (prog < 0)) {
dir = " ";
dir += mf->GetCurrentSourceDirectory();
- } else if ((mf) && (strstr(m, "Generating") == m)) {
+ } else if (mf && cmHasLiteralPrefix(m, "Generating")) {
dir = " ";
dir += mf->GetCurrentBinaryDirectory();
}
if ((prog < 0) || (!dir.empty())) {
- std::cout << "-- " << m << dir << cmakemainGetStack(clientdata)
- << std::endl;
+ std::cout << "-- " << m << dir << cmakemainGetStack(cm) << std::endl;
}
std::cout.flush();
@@ -160,6 +184,7 @@ static void cmakemainProgressCallback(const char* m, float prog,
int main(int ac, char const* const* av)
{
+ cmSystemTools::EnsureStdPipes();
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
// Replace streambuf so we can output Unicode to console
cmsys::ConsoleBuf::Manager consoleOut(std::cout);
@@ -172,24 +197,19 @@ int main(int ac, char const* const* av)
ac = args.argc();
av = args.argv();
-#if defined(CMAKE_USE_LIBUV) && defined(_WIN32)
- // Perform libuv one-time initialization now, and then un-do its
- // global _fmode setting so that using libuv does not change the
- // default file text/binary mode. See libuv issue 840.
- uv_loop_close(uv_default_loop());
-#ifdef _MSC_VER
- _set_fmode(_O_TEXT);
-#else
- _fmode = _O_TEXT;
-#endif
-#endif
-
cmSystemTools::EnableMSVCDebugHook();
+ cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(av[0]);
if (ac > 1) {
if (strcmp(av[1], "--build") == 0) {
return do_build(ac, av);
}
+ if (strcmp(av[1], "--install") == 0) {
+ return do_install(ac, av);
+ }
+ if (strcmp(av[1], "--open") == 0) {
+ return do_open(ac, av);
+ }
if (strcmp(av[1], "-E") == 0) {
return do_command(ac, av);
}
@@ -198,9 +218,7 @@ int main(int ac, char const* const* av)
#ifdef CMAKE_BUILD_WITH_CMAKE
cmDynamicLoader::FlushCache();
#endif
-#ifdef CMAKE_USE_LIBUV
uv_loop_close(uv_default_loop());
-#endif
return ret;
}
@@ -217,7 +235,7 @@ int do_cmake(int ac, char const* const* av)
doc.addCMakeStandardDocSections();
if (doc.CheckOptions(ac, av)) {
// Construct and print requested documentation.
- cmake hcm(cmake::RoleInternal);
+ cmake hcm(cmake::RoleInternal, cmState::Unknown);
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
hcm.AddCMakePaths();
@@ -227,9 +245,7 @@ int do_cmake(int ac, char const* const* av)
std::vector<std::string> args(av, av + ac);
hcm.SetCacheArgs(args);
- std::vector<cmDocumentationEntry> generators;
-
- hcm.GetGeneratorDocumentation(generators);
+ auto generators = hcm.GetGeneratorsDocumentation();
doc.SetName("cmake");
doc.SetSection("Name", cmDocumentationName);
@@ -285,21 +301,21 @@ int do_cmake(int ac, char const* const* av)
} 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]);
+ return 1;
}
+ workingMode = cmake::SCRIPT_MODE;
+ args.emplace_back(av[i]);
+ i++;
+ args.emplace_back(av[i]);
} else if (cmHasLiteralPrefix(av[i], "--find-package")) {
workingMode = cmake::FIND_PACKAGE_MODE;
- args.push_back(av[i]);
+ args.emplace_back(av[i]);
} else {
- args.push_back(av[i]);
+ args.emplace_back(av[i]);
}
}
if (sysinfo) {
- cmake cm(cmake::RoleProject);
+ cmake cm(cmake::RoleProject, cmState::Project);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
int ret = cm.GetSystemInformation(args);
@@ -307,33 +323,48 @@ int do_cmake(int ac, char const* const* av)
}
cmake::Role const role =
workingMode == cmake::SCRIPT_MODE ? cmake::RoleScript : cmake::RoleProject;
- cmake cm(role);
+ cmState::Mode mode = cmState::Unknown;
+ switch (workingMode) {
+ case cmake::NORMAL_MODE:
+ mode = cmState::Project;
+ break;
+ case cmake::SCRIPT_MODE:
+ mode = cmState::Script;
+ break;
+ case cmake::FIND_PACKAGE_MODE:
+ mode = cmState::FindPackage;
+ break;
+ }
+ cmake cm(role, mode);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
- cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm);
- cm.SetProgressCallback(cmakemainProgressCallback, (void*)&cm);
+ cmSystemTools::SetMessageCallback(
+ [&cm](const std::string& msg, const char* title) {
+ cmakemainMessageCallback(msg, title, &cm);
+ });
+ cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
+ cmakemainProgressCallback(msg, prog, &cm);
+ });
cm.SetWorkingMode(workingMode);
int res = cm.Run(args, view_only);
if (list_cached || list_all_cached) {
std::cout << "-- Cache values" << std::endl;
std::vector<std::string> keys = cm.GetState()->GetCacheEntryKeys();
- for (std::vector<std::string>::const_iterator it = keys.begin();
- it != keys.end(); ++it) {
- cmStateEnums::CacheEntryType t = cm.GetState()->GetCacheEntryType(*it);
+ for (std::string const& k : keys) {
+ cmStateEnums::CacheEntryType t = cm.GetState()->GetCacheEntryType(k);
if (t != cmStateEnums::INTERNAL && t != cmStateEnums::STATIC &&
t != cmStateEnums::UNINITIALIZED) {
const char* advancedProp =
- cm.GetState()->GetCacheEntryProperty(*it, "ADVANCED");
+ cm.GetState()->GetCacheEntryProperty(k, "ADVANCED");
if (list_all_cached || !advancedProp) {
if (list_help) {
std::cout << "// "
- << cm.GetState()->GetCacheEntryProperty(*it,
- "HELPSTRING")
+ << cm.GetState()->GetCacheEntryProperty(k, "HELPSTRING")
<< std::endl;
}
- std::cout << *it << ":" << cmState::CacheEntryTypeToString(t) << "="
- << cm.GetState()->GetCacheEntryValue(*it) << std::endl;
+ std::cout << k << ":" << cmState::CacheEntryTypeToString(t) << "="
+ << cm.GetState()->GetCacheEntryValue(k) << std::endl;
if (list_help) {
std::cout << std::endl;
}
@@ -350,18 +381,53 @@ int do_cmake(int ac, char const* const* av)
return 0;
}
+namespace {
+int extract_job_number(int& index, char const* current, char const* next,
+ int len_of_flag)
+{
+ std::string command(current);
+ std::string jobString = command.substr(len_of_flag);
+ if (jobString.empty() && next && isdigit(next[0])) {
+ ++index; // skip parsing the job number
+ jobString = std::string(next);
+ }
+
+ int jobs = -1;
+ unsigned long numJobs = 0;
+ if (jobString.empty()) {
+ jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
+ } else if (cmSystemTools::StringToULong(jobString.c_str(), &numJobs)) {
+ if (numJobs == 0) {
+ std::cerr
+ << "The <jobs> value requires a positive integer argument.\n\n";
+ } else if (numJobs > INT_MAX) {
+ std::cerr << "The <jobs> value is too large.\n\n";
+ } else {
+ jobs = int(numJobs);
+ }
+ } else {
+ std::cerr << "'" << command.substr(0, len_of_flag) << "' invalid number '"
+ << jobString << "' given.\n\n";
+ }
+ return jobs;
+}
+}
+
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;
+ int jobs = cmake::NO_BUILD_PARALLEL_LEVEL;
+ std::vector<std::string> targets;
std::string config = "Debug";
std::string dir;
std::vector<std::string> nativeOptions;
- bool clean = false;
- bool hasTarget = false;
+ bool cleanFirst = false;
+ bool foundClean = false;
+ bool foundNonClean = false;
+ bool verbose = cmSystemTools::HasEnv("VERBOSE");
enum Doing
{
@@ -374,20 +440,32 @@ static int do_build(int ac, char const* const* av)
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) {
- if (!hasTarget) {
- doing = DoingTarget;
- hasTarget = true;
- } else {
- std::cerr << "'--target' may not be specified more than once.\n\n";
- dir = "";
- break;
+ nativeOptions.emplace_back(av[i]);
+ } else if (cmHasLiteralPrefix(av[i], "-j")) {
+ const char* nextArg = ((i + 1 < ac) ? av[i + 1] : nullptr);
+ jobs = extract_job_number(i, av[i], nextArg, sizeof("-j") - 1);
+ if (jobs < 0) {
+ dir.clear();
+ }
+ doing = DoingNone;
+ } else if (cmHasLiteralPrefix(av[i], "--parallel")) {
+ const char* nextArg = ((i + 1 < ac) ? av[i + 1] : nullptr);
+ jobs = extract_job_number(i, av[i], nextArg, sizeof("--parallel") - 1);
+ if (jobs < 0) {
+ dir.clear();
}
+ doing = DoingNone;
+ } else if ((strcmp(av[i], "--target") == 0) ||
+ (strcmp(av[i], "-t") == 0)) {
+ doing = DoingTarget;
} else if (strcmp(av[i], "--config") == 0) {
doing = DoingConfig;
} else if (strcmp(av[i], "--clean-first") == 0) {
- clean = true;
+ cleanFirst = true;
+ doing = DoingNone;
+ } else if ((strcmp(av[i], "--verbose") == 0) ||
+ (strcmp(av[i], "-v") == 0)) {
+ verbose = true;
doing = DoingNone;
} else if (strcmp(av[i], "--use-stderr") == 0) {
/* tolerate legacy option */
@@ -400,8 +478,23 @@ static int do_build(int ac, char const* const* av)
doing = DoingNone;
break;
case DoingTarget:
- target = av[i];
- doing = DoingNone;
+ if (strlen(av[i]) == 0) {
+ std::cerr << "Warning: Argument number " << i
+ << " after --target option is empty." << std::endl;
+ } else {
+ targets.emplace_back(av[i]);
+ if (strcmp(av[i], "clean") == 0) {
+ foundClean = true;
+ } else {
+ foundNonClean = true;
+ }
+ }
+ if (foundClean && foundNonClean) {
+ std::cerr << "Error: Building 'clean' and other targets together "
+ "is not supported."
+ << std::endl;
+ dir.clear();
+ }
break;
case DoingConfig:
config = av[i];
@@ -409,11 +502,40 @@ static int do_build(int ac, char const* const* av)
break;
default:
std::cerr << "Unknown argument " << av[i] << std::endl;
- dir = "";
+ dir.clear();
break;
}
}
}
+
+ if (jobs == cmake::NO_BUILD_PARALLEL_LEVEL) {
+ std::string parallel;
+ if (cmSystemTools::GetEnv("CMAKE_BUILD_PARALLEL_LEVEL", parallel)) {
+ if (parallel.empty()) {
+ jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
+ } else {
+ unsigned long numJobs = 0;
+ if (cmSystemTools::StringToULong(parallel.c_str(), &numJobs)) {
+ if (numJobs == 0) {
+ std::cerr << "The CMAKE_BUILD_PARALLEL_LEVEL environment variable "
+ "requires a positive integer argument.\n\n";
+ dir.clear();
+ } else if (numJobs > INT_MAX) {
+ std::cerr << "The CMAKE_BUILD_PARALLEL_LEVEL environment variable "
+ "is too large.\n\n";
+ dir.clear();
+ } else {
+ jobs = int(numJobs);
+ }
+ } else {
+ std::cerr << "'CMAKE_BUILD_PARALLEL_LEVEL' environment variable\n"
+ << "invalid number '" << parallel << "' given.\n\n";
+ dir.clear();
+ }
+ }
+ }
+ }
+
if (dir.empty()) {
/* clang-format off */
std::cerr <<
@@ -425,9 +547,169 @@ static int do_build(int ac, char const* const* av)
return 1;
}
- cmake cm(cmake::RoleInternal);
- cmSystemTools::SetMessageCallback(cmakemainMessageCallback, (void*)&cm);
- cm.SetProgressCallback(cmakemainProgressCallback, (void*)&cm);
- return cm.Build(dir, target, config, nativeOptions, clean);
+ cmake cm(cmake::RoleInternal, cmState::Project);
+ cmSystemTools::SetMessageCallback(
+ [&cm](const std::string& msg, const char* title) {
+ cmakemainMessageCallback(msg, title, &cm);
+ });
+ cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
+ cmakemainProgressCallback(msg, prog, &cm);
+ });
+ return cm.Build(jobs, dir, targets, config, nativeOptions, cleanFirst,
+ verbose);
+#endif
+}
+
+static int do_install(int ac, char const* const* av)
+{
+#ifndef CMAKE_BUILD_WITH_CMAKE
+ std::cerr << "This cmake does not support --install\n";
+ return -1;
+#else
+ assert(1 < ac);
+
+ std::string config;
+ std::string component;
+ std::string prefix;
+ std::string dir;
+ bool strip = false;
+ bool verbose = cmSystemTools::HasEnv("VERBOSE");
+
+ enum Doing
+ {
+ DoingNone,
+ DoingDir,
+ DoingConfig,
+ DoingComponent,
+ DoingPrefix,
+ };
+
+ Doing doing = DoingDir;
+
+ for (int i = 2; i < ac; ++i) {
+ if (strcmp(av[i], "--config") == 0) {
+ doing = DoingConfig;
+ } else if (strcmp(av[i], "--component") == 0) {
+ doing = DoingComponent;
+ } else if (strcmp(av[i], "--prefix") == 0) {
+ doing = DoingPrefix;
+ } else if (strcmp(av[i], "--strip") == 0) {
+ strip = true;
+ doing = DoingNone;
+ } else if ((strcmp(av[i], "--verbose") == 0) ||
+ (strcmp(av[i], "-v") == 0)) {
+ verbose = true;
+ doing = DoingNone;
+ } else {
+ switch (doing) {
+ case DoingDir:
+ dir = cmSystemTools::CollapseFullPath(av[i]);
+ doing = DoingNone;
+ break;
+ case DoingConfig:
+ config = av[i];
+ doing = DoingNone;
+ break;
+ case DoingComponent:
+ component = av[i];
+ doing = DoingNone;
+ break;
+ case DoingPrefix:
+ prefix = av[i];
+ doing = DoingNone;
+ break;
+ default:
+ std::cerr << "Unknown argument " << av[i] << std::endl;
+ dir.clear();
+ break;
+ }
+ }
+ }
+
+ if (dir.empty()) {
+ std::cerr << "Usage: cmake --install <dir> "
+ "[options]\nOptions:\n" CMAKE_INSTALL_OPTIONS;
+ return 1;
+ }
+
+ cmake cm(cmake::RoleScript, cmState::Script);
+
+ cmSystemTools::SetMessageCallback(
+ [&cm](const std::string& msg, const char* title) {
+ cmakemainMessageCallback(msg, title, &cm);
+ });
+ cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
+ cmakemainProgressCallback(msg, prog, &cm);
+ });
+ cm.SetHomeDirectory("");
+ cm.SetHomeOutputDirectory("");
+ cm.SetDebugOutputOn(verbose);
+ cm.SetWorkingMode(cmake::SCRIPT_MODE);
+
+ std::vector<std::string> args{ av[0] };
+
+ if (!prefix.empty()) {
+ args.emplace_back("-DCMAKE_INSTALL_PREFIX=" + prefix);
+ }
+
+ if (!component.empty()) {
+ args.emplace_back("-DCMAKE_INSTALL_COMPONENT=" + component);
+ }
+
+ if (strip) {
+ args.emplace_back("-DCMAKE_INSTALL_DO_STRIP=1");
+ }
+
+ if (!config.empty()) {
+ args.emplace_back("-DCMAKE_INSTALL_CONFIG_NAME=" + config);
+ }
+
+ args.emplace_back("-P");
+ args.emplace_back(dir + "/cmake_install.cmake");
+
+ return cm.Run(args) ? 1 : 0;
+#endif
+}
+
+static int do_open(int ac, char const* const* av)
+{
+#ifndef CMAKE_BUILD_WITH_CMAKE
+ std::cerr << "This cmake does not support --open\n";
+ return -1;
+#else
+ std::string dir;
+
+ enum Doing
+ {
+ DoingNone,
+ DoingDir,
+ };
+ Doing doing = DoingDir;
+ for (int i = 2; i < ac; ++i) {
+ switch (doing) {
+ case DoingDir:
+ dir = cmSystemTools::CollapseFullPath(av[i]);
+ doing = DoingNone;
+ break;
+ default:
+ std::cerr << "Unknown argument " << av[i] << std::endl;
+ dir.clear();
+ break;
+ }
+ }
+ if (dir.empty()) {
+ std::cerr << "Usage: cmake --open <dir>\n";
+ return 1;
+ }
+
+ cmake cm(cmake::RoleInternal, cmState::Unknown);
+ cmSystemTools::SetMessageCallback(
+ [&cm](const std::string& msg, const char* title) {
+ cmakemainMessageCallback(msg, title, &cm);
+ });
+ cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
+ cmakemainProgressCallback(msg, prog, &cm);
+ });
+ return cm.Open(dir, false) ? 0 : 1;
#endif
}
diff --git a/Source/cmcldeps.cxx b/Source/cmcldeps.cxx
index 0c5bbe2df..19d0d3843 100644
--- a/Source/cmcldeps.cxx
+++ b/Source/cmcldeps.cxx
@@ -221,7 +221,7 @@ static int process(const std::string& srcfilename, const std::string& dfile,
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
+ if (inc.back() == '\r') // blech, stupid \r\n
inc = inc.substr(0, inc.size() - 1);
includes.push_back(inc);
} else {
@@ -276,7 +276,7 @@ int main()
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, "/fo ", "/out:");
clrest = replace(clrest, objfile, objfile + ".dep.obj ");
cl = "\"" + cl + "\" /P /DRC_INVOKED /TC ";
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index d5b086174..86082e517 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -3,46 +3,53 @@
#include "cmcmd.h"
#include "cmAlgorithms.h"
+#include "cmDuration.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
-#include "cmQtAutoGenerators.h"
+#include "cmQtAutoMocUic.h"
+#include "cmQtAutoRcc.h"
+#include "cmRange.h"
+#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmUtils.hxx"
#include "cmVersion.h"
-#include "cm_auto_ptr.hxx"
#include "cmake.h"
-#if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
-#include "cmServer.h"
-#include "cmServerConnection.h"
-#endif
-
#if defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
+# include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
+# include "cmServer.h"
+# include "cmServerConnection.h"
#endif
#if defined(CMAKE_BUILD_WITH_CMAKE) && defined(_WIN32)
-#include "bindexplib.h"
+# include "bindexplib.h"
+# include "cmsys/ConsoleBuf.hxx"
#endif
#if defined(CMAKE_BUILD_WITH_CMAKE) && defined(_WIN32) && !defined(__CYGWIN__)
-#include "cmVisualStudioWCEPlatformParser.h"
+# include "cmVisualStudioWCEPlatformParser.h"
#endif
-#include "cmConfigure.h"
#include "cmsys/Directory.hxx"
#include "cmsys/FStream.hxx"
#include "cmsys/Process.h"
#include "cmsys/Terminal.h"
#include <algorithm>
+#include <array>
#include <iostream>
+#include <iterator>
+#include <memory> // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
+#include <utility>
+
+class cmConnection;
int cmcmd_cmake_ninja_depends(std::vector<std::string>::const_iterator argBeg,
std::vector<std::string>::const_iterator argEnd);
@@ -73,7 +80,8 @@ void CMakeCommandUsage(const char* program)
<< " capabilities - Report capabilities built into cmake "
"in JSON format\n"
<< " chdir dir cmd [args...] - run command in a given directory\n"
- << " compare_files file1 file2 - check if file1 is same as file2\n"
+ << " compare_files [--ignore-eol] file1 file2\n"
+ << " - check if file1 is same as file2\n"
<< " copy <file>... destination - copy files to destination "
"(either file or directory)\n"
<< " copy_directory <dir>... destination - copy content of <dir>... "
@@ -88,18 +96,24 @@ void CMakeCommandUsage(const char* program)
<< " environment - display the current environment\n"
<< " make_directory <dir>... - create parent and <dir> directories\n"
<< " md5sum <file>... - create MD5 checksum of files\n"
+ << " sha1sum <file>... - create SHA1 checksum of files\n"
+ << " sha224sum <file>... - create SHA224 checksum of files\n"
+ << " sha256sum <file>... - create SHA256 checksum of files\n"
+ << " sha384sum <file>... - create SHA384 checksum of files\n"
+ << " sha512sum <file>... - create SHA512 checksum of files\n"
<< " remove [-f] <file>... - remove the file(s), use -f to force "
"it\n"
- << " remove_directory dir - remove a directory and its contents\n"
+ << " remove_directory <dir>... - remove directories and their contents\n"
<< " rename oldname newname - rename a file or directory "
"(on one volume)\n"
<< " server - start cmake in server mode\n"
<< " sleep <number>... - sleep for given number of seconds\n"
<< " tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]\n"
<< " - create or extract a tar or zip archive\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"
+ << " time command [args...] - run command and display elapsed time\n"
+ << " touch <file>... - touch a <file>.\n"
+ << " touch_nocreate <file>... - touch a <file> but do not create it.\n"
+ << " create_symlink old new - create a symbolic link new -> old\n"
#if defined(_WIN32) && !defined(__CYGWIN__)
<< "Available on Windows only:\n"
<< " delete_regv key - delete registry value\n"
@@ -108,14 +122,11 @@ void CMakeCommandUsage(const char* program)
<< " 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
;
/* clang-format on */
- cmSystemTools::Error(errorStream.str().c_str());
+ cmSystemTools::Error(errorStream.str());
}
static bool cmTarFilesFrom(std::string const& file,
@@ -124,14 +135,14 @@ static bool cmTarFilesFrom(std::string const& file,
if (cmSystemTools::FileIsDirectory(file)) {
std::ostringstream e;
e << "-E tar --files-from= file '" << file << "' is a directory";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return false;
}
cmsys::ifstream fin(file.c_str());
if (!fin) {
std::ostringstream e;
e << "-E tar --files-from= file '" << file << "' not found";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return false;
}
std::string line;
@@ -145,7 +156,7 @@ static bool cmTarFilesFrom(std::string const& file,
std::ostringstream e;
e << "-E tar --files-from='" << file << "' file invalid line:\n"
<< line << "\n";
- cmSystemTools::Error(e.str().c_str());
+ cmSystemTools::Error(e.str());
return false;
} else {
files.push_back(line);
@@ -154,7 +165,307 @@ static bool cmTarFilesFrom(std::string const& file,
return true;
}
-int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
+static int HandleIWYU(const std::string& runCmd,
+ const std::string& /* sourceFile */,
+ const std::vector<std::string>& orig_cmd)
+{
+ // Construct the iwyu command line by taking what was given
+ // and adding all the arguments we give to the compiler.
+ std::vector<std::string> iwyu_cmd;
+ cmSystemTools::ExpandListArgument(runCmd, iwyu_cmd, true);
+ cmAppend(iwyu_cmd, orig_cmd.begin() + 1, orig_cmd.end());
+ // Run the iwyu command line. Capture its stderr and hide its stdout.
+ // Ignore its return code because the tool always returns non-zero.
+ std::string stdErr;
+ int ret;
+ if (!cmSystemTools::RunSingleCommand(iwyu_cmd, nullptr, &stdErr, &ret,
+ nullptr, cmSystemTools::OUTPUT_NONE)) {
+ std::cerr << "Error running '" << iwyu_cmd[0] << "': " << stdErr << "\n";
+ return 1;
+ }
+ // Warn if iwyu reported anything.
+ if (stdErr.find("should remove these lines:") != std::string::npos ||
+ stdErr.find("should add these lines:") != std::string::npos) {
+ std::cerr << "Warning: include-what-you-use reported diagnostics:\n"
+ << stdErr << "\n";
+ }
+ // always return 0 we don't want to break the compile
+ return 0;
+}
+
+static int HandleTidy(const std::string& runCmd, const std::string& sourceFile,
+ const std::vector<std::string>& orig_cmd)
+{
+ // Construct the clang-tidy command line by taking what was given
+ // and adding our compiler command line. The clang-tidy tool will
+ // automatically skip over the compiler itself and extract the
+ // options.
+ int ret;
+ std::vector<std::string> tidy_cmd =
+ cmSystemTools::ExpandedListArgument(runCmd, true);
+ tidy_cmd.push_back(sourceFile);
+ tidy_cmd.emplace_back("--");
+ cmAppend(tidy_cmd, orig_cmd);
+
+ // Run the tidy command line. Capture its stdout and hide its stderr.
+ std::string stdOut;
+ std::string stdErr;
+ if (!cmSystemTools::RunSingleCommand(tidy_cmd, &stdOut, &stdErr, &ret,
+ nullptr, cmSystemTools::OUTPUT_NONE)) {
+ std::cerr << "Error running '" << tidy_cmd[0] << "': " << stdErr << "\n";
+ return 1;
+ }
+ // Output the stdout from clang-tidy to stderr
+ std::cerr << stdOut;
+ // If clang-tidy exited with an error do the same.
+ if (ret != 0) {
+ std::cerr << stdErr;
+ }
+ return ret;
+}
+
+static int HandleLWYU(const std::string& runCmd,
+ const std::string& /* sourceFile */,
+ const std::vector<std::string>&)
+{
+ // Construct the ldd -r -u (link what you use lwyu) command line
+ // ldd -u -r lwuy target
+ std::vector<std::string> lwyu_cmd;
+ lwyu_cmd.emplace_back("ldd");
+ lwyu_cmd.emplace_back("-u");
+ lwyu_cmd.emplace_back("-r");
+ lwyu_cmd.push_back(runCmd);
+
+ // Run the ldd -u -r command line.
+ // Capture its stdout and hide its stderr.
+ // Ignore its return code because the tool always returns non-zero
+ // if there are any warnings, but we just want to warn.
+ std::string stdOut;
+ std::string stdErr;
+ int ret;
+ if (!cmSystemTools::RunSingleCommand(lwyu_cmd, &stdOut, &stdErr, &ret,
+ nullptr, cmSystemTools::OUTPUT_NONE)) {
+ std::cerr << "Error running '" << lwyu_cmd[0] << "': " << stdErr << "\n";
+ return 1;
+ }
+
+ // Output the stdout from ldd -r -u to stderr
+ // Warn if lwyu reported anything.
+ if (stdOut.find("Unused direct dependencies:") != std::string::npos) {
+ std::cerr << "Warning: " << stdOut;
+ }
+ return 0;
+}
+
+static int HandleCppLint(const std::string& runCmd,
+ const std::string& sourceFile,
+ const std::vector<std::string>&)
+{
+ // Construct the cpplint command line.
+ std::vector<std::string> cpplint_cmd;
+ cmSystemTools::ExpandListArgument(runCmd, cpplint_cmd, true);
+ cpplint_cmd.push_back(sourceFile);
+
+ // Run the cpplint command line. Capture its output.
+ std::string stdOut;
+ int ret;
+ if (!cmSystemTools::RunSingleCommand(cpplint_cmd, &stdOut, &stdOut, &ret,
+ nullptr, cmSystemTools::OUTPUT_NONE)) {
+ std::cerr << "Error running '" << cpplint_cmd[0] << "': " << stdOut
+ << "\n";
+ return 1;
+ }
+ if (!stdOut.empty()) {
+ std::cerr << "Warning: cpplint diagnostics:\n";
+ // Output the output from cpplint to stderr
+ std::cerr << stdOut;
+ }
+
+ // always return 0 so the build can continue as cpplint returns non-zero
+ // for any warning
+ return 0;
+}
+
+static int HandleCppCheck(const std::string& runCmd,
+ const std::string& sourceFile,
+ const std::vector<std::string>& orig_cmd)
+{
+ // Construct the cpplint command line.
+ std::vector<std::string> cppcheck_cmd;
+ cmSystemTools::ExpandListArgument(runCmd, cppcheck_cmd, true);
+ // extract all the -D, -U, and -I options from the compile line
+ for (auto const& opt : orig_cmd) {
+ if (opt.size() > 2) {
+ if ((opt[0] == '-') &&
+ ((opt[1] == 'D') || (opt[1] == 'I') || (opt[1] == 'U'))) {
+ cppcheck_cmd.push_back(opt);
+// convert cl / options to - options if needed
+#if defined(_WIN32)
+ } else if ((opt[0] == '/') &&
+ ((opt[1] == 'D') || (opt[1] == 'I') || (opt[1] == 'U'))) {
+ std::string optcopy = opt;
+ optcopy[0] = '-';
+ cppcheck_cmd.push_back(optcopy);
+#endif
+ }
+ }
+ }
+ // add the source file
+ cppcheck_cmd.push_back(sourceFile);
+
+ // Run the cpplint command line. Capture its output.
+ std::string stdOut;
+ std::string stdErr;
+ int ret;
+ if (!cmSystemTools::RunSingleCommand(cppcheck_cmd, &stdOut, &stdErr, &ret,
+ nullptr, cmSystemTools::OUTPUT_NONE)) {
+ std::cerr << "Error running '" << cppcheck_cmd[0] << "': " << stdOut
+ << "\n";
+ return 1;
+ }
+ std::cerr << stdOut;
+ // Output the output from cpplint to stderr
+ if (stdErr.find("(error)") != std::string::npos ||
+ stdErr.find("(warning)") != std::string::npos ||
+ stdErr.find("(style)") != std::string::npos ||
+ stdErr.find("(performance)") != std::string::npos ||
+ stdErr.find("(portability)") != std::string::npos ||
+ stdErr.find("(information)") != std::string::npos) {
+ if (ret == 0) {
+ std::cerr << "Warning: cppcheck reported diagnostics:\n";
+ } else {
+ std::cerr << "Error: cppcheck reported failure:\n";
+ }
+ }
+ std::cerr << stdErr;
+
+ return ret;
+}
+
+typedef int (*CoCompileHandler)(const std::string&, const std::string&,
+ const std::vector<std::string>&);
+
+struct CoCompiler
+{
+ const char* Option;
+ CoCompileHandler Handler;
+ bool NoOriginalCommand;
+};
+
+static const std::array<CoCompiler, 5> CoCompilers = {
+ { // Table of options and handlers.
+ { "--cppcheck=", HandleCppCheck, false },
+ { "--cpplint=", HandleCppLint, false },
+ { "--iwyu=", HandleIWYU, false },
+ { "--lwyu=", HandleLWYU, true },
+ { "--tidy=", HandleTidy, false } }
+};
+
+struct CoCompileJob
+{
+ std::string Command;
+ CoCompileHandler Handler;
+};
+
+// called when args[0] == "__run_co_compile"
+int cmcmd::HandleCoCompileCommands(std::vector<std::string> const& args)
+{
+ std::vector<CoCompileJob> jobs;
+ std::string sourceFile; // store --source=
+ std::vector<std::string> launchers; // store --launcher=
+
+ // Default is to run the original command found after -- if the option
+ // does not need to do that, it should be specified here, currently only
+ // lwyu does that.
+ bool runOriginalCmd = true;
+
+ std::vector<std::string> orig_cmd;
+ bool doing_options = true;
+ for (std::string const& arg : cmMakeRange(args).advance(2)) {
+ // if the arg is -- then the rest of the args after
+ // go into orig_cmd
+ if (arg == "--") {
+ doing_options = false;
+ } else if (doing_options) {
+ bool optionFound = false;
+ for (CoCompiler const& cc : CoCompilers) {
+ size_t optionLen = strlen(cc.Option);
+ if (arg.compare(0, optionLen, cc.Option) == 0) {
+ optionFound = true;
+ CoCompileJob job;
+ job.Command = arg.substr(optionLen);
+ job.Handler = cc.Handler;
+ jobs.push_back(std::move(job));
+ if (cc.NoOriginalCommand) {
+ runOriginalCmd = false;
+ }
+ }
+ }
+ if (!optionFound) {
+ if (cmHasLiteralPrefix(arg, "--source=")) {
+ sourceFile = arg.substr(9);
+ } else if (cmHasLiteralPrefix(arg, "--launcher=")) {
+ cmSystemTools::ExpandListArgument(arg.substr(11), launchers, true);
+ } else {
+ // if it was not a co-compiler or --source/--launcher then error
+ std::cerr << "__run_co_compile given unknown argument: " << arg
+ << "\n";
+ return 1;
+ }
+ }
+ } else { // if not doing_options then push to orig_cmd
+ orig_cmd.push_back(arg);
+ }
+ }
+ if (jobs.empty()) {
+ std::cerr << "__run_co_compile missing command to run. "
+ "Looking for one or more of the following:\n";
+ for (CoCompiler const& cc : CoCompilers) {
+ std::cerr << cc.Option << "\n";
+ }
+ return 1;
+ }
+
+ if (runOriginalCmd && orig_cmd.empty()) {
+ std::cerr << "__run_co_compile missing compile command after --\n";
+ return 1;
+ }
+
+ for (CoCompileJob const& job : jobs) {
+ // call the command handler here
+ int ret = job.Handler(job.Command, sourceFile, orig_cmd);
+
+ // if the command returns non-zero then return and fail.
+ // for commands that do not want to break the build, they should return
+ // 0 no matter what.
+ if (ret != 0) {
+ return ret;
+ }
+ }
+
+ // if there is no original command to run return now
+ if (!runOriginalCmd) {
+ return 0;
+ }
+
+ // Prepend launcher argument(s), if any
+ if (!launchers.empty()) {
+ orig_cmd.insert(orig_cmd.begin(), launchers.begin(), launchers.end());
+ }
+
+ // Now run the real compiler command and return its result value
+ int ret;
+ if (!cmSystemTools::RunSingleCommand(orig_cmd, nullptr, nullptr, &ret,
+ nullptr,
+ cmSystemTools::OUTPUT_PASSTHROUGH)) {
+ std::cerr << "Error running '" << orig_cmd[0] << "'\n";
+ return 1;
+ }
+ // return the return value from the original compiler command
+ return ret;
+}
+
+int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args)
{
// IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
if (args.size() > 1) {
@@ -163,18 +474,17 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// If multiple source files specified,
// then destination must be directory
if ((args.size() > 4) &&
- (!cmSystemTools::FileIsDirectory(args[args.size() - 1]))) {
- std::cerr << "Error: Target (for copy command) \""
- << args[args.size() - 1] << "\" is not a directory.\n";
+ (!cmSystemTools::FileIsDirectory(args.back()))) {
+ std::cerr << "Error: Target (for copy command) \"" << args.back()
+ << "\" is not a directory.\n";
return 1;
}
// If error occurs we want to continue copying next files.
bool return_value = false;
- for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
- if (!cmSystemTools::cmCopyFile(args[cc].c_str(),
- args[args.size() - 1].c_str())) {
- std::cerr << "Error copying file \"" << args[cc] << "\" to \""
- << args[args.size() - 1] << "\".\n";
+ for (auto const& arg : cmMakeRange(args).advance(2).retreat(1)) {
+ if (!cmsys::SystemTools::CopyFileAlways(arg, args.back())) {
+ std::cerr << "Error copying file \"" << arg << "\" to \""
+ << args.back() << "\".\n";
return_value = true;
}
}
@@ -186,18 +496,17 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// If multiple source files specified,
// then destination must be directory
if ((args.size() > 4) &&
- (!cmSystemTools::FileIsDirectory(args[args.size() - 1]))) {
+ (!cmSystemTools::FileIsDirectory(args.back()))) {
std::cerr << "Error: Target (for copy_if_different command) \""
- << args[args.size() - 1] << "\" is not a directory.\n";
+ << args.back() << "\" is not a directory.\n";
return 1;
}
// If error occurs we want to continue copying next files.
bool return_value = false;
- for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
- if (!cmSystemTools::CopyFileIfDifferent(
- args[cc].c_str(), args[args.size() - 1].c_str())) {
- std::cerr << "Error copying file (if different) from \"" << args[cc]
- << "\" to \"" << args[args.size() - 1] << "\".\n";
+ for (auto const& arg : cmMakeRange(args).advance(2).retreat(1)) {
+ if (!cmSystemTools::CopyFileIfDifferent(arg, args.back())) {
+ std::cerr << "Error copying file (if different) from \"" << arg
+ << "\" to \"" << args.back() << "\".\n";
return_value = true;
}
}
@@ -208,10 +517,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
if (args[1] == "copy_directory" && args.size() > 3) {
// If error occurs we want to continue copying next files.
bool return_value = false;
- for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
- if (!cmSystemTools::CopyADirectory(args[cc], args[args.size() - 1])) {
- std::cerr << "Error copying directory from \"" << args[cc]
- << "\" to \"" << args[args.size() - 1] << "\".\n";
+ for (auto const& arg : cmMakeRange(args).advance(2).retreat(1)) {
+ if (!cmSystemTools::CopyADirectory(arg, args.back())) {
+ std::cerr << "Error copying directory from \"" << arg << "\" to \""
+ << args.back() << "\".\n";
return_value = true;
}
}
@@ -220,7 +529,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Rename a file or directory
if (args[1] == "rename" && args.size() == 4) {
- if (!cmSystemTools::RenameFile(args[2].c_str(), args[3].c_str())) {
+ if (!cmSystemTools::RenameFile(args[2], args[3])) {
std::string e = cmSystemTools::GetLastSystemError();
std::cerr << "Error renaming from \"" << args[2] << "\" to \""
<< args[3] << "\": " << e << "\n";
@@ -230,10 +539,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
}
// Compare files
- if (args[1] == "compare_files" && args.size() == 4) {
- if (cmSystemTools::FilesDiffer(args[2], args[3])) {
- std::cerr << "Files \"" << args[2] << "\" to \"" << args[3]
- << "\" are different.\n";
+ if (args[1] == "compare_files" && (args.size() == 4 || args.size() == 5)) {
+ bool filesDiffer;
+ if (args.size() == 4) {
+ filesDiffer = cmSystemTools::FilesDiffer(args[2], args[3]);
+ } else if (args[2] == "--ignore-eol") {
+ filesDiffer = cmsys::SystemTools::TextFilesDiffer(args[3], args[4]);
+ } else {
+ ::CMakeCommandUsage(args[0].c_str());
+ return 1;
+ }
+
+ if (filesDiffer) {
+ std::cerr << "Files \"" << args[args.size() - 2] << "\" to \""
+ << args[args.size() - 1] << "\" are different.\n";
return 1;
}
return 0;
@@ -277,181 +596,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
return 0;
}
#endif
- // run include what you use command and then run the compile
- // command. This is an internal undocumented option and should
- // only be used by CMake itself when running iwyu.
- if (args[1] == "__run_iwyu") {
- if (args.size() < 3) {
- std::cerr << "__run_iwyu Usage: -E __run_iwyu [--iwyu=/path/iwyu]"
- " [--cpplint=/path/cpplint] [--tidy=/path/tidy]"
- " -- compile command\n";
- return 1;
- }
- bool doing_options = true;
- std::vector<std::string> orig_cmd;
- std::string iwyu;
- std::string tidy;
- std::string sourceFile;
- std::string lwyu;
- std::string cpplint;
- for (std::string::size_type cc = 2; cc < args.size(); cc++) {
- std::string const& arg = args[cc];
- if (arg == "--") {
- doing_options = false;
- } else if (doing_options && cmHasLiteralPrefix(arg, "--iwyu=")) {
- iwyu = arg.substr(7);
- } else if (doing_options && cmHasLiteralPrefix(arg, "--tidy=")) {
- tidy = arg.substr(7);
- } else if (doing_options && cmHasLiteralPrefix(arg, "--source=")) {
- sourceFile = arg.substr(9);
- } else if (doing_options && cmHasLiteralPrefix(arg, "--lwyu=")) {
- lwyu = arg.substr(7);
- } else if (doing_options && cmHasLiteralPrefix(arg, "--cpplint=")) {
- cpplint = arg.substr(10);
- } else if (doing_options) {
- std::cerr << "__run_iwyu given unknown argument: " << arg << "\n";
- return 1;
- } else {
- orig_cmd.push_back(arg);
- }
- }
- if (tidy.empty() && iwyu.empty() && lwyu.empty() && cpplint.empty()) {
- std::cerr << "__run_iwyu missing --cpplint=, --iwyu=, --lwyu=, and/or"
- " --tidy=\n";
- return 1;
- }
- if ((!cpplint.empty() || !tidy.empty()) && sourceFile.empty()) {
- std::cerr << "__run_iwyu --cpplint= and/or __run_iwyu --tidy="
- " require --source=\n";
- return 1;
- }
- if (orig_cmd.empty() && lwyu.empty()) {
- std::cerr << "__run_iwyu missing compile command after --\n";
- return 1;
- }
-
- int ret = 0;
-
- if (!iwyu.empty()) {
- // Construct the iwyu command line by taking what was given
- // and adding all the arguments we give to the compiler.
- std::vector<std::string> iwyu_cmd;
- cmSystemTools::ExpandListArgument(iwyu, iwyu_cmd, true);
- iwyu_cmd.insert(iwyu_cmd.end(), orig_cmd.begin() + 1, orig_cmd.end());
-
- // Run the iwyu command line. Capture its stderr and hide its stdout.
- // Ignore its return code because the tool always returns non-zero.
- std::string stdErr;
- if (!cmSystemTools::RunSingleCommand(iwyu_cmd, CM_NULLPTR, &stdErr,
- &ret, CM_NULLPTR,
- cmSystemTools::OUTPUT_NONE)) {
- std::cerr << "Error running '" << iwyu_cmd[0] << "': " << stdErr
- << "\n";
- return 1;
- }
-
- // Warn if iwyu reported anything.
- if (stdErr.find("should remove these lines:") != std::string::npos ||
- stdErr.find("should add these lines:") != std::string::npos) {
- std::cerr << "Warning: include-what-you-use reported diagnostics:\n"
- << stdErr << "\n";
- }
- }
-
- if (!tidy.empty()) {
- // Construct the clang-tidy command line by taking what was given
- // and adding our compiler command line. The clang-tidy tool will
- // automatically skip over the compiler itself and extract the
- // options.
- std::vector<std::string> tidy_cmd;
- cmSystemTools::ExpandListArgument(tidy, tidy_cmd, true);
- tidy_cmd.push_back(sourceFile);
- tidy_cmd.push_back("--");
- tidy_cmd.insert(tidy_cmd.end(), orig_cmd.begin(), orig_cmd.end());
-
- // Run the tidy command line. Capture its stdout and hide its stderr.
- std::string stdOut;
- std::string stdErr;
- if (!cmSystemTools::RunSingleCommand(tidy_cmd, &stdOut, &stdErr, &ret,
- CM_NULLPTR,
- cmSystemTools::OUTPUT_NONE)) {
- std::cerr << "Error running '" << tidy_cmd[0] << "': " << stdErr
- << "\n";
- return 1;
- }
- // Output the stdout from clang-tidy to stderr
- std::cerr << stdOut;
- // If clang-tidy exited with an error do the same.
- if (ret != 0) {
- std::cerr << stdErr;
- return ret;
- }
- }
- if (!lwyu.empty()) {
- // Construct the ldd -r -u (link what you use lwyu) command line
- // ldd -u -r lwuy target
- std::vector<std::string> lwyu_cmd;
- lwyu_cmd.push_back("ldd");
- lwyu_cmd.push_back("-u");
- lwyu_cmd.push_back("-r");
- lwyu_cmd.push_back(lwyu);
-
- // Run the ldd -u -r command line.
- // Capture its stdout and hide its stderr.
- // Ignore its return code because the tool always returns non-zero
- // if there are any warnings, but we just want to warn.
- std::string stdOut;
- std::string stdErr;
- if (!cmSystemTools::RunSingleCommand(lwyu_cmd, &stdOut, &stdErr, &ret,
- CM_NULLPTR,
- cmSystemTools::OUTPUT_NONE)) {
- std::cerr << "Error running '" << lwyu_cmd[0] << "': " << stdErr
- << "\n";
- return 1;
- }
-
- // Output the stdout from ldd -r -u to stderr
- // Warn if lwyu reported anything.
- if (stdOut.find("Unused direct dependencies:") != std::string::npos) {
- std::cerr << "Warning: " << stdOut;
- }
- }
-
- if (!cpplint.empty()) {
- // Construct the cpplint command line.
- std::vector<std::string> cpplint_cmd;
- cmSystemTools::ExpandListArgument(cpplint, cpplint_cmd, true);
- cpplint_cmd.push_back(sourceFile);
-
- // Run the cpplint command line. Capture its output.
- std::string stdOut;
- if (!cmSystemTools::RunSingleCommand(cpplint_cmd, &stdOut, &stdOut,
- &ret, CM_NULLPTR,
- cmSystemTools::OUTPUT_NONE)) {
- std::cerr << "Error running '" << cpplint_cmd[0] << "': " << stdOut
- << "\n";
- return 1;
- }
-
- // Output the output from cpplint to stderr
- std::cerr << stdOut;
-
- // If cpplint exited with an error do the same.
- if (ret != 0) {
- return ret;
- }
- }
-
- ret = 0;
- // Now run the real compiler command and return its result value.
- if (lwyu.empty() &&
- !cmSystemTools::RunSingleCommand(
- orig_cmd, CM_NULLPTR, CM_NULLPTR, &ret, CM_NULLPTR,
- cmSystemTools::OUTPUT_PASSTHROUGH)) {
- std::cerr << "Error running '" << orig_cmd[0] << "'\n";
- return 1;
- }
- return ret;
+ if (args[1] == "__run_co_compile") {
+ return cmcmd::HandleCoCompileCommands(args);
}
// Echo string
@@ -467,13 +613,13 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
}
if (args[1] == "env") {
- std::vector<std::string>::const_iterator ai = args.begin() + 2;
- std::vector<std::string>::const_iterator ae = args.end();
+ auto ai = args.cbegin() + 2;
+ auto ae = args.cend();
for (; ai != ae; ++ai) {
std::string const& a = *ai;
if (cmHasLiteralPrefix(a, "--unset=")) {
// Unset environment variable.
- cmSystemTools::UnPutEnv(a.c_str() + 8);
+ cmSystemTools::UnPutEnv(a.substr(8));
} else if (!a.empty() && a[0] == '-') {
// Environment variable and command names cannot start in '-',
// so this must be an unknown option.
@@ -497,8 +643,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Execute command from remaining arguments.
std::vector<std::string> cmd(ai, ae);
int retval;
- if (cmSystemTools::RunSingleCommand(cmd, CM_NULLPTR, CM_NULLPTR, &retval,
- CM_NULLPTR,
+ if (cmSystemTools::RunSingleCommand(cmd, nullptr, nullptr, &retval,
+ nullptr,
cmSystemTools::OUTPUT_PASSTHROUGH)) {
return retval;
}
@@ -507,47 +653,49 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
#if defined(CMAKE_BUILD_WITH_CMAKE)
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;
+ for (auto const& env : cmSystemTools::GetEnvironmentVariables()) {
+ std::cout << env << std::endl;
}
return 0;
}
#endif
if (args[1] == "make_directory" && args.size() > 2) {
- // If error occurs we want to continue copying next files.
+ // If an error occurs, we want to continue making directories.
bool return_value = false;
- for (std::string::size_type cc = 2; cc < args.size(); cc++) {
- if (!cmSystemTools::MakeDirectory(args[cc].c_str())) {
- std::cerr << "Error creating directory \"" << args[cc] << "\".\n";
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
+ if (!cmSystemTools::MakeDirectory(arg)) {
+ std::cerr << "Error creating directory \"" << arg << "\".\n";
return_value = true;
}
}
return return_value;
}
- if (args[1] == "remove_directory" && args.size() == 3) {
- if (cmSystemTools::FileIsDirectory(args[2]) &&
- !cmSystemTools::RemoveADirectory(args[2])) {
- std::cerr << "Error removing directory \"" << args[2] << "\".\n";
- return 1;
+ if (args[1] == "remove_directory" && args.size() > 2) {
+ // If an error occurs, we want to continue removing directories.
+ bool return_value = false;
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
+ if (cmSystemTools::FileIsDirectory(arg) &&
+ !cmSystemTools::RemoveADirectory(arg)) {
+ std::cerr << "Error removing directory \"" << arg << "\".\n";
+ return_value = true;
+ }
}
- return 0;
+ return return_value;
}
// Remove file
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") {
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
+ if (arg == "\\-f" || arg == "-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]) && !force &&
- cmSystemTools::FileExists(args[cc].c_str())) {
+ if (!cmSystemTools::RemoveFile(arg) && !force &&
+ cmSystemTools::FileExists(arg)) {
return 1;
}
}
@@ -557,8 +705,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Touch file
if (args[1] == "touch" && args.size() > 2) {
- for (std::string::size_type cc = 2; cc < args.size(); cc++) {
- if (!cmSystemTools::Touch(args[cc], true)) {
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
+ if (!cmSystemTools::Touch(arg, true)) {
+ std::cerr << "cmake -E touch: failed to update \"";
+ std::cerr << arg << "\".\n";
return 1;
}
}
@@ -567,10 +717,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Touch file
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], false)) {
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
+ if (!cmSystemTools::Touch(arg, false)) {
+ std::cerr << "cmake -E touch_nocreate: failed to update \"";
+ std::cerr << arg << "\".\n";
return 1;
}
}
@@ -583,27 +733,23 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::cerr << "-E capabilities accepts no additional arguments\n";
return 1;
}
- cmake cm(cmake::RoleInternal);
-#if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
- std::cout << cm.ReportCapabilities(true);
-#else
- std::cout << cm.ReportCapabilities(false);
-#endif
+ cmake cm(cmake::RoleInternal, cmState::Unknown);
+ std::cout << cm.ReportCapabilities();
return 0;
}
// Sleep command
if (args[1] == "sleep" && args.size() > 2) {
double total = 0;
- for (size_t i = 2; i < args.size(); ++i) {
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
double num = 0.0;
char unit;
char extra;
- int n = sscanf(args[i].c_str(), "%lg%c%c", &num, &unit, &extra);
+ int n = sscanf(arg.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";
+ std::cerr << "Unknown sleep time format \"" << arg << "\".\n";
return 1;
}
}
@@ -623,7 +769,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
time(&time_start);
clock_start = clock();
int ret = 0;
- cmSystemTools::RunSingleCommand(command, CM_NULLPTR, CM_NULLPTR, &ret);
+ cmSystemTools::RunSingleCommand(command, nullptr, nullptr, &ret);
clock_finish = clock();
time(&time_finish);
@@ -641,42 +787,45 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
// Command to calculate the md5sum of a file
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;
+ return HashSumFile(args, cmCryptoHash::AlgoMD5);
+ }
+
+ // Command to calculate the sha1sum of a file
+ if (args[1] == "sha1sum" && args.size() >= 3) {
+ return HashSumFile(args, cmCryptoHash::AlgoSHA1);
+ }
+
+ if (args[1] == "sha224sum" && args.size() >= 3) {
+ return HashSumFile(args, cmCryptoHash::AlgoSHA224);
+ }
+
+ if (args[1] == "sha256sum" && args.size() >= 3) {
+ return HashSumFile(args, cmCryptoHash::AlgoSHA256);
+ }
+
+ if (args[1] == "sha384sum" && args.size() >= 3) {
+ return HashSumFile(args, cmCryptoHash::AlgoSHA384);
+ }
+
+ if (args[1] == "sha512sum" && args.size() >= 3) {
+ return HashSumFile(args, cmCryptoHash::AlgoSHA512);
}
// Command to change directory and run a program.
if (args[1] == "chdir" && args.size() >= 4) {
std::string const& directory = args[2];
- if (!cmSystemTools::FileExists(directory.c_str())) {
- cmSystemTools::Error("Directory does not exist for chdir command: ",
- args[2].c_str());
+ if (!cmSystemTools::FileExists(directory)) {
+ cmSystemTools::Error("Directory does not exist for chdir command: " +
+ args[2]);
return 1;
}
std::string command =
cmWrap('"', cmMakeRange(args).advance(3), '"', " ");
int retval = 0;
- int timeout = 0;
if (cmSystemTools::RunSingleCommand(
- command.c_str(), CM_NULLPTR, CM_NULLPTR, &retval,
- directory.c_str(), cmSystemTools::OUTPUT_PASSTHROUGH, timeout)) {
+ command, nullptr, nullptr, &retval, directory.c_str(),
+ cmSystemTools::OUTPUT_PASSTHROUGH, cmDuration::zero())) {
return retval;
}
@@ -702,7 +851,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
count = atoi(args[3].c_str());
}
if (count) {
- cmSystemTools::MakeDirectory(dirName.c_str());
+ cmSystemTools::MakeDirectory(dirName);
// write the count into the directory
std::string fName = dirName;
fName += "/count.txt";
@@ -737,9 +886,6 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
return 1;
}
if (!cmSystemTools::CreateSymlink(args[2], args[3])) {
- std::string emsg = cmSystemTools::GetLastSystemError();
- std::cerr << "failed to create symbolic link '" << destinationFileName
- << "': " << emsg << "\n";
return 1;
}
return 0;
@@ -760,7 +906,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
const bool verbose = isCMakeVerbose();
// Create a cmake object instance to process dependencies.
- cmake cm(cmake::RoleScript); // All we need is the `set` command.
+ // All we need is the `set` command.
+ cmake cm(cmake::RoleScript, cmState::Unknown);
std::string gen;
std::string homeDir;
std::string startDir;
@@ -786,8 +933,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
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()));
+ color =
+ (args[8].size() == 8 || cmSystemTools::IsOn(args[8].substr(8)));
}
} else {
// Support older signature for existing makefiles:
@@ -820,12 +967,11 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
cmStateSnapshot snapshot = cm.GetCurrentSnapshot();
snapshot.GetDirectory().SetCurrentBinary(startOutDir);
snapshot.GetDirectory().SetCurrentSource(startDir);
- CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(ggd, snapshot));
- CM_AUTO_PTR<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(mf.get()));
+ cmMakefile mf(ggd, snapshot);
+ std::unique_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator(&mf));
// Actually scan dependencies.
- return lgd->UpdateDependencies(depInfo.c_str(), verbose, color) ? 0
- : 2;
+ return lgd->UpdateDependencies(depInfo, verbose, color) ? 0 : 2;
}
return 1;
}
@@ -871,11 +1017,20 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
}
#ifdef CMAKE_BUILD_WITH_CMAKE
- if (args[1] == "cmake_autogen" && args.size() >= 4) {
- cmQtAutoGenerators autogen;
+ if ((args[1] == "cmake_autogen") && (args.size() >= 4)) {
+ cmQtAutoMocUic autoGen;
+ std::string const& infoDir = args[2];
std::string const& config = args[3];
- bool autogenSuccess = autogen.Run(args[2], config);
- return autogenSuccess ? 0 : 1;
+ return autoGen.Run(infoDir, config) ? 0 : 1;
+ }
+ if ((args[1] == "cmake_autorcc") && (args.size() >= 3)) {
+ cmQtAutoRcc autoGen;
+ std::string const& infoFile = args[2];
+ std::string config;
+ if (args.size() > 3) {
+ config = args[3];
+ }
+ return autoGen.Run(infoFile, config) ? 0 : 1;
}
#endif
@@ -888,12 +1043,17 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
std::vector<std::string> files;
std::string mtime;
std::string format;
+ cmSystemTools::cmTarCompression compress =
+ cmSystemTools::TarCompressNone;
+ int nCompress = 0;
bool doing_options = true;
- for (std::string::size_type cc = 4; cc < args.size(); cc++) {
- std::string const& arg = args[cc];
+ for (auto const& arg : cmMakeRange(args).advance(4)) {
if (doing_options && cmHasLiteralPrefix(arg, "--")) {
if (arg == "--") {
doing_options = false;
+ } else if (arg == "--zstd") {
+ compress = cmSystemTools::TarCompressZstd;
+ ++nCompress;
} else if (cmHasLiteralPrefix(arg, "--mtime=")) {
mtime = arg.substr(8);
} else if (cmHasLiteralPrefix(arg, "--files-from=")) {
@@ -904,41 +1064,64 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
} else if (cmHasLiteralPrefix(arg, "--format=")) {
format = arg.substr(9);
bool isKnown =
- std::find(cmArrayBegin(knownFormats), cmArrayEnd(knownFormats),
- format) != cmArrayEnd(knownFormats);
+ std::find(cm::cbegin(knownFormats), cm::cend(knownFormats),
+ format) != cm::cend(knownFormats);
if (!isKnown) {
- cmSystemTools::Error("Unknown -E tar --format= argument: ",
- format.c_str());
+ cmSystemTools::Error("Unknown -E tar --format= argument: " +
+ format);
return 1;
}
} else {
- cmSystemTools::Error("Unknown option to -E tar: ", arg.c_str());
+ cmSystemTools::Error("Unknown option to -E tar: " + arg);
return 1;
}
} else {
files.push_back(arg);
}
}
- cmSystemTools::cmTarCompression compress =
- cmSystemTools::TarCompressNone;
+ cmSystemTools::cmTarAction action = cmSystemTools::TarActionNone;
bool verbose = false;
- int nCompress = 0;
- if (flags.find_first_of('j') != std::string::npos) {
- compress = cmSystemTools::TarCompressBZip2;
- ++nCompress;
- }
- if (flags.find_first_of('J') != std::string::npos) {
- compress = cmSystemTools::TarCompressXZ;
- ++nCompress;
- }
- if (flags.find_first_of('z') != std::string::npos) {
- compress = cmSystemTools::TarCompressGZip;
- ++nCompress;
+
+ for (auto flag : flags) {
+ switch (flag) {
+ case '-':
+ case 'f': {
+ // Keep for backward compatibility. Ignored
+ } break;
+ case 'j': {
+ compress = cmSystemTools::TarCompressBZip2;
+ ++nCompress;
+ } break;
+ case 'J': {
+ compress = cmSystemTools::TarCompressXZ;
+ ++nCompress;
+ } break;
+ case 'z': {
+ compress = cmSystemTools::TarCompressGZip;
+ ++nCompress;
+ } break;
+ case 'v': {
+ verbose = true;
+ } break;
+ case 't': {
+ action = cmSystemTools::TarActionList;
+ } break;
+ case 'c': {
+ action = cmSystemTools::TarActionCreate;
+ } break;
+ case 'x': {
+ action = cmSystemTools::TarActionExtract;
+ } break;
+ default: {
+ cmSystemTools::Message(
+ std::string("tar: Unknown argument: ") + flag, "Warning");
+ }
+ }
}
if ((format == "7zip" || format == "zip") && nCompress > 0) {
- cmSystemTools::Error("Can not use compression flags with format: ",
- format.c_str());
+ cmSystemTools::Error("Can not use compression flags with format: " +
+ format);
return 1;
}
if (nCompress > 1) {
@@ -946,24 +1129,24 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
"at most one flag of z, j, or J may be used");
return 1;
}
- if (flags.find_first_of('v') != std::string::npos) {
- verbose = true;
- }
-
- if (flags.find_first_of('t') != std::string::npos) {
- if (!cmSystemTools::ListTar(outFile.c_str(), verbose)) {
- cmSystemTools::Error("Problem listing tar: ", outFile.c_str());
+ if (action == cmSystemTools::TarActionList) {
+ if (!cmSystemTools::ListTar(outFile, files, verbose)) {
+ cmSystemTools::Error("Problem listing tar: " + outFile);
return 1;
}
- } else if (flags.find_first_of('c') != std::string::npos) {
- if (!cmSystemTools::CreateTar(outFile.c_str(), files, compress,
- verbose, mtime, format)) {
- cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
+ } else if (action == cmSystemTools::TarActionCreate) {
+ if (files.empty()) {
+ cmSystemTools::Message("tar: No files or directories specified",
+ "Warning");
+ }
+ if (!cmSystemTools::CreateTar(outFile, files, compress, verbose, mtime,
+ format)) {
+ cmSystemTools::Error("Problem creating tar: " + outFile);
return 1;
}
- } else if (flags.find_first_of('x') != std::string::npos) {
- if (!cmSystemTools::ExtractTar(outFile.c_str(), verbose)) {
- cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
+ } else if (action == cmSystemTools::TarActionExtract) {
+ if (!cmSystemTools::ExtractTar(outFile, files, verbose)) {
+ cmSystemTools::Error("Problem extracting tar: " + outFile);
return 1;
}
#ifdef WIN32
@@ -982,6 +1165,10 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
cmSystemTools::Delay(delay);
}
#endif
+ } else {
+ cmSystemTools::Error("tar: No action specified. Please choose: 't' "
+ "(list), 'c' (create) or 'x' (extract)");
+ return 1;
}
return 0;
}
@@ -992,17 +1179,15 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
bool isDebug = false;
std::string pipe;
- for (size_t i = 2; i < args.size(); ++i) {
- const std::string& a = args[i];
-
- if (a == "--experimental") {
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
+ if (arg == "--experimental") {
supportExperimental = true;
- } else if (a == "--debug") {
+ } else if (arg == "--debug") {
pipe.clear();
isDebug = true;
- } else if (a.substr(0, pipePrefix.size()) == pipePrefix) {
+ } else if (arg.substr(0, pipePrefix.size()) == pipePrefix) {
isDebug = false;
- pipe = a.substr(pipePrefix.size());
+ pipe = arg.substr(pipePrefix.size());
if (pipe.empty()) {
cmSystemTools::Error("No pipe given after --pipe=");
return 2;
@@ -1012,8 +1197,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
return 1;
}
}
-#if defined(HAVE_SERVER_MODE) && HAVE_SERVER_MODE
- cmServerConnection* conn;
+#if defined(CMAKE_BUILD_WITH_CMAKE)
+ cmConnection* conn;
if (isDebug) {
conn = new cmServerStdIoConnection;
} else {
@@ -1024,7 +1209,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
if (server.Serve(&errorMessage)) {
return 0;
}
- cmSystemTools::Error(errorMessage.c_str());
+ cmSystemTools::Error(errorMessage);
#else
static_cast<void>(supportExperimental);
static_cast<void>(isDebug);
@@ -1074,12 +1259,42 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
return 1;
}
-int cmcmd::SymlinkLibrary(std::vector<std::string>& args)
+int cmcmd::HashSumFile(std::vector<std::string> const& args,
+ cmCryptoHash::Algo algo)
+{
+ if (args.size() < 3) {
+ return -1;
+ }
+ int retval = 0;
+
+ for (auto const& filename : cmMakeRange(args).advance(2)) {
+ // Cannot compute sum of a directory
+ if (cmSystemTools::FileIsDirectory(filename)) {
+ std::cerr << "Error: " << filename << " is a directory" << std::endl;
+ retval++;
+ } else {
+ std::string value = cmSystemTools::ComputeFileHash(filename, algo);
+ if (value.empty()) {
+ // To mimic "md5sum/shasum" behavior in a shell:
+ std::cerr << filename << ": No such file or directory" << std::endl;
+ retval++;
+ } else {
+ std::cout << value << " " << filename << std::endl;
+ }
+ }
+ }
+ return retval;
+}
+
+int cmcmd::SymlinkLibrary(std::vector<std::string> const& args)
{
int result = 0;
- std::string const& realName = args[2];
- std::string const& soName = args[3];
- std::string const& name = args[4];
+ std::string realName = args[2];
+ std::string soName = args[3];
+ std::string name = args[4];
+ cmSystemTools::ConvertToUnixSlashes(realName);
+ cmSystemTools::ConvertToUnixSlashes(soName);
+ cmSystemTools::ConvertToUnixSlashes(name);
if (soName != realName) {
if (!cmcmd::SymlinkInternal(realName, soName)) {
cmSystemTools::ReportLastSystemError("cmake_symlink_library");
@@ -1095,7 +1310,7 @@ int cmcmd::SymlinkLibrary(std::vector<std::string>& args)
return result;
}
-int cmcmd::SymlinkExecutable(std::vector<std::string>& args)
+int cmcmd::SymlinkExecutable(std::vector<std::string> const& args)
{
int result = 0;
std::string const& realName = args[2];
@@ -1111,12 +1326,11 @@ int cmcmd::SymlinkExecutable(std::vector<std::string>& args)
bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link)
{
- if (cmSystemTools::FileExists(link.c_str()) ||
- cmSystemTools::FileIsSymlink(link)) {
+ if (cmSystemTools::FileExists(link) || cmSystemTools::FileIsSymlink(link)) {
cmSystemTools::RemoveFile(link);
}
#if defined(_WIN32) && !defined(__CYGWIN__)
- return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
+ return cmSystemTools::CopyFileAlways(file, link);
#else
std::string linktext = cmSystemTools::GetFilenameName(file);
return cmSystemTools::CreateSymlink(linktext, link);
@@ -1170,75 +1384,74 @@ static void cmcmdProgressReport(std::string const& dir, std::string const& num)
}
}
-int cmcmd::ExecuteEchoColor(std::vector<std::string>& args)
+int cmcmd::ExecuteEchoColor(std::vector<std::string> const& args)
{
// The arguments are
- // argv[0] == <cmake-executable>
- // argv[1] == cmake_echo_color
+ // args[0] == <cmake-executable>
+ // args[1] == cmake_echo_color
bool enabled = true;
int color = cmsysTerminal_Color_Normal;
bool newline = true;
std::string progressDir;
- for (unsigned int i = 2; i < args.size(); ++i) {
- if (args[i].find("--switch=") == 0) {
+ for (auto const& arg : cmMakeRange(args).advance(2)) {
+ if (arg.find("--switch=") == 0) {
// Enable or disable color based on the switch value.
- std::string value = args[i].substr(9);
+ std::string value = arg.substr(9);
if (!value.empty()) {
- enabled = cmSystemTools::IsOn(value.c_str());
+ enabled = cmSystemTools::IsOn(value);
}
- } else if (cmHasLiteralPrefix(args[i], "--progress-dir=")) {
- progressDir = args[i].substr(15);
- } else if (cmHasLiteralPrefix(args[i], "--progress-num=")) {
+ } else if (cmHasLiteralPrefix(arg, "--progress-dir=")) {
+ progressDir = arg.substr(15);
+ } else if (cmHasLiteralPrefix(arg, "--progress-num=")) {
if (!progressDir.empty()) {
- std::string const& progressNum = args[i].substr(15);
+ std::string const& progressNum = arg.substr(15);
cmcmdProgressReport(progressDir, progressNum);
}
- } else if (args[i] == "--normal") {
+ } else if (arg == "--normal") {
color = cmsysTerminal_Color_Normal;
- } else if (args[i] == "--black") {
+ } else if (arg == "--black") {
color = cmsysTerminal_Color_ForegroundBlack;
- } else if (args[i] == "--red") {
+ } else if (arg == "--red") {
color = cmsysTerminal_Color_ForegroundRed;
- } else if (args[i] == "--green") {
+ } else if (arg == "--green") {
color = cmsysTerminal_Color_ForegroundGreen;
- } else if (args[i] == "--yellow") {
+ } else if (arg == "--yellow") {
color = cmsysTerminal_Color_ForegroundYellow;
- } else if (args[i] == "--blue") {
+ } else if (arg == "--blue") {
color = cmsysTerminal_Color_ForegroundBlue;
- } else if (args[i] == "--magenta") {
+ } else if (arg == "--magenta") {
color = cmsysTerminal_Color_ForegroundMagenta;
- } else if (args[i] == "--cyan") {
+ } else if (arg == "--cyan") {
color = cmsysTerminal_Color_ForegroundCyan;
- } else if (args[i] == "--white") {
+ } else if (arg == "--white") {
color = cmsysTerminal_Color_ForegroundWhite;
- } else if (args[i] == "--bold") {
+ } else if (arg == "--bold") {
color |= cmsysTerminal_Color_ForegroundBold;
- } else if (args[i] == "--no-newline") {
+ } else if (arg == "--no-newline") {
newline = false;
- } else if (args[i] == "--newline") {
+ } else if (arg == "--newline") {
newline = true;
} else {
// Color is enabled. Print with the current color.
- cmSystemTools::MakefileColorEcho(color, args[i].c_str(), newline,
- enabled);
+ cmSystemTools::MakefileColorEcho(color, arg.c_str(), newline, enabled);
}
}
return 0;
}
-int cmcmd::ExecuteLinkScript(std::vector<std::string>& args)
+int cmcmd::ExecuteLinkScript(std::vector<std::string> const& args)
{
// The arguments are
- // argv[0] == <cmake-executable>
- // argv[1] == cmake_link_script
- // argv[2] == <link-script-name>
- // argv[3] == --verbose=?
+ // args[0] == <cmake-executable>
+ // args[1] == cmake_link_script
+ // args[2] == <link-script-name>
+ // args[3] == --verbose=?
bool verbose = false;
if (args.size() >= 4) {
if (args[3].find("--verbose=") == 0) {
- if (!cmSystemTools::IsOff(args[3].substr(10).c_str())) {
+ if (!cmSystemTools::IsOff(args[3].substr(10))) {
verbose = true;
}
}
@@ -1277,7 +1490,7 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string>& args)
}
// Setup this command line.
- const char* cmd[2] = { command.c_str(), CM_NULLPTR };
+ const char* cmd[2] = { command.c_str(), nullptr };
cmsysProcess_SetCommand(cp, cmd);
// Report the command if verbose output is enabled.
@@ -1287,7 +1500,7 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string>& args)
// Run the command and wait for it to exit.
cmsysProcess_Execute(cp);
- cmsysProcess_WaitForExit(cp, CM_NULLPTR);
+ cmsysProcess_WaitForExit(cp, nullptr);
// Report failure if any.
switch (cmsysProcess_GetState(cp)) {
@@ -1309,7 +1522,7 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string>& args)
break;
default:
break;
- };
+ }
}
// Free the process instance.
@@ -1353,6 +1566,8 @@ class cmVSLink
std::string ManifestFileRC;
std::string ManifestFileRes;
std::string TargetFile;
+ std::string MtPath;
+ std::string RcPath;
public:
cmVSLink(int type, bool verbose)
@@ -1375,24 +1590,32 @@ private:
// 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)
+int cmcmd::VisualStudioLink(std::vector<std::string> const& args, int type)
{
+#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
+ // Replace streambuf so we output in the system codepage. CMake is set up
+ // to output in Unicode (see SetUTF8Pipes) but the Visual Studio linker
+ // outputs using the system codepage so we need to change behavior when
+ // we run the link command.
+ cmsys::ConsoleBuf::Manager consoleOut(std::cout);
+ cmsys::ConsoleBuf::Manager consoleErr(std::cerr, true);
+#endif
+
if (args.size() < 2) {
return -1;
}
const bool verbose = cmSystemTools::HasEnv("VERBOSE");
std::vector<std::string> expandedArgs;
- for (std::vector<std::string>::iterator i = args.begin(); i != args.end();
- ++i) {
+ for (std::string const& i : args) {
// check for nmake temporary files
- if ((*i)[0] == '@' && i->find("@CMakeFiles") != 0) {
- cmsys::ifstream fin(i->substr(1).c_str());
+ 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);
+ expandedArgs.push_back(i);
}
}
@@ -1403,8 +1626,38 @@ int cmcmd::VisualStudioLink(std::vector<std::string>& args, int type)
return vsLink.Link();
}
-static bool RunCommand(const char* comment, std::vector<std::string>& command,
- bool verbose, int* retCodeOut = CM_NULLPTR)
+enum NumberFormat
+{
+ FORMAT_DECIMAL,
+ FORMAT_HEX
+};
+struct NumberFormatter
+{
+ NumberFormat Format;
+ int Value;
+ NumberFormatter(NumberFormat format, int value)
+ : Format(format)
+ , Value(value)
+ {
+ }
+};
+std::ostream& operator<<(std::ostream& stream,
+ NumberFormatter const& formatter)
+{
+ auto const& flags = stream.flags();
+ if (formatter.Format == FORMAT_DECIMAL) {
+ stream << std::dec << formatter.Value;
+ } else {
+ stream << "0x" << std::hex << formatter.Value;
+ }
+ stream.flags(flags);
+ return stream;
+}
+
+static bool RunCommand(const char* comment,
+ std::vector<std::string> const& command, bool verbose,
+ NumberFormat exitFormat, int* retCodeOut = nullptr,
+ bool (*retCodeOkay)(int) = nullptr)
{
if (verbose) {
std::cout << comment << ":\n";
@@ -1412,32 +1665,32 @@ static bool RunCommand(const char* comment, std::vector<std::string>& command,
}
std::string output;
int retCode = 0;
- // use rc command to create .res file
- bool res =
- cmSystemTools::RunSingleCommand(command, &output, &output, &retCode,
- CM_NULLPTR, 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") == std::string::npos || !res ||
- retCode) {
- std::cout << output;
- }
- if (!res) {
- std::cout << comment << " failed to run." << std::endl;
- return false;
- }
- // if retCodeOut is requested then always return true
- // and set the retCodeOut to retCode
+ bool commandResult = cmSystemTools::RunSingleCommand(
+ command, &output, &output, &retCode, nullptr, cmSystemTools::OUTPUT_NONE);
+ bool const retCodeSuccess =
+ retCode == 0 || (retCodeOkay && retCodeOkay(retCode));
+ bool const success = commandResult && retCodeSuccess;
if (retCodeOut) {
- *retCodeOut = retCode;
- return true;
+ if (commandResult || !retCodeSuccess) {
+ *retCodeOut = retCode;
+ } else {
+ *retCodeOut = -1;
+ }
}
- if (retCode != 0) {
- std::cout << comment << " failed. with " << retCode << "\n";
+ if (!success) {
+ std::cout << comment << ": command \"" << cmJoin(command, " ")
+ << "\" failed (exit code "
+ << NumberFormatter(exitFormat, retCode)
+ << ") with the following output:\n"
+ << output;
+ } else {
+ // always print the output of the command, unless
+ // it is the dumb rc command banner
+ if (output.find("Resource Compiler Version") == std::string::npos) {
+ std::cout << output;
+ }
}
- return retCode == 0;
+ return success;
}
bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
@@ -1458,6 +1711,12 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
} else if (cmHasLiteralPrefix(*arg, "--intdir=")) {
intDir = arg->substr(9);
++arg;
+ } else if (cmHasLiteralPrefix(*arg, "--rc=")) {
+ this->RcPath = arg->substr(5);
+ ++arg;
+ } else if (cmHasLiteralPrefix(*arg, "--mt=")) {
+ this->MtPath = arg->substr(5);
+ ++arg;
} else {
std::cerr << "unknown argument '" << *arg << "'\n";
return false;
@@ -1509,7 +1768,7 @@ bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
}
if (this->LinkGeneratesManifest) {
- this->LinkCommand.push_back("/MANIFEST");
+ this->LinkCommand.emplace_back("/MANIFEST");
this->LinkCommand.push_back("/MANIFESTFILE:" + this->LinkerManifestFile);
}
@@ -1535,6 +1794,13 @@ int cmVSLink::Link()
return LinkNonIncremental();
}
+static bool mtRetIsUpdate(int mtRet)
+{
+ // 'mt /notify_update' returns a special value (differing between
+ // Windows and POSIX hosts) when it updated the manifest file.
+ return mtRet == 0x41020001 || mtRet == 0xbb;
+}
+
int cmVSLink::LinkIncremental()
{
// This follows the steps listed here:
@@ -1571,8 +1837,11 @@ int cmVSLink::LinkIncremental()
if (!fout) {
return -1;
}
- fout << this->Type << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ "
- "24 /* RT_MANIFEST */ \""
+ // Insert a pragma statement to specify utf-8 encoding.
+ fout << "#pragma code_page(65001)\n";
+ fout << this->Type
+ << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ "
+ "24 /* RT_MANIFEST */ \""
<< absManifestFile << "\"";
}
@@ -1587,10 +1856,11 @@ int cmVSLink::LinkIncremental()
// Compile the resource file.
std::vector<std::string> rcCommand;
- rcCommand.push_back(cmSystemTools::FindProgram("rc.exe"));
- rcCommand.push_back("/fo" + this->ManifestFileRes);
+ rcCommand.push_back(this->RcPath.empty() ? "rc" : this->RcPath);
+ rcCommand.emplace_back("/fo");
+ rcCommand.push_back(this->ManifestFileRes);
rcCommand.push_back(this->ManifestFileRC);
- if (!RunCommand("RC Pass 1", rcCommand, this->Verbose)) {
+ if (!RunCommand("RC Pass 1", rcCommand, this->Verbose, FORMAT_DECIMAL)) {
return -1;
}
@@ -1598,26 +1868,28 @@ int cmVSLink::LinkIncremental()
this->LinkCommand.push_back(this->ManifestFileRes);
// Run the link command (possibly generates intermediate manifest).
- if (!RunCommand("LINK Pass 1", this->LinkCommand, this->Verbose)) {
+ if (!RunCommand("LINK Pass 1", this->LinkCommand, this->Verbose,
+ FORMAT_DECIMAL)) {
return -1;
}
// Run the manifest tool to create the final manifest.
int mtRet = this->RunMT("/out:" + this->ManifestFile, true);
- // If mt returns 1090650113 (or 187 on a posix host) then it updated the
- // manifest file so we need to embed it again. Otherwise we are done.
- if (mtRet != 1090650113 && mtRet != 187) {
+ // If mt returns a special value then it updated the manifest file so
+ // we need to embed it again. Otherwise we are done.
+ if (!mtRetIsUpdate(mtRet)) {
return mtRet;
}
// Compile the resource file again.
- if (!RunCommand("RC Pass 2", rcCommand, this->Verbose)) {
+ if (!RunCommand("RC Pass 2", rcCommand, this->Verbose, FORMAT_DECIMAL)) {
return -1;
}
// Link incrementally again to use the updated resource.
- if (!RunCommand("FINAL LINK", this->LinkCommand, this->Verbose)) {
+ if (!RunCommand("FINAL LINK", this->LinkCommand, this->Verbose,
+ FORMAT_DECIMAL)) {
return -1;
}
return 0;
@@ -1626,7 +1898,7 @@ int cmVSLink::LinkIncremental()
int cmVSLink::LinkNonIncremental()
{
// Run the link command (possibly generates intermediate manifest).
- if (!RunCommand("LINK", this->LinkCommand, this->Verbose)) {
+ if (!RunCommand("LINK", this->LinkCommand, this->Verbose, FORMAT_DECIMAL)) {
return -1;
}
@@ -1644,22 +1916,22 @@ int cmVSLink::LinkNonIncremental()
int cmVSLink::RunMT(std::string const& out, bool notify)
{
std::vector<std::string> mtCommand;
- mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
- mtCommand.push_back("/nologo");
- mtCommand.push_back("/manifest");
+ mtCommand.push_back(this->MtPath.empty() ? "mt" : this->MtPath);
+ mtCommand.emplace_back("/nologo");
+ mtCommand.emplace_back("/manifest");
if (this->LinkGeneratesManifest) {
mtCommand.push_back(this->LinkerManifestFile);
}
- mtCommand.insert(mtCommand.end(), this->UserManifests.begin(),
- this->UserManifests.end());
+ cmAppend(mtCommand, this->UserManifests);
mtCommand.push_back(out);
if (notify) {
// Add an undocumented option that enables a special return
// code to notify us when the manifest is modified.
- mtCommand.push_back("/notify_update");
+ mtCommand.emplace_back("/notify_update");
}
int mtRet = 0;
- if (!RunCommand("MT", mtCommand, this->Verbose, &mtRet)) {
+ if (!RunCommand("MT", mtCommand, this->Verbose, FORMAT_HEX, &mtRet,
+ mtRetIsUpdate)) {
return -1;
}
return mtRet;
diff --git a/Source/cmcmd.h b/Source/cmcmd.h
index 929f1ae47..69a7ecbb1 100644
--- a/Source/cmcmd.h
+++ b/Source/cmcmd.h
@@ -4,6 +4,7 @@
#define cmcmd_h
#include "cmConfigure.h" // IWYU pragma: keep
+#include "cmCryptoHash.h"
#include <string>
#include <vector>
@@ -15,18 +16,21 @@ public:
* Execute commands during the build process. Supports options such
* as echo, remove file etc.
*/
- static int ExecuteCMakeCommand(std::vector<std::string>&);
+ static int ExecuteCMakeCommand(std::vector<std::string> const&);
protected:
- static int SymlinkLibrary(std::vector<std::string>& args);
- static int SymlinkExecutable(std::vector<std::string>& args);
+ static int HandleCoCompileCommands(std::vector<std::string> const& args);
+ static int HashSumFile(std::vector<std::string> const& args,
+ cmCryptoHash::Algo algo);
+ static int SymlinkLibrary(std::vector<std::string> const& args);
+ static int SymlinkExecutable(std::vector<std::string> const& 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 ExecuteEchoColor(std::vector<std::string> const& args);
+ static int ExecuteLinkScript(std::vector<std::string> const& args);
static int WindowsCEEnvironment(const char* version,
const std::string& name);
- static int VisualStudioLink(std::vector<std::string>& args, int type);
+ static int VisualStudioLink(std::vector<std::string> const& args, int type);
};
#endif
diff --git a/Source/ctest.cxx b/Source/ctest.cxx
index 84e815d1d..3b3630fc9 100644
--- a/Source/ctest.cxx
+++ b/Source/ctest.cxx
@@ -1,6 +1,5 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
-#include "cmConfigure.h"
#include "CTest/cmCTestLaunch.h"
#include "CTest/cmCTestScriptHandler.h"
@@ -10,7 +9,7 @@
#include "cmsys/Encoding.hxx"
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
-#include "cmsys/ConsoleBuf.hxx"
+# include "cmsys/ConsoleBuf.hxx"
#endif
#include <iostream>
#include <string.h>
@@ -18,71 +17,93 @@
#include <vector>
static const char* cmDocumentationName[][2] = {
- { CM_NULLPTR, " ctest - Testing driver provided by CMake." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, " ctest - Testing driver provided by CMake." },
+ { nullptr, nullptr }
};
-static const char* cmDocumentationUsage[][2] = { { CM_NULLPTR,
+static const char* cmDocumentationUsage[][2] = { { nullptr,
" ctest [options]" },
- { CM_NULLPTR, CM_NULLPTR } };
+ { nullptr, nullptr } };
static const char* cmDocumentationOptions[][2] = {
{ "-C <cfg>, --build-config <cfg>", "Choose configuration to test." },
+ { "--progress", "Enable short progress output from tests." },
{ "-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." },
- { "--test-output-size-passed <size>", "Limit the output for passed tests "
- "to <size> bytes" },
- { "--test-output-size-failed <size>", "Limit the output for failed tests "
- "to <size> bytes" },
+ { "--output-on-failure",
+ "Output anything outputted by the test program "
+ "if the test should fail." },
+ { "--test-output-size-passed <size>",
+ "Limit the output for passed tests "
+ "to <size> bytes" },
+ { "--test-output-size-failed <size>",
+ "Limit the output for failed tests "
+ "to <size> bytes" },
{ "-F", "Enable failover." },
- { "-j <jobs>, --parallel <jobs>", "Run the tests in parallel using the "
- "given number of jobs." },
+ { "-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." },
- { "-FA <regex>, --fixture-exclude-any <regex>", "Do not automatically "
- "add any tests for "
- "fixtures matching "
- "regular expression." },
- { "-FS <regex>, --fixture-exclude-setup <regex>", "Do not automatically "
- "add setup tests for "
- "fixtures matching "
- "regular expression." },
- { "-FC <regex>, --fixture-exclude-cleanup <regex>", "Do not automatically "
- "add cleanup tests for "
- "fixtures matching "
- "regular expression." },
+ { "-N,--show-only[=format]",
+ "Disable actual execution of tests. The optional 'format' defines the "
+ "format of the test information and can be 'human' for the current text "
+ "format or 'json-v1' for json format. Defaults to 'human'." },
+ { "-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." },
+ { "-FA <regex>, --fixture-exclude-any <regex>",
+ "Do not automatically "
+ "add any tests for "
+ "fixtures matching "
+ "regular expression." },
+ { "-FS <regex>, --fixture-exclude-setup <regex>",
+ "Do not automatically "
+ "add setup tests for "
+ "fixtures matching "
+ "regular expression." },
+ { "-FC <regex>, --fixture-exclude-cleanup <regex>",
+ "Do not automatically "
+ "add cleanup tests for "
+ "fixtures 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" },
+ { "-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" },
+ { "-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" },
- { "--repeat-until-fail <n>", "Require each test to run <n> "
- "times without failing in order to pass" },
+ { "--repeat-until-fail <n>",
+ "Require each test to run <n> "
+ "times without failing in order to pass" },
{ "--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." },
+ { "--no-subproject-summary",
+ "Disable timing summary information for "
+ "subprojects." },
{ "--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." },
@@ -103,8 +124,6 @@ static const char* cmDocumentationOptions[][2] = {
{ "--test-timeout", "The time limit in seconds, internal use only." },
{ "--test-load", "CPU load threshold for starting new parallel tests." },
{ "--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",
@@ -112,18 +131,19 @@ static const char* cmDocumentationOptions[][2] = {
{ "--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." },
+ { "--timeout <seconds>", "Set the default test timeout." },
{ "--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." },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, nullptr }
};
// this is a test driver program for cmCTest.
int main(int argc, char const* const* argv)
{
+ cmSystemTools::EnsureStdPipes();
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
// Replace streambuf so we can output Unicode to console
cmsys::ConsoleBuf::Manager consoleOut(std::cout);
@@ -138,6 +158,7 @@ int main(int argc, char const* const* argv)
cmSystemTools::DoNotInheritStdPipes();
cmSystemTools::EnableMSVCDebugHook();
+ cmSystemTools::InitializeLibUV();
cmSystemTools::FindCMakeResources(argv[0]);
// Dispatch 'ctest --launch' mode directly.
@@ -161,7 +182,8 @@ int main(int argc, char const* const* argv)
!(cmSystemTools::FileExists("CTestTestfile.cmake") ||
cmSystemTools::FileExists("DartTestfile.txt"))) {
if (argc == 1) {
- cmCTestLog(&inst, ERROR_MESSAGE, "*********************************"
+ cmCTestLog(&inst, ERROR_MESSAGE,
+ "*********************************"
<< std::endl
<< "No test configuration file found!" << std::endl
<< "*********************************" << std::endl);
@@ -170,8 +192,7 @@ int main(int argc, char const* const* argv)
doc.addCTestStandardDocSections();
if (doc.CheckOptions(argc, argv)) {
// Construct and print requested documentation.
- cmCTestScriptHandler* ch =
- static_cast<cmCTestScriptHandler*>(inst.GetHandler("script"));
+ cmCTestScriptHandler* ch = inst.GetScriptHandler();
ch->CreateCMake();
doc.SetShowGenerators(false);
@@ -185,8 +206,9 @@ int main(int argc, char const* const* argv)
// copy the args to a vector
std::vector<std::string> args;
+ args.reserve(argc);
for (int i = 0; i < argc; ++i) {
- args.push_back(argv[i]);
+ args.emplace_back(argv[i]);
}
// run ctest
std::string output;
diff --git a/Source/kwsys/Base64.c b/Source/kwsys/Base64.c
index 99f008e59..bf876f2d5 100644
--- a/Source/kwsys/Base64.c
+++ b/Source/kwsys/Base64.c
@@ -6,7 +6,7 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "Base64.h.in"
+# include "Base64.h.in"
#endif
static const unsigned char kwsysBase64EncodeTable[65] =
diff --git a/Source/kwsys/Base64.h.in b/Source/kwsys/Base64.h.in
index 35367574a..729f97297 100644
--- a/Source/kwsys/Base64.h.in
+++ b/Source/kwsys/Base64.h.in
@@ -12,17 +12,17 @@
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
+# 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)
+# 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)
@@ -94,17 +94,17 @@ kwsysEXPORT size_t kwsysBase64_Decode(const unsigned char* input,
/* 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
+# 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/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
index e915b1a80..79e813eef 100644
--- a/Source/kwsys/CMakeLists.txt
+++ b/Source/kwsys/CMakeLists.txt
@@ -20,12 +20,32 @@
# 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.
+# KWSYS_SPLIT_OBJECTS_FROM_INTERFACE
+# = Instead of creating a single ${KWSYS_NAMESPACE} library
+# target, create three separate targets:
+# ${KWSYS_NAMESPACE}
+# - An INTERFACE library only containing usage
+# requirements.
+# ${KWSYS_NAMESPACE}_objects
+# - An OBJECT library for the built kwsys objects.
+# Note: This is omitted from the install rules
+# ${KWSYS_NAMESPACE}_private
+# - An INTERFACE library combining both that is
+# appropriate for use with PRIVATE linking in
+# target_link_libraries. Because of how interface
+# properties propagate, this target is not suitable
+# for use with PUBLIC or INTERFACE linking.
+# KWSYS_ALIAS_TARGET = The name of an alias target to create to the actual target.
#
# Example:
#
# SET(KWSYS_HEADER_ROOT ${PROJECT_BINARY_DIR})
# INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
#
+# KWSYS_CXX_STANDARD = A value for CMAKE_CXX_STANDARD within KWSys.
+# Set to empty string to use no default value.
+# KWSYS_CXX_COMPILE_FEATURES = target_compile_features arguments for KWSys.
+#
# Optional settings to setup install rules are as follows:
#
# KWSYS_INSTALL_BIN_DIR = The installation target directories into
@@ -66,18 +86,17 @@
# any outside mailing list and no documentation of the change will be
# written.
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.1 FATAL_ERROR)
FOREACH(p
- CMP0025 # CMake 3.0, Compiler id for Apple Clang is now AppleClang.
- CMP0048 # CMake 3.0, Let the project command manage version variables.
CMP0056 # CMake 3.2, Honor link flags in try_compile() source-file signature.
CMP0063 # CMake 3.3, Honor visibility properties for all target types.
+ CMP0067 # CMake 3.8, Honor language standard in try_compile source-file signature.
+ CMP0069 # CMake 3.9, INTERPROCEDURAL_OPTIMIZATION is enforced when enabled.
)
IF(POLICY ${p})
CMAKE_POLICY(SET ${p} NEW)
ENDIF()
ENDFOREACH()
-SET(CMAKE_LEGACY_CYGWIN_WIN32 0)
#-----------------------------------------------------------------------------
# If a namespace is not specified, use "kwsys" and enable testing.
@@ -98,6 +117,19 @@ SET_PROPERTY(DIRECTORY
"KWSYS_HEADER(%)=<${KWSYS_NAMESPACE}/%>"
)
+if(KWSYS_CXX_STANDARD)
+ set(CMAKE_CXX_STANDARD "${KWSYS_CXX_STANDARD}")
+elseif(NOT DEFINED CMAKE_CXX_STANDARD AND NOT DEFINED KWSYS_CXX_STANDARD)
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
+ AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
+ AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU"
+ )
+ set(CMAKE_CXX_STANDARD 14)
+ else()
+ set(CMAKE_CXX_STANDARD 11)
+ endif()
+endif()
+
# Select library components.
IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET(KWSYS_ENABLE_C 1)
@@ -147,6 +179,9 @@ ENDIF()
IF(KWSYS_USE_Directory)
SET(KWSYS_USE_Encoding 1)
ENDIF()
+IF(KWSYS_USE_DynamicLoader)
+ SET(KWSYS_USE_Encoding 1)
+ENDIF()
IF(KWSYS_USE_FStream)
SET(KWSYS_USE_Encoding 1)
ENDIF()
@@ -154,13 +189,6 @@ IF(KWSYS_USE_ConsoleBuf)
SET(KWSYS_USE_Encoding 1)
ENDIF()
-# Setup the large file support default.
-IF(KWSYS_LFS_DISABLE)
- SET(KWSYS_LFS_REQUESTED 0)
-ELSE()
- SET(KWSYS_LFS_REQUESTED 1)
-ENDIF()
-
# Specify default 8 bit encoding for Windows
IF(NOT KWSYS_ENCODING_DEFAULT_CODEPAGE)
SET(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_ACP)
@@ -175,6 +203,11 @@ IF(KWSYS_STANDALONE)
ENDIF()
ENDIF()
+# Choose default shared/static build if not specified.
+IF(NOT DEFINED KWSYS_BUILD_SHARED)
+ SET(KWSYS_BUILD_SHARED ${BUILD_SHARED_LIBS})
+ENDIF()
+
# Include helper macros.
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/kwsysPlatformTests.cmake)
INCLUDE(CheckTypeSize)
@@ -209,13 +242,14 @@ ENDIF()
# Setup library install rules.
SET(KWSYS_INSTALL_LIBRARY_RULE)
+SET(KWSYS_INSTALL_NAMELINK_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}
+ LIBRARY DESTINATION ${KWSYS_INSTALL_LIB_DIR} NAMELINK_SKIP
)
# Assign the shared library to the runtime component.
IF(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME)
@@ -223,6 +257,17 @@ IF(KWSYS_INSTALL_LIB_DIR)
COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME}
)
ENDIF()
+ IF(KWSYS_BUILD_SHARED)
+ SET(KWSYS_INSTALL_NAMELINK_RULE ${KWSYS_INSTALL_NAMELINK_RULE}
+ LIBRARY DESTINATION ${KWSYS_INSTALL_LIB_DIR} NAMELINK_ONLY
+ )
+ # Assign the namelink to the development component.
+ IF(KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT)
+ SET(KWSYS_INSTALL_NAMELINK_RULE ${KWSYS_INSTALL_NAMELINK_RULE}
+ COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_DEVELOPMENT}
+ )
+ ENDIF()
+ ENDIF()
# Install the archive to the lib directory.
SET(KWSYS_INSTALL_LIBRARY_RULE ${KWSYS_INSTALL_LIBRARY_RULE}
@@ -311,30 +356,6 @@ IF(KWSYS_STANDALONE)
ENDIF()
#-----------------------------------------------------------------------------
-# 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()
-ELSE()
- # Large File Support is not requested.
- SET(KWSYS_LFS_REQUESTED 0)
-ENDIF()
-
-#-----------------------------------------------------------------------------
# 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.
@@ -406,11 +427,6 @@ ELSE()
SET(KWSYS_NAME_IS_KWSYS 0)
ENDIF()
-# Choose default shared/static build if not specified.
-IF(KWSYS_BUILD_SHARED MATCHES "^KWSYS_BUILD_SHARED$")
- SET(KWSYS_BUILD_SHARED ${BUILD_SHARED_LIBS})
-ENDIF()
-
IF(KWSYS_BUILD_SHARED)
SET(KWSYS_BUILD_SHARED 1)
SET(KWSYS_LIBRARY_TYPE SHARED)
@@ -419,6 +435,10 @@ ELSE()
SET(KWSYS_LIBRARY_TYPE STATIC)
ENDIF()
+if(NOT DEFINED KWSYS_BUILD_PIC)
+ set(KWSYS_BUILD_PIC 0)
+endif()
+
#-----------------------------------------------------------------------------
# Configure some implementation details.
@@ -426,10 +446,20 @@ 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)
+IF(KWSYS_USE_Process)
+ KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
+ "Checking whether C compiler has clock_gettime" DIRECT)
+ENDIF()
+
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}"
+ COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T} -DKWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC=${KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC}"
)
+IF(DEFINED KWSYS_PROCESS_USE_SELECT)
+ GET_PROPERTY(ProcessUNIX_FLAGS SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS)
+ SET_PROPERTY(SOURCE ProcessUNIX.c PROPERTY COMPILE_FLAGS "${ProcessUNIX_FLAGS} -DKWSYSPE_USE_SELECT=${KWSYSPE_USE_SELECT}")
+ENDIF()
+
IF(KWSYS_USE_DynamicLoader)
GET_PROPERTY(KWSYS_SUPPORTS_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
IF(KWSYS_SUPPORTS_SHARED_LIBS)
@@ -442,6 +472,14 @@ IF(KWSYS_USE_DynamicLoader)
ENDIF()
IF(KWSYS_USE_SystemTools)
+ if (NOT DEFINED KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP)
+ set(KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP 1)
+ endif ()
+ if (KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP)
+ set(KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP 1)
+ else ()
+ set(KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP 0)
+ endif ()
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_SETENV
"Checking whether CXX compiler has setenv" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UNSETENV
@@ -465,6 +503,24 @@ IF(KWSYS_USE_SystemTools)
KWSYS_CXX_STAT_HAS_ST_MTIM=${KWSYS_CXX_STAT_HAS_ST_MTIM}
KWSYS_CXX_STAT_HAS_ST_MTIMESPEC=${KWSYS_CXX_STAT_HAS_ST_MTIMESPEC}
)
+ IF(NOT WIN32)
+ IF(KWSYS_STANDALONE)
+ OPTION(KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES "If true, Windows paths will be supported on Unix as well" ON)
+ ENDIF()
+ IF(KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES)
+ SET_PROPERTY(SOURCE SystemTools.cxx testSystemTools.cxx APPEND PROPERTY COMPILE_DEFINITIONS
+ KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES
+ )
+ ENDIF()
+ ENDIF()
+
+ # Disable getpwnam for static linux builds since it depends on shared glibc
+ GET_PROPERTY(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
+ IF(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT SHARED_LIBS_SUPPORTED)
+ SET_PROPERTY(SOURCE SystemTools.cxx APPEND PROPERTY COMPILE_DEFINITIONS
+ HAVE_GETPWNAM=0
+ )
+ ENDIF()
ENDIF()
IF(KWSYS_USE_SystemInformation)
@@ -506,9 +562,6 @@ IF(KWSYS_USE_SystemInformation)
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)
@@ -547,7 +600,7 @@ IF(KWSYS_USE_SystemInformation)
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
+ # 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)
@@ -676,9 +729,13 @@ ENDIF()
# 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
- )
+SET(KWSYS_HXX_FILES Configure String)
+
+IF(NOT CMake_SOURCE_DIR)
+ SET(KWSYS_HXX_FILES ${KWSYS_HXX_FILES}
+ hashtable hash_fun hash_map hash_set
+ )
+ENDIF()
# Add selected C++ classes.
SET(cppclasses
@@ -795,68 +852,158 @@ ENDFOREACH()
#-----------------------------------------------------------------------------
# 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 C_CLANG_TIDY "")
- SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY CXX_CLANG_TIDY "")
- SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY C_INCLUDE_WHAT_YOU_USE "")
- SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "")
- SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY LABELS ${KWSYS_LABELS_LIB})
+ IF(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE)
+ SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE})
+ SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE}_objects)
+ SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE}_private)
+ SET(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_INTERFACE} ${KWSYS_TARGET_LINK})
+ SET(KWSYS_LINK_DEPENDENCY INTERFACE)
+ ADD_LIBRARY(${KWSYS_TARGET_OBJECT} OBJECT
+ ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
+ IF(KWSYS_BUILD_SHARED OR KWSYS_BUILD_PIC)
+ SET_PROPERTY(TARGET ${KWSYS_TARGET_OBJECT} PROPERTY
+ POSITION_INDEPENDENT_CODE TRUE)
+ ENDIF()
+ ADD_LIBRARY(${KWSYS_TARGET_INTERFACE} INTERFACE)
+ ADD_LIBRARY(${KWSYS_TARGET_LINK} INTERFACE)
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_LINK} INTERFACE
+ ${KWSYS_TARGET_INTERFACE})
+ TARGET_SOURCES(${KWSYS_TARGET_LINK} INTERFACE
+ $<TARGET_OBJECTS:${KWSYS_TARGET_OBJECT}>)
+ target_compile_features(${KWSYS_TARGET_OBJECT} PRIVATE ${KWSYS_CXX_COMPILE_FEATURES})
+ target_compile_features(${KWSYS_TARGET_INTERFACE} INTERFACE ${KWSYS_CXX_COMPILE_FEATURES})
+ ELSE()
+ SET(KWSYS_TARGET_INTERFACE ${KWSYS_NAMESPACE})
+ SET(KWSYS_TARGET_OBJECT ${KWSYS_NAMESPACE})
+ SET(KWSYS_TARGET_LINK ${KWSYS_NAMESPACE})
+ set(KWSYS_TARGET_INSTALL ${KWSYS_TARGET_LINK})
+ SET(KWSYS_LINK_DEPENDENCY PUBLIC)
+ ADD_LIBRARY(${KWSYS_TARGET_INTERFACE} ${KWSYS_LIBRARY_TYPE}
+ ${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
+ target_compile_features(${KWSYS_TARGET_INTERFACE} PUBLIC ${KWSYS_CXX_COMPILE_FEATURES})
+ ENDIF()
+ if (KWSYS_ALIAS_TARGET)
+ add_library(${KWSYS_ALIAS_TARGET} ALIAS ${KWSYS_TARGET_INTERFACE})
+ endif ()
+ SET_TARGET_PROPERTIES(${KWSYS_TARGET_OBJECT} PROPERTIES
+ C_CLANG_TIDY ""
+ CXX_CLANG_TIDY ""
+ C_INCLUDE_WHAT_YOU_USE ""
+ CXX_INCLUDE_WHAT_YOU_USE ""
+ LABELS "${KWSYS_LABELS_LIB}")
IF(KWSYS_USE_DynamicLoader)
IF(UNIX)
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY}
+ ${CMAKE_DL_LIBS})
ENDIF()
ENDIF()
IF(KWSYS_USE_SystemInformation)
IF(WIN32)
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32)
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} ws2_32)
+ # link in dbghelp.dll for symbol lookup if MSVC 1800 or later
+ # Note that the dbghelp runtime is part of MS Windows OS
+ IF(MSVC_VERSION AND NOT MSVC_VERSION VERSION_LESS 1800)
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} dbghelp)
+ ENDIF()
IF(KWSYS_SYS_HAS_PSAPI)
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi)
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY}
+ 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})
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY}
+ ${EXECINFO_LIB})
ENDIF()
IF (KWSYS_CXX_HAS_DLADDR)
# for symbol lookup using dladdr
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY}
+ ${CMAKE_DL_LIBS})
ENDIF()
IF (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} socket)
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY}
+ socket)
ENDIF()
ENDIF()
ENDIF()
# Apply user-defined target properties to the library.
IF(KWSYS_PROPERTIES_CXX)
- SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE} PROPERTIES
- ${KWSYS_PROPERTIES_CXX}
- )
+ SET_TARGET_PROPERTIES(${KWSYS_TARGET_INTERFACE} PROPERTIES
+ ${KWSYS_PROPERTIES_CXX})
+ ENDIF()
+
+ # Set up include usage requirement
+ IF(COMMAND TARGET_INCLUDE_DIRECTORIES)
+ TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE
+ $<BUILD_INTERFACE:${KWSYS_HEADER_ROOT}>)
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_INTERFACE} INTERFACE
+ $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>)
+ ENDIF()
ENDIF()
# Create an install target for the library.
IF(KWSYS_INSTALL_LIBRARY_RULE)
- INSTALL(TARGETS ${KWSYS_NAMESPACE} ${KWSYS_INSTALL_LIBRARY_RULE})
+ INSTALL(TARGETS ${KWSYS_TARGET_INSTALL} ${KWSYS_INSTALL_LIBRARY_RULE})
+ ENDIF()
+ IF(KWSYS_INSTALL_NAMELINK_RULE)
+ INSTALL(TARGETS ${KWSYS_TARGET_INSTALL} ${KWSYS_INSTALL_NAMELINK_RULE})
ENDIF()
ENDIF()
# 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})
+ IF(KWSYS_SPLIT_OBJECTS_FROM_INTERFACE)
+ SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c)
+ SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c_objects)
+ SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c_private)
+ SET(KWSYS_TARGET_C_INSTALL
+ ${KWSYS_TARGET_C_INTERFACE} ${KWSYS_TARGET_C_LINK})
+ SET(KWSYS_LINK_DEPENDENCY INTERFACE)
+ ADD_LIBRARY(${KWSYS_TARGET_C_OBJECT} OBJECT ${KWSYS_C_SRCS})
+ IF(KWSYS_BUILD_SHARED OR KWSYS_BUILD_PIC)
+ SET_PROPERTY(TARGET ${KWSYS_TARGET_C_OBJECT} PROPERTY
+ POSITION_INDEPENDENT_CODE TRUE)
+ ENDIF()
+ ADD_LIBRARY(${KWSYS_TARGET_C_INTERFACE} INTERFACE)
+ ADD_LIBRARY(${KWSYS_TARGET_C_LINK} INTERFACE)
+ TARGET_LINK_LIBRARIES(${KWSYS_TARGET_C_LINK} INTERFACE
+ ${KWSYS_TARGET_C_INTERFACE})
+ TARGET_SOURCES(${KWSYS_TARGET_C_LINK} INTERFACE
+ $<TARGET_OBJECTS:${KWSYS_TARGET_C_OBJECT}>)
+ ELSE()
+ SET(KWSYS_TARGET_C_INTERFACE ${KWSYS_NAMESPACE}_c)
+ SET(KWSYS_TARGET_C_OBJECT ${KWSYS_NAMESPACE}_c)
+ SET(KWSYS_TARGET_C_LINK ${KWSYS_NAMESPACE}_c)
+ SET(KWSYS_TARGET_C_INSTALL ${KWSYS_TARGET_C_LINK})
+ SET(KWSYS_LINK_DEPENDENCY PUBLIC)
+ ADD_LIBRARY(${KWSYS_TARGET_C_INTERFACE} ${KWSYS_LIBRARY_TYPE}
+ ${KWSYS_C_SRCS})
+ ENDIF()
+ SET_TARGET_PROPERTIES(${KWSYS_TARGET_C_OBJECT} PROPERTIES
+ LABELS "${KWSYS_LABELS_LIB}")
# Apply user-defined target properties to the library.
IF(KWSYS_PROPERTIES_C)
- SET_TARGET_PROPERTIES(${KWSYS_NAMESPACE}_c PROPERTIES
- ${KWSYS_PROPERTIES_C}
- )
+ SET_TARGET_PROPERTIES(${KWSYS_TARGET_C_INTERFACE} PROPERTIES
+ ${KWSYS_PROPERTIES_C})
+ ENDIF()
+
+ # Set up include usage requirement
+ IF(COMMAND TARGET_INCLUDE_DIRECTORIES)
+ TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE
+ $<BUILD_INTERFACE:${KWSYS_HEADER_ROOT}>)
+ IF(KWSYS_INSTALL_INCLUDE_DIR)
+ TARGET_INCLUDE_DIRECTORIES(${KWSYS_TARGET_C_INTERFACE} INTERFACE
+ $<INSTALL_INTERFACE:${KWSYS_INSTALL_INCLUDE_DIR}>)
+ ENDIF()
ENDIF()
# Create an install target for the library.
IF(KWSYS_INSTALL_LIBRARY_RULE)
- INSTALL(TARGETS ${KWSYS_NAMESPACE}_c ${KWSYS_INSTALL_LIBRARY_RULE})
+ INSTALL(TARGETS ${KWSYS_TARGET_C_INSTALL})
ENDIF()
ENDIF()
@@ -865,7 +1012,8 @@ ENDIF()
ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}")
# Disable deprecation warnings for standard C functions.
-IF(MSVC OR (WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Intel"))
+IF(MSVC OR (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "Intel" OR
+ (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"))))
ADD_DEFINITIONS(
-D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_SECURE_NO_DEPRECATE
@@ -903,11 +1051,11 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
# C tests
SET(KWSYS_C_TESTS
- testEncode
- testTerminal
+ testEncode.c
+ testTerminal.c
)
IF(KWSYS_STANDALONE)
- SET(KWSYS_C_TESTS ${KWSYS_C_TESTS} testFail)
+ SET(KWSYS_C_TESTS ${KWSYS_C_TESTS} testFail.c)
ENDIF()
CREATE_TEST_SOURCELIST(
KWSYS_C_TEST_SRCS ${KWSYS_NAMESPACE}TestsC.c
@@ -915,32 +1063,34 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
)
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})
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsC ${KWSYS_TARGET_C_LINK})
+ FOREACH(testfile ${KWSYS_C_TESTS})
+ get_filename_component(test "${testfile}" NAME_WE)
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()
# C++ tests
- IF(NOT WATCOM)
+ IF(NOT WATCOM AND NOT CMake_SOURCE_DIR)
SET(KWSYS_CXX_TESTS
- testHashSTL
+ testHashSTL.cxx
)
ENDIF()
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
- testIOS
- testSystemTools
- testCommandLineArguments
- testCommandLineArguments1
+ testConfigure.cxx
+ testSystemTools.cxx
+ testCommandLineArguments.cxx
+ testCommandLineArguments1.cxx
+ testDirectory.cxx
)
IF(KWSYS_STL_HAS_WSTRING)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
- testEncoding
+ testEncoding.cxx
)
ENDIF()
IF(KWSYS_USE_FStream)
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
- testFStream
+ testFStream.cxx
)
ENDIF()
IF(KWSYS_USE_ConsoleBuf)
@@ -950,9 +1100,9 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET_PROPERTY(TARGET testConsoleBufChild PROPERTY C_INCLUDE_WHAT_YOU_USE "")
SET_PROPERTY(TARGET testConsoleBufChild PROPERTY CXX_INCLUDE_WHAT_YOU_USE "")
SET_PROPERTY(TARGET testConsoleBufChild PROPERTY LABELS ${KWSYS_LABELS_EXE})
- TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_NAMESPACE})
+ TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_TARGET_LINK})
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
- testConsoleBuf
+ testConsoleBuf.cxx
)
IF("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "19.0.23506")
@@ -962,14 +1112,28 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
KWSYS_ENCODING_DEFAULT_CODEPAGE=${KWSYS_ENCODING_DEFAULT_CODEPAGE})
ENDIF()
IF(KWSYS_USE_SystemInformation)
- SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testSystemInformation)
+ SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testSystemInformation.cxx)
ENDIF()
IF(KWSYS_USE_DynamicLoader)
- SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testDynamicLoader)
+ SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS} testDynamicLoader.cxx)
# 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})
+ ADD_DEPENDENCIES(${KWSYS_NAMESPACE}TestDynload ${KWSYS_TARGET_INTERFACE})
+
+ if (WIN32)
+ # Windows tests supported flags.
+ add_library(${KWSYS_NAMESPACE}TestDynloadImpl SHARED testDynloadImpl.c)
+ set_property(TARGET ${KWSYS_NAMESPACE}TestDynloadImpl PROPERTY LABELS ${KWSYS_LABELS_LIB})
+ set_property(TARGET ${KWSYS_NAMESPACE}TestDynloadImpl PROPERTY DEFINE_SYMBOL BUILDING_TestDynloadImpl)
+ set_property(TARGET ${KWSYS_NAMESPACE}TestDynloadImpl PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynloaddir")
+ add_dependencies(${KWSYS_NAMESPACE}TestDynloadImpl ${KWSYS_TARGET_INTERFACE})
+ add_library(${KWSYS_NAMESPACE}TestDynloadUse MODULE testDynloadUse.c)
+ set_property(TARGET ${KWSYS_NAMESPACE}TestDynloadUse PROPERTY LABELS ${KWSYS_LABELS_LIB})
+ set_property(TARGET ${KWSYS_NAMESPACE}TestDynloadUse PROPERTY LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dynloaddir")
+ add_dependencies(${KWSYS_NAMESPACE}TestDynloadUse ${KWSYS_TARGET_INTERFACE})
+ target_link_libraries(${KWSYS_NAMESPACE}TestDynloadUse PRIVATE ${KWSYS_NAMESPACE}TestDynloadImpl)
+ endif ()
ENDIF()
CREATE_TEST_SOURCELIST(
KWSYS_CXX_TEST_SRCS ${KWSYS_NAMESPACE}TestsCxx.cxx
@@ -981,7 +1145,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY C_INCLUDE_WHAT_YOU_USE "")
SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY CXX_INCLUDE_WHAT_YOU_USE "")
SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE})
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_NAMESPACE})
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_TARGET_LINK})
SET(TEST_SYSTEMTOOLS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
SET(TEST_SYSTEMTOOLS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
@@ -1024,7 +1188,8 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
-p
some junk at the end
)
- FOREACH(test ${KWSYS_CXX_TESTS})
+ FOREACH(testfile ${KWSYS_CXX_TESTS})
+ get_filename_component(test "${testfile}" NAME_WE)
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()
@@ -1032,7 +1197,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
# 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)
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestProcess ${KWSYS_TARGET_C_LINK})
IF(NOT CYGWIN)
SET(KWSYS_TEST_PROCESS_7 7)
ENDIF()
@@ -1042,17 +1207,26 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
SET_TESTS_PROPERTIES(kwsys.testProcess-${n} PROPERTIES TIMEOUT 120)
ENDFOREACH()
+ SET(testProcess_COMPILE_FLAGS "")
# 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" AND
- NOT (CMAKE_SYSTEM MATCHES "Linux.*ppc64le" AND
- NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13.1.1"))
+ SET(testProcess_COMPILE_FLAGS "${testProcess_COMPILE_FLAGS} -O0")
+ ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "XL")
# Tell IBM XL not to warn about our test infinite loop
- # v13.1.1 and newer on Linux ppc64le is clang based and does not accept
- # the -qsuppress option
- SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS -qsuppress=1500-010)
+ IF(CMAKE_SYSTEM MATCHES "Linux.*ppc64le"
+ AND CMAKE_C_COMPILER_VERSION VERSION_LESS "16.1.0"
+ AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13.1.1")
+ # v13.1.[1-6] on Linux ppc64le is clang based and does not accept
+ # the -qsuppress option, so just suppress all warnings.
+ SET(testProcess_COMPILE_FLAGS "${testProcess_COMPILE_FLAGS} -w")
+ ELSE()
+ SET(testProcess_COMPILE_FLAGS "${testProcess_COMPILE_FLAGS} -qsuppress=1500-010")
+ ENDIF()
+ ENDIF()
+ IF(CMAKE_C_FLAGS MATCHES "-fsanitize=")
+ SET(testProcess_COMPILE_FLAGS "${testProcess_COMPILE_FLAGS} -DCRASH_USING_ABORT")
ENDIF()
+ SET_PROPERTY(SOURCE testProcess.c PROPERTY COMPILE_FLAGS "${testProcess_COMPILE_FLAGS}")
# Test SharedForward
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/testSharedForward.c.in
@@ -1060,7 +1234,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
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_DEPENDENCIES(${KWSYS_NAMESPACE}TestSharedForward ${KWSYS_TARGET_C_LINK})
ADD_TEST(kwsys.testSharedForward ${EXEC_DIR}/${KWSYS_NAMESPACE}TestSharedForward 1)
SET_PROPERTY(TEST kwsys.testSharedForward PROPERTY LABELS ${KWSYS_LABELS_TEST})
diff --git a/Source/kwsys/CONTRIBUTING.rst b/Source/kwsys/CONTRIBUTING.rst
index 70a313e05..32e7b83c5 100644
--- a/Source/kwsys/CONTRIBUTING.rst
+++ b/Source/kwsys/CONTRIBUTING.rst
@@ -27,7 +27,7 @@ copies of KWSys within dependent projects can be updated to get the changes.
Code Style
==========
-We use `clang-format`_ version **3.8** to define our style for C++ code in
+We use `clang-format`_ version **6.0** to define our style for C++ code in
the KWSys source tree. See the `.clang-format`_ configuration file for
our style settings. Use the `clang-format.bash`_ script to format source
code. It automatically runs ``clang-format`` on the set of source files
diff --git a/Source/kwsys/CommandLineArguments.cxx b/Source/kwsys/CommandLineArguments.cxx
index 5613bd7ab..a97f7a836 100644
--- a/Source/kwsys/CommandLineArguments.cxx
+++ b/Source/kwsys/CommandLineArguments.cxx
@@ -9,9 +9,9 @@
// 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 "String.hxx.in"
+# include "CommandLineArguments.hxx.in"
+# include "Configure.hxx.in"
+# include "String.hxx.in"
#endif
#include <iostream>
@@ -25,18 +25,18 @@
#include <string.h>
#ifdef _MSC_VER
-#pragma warning(disable : 4786)
+# pragma warning(disable : 4786)
#endif
#if defined(__sgi) && !defined(__GNUC__)
-#pragma set woff 1375 /* base class destructor not virtual */
+# pragma set woff 1375 /* base class destructor not virtual */
#endif
#if 0
-#define CommandLineArguments_DEBUG(x) \
- std::cout << __LINE__ << " CLA: " << x << std::endl
+# define CommandLineArguments_DEBUG(x) \
+ std::cout << __LINE__ << " CLA: " << x << std::endl
#else
-#define CommandLineArguments_DEBUG(x)
+# define CommandLineArguments_DEBUG(x)
#endif
namespace KWSYS_NAMESPACE {
@@ -68,8 +68,8 @@ class CommandLineArgumentsInternal
public:
CommandLineArgumentsInternal()
{
- this->UnknownArgumentCallback = 0;
- this->ClientData = 0;
+ this->UnknownArgumentCallback = KWSYS_NULLPTR;
+ this->ClientData = KWSYS_NULLPTR;
this->LastArgument = 0;
}
@@ -187,7 +187,7 @@ int CommandLineArguments::Parse()
switch (cs->ArgumentType) {
case NO_ARGUMENT:
// No value
- if (!this->PopulateVariable(cs, 0)) {
+ if (!this->PopulateVariable(cs, KWSYS_NULLPTR)) {
return 0;
}
break;
@@ -340,7 +340,7 @@ void CommandLineArguments::AddCallback(const char* argument,
s.Callback = callback;
s.CallData = call_data;
s.VariableType = CommandLineArguments::NO_VARIABLE_TYPE;
- s.Variable = 0;
+ s.Variable = KWSYS_NULLPTR;
s.Help = help;
this->Internals->Callbacks[argument] = s;
@@ -355,8 +355,8 @@ void CommandLineArguments::AddArgument(const char* argument,
CommandLineArgumentsCallbackStructure s;
s.Argument = argument;
s.ArgumentType = type;
- s.Callback = 0;
- s.CallData = 0;
+ s.Callback = KWSYS_NULLPTR;
+ s.CallData = KWSYS_NULLPTR;
s.VariableType = vtype;
s.Variable = variable;
s.Help = help;
@@ -427,7 +427,7 @@ 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;
+ return KWSYS_NULLPTR;
}
// Since several arguments may point to the same argument, find the one this
@@ -529,10 +529,7 @@ void CommandLineArguments::GenerateHelp()
}
}
- // Create format for that string
- char format[80];
- sprintf(format, " %%-%us ", static_cast<unsigned int>(maxlen));
-
+ CommandLineArguments::Internal::String::size_type maxstrlen = maxlen;
maxlen += 4; // For the space before and after the option
// Print help for each option
@@ -540,27 +537,24 @@ void CommandLineArguments::GenerateHelp()
CommandLineArguments::Internal::SetOfStrings::iterator sit;
for (sit = mpit->second.begin(); sit != mpit->second.end(); sit++) {
str << std::endl;
- char argument[100];
- sprintf(argument, "%s", sit->c_str());
+ std::string argument = *sit;
switch (this->Internals->Callbacks[*sit].ArgumentType) {
case CommandLineArguments::NO_ARGUMENT:
break;
case CommandLineArguments::CONCAT_ARGUMENT:
- strcat(argument, "opt");
+ argument += "opt";
break;
case CommandLineArguments::SPACE_ARGUMENT:
- strcat(argument, " opt");
+ argument += " opt";
break;
case CommandLineArguments::EQUAL_ARGUMENT:
- strcat(argument, "=opt");
+ argument += "=opt";
break;
case CommandLineArguments::MULTI_ARGUMENT:
- strcat(argument, " opt opt ...");
+ argument += " opt opt ...";
break;
}
- char buffer[80];
- sprintf(buffer, format, argument);
- str << buffer;
+ str << " " << argument.substr(0, maxstrlen) << " ";
}
const char* ptr = this->Internals->Callbacks[mpit->first].Help;
size_t len = strlen(ptr);
@@ -627,7 +621,7 @@ void CommandLineArguments::PopulateVariable(bool* variable,
void CommandLineArguments::PopulateVariable(int* variable,
const std::string& value)
{
- char* res = 0;
+ char* res = KWSYS_NULLPTR;
*variable = static_cast<int>(strtol(value.c_str(), &res, 10));
// if ( res && *res )
// {
@@ -638,7 +632,7 @@ void CommandLineArguments::PopulateVariable(int* variable,
void CommandLineArguments::PopulateVariable(double* variable,
const std::string& value)
{
- char* res = 0;
+ char* res = KWSYS_NULLPTR;
*variable = strtod(value.c_str(), &res);
// if ( res && *res )
// {
@@ -649,10 +643,7 @@ void CommandLineArguments::PopulateVariable(double* variable,
void CommandLineArguments::PopulateVariable(char** variable,
const std::string& value)
{
- if (*variable) {
- delete[] * variable;
- *variable = 0;
- }
+ delete[] * variable;
*variable = new char[value.size() + 1];
strcpy(*variable, value.c_str());
}
@@ -678,7 +669,7 @@ void CommandLineArguments::PopulateVariable(std::vector<bool>* variable,
void CommandLineArguments::PopulateVariable(std::vector<int>* variable,
const std::string& value)
{
- char* res = 0;
+ char* res = KWSYS_NULLPTR;
variable->push_back(static_cast<int>(strtol(value.c_str(), &res, 10)));
// if ( res && *res )
// {
@@ -689,7 +680,7 @@ void CommandLineArguments::PopulateVariable(std::vector<int>* variable,
void CommandLineArguments::PopulateVariable(std::vector<double>* variable,
const std::string& value)
{
- char* res = 0;
+ char* res = KWSYS_NULLPTR;
variable->push_back(strtod(value.c_str(), &res));
// if ( res && *res )
// {
diff --git a/Source/kwsys/CommandLineArguments.hxx.in b/Source/kwsys/CommandLineArguments.hxx.in
index 31115e51f..7db901556 100644
--- a/Source/kwsys/CommandLineArguments.hxx.in
+++ b/Source/kwsys/CommandLineArguments.hxx.in
@@ -62,6 +62,9 @@ public:
CommandLineArguments();
~CommandLineArguments();
+ CommandLineArguments(const CommandLineArguments&) = delete;
+ CommandLineArguments& operator=(const CommandLineArguments&) = delete;
+
/**
* Various argument types.
*/
diff --git a/Source/kwsys/Configure.h.in b/Source/kwsys/Configure.h.in
index 0afcae781..5323c57be 100644
--- a/Source/kwsys/Configure.h.in
+++ b/Source/kwsys/Configure.h.in
@@ -7,110 +7,72 @@
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
+# 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
+# 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)
+# 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 __declspec(dllimport)
-#endif
-#elif __GNUC__ >= 4
-#define @KWSYS_NAMESPACE@_EXPORT __attribute__((visibility("default")))
-#else
-#define @KWSYS_NAMESPACE@_EXPORT
-#endif
-#else
-#define @KWSYS_NAMESPACE@_EXPORT
+# 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
+# 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
-#if defined(__BORLANDC__) && !defined(__cplusplus)
+# 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
+# if defined(__BORLANDC__) && !defined(__cplusplus)
/* Code has no effect; raised by winnt.h in C (not C++) when ignoring an
unused parameter using "(param)" syntax (i.e. no cast to void). */
-#pragma warn - 8019
-#endif
+# pragma warn - 8019
+# endif
#endif
/* MSVC 6.0 in release mode will warn about code it produces with its
@@ -118,10 +80,10 @@
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
+# 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
index 1c07a4ef7..92ffea3c9 100644
--- a/Source/kwsys/Configure.hxx.in
+++ b/Source/kwsys/Configure.hxx.in
@@ -11,17 +11,56 @@
/* Whether <ext/stdio_filebuf.h> is available. */
#define @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H \
@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@
+/* Whether the translation map is available or not. */
+#define @KWSYS_NAMESPACE@_SYSTEMTOOLS_USE_TRANSLATION_MAP \
+ @KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP@
+
+#if defined(__SUNPRO_CC) && __SUNPRO_CC > 0x5130 && defined(__has_attribute)
+# define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_attribute(x)
+#elif defined(__has_cpp_attribute)
+# define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_cpp_attribute(x)
+#else
+# define @KWSYS_NAMESPACE@__has_cpp_attribute(x) 0
+#endif
+
+#if __cplusplus >= 201103L
+# define @KWSYS_NAMESPACE@_NULLPTR nullptr
+#else
+# define @KWSYS_NAMESPACE@_NULLPTR 0
+#endif
+
+#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
+# if __cplusplus >= 201703L && \
+ @KWSYS_NAMESPACE@__has_cpp_attribute(fallthrough)
+# define @KWSYS_NAMESPACE@_FALLTHROUGH [[fallthrough]]
+# elif __cplusplus >= 201103L && \
+ @KWSYS_NAMESPACE@__has_cpp_attribute(gnu::fallthrough)
+# define @KWSYS_NAMESPACE@_FALLTHROUGH [[gnu::fallthrough]]
+# elif __cplusplus >= 201103L && \
+ @KWSYS_NAMESPACE@__has_cpp_attribute(clang::fallthrough)
+# define @KWSYS_NAMESPACE@_FALLTHROUGH [[clang::fallthrough]]
+# endif
+#endif
+#ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
+# define @KWSYS_NAMESPACE@_FALLTHROUGH static_cast<void>(0)
+#endif
+
+#undef @KWSYS_NAMESPACE@__has_cpp_attribute
/* 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 @KWSYS_NAMESPACE@
-#endif
-#define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS
-#define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
-#define KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H \
- @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
+# if !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define kwsys @KWSYS_NAMESPACE@
+# endif
+# define KWSYS_NAME_IS_KWSYS @KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# define KWSYS_STL_HAS_WSTRING @KWSYS_NAMESPACE@_STL_HAS_WSTRING
+# define KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H \
+ @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
+# define KWSYS_FALLTHROUGH @KWSYS_NAMESPACE@_FALLTHROUGH
+# define KWSYS_NULLPTR @KWSYS_NAMESPACE@_NULLPTR
+# define KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP \
+ @KWSYS_NAMESPACE@_SYSTEMTOOLS_USE_TRANSLATION_MAP
#endif
#endif
diff --git a/Source/kwsys/ConsoleBuf.hxx.in b/Source/kwsys/ConsoleBuf.hxx.in
index 46d65a865..73a1efb25 100644
--- a/Source/kwsys/ConsoleBuf.hxx.in
+++ b/Source/kwsys/ConsoleBuf.hxx.in
@@ -15,10 +15,10 @@
#include <string>
#if defined(_WIN32)
-#include <windows.h>
-#if __cplusplus >= 201103L
-#include <system_error>
-#endif
+# include <windows.h>
+# if __cplusplus >= 201103L
+# include <system_error>
+# endif
#endif
namespace @KWSYS_NAMESPACE@ {
@@ -231,12 +231,12 @@ private:
(!input && m_hOutput == INVALID_HANDLE_VALUE)) {
std::string errmsg =
"GetStdHandle(" + handleName + ") returned INVALID_HANDLE_VALUE";
-#if __cplusplus >= 201103L
+# if __cplusplus >= 201103L
throw std::system_error(::GetLastError(), std::system_category(),
errmsg);
-#else
+# else
throw std::runtime_error(errmsg);
-#endif
+# endif
}
}
UINT getConsolesCodepage()
@@ -264,6 +264,7 @@ private:
if (m_isConsoleInput) {
break;
}
+ @KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeInputCodepage = input_pipe_codepage;
break;
@@ -290,6 +291,7 @@ private:
if (m_isConsoleOutput) {
break;
}
+ @KWSYS_NAMESPACE@_FALLTHROUGH;
case FILE_TYPE_PIPE:
m_activeOutputCodepage = output_pipe_codepage;
break;
diff --git a/Source/kwsys/Directory.cxx b/Source/kwsys/Directory.cxx
index 5141d4519..59530a43f 100644
--- a/Source/kwsys/Directory.cxx
+++ b/Source/kwsys/Directory.cxx
@@ -10,9 +10,9 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Configure.hxx.in"
-#include "Directory.hxx.in"
-#include "Encoding.hxx.in"
+# include "Configure.hxx.in"
+# include "Directory.hxx.in"
+# include "Encoding.hxx.in"
#endif
#include <string>
@@ -48,7 +48,7 @@ unsigned long Directory::GetNumberOfFiles() const
const char* Directory::GetFile(unsigned long dindex) const
{
if (dindex >= this->Internal->Files.size()) {
- return 0;
+ return KWSYS_NULLPTR;
}
return this->Internal->Files[dindex].c_str();
}
@@ -69,40 +69,40 @@ void Directory::Clear()
// First Windows platforms
#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <windows.h>
+# include <windows.h>
-#include <ctype.h>
-#include <fcntl.h>
-#include <io.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
+# include <ctype.h>
+# include <fcntl.h>
+# include <io.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
+# include <sys/stat.h>
+# include <sys/types.h>
// Wide function names can vary depending on compiler:
-#ifdef __BORLANDC__
-#define _wfindfirst_func __wfindfirst
-#define _wfindnext_func __wfindnext
-#else
-#define _wfindfirst_func _wfindfirst
-#define _wfindnext_func _wfindnext
-#endif
+# ifdef __BORLANDC__
+# define _wfindfirst_func __wfindfirst
+# define _wfindnext_func __wfindnext
+# else
+# define _wfindfirst_func _wfindfirst
+# define _wfindnext_func _wfindnext
+# endif
namespace KWSYS_NAMESPACE {
bool Directory::Load(const std::string& name)
{
this->Clear();
-#if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
+# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
// Older Visual C++ and Embarcadero compilers.
long srchHandle;
-#else // Newer Visual C++
+# else // Newer Visual C++
intptr_t srchHandle;
-#endif
+# endif
char* buf;
size_t n = name.size();
- if (*name.rbegin() == '/' || *name.rbegin() == '\\') {
+ if (name.back() == '/' || name.back() == '\\') {
buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name.c_str());
} else {
@@ -118,8 +118,8 @@ bool Directory::Load(const std::string& name)
struct _wfinddata_t data; // data of current file
// Now put them into the file array
- srchHandle =
- _wfindfirst_func((wchar_t*)Encoding::ToWide(buf).c_str(), &data);
+ srchHandle = _wfindfirst_func(
+ (wchar_t*)Encoding::ToWindowsExtendedPath(buf).c_str(), &data);
delete[] buf;
if (srchHandle == -1) {
@@ -136,15 +136,15 @@ bool Directory::Load(const std::string& name)
unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
{
-#if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
+# if (defined(_MSC_VER) && _MSC_VER < 1300) || defined(__BORLANDC__)
// Older Visual C++ and Embarcadero compilers.
long srchHandle;
-#else // Newer Visual C++
+# else // Newer Visual C++
intptr_t srchHandle;
-#endif
+# endif
char* buf;
size_t n = name.size();
- if (*name.rbegin() == '/') {
+ if (name.back() == '/') {
buf = new char[n + 1 + 1];
sprintf(buf, "%s*", name.c_str());
} else {
@@ -177,23 +177,23 @@ unsigned long Directory::GetNumberOfFilesInDirectory(const std::string& name)
// Now the POSIX style directory access
-#include <sys/types.h>
+# include <sys/types.h>
-#include <dirent.h>
+# include <dirent.h>
// PGI with glibc has trouble with dirent and large file support:
// http://www.pgroup.com/userforum/viewtopic.php?
// p=1992&sid=f16167f51964f1a68fe5041b8eb213b6
// Work around the problem by mapping dirent the same way as readdir.
-#if defined(__PGI) && defined(__GLIBC__)
-#define kwsys_dirent_readdir dirent
-#define kwsys_dirent_readdir64 dirent64
-#define kwsys_dirent kwsys_dirent_lookup(readdir)
-#define kwsys_dirent_lookup(x) kwsys_dirent_lookup_delay(x)
-#define kwsys_dirent_lookup_delay(x) kwsys_dirent_##x
-#else
-#define kwsys_dirent dirent
-#endif
+# if defined(__PGI) && defined(__GLIBC__)
+# define kwsys_dirent_readdir dirent
+# define kwsys_dirent_readdir64 dirent64
+# define kwsys_dirent kwsys_dirent_lookup(readdir)
+# define kwsys_dirent_lookup(x) kwsys_dirent_lookup_delay(x)
+# define kwsys_dirent_lookup_delay(x) kwsys_dirent_##x
+# else
+# define kwsys_dirent dirent
+# endif
namespace KWSYS_NAMESPACE {
diff --git a/Source/kwsys/DynamicLoader.cxx b/Source/kwsys/DynamicLoader.cxx
index 1b4596a4e..b93a215cc 100644
--- a/Source/kwsys/DynamicLoader.cxx
+++ b/Source/kwsys/DynamicLoader.cxx
@@ -1,15 +1,20 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
+#if defined(_WIN32)
+# define NOMINMAX // hide min,max to not conflict with <limits>
+#endif
+
#include "kwsysPrivate.h"
#include KWSYS_HEADER(DynamicLoader.hxx)
#include KWSYS_HEADER(Configure.hxx)
+#include KWSYS_HEADER(Encoding.hxx)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Configure.hxx.in"
-#include "DynamicLoader.hxx.in"
+# include "Configure.hxx.in"
+# include "DynamicLoader.hxx.in"
#endif
// This file actually contains several different implementations:
@@ -25,14 +30,36 @@
// Each part of the ifdef contains a complete implementation for
// the static methods of DynamicLoader.
+#define CHECK_OPEN_FLAGS(var, supported, ret) \
+ do { \
+ /* Check for unknown flags. */ \
+ if ((var & AllOpenFlags) != var) { \
+ return ret; \
+ } \
+ \
+ /* Check for unsupported flags. */ \
+ if ((var & (supported)) != var) { \
+ return ret; \
+ } \
+ } while (0)
+
+namespace KWSYS_NAMESPACE {
+
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
+ const std::string& libname)
+{
+ return DynamicLoader::OpenLibrary(libname, 0);
+}
+}
+
#if !KWSYS_SUPPORTS_SHARED_LIBS
// Implementation for environments without dynamic libs
-#include <string.h> // for strerror()
+# include <string.h> // for strerror()
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
- const std::string& libname)
+ const std::string& libname, int flags)
{
return 0;
}
@@ -60,15 +87,17 @@ const char* DynamicLoader::LastError()
} // namespace KWSYS_NAMESPACE
#elif defined(__hpux)
-// Implementation for HPUX machines
-#include <dl.h>
-#include <errno.h>
+// Implementation for HPUX machines
+# include <dl.h>
+# include <errno.h>
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
- const std::string& libname)
+ const std::string& libname, int flags)
{
+ CHECK_OPEN_FLAGS(flags, 0, 0);
+
return shl_load(libname.c_str(), BIND_DEFERRED | DYNAMIC_PATH, 0L);
}
@@ -124,14 +153,16 @@ const char* DynamicLoader::LastError()
#elif defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED < 1030)
// Implementation for Mac OS X 10.2.x and earlier
-#include <mach-o/dyld.h>
-#include <string.h> // for strlen
+# include <mach-o/dyld.h>
+# include <string.h> // for strlen
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
- const std::string& libname)
+ const std::string& libname, int flags)
{
+ CHECK_OPEN_FLAGS(flags, 0, 0);
+
NSObjectFileImageReturnCode rc;
NSObjectFileImage image = 0;
@@ -140,9 +171,9 @@ DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
if (rc != NSObjectFileImageSuccess) {
return 0;
}
- NSModule handle =
- NSLinkModule(image, libname.c_str(), NSLINKMODULE_OPTION_BINDNOW |
- NSLINKMODULE_OPTION_RETURN_ON_ERROR);
+ NSModule handle = NSLinkModule(image, libname.c_str(),
+ NSLINKMODULE_OPTION_BINDNOW |
+ NSLINKMODULE_OPTION_RETURN_ON_ERROR);
NSDestroyObjectFileImage(image);
return handle;
}
@@ -163,17 +194,13 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
{
void* result = 0;
// Need to prepend symbols with '_' on Apple-gcc compilers
- size_t len = sym.size();
- char* rsym = new char[len + 1 + 1];
- strcpy(rsym, "_");
- strcat(rsym + 1, sym.c_str());
+ std::string rsym = '_' + sym;
- NSSymbol symbol = NSLookupSymbolInModule(lib, rsym);
+ NSSymbol symbol = NSLookupSymbolInModule(lib, rsym.c_str());
if (symbol) {
result = NSAddressOfSymbol(symbol);
}
- delete[] rsym;
// Hack to cast pointer-to-data to pointer-to-function.
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
@@ -187,21 +214,24 @@ const char* DynamicLoader::LastError()
#elif defined(_WIN32) && !defined(__CYGWIN__)
// Implementation for Windows win32 code but not cygwin
-#include <windows.h>
+# include <windows.h>
+
+# include <stdio.h>
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
- const std::string& libname)
+ const std::string& libname, int flags)
{
- DynamicLoader::LibraryHandle lh;
- int length = MultiByteToWideChar(CP_UTF8, 0, libname.c_str(), -1, NULL, 0);
- wchar_t* wchars = new wchar_t[length + 1];
- wchars[0] = '\0';
- MultiByteToWideChar(CP_UTF8, 0, libname.c_str(), -1, wchars, length);
- lh = LoadLibraryW(wchars);
- delete[] wchars;
- return lh;
+ CHECK_OPEN_FLAGS(flags, SearchBesideLibrary, NULL);
+
+ DWORD llFlags = 0;
+ if (flags & SearchBesideLibrary) {
+ llFlags |= LOAD_WITH_ALTERED_SEARCH_PATH;
+ }
+
+ return LoadLibraryExW(Encoding::ToWindowsExtendedPath(libname).c_str(), NULL,
+ llFlags);
}
int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
@@ -235,45 +265,54 @@ DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
// 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__)
+# if defined(__BORLANDC__) || defined(__WATCOMC__)
// Need to prepend symbols with '_'
- size_t len = sym.size();
- char* rsym = new char[len + 1 + 1];
- strcpy(rsym, "_");
- strcat(rsym, sym.c_str());
-#else
+ std::string ssym = '_' + sym;
+ const char* rsym = ssym.c_str();
+# else
const char* rsym = sym.c_str();
-#endif
+# 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__
+# ifdef __WATCOMC__
return *(DynamicLoader::SymbolPointer*)(&result);
-#else
+# else
return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
-#endif
+# endif
}
+# define DYNLOAD_ERROR_BUFFER_SIZE 1024
+
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);
+ wchar_t lpMsgBuf[DYNLOAD_ERROR_BUFFER_SIZE + 1];
+
+ DWORD error = GetLastError();
+ DWORD length = FormatMessageW(
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ lpMsgBuf, DYNLOAD_ERROR_BUFFER_SIZE, NULL);
+
+ static char str[DYNLOAD_ERROR_BUFFER_SIZE + 1];
+
+ if (length < 1) {
+ /* FormatMessage failed. Use a default message. */
+ _snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
+ "DynamicLoader encountered error 0x%X. "
+ "FormatMessage failed with error 0x%X",
+ error, GetLastError());
+ return str;
+ }
- if (!lpMsgBuf) {
- return NULL;
+ if (!WideCharToMultiByte(CP_UTF8, 0, lpMsgBuf, -1, str,
+ DYNLOAD_ERROR_BUFFER_SIZE, NULL, NULL)) {
+ /* WideCharToMultiByte failed. Use a default message. */
+ _snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
+ "DynamicLoader encountered error 0x%X. "
+ "WideCharToMultiByte failed with error 0x%X",
+ error, GetLastError());
}
- static char* str = 0;
- delete[] str;
- str = strcpy(new char[strlen((char*)lpMsgBuf) + 1], (char*)lpMsgBuf);
- // Free the buffer.
- LocalFree(lpMsgBuf);
return str;
}
@@ -281,18 +320,20 @@ const char* DynamicLoader::LastError()
#elif defined(__BEOS__)
// Implementation for BeOS / Haiku
-#include <string.h> // for strerror()
+# include <string.h> // for strerror()
-#include <be/kernel/image.h>
-#include <be/support/Errors.h>
+# include <be/kernel/image.h>
+# include <be/support/Errors.h>
namespace KWSYS_NAMESPACE {
static image_id last_dynamic_err = B_OK;
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
- const std::string& libname)
+ const std::string& libname, int flags)
{
+ CHECK_OPEN_FLAGS(flags, 0, 0);
+
// 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.c_str());
@@ -360,17 +401,19 @@ const char* DynamicLoader::LastError()
#elif defined(__MINT__)
// Implementation for FreeMiNT on Atari
-#define _GNU_SOURCE /* for program_invocation_name */
-#include <dld.h>
-#include <errno.h>
-#include <malloc.h>
-#include <string.h>
+# define _GNU_SOURCE /* for program_invocation_name */
+# include <dld.h>
+# include <errno.h>
+# include <malloc.h>
+# include <string.h>
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
- const std::string& libname)
+ const std::string& libname, int flags)
{
+ CHECK_OPEN_FLAGS(flags, 0, NULL);
+
char* name = (char*)calloc(1, libname.size() + 1);
dld_init(program_invocation_name);
strncpy(name, libname.c_str(), libname.size());
@@ -408,13 +451,15 @@ const char* DynamicLoader::LastError()
#else
// Default implementation for *NIX systems (including Mac OS X 10.3 and
// later) which use dlopen
-#include <dlfcn.h>
+# include <dlfcn.h>
namespace KWSYS_NAMESPACE {
DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
- const std::string& libname)
+ const std::string& libname, int flags)
{
+ CHECK_OPEN_FLAGS(flags, 0, NULL);
+
return dlopen(libname.c_str(), RTLD_LAZY);
}
diff --git a/Source/kwsys/DynamicLoader.hxx.in b/Source/kwsys/DynamicLoader.hxx.in
index 7e71a4593..539c74259 100644
--- a/Source/kwsys/DynamicLoader.hxx.in
+++ b/Source/kwsys/DynamicLoader.hxx.in
@@ -8,16 +8,16 @@
#include <string>
#if defined(__hpux)
-#include <dl.h>
+# include <dl.h>
#elif defined(_WIN32) && !defined(__CYGWIN__)
-#include <windows.h>
+# include <windows.h>
#elif defined(__APPLE__)
-#include <AvailabilityMacros.h>
-#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
-#include <mach-o/dyld.h>
-#endif
+# 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>
+# include <be/kernel/image.h>
#endif
namespace @KWSYS_NAMESPACE@ {
@@ -35,7 +35,7 @@ namespace @KWSYS_NAMESPACE@ {
* 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
+ * should be doing full path to guarantee 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
@@ -52,11 +52,11 @@ public:
#elif defined(_WIN32) && !defined(__CYGWIN__)
typedef HMODULE LibraryHandle;
#elif defined(__APPLE__)
-#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
+# if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
typedef NSModule LibraryHandle;
-#else
+# else
typedef void* LibraryHandle;
-#endif
+# endif
#elif defined(__BEOS__)
typedef image_id LibraryHandle;
#else // POSIX
@@ -66,13 +66,26 @@ public:
// Return type from DynamicLoader::GetSymbolAddress.
typedef void (*SymbolPointer)();
+ enum OpenFlags
+ {
+ // Search for dependent libraries beside the library being loaded.
+ //
+ // This is currently only supported on Windows.
+ SearchBesideLibrary = 0x00000001,
+
+ AllOpenFlags = SearchBesideLibrary
+ };
+
/** Load a dynamic library into the current process.
* The returned LibraryHandle can be used to access the symbols in the
- * library. */
+ * library. The optional second argument is a set of flags to use when
+ * opening the library. If unrecognized or unsupported flags are specified,
+ * the library is not opened. */
static LibraryHandle OpenLibrary(const std::string&);
+ static LibraryHandle OpenLibrary(const std::string&, int);
/** Attempt to detach a dynamic library from the
- * process. A value of true is returned if it is sucessful. */
+ * process. A value of true is returned if it is successful. */
static int CloseLibrary(LibraryHandle);
/** Find the address of the symbol in the given library. */
diff --git a/Source/kwsys/Encoding.h.in b/Source/kwsys/Encoding.h.in
index 7b6ed10f8..86a26692a 100644
--- a/Source/kwsys/Encoding.h.in
+++ b/Source/kwsys/Encoding.h.in
@@ -12,15 +12,15 @@
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
+# 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)
+# 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)
@@ -55,15 +55,15 @@ kwsysEXPORT char* kwsysEncoding_DupToNarrow(const wchar_t* str);
/* 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
+# 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
index 09691fd3f..b06752115 100644
--- a/Source/kwsys/Encoding.hxx.in
+++ b/Source/kwsys/Encoding.hxx.in
@@ -41,9 +41,9 @@ public:
std::vector<char*> argv_;
};
-/**
- * Convert between char and wchar_t
- */
+ /**
+ * Convert between char and wchar_t
+ */
#if @KWSYS_NAMESPACE@_STL_HAS_WSTRING
@@ -59,7 +59,7 @@ public:
static std::string ToNarrow(const std::wstring& str);
static std::string ToNarrow(const wchar_t* str);
-#if defined(_WIN32)
+# if defined(_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
@@ -68,7 +68,7 @@ public:
* absolute paths with Windows-style backslashes.
**/
static std::wstring ToWindowsExtendedPath(std::string const&);
-#endif
+# endif
#endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
diff --git a/Source/kwsys/EncodingC.c b/Source/kwsys/EncodingC.c
index c1315b2d5..e12236afe 100644
--- a/Source/kwsys/EncodingC.c
+++ b/Source/kwsys/EncodingC.c
@@ -6,13 +6,13 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "Encoding.h.in"
+# include "Encoding.h.in"
#endif
#include <stdlib.h>
#ifdef _WIN32
-#include <windows.h>
+# include <windows.h>
#endif
size_t kwsysEncoding_mbstowcs(wchar_t* dest, const char* str, size_t n)
diff --git a/Source/kwsys/EncodingCXX.cxx b/Source/kwsys/EncodingCXX.cxx
index b1e54c958..251deef3d 100644
--- a/Source/kwsys/EncodingCXX.cxx
+++ b/Source/kwsys/EncodingCXX.cxx
@@ -1,9 +1,9 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifdef __osf__
-#define _OSF_SOURCE
-#define _POSIX_C_SOURCE 199506L
-#define _XOPEN_SOURCE_EXTENDED
+# define _OSF_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# define _XOPEN_SOURCE_EXTENDED
#endif
#include "kwsysPrivate.h"
@@ -13,8 +13,8 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Encoding.h.in"
-#include "Encoding.hxx.in"
+# include "Encoding.h.in"
+# include "Encoding.hxx.in"
#endif
#include <stdlib.h>
@@ -22,15 +22,15 @@
#include <vector>
#ifdef _MSC_VER
-#pragma warning(disable : 4786)
+# pragma warning(disable : 4786)
#endif
// Windows API.
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
-#include <ctype.h>
-#include <shellapi.h>
+# include <ctype.h>
+# include <shellapi.h>
#endif
namespace KWSYS_NAMESPACE {
@@ -65,7 +65,7 @@ Encoding::CommandLineArguments::CommandLineArguments(int ac,
for (int i = 0; i < ac; i++) {
this->argv_[i] = strdup(av[i]);
}
- this->argv_[ac] = 0;
+ this->argv_[ac] = KWSYS_NULLPTR;
}
Encoding::CommandLineArguments::CommandLineArguments(int ac,
@@ -75,7 +75,7 @@ Encoding::CommandLineArguments::CommandLineArguments(int ac,
for (int i = 0; i < ac; i++) {
this->argv_[i] = kwsysEncoding_DupToNarrow(av[i]);
}
- this->argv_[ac] = 0;
+ this->argv_[ac] = KWSYS_NULLPTR;
}
Encoding::CommandLineArguments::~CommandLineArguments()
@@ -90,7 +90,7 @@ Encoding::CommandLineArguments::CommandLineArguments(
{
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;
+ this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : KWSYS_NULLPTR;
}
}
@@ -105,7 +105,7 @@ Encoding::CommandLineArguments& Encoding::CommandLineArguments::operator=(
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;
+ this->argv_[i] = other.argv_[i] ? strdup(other.argv_[i]) : KWSYS_NULLPTR;
}
}
@@ -127,7 +127,7 @@ char const* const* Encoding::CommandLineArguments::argv() const
std::wstring Encoding::ToWide(const std::string& str)
{
std::wstring wstr;
-#if defined(_WIN32)
+# if defined(_WIN32)
const int wlength = MultiByteToWideChar(
KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str.data(), int(str.size()), NULL, 0);
if (wlength > 0) {
@@ -139,7 +139,7 @@ std::wstring Encoding::ToWide(const std::string& str)
}
delete[] wdata;
}
-#else
+# else
size_t pos = 0;
size_t nullPos = 0;
do {
@@ -152,14 +152,14 @@ std::wstring Encoding::ToWide(const std::string& str)
wstr += wchar_t('\0');
}
} while (nullPos != std::string::npos);
-#endif
+# endif
return wstr;
}
std::string Encoding::ToNarrow(const std::wstring& str)
{
std::string nstr;
-#if defined(_WIN32)
+# if defined(_WIN32)
int length =
WideCharToMultiByte(KWSYS_ENCODING_DEFAULT_CODEPAGE, 0, str.c_str(),
int(str.size()), NULL, 0, NULL, NULL);
@@ -173,7 +173,7 @@ std::string Encoding::ToNarrow(const std::wstring& str)
}
delete[] data;
}
-#else
+# else
size_t pos = 0;
size_t nullPos = 0;
do {
@@ -186,14 +186,14 @@ std::string Encoding::ToNarrow(const std::wstring& str)
nstr += '\0';
}
} while (nullPos != std::string::npos);
-#endif
+# endif
return nstr;
}
std::wstring Encoding::ToWide(const char* cstr)
{
std::wstring wstr;
- size_t length = kwsysEncoding_mbstowcs(0, cstr, 0) + 1;
+ size_t length = kwsysEncoding_mbstowcs(KWSYS_NULLPTR, cstr, 0) + 1;
if (length > 0) {
std::vector<wchar_t> wchars(length);
if (kwsysEncoding_mbstowcs(&wchars[0], cstr, length) > 0) {
@@ -206,7 +206,7 @@ std::wstring Encoding::ToWide(const char* cstr)
std::string Encoding::ToNarrow(const wchar_t* wcstr)
{
std::string str;
- size_t length = kwsysEncoding_wcstombs(0, wcstr, 0) + 1;
+ size_t length = kwsysEncoding_wcstombs(KWSYS_NULLPTR, wcstr, 0) + 1;
if (length > 0) {
std::vector<char> chars(length);
if (kwsysEncoding_wcstombs(&chars[0], wcstr, length) > 0) {
@@ -216,7 +216,7 @@ std::string Encoding::ToNarrow(const wchar_t* wcstr)
return str;
}
-#if defined(_WIN32)
+# if defined(_WIN32)
// Convert local paths to UNC style paths
std::wstring Encoding::ToWindowsExtendedPath(std::string const& source)
{
@@ -270,7 +270,7 @@ std::wstring Encoding::ToWindowsExtendedPath(std::string const& source)
// unchanged
return Encoding::ToWide(source);
}
-#endif
+# endif
#endif // KWSYS_STL_HAS_WSTRING
diff --git a/Source/kwsys/FStream.cxx b/Source/kwsys/FStream.cxx
index 3c44a6fa0..5e4133ac5 100644
--- a/Source/kwsys/FStream.cxx
+++ b/Source/kwsys/FStream.cxx
@@ -6,7 +6,7 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "FStream.hxx.in"
+# include "FStream.hxx.in"
#endif
namespace KWSYS_NAMESPACE {
diff --git a/Source/kwsys/FStream.hxx.in b/Source/kwsys/FStream.hxx.in
index a4c65fe30..d79bbdf16 100644
--- a/Source/kwsys/FStream.hxx.in
+++ b/Source/kwsys/FStream.hxx.in
@@ -9,26 +9,26 @@
#include <fstream>
#if defined(_WIN32)
-#if !defined(_MSC_VER) && @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
-#include <ext/stdio_filebuf.h>
-#endif
+# if !defined(_MSC_VER) && @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H
+# include <ext/stdio_filebuf.h>
+# endif
#endif
namespace @KWSYS_NAMESPACE@ {
#if defined(_WIN32) && \
(defined(_MSC_VER) || @KWSYS_NAMESPACE@_CXX_HAS_EXT_STDIO_FILEBUF_H)
-#if defined(_NOEXCEPT)
-#define @KWSYS_NAMESPACE@_FStream_NOEXCEPT _NOEXCEPT
-#else
-#define @KWSYS_NAMESPACE@_FStream_NOEXCEPT
-#endif
+# if defined(_NOEXCEPT)
+# define @KWSYS_NAMESPACE@_FStream_NOEXCEPT _NOEXCEPT
+# else
+# define @KWSYS_NAMESPACE@_FStream_NOEXCEPT
+# endif
-#if defined(_MSC_VER)
+# if defined(_MSC_VER)
template <typename CharType, typename Traits>
class basic_filebuf : public std::basic_filebuf<CharType, Traits>
{
-#if _MSC_VER >= 1400
+# if _MSC_VER >= 1400
public:
typedef std::basic_filebuf<CharType, Traits> my_base_type;
basic_filebuf* open(char const* s, std::ios_base::openmode mode)
@@ -36,10 +36,10 @@ public:
const std::wstring wstr = Encoding::ToWindowsExtendedPath(s);
return static_cast<basic_filebuf*>(my_base_type::open(wstr.c_str(), mode));
}
-#endif
+# endif
};
-#else
+# else
inline std::wstring getcmode(const std::ios_base::openmode mode)
{
@@ -67,17 +67,17 @@ inline std::wstring getcmode(const std::ios_base::openmode mode)
return cmode;
};
-#endif
+# endif
template <typename CharType, typename Traits = std::char_traits<CharType> >
class basic_efilebuf
{
public:
-#if defined(_MSC_VER)
+# if defined(_MSC_VER)
typedef basic_filebuf<CharType, Traits> internal_buffer_type;
-#else
+# else
typedef __gnu_cxx::stdio_filebuf<CharType, Traits> internal_buffer_type;
-#endif
+# endif
basic_efilebuf()
: file_(0)
@@ -90,9 +90,9 @@ public:
if (is_open() || file_) {
return false;
}
-#if defined(_MSC_VER)
+# if defined(_MSC_VER)
const bool success = buf_->open(file_name, mode) != 0;
-#else
+# else
const std::wstring wstr = Encoding::ToWindowsExtendedPath(file_name);
bool success = false;
std::wstring cmode = getcmode(mode);
@@ -104,7 +104,7 @@ public:
buf_ = new internal_buffer_type(file_, mode);
success = true;
}
-#endif
+# endif
return success;
}
@@ -129,12 +129,12 @@ public:
bool success = false;
if (buf_) {
success = buf_->close() != 0;
-#if !defined(_MSC_VER)
+# if !defined(_MSC_VER)
if (file_) {
success = fclose(file_) == 0 ? success : false;
file_ = 0;
}
-#endif
+# endif
}
return success;
}
@@ -142,11 +142,11 @@ public:
static void _set_state(bool success, std::basic_ios<CharType, Traits>* ios,
basic_efilebuf* efilebuf)
{
-#if !defined(_MSC_VER)
+# if !defined(_MSC_VER)
ios->rdbuf(efilebuf->buf_);
-#else
+# else
static_cast<void>(efilebuf);
-#endif
+# endif
if (!success) {
ios->setstate(std::ios_base::failbit);
} else {
@@ -167,8 +167,9 @@ protected:
};
template <typename CharType, typename Traits = std::char_traits<CharType> >
-class basic_ifstream : public std::basic_istream<CharType, Traits>,
- public basic_efilebuf<CharType, Traits>
+class basic_ifstream
+ : public std::basic_istream<CharType, Traits>
+ , public basic_efilebuf<CharType, Traits>
{
public:
typedef typename basic_efilebuf<CharType, Traits>::internal_buffer_type
@@ -207,8 +208,9 @@ public:
};
template <typename CharType, typename Traits = std::char_traits<CharType> >
-class basic_ofstream : public std::basic_ostream<CharType, Traits>,
- public basic_efilebuf<CharType, Traits>
+class basic_ofstream
+ : public std::basic_ostream<CharType, Traits>
+ , public basic_efilebuf<CharType, Traits>
{
using basic_efilebuf<CharType, Traits>::is_open;
@@ -248,7 +250,7 @@ public:
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
-#undef @KWSYS_NAMESPACE@_FStream_NOEXCEPT
+# undef @KWSYS_NAMESPACE@_FStream_NOEXCEPT
#else
using std::ofstream;
using std::ifstream;
diff --git a/Source/kwsys/Glob.cxx b/Source/kwsys/Glob.cxx
index d2f0b8516..829c1389f 100644
--- a/Source/kwsys/Glob.cxx
+++ b/Source/kwsys/Glob.cxx
@@ -12,11 +12,11 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Configure.hxx.in"
-#include "Directory.hxx.in"
-#include "Glob.hxx.in"
-#include "RegularExpression.hxx.in"
-#include "SystemTools.hxx.in"
+# include "Configure.hxx.in"
+# include "Directory.hxx.in"
+# include "Glob.hxx.in"
+# include "RegularExpression.hxx.in"
+# include "SystemTools.hxx.in"
#endif
#include <algorithm>
@@ -28,13 +28,13 @@
#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
+// 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
+# define KWSYS_GLOB_SUPPORT_NETWORK_PATHS
#endif
class GlobInternals
@@ -81,13 +81,13 @@ std::string Glob::PatternToRegex(const std::string& pattern,
int c = *i;
if (c == '*') {
// A '*' (not between brackets) matches any string.
- // We modify this to not match slashes since the orignal glob
+ // We modify this to not match slashes since the original 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
+ // We modify this to not match slashes since the original glob
// pattern documentation was meant for matching file name
// components separated by slashes.
regex += "[^/]";
@@ -201,7 +201,7 @@ bool Glob::RecurseDirectory(std::string::size_type start,
}
#if defined(KWSYS_GLOB_CASE_INDEPENDENT)
- // On Windows and apple, no difference between lower and upper case
+ // On Windows and Apple, no difference between lower and upper case
fname = kwsys::SystemTools::LowerCase(fname);
#endif
@@ -217,9 +217,10 @@ bool Glob::RecurseDirectory(std::string::size_type start,
if (!realPathErrorMessage.empty()) {
if (messages) {
- messages->push_back(Message(
- Glob::error, "Canonical path generation from path '" + dir +
- "' failed! Reason: '" + realPathErrorMessage + "'"));
+ messages->push_back(
+ Message(Glob::error,
+ "Canonical path generation from path '" + dir +
+ "' failed! Reason: '" + realPathErrorMessage + "'"));
}
return false;
}
@@ -262,7 +263,7 @@ bool Glob::RecurseDirectory(std::string::size_type start,
}
} else {
if (!this->Internals->Expressions.empty() &&
- this->Internals->Expressions.rbegin()->find(fname)) {
+ this->Internals->Expressions.back().find(fname)) {
this->AddFile(this->Internals->Files, realname);
}
}
@@ -430,7 +431,7 @@ void Glob::SetRelative(const char* dir)
const char* Glob::GetRelative()
{
if (this->Relative.empty()) {
- return 0;
+ return KWSYS_NULLPTR;
}
return this->Relative.c_str();
}
diff --git a/Source/kwsys/Glob.hxx.in b/Source/kwsys/Glob.hxx.in
index bd4a17616..4c3bde167 100644
--- a/Source/kwsys/Glob.hxx.in
+++ b/Source/kwsys/Glob.hxx.in
@@ -41,17 +41,9 @@ public:
, content(c)
{
}
- Message(const Message& msg)
- : type(msg.type)
- , content(msg.content)
- {
- }
- Message& operator=(Message const& msg)
- {
- this->type = msg.type;
- this->content = msg.content;
- return *this;
- }
+ ~Message() = default;
+ Message(const Message& msg) = default;
+ Message& operator=(Message const& msg) = default;
};
typedef std::vector<Message> GlobMessages;
diff --git a/Source/kwsys/IOStream.cxx b/Source/kwsys/IOStream.cxx
index 01ada1f2f..e21f87d45 100644
--- a/Source/kwsys/IOStream.cxx
+++ b/Source/kwsys/IOStream.cxx
@@ -10,21 +10,21 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Configure.hxx.in"
-#include "IOStream.hxx.in"
+# include "Configure.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
+# 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
+# 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 {
@@ -118,13 +118,13 @@ std::istream& IOStreamScanTemplate(std::istream& is, T& value, char type)
try {
// Copy the string to a buffer and construct the format string.
char buffer[KWSYS_IOS_INT64_MAX_DIG];
-#if defined(_MSC_VER)
+# if defined(_MSC_VER)
char format[] = "%I64_";
const int typeIndex = 4;
-#else
+# else
char format[] = "%ll_";
const int typeIndex = 3;
-#endif
+# endif
switch (IOStreamScanStream(is, buffer)) {
case 8:
format[typeIndex] = 'o';
@@ -177,14 +177,14 @@ std::ostream& IOStreamPrintTemplate(std::ostream& os, T value, char type)
if (os.flags() & std::ios_base::showbase) {
*f++ = '#';
}
-#if defined(_MSC_VER)
+# if defined(_MSC_VER)
*f++ = 'I';
*f++ = '6';
*f++ = '4';
-#else
+# else
*f++ = 'l';
*f++ = 'l';
-#endif
+# endif
long bflags = os.flags() & std::ios_base::basefield;
if (bflags == std::ios_base::oct) {
*f++ = 'o';
@@ -209,7 +209,7 @@ std::ostream& IOStreamPrintTemplate(std::ostream& os, T value, char type)
return os;
}
-#if !KWSYS_IOS_HAS_ISTREAM_LONG_LONG
+# if !KWSYS_IOS_HAS_ISTREAM_LONG_LONG
// Implement input stream operator for IOStreamSLL.
std::istream& IOStreamScan(std::istream& is, IOStreamSLL& value)
{
@@ -221,9 +221,9 @@ std::istream& IOStreamScan(std::istream& is, IOStreamULL& value)
{
return IOStreamScanTemplate(is, value, 'u');
}
-#endif
+# endif
-#if !KWSYS_IOS_HAS_OSTREAM_LONG_LONG
+# if !KWSYS_IOS_HAS_OSTREAM_LONG_LONG
// Implement output stream operator for IOStreamSLL.
std::ostream& IOStreamPrint(std::ostream& os, IOStreamSLL value)
{
@@ -235,7 +235,7 @@ std::ostream& IOStreamPrint(std::ostream& os, IOStreamULL value)
{
return IOStreamPrintTemplate(os, value, 'u');
}
-#endif
+# endif
} // namespace KWSYS_NAMESPACE
diff --git a/Source/kwsys/IOStream.hxx.in b/Source/kwsys/IOStream.hxx.in
index de3a2e634..db8a23ef5 100644
--- a/Source/kwsys/IOStream.hxx.in
+++ b/Source/kwsys/IOStream.hxx.in
@@ -7,7 +7,7 @@
/* Define these macros temporarily to keep the code readable. */
#if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
-#define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
+# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT
#endif
/* Whether istream supports long long. */
@@ -21,27 +21,27 @@
/* 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
+# 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
+# endif
#elif defined(_MSC_VER) && _MSC_VER < 1300
-#define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 1
+# 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
+# define @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL 0
#endif
#if @KWSYS_NAMESPACE@_IOS_NEED_OPERATORS_LL
-#if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG
+# if !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG
/* Input stream operator implementation functions. */
namespace @KWSYS_NAMESPACE@ {
@@ -50,31 +50,31 @@ kwsysEXPORT std::istream& IOStreamScan(std::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
+# 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 std::istream& operator>>(std::istream& is,
@KWSYS_NAMESPACE@::IOStreamSLL& value)
{
return @KWSYS_NAMESPACE@::IOStreamScan(is, value);
}
-#endif
+# 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
+# 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 std::istream& operator>>(std::istream& is,
@KWSYS_NAMESPACE@::IOStreamULL& value)
{
return @KWSYS_NAMESPACE@::IOStreamScan(is, value);
}
-#endif
-#endif /* !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG */
+# endif
+# endif /* !@KWSYS_NAMESPACE@_IOS_HAS_ISTREAM_LONG_LONG */
-#if !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
+# if !@KWSYS_NAMESPACE@_IOS_HAS_OSTREAM_LONG_LONG
/* Output stream operator implementation functions. */
namespace @KWSYS_NAMESPACE@ {
@@ -83,44 +83,44 @@ kwsysEXPORT std::ostream& IOStreamPrint(std::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
+# 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 std::ostream& operator<<(std::ostream& os,
@KWSYS_NAMESPACE@::IOStreamSLL value)
{
return @KWSYS_NAMESPACE@::IOStreamPrint(os, value);
}
-#endif
+# 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
+# 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 std::ostream& operator<<(std::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 */
+# 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 kwsysEXPORT
#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
+# 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
index 3188fb67a..97cf9ba68 100644
--- a/Source/kwsys/MD5.c
+++ b/Source/kwsys/MD5.c
@@ -6,7 +6,7 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "MD5.h.in"
+# include "MD5.h.in"
#endif
#include <stddef.h> /* size_t */
@@ -19,8 +19,8 @@
implementation file. */
#if defined(__clang__) && !defined(__INTEL_COMPILER)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-align"
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-align"
#endif
/*
@@ -98,9 +98,9 @@ typedef struct md5_state_s
#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)
+# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
#else
-#define BYTE_ORDER 0
+# define BYTE_ORDER 0
#endif
#define T_MASK ((md5_word_t)~0)
@@ -222,11 +222,11 @@ static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/)
const md5_byte_t* xp = data;
int i;
-#if BYTE_ORDER == 0
+# if BYTE_ORDER == 0
X = xbuf; /* (dynamic only) */
-#else
-#define xbuf X /* (static only) */
-#endif
+# 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));
@@ -420,7 +420,7 @@ static void md5_finish(md5_state_t* pms, md5_byte_t digest[16])
}
#if defined(__clang__) && !defined(__INTEL_COMPILER)
-#pragma clang diagnostic pop
+# pragma clang diagnostic pop
#endif
/* Wrap up the MD5 state in our opaque structure. */
diff --git a/Source/kwsys/MD5.h.in b/Source/kwsys/MD5.h.in
index c257f7f9a..7646f1297 100644
--- a/Source/kwsys/MD5.h.in
+++ b/Source/kwsys/MD5.h.in
@@ -10,19 +10,19 @@
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
+# 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)
+# 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)
@@ -79,19 +79,19 @@ kwsysEXPORT void kwsysMD5_DigestToHex(unsigned char const digest[16],
/* 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
+# 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
index 237001c60..73ea9dbfc 100644
--- a/Source/kwsys/Process.h.in
+++ b/Source/kwsys/Process.h.in
@@ -10,74 +10,79 @@
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
+# 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_MergeOutput kwsys_ns(Process_Option_MergeOutput)
-#define kwsysProcess_Option_Verbatim kwsys_ns(Process_Option_Verbatim)
-#define kwsysProcess_Option_CreateProcessGroup \
- kwsys_ns(Process_Option_CreateProcessGroup)
-#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_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_Exception_e kwsys_ns(Process_Exception_e)
-#define kwsysProcess_GetState kwsys_ns(Process_GetState)
-#define kwsysProcess_GetExitException kwsys_ns(Process_GetExitException)
-#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_GetStateByIndex kwsys_ns(Process_GetStateByIndex)
-#define kwsysProcess_GetExitExceptionByIndex \
- kwsys_ns(Process_GetExitExceptionByIndex)
-#define kwsysProcess_GetExitCodeByIndex kwsys_ns(Process_GetExitCodeByIndex)
-#define kwsysProcess_GetExitValueByIndex kwsys_ns(Process_GetExitValueByIndex)
-#define kwsysProcess_GetExceptionStringByIndex \
- kwsys_ns(Process_GetExceptionStringByIndex)
-#define kwsysProcess_GetExitCodeByIndex kwsys_ns(Process_GetExitCodeByIndex)
-#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_Interrupt kwsys_ns(Process_Interrupt)
-#define kwsysProcess_Kill kwsys_ns(Process_Kill)
-#define kwsysProcess_ResetStartTime kwsys_ns(Process_ResetStartTime)
+# 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_MergeOutput kwsys_ns(Process_Option_MergeOutput)
+# define kwsysProcess_Option_Verbatim kwsys_ns(Process_Option_Verbatim)
+# define kwsysProcess_Option_CreateProcessGroup \
+ kwsys_ns(Process_Option_CreateProcessGroup)
+# 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_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_Exception_e kwsys_ns(Process_Exception_e)
+# define kwsysProcess_GetState kwsys_ns(Process_GetState)
+# define kwsysProcess_GetExitException kwsys_ns(Process_GetExitException)
+# 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_GetStateByIndex kwsys_ns(Process_GetStateByIndex)
+# define kwsysProcess_GetExitExceptionByIndex \
+ kwsys_ns(Process_GetExitExceptionByIndex)
+# define kwsysProcess_GetExitCodeByIndex kwsys_ns(Process_GetExitCodeByIndex)
+# define kwsysProcess_GetExitValueByIndex \
+ kwsys_ns(Process_GetExitValueByIndex)
+# define kwsysProcess_GetExceptionStringByIndex \
+ kwsys_ns(Process_GetExceptionStringByIndex)
+# define kwsysProcess_GetExitCodeByIndex kwsys_ns(Process_GetExitCodeByIndex)
+# 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_Interrupt kwsys_ns(Process_Interrupt)
+# define kwsysProcess_Kill kwsys_ns(Process_Kill)
+# define kwsysProcess_KillPID kwsys_ns(Process_KillPID)
+# define kwsysProcess_ResetStartTime kwsys_ns(Process_ResetStartTime)
#endif
#if defined(__cplusplus)
@@ -306,13 +311,13 @@ kwsysEXPORT const char* kwsysProcess_GetErrorString(kwsysProcess* cp);
kwsysEXPORT const char* kwsysProcess_GetExceptionString(kwsysProcess* cp);
/**
-* Get the current state of the Process instance. Possible states are:
-*
-* kwsysProcess_StateByIndex_Starting = Execute has not yet been called.
-* kwsysProcess_StateByIndex_Exception = Child process exited abnormally.
-* kwsysProcess_StateByIndex_Exited = Child process exited normally.
-* kwsysProcess_StateByIndex_Error = Error getting the child return code.
-*/
+ * Get the current state of the Process instance. Possible states are:
+ *
+ * kwsysProcess_StateByIndex_Starting = Execute has not yet been called.
+ * kwsysProcess_StateByIndex_Exception = Child process exited abnormally.
+ * kwsysProcess_StateByIndex_Exited = Child process exited normally.
+ * kwsysProcess_StateByIndex_Error = Error getting the child return code.
+ */
kwsysEXPORT int kwsysProcess_GetStateByIndex(kwsysProcess* cp, int idx);
enum kwsysProcess_StateByIndex_e
{
@@ -323,46 +328,46 @@ enum kwsysProcess_StateByIndex_e
};
/**
-* 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.
-*/
+ * 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_GetExitExceptionByIndex(kwsysProcess* cp,
int idx);
/**
-* 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.
-*/
+ * 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_GetExitCodeByIndex(kwsysProcess* cp, int idx);
/**
-* When GetState returns "Exited", this method returns the child's
-* platform-independent exit code (such as the value returned by the
-* child's main).
-*/
+ * 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_GetExitValueByIndex(kwsysProcess* cp, int idx);
/**
-* When GetState returns "Exception", this method returns a string
-* describing the problem. Otherwise, it returns NULL.
-*/
+ * When GetState returns "Exception", this method returns a string
+ * describing the problem. Otherwise, it returns NULL.
+ */
kwsysEXPORT const char* kwsysProcess_GetExceptionStringByIndex(
kwsysProcess* cp, int idx);
@@ -420,7 +425,7 @@ enum kwsysProcess_Pipes_e
/**
* Block until the child process terminates or the given timeout
- * expires. If no process is running, returns immediatly. The
+ * expires. If no process is running, returns immediately. The
* argument is:
*
* timeout = Specifies the maximum time this call may block. Upon
@@ -457,6 +462,13 @@ kwsysEXPORT void kwsysProcess_Interrupt(kwsysProcess* cp);
kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp);
/**
+ * Same as kwsysProcess_Kill using process ID to locate process to
+ * terminate.
+ * @see kwsysProcess_Kill(kwsysProcess* cp)
+ */
+kwsysEXPORT void kwsysProcess_KillPID(unsigned long);
+
+/**
* Reset the start time of the child process to the current time.
*/
kwsysEXPORT void kwsysProcess_ResetStartTime(kwsysProcess* cp);
@@ -468,65 +480,65 @@ kwsysEXPORT void kwsysProcess_ResetStartTime(kwsysProcess* cp);
/* 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_MergeOutput
-#undef kwsysProcess_Option_Verbatim
-#undef kwsysProcess_Option_CreateProcessGroup
-#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_Interrupt
-#undef kwsysProcess_Kill
-#undef kwsysProcess_ResetStartTime
-#endif
+# 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_MergeOutput
+# undef kwsysProcess_Option_Verbatim
+# undef kwsysProcess_Option_CreateProcessGroup
+# 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_Interrupt
+# undef kwsysProcess_Kill
+# undef kwsysProcess_ResetStartTime
+# endif
#endif
#endif
diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c
index 9ebcfce59..f65690b31 100644
--- a/Source/kwsys/ProcessUNIX.c
+++ b/Source/kwsys/ProcessUNIX.c
@@ -7,8 +7,8 @@
/* 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 "Process.h.in"
+# include "System.h.in"
#endif
/*
@@ -40,7 +40,7 @@ do.
#if defined(__CYGWIN__)
/* Increase the file descriptor limit for select() before including
related system headers. (Default: 64) */
-#define FD_SETSIZE 16384
+# define FD_SETSIZE 16384
#endif
#include <assert.h> /* assert */
@@ -61,9 +61,9 @@ do.
#include <unistd.h> /* pipe, close, fork, execvp, select, _exit */
#if defined(__VMS)
-#define KWSYSPE_VMS_NONBLOCK , O_NONBLOCK
+# define KWSYSPE_VMS_NONBLOCK , O_NONBLOCK
#else
-#define KWSYSPE_VMS_NONBLOCK
+# define KWSYSPE_VMS_NONBLOCK
#endif
#if defined(KWSYS_C_HAS_PTRDIFF_T) && KWSYS_C_HAS_PTRDIFF_T
@@ -80,13 +80,13 @@ typedef int kwsysProcess_ssize_t;
#if defined(__BEOS__) && !defined(__ZETA__)
/* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
-#include <be/kernel/OS.h>
+# include <be/kernel/OS.h>
static inline void kwsysProcess_usleep(unsigned int msec)
{
snooze(msec);
}
#else
-#define kwsysProcess_usleep usleep
+# define kwsysProcess_usleep usleep
#endif
/*
@@ -99,13 +99,14 @@ static inline void kwsysProcess_usleep(unsigned int msec)
* 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
+#if !defined(__BEOS__) && !defined(__VMS) && !defined(__MINT__) && \
+ !defined(KWSYSPE_USE_SELECT)
+# 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
+# define KWSYSPE_USE_SIGINFO 1
#endif
/* The number of pipes for the child's output. The standard stdout
@@ -230,7 +231,7 @@ struct kwsysProcess_s
when reaping PIDs or modifying this array to avoid race conditions. */
volatile pid_t* volatile ForkPIDs;
- /* Flag for whether the children were terminated by a faild select. */
+ /* Flag for whether the children were terminated by a failed select. */
int SelectError;
/* The timeout length. */
@@ -358,9 +359,7 @@ void kwsysProcess_Delete(kwsysProcess* cp)
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->CommandExitCodes);
free(cp->ProcessResults);
free(cp);
}
@@ -497,11 +496,10 @@ int kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
cp->WorkingDirectory = 0;
}
if (dir) {
- cp->WorkingDirectory = (char*)malloc(strlen(dir) + 1);
+ cp->WorkingDirectory = strdup(dir);
if (!cp->WorkingDirectory) {
return 0;
}
- strcpy(cp->WorkingDirectory, dir);
}
return 1;
}
@@ -530,11 +528,10 @@ int kwsysProcess_SetPipeFile(kwsysProcess* cp, int prPipe, const char* file)
*pfile = 0;
}
if (file) {
- *pfile = (char*)malloc(strlen(file) + 1);
+ *pfile = strdup(file);
if (!*pfile) {
return 0;
}
- strcpy(*pfile, file);
}
/* If we are redirecting the pipe, do not share it or use a native
@@ -1165,7 +1162,7 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
case KWSYSPE_PIPE_STDERR:
wd->PipeId = kwsysProcess_Pipe_STDERR;
break;
- };
+ }
return 1;
}
} else if (n < 0 && errno == EAGAIN) {
@@ -1269,21 +1266,21 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
} else if (n == 0) /* EOF */
{
/* We are done reading from this pipe. */
-#if defined(__VMS)
+# if defined(__VMS)
if (!cp->CommandsLeft)
-#endif
+# endif
{
kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);
--cp->PipesLeft;
}
} else if (n < 0) /* error */
{
-#if defined(__VMS)
+# if defined(__VMS)
if (!cp->CommandsLeft) {
kwsysProcessCleanupDescriptor(&cp->PipeReadEnds[i]);
--cp->PipesLeft;
} else
-#endif
+# endif
if ((errno != EINTR) && (errno != EAGAIN)) {
strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
/* Kill the children now. */
@@ -1474,12 +1471,12 @@ static void kwsysProcessVolatileFree(volatile void* p)
/* clang has made it impossible to free memory that points to volatile
without first using special pragmas to disable a warning... */
#if defined(__clang__) && !defined(__INTEL_COMPILER)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-qual"
#endif
free((void*)p); /* The cast will silence most compilers, but not clang. */
#if defined(__clang__) && !defined(__INTEL_COMPILER)
-#pragma clang diagnostic pop
+# pragma clang diagnostic pop
#endif
}
@@ -1513,9 +1510,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp)
oldForkPIDs = cp->ForkPIDs;
cp->ForkPIDs = (volatile pid_t*)malloc(sizeof(volatile pid_t) *
(size_t)(cp->NumberOfCommands));
- if (oldForkPIDs) {
- kwsysProcessVolatileFree(oldForkPIDs);
- }
+ kwsysProcessVolatileFree(oldForkPIDs);
if (!cp->ForkPIDs) {
return 0;
}
@@ -1523,9 +1518,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp)
cp->ForkPIDs[i] = 0; /* can't use memset due to volatile */
}
- if (cp->CommandExitCodes) {
- free(cp->CommandExitCodes);
- }
+ free(cp->CommandExitCodes);
cp->CommandExitCodes =
(int*)malloc(sizeof(int) * (size_t)(cp->NumberOfCommands));
if (!cp->CommandExitCodes) {
@@ -1937,6 +1930,7 @@ static int kwsysProcessSetupOutputPipeFile(int* p, const char* name)
/* Set close-on-exec flag on the pipe's end. */
if (fcntl(fout, F_SETFD, FD_CLOEXEC) < 0) {
+ close(fout);
return 0;
}
@@ -2032,7 +2026,15 @@ static kwsysProcessTime kwsysProcessTimeGetCurrent(void)
{
kwsysProcessTime current;
kwsysProcessTimeNative current_native;
+#if KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
+ struct timespec current_timespec;
+ clock_gettime(CLOCK_MONOTONIC, &current_timespec);
+
+ current_native.tv_sec = current_timespec.tv_sec;
+ current_native.tv_usec = current_timespec.tv_nsec / 1000;
+#else
gettimeofday(&current_native, 0);
+#endif
current.tv_sec = (long)current_native.tv_sec;
current.tv_usec = (long)current_native.tv_usec;
return current;
@@ -2096,11 +2098,11 @@ static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int sig,
break;
#endif
#ifdef SIGBUS
-#if !defined(SIGSEGV) || SIGBUS != SIGSEGV
+# if !defined(SIGSEGV) || SIGBUS != SIGSEGV
case SIGBUS:
KWSYSPE_CASE(Fault, "Bus error");
break;
-#endif
+# endif
#endif
#ifdef SIGFPE
case SIGFPE:
@@ -2148,11 +2150,11 @@ static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int sig,
break;
#endif
#ifdef SIGIOT
-#if !defined(SIGABRT) || SIGIOT != SIGABRT
+# if !defined(SIGABRT) || SIGIOT != SIGABRT
case SIGIOT:
KWSYSPE_CASE(Other, "SIGIOT");
break;
-#endif
+# endif
#endif
#ifdef SIGUSR1
case SIGUSR1:
@@ -2249,11 +2251,11 @@ static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int sig,
break;
#endif
#ifdef SIGIO
-#if !defined(SIGPOLL) || SIGIO != SIGPOLL
+# if !defined(SIGPOLL) || SIGIO != SIGPOLL
case SIGIO:
KWSYSPE_CASE(Other, "SIGIO");
break;
-#endif
+# endif
#endif
#ifdef SIGPWR
case SIGPWR:
@@ -2266,11 +2268,11 @@ static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int sig,
break;
#endif
#ifdef SIGUNUSED
-#if !defined(SIGSYS) || SIGUNUSED != SIGSYS
+# if !defined(SIGSYS) || SIGUNUSED != SIGSYS
case SIGUNUSED:
KWSYSPE_CASE(Other, "SIGUNUSED");
break;
-#endif
+# endif
#endif
default:
cp->ProcessResults[idx].ExitException = kwsysProcess_Exception_Other;
@@ -2289,6 +2291,7 @@ static void kwsysProcessChildErrorExit(int errorPipe)
char buffer[KWSYSPE_PIPE_BUFFER_SIZE];
kwsysProcess_ssize_t result;
strncpy(buffer, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
+ buffer[KWSYSPE_PIPE_BUFFER_SIZE - 1] = '\0';
/* Report the error to the parent through the special pipe. */
result = write(errorPipe, buffer, strlen(buffer));
@@ -2465,23 +2468,28 @@ static pid_t kwsysProcessFork(kwsysProcess* cp,
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"
+# 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"
+# 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"
+# 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"
+# 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"
+# define KWSYSPE_PS_COMMAND "ps aux"
+# define KWSYSPE_PS_FORMAT "%d %d %*[^\n]\n"
#endif
+void kwsysProcess_KillPID(unsigned long process_id)
+{
+ kwsysProcessKill((pid_t)process_id);
+}
+
static void kwsysProcessKill(pid_t process_id)
{
#if defined(__linux__) || defined(__CYGWIN__)
@@ -2501,13 +2509,13 @@ static void kwsysProcessKill(pid_t process_id)
#if defined(__linux__) || defined(__CYGWIN__)
/* First try using the /proc filesystem. */
if ((procdir = opendir("/proc")) != NULL) {
-#if defined(MAXPATHLEN)
+# if defined(MAXPATHLEN)
char fname[MAXPATHLEN];
-#elif defined(PATH_MAX)
+# elif defined(PATH_MAX)
char fname[PATH_MAX];
-#else
+# else
char fname[4096];
-#endif
+# endif
char buffer[KWSYSPE_PIPE_BUFFER_SIZE + 1];
struct dirent* d;
@@ -2707,9 +2715,9 @@ static int kwsysProcessesAdd(kwsysProcess* cp)
#if KWSYSPE_USE_SIGINFO
newSigAction.sa_sigaction = kwsysProcessesSignalHandler;
newSigAction.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
-#ifdef SA_RESTART
+# ifdef SA_RESTART
newSigAction.sa_flags |= SA_RESTART;
-#endif
+# endif
#else
newSigAction.sa_handler = kwsysProcessesSignalHandler;
newSigAction.sa_flags = SA_NOCLDSTOP;
@@ -2796,7 +2804,7 @@ static void kwsysProcessesSignalHandler(int signum
,
siginfo_t* info, void* ucontext
#endif
- )
+)
{
int i, j, procStatus, old_errno = errno;
#if KWSYSPE_USE_SIGINFO
diff --git a/Source/kwsys/ProcessWin32.c b/Source/kwsys/ProcessWin32.c
index 5183e3d2c..68c52185e 100644
--- a/Source/kwsys/ProcessWin32.c
+++ b/Source/kwsys/ProcessWin32.c
@@ -7,8 +7,8 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "Encoding.h.in"
-#include "Process.h.in"
+# include "Encoding.h.in"
+# include "Process.h.in"
#endif
/*
@@ -22,35 +22,35 @@ a UNIX-style select system call.
*/
#ifdef _MSC_VER
-#pragma warning(push, 1)
+# pragma warning(push, 1)
#endif
#include <windows.h> /* Windows API */
#if defined(_MSC_VER) && _MSC_VER >= 1800
-#define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
#endif
#include <io.h> /* _unlink */
#include <stdio.h> /* sprintf */
#include <string.h> /* strlen, strdup */
#ifdef __WATCOMC__
-#define _unlink unlink
+# define _unlink unlink
#endif
#ifndef _MAX_FNAME
-#define _MAX_FNAME 4096
+# define _MAX_FNAME 4096
#endif
#ifndef _MAX_PATH
-#define _MAX_PATH 4096
+# define _MAX_PATH 4096
#endif
#ifdef _MSC_VER
-#pragma warning(pop)
-#pragma warning(disable : 4514)
-#pragma warning(disable : 4706)
+# 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. */
+# 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. */
@@ -63,14 +63,14 @@ a UNIX-style select system call.
/* 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))
+# 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
+# define KWSYSPE_DEBUG(x) (void)1
#endif
typedef LARGE_INTEGER kwsysProcessTime;
@@ -117,7 +117,6 @@ static kwsysProcessTime kwsysProcessTimeAdd(kwsysProcessTime in1,
kwsysProcessTime in2);
static kwsysProcessTime kwsysProcessTimeSubtract(kwsysProcessTime in1,
kwsysProcessTime in2);
-static void kwsysProcessSetExitException(kwsysProcess* cp, int code);
static void kwsysProcessSetExitExceptionByIndex(kwsysProcess* cp, int code,
int idx);
static void kwsysProcessKillTree(int pid);
@@ -355,16 +354,23 @@ kwsysProcess* kwsysProcess_New(void)
ZeroMemory(&osv, sizeof(osv));
osv.dwOSVersionInfoSize = sizeof(osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(push)
-#ifdef __INTEL_COMPILER
-#pragma warning(disable : 1478)
-#else
-#pragma warning(disable : 4996)
-#endif
+# pragma warning(push)
+# ifdef __INTEL_COMPILER
+# pragma warning(disable : 1478)
+# elif defined __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# else
+# pragma warning(disable : 4996)
+# endif
#endif
GetVersionEx(&osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(pop)
+# ifdef __clang__
+# pragma clang diagnostic pop
+# else
+# pragma warning(pop)
+# endif
#endif
if (osv.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
/* Win9x no longer supported. */
@@ -523,9 +529,7 @@ void kwsysProcess_Delete(kwsysProcess* cp)
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->CommandExitCodes);
free(cp->ProcessResults);
free(cp);
}
@@ -713,11 +717,10 @@ int kwsysProcess_SetPipeFile(kwsysProcess* cp, int pipe, const char* file)
*pfile = 0;
}
if (file) {
- *pfile = (char*)malloc(strlen(file) + 1);
+ *pfile = strdup(file);
if (!*pfile) {
return 0;
}
- strcpy(*pfile, file);
}
/* If we are redirecting the pipe, do not share it or use a native
@@ -976,8 +979,8 @@ void kwsysProcess_Execute(kwsysProcess* cp)
wchar_t* wstdin = kwsysEncoding_DupToWide(cp->PipeFileSTDIN);
DWORD error;
cp->PipeChildStd[0] =
- CreateFileW(wstdin, GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
+ CreateFileW(wstdin, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
+ OPEN_EXISTING, 0, 0);
error = GetLastError(); /* Check now in case free changes this. */
free(wstdin);
if (cp->PipeChildStd[0] == INVALID_HANDLE_VALUE) {
@@ -1469,6 +1472,11 @@ void kwsysProcess_Kill(kwsysProcess* cp)
for them to exit. */
}
+void kwsysProcess_KillPID(unsigned long process_id)
+{
+ kwsysProcessKillTree((DWORD)process_id);
+}
+
/*
Function executed for each pipe's thread. Argument is a pointer to
the kwsysProcessPipeData instance for this thread.
@@ -1607,9 +1615,7 @@ int kwsysProcessInitialize(kwsysProcess* cp)
}
ZeroMemory(cp->ProcessInformation,
sizeof(PROCESS_INFORMATION) * cp->NumberOfCommands);
- if (cp->CommandExitCodes) {
- free(cp->CommandExitCodes);
- }
+ free(cp->CommandExitCodes);
cp->CommandExitCodes = (DWORD*)malloc(sizeof(DWORD) * cp->NumberOfCommands);
if (!cp->CommandExitCodes) {
return 0;
@@ -2266,16 +2272,23 @@ static kwsysProcess_List* kwsysProcess_List_New(void)
ZeroMemory(&osv, sizeof(osv));
osv.dwOSVersionInfoSize = sizeof(osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(push)
-#ifdef __INTEL_COMPILER
-#pragma warning(disable : 1478)
-#else
-#pragma warning(disable : 4996)
-#endif
+# pragma warning(push)
+# ifdef __INTEL_COMPILER
+# pragma warning(disable : 1478)
+# elif defined __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# else
+# pragma warning(disable : 4996)
+# endif
#endif
GetVersionEx(&osv);
#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(pop)
+# ifdef __clang__
+# pragma clang diagnostic pop
+# else
+# pragma warning(pop)
+# endif
#endif
self->NT4 =
(osv.dwPlatformId == VER_PLATFORM_WIN32_NT && osv.dwMajorVersion < 5) ? 1
@@ -2362,9 +2375,7 @@ static int kwsysProcess_List__New_NT4(kwsysProcess_List* self)
static void kwsysProcess_List__Delete_NT4(kwsysProcess_List* self)
{
/* Free the process information buffer. */
- if (self->Buffer) {
- free(self->Buffer);
- }
+ free(self->Buffer);
}
static int kwsysProcess_List__Update_NT4(kwsysProcess_List* self)
@@ -2661,8 +2672,8 @@ static int kwsysProcessesAdd(HANDLE hProcess, DWORD dwProcessid,
newSize = kwsysProcesses.Size ? kwsysProcesses.Size * 2 : 4;
/* Try allocating the new block of memory. */
- if (newArray = (kwsysProcessInstance*)malloc(
- newSize * sizeof(kwsysProcessInstance))) {
+ if ((newArray = (kwsysProcessInstance*)malloc(
+ newSize * sizeof(kwsysProcessInstance)))) {
/* Copy the old process handles to the new memory. */
if (kwsysProcesses.Count > 0) {
memcpy(newArray, kwsysProcesses.Processes,
diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx
index 6d7f83295..5f84b1946 100644
--- a/Source/kwsys/RegularExpression.cxx
+++ b/Source/kwsys/RegularExpression.cxx
@@ -25,7 +25,7 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "RegularExpression.hxx.in"
+# include "RegularExpression.hxx.in"
#endif
#include <stdio.h>
@@ -37,18 +37,18 @@ namespace KWSYS_NAMESPACE {
RegularExpression::RegularExpression(const RegularExpression& rxp)
{
if (!rxp.program) {
- this->program = 0;
+ this->program = KWSYS_NULLPTR;
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
+ for (ind = this->progsize; ind-- != 0;) // Copy regular expression
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) {
+ // Copy pointers into last successful "find" operation
+ this->regmatch = rxp.regmatch;
+ this->regmust = rxp.regmust; // Copy field
+ if (rxp.regmust != KWSYS_NULLPTR) {
char* dum = rxp.program;
ind = 0;
while (dum != rxp.regmust) {
@@ -69,19 +69,19 @@ RegularExpression& RegularExpression::operator=(const RegularExpression& rxp)
return *this;
}
if (!rxp.program) {
- this->program = 0;
+ this->program = KWSYS_NULLPTR;
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
+ for (ind = this->progsize; ind-- != 0;) // Copy regular expression
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) {
+ // Copy pointers into last successful "find" operation
+ this->regmatch = rxp.regmatch;
+ this->regmust = rxp.regmust; // Copy field
+ if (rxp.regmust != KWSYS_NULLPTR) {
char* dum = rxp.program;
ind = 0;
while (dum != rxp.regmust) {
@@ -123,12 +123,13 @@ bool RegularExpression::deep_equal(const RegularExpression& rxp) const
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
+ // Else if same start/end ptrs, return true
+ return (this->regmatch.start() == rxp.regmatch.start() &&
+ this->regmatch.end() == rxp.regmatch.end());
}
-// The remaining code in this file is derived from the regular expression code
-// whose copyright statement appears below. It has been changed to work
+// 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.
/*
@@ -193,24 +194,29 @@ bool RegularExpression::deep_equal(const RegularExpression& rxp) const
*/
// 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
+#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.
+#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.
@@ -258,11 +264,6 @@ const unsigned char MAGIC = 0234;
#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 "^$.[()|?+*\\"
@@ -281,31 +282,35 @@ const unsigned char MAGIC = 0234;
/////////////////////////////////////////////////////////////////////////
/*
- * Global work variables for compile().
+ * Read only utility variables.
*/
-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.
+static char* const regdummyptr = &regdummy;
/*
- * Forward declarations for compile()'s friends.
+ * Utility class for RegularExpression::compile().
*/
-// #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);
+class RegExpCompile
+{
+public:
+ const char* regparse; // Input-scan pointer.
+ int regnpar; // () count.
+ char* regcode; // Code-emit pointer; regdummyptr = don't.
+ long regsize; // Code size.
+
+ char* reg(int, int*);
+ char* regbranch(int*);
+ char* regpiece(int*);
+ char* regatom(int*);
+ char* regnode(char);
+ void regc(char);
+ void reginsert(char, char*);
+ static void regtail(char*, const char*);
+ static void regoptail(char*, const 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();
@@ -335,26 +340,27 @@ bool RegularExpression::compile(const char* exp)
size_t len;
int flags;
- if (exp == 0) {
+ if (exp == KWSYS_NULLPTR) {
// 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)) {
+ RegExpCompile comp;
+ comp.regparse = exp;
+ comp.regnpar = 1;
+ comp.regsize = 0L;
+ comp.regcode = regdummyptr;
+ comp.regc(static_cast<char>(MAGIC));
+ if (!comp.reg(0, &flags)) {
printf("RegularExpression::compile(): Error in compile.\n");
return false;
}
- this->startp[0] = this->endp[0] = this->searchstring = 0;
+ this->regmatch.clear();
// Small enough for pointer-storage convention?
- if (regsize >= 32767L) { // Probably could be 65535L.
+ if (comp.regsize >= 32767L) { // Probably could be 65535L.
// RAISE Error, SYM(RegularExpression), SYM(Expr_Too_Big),
printf("RegularExpression::compile(): Expression too big.\n");
return false;
@@ -362,29 +368,29 @@ bool RegularExpression::compile(const char* exp)
// Allocate space.
//#ifndef _WIN32
- if (this->program != 0)
+ if (this->program != KWSYS_NULLPTR)
delete[] this->program;
//#endif
- this->program = new char[regsize];
- this->progsize = static_cast<int>(regsize);
+ this->program = new char[comp.regsize];
+ this->progsize = static_cast<int>(comp.regsize);
- if (this->program == 0) {
+ if (this->program == KWSYS_NULLPTR) {
// 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);
+ comp.regparse = exp;
+ comp.regnpar = 1;
+ comp.regcode = this->program;
+ comp.regc(static_cast<char>(MAGIC));
+ comp.reg(0, &flags);
// Dig out information for optimizations.
this->regstart = '\0'; // Worst-case defaults.
this->reganch = 0;
- this->regmust = 0;
+ this->regmust = KWSYS_NULLPTR;
this->regmlen = 0;
scan = this->program + 1; // First BRANCH.
if (OP(regnext(scan)) == END) { // Only one top-level choice.
@@ -405,9 +411,9 @@ bool RegularExpression::compile(const char* exp)
// absence of others.
//
if (flags & SPSTART) {
- longest = 0;
+ longest = KWSYS_NULLPTR;
len = 0;
- for (; scan != 0; scan = regnext(scan))
+ for (; scan != KWSYS_NULLPTR; scan = regnext(scan))
if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
longest = OPERAND(scan);
len = strlen(OPERAND(scan));
@@ -428,7 +434,7 @@ bool RegularExpression::compile(const char* exp)
* 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* RegExpCompile::reg(int paren, int* flagp)
{
char* ret;
char* br;
@@ -440,22 +446,22 @@ static char* reg(int paren, int* flagp)
// Make an OPEN node, if parenthesized.
if (paren) {
- if (regnpar >= RegularExpression::NSUBEXP) {
+ if (regnpar >= RegularExpressionMatch::NSUBEXP) {
// RAISE Error, SYM(RegularExpression), SYM(Too_Many_Parens),
printf("RegularExpression::compile(): Too many parentheses.\n");
- return 0;
+ return KWSYS_NULLPTR;
}
parno = regnpar;
regnpar++;
ret = regnode(static_cast<char>(OPEN + parno));
} else
- ret = 0;
+ ret = KWSYS_NULLPTR;
// Pick up the branches, linking them together.
br = regbranch(&flags);
- if (br == 0)
- return (0);
- if (ret != 0)
+ if (br == KWSYS_NULLPTR)
+ return (KWSYS_NULLPTR);
+ if (ret != KWSYS_NULLPTR)
regtail(ret, br); // OPEN -> first.
else
ret = br;
@@ -465,8 +471,8 @@ static char* reg(int paren, int* flagp)
while (*regparse == '|') {
regparse++;
br = regbranch(&flags);
- if (br == 0)
- return (0);
+ if (br == KWSYS_NULLPTR)
+ return (KWSYS_NULLPTR);
regtail(ret, br); // BRANCH -> BRANCH.
if (!(flags & HASWIDTH))
*flagp &= ~HASWIDTH;
@@ -478,23 +484,23 @@ static char* reg(int paren, int* flagp)
regtail(ret, ender);
// Hook the tails of the branches to the closing node.
- for (br = ret; br != 0; br = regnext(br))
+ for (br = ret; br != KWSYS_NULLPTR; 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;
+ return KWSYS_NULLPTR;
} else if (!paren && *regparse != '\0') {
if (*regparse == ')') {
// RAISE Error, SYM(RegularExpression), SYM(Unmatched_Parens),
printf("RegularExpression::compile(): Unmatched parentheses.\n");
- return 0;
+ return KWSYS_NULLPTR;
} else {
// RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
printf("RegularExpression::compile(): Internal error.\n");
- return 0;
+ return KWSYS_NULLPTR;
}
// NOTREACHED
}
@@ -506,7 +512,7 @@ static char* reg(int paren, int* flagp)
*
* Implements the concatenation operator.
*/
-static char* regbranch(int* flagp)
+char* RegExpCompile::regbranch(int* flagp)
{
char* ret;
char* chain;
@@ -516,19 +522,19 @@ static char* regbranch(int* flagp)
*flagp = WORST; // Tentatively.
ret = regnode(BRANCH);
- chain = 0;
+ chain = KWSYS_NULLPTR;
while (*regparse != '\0' && *regparse != '|' && *regparse != ')') {
latest = regpiece(&flags);
- if (latest == 0)
- return (0);
+ if (latest == KWSYS_NULLPTR)
+ return (KWSYS_NULLPTR);
*flagp |= flags & HASWIDTH;
- if (chain == 0) // First piece.
+ if (chain == KWSYS_NULLPTR) // First piece.
*flagp |= flags & SPSTART;
else
regtail(chain, latest);
chain = latest;
}
- if (chain == 0) // Loop ran zero times.
+ if (chain == KWSYS_NULLPTR) // Loop ran zero times.
regnode(NOTHING);
return (ret);
@@ -543,7 +549,7 @@ static char* regbranch(int* flagp)
* It might seem that this node could be dispensed with entirely, but the
* endmarker role is not redundant.
*/
-static char* regpiece(int* flagp)
+char* RegExpCompile::regpiece(int* flagp)
{
char* ret;
char op;
@@ -551,8 +557,8 @@ static char* regpiece(int* flagp)
int flags;
ret = regatom(&flags);
- if (ret == 0)
- return (0);
+ if (ret == KWSYS_NULLPTR)
+ return (KWSYS_NULLPTR);
op = *regparse;
if (!ISMULT(op)) {
@@ -563,7 +569,7 @@ static char* regpiece(int* flagp)
if (!(flags & HASWIDTH) && op != '?') {
// RAISE Error, SYM(RegularExpression), SYM(Empty_Operand),
printf("RegularExpression::compile() : *+ operand could be empty.\n");
- return 0;
+ return KWSYS_NULLPTR;
}
*flagp = (op != '+') ? (WORST | SPSTART) : (WORST | HASWIDTH);
@@ -597,7 +603,7 @@ static char* regpiece(int* flagp)
if (ISMULT(*regparse)) {
// RAISE Error, SYM(RegularExpression), SYM(Nested_Operand),
printf("RegularExpression::compile(): Nested *?+.\n");
- return 0;
+ return KWSYS_NULLPTR;
}
return (ret);
}
@@ -610,7 +616,7 @@ static char* regpiece(int* flagp)
* 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* RegExpCompile::regatom(int* flagp)
{
char* ret;
int flags;
@@ -650,7 +656,7 @@ static char* regatom(int* flagp)
if (rxpclass > rxpclassend + 1) {
// RAISE Error, SYM(RegularExpression), SYM(Invalid_Range),
printf("RegularExpression::compile(): Invalid range in [].\n");
- return 0;
+ return KWSYS_NULLPTR;
}
for (; rxpclass <= rxpclassend; rxpclass++)
regc(static_cast<char>(rxpclass));
@@ -663,15 +669,15 @@ static char* regatom(int* flagp)
if (*regparse != ']') {
// RAISE Error, SYM(RegularExpression), SYM(Unmatched_Bracket),
printf("RegularExpression::compile(): Unmatched [].\n");
- return 0;
+ return KWSYS_NULLPTR;
}
regparse++;
*flagp |= HASWIDTH | SIMPLE;
} break;
case '(':
ret = reg(1, &flags);
- if (ret == 0)
- return (0);
+ if (ret == KWSYS_NULLPTR)
+ return (KWSYS_NULLPTR);
*flagp |= flags & (HASWIDTH | SPSTART);
break;
case '\0':
@@ -679,18 +685,18 @@ static char* regatom(int* flagp)
case ')':
// RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
printf("RegularExpression::compile(): Internal error.\n"); // Never here
- return 0;
+ return KWSYS_NULLPTR;
case '?':
case '+':
case '*':
// RAISE Error, SYM(RegularExpression), SYM(No_Operand),
printf("RegularExpression::compile(): ?+* follows nothing.\n");
- return 0;
+ return KWSYS_NULLPTR;
case '\\':
if (*regparse == '\0') {
// RAISE Error, SYM(RegularExpression), SYM(Trailing_Backslash),
printf("RegularExpression::compile(): Trailing backslash.\n");
- return 0;
+ return KWSYS_NULLPTR;
}
ret = regnode(EXACTLY);
regc(*regparse++);
@@ -706,7 +712,7 @@ static char* regatom(int* flagp)
if (len <= 0) {
// RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
printf("RegularExpression::compile(): Internal error.\n");
- return 0;
+ return KWSYS_NULLPTR;
}
ender = *(regparse + len);
if (len > 1 && ISMULT(ender))
@@ -729,13 +735,13 @@ static char* regatom(int* flagp)
- regnode - emit a node
Location.
*/
-static char* regnode(char op)
+char* RegExpCompile::regnode(char op)
{
char* ret;
char* ptr;
ret = regcode;
- if (ret == &regdummy) {
+ if (ret == regdummyptr) {
regsize += 3;
return (ret);
}
@@ -752,9 +758,9 @@ static char* regnode(char op)
/*
- regc - emit (if appropriate) a byte of code
*/
-static void regc(char b)
+void RegExpCompile::regc(char b)
{
- if (regcode != &regdummy)
+ if (regcode != regdummyptr)
*regcode++ = b;
else
regsize++;
@@ -765,13 +771,13 @@ static void regc(char b)
*
* Means relocating the operand.
*/
-static void reginsert(char op, char* opnd)
+void RegExpCompile::reginsert(char op, char* opnd)
{
char* src;
char* dst;
char* place;
- if (regcode == &regdummy) {
+ if (regcode == regdummyptr) {
regsize += 3;
return;
}
@@ -791,20 +797,20 @@ static void reginsert(char op, char* opnd)
/*
- regtail - set the next-pointer at the end of a node chain
*/
-static void regtail(char* p, const char* val)
+void RegExpCompile::regtail(char* p, const char* val)
{
char* scan;
char* temp;
int offset;
- if (p == &regdummy)
+ if (p == regdummyptr)
return;
// Find last node.
scan = p;
for (;;) {
temp = regnext(scan);
- if (temp == 0)
+ if (temp == KWSYS_NULLPTR)
break;
scan = temp;
}
@@ -820,10 +826,10 @@ static void regtail(char* p, const char* val)
/*
- regoptail - regtail on operand of first argument; nop if operandless
*/
-static void regoptail(char* p, const char* val)
+void RegExpCompile::regoptail(char* p, const char* val)
{
// "Operandless" and "op != BRANCH" are synonymous in practice.
- if (p == 0 || p == &regdummy || OP(p) != BRANCH)
+ if (p == KWSYS_NULLPTR || p == regdummyptr || OP(p) != BRANCH)
return;
regtail(OPERAND(p), val);
}
@@ -835,34 +841,30 @@ static void regoptail(char* p, const char* val)
////////////////////////////////////////////////////////////////////////
/*
- * Global work variables for find().
+ * Utility class for RegularExpression::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.
+class RegExpFind
+{
+public:
+ const char* reginput; // String-input pointer.
+ const char* regbol; // Beginning of input, for ^ check.
+ const char** regstartp; // Pointer to startp array.
+ 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
+ int regtry(const char*, const char**, const char**, const char*);
+ int regmatch(const char*);
+ int regrepeat(const char*);
+};
// 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)
+bool RegularExpression::find(char const* string,
+ RegularExpressionMatch& rmatch) const
{
const char* s;
- this->searchstring = string;
+ rmatch.clear();
+ rmatch.searchstring = string;
if (!this->program) {
return false;
@@ -873,54 +875,57 @@ bool RegularExpression::find(const char* string)
// RAISE Error, SYM(RegularExpression), SYM(Internal_Error),
printf(
"RegularExpression::find(): Compiled regular expression corrupted.\n");
- return 0;
+ return false;
}
// If there is a "must appear" string, look for it.
- if (this->regmust != 0) {
+ if (this->regmust != KWSYS_NULLPTR) {
s = string;
- while ((s = strchr(s, this->regmust[0])) != 0) {
+ while ((s = strchr(s, this->regmust[0])) != KWSYS_NULLPTR) {
if (strncmp(s, this->regmust, this->regmlen) == 0)
break; // Found it.
s++;
}
- if (s == 0) // Not present.
- return (0);
+ if (s == KWSYS_NULLPTR) // Not present.
+ return false;
}
+ RegExpFind regFind;
+
// Mark beginning of line for ^ .
- regbol = string;
+ regFind.regbol = string;
// Simplest case: anchored match need be tried only once.
if (this->reganch)
- return (regtry(string, this->startp, this->endp, this->program) != 0);
+ return (
+ regFind.regtry(string, rmatch.startp, rmatch.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);
+ while ((s = strchr(s, this->regstart)) != KWSYS_NULLPTR) {
+ if (regFind.regtry(s, rmatch.startp, rmatch.endp, this->program))
+ return true;
s++;
}
else
// We don't -- general case.
do {
- if (regtry(s, this->startp, this->endp, this->program))
- return (1);
+ if (regFind.regtry(s, rmatch.startp, rmatch.endp, this->program))
+ return true;
} while (*s++ != '\0');
// Failure.
- return (0);
+ return false;
}
/*
- 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 RegExpFind::regtry(const char* string, const char** start,
+ const char** end, const char* prog)
{
int i;
const char** sp1;
@@ -932,9 +937,9 @@ static int regtry(const char* string, const char** start, const char** end,
sp1 = start;
ep = end;
- for (i = RegularExpression::NSUBEXP; i > 0; i--) {
- *sp1++ = 0;
- *ep++ = 0;
+ for (i = RegularExpressionMatch::NSUBEXP; i > 0; i--) {
+ *sp1++ = KWSYS_NULLPTR;
+ *ep++ = KWSYS_NULLPTR;
}
if (regmatch(prog + 1)) {
start[0] = string;
@@ -955,14 +960,14 @@ static int regtry(const char* string, const char** start, const char** end,
* by recursion.
* 0 failure, 1 success
*/
-static int regmatch(const char* prog)
+int RegExpFind::regmatch(const char* prog)
{
const char* scan; // Current node.
const char* next; // Next node.
scan = prog;
- while (scan != 0) {
+ while (scan != KWSYS_NULLPTR) {
next = regnext(scan);
@@ -994,12 +999,14 @@ static int regmatch(const char* prog)
reginput += len;
} break;
case ANYOF:
- if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == 0)
+ if (*reginput == '\0' ||
+ strchr(OPERAND(scan), *reginput) == KWSYS_NULLPTR)
return (0);
reginput++;
break;
case ANYBUT:
- if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != 0)
+ if (*reginput == '\0' ||
+ strchr(OPERAND(scan), *reginput) != KWSYS_NULLPTR)
return (0);
reginput++;
break;
@@ -1028,7 +1035,7 @@ static int regmatch(const char* prog)
// Don't set startp if some later invocation of the
// same parentheses already has.
//
- if (regstartp[no] == 0)
+ if (regstartp[no] == KWSYS_NULLPTR)
regstartp[no] = save;
return (1);
} else
@@ -1056,7 +1063,7 @@ static int regmatch(const char* prog)
// Don't set endp if some later invocation of the
// same parentheses already has.
//
- if (regendp[no] == 0)
+ if (regendp[no] == KWSYS_NULLPTR)
regendp[no] = save;
return (1);
} else
@@ -1076,7 +1083,7 @@ static int regmatch(const char* prog)
return (1);
reginput = save;
scan = regnext(scan);
- } while (scan != 0 && OP(scan) == BRANCH);
+ } while (scan != KWSYS_NULLPTR && OP(scan) == BRANCH);
return (0);
// NOTREACHED
}
@@ -1134,7 +1141,7 @@ static int regmatch(const char* prog)
/*
- regrepeat - repeatedly match something simple, report how many
*/
-static int regrepeat(const char* p)
+int RegExpFind::regrepeat(const char* p)
{
int count = 0;
const char* scan;
@@ -1154,13 +1161,13 @@ static int regrepeat(const char* p)
}
break;
case ANYOF:
- while (*scan != '\0' && strchr(opnd, *scan) != 0) {
+ while (*scan != '\0' && strchr(opnd, *scan) != KWSYS_NULLPTR) {
count++;
scan++;
}
break;
case ANYBUT:
- while (*scan != '\0' && strchr(opnd, *scan) == 0) {
+ while (*scan != '\0' && strchr(opnd, *scan) == KWSYS_NULLPTR) {
count++;
scan++;
}
@@ -1181,12 +1188,12 @@ static const char* regnext(const char* p)
{
int offset;
- if (p == &regdummy)
- return (0);
+ if (p == regdummyptr)
+ return (KWSYS_NULLPTR);
offset = NEXT(p);
if (offset == 0)
- return (0);
+ return (KWSYS_NULLPTR);
if (OP(p) == BACK)
return (p - offset);
@@ -1198,12 +1205,12 @@ static char* regnext(char* p)
{
int offset;
- if (p == &regdummy)
- return (0);
+ if (p == regdummyptr)
+ return (KWSYS_NULLPTR);
offset = NEXT(p);
if (offset == 0)
- return (0);
+ return (KWSYS_NULLPTR);
if (OP(p) == BACK)
return (p - offset);
diff --git a/Source/kwsys/RegularExpression.hxx.in b/Source/kwsys/RegularExpression.hxx.in
index 606e3da6e..b7b93f962 100644
--- a/Source/kwsys/RegularExpression.hxx.in
+++ b/Source/kwsys/RegularExpression.hxx.in
@@ -29,11 +29,121 @@
/* 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. */
+# pragma warn - 8027 /* function not inlined. */
#endif
namespace @KWSYS_NAMESPACE@ {
+// Forward declaration
+class RegularExpression;
+
+/** \class RegularExpressionMatch
+ * \brief Stores the pattern matches of a RegularExpression
+ */
+class @KWSYS_NAMESPACE@_EXPORT RegularExpressionMatch
+{
+public:
+ RegularExpressionMatch();
+
+ bool isValid() const;
+ void clear();
+
+ std::string::size_type start() const;
+ std::string::size_type end() const;
+ std::string::size_type start(int n) const;
+ std::string::size_type end(int n) const;
+ std::string match(int n) const;
+
+ enum
+ {
+ NSUBEXP = 10
+ };
+
+private:
+ friend class RegularExpression;
+ const char* startp[NSUBEXP];
+ const char* endp[NSUBEXP];
+ const char* searchstring;
+};
+
+/**
+ * \brief Creates an invalid match object
+ */
+inline RegularExpressionMatch::RegularExpressionMatch()
+{
+ startp[0] = 0;
+ endp[0] = 0;
+ searchstring = 0;
+}
+
+/**
+ * \brief Returns true if the match pointers are valid
+ */
+inline bool RegularExpressionMatch::isValid() const
+{
+ return (this->startp[0] != 0);
+}
+
+/**
+ * \brief Resets to the (invalid) construction state.
+ */
+inline void RegularExpressionMatch::clear()
+{
+ startp[0] = 0;
+ endp[0] = 0;
+ searchstring = 0;
+}
+
+/**
+ * \brief Returns the start index of the full match.
+ */
+inline std::string::size_type RegularExpressionMatch::start() const
+{
+ return static_cast<std::string::size_type>(this->startp[0] - searchstring);
+}
+
+/**
+ * \brief Returns the end index of the full match.
+ */
+inline std::string::size_type RegularExpressionMatch::end() const
+{
+ return static_cast<std::string::size_type>(this->endp[0] - searchstring);
+}
+
+/**
+ * \brief Returns the start index of nth submatch.
+ * start(0) is the start of the full match.
+ */
+inline std::string::size_type RegularExpressionMatch::start(int n) const
+{
+ return static_cast<std::string::size_type>(this->startp[n] -
+ this->searchstring);
+}
+
+/**
+ * \brief Returns the end index of nth submatch.
+ * end(0) is the end of the full match.
+ */
+inline std::string::size_type RegularExpressionMatch::end(int n) const
+{
+ return static_cast<std::string::size_type>(this->endp[n] -
+ this->searchstring);
+}
+
+/**
+ * \brief Returns the nth submatch as a string.
+ */
+inline std::string RegularExpressionMatch::match(int n) const
+{
+ if (this->startp[n] == 0) {
+ return std::string();
+ } else {
+ return std::string(
+ this->startp[n],
+ static_cast<std::string::size_type>(this->endp[n] - this->startp[n]));
+ }
+}
+
/** \class RegularExpression
* \brief Implements pattern matching with regular expressions.
*
@@ -93,7 +203,7 @@ namespace @KWSYS_NAMESPACE@ {
*
* ? Matches preceding pattern zero or once only
*
- * () Saves a matched expression and uses it in a later match
+ * () 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
@@ -109,21 +219,21 @@ namespace @KWSYS_NAMESPACE@ {
* 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
+ * The find member function finds the first occurrence of the regular
* 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
+ * member functions return indices 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:
+ * (i.e. there is no valid compiled expression). 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,
@@ -161,15 +271,18 @@ namespace @KWSYS_NAMESPACE@ {
*
* * 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
+ * encountered 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 same as the two characters before the first p encountered in
* the line. It would match "drepa qrepb" in "rep drepa qrepb".
*
+ * All methods of RegularExpression can be called simultaneously from
+ * different threads but only if each invocation uses an own instance of
+ * RegularExpression.
*/
class @KWSYS_NAMESPACE@_EXPORT RegularExpression
{
@@ -213,9 +326,19 @@ public:
/**
* Matches the regular expression to the given string.
+ * Returns true if found, and sets start and end indexes
+ * in the RegularExpressionMatch instance accordingly.
+ *
+ * This method is thread safe when called with different
+ * RegularExpressionMatch instances.
+ */
+ bool find(char const*, RegularExpressionMatch&) const;
+
+ /**
+ * Matches the regular expression to the given string.
* Returns true if found, and sets start and end indexes accordingly.
*/
- bool find(char const*);
+ inline bool find(char const*);
/**
* Matches the regular expression to the given std string.
@@ -224,14 +347,18 @@ public:
inline bool find(std::string const&);
/**
- * Index to start of first find.
+ * Match indices
*/
+ inline RegularExpressionMatch const& regMatch() const;
inline std::string::size_type start() const;
+ inline std::string::size_type end() const;
+ inline std::string::size_type start(int n) const;
+ inline std::string::size_type end(int n) const;
/**
- * Index to end of first find.
+ * Match strings
*/
- inline std::string::size_type end() const;
+ inline std::string match(int n) const;
/**
* Copy the given regular expression.
@@ -266,29 +393,14 @@ public:
*/
inline void set_invalid();
- /**
- * Destructor.
- */
- // awf added
- std::string::size_type start(int n) const;
- std::string::size_type end(int n) const;
- std::string match(int n) const;
-
- enum
- {
- NSUBEXP = 10
- };
-
private:
- const char* startp[NSUBEXP];
- const char* endp[NSUBEXP];
+ RegularExpressionMatch regmatch;
char regstart; // Internal use only
char reganch; // Internal use only
const char* regmust; // Internal use only
std::string::size_type regmlen; // Internal use only
char* program;
int progsize;
- const char* searchstring;
};
/**
@@ -344,51 +456,42 @@ inline bool RegularExpression::compile(std::string const& s)
* Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly.
*/
-inline bool RegularExpression::find(std::string const& s)
+inline bool RegularExpression::find(const char* s)
{
- return this->find(s.c_str());
+ return this->find(s, this->regmatch);
}
/**
- * Set the start position for the regular expression.
+ * Matches the regular expression to the given std string.
+ * Returns true if found, and sets start and end indexes accordingly.
*/
-inline std::string::size_type RegularExpression::start() const
+inline bool RegularExpression::find(std::string const& s)
{
- return static_cast<std::string::size_type>(this->startp[0] - searchstring);
+ return this->find(s.c_str());
}
/**
- * Returns the start/end index of the last item found.
+ * Returns the internal match object
*/
-inline std::string::size_type RegularExpression::end() const
+inline RegularExpressionMatch const& RegularExpression::regMatch() const
{
- return static_cast<std::string::size_type>(this->endp[0] - searchstring);
+ return this->regmatch;
}
/**
- * Returns true if two regular expressions have different
- * compiled program for pattern matching.
+ * Returns the start index of the full match.
*/
-inline bool RegularExpression::operator!=(const RegularExpression& r) const
+inline std::string::size_type RegularExpression::start() const
{
- return (!(*this == r));
+ return regmatch.start();
}
/**
- * Returns true if a valid regular expression is compiled
- * and ready for pattern matching.
+ * Returns the end index of the full match.
*/
-inline bool RegularExpression::is_valid() const
-{
- return (this->program != 0);
-}
-
-inline void RegularExpression::set_invalid()
+inline std::string::size_type RegularExpression::end() const
{
- //#ifndef _WIN32
- delete[] this->program;
- //#endif
- this->program = 0;
+ return regmatch.end();
}
/**
@@ -396,7 +499,7 @@ inline void RegularExpression::set_invalid()
*/
inline std::string::size_type RegularExpression::start(int n) const
{
- return static_cast<std::string::size_type>(this->startp[n] - searchstring);
+ return regmatch.start(n);
}
/**
@@ -404,7 +507,7 @@ inline std::string::size_type RegularExpression::start(int n) const
*/
inline std::string::size_type RegularExpression::end(int n) const
{
- return static_cast<std::string::size_type>(this->endp[n] - searchstring);
+ return regmatch.end(n);
}
/**
@@ -412,12 +515,33 @@ inline std::string::size_type RegularExpression::end(int n) const
*/
inline std::string RegularExpression::match(int n) const
{
- if (this->startp[n] == 0) {
- return std::string("");
- } else {
- return std::string(this->startp[n], static_cast<std::string::size_type>(
- this->endp[n] - this->startp[n]));
- }
+ return regmatch.match(n);
+}
+
+/**
+ * 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;
}
} // namespace @KWSYS_NAMESPACE@
diff --git a/Source/kwsys/SharedForward.h.in b/Source/kwsys/SharedForward.h.in
index f638267ec..5716cd4f1 100644
--- a/Source/kwsys/SharedForward.h.in
+++ b/Source/kwsys/SharedForward.h.in
@@ -1,7 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef @KWSYS_NAMESPACE@_SharedForward_h
-#define @KWSYS_NAMESPACE@_SharedForward_h
+# define @KWSYS_NAMESPACE@_SharedForward_h
/*
This header is used to create a forwarding executable sets up the
@@ -59,134 +59,134 @@
/* Disable -Wcast-qual warnings since they are too hard to fix in a
cross-platform way. */
-#if defined(__clang__) && defined(__has_warning)
-#if __has_warning("-Wcast-qual")
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
-#endif
-#endif
-
-#if defined(__BORLANDC__) && !defined(__cplusplus)
+# if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wcast-qual")
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wcast-qual"
+# endif
+# endif
+
+# if defined(__BORLANDC__) && !defined(__cplusplus)
/* Code has no effect; raised by winnt.h in C (not C++) when ignoring an
unused parameter using "(param)" syntax (i.e. no cast to void). */
-#pragma warn - 8019
-#endif
+# pragma warn - 8019
+# endif
/* 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
+# 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
+# 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
+# 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
+# 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
+# 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
+# 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
+# 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
+# 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
+# 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 <errno.h>
-#include <limits.h>
-#include <stddef.h> /* size_t */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+# include <errno.h>
+# include <limits.h>
+# include <stddef.h> /* size_t */
+# include <stdio.h>
+# include <stdlib.h>
+# include <string.h>
-#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <windows.h>
+# if defined(_WIN32) && !defined(__CYGWIN__)
+# include <windows.h>
-#include <io.h>
-#include <process.h>
-#define KWSYS_SHARED_FORWARD_ESCAPE_ARGV /* re-escape argv for execvp */
-#else
-#include <sys/stat.h>
-#include <unistd.h>
-#endif
+# include <io.h>
+# include <process.h>
+# define KWSYS_SHARED_FORWARD_ESCAPE_ARGV /* re-escape argv for execvp */
+# else
+# include <sys/stat.h>
+# include <unistd.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
+# 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
};
@@ -195,99 +195,101 @@ static const char kwsys_shared_forward_path_slash[2] = {
};
/* 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
+# 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"
+# 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"
+# 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"
+# 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"
+/* OS X */
+# 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"
+# 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
+# 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
+# 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
+# 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"
+# 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"
+# 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
+# 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
+# ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV
typedef struct kwsys_sf_arg_info_s
{
const char* arg;
@@ -404,25 +406,25 @@ static char* kwsys_sf_get_arg(kwsys_sf_arg_info info, char* out)
return out;
}
-#endif
+# 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__)
+# 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
+# else
/* Implementation for UNIX. */
return realpath(in_path, out_path) != 0;
-#endif
+# endif
}
static int kwsys_shared_forward_samepath(const char* file1, const char* file2)
{
-#if defined(_WIN32)
+# if defined(_WIN32)
int result = 0;
HANDLE h1 = CreateFileA(file1, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
@@ -440,19 +442,19 @@ static int kwsys_shared_forward_samepath(const char* file1, const char* file2)
CloseHandle(h1);
CloseHandle(h2);
return result;
-#else
+# 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
+# endif
}
/* Function to report a system error message. */
static void kwsys_shared_forward_strerror(char* message)
{
-#if defined(_WIN32) && !defined(__CYGWIN__)
+# if defined(_WIN32) && !defined(__CYGWIN__)
/* Implementation for Windows. */
DWORD original = GetLastError();
DWORD length =
@@ -465,17 +467,17 @@ static void kwsys_shared_forward_strerror(char* message)
"Error 0x%X (FormatMessage failed with error 0x%X)", original,
GetLastError());
}
-#else
+# else
/* Implementation for UNIX. */
strcpy(message, strerror(errno));
-#endif
+# 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
+# ifdef KWSYS_SHARED_FORWARD_ESCAPE_ARGV
/* Count the number of arguments. */
int argc = 0;
{
@@ -498,16 +500,16 @@ static void kwsys_shared_forward_execvp(const char* cmd,
/* Replace the command line to be used. */
argv = (char const* const*)nargv;
}
-#endif
+# endif
/* Invoke the child process. */
-#if defined(_MSC_VER)
+# if defined(_MSC_VER)
_execvp(cmd, argv);
-#elif defined(__MINGW32__) && !defined(__MINGW64__)
+# elif defined(__MINGW32__) && !defined(__MINGW64__)
execvp(cmd, argv);
-#else
+# else
execvp(cmd, (char* const*)argv);
-#endif
+# endif
}
/* Function to get the directory containing the given file or directory. */
@@ -530,14 +532,14 @@ static void kwsys_shared_forward_dirname(const char* begin, char* result)
/* Only one leading slash. */
strcpy(result, kwsys_shared_forward_path_slash);
}
-#if defined(_WIN32)
+# 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
+# endif
else {
/* A non-leading slash. */
strncpy(result, begin, (size_t)last_slash_index);
@@ -548,16 +550,16 @@ static void kwsys_shared_forward_dirname(const char* begin, char* result)
/* 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 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 {
@@ -641,12 +643,12 @@ static int kwsys_shared_forward_fullpath(const char* self_path,
/* Already a full path. */
strcpy(result, in_path);
}
-#if defined(_WIN32)
+# if defined(_WIN32)
else if (in_path[0] && in_path[1] == ':') {
/* Already a full path. */
strcpy(result, in_path);
}
-#endif
+# endif
else {
/* Relative to self path. */
char temp_path[KWSYS_SHARED_FORWARD_MAXPATH];
@@ -683,14 +685,14 @@ static int kwsys_shared_forward_get_settings(const char* self_path,
const char* exe_path;
/* Get the real name of the build and self paths. */
-#if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
+# 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
+# else
char build_path[] = KWSYS_SHARED_FORWARD_DIR_BUILD;
const char* self_path_logical = self_path;
-#endif
+# 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)) {
@@ -706,29 +708,29 @@ static int kwsys_shared_forward_get_settings(const char* self_path,
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)
+# if defined(_WIN32)
exe_path = KWSYS_SHARED_FORWARD_EXE_BUILD ".exe";
-#else
+# else
exe_path = KWSYS_SHARED_FORWARD_EXE_BUILD;
-#endif
+# endif
-#if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
+# if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
/* Remove the configuration directory from self_path. */
kwsys_shared_forward_dirname(self_path, self_path_logical);
-#endif
+# endif
} else {
/* Running in install tree. Use the install path and exe. */
search_path = search_path_install;
-#if defined(_WIN32)
+# if defined(_WIN32)
exe_path = KWSYS_SHARED_FORWARD_EXE_INSTALL ".exe";
-#else
+# else
exe_path = KWSYS_SHARED_FORWARD_EXE_INSTALL;
-#endif
+# endif
-#if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
+# if defined(KWSYS_SHARED_FORWARD_CONFIG_NAME)
/* Use the original self path directory. */
strcpy(self_path_logical, self_path);
-#endif
+# endif
}
/* Construct the runtime search path. */
@@ -795,7 +797,7 @@ static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in)
/* Store the environment variable. */
putenv(kwsys_shared_forward_ldpath);
-#if defined(KWSYS_SHARED_FORWARD_OPTION_COMMAND)
+# 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) {
@@ -806,14 +808,15 @@ static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in)
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");
+ fprintf(stderr,
+ "Option " KWSYS_SHARED_FORWARD_OPTION_COMMAND
+ " must be followed by a command line.\n");
return 1;
}
}
-#endif
+# endif
-#if defined(KWSYS_SHARED_FORWARD_OPTION_PRINT)
+# 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) {
@@ -821,12 +824,12 @@ static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in)
fprintf(stdout, "%s\n", exe);
return 0;
}
-#endif
+# endif
-#if defined(KWSYS_SHARED_FORWARD_OPTION_LDD)
+# 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)
+# 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;
@@ -835,13 +838,13 @@ static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in)
/* Report why execution failed. */
kwsys_shared_forward_print_failure(ldd_argv);
return 1;
-#else
+# 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
}
-#endif
+# endif
/* Replace this process with the real executable. */
argv[0] = exe;
@@ -865,12 +868,12 @@ static int @KWSYS_NAMESPACE@_shared_forward_to_real(int argc, char** argv_in)
}
/* Restore warning stack. */
-#if defined(__clang__) && defined(__has_warning)
-#if __has_warning("-Wcast-qual")
-#pragma clang diagnostic pop
-#endif
-#endif
+# if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wcast-qual")
+# pragma clang diagnostic pop
+# endif
+# endif
#else
-#error "@KWSYS_NAMESPACE@/SharedForward.h should be included only once."
+# error "@KWSYS_NAMESPACE@/SharedForward.h should be included only once."
#endif
diff --git a/Source/kwsys/String.c b/Source/kwsys/String.c
index 048222968..daf7ad1a0 100644
--- a/Source/kwsys/String.c
+++ b/Source/kwsys/String.c
@@ -8,23 +8,23 @@ 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)
+# 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
+# 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
+# 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[] = {
@@ -58,16 +58,16 @@ static char kwsysString_strcasecmp_tolower[] = {
'\363', '\364', '\365', '\366', '\367', '\370', '\371', '\372', '\373',
'\374', '\375', '\376', '\377'
};
-#endif
+# endif
/*--------------------------------------------------------------------------*/
int kwsysString_strcasecmp(const char* lhs, const char* rhs)
{
-#if defined(KWSYS_STRING_USE_STRICMP)
+# if defined(KWSYS_STRING_USE_STRICMP)
return _stricmp(lhs, rhs);
-#elif defined(KWSYS_STRING_USE_STRCASECMP)
+# elif defined(KWSYS_STRING_USE_STRCASECMP)
return strcasecmp(lhs, rhs);
-#else
+# else
const char* const lower = kwsysString_strcasecmp_tolower;
unsigned char const* us1 = (unsigned char const*)lhs;
unsigned char const* us2 = (unsigned char const*)rhs;
@@ -75,17 +75,17 @@ int kwsysString_strcasecmp(const char* lhs, const char* rhs)
while ((result = lower[*us1] - lower[*us2++], result == 0) && *us1++) {
}
return result;
-#endif
+# endif
}
/*--------------------------------------------------------------------------*/
int kwsysString_strncasecmp(const char* lhs, const char* rhs, size_t n)
{
-#if defined(KWSYS_STRING_USE_STRICMP)
+# if defined(KWSYS_STRING_USE_STRICMP)
return _strnicmp(lhs, rhs, n);
-#elif defined(KWSYS_STRING_USE_STRCASECMP)
+# elif defined(KWSYS_STRING_USE_STRCASECMP)
return strncasecmp(lhs, rhs, n);
-#else
+# else
const char* const lower = kwsysString_strcasecmp_tolower;
unsigned char const* us1 = (unsigned char const*)lhs;
unsigned char const* us2 = (unsigned char const*)rhs;
@@ -94,7 +94,7 @@ int kwsysString_strncasecmp(const char* lhs, const char* rhs, size_t n)
--n;
}
return result;
-#endif
+# endif
}
#endif /* KWSYS_STRING_C */
diff --git a/Source/kwsys/String.h.in b/Source/kwsys/String.h.in
index 3c1d571c0..7c9348af1 100644
--- a/Source/kwsys/String.h.in
+++ b/Source/kwsys/String.h.in
@@ -12,12 +12,12 @@
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
+# 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)
+# define kwsysString_strcasecmp kwsys_ns(String_strcasecmp)
+# define kwsysString_strncasecmp kwsys_ns(String_strncasecmp)
#endif
#if defined(__cplusplus)
@@ -46,12 +46,12 @@ kwsysEXPORT int kwsysString_strncasecmp(const char* lhs, const char* rhs,
/* 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
+# 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/System.c b/Source/kwsys/System.c
index b9af8e9d9..d43cc6fbb 100644
--- a/Source/kwsys/System.c
+++ b/Source/kwsys/System.c
@@ -6,7 +6,7 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "System.h.in"
+# include "System.h.in"
#endif
#include <ctype.h> /* isspace */
diff --git a/Source/kwsys/System.h.in b/Source/kwsys/System.h.in
index 102974db7..a9d4f5e69 100644
--- a/Source/kwsys/System.h.in
+++ b/Source/kwsys/System.h.in
@@ -10,11 +10,12 @@
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
+# 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_Parse_CommandForUnix \
+ kwsys_ns(System_Parse_CommandForUnix)
#endif
#if defined(__cplusplus)
@@ -49,11 +50,11 @@ kwsysEXPORT char** kwsysSystem_Parse_CommandForUnix(const char* command,
/* 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
-#endif
+# undef kwsys_ns
+# undef kwsysEXPORT
+# if !defined(KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
+# undef kwsysSystem_Parse_CommandForUnix
+# endif
#endif
#endif
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index 86fdccdc7..7dc6cf4b0 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/SystemInformation.cxx
@@ -1,15 +1,18 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#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
+# define NOMINMAX // use our min,max
+# if !defined(_WIN32_WINNT) && defined(_MSC_VER) && _MSC_VER >= 1800
+# define _WIN32_WINNT 0x0600 // vista
+# endif
+# 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
+# define _GNU_SOURCE
#endif
// TODO:
@@ -31,8 +34,8 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Process.h.in"
-#include "SystemInformation.hxx.in"
+# include "Process.h.in"
+# include "SystemInformation.hxx.in"
#endif
#include <algorithm>
@@ -47,114 +50,117 @@
#include <vector>
#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)
+# 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
+# endif
#else
-#include <sys/types.h>
-
-#include <errno.h> // extern int errno;
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/resource.h> // getrlimit
-#include <sys/time.h>
-#include <sys/utsname.h> // int uname(struct utsname *buf);
-#include <unistd.h>
+# include <sys/types.h>
+
+# include <errno.h> // extern int errno;
+# include <fcntl.h>
+# include <signal.h>
+# include <sys/resource.h> // getrlimit
+# include <sys/time.h>
+# include <sys/utsname.h> // int uname(struct utsname *buf);
+# include <unistd.h>
#endif
#if defined(__CYGWIN__) && !defined(_WIN32)
-#include <windows.h>
-#undef _WIN32
+# include <windows.h>
+# undef _WIN32
#endif
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
defined(__DragonFly__)
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <sys/sysctl.h>
-#if defined(KWSYS_SYS_HAS_IFADDRS_H)
-#include <ifaddrs.h>
-#include <net/if.h>
-#define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
-#endif
+# include <netdb.h>
+# include <netinet/in.h>
+# include <sys/param.h>
+# include <sys/socket.h>
+# include <sys/sysctl.h>
+# if defined(KWSYS_SYS_HAS_IFADDRS_H)
+# include <ifaddrs.h>
+# include <net/if.h>
+# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
+# endif
#endif
#if defined(KWSYS_SYS_HAS_MACHINE_CPU_H)
-#include <machine/cpu.h>
+# include <machine/cpu.h>
#endif
#ifdef __APPLE__
-#include <fenv.h>
-#include <mach/host_info.h>
-#include <mach/mach.h>
-#include <mach/mach_types.h>
-#include <mach/vm_statistics.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <sys/sysctl.h>
-#if defined(KWSYS_SYS_HAS_IFADDRS_H)
-#include <ifaddrs.h>
-#include <net/if.h>
-#define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
-#endif
-#if !(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0 >= 1050)
-#undef KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE
-#endif
-#endif
-
-#if defined(__linux) || defined(__sun) || defined(_SCO_DS)
-#include <fenv.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#if defined(KWSYS_SYS_HAS_IFADDRS_H)
-#include <ifaddrs.h>
-#include <net/if.h>
-#if !defined(__LSB_VERSION__) /* LSB has no getifaddrs */
-#define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
-#endif
-#endif
-#if defined(KWSYS_CXX_HAS_RLIMIT64)
+# include <mach/host_info.h>
+# include <mach/mach.h>
+# include <mach/mach_types.h>
+# include <mach/vm_statistics.h>
+# include <netdb.h>
+# include <netinet/in.h>
+# include <sys/socket.h>
+# include <sys/sysctl.h>
+# if defined(KWSYS_SYS_HAS_IFADDRS_H)
+# include <ifaddrs.h>
+# include <net/if.h>
+# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
+# endif
+# if !(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0 >= 1050)
+# undef KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE
+# endif
+#endif
+
+#if defined(__linux) || defined(__sun) || defined(_SCO_DS) || \
+ defined(__GLIBC__) || defined(__GNU__)
+# include <netdb.h>
+# include <netinet/in.h>
+# include <sys/socket.h>
+# if defined(KWSYS_SYS_HAS_IFADDRS_H)
+# include <ifaddrs.h>
+# include <net/if.h>
+# if defined(__LSB_VERSION__)
+/* LSB has no getifaddrs */
+# elif defined(__ANDROID_API__) && __ANDROID_API__ < 24
+/* Android has no getifaddrs prior to API 24. */
+# else
+# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
+# endif
+# endif
+# if defined(KWSYS_CXX_HAS_RLIMIT64)
typedef struct rlimit64 ResourceLimitType;
-#define GetResourceLimit getrlimit64
-#else
+# define GetResourceLimit getrlimit64
+# else
typedef struct rlimit ResourceLimitType;
-#define GetResourceLimit getrlimit
-#endif
+# 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
+# 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>
+# 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
+# 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
+# undef KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE
+# undef KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP
#endif
#include <ctype.h> // int isdigit(int c);
@@ -164,57 +170,57 @@ typedef struct rlimit ResourceLimitType;
#include <string.h>
#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
+# 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
+# if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
+# define iostreamLongLong(x) (x)
+# else
+# define iostreamLongLong(x) ((long)(x))
+# endif
#else
-#error "No Long Long"
+# error "No Long Long"
#endif
#if defined(KWSYS_CXX_HAS_ATOLL)
-#define atoLongLong 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
+# 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) && \
!defined(__clang__)
-#define USE_ASM_INSTRUCTIONS 1
+# define USE_ASM_INSTRUCTIONS 1
#else
-#define USE_ASM_INSTRUCTIONS 0
+# define USE_ASM_INSTRUCTIONS 0
#endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__clang__)
-#include <intrin.h>
-#define USE_CPUID_INTRINSICS 1
+# include <intrin.h>
+# define USE_CPUID_INTRINSICS 1
#else
-#define USE_CPUID_INTRINSICS 0
+# define USE_CPUID_INTRINSICS 0
#endif
#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || \
defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
-#define USE_CPUID 1
+# define USE_CPUID 1
#else
-#define USE_CPUID 0
+# define USE_CPUID 0
#endif
#if USE_CPUID
-#define CPUID_AWARE_COMPILER
+# define CPUID_AWARE_COMPILER
/**
* call CPUID instruction
@@ -223,16 +229,16 @@ typedef struct rlimit ResourceLimitType;
*/
static bool call_cpuid(int select, int result[4])
{
-#if USE_CPUID_INTRINSICS
+# if USE_CPUID_INTRINSICS
__cpuid(result, select);
return true;
-#else
+# else
int tmp[4];
-#if defined(_MSC_VER)
+# if defined(_MSC_VER)
// Use SEH to determine CPUID presence
__try {
_asm {
-#ifdef CPUID_AWARE_COMPILER
+# 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.
@@ -240,33 +246,33 @@ static bool call_cpuid(int select, int result[4])
push ebx
push ecx
push edx
-#endif
+# endif
; <<CPUID>>
mov eax, select
-#ifdef CPUID_AWARE_COMPILER
+# ifdef CPUID_AWARE_COMPILER
cpuid
-#else
+# else
_asm _emit 0x0f
_asm _emit 0xa2
-#endif
+# 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
+# ifdef CPUID_AWARE_COMPILER
pop edx
pop ecx
pop ebx
pop eax
-#endif
+# endif
}
} __except (1) {
return false;
}
memcpy(result, tmp, sizeof(tmp));
-#elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
+# elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
unsigned int a, b, c, d;
__asm {
mov EAX, select;
@@ -281,11 +287,11 @@ static bool call_cpuid(int select, int result[4])
result[1] = b;
result[2] = c;
result[3] = d;
-#endif
+# endif
// The cpuid instruction succeeded.
return true;
-#endif
+# endif
}
#endif
@@ -340,7 +346,7 @@ public:
bool DoesCPUSupportCPUID();
- // Retrieve memory information in megabyte.
+ // Retrieve memory information in MiB.
size_t GetTotalVirtualMemory();
size_t GetAvailableVirtualMemory();
size_t GetTotalPhysicalMemory();
@@ -348,7 +354,7 @@ public:
LongLong GetProcessId();
- // Retrieve memory information in kib
+ // Retrieve memory information in KiB.
LongLong GetHostMemoryTotal();
LongLong GetHostMemoryAvailable(const char* envVarName);
LongLong GetHostMemoryUsed();
@@ -441,6 +447,7 @@ public:
IBM,
Motorola,
HP,
+ Hygon,
UnknownManufacturer
};
@@ -736,7 +743,7 @@ bool SystemInformation::DoesCPUSupportCPUID()
return this->Implementation->DoesCPUSupportCPUID();
}
-// Retrieve memory information in megabyte.
+// Retrieve memory information in MiB.
size_t SystemInformation::GetTotalVirtualMemory()
{
return this->Implementation->GetTotalVirtualMemory();
@@ -881,7 +888,7 @@ int LoadLines(FILE* file, std::vector<std::string>& lines)
char buf[bufSize] = { '\0' };
while (!feof(file) && !ferror(file)) {
errno = 0;
- if (fgets(buf, bufSize, file) == 0) {
+ if (fgets(buf, bufSize, file) == KWSYS_NULLPTR) {
if (ferror(file) && (errno == EINTR)) {
clearerr(file);
}
@@ -902,7 +909,7 @@ int LoadLines(FILE* file, std::vector<std::string>& lines)
return nRead;
}
-#if defined(__linux)
+# if defined(__linux)
// *****************************************************************************
int LoadLines(const char* fileName, std::vector<std::string>& lines)
{
@@ -914,7 +921,7 @@ int LoadLines(const char* fileName, std::vector<std::string>& lines)
fclose(file);
return nRead;
}
-#endif
+# endif
// ****************************************************************************
template <typename T>
@@ -977,7 +984,7 @@ int GetFieldsFromCommand(const char* command, const char** fieldNames,
T* values)
{
FILE* file = popen(command, "r");
- if (file == 0) {
+ if (file == KWSYS_NULLPTR) {
return -1;
}
std::vector<std::string> fields;
@@ -987,7 +994,7 @@ int GetFieldsFromCommand(const char* command, const char** fieldNames,
return -1;
}
int i = 0;
- while (fieldNames[i] != NULL) {
+ while (fieldNames[i] != KWSYS_NULLPTR) {
int ierr = NameValue(fields, fieldNames[i], values[i]);
if (ierr) {
return -(i + 2);
@@ -1003,7 +1010,7 @@ int GetFieldsFromCommand(const char* command, const char** fieldNames,
void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
void* /*sigContext*/)
{
-#if defined(__linux) || defined(__APPLE__)
+# if defined(__linux) || defined(__APPLE__)
std::ostringstream oss;
oss << std::endl
<< "========================================================="
@@ -1023,20 +1030,21 @@ void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
break;
case SIGFPE:
- oss << "Caught SIGFPE at " << (sigInfo->si_addr == 0 ? "0x" : "")
+ oss << "Caught SIGFPE at "
+ << (sigInfo->si_addr == KWSYS_NULLPTR ? "0x" : "")
<< sigInfo->si_addr << " ";
switch (sigInfo->si_code) {
-#if defined(FPE_INTDIV)
+# if defined(FPE_INTDIV)
case FPE_INTDIV:
oss << "integer division by zero";
break;
-#endif
+# endif
-#if defined(FPE_INTOVF)
+# if defined(FPE_INTOVF)
case FPE_INTOVF:
oss << "integer overflow";
break;
-#endif
+# endif
case FPE_FLTDIV:
oss << "floating point divide by zero";
@@ -1058,11 +1066,11 @@ void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
oss << "floating point invalid operation";
break;
-#if defined(FPE_FLTSUB)
+# if defined(FPE_FLTSUB)
case FPE_FLTSUB:
oss << "floating point subscript out of range";
break;
-#endif
+# endif
default:
oss << "code " << sigInfo->si_code;
@@ -1071,7 +1079,8 @@ void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
break;
case SIGSEGV:
- oss << "Caught SIGSEGV at " << (sigInfo->si_addr == 0 ? "0x" : "")
+ oss << "Caught SIGSEGV at "
+ << (sigInfo->si_addr == KWSYS_NULLPTR ? "0x" : "")
<< sigInfo->si_addr << " ";
switch (sigInfo->si_code) {
case SEGV_MAPERR:
@@ -1089,38 +1098,39 @@ void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
break;
case SIGBUS:
- oss << "Caught SIGBUS at " << (sigInfo->si_addr == 0 ? "0x" : "")
+ oss << "Caught SIGBUS at "
+ << (sigInfo->si_addr == KWSYS_NULLPTR ? "0x" : "")
<< sigInfo->si_addr << " ";
switch (sigInfo->si_code) {
case BUS_ADRALN:
oss << "invalid address alignment";
break;
-#if defined(BUS_ADRERR)
+# if defined(BUS_ADRERR)
case BUS_ADRERR:
oss << "nonexistent physical address";
break;
-#endif
+# endif
-#if defined(BUS_OBJERR)
+# if defined(BUS_OBJERR)
case BUS_OBJERR:
oss << "object-specific hardware error";
break;
-#endif
+# endif
-#if defined(BUS_MCEERR_AR)
+# if defined(BUS_MCEERR_AR)
case BUS_MCEERR_AR:
oss << "Hardware memory error consumed on a machine check; action "
"required.";
break;
-#endif
+# endif
-#if defined(BUS_MCEERR_AO)
+# if defined(BUS_MCEERR_AO)
case BUS_MCEERR_AO:
oss << "Hardware memory error detected in process but not consumed; "
"action optional.";
break;
-#endif
+# endif
default:
oss << "code " << sigInfo->si_code;
@@ -1129,24 +1139,25 @@ void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
break;
case SIGILL:
- oss << "Caught SIGILL at " << (sigInfo->si_addr == 0 ? "0x" : "")
+ oss << "Caught SIGILL at "
+ << (sigInfo->si_addr == KWSYS_NULLPTR ? "0x" : "")
<< sigInfo->si_addr << " ";
switch (sigInfo->si_code) {
case ILL_ILLOPC:
oss << "illegal opcode";
break;
-#if defined(ILL_ILLOPN)
+# if defined(ILL_ILLOPN)
case ILL_ILLOPN:
oss << "illegal operand";
break;
-#endif
+# endif
-#if defined(ILL_ILLADR)
+# if defined(ILL_ILLADR)
case ILL_ILLADR:
oss << "illegal addressing mode.";
break;
-#endif
+# endif
case ILL_ILLTRP:
oss << "illegal trap";
@@ -1156,23 +1167,23 @@ void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
oss << "privileged opcode";
break;
-#if defined(ILL_PRVREG)
+# if defined(ILL_PRVREG)
case ILL_PRVREG:
oss << "privileged register";
break;
-#endif
+# endif
-#if defined(ILL_COPROC)
+# if defined(ILL_COPROC)
case ILL_COPROC:
oss << "co-processor error";
break;
-#endif
+# endif
-#if defined(ILL_BADSTK)
+# if defined(ILL_BADSTK)
case ILL_BADSTK:
oss << "internal stack error";
break;
-#endif
+# endif
default:
oss << "code " << sigInfo->si_code;
@@ -1195,16 +1206,16 @@ void StacktraceSignalHandler(int sigNo, siginfo_t* sigInfo,
// and abort
SystemInformationImplementation::SetStackTraceOnError(0);
abort();
-#else
+# else
// avoid warning C4100
(void)sigNo;
(void)sigInfo;
-#endif
+# endif
}
#endif
#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
-#define safes(_arg) ((_arg) ? (_arg) : "???")
+# define safes(_arg) ((_arg) ? (_arg) : "???")
// Description:
// A container for symbol properties. Each instance
@@ -1264,7 +1275,7 @@ public:
long GetLineNumber() const { return this->LineNumber; }
// Description:
- // Set the address where the biinary image is mapped
+ // Set the address where the binary image is mapped
// into memory.
void SetBinaryBaseAddress(void* address)
{
@@ -1292,19 +1303,19 @@ private:
std::ostream& operator<<(std::ostream& os, const SymbolProperties& sp)
{
-#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
os << std::hex << sp.GetAddress() << " : " << sp.GetFunction() << " [("
<< sp.GetBinary() << ") " << sp.GetSourceFile() << ":" << std::dec
<< sp.GetLineNumber() << "]";
-#elif defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+# elif defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
void* addr = sp.GetAddress();
char** syminfo = backtrace_symbols(&addr, 1);
os << safes(syminfo[0]);
free(syminfo);
-#else
+# else
(void)os;
(void)sp;
-#endif
+# endif
return os;
}
@@ -1313,8 +1324,8 @@ SymbolProperties::SymbolProperties()
// not using an initializer list
// to avoid some PGI compiler warnings
this->SetBinary("???");
- this->SetBinaryBaseAddress(NULL);
- this->Address = NULL;
+ this->SetBinaryBaseAddress(KWSYS_NULLPTR);
+ this->Address = KWSYS_NULLPTR;
this->SetSourceFile("???");
this->SetFunction("???");
this->SetLineNumber(-1);
@@ -1341,12 +1352,12 @@ std::string SymbolProperties::GetFileName(const std::string& path) const
std::string SymbolProperties::GetBinary() const
{
// only linux has proc fs
-#if defined(__linux__)
+# if defined(__linux__)
if (this->Binary == "/proc/self/exe") {
std::string binary;
char buf[1024] = { '\0' };
ssize_t ll = 0;
- if ((ll = readlink("/proc/self/exe", buf, 1024)) > 0) {
+ if ((ll = readlink("/proc/self/exe", buf, 1024)) > 0 && ll < 1024) {
buf[ll] = '\0';
binary = buf;
} else {
@@ -1354,14 +1365,14 @@ std::string SymbolProperties::GetBinary() const
}
return this->GetFileName(binary);
}
-#endif
+# endif
return this->GetFileName(this->Binary);
}
std::string SymbolProperties::Demangle(const char* symbol) const
{
std::string result = safes(symbol);
-#if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
int status = 0;
size_t bufferLen = 1024;
char* buffer = (char*)malloc(1024);
@@ -1371,16 +1382,16 @@ std::string SymbolProperties::Demangle(const char* symbol) const
result = demangledSymbol;
}
free(buffer);
-#else
+# else
(void)symbol;
-#endif
+# endif
return result;
}
void SymbolProperties::Initialize(void* address)
{
this->Address = address;
-#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
// first fallback option can demangle c++ functions
Dl_info info;
int ierr = dladdr(this->Address, &info);
@@ -1388,18 +1399,18 @@ void SymbolProperties::Initialize(void* address)
this->SetBinary(info.dli_fname);
this->SetFunction(info.dli_sname);
}
-#else
+# else
// second fallback use builtin backtrace_symbols
// to decode the bactrace.
-#endif
+# endif
}
#endif // don't define this class if we're not using it
#if defined(_WIN32) || defined(__CYGWIN__)
-#define KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes
+# define KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes
#endif
#if defined(_MSC_VER) && _MSC_VER < 1310
-#undef KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes
+# undef KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes
#endif
#if defined(KWSYS_SYSTEMINFORMATION_USE_GetSystemTimes)
double calculateCPULoad(unsigned __int64 idleTicks,
@@ -1649,7 +1660,7 @@ int SystemInformationImplementation::GetFullyQualifiedDomainName(
// 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
+ // with a failure code. Return of a failure code is not necessarily
// 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
@@ -1671,7 +1682,7 @@ int SystemInformationImplementation::GetFullyQualifiedDomainName(
return -2;
}
- for (ifa = ifas; ifa != NULL; ifa = ifa->ifa_next) {
+ for (ifa = ifas; ifa != KWSYS_NULLPTR; ifa = ifa->ifa_next) {
int fam = ifa->ifa_addr ? ifa->ifa_addr->sa_family : -1;
// Skip Loopback interfaces
if (((fam == AF_INET) || (fam == AF_INET6)) &&
@@ -1682,7 +1693,7 @@ int SystemInformationImplementation::GetFullyQualifiedDomainName(
: sizeof(struct sockaddr_in6));
ierr = getnameinfo(ifa->ifa_addr, static_cast<socklen_t>(addrlen), host,
- NI_MAXHOST, NULL, 0, NI_NAMEREQD);
+ NI_MAXHOST, KWSYS_NULLPTR, 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.
@@ -1759,6 +1770,8 @@ const char* SystemInformationImplementation::GetVendorID()
return "Motorola";
case HP:
return "Hewlett-Packard";
+ case Hygon:
+ return "Chengdu Haiguang IC Design Co., Ltd.";
case UnknownManufacturer:
default:
return "Unknown Manufacturer";
@@ -2004,12 +2017,12 @@ bool SystemInformationImplementation::DoesCPUSupportCPUID()
#if USE_CPUID
int dummy[4] = { 0, 0, 0, 0 };
-#if USE_ASM_INSTRUCTIONS
+# if USE_ASM_INSTRUCTIONS
return call_cpuid(0, dummy);
-#else
+# else
call_cpuid(0, dummy);
return dummy[0] || dummy[1] || dummy[2] || dummy[3];
-#endif
+# endif
#else
// Assume no cpuid instruction.
return false;
@@ -2051,7 +2064,7 @@ bool SystemInformationImplementation::RetrieveCPUFeatures()
this->Features.HasIA64 =
((cpuinfo[3] & 0x40000000) != 0); // IA64 Present --> Bit 30
-#if USE_ASM_INSTRUCTIONS
+# if USE_ASM_INSTRUCTIONS
// Retrieve extended SSE capabilities if SSE is available.
if (this->Features.HasSSE) {
@@ -2075,9 +2088,9 @@ bool SystemInformationImplementation::RetrieveCPUFeatures()
// Set the advanced SSE capabilities to not available.
this->Features.HasSSEFP = false;
}
-#else
+# else
this->Features.HasSSEFP = false;
-#endif
+# endif
// Retrieve Intel specific extended features.
if (this->ChipManufacturer == Intel) {
@@ -2110,6 +2123,8 @@ void SystemInformationImplementation::FindManufacturer(
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 == "HygonGenuine")
+ this->ChipManufacturer = Hygon; // Chengdu Haiguang IC Design Co., Ltd.
else if (this->ChipID.Vendor == "CyrixInstead")
this->ChipManufacturer = Cyrix; // Cyrix Corp., VIA Inc.
else if (this->ChipID.Vendor == "NexGenDriven")
@@ -2744,7 +2759,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures()
0); // MP Capable -- > Bit 19.
// Retrieve AMD specific extended features.
- if (this->ChipManufacturer == AMD) {
+ if (this->ChipManufacturer == AMD || this->ChipManufacturer == Hygon) {
this->Features.ExtendedFeatures.HasMMXPlus =
((localCPUExtendedFeatures[3] & 0x00400000) !=
0); // AMD specific: MMX-SSE --> Bit 22
@@ -3151,6 +3166,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity()
}
break;
+ case Hygon:
+ this->ChipID.ProcessorName = "Unknown Hygon family";
+ return false;
+
case Transmeta:
switch (this->ChipID.Family) {
case 5:
@@ -3489,7 +3508,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
// Chip Model Name
this->ChipID.ModelName =
- this->ExtractValueFromCpuInfoFile(buffer, "model name").c_str();
+ this->ExtractValueFromCpuInfoFile(buffer, "model name");
// L1 Cache size
// Different architectures may show different names for the caches.
@@ -3558,7 +3577,7 @@ bool SystemInformationImplementation::QueryProcessorBySysconf()
{
#if defined(_SC_NPROC_ONLN) && !defined(_SC_NPROCESSORS_ONLN)
// IRIX names this slightly different
-#define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
+# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
#endif
#ifdef _SC_NPROCESSORS_ONLN
@@ -3588,17 +3607,17 @@ SystemInformation::LongLong
SystemInformationImplementation::GetHostMemoryTotal()
{
#if defined(_WIN32)
-#if defined(_MSC_VER) && _MSC_VER < 1300
+# if defined(_MSC_VER) && _MSC_VER < 1300
MEMORYSTATUS stat;
stat.dwLength = sizeof(stat);
GlobalMemoryStatus(&stat);
return stat.dwTotalPhys / 1024;
-#else
+# else
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
return statex.ullTotalPhys / 1024;
-#endif
+# endif
#elif defined(__linux)
SystemInformation::LongLong memTotal = 0;
int ierr = GetFieldFromFile("/proc/meminfo", "MemTotal:", memTotal);
@@ -3609,7 +3628,7 @@ SystemInformationImplementation::GetHostMemoryTotal()
#elif defined(__APPLE__)
uint64_t mem;
size_t len = sizeof(mem);
- int ierr = sysctlbyname("hw.memsize", &mem, &len, NULL, 0);
+ int ierr = sysctlbyname("hw.memsize", &mem, &len, KWSYS_NULLPTR, 0);
if (ierr) {
return -1;
}
@@ -3633,7 +3652,7 @@ SystemInformationImplementation::GetHostMemoryAvailable(
// 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
+ // access to it is severely restricted. The system will
// apply a limit across a set of processes. Units are in KiB.
if (hostLimitEnvVarName) {
const char* hostLimitEnvVarValue = getenv(hostLimitEnvVarName);
@@ -3713,17 +3732,17 @@ SystemInformation::LongLong
SystemInformationImplementation::GetHostMemoryUsed()
{
#if defined(_WIN32)
-#if defined(_MSC_VER) && _MSC_VER < 1300
+# if defined(_MSC_VER) && _MSC_VER < 1300
MEMORYSTATUS stat;
stat.dwLength = sizeof(stat);
GlobalMemoryStatus(&stat);
return (stat.dwTotalPhys - stat.dwAvailPhys) / 1024;
-#else
+# else
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
return (statex.ullTotalPhys - statex.ullAvailPhys) / 1024;
-#endif
+# endif
#elif defined(__linux)
// First try to use MemAvailable, but it only works on newer kernels
const char* names2[3] = { "MemTotal:", "MemAvailable:", NULL };
@@ -3752,7 +3771,8 @@ SystemInformationImplementation::GetHostMemoryUsed()
if (psz < 1) {
return -1;
}
- const char* names[3] = { "Pages wired down:", "Pages active:", NULL };
+ const char* names[3] = { "Pages wired down:", "Pages active:",
+ KWSYS_NULLPTR };
SystemInformation::LongLong values[2] = { SystemInformation::LongLong(0) };
int ierr = GetFieldsFromCommand("vm_stat", names, values);
if (ierr) {
@@ -3800,7 +3820,7 @@ SystemInformationImplementation::GetProcMemoryUsed()
std::ostringstream oss;
oss << "ps -o rss= -p " << pid;
FILE* file = popen(oss.str().c_str(), "r");
- if (file == 0) {
+ if (file == KWSYS_NULLPTR) {
return -1;
}
oss.str("");
@@ -3863,7 +3883,8 @@ SystemInformation::LongLong SystemInformationImplementation::GetProcessId()
{
#if defined(_WIN32)
return GetCurrentProcessId();
-#elif defined(__linux) || defined(__APPLE__)
+#elif defined(__linux) || defined(__APPLE__) || defined(__OpenBSD__) || \
+ defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
return getpid();
#else
return -1;
@@ -3871,34 +3892,78 @@ SystemInformation::LongLong SystemInformationImplementation::GetProcessId()
}
/**
+ * Used in GetProgramStack(...) below
+ */
+#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && defined(_MSC_VER) && \
+ _MSC_VER >= 1800
+# define KWSYS_SYSTEMINFORMATION_HAS_DBGHELP
+# define TRACE_MAX_STACK_FRAMES 1024
+# define TRACE_MAX_FUNCTION_NAME_LENGTH 1024
+# pragma warning(push)
+# pragma warning(disable : 4091) /* 'typedef ': ignored on left of '' */
+# include "dbghelp.h"
+# pragma warning(pop)
+#endif
+
+/**
return current program stack in a string
demangle cxx symbols if possible.
*/
std::string SystemInformationImplementation::GetProgramStack(int firstFrame,
int wholePath)
{
- std::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"
+ std::ostringstream oss;
+ std::string programStack = "";
+
+#ifdef KWSYS_SYSTEMINFORMATION_HAS_DBGHELP
+ (void)wholePath;
+
+ void* stack[TRACE_MAX_STACK_FRAMES];
+ HANDLE process = GetCurrentProcess();
+ SymInitialize(process, NULL, TRUE);
+ WORD numberOfFrames =
+ CaptureStackBackTrace(firstFrame, TRACE_MAX_STACK_FRAMES, stack, NULL);
+ SYMBOL_INFO* symbol = static_cast<SYMBOL_INFO*>(
+ malloc(sizeof(SYMBOL_INFO) +
+ (TRACE_MAX_FUNCTION_NAME_LENGTH - 1) * sizeof(TCHAR)));
+ symbol->MaxNameLen = TRACE_MAX_FUNCTION_NAME_LENGTH;
+ symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
+ DWORD displacement;
+ IMAGEHLP_LINE64 line;
+ line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
+ for (int i = 0; i < numberOfFrames; i++) {
+ DWORD64 address = reinterpret_cast<DWORD64>(stack[i]);
+ SymFromAddr(process, address, NULL, symbol);
+ if (SymGetLineFromAddr64(process, address, &displacement, &line)) {
+ oss << " at " << symbol->Name << " in " << line.FileName << " line "
+ << line.LineNumber << std::endl;
+ } else {
+ oss << " at " << symbol->Name << std::endl;
+ }
+ }
+ free(symbol);
+
#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
+ 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
;
- std::ostringstream oss;
-#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
void* stackSymbols[256];
int nFrames = backtrace(stackSymbols, 256);
for (int i = firstFrame; i < nFrames; ++i) {
@@ -3907,10 +3972,12 @@ std::string SystemInformationImplementation::GetProgramStack(int firstFrame,
symProps.Initialize(stackSymbols[i]);
oss << symProps << std::endl;
}
-#else
+# else
(void)firstFrame;
(void)wholePath;
+# endif
#endif
+
programStack += oss.str();
return programStack;
@@ -3933,13 +4000,13 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable)
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);
+ sigaction(SIGABRT, KWSYS_NULLPTR, &saABRTOrig);
+ sigaction(SIGSEGV, KWSYS_NULLPTR, &saSEGVOrig);
+ sigaction(SIGTERM, KWSYS_NULLPTR, &saTERMOrig);
+ sigaction(SIGINT, KWSYS_NULLPTR, &saINTOrig);
+ sigaction(SIGILL, KWSYS_NULLPTR, &saILLOrig);
+ sigaction(SIGBUS, KWSYS_NULLPTR, &saBUSOrig);
+ sigaction(SIGFPE, KWSYS_NULLPTR, &saFPEOrig);
// enable read, disable write
saOrigValid = 1;
@@ -3948,27 +4015,27 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable)
struct sigaction sa;
sa.sa_sigaction = (SigAction)StacktraceSignalHandler;
sa.sa_flags = SA_SIGINFO | SA_RESETHAND;
-#ifdef SA_RESTART
+# ifdef SA_RESTART
sa.sa_flags |= SA_RESTART;
-#endif
+# 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);
+ sigaction(SIGABRT, &sa, KWSYS_NULLPTR);
+ sigaction(SIGSEGV, &sa, KWSYS_NULLPTR);
+ sigaction(SIGTERM, &sa, KWSYS_NULLPTR);
+ sigaction(SIGINT, &sa, KWSYS_NULLPTR);
+ sigaction(SIGILL, &sa, KWSYS_NULLPTR);
+ sigaction(SIGBUS, &sa, KWSYS_NULLPTR);
+ sigaction(SIGFPE, &sa, KWSYS_NULLPTR);
} 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);
+ sigaction(SIGABRT, &saABRTOrig, KWSYS_NULLPTR);
+ sigaction(SIGSEGV, &saSEGVOrig, KWSYS_NULLPTR);
+ sigaction(SIGTERM, &saTERMOrig, KWSYS_NULLPTR);
+ sigaction(SIGINT, &saINTOrig, KWSYS_NULLPTR);
+ sigaction(SIGILL, &saILLOrig, KWSYS_NULLPTR);
+ sigaction(SIGBUS, &saBUSOrig, KWSYS_NULLPTR);
+ sigaction(SIGFPE, &saFPEOrig, KWSYS_NULLPTR);
// enable write, disable read
saOrigValid = 0;
@@ -3982,21 +4049,21 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable)
bool SystemInformationImplementation::QueryWindowsMemory()
{
#if defined(_WIN32)
-#if defined(_MSC_VER) && _MSC_VER < 1300
+# 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
+# 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
+# define MEM_VAL(value) ull##value
+# endif
tv = ms.MEM_VAL(TotalPageFile);
tp = ms.MEM_VAL(TotalPhys);
av = ms.MEM_VAL(AvailPageFile);
@@ -4054,7 +4121,7 @@ bool SystemInformationImplementation::QueryLinuxMemory()
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
+ // Rigorously, this test should check from the developing version 2.5.x
// that introduced the new format...
enum
@@ -4179,7 +4246,7 @@ bool SystemInformationImplementation::QueryMemoryBySysconf()
this->TotalPhysicalMemory = p;
this->TotalPhysicalMemory /= pagediv;
-#if defined(_SC_AVPHYS_PAGES)
+# if defined(_SC_AVPHYS_PAGES)
p = sysconf(_SC_AVPHYS_PAGES);
if (p < 0) {
return false;
@@ -4187,7 +4254,7 @@ bool SystemInformationImplementation::QueryMemoryBySysconf()
this->AvailablePhysicalMemory = p;
this->AvailablePhysicalMemory /= pagediv;
-#endif
+# endif
return true;
#else
@@ -4404,7 +4471,7 @@ bool SystemInformationImplementation::ParseSysCtl()
int err = 0;
uint64_t value = 0;
size_t len = sizeof(value);
- sysctlbyname("hw.memsize", &value, &len, NULL, 0);
+ sysctlbyname("hw.memsize", &value, &len, KWSYS_NULLPTR, 0);
this->TotalPhysicalMemory = static_cast<size_t>(value / 1048576);
// Parse values for Mac
@@ -4414,96 +4481,101 @@ bool SystemInformationImplementation::ParseSysCtl()
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;
+ err = sysctlbyname("hw.pagesize", &value, &len, KWSYS_NULLPTR, 0);
+ int64_t available_memory =
+ (vmstat.free_count + vmstat.inactive_count) * value;
this->AvailablePhysicalMemory =
static_cast<size_t>(available_memory / 1048576);
}
-#ifdef VM_SWAPUSAGE
+# 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);
+ err = sysctl(mib, miblen, &swap, &len, KWSYS_NULLPTR, 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
+# else
this->AvailableVirtualMemory = 0;
this->TotalVirtualMemory = 0;
-#endif
+# endif
// CPU Info
len = sizeof(this->NumberOfPhysicalCPU);
- sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, NULL, 0);
+ sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len,
+ KWSYS_NULLPTR, 0);
len = sizeof(this->NumberOfLogicalCPU);
- sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, NULL, 0);
+ sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, KWSYS_NULLPTR,
+ 0);
int cores_per_package = 0;
len = sizeof(cores_per_package);
err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len,
- NULL, 0);
+ KWSYS_NULLPTR, 0);
// That name was not found, default to 1
this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical =
err != 0 ? 1 : static_cast<unsigned char>(cores_per_package);
len = sizeof(value);
- sysctlbyname("hw.cpufrequency", &value, &len, NULL, 0);
+ sysctlbyname("hw.cpufrequency", &value, &len, KWSYS_NULLPTR, 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);
+ err = sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len,
+ KWSYS_NULLPTR, 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);
+ err = sysctlbyname("hw.machine", &retBuf, &len, KWSYS_NULLPTR, 0);
std::string machineBuf(retBuf);
if (machineBuf.find_first_of("Power") != std::string::npos) {
this->ChipID.Vendor = "IBM";
len = sizeof(this->ChipID.Family);
- err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, NULL, 0);
+ err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len,
+ KWSYS_NULLPTR, 0);
len = sizeof(this->ChipID.Model);
- err = sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, NULL, 0);
+ err = sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len,
+ KWSYS_NULLPTR, 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);
+ err = sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len,
+ KWSYS_NULLPTR, 0);
::memset(retBuf, 0, 128);
len = 128;
- err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, NULL, 0);
+ err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, KWSYS_NULLPTR, 0);
// Chip Vendor
this->ChipID.Vendor = retBuf;
this->FindManufacturer();
// Chip Model
len = sizeof(value);
- err = sysctlbyname("machdep.cpu.model", &value, &len, NULL, 0);
+ err = sysctlbyname("machdep.cpu.model", &value, &len, KWSYS_NULLPTR, 0);
this->ChipID.Model = static_cast<int>(value);
// Chip Stepping
len = sizeof(value);
value = 0;
- err = sysctlbyname("machdep.cpu.stepping", &value, &len, NULL, 0);
+ err = sysctlbyname("machdep.cpu.stepping", &value, &len, KWSYS_NULLPTR, 0);
if (!err) {
this->ChipID.Revision = static_cast<int>(value);
}
// feature string
- char* buf = 0;
+ char* buf = KWSYS_NULLPTR;
size_t allocSize = 128;
err = 0;
@@ -4520,7 +4592,8 @@ bool SystemInformationImplementation::ParseSysCtl()
}
buf[0] = ' ';
len = allocSize - 2; // keep space for leading and trailing space
- err = sysctlbyname("machdep.cpu.features", buf + 1, &len, NULL, 0);
+ err =
+ sysctlbyname("machdep.cpu.features", buf + 1, &len, KWSYS_NULLPTR, 0);
}
if (!err && buf && len) {
// now we can match every flags as space + flag + space
@@ -4561,7 +4634,8 @@ bool SystemInformationImplementation::ParseSysCtl()
// brand string
::memset(retBuf, 0, sizeof(retBuf));
len = sizeof(retBuf);
- err = sysctlbyname("machdep.cpu.brand_string", retBuf, &len, NULL, 0);
+ err =
+ sysctlbyname("machdep.cpu.brand_string", retBuf, &len, KWSYS_NULLPTR, 0);
if (!err) {
this->ChipID.ProcessorName = retBuf;
this->ChipID.ModelName = retBuf;
@@ -4569,10 +4643,10 @@ bool SystemInformationImplementation::ParseSysCtl()
// Cache size
len = sizeof(value);
- err = sysctlbyname("hw.l1icachesize", &value, &len, NULL, 0);
+ err = sysctlbyname("hw.l1icachesize", &value, &len, KWSYS_NULLPTR, 0);
this->Features.L1CacheSize = static_cast<int>(value);
len = sizeof(value);
- err = sysctlbyname("hw.l2cachesize", &value, &len, NULL, 0);
+ err = sysctlbyname("hw.l2cachesize", &value, &len, KWSYS_NULLPTR, 0);
this->Features.L2CacheSize = static_cast<int>(value);
return true;
@@ -4600,16 +4674,16 @@ std::string SystemInformationImplementation::ExtractValueFromSysCtl(
std::string SystemInformationImplementation::RunProcess(
std::vector<const char*> args)
{
- std::string buffer = "";
+ std::string buffer;
// Run the application
kwsysProcess* gp = kwsysProcess_New();
- kwsysProcess_SetCommand(gp, &*args.begin());
+ kwsysProcess_SetCommand(gp, args.data());
kwsysProcess_SetOption(gp, kwsysProcess_Option_HideWindow, 1);
kwsysProcess_Execute(gp);
- char* data = NULL;
+ char* data = KWSYS_NULLPTR;
int length;
double timeout = 255;
int pipe; // pipe id as returned by kwsysProcess_WaitForData()
@@ -4621,7 +4695,7 @@ std::string SystemInformationImplementation::RunProcess(
{
buffer.append(data, length);
}
- kwsysProcess_WaitForExit(gp, 0);
+ kwsysProcess_WaitForExit(gp, KWSYS_NULLPTR);
int result = 0;
switch (kwsysProcess_GetState(gp)) {
@@ -4655,11 +4729,7 @@ std::string SystemInformationImplementation::RunProcess(
std::string SystemInformationImplementation::ParseValueFromKStat(
const char* arguments)
{
- std::vector<const char*> args;
- args.clear();
- args.push_back("kstat");
- args.push_back("-p");
-
+ std::vector<std::string> args_string;
std::string command = arguments;
size_t start = std::string::npos;
size_t pos = command.find(' ', 0);
@@ -4678,35 +4748,35 @@ std::string SystemInformationImplementation::ParseValueFromKStat(
}
if (!inQuotes) {
- std::string arg = command.substr(start + 1, pos - start - 1);
+ args_string.push_back(command.substr(start + 1, pos - start - 1));
+ std::string& arg = args_string.back();
// Remove the quotes if any
- size_t quotes = arg.find('"');
- while (quotes != std::string::npos) {
- arg.erase(quotes, 1);
- quotes = arg.find('"');
- }
- args.push_back(arg.c_str());
+ arg.erase(std::remove(arg.begin(), arg.end(), '"'), arg.end());
start = pos;
}
pos = command.find(' ', pos + 1);
}
- std::string lastArg = command.substr(start + 1, command.size() - start - 1);
- args.push_back(lastArg.c_str());
+ args_string.push_back(command.substr(start + 1, command.size() - start - 1));
- args.push_back(0);
+ std::vector<const char*> args;
+ args.reserve(3 + args_string.size());
+ args.push_back("kstat");
+ args.push_back("-p");
+ for (size_t i = 0; i < args_string.size(); ++i) {
+ args.push_back(args_string[i].c_str());
+ }
+ args.push_back(KWSYS_NULLPTR);
std::string buffer = this->RunProcess(args);
- std::string value = "";
+ std::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') {
- std::string val = value;
- value = buffer[i];
- value += val;
+ value.insert(0u, 1, buffer[i]);
}
}
return value;
@@ -4720,11 +4790,11 @@ bool SystemInformationImplementation::QuerySolarisMemory()
// 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 SIZEOF_VOID_P == 8
if (this->QueryMemoryBySysconf()) {
return true;
}
-#endif
+# endif
char* tail;
unsigned long totalMemory =
@@ -4887,12 +4957,12 @@ bool SystemInformationImplementation::QueryBSDMemory()
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
defined(__DragonFly__)
int ctrl[2] = { CTL_HW, HW_PHYSMEM };
-#if defined(HW_PHYSMEM64)
+# if defined(HW_PHYSMEM64)
int64_t k;
ctrl[1] = HW_PHYSMEM64;
-#else
+# else
int k;
-#endif
+# endif
size_t sz = sizeof(k);
if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0) {
@@ -4973,7 +5043,7 @@ bool SystemInformationImplementation::QueryBSDProcessor()
this->NumberOfPhysicalCPU = k;
this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
-#if defined(HW_CPUSPEED)
+# if defined(HW_CPUSPEED)
ctrl[1] = HW_CPUSPEED;
if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0) {
@@ -4981,9 +5051,9 @@ bool SystemInformationImplementation::QueryBSDProcessor()
}
this->CPUSpeedInMHz = (float)k;
-#endif
+# endif
-#if defined(CPU_SSE)
+# if defined(CPU_SSE)
ctrl[0] = CTL_MACHDEP;
ctrl[1] = CPU_SSE;
@@ -4992,9 +5062,9 @@ bool SystemInformationImplementation::QueryBSDProcessor()
}
this->Features.HasSSE = (k > 0);
-#endif
+# endif
-#if defined(CPU_SSE2)
+# if defined(CPU_SSE2)
ctrl[0] = CTL_MACHDEP;
ctrl[1] = CPU_SSE2;
@@ -5003,9 +5073,9 @@ bool SystemInformationImplementation::QueryBSDProcessor()
}
this->Features.HasSSE2 = (k > 0);
-#endif
+# endif
-#if defined(CPU_CPUVENDOR)
+# if defined(CPU_CPUVENDOR)
ctrl[0] = CTL_MACHDEP;
ctrl[1] = CPU_CPUVENDOR;
char vbuf[25];
@@ -5017,7 +5087,7 @@ bool SystemInformationImplementation::QueryBSDProcessor()
this->ChipID.Vendor = vbuf;
this->FindManufacturer();
-#endif
+# endif
return true;
#else
@@ -5062,7 +5132,7 @@ bool SystemInformationImplementation::QueryHPUXMemory()
bool SystemInformationImplementation::QueryHPUXProcessor()
{
#if defined(__hpux)
-#if defined(KWSYS_SYS_HAS_MPCTL_H)
+# if defined(KWSYS_SYS_HAS_MPCTL_H)
int c = mpctl(MPC_GETNUMSPUS_SYS, 0, 0);
if (c <= 0) {
return false;
@@ -5090,17 +5160,17 @@ bool SystemInformationImplementation::QueryHPUXProcessor()
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
+# 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
+# endif
+# ifdef CPU_IA64_ARCHREV_0
case CPU_IA64_ARCHREV_0:
-#endif
+# endif
this->ChipID.Vendor = "GenuineIntel";
this->Features.HasIA64 = true;
break;
-#endif
+# endif
default:
return false;
}
@@ -5108,9 +5178,9 @@ bool SystemInformationImplementation::QueryHPUXProcessor()
this->FindManufacturer();
return true;
-#else
+# else
return false;
-#endif
+# endif
#else
return false;
#endif
@@ -5131,14 +5201,17 @@ bool SystemInformationImplementation::QueryOSInformation()
// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEXW));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(push)
-#ifdef __INTEL_COMPILER
-#pragma warning(disable : 1478)
-#else
-#pragma warning(disable : 4996)
-#endif
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning(push)
+# ifdef __INTEL_COMPILER
+# pragma warning(disable : 1478)
+# elif defined __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# else
+# pragma warning(disable : 4996)
+# endif
+# endif
bOsVersionInfoEx = GetVersionExW((OSVERSIONINFOW*)&osvi);
if (!bOsVersionInfoEx) {
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
@@ -5146,9 +5219,13 @@ bool SystemInformationImplementation::QueryOSInformation()
return false;
}
}
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(pop)
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# ifdef __clang__
+# pragma clang diagnostic pop
+# else
+# pragma warning(pop)
+# endif
+# endif
switch (osvi.dwPlatformId) {
case VER_PLATFORM_WIN32_NT:
@@ -5166,7 +5243,7 @@ bool SystemInformationImplementation::QueryOSInformation()
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) {
this->OSRelease = "XP";
}
-#ifdef VER_NT_WORKSTATION
+# ifdef VER_NT_WORKSTATION
// Test for product type.
if (bOsVersionInfoEx) {
if (osvi.wProductType == VER_NT_WORKSTATION) {
@@ -5177,7 +5254,7 @@ bool SystemInformationImplementation::QueryOSInformation()
this->OSRelease = "7";
}
// VER_SUITE_PERSONAL may not be defined
-#ifdef VER_SUITE_PERSONAL
+# ifdef VER_SUITE_PERSONAL
else {
if (osvi.wSuiteMask & VER_SUITE_PERSONAL) {
this->OSRelease += " Personal";
@@ -5185,7 +5262,7 @@ bool SystemInformationImplementation::QueryOSInformation()
this->OSRelease += " Professional";
}
}
-#endif
+# endif
} else if (osvi.wProductType == VER_NT_SERVER) {
// Check for .NET Server instead of Windows XP.
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) {
@@ -5206,7 +5283,7 @@ bool SystemInformationImplementation::QueryOSInformation()
osvi.dwBuildNumber & 0xFFFF);
this->OSVersion = operatingSystem;
} else
-#endif // VER_NT_WORKSTATION
+# endif // VER_NT_WORKSTATION
{
HKEY hKey;
wchar_t szProductType[80];
@@ -5357,7 +5434,7 @@ bool SystemInformationImplementation::QueryOSInformation()
}
}
-#ifdef __APPLE__
+# ifdef __APPLE__
this->OSName = "Unknown Apple OS";
this->OSRelease = "Unknown product version";
this->OSVersion = "Unknown build version";
@@ -5365,7 +5442,7 @@ bool SystemInformationImplementation::QueryOSInformation()
this->CallSwVers("-productName", this->OSName);
this->CallSwVers("-productVersion", this->OSRelease);
this->CallSwVers("-buildVersion", this->OSVersion);
-#endif
+# endif
#endif
@@ -5379,7 +5456,7 @@ int SystemInformationImplementation::CallSwVers(const char* arg,
std::vector<const char*> args;
args.push_back("sw_vers");
args.push_back(arg);
- args.push_back(0);
+ args.push_back(KWSYS_NULLPTR);
ver = this->RunProcess(args);
this->TrimNewline(ver);
#else
diff --git a/Source/kwsys/SystemInformation.hxx.in b/Source/kwsys/SystemInformation.hxx.in
index 516c505c5..5e93878fa 100644
--- a/Source/kwsys/SystemInformation.hxx.in
+++ b/Source/kwsys/SystemInformation.hxx.in
@@ -20,7 +20,7 @@ class @KWSYS_NAMESPACE@_EXPORT SystemInformation
#elif @KWSYS_USE___INT64@
typedef __int64 LongLong;
#else
-#error "No Long Long"
+# error "No Long Long"
#endif
friend class SystemInformationImplementation;
SystemInformationImplementation* Implementation;
@@ -56,6 +56,9 @@ public:
SystemInformation();
~SystemInformation();
+ SystemInformation(const SystemInformation&) = delete;
+ SystemInformation& operator=(const SystemInformation&) = delete;
+
const char* GetVendorString();
const char* GetVendorID();
std::string GetTypeID();
@@ -103,14 +106,14 @@ public:
// Retrieve id of the current running process
LongLong GetProcessId();
- // Retrieve memory information in megabyte.
+ // Retrieve memory information in MiB.
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
+ // available ram on this system. See the GetHostMemoryTotal, and
// Get{Host,Proc}MemoryAvailable methods for more information.
std::string GetMemoryDescription(const char* hostLimitEnvVarName = NULL,
const char* procLimitEnvVarName = NULL);
@@ -124,7 +127,7 @@ public:
// 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.
+ // are reported to us via an application specified environment variable.
LongLong GetHostMemoryAvailable(const char* hostLimitEnvVarName = NULL);
// Get total system RAM in units of KiB available to this process.
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 1c4fe3389..ae7a18a8c 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -1,18 +1,19 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifdef __osf__
-#define _OSF_SOURCE
-#define _POSIX_C_SOURCE 199506L
-#define _XOPEN_SOURCE_EXTENDED
+# define _OSF_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# define _XOPEN_SOURCE_EXTENDED
#endif
-#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || \
- defined(__BORLANDC__) || defined(__MINGW32__))
-#define KWSYS_WINDOWS_DIRS
+#if defined(_WIN32) && \
+ (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || \
+ defined(__MINGW32__))
+# define KWSYS_WINDOWS_DIRS
#else
-#if defined(__SUNPRO_CC)
-#include <fcntl.h>
-#endif
+# if defined(__SUNPRO_CC)
+# include <fcntl.h>
+# endif
#endif
#include "kwsysPrivate.h"
@@ -20,37 +21,38 @@
#include KWSYS_HEADER(SystemTools.hxx)
#include KWSYS_HEADER(Directory.hxx)
#include KWSYS_HEADER(FStream.hxx)
+#include KWSYS_HEADER(Encoding.h)
#include KWSYS_HEADER(Encoding.hxx)
-#include <algorithm>
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
+#include <utility>
#include <vector>
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Directory.hxx.in"
-#include "Encoding.hxx.in"
-#include "FStream.hxx.in"
-#include "RegularExpression.hxx.in"
-#include "SystemTools.hxx.in"
+# include "Directory.hxx.in"
+# include "Encoding.hxx.in"
+# include "FStream.hxx.in"
+# include "RegularExpression.hxx.in"
+# include "SystemTools.hxx.in"
#endif
#ifdef _MSC_VER
-#pragma warning(disable : 4786)
+# pragma warning(disable : 4786)
#endif
#if defined(__sgi) && !defined(__GNUC__)
-#pragma set woff 1375 /* base class destructor not virtual */
+# 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 */
+# include <malloc.h> /* for malloc/free on QNX */
#endif
#include <stdio.h>
#include <stdlib.h>
@@ -58,42 +60,46 @@
#include <time.h>
#if defined(_WIN32) && !defined(_MSC_VER) && defined(__GNUC__)
-#include <strings.h> /* for strcasecmp */
+# include <strings.h> /* for strcasecmp */
#endif
#ifdef _MSC_VER
-#define umask _umask // Note this is still umask on Borland
+# define umask _umask // Note this is still umask on Borland
#endif
// support for realpath call
#ifndef _WIN32
-#include <limits.h>
-#include <pwd.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <utime.h>
-#ifndef __VMS
-#include <sys/param.h>
-#include <termios.h>
+# include <limits.h>
+# include <pwd.h>
+# include <sys/ioctl.h>
+# include <sys/time.h>
+# include <sys/wait.h>
+# include <unistd.h>
+# include <utime.h>
+# ifndef __VMS
+# include <sys/param.h>
+# include <termios.h>
+# endif
+# include <signal.h> /* sigprocmask */
#endif
-#include <signal.h> /* sigprocmask */
+
+#ifdef __linux
+# include <linux/fs.h>
#endif
// Windows API.
#if defined(_WIN32)
-#include <windows.h>
-#include <winioctl.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
+# include <windows.h>
+# include <winioctl.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
+# include <windows.h>
+# undef _WIN32
#endif
#if !KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
@@ -101,17 +107,18 @@ extern char** environ;
#endif
#ifdef __CYGWIN__
-#include <sys/cygwin.h>
+# 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
+#if defined(_WIN32) || defined(__LIBCATAMOUNT__) || \
+ (defined(HAVE_GETPWNAM) && HAVE_GETPWNAM == 0)
+# undef HAVE_GETPWNAM
+# undef HAVE_TTY_INFO
#else
-#define HAVE_GETPWNAM 1
-#define HAVE_TTY_INFO 1
+# define HAVE_GETPWNAM 1
+# define HAVE_TTY_INFO 1
#endif
#define VTK_URL_PROTOCOL_REGEX "([a-zA-Z0-9]*)://(.*)"
@@ -120,15 +127,15 @@ extern char** environ;
"(.+)?"
#ifdef _MSC_VER
-#include <sys/utime.h>
+# include <sys/utime.h>
#else
-#include <utime.h>
+# 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>
+# include <sys/termios.h>
namespace KWSYS_NAMESPACE {
class SystemToolsHack
{
@@ -146,32 +153,33 @@ public:
}
#endif
-#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || \
- defined(__BORLANDC__) || defined(__MINGW32__))
-#include <direct.h>
-#include <io.h>
-#define _unlink unlink
+#if defined(_WIN32) && \
+ (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || \
+ defined(__MINGW32__))
+# include <direct.h>
+# include <io.h>
+# define _unlink unlink
#endif
/* The maximum length of a file name. */
#if defined(PATH_MAX)
-#define KWSYS_SYSTEMTOOLS_MAXPATH PATH_MAX
+# define KWSYS_SYSTEMTOOLS_MAXPATH PATH_MAX
#elif defined(MAXPATHLEN)
-#define KWSYS_SYSTEMTOOLS_MAXPATH MAXPATHLEN
+# define KWSYS_SYSTEMTOOLS_MAXPATH MAXPATHLEN
#else
-#define KWSYS_SYSTEMTOOLS_MAXPATH 16384
+# define KWSYS_SYSTEMTOOLS_MAXPATH 16384
#endif
#if defined(__WATCOMC__)
-#include <direct.h>
-#define _mkdir mkdir
-#define _rmdir rmdir
-#define _getcwd getcwd
-#define _chdir chdir
+# 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>
+# 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)
@@ -212,7 +220,7 @@ static time_t windows_filetime_to_posix_time(const FILETIME& ft)
#endif
#ifdef KWSYS_WINDOWS_DIRS
-#include <wctype.h>
+# include <wctype.h>
inline int Mkdir(const std::string& dir)
{
@@ -228,23 +236,27 @@ inline const char* Getcwd(char* buf, unsigned int len)
{
std::vector<wchar_t> w_buf(len);
if (_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]);
+ size_t nlen = kwsysEncoding_wcstombs(buf, &w_buf[0], len);
+ if (nlen == static_cast<size_t>(-1)) {
+ return 0;
+ }
+ if (nlen < len) {
+ // make sure the drive letter is capital
+ if (nlen > 1 && buf[1] == ':') {
+ buf[0] = toupper(buf[0]);
+ }
+ return buf;
}
- std::string tmp = KWSYS_NAMESPACE::Encoding::ToNarrow(&w_buf[0]);
- strcpy(buf, tmp.c_str());
- return buf;
}
return 0;
}
inline int Chdir(const std::string& dir)
{
-#if defined(__BORLANDC__)
+# if defined(__BORLANDC__)
return chdir(dir.c_str());
-#else
+# else
return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
-#endif
+# endif
}
inline void Realpath(const std::string& path, std::string& resolved_path,
std::string* errorMessage = 0)
@@ -279,10 +291,10 @@ inline void Realpath(const std::string& path, std::string& resolved_path,
}
}
#else
-#include <sys/types.h>
+# include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
+# include <fcntl.h>
+# include <unistd.h>
inline int Mkdir(const std::string& dir)
{
return mkdir(dir.c_str(), 00777);
@@ -301,7 +313,7 @@ inline int Chdir(const std::string& dir)
return chdir(dir.c_str());
}
inline void Realpath(const std::string& path, std::string& resolved_path,
- std::string* errorMessage = 0)
+ std::string* errorMessage = KWSYS_NULLPTR)
{
char resolved_name[KWSYS_SYSTEMTOOLS_MAXPATH];
@@ -347,15 +359,11 @@ double SystemTools::GetTime(void)
11644473600.0);
#else
struct timeval t;
- gettimeofday(&t, 0);
+ gettimeofday(&t, KWSYS_NULLPTR);
return 1.0 * double(t.tv_sec) + 0.000001 * double(t.tv_usec);
#endif
}
-class SystemToolsTranslationMap : public std::map<std::string, std::string>
-{
-};
-
/* Type of character storing the environment. */
#if defined(_WIN32)
typedef wchar_t envchar;
@@ -405,11 +413,14 @@ public:
{
}
~Free() { free(const_cast<envchar*>(this->Env)); }
+
+ Free(const Free&) = delete;
+ Free& operator=(const Free&) = delete;
};
const envchar* Release(const envchar* env)
{
- const envchar* old = 0;
+ const envchar* old = KWSYS_NULLPTR;
iterator i = this->find(env);
if (i != this->end()) {
old = *i;
@@ -424,24 +435,150 @@ struct SystemToolsPathCaseCmp
{
bool operator()(std::string const& l, std::string const& r) const
{
-#ifdef _MSC_VER
+# ifdef _MSC_VER
return _stricmp(l.c_str(), r.c_str()) < 0;
-#elif defined(__GNUC__)
+# elif defined(__GNUC__)
return strcasecmp(l.c_str(), r.c_str()) < 0;
-#else
+# else
return SystemTools::Strucmp(l.c_str(), r.c_str()) < 0;
-#endif
+# endif
}
};
+#endif
-class SystemToolsPathCaseMap
- : public std::map<std::string, std::string, SystemToolsPathCaseCmp>
+/**
+ * SystemTools static variables singleton class.
+ */
+class SystemToolsStatic
{
+public:
+ typedef std::map<std::string, std::string> StringMap;
+#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP
+ /**
+ * Path translation table from dir to refdir
+ * Each time 'dir' will be found it will be replace by 'refdir'
+ */
+ StringMap TranslationMap;
+#endif
+#ifdef _WIN32
+ static std::string GetCasePathName(std::string const& pathIn);
+ static std::string GetActualCaseForPathCached(std::string const& path);
+ static const char* GetEnvBuffered(const char* key);
+ std::map<std::string, std::string, SystemToolsPathCaseCmp> PathCaseMap;
+ std::map<std::string, std::string> EnvMap;
+#endif
+#ifdef __CYGWIN__
+ StringMap Cyg2Win32Map;
+#endif
+
+ /**
+ * Actual implementation of ReplaceString.
+ */
+ static void ReplaceString(std::string& source, const char* replace,
+ size_t replaceSize, const std::string& with);
+
+ /**
+ * 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 std::string FindName(
+ const std::string& name,
+ const std::vector<std::string>& path = std::vector<std::string>(),
+ bool no_system_path = false);
};
-class SystemToolsEnvMap : public std::map<std::string, std::string>
+#ifdef _WIN32
+std::string SystemToolsStatic::GetCasePathName(std::string const& pathIn)
{
-};
+ std::string casePath;
+
+ // First check if the file is relative. We don't fix relative paths since the
+ // real case depends on the root directory and the given path fragment may
+ // have meaning elsewhere in the project.
+ if (!SystemTools::FileIsFullPath(pathIn)) {
+ // This looks unnecessary, but it allows for the return value optimization
+ // since all return paths return the same local variable.
+ casePath = pathIn;
+ return casePath;
+ }
+
+ std::vector<std::string> path_components;
+ SystemTools::SplitPath(pathIn, path_components);
+
+ // Start with root component.
+ std::vector<std::string>::size_type idx = 0;
+ casePath = path_components[idx++];
+ // make sure drive letter is always upper case
+ if (casePath.size() > 1 && casePath[1] == ':') {
+ casePath[0] = toupper(casePath[0]);
+ }
+ 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 = "/";
+ }
+
+ // Convert case of all components that exist.
+ bool converting = true;
+ for (; idx < path_components.size(); idx++) {
+ casePath += sep;
+ sep = "/";
+
+ if (converting) {
+ // 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('*') != std::string::npos ||
+ path_components[idx].find('?') != std::string::npos) {
+ converting = false;
+ } else {
+ std::string test_str = casePath;
+ test_str += path_components[idx];
+ WIN32_FIND_DATAW findData;
+ HANDLE hFind =
+ ::FindFirstFileW(Encoding::ToWide(test_str).c_str(), &findData);
+ if (INVALID_HANDLE_VALUE != hFind) {
+ path_components[idx] = Encoding::ToNarrow(findData.cFileName);
+ ::FindClose(hFind);
+ } else {
+ converting = false;
+ }
+ }
+ }
+
+ casePath += path_components[idx];
+ }
+ return casePath;
+}
+
+std::string SystemToolsStatic::GetActualCaseForPathCached(std::string const& p)
+{
+ // Check to see if actual case has already been called
+ // for this path, and the result is stored in the PathCaseMap
+ auto& pcm = SystemTools::Statics->PathCaseMap;
+ {
+ auto itr = pcm.find(p);
+ if (itr != pcm.end()) {
+ return itr->second;
+ }
+ }
+ std::string casePath = SystemToolsStatic::GetCasePathName(p);
+ if (casePath.size() <= MAX_PATH) {
+ pcm[p] = casePath;
+ }
+ return casePath;
+}
#endif
// adds the elements of the env variable path to the arg passed in
@@ -462,7 +599,7 @@ void SystemTools::GetPath(std::vector<std::string>& path, const char* env)
}
// A hack to make the below algorithm work.
- if (!pathEnv.empty() && *pathEnv.rbegin() != pathSep) {
+ if (!pathEnv.empty() && pathEnv.back() != pathSep) {
pathEnv += pathSep;
}
std::string::size_type start = 0;
@@ -482,30 +619,37 @@ void SystemTools::GetPath(std::vector<std::string>& path, const char* env)
}
}
-const char* SystemTools::GetEnvImpl(const char* key)
-{
- const char* v = 0;
#if defined(_WIN32)
+const char* SystemToolsStatic::GetEnvBuffered(const char* key)
+{
std::string env;
if (SystemTools::GetEnv(key, env)) {
- std::string& menv = (*SystemTools::EnvMap)[key];
- menv = env;
- v = menv.c_str();
+ std::string& menv = SystemTools::Statics->EnvMap[key];
+ if (menv != env) {
+ menv = std::move(env);
+ }
+ return menv.c_str();
}
-#else
- v = getenv(key);
-#endif
- return v;
+ return KWSYS_NULLPTR;
}
+#endif
const char* SystemTools::GetEnv(const char* key)
{
- return SystemTools::GetEnvImpl(key);
+#if defined(_WIN32)
+ return SystemToolsStatic::GetEnvBuffered(key);
+#else
+ return getenv(key);
+#endif
}
const char* SystemTools::GetEnv(const std::string& key)
{
- return SystemTools::GetEnvImpl(key.c_str());
+#if defined(_WIN32)
+ return SystemToolsStatic::GetEnvBuffered(key.c_str());
+#else
+ return getenv(key.c_str());
+#endif
}
bool SystemTools::GetEnv(const char* key, std::string& result)
@@ -540,7 +684,7 @@ bool SystemTools::HasEnv(const char* key)
#else
const char* v = getenv(key);
#endif
- return v != 0;
+ return v != KWSYS_NULLPTR;
}
bool SystemTools::HasEnv(const std::string& key)
@@ -667,9 +811,9 @@ bool SystemTools::UnPutEnv(const std::string& env)
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
+# ifdef __INTEL_COMPILER
+# pragma warning disable 444 /* base has non-virtual destructor */
+# endif
class kwsysEnv : public kwsysEnvSet
{
@@ -677,39 +821,39 @@ public:
~kwsysEnv()
{
for (iterator i = this->begin(); i != this->end(); ++i) {
-#if defined(_WIN32)
+# if defined(_WIN32)
const std::string s = Encoding::ToNarrow(*i);
- kwsysUnPutEnv(s.c_str());
-#else
+ kwsysUnPutEnv(s);
+# else
kwsysUnPutEnv(*i);
-#endif
+# endif
free(const_cast<envchar*>(*i));
}
}
bool Put(const char* env)
{
-#if defined(_WIN32)
+# if defined(_WIN32)
const std::wstring wEnv = Encoding::ToWide(env);
wchar_t* newEnv = _wcsdup(wEnv.c_str());
-#else
+# else
char* newEnv = strdup(env);
-#endif
+# endif
Free oldEnv(this->Release(newEnv));
this->insert(newEnv);
-#if defined(_WIN32)
+# if defined(_WIN32)
return _wputenv(newEnv) == 0;
-#else
+# else
return putenv(newEnv) == 0;
-#endif
+# endif
}
bool UnPut(const char* env)
{
-#if defined(_WIN32)
+# if defined(_WIN32)
const std::wstring wEnv = Encoding::ToWide(env);
Free oldEnv(this->Release(wEnv.c_str()));
-#else
+# else
Free oldEnv(this->Release(env));
-#endif
+# endif
return kwsysUnPutEnv(env) == 0;
}
};
@@ -747,15 +891,15 @@ FILE* SystemTools::Fopen(const std::string& file, const char* mode)
#endif
}
-bool SystemTools::MakeDirectory(const char* path)
+bool SystemTools::MakeDirectory(const char* path, const mode_t* mode)
{
if (!path) {
return false;
}
- return SystemTools::MakeDirectory(std::string(path));
+ return SystemTools::MakeDirectory(std::string(path), mode);
}
-bool SystemTools::MakeDirectory(const std::string& path)
+bool SystemTools::MakeDirectory(const std::string& path, const mode_t* mode)
{
if (SystemTools::PathExists(path)) {
return SystemTools::FileIsDirectory(path);
@@ -770,8 +914,12 @@ bool SystemTools::MakeDirectory(const std::string& path)
std::string topdir;
while ((pos = dir.find('/', pos)) != std::string::npos) {
topdir = dir.substr(0, pos);
- Mkdir(topdir);
- pos++;
+
+ if (Mkdir(topdir) == 0 && mode != KWSYS_NULLPTR) {
+ SystemTools::SetPermissions(topdir, *mode);
+ }
+
+ ++pos;
}
topdir = dir;
if (Mkdir(topdir) != 0) {
@@ -783,10 +931,13 @@ bool SystemTools::MakeDirectory(const std::string& path)
#ifdef __BORLANDC__
&& (errno != EACCES)
#endif
- ) {
+ ) {
return false;
}
+ } else if (mode != KWSYS_NULLPTR) {
+ SystemTools::SetPermissions(topdir, *mode);
}
+
return true;
}
@@ -801,7 +952,8 @@ void SystemTools::ReplaceString(std::string& source,
return;
}
- SystemTools::ReplaceString(source, replace.c_str(), replace.size(), with);
+ SystemToolsStatic::ReplaceString(source, replace.c_str(), replace.size(),
+ with);
}
void SystemTools::ReplaceString(std::string& source, const char* replace,
@@ -812,12 +964,13 @@ void SystemTools::ReplaceString(std::string& source, const char* replace,
return;
}
- SystemTools::ReplaceString(source, replace, strlen(replace),
- with ? with : "");
+ SystemToolsStatic::ReplaceString(source, replace, strlen(replace),
+ with ? with : "");
}
-void SystemTools::ReplaceString(std::string& source, const char* replace,
- size_t replaceSize, const std::string& with)
+void SystemToolsStatic::ReplaceString(std::string& source, const char* replace,
+ size_t replaceSize,
+ const std::string& with)
{
const char* src = source.c_str();
char* searchPos = const_cast<char*>(strstr(src, replace));
@@ -848,15 +1001,16 @@ void SystemTools::ReplaceString(std::string& source, const char* replace,
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__)
+
+# 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
+
static bool SystemToolsParseRegistryKey(const std::string& key,
HKEY& primaryKey, std::string& second,
std::string& valuename)
@@ -1059,7 +1213,7 @@ bool SystemTools::WriteRegistryValue(const std::string&, const std::string&,
// 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
+// => will delete the data of the "Root" value of the key
#if defined(_WIN32) && !defined(__CYGWIN__)
bool SystemTools::DeleteRegistryValue(const std::string& key, KeyWOW64 view)
@@ -1182,16 +1336,34 @@ bool SystemTools::FileExists(const std::string& filename)
}
return access(filename.c_str(), R_OK) == 0;
#elif defined(_WIN32)
- return (
- GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str()) !=
- INVALID_FILE_ATTRIBUTES);
+ DWORD attr =
+ GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str());
+ if (attr == INVALID_FILE_ATTRIBUTES) {
+ return false;
+ }
+
+ if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
+ // Using 0 instead of GENERIC_READ as it allows reading of file attributes
+ // even if we do not have permission to read the file itself
+ HANDLE handle =
+ CreateFileW(Encoding::ToWindowsExtendedPath(filename).c_str(), 0, 0,
+ NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+
+ if (handle == INVALID_HANDLE_VALUE) {
+ return false;
+ }
+
+ CloseHandle(handle);
+ }
+
+ return true;
#else
// SCO OpenServer 5.0.7/3.2's command has 711 permission.
-#if defined(_SCO_DS)
+# if defined(_SCO_DS)
return access(filename.c_str(), F_OK) == 0;
-#else
+# else
return access(filename.c_str(), R_OK) == 0;
-#endif
+# endif
#endif
}
@@ -1263,11 +1435,11 @@ int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
// long paths, but _wstat64 rejects paths with '?' in them, thinking
// they are wildcards.
std::wstring const& wpath = Encoding::ToWide(path);
-#if defined(__BORLANDC__)
+# if defined(__BORLANDC__)
return _wstati64(wpath.c_str(), buf);
-#else
+# else
return _wstat64(wpath.c_str(), buf);
-#endif
+# endif
#else
return stat(path.c_str(), buf);
#endif
@@ -1276,18 +1448,16 @@ int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
#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);
+ auto itr = SystemTools::Statics->Cyg2Win32Map.find(path);
+ if (itr != SystemTools::Statics->Cyg2Win32Map.end()) {
+ strncpy(win32_path, itr->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);
+ SystemTools::Statics->Cyg2Win32Map.insert(
+ SystemToolsStatic::StringMap::value_type(path, win32_path));
}
return win32_path[0] != 0;
}
@@ -1322,39 +1492,15 @@ bool SystemTools::Touch(const std::string& filename, bool create)
}
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) {
+ // utimensat is only available on newer Unixes and macOS 10.13+
+ if (utimensat(AT_FDCWD, filename.c_str(), NULL, 0) < 0) {
return false;
}
- struct timeval mtime;
- gettimeofday(&mtime, 0);
-#if KWSYS_CXX_HAS_UTIMES
- struct timeval atime;
-#if KWSYS_CXX_STAT_HAS_ST_MTIM
- atime.tv_sec = st.st_atim.tv_sec;
- atime.tv_usec = st.st_atim.tv_nsec / 1000;
-#elif KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
- atime.tv_sec = st.st_atimespec.tv_sec;
- atime.tv_usec = st.st_atimespec.tv_nsec / 1000;
#else
- atime.tv_sec = st.st_atime;
- atime.tv_usec = 0;
-#endif
- struct timeval times[2] = { atime, mtime };
- if (utimes(filename.c_str(), times) < 0) {
+ // fall back to utimes
+ if (utimes(filename.c_str(), NULL) < 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;
}
@@ -1374,7 +1520,7 @@ bool SystemTools::FileTimeCompare(const std::string& f1, const std::string& f2,
if (stat(f2.c_str(), &s2) != 0) {
return false;
}
-#if KWSYS_CXX_STAT_HAS_ST_MTIM
+# if KWSYS_CXX_STAT_HAS_ST_MTIM
// Compare using nanosecond resolution.
if (s1.st_mtim.tv_sec < s2.st_mtim.tv_sec) {
*result = -1;
@@ -1385,7 +1531,7 @@ bool SystemTools::FileTimeCompare(const std::string& f1, const std::string& f2,
} else if (s1.st_mtim.tv_nsec > s2.st_mtim.tv_nsec) {
*result = 1;
}
-#elif KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
+# elif KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
// Compare using nanosecond resolution.
if (s1.st_mtimespec.tv_sec < s2.st_mtimespec.tv_sec) {
*result = -1;
@@ -1396,14 +1542,14 @@ bool SystemTools::FileTimeCompare(const std::string& f1, const std::string& f2,
} else if (s1.st_mtimespec.tv_nsec > s2.st_mtimespec.tv_nsec) {
*result = 1;
}
-#else
+# 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
+# endif
#else
// Windows version. Get the modification time from extended file attributes.
WIN32_FILE_ATTRIBUTE_DATA f1d;
@@ -1507,7 +1653,7 @@ char* SystemTools::AppendStrings(const char* str1, const char* str2)
size_t len1 = strlen(str1);
char* newstr = new char[len1 + strlen(str2) + 1];
if (!newstr) {
- return 0;
+ return KWSYS_NULLPTR;
}
strcpy(newstr, str1);
strcat(newstr + len1, str2);
@@ -1530,7 +1676,7 @@ char* SystemTools::AppendStrings(const char* str1, const char* str2,
size_t len1 = strlen(str1), len2 = strlen(str2);
char* newstr = new char[len1 + len2 + strlen(str3) + 1];
if (!newstr) {
- return 0;
+ return KWSYS_NULLPTR;
}
strcpy(newstr, str1);
strcat(newstr + len1, str2);
@@ -1580,7 +1726,7 @@ size_t SystemTools::CountChar(const char* str, char c)
char* SystemTools::RemoveChars(const char* str, const char* toremove)
{
if (!str) {
- return NULL;
+ return KWSYS_NULLPTR;
}
char* clean_str = new char[strlen(str) + 1];
char* ptr = clean_str;
@@ -1602,7 +1748,7 @@ char* SystemTools::RemoveChars(const char* str, const char* toremove)
char* SystemTools::RemoveCharsButUpperHex(const char* str)
{
if (!str) {
- return 0;
+ return KWSYS_NULLPTR;
}
char* clean_str = new char[strlen(str) + 1];
char* ptr = clean_str;
@@ -1679,11 +1825,11 @@ bool SystemTools::StringEndsWith(const std::string& str1, const char* str2)
: false;
}
-// Returns a pointer to the last occurence of str2 in str1
+// Returns a pointer to the last occurrence of str2 in str1
const char* SystemTools::FindLastString(const char* str1, const char* str2)
{
if (!str1 || !str2) {
- return NULL;
+ return KWSYS_NULLPTR;
}
size_t len1 = strlen(str1), len2 = strlen(str2);
@@ -1696,7 +1842,7 @@ const char* SystemTools::FindLastString(const char* str1, const char* str2)
} while (ptr-- != str1);
}
- return NULL;
+ return KWSYS_NULLPTR;
}
// Duplicate string
@@ -1706,7 +1852,7 @@ char* SystemTools::DuplicateString(const char* str)
char* newstr = new char[strlen(str) + 1];
return strcpy(newstr, str);
}
- return NULL;
+ return KWSYS_NULLPTR;
}
// Return a cropped string
@@ -1737,11 +1883,11 @@ std::string SystemTools::CropString(const std::string& s, size_t max_len)
return n;
}
-std::vector<kwsys::String> SystemTools::SplitString(const std::string& p,
- char sep, bool isPath)
+std::vector<std::string> SystemTools::SplitString(const std::string& p,
+ char sep, bool isPath)
{
std::string path = p;
- std::vector<kwsys::String> paths;
+ std::vector<std::string> paths;
if (path.empty()) {
return paths;
}
@@ -1870,70 +2016,70 @@ static void ConvertVMSToUnix(std::string& path)
// convert windows slashes to unix slashes
void SystemTools::ConvertToUnixSlashes(std::string& path)
{
+ if (path.empty()) {
+ return;
+ }
+
const char* pathCString = path.c_str();
bool hasDoubleSlash = false;
#ifdef __VMS
ConvertVMSToUnix(path);
#else
const char* pos0 = pathCString;
- const char* pos1 = pathCString + 1;
for (std::string::size_type pos = 0; *pos0; ++pos) {
- // make sure we don't convert an escaped space to a unix slash
- if (*pos0 == '\\' && *pos1 != ' ') {
+ if (*pos0 == '\\') {
path[pos] = '/';
}
// Also, reuse the loop to check for slash followed by another slash
- if (*pos1 == '/' && *(pos1 + 1) == '/' && !hasDoubleSlash) {
-#ifdef _WIN32
+ if (!hasDoubleSlash && *(pos0 + 1) == '/' && *(pos0 + 2) == '/') {
+# 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
+# else
hasDoubleSlash = true;
-#endif
+# 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')) {
- std::string homeEnv;
- if (SystemTools::GetEnv("HOME", homeEnv)) {
- path.replace(0, 1, homeEnv);
- }
+ // if there is a tilda ~ then replace it with HOME
+ pathCString = path.c_str();
+ if (pathCString[0] == '~' &&
+ (pathCString[1] == '/' || pathCString[1] == '\0')) {
+ std::string homeEnv;
+ if (SystemTools::GetEnv("HOME", homeEnv)) {
+ path.replace(0, 1, homeEnv);
}
+ }
#ifdef HAVE_GETPWNAM
- else if (pathCString[0] == '~') {
- std::string::size_type idx = path.find_first_of("/\0");
- std::string user = path.substr(1, idx - 1);
- passwd* pw = getpwnam(user.c_str());
- if (pw) {
- path.replace(0, idx, pw->pw_dir);
- }
+ else if (pathCString[0] == '~') {
+ std::string::size_type idx = path.find_first_of("/\0");
+ std::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);
- }
+ // remove trailing slash if the path is more than
+ // a single /
+ pathCString = path.c_str();
+ size_t size = path.size();
+ if (size > 1 && path.back() == '/') {
+ // if it is c:/ then do not remove the trailing slash
+ if (!((size == 3 && pathCString[1] == ':'))) {
+ path.resize(size - 1);
}
}
}
@@ -1958,7 +2104,7 @@ std::string SystemTools::ConvertToUnixOutputPath(const std::string& path)
}
// escape spaces and () in the path
if (ret.find_first_of(" ") != std::string::npos) {
- std::string result = "";
+ std::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
@@ -2148,16 +2294,152 @@ bool SystemTools::FilesDiffer(const std::string& source,
return false;
}
+bool SystemTools::TextFilesDiffer(const std::string& path1,
+ const std::string& path2)
+{
+ kwsys::ifstream if1(path1.c_str());
+ kwsys::ifstream if2(path2.c_str());
+ if (!if1 || !if2) {
+ return true;
+ }
+
+ for (;;) {
+ std::string line1, line2;
+ bool hasData1 = GetLineFromStream(if1, line1);
+ bool hasData2 = GetLineFromStream(if2, line2);
+ if (hasData1 != hasData2) {
+ return true;
+ }
+ if (!hasData1) {
+ break;
+ }
+ if (line1 != line2) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Blockwise copy source to destination file
+ */
+static bool CopyFileContentBlockwise(const std::string& source,
+ const std::string& destination)
+{
+// Open files
+#if defined(_WIN32)
+ kwsys::ifstream fin(
+ Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)).c_str(),
+ std::ios::in | std::ios::binary);
+#else
+ kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary);
+#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(destination);
+
+#if defined(_WIN32)
+ kwsys::ofstream fout(
+ Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(destination)).c_str(),
+ std::ios::out | std::ios::trunc | std::ios::binary);
+#else
+ kwsys::ofstream fout(destination.c_str(),
+ std::ios::out | std::ios::trunc | std::ios::binary);
+#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) {
+ const int bufferSize = 4096;
+ char buffer[bufferSize];
+
+ fin.read(buffer, bufferSize);
+ if (fin.gcount()) {
+ fout.write(buffer, fin.gcount());
+ } else {
+ break;
+ }
+ }
+
+ // 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;
+ }
+
+ return true;
+}
+
+/**
+ * Clone the source file to the destination file
+ *
+ * If available, the Linux FICLONE ioctl is used to create a check
+ * copy-on-write clone of the source file.
+ *
+ * The method returns false for the following cases:
+ * - The code has not been compiled on Linux or the ioctl was unknown
+ * - The source and destination is on different file systems
+ * - The underlying filesystem does not support file cloning
+ * - An unspecified error occurred
+ */
+static bool CloneFileContent(const std::string& source,
+ const std::string& destination)
+{
+#if defined(__linux) && defined(FICLONE)
+ int in = open(source.c_str(), O_RDONLY);
+ if (in < 0) {
+ return false;
+ }
+
+ SystemTools::RemoveFile(destination);
+
+ int out =
+ open(destination.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
+ if (out < 0) {
+ close(in);
+ return false;
+ }
+
+ int result = ioctl(out, FICLONE, in);
+ close(in);
+ close(out);
+
+ if (result < 0) {
+ return false;
+ }
+
+ return true;
+#else
+ (void)source;
+ (void)destination;
+ return false;
+#endif
+}
+
/**
* Copy a file named by "source" to the file named by "destination".
*/
bool SystemTools::CopyFileAlways(const std::string& source,
const std::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);
std::string real_destination = destination;
@@ -2165,9 +2447,6 @@ bool SystemTools::CopyFileAlways(const std::string& source,
if (SystemTools::FileIsDirectory(source)) {
SystemTools::MakeDirectory(destination);
} else {
- 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.
@@ -2181,67 +2460,21 @@ bool SystemTools::CopyFileAlways(const std::string& source,
} else {
destination_dir = SystemTools::GetFilenamePath(destination);
}
+ // If files are the same do not copy
+ if (SystemTools::SameFile(source, real_destination)) {
+ return true;
+ }
// Create destination directory
SystemTools::MakeDirectory(destination_dir);
-// Open files
-#if defined(_WIN32)
- kwsys::ifstream fin(
- Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)).c_str(),
- std::ios::in | std::ios::binary);
-#else
- kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary);
-#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)
- kwsys::ofstream fout(
- Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(real_destination))
- .c_str(),
- std::ios::out | std::ios::trunc | std::ios::binary);
-#else
- kwsys::ofstream fout(real_destination.c_str(),
- std::ios::out | std::ios::trunc | std::ios::binary);
-#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());
- } else {
- break;
+ if (!CloneFileContent(source, real_destination)) {
+ // if cloning did not succeed, fall back to blockwise copy
+ if (!CopyFileContentBlockwise(source, real_destination)) {
+ return false;
}
}
-
- // 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)) {
@@ -2269,11 +2502,9 @@ bool SystemTools::CopyADirectory(const std::string& source,
const std::string& destination, bool always)
{
Directory dir;
-#ifdef _WIN32
- dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)));
-#else
- dir.Load(source);
-#endif
+ if (dir.Load(source) == 0) {
+ return false;
+ }
size_t fileNum;
if (!SystemTools::MakeDirectory(destination)) {
return false;
@@ -2375,104 +2606,6 @@ long int SystemTools::CreationTime(const std::string& filename)
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;
-}
-
std::string SystemTools::GetLastSystemError()
{
int e = errno;
@@ -2483,7 +2616,7 @@ std::string SystemTools::GetLastSystemError()
static bool IsJunction(const std::wstring& source)
{
-#ifdef FSCTL_GET_REPARSE_POINT
+# ifdef FSCTL_GET_REPARSE_POINT
const DWORD JUNCTION_ATTRS =
FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT;
DWORD attrs = GetFileAttributesW(source.c_str());
@@ -2525,14 +2658,14 @@ static bool IsJunction(const std::wstring& source)
return (success &&
(reparse_buffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT));
-#else
+# else
return false;
-#endif
+# endif
}
static bool DeleteJunction(const std::wstring& source)
{
-#ifdef FSCTL_DELETE_REPARSE_POINT
+# ifdef FSCTL_DELETE_REPARSE_POINT
// Adjust privileges so that we can succefully open junction points as
// read/write.
HANDLE token;
@@ -2567,9 +2700,9 @@ static bool DeleteJunction(const std::wstring& source)
CloseHandle(dir);
return !!success;
-#else
+# else
return false;
-#endif
+# endif
}
#endif
@@ -2598,6 +2731,14 @@ bool SystemTools::RemoveFile(const std::string& source)
if (IsJunction(ws) && DeleteJunction(ws)) {
return true;
}
+ const DWORD DIRECTORY_SOFT_LINK_ATTRS =
+ FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_REPARSE_POINT;
+ DWORD attrs = GetFileAttributesW(ws.c_str());
+ if (attrs != INVALID_FILE_ATTRIBUTES &&
+ (attrs & DIRECTORY_SOFT_LINK_ATTRS) == DIRECTORY_SOFT_LINK_ATTRS &&
+ RemoveDirectoryW(ws.c_str())) {
+ return true;
+ }
if (DeleteFileW(ws.c_str()) || GetLastError() == ERROR_FILE_NOT_FOUND ||
GetLastError() == ERROR_PATH_NOT_FOUND) {
return true;
@@ -2626,11 +2767,7 @@ bool SystemTools::RemoveADirectory(const std::string& source)
}
Directory dir;
-#ifdef _WIN32
- dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(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)), ".") &&
@@ -2666,9 +2803,9 @@ size_t SystemTools::GetMaximumFilePathLength()
* the system search path. Returns the full path to the file if it is
* found. Otherwise, the empty string is returned.
*/
-std::string SystemTools::FindName(const std::string& name,
- const std::vector<std::string>& userPaths,
- bool no_system_path)
+std::string SystemToolsStatic::FindName(
+ const std::string& name, const std::vector<std::string>& userPaths,
+ bool no_system_path)
{
// Add the system search path to our path first
std::vector<std::string> path;
@@ -2677,27 +2814,15 @@ std::string SystemTools::FindName(const std::string& name,
SystemTools::GetPath(path);
}
// now add the additional paths
- {
- for (std::vector<std::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 (std::vector<std::string>::iterator i = path.begin(); i != path.end();
- ++i) {
- std::string& p = *i;
- if (p.empty() || *p.rbegin() != '/') {
- p += "/";
- }
- }
- }
+ path.reserve(path.size() + userPaths.size());
+ path.insert(path.end(), userPaths.begin(), userPaths.end());
// now look for the file
std::string tryPath;
- for (std::vector<std::string>::const_iterator p = path.begin();
- p != path.end(); ++p) {
- tryPath = *p;
+ for (std::string const& p : path) {
+ tryPath = p;
+ if (tryPath.empty() || tryPath.back() != '/') {
+ tryPath += '/';
+ }
tryPath += name;
if (SystemTools::FileExists(tryPath)) {
return tryPath;
@@ -2716,7 +2841,8 @@ std::string SystemTools::FindFile(const std::string& name,
const std::vector<std::string>& userPaths,
bool no_system_path)
{
- std::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
+ std::string tryPath =
+ SystemToolsStatic::FindName(name, userPaths, no_system_path);
if (!tryPath.empty() && !SystemTools::FileIsDirectory(tryPath)) {
return SystemTools::CollapseFullPath(tryPath);
}
@@ -2733,7 +2859,8 @@ std::string SystemTools::FindDirectory(
const std::string& name, const std::vector<std::string>& userPaths,
bool no_system_path)
{
- std::string tryPath = SystemTools::FindName(name, userPaths, no_system_path);
+ std::string tryPath =
+ SystemToolsStatic::FindName(name, userPaths, no_system_path);
if (!tryPath.empty() && SystemTools::FileIsDirectory(tryPath)) {
return SystemTools::CollapseFullPath(tryPath);
}
@@ -2769,14 +2896,13 @@ std::string SystemTools::FindProgram(const std::string& name,
// the end of it
// on windows try .com then .exe
if (name.size() <= 3 || name[name.size() - 4] != '.') {
- extensions.push_back(".com");
- extensions.push_back(".exe");
+ extensions.emplace_back(".com");
+ extensions.emplace_back(".exe");
// first try with extensions if the os supports them
- for (std::vector<std::string>::iterator i = extensions.begin();
- i != extensions.end(); ++i) {
+ for (std::string const& ext : extensions) {
tryPath = name;
- tryPath += *i;
+ tryPath += ext;
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
}
@@ -2795,43 +2921,33 @@ std::string SystemTools::FindProgram(const std::string& name,
SystemTools::GetPath(path);
}
// now add the additional paths
- {
- for (std::vector<std::string>::const_iterator i = userPaths.begin();
- i != userPaths.end(); ++i) {
- path.push_back(*i);
- }
- }
+ path.reserve(path.size() + userPaths.size());
+ path.insert(path.end(), userPaths.begin(), userPaths.end());
// Add a trailing slash to all paths to aid the search process.
- {
- for (std::vector<std::string>::iterator i = path.begin(); i != path.end();
- ++i) {
- std::string& p = *i;
- if (p.empty() || *p.rbegin() != '/') {
- p += "/";
- }
+ for (std::string& p : path) {
+ if (p.empty() || p.back() != '/') {
+ p += '/';
}
}
// Try each path
- for (std::vector<std::string>::iterator p = path.begin(); p != path.end();
- ++p) {
+ for (std::string& p : path) {
#ifdef _WIN32
// Remove double quotes from the path on windows
- SystemTools::ReplaceString(*p, "\"", "");
+ SystemTools::ReplaceString(p, "\"", "");
#endif
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
// first try with extensions
- for (std::vector<std::string>::iterator ext = extensions.begin();
- ext != extensions.end(); ++ext) {
- tryPath = *p;
+ for (std::string const& ext : extensions) {
+ tryPath = p;
tryPath += name;
- tryPath += *ext;
+ tryPath += ext;
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
}
}
#endif
// now try it without them
- tryPath = *p;
+ tryPath = p;
tryPath += name;
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
@@ -2845,10 +2961,9 @@ std::string SystemTools::FindProgram(const std::vector<std::string>& names,
const std::vector<std::string>& path,
bool noSystemPath)
{
- for (std::vector<std::string>::const_iterator it = names.begin();
- it != names.end(); ++it) {
+ for (std::string const& name : names) {
// Try to find the program.
- std::string result = SystemTools::FindProgram(*it, path, noSystemPath);
+ std::string result = SystemTools::FindProgram(name, path, noSystemPath);
if (!result.empty()) {
return result;
}
@@ -2873,27 +2988,18 @@ std::string SystemTools::FindLibrary(const std::string& name,
std::vector<std::string> path;
SystemTools::GetPath(path);
// now add the additional paths
- {
- for (std::vector<std::string>::const_iterator i = userPaths.begin();
- i != userPaths.end(); ++i) {
- path.push_back(*i);
- }
- }
+ path.reserve(path.size() + userPaths.size());
+ path.insert(path.end(), userPaths.begin(), userPaths.end());
// Add a trailing slash to all paths to aid the search process.
- {
- for (std::vector<std::string>::iterator i = path.begin(); i != path.end();
- ++i) {
- std::string& p = *i;
- if (p.empty() || *p.rbegin() != '/') {
- p += "/";
- }
+ for (std::string& p : path) {
+ if (p.empty() || p.back() != '/') {
+ p += '/';
}
}
std::string tryPath;
- for (std::vector<std::string>::const_iterator p = path.begin();
- p != path.end(); ++p) {
+ for (std::string const& p : path) {
#if defined(__APPLE__)
- tryPath = *p;
+ tryPath = p;
tryPath += name;
tryPath += ".framework";
if (SystemTools::FileIsDirectory(tryPath)) {
@@ -2901,42 +3007,42 @@ std::string SystemTools::FindLibrary(const std::string& name,
}
#endif
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__)
- tryPath = *p;
+ tryPath = p;
tryPath += name;
tryPath += ".lib";
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
}
#else
- tryPath = *p;
+ tryPath = p;
tryPath += "lib";
tryPath += name;
tryPath += ".so";
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
}
- tryPath = *p;
+ tryPath = p;
tryPath += "lib";
tryPath += name;
tryPath += ".a";
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
}
- tryPath = *p;
+ tryPath = p;
tryPath += "lib";
tryPath += name;
tryPath += ".sl";
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
}
- tryPath = *p;
+ tryPath = p;
tryPath += "lib";
tryPath += name;
tryPath += ".dylib";
if (SystemTools::FileExists(tryPath, true)) {
return SystemTools::CollapseFullPath(tryPath);
}
- tryPath = *p;
+ tryPath = p;
tryPath += "lib";
tryPath += name;
tryPath += ".dll";
@@ -3001,10 +3107,36 @@ bool SystemTools::FileIsDirectory(const std::string& inName)
bool SystemTools::FileIsSymlink(const std::string& name)
{
#if defined(_WIN32)
- DWORD attr =
- GetFileAttributesW(Encoding::ToWindowsExtendedPath(name).c_str());
+ std::wstring path = Encoding::ToWindowsExtendedPath(name);
+ DWORD attr = GetFileAttributesW(path.c_str());
if (attr != INVALID_FILE_ATTRIBUTES) {
- return (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
+ // FILE_ATTRIBUTE_REPARSE_POINT means:
+ // * a file or directory that has an associated reparse point, or
+ // * a file that is a symbolic link.
+ HANDLE hFile = CreateFileW(
+ path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
+ FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL);
+ if (hFile == INVALID_HANDLE_VALUE) {
+ return false;
+ }
+ byte buffer[MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
+ DWORD bytesReturned = 0;
+ if (!DeviceIoControl(hFile, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer,
+ MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &bytesReturned,
+ NULL)) {
+ CloseHandle(hFile);
+ // Since FILE_ATTRIBUTE_REPARSE_POINT is set this file must be
+ // a symbolic link if it is not a reparse point.
+ return GetLastError() == ERROR_NOT_A_REPARSE_POINT;
+ }
+ CloseHandle(hFile);
+ ULONG reparseTag =
+ reinterpret_cast<PREPARSE_GUID_DATA_BUFFER>(&buffer[0])->ReparseTag;
+ return (reparseTag == IO_REPARSE_TAG_SYMLINK) ||
+ (reparseTag == IO_REPARSE_TAG_MOUNT_POINT);
+ }
+ return false;
} else {
return false;
}
@@ -3172,9 +3304,8 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut,
msg << " argv[0] = \"" << argv0 << "\"\n";
}
msg << " Attempted paths:\n";
- std::vector<std::string>::iterator i;
- for (i = failures.begin(); i != failures.end(); ++i) {
- msg << " \"" << *i << "\"\n";
+ for (std::string const& ff : failures) {
+ msg << " \"" << ff << "\"\n";
}
errorMsg = msg.str();
return false;
@@ -3185,9 +3316,10 @@ bool SystemTools::FindProgramPath(const char* argv0, std::string& pathOut,
std::string SystemTools::CollapseFullPath(const std::string& in_relative)
{
- return SystemTools::CollapseFullPath(in_relative, 0);
+ return SystemTools::CollapseFullPath(in_relative, KWSYS_NULLPTR);
}
+#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP
void SystemTools::AddTranslationPath(const std::string& a,
const std::string& b)
{
@@ -3204,15 +3336,16 @@ void SystemTools::AddTranslationPath(const std::string& a,
if (SystemTools::FileIsFullPath(path_b) &&
path_b.find("..") == std::string::npos) {
// Before inserting make sure path ends with '/'
- if (!path_a.empty() && *path_a.rbegin() != '/') {
+ if (!path_a.empty() && path_a.back() != '/') {
path_a += '/';
}
- if (!path_b.empty() && *path_b.rbegin() != '/') {
+ if (!path_b.empty() && path_b.back() != '/') {
path_b += '/';
}
if (!(path_a == path_b)) {
- SystemTools::TranslationMap->insert(
- SystemToolsTranslationMap::value_type(path_a, path_b));
+ SystemTools::Statics->TranslationMap.insert(
+ SystemToolsStatic::StringMap::value_type(std::move(path_a),
+ std::move(path_b)));
}
}
}
@@ -3221,7 +3354,7 @@ void SystemTools::AddTranslationPath(const std::string& a,
void SystemTools::AddKeepPath(const std::string& dir)
{
std::string cdir;
- Realpath(SystemTools::CollapseFullPath(dir).c_str(), cdir);
+ Realpath(SystemTools::CollapseFullPath(dir), cdir);
SystemTools::AddTranslationPath(cdir, dir);
}
@@ -3236,37 +3369,45 @@ void SystemTools::CheckTranslationPath(std::string& path)
// 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 += "/";
+ 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:
- std::map<std::string, std::string>::const_iterator it;
- for (it = SystemTools::TranslationMap->begin();
- it != SystemTools::TranslationMap->end(); ++it) {
+ for (auto const& pair : SystemTools::Statics->TranslationMap) {
// 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);
+ if (path.find(pair.first) == 0) {
+ path = path.replace(0, pair.first.size(), pair.second);
}
}
// Remove the trailing slash we added before.
- path.erase(path.end() - 1, path.end());
+ path.pop_back();
}
+#endif
static void SystemToolsAppendComponents(
std::vector<std::string>& out_components,
- std::vector<std::string>::const_iterator first,
- std::vector<std::string>::const_iterator last)
+ std::vector<std::string>::iterator first,
+ std::vector<std::string>::iterator last)
{
static const std::string up = "..";
static const std::string cur = ".";
for (std::vector<std::string>::const_iterator i = first; i != last; ++i) {
if (*i == up) {
- if (out_components.size() > 1) {
+ // Remove the previous component if possible. Ignore ../ components
+ // that try to go above the root. Keep ../ components if they are
+ // at the beginning of a relative path (base path is relative).
+ if (out_components.size() > 1 && out_components.back() != up) {
out_components.resize(out_components.size() - 1);
+ } else if (!out_components.empty() && out_components[0].empty()) {
+ out_components.emplace_back(std::move(*i));
}
} else if (!i->empty() && *i != cur) {
+#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L)
+ out_components.push_back(std::move(*i));
+#else
out_components.push_back(*i);
+#endif
}
}
}
@@ -3274,63 +3415,18 @@ static void SystemToolsAppendComponents(
std::string SystemTools::CollapseFullPath(const std::string& in_path,
const char* in_base)
{
- // Collect the output path components.
- std::vector<std::string> out_components;
-
- // Split the input path components.
- std::vector<std::string> path_components;
- SystemTools::SplitPath(in_path, path_components);
-
- // If the input path is relative, start with a base path.
- if (path_components[0].empty()) {
- std::vector<std::string> base_components;
- if (in_base) {
- // Use the given base path.
- SystemTools::SplitPath(in_base, base_components);
+ // Use the current working directory as a base path.
+ char buf[2048];
+ const char* res_in_base = in_base;
+ if (!res_in_base) {
+ if (const char* cwd = Getcwd(buf, 2048)) {
+ res_in_base = cwd;
} 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("");
- }
+ res_in_base = "";
}
-
- // 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.
- std::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);
- SystemTools::ConvertToUnixSlashes(newPath);
-#endif
- // Return the reconstructed path.
- return newPath;
+ return SystemTools::CollapseFullPath(in_path, std::string(res_in_base));
}
std::string SystemTools::CollapseFullPath(const std::string& in_path,
@@ -3342,9 +3438,10 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
// Split the input path components.
std::vector<std::string> path_components;
SystemTools::SplitPath(in_path, path_components);
+ out_components.reserve(path_components.size());
// If the input path is relative, start with a base path.
- if (path_components[0].length() == 0) {
+ if (path_components[0].empty()) {
std::vector<std::string> base_components;
// Use the given base path.
SystemTools::SplitPath(in_base, base_components);
@@ -3362,6 +3459,7 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
// Transform the path back to a string.
std::string newPath = SystemTools::JoinPath(out_components);
+#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP
// 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
@@ -3377,8 +3475,9 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
// SystemTools::AddTranslationPath(newPath, in_path);
SystemTools::CheckTranslationPath(newPath);
+#endif
#ifdef _WIN32
- newPath = SystemTools::GetActualCaseForPath(newPath);
+ newPath = SystemTools::Statics->GetActualCaseForPathCached(newPath);
SystemTools::ConvertToUnixSlashes(newPath);
#endif
// Return the reconstructed path.
@@ -3400,25 +3499,24 @@ std::string SystemTools::RelativePath(const std::string& local,
std::string r = SystemTools::CollapseFullPath(remote);
// split up both paths into arrays of strings using / as a separator
- std::vector<kwsys::String> localSplit =
- SystemTools::SplitString(l, '/', true);
- std::vector<kwsys::String> remoteSplit =
+ std::vector<std::string> localSplit = SystemTools::SplitString(l, '/', true);
+ std::vector<std::string> remoteSplit =
SystemTools::SplitString(r, '/', true);
- std::vector<kwsys::String>
+ std::vector<std::string>
commonPath; // store shared parts of path in this array
- std::vector<kwsys::String> finalPath; // store the final relative path here
+ std::vector<std::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
+// 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
@@ -3439,115 +3537,36 @@ std::string SystemTools::RelativePath(const std::string& local,
// 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 (std::string const& lp : localSplit) {
+ if (!lp.empty()) {
+ finalPath.emplace_back("../");
}
}
// for each entry that is not common in the remote path add it
// to the final path.
- for (std::vector<String>::iterator vit = remoteSplit.begin();
- vit != remoteSplit.end(); ++vit) {
- if (!vit->empty()) {
- finalPath.push_back(*vit);
+ for (std::string const& rp : remoteSplit) {
+ if (!rp.empty()) {
+ finalPath.push_back(rp);
}
}
std::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 (std::vector<String>::iterator vit1 = finalPath.begin();
- vit1 != finalPath.end(); ++vit1) {
- if (!relativePath.empty() && *relativePath.rbegin() != '/') {
- relativePath += "/";
+ for (std::string const& fp : finalPath) {
+ if (!relativePath.empty() && relativePath.back() != '/') {
+ relativePath += '/';
}
- relativePath += *vit1;
+ relativePath += fp;
}
return relativePath;
}
-#ifdef _WIN32
-static std::string GetCasePathName(std::string const& pathIn)
-{
- std::string casePath;
- std::vector<std::string> path_components;
- SystemTools::SplitPath(pathIn, path_components);
- if (path_components[0].empty()) // First component always exists.
- {
- // Relative paths cannot be converted.
- casePath = pathIn;
- return casePath;
- }
-
- // Start with root component.
- std::vector<std::string>::size_type idx = 0;
- casePath = path_components[idx++];
- // make sure drive letter is always upper case
- if (casePath.size() > 1 && casePath[1] == ':') {
- casePath[0] = toupper(casePath[0]);
- }
- 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 = "/";
- }
-
- // Convert case of all components that exist.
- bool converting = true;
- for (; idx < path_components.size(); idx++) {
- casePath += sep;
- sep = "/";
-
- if (converting) {
- // 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('*') != std::string::npos ||
- path_components[idx].find('?') != std::string::npos) {
- converting = false;
- } else {
- std::string test_str = casePath;
- test_str += path_components[idx];
- WIN32_FIND_DATAW findData;
- HANDLE hFind =
- ::FindFirstFileW(Encoding::ToWide(test_str).c_str(), &findData);
- if (INVALID_HANDLE_VALUE != hFind) {
- path_components[idx] = Encoding::ToNarrow(findData.cFileName);
- ::FindClose(hFind);
- } else {
- converting = false;
- }
- }
- }
-
- casePath += path_components[idx];
- }
- return casePath;
-}
-#endif
-
std::string SystemTools::GetActualCaseForPath(const std::string& p)
{
-#ifndef _WIN32
- return p;
+#ifdef _WIN32
+ return SystemToolsStatic::GetCasePathName(p);
#else
- // Check to see if actual case has already been called
- // for this path, and the result is stored in the PathCaseMap
- SystemToolsPathCaseMap::iterator i = SystemTools::PathCaseMap->find(p);
- if (i != SystemTools::PathCaseMap->end()) {
- return i->second;
- }
- std::string casePath = GetCasePathName(p);
- if (casePath.size() > MAX_PATH) {
- return casePath;
- }
- (*SystemTools::PathCaseMap)[p] = casePath;
- return casePath;
+ return p;
#endif
}
@@ -3647,7 +3666,7 @@ void SystemTools::SplitPath(const std::string& p,
}
#endif
if (!homedir.empty() &&
- (*homedir.rbegin() == '/' || *homedir.rbegin() == '\\')) {
+ (homedir.back() == '/' || homedir.back() == '\\')) {
homedir.resize(homedir.size() - 1);
}
SystemTools::SplitPath(homedir, components);
@@ -3685,8 +3704,7 @@ std::string SystemTools::JoinPath(
// Construct result in a single string.
std::string result;
size_t len = 0;
- std::vector<std::string>::const_iterator i;
- for (i = first; i != last; ++i) {
+ for (std::vector<std::string>::const_iterator i = first; i != last; ++i) {
len += 1 + i->size();
}
result.reserve(len);
@@ -3701,7 +3719,7 @@ std::string SystemTools::JoinPath(
// All remaining components are always separated with a slash.
while (first != last) {
- result.append("/");
+ result.push_back('/');
result.append((*first++));
}
@@ -3709,26 +3727,16 @@ std::string SystemTools::JoinPath(
return result;
}
-void SystemTools::RemoveEmptyPathElements(std::vector<std::string>& path)
-{
- if (path.empty()) {
- return;
- }
-
- path.erase(std::remove(path.begin() + 1, path.end(), std::string("")),
- path.end());
-}
-
bool SystemTools::ComparePath(const std::string& c1, const std::string& c2)
{
#if defined(_WIN32) || defined(__APPLE__)
-#ifdef _MSC_VER
+# ifdef _MSC_VER
return _stricmp(c1.c_str(), c2.c_str()) == 0;
-#elif defined(__APPLE__) || defined(__GNUC__)
+# elif defined(__APPLE__) || defined(__GNUC__)
return strcasecmp(c1.c_str(), c2.c_str()) == 0;
-#else
+# else
return SystemTools::Strucmp(c1.c_str(), c2.c_str()) == 0;
-#endif
+# endif
#else
return c1 == c2;
#endif
@@ -3742,11 +3750,11 @@ bool SystemTools::Split(const std::string& str,
while (lpos < data.length()) {
std::string::size_type rpos = data.find_first_of(separator, lpos);
if (rpos == std::string::npos) {
- // Line ends at end of string without a newline.
+ // String ends at end of string without a separator.
lines.push_back(data.substr(lpos));
return false;
} else {
- // Line ends in a "\n", remove the character.
+ // String ends in a separator, remove the character.
lines.push_back(data.substr(lpos, rpos - lpos));
}
lpos = rpos + 1;
@@ -3760,7 +3768,7 @@ bool SystemTools::Split(const std::string& str,
std::string data(str);
std::string::size_type lpos = 0;
while (lpos < data.length()) {
- std::string::size_type rpos = data.find_first_of("\n", lpos);
+ std::string::size_type rpos = data.find_first_of('\n', lpos);
if (rpos == std::string::npos) {
// Line ends at end of string without a newline.
lines.push_back(data.substr(lpos));
@@ -3807,11 +3815,12 @@ std::string SystemTools::GetFilenamePath(const std::string& filename)
*/
std::string SystemTools::GetFilenameName(const std::string& filename)
{
-#if defined(_WIN32)
- std::string::size_type slash_pos = filename.find_last_of("/\\");
+#if defined(_WIN32) || defined(KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES)
+ const char* separators = "/\\";
#else
- std::string::size_type slash_pos = filename.rfind('/');
+ char separators = '/';
#endif
+ std::string::size_type slash_pos = filename.find_last_of(separators);
if (slash_pos != std::string::npos) {
return filename.substr(slash_pos + 1);
} else {
@@ -4024,7 +4033,7 @@ bool SystemTools::LocateFileInDir(const char* filename, const char* dir,
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() == ':')
+ if (filename_dir_base.empty() || filename_dir_base.back() == ':')
#else
if (filename_dir_base.empty())
#endif
@@ -4052,16 +4061,16 @@ bool SystemTools::LocateFileInDir(const char* filename, const char* dir,
bool SystemTools::FileIsFullPath(const std::string& in_name)
{
- return SystemTools::FileIsFullPath(in_name.c_str(), in_name.size());
+ return SystemToolsStatic::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);
+ return SystemToolsStatic::FileIsFullPath(
+ in_name, in_name[0] ? (in_name[1] ? 2 : 1) : 0);
}
-bool SystemTools::FileIsFullPath(const char* in_name, size_t len)
+bool SystemToolsStatic::FileIsFullPath(const char* in_name, size_t len)
{
#if defined(_WIN32) || defined(__CYGWIN__)
// On Windows, the name must be at least two characters long.
@@ -4100,7 +4109,7 @@ bool SystemTools::GetShortPath(const std::string& path, std::string& shortPath)
std::string tempPath = path; // create a buffer
// if the path passed in has quotes around it, first remove the quotes
- if (!path.empty() && path[0] == '"' && *path.rbegin() == '"') {
+ if (!path.empty() && path[0] == '"' && path.back() == '"') {
tempPath = path.substr(1, path.length() - 2);
}
@@ -4124,66 +4133,6 @@ bool SystemTools::GetShortPath(const std::string& path, std::string& shortPath)
#endif
}
-void SystemTools::SplitProgramFromArgs(const std::string& path,
- std::string& program, std::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
- std::vector<std::string> e;
- std::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
- std::string dir = path;
- std::string::size_type spacePos = dir.rfind(' ');
- while (spacePos != std::string::npos) {
- std::string tryProg = dir.substr(0, spacePos);
- // See if the file exists
- if (SystemTools::FileExists(tryProg)) {
- program = tryProg;
- // remove trailing spaces from program
- std::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
- std::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 = "";
-}
-
std::string SystemTools::GetCurrentDateTime(const char* format)
{
char buf[1024];
@@ -4212,23 +4161,16 @@ std::string SystemTools::MakeCidentifier(const std::string& s)
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
+// Convenience function around std::getline which removes a trailing carriage
+// return and can truncate the buffer as needed. Returns true
// if any data were read before the end-of-file was reached.
bool SystemTools::GetLineFromStream(std::istream& is, std::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...)
@@ -4240,44 +4182,23 @@ bool SystemTools::GetLineFromStream(std::istream& is, std::string& line,
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 &&
- (static_cast<void>(is.clear(is.rdstate() & ~std::ios::failbit)),
- static_cast<void>(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;
- }
-
+ std::getline(is, line);
+ bool haveData = !line.empty() || !is.eof();
+ if (!line.empty()) {
// Avoid storing a carriage return character.
- if (length > 0 && buffer[length - 1] == '\r') {
- buffer[length - 1] = 0;
+ if (line.back() == '\r') {
+ line.resize(line.size() - 1);
}
// if we read too much then truncate the buffer
- if (leftToRead > 0) {
- if (static_cast<long>(length) > leftToRead) {
- buffer[leftToRead] = 0;
- leftToRead = 0;
- } else {
- leftToRead -= static_cast<long>(length);
- }
+ if (sizeLimit >= 0 && line.size() >= static_cast<size_t>(sizeLimit)) {
+ line.resize(sizeLimit);
}
-
- // Append the data read to the line.
- line.append(buffer);
}
// Return the results.
if (has_newline) {
- *has_newline = haveNewline;
+ *has_newline = !is.eof();
}
return haveData;
}
@@ -4338,8 +4259,9 @@ bool SystemTools::GetPermissions(const std::string& file, mode_t& mode)
}
size_t dotPos = file.rfind('.');
const char* ext = dotPos == std::string::npos ? 0 : (file.c_str() + dotPos);
- if (ext && (Strucmp(ext, ".exe") == 0 || Strucmp(ext, ".com") == 0 ||
- Strucmp(ext, ".cmd") == 0 || Strucmp(ext, ".bat") == 0)) {
+ 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
@@ -4399,11 +4321,16 @@ bool SystemTools::IsSubDirectory(const std::string& cSubdir,
std::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);
+ if (subdir.size() <= dir.size() || dir.empty()) {
+ return false;
}
- return false;
+ bool isRootPath = dir.back() == '/'; // like "/" or "C:/"
+ size_t expectedSlashPosition = isRootPath ? dir.size() - 1u : dir.size();
+ if (subdir[expectedSlashPosition] != '/') {
+ return false;
+ }
+ std::string s = subdir.substr(0, dir.size());
+ return SystemTools::ComparePath(s, dir);
}
void SystemTools::Delay(unsigned int msec)
@@ -4440,24 +4367,31 @@ std::string SystemTools::GetOperatingSystemNameAndVersion()
ZeroMemory(&osvi, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(push)
-#ifdef __INTEL_COMPILER
-#pragma warning(disable : 1478)
-#else
-#pragma warning(disable : 4996)
-#endif
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# pragma warning(push)
+# ifdef __INTEL_COMPILER
+# pragma warning(disable : 1478)
+# elif defined __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# else
+# pragma warning(disable : 4996)
+# endif
+# endif
bOsVersionInfoEx = GetVersionExA((OSVERSIONINFOA*)&osvi);
if (!bOsVersionInfoEx) {
return 0;
}
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
-#pragma warning(pop)
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersionEx
+# ifdef __clang__
+# pragma clang diagnostic pop
+# else
+# pragma warning(pop)
+# endif
+# endif
switch (osvi.dwPlatformId) {
- // Test for the Windows NT product family.
+ // Test for the Windows NT product family.
case VER_PLATFORM_WIN32_NT:
@@ -4575,7 +4509,7 @@ std::string SystemTools::GetOperatingSystemNameAndVersion()
else {
HKEY hKey;
-#define BUFSIZE 80
+# define BUFSIZE 80
wchar_t szProductType[BUFSIZE];
DWORD dwBufLen = BUFSIZE;
LONG lRet;
@@ -4657,7 +4591,7 @@ std::string SystemTools::GetOperatingSystemNameAndVersion()
break;
- // Test for the Windows 95 product family.
+ // Test for the Windows 95 product family.
case VER_PLATFORM_WIN32_WINDOWS:
@@ -4741,14 +4675,7 @@ bool SystemTools::ParseURL(const std::string& URL, std::string& protocol,
// These must NOT be initialized. Default initialization to zero is
// necessary.
static unsigned int SystemToolsManagerCount;
-SystemToolsTranslationMap* SystemTools::TranslationMap;
-#ifdef _WIN32
-SystemToolsPathCaseMap* SystemTools::PathCaseMap;
-SystemToolsEnvMap* SystemTools::EnvMap;
-#endif
-#ifdef __CYGWIN__
-SystemToolsTranslationMap* SystemTools::Cyg2Win32Map;
-#endif
+SystemToolsStatic* SystemTools::Statics;
// SystemToolsManager manages the SystemTools singleton.
// SystemToolsManager should be included in any translation unit
@@ -4789,20 +4716,15 @@ void SystemTools::ClassInitialize()
#ifdef __VMS
SetVMSFeature("DECC$FILENAME_UNIX_ONLY", 1);
#endif
- // Allocate the translation map first.
- SystemTools::TranslationMap = new SystemToolsTranslationMap;
-#ifdef _WIN32
- SystemTools::PathCaseMap = new SystemToolsPathCaseMap;
- SystemTools::EnvMap = new SystemToolsEnvMap;
-#endif
-#ifdef __CYGWIN__
- SystemTools::Cyg2Win32Map = new SystemToolsTranslationMap;
-#endif
+ // Create statics singleton instance
+ SystemTools::Statics = new SystemToolsStatic;
+
+#if KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP
// 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__)
+# if !defined(_WIN32) || defined(__CYGWIN__)
// The tmp path is frequently a logical path so always keep it:
SystemTools::AddKeepPath("/tmp/");
@@ -4840,27 +4762,21 @@ void SystemTools::ClassInitialize()
}
}
}
+# endif
#endif
}
void SystemTools::ClassFinalize()
{
- delete SystemTools::TranslationMap;
-#ifdef _WIN32
- delete SystemTools::PathCaseMap;
- delete SystemTools::EnvMap;
-#endif
-#ifdef __CYGWIN__
- delete SystemTools::Cyg2Win32Map;
-#endif
+ delete SystemTools::Statics;
}
} // namespace KWSYS_NAMESPACE
#if defined(_MSC_VER) && defined(_DEBUG)
-#include <crtdbg.h>
-#include <stdio.h>
-#include <stdlib.h>
+# include <crtdbg.h>
+# include <stdio.h>
+# include <stdlib.h>
namespace KWSYS_NAMESPACE {
static int SystemToolsDebugReport(int, char* message, int*)
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index 5e091c2af..dd1266bee 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -10,14 +10,12 @@
#include <string>
#include <vector>
-#include <@KWSYS_NAMESPACE@/String.hxx>
-
#include <sys/types.h>
// include sys/stat.h after sys/types.h
#include <sys/stat.h>
#if !defined(_WIN32) || defined(__CYGWIN__)
-#include <unistd.h> // For access permissions for use with access()
+# include <unistd.h> // For access permissions for use with access()
#endif
// Required for va_list
@@ -43,9 +41,7 @@ typedef @KWSYS_NAMESPACE@_VA_LIST::hack_va_list va_list;
namespace @KWSYS_NAMESPACE@ {
-class SystemToolsTranslationMap;
-class SystemToolsPathCaseMap;
-class SystemToolsEnvMap;
+class SystemToolsStatic;
/** \class SystemToolsManager
* \brief Use to make sure SystemTools is initialized before it is used
@@ -56,6 +52,9 @@ class @KWSYS_NAMESPACE@_EXPORT SystemToolsManager
public:
SystemToolsManager();
~SystemToolsManager();
+
+ SystemToolsManager(const SystemToolsManager&) = delete;
+ SystemToolsManager& operator=(const SystemToolsManager&) = delete;
};
// This instance will show up in any translation unit that uses
@@ -107,7 +106,7 @@ public:
}
/**
- * Replace replace all occurences of the string in the source string.
+ * Replace replace all occurrences of the string in the source string.
*/
static void ReplaceString(std::string& source, const char* replace,
const char* with);
@@ -175,7 +174,7 @@ public:
static bool StringEndsWith(const std::string& str1, const char* str2);
/**
- * Returns a pointer to the last occurence of str2 in str1
+ * Returns a pointer to the last occurrence of str2 in str1
*/
static const char* FindLastString(const char* str1, const char* str2);
@@ -197,22 +196,15 @@ public:
s starts with a / then the first element of the returned array will
be /, so /foo/bar will be [/, foo, bar]
*/
- static std::vector<String> SplitString(const std::string& s,
- char separator = '/',
- bool isPath = false);
+ static std::vector<std::string> SplitString(const std::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
*/
@@ -325,11 +317,11 @@ public:
* Cross platform wrapper for stat struct
*/
#if defined(_WIN32) && !defined(__CYGWIN__)
-#if defined(__BORLANDC__)
+# if defined(__BORLANDC__)
typedef struct stati64 Stat_t;
-#else
+# else
typedef struct _stat64 Stat_t;
-#endif
+# endif
#else
typedef struct stat Stat_t;
#endif
@@ -461,6 +453,10 @@ public:
* produce the original path. Home directory references are
* automatically expanded if expand_home_dir is true and this
* platform supports them.
+ *
+ * This does *not* normalize the input path. All components are
+ * preserved, including empty ones. Typically callers should use
+ * this only on paths that have already been normalized.
*/
static void SplitPath(const std::string& p,
std::vector<std::string>& components,
@@ -469,15 +465,15 @@ public:
/**
* Join components of a path name into a single string. See
* SplitPath for the format of the components.
+ *
+ * This does *not* normalize the input path. All components are
+ * preserved, including empty ones. Typically callers should use
+ * this only on paths that have already been normalized.
*/
static std::string JoinPath(const std::vector<std::string>& components);
static std::string JoinPath(std::vector<std::string>::const_iterator first,
std::vector<std::string>::const_iterator last);
- /** Removes empty components from path.
- */
- static void RemoveEmptyPathElements(std::vector<std::string>& path);
-
/**
* Compare a path or components of a path.
*/
@@ -494,12 +490,6 @@ public:
static std::string GetFilenameName(const std::string&);
/**
- * Split a program from its arguments and handle spaces in the paths
- */
- static void SplitProgramFromArgs(const std::string& path,
- std::string& program, std::string& args);
-
- /**
* Return longest file extension of a full filename (dot included)
*/
static std::string GetFilenameExtension(const std::string&);
@@ -532,9 +522,8 @@ public:
static bool GetShortPath(const std::string& path, std::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
+ * Read line from file. Make sure to read a full line and truncates it if
+ * requested via sizeLimit. 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.
*/
@@ -562,13 +551,20 @@ public:
*/
static FILE* Fopen(const std::string& file, const char* mode);
+/**
+ * Visual C++ does not define mode_t (note that Borland does, however).
+ */
+#if defined(_MSC_VER)
+ typedef unsigned short mode_t;
+#endif
+
/**
* 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 std::string& path);
+ static bool MakeDirectory(const char* path, const mode_t* mode = 0);
+ static bool MakeDirectory(const std::string& path, const mode_t* mode = 0);
/**
* Copy the source file to the destination file only
@@ -584,6 +580,13 @@ public:
const std::string& destination);
/**
+ * Compare the contents of two files, ignoring line ending differences.
+ * Return true if different
+ */
+ static bool TextFilesDiffer(const std::string& path1,
+ const std::string& path2);
+
+ /**
* Return true if the two files are the same file
*/
static bool SameFile(const std::string& file1, const std::string& file2);
@@ -758,13 +761,6 @@ public:
*/
static long int CreationTime(const std::string& filename);
-/**
- * Visual C++ does not define mode_t (note that Borland does, however).
- */
-#if defined(_MSC_VER)
- typedef unsigned short mode_t;
-#endif
-
/**
* Get and set permissions of the file. If honor_umask is set, the umask
* is queried and applied to the given permissions. Returns false if
@@ -890,11 +886,12 @@ public:
/**
* 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
+ * make sure you have some reasonable defaults prepared if the code returns
* some bogus size.
*/
static int GetTerminalWidth();
+#if @KWSYS_NAMESPACE@_SYSTEMTOOLS_USE_TRANSLATION_MAP
/**
* Add an entry in the path translation table.
*/
@@ -911,10 +908,11 @@ public:
* Update path by going through the Path Translation table;
*/
static void CheckTranslationPath(std::string& path);
+#endif
/**
* Delay the execution for a specified amount of time specified
- * in miliseconds
+ * in milliseconds
*/
static void Delay(unsigned int msec);
@@ -969,40 +967,8 @@ private:
return &SystemToolsManagerInstance;
}
- /**
- * Actual implementation of ReplaceString.
- */
- static void ReplaceString(std::string& source, const char* replace,
- size_t replaceSize, const std::string& with);
-
- /**
- * 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 std::string FindName(
- const std::string& name,
- const std::vector<std::string>& path = std::vector<std::string>(),
- bool no_system_path = false);
-
- static const char* GetEnvImpl(const char* key);
-
- /**
- * Path translation table from dir to refdir
- * Each time 'dir' will be found it will be replace by 'refdir'
- */
- static SystemToolsTranslationMap* TranslationMap;
-#ifdef _WIN32
- static SystemToolsPathCaseMap* PathCaseMap;
- static SystemToolsEnvMap* EnvMap;
-#endif
-#ifdef __CYGWIN__
- static SystemToolsTranslationMap* Cyg2Win32Map;
-#endif
+ static SystemToolsStatic* Statics;
+ friend class SystemToolsStatic;
friend class SystemToolsManager;
};
diff --git a/Source/kwsys/Terminal.c b/Source/kwsys/Terminal.c
index eaa5c7d43..4dd246148 100644
--- a/Source/kwsys/Terminal.c
+++ b/Source/kwsys/Terminal.c
@@ -6,15 +6,15 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "Terminal.h.in"
+# include "Terminal.h.in"
#endif
/* Configure support for this platform. */
#if defined(_WIN32) || defined(__CYGWIN__)
-#define KWSYS_TERMINAL_SUPPORT_CONSOLE
+# define KWSYS_TERMINAL_SUPPORT_CONSOLE
#endif
#if !defined(_WIN32)
-#define KWSYS_TERMINAL_ISATTY_WORKS
+# define KWSYS_TERMINAL_ISATTY_WORKS
#endif
/* Include needed system APIs. */
@@ -24,14 +24,14 @@
#include <string.h> /* strcmp */
#if defined(KWSYS_TERMINAL_SUPPORT_CONSOLE)
-#include <io.h> /* _get_osfhandle */
-#include <windows.h> /* SetConsoleTextAttribute */
+# include <io.h> /* _get_osfhandle */
+# include <windows.h> /* SetConsoleTextAttribute */
#endif
#if defined(KWSYS_TERMINAL_ISATTY_WORKS)
-#include <unistd.h> /* isatty */
+# include <unistd.h> /* isatty */
#else
-#include <sys/stat.h> /* fstat */
+# include <sys/stat.h> /* fstat */
#endif
static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
@@ -103,6 +103,8 @@ static int kwsysTerminalStreamIsNotInteractive(FILE* stream)
/* List of terminal names known to support VT100 color escape sequences. */
static const char* kwsysTerminalVT100Names[] = { "Eterm",
+ "alacritty",
+ "alacritty-direct",
"ansi",
"color-xterm",
"con132x25",
@@ -153,6 +155,7 @@ static const char* kwsysTerminalVT100Names[] = { "Eterm",
"xterm-88color",
"xterm-color",
"xterm-debian",
+ "xterm-kitty",
"xterm-termite",
0 };
@@ -208,27 +211,34 @@ static int kwsysTerminalStreamIsVT100(FILE* stream, int default_vt100,
}
/* 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"
+#if defined(__MVS__)
+/* if building on z/OS (aka MVS), assume we are using EBCDIC */
+# define ESCAPE_CHAR "\47"
+#else
+# define ESCAPE_CHAR "\33"
+#endif
+
+#define KWSYS_TERMINAL_VT100_NORMAL ESCAPE_CHAR "[0m"
+#define KWSYS_TERMINAL_VT100_BOLD ESCAPE_CHAR "[1m"
+#define KWSYS_TERMINAL_VT100_UNDERLINE ESCAPE_CHAR "[4m"
+#define KWSYS_TERMINAL_VT100_BLINK ESCAPE_CHAR "[5m"
+#define KWSYS_TERMINAL_VT100_INVERSE ESCAPE_CHAR "[7m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_BLACK ESCAPE_CHAR "[30m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_RED ESCAPE_CHAR "[31m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_GREEN ESCAPE_CHAR "[32m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_YELLOW ESCAPE_CHAR "[33m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_BLUE ESCAPE_CHAR "[34m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_MAGENTA ESCAPE_CHAR "[35m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_CYAN ESCAPE_CHAR "[36m"
+#define KWSYS_TERMINAL_VT100_FOREGROUND_WHITE ESCAPE_CHAR "[37m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_BLACK ESCAPE_CHAR "[40m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_RED ESCAPE_CHAR "[41m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_GREEN ESCAPE_CHAR "[42m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_YELLOW ESCAPE_CHAR "[43m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_BLUE ESCAPE_CHAR "[44m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_MAGENTA ESCAPE_CHAR "[45m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_CYAN ESCAPE_CHAR "[46m"
+#define KWSYS_TERMINAL_VT100_BACKGROUND_WHITE ESCAPE_CHAR "[47m"
/* Write VT100 escape sequences to the stream for the given color. */
static void kwsysTerminalSetVT100Color(FILE* stream, int color)
@@ -300,10 +310,12 @@ static void kwsysTerminalSetVT100Color(FILE* stream, int color)
#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)
+# 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)
@@ -311,7 +323,7 @@ static HANDLE kwsysTerminalGetStreamHandle(FILE* stream)
/* Get the C-library file descriptor from the stream. */
int fd = fileno(stream);
-#if defined(__CYGWIN__)
+# 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. */
@@ -320,7 +332,7 @@ static HANDLE kwsysTerminalGetStreamHandle(FILE* stream)
} else if (fd == fileno(stderr)) {
return GetStdHandle(STD_ERROR_HANDLE);
}
-#endif
+# endif
/* Get the underlying Windows handle for the descriptor. */
return (HANDLE)_get_osfhandle(fd);
diff --git a/Source/kwsys/Terminal.h.in b/Source/kwsys/Terminal.h.in
index 5d2983004..1a2c7452f 100644
--- a/Source/kwsys/Terminal.h.in
+++ b/Source/kwsys/Terminal.h.in
@@ -12,57 +12,57 @@
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
+# 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)
+# 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)
@@ -135,36 +135,36 @@ enum kwsysTerminal_Color_e
/* 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
+# 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/hash_map.hxx.in b/Source/kwsys/hash_map.hxx.in
index 3f9174f3b..5f04e9c16 100644
--- a/Source/kwsys/hash_map.hxx.in
+++ b/Source/kwsys/hash_map.hxx.in
@@ -35,21 +35,21 @@
#include <functional> // equal_to
#if defined(_MSC_VER)
-#pragma warning(push)
-#pragma warning(disable : 4284)
-#pragma warning(disable : 4786)
+# 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
+# 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 std::unary_function<std::pair<T1, T2>, T1>
+struct hash_select1st
{
const T1& operator()(const std::pair<T1, T2>& __x) const
{
@@ -412,12 +412,12 @@ inline void swap(hash_multimap<_Key, _Tp, _HashFcn, _EqlKey, _Alloc>& __hm1,
} // namespace @KWSYS_NAMESPACE@
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
-#pragma reset woff 1174
-#pragma reset woff 1375
+# pragma reset woff 1174
+# pragma reset woff 1375
#endif
#if defined(_MSC_VER)
-#pragma warning(pop)
+# pragma warning(pop)
#endif
#endif
diff --git a/Source/kwsys/hash_set.hxx.in b/Source/kwsys/hash_set.hxx.in
index e3a0c6c44..f4a37eebd 100644
--- a/Source/kwsys/hash_set.hxx.in
+++ b/Source/kwsys/hash_set.hxx.in
@@ -35,21 +35,21 @@
#include <functional> // equal_to
#if defined(_MSC_VER)
-#pragma warning(push)
-#pragma warning(disable : 4284)
-#pragma warning(disable : 4786)
+# 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
+# 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 std::unary_function<_Tp, _Tp>
+struct _Identity
{
const _Tp& operator()(const _Tp& __x) const { return __x; }
};
@@ -381,12 +381,12 @@ inline void swap(hash_multiset<_Val, _HashFcn, _EqualKey, _Alloc>& __hs1,
} // namespace @KWSYS_NAMESPACE@
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
-#pragma reset woff 1174
-#pragma reset woff 1375
+# pragma reset woff 1174
+# pragma reset woff 1375
#endif
#if defined(_MSC_VER)
-#pragma warning(pop)
+# pragma warning(pop)
#endif
#endif
diff --git a/Source/kwsys/hashtable.hxx.in b/Source/kwsys/hashtable.hxx.in
index dd92cb9d4..0981c66ff 100644
--- a/Source/kwsys/hashtable.hxx.in
+++ b/Source/kwsys/hashtable.hxx.in
@@ -26,43 +26,42 @@
*
*/
#ifdef __BORLANDC__
-#pragma warn - 8027 /* 'for' not inlined. */
-#pragma warn - 8026 /* 'exception' not inlined. */
+# 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 <algorithm> // lower_bound
-#include <functional> // unary_function
-#include <iterator> // iterator_traits
-#include <memory> // allocator
-#include <stddef.h> // size_t
-#include <utility> // pair
-#include <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
+# define @KWSYS_NAMESPACE@_hashtable_hxx
+
+# include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+# include <algorithm> // lower_bound
+# include <iterator> // iterator_traits
+# include <memory> // allocator
+# include <stddef.h> // size_t
+# include <utility> // pair
+# include <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 defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated"
+# endif
+# endif
namespace @KWSYS_NAMESPACE@ {
@@ -74,7 +73,7 @@ struct _Hashtable_node
void public_method_to_quiet_warning_about_all_methods_private();
private:
- void operator=(_Hashtable_node<_Val> const&); // poison node assignment
+ void operator=(_Hashtable_node<_Val> const&) = delete;
};
template <class _Val, class _Key, class _HashFcn, class _ExtractKey,
@@ -251,6 +250,7 @@ private:
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;
@@ -569,7 +569,7 @@ private:
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++()
+_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++()
{
const _Node* __old = _M_cur;
_M_cur = _M_cur->_M_next;
@@ -584,7 +584,7 @@ _Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>&
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)
+_Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++(int)
{
iterator __tmp = *this;
++*this;
@@ -594,7 +594,7 @@ inline _Hashtable_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>
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++()
+_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++()
{
const _Node* __old = _M_cur;
_M_cur = _M_cur->_M_next;
@@ -609,7 +609,7 @@ _Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>&
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)
+_Hashtable_const_iterator<_Val, _Key, _HF, _ExK, _EqK, _All>::operator++(int)
{
const_iterator __tmp = *this;
++*this;
@@ -694,8 +694,9 @@ hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::insert_equal_noresize(
}
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)
+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);
@@ -963,7 +964,7 @@ void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_copy_from(
_Node* __copy = _M_new_node(__cur->_M_val);
_M_buckets[__i] = __copy;
- for (_Node *__next = __cur->_M_next; __next;
+ 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;
@@ -980,14 +981,14 @@ void hashtable<_Val, _Key, _HF, _Ex, _Eq, _All>::_M_copy_from(
} // namespace @KWSYS_NAMESPACE@
// 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
+# 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/kwsysPlatformTests.cmake b/Source/kwsys/kwsysPlatformTests.cmake
index 5386a49a3..28d3f68e2 100644
--- a/Source/kwsys/kwsysPlatformTests.cmake
+++ b/Source/kwsys/kwsysPlatformTests.cmake
@@ -7,11 +7,16 @@ SET(KWSYS_PLATFORM_TEST_FILE_CXX kwsysPlatformTestsCXX.cxx)
MACRO(KWSYS_PLATFORM_TEST lang var description invert)
IF(NOT DEFINED ${var}_COMPILED)
MESSAGE(STATUS "${description}")
+ set(maybe_cxx_standard "")
+ if(CMAKE_VERSION VERSION_LESS 3.8 AND CMAKE_CXX_STANDARD)
+ set(maybe_cxx_standard "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
+ endif()
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}"
+ ${maybe_cxx_standard}
OUTPUT_VARIABLE OUTPUT)
IF(${var}_COMPILED)
FILE(APPEND
diff --git a/Source/kwsys/kwsysPlatformTestsC.c b/Source/kwsys/kwsysPlatformTestsC.c
index 64a361bbe..b0cf7ad3b 100644
--- a/Source/kwsys/kwsysPlatformTestsC.c
+++ b/Source/kwsys/kwsysPlatformTestsC.c
@@ -17,18 +17,18 @@
}
*/
#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[];
+# 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[])
+# 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>
+# include <stddef.h>
int f(ptrdiff_t n)
{
return n > 0;
@@ -43,7 +43,7 @@ int KWSYS_PLATFORM_TEST_C_MAIN()
#endif
#ifdef TEST_KWSYS_C_HAS_SSIZE_T
-#include <unistd.h>
+# include <unistd.h>
int f(ssize_t n)
{
return (int)n;
@@ -55,32 +55,47 @@ int KWSYS_PLATFORM_TEST_C_MAIN()
}
#endif
+#ifdef TEST_KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
+# if defined(__APPLE__)
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
+# error "clock_gettime not available on macOS < 10.12"
+# endif
+# endif
+# include <time.h>
+int KWSYS_PLATFORM_TEST_C_MAIN()
+{
+ struct timespec ts;
+ return clock_gettime(CLOCK_MONOTONIC, &ts);
+}
+#endif
+
#ifdef TEST_KWSYS_C_TYPE_MACROS
char* info_macros =
-#if defined(__SIZEOF_SHORT__)
+# if defined(__SIZEOF_SHORT__)
"INFO:macro[__SIZEOF_SHORT__]\n"
-#endif
-#if defined(__SIZEOF_INT__)
+# endif
+# if defined(__SIZEOF_INT__)
"INFO:macro[__SIZEOF_INT__]\n"
-#endif
-#if defined(__SIZEOF_LONG__)
+# endif
+# if defined(__SIZEOF_LONG__)
"INFO:macro[__SIZEOF_LONG__]\n"
-#endif
-#if defined(__SIZEOF_LONG_LONG__)
+# endif
+# if defined(__SIZEOF_LONG_LONG__)
"INFO:macro[__SIZEOF_LONG_LONG__]\n"
-#endif
-#if defined(__SHORT_MAX__)
+# endif
+# if defined(__SHORT_MAX__)
"INFO:macro[__SHORT_MAX__]\n"
-#endif
-#if defined(__INT_MAX__)
+# endif
+# if defined(__INT_MAX__)
"INFO:macro[__INT_MAX__]\n"
-#endif
-#if defined(__LONG_MAX__)
+# endif
+# if defined(__LONG_MAX__)
"INFO:macro[__LONG_MAX__]\n"
-#endif
-#if defined(__LONG_LONG_MAX__)
+# endif
+# if defined(__LONG_LONG_MAX__)
"INFO:macro[__LONG_LONG_MAX__]\n"
-#endif
+# endif
"";
int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)
diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx
index 01c69514c..cfd5666f3 100644
--- a/Source/kwsys/kwsysPlatformTestsCXX.cxx
+++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx
@@ -1,7 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifdef TEST_KWSYS_CXX_HAS_CSTDIO
-#include <cstdio>
+# include <cstdio>
int main()
{
return 0;
@@ -33,10 +33,10 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIM
-#include <sys/types.h>
+# include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+# include <sys/stat.h>
+# include <unistd.h>
int main()
{
struct stat stat1;
@@ -47,10 +47,10 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_STAT_HAS_ST_MTIMESPEC
-#include <sys/types.h>
+# include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+# include <sys/stat.h>
+# include <unistd.h>
int main()
{
struct stat stat1;
@@ -85,7 +85,7 @@ int main()
#endif
#ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
-#include <iostream>
+# include <iostream>
int test_istream(std::istream& is, long long& x)
{
return (is >> x) ? 1 : 0;
@@ -98,7 +98,7 @@ int main()
#endif
#ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
-#include <iostream>
+# include <iostream>
int test_ostream(std::ostream& os, long long x)
{
return (os << x) ? 1 : 0;
@@ -111,7 +111,7 @@ int main()
#endif
#ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64
-#include <iostream>
+# include <iostream>
int test_istream(std::istream& is, __int64& x)
{
return (is >> x) ? 1 : 0;
@@ -124,7 +124,7 @@ int main()
#endif
#ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64
-#include <iostream>
+# include <iostream>
int test_ostream(std::ostream& os, __int64 x)
{
return (os << x) ? 1 : 0;
@@ -136,44 +136,8 @@ int main()
}
#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 <assert.h>
-#include <sys/stat.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>
+# include <stdlib.h>
int main()
{
return setenv("A", "B", 1);
@@ -181,7 +145,7 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_UNSETENV
-#include <stdlib.h>
+# include <stdlib.h>
int main()
{
unsetenv("A");
@@ -190,7 +154,7 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
-#include <stdlib.h>
+# include <stdlib.h>
int main()
{
char* e = environ[0];
@@ -200,10 +164,10 @@ int main()
#ifdef TEST_KWSYS_CXX_HAS_GETLOADAVG
// Match feature definitions from SystemInformation.cxx
-#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
-#define _GNU_SOURCE
-#endif
-#include <stdlib.h>
+# if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+# endif
+# include <stdlib.h>
int main()
{
double loadavg[3] = { 0.0, 0.0, 0.0 };
@@ -212,13 +176,7 @@ int main()
#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>
+# include <sys/resource.h>
int main()
{
struct rlimit64 rlim;
@@ -227,7 +185,7 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_ATOLL
-#include <stdlib.h>
+# include <stdlib.h>
int main()
{
const char* str = "1024";
@@ -236,7 +194,7 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_ATOL
-#include <stdlib.h>
+# include <stdlib.h>
int main()
{
const char* str = "1024";
@@ -245,7 +203,7 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS__ATOI64
-#include <stdlib.h>
+# include <stdlib.h>
int main()
{
const char* str = "1024";
@@ -254,7 +212,7 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_UTIMES
-#include <sys/time.h>
+# include <sys/time.h>
int main()
{
struct timeval* current_time = 0;
@@ -263,8 +221,14 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT
-#include <fcntl.h>
-#include <sys/stat.h>
+# include <fcntl.h>
+# include <sys/stat.h>
+# if defined(__APPLE__)
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MIN_REQUIRED < 101300
+# error "utimensat not available on macOS < 10.13"
+# endif
+# endif
int main()
{
struct timespec times[2] = { { 0, UTIME_OMIT }, { 0, UTIME_NOW } };
@@ -273,14 +237,14 @@ int main()
#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>
+# if defined(__PATHSCALE__) || defined(__PATHCC__) || \
+ (defined(__LSB_VERSION__) && (__LSB_VERSION__ < 41))
+backtrace does not 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];
@@ -291,10 +255,10 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_DLADDR
-#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
-#define _GNU_SOURCE
-#endif
-#include <dlfcn.h>
+# if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+# endif
+# include <dlfcn.h>
int main()
{
Dl_info info;
@@ -304,14 +268,14 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_CXXABI
-#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
-#define _GNU_SOURCE
-#endif
-#if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5130 && __linux && \
- __SUNPRO_CC_COMPAT == 'G'
-#include <iostream>
-#endif
-#include <cxxabi.h>
+# if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+# endif
+# if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5130 && __linux && \
+ __SUNPRO_CC_COMPAT == 'G'
+# include <iostream>
+# endif
+# include <cxxabi.h>
int main()
{
int status = 0;
@@ -352,7 +316,7 @@ int main()
#endif
#ifdef TEST_KWSYS_STL_HAS_WSTRING
-#include <string>
+# include <string>
void f(std::wstring*)
{
}
@@ -363,7 +327,7 @@ int main()
#endif
#ifdef TEST_KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H
-#include <ext/stdio_filebuf.h>
+# include <ext/stdio_filebuf.h>
int main()
{
return 0;
diff --git a/Source/kwsys/kwsysPrivate.h b/Source/kwsys/kwsysPrivate.h
index ce1b53ed8..dd9c1277f 100644
--- a/Source/kwsys/kwsysPrivate.h
+++ b/Source/kwsys/kwsysPrivate.h
@@ -1,11 +1,11 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifndef KWSYS_NAMESPACE
-#error "Do not include kwsysPrivate.h outside of kwsys c and cxx files."
+# error "Do not include kwsysPrivate.h outside of kwsys c and cxx files."
#endif
#ifndef _kwsysPrivate_h
-#define _kwsysPrivate_h
+# define _kwsysPrivate_h
/*
Define KWSYS_HEADER macro to help the c and cxx files include kwsys
@@ -18,17 +18,17 @@
/* clang-format off */
#define KWSYS_HEADER(x) KWSYS_HEADER0(KWSYS_NAMESPACE/x)
/* clang-format on */
-#define KWSYS_HEADER0(x) KWSYS_HEADER1(x)
-#define KWSYS_HEADER1(x) <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
+# 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."
+# error "kwsysPrivate.h included multiple times."
#endif
diff --git a/Source/kwsys/testCommandLineArguments.cxx b/Source/kwsys/testCommandLineArguments.cxx
index d2215d62f..15f9c02ba 100644
--- a/Source/kwsys/testCommandLineArguments.cxx
+++ b/Source/kwsys/testCommandLineArguments.cxx
@@ -6,7 +6,7 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "CommandLineArguments.hxx.in"
+# include "CommandLineArguments.hxx.in"
#endif
#include <iostream>
@@ -76,8 +76,8 @@ int testCommandLineArguments(int argc, char* argv[])
int some_int_variable = 10;
double some_double_variable = 10.10;
- char* some_string_variable = 0;
- std::string some_stl_string_variable = "";
+ char* some_string_variable = KWSYS_NULLPTR;
+ std::string some_stl_string_variable;
bool some_bool_variable = false;
bool some_bool_variable1 = false;
bool bool_arg1 = false;
@@ -136,7 +136,7 @@ int testCommandLineArguments(int argc, char* argv[])
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");
+ "This option takes concatenated 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,
@@ -165,25 +165,26 @@ int testCommandLineArguments(int argc, char* argv[])
}
size_t cc;
#define CompareTwoLists(list1, list_valid, lsize) \
- if (list1.size() != lsize) { \
- std::cerr << "Problem setting " #list1 ". Size is: " << list1.size() \
- << " should be: " << lsize << std::endl; \
- res = 1; \
- } else { \
- std::cout << #list1 " argument set:"; \
- for (cc = 0; cc < lsize; ++cc) { \
- std::cout << " " << list1[cc]; \
- if (!CompareTwoItemsOnList(list1[cc], list_valid[cc])) { \
- std::cerr << "Problem setting " #list1 ". Value of " << cc \
- << " is: [" << list1[cc] << "] <> [" << list_valid[cc] \
- << "]" << std::endl; \
- res = 1; \
- break; \
+ do { \
+ if (list1.size() != lsize) { \
+ std::cerr << "Problem setting " #list1 ". Size is: " << list1.size() \
+ << " should be: " << lsize << std::endl; \
+ res = 1; \
+ } else { \
+ std::cout << #list1 " argument set:"; \
+ for (cc = 0; cc < lsize; ++cc) { \
+ std::cout << " " << list1[cc]; \
+ if (!CompareTwoItemsOnList(list1[cc], list_valid[cc])) { \
+ std::cerr << "Problem setting " #list1 ". Value of " << cc \
+ << " is: [" << list1[cc] << "] <> [" << list_valid[cc] \
+ << "]" << std::endl; \
+ res = 1; \
+ break; \
+ } \
} \
+ std::cout << std::endl; \
} \
- std::cout << std::endl; \
- }
-
+ } while (0)
CompareTwoLists(numbers_argument, valid_numbers, 10);
CompareTwoLists(doubles_argument, valid_doubles, 3);
CompareTwoLists(bools_argument, valid_bools, 3);
@@ -202,7 +203,7 @@ int testCommandLineArguments(int argc, char* argv[])
for (cc = 0; cc < strings_argument.size(); ++cc) {
delete[] strings_argument[cc];
- strings_argument[cc] = 0;
+ strings_argument[cc] = KWSYS_NULLPTR;
}
return res;
}
diff --git a/Source/kwsys/testCommandLineArguments1.cxx b/Source/kwsys/testCommandLineArguments1.cxx
index 5a03401bc..9895008f0 100644
--- a/Source/kwsys/testCommandLineArguments1.cxx
+++ b/Source/kwsys/testCommandLineArguments1.cxx
@@ -6,7 +6,7 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "CommandLineArguments.hxx.in"
+# include "CommandLineArguments.hxx.in"
#endif
#include <iostream>
@@ -21,7 +21,7 @@ int testCommandLineArguments1(int argc, char* argv[])
arg.Initialize(argc, argv);
int n = 0;
- char* m = 0;
+ char* m = KWSYS_NULLPTR;
std::string p;
int res = 0;
@@ -55,11 +55,11 @@ int testCommandLineArguments1(int argc, char* argv[])
delete[] m;
}
- char** newArgv = 0;
+ char** newArgv = KWSYS_NULLPTR;
int newArgc = 0;
arg.GetUnusedArguments(&newArgc, &newArgv);
int cc;
- const char* valid_unused_args[9] = { 0,
+ const char* valid_unused_args[9] = { KWSYS_NULLPTR,
"--ignored",
"--second-ignored",
"third-ignored",
diff --git a/Source/kwsys/testConsoleBuf.cxx b/Source/kwsys/testConsoleBuf.cxx
index 816a4338e..b6ad1188d 100644
--- a/Source/kwsys/testConsoleBuf.cxx
+++ b/Source/kwsys/testConsoleBuf.cxx
@@ -13,24 +13,24 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Encoding.hxx.in"
+# include "Encoding.hxx.in"
#endif
#if defined(_WIN32)
-#include <algorithm>
-#include <iomanip>
-#include <iostream>
-#include <stdexcept>
-#include <string.h>
-#include <wchar.h>
-#include <windows.h>
+# include <algorithm>
+# include <iomanip>
+# include <iostream>
+# include <stdexcept>
+# include <string.h>
+# include <wchar.h>
+# include <windows.h>
-#include "testConsoleBuf.hxx"
+# include "testConsoleBuf.hxx"
-#if defined(_MSC_VER) && _MSC_VER >= 1800
-#define KWSYS_WINDOWS_DEPRECATED_GetVersion
-#endif
+# if defined(_MSC_VER) && _MSC_VER >= 1800
+# define KWSYS_WINDOWS_DEPRECATED_GetVersion
+# endif
// يونيكود
static const WCHAR UnicodeInputTestString[] =
L"\u064A\u0648\u0646\u064A\u0643\u0648\u062F!";
@@ -219,9 +219,9 @@ static void finishFile(HANDLE file)
}
}
-#ifndef MAPVK_VK_TO_VSC
-#define MAPVK_VK_TO_VSC (0)
-#endif
+# ifndef MAPVK_VK_TO_VSC
+# define MAPVK_VK_TO_VSC (0)
+# endif
static void writeInputKeyEvent(INPUT_RECORD inputBuffer[], WCHAR chr)
{
@@ -470,9 +470,9 @@ static int testFile()
return didFail;
}
-#ifndef _WIN32_WINNT_VISTA
-#define _WIN32_WINNT_VISTA 0x0600
-#endif
+# ifndef _WIN32_WINNT_VISTA
+# define _WIN32_WINNT_VISTA 0x0600
+# endif
static int testConsole()
{
@@ -495,19 +495,26 @@ static int testConsole()
DWORD FaceNameSize = sizeof(FaceName);
DWORD FontFamily = TestFontFamily;
DWORD FontSize = TestFontSize;
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersion
-#pragma warning(push)
-#ifdef __INTEL_COMPILER
-#pragma warning(disable : 1478)
-#else
-#pragma warning(disable : 4996)
-#endif
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersion
+# pragma warning(push)
+# ifdef __INTEL_COMPILER
+# pragma warning(disable : 1478)
+# elif defined __clang__
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated-declarations"
+# else
+# pragma warning(disable : 4996)
+# endif
+# endif
const bool isVistaOrGreater =
LOBYTE(LOWORD(GetVersion())) >= HIBYTE(_WIN32_WINNT_VISTA);
-#ifdef KWSYS_WINDOWS_DEPRECATED_GetVersion
-#pragma warning(pop)
-#endif
+# ifdef KWSYS_WINDOWS_DEPRECATED_GetVersion
+# ifdef __clang__
+# pragma clang diagnostic pop
+# else
+# pragma warning(pop)
+# endif
+# endif
if (!isVistaOrGreater) {
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Console", 0, KEY_READ | KEY_WRITE,
&hConsoleKey) == ERROR_SUCCESS) {
@@ -573,7 +580,7 @@ static int testConsole()
newConsole = true;
}
-#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
+# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
if (isVistaOrGreater) {
CONSOLE_FONT_INFOEX consoleFont;
memset(&consoleFont, 0, sizeof(consoleFont));
@@ -603,7 +610,7 @@ static int testConsole()
std::cerr << "GetCurrentConsoleFontEx failed!" << std::endl;
}
} else {
-#endif
+# endif
if (restoreConsole &&
RegOpenKeyExW(HKEY_CURRENT_USER, L"Console", 0, KEY_WRITE,
&hConsoleKey) == ERROR_SUCCESS) {
@@ -619,9 +626,9 @@ static int testConsole()
sizeof(FontSize));
RegCloseKey(hConsoleKey);
}
-#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
+# if _WIN32_WINNT >= _WIN32_WINNT_VISTA
}
-#endif
+# endif
if (createProcess(NULL, NULL, NULL)) {
try {
diff --git a/Source/kwsys/testConsoleBufChild.cxx b/Source/kwsys/testConsoleBufChild.cxx
index 6a743edcd..3c8fdc2e1 100644
--- a/Source/kwsys/testConsoleBufChild.cxx
+++ b/Source/kwsys/testConsoleBufChild.cxx
@@ -8,8 +8,8 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "ConsoleBuf.hxx.in"
-#include "Encoding.hxx.in"
+# include "ConsoleBuf.hxx.in"
+# include "Encoding.hxx.in"
#endif
#include <iostream>
diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx
index b52ddda8b..eff2ed7ee 100644
--- a/Source/kwsys/testDynamicLoader.cxx
+++ b/Source/kwsys/testDynamicLoader.cxx
@@ -5,13 +5,13 @@
#include KWSYS_HEADER(DynamicLoader.hxx)
#if defined(__BEOS__) || defined(__HAIKU__)
-#include <be/kernel/OS.h> /* disable_debugger() API. */
+# 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 "DynamicLoader.hxx.in"
#endif
#include <iostream>
@@ -21,11 +21,15 @@
// left on disk.
#include <testSystemTools.h>
-static std::string GetLibName(const char* lname)
+static std::string GetLibName(const char* lname, const char* subdir = NULL)
{
// Construct proper name of lib
std::string slname;
slname = EXECUTABLE_OUTPUT_PATH;
+ if (subdir) {
+ slname += "/";
+ slname += subdir;
+ }
#ifdef CMAKE_INTDIR
slname += "/";
slname += CMAKE_INTDIR;
@@ -45,26 +49,29 @@ static std::string GetLibName(const char* lname)
* r3: should CloseLibrary succeed ?
*/
static int TestDynamicLoader(const char* libname, const char* symbol, int r1,
- int r2, int r3)
+ int r2, int r3, int flags = 0)
{
std::cerr << "Testing: " << libname << std::endl;
kwsys::DynamicLoader::LibraryHandle l =
- kwsys::DynamicLoader::OpenLibrary(libname);
+ kwsys::DynamicLoader::OpenLibrary(libname, flags);
// If result is incompatible with expectation just fails (xor):
if ((r1 && !l) || (!r1 && l)) {
- std::cerr << kwsys::DynamicLoader::LastError() << std::endl;
+ std::cerr << "OpenLibrary: " << kwsys::DynamicLoader::LastError()
+ << std::endl;
return 1;
}
kwsys::DynamicLoader::SymbolPointer f =
kwsys::DynamicLoader::GetSymbolAddress(l, symbol);
if ((r2 && !f) || (!r2 && f)) {
- std::cerr << kwsys::DynamicLoader::LastError() << std::endl;
+ std::cerr << "GetSymbolAddress: " << kwsys::DynamicLoader::LastError()
+ << std::endl;
return 1;
}
#ifndef __APPLE__
int s = kwsys::DynamicLoader::CloseLibrary(l);
if ((r3 && !s) || (!r3 && s)) {
- std::cerr << kwsys::DynamicLoader::LastError() << std::endl;
+ std::cerr << "CloseLibrary: " << kwsys::DynamicLoader::LastError()
+ << std::endl;
return 1;
}
#else
@@ -113,5 +120,14 @@ int testDynamicLoader(int argc, char* argv[])
res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderData", 1, 1, 1);
res += TestDynamicLoader(libname.c_str(), "_TestDynamicLoaderData", 1, 0, 1);
+#ifdef _WIN32
+ libname = GetLibName(KWSYS_NAMESPACE_STRING "TestDynloadUse", "dynloaddir");
+ res += TestDynamicLoader(libname.c_str(), "dummy", 0, 0, 0);
+ res += TestDynamicLoader(libname.c_str(), "TestLoad", 1, 1, 1,
+ kwsys::DynamicLoader::SearchBesideLibrary);
+ res += TestDynamicLoader(libname.c_str(), "_TestLoad", 1, 0, 1,
+ kwsys::DynamicLoader::SearchBesideLibrary);
+#endif
+
return res;
}
diff --git a/Source/kwsys/testDynload.c b/Source/kwsys/testDynload.c
index cdb9e5c35..c49f747df 100644
--- a/Source/kwsys/testDynload.c
+++ b/Source/kwsys/testDynload.c
@@ -1,9 +1,9 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#ifdef _WIN32
-#define DL_EXPORT __declspec(dllexport)
+# define DL_EXPORT __declspec(dllexport)
#else
-#define DL_EXPORT
+# define DL_EXPORT
#endif
DL_EXPORT int TestDynamicLoaderData = 0;
diff --git a/Source/kwsys/testEncode.c b/Source/kwsys/testEncode.c
index a20d46fd3..b7b6dd845 100644
--- a/Source/kwsys/testEncode.c
+++ b/Source/kwsys/testEncode.c
@@ -6,7 +6,7 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "MD5.h.in"
+# include "MD5.h.in"
#endif
#include <stdio.h>
diff --git a/Source/kwsys/testEncoding.cxx b/Source/kwsys/testEncoding.cxx
index 2c5ef46eb..fdad1cdff 100644
--- a/Source/kwsys/testEncoding.cxx
+++ b/Source/kwsys/testEncoding.cxx
@@ -3,7 +3,7 @@
#include "kwsysPrivate.h"
#if defined(_MSC_VER)
-#pragma warning(disable : 4786)
+# pragma warning(disable : 4786)
#endif
#include KWSYS_HEADER(Encoding.hxx)
@@ -18,8 +18,8 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "Encoding.h.in"
-#include "Encoding.hxx.in"
+# include "Encoding.h.in"
+# include "Encoding.hxx.in"
#endif
static const unsigned char helloWorldStrings[][32] = {
@@ -75,12 +75,16 @@ static int testRobustEncoding()
// test that the conversion functions handle invalid
// unicode correctly/gracefully
+ // we manipulate the format flags of stdout, remember
+ // the original state here to restore before return
+ std::ios::fmtflags const& flags = std::cout.flags();
+
int ret = 0;
char cstr[] = { (char)-1, 0 };
// this conversion could fail
std::wstring wstr = kwsys::Encoding::ToWide(cstr);
- wstr = kwsys::Encoding::ToWide(NULL);
+ wstr = kwsys::Encoding::ToWide(KWSYS_NULLPTR);
if (wstr != L"") {
const wchar_t* wcstr = wstr.c_str();
std::cout << "ToWide(NULL) returned";
@@ -108,7 +112,7 @@ static int testRobustEncoding()
std::string win_str = kwsys::Encoding::ToNarrow(cwstr);
#endif
- std::string str = kwsys::Encoding::ToNarrow(NULL);
+ std::string str = kwsys::Encoding::ToNarrow(KWSYS_NULLPTR);
if (str != "") {
std::cout << "ToNarrow(NULL) returned " << str << std::endl;
ret++;
@@ -120,6 +124,7 @@ static int testRobustEncoding()
ret++;
}
+ std::cout.flags(flags);
return ret;
}
diff --git a/Source/kwsys/testFStream.cxx b/Source/kwsys/testFStream.cxx
index a92a781c3..5009e9887 100644
--- a/Source/kwsys/testFStream.cxx
+++ b/Source/kwsys/testFStream.cxx
@@ -3,19 +3,19 @@
#include "kwsysPrivate.h"
#if defined(_MSC_VER)
-#pragma warning(disable : 4786)
+# pragma warning(disable : 4786)
#endif
#include KWSYS_HEADER(FStream.hxx)
#include <string.h>
#ifdef __BORLANDC__
-#include <mem.h> /* memcmp */
+# 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 "FStream.hxx.in"
#endif
#include <iostream>
diff --git a/Source/kwsys/testHashSTL.cxx b/Source/kwsys/testHashSTL.cxx
index 044487473..4ed2f899d 100644
--- a/Source/kwsys/testHashSTL.cxx
+++ b/Source/kwsys/testHashSTL.cxx
@@ -7,18 +7,19 @@
// 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 "hash_map.hxx.in"
+# include "hash_set.hxx.in"
#endif
#include <iostream>
#if defined(_MSC_VER)
-#pragma warning(disable : 4786)
+# pragma warning(disable : 4786)
#endif
#if defined(__sgi) && !defined(__GNUC__)
-#pragma set woff 1468 /* inline function cannot be explicitly instantiated */
+# pragma set woff 1468 /* inline function cannot be explicitly instantiated \
+ */
#endif
template class kwsys::hash_map<const char*, int>;
diff --git a/Source/kwsys/testProcess.c b/Source/kwsys/testProcess.c
index 092dd0347..f139f5860 100644
--- a/Source/kwsys/testProcess.c
+++ b/Source/kwsys/testProcess.c
@@ -7,8 +7,8 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "Encoding.h.in"
-#include "Process.h.in"
+# include "Encoding.h.in"
+# include "Process.h.in"
#endif
#include <assert.h>
@@ -18,21 +18,21 @@
#include <string.h>
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <signal.h>
-#include <unistd.h>
+# include <signal.h>
+# include <unistd.h>
#endif
#if defined(__BORLANDC__)
-#pragma warn - 8060 /* possibly incorrect assignment */
+# pragma warn - 8060 /* possibly incorrect assignment */
#endif
/* Platform-specific sleep functions. */
#if defined(__BEOS__) && !defined(__ZETA__)
/* BeOS 5 doesn't have usleep(), but it has snooze(), which is identical. */
-#include <be/kernel/OS.h>
+# include <be/kernel/OS.h>
static inline void testProcess_usleep(unsigned int usec)
{
snooze(usec);
@@ -44,7 +44,7 @@ static void testProcess_usleep(unsigned int usec)
Sleep(usec / 1000);
}
#else
-#define testProcess_usleep usleep
+# define testProcess_usleep usleep
#endif
#if defined(_WIN32)
@@ -107,6 +107,7 @@ static int test3(int argc, const char* argv[])
static int test4(int argc, const char* argv[])
{
+#ifndef CRASH_USING_ABORT
/* 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
@@ -114,6 +115,7 @@ static int test4(int argc, const char* argv[])
'volatile' and a slightly larger address, based on a runtime value. */
volatile int* invalidAddress = 0;
invalidAddress += argc ? 1 : 2;
+#endif
#if defined(_WIN32)
/* Avoid error diagnostic popups since we are crashing on purpose. */
@@ -128,9 +130,13 @@ static int test4(int argc, const char* argv[])
fprintf(stderr, "Output before crash on stderr from crash test.\n");
fflush(stdout);
fflush(stderr);
+#ifdef CRASH_USING_ABORT
+ abort();
+#else
assert(invalidAddress); /* Quiet Clang scan-build. */
/* Provoke deliberate crash by writing to the invalid address. */
*invalidAddress = 0;
+#endif
fprintf(stdout, "Output after crash on stdout from crash test.\n");
fprintf(stderr, "Output after crash on stderr from crash test.\n");
return 0;
@@ -149,7 +155,12 @@ static int test5(int argc, const char* argv[])
fprintf(stderr, "Output on stderr before recursive test.\n");
fflush(stdout);
fflush(stderr);
- r = runChild(cmd, kwsysProcess_State_Exception, kwsysProcess_Exception_Fault,
+ r = runChild(cmd, kwsysProcess_State_Exception,
+#ifdef CRASH_USING_ABORT
+ kwsysProcess_Exception_Other,
+#else
+ kwsysProcess_Exception_Fault,
+#endif
1, 1, 1, 0, 15, 0, 1, 0, 0, 0);
fprintf(stdout, "Output on stdout after recursive test.\n");
fprintf(stderr, "Output on stderr after recursive test.\n");
@@ -470,20 +481,23 @@ static int runChild2(kwsysProcess* kp, const char* cmd[], int state,
if (result) {
if (exception != kwsysProcess_GetExitException(kp)) {
- fprintf(stderr, "Mismatch in exit exception. "
- "Should have been %d, was %d.\n",
+ 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",
+ 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",
+ fprintf(stderr,
+ "Mismatch in state. "
+ "Should have been %d, was %d.\n",
state, kwsysProcess_GetState(kp));
result = 1;
}
@@ -628,11 +642,16 @@ int main(int argc, const char* argv[])
kwsysProcess_State_Exception /* Process group test */
};
int exceptions[10] = {
- kwsysProcess_Exception_None, kwsysProcess_Exception_None,
- kwsysProcess_Exception_None, kwsysProcess_Exception_Fault,
- kwsysProcess_Exception_None, kwsysProcess_Exception_None,
- kwsysProcess_Exception_None, kwsysProcess_Exception_None,
- kwsysProcess_Exception_None, kwsysProcess_Exception_Interrupt
+ kwsysProcess_Exception_None, kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None,
+#ifdef CRASH_USING_ABORT
+ kwsysProcess_Exception_Other,
+#else
+ kwsysProcess_Exception_Fault,
+#endif
+ kwsysProcess_Exception_None, kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None, kwsysProcess_Exception_None,
+ kwsysProcess_Exception_None, kwsysProcess_Exception_Interrupt
};
int values[10] = { 0, 123, 1, 1, 0, 0, 0, 0, 1, 1 };
int shares[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 };
@@ -687,9 +706,7 @@ int main(int argc, const char* argv[])
fflush(stdout);
fflush(stderr);
#if defined(_WIN32)
- if (argv0) {
- free(argv0);
- }
+ free(argv0);
#endif
return r;
} else if (argc > 2 && strcmp(argv[1], "0") == 0) {
diff --git a/Source/kwsys/testSharedForward.c.in b/Source/kwsys/testSharedForward.c.in
index 9a0c0c061..b3eb41382 100644
--- a/Source/kwsys/testSharedForward.c.in
+++ b/Source/kwsys/testSharedForward.c.in
@@ -1,11 +1,11 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#if defined(CMAKE_INTDIR)
-#define CONFIG_DIR_PRE CMAKE_INTDIR "/"
-#define CONFIG_DIR_POST "/" CMAKE_INTDIR
+# define CONFIG_DIR_PRE CMAKE_INTDIR "/"
+# define CONFIG_DIR_POST "/" CMAKE_INTDIR
#else
-#define CONFIG_DIR_PRE ""
-#define CONFIG_DIR_POST ""
+# 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
@@ -18,7 +18,7 @@
#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
+# define @KWSYS_NAMESPACE@_SHARED_FORWARD_CONFIG_NAME CMAKE_INTDIR
#endif
#include <@KWSYS_NAMESPACE@/SharedForward.h>
int main(int argc, char** argv)
diff --git a/Source/kwsys/testSystemInformation.cxx b/Source/kwsys/testSystemInformation.cxx
index 3a9217f2c..154517eae 100644
--- a/Source/kwsys/testSystemInformation.cxx
+++ b/Source/kwsys/testSystemInformation.cxx
@@ -6,25 +6,25 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "SystemInformation.hxx.in"
+# include "SystemInformation.hxx.in"
#endif
#include <iostream>
#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
+# 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)
+# if defined(KWSYS_IOS_HAS_OSTREAM___INT64)
+# define iostreamLongLong(x) (x)
+# else
+# define iostreamLongLong(x) ((long)x)
+# endif
#else
-#define iostreamLongLong(x) ((long)x)
-#endif
-#else
-#error "No Long Long"
+# error "No Long Long"
#endif
#define printMethod(info, m) std::cout << #m << ": " << info.m() << "\n"
@@ -86,7 +86,7 @@ int testSystemInformation(int, char* [])
}
/* test stack trace
- */
+ */
std::cout << "Program Stack:" << std::endl
<< kwsys::SystemInformation::GetProgramStack(0, 0) << std::endl
<< std::endl;
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index e6fbf6cda..ffa6a297d 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -3,7 +3,7 @@
#include "kwsysPrivate.h"
#if defined(_MSC_VER)
-#pragma warning(disable : 4786)
+# pragma warning(disable : 4786)
#endif
#include KWSYS_HEADER(FStream.hxx)
@@ -12,8 +12,8 @@
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
-#include "FStream.hxx.in"
-#include "SystemTools.hxx.in"
+# include "FStream.hxx.in"
+# include "SystemTools.hxx.in"
#endif
// Include with <> instead of "" to avoid getting any in-source copy
@@ -22,12 +22,13 @@
#include <iostream>
#include <sstream>
+#include <stdlib.h> /* free */
#include <string.h> /* strcmp */
#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <io.h> /* _umask (MSVC) / umask (Borland) */
-#ifdef _MSC_VER
-#define umask _umask // Note this is still umask on Borland
-#endif
+# include <io.h> /* _umask (MSVC) / umask (Borland) */
+# ifdef _MSC_VER
+# define umask _umask // Note this is still umask on Borland
+# endif
#endif
#include <sys/stat.h> /* umask (POSIX), _S_I* constants (Windows) */
// Visual C++ does not define mode_t (note that Borland does, however).
@@ -38,20 +39,20 @@ typedef unsigned short mode_t;
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" },
+ { "/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" },
+ { "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" },
+ { "\\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" },
+ { "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 }
+ { "\\\\usr\\lo\\ cal\\bin\\pa\\ sswd", "//usr/lo/ cal/bin/pa/ sswd" },
+ { KWSYS_NULLPTR, KWSYS_NULLPTR }
};
static bool CheckConvertToUnixSlashes(std::string const& input,
@@ -67,10 +68,11 @@ static bool CheckConvertToUnixSlashes(std::string const& input,
return true;
}
-static const char* checkEscapeChars[][4] = { { "1 foo 2 bar 2", "12", "\\",
- "\\1 foo \\2 bar \\2" },
- { " {} ", "{}", "#", " #{#} " },
- { 0, 0, 0, 0 } };
+static const char* checkEscapeChars[][4] = {
+ { "1 foo 2 bar 2", "12", "\\", "\\1 foo \\2 bar \\2" },
+ { " {} ", "{}", "#", " #{#} " },
+ { KWSYS_NULLPTR, KWSYS_NULLPTR, KWSYS_NULLPTR, KWSYS_NULLPTR }
+};
static bool CheckEscapeChars(std::string const& input,
const char* chars_to_escape, char escape_char,
@@ -158,7 +160,7 @@ static bool CheckFileOperations()
res = false;
}
// calling with 0 pointer should return false
- if (kwsys::SystemTools::MakeDirectory(0)) {
+ if (kwsys::SystemTools::MakeDirectory(KWSYS_NULLPTR)) {
std::cerr << "Problem with MakeDirectory(0)" << std::endl;
res = false;
}
@@ -204,7 +206,7 @@ static bool CheckFileOperations()
res = false;
}
- if (!kwsys::SystemTools::Touch(testNewFile.c_str(), true)) {
+ if (!kwsys::SystemTools::Touch(testNewFile, true)) {
std::cerr << "Problem with Touch for: " << testNewFile << std::endl;
res = false;
}
@@ -216,11 +218,11 @@ static bool CheckFileOperations()
}
// calling with 0 pointer should return false
- if (kwsys::SystemTools::FileExists(0)) {
+ if (kwsys::SystemTools::FileExists(KWSYS_NULLPTR)) {
std::cerr << "Problem with FileExists(0)" << std::endl;
res = false;
}
- if (kwsys::SystemTools::FileExists(0, true)) {
+ if (kwsys::SystemTools::FileExists(KWSYS_NULLPTR, true)) {
std::cerr << "Problem with FileExists(0) as file" << std::endl;
res = false;
}
@@ -253,22 +255,22 @@ static bool CheckFileOperations()
}
// should work, was created as new file before
if (!kwsys::SystemTools::FileExists(testNewFile)) {
- std::cerr << "Problem with FileExists for: " << testNewDir << std::endl;
+ std::cerr << "Problem with FileExists for: " << testNewFile << std::endl;
res = false;
}
if (!kwsys::SystemTools::FileExists(testNewFile.c_str())) {
- std::cerr << "Problem with FileExists as C string for: " << testNewDir
+ std::cerr << "Problem with FileExists as C string for: " << testNewFile
<< std::endl;
res = false;
}
if (!kwsys::SystemTools::FileExists(testNewFile, true)) {
- std::cerr << "Problem with FileExists as file for: " << testNewDir
+ std::cerr << "Problem with FileExists as file for: " << testNewFile
<< std::endl;
res = false;
}
if (!kwsys::SystemTools::FileExists(testNewFile.c_str(), true)) {
std::cerr << "Problem with FileExists as C string and file for: "
- << testNewDir << std::endl;
+ << testNewFile << std::endl;
res = false;
}
@@ -284,7 +286,7 @@ static bool CheckFileOperations()
}
// should work, was created as new file before
if (!kwsys::SystemTools::PathExists(testNewFile)) {
- std::cerr << "Problem with PathExists for: " << testNewDir << std::endl;
+ std::cerr << "Problem with PathExists for: " << testNewFile << std::endl;
res = false;
}
@@ -413,7 +415,7 @@ static bool CheckFileOperations()
res = false;
}
- kwsys::SystemTools::Touch(testNewFile.c_str(), true);
+ kwsys::SystemTools::Touch(testNewFile, true);
if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) {
std::cerr << "Problem with RemoveADirectory for: " << testNewDir
<< std::endl;
@@ -535,15 +537,14 @@ static bool CheckStringOperations()
}
delete[] cres;
- char* cres2 = new char[strlen("Mary Had A Little Lamb.") + 1];
- strcpy(cres2, "Mary Had A Little Lamb.");
+ char* cres2 = strdup("Mary Had A Little Lamb.");
kwsys::SystemTools::ReplaceChars(cres2, "aeiou", 'X');
if (strcmp(cres2, "MXry HXd A LXttlX LXmb.")) {
std::cerr << "Problem with ReplaceChars "
<< "\"Mary Had A Little Lamb.\"" << std::endl;
res = false;
}
- delete[] cres2;
+ free(cres2);
if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
"Mary ")) {
@@ -683,9 +684,10 @@ static bool CheckRelativePaths()
}
static bool CheckCollapsePath(const std::string& path,
- const std::string& expected)
+ const std::string& expected,
+ const char* base = nullptr)
{
- std::string result = kwsys::SystemTools::CollapseFullPath(path);
+ std::string result = kwsys::SystemTools::CollapseFullPath(path, base);
if (!kwsys::SystemTools::ComparePath(expected, result)) {
std::cerr << "CollapseFullPath(" << path << ") yielded " << result
<< " instead of " << expected << std::endl;
@@ -699,6 +701,19 @@ static bool CheckCollapsePath()
bool res = true;
res &= CheckCollapsePath("/usr/share/*", "/usr/share/*");
res &= CheckCollapsePath("C:/Windows/*", "C:/Windows/*");
+ res &= CheckCollapsePath("/usr/share/../lib", "/usr/lib");
+ res &= CheckCollapsePath("/usr/share/./lib", "/usr/share/lib");
+ res &= CheckCollapsePath("/usr/share/../../lib", "/lib");
+ res &= CheckCollapsePath("/usr/share/.././../lib", "/lib");
+ res &= CheckCollapsePath("/../lib", "/lib");
+ res &= CheckCollapsePath("/../lib/", "/lib");
+ res &= CheckCollapsePath("/", "/");
+ res &= CheckCollapsePath("C:/", "C:/");
+ res &= CheckCollapsePath("C:/../", "C:/");
+ res &= CheckCollapsePath("C:/../../", "C:/");
+ res &= CheckCollapsePath("../b", "../../b", "../");
+ res &= CheckCollapsePath("../a/../b", "../b", "../rel");
+ res &= CheckCollapsePath("a/../b", "../rel/b", "../rel");
return res;
}
@@ -727,29 +742,29 @@ static bool CheckGetPath()
#endif
const char* registryPath = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MyApp; MyKey]";
- std::vector<std::string> originalPathes;
- originalPathes.push_back(registryPath);
+ std::vector<std::string> originalPaths;
+ originalPaths.push_back(registryPath);
- std::vector<std::string> expectedPathes;
- expectedPathes.push_back(registryPath);
+ std::vector<std::string> expectedPaths;
+ expectedPaths.push_back(registryPath);
#ifdef _WIN32
- expectedPathes.push_back("C:/Somewhere/something");
- expectedPathes.push_back("D:/Temp");
+ expectedPaths.push_back("C:/Somewhere/something");
+ expectedPaths.push_back("D:/Temp");
#else
- expectedPathes.push_back("/Somewhere/something");
- expectedPathes.push_back("/tmp");
+ expectedPaths.push_back("/Somewhere/something");
+ expectedPaths.push_back("/tmp");
#endif
bool res = true;
res &= CheckPutEnv(std::string(envName) + "=" + envValue, envName, envValue);
- std::vector<std::string> pathes = originalPathes;
- kwsys::SystemTools::GetPath(pathes, envName);
+ std::vector<std::string> paths = originalPaths;
+ kwsys::SystemTools::GetPath(paths, envName);
- if (pathes != expectedPathes) {
- std::cerr << "GetPath(" << StringVectorToString(originalPathes) << ", "
- << envName << ") yielded " << StringVectorToString(pathes)
- << " instead of " << StringVectorToString(expectedPathes)
+ if (paths != expectedPaths) {
+ std::cerr << "GetPath(" << StringVectorToString(originalPaths) << ", "
+ << envName << ") yielded " << StringVectorToString(paths)
+ << " instead of " << StringVectorToString(expectedPaths)
<< std::endl;
res = false;
}
@@ -758,6 +773,36 @@ static bool CheckGetPath()
return res;
}
+static bool CheckGetFilenameName()
+{
+ const char* windowsFilepath = "C:\\somewhere\\something";
+ const char* unixFilepath = "/somewhere/something";
+
+#if defined(_WIN32) || defined(KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES)
+ std::string expectedWindowsFilename = "something";
+#else
+ std::string expectedWindowsFilename = "C:\\somewhere\\something";
+#endif
+ std::string expectedUnixFilename = "something";
+
+ bool res = true;
+ std::string filename = kwsys::SystemTools::GetFilenameName(windowsFilepath);
+ if (filename != expectedWindowsFilename) {
+ std::cerr << "GetFilenameName(" << windowsFilepath << ") yielded "
+ << filename << " instead of " << expectedWindowsFilename
+ << std::endl;
+ res = false;
+ }
+
+ filename = kwsys::SystemTools::GetFilenameName(unixFilepath);
+ if (filename != expectedUnixFilename) {
+ std::cerr << "GetFilenameName(" << unixFilepath << ") yielded " << filename
+ << " instead of " << expectedUnixFilename << std::endl;
+ res = false;
+ }
+ return res;
+}
+
static bool CheckFind()
{
bool res = true;
@@ -765,7 +810,7 @@ static bool CheckFind()
const std::string testFindFile(TEST_SYSTEMTOOLS_BINARY_DIR "/" +
testFindFileName);
- if (!kwsys::SystemTools::Touch(testFindFile.c_str(), true)) {
+ if (!kwsys::SystemTools::Touch(testFindFile, true)) {
std::cerr << "Problem with Touch for: " << testFindFile << std::endl;
// abort here as the existence of the file only makes the test meaningful
return false;
@@ -789,6 +834,39 @@ static bool CheckFind()
return res;
}
+static bool CheckIsSubDirectory()
+{
+ bool res = true;
+
+ if (kwsys::SystemTools::IsSubDirectory("/foo", "/") == false) {
+ std::cerr << "Problem with IsSubDirectory (root - unix): " << std::endl;
+ res = false;
+ }
+ if (kwsys::SystemTools::IsSubDirectory("c:/foo", "c:/") == false) {
+ std::cerr << "Problem with IsSubDirectory (root - dos): " << std::endl;
+ res = false;
+ }
+ if (kwsys::SystemTools::IsSubDirectory("/foo/bar", "/foo") == false) {
+ std::cerr << "Problem with IsSubDirectory (deep): " << std::endl;
+ res = false;
+ }
+ if (kwsys::SystemTools::IsSubDirectory("/foo", "/foo") == true) {
+ std::cerr << "Problem with IsSubDirectory (identity): " << std::endl;
+ res = false;
+ }
+ if (kwsys::SystemTools::IsSubDirectory("/fooo", "/foo") == true) {
+ std::cerr << "Problem with IsSubDirectory (substring): " << std::endl;
+ res = false;
+ }
+ if (kwsys::SystemTools::IsSubDirectory("/foo/", "/foo") == true) {
+ std::cerr << "Problem with IsSubDirectory (prepended slash): "
+ << std::endl;
+ res = false;
+ }
+
+ return res;
+}
+
static bool CheckGetLineFromStream()
{
const std::string fileWithFiveCharsOnFirstLine(TEST_SYSTEMTOOLS_SOURCE_DIR
@@ -838,6 +916,122 @@ static bool CheckGetLineFromStream()
return ret;
}
+static bool CheckGetLineFromStreamLongLine()
+{
+ const std::string fileWithLongLine("longlines.txt");
+ std::string firstLine, secondLine;
+ // First line: large buffer, containing a carriage return for some reason.
+ firstLine.assign(2050, ' ');
+ firstLine += "\rfirst";
+ secondLine.assign(2050, 'y');
+ secondLine += "second";
+
+ // Create file with long lines.
+ {
+ kwsys::ofstream out(fileWithLongLine.c_str(), std::ios::binary);
+ if (!out) {
+ std::cerr << "Problem opening for write: " << fileWithLongLine
+ << std::endl;
+ return false;
+ }
+ out << firstLine << "\r\n\n" << secondLine << "\n";
+ }
+
+ kwsys::ifstream file(fileWithLongLine.c_str(), std::ios::binary);
+ if (!file) {
+ std::cerr << "Problem opening: " << fileWithLongLine << std::endl;
+ return false;
+ }
+
+ std::string line;
+ bool has_newline = false;
+ bool result;
+
+ // Read first line.
+ result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
+ if (!result || line != firstLine) {
+ std::cerr << "First line does not match, expected " << firstLine.size()
+ << " characters, got " << line.size() << std::endl;
+ return false;
+ }
+ if (!has_newline) {
+ std::cerr << "Expected new line to be read from first line" << std::endl;
+ return false;
+ }
+
+ // Read empty line.
+ has_newline = false;
+ result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
+ if (!result || !line.empty()) {
+ std::cerr << "Expected successful read with an empty line, got "
+ << line.size() << " characters" << std::endl;
+ return false;
+ }
+ if (!has_newline) {
+ std::cerr << "Expected new line to be read for an empty line" << std::endl;
+ return false;
+ }
+
+ // Read second line.
+ has_newline = false;
+ result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
+ if (!result || line != secondLine) {
+ std::cerr << "Second line does not match, expected " << secondLine.size()
+ << " characters, got " << line.size() << std::endl;
+ return false;
+ }
+ if (!has_newline) {
+ std::cerr << "Expected new line to be read from second line" << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+static bool writeFile(const char* fileName, const char* data)
+{
+ kwsys::ofstream out(fileName, std::ios::binary);
+ out << data;
+ if (!out) {
+ std::cerr << "Failed to write file: " << fileName << std::endl;
+ return false;
+ }
+ return true;
+}
+
+static bool CheckTextFilesDiffer()
+{
+ struct
+ {
+ const char* a;
+ const char* b;
+ bool differ;
+ } test_cases[] = { { "one", "one", false },
+ { "one", "two", true },
+ { "", "", false },
+ { "\n", "\r\n", false },
+ { "one\n", "one\n", false },
+ { "one\r\n", "one\n", false },
+ { "one\n", "one", false },
+ { "one\ntwo", "one\ntwo", false },
+ { "one\ntwo", "one\r\ntwo", false } };
+ const int num_test_cases = sizeof(test_cases) / sizeof(test_cases[0]);
+ for (int i = 0; i < num_test_cases; ++i) {
+ if (!writeFile("file_a", test_cases[i].a) ||
+ !writeFile("file_b", test_cases[i].b)) {
+ return false;
+ }
+ if (kwsys::SystemTools::TextFilesDiffer("file_a", "file_b") !=
+ test_cases[i].differ) {
+ std::cerr << "Incorrect TextFilesDiffer result for test case " << i + 1
+ << "." << std::endl;
+ return false;
+ }
+ }
+
+ return true;
+}
+
int testSystemTools(int, char* [])
{
bool res = true;
@@ -873,7 +1067,15 @@ int testSystemTools(int, char* [])
res &= CheckFind();
+ res &= CheckIsSubDirectory();
+
res &= CheckGetLineFromStream();
+ res &= CheckGetLineFromStreamLongLine();
+
+ res &= CheckGetFilenameName();
+
+ res &= CheckTextFilesDiffer();
+
return res ? 0 : 1;
}
diff --git a/Source/kwsys/testTerminal.c b/Source/kwsys/testTerminal.c
index f6c1eddb7..652830ccd 100644
--- a/Source/kwsys/testTerminal.c
+++ b/Source/kwsys/testTerminal.c
@@ -6,7 +6,7 @@
/* Work-around CMake dependency scanning limitation. This must
duplicate the above list of headers. */
#if 0
-#include "Terminal.h.in"
+# include "Terminal.h.in"
#endif
int testTerminal(int argc, char* argv[])
diff --git a/Templates/MSBuild/nasm.xml b/Templates/MSBuild/nasm.xml
index 92f8548c3..a5dcdd5e2 100644
--- a/Templates/MSBuild/nasm.xml
+++ b/Templates/MSBuild/nasm.xml
@@ -36,7 +36,7 @@
<DataSource Persistence="ProjectFile" ItemType="NASM" SourceType="Item"/>
</StringProperty.DataSource>
</StringProperty>
- <StringProperty Name="OutputFormat" Category="Assembler Options" HelpUrl="http://www.nasm.us/doc/" DisplayName="Output File Name" Description="Specify Output Filename.-o [value]" Switch="-o [value]"/>
+ <StringProperty Name="OutputFormat" Category="Assembler Options" HelpUrl="http://www.nasm.us/doc/" DisplayName="Output File Name" Description="Specify Output Filename.-o [value]" Switch="-o &quot;[value]&quot;"/>
<BoolProperty Name="tasmmode" Category="Advanced" HelpUrl="http://www.nasm.us/doc/" DisplayName="SciTech TASM compatible mode" Description="assemble in SciTech TASM compatible mode" Switch="-t"/>
<EnumProperty Name="Outputswitch" Category="Assembler Options" HelpUrl="http://www.nasm.us/doc/" DisplayName="Output Switch" Description="Select the type of output format required. Linking Should be disabled for ELF and Binary ,else error will popup">
<EnumValue Name="0" DisplayName="Object File win32" Switch="-fwin32"/>
@@ -48,8 +48,8 @@
<BoolProperty Name="GenerateDebugInformation" Category="Assembler Options" DisplayName="Generate Debug Information" Description="Generates Debug Information. (-g)" HelpUrl="http://www.nasm.us/doc/" Switch="-g"/>
<StringListProperty Name="ErrorReporting" Category="Advanced" HelpUrl="http://www.nasm.us/doc/" DisplayName="Redirect Error Messages to File" Description="Drops the error Message on specified device" Switch="-Z &quot;[value]&quot;"/>
<StringListProperty Name="IncludePaths" Category="General" DisplayName="Include Paths" Description="Sets path for include file. (-I[path])" HelpUrl="http://www.nasm.us/doc/" Switch="-I&quot;[value]&quot;"/>
- <StringListProperty Name="PreprocessorDefinitions" Category="Preprocessor" HelpUrl="http://www.nasm.us/doc/" DisplayName="Preprocessor Definitions" Description="Defines a text macro with the given name. (-D[symbol])" Switch="-D[value]"/>
- <StringListProperty Name="UndefinePreprocessorDefinitions" Category="Preprocessor" HelpUrl="http://www.nasm.us/doc/" DisplayName="Undefine Preprocessor Definitions" Description="Undefines a text macro with the given name. (-U[symbol])" Switch="-U[value]"/>
+ <StringListProperty Name="PreprocessorDefinitions" Category="Preprocessor" HelpUrl="http://www.nasm.us/doc/" DisplayName="Preprocessor Definitions" Description="Defines a text macro with the given name. (-D[symbol])" Switch="-D&quot;[value]&quot;"/>
+ <StringListProperty Name="UndefinePreprocessorDefinitions" Category="Preprocessor" HelpUrl="http://www.nasm.us/doc/" DisplayName="Undefine Preprocessor Definitions" Description="Undefines a text macro with the given name. (-U[symbol])" Switch="-U&quot;[value]&quot;"/>
<EnumProperty Name="ErrorReportingFormat" Category="Advanced" HelpUrl="http://www.nasm.us/doc/" DisplayName="Error Reporting Format" Description="Select the error reporting format ie. GNU or VC">
<EnumValue Name="0" DisplayName="-Xgnu GNU format: Default format" Switch="-Xgnu"/>
<EnumValue Name="1" DisplayName="-Xvc Style used by Microsoft Visual C++" Switch="-Xvc"/>
diff --git a/Templates/TestDriver.cxx.in b/Templates/TestDriver.cxx.in
index bf61be4c9..c58ef714f 100644
--- a/Templates/TestDriver.cxx.in
+++ b/Templates/TestDriver.cxx.in
@@ -20,8 +20,8 @@
/* Create map. */
-typedef int (*MainFuncPointer)(int, char* []);
-typedef struct
+typedef int (*MainFuncPointer)(int, char* []); /* NOLINT */
+typedef struct /* NOLINT */
{
const char* name;
MainFuncPointer func;
@@ -48,7 +48,7 @@ static char* lowercase(const char* string)
if (new_string == NULL) { /* NOLINT */
return NULL; /* NOLINT */
}
- strncpy(new_string, string, stringSize);
+ strcpy(new_string, string);
for (p = new_string; *p != 0; ++p) {
*p = CM_CAST(char, tolower(*p));
}
@@ -58,7 +58,7 @@ static char* lowercase(const char* string)
int main(int ac, char* av[])
{
int i, testNum = 0, partial_match;
- char *arg, *test_name;
+ char *arg;
int testToRun = -1;
@CMAKE_TESTDRIVER_ARGVC_FUNCTION@
@@ -99,7 +99,7 @@ int main(int ac, char* av[])
arg = lowercase(av[1 + partial_match]);
}
for (i = 0; i < NumTests && testToRun == -1; ++i) {
- test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
+ char *test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);
if (partial_match != 0 && strstr(test_name, arg) != NULL) { /* NOLINT */
testToRun = i;
ac -= 2;
diff --git a/Templates/Windows/ApplicationIcon.png b/Templates/Windows/ApplicationIcon.png
index 7d95d4e08..c715e1bc7 100644
--- a/Templates/Windows/ApplicationIcon.png
+++ b/Templates/Windows/ApplicationIcon.png
Binary files differ
diff --git a/Templates/Windows/Logo.png b/Templates/Windows/Logo.png
index e26771cb3..65f91ac0f 100644
--- a/Templates/Windows/Logo.png
+++ b/Templates/Windows/Logo.png
Binary files differ
diff --git a/Templates/Windows/SmallLogo.png b/Templates/Windows/SmallLogo.png
index 1eb0d9d52..460c0222d 100644
--- a/Templates/Windows/SmallLogo.png
+++ b/Templates/Windows/SmallLogo.png
Binary files differ
diff --git a/Templates/Windows/SmallLogo44x44.png b/Templates/Windows/SmallLogo44x44.png
index 28810b7c0..c2374581a 100644
--- a/Templates/Windows/SmallLogo44x44.png
+++ b/Templates/Windows/SmallLogo44x44.png
Binary files differ
diff --git a/Templates/Windows/SplashScreen.png b/Templates/Windows/SplashScreen.png
index c951e031b..834256580 100644
--- a/Templates/Windows/SplashScreen.png
+++ b/Templates/Windows/SplashScreen.png
Binary files differ
diff --git a/Templates/Windows/StoreLogo.png b/Templates/Windows/StoreLogo.png
index dcb672712..508c8a809 100644
--- a/Templates/Windows/StoreLogo.png
+++ b/Templates/Windows/StoreLogo.png
Binary files differ
diff --git a/Tests/AliasTarget/CMakeLists.txt b/Tests/AliasTarget/CMakeLists.txt
index e156420db..fc7013598 100644
--- a/Tests/AliasTarget/CMakeLists.txt
+++ b/Tests/AliasTarget/CMakeLists.txt
@@ -4,13 +4,6 @@ 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")
- string(APPEND CMAKE_CXX_FLAGS " -AA")
-endif ()
-
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
diff --git a/Tests/AliasTarget/bat.cpp b/Tests/AliasTarget/bat.cpp
index cb76bfe2f..14942bf1c 100644
--- a/Tests/AliasTarget/bat.cpp
+++ b/Tests/AliasTarget/bat.cpp
@@ -1,22 +1,22 @@
#ifndef FOO_DEFINE
-#error Expected FOO_DEFINE
+# error Expected FOO_DEFINE
#endif
#ifndef BAR_DEFINE
-#error Expected Bar_DEFINE
+# error Expected Bar_DEFINE
#endif
#include "commandoutput.h"
#ifndef COMMANDOUTPUT_DEFINE
-#error Expected COMMANDOUTPUT_DEFINE
+# error Expected COMMANDOUTPUT_DEFINE
#endif
#include "targetoutput.h"
#ifndef TARGETOUTPUT_DEFINE
-#error Expected TARGETOUTPUT_DEFINE
+# error Expected TARGETOUTPUT_DEFINE
#endif
#ifdef _WIN32
diff --git a/Tests/BuildDepends/CMakeLists.txt b/Tests/BuildDepends/CMakeLists.txt
index 11978dbf8..39a5131fe 100644
--- a/Tests/BuildDepends/CMakeLists.txt
+++ b/Tests/BuildDepends/CMakeLists.txt
@@ -42,7 +42,7 @@ list(APPEND _cmake_options "-DTEST_LINK_DEPENDS=${TEST_LINK_DEPENDS}")
list(APPEND _cmake_options "-DCMAKE_FORCE_DEPFILES=1")
-if(NOT CMAKE_GENERATOR MATCHES "Visual Studio ([^89]|[89][0-9])")
+if(NOT CMAKE_GENERATOR MATCHES "Visual Studio ([^9]|9[0-9])")
set(TEST_MULTI3 1)
list(APPEND _cmake_options "-DTEST_MULTI3=1")
endif()
@@ -345,6 +345,17 @@ is not newer than dependency
${TEST_LINK_DEPENDS}
")
endif()
+
+ set(linkdep2 ${BuildDepends_BINARY_DIR}/Project/linkdep2${CMAKE_EXECUTABLE_SUFFIX})
+ if(${linkdep2} IS_NEWER_THAN ${TEST_LINK_DEPENDS})
+ message("INTERFACE_LINK_DEPENDS worked")
+ else()
+ message(SEND_ERROR "INTERFACE_LINK_DEPENDS failed. Executable
+ ${linkdep2}
+is not newer than dependency
+ ${TEST_LINK_DEPENDS}
+")
+ endif()
endif()
if(EXISTS "${link_depends_no_shared_check_txt}")
diff --git a/Tests/BuildDepends/Project/CMakeLists.txt b/Tests/BuildDepends/Project/CMakeLists.txt
index 3aa57fc9e..3f41b26d0 100644
--- a/Tests/BuildDepends/Project/CMakeLists.txt
+++ b/Tests/BuildDepends/Project/CMakeLists.txt
@@ -1,30 +1,30 @@
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(APPLE)
+ set(CMake_TEST_XCODE_VERSION 0)
+ if(XCODE_VERSION)
+ set(CMake_TEST_XCODE_VERSION "${XCODE_VERSION}")
+ else()
+ execute_process(
+ COMMAND xcodebuild -version
+ OUTPUT_VARIABLE _version ERROR_VARIABLE _version
)
- 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()
+ if(_version MATCHES "^Xcode ([0-9]+(\\.[0-9]+)*)")
+ set(CMake_TEST_XCODE_VERSION "${CMAKE_MATCH_1}")
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
+ if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 10)
+ # Arch 'i386' no longer works in Xcode 10.
+ set(CMAKE_OSX_ARCHITECTURES x86_64)
+ elseif(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 4)
+ # Arch 'ppc' no longer works in Xcode 4.
set(CMAKE_OSX_ARCHITECTURES i386 x86_64)
+ else()
+ set(CMAKE_OSX_ARCHITECTURES ppc i386)
endif()
endif()
endif()
@@ -106,7 +106,12 @@ set_property(
if(TEST_LINK_DEPENDS)
add_executable(linkdep linkdep.cxx)
- set_property(TARGET linkdep PROPERTY LINK_DEPENDS ${TEST_LINK_DEPENDS})
+ set_property(TARGET linkdep PROPERTY LINK_DEPENDS $<1:${TEST_LINK_DEPENDS}>)
+
+ add_library(foo_interface INTERFACE)
+ set_property(TARGET foo_interface PROPERTY INTERFACE_LINK_DEPENDS $<1:${TEST_LINK_DEPENDS}>)
+ add_executable(linkdep2 linkdep.cxx)
+ target_link_libraries(linkdep2 PRIVATE foo_interface)
endif()
add_library(link_depends_no_shared_lib SHARED link_depends_no_shared_lib.c
diff --git a/Tests/BundleTest/BundleLib.cxx b/Tests/BundleTest/BundleLib.cxx
index 9ae802f5b..2e4325cf9 100644
--- a/Tests/BundleTest/BundleLib.cxx
+++ b/Tests/BundleTest/BundleLib.cxx
@@ -8,7 +8,7 @@
int fileExists(char* filename)
{
#ifndef R_OK
-#define R_OK 04
+# define R_OK 04
#endif
if (access(filename, R_OK) != 0) {
printf("Cannot find file: %s\n", filename);
diff --git a/Tests/BundleTest/BundleSubDir/CMakeLists.txt b/Tests/BundleTest/BundleSubDir/CMakeLists.txt
index 43c366a09..2f7f2c44b 100644
--- a/Tests/BundleTest/BundleSubDir/CMakeLists.txt
+++ b/Tests/BundleTest/BundleSubDir/CMakeLists.txt
@@ -1,3 +1,5 @@
+project(BundleSubDir)
+
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist"
COMMAND /bin/cp
@@ -34,3 +36,8 @@ install(TARGETS SecondBundle DESTINATION Applications)
# 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)
+
+# Express one app bundle in terms of another's SOURCES to verify that
+# the generators do not expose the Info.plist of one to the other.
+add_executable(SubdirBundle1 MACOSX_BUNDLE EXCLUDE_FROM_ALL ../BundleTest.cxx)
+add_executable(SubdirBundle2 MACOSX_BUNDLE EXCLUDE_FROM_ALL $<TARGET_PROPERTY:SubdirBundle1,SOURCES>)
diff --git a/Tests/BundleUtilities/framework.h b/Tests/BundleUtilities/framework.h
index 343317c59..5a3cfc457 100644
--- a/Tests/BundleUtilities/framework.h
+++ b/Tests/BundleUtilities/framework.h
@@ -3,13 +3,13 @@
#define framework_h
#ifdef WIN32
-#ifdef framework_EXPORTS
-#define FRAMEWORK_EXPORT __declspec(dllexport)
+# ifdef framework_EXPORTS
+# define FRAMEWORK_EXPORT __declspec(dllexport)
+# else
+# define FRAMEWORK_EXPORT __declspec(dllimport)
+# endif
#else
-#define FRAMEWORK_EXPORT __declspec(dllimport)
-#endif
-#else
-#define FRAMEWORK_EXPORT
+# define FRAMEWORK_EXPORT
#endif
void FRAMEWORK_EXPORT framework();
diff --git a/Tests/BundleUtilities/shared.h b/Tests/BundleUtilities/shared.h
index 28904fd78..5d5b6335c 100644
--- a/Tests/BundleUtilities/shared.h
+++ b/Tests/BundleUtilities/shared.h
@@ -3,13 +3,13 @@
#define shared_h
#ifdef WIN32
-#ifdef shared_EXPORTS
-#define SHARED_EXPORT __declspec(dllexport)
+# ifdef shared_EXPORTS
+# define SHARED_EXPORT __declspec(dllexport)
+# else
+# define SHARED_EXPORT __declspec(dllimport)
+# endif
#else
-#define SHARED_EXPORT __declspec(dllimport)
-#endif
-#else
-#define SHARED_EXPORT
+# define SHARED_EXPORT
#endif
void SHARED_EXPORT shared();
diff --git a/Tests/BundleUtilities/shared2.h b/Tests/BundleUtilities/shared2.h
index 3f0015c80..3f016c8f0 100644
--- a/Tests/BundleUtilities/shared2.h
+++ b/Tests/BundleUtilities/shared2.h
@@ -3,13 +3,13 @@
#define shared2_h
#ifdef WIN32
-#ifdef shared2_EXPORTS
-#define SHARED2_EXPORT __declspec(dllexport)
+# ifdef shared2_EXPORTS
+# define SHARED2_EXPORT __declspec(dllexport)
+# else
+# define SHARED2_EXPORT __declspec(dllimport)
+# endif
#else
-#define SHARED2_EXPORT __declspec(dllimport)
-#endif
-#else
-#define SHARED2_EXPORT
+# define SHARED2_EXPORT
#endif
void SHARED2_EXPORT shared2();
diff --git a/Tests/BundleUtilities/testbundleutils1.cpp b/Tests/BundleUtilities/testbundleutils1.cpp
index 3eb6a44bf..080157ac2 100644
--- a/Tests/BundleUtilities/testbundleutils1.cpp
+++ b/Tests/BundleUtilities/testbundleutils1.cpp
@@ -4,9 +4,9 @@
#include "stdio.h"
#if defined(WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include "dlfcn.h"
+# include "dlfcn.h"
#endif
int main(int, char**)
diff --git a/Tests/BundleUtilities/testbundleutils2.cpp b/Tests/BundleUtilities/testbundleutils2.cpp
index c39eb52c5..e747544db 100644
--- a/Tests/BundleUtilities/testbundleutils2.cpp
+++ b/Tests/BundleUtilities/testbundleutils2.cpp
@@ -4,9 +4,9 @@
#include "stdio.h"
#if defined(WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include "dlfcn.h"
+# include "dlfcn.h"
#endif
int main(int, char**)
diff --git a/Tests/BundleUtilities/testbundleutils3.cpp b/Tests/BundleUtilities/testbundleutils3.cpp
index 3bc8a83ec..2dee46fe5 100644
--- a/Tests/BundleUtilities/testbundleutils3.cpp
+++ b/Tests/BundleUtilities/testbundleutils3.cpp
@@ -4,9 +4,9 @@
#include "stdio.h"
#if defined(WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include "dlfcn.h"
+# include "dlfcn.h"
#endif
int main(int, char**)
diff --git a/Tests/CFBundleTest/np_macmain.cpp b/Tests/CFBundleTest/np_macmain.cpp
index b5a422687..e5fd0d773 100644
--- a/Tests/CFBundleTest/np_macmain.cpp
+++ b/Tests/CFBundleTest/np_macmain.cpp
@@ -4,7 +4,7 @@
Based on the default np_macmain.cpp from FireBreath
http://firebreath.googlecode.com
- This file has been stripped to prevent it from accidently
+ This file has been stripped to prevent it from accidentally
doing anything useful.
\***********************************************************/
diff --git a/Tests/CMakeBuildTest.cmake.in b/Tests/CMakeBuildTest.cmake.in
index 71bcb183e..b4b12863d 100644
--- a/Tests/CMakeBuildTest.cmake.in
+++ b/Tests/CMakeBuildTest.cmake.in
@@ -29,11 +29,10 @@ 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)
+# run the executable out of the Debug directory if using a
+# multi-config generator
+set(_isMultiConfig @_isMultiConfig@)
+if(_isMultiConfig)
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@")
diff --git a/Tests/CMakeCommands/add_compile_options/main.cpp b/Tests/CMakeCommands/add_compile_options/main.cpp
index 1d5702165..53f54b771 100644
--- a/Tests/CMakeCommands/add_compile_options/main.cpp
+++ b/Tests/CMakeCommands/add_compile_options/main.cpp
@@ -1,8 +1,8 @@
#ifdef DO_GNU_TESTS
-#ifndef TEST_OPTION
-#error Expected TEST_OPTION
-#endif
+# ifndef TEST_OPTION
+# error Expected TEST_OPTION
+# endif
#endif
int main(void)
diff --git a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
index f96283d55..a5bc1e1b3 100644
--- a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt
@@ -26,18 +26,19 @@ target_compile_definitions(consumer
PRIVATE
)
-if (CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja")
- target_sources(consumer PRIVATE
- "${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
- )
- target_compile_definitions(consumer
- PRIVATE
- CONSUMER_LANG_$<COMPILE_LANGUAGE>
- LANG_IS_CXX=$<COMPILE_LANGUAGE:CXX>
- LANG_IS_C=$<COMPILE_LANGUAGE:C>
- )
+target_sources(consumer PRIVATE
+ "${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
+)
+target_compile_definitions(consumer
+ PRIVATE
+ CONSUMER_LANG_$<COMPILE_LANGUAGE>
+ LANG_IS_CXX=$<COMPILE_LANGUAGE:CXX>
+ LANG_IS_C=$<COMPILE_LANGUAGE:C>
+ LANG_IS_C_OR_CXX=$<COMPILE_LANGUAGE:C,CXX>
+)
+if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
target_compile_definitions(consumer
- PRIVATE -DTEST_LANG_DEFINES
+ PRIVATE TEST_LANG_DEFINES_FOR_VISUAL_STUDIO_OR_XCODE
)
endif()
diff --git a/Tests/CMakeCommands/target_compile_definitions/consumer.c b/Tests/CMakeCommands/target_compile_definitions/consumer.c
index 7931a6f0e..bb65e011b 100644
--- a/Tests/CMakeCommands/target_compile_definitions/consumer.c
+++ b/Tests/CMakeCommands/target_compile_definitions/consumer.c
@@ -1,20 +1,42 @@
-#ifdef TEST_LANG_DEFINES
-#ifdef CONSUMER_LANG_CXX
-#error Unexpected CONSUMER_LANG_CXX
-#endif
+// Visual Studio allows only one set of flags for C and C++.
+// In a target using C++ we pick the C++ flags even for C sources.
+#ifdef TEST_LANG_DEFINES_FOR_VISUAL_STUDIO_OR_XCODE
+# ifndef CONSUMER_LANG_CXX
+# error Expected CONSUMER_LANG_CXX
+# endif
-#ifndef CONSUMER_LANG_C
-#error Expected CONSUMER_LANG_C
-#endif
+# ifdef CONSUMER_LANG_C
+# error Unexpected CONSUMER_LANG_C
+# endif
-#if !LANG_IS_C
-#error Expected LANG_IS_C
-#endif
+# if !LANG_IS_CXX
+# error Expected LANG_IS_CXX
+# endif
+
+# if LANG_IS_C
+# error Unexpected LANG_IS_C
+# endif
+#else
+# ifdef CONSUMER_LANG_CXX
+# error Unexpected CONSUMER_LANG_CXX
+# endif
-#if LANG_IS_CXX
-#error Unexpected LANG_IS_CXX
+# ifndef CONSUMER_LANG_C
+# error Expected CONSUMER_LANG_C
+# endif
+
+# if !LANG_IS_C
+# error Expected LANG_IS_C
+# endif
+
+# if LANG_IS_CXX
+# error Unexpected LANG_IS_CXX
+# endif
#endif
+
+#if !LANG_IS_C_OR_CXX
+# error Expected LANG_IS_C_OR_CXX
#endif
void consumer_c()
diff --git a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp
index 0202c172e..099952666 100644
--- a/Tests/CMakeCommands/target_compile_definitions/consumer.cpp
+++ b/Tests/CMakeCommands/target_compile_definitions/consumer.cpp
@@ -1,36 +1,34 @@
#ifdef MY_PRIVATE_DEFINE
-#error Unexpected MY_PRIVATE_DEFINE
+# error Unexpected MY_PRIVATE_DEFINE
#endif
#ifndef MY_PUBLIC_DEFINE
-#error Expected MY_PUBLIC_DEFINE
+# error Expected MY_PUBLIC_DEFINE
#endif
#ifndef MY_INTERFACE_DEFINE
-#error Expected MY_INTERFACE_DEFINE
+# error Expected MY_INTERFACE_DEFINE
#endif
#ifndef DASH_D_DEFINE
-#error Expected DASH_D_DEFINE
+# error Expected DASH_D_DEFINE
#endif
-#ifdef TEST_LANG_DEFINES
#ifndef CONSUMER_LANG_CXX
-#error Expected CONSUMER_LANG_CXX
+# error Expected CONSUMER_LANG_CXX
#endif
#ifdef CONSUMER_LANG_C
-#error Unexpected CONSUMER_LANG_C
+# error Unexpected CONSUMER_LANG_C
#endif
#if !LANG_IS_CXX
-#error Expected LANG_IS_CXX
+# error Expected LANG_IS_CXX
#endif
#if LANG_IS_C
-#error Unexpected LANG_IS_C
-#endif
+# error Unexpected LANG_IS_C
#endif
int main()
diff --git a/Tests/CMakeCommands/target_compile_definitions/main.cpp b/Tests/CMakeCommands/target_compile_definitions/main.cpp
index bf08b45e3..3f64dc843 100644
--- a/Tests/CMakeCommands/target_compile_definitions/main.cpp
+++ b/Tests/CMakeCommands/target_compile_definitions/main.cpp
@@ -1,14 +1,14 @@
#ifndef MY_PRIVATE_DEFINE
-#error Expected MY_PRIVATE_DEFINE
+# error Expected MY_PRIVATE_DEFINE
#endif
#ifndef MY_PUBLIC_DEFINE
-#error Expected MY_PUBLIC_DEFINE
+# error Expected MY_PUBLIC_DEFINE
#endif
#ifdef MY_INTERFACE_DEFINE
-#error Unexpected MY_INTERFACE_DEFINE
+# error Unexpected MY_INTERFACE_DEFINE
#endif
int main()
diff --git a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
index 5096a58bf..9664025a4 100644
--- a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
@@ -1,5 +1,4 @@
-cmake_minimum_required(VERSION 3.0)
-cmake_policy(SET CMP0057 NEW)
+cmake_minimum_required(VERSION 3.3)
project(target_compile_features)
set(CMAKE_VERBOSE_MAKEFILE ON)
@@ -19,7 +18,8 @@ if (c_restrict IN_LIST CMAKE_C_COMPILE_FEATURES)
target_link_libraries(c_restrict_user_specific c_lib_restrict_specific)
endif()
-if (c_std_99 IN_LIST CMAKE_C_COMPILE_FEATURES)
+if (c_std_99 IN_LIST CMAKE_C_COMPILE_FEATURES AND
+ NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
add_executable(c_target_compile_features_meta main.c)
target_compile_features(c_target_compile_features_meta
PRIVATE c_std_99
diff --git a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt
index 35dd276ba..a7055b157 100644
--- a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt
@@ -7,9 +7,11 @@ 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>
+ PRIVATE $<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-DMY_PRIVATE_DEFINE>
+ PUBLIC $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-DMY_PUBLIC_DEFINE>
+ PUBLIC $<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-DMY_MUTLI_COMP_PUBLIC_DEFINE>
INTERFACE $<$<CXX_COMPILER_ID:GNU>:-DMY_INTERFACE_DEFINE>
+ INTERFACE $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-DMY_MULTI_COMP_INTERFACE_DEFINE>
)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
@@ -17,29 +19,35 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
PRIVATE
"DO_GNU_TESTS"
)
+elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ target_compile_definitions(target_compile_options
+ PRIVATE
+ "DO_CLANG_TESTS"
+ )
endif()
add_executable(consumer
"${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
)
-if (NOT CMAKE_GENERATOR MATCHES "Visual Studio")
- target_sources(consumer PRIVATE
- "${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
- )
- target_compile_options(consumer
- PRIVATE
- -DCONSUMER_LANG_$<COMPILE_LANGUAGE>
- -DLANG_IS_CXX=$<COMPILE_LANGUAGE:CXX>
- -DLANG_IS_C=$<COMPILE_LANGUAGE:C>
- )
+target_sources(consumer PRIVATE
+ "${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
+)
+target_compile_options(consumer
+ PRIVATE
+ -DCONSUMER_LANG_$<COMPILE_LANGUAGE>
+ -DLANG_IS_CXX=$<COMPILE_LANGUAGE:CXX>
+ -DLANG_IS_C=$<COMPILE_LANGUAGE:C>
+)
+
+if(CMAKE_GENERATOR MATCHES "Visual Studio")
target_compile_definitions(consumer
- PRIVATE -DTEST_LANG_DEFINES
+ PRIVATE TEST_LANG_DEFINES_FOR_VISUAL_STUDIO
)
endif()
target_compile_options(consumer
- PRIVATE $<$<CXX_COMPILER_ID:GNU>:$<TARGET_PROPERTY:target_compile_options,INTERFACE_COMPILE_OPTIONS>>
+ PRIVATE $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:$<TARGET_PROPERTY:target_compile_options,INTERFACE_COMPILE_OPTIONS>>
)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
@@ -47,6 +55,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
PRIVATE
"DO_GNU_TESTS"
)
+elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ target_compile_definitions(consumer
+ PRIVATE
+ "DO_CLANG_TESTS"
+ )
endif()
# Test no items
diff --git a/Tests/CMakeCommands/target_compile_options/consumer.c b/Tests/CMakeCommands/target_compile_options/consumer.c
index 7931a6f0e..f9b66543a 100644
--- a/Tests/CMakeCommands/target_compile_options/consumer.c
+++ b/Tests/CMakeCommands/target_compile_options/consumer.c
@@ -1,20 +1,38 @@
-#ifdef TEST_LANG_DEFINES
-#ifdef CONSUMER_LANG_CXX
-#error Unexpected CONSUMER_LANG_CXX
-#endif
+// Visual Studio allows only one set of flags for C and C++.
+// In a target using C++ we pick the C++ flags even for C sources.
+#ifdef TEST_LANG_DEFINES_FOR_VISUAL_STUDIO
+# ifndef CONSUMER_LANG_CXX
+# error Expected CONSUMER_LANG_CXX
+# endif
-#ifndef CONSUMER_LANG_C
-#error Expected CONSUMER_LANG_C
-#endif
+# ifdef CONSUMER_LANG_C
+# error Unexpected CONSUMER_LANG_C
+# endif
-#if !LANG_IS_C
-#error Expected LANG_IS_C
-#endif
+# if !LANG_IS_CXX
+# error Expected LANG_IS_CXX
+# endif
-#if LANG_IS_CXX
-#error Unexpected LANG_IS_CXX
-#endif
+# if LANG_IS_C
+# error Unexpected LANG_IS_C
+# endif
+#else
+# ifdef CONSUMER_LANG_CXX
+# error Unexpected CONSUMER_LANG_CXX
+# endif
+
+# ifndef CONSUMER_LANG_C
+# error Expected CONSUMER_LANG_C
+# endif
+
+# if !LANG_IS_C
+# error Expected LANG_IS_C
+# endif
+
+# if LANG_IS_CXX
+# error Unexpected LANG_IS_CXX
+# endif
#endif
void consumer_c()
diff --git a/Tests/CMakeCommands/target_compile_options/consumer.cpp b/Tests/CMakeCommands/target_compile_options/consumer.cpp
index 71a60986a..78928b42e 100644
--- a/Tests/CMakeCommands/target_compile_options/consumer.cpp
+++ b/Tests/CMakeCommands/target_compile_options/consumer.cpp
@@ -1,36 +1,58 @@
#ifdef DO_GNU_TESTS
-#ifdef MY_PRIVATE_DEFINE
-#error Unexpected MY_PRIVATE_DEFINE
-#endif
+# ifdef MY_PRIVATE_DEFINE
+# error Unexpected MY_PRIVATE_DEFINE
+# endif
-#ifndef MY_PUBLIC_DEFINE
-#error Expected MY_PUBLIC_DEFINE
-#endif
+# ifndef MY_PUBLIC_DEFINE
+# error Expected MY_PUBLIC_DEFINE
+# endif
+
+# ifndef MY_INTERFACE_DEFINE
+# error Expected MY_INTERFACE_DEFINE
+# endif
+
+# ifndef MY_MULTI_COMP_INTERFACE_DEFINE
+# error Expected MY_MULTI_COMP_INTERFACE_DEFINE
+# endif
+
+# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE
+# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE
+# endif
-#ifndef MY_INTERFACE_DEFINE
-#error Expected MY_INTERFACE_DEFINE
#endif
+#ifdef DO_CLANG_TESTS
+
+# ifdef MY_PRIVATE_DEFINE
+# error Unexpected MY_PRIVATE_DEFINE
+# endif
+
+# ifndef MY_MULTI_COMP_INTERFACE_DEFINE
+# error Expected MY_MULTI_COMP_INTERFACE_DEFINE
+# endif
+
+# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE
+# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE
+# endif
+
#endif
-#ifdef TEST_LANG_DEFINES
#ifndef CONSUMER_LANG_CXX
-#error Expected CONSUMER_LANG_CXX
+# error Expected CONSUMER_LANG_CXX
#endif
#ifdef CONSUMER_LANG_C
-#error Unexpected CONSUMER_LANG_C
+# error Unexpected CONSUMER_LANG_C
#endif
#if !LANG_IS_CXX
-#error Expected LANG_IS_CXX
+# error Expected LANG_IS_CXX
#endif
#if LANG_IS_C
-#error Unexpected LANG_IS_C
-#endif
+# error Unexpected LANG_IS_C
#endif
int main()
diff --git a/Tests/CMakeCommands/target_compile_options/main.cpp b/Tests/CMakeCommands/target_compile_options/main.cpp
index ac472aeda..7608400c4 100644
--- a/Tests/CMakeCommands/target_compile_options/main.cpp
+++ b/Tests/CMakeCommands/target_compile_options/main.cpp
@@ -1,18 +1,38 @@
#ifdef DO_GNU_TESTS
-#ifndef MY_PRIVATE_DEFINE
-#error Expected MY_PRIVATE_DEFINE
-#endif
+# ifndef MY_PRIVATE_DEFINE
+# error Expected MY_PRIVATE_DEFINE
+# endif
-#ifndef MY_PUBLIC_DEFINE
-#error Expected MY_PUBLIC_DEFINE
-#endif
+# ifndef MY_PUBLIC_DEFINE
+# error Expected MY_PUBLIC_DEFINE
+# endif
+
+# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE
+# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE
+# endif
+
+# ifdef MY_INTERFACE_DEFINE
+# error Unexpected MY_INTERFACE_DEFINE
+# endif
-#ifdef MY_INTERFACE_DEFINE
-#error Unexpected MY_INTERFACE_DEFINE
#endif
+#ifdef DO_CLANG_TESTS
+
+# ifndef MY_PRIVATE_DEFINE
+# error Expected MY_PRIVATE_DEFINE
+# endif
+
+# ifdef MY_PUBLIC_DEFINE
+# error Unexpected MY_PUBLIC_DEFINE
+# endif
+
+# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE
+# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE
+# endif
+
#endif
int main()
diff --git a/Tests/CMakeCommands/target_include_directories/CMakeLists.txt b/Tests/CMakeCommands/target_include_directories/CMakeLists.txt
index d57556aad..8713d99dd 100644
--- a/Tests/CMakeCommands/target_include_directories/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_include_directories/CMakeLists.txt
@@ -42,17 +42,17 @@ add_executable(consumer
"${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
)
-if (CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja")
- target_sources(consumer PRIVATE
- "${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
- )
- target_include_directories(consumer
- PRIVATE
- $<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_only>
- $<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}/c_only>
- )
+target_sources(consumer PRIVATE
+ "${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
+)
+target_include_directories(consumer
+ PRIVATE
+ $<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_only>
+ $<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}/c_only>
+)
+if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
target_compile_definitions(consumer
- PRIVATE -DTEST_LANG_DEFINES
+ PRIVATE TEST_LANG_DEFINES_FOR_VISUAL_STUDIO_OR_XCODE
)
endif()
diff --git a/Tests/CMakeCommands/target_include_directories/consumer.c b/Tests/CMakeCommands/target_include_directories/consumer.c
index ae88f9248..7fd694b08 100644
--- a/Tests/CMakeCommands/target_include_directories/consumer.c
+++ b/Tests/CMakeCommands/target_include_directories/consumer.c
@@ -1,10 +1,18 @@
-#ifdef TEST_LANG_DEFINES
-#include "c_only.h"
+// Visual Studio allows only one set of flags for C and C++.
+// In a target using C++ we pick the C++ flags even for C sources.
+#ifdef TEST_LANG_DEFINES_FOR_VISUAL_STUDIO_OR_XCODE
+# include "cxx_only.h"
-#ifndef C_ONLY_DEFINE
-#error Expected C_ONLY_DEFINE
-#endif
+# ifndef CXX_ONLY_DEFINE
+# error Expected CXX_ONLY_DEFINE
+# endif
+#else
+# include "c_only.h"
+
+# ifndef C_ONLY_DEFINE
+# error Expected C_ONLY_DEFINE
+# endif
#endif
int consumer_c()
diff --git a/Tests/CMakeCommands/target_include_directories/consumer.cpp b/Tests/CMakeCommands/target_include_directories/consumer.cpp
index 0f8153b83..267b0a342 100644
--- a/Tests/CMakeCommands/target_include_directories/consumer.cpp
+++ b/Tests/CMakeCommands/target_include_directories/consumer.cpp
@@ -1,41 +1,37 @@
#include "consumer.h"
#include "common.h"
+#include "cxx_only.h"
#include "interfaceinclude.h"
#include "publicinclude.h"
#include "relative_dir.h"
-#ifdef TEST_LANG_DEFINES
-#include "cxx_only.h"
-#endif
#ifdef PRIVATEINCLUDE_DEFINE
-#error Unexpected PRIVATEINCLUDE_DEFINE
+# error Unexpected PRIVATEINCLUDE_DEFINE
#endif
#ifndef PUBLICINCLUDE_DEFINE
-#error Expected PUBLICINCLUDE_DEFINE
+# error Expected PUBLICINCLUDE_DEFINE
#endif
#ifndef INTERFACEINCLUDE_DEFINE
-#error Expected INTERFACEINCLUDE_DEFINE
+# error Expected INTERFACEINCLUDE_DEFINE
#endif
#ifndef CURE_DEFINE
-#error Expected CURE_DEFINE
+# error Expected CURE_DEFINE
#endif
#ifndef RELATIVE_DIR_DEFINE
-#error Expected RELATIVE_DIR_DEFINE
+# error Expected RELATIVE_DIR_DEFINE
#endif
#ifndef CONSUMER_DEFINE
-#error Expected CONSUMER_DEFINE
+# error Expected CONSUMER_DEFINE
#endif
-#ifdef TEST_LANG_DEFINES
#ifndef CXX_ONLY_DEFINE
-#error Expected CXX_ONLY_DEFINE
-#endif
+# error Expected CXX_ONLY_DEFINE
#endif
int main()
diff --git a/Tests/CMakeCommands/target_include_directories/main.cpp b/Tests/CMakeCommands/target_include_directories/main.cpp
index 71298ceac..dd591bfed 100644
--- a/Tests/CMakeCommands/target_include_directories/main.cpp
+++ b/Tests/CMakeCommands/target_include_directories/main.cpp
@@ -4,19 +4,19 @@
#include "publicinclude.h"
#ifndef PRIVATEINCLUDE_DEFINE
-#error Expected PRIVATEINCLUDE_DEFINE
+# error Expected PRIVATEINCLUDE_DEFINE
#endif
#ifndef PUBLICINCLUDE_DEFINE
-#error Expected PUBLICINCLUDE_DEFINE
+# error Expected PUBLICINCLUDE_DEFINE
#endif
#ifdef INTERFACEINCLUDE_DEFINE
-#error Unexpected INTERFACEINCLUDE_DEFINE
+# error Unexpected INTERFACEINCLUDE_DEFINE
#endif
#ifndef CURE_DEFINE
-#error Expected CURE_DEFINE
+# error Expected CURE_DEFINE
#endif
int main()
diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
index e11f980df..5c704ac83 100644
--- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
@@ -130,3 +130,19 @@ target_link_libraries(newsignature1 PRIVATE depC INTERFACE depD PUBLIC depB PRIV
assert_property(newsignature1 INTERFACE_LINK_LIBRARIES "depD;depB")
assert_property(newsignature1 LINK_LIBRARIES "depC;depB;subdirlib")
+
+#----------------------------------------------------------------------------
+# Test cross-directory linking.
+cmake_policy(PUSH)
+cmake_policy(SET CMP0022 NEW)
+cmake_policy(SET CMP0079 NEW)
+add_executable(TopDir TopDir.c)
+add_subdirectory(SubDirA)
+add_subdirectory(SubDirB)
+target_link_libraries(SubDirB TopDirImported)
+add_subdirectory(SubDirC)
+target_link_libraries(SubDirC PRIVATE SubDirC2)
+target_link_libraries(TopDir SubDirC)
+add_library(TopDirImported IMPORTED INTERFACE)
+target_compile_definitions(TopDirImported INTERFACE DEF_TopDirImported)
+cmake_policy(POP)
diff --git a/Tests/CMakeCommands/target_link_libraries/libgenex.h b/Tests/CMakeCommands/target_link_libraries/libgenex.h
index 733f9b6df..59ac18a33 100644
--- a/Tests/CMakeCommands/target_link_libraries/libgenex.h
+++ b/Tests/CMakeCommands/target_link_libraries/libgenex.h
@@ -2,7 +2,7 @@
#include "libgenex_export.h"
#ifndef LIBGENEX_H
-#define LIBGENEX_H
+# define LIBGENEX_H
struct LIBGENEX_EXPORT LibGenex
{
diff --git a/Tests/CMakeCommands/target_link_libraries/targetC.cpp b/Tests/CMakeCommands/target_link_libraries/targetC.cpp
index 7c5c9e426..cae02b9cd 100644
--- a/Tests/CMakeCommands/target_link_libraries/targetC.cpp
+++ b/Tests/CMakeCommands/target_link_libraries/targetC.cpp
@@ -5,7 +5,7 @@
#include "foo.h"
#ifndef TEST_DEF
-#error Expected TEST_DEF definition
+# error Expected TEST_DEF definition
#endif
int main(int, char**)
diff --git a/Tests/CMakeInstall.cmake b/Tests/CMakeInstall.cmake
index fda8c54b3..d9d85f71b 100644
--- a/Tests/CMakeInstall.cmake
+++ b/Tests/CMakeInstall.cmake
@@ -14,7 +14,18 @@ if(CMake_TEST_INSTALL)
set(CMake_TEST_INSTALL_PREFIX ${CMake_BINARY_DIR}/Tests/CMakeInstall)
set(CMAKE_INSTALL_PREFIX "${CMake_TEST_INSTALL_PREFIX}")
- if(CMAKE_CONFIGURATION_TYPES)
+ # 3.9 or later provides a definitive answer to whether we are multi-config
+ # through a global property. Prior to 3.9, CMAKE_CONFIGURATION_TYPES being set
+ # is assumed to mean multi-config, but developers might modify it so it is
+ # technically not as reliable.
+ if(NOT CMAKE_VERSION VERSION_LESS 3.9)
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+ elseif(CMAKE_CONFIGURATION_TYPES)
+ set(_isMultiConfig True)
+ else()
+ set(_isMultiConfig False)
+ endif()
+ if(_isMultiConfig)
# There are multiple configurations. Make sure the tested
# configuration is the one that is installed.
set(CMake_TEST_INSTALL_CONFIG --config $<CONFIGURATION>)
diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt
index d1a1df5ed..a25f25af0 100644
--- a/Tests/CMakeLib/CMakeLists.txt
+++ b/Tests/CMakeLib/CMakeLists.txt
@@ -5,20 +5,30 @@ include_directories(
)
set(CMakeLib_TESTS
- testGeneratedFileStream
- testRST
- testSystemTools
- testUTF8
- testXMLParser
- testXMLSafe
- testFindPackageCommand
+ testArgumentParser.cxx
+ testGeneratedFileStream.cxx
+ testRST.cxx
+ testRange.cxx
+ testString.cxx
+ testSystemTools.cxx
+ testUTF8.cxx
+ testXMLParser.cxx
+ testXMLSafe.cxx
+ testFindPackageCommand.cxx
+ testUVProcessChain.cxx
+ testUVRAII.cxx
+ testUVStreambuf.cxx
)
+add_executable(testUVProcessChainHelper testUVProcessChainHelper.cxx)
+
set(testRST_ARGS ${CMAKE_CURRENT_SOURCE_DIR})
+set(testUVProcessChain_ARGS $<TARGET_FILE:testUVProcessChainHelper>)
+set(testUVStreambuf_ARGS $<TARGET_FILE:cmake>)
if(WIN32)
list(APPEND CMakeLib_TESTS
- testVisualStudioSlnParser
+ testVisualStudioSlnParser.cxx
)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testVisualStudioSlnParser.h.in
${CMAKE_CURRENT_BINARY_DIR}/testVisualStudioSlnParser.h @ONLY)
@@ -31,11 +41,15 @@ create_test_sourcelist(CMakeLib_TEST_SRCS CMakeLibTests.cxx ${CMakeLib_TESTS})
add_executable(CMakeLibTests ${CMakeLib_TEST_SRCS})
target_link_libraries(CMakeLibTests CMakeLib)
+set_property(TARGET CMakeLibTests PROPERTY C_CLANG_TIDY "")
+set_property(TARGET CMakeLibTests PROPERTY CXX_CLANG_TIDY "")
+
add_executable(testEncoding testEncoding.cxx)
target_link_libraries(testEncoding cmsys)
-foreach(test ${CMakeLib_TESTS})
- add_test(CMakeLib.${test} CMakeLibTests ${test} ${${test}_ARGS})
+foreach(testfile ${CMakeLib_TESTS})
+ get_filename_component(test "${testfile}" NAME_WE)
+ add_test(NAME CMakeLib.${test} COMMAND CMakeLibTests ${test} ${${test}_ARGS})
endforeach()
if(TEST_CompileCommandOutput)
@@ -44,3 +58,6 @@ if(TEST_CompileCommandOutput)
endif()
add_subdirectory(PseudoMemcheck)
+
+add_executable(testAffinity testAffinity.cxx)
+target_link_libraries(testAffinity CMakeLib)
diff --git a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in
index b4c6fae44..3183bc0b6 100644
--- a/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in
+++ b/Tests/CMakeLib/PseudoMemcheck/memtester.cxx.in
@@ -15,15 +15,15 @@ int main(int ac, char** av)
std::string logarg;
bool nextarg = false;
- if (exename.find("valgrind") != exename.npos) {
+ if (exename.find("valgrind") != std::string::npos) {
logarg = "--log-file=";
- } else if (exename.find("purify") != exename.npos) {
+ } else if (exename.find("purify") != std::string::npos) {
#ifdef _WIN32
logarg = "/SAVETEXTDATA=";
#else
logarg = "-log-file=";
#endif
- } else if (exename.find("BC") != exename.npos) {
+ } else if (exename.find("BC") != std::string::npos) {
nextarg = true;
logarg = "/X";
}
diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx
index 46431bc33..b49803bd6 100644
--- a/Tests/CMakeLib/run_compile_commands.cxx
+++ b/Tests/CMakeLib/run_compile_commands.cxx
@@ -1,4 +1,4 @@
-#include <cmConfigure.h>
+#include "cmConfigure.h" // IWYU pragma: keep
#include "cmsys/FStream.hxx"
#include <iostream>
@@ -144,15 +144,11 @@ int main()
cmsys::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) {
+ for (auto const& tu : parser.GetTranslationUnits()) {
std::vector<std::string> command;
- cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command);
- if (!cmSystemTools::RunSingleCommand(command, CM_NULLPTR, CM_NULLPTR,
- CM_NULLPTR,
- it->at("directory").c_str())) {
+ cmSystemTools::ParseUnixCommandLine(tu.at("command").c_str(), command);
+ if (!cmSystemTools::RunSingleCommand(command, nullptr, nullptr, nullptr,
+ tu.at("directory").c_str())) {
std::cout << "ERROR: Failed to run command \"" << command[0] << "\""
<< std::endl;
exit(1);
diff --git a/Tests/CMakeLib/testEncoding.cxx b/Tests/CMakeLib/testEncoding.cxx
index 5e40638f7..d608e86d7 100644
--- a/Tests/CMakeLib/testEncoding.cxx
+++ b/Tests/CMakeLib/testEncoding.cxx
@@ -3,7 +3,7 @@
#include <string>
#ifdef _WIN32
-#include "cmsys/ConsoleBuf.hxx"
+# include "cmsys/ConsoleBuf.hxx"
#endif
#ifdef _WIN32
@@ -31,7 +31,7 @@ int main(int argc, char* argv[])
}
const std::string encoding(argv[1]);
#ifdef _WIN32
- if (encoding == "UTF8") {
+ if ((encoding == "UTF8") || (encoding == "UTF-8")) {
setEncoding(consoleOut, CP_UTF8);
} else if (encoding == "ANSI") {
setEncoding(consoleOut, CP_ACP);
diff --git a/Tests/CMakeLib/testRST.expect b/Tests/CMakeLib/testRST.expect
index fa436cb91..c19ee9400 100644
--- a/Tests/CMakeLib/testRST.expect
+++ b/Tests/CMakeLib/testRST.expect
@@ -16,7 +16,14 @@ 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.
+Environment variable ``SOME_ENV_VAR``.
+Environment variable ``some env var`` with space and target.
Generator ``Some Generator`` with space.
+Generator ``Some Generator`` with space.
+Inline literal ``~!@#$%^&*( )_+-=\\[]{}'":;,<>.?/``.
+Inline link Link Text.
+Inline link Link Text <With \-escaped Brackets>.
+Inline literal ``__`` followed by inline link Link Text.
First TOC entry.
@@ -76,6 +83,10 @@ or after a paragraph ending in two colons::
but not after a line ending in two colons::
in the middle of a paragraph.
+A literal block can be empty::
+
+
+
.. productionlist::
grammar: `production`
production: "content rendered"
diff --git a/Tests/CMakeLib/testRST.rst b/Tests/CMakeLib/testRST.rst
index 54952dd9f..d2d1140f3 100644
--- a/Tests/CMakeLib/testRST.rst
+++ b/Tests/CMakeLib/testRST.rst
@@ -23,7 +23,14 @@ 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.
+Environment variable :envvar:`SOME_ENV_VAR`.
+Environment variable :envvar:`some env var <SOME_ENV_VAR>` with space and target.
Generator :generator:`Some Generator` with space.
+Generator :cpack_gen:`Some Generator` with space.
+Inline literal ``~!@#$%^&*( )_+-=\\[]{}'":;,<>.?/``.
+Inline link `Link Text <ExternalDest>`_.
+Inline link `Link Text \<With \\-escaped Brackets\> <ExternalDest>`_.
+Inline literal ``__`` followed by inline link `Link Text <InternalDest_>`_.
.. |not replaced| replace:: not replaced through toctree
.. |not replaced in literal| replace:: replaced in parsed literal
@@ -83,6 +90,10 @@ or after a paragraph ending in two colons::
but not after a line ending in two colons::
in the middle of a paragraph.
+A literal block can be empty::
+
+
+
.. productionlist::
grammar: `production`
production: "content rendered"
diff --git a/Tests/CMakeLib/testSystemTools.cxx b/Tests/CMakeLib/testSystemTools.cxx
index 0dfa326a3..121e63985 100644
--- a/Tests/CMakeLib/testSystemTools.cxx
+++ b/Tests/CMakeLib/testSystemTools.cxx
@@ -16,11 +16,13 @@
failed = 1
#define cmAssert(exp, m) \
- if ((exp)) { \
- cmPassed(m); \
- } else { \
- cmFailed(m); \
- }
+ do { \
+ if ((exp)) { \
+ cmPassed(m); \
+ } else { \
+ cmFailed(m); \
+ } \
+ } while (false)
int testSystemTools(int /*unused*/, char* /*unused*/ [])
{
@@ -52,7 +54,7 @@ int testSystemTools(int /*unused*/, char* /*unused*/ [])
cmAssert(cmSystemTools::strverscmp("99999999999999", "99999999999991") > 0,
"strverscmp natural overflow");
cmAssert(cmSystemTools::strverscmp("00000000000009", "00000000000001") > 0,
- "strverscmp deciaml precision");
+ "strverscmp decimal precision");
cmAssert(cmSystemTools::strverscmp("a.b.c.0", "a.b.c.000") > 0,
"strverscmp multiple zeros");
cmAssert(cmSystemTools::strverscmp("lib_1.2_10", "lib_1.2_2") > 0,
@@ -91,5 +93,22 @@ int testSystemTools(int /*unused*/, char* /*unused*/ [])
if (!failed) {
cmPassed("cmSystemTools::strverscmp working");
}
+
+ // ----------------------------------------------------------------------
+ // Test cmSystemTools::StringToULong
+ {
+ unsigned long value;
+ cmAssert(cmSystemTools::StringToULong("1", &value) && value == 1,
+ "StringToULong parses a decimal integer.");
+ cmAssert(cmSystemTools::StringToULong(" 1", &value) && value == 1,
+ "StringToULong parses a decimal integer after whitespace.");
+ cmAssert(!cmSystemTools::StringToULong("-1", &value),
+ "StringToULong rejects a negative number.");
+ cmAssert(!cmSystemTools::StringToULong(" -1", &value),
+ "StringToULong rejects a negative number after whitespace.");
+ cmAssert(!cmSystemTools::StringToULong("1x", &value),
+ "StringToULong rejects trailing content.");
+ }
+
return failed;
}
diff --git a/Tests/CMakeLib/testUTF8.cxx b/Tests/CMakeLib/testUTF8.cxx
index fb5f3d815..a0bb5cd23 100644
--- a/Tests/CMakeLib/testUTF8.cxx
+++ b/Tests/CMakeLib/testUTF8.cxx
@@ -8,8 +8,24 @@ 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]);
+ printf("[0x%02X,0x%02X,0x%02X,0x%02X]", static_cast<int>(d[0]),
+ static_cast<int>(d[1]), static_cast<int>(d[2]),
+ static_cast<int>(d[3]));
+}
+
+static void byte_array_print(char const* s)
+{
+ unsigned char const* d = reinterpret_cast<unsigned char const*>(s);
+ bool started = false;
+ printf("[");
+ for (; *d; ++d) {
+ if (started) {
+ printf(",");
+ }
+ started = true;
+ printf("0x%02X", static_cast<int>(*d));
+ }
+ printf("]");
}
struct test_utf8_entry
@@ -20,17 +36,36 @@ struct test_utf8_entry
};
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. */
+ { 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. */
+ { 3, "\xED\x80\x80\x00", 0xD000 }, /* Valid 0xED prefixed codepoint. */
+ { 4, "\xF4\x8F\xBF\xBF", 0x10FFFF }, /* Highest valid RFC codepoint. */
{ 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 }
+ "\x80\x00\x00\x00", /* Leading continuation byte. */
+ "\xC0\x80\x00\x00", /* Overlong encoding. */
+ "\xC1\x80\x00\x00", /* Overlong encoding. */
+ "\xC2\x00\x00\x00", /* Missing continuation byte. */
+ "\xE0\x00\x00\x00", /* Missing continuation bytes. */
+ "\xE0\x80\x80\x00", /* Overlong encoding. */
+ "\xF0\x80\x80\x80", /* Overlong encoding. */
+ "\xED\xA0\x80\x00", /* UTF-16 surrogate half. */
+ "\xED\xBF\xBF\x00", /* UTF-16 surrogate half. */
+ "\xF4\x90\x80\x80", /* Lowest out-of-range codepoint. */
+ "\xF5\x80\x80\x80", /* Prefix forces out-of-range codepoints. */
+ { 0, 0, 0, 0, 0 }
+};
+
+static char const* good_strings[] = { "", "ASCII", "\xC2\xA9 Kitware", 0 };
+
+static char const* bad_strings[] = {
+ "\xC0\x80", /* Modified UTF-8 for embedded 0-byte. */
+ 0
};
static void report_good(bool passed, test_utf8_char const c)
@@ -86,6 +121,46 @@ static bool decode_bad(test_utf8_char const s)
return true;
}
+static void report_valid(bool passed, char const* s)
+{
+ printf("%s: validity good ", passed ? "pass" : "FAIL");
+ byte_array_print(s);
+ printf(" (%s) ", s);
+}
+
+static void report_invalid(bool passed, char const* s)
+{
+ printf("%s: validity bad ", passed ? "pass" : "FAIL");
+ byte_array_print(s);
+ printf(" ");
+}
+
+static bool is_valid(const char* s)
+{
+ bool valid = cm_utf8_is_valid(s) != 0;
+ if (!valid) {
+ report_valid(false, s);
+ printf("expected valid, reported as invalid\n");
+ return false;
+ }
+ report_valid(true, s);
+ printf("valid as expected\n");
+ return true;
+}
+
+static bool is_invalid(const char* s)
+{
+ bool valid = cm_utf8_is_valid(s) != 0;
+ if (valid) {
+ report_invalid(false, s);
+ printf("expected invalid, reported as valid\n");
+ return false;
+ }
+ report_invalid(true, s);
+ printf("invalid as expected\n");
+ return true;
+}
+
int testUTF8(int /*unused*/, char* /*unused*/ [])
{
int result = 0;
@@ -93,11 +168,27 @@ int testUTF8(int /*unused*/, char* /*unused*/ [])
if (!decode_good(*e)) {
result = 1;
}
+ if (!is_valid(e->str)) {
+ result = 1;
+ }
}
for (test_utf8_char const* c = bad_chars; (*c)[0]; ++c) {
if (!decode_bad(*c)) {
result = 1;
}
+ if (!is_invalid(*c)) {
+ result = 1;
+ }
+ }
+ for (char const** s = good_strings; *s; ++s) {
+ if (!is_valid(*s)) {
+ result = 1;
+ }
+ }
+ for (char const** s = bad_strings; *s; ++s) {
+ if (!is_invalid(*s)) {
+ result = 1;
+ }
}
return result;
}
diff --git a/Tests/CMakeLib/testVisualStudioSlnParser.cxx b/Tests/CMakeLib/testVisualStudioSlnParser.cxx
index f8bcfae85..c7fd585cc 100644
--- a/Tests/CMakeLib/testVisualStudioSlnParser.cxx
+++ b/Tests/CMakeLib/testVisualStudioSlnParser.cxx
@@ -45,17 +45,55 @@ int testVisualStudioSlnParser(int, char* [])
}
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",
+ "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"
/* clang-format needs this comment to break after the opening brace */
};
diff --git a/Tests/CMakeLib/testXMLSafe.cxx b/Tests/CMakeLib/testXMLSafe.cxx
index fe776c587..21bb95292 100644
--- a/Tests/CMakeLib/testXMLSafe.cxx
+++ b/Tests/CMakeLib/testXMLSafe.cxx
@@ -1,7 +1,7 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
-#include <cmConfigure.h>
+#include "cmConfigure.h" // IWYU pragma: keep
#include <sstream>
#include <stdio.h>
@@ -21,7 +21,7 @@ static test_pair const pairs[] = {
{ "angles <>", "angles &lt;&gt;" },
{ "ampersand &", "ampersand &amp;" },
{ "bad-byte \x80", "bad-byte [NON-UTF-8-BYTE-0x80]" },
- { CM_NULLPTR, CM_NULLPTR }
+ { nullptr, nullptr }
};
int testXMLSafe(int /*unused*/, char* /*unused*/ [])
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index d16df1cf5..e73b277f1 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -22,6 +22,7 @@ macro(ADD_TEST_MACRO NAME)
endmacro()
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
+include(${CMAKE_CURRENT_SOURCE_DIR}/CheckSwift.cmake)
# Fake a user home directory to avoid polluting the real one.
if(DEFINED ENV{HOME} AND NOT CTEST_NO_TEST_HOME)
@@ -31,14 +32,28 @@ if(DEFINED ENV{HOME} AND NOT CTEST_NO_TEST_HOME)
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}\")
+if(NOT DEFINED ENV{CTEST_REAL_HOME})
+ set(ENV{CTEST_REAL_HOME} \"\$ENV{HOME}\")
+endif()
set(ENV{HOME} \"${TEST_HOME}\")
")
endif()
+# 3.9 or later provides a definitive answer to whether we are multi-config
+# through a global property. Prior to 3.9, CMAKE_CONFIGURATION_TYPES being set
+# is assumed to mean multi-config, but developers might modify it so it is
+# technically not as reliable.
+if(NOT CMAKE_VERSION VERSION_LESS 3.9)
+ get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+elseif(CMAKE_CONFIGURATION_TYPES)
+ set(_isMultiConfig True)
+else()
+ set(_isMultiConfig False)
+endif()
+
# Choose a default configuration for CTest tests.
set(CTestTest_CONFIG Debug)
-if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE)
+if(NOT _isMultiConfig AND CMAKE_BUILD_TYPE)
set(CTestTest_CONFIG ${CMAKE_BUILD_TYPE})
endif()
@@ -50,7 +65,7 @@ if(BUILD_TESTING)
set(CMake_TEST_DEVENV "")
if(CMAKE_VS_DEVENV_COMMAND)
set(CMake_TEST_DEVENV "${CMAKE_VS_DEVENV_COMMAND}")
- elseif(CMAKE_GENERATOR MATCHES "Visual Studio [89] " AND
+ elseif(CMAKE_GENERATOR MATCHES "Visual Studio 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()
@@ -131,8 +146,7 @@ if(BUILD_TESTING)
set(CPACK_BINARY_RPM OFF)
endif()
- # Look for rpmbuild to use for tests.
- # The tool does not work with spaces in the path.
+ # Look for dpkg to use for tests.
find_program(DPKG_EXECUTABLE NAMES dpkg)
if(DPKG_EXECUTABLE)
@@ -141,11 +155,65 @@ if(BUILD_TESTING)
set(CPACK_BINARY_DEB OFF)
endif()
+ # Look for NuGet to use for tests.
+ find_program(NUGET_EXECUTABLE NAMES NuGet nuget)
+
+ if(NUGET_EXECUTABLE)
+ set(CPACK_BINARY_NUGET ON)
+ else()
+ set(CPACK_BINARY_NUGET OFF)
+ endif()
+
+ if(WIN32)
+ # Macro to search for available Windows CE SDKs in the windows Registry
+ macro(select_wince_sdk selected_reg selected_sdk)
+ if(CMAKE_HOST_WIN32)
+ execute_process(COMMAND reg QUERY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs"
+ OUTPUT_VARIABLE sdk_reg
+ ERROR_VARIABLE my_err)
+ string(REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Wow6432Node\\\\Microsoft\\\\Windows CE Tools\\\\SDKs\\\\" ";" sdk_list "${sdk_reg}")
+ list(LENGTH sdk_list sdk_list_len)
+ if (${sdk_list_len} GREATER 1)
+ list(GET sdk_list 1 _sdk) # The first entry is always empty due to the regex replace above
+ string(STRIP ${_sdk} _sdk) # Make sure there is no newline in the SDK name
+ endif()
+ # Build a key to be used by get_filename_component that is pointing to the SDK directory
+ set(_reg "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs\\${_sdk}]")
+ # Set return values
+ set(${selected_reg} ${_reg})
+ set(${selected_sdk} ${_sdk})
+ endif(CMAKE_HOST_WIN32)
+ endmacro(select_wince_sdk)
+
+ 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_vs14 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.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_ws10_0 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\Setup\\Build Tools for Windows 10;srcPath]")
+ 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]")
+ select_wince_sdk(reg_wince wince_sdk)
+ set(reg_tegra "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;sdkRoot]")
+ set(reg_nasm "[HKEY_CURRENT_USER\\SOFTWARE\\nasm]")
+ foreach(reg vs10 vs11 vs12 vs14 ws80 ws81 ws10_0 wp80 wp81 wince tegra nasm)
+ get_filename_component(r "${reg_${reg}}" ABSOLUTE)
+ if(IS_DIRECTORY "${r}" AND NOT "${r}" STREQUAL "/registry")
+ set(${reg} 1)
+ else()
+ set(${reg} 0)
+ endif()
+ endforeach()
+ endif()
+
#---------------------------------------------------------------------------
# Add tests below here.
if(NOT CMake_TEST_EXTERNAL_CMAKE)
add_subdirectory(CMakeLib)
+
+ add_subdirectory(CMakeServerLib)
endif()
add_subdirectory(CMakeOnly)
add_subdirectory(RunCMake)
@@ -228,6 +296,10 @@ if(BUILD_TESTING)
set(CMake_TEST_XCODE_VERSION "${CMAKE_MATCH_1}")
endif()
endif()
+ if(NOT CMake_TEST_XCODE_VERSION VERSION_LESS 10)
+ # Since Xcode 10 we do not have two supported architectures for the host.
+ set(CTEST_TEST_OSX_ARCH 0)
+ endif()
if(CMAKE_OSX_SYSROOT)
execute_process(
COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version ProductName
@@ -264,7 +336,7 @@ if(BUILD_TESTING)
endif()
add_test(NAME CMake.Copyright
- COMMAND cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCopyright.cmake)
+ COMMAND ${CMAKE_CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/CMakeCopyright.cmake)
# add a bunch of standard build-and-test style tests
ADD_TEST_MACRO(CommandLineTest CommandLineTest)
@@ -294,11 +366,16 @@ if(BUILD_TESTING)
((NOT CMAKE_OSX_SDKPRODUCT STREQUAL "Mac OS X") OR
(NOT CMAKE_OSX_SDKVERSION VERSION_LESS 10.10)))
if(CMAKE_GENERATOR STREQUAL "Xcode")
- ADD_TEST_MACRO(SwiftMix SwiftMix)
- ADD_TEST_MACRO(SwiftOnly SwiftOnly)
+ set(CMake_TEST_XCODE_SWIFT 1)
endif()
endif()
endif()
+ if(CMAKE_Swift_COMPILER OR CMake_TEST_XCODE_SWIFT)
+ ADD_TEST_MACRO(SwiftOnly SwiftOnly)
+ if(CMake_TEST_XCODE_SWIFT)
+ ADD_TEST_MACRO(SwiftMix SwiftMix)
+ endif()
+ endif()
if(CMAKE_Fortran_COMPILER)
ADD_TEST_MACRO(FortranOnly FortranOnly)
endif()
@@ -325,13 +402,14 @@ if(BUILD_TESTING)
set(CMAKE_SKIP_VSGNUFortran TRUE)
endif()
if(NOT CMAKE_SKIP_VSGNUFortran)
- ADD_TEST_MACRO(VSGNUFortran ${CMAKE_COMMAND} -P runtest.cmake)
+ ADD_TEST_MACRO(VSGNUFortran ${CMAKE_CMAKE_COMMAND} -P runtest.cmake)
endif()
endif()
- if(${CMAKE_GENERATOR} MATCHES "Visual Studio ([^89]|[89][0-9])")
+ if(${CMAKE_GENERATOR} MATCHES "Visual Studio ([^9]|[9][0-9])")
ADD_TEST_MACRO(CSharpOnly CSharpOnly)
ADD_TEST_MACRO(CSharpLinkToCxx CSharpLinkToCxx)
+ ADD_TEST_MACRO(CSharpLinkFromCxx CSharpLinkFromCxx)
endif()
ADD_TEST_MACRO(COnly COnly)
@@ -339,6 +417,7 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(CxxSubdirC CxxSubdirC)
ADD_TEST_MACRO(IPO COnly/COnly)
ADD_TEST_MACRO(OutDir runtime/OutDir)
+ ADD_TEST_MACRO(OutName exe.OutName.exe)
ADD_TEST_MACRO(ObjectLibrary UseCshared)
ADD_TEST_MACRO(NewlineArgs NewlineArgs)
ADD_TEST_MACRO(SetLang SetLang)
@@ -363,10 +442,14 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(PolicyScope PolicyScope)
ADD_TEST_MACRO(EmptyLibrary EmptyLibrary)
ADD_TEST_MACRO(CompileDefinitions CompileDefinitions)
+ if(CMAKE_Fortran_COMPILER)
+ set(CompileOptions_BUILD_OPTIONS -DTEST_FORTRAN=1)
+ endif()
ADD_TEST_MACRO(CompileOptions CompileOptions)
ADD_TEST_MACRO(CompatibleInterface CompatibleInterface)
ADD_TEST_MACRO(AliasTarget AliasTarget)
ADD_TEST_MACRO(StagingPrefix StagingPrefix)
+ ADD_TEST_MACRO(ImportedSameName ImportedSameName)
ADD_TEST_MACRO(InterfaceLibrary InterfaceLibrary)
if (CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
set(ConfigSources_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
@@ -374,12 +457,15 @@ if(BUILD_TESTING)
endif()
ADD_TEST_MACRO(SourcesProperty SourcesProperty)
ADD_TEST_MACRO(SourceFileProperty SourceFileProperty)
+ if (NOT CMAKE_GENERATOR STREQUAL "Xcode")
+ ADD_TEST_MACRO(SourceFileIncludeDirProperty SourceFileIncludeDirProperty)
+ endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU
AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
set(runCxxDialectTest 1)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang
- AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
+ AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4 AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
if(NOT APPLE OR POLICY CMP0025)
set(runCxxDialectTest 1)
endif()
@@ -403,11 +489,14 @@ if(BUILD_TESTING)
list(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX})
- if(NOT QT4_FOUND)
+ if(NOT DEFINED CMake_TEST_Qt4)
+ set(CMake_TEST_Qt4 1)
+ endif()
+ if(CMake_TEST_Qt4 AND NOT QT4_FOUND)
find_package(Qt4 QUIET)
endif()
- if(QT4_FOUND)
+ if(CMake_TEST_Qt4 AND 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
@@ -517,7 +606,6 @@ if(BUILD_TESTING)
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()
@@ -605,7 +693,6 @@ if(BUILD_TESTING)
"CodeLite"
"Eclipse CDT4"
"Kate"
- "KDevelop3"
"Sublime Text 2")
foreach(extraGenerator ${extraGenerators})
@@ -683,14 +770,14 @@ if(BUILD_TESTING)
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
+${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGHTLY_RELEASES}'
")
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)
+ if(CMake_BUILD_NIGHTLY_RELEASES)
ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin32
win32_release.cmake)
ADD_NIGHTLY_BUILD_TEST(CMakeNightlyWin64
@@ -795,6 +882,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
ADD_TEST_MACRO(CustomCommandByproducts CustomCommandByproducts)
+ ADD_TEST_MACRO(CommandLength CommandLength)
+
ADD_TEST_MACRO(EmptyDepends ${CMAKE_CTEST_COMMAND})
add_test(CustomCommandWorkingDirectory ${CMAKE_CTEST_COMMAND}
@@ -809,31 +898,6 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
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"
@@ -858,33 +922,6 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
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}
@@ -952,6 +989,44 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
endif()
+ if(CTEST_TEST_CPACK)
+ add_test(CPackUseDefaultVersion ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CPackUseDefaultVersion"
+ "${CMake_BINARY_DIR}/Tests/CPackUseDefaultVersion"
+ ${build_generator_args}
+ --build-project CPackUseDefaultVersion
+ --build-two-config
+ --build-options ${build_options}
+ ${CPackUseDefaultVersion_BUILD_OPTIONS})
+ set_tests_properties(CPackUseDefaultVersion PROPERTIES PASS_REGULAR_EXPRESSION "CPACK_PACKAGE_VERSION=0\\.1\\.1")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackUseDefaultVersion")
+
+ add_test(CPackUseProjectVersion ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CPackUseProjectVersion"
+ "${CMake_BINARY_DIR}/Tests/CPackUseProjectVersion"
+ ${build_generator_args}
+ --build-project CPackUseProjectVersion
+ --build-two-config
+ --build-options ${build_options}
+ ${CPackUseProjectVersion_BUILD_OPTIONS})
+ set_tests_properties(CPackUseProjectVersion PROPERTIES PASS_REGULAR_EXPRESSION "CPACK_PACKAGE_VERSION=1\\.2\\.3")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackUseProjectVersion")
+
+ add_test(CPackUseShortProjectVersion ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/CPackUseShortProjectVersion"
+ "${CMake_BINARY_DIR}/Tests/CPackUseShortProjectVersion"
+ ${build_generator_args}
+ --build-project CPackUseShortProjectVersion
+ --build-two-config
+ --build-options ${build_options}
+ ${CPackUseProjectVersion_BUILD_OPTIONS})
+ set_tests_properties(CPackUseShortProjectVersion PROPERTIES PASS_REGULAR_EXPRESSION "CPACK_PACKAGE_VERSION=2")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/CPackUseShortProjectVersion")
+ endif()
+
if(CTEST_RUN_CPackComponents)
set(CPackComponents_BUILD_OPTIONS)
if(APPLE)
@@ -996,6 +1071,12 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
if(CPACK_BINARY_DEB)
list(APPEND ACTIVE_CPACK_GENERATORS DEB)
endif()
+ # Check whether if NuGet command is found
+ # before adding NuGet tests
+ if(CPACK_BINARY_NUGET)
+ list(APPEND ACTIVE_CPACK_GENERATORS NUGET)
+ set(CPACK_GENERATOR_STRING_NUGET NuGet)
+ endif()
# ACTIVE_CPACK_GENERATORS variable
# now contains the list of 'active generators'
@@ -1015,7 +1096,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
list(APPEND CWAYLST "IgnoreGroup")
list(APPEND CWAYLST "AllInOne")
foreach(CPackGen IN LISTS ACTIVE_CPACK_GENERATORS)
- set(CPackRun_CPackGen "-DCPackGen=${CPackGen}")
+ if(NOT DEFINED CPACK_GENERATOR_STRING_${CPackGen})
+ set(CPACK_GENERATOR_STRING_${CPackGen} ${CPackGen})
+ endif()
+ set(CPackRun_CPackGen "-DCPackGen=${CPACK_GENERATOR_STRING_${CPackGen}}")
foreach(CPackComponentWay ${CWAYLST})
set(CPackRun_CPackComponentWay "-DCPackComponentWay=${CPackComponentWay}")
add_test(CPackComponentsForAll-${CPackGen}-${CPackComponentWay}
@@ -1026,7 +1110,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
${build_generator_args}
--build-project CPackComponentsForAll
--build-options ${build_options}
- -DCPACK_GENERATOR:STRING=${CPackGen}
+ -DCPACK_GENERATOR:STRING=${CPACK_GENERATOR_STRING_${CPackGen}}
-DCPACK_BINARY_${CPackGen}:BOOL=ON
${CPackRun_CPackComponentWay}
${CPackComponentsForAll_BUILD_OPTIONS}
@@ -1260,80 +1344,17 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
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 complex/QtAutogen)
- set(run_autouic_test QtAutoUicInterface)
+ if(NOT DEFINED CMake_TEST_Qt5)
+ set(CMake_TEST_Qt5 1)
endif()
- if(NOT CMAKE_CONFIGURATION_TYPES)
- set(QtAutogen_BUILD_OPTIONS -DCMAKE_BUILD_TYPE=$<CONFIGURATION>)
+ if(CMake_TEST_Qt5)
+ find_package(Qt5Widgets QUIET NO_MODULE)
endif()
-
- find_package(Qt5Widgets QUIET NO_MODULE)
- if(Qt5Widgets_FOUND)
- add_test(NAME Qt5Autogen COMMAND ${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
- ${QtAutogen_BUILD_OPTIONS}
- --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")
+ if(CMake_TEST_Qt5 AND Qt5Widgets_FOUND)
+ add_subdirectory(Qt5Autogen)
endif()
if(QT4_WORKS AND QT_QTGUI_FOUND)
- add_test(NAME Qt4Autogen COMMAND ${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
- ${QtAutogen_BUILD_OPTIONS}
- --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_subdirectory(Qt4Autogen)
add_test(Qt4Targets ${CMAKE_CTEST_COMMAND}
--build-and-test
@@ -1350,18 +1371,18 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
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}
+ add_test(Qt4And5AutomocForward ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/Qt4And5Automoc"
- "${CMake_BINARY_DIR}/Tests/Qt4And5Automoc"
+ "${CMake_BINARY_DIR}/Tests/Qt4And5AutomocForward"
${build_generator_args}
--build-project Qt4And5Automoc
- --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4And5Automoc"
+ --build-exe-dir "${CMake_BINARY_DIR}/Tests/Qt4And5AutomocForward"
--force-new-ctest-process
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V
)
- list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4And5Automoc")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4And5AutomocForward")
add_test(Qt4And5AutomocReverse ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/Qt4And5Automoc"
@@ -1377,6 +1398,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
endif()
+ if(CMake_TEST_FindALSA)
+ add_subdirectory(FindALSA)
+ endif()
+
if(CMake_TEST_CUDA)
add_subdirectory(Cuda)
add_subdirectory(CudaOnly)
@@ -1390,10 +1415,50 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindBZip2)
endif()
+ if(CMake_TEST_FindCURL)
+ add_subdirectory(FindCURL)
+ endif()
+
+ if(CMake_TEST_FindCups)
+ add_subdirectory(FindCups)
+ endif()
+
if(CMake_TEST_FindDoxygen)
add_subdirectory(FindDoxygen)
endif()
+ if(CMake_TEST_FindEnvModules)
+ add_subdirectory(FindEnvModules)
+ endif()
+
+ if(CMake_TEST_FindEXPAT)
+ add_subdirectory(FindEXPAT)
+ endif()
+
+ if(CMake_TEST_FindFontconfig)
+ add_subdirectory(FindFontconfig)
+ endif()
+
+ if(CMake_TEST_FindFreetype)
+ add_subdirectory(FindFreetype)
+ endif()
+
+ if(CMake_TEST_FindGDAL)
+ add_subdirectory(FindGDAL)
+ endif()
+
+ if(CMake_TEST_FindGIF)
+ add_subdirectory(FindGIF)
+ endif()
+
+ if(CMake_TEST_FindGit)
+ add_subdirectory(FindGit)
+ endif()
+
+ if(CMake_TEST_FindGLEW)
+ add_subdirectory(FindGLEW)
+ endif()
+
if(CMake_TEST_FindGSL)
add_subdirectory(FindGSL)
endif()
@@ -1403,26 +1468,54 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(GoogleTest)
endif()
+ if(CMake_TEST_FindGTK2)
+ add_subdirectory(FindGTK2)
+ endif()
+
+ if(CMake_TEST_FindIconv)
+ add_subdirectory(FindIconv)
+ endif()
+
if(CMake_TEST_FindICU)
add_subdirectory(FindICU)
endif()
+ if(CMake_TEST_FindJPEG)
+ add_subdirectory(FindJPEG)
+ endif()
+
if(CMake_TEST_FindJsonCpp)
add_subdirectory(FindJsonCpp)
endif()
+ if(CMake_TEST_FindLibLZMA)
+ add_subdirectory(FindLibLZMA)
+ endif()
+
if(CMake_TEST_FindLibRHash)
add_subdirectory(FindLibRHash)
endif()
+ if(CMake_TEST_FindLibinput)
+ add_subdirectory(FindLibinput)
+ endif()
+
if(CMake_TEST_FindLibUV)
add_subdirectory(FindLibUV)
endif()
+ if(CMake_TEST_FindLibXml2)
+ add_subdirectory(FindLibXml2)
+ endif()
+
if(CMake_TEST_FindLTTngUST)
add_subdirectory(FindLTTngUST)
endif()
+ if(CMake_TEST_FindODBC)
+ add_subdirectory(FindODBC)
+ endif()
+
if(CMake_TEST_FindOpenCL)
add_subdirectory(FindOpenCL)
endif()
@@ -1447,10 +1540,22 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindPNG)
endif()
+ if(CMake_TEST_FindPatch)
+ add_subdirectory(FindPatch)
+ endif()
+
+ if(CMake_TEST_FindPostgreSQL)
+ add_subdirectory(FindPostgreSQL)
+ endif()
+
if(CMake_TEST_FindProtobuf)
add_subdirectory(FindProtobuf)
endif()
+ if(CMake_TEST_FindSQLite3)
+ add_subdirectory(FindSQLite3)
+ endif()
+
if(CMake_TEST_FindTIFF)
add_subdirectory(FindTIFF)
endif()
@@ -1459,6 +1564,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindVulkan)
endif()
+ if(CMake_TEST_FindX11)
+ add_subdirectory(FindX11)
+ endif()
+
if(CMake_TEST_FindXalanC)
add_subdirectory(FindXalanC)
endif()
@@ -1467,18 +1576,43 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindXercesC)
endif()
+ if(CMake_TEST_FindPython OR CMake_TEST_FindPython_NumPy)
+ add_subdirectory(FindPython)
+ endif()
+
+ if(CMake_TEST_UseSWIG)
+ add_subdirectory(UseSWIG)
+ endif()
+
add_subdirectory(FindThreads)
# Matlab module
- if(CMake_TEST_FindMatlab)
+ # CMake_TEST_FindMatlab: indicates to look for Matlab (from PATH for Linux)
+ # CMake_TEST_FindMatlab_ROOT_DIR: indicates an optional root directory for Matlab, allows to select a version.
+ # CMake_TEST_FindMatlab_MCR: indicates the MCR is installed
+ # CMake_TEST_FindMatlab_MCR_ROOT_DIR: indicates an optional root directory for the MCR, required on Linux
+ if(CMake_TEST_FindMatlab OR (NOT "${CMake_TEST_FindMatlab_ROOT_DIR}" STREQUAL "") OR
+ CMake_TEST_FindMatlab_MCR OR (NOT "${CMake_TEST_FindMatlab_MCR_ROOT_DIR}" STREQUAL ""))
+ set(FindMatlab_additional_test_options )
+ if(CMake_TEST_FindMatlab_MCR OR NOT "${CMake_TEST_FindMatlab_MCR_ROOT_DIR}" STREQUAL "")
+ set(FindMatlab_additional_test_options -DIS_MCR=TRUE)
+ endif()
+ if(NOT "${CMake_TEST_FindMatlab_ROOT_DIR}" STREQUAL "")
+ set(FindMatlab_additional_test_options ${FindMatlab_additional_test_options} "-DMatlab_ROOT_DIR=${CMake_TEST_FindMatlab_ROOT_DIR}")
+ endif()
+ if(NOT "${CMake_TEST_FindMatlab_MCR_ROOT_DIR}" STREQUAL "")
+ set(FindMatlab_additional_test_options ${FindMatlab_additional_test_options} "-DMCR_ROOT:FILEPATH=${CMake_TEST_FindMatlab_MCR_ROOT_DIR}")
+ endif()
+ set(FindMatlab.basic_checks_BUILD_OPTIONS ${FindMatlab_additional_test_options})
ADD_TEST_MACRO(FindMatlab.basic_checks ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>)
+ set(FindMatlab.versions_checks_BUILD_OPTIONS ${FindMatlab_additional_test_options})
ADD_TEST_MACRO(FindMatlab.versions_checks ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>)
+ set(FindMatlab.components_checks_BUILD_OPTIONS ${FindMatlab_additional_test_options})
ADD_TEST_MACRO(FindMatlab.components_checks ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>)
- endif()
-
- find_package(GTK2 QUIET)
- if(GTK2_FOUND)
- add_subdirectory(FindGTK2)
+ set(FindMatlab.failure_reports_BUILD_OPTIONS ${FindMatlab_additional_test_options})
+ ADD_TEST_MACRO(FindMatlab.failure_reports ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>)
+ set(FindMatlab.r2018a_check_BUILD_OPTIONS ${FindMatlab_additional_test_options})
+ ADD_TEST_MACRO(FindMatlab.r2018a_check ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>)
endif()
add_test(ExternalProject ${CMAKE_CTEST_COMMAND}
@@ -1494,6 +1628,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProject")
set_tests_properties(ExternalProject PROPERTIES
+ RUN_SERIAL 1
TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
add_test(NAME ExternalProjectSubdir
@@ -1520,6 +1655,18 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectSourceSubdir")
+ add_test(NAME ExternalProjectSourceSubdirNotCMake
+ COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/ExternalProjectSourceSubdirNotCMake"
+ "${CMake_BINARY_DIR}/Tests/ExternalProjectSourceSubdirNotCMake"
+ ${build_generator_args}
+ --build-project ExternalProjectSourceSubdirNotCMake
+ --force-new-ctest-process
+ --build-options ${build_options}
+ )
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectSourceSubdirNotCMake")
+
add_test(ExternalProjectLocal ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/ExternalProjectLocal"
@@ -1533,6 +1680,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectLocal")
set_tests_properties(ExternalProjectLocal PROPERTIES
+ RUN_SERIAL 1
TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
add_test(ExternalProjectUpdateSetup ${CMAKE_CTEST_COMMAND}
@@ -1548,6 +1696,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectUpdate")
set_tests_properties(ExternalProjectUpdateSetup PROPERTIES
+ RUN_SERIAL 1
TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
add_test(NAME ExternalProjectUpdate
@@ -1562,23 +1711,43 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ExternalProjectUpdate")
set_tests_properties(ExternalProjectUpdate PROPERTIES
+ RUN_SERIAL 1
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}
+ function(add_tutorial_test step_name use_mymath)
+ set(tutorial_test_name Tutorial${step_name})
+ set(tutorial_build_dir "${CMake_BINARY_DIR}/Tests/Tutorial/${step_name}")
+ if (use_mymath)
+ set(tutorial_build_options "")
+ else()
+ set(tutorial_test_name ${tutorial_test_name}_MYMATH)
+ set(tutorial_build_dir "${tutorial_build_dir}_MYMATH")
+ set(tutorial_build_options -DUSE_MYMATH:BOOL=OFF)
+ endif()
+ add_test(${tutorial_test_name} ${CMAKE_CTEST_COMMAND}
--build-and-test
- "${CMake_SOURCE_DIR}/Tests/Tutorial/Step${STP}"
- "${CMake_BINARY_DIR}/Tests/Tutorial/Step${STP}"
- --build-two-config
+ "${CMake_SOURCE_DIR}/Tests/Tutorial/${step_name}"
+ ${tutorial_build_dir}_Build
${build_generator_args}
--build-project Tutorial
- --build-options ${build_options}
+ --build-options ${build_options} ${tutorial_build_options}
--test-command Tutorial 25.0)
- endforeach()
- list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Tutorial")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/${tutorial_build_dir}_Build")
+ endfunction()
+
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ foreach(STP RANGE 1 11)
+ add_tutorial_test(Step${STP} TRUE)
+ endforeach()
+ add_tutorial_test(Complete TRUE)
+ foreach(STP RANGE 3 11)
+ add_tutorial_test(Step${STP} FALSE)
+ endforeach()
+ add_tutorial_test(Complete FALSE)
+ endif()
add_test(testing ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE}
--build-and-test
@@ -1763,7 +1932,6 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
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 STREQUAL "GNU"
@@ -1833,6 +2001,11 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
ADD_TEST_MACRO(PrecompiledHeader foo)
endif()
+ set(MSVCRuntimeLibrary_BUILD_OPTIONS -DCMake_TEST_CUDA=${CMake_TEST_CUDA})
+ ADD_TEST_MACRO(MSVCRuntimeLibrary)
+ if(CMAKE_Fortran_COMPILER)
+ ADD_TEST_MACRO(MSVCRuntimeLibrary.Fortran)
+ endif()
endif()
if(MSVC OR
"${CMAKE_GENERATOR}" MATCHES "(MSYS|MinGW) Makefiles")
@@ -1841,7 +2014,8 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
ADD_TEST_MACRO(CheckCompilerRelatedVariables CheckCompilerRelatedVariables)
- if("${CMAKE_GENERATOR}" MATCHES "Makefile")
+ if("${CMAKE_GENERATOR}" MATCHES "Makefile" OR
+ "${CMAKE_GENERATOR}" MATCHES "Ninja")
add_test(MakeClean ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/MakeClean"
@@ -1882,6 +2056,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
message(STATUS
".vcproj file association indicates VCExpress, avoiding MFC test")
set(CTEST_RUN_MFC OFF)
+ elseif( NOT ov )
+ message(STATUS
+ ".vcproj has no file association, avoiding MFC test")
+ set(CTEST_RUN_MFC OFF)
endif()
endif()
@@ -1961,7 +2139,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
if(MSVC AND NOT MSVC_VERSION LESS 1310
- AND (NOT CMAKE_GENERATOR MATCHES "Visual Studio [89]( |$)"
+ AND (NOT CMAKE_GENERATOR MATCHES "Visual Studio 9 "
OR CMAKE_SIZEOF_VOID_P EQUAL 4)
)
ADD_TEST_MACRO(VSMASM VSMASM)
@@ -1972,7 +2150,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
ADD_TEST_MACRO(SBCS SBCS)
endif()
- if(NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio [89]( |$)"
+ if(NOT "${CMAKE_GENERATOR}" MATCHES "Visual Studio 9 "
AND NOT CMAKE_GENERATOR_TOOLSET)
ADD_TEST_MACRO(VSWindowsFormsResx VSWindowsFormsResx)
endif()
@@ -2046,58 +2224,15 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
endif()
- if(WIN32)
- # Macro to search for available Windows CE SDKs in the windows Registry
- macro(select_wince_sdk selected_reg selected_sdk)
- if(CMAKE_HOST_WIN32)
- execute_process(COMMAND reg QUERY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs"
- OUTPUT_VARIABLE sdk_reg
- ERROR_VARIABLE my_err)
- string(REGEX REPLACE "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Wow6432Node\\\\Microsoft\\\\Windows CE Tools\\\\SDKs\\\\" ";" sdk_list "${sdk_reg}")
- list(LENGTH sdk_list sdk_list_len)
- if (${sdk_list_len} GREATER 1)
- list(GET sdk_list 1 _sdk) # The first entry is always empty due to the regex replace above
- string(STRIP ${_sdk} _sdk) # Make sure there is no newline in the SDK name
- endif()
- # Build a key to be used by get_filename_component that is pointing to the SDK directory
- set(_reg "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows CE Tools\\SDKs\\${_sdk}]")
-
- # Set return values
- set(${selected_reg} ${_reg})
- set(${selected_sdk} ${_sdk})
- endif(CMAKE_HOST_WIN32)
- endmacro(select_wince_sdk)
-
- 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_vs14 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]")
- 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_ws10_0 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\Setup\\Build Tools for Windows 10;srcPath]")
- 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]")
- select_wince_sdk(reg_wince wince_sdk)
- set(reg_tegra "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Nsight Tegra;sdkRoot]")
- set(reg_nasm "[HKEY_CURRENT_USER\\SOFTWARE\\nasm]")
- foreach(reg vs10 vs11 vs12 vs14 ws80 ws81 ws10_0 wp80 wp81 wince tegra nasm)
- 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)
+ macro(add_test_VSWinStorePhone name generator systemName systemVersion architecture)
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-generator-platform "${architecture}"
--build-project VSWinStorePhone
--build-config $<CONFIGURATION>
--build-options -DCMAKE_SYSTEM_NAME=${systemName}
@@ -2107,14 +2242,14 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
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)
+ add_test_VSWinStorePhone(vs11-store80-X86 "Visual Studio 11 2012" WindowsStore 8.0 Win32)
+ add_test_VSWinStorePhone(vs11-store80-ARM "Visual Studio 11 2012" WindowsStore 8.0 ARM)
+ add_test_VSWinStorePhone(vs11-store80-X64 "Visual Studio 11 2012" WindowsStore 8.0 x64)
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)
+ add_test_VSWinStorePhone(vs12-store81-X86 "Visual Studio 12 2013" WindowsStore 8.1 Win32)
+ add_test_VSWinStorePhone(vs12-store81-ARM "Visual Studio 12 2013" WindowsStore 8.1 ARM)
+ add_test_VSWinStorePhone(vs12-store81-X64 "Visual Studio 12 2013" WindowsStore 8.1 x64)
add_test(NAME VSXaml COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test
@@ -2127,18 +2262,24 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
-DCMAKE_SYSTEM_VERSION=8.1
)
endif()
+ if(CMake_TEST_VSWinStorePhone_VS_2017 AND ws10_0)
+ add_test_VSWinStorePhone(vs15-store10_0-X86 "Visual Studio 15 2017" WindowsStore 10.0 Win32)
+ add_test_VSWinStorePhone(vs15-store10_0-ARM "Visual Studio 15 2017" WindowsStore 10.0 ARM)
+ add_test_VSWinStorePhone(vs15-store10_0-X64 "Visual Studio 15 2017" WindowsStore 10.0 x64)
+ add_test_VSWinStorePhone(vs15-store10_0-ARM64 "Visual Studio 15 2017" WindowsStore 10.0 ARM64)
+ endif()
if(vs14 AND ws10_0)
- add_test_VSWinStorePhone(vs14-store10_0-X86 "Visual Studio 14 2015" WindowsStore 10.0)
- add_test_VSWinStorePhone(vs14-store10_0-ARM "Visual Studio 14 2015 ARM" WindowsStore 10.0)
- add_test_VSWinStorePhone(vs14-store10_0-X64 "Visual Studio 14 2015 Win64" WindowsStore 10.0)
+ add_test_VSWinStorePhone(vs14-store10_0-X86 "Visual Studio 14 2015" WindowsStore 10.0 Win32)
+ add_test_VSWinStorePhone(vs14-store10_0-ARM "Visual Studio 14 2015" WindowsStore 10.0 ARM)
+ add_test_VSWinStorePhone(vs14-store10_0-X64 "Visual Studio 14 2015" WindowsStore 10.0 x64)
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)
+ add_test_VSWinStorePhone(vs11-phone80-X86 "Visual Studio 11 2012" WindowsPhone 8.0 Win32)
+ add_test_VSWinStorePhone(vs11-phone80-ARM "Visual Studio 11 2012" WindowsPhone 8.0 ARM)
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)
+ add_test_VSWinStorePhone(vs12-phone81-X86 "Visual Studio 12 2013" WindowsPhone 8.1 Win32)
+ add_test_VSWinStorePhone(vs12-phone81-ARM "Visual Studio 12 2013" WindowsPhone 8.1 ARM)
endif()
endif()
@@ -2171,37 +2312,113 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
endif()
endif()
- if(CMAKE_GENERATOR MATCHES "Visual Studio ([^89]|[89][0-9])" AND nasm)
+ if(CMAKE_GENERATOR MATCHES "Visual Studio ([^9]|9[0-9])" AND nasm)
ADD_TEST_MACRO(VSNASM VSNASM)
endif()
if (CMake_TEST_GreenHillsMULTI)
- macro(add_test_GhsMulti name primaryTarget bspName)
- add_test(NAME GhsMulti.${name} COMMAND ${CMAKE_CTEST_COMMAND}
- --build-and-test
- "${CMake_SOURCE_DIR}/Tests/GhsMulti"
- "${CMake_BINARY_DIR}/Tests/GhsMulti/${name}"
- --build-generator "Green Hills MULTI"
- --build-project ReturnNum
- --build-config $<CONFIGURATION>
- --build-options -DGHS_PRIMARY_TARGET=${primaryTarget}
- -DGHS_BSP_NAME=${bspName}
- )
- endmacro ()
- add_test_GhsMulti("arm_integrity_simarm" "arm_integrity.tgt" "simarm")
- add_test_GhsMulti("arm64_integrity_simarm" "arm64_integrity.tgt" "simarm")
- add_test(NAME GhsMulti.duplicate_source_filenames
+ macro(add_test_GhsMulti test_name test_dir bin_sub_dir build_opts)
+ separate_arguments(_ghs_build_opts UNIX_COMMAND ${build_opts})
+ separate_arguments(_ghs_toolset_extra UNIX_COMMAND ${ghs_toolset_extra})
+ if(${ARGC} GREATER 4)
+ set(_ghs_test_command --test-command ${ARGN})
+ endif()
+ if(ghs_config_name STREQUAL "__default__")
+ set(_ghs_test_name "${test_name}")
+ else()
+ set(_ghs_test_name "${ghs_config_name}.${test_name}")
+ endif()
+ add_test(NAME GhsMulti.${_ghs_test_name}
COMMAND ${CMAKE_CTEST_COMMAND}
--build-and-test
- "${CMake_SOURCE_DIR}/Tests/GhsMultiDuplicateSourceFilenames"
- "${CMake_BINARY_DIR}/Tests/GhsMultiDuplicateSourceFilenames"
+ "${CMake_SOURCE_DIR}/Tests/GhsMulti/${test_dir}"
+ "${CMake_BINARY_DIR}/Tests/GhsMulti/${ghs_config_name}/${test_dir}/${bin_sub_dir}"
--build-generator "Green Hills MULTI"
- --build-project ReturnNum
+ --build-project test
--build-config $<CONFIGURATION>
- --build-options -DGHS_PRIMARY_TARGET="arm_integrity.tgt"
- -DGHS_BSP_NAME="simarm"
+ --force-new-ctest-process
+ --build-options ${ghs_target_arch} ${ghs_toolset_name} ${ghs_toolset_root} ${ghs_target_platform}
+ ${ghs_os_root} ${ghs_os_dir} ${ghs_bsp_name} ${_ghs_build_opts} ${_ghs_toolset_extra}
+ ${_ghs_test_command}
)
- endif ()
+ unset(_ghs_build_opts)
+ unset(_ghs_toolset_extra)
+ unset(_ghs_test_command)
+ unset(_ghs_test_name)
+ endmacro()
+ macro(add_test_GhsMulti_rename_install test_name)
+ add_test_GhsMulti( ${test_name} GhsMultiRenameInstall ${test_name}
+ "-DCMAKE_INSTALL_PREFIX=. -DRUN_TEST=${test_name}" ${CMAKE_CMAKE_COMMAND} --build . --target install)
+ endmacro()
+ #unset ghs config variables
+ unset(ghs_config_name)
+ unset(ghs_target_arch)
+ unset(ghs_toolset_root)
+ unset(ghs_toolset_name)
+ unset(ghs_os_root)
+ unset(ghs_os_dir)
+ unset(ghs_target_platform)
+ unset(ghs_bsp_name)
+ unset(ghs_toolset_extra)
+ if(NOT CMake_TEST_GreenHillsMULTI_config)
+ #if list of config settings not defined then just run once as default
+ set(CMake_TEST_GreenHillsMULTI_config "__default__")
+ endif()
+ foreach(ghs_file IN LISTS CMake_TEST_GreenHillsMULTI_config)
+ # source GHS tools config file
+ if(NOT ghs_file STREQUAL "__default__")
+ if(IS_ABSOLUTE ${ghs_file})
+ include(${ghs_file})
+ else()
+ include(${CMAKE_BINARY_DIR}/${ghs_file})
+ endif()
+ endif()
+ if(NOT ghs_config_name)
+ set(ghs_config_name "__default__")
+ endif()
+ # test integrity build
+ if (NOT ghs_skip_integrity AND (NOT ghs_target_platform OR ghs_target_platform MATCHES "integrity"))
+ add_test_GhsMulti(integrityDDInt GhsMultiIntegrity/GhsMultiIntegrityDDInt "" "")
+ add_test_GhsMulti(integrityMonolith GhsMultiIntegrity/GhsMultiIntegrityMonolith "" "")
+ add_test_GhsMulti(integrityDD GhsMultiIntegrity/GhsMultiIntegrityDD "" "")
+ endif()
+ add_test_GhsMulti(duplicate_source_filenames GhsMultiDuplicateSourceFilenames "" "")
+ add_test_GhsMulti_rename_install(SINGLE_EXEC)
+ add_test_GhsMulti_rename_install(SINGLE_EXEC_RENAMED)
+ add_test_GhsMulti_rename_install(EXEC_AND_LIB)
+ add_test_GhsMulti(multiple_source_groups GhsMultiSrcGroups Default "")
+ add_test_GhsMulti(multiple_source_groups_folders GhsMultiSrcGroups PropFolders "-DTEST_PROP=ON")
+ add_test_GhsMulti(multiple_source_groups_all_folders GhsMultiSrcGroups AllFolders "-DCMAKE_GHS_NO_SOURCE_GROUP_FILE=ON")
+ add_test_GhsMulti(unsupported_targets GhsMultiUnsupportedTargets "" "")
+ add_test_GhsMulti(object_library GhsMultiObjectLibrary "" "")
+ add_test_GhsMulti(exclude GhsMultiExclude "" ""
+ ${CMAKE_CMAKE_COMMAND} -P ${CMake_SOURCE_DIR}/Tests/GhsMulti/GhsMultiExclude/verify.cmake)
+ add_test_GhsMulti(interface GhsMultiInterface "" "")
+ add_test_GhsMulti(transitive_link_test GhsMultiLinkTest TransitiveLink "-DRUN_TEST=NO_FLAGS")
+ add_test_GhsMulti(flags_link_test GhsMultiLinkTest FlagsCheck "-DRUN_TEST=CHECK_FLAGS")
+ add_test_GhsMulti(sub_link_test GhsMultiLinkTestSub "" "")
+ add_test_GhsMulti(multiple_projects GhsMultiMultipleProjects "" ""
+ ${CMAKE_CMAKE_COMMAND} -P ${CMake_SOURCE_DIR}/Tests/GhsMulti/GhsMultiMultipleProjects/verify.cmake)
+ add_test_GhsMulti(compiler_options_none GhsMultiCompilerOptions None "-DRUN_TEST=RELEASE_FLAGS -DRUN_TEST_BUILD_TYPE=\"\"")
+ add_test_GhsMulti(compiler_options_kernel GhsMultiCompilerOptions Kernel "-DRUN_TEST=KERNEL_FLAGS -DRUN_TEST_BUILD_TYPE=DEBUG")
+ add_test_GhsMulti(try_compile_copy GhsMultiCopyFile "" "")
+ add_test_GhsMulti(ghs_platform GhsMultiPlatform "" "")
+ add_test_GhsMulti(custom_target GhsMultiCustomTarget "" "")
+ add_test_GhsMulti(dep_order GhsMultiDepOrder "" "")
+ add_test_GhsMulti(external_project GhsMultiExternalProject "" "")
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/GhsMulti/${ghs_config_name}")
+ #unset ghs config variables
+ unset(ghs_config_name)
+ unset(ghs_target_arch)
+ unset(ghs_toolset_root)
+ unset(ghs_toolset_name)
+ unset(ghs_os_root)
+ unset(ghs_os_dir)
+ unset(ghs_target_platform)
+ unset(ghs_bsp_name)
+ unset(ghs_toolset_extra)
+ endforeach()
+ endif()
if(tegra AND NOT "${CMake_SOURCE_DIR};${CMake_BINARY_DIR}" MATCHES " ")
macro(add_test_VSNsightTegra name generator)
@@ -2315,24 +2532,17 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
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(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")
add_test(WarnUnusedCliUsed ${CMAKE_CTEST_COMMAND}
--build-and-test
@@ -2617,12 +2827,12 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
file(COPY "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/VistA-FOIA"
DESTINATION "${CMake_BINARY_DIR}/Testing/MumpsCoverage")
add_test(NAME CTestGTMCoverage
- COMMAND cmake -E chdir
+ COMMAND ${CMAKE_CMAKE_COMMAND} -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*"
+ "Process file.*ZZCOVTST.m.*Total LOC:.*32.*Percentage Coverage: 81.25*"
ENVIRONMENT COVFILE=)
configure_file(
@@ -2635,12 +2845,12 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
file(COPY "${CMake_SOURCE_DIR}/Tests/MumpsCoverage/VistA-FOIA"
DESTINATION "${CMake_BINARY_DIR}/Testing/MumpsCacheCoverage")
add_test(NAME CTestCacheCoverage
- COMMAND cmake -E chdir
+ COMMAND ${CMAKE_CMAKE_COMMAND} -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.*"
+ "Process file.*ZZCOVTST.m.*Total LOC:.*32.*Percentage Coverage: 87.50.*"
ENVIRONMENT COVFILE=)
# Adding a test case for Python Coverage
@@ -2653,7 +2863,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
file(COPY "${CMake_SOURCE_DIR}/Tests/PythonCoverage/coveragetest"
DESTINATION "${CMake_BINARY_DIR}/Testing/PythonCoverage")
add_test(NAME CTestPythonCoverage
- COMMAND cmake -E chdir
+ COMMAND ${CMAKE_CMAKE_COMMAND} -E chdir
${CMake_BINARY_DIR}/Testing/PythonCoverage
$<TARGET_FILE:ctest> -T Coverage --debug)
set_tests_properties(CTestPythonCoverage PROPERTIES
@@ -2671,7 +2881,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
file(COPY "${CMake_SOURCE_DIR}/Tests/CoberturaCoverage/src"
DESTINATION "${CMake_BINARY_DIR}/Testing/CoberturaCoverage")
add_test(NAME CTestCoberturaCoverage
- COMMAND cmake -E chdir
+ COMMAND ${CMAKE_CMAKE_COMMAND} -E chdir
${CMake_BINARY_DIR}/Testing/CoberturaCoverage
$<TARGET_FILE:ctest> -T Coverage --debug)
set_tests_properties(CTestCoberturaCoverage PROPERTIES
@@ -2690,7 +2900,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
configure_file("${CMake_BINARY_DIR}/Testing/JacocoCoverage/Coverage/target/site/jacoco.xml.in"
"${CMake_BINARY_DIR}/Testing/JacocoCoverage/Coverage/target/site/jacoco.xml")
add_test(NAME CTestJacocoCoverage
- COMMAND cmake -E chdir
+ COMMAND ${CMAKE_CMAKE_COMMAND} -E chdir
${CMake_BINARY_DIR}/Testing/JacocoCoverage
$<TARGET_FILE:ctest> -T Coverage --debug)
set_tests_properties(CTestJacocoCoverage PROPERTIES
@@ -2709,7 +2919,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
DESTINATION "${CMake_BINARY_DIR}/Testing/JavascriptCoverage"
FILES_MATCHING PATTERN "*.js")
add_test(NAME CTestJavascriptCoverage
- COMMAND cmake -E chdir
+ COMMAND ${CMAKE_CMAKE_COMMAND} -E chdir
${CMake_BINARY_DIR}/Testing/JavascriptCoverage
$<TARGET_FILE:ctest> -T Coverage --debug)
set_tests_properties(CTestJavascriptCoverage PROPERTIES
@@ -2727,7 +2937,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
"${CMake_SOURCE_DIR}/Tests/DelphiCoverage/UTCovTest(UTCovTest.pas).html.in"
"${CMake_BINARY_DIR}/Testing/DelphiCoverage/UTCovTest(UTCovTest.pas).html")
add_test(NAME CTestDelphiCoverage
- COMMAND cmake -E chdir
+ COMMAND ${CMAKE_CMAKE_COMMAND} -E chdir
${CMake_BINARY_DIR}/Testing/DelphiCoverage
$<TARGET_FILE:ctest> -T Coverage --debug)
set_tests_properties(CTestDelphiCoverage PROPERTIES
@@ -2779,19 +2989,24 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
--output-log "${CMake_BINARY_DIR}/Tests/CTestConfig/ScriptWithArgs.log"
)
+ ADD_TEST_MACRO(CMakeCommands.add_compile_definitions add_compile_definitions)
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)
+ ADD_TEST_MACRO(CMakeCommands.target_sources target_sources)
- if(CMake_TEST_SERVER_MODE)
- # The cmake server-mode test requires python for a simple client.
- find_package(PythonInterp QUIET)
- if(PYTHON_EXECUTABLE)
- set(Server_BUILD_OPTIONS -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE})
- ADD_TEST_MACRO(Server Server)
- endif()
+ ADD_TEST_MACRO(CMakeCommands.add_link_options)
+ ADD_TEST_MACRO(CMakeCommands.target_link_options)
+ ADD_TEST_MACRO(CMakeCommands.link_directories)
+ ADD_TEST_MACRO(CMakeCommands.target_link_directories)
+
+ # The cmake server-mode test requires python for a simple client.
+ find_package(PythonInterp QUIET)
+ if(PYTHON_EXECUTABLE)
+ set(Server_BUILD_OPTIONS -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE})
+ ADD_TEST_MACRO(Server Server)
endif()
configure_file(
@@ -2808,7 +3023,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
PASS_REGULAR_EXPRESSION "Failed")
else()
set_tests_properties(CTestTestCrash PROPERTIES
- PASS_REGULAR_EXPRESSION "(Illegal|SegFault)")
+ PASS_REGULAR_EXPRESSION "(Illegal|SegFault|Child aborted)")
endif()
configure_file(
@@ -3035,8 +3250,6 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
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"
@@ -3071,12 +3284,14 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
--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(NOT CMake_TEST_EXTERNAL_CMAKE)
+ 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"
+ )
+ endif()
if("${CMAKE_GENERATOR}" MATCHES "Makefiles" OR "${CMAKE_GENERATOR}" MATCHES "Ninja")
configure_file("${CMake_SOURCE_DIR}/Tests/CTestTestLaunchers/test.cmake.in"
@@ -3108,11 +3323,13 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
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 ()
+ if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ get_test_property(CTestTest2 TIMEOUT PREVIOUS_TIMEOUT)
+ if("${PREVIOUS_TIMEOUT}" MATCHES NOTFOUND)
+ set_tests_properties ( CTestTest2
+ PROPERTIES TIMEOUT ${CMAKE_LONG_TEST_TIMEOUT})
+ endif()
+ endif()
endif ()
if(CMake_TEST_EXTERNAL_CMAKE)
@@ -3176,6 +3393,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
--build-options ${build_options}
-DCMake_TEST_NESTED_MAKE_PROGRAM:FILEPATH=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
-DCMake_TEST_Fortran_SUBMODULES:BOOL=${CMake_TEST_Fortran_SUBMODULES}
+ ${CMake_TEST_FortranModules_BUILD_OPTIONS}
)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/FortranModules")
endif()
@@ -3239,37 +3457,71 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
--build-options ${build_options}
--test-command ${JAVA_RUNTIME} -classpath hello2.jar HelloWorld)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJarSourceList")
+ add_test(Java.JarSourceListAndOutput ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/Java"
+ "${CMake_BINARY_DIR}/Tests/JavaJarSourceListAndOutput"
+ ${build_generator_args}
+ --build-project hello
+ --build-target hello3
+ --build-two-config
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJarSourceListAndOutput/hello3"
+ --build-options ${build_options}
+ --test-command ${JAVA_RUNTIME} -classpath hello3.jar HelloWorld)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJarSourceListAndOutput")
- # For next test, java tool must have same architecture as toolchain
+ # For next tests, java tool must have same architecture as toolchain
math(EXPR _object_mode "${CMAKE_SIZEOF_VOID_P} * 8")
execute_process(
COMMAND "${Java_JAVA_EXECUTABLE}" -d${_object_mode} -version
OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE _result
)
if(_result EQUAL 0)
- if(CMAKE_CONFIGURATION_TYPES)
- set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah/$<CONFIGURATION>)
- else()
- set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah)
+ ## next test is valid only if Java version is less than 1.10
+ if ("${Java_VERSION}" VERSION_LESS 1.10)
+ if(_isMultiConfig)
+ set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah/$<CONFIGURATION>)
+ else()
+ set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah)
+ endif()
+ add_test(NAME Java.Javah COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/JavaJavah"
+ "${CMake_BINARY_DIR}/Tests/JavaJavah"
+ ${build_generator_args}
+ --build-project helloJavah
+ --build-two-config
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJavah/"
+ --build-options ${build_options}
+ --test-command ${JAVA_RUNTIME} -Djava.library.path=${JAVAH_LIBRARY_PATH} -classpath hello3.jar HelloWorld2)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJavah")
+ endif()
+ ## next test is valid only if Java is, at least, version 1.8
+ if (NOT "${Java_VERSION}" VERSION_LESS 1.8)
+ if(_isMultiConfig)
+ set (JAVANATIVEHEADERS_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaNativeHeaders/$<CONFIGURATION>)
+ else()
+ set (JAVANATIVEHEADERS_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaNativeHeaders)
+ endif()
+ add_test(NAME Java.NativeHeaders COMMAND ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/JavaNativeHeaders"
+ "${CMake_BINARY_DIR}/Tests/JavaNativeHeaders"
+ ${build_generator_args}
+ --build-project helloJavaNativeHeaders
+ --build-two-config
+ --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaNativeHeaders/"
+ --build-options ${build_options}
+ --test-command ${JAVA_RUNTIME} -Djava.library.path=${JAVANATIVEHEADERS_LIBRARY_PATH} -classpath hello4.jar HelloWorld3)
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaNativeHeaders")
endif()
- add_test(NAME Java.Javah COMMAND ${CMAKE_CTEST_COMMAND}
- --build-and-test
- "${CMake_SOURCE_DIR}/Tests/JavaJavah"
- "${CMake_BINARY_DIR}/Tests/JavaJavah"
- ${build_generator_args}
- --build-project helloJavah
- --build-two-config
- --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJavah/"
- --build-options ${build_options}
- --test-command ${JAVA_RUNTIME} -Djava.library.path=${JAVAH_LIBRARY_PATH} -classpath hello3.jar HelloWorld2)
- list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJavah")
endif()
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(CMAKE_GENERATOR MATCHES "Makefiles")
# if sdcc is found, build the SimpleCOnly project with sdcc
find_program(SDCC_EXECUTABLE sdcc)
@@ -3348,35 +3600,31 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
)
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)
+ # Define a set of "contract" tests, each activated by a cache entry
+ # named "CMake_TEST_CONTRACT_<project>". For each Contract test,
+ # the project should provide a directory with a CMakeLists.txt file
+ # that uses ExternalProject to download and configure the project.
+ # The directory should also contain a Configure.cmake file that
+ # sets "CMake_TEST_CONTRACT_<project>_<var>" variables to configure
+ # the code below.
+ foreach(project
+ PLplot
+ Trilinos
+ VTK
+ )
+ if(CMake_TEST_CONTRACT_${project})
+ include(Contracts/${project}/Configure.cmake)
+ ADD_TEST_MACRO(Contracts.${project} ${CMake_TEST_CONTRACT_${project}_RUN_TEST})
+ # The external projects may take a long time to build.
+ if(DEFINED CMake_TEST_CONTRACT_${project}_TIMEOUT)
+ set(timeout ${CMake_TEST_CONTRACT_${project}_TIMEOUT})
+ elseif(CMake_TEST_CONTRACT_DEFAULT_TIMEOUT)
+ set(timeout ${CMake_TEST_CONTRACT_DEFAULT_TIMEOUT})
+ else()
+ set(timeout 21600)
+ endif()
+ set_property(TEST Contracts.${project} PROPERTY TIMEOUT "${timeout}")
endif()
- set_tests_properties(Contracts.${project} PROPERTIES TIMEOUT ${timeout})
endforeach()
if(TEST_CompileCommandOutput)
@@ -3397,6 +3645,24 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
--test-command IncludeDirectories)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/IncludeDirectories")
+ if(CMAKE_GENERATOR MATCHES "^((Unix|MSYS) Makefiles|Ninja)$" AND
+ ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")))
+ add_test(IncludeDirectoriesCPATH ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/IncludeDirectoriesCPATH"
+ "${CMake_BINARY_DIR}/Tests/IncludeDirectoriesCPATH"
+ --build-two-config
+ ${build_generator_args}
+ --build-project IncludeDirectoriesCPATH
+ --build-options ${build_options})
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/IncludeDirectoriesCPATH")
+ set_tests_properties(IncludeDirectoriesCPATH
+ PROPERTIES
+ ENVIRONMENT "CPATH=${CMAKE_CURRENT_SOURCE_DIR}/IncludeDirectoriesCPATH/viacpath")
+ endif()
+
add_test(InterfaceLinkLibraries ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/InterfaceLinkLibraries"
diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
index 443d366c4..a53e4418b 100644
--- a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
+++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
@@ -86,7 +86,7 @@ foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HG
endforeach()
foreach(VTEST BISON Boost CUDA DOXYGEN FLEX GIF GTK2
- HDF5 LibArchive OPENSCENEGRAPH RUBY SWIG Protobuf)
+ HDF5 JPEG LibArchive OPENSCENEGRAPH RUBY SWIG Protobuf)
check_version_string(${VTEST} ${VTEST}_VERSION)
endforeach()
diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt
index c84fa748c..1aeab8b39 100644
--- a/Tests/CMakeOnly/CMakeLists.txt
+++ b/Tests/CMakeOnly/CMakeLists.txt
@@ -33,7 +33,7 @@ add_CMakeOnly_test(CompilerIdCXX)
if(CMAKE_Fortran_COMPILER)
add_CMakeOnly_test(CompilerIdFortran)
endif()
-if(CMAKE_GENERATOR MATCHES "Visual Studio ([^89]|[89][0-9])")
+if(CMAKE_GENERATOR MATCHES "Visual Studio ([^9]|9[0-9])")
add_CMakeOnly_test(CompilerIdCSharp)
endif()
@@ -56,7 +56,19 @@ add_test(CMakeOnly.ProjectInclude ${CMAKE_CMAKE_COMMAND}
-P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
)
-include(${CMAKE_SOURCE_DIR}/Modules/CMakeParseArguments.cmake)
+add_test(CMakeOnly.ProjectIncludeAny ${CMAKE_CMAKE_COMMAND}
+ -DTEST=ProjectIncludeAny
+ -DCMAKE_ARGS=-DCMAKE_PROJECT_INCLUDE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectInclude/include.cmake
+ -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
+ )
+
+add_test(CMakeOnly.ProjectIncludeBefore ${CMAKE_CMAKE_COMMAND}
+ -DTEST=ProjectIncludeBefore
+ -DCMAKE_ARGS=-DCMAKE_PROJECT_INCLUDE_BEFORE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectIncludeBefore/include.cmake
+ -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake
+ )
+
+include(CMakeParseArguments)
function(add_major_test module)
cmake_parse_arguments(MAJOR_TEST "NOLANG" "VERSION_VAR" "VERSIONS" ${ARGN})
diff --git a/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt
index 9be69f128..1f9d3acb7 100644
--- a/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt
+++ b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt
@@ -57,7 +57,7 @@ else()
message("Unhandled Platform")
endif()
-if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
check_cxx_compiler_flag("-x c++" HAVE_X_CXX)
if(NOT HAVE_X_CXX)
message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++' check failed")
diff --git a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
index f5336dc03..ca4becb77 100644
--- a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
+++ b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt
@@ -7,7 +7,8 @@ set(expect_C 1)
set(expect_CXX 1)
unset(expect_Fortran)
set(expect_NoSuchLanguage 0)
-foreach(lang C CXX Fortran NoSuchLanguage)
+
+foreach(lang C CXX Fortran CUDA NoSuchLanguage)
check_language(${lang})
if(NOT DEFINED CMAKE_${lang}_COMPILER)
message(FATAL_ERROR "check_language(${lang}) did not set result")
diff --git a/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt b/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt
index a9abb4ad7..ffce488f4 100644
--- a/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt
+++ b/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt
@@ -1,4 +1,4 @@
-project(ProjectInclude)
+project(ProjectInclude LANGUAGES NONE)
if(NOT AUTO_INCLUDE)
message(FATAL_ERROR "include file not found")
endif()
diff --git a/Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt b/Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt
index 6d1628ae5..3676b1792 100644
--- a/Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt
+++ b/Tests/CMakeOnly/SelectLibraryConfigurations/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.9)
project(SelectLibraryConfigurations NONE)
@@ -15,7 +15,8 @@ macro(check_slc basename expect)
endif ()
endmacro(check_slc)
-if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if (NOT _isMultiConfig AND NOT CMAKE_BUILD_TYPE)
set(NOTYPE_RELONLY_LIBRARY_RELEASE "opt")
check_slc(NOTYPE_RELONLY "opt")
diff --git a/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in b/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in
index 3294a2f0d..a3c2b055a 100644
--- a/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in
+++ b/Tests/CMakeTests/CMakeHostSystemInformationTest.cmake.in
@@ -22,6 +22,25 @@ try_and_print(TOTAL_VIRTUAL_MEMORY)
try_and_print(AVAILABLE_VIRTUAL_MEMORY)
try_and_print(TOTAL_PHYSICAL_MEMORY)
try_and_print(AVAILABLE_PHYSICAL_MEMORY)
+try_and_print(IS_64BIT)
+try_and_print(HAS_FPU)
+try_and_print(HAS_MMX)
+try_and_print(HAS_MMX_PLUS)
+try_and_print(HAS_SSE)
+try_and_print(HAS_SSE2)
+try_and_print(HAS_SSE_FP)
+try_and_print(HAS_SSE_MMX)
+try_and_print(HAS_AMD_3DNOW)
+try_and_print(HAS_AMD_3DNOW_PLUS)
+try_and_print(HAS_IA64)
+try_and_print(HAS_SERIAL_NUMBER)
+try_and_print(PROCESSOR_SERIAL_NUMBER)
+try_and_print(PROCESSOR_NAME)
+try_and_print(PROCESSOR_DESCRIPTION)
+try_and_print(OS_NAME)
+try_and_print(OS_RELEASE)
+try_and_print(OS_VERSION)
+try_and_print(OS_PLATFORM)
include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
diff --git a/Tests/CMakeTests/CheckSourceTreeTest.cmake.in b/Tests/CMakeTests/CheckSourceTreeTest.cmake.in
index 8145db7cb..4f2aaea9c 100644
--- a/Tests/CMakeTests/CheckSourceTreeTest.cmake.in
+++ b/Tests/CMakeTests/CheckSourceTreeTest.cmake.in
@@ -308,13 +308,11 @@ 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("")
@@ -341,7 +339,7 @@ endif()
# Not even developers.
#
if(nonadditions)
- if(in_source_build AND is_dashboard)
+ if(in_source_build)
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
diff --git a/Tests/CMakeTests/FileDownloadInput.png b/Tests/CMakeTests/FileDownloadInput.png
index 7bbcee413..9ab565a1b 100644
--- a/Tests/CMakeTests/FileDownloadInput.png
+++ b/Tests/CMakeTests/FileDownloadInput.png
Binary files differ
diff --git a/Tests/CMakeTests/FileDownloadTest.cmake.in b/Tests/CMakeTests/FileDownloadTest.cmake.in
index f6d9ad99b..39354490b 100644
--- a/Tests/CMakeTests/FileDownloadTest.cmake.in
+++ b/Tests/CMakeTests/FileDownloadTest.cmake.in
@@ -32,7 +32,7 @@ file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
- EXPECTED_MD5 d16778650db435bda3a8c3435c3ff5d1
+ EXPECTED_MD5 dbd330d52f4dbd60115d4191904ded92
)
message(STATUS "FileDownload:4")
@@ -41,7 +41,7 @@ file(DOWNLOAD
${dir}/file3.png
TIMEOUT 2
STATUS status
- EXPECTED_HASH SHA1=50c614fc28b39c1281d0517bb6d5858b4359c9b7
+ EXPECTED_HASH SHA1=67eee17f79d9ac557284fc0b8ad19f25723fb578
)
message(STATUS "FileDownload:5")
@@ -50,7 +50,7 @@ file(DOWNLOAD
${dir}/file3.png
TIMEOUT 2
STATUS status
- EXPECTED_HASH SHA224=73cd5f442b04e8320e4f907f8e1b21d4befff98b5bd77bc32526ea68
+ EXPECTED_HASH SHA224=ba283726bbb602776818b463943189afd91836cb7ee5dd6e2c7b5ae4
)
message(STATUS "FileDownload:6")
@@ -59,7 +59,7 @@ file(DOWNLOAD
${dir}/file3.png
TIMEOUT 2
STATUS status
- EXPECTED_HASH SHA256=2e067f6c09cbc7cd619c8fbcc44eb64cd6b45a95e4cddb3a585eee1f731c4da9
+ EXPECTED_HASH SHA256=cf3334b1275071e1da6e8c396ccb72cf1b2388d8c937526f3af26230affb9423
)
message(STATUS "FileDownload:7")
@@ -68,7 +68,7 @@ file(DOWNLOAD
${dir}/file3.png
TIMEOUT 2
STATUS status
- EXPECTED_HASH SHA384=398bf41902a7251c30e522b307e3e41e3fb617c765b3feaa99b2f7d063894708ad399267ccc25d877437a10e5e890d35
+ EXPECTED_HASH SHA384=43a5d13978d97c660db44481aee0604cb4ff6ca0775cd5c2cd68cd8000e107e507c4caf6c228941231041e282ffb8950
)
message(STATUS "FileDownload:8")
@@ -77,7 +77,7 @@ file(DOWNLOAD
${dir}/file3.png
TIMEOUT 2
STATUS status
- EXPECTED_HASH SHA512=c51854d21052713968b849c2b4263cf54be03bc3a7e9847a6c71c6c8d1d13cd805fe1b9fa95f9ba1d0a5631513974f6fae21e34ab5b171d94bad48df5f073e48
+ EXPECTED_HASH SHA512=6984e0909a1018030ccaa418e3be1654223cdccff0fe6adc745f9aea7e377f178be53b9fc7d54a6f81c2b62ef9ddcd38ba1978fedf4c5e7139baaf355eefad5b
)
message(STATUS "FileDownload:9")
file(DOWNLOAD
@@ -85,7 +85,7 @@ file(DOWNLOAD
${dir}/file3.png
TIMEOUT 2
STATUS status
- EXPECTED_HASH MD5=d16778650db435bda3a8c3435c3ff5d1
+ EXPECTED_HASH MD5=dbd330d52f4dbd60115d4191904ded92
)
message(STATUS "FileDownload:10")
@@ -94,7 +94,7 @@ file(DOWNLOAD
${dir}/file3.png
TIMEOUT 2
STATUS status
- EXPECTED_MD5 d16778650db435bda3a8c3435c3ff5d1
+ EXPECTED_MD5 dbd330d52f4dbd60115d4191904ded92
)
message(STATUS "${status}")
diff --git a/Tests/CMakeTests/FileUploadTest.cmake.in b/Tests/CMakeTests/FileUploadTest.cmake.in
index 9e2290988..0e6f08048 100644
--- a/Tests/CMakeTests/FileUploadTest.cmake.in
+++ b/Tests/CMakeTests/FileUploadTest.cmake.in
@@ -35,7 +35,7 @@ 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$")
+if(NOT sum1 MATCHES "^dbd330d52f4dbd60115d4191904ded92 .*/uploads/file1.png$")
message(FATAL_ERROR "file1.png did not upload correctly (sum1='${sum1}')")
endif()
@@ -43,7 +43,7 @@ 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$")
+if(NOT sum2 MATCHES "^dbd330d52f4dbd60115d4191904ded92 .*/uploads/file2.png$")
message(FATAL_ERROR "file2.png did not upload correctly (sum2='${sum2}')")
endif()
diff --git a/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in b/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in
index d7d881e79..f01e616f0 100644
--- a/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in
+++ b/Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in
@@ -349,6 +349,12 @@ 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)
+# g++ dummy.c -v
+set(aix_g++_text " /prefix/libexec/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/collect2 -bpT:0x10000000 -bpD:0x20000000 -btextro /lib/crt0.o /prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/crtcxa.o /prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/crtdbase.o -L/prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0 -L/prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/../../.. /tmp//ccKROJ1f.o -lstdc++ -lm -lgcc_s /prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/libgcc.a -lc -lgcc_s /prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/libgcc.a")
+set(aix_g++_libs "stdc++;m;gcc_s;/prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/libgcc.a;c;gcc_s;/prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0/libgcc.a")
+set(aix_g++_dirs "/prefix/lib/gcc/powerpc-ibm-aix7.2.0.0/7.2.0;/prefix/lib")
+list(APPEND platforms aix_g++)
+
#-----------------------------------------------------------------------------
# HP
@@ -409,78 +415,6 @@ 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
@@ -525,6 +459,27 @@ set(msys_g77_dirs "C:/some-mingw/lib/gcc/mingw32/3.4.5;C:/some-mingw/lib/gcc;/so
list(APPEND platforms msys_g77)
#-----------------------------------------------------------------------------
+# MSYS2
+
+# gcc dummy.c -v
+set(msys2_gcc_text " C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/liblto_plugin-0.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:/msys64/tmp/ccikz9Wf.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/crtbegin.o -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../.. C:/msys64/tmp/ccK0dTUv.o -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/crtend.o")
+set(msys2_gcc_libs "mingw32;gcc;moldname;mingwex;pthread;advapi32;shell32;user32;kernel32;mingw32;gcc;moldname;mingwex")
+set(msys2_gcc_dirs "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0;C:/msys64/mingw64/lib/gcc;C:/msys64/mingw64/x86_64-w64-mingw32/lib;C:/msys64/mingw64/lib")
+list(APPEND platforms msys2_gcc)
+
+# g++ dummy.cxx -v
+set(msys2_g++_text " C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/liblto_plugin-0.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:/msys64/tmp/ccJQgvbN.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/crtbegin.o -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../.. C:/msys64/tmp/ccqPpuVS.o -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/crtend.o")
+set(msys2_g++_libs "stdc++;mingw32;gcc_s;gcc;moldname;mingwex;pthread;advapi32;shell32;user32;kernel32;mingw32;gcc_s;gcc;moldname;mingwex")
+set(msys2_g++_dirs "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0;C:/msys64/mingw64/lib/gcc;C:/msys64/mingw64/x86_64-w64-mingw32/lib;C:/msys64/mingw64/lib")
+list(APPEND platforms msys2_g++)
+
+# gfortran dummy.f90 -v
+set(msys2_gfortran_text " C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/liblto_plugin-0.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:/msys64/tmp/cczOKIDy.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/crtbegin.o -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../.. C:/msys64/tmp/ccyXuCgD.o -lgfortran -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lquadmath -lm -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/lib/../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/crtend.o")
+set(msys2_gfortran_libs "gfortran;mingw32;gcc_s;gcc;moldname;mingwex;quadmath;m;mingw32;gcc_s;gcc;moldname;mingwex;pthread;advapi32;shell32;user32;kernel32;mingw32;gcc_s;gcc;moldname;mingwex")
+set(msys2_gfortran_dirs "C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0;C:/msys64/mingw64/lib/gcc;C:/msys64/mingw64/x86_64-w64-mingw32/lib;C:/msys64/mingw64/lib")
+list(APPEND platforms msys2_gfortran)
+
+#-----------------------------------------------------------------------------
# MSVC from NVIDIA CUDA
set(nvcc_msvc_text [[cuda-fake-ld cl.exe -nologo "tmp/a_dlink.obj" "tmp/CMakeCUDACompilerId.obj" -link -INCREMENTAL:NO "/LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/bin/../lib/x64" cudadevrt.lib cudart_static.lib -Fe"a.exe"]])
@@ -532,7 +487,6 @@ set(nvcc_msvc_libs "cudadevrt.lib;cudart_static.lib")
set(nvcc_msvc_dirs "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64")
list(APPEND platforms nvcc_msvc)
-
#-----------------------------------------------------------------------------
# PGI on Windows
diff --git a/Tests/CMakeTests/ListTest.cmake.in b/Tests/CMakeTests/ListTest.cmake.in
index 76f5e4f6a..f517e64a6 100644
--- a/Tests/CMakeTests/ListTest.cmake.in
+++ b/Tests/CMakeTests/ListTest.cmake.in
@@ -53,6 +53,10 @@ set(result andy brad)
list(INSERT result -1 bill ken)
TEST("INSERT result -1 bill ken" "andy;bill;ken;brad")
+set(result andy brad)
+list(INSERT result 2 bill ken)
+TEST("INSERT result 2 bill ken" "andy;brad;bill;ken")
+
set(result andy bill brad ken bob)
list(REMOVE_ITEM result bob)
TEST("REMOVE_ITEM result bob" "andy;bill;brad;ken")
diff --git a/Tests/CMakeTests/PushCheckStateTest.cmake.in b/Tests/CMakeTests/PushCheckStateTest.cmake.in
index b4c48f4f4..cbd879def 100644
--- a/Tests/CMakeTests/PushCheckStateTest.cmake.in
+++ b/Tests/CMakeTests/PushCheckStateTest.cmake.in
@@ -1,3 +1,4 @@
+cmake_minimum_required(VERSION 3.8)
include(CMakePushCheckState)
set(CMAKE_EXTRA_INCLUDE_FILES file1)
@@ -26,6 +27,27 @@ set(CMAKE_REQUIRED_LIBRARIES lib3)
set(CMAKE_REQUIRED_FLAGS flag3)
set(CMAKE_REQUIRED_QUIET 3)
+cmake_push_check_state(RESET)
+
+foreach(pair IN ITEMS
+ EXTRA_INCLUDE_FILES|
+ REQUIRED_INCLUDES|
+ REQUIRED_DEFINITIONS|
+ REQUIRED_LIBRARIES|
+ REQUIRED_FLAGS|
+ REQUIRED_QUIET|
+ )
+ string(REPLACE "|" ";" pair "${pair}")
+ list(GET pair 0 var)
+ list(GET pair 1 expected)
+ if (NOT "${CMAKE_${var}}" STREQUAL "${expected}")
+ set(fatal TRUE)
+ message("ERROR: CMAKE_${var} is \"${CMAKE_${var}}\" (expected \"${expected}\")" )
+ endif()
+endforeach()
+
+cmake_pop_check_state()
+
cmake_pop_check_state()
foreach(pair IN ITEMS
diff --git a/Tests/CMakeTests/String-TIMESTAMP-UnixTime.cmake b/Tests/CMakeTests/String-TIMESTAMP-UnixTime.cmake
index a93e7f546..43c93848e 100644
--- a/Tests/CMakeTests/String-TIMESTAMP-UnixTime.cmake
+++ b/Tests/CMakeTests/String-TIMESTAMP-UnixTime.cmake
@@ -11,12 +11,12 @@ string(TIMESTAMP days "%j" UTC)
# see if we are somewhere in the right region.
math(EXPR years_since_epoch "${year} - 1970")
-math(EXPR lower_bound "((${years_since_epoch} * 365) + ${days}) * 86400")
+math(EXPR lower_bound "((${years_since_epoch} * 365) + ${days} - 1) * 86400")
math(EXPR upper_bound "((${years_since_epoch} * 366) + ${days}) * 86400")
-if(unix_time GREATER lower_bound AND unix_time LESS upper_bound)
+if(unix_time GREATER_EQUAL lower_bound AND unix_time LESS upper_bound)
message("~${unix_time}~")
else()
- message(FATAL_ERROR "${timestamp} unix time not in expected range [${lower_bound}, ${upper_bound}]")
+ message(FATAL_ERROR "${timestamp} unix time not in expected range [${lower_bound}, ${upper_bound})")
endif()
diff --git a/Tests/CMakeTests/StringTest.cmake.in b/Tests/CMakeTests/StringTest.cmake.in
index 83655dae5..154afa7f8 100644
--- a/Tests/CMakeTests/StringTest.cmake.in
+++ b/Tests/CMakeTests/StringTest.cmake.in
@@ -47,7 +47,7 @@ set(TIMESTAMP-AllSpecifiers-STDERR "~[0-9]+(;[0-9]+)*~")
set(TIMESTAMP-MonthWeekNames-RESULT 0)
set(TIMESTAMP-MonthWeekNames-STDERR "~[^%]+;[^%]+~")
set(TIMESTAMP-UnixTime-RESULT 0)
-set(TIMESTAMP-UnixTime-STDERR "~[1-9][0-9]+~")
+set(TIMESTAMP-UnixTime-STDERR "~[0-9]+~")
include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake")
check_cmake_test(String
@@ -81,7 +81,7 @@ check_cmake_test(String
# Execute each test listed in StringTestScript.cmake:
#
set(scriptname "@CMAKE_CURRENT_SOURCE_DIR@/StringTestScript.cmake")
-set(number_of_tests_expected 70)
+set(number_of_tests_expected 74)
include("@CMAKE_CURRENT_SOURCE_DIR@/ExecuteScriptTests.cmake")
execute_all_script_tests(${scriptname} number_of_tests_executed)
diff --git a/Tests/CMakeTests/StringTestScript.cmake b/Tests/CMakeTests/StringTestScript.cmake
index 44d56531f..e069897b6 100644
--- a/Tests/CMakeTests/StringTestScript.cmake
+++ b/Tests/CMakeTests/StringTestScript.cmake
@@ -1,5 +1,18 @@
message(STATUS "testname='${testname}'")
+function(test_configure_line_number EXPRESSION POLICY)
+ cmake_policy(PUSH)
+ cmake_policy(SET CMP0053 ${POLICY})
+ string(CONFIGURE
+ "${EXPRESSION}" v) # line should indicate string() call
+ math(EXPR vplus3 "${v} + 3")
+ if(NOT ${CMAKE_CURRENT_LIST_LINE} EQUAL ${vplus3})
+ message(SEND_ERROR "Couldn't configure CMAKE_CURRENT_LIST_LINE, evaluated into '${v}'")
+ endif()
+ message(STATUS "v='${v}'")
+ cmake_policy(POP)
+endfunction()
+
if(testname STREQUAL empty) # fail
string()
@@ -32,6 +45,18 @@ elseif(testname STREQUAL configure_escape_quotes) # pass
string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES)
message(STATUS "v='${v}'")
+elseif(testname STREQUAL configure_line_number_CMP0053_old) # pass
+ test_configure_line_number("\${CMAKE_CURRENT_LIST_LINE}" OLD)
+
+elseif(testname STREQUAL configure_line_number_CMP0053_new) # pass
+ test_configure_line_number("\${CMAKE_CURRENT_LIST_LINE}" NEW)
+
+elseif(testname STREQUAL configure_line_number_CMP0053_old_use_at) # pass
+ test_configure_line_number("\@CMAKE_CURRENT_LIST_LINE\@" OLD)
+
+elseif(testname STREQUAL configure_line_number_CMP0053_new_use_at) # pass
+ test_configure_line_number("\@CMAKE_CURRENT_LIST_LINE\@" NEW)
+
elseif(testname STREQUAL configure_bogus) # fail
string(CONFIGURE "this is @testname@" v ESCAPE_QUOTES BOGUS)
diff --git a/Tests/COnly/CMakeLists.txt b/Tests/COnly/CMakeLists.txt
index b3cc43813..3037f13cb 100644
--- a/Tests/COnly/CMakeLists.txt
+++ b/Tests/COnly/CMakeLists.txt
@@ -7,7 +7,7 @@ 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)
+if(MSVC_VERSION AND NOT CMAKE_C_COMPILER_ID STREQUAL Clang OR "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
set_target_properties(COnly PROPERTIES
LINK_FLAGS " /NODEFAULTLIB:\"libcdg.lib\" /NODEFAULTLIB:\"libcmtg.lib\" /NODEFAULTLIB:\"foomsvcrt.lib\" /NODEFAULTLIB:\"libbar.lib\" /NODEFAULTLIB:\"libfooba.lib\"")
endif()
diff --git a/Tests/COnly/libc2.h b/Tests/COnly/libc2.h
index 7bc4fb1c8..43ebce914 100644
--- a/Tests/COnly/libc2.h
+++ b/Tests/COnly/libc2.h
@@ -1,11 +1,11 @@
#ifdef _WIN32
-#ifdef testc2_EXPORTS
-#define CM_TEST_LIB_EXPORT __declspec(dllexport)
+# 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 __declspec(dllimport)
-#endif
-#else
-#define CM_TEST_LIB_EXPORT
+# define CM_TEST_LIB_EXPORT
#endif
CM_TEST_LIB_EXPORT float LibC2Func();
diff --git a/Tests/COnly/testCModule.c b/Tests/COnly/testCModule.c
index 4381bd746..edeb2b1fd 100644
--- a/Tests/COnly/testCModule.c
+++ b/Tests/COnly/testCModule.c
@@ -1,7 +1,7 @@
#ifdef _WIN32
-#define TEST_EXPORT __declspec(dllexport)
+# define TEST_EXPORT __declspec(dllexport)
#else
-#define TEST_EXPORT
+# define TEST_EXPORT
#endif
TEST_EXPORT int testCModule(void)
{
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend1.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend1.cmake
index 70d6edf49..73fd0abe2 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend1.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend1.cmake
@@ -6,7 +6,7 @@ include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
# expected results
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2-1_*.deb")
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2_*.deb")
set(expected_count 3)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend2.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend2.cmake
index 415d5360a..81dbbc515 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend2.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-depend2.cmake
@@ -6,7 +6,7 @@ include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
# expected results
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2-1_*.deb")
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2_*.deb")
set(expected_count 3)
set(config_verbose -V)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake
index 337cc1675..ad52f56b7 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description1.cmake
@@ -6,7 +6,7 @@ include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
# expected results
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2-1_*.deb")
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2_*.deb")
set(expected_count 3)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake
index 35ca74cdd..af27c5183 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-description2.cmake
@@ -7,7 +7,7 @@ include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
# expected results
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2-1_*.deb")
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2_*.deb")
set(expected_count 3)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake
index f1391cd73..ec75d618a 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-lintian-dpkgdeb-checks.cmake
@@ -4,8 +4,8 @@ endif()
include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
-# TODO: currently debian doens't produce lower cased names
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2-1_*.deb")
+# TODO: currently debian doesn't produce lower cased names
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2_*.deb")
set(expected_count 3)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-shlibdeps1.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-shlibdeps1.cmake
index fcfc7eaee..e57488cbb 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-shlibdeps1.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-shlibdeps1.cmake
@@ -9,7 +9,7 @@ include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
# requirements
# debian now produces lower case names
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2-1_*.deb")
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2_*.deb")
set(expected_count 3)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake
index 351bf2148..5ee057a3d 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-components-source.cmake
@@ -6,7 +6,7 @@ include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
# expected results
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2-1_*.deb")
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib-*_1.0.2_*.deb")
set(expected_count 3)
set(config_verbose -V)
diff --git a/Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake b/Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake
index c97ecb019..8c0bc4bd1 100644
--- a/Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake
+++ b/Tests/CPackComponentsDEB/RunCPackVerifyResult-compression.cmake
@@ -4,8 +4,8 @@ endif()
include(${CPackComponentsDEB_SOURCE_DIR}/RunCPackVerifyResult.cmake)
-# TODO: currently debian doens't produce lower cased names
-set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib_1.0.2-1_*.deb")
+# TODO: currently debian doesn't produce lower cased names
+set(expected_file_mask "${CPackComponentsDEB_BINARY_DIR}/mylib_1.0.2_*.deb")
set(expected_count 1)
set(actual_output)
diff --git a/Tests/CPackComponentsForAll/CMakeLists.txt b/Tests/CPackComponentsForAll/CMakeLists.txt
index 344084317..e49138a58 100644
--- a/Tests/CPackComponentsForAll/CMakeLists.txt
+++ b/Tests/CPackComponentsForAll/CMakeLists.txt
@@ -168,6 +168,18 @@ set(CPACK_RPM_RELOCATION_PATHS "${CMAKE_INSTALL_INCLUDEDIR}"
# set CPACK_DEBIAN_FILE_NAME to use default package name format
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
+# set some tags for NuGet packages
+# 1. all in one package
+set(CPACK_NUGET_PACKAGE_TAGS "nuget" "unit" "test" "all-in-one")
+# 2. per component packages
+set(CPACK_NUGET_APPLICATIONS_PACKAGE_TAGS "nuget" "unit" "test" "applications")
+set(CPACK_NUGET_LIBRARIES_PACKAGE_TAGS "nuget" "unit" "test" "libraries")
+set(CPACK_NUGET_HEADERS_PACKAGE_TAGS "nuget" "unit" "test" "headers")
+set(CPACK_NUGET_UNSPECIFIED_PACKAGE_TAGS "nuget" "unit" "test" "uNsP3c1FiEd")
+# 3. per group packages
+set(CPACK_NUGET_RUNTIME_PACKAGE_TAGS "nuget" "unit" "test" "run-time")
+set(CPACK_NUGET_DEVELOPMENT_PACKAGE_TAGS "nuget" "unit" "test" "development")
+
# 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 ...)
diff --git a/Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in b/Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in
index 0bfbf1467..1b9e6584d 100644
--- a/Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in
+++ b/Tests/CPackComponentsForAll/MyLibCPackConfig-AllInOne.cmake.in
@@ -13,6 +13,10 @@ if(CPACK_GENERATOR MATCHES "DEB")
set(CPACK_DEB_COMPONENT_INSTALL "ON")
endif()
+if(CPACK_GENERATOR MATCHES "NuGet")
+ set(CPACK_NUGET_COMPONENT_INSTALL "ON")
+endif()
+
#
# Choose grouping way
#
diff --git a/Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in b/Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in
index 0ffe44d3a..a6f6ea9e8 100644
--- a/Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in
+++ b/Tests/CPackComponentsForAll/MyLibCPackConfig-IgnoreGroup.cmake.in
@@ -52,6 +52,10 @@ if(CPACK_GENERATOR MATCHES "DEB")
set(CPACK_DEB_COMPONENT_INSTALL "ON")
endif()
+if(CPACK_GENERATOR MATCHES "NuGet")
+ set(CPACK_NUGET_COMPONENT_INSTALL "ON")
+endif()
+
#
# Choose grouping way
#
diff --git a/Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in b/Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in
index ac65dc996..d41225d1f 100644
--- a/Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in
+++ b/Tests/CPackComponentsForAll/MyLibCPackConfig-OnePackPerGroup.cmake.in
@@ -18,6 +18,10 @@ if(CPACK_GENERATOR MATCHES "DragNDrop")
set(CPACK_COMPONENTS_GROUPING "ONE_PER_GROUP")
endif()
+if(CPACK_GENERATOR MATCHES "NuGet")
+ set(CPACK_NUGET_COMPONENT_INSTALL "ON")
+endif()
+
#
# Choose grouping way
#
diff --git a/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake b/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake
index a5b38fdb6..253d128f1 100644
--- a/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake
+++ b/Tests/CPackComponentsForAll/RunCPackVerifyResult.cmake
@@ -38,57 +38,69 @@ set(config_verbose )
if(CPackGen MATCHES "ZIP")
set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib-*.zip")
- if (${CPackComponentWay} STREQUAL "default")
+ if(${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
- elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
- elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
- elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ elseif(${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
- endif ()
-elseif (CPackGen MATCHES "RPM")
+ 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")
+ if(${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
- elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
- elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
- elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ elseif(${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
- endif ()
-elseif (CPackGen MATCHES "DEB")
- set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/mylib*_1.0.2-1_*.deb")
- if (${CPackComponentWay} STREQUAL "default")
+ endif()
+elseif(CPackGen MATCHES "DEB")
+ set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/mylib*_1.0.2_*.deb")
+ if(${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
- elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
- elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
- elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ elseif(${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
- endif ()
+ endif()
+elseif(CPackGen MATCHES "NuGet")
+ set(config_verbose -D "CPACK_NUGET_PACKAGE_DEBUG=1")
+ set(expected_file_mask "${CPackComponentsForAll_BINARY_DIR}/MyLib*1.0.2.nupkg")
+ 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")
+ if(${CPackComponentWay} STREQUAL "default")
set(expected_count 1)
- elseif (${CPackComponentWay} STREQUAL "OnePackPerGroup")
+ elseif(${CPackComponentWay} STREQUAL "OnePackPerGroup")
set(expected_count 3)
- elseif (${CPackComponentWay} STREQUAL "IgnoreGroup")
+ elseif(${CPackComponentWay} STREQUAL "IgnoreGroup")
set(expected_count 4)
- elseif (${CPackComponentWay} STREQUAL "AllInOne")
+ elseif(${CPackComponentWay} STREQUAL "AllInOne")
set(expected_count 1)
- endif ()
+ endif()
endif()
# clean-up previously CPack generated files
if(expected_file_mask)
file(GLOB expected_file "${expected_file_mask}")
- if (expected_file)
+ if(expected_file)
file(REMOVE ${expected_file})
endif()
endif()
@@ -101,7 +113,7 @@ execute_process(COMMAND ${CMAKE_CPACK_COMMAND} ${config_verbose} -G ${CPackGen}
ERROR_VARIABLE CPack_error
WORKING_DIRECTORY ${CPackComponentsForAll_BINARY_DIR})
-if (CPack_result)
+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}")
diff --git a/Tests/CSharpLinkToCxx/CMakeLists.txt b/Tests/CSharpLinkToCxx/CMakeLists.txt
index 153c57c90..a3067afa2 100644
--- a/Tests/CSharpLinkToCxx/CMakeLists.txt
+++ b/Tests/CSharpLinkToCxx/CMakeLists.txt
@@ -21,3 +21,9 @@ target_link_libraries(CSharpLinkToCxx CLIApp)
# because it is unmanaged
add_library(CppNativeApp SHARED cpp_native.hpp cpp_native.cpp)
target_link_libraries(CSharpLinkToCxx CppNativeApp)
+
+# Link a static C++ library into the CSharp executable.
+# We do not actually use any symbols but this helps cover
+# link language selection.
+add_library(CppStaticLib STATIC cpp_static.cpp)
+target_link_libraries(CSharpLinkToCxx CppStaticLib)
diff --git a/Tests/CSharpOnly/CMakeLists.txt b/Tests/CSharpOnly/CMakeLists.txt
index 0e3e39e21..82049c78d 100644
--- a/Tests/CSharpOnly/CMakeLists.txt
+++ b/Tests/CSharpOnly/CMakeLists.txt
@@ -8,3 +8,6 @@ add_library(lib2 SHARED lib2.cs)
add_executable(CSharpOnly csharponly.cs)
target_link_libraries(CSharpOnly lib1 lib2)
+
+add_custom_target(CSharpCustom ALL SOURCES empty.cs)
+add_custom_target(custom.cs ALL DEPENDS empty.txt)
diff --git a/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in b/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in
index 670a8745f..0f5678160 100644
--- a/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in
+++ b/Tests/CTestBuildCommandProjectInSubdir/CTestBuildCommandProjectInSubdir.cmake.in
@@ -3,7 +3,6 @@ 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})
diff --git a/Tests/CTestConfig/CMakeLists.txt b/Tests/CTestConfig/CMakeLists.txt
index f46d89a55..8c19adbe2 100644
--- a/Tests/CTestConfig/CMakeLists.txt
+++ b/Tests/CTestConfig/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.9)
project(CTestConfig)
include(CTest)
@@ -8,32 +8,41 @@ include(CTest)
# '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.
+# build trees and not defined for multi-configuration build trees. The value of
+# CMAKE_CONFIGURATION_TYPES should not be relied upon to determine whether we
+# are using a multi-config generator or not, the GENERATOR_IS_MULTI_CONFIG
+# global property is the canonical way to do that as of CMake 3.9.
#
-if(CMAKE_CONFIGURATION_TYPES)
- # multi-configuration: expect not defined, error if defined
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
+ if(NOT DEFINED CMAKE_CONFIGURATION_TYPES OR CMAKE_CONFIGURATION_TYPES STREQUAL "")
+ message(FATAL_ERROR "CMAKE_CONFIGURATION_TYPES is not defined or is empty "
+ "(but must be defined and non-empty for a multi-configuration generator)")
+ endif()
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)")
+ message(FATAL_ERROR "CMAKE_BUILD_TYPE='${CMAKE_BUILD_TYPE}' is defined and non-empty "
+ "(but should not be for a multi-configuration generator)")
endif()
+ set(_configs ${CMAKE_CONFIGURATION_TYPES})
else()
- # single-configuration: expect defined, error if not defined
+ # Populating CMAKE_CONFIGURATION_TYPES even for single config generators is
+ # common enough for user projects that we don't want to consider it an error.
+ # We just need CMAKE_BUILD_TYPE to be set and ignore CMAKE_CONFIGURATION_TYPES.
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)")
+ 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}")
+ set(_configs ${CMAKE_BUILD_TYPE})
endif()
add_executable(ctc CTestConfig.cxx)
-foreach(cfg ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
+foreach(cfg ${_configs})
add_test(NAME ctc-${cfg} CONFIGURATIONS ${cfg} COMMAND ctc --config $<CONFIGURATION>)
- if(CMAKE_CONFIGURATION_TYPES)
+ if(_isMultiConfig)
set_property(TEST ctc-${cfg}
PROPERTY PASS_REGULAR_EXPRESSION "CMAKE_INTDIR is ${cfg}")
set_property(TEST ctc-${cfg}
diff --git a/Tests/CTestConfig/dashboard.cmake.in b/Tests/CTestConfig/dashboard.cmake.in
index 143fe717a..4bb1262c0 100644
--- a/Tests/CTestConfig/dashboard.cmake.in
+++ b/Tests/CTestConfig/dashboard.cmake.in
@@ -1,4 +1,4 @@
-set(CMAKE_CONFIGURATION_TYPES "@CMAKE_CONFIGURATION_TYPES@")
+set(_isMultiConfig "@_isMultiConfig@")
set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestConfig")
set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestConfig/@cfg@-dashboard")
@@ -11,7 +11,7 @@ message("CMAKE_COMMAND='${CMAKE_COMMAND}'")
message("CMAKE_CTEST_COMMAND='${CMAKE_CTEST_COMMAND}'")
set(arg "")
-if(NOT CMAKE_CONFIGURATION_TYPES)
+if(NOT _isMultiConfig)
set(arg "-DCMAKE_BUILD_TYPE:STRING=@cfg@")
endif()
diff --git a/Tests/CTestConfig/script.cmake.in b/Tests/CTestConfig/script.cmake.in
index b6ccedb57..973c7b8c4 100644
--- a/Tests/CTestConfig/script.cmake.in
+++ b/Tests/CTestConfig/script.cmake.in
@@ -1,7 +1,6 @@
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")
diff --git a/Tests/CTestCoverageCollectGCOV/fakegcov.cmake b/Tests/CTestCoverageCollectGCOV/fakegcov.cmake
index b0c3a9b9f..6df429256 100644
--- a/Tests/CTestCoverageCollectGCOV/fakegcov.cmake
+++ b/Tests/CTestCoverageCollectGCOV/fakegcov.cmake
@@ -1,14 +1,17 @@
+function(create_gcov_file gcda_full_path)
+ get_filename_component(gcda_name ${gcda_full_path} NAME)
+ string(REPLACE ".gcda" ".gcov" gcov_name "${gcda_name}")
+
+ file(STRINGS "${gcda_full_path}" source_file LIMIT_COUNT 1 ENCODING UTF-8)
+
+ file(WRITE "${CMAKE_SOURCE_DIR}/${gcov_name}"
+ " -: 0:Source:${source_file}"
+ )
+endfunction()
+
foreach(I RANGE 0 ${CMAKE_ARGC})
if("${CMAKE_ARGV${I}}" MATCHES ".*\\.gcda")
set(gcda_file "${CMAKE_ARGV${I}}")
+ create_gcov_file(${gcda_file})
endif()
endforeach()
-
-get_filename_component(gcda_name ${gcda_file} NAME)
-string(REPLACE ".gcda" ".gcov" gcov_name "${gcda_name}")
-
-file(STRINGS "${gcda_file}" source_file LIMIT_COUNT 1 ENCODING UTF-8)
-
-file(WRITE "${CMAKE_SOURCE_DIR}/${gcov_name}"
- " -: 0:Source:${source_file}"
-)
diff --git a/Tests/CTestCoverageCollectGCOV/test.cmake.in b/Tests/CTestCoverageCollectGCOV/test.cmake.in
index d48ef6130..2c98876b3 100644
--- a/Tests/CTestCoverageCollectGCOV/test.cmake.in
+++ b/Tests/CTestCoverageCollectGCOV/test.cmake.in
@@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 2.8.12)
-set(CTEST_PROJECT_NAME "TestProject")
set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/TestProject")
set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestCoverageCollectGCOV/TestProject")
set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
diff --git a/Tests/CTestTest/test.cmake.in b/Tests/CTestTest/test.cmake.in
index bb6346b8a..23166a7e3 100644
--- a/Tests/CTestTest/test.cmake.in
+++ b/Tests/CTestTest/test.cmake.in
@@ -62,7 +62,7 @@ COVERAGE_COMMAND:FILEPATH=@COVERAGE_COMMAND@
set (CTEST_DASHBOARD_ROOT "@CMAKE_CURRENT_BINARY_DIR@/Tests/CTestTest")
-# set any extra envionment varibles here
+# set any extra environment variables here
set (CTEST_ENVIRONMENT
)
diff --git a/Tests/CTestTest2/test.cmake.in b/Tests/CTestTest2/test.cmake.in
index 825b957d7..a9bbc527d 100644
--- a/Tests/CTestTest2/test.cmake.in
+++ b/Tests/CTestTest2/test.cmake.in
@@ -34,6 +34,7 @@ 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@
+KWSYS_ENCODING_DEFAULT_CODEPAGE:STRING=CP_UTF8
# This one is needed for testing advanced ctest features
CTEST_TEST_KWSYS:BOOL=ON
diff --git a/Tests/CTestTestBadExe/CTestConfig.cmake b/Tests/CTestTestBadExe/CTestConfig.cmake
index c7286e2c5..5bc1e9e16 100644
--- a/Tests/CTestTestBadExe/CTestConfig.cmake
+++ b/Tests/CTestTestBadExe/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestBadGenerator/CTestConfig.cmake b/Tests/CTestTestBadGenerator/CTestConfig.cmake
index 1e61bf441..5bc1e9e16 100644
--- a/Tests/CTestTestBadGenerator/CTestConfig.cmake
+++ b/Tests/CTestTestBadGenerator/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestCostSerial/CTestConfig.cmake b/Tests/CTestTestCostSerial/CTestConfig.cmake
index 3ab99ac5e..bd265f981 100644
--- a/Tests/CTestTestCostSerial/CTestConfig.cmake
+++ b/Tests/CTestTestCostSerial/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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
index b7abe946b..8a174c9b8 100644
--- a/Tests/CTestTestCostSerial/sleep.c
+++ b/Tests/CTestTestCostSerial/sleep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
/* sleeps for 1 second */
diff --git a/Tests/CTestTestCrash/CTestConfig.cmake b/Tests/CTestTestCrash/CTestConfig.cmake
index 5c2ca0ea9..5bc1e9e16 100644
--- a/Tests/CTestTestCrash/CTestConfig.cmake
+++ b/Tests/CTestTestCrash/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestCycle/CTestConfig.cmake b/Tests/CTestTestCycle/CTestConfig.cmake
index 8aeb09b70..5bc1e9e16 100644
--- a/Tests/CTestTestCycle/CTestConfig.cmake
+++ b/Tests/CTestTestCycle/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestDepends/CTestConfig.cmake b/Tests/CTestTestDepends/CTestConfig.cmake
index 7af9200e2..5bc1e9e16 100644
--- a/Tests/CTestTestDepends/CTestConfig.cmake
+++ b/Tests/CTestTestDepends/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestFailure/CTestConfig.cmake b/Tests/CTestTestFailure/CTestConfig.cmake
index 07e1be00c..5bc1e9e16 100644
--- a/Tests/CTestTestFailure/CTestConfig.cmake
+++ b/Tests/CTestTestFailure/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestFdSetSize/sleep.c b/Tests/CTestTestFdSetSize/sleep.c
index 6676488fb..2fb6490aa 100644
--- a/Tests/CTestTestFdSetSize/sleep.c
+++ b/Tests/CTestTestFdSetSize/sleep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
/* sleeps for 0.1 second */
diff --git a/Tests/CTestTestLaunchers/launcher_compiler_test_project/CTestConfig.cmake b/Tests/CTestTestLaunchers/launcher_compiler_test_project/CTestConfig.cmake
index 669b0fb68..c08eded76 100644
--- a/Tests/CTestTestLaunchers/launcher_compiler_test_project/CTestConfig.cmake
+++ b/Tests/CTestTestLaunchers/launcher_compiler_test_project/CTestConfig.cmake
@@ -1,8 +1,5 @@
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_custom_command_test_project/CTestConfig.cmake b/Tests/CTestTestLaunchers/launcher_custom_command_test_project/CTestConfig.cmake
index 669b0fb68..c08eded76 100644
--- a/Tests/CTestTestLaunchers/launcher_custom_command_test_project/CTestConfig.cmake
+++ b/Tests/CTestTestLaunchers/launcher_custom_command_test_project/CTestConfig.cmake
@@ -1,8 +1,5 @@
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_linker_test_project/CTestConfig.cmake b/Tests/CTestTestLaunchers/launcher_linker_test_project/CTestConfig.cmake
index 669b0fb68..c08eded76 100644
--- a/Tests/CTestTestLaunchers/launcher_linker_test_project/CTestConfig.cmake
+++ b/Tests/CTestTestLaunchers/launcher_linker_test_project/CTestConfig.cmake
@@ -1,8 +1,5 @@
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/CTestTestParallel/CTestConfig.cmake b/Tests/CTestTestParallel/CTestConfig.cmake
index fc5b6668e..bd265f981 100644
--- a/Tests/CTestTestParallel/CTestConfig.cmake
+++ b/Tests/CTestTestParallel/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestResourceLock/CTestConfig.cmake b/Tests/CTestTestResourceLock/CTestConfig.cmake
index c1187778d..bd265f981 100644
--- a/Tests/CTestTestResourceLock/CTestConfig.cmake
+++ b/Tests/CTestTestResourceLock/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestScheduler/CTestConfig.cmake b/Tests/CTestTestScheduler/CTestConfig.cmake
index 797387bdd..bd265f981 100644
--- a/Tests/CTestTestScheduler/CTestConfig.cmake
+++ b/Tests/CTestTestScheduler/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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
index 41a5d450b..327bff57e 100644
--- a/Tests/CTestTestScheduler/sleep.c
+++ b/Tests/CTestTestScheduler/sleep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
/* sleeps for 4n seconds, where n is the argument to the program */
diff --git a/Tests/CTestTestSkipReturnCode/CTestConfig.cmake b/Tests/CTestTestSkipReturnCode/CTestConfig.cmake
index da0c76b73..5bc1e9e16 100644
--- a/Tests/CTestTestSkipReturnCode/CTestConfig.cmake
+++ b/Tests/CTestTestSkipReturnCode/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestStopTime/CTestConfig.cmake b/Tests/CTestTestStopTime/CTestConfig.cmake
index 412283e69..5bc1e9e16 100644
--- a/Tests/CTestTestStopTime/CTestConfig.cmake
+++ b/Tests/CTestTestStopTime/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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
index 46ab2fbac..64a4fb9b3 100644
--- a/Tests/CTestTestStopTime/GetDate.cmake
+++ b/Tests/CTestTestStopTime/GetDate.cmake
@@ -68,7 +68,7 @@ macro(GET_DATE)
#
# Extract six individual components by matching a regex with paren groupings.
- # Use the replace functionality and \\1 thru \\6 to extract components.
+ # Use the replace functionality and \\1 through \\6 to extract components.
#
set(${GD_PREFIX}REGEX "([^/]+)/([^/]+)/([^ ]+) +([^:]+):([^:]+):([^\\.]+)")
diff --git a/Tests/CTestTestStopTime/sleep.c b/Tests/CTestTestStopTime/sleep.c
index 3baad9ea0..b9b6e897b 100644
--- a/Tests/CTestTestStopTime/sleep.c
+++ b/Tests/CTestTestStopTime/sleep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
/* sleeps for n seconds, where n is the argument to the program */
diff --git a/Tests/CTestTestSubdir/CTestConfig.cmake b/Tests/CTestTestSubdir/CTestConfig.cmake
index 47ebb925c..bd265f981 100644
--- a/Tests/CTestTestSubdir/CTestConfig.cmake
+++ b/Tests/CTestTestSubdir/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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/CTestTestTimeout/CTestConfig.cmake b/Tests/CTestTestTimeout/CTestConfig.cmake
index 13114f1ca..bd265f981 100644
--- a/Tests/CTestTestTimeout/CTestConfig.cmake
+++ b/Tests/CTestTestTimeout/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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
index a4872b52e..ebe127430 100644
--- a/Tests/CTestTestTimeout/sleep.c
+++ b/Tests/CTestTestTimeout/sleep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
#include <stdio.h>
diff --git a/Tests/CTestTestTimeout/timeout.cmake b/Tests/CTestTestTimeout/timeout.cmake
index 0989b65df..ba2f58b7d 100644
--- a/Tests/CTestTestTimeout/timeout.cmake
+++ b/Tests/CTestTestTimeout/timeout.cmake
@@ -1,6 +1,6 @@
# Remove the log file.
file(REMOVE ${Log})
-# Run a child that sleeps longer than the timout of this test.
+# Run a child that sleeps longer than the timeout 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/CTestConfig.cmake b/Tests/CTestTestUpload/CTestConfig.cmake
index a54708838..21318b4fc 100644
--- a/Tests/CTestTestUpload/CTestConfig.cmake
+++ b/Tests/CTestTestUpload/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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
index 3baad9ea0..b9b6e897b 100644
--- a/Tests/CTestTestUpload/sleep.c
+++ b/Tests/CTestTestUpload/sleep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
/* sleeps for n seconds, where n is the argument to the program */
diff --git a/Tests/CTestTestVerboseOutput/CTestConfig.cmake b/Tests/CTestTestVerboseOutput/CTestConfig.cmake
index 4f96c79a9..bd265f981 100644
--- a/Tests/CTestTestVerboseOutput/CTestConfig.cmake
+++ b/Tests/CTestTestVerboseOutput/CTestConfig.cmake
@@ -1,7 +1,4 @@
-set(CTEST_PROJECT_NAME "CTestTestVerboseOutput")
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/CTestConfig.cmake b/Tests/CTestTestZeroTimeout/CTestConfig.cmake
index 60948647f..bd265f981 100644
--- a/Tests/CTestTestZeroTimeout/CTestConfig.cmake
+++ b/Tests/CTestTestZeroTimeout/CTestConfig.cmake
@@ -1,7 +1,4 @@
-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
index 0be7bbc4f..5d0b89bf7 100644
--- a/Tests/CTestTestZeroTimeout/sleep.c
+++ b/Tests/CTestTestZeroTimeout/sleep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32)
-#include <windows.h>
+# include <windows.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
/* sleeps for 5 seconds */
diff --git a/Tests/CTestUpdateCommon.cmake b/Tests/CTestUpdateCommon.cmake
index 61aa13b94..0f8ec8e27 100644
--- a/Tests/CTestUpdateCommon.cmake
+++ b/Tests/CTestUpdateCommon.cmake
@@ -130,7 +130,6 @@ function(create_content 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\")
")
diff --git a/Tests/CheckFortran.cmake b/Tests/CheckFortran.cmake
index b1652baf1..16a8ed2c6 100644
--- a/Tests/CheckFortran.cmake
+++ b/Tests/CheckFortran.cmake
@@ -15,11 +15,18 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
\"set(CMAKE_Fortran_COMPILER_SUPPORTS_F90 \\\"\${CMAKE_Fortran_COMPILER_SUPPORTS_F90}\\\")\\n\"
)
")
+ if(CMAKE_GENERATOR_INSTANCE)
+ set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
+ else()
+ set(_D_CMAKE_GENERATOR_INSTANCE "")
+ endif()
execute_process(
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckFortran
COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
-A "${CMAKE_GENERATOR_PLATFORM}"
-T "${CMAKE_GENERATOR_TOOLSET}"
+ ${_D_CMAKE_GENERATOR_INSTANCE}
+ TIMEOUT 60
OUTPUT_VARIABLE output
ERROR_VARIABLE output
RESULT_VARIABLE result
diff --git a/Tests/CompatibleInterface/main.cpp b/Tests/CompatibleInterface/main.cpp
index 93723afa0..0bccb8206 100644
--- a/Tests/CompatibleInterface/main.cpp
+++ b/Tests/CompatibleInterface/main.cpp
@@ -1,26 +1,26 @@
#ifndef BOOL_PROP1
-#error Expected BOOL_PROP1
+# error Expected BOOL_PROP1
#endif
#ifndef BOOL_PROP2
-#error Expected BOOL_PROP2
+# error Expected BOOL_PROP2
#endif
#ifndef BOOL_PROP3
-#error Expected BOOL_PROP3
+# error Expected BOOL_PROP3
#endif
#ifndef STRING_PROP1
-#error Expected STRING_PROP1
+# error Expected STRING_PROP1
#endif
#ifndef STRING_PROP2
-#error Expected STRING_PROP2
+# error Expected STRING_PROP2
#endif
#ifndef STRING_PROP3
-#error Expected STRING_PROP3
+# error Expected STRING_PROP3
#endif
template <bool test>
diff --git a/Tests/CompileCommandOutput/relative.h b/Tests/CompileCommandOutput/relative.h
index 221e35453..fa6eefff6 100644
--- a/Tests/CompileCommandOutput/relative.h
+++ b/Tests/CompileCommandOutput/relative.h
@@ -1,11 +1,11 @@
#if defined(_WIN32)
-#ifdef test2_EXPORTS
-#define TEST2_EXPORT __declspec(dllexport)
+# ifdef test2_EXPORTS
+# define TEST2_EXPORT __declspec(dllexport)
+# else
+# define TEST2_EXPORT __declspec(dllimport)
+# endif
#else
-#define TEST2_EXPORT __declspec(dllimport)
-#endif
-#else
-#define TEST2_EXPORT
+# define TEST2_EXPORT
#endif
TEST2_EXPORT void relative();
diff --git a/Tests/CompileDefinitions/compiletest.c b/Tests/CompileDefinitions/compiletest.c
index 8871750af..66248668a 100644
--- a/Tests/CompileDefinitions/compiletest.c
+++ b/Tests/CompileDefinitions/compiletest.c
@@ -1,20 +1,20 @@
#ifndef LINK_C_DEFINE
-#error Expected LINK_C_DEFINE
+# error Expected LINK_C_DEFINE
#endif
#ifndef LINK_LANGUAGE_IS_C
-#error Expected LINK_LANGUAGE_IS_C
+# error Expected LINK_LANGUAGE_IS_C
#endif
#ifdef LINK_CXX_DEFINE
-#error Unexpected LINK_CXX_DEFINE
+# error Unexpected LINK_CXX_DEFINE
#endif
#ifdef LINK_LANGUAGE_IS_CXX
-#error Unexpected LINK_LANGUAGE_IS_CXX
+# error Unexpected LINK_LANGUAGE_IS_CXX
#endif
#ifdef DEBUG_MODE
-#error Unexpected DEBUG_MODE
+# error Unexpected DEBUG_MODE
#endif
int main(void)
diff --git a/Tests/CompileDefinitions/compiletest.cpp b/Tests/CompileDefinitions/compiletest.cpp
index 640e7cf56..328e72e91 100644
--- a/Tests/CompileDefinitions/compiletest.cpp
+++ b/Tests/CompileDefinitions/compiletest.cpp
@@ -1,10 +1,10 @@
#ifndef CMAKE_IS_FUN
-#error Expect CMAKE_IS_FUN definition
+# error Expect CMAKE_IS_FUN definition
#endif
#if CMAKE_IS != Fun
-#error Expect CMAKE_IS=Fun definition
+# error Expect CMAKE_IS=Fun definition
#endif
template <bool test>
@@ -43,67 +43,67 @@ enum
};
#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
+# 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!"
+# error "BUILD_IS_DEBUG not defined!"
#endif
#ifndef BUILD_IS_NOT_DEBUG
-#error "BUILD_IS_NOT_DEBUG not defined!"
+# 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
+# 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
+# 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)
diff --git a/Tests/CompileDefinitions/compiletest_mixed_c.c b/Tests/CompileDefinitions/compiletest_mixed_c.c
index 5fbe45f92..e4adef322 100644
--- a/Tests/CompileDefinitions/compiletest_mixed_c.c
+++ b/Tests/CompileDefinitions/compiletest_mixed_c.c
@@ -1,20 +1,20 @@
#ifndef LINK_CXX_DEFINE
-#error Expected LINK_CXX_DEFINE
+# error Expected LINK_CXX_DEFINE
#endif
#ifndef LINK_LANGUAGE_IS_CXX
-#error Expected LINK_LANGUAGE_IS_CXX
+# error Expected LINK_LANGUAGE_IS_CXX
#endif
#ifdef LINK_C_DEFINE
-#error Unexpected LINK_C_DEFINE
+# error Unexpected LINK_C_DEFINE
#endif
#ifdef LINK_LANGUAGE_IS_C
-#error Unexpected 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
+# 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
index 4eab0999c..b50b4bf10 100644
--- a/Tests/CompileDefinitions/compiletest_mixed_cxx.cpp
+++ b/Tests/CompileDefinitions/compiletest_mixed_cxx.cpp
@@ -1,20 +1,20 @@
#ifndef LINK_CXX_DEFINE
-#error Expected LINK_CXX_DEFINE
+# error Expected LINK_CXX_DEFINE
#endif
#ifndef LINK_LANGUAGE_IS_CXX
-#error Expected LINK_LANGUAGE_IS_CXX
+# error Expected LINK_LANGUAGE_IS_CXX
#endif
#ifdef LINK_C_DEFINE
-#error Unexpected LINK_C_DEFINE
+# error Unexpected LINK_C_DEFINE
#endif
#ifdef LINK_LANGUAGE_IS_C
-#error Unexpected 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
+# error Expected C_EXECUTABLE_LINK_LANGUAGE_IS_C define
#endif
int main(int argc, char** argv)
diff --git a/Tests/CompileDefinitions/runtest.c b/Tests/CompileDefinitions/runtest.c
index 7c28ab90e..c6dac4dfc 100644
--- a/Tests/CompileDefinitions/runtest.c
+++ b/Tests/CompileDefinitions/runtest.c
@@ -3,7 +3,7 @@
#include <string.h>
#ifndef BUILD_CONFIG_NAME
-#error "BUILD_CONFIG_NAME not defined!"
+# error "BUILD_CONFIG_NAME not defined!"
#endif
int main()
diff --git a/Tests/CompileDefinitions/target_prop/usetgt.c b/Tests/CompileDefinitions/target_prop/usetgt.c
index 8408a908c..56823b089 100644
--- a/Tests/CompileDefinitions/target_prop/usetgt.c
+++ b/Tests/CompileDefinitions/target_prop/usetgt.c
@@ -1,11 +1,11 @@
#ifndef TGT_DEF
-#error TGT_DEF incorrectly not defined
+# error TGT_DEF incorrectly not defined
#endif
#ifndef TGT_TYPE_STATIC_LIBRARY
-#error TGT_TYPE_STATIC_LIBRARY incorrectly not defined
+# error TGT_TYPE_STATIC_LIBRARY incorrectly not defined
#endif
#ifdef TGT_TYPE_EXECUTABLE
-#error TGT_TYPE_EXECUTABLE incorrectly defined
+# error TGT_TYPE_EXECUTABLE incorrectly defined
#endif
int main(void)
{
diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt
index 4a5558d48..060fb4940 100644
--- a/Tests/CompileFeatures/CMakeLists.txt
+++ b/Tests/CompileFeatures/CMakeLists.txt
@@ -15,17 +15,21 @@ macro(run_test feature lang)
endif()
endmacro()
-get_property(c_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES)
-list(FILTER c_features EXCLUDE REGEX "^c_std_[0-9][0-9]")
-foreach(feature ${c_features})
- run_test(${feature} C)
-endforeach()
+if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$")
+ get_property(c_features GLOBAL PROPERTY CMAKE_C_KNOWN_FEATURES)
+ list(FILTER c_features EXCLUDE REGEX "^c_std_[0-9][0-9]")
+ foreach(feature ${c_features})
+ run_test(${feature} C)
+ endforeach()
+endif()
-get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
-list(FILTER cxx_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]")
-foreach(feature ${cxx_features})
- run_test(${feature} CXX)
-endforeach()
+if(NOT CMAKE_CXX_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$")
+ get_property(cxx_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
+ list(FILTER cxx_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]")
+ foreach(feature ${cxx_features})
+ run_test(${feature} CXX)
+ endforeach()
+endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
@@ -48,6 +52,16 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro)
+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.15)
+ # SunPro 5.14 accepts -std=c++14 and compiles two features but does
+ # not define __cplusplus to a value different than with -std=c++11.
+ list(REMOVE_ITEM CXX_non_features
+ cxx_aggregate_default_initializers
+ cxx_digit_separators
+ )
+ endif()
+
+ # FIXME: Do any of these work correctly on SunPro 5.13 or above?
list(REMOVE_ITEM CXX_non_features
cxx_attribute_deprecated
cxx_contextual_conversions
@@ -224,54 +238,22 @@ if (C_expected_features)
add_executable(CompileFeaturesGenex_C genex_test.c)
set_property(TARGET CompileFeaturesGenex_C PROPERTY C_STANDARD 11)
- if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
- list(APPEND expected_defs
- EXPECT_C_STATIC_ASSERT=1
- )
- else()
- list(APPEND expected_defs
- EXPECT_C_STATIC_ASSERT=0
+ foreach(f
+ c_restrict
+ c_static_assert
+ c_function_prototypes
)
- endif()
- elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang"
- OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
- list(APPEND expected_defs
- EXPECT_C_STATIC_ASSERT=1
- )
- elseif (CMAKE_C_COMPILER_ID STREQUAL "Intel")
- if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 15)
- list(APPEND expected_defs
- EXPECT_C_STATIC_ASSERT=1
- )
+ if(${f} IN_LIST C_expected_features)
+ set(expect_${f} 1)
else()
- list(APPEND expected_defs
- EXPECT_C_STATIC_ASSERT=0
- )
+ set(expect_${f} 0)
endif()
- elseif (CMAKE_C_COMPILER_ID STREQUAL "SunPro")
- if (NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.13)
- list(APPEND expected_defs
- EXPECT_C_STATIC_ASSERT=1
- )
- else()
- list(APPEND expected_defs
- EXPECT_C_STATIC_ASSERT=0
- )
- endif()
- endif()
-
- list(APPEND expected_defs
- EXPECT_C_FUNCTION_PROTOTYPES=1
- EXPECT_C_RESTRICT=1
- )
-
- target_compile_definitions(CompileFeaturesGenex_C PRIVATE
- HAVE_C_FUNCTION_PROTOTYPES=$<COMPILE_FEATURES:c_function_prototypes>
- HAVE_C_RESTRICT=$<COMPILE_FEATURES:c_restrict>
- HAVE_C_STATIC_ASSERT=$<COMPILE_FEATURES:c_static_assert>
- ${expected_defs}
- )
+ string(TOUPPER "${f}" F)
+ target_compile_definitions(CompileFeaturesGenex_C PRIVATE
+ EXPECT_${F}=${expect_${f}}
+ HAVE_${F}=$<COMPILE_FEATURES:${f}>
+ )
+ endforeach()
endif()
if (CMAKE_CXX_COMPILE_FEATURES)
@@ -280,6 +262,7 @@ if (CMAKE_CXX_COMPILE_FEATURES)
if (std_flag_idx EQUAL -1)
add_executable(default_dialect default_dialect.cpp)
target_compile_definitions(default_dialect PRIVATE
+ DEFAULT_CXX20=$<EQUAL:${CMAKE_CXX_STANDARD_DEFAULT},20>
DEFAULT_CXX17=$<EQUAL:${CMAKE_CXX_STANDARD_DEFAULT},17>
DEFAULT_CXX14=$<EQUAL:${CMAKE_CXX_STANDARD_DEFAULT},14>
DEFAULT_CXX11=$<EQUAL:${CMAKE_CXX_STANDARD_DEFAULT},11>
@@ -318,136 +301,62 @@ else()
add_executable(IfaceCompileFeatures main.cpp)
target_link_libraries(IfaceCompileFeatures iface)
- if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
- if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=1
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
- )
- elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7)
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=0
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
+ foreach(f
+ cxx_final
+ cxx_override
+ cxx_auto_type
+ cxx_inheriting_constructors
)
+ if(${f} IN_LIST CXX_expected_features)
+ set(expect_${f} 1)
else()
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=0
- -DEXPECT_INHERITING_CONSTRUCTORS=0
- -DEXPECT_FINAL=0
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
- )
- endif()
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=1
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
- )
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
- if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=1
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
- )
- else()
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=0
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
- )
- endif()
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
- if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0)
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=1
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
- )
- elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0)
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=0
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
- )
- else()
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=0
- -DEXPECT_INHERITING_CONSTRUCTORS=0
- -DEXPECT_FINAL=0
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
- )
- endif()
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=1
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
- )
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
- if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15)
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=1
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=1
- )
- elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=1
- -DEXPECT_INHERITING_CONSTRUCTORS=0
- -DEXPECT_FINAL=1
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
- )
- else()
- add_definitions(
- -DEXPECT_OVERRIDE_CONTROL=0
- -DEXPECT_INHERITING_CONSTRUCTORS=0
- -DEXPECT_FINAL=0
- -DEXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=0
- )
+ set(expect_${f} 0)
endif()
+ endforeach()
+
+ if(expect_cxx_final AND expect_cxx_override)
+ set(expect_override_control 1)
+ else()
+ set(expect_override_control 0)
+ endif()
+ if(expect_cxx_inheriting_constructors AND expect_cxx_final)
+ set(expect_inheriting_constructors_and_final 1)
+ else()
+ set(expect_inheriting_constructors_and_final 0)
endif()
- add_executable(CompileFeaturesGenex genex_test.cpp)
- set_property(TARGET CompileFeaturesGenex PROPERTY CXX_STANDARD 11)
- target_compile_definitions(CompileFeaturesGenex PRIVATE
+ set(genex_test_defs
HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>
HAVE_AUTO_TYPE=$<COMPILE_FEATURES:cxx_auto_type>
HAVE_INHERITING_CONSTRUCTORS=$<COMPILE_FEATURES:cxx_inheriting_constructors>
HAVE_FINAL=$<COMPILE_FEATURES:cxx_final>
HAVE_INHERITING_CONSTRUCTORS_AND_FINAL=$<COMPILE_FEATURES:cxx_inheriting_constructors,cxx_final>
- )
+ EXPECT_OVERRIDE_CONTROL=${expect_override_control}
+ EXPECT_INHERITING_CONSTRUCTORS=${expect_cxx_inheriting_constructors}
+ EXPECT_FINAL=${expect_cxx_final}
+ EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL=${expect_inheriting_constructors_and_final}
+ )
+ if (CMAKE_CXX_STANDARD_DEFAULT)
+ list(APPEND genex_test_defs
+ TEST_CXX_STD
+ HAVE_CXX_STD_11=$<COMPILE_FEATURES:cxx_std_11>
+ HAVE_CXX_STD_14=$<COMPILE_FEATURES:cxx_std_14>
+ HAVE_CXX_STD_17=$<COMPILE_FEATURES:cxx_std_17>
+ HAVE_CXX_STD_20=$<COMPILE_FEATURES:cxx_std_20>
+ )
+ endif()
+
+ add_executable(CompileFeaturesGenex genex_test.cpp)
+ set_property(TARGET CompileFeaturesGenex PROPERTY CXX_STANDARD 11)
+ target_compile_definitions(CompileFeaturesGenex PRIVATE ${genex_test_defs})
add_executable(CompileFeaturesGenex2 genex_test.cpp)
target_compile_features(CompileFeaturesGenex2 PRIVATE cxx_std_11)
- target_compile_definitions(CompileFeaturesGenex2 PRIVATE
- HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>
- HAVE_AUTO_TYPE=$<COMPILE_FEATURES:cxx_auto_type>
- HAVE_INHERITING_CONSTRUCTORS=$<COMPILE_FEATURES:cxx_inheriting_constructors>
- HAVE_FINAL=$<COMPILE_FEATURES:cxx_final>
- HAVE_INHERITING_CONSTRUCTORS_AND_FINAL=$<COMPILE_FEATURES:cxx_inheriting_constructors,cxx_final>
- )
+ target_compile_definitions(CompileFeaturesGenex2 PRIVATE ${genex_test_defs} ALLOW_LATER_STANDARDS=1)
add_library(std_11_iface INTERFACE)
target_compile_features(std_11_iface INTERFACE cxx_std_11)
add_executable(CompileFeaturesGenex3 genex_test.cpp)
target_link_libraries(CompileFeaturesGenex3 PRIVATE std_11_iface)
- target_compile_definitions(CompileFeaturesGenex3 PRIVATE
- HAVE_OVERRIDE_CONTROL=$<COMPILE_FEATURES:cxx_final,cxx_override>
- HAVE_AUTO_TYPE=$<COMPILE_FEATURES:cxx_auto_type>
- HAVE_INHERITING_CONSTRUCTORS=$<COMPILE_FEATURES:cxx_inheriting_constructors>
- HAVE_FINAL=$<COMPILE_FEATURES:cxx_final>
- HAVE_INHERITING_CONSTRUCTORS_AND_FINAL=$<COMPILE_FEATURES:cxx_inheriting_constructors,cxx_final>
- )
+ target_compile_definitions(CompileFeaturesGenex3 PRIVATE ${genex_test_defs} ALLOW_LATER_STANDARDS=1)
endif()
diff --git a/Tests/CompileFeatures/cxx_attribute_deprecated.cpp b/Tests/CompileFeatures/cxx_attribute_deprecated.cpp
index 5482db8ca..8faeca870 100644
--- a/Tests/CompileFeatures/cxx_attribute_deprecated.cpp
+++ b/Tests/CompileFeatures/cxx_attribute_deprecated.cpp
@@ -1,8 +1,5 @@
-[[deprecated]] int foo()
-{
- return 0;
-}
+[[deprecated]] int foo() { return 0; }
int someFunc()
{
diff --git a/Tests/CompileFeatures/cxx_contextual_conversions.cpp b/Tests/CompileFeatures/cxx_contextual_conversions.cpp
index cbc730417..247f13f9f 100644
--- a/Tests/CompileFeatures/cxx_contextual_conversions.cpp
+++ b/Tests/CompileFeatures/cxx_contextual_conversions.cpp
@@ -17,6 +17,7 @@ public:
}
operator T&() { return val; }
operator T() const { return val; }
+
private:
T val;
};
diff --git a/Tests/CompileFeatures/cxx_digit_separators.cpp b/Tests/CompileFeatures/cxx_digit_separators.cpp
index a40ac0aac..abcd1c8fa 100644
--- a/Tests/CompileFeatures/cxx_digit_separators.cpp
+++ b/Tests/CompileFeatures/cxx_digit_separators.cpp
@@ -1,5 +1,6 @@
int someFunc()
{
- int one_thousand = 1'000; return one_thousand - 1000;
+ int one_thousand = 1'000;
+ return one_thousand - 1000;
}
diff --git a/Tests/CompileFeatures/cxx_generalized_initializers.cpp b/Tests/CompileFeatures/cxx_generalized_initializers.cpp
index cfe9d9852..bfe0d415e 100644
--- a/Tests/CompileFeatures/cxx_generalized_initializers.cpp
+++ b/Tests/CompileFeatures/cxx_generalized_initializers.cpp
@@ -1,5 +1,5 @@
#if defined(_MSC_VER) && _MSC_VER == 1800 && _MSC_FULL_VER < 180030723
-#error "VS 2013 safely supports this only with Update 3 or greater"
+# error "VS 2013 safely supports this only with Update 3 or greater"
#endif
// Dummy implementation. Test only the compiler feature.
@@ -11,11 +11,17 @@ class initializer_list
const _E* __begin_;
size_t __size_;
+#ifdef __INTEL_COMPILER
+ // The Intel compiler internally asserts the constructor overloads, so
+ // reproduce the constructor used in its <initializer_list> header.
+ initializer_list(const _E*, size_t) {}
+#else
public:
template <typename T1, typename T2>
initializer_list(T1, T2)
{
}
+#endif
};
}
diff --git a/Tests/CompileFeatures/cxx_lambda_init_captures.cpp b/Tests/CompileFeatures/cxx_lambda_init_captures.cpp
index 46f22cb51..7e337faf4 100644
--- a/Tests/CompileFeatures/cxx_lambda_init_captures.cpp
+++ b/Tests/CompileFeatures/cxx_lambda_init_captures.cpp
@@ -2,6 +2,5 @@
int someFunc()
{
int a = 0;
- return [b = static_cast<int&&>(a)]() { return b; }
- ();
+ return [b = static_cast<int&&>(a)]() { return b; }();
}
diff --git a/Tests/CompileFeatures/cxx_raw_string_literals.cpp b/Tests/CompileFeatures/cxx_raw_string_literals.cpp
index ea4d2312c..0f83a7c9a 100644
--- a/Tests/CompileFeatures/cxx_raw_string_literals.cpp
+++ b/Tests/CompileFeatures/cxx_raw_string_literals.cpp
@@ -1,7 +1,7 @@
void someFunc()
{
-const char p[] = R"(a\
+ const char p[] = R"(a\
b
c)";
}
diff --git a/Tests/CompileFeatures/cxx_relaxed_constexpr.cpp b/Tests/CompileFeatures/cxx_relaxed_constexpr.cpp
index 7b3602cd5..953148d75 100644
--- a/Tests/CompileFeatures/cxx_relaxed_constexpr.cpp
+++ b/Tests/CompileFeatures/cxx_relaxed_constexpr.cpp
@@ -22,6 +22,7 @@ constexpr int g(const int (&is)[4])
int someFunc()
{
- constexpr int k3 = g({ 4, 5, 6, 7 });
+ constexpr int values[4] = { 4, 5, 6, 7 };
+ constexpr int k3 = g(values);
return k3 - 42;
}
diff --git a/Tests/CompileFeatures/cxx_variadic_templates.cpp b/Tests/CompileFeatures/cxx_variadic_templates.cpp
index 3dc25704d..627b8d939 100644
--- a/Tests/CompileFeatures/cxx_variadic_templates.cpp
+++ b/Tests/CompileFeatures/cxx_variadic_templates.cpp
@@ -1,5 +1,5 @@
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) < 407)
-#define OLD_GNU
+# define OLD_GNU
#endif
#ifdef OLD_GNU
@@ -35,7 +35,7 @@ struct eval
};
template <template <typename...> class T, typename... U>
-struct eval<T<U...> >
+struct eval<T<U...>>
{
enum
{
@@ -62,11 +62,11 @@ 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");
+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/default_dialect.c b/Tests/CompileFeatures/default_dialect.c
index 4debd9410..6160c2f44 100644
--- a/Tests/CompileFeatures/default_dialect.c
+++ b/Tests/CompileFeatures/default_dialect.c
@@ -1,20 +1,20 @@
#if DEFAULT_C11
-#if __STDC_VERSION__ != 201112L
-#error Unexpected value for __STDC_VERSION__.
-#endif
+# if __STDC_VERSION__ < 201112L
+# error Unexpected value for __STDC_VERSION__.
+# endif
#elif DEFAULT_C99
-#if __STDC_VERSION__ != 199901L
-#error Unexpected value for __STDC_VERSION__.
-#endif
+# if __STDC_VERSION__ != 199901L
+# error Unexpected value for __STDC_VERSION__.
+# endif
#else
-#if !DEFAULT_C90
-#error Buildsystem error
-#endif
-#if defined(__STDC_VERSION__) && \
- !(defined(__SUNPRO_C) && __STDC_VERSION__ == 199409L)
-#error Unexpected __STDC_VERSION__ definition
-#endif
+# if !DEFAULT_C90
+# error Buildsystem error
+# endif
+# if defined(__STDC_VERSION__) && \
+ !(defined(__SUNPRO_C) && __STDC_VERSION__ == 199409L)
+# error Unexpected __STDC_VERSION__ definition
+# endif
#endif
int main()
diff --git a/Tests/CompileFeatures/default_dialect.cpp b/Tests/CompileFeatures/default_dialect.cpp
index 9b65b424a..3ee60a65e 100644
--- a/Tests/CompileFeatures/default_dialect.cpp
+++ b/Tests/CompileFeatures/default_dialect.cpp
@@ -2,26 +2,36 @@
template <long l>
struct Outputter;
-#if DEFAULT_CXX17
-#if __cplusplus <= 201402L
-Outputter<__cplusplus> o;
+#if defined(_MSC_VER) && defined(_MSVC_LANG)
+# define CXX_STD _MSVC_LANG
+#else
+# define CXX_STD __cplusplus
#endif
+
+#if DEFAULT_CXX20
+# if CXX_STD <= 201703L
+Outputter<CXX_STD> o;
+# endif
+#elif DEFAULT_CXX17
+# if CXX_STD <= 201402L
+Outputter<CXX_STD> o;
+# endif
#elif DEFAULT_CXX14
-#if __cplusplus != 201402L
-Outputter<__cplusplus> o;
-#endif
+# if CXX_STD != 201402L
+Outputter<CXX_STD> o;
+# endif
#elif DEFAULT_CXX11
-#if __cplusplus != 201103L
-Outputter<__cplusplus> o;
-#endif
+# if CXX_STD != 201103L
+Outputter<CXX_STD> o;
+# endif
#else
-#if !DEFAULT_CXX98
-#error Buildsystem error
-#endif
-#if __cplusplus != 199711L && __cplusplus != 1 && \
- !defined(__GXX_EXPERIMENTAL_CXX0X__)
-Outputter<__cplusplus> o;
-#endif
+# if !DEFAULT_CXX98
+# error Buildsystem error
+# endif
+# if CXX_STD != 199711L && CXX_STD != 1 && \
+ !defined(__GXX_EXPERIMENTAL_CXX0X__)
+Outputter<CXX_STD> o;
+# endif
#endif
int main()
diff --git a/Tests/CompileFeatures/genex_test.c b/Tests/CompileFeatures/genex_test.c
index 1d548406f..de408ce32 100644
--- a/Tests/CompileFeatures/genex_test.c
+++ b/Tests/CompileFeatures/genex_test.c
@@ -1,35 +1,41 @@
#ifndef EXPECT_C_STATIC_ASSERT
-#error EXPECT_C_STATIC_ASSERT not defined
+# error EXPECT_C_STATIC_ASSERT not defined
#endif
#ifndef EXPECT_C_FUNCTION_PROTOTYPES
-#error EXPECT_C_FUNCTION_PROTOTYPES not defined
+# error EXPECT_C_FUNCTION_PROTOTYPES not defined
#endif
#ifndef EXPECT_C_RESTRICT
-#error EXPECT_C_RESTRICT not defined
+# error EXPECT_C_RESTRICT not defined
#endif
-#if !EXPECT_C_STATIC_ASSERT
-#if EXPECT_C_STATIC_ASSERT
-#error "Expect c_static_assert feature"
-#endif
+#if !HAVE_C_STATIC_ASSERT
+# if EXPECT_C_STATIC_ASSERT
+# error "Expect c_static_assert feature"
+# endif
#else
-#if !EXPECT_C_STATIC_ASSERT
-#error "Expect no c_static_assert feature"
-#endif
+# if !EXPECT_C_STATIC_ASSERT
+# error "Expect no c_static_assert feature"
+# endif
#endif
-#if !EXPECT_C_FUNCTION_PROTOTYPES
-#error Expect c_function_prototypes support
+#if !HAVE_C_FUNCTION_PROTOTYPES
+# if EXPECT_C_FUNCTION_PROTOTYPES
+# error Expect c_function_prototypes support
+# endif
+#else
+# if !EXPECT_C_FUNCTION_PROTOTYPES
+# error Expect no c_function_prototypes support
+# endif
#endif
-#if !EXPECT_C_RESTRICT
-#if EXPECT_C_RESTRICT
-#error Expect c_restrict support
-#endif
+#if !HAVE_C_RESTRICT
+# if EXPECT_C_RESTRICT
+# error Expect c_restrict support
+# endif
#else
-#if !EXPECT_C_RESTRICT
-#error Expect no c_restrict support
-#endif
+# if !EXPECT_C_RESTRICT
+# error Expect no c_restrict support
+# endif
#endif
int main()
diff --git a/Tests/CompileFeatures/genex_test.cpp b/Tests/CompileFeatures/genex_test.cpp
index 5ae8a7880..53dce625a 100644
--- a/Tests/CompileFeatures/genex_test.cpp
+++ b/Tests/CompileFeatures/genex_test.cpp
@@ -1,69 +1,70 @@
#ifndef EXPECT_FINAL
-#error EXPECT_FINAL not defined
+# error EXPECT_FINAL not defined
#endif
#ifndef EXPECT_INHERITING_CONSTRUCTORS
-#error EXPECT_INHERITING_CONSTRUCTORS not defined
+# error EXPECT_INHERITING_CONSTRUCTORS not defined
#endif
#ifndef EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL
-#error EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL not defined
+# error EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL not defined
#endif
#ifndef EXPECT_OVERRIDE_CONTROL
-#error EXPECT_OVERRIDE_CONTROL not defined
+# error EXPECT_OVERRIDE_CONTROL not defined
#endif
-#if !HAVE_OVERRIDE_CONTROL
-#if EXPECT_OVERRIDE_CONTROL
-#error "Expect override control feature"
-#endif
-#else
-#if !EXPECT_OVERRIDE_CONTROL
-#error "Expect no override control feature"
+#ifdef TEST_CXX_STD
+# if !HAVE_CXX_STD_11
+# error HAVE_CXX_STD_11 is false with CXX_STANDARD == 11
+# endif
+# if HAVE_CXX_STD_14 && !defined(ALLOW_LATER_STANDARDS)
+# error HAVE_CXX_STD_14 is true with CXX_STANDARD == 11
+# endif
+# if HAVE_CXX_STD_17 && !defined(ALLOW_LATER_STANDARDS)
+# error HAVE_CXX_STD_17 is true with CXX_STANDARD == 11
+# endif
#endif
-struct A
-{
- virtual int getA() { return 7; }
-};
-
-struct B final : A
-{
- int getA() override { return 42; }
-};
-
+#if !HAVE_OVERRIDE_CONTROL
+# if EXPECT_OVERRIDE_CONTROL
+# error "Expect override control feature"
+# endif
+#else
+# if !EXPECT_OVERRIDE_CONTROL
+# error "Expect no override control feature"
+# endif
#endif
#if !HAVE_AUTO_TYPE
-#error Expect cxx_auto_type support
+# error Expect cxx_auto_type support
#endif
#if !HAVE_INHERITING_CONSTRUCTORS
-#if EXPECT_INHERITING_CONSTRUCTORS
-#error Expect cxx_inheriting_constructors support
-#endif
+# if EXPECT_INHERITING_CONSTRUCTORS
+# error Expect cxx_inheriting_constructors support
+# endif
#else
-#if !EXPECT_INHERITING_CONSTRUCTORS
-#error Expect no cxx_inheriting_constructors support
-#endif
+# if !EXPECT_INHERITING_CONSTRUCTORS
+# error Expect no cxx_inheriting_constructors support
+# endif
#endif
#if !HAVE_FINAL
-#if EXPECT_FINAL
-#error Expect cxx_final support
-#endif
+# if EXPECT_FINAL
+# error Expect cxx_final support
+# endif
#else
-#if !EXPECT_FINAL
-#error Expect no cxx_final support
-#endif
+# if !EXPECT_FINAL
+# error Expect no cxx_final support
+# endif
#endif
#if !HAVE_INHERITING_CONSTRUCTORS_AND_FINAL
-#if EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL
-#error Expect cxx_inheriting_constructors and cxx_final support
-#endif
+# if EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL
+# error Expect cxx_inheriting_constructors and cxx_final support
+# endif
#else
-#if !EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL
-#error Expect no combined cxx_inheriting_constructors and cxx_final support
-#endif
+# if !EXPECT_INHERITING_CONSTRUCTORS_AND_FINAL
+# error Expect no combined cxx_inheriting_constructors and cxx_final support
+# endif
#endif
int main()
diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt
index 692e0de0c..1433462ba 100644
--- a/Tests/CompileOptions/CMakeLists.txt
+++ b/Tests/CompileOptions/CMakeLists.txt
@@ -4,6 +4,10 @@ project(CompileOptions)
add_library(testlib other.cpp)
+if(TEST_FORTRAN)
+ enable_language(Fortran)
+endif()
+
add_executable(CompileOptions main.cpp)
macro(get_compiler_test_genex lst lang)
@@ -13,16 +17,33 @@ endmacro()
get_compiler_test_genex(c_tests C)
get_compiler_test_genex(cxx_tests CXX)
+if(TEST_FORTRAN)
+ get_compiler_test_genex(fortran_tests Fortran)
+endif()
set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS
"-DTEST_DEFINE"
"-DNEEDS_ESCAPE=\"E$CAPE\""
"$<$<CXX_COMPILER_ID:GNU>:-DTEST_DEFINE_GNU>"
+ "$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-DTEST_DEFINE_CXX_AND_GNU>"
+ "SHELL:" # produces no options
${c_tests}
${cxx_tests}
+ ${fortran_tests}
)
+if(BORLAND OR WATCOM)
+ # these compilers do not support separate -D flags
+ target_compile_definitions(CompileOptions PRIVATE NO_DEF_TESTS)
+else()
+ set_property(TARGET CompileOptions APPEND PROPERTY COMPILE_OPTIONS
+ "SHELL:-D DEF_A"
+ "$<1:SHELL:-D DEF_B>"
+ "SHELL:-D 'DEF_C' -D \"DEF_D\""
+ [[SHELL:-D "DEF_STR=\"string with spaces\""]]
+ )
+endif()
-if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland|Embarcadero")
+if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|Borland|Embarcadero" AND NOT "${CMAKE_GENERATOR}" MATCHES "NMake Makefiles")
set_property(TARGET CompileOptions APPEND PROPERTY COMPILE_OPTIONS
"-DTEST_OCTOTHORPE=\"#\""
)
@@ -42,3 +63,12 @@ target_compile_definitions(CompileOptions
"EXPECTED_C_COMPILER_VERSION=\"${CMAKE_C_COMPILER_VERSION}\""
"EXPECTED_CXX_COMPILER_VERSION=\"${CMAKE_CXX_COMPILER_VERSION}\""
)
+
+if(TEST_FORTRAN)
+ # Definitions for the C++ code to test the values
+ target_compile_definitions(CompileOptions
+ PRIVATE
+ "TEST_FORTRAN"
+ "EXPECTED_Fortran_COMPILER_VERSION=\"${CMAKE_Fortran_COMPILER_VERSION}\""
+ )
+endif()
diff --git a/Tests/CompileOptions/main.cpp b/Tests/CompileOptions/main.cpp
index 63a0480cc..ebc101762 100644
--- a/Tests/CompileOptions/main.cpp
+++ b/Tests/CompileOptions/main.cpp
@@ -1,15 +1,40 @@
#ifndef TEST_DEFINE
-#error Expected definition TEST_DEFINE
+# error Expected definition TEST_DEFINE
#endif
#ifndef NEEDS_ESCAPE
-#error Expected definition NEEDS_ESCAPE
+# error Expected definition NEEDS_ESCAPE
#endif
#ifdef DO_GNU_TESTS
-#ifndef TEST_DEFINE_GNU
-#error Expected definition TEST_DEFINE_GNU
+# ifndef TEST_DEFINE_GNU
+# error Expected definition TEST_DEFINE_GNU
+# endif
+# ifndef TEST_DEFINE_CXX_AND_GNU
+# error Expected definition TEST_DEFINE_CXX_AND_GNU
+# endif
#endif
+
+#ifndef NO_DEF_TESTS
+# ifndef DEF_A
+# error Expected definition DEF_A
+# endif
+
+# ifndef DEF_B
+# error Expected definition DEF_B
+# endif
+
+# ifndef DEF_C
+# error Expected definition DEF_C
+# endif
+
+# ifndef DEF_D
+# error Expected definition DEF_D
+# endif
+
+# ifndef DEF_STR
+# error Expected definition DEF_STR
+# endif
#endif
#include <string.h>
@@ -20,12 +45,22 @@ int main()
#ifdef TEST_OCTOTHORPE
&& strcmp(TEST_OCTOTHORPE, "#") == 0
#endif
+#ifndef NO_DEF_TESTS
+ && strcmp(DEF_STR, "string with spaces") == 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)
+ strcmp(EXPECTED_CXX_COMPILER_VERSION, TEST_CXX_COMPILER_VERSION) == 0
+#ifdef TEST_FORTRAN
+ && strcmp(EXPECTED_Fortran_COMPILER_VERSION,
+ TEST_Fortran_COMPILER_VERSION) == 0
+#endif
+ && TEST_C_COMPILER_VERSION_EQUALITY == 1 &&
+ TEST_CXX_COMPILER_VERSION_EQUALITY == 1
+#ifdef TEST_FORTRAN
+ && TEST_Fortran_COMPILER_VERSION_EQUALITY == 1
+#endif
+ )
? 0
: 1;
}
diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt
index 075faa768..2e4175442 100644
--- a/Tests/Complex/CMakeLists.txt
+++ b/Tests/Complex/CMakeLists.txt
@@ -356,6 +356,8 @@ endwhile()
set(SHOULD_BE_ZERO )
set(SHOULD_BE_ONE 1)
+set(SHOULD_BE_ZERO_AND_INDENTED )
+set(SHOULD_BE_ONE_AND_INDENTED 1)
# test elseif functionality, the mess below tries to catch problem
# of clauses being executed early or late etc
@@ -438,13 +440,6 @@ set(CMAKE_CXX_STANDARD 98)
#
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")
- string(APPEND CMAKE_CXX_FLAGS " -AA")
-endif ()
-
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
diff --git a/Tests/Complex/Cache/CMakeCache.txt b/Tests/Complex/Cache/CMakeCache.txt
index 17c55aa01..727faa2e7 100644
--- a/Tests/Complex/Cache/CMakeCache.txt
+++ b/Tests/Complex/Cache/CMakeCache.txt
@@ -5,7 +5,7 @@
# 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.
+# KEY is the name of a variable 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.
diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx
index 3b09229ba..9ddf00538 100644
--- a/Tests/Complex/Executable/complex.cxx
+++ b/Tests/Complex/Executable/complex.cxx
@@ -17,7 +17,7 @@ extern "C" {
#include <stdio.h>
#include <sys/stat.h>
#if !defined(S_ISDIR)
-#define S_ISDIR(mode) ((mode)&_S_IFDIR)
+# define S_ISDIR(mode) ((mode)&_S_IFDIR)
#endif
#ifdef COMPLEX_TEST_LINK_STATIC
@@ -45,23 +45,23 @@ void cmPassed(const char* Message, const char* m2 = "")
}
#ifndef COMPLEX_DEFINED_PRE
-#error "COMPLEX_DEFINED_PRE not defined!"
+# error "COMPLEX_DEFINED_PRE not defined!"
#endif
#ifdef COMPLEX_DEFINED
-#error "COMPLEX_DEFINED is defined but it should not!"
+# error "COMPLEX_DEFINED is defined but it should not!"
#endif
#ifndef COMPLEX_DEFINED_POST
-#error "COMPLEX_DEFINED_POST not defined!"
+# 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
+# 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.
+# error Per-configuration directory-level definition not inherited.
#endif
// ======================================================================
@@ -200,8 +200,8 @@ int main()
cmFailed(msg);
}
-// ----------------------------------------------------------------------
-// Test ADD_DEFINITIONS
+ // ----------------------------------------------------------------------
+ // Test ADD_DEFINITIONS
#ifndef CMAKE_IS_FUN
cmFailed("CMake is not fun, so it is broken and should be fixed.");
@@ -240,8 +240,8 @@ int main()
cmPassed("CMake found the listfile stack properly");
#endif
-// ----------------------------------------------------------------------
-// Test SET, VARIABLE_REQUIRES
+ // ----------------------------------------------------------------------
+ // Test SET, VARIABLE_REQUIRES
#ifdef SHOULD_NOT_BE_DEFINED
cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
@@ -261,6 +261,12 @@ int main()
cmPassed("ONE_VAR is defined.");
#endif
+#ifndef ONE_VAR_AND_INDENTED
+ cmFailed("cmakedefine is broken, ONE_VAR_AND_INDENTED is not defined.");
+#else
+ cmPassed("ONE_VAR_AND_INDENTED is defined.");
+#endif
+
#ifndef ONE_VAR_IS_DEFINED
cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
"ONE_VAR_IS_DEFINED is not defined.");
@@ -274,6 +280,12 @@ int main()
cmPassed("ZERO_VAR is not defined.");
#endif
+#ifdef ZERO_VAR_AND_INDENTED
+ cmFailed("cmakedefine is broken, ZERO_VAR_AND_INDENTED is defined.");
+#else
+ cmPassed("ZERO_VAR_AND_INDENTED is not defined.");
+#endif
+
#ifndef STRING_VAR
cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
#else
@@ -285,8 +297,8 @@ int main()
}
#endif
-// ----------------------------------------------------------------------
-// Test various IF/ELSE combinations
+ // ----------------------------------------------------------------------
+ // Test various IF/ELSE combinations
#ifdef SHOULD_NOT_BE_DEFINED_NOT
cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
@@ -728,8 +740,8 @@ int main()
cmPassed("SHOULD_BE_DEFINED_STRGREATER_EQUAL3 is defined.");
#endif
-// ----------------------------------------------------------------------
-// Test FOREACH
+ // ----------------------------------------------------------------------
+ // Test FOREACH
#ifndef FOREACH_VAR1
cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
@@ -779,8 +791,8 @@ int main()
cmPassed("WHILE command is working");
}
-// ----------------------------------------------------------------------
-// Test LOAD_CACHE
+ // ----------------------------------------------------------------------
+ // Test LOAD_CACHE
#ifndef CACHE_TEST_VAR1
cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
@@ -889,8 +901,8 @@ int main()
TestAndRemoveFile("Executable/Temp/complex-required.txt");
-// ----------------------------------------------------------------------
-// Test FIND_LIBRARY
+ // ----------------------------------------------------------------------
+ // Test FIND_LIBRARY
#ifndef FIND_DUMMY_LIB
cmFailed("the CONFIGURE_FILE command is broken, "
@@ -905,8 +917,8 @@ int main()
}
#endif
-// ----------------------------------------------------------------------
-// Test SET_SOURCE_FILES_PROPERTIES
+ // ----------------------------------------------------------------------
+ // Test SET_SOURCE_FILES_PROPERTIES
#ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting "
@@ -917,9 +929,9 @@ int main()
#endif
#if 0 // Disable until implemented everywhere.
-#ifndef FILE_DEFINE_STRING
+# ifndef FILE_DEFINE_STRING
cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag");
-#else
+# else
if(strcmp(FILE_DEFINE_STRING, "hello") != 0)
{
cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
@@ -928,7 +940,7 @@ int main()
{
cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
}
-#endif
+# endif
#endif
#ifndef FILE_HAS_ABSTRACT
@@ -961,10 +973,10 @@ int main()
// ----------------------------------------------------------------------
// Test registry (win32)
#if defined(_WIN32) && !defined(__CYGWIN__)
-#ifndef REGISTRY_TEST_PATH
+# ifndef REGISTRY_TEST_PATH
cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not "
"defined.");
-#else
+# 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 "
@@ -973,7 +985,7 @@ int main()
} else {
cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
}
-#endif
+# endif
#endif // defined(_WIN32) && !defined(__CYGWIN__)
if (strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "2.4") == 0) {
@@ -1030,6 +1042,16 @@ int main()
} else {
cmFailed("cmakedefine01 is not working for 1");
}
+ if (SHOULD_BE_ZERO_AND_INDENTED == 0) {
+ cmPassed("cmakedefine01 is working for 0 and indented");
+ } else {
+ cmFailed("cmakedefine01 is not working for 0 and indented");
+ }
+ if (SHOULD_BE_ONE_AND_INDENTED == 1) {
+ cmPassed("cmakedefine01 is working for 1 and indented");
+ } else {
+ cmFailed("cmakedefine01 is not working for 1 and indented");
+ }
#ifdef FORCE_TEST
cmFailed("CMake SET CACHE FORCE");
#else
diff --git a/Tests/Complex/Executable/complex.file.cxx b/Tests/Complex/Executable/complex.file.cxx
index cfba9ed42..55964302d 100644
--- a/Tests/Complex/Executable/complex.file.cxx
+++ b/Tests/Complex/Executable/complex.file.cxx
@@ -1,5 +1,5 @@
#if 0
-#include "cmMissingHeader.h"
+# include "cmMissingHeader.h"
#endif
int main(int, char**)
diff --git a/Tests/Complex/Executable/notInAllExe.cxx b/Tests/Complex/Executable/notInAllExe.cxx
index 2685073d6..2b857b47c 100644
--- a/Tests/Complex/Executable/notInAllExe.cxx
+++ b/Tests/Complex/Executable/notInAllExe.cxx
@@ -6,5 +6,5 @@ int main()
}
#if 1
-#error "This target should not be compiled by ALL."
+# error "This target should not be compiled by ALL."
#endif
diff --git a/Tests/Complex/Library/CMakeLists.txt b/Tests/Complex/Library/CMakeLists.txt
index dbf806e4f..64f6dc854 100644
--- a/Tests/Complex/Library/CMakeLists.txt
+++ b/Tests/Complex/Library/CMakeLists.txt
@@ -48,7 +48,7 @@ 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"
+ FULL_DOCS "A simple test property that means nothing 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.
diff --git a/Tests/Complex/Library/notInAllLib.cxx b/Tests/Complex/Library/notInAllLib.cxx
index e66ea056f..033988fd8 100644
--- a/Tests/Complex/Library/notInAllLib.cxx
+++ b/Tests/Complex/Library/notInAllLib.cxx
@@ -4,5 +4,5 @@ int notInAllLibFunc()
}
#if 1
-#error "This target should not be compiled by ALL."
+# error "This target should not be compiled by ALL."
#endif
diff --git a/Tests/Complex/Library/sharedFile.h b/Tests/Complex/Library/sharedFile.h
index e32fcb760..830cbd5e8 100644
--- a/Tests/Complex/Library/sharedFile.h
+++ b/Tests/Complex/Library/sharedFile.h
@@ -1,12 +1,12 @@
#if defined(_WIN32) || defined(WIN32) /* Win32 version */
-#ifdef CMakeTestLibraryShared_EXPORTS
-#define CMakeTest_EXPORT __declspec(dllexport)
-#else
-#define CMakeTest_EXPORT __declspec(dllimport)
-#endif
+# ifdef CMakeTestLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+# else
+# define CMakeTest_EXPORT __declspec(dllimport)
+# endif
#else
/* unix needs nothing */
-#define CMakeTest_EXPORT
+# define CMakeTest_EXPORT
#endif
CMakeTest_EXPORT int sharedFunction();
diff --git a/Tests/Complex/Library/testConly.h b/Tests/Complex/Library/testConly.h
index 9b0fb73ff..02b28ccab 100644
--- a/Tests/Complex/Library/testConly.h
+++ b/Tests/Complex/Library/testConly.h
@@ -1,12 +1,12 @@
#if defined(_WIN32) || defined(WIN32) /* Win32 version */
-#ifdef CMakeTestCLibraryShared_EXPORTS
-#define CMakeTest_EXPORT __declspec(dllexport)
-#else
-#define CMakeTest_EXPORT __declspec(dllimport)
-#endif
+# ifdef CMakeTestCLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+# else
+# define CMakeTest_EXPORT __declspec(dllimport)
+# endif
#else
/* unix needs nothing */
-#define CMakeTest_EXPORT
+# define CMakeTest_EXPORT
#endif
CMakeTest_EXPORT int CsharedFunction();
diff --git a/Tests/Complex/VarTests.cmake b/Tests/Complex/VarTests.cmake
index 8be59be5e..9761986ab 100644
--- a/Tests/Complex/VarTests.cmake
+++ b/Tests/Complex/VarTests.cmake
@@ -2,6 +2,7 @@
# Test SET
#
set (ZERO_VAR 0)
+set (ZERO_VAR_AND_INDENTED 0)
set (ZERO_VAR2 0)
if(ZERO_VAR)
@@ -11,6 +12,7 @@ else()
endif()
set(ONE_VAR 1)
+set(ONE_VAR_AND_INDENTED 1)
set(ONE_VAR2 1)
set(STRING_VAR "CMake is great" CACHE STRING "test a cache variable")
diff --git a/Tests/Complex/cmTestConfigure.h.in b/Tests/Complex/cmTestConfigure.h.in
index d7424b184..72317bcc8 100644
--- a/Tests/Complex/cmTestConfigure.h.in
+++ b/Tests/Complex/cmTestConfigure.h.in
@@ -1,8 +1,10 @@
// Test SET, VARIABLE_REQUIRES
#cmakedefine ONE_VAR
+# cmakedefine ONE_VAR_AND_INDENTED
#cmakedefine ONE_VAR_IS_DEFINED
#cmakedefine ZERO_VAR
+# cmakedefine ZERO_VAR_AND_INDENTED
#define STRING_VAR "${STRING_VAR}"
@@ -32,6 +34,8 @@
#cmakedefine01 SHOULD_BE_ZERO
#cmakedefine01 SHOULD_BE_ONE
+# cmakedefine01 SHOULD_BE_ZERO_AND_INDENTED
+# cmakedefine01 SHOULD_BE_ONE_AND_INDENTED
// Needed to check for files
#define BINARY_DIR "${Complex_BINARY_DIR}"
diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt
index 1b833b241..628cd4ec3 100644
--- a/Tests/ComplexOneConfig/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/CMakeLists.txt
@@ -313,6 +313,8 @@ endwhile()
set(SHOULD_BE_ZERO )
set(SHOULD_BE_ONE 1)
+set(SHOULD_BE_ZERO_AND_INDENTED )
+set(SHOULD_BE_ONE_AND_INDENTED 1)
# test elseif functionality, the mess below tries to catch problem
# of clauses being executed early or late etc
@@ -395,13 +397,6 @@ set(CMAKE_CXX_STANDARD 98)
#
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")
- string(APPEND CMAKE_CXX_FLAGS " -AA")
-endif ()
-
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
diff --git a/Tests/ComplexOneConfig/Cache/CMakeCache.txt b/Tests/ComplexOneConfig/Cache/CMakeCache.txt
index 17c55aa01..727faa2e7 100644
--- a/Tests/ComplexOneConfig/Cache/CMakeCache.txt
+++ b/Tests/ComplexOneConfig/Cache/CMakeCache.txt
@@ -5,7 +5,7 @@
# 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.
+# KEY is the name of a variable 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.
diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx
index 9e4eaadf7..5b5089960 100644
--- a/Tests/ComplexOneConfig/Executable/complex.cxx
+++ b/Tests/ComplexOneConfig/Executable/complex.cxx
@@ -17,7 +17,7 @@ extern "C" {
#include <stdio.h>
#include <sys/stat.h>
#if !defined(S_ISDIR)
-#define S_ISDIR(mode) ((mode)&_S_IFDIR)
+# define S_ISDIR(mode) ((mode)&_S_IFDIR)
#endif
#ifdef COMPLEX_TEST_LINK_STATIC
@@ -45,23 +45,23 @@ void cmPassed(const char* Message, const char* m2 = "")
}
#ifndef COMPLEX_DEFINED_PRE
-#error "COMPLEX_DEFINED_PRE not defined!"
+# error "COMPLEX_DEFINED_PRE not defined!"
#endif
#ifdef COMPLEX_DEFINED
-#error "COMPLEX_DEFINED is defined but it should not!"
+# error "COMPLEX_DEFINED is defined but it should not!"
#endif
#ifndef COMPLEX_DEFINED_POST
-#error "COMPLEX_DEFINED_POST not defined!"
+# 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
+# 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.
+# error Per-configuration directory-level definition not inherited.
#endif
// ======================================================================
@@ -200,8 +200,8 @@ int main()
cmFailed(msg);
}
-// ----------------------------------------------------------------------
-// Test ADD_DEFINITIONS
+ // ----------------------------------------------------------------------
+ // Test ADD_DEFINITIONS
#ifndef CMAKE_IS_FUN
cmFailed("CMake is not fun, so it is broken and should be fixed.");
@@ -240,8 +240,8 @@ int main()
cmPassed("CMake found the listfile stack properly");
#endif
-// ----------------------------------------------------------------------
-// Test SET, VARIABLE_REQUIRES
+ // ----------------------------------------------------------------------
+ // Test SET, VARIABLE_REQUIRES
#ifdef SHOULD_NOT_BE_DEFINED
cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
@@ -261,6 +261,12 @@ int main()
cmPassed("ONE_VAR is defined.");
#endif
+#ifndef ONE_VAR_AND_INDENTED
+ cmFailed("cmakedefine is broken, ONE_VAR_AND_INDENTED is not defined.");
+#else
+ cmPassed("ONE_VAR_AND_INDENTED is defined.");
+#endif
+
#ifndef ONE_VAR_IS_DEFINED
cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
"ONE_VAR_IS_DEFINED is not defined.");
@@ -274,6 +280,12 @@ int main()
cmPassed("ZERO_VAR is not defined.");
#endif
+#ifdef ZERO_VAR_AND_INDENTED
+ cmFailed("cmakedefine is broken, ZERO_VAR_AND_INDENTED is defined.");
+#else
+ cmPassed("ZERO_VAR_AND_INDENTED is not defined.");
+#endif
+
#ifndef STRING_VAR
cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
#else
@@ -285,8 +297,8 @@ int main()
}
#endif
-// ----------------------------------------------------------------------
-// Test various IF/ELSE combinations
+ // ----------------------------------------------------------------------
+ // Test various IF/ELSE combinations
#ifdef SHOULD_NOT_BE_DEFINED_NOT
cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined.");
@@ -728,8 +740,8 @@ int main()
cmPassed("SHOULD_BE_DEFINED_STRGREATER_EQUAL3 is defined.");
#endif
-// ----------------------------------------------------------------------
-// Test FOREACH
+ // ----------------------------------------------------------------------
+ // Test FOREACH
#ifndef FOREACH_VAR1
cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
@@ -779,8 +791,8 @@ int main()
cmPassed("WHILE command is working");
}
-// ----------------------------------------------------------------------
-// Test LOAD_CACHE
+ // ----------------------------------------------------------------------
+ // Test LOAD_CACHE
#ifndef CACHE_TEST_VAR1
cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
@@ -889,8 +901,8 @@ int main()
TestAndRemoveFile("Executable/Temp/complex-required.txt");
-// ----------------------------------------------------------------------
-// Test FIND_LIBRARY
+ // ----------------------------------------------------------------------
+ // Test FIND_LIBRARY
#ifndef FIND_DUMMY_LIB
cmFailed("the CONFIGURE_FILE command is broken, "
@@ -905,8 +917,8 @@ int main()
}
#endif
-// ----------------------------------------------------------------------
-// Test SET_SOURCE_FILES_PROPERTIES
+ // ----------------------------------------------------------------------
+ // Test SET_SOURCE_FILES_PROPERTIES
#ifndef FILE_HAS_EXTRA_COMPILE_FLAGS
cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting "
@@ -917,9 +929,9 @@ int main()
#endif
#if 0 // Disable until implemented everywhere.
-#ifndef FILE_DEFINE_STRING
+# ifndef FILE_DEFINE_STRING
cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag");
-#else
+# else
if(strcmp(FILE_DEFINE_STRING, "hello") != 0)
{
cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly");
@@ -928,7 +940,7 @@ int main()
{
cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag");
}
-#endif
+# endif
#endif
#ifndef FILE_HAS_ABSTRACT
@@ -961,10 +973,10 @@ int main()
// ----------------------------------------------------------------------
// Test registry (win32)
#if defined(_WIN32) && !defined(__CYGWIN__)
-#ifndef REGISTRY_TEST_PATH
+# ifndef REGISTRY_TEST_PATH
cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not "
"defined.");
-#else
+# 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 "
@@ -973,7 +985,7 @@ int main()
} else {
cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH);
}
-#endif
+# endif
#endif // defined(_WIN32) && !defined(__CYGWIN__)
if (strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "2.4") == 0) {
@@ -1030,6 +1042,16 @@ int main()
} else {
cmFailed("cmakedefine01 is not working for 1");
}
+ if (SHOULD_BE_ZERO_AND_INDENTED == 0) {
+ cmPassed("cmakedefine01 is working for 0 and indented");
+ } else {
+ cmFailed("cmakedefine01 is not working for 0 and indented");
+ }
+ if (SHOULD_BE_ONE_AND_INDENTED == 1) {
+ cmPassed("cmakedefine01 is working for 1 and indented");
+ } else {
+ cmFailed("cmakedefine01 is not working for 1 and indented");
+ }
#ifdef FORCE_TEST
cmFailed("CMake SET CACHE FORCE");
#else
diff --git a/Tests/ComplexOneConfig/Executable/complex.file.cxx b/Tests/ComplexOneConfig/Executable/complex.file.cxx
index cfba9ed42..55964302d 100644
--- a/Tests/ComplexOneConfig/Executable/complex.file.cxx
+++ b/Tests/ComplexOneConfig/Executable/complex.file.cxx
@@ -1,5 +1,5 @@
#if 0
-#include "cmMissingHeader.h"
+# include "cmMissingHeader.h"
#endif
int main(int, char**)
diff --git a/Tests/ComplexOneConfig/Executable/notInAllExe.cxx b/Tests/ComplexOneConfig/Executable/notInAllExe.cxx
index 2685073d6..2b857b47c 100644
--- a/Tests/ComplexOneConfig/Executable/notInAllExe.cxx
+++ b/Tests/ComplexOneConfig/Executable/notInAllExe.cxx
@@ -6,5 +6,5 @@ int main()
}
#if 1
-#error "This target should not be compiled by ALL."
+# error "This target should not be compiled by ALL."
#endif
diff --git a/Tests/ComplexOneConfig/Library/CMakeLists.txt b/Tests/ComplexOneConfig/Library/CMakeLists.txt
index dbf806e4f..64f6dc854 100644
--- a/Tests/ComplexOneConfig/Library/CMakeLists.txt
+++ b/Tests/ComplexOneConfig/Library/CMakeLists.txt
@@ -48,7 +48,7 @@ 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"
+ FULL_DOCS "A simple test property that means nothing 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.
diff --git a/Tests/ComplexOneConfig/Library/notInAllLib.cxx b/Tests/ComplexOneConfig/Library/notInAllLib.cxx
index e66ea056f..033988fd8 100644
--- a/Tests/ComplexOneConfig/Library/notInAllLib.cxx
+++ b/Tests/ComplexOneConfig/Library/notInAllLib.cxx
@@ -4,5 +4,5 @@ int notInAllLibFunc()
}
#if 1
-#error "This target should not be compiled by ALL."
+# error "This target should not be compiled by ALL."
#endif
diff --git a/Tests/ComplexOneConfig/Library/sharedFile.h b/Tests/ComplexOneConfig/Library/sharedFile.h
index e32fcb760..830cbd5e8 100644
--- a/Tests/ComplexOneConfig/Library/sharedFile.h
+++ b/Tests/ComplexOneConfig/Library/sharedFile.h
@@ -1,12 +1,12 @@
#if defined(_WIN32) || defined(WIN32) /* Win32 version */
-#ifdef CMakeTestLibraryShared_EXPORTS
-#define CMakeTest_EXPORT __declspec(dllexport)
-#else
-#define CMakeTest_EXPORT __declspec(dllimport)
-#endif
+# ifdef CMakeTestLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+# else
+# define CMakeTest_EXPORT __declspec(dllimport)
+# endif
#else
/* unix needs nothing */
-#define CMakeTest_EXPORT
+# define CMakeTest_EXPORT
#endif
CMakeTest_EXPORT int sharedFunction();
diff --git a/Tests/ComplexOneConfig/Library/testConly.h b/Tests/ComplexOneConfig/Library/testConly.h
index 9b0fb73ff..02b28ccab 100644
--- a/Tests/ComplexOneConfig/Library/testConly.h
+++ b/Tests/ComplexOneConfig/Library/testConly.h
@@ -1,12 +1,12 @@
#if defined(_WIN32) || defined(WIN32) /* Win32 version */
-#ifdef CMakeTestCLibraryShared_EXPORTS
-#define CMakeTest_EXPORT __declspec(dllexport)
-#else
-#define CMakeTest_EXPORT __declspec(dllimport)
-#endif
+# ifdef CMakeTestCLibraryShared_EXPORTS
+# define CMakeTest_EXPORT __declspec(dllexport)
+# else
+# define CMakeTest_EXPORT __declspec(dllimport)
+# endif
#else
/* unix needs nothing */
-#define CMakeTest_EXPORT
+# define CMakeTest_EXPORT
#endif
CMakeTest_EXPORT int CsharedFunction();
diff --git a/Tests/ComplexOneConfig/VarTests.cmake b/Tests/ComplexOneConfig/VarTests.cmake
index 7dd851974..42afd19ea 100644
--- a/Tests/ComplexOneConfig/VarTests.cmake
+++ b/Tests/ComplexOneConfig/VarTests.cmake
@@ -2,6 +2,7 @@
# Test SET
#
set (ZERO_VAR 0)
+set (ZERO_VAR_AND_INDENTED 0)
set (ZERO_VAR2 0)
if(ZERO_VAR)
@@ -11,6 +12,7 @@ else()
endif()
set(ONE_VAR 1)
+set(ONE_VAR_AND_INDENTED 1)
set(ONE_VAR2 1)
set(STRING_VAR "CMake is great" CACHE STRING "test a cache variable")
diff --git a/Tests/ComplexOneConfig/cmTestConfigure.h.in b/Tests/ComplexOneConfig/cmTestConfigure.h.in
index d7424b184..72317bcc8 100644
--- a/Tests/ComplexOneConfig/cmTestConfigure.h.in
+++ b/Tests/ComplexOneConfig/cmTestConfigure.h.in
@@ -1,8 +1,10 @@
// Test SET, VARIABLE_REQUIRES
#cmakedefine ONE_VAR
+# cmakedefine ONE_VAR_AND_INDENTED
#cmakedefine ONE_VAR_IS_DEFINED
#cmakedefine ZERO_VAR
+# cmakedefine ZERO_VAR_AND_INDENTED
#define STRING_VAR "${STRING_VAR}"
@@ -32,6 +34,8 @@
#cmakedefine01 SHOULD_BE_ZERO
#cmakedefine01 SHOULD_BE_ONE
+# cmakedefine01 SHOULD_BE_ZERO_AND_INDENTED
+# cmakedefine01 SHOULD_BE_ONE_AND_INDENTED
// Needed to check for files
#define BINARY_DIR "${Complex_BINARY_DIR}"
diff --git a/Tests/Contracts/Trilinos/CMakeLists.txt b/Tests/Contracts/Trilinos/CMakeLists.txt
index 8d74ca574..4d7062bbd 100644
--- a/Tests/Contracts/Trilinos/CMakeLists.txt
+++ b/Tests/Contracts/Trilinos/CMakeLists.txt
@@ -6,24 +6,7 @@ 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()
+include(${CMAKE_CURRENT_SOURCE_DIR}/../Home.cmake)
message(STATUS "HOME='${HOME}'")
if(NOT DEFINED url)
diff --git a/Tests/Contracts/VTK/CMakeLists.txt b/Tests/Contracts/VTK/CMakeLists.txt
index ef19325a4..c946499b6 100644
--- a/Tests/Contracts/VTK/CMakeLists.txt
+++ b/Tests/Contracts/VTK/CMakeLists.txt
@@ -5,24 +5,7 @@ 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()
+include(${CMAKE_CURRENT_SOURCE_DIR}/../Home.cmake)
set(base_dir "${HOME}/.cmake/Contracts/VTK")
diff --git a/Tests/Cuda/CMakeLists.txt b/Tests/Cuda/CMakeLists.txt
index de4850158..a30071fd3 100644
--- a/Tests/Cuda/CMakeLists.txt
+++ b/Tests/Cuda/CMakeLists.txt
@@ -2,6 +2,9 @@
ADD_TEST_MACRO(Cuda.Complex CudaComplex)
ADD_TEST_MACRO(Cuda.ConsumeCompileFeatures CudaConsumeCompileFeatures)
ADD_TEST_MACRO(Cuda.ObjectLibrary CudaObjectLibrary)
+ADD_TEST_MACRO(Cuda.MixedStandardLevels MixedStandardLevels)
+ADD_TEST_MACRO(Cuda.NotEnabled CudaNotEnabled)
ADD_TEST_MACRO(Cuda.ToolkitInclude CudaToolkitInclude)
+ADD_TEST_MACRO(Cuda.ProperDeviceLibraries ProperDeviceLibraries)
ADD_TEST_MACRO(Cuda.ProperLinkFlags ProperLinkFlags)
ADD_TEST_MACRO(Cuda.WithC CudaWithC)
diff --git a/Tests/Cuda/Complex/CMakeLists.txt b/Tests/Cuda/Complex/CMakeLists.txt
index 450ef487c..d3d4b7c28 100644
--- a/Tests/Cuda/Complex/CMakeLists.txt
+++ b/Tests/Cuda/Complex/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7)
-project (CudaComplex CXX CUDA)
+project (Complex CXX CUDA)
#Goal for this example:
#build a cpp dynamic library base
@@ -12,7 +12,7 @@ project (CudaComplex CXX CUDA)
#lastly build a cpp executable that uses this last cuda dynamic library
#this tests that we can properly handle linking cuda and cpp together
-#and also bulding cpp targets that need cuda implicit libraries
+#and also building cpp targets that need cuda implicit libraries
#verify that we can pass explicit cuda arch flags
string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30")
@@ -42,7 +42,6 @@ add_executable(CudaComplex main.cpp)
target_link_libraries(CudaComplex PUBLIC CudaComplexMixedLib)
if(APPLE)
- # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
- # the static cuda runtime can find it at runtime.
- target_link_libraries(CudaComplex PRIVATE -Wl,-rpath,/usr/local/cuda/lib)
+ # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
+ set_property(TARGET CudaComplex PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
diff --git a/Tests/Cuda/Complex/dynamic.cpp b/Tests/Cuda/Complex/dynamic.cpp
index 3848ce7b5..38da6a6a8 100644
--- a/Tests/Cuda/Complex/dynamic.cpp
+++ b/Tests/Cuda/Complex/dynamic.cpp
@@ -1,8 +1,8 @@
#ifdef _WIN32
-#define EXPORT __declspec(dllexport)
+# define EXPORT __declspec(dllexport)
#else
-#define EXPORT
+# define EXPORT
#endif
EXPORT int dynamic_base_func(int x)
diff --git a/Tests/Cuda/Complex/dynamic.cu b/Tests/Cuda/Complex/dynamic.cu
index a76973d62..c3d8affa8 100644
--- a/Tests/Cuda/Complex/dynamic.cu
+++ b/Tests/Cuda/Complex/dynamic.cu
@@ -4,9 +4,9 @@
#include <string>
#ifdef _WIN32
-#define EXPORT __declspec(dllexport)
+# define EXPORT __declspec(dllexport)
#else
-#define EXPORT
+# define EXPORT
#endif
int dynamic_base_func(int);
diff --git a/Tests/Cuda/Complex/main.cpp b/Tests/Cuda/Complex/main.cpp
index 249823535..6ca5952a5 100644
--- a/Tests/Cuda/Complex/main.cpp
+++ b/Tests/Cuda/Complex/main.cpp
@@ -4,9 +4,9 @@
#include "file2.h"
#ifdef _WIN32
-#define IMPORT __declspec(dllimport)
+# define IMPORT __declspec(dllimport)
#else
-#define IMPORT
+# define IMPORT
#endif
IMPORT int choose_cuda_device();
diff --git a/Tests/Cuda/Complex/mixed.cpp b/Tests/Cuda/Complex/mixed.cpp
index bd32e5199..38a1f0c75 100644
--- a/Tests/Cuda/Complex/mixed.cpp
+++ b/Tests/Cuda/Complex/mixed.cpp
@@ -1,10 +1,10 @@
#ifdef _WIN32
-#define EXPORT __declspec(dllexport)
-#define IMPORT __declspec(dllimport)
+# define EXPORT __declspec(dllexport)
+# define IMPORT __declspec(dllimport)
#else
-#define EXPORT
-#define IMPORT
+# define EXPORT
+# define IMPORT
#endif
int dynamic_base_func(int);
diff --git a/Tests/Cuda/Complex/mixed.cu b/Tests/Cuda/Complex/mixed.cu
index a81ccb731..5b85aecce 100644
--- a/Tests/Cuda/Complex/mixed.cu
+++ b/Tests/Cuda/Complex/mixed.cu
@@ -5,11 +5,11 @@
#include "file2.h"
#ifdef _WIN32
-#define EXPORT __declspec(dllexport)
-#define IMPORT __declspec(dllimport)
+# define EXPORT __declspec(dllexport)
+# define IMPORT __declspec(dllimport)
#else
-#define EXPORT
-#define IMPORT
+# define EXPORT
+# define IMPORT
#endif
result_type __device__ file1_func(int x);
diff --git a/Tests/Cuda/ConsumeCompileFeatures/CMakeLists.txt b/Tests/Cuda/ConsumeCompileFeatures/CMakeLists.txt
index 9fda2d02b..7098a7df5 100644
--- a/Tests/Cuda/ConsumeCompileFeatures/CMakeLists.txt
+++ b/Tests/Cuda/ConsumeCompileFeatures/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7)
-project (CudaConsumeCompileFeatures CXX CUDA)
+project (ConsumeCompileFeatures CXX CUDA)
#Goal for this example:
#build a c++11 library that express a c++11 public compile feature
diff --git a/Tests/Cuda/ObjectLibrary/CMakeLists.txt b/Tests/Cuda/ObjectLibrary/CMakeLists.txt
index 1d93be732..395bd3881 100644
--- a/Tests/Cuda/ObjectLibrary/CMakeLists.txt
+++ b/Tests/Cuda/ObjectLibrary/CMakeLists.txt
@@ -1,17 +1,20 @@
cmake_minimum_required(VERSION 3.7)
-project (CudaObjectLibrary CUDA CXX)
+project (ObjectLibrary CUDA CXX)
#Goal for this example:
-
-#build a object files some with cuda and some without than
-#embed these into an executable
+#
+#Build C++ and CUDA object files and than use them to make an executable
+#Make sure that CMake logic to handle object output when multiple files
+#with the same name works
+add_subdirectory(Conflicts)
add_library(CudaMixedObjectLib OBJECT static.cu static.cpp)
add_executable(CudaObjectLibrary
main.cpp
- $<TARGET_OBJECTS:CudaMixedObjectLib>)
+ $<TARGET_OBJECTS:CudaMixedObjectLib>
+ $<TARGET_OBJECTS:CudaConflicts>)
+
if(APPLE)
- # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
- # the static cuda runtime can find it at runtime.
- target_link_libraries(CudaObjectLibrary PRIVATE -Wl,-rpath,/usr/local/cuda/lib)
+ # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
+ set_property(TARGET CudaObjectLibrary PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
diff --git a/Tests/Cuda/ObjectLibrary/main.cpp b/Tests/Cuda/ObjectLibrary/main.cpp
index 4d2f89028..e28f08851 100644
--- a/Tests/Cuda/ObjectLibrary/main.cpp
+++ b/Tests/Cuda/ObjectLibrary/main.cpp
@@ -1,22 +1,18 @@
#include <iostream>
-int static_func(int);
-int file1_sq_func(int);
+int cpp_sq_func(int);
+int cu1_sq_func(int);
+int cu2_sq_func(int);
-int test_functions()
+bool test_functions()
{
- return file1_sq_func(static_func(42));
+ return (cu1_sq_func(42) == cpp_sq_func(42)) &&
+ (cu2_sq_func(42) == cpp_sq_func(42));
}
int main(int argc, char** argv)
{
- if (test_functions() == 1) {
- return 1;
- }
- std::cout
- << "this executable doesn't use cuda code, just call methods defined"
- << std::endl;
- std::cout << "in object files that have cuda code" << std::endl;
- return 0;
+ int result = test_functions() ? 0 : 1;
+ return result;
}
diff --git a/Tests/Cuda/ObjectLibrary/static.cpp b/Tests/Cuda/ObjectLibrary/static.cpp
index 6db1f914f..527f7f554 100644
--- a/Tests/Cuda/ObjectLibrary/static.cpp
+++ b/Tests/Cuda/ObjectLibrary/static.cpp
@@ -1,6 +1,6 @@
int file1_sq_func(int);
-int static_func(int x)
+int cpp_sq_func(int x)
{
- return file1_sq_func(x);
+ return x * x;
}
diff --git a/Tests/Cuda/ObjectLibrary/static.cu b/Tests/Cuda/ObjectLibrary/static.cu
index aa357295a..37bb8391e 100644
--- a/Tests/Cuda/ObjectLibrary/static.cu
+++ b/Tests/Cuda/ObjectLibrary/static.cu
@@ -3,7 +3,7 @@
#include <cuda_runtime.h>
#include <iostream>
-int __host__ file1_sq_func(int x)
+int __host__ cu1_sq_func(int x)
{
cudaError_t err;
int nDevices = 0;
@@ -13,9 +13,5 @@ int __host__ file1_sq_func(int x)
std::cerr << "err: " << err << std::endl;
return 1;
}
- std::cout << "this library uses cuda code" << std::endl;
- std::cout << "you have " << nDevices << " devices that support cuda"
- << std::endl;
-
return x * x;
}
diff --git a/Tests/Cuda/WithC/CMakeLists.txt b/Tests/Cuda/WithC/CMakeLists.txt
index 1f25ab43e..69aa3f992 100644
--- a/Tests/Cuda/WithC/CMakeLists.txt
+++ b/Tests/Cuda/WithC/CMakeLists.txt
@@ -1,12 +1,11 @@
cmake_minimum_required(VERSION 3.7)
-project(CudaComplex CUDA C)
+project(WithC CUDA C)
string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30")
add_executable(CudaWithC main.c cuda.cu)
if(APPLE)
- # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
- # the static cuda runtime can find it at runtime.
- target_link_libraries(CudaWithC PRIVATE -Wl,-rpath,/usr/local/cuda/lib)
+ # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
+ set_property(TARGET CudaWithC PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
diff --git a/Tests/Cuda/WithC/main.c b/Tests/Cuda/WithC/main.c
index cb5fddc1f..5f3c781b0 100644
--- a/Tests/Cuda/WithC/main.c
+++ b/Tests/Cuda/WithC/main.c
@@ -1,7 +1,7 @@
extern int use_cuda(void);
#ifdef _WIN32
-#include <windows.h>
+# include <windows.h>
#endif
int main()
diff --git a/Tests/CudaOnly/CMakeLists.txt b/Tests/CudaOnly/CMakeLists.txt
index 5f456fcf4..f1fd34487 100644
--- a/Tests/CudaOnly/CMakeLists.txt
+++ b/Tests/CudaOnly/CMakeLists.txt
@@ -1,6 +1,23 @@
+ADD_TEST_MACRO(CudaOnly.CircularLinkLine CudaOnlyCircularLinkLine)
ADD_TEST_MACRO(CudaOnly.EnableStandard CudaOnlyEnableStandard)
ADD_TEST_MACRO(CudaOnly.ExportPTX CudaOnlyExportPTX)
+ADD_TEST_MACRO(CudaOnly.GPUDebugFlag CudaOnlyGPUDebugFlag)
+ADD_TEST_MACRO(CudaOnly.ResolveDeviceSymbols CudaOnlyResolveDeviceSymbols)
ADD_TEST_MACRO(CudaOnly.SeparateCompilation CudaOnlySeparateCompilation)
ADD_TEST_MACRO(CudaOnly.WithDefs CudaOnlyWithDefs)
-ADD_TEST_MACRO(CudaOnly.ResolveDeviceSymbols CudaOnlyResolveDeviceSymbols)
+
+add_test(NAME CudaOnly.DontResolveDeviceSymbols COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMAKE_CURRENT_SOURCE_DIR}/DontResolveDeviceSymbols/"
+ "${CMAKE_CURRENT_BINARY_DIR}/DontResolveDeviceSymbols/"
+ ${build_generator_args}
+ --build-project DontResolveDeviceSymbols
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
+
+if(MSVC)
+ ADD_TEST_MACRO(CudaOnly.PDB CudaOnlyPDB)
+endif()
diff --git a/Tests/CudaOnly/EnableStandard/CMakeLists.txt b/Tests/CudaOnly/EnableStandard/CMakeLists.txt
index 35a1deb69..54e2c1413 100644
--- a/Tests/CudaOnly/EnableStandard/CMakeLists.txt
+++ b/Tests/CudaOnly/EnableStandard/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7)
-project (CudaOnlyEnableStandard CUDA)
+project (EnableStandard CUDA)
#Goal for this example:
#build cuda sources that require C++11 to be enabled.
diff --git a/Tests/CudaOnly/EnableStandard/main.cu b/Tests/CudaOnly/EnableStandard/main.cu
index f21958371..740c832a6 100644
--- a/Tests/CudaOnly/EnableStandard/main.cu
+++ b/Tests/CudaOnly/EnableStandard/main.cu
@@ -2,9 +2,9 @@
#include <iostream>
#ifdef _WIN32
-#define IMPORT __declspec(dllimport)
+# define IMPORT __declspec(dllimport)
#else
-#define IMPORT
+# define IMPORT
#endif
int static_cuda11_func(int);
diff --git a/Tests/CudaOnly/EnableStandard/shared.cu b/Tests/CudaOnly/EnableStandard/shared.cu
index ccdd0b28e..004cb8372 100644
--- a/Tests/CudaOnly/EnableStandard/shared.cu
+++ b/Tests/CudaOnly/EnableStandard/shared.cu
@@ -2,9 +2,9 @@
#include <type_traits>
#ifdef _WIN32
-#define EXPORT __declspec(dllexport)
+# define EXPORT __declspec(dllexport)
#else
-#define EXPORT
+# define EXPORT
#endif
using tt = std::true_type;
diff --git a/Tests/CudaOnly/ExportPTX/CMakeLists.txt b/Tests/CudaOnly/ExportPTX/CMakeLists.txt
index 10249c614..ff6e77c33 100644
--- a/Tests/CudaOnly/ExportPTX/CMakeLists.txt
+++ b/Tests/CudaOnly/ExportPTX/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
-project (CudaOnlyExportPTX CUDA)
+project (ExportPTX CUDA)
#Goal for this example:
# How to generate PTX files instead of OBJECT files
@@ -67,9 +67,8 @@ target_compile_definitions(CudaOnlyExportPTX PRIVATE
"CONFIG_TYPE=gen_$<LOWER_CASE:$<CONFIG>>")
if(APPLE)
- # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
- # the static cuda runtime can find it at runtime.
- target_link_libraries(CudaOnlyExportPTX PRIVATE -Wl,-rpath,/usr/local/cuda/lib)
+ # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
+ set_property(TARGET CudaOnlyExportPTX PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
#Verify that we can install object targets properly
diff --git a/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt b/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt
index b96bb984b..796e13382 100644
--- a/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt
+++ b/Tests/CudaOnly/ResolveDeviceSymbols/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.7)
-project (CudaOnlyResolveDeviceSymbols CUDA)
+project (ResolveDeviceSymbols CUDA)
# Find nm and dumpbin
if(CMAKE_NM)
@@ -16,12 +16,12 @@ else()
endif()
#Goal for this example:
-#Build a static library that defines multiple methods and kernels that
-#use each other.
-#Use a custom command to build an executable that uses this static library
-#We do these together to verify that we can get a static library to do
-#device symbol linking, and not have it done when the executable is made
-string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30")
+# Build a static library that defines multiple methods and kernels that
+# use each other.
+# Resolve the device symbols into that static library
+# Verify that we can't use those device symbols from anything that links
+# to the static library
+string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=[compute_30] -gencode arch=compute_50,code=\\\"compute_50\\\"")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CUDA_STANDARD 11)
@@ -43,10 +43,13 @@ add_custom_command(TARGET CUDAResolveDeviceLib POST_BUILD
endif()
add_executable(CudaOnlyResolveDeviceSymbols main.cu)
+set_target_properties(CudaOnlyResolveDeviceSymbols
+ PROPERTIES
+ CUDA_SEPARABLE_COMPILATION ON)
+
target_link_libraries(CudaOnlyResolveDeviceSymbols PRIVATE CUDAResolveDeviceLib)
if(APPLE)
- # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
- # the static cuda runtime can find it at runtime.
- target_link_libraries(CudaOnlyResolveDeviceSymbols PRIVATE -Wl,-rpath,/usr/local/cuda/lib)
+ # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
+ set_property(TARGET CudaOnlyResolveDeviceSymbols PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
diff --git a/Tests/CudaOnly/ResolveDeviceSymbols/main.cu b/Tests/CudaOnly/ResolveDeviceSymbols/main.cu
index b4b5b9eac..d464f964e 100644
--- a/Tests/CudaOnly/ResolveDeviceSymbols/main.cu
+++ b/Tests/CudaOnly/ResolveDeviceSymbols/main.cu
@@ -62,17 +62,8 @@ int main(int argc, char** argv)
return 0;
}
- cudaError_t err;
- file2_launch_kernel(42);
- err = cudaGetLastError();
- if (err != cudaSuccess) {
- std::cerr << "file2_launch_kernel: kernel launch failed: "
- << cudaGetErrorString(err) << std::endl;
- return 1;
- }
-
main_launch_kernel(1);
- err = cudaGetLastError();
+ cudaError_t err = cudaGetLastError();
if (err == cudaSuccess) {
// This kernel launch should fail as the file2_func was device linked
// into the static library and is not usable by the executable
diff --git a/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt b/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt
index 3d4a17073..1e574d6cc 100644
--- a/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt
+++ b/Tests/CudaOnly/SeparateCompilation/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.7)
-project (CudaOnlySeparateCompilation CUDA)
+project (SeparateCompilation CUDA)
#Goal for this example:
#Build a static library that defines multiple methods and kernels that
@@ -9,11 +9,18 @@ project (CudaOnlySeparateCompilation CUDA)
#and executables.
#We complicate the matter by also testing that multiple static libraries
#all containing cuda separable compilation code links properly
-string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30")
+string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=\\\"compute_30,sm_30,sm_35\\\"")
+string(APPEND CMAKE_CUDA_FLAGS " --generate-code=arch=compute_50,code=[compute_50,sm_50,sm_52]")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CUDA_STANDARD 11)
+set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
add_library(CUDASeparateLibA STATIC file1.cu file2.cu file3.cu)
+get_property(sep_comp TARGET CUDASeparateLibA PROPERTY CUDA_SEPARABLE_COMPILATION)
+if(NOT sep_comp)
+ message(FATAL_ERROR "CUDA_SEPARABLE_COMPILATION not initialized")
+endif()
+unset(CMAKE_CUDA_SEPARABLE_COMPILATION)
if(CMAKE_CUDA_SIMULATE_ID STREQUAL "MSVC")
# Test adding a flag that is not in our CUDA flag table for VS.
@@ -48,8 +55,7 @@ if (CMAKE_GENERATOR MATCHES "^Visual Studio")
PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
endif()
-if (APPLE)
- # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that
- # the static cuda runtime can find it at runtime.
- target_link_libraries(CudaOnlySeparateCompilation PRIVATE -Wl,-rpath,/usr/local/cuda/lib)
+if(APPLE)
+ # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
+ set_property(TARGET CudaOnlySeparateCompilation PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt
index e25f141ea..00fd7d24c 100644
--- a/Tests/CudaOnly/WithDefs/CMakeLists.txt
+++ b/Tests/CudaOnly/WithDefs/CMakeLists.txt
@@ -1,10 +1,14 @@
cmake_minimum_required(VERSION 3.7)
-project (CudaOnlyWithDefs CUDA)
+project (WithDefs CUDA)
#verify that we can pass explicit cuda arch flags
string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_30,code=compute_30")
-set(debug_compile_flags --generate-code arch=compute_20,code=sm_20)
+if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
+ set(debug_compile_flags --generate-code arch=compute_32,code=sm_32)
+else()
+ set(debug_compile_flags --generate-code arch=compute_20,code=sm_20)
+endif()
if(CMAKE_CUDA_SIMULATE_ID STREQUAL "MSVC")
list(APPEND debug_compile_flags -Xcompiler=-WX)
else()
@@ -17,17 +21,13 @@ set(release_compile_defs DEFREL)
#this verifies we can pass things such as '_','(' to nvcc
add_definitions("-DPACKED_DEFINE=__attribute__((packed))")
-if(CMAKE_GENERATOR MATCHES "Visual Studio")
- # CUDA MSBuild rules do not pass '-x cu' to nvcc
- set(main main_for_vs.cu)
-else()
- set(main main.notcu)
- set_source_files_properties(main.notcu PROPERTIES LANGUAGE CUDA)
-endif()
-add_executable(CudaOnlyWithDefs ${main})
+add_executable(CudaOnlyWithDefs main.notcu)
+set_source_files_properties(main.notcu PROPERTIES LANGUAGE CUDA)
target_compile_options(CudaOnlyWithDefs
PRIVATE
+ -DFLAG_COMPILE_LANG_$<COMPILE_LANGUAGE>
+ -DFLAG_LANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
-Xcompiler=-DHOST_DEFINE
$<$<CONFIG:DEBUG>:$<BUILD_INTERFACE:${debug_compile_flags}>>
)
@@ -35,10 +35,18 @@ target_compile_options(CudaOnlyWithDefs
target_compile_definitions(CudaOnlyWithDefs
PRIVATE
$<$<CONFIG:RELEASE>:$<BUILD_INTERFACE:${release_compile_defs}>>
+ -DDEF_COMPILE_LANG_$<COMPILE_LANGUAGE>
+ -DDEF_LANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
+ -DDEF_CUDA_COMPILER=$<CUDA_COMPILER_ID>
+ -DDEF_CUDA_COMPILER_VERSION=$<CUDA_COMPILER_VERSION>
)
-#we need to add an rpath for the cuda library so that everything
-#loads properly on the mac
-if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- set_target_properties(CudaOnlyWithDefs PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}")
+target_include_directories(CudaOnlyWithDefs
+ PRIVATE
+ $<$<COMPILE_LANGUAGE:CUDA>:${CMAKE_CURRENT_SOURCE_DIR}/inc_cuda>
+)
+
+if(APPLE)
+ # Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
+ set_property(TARGET CudaOnlyWithDefs PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
endif()
diff --git a/Tests/CudaOnly/WithDefs/main.notcu b/Tests/CudaOnly/WithDefs/main.notcu
index d2eff3f4b..68a296b2c 100644
--- a/Tests/CudaOnly/WithDefs/main.notcu
+++ b/Tests/CudaOnly/WithDefs/main.notcu
@@ -2,12 +2,49 @@
#include <cuda_runtime.h>
#include <iostream>
+#include <inc_cuda.h>
+#ifndef INC_CUDA
+# error "INC_CUDA not defined!"
+#endif
+
#ifndef HOST_DEFINE
-#error "HOST_DEFINE not defined!"
+# error "HOST_DEFINE not defined!"
#endif
#ifndef PACKED_DEFINE
-#error "PACKED_DEFINE not defined!"
+# error "PACKED_DEFINE not defined!"
+#endif
+
+#ifndef FLAG_COMPILE_LANG_CUDA
+# error "FLAG_COMPILE_LANG_CUDA not defined!"
+#endif
+
+#ifndef FLAG_LANG_IS_CUDA
+# error "FLAG_LANG_IS_CUDA not defined!"
+#endif
+
+#if !FLAG_LANG_IS_CUDA
+# error "Expected FLAG_LANG_IS_CUDA"
+#endif
+
+#ifndef DEF_COMPILE_LANG_CUDA
+# error "DEF_COMPILE_LANG_CUDA not defined!"
+#endif
+
+#ifndef DEF_LANG_IS_CUDA
+# error "DEF_LANG_IS_CUDA not defined!"
+#endif
+
+#if !DEF_LANG_IS_CUDA
+# error "Expected DEF_LANG_IS_CUDA"
+#endif
+
+#ifndef DEF_CUDA_COMPILER
+# error "DEF_CUDA_COMPILER not defined!"
+#endif
+
+#ifndef DEF_CUDA_COMPILER_VERSION
+# error "DEF_CUDA_COMPILER_VERSION not defined!"
#endif
static __global__ void DetermineIfValidCudaDevice()
@@ -15,20 +52,20 @@ static __global__ void DetermineIfValidCudaDevice()
}
#ifdef _MSC_VER
-#pragma pack(push, 1)
-#undef PACKED_DEFINE
-#define PACKED_DEFINE
+# pragma pack(push, 1)
+# undef PACKED_DEFINE
+# define PACKED_DEFINE
#endif
struct PACKED_DEFINE result_type
{
bool valid;
int value;
#if defined(NDEBUG) && !defined(DEFREL)
-#error missing DEFREL flag
+# error missing DEFREL flag
#endif
};
#ifdef _MSC_VER
-#pragma pack(pop)
+# pragma pack(pop)
#endif
result_type can_launch_kernel()
diff --git a/Tests/CustComDepend/bar.h b/Tests/CustComDepend/bar.h
index c072b81a9..b0a690b57 100644
--- a/Tests/CustComDepend/bar.h
+++ b/Tests/CustComDepend/bar.h
@@ -1,9 +1,9 @@
#ifdef _WIN32
-#ifdef bar_EXPORTS
-#define BAR_EXPORT __declspec(dllexport)
+# ifdef bar_EXPORTS
+# define BAR_EXPORT __declspec(dllexport)
+# else
+# define BAR_EXPORT __declspec(dllimport)
+# endif
#else
-#define BAR_EXPORT __declspec(dllimport)
-#endif
-#else
-#define BAR_EXPORT
+# define BAR_EXPORT
#endif
diff --git a/Tests/CustomCommand/wrapper.cxx b/Tests/CustomCommand/wrapper.cxx
index c38093816..33412f8b6 100644
--- a/Tests/CustomCommand/wrapper.cxx
+++ b/Tests/CustomCommand/wrapper.cxx
@@ -17,9 +17,10 @@ int main(int argc, char* argv[])
#ifdef CMAKE_INTDIR
const char* cfg = (argc >= 4) ? argv[3] : "";
if (strcmp(cfg, CMAKE_INTDIR) != 0) {
- fprintf(stderr, "Did not receive expected configuration argument:\n"
- " expected [" CMAKE_INTDIR "]\n"
- " received [%s]\n",
+ fprintf(stderr,
+ "Did not receive expected configuration argument:\n"
+ " expected [" CMAKE_INTDIR "]\n"
+ " received [%s]\n",
cfg);
return 1;
}
diff --git a/Tests/CustomCommandByproducts/CMakeLists.txt b/Tests/CustomCommandByproducts/CMakeLists.txt
index 3289e8f9f..d0bf6487e 100644
--- a/Tests/CustomCommandByproducts/CMakeLists.txt
+++ b/Tests/CustomCommandByproducts/CMakeLists.txt
@@ -1,4 +1,5 @@
-cmake_minimum_required(VERSION 3.1)
+cmake_minimum_required(VERSION 3.9)
+cmake_policy(SET CMP0058 OLD)
project(CustomCommandByproducts C)
# Generate a byproduct in a rule that runs in the target consuming it.
@@ -81,7 +82,8 @@ add_custom_command(OUTPUT timestamp8.txt
# Generate the library file of an imported target as a byproduct
# of an external project.
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
set(cfg /${CMAKE_CFG_INTDIR})
else()
set(cfg)
@@ -105,7 +107,7 @@ add_dependencies(ExternalLibrary ExternalTarget)
# Generate the library file of an imported target as a byproduct
# of an external project. The byproduct uses <BINARY_DIR> that is substituted
# by the real binary path
-if(CMAKE_CONFIGURATION_TYPES)
+if(_isMultiConfig)
set(cfg /${CMAKE_CFG_INTDIR})
else()
set(cfg)
diff --git a/Tests/CustomCommandWorkingDirectory/CMakeLists.txt b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt
index 4975feb2d..3bab1fec0 100644
--- a/Tests/CustomCommandWorkingDirectory/CMakeLists.txt
+++ b/Tests/CustomCommandWorkingDirectory/CMakeLists.txt
@@ -9,17 +9,17 @@ add_custom_command(
)
set_source_files_properties(
- "${TestWorkingDir_BINARY_DIR}/customTarget.c"
+ "${TestWorkingDir_BINARY_DIR}/customTarget1.c"
"${TestWorkingDir_BINARY_DIR}/customTarget2.c"
PROPERTIES GENERATED 1)
add_executable(working "${TestWorkingDir_BINARY_DIR}/working.c"
- "${TestWorkingDir_BINARY_DIR}/customTarget.c")
+ "${TestWorkingDir_BINARY_DIR}/customTarget1.c")
add_custom_target(
Custom ALL
- COMMAND "${CMAKE_COMMAND}" -E copy_if_different ./customTarget.c "${TestWorkingDir_BINARY_DIR}/customTarget.c"
- BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/customTarget.c"
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different ./customTarget.c "${TestWorkingDir_BINARY_DIR}/customTarget1.c"
+ BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/customTarget1.c"
WORKING_DIRECTORY "${TestWorkingDir_SOURCE_DIR}"
)
@@ -42,3 +42,23 @@ add_custom_target(
)
add_dependencies(working2 Custom2)
+
+file(MAKE_DIRECTORY ${TestWorkingDir_BINARY_DIR}/genex)
+add_custom_command(
+ OUTPUT "${TestWorkingDir_BINARY_DIR}/genex/working.c"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${TestWorkingDir_SOURCE_DIR}/working.c.in" "${TestWorkingDir_BINARY_DIR}/genex/working.c"
+ WORKING_DIRECTORY "$<0:not_used/>${TestWorkingDir_BINARY_DIR}/$<1:genex>/"
+ COMMENT "custom command"
+)
+
+add_executable(workinggenex "${TestWorkingDir_BINARY_DIR}/genex/working.c"
+ "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c")
+
+add_custom_target(
+ CustomGenex ALL
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${TestWorkingDir_SOURCE_DIR}/customTarget.c" "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c"
+ BYPRODUCTS "${TestWorkingDir_BINARY_DIR}/genex/customTarget.c"
+ WORKING_DIRECTORY "$<0:not_used/>${TestWorkingDir_BINARY_DIR}/$<1:genex>/"
+)
+
+add_dependencies(workinggenex CustomGenex)
diff --git a/Tests/CxxOnly/libcxx2.h b/Tests/CxxOnly/libcxx2.h
index 1d97fa0ac..774e4e897 100644
--- a/Tests/CxxOnly/libcxx2.h
+++ b/Tests/CxxOnly/libcxx2.h
@@ -1,11 +1,11 @@
#ifdef _WIN32
-#ifdef testcxx2_EXPORTS
-#define CM_TEST_LIB_EXPORT __declspec(dllexport)
+# 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 __declspec(dllimport)
-#endif
-#else
-#define CM_TEST_LIB_EXPORT
+# define CM_TEST_LIB_EXPORT
#endif
class CM_TEST_LIB_EXPORT LibCxx2Class
diff --git a/Tests/CxxOnly/testCxxModule.cxx b/Tests/CxxOnly/testCxxModule.cxx
index 039e8bba6..5015d07f8 100644
--- a/Tests/CxxOnly/testCxxModule.cxx
+++ b/Tests/CxxOnly/testCxxModule.cxx
@@ -1,7 +1,7 @@
#ifdef _WIN32
-#define TEST_EXPORT __declspec(dllexport)
+# define TEST_EXPORT __declspec(dllexport)
#else
-#define TEST_EXPORT
+# define TEST_EXPORT
#endif
TEST_EXPORT int testCxxModule(void)
{
diff --git a/Tests/EnforceConfig.cmake.in b/Tests/EnforceConfig.cmake.in
index 8c0817cd6..b7587aa47 100644
--- a/Tests/EnforceConfig.cmake.in
+++ b/Tests/EnforceConfig.cmake.in
@@ -18,9 +18,20 @@ if(NOT CTEST_CONFIGURATION_TYPE)
endif()
endforeach()
if(NOT CTEST_CONFIGURATION_TYPE)
- set(CTEST_CONFIGURATION_TYPE NoConfig)
+ if("@CMAKE_C_COMPILER_ID@;@CMAKE_C_SIMULATE_ID@;@CMAKE_C_COMPILER_FRONTEND_VARIANT@" STREQUAL "Clang;MSVC;GNU")
+ # A valid configuration is required for this compiler in tests that do not set CMP0091 to NEW.
+ set(CTEST_CONFIGURATION_TYPE Debug)
+ else()
+ set(CTEST_CONFIGURATION_TYPE NoConfig)
+ endif()
endif()
message("Guessing configuration ${CTEST_CONFIGURATION_TYPE}")
endif()
+# Isolate tests from user configuration in the environment.
+unset(ENV{CMAKE_GENERATOR})
+unset(ENV{CMAKE_GENERATOR_INSTANCE})
+unset(ENV{CMAKE_GENERATOR_PLATFORM})
+unset(ENV{CMAKE_GENERATOR_TOOLSET})
+
@TEST_HOME_ENV_CODE@
diff --git a/Tests/ExportImport/CMakeLists.txt b/Tests/ExportImport/CMakeLists.txt
index eaad3d46c..dc621eb27 100644
--- a/Tests/ExportImport/CMakeLists.txt
+++ b/Tests/ExportImport/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 2.7.20090711)
+cmake_minimum_required (VERSION 3.9)
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}")
@@ -15,7 +15,8 @@ set_property(
PROPERTY SYMBOLIC 1
)
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
else()
if(CMAKE_BUILD_TYPE)
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
index eeae3f006..c6b7dbc95 100644
--- a/Tests/ExportImport/Export/CMakeLists.txt
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -83,11 +83,23 @@ set_property(TARGET testLib7 PROPERTY OUTPUT_NAME testLib7-$<CONFIG>)
add_library(testLib8 OBJECT testLib8A.c testLib8B.c sub/testLib8C.c)
if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]")
- set(maybe_testLib8 testLib8)
+ set(maybe_OBJECTS_DESTINATION OBJECTS DESTINATION $<1:lib>)
else()
- set(maybe_testLib8 "")
+ set(maybe_OBJECTS_DESTINATION "")
endif()
+cmake_policy(PUSH)
+cmake_policy(SET CMP0022 NEW)
+add_library(testLib9ObjPub OBJECT testLib9ObjPub.c)
+target_compile_definitions(testLib9ObjPub INTERFACE testLib9ObjPub_USED)
+add_library(testLib9ObjPriv OBJECT testLib9ObjPriv.c)
+target_compile_definitions(testLib9ObjPriv INTERFACE testLib9ObjPriv_USED)
+add_library(testLib9ObjIface OBJECT testLib9ObjIface.c)
+target_compile_definitions(testLib9ObjIface INTERFACE testLib9ObjIface_USED)
+add_library(testLib9 STATIC testLib9.c)
+target_link_libraries(testLib9 INTERFACE testLib9ObjIface PUBLIC testLib9ObjPub PRIVATE testLib9ObjPriv)
+cmake_policy(POP)
+
# 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
@@ -143,6 +155,13 @@ add_library(testStaticLibRequiredPrivate testStaticLibRequiredPrivate.c)
target_link_libraries(testLibDepends PRIVATE testStaticLibRequiredPrivate)
cmake_policy(POP)
+cmake_policy(PUSH)
+cmake_policy(SET CMP0079 NEW)
+add_library(TopDirLib STATIC testTopDirLib.c)
+add_subdirectory(SubDirLinkA)
+add_subdirectory(SubDirLinkB)
+cmake_policy(POP)
+
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")
@@ -344,6 +363,14 @@ install(FILES
set_property(TARGET testLib2 APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS USING_TESTLIB2)
set_property(TARGET testLib3 APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS USING_TESTLIB3)
+set_target_properties(testLib3 PROPERTIES
+ EXPORT_PROPERTIES "EXPORTED_PROPERTY1"
+ EXPORTED_PROPERTY1 "EXPORTING_TESTLIB3")
+set_target_properties(testLib4 PROPERTIES
+ EXPORTED_PROPERTY2 "EXPORTING_TESTLIB4_1"
+ EXPORTED_PROPERTY3 "EXPORTING_TESTLIB4_2")
+set_property(TARGET testLib4 PROPERTY
+ EXPORT_PROPERTIES EXPORTED_PROPERTY2 EXPORTED_PROPERTY3)
set_property(TARGET cmp0022NEW APPEND PROPERTY INTERFACE_LINK_LIBRARIES testLib2)
# set_property(TARGET cmp0022NEW APPEND PROPERTY LINK_INTERFACE_LIBRARIES testLibIncludeRequired2) # TODO: Test for error
@@ -483,19 +510,26 @@ install(
TARGETS
testExe1 testLib1 testLib2 testExe2 testLib3 testLib4 testExe3 testExe4
testExe2lib testLib4lib testLib4libdbg testLib4libopt
- testLib6 testLib7 ${maybe_testLib8}
+ testLib6 testLib7 testLib8
+ testLib9
testLibCycleA testLibCycleB
testLibNoSONAME
cmp0022NEW cmp0022OLD
+ TopDirLib SubDirLinkA
systemlib
EXPORT exp
- RUNTIME DESTINATION $<1:bin>
- LIBRARY DESTINATION $<1:lib> NAMELINK_SKIP
- ARCHIVE DESTINATION $<1:lib>
- OBJECTS DESTINATION $<1:lib>
+ RUNTIME DESTINATION $<1:bin>$<0:/wrong>
+ LIBRARY DESTINATION $<1:lib>$<0:/wrong> NAMELINK_SKIP
+ ARCHIVE DESTINATION $<1:lib>$<0:/wrong>
+ ${maybe_OBJECTS_DESTINATION}
FRAMEWORK DESTINATION Frameworks
BUNDLE DESTINATION Applications
)
+install(
+ TARGETS
+ testLib9ObjPub testLib9ObjPriv testLib9ObjIface
+ EXPORT exp
+ )
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)
@@ -540,12 +574,14 @@ export(TARGETS testExe1 testLib1 testLib2 testLib3
testSharedLibRequired testSharedLibRequiredUser testSharedLibRequiredUser2
testSharedLibDepends renamed_on_export
cmp0022NEW cmp0022OLD
+ TopDirLib SubDirLinkA
systemlib
NAMESPACE bld_
FILE ExportBuildTree.cmake
)
export(TARGETS testExe2 testLib4 testLib5 testLib6 testLib7 testExe3 testExe4 testExe2lib
- ${maybe_testLib8}
+ testLib8
+ testLib9 testLib9ObjPub testLib9ObjPriv testLib9ObjIface
testLib4lib testLib4libdbg testLib4libopt
testLibCycleA testLibCycleB
testLibNoSONAME
@@ -570,3 +606,39 @@ install(
)
install(DIRECTORY $<1:include/abs>$<0:/wrong> DESTINATION $<1:include>$<0:/wrong>)
install(EXPORT expAbs NAMESPACE expAbs_ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/expAbs)
+
+
+#------------------------------------------------------------------------------
+# test export of INTERFACE_LINK_OPTIONS
+add_library(testLinkOptions INTERFACE)
+target_link_options(testLinkOptions INTERFACE INTERFACE_FLAG)
+
+install(TARGETS testLinkOptions
+ EXPORT RequiredExp DESTINATION lib)
+export(TARGETS testLinkOptions NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake)
+
+
+#------------------------------------------------------------------------------
+# test export of INTERFACE_LINK_DIRECTORIES
+add_library(testLinkDirectories INTERFACE)
+target_link_directories(testLinkDirectories INTERFACE
+ $<BUILD_INTERFACE:/interface/build>
+ $<INSTALL_INTERFACE:interface/install>)
+
+install(TARGETS testLinkDirectories
+ EXPORT RequiredExp DESTINATION lib)
+export(TARGETS testLinkDirectories NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake)
+
+
+#------------------------------------------------------------------------------
+# test export of INTERFACE_LINK_DEPENDS
+if(CMAKE_GENERATOR MATCHES "Make|Ninja")
+ add_library(testLinkDepends INTERFACE)
+ set_property(TARGET testLinkDepends PROPERTY INTERFACE_LINK_DEPENDS
+ $<BUILD_INTERFACE:BUILD_LINK_DEPENDS>
+ $<INSTALL_INTERFACE:INSTALL_LINK_DEPENDS>)
+
+ install(TARGETS testLinkDepends
+ EXPORT RequiredExp DESTINATION lib)
+ export(TARGETS testLinkDepends NAMESPACE bld_ APPEND FILE ExportBuildTree.cmake)
+endif()
diff --git a/Tests/ExportImport/Export/Interface/CMakeLists.txt b/Tests/ExportImport/Export/Interface/CMakeLists.txt
index fd55c423c..22a4ef600 100644
--- a/Tests/ExportImport/Export/Interface/CMakeLists.txt
+++ b/Tests/ExportImport/Export/Interface/CMakeLists.txt
@@ -41,6 +41,8 @@ install(FILES
add_library(cmakeonly INTERFACE)
set_property(TARGET cmakeonly PROPERTY INTERFACE_COMPILE_DEFINITIONS [[DEF="\"\$\B"]])
+set_property(TARGET cmakeonly PROPERTY custom_property CustomPropertyValue)
+set_property(TARGET cmakeonly PROPERTY EXPORT_PROPERTIES custom_property)
install(TARGETS headeronly sharediface use_auto_type use_c_restrict source_target
cmakeonly
diff --git a/Tests/ExportImport/Export/Interface/source_target.cpp b/Tests/ExportImport/Export/Interface/source_target.cpp
index 037191cf6..1eb5b1307 100644
--- a/Tests/ExportImport/Export/Interface/source_target.cpp
+++ b/Tests/ExportImport/Export/Interface/source_target.cpp
@@ -1,10 +1,10 @@
#ifndef USE_FROM_BUILD_DIR
-#error Expected define USE_FROM_BUILD_DIR
+# error Expected define USE_FROM_BUILD_DIR
#endif
#ifdef USE_FROM_INSTALL_DIR
-#error Unexpected define USE_FROM_INSTALL_DIR
+# error Unexpected define USE_FROM_INSTALL_DIR
#endif
int source_symbol()
diff --git a/Tests/ExportImport/Export/Interface/source_target_for_install.cpp b/Tests/ExportImport/Export/Interface/source_target_for_install.cpp
index 64514edb2..2f8819052 100644
--- a/Tests/ExportImport/Export/Interface/source_target_for_install.cpp
+++ b/Tests/ExportImport/Export/Interface/source_target_for_install.cpp
@@ -1,10 +1,10 @@
#ifdef USE_FROM_BUILD_DIR
-#error Unexpected define USE_FROM_BUILD_DIR
+# error Unexpected define USE_FROM_BUILD_DIR
#endif
#ifndef USE_FROM_INSTALL_DIR
-#error Expected define USE_FROM_INSTALL_DIR
+# error Expected define USE_FROM_INSTALL_DIR
#endif
int source_symbol()
diff --git a/Tests/ExportImport/Export/systemlib.h b/Tests/ExportImport/Export/systemlib.h
index 6fd00d503..8ec055bb0 100644
--- a/Tests/ExportImport/Export/systemlib.h
+++ b/Tests/ExportImport/Export/systemlib.h
@@ -3,9 +3,9 @@
#define SYSTEMLIB_H
#if defined(_WIN32) || defined(__CYGWIN__)
-#define systemlib_EXPORT __declspec(dllexport)
+# define systemlib_EXPORT __declspec(dllexport)
#else
-#define systemlib_EXPORT
+# define systemlib_EXPORT
#endif
struct systemlib_EXPORT SystemStruct
diff --git a/Tests/ExportImport/Export/testExe2.c b/Tests/ExportImport/Export/testExe2.c
index f8976c46a..958e4d2bc 100644
--- a/Tests/ExportImport/Export/testExe2.c
+++ b/Tests/ExportImport/Export/testExe2.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testExe2_EXPORT __declspec(dllexport)
+# define testExe2_EXPORT __declspec(dllexport)
#else
-#define testExe2_EXPORT
+# define testExe2_EXPORT
#endif
testExe2_EXPORT int testExe2Func(void)
diff --git a/Tests/ExportImport/Export/testExe2lib.c b/Tests/ExportImport/Export/testExe2lib.c
index 2a5a77bd5..905e6c7f5 100644
--- a/Tests/ExportImport/Export/testExe2lib.c
+++ b/Tests/ExportImport/Export/testExe2lib.c
@@ -1,9 +1,9 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testExe2lib_EXPORT __declspec(dllexport)
-#define testExe2libImp_IMPORT __declspec(dllimport)
+# define testExe2lib_EXPORT __declspec(dllexport)
+# define testExe2libImp_IMPORT __declspec(dllimport)
#else
-#define testExe2lib_EXPORT
-#define testExe2libImp_IMPORT
+# define testExe2lib_EXPORT
+# define testExe2libImp_IMPORT
#endif
testExe2libImp_IMPORT int testExe2libImp(void);
diff --git a/Tests/ExportImport/Export/testExe2libImp.c b/Tests/ExportImport/Export/testExe2libImp.c
index aba914b88..8892c8553 100644
--- a/Tests/ExportImport/Export/testExe2libImp.c
+++ b/Tests/ExportImport/Export/testExe2libImp.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testExe2libImp_EXPORT __declspec(dllexport)
+# define testExe2libImp_EXPORT __declspec(dllexport)
#else
-#define testExe2libImp_EXPORT
+# define testExe2libImp_EXPORT
#endif
testExe2libImp_EXPORT int testExe2libImp(void)
diff --git a/Tests/ExportImport/Export/testLib3.c b/Tests/ExportImport/Export/testLib3.c
index cacac810f..016fae0b1 100644
--- a/Tests/ExportImport/Export/testLib3.c
+++ b/Tests/ExportImport/Export/testLib3.c
@@ -1,9 +1,9 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testLib3_EXPORT __declspec(dllexport)
-#define testLib3Imp_IMPORT __declspec(dllimport)
+# define testLib3_EXPORT __declspec(dllexport)
+# define testLib3Imp_IMPORT __declspec(dllimport)
#else
-#define testLib3_EXPORT
-#define testLib3Imp_IMPORT
+# define testLib3_EXPORT
+# define testLib3Imp_IMPORT
#endif
testLib3Imp_IMPORT int testLib3Imp(void);
diff --git a/Tests/ExportImport/Export/testLib3Imp.c b/Tests/ExportImport/Export/testLib3Imp.c
index 3d836daf1..877d0b6bf 100644
--- a/Tests/ExportImport/Export/testLib3Imp.c
+++ b/Tests/ExportImport/Export/testLib3Imp.c
@@ -1,9 +1,9 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testLib3Imp_EXPORT __declspec(dllexport)
-#define testLib3ImpDep_IMPORT __declspec(dllimport)
+# define testLib3Imp_EXPORT __declspec(dllexport)
+# define testLib3ImpDep_IMPORT __declspec(dllimport)
#else
-#define testLib3Imp_EXPORT
-#define testLib3ImpDep_IMPORT
+# define testLib3Imp_EXPORT
+# define testLib3ImpDep_IMPORT
#endif
testLib3ImpDep_IMPORT int testLib3ImpDep(void);
diff --git a/Tests/ExportImport/Export/testLib3ImpDep.c b/Tests/ExportImport/Export/testLib3ImpDep.c
index b824e03de..4fc97836b 100644
--- a/Tests/ExportImport/Export/testLib3ImpDep.c
+++ b/Tests/ExportImport/Export/testLib3ImpDep.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testLib3ImpDep_EXPORT __declspec(dllexport)
+# define testLib3ImpDep_EXPORT __declspec(dllexport)
#else
-#define testLib3ImpDep_EXPORT
+# define testLib3ImpDep_EXPORT
#endif
testLib3ImpDep_EXPORT int testLib3ImpDep(void)
diff --git a/Tests/ExportImport/Export/testLib4.c b/Tests/ExportImport/Export/testLib4.c
index 0e583b176..2031a4fd7 100644
--- a/Tests/ExportImport/Export/testLib4.c
+++ b/Tests/ExportImport/Export/testLib4.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testLib4_EXPORT __declspec(dllexport)
+# define testLib4_EXPORT __declspec(dllexport)
#else
-#define testLib4_EXPORT
+# define testLib4_EXPORT
#endif
testLib4_EXPORT int testLib4(void)
diff --git a/Tests/ExportImport/Export/testLib5.c b/Tests/ExportImport/Export/testLib5.c
index 7c61fc030..edd02ebd1 100644
--- a/Tests/ExportImport/Export/testLib5.c
+++ b/Tests/ExportImport/Export/testLib5.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testLib5_EXPORT __declspec(dllexport)
+# define testLib5_EXPORT __declspec(dllexport)
#else
-#define testLib5_EXPORT
+# define testLib5_EXPORT
#endif
testLib5_EXPORT int testLib5(void)
diff --git a/Tests/ExportImport/Export/testLibDepends.c b/Tests/ExportImport/Export/testLibDepends.c
index c896c10ef..6100da1dc 100644
--- a/Tests/ExportImport/Export/testLibDepends.c
+++ b/Tests/ExportImport/Export/testLibDepends.c
@@ -4,15 +4,15 @@
#include "testLibIncludeRequired4.h"
#ifndef testLibRequired_IFACE_DEFINE
-#error Expected testLibRequired_IFACE_DEFINE
+# error Expected testLibRequired_IFACE_DEFINE
#endif
#ifndef BuildOnly_DEFINE
-#error Expected BuildOnly_DEFINE
+# error Expected BuildOnly_DEFINE
#endif
#ifdef InstallOnly_DEFINE
-#error Unexpected InstallOnly_DEFINE
+# error Unexpected InstallOnly_DEFINE
#endif
extern int testLibRequired(void);
diff --git a/Tests/ExportImport/Export/testLibNoSONAME.c b/Tests/ExportImport/Export/testLibNoSONAME.c
index 4d98562df..955284852 100644
--- a/Tests/ExportImport/Export/testLibNoSONAME.c
+++ b/Tests/ExportImport/Export/testLibNoSONAME.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testLibNoSONAME_EXPORT __declspec(dllexport)
+# define testLibNoSONAME_EXPORT __declspec(dllexport)
#else
-#define testLibNoSONAME_EXPORT
+# define testLibNoSONAME_EXPORT
#endif
testLibNoSONAME_EXPORT int testLibNoSoName(void)
diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt
index 01960ea19..b5df96168 100644
--- a/Tests/ExportImport/Import/A/CMakeLists.txt
+++ b/Tests/ExportImport/Import/A/CMakeLists.txt
@@ -1,3 +1,9 @@
+# Prepare imported targets that the exported project itself imported.
+add_library(SubDirLinkAImported IMPORTED INTERFACE)
+target_compile_definitions(SubDirLinkAImported INTERFACE DEF_SubDirLinkAImportedForImport)
+add_library(SubDirLinkBImported IMPORTED INTERFACE)
+target_compile_definitions(SubDirLinkBImported INTERFACE DEF_SubDirLinkBImportedForImport)
+
# Import targets from the exported build tree.
include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake)
@@ -32,6 +38,20 @@ add_executable(imp_testExe1
${Import_BINARY_DIR}/exp_generated4.c
)
+function(checkForProperty _TARGET _PROP _EXPECTED)
+ get_target_property(EXPORTED_PROPERTY ${_TARGET} "${_PROP}")
+ if (NOT EXPORTED_PROPERTY STREQUAL "${_EXPECTED}")
+ message(SEND_ERROR "${_TARGET} was expected to export \"${_PROP}\" with value \"${_EXPECTED}\" but got \"${EXPORTED_PROPERTY}\"")
+ endif()
+endfunction()
+
+checkForProperty(bld_testLib3 "EXPORTED_PROPERTY1" "EXPORTING_TESTLIB3")
+checkForProperty(exp_testLib3 "EXPORTED_PROPERTY1" "EXPORTING_TESTLIB3")
+checkForProperty(bld_testLib4 "EXPORTED_PROPERTY2" "EXPORTING_TESTLIB4_1")
+checkForProperty(exp_testLib4 "EXPORTED_PROPERTY2" "EXPORTING_TESTLIB4_1")
+checkForProperty(bld_testLib4 "EXPORTED_PROPERTY3" "EXPORTING_TESTLIB4_2")
+checkForProperty(exp_testLib4 "EXPORTED_PROPERTY3" "EXPORTING_TESTLIB4_2")
+
# Try linking to a library imported from the install tree.
target_link_libraries(imp_testExe1
exp_testLib2
@@ -144,6 +164,11 @@ 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)
+add_executable(SubDirLink_bld SubDirLink.c)
+target_link_libraries(SubDirLink_bld PRIVATE bld_TopDirLib bld_SubDirLinkA)
+add_executable(SubDirLink_exp SubDirLink.c)
+target_link_libraries(SubDirLink_exp PRIVATE exp_TopDirLib exp_SubDirLinkA)
+
# 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)
@@ -229,15 +254,44 @@ add_library(imp_lib1b STATIC imp_lib1.c)
target_link_libraries(imp_lib1b bld_testLib2)
if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]")
- # Create a executable that is using objects imported from the install tree
- add_executable(imp_testLib8 imp_testLib8.c $<TARGET_OBJECTS:exp_testLib8>)
+ set(bld_objlib_type OBJECT_LIBRARY)
+
+ # Create executables using objects imported from the install tree
+ add_executable(imp_testLib8_src imp_testLib8.c $<TARGET_OBJECTS:exp_testLib8>)
+ add_executable(imp_testLib8_link imp_testLib8.c)
+ target_link_libraries(imp_testLib8_link exp_testLib8)
if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT XCODE_VERSION VERSION_LESS 5)
- # Create a executable that is using objects imported from the build tree
- add_executable(imp_testLib8b imp_testLib8.c $<TARGET_OBJECTS:bld_testLib8>)
+ # Create executables using objects imported from the build tree
+ add_executable(imp_testLib8b_src imp_testLib8.c $<TARGET_OBJECTS:bld_testLib8>)
+ add_executable(imp_testLib8b_link imp_testLib8.c)
+ target_link_libraries(imp_testLib8b_link bld_testLib8)
endif()
+else()
+ set(bld_objlib_type INTERFACE_LIBRARY)
endif()
+# Create an executable that uses a library imported from the install tree
+# that itself was built using an object library. Verify we get the usage
+# requirements.
+add_executable(imp_testLib9 imp_testLib9.c)
+target_link_libraries(imp_testLib9 exp_testLib9)
+# Similarly for importing from the build tree.
+add_executable(imp_testLib9b imp_testLib9.c)
+target_link_libraries(imp_testLib9b bld_testLib9)
+
+# Check that object libraries were transformed on export as expected.
+foreach(vis Pub Priv Iface)
+ get_property(type TARGET exp_testLib9Obj${vis} PROPERTY TYPE)
+ if(NOT type STREQUAL INTERFACE_LIBRARY)
+ message(FATAL_ERROR "exp_testLib9Obj${vis} type is '${type}', not 'INTERFACE_LIBRARY'")
+ endif()
+ get_property(type TARGET bld_testLib9Obj${vis} PROPERTY TYPE)
+ if(NOT type STREQUAL "${bld_objlib_type}")
+ message(FATAL_ERROR "bld_testLib9Obj${vis} type is '${type}', not '${bld_objlib_type}'")
+ endif()
+endforeach()
+
#-----------------------------------------------------------------------------
# Test that handling imported targets, including transitive dependencies,
# works in CheckFunctionExists (...and hopefully all other try_compile() checks
@@ -278,7 +332,6 @@ if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
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()
@@ -354,7 +407,7 @@ 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)
+ OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"))
AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja"))
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
@@ -429,3 +482,20 @@ if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREA
endif()
endif()
endif()
+
+#---------------------------------------------------------------------------------
+# check that imported libraries have the expected INTERFACE_LINK_OPTIONS property
+checkForProperty(bld_testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG")
+checkForProperty(Req::testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG")
+
+#---------------------------------------------------------------------------------
+# check that imported libraries have the expected INTERFACE_LINK_DIRECTORIES property
+checkForProperty(bld_testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "/interface/build")
+checkForProperty(Req::testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "${CMAKE_INSTALL_PREFIX}/interface/install")
+
+#---------------------------------------------------------------------------------
+# check that imported libraries have the expected INTERFACE_LINK_DEPENDS property
+if(CMAKE_GENERATOR MATCHES "Make|Ninja")
+ checkForProperty(bld_testLinkDepends "INTERFACE_LINK_DEPENDS" "BUILD_LINK_DEPENDS")
+ checkForProperty(Req::testLinkDepends "INTERFACE_LINK_DEPENDS" "${CMAKE_INSTALL_PREFIX}/INSTALL_LINK_DEPENDS")
+endif()
diff --git a/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp b/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp
index 587834987..778b8287e 100644
--- a/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp
+++ b/Tests/ExportImport/Import/A/cmp0022NEW_test.cpp
@@ -1,9 +1,9 @@
#ifndef USING_TESTLIB2
-#error Expected USING_TESTLIB2
+# error Expected USING_TESTLIB2
#endif
#ifdef USING_TESTLIB3
-#error Unexpected USING_TESTLIB3
+# error Unexpected USING_TESTLIB3
#endif
int main(void)
diff --git a/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp b/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp
index e50158b76..9eaaee9b4 100644
--- a/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp
+++ b/Tests/ExportImport/Import/A/cmp0022OLD_test.cpp
@@ -1,9 +1,9 @@
#ifdef USING_TESTLIB2
-#error Unexpected USING_TESTLIB2
+# error Unexpected USING_TESTLIB2
#endif
#ifndef USING_TESTLIB3
-#error Expected USING_TESTLIB3
+# error Expected USING_TESTLIB3
#endif
int main(void)
diff --git a/Tests/ExportImport/Import/A/deps_iface.c b/Tests/ExportImport/Import/A/deps_iface.c
index 1539bcb68..e2d973c2f 100644
--- a/Tests/ExportImport/Import/A/deps_iface.c
+++ b/Tests/ExportImport/Import/A/deps_iface.c
@@ -14,15 +14,15 @@
#include "installIncludesTest8.h"
#ifndef testLibRequired_IFACE_DEFINE
-#error Expected testLibRequired_IFACE_DEFINE
+# error Expected testLibRequired_IFACE_DEFINE
#endif
#ifdef BuildOnly_DEFINE
-#error Unexpected BuildOnly_DEFINE
+# error Unexpected BuildOnly_DEFINE
#endif
#ifndef InstallOnly_DEFINE
-#error Expected InstallOnly_DEFINE
+# error Expected InstallOnly_DEFINE
#endif
extern int testLibDepends(void);
diff --git a/Tests/ExportImport/Import/A/deps_shared_iface.cpp b/Tests/ExportImport/Import/A/deps_shared_iface.cpp
index 3658ab548..d239fb418 100644
--- a/Tests/ExportImport/Import/A/deps_shared_iface.cpp
+++ b/Tests/ExportImport/Import/A/deps_shared_iface.cpp
@@ -3,32 +3,32 @@
#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
+# 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
+# error Expected PIC_PROPERTY_IS_ON
#endif
#ifndef CUSTOM_PROPERTY_IS_ON
-#error Expected CUSTOM_PROPERTY_IS_ON
+# error Expected CUSTOM_PROPERTY_IS_ON
#endif
#ifndef CUSTOM_STRING_IS_MATCH
-#error Expected CUSTOM_STRING_IS_MATCH
+# error Expected CUSTOM_STRING_IS_MATCH
#endif
#ifdef TEST_SUBDIR_LIB
-#include "renamed.h"
-#include "subdir.h"
+# include "renamed.h"
+# include "subdir.h"
#endif
#ifdef DO_GNU_TESTS
-#ifndef CUSTOM_COMPILE_OPTION
-#error Expected CUSTOM_COMPILE_OPTION
-#endif
+# ifndef CUSTOM_COMPILE_OPTION
+# error Expected CUSTOM_COMPILE_OPTION
+# endif
#endif
int main(int, char**)
diff --git a/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp b/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp
index 357f64f02..ddb8c4b35 100644
--- a/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp
+++ b/Tests/ExportImport/Import/A/framework_interface/framework_test.cpp
@@ -2,5 +2,5 @@
#include <testLib4/testLib4.h>
#ifndef TESTLIB4_H
-#error Expected define 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
index fa4474bdb..4428c1c50 100644
--- a/Tests/ExportImport/Import/A/iface_test.cpp
+++ b/Tests/ExportImport/Import/A/iface_test.cpp
@@ -1,6 +1,6 @@
#ifndef USING_TESTSHAREDLIBREQUIRED
-#error Expected USING_TESTSHAREDLIBREQUIRED
+# error Expected USING_TESTSHAREDLIBREQUIRED
#endif
#include "excludedFromAll.h"
diff --git a/Tests/ExportImport/Import/A/imp_mod1.c b/Tests/ExportImport/Import/A/imp_mod1.c
index 89d754595..9385d5519 100644
--- a/Tests/ExportImport/Import/A/imp_mod1.c
+++ b/Tests/ExportImport/Import/A/imp_mod1.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(__CYGWIN__)
-#define testExe2_IMPORT __declspec(dllimport)
+# define testExe2_IMPORT __declspec(dllimport)
#else
-#define testExe2_IMPORT
+# define testExe2_IMPORT
#endif
testExe2_IMPORT int testExe2Func(void);
diff --git a/Tests/ExportImport/Import/A/imp_testExe1.c b/Tests/ExportImport/Import/A/imp_testExe1.c
index 348843928..8173557cd 100644
--- a/Tests/ExportImport/Import/A/imp_testExe1.c
+++ b/Tests/ExportImport/Import/A/imp_testExe1.c
@@ -14,9 +14,9 @@ extern int testLibPerConfigDest(void);
/* 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
+# define testLib4libcfg testLib4libdbg
#else
-#define testLib4libcfg testLib4libopt
+# define testLib4libcfg testLib4libopt
#endif
extern testLib4libcfg(void);
diff --git a/Tests/ExportImport/Import/A/imp_testExeAbs1.c b/Tests/ExportImport/Import/A/imp_testExeAbs1.c
index 629b891f1..fd0524206 100644
--- a/Tests/ExportImport/Import/A/imp_testExeAbs1.c
+++ b/Tests/ExportImport/Import/A/imp_testExeAbs1.c
@@ -2,10 +2,10 @@
#include "testLibAbs1a.h"
#include "testLibAbs1b.h"
#ifndef testLibAbs1a
-#error "testLibAbs1a not defined"
+# error "testLibAbs1a not defined"
#endif
#ifndef testLibAbs1b
-#error "testLibAbs1b not defined"
+# error "testLibAbs1b not defined"
#endif
int main()
{
diff --git a/Tests/ExportImport/Import/Interface/CMakeLists.txt b/Tests/ExportImport/Import/Interface/CMakeLists.txt
index c850508e5..a07a5b3c4 100644
--- a/Tests/ExportImport/Import/Interface/CMakeLists.txt
+++ b/Tests/ExportImport/Import/Interface/CMakeLists.txt
@@ -109,4 +109,12 @@ foreach(ns exp bld)
"not\n"
" " [[DEF="\"\$\B"]] "\n")
endif()
+ get_property(custom TARGET ${ns}::cmakeonly PROPERTY custom_property)
+ if(NOT custom STREQUAL "CustomPropertyValue")
+ message(SEND_ERROR
+ "${ns}::cmakeonly property custom_property is:\n"
+ " ${custom}\n"
+ "not\n"
+ " CustomPropertyValue\n")
+ endif()
endforeach()
diff --git a/Tests/ExportImport/Import/Interface/headeronlytest.cpp b/Tests/ExportImport/Import/Interface/headeronlytest.cpp
index 0e754e9e3..7b63a0496 100644
--- a/Tests/ExportImport/Import/Interface/headeronlytest.cpp
+++ b/Tests/ExportImport/Import/Interface/headeronlytest.cpp
@@ -2,11 +2,11 @@
#include "headeronly.h"
#ifndef HEADERONLY_DEFINE
-#error Expected HEADERONLY_DEFINE
+# error Expected HEADERONLY_DEFINE
#endif
#ifdef SHAREDLIB_DEFINE
-#error Unexpected SHAREDLIB_DEFINE
+# error Unexpected SHAREDLIB_DEFINE
#endif
int main(int, char**)
diff --git a/Tests/ExportImport/Import/Interface/interfacetest.cpp b/Tests/ExportImport/Import/Interface/interfacetest.cpp
index 7be816286..c1e29c246 100644
--- a/Tests/ExportImport/Import/Interface/interfacetest.cpp
+++ b/Tests/ExportImport/Import/Interface/interfacetest.cpp
@@ -2,15 +2,15 @@
#include "sharedlib.h"
#ifndef SHAREDLIB_DEFINE
-#error Expected SHAREDLIB_DEFINE
+# error Expected SHAREDLIB_DEFINE
#endif
#ifdef HEADERONLY_DEFINE
-#error Unexpected HEADERONLY_DEFINE
+# error Unexpected HEADERONLY_DEFINE
#endif
#ifndef DEFINE_IFACE_DEFINE
-#error Expected DEFINE_IFACE_DEFINE
+# error Expected DEFINE_IFACE_DEFINE
#endif
int main(int, char**)
diff --git a/Tests/ExternalOBJ/CMakeLists.txt b/Tests/ExternalOBJ/CMakeLists.txt
index 458c88bfd..4ff75b8cc 100644
--- a/Tests/ExternalOBJ/CMakeLists.txt
+++ b/Tests/ExternalOBJ/CMakeLists.txt
@@ -55,7 +55,7 @@ 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
+# part of a custom command 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})
diff --git a/Tests/ExternalProject/CMakeLists.txt b/Tests/ExternalProject/CMakeLists.txt
index 6b7356340..5adcbd9e2 100644
--- a/Tests/ExternalProject/CMakeLists.txt
+++ b/Tests/ExternalProject/CMakeLists.txt
@@ -631,3 +631,21 @@ ExternalProject_Add(${proj}
LOG_BUILD 1
LOG_INSTALL 1
)
+
+set(proj ExternalProject-log-dir)
+ExternalProject_Add(${proj}
+ DOWNLOAD_COMMAND "${download_cmd}" COMMAND "${CMAKE_COMMAND}" -E echo "download"
+ PATCH_COMMAND "${patch_cmd}" COMMAND "${CMAKE_COMMAND}" -E echo "patch"
+ UPDATE_COMMAND "${update_cmd}" COMMAND "${CMAKE_COMMAND}" -E echo "update"
+ CONFIGURE_COMMAND "${configure_cmd}" COMMAND "${CMAKE_COMMAND}" -E echo "configure"
+ BUILD_COMMAND "${build_cmd}" COMMAND "${CMAKE_COMMAND}" -E echo "build"
+ INSTALL_COMMAND "${install_cmd}" COMMAND "${CMAKE_COMMAND}" -E echo "install"
+ LOG_MERGED_STDOUTERR 1
+ LOG_DIR ${CMAKE_CURRENT_BINARY_DIR}/different_log
+ LOG_DOWNLOAD 1
+ LOG_PATCH 1
+ LOG_UPDATE 1
+ LOG_CONFIGURE 1
+ LOG_BUILD 1
+ LOG_INSTALL 1
+ )
diff --git a/Tests/ExternalProjectLocal/CMakeLists.txt b/Tests/ExternalProjectLocal/CMakeLists.txt
index 5b941630a..1075a9d07 100644
--- a/Tests/ExternalProjectLocal/CMakeLists.txt
+++ b/Tests/ExternalProjectLocal/CMakeLists.txt
@@ -20,71 +20,55 @@ 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)
-
- # 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>
- CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
- TEST_AFTER_INSTALL 1
- LOG_TEST 1
- )
- set_property(TARGET ${proj} PROPERTY FOLDER "Local")
-
- set(proj TutorialStep5-Local-TestExcludeFromMainBefore)
- ExternalProject_Add(${proj}
- URL "${CMAKE_CURRENT_SOURCE_DIR}/../Tutorial/Step5"
- CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
- CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
- TEST_BEFORE_INSTALL 1
- TEST_EXCLUDE_FROM_MAIN 1
- STEP_TARGETS test
- LOG_TEST 1
- )
- set_property(TARGET ${proj} PROPERTY FOLDER "Local")
-
- set(proj TutorialStep5-Local-TestExcludeFromMainAfter)
- ExternalProject_Add(${proj}
- URL "${CMAKE_CURRENT_SOURCE_DIR}/../Tutorial/Step5"
- CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
- CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
- TEST_AFTER_INSTALL 1
- TEST_EXCLUDE_FROM_MAIN 1
- STEP_TARGETS test
- LOG_TEST 1
- )
- set_property(TARGET ${proj} PROPERTY FOLDER "Local")
+set(proj TutorialStep5-Local)
+ExternalProject_Add(${proj}
+URL "${CMAKE_CURRENT_SOURCE_DIR}/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}/Step5"
+CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
+TEST_AFTER_INSTALL 1
+LOG_TEST 1
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local")
+
+set(proj TutorialStep5-Local-TestExcludeFromMainBefore)
+ExternalProject_Add(${proj}
+URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
+CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
+TEST_BEFORE_INSTALL 1
+TEST_EXCLUDE_FROM_MAIN 1
+STEP_TARGETS test
+LOG_TEST 1
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local")
+
+set(proj TutorialStep5-Local-TestExcludeFromMainAfter)
+ExternalProject_Add(${proj}
+URL "${CMAKE_CURRENT_SOURCE_DIR}/Step5"
+CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -G ${CMAKE_GENERATOR} <SOURCE_DIR>
+CMAKE_CACHE_DEFAULT_ARGS -DUSE_MYMATH:BOOL=OFF
+TEST_AFTER_INSTALL 1
+TEST_EXCLUDE_FROM_MAIN 1
+STEP_TARGETS test
+LOG_TEST 1
+)
+set_property(TARGET ${proj} PROPERTY FOLDER "Local")
-endif()
# Local TAR:
@@ -100,6 +84,7 @@ ExternalProject_Add(${proj}
-DTEST_LIST:STRING=A::B::C
INSTALL_COMMAND ""
LOG_CONFIGURE 1
+ LOG_PATCH 1
)
set_property(TARGET ${proj} PROPERTY FOLDER "Local/TAR")
@@ -208,12 +193,10 @@ enable_testing()
#
# 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(TutorialStep5-Local-BuildTreeTest
+"${binary_base}/TutorialStep5-Local/Tutorial" 42)
+set_property(TEST TutorialStep5-Local-BuildTreeTest
+APPEND PROPERTY LABELS Step5 BuildTree)
add_test(TutorialStep1-LocalTAR-BuildTreeTest
"${binary_base}/TutorialStep1-LocalTAR/EP-Tutorial" 36)
@@ -233,12 +216,7 @@ add_test(TutorialStep1-LocalNoDirTGZ-BuildTreeTest
# 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}'")
+add_test(TutorialStep5-InstallTreeTest
+"${TutorialStep5_install_dir}/bin/Tutorial" 49)
+set_property(TEST TutorialStep5-InstallTreeTest
+APPEND PROPERTY LABELS Step5 InstallTree)
diff --git a/Tests/FindBoost/CMakeLists.txt b/Tests/FindBoost/CMakeLists.txt
index 0e9527de0..8489d859c 100644
--- a/Tests/FindBoost/CMakeLists.txt
+++ b/Tests/FindBoost/CMakeLists.txt
@@ -9,6 +9,21 @@ add_test(NAME FindBoost.Test COMMAND
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
+add_test(NAME FindBoost.TestFail COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindBoost/TestFail"
+ "${CMake_BINARY_DIR}/Tests/FindBoost/TestFail"
+ ${build_generator_args}
+ --build-project TestFailFindBoost
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
+
+set_tests_properties(FindBoost.TestFail PROPERTIES
+ WILL_FAIL ON
+ PASS_REGULAR_EXPRESSION "Could NOT find Boost (missing: foobar)")
+
add_test(NAME FindBoost.TestHeaders COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
@@ -19,3 +34,16 @@ add_test(NAME FindBoost.TestHeaders COMMAND
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
+
+if (CMake_TEST_FindBoost_Python)
+ add_test(NAME FindBoost.TestPython COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindBoost/TestPython"
+ "${CMake_BINARY_DIR}/Tests/FindBoost/TestPython"
+ ${build_generator_args}
+ --build-project TestFindBoostPython
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
+endif ()
diff --git a/Tests/FindBoost/Test/CMakeLists.txt b/Tests/FindBoost/Test/CMakeLists.txt
index ce50fc775..f60ccfa00 100644
--- a/Tests/FindBoost/Test/CMakeLists.txt
+++ b/Tests/FindBoost/Test/CMakeLists.txt
@@ -2,7 +2,20 @@ cmake_minimum_required(VERSION 3.1)
project(TestFindBoost CXX)
include(CTest)
-find_package(Boost REQUIRED COMPONENTS filesystem thread)
+set(Boost_NO_BOOST_CMAKE ON)
+find_package(Boost REQUIRED COMPONENTS filesystem thread
+ OPTIONAL_COMPONENTS program_options foobar)
+
+if(Boost_FOOBAR_FOUND)
+ message(FATAL_ERROR "Optional inexistent Boost component \"foobar\" found which is unexpected")
+endif(Boost_FOOBAR_FOUND)
+
+if(NOT Boost_PROGRAM_OPTIONS_FOUND)
+ message(FATAL_ERROR "Optional Boost component \"program_options\" not found which is unexpected")
+endif(NOT Boost_PROGRAM_OPTIONS_FOUND)
+
+add_definitions(-DCMAKE_EXPECTED_BOOST_VERSION="${Boost_VERSION}")
+add_definitions(-DCMAKE_EXPECTED_BOOST_VERSION_COMPONENTS="${Boost_VERSION_STRING}")
add_executable(test_boost_tgt main.cxx)
target_link_libraries(test_boost_tgt
diff --git a/Tests/FindBoost/Test/main.cxx b/Tests/FindBoost/Test/main.cxx
index 6e8b5da63..50ddadfba 100644
--- a/Tests/FindBoost/Test/main.cxx
+++ b/Tests/FindBoost/Test/main.cxx
@@ -20,5 +20,20 @@ int main()
boost::thread foo(threadmain);
foo.join();
- return 0;
+ int version = BOOST_VERSION;
+ int major = version / 100000;
+ int minor = version / 100 % 1000;
+ int patch = version % 100;
+ char version_string[100];
+ snprintf(version_string, sizeof(version_string), "%d.%d.%d", major, minor,
+ patch);
+ printf("Found Boost version %s, expected version %s\n", version_string,
+ CMAKE_EXPECTED_BOOST_VERSION_COMPONENTS);
+ int ret = strcmp(version_string, CMAKE_EXPECTED_BOOST_VERSION_COMPONENTS);
+ char raw_version_string[100];
+ snprintf(raw_version_string, sizeof(raw_version_string), "%d",
+ BOOST_VERSION);
+ printf("Found Boost version %s, expected version %s\n", raw_version_string,
+ CMAKE_EXPECTED_BOOST_VERSION);
+ return ret | strcmp(raw_version_string, CMAKE_EXPECTED_BOOST_VERSION);
}
diff --git a/Tests/FindDoxygen/CMakeLists.txt b/Tests/FindDoxygen/CMakeLists.txt
index daceaa3e9..7ce98d59b 100644
--- a/Tests/FindDoxygen/CMakeLists.txt
+++ b/Tests/FindDoxygen/CMakeLists.txt
@@ -8,6 +8,26 @@ add_test(NAME FindDoxygen.SimpleTest COMMAND
--build-options ${build_options}
)
+add_test(NAME FindDoxygen.QuotingTest COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindDoxygen/QuotingTest"
+ "${CMake_BINARY_DIR}/Tests/FindDoxygen/QuotingTest"
+ --build-target allDocTargets
+ ${build_generator_args}
+ --build-options ${build_options}
+)
+
+add_test(NAME FindDoxygen.AllTarget COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindDoxygen/AllTarget"
+ "${CMake_BINARY_DIR}/Tests/FindDoxygen/AllTarget"
+ ${build_generator_args}
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+)
+
if(CMake_TEST_FindDoxygen_Dot)
add_test(NAME FindDoxygen.DotComponentTest COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
diff --git a/Tests/FindGTK2/cairomm/main.cpp b/Tests/FindGTK2/cairomm/main.cpp
index 1a669c36e..44326012b 100644
--- a/Tests/FindGTK2/cairomm/main.cpp
+++ b/Tests/FindGTK2/cairomm/main.cpp
@@ -5,7 +5,7 @@
* et. al.
*/
#if defined(_MSC_VER)
-#define _USE_MATH_DEFINES
+# define _USE_MATH_DEFINES
#endif
#include <cairomm/context.h>
diff --git a/Tests/FindGTest/Test/main.cxx b/Tests/FindGTest/Test/main.cxx
index 0572a5ddc..19d29675b 100644
--- a/Tests/FindGTest/Test/main.cxx
+++ b/Tests/FindGTest/Test/main.cxx
@@ -2,5 +2,7 @@
TEST(FindCMake, LinksAndRuns)
{
+ using namespace testing;
+ EXPECT_FALSE(GTEST_FLAG(list_tests));
ASSERT_TRUE(true);
}
diff --git a/Tests/FindLTTngUST/Test/main.c b/Tests/FindLTTngUST/Test/main.c
index 1f313c1a9..01d73cb73 100644
--- a/Tests/FindLTTngUST/Test/main.c
+++ b/Tests/FindLTTngUST/Test/main.c
@@ -4,11 +4,11 @@
#include <string.h>
#ifdef CMAKE_LTTNGUST_HAS_TRACEF
-#include <lttng/tracef.h>
+# include <lttng/tracef.h>
#endif
#ifdef CMAKE_LTTNGUST_HAS_TRACELOG
-#include <lttng/tracelog.h>
+# include <lttng/tracelog.h>
#endif
int main(void)
diff --git a/Tests/FindMPI/Test/CMakeLists.txt b/Tests/FindMPI/Test/CMakeLists.txt
index 3910c254f..efe8c6261 100644
--- a/Tests/FindMPI/Test/CMakeLists.txt
+++ b/Tests/FindMPI/Test/CMakeLists.txt
@@ -20,12 +20,17 @@ foreach(c C CXX Fortran)
endif()
endforeach()
+set(MPI_CXX_SKIP_MPICXX TRUE)
+set(MPI_CXX_VALIDATE_SKIP_MPICXX TRUE)
find_package(MPI REQUIRED)
foreach(c C CXX Fortran)
if(NOT "${MPI_TEST_${c}}")
continue()
endif()
+ if(${c} STREQUAL CXX AND MPI_MPICXX_FOUND)
+ message(FATAL_ERROR "Could not suppress MPI-2 C++ bindings for this MPI.")
+ endif()
source_code_mapper_helper(${c})
add_executable(test_tgt_${c} ${MPITEST_SOURCE_FILE})
target_link_libraries(test_tgt_${c} MPI::MPI_${c})
diff --git a/Tests/FindMatlab/basic_checks/CMakeLists.txt b/Tests/FindMatlab/basic_checks/CMakeLists.txt
index bf5442767..c5be1ea25 100644
--- a/Tests/FindMatlab/basic_checks/CMakeLists.txt
+++ b/Tests/FindMatlab/basic_checks/CMakeLists.txt
@@ -8,8 +8,22 @@ set(MATLAB_FIND_DEBUG TRUE)
# the success of the following command is dependent on the current configuration:
# - on 32bits builds (cmake is building with 32 bits), it looks for 32 bits Matlab
# - on 64bits builds (cmake is building with 64 bits), it looks for 64 bits Matlab
-find_package(Matlab REQUIRED COMPONENTS MX_LIBRARY MAIN_PROGRAM)
+if(IS_MCR)
+ set(RUN_UNIT_TESTS FALSE)
+else()
+ set(RUN_UNIT_TESTS TRUE)
+ set(components MAIN_PROGRAM)
+endif()
+
+if(NOT "${MCR_ROOT}" STREQUAL "")
+ set(Matlab_ROOT_DIR "${MCR_ROOT}")
+ if(NOT EXISTS "${MCR_ROOT}")
+ message(FATAL_ERROR "MCR does not exist ${MCR_ROOT}")
+ endif()
+endif()
+
+find_package(Matlab REQUIRED COMPONENTS ${components})
matlab_add_mex(
@@ -19,39 +33,41 @@ matlab_add_mex(
OUTPUT_NAME cmake_matlab_mex1
SRC ${CMAKE_CURRENT_SOURCE_DIR}/../matlab_wrapper1.cpp
DOCUMENTATION ${CMAKE_CURRENT_SOURCE_DIR}/../help_text1.m.txt
- )
-
-
-matlab_add_unit_test(
- NAME ${PROJECT_NAME}_matlabtest-1
- TIMEOUT 90
- UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests1.m
- ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
)
-matlab_add_unit_test(
- NAME ${PROJECT_NAME}_matlabtest-2
- TIMEOUT 15
- UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests_timeout.m
- ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
- )
-set_tests_properties(${PROJECT_NAME}_matlabtest-2 PROPERTIES WILL_FAIL TRUE)
+if(RUN_UNIT_TESTS)
+ matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-1
+ TIMEOUT 300
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests1.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+ # timeout tests, TIMEOUT set to very short on purpose
+ matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-2
+ TIMEOUT 15
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests_timeout.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+ set_tests_properties(${PROJECT_NAME}_matlabtest-2 PROPERTIES WILL_FAIL TRUE)
-# testing the test without the unittest framework of Matlab
-matlab_add_unit_test(
- NAME ${PROJECT_NAME}_matlabtest-3
- TIMEOUT 30
- NO_UNITTEST_FRAMEWORK
- UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests2.m
- ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
- )
-matlab_add_unit_test(
- NAME ${PROJECT_NAME}_matlabtest-4
- TIMEOUT 30
- NO_UNITTEST_FRAMEWORK
- UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests3.m
- ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
- )
-set_tests_properties(${PROJECT_NAME}_matlabtest-4 PROPERTIES WILL_FAIL TRUE)
+ # testing the test without the unittest framework of Matlab
+ matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-3
+ TIMEOUT 300
+ NO_UNITTEST_FRAMEWORK
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests2.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+
+ matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-4
+ TIMEOUT 300
+ NO_UNITTEST_FRAMEWORK
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests3.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+ set_tests_properties(${PROJECT_NAME}_matlabtest-4 PROPERTIES WILL_FAIL TRUE)
+endif()
diff --git a/Tests/FindMatlab/components_checks/CMakeLists.txt b/Tests/FindMatlab/components_checks/CMakeLists.txt
index 3dec0931c..f5d488060 100644
--- a/Tests/FindMatlab/components_checks/CMakeLists.txt
+++ b/Tests/FindMatlab/components_checks/CMakeLists.txt
@@ -5,10 +5,18 @@ project(component_checks)
set(MATLAB_FIND_DEBUG TRUE)
+if(NOT "${MCR_ROOT}" STREQUAL "")
+ set(Matlab_ROOT_DIR "${MCR_ROOT}")
+ if(NOT EXISTS "${MCR_ROOT}")
+ message(FATAL_ERROR "MCR does not exist ${MCR_ROOT}")
+ endif()
+endif()
+
# the success of the following command is dependent on the current configuration:
# - on 32bits builds (cmake is building with 32 bits), it looks for 32 bits Matlab
# - on 64bits builds (cmake is building with 64 bits), it looks for 64 bits Matlab
-find_package(Matlab REQUIRED COMPONENTS MX_LIBRARY ENG_LIBRARY MAT_LIBRARY MAIN_PROGRAM)
+find_package(Matlab REQUIRED COMPONENTS ENG_LIBRARY MAT_LIBRARY
+ OPTIONAL_COMPONENTS MAIN_PROGRAM)
message(STATUS "FindMatlab libraries: ${Matlab_LIBRARIES}")
@@ -20,4 +28,4 @@ matlab_add_mex(
SRC ${CMAKE_CURRENT_SOURCE_DIR}/../matlab_wrapper1.cpp
DOCUMENTATION ${CMAKE_CURRENT_SOURCE_DIR}/../help_text1.m.txt
LINK_TO ${Matlab_LIBRARIES}
- )
+ )
diff --git a/Tests/FindMatlab/versions_checks/CMakeLists.txt b/Tests/FindMatlab/versions_checks/CMakeLists.txt
index 5d20685c2..d015730b0 100644
--- a/Tests/FindMatlab/versions_checks/CMakeLists.txt
+++ b/Tests/FindMatlab/versions_checks/CMakeLists.txt
@@ -7,6 +7,13 @@ set(MATLAB_FIND_DEBUG TRUE)
set(MATLAB_ADDITIONAL_VERSIONS
"dummy=14.9")
+if(NOT "${MCR_ROOT}" STREQUAL "")
+ set(Matlab_ROOT_DIR "${MCR_ROOT}")
+ if(NOT EXISTS "${MCR_ROOT}")
+ message(FATAL_ERROR "MCR does not exist ${MCR_ROOT}")
+ endif()
+endif()
+
# the success of the following command is dependent on the current configuration
# in this case, we are only interested in the version macros
find_package(Matlab)
diff --git a/Tests/FindOpenCL/Test/main.c b/Tests/FindOpenCL/Test/main.c
index dc7763645..2fe949bd0 100644
--- a/Tests/FindOpenCL/Test/main.c
+++ b/Tests/FindOpenCL/Test/main.c
@@ -1,7 +1,7 @@
#ifdef __APPLE__
-#include <OpenCL/opencl.h>
+# include <OpenCL/opencl.h>
#else
-#include <CL/cl.h>
+# include <CL/cl.h>
#endif
int main()
diff --git a/Tests/FindOpenGL/CMakeLists.txt b/Tests/FindOpenGL/CMakeLists.txt
index 9aa3abafb..97c9e6052 100644
--- a/Tests/FindOpenGL/CMakeLists.txt
+++ b/Tests/FindOpenGL/CMakeLists.txt
@@ -1,3 +1,9 @@
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMake_TEST_FindOpenGL_VND)
+ set(_vnd_testing TRUE)
+else()
+ set(_vnd_testing FALSE)
+endif()
+
add_test(NAME FindOpenGL.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
@@ -6,5 +12,6 @@ add_test(NAME FindOpenGL.Test COMMAND
${build_generator_args}
--build-project TestFindOpenGL
--build-options ${build_options}
+ -DOpenGL_TEST_VND=${_vnd_testing}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
diff --git a/Tests/FindOpenGL/Test/CMakeLists.txt b/Tests/FindOpenGL/Test/CMakeLists.txt
index cac342488..9004a9860 100644
--- a/Tests/FindOpenGL/Test/CMakeLists.txt
+++ b/Tests/FindOpenGL/Test/CMakeLists.txt
@@ -1,14 +1,71 @@
-cmake_minimum_required(VERSION 3.7)
+cmake_minimum_required(VERSION 3.10)
+cmake_policy(SET CMP0072 NEW)
project(TestFindOpenGL C)
include(CTest)
find_package(OpenGL REQUIRED)
+# import target for GLU
add_executable(test_tgt main.c)
target_link_libraries(test_tgt OpenGL::GLU)
add_test(NAME test_tgt COMMAND test_tgt)
+# OPENGL_LIBRARIES should be whatever libraries are needed to link.
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${OPENGL_INGLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${OPENGL_LIBRARIES})
add_test(NAME test_var COMMAND test_var)
+
+# VND support adds an ::OpenGL import target. This can be used for OpenGL-only
+# code (code that does not manipulate contexts, like our 'main.c'). Without
+# VND, ::GL can be used for both context and non-context OpenGL code.
+if(OpenGL_TEST_VND)
+ add_executable(test_comp_none main.c)
+ target_link_libraries(test_comp_none PRIVATE OpenGL::OpenGL)
+ add_test(NAME test_comp_none COMMAND test_comp_none)
+else()
+ add_executable(test_comp_none main.c)
+ target_link_libraries(test_comp_none PRIVATE OpenGL::GL)
+ add_test(NAME test_comp_none COMMAND test_comp_none)
+endif()
+
+# GLX
+if(OpenGL_TEST_VND)
+ find_package(OpenGL REQUIRED COMPONENTS OpenGL GLX)
+ add_executable(test_comp_glx main.c)
+ target_link_libraries(test_comp_glx PRIVATE OpenGL::OpenGL OpenGL::GLX)
+ add_test(NAME test_comp_glx COMMAND test_comp_glx)
+else()
+ # non-VND systems won't have it, but an optional search for GLX should still
+ # be okay.
+ find_package(OpenGL COMPONENTS GLX)
+ add_executable(test_comp_glx_novnd main.c)
+ target_link_libraries(test_comp_glx_novnd PRIVATE OpenGL::GL)
+ add_test(NAME test_comp_glx_novnd COMMAND test_comp_glx_novnd)
+endif()
+
+# EGL is only available on Linux+GLVND at present.
+if(OpenGL_TEST_VND)
+ find_package(OpenGL COMPONENTS OpenGL EGL)
+ if(OpenGL_EGL_FOUND)
+ add_executable(test_comp_egl main.c)
+ target_link_libraries(test_comp_egl PRIVATE OpenGL::OpenGL OpenGL::EGL)
+ add_test(NAME test_comp_egl COMMAND test_comp_egl)
+ # EGL-only code should not link to GLX.
+ execute_process(COMMAND ldd test_comp_egl
+ OUTPUT_VARIABLE LDD_OUT
+ ERROR_VARIABLE LDD_ERR)
+ if("${LDD_OUT}" MATCHES "GLX")
+ message(FATAL_ERROR "EGL-only code links to GLX!")
+ endif()
+ endif()
+
+ # all three COMPONENTS together.
+ find_package(OpenGL COMPONENTS OpenGL EGL GLX)
+ if(OpenGL_EGL_FOUND AND OpenGL_GLX_FOUND)
+ add_executable(test_comp_both main.c)
+ target_link_libraries(test_comp_both PRIVATE OpenGL::OpenGL OpenGL::EGL
+ OpenGL::GLX)
+ add_test(NAME test_comp_both COMMAND test_comp_both)
+ endif()
+endif()
diff --git a/Tests/FindOpenGL/Test/main.c b/Tests/FindOpenGL/Test/main.c
index bca3d7e3f..e1f25c630 100644
--- a/Tests/FindOpenGL/Test/main.c
+++ b/Tests/FindOpenGL/Test/main.c
@@ -1,10 +1,10 @@
#ifdef _WIN32
-#include <windows.h>
+# include <windows.h>
#endif
#ifdef __APPLE__
-#include <OpenGL/gl.h>
+# include <OpenGL/gl.h>
#else
-#include <GL/gl.h>
+# include <GL/gl.h>
#endif
#include <stdio.h>
diff --git a/Tests/FindOpenMP/Test/scaltest.c b/Tests/FindOpenMP/Test/scaltest.c
index 2ee57f833..4678b87a4 100644
--- a/Tests/FindOpenMP/Test/scaltest.c
+++ b/Tests/FindOpenMP/Test/scaltest.c
@@ -1,8 +1,8 @@
#ifdef __cplusplus
-#include <iostream>
+# include <iostream>
extern "C"
#else
-#include <stdio.h>
+# include <stdio.h>
#endif
int scalprod(int n, double* x, double* y, double* res);
diff --git a/Tests/FindOpenSSL/rand/main.cc b/Tests/FindOpenSSL/rand/main.cc
index d81b31898..147044ba3 100644
--- a/Tests/FindOpenSSL/rand/main.cc
+++ b/Tests/FindOpenSSL/rand/main.cc
@@ -9,7 +9,7 @@ int main()
unsigned char buf[1024];
// random bytes
- int rezval = RAND_bytes(buf, sizeof(buf)); /* 1 succes, 0 otherwise */
+ int rezval = RAND_bytes(buf, sizeof(buf)); /* 1 success, 0 otherwise */
// check result
if (rezval == 1) {
diff --git a/Tests/FindPackageModeMakefileTest/foo.cpp b/Tests/FindPackageModeMakefileTest/foo.cpp
index 6aea22629..7cb9381ed 100644
--- a/Tests/FindPackageModeMakefileTest/foo.cpp
+++ b/Tests/FindPackageModeMakefileTest/foo.cpp
@@ -1,3 +1,5 @@
+#include "foo.h"
+
int foo()
{
return 1477;
diff --git a/Tests/FindPackageModeMakefileTest/foo.h b/Tests/FindPackageModeMakefileTest/foo.h
index 4ec598ad5..7051edac4 100644
--- a/Tests/FindPackageModeMakefileTest/foo.h
+++ b/Tests/FindPackageModeMakefileTest/foo.h
@@ -1,6 +1,14 @@
#ifndef FOO_H
#define FOO_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
int foo();
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
#endif
diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt
index 1a6f20429..1b9c973b1 100644
--- a/Tests/FindPackageTest/CMakeLists.txt
+++ b/Tests/FindPackageTest/CMakeLists.txt
@@ -188,7 +188,43 @@ 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.
+# Test find_package() with CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS enabled
+if(UNIX)
+ # Create ./symlink pointing back here.
+ execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
+ . "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
+ # Make find_package search through the symlink
+ set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
+
+ # First, test the default behavior where symlinks are preserved.
+ set(SetFoundResolved_DIR "")
+ find_package(SetFoundResolved)
+ # The result must preserve the /symlink/ path.
+ set(SetFoundResolved_EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/symlink/cmake")
+ if(NOT "${SetFoundResolved_DIR}" STREQUAL "${SetFoundResolved_EXPECTED}")
+ message(SEND_ERROR "SetFoundResolved_DIR set by find_package() is set to \"${SetFoundResolved_DIR}\" (expected \"${SetFoundResolved_EXPECTED}\")")
+ endif()
+
+ # This part of the test only works if there are no symlinks in our path.
+ get_filename_component(real_src_dir "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
+ if(real_src_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ # Resolve symlinks when finding the package.
+ set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS TRUE)
+ set(SetFoundResolved_DIR "")
+ find_package(SetFoundResolved)
+ # ./symlink points back here so it should be gone when resolved.
+ set(SetFoundResolved_EXPECTED "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+ if(NOT "${SetFoundResolved_DIR}" STREQUAL "${SetFoundResolved_EXPECTED}")
+ message(SEND_ERROR "SetFoundResolved_DIR set by find_package() is set to \"${SetFoundResolved_DIR}\" (expected \"${SetFoundResolved_EXPECTED}\")")
+ endif()
+ endif()
+
+ # Cleanup.
+ unset(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS)
+ file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/symlink")
+endif()
+
+# Test <PackageName>_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")
@@ -349,6 +385,7 @@ try_compile(EXPORTER_COMPILED
${FindPackageTest_SOURCE_DIR}/Exporter
CMakeTestExportPackage dummy
CMAKE_FLAGS "-UCMAKE_EXPORT_NO_PACKAGE_REGISTRY"
+ "-DCMAKE_POLICY_DEFAULT_CMP0090:STRING=OLD"
-Dversion=${version}
OUTPUT_VARIABLE output)
message(STATUS "Searching for export(PACKAGE) test project")
@@ -386,6 +423,25 @@ if(CMakeTestExportPackage_FOUND)
message(SEND_ERROR "CMakeTestExportPackage should not be FOUND!")
endif()
+message(STATUS "Remove export(PACKAGE) test project")
+file(REMOVE_RECURSE ${FindPackageTest_BINARY_DIR}/Exporter-build)
+
+message(STATUS "Preparing export(PACKAGE) test project with POLICY CMP0090=NEW")
+try_compile(EXPORTER_COMPILED
+ ${FindPackageTest_BINARY_DIR}/Exporter-build
+ ${FindPackageTest_SOURCE_DIR}/Exporter
+ CMakeTestExportPackage dummy
+ CMAKE_FLAGS
+ "-DCMAKE_POLICY_DEFAULT_CMP0090:STRING=NEW"
+ -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().
@@ -461,205 +517,117 @@ if(Relocatable_FOUND)
endif()
+############################################################################
+##Test FIND_PACKAGE using sorting
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+SET(CMAKE_FIND_PACKAGE_SORT_ORDER NAME)
+SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION ASC)
-#-----------------------------------------------------------------------------
-# 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 !")
+set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
+FIND_PACKAGE(SortLib CONFIG)
+IF (NOT "${SortLib_VERSION}" STREQUAL "3.1.1")
+ message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Name Asc! ${SortLib_VERSION}")
endif()
+unset(SortLib_VERSION)
-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 !")
+set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
+SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
+SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
+FIND_PACKAGE(SortLib CONFIG)
+IF (NOT "${SortLib_VERSION}" STREQUAL "3.10.1")
+ message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Natural! Dec ${SortLib_VERSION}")
endif()
+set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
+unset(SortLib_VERSION)
+unset(CMAKE_FIND_PACKAGE_SORT_ORDER)
+unset(CMAKE_FIND_PACKAGE_SORT_DIRECTION)
+set(CMAKE_PREFIX_PATH )
-#######################
-include(WriteBasicConfigVersionFile)
+############################################################################
+##Test FIND_PACKAGE CMAKE_FIND_PACKAGE_PREFER_CONFIG
-write_basic_config_version_file(${CMAKE_CURRENT_BINARY_DIR}/Boo123ConfigVersion.cmake
- VERSION 1.2.3
- COMPATIBILITY SameMajorVersion)
+set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfig)
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfig)
-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()
+# prefer module mode
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF)
+unset(ABC_FOUND)
+unset(ABC_CONFIG)
-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 !")
+find_package(ABC)
+if(NOT ABC_FOUND)
+ message(SEND_ERROR "Did not find ABC package")
endif()
-if(PACKAGE_VERSION_EXACT)
- message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !")
+if(ABC_CONFIG)
+ message(SEND_ERROR "Incorrectly found ABC in CONFIG mode, expected to find it with MODULE mode")
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()
+# Now prefer config mode
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
+unset(ABC_FOUND)
+unset(ABC_CONFIG)
-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) !")
+find_package(ABC)
+if(NOT ABC_FOUND)
+ message(SEND_ERROR "Did not find ABC package")
endif()
-if(NOT PACKAGE_VERSION_EXACT)
- message(SEND_ERROR "PACKAGE_VERSION_EXACT not set, although it should be !")
+if(NOT ABC_CONFIG)
+ message(SEND_ERROR "Incorrectly found ABC in MODULE mode, expected to find it with CONFIG mode")
endif()
-if(PACKAGE_VERSION_UNSUITABLE)
- message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !")
-endif()
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF)
+set(CMAKE_PREFIX_PATH)
+set(CMAKE_MODULE_PATH)
-#######################
+############################################################################
+##Test FIND_PACKAGE CMAKE_FIND_PACKAGE_PREFER_CONFIG - Do not recurse
-write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake
- VERSION 1.2.3.17
- COMPATIBILITY ExactVersion)
+# No CMAKE_PREFIX_PATH
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfigRecurse)
-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()
+# Now prefer config mode
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
+unset(ACME_FOUND)
+unset(ACME_CONFIG)
-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 !")
+find_package(ACME)
+if(ACME_FOUND AND ACME_CONFIG)
+ message(SEND_ERROR "Incorrectly found ACME in CONFIG mode, from the MODULE package")
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(CMAKE_FIND_PACKAGE_PREFER_CONFIG OFF)
+set(CMAKE_MODULE_PATH)
-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()
+############################################################################
+##Test find_package CMAKE_FIND_PACKAGE_PREFER_CONFIG with module fallback
-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(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfigOnlyModule)
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
-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()
+find_package(ACME REQUIRED)
-if(PACKAGE_VERSION_UNSUITABLE)
- message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !")
+if(NOT ACME_FOUND)
+ message(SEND_ERROR "Did not find ACME package")
endif()
-
############################################################################
-##Test FIND_PACKAGE using sorting
-set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR})
-SET(CMAKE_FIND_PACKAGE_SORT_ORDER NAME)
-SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION ASC)
+##Test find_package CMAKE_FIND_PACKAGE_PREFER_CONFIG with NO_MODULE
-set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
-FIND_PACKAGE(SortLib CONFIG)
-IF (NOT "${SortLib_VERSION}" STREQUAL "3.1.1")
- message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Name Asc! ${SortLib_VERSION}")
-endif()
-unset(SortLib_VERSION)
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/PreferConfigOnlyModule)
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
-set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
-SET(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
-SET(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
-FIND_PACKAGE(SortLib CONFIG)
-IF (NOT "${SortLib_VERSION}" STREQUAL "3.10.1")
- message(SEND_ERROR "FIND_PACKAGE_SORT_ORDER Natural! Dec ${SortLib_VERSION}")
+find_package(ACME NO_MODULE)
+
+if(ACME_FOUND)
+ message(SEND_ERROR "Should not find ACME package")
endif()
-set(SortLib_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
-unset(SortLib_VERSION)
+############################################################################
+##Test find_package CMAKE_FIND_PACKAGE_PREFER_CONFIG with unknown package
-unset(CMAKE_FIND_PACKAGE_SORT_ORDER)
-unset(CMAKE_FIND_PACKAGE_SORT_DIRECTION)
-set(CMAKE_PREFIX_PATH )
+set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
+find_package(DoesNotExist)
diff --git a/Tests/FindProtobuf/Test/CMakeLists.txt b/Tests/FindProtobuf/Test/CMakeLists.txt
index 8b6e38a8e..bc89190b3 100644
--- a/Tests/FindProtobuf/Test/CMakeLists.txt
+++ b/Tests/FindProtobuf/Test/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.4)
+cmake_minimum_required(VERSION 3.8)
project(TestFindProtobuf CXX)
include(CTest)
@@ -30,3 +30,21 @@ add_executable(test_var_protoc main-protoc.cxx)
target_include_directories(test_var_protoc PRIVATE ${Protobuf_INCLUDE_DIRS})
target_link_libraries(test_var_protoc PRIVATE ${Protobuf_PROTOC_LIBRARIES})
add_test(NAME test_var_protoc COMMAND test_var_protoc)
+
+add_test(NAME test_tgt_protoc_version COMMAND protobuf::protoc --version)
+
+set(Protobuf_IMPORT_DIRS ${Protobuf_INCLUDE_DIRS})
+PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HEADER msgs/example.proto)
+PROTOBUF_GENERATE_CPP(DESC_PROTO_SRC DESC_PROTO_HEADER DESCRIPTORS DESC_PROTO_DESC msgs/example_desc.proto)
+add_library(msgs ${PROTO_SRC} ${PROTO_HEADER})
+
+add_executable(test_generate main-generate.cxx ${PROTO_SRC})
+target_include_directories(test_generate PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(test_generate msgs ${Protobuf_LIBRARIES})
+add_test(NAME test_generate COMMAND test_generate)
+
+add_executable(test_desc main-desc.cxx ${DESC_PROTO_SRC})
+target_compile_features(test_desc PRIVATE cxx_std_11)
+target_include_directories(test_desc PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(test_desc msgs ${Protobuf_LIBRARIES})
+add_test(NAME test_desc COMMAND test_desc ${DESC_PROTO_DESC})
diff --git a/Tests/FindThreads/C-only/CMakeLists.txt b/Tests/FindThreads/C-only/CMakeLists.txt
index ab4ca0ddd..ee2a5f991 100644
--- a/Tests/FindThreads/C-only/CMakeLists.txt
+++ b/Tests/FindThreads/C-only/CMakeLists.txt
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(FindThreads_C-only C)
-set(CMAKE_THREAD_PREFER_PTHREAD On)
find_package(Threads REQUIRED)
if (NOT WIN32)
diff --git a/Tests/FindThreads/CXX-only/CMakeLists.txt b/Tests/FindThreads/CXX-only/CMakeLists.txt
index 999312322..3c6cc1e55 100644
--- a/Tests/FindThreads/CXX-only/CMakeLists.txt
+++ b/Tests/FindThreads/CXX-only/CMakeLists.txt
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(FindThreads_CXX-only CXX)
-set(CMAKE_THREAD_PREFER_PTHREAD On)
find_package(Threads REQUIRED)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../../Modules/CheckForPthreads.c
diff --git a/Tests/ForceInclude/foo.c b/Tests/ForceInclude/foo.c
index 7f550d0f9..2a26c6f33 100644
--- a/Tests/ForceInclude/foo.c
+++ b/Tests/ForceInclude/foo.c
@@ -1,8 +1,8 @@
#ifndef FOO_1
-#error "foo1.h not included by /FI"
+# error "foo1.h not included by /FI"
#endif
#ifndef FOO_2
-#error "foo2.h not included by /FI"
+# error "foo2.h not included by /FI"
#endif
int main(void)
{
diff --git a/Tests/Fortran/CMakeLists.txt b/Tests/Fortran/CMakeLists.txt
index 740e6f594..929fa4ddf 100644
--- a/Tests/Fortran/CMakeLists.txt
+++ b/Tests/Fortran/CMakeLists.txt
@@ -46,7 +46,7 @@ function(test_fortran_c_interface_module)
FortranCInterface_VERIFY()
FortranCInterface_VERIFY(CXX)
if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
- if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|MIPSpro|PathScale|Absoft")
+ if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "SunPro|PathScale|Absoft")
set(module_expected 1)
endif()
if(FortranCInterface_MODULE_FOUND OR module_expected)
@@ -99,6 +99,11 @@ function(test_fortran_c_interface_module)
target_link_libraries(myc myfort)
set_property(TARGET myc PROPERTY COMPILE_DEFINITIONS ${MYC_DEFS})
+ add_library(myfort_obj OBJECT mysub.f)
+ add_library(myc_use_obj myc.c $<TARGET_OBJECTS:myfort_obj>)
+ add_executable(mainc_use_obj mainc.c)
+ target_link_libraries(mainc_use_obj myc_use_obj)
+
add_library(mycxx mycxx.cxx)
target_link_libraries(mycxx myc)
@@ -123,7 +128,7 @@ else()
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
+ # as a language, cmake needs language specific versions
# of these variables....
if(WIN32 AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_CREATE_CONSOLE_EXE )
diff --git a/Tests/FortranModules/CMakeLists.txt b/Tests/FortranModules/CMakeLists.txt
index 399660002..d056b4379 100644
--- a/Tests/FortranModules/CMakeLists.txt
+++ b/Tests/FortranModules/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 3.1)
+cmake_minimum_required (VERSION 3.9)
project(FortranModules Fortran)
if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
@@ -56,7 +56,8 @@ add_executable(test_non_pp_include test_non_pp_include_main.f90)
# Build the external project separately using a custom target.
# Make sure it uses the same build configuration as this test.
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
set(External_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
set(External_BUILD_TYPE)
else()
diff --git a/Tests/FortranModules/Submodules/CMakeLists.txt b/Tests/FortranModules/Submodules/CMakeLists.txt
index bf0152f63..ab8e0f9e5 100644
--- a/Tests/FortranModules/Submodules/CMakeLists.txt
+++ b/Tests/FortranModules/Submodules/CMakeLists.txt
@@ -1 +1,23 @@
-add_executable(submod main.f90 provide.f90)
+# The program units in this file consist of a module/submodule
+# tree represented by the following graph:
+#
+# parent
+# |
+# / \
+# / \
+# child sibling
+# |
+# grandchild
+# |
+# GreatGrandChild
+#
+# where the parent node is a module and all other nodes are submodules.
+
+add_executable(submod
+ main.f90
+ parent.f90
+ child.f90
+ grandchild.f90
+ greatgrandchild.f90
+ sibling.f90
+ )
diff --git a/Tests/FortranModules/Submodules/main.f90 b/Tests/FortranModules/Submodules/main.f90
index 3c750ce38..3cd29892c 100644
--- a/Tests/FortranModules/Submodules/main.f90
+++ b/Tests/FortranModules/Submodules/main.f90
@@ -1,5 +1,7 @@
program main
use parent, only : child_function,grandchild_subroutine
+ use parent, only : sibling_function,GreatGrandChild_subroutine
implicit none
if (child_function()) call grandchild_subroutine
+ if (sibling_function()) call GreatGrandChild_subroutine
end program
diff --git a/Tests/FortranModules/test_preprocess.F90 b/Tests/FortranModules/test_preprocess.F90
index 3a09976c5..c5a5ec32d 100644
--- a/Tests/FortranModules/test_preprocess.F90
+++ b/Tests/FortranModules/test_preprocess.F90
@@ -1,5 +1,5 @@
MODULE Available
-! no conent
+! no content
END MODULE
PROGRAM PPTEST
diff --git a/Tests/FortranModules/test_preprocess_module.F90 b/Tests/FortranModules/test_preprocess_module.F90
index 5849b62b4..fdbc051e0 100644
--- a/Tests/FortranModules/test_preprocess_module.F90
+++ b/Tests/FortranModules/test_preprocess_module.F90
@@ -1,5 +1,5 @@
#ifdef FOO
MODULE PPAvailable
-! no conent
+! no content
END MODULE
#endif
diff --git a/Tests/FortranOnly/CMakeLists.txt b/Tests/FortranOnly/CMakeLists.txt
index 9bf03033a..45372ddb9 100644
--- a/Tests/FortranOnly/CMakeLists.txt
+++ b/Tests/FortranOnly/CMakeLists.txt
@@ -12,6 +12,12 @@ add_executable(FortranOnly1 testf.f)
set_property(TARGET FortranOnly1 PROPERTY OUTPUT_NAME FortranOnly)
target_link_libraries(FortranOnly1 FortranOnlylib)
+# Test that Fortran+RC work together.
+# FIXME: Add .rc in more cases.
+if(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(test_rc testRC.rc)
+endif()
+
# 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
@@ -20,7 +26,7 @@ add_custom_command(OUTPUT ${FortranOnly_BINARY_DIR}/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)
+add_executable(FortranOnly2 testfhello.txt testf.f ${test_rc})
target_link_libraries(FortranOnly2 FortranOnlylib)
# create a custom target to check the content of testfhello.txt
# by running the cmake script checktestf2.cmake
@@ -28,7 +34,7 @@ add_custom_target(checktestf2 ALL
COMMAND ${CMAKE_COMMAND}
-P ${FortranOnly_SOURCE_DIR}/checktestf2.cmake)
-# create a custom target that runs FortranOnly1 exectuable and creates
+# create a custom target that runs FortranOnly1 executable and creates
# a file out.txt that should have hello world in it.
add_custom_target(sayhello ALL
COMMAND FortranOnly1 > out.txt
@@ -38,7 +44,7 @@ add_dependencies(checktestf2 FortranOnly2)
add_dependencies(sayhello FortranOnly1)
add_dependencies(FortranOnly2 FortranOnly1)
-# add a custom target that checkes that out.txt has the correct
+# add a custom target that checks that out.txt has the correct
# content
add_custom_target(checksayhello ALL
COMMAND ${CMAKE_COMMAND} -P ${FortranOnly_SOURCE_DIR}/checksayhello.cmake
@@ -70,8 +76,15 @@ if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL XL)
include(CheckFortranCompilerFlag)
CHECK_Fortran_COMPILER_FLAG(-_this_is_not_a_flag_ Fortran_BOGUS_FLAG)
if (Fortran_BOGUS_FLAG)
- message (SEND_ERROR "CHECK_Fortran_COMPILER_FLAG() succeeded, but should have failed")
- endif ()
+ message(SEND_ERROR "CHECK_Fortran_COMPILER_FLAG() succeeded, but should have failed")
+ endif()
+
+ unset(Fortran_RUN_FLAG CACHE)
+ include(CheckFortranSourceRuns)
+ check_fortran_source_runs("program a; end program" Fortran_RUN_FLAG SRC_EXT F90)
+ if(NOT Fortran_RUN_FLAG)
+ message(SEND_ERROR "CHECK_Fortran_SOURCE_RUNS() failed")
+ endif()
endif()
# Test generation of preprocessed sources.
diff --git a/Tests/Framework/foo.cxx b/Tests/Framework/foo.cxx
index c3520c1dd..a4d15f609 100644
--- a/Tests/Framework/foo.cxx
+++ b/Tests/Framework/foo.cxx
@@ -1,8 +1,8 @@
#include <stdio.h>
#if defined(_WIN32) && defined(foo_EXPORTS)
-#define CM_TEST_LIB_EXPORT __declspec(dllexport)
+# define CM_TEST_LIB_EXPORT __declspec(dllexport)
#else
-#define CM_TEST_LIB_EXPORT
+# define CM_TEST_LIB_EXPORT
#endif
CM_TEST_LIB_EXPORT void foo()
{
diff --git a/Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp b/Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp
index 233eb57e4..2812b0d6f 100644
--- a/Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp
+++ b/Tests/GeneratorExpression/CMP0044/cmp0044-check.cpp
@@ -1,24 +1,24 @@
#ifdef Type_Is_
-#if !Result
-#error Result should be 1 in WARN mode
-#endif
+# 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
+# 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
+# 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
+# error No expected definition present
#endif
void foo(void)
diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt
index 8ac341912..3ff2b8595 100644
--- a/Tests/GeneratorExpression/CMakeLists.txt
+++ b/Tests/GeneratorExpression/CMakeLists.txt
@@ -3,11 +3,26 @@ project(GeneratorExpression)
include(CTest)
+# Real projects normally want the MSYS shell path conversion, but for this test
+# we need to verify that the command line is constructed with the proper string.
+set(msys1_prefix "")
+set(msys2_no_conv "")
+if(CMAKE_GENERATOR STREQUAL "MSYS Makefiles")
+ execute_process(COMMAND "uname" OUTPUT_VARIABLE uname)
+ if("${uname}" MATCHES "^MINGW32")
+ # MinGW.org MSYS 1.0 does not support generic path conversion suppression
+ set(msys1_prefix MSYS1_PREFIX)
+ else()
+ # msys2 supports generic path conversion suppression
+ set(msys2_no_conv env MSYS2_ARG_CONV_EXCL=-D)
+ endif()
+endif()
+
# This test is split into multiple parts as needed to avoid NMake command
# length limits.
add_custom_target(check-part1 ALL
- COMMAND ${CMAKE_COMMAND}
+ COMMAND ${msys2_no_conv} ${CMAKE_COMMAND}
-Dtest_0=$<0:nothing>
-Dtest_0_with_comma=$<0:-Wl,--no-undefined>
-Dtest_1=$<1:content>
@@ -57,6 +72,11 @@ add_custom_target(check-part1 ALL
-Dtest_strequal_angle_r_comma=$<STREQUAL:$<ANGLE-R>,$<COMMA>>
-Dtest_strequal_both_empty=$<STREQUAL:,>
-Dtest_strequal_one_empty=$<STREQUAL:something,>
+ -Dtest_inlist_true=$<IN_LIST:a,a$<SEMICOLON>b>
+ -Dtest_inlist_false=$<IN_LIST:c,a$<SEMICOLON>b>
+ -Dtest_inlist_empty_1=$<IN_LIST:a,>
+ -Dtest_inlist_empty_2=$<IN_LIST:,a>
+ -Dtest_inlist_empty_3=$<IN_LIST:,>
-Dtest_angle_r=$<ANGLE-R>
-Dtest_comma=$<COMMA>
-Dtest_semicolon=$<SEMICOLON>
@@ -92,7 +112,7 @@ add_library(empty5 empty.cpp)
target_include_directories(empty5 PRIVATE /empty5/private1 /empty5/private2)
add_custom_target(check-part2 ALL
- COMMAND ${CMAKE_COMMAND}
+ COMMAND ${msys2_no_conv} ${CMAKE_COMMAND}
-Dtest_incomplete_1=$<
-Dtest_incomplete_2=$<something
-Dtest_incomplete_3=$<something:
@@ -183,7 +203,7 @@ set_property(TARGET importedFallback PROPERTY MAP_IMPORTED_CONFIG_DEBUG "" DEBUG
set_property(TARGET importedFallback PROPERTY MAP_IMPORTED_CONFIG_RELEASE "")
add_custom_target(check-part3 ALL
- COMMAND ${CMAKE_COMMAND}
+ COMMAND ${msys2_no_conv} ${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>
@@ -200,6 +220,7 @@ add_custom_target(check-part3 ALL
-Dtest_early_termination_2=$<$<1:>:,
-Dsystem_name=${CMAKE_HOST_SYSTEM_NAME}
-Dtest_platform_id=$<PLATFORM_ID>
+ -Dtest_platform_id_supported=$<PLATFORM_ID:Linux,Windows,Darwin>
-Dtest_platform_id_Linux=$<PLATFORM_ID:Linux>
-Dtest_platform_id_Windows=$<PLATFORM_ID:Windows>
-Dtest_platform_id_Darwin=$<PLATFORM_ID:Darwin>
@@ -236,17 +257,19 @@ add_custom_target(check-part3 ALL
if(WIN32)
set(test_shell_path c:/shell/path)
+ set(test_shell_path2 c:/shell/path d:/another/path)
else()
set(test_shell_path /shell/path)
+ set(test_shell_path2 /shell/path /another/path)
endif()
-set(path_prefix BYPASS_FURTHER_CONVERSION)
add_custom_target(check-part4 ALL
- COMMAND ${CMAKE_COMMAND}
+ COMMAND ${msys2_no_conv} ${CMAKE_COMMAND}
# Prefix path to bypass its further conversion when being processed by
# CMake as command-line argument
- -Dtest_shell_path=${path_prefix}$<SHELL_PATH:${test_shell_path}>
- -Dpath_prefix=${path_prefix}
+ -Dmsys1_prefix=${msys1_prefix}
+ -Dtest_shell_path=${msys1_prefix}$<SHELL_PATH:${test_shell_path}>
+ "-Dtest_shell_path2=$<SHELL_PATH:${test_shell_path2}>"
-Dif_1=$<IF:1,a,b>
-Dif_2=$<IF:0,a,b>
-Dif_3=$<IF:$<EQUAL:10,30>,a,b>
@@ -259,10 +282,55 @@ add_custom_target(check-part4 ALL
)
#-----------------------------------------------------------------------------
+# Cover source file properties with generator expressions.
+## generate various source files
+foreach (item IN ITEMS flags flags_COMPILE_LANGUAGE
+ options options_COMPILE_LANGUAGE
+ defs defs_COMPILE_LANGUAGE)
+ set(TARGET_NAME srcgenex_${item})
+ configure_file(srcgenex.c.in ${TARGET_NAME}.c @ONLY)
+endforeach()
+add_executable(srcgenex_flags "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_flags.c")
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_flags.c"
+ PROPERTY COMPILE_FLAGS "-DNAME=$<TARGET_PROPERTY:NAME>")
+add_executable(srcgenex_flags_COMPILE_LANGUAGE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_flags_COMPILE_LANGUAGE.c")
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_flags_COMPILE_LANGUAGE.c"
+ PROPERTY COMPILE_FLAGS "$<$<COMPILE_LANGUAGE:C>:-DNAME=$<TARGET_PROPERTY:NAME>>")
+
+add_executable(srcgenex_options "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_options.c")
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_options.c"
+ PROPERTY COMPILE_OPTIONS -DUNUSED -DNAME=$<TARGET_PROPERTY:NAME>)
+add_executable(srcgenex_options_COMPILE_LANGUAGE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_options_COMPILE_LANGUAGE.c")
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_options_COMPILE_LANGUAGE.c"
+ PROPERTY COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:C>:-DNAME=$<TARGET_PROPERTY:NAME>>)
+
+add_executable(srcgenex_defs "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_defs.c")
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_defs.c"
+ PROPERTY COMPILE_DEFINITIONS UNUSED NAME=$<TARGET_PROPERTY:NAME>)
+add_executable(srcgenex_defs_COMPILE_LANGUAGE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_defs_COMPILE_LANGUAGE.c")
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_defs_COMPILE_LANGUAGE.c"
+ PROPERTY COMPILE_DEFINITIONS $<$<COMPILE_LANGUAGE:C>:NAME=$<TARGET_PROPERTY:NAME>>)
+
+foreach (item IN ITEMS basic COMPILE_LANGUAGE)
+ set(TARGET_NAME srcgenex_includes_${item})
+ configure_file(srcgenex_includes.h.in "sf_includes_${item}/${TARGET_NAME}.h" @ONLY)
+ configure_file(srcgenex_includes.c.in ${TARGET_NAME}.c @ONLY)
+endforeach()
+add_executable(srcgenex_includes_basic "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_includes_basic.c")
+# first include directory is useless but ensure list aspect is tested
+set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_includes_basic.c"
+ PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/sf_includes_basic")
+if (CMAKE_GENERATOR MATCHES "Makefiles|Ninja|Watcom WMake")
+ add_executable(srcgenex_includes_COMPILE_LANGUAGE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_includes_COMPILE_LANGUAGE.c")
+ # first include directory is useless but ensure list aspect is tested
+ set_property(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/srcgenex_includes_COMPILE_LANGUAGE.c"
+ PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}" $<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_BINARY_DIR}/sf_includes_COMPILE_LANGUAGE>)
+endif()
+
+#-----------------------------------------------------------------------------
# Cover test properties with generator expressions.
add_executable(echo echo.c)
add_executable(pwd pwd.c)
-set_property(SOURCE echo.c PROPERTY COMPILE_FLAGS $<1:-DSRC_GENEX_WORKS>)
add_test(NAME echo-configuration COMMAND echo $<CONFIGURATION>)
set_property(TEST echo-configuration PROPERTY
@@ -307,4 +375,49 @@ if(NOT CMAKE_GENERATOR STREQUAL Xcode OR NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;
-P "${CMAKE_CURRENT_SOURCE_DIR}/check_object_files.cmake"
DEPENDS objlib
)
+
+
+ add_library(sharedlib SHARED objlib1.c objlib2.c)
+ file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/sharedlib_files_$<CONFIGURATION>"
+ CONTENT "$<JOIN:$<TARGET_OBJECTS:sharedlib>,\n>\n"
+ )
+
+ add_custom_target(check_sharedlib_objs ALL
+ COMMAND ${CMAKE_COMMAND}
+ "-DOBJLIB_LISTFILE=${CMAKE_CURRENT_BINARY_DIR}/sharedlib_files_$<CONFIGURATION>"
+ -DEXPECTED_NUM_OBJECTFILES=2
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/check_object_files.cmake"
+ DEPENDS sharedlib
+ )
+
+
+ add_library(staticlib STATIC objlib1.c objlib2.c)
+ file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/staticlib_files_$<CONFIGURATION>"
+ CONTENT "$<JOIN:$<TARGET_OBJECTS:staticlib>,\n>\n"
+ )
+
+ add_custom_target(check_staticlib_objs ALL
+ COMMAND ${CMAKE_COMMAND}
+ "-DOBJLIB_LISTFILE=${CMAKE_CURRENT_BINARY_DIR}/staticlib_files_$<CONFIGURATION>"
+ -DEXPECTED_NUM_OBJECTFILES=2
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/check_object_files.cmake"
+ DEPENDS staticlib
+ )
+
+
+ add_executable(execobjs objlib1.c objlib2.c echo.c)
+ file(GENERATE
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/execobjs_files_$<CONFIGURATION>"
+ CONTENT "$<JOIN:$<TARGET_OBJECTS:execobjs>,\n>\n"
+ )
+
+ add_custom_target(check_exec_objs ALL
+ COMMAND ${CMAKE_COMMAND}
+ "-DOBJLIB_LISTFILE=${CMAKE_CURRENT_BINARY_DIR}/execobjs_files_$<CONFIGURATION>"
+ -DEXPECTED_NUM_OBJECTFILES=3
+ -P "${CMAKE_CURRENT_SOURCE_DIR}/check_object_files.cmake"
+ DEPENDS execobjs
+ )
endif()
diff --git a/Tests/GeneratorExpression/check-part1.cmake b/Tests/GeneratorExpression/check-part1.cmake
index 60b193f58..41bcd6d99 100644
--- a/Tests/GeneratorExpression/check-part1.cmake
+++ b/Tests/GeneratorExpression/check-part1.cmake
@@ -49,6 +49,11 @@ 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_inlist_true "1")
+check(test_inlist_false "0")
+check(test_inlist_empty_1 "0")
+check(test_inlist_empty_2 "0")
+check(test_inlist_empty_3 "0")
check(test_angle_r ">")
check(test_comma ",")
check(test_semicolon ";")
diff --git a/Tests/GeneratorExpression/check-part3.cmake b/Tests/GeneratorExpression/check-part3.cmake
index 9014406c2..4fb730887 100644
--- a/Tests/GeneratorExpression/check-part3.cmake
+++ b/Tests/GeneratorExpression/check-part3.cmake
@@ -28,11 +28,16 @@ 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_supported 1)
check(test_platform_id_${system} 1)
+ set(platform_supported 1)
else()
check(test_platform_id_${system} 0)
endif()
endforeach()
+if(NOT platform_supported)
+ check(test_platform_id_supported 0)
+endif()
check(lower_case "mi,xed")
check(upper_case "MIX,ED")
check(make_c_identifier "_4f_oo__bar__")
diff --git a/Tests/GeneratorExpression/check-part4.cmake b/Tests/GeneratorExpression/check-part4.cmake
index f5d14dd45..a7e09445e 100644
--- a/Tests/GeneratorExpression/check-part4.cmake
+++ b/Tests/GeneratorExpression/check-part4.cmake
@@ -1,6 +1,8 @@
include(${CMAKE_CURRENT_LIST_DIR}/check-common.cmake)
-string(REPLACE ${path_prefix} "" test_shell_path ${test_shell_path})
+if(msys1_prefix)
+ string(REPLACE "${msys1_prefix}" "" test_shell_path ${test_shell_path})
+endif()
if(WIN32)
if(CMAKE_GENERATOR STREQUAL "MSYS Makefiles")
@@ -13,6 +15,17 @@ if(WIN32)
else()
check(test_shell_path [[/shell/path]])
endif()
+if(WIN32)
+ if(CMAKE_GENERATOR STREQUAL "MSYS Makefiles" AND NOT msys1_prefix)
+ check(test_shell_path2 [[/c/shell/path:/d/another/path]])
+ elseif(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
+ check(test_shell_path2 [[c:/shell/path;d:/another/path]])
+ else()
+ check(test_shell_path2 [[c:\shell\path;d:\another\path]])
+ endif()
+else()
+ check(test_shell_path2 [[/shell/path:/another/path]])
+endif()
check(if_1 "a")
check(if_2 "b")
diff --git a/Tests/GeneratorExpression/echo.c b/Tests/GeneratorExpression/echo.c
index 41596a21d..06b0844b3 100644
--- a/Tests/GeneratorExpression/echo.c
+++ b/Tests/GeneratorExpression/echo.c
@@ -3,9 +3,6 @@
int main(int argc, char* argv[])
{
-#ifndef SRC_GENEX_WORKS
-#error SRC_GENEX_WORKS not defined
-#endif
printf("%s\n", argv[1]);
return EXIT_SUCCESS;
}
diff --git a/Tests/GeneratorExpression/pwd.c b/Tests/GeneratorExpression/pwd.c
index ed2304370..31ebe493a 100644
--- a/Tests/GeneratorExpression/pwd.c
+++ b/Tests/GeneratorExpression/pwd.c
@@ -3,11 +3,11 @@
#include <stdlib.h>
#ifdef _WIN32
-#include <direct.h>
-#define getcurdir _getcwd
+# include <direct.h>
+# define getcurdir _getcwd
#else
-#include <unistd.h>
-#define getcurdir getcwd
+# include <unistd.h>
+# define getcurdir getcwd
#endif
int main(int argc, char* argv[])
diff --git a/Tests/GoogleTest/Test/CMakeLists.txt b/Tests/GoogleTest/Test/CMakeLists.txt
index f798d313c..baf00d53f 100644
--- a/Tests/GoogleTest/Test/CMakeLists.txt
+++ b/Tests/GoogleTest/Test/CMakeLists.txt
@@ -44,12 +44,13 @@ endif()
set_tests_properties(set2.GoogleTest.ConditionalFail.foo PROPERTIES WILL_FAIL YES)
-# Search specific sources to get the test list
-add_executable(test_gtest2 main2.cxx)
+# Search specific sources to get the test list. Include an empty file
+# to ensure they are handled correctly too.
+add_executable(test_gtest2 main2.cxx empty.cxx)
target_link_libraries(test_gtest2 GTest::Main)
gtest_add_tests(TARGET test_gtest2
TEST_LIST testList
- SOURCES main2.h
+ SOURCES main2.h empty.cxx
)
set(expectedTests
GoogleTest.SomethingElse
diff --git a/Tests/IncludeDirectories/CMP0021/main.cpp b/Tests/IncludeDirectories/CMP0021/main.cpp
index f638ed14a..0f87dd997 100644
--- a/Tests/IncludeDirectories/CMP0021/main.cpp
+++ b/Tests/IncludeDirectories/CMP0021/main.cpp
@@ -2,7 +2,7 @@
#include "cmp0021.h"
#ifndef CMP0021_DEFINE
-#error Expected CMP0021_DEFINE
+# error Expected CMP0021_DEFINE
#endif
int main(int, char**)
diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt
index db18462a8..761c405b1 100644
--- a/Tests/IncludeDirectories/CMakeLists.txt
+++ b/Tests/IncludeDirectories/CMakeLists.txt
@@ -2,7 +2,7 @@ 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)
+ OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC") OR CMAKE_C_COMPILER_ID STREQUAL AppleClang)
AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles"
OR CMAKE_GENERATOR STREQUAL "Ninja"
OR (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT XCODE_VERSION VERSION_LESS 6.0)))
@@ -65,6 +65,10 @@ else()
PROPERTIES COMPILE_FLAGS "-ITarProp")
endif()
+add_library(ordertest ordertest.cpp)
+target_include_directories(ordertest SYSTEM PUBLIC SystemIncludeDirectories/systemlib)
+target_include_directories(ordertest PUBLIC SystemIncludeDirectories/userlib)
+
add_subdirectory(StandardIncludeDirectories)
add_subdirectory(TargetIncludeDirectories)
diff --git a/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt
index 5078f3099..20bd60196 100644
--- a/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt
+++ b/Tests/IncludeDirectories/SystemIncludeDirectories/CMakeLists.txt
@@ -32,7 +32,9 @@ target_link_libraries(consumer upstream config_specific)
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")
+set_property(TARGET iface PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/systemlib_header_only>"
+ )
add_library(imported_consumer imported_consumer.cpp)
target_link_libraries(imported_consumer iface)
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt
index 5b99ea7b3..a9edf9a97 100644
--- a/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt
@@ -17,7 +17,8 @@ create_header(bing)
create_header(bung)
create_header(arguments)
create_header(list)
-create_header(target)
+create_header(target1)
+create_header(target2)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@@ -69,14 +70,23 @@ set_property(TARGET lib4 APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BI
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 somelib::withcolons PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/target1")
+set_property(TARGET somelib::withcolons PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/target1")
set_property(TARGET TargetIncludeDirectories
APPEND PROPERTY INCLUDE_DIRECTORIES
"$<TARGET_PROPERTY:somelib::withcolons,INTERFACE_INCLUDE_DIRECTORIES>"
)
+add_library(somelib_aliased UNKNOWN IMPORTED GLOBAL)
+set_property(TARGET somelib_aliased PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/target2")
+add_library(somelib::withcolons2 ALIAS somelib_aliased)
+
+set_property(TARGET TargetIncludeDirectories
+ APPEND PROPERTY INCLUDE_DIRECTORIES
+ "$<TARGET_PROPERTY:somelib::withcolons2,INTERFACE_INCLUDE_DIRECTORIES>"
+)
+
add_custom_target(test_custom_target
"some_bogus_custom_tool"
$<TARGET_PROPERTY:TargetIncludeDirectories,COMPILE_DEFINITIONS>
diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp
index 2ee05e2ee..541ef92c2 100644
--- a/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp
+++ b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp
@@ -10,7 +10,8 @@
#include "foo.h"
#include "list.h"
#include "prefix_foo_bar_bat.h"
-#include "target.h"
+#include "target1.h"
+#include "target2.h"
#include "ting.h"
int main(int, char**)
diff --git a/Tests/InterfaceLibrary/CMakeLists.txt b/Tests/InterfaceLibrary/CMakeLists.txt
index 33c4b9073..954c02d51 100644
--- a/Tests/InterfaceLibrary/CMakeLists.txt
+++ b/Tests/InterfaceLibrary/CMakeLists.txt
@@ -31,6 +31,7 @@ add_library(item_real STATIC item.cpp)
add_library(item_iface INTERFACE IMPORTED)
set_property(TARGET item_iface PROPERTY IMPORTED_LIBNAME item_real)
add_dependencies(item_iface item_real)
+get_property(item_iface_dependencies TARGET item_iface PROPERTY MANUALLY_ADDED_DEPENDENCIES)
link_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(InterfaceLibrary definetestexe.cpp)
@@ -46,6 +47,7 @@ target_link_libraries(InterfaceLibrary
add_dependencies(InterfaceLibrary item_fake_tgt)
add_subdirectory(libsdir)
+add_subdirectory(excluded EXCLUDE_FROM_ALL)
add_executable(sharedlibtestexe sharedlibtestexe.cpp)
target_link_libraries(sharedlibtestexe shared_iface imported::iface)
@@ -64,7 +66,6 @@ target_link_libraries(iface_whitelist INTERFACE $<$<BOOL:$<TARGET_PROPERTY:CUSTO
add_executable(exec_whitelist dummy.cpp)
target_link_libraries(exec_whitelist iface_whitelist)
-set(CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
add_library(iface_imported INTERFACE IMPORTED)
set_property(TARGET iface_imported PROPERTY
INTERFACE_COMPILE_DEFINITIONS
diff --git a/Tests/InterfaceLibrary/definetestexe.cpp b/Tests/InterfaceLibrary/definetestexe.cpp
index 098502c4c..9156426cd 100644
--- a/Tests/InterfaceLibrary/definetestexe.cpp
+++ b/Tests/InterfaceLibrary/definetestexe.cpp
@@ -1,18 +1,18 @@
#ifndef IFACE_DEFINE
-#error Expected IFACE_DEFINE
+# error Expected IFACE_DEFINE
#endif
#include "iface_header.h"
#ifndef IFACE_HEADER_SRCDIR
-#error Expected IFACE_HEADER_SRCDIR
+# error Expected IFACE_HEADER_SRCDIR
#endif
#include "iface_header_builddir.h"
#ifndef IFACE_HEADER_BUILDDIR
-#error Expected IFACE_HEADER_BUILDDIR
+# error Expected IFACE_HEADER_BUILDDIR
#endif
extern int obj();
diff --git a/Tests/InterfaceLibrary/map_config.cpp b/Tests/InterfaceLibrary/map_config.cpp
index 232a18e88..d0356327d 100644
--- a/Tests/InterfaceLibrary/map_config.cpp
+++ b/Tests/InterfaceLibrary/map_config.cpp
@@ -1,12 +1,12 @@
#ifdef DEBUG_MODE
-#ifndef SPECIAL_MODE
-#error Special configuration should be mapped to debug configuration.
-#endif
+# 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
+# ifdef SPECIAL_MODE
+# error Special configuration should not be enabled if not debug configuration
+# endif
#endif
int main(int, char**)
diff --git a/Tests/InterfaceLibrary/sharedlibtestexe.cpp b/Tests/InterfaceLibrary/sharedlibtestexe.cpp
index 44f160da8..97b5aa900 100644
--- a/Tests/InterfaceLibrary/sharedlibtestexe.cpp
+++ b/Tests/InterfaceLibrary/sharedlibtestexe.cpp
@@ -1,14 +1,14 @@
#ifndef SHAREDLIB_DEFINE
-#error Expected SHAREDLIB_DEFINE
+# error Expected SHAREDLIB_DEFINE
#endif
#ifndef SHAREDDEPENDLIB_DEFINE
-#error Expected SHAREDDEPENDLIB_DEFINE
+# error Expected SHAREDDEPENDLIB_DEFINE
#endif
-#include "sharedlib.h"
#include "shareddependlib.h"
+#include "sharedlib.h"
int main(int, char**)
{
diff --git a/Tests/InterfaceLinkLibraries/bang.cpp b/Tests/InterfaceLinkLibraries/bang.cpp
index 2e950986b..722af9f18 100644
--- a/Tests/InterfaceLinkLibraries/bang.cpp
+++ b/Tests/InterfaceLinkLibraries/bang.cpp
@@ -1,10 +1,10 @@
#ifdef FOO_LIBRARY
-#error Unexpected FOO_LIBRARY
+# error Unexpected FOO_LIBRARY
#endif
#ifdef BAR_LIBRARY
-#error Unexpected BAR_LIBRARY
+# error Unexpected BAR_LIBRARY
#endif
#include "bang.h"
diff --git a/Tests/InterfaceLinkLibraries/bar.cpp b/Tests/InterfaceLinkLibraries/bar.cpp
index 228ed803a..c1d95ab6e 100644
--- a/Tests/InterfaceLinkLibraries/bar.cpp
+++ b/Tests/InterfaceLinkLibraries/bar.cpp
@@ -1,17 +1,17 @@
#ifdef FOO_LIBRARY
-#error Unexpected FOO_LIBRARY
+# error Unexpected FOO_LIBRARY
#endif
#ifdef BAR_USE_BANG
-#ifndef BANG_LIBRARY
-#error Expected BANG_LIBRARY
-#endif
-#include "bang.h"
+# ifndef BANG_LIBRARY
+# error Expected BANG_LIBRARY
+# endif
+# include "bang.h"
#else
-#ifdef BANG_LIBRARY
-#error Unexpected BANG_LIBRARY
-#endif
+# ifdef BANG_LIBRARY
+# error Unexpected BANG_LIBRARY
+# endif
#endif
#include "bar.h"
diff --git a/Tests/InterfaceLinkLibraries/foo.cpp b/Tests/InterfaceLinkLibraries/foo.cpp
index 5295707b5..c1e93e849 100644
--- a/Tests/InterfaceLinkLibraries/foo.cpp
+++ b/Tests/InterfaceLinkLibraries/foo.cpp
@@ -1,10 +1,10 @@
#ifdef BAR_LIBRARY
-#error Unexpected BAR_LIBRARY
+# error Unexpected BAR_LIBRARY
#endif
#ifdef BANG_LIBRARY
-#error Unexpected BANG_LIBRARY
+# error Unexpected BANG_LIBRARY
#endif
#include "foo.h"
diff --git a/Tests/InterfaceLinkLibraries/main.cpp b/Tests/InterfaceLinkLibraries/main.cpp
index 6e1295a10..e8298d41c 100644
--- a/Tests/InterfaceLinkLibraries/main.cpp
+++ b/Tests/InterfaceLinkLibraries/main.cpp
@@ -1,18 +1,18 @@
#ifndef FOO_LIBRARY
-#error Expected FOO_LIBRARY
+# error Expected FOO_LIBRARY
#endif
#ifndef BAR_LIBRARY
-#error Expected BAR_LIBRARY
+# error Expected BAR_LIBRARY
#endif
#ifdef BANG_LIBRARY
-#error Unexpected BANG_LIBRARY
+# error Unexpected BANG_LIBRARY
#endif
#ifdef ZOT_LIBRARY
-#error Unexpected ZOT_LIBRARY
+# error Unexpected ZOT_LIBRARY
#endif
#include "zot.h"
diff --git a/Tests/Java/CMakeLists.txt b/Tests/Java/CMakeLists.txt
index e1bcf3c20..0b8269bb7 100644
--- a/Tests/Java/CMakeLists.txt
+++ b/Tests/Java/CMakeLists.txt
@@ -11,3 +11,6 @@ add_jar(hello A.java HelloWorld.java)
# use listing file to specify sources
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/java_fileslist "A.java\nHelloWorld.java\n")
add_jar(hello2 @${CMAKE_CURRENT_BINARY_DIR}/java_fileslist)
+
+# use listing file to specify sources and specify output directory (issue #17316)
+add_jar(hello3 @${CMAKE_CURRENT_BINARY_DIR}/java_fileslist OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/hello3")
diff --git a/Tests/JavaExportImport/CMakeLists.txt b/Tests/JavaExportImport/CMakeLists.txt
index a075301f9..c70704a04 100644
--- a/Tests/JavaExportImport/CMakeLists.txt
+++ b/Tests/JavaExportImport/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 3.5)
+cmake_minimum_required (VERSION 3.9)
project(JavaExportImport)
if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
set(CMake_TEST_NESTED_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM}")
@@ -17,7 +17,8 @@ set_property(
PROPERTY SYMBOLIC 1
)
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
else()
if(CMAKE_BUILD_TYPE)
diff --git a/Tests/Jump/Executable/jumpExecutable.cxx b/Tests/Jump/Executable/jumpExecutable.cxx
index 6fa268377..2c5961c5d 100644
--- a/Tests/Jump/Executable/jumpExecutable.cxx
+++ b/Tests/Jump/Executable/jumpExecutable.cxx
@@ -1,7 +1,7 @@
#ifdef _WIN32
-#define JUMP_IMPORT __declspec(dllimport)
+# define JUMP_IMPORT __declspec(dllimport)
#else
-#define JUMP_IMPORT extern
+# define JUMP_IMPORT extern
#endif
extern int jumpStatic();
diff --git a/Tests/Jump/Library/Shared/jumpShared.cxx b/Tests/Jump/Library/Shared/jumpShared.cxx
index 7c4dee9a8..87484b795 100644
--- a/Tests/Jump/Library/Shared/jumpShared.cxx
+++ b/Tests/Jump/Library/Shared/jumpShared.cxx
@@ -1,7 +1,7 @@
#ifdef _WIN32
-#define JUMP_EXPORT __declspec(dllexport)
+# define JUMP_EXPORT __declspec(dllexport)
#else
-#define JUMP_EXPORT
+# define JUMP_EXPORT
#endif
JUMP_EXPORT int jumpShared()
diff --git a/Tests/LinkDirectory/External/CMakeLists.txt b/Tests/LinkDirectory/External/CMakeLists.txt
index f7c840f9a..d2a1f9f77 100644
--- a/Tests/LinkDirectory/External/CMakeLists.txt
+++ b/Tests/LinkDirectory/External/CMakeLists.txt
@@ -1,6 +1,20 @@
cmake_minimum_required(VERSION 2.8)
project(LinkDirectoryExternal C)
+
+add_executable(myexe2 myexe.c)
+set_property(TARGET myexe2 PROPERTY OUTPUT_NAME LinkDirectory2)
+target_link_directories(myexe2 PRIVATE lib "${CMAKE_CURRENT_SOURCE_DIR}/../lib")
+target_link_libraries(myexe2 PRIVATE mylibA mylibB)
+
+add_library (mylibs INTERFACE)
+target_link_directories(mylibs INTERFACE lib "${CMAKE_CURRENT_SOURCE_DIR}/../lib")
+target_link_libraries(mylibs INTERFACE mylibA mylibB)
+add_executable(myexe3 myexe.c)
+set_property(TARGET myexe3 PROPERTY OUTPUT_NAME LinkDirectory3)
+target_link_libraries(myexe3 PRIVATE mylibs)
+
+
# Test CMP0015 OLD behavior: -L../lib
cmake_policy(SET CMP0015 OLD)
link_directories(../lib)
diff --git a/Tests/LinkFlags/LinkFlagsExe.c b/Tests/LinkFlags/LinkFlagsExe.c
index 4d441469f..202d34d26 100644
--- a/Tests/LinkFlags/LinkFlagsExe.c
+++ b/Tests/LinkFlags/LinkFlagsExe.c
@@ -5,5 +5,5 @@ int main(void)
/* Intel compiler does not reject bad flags or objects! */
#if defined(__INTEL_COMPILER)
-#error BADFLAG
+# error BADFLAG
#endif
diff --git a/Tests/LinkFlags/LinkFlagsLib.c b/Tests/LinkFlags/LinkFlagsLib.c
index f35420666..bd288e908 100644
--- a/Tests/LinkFlags/LinkFlagsLib.c
+++ b/Tests/LinkFlags/LinkFlagsLib.c
@@ -5,5 +5,5 @@ int flags_lib(void)
/* Intel compiler does not reject bad flags or objects! */
#if defined(__INTEL_COMPILER)
-#error BADFLAG
+# error BADFLAG
#endif
diff --git a/Tests/LoadCommand/CMakeLists.txt b/Tests/LoadCommand/CMakeLists.txt
index 03a3b4942..cfaebade4 100644
--- a/Tests/LoadCommand/CMakeLists.txt
+++ b/Tests/LoadCommand/CMakeLists.txt
@@ -22,13 +22,6 @@ else()
${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}")
diff --git a/Tests/LoadCommandOneConfig/CMakeLists.txt b/Tests/LoadCommandOneConfig/CMakeLists.txt
index 6affd343f..65de04230 100644
--- a/Tests/LoadCommandOneConfig/CMakeLists.txt
+++ b/Tests/LoadCommandOneConfig/CMakeLists.txt
@@ -28,13 +28,6 @@ else()
${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}")
diff --git a/Tests/MFC/CMakeLists.txt.in b/Tests/MFC/CMakeLists.txt.in
index e6bfabd33..bf98e918c 100644
--- a/Tests/MFC/CMakeLists.txt.in
+++ b/Tests/MFC/CMakeLists.txt.in
@@ -45,6 +45,11 @@ set(files
set(CMAKE_MFC_FLAG "@CMAKE_MFC_FLAG_VALUE@")
+FIND_PACKAGE(MFC)
+IF (NOT MFC_FOUND)
+ MESSAGE(FATAL_ERROR "MFC Could not be found during the MFC test")
+ENDIF()
+
if("${CMAKE_MFC_FLAG}" STREQUAL "1")
msvc_link_to_static_crt()
else()
diff --git a/Tests/MFC/mfc1/ChildFrm.cpp b/Tests/MFC/mfc1/ChildFrm.cpp
index ddb19c620..a415229d7 100644
--- a/Tests/MFC/mfc1/ChildFrm.cpp
+++ b/Tests/MFC/mfc1/ChildFrm.cpp
@@ -8,7 +8,7 @@
#include "ChildFrm.h"
#ifdef _DEBUG
-#define new DEBUG_NEW
+# define new DEBUG_NEW
#endif
// CChildFrame
diff --git a/Tests/MFC/mfc1/MainFrm.cpp b/Tests/MFC/mfc1/MainFrm.cpp
index c5510657b..6bd2b3d9a 100644
--- a/Tests/MFC/mfc1/MainFrm.cpp
+++ b/Tests/MFC/mfc1/MainFrm.cpp
@@ -8,7 +8,7 @@
#include "MainFrm.h"
#ifdef _DEBUG
-#define new DEBUG_NEW
+# define new DEBUG_NEW
#endif
// CMainFrame
@@ -21,7 +21,9 @@ END_MESSAGE_MAP()
static UINT indicators[] = {
ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,
+ ID_INDICATOR_CAPS,
+ ID_INDICATOR_NUM,
+ ID_INDICATOR_SCRL,
};
// CMainFrame construction/destruction
@@ -40,9 +42,10 @@ 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) ||
+ 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
diff --git a/Tests/MFC/mfc1/Resource.h b/Tests/MFC/mfc1/Resource.h
index 7184e3064..e3a04f11e 100644
--- a/Tests/MFC/mfc1/Resource.h
+++ b/Tests/MFC/mfc1/Resource.h
@@ -11,10 +11,10 @@
// 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
+# 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
index 664c6c4ec..892a89d27 100644
--- a/Tests/MFC/mfc1/mfc1.cpp
+++ b/Tests/MFC/mfc1/mfc1.cpp
@@ -11,7 +11,7 @@
#include "mfc1View.h"
#ifdef _DEBUG
-#define new DEBUG_NEW
+# define new DEBUG_NEW
#endif
// Cmfc1App
diff --git a/Tests/MFC/mfc1/mfc1.h b/Tests/MFC/mfc1/mfc1.h
index 15e970ba0..f4fcadb45 100644
--- a/Tests/MFC/mfc1/mfc1.h
+++ b/Tests/MFC/mfc1/mfc1.h
@@ -3,7 +3,7 @@
#pragma once
#ifndef __AFXWIN_H__
-#error include 'stdafx.h' before including this file for PCH
+# error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
diff --git a/Tests/MFC/mfc1/mfc1Doc.cpp b/Tests/MFC/mfc1/mfc1Doc.cpp
index 08ab1580a..e69b61c71 100644
--- a/Tests/MFC/mfc1/mfc1Doc.cpp
+++ b/Tests/MFC/mfc1/mfc1Doc.cpp
@@ -8,7 +8,7 @@
#include "mfc1Doc.h"
#ifdef _DEBUG
-#define new DEBUG_NEW
+# define new DEBUG_NEW
#endif
// Cmfc1Doc
diff --git a/Tests/MFC/mfc1/mfc1View.cpp b/Tests/MFC/mfc1/mfc1View.cpp
index 6169ce524..3de55cf6e 100644
--- a/Tests/MFC/mfc1/mfc1View.cpp
+++ b/Tests/MFC/mfc1/mfc1View.cpp
@@ -9,7 +9,7 @@
#include "mfc1View.h"
#ifdef _DEBUG
-#define new DEBUG_NEW
+# define new DEBUG_NEW
#endif
// Cmfc1View
diff --git a/Tests/MFC/mfc1/stdafx.h b/Tests/MFC/mfc1/stdafx.h
index 56f8a6ab4..2680f2632 100644
--- a/Tests/MFC/mfc1/stdafx.h
+++ b/Tests/MFC/mfc1/stdafx.h
@@ -5,7 +5,7 @@
#pragma once
#ifndef VC_EXTRALEAN
-#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
+# define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
// See http://msdn.microsoft.com/en-us/library/6sehtctf.aspx for more info
@@ -17,39 +17,41 @@
// 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
+# 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
+# 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
+# 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
+# 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
@@ -65,5 +67,5 @@
#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
+# include <afxcmn.h> // MFC support for Windows Common Controls
+#endif // _AFX_NO_AFXCMN_SUPPORT
diff --git a/Tests/MacRuntimePath/A/framework.h b/Tests/MacRuntimePath/A/framework.h
index 343317c59..5a3cfc457 100644
--- a/Tests/MacRuntimePath/A/framework.h
+++ b/Tests/MacRuntimePath/A/framework.h
@@ -3,13 +3,13 @@
#define framework_h
#ifdef WIN32
-#ifdef framework_EXPORTS
-#define FRAMEWORK_EXPORT __declspec(dllexport)
+# ifdef framework_EXPORTS
+# define FRAMEWORK_EXPORT __declspec(dllexport)
+# else
+# define FRAMEWORK_EXPORT __declspec(dllimport)
+# endif
#else
-#define FRAMEWORK_EXPORT __declspec(dllimport)
-#endif
-#else
-#define FRAMEWORK_EXPORT
+# define FRAMEWORK_EXPORT
#endif
void FRAMEWORK_EXPORT framework();
diff --git a/Tests/MacRuntimePath/A/framework2.h b/Tests/MacRuntimePath/A/framework2.h
index 7f45f4d2f..2562396f9 100644
--- a/Tests/MacRuntimePath/A/framework2.h
+++ b/Tests/MacRuntimePath/A/framework2.h
@@ -3,13 +3,13 @@
#define framework2_h
#ifdef WIN32
-#ifdef framework2_EXPORTS
-#define FRAMEWORK2_EXPORT __declspec(dllexport)
+# ifdef framework2_EXPORTS
+# define FRAMEWORK2_EXPORT __declspec(dllexport)
+# else
+# define FRAMEWORK2_EXPORT __declspec(dllimport)
+# endif
#else
-#define FRAMEWORK2_EXPORT __declspec(dllimport)
-#endif
-#else
-#define FRAMEWORK2_EXPORT
+# define FRAMEWORK2_EXPORT
#endif
void FRAMEWORK2_EXPORT framework2();
diff --git a/Tests/MacRuntimePath/A/shared.h b/Tests/MacRuntimePath/A/shared.h
index 28904fd78..5d5b6335c 100644
--- a/Tests/MacRuntimePath/A/shared.h
+++ b/Tests/MacRuntimePath/A/shared.h
@@ -3,13 +3,13 @@
#define shared_h
#ifdef WIN32
-#ifdef shared_EXPORTS
-#define SHARED_EXPORT __declspec(dllexport)
+# ifdef shared_EXPORTS
+# define SHARED_EXPORT __declspec(dllexport)
+# else
+# define SHARED_EXPORT __declspec(dllimport)
+# endif
#else
-#define SHARED_EXPORT __declspec(dllimport)
-#endif
-#else
-#define SHARED_EXPORT
+# define SHARED_EXPORT
#endif
void SHARED_EXPORT shared();
diff --git a/Tests/MacRuntimePath/CMakeLists.txt b/Tests/MacRuntimePath/CMakeLists.txt
index 3e9ab8a55..a3c6fd9a9 100644
--- a/Tests/MacRuntimePath/CMakeLists.txt
+++ b/Tests/MacRuntimePath/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 2.8)
+cmake_minimum_required (VERSION 3.9)
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}")
@@ -18,7 +18,8 @@ set_property(
configure_file(${MacRuntimePath_SOURCE_DIR}/InitialCache.cmake.in
${MacRuntimePath_BINARY_DIR}/InitialCache.cmake @ONLY)
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
else()
if(CMAKE_BUILD_TYPE)
diff --git a/Tests/MakeClean/ToClean/CMakeLists.txt b/Tests/MakeClean/ToClean/CMakeLists.txt
index d0e24cefe..a05c38b22 100644
--- a/Tests/MakeClean/ToClean/CMakeLists.txt
+++ b/Tests/MakeClean/ToClean/CMakeLists.txt
@@ -1,42 +1,122 @@
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 3.14)
project(ToClean)
-# Build a simple project.
-add_executable(toclean toclean.cxx)
+# Utility variables
+set(CSD ${CMAKE_CURRENT_SOURCE_DIR})
+set(CBD ${CMAKE_CURRENT_BINARY_DIR})
+set(CLEAN_FILE_CONTENT "File registered for cleaning.\n")
+
+# Lists build-time-generated files that should be cleaned away
+set_property(GLOBAL PROPERTY TOCLEAN_FILES "")
+function(addCleanFile FILENAME)
+ set_property(GLOBAL APPEND PROPERTY TOCLEAN_FILES "${FILENAME}")
+endfunction()
+function(writeCleanFile FILENAME)
+ file(WRITE "${FILENAME}" ${CLEAN_FILE_CONTENT})
+endfunction()
-# 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}")
+set(DUMMY_CONTENT_FILE ${CSD}/toclean.cxx)
-# 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")
+# Build a simple project whose compiled objects should be cleaned.
+add_executable(toclean toclean.cxx)
+addCleanFile(
+ "${CBD}${CMAKE_FILES_DIRECTORY}/toclean.dir/toclean.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
+
+# Create a post build custom command that copies a dummy file
+# to a custom location
+function(addPostBuildFile TARGET FILENAME)
+ add_custom_command(TARGET ${TARGET} POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy ${DUMMY_CONTENT_FILE} ${FILENAME})
+endfunction()
# Create a custom command whose output should be cleaned.
-add_custom_command(OUTPUT ${ToClean_BINARY_DIR}/generated.txt
- DEPENDS ${ToClean_SOURCE_DIR}/toclean.cxx
+set(CustomCommandFile "${CBD}/CustomCommandFile.txt")
+add_custom_command(OUTPUT ${CustomCommandFile}
+ DEPENDS ${DUMMY_CONTENT_FILE}
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")
+ ARGS -E copy ${DUMMY_CONTENT_FILE} ${CustomCommandFile})
+add_custom_target(customTarget ALL DEPENDS ${CustomCommandFile})
+addCleanFile(${CustomCommandFile})
+
+
+### Tests ADDITIONAL_MAKE_CLEAN_FILES directory property
+if("${CMAKE_GENERATOR}" MATCHES "Makefile")
+ # Create a file that must be registered for cleaning.
+ set(MakeDirPropFileAbs "${CBD}/MakeDirPropFile.txt")
+ writeCleanFile("${MakeDirPropFileAbs}")
+ set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${MakeDirPropFileAbs}")
+ addCleanFile(${MakeDirPropFileAbs})
+
+ # Create a custom command whose output should be cleaned, but whose name
+ # is not known until generate-time
+ set(MakeDirPropExpFileRel "MakeDirProp_copy${CMAKE_EXECUTABLE_SUFFIX}")
+ set(MakeDirPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${MakeDirPropExpFileRel}")
+ addPostBuildFile(toclean "${MakeDirPropExpFileAbs}")
+ set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${MakeDirPropExpFileAbs})
+ addCleanFile("${CBD}/${MakeDirPropExpFileRel}")
+endif()
+
+
+### Tests ADDITIONAL_CLEAN_FILES directory property
+
+# Register a file path relative to the build directory
+set(DirPropFileRel "DirPropFileRel.txt")
+writeCleanFile("${CBD}/${DirPropFileRel}")
+set_directory_properties(PROPERTIES ADDITIONAL_CLEAN_FILES ${DirPropFileRel})
+addCleanFile("${CBD}/${DirPropFileRel}")
+
+# Register an absolute file path
+set(DirPropFileAbs "${CBD}/DirPropFileAbs.txt")
+writeCleanFile("${DirPropFileAbs}")
+set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropFileAbs})
+addCleanFile("${DirPropFileAbs}")
# 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}")
+set(DirPropExpFileRel "DirProp_copy${CMAKE_EXECUTABLE_SUFFIX}")
+set(DirPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${DirPropExpFileRel}")
+addPostBuildFile(toclean "${DirPropExpFileAbs}")
+set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${DirPropExpFileAbs})
+addCleanFile("${CBD}/${DirPropExpFileRel}")
+
+
+### Tests ADDITIONAL_CLEAN_FILES target property
+
+function(test_target_property TARGET)
+ # Register a file path relative to the build directory
+ set(TgtPropFileRel "${TARGET}_TargetPropFileRel.txt")
+ writeCleanFile("${CBD}/${TgtPropFileRel}")
+ set_target_properties(${TARGET} PROPERTIES ADDITIONAL_CLEAN_FILES ${TgtPropFileRel})
+ addCleanFile("${CBD}/${TgtPropFileRel}")
+
+ # Register an absolute file path
+ set(TgtPropFileAbs "${CBD}/${TARGET}_TargetPropFileAbs.txt")
+ writeCleanFile("${TgtPropFileAbs}")
+ set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropFileAbs})
+ addCleanFile("${TgtPropFileAbs}")
+
+ # Create a custom command whose output should be cleaned, but whose name
+ # is not known until generate-time
+ set(TgtPropExpFileRel "${TARGET}_TargetPropGenExp.txt")
+ set(TgtPropExpFileAbs "$<TARGET_FILE_DIR:toclean>/${TgtPropExpFileRel}")
+ addPostBuildFile(${TARGET} "${TgtPropExpFileAbs}")
+ set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${TgtPropExpFileAbs})
+ addCleanFile("${CBD}/${TgtPropExpFileRel}")
+endfunction()
+
+# Test target property for various target types
+add_executable(acf_exec toclean.cxx)
+test_target_property(acf_exec)
+add_library(acf_lib toclean.cxx)
+test_target_property(acf_lib)
+add_custom_target(acf_custom ALL DEPENDS ${CustomCommandFile})
+test_target_property(acf_custom)
+
+# Process subdirectory without targets
+add_subdirectory(EmptySubDir)
+
# Configure a file listing these build-time-generated files.
-configure_file(${ToClean_SOURCE_DIR}/ToCleanFiles.cmake.in
- ${ToClean_BINARY_DIR}/ToCleanFiles.cmake @ONLY)
+get_property(TOCLEAN_FILES GLOBAL PROPERTY TOCLEAN_FILES)
+configure_file(${CSD}/ToCleanFiles.cmake.in ${CBD}/ToCleanFiles.cmake @ONLY)
diff --git a/Tests/MakeClean/check_clean.c.in b/Tests/MakeClean/check_clean.c.in
index 5bc4ab880..e5a7945af 100644
--- a/Tests/MakeClean/check_clean.c.in
+++ b/Tests/MakeClean/check_clean.c.in
@@ -18,7 +18,7 @@ int main()
if(pf)
{
fclose(pf);
- fprintf(stderr, "File \"%s\" exists!", *f);
+ fprintf(stderr, "File \"%s\" still exists!\n", *f);
result = 1;
}
}
diff --git a/Tests/MathTest/CMakeLists.txt b/Tests/MathTest/CMakeLists.txt
index f764b3a4f..5403d297c 100644
--- a/Tests/MathTest/CMakeLists.txt
+++ b/Tests/MathTest/CMakeLists.txt
@@ -13,14 +13,35 @@ set(expressions
"-1 + +1"
"+1 - -1"
"+1 - - + + -(-3 + - - +1)"
+ "1000 -12*5"
+ "1000 +12*-5"
+ "1000 -12*-5"
)
-set(FILE_EXPRESSIONS "")
-foreach(expression
- ${expressions})
- math(EXPR expr "${expression}")
- string(APPEND FILE_EXPRESSIONS "TEST_EXPRESSION(${expression}, ${expr})\n")
-endforeach()
+set(FILE_EXPRESSIONS "extern void test_expression(int x, int y, const char * text);\n")
+
+
+macro(add_math_test expression)
+ math(EXPR result ${expression} ${ARGV1} ${ARGV2})
+ set(CODE "test_expression(${expression}, ${result}, \"${expression}\");")
+ string(APPEND FILE_EXPRESSIONS "${CODE}\n")
+endmacro()
+
+macro(add_math_tests)
+ foreach (expression ${expressions})
+ add_math_test(${expression} ${ARGV0} ${ARGV1})
+ endforeach ()
+endmacro()
+
+add_math_tests()
+add_math_tests("OUTPUT_FORMAT" "DECIMAL")
+add_math_tests("OUTPUT_FORMAT" "HEXADECIMAL")
+
+# Avoid the test with negative result and hexadecimal formatting
+# therefore more tests with a negative result
+add_math_test("-12*5")
+add_math_test("12*-5")
+
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/MathTestTests.h.in"
diff --git a/Tests/MathTest/MathTestExec.cxx b/Tests/MathTest/MathTestExec.cxx
index 124eba46f..fbcddc4ed 100644
--- a/Tests/MathTest/MathTestExec.cxx
+++ b/Tests/MathTest/MathTestExec.cxx
@@ -1,21 +1,43 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <string.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 res = 0;
+bool print = false;
+
+void test_expression(int x, int y, const char* text)
+{
+ bool fail = (x) != (y);
+ if (fail) {
+ res++;
+ printf("Problem with EXPR:");
+ }
+ if (fail || print) {
+ printf("Expression: \"%s\" in CMake returns %d", text, (y));
+ if (fail) {
+ printf(" while in C returns: %d", (x));
+ }
+ printf("\n");
}
+}
int main(int argc, char* argv[])
{
- if (argc > 1) {
- printf("Usage: %s\n", argv[0]);
+ if (argc > 2) {
+ printf("Usage: %s [print]\n", argv[0]);
return 1;
}
- int res = 0;
+
+ if (argc > 1) {
+ if (strcmp(argv[1], "print") != 0) {
+ printf("Usage: %s [print]\n", argv[0]);
+ return 1;
+ }
+ print = true;
+ }
+
#include "MathTestTests.h"
+
if (res != 0) {
printf("%s: %d math tests failed\n", argv[0], res);
return 1;
diff --git a/Tests/MissingInstall/CMakeLists.txt b/Tests/MissingInstall/CMakeLists.txt
index 91624f710..365b31f62 100644
--- a/Tests/MissingInstall/CMakeLists.txt
+++ b/Tests/MissingInstall/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 2.8.12)
+cmake_minimum_required (VERSION 3.9)
project(TestMissingInstall)
set(CMAKE_SKIP_INSTALL_RULES ON)
@@ -8,11 +8,7 @@ set(CMAKE_SKIP_INSTALL_RULES ON)
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()
+get_property(MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
add_executable(mybin mybin.cpp)
install(TARGETS mybin RUNTIME DESTINATION bin)
diff --git a/Tests/Module/CheckIPOSupported-C/CMakeLists.txt b/Tests/Module/CheckIPOSupported-C/CMakeLists.txt
index 607dcd33a..4a41a988d 100644
--- a/Tests/Module/CheckIPOSupported-C/CMakeLists.txt
+++ b/Tests/Module/CheckIPOSupported-C/CMakeLists.txt
@@ -4,11 +4,12 @@ project(CheckIPOSupported-C LANGUAGES C)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
-check_ipo_supported(RESULT ipo_supported)
+check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output)
if(ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif(CMake_TEST_IPO_WORKS_C)
- message(FATAL_ERROR "IPO expected to work")
+ string(REPLACE "\n" "\n " ipo_output "${ipo_output}")
+ message(FATAL_ERROR "IPO expected to work, but the check failed:\n ${ipo_output}")
endif()
add_library(foo foo.c)
diff --git a/Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt b/Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt
index 2dede930b..1bb2b8496 100644
--- a/Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt
+++ b/Tests/Module/CheckIPOSupported-CXX/CMakeLists.txt
@@ -4,11 +4,12 @@ project(CheckIPOSupported-CXX LANGUAGES CXX)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
-check_ipo_supported(RESULT ipo_supported)
+check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output)
if(ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif(CMake_TEST_IPO_WORKS_CXX)
- message(FATAL_ERROR "IPO expected to work")
+ string(REPLACE "\n" "\n " ipo_output "${ipo_output}")
+ message(FATAL_ERROR "IPO expected to work, but the check failed:\n ${ipo_output}")
endif()
add_library(foo foo.cpp)
diff --git a/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt b/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
index dee5c25bd..3872b567b 100644
--- a/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
+++ b/Tests/Module/CheckIPOSupported-Fortran/CMakeLists.txt
@@ -4,11 +4,12 @@ project(CheckIPOSupported-Fortran LANGUAGES Fortran)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
-check_ipo_supported(RESULT ipo_supported)
+check_ipo_supported(RESULT ipo_supported OUTPUT ipo_output)
if(ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif(CMake_TEST_IPO_WORKS_Fortran)
- message(FATAL_ERROR "IPO expected to work")
+ string(REPLACE "\n" "\n " ipo_output "${ipo_output}")
+ message(FATAL_ERROR "IPO expected to work, but the check failed:\n ${ipo_output}")
endif()
add_library(foo foo.f)
diff --git a/Tests/Module/CheckTypeSize/CheckTypeSize.c b/Tests/Module/CheckTypeSize/CheckTypeSize.c
index 05c798b05..adfd2fc2a 100644
--- a/Tests/Module/CheckTypeSize/CheckTypeSize.c
+++ b/Tests/Module/CheckTypeSize/CheckTypeSize.c
@@ -2,13 +2,13 @@
#include "somestruct.h"
#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
+# include <sys/types.h>
#endif
#ifdef HAVE_STDINT_H
-#include <stdint.h>
+# include <stdint.h>
#endif
#ifdef HAVE_STDDEF_H
-#include <stddef.h>
+# include <stddef.h>
#endif
#include <stdio.h>
@@ -86,17 +86,17 @@ int main()
/* long long */
#if defined(SIZEOF_LONG_LONG)
CHECK(long long, SIZEOF_LONG_LONG);
-#if !defined(HAVE_SIZEOF_LONG_LONG)
+# if !defined(HAVE_SIZEOF_LONG_LONG)
NODEF(HAVE_SIZEOF_LONG_LONG);
-#endif
+# endif
#endif
/* __int64 */
#if defined(SIZEOF___INT64)
CHECK(__int64, SIZEOF___INT64);
-#if !defined(HAVE_SIZEOF___INT64)
+# if !defined(HAVE_SIZEOF___INT64)
NODEF(HAVE_SIZEOF___INT64);
-#endif
+# endif
#elif defined(HAVE_SIZEOF___INT64)
NODEF(SIZEOF___INT64);
#endif
@@ -114,9 +114,9 @@ int main()
/* ssize_t */
#if defined(SIZEOF_SSIZE_T)
CHECK(ssize_t, SIZEOF_SSIZE_T);
-#if !defined(HAVE_SIZEOF_SSIZE_T)
+# if !defined(HAVE_SIZEOF_SSIZE_T)
NODEF(HAVE_SIZEOF_SSIZE_T);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_SSIZE_T)
NODEF(SIZEOF_SSIZE_T);
#endif
@@ -125,9 +125,9 @@ int main()
#if defined(SIZEOF_STRUCTMEMBER_INT)
CHECK(x.someint, SIZEOF_STRUCTMEMBER_INT);
CHECK(x.someint, SIZEOF_INT);
-#if !defined(HAVE_SIZEOF_STRUCTMEMBER_INT)
+# if !defined(HAVE_SIZEOF_STRUCTMEMBER_INT)
NODEF(HAVE_SIZEOF_STRUCTMEMBER_INT);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_STRUCTMEMBER_INT)
NODEF(SIZEOF_STRUCTMEMBER_INT);
#endif
@@ -136,9 +136,9 @@ int main()
#if defined(SIZEOF_STRUCTMEMBER_PTR)
CHECK(x.someptr, SIZEOF_STRUCTMEMBER_PTR);
CHECK(x.someptr, SIZEOF_DATA_PTR);
-#if !defined(HAVE_SIZEOF_STRUCTMEMBER_PTR)
+# if !defined(HAVE_SIZEOF_STRUCTMEMBER_PTR)
NODEF(HAVE_SIZEOF_STRUCTMEMBER_PTR);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_STRUCTMEMBER_PTR)
NODEF(SIZEOF_STRUCTMEMBER_PTR);
#endif
@@ -147,9 +147,9 @@ int main()
#if defined(SIZEOF_STRUCTMEMBER_CHAR)
CHECK(x.somechar, SIZEOF_STRUCTMEMBER_CHAR);
CHECK(x.somechar, SIZEOF_CHAR);
-#if !defined(HAVE_SIZEOF_STRUCTMEMBER_CHAR)
+# if !defined(HAVE_SIZEOF_STRUCTMEMBER_CHAR)
NODEF(HAVE_SIZEOF_STRUCTMEMBER_CHAR);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_STRUCTMEMBER_CHAR)
NODEF(SIZEOF_STRUCTMEMBER_CHAR);
#endif
diff --git a/Tests/Module/CheckTypeSize/CheckTypeSize.cxx b/Tests/Module/CheckTypeSize/CheckTypeSize.cxx
index 2ae84a32f..15dc890c8 100644
--- a/Tests/Module/CheckTypeSize/CheckTypeSize.cxx
+++ b/Tests/Module/CheckTypeSize/CheckTypeSize.cxx
@@ -3,13 +3,13 @@
#include "someclass.hxx"
#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
+# include <sys/types.h>
#endif
#ifdef HAVE_STDINT_H
-#include <stdint.h>
+# include <stdint.h>
#endif
#ifdef HAVE_STDDEF_H
-#include <stddef.h>
+# include <stddef.h>
#endif
#include <stdio.h>
@@ -87,17 +87,17 @@ int main()
/* long long */
#if defined(SIZEOF_LONG_LONG)
CHECK(long long, SIZEOF_LONG_LONG);
-#if !defined(HAVE_SIZEOF_LONG_LONG)
+# if !defined(HAVE_SIZEOF_LONG_LONG)
NODEF(HAVE_SIZEOF_LONG_LONG);
-#endif
+# endif
#endif
/* __int64 */
#if defined(SIZEOF___INT64)
CHECK(__int64, SIZEOF___INT64);
-#if !defined(HAVE_SIZEOF___INT64)
+# if !defined(HAVE_SIZEOF___INT64)
NODEF(HAVE_SIZEOF___INT64);
-#endif
+# endif
#elif defined(HAVE_SIZEOF___INT64)
NODEF(SIZEOF___INT64);
#endif
@@ -115,9 +115,9 @@ int main()
/* ssize_t */
#if defined(SIZEOF_SSIZE_T)
CHECK(ssize_t, SIZEOF_SSIZE_T);
-#if !defined(HAVE_SIZEOF_SSIZE_T)
+# if !defined(HAVE_SIZEOF_SSIZE_T)
NODEF(HAVE_SIZEOF_SSIZE_T);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_SSIZE_T)
NODEF(SIZEOF_SSIZE_T);
#endif
@@ -126,9 +126,9 @@ int main()
#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)
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_INT)
NODEF(HAVE_SIZEOF_STRUCTMEMBER_INT);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_STRUCTMEMBER_INT)
NODEF(SIZEOF_STRUCTMEMBER_INT);
#endif
@@ -137,9 +137,9 @@ int main()
#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)
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_PTR)
NODEF(HAVE_SIZEOF_NS_CLASSMEMBER_PTR);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_NS_CLASSMEMBER_PTR)
NODEF(SIZEOF_NS_CLASSMEMBER_PTR);
#endif
@@ -148,9 +148,9 @@ int main()
#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)
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_CHAR)
NODEF(HAVE_SIZEOF_NS_CLASSMEMBER_CHAR);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_NS_CLASSMEMBER_CHAR)
NODEF(SIZEOF_NS_CLASSMEMBER_CHAR);
#endif
@@ -159,9 +159,9 @@ int main()
#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)
+# if !defined(HAVE_SIZEOF_NS_CLASSMEMBER_BOOL)
NODEF(HAVE_SIZEOF_NS_CLASSMEMBER_BOOL);
-#endif
+# endif
#elif defined(HAVE_SIZEOF_NS_CLASSMEMBER_BOOL)
NODEF(SIZEOF_NS_CLASSMEMBER_BOOL);
#endif
diff --git a/Tests/Module/ExternalData/Data5/CMakeLists.txt b/Tests/Module/ExternalData/Data5/CMakeLists.txt
index 13c7fabed..ea67f05af 100644
--- a/Tests/Module/ExternalData/Data5/CMakeLists.txt
+++ b/Tests/Module/ExternalData/Data5/CMakeLists.txt
@@ -2,21 +2,21 @@
ExternalData_Add_Test(Data5.A
NAME Data5Check.A
COMMAND ${CMAKE_COMMAND}
- -D Data5=DATA{../Data.dat}
+ -D Data5=DATA{Data5.dat}
-P ${CMAKE_CURRENT_SOURCE_DIR}/Data5Check.cmake
)
ExternalData_Add_Target(Data5.A)
ExternalData_Add_Test(Data5.B
NAME Data5Check.B
COMMAND ${CMAKE_COMMAND}
- -D Data5=DATA{../Data.dat}
+ -D Data5=DATA{Data5.dat}
-P ${CMAKE_CURRENT_SOURCE_DIR}/Data5Check.cmake
)
ExternalData_Add_Target(Data5.B)
ExternalData_Add_Test(Data5.C
NAME Data5Check.C
COMMAND ${CMAKE_COMMAND}
- -D Data5=DATA{../Data.dat}
+ -D Data5=DATA{Data5.dat}
-P ${CMAKE_CURRENT_SOURCE_DIR}/Data5Check.cmake
)
ExternalData_Add_Target(Data5.C)
diff --git a/Tests/Module/FindDependency/CMakeLists.txt b/Tests/Module/FindDependency/CMakeLists.txt
index dcb998a4b..06d7dce9a 100644
--- a/Tests/Module/FindDependency/CMakeLists.txt
+++ b/Tests/Module/FindDependency/CMakeLists.txt
@@ -6,6 +6,8 @@ set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/packages")
find_package(Pack1 REQUIRED)
find_package(Pack4 4.3 EXACT REQUIRED)
+find_package(Pack7 REQUIRED)
+find_package(Pack8 REQUIRED)
add_executable(FindDependency main.cpp)
-target_link_libraries(FindDependency Pack1::Lib Pack4::Lib)
+target_link_libraries(FindDependency Pack1::Lib Pack4::Lib Pack8::Lib)
diff --git a/Tests/Module/FindDependency/main.cpp b/Tests/Module/FindDependency/main.cpp
index 50c5958ca..4ee460fbf 100644
--- a/Tests/Module/FindDependency/main.cpp
+++ b/Tests/Module/FindDependency/main.cpp
@@ -1,26 +1,38 @@
#ifndef HAVE_PACK1
-#error Expected HAVE_PACK1
+# error Expected HAVE_PACK1
#endif
#ifndef HAVE_PACK2
-#error Expected HAVE_PACK2
+# error Expected HAVE_PACK2
#endif
#ifndef HAVE_PACK3
-#error Expected HAVE_PACK3
+# error Expected HAVE_PACK3
#endif
#ifndef HAVE_PACK4
-#error Expected HAVE_PACK4
+# error Expected HAVE_PACK4
#endif
#ifndef HAVE_PACK5
-#error Expected HAVE_PACK5
+# error Expected HAVE_PACK5
#endif
#ifndef HAVE_PACK6
-#error Expected HAVE_PACK6
+# error Expected HAVE_PACK6
+#endif
+
+#ifndef HAVE_PACK7
+# error Expected HAVE_PACK7
+#endif
+
+#ifndef HAVE_PACK7_COMP1
+# error Expected HAVE_PACK7_COMP1
+#endif
+
+#ifndef HAVE_PACK8
+# error Expected HAVE_PACK8
#endif
int main(int argc, char** argv)
diff --git a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
index 52d461350..cffef5a0b 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
+++ b/Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt
@@ -52,8 +52,10 @@ endmacro()
# detailed features tables, not just meta-features
if (CMAKE_C_COMPILE_FEATURES)
- set(C_expected_features ${CMAKE_C_COMPILE_FEATURES})
- list(FILTER C_expected_features EXCLUDE REGEX "^c_std_[0-9][0-9]")
+ if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$")
+ set(C_expected_features ${CMAKE_C_COMPILE_FEATURES})
+ list(FILTER C_expected_features EXCLUDE REGEX "^c_std_[0-9][0-9]")
+ endif()
endif()
if (C_expected_features)
string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" COMPILER_VERSION_MAJOR "${CMAKE_C_COMPILER_VERSION}")
@@ -61,7 +63,7 @@ if (C_expected_features)
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" COMPILER_VERSION_PATCH "${CMAKE_C_COMPILER_VERSION}")
if (CMAKE_C_COMPILER_ID STREQUAL "GNU"
- OR CMAKE_C_COMPILER_ID STREQUAL "Clang"
+ OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang"
OR CMAKE_C_COMPILER_ID STREQUAL "Intel")
add_executable(WriteCompilerDetectionHeader_C11 main.c)
@@ -93,8 +95,10 @@ if (C_expected_features)
endif()
if (CMAKE_CXX_COMPILE_FEATURES)
- set(CXX_expected_features ${CMAKE_CXX_COMPILE_FEATURES})
- list(FILTER CXX_expected_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]")
+ if(NOT CMAKE_CXX_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$")
+ set(CXX_expected_features ${CMAKE_CXX_COMPILE_FEATURES})
+ list(FILTER CXX_expected_features EXCLUDE REGEX "^cxx_std_[0-9][0-9]")
+ endif()
endif()
if (NOT CXX_expected_features)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp"
@@ -118,7 +122,7 @@ string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" COMPILER_VERSION_MINO
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" COMPILER_VERSION_PATCH "${CMAKE_CXX_COMPILER_VERSION}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
- OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"
OR CMAKE_CXX_COMPILER_ID STREQUAL "SunPro"
OR CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
@@ -128,7 +132,8 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
endif()
# for msvc the compiler version determines which c++11 features are available.
-if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
+if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"))
if(";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;")
list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)
@@ -190,7 +195,7 @@ write_compiler_detection_header(
ALLOW_UNKNOWN_COMPILERS
)
-# intentionally abuse the TEST_NULLPR variable: this will only work
+# intentionally abuse the TEST_NULLPTR variable: this will only work
# with the fallback code.
check_cxx_source_compiles("#include \"${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection_allow_unknown.h\"
int main() {\n int i = TEST_NULLPTR;\n return 0; }\n"
@@ -199,3 +204,16 @@ int main() {\n int i = TEST_NULLPTR;\n return 0; }\n"
if (NOT file_include_works_allow_unknown)
message(SEND_ERROR "Inclusion of ${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection_allow_unknown.h was expected to work, but did not.")
endif()
+
+# test for BARE_FEATURES
+
+write_compiler_detection_header(
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/test_compiler_detection_bare_features.h"
+ PREFIX TEST
+ COMPILERS GNU Clang AppleClang MSVC SunPro Intel
+ VERSION 3.1
+ BARE_FEATURES cxx_nullptr cxx_override cxx_noexcept cxx_final
+)
+
+add_executable(WriteCompilerDetectionHeaderBareFeatures main_bare.cpp)
+set_property(TARGET WriteCompilerDetectionHeaderBareFeatures PROPERTY CXX_STANDARD 11)
diff --git a/Tests/Module/WriteCompilerDetectionHeader/compile_tests.h b/Tests/Module/WriteCompilerDetectionHeader/compile_tests.h
index d3c2a2d39..0da8bab94 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/compile_tests.h
+++ b/Tests/Module/WriteCompilerDetectionHeader/compile_tests.h
@@ -7,21 +7,21 @@
JOIN(EXPECTED_COMPILER_, FEATURE))
#if !CHECK(CXX_DELEGATING_CONSTRUCTORS)
-#error cxx_delegating_constructors expected availability did not match.
+# error cxx_delegating_constructors expected availability did not match.
#endif
#if !CHECK(CXX_VARIADIC_TEMPLATES)
-#error cxx_variadic_templates expected availability did not match.
+# error cxx_variadic_templates expected availability did not match.
#endif
#if !CHECK(VERSION_MAJOR)
-#error Compiler major version did not match.
+# error Compiler major version did not match.
#endif
#if !CHECK(VERSION_MINOR)
-#error Compiler minor version did not match.
+# error Compiler minor version did not match.
#endif
#if !CHECK(VERSION_PATCH)
-#error Compiler patch version did not match.
+# error Compiler patch version did not match.
#endif
diff --git a/Tests/Module/WriteCompilerDetectionHeader/main.c b/Tests/Module/WriteCompilerDetectionHeader/main.c
index ee6abdb92..3420c6750 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/main.c
+++ b/Tests/Module/WriteCompilerDetectionHeader/main.c
@@ -3,25 +3,25 @@
#if !defined(TEST_COMPILER_C_FUNCTION_PROTOTYPES) || \
!TEST_COMPILER_C_FUNCTION_PROTOTYPES
-#error Expected TEST_COMPILER_C_FUNCTION_PROTOTYPES
+# error Expected TEST_COMPILER_C_FUNCTION_PROTOTYPES
#endif
#if !EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES
-#error Expected EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES
+# error Expected EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES
#endif
#if !defined(TEST_COMPILER_C_RESTRICT) || !TEST_COMPILER_C_RESTRICT
-#if EXPECTED_COMPILER_C_RESTRICT
-#error Expected TEST_COMPILER_C_RESTRICT
-#endif
+# if EXPECTED_COMPILER_C_RESTRICT
+# error Expected TEST_COMPILER_C_RESTRICT
+# endif
#else
-#if !EXPECTED_COMPILER_C_RESTRICT
-#error Expect no TEST_COMPILER_C_RESTRICT
-#endif
+# if !EXPECTED_COMPILER_C_RESTRICT
+# error Expect no TEST_COMPILER_C_RESTRICT
+# endif
#endif
#ifdef TEST_COMPILER_CXX_STATIC_ASSERT
-#error Expect no CXX features defined
+# error Expect no CXX features defined
#endif
int main()
diff --git a/Tests/Module/WriteCompilerDetectionHeader/main.cpp b/Tests/Module/WriteCompilerDetectionHeader/main.cpp
index 9979cbae6..97116a5a8 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/main.cpp
+++ b/Tests/Module/WriteCompilerDetectionHeader/main.cpp
@@ -5,7 +5,7 @@
#include "compile_tests.h"
#ifdef TEST_COMPILER_C_STATIC_ASSERT
-#error Expect no C features defined
+# error Expect no C features defined
#endif
TEST_STATIC_ASSERT(true);
diff --git a/Tests/Module/WriteCompilerDetectionHeader/main_multi.c b/Tests/Module/WriteCompilerDetectionHeader/main_multi.c
index 6e13fd762..28f9daea2 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/main_multi.c
+++ b/Tests/Module/WriteCompilerDetectionHeader/main_multi.c
@@ -3,25 +3,25 @@
#if !defined(MULTI_COMPILER_C_FUNCTION_PROTOTYPES) || \
!MULTI_COMPILER_C_FUNCTION_PROTOTYPES
-#error Expected MULTI_COMPILER_C_FUNCTION_PROTOTYPES
+# error Expected MULTI_COMPILER_C_FUNCTION_PROTOTYPES
#endif
#if !EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES
-#error Expected EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES
+# error Expected EXPECTED_COMPILER_C_FUNCTION_PROTOTYPES
#endif
#if !defined(MULTI_COMPILER_C_RESTRICT) || !MULTI_COMPILER_C_RESTRICT
-#if EXPECTED_COMPILER_C_RESTRICT
-#error Expected MULTI_COMPILER_C_RESTRICT
-#endif
+# if EXPECTED_COMPILER_C_RESTRICT
+# error Expected MULTI_COMPILER_C_RESTRICT
+# endif
#else
-#if !EXPECTED_COMPILER_C_RESTRICT
-#error Expect no MULTI_COMPILER_C_RESTRICT
-#endif
+# if !EXPECTED_COMPILER_C_RESTRICT
+# error Expect no MULTI_COMPILER_C_RESTRICT
+# endif
#endif
#ifdef MULTI_COMPILER_CXX_STATIC_ASSERT
-#error Expect no CXX features defined
+# error Expect no CXX features defined
#endif
int main()
diff --git a/Tests/Module/WriteCompilerDetectionHeader/multi_files.cpp b/Tests/Module/WriteCompilerDetectionHeader/multi_files.cpp
index d1f178f7c..44f4d17c7 100644
--- a/Tests/Module/WriteCompilerDetectionHeader/multi_files.cpp
+++ b/Tests/Module/WriteCompilerDetectionHeader/multi_files.cpp
@@ -5,7 +5,7 @@
#include "compile_tests.h"
#ifdef MULTI_COMPILER_C_STATIC_ASSERT
-#error Expect no C features defined
+# error Expect no C features defined
#endif
MULTI_STATIC_ASSERT(true);
diff --git a/Tests/ModuleDefinition/example_mod_1.c b/Tests/ModuleDefinition/example_mod_1.c
index 6b355cf6b..8afdb31e7 100644
--- a/Tests/ModuleDefinition/example_mod_1.c
+++ b/Tests/ModuleDefinition/example_mod_1.c
@@ -1,7 +1,7 @@
#ifdef __WATCOMC__
-#define MODULE_CCONV __cdecl
+# define MODULE_CCONV __cdecl
#else
-#define MODULE_CCONV
+# define MODULE_CCONV
#endif
int __declspec(dllimport) example_exe_function(void);
diff --git a/Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m b/Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m
index ee7068240..5567c4eef 100644
--- a/Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m
+++ b/Tests/MumpsCoverage/VistA-FOIA/Packages/Uncategorized/ZZCOVTST.m
@@ -12,6 +12,9 @@ EN ; This entry point shouldn't be found without fixing
; This line not executable
D T6^ZZCOVTST
;
+% ; a line to test for a problem where % was dropped
+ N Do,Re,Mi
+ S Do="A#"
T1 ; This line should always be found
N D
S D=2
diff --git a/Tests/MumpsCoverage/ZZCOVTST.cmcov b/Tests/MumpsCoverage/ZZCOVTST.cmcov
index 7a5df6105..515f822cc 100644
--- a/Tests/MumpsCoverage/ZZCOVTST.cmcov
+++ b/Tests/MumpsCoverage/ZZCOVTST.cmcov
@@ -13,33 +13,36 @@ ZZCOVTST,1,1,"ZZCOVTST;OSEHRA/JPS -- Test routine for Coverage Parsing;4/28/2014
,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
+,15,1,"% ; a line to test for a problem where % was dropped"
+,16,1,"N Do,Re,Mi"
+,17,1,"S Do=""A#"""
+,18,0,"T1 ; This line should always be found"
+,19,1," N D"
+,20,1," S D=2"
+,21,1," W !,D,!,""This is the second entry point"",!"
+,22,1," D T2^ZZCOVTST(D)"
+,23,1," Q"
+,24,0," ;"
+,25,0,"T2(EQ) ; This is debatable and only called with ENT^ROU notation"
+,26,1," N D"
+,27,1," S D=3"
+,28,1," W !,D,!,EQ,""This is the third entry point"",!"
+,29,1," D T3^ZZCOVTST"
+,30,1," Q"
+,31,0," ;"
+,32,1,"T3 N D S D=4 W D,!,""Fourth Entry point"",! Q"
+,33,0," ;"
+,34,0,"T4 N D S D=5 W ""Shouldn't be executed"""
+,35,0," W ""Lots to not do"""
+,36,0," Q"
+,37,1,"T5(EQ) ;this entry point is called with a $$ notation"
+,38,1," W ""THIS IS THE $$ NOTATION!"",!"
+,39,1," Q 0"
+,40,0,"T6 ; An entry point to show comments inside of ""DO"" blocks"
+,41,1," D"
+,42,1," . W ""This is executable code"",!"
+,43,0," . ; This is a comment inside the do block, not executable"
+,44,1," . S ZZBLAH=""blah"""
+,45,1," W ""Ending T6"",!"
+,46,0," ;"
+Toals for ZZCOVTST,,28,
diff --git a/Tests/MumpsCoverage/ZZCOVTST.mcov b/Tests/MumpsCoverage/ZZCOVTST.mcov
index b2608d952..e1fa18cad 100644
--- a/Tests/MumpsCoverage/ZZCOVTST.mcov
+++ b/Tests/MumpsCoverage/ZZCOVTST.mcov
@@ -9,6 +9,9 @@ GT.M 15-AUG-2014 10:14:32 ZWR
^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","%")="2:0:0:0:208"
+^ZZCOVERAGE("ZZCOVTST","%",1)="2:0:0:0:208"
+^ZZCOVERAGE("ZZCOVTST","%",2)="2:0:0:0:208"
^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"
diff --git a/Tests/NewlineArgs/libcxx1.cxx b/Tests/NewlineArgs/libcxx1.cxx
index 72f171d5c..b3c219247 100644
--- a/Tests/NewlineArgs/libcxx1.cxx
+++ b/Tests/NewlineArgs/libcxx1.cxx
@@ -1,10 +1,10 @@
#include "libcxx1.h"
#ifdef TEST_FLAG_1
-#ifdef TEST_FLAG_2
+# ifdef TEST_FLAG_2
float LibCxx1Class::Method()
{
return 2.0;
}
-#endif
+# endif
#endif
diff --git a/Tests/NewlineArgs/libcxx1.h b/Tests/NewlineArgs/libcxx1.h
index ea094d758..8bb09cdc2 100644
--- a/Tests/NewlineArgs/libcxx1.h
+++ b/Tests/NewlineArgs/libcxx1.h
@@ -2,8 +2,8 @@ class LibCxx1Class
{
public:
#ifdef TEST_FLAG_1
-#ifdef TEST_FLAG_2
+# ifdef TEST_FLAG_2
static float Method();
-#endif
+# endif
#endif
};
diff --git a/Tests/ObjectLibrary/A/a.h b/Tests/ObjectLibrary/A/a.h
index b1fd42fac..184df3ced 100644
--- a/Tests/ObjectLibrary/A/a.h
+++ b/Tests/ObjectLibrary/A/a.h
@@ -1,6 +1,6 @@
#ifndef A_DEF
-#error "A_DEF not defined"
+# error "A_DEF not defined"
#endif
#ifdef B_DEF
-#error "B_DEF must not be defined"
+# error "B_DEF must not be defined"
#endif
diff --git a/Tests/ObjectLibrary/B/b.h b/Tests/ObjectLibrary/B/b.h
index a7bd35230..de81d69f2 100644
--- a/Tests/ObjectLibrary/B/b.h
+++ b/Tests/ObjectLibrary/B/b.h
@@ -1,18 +1,18 @@
#ifdef A_DEF
-#error "A_DEF must not be defined"
+# error "A_DEF must not be defined"
#endif
#ifndef B_DEF
-#error "B_DEF not defined"
+# error "B_DEF not defined"
#endif
#if defined(_WIN32) && defined(Bexport)
-#define EXPORT_B __declspec(dllexport)
+# define EXPORT_B __declspec(dllexport)
#else
-#define EXPORT_B
+# define EXPORT_B
#endif
#if defined(_WIN32) && defined(SHARED_B)
-#define IMPORT_B __declspec(dllimport)
+# define IMPORT_B __declspec(dllimport)
#else
-#define IMPORT_B
+# define IMPORT_B
#endif
diff --git a/Tests/ObjectLibrary/CMakeLists.txt b/Tests/ObjectLibrary/CMakeLists.txt
index 4bffd1221..7897ab99b 100644
--- a/Tests/ObjectLibrary/CMakeLists.txt
+++ b/Tests/ObjectLibrary/CMakeLists.txt
@@ -62,4 +62,14 @@ add_custom_target(UseABinternalDep COMMAND ${CMAKE_COMMAND} -E touch UseABintern
add_custom_command(TARGET UseABinternal POST_BUILD COMMAND ${CMAKE_COMMAND} -P UseABinternalDep.cmake)
add_dependencies(UseABinternal UseABinternalDep)
+# Test a static library with sources from a different static library
+add_library(UseCstaticObjs STATIC $<TARGET_OBJECTS:Cstatic> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
+
+# Test a shared library with sources from a different shared library
+add_library(UseCsharedObjs SHARED $<TARGET_OBJECTS:Cshared> $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:Bexport>)
+
+# Test a shared executable with sources from a different shared library
+add_executable(UseABstaticObjs $<TARGET_OBJECTS:UseABstatic>)
+target_link_libraries(UseABstaticObjs ABstatic)
+
add_subdirectory(ExportLanguages)
diff --git a/Tests/ObjectLibrary/c.c b/Tests/ObjectLibrary/c.c
index 4c37e38b2..2692899cc 100644
--- a/Tests/ObjectLibrary/c.c
+++ b/Tests/ObjectLibrary/c.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) && defined(Cshared_EXPORTS)
-#define EXPORT_C __declspec(dllexport)
+# define EXPORT_C __declspec(dllexport)
#else
-#define EXPORT_C
+# define EXPORT_C
#endif
extern int a1(void);
diff --git a/Tests/ObjectLibrary/main.c b/Tests/ObjectLibrary/main.c
index b2f1d44bd..cc7568527 100644
--- a/Tests/ObjectLibrary/main.c
+++ b/Tests/ObjectLibrary/main.c
@@ -1,7 +1,7 @@
#if defined(_WIN32) && defined(SHARED_C)
-#define IMPORT_C __declspec(dllimport)
+# define IMPORT_C __declspec(dllimport)
#else
-#define IMPORT_C
+# define IMPORT_C
#endif
extern IMPORT_C int b1(void);
extern IMPORT_C int b2(void);
diff --git a/Tests/OutDir/CMakeLists.txt b/Tests/OutDir/CMakeLists.txt
index 88468c3c0..823ab0864 100644
--- a/Tests/OutDir/CMakeLists.txt
+++ b/Tests/OutDir/CMakeLists.txt
@@ -1,7 +1,8 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.9)
project(OutDir C)
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" CONFIG)
list(APPEND configs "${CONFIG}")
diff --git a/Tests/OutOfSource/CMakeLists.txt b/Tests/OutOfSource/CMakeLists.txt
index de1603a55..4687882aa 100644
--- a/Tests/OutOfSource/CMakeLists.txt
+++ b/Tests/OutOfSource/CMakeLists.txt
@@ -1,4 +1,4 @@
-# a simple test cas
+# a simple test case
cmake_minimum_required (VERSION 2.6)
project (OutOfSource)
diff --git a/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt b/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt
index 10a2f59d1..76a93d24a 100644
--- a/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt
+++ b/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt
@@ -16,11 +16,11 @@ if ("${PROJECT_SOURCE_DIR}" STREQUAL "${ANOTHER_PROJ_SOURCE_DIR}")
# Use a separate variable for computation.
set(MAXPATH "${CMAKE_OBJECT_PATH_MAX}")
- # VS8 adds "OutOfSource/SubDir/OutOfSourceSubdir/../../../" to the
+ # VS 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)")
+ if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
math(EXPR MAXPATH "${MAXPATH} - 46")
endif()
diff --git a/Tests/OutOfSource/OutOfSourceSubdir/testlib.h b/Tests/OutOfSource/OutOfSourceSubdir/testlib.h
index bacf5a109..3e012d252 100644
--- a/Tests/OutOfSource/OutOfSourceSubdir/testlib.h
+++ b/Tests/OutOfSource/OutOfSourceSubdir/testlib.h
@@ -1,11 +1,11 @@
#ifdef _WIN32
-#ifdef testlib_EXPORTS
-#define CM_TEST_LIB_EXPORT __declspec(dllexport)
+# 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 __declspec(dllimport)
-#endif
-#else
-#define CM_TEST_LIB_EXPORT
+# define CM_TEST_LIB_EXPORT
#endif
CM_TEST_LIB_EXPORT float TestLib();
diff --git a/Tests/PDBDirectoryAndName/CMakeLists.txt b/Tests/PDBDirectoryAndName/CMakeLists.txt
index 2fb894ed8..6d8d6cc00 100644
--- a/Tests/PDBDirectoryAndName/CMakeLists.txt
+++ b/Tests/PDBDirectoryAndName/CMakeLists.txt
@@ -19,7 +19,7 @@ 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"
+ PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mylibA_PDB/$<CONFIG>"
)
list(APPEND my_targets mylibA)
@@ -87,7 +87,13 @@ foreach(t ${my_targets})
if(NOT pdb_dir)
set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR})
endif()
- list(APPEND pdbs ${pdb_dir}/${CMAKE_CFG_INTDIR}/${pdb_name}.pdb)
+ if (pdb_dir MATCHES "\\$<.*>")
+ # Skip per-configuration subdirectory if the value contained
+ # a generator expression.
+ list(APPEND pdbs ${pdb_dir}/${pdb_name}.pdb)
+ else()
+ list(APPEND pdbs ${pdb_dir}/${CMAKE_CFG_INTDIR}/${pdb_name}.pdb)
+ endif()
endforeach()
add_custom_target(check_pdbs ALL VERBATIM
COMMAND ${CMAKE_COMMAND} -Dconfig=$<CONFIGURATION> "-Dpdbs=${pdbs}"
diff --git a/Tests/PerConfig/pcShared.h b/Tests/PerConfig/pcShared.h
index 031cd7965..2ae66cd42 100644
--- a/Tests/PerConfig/pcShared.h
+++ b/Tests/PerConfig/pcShared.h
@@ -2,13 +2,13 @@
#define pcShared_h
#ifdef _WIN32
-#ifdef pcShared_EXPORTS
-#define PC_EXPORT __declspec(dllexport)
+# ifdef pcShared_EXPORTS
+# define PC_EXPORT __declspec(dllexport)
+# else
+# define PC_EXPORT __declspec(dllimport)
+# endif
#else
-#define PC_EXPORT __declspec(dllimport)
-#endif
-#else
-#define PC_EXPORT
+# define PC_EXPORT
#endif
PC_EXPORT const char* pcShared(void);
diff --git a/Tests/Plugin/CMakeLists.txt b/Tests/Plugin/CMakeLists.txt
index 9e2b4abd9..8e8fa0759 100644
--- a/Tests/Plugin/CMakeLists.txt
+++ b/Tests/Plugin/CMakeLists.txt
@@ -15,6 +15,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/static)
set(KWSYS_NAMESPACE kwsys)
set(KWSYS_HEADER_ROOT ${Plugin_BINARY_DIR}/include)
set(KWSYS_USE_DynamicLoader 1)
+set(KWSYS_ENCODING_DEFAULT_CODEPAGE CP_UTF8)
add_subdirectory(${Plugin_SOURCE_DIR}/../../Source/kwsys src/kwsys)
# Configure the location of plugins.
@@ -28,13 +29,6 @@ include_directories(
${Plugin_SOURCE_DIR}/include
)
-# 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")
- string(APPEND CMAKE_CXX_FLAGS " -AA")
-endif ()
-
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
diff --git a/Tests/Plugin/include/example.h b/Tests/Plugin/include/example.h
index 87d992e57..cbcb3dcc3 100644
--- a/Tests/Plugin/include/example.h
+++ b/Tests/Plugin/include/example.h
@@ -2,13 +2,13 @@
#define example_h
#if defined(_WIN32) || defined(__CYGWIN__)
-#if defined(example_exe_EXPORTS)
-#define EXAMPLE_EXPORT __declspec(dllexport)
+# if defined(example_exe_EXPORTS)
+# define EXAMPLE_EXPORT __declspec(dllexport)
+# else
+# define EXAMPLE_EXPORT __declspec(dllimport)
+# endif
#else
-#define EXAMPLE_EXPORT __declspec(dllimport)
-#endif
-#else
-#define EXAMPLE_EXPORT
+# define EXAMPLE_EXPORT
#endif
#ifdef __cplusplus
diff --git a/Tests/Plugin/src/example_exe.cxx b/Tests/Plugin/src/example_exe.cxx
index 017fbf607..257a35ca5 100644
--- a/Tests/Plugin/src/example_exe.cxx
+++ b/Tests/Plugin/src/example_exe.cxx
@@ -17,9 +17,9 @@ extern "C" int example_exe_function()
}
#ifdef CMAKE_INTDIR
-#define CONFIG_DIR "/" CMAKE_INTDIR
+# define CONFIG_DIR "/" CMAKE_INTDIR
#else
-#define CONFIG_DIR ""
+# define CONFIG_DIR ""
#endif
int main()
diff --git a/Tests/Plugin/src/example_mod_1.c b/Tests/Plugin/src/example_mod_1.c
index a5dd9840d..87b559d2f 100644
--- a/Tests/Plugin/src/example_mod_1.c
+++ b/Tests/Plugin/src/example_mod_1.c
@@ -3,15 +3,15 @@
#include <stdio.h>
#if defined(_WIN32)
-#define MODULE_EXPORT __declspec(dllexport)
+# define MODULE_EXPORT __declspec(dllexport)
#else
-#define MODULE_EXPORT
+# define MODULE_EXPORT
#endif
#ifdef __WATCOMC__
-#define MODULE_CCONV __cdecl
+# define MODULE_CCONV __cdecl
#else
-#define MODULE_CCONV
+# define MODULE_CCONV
#endif
MODULE_EXPORT int MODULE_CCONV example_mod_1_function(int n)
diff --git a/Tests/PolicyScope/CMakeLists.txt b/Tests/PolicyScope/CMakeLists.txt
index 413195a5c..353842bc4 100644
--- a/Tests/PolicyScope/CMakeLists.txt
+++ b/Tests/PolicyScope/CMakeLists.txt
@@ -52,6 +52,10 @@ if(1)
# CMP0002 should be changed when this function is invoked
cmake_policy(GET CMP0002 cmp)
check(CMP0002 "OLD" "${cmp}")
+
+ # The undocumented PARENT_SCOPE option sees the caller's setting.
+ cmake_policy(GET CMP0002 cmp PARENT_SCOPE)
+ check(CMP0002 "NEW" "${cmp}")
endfunction()
# Unset CMP0002
@@ -61,6 +65,10 @@ if(1)
cmake_policy(GET CMP0002 cmp)
check(CMP0002 "" "${cmp}")
+ # The undocumented PARENT_SCOPE option sees the caller's setting.
+ cmake_policy(GET CMP0002 cmp PARENT_SCOPE)
+ check(CMP0002 "NEW" "${cmp}")
+
# Setting the policy should work here and also in the caller.
cmake_policy(SET CMP0002 OLD)
cmake_policy(GET CMP0002 cmp)
diff --git a/Tests/PrecompiledHeader/CMakeLists.txt b/Tests/PrecompiledHeader/CMakeLists.txt
index a80453892..58f4863b4 100644
--- a/Tests/PrecompiledHeader/CMakeLists.txt
+++ b/Tests/PrecompiledHeader/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 2.6)
+cmake_minimum_required (VERSION 3.9)
project(PrecompiledHeader C)
# Make sure the proper compiler is in use.
@@ -7,7 +7,8 @@ if(NOT MSVC AND NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
endif()
# Compute a custom name for the precompiled header.
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
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})
diff --git a/Tests/PrecompiledHeader/foo1.c b/Tests/PrecompiledHeader/foo1.c
index 77172bae7..fef258612 100644
--- a/Tests/PrecompiledHeader/foo1.c
+++ b/Tests/PrecompiledHeader/foo1.c
@@ -1,5 +1,5 @@
#ifndef foo_h
-#error "Precompiled header foo_precompiled.h has not been loaded."
+# error "Precompiled header foo_precompiled.h has not been loaded."
#endif
int main()
diff --git a/Tests/PrecompiledHeader/foo2.c b/Tests/PrecompiledHeader/foo2.c
index f192e1615..3ed04ed99 100644
--- a/Tests/PrecompiledHeader/foo2.c
+++ b/Tests/PrecompiledHeader/foo2.c
@@ -1,6 +1,6 @@
#ifndef foo_h
-#include "foo.h"
-#error "Precompiled header foo_precompiled.h has not been loaded."
+# include "foo.h"
+# error "Precompiled header foo_precompiled.h has not been loaded."
#endif
int foo()
diff --git a/Tests/Preprocess/CMakeLists.txt b/Tests/Preprocess/CMakeLists.txt
index 8c2cdc9e7..588af0320 100644
--- a/Tests/Preprocess/CMakeLists.txt
+++ b/Tests/Preprocess/CMakeLists.txt
@@ -28,6 +28,11 @@ endif()
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
set(PP_VS 1)
endif()
+if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
+ "x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC" AND
+ "x${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
+ set(CLANG_GNULIKE_WINDOWS 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
@@ -53,7 +58,7 @@ endif()
string(APPEND STRING_EXTRA " ")
-if(NOT PP_BORLAND AND NOT PP_WATCOM)
+if(NOT PP_BORLAND AND NOT PP_WATCOM AND NOT CLANG_GNULIKE_WINDOWS)
# 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
@@ -70,14 +75,14 @@ if(NOT PP_VS)
string(APPEND STRING_EXTRA ",")
endif()
-if(NOT PP_MINGW)
+if(NOT PP_MINGW AND NOT CLANG_GNULIKE_WINDOWS)
# MinGW: &
# When inside -D"FOO=\"a & b\"" MinGW make wants -D"FOO=\"a "&" b\""
# but it does not like quoted ampersand elsewhere.
string(APPEND STRING_EXTRA "&")
endif()
-if(NOT PP_MINGW)
+if(NOT PP_MINGW AND NOT CLANG_GNULIKE_WINDOWS)
# MinGW: |
# When inside -D"FOO=\"a | b\"" MinGW make wants -D"FOO=\"a "|" b\""
# but it does not like quoted pipe elsewhere.
@@ -100,7 +105,8 @@ endif()
set(EXPR_OP1 "/")
if((NOT MSVC OR PP_NMAKE) AND
- NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
+ NOT CMAKE_C_COMPILER_ID STREQUAL "Intel" AND
+ NOT CLANG_GNULIKE_WINDOWS)
# 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
diff --git a/Tests/Preprocess/preprocess.c b/Tests/Preprocess/preprocess.c
index 1b038b0c5..958c77ebc 100644
--- a/Tests/Preprocess/preprocess.c
+++ b/Tests/Preprocess/preprocess.c
@@ -10,7 +10,8 @@ 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);
+ fprintf(stderr, "FILE_STRING has wrong value in C [%s] vs [%s]\n",
+ FILE_STRING, STRING_VALUE);
result = 0;
}
if (strcmp(TARGET_STRING, STRING_VALUE) != 0) {
@@ -33,117 +34,117 @@ int check_defines_C(void)
}
}
#ifdef NDEBUG
-#ifdef FILE_DEF_DEBUG
+# ifdef FILE_DEF_DEBUG
{
fprintf(stderr, "FILE_DEF_DEBUG should not be defined in C\n");
result = 0;
}
-#endif
-#ifdef TARGET_DEF_DEBUG
+# endif
+# ifdef TARGET_DEF_DEBUG
{
fprintf(stderr, "TARGET_DEF_DEBUG should not be defined in C\n");
result = 0;
}
-#endif
-#ifdef DIRECTORY_DEF_DEBUG
+# 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
+# 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
+# endif
+# endif
+# ifndef TARGET_DEF_RELEASE
{
fprintf(stderr, "TARGET_DEF_RELEASE should be defined in C\n");
result = 0;
}
-#endif
-#ifndef DIRECTORY_DEF_RELEASE
+# endif
+# ifndef DIRECTORY_DEF_RELEASE
{
fprintf(stderr, "DIRECTORY_DEF_RELEASE should be defined in C\n");
result = 0;
}
-#endif
+# endif
#endif
#ifdef PREPROCESS_DEBUG
-#ifndef FILE_DEF_DEBUG
-#ifndef PREPROCESS_XCODE
+# 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
+# endif
+# endif
+# ifndef TARGET_DEF_DEBUG
{
fprintf(stderr, "TARGET_DEF_DEBUG should be defined in C\n");
result = 0;
}
-#endif
-#ifndef DIRECTORY_DEF_DEBUG
+# endif
+# ifndef DIRECTORY_DEF_DEBUG
{
fprintf(stderr, "DIRECTORY_DEF_DEBUG should be defined in C\n");
result = 0;
}
-#endif
-#ifdef FILE_DEF_RELEASE
+# endif
+# ifdef FILE_DEF_RELEASE
{
fprintf(stderr, "FILE_DEF_RELEASE should not be defined in C\n");
result = 0;
}
-#endif
-#ifdef TARGET_DEF_RELEASE
+# endif
+# ifdef TARGET_DEF_RELEASE
{
fprintf(stderr, "TARGET_DEF_RELEASE should not be defined in C\n");
result = 0;
}
-#endif
-#ifdef DIRECTORY_DEF_RELEASE
+# endif
+# ifdef DIRECTORY_DEF_RELEASE
{
fprintf(stderr, "DIRECTORY_DEF_RELEASE should not be defined in C\n");
result = 0;
}
-#endif
+# endif
#endif
#if defined(FILE_DEF_DEBUG) || defined(TARGET_DEF_DEBUG)
-#if !defined(FILE_DEF_DEBUG) || !defined(TARGET_DEF_DEBUG)
-#ifndef PREPROCESS_XCODE
+# 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)
+# 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
#endif
#if defined(FILE_DEF_RELEASE) || defined(TARGET_DEF_RELEASE)
-#if !defined(FILE_DEF_RELEASE) || !defined(TARGET_DEF_RELEASE)
-#ifndef PREPROCESS_XCODE
+# 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)
+# 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
#endif
#ifndef FILE_PATH_DEF
{
diff --git a/Tests/Preprocess/preprocess.cxx b/Tests/Preprocess/preprocess.cxx
index 0fab78525..34a69c6c6 100644
--- a/Tests/Preprocess/preprocess.cxx
+++ b/Tests/Preprocess/preprocess.cxx
@@ -35,118 +35,118 @@ int check_defines_CXX()
}
}
#ifdef NDEBUG
-#ifdef FILE_DEF_DEBUG
+# ifdef FILE_DEF_DEBUG
{
fprintf(stderr, "FILE_DEF_DEBUG should not be defined in CXX\n");
result = 0;
}
-#endif
-#ifdef TARGET_DEF_DEBUG
+# endif
+# ifdef TARGET_DEF_DEBUG
{
fprintf(stderr, "TARGET_DEF_DEBUG should not be defined in CXX\n");
result = 0;
}
-#endif
-#ifdef DIRECTORY_DEF_DEBUG
+# 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
+# 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
+# endif
+# endif
+# ifndef TARGET_DEF_RELEASE
{
fprintf(stderr, "TARGET_DEF_RELEASE should be defined in CXX\n");
result = 0;
}
-#endif
-#ifndef DIRECTORY_DEF_RELEASE
+# endif
+# ifndef DIRECTORY_DEF_RELEASE
{
fprintf(stderr, "DIRECTORY_DEF_RELEASE should be defined in CXX\n");
result = 0;
}
-#endif
+# endif
#endif
#ifdef PREPROCESS_DEBUG
-#ifndef FILE_DEF_DEBUG
-#ifndef PREPROCESS_XCODE
+# 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
+# endif
+# endif
+# ifndef TARGET_DEF_DEBUG
{
fprintf(stderr, "TARGET_DEF_DEBUG should be defined in CXX\n");
result = 0;
}
-#endif
-#ifndef DIRECTORY_DEF_DEBUG
+# endif
+# ifndef DIRECTORY_DEF_DEBUG
{
fprintf(stderr, "DIRECTORY_DEF_DEBUG should be defined in CXX\n");
result = 0;
}
-#endif
-#ifdef FILE_DEF_RELEASE
+# endif
+# ifdef FILE_DEF_RELEASE
{
fprintf(stderr, "FILE_DEF_RELEASE should not be defined in CXX\n");
result = 0;
}
-#endif
-#ifdef TARGET_DEF_RELEASE
+# endif
+# ifdef TARGET_DEF_RELEASE
{
fprintf(stderr, "TARGET_DEF_RELEASE should not be defined in CXX\n");
result = 0;
}
-#endif
-#ifdef DIRECTORY_DEF_RELEASE
+# endif
+# ifdef DIRECTORY_DEF_RELEASE
{
fprintf(stderr, "DIRECTORY_DEF_RELEASE should not be defined in CXX\n");
result = 0;
}
-#endif
+# endif
#endif
#if defined(FILE_DEF_DEBUG) || defined(TARGET_DEF_DEBUG)
-#if !defined(FILE_DEF_DEBUG) || !defined(TARGET_DEF_DEBUG)
-#ifndef PREPROCESS_XCODE
+# 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)
+# 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
#endif
#if defined(FILE_DEF_RELEASE) || defined(TARGET_DEF_RELEASE)
-#if !defined(FILE_DEF_RELEASE) || !defined(TARGET_DEF_RELEASE)
-#ifndef PREPROCESS_XCODE
+# 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)
+# 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
#endif
#ifndef FILE_PATH_DEF
{
diff --git a/Tests/Properties/CMakeLists.txt b/Tests/Properties/CMakeLists.txt
index 11fca45b0..a26306122 100644
--- a/Tests/Properties/CMakeLists.txt
+++ b/Tests/Properties/CMakeLists.txt
@@ -11,7 +11,7 @@ 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)
+# accessed without an extension (also yuck)
set_source_files_properties(properties2 PROPERTIES TEST2 1)
get_source_file_property(RESULT2 properties2 TEST2)
diff --git a/Tests/Properties/subdirtest.cxx b/Tests/Properties/subdirtest.cxx
index 02d8f3d3f..23f1048ec 100644
--- a/Tests/Properties/subdirtest.cxx
+++ b/Tests/Properties/subdirtest.cxx
@@ -1,6 +1,6 @@
#ifndef SUBDIR_TEST
-#error Expected SUBDIR_TEST
+# error Expected SUBDIR_TEST
#endif
int main(int, char**)
diff --git a/Tests/Qt4Deploy/CMakeLists.txt b/Tests/Qt4Deploy/CMakeLists.txt
index 646ea9f3b..c73a38c0f 100644
--- a/Tests/Qt4Deploy/CMakeLists.txt
+++ b/Tests/Qt4Deploy/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.9)
project(Qt4Deploy)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install)
@@ -10,7 +10,8 @@ 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)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig 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 "
@@ -58,7 +59,7 @@ if(QT_QSQLITE_PLUGIN_DEBUG OR QT_QSQLITE_PLUGIN_RELEASE)
endif()
# custom target to install and test the installation at build time
- if(CMAKE_CONFIGURATION_TYPES)
+ if(_isMultiConfig)
set(install_config "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_CFG_INTDIR}")
endif()
diff --git a/Tests/Qt4Targets/CMakeLists.txt b/Tests/Qt4Targets/CMakeLists.txt
index ae0a02bb6..2ca11e40b 100644
--- a/Tests/Qt4Targets/CMakeLists.txt
+++ b/Tests/Qt4Targets/CMakeLists.txt
@@ -20,6 +20,16 @@ if (WIN32)
endif()
endif()
+# Qt4 moc does not support utf8 paths in _parameter files generated by
+# qt4_wrap_cpp and qt4_generate_moc
+# https://bugreports.qt.io/browse/QTBUG-35480
+# Do a simple check if there is are non ASCII character in the build path
+string(REGEX MATCH "[^ -~]+" NON_ASCII_BDIR ${CMAKE_CURRENT_BINARY_DIR})
+if(NON_ASCII_BDIR)
+ message(WARNING "Build path contains non ASCII characters. Skipping Qt4 test.")
+ return()
+endif()
+
qt4_generate_moc(main_gen_test.cpp
"${CMAKE_CURRENT_BINARY_DIR}/main_gen_test.moc"
TARGET Qt4GenerateMacroTest
diff --git a/Tests/Qt4Targets/activeqtexe.cpp b/Tests/Qt4Targets/activeqtexe.cpp
index f17b0a639..98176f1de 100644
--- a/Tests/Qt4Targets/activeqtexe.cpp
+++ b/Tests/Qt4Targets/activeqtexe.cpp
@@ -2,7 +2,7 @@
#include <QApplication>
#ifndef QT_QAXSERVER_LIB
-#error Expected QT_QAXSERVER_LIB
+# error Expected QT_QAXSERVER_LIB
#endif
#include <QAxFactory>
diff --git a/Tests/Qt4Targets/main.cpp b/Tests/Qt4Targets/main.cpp
index 07443b0c4..f8eacdcdc 100644
--- a/Tests/Qt4Targets/main.cpp
+++ b/Tests/Qt4Targets/main.cpp
@@ -5,11 +5,11 @@
#include <QString>
#ifndef QT_CORE_LIB
-#error Expected QT_CORE_LIB
+# error Expected QT_CORE_LIB
#endif
#ifndef QT_GUI_LIB
-#error Expected QT_GUI_LIB
+# error Expected QT_GUI_LIB
#endif
int main(int argc, char** argv)
diff --git a/Tests/Qt4Targets/main_gen_test.cpp b/Tests/Qt4Targets/main_gen_test.cpp
index 1ea390bcf..6616e844c 100644
--- a/Tests/Qt4Targets/main_gen_test.cpp
+++ b/Tests/Qt4Targets/main_gen_test.cpp
@@ -3,7 +3,9 @@
#include "myinterface.h"
-class MyObject : public QObject, MyInterface
+class MyObject
+ : public QObject
+ , MyInterface
{
Q_OBJECT
Q_INTERFACES(MyInterface)
diff --git a/Tests/Qt4Targets/mywrapobject.h b/Tests/Qt4Targets/mywrapobject.h
index 5d4e52aec..231a1fe8b 100644
--- a/Tests/Qt4Targets/mywrapobject.h
+++ b/Tests/Qt4Targets/mywrapobject.h
@@ -6,7 +6,9 @@
#include "myinterface.h"
-class MyWrapObject : public QObject, MyInterface
+class MyWrapObject
+ : public QObject
+ , MyInterface
{
Q_OBJECT
Q_INTERFACES(MyInterface)
diff --git a/Tests/RunCMake/Android/RunCMakeTest.cmake b/Tests/RunCMake/Android/RunCMakeTest.cmake
index 86a989623..45798ce59 100644
--- a/Tests/RunCMake/Android/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Android/RunCMakeTest.cmake
@@ -61,8 +61,12 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK)
list(APPEND _abis_${_version} ${_abis})
endif()
endforeach()
- set(_abis_ ${_abis_${_latest_gcc}})
set(_abis_clang ${_abis_${_latest_clang}})
+ if(_latest_gcc)
+ set(_abis_ ${_abis_${_latest_gcc}})
+ else()
+ set(_abis_ ${_abis_clang})
+ endif()
if(_versions MATCHES "clang")
set(_versions "clang" ${_versions})
endif()
@@ -88,12 +92,14 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK)
-DCMAKE_ANDROID_ARM_MODE=0
)
run_cmake(ndk-badarm)
- set(RunCMake_TEST_OPTIONS
- -DCMAKE_SYSTEM_NAME=Android
- -DCMAKE_ANDROID_NDK=${ndk}
- -DCMAKE_ANDROID_ARM_NEON=0
- )
- run_cmake(ndk-badneon)
+ if("armeabi" IN_LIST _abis_)
+ set(RunCMake_TEST_OPTIONS
+ -DCMAKE_SYSTEM_NAME=Android
+ -DCMAKE_ANDROID_NDK=${ndk}
+ -DCMAKE_ANDROID_ARM_NEON=0
+ )
+ run_cmake(ndk-badneon)
+ endif()
set(RunCMake_TEST_OPTIONS
-DCMAKE_SYSTEM_NAME=Android
-DCMAKE_ANDROID_NDK=${ndk}
@@ -130,10 +136,11 @@ foreach(ndk IN LISTS TEST_ANDROID_NDK)
set(stl_types
none
system
- gnustl_static
- gnustl_shared
)
+ if(IS_DIRECTORY "${ndk}/sources/cxx-stl/gnu-libstdc++")
+ list(APPEND stl_types gnustl_static gnustl_shared)
+ endif()
if(IS_DIRECTORY "${ndk}/sources/cxx-stl/gabi++/libs")
list(APPEND stl_types gabi++_static gabi++_shared)
endif()
diff --git a/Tests/RunCMake/Android/android.cxx b/Tests/RunCMake/Android/android.cxx
index 2dee8f9bd..a6d8c551d 100644
--- a/Tests/RunCMake/Android/android.cxx
+++ b/Tests/RunCMake/Android/android.cxx
@@ -1,19 +1,19 @@
#include "android.h"
#ifndef STL_NONE
-#include <cmath>
-#include <cstdio>
-#ifndef STL_SYSTEM
-#include <exception>
-#include <typeinfo>
-#ifndef STL_STLPORT
-#include <cxxabi.h>
-#endif
-#ifndef STL_GABI
-#include <iostream>
-#include <string>
-#endif
-#endif
+# include <cmath>
+# include <cstdio>
+# ifndef STL_SYSTEM
+# include <exception>
+# include <typeinfo>
+# ifndef STL_STLPORT
+# include <cxxabi.h>
+# endif
+# ifndef STL_GABI
+# include <iostream>
+# include <string>
+# endif
+# endif
#endif
int main()
@@ -30,19 +30,19 @@ int main()
try {
delete (new int);
} catch (std::exception const& e) {
-#if defined(STL_GABI)
+# if defined(STL_GABI)
e.what();
typeid(e).name();
-#else
+# else
std::cerr << e.what() << std::endl;
std::cerr << typeid(e).name() << std::endl;
-#endif
+# endif
}
-#if defined(STL_GABI)
+# if defined(STL_GABI)
return 0;
-#else
+# else
std::string s;
return static_cast<int>(s.size());
-#endif
+# endif
#endif
}
diff --git a/Tests/RunCMake/Android/android.h b/Tests/RunCMake/Android/android.h
index a5fd67e58..2c5cd9590 100644
--- a/Tests/RunCMake/Android/android.h
+++ b/Tests/RunCMake/Android/android.h
@@ -1,103 +1,103 @@
#ifndef __ANDROID__
-#error "__ANDROID__ not defined"
+# error "__ANDROID__ not defined"
#endif
#include <android/api-level.h>
#if API_LEVEL != __ANDROID_API__
-#error "API levels do not match"
+# error "API levels do not match"
#endif
#ifdef COMPILER_IS_CLANG
-#ifndef __clang__
-#error "COMPILER_IS_CLANG but __clang__ is not defined"
-#endif
+# ifndef __clang__
+# error "COMPILER_IS_CLANG but __clang__ is not defined"
+# endif
#else
-#ifdef __clang__
-#error "!COMPILER_IS_CLANG but __clang__ is defined"
-#endif
+# ifdef __clang__
+# error "!COMPILER_IS_CLANG but __clang__ is defined"
+# endif
#endif
#ifdef ARM_MODE
-#if ARM_MODE == 1 && defined(__thumb__)
-#error "ARM_MODE==1 but __thumb__ is defined"
-#elif ARM_MODE == 0 && !defined(__thumb__)
-#error "ARM_MODE==0 but __thumb__ is not defined"
-#endif
+# if ARM_MODE == 1 && defined(__thumb__)
+# error "ARM_MODE==1 but __thumb__ is defined"
+# elif ARM_MODE == 0 && !defined(__thumb__)
+# error "ARM_MODE==0 but __thumb__ is not defined"
+# endif
#endif
#ifdef ARM_NEON
-#if ARM_NEON == 0 && defined(__ARM_NEON__)
-#error "ARM_NEON==0 but __ARM_NEON__ is defined"
-#elif ARM_NEON == 1 && !defined(__ARM_NEON__)
-#error "ARM_NEON==1 but __ARM_NEON__ is not defined"
-#endif
+# if ARM_NEON == 0 && defined(__ARM_NEON__)
+# error "ARM_NEON==0 but __ARM_NEON__ is defined"
+# elif ARM_NEON == 1 && !defined(__ARM_NEON__)
+# error "ARM_NEON==1 but __ARM_NEON__ is not defined"
+# endif
#endif
#ifdef ABI_armeabi
-#ifndef __ARM_EABI__
-#error "ABI_armeabi: __ARM_EABI__ not defined"
-#endif
-#if __ARM_ARCH != 5
-#error "ABI_armeabi: __ARM_ARCH is not 5"
-#endif
+# ifndef __ARM_EABI__
+# error "ABI_armeabi: __ARM_EABI__ not defined"
+# endif
+# if __ARM_ARCH != 5
+# error "ABI_armeabi: __ARM_ARCH is not 5"
+# endif
#endif
#ifdef ABI_armeabi_v6
-#ifndef __ARM_EABI__
-#error "ABI_armeabi_v6: __ARM_EABI__ not defined"
-#endif
-#if __ARM_ARCH != 6
-#error "ABI_armeabi_v6: __ARM_ARCH is not 6"
-#endif
+# ifndef __ARM_EABI__
+# error "ABI_armeabi_v6: __ARM_EABI__ not defined"
+# endif
+# if __ARM_ARCH != 6
+# error "ABI_armeabi_v6: __ARM_ARCH is not 6"
+# endif
#endif
#ifdef ABI_armeabi_v7a
-#ifndef __ARM_EABI__
-#error "ABI_armeabi_v7a: __ARM_EABI__ not defined"
-#endif
-#if __ARM_ARCH != 7
-#error "ABI_armeabi_v7a: __ARM_ARCH is not 7"
-#endif
+# ifndef __ARM_EABI__
+# error "ABI_armeabi_v7a: __ARM_EABI__ not defined"
+# endif
+# if __ARM_ARCH != 7
+# error "ABI_armeabi_v7a: __ARM_ARCH is not 7"
+# endif
#endif
#ifdef ABI_arm64_v8a
-#ifdef __ARM_EABI__
-#error "ABI_arm64_v8a: __ARM_EABI__ defined"
-#endif
-#ifndef __aarch64__
-#error "ABI_arm64_v8a: __aarch64__ not defined"
-#endif
+# ifdef __ARM_EABI__
+# error "ABI_arm64_v8a: __ARM_EABI__ defined"
+# endif
+# ifndef __aarch64__
+# error "ABI_arm64_v8a: __aarch64__ not defined"
+# endif
#endif
#ifdef ABI_mips
-#if __mips != 32
-#error "ABI_mips: __mips != 32"
-#endif
-#ifndef _ABIO32
-#error "ABI_mips: _ABIO32 not defined"
-#endif
+# if __mips != 32
+# error "ABI_mips: __mips != 32"
+# endif
+# ifndef _ABIO32
+# error "ABI_mips: _ABIO32 not defined"
+# endif
#endif
#ifdef ABI_mips64
-#if __mips != 64
-#error "ABI_mips64: __mips != 64"
-#endif
-#ifndef _ABI64
-#error "ABI_mips: _ABI64 not defined"
-#endif
+# if __mips != 64
+# error "ABI_mips64: __mips != 64"
+# endif
+# ifndef _ABI64
+# error "ABI_mips: _ABI64 not defined"
+# endif
#endif
#ifdef ABI_x86
-#ifndef __i686__
-#error "ABI_x86: __i686__ not defined"
-#endif
+# ifndef __i686__
+# error "ABI_x86: __i686__ not defined"
+# endif
#endif
#ifdef ABI_x86_64
-#ifndef __x86_64__
-#error "ABI_x86_64: __x86_64__ not defined"
-#endif
+# ifndef __x86_64__
+# error "ABI_x86_64: __x86_64__ not defined"
+# endif
#endif
#include <stddef.h>
diff --git a/Tests/RunCMake/Android/android_sysinc.c b/Tests/RunCMake/Android/android_sysinc.c
index 18d73dbc8..f7cc6f026 100644
--- a/Tests/RunCMake/Android/android_sysinc.c
+++ b/Tests/RunCMake/Android/android_sysinc.c
@@ -1,7 +1,7 @@
#include <dlfcn.h>
#ifndef NOT_SYSTEM_DLFCN_HEADER
-#error "sysroot /usr/include appears too early"
+# error "sysroot /usr/include appears too early"
#endif
#include "android.c"
diff --git a/Tests/RunCMake/Android/android_sysinc.cxx b/Tests/RunCMake/Android/android_sysinc.cxx
index 5c5694b8d..9379f1453 100644
--- a/Tests/RunCMake/Android/android_sysinc.cxx
+++ b/Tests/RunCMake/Android/android_sysinc.cxx
@@ -1,7 +1,7 @@
#include <dlfcn.h>
#ifndef NOT_SYSTEM_DLFCN_HEADER
-#error "sysroot /usr/include appears too early"
+# error "sysroot /usr/include appears too early"
#endif
#include "android.cxx"
diff --git a/Tests/RunCMake/Android/common.cmake b/Tests/RunCMake/Android/common.cmake
index 015f2029e..aaa7c8919 100644
--- a/Tests/RunCMake/Android/common.cmake
+++ b/Tests/RunCMake/Android/common.cmake
@@ -8,7 +8,6 @@ endif()
foreach(f
"${CMAKE_C_ANDROID_TOOLCHAIN_PREFIX}gcc${CMAKE_C_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}g++${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
- "${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}cpp${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ar${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
"${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}ld${CMAKE_CXX_ANDROID_TOOLCHAIN_SUFFIX}"
)
@@ -61,10 +60,12 @@ execute_process(
if(NOT _res EQUAL 0)
message(SEND_ERROR "Failed to run 'gcc -dumpmachine':\n ${_res}")
endif()
-if(NOT _out STREQUAL "${CMAKE_C_ANDROID_TOOLCHAIN_MACHINE}")
+string(REPLACE "--" "-" _out_check "${_out}")
+if(NOT _out_check STREQUAL "${CMAKE_C_ANDROID_TOOLCHAIN_MACHINE}"
+ AND NOT (_out STREQUAL "arm--linux-android" AND CMAKE_C_ANDROID_TOOLCHAIN_MACHINE STREQUAL "arm-linux-androideabi"))
message(SEND_ERROR "'gcc -dumpmachine' produced:\n"
" ${_out}\n"
- "which is not equal to CMAKE_C_ANDROID_TOOLCHAIN_MACHINE:\n"
+ "which does not match CMAKE_C_ANDROID_TOOLCHAIN_MACHINE:\n"
" ${CMAKE_C_ANDROID_TOOLCHAIN_MACHINE}"
)
endif()
@@ -92,6 +93,23 @@ if(CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
endif()
add_executable(android_c android.c)
add_executable(android_cxx android.cxx)
+add_library(android_cxx_lib SHARED android_lib.cxx)
+
+set(objdump "${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}objdump")
+if(NOT EXISTS "${objdump}")
+ message(FATAL_ERROR "Expected tool missing:\n ${objdump}")
+endif()
+
+if(NOT CMAKE_ANDROID_STL_TYPE MATCHES "^(system|stlport_static|stlport_shared)$")
+ foreach(tgt android_cxx android_cxx_lib)
+ add_custom_command(TARGET ${tgt} POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ -Dobjdump=${objdump}
+ -Dfile=$<TARGET_FILE:${tgt}>
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check_binary.cmake
+ )
+ endforeach()
+endif()
# Test that an explicit /usr/include is ignored in favor of
# appearing as a standard include directory at the end.
diff --git a/Tests/RunCMake/Android/ndk-badvernum-stderr.txt b/Tests/RunCMake/Android/ndk-badvernum-stderr.txt
index 25bbaf92c..adacaf160 100644
--- a/Tests/RunCMake/Android/ndk-badvernum-stderr.txt
+++ b/Tests/RunCMake/Android/ndk-badvernum-stderr.txt
@@ -1,5 +1,5 @@
^CMake Error at .*/Modules/Platform/Android/Determine-Compiler-NDK.cmake:[0-9]+ \(message\):
- Android: No toolchain for ABI 'armeabi' found in the NDK:
+ Android: No toolchain for ABI 'armeabi(-v7a)?' found in the NDK:
.*
diff --git a/Tests/RunCMake/AndroidMK/AndroidMK.cmake b/Tests/RunCMake/AndroidMK/AndroidMK.cmake
index 2596e8c30..9137f2be6 100644
--- a/Tests/RunCMake/AndroidMK/AndroidMK.cmake
+++ b/Tests/RunCMake/AndroidMK/AndroidMK.cmake
@@ -4,8 +4,10 @@ add_library(foo foo.cxx)
add_library(car foo.cxx)
add_library(bar bar.c)
add_library(dog foo.cxx)
-target_link_libraries(foo car bar dog debug -lm)
-export(TARGETS bar dog car foo ANDROID_MK
+target_link_libraries(foo PRIVATE car bar dog debug -lm)
+add_library(foo2 foo.cxx)
+target_link_options(foo2 INTERFACE -lm)
+export(TARGETS bar dog car foo foo2 ANDROID_MK
${build_BINARY_DIR}/Android.mk)
-install(TARGETS bar dog car foo DESTINATION lib EXPORT myexp)
+install(TARGETS bar dog car foo foo2 DESTINATION lib EXPORT myexp)
install(EXPORT_ANDROID_MK myexp DESTINATION share/ndk-modules)
diff --git a/Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt b/Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt
index bbf67a51c..a0e5044b1 100644
--- a/Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt
+++ b/Tests/RunCMake/AndroidMK/expectedBuildAndroidMK.txt
@@ -24,3 +24,11 @@ LOCAL_STATIC_LIBRARIES.*car bar dog
LOCAL_EXPORT_LDLIBS := -lm
LOCAL_HAS_CPP := true
include.*PREBUILT_STATIC_LIBRARY.*
+.*
+include.*CLEAR_VARS.*
+LOCAL_MODULE.*foo2
+LOCAL_SRC_FILES.*.*foo2.*
+LOCAL_CPP_FEATURES.*rtti exceptions
+LOCAL_EXPORT_LDFLAGS := -lm
+LOCAL_HAS_CPP := true
+include.*PREBUILT_STATIC_LIBRARY.*
diff --git a/Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt b/Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt
index 3515fb9e9..28b1c210e 100644
--- a/Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt
+++ b/Tests/RunCMake/AndroidMK/expectedInstallAndroidMK.txt
@@ -26,3 +26,11 @@ LOCAL_STATIC_LIBRARIES.*car bar dog
LOCAL_EXPORT_LDLIBS := -lm
LOCAL_HAS_CPP := true
include.*PREBUILT_STATIC_LIBRARY.*
+
+include.*CLEAR_VARS.*
+LOCAL_MODULE.*foo2
+LOCAL_SRC_FILES.*_IMPORT_PREFIX\)/lib.*foo2.*
+LOCAL_CPP_FEATURES.*rtti exceptions
+LOCAL_EXPORT_LDFLAGS := -lm
+LOCAL_HAS_CPP := true
+include.*PREBUILT_STATIC_LIBRARY.*
diff --git a/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake b/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake
index f268de721..27a609dcb 100644
--- a/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake
+++ b/Tests/RunCMake/AutoExportDll/RunCMakeTest.cmake
@@ -12,7 +12,7 @@ if("${RunCMake_GENERATOR}" MATCHES "Watcom WMake|Borland Makefiles")
endif()
# we build debug so the say.exe will be found in Debug/say.exe for
# Visual Studio generators
-if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode")
+if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(INTDIR "Debug/")
endif()
# build AutoExport
diff --git a/Tests/RunCMake/AutoExportDll/foo.c b/Tests/RunCMake/AutoExportDll/foo.c
index 4b1318b9e..d13bc3ede 100644
--- a/Tests/RunCMake/AutoExportDll/foo.c
+++ b/Tests/RunCMake/AutoExportDll/foo.c
@@ -1,7 +1,7 @@
#ifdef _MSC_VER
-#include "windows.h"
+# include "windows.h"
#else
-#define WINAPI
+# define WINAPI
#endif
int WINAPI foo()
diff --git a/Tests/RunCMake/AutoExportDll/hello.h b/Tests/RunCMake/AutoExportDll/hello.h
index 3749b976f..7192f65af 100644
--- a/Tests/RunCMake/AutoExportDll/hello.h
+++ b/Tests/RunCMake/AutoExportDll/hello.h
@@ -1,11 +1,11 @@
#ifndef _MSC_VER
-#define winexport
+# define winexport
#else
-#ifdef autoexport_EXPORTS
-#define winexport
-#else
-#define winexport __declspec(dllimport)
-#endif
+# ifdef autoexport_EXPORTS
+# define winexport
+# else
+# define winexport __declspec(dllimport)
+# endif
#endif
class Hello
diff --git a/Tests/RunCMake/AutoExportDll/say.cxx b/Tests/RunCMake/AutoExportDll/say.cxx
index 51060e8de..c8bfcc7bd 100644
--- a/Tests/RunCMake/AutoExportDll/say.cxx
+++ b/Tests/RunCMake/AutoExportDll/say.cxx
@@ -1,9 +1,9 @@
#include "hello.h"
#include <stdio.h>
#ifdef _MSC_VER
-#include "windows.h"
+# include "windows.h"
#else
-#define WINAPI
+# define WINAPI
#endif
extern "C" {
diff --git a/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake b/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake
index ef3301216..87b0de010 100644
--- a/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake
+++ b/Tests/RunCMake/BuildDepends/C-Exe-Manifest.cmake
@@ -11,7 +11,7 @@ endif()
]])
endif()
-file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
set(check_pairs
\"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/test.manifest\"
)
diff --git a/Tests/RunCMake/BuildDepends/C-Exe.cmake b/Tests/RunCMake/BuildDepends/C-Exe.cmake
index 5057ca91d..ad5cd4d47 100644
--- a/Tests/RunCMake/BuildDepends/C-Exe.cmake
+++ b/Tests/RunCMake/BuildDepends/C-Exe.cmake
@@ -2,7 +2,7 @@ enable_language(C)
add_executable(main ${CMAKE_CURRENT_BINARY_DIR}/main.c)
-file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
set(check_pairs
\"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/main.c\"
)
diff --git a/Tests/RunCMake/BuildDepends/Custom-Always.cmake b/Tests/RunCMake/BuildDepends/Custom-Always.cmake
index d412708a1..c7e7fb0bc 100644
--- a/Tests/RunCMake/BuildDepends/Custom-Always.cmake
+++ b/Tests/RunCMake/BuildDepends/Custom-Always.cmake
@@ -16,7 +16,7 @@ add_custom_command(
add_custom_target(drive ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/after-always)
-file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
set(check_pairs
\"${CMAKE_CURRENT_BINARY_DIR}/always-updated|${CMAKE_CURRENT_BINARY_DIR}/before-always\"
\"${CMAKE_CURRENT_BINARY_DIR}/after-always|${CMAKE_CURRENT_BINARY_DIR}/always-updated\"
diff --git a/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake b/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake
index 687c8271f..1e1f22ad0 100644
--- a/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake
+++ b/Tests/RunCMake/BuildDepends/Custom-Symbolic-and-Byproduct.cmake
@@ -16,7 +16,7 @@ add_custom_command(
add_custom_target(drive ALL DEPENDS use-byproduct)
add_dependencies(drive produce)
-file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
if (check_step EQUAL 1)
set(check_pairs
\"${CMAKE_CURRENT_BINARY_DIR}/use-byproduct|${CMAKE_CURRENT_BINARY_DIR}/gen-byproduct-stamp\"
diff --git a/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake b/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake
index 0f92e0edb..8b2ae78cf 100644
--- a/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake
+++ b/Tests/RunCMake/BuildDepends/MakeCustomIncludes.cmake
@@ -6,7 +6,7 @@ add_custom_command(
add_custom_target(generate ALL DEPENDS output.cxx)
set_property(TARGET generate PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})
-file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
set(check_pairs
\"${CMAKE_CURRENT_BINARY_DIR}/output.cxx|${CMAKE_CURRENT_BINARY_DIR}/MakeCustomIncludes.h\"
)
diff --git a/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake b/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake
index add9aeb69..af6ad86ba 100644
--- a/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake
+++ b/Tests/RunCMake/BuildDepends/MakeInProjectOnly.cmake
@@ -3,7 +3,7 @@ get_filename_component(include_dir "${CMAKE_BINARY_DIR}" PATH)
include_directories("${include_dir}")
add_executable(MakeInProjectOnly MakeInProjectOnly.c)
set(CMAKE_DEPENDS_IN_PROJECT_ONLY 1)
-file(GENERATE OUTPUT check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
if (check_step EQUAL 1)
set(check_pairs
\"$<TARGET_FILE:MakeInProjectOnly>|${include_dir}/MakeInProjectOnly.h\"
diff --git a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
index 9941c70df..14ae2439b 100644
--- a/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
+++ b/Tests/RunCMake/BuildDepends/RunCMakeTest.cmake
@@ -9,9 +9,11 @@ endif()
function(run_BuildDepends CASE)
# Use a single build tree for a few tests without cleaning.
- set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${CASE}-build)
+ if(NOT RunCMake_TEST_BINARY_DIR)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${CASE}-build)
+ endif()
set(RunCMake_TEST_NO_CLEAN 1)
- if(RunCMake_GENERATOR MATCHES "Make|Ninja")
+ if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@@ -32,7 +34,8 @@ endfunction()
run_BuildDepends(C-Exe)
if(NOT RunCMake_GENERATOR STREQUAL "Xcode")
- if(RunCMake_GENERATOR MATCHES "Visual Studio 10")
+ if(RunCMake_GENERATOR MATCHES "Visual Studio 10" OR
+ RunCMake_GENERATOR_TOOLSET MATCHES "^(v80|v90|v100)$")
# VS 10 forgets to re-link when a manifest changes
set(run_BuildDepends_skip_step_2 1)
endif()
@@ -43,6 +46,18 @@ endif()
run_BuildDepends(Custom-Symbolic-and-Byproduct)
run_BuildDepends(Custom-Always)
+# Test header dependencies with a build tree underneath a source tree.
+set(RunCMake_TEST_SOURCE_DIR "${RunCMake_BINARY_DIR}/BuildUnderSource")
+set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/BuildUnderSource/build")
+file(REMOVE_RECURSE "${RunCMake_TEST_SOURCE_DIR}")
+file(MAKE_DIRECTORY "${RunCMake_TEST_SOURCE_DIR}/include")
+foreach(f CMakeLists.txt BuildUnderSource.cmake BuildUnderSource.c)
+ configure_file("${RunCMake_SOURCE_DIR}/${f}" "${RunCMake_TEST_SOURCE_DIR}/${f}" COPYONLY)
+endforeach()
+run_BuildDepends(BuildUnderSource)
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_SOURCE_DIR)
+
if(RunCMake_GENERATOR MATCHES "Make")
run_BuildDepends(MakeCustomIncludes)
if(NOT "${RunCMake_BINARY_DIR}" STREQUAL "${RunCMake_SOURCE_DIR}")
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
index 05b021746..6a1f1bde4 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-NEW-stderr.txt
@@ -4,4 +4,4 @@ CMake Error at CMP0026-CONFIG-LOCATION-NEW.cmake:7 \(get_target_property\):
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt
index edeb33728..84dec3212 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-OLD-stderr.txt
@@ -7,4 +7,4 @@
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt
index d44dcb48d..d2209fdc8 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-CONFIG-LOCATION-WARN-stderr.txt
@@ -8,5 +8,5 @@ CMake Warning \(dev\) at CMP0026-CONFIG-LOCATION-WARN.cmake:5 \(get_target_prope
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
index fec9dfb4d..1490103d5 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-NEW-stderr.txt
@@ -4,4 +4,4 @@ CMake Error at CMP0026-LOCATION-CONFIG-NEW.cmake:7 \(get_target_property\):
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt
index 32ff698f1..1fb4ef679 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-OLD-stderr.txt
@@ -7,4 +7,4 @@
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt
index cd6f3d095..8b4faf011 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-LOCATION-CONFIG-WARN-stderr.txt
@@ -8,5 +8,5 @@ CMake Warning \(dev\) at CMP0026-LOCATION-CONFIG-WARN.cmake:5 \(get_target_prope
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
index fa025129f..8c47c2ab3 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-NEW-stderr.txt
@@ -4,4 +4,4 @@ CMake Error at CMP0026-NEW.cmake:7 \(get_target_property\):
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CMP0026/CMP0026-OLD-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-OLD-stderr.txt
index b3f79fc4d..b4282f545 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-OLD-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-OLD-stderr.txt
@@ -7,4 +7,4 @@
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt b/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt
index d122c4a2e..0d39596b4 100644
--- a/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt
+++ b/Tests/RunCMake/CMP0026/CMP0026-WARN-stderr.txt
@@ -8,7 +8,7 @@ CMake Warning \(dev\) at CMP0026-WARN.cmake:5 \(get_target_property\):
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
+
CMake Warning \(dev\) at CMP0026-WARN.cmake:8 \(get_target_property\):
@@ -21,5 +21,5 @@ CMake Warning \(dev\) at CMP0026-WARN.cmake:8 \(get_target_property\):
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0026/LOCATION-and-TARGET_OBJECTS-stderr.txt b/Tests/RunCMake/CMP0026/LOCATION-and-TARGET_OBJECTS-stderr.txt
index 0996cb6b4..63779219a 100644
--- a/Tests/RunCMake/CMP0026/LOCATION-and-TARGET_OBJECTS-stderr.txt
+++ b/Tests/RunCMake/CMP0026/LOCATION-and-TARGET_OBJECTS-stderr.txt
@@ -8,5 +8,5 @@ CMake Warning \(dev\) at LOCATION-and-TARGET_OBJECTS.cmake:[0-9]+ \(get_target_p
\$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt b/Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt
index 87d198d00..360d98765 100644
--- a/Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt
+++ b/Tests/RunCMake/CMP0026/ObjlibNotDefined-stderr.txt
@@ -8,5 +8,5 @@ CMake Warning \(dev\) at ObjlibNotDefined.cmake:[0-9]+ \(get_target_property\):
expression \$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0026/clear-cached-information-stderr.txt b/Tests/RunCMake/CMP0026/clear-cached-information-stderr.txt
index 157a0468a..3525704bb 100644
--- a/Tests/RunCMake/CMP0026/clear-cached-information-stderr.txt
+++ b/Tests/RunCMake/CMP0026/clear-cached-information-stderr.txt
@@ -7,4 +7,4 @@
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake
index f4c070d7a..fd56e7566 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-colon.cmake
@@ -1,4 +1,4 @@
-
+enable_language(CXX)
cmake_policy(SET CMP0037 NEW)
add_library("lib:colon" empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake
index e9f640469..83a711909 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-reserved.cmake
@@ -1,4 +1,4 @@
-
+enable_language(CXX)
cmake_policy(SET CMP0037 NEW)
add_library(all empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake
index 9227986e9..2a288cc99 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-space.cmake
@@ -1,4 +1,4 @@
-
+enable_language(CXX)
cmake_policy(SET CMP0037 NEW)
add_library("lib with spaces" empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake
index 870a28672..f52e4d2d0 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-reserved.cmake
@@ -1,4 +1,4 @@
-
+enable_language(CXX)
cmake_policy(SET CMP0037 OLD)
add_library(all empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake b/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake
index 46193a1fa..c9fb6c890 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-space.cmake
@@ -1,4 +1,4 @@
-
+enable_language(CXX)
cmake_policy(SET CMP0037 OLD)
add_library("lib with spaces" empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake
index 445e3b23e..1b1a405e8 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-colon.cmake
@@ -1,4 +1,4 @@
-
+enable_language(CXX)
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.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake
index e50a64dcf..e01b8e5ec 100644
--- a/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-space.cmake
@@ -1,4 +1,4 @@
-
+enable_language(CXX)
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
index f452db177..12cd3c775 100644
--- a/Tests/RunCMake/CMP0037/CMakeLists.txt
+++ b/Tests/RunCMake/CMP0037/CMakeLists.txt
@@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 2.8.4)
-project(${RunCMake_TEST} CXX)
+project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
index b7d8d7bb4..98274f08b 100644
--- a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
@@ -9,5 +9,22 @@ if(NOT (WIN32 AND "${RunCMake_GENERATOR}" MATCHES "Make"))
run_cmake(CMP0037-WARN-colon)
endif()
+run_cmake(CMP0037-WARN-reserved)
run_cmake(CMP0037-OLD-reserved)
run_cmake(CMP0037-NEW-reserved)
+
+run_cmake(NEW-cond)
+run_cmake(NEW-cond-test)
+run_cmake(NEW-cond-package)
+run_cmake(OLD-cond)
+run_cmake(OLD-cond-test)
+run_cmake(OLD-cond-package)
+run_cmake(WARN-cond)
+run_cmake(WARN-cond-test)
+run_cmake(WARN-cond-package)
+
+if(RunCMake_GENERATOR MATCHES "Make|Ninja")
+ run_cmake(NEW-cond-package_source)
+ run_cmake(OLD-cond-package_source)
+ run_cmake(WARN-cond-package_source)
+endif()
diff --git a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
index e3e3ff468..70ed05ba1 100644
--- a/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
+++ b/Tests/RunCMake/CMP0040/CMP0040-WARN-missing-target-stderr.txt
@@ -1,8 +1,8 @@
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.
+ add_custom_command\(\) must exist and must be defined in the current
+ directory. Run "cmake --help-policy CMP0040" for policy details. Use the
+ cmake_policy command to set the policy and suppress this warning.
+
No TARGET 'foobar' has been created in this directory.
Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt
index cc17f3371..e1c44e507 100644
--- a/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt
+++ b/Tests/RunCMake/CMP0051/CMP0051-OLD-stderr.txt
@@ -1 +1,12 @@
-^Sources: "empty.cpp"$
+^CMake Deprecation Warning at CMP0051-OLD.cmake:2 \(cmake_policy\):
+ The OLD behavior for policy CMP0051 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+Sources: "empty.cpp"$
diff --git a/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt b/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt
index ae2e46848..78c6b6d30 100644
--- a/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt
+++ b/Tests/RunCMake/CMP0051/CMP0051-WARN-stderr.txt
@@ -9,7 +9,7 @@ CMake Warning \(dev\) at CMP0051-WARN.cmake:6 \(get_target_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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
Sources: "empty.cpp"
@@ -25,7 +25,7 @@ CMake Warning \(dev\) at CMP0051-WARN.cmake:12 \(get_target_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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
Sources: "../empty.cpp"$
diff --git a/Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt b/Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt
index 836b0ffe9..2a0ddbaaf 100644
--- a/Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt
+++ b/Tests/RunCMake/CMP0053/CMP0053-OLD-stderr.txt
@@ -1,2 +1,13 @@
-^called
+^CMake Deprecation Warning at CMP0053-OLD.cmake:1 \(cmake_policy\):
+ The OLD behavior for policy CMP0053 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+called
--><--$
diff --git a/Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt
index f5a8fbe6e..0500280cd 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt
+++ b/Tests/RunCMake/CMP0054/CMP0054-OLD-stderr.txt
@@ -1 +1,10 @@
-$^
+^CMake Deprecation Warning at CMP0054-OLD.cmake:1 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt
index f5a8fbe6e..60303cd86 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt
+++ b/Tests/RunCMake/CMP0054/CMP0054-keywords-OLD-stderr.txt
@@ -1 +1,10 @@
-$^
+^CMake Deprecation Warning at CMP0054-keywords-OLD.cmake:1 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt
index f5a8fbe6e..1b354728d 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-command-scope-stderr.txt
@@ -1 +1,10 @@
-$^
+^CMake Deprecation Warning at CMP0054-policy-command-scope.cmake:25 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt
index f5a8fbe6e..4eac90eed 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-foreach-scope-stderr.txt
@@ -1 +1,54 @@
-$^
+^CMake Deprecation Warning at CMP0054-policy-foreach-scope.cmake:14 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-foreach-scope.cmake:14 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-foreach-scope.cmake:27 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-foreach-scope.cmake:48 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-foreach-scope.cmake:48 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt
index f5a8fbe6e..a2dd62e4a 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-nested-if-stderr.txt
@@ -1 +1,10 @@
-$^
+^CMake Deprecation Warning at CMP0054-policy-nested-if.cmake:23 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt b/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt
index f5a8fbe6e..718904d39 100644
--- a/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt
+++ b/Tests/RunCMake/CMP0054/CMP0054-policy-while-scope-stderr.txt
@@ -1 +1,54 @@
-$^
+^CMake Deprecation Warning at CMP0054-policy-while-scope.cmake:16 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-while-scope.cmake:16 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-while-scope.cmake:37 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-while-scope.cmake:58 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+CMake Deprecation Warning at CMP0054-policy-while-scope.cmake:58 \(cmake_policy\):
+ The OLD behavior for policy CMP0054 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/CMP0060/CMP0060-Common.cmake b/Tests/RunCMake/CMP0060/CMP0060-Common.cmake
index e0a56e68c..06955eeba 100644
--- a/Tests/RunCMake/CMP0060/CMP0060-Common.cmake
+++ b/Tests/RunCMake/CMP0060/CMP0060-Common.cmake
@@ -1,6 +1,7 @@
# Always build in a predictable configuration. For multi-config
# generators we depend on RunCMakeTest.cmake to do this for us.
-if(NOT CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(NOT _isMultiConfig)
set(CMAKE_BUILD_TYPE Debug)
endif()
diff --git a/Tests/RunCMake/CMP0060/CMP0060-WARN-ON-stderr.txt b/Tests/RunCMake/CMP0060/CMP0060-WARN-ON-stderr.txt
index f6cc97854..e2c280ee7 100644
--- a/Tests/RunCMake/CMP0060/CMP0060-WARN-ON-stderr.txt
+++ b/Tests/RunCMake/CMP0060/CMP0060-WARN-ON-stderr.txt
@@ -12,5 +12,5 @@
will ask the linker to search for these by library name.
Call Stack \(most recent call first\):
CMP0060-WARN-ON.cmake:[0-9]+ \(include\)
- CMakeLists.txt:3 \(include\)
+ CMakeLists.txt:4 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CMP0060/CMakeLists.txt b/Tests/RunCMake/CMP0060/CMakeLists.txt
index db6b701c0..291d34d43 100644
--- a/Tests/RunCMake/CMP0060/CMakeLists.txt
+++ b/Tests/RunCMake/CMP0060/CMakeLists.txt
@@ -1,3 +1,4 @@
-cmake_minimum_required(VERSION 3.2)
+cmake_minimum_required(VERSION 3.9)
+cmake_policy(VERSION 3.2)
project(${RunCMake_TEST} C)
include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/CMP0069/CMP0069-NEW-cmake-stderr.txt b/Tests/RunCMake/CMP0069/CMP0069-NEW-cmake-stderr.txt
index ddb3cae61..87ac88e62 100644
--- a/Tests/RunCMake/CMP0069/CMP0069-NEW-cmake-stderr.txt
+++ b/Tests/RunCMake/CMP0069/CMP0069-NEW-cmake-stderr.txt
@@ -1,4 +1,6 @@
^CMake Error at CMP0069-NEW-cmake\.cmake:[0-9]+ \(add_executable\):
CMake doesn't support IPO for current compiler
Call Stack \(most recent call first\):
- CMakeLists\.txt:[0-9]+ \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/CMP0069/CMP0069-NEW-compiler-stderr.txt b/Tests/RunCMake/CMP0069/CMP0069-NEW-compiler-stderr.txt
index 8decfab3c..cb9d19b47 100644
--- a/Tests/RunCMake/CMP0069/CMP0069-NEW-compiler-stderr.txt
+++ b/Tests/RunCMake/CMP0069/CMP0069-NEW-compiler-stderr.txt
@@ -1,4 +1,6 @@
^CMake Error at CMP0069-NEW-compiler\.cmake:[0-9]+ \(add_executable\):
Compiler doesn't support IPO
Call Stack \(most recent call first\):
- CMakeLists\.txt:[0-9]+ \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/CMP0069/CMP0069-NEW-generator-stderr.txt b/Tests/RunCMake/CMP0069/CMP0069-NEW-generator-stderr.txt
index 0e05ee783..1159ec043 100644
--- a/Tests/RunCMake/CMP0069/CMP0069-NEW-generator-stderr.txt
+++ b/Tests/RunCMake/CMP0069/CMP0069-NEW-generator-stderr.txt
@@ -1,4 +1,6 @@
^CMake Error at CMP0069-NEW-generator\.cmake:[0-9]+ \(add_executable\):
CMake doesn't support IPO for current generator
Call Stack \(most recent call first\):
- CMakeLists\.txt:[0-9]+ \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/CMP0069/RunCMakeTest.cmake b/Tests/RunCMake/CMP0069/RunCMakeTest.cmake
index f44f84002..456e6a656 100644
--- a/Tests/RunCMake/CMP0069/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMP0069/RunCMakeTest.cmake
@@ -5,6 +5,6 @@ run_cmake(CMP0069-NEW-cmake)
run_cmake(CMP0069-NEW-compiler)
run_cmake(CMP0069-WARN)
-if(RunCMake_GENERATOR MATCHES "^Visual Studio ")
+if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
run_cmake(CMP0069-NEW-generator)
endif()
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 79f487d41..69f816215 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -1,5 +1,8 @@
# See adjacent README.rst for documentation of this test infrastructure.
+# Note that the _isMultiConfig variable is set in the parent directory's
+# CMakeLists.txt (slightly complex logic to support CMake versions before 3.9)
+
macro(add_RunCMake_test test)
set(TEST_ARGS ${ARGN})
if ("${ARGV1}" STREQUAL "TEST_DIR")
@@ -14,7 +17,9 @@ macro(add_RunCMake_test test)
endif()
add_test(NAME RunCMake.${test} COMMAND ${CMAKE_CMAKE_COMMAND}
-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_SOURCE_DIR}
+ -DRunCMake_GENERATOR_IS_MULTI_CONFIG=${_isMultiConfig}
-DRunCMake_GENERATOR=${CMAKE_GENERATOR}
+ -DRunCMake_GENERATOR_INSTANCE=${CMAKE_GENERATOR_INSTANCE}
-DRunCMake_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DRunCMake_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-DRunCMake_MAKE_PROGRAM=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
@@ -37,7 +42,12 @@ function(add_RunCMake_test_group test types)
# much system information so it is easier to set programs and environment
# values here
unset(${test}_${type}_FOUND_PREREQUIREMENTS)
- include("${CMAKE_CURRENT_SOURCE_DIR}/${test}/${type}/Prerequirements.cmake")
+ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test}/${type}/Prerequirements.cmake")
+ include("${CMAKE_CURRENT_SOURCE_DIR}/${test}/${type}/Prerequirements.cmake")
+ else()
+ string(REGEX MATCH "^[^.]*" main_type "${type}")
+ include("${CMAKE_CURRENT_SOURCE_DIR}/${test}/${main_type}/Prerequirements.cmake")
+ endif()
get_test_prerequirements("${test}_${type}_FOUND_PREREQUIREMENTS"
"${TEST_CONFIG_DIR}/${type}_config.cmake")
@@ -46,7 +56,9 @@ function(add_RunCMake_test_group test types)
add_test(NAME RunCMake.${test}_${type} COMMAND ${CMAKE_CMAKE_COMMAND}
-DTEST_TYPE=${type}
-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_SOURCE_DIR}
+ -DRunCMake_GENERATOR_IS_MULTI_CONFIG=${_isMultiConfig}
-DRunCMake_GENERATOR=${CMAKE_GENERATOR}
+ -DRunCMake_GENERATOR_INSTANCE=${CMAKE_GENERATOR_INSTANCE}
-DRunCMake_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DRunCMake_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-DRunCMake_MAKE_PROGRAM=${CMake_TEST_EXPLICIT_MAKE_PROGRAM}
@@ -59,6 +71,9 @@ function(add_RunCMake_test_group test types)
endforeach()
endfunction()
+# Some tests use python for extra checks.
+find_package(PythonInterp QUIET)
+
if(XCODE_VERSION AND "${XCODE_VERSION}" VERSION_LESS 6.1)
set(Swift_ARGS -DXCODE_BELOW_6_1=1)
endif()
@@ -99,6 +114,7 @@ if(CMAKE_SYSTEM_NAME MATCHES Darwin AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
add_RunCMake_test(CMP0068)
endif()
add_RunCMake_test(CMP0069)
+add_RunCMake_test(CMP0081)
# The test for Policy 65 requires the use of the
# CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS variable, which both the VS and Xcode
@@ -107,13 +123,16 @@ if(NOT CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
add_RunCMake_test(CMP0065)
endif()
if(CMAKE_GENERATOR MATCHES "Make")
- add_RunCMake_test(Make)
+ add_RunCMake_test(Make -DMAKE_IS_GNU=${MAKE_IS_GNU})
endif()
if(CMAKE_GENERATOR STREQUAL "Ninja")
set(Ninja_ARGS
-DCMAKE_C_OUTPUT_EXTENSION=${CMAKE_C_OUTPUT_EXTENSION}
-DCMAKE_SHARED_LIBRARY_PREFIX=${CMAKE_SHARED_LIBRARY_PREFIX}
-DCMAKE_SHARED_LIBRARY_SUFFIX=${CMAKE_SHARED_LIBRARY_SUFFIX})
+ if(CMAKE_Fortran_COMPILER)
+ list(APPEND Ninja_ARGS -DTEST_Fortran=1)
+ endif()
add_RunCMake_test(Ninja)
endif()
add_RunCMake_test(CTest)
@@ -131,8 +150,20 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE)
endif()
add_RunCMake_test(AndroidTestUtilities)
+set(autogen_with_qt5 FALSE)
+if(CMake_TEST_Qt5)
+ find_package(Qt5Widgets QUIET NO_MODULE)
+endif()
+if(CMake_TEST_Qt5 AND Qt5Widgets_FOUND)
+ set(autogen_with_qt5 TRUE)
+endif ()
+add_RunCMake_test(Autogen -Dwith_qt5=${autogen_with_qt5})
add_RunCMake_test(BuildDepends)
if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
+ add_RunCMake_test(Byproducts)
+endif()
+add_RunCMake_test(CMakeRoleGlobalProperty)
+if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
add_RunCMake_test(CompilerChange)
endif()
add_RunCMake_test(CompilerNotFound)
@@ -141,21 +172,40 @@ add_RunCMake_test(DisallowedCommands)
add_RunCMake_test(ExternalData)
add_RunCMake_test(FeatureSummary)
add_RunCMake_test(FPHSA)
+add_RunCMake_test(FileAPI -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE})
+add_RunCMake_test(FindBoost)
+add_RunCMake_test(FindLua)
+add_RunCMake_test(FindOpenGL)
+if(CMake_TEST_UseSWIG)
+ add_RunCMake_test(UseSWIG -DCMake_TEST_FindPython=${CMake_TEST_FindPython})
+endif()
if(NOT CMAKE_C_COMPILER_ID MATCHES "Watcom")
add_RunCMake_test(GenerateExportHeader)
endif()
add_RunCMake_test(GeneratorExpression)
+add_RunCMake_test(GeneratorInstance)
add_RunCMake_test(GeneratorPlatform)
add_RunCMake_test(GeneratorToolset)
+add_RunCMake_test(GetPrerequisites)
add_RunCMake_test(GNUInstallDirs -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME})
+add_RunCMake_test(GoogleTest) # Note: does not actually depend on Google Test
add_RunCMake_test(TargetPropertyGeneratorExpressions)
add_RunCMake_test(Languages)
add_RunCMake_test(LinkStatic)
+if(CMAKE_CXX_COMPILER_ID MATCHES "^(Cray|PGI|XL|XLClang)$")
+ add_RunCMake_test(MetaCompileFeatures)
+endif()
+if(MSVC)
+ add_RunCMake_test(MSVCRuntimeLibrary)
+ add_RunCMake_test(MSVCWarningFlags)
+endif()
add_RunCMake_test(ObjectLibrary)
+add_RunCMake_test(ParseImplicitIncludeInfo)
if(UNIX AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG AND CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
add_RunCMake_test(RuntimePath)
endif()
-add_RunCMake_test(Swift)
+add_RunCMake_test(ScriptMode)
+add_RunCMake_test(Swift -DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER})
add_RunCMake_test(TargetObjects)
add_RunCMake_test(TargetSources)
add_RunCMake_test(ToolchainFile)
@@ -163,9 +213,12 @@ add_RunCMake_test(find_dependency)
add_RunCMake_test(CompileDefinitions)
add_RunCMake_test(CompileFeatures)
add_RunCMake_test(PolicyScope)
+add_RunCMake_test(WriteBasicConfigVersionFile)
add_RunCMake_test(WriteCompilerDetectionHeader)
+add_RunCMake_test(SourceProperties)
if(NOT WIN32)
- add_RunCMake_test(PositionIndependentCode)
+ add_RunCMake_test(PositionIndependentCode -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
+ -DCMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID})
endif()
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
add_RunCMake_test(VisibilityPreset)
@@ -175,14 +228,20 @@ if (QT4_FOUND)
endif()
add_RunCMake_test(CompatibleInterface)
add_RunCMake_test(Syntax)
+add_RunCMake_test(WorkingDirectory)
+add_RunCMake_test(MaxRecursionDepth)
add_RunCMake_test(add_custom_command)
add_RunCMake_test(add_custom_target)
add_RunCMake_test(add_dependencies)
+add_RunCMake_test(add_executable)
+add_RunCMake_test(add_library)
add_RunCMake_test(add_subdirectory)
add_RunCMake_test(build_command)
+add_executable(exit_code exit_code.c)
+set(execute_process_ARGS -DEXIT_CODE_EXE=$<TARGET_FILE:exit_code>)
if(NOT CMake_TEST_EXTERNAL_CMAKE)
- set(execute_process_ARGS -DTEST_ENCODING_EXE=$<TARGET_FILE:testEncoding>)
+ list(APPEND execute_process_ARGS -DTEST_ENCODING_EXE=$<TARGET_FILE:testEncoding>)
endif()
add_RunCMake_test(execute_process)
add_RunCMake_test(export)
@@ -200,6 +259,7 @@ add_RunCMake_test(ctest_submit)
add_RunCMake_test(ctest_test)
add_RunCMake_test(ctest_disabled_test)
add_RunCMake_test(ctest_skipped_test)
+add_RunCMake_test(ctest_update)
add_RunCMake_test(ctest_upload)
add_RunCMake_test(ctest_fixtures)
add_RunCMake_test(file)
@@ -208,33 +268,60 @@ add_RunCMake_test(find_library)
add_RunCMake_test(find_package)
add_RunCMake_test(find_path)
add_RunCMake_test(find_program -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
+add_RunCMake_test(foreach)
add_RunCMake_test(get_filename_component)
add_RunCMake_test(get_property)
add_RunCMake_test(if)
add_RunCMake_test(include)
add_RunCMake_test(include_directories)
+add_RunCMake_test(include_guard)
add_RunCMake_test(list)
+add_RunCMake_test(math)
add_RunCMake_test(message)
+add_RunCMake_test(option)
add_RunCMake_test(project -DCMake_TEST_RESOURCES=${CMake_TEST_RESOURCES})
+add_RunCMake_test(project_injected)
add_RunCMake_test(return)
add_RunCMake_test(separate_arguments)
add_RunCMake_test(set_property)
add_RunCMake_test(string)
-foreach(var
- CMAKE_C_COMPILER_ID
- CMAKE_C_COMPILER_VERSION
- CMAKE_C_STANDARD_DEFAULT
- CMAKE_CXX_COMPILER_ID
- CMAKE_CXX_COMPILER_VERSION
- CMAKE_CXX_STANDARD_DEFAULT
- CMake_TEST_CUDA
- )
- if(DEFINED ${var})
- list(APPEND try_compile_ARGS -D${var}=${${var}})
+add_RunCMake_test(test_include_dirs)
+add_RunCMake_test(BundleUtilities)
+
+function(add_RunCMake_test_try_compile)
+ if(CMAKE_VERSION VERSION_LESS 3.9.20170907 AND "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
+ # Older CMake versions do not know about MSVC language standards.
+ # Approximate our logic from MSVC-CXX.cmake.
+ if ((NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.0.24215.1 AND
+ CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) OR
+ NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10.25017)
+ set(CMAKE_CXX_STANDARD_DEFAULT 14)
+ elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16.0)
+ set(CMAKE_CXX_STANDARD_DEFAULT "")
+ else()
+ unset(CMAKE_CXX_STANDARD_DEFAULT)
+ endif()
endif()
-endforeach()
-add_RunCMake_test(try_compile)
-add_RunCMake_test(try_run)
+ foreach(var
+ CMAKE_SYSTEM_NAME
+ CMAKE_C_COMPILER_ID
+ CMAKE_C_COMPILER_VERSION
+ CMAKE_C_STANDARD_DEFAULT
+ CMAKE_CXX_COMPILER_ID
+ CMAKE_CXX_COMPILER_VERSION
+ CMAKE_CXX_STANDARD_DEFAULT
+ CMake_TEST_CUDA
+ )
+ if(DEFINED ${var})
+ list(APPEND try_compile_ARGS -D${var}=${${var}})
+ endif()
+ endforeach()
+ add_RunCMake_test(try_compile)
+endfunction()
+add_RunCMake_test_try_compile()
+
+add_RunCMake_test(try_run -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
+ -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
add_RunCMake_test(set)
add_RunCMake_test(variable_watch)
add_RunCMake_test(while)
@@ -260,25 +347,37 @@ if(PKG_CONFIG_FOUND)
add_RunCMake_test(FindPkgConfig)
endif()
-find_package(GTK2 QUIET)
-if (GTK2_FOUND)
+if(CMake_TEST_FindGTK2)
add_RunCMake_test(FindGTK2)
endif()
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
- add_RunCMake_test(include_external_msproject)
- if("${CMAKE_GENERATOR}" MATCHES "Visual Studio ([89]|10)" AND NOT CMAKE_VS_DEVENV_COMMAND)
+ add_RunCMake_test(include_external_msproject -DVS_PLATFORM_NAME=${CMAKE_VS_PLATFORM_NAME})
+ if("${CMAKE_GENERATOR}" MATCHES "Visual Studio (9|10)" AND NOT CMAKE_VS_DEVENV_COMMAND)
set(NO_USE_FOLDERS 1)
endif()
add_RunCMake_test(VSSolution -DNO_USE_FOLDERS=${NO_USE_FOLDERS})
endif()
-if("${CMAKE_GENERATOR}" MATCHES "Visual Studio ([^89]|[89][0-9])")
- add_RunCMake_test(VS10Project)
+if("${CMAKE_GENERATOR}" MATCHES "Visual Studio ([^9]|9[0-9])")
+ add_RunCMake_test(VS10Project
+ -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}
+ -DCMAKE_C_COMPILER_VERSION=${CMAKE_C_COMPILER_VERSION}
+ )
+ if( vs12 AND wince )
+ add_RunCMake_test( VS10ProjectWinCE "-DRunCMake_GENERATOR_PLATFORM=${wince_sdk}")
+ endif()
endif()
if(XCODE_VERSION)
add_RunCMake_test(XcodeProject -DXCODE_VERSION=${XCODE_VERSION})
+
+ # This test can take a very long time due to lots of combinations.
+ # Use a long default timeout and provide an option to customize it.
+ if(NOT DEFINED CMake_TEST_XcodeProject_TIMEOUT)
+ set(CMake_TEST_XcodeProject_TIMEOUT 2000)
+ endif()
+ set_property(TEST RunCMake.XcodeProject PROPERTY TIMEOUT ${CMake_TEST_XcodeProject_TIMEOUT})
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "AppleClang"
@@ -288,19 +387,40 @@ endif()
add_RunCMake_test(File_Generate)
add_RunCMake_test(ExportWithoutLanguage)
+add_RunCMake_test(target_link_directories)
add_RunCMake_test(target_link_libraries)
+add_RunCMake_test(add_link_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
+add_RunCMake_test(target_link_options -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
+add_RunCMake_test(target_compile_definitions)
add_RunCMake_test(target_compile_features)
+add_RunCMake_test(target_compile_options)
+add_RunCMake_test(target_include_directories)
+add_RunCMake_test(target_sources)
add_RunCMake_test(CheckModules)
add_RunCMake_test(CheckIPOSupported)
add_RunCMake_test(CommandLine -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})
add_RunCMake_test(CommandLineTar)
-add_RunCMake_test(install)
+if(CMAKE_PLATFORM_NO_VERSIONED_SONAME OR (NOT CMAKE_SHARED_LIBRARY_SONAME_FLAG AND NOT CMAKE_SHARED_LIBRARY_SONAME_C_FLAG))
+ set(NO_NAMELINK 1)
+else()
+ set(NO_NAMELINK 0)
+endif()
+
+add_RunCMake_test(install -DNO_NAMELINK=${NO_NAMELINK} -DCYGWIN=${CYGWIN})
+add_RunCMake_test(CPackCommandLine)
add_RunCMake_test(CPackConfig)
add_RunCMake_test(CPackInstallProperties)
add_RunCMake_test(ExternalProject)
-add_RunCMake_test(CTestCommandLine)
+add_RunCMake_test(FetchContent)
+set(CTestCommandLine_ARGS -DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE})
+if(NOT CMake_TEST_EXTERNAL_CMAKE)
+ list(APPEND CTestCommandLine_ARGS -DTEST_AFFINITY=$<TARGET_FILE:testAffinity>)
+endif()
+add_executable(print_stdin print_stdin.c)
+add_RunCMake_test(CTestCommandLine -DTEST_PRINT_STDIN=$<TARGET_FILE:print_stdin>)
+add_RunCMake_test(CacheNewline)
# Only run this test on unix platforms that support
# symbolic links
if(UNIX)
@@ -313,18 +433,26 @@ add_RunCMake_test(IfacePaths_INCLUDE_DIRECTORIES TEST_DIR IfacePaths)
set(IfacePaths_SOURCES_ARGS -DTEST_PROP=SOURCES)
add_RunCMake_test(IfacePaths_SOURCES TEST_DIR IfacePaths)
-add_RunCMake_test(COMPILE_LANGUAGE-genex)
-
# Matlab module related tests
-if(CMake_TEST_FindMatlab)
- add_RunCMake_test(FindMatlab)
+if(CMake_TEST_FindMatlab OR CMake_TEST_FindMatlab_MCR OR (NOT "${CMake_TEST_FindMatlab_MCR_ROOT_DIR}" STREQUAL ""))
+ set(FindMatlab_additional_test_options )
+ if(CMake_TEST_FindMatlab_MCR OR NOT "${CMake_TEST_FindMatlab_MCR_ROOT_DIR}" STREQUAL "")
+ set(FindMatlab_additional_test_options -DIS_MCR=TRUE)
+ endif()
+ if(NOT "${CMake_TEST_FindMatlab_MCR_ROOT_DIR}" STREQUAL "")
+ set(FindMatlab_additional_test_options ${FindMatlab_additional_test_options} "-DMCR_ROOT:FILEPATH=${CMake_TEST_FindMatlab_MCR_ROOT_DIR}")
+ endif()
+
+ add_RunCMake_test(FindMatlab ${FindMatlab_additional_test_options})
endif()
add_executable(pseudo_emulator pseudo_emulator.c)
add_executable(pseudo_emulator_custom_command pseudo_emulator_custom_command.c)
+add_executable(pseudo_emulator_custom_command_arg pseudo_emulator_custom_command_arg.c)
add_RunCMake_test(CrosscompilingEmulator
-DPSEUDO_EMULATOR=$<TARGET_FILE:pseudo_emulator>
- -DPSEUDO_EMULATOR_CUSTOM_COMMAND=$<TARGET_FILE:pseudo_emulator_custom_command>)
+ -DPSEUDO_EMULATOR_CUSTOM_COMMAND=$<TARGET_FILE:pseudo_emulator_custom_command>
+ -DPSEUDO_EMULATOR_CUSTOM_COMMAND_ARG=$<TARGET_FILE:pseudo_emulator_custom_command_arg>)
if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
if(UNIX AND NOT CYGWIN)
execute_process(COMMAND ldd --help
@@ -338,13 +466,74 @@ if("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
add_executable(pseudo_tidy pseudo_tidy.c)
add_executable(pseudo_iwyu pseudo_iwyu.c)
add_executable(pseudo_cpplint pseudo_cpplint.c)
+ add_executable(pseudo_cppcheck pseudo_cppcheck.c)
add_RunCMake_test(ClangTidy -DPSEUDO_TIDY=$<TARGET_FILE:pseudo_tidy>)
add_RunCMake_test(IncludeWhatYouUse -DPSEUDO_IWYU=$<TARGET_FILE:pseudo_iwyu>)
add_RunCMake_test(Cpplint -DPSEUDO_CPPLINT=$<TARGET_FILE:pseudo_cpplint>)
+ add_RunCMake_test(Cppcheck -DPSEUDO_CPPCHECK=$<TARGET_FILE:pseudo_cppcheck>)
+ add_RunCMake_test(MultiLint
+ -DPSEUDO_TIDY=$<TARGET_FILE:pseudo_tidy>
+ -DPSEUDO_IWYU=$<TARGET_FILE:pseudo_iwyu>
+ -DPSEUDO_CPPLINT=$<TARGET_FILE:pseudo_cpplint>
+ -DPSEUDO_CPPCHECK=$<TARGET_FILE:pseudo_cppcheck>
+ )
+ if(DEFINED CMake_TEST_CUDA)
+ list(APPEND CompilerLauncher_ARGS -DCMake_TEST_CUDA=${CMake_TEST_CUDA})
+ endif()
+ if(CMAKE_Fortran_COMPILER)
+ list(APPEND CompilerLauncher_ARGS -DCMake_TEST_Fortran=1)
+ endif()
add_RunCMake_test(CompilerLauncher)
+ add_RunCMake_test(ctest_labels_for_subprojects)
endif()
-add_RunCMake_test_group(CPack "DEB;RPM;7Z;TBZ2;TGZ;TXZ;TZ;ZIP;STGZ")
+set(cpack_tests
+ DEB.CUSTOM_NAMES
+ DEB.DEBUGINFO
+ DEB.DEFAULT_PERMISSIONS
+ DEB.DEPENDENCIES
+ DEB.EMPTY_DIR
+ DEB.VERSION
+ DEB.EXTRA
+ DEB.GENERATE_SHLIBS
+ DEB.GENERATE_SHLIBS_LDCONFIG
+ DEB.LONG_FILENAMES
+ DEB.MINIMAL
+ DEB.PER_COMPONENT_FIELDS
+ DEB.TIMESTAMPS
+ DEB.MD5SUMS
+ DEB.DEB_PACKAGE_VERSION_BACK_COMPATIBILITY
+
+ RPM.CUSTOM_BINARY_SPEC_FILE
+ RPM.CUSTOM_NAMES
+ RPM.DEBUGINFO
+ RPM.DEFAULT_PERMISSIONS
+ RPM.DEPENDENCIES
+ RPM.DIST
+ RPM.EMPTY_DIR
+ RPM.VERSION
+ RPM.INSTALL_SCRIPTS
+ RPM.MAIN_COMPONENT
+ RPM.MINIMAL
+ RPM.PARTIALLY_RELOCATABLE_WARNING
+ RPM.PER_COMPONENT_FIELDS
+ RPM.SINGLE_DEBUGINFO
+ RPM.EXTRA_SLASH_IN_PATH
+ RPM.SOURCE_PACKAGE
+ RPM.SUGGESTS
+ RPM.SYMLINKS
+ RPM.USER_FILELIST
+
+ 7Z
+ TBZ2
+ TGZ
+ TXZ
+ TZ
+ ZIP
+ STGZ
+ External
+ )
+add_RunCMake_test_group(CPack "${cpack_tests}")
# add a test to make sure symbols are exported from a shared library
# for MSVC compilers CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS property is used
add_RunCMake_test(AutoExportDll)
@@ -371,3 +560,8 @@ if(CMake_TEST_ANDROID_NDK OR CMake_TEST_ANDROID_STANDALONE_TOOLCHAIN)
endif()
set_property(TEST RunCMake.Android PROPERTY TIMEOUT ${CMake_TEST_ANDROID_TIMEOUT})
endif()
+
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio ([^9]|9[0-9])")
+ add_RunCMake_test(CSharpCustomCommand)
+ add_RunCMake_test(CSharpReferenceImport)
+endif()
diff --git a/Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake b/Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake
index 99d3155dd..948c6ab15 100644
--- a/Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake
+++ b/Tests/RunCMake/CPack/ArchiveCommon/common_helpers.cmake
@@ -45,13 +45,22 @@ function(toExpectedContentList FILE_NO CONTENT_VAR)
unset(prefix_)
endif()
- if(NOT DEFINED TEST_MAIN_INSTALL_PREFIX_PATH)
- set(TEST_MAIN_INSTALL_PREFIX_PATH "/usr")
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPack Archive packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/")
endif()
+ set(prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
+ endforeach()
unset(filtered_)
- foreach(part_ IN LISTS ${CONTENT_VAR})
- string(REGEX REPLACE "^${TEST_MAIN_INSTALL_PREFIX_PATH}(/|$)" "" part_ "${part_}")
+ foreach(part_ IN LISTS prepared_)
+ string(REGEX REPLACE "^/" "" part_ "${part_}")
if(part_)
list(APPEND filtered_ "${prefix_}${part_}")
diff --git a/Tests/RunCMake/CPack/CMakeLists.txt b/Tests/RunCMake/CPack/CMakeLists.txt
index c361af065..1b3dbb228 100644
--- a/Tests/RunCMake/CPack/CMakeLists.txt
+++ b/Tests/RunCMake/CPack/CMakeLists.txt
@@ -15,3 +15,7 @@ include(tests/${RunCMake_TEST_FILE_PREFIX}/test.cmake)
set(CPACK_GENERATOR "${GENERATOR_TYPE}")
include(CPack)
+
+if(COMMAND run_after_include_cpack)
+ run_after_include_cpack()
+endif()
diff --git a/Tests/RunCMake/CPack/CPackTestHelpers.cmake b/Tests/RunCMake/CPack/CPackTestHelpers.cmake
index f883c69e5..f65cb9df8 100644
--- a/Tests/RunCMake/CPack/CPackTestHelpers.cmake
+++ b/Tests/RunCMake/CPack/CPackTestHelpers.cmake
@@ -1,10 +1,15 @@
cmake_policy(SET CMP0057 NEW)
-function(run_cpack_test_common_ TEST_NAME types build SUBTEST_SUFFIX source PACKAGING_TYPE)
+function(run_cpack_test_common_ TEST_NAME types build SUBTEST_SUFFIX source PACKAGING_TYPE package_target)
if(TEST_TYPE IN_LIST types)
+ string(REGEX MATCH "^[^.]*" GENERATOR_TYPE "${TEST_TYPE}")
set(RunCMake_TEST_NO_CLEAN TRUE)
- set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${TEST_NAME}-build")
- set(full_test_name_ "${TEST_NAME}")
+ if(package_target)
+ set(full_test_name_ "${TEST_NAME}-package-target")
+ else()
+ set(full_test_name_ "${TEST_NAME}")
+ endif()
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${full_test_name_}-build")
if(SUBTEST_SUFFIX)
set(RunCMake_TEST_BINARY_DIR "${RunCMake_TEST_BINARY_DIR}-${SUBTEST_SUFFIX}-subtest")
@@ -17,8 +22,8 @@ function(run_cpack_test_common_ TEST_NAME types build SUBTEST_SUFFIX source PACK
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
- if(EXISTS "${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${TEST_TYPE}-Prerequirements.cmake")
- include("${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${TEST_TYPE}-Prerequirements.cmake")
+ if(EXISTS "${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-Prerequirements.cmake")
+ include("${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-Prerequirements.cmake")
set(FOUND_PREREQUIREMENTS false)
get_test_prerequirements("FOUND_PREREQUIREMENTS" "${config_file}")
@@ -31,28 +36,55 @@ function(run_cpack_test_common_ TEST_NAME types build SUBTEST_SUFFIX source PACK
endif()
# execute cmake
- set(RunCMake_TEST_OPTIONS "-DGENERATOR_TYPE=${TEST_TYPE}"
+ set(RunCMake_TEST_OPTIONS "-DGENERATOR_TYPE=${GENERATOR_TYPE}"
"-DRunCMake_TEST_FILE_PREFIX=${TEST_NAME}"
"-DRunCMake_SUBTEST_SUFFIX=${SUBTEST_SUFFIX}"
"-DPACKAGING_TYPE=${PACKAGING_TYPE}")
+
+ foreach(o out err)
+ if(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-${PACKAGING_TYPE}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/configure-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/configure-std${o}.txt")
+ else()
+ unset(RunCMake-std${o}-file)
+ endif()
+ endforeach()
+
run_cmake(${full_test_name_})
# execute optional build step
if(build)
+ unset(RunCMake-stdout-file)
+ unset(RunCMake-stderr-file)
run_cmake_command(${full_test_name_}-Build "${CMAKE_COMMAND}" --build "${RunCMake_TEST_BINARY_DIR}")
endif()
if(source)
- set(pack_params_ -G ${TEST_TYPE} --config ./CPackSourceConfig.cmake)
+ set(pack_params_ -G ${GENERATOR_TYPE} --config ./CPackSourceConfig.cmake)
FILE(APPEND ${RunCMake_TEST_BINARY_DIR}/CPackSourceConfig.cmake
- "\nset(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS \"-DRunCMake_TEST:STRING=${full_test_name_} -DRunCMake_TEST_FILE_PREFIX:STRING=${TEST_NAME} -DGENERATOR_TYPE:STRING=${TEST_TYPE}\")")
+ "\nset(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS \"-DRunCMake_TEST:STRING=${full_test_name_} -DRunCMake_TEST_FILE_PREFIX:STRING=${TEST_NAME} -DGENERATOR_TYPE:STRING=${GENERATOR_TYPE}\")")
else()
unset(pack_params_)
endif()
+ if(package_target)
+ set(cpack_command_ ${CMAKE_COMMAND} --build "${RunCMake_TEST_BINARY_DIR}" --target package)
+ else()
+ set(cpack_command_ ${CMAKE_CPACK_COMMAND} ${pack_params_})
+ endif()
+
# execute cpack
+ set(SETENV)
+ if(ENVIRONMENT)
+ set(SETENV ${CMAKE_COMMAND} -E env "${ENVIRONMENT}")
+ endif()
execute_process(
- COMMAND ${CMAKE_CPACK_COMMAND} ${pack_params_}
+ COMMAND ${SETENV} ${cpack_command_}
WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}"
RESULT_VARIABLE "result_"
OUTPUT_FILE "${RunCMake_TEST_BINARY_DIR}/test_output.txt"
@@ -60,27 +92,31 @@ function(run_cpack_test_common_ TEST_NAME types build SUBTEST_SUFFIX source PACK
)
foreach(o out err)
- if(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${TEST_TYPE}-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
- set(RunCMake-std${o}-file "tests/${TEST_NAME}/${TEST_TYPE}-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
- elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${TEST_TYPE}-${PACKAGING_TYPE}-std${o}.txt)
- set(RunCMake-std${o}-file "tests/${TEST_NAME}/${TEST_TYPE}-${PACKAGING_TYPE}-std${o}.txt")
- elseif(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${TEST_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
- set(RunCMake-std${o}-file "tests/${TEST_NAME}/${TEST_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
- elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${TEST_TYPE}-std${o}.txt)
- set(RunCMake-std${o}-file "tests/${TEST_NAME}/${TEST_TYPE}-std${o}.txt")
- elseif(EXISTS ${RunCMake_SOURCE_DIR}/${TEST_TYPE}/default_expected_std${o}.txt)
- set(RunCMake-std${o}-file "${TEST_TYPE}/default_expected_std${o}.txt")
+ if(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-${PACKAGING_TYPE}-std${o}.txt")
+ elseif(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${GENERATOR_TYPE}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${GENERATOR_TYPE}-std${o}.txt")
+ elseif(SUBTEST_SUFFIX AND EXISTS ${RunCMake_SOURCE_DIR}/tests/${TEST_NAME}/${SUBTEST_SUFFIX}-std${o}.txt)
+ set(RunCMake-std${o}-file "tests/${TEST_NAME}/${SUBTEST_SUFFIX}-std${o}.txt")
+ elseif(EXISTS ${RunCMake_SOURCE_DIR}/${GENERATOR_TYPE}/default_expected_std${o}.txt)
+ set(RunCMake-std${o}-file "${GENERATOR_TYPE}/default_expected_std${o}.txt")
+ else()
+ unset(RunCMake-std${o}-file)
endif()
endforeach()
# verify result
run_cmake_command(
- ${TEST_TYPE}/${full_test_name_}
+ ${GENERATOR_TYPE}/${full_test_name_}
"${CMAKE_COMMAND}"
-DRunCMake_TEST=${full_test_name_}
-DRunCMake_TEST_FILE_PREFIX=${TEST_NAME}
-DRunCMake_SUBTEST_SUFFIX=${SUBTEST_SUFFIX}
- -DGENERATOR_TYPE=${TEST_TYPE}
+ -DGENERATOR_TYPE=${GENERATOR_TYPE}
-DPACKAGING_TYPE=${PACKAGING_TYPE}
"-Dsrc_dir=${RunCMake_SOURCE_DIR}"
"-Dbin_dir=${RunCMake_TEST_BINARY_DIR}"
@@ -92,18 +128,24 @@ endfunction()
function(run_cpack_test TEST_NAME types build PACKAGING_TYPES)
foreach(packaging_type_ IN LISTS PACKAGING_TYPES)
- run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "" false "${packaging_type_}")
+ run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "" false "${packaging_type_}" false)
+ endforeach()
+endfunction()
+
+function(run_cpack_test_package_target TEST_NAME types build PACKAGING_TYPES)
+ foreach(packaging_type_ IN LISTS PACKAGING_TYPES)
+ run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "" false "${packaging_type_}" true)
endforeach()
endfunction()
function(run_cpack_test_subtests TEST_NAME SUBTEST_SUFFIXES types build PACKAGING_TYPES)
foreach(suffix_ IN LISTS SUBTEST_SUFFIXES)
foreach(packaging_type_ IN LISTS PACKAGING_TYPES)
- run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "${suffix_}" false "${packaging_type_}")
+ run_cpack_test_common_("${TEST_NAME}" "${types}" "${build}" "${suffix_}" false "${packaging_type_}" false)
endforeach()
endforeach()
endfunction()
function(run_cpack_source_test TEST_NAME types)
- run_cpack_test_common_("${TEST_NAME}" "${types}" false "" true "")
+ run_cpack_test_common_("${TEST_NAME}" "${types}" false "" true "" false)
endfunction()
diff --git a/Tests/RunCMake/CPack/DEB/Helpers.cmake b/Tests/RunCMake/CPack/DEB/Helpers.cmake
index ad1b47bdc..9b98ed41f 100644
--- a/Tests/RunCMake/CPack/DEB/Helpers.cmake
+++ b/Tests/RunCMake/CPack/DEB/Helpers.cmake
@@ -1,7 +1,7 @@
-set(ALL_FILES_GLOB "*.deb")
+set(ALL_FILES_GLOB "*.deb" "*.ddeb")
function(getPackageContent FILE RESULT_VAR)
- execute_process(COMMAND ${DPKG_EXECUTABLE} -c "${FILE}"
+ execute_process(COMMAND ${CMAKE_COMMAND} -E env TZ=Etc/UTC ${DPKG_EXECUTABLE} -c "${FILE}"
OUTPUT_VARIABLE package_content_
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
@@ -23,7 +23,7 @@ function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_V
endif()
if(GENERATOR_SPECIFIC_FORMAT)
- set(${RESULT_VAR} "${NAME}${COMPONENT}_${VERSION}-${REVISION}_*.deb" PARENT_SCOPE)
+ set(${RESULT_VAR} "${NAME}${COMPONENT}_${VERSION}_*.deb" PARENT_SCOPE)
else()
set(${RESULT_VAR} "${NAME}-${VERSION}-*${COMPONENT}.deb" PARENT_SCOPE)
endif()
@@ -47,7 +47,20 @@ function(getPackageContentList FILE RESULT_VAR)
endfunction()
function(toExpectedContentList FILE_NO CONTENT_VAR)
- # no need to do anything
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPackDeb packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/usr")
+ endif()
+ set(prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
+ endforeach()
+
+ set(${CONTENT_VAR} "${prepared_}" PARENT_SCOPE)
endfunction()
function(getMissingShlibsErrorExtra FILE RESULT_VAR)
diff --git a/Tests/RunCMake/CPack/README.txt b/Tests/RunCMake/CPack/README.txt
index 7c98f6972..216512505 100644
--- a/Tests/RunCMake/CPack/README.txt
+++ b/Tests/RunCMake/CPack/README.txt
@@ -91,6 +91,19 @@ If test will be used for multiple generators but some of them require some
generator specific commands then those commands should be added to 'test.cmake'
script wrapped with 'if(GENERATOR_TYPE STREQUAL <name_of_the_generator>)'.
+NOTE: In some cases (for example when testing CPackComponent.cmake functions)
+the test has to run some functions after CPack.cmake is included. In such cases
+a function run_after_include_cpack can be declared in test.cmake file and that
+function will run after the inclusion of CPack.cmake.
+
+NOTE: During CMake configure stage developer warnings may be expected. In such
+cases an expected output regular expression can be provided by creating
+'<test_name>/configure-stdout.txt' and/or '<test_name>/configure-stderr.txt'
+file. There are also more specialized versions of the file available:
+- configure-${PACKAGING_TYPE}-${SUBTEST_SUFFIX}-std${o}.txt
+- configure-${SUBTEST_SUFFIX}-std${o}.txt
+- configure-${PACKAGING_TYPE}-std${o}.txt
+
build phase (optional and not available for source package tests)
-----------------------------------------------------------------
@@ -144,17 +157,23 @@ this step and must contain
NOTE: This variable should be used only as last resort as it sets generator
specific regular expression.
EXPECTED_FILE_CONTENT_<file_number_starting_with_1>_LIST should be
- prefered as it requires a list of expected files and directories that
+ preferred as it requires a list of expected files and directories that
is later changed automatically depending on the generator so expected
package content can be written only once per test for all generators.
-Optional verification phase is generator specific and is optionaly executed.
+- EXPECTED_FILE_PACKAGING_PREFIX and
+ EXPECTED_FILE_<file_number_starting_with_1>_PACKAGING_PREFIX variables can be
+ set to explicitly specified CPACK_PACKAGING_PREFIX value. By default this
+ variable does not need to be set as it is implicitly set to package generator
+ specific prefix.
+
+Optional verification phase is generator specific and is optionally executed.
This phase is executed if '<test_name>/VerifyResult.cmake' script exists.
VerifyResult.cmake script also automatically prints out standard output and
standard error from CPack execution phase that is compared with
'<test_name>/<generator_name>-stdout.txt' regular expression and
-and '<test_name>/<generator_name>-stderr.txt' regular expresson respectively.
+'<test_name>/<generator_name>-stderr.txt' regular expresson respectively.
NOTE: For subtests generator name can also be suffixed with subtest name and/or
packaging type (MONOLITHIC, COMPONENT, GROUP) and in such cases the
preferences of which file will be used are as follows:
@@ -162,6 +181,7 @@ NOTE: For subtests generator name can also be suffixed with subtest name and/or
- generator name + packaging type
- generator name + subtest name
- generator name
+ - subtest name
- default generator
File name format: '<generator_name>-<packaging_type>-<subtest_name>-std<type>.txt'
where <type> can either be 'out' or 'err'.
@@ -204,7 +224,7 @@ To add a new generator we must
+ FILE that will contain the package file for which the package content
should be returned.
+ RESULT_VAR that will tell the function which variable in parent scope
- should contain the result (list of pacakge content)
+ should contain the result (list of package content)
- toExpectedContentList: This function should convert an expected package
content list into one that is expected for the
generator (e.g. rpm packages have install/relocate
diff --git a/Tests/RunCMake/CPack/RPM/Helpers.cmake b/Tests/RunCMake/CPack/RPM/Helpers.cmake
index d8012b11b..a29c02065 100644
--- a/Tests/RunCMake/CPack/RPM/Helpers.cmake
+++ b/Tests/RunCMake/CPack/RPM/Helpers.cmake
@@ -23,6 +23,9 @@ function(getPackageNameGlobexpr NAME COMPONENT VERSION REVISION FILE_NO RESULT_V
endif()
if(GENERATOR_SPECIFIC_FORMAT)
+ if(NOT REVISION)
+ set(REVISION "1")
+ endif()
set(${RESULT_VAR} "${NAME}${COMPONENT}-${VERSION}-${REVISION}.*.rpm" PARENT_SCOPE)
else()
set(${RESULT_VAR} "${NAME}-${VERSION}-*${COMPONENT}.rpm" PARENT_SCOPE)
@@ -44,14 +47,29 @@ function(getPackageContentList FILE RESULT_VAR)
endfunction()
function(toExpectedContentList FILE_NO CONTENT_VAR)
- if(NOT DEFINED TEST_INSTALL_PREFIX_PATHS)
- set(TEST_INSTALL_PREFIX_PATHS "/usr")
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPackRPM packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/usr")
endif()
+ set(prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
+ endforeach()
+ # remove paths that are excluded from auto packaging
+ if(NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
+ set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST
+ /etc /etc/init.d /usr /usr/bin /usr/include /usr/lib
+ /usr/libx32 /usr/lib64 /usr/share /usr/share/aclocal /usr/share/doc)
+ endif()
unset(filtered_)
- foreach(part_ IN LISTS ${CONTENT_VAR})
+ foreach(part_ IN LISTS prepared_)
unset(dont_add_)
- foreach(for_removal_ IN LISTS TEST_INSTALL_PREFIX_PATHS)
+ foreach(for_removal_ IN LISTS CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST)
if(part_ STREQUAL for_removal_)
set(dont_add_ TRUE)
break()
diff --git a/Tests/RunCMake/CPack/RPM/default_expected_stderr.txt b/Tests/RunCMake/CPack/RPM/default_expected_stderr.txt
index 4a0e4e6d0..6c87ca0c0 100644
--- a/Tests/RunCMake/CPack/RPM/default_expected_stderr.txt
+++ b/Tests/RunCMake/CPack/RPM/default_expected_stderr.txt
@@ -1 +1 @@
-^(CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM/CPack/[^-]*-build((-[^-]*-subtest/)|/)_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec(\n|$))*$
+^(CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM\.[^/]*/CPack/[^-]*(-package-target)?-build((-[^-]*-subtest/)|/)_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec(\n|$))*$
diff --git a/Tests/RunCMake/CPack/RunCMakeTest.cmake b/Tests/RunCMake/CPack/RunCMakeTest.cmake
index faf151a13..37df57cd0 100644
--- a/Tests/RunCMake/CPack/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CPack/RunCMakeTest.cmake
@@ -4,26 +4,35 @@ include(RunCMake)
include("${RunCMake_SOURCE_DIR}/CPackTestHelpers.cmake")
# run_cpack_test args: TEST_NAME "GENERATORS" RUN_CMAKE_BUILD_STEP "PACKAGING_TYPES"
-run_cpack_test(CUSTOM_BINARY_SPEC_FILE "RPM" false "MONOLITHIC;COMPONENT")
-run_cpack_test(CUSTOM_NAMES "RPM;DEB;TGZ" true "COMPONENT")
-run_cpack_test(DEBUGINFO "RPM" true "COMPONENT")
-run_cpack_test(DEPENDENCIES "RPM;DEB" true "COMPONENT")
-run_cpack_test(DIST "RPM" false "MONOLITHIC")
-run_cpack_test(EMPTY_DIR "RPM;DEB;TGZ" true "MONOLITHIC;COMPONENT")
-run_cpack_test(EXTRA "DEB" false "COMPONENT")
-run_cpack_test(GENERATE_SHLIBS "DEB" true "COMPONENT")
-run_cpack_test(GENERATE_SHLIBS_LDCONFIG "DEB" true "COMPONENT")
-run_cpack_test(INSTALL_SCRIPTS "RPM" false "COMPONENT")
-run_cpack_test(LONG_FILENAMES "DEB" false "MONOLITHIC")
-run_cpack_test_subtests(MAIN_COMPONENT "invalid;found" "RPM" false "COMPONENT")
-run_cpack_test(MINIMAL "RPM;DEB;7Z;TBZ2;TGZ;TXZ;TZ;ZIP;STGZ" false "MONOLITHIC;COMPONENT")
+run_cpack_test(CUSTOM_BINARY_SPEC_FILE "RPM.CUSTOM_BINARY_SPEC_FILE" false "MONOLITHIC;COMPONENT")
+run_cpack_test(CUSTOM_NAMES "RPM.CUSTOM_NAMES;DEB.CUSTOM_NAMES;TGZ" true "COMPONENT")
+run_cpack_test(DEBUGINFO "RPM.DEBUGINFO;DEB.DEBUGINFO" true "COMPONENT")
+run_cpack_test_subtests(DEFAULT_PERMISSIONS "CMAKE_var_set;CPACK_var_set;both_set;invalid_CMAKE_var;invalid_CPACK_var" "RPM.DEFAULT_PERMISSIONS;DEB.DEFAULT_PERMISSIONS" false "MONOLITHIC;COMPONENT")
+run_cpack_test(DEPENDENCIES "RPM.DEPENDENCIES;DEB.DEPENDENCIES" true "COMPONENT")
+run_cpack_test(DIST "RPM.DIST" false "MONOLITHIC")
+run_cpack_test(EMPTY_DIR "RPM.EMPTY_DIR;DEB.EMPTY_DIR;TGZ" true "MONOLITHIC;COMPONENT")
+run_cpack_test(VERSION "RPM.VERSION;DEB.VERSION" false "MONOLITHIC;COMPONENT")
+run_cpack_test(EXTRA "DEB.EXTRA" false "COMPONENT")
+run_cpack_test_subtests(GENERATE_SHLIBS "soversion_not_zero;soversion_zero" "DEB.GENERATE_SHLIBS" true "COMPONENT")
+run_cpack_test(GENERATE_SHLIBS_LDCONFIG "DEB.GENERATE_SHLIBS_LDCONFIG" true "COMPONENT")
+run_cpack_test(INSTALL_SCRIPTS "RPM.INSTALL_SCRIPTS" false "COMPONENT")
+run_cpack_test(LONG_FILENAMES "DEB.LONG_FILENAMES" false "MONOLITHIC")
+run_cpack_test_subtests(MAIN_COMPONENT "invalid;found" "RPM.MAIN_COMPONENT" false "COMPONENT")
+run_cpack_test(MINIMAL "RPM.MINIMAL;DEB.MINIMAL;7Z;TBZ2;TGZ;TXZ;TZ;ZIP;STGZ;External" false "MONOLITHIC;COMPONENT")
+run_cpack_test_package_target(MINIMAL "RPM.MINIMAL;DEB.MINIMAL;7Z;TBZ2;TGZ;TXZ;TZ;ZIP;STGZ;External" false "MONOLITHIC;COMPONENT")
run_cpack_test_subtests(PACKAGE_CHECKSUM "invalid;MD5;SHA1;SHA224;SHA256;SHA384;SHA512" "TGZ" false "MONOLITHIC")
-run_cpack_test(PARTIALLY_RELOCATABLE_WARNING "RPM" false "COMPONENT")
-run_cpack_test(PER_COMPONENT_FIELDS "RPM;DEB" false "COMPONENT")
-run_cpack_test_subtests(SINGLE_DEBUGINFO "no_main_component;one_component;one_component_main;no_debuginfo;one_component_no_debuginfo;no_components;valid" "RPM" true "CUSTOM")
-run_cpack_test(EXTRA_SLASH_IN_PATH "RPM" true "COMPONENT")
-run_cpack_source_test(SOURCE_PACKAGE "RPM")
-run_cpack_test(SUGGESTS "RPM" false "MONOLITHIC")
-run_cpack_test(SYMLINKS "RPM;TGZ" false "MONOLITHIC;COMPONENT")
-run_cpack_test(USER_FILELIST "RPM" false "MONOLITHIC")
-run_cpack_test(MD5SUMS "DEB" false "MONOLITHIC;COMPONENT")
+run_cpack_test(PARTIALLY_RELOCATABLE_WARNING "RPM.PARTIALLY_RELOCATABLE_WARNING" false "COMPONENT")
+run_cpack_test(PER_COMPONENT_FIELDS "RPM.PER_COMPONENT_FIELDS;DEB.PER_COMPONENT_FIELDS" false "COMPONENT")
+run_cpack_test_subtests(SINGLE_DEBUGINFO "no_main_component;one_component;one_component_main;no_debuginfo;one_component_no_debuginfo;no_components;valid" "RPM.SINGLE_DEBUGINFO" true "CUSTOM")
+run_cpack_test(EXTRA_SLASH_IN_PATH "RPM.EXTRA_SLASH_IN_PATH" true "COMPONENT")
+run_cpack_source_test(SOURCE_PACKAGE "RPM.SOURCE_PACKAGE")
+run_cpack_test(SUGGESTS "RPM.SUGGESTS" false "MONOLITHIC")
+run_cpack_test(SYMLINKS "RPM.SYMLINKS;TGZ" false "MONOLITHIC;COMPONENT")
+set(ENVIRONMENT "SOURCE_DATE_EPOCH=123456789")
+run_cpack_test(TIMESTAMPS "DEB.TIMESTAMPS;TGZ" false "COMPONENT")
+unset(ENVIRONMENT)
+run_cpack_test(USER_FILELIST "RPM.USER_FILELIST" false "MONOLITHIC")
+run_cpack_test(MD5SUMS "DEB.MD5SUMS" false "MONOLITHIC;COMPONENT")
+run_cpack_test(CPACK_INSTALL_SCRIPT "ZIP" false "MONOLITHIC")
+run_cpack_test(DEB_PACKAGE_VERSION_BACK_COMPATIBILITY "DEB.DEB_PACKAGE_VERSION_BACK_COMPATIBILITY" false "MONOLITHIC;COMPONENT")
+run_cpack_test_subtests(EXTERNAL "none;good;good_multi;bad_major;bad_minor;invalid_good;invalid_bad;stage_and_package" "External" false "MONOLITHIC;COMPONENT")
diff --git a/Tests/RunCMake/CPack/STGZ/Helpers.cmake b/Tests/RunCMake/CPack/STGZ/Helpers.cmake
index 68b1eabd2..175664551 100644
--- a/Tests/RunCMake/CPack/STGZ/Helpers.cmake
+++ b/Tests/RunCMake/CPack/STGZ/Helpers.cmake
@@ -47,18 +47,29 @@ function(toExpectedContentList FILE_NO CONTENT_VAR)
string(SUBSTRING "${prefix_}" 0 ${pos_} prefix_)
endif()
- if(NOT DEFINED TEST_MAIN_INSTALL_PREFIX_PATH)
- set(TEST_MAIN_INSTALL_PREFIX_PATH "/usr")
+ # add install prefix to expected paths
+ if(DEFINED EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX)
+ set(EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_${FILE_NO}_PACKAGING_PREFIX}")
+ elseif(NOT DEFINED EXPECTED_FILE_PACKAGING_PREFIX)
+ # default CPack Archive packaging install prefix
+ set(EXPECTED_FILE_PACKAGING_PREFIX "/")
endif()
- set(filtered_ "${prefix_}")
- foreach(part_ IN LISTS ${CONTENT_VAR})
- string(REGEX REPLACE "^${TEST_MAIN_INSTALL_PREFIX_PATH}(/|$)" "" part_ "${part_}")
+ # remove trailing slash otherwise path concatenation will cause double slashes
+ string(REGEX REPLACE "/$" "" EXPECTED_FILE_PACKAGING_PREFIX
+ "${EXPECTED_FILE_PACKAGING_PREFIX}")
+
+ if(EXPECTED_FILE_PACKAGING_PREFIX)
+ set(prepared_ "${prefix_}")
+ else()
+ unset(prepared_)
+ endif()
- if(part_)
- list(APPEND filtered_ "${prefix_}/${part_}")
- endif()
+ list(APPEND prepared_ "${prefix_}${EXPECTED_FILE_PACKAGING_PREFIX}")
+ foreach(part_ IN LISTS ${CONTENT_VAR})
+ list(APPEND prepared_ "${prefix_}${EXPECTED_FILE_PACKAGING_PREFIX}${part_}")
endforeach()
- set(${CONTENT_VAR} "${filtered_}" PARENT_SCOPE)
+ set(${CONTENT_VAR} "${prepared_}" PARENT_SCOPE)
endfunction()
diff --git a/Tests/RunCMake/CPack/VerifyResult.cmake b/Tests/RunCMake/CPack/VerifyResult.cmake
index 470ebf7a8..345b37fac 100644
--- a/Tests/RunCMake/CPack/VerifyResult.cmake
+++ b/Tests/RunCMake/CPack/VerifyResult.cmake
@@ -8,9 +8,7 @@ function(findExpectedFile FILE_NO RESULT_VAR GLOBING_EXPR_VAR)
endif()
if(NOT DEFINED EXPECTED_FILE_${FILE_NO}_VERSION)
set(EXPECTED_FILE_${FILE_NO}_VERSION "0.1.1")
- endif()
- if(NOT DEFINED EXPECTED_FILE_${FILE_NO}_REVISION)
- set(EXPECTED_FILE_${FILE_NO}_REVISION "1")
+ set(EXPECTED_FILE_${FILE_NO}_VERSION "0.1.1" PARENT_SCOPE)
endif()
getPackageNameGlobexpr("${EXPECTED_FILE_${FILE_NO}_NAME}"
@@ -58,8 +56,12 @@ if(NOT EXPECTED_FILES_COUNT EQUAL 0)
set(EXPECTED_FILE_CONTENT_${file_no_} "${EXPECTED_FILE_CONTENT_${file_no_}_LIST}")
toExpectedContentList("${file_no_}" "EXPECTED_FILE_CONTENT_${file_no_}")
- list(SORT PACKAGE_CONTENT)
- list(SORT EXPECTED_FILE_CONTENT_${file_no_})
+ if(NOT PACKAGE_CONTENT STREQUAL "")
+ list(SORT PACKAGE_CONTENT)
+ endif()
+ if(NOT EXPECTED_FILE_CONTENT_${file_no_} STREQUAL "")
+ list(SORT EXPECTED_FILE_CONTENT_${file_no_})
+ endif()
if(PACKAGE_CONTENT STREQUAL EXPECTED_FILE_CONTENT_${file_no_})
set(expected_content_list TRUE)
@@ -90,7 +92,7 @@ if(NOT EXPECTED_FILES_COUNT EQUAL 0)
# check that there were no extra files generated
foreach(all_files_glob_ IN LISTS ALL_FILES_GLOB)
file(GLOB foundAll_ RELATIVE "${bin_dir}" "${all_files_glob_}")
- list(APPEND allFoundFiles_ "${foundAll_}")
+ list(APPEND allFoundFiles_ ${foundAll_})
endforeach()
list(LENGTH foundFiles_ foundFilesCount_)
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake
index 694dc00ab..6d895ec2f 100644
--- a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/ExpectedFiles.cmake
@@ -1,9 +1,9 @@
set(EXPECTED_FILES_COUNT "1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
if(PACKAGING_TYPE STREQUAL "COMPONENT")
set(EXPECTED_FILES_COUNT "2")
set(EXPECTED_FILE_1_COMPONENT "test")
set(EXPECTED_FILE_2_COMPONENT "test2")
- set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
endif()
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt
index e6d86d0de..b0502628e 100644
--- a/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_BINARY_SPEC_FILE/RPM-COMPONENT-stderr.txt
@@ -1,2 +1,2 @@
^CPackRPM: Will use USER specified spec file: (/[^/]*)*/CUSTOM_BINARY_SPEC_FILE/custom\.spec\.in
-CPackRPM: Will use GENERATED spec file:.*/Tests/RunCMake/RPM/CPack/CUSTOM_BINARY_SPEC_FILE-build/_CPack_Packages/.*/RPM/SPECS/custom_binary_spec_file-test2\.spec$
+CPackRPM: Will use GENERATED spec file:.*/Tests/RunCMake/RPM\.CUSTOM_BINARY_SPEC_FILE/CPack/CUSTOM_BINARY_SPEC_FILE-build/_CPack_Packages/.*/RPM/SPECS/custom_binary_spec_file-test2\.spec$
diff --git a/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake
index 5cb280cd6..07226df04 100644
--- a/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/CUSTOM_NAMES/ExpectedFiles.cmake
@@ -1,10 +1,10 @@
set(EXPECTED_FILES_COUNT "3")
set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
set(EXPECTED_FILE_1_COMPONENT "pkg_1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
set(EXPECTED_FILE_2_NAME "second")
-set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
-set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_2_LIST "/foo;/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_3_LIST "/foo;/foo/CMakeLists.txt")
if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
string(TOLOWER "${GENERATOR_TYPE}" file_extension_)
diff --git a/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake
index 3d8de74d4..cf2e8ac6b 100644
--- a/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/DEBUGINFO/ExpectedFiles.cmake
@@ -3,16 +3,39 @@ set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "5")
set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
-set(EXPECTED_FILE_1_NAME "Debuginfo")
+if(GENERATOR_TYPE STREQUAL "RPM")
+ set(NAME "Debuginfo")
+ set(DEBUG_SUFFIX "debuginfo")
+ set(PKG "rpm")
+ set(DEBUG_PKG "rpm")
+elseif(GENERATOR_TYPE STREQUAL "DEB")
+ set(NAME "debuginfo")
+ set(DEBUG_SUFFIX "dbgsym")
+ set(PKG "deb")
+ set(DEBUG_PKG "ddeb")
+endif()
+
+set(EXPECTED_FILE_1_NAME "${NAME}")
set(EXPECTED_FILE_1_COMPONENT "applications")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/test_prog")
-set(EXPECTED_FILE_2 "TestDinfo-pkg*-headers.rpm")
-set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
-set(EXPECTED_FILE_3 "TestDinfo-pkg*-libs.rpm")
-set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/bas;/usr/bas/libtest_lib.so")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
+
+set(EXPECTED_FILE_2 "TestDinfo-pkg*-headers.${PKG}")
+set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
+
+set(EXPECTED_FILE_3 "TestDinfo-pkg*-libs.${PKG}")
+set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so")
+
+set(EXPECTED_FILE_4 "${NAME}-applications-${DEBUG_SUFFIX}*.${DEBUG_PKG}")
+if(GENERATOR_TYPE STREQUAL "RPM")
+ set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
+elseif(GENERATOR_TYPE STREQUAL "DEB")
+ set(EXPECTED_FILE_CONTENT_4 ".*/usr/lib/debug/.build-id/.*\.debug.*")
+endif()
-set(EXPECTED_FILE_4_NAME "Debuginfo")
-set(EXPECTED_FILE_4_COMPONENT "applications-debuginfo")
-set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*")
-set(EXPECTED_FILE_5 "libs-DebugInfoPackage.rpm")
-set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*")
+if(GENERATOR_TYPE STREQUAL "RPM")
+ set(EXPECTED_FILE_5 "libs-DebugInfoPackage.rpm")
+ set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*")
+elseif(GENERATOR_TYPE STREQUAL "DEB")
+ set(EXPECTED_FILE_5 "TestDinfo-pkg-libs-dbgsym.ddeb")
+ set(EXPECTED_FILE_CONTENT_5 ".*/usr/lib/debug/.build-id/.*\.debug.*")
+endif()
diff --git a/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake b/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake
index f1b6738bd..161a36a85 100644
--- a/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake
+++ b/Tests/RunCMake/CPack/tests/DEBUGINFO/test.cmake
@@ -8,6 +8,10 @@ endif()
set(CMAKE_BUILD_TYPE Debug)
+# for rpm packages execute flag must be set for shared libs if debuginfo
+# packages are generated
+set(CPACK_RPM_INSTALL_WITH_EXEC TRUE)
+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
"int test_lib();\n")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
@@ -25,12 +29,16 @@ install(TARGETS test_lib DESTINATION bas COMPONENT libs)
set(CPACK_RPM_APPLICATIONS_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_APPLICATIONS_DEBUGINFO_PACKAGE ON)
+set(CPACK_DEBIAN_APPLICATIONS_FILE_NAME "DEB-DEFAULT")
+set(CPACK_DEBIAN_APPLICATIONS_DEBUGINFO_PACKAGE ON)
# test that components with debuginfo enabled still honor
# CPACK_PACKAGE_FILE_NAME setting
set(CPACK_RPM_PACKAGE_NAME "Debuginfo")
set(CPACK_PACKAGE_FILE_NAME "TestDinfo-pkg")
set(CPACK_RPM_LIBS_DEBUGINFO_PACKAGE ON)
+set(CPACK_DEBIAN_PACKAGE_NAME "Debuginfo")
+set(CPACK_DEBIAN_LIBS_DEBUGINFO_PACKAGE ON)
# test debuginfo package rename
set(CPACK_RPM_DEBUGINFO_FILE_NAME
diff --git a/Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake
index 3b280ba73..be7ba07db 100644
--- a/Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/DEPENDENCIES/ExpectedFiles.cmake
@@ -1,14 +1,14 @@
set(EXPECTED_FILES_COUNT "5")
set(EXPECTED_FILE_1_COMPONENT "applications")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/test_prog")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
set(EXPECTED_FILE_2_COMPONENT "applications_auto")
-set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/foo_auto;/usr/foo_auto/test_prog")
+set(EXPECTED_FILE_CONTENT_2_LIST "/foo_auto;/foo_auto/test_prog")
set(EXPECTED_FILE_3_COMPONENT "headers")
-set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_3_LIST "/bar;/bar/CMakeLists.txt")
set(EXPECTED_FILE_4_COMPONENT "libs")
-set(EXPECTED_FILE_CONTENT_4_LIST "/usr/bas;/usr/bas/libtest_lib.so")
+set(EXPECTED_FILE_CONTENT_4_LIST "/bas;/bas/libtest_lib.so")
set(EXPECTED_FILE_5_COMPONENT "libs_auto")
-set(EXPECTED_FILE_CONTENT_5_LIST "/usr;/usr/bas_auto;/usr/bas_auto/libtest_lib.so")
+set(EXPECTED_FILE_CONTENT_5_LIST "/bas_auto;/bas_auto/libtest_lib.so")
if(GENERATOR_TYPE STREQUAL "DEB")
set(whitespaces_ "[\t\n\r ]*")
diff --git a/Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake
index 6142eb39a..d1a3a5fb2 100644
--- a/Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/DIST/ExpectedFiles.cmake
@@ -1,2 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake
index 7375ecc21..1b2eb4877 100644
--- a/Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake
+++ b/Tests/RunCMake/CPack/tests/DIST/VerifyResult.cmake
@@ -5,6 +5,11 @@ execute_process(COMMAND ${RPMBUILD_EXECUTABLE} -E %{?dist}
set(whitespaces_ "[\t\n\r ]*")
+# since we have no control over dist tag value we should try to escape
+# the content for use as a regular expression
+string(REPLACE "+" "\\+" DIST_TAG "${DIST_TAG}")
+string(REPLACE "." "\\." DIST_TAG "${DIST_TAG}")
+
getPackageInfo("${FOUND_FILE_1}" "FILE_INFO_")
if(NOT FILE_INFO_ MATCHES ".*Release${whitespaces_}:${whitespaces_}1${DIST_TAG}")
message(FATAL_ERROR "Unexpected Release in '${FOUND_FILE_1}'; file info: '${FILE_INFO_}'")
diff --git a/Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake
index 650687ce0..8df683115 100644
--- a/Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/EMPTY_DIR/ExpectedFiles.cmake
@@ -1,6 +1,6 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/empty")
+set(EXPECTED_FILE_CONTENT_1_LIST "/empty")
if(PACKAGING_TYPE STREQUAL "COMPONENT")
set(EXPECTED_FILE_1_COMPONENT "test")
diff --git a/Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake
index ded2923e2..407cbe630 100644
--- a/Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/EXTRA/ExpectedFiles.cmake
@@ -1,8 +1,8 @@
set(EXPECTED_FILES_COUNT "3")
set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
set(EXPECTED_FILE_1_COMPONENT "foo")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
set(EXPECTED_FILE_2_COMPONENT "bar")
-set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
set(EXPECTED_FILE_3_COMPONENT "bas")
-set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/bas;/usr/bas/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake
index a45b38ddd..3fb05346c 100644
--- a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/ExpectedFiles.cmake
@@ -2,6 +2,7 @@ set(whitespaces_ "[\t\n\r ]*")
set(EXPECTED_FILES_COUNT "5")
set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
+set(EXPECTED_FILE_PACKAGING_PREFIX "")
set(EXPECTED_FILE_1_COMPONENT "applications")
set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
@@ -11,6 +12,6 @@ set(EXPECTED_FILE_3 "extra_slash_in_path*-libs.rpm")
set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so")
set(EXPECTED_FILE_4_COMPONENT "applications-debuginfo")
-set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*")
+set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
set(EXPECTED_FILE_5_COMPONENT "libs-debuginfo")
-set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*")
+set(EXPECTED_FILE_CONTENT_5 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*")
diff --git a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake
index 4fd1e810a..7cee1888e 100644
--- a/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake
+++ b/Tests/RunCMake/CPack/tests/EXTRA_SLASH_IN_PATH/test.cmake
@@ -8,6 +8,10 @@ endif()
set(CMAKE_BUILD_TYPE Debug)
+# for rpm packages execute flag must be set for shared libs if debuginfo
+# packages are generated
+set(CPACK_RPM_INSTALL_WITH_EXEC TRUE)
+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
"int test_lib();\n")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake
index b1952efd1..8cefeea5f 100644
--- a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/VerifyResult.cmake
@@ -1,4 +1,9 @@
-set(shlibs_shlibs "^libtest_lib 0\\.8 generate_shlibs \\(\\= 0\\.1\\.1\\)\n$")
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "soversion_not_zero")
+ set(shlibs_shlibs "^libtest_lib 0\\.8 generate_shlibs \\(\\= 0\\.1\\.1\\)\n$")
+else() # soversion_zero
+ set(shlibs_shlibs "^libtest_lib 0 generate_shlibs \\(\\= 0\\.1\\.1\\)\n$")
+endif()
+
# optional dot at the end of permissions regex is for SELinux enabled systems
set(shlibs_shlibs_permissions_regex "-rw-r--r--\.? .*")
verifyDebControl("${FOUND_FILE_1}" "shlibs" "shlibs")
diff --git a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake
index 90351ba43..e0eb67b84 100644
--- a/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake
+++ b/Tests/RunCMake/CPack/tests/GENERATE_SHLIBS/test.cmake
@@ -9,6 +9,11 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.hpp"
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp"
"#include \"test_lib.hpp\"\nint test_lib() {return 0;}\n")
add_library(test_lib SHARED "${CMAKE_CURRENT_BINARY_DIR}/test_lib.cpp")
-set_target_properties(test_lib PROPERTIES SOVERSION "0.8")
+
+if(RunCMake_SUBTEST_SUFFIX STREQUAL "soversion_not_zero")
+ set_target_properties(test_lib PROPERTIES SOVERSION "0.8")
+else() # soversion_zero
+ set_target_properties(test_lib PROPERTIES SOVERSION "0")
+endif()
install(TARGETS test_lib DESTINATION foo COMPONENT libs)
diff --git a/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake
index 44346ab8d..de38df9ef 100644
--- a/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/INSTALL_SCRIPTS/ExpectedFiles.cmake
@@ -1,5 +1,5 @@
set(EXPECTED_FILES_COUNT "2")
set(EXPECTED_FILE_1_COMPONENT "foo")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
set(EXPECTED_FILE_2_COMPONENT "bar")
-set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake
index 631d95704..4cb8dd0eb 100644
--- a/Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/LONG_FILENAMES/ExpectedFiles.cmake
@@ -1,3 +1,3 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/llllllllll_oooooooooo_nnnnnnnnnn_gggggggggg_ffffffffff_iiiiiiiiii_llllllllll_eeeeeeeeee_nnnnnnnnnn_aaaaaaaaaa_mmmmmmmmmm_eeeeeeeeee.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/llllllllll_oooooooooo_nnnnnnnnnn_gggggggggg_ffffffffff_iiiiiiiiii_llllllllll_eeeeeeeeee_nnnnnnnnnn_aaaaaaaaaa_mmmmmmmmmm_eeeeeeeeee.txt")
diff --git a/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake
index 6bfb0c19f..629be9ea5 100644
--- a/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/MAIN_COMPONENT/ExpectedFiles.cmake
@@ -3,9 +3,9 @@ set(EXPECTED_FILES_COUNT "0")
if(NOT RunCMake_SUBTEST_SUFFIX STREQUAL "invalid")
set(EXPECTED_FILES_COUNT "3")
set(EXPECTED_FILE_1 "main_component-0.1.1-1.*.rpm")
- set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
set(EXPECTED_FILE_2_COMPONENT "headers")
- set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
set(EXPECTED_FILE_3_COMPONENT "libs")
- set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/bas;/usr/bas/CMakeLists.txt")
+ set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/CMakeLists.txt")
endif()
diff --git a/Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake
index 6142eb39a..d1a3a5fb2 100644
--- a/Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/MD5SUMS/ExpectedFiles.cmake
@@ -1,2 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake
index 6142eb39a..d1a3a5fb2 100644
--- a/Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/MINIMAL/ExpectedFiles.cmake
@@ -1,2 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake
index eed5b92b0..c375aca9d 100644
--- a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/ExpectedFiles.cmake
@@ -2,5 +2,5 @@ set(EXPECTED_FILES_COUNT "0")
if(NOT ${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid")
set(EXPECTED_FILES_COUNT "1")
- set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
endif()
diff --git a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake
index e4f9618d3..2bb4d3ff9 100644
--- a/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake
+++ b/Tests/RunCMake/CPack/tests/PACKAGE_CHECKSUM/VerifyResult.cmake
@@ -1,8 +1,7 @@
if(NOT ${RunCMake_SUBTEST_SUFFIX} MATCHES "invalid")
- string(TOLOWER ${RunCMake_SUBTEST_SUFFIX} EXTENSION)
+ string(TOLOWER ${RunCMake_SUBTEST_SUFFIX} CHECKSUM_EXTENSION)
file(GLOB PACKAGE RELATIVE ${bin_dir} "*.tar.gz")
- file(GLOB CSUMFILE RELATIVE ${bin_dir} "*.${EXTENSION}")
- file(STRINGS ${CSUMFILE} CHSUM_VALUE)
+ file(STRINGS ${PACKAGE}.${CHECKSUM_EXTENSION} CHSUM_VALUE)
file(${RunCMake_SUBTEST_SUFFIX} ${PACKAGE} expected_value )
set(expected_value "${expected_value} ${PACKAGE}")
diff --git a/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake
index ae58c4b0c..137da470e 100644
--- a/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/PARTIALLY_RELOCATABLE_WARNING/ExpectedFiles.cmake
@@ -1,2 +1,4 @@
set(EXPECTED_FILES_COUNT "1")
+# don't set the prefix here as we have absolute paths that should not be prefixed
+set(EXPECTED_FILE_PACKAGING_PREFIX "")
set(EXPECTED_FILE_CONTENT_1_LIST "/not_relocatable;/not_relocatable/CMakeLists.txt;/opt")
diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake
index 9bdb176dd..26fa1df92 100644
--- a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/ExpectedFiles.cmake
@@ -1,8 +1,8 @@
set(EXPECTED_FILES_COUNT "3")
set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
set(EXPECTED_FILE_1_COMPONENT "pkg_1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
set(EXPECTED_FILE_2_NAME "second")
-set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_2_LIST "/foo;/foo/CMakeLists.txt")
set(EXPECTED_FILE_3_COMPONENT "pkg_3")
-set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_3_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake
index 18ef63cd8..b4bdb61b6 100644
--- a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake
+++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/VerifyResult.cmake
@@ -1,7 +1,7 @@
function(checkPackageInfo_ TYPE FILE REGEX)
getPackageInfo("${FILE}" "FILE_INFO_")
if(NOT FILE_INFO_ MATCHES "${REGEX}")
- message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}'; file info: '${FILE_INFO_}'")
+ message(FATAL_ERROR "Unexpected ${TYPE} in '${FILE}'; file info: '${FILE_INFO_}'; does not match '${REGEX}'")
endif()
endfunction()
@@ -24,3 +24,15 @@ checkPackageInfo_("name" "${FOUND_FILE_3}" ".*${name_}${whitespaces_}:${whitespa
checkPackageInfo_("group" "${FOUND_FILE_1}" ".*${group_}${whitespaces_}:${whitespaces_}default")
checkPackageInfo_("group" "${FOUND_FILE_2}" ".*${group_}${whitespaces_}:${whitespaces_}second_group")
checkPackageInfo_("group" "${FOUND_FILE_3}" ".*${group_}${whitespaces_}:${whitespaces_}default")
+
+# check package summaries (not available in DEB)
+if(GENERATOR_TYPE STREQUAL "RPM")
+ checkPackageInfo_("summary" "${FOUND_FILE_1}" ".*Summary${whitespaces_}:${whitespaces_}Global summary")
+ checkPackageInfo_("summary" "${FOUND_FILE_2}" ".*Summary${whitespaces_}:${whitespaces_}Summary for pkg_2")
+ checkPackageInfo_("summary" "${FOUND_FILE_3}" ".*Summary${whitespaces_}:${whitespaces_}Global summary")
+endif()
+
+# check package description
+checkPackageInfo_("description" "${FOUND_FILE_1}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_1")
+checkPackageInfo_("description" "${FOUND_FILE_2}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_2")
+checkPackageInfo_("description" "${FOUND_FILE_3}" ".*Description${whitespaces_}:${whitespaces_}Description for pkg_3")
diff --git a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake
index 8719c0b5e..dc61d0abb 100644
--- a/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake
+++ b/Tests/RunCMake/CPack/tests/PER_COMPONENT_FIELDS/test.cmake
@@ -11,6 +11,13 @@ if(GENERATOR_TYPE STREQUAL "DEB" OR GENERATOR_TYPE STREQUAL "RPM")
set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_${group_} "default")
set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_NAME "second")
set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_${group_} "second_group")
+
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PACKAGE_SUMMARY "Global summary") # not used for DEB
+ set(CPACK_${GENERATOR_TYPE}${generator_type_suffix_}_PKG_2_PACKAGE_SUMMARY "Summary for pkg_2") # not used for DEB
+
+ set(CPACK_COMPONENT_PKG_1_DESCRIPTION "Description for pkg_1")
+ set(CPACK_COMPONENT_PKG_2_DESCRIPTION "Description for pkg_2")
+ set(CPACK_COMPONENT_PKG_3_DESCRIPTION "Description for pkg_3")
endif()
install(FILES CMakeLists.txt DESTINATION foo COMPONENT pkg_1)
diff --git a/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake
index ca866eaa8..936e4ed80 100644
--- a/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/SINGLE_DEBUGINFO/ExpectedFiles.cmake
@@ -5,26 +5,26 @@ set(EXPECTED_FILES_NAME_GENERATOR_SPECIFIC_FORMAT TRUE)
if(RunCMake_SUBTEST_SUFFIX STREQUAL "valid" OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_debuginfo")
set(EXPECTED_FILES_COUNT "4")
set(EXPECTED_FILE_1 "single_debuginfo-0.1.1-1.*.rpm")
- set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/test_prog")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
set(EXPECTED_FILE_2 "single_debuginfo*-headers.rpm")
- set(EXPECTED_FILE_CONTENT_2_LIST "/usr;/usr/bar;/usr/bar/CMakeLists.txt")
+ set(EXPECTED_FILE_CONTENT_2_LIST "/bar;/bar/CMakeLists.txt")
set(EXPECTED_FILE_3 "single_debuginfo*-libs.rpm")
- set(EXPECTED_FILE_CONTENT_3_LIST "/usr;/usr/bas;/usr/bas/libtest_lib.so")
+ set(EXPECTED_FILE_CONTENT_3_LIST "/bas;/bas/libtest_lib.so")
set(EXPECTED_FILE_4_COMPONENT "debuginfo")
- set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp${whitespaces_}/src/src_1/test_lib.cpp.*")
+ set(EXPECTED_FILE_CONTENT_4 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp${whitespaces_}/src/src_1/test_lib.cpp.*\.debug.*")
elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "one_component" OR RunCMake_SUBTEST_SUFFIX STREQUAL "one_component_no_debuginfo")
set(EXPECTED_FILES_COUNT "2")
set(EXPECTED_FILE_1 "single_debuginfo-0*-applications.rpm")
- set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/test_prog")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
set(EXPECTED_FILE_2 "single_debuginfo-applications-debuginfo*.rpm")
- set(EXPECTED_FILE_CONTENT_2 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*")
+ set(EXPECTED_FILE_CONTENT_2 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
elseif(RunCMake_SUBTEST_SUFFIX STREQUAL "one_component_main" OR RunCMake_SUBTEST_SUFFIX STREQUAL "no_components")
set(EXPECTED_FILES_COUNT "2")
set(EXPECTED_FILE_1 "single_debuginfo-0*.rpm")
- set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/test_prog")
+ set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/test_prog")
set(EXPECTED_FILE_2 "single_debuginfo-debuginfo*.rpm")
- set(EXPECTED_FILE_CONTENT_2 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*")
+ set(EXPECTED_FILE_CONTENT_2 ".*/src${whitespaces_}/src/src_1${whitespaces_}/src/src_1/main.cpp.*\.debug.*")
endif()
diff --git a/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake
index 0a3e42635..d78f222a3 100644
--- a/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/SOURCE_PACKAGE/ExpectedFiles.cmake
@@ -1,2 +1,3 @@
set(EXPECTED_FILES_COUNT "1")
+set(EXPECTED_FILE_PACKAGING_PREFIX "")
set(EXPECTED_FILE_CONTENT_1_LIST "source_package-0.1.1.tar.gz;source_package.spec")
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake
index 6142eb39a..d1a3a5fb2 100644
--- a/Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/ExpectedFiles.cmake
@@ -1,2 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr;/usr/foo;/usr/foo/CMakeLists.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/foo;/foo/CMakeLists.txt")
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt b/Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt
index feb296cae..53d71d91f 100644
--- a/Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/RPM-stderr.txt
@@ -1 +1 @@
-^(.*CPackRPM:Warning: SUGGESTS not supported in provided rpmbuild.*)?CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM/CPack/[^-]*-build/_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec$
+^(.*CPackRPM:Warning: SUGGESTS not supported in provided rpmbuild.*)?CPackRPM: Will use GENERATED spec file: (/[^/]*)*/Tests/RunCMake/RPM\.SUGGESTS/CPack/[^-]*-build/_CPack_Packages/.*/RPM/SPECS/[^\.]*\.spec$
diff --git a/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake b/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
index 32cc6d1af..61ce752fe 100644
--- a/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
+++ b/Tests/RunCMake/CPack/tests/SUGGESTS/VerifyResult.cmake
@@ -13,7 +13,7 @@ if(NOT RPMBUILD_CAPS_RESULT)
endif()
# Only verify that suggests tag is present only if that tag is supported.
-# If it is not supported the rpm package was corretly generated by ignoring
+# If it is not supported the rpm package was correctly generated by ignoring
# that tag and that was already checked by expected files test.
if(should_contain_suggests_tag_)
execute_process(COMMAND ${RPM_EXECUTABLE} -q --suggests -p "${FOUND_FILE_1}"
diff --git a/Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake
index 05be748c1..e8281a8d3 100644
--- a/Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/SYMLINKS/ExpectedFiles.cmake
@@ -1,12 +1,11 @@
set(EXPECTED_FILES_COUNT "1")
set(EXPECTED_FILE_CONTENT_1_LIST
- "/usr"
- "/usr/empty_dir"
- "/usr/non_empty_dir"
- "/usr/non_empty_dir/CMakeLists.txt"
- "/usr/symlink_to_empty_dir"
- "/usr/symlink_to_non_empty_dir")
+ "/empty_dir"
+ "/non_empty_dir"
+ "/non_empty_dir/CMakeLists.txt"
+ "/symlink_to_empty_dir"
+ "/symlink_to_non_empty_dir")
if(PACKAGING_TYPE STREQUAL "COMPONENT")
set(EXPECTED_FILE_1_COMPONENT "links")
diff --git a/Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake b/Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake
index aabe53761..8420986f2 100644
--- a/Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake
+++ b/Tests/RunCMake/CPack/tests/USER_FILELIST/ExpectedFiles.cmake
@@ -1,2 +1,2 @@
set(EXPECTED_FILES_COUNT "1")
-set(EXPECTED_FILE_CONTENT_1_LIST "/usr/one;/usr/one/foo.txt;/usr/one/two;/usr/one/two/bar.txt;/usr/three;/usr/three/baz.txt;/usr/three/qux.txt")
+set(EXPECTED_FILE_CONTENT_1_LIST "/one;/one/foo.txt;/one/two;/one/two/bar.txt;/three;/three/baz.txt;/three/qux.txt")
diff --git a/Tests/RunCMake/CPackConfig/RunCMakeTest.cmake b/Tests/RunCMake/CPackConfig/RunCMakeTest.cmake
index 16d2cf39f..8f2196d5b 100644
--- a/Tests/RunCMake/CPackConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CPackConfig/RunCMakeTest.cmake
@@ -4,3 +4,6 @@ run_cmake(Simple)
run_cmake(Default)
run_cmake(Special)
run_cmake(Verbatim)
+run_cmake(Version1)
+run_cmake(Version2)
+run_cmake(Version3)
diff --git a/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake b/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake
index 1a373b928..8fc1218f2 100644
--- a/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake
+++ b/Tests/RunCMake/CPackInstallProperties/FilenameGenex.cmake
@@ -1,6 +1,6 @@
add_executable(mytest test.cpp)
-file(GENERATE OUTPUT runtest_info.cmake CONTENT [[
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/runtest_info.cmake CONTENT [[
set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>")
]])
diff --git a/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake b/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake
index 77fe8ed5d..b23d3c7df 100644
--- a/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake
+++ b/Tests/RunCMake/CPackInstallProperties/PerConfigValue.cmake
@@ -6,7 +6,7 @@ foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
OUTPUT_NAME_${UPPER_CONFIG} bar_${CONFIG})
endforeach()
-file(GENERATE OUTPUT runtest_info_$<CONFIG>.cmake CONTENT [[
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/runtest_info_$<CONFIG>.cmake CONTENT [[
set(CPACK_BUILD_CONFIG "$<CONFIG>")
set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>")
]])
diff --git a/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake b/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake
index 2e1d4656c..2001d9f4c 100644
--- a/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake
+++ b/Tests/RunCMake/CPackInstallProperties/ValueGenex.cmake
@@ -1,6 +1,6 @@
add_executable(mytest test.cpp)
-file(GENERATE OUTPUT runtest_info.cmake CONTENT [[
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/runtest_info.cmake CONTENT [[
set(EXPECTED_MYTEST_NAME "$<TARGET_FILE_NAME:mytest>")
]])
diff --git a/Tests/RunCMake/CTest/RunCMakeTest.cmake b/Tests/RunCMake/CTest/RunCMakeTest.cmake
index a6f684224..13922401e 100644
--- a/Tests/RunCMake/CTest/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CTest/RunCMakeTest.cmake
@@ -3,3 +3,5 @@ include(RunCMake)
set(RunCMake_TEST_OPTIONS -DNoProject=1)
run_cmake(BeforeProject)
unset(RunCMake_TEST_OPTIONS)
+
+run_cmake(NotOn)
diff --git a/Tests/RunCMake/CTestCommandLine/LabelCount-stdout.txt b/Tests/RunCMake/CTestCommandLine/LabelCount-stdout.txt
index 7fe04eb6a..9cfe41ca3 100644
--- a/Tests/RunCMake/CTestCommandLine/LabelCount-stdout.txt
+++ b/Tests/RunCMake/CTestCommandLine/LabelCount-stdout.txt
@@ -1,7 +1,7 @@
100% tests passed, 0 tests failed out of 4
+
+Label Time Summary:
-+'bar' = +[0-9.]+ sec \(3 tests\)
-+'foo' = +[0-9.]+ sec \(1 test\)
++'bar' = +[0-9.]+ sec\*proc \(3 tests\)
++'foo' = +[0-9.]+ sec\*proc \(1 test\)
+
Total Test time \(real\) = +[0-9.]+ sec
diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
index e936dab4c..b7f9a37ac 100644
--- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake
@@ -102,7 +102,7 @@ function(run_TestLoad name load)
add_test(TestLoad1 \"${CMAKE_COMMAND}\" -E echo \"test of --test-load\")
add_test(TestLoad2 \"${CMAKE_COMMAND}\" -E echo \"test of --test-load\")
")
- run_cmake_command(${name} ${CMAKE_CTEST_COMMAND} -j2 --test-load ${load} --test-timeout 5)
+ run_cmake_command(${name} ${CMAKE_CTEST_COMMAND} -j2 --test-load ${load})
endfunction()
# Tests for the --test-load feature of ctest
@@ -111,8 +111,8 @@ endfunction()
set(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING} 5)
# Verify that new tests are not started when the load average exceeds
-# our threshold.
-run_TestLoad(test-load-fail 2)
+# our threshold and that they then run once the load average drops.
+run_TestLoad(test-load-wait 3)
# Verify that warning message is displayed but tests still start when
# an invalid argument is given.
@@ -141,3 +141,74 @@ function(run_TestOutputSize)
)
endfunction()
run_TestOutputSize()
+
+function(run_TestAffinity)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TestAffinity)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ # Create a test with affinity enabled. The default PROCESSORS
+ # value is 1, so our expected output checks that this is the
+ # number of processors in the mask.
+ file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
+ add_test(Affinity \"${TEST_AFFINITY}\")
+ set_tests_properties(Affinity PROPERTIES PROCESSOR_AFFINITY ON)
+")
+ # Run ctest with a large parallel level so that the value is
+ # not responsible for capping the number of processors available.
+ run_cmake_command(TestAffinity ${CMAKE_CTEST_COMMAND} -V -j 64)
+endfunction()
+if(TEST_AFFINITY)
+ run_TestAffinity()
+endif()
+
+function(run_TestStdin)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TestStdin)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
+ add_test(TestStdin \"${TEST_PRINT_STDIN}\")
+ ")
+ run_cmake_command(TestStdin ${CMAKE_CTEST_COMMAND} -V)
+endfunction()
+run_TestStdin()
+
+function(show_only_json_check_python v)
+ if(RunCMake_TEST_FAILED OR NOT PYTHON_EXECUTABLE)
+ return()
+ endif()
+ set(json_file "${RunCMake_TEST_BINARY_DIR}/ctest.json")
+ file(WRITE "${json_file}" "${actual_stdout}")
+ set(actual_stdout "" PARENT_SCOPE)
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} "${RunCMake_SOURCE_DIR}/show-only_json-v${v}_check.py" "${json_file}"
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE output
+ ERROR_VARIABLE output
+ )
+ if(NOT result EQUAL 0)
+ string(REPLACE "\n" "\n " output " ${output}")
+ set(RunCMake_TEST_FAILED "Unexpected output:\n${output}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(run_ShowOnly)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ShowOnly)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" "
+ add_test(ShowOnly \"${CMAKE_COMMAND}\" -E echo)
+ set_tests_properties(ShowOnly PROPERTIES
+ WILL_FAIL true
+ REQUIRED_FILES RequiredFileDoesNotExist
+ _BACKTRACE_TRIPLES \"file1;1;add_test;file0;;\"
+ )
+ add_test(ShowOnlyNotAvailable NOT_AVAILABLE)
+")
+ run_cmake_command(show-only_human ${CMAKE_CTEST_COMMAND} --show-only=human)
+ run_cmake_command(show-only_bad ${CMAKE_CTEST_COMMAND} --show-only=bad)
+ run_cmake_command(show-only_json-v1 ${CMAKE_CTEST_COMMAND} --show-only=json-v1)
+endfunction()
+run_ShowOnly()
diff --git a/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake b/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake
index e14556944..b7d524ccf 100644
--- a/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake
@@ -8,6 +8,6 @@ run_cmake(not-supported-by-compiler)
run_cmake(save-to-result)
run_cmake(cmp0069-is-old)
-if(RunCMake_GENERATOR MATCHES "^Visual Studio ")
+if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
run_cmake(not-supported-by-generator)
endif()
diff --git a/Tests/RunCMake/CheckModules/RunCMakeTest.cmake b/Tests/RunCMake/CheckModules/RunCMakeTest.cmake
index 5b4e57edc..8a046e14c 100644
--- a/Tests/RunCMake/CheckModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CheckModules/RunCMakeTest.cmake
@@ -1,5 +1,7 @@
include(RunCMake)
+run_cmake(CMP0075)
+
run_cmake(CheckStructHasMemberOk)
run_cmake(CheckStructHasMemberUnknownLanguage)
run_cmake(CheckStructHasMemberMissingLanguage)
@@ -14,3 +16,9 @@ run_cmake(CheckTypeSizeUnknownArgument)
run_cmake(CheckTypeSizeMixedArgs)
run_cmake(CheckTypeSizeOkNoC)
+
+run_cmake(CheckIncludeFilesOk)
+run_cmake(CheckIncludeFilesOkNoC)
+run_cmake(CheckIncludeFilesMissingLanguage)
+run_cmake(CheckIncludeFilesUnknownArgument)
+run_cmake(CheckIncludeFilesUnknownLanguage)
diff --git a/Tests/RunCMake/CommandLine/C-no-file-stderr.txt b/Tests/RunCMake/CommandLine/C-no-file-stderr.txt
index 5315f5904..2a4ee6451 100644
--- a/Tests/RunCMake/CommandLine/C-no-file-stderr.txt
+++ b/Tests/RunCMake/CommandLine/C-no-file-stderr.txt
@@ -1,3 +1,3 @@
^CMake Error: Error processing file: nosuchcachefile.txt
-CMake Error: The source directory ".*/Tests/RunCMake/CommandLine/C-no-file-build/nosuchcachefile.txt" does not exist.
+CMake Error: The source directory ".*/Tests/RunCMake/CommandLine/C-no-file-build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.$
diff --git a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt
index 6c5ea44b3..b4b170ef2 100644
--- a/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt
+++ b/Tests/RunCMake/CommandLine/E_capabilities-stdout.txt
@@ -1 +1 @@
-^{.*}$
+^{"fileApi":{"requests":\[{"kind":"codemodel","version":\[{"major":2,"minor":0}]},{"kind":"cache","version":\[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":\[{"major":1,"minor":0}]}]},"generators":\[.*\],"serverMode":true,"version":{.*}}$
diff --git a/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake b/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake
index d7e652de7..5df5f2fb7 100644
--- a/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-broken-create-check.cmake
@@ -1,6 +1,10 @@
-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!")
+if(${actual_stderr_var} MATCHES "operation not permitted")
+ unset(msg)
+else()
+ 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()
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
index c078ae8fc..d37df0169 100644
--- a/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake
+++ b/Tests/RunCMake/CommandLine/E_create_symlink-broken-replace-check.cmake
@@ -1,3 +1,7 @@
-if(NOT IS_DIRECTORY ${RunCMake_TEST_BINARY_DIR}/L)
- set(RunCMake_TEST_FAILED "Symlink 'L' not replaced correctly!")
+if(${actual_stderr_var} MATCHES "operation not permitted")
+ unset(msg)
+else()
+ if(NOT IS_DIRECTORY ${RunCMake_TEST_BINARY_DIR}/L)
+ set(RunCMake_TEST_FAILED "Symlink 'L' not replaced correctly!")
+ endif()
endif()
diff --git a/Tests/RunCMake/CommandLine/NoArgs-stdout.txt b/Tests/RunCMake/CommandLine/NoArgs-stdout.txt
index 1cd34697b..f1dafc886 100644
--- a/Tests/RunCMake/CommandLine/NoArgs-stdout.txt
+++ b/Tests/RunCMake/CommandLine/NoArgs-stdout.txt
@@ -2,6 +2,7 @@
cmake \[options\] <path-to-source>
cmake \[options\] <path-to-existing-build>
+ cmake \[options\] -S <path-to-source> -B <path-to-build>
Specify a source directory to \(re-\)generate a build system for it in the
current working directory. Specify an existing build directory to
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index f94b10ac5..c9d3a4ddd 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -3,31 +3,43 @@ cmake_minimum_required(VERSION 3.1)
include(RunCMake)
run_cmake_command(NoArgs ${CMAKE_COMMAND})
-run_cmake_command(C-no-arg ${CMAKE_COMMAND} -C)
-run_cmake_command(C-no-file ${CMAKE_COMMAND} -C nosuchcachefile.txt)
+run_cmake_command(Wizard ${CMAKE_COMMAND} -i)
+run_cmake_command(C-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -C)
+run_cmake_command(C-no-file ${CMAKE_COMMAND} -B DummyBuildDir -C nosuchcachefile.txt)
+run_cmake_command(Cno-file ${CMAKE_COMMAND} -B DummyBuildDir -Cnosuchcachefile.txt)
run_cmake_command(cache-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeCache.txt)
run_cmake_command(lists-no-file ${CMAKE_COMMAND} nosuchsubdir/CMakeLists.txt)
-run_cmake_command(D-no-arg ${CMAKE_COMMAND} -D)
-run_cmake_command(U-no-arg ${CMAKE_COMMAND} -U)
+run_cmake_command(D-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -D)
+run_cmake_command(D-no-src ${CMAKE_COMMAND} -B DummyBuildDir -D VAR=VALUE)
+run_cmake_command(Dno-src ${CMAKE_COMMAND} -B DummyBuildDir -DVAR=VALUE)
+run_cmake_command(U-no-arg ${CMAKE_COMMAND} -B DummyBuildDir -U)
+run_cmake_command(U-no-src ${CMAKE_COMMAND} -B DummyBuildDir -U VAR)
+run_cmake_command(Uno-src ${CMAKE_COMMAND} -B DummyBuildDir -UVAR)
run_cmake_command(E-no-arg ${CMAKE_COMMAND} -E)
run_cmake_command(E_capabilities ${CMAKE_COMMAND} -E capabilities)
run_cmake_command(E_capabilities-arg ${CMAKE_COMMAND} -E capabilities --extra-arg)
+run_cmake_command(E_compare_files-different-eol ${CMAKE_COMMAND} -E compare_files ${RunCMake_SOURCE_DIR}/compare_files/lf ${RunCMake_SOURCE_DIR}/compare_files/crlf)
+run_cmake_command(E_compare_files-ignore-eol-same ${CMAKE_COMMAND} -E compare_files --ignore-eol ${RunCMake_SOURCE_DIR}/compare_files/lf ${RunCMake_SOURCE_DIR}/compare_files/crlf)
+run_cmake_command(E_compare_files-ignore-eol-empty ${CMAKE_COMMAND} -E compare_files --ignore-eol ${RunCMake_SOURCE_DIR}/compare_files/empty1 ${RunCMake_SOURCE_DIR}/compare_files/empty2)
+run_cmake_command(E_compare_files-ignore-eol-nonexistent ${CMAKE_COMMAND} -E compare_files --ignore-eol nonexistent_a nonexistent_b)
run_cmake_command(E_echo_append ${CMAKE_COMMAND} -E echo_append)
run_cmake_command(E_rename-no-arg ${CMAKE_COMMAND} -E rename)
run_cmake_command(E_server-arg ${CMAKE_COMMAND} -E server --extra-arg)
run_cmake_command(E_server-pipe ${CMAKE_COMMAND} -E server --pipe=)
+
run_cmake_command(E_touch_nocreate-no-arg ${CMAKE_COMMAND} -E touch_nocreate)
+run_cmake_command(E_touch-nonexistent-dir ${CMAKE_COMMAND} -E touch "${RunCMake_BINARY_DIR}/touch-nonexistent-dir/foo")
run_cmake_command(E_time ${CMAKE_COMMAND} -E time ${CMAKE_COMMAND} -E echo "hello world")
run_cmake_command(E_time-no-arg ${CMAKE_COMMAND} -E time)
-run_cmake_command(E___run_iwyu-no-iwyu ${CMAKE_COMMAND} -E __run_iwyu -- command-does-not-exist)
-run_cmake_command(E___run_iwyu-bad-iwyu ${CMAKE_COMMAND} -E __run_iwyu --iwyu=iwyu-does-not-exist -- command-does-not-exist)
-run_cmake_command(E___run_iwyu-no--- ${CMAKE_COMMAND} -E __run_iwyu --iwyu=iwyu-does-not-exist command-does-not-exist)
-run_cmake_command(E___run_iwyu-no-cc ${CMAKE_COMMAND} -E __run_iwyu --iwyu=iwyu-does-not-exist --)
+run_cmake_command(E___run_co_compile-no-iwyu ${CMAKE_COMMAND} -E __run_co_compile -- command-does-not-exist)
+run_cmake_command(E___run_co_compile-bad-iwyu ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist -- command-does-not-exist)
+run_cmake_command(E___run_co_compile-no--- ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist command-does-not-exist)
+run_cmake_command(E___run_co_compile-no-cc ${CMAKE_COMMAND} -E __run_co_compile --iwyu=iwyu-does-not-exist --)
-run_cmake_command(G_no-arg ${CMAKE_COMMAND} -G)
-run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -G NoSuchGenerator)
+run_cmake_command(G_no-arg ${CMAKE_COMMAND} -B DummyBuildDir -G)
+run_cmake_command(G_bad-arg ${CMAKE_COMMAND} -B DummyBuildDir -G NoSuchGenerator)
run_cmake_command(P_no-arg ${CMAKE_COMMAND} -P)
run_cmake_command(P_no-file ${CMAKE_COMMAND} -P nosuchscriptfile.cmake)
@@ -42,11 +54,61 @@ run_cmake_command(build-bad-dir
run_cmake_command(build-bad-generator
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-generator)
+run_cmake_command(install-no-dir
+ ${CMAKE_COMMAND} --install)
+run_cmake_command(install-bad-dir
+ ${CMAKE_COMMAND} --install dir-does-not-exist)
+run_cmake_command(install-options-to-vars
+ ${CMAKE_COMMAND} --install ${RunCMake_SOURCE_DIR}/dir-install-options-to-vars
+ --strip --prefix /var/test --config sample --component pack)
+
run_cmake_command(cache-bad-entry
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-bad-entry/)
run_cmake_command(cache-empty-entry
${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-empty-entry/)
+function(run_ExplicitDirs)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_NO_SOURCE_DIR 1)
+
+ set(source_dir ${RunCMake_BINARY_DIR}/ExplicitDirsMissing)
+
+ file(REMOVE_RECURSE "${source_dir}")
+ file(MAKE_DIRECTORY "${source_dir}")
+ file(WRITE ${source_dir}/CMakeLists.txt [=[
+cmake_minimum_required(VERSION 3.13)
+project(ExplicitDirsMissing LANGUAGES NONE)
+]=])
+ set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
+ set(RunCMake_TEST_BINARY_DIR "${source_dir}")
+ run_cmake_with_options(no-S-B -DFOO=BAR)
+
+ set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs)
+ set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build)
+
+ set(RunCMake_TEST_SOURCE_DIR "${source_dir}")
+ set(RunCMake_TEST_BINARY_DIR "${binary_dir}")
+
+ file(REMOVE_RECURSE "${binary_dir}")
+ run_cmake_with_options(S-arg -S ${source_dir} ${binary_dir})
+ run_cmake_with_options(S-arg-reverse-order ${binary_dir} -S${source_dir} )
+ run_cmake_with_options(S-no-arg -S )
+ run_cmake_with_options(S-no-arg2 -S -T)
+ run_cmake_with_options(S-B -S ${source_dir} -B ${binary_dir})
+
+ # make sure that -B can explicitly construct build directories
+ file(REMOVE_RECURSE "${binary_dir}")
+ run_cmake_with_options(B-arg -B ${binary_dir} ${source_dir})
+ file(REMOVE_RECURSE "${binary_dir}")
+ run_cmake_with_options(B-arg-reverse-order ${source_dir} -B${binary_dir})
+ run_cmake_with_options(B-no-arg -B )
+ run_cmake_with_options(B-no-arg2 -B -T)
+ file(REMOVE_RECURSE "${binary_dir}")
+ run_cmake_with_options(B-S -B${binary_dir} -S${source_dir})
+
+endfunction()
+run_ExplicitDirs()
+
function(run_BuildDir)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/BuildDir-build)
@@ -58,10 +120,128 @@ function(run_BuildDir)
run_cmake_command(BuildDir--build ${CMAKE_COMMAND} -E chdir ..
${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget)
run_cmake_command(BuildDir--build-multiple-targets ${CMAKE_COMMAND} -E chdir ..
- ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget2 --target CustomTarget3)
+ ${CMAKE_COMMAND} --build BuildDir-build -t CustomTarget2 --target CustomTarget3)
+ run_cmake_command(BuildDir--build-multiple-targets-jobs ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget CustomTarget2 -j2 --target CustomTarget3)
+ run_cmake_command(BuildDir--build-multiple-targets-with-clean-first ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --target clean CustomTarget)
+ run_cmake_command(BuildDir--build-multiple-targets-with-clean-second ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --target CustomTarget clean)
+ run_cmake_command(BuildDir--build-jobs-bad-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j 12ab)
+ run_cmake_command(BuildDir--build-jobs-good-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j 2)
+ run_cmake_command(BuildDir--build-jobs-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j 2 --target CustomTarget)
+ run_cmake_command(BuildDir--build--parallel-bad-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel 12ab)
+ run_cmake_command(BuildDir--build--parallel-good-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel 2)
+ run_cmake_command(BuildDir--build--parallel-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel 2 --target CustomTarget)
+ run_cmake_command(BuildDir--build-jobs-no-space-bad-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j12ab)
+ run_cmake_command(BuildDir--build-jobs-no-space-good-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j2)
+ run_cmake_command(BuildDir--build-jobs-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j2 --target CustomTarget)
+ run_cmake_command(BuildDir--build--parallel-no-space-bad-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel12ab)
+ run_cmake_command(BuildDir--build--parallel-no-space-good-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel2)
+ run_cmake_command(BuildDir--build--parallel-no-space-good-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel2 --target CustomTarget)
+ run_cmake_command(BuildDir--build-jobs-zero ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j 0)
+ run_cmake_command(BuildDir--build--parallel-zero ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel 0)
+ run_cmake_command(BuildDir--build-jobs-large ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j 4294967293)
+ run_cmake_command(BuildDir--build--parallel-large ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel 4294967293)
+
+ # No default jobs for Xcode and FreeBSD build command
+ if(NOT RunCMake_GENERATOR MATCHES "Xcode" AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ run_cmake_command(BuildDir--build-jobs-no-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j)
+ run_cmake_command(BuildDir--build-jobs-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build -j --target CustomTarget)
+ run_cmake_command(BuildDir--build--parallel-no-number ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel)
+ run_cmake_command(BuildDir--build--parallel-no-number-trailing--target ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build BuildDir-build --parallel --target CustomTarget)
+ endif()
endfunction()
run_BuildDir()
+function(run_EnvironmentGenerator)
+ set(source_dir ${RunCMake_SOURCE_DIR}/EnvGenerator)
+
+ set(ENV{CMAKE_GENERATOR_INSTANCE} "instance")
+ set(ENV{CMAKE_GENERATOR_PLATFORM} "platform")
+ set(ENV{CMAKE_GENERATOR_TOOLSET} "toolset")
+ run_cmake_command(Envgen-warnings ${CMAKE_COMMAND} -G)
+ unset(ENV{CMAKE_GENERATOR_INSTANCE})
+ unset(ENV{CMAKE_GENERATOR_PLATFORM})
+ unset(ENV{CMAKE_GENERATOR_TOOLSET})
+
+ # Test CMAKE_GENERATOR without actual configuring
+ run_cmake_command(Envgen-unset ${CMAKE_COMMAND} -G)
+ set(ENV{CMAKE_GENERATOR} "Ninja")
+ run_cmake_command(Envgen-ninja ${CMAKE_COMMAND} -G)
+ set(ENV{CMAKE_GENERATOR} "NoSuchGenerator")
+ run_cmake_command(Envgen-bad ${CMAKE_COMMAND} -G)
+ unset(ENV{CMAKE_GENERATOR})
+
+ if(RunCMake_GENERATOR MATCHES "Visual Studio.*")
+ set(ENV{CMAKE_GENERATOR} "${RunCMake_GENERATOR}")
+ run_cmake_command(Envgen ${CMAKE_COMMAND} ${source_dir})
+ # Toolset is available since VS 2010.
+ if(RunCMake_GENERATOR MATCHES "Visual Studio [1-9][0-9]")
+ set(ENV{CMAKE_GENERATOR_TOOLSET} "invalid")
+ # Envvar shouldn't affect existing build tree
+ run_cmake_command(Envgen-toolset-existing ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build Envgen-build)
+ run_cmake_command(Envgen-toolset-invalid ${CMAKE_COMMAND} ${source_dir})
+ # Command line -G implies -T""
+ run_cmake_command(Envgen-G-implicit-toolset ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
+ run_cmake_command(Envgen-T-toolset ${CMAKE_COMMAND} -T "fromcli" ${source_dir})
+ unset(ENV{CMAKE_GENERATOR_TOOLSET})
+ endif()
+ # Platform can be set only if not in generator name.
+ if(RunCMake_GENERATOR MATCHES "^Visual Studio [0-9]+ [0-9]+$")
+ set(ENV{CMAKE_GENERATOR_PLATFORM} "invalid")
+ # Envvar shouldn't affect existing build tree
+ run_cmake_command(Envgen-platform-existing ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build Envgen-build)
+ if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
+ set(RunCMake-stderr-file "Envgen-platform-invalid-stderr-vs9.txt")
+ endif()
+ run_cmake_command(Envgen-platform-invalid ${CMAKE_COMMAND} ${source_dir})
+ unset(RunCMake-stderr-file)
+ # Command line -G implies -A""
+ run_cmake_command(Envgen-G-implicit-platform ${CMAKE_COMMAND} -G "${RunCMake_GENERATOR}" ${source_dir})
+ if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ")
+ set(RunCMake-stderr-file "Envgen-A-platform-stderr-vs9.txt")
+ endif()
+ run_cmake_command(Envgen-A-platform ${CMAKE_COMMAND} -A "fromcli" ${source_dir})
+ unset(RunCMake-stderr-file)
+ unset(ENV{CMAKE_GENERATOR_PLATFORM})
+ endif()
+ # Instance is available since VS 2017.
+ if(RunCMake_GENERATOR MATCHES "Visual Studio (15|16).*")
+ set(ENV{CMAKE_GENERATOR_INSTANCE} "invalid")
+ # Envvar shouldn't affect existing build tree
+ run_cmake_command(Envgen-instance-existing ${CMAKE_COMMAND} -E chdir ..
+ ${CMAKE_COMMAND} --build Envgen-build)
+ run_cmake_command(Envgen-instance-invalid ${CMAKE_COMMAND} ${source_dir})
+ unset(ENV{CMAKE_GENERATOR_INSTANCE})
+ endif()
+ unset(ENV{CMAKE_GENERATOR})
+ endif()
+endfunction()
+run_EnvironmentGenerator()
+
if(RunCMake_GENERATOR STREQUAL "Ninja")
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Build-build)
@@ -78,39 +258,35 @@ if(RunCMake_GENERATOR STREQUAL "Ninja")
unset(RunCMake_TEST_NO_CLEAN)
endif()
-if(RunCMake_GENERATOR MATCHES "^Visual Studio 8 2005")
- set(RunCMake_WARN_VS8 1)
- run_cmake(DeprecateVS8-WARN-ON)
- unset(RunCMake_WARN_VS8)
- run_cmake(DeprecateVS8-WARN-OFF)
-endif()
-
-if(UNIX)
- run_cmake_command(E_create_symlink-no-arg
- ${CMAKE_COMMAND} -E create_symlink
- )
- run_cmake_command(E_create_symlink-missing-dir
- ${CMAKE_COMMAND} -E create_symlink T missing-dir/L
- )
+run_cmake_command(E_create_symlink-no-arg
+ ${CMAKE_COMMAND} -E create_symlink
+ )
+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)
+# Use a single build tree for a few tests without cleaning.
+# These tests are special on Windows since it will only fail if the user
+# running the test does not have the priveldge to create symlinks. If this
+# happens we clear the msg in the -check.cmake and say that the test passes
+set(RunCMake_DEFAULT_stderr "(operation not permitted)?")
+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)
+unset(RunCMake_DEFAULT_stderr)
- run_cmake_command(E_create_symlink-no-replace-dir
- ${CMAKE_COMMAND} -E create_symlink T .
- )
-endif()
+run_cmake_command(E_create_symlink-no-replace-dir
+ ${CMAKE_COMMAND} -E create_symlink T .
+ )
set(in ${RunCMake_SOURCE_DIR}/copy_input)
set(out ${RunCMake_BINARY_DIR}/copy_output)
@@ -158,10 +334,16 @@ file(MAKE_DIRECTORY ${out})
file(WRITE ${outfile} "")
run_cmake_command(E_make_directory-three-directories
${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${out}/d2)
+run_cmake_command(E_remove_directory-three-directories
+ ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${out}/d2)
run_cmake_command(E_make_directory-directory-with-parent
${CMAKE_COMMAND} -E make_directory ${out}/parent/child)
-run_cmake_command(E_make_directory-three-directories-and-file
+run_cmake_command(E_remove_directory-directory-with-parent
+ ${CMAKE_COMMAND} -E remove_directory ${out}/parent)
+run_cmake_command(E_make_directory-two-directories-and-file
${CMAKE_COMMAND} -E make_directory ${out}/d1 ${out}/d2 ${outfile})
+run_cmake_command(E_remove_directory-two-directories-and-file
+ ${CMAKE_COMMAND} -E remove_directory ${out}/d1 ${out}/d2 ${outfile})
unset(out)
unset(outfile)
@@ -172,6 +354,30 @@ 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_md5sum-dir ${CMAKE_COMMAND} -E md5sum .)
+run_cmake_command(E_sha1sum-dir ${CMAKE_COMMAND} -E sha1sum .)
+run_cmake_command(E_sha224sum-dir ${CMAKE_COMMAND} -E sha224sum .)
+run_cmake_command(E_sha256sum-dir ${CMAKE_COMMAND} -E sha256sum .)
+run_cmake_command(E_sha384sum-dir ${CMAKE_COMMAND} -E sha384sum .)
+run_cmake_command(E_sha512sum-dir ${CMAKE_COMMAND} -E sha512sum .)
+
+run_cmake_command(E_md5sum-no-file ${CMAKE_COMMAND} -E md5sum nonexisting)
+run_cmake_command(E_sha1sum-no-file ${CMAKE_COMMAND} -E sha1sum nonexisting)
+run_cmake_command(E_sha224sum-no-file ${CMAKE_COMMAND} -E sha224sum nonexisting)
+run_cmake_command(E_sha256sum-no-file ${CMAKE_COMMAND} -E sha256sum nonexisting)
+run_cmake_command(E_sha384sum-no-file ${CMAKE_COMMAND} -E sha384sum nonexisting)
+run_cmake_command(E_sha512sum-no-file ${CMAKE_COMMAND} -E sha512sum nonexisting)
+
+file(WRITE "${RunCMake_BINARY_DIR}/dummy" "dummy")
+run_cmake_command(E_md5sum ${CMAKE_COMMAND} -E md5sum ../dummy)
+run_cmake_command(E_md5sum-mixed ${CMAKE_COMMAND} -E md5sum . ../dummy nonexisting)
+run_cmake_command(E_sha1sum ${CMAKE_COMMAND} -E sha1sum ../dummy)
+run_cmake_command(E_sha224sum ${CMAKE_COMMAND} -E sha224sum ../dummy)
+run_cmake_command(E_sha256sum ${CMAKE_COMMAND} -E sha256sum ../dummy)
+run_cmake_command(E_sha384sum ${CMAKE_COMMAND} -E sha384sum ../dummy)
+run_cmake_command(E_sha512sum ${CMAKE_COMMAND} -E sha512sum ../dummy)
+file(REMOVE "${RunCMake_BINARY_DIR}/dummy")
+
set(RunCMake_DEFAULT_stderr ".")
run_cmake_command(E_sleep-no-args ${CMAKE_COMMAND} -E sleep)
unset(RunCMake_DEFAULT_stderr)
@@ -254,9 +460,9 @@ set(RunCMake_TEST_OPTIONS -Wdev -Wno-dev)
run_cmake(Wno-dev)
unset(RunCMake_TEST_OPTIONS)
-run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -W)
-run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -Wno-)
-run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -Werror=)
+run_cmake_command(W_bad-arg1 ${CMAKE_COMMAND} -B DummyBuildDir -W)
+run_cmake_command(W_bad-arg2 ${CMAKE_COMMAND} -B DummyBuildDir -Wno-)
+run_cmake_command(W_bad-arg3 ${CMAKE_COMMAND} -B DummyBuildDir -Werror=)
set(RunCMake_TEST_OPTIONS --debug-output)
run_cmake(debug-output)
@@ -270,6 +476,14 @@ set(RunCMake_TEST_OPTIONS --trace-expand)
run_cmake(trace-expand)
unset(RunCMake_TEST_OPTIONS)
+set(RunCMake_TEST_OPTIONS --trace-expand --warn-uninitialized)
+run_cmake(trace-expand-warn-uninitialized)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS -Wno-deprecated --warn-uninitialized)
+run_cmake(warn-uninitialized)
+unset(RunCMake_TEST_OPTIONS)
+
set(RunCMake_TEST_OPTIONS --trace-source=trace-only-this-file.cmake)
run_cmake(trace-source)
unset(RunCMake_TEST_OPTIONS)
@@ -313,4 +527,8 @@ function(reject_fifo)
endfunction()
if(CMAKE_HOST_UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL "CYGWIN")
reject_fifo()
+ run_cmake_command(closed_stdin sh -c "\"${CMAKE_COMMAND}\" --version <&-")
+ run_cmake_command(closed_stdout sh -c "\"${CMAKE_COMMAND}\" --version >&-")
+ run_cmake_command(closed_stderr sh -c "\"${CMAKE_COMMAND}\" --version 2>&-")
+ run_cmake_command(closed_stdall sh -c "\"${CMAKE_COMMAND}\" --version <&- >&- 2>&-")
endif()
diff --git a/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt b/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
index e9be1dcb3..30385f88e 100644
--- a/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Wdeprecated-stderr.txt
@@ -1,4 +1,4 @@
^CMake Deprecation Warning at Wdeprecated.cmake:1 \(message\):
Some deprecated warning
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CommandLine/Wdev-stderr.txt b/Tests/RunCMake/CommandLine/Wdev-stderr.txt
index 88cfb3a30..172fb8155 100644
--- a/Tests/RunCMake/CommandLine/Wdev-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Wdev-stderr.txt
@@ -1,11 +1,11 @@
^CMake Warning \(dev\) at Wdev.cmake:1 \(message\):
Some author warning
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning \(dev\) at Wdev.cmake:6 \(include\):
include\(\) given empty file name \(ignored\).
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt b/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
index 6acdc7362..d681836b2 100644
--- a/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Werror_deprecated-stderr.txt
@@ -1,4 +1,4 @@
^CMake Deprecation Error at Werror_deprecated.cmake:1 \(message\):
Some deprecated warning
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CommandLine/Werror_dev-stderr.txt b/Tests/RunCMake/CommandLine/Werror_dev-stderr.txt
index 590ec96d3..35890fc99 100644
--- a/Tests/RunCMake/CommandLine/Werror_dev-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Werror_dev-stderr.txt
@@ -1,11 +1,11 @@
^CMake Error \(dev\) at Werror_dev.cmake:4 \(include\):
include\(\) given empty file name \(ignored\).
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This error is for project developers. Use -Wno-error=dev to suppress it.
CMake Error \(dev\) at Werror_dev.cmake:7 \(message\):
Some author warning
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This error is for project developers. Use -Wno-error=dev to suppress it.$
diff --git a/Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt b/Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt
index 0ed169861..45897062d 100644
--- a/Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Wno-error_deprecated-stderr.txt
@@ -1,4 +1,4 @@
^CMake Deprecation Warning at Wno-error_deprecated.cmake:2 \(message\):
Some deprecated warning
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt b/Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt
index dd22d5568..ee28d7f02 100644
--- a/Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt
+++ b/Tests/RunCMake/CommandLine/Wno-error_dev-stderr.txt
@@ -1,11 +1,11 @@
^CMake Warning \(dev\) at Wno-error_dev.cmake:2 \(message\):
Some author warning
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning \(dev\) at Wno-error_dev.cmake:6 \(include\):
include\(\) given empty file name \(ignored\).
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake
index 12635dbfb..a64af9524 100644
--- a/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLineTar/RunCMakeTest.cmake
@@ -4,25 +4,33 @@ function(external_command_test NAME)
run_cmake_command(${NAME} ${CMAKE_COMMAND} -E ${ARGN})
endfunction()
-external_command_test(bad-opt1 tar cvf bad.tar --bad)
-external_command_test(bad-mtime1 tar cvf bad.tar --mtime=bad .)
-external_command_test(bad-from1 tar cvf bad.tar --files-from=bad)
-external_command_test(bad-from2 tar cvf bad.tar --files-from=.)
-external_command_test(bad-from3 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from3.txt)
-external_command_test(bad-from4 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from4.txt)
-external_command_test(bad-from5 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from5.txt)
-external_command_test(end-opt1 tar cvf bad.tar -- --bad)
-external_command_test(end-opt2 tar cvf bad.tar --)
-external_command_test(mtime tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC")
-external_command_test(bad-format tar cvf bad.tar "--format=bad-format")
-external_command_test(zip-bz2 tar cvjf bad.tar "--format=zip")
-external_command_test(7zip-gz tar cvzf bad.tar "--format=7zip")
+external_command_test(without-files tar cvf bad.tar)
+external_command_test(bad-opt1 tar cvf bad.tar --bad)
+external_command_test(bad-mtime1 tar cvf bad.tar --mtime=bad .)
+external_command_test(bad-from1 tar cvf bad.tar --files-from=bad)
+external_command_test(bad-from2 tar cvf bad.tar --files-from=.)
+external_command_test(bad-from3 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from3.txt)
+external_command_test(bad-from4 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from4.txt)
+external_command_test(bad-from5 tar cvf bad.tar --files-from=${CMAKE_CURRENT_LIST_DIR}/bad-from5.txt)
+external_command_test(bad-file tar cf bad.tar badfile.txt ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(bad-without-action tar f bad.tar ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(bad-wrong-flag tar cvfq bad.tar ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(end-opt1 tar cvf bad.tar -- --bad)
+external_command_test(end-opt2 tar cvf bad.tar --)
+external_command_test(mtime tar cvf bad.tar "--mtime=1970-01-01 00:00:00 UTC" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(bad-format tar cvf bad.tar "--format=bad-format" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(zip-bz2 tar cvjf bad.tar "--format=zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
+external_command_test(7zip-gz tar cvzf bad.tar "--format=7zip" ${CMAKE_CURRENT_LIST_DIR}/test-file.txt)
run_cmake(7zip)
run_cmake(gnutar)
run_cmake(gnutar-gz)
run_cmake(pax)
run_cmake(pax-xz)
+run_cmake(pax-zstd)
run_cmake(paxr)
run_cmake(paxr-bz2)
run_cmake(zip)
+
+# Extracting only selected files or directories
+run_cmake(zip-filtered)
diff --git a/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt
index 1417d4d32..fb0702a1a 100644
--- a/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt
+++ b/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt
@@ -1,2 +1,2 @@
-^CMake Error: archive_read_disk_entry_from_file 'does-not-exist':.*
+^CMake Error: Unable to read from file 'does-not-exist':.*
CMake Error: Problem creating tar: bad.tar$
diff --git a/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt
index 1417d4d32..fb0702a1a 100644
--- a/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt
+++ b/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt
@@ -1,2 +1,2 @@
-^CMake Error: archive_read_disk_entry_from_file 'does-not-exist':.*
+^CMake Error: Unable to read from file 'does-not-exist':.*
CMake Error: Problem creating tar: bad.tar$
diff --git a/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt b/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt
index 1fddf6d2d..1342dc8d0 100644
--- a/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt
+++ b/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt
@@ -1,2 +1,2 @@
-^CMake Error: archive_read_disk_entry_from_file '--bad':.*
+^CMake Error: Unable to read from file '--bad':.*
CMake Error: Problem creating tar: bad.tar$
diff --git a/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake b/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake
index 5f2674a8f..53ee96186 100644
--- a/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake
+++ b/Tests/RunCMake/CommandLineTar/gnutar-gz.cmake
@@ -1,9 +1,9 @@
set(OUTPUT_NAME "test.tar.gz")
-set(COMPRESSION_FLAGS cvzf)
+set(COMPRESSION_FLAGS -cvzf)
set(COMPRESSION_OPTIONS --format=gnutar)
-set(DECOMPRESSION_FLAGS xvzf)
+set(DECOMPRESSION_FLAGS -xvzf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/CommandLineTar/pax.cmake b/Tests/RunCMake/CommandLineTar/pax.cmake
index 60ed2385c..77f74d135 100644
--- a/Tests/RunCMake/CommandLineTar/pax.cmake
+++ b/Tests/RunCMake/CommandLineTar/pax.cmake
@@ -1,9 +1,9 @@
set(OUTPUT_NAME "test.tar")
-set(COMPRESSION_FLAGS cvf)
+set(COMPRESSION_FLAGS -cvf)
set(COMPRESSION_OPTIONS --format=pax)
-set(DECOMPRESSION_FLAGS xvf)
+set(DECOMPRESSION_FLAGS -xvf)
include(${CMAKE_CURRENT_LIST_DIR}/roundtrip.cmake)
diff --git a/Tests/RunCMake/CommandLineTar/roundtrip.cmake b/Tests/RunCMake/CommandLineTar/roundtrip.cmake
index dc1c88528..fa63d1240 100644
--- a/Tests/RunCMake/CommandLineTar/roundtrip.cmake
+++ b/Tests/RunCMake/CommandLineTar/roundtrip.cmake
@@ -47,7 +47,11 @@ file(REMOVE_RECURSE ${FULL_DECOMPRESS_DIR})
file(MAKE_DIRECTORY ${FULL_DECOMPRESS_DIR})
run_tar(${CMAKE_CURRENT_BINARY_DIR} ${COMPRESSION_FLAGS} ${FULL_OUTPUT_NAME} ${COMPRESSION_OPTIONS} ${COMPRESS_DIR})
-run_tar(${FULL_DECOMPRESS_DIR} ${DECOMPRESSION_FLAGS} ${FULL_OUTPUT_NAME} ${DECOMPRESSION_OPTIONS})
+run_tar(${FULL_DECOMPRESS_DIR} ${DECOMPRESSION_FLAGS} ${FULL_OUTPUT_NAME} ${DECOMPRESSION_OPTIONS} -- ${DECOMPRESSION_PATHNAMES})
+
+if(CUSTOM_CHECK_FILES)
+ set(CHECK_FILES ${CUSTOM_CHECK_FILES})
+endif()
foreach(file ${CHECK_FILES})
set(input ${FULL_COMPRESS_DIR}/${file})
@@ -69,6 +73,14 @@ foreach(file ${CHECK_FILES})
endif()
endforeach()
+foreach(file ${NOT_EXISTING_FILES_CHECK})
+ set(output ${FULL_DECOMPRESS_DIR}/${COMPRESS_DIR}/${file})
+
+ if(EXISTS ${output})
+ message(SEND_ERROR "File ${output} exists but it shouldn't")
+ endif()
+endforeach()
+
function(check_magic EXPECTED)
file(READ ${FULL_OUTPUT_NAME} ACTUAL
${ARGN}
diff --git a/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake b/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake
index 5884d5c4d..bb8da037a 100644
--- a/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CompilerLauncher/RunCMakeTest.cmake
@@ -15,9 +15,17 @@ function(run_compiler_launcher lang)
run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
endfunction()
-run_compiler_launcher(C)
-run_compiler_launcher(CXX)
-if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
- run_compiler_launcher(C-launch)
- run_compiler_launcher(CXX-launch)
+set(langs C CXX)
+if(CMake_TEST_CUDA)
+ list(APPEND langs CUDA)
endif()
+if(CMake_TEST_Fortran)
+ list(APPEND langs Fortran)
+endif()
+
+foreach(lang ${langs})
+ run_compiler_launcher(${lang})
+ if (NOT RunCMake_GENERATOR STREQUAL "Watcom WMake")
+ run_compiler_launcher(${lang}-launch)
+ endif()
+endforeach()
diff --git a/Tests/RunCMake/Cpplint/C-error-Build-result.txt b/Tests/RunCMake/Cpplint/C-error-Build-result.txt
index d197c913c..573541ac9 100644
--- a/Tests/RunCMake/Cpplint/C-error-Build-result.txt
+++ b/Tests/RunCMake/Cpplint/C-error-Build-result.txt
@@ -1 +1 @@
-[^0]
+0
diff --git a/Tests/RunCMake/Cpplint/C-error-launch-Build-result.txt b/Tests/RunCMake/Cpplint/C-error-launch-Build-result.txt
index d197c913c..573541ac9 100644
--- a/Tests/RunCMake/Cpplint/C-error-launch-Build-result.txt
+++ b/Tests/RunCMake/Cpplint/C-error-launch-Build-result.txt
@@ -1 +1 @@
-[^0]
+0
diff --git a/Tests/RunCMake/Cpplint/CXX-error-Build-result.txt b/Tests/RunCMake/Cpplint/CXX-error-Build-result.txt
index d197c913c..573541ac9 100644
--- a/Tests/RunCMake/Cpplint/CXX-error-Build-result.txt
+++ b/Tests/RunCMake/Cpplint/CXX-error-Build-result.txt
@@ -1 +1 @@
-[^0]
+0
diff --git a/Tests/RunCMake/Cpplint/CXX-error-launch-Build-result.txt b/Tests/RunCMake/Cpplint/CXX-error-launch-Build-result.txt
index d197c913c..573541ac9 100644
--- a/Tests/RunCMake/Cpplint/CXX-error-launch-Build-result.txt
+++ b/Tests/RunCMake/Cpplint/CXX-error-launch-Build-result.txt
@@ -1 +1 @@
-[^0]
+0
diff --git a/Tests/RunCMake/CrosscompilingEmulator/AddCustomCommand.cmake b/Tests/RunCMake/CrosscompilingEmulator/AddCustomCommand.cmake
index c4db11bde..9fcc5bcd7 100644
--- a/Tests/RunCMake/CrosscompilingEmulator/AddCustomCommand.cmake
+++ b/Tests/RunCMake/CrosscompilingEmulator/AddCustomCommand.cmake
@@ -26,12 +26,14 @@ add_custom_command(OUTPUT output2
# DoesNotUseEmulator: The command will fail if emulator is prepended
add_custom_command(OUTPUT output3
+ COMMAND ${CMAKE_COMMAND} -E echo generated_exe_emulator_unexpected
COMMAND $<TARGET_FILE:generated_exe_emulator_unexpected>
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/output3
DEPENDS generated_exe_emulator_unexpected)
# DoesNotUseEmulator: The command will fail if emulator is prepended
add_custom_command(OUTPUT outputImp
+ COMMAND ${CMAKE_COMMAND} -E echo generated_exe_emulator_unexpected_imported
COMMAND generated_exe_emulator_unexpected_imported
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/outputImp
)
@@ -39,6 +41,7 @@ add_custom_command(OUTPUT outputImp
# UsesEmulator: The command only succeeds if the emulator is prepended
# to the command.
add_custom_command(OUTPUT output4
+ COMMAND ${CMAKE_COMMAND} -E echo generated_exe_emulator_expected
COMMAND generated_exe_emulator_expected
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/output4
DEPENDS generated_exe_emulator_expected)
diff --git a/Tests/RunCMake/CrosscompilingEmulator/CrosscompilingEmulatorProperty.cmake b/Tests/RunCMake/CrosscompilingEmulator/CrosscompilingEmulatorProperty.cmake
index 1aeb510f0..2fdefc4ce 100644
--- a/Tests/RunCMake/CrosscompilingEmulator/CrosscompilingEmulatorProperty.cmake
+++ b/Tests/RunCMake/CrosscompilingEmulator/CrosscompilingEmulatorProperty.cmake
@@ -26,3 +26,9 @@ get_property(emulator TARGET target_without_emulator
if(NOT "${emulator}" STREQUAL "")
message(SEND_ERROR "Default CROSSCOMPILING_EMULATOR property not set to null")
endif()
+
+add_executable(target_with_empty_emulator simple_src_exiterror.cxx)
+set_property(TARGET target_with_empty_emulator PROPERTY CROSSCOMPILING_EMULATOR "")
+
+enable_testing()
+add_test(NAME test_target_with_empty_emulator COMMAND target_with_empty_emulator)
diff --git a/Tests/RunCMake/CrosscompilingEmulator/RunCMakeTest.cmake b/Tests/RunCMake/CrosscompilingEmulator/RunCMakeTest.cmake
index 71aaad19b..97b7b5a31 100644
--- a/Tests/RunCMake/CrosscompilingEmulator/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CrosscompilingEmulator/RunCMakeTest.cmake
@@ -11,13 +11,18 @@ function(CustomCommandGenerator_run_and_build case)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
set(RunCMake_TEST_NO_CLEAN 1)
- set(RunCMake_TEST_OPTIONS
- "-DCMAKE_CROSSCOMPILING_EMULATOR=${PSEUDO_EMULATOR_CUSTOM_COMMAND}")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(${case})
run_cmake_command(${case}-build ${CMAKE_COMMAND} --build .)
endfunction()
+set(RunCMake_TEST_OPTIONS
+"-DCMAKE_CROSSCOMPILING_EMULATOR=${PSEUDO_EMULATOR_CUSTOM_COMMAND}")
CustomCommandGenerator_run_and_build(AddCustomCommand)
CustomCommandGenerator_run_and_build(AddCustomTarget)
+
+set(RunCMake_TEST_OPTIONS
+"-DCMAKE_CROSSCOMPILING_EMULATOR=${PSEUDO_EMULATOR_CUSTOM_COMMAND_ARG}\;custom_argument")
+CustomCommandGenerator_run_and_build(AddCustomCommandWithArg)
+CustomCommandGenerator_run_and_build(AddCustomTargetWithArg)
diff --git a/Tests/RunCMake/ExternalData/BadAlgoMap1-stderr.txt b/Tests/RunCMake/ExternalData/BadAlgoMap1-stderr.txt
index c3708a9c8..5388c46de 100644
--- a/Tests/RunCMake/ExternalData/BadAlgoMap1-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadAlgoMap1-stderr.txt
@@ -5,5 +5,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
The transform name must be a valid C identifier.
Call Stack \(most recent call first\):
- BadAlgoMap1.cmake:[0-9]+ \(ExternalData_Add_Target\)
- CMakeLists.txt:3 \(include\)
+ BadAlgoMap1\.cmake:[0-9]+ \(ExternalData_Add_Target\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadAlgoMap2-stderr.txt b/Tests/RunCMake/ExternalData/BadAlgoMap2-stderr.txt
index 1f10644dc..a48e41455 100644
--- a/Tests/RunCMake/ExternalData/BadAlgoMap2-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadAlgoMap2-stderr.txt
@@ -5,5 +5,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
The transform name must be a valid C identifier.
Call Stack \(most recent call first\):
- BadAlgoMap2.cmake:[0-9]+ \(ExternalData_Add_Target\)
- CMakeLists.txt:3 \(include\)
+ BadAlgoMap2\.cmake:[0-9]+ \(ExternalData_Add_Target\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt b/Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt
index f68f0be6b..1f9f6b51b 100644
--- a/Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadHashAlgo1-stderr.txt
@@ -4,5 +4,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
BAD
Call Stack \(most recent call first\):
.*
- BadHashAlgo1.cmake:3 \(ExternalData_Expand_Arguments\)
- CMakeLists.txt:3 \(include\)
+ BadHashAlgo1\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadOption1-stderr.txt b/Tests/RunCMake/ExternalData/BadOption1-stderr.txt
index b63d098c0..fece87703 100644
--- a/Tests/RunCMake/ExternalData/BadOption1-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadOption1-stderr.txt
@@ -5,5 +5,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Call Stack \(most recent call first\):
.*
- BadOption1.cmake:2 \(ExternalData_Add_Test\)
- CMakeLists.txt:3 \(include\)
+ BadOption1\.cmake:[0-9]+ \(ExternalData_Add_Test\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadOption2-stderr.txt b/Tests/RunCMake/ExternalData/BadOption2-stderr.txt
index d114c8aa9..865552aca 100644
--- a/Tests/RunCMake/ExternalData/BadOption2-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadOption2-stderr.txt
@@ -5,5 +5,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Call Stack \(most recent call first\):
.*
- BadOption2.cmake:2 \(ExternalData_Add_Test\)
- CMakeLists.txt:3 \(include\)
+ BadOption2\.cmake:[0-9]+ \(ExternalData_Add_Test\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadRecurse1-stderr.txt b/Tests/RunCMake/ExternalData/BadRecurse1-stderr.txt
index aedc33015..9d04693ca 100644
--- a/Tests/RunCMake/ExternalData/BadRecurse1-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadRecurse1-stderr.txt
@@ -2,5 +2,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Recurse option "RECURSE:" allowed only with directories.
Call Stack \(most recent call first\):
.*
- BadRecurse1.cmake:2 \(ExternalData_Expand_Arguments\)
- CMakeLists.txt:3 \(include\)
+ BadRecurse1\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadRecurse2-stderr.txt b/Tests/RunCMake/ExternalData/BadRecurse2-stderr.txt
index 3f809ca69..135b42477 100644
--- a/Tests/RunCMake/ExternalData/BadRecurse2-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadRecurse2-stderr.txt
@@ -2,5 +2,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Recurse option "RECURSE:" allowed only with directories.
Call Stack \(most recent call first\):
.*
- BadRecurse2.cmake:2 \(ExternalData_Expand_Arguments\)
- CMakeLists.txt:3 \(include\)
+ BadRecurse2\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadRecurse3-stderr.txt b/Tests/RunCMake/ExternalData/BadRecurse3-stderr.txt
index 37740e0f7..df9bb0e17 100644
--- a/Tests/RunCMake/ExternalData/BadRecurse3-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadRecurse3-stderr.txt
@@ -5,5 +5,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Call Stack \(most recent call first\):
.*
- BadRecurse3.cmake:2 \(ExternalData_Expand_Arguments\)
- CMakeLists.txt:3 \(include\)
+ BadRecurse3\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadSeries1-stderr.txt b/Tests/RunCMake/ExternalData/BadSeries1-stderr.txt
index 3099be579..5b3495985 100644
--- a/Tests/RunCMake/ExternalData/BadSeries1-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadSeries1-stderr.txt
@@ -15,5 +15,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
Call Stack \(most recent call first\):
.*
- BadSeries1.cmake:3 \(ExternalData_Expand_Arguments\)
- CMakeLists.txt:3 \(include\)
+ BadSeries1\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadSeries2-stderr.txt b/Tests/RunCMake/ExternalData/BadSeries2-stderr.txt
index 3a02c25e9..82b2311d2 100644
--- a/Tests/RunCMake/ExternalData/BadSeries2-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadSeries2-stderr.txt
@@ -12,5 +12,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
\(x\)\(y\)\$
Call Stack \(most recent call first\):
.*
- BadSeries2.cmake:3 \(ExternalData_Expand_Arguments\)
- CMakeLists.txt:3 \(include\)
+ BadSeries2\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/BadSeries3-stderr.txt b/Tests/RunCMake/ExternalData/BadSeries3-stderr.txt
index 594cb6f6a..13e75c5c5 100644
--- a/Tests/RunCMake/ExternalData/BadSeries3-stderr.txt
+++ b/Tests/RunCMake/ExternalData/BadSeries3-stderr.txt
@@ -2,5 +2,5 @@ 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\)
+ BadSeries3\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory1-stderr.txt b/Tests/RunCMake/ExternalData/Directory1-stderr.txt
index 2bc3c601d..833683285 100644
--- a/Tests/RunCMake/ExternalData/Directory1-stderr.txt
+++ b/Tests/RunCMake/ExternalData/Directory1-stderr.txt
@@ -10,5 +10,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
that is directory instead of a file!
Call Stack \(most recent call first\):
.*
- Directory1.cmake:3 \(ExternalData_Add_Test\)
- CMakeLists.txt:3 \(include\)
+ Directory1\.cmake:[0-9]+ \(ExternalData_Add_Test\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory2-stderr.txt b/Tests/RunCMake/ExternalData/Directory2-stderr.txt
index 92c9a2ff5..ad6d814ec 100644
--- a/Tests/RunCMake/ExternalData/Directory2-stderr.txt
+++ b/Tests/RunCMake/ExternalData/Directory2-stderr.txt
@@ -6,5 +6,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
must list associated files.
Call Stack \(most recent call first\):
.*
- Directory2.cmake:3 \(ExternalData_Add_Test\)
- CMakeLists.txt:3 \(include\)
+ Directory2\.cmake:[0-9]+ \(ExternalData_Add_Test\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory3-stderr.txt b/Tests/RunCMake/ExternalData/Directory3-stderr.txt
index ceed2a04d..5538c38a8 100644
--- a/Tests/RunCMake/ExternalData/Directory3-stderr.txt
+++ b/Tests/RunCMake/ExternalData/Directory3-stderr.txt
@@ -10,6 +10,6 @@ CMake Warning \(dev\) at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
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\)
+ Directory3\.cmake:[0-9]+ \(ExternalData_Add_Test\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/ExternalData/Directory4-stderr.txt b/Tests/RunCMake/ExternalData/Directory4-stderr.txt
index dcb8522f8..ef8847685 100644
--- a/Tests/RunCMake/ExternalData/Directory4-stderr.txt
+++ b/Tests/RunCMake/ExternalData/Directory4-stderr.txt
@@ -2,5 +2,5 @@ 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\)
+ Directory4\.cmake:[0-9]+ \(ExternalData_Add_Test\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/Directory5-stderr.txt b/Tests/RunCMake/ExternalData/Directory5-stderr.txt
index 8e54aecd2..3fcde414d 100644
--- a/Tests/RunCMake/ExternalData/Directory5-stderr.txt
+++ b/Tests/RunCMake/ExternalData/Directory5-stderr.txt
@@ -10,5 +10,5 @@ CMake Error at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
that does not exist as a directory!
Call Stack \(most recent call first\):
.*
- Directory5.cmake:3 \(ExternalData_Add_Test\)
- CMakeLists.txt:3 \(include\)
+ Directory5\.cmake:[0-9]+ \(ExternalData_Add_Test\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/MissingData-stderr.txt b/Tests/RunCMake/ExternalData/MissingData-stderr.txt
index 39ed2f15f..b10997681 100644
--- a/Tests/RunCMake/ExternalData/MissingData-stderr.txt
+++ b/Tests/RunCMake/ExternalData/MissingData-stderr.txt
@@ -10,6 +10,6 @@ CMake Warning \(dev\) at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
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\)
+ MissingData\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt b/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt
index 315af5e49..426d86ccd 100644
--- a/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt
+++ b/Tests/RunCMake/ExternalData/MissingDataWithAssociated-stderr.txt
@@ -10,6 +10,6 @@ CMake Warning \(dev\) at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
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\)
+ MissingDataWithAssociated\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt b/Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt
index 496ad8ae4..33cef07b4 100644
--- a/Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt
+++ b/Tests/RunCMake/ExternalData/NoLinkInSource-stderr.txt
@@ -2,5 +2,5 @@ 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\)
+ NoLinkInSource\.cmake:[0-9]+ \(ExternalData_Expand_Arguments\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt b/Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt
index ccbaf5af3..45dfb94cb 100644
--- a/Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt
+++ b/Tests/RunCMake/ExternalData/NoURLTemplates-stderr.txt
@@ -1,5 +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\)
+ NoURLTemplates\.cmake:[0-9]+ \(ExternalData_Add_Target\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake
index cb48be7e0..c5018563c 100644
--- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake
+++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS-check.cmake
@@ -24,3 +24,21 @@ if(NOT "${CMAKE_MATCH_0}" MATCHES FORCE)
set(RunCMake_TEST_FAILED "Expected forced TEST_LIST argument")
return()
endif()
+
+if(NOT "${_cache}" MATCHES "set\\(TEST_OPTIONAL \"TEST_OPTIONAL-NOTFOUND\".+\\)")
+ set(RunCMake_TEST_FAILED "Cannot find TEST_OPTIONAL argument in cache")
+ return()
+endif()
+if(NOT "${CMAKE_MATCH_0}" MATCHES FORCE)
+ set(RunCMake_TEST_FAILED "Expected forced TEST_OPTIONAL argument")
+ return()
+endif()
+
+if(NOT "${_cache}" MATCHES "set\\(TEST_OPTIONAL_LAST \"TEST_OPTIONAL_LAST-NOTFOUND\".+\\)")
+ set(RunCMake_TEST_FAILED "Cannot find TEST_OPTIONAL_LAST argument in cache")
+ return()
+endif()
+if(NOT "${CMAKE_MATCH_0}" MATCHES FORCE)
+ set(RunCMake_TEST_FAILED "Expected forced TEST_OPTIONAL_LAST argument")
+ return()
+endif()
diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake
index 1f76fd03e..4f7e02006 100644
--- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake
+++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_ARGS.cmake
@@ -1,4 +1,5 @@
-if(NOT CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(NOT _isMultiConfig)
set(CMAKE_BUILD_TYPE Debug)
endif()
include(ExternalProject)
@@ -7,4 +8,6 @@ ExternalProject_Add(FOO TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp"
DOWNLOAD_COMMAND ""
CMAKE_CACHE_ARGS
"-DFOO:STRING=$<1:BAR>$<0:BAD>"
- "-DTEST_LIST:STRING=A;B;C")
+ "-DTEST_LIST:STRING=A;B;C"
+ "-DTEST_OPTIONAL:FILEPATH=TEST_OPTIONAL-NOTFOUND"
+ "-DTEST_OPTIONAL_LAST:FILEPATH=TEST_OPTIONAL_LAST-NOTFOUND")
diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake
index c84932d60..059f6d327 100644
--- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake
+++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS-check.cmake
@@ -24,3 +24,21 @@ if("${CMAKE_MATCH_0}" MATCHES FORCE)
set(RunCMake_TEST_FAILED "Expected not forced TEST_LIST argument")
return()
endif()
+
+if(NOT "${_cache}" MATCHES "set\\(TEST_OPTIONAL \"TEST_OPTIONAL-NOTFOUND\".+\\)")
+ set(RunCMake_TEST_FAILED "Cannot find TEST_OPTIONAL argument in cache")
+ return()
+endif()
+if("${CMAKE_MATCH_0}" MATCHES FORCE)
+ set(RunCMake_TEST_FAILED "Expected not forced TEST_OPTIONAL argument")
+ return()
+endif()
+
+if(NOT "${_cache}" MATCHES "set\\(TEST_OPTIONAL_LAST \"TEST_OPTIONAL_LAST-NOTFOUND\".+\\)")
+ set(RunCMake_TEST_FAILED "Cannot find TEST_OPTIONAL_LAST argument in cache")
+ return()
+endif()
+if("${CMAKE_MATCH_0}" MATCHES FORCE)
+ set(RunCMake_TEST_FAILED "Expected not forced TEST_OPTIONAL_LAST argument")
+ return()
+endif()
diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake
index 1b619c8c0..61334183c 100644
--- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake
+++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_DEFAULT_ARGS.cmake
@@ -1,4 +1,5 @@
-if(NOT CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(NOT _isMultiConfig)
set(CMAKE_BUILD_TYPE Debug)
endif()
include(ExternalProject)
@@ -7,4 +8,6 @@ ExternalProject_Add(FOO TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp"
DOWNLOAD_COMMAND ""
CMAKE_CACHE_DEFAULT_ARGS
"-DFOO:STRING=$<1:BAR>$<0:BAD>"
- "-DTEST_LIST:STRING=A;B;C")
+ "-DTEST_LIST:STRING=A;B;C"
+ "-DTEST_OPTIONAL:FILEPATH=TEST_OPTIONAL-NOTFOUND"
+ "-DTEST_OPTIONAL_LAST:FILEPATH=TEST_OPTIONAL_LAST-NOTFOUND")
diff --git a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake
index 192776ba7..2fb0705a5 100644
--- a/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake
+++ b/Tests/RunCMake/ExternalProject/CMAKE_CACHE_mix.cmake
@@ -1,4 +1,5 @@
-if(NOT CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(NOT _isMultiConfig)
set(CMAKE_BUILD_TYPE Debug)
endif()
include(ExternalProject)
diff --git a/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt b/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt
index 12a76c5d4..2fc7d291b 100644
--- a/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt
+++ b/Tests/RunCMake/ExternalProject/NoOptions-stderr.txt
@@ -6,12 +6,12 @@
is not an existing non-empty directory. Please specify one of:
\* SOURCE_DIR with an existing non-empty directory
+ \* DOWNLOAD_COMMAND
\* URL
\* GIT_REPOSITORY
+ \* SVN_REPOSITORY
\* HG_REPOSITORY
\* CVS_REPOSITORY and CVS_MODULE
- \* SVN_REVISION
- \* DOWNLOAD_COMMAND
Call Stack \(most recent call first\):
.*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_add_download_command\)
NoOptions.cmake:[0-9]+ \(ExternalProject_Add\)
diff --git a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake
index 47d612969..caaf0d2fd 100644
--- a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake
@@ -1,5 +1,7 @@
include(RunCMake)
+run_cmake(IncludeScope-Add)
+run_cmake(IncludeScope-Add_Step)
run_cmake(NoOptions)
run_cmake(SourceEmpty)
run_cmake(SourceMissing)
@@ -12,3 +14,41 @@ run_cmake(Add_StepDependencies_iface)
run_cmake(Add_StepDependencies_iface_step)
run_cmake(Add_StepDependencies_no_target)
run_cmake(UsesTerminal)
+
+# Run both cmake and build steps. We always do a clean before the
+# build to ensure that the download step re-runs each time.
+function(__ep_test_with_build testName)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${testName}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(${testName})
+ run_cmake_command(${testName}-clean ${CMAKE_COMMAND} --build . --target clean)
+ run_cmake_command(${testName}-build ${CMAKE_COMMAND} --build .)
+endfunction()
+
+__ep_test_with_build(MultiCommand)
+
+# Output is not predictable enough to be able to verify it reliably
+# when using the various different Visual Studio generators
+if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
+ __ep_test_with_build(LogOutputOnFailure)
+ __ep_test_with_build(LogOutputOnFailureMerged)
+endif()
+
+# We can't test the substitution when using the old MSYS due to
+# make/sh mangling the paths (substitution is performed correctly,
+# but the mangling means we can't reliably test the output).
+# There is no such issue when using the newer MSYS though. Therefore,
+# we need to bypass the substitution test if using old MSYS.
+# See merge request 1537 for discussion.
+set(doSubstitutionTest YES)
+if(RunCMake_GENERATOR STREQUAL "MSYS Makefiles")
+ execute_process(COMMAND uname OUTPUT_VARIABLE uname)
+ if(uname MATCHES "^MINGW32_NT")
+ set(doSubstitutionTest NO)
+ endif()
+endif()
+if(doSubstitutionTest)
+ __ep_test_with_build(Substitutions)
+endif()
diff --git a/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt b/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt
index 58a343ccf..07c6e8798 100644
--- a/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt
+++ b/Tests/RunCMake/ExternalProject/SourceEmpty-stderr.txt
@@ -6,12 +6,12 @@
is not an existing non-empty directory. Please specify one of:
\* SOURCE_DIR with an existing non-empty directory
+ \* DOWNLOAD_COMMAND
\* URL
\* GIT_REPOSITORY
+ \* SVN_REPOSITORY
\* HG_REPOSITORY
\* CVS_REPOSITORY and CVS_MODULE
- \* SVN_REVISION
- \* DOWNLOAD_COMMAND
Call Stack \(most recent call first\):
.*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_add_download_command\)
SourceEmpty.cmake:[0-9]+ \(ExternalProject_Add\)
diff --git a/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt b/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt
index e62f7cf5a..373f6e3aa 100644
--- a/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt
+++ b/Tests/RunCMake/ExternalProject/SourceMissing-stderr.txt
@@ -6,12 +6,12 @@
is not an existing non-empty directory. Please specify one of:
\* SOURCE_DIR with an existing non-empty directory
+ \* DOWNLOAD_COMMAND
\* URL
\* GIT_REPOSITORY
+ \* SVN_REPOSITORY
\* HG_REPOSITORY
\* CVS_REPOSITORY and CVS_MODULE
- \* SVN_REVISION
- \* DOWNLOAD_COMMAND
Call Stack \(most recent call first\):
.*/Modules/ExternalProject.cmake:[0-9]+ \(_ep_add_download_command\)
SourceMissing.cmake:[0-9]+ \(ExternalProject_Add\)
diff --git a/Tests/RunCMake/ExternalProject/UsesTerminal.cmake b/Tests/RunCMake/ExternalProject/UsesTerminal.cmake
index cd874039d..d3494fd4e 100644
--- a/Tests/RunCMake/ExternalProject/UsesTerminal.cmake
+++ b/Tests/RunCMake/ExternalProject/UsesTerminal.cmake
@@ -1,4 +1,5 @@
-if(NOT CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(NOT _isMultiConfig)
set(CMAKE_BUILD_TYPE Debug)
endif()
include(ExternalProject)
diff --git a/Tests/RunCMake/FPHSA/RunCMakeTest.cmake b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake
index e9b2a7a70..dd73cd487 100644
--- a/Tests/RunCMake/FPHSA/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FPHSA/RunCMakeTest.cmake
@@ -4,7 +4,18 @@ 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")
+
+# Find a package with version 0.
+set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=0")
+run_cmake(any_version_find_0)
+
+# Find a package with more customary version number, without requesting a specific version and in
+# the presence of a cache variable VERSION.
+set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudoNoVersionVar_VERSION=1.2.3.4_SHOULD_BE_IGNORED" "-DVERSION=BAD_VERSION")
+run_cmake(any_version_VERSION_cache_variable)
+
+# Find a package with a more customary version number, without requesting a specific version.
+set(RunCMake_TEST_OPTIONS "-DCMAKE_MODULE_PATH=${CMAKE_CURRENT_LIST_DIR}" "-DPseudo_VERSION=1.2.3.4")
run_cmake(any_version)
# test EXACT mode with every subcomponent
diff --git a/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake b/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake
index e2b081d48..bead2af6f 100644
--- a/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake
+++ b/Tests/RunCMake/File_Generate/COMPILE_LANGUAGE-genex.cmake
@@ -1,12 +1,6 @@
-
enable_language(CXX C)
-add_library(empty empty.cpp empty.c)
-target_compile_options(empty
- PRIVATE LANG_IS_$<COMPILE_LANGUAGE>
-)
-
file(GENERATE
- OUTPUT opts-$<COMPILE_LANGUAGE>.txt
- CONTENT "$<TARGET_PROPERTY:empty,COMPILE_OPTIONS>\n"
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/opts-$<COMPILE_LANGUAGE>.txt
+ CONTENT "LANG_IS_$<COMPILE_LANGUAGE>\n"
)
diff --git a/Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt b/Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt
index b08ef5a15..4c2e35fcc 100644
--- a/Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt
+++ b/Tests/RunCMake/File_Generate/OutputNameMatchesObjects-stderr.txt
@@ -3,6 +3,7 @@ CMake Error at OutputNameMatchesObjects.cmake:[0-9]+ \(file\):
\$<TARGET_OBJECTS:foo>
- Objects of target "foo" referenced but is not an OBJECT library.
+ Objects of target "foo" referenced but is not an allowed library types
+ \(EXECUTABLE, STATIC, SHARED, MODULE, OBJECT\).
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/File_Generate/OutputNameMatchesObjects.cmake b/Tests/RunCMake/File_Generate/OutputNameMatchesObjects.cmake
index daa7c49ca..84825feea 100644
--- a/Tests/RunCMake/File_Generate/OutputNameMatchesObjects.cmake
+++ b/Tests/RunCMake/File_Generate/OutputNameMatchesObjects.cmake
@@ -1,11 +1,8 @@
enable_language(CXX)
file(GENERATE
- OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<BOOL:$<TARGET_OBJECTS:foo>>somefile.cpp"
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<LOWER_CASE:$<CONFIG>/somefile.cpp"
CONTENT "static const char content[] = \"$<TARGET_OBJECTS:foo>\";\n"
)
-add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/input.txt"
- COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/input.txt" "${CMAKE_CURRENT_BINARY_DIR}")
-
-add_executable(foo empty.cpp "${CMAKE_CURRENT_BINARY_DIR}/1somefile.cpp" "${CMAKE_CURRENT_BINARY_DIR}/input.txt")
+add_library(foo INTERFACE )
diff --git a/Tests/RunCMake/File_Generate/ReRunCMake.cmake b/Tests/RunCMake/File_Generate/ReRunCMake.cmake
index 109d60e6f..541d86df2 100644
--- a/Tests/RunCMake/File_Generate/ReRunCMake.cmake
+++ b/Tests/RunCMake/File_Generate/ReRunCMake.cmake
@@ -1,5 +1,5 @@
file(GENERATE
- OUTPUT output_file.txt
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/output_file.txt"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/input_file.txt"
)
diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
index 82e903d82..94aaca84a 100644
--- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
+++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake
@@ -1,7 +1,11 @@
include(RunCMake)
+run_cmake(CMP0070-NEW)
+run_cmake(CMP0070-OLD)
+run_cmake(CMP0070-WARN)
+
run_cmake(CommandConflict)
-if("${RunCMake_GENERATOR}" MATCHES "Visual Studio|Xcode")
+if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
run_cmake(OutputConflict)
endif()
run_cmake(EmptyCondition1)
@@ -17,15 +21,13 @@ if (NOT file_contents MATCHES "generated.cpp.rule")
message(SEND_ERROR "Rule file not in target sources! ${file_contents}")
endif()
-if (NOT RunCMake_GENERATOR MATCHES "Visual Studio")
- run_cmake(COMPILE_LANGUAGE-genex)
- foreach(l CXX C)
- file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs)
- if (NOT l_defs STREQUAL "LANG_IS_${l}\n")
- message(FATAL_ERROR "File content does not match: ${l_defs}")
- endif()
- endforeach()
-endif()
+run_cmake(COMPILE_LANGUAGE-genex)
+foreach(l CXX C)
+ file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs)
+ if (NOT l_defs STREQUAL "LANG_IS_${l}\n")
+ message(FATAL_ERROR "File content does not match: ${l_defs}")
+ endif()
+endforeach()
set(timeformat "%Y%j%H%M%S")
diff --git a/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake b/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake
index d1d832a11..bb36a4c48 100644
--- a/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake
+++ b/Tests/RunCMake/File_Generate/WriteIfDifferent.cmake
@@ -1,5 +1,5 @@
file(GENERATE
- OUTPUT output_file.txt
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/output_file.txt
CONTENT "123"
)
diff --git a/Tests/RunCMake/FindMatlab/MatlabTest1.cmake b/Tests/RunCMake/FindMatlab/MatlabTest1.cmake
index 1cbc1c202..b4cc7415b 100644
--- a/Tests/RunCMake/FindMatlab/MatlabTest1.cmake
+++ b/Tests/RunCMake/FindMatlab/MatlabTest1.cmake
@@ -3,6 +3,9 @@ cmake_minimum_required (VERSION 2.8.12)
enable_testing()
project(test_should_fail)
+if(NOT "${matlab_root}" STREQUAL "")
+ set(Matlab_ROOT_DIR ${matlab_root})
+endif()
find_package(Matlab REQUIRED COMPONENTS MX_LIBRARY)
matlab_add_mex(
diff --git a/Tests/RunCMake/FindMatlab/MatlabTest2.cmake b/Tests/RunCMake/FindMatlab/MatlabTest2.cmake
index d5b0e6db1..4295d3c73 100644
--- a/Tests/RunCMake/FindMatlab/MatlabTest2.cmake
+++ b/Tests/RunCMake/FindMatlab/MatlabTest2.cmake
@@ -6,4 +6,8 @@ if(NOT DEFINED matlab_required)
set(matlab_required REQUIRED)
endif()
+if(NOT DEFINED Matlab_ROOT_DIR AND NOT "${matlab_root}" STREQUAL "")
+ set(Matlab_ROOT_DIR ${matlab_root})
+endif()
+
find_package(Matlab ${matlab_required} COMPONENTS MX_LIBRARY)
diff --git a/Tests/RunCMake/FindMatlab/RunCMakeTest.cmake b/Tests/RunCMake/FindMatlab/RunCMakeTest.cmake
index f0eb6b4bb..deebf89d9 100644
--- a/Tests/RunCMake/FindMatlab/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FindMatlab/RunCMakeTest.cmake
@@ -1,5 +1,13 @@
include(RunCMake)
+
+
+if(NOT "${MCR_ROOT}" STREQUAL "")
+ if(NOT EXISTS "${MCR_ROOT}")
+ message(FATAL_ERROR "MCR does not exist ${MCR_ROOT}")
+ endif()
+ set(RunCMake_TEST_OPTIONS "-Dmatlab_root=${MCR_ROOT}")
+endif()
run_cmake(MatlabTest1)
if(RunCMake_GENERATOR MATCHES "Make" AND UNIX)
@@ -11,6 +19,9 @@ if(RunCMake_GENERATOR MATCHES "Make" AND UNIX)
message(STATUS "RerunFindMatlab: first configuration to extract real Matlab_ROOT_DIR")
set(RunCMake_TEST_OPTIONS "-Dmatlab_required=REQUIRED")
+ if(NOT "${MCR_ROOT}" STREQUAL "")
+ set(RunCMake_TEST_OPTIONS ${RunCMake_TEST_OPTIONS} "-Dmatlab_root=${MCR_ROOT}")
+ endif()
run_cmake(MatlabTest2)
message(STATUS "RerunFindMatlab: flushing the variables")
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake
index 00cbb7b38..e82b05fd8 100644
--- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_IMPORTED_TARGET.cmake
@@ -1,10 +1,12 @@
-cmake_minimum_required(VERSION 3.5)
+cmake_minimum_required(VERSION 3.12)
project(FindPkgConfig_IMPORTED_TARGET C)
find_package(PkgConfig REQUIRED)
pkg_check_modules(NCURSES IMPORTED_TARGET QUIET ncurses)
+message(STATUS "source: ${CMAKE_CURRENT_SOURCE_DIR} bin ${CMAKE_CURRENT_BINARY_DIR}")
+
if (NCURSES_FOUND)
set(tgt PkgConfig::NCURSES)
if (NOT TARGET ${tgt})
@@ -24,3 +26,107 @@ if (NCURSES_FOUND)
else ()
message(STATUS "skipping test; ncurses not found")
endif ()
+
+
+# Setup for the remaining package tests below
+set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH)
+set(fakePkgDir ${CMAKE_CURRENT_BINARY_DIR}/pc-fakepackage)
+foreach(i 1 2)
+ set(pname cmakeinternalfakepackage${i})
+ file(WRITE ${fakePkgDir}/lib/lib${pname}.a "")
+ file(WRITE ${fakePkgDir}/lib/${pname}.lib "")
+ file(WRITE ${fakePkgDir}/lib/pkgconfig/${pname}.pc
+"Name: CMakeInternalFakePackage${i}
+Description: Dummy package (${i}) for FindPkgConfig IMPORTED_TARGET test
+Version: 1.2.3
+Libs: -l${pname}
+")
+endforeach()
+
+# Always find the .pc file in the calls further below so that we can test that
+# the import target find_library() calls handle the NO...PATH options correctly
+set(ENV{PKG_CONFIG_PATH} ${fakePkgDir}/lib/pkgconfig)
+
+# Confirm correct behavior of NO_CMAKE_PATH, ensuring we only find the library
+# for the imported target if we have both set CMAKE_PREFIX_PATH and have not
+# given the NO_CMAKE_PATH option
+unset(CMAKE_PREFIX_PATH)
+unset(ENV{CMAKE_PREFIX_PATH})
+pkg_check_modules(FakePackage1 QUIET IMPORTED_TARGET cmakeinternalfakepackage1)
+if (TARGET PkgConfig::FakePackage1)
+ message(FATAL_ERROR "Have import target for fake package 1 with no path prefix")
+endif()
+
+set(CMAKE_PREFIX_PATH ${fakePkgDir})
+pkg_check_modules(FakePackage1 QUIET IMPORTED_TARGET NO_CMAKE_PATH cmakeinternalfakepackage1)
+if (TARGET PkgConfig::FakePackage1)
+ message(FATAL_ERROR "Have import target for fake package 1 with ignored cmake path")
+endif()
+
+pkg_check_modules(FakePackage1 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakepackage1)
+if (NOT TARGET PkgConfig::FakePackage1)
+ message(FATAL_ERROR "No import target for fake package 1 with prefix path")
+endif()
+
+# find targets in subdir and check their visibility
+add_subdirectory(target_subdir)
+if (TARGET PkgConfig::FakePackage1_dir)
+ message(FATAL_ERROR "imported target PkgConfig::FakePackage1_dir is visible outside it's directory")
+endif()
+
+if (NOT TARGET PkgConfig::FakePackage1_global)
+ message(FATAL_ERROR "imported target PkgConfig::FakePackage1_global is not visible outside it's directory")
+endif()
+
+# And now do the same for the NO_CMAKE_ENVIRONMENT_PATH - ENV{CMAKE_PREFIX_PATH}
+# combination
+unset(CMAKE_PREFIX_PATH)
+unset(ENV{CMAKE_PREFIX_PATH})
+pkg_check_modules(FakePackage2 QUIET IMPORTED_TARGET cmakeinternalfakepackage2)
+if (TARGET PkgConfig::FakePackage2)
+ message(FATAL_ERROR "Have import target for fake package 2 with no path prefix")
+endif()
+
+set(ENV{CMAKE_PREFIX_PATH} ${fakePkgDir})
+pkg_check_modules(FakePackage2 QUIET IMPORTED_TARGET NO_CMAKE_ENVIRONMENT_PATH cmakeinternalfakepackage2)
+if (TARGET PkgConfig::FakePackage2)
+ message(FATAL_ERROR "Have import target for fake package 2 with ignored cmake path")
+endif()
+
+pkg_check_modules(FakePackage2 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakepackage2)
+if (NOT TARGET PkgConfig::FakePackage2)
+ message(FATAL_ERROR "No import target for fake package 2 with prefix path")
+endif()
+
+# check that the full library path is also returned
+if (NOT FakePackage2_LINK_LIBRARIES STREQUAL "${fakePkgDir}/lib/libcmakeinternalfakepackage2.a")
+ message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has bad content on first run: ${FakePackage2_LINK_LIBRARIES}")
+endif()
+
+# the information in *_LINK_LIBRARIES is not cached, so ensure is also is present on second run
+unset(FakePackage2_LINK_LIBRARIES)
+pkg_check_modules(FakePackage2 REQUIRED QUIET IMPORTED_TARGET cmakeinternalfakepackage2)
+if (NOT FakePackage2_LINK_LIBRARIES STREQUAL "${fakePkgDir}/lib/libcmakeinternalfakepackage2.a")
+ message(FATAL_ERROR "FakePackage2_LINK_LIBRARIES has bad content on second run: ${FakePackage2_LINK_LIBRARIES}")
+endif()
+
+set(pname fakelinkoptionspackage)
+file(WRITE ${fakePkgDir}/lib/pkgconfig/${pname}.pc
+"Name: FakeLinkOptionsPackage
+Description: Dummy package for FindPkgConfig IMPORTED_TARGET INTERFACE_LINK_OPTIONS test
+Version: 1.2.3
+Libs: -e dummy_main
+")
+
+set(expected_link_options -e dummy_main)
+pkg_check_modules(FakeLinkOptionsPackage REQUIRED QUIET IMPORTED_TARGET fakelinkoptionspackage)
+if (NOT TARGET PkgConfig::FakeLinkOptionsPackage)
+ message(FATAL_ERROR "No import target for fake link options package")
+endif()
+get_target_property(link_options PkgConfig::FakeLinkOptionsPackage INTERFACE_LINK_OPTIONS)
+if (NOT link_options STREQUAL expected_link_options)
+ message(FATAL_ERROR
+ "Additional link options not present in INTERFACE_LINK_OPTIONS property"
+ "expected: \"${expected_link_options}\", but got \"${link_options}\""
+ )
+endif()
diff --git a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake
index 1defde840..d1d538512 100644
--- a/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake
+++ b/Tests/RunCMake/FindPkgConfig/FindPkgConfig_PKGCONFIG_PATH.cmake
@@ -29,7 +29,7 @@ if(NOT DEFINED CMAKE_SYSTEM_NAME
set(expected_path "/baz:${CMAKE_CURRENT_SOURCE_DIR}/pc-foo/lib/pkgconfig:${CMAKE_CURRENT_SOURCE_DIR}/pc-bar/lib/pkgconfig")
endif()
else()
- # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS propertie
+ # not debian, check the FIND_LIBRARY_USE_LIB32_PATHS and FIND_LIBRARY_USE_LIB64_PATHS properties
get_property(uselibx32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIBX32_PATHS)
get_property(uselib32 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB32_PATHS)
get_property(uselib64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
diff --git a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
index e12b52fe4..414d9b68f 100644
--- a/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/FindPkgConfig/RunCMakeTest.cmake
@@ -14,6 +14,9 @@ endif()
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
run_cmake(FindPkgConfig_GET_VARIABLE)
+ run_cmake(FindPkgConfig_GET_VARIABLE_PREFIX_PATH)
+ run_cmake(FindPkgConfig_GET_VARIABLE_PKGCONFIG_PATH)
run_cmake(FindPkgConfig_cache_variables)
run_cmake(FindPkgConfig_IMPORTED_TARGET)
+ run_cmake(FindPkgConfig_VERSION_OPERATORS)
endif ()
diff --git a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat
index b03837030..486977cbb 100755
--- a/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat
+++ b/Tests/RunCMake/FindPkgConfig/dummy-pkg-config.bat
@@ -1,27 +1,27 @@
-@ECHO OFF
-
-:LOOP
-
-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
- ) ELSE (
- EXIT /B 0
- )
-)
-SHIFT
-IF NOT "%~1"=="" GOTO LOOP
-
-EXIT /B 255
+@ECHO OFF
+
+:LOOP
+
+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
+ ) ELSE (
+ EXIT /B 0
+ )
+)
+SHIFT
+IF NOT "%~1"=="" GOTO LOOP
+
+EXIT /B 255
diff --git a/Tests/RunCMake/Framework/FrameworkLayout.cmake b/Tests/RunCMake/Framework/FrameworkLayout.cmake
index 3d62a8af3..84012aa36 100644
--- a/Tests/RunCMake/Framework/FrameworkLayout.cmake
+++ b/Tests/RunCMake/Framework/FrameworkLayout.cmake
@@ -11,8 +11,11 @@ add_library(Framework ${FRAMEWORK_TYPE}
flatresource.txt
deepresource.txt
some.txt)
+if("${CMAKE_FRAMEWORK}" STREQUAL "")
+ set_target_properties(Framework PROPERTIES
+ FRAMEWORK TRUE)
+endif()
set_target_properties(Framework PROPERTIES
- FRAMEWORK TRUE
PUBLIC_HEADER foo.h
RESOURCE "res.txt")
set_source_files_properties(flatresource.txt PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
@@ -22,4 +25,4 @@ set_source_files_properties(some.txt PROPERTIES MACOSX_PACKAGE_LOCATION somedir)
add_custom_command(TARGET Framework POST_BUILD
COMMAND /usr/bin/file $<TARGET_FILE:Framework>)
-file(GENERATE OUTPUT FrameworkName.cmake CONTENT "set(framework-dir \"$<TARGET_BUNDLE_DIR:Framework>\")\n")
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/FrameworkName.cmake CONTENT "set(framework-dir \"$<TARGET_BUNDLE_DIR:Framework>\")\n")
diff --git a/Tests/RunCMake/Framework/FrameworkTypeSTATIC-build-stdout.txt b/Tests/RunCMake/Framework/FrameworkTypeSTATIC-build-stdout.txt
index 532cfedcc..4b5f761af 100644
--- a/Tests/RunCMake/Framework/FrameworkTypeSTATIC-build-stdout.txt
+++ b/Tests/RunCMake/Framework/FrameworkTypeSTATIC-build-stdout.txt
@@ -1,2 +1,2 @@
-.*/Framework:( Mach-O universal binary with [^
-]*)? current ar archive random library.*
+/Framework: (Mach-O universal binary with [^
+]*)?current ar archive random library
diff --git a/Tests/RunCMake/Framework/RunCMakeTest.cmake b/Tests/RunCMake/Framework/RunCMakeTest.cmake
index 4fc83f801..c7e1319c1 100644
--- a/Tests/RunCMake/Framework/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Framework/RunCMakeTest.cmake
@@ -1,5 +1,7 @@
include(RunCMake)
+run_cmake(InstallBeforeFramework)
+
function(framework_layout_test Name Toolchain Type)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${Toolchain}${Type}FrameworkLayout-build)
set(RunCMake_TEST_NO_CLEAN 1)
@@ -18,11 +20,14 @@ framework_layout_test(iOSFrameworkLayout-build ios STATIC)
framework_layout_test(OSXFrameworkLayout-build osx SHARED)
framework_layout_test(OSXFrameworkLayout-build osx STATIC)
-function(framework_type_test Toolchain Type)
+function(framework_type_test Toolchain Type UseProperty)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${Toolchain}${Type}FrameworkType-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/${Toolchain}.cmake")
list(APPEND RunCMake_TEST_OPTIONS "-DFRAMEWORK_TYPE=${Type}")
+ if(NOT ${UseProperty})
+ list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_FRAMEWORK=YES")
+ endif()
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
@@ -31,7 +36,12 @@ function(framework_type_test Toolchain Type)
run_cmake_command(FrameworkType${Type}-build ${CMAKE_COMMAND} --build .)
endfunction()
-framework_type_test(ios SHARED)
-framework_type_test(ios STATIC)
-framework_type_test(osx SHARED)
-framework_type_test(osx STATIC)
+framework_type_test(ios SHARED NO)
+framework_type_test(ios STATIC NO)
+framework_type_test(osx SHARED NO)
+framework_type_test(osx STATIC NO)
+
+framework_type_test(ios SHARED YES)
+framework_type_test(ios STATIC YES)
+framework_type_test(osx SHARED YES)
+framework_type_test(osx STATIC YES)
diff --git a/Tests/RunCMake/Framework/ios.cmake b/Tests/RunCMake/Framework/ios.cmake
index 209a50d39..446e9146a 100644
--- a/Tests/RunCMake/Framework/ios.cmake
+++ b/Tests/RunCMake/Framework/ios.cmake
@@ -20,6 +20,16 @@ execute_process(
OUTPUT_VARIABLE IOS_SDK_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
+execute_process(
+ COMMAND ${XCRUN_EXECUTABLE} --sdk iphoneos --show-sdk-version
+ OUTPUT_VARIABLE IOS_SDK_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(IOS_SDK_VERSION VERSION_GREATER_EQUAL 11.0)
+ set(IOS_ARCH arm64)
+else()
+ set(IOS_ARCH armv7)
+endif()
+
set(CMAKE_OSX_SYSROOT ${IOS_SDK_PATH} CACHE PATH "Sysroot used for iOS support")
-set(CMAKE_OSX_ARCHITECTURES "armv7" CACHE STRING "Architectures to build for")
+set(CMAKE_OSX_ARCHITECTURES "${IOS_ARCH}" CACHE STRING "Architectures to build for")
set(CMAKE_FIND_ROOT_PATH ${IOS_SDK_PATH} CACHE PATH "Find search path root")
diff --git a/Tests/RunCMake/GNUInstallDirs/RunCMakeTest.cmake b/Tests/RunCMake/GNUInstallDirs/RunCMakeTest.cmake
index b544ba640..d671ee0ab 100644
--- a/Tests/RunCMake/GNUInstallDirs/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GNUInstallDirs/RunCMakeTest.cmake
@@ -1,7 +1,11 @@
include(RunCMake)
-if(SYSTEM_NAME MATCHES "^(.*BSD|DragonFly)$")
- set(EXPECT_BSD 1)
+if(SYSTEM_NAME STREQUAL "FreeBSD")
+ set(variant "-FreeBSD")
+elseif(SYSTEM_NAME MATCHES "^(([^k].*)?BSD|DragonFly)$")
+ set(variant "-BSD")
+else()
+ set(variant "")
endif()
foreach(case
@@ -10,8 +14,6 @@ foreach(case
Usr
UsrLocal
)
- if(EXPECT_BSD)
- set(RunCMake-stderr-file ${case}-BSD-stderr.txt)
- endif()
+ set(RunCMake-stderr-file ${case}${variant}-stderr.txt)
run_cmake(${case})
endforeach()
diff --git a/Tests/RunCMake/GenerateExportHeader/GEH.cmake b/Tests/RunCMake/GenerateExportHeader/GEH.cmake
index e0677a7a3..ae9a84c43 100644
--- a/Tests/RunCMake/GenerateExportHeader/GEH.cmake
+++ b/Tests/RunCMake/GenerateExportHeader/GEH.cmake
@@ -45,13 +45,6 @@ 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")
- string(APPEND CMAKE_CXX_FLAGS " -AA")
-endif ()
-
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
@@ -60,7 +53,16 @@ endif()
add_subdirectory(lib_shared_and_static)
-add_compiler_export_flags()
+if(CMAKE_SYSTEM_NAME MATCHES "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
+ AND CMAKE_CXX_COMPILE_OPTIONS_VISIBILITY)
+ # With GNU 7 on AIX, passing -fvisibility=hidden when driving the
+ # linker for a shared library drops the so init/destruct symbols.
+ # Just use the modern approach instead of testing the macro.
+ set(CMAKE_CXX_VISIBILITY_PRESET hidden)
+ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
+else()
+ add_compiler_export_flags()
+endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR})
@@ -83,6 +85,7 @@ macro_add_test_library(libshared)
macro_add_test_library(libstatic)
add_subdirectory(nodeprecated)
+add_subdirectory(includeguard)
if(NOT BORLAND)
add_subdirectory(c_identifier)
endif()
diff --git a/Tests/RunCMake/GenerateExportHeader/RunCMakeTest.cmake b/Tests/RunCMake/GenerateExportHeader/RunCMakeTest.cmake
index 9423ef5dd..18c334080 100644
--- a/Tests/RunCMake/GenerateExportHeader/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GenerateExportHeader/RunCMakeTest.cmake
@@ -4,7 +4,7 @@ function(run_GEH)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GEH-build)
set(RunCMake_TEST_NO_CLEAN 1)
- if(RunCMake_GENERATOR MATCHES "Make|Ninja")
+ if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@@ -12,6 +12,8 @@ function(run_GEH)
run_cmake(GEH)
run_cmake_command(GEH-build ${CMAKE_COMMAND} --build . --config Debug)
run_cmake_command(GEH-run ${RunCMake_TEST_BINARY_DIR}/GenerateExportHeader)
+ run_cmake_command(GEH-incguard-macro-run ${RunCMake_TEST_BINARY_DIR}/test_includeguard_macro)
+ run_cmake_command(GEH-incguard-custom-run ${RunCMake_TEST_BINARY_DIR}/test_includeguard_custom)
file(STRINGS "${RunCMake_TEST_BINARY_DIR}/failure_test_targets"
failure_test_targets)
diff --git a/Tests/RunCMake/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp b/Tests/RunCMake/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp
index 9ac838183..752b49e71 100644
--- a/Tests/RunCMake/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp
+++ b/Tests/RunCMake/GenerateExportHeader/lib_shared_and_static/libshared_and_static.cpp
@@ -1,7 +1,7 @@
#include "libshared_and_static.h"
#ifndef MY_CUSTOM_CONTENT_ADDED
-#error "MY_CUSTOM_CONTENT_ADDED not defined!"
+# error "MY_CUSTOM_CONTENT_ADDED not defined!"
#endif
int libshared_and_static::Class::method() const
diff --git a/Tests/RunCMake/GenerateExportHeader/libshared/CMakeLists.txt b/Tests/RunCMake/GenerateExportHeader/libshared/CMakeLists.txt
index c4a761c74..9516a5aa2 100644
--- a/Tests/RunCMake/GenerateExportHeader/libshared/CMakeLists.txt
+++ b/Tests/RunCMake/GenerateExportHeader/libshared/CMakeLists.txt
@@ -1,7 +1,5 @@
include(GenerateExportHeader)
-add_compiler_export_flags()
-
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_library(libshared SHARED libshared.cpp)
diff --git a/Tests/RunCMake/GenerateExportHeader/libstatic/CMakeLists.txt b/Tests/RunCMake/GenerateExportHeader/libstatic/CMakeLists.txt
index 0fd136cee..56e833524 100644
--- a/Tests/RunCMake/GenerateExportHeader/libstatic/CMakeLists.txt
+++ b/Tests/RunCMake/GenerateExportHeader/libstatic/CMakeLists.txt
@@ -2,8 +2,6 @@ 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)
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/Empty/libshared_export.h b/Tests/RunCMake/GenerateExportHeader/reference/Empty/libshared_export.h
index e8af0a5c1..0b1dcba5b 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/Empty/libshared_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/Empty/libshared_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSHARED_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/Empty/libstatic_export.h b/Tests/RunCMake/GenerateExportHeader/reference/Empty/libstatic_export.h
index 598bd71be..5e3ac9f3f 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/Empty/libstatic_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/Empty/libstatic_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSTATIC_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libshared_export.h b/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libshared_export.h
index cc20e09b0..dac4fda65 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libshared_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libshared_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSHARED_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libstatic_export.h b/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libstatic_export.h
index 4aaa84863..b6e2a4a88 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libstatic_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/MinGW/libstatic_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSTATIC_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libshared_export.h b/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libshared_export.h
index 053ad1869..11f8042e3 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libshared_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libshared_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSHARED_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libstatic_export.h b/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libstatic_export.h
index 4aaa84863..b6e2a4a88 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libstatic_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/UNIX/libstatic_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSTATIC_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h b/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h
index 808ff0131..1481acd87 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libshared_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSHARED_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h b/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h
index 4aaa84863..b6e2a4a88 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/UNIX_DeprecatedOnly/libstatic_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSTATIC_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libshared_export.h b/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libshared_export.h
index cc20e09b0..dac4fda65 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libshared_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libshared_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSHARED_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libstatic_export.h b/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libstatic_export.h
index 4aaa84863..b6e2a4a88 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libstatic_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/Win32-Clang/libstatic_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSTATIC_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/Win32/libshared_export.h b/Tests/RunCMake/GenerateExportHeader/reference/Win32/libshared_export.h
index 4e675af6c..3ba2d2eac 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/Win32/libshared_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/Win32/libshared_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSHARED_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/Win32/libstatic_export.h b/Tests/RunCMake/GenerateExportHeader/reference/Win32/libstatic_export.h
index 4d5ed4ecd..3c7e093ab 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/Win32/libstatic_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/Win32/libstatic_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSTATIC_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libshared_export.h b/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libshared_export.h
index 84340e305..bf9163ebe 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libshared_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libshared_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSHARED_EXPORT_H */
diff --git a/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libstatic_export.h b/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libstatic_export.h
index 598bd71be..5e3ac9f3f 100644
--- a/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libstatic_export.h
+++ b/Tests/RunCMake/GenerateExportHeader/reference/WinEmpty/libstatic_export.h
@@ -39,4 +39,4 @@
# endif
#endif
-#endif
+#endif /* LIBSTATIC_EXPORT_H */
diff --git a/Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt
index 0e48ba423..86d3e0472 100644
--- a/Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadAND-stderr.txt
@@ -50,4 +50,6 @@ CMake Error at BadAND.cmake:1 \(add_custom_target\):
Parameters to \$<AND> must resolve to either '0' or '1'.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists.txt:3 \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt
index 964ea4d4e..42dd0ce50 100644
--- a/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadCONFIG-stderr.txt
@@ -32,4 +32,6 @@ CMake Error at BadCONFIG.cmake:1 \(add_custom_target\):
Expression syntax not recognized.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists.txt:3 \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt
index e5e628c30..627327c12 100644
--- a/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadNOT-stderr.txt
@@ -49,4 +49,6 @@ CMake Error at BadNOT.cmake:1 \(add_custom_target\):
\$<NOT> parameter must resolve to exactly one '0' or '1' value.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists.txt:3 \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt
index eb263286e..56e6af00f 100644
--- a/Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadOR-stderr.txt
@@ -50,4 +50,6 @@ CMake Error at BadOR.cmake:1 \(add_custom_target\):
Parameters to \$<OR> must resolve to either '0' or '1'.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists.txt:3 \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH-stderr.txt
index 8d3c4ccd6..a08e7b236 100644
--- a/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH-stderr.txt
@@ -15,3 +15,12 @@ CMake Error at BadSHELL_PATH.cmake:[0-9]+ \(add_custom_target\):
"Relative/Path" is not an absolute path.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
++
+CMake Error at BadSHELL_PATH.cmake:[0-9]+ \(add_custom_target\):
+ Error evaluating generator expression:
+
+ \$<SHELL_PATH:;>
+
+ "" is not an absolute path.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH.cmake b/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH.cmake
index 5eff7bccb..0e7c342e4 100644
--- a/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH.cmake
+++ b/Tests/RunCMake/GeneratorExpression/BadSHELL_PATH.cmake
@@ -1,4 +1,5 @@
add_custom_target(check ALL COMMAND check
$<SHELL_PATH:>
$<SHELL_PATH:Relative/Path>
+ "$<SHELL_PATH:;>"
VERBATIM)
diff --git a/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt
index dd0d931be..2f04c78f0 100644
--- a/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadStrEqual-stderr.txt
@@ -35,4 +35,6 @@ CMake Error at BadStrEqual.cmake:1 \(add_custom_target\):
\$<STREQUAL> expression requires 2 comma separated parameters, but got 3
instead.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists.txt:3 \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt
index 969393acc..98eed1f0a 100644
--- a/Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetName-stderr.txt
@@ -5,4 +5,6 @@ CMake Error at BadTargetName.cmake:1 \(add_custom_target\):
\$<TARGET_NAME> expression requires literal input.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists.txt:3 \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt
index 533d38cef..a597d79b6 100644
--- a/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
+CMake Error at BadTargetTypeObject.cmake:2 \(add_custom_target\):
Error evaluating generator expression:
\$<TARGET_FILE:objlib>
@@ -7,7 +7,7 @@ CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
-CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
+CMake Error at BadTargetTypeObject.cmake:2 \(add_custom_target\):
Error evaluating generator expression:
\$<TARGET_SONAME_FILE:objlib>
@@ -16,7 +16,7 @@ CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
+
-CMake Error at BadTargetTypeObject.cmake:3 \(add_custom_target\):
+CMake Error at BadTargetTypeObject.cmake:2 \(add_custom_target\):
Error evaluating generator expression:
\$<TARGET_LINKER_FILE:objlib>
diff --git a/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake
index c47ee2bec..60e2c0dbc 100644
--- a/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake
+++ b/Tests/RunCMake/GeneratorExpression/BadTargetTypeObject.cmake
@@ -1,5 +1,4 @@
-enable_language(C)
-add_library(objlib OBJECT empty.c)
+add_library(objlib OBJECT)
add_custom_target(check ALL COMMAND echo
$<TARGET_FILE:objlib>
$<TARGET_SONAME_FILE:objlib>
diff --git a/Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake
index d5b85c936..dfa23e09e 100644
--- a/Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake
+++ b/Tests/RunCMake/GeneratorExpression/CMP0044-WARN.cmake
@@ -1,5 +1,5 @@
-project(CMP0044-WARN)
+enable_language(C)
string(TOLOWER ${CMAKE_C_COMPILER_ID} lc_test)
if (lc_test STREQUAL CMAKE_C_COMPILER_ID)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt
index 789b4d09a..c8f773a0a 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command-stderr.txt
@@ -1,10 +1,10 @@
-CMake Error at COMPILE_LANGUAGE-add_custom_command.cmake:6 \(add_custom_command\):
+CMake Error at COMPILE_LANGUAGE-add_custom_command.cmake:2 \(add_custom_command\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
- \$<COMPILE_LANGUAGE:...> may only be used to specify include directories
- compile definitions, compile options and to evaluate components of the
+ \$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
+ compile definitions, compile options, and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake
index f4ba26153..c3f051ab4 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_command.cmake
@@ -1,8 +1,4 @@
-
-enable_language(C)
-
-add_library(empty empty.c)
-
-add_custom_command(TARGET empty PRE_BUILD
+add_custom_target(drive)
+add_custom_command(TARGET drive PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANGUAGE>
)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt
index 400fbc035..7025838b1 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target-stderr.txt
@@ -1,10 +1,10 @@
-CMake Error at COMPILE_LANGUAGE-add_custom_target.cmake:4 \(add_custom_target\):
+CMake Error at COMPILE_LANGUAGE-add_custom_target.cmake:1 \(add_custom_target\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
- \$<COMPILE_LANGUAGE:...> may only be used to specify include directories
- compile definitions, compile options and to evaluate components of the
+ \$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
+ compile definitions, compile options, and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake
index 4102623f8..b826772e2 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_custom_target.cmake
@@ -1,6 +1,3 @@
-
-enable_language(C)
-
-add_custom_target(empty
+add_custom_target(drive
COMMAND ${CMAKE_COMMAND} -E echo $<COMPILE_LANGUAGE>
)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt
index e45bb020e..8d05e59a0 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable-stderr.txt
@@ -1,10 +1,10 @@
-CMake Error at COMPILE_LANGUAGE-add_executable.cmake:4 \(add_executable\):
+CMake Error at COMPILE_LANGUAGE-add_executable.cmake:1 \(add_executable\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
- \$<COMPILE_LANGUAGE:...> may only be used to specify include directories
- compile definitions, compile options and to evaluate components of the
+ \$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
+ compile definitions, compile options, and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake
index 5c2ff351c..ff965a9e7 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_executable.cmake
@@ -1,4 +1 @@
-
-enable_language(C)
-
add_executable(empty empty.$<COMPILE_LANGUAGE>)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt
index c9ee6fe2a..2ac9b76ac 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library-stderr.txt
@@ -1,10 +1,10 @@
-CMake Error at COMPILE_LANGUAGE-add_library.cmake:4 \(add_library\):
+CMake Error at COMPILE_LANGUAGE-add_library.cmake:1 \(add_library\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
- \$<COMPILE_LANGUAGE:...> may only be used to specify include directories
- compile definitions, compile options and to evaluate components of the
+ \$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
+ compile definitions, compile options, and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake
index dd9f82403..dd1b5a2d7 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_library.cmake
@@ -1,4 +1 @@
-
-enable_language(C)
-
add_library(empty empty.$<COMPILE_LANGUAGE>)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt
index 9955f5d91..fd8a731f1 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-add_test-stderr.txt
@@ -3,8 +3,8 @@ CMake Error at COMPILE_LANGUAGE-add_test.cmake:5 \(add_test\):
\$<COMPILE_LANGUAGE>
- \$<COMPILE_LANGUAGE:...> may only be used to specify include directories
- compile definitions, compile options and to evaluate components of the
+ \$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
+ compile definitions, compile options, and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt
index eca700f4d..bef7f63b9 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-install-stderr.txt
@@ -3,6 +3,6 @@ CMake Error:
\$<COMPILE_LANGUAGE>
- \$<COMPILE_LANGUAGE:...> may only be used to specify include directories
- compile definitions, compile options and to evaluate components of the
+ \$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
+ compile definitions, compile options, and to evaluate components of the
file\(GENERATE\) command.
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt
index 2d324e2ac..8e7f88125 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources-stderr.txt
@@ -1,10 +1,10 @@
-CMake Error at COMPILE_LANGUAGE-target_sources.cmake:5 \(target_sources\):
+CMake Error at COMPILE_LANGUAGE-target_sources.cmake:2 \(target_sources\):
Error evaluating generator expression:
\$<COMPILE_LANGUAGE>
- \$<COMPILE_LANGUAGE:...> may only be used to specify include directories
- compile definitions, compile options and to evaluate components of the
+ \$<COMPILE_LANGUAGE:...> may only be used to specify include directories,
+ compile definitions, compile options, and to evaluate components of the
file\(GENERATE\) command.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake
index 0c78acd74..a4a5abb5e 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-target_sources.cmake
@@ -1,5 +1,2 @@
-
-enable_language(C)
-
-add_library(empty empty.c)
+add_library(empty)
target_sources(empty PRIVATE empty.$<COMPILE_LANGUAGE>)
diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-unknown-lang.cmake b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-unknown-lang.cmake
index cec12a3fb..00dd29070 100644
--- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-unknown-lang.cmake
+++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANGUAGE-unknown-lang.cmake
@@ -1,4 +1,4 @@
enable_language(C)
add_executable(empty empty.c)
-target_compile_options(empty PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wall>)
+target_compile_options(empty PRIVATE $<$<COMPILE_LANGUAGE:CXX>:$<TARGET_EXISTS:too,many,parameters>>)
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt
index dd7a18304..0c21aa682 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at NonValidTarget-CXX_COMPILER_ID.cmake:4 \(add_custom_command\):
+CMake Error at NonValidTarget-CXX_COMPILER_ID.cmake:1 \(add_custom_command\):
Error evaluating generator expression:
\$<CXX_COMPILER_ID>
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake
index 7dd38da4a..a9fb0925f 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake
@@ -1,8 +1,4 @@
-
-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")
+add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt
index d4a064af1..fae1bd225 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at NonValidTarget-CXX_COMPILER_VERSION.cmake:4 \(add_custom_command\):
+CMake Error at NonValidTarget-CXX_COMPILER_VERSION.cmake:1 \(add_custom_command\):
Error evaluating generator expression:
\$<CXX_COMPILER_VERSION>
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake
index 1afb2b56f..41610c422 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake
@@ -1,8 +1,4 @@
-
-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")
+add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt
index b8e53ed91..337b2996e 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at NonValidTarget-C_COMPILER_ID.cmake:4 \(add_custom_command\):
+CMake Error at NonValidTarget-C_COMPILER_ID.cmake:1 \(add_custom_command\):
Error evaluating generator expression:
\$<C_COMPILER_ID>
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake
index 2d92ee39e..1b02431e1 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake
@@ -1,8 +1,4 @@
-
-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_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.c" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<C_COMPILER_ID>.c"
)
-
-add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
+add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt
index 551efe963..d8548b515 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at NonValidTarget-C_COMPILER_VERSION.cmake:4 \(add_custom_command\):
+CMake Error at NonValidTarget-C_COMPILER_VERSION.cmake:1 \(add_custom_command\):
Error evaluating generator expression:
\$<C_COMPILER_VERSION>
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake
index 9b8a53150..bc1ffe059 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake
@@ -1,8 +1,4 @@
-
-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_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c"
+ COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.c" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$<C_COMPILER_VERSION>.c"
)
-
-add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
+add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.c")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt
index 0e87538c6..4babf4375 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at NonValidTarget-TARGET_POLICY.cmake:4 \(add_custom_command\):
+CMake Error at NonValidTarget-TARGET_POLICY.cmake:1 \(add_custom_command\):
Error evaluating generator expression:
\$<TARGET_POLICY:CMP0004>
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake
index 10b37b5a4..55d8a9981 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake
@@ -1,8 +1,4 @@
-
-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")
+add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt
index 08ad3c2d8..c4149470a 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at NonValidTarget-TARGET_PROPERTY.cmake:4 \(add_custom_command\):
+CMake Error at NonValidTarget-TARGET_PROPERTY.cmake:1 \(add_custom_command\):
Error evaluating generator expression:
\$<TARGET_PROPERTY:NotAProperty>
diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake
index 64abc5f90..9e246b278 100644
--- a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake
+++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake
@@ -1,8 +1,4 @@
-
-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")
+add_custom_target(drive DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp")
diff --git a/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion-stderr.txt b/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion-stderr.txt
index bf592e75c..013c4f25b 100644
--- a/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion-stderr.txt
+++ b/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion-stderr.txt
@@ -1,4 +1,10 @@
CMake Error at OUTPUT_NAME-recursion.cmake:[0-9]+ \(add_executable\):
- Target 'empty1' OUTPUT_NAME depends on itself.
+ Target 'empty2' OUTPUT_NAME depends on itself.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
+
+
+CMake Error at OUTPUT_NAME-recursion.cmake:[0-9]+ \(add_executable\):
+ Target 'empty2' OUTPUT_NAME depends on itself.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion.cmake b/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion.cmake
index 5cb80509e..006b0daad 100644
--- a/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion.cmake
+++ b/Tests/RunCMake/GeneratorExpression/OUTPUT_NAME-recursion.cmake
@@ -1,3 +1,6 @@
enable_language(C)
add_executable(empty1 empty.c)
set_property(TARGET empty1 PROPERTY OUTPUT_NAME $<TARGET_FILE_NAME:empty1>)
+
+add_executable(empty2 empty.c)
+set_property(TARGET empty2 PROPERTY OUTPUT_NAME $<TARGET_FILE_BASE_NAME:empty2>)
diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
index 2486259da..68a017251 100644
--- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake
@@ -15,8 +15,10 @@ run_cmake(BadSHELL_PATH)
run_cmake(CMP0044-WARN)
run_cmake(NonValidTarget-C_COMPILER_ID)
run_cmake(NonValidTarget-CXX_COMPILER_ID)
+run_cmake(NonValidTarget-Fortran_COMPILER_ID)
run_cmake(NonValidTarget-C_COMPILER_VERSION)
run_cmake(NonValidTarget-CXX_COMPILER_VERSION)
+run_cmake(NonValidTarget-Fortran_COMPILER_VERSION)
run_cmake(NonValidTarget-TARGET_BUNDLE_DIR)
run_cmake(NonValidTarget-TARGET_BUNDLE_CONTENT_DIR)
run_cmake(NonValidTarget-TARGET_PROPERTY)
@@ -29,18 +31,79 @@ run_cmake(COMPILE_LANGUAGE-add_executable)
run_cmake(COMPILE_LANGUAGE-add_library)
run_cmake(COMPILE_LANGUAGE-add_test)
run_cmake(COMPILE_LANGUAGE-unknown-lang)
+run_cmake(COMPILE_LANG_AND_ID-add_custom_target)
+run_cmake(COMPILE_LANG_AND_ID-add_custom_command)
+run_cmake(COMPILE_LANG_AND_ID-install)
+run_cmake(COMPILE_LANG_AND_ID-target_sources)
+run_cmake(COMPILE_LANG_AND_ID-add_executable)
+run_cmake(COMPILE_LANG_AND_ID-add_library)
+run_cmake(COMPILE_LANG_AND_ID-add_test)
+run_cmake(COMPILE_LANG_AND_ID-unknown-lang)
run_cmake(TARGET_FILE-recursion)
run_cmake(OUTPUT_NAME-recursion)
+run_cmake(TARGET_FILE_PREFIX)
+run_cmake(TARGET_FILE_PREFIX-imported-target)
+run_cmake(TARGET_FILE_PREFIX-non-valid-target)
+run_cmake(TARGET_LINKER_FILE_PREFIX-non-valid-target)
+run_cmake(TARGET_FILE_SUFFIX)
+run_cmake(TARGET_FILE_SUFFIX-imported-target)
+run_cmake(TARGET_FILE_SUFFIX-non-valid-target)
+run_cmake(TARGET_LINKER_FILE_SUFFIX-non-valid-target)
+run_cmake_with_options(TARGET_FILE_BASE_NAME -DCMAKE_BUILD_TYPE:STRING=Debug)
+run_cmake_with_options(TARGET_FILE_BASE_NAME-imported-target -DCMAKE_BUILD_TYPE:STRING=Debug)
+run_cmake(TARGET_FILE_BASE_NAME-non-valid-target)
+run_cmake(TARGET_LINKER_FILE_BASE_NAME-non-valid-target)
+run_cmake(TARGET_PROPERTY-INCLUDE_DIRECTORIES)
run_cmake(TARGET_PROPERTY-LOCATION)
run_cmake(TARGET_PROPERTY-SOURCES)
run_cmake(LINK_ONLY-not-linking)
+run_cmake(TARGET_EXISTS-no-arg)
+run_cmake(TARGET_EXISTS-empty-arg)
+run_cmake(TARGET_EXISTS)
+run_cmake(TARGET_EXISTS-not-a-target)
+run_cmake(TARGET_NAME_IF_EXISTS-no-arg)
+run_cmake(TARGET_NAME_IF_EXISTS-empty-arg)
+run_cmake(TARGET_NAME_IF_EXISTS)
+run_cmake(TARGET_NAME_IF_EXISTS-not-a-target)
+run_cmake(TARGET_GENEX_EVAL-no-arg)
+run_cmake(TARGET_GENEX_EVAL-no-target)
+run_cmake(TARGET_GENEX_EVAL-non-valid-target)
+run_cmake(TARGET_GENEX_EVAL-recursion1)
+run_cmake(TARGET_GENEX_EVAL-recursion2)
+run_cmake(TARGET_GENEX_EVAL)
+run_cmake(GENEX_EVAL-recursion1)
+run_cmake(GENEX_EVAL-recursion2)
+run_cmake(GENEX_EVAL)
+run_cmake(REMOVE_DUPLICATES-empty)
+run_cmake(REMOVE_DUPLICATES-1)
+run_cmake(REMOVE_DUPLICATES-2)
+run_cmake(REMOVE_DUPLICATES-3)
+run_cmake(REMOVE_DUPLICATES-4)
+run_cmake(FILTER-empty)
+run_cmake(FILTER-InvalidOperator)
+run_cmake(FILTER-Exclude)
+run_cmake(FILTER-Include)
run_cmake(ImportedTarget-TARGET_BUNDLE_DIR)
run_cmake(ImportedTarget-TARGET_BUNDLE_CONTENT_DIR)
run_cmake(ImportedTarget-TARGET_PDB_FILE)
+run_cmake(ImportedTarget-TARGET_PDB_FILE_BASE_NAME)
if(LINKER_SUPPORTS_PDB)
run_cmake(NonValidTarget-TARGET_PDB_FILE)
run_cmake(ValidTarget-TARGET_PDB_FILE)
+ run_cmake(NonValidTarget-TARGET_PDB_FILE_BASE_NAME)
+ run_cmake(ValidTarget-TARGET_PDB_FILE_BASE_NAME)
else()
run_cmake(NonValidCompiler-TARGET_PDB_FILE)
+ run_cmake(NonValidCompiler-TARGET_PDB_FILE_BASE_NAME)
endif()
+
+set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0085:STRING=OLD)
+run_cmake(CMP0085-OLD)
+unset(RunCMake_TEST_OPTIONS)
+
+run_cmake(CMP0085-WARN)
+
+set(RunCMake_TEST_OPTIONS -DCMAKE_POLICY_DEFAULT_CMP0085:STRING=NEW)
+run_cmake(CMP0085-NEW)
+unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES-check.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES-check.cmake
index f1452b54d..c1a0f5bc4 100644
--- a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES-check.cmake
+++ b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES-check.cmake
@@ -1,8 +1,5 @@
file(READ ${RunCMake_TEST_BINARY_DIR}/foo.txt foo_sources)
-# VS generators inject CMakeLists.txt as a source. Remove it.
-string(REGEX REPLACE ";[^;]*CMakeLists.txt$" "" foo_sources "${foo_sources}")
-
set(foo_expected "empty.c;empty2.c;empty3.c")
if(NOT foo_sources STREQUAL foo_expected)
set(RunCMake_TEST_FAILED "foo SOURCES was:\n [[${foo_sources}]]\nbut expected:\n [[${foo_expected}]]")
diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES.cmake b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES.cmake
index 89993ee09..dee7ead54 100644
--- a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES.cmake
+++ b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-SOURCES.cmake
@@ -1,5 +1,5 @@
+cmake_policy(SET CMP0070 NEW)
enable_language(C)
add_library(foo empty.c empty2.c)
target_sources(foo PRIVATE empty3.c)
-file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/foo.txt
- CONTENT "$<TARGET_PROPERTY:foo,SOURCES>")
+file(GENERATE OUTPUT foo.txt CONTENT "$<TARGET_PROPERTY:foo,SOURCES>")
diff --git a/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake
index 38e47f91f..a66394b42 100644
--- a/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake
+++ b/Tests/RunCMake/GeneratorExpression/ValidTarget-TARGET_PDB_FILE.cmake
@@ -3,7 +3,8 @@ enable_language(C)
add_library(empty SHARED empty.c)
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
list(GET CMAKE_CONFIGURATION_TYPES 0 FIRST_CONFIG)
set(GENERATE_CONDITION CONDITION $<CONFIG:${FIRST_CONFIG}>)
endif()
diff --git a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake
index 27250cba7..27ede066e 100644
--- a/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GeneratorPlatform/RunCMakeTest.cmake
@@ -3,7 +3,7 @@ include(RunCMake)
set(RunCMake_GENERATOR_PLATFORM "")
run_cmake(NoPlatform)
-if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio ([89]|1[01245])( 20[0-9][0-9])?$")
+if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio ([89]|1[012456])( 20[0-9][0-9])?$")
set(RunCMake_GENERATOR_PLATFORM "x64")
run_cmake(x64Platform)
else()
@@ -17,7 +17,7 @@ set(RunCMake_TEST_OPTIONS -A "Extra Platform")
run_cmake(TwoPlatforms)
unset(RunCMake_TEST_OPTIONS)
-if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio ([89]|1[01245])( 20[0-9][0-9])?$")
+if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio ([89]|1[012456])( 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)
diff --git a/Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake b/Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake
index 763478cc5..d8138b8b2 100644
--- a/Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake
+++ b/Tests/RunCMake/GeneratorPlatform/TestPlatform-toolchain.cmake
@@ -1 +1,2 @@
+message("CMAKE_VS_PLATFORM_NAME_DEFAULT is \"${CMAKE_VS_PLATFORM_NAME_DEFAULT}\"")
set(CMAKE_GENERATOR_PLATFORM "Test Platform")
diff --git a/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt
index b9bb3b231..686779013 100644
--- a/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt
+++ b/Tests/RunCMake/GeneratorPlatform/TestPlatformToolchain-stderr.txt
@@ -1,3 +1,4 @@
+CMAKE_VS_PLATFORM_NAME_DEFAULT is "[^"]+"
CMake Error at TestPlatformToolchain.cmake:[0-9]+ \(message\):
CMAKE_GENERATOR_PLATFORM is "Test Platform" as expected.
Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/GeneratorToolset/BadToolsetHostArchTwice-stderr.txt b/Tests/RunCMake/GeneratorToolset/BadToolsetHostArchTwice-stderr.txt
index 164d3aa79..7067423f4 100644
--- a/Tests/RunCMake/GeneratorToolset/BadToolsetHostArchTwice-stderr.txt
+++ b/Tests/RunCMake/GeneratorToolset/BadToolsetHostArchTwice-stderr.txt
@@ -5,6 +5,6 @@ CMake Error at CMakeLists.txt:[0-9]+ \(project\):
given toolset specification
- Test Toolset,host=x64,host=x64
+ Test Toolset,host=x64,host=x86
that contains duplicate field key 'host'\.$
diff --git a/Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake
index f89100e84..ef8fd2540 100644
--- a/Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GeneratorToolset/RunCMakeTest.cmake
@@ -3,7 +3,7 @@ include(RunCMake)
set(RunCMake_GENERATOR_TOOLSET "")
run_cmake(NoToolset)
-if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[01245]")
+if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[012456]")
set(RunCMake_GENERATOR_TOOLSET "Test Toolset")
run_cmake(TestToolset)
set(RunCMake_GENERATOR_TOOLSET "Test Toolset,cuda=Test Cuda")
@@ -12,19 +12,33 @@ if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[01245]")
run_cmake(TestToolsetCudaOnly)
set(RunCMake_GENERATOR_TOOLSET "cuda=Test Cuda")
run_cmake(TestToolsetCudaOnly)
- if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[245]")
+ if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[2456]")
set(RunCMake_GENERATOR_TOOLSET "Test Toolset,host=x64")
run_cmake(TestToolsetHostArchBoth)
set(RunCMake_GENERATOR_TOOLSET ",host=x64")
- run_cmake(TestToolsetHostArchOnly)
+ run_cmake(TestToolsetHostArchOnly_x64)
set(RunCMake_GENERATOR_TOOLSET "host=x64")
- run_cmake(TestToolsetHostArchOnly)
+ run_cmake(TestToolsetHostArchOnly_x64)
+ set(RunCMake_GENERATOR_TOOLSET "host=x86")
+ run_cmake(TestToolsetHostArchOnly_x86)
set(RunCMake_GENERATOR_TOOLSET "Test Toolset")
run_cmake(TestToolsetHostArchNone)
set(RunCMake_GENERATOR_TOOLSET "Test Toolset,host=x65")
run_cmake(BadToolsetHostArch)
- set(RunCMake_GENERATOR_TOOLSET "Test Toolset,host=x64,host=x64")
+ set(RunCMake_GENERATOR_TOOLSET "Test Toolset,host=x64,host=x86")
run_cmake(BadToolsetHostArchTwice)
+ if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[56]")
+ set(RunCMake_GENERATOR_TOOLSET "Test Toolset,version=Test Toolset Version")
+ run_cmake(TestToolsetVersionBoth)
+ set(RunCMake_GENERATOR_TOOLSET ",version=Test Toolset Version")
+ run_cmake(TestToolsetVersionOnly)
+ set(RunCMake_GENERATOR_TOOLSET "version=Test Toolset Version")
+ run_cmake(TestToolsetVersionOnly)
+ set(RunCMake_GENERATOR_TOOLSET "Test Toolset,version=Bad Toolset Version")
+ run_cmake(BadToolsetVersion)
+ set(RunCMake_GENERATOR_TOOLSET "Test Toolset,version=Test Toolset Version,version=Test Toolset Version")
+ run_cmake(BadToolsetVersionTwice)
+ endif()
else()
set(RunCMake_GENERATOR_TOOLSET "Test Toolset,host=x64")
run_cmake(BadToolsetHostArch)
@@ -47,7 +61,7 @@ set(RunCMake_TEST_OPTIONS -T "Extra Toolset")
run_cmake(TwoToolsets)
unset(RunCMake_TEST_OPTIONS)
-if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[01245]|Xcode")
+if("${RunCMake_GENERATOR}" MATCHES "Visual Studio 1[012456]|Xcode")
set(RunCMake_TEST_OPTIONS -DCMAKE_TOOLCHAIN_FILE=${RunCMake_SOURCE_DIR}/TestToolset-toolchain.cmake)
run_cmake(TestToolsetToolchain)
unset(RunCMake_TEST_OPTIONS)
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone-stdout.txt b/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone-stdout.txt
index 576b40cc0..e5e6c8da9 100644
--- a/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone-stdout.txt
+++ b/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone-stdout.txt
@@ -1,2 +1,2 @@
-- CMAKE_VS_PLATFORM_TOOLSET='Test Toolset'
--- CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE=''
+-- CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE='.*'
diff --git a/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone.cmake b/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone.cmake
index 26926f9db..085bb6b17 100644
--- a/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone.cmake
+++ b/Tests/RunCMake/GeneratorToolset/TestToolsetHostArchNone.cmake
@@ -1,2 +1,15 @@
message(STATUS "CMAKE_VS_PLATFORM_TOOLSET='${CMAKE_VS_PLATFORM_TOOLSET}'")
message(STATUS "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE='${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}'")
+
+if(CMAKE_GENERATOR MATCHES "Visual Studio 1[6]")
+ cmake_host_system_information(RESULT is_64_bit QUERY IS_64BIT)
+ if(is_64_bit)
+ if(NOT "${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}" STREQUAL "x64")
+ message(FATAL_ERROR "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE is not 'x64' as expected.")
+ endif()
+ endif()
+else()
+ if(NOT "${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}" STREQUAL "")
+ message(FATAL_ERROR "CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE is not empty as expected.")
+ endif()
+endif()
diff --git a/Tests/RunCMake/Languages/RunCMakeTest.cmake b/Tests/RunCMake/Languages/RunCMakeTest.cmake
index 732baae41..2a534b338 100644
--- a/Tests/RunCMake/Languages/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Languages/RunCMakeTest.cmake
@@ -6,3 +6,5 @@ run_cmake(link-libraries-TARGET_FILE-genex)
run_cmake(link-libraries-TARGET_FILE-genex-ok)
run_cmake(DetermineFail)
+
+run_cmake(ExternalCUDA)
diff --git a/Tests/RunCMake/LinkStatic/RunCMakeTest.cmake b/Tests/RunCMake/LinkStatic/RunCMakeTest.cmake
index 0d2949211..d3a8afb21 100644
--- a/Tests/RunCMake/LinkStatic/RunCMakeTest.cmake
+++ b/Tests/RunCMake/LinkStatic/RunCMakeTest.cmake
@@ -1,3 +1,30 @@
include(RunCMake)
run_cmake(LINK_SEARCH_STATIC)
+
+
+macro(run_cmake_target test subtest target)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(${test}-${subtest} ${CMAKE_COMMAND} --build . --target ${target} ${ARGN})
+
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+endmacro()
+
+if (NOT CMAKE_C_COMPILER_ID STREQUAL "Intel")
+ # Intel compiler does not reject bad flags or objects!
+ set(RunCMake_TEST_OUTPUT_MERGE TRUE)
+ if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)
+ endif()
+
+ run_cmake(STATIC_LIBRARY_OPTIONS)
+
+ run_cmake_target(STATIC_LIBRARY_OPTIONS basic StaticLinkOptions)
+ run_cmake_target(STATIC_LIBRARY_OPTIONS genex StaticLinkOptions_genex --config Release)
+ run_cmake_target(STATIC_LIBRARY_OPTIONS shared SharedLinkOptions)
+
+ unset(RunCMake_TEST_OPTIONS)
+ unset(RunCMake_TEST_OUTPUT_MERGE)
+endif()
diff --git a/Tests/RunCMake/Make/RunCMakeTest.cmake b/Tests/RunCMake/Make/RunCMakeTest.cmake
index 869d11e5d..82db6b742 100644
--- a/Tests/RunCMake/Make/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Make/RunCMakeTest.cmake
@@ -16,4 +16,22 @@ run_TargetMessages(OFF)
run_TargetMessages(VAR-ON -DCMAKE_TARGET_MESSAGES=ON)
run_TargetMessages(VAR-OFF -DCMAKE_TARGET_MESSAGES=OFF)
+function(run_VerboseBuild)
+ run_cmake(VerboseBuild)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VerboseBuild-build)
+ if(RunCMake_GENERATOR STREQUAL "Watcom WMake")
+ # wmake does not actually show the verbose output.
+ set(RunCMake-stdout-file VerboseBuild-build-watcom-stdout.txt)
+ endif()
+ run_cmake_command(VerboseBuild-build ${CMAKE_COMMAND} --build . -v --clean-first)
+ unset(RunCMake-stdout-file)
+ if(MAKE_IS_GNU)
+ set(RunCMake-stdout-file VerboseBuild-nowork-gnu-stdout.txt)
+ endif()
+ run_cmake_command(VerboseBuild-nowork ${CMAKE_COMMAND} --build . --verbose)
+endfunction()
+run_VerboseBuild()
+
run_cmake(CustomCommandDepfile-ERROR)
+run_cmake(IncludeRegexSubdir)
diff --git a/Tests/RunCMake/Ninja/RunCMakeTest.cmake b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
index b3720fb7a..808a872aa 100644
--- a/Tests/RunCMake/Ninja/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Ninja/RunCMakeTest.cmake
@@ -21,6 +21,24 @@ function(run_NinjaToolMissing)
endfunction()
run_NinjaToolMissing()
+function(run_NoWorkToDo)
+ run_cmake(NoWorkToDo)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/NoWorkToDo-build)
+ run_cmake_command(NoWorkToDo-build ${CMAKE_COMMAND} --build .)
+ run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain)
+endfunction()
+run_NoWorkToDo()
+
+function(run_VerboseBuild)
+ run_cmake(VerboseBuild)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/VerboseBuild-build)
+ run_cmake_command(VerboseBuild-build ${CMAKE_COMMAND} --build . -v --clean-first)
+ run_cmake_command(VerboseBuild-nowork ${CMAKE_COMMAND} --build . --verbose)
+endfunction()
+run_VerboseBuild()
+
function(run_CMP0058 case)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0058-${case}-build)
@@ -39,6 +57,14 @@ run_CMP0058(NEW-no)
run_CMP0058(NEW-by)
run_cmake(CustomCommandDepfile)
+run_cmake(CustomCommandJobPool)
+run_cmake(JobPoolUsesTerminal)
+
+run_cmake(RspFileC)
+run_cmake(RspFileCXX)
+if(TEST_Fortran)
+ run_cmake(RspFileFortran)
+endif()
function(run_CommandConcat)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CommandConcat-build)
@@ -190,15 +216,16 @@ function(run_sub_cmake test ninja_output_path_prefix)
set(cmd_prefix "")
set(cmd_suffix "")
endif()
+ set(fs_delay 3) # We assume the system as 1 sec timestamp resolution.
file(WRITE "${top_build_ninja}" "\
subninja ${escaped_ninja_output_path_prefix}/build.ninja
default ${escaped_ninja_output_path_prefix}/all
-# Sleep for 1 second before to regenerate to make sure the timestamp of
+# Sleep for long enough before regenerating to make sure the timestamp of
# the top build.ninja will be strictly greater than the timestamp of the
-# sub/build.ninja file. We assume the system as 1 sec timestamp resolution.
+# sub/build.ninja file.
rule RERUN
- command = ${cmd_prefix}\"${escaped_CMAKE_COMMAND}\" -E sleep 1 && \"${escaped_CMAKE_COMMAND}\" -E touch \"${escaped_top_build_ninja}\"${cmd_suffix}
+ command = ${cmd_prefix}\"${escaped_CMAKE_COMMAND}\" -E sleep ${fs_delay} && \"${escaped_CMAKE_COMMAND}\" -E touch \"${escaped_top_build_ninja}\"${cmd_suffix}
description = Testing regeneration
generator = 1
@@ -224,7 +251,7 @@ build build.ninja: RERUN ${escaped_build_ninja_dep} || ${escaped_ninja_output_pa
# Test regeneration rules run in order.
set(main_cmakelists "${RunCMake_SOURCE_DIR}/CMakeLists.txt")
- sleep(1) # Assume the system as 1 sec timestamp resolution.
+ sleep(${fs_delay})
touch("${main_cmakelists}")
touch("${build_ninja_dep}")
run_ninja("${top_build_dir}")
@@ -263,3 +290,17 @@ foreach(ninja_output_path_prefix "sub space" "sub")
run_sub_cmake(SubDirPrefix "${ninja_output_path_prefix}")
run_sub_cmake(CustomCommandWorkingDirectory "${ninja_output_path_prefix}")
endforeach(ninja_output_path_prefix)
+
+function (run_PreventTargetAliasesDupBuildRule)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/PreventTargetAliasesDupBuildRule-build)
+ run_cmake(PreventTargetAliasesDupBuildRule)
+ run_ninja("${RunCMake_TEST_BINARY_DIR}" -w dupbuild=err)
+endfunction ()
+run_PreventTargetAliasesDupBuildRule()
+
+function (run_PreventConfigureFileDupBuildRule)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/PreventConfigureFileDupBuildRule-build)
+ run_cmake(PreventConfigureFileDupBuildRule)
+ run_ninja("${RunCMake_TEST_BINARY_DIR}" -w dupbuild=err)
+endfunction()
+run_PreventConfigureFileDupBuildRule()
diff --git a/Tests/RunCMake/Ninja/greeting.c b/Tests/RunCMake/Ninja/greeting.c
index ba3e55beb..1124d14c0 100644
--- a/Tests/RunCMake/Ninja/greeting.c
+++ b/Tests/RunCMake/Ninja/greeting.c
@@ -6,4 +6,5 @@ __declspec(dllexport)
void greeting(void)
{
printf("Hello world!\n");
+ fflush(stdout);
}
diff --git a/Tests/RunCMake/Ninja/greeting2.c b/Tests/RunCMake/Ninja/greeting2.c
index c6ed87daa..cc8409c11 100644
--- a/Tests/RunCMake/Ninja/greeting2.c
+++ b/Tests/RunCMake/Ninja/greeting2.c
@@ -3,4 +3,5 @@
void greeting2(void)
{
printf("Hello world 2!\n");
+ fflush(stdout);
}
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt
index 838b3d8c4..4dbd86144 100644
--- a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt
@@ -3,6 +3,7 @@ CMake Error at BadSourceExpression3.cmake:2 \(add_library\):
\$<TARGET_OBJECTS:NotObjLib>
- Objects of target "NotObjLib" referenced but is not an OBJECT library.
+ Objects of target "NotObjLib" referenced but is not an allowed library
+ types \(EXECUTABLE, STATIC, SHARED, MODULE, OBJECT\).
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake
index c3d9a622d..4e07ea6fa 100644
--- a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake
+++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake
@@ -1,2 +1,2 @@
-add_library(NotObjLib STATIC a.c)
+add_library(NotObjLib INTERFACE)
add_library(A STATIC a.c $<TARGET_OBJECTS:NotObjLib>)
diff --git a/Tests/RunCMake/ObjectLibrary/CMakeLists.txt b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt
index a17c8cd13..d1b0d2c3e 100644
--- a/Tests/RunCMake/ObjectLibrary/CMakeLists.txt
+++ b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt
@@ -1,3 +1,3 @@
-cmake_minimum_required(VERSION 2.8.4)
+cmake_minimum_required(VERSION 3.10)
project(${RunCMake_TEST} C)
include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/ObjectLibrary/InstallNotSupported-stderr.txt b/Tests/RunCMake/ObjectLibrary/InstallNotSupported-stderr.txt
index 35a0e4fdf..a7004c14e 100644
--- a/Tests/RunCMake/ObjectLibrary/InstallNotSupported-stderr.txt
+++ b/Tests/RunCMake/ObjectLibrary/InstallNotSupported-stderr.txt
@@ -1,5 +1,5 @@
CMake Error at InstallNotSupported.cmake:[0-9]+ \(install\):
- install TARGETS given OBJECT library "A" which may not be installed under
- Xcode with multiple architectures.
+ install TARGETS given OBJECT library "A" whose objects may not be installed
+ under Xcode with multiple architectures.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt b/Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt
index 40d650e21..208f3c9e6 100644
--- a/Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt
+++ b/Tests/RunCMake/ObjectLibrary/OwnSources-stderr.txt
@@ -2,4 +2,6 @@
The SOURCES of "A" use a generator expression that depends on the SOURCES
themselves.
Call Stack \(most recent call first\):
- CMakeLists.txt:[0-9]+ \(include\)$
+ CMakeLists.txt:[0-9]+ \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake
index b8eed73bb..5ec401873 100644
--- a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake
@@ -6,17 +6,51 @@ run_cmake(BadSourceExpression3)
run_cmake(BadObjSource1)
run_cmake(BadObjSource2)
if(RunCMake_GENERATOR STREQUAL "Xcode" AND "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]")
- run_cmake(ExportNotSupported)
run_cmake(ImportNotSupported)
run_cmake(InstallNotSupported)
else()
- run_cmake(Export)
run_cmake(Import)
run_cmake(Install)
+ run_cmake(InstallLinkedObj1)
+ run_cmake(InstallLinkedObj2)
endif()
-run_cmake(LinkObjLHS)
-run_cmake(LinkObjRHS1)
-run_cmake(LinkObjRHS2)
+run_cmake(Export)
+
+function (run_object_lib_build name)
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${name}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(${name})
+ run_cmake_command(${name}-build ${CMAKE_COMMAND} --build .)
+endfunction ()
+
+function (run_object_lib_build2 name)
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${name}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(${name})
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ run_cmake_command(${name}-build ${CMAKE_COMMAND} --build .)
+endfunction ()
+
+if(NOT (RunCMake_GENERATOR STREQUAL "Xcode" AND "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]"))
+ run_object_lib_build(CheckTargetObjects)
+endif()
+
+run_object_lib_build(LinkObjLHSShared)
+run_object_lib_build(LinkObjLHSStatic)
+run_object_lib_build(LinkObjRHSShared)
+run_object_lib_build(LinkObjRHSStatic)
+run_object_lib_build2(LinkObjRHSObject)
+run_object_lib_build(LinkObjRHSShared2)
+run_object_lib_build(LinkObjRHSStatic2)
+run_object_lib_build2(LinkObjRHSObject2)
+run_object_lib_build(TransitiveDependencies)
+
run_cmake(MissingSource)
run_cmake(ObjWithObj)
run_cmake(OwnSources)
@@ -24,6 +58,7 @@ run_cmake(PostBuild)
run_cmake(PreBuild)
run_cmake(PreLink)
+
function(run_Dependencies)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Dependencies-build)
set(RunCMake_TEST_NO_CLEAN 1)
diff --git a/Tests/RunCMake/ObjectLibrary/a.c b/Tests/RunCMake/ObjectLibrary/a.c
index 16363033d..8e490f374 100644
--- a/Tests/RunCMake/ObjectLibrary/a.c
+++ b/Tests/RunCMake/ObjectLibrary/a.c
@@ -1,4 +1,10 @@
-int a(void)
+#if defined(_WIN32) && defined(COMPILE_FOR_SHARED_LIB)
+# define EXPORT __declspec(dllexport)
+#else
+# define EXPORT
+#endif
+
+EXPORT int a(void)
{
return 0;
}
diff --git a/Tests/RunCMake/ObjectLibrary/b.c b/Tests/RunCMake/ObjectLibrary/b.c
index 6751907b6..220ce0302 100644
--- a/Tests/RunCMake/ObjectLibrary/b.c
+++ b/Tests/RunCMake/ObjectLibrary/b.c
@@ -1,4 +1,14 @@
-int b(void)
+#if defined(_WIN32) && defined(COMPILE_FOR_SHARED_LIB)
+# define EXPORT __declspec(dllexport)
+#else
+# define EXPORT
+#endif
+
+extern int a(void);
+EXPORT int b()
{
- return 0;
+ return a();
}
+#ifndef REQUIRED
+# error "REQUIRED needs to be defined"
+#endif
diff --git a/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt b/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt
index 16bcb3689..66ff016f9 100644
--- a/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt
+++ b/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt
@@ -2,4 +2,4 @@
add_library(foo STATIC foo.cpp)
string(TOLOWER ${CMAKE_CXX_COMPILER_ID} compiler_id)
-target_compile_definitions(foo PRIVATE Foo=$<CXX_COMPILER_ID:${compiler_id}>)
+target_compile_definitions(foo PRIVATE Foo=$<CXX_COMPILER_ID:invalid,${compiler_id}>)
diff --git a/Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake b/Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake
index 6a67e3cad..6efa0d402 100644
--- a/Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake
+++ b/Tests/RunCMake/PositionIndependentCode/RunCMakeTest.cmake
@@ -7,3 +7,67 @@ run_cmake(Conflict4)
run_cmake(Conflict5)
run_cmake(Conflict6)
run_cmake(Debug)
+run_cmake(Genex1)
+run_cmake(Genex2)
+
+set(RunCMake_TEST_OPTIONS "-DPIE_SUPPORTED=${RunCMake_BINARY_DIR}/PIESupported.cmake")
+run_cmake(CheckPIESupported)
+include ("${RunCMake_BINARY_DIR}/PIESupported.cmake" OPTIONAL)
+
+if (PIE_SUPPORTED OR NO_PIE_SUPPORTED)
+ if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|(Free|Net|Open)BSD)$")
+ # try to locate readelf needed for validation
+ find_program (READELF NAMES readelf)
+ endif()
+ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ # try to locate otool needed for validation
+ find_program (OTOOL NAMES otool)
+ endif()
+
+ if ((READELF OR OTOOL) AND
+ (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
+ OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
+ OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
+ macro(run_cmake_target test subtest)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_CONFIG Release)
+ run_cmake_command(${test}-${subtest} ${CMAKE_COMMAND} --build . --config Release --target ${subtest} ${ARGN})
+
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+ endmacro()
+
+ set(RunCMake_TEST_SOURCE_DIR "${RunCMake_SOURCE_DIR}")
+ set(RunCMake_TEST_OUTPUT_MERGE TRUE)
+ if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)
+ endif()
+
+ run_cmake(PIE)
+ if (PIE_SUPPORTED)
+ run_cmake_target(PIE pie_on)
+ endif()
+ if (NO_PIE_SUPPORTED)
+ run_cmake_target(PIE pie_off)
+ endif()
+
+ run_cmake(CMP0083)
+ run_cmake_target(CMP0083 cmp0083_ref)
+
+ # retrieve default mode
+ include("${RunCMake_SOURCE_DIR}/PIE_validator.cmake")
+ include("${RunCMake_BINARY_DIR}/CMP0083-build/Release/CMP0083_config.cmake")
+ check_executable("${cmp0083_ref}" cmp0083_ref_mode)
+
+ if ((cmp0083_ref_mode STREQUAL "PIE" AND NO_PIE_SUPPORTED)
+ OR (cmp0083_ref_mode STREQUAL "NO_PIE" AND PIE_SUPPORTED))
+ run_cmake_target(CMP0083 cmp0083_new)
+ endif()
+ run_cmake_target(CMP0083 cmp0083_old)
+
+ unset(RunCMake_TEST_SOURCE_DIR)
+ unset(RunCMake_TEST_OPTIONS)
+ unset(RunCMake_TEST_OUTPUT_MERGE)
+ endif()
+endif()
diff --git a/Tests/RunCMake/README.rst b/Tests/RunCMake/README.rst
index 4aae4aed5..d8b43feef 100644
--- a/Tests/RunCMake/README.rst
+++ b/Tests/RunCMake/README.rst
@@ -47,11 +47,11 @@ but do not actually build anything. To add a test:
containing expected test results:
``<SubTest>-result.txt``
- Process result expected if not "0"
+ Regex matching expected process result, if not ``0``
``<SubTest>-stdout.txt``
Regex matching expected stdout content
``<SubTest>-stderr.txt``
- Regex matching expected stderr content, if not "^$"
+ Regex matching expected stderr content, if not ``^$``
``<SubTest>-check.cmake``
Custom result check.
@@ -65,3 +65,14 @@ but do not actually build anything. To add a test:
Top of test binary tree
and an failure must store a message in ``RunCMake_TEST_FAILED``.
+
+To speed up local testing, you can choose to run only a subset of
+``run_cmake()`` tests in a ``RunCMakeTest.cmake`` script by using the
+``RunCMake_TEST_FILTER`` environment variable. If this variable is set,
+it is treated as a regular expression, and any tests whose names don't
+match the regular expression are not run. For example::
+
+ $ RunCMake_TEST_FILTER="^example" ctest -R '^RunCMake\.Example$'
+
+This will only run subtests in ``RunCMake.Example`` that start with
+``example``.
diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake
index 26312c45c..c743a02a3 100644
--- a/Tests/RunCMake/RunCMake.cmake
+++ b/Tests/RunCMake/RunCMake.cmake
@@ -9,6 +9,10 @@ foreach(arg
endforeach()
function(run_cmake test)
+ if(DEFINED ENV{RunCMake_TEST_FILTER} AND NOT test MATCHES "$ENV{RunCMake_TEST_FILTER}")
+ return()
+ endif()
+
set(top_src "${RunCMake_SOURCE_DIR}")
set(top_bin "${RunCMake_BINARY_DIR}")
if(EXISTS ${top_src}/${test}-result.txt)
@@ -45,15 +49,17 @@ function(run_cmake test)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
endif()
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ if(RunCMake-prep-file AND EXISTS ${top_src}/${RunCMake-prep-file})
+ include(${top_src}/${RunCMake-prep-file})
+ else()
+ include(${top_src}/${test}-prep.cmake OPTIONAL)
+ endif()
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_GENERATOR MATCHES "^Visual Studio 8 2005" AND NOT RunCMake_WARN_VS8)
- list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_WARN_VS8=OFF)
- endif()
if(RunCMake_MAKE_PROGRAM)
list(APPEND RunCMake_TEST_OPTIONS "-DCMAKE_MAKE_PROGRAM=${RunCMake_MAKE_PROGRAM}")
endif()
@@ -68,22 +74,45 @@ function(run_cmake test)
else()
set(maybe_timeout "")
endif()
+ if(RunCMake-stdin-file AND EXISTS ${top_src}/${RunCMake-stdin-file})
+ set(maybe_input_file INPUT_FILE ${top_src}/${RunCMake-stdin-file})
+ elseif(EXISTS ${top_src}/${test}-stdin.txt)
+ set(maybe_input_file INPUT_FILE ${top_src}/${test}-stdin.txt)
+ else()
+ set(maybe_input_file "")
+ endif()
if(RunCMake_TEST_COMMAND)
+ if(NOT RunCMake_TEST_COMMAND_WORKING_DIRECTORY)
+ set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ endif()
execute_process(
COMMAND ${RunCMake_TEST_COMMAND}
- WORKING_DIRECTORY "${RunCMake_TEST_BINARY_DIR}"
+ WORKING_DIRECTORY "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}"
OUTPUT_VARIABLE actual_stdout
ERROR_VARIABLE ${actual_stderr_var}
RESULT_VARIABLE actual_result
ENCODING UTF8
${maybe_timeout}
+ ${maybe_input_file}
)
else()
+ if(RunCMake_GENERATOR_INSTANCE)
+ set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE=${RunCMake_GENERATOR_INSTANCE}")
+ else()
+ set(_D_CMAKE_GENERATOR_INSTANCE "")
+ endif()
+ if(NOT RunCMake_TEST_NO_SOURCE_DIR)
+ set(maybe_source_dir "${RunCMake_TEST_SOURCE_DIR}")
+ else()
+ set(maybe_source_dir "")
+ endif()
execute_process(
- COMMAND ${CMAKE_COMMAND} "${RunCMake_TEST_SOURCE_DIR}"
+ COMMAND ${CMAKE_COMMAND}
+ ${maybe_source_dir}
-G "${RunCMake_GENERATOR}"
-A "${RunCMake_GENERATOR_PLATFORM}"
-T "${RunCMake_GENERATOR_TOOLSET}"
+ ${_D_CMAKE_GENERATOR_INSTANCE}
-DRunCMake_TEST=${test}
--no-warn-unused-cli
${RunCMake_TEST_OPTIONS}
@@ -93,15 +122,31 @@ function(run_cmake test)
RESULT_VARIABLE actual_result
ENCODING UTF8
${maybe_timeout}
+ ${maybe_input_file}
)
endif()
set(msg "")
if(NOT "${actual_result}" MATCHES "${expect_result}")
string(APPEND msg "Result is [${actual_result}], not [${expect_result}].\n")
endif()
+ string(CONCAT ignore_line_regex
+ "(^|\n)((==[0-9]+=="
+ "|BullseyeCoverage"
+ "|[a-z]+\\([0-9]+\\) malloc:"
+ "|clang[^:]*: warning: the object size sanitizer has no effect at -O0, but is explicitly enabled:"
+ "|Error kstat returned"
+ "|Hit xcodebuild bug"
+ "|[^\n]*xcodebuild[^\n]*warning: file type[^\n]*is based on missing file type"
+ "|ld: 0711-224 WARNING: Duplicate symbol: .__init_aix_libgcc_cxa_atexit"
+ "|ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information"
+ "|[^\n]*is a member of multiple groups"
+ "|[^\n]*from Time Machine by path"
+ "|[^\n]*Bullseye Testing Technology"
+ ")[^\n]*\n)+"
+ )
foreach(o out err)
string(REGEX REPLACE "\r\n" "\n" actual_std${o} "${actual_std${o}}")
- string(REGEX REPLACE "(^|\n)((==[0-9]+==|BullseyeCoverage|[a-z]+\\([0-9]+\\) malloc:|Error kstat returned|Hit xcodebuild bug|[^\n]*is a member of multiple groups|[^\n]*from Time Machine by path|[^\n]*Bullseye Testing Technology)[^\n]*\n)+" "\\1" actual_std${o} "${actual_std${o}}")
+ string(REGEX REPLACE "${ignore_line_regex}" "\\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})
@@ -146,5 +191,10 @@ function(run_cmake_command test)
run_cmake(${test})
endfunction()
+function(run_cmake_with_options test)
+ set(RunCMake_TEST_OPTIONS "${ARGN}")
+ run_cmake(${test})
+endfunction()
+
# Protect RunCMake tests from calling environment.
unset(ENV{MAKEFLAGS})
diff --git a/Tests/RunCMake/RunCTest.cmake b/Tests/RunCMake/RunCTest.cmake
index 89e16ee69..98fdf20ac 100644
--- a/Tests/RunCMake/RunCTest.cmake
+++ b/Tests/RunCMake/RunCTest.cmake
@@ -3,8 +3,12 @@ include(RunCMake)
function(run_ctest CASE_NAME)
configure_file(${RunCMake_SOURCE_DIR}/test.cmake.in
${RunCMake_BINARY_DIR}/${CASE_NAME}/test.cmake @ONLY)
- configure_file(${RunCMake_SOURCE_DIR}/CTestConfig.cmake.in
- ${RunCMake_BINARY_DIR}/${CASE_NAME}/CTestConfig.cmake @ONLY)
+ if(EXISTS "${RunCMake_SOURCE_DIR}/CTestConfig.cmake.in")
+ configure_file(${RunCMake_SOURCE_DIR}/CTestConfig.cmake.in
+ ${RunCMake_BINARY_DIR}/${CASE_NAME}/CTestConfig.cmake @ONLY)
+ else()
+ file(REMOVE ${RunCMake_BINARY_DIR}/${CASE_NAME}/CTestConfig.cmake)
+ endif()
configure_file(${RunCMake_SOURCE_DIR}/CMakeLists.txt.in
${RunCMake_BINARY_DIR}/${CASE_NAME}/CMakeLists.txt @ONLY)
run_cmake_command(${CASE_NAME} ${CMAKE_CTEST_COMMAND}
diff --git a/Tests/RunCMake/RuntimePath/RunCMakeTest.cmake b/Tests/RunCMake/RuntimePath/RunCMakeTest.cmake
index a9a7f05c7..6f1baa1d9 100644
--- a/Tests/RunCMake/RuntimePath/RunCMakeTest.cmake
+++ b/Tests/RunCMake/RuntimePath/RunCMakeTest.cmake
@@ -5,7 +5,7 @@ function(run_SymlinkImplicit)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SymlinkImplicit-build)
set(RunCMake_TEST_NO_CLEAN 1)
- if(RunCMake_GENERATOR MATCHES "Make|Ninja")
+ if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@@ -16,3 +16,17 @@ function(run_SymlinkImplicit)
${CMAKE_COMMAND} -Ddir=${RunCMake_TEST_BINARY_DIR} -P ${RunCMake_SOURCE_DIR}/SymlinkImplicitCheck.cmake)
endfunction()
run_SymlinkImplicit()
+
+function(run_Relative)
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Relative-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+ endif()
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(Relative)
+ run_cmake_command(Relative-build ${CMAKE_COMMAND} --build . --config Debug)
+endfunction()
+run_Relative()
diff --git a/Tests/RunCMake/RuntimePath/main.c b/Tests/RunCMake/RuntimePath/main.c
index 8488f4e58..181cd0973 100644
--- a/Tests/RunCMake/RuntimePath/main.c
+++ b/Tests/RunCMake/RuntimePath/main.c
@@ -1,4 +1,6 @@
+extern int libA(void);
+
int main(void)
{
- return 0;
+ return libA();
}
diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake
index 4864295dc..481704554 100644
--- a/Tests/RunCMake/Swift/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake
@@ -4,6 +4,10 @@ if(RunCMake_GENERATOR STREQUAL Xcode)
if(XCODE_BELOW_6_1)
run_cmake(XcodeTooOld)
endif()
+elseif(RunCMake_GENERATOR STREQUAL Ninja)
+ if(CMAKE_Swift_COMPILER)
+ run_cmake(Win32ExecutableDisallowed)
+ endif()
else()
run_cmake(NotSupported)
endif()
diff --git a/Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt b/Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt
index acfa30a25..0dde1bc5e 100644
--- a/Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt
+++ b/Tests/RunCMake/Syntax/CMP0053-At-OLD-stderr.txt
@@ -1 +1,12 @@
-^-->wrong<--$
+^CMake Deprecation Warning at CMP0053-At-OLD.cmake:1 \(cmake_policy\):
+ The OLD behavior for policy CMP0053 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:3 \(include\)
++
+-->wrong<--$
diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake
index d1fbb16aa..8d74dc163 100644
--- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake
@@ -55,6 +55,8 @@ run_cmake(BracketNoSpace5)
run_cmake(Escape1)
run_cmake(Escape2)
run_cmake(EscapeCharsAllowed)
+run_cmake(NullAfterBackslash)
+run_cmake(NullTerminatedArgument)
include("${RunCMake_SOURCE_DIR}/EscapeCharsDisallowed.cmake")
run_cmake(ParenNoSpace0)
run_cmake(ParenNoSpace1)
@@ -109,6 +111,11 @@ run_cmake(CMP0053-NameWithNewlineQuoted)
run_cmake(CMP0053-NameWithCarriageReturnQuoted)
run_cmake(CMP0053-NameWithEscapedSpacesQuoted)
run_cmake(CMP0053-NameWithEscapedTabsQuoted)
+run_cmake(CMP0053-Dollar-OLD)
+run_cmake(CMP0053-Dollar-NEW)
+
+# Variable special types
+run_cmake(QueryCache)
# Function and macro tests.
run_cmake(FunctionUnmatched)
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt
index 3f5224487..f3ee8951b 100644
--- a/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt
+++ b/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at UnterminatedCall1.cmake:2:
+CMake Error at UnterminatedCall1.cmake:1:
Parse error. Function missing ending "\)". End of file reached.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall1.cmake b/Tests/RunCMake/Syntax/UnterminatedCall1.cmake
index 1166109c9..e1d211877 100644
--- a/Tests/RunCMake/Syntax/UnterminatedCall1.cmake
+++ b/Tests/RunCMake/Syntax/UnterminatedCall1.cmake
@@ -1 +1,4 @@
message(
+
+
+message("Additional message")
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt
index 18656f713..04216c32f 100644
--- a/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt
+++ b/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt
@@ -1,4 +1,4 @@
-CMake Error at UnterminatedCall2.cmake:4:
+CMake Error at UnterminatedCall2.cmake:3:
Parse error. Function missing ending "\)". End of file reached.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/Syntax/UnterminatedCall2.cmake b/Tests/RunCMake/Syntax/UnterminatedCall2.cmake
index 26e9e6223..8d4088dcb 100644
--- a/Tests/RunCMake/Syntax/UnterminatedCall2.cmake
+++ b/Tests/RunCMake/Syntax/UnterminatedCall2.cmake
@@ -1,3 +1,6 @@
set(var "\
")
message(
+
+
+message("Additional message")
diff --git a/Tests/RunCMake/TargetObjects/NoTarget.cmake b/Tests/RunCMake/TargetObjects/NoTarget.cmake
index 5d7e33e79..268577d50 100644
--- a/Tests/RunCMake/TargetObjects/NoTarget.cmake
+++ b/Tests/RunCMake/TargetObjects/NoTarget.cmake
@@ -1,7 +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>)
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_output CONTENT $<TARGET_OBJECTS:NoTarget>)
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_output2 CONTENT $<TARGET_PROPERTY:iface,INTERFACE_SOURCES>)
install(FILES $<TARGET_OBJECTS:NoTarget> DESTINATION objects)
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt b/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt
index a66794ce8..77c4afd08 100644
--- a/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt
+++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget-stderr.txt
@@ -1,8 +1,9 @@
-CMake Error at NotObjlibTarget.cmake:3 \(file\):
+CMake Error at NotObjlibTarget.cmake:[0-9]+ \(file\):
Error evaluating generator expression:
- \$<TARGET_OBJECTS:StaticLib>
+ \$<TARGET_OBJECTS:IFaceLib>
- Objects of target "StaticLib" referenced but is not an OBJECT library.
+ Objects of target "IFaceLib" referenced but is not an allowed library types
+ \(EXECUTABLE, STATIC, SHARED, MODULE, OBJECT\).
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake
index 8e5fdd047..9fec369a7 100644
--- a/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake
+++ b/Tests/RunCMake/TargetObjects/NotObjlibTarget.cmake
@@ -1,3 +1,3 @@
-add_library(StaticLib empty.cpp)
+add_library(IFaceLib INTERFACE )
-file(GENERATE OUTPUT test_output CONTENT $<TARGET_OBJECTS:StaticLib>)
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_output CONTENT $<TARGET_OBJECTS:IFaceLib>)
diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
index 5f6be877b..0bcf88678 100644
--- a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
+++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
@@ -12,6 +12,7 @@
\* CMP0021
\* CMP0022
\* CMP0027
+ \* CMP0037
\* CMP0038
\* CMP0041
\* CMP0042
@@ -22,6 +23,10 @@
\* CMP0065
\* CMP0068
\* CMP0069
+ \* CMP0073
+ \* CMP0076
+ \* CMP0081
+ \* CMP0083
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt
index 3adf73ea0..d40b16baa 100644
--- a/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/BadNonTarget-stderr.txt
@@ -5,4 +5,6 @@ CMake Error at BadNonTarget.cmake:7 \(include_directories\):
Target "NonExistent" not found.
Call Stack \(most recent call first\):
- CMakeLists.txt:8 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt
index 7e002f547..8bff68e08 100644
--- a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle1-stderr.txt
@@ -7,4 +7,4 @@ CMake Error at LinkImplementationCycle1.cmake:5 \(target_link_libraries\):
target property which is transitive over the link libraries, creating a
recursion.
Call Stack \(most recent call first\):
- CMakeLists.txt:8 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt
index 2f72de6ec..044b77cc6 100644
--- a/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/LinkImplementationCycle2-stderr.txt
@@ -7,4 +7,4 @@ CMake Error at LinkImplementationCycle2.cmake:5 \(target_link_libraries\):
target property which is transitive over the link libraries, creating a
recursion.
Call Stack \(most recent call first\):
- CMakeLists.txt:8 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake
index 645a57d5f..4294e9fd7 100644
--- a/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake
+++ b/Tests/RunCMake/TargetPropertyGeneratorExpressions/RunCMakeTest.cmake
@@ -1,20 +1,8 @@
include(RunCMake)
-run_cmake(BadSelfReference1)
-run_cmake(BadSelfReference2)
-run_cmake(BadSelfReference3)
-run_cmake(BadSelfReference4)
-run_cmake(BadSelfReference5)
-run_cmake(BadSelfReference6)
+run_cmake(BadSelfReference)
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(BadInvalidName)
run_cmake(LinkImplementationCycle1)
run_cmake(LinkImplementationCycle2)
run_cmake(LinkImplementationCycle3)
diff --git a/Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt b/Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt
index 1de5dd72e..c6b75fceb 100644
--- a/Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt
+++ b/Tests/RunCMake/TargetSources/ConfigNotAllowed-stderr.txt
@@ -6,9 +6,7 @@ CMake Error in CMakeLists.txt:
.*/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/OriginDebug-stderr.txt b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt
index 11bc96cf9..a40f46315 100644
--- a/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt
+++ b/Tests/RunCMake/TargetSources/OriginDebug-stderr.txt
@@ -4,7 +4,7 @@ CMake Debug Log at OriginDebug.cmake:13 \(add_library\):
\* .*Tests/RunCMake/TargetSources/empty_2.cpp
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
.*
CMake Debug Log at OriginDebug.cmake:16 \(set_property\):
Used sources for target OriginDebug:
@@ -12,7 +12,7 @@ CMake Debug Log at OriginDebug.cmake:16 \(set_property\):
\* .*Tests/RunCMake/TargetSources/empty_3.cpp
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
.*
CMake Debug Log at OriginDebug.cmake:20 \(target_sources\):
Used sources for target OriginDebug:
@@ -20,7 +20,7 @@ CMake Debug Log at OriginDebug.cmake:20 \(target_sources\):
\* .*Tests/RunCMake/TargetSources/empty_4.cpp
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
.*
CMake Debug Log at OriginDebug.cmake:14 \(target_link_libraries\):
Used sources for target OriginDebug:
@@ -28,4 +28,4 @@ CMake Debug Log at OriginDebug.cmake:14 \(target_link_libraries\):
\* .*Tests/RunCMake/TargetSources/empty_1.cpp
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/TargetSources/RelativePathInInterface.cmake b/Tests/RunCMake/TargetSources/RelativePathInInterface.cmake
index 8bb6149d9..0d3e9a456 100644
--- a/Tests/RunCMake/TargetSources/RelativePathInInterface.cmake
+++ b/Tests/RunCMake/TargetSources/RelativePathInInterface.cmake
@@ -1,6 +1,10 @@
+cmake_policy(SET CMP0076 NEW)
add_library(iface INTERFACE)
target_sources(iface INTERFACE empty_1.cpp)
+get_property(iface_sources TARGET iface PROPERTY INTERFACE_SOURCES)
+message(STATUS "iface: ${iface_sources}")
+
add_executable(main main.cpp)
target_link_libraries(main iface)
diff --git a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake
index bb55a6ebd..bee8c4e38 100644
--- a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake
+++ b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake
@@ -2,11 +2,15 @@ include(RunCMake)
if(RunCMake_GENERATOR MATCHES "Visual Studio|Xcode")
run_cmake(ConfigNotAllowed)
- run_cmake(OriginDebugIDE)
-else()
- run_cmake(OriginDebug)
endif()
+run_cmake(OriginDebug)
run_cmake(CMP0026-LOCATION)
+run_cmake(CMP0076-OLD)
+run_cmake(CMP0076-WARN)
run_cmake(RelativePathInInterface)
+run_cmake(RelativePathInSubdirGenEx)
+run_cmake(RelativePathInSubdirInterface)
+run_cmake(RelativePathInSubdirPrivate)
+run_cmake(RelativePathInSubdirInclude)
run_cmake(ExportBuild)
diff --git a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
index 8a202008f..7eb4485d0 100644
--- a/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ToolchainFile/RunCMakeTest.cmake
@@ -9,3 +9,11 @@ run_cmake_toolchain(CallEnableLanguage)
run_cmake_toolchain(CallProject)
run_cmake_toolchain(FlagsInit)
run_cmake_toolchain(LinkFlagsInit)
+
+function(run_IncludeDirectories)
+ run_cmake_toolchain(IncludeDirectories)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/IncludeDirectories-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(IncludeDirectories-build ${CMAKE_COMMAND} --build . --config Debug)
+endfunction()
+run_IncludeDirectories()
diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
index 3af877f4f..27b81b7cd 100644
--- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
@@ -1,6 +1,32 @@
include(RunCMake)
+cmake_policy(SET CMP0054 NEW)
+
+run_cmake(VsCSharpCompilerOpts)
+run_cmake(ExplicitCMakeLists)
+run_cmake(RuntimeLibrary)
+run_cmake(SourceGroupCMakeLists)
+
run_cmake(VsConfigurationType)
run_cmake(VsTargetsFileReferences)
run_cmake(VsCustomProps)
run_cmake(VsDebuggerWorkingDir)
+run_cmake(VsDebuggerCommand)
+run_cmake(VsDebuggerCommandArguments)
+run_cmake(VsDebuggerEnvironment)
run_cmake(VsCSharpCustomTags)
+run_cmake(VsCSharpReferenceProps)
+run_cmake(VsCSharpWithoutSources)
+run_cmake(VsCSharpDeployFiles)
+run_cmake(VSCSharpDefines)
+run_cmake(VsSdkDirectories)
+run_cmake(VsGlobals)
+run_cmake(VsProjectImport)
+run_cmake(VsPackageReferences)
+
+if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
+ run_cmake(VsJustMyCode)
+endif()
+
+if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.20)
+ run_cmake(VsSpectreMitigation)
+endif()
diff --git a/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake b/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake
index 70ea19326..9eb4619f4 100644
--- a/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake
+++ b/Tests/RunCMake/VS10Project/VsCSharpCustomTags-check.cmake
@@ -4,20 +4,31 @@ if(NOT EXISTS "${csProjectFile}")
return()
endif()
-set(tagFound FALSE)
+# test VS_CSHARP_* for the following extensions
+set(fileExtensions
+ "cs"
+ "png"
+ "jpg"
+ "xml"
+ "settings")
+#
set(tagName "MyCustomTag")
set(tagValue "MyCustomValue")
file(STRINGS "${csProjectFile}" lines)
-foreach(line IN LISTS lines)
- if(line MATCHES "^ *<${tagName}>${tagValue}</${tagName}>")
- message(STATUS "foo.csproj has tag ${tagName} with value ${tagValue} defined")
- set(tagFound TRUE)
+
+foreach(e ${fileExtensions})
+ string(TOUPPER ${e} eUC)
+ set(tagFound FALSE)
+ foreach(line IN LISTS lines)
+ if(line MATCHES "^ *<${tagName}${eUC}>${tagValue}${eUC}</${tagName}${eUC}>")
+ message(STATUS "foo.csproj has tag ${tagName}${eUC} with value ${tagValue}${eUC} defined")
+ set(tagFound TRUE)
+ endif()
+ endforeach()
+ if(NOT tagFound)
+ set(RunCMake_TEST_FAILED "Source file tag ${tagName}${eUC} with value ${tagValue}${eUC} not found.")
+ return()
endif()
endforeach()
-
-if(NOT tagFound)
- set(RunCMake_TEST_FAILED "Source file tag ${tagName} with value ${tagValue} not found.")
- return()
-endif()
diff --git a/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake b/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake
index c51e9c370..96be54b06 100644
--- a/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake
+++ b/Tests/RunCMake/VS10Project/VsCSharpCustomTags.cmake
@@ -1,11 +1,26 @@
enable_language(CSharp)
-add_library(foo foo.cs)
-set(props_file "${CMAKE_CURRENT_SOURCE_DIR}/my.props")
+# test VS_CSHARP_* for the following extensions
+set(fileExtensions
+ "cs"
+ "png"
+ "jpg"
+ "xml"
+ "settings")
+#
set(tagName "MyCustomTag")
set(tagValue "MyCustomValue")
-set_source_files_properties(foo.cs
- PROPERTIES
- VS_CSHARP_${tagName} "${tagValue}")
+set(fileNames)
+foreach(e ${fileExtensions})
+ set(currentFile "${CMAKE_CURRENT_BINARY_DIR}/foo.${e}")
+ list(APPEND fileNames ${currentFile})
+ file(TOUCH "${currentFile}")
+ string(TOUPPER ${e} eUC)
+ set_source_files_properties("${currentFile}"
+ PROPERTIES
+ VS_CSHARP_${tagName}${eUC} "${tagValue}${eUC}")
+endforeach()
+
+add_library(foo ${fileNames})
diff --git a/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir-check.cmake b/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir-check.cmake
index 637c68c60..9d3f2a850 100644
--- a/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir-check.cmake
+++ b/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir-check.cmake
@@ -1,22 +1,24 @@
-set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
-if(NOT EXISTS "${vcProjectFile}")
- set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
- return()
-endif()
+foreach(target foo bar)
+ set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/${target}.vcxproj")
+ if(NOT EXISTS "${vcProjectFile}")
+ set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.")
+ return()
+ endif()
-set(debuggerWorkDirSet FALSE)
+ set(debuggerWorkDirSet FALSE)
-file(STRINGS "${vcProjectFile}" lines)
-foreach(line IN LISTS lines)
- if(line MATCHES "^ *<LocalDebuggerWorkingDirectory[^>]*>([^<>]+)</LocalDebuggerWorkingDirectory>$")
- if("${CMAKE_MATCH_1}" STREQUAL "my-debugger-directory")
- message(STATUS "foo.vcxproj has debugger working dir set")
- set(debuggerWorkDirSet TRUE)
+ file(STRINGS "${vcProjectFile}" lines)
+ foreach(line IN LISTS lines)
+ if(line MATCHES "^ *<LocalDebuggerWorkingDirectory[^>]*>([^<>]+)</LocalDebuggerWorkingDirectory>$")
+ if("${CMAKE_MATCH_1}" STREQUAL "my-debugger-directory foo")
+ message(STATUS "${target}.vcxproj has debugger working dir set")
+ set(debuggerWorkDirSet TRUE)
+ endif()
endif()
+ endforeach()
+
+ if(NOT debuggerWorkDirSet)
+ set(RunCMake_TEST_FAILED "LocalDebuggerWorkingDirectory not found or not set correctly.")
+ return()
endif()
endforeach()
-
-if(NOT debuggerWorkDirSet)
- set(RunCMake_TEST_FAILED "LocalDebuggerWorkingDirectory not found or not set correctly.")
- return()
-endif()
diff --git a/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir.cmake b/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir.cmake
index a277c6575..69ed85c62 100644
--- a/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir.cmake
+++ b/Tests/RunCMake/VS10Project/VsDebuggerWorkingDir.cmake
@@ -1,5 +1,6 @@
enable_language(CXX)
add_library(foo foo.cpp)
+add_custom_target(bar)
-set_target_properties(foo PROPERTIES
- VS_DEBUGGER_WORKING_DIRECTORY "my-debugger-directory")
+set_target_properties(foo bar PROPERTIES
+ VS_DEBUGGER_WORKING_DIRECTORY "my-debugger-directory $<TARGET_PROPERTY:foo,NAME>")
diff --git a/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt b/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt
index ca8c33f36..a63591fff 100644
--- a/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt
+++ b/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt
@@ -1 +1 @@
-CMake Error: Target visibility_preset uses unsupported value \"hiden\" for CXX_VISIBILITY_PRESET
+CMake Error: Target visibility_preset uses unsupported value \"hiden\" for CXX_VISIBILITY_PRESET. The supported values are: default, hidden, protected, and internal.
diff --git a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt
index 044574404..f4449929f 100644
--- a/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt
+++ b/Tests/RunCMake/WriteCompilerDetectionHeader/InvalidFeature-stderr.txt
@@ -1,5 +1,6 @@
CMake Error at .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(message\):
Unsupported feature not_a_feature.
Call Stack \(most recent call first\):
+ .*Modules/WriteCompilerDetectionHeader.cmake:[0-9]+ \(_check_feature_lists\)
InvalidFeature.cmake:4 \(write_compiler_detection_header\)
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/XcodeProject/PerConfigPerSourceFlags-stderr.txt b/Tests/RunCMake/XcodeProject/PerConfigPerSourceFlags-stderr.txt
index 650064920..c3e9e318a 100644
--- a/Tests/RunCMake/XcodeProject/PerConfigPerSourceFlags-stderr.txt
+++ b/Tests/RunCMake/XcodeProject/PerConfigPerSourceFlags-stderr.txt
@@ -5,4 +5,6 @@
specified for source:
- .*/Tests/RunCMake/XcodeProject/main.c$
+ .*/Tests/RunCMake/XcodeProject/main.c
++
+CMake Generate step failed\. Build files cannot be regenerated correctly\.$
diff --git a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
index 5f4bdc30d..191f56dd7 100644
--- a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
+++ b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake
@@ -1,9 +1,12 @@
include(RunCMake)
+run_cmake(ExplicitCMakeLists)
+
run_cmake(XcodeFileType)
run_cmake(XcodeAttributeLocation)
run_cmake(XcodeAttributeGenex)
run_cmake(XcodeAttributeGenexError)
+run_cmake(XcodeGenerateTopLevelProjectOnly)
run_cmake(XcodeObjectNeedsEscape)
run_cmake(XcodeObjectNeedsQuote)
run_cmake(XcodeOptimizationFlags)
@@ -14,13 +17,52 @@ if (NOT XCODE_VERSION VERSION_LESS 6)
endif()
run_cmake(PerConfigPerSourceFlags)
+run_cmake(PerConfigPerSourceOptions)
+run_cmake(PerConfigPerSourceDefinitions)
+run_cmake(PerConfigPerSourceIncludeDirs)
+
+function(XcodeSchemaGeneration)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeSchemaGeneration-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_OPTIONS "-DCMAKE_XCODE_GENERATE_SCHEME=ON")
+
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+ run_cmake(XcodeSchemaGeneration)
+ run_cmake_command(XcodeSchemaGeneration-build xcodebuild -scheme foo build)
+endfunction()
+
+if(NOT XCODE_VERSION VERSION_LESS 7)
+ XcodeSchemaGeneration()
+ run_cmake(XcodeSchemaProperty)
+endif()
+
+function(XcodeDependOnZeroCheck)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeDependOnZeroCheck-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+ run_cmake(XcodeDependOnZeroCheck)
+ run_cmake_command(XcodeDependOnZeroCheck-build ${CMAKE_COMMAND} --build . --target parentdirlib)
+ run_cmake_command(XcodeDependOnZeroCheck-build ${CMAKE_COMMAND} --build . --target subdirlib)
+endfunction()
+
+XcodeDependOnZeroCheck()
+
+# Isolate device tests from host architecture selection.
+unset(ENV{CMAKE_OSX_ARCHITECTURES})
# Use a single build tree for a few tests without cleaning.
if(NOT XCODE_VERSION VERSION_LESS 5)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeInstallIOS-build)
set(RunCMake_TEST_NO_CLEAN 1)
- set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_BINARY_DIR}/ios_install")
+ set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_SYSTEM_NAME=iOS"
+ "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_BINARY_DIR}/ios_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
@@ -35,7 +77,7 @@ if(NOT XCODE_VERSION VERSION_LESS 5)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeBundlesOSX-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
- "-DTEST_IOS=OFF"
+ "-DCMAKE_SYSTEM_NAME=Darwin"
"-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@@ -52,7 +94,7 @@ if(NOT XCODE_VERSION VERSION_LESS 5)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeBundlesIOS-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
- "-DTEST_IOS=ON"
+ "-DCMAKE_SYSTEM_NAME=iOS"
"-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@@ -71,7 +113,7 @@ if(NOT XCODE_VERSION VERSION_LESS 7)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeBundlesWatchOS-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
- "-DTEST_WATCHOS=ON"
+ "-DCMAKE_SYSTEM_NAME=watchOS"
"-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@@ -90,7 +132,7 @@ if(NOT XCODE_VERSION VERSION_LESS 7.1)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeBundlesTvOS-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
- "-DTEST_TVOS=ON"
+ "-DCMAKE_SYSTEM_NAME=tvOS"
"-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
@@ -116,8 +158,9 @@ if(NOT XCODE_VERSION VERSION_LESS 6)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombined-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
- "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install"
- "-DCMAKE_IOS_INSTALL_COMBINED=YES")
+ "-DCMAKE_SYSTEM_NAME=iOS"
+ "-DCMAKE_IOS_INSTALL_COMBINED=YES"
+ "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
@@ -134,8 +177,9 @@ if(NOT XCODE_VERSION VERSION_LESS 6)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombinedPrune-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
- "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install"
- "-DCMAKE_IOS_INSTALL_COMBINED=YES")
+ "-DCMAKE_SYSTEM_NAME=iOS"
+ "-DCMAKE_IOS_INSTALL_COMBINED=YES"
+ "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
@@ -152,8 +196,9 @@ if(NOT XCODE_VERSION VERSION_LESS 6)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombinedSingleArch-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
- "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install"
- "-DCMAKE_IOS_INSTALL_COMBINED=YES")
+ "-DCMAKE_SYSTEM_NAME=iOS"
+ "-DCMAKE_IOS_INSTALL_COMBINED=YES"
+ "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
@@ -170,6 +215,7 @@ endif()
if(NOT XCODE_VERSION VERSION_LESS 5)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeMultiplatform-build)
set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_OPTIONS "${IOS_DEPLOYMENT_TARGET}")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
@@ -188,18 +234,41 @@ if(NOT XCODE_VERSION VERSION_LESS 5)
unset(RunCMake_TEST_OPTIONS)
endif()
-function(XcodeSchemaGeneration)
- set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeSchemaGeneration-build)
- set(RunCMake_TEST_NO_CLEAN 1)
- set(RunCMake_TEST_OPTIONS "-DCMAKE_XCODE_GENERATE_SCHEME=ON")
+if(XCODE_VERSION VERSION_GREATER_EQUAL 8)
+ function(deployment_target_test SystemName SDK)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/DeploymentTarget-${SDK}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_OPTIONS "-DCMAKE_SYSTEM_NAME=${SystemName}" "-DCMAKE_OSX_SYSROOT=${SDK}")
+
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+ run_cmake(DeploymentTarget)
+ run_cmake_command(DeploymentTarget-${SDK} ${CMAKE_COMMAND} --build .)
+ endfunction()
+
+ deployment_target_test(Darwin macosx)
+ deployment_target_test(iOS iphoneos)
+ deployment_target_test(iOS iphonesimulator)
+ deployment_target_test(tvOS appletvos)
+ deployment_target_test(tvOS appletvsimulator)
+ deployment_target_test(watchOS watchos)
+ deployment_target_test(watchOS watchsimulator)
+endif()
- file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
- file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+if(XCODE_VERSION VERSION_GREATER_EQUAL 8)
+ function(xctest_lookup_test SystemName SDK)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XCTestLookup-${SDK}-build)
+ set(RunCMake_TEST_OPTIONS "-DCMAKE_SYSTEM_NAME=${SystemName}" "-DCMAKE_OSX_SYSROOT=${SDK}")
- run_cmake(XcodeSchemaGeneration)
- run_cmake_command(XcodeSchemaGeneration-build xcodebuild -scheme foo build)
-endfunction()
+ run_cmake(XCTestLookup)
+ endfunction()
-if(NOT XCODE_VERSION VERSION_LESS 7)
- XcodeSchemaGeneration()
+ xctest_lookup_test(Darwin macosx)
+ xctest_lookup_test(iOS iphoneos)
+ xctest_lookup_test(iOS iphonesimulator)
+ xctest_lookup_test(tvOS appletvos)
+ xctest_lookup_test(tvOS appletvsimulator)
endif()
+
+# Please add macOS-only tests above before the device-specific tests.
diff --git a/Tests/RunCMake/XcodeProject/XcodeBundles.cmake b/Tests/RunCMake/XcodeProject/XcodeBundles.cmake
index 0b854d80a..ef772ea65 100644
--- a/Tests/RunCMake/XcodeProject/XcodeBundles.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeBundles.cmake
@@ -3,24 +3,12 @@
cmake_minimum_required(VERSION 3.3)
enable_language(C)
-if(TEST_IOS)
- set(CMAKE_OSX_SYSROOT iphoneos)
- set(CMAKE_OSX_ARCHITECTURES "armv7")
+if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
-endif(TEST_IOS)
-
-if(TEST_WATCHOS)
- set(CMAKE_OSX_SYSROOT watchos)
- set(CMAKE_OSX_ARCHITECTURES "armv7k")
- set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
- set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
- set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
endif()
-if(TEST_TVOS)
- set(CMAKE_OSX_SYSROOT appletvos)
- set(CMAKE_OSX_ARCHITECTURES "arm64")
+if(CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAKE_SYSTEM_NAME STREQUAL "watchOS")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
@@ -38,7 +26,7 @@ add_dependencies(AppBundleTest AppBundle)
# with custom extension
-if (NOT TEST_IOS AND NOT TEST_WATCHOS AND NOT TEST_TVOS)
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_executable(AppBundleExt MACOSX_BUNDLE main.m)
set_target_properties(AppBundleExt PROPERTIES BUNDLE_EXTENSION "foo")
install(TARGETS AppBundleExt BUNDLE DESTINATION FooExtension)
@@ -52,7 +40,7 @@ endif()
# Shared Framework (not supported for iOS on Xcode < 6)
-if(NOT TEST_IOS OR NOT XCODE_VERSION VERSION_LESS 6)
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "iOS" OR NOT XCODE_VERSION VERSION_LESS 6)
add_library(SharedFramework SHARED main.c)
set_target_properties(SharedFramework PROPERTIES FRAMEWORK TRUE)
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake
index fc830b19e..f6c00b165 100644
--- a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake
@@ -2,7 +2,14 @@ cmake_minimum_required(VERSION 3.3)
project(IOSInstallCombined CXX)
-set(CMAKE_OSX_SYSROOT iphoneos)
+if(XCODE_VERSION VERSION_GREATER_EQUAL 9)
+ set(CMAKE_OSX_DEPLOYMENT_TARGET 10)
+endif()
+
+if(NOT IOS)
+ message(FATAL_ERROR "IOS variable is not set")
+endif()
+
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake
index b47d3a597..ec11dbbd4 100644
--- a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake
@@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.3)
project(XcodeIOSInstallCombinedPrune CXX)
-set(CMAKE_OSX_SYSROOT iphoneos)
+if(XCODE_VERSION VERSION_GREATER_EQUAL 9)
+ set(CMAKE_OSX_DEPLOYMENT_TARGET 10)
+endif()
+
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")
diff --git a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedSingleArch.cmake b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedSingleArch.cmake
index 4b5e7ce36..58e96b4f3 100644
--- a/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedSingleArch.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedSingleArch.cmake
@@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.3)
project(XcodeIOSInstallCombinedSingleArch CXX)
-set(CMAKE_OSX_SYSROOT iphoneos)
+if(XCODE_VERSION VERSION_GREATER_EQUAL 9)
+ set(CMAKE_OSX_DEPLOYMENT_TARGET 10)
+endif()
+
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")
diff --git a/Tests/RunCMake/XcodeProject/XcodeInstallIOS.cmake b/Tests/RunCMake/XcodeProject/XcodeInstallIOS.cmake
index a79741069..ab31387cd 100644
--- a/Tests/RunCMake/XcodeProject/XcodeInstallIOS.cmake
+++ b/Tests/RunCMake/XcodeProject/XcodeInstallIOS.cmake
@@ -2,11 +2,8 @@ cmake_minimum_required(VERSION 2.8.5)
project(XcodeInstallIOS)
-set(CMAKE_OSX_SYSROOT iphoneos)
set(XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
-set(CMAKE_OSX_ARCHITECTURES "armv7;i386")
-
add_library(foo STATIC foo.cpp)
install(TARGETS foo ARCHIVE DESTINATION lib)
diff --git a/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake b/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
index 397c63d0a..0387dbb60 100644
--- a/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
+++ b/Tests/RunCMake/add_custom_command/RunCMakeTest.cmake
@@ -10,3 +10,14 @@ run_cmake(SourceByproducts)
run_cmake(SourceUsesTerminal)
run_cmake(TargetImported)
run_cmake(TargetNotInDir)
+
+if(${RunCMake_GENERATOR} MATCHES "Visual Studio ([^89]|[89][0-9])")
+ run_cmake(RemoveEmptyCommands)
+endif()
+
+run_cmake(AssigningMultipleTargets)
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AssigningMultipleTargets-build)
+set(RunCMake_TEST_NO_CLEAN 1)
+run_cmake_command(AssigningMultipleTargets-build ${CMAKE_COMMAND} --build .)
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_NO_CLEAN)
diff --git a/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake b/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake
index 6c4e91bca..2caed0328 100644
--- a/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake
+++ b/Tests/RunCMake/add_custom_target/RunCMakeTest.cmake
@@ -1,5 +1,6 @@
include(RunCMake)
+run_cmake(CommandExpandsEmpty)
run_cmake(NoArguments)
run_cmake(BadTargetName)
run_cmake(ByproductsNoCommand)
diff --git a/Tests/RunCMake/add_subdirectory/CMakeLists.txt b/Tests/RunCMake/add_subdirectory/CMakeLists.txt
index 18dfd2686..47d249cce 100644
--- a/Tests/RunCMake/add_subdirectory/CMakeLists.txt
+++ b/Tests/RunCMake/add_subdirectory/CMakeLists.txt
@@ -1,3 +1,10 @@
cmake_minimum_required(VERSION 3.2)
+
+# Have to set policy here due to policy scope
+if(DEFINED CMP0082_VALUE)
+ cmake_policy(SET CMP0082 "${CMP0082_VALUE}")
+endif()
+set(CMAKE_POLICY_WARNING_CMP0082 ON)
+
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/add_subdirectory/DoesNotExist-stderr.txt b/Tests/RunCMake/add_subdirectory/DoesNotExist-stderr.txt
index 369a956e6..013058111 100644
--- a/Tests/RunCMake/add_subdirectory/DoesNotExist-stderr.txt
+++ b/Tests/RunCMake/add_subdirectory/DoesNotExist-stderr.txt
@@ -2,4 +2,4 @@
add_subdirectory given source "DoesNotExist" which is not an existing
directory.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake
index f68600511..ff676a6ba 100644
--- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake
+++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake
@@ -4,3 +4,11 @@ add_subdirectory(ExcludeFromAll EXCLUDE_FROM_ALL)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE foo)
+
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
+set(main_exe \"$<TARGET_FILE:main>\")
+set(foo_lib \"$<TARGET_FILE:foo>\")
+set(bar_lib \"$<TARGET_FILE:bar>\")
+set(zot_lib \"$<TARGET_FILE:zot>\")
+set(subinc_lib \"$<TARGET_FILE:subinc>\")
+")
diff --git a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt
index b1df6b04f..790da542f 100644
--- a/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt
+++ b/Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt
@@ -1,4 +1,11 @@
-add_library(bar STATIC bar.cpp)
+project(ExcludeFromAllSub NONE)
+
+add_library(bar STATIC EXCLUDE_FROM_ALL bar.cpp)
+
+add_library(zot STATIC zot.cpp)
add_library(foo STATIC foo.cpp)
target_include_directories(foo PUBLIC .)
+
+add_library(subinc STATIC subinc.cpp)
+set_target_properties(subinc PROPERTIES EXCLUDE_FROM_ALL OFF)
diff --git a/Tests/RunCMake/add_subdirectory/Missing-stderr.txt b/Tests/RunCMake/add_subdirectory/Missing-stderr.txt
index aba06755a..dd831406e 100644
--- a/Tests/RunCMake/add_subdirectory/Missing-stderr.txt
+++ b/Tests/RunCMake/add_subdirectory/Missing-stderr.txt
@@ -5,4 +5,4 @@
does not contain a CMakeLists.txt file.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake
index 88b928308..951e03c8f 100644
--- a/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake
+++ b/Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake
@@ -4,14 +4,57 @@ run_cmake(DoesNotExist)
run_cmake(Missing)
run_cmake(Function)
-set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExcludeFromAll-build)
-set(RunCMake_TEST_NO_CLEAN 1)
+macro(run_cmake_install case)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_TEST_OPTIONS ${ARGN})
-file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
-file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake(${case})
+ run_cmake_command(${case}-install ${CMAKE_COMMAND} -P cmake_install.cmake)
+ run_cmake_command(${case}-install-component ${CMAKE_COMMAND} -DCOMPONENT=Unspecified -P cmake_install.cmake)
-run_cmake(ExcludeFromAll)
-run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .)
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+ unset(RunCMake_TEST_OPTIONS)
+endmacro()
-unset(RunCMake_TEST_BINARY_DIR)
+run_cmake_install(CMP0082-WARN)
+run_cmake_install(CMP0082-WARN-Nested)
+run_cmake_install(CMP0082-WARN-NestedSub)
+run_cmake_install(CMP0082-WARN-None)
+run_cmake_install(CMP0082-WARN-NoTopInstall)
+run_cmake_install(CMP0082-OLD -DCMP0082_VALUE=OLD)
+run_cmake_install(CMP0082-NEW -DCMP0082_VALUE=NEW)
+
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExcludeFromAll-build)
+if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+endif()
+run_cmake(ExcludeFromAll)
+set(RunCMake_TEST_NO_CLEAN 1)
+set(RunCMake-check-file ExcludeFromAll/check.cmake)
+run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build . --config Debug)
+if(RunCMake_GENERATOR STREQUAL "Ninja")
+ if(WIN32)
+ set(slash [[\]])
+ else()
+ set(slash [[/]])
+ endif()
+ set(RunCMake-check-file ExcludeFromAll/check-sub.cmake)
+ run_cmake_command(ExcludeFromAll-build-sub ${CMAKE_COMMAND} --build . --target "ExcludeFromAll${slash}all")
+elseif(RunCMake_GENERATOR MATCHES "Make")
+ set(RunCMake-check-file ExcludeFromAll/check-sub.cmake)
+ set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY ${RunCMake_BINARY_DIR}/ExcludeFromAll-build/ExcludeFromAll)
+ run_cmake_command(ExcludeFromAll-build-sub "${RunCMake_MAKE_PROGRAM}")
+elseif(RunCMake_GENERATOR MATCHES "^Visual Studio [1-9][0-9]")
+ set(RunCMake-check-file ExcludeFromAll/check-sub.cmake)
+ run_cmake_command(ExcludeFromAll-build-sub ${CMAKE_COMMAND} --build ExcludeFromAll --config Debug)
+elseif(RunCMake_GENERATOR STREQUAL "Xcode")
+ set(RunCMake-check-file ExcludeFromAll/check-sub.cmake)
+ set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY ${RunCMake_BINARY_DIR}/ExcludeFromAll-build/ExcludeFromAll)
+ run_cmake_command(ExcludeFromAll-build-sub xcodebuild -configuration Debug)
+endif()
+unset(RunCMake-check-file)
unset(RunCMake_TEST_NO_CLEAN)
+unset(RunCMake_TEST_OPTIONS)
+unset(RunCMake_TEST_BINARY_DIR)
diff --git a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
index 9a5eaaf1c..dded248ed 100644
--- a/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/alias_targets/RunCMakeTest.cmake
@@ -6,6 +6,7 @@ run_cmake(exclude-from-all)
run_cmake(imported)
run_cmake(invalid-name)
run_cmake(invalid-target)
+run_cmake(imported-global-target)
run_cmake(imported-target)
run_cmake(alias-target)
run_cmake(set_property)
diff --git a/Tests/RunCMake/alias_targets/imported-target-stderr.txt b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
index bbff29a80..465de0362 100644
--- a/Tests/RunCMake/alias_targets/imported-target-stderr.txt
+++ b/Tests/RunCMake/alias_targets/imported-target-stderr.txt
@@ -1,5 +1,15 @@
-CMake Error at imported-target.cmake:6 \(add_library\):
- add_library cannot create ALIAS target "alias" because target "foo" is
- IMPORTED.
+^CMake Error at imported-target.cmake:[0-9]+ \(add_executable\):
+ add_executable cannot create ALIAS target \"alias-test-exe\" because target
+ \"test-exe\" is imported but not globally visible.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists.txt:[0-9]+ \(include\)
++
+'alias-test-exe' does not exist![?]
+*
+CMake Error at imported-target.cmake:[0-9]+ \(add_library\):
+ add_library cannot create ALIAS target "alias-test-lib" because target
+ "test-lib" is imported but not globally visible.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
++
+'alias-test-lib' does not exist![?]$
diff --git a/Tests/RunCMake/alias_targets/imported-target.cmake b/Tests/RunCMake/alias_targets/imported-target.cmake
index 7259ab091..bb682fecd 100644
--- a/Tests/RunCMake/alias_targets/imported-target.cmake
+++ b/Tests/RunCMake/alias_targets/imported-target.cmake
@@ -1,6 +1,46 @@
enable_language(CXX)
-add_library(foo SHARED IMPORTED)
-add_library(alias ALIAS foo)
+add_executable(test-exe IMPORTED)
+add_executable(alias-test-exe ALIAS test-exe)
+
+if(TARGET alias-test-exe)
+ get_target_property(aliased-target alias-test-exe ALIASED_TARGET)
+ if("${aliased-target}" STREQUAL "test-exe")
+ get_target_property(aliased-name alias-test-exe NAME)
+ if("${aliased-name}" STREQUAL "test-exe")
+ message("'alias-test-exe' is an alias for '${aliased-target}'"
+ " and its name-property contains '${aliased-name}'.")
+ else()
+ message("'alias-test-exe' is an alias for '${aliased-target}'"
+ " but its name-property contains '${aliased-name}'!?")
+ endif()
+ else()
+ message("'alias-test-exe' is something but not a real target!?")
+ endif()
+else()
+ message("'alias-test-exe' does not exist!?")
+endif()
+
+
+add_library(test-lib SHARED IMPORTED)
+add_library(alias-test-lib ALIAS test-lib)
+
+if(TARGET alias-test-lib)
+ get_target_property(aliased-target alias-test-lib ALIASED_TARGET)
+ if("${aliased-target}" STREQUAL "test-lib")
+ get_target_property(aliased-name alias-test-lib NAME)
+ if("${aliased-name}" STREQUAL "test-lib")
+ message("'alias-test-lib' is an alias for '${aliased-target}'"
+ " and its name-property contains '${aliased-name}'.")
+ else()
+ message("'alias-test-lib' is an alias for '${aliased-target}'"
+ " but its name-property contains '${aliased-name}'!?")
+ endif()
+ else()
+ message("'alias-test-lib' is something but not a real target!?")
+ endif()
+else()
+ message("'alias-test-lib' does not exist!?")
+endif()
diff --git a/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt b/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt
index 28e0e7235..1938da37f 100644
--- a/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt
+++ b/Tests/RunCMake/build_command/CMP0061-OLD-make-stderr.txt
@@ -1,4 +1,15 @@
-^[^
+^CMake Deprecation Warning at CMP0061-OLD-make.cmake:[0-9]+ \(cmake_policy\):
+ The OLD behavior for policy CMP0061 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
++
+[^
]+ --build \. --config "Release" -- -i
[^
]+ --build \. --config "Release" --target "MyTarget" -- -i
diff --git a/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt b/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt
index 1dde84379..85bbdf175 100644
--- a/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt
+++ b/Tests/RunCMake/build_command/CMP0061-OLD-other-stderr.txt
@@ -1,4 +1,15 @@
-^[^
+^CMake Deprecation Warning at CMP0061-OLD-other.cmake:[0-9]+ \(cmake_policy\):
+ The OLD behavior for policy CMP0061 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)
++
+[^
]+ --build \. --config "Release"
[^
]+ --build \. --config "Release" --target "MyTarget"
diff --git a/Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake b/Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake
index e4c65e3b6..1030211e7 100644
--- a/Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake
+++ b/Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake
@@ -2,4 +2,8 @@ include(RunCMake)
run_cmake(Before24)
run_cmake(CompatBefore24)
+run_cmake(Future)
run_cmake(PolicyBefore24)
+run_cmake(Range)
+run_cmake(RangeBad)
+run_cmake(Unknown)
diff --git a/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake b/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake
index 1e15b3b2c..505840d7a 100644
--- a/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake
+++ b/Tests/RunCMake/cmake_parse_arguments/RunCMakeTest.cmake
@@ -11,3 +11,4 @@ run_cmake(BadArgvN2)
run_cmake(BadArgvN3)
run_cmake(BadArgvN4)
run_cmake(CornerCasesArgvN)
+run_cmake(KeyWordsMissingValues)
diff --git a/Tests/RunCMake/configure_file/DirInput-stderr.txt b/Tests/RunCMake/configure_file/DirInput-stderr.txt
index 2e0cd144c..165ad80eb 100644
--- a/Tests/RunCMake/configure_file/DirInput-stderr.txt
+++ b/Tests/RunCMake/configure_file/DirInput-stderr.txt
@@ -1,7 +1,7 @@
CMake Error at DirInput.cmake:[0-9]+ \(configure_file\):
configure_file input location
- .*/Tests/RunCMake/configure_file/.
+ .*/Tests/RunCMake/configure_file
is a directory but a file was expected.
Call Stack \(most recent call first\):
diff --git a/Tests/RunCMake/ctest_build/BuildQuiet-stdout.txt b/Tests/RunCMake/ctest_build/BuildQuiet-stdout.txt
index 2e59d99ec..cc9085fee 100644
--- a/Tests/RunCMake/ctest_build/BuildQuiet-stdout.txt
+++ b/Tests/RunCMake/ctest_build/BuildQuiet-stdout.txt
@@ -1,7 +1,6 @@
Run dashboard with model Experimental
Source directory: .*/Tests/RunCMake/ctest_build/BuildQuiet
Build directory: .*/Tests/RunCMake/ctest_build/BuildQuiet-build
- Reading ctest configuration file: .*/Tests/RunCMake/ctest_build/BuildQuiet/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use Experimental tag: [0-9-]+
diff --git a/Tests/RunCMake/ctest_configure/ConfigureQuiet-stdout.txt b/Tests/RunCMake/ctest_configure/ConfigureQuiet-stdout.txt
index 015644d81..98f5a4cd4 100644
--- a/Tests/RunCMake/ctest_configure/ConfigureQuiet-stdout.txt
+++ b/Tests/RunCMake/ctest_configure/ConfigureQuiet-stdout.txt
@@ -1,7 +1,6 @@
Run dashboard with model Experimental
Source directory: .*/Tests/RunCMake/ctest_configure/ConfigureQuiet
Build directory: .*/Tests/RunCMake/ctest_configure/ConfigureQuiet-build
- Reading ctest configuration file: .*/Tests/RunCMake/ctest_configure/ConfigureQuiet/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use Experimental tag: [0-9-]+
diff --git a/Tests/RunCMake/ctest_fixtures/CMakeLists.txt.in b/Tests/RunCMake/ctest_fixtures/CMakeLists.txt.in
index 5cb0b4ef6..6b11cffac 100644
--- a/Tests/RunCMake/ctest_fixtures/CMakeLists.txt.in
+++ b/Tests/RunCMake/ctest_fixtures/CMakeLists.txt.in
@@ -27,7 +27,11 @@ passTest(two) # 6
passTest(cleanupBar) # 7
passTest(three) # 8
failTest(setupFails) # 9
-passTest(wontRun) # 10
+
+# Special case, test executable always missing to verify fixture dependencies
+# are checked before existence of test executable to be run
+add_test(NAME wontRun COMMAND iDoNotExist) # 10
+
passTest(cyclicSetup) # 11
passTest(cyclicCleanup) # 12
passTest(cleanupUnused) # 13
diff --git a/Tests/RunCMake/ctest_memcheck/CTestConfig.cmake.in b/Tests/RunCMake/ctest_memcheck/CTestConfig.cmake.in
index 6d4a718d0..53bdd20c8 100644
--- a/Tests/RunCMake/ctest_memcheck/CTestConfig.cmake.in
+++ b/Tests/RunCMake/ctest_memcheck/CTestConfig.cmake.in
@@ -1,9 +1,6 @@
-set (CTEST_PROJECT_NAME "CTestTestMemcheck@CASE_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/RunCMake/ctest_skipped_test/skip.bat b/Tests/RunCMake/ctest_skipped_test/skip.bat
index 80e1290df..580f46018 100755
--- a/Tests/RunCMake/ctest_skipped_test/skip.bat
+++ b/Tests/RunCMake/ctest_skipped_test/skip.bat
@@ -1 +1 @@
-EXIT 125
+EXIT 125
diff --git a/Tests/RunCMake/ctest_start/ConfigInBuild-stdout.txt b/Tests/RunCMake/ctest_start/ConfigInBuild-stdout.txt
index 7e94b8a12..f4a0ba37a 100644
--- a/Tests/RunCMake/ctest_start/ConfigInBuild-stdout.txt
+++ b/Tests/RunCMake/ctest_start/ConfigInBuild-stdout.txt
@@ -1,7 +1,6 @@
Run dashboard with model Experimental
Source directory: .*/Tests/RunCMake/ctest_start/ConfigInBuild
Build directory: .*/Tests/RunCMake/ctest_start/ConfigInBuild-build
- Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/ConfigInBuild-build/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use Experimental tag: [0-9-]+
diff --git a/Tests/RunCMake/ctest_start/ConfigInSource-stdout.txt b/Tests/RunCMake/ctest_start/ConfigInSource-stdout.txt
index c3903726a..5f98b4e31 100644
--- a/Tests/RunCMake/ctest_start/ConfigInSource-stdout.txt
+++ b/Tests/RunCMake/ctest_start/ConfigInSource-stdout.txt
@@ -1,7 +1,6 @@
Run dashboard with model Experimental
Source directory: .*/Tests/RunCMake/ctest_start/ConfigInSource
Build directory: .*/Tests/RunCMake/ctest_start/ConfigInSource-build
- Reading ctest configuration file: .*/Tests/RunCMake/ctest_start/ConfigInSource/CTestConfig.cmake
Site: test-site
Build name: test-build-name
Use Experimental tag: [0-9-]+
diff --git a/Tests/RunCMake/ctest_start/RunCMakeTest.cmake b/Tests/RunCMake/ctest_start/RunCMakeTest.cmake
index d630a7904..905ad0003 100644
--- a/Tests/RunCMake/ctest_start/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ctest_start/RunCMakeTest.cmake
@@ -7,17 +7,47 @@ function(run_ctest_start CASE_NAME)
run_ctest(${CASE_NAME})
endfunction()
-run_ctest_start(StartQuiet Experimental QUIET)
+function(check_tag_contents EXPECTED)
+ set(_tag_file "${RunCMake_BINARY_DIR}/${CASE_NAME}-build/Testing/TAG")
+ if(EXISTS "${_tag_file}")
+ file(READ "${_tag_file}" _tag_contents)
+ if(NOT _tag_contents MATCHES "${EXPECTED}")
+ set(RunCMake_TEST_FAILED "Testing/TAG file does not match expected value.\nActual TAG file:\n${_tag_contents}\nExpected TAG file:\n${EXPECTED}\n" PARENT_SCOPE)
+ endif()
+ else()
+ set(RunCMake_TEST_FAILED "Testing/TAG file does not exist." PARENT_SCOPE)
+ endif()
+endfunction()
+run_ctest_start(StartQuiet Experimental QUIET)
run_ctest_start(ConfigInSource Experimental)
+run_ctest_start(FunctionScope Experimental QUIET)
+run_ctest_start(WriteModelToTagExperimental Experimental QUIET)
+run_ctest_start(WriteModelToTagContinuous Continuous QUIET)
+run_ctest_start(WriteModelToTagNightly Nightly QUIET)
+run_ctest_start(WriteModelToTagNoMatchingTrack Continuous TRACK SomeWeirdTrackName QUIET)
+run_ctest_start(AppendSameModel Continuous APPEND)
+run_ctest_start(AppendDifferentModel Experimental APPEND)
+run_ctest_start(AppendNoModel APPEND)
+run_ctest_start(AppendDifferentTrack TRACK ExperimentalDifferent APPEND)
+run_ctest_start(NoAppendDifferentTrack Experimental TRACK ExperimentalDifferent)
+run_ctest_start(AppendNoMatchingTrack Continuous APPEND)
+run_ctest_start(AppendOldContinuous Continuous APPEND)
+run_ctest_start(AppendOldNoModel APPEND)
+run_ctest_start(NoModel QUIET)
+run_ctest_start(MissingTrackArg Experimental TRACK)
+run_ctest_start(MissingTrackArgAppend Experimental TRACK APPEND)
+run_ctest_start(MissingTrackArgQuiet Experimental TRACK QUIET)
+run_ctest_start(TooManyArgs Experimental
+ ${RunCMake_BINARY_DIR}/TooManyArgs-build
+ ${RunCMake_BINARY_DIR}/TooManyArgs-build
+ ${RunCMake_BINARY_DIR}/TooManyArgs-build)
function(run_ConfigInBuild)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ConfigInBuild-build)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
- configure_file(${RunCMake_SOURCE_DIR}/CTestConfig.cmake.in
- ${RunCMake_BINARY_DIR}/ConfigInBuild-build/CTestConfig.cmake @ONLY)
run_ctest_start(ConfigInBuild Experimental)
endfunction()
run_ConfigInBuild()
diff --git a/Tests/RunCMake/ctest_start/test.cmake.in b/Tests/RunCMake/ctest_start/test.cmake.in
index 21e3fad2d..8cd3cff5a 100644
--- a/Tests/RunCMake/ctest_start/test.cmake.in
+++ b/Tests/RunCMake/ctest_start/test.cmake.in
@@ -8,6 +8,26 @@ set(CTEST_CMAKE_GENERATOR "@RunCMake_GENERATOR@")
set(CTEST_CMAKE_GENERATOR_PLATFORM "@RunCMake_GENERATOR_PLATFORM@")
set(CTEST_CMAKE_GENERATOR_TOOLSET "@RunCMake_GENERATOR_TOOLSET@")
set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
+
+function(setup_tests)
+ ctest_start(${ctest_start_args})
+endfunction()
+
+if("@CASE_NAME@" MATCHES "^(No)?Append")
+ if("@CASE_NAME@" MATCHES "^AppendNoMatchingTrack$")
+ file(WRITE "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "19551112-2204\nSomeWeirdTrackName\n")
+ else()
+ file(WRITE "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "19551112-2204\nContinuousTrack\n")
+ endif()
+ if(NOT "@CASE_NAME@" MATCHES "^AppendOld")
+ file(APPEND "${CTEST_BINARY_DIRECTORY}/Testing/TAG" "Continuous\n")
+ endif()
+endif()
set(ctest_start_args "@CASE_CTEST_START_ARGS@")
-ctest_start(${ctest_start_args})
+if("@CASE_NAME@" STREQUAL "FunctionScope")
+ setup_tests()
+else()
+ ctest_start(${ctest_start_args})
+endif()
diff --git a/Tests/RunCMake/ctest_submit/CDashSubmitHeaders-stderr.txt b/Tests/RunCMake/ctest_submit/CDashSubmitHeaders-stderr.txt
index 4825d7a8e..a8f10b558 100644
--- a/Tests/RunCMake/ctest_submit/CDashSubmitHeaders-stderr.txt
+++ b/Tests/RunCMake/ctest_submit/CDashSubmitHeaders-stderr.txt
@@ -1,3 +1 @@
- *Error when uploading file: .*/Configure.xml
*Error message was: ([Cc]ould *n.t resolve host:? '?-no-site-'?.*|The requested URL returned error:.*)
- *Problems when submitting via HTTP
diff --git a/Tests/RunCMake/ctest_submit/CTestConfig.cmake.in b/Tests/RunCMake/ctest_submit/CTestConfig.cmake.in
index 378a85a0c..140e4be35 100644
--- a/Tests/RunCMake/ctest_submit/CTestConfig.cmake.in
+++ b/Tests/RunCMake/ctest_submit/CTestConfig.cmake.in
@@ -1,4 +1,3 @@
-set(CTEST_PROJECT_NAME "CTestSubmit@CASE_NAME@")
# Intentionally leave out other upload-related CTestConfig.cmake settings
# so that any ctest_submit calls fail with an error message.
diff --git a/Tests/RunCMake/ctest_submit/FailDrop-http-stdout.txt b/Tests/RunCMake/ctest_submit/FailDrop-http-stdout.txt
index c7f35c5ff..c9111b0cf 100644
--- a/Tests/RunCMake/ctest_submit/FailDrop-http-stdout.txt
+++ b/Tests/RunCMake/ctest_submit/FailDrop-http-stdout.txt
@@ -1,3 +1,2 @@
-Submit files \(using http\)
- Using HTTP submit method
- Drop site:http://
+Submit files
+ SubmitURL: http://-no-site-
diff --git a/Tests/RunCMake/ctest_submit/FailDrop-https-stdout.txt b/Tests/RunCMake/ctest_submit/FailDrop-https-stdout.txt
index 19f82347b..2c67eb9db 100644
--- a/Tests/RunCMake/ctest_submit/FailDrop-https-stdout.txt
+++ b/Tests/RunCMake/ctest_submit/FailDrop-https-stdout.txt
@@ -1,3 +1,2 @@
-Submit files \(using https\)
- Using HTTP submit method
- Drop site:https://
+Submit files
+ SubmitURL: https://-no-site-
diff --git a/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake b/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake
index b5d90d28c..78856b410 100644
--- a/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ctest_submit/RunCMakeTest.cmake
@@ -5,28 +5,36 @@ set(CASE_DROP_METHOD "http")
set(CASE_DROP_SITE "-no-site-")
set(CASE_CTEST_SUBMIT_ARGS "")
-#-----------------------------------------------------------------------------
-# Test bad argument combinations.
function(run_ctest_submit CASE_NAME)
set(CASE_CTEST_SUBMIT_ARGS "${ARGN}")
run_ctest(${CASE_NAME})
endfunction()
+function(run_ctest_submit_debug CASE_NAME)
+ set(CASE_CTEST_SUBMIT_ARGS "${ARGN}")
+ run_ctest(${CASE_NAME} "--debug")
+endfunction()
+
+#-----------------------------------------------------------------------------
+# Test bad argument combinations.
run_ctest_submit(BadArg bad-arg)
run_ctest_submit(BadPARTS PARTS bad-part)
run_ctest_submit(BadFILES FILES bad-file)
run_ctest_submit(RepeatRETURN_VALUE RETURN_VALUE res RETURN_VALUE res)
run_ctest_submit(PARTSCDashUpload PARTS Configure CDASH_UPLOAD)
run_ctest_submit(PARTSCDashUploadType PARTS Configure CDASH_UPLOAD_TYPE)
+run_ctest_submit(PARTSDone PARTS Done)
run_ctest_submit(CDashUploadPARTS CDASH_UPLOAD bad-upload PARTS)
run_ctest_submit(CDashUploadFILES CDASH_UPLOAD bad-upload FILES)
run_ctest_submit(CDashUploadNone CDASH_UPLOAD)
run_ctest_submit(CDashUploadMissingFile CDASH_UPLOAD bad-upload)
run_ctest_submit(CDashUploadRetry CDASH_UPLOAD ${CMAKE_CURRENT_LIST_FILE} CDASH_UPLOAD_TYPE foo RETRY_COUNT 2 RETRY_DELAY 1 INTERNAL_TEST_CHECKSUM)
run_ctest_submit(CDashSubmitQuiet QUIET)
-run_ctest_submit(CDashSubmitHeaders HTTPHEADER "Authorization: Bearer asdf")
-run_ctest_submit(CDashUploadHeaders CDASH_UPLOAD ${CMAKE_CURRENT_LIST_FILE} CDASH_UPLOAD_TYPE foo HTTPHEADER "Authorization: Bearer asdf")
+run_ctest_submit_debug(CDashSubmitVerbose BUILD_ID my_build_id)
+run_ctest_submit_debug(FILESNoBuildId FILES ${CMAKE_CURRENT_LIST_FILE})
+run_ctest_submit_debug(CDashSubmitHeaders HTTPHEADER "Authorization: Bearer asdf")
+run_ctest_submit_debug(CDashUploadHeaders CDASH_UPLOAD ${CMAKE_CURRENT_LIST_FILE} CDASH_UPLOAD_TYPE foo HTTPHEADER "Authorization: Bearer asdf")
function(run_ctest_CDashUploadFTP)
set(CASE_DROP_METHOD ftp)
@@ -41,9 +49,5 @@ function(run_ctest_submit_FailDrop CASE_DROP_METHOD)
run_ctest(FailDrop-${CASE_DROP_METHOD})
endfunction()
-run_ctest_submit_FailDrop(cp)
-run_ctest_submit_FailDrop(ftp)
run_ctest_submit_FailDrop(http)
run_ctest_submit_FailDrop(https)
-run_ctest_submit_FailDrop(scp)
-run_ctest_submit_FailDrop(xmlrpc)
diff --git a/Tests/RunCMake/ctest_submit/test.cmake.in b/Tests/RunCMake/ctest_submit/test.cmake.in
index ba826f1b3..35cd16a98 100644
--- a/Tests/RunCMake/ctest_submit/test.cmake.in
+++ b/Tests/RunCMake/ctest_submit/test.cmake.in
@@ -9,6 +9,7 @@ set(CTEST_CMAKE_GENERATOR_PLATFORM "@RunCMake_GENERATOR_PLATFORM@")
set(CTEST_CMAKE_GENERATOR_TOOLSET "@RunCMake_GENERATOR_TOOLSET@")
set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
+set_property(GLOBAL PROPERTY SubProject "mysubproj")
ctest_start(Experimental)
ctest_configure()
diff --git a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
index 1b3172676..6877e6a87 100644
--- a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
+++ b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake
@@ -21,8 +21,8 @@ set(ENV{__CTEST_FAKE_LOAD_AVERAGE_FOR_TESTING} 5)
run_ctest_test(TestLoadPass TEST_LOAD 6)
# Verify that new tests are not started when the load average exceeds
-# our threshold.
-run_ctest_test(TestLoadFail TEST_LOAD 2)
+# our threshold and that they then run once the load average drops.
+run_ctest_test(TestLoadWait TEST_LOAD 2)
# Verify that when an invalid "TEST_LOAD" value is given, a warning
# message is displayed and the value is ignored.
@@ -34,9 +34,9 @@ set(CASE_CTEST_TEST_LOAD 7)
run_ctest_test(CTestTestLoadPass)
# Verify that new tests are not started when the load average exceeds
-# our threshold.
+# our threshold and that they then run once the load average drops.
set(CASE_CTEST_TEST_LOAD 4)
-run_ctest_test(CTestTestLoadFail)
+run_ctest_test(CTestTestLoadWait)
# Verify that when an invalid "CTEST_TEST_LOAD" value is given,
# a warning message is displayed and the value is ignored.
diff --git a/Tests/RunCMake/execute_process/RunCMakeTest.cmake b/Tests/RunCMake/execute_process/RunCMakeTest.cmake
index 62e18c601..b203aabfd 100644
--- a/Tests/RunCMake/execute_process/RunCMakeTest.cmake
+++ b/Tests/RunCMake/execute_process/RunCMakeTest.cmake
@@ -10,4 +10,17 @@ run_cmake_command(MergeOutputVars ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/Mer
run_cmake(EncodingMissing)
if(TEST_ENCODING_EXE)
run_cmake_command(EncodingUTF8 ${CMAKE_COMMAND} -DTEST_ENCODING=UTF8 -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE} -P ${RunCMake_SOURCE_DIR}/Encoding.cmake)
+ run_cmake_command(EncodingUTF-8 ${CMAKE_COMMAND} -DTEST_ENCODING=UTF-8 -DTEST_ENCODING_EXE=${TEST_ENCODING_EXE} -P ${RunCMake_SOURCE_DIR}/Encoding.cmake)
endif()
+
+if(EXIT_CODE_EXE)
+ run_cmake_command(ExitValues ${CMAKE_COMMAND} -DEXIT_CODE_EXE=${EXIT_CODE_EXE} -P ${RunCMake_SOURCE_DIR}/ExitValues.cmake)
+endif()
+
+run_cmake_command(EchoCommand ${CMAKE_COMMAND} -DCHECK_GLOBAL=TRUE
+ -P ${RunCMake_SOURCE_DIR}/EchoCommand.cmake)
+run_cmake_command(EchoCommand2 ${CMAKE_COMMAND} -P
+ ${RunCMake_SOURCE_DIR}/EchoCommand.cmake)
+run_cmake_command(EchoCommand3 ${CMAKE_COMMAND}
+ -DCHECK_ERROR_OUTPUT_LOCATION=TRUE -P
+ ${RunCMake_SOURCE_DIR}/EchoCommand.cmake)
diff --git a/Tests/RunCMake/export/AppendExport-stderr.txt b/Tests/RunCMake/export/AppendExport-stderr.txt
index d71620e5f..d12124c9a 100644
--- a/Tests/RunCMake/export/AppendExport-stderr.txt
+++ b/Tests/RunCMake/export/AppendExport-stderr.txt
@@ -1,4 +1,4 @@
CMake Error at AppendExport.cmake:[0-9]+ \(export\):
- export EXPORT signature does not recognise the APPEND option.
+ export Unknown argument: "APPEND".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/export/OldIface-stderr.txt b/Tests/RunCMake/export/OldIface-stderr.txt
index 818c2cb20..3cc10331e 100644
--- a/Tests/RunCMake/export/OldIface-stderr.txt
+++ b/Tests/RunCMake/export/OldIface-stderr.txt
@@ -1,5 +1,4 @@
CMake Error at OldIface.cmake:[0-9]+ \(export\):
- export EXPORT signature does not recognise the
- EXPORT_LINK_INTERFACE_LIBRARIES option.
+ export Unknown argument: "EXPORT_LINK_INTERFACE_LIBRARIES".
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/export/RunCMakeTest.cmake b/Tests/RunCMake/export/RunCMakeTest.cmake
index 6d0b7ca7c..97a0ca6d8 100644
--- a/Tests/RunCMake/export/RunCMakeTest.cmake
+++ b/Tests/RunCMake/export/RunCMakeTest.cmake
@@ -1,7 +1,12 @@
include(RunCMake)
run_cmake(CustomTarget)
+run_cmake(Empty)
run_cmake(TargetNotFound)
run_cmake(AppendExport)
run_cmake(OldIface)
run_cmake(NoExportSet)
+run_cmake(ForbiddenToExportInterfaceProperties)
+run_cmake(ForbiddenToExportImportedProperties)
+run_cmake(ForbiddenToExportPropertyWithGenExp)
+run_cmake(ExportPropertiesUndefined)
diff --git a/Tests/RunCMake/file/FileOpenFailRead-stderr.txt b/Tests/RunCMake/file/FileOpenFailRead-stderr.txt
index 23d4337f4..9f8cee26a 100644
--- a/Tests/RunCMake/file/FileOpenFailRead-stderr.txt
+++ b/Tests/RunCMake/file/FileOpenFailRead-stderr.txt
@@ -3,4 +3,4 @@ CMake Error at FileOpenFailRead.cmake:[0-9]+ \(file\):
.*/Tests/RunCMake/file/does_not_exist/file.txt
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt b/Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt
index 557b817bb..bb7e4d2cc 100644
--- a/Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt
+++ b/Tests/RunCMake/file/INSTALL-MESSAGE-bad-stderr.txt
@@ -2,31 +2,31 @@ 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\)
+ CMakeLists\.txt:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/file/RunCMakeTest.cmake b/Tests/RunCMake/file/RunCMakeTest.cmake
index 26051b4d7..5db4b3bce 100644
--- a/Tests/RunCMake/file/RunCMakeTest.cmake
+++ b/Tests/RunCMake/file/RunCMakeTest.cmake
@@ -1,11 +1,20 @@
include(RunCMake)
+run_cmake(CREATE_LINK)
+run_cmake(CREATE_LINK-COPY_ON_ERROR)
+run_cmake(CREATE_LINK-noarg)
+run_cmake(CREATE_LINK-noexist)
run_cmake(DOWNLOAD-hash-mismatch)
run_cmake(DOWNLOAD-unused-argument)
run_cmake(DOWNLOAD-httpheader-not-set)
+run_cmake(DOWNLOAD-netrc-bad)
run_cmake(DOWNLOAD-pass-not-set)
+run_cmake(TOUCH)
+run_cmake(TOUCH-error-in-source-directory)
+run_cmake(TOUCH-error-missing-directory)
run_cmake(UPLOAD-unused-argument)
run_cmake(UPLOAD-httpheader-not-set)
+run_cmake(UPLOAD-netrc-bad)
run_cmake(UPLOAD-pass-not-set)
run_cmake(INSTALL-DIRECTORY)
run_cmake(INSTALL-FILES_FROM_DIR)
@@ -30,13 +39,97 @@ run_cmake(LOCK-lowercase)
run_cmake(READ_ELF)
run_cmake(GLOB)
run_cmake(GLOB_RECURSE)
-# test is valid both for GLOB and GLOB_RECURSE
+run_cmake(GLOB_RECURSE-noexp-FOLLOW_SYMLINKS)
+run_cmake(SIZE)
+run_cmake(SIZE-error-does-not-exist)
+
+run_cmake(REMOVE-empty)
+
+# tests are valid both for GLOB and GLOB_RECURSE
+run_cmake(GLOB-sort-dedup)
run_cmake(GLOB-error-LIST_DIRECTORIES-not-boolean)
-# test is valid both for GLOB and GLOB_RECURSE
run_cmake(GLOB-error-LIST_DIRECTORIES-no-arg)
+run_cmake(GLOB-error-RELATIVE-no-arg)
+run_cmake(GLOB-error-CONFIGURE_DEPENDS-modified)
+run_cmake(GLOB-noexp-CONFIGURE_DEPENDS)
+run_cmake(GLOB-noexp-FOLLOW_SYMLINKS)
run_cmake(GLOB-noexp-LIST_DIRECTORIES)
+run_cmake(GLOB-noexp-RELATIVE)
+run_cmake_command(GLOB-error-CONFIGURE_DEPENDS-SCRIPT_MODE ${CMAKE_COMMAND} -P
+ ${RunCMake_SOURCE_DIR}/GLOB-error-CONFIGURE_DEPENDS-SCRIPT_MODE.cmake)
if(NOT WIN32 OR CYGWIN)
+ run_cmake(CREATE_LINK-SYMBOLIC)
+ run_cmake(CREATE_LINK-SYMBOLIC-noexist)
run_cmake(GLOB_RECURSE-cyclic-recursion)
run_cmake(INSTALL-SYMLINK)
+ run_cmake(READ_SYMLINK)
+ run_cmake(READ_SYMLINK-noexist)
+ run_cmake(READ_SYMLINK-notsymlink)
+ run_cmake(INSTALL-FOLLOW_SYMLINK_CHAIN)
+endif()
+
+if(RunCMake_GENERATOR STREQUAL "Ninja")
+ # Detect ninja version so we know what tests can be supported.
+ execute_process(
+ COMMAND "${RunCMake_MAKE_PROGRAM}" --version
+ OUTPUT_VARIABLE ninja_out
+ ERROR_VARIABLE ninja_out
+ RESULT_VARIABLE ninja_res
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(ninja_res EQUAL 0 AND "x${ninja_out}" MATCHES "^x[0-9]+\\.[0-9]+")
+ set(ninja_version "${ninja_out}")
+ message(STATUS "ninja version: ${ninja_version}")
+ else()
+ message(FATAL_ERROR "'ninja --version' reported:\n${ninja_out}")
+ endif()
+
+ if("${ninja_version}" VERSION_LESS 1.8)
+ message(STATUS "Ninja is too old for GLOB CONFIGURE_DEPENDS; expect a warning.")
+ endif()
+endif()
+
+if(RunCMake_GENERATOR STREQUAL "Ninja" AND "${ninja_version}" VERSION_LESS 1.8)
+ run_cmake(GLOB_RECURSE-warn-CONFIGURE_DEPENDS-ninja-version)
+else()
+ run_cmake(GLOB-warn-CONFIGURE_DEPENDS-late)
+
+ # Use a single build tree for a few tests without cleaning.
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GLOB-CONFIGURE_DEPENDS-RerunCMake-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ set(RunCMake_DEFAULT_stderr ".*")
+ if(RunCMake_GENERATOR STREQUAL "Borland Makefiles" OR
+ RunCMake_GENERATOR STREQUAL "Watcom WMake")
+ set(fs_delay 3)
+ else()
+ set(fs_delay 1.125)
+ endif()
+
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/test")
+ set(tf_1 "${RunCMake_TEST_BINARY_DIR}/test/1.txt")
+ file(WRITE "${tf_1}" "1")
+
+ message(STATUS "GLOB-RerunCMake: first configuration...")
+ run_cmake(GLOB-CONFIGURE_DEPENDS-RerunCMake)
+ run_cmake_command(GLOB-CONFIGURE_DEPENDS-RerunCMake-build ${CMAKE_COMMAND} --build .)
+
+ execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay})
+ message(STATUS "GLOB-CONFIGURE_DEPENDS-RerunCMake: add another file...")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/test/sub")
+ set(tf_2 "${RunCMake_TEST_BINARY_DIR}/test/sub/2.txt")
+ file(WRITE "${tf_2}" "2")
+ run_cmake_command(GLOB-CONFIGURE_DEPENDS-RerunCMake-rebuild_first ${CMAKE_COMMAND} --build .)
+ run_cmake_command(GLOB-CONFIGURE_DEPENDS-RerunCMake-nowork ${CMAKE_COMMAND} --build .)
+
+ execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay})
+ message(STATUS "GLOB-CONFIGURE_DEPENDS-RerunCMake: remove first test file...")
+ file(REMOVE "${RunCMake_TEST_BINARY_DIR}/test/1.txt")
+ run_cmake_command(GLOB-CONFIGURE_DEPENDS-RerunCMake-rebuild_second ${CMAKE_COMMAND} --build .)
+ run_cmake_command(GLOB-CONFIGURE_DEPENDS-RerunCMake-nowork ${CMAKE_COMMAND} --build .)
+
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+ unset(RunCMake_DEFAULT_stderr)
endif()
diff --git a/Tests/RunCMake/find_package/PackageRoot.cmake b/Tests/RunCMake/find_package/PackageRoot.cmake
index 4c4f4c233..aa12e9b5f 100644
--- a/Tests/RunCMake/find_package/PackageRoot.cmake
+++ b/Tests/RunCMake/find_package/PackageRoot.cmake
@@ -1,5 +1,5 @@
-set(__UNDOCUMENTED_CMAKE_FIND_PACKAGE_ROOT 1)
cmake_policy(SET CMP0057 NEW)
+cmake_policy(SET CMP0074 NEW)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot)
set(PackageRoot_BASE ${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot)
diff --git a/Tests/RunCMake/find_package/PackageRootNestedConfig.cmake b/Tests/RunCMake/find_package/PackageRootNestedConfig.cmake
index ba06c09ce..1ef32cbba 100644
--- a/Tests/RunCMake/find_package/PackageRootNestedConfig.cmake
+++ b/Tests/RunCMake/find_package/PackageRootNestedConfig.cmake
@@ -1,5 +1,5 @@
-set(__UNDOCUMENTED_CMAKE_FIND_PACKAGE_ROOT 1)
cmake_policy(SET CMP0057 NEW)
+cmake_policy(SET CMP0074 NEW)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot)
set(PackageRoot_BASE ${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot)
diff --git a/Tests/RunCMake/find_package/PackageRootNestedModule.cmake b/Tests/RunCMake/find_package/PackageRootNestedModule.cmake
index 2795cd48f..017834cd3 100644
--- a/Tests/RunCMake/find_package/PackageRootNestedModule.cmake
+++ b/Tests/RunCMake/find_package/PackageRootNestedModule.cmake
@@ -1,5 +1,5 @@
-set(__UNDOCUMENTED_CMAKE_FIND_PACKAGE_ROOT 1)
cmake_policy(SET CMP0057 NEW)
+cmake_policy(SET CMP0074 NEW)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot)
set(PackageRoot_BASE ${CMAKE_CURRENT_SOURCE_DIR}/PackageRoot)
diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake
index d548da027..066523ec6 100644
--- a/Tests/RunCMake/find_package/RunCMakeTest.cmake
+++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake
@@ -1,5 +1,7 @@
include(RunCMake)
+run_cmake(CMP0074-WARN)
+run_cmake(CMP0074-OLD)
run_cmake(ComponentRequiredAndOptional)
run_cmake(MissingNormal)
run_cmake(MissingNormalRequired)
@@ -21,3 +23,9 @@ run_cmake(PolicyPop)
run_cmake(SetFoundFALSE)
run_cmake(WrongVersion)
run_cmake(WrongVersionConfig)
+run_cmake(CMP0084-OLD)
+run_cmake(CMP0084-WARN)
+run_cmake(CMP0084-NEW)
+if(UNIX)
+ run_cmake(SetFoundResolved)
+endif()
diff --git a/Tests/RunCMake/find_path/RunCMakeTest.cmake b/Tests/RunCMake/find_path/RunCMakeTest.cmake
index bf0fa8951..3afbedc90 100644
--- a/Tests/RunCMake/find_path/RunCMakeTest.cmake
+++ b/Tests/RunCMake/find_path/RunCMakeTest.cmake
@@ -1,5 +1,6 @@
include(RunCMake)
+run_cmake(EmptyOldStyle)
if(WIN32 OR CYGWIN)
run_cmake(PrefixInPATH)
endif()
diff --git a/Tests/RunCMake/find_program/RunCMakeTest.cmake b/Tests/RunCMake/find_program/RunCMakeTest.cmake
index 89307c1ae..6903f057b 100644
--- a/Tests/RunCMake/find_program/RunCMakeTest.cmake
+++ b/Tests/RunCMake/find_program/RunCMakeTest.cmake
@@ -3,6 +3,7 @@ include(RunCMake)
run_cmake(EnvAndHints)
run_cmake(DirsPerName)
run_cmake(NamesPerDir)
+run_cmake(RelAndAbsPath)
if(CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN)$")
run_cmake(WindowsCom)
diff --git a/Tests/RunCMake/get_filename_component/KnownComponents.cmake b/Tests/RunCMake/get_filename_component/KnownComponents.cmake
index 7dfb55d79..54b858f92 100644
--- a/Tests/RunCMake/get_filename_component/KnownComponents.cmake
+++ b/Tests/RunCMake/get_filename_component/KnownComponents.cmake
@@ -11,8 +11,10 @@ set(expect_DIRECTORY "/path/to")
set(expect_NAME "filename.ext.in")
set(expect_EXT ".ext.in")
set(expect_NAME_WE "filename")
+set(expect_LAST_EXT ".in")
+set(expect_NAME_WLE "filename.ext")
set(expect_PATH "/path/to")
-foreach(c DIRECTORY NAME EXT NAME_WE PATH)
+foreach(c DIRECTORY NAME EXT NAME_WE LAST_EXT NAME_WLE PATH)
get_filename_component(actual_${c} "${filename}" ${c})
check("${c}" "${actual_${c}}" "${expect_${c}}")
list(APPEND non_cache_vars actual_${c})
@@ -80,6 +82,17 @@ get_filename_component(test_program_name "/ arg1 arg2" PROGRAM
check("PROGRAM with args output: name" "${test_program_name}" "/")
check("PROGRAM with args output: args" "${test_program_args}" " arg1 arg2")
+get_filename_component(test_program_name " " PROGRAM)
+check("PROGRAM with just a space" "${test_program_name}" "")
+
+get_filename_component(test_program_name "${CMAKE_CURRENT_LIST_FILE}" PROGRAM)
+check("PROGRAM specified explicitly without quoting" "${test_program_name}" "${CMAKE_CURRENT_LIST_FILE}")
+
+get_filename_component(test_program_name "\"${CMAKE_CURRENT_LIST_FILE}\" arg1 arg2" PROGRAM
+ PROGRAM_ARGS test_program_args)
+check("PROGRAM specified explicitly with arguments: name" "${test_program_name}" "${CMAKE_CURRENT_LIST_FILE}")
+check("PROGRAM specified explicitly with arguments: args" "${test_program_args}" " arg1 arg2")
+
list(APPEND non_cache_vars test_program_name)
list(APPEND non_cache_vars test_program_args)
diff --git a/Tests/RunCMake/get_property/BadArgument-stderr.txt b/Tests/RunCMake/get_property/BadArgument-stderr.txt
index 37c44775c..ce5a20923 100644
--- a/Tests/RunCMake/get_property/BadArgument-stderr.txt
+++ b/Tests/RunCMake/get_property/BadArgument-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at BadArgument.cmake:1 \(get_property\):
get_property given invalid argument "FOO".
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/BadDirectory-stderr.txt b/Tests/RunCMake/get_property/BadDirectory-stderr.txt
index 98464f8dc..6afec038a 100644
--- a/Tests/RunCMake/get_property/BadDirectory-stderr.txt
+++ b/Tests/RunCMake/get_property/BadDirectory-stderr.txt
@@ -3,4 +3,4 @@
found. This could be because the directory argument was invalid or, it is
valid but has not been processed yet.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/BadScope-stderr.txt b/Tests/RunCMake/get_property/BadScope-stderr.txt
index 4cc32c87b..3084bb7fd 100644
--- a/Tests/RunCMake/get_property/BadScope-stderr.txt
+++ b/Tests/RunCMake/get_property/BadScope-stderr.txt
@@ -2,4 +2,4 @@
get_property given invalid scope FOO. Valid scopes are GLOBAL, DIRECTORY,
TARGET, SOURCE, TEST, VARIABLE, CACHE, INSTALL.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/BadTarget-stderr.txt b/Tests/RunCMake/get_property/BadTarget-stderr.txt
index 45a0df6c9..e85711721 100644
--- a/Tests/RunCMake/get_property/BadTarget-stderr.txt
+++ b/Tests/RunCMake/get_property/BadTarget-stderr.txt
@@ -2,4 +2,4 @@
get_property could not find TARGET FOO. Perhaps it has not yet been
created.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/BadTest-stderr.txt b/Tests/RunCMake/get_property/BadTest-stderr.txt
index 819c0704a..aec9e9e9c 100644
--- a/Tests/RunCMake/get_property/BadTest-stderr.txt
+++ b/Tests/RunCMake/get_property/BadTest-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at BadTest.cmake:1 \(get_property\):
get_property given TEST name that does not exist: FOO
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/GlobalName-stderr.txt b/Tests/RunCMake/get_property/GlobalName-stderr.txt
index a7d4971c2..4ddceb257 100644
--- a/Tests/RunCMake/get_property/GlobalName-stderr.txt
+++ b/Tests/RunCMake/get_property/GlobalName-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at GlobalName.cmake:1 \(get_property\):
get_property given name for GLOBAL scope.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/MissingArgument-stderr.txt b/Tests/RunCMake/get_property/MissingArgument-stderr.txt
index 87227127a..00d3311af 100644
--- a/Tests/RunCMake/get_property/MissingArgument-stderr.txt
+++ b/Tests/RunCMake/get_property/MissingArgument-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at MissingArgument.cmake:1 \(get_property\):
get_property called with incorrect number of arguments
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/NoCache-stderr.txt b/Tests/RunCMake/get_property/NoCache-stderr.txt
index defafb62d..7348cffdb 100644
--- a/Tests/RunCMake/get_property/NoCache-stderr.txt
+++ b/Tests/RunCMake/get_property/NoCache-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at NoCache.cmake:1 \(get_property\):
get_property not given name for CACHE scope.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/NoProperty-stderr.txt b/Tests/RunCMake/get_property/NoProperty-stderr.txt
index 0ef147fdb..79b8c8702 100644
--- a/Tests/RunCMake/get_property/NoProperty-stderr.txt
+++ b/Tests/RunCMake/get_property/NoProperty-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at NoProperty.cmake:1 \(get_property\):
get_property not given a PROPERTY <name> argument.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/NoSource-stderr.txt b/Tests/RunCMake/get_property/NoSource-stderr.txt
index 59fd0add7..cefff4167 100644
--- a/Tests/RunCMake/get_property/NoSource-stderr.txt
+++ b/Tests/RunCMake/get_property/NoSource-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at NoSource.cmake:1 \(get_property\):
get_property not given name for SOURCE scope.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/NoTarget-stderr.txt b/Tests/RunCMake/get_property/NoTarget-stderr.txt
index a0e1a9440..fb1c8f4e8 100644
--- a/Tests/RunCMake/get_property/NoTarget-stderr.txt
+++ b/Tests/RunCMake/get_property/NoTarget-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at NoTarget.cmake:1 \(get_property\):
get_property not given name for TARGET scope.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/NoTest-stderr.txt b/Tests/RunCMake/get_property/NoTest-stderr.txt
index c90a0ffc2..93c3e9821 100644
--- a/Tests/RunCMake/get_property/NoTest-stderr.txt
+++ b/Tests/RunCMake/get_property/NoTest-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at NoTest.cmake:1 \(get_property\):
get_property not given name for TEST scope.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/RunCMakeTest.cmake b/Tests/RunCMake/get_property/RunCMakeTest.cmake
index 017990fa9..06a0c673c 100644
--- a/Tests/RunCMake/get_property/RunCMakeTest.cmake
+++ b/Tests/RunCMake/get_property/RunCMakeTest.cmake
@@ -23,6 +23,10 @@ run_cmake(NoSource)
run_cmake(NoProperty)
run_cmake(NoCache)
+# Since we are testing the GENERATOR_IS_MULTI_CONFIG property itself,
+# don't rely on RunCMake_GENERATOR_IS_MULTI_CONFIG being set correctly
+# and instead explicitly check for a match against those generators we
+# expect to be multi-config
if(RunCMake_GENERATOR MATCHES "Visual Studio|Xcode")
run_cmake(IsMultiConfig)
else()
diff --git a/Tests/RunCMake/get_property/VariableName-stderr.txt b/Tests/RunCMake/get_property/VariableName-stderr.txt
index e9f382759..250d920b4 100644
--- a/Tests/RunCMake/get_property/VariableName-stderr.txt
+++ b/Tests/RunCMake/get_property/VariableName-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at VariableName.cmake:1 \(get_property\):
get_property given name for VARIABLE scope.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/get_property/directory_properties-stderr.txt b/Tests/RunCMake/get_property/directory_properties-stderr.txt
index 6d5bcdb0d..89f5618ee 100644
--- a/Tests/RunCMake/get_property/directory_properties-stderr.txt
+++ b/Tests/RunCMake/get_property/directory_properties-stderr.txt
@@ -19,4 +19,12 @@ get_property: -->[^<;]*/Tests/RunCMake/get_property<--
get_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build/directory_properties<--
get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties-build/directory_properties<--
get_directory_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--
-get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--$
+get_property: -->[^<;]*/Tests/RunCMake/get_property/directory_properties<--
+get_directory_property: --><--
+get_property: --><--
+get_directory_property: -->test1;test2<--
+get_property: -->test1;test2<--
+get_directory_property: -->test1;test2;test3<--
+get_property: -->test1;test2;test3<--
+get_directory_property: -->Sub/test1;Sub/test2<--
+get_property: -->Sub/test1;Sub/test2<--$
diff --git a/Tests/RunCMake/get_property/directory_properties.cmake b/Tests/RunCMake/get_property/directory_properties.cmake
index 4e68738d8..9b978fd50 100644
--- a/Tests/RunCMake/get_property/directory_properties.cmake
+++ b/Tests/RunCMake/get_property/directory_properties.cmake
@@ -28,3 +28,12 @@ check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" BINARY_DIR)
check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" SOURCE_DIR)
+
+check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" TESTS)
+add_test(NAME test1 COMMAND "${CMAKE_COMMAND}" -E echo "test1")
+add_test(NAME test2 COMMAND "${CMAKE_COMMAND}" -E echo "test2")
+check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" TESTS)
+add_test(NAME test3 COMMAND "${CMAKE_COMMAND}" -E echo "test3")
+check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}" TESTS)
+
+check_directory_property("${CMAKE_CURRENT_SOURCE_DIR}/directory_properties" TESTS)
diff --git a/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt b/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt
index 7318b9777..95106adca 100644
--- a/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt
+++ b/Tests/RunCMake/get_property/directory_properties/CMakeLists.txt
@@ -4,3 +4,6 @@ subdirs(sub2)
add_custom_target(CustomSub)
add_library(InterfaceSub INTERFACE)
add_library(my::InterfaceSub ALIAS InterfaceSub)
+
+add_test(Sub/test1 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test1")
+add_test(Sub/test2 COMMAND "${CMAKE_COMMAND}" -E echo "Sub/test2")
diff --git a/Tests/RunCMake/get_property/source_properties-stderr.txt b/Tests/RunCMake/get_property/source_properties-stderr.txt
index 0a46f96a0..00a9b8287 100644
--- a/Tests/RunCMake/get_property/source_properties-stderr.txt
+++ b/Tests/RunCMake/get_property/source_properties-stderr.txt
@@ -3,4 +3,10 @@ get_property: --><--
get_source_file_property: -->value<--
get_property: -->value<--
get_source_file_property: -->NOTFOUND<--
-get_property: --><--$
+get_property: --><--
+get_source_file_property: -->value<--
+get_property: -->value<--
+get_source_file_property: -->NOTFOUND<--
+get_property: --><--
+get_source_file_property: -->value<--
+get_property: -->value<--$
diff --git a/Tests/RunCMake/get_property/source_properties.cmake b/Tests/RunCMake/get_property/source_properties.cmake
index 263ffe123..12d2d0797 100644
--- a/Tests/RunCMake/get_property/source_properties.cmake
+++ b/Tests/RunCMake/get_property/source_properties.cmake
@@ -13,3 +13,13 @@ set_source_files_properties(file.c PROPERTIES empty "" custom value)
check_source_file_property(file.c empty)
check_source_file_property(file.c custom)
check_source_file_property(file.c noexist)
+
+# Test strange legacy behavior in which the order in which source files are
+# first accessed affects how properties are applied without an extension.
+# See also issue #15208.
+get_property(lang SOURCE ${CMAKE_CURRENT_BINARY_DIR}/file2.c PROPERTY LANGUAGE)
+get_property(lang SOURCE ${CMAKE_CURRENT_BINARY_DIR}/file2.h PROPERTY LANGUAGE)
+set_property(SOURCE file2 PROPERTY custom value) # set property without extension
+check_source_file_property(file2 custom) # should have property
+check_source_file_property(file2.h custom) # should not have property
+check_source_file_property(file2.c custom) # should have property
diff --git a/Tests/RunCMake/get_property/target_properties-stderr.txt b/Tests/RunCMake/get_property/target_properties-stderr.txt
index 6b3c6ca1b..df7a2f12c 100644
--- a/Tests/RunCMake/get_property/target_properties-stderr.txt
+++ b/Tests/RunCMake/get_property/target_properties-stderr.txt
@@ -7,4 +7,10 @@ get_property: --><--
get_target_property: -->(.*)/Tests/RunCMake/get_property<--
get_property: -->(.*)/Tests/RunCMake/get_property<--
get_target_property: -->(.*)/Tests/RunCMake/get_property/target_properties-build<--
-get_property: -->(.*)/Tests/RunCMake/get_property/target_properties-build<--$
+get_property: -->(.*)/Tests/RunCMake/get_property/target_properties-build<--
+get_target_property: -->FALSE<--
+get_property: -->FALSE<--
+get_target_property: -->FALSE<--
+get_property: -->FALSE<--
+get_target_property: -->TRUE<--
+get_property: -->TRUE<--$
diff --git a/Tests/RunCMake/get_property/target_properties.cmake b/Tests/RunCMake/get_property/target_properties.cmake
index 9ff833a67..321d5b5b8 100644
--- a/Tests/RunCMake/get_property/target_properties.cmake
+++ b/Tests/RunCMake/get_property/target_properties.cmake
@@ -16,3 +16,10 @@ check_target_property(tgt custom)
check_target_property(tgt noexist)
check_target_property(tgt SOURCE_DIR)
check_target_property(tgt BINARY_DIR)
+
+add_library(imported_local_tgt SHARED IMPORTED)
+add_library(imported_global_tgt SHARED IMPORTED GLOBAL)
+
+check_target_property(tgt IMPORTED_GLOBAL)
+check_target_property(imported_local_tgt IMPORTED_GLOBAL)
+check_target_property(imported_global_tgt IMPORTED_GLOBAL)
diff --git a/Tests/RunCMake/include_external_msproject/check_utils.cmake b/Tests/RunCMake/include_external_msproject/check_utils.cmake
index e9e9cac72..0a2ba63f5 100644
--- a/Tests/RunCMake/include_external_msproject/check_utils.cmake
+++ b/Tests/RunCMake/include_external_msproject/check_utils.cmake
@@ -100,6 +100,8 @@ function(check_project test name guid type platform imported_release_config_name
set(platform "${RunCMake_GENERATOR_PLATFORM}")
elseif("${RunCMake_GENERATOR}" MATCHES "Win64")
set(platform "x64")
+ elseif(VS_PLATFORM_NAME)
+ set(platform "${VS_PLATFORM_NAME}")
else()
set(platform "Win32")
endif()
diff --git a/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt
index 166ba6f04..c8074e96f 100644
--- a/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt
+++ b/Tests/RunCMake/install/DIRECTORY-PATTERN-MESSAGE_NEVER-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake
index 1a60f0c27..c637db151 100644
--- a/Tests/RunCMake/install/RunCMakeTest.cmake
+++ b/Tests/RunCMake/install/RunCMakeTest.cmake
@@ -21,6 +21,10 @@ function(run_install_test case)
# Check explicit component.
set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root-exc)
run_cmake_command(${case}-exc ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -DCOMPONENT=exc -P cmake_install.cmake)
+ set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root-lib)
+ run_cmake_command(${case}-lib ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -DCOMPONENT=lib -P cmake_install.cmake)
+ set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root-dev)
+ run_cmake_command(${case}-dev ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DBUILD_TYPE=Debug -DCOMPONENT=dev -P cmake_install.cmake)
endif()
endfunction()
@@ -59,11 +63,84 @@ run_cmake(EXPORT-OldIFace)
run_cmake(CMP0062-OLD)
run_cmake(CMP0062-NEW)
run_cmake(CMP0062-WARN)
+run_cmake(CMP0087-OLD)
+run_cmake(CMP0087-NEW)
+run_cmake(CMP0087-WARN)
+run_cmake(TARGETS-ImportedGlobal)
+run_cmake(TARGETS-NAMELINK_COMPONENT-bad-all)
+run_cmake(TARGETS-NAMELINK_COMPONENT-bad-exc)
+run_cmake(FILES-DESTINATION-TYPE)
+run_cmake(DIRECTORY-DESTINATION-TYPE)
+
+if(APPLE)
+ run_cmake(TARGETS-Apple-Defaults)
+endif()
if(NOT RunCMake_GENERATOR STREQUAL "Xcode" OR NOT "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]")
run_install_test(FILES-TARGET_OBJECTS)
endif()
+run_install_test(TARGETS-InstallFromSubDir)
+run_install_test(TARGETS-OPTIONAL)
+run_install_test(FILES-OPTIONAL)
+run_install_test(DIRECTORY-OPTIONAL)
+run_install_test(TARGETS-Defaults)
+
+set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_BINDIR:PATH=mybin"
+ "-DCMAKE_INSTALL_LIBDIR:PATH=mylib"
+ "-DCMAKE_INSTALL_INCLUDEDIR:PATH=myinclude"
+ )
+run_install_test(TARGETS-Defaults-Cache)
+unset(RunCMake_TEST_OPTIONS)
+
+run_install_test(FILES-TYPE)
+run_install_test(DIRECTORY-TYPE)
+
+set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_BINDIR:PATH=mybin"
+ "-DCMAKE_INSTALL_SBINDIR:PATH=mysbin"
+ "-DCMAKE_INSTALL_LIBEXECDIR:PATH=mylibexec"
+ "-DCMAKE_INSTALL_LIBDIR:PATH=mylib"
+ "-DCMAKE_INSTALL_INCLUDEDIR:PATH=myinclude"
+ "-DCMAKE_INSTALL_SYSCONFDIR:PATH=myetc"
+ "-DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=mycom"
+ "-DCMAKE_INSTALL_LOCALSTATEDIR:PATH=myvar"
+ "-DCMAKE_INSTALL_RUNSTATEDIR:PATH=myrun"
+ "-DCMAKE_INSTALL_DATADIR:PATH=myshare"
+ "-DCMAKE_INSTALL_INFODIR:PATH=myinfo"
+ "-DCMAKE_INSTALL_LOCALEDIR:PATH=mylocale"
+ "-DCMAKE_INSTALL_MANDIR:PATH=myman"
+ "-DCMAKE_INSTALL_DOCDIR:PATH=mydoc"
+ )
+run_install_test(FILES-TYPE-Cache)
+run_install_test(DIRECTORY-TYPE-Cache)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS
+ "-DCMAKE_INSTALL_LOCALSTATEDIR:PATH=myvar"
+ "-DCMAKE_INSTALL_DATAROOTDIR:PATH=myshare"
+ )
+run_install_test(FILES-TYPE-CacheDependent)
+run_install_test(DIRECTORY-TYPE-CacheDependent)
+unset(RunCMake_TEST_OPTIONS)
+
+set(RunCMake_TEST_OPTIONS "-DCMAKE_BUILD_TYPE:STRING=Debug")
+run_install_test(TARGETS-OUTPUT_NAME)
+unset(RunCMake_TEST_OPTIONS)
+
+run_install_test(Deprecated)
+run_install_test(PRE_POST_INSTALL_SCRIPT)
+run_install_test(SCRIPT)
+run_install_test(TARGETS-CONFIGURATIONS)
+run_install_test(DIRECTORY-PATTERN)
+run_install_test(TARGETS-Parts)
+run_install_test(FILES-PERMISSIONS)
+run_install_test(TARGETS-RPATH)
+run_install_test(InstallRequiredSystemLibraries)
+
set(run_install_test_components 1)
run_install_test(FILES-EXCLUDE_FROM_ALL)
run_install_test(TARGETS-EXCLUDE_FROM_ALL)
+run_install_test(TARGETS-NAMELINK_COMPONENT)
+run_install_test(SCRIPT-COMPONENT)
diff --git a/Tests/RunCMake/install/obj1.c b/Tests/RunCMake/install/obj1.c
index 2411aab79..70007df8a 100644
--- a/Tests/RunCMake/install/obj1.c
+++ b/Tests/RunCMake/install/obj1.c
@@ -1,4 +1,7 @@
-int obj1(void)
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+ int obj1(void)
{
return 0;
}
diff --git a/Tests/RunCMake/interface_library/global-interface-stderr.txt b/Tests/RunCMake/interface_library/global-interface-stderr.txt
index 24edd0f89..23b45d926 100644
--- a/Tests/RunCMake/interface_library/global-interface-stderr.txt
+++ b/Tests/RunCMake/interface_library/global-interface-stderr.txt
@@ -3,7 +3,7 @@ CMake Error at global-interface.cmake:2 \(add_library\):
GLOBAL
- Tried extensions \.c \.C \.c\+\+ \.cc \.cpp \.cxx \.m \.M \.mm \.h \.hh \.h\+\+ \.hm \.hpp
- \.hxx \.in \.txx
+ Tried extensions( \.[A-Za-z+]+|
+ )*
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/interface_library/target_commands-stderr.txt b/Tests/RunCMake/interface_library/target_commands-stderr.txt
index be11b7754..9362a752d 100644
--- a/Tests/RunCMake/interface_library/target_commands-stderr.txt
+++ b/Tests/RunCMake/interface_library/target_commands-stderr.txt
@@ -23,25 +23,25 @@ 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
+ target_include_directories may only 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
+ target_include_directories may only 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
+ target_compile_definitions may only 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
+ target_compile_definitions may only set INTERFACE properties on INTERFACE
+ targets
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
index 98ef05c0f..0db637531 100644
--- a/Tests/RunCMake/interface_library/whitelist.cmake
+++ b/Tests/RunCMake/interface_library/whitelist.cmake
@@ -4,3 +4,22 @@ 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)
+
+# Properties starting with `_` are allowed.
+set_property(TARGET iface PROPERTY "_custom_property" output)
+set_property(TARGET iface APPEND PROPERTY "_custom_property" append)
+get_target_property(outname iface "_custom_property")
+
+# Properties starting with a lowercase letter are allowed.
+set_property(TARGET iface PROPERTY "custom_property" output)
+set_property(TARGET iface APPEND PROPERTY "custom_property" append)
+get_target_property(outname iface "custom_property")
+
+# PUBLIC_HEADER / PRIVATE_HEADER properties are allowed
+set_property(TARGET iface PROPERTY PUBLIC_HEADER foo.h)
+set_property(TARGET iface APPEND PROPERTY PUBLIC_HEADER bar.h)
+get_target_property(outname iface PUBLIC_HEADER)
+
+set_property(TARGET iface PROPERTY PRIVATE_HEADER foo.h)
+set_property(TARGET iface APPEND PROPERTY PRIVATE_HEADER bar.h)
+get_target_property(outname iface PRIVATE_HEADER)
diff --git a/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt
index b24a0ed0b..9368e880b 100644
--- a/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt
+++ b/Tests/RunCMake/list/EmptyRemoveAt0-stderr.txt
@@ -1,4 +1,4 @@
CMake Error at EmptyRemoveAt0.cmake:2 \(list\):
- list REMOVE_AT given empty list
+ list index: mylist, 0 out of range \(0, 0\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/list/FILTER-NotList.cmake b/Tests/RunCMake/list/FILTER-NotList.cmake
index 1e15635b9..bf09ec74f 100644
--- a/Tests/RunCMake/list/FILTER-NotList.cmake
+++ b/Tests/RunCMake/list/FILTER-NotList.cmake
@@ -1,2 +1,6 @@
unset(nosuchlist)
list(FILTER nosuchlist EXCLUDE REGEX "^FILTER_THIS_.+")
+if (DEFINED nosuchlist)
+ message(FATAL_ERROR
+ "list(FILTER) created our list")
+endif ()
diff --git a/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt b/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt
index 6e15c0b43..9b9c5e0af 100644
--- a/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt
+++ b/Tests/RunCMake/list/INSERT-InvalidIndex-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at INSERT-InvalidIndex.cmake:2 \(list\):
- list index: 3 out of range \(-3, 2\)
+ list index: 4 out of range \(-3, 3\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/list/INSERT-InvalidIndex.cmake b/Tests/RunCMake/list/INSERT-InvalidIndex.cmake
index 4103d974b..12ac114cb 100644
--- a/Tests/RunCMake/list/INSERT-InvalidIndex.cmake
+++ b/Tests/RunCMake/list/INSERT-InvalidIndex.cmake
@@ -1,2 +1,2 @@
set(mylist alpha bravo charlie)
-list(INSERT mylist 3 delta)
+list(INSERT mylist 4 delta)
diff --git a/Tests/RunCMake/list/REMOVE_AT-NotList-stderr.txt b/Tests/RunCMake/list/REMOVE_AT-NotList-stderr.txt
index d6e8d85f5..563d865ea 100644
--- a/Tests/RunCMake/list/REMOVE_AT-NotList-stderr.txt
+++ b/Tests/RunCMake/list/REMOVE_AT-NotList-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at REMOVE_AT-NotList.cmake:2 \(list\):
- list sub-command REMOVE_AT requires list to be present.
+ list index: nosuchlist, 0 out of range \(0, 0\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/list/REMOVE_AT-NotList.cmake b/Tests/RunCMake/list/REMOVE_AT-NotList.cmake
index 5266c7fe9..090df4933 100644
--- a/Tests/RunCMake/list/REMOVE_AT-NotList.cmake
+++ b/Tests/RunCMake/list/REMOVE_AT-NotList.cmake
@@ -1,2 +1,6 @@
unset(nosuchlist)
list(REMOVE_AT nosuchlist 0)
+if (DEFINED nosuchlist)
+ message(FATAL_ERROR
+ "list(REMOVE_AT) created our list")
+endif ()
diff --git a/Tests/RunCMake/list/REMOVE_DUPLICATES-NotList.cmake b/Tests/RunCMake/list/REMOVE_DUPLICATES-NotList.cmake
index 218f2272c..b9f399943 100644
--- a/Tests/RunCMake/list/REMOVE_DUPLICATES-NotList.cmake
+++ b/Tests/RunCMake/list/REMOVE_DUPLICATES-NotList.cmake
@@ -1,2 +1,6 @@
unset(nosuchlist)
list(REMOVE_DUPLICATES nosuchlist)
+if (DEFINED nosuchlist)
+ message(FATAL_ERROR
+ "list(REMOVE_DUPLICATES) created our list")
+endif ()
diff --git a/Tests/RunCMake/list/REMOVE_ITEM-NotList.cmake b/Tests/RunCMake/list/REMOVE_ITEM-NotList.cmake
index 079e7fbce..0c66837c5 100644
--- a/Tests/RunCMake/list/REMOVE_ITEM-NotList.cmake
+++ b/Tests/RunCMake/list/REMOVE_ITEM-NotList.cmake
@@ -1,2 +1,6 @@
unset(nosuchlist)
list(REMOVE_ITEM nosuchlist alpha)
+if (DEFINED nosuchlist)
+ message(FATAL_ERROR
+ "list(REMOVE_ITEM) created our list")
+endif ()
diff --git a/Tests/RunCMake/list/REVERSE-NotList.cmake b/Tests/RunCMake/list/REVERSE-NotList.cmake
index 977e2ccac..71383294c 100644
--- a/Tests/RunCMake/list/REVERSE-NotList.cmake
+++ b/Tests/RunCMake/list/REVERSE-NotList.cmake
@@ -1,2 +1,6 @@
unset(nosuchlist)
list(REVERSE nosuchlist)
+if (DEFINED nosuchlist)
+ message(FATAL_ERROR
+ "list(REVERSE) created our list")
+endif ()
diff --git a/Tests/RunCMake/list/RunCMakeTest.cmake b/Tests/RunCMake/list/RunCMakeTest.cmake
index b002ab388..b4a91bc62 100644
--- a/Tests/RunCMake/list/RunCMakeTest.cmake
+++ b/Tests/RunCMake/list/RunCMakeTest.cmake
@@ -13,12 +13,18 @@ run_cmake(FILTER-REGEX-InvalidRegex)
run_cmake(GET-InvalidIndex)
run_cmake(INSERT-InvalidIndex)
run_cmake(REMOVE_AT-InvalidIndex)
+run_cmake(SUBLIST-InvalidIndex)
run_cmake(FILTER-REGEX-TooManyArguments)
+run_cmake(JOIN-TooManyArguments)
run_cmake(LENGTH-TooManyArguments)
run_cmake(REMOVE_DUPLICATES-TooManyArguments)
run_cmake(REVERSE-TooManyArguments)
-run_cmake(SORT-TooManyArguments)
+run_cmake(SUBLIST-TooManyArguments)
+
+run_cmake(REMOVE_AT-EmptyList)
+
+run_cmake(REMOVE_DUPLICATES-PreserveOrder)
run_cmake(FILTER-NotList)
run_cmake(REMOVE_AT-NotList)
@@ -31,3 +37,78 @@ run_cmake(FILTER-REGEX-InvalidMode)
run_cmake(FILTER-REGEX-InvalidOperator)
run_cmake(FILTER-REGEX-Valid0)
run_cmake(FILTER-REGEX-Valid1)
+
+run_cmake(JOIN-NoArguments)
+run_cmake(JOIN-NoVariable)
+run_cmake(JOIN)
+
+run_cmake(SUBLIST-NoArguments)
+run_cmake(SUBLIST-NoVariable)
+run_cmake(SUBLIST-InvalidLength)
+run_cmake(SUBLIST)
+
+run_cmake(TRANSFORM-NoAction)
+run_cmake(TRANSFORM-InvalidAction)
+# 'action' oriented tests
+run_cmake(TRANSFORM-TOUPPER-TooManyArguments)
+run_cmake(TRANSFORM-TOLOWER-TooManyArguments)
+run_cmake(TRANSFORM-STRIP-TooManyArguments)
+run_cmake(TRANSFORM-GENEX_STRIP-TooManyArguments)
+run_cmake(TRANSFORM-APPEND-NoArguments)
+run_cmake(TRANSFORM-APPEND-TooManyArguments)
+run_cmake(TRANSFORM-PREPEND-NoArguments)
+run_cmake(TRANSFORM-PREPEND-TooManyArguments)
+run_cmake(TRANSFORM-REPLACE-NoArguments)
+run_cmake(TRANSFORM-REPLACE-NoEnoughArguments)
+run_cmake(TRANSFORM-REPLACE-TooManyArguments)
+run_cmake(TRANSFORM-REPLACE-InvalidRegex)
+run_cmake(TRANSFORM-REPLACE-InvalidReplace1)
+run_cmake(TRANSFORM-REPLACE-InvalidReplace2)
+# 'selector' oriented tests
+run_cmake(TRANSFORM-Selector-REGEX-NoArguments)
+run_cmake(TRANSFORM-Selector-REGEX-TooManyArguments)
+run_cmake(TRANSFORM-Selector-REGEX-InvalidRegex)
+run_cmake(TRANSFORM-Selector-AT-NoArguments)
+run_cmake(TRANSFORM-Selector-AT-BadArgument)
+run_cmake(TRANSFORM-Selector-AT-InvalidIndex)
+run_cmake(TRANSFORM-Selector-FOR-NoArguments)
+run_cmake(TRANSFORM-Selector-FOR-NoEnoughArguments)
+run_cmake(TRANSFORM-Selector-FOR-TooManyArguments)
+run_cmake(TRANSFORM-Selector-FOR-BadArgument)
+run_cmake(TRANSFORM-Selector-FOR-InvalidIndex)
+# 'output' oriented tests
+run_cmake(TRANSFORM-Output-OUTPUT_VARIABLE-NoArguments)
+run_cmake(TRANSFORM-Output-OUTPUT_VARIABLE-TooManyArguments)
+# Successful tests
+run_cmake(TRANSFORM-TOUPPER)
+run_cmake(TRANSFORM-TOLOWER)
+run_cmake(TRANSFORM-STRIP)
+run_cmake(TRANSFORM-GENEX_STRIP)
+run_cmake(TRANSFORM-APPEND)
+run_cmake(TRANSFORM-PREPEND)
+run_cmake(TRANSFORM-REPLACE)
+
+# argument tests
+run_cmake(SORT-WrongOption)
+run_cmake(SORT-BadCaseOption)
+run_cmake(SORT-BadCompareOption)
+run_cmake(SORT-BadOrderOption)
+run_cmake(SORT-DuplicateOrderOption)
+run_cmake(SORT-DuplicateCompareOption)
+run_cmake(SORT-DuplicateCaseOption)
+run_cmake(SORT-NoCaseOption)
+
+# Successful tests
+run_cmake(SORT)
+
+# argument tests
+run_cmake(PREPEND-NoArgs)
+# Successful tests
+run_cmake(PREPEND)
+
+# argument tests
+run_cmake(POP_BACK-NoArgs)
+run_cmake(POP_FRONT-NoArgs)
+# Successful tests
+run_cmake(POP_BACK)
+run_cmake(POP_FRONT)
diff --git a/Tests/RunCMake/list/SORT-NotList.cmake b/Tests/RunCMake/list/SORT-NotList.cmake
index 8f48e1043..6314f1493 100644
--- a/Tests/RunCMake/list/SORT-NotList.cmake
+++ b/Tests/RunCMake/list/SORT-NotList.cmake
@@ -1,2 +1,6 @@
unset(nosuchlist)
list(SORT nosuchlist)
+if (DEFINED nosuchlist)
+ message(FATAL_ERROR
+ "list(SORT) created our list")
+endif ()
diff --git a/Tests/RunCMake/message/RunCMakeTest.cmake b/Tests/RunCMake/message/RunCMakeTest.cmake
index 2346c8675..cecfc7fe5 100644
--- a/Tests/RunCMake/message/RunCMakeTest.cmake
+++ b/Tests/RunCMake/message/RunCMakeTest.cmake
@@ -7,6 +7,48 @@ run_cmake(nomessage-internal-warning)
run_cmake(warnmessage)
# message command sets fatal occurred flag, so check each type of error
-# seperately
+# separately
run_cmake(errormessage_deprecated)
run_cmake(errormessage_dev)
+
+run_cmake_command(
+ message-loglevel-invalid
+ ${CMAKE_COMMAND} --loglevel=blah -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
+
+# Checking various combinations of `message(...)` and log levels `WARNING` to `TRACE`
+# - no CLI option -> `WARNING` to `STATUS` output
+run_cmake_command(
+ message-loglevel-default
+ ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
+# - Only `WARNING` output
+run_cmake_command(
+ message-loglevel-warning
+ ${CMAKE_COMMAND} --loglevel=warning -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
+# - Only `WARNING` and `NOTICE` output
+run_cmake_command(
+ message-loglevel-notice
+ ${CMAKE_COMMAND} --loglevel=notice -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
+# - `WARNING` to `STATUS` output
+run_cmake_command(
+ message-loglevel-status
+ ${CMAKE_COMMAND} --loglevel=status -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
+# - `WARNING` to `VERBOSE` output
+run_cmake_command(
+ message-loglevel-verbose
+ ${CMAKE_COMMAND} --loglevel=verbose -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
+# - `WARNING` to `DEBUG` output
+run_cmake_command(
+ message-loglevel-debug
+ ${CMAKE_COMMAND} --loglevel=debug -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
+# - `WARNING` to `TRACE` output
+run_cmake_command(
+ message-loglevel-trace
+ ${CMAKE_COMMAND} --loglevel=trace -P ${RunCMake_SOURCE_DIR}/message-all-loglevels.cmake
+ )
diff --git a/Tests/RunCMake/project/ProjectDescription2-stderr.txt b/Tests/RunCMake/project/ProjectDescription2-stderr.txt
index 558e2dfbb..c65a99731 100644
--- a/Tests/RunCMake/project/ProjectDescription2-stderr.txt
+++ b/Tests/RunCMake/project/ProjectDescription2-stderr.txt
@@ -1 +1 @@
- DESCRITPION may be specified at most once.
+ DESCRIPTION may be specified at most once.
diff --git a/Tests/RunCMake/project/RunCMakeTest.cmake b/Tests/RunCMake/project/RunCMakeTest.cmake
index 3d13e2ef4..3a8ad4bbf 100644
--- a/Tests/RunCMake/project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/project/RunCMakeTest.cmake
@@ -7,8 +7,15 @@ run_cmake(LanguagesImplicit)
run_cmake(LanguagesEmpty)
run_cmake(LanguagesNONE)
run_cmake(LanguagesTwice)
+run_cmake(LanguagesUnordered)
run_cmake(ProjectDescription)
run_cmake(ProjectDescription2)
+run_cmake(ProjectDescriptionNoArg)
+run_cmake(ProjectDescriptionNoArg2)
+run_cmake(ProjectHomepage)
+run_cmake(ProjectHomepage2)
+run_cmake(ProjectHomepageNoArg)
+run_cmake(ProjectTwice)
run_cmake(VersionAndLanguagesEmpty)
run_cmake(VersionEmpty)
run_cmake(VersionInvalid)
diff --git a/Tests/RunCMake/project/VersionMissingLanguages-stderr.txt b/Tests/RunCMake/project/VersionMissingLanguages-stderr.txt
index 52433bcc0..576ac6934 100644
--- a/Tests/RunCMake/project/VersionMissingLanguages-stderr.txt
+++ b/Tests/RunCMake/project/VersionMissingLanguages-stderr.txt
@@ -1,4 +1,5 @@
CMake Error at VersionMissingLanguages.cmake:2 \(project\):
- project with VERSION must use LANGUAGES before language names.
+ project with VERSION, DESCRIPTION or HOMEPAGE_URL must use LANGUAGES before
+ language names.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$
diff --git a/Tests/RunCMake/set/RunCMakeTest.cmake b/Tests/RunCMake/set/RunCMakeTest.cmake
index b8e8cf1f9..b3bd0a480 100644
--- a/Tests/RunCMake/set/RunCMakeTest.cmake
+++ b/Tests/RunCMake/set/RunCMakeTest.cmake
@@ -3,3 +3,5 @@ include(RunCMake)
run_cmake(ParentScope)
run_cmake(ParentPulling)
run_cmake(ParentPullingRecursive)
+run_cmake(UnknownCacheType)
+run_cmake(ExtraEnvValue)
diff --git a/Tests/RunCMake/set_property/RunCMakeTest.cmake b/Tests/RunCMake/set_property/RunCMakeTest.cmake
index 1ddaceeab..8d4614c5d 100644
--- a/Tests/RunCMake/set_property/RunCMakeTest.cmake
+++ b/Tests/RunCMake/set_property/RunCMakeTest.cmake
@@ -3,8 +3,12 @@ include(RunCMake)
run_cmake(COMPILE_DEFINITIONS)
run_cmake(COMPILE_FEATURES)
run_cmake(COMPILE_OPTIONS)
+run_cmake(IMPORTED_GLOBAL)
run_cmake(INCLUDE_DIRECTORIES)
+run_cmake(LINK_OPTIONS)
+run_cmake(LINK_DIRECTORIES)
run_cmake(LINK_LIBRARIES)
run_cmake(SOURCES)
run_cmake(TYPE)
run_cmake(USER_PROP)
+run_cmake(USER_PROP_INHERITED)
diff --git a/Tests/RunCMake/string/AppendNoArgs-stderr.txt b/Tests/RunCMake/string/AppendNoArgs-stderr.txt
index 75ad427fd..9b7e9facd 100644
--- a/Tests/RunCMake/string/AppendNoArgs-stderr.txt
+++ b/Tests/RunCMake/string/AppendNoArgs-stderr.txt
@@ -1,4 +1,4 @@
CMake Error at AppendNoArgs.cmake:1 \(string\):
string sub-command APPEND requires at least one argument.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/string/ConcatNoArgs-stderr.txt b/Tests/RunCMake/string/ConcatNoArgs-stderr.txt
index efea5f1d8..22b608dd7 100644
--- a/Tests/RunCMake/string/ConcatNoArgs-stderr.txt
+++ b/Tests/RunCMake/string/ConcatNoArgs-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/string/RunCMakeTest.cmake b/Tests/RunCMake/string/RunCMakeTest.cmake
index 38a77b0d1..c432b4ed5 100644
--- a/Tests/RunCMake/string/RunCMakeTest.cmake
+++ b/Tests/RunCMake/string/RunCMakeTest.cmake
@@ -3,9 +3,16 @@ include(RunCMake)
run_cmake(Append)
run_cmake(AppendNoArgs)
+run_cmake(Prepend)
+run_cmake(PrependNoArgs)
+
run_cmake(Concat)
run_cmake(ConcatNoArgs)
+run_cmake(Join)
+run_cmake(JoinNoArgs)
+run_cmake(JoinNoVar)
+
run_cmake(Timestamp)
run_cmake(TimestampEmpty)
run_cmake(TimestampInvalid)
@@ -20,8 +27,13 @@ run_cmake(UuidMissingTypeValue)
run_cmake(UuidBadType)
run_cmake(RegexClear)
+run_cmake(RegexMultiMatchClear)
run_cmake(UTF-16BE)
run_cmake(UTF-16LE)
run_cmake(UTF-32BE)
run_cmake(UTF-32LE)
+
+run_cmake(Repeat)
+run_cmake(RepeatNoArgs)
+run_cmake(RepeatNegativeCount)
diff --git a/Tests/RunCMake/string/Timestamp-stderr.txt b/Tests/RunCMake/string/Timestamp-stderr.txt
index 653974c62..cd4dcb37e 100644
--- a/Tests/RunCMake/string/Timestamp-stderr.txt
+++ b/Tests/RunCMake/string/Timestamp-stderr.txt
@@ -1 +1 @@
-RESULT=2005-08-07 23:19:49 Sun Aug 05 day=219 wd=0 week=32 %I=11 epoch=1123456789
+RESULT=2005-08-07 23:19:49 Sunday=Sun August=Aug 05 day=219 wd=0 week=32 %I=11 epoch=1123456789
diff --git a/Tests/RunCMake/string/Timestamp.cmake b/Tests/RunCMake/string/Timestamp.cmake
index d24203942..cba258d12 100644
--- a/Tests/RunCMake/string/Timestamp.cmake
+++ b/Tests/RunCMake/string/Timestamp.cmake
@@ -1,3 +1,3 @@
set(ENV{SOURCE_DATE_EPOCH} "1123456789")
-string(TIMESTAMP RESULT "%Y-%m-%d %H:%M:%S %a %b %y day=%j wd=%w week=%U %%I=%I epoch=%s" UTC)
+string(TIMESTAMP RESULT "%Y-%m-%d %H:%M:%S %A=%a %B=%b %y day=%j wd=%w week=%U %%I=%I epoch=%s" UTC)
message("RESULT=${RESULT}")
diff --git a/Tests/RunCMake/string/UuidBadNamespace-stderr.txt b/Tests/RunCMake/string/UuidBadNamespace-stderr.txt
index cb12903e1..340189b9f 100644
--- a/Tests/RunCMake/string/UuidBadNamespace-stderr.txt
+++ b/Tests/RunCMake/string/UuidBadNamespace-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/string/UuidBadType-stderr.txt b/Tests/RunCMake/string/UuidBadType-stderr.txt
index 1993c044a..2734d86a6 100644
--- a/Tests/RunCMake/string/UuidBadType-stderr.txt
+++ b/Tests/RunCMake/string/UuidBadType-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingNameValue-stderr.txt b/Tests/RunCMake/string/UuidMissingNameValue-stderr.txt
index 0b7cde463..79819a97d 100644
--- a/Tests/RunCMake/string/UuidMissingNameValue-stderr.txt
+++ b/Tests/RunCMake/string/UuidMissingNameValue-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingNamespace-stderr.txt b/Tests/RunCMake/string/UuidMissingNamespace-stderr.txt
index dfcfe42b2..1ffc53fe0 100644
--- a/Tests/RunCMake/string/UuidMissingNamespace-stderr.txt
+++ b/Tests/RunCMake/string/UuidMissingNamespace-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt b/Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt
index 86585ad40..2a73d3f0c 100644
--- a/Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt
+++ b/Tests/RunCMake/string/UuidMissingNamespaceValue-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt b/Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt
index 70252f8cd..44bd479cd 100644
--- a/Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt
+++ b/Tests/RunCMake/string/UuidMissingTypeValue-stderr.txt
@@ -1,4 +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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
index 1f67f11a0..f8b08094b 100644
--- a/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_compile_features/RunCMakeTest.cmake
@@ -12,3 +12,4 @@ run_cmake(no_matching_cxx_feature)
run_cmake(not_a_c_feature)
run_cmake(no_matching_c_feature)
run_cmake(cxx_not_enabled)
+run_cmake(empty_keyword_args)
diff --git a/Tests/RunCMake/target_compile_features/alias_target-stderr.txt b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt
index 5ebe170c3..1658f58df 100644
--- a/Tests/RunCMake/target_compile_features/alias_target-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/alias_target-stderr.txt
@@ -1,4 +1,4 @@
CMake Error at alias_target.cmake:[0-9]+ \(target_compile_features\):
target_compile_features can not be used on an ALIAS target.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt b/Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt
index 4f707c7b9..5b4761c60 100644
--- a/Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/cxx_not_enabled-stderr.txt
@@ -1,4 +1,4 @@
^CMake Error at cxx_not_enabled.cmake:[0-9]+ \(target_compile_features\):
target_compile_features cannot use features from non-enabled language CXX
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)$
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_compile_features/imported_target-stderr.txt b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt
index 7a07427a0..f2a1aba9c 100644
--- a/Tests/RunCMake/target_compile_features/imported_target-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/imported_target-stderr.txt
@@ -1,4 +1,5 @@
-CMake Error at imported_target.cmake:[0-9]+ \(target_compile_features\):
- Cannot specify compile features for imported target "main".
+^CMake Error at imported_target.cmake:[0-9]+ \(target_compile_features\):
+ target_compile_features may only set INTERFACE properties on INTERFACE
+ targets
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/target_compile_features/imported_target.cmake b/Tests/RunCMake/target_compile_features/imported_target.cmake
index e886ce922..e410ace2a 100644
--- a/Tests/RunCMake/target_compile_features/imported_target.cmake
+++ b/Tests/RunCMake/target_compile_features/imported_target.cmake
@@ -1,4 +1,10 @@
enable_language(CXX)
-add_library(main INTERFACE IMPORTED)
-target_compile_features(main INTERFACE cxx_delegating_constructors)
+add_library(lib1-interface INTERFACE IMPORTED)
+target_compile_features(lib1-interface INTERFACE cxx_delegating_constructors)
+
+add_library(lib2-interface INTERFACE IMPORTED)
+target_compile_features(lib2-interface PUBLIC cxx_delegating_constructors)
+
+add_library(lib-shared SHARED IMPORTED)
+target_compile_features(lib-shared INTERFACE cxx_delegating_constructors)
diff --git a/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt
index 9917be77a..ee57b5484 100644
--- a/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/invalid_args-stderr.txt
@@ -1,4 +1,4 @@
CMake Error at invalid_args.cmake:[0-9]+ \(target_compile_features\):
target_compile_features called with invalid arguments
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
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
index 37089983a..d6564f4c0 100644
--- a/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/invalid_args_on_interface-stderr.txt
@@ -1,5 +1,5 @@
CMake Error at invalid_args_on_interface.cmake:[0-9]+ \(target_compile_features\):
- target_compile_features may only be set INTERFACE properties on INTERFACE
+ target_compile_features may only set INTERFACE properties on INTERFACE
targets
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
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
index 1875d1209..07ddd6a55 100644
--- a/Tests/RunCMake/target_compile_features/no_matching_c_feature-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/no_matching_c_feature-stderr.txt
@@ -5,4 +5,4 @@ CMake Error at no_matching_c_feature.cmake:[0-9]+ \((target_compile_features|mes
version 4.8.1.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
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
index 90d41c957..9392f4b25 100644
--- a/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/no_matching_cxx_feature-stderr.txt
@@ -5,4 +5,4 @@ CMake Error at no_matching_cxx_feature.cmake:[0-9]+ \((target_compile_features|m
version *[.0-9]+\.
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_compile_features/no_target-stderr.txt b/Tests/RunCMake/target_compile_features/no_target-stderr.txt
index 65974b4d6..7b62c947e 100644
--- a/Tests/RunCMake/target_compile_features/no_target-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/no_target-stderr.txt
@@ -2,4 +2,4 @@ CMake Error at no_target.cmake:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
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
index 493c5826c..8a4055d07 100644
--- a/Tests/RunCMake/target_compile_features/not_a_c_feature-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/not_a_c_feature-stderr.txt
@@ -2,4 +2,4 @@ CMake Error at not_a_c_feature.cmake:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
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
index 3dbf0e654..bd7f2c6b4 100644
--- a/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/not_a_cxx_feature-stderr.txt
@@ -2,4 +2,4 @@ CMake Error at not_a_cxx_feature.cmake:[0-9]+ \(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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt
index c0c2efac4..34f1ce222 100644
--- a/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/not_enough_args-stderr.txt
@@ -1,4 +1,4 @@
CMake Error at not_enough_args.cmake:[0-9]+ \(target_compile_features\):
target_compile_features called with incorrect number of arguments
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_compile_features/utility_target-stderr.txt b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt
index ff03310d1..0c01377fa 100644
--- a/Tests/RunCMake/target_compile_features/utility_target-stderr.txt
+++ b/Tests/RunCMake/target_compile_features/utility_target-stderr.txt
@@ -1,4 +1,4 @@
CMake Error at utility_target.cmake:[0-9]+ \(target_compile_features\):
target_compile_features called with non-compilable target type
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
index 8e3f3153b..12c00fb01 100644
--- a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-2-stderr.txt
@@ -8,4 +8,4 @@ CMake Error at CMP0023-NEW-2.cmake:11 \(target_link_libraries\):
\* CMP0023-NEW-2.cmake:10 \(target_link_libraries\)
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
index 2ef229034..117c80614 100644
--- a/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-NEW-stderr.txt
@@ -8,4 +8,4 @@ CMake Error at CMP0023-NEW.cmake:11 \(target_link_libraries\):
\* CMP0023-NEW.cmake:10 \(target_link_libraries\)
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt
index 514786154..7e49d525e 100644
--- a/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-2-stderr.txt
@@ -13,4 +13,4 @@ CMake Warning \(dev\) at CMP0023-WARN-2.cmake:9 \(target_link_libraries\):
\* CMP0023-WARN-2.cmake:8 \(target_link_libraries\)
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt
index a7474fac9..df1288e35 100644
--- a/Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt
+++ b/Tests/RunCMake/target_link_libraries/CMP0023-WARN-stderr.txt
@@ -13,4 +13,4 @@ CMake Warning \(dev\) at CMP0023-WARN.cmake:9 \(target_link_libraries\):
\* CMP0023-WARN.cmake:8 \(target_link_libraries\)
Call Stack \(most recent call first\):
- CMakeLists.txt:3 \(include\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/CMakeLists.txt b/Tests/RunCMake/target_link_libraries/CMakeLists.txt
index 12cd3c775..8f85fbf54 100644
--- a/Tests/RunCMake/target_link_libraries/CMakeLists.txt
+++ b/Tests/RunCMake/target_link_libraries/CMakeLists.txt
@@ -1,3 +1,3 @@
cmake_minimum_required(VERSION 2.8.4)
project(${RunCMake_TEST} NONE)
-include(${RunCMake_TEST}.cmake)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
diff --git a/Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt b/Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt
index a0c66dbe2..5b0caf757 100644
--- a/Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt
+++ b/Tests/RunCMake/target_link_libraries/MixedSignature-stderr.txt
@@ -1,5 +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.
+ The INTERFACE, 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\)
+ CMakeLists\.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
index 1466fbf61..0152d4c67 100644
--- a/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
+++ b/Tests/RunCMake/target_link_libraries/RunCMakeTest.cmake
@@ -4,9 +4,19 @@ run_cmake(CMP0023-WARN)
run_cmake(CMP0023-NEW)
run_cmake(CMP0023-WARN-2)
run_cmake(CMP0023-NEW-2)
+run_cmake(CMP0079-iface-WARN)
+run_cmake(CMP0079-iface-OLD)
+run_cmake(CMP0079-iface-NEW)
+run_cmake(CMP0079-link-WARN)
+run_cmake(CMP0079-link-OLD)
+run_cmake(CMP0079-link-NEW)
+run_cmake(CMP0079-link-NEW-bogus)
+run_cmake(ImportedTarget)
+run_cmake(ImportedTargetFailure)
run_cmake(MixedSignature)
run_cmake(Separate-PRIVATE-LINK_PRIVATE-uses)
-run_cmake(SubDirTarget)
run_cmake(SharedDepNotTarget)
run_cmake(StaticPrivateDepNotExported)
run_cmake(StaticPrivateDepNotTarget)
+run_cmake(UNKNOWN-IMPORTED-GLOBAL)
+run_cmake(empty_keyword_args)
diff --git a/Tests/RunCMake/try_compile/CMP0056-stderr.txt b/Tests/RunCMake/try_compile/CMP0056-stderr.txt
index 5c1f0e4cf..de442059d 100644
--- a/Tests/RunCMake/try_compile/CMP0056-stderr.txt
+++ b/Tests/RunCMake/try_compile/CMP0056-stderr.txt
@@ -10,4 +10,15 @@ CMake Warning \(dev\) at CMP0056.cmake:[0-9]+ \(try_compile\):
caller link flags \(e.g. CMAKE_EXE_LINKER_FLAGS\) in the test project.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
-This warning is for project developers. Use -Wno-dev to suppress it.$
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Deprecation Warning at CMP0056.cmake:[0-9]+ \(cmake_policy\):
+ The OLD behavior for policy CMP0056 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/try_compile/CMP0066-stderr.txt b/Tests/RunCMake/try_compile/CMP0066-stderr.txt
index b14e2900e..0b92dcfc7 100644
--- a/Tests/RunCMake/try_compile/CMP0066-stderr.txt
+++ b/Tests/RunCMake/try_compile/CMP0066-stderr.txt
@@ -12,4 +12,15 @@ CMake Warning \(dev\) at CMP0066.cmake:[0-9]+ \(try_compile\):
test project.
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)
-This warning is for project developers. Use -Wno-dev to suppress it.$
+This warning is for project developers. Use -Wno-dev to suppress it.
+*
+CMake Deprecation Warning at CMP0066.cmake:[0-9]+ \(cmake_policy\):
+ The OLD behavior for policy CMP0066 will be removed from a future version
+ of CMake.
+
+ The cmake-policies\(7\) manual explains that the OLD behaviors of all
+ policies are deprecated and that a policy should be set to OLD only under
+ specific short-term circumstances. Projects should be ported to the NEW
+ behavior and not rely on setting a policy to OLD.
+Call Stack \(most recent call first\):
+ CMakeLists.txt:[0-9]+ \(include\)$
diff --git a/Tests/RunCMake/try_compile/CStandardGNU.c b/Tests/RunCMake/try_compile/CStandardGNU.c
index ac26c15e9..f7ddff4d3 100644
--- a/Tests/RunCMake/try_compile/CStandardGNU.c
+++ b/Tests/RunCMake/try_compile/CStandardGNU.c
@@ -1,8 +1,8 @@
#if __STDC_VERSION__ != 199901L
-#error "Not GNU C 99 mode!"
+# error "Not GNU C 99 mode!"
#endif
#ifndef __STRICT_ANSI__
-#error "Not GNU C strict ANSI!"
+# error "Not GNU C strict ANSI!"
#endif
int main(void)
{
diff --git a/Tests/RunCMake/try_compile/CxxStandardGNU.cxx b/Tests/RunCMake/try_compile/CxxStandardGNU.cxx
index 7990a78dd..ef65e2656 100644
--- a/Tests/RunCMake/try_compile/CxxStandardGNU.cxx
+++ b/Tests/RunCMake/try_compile/CxxStandardGNU.cxx
@@ -1,9 +1,9 @@
#if __cplusplus != 201103L && \
!(__cplusplus < 201103L && defined(__GXX_EXPERIMENTAL_CXX0X__))
-#error "Not GNU C++ 11 mode!"
+# error "Not GNU C++ 11 mode!"
#endif
#ifndef __STRICT_ANSI__
-#error "Not GNU C++ strict ANSI!"
+# error "Not GNU C++ strict ANSI!"
#endif
int main()
{
diff --git a/Tests/RunCMake/try_compile/RunCMakeTest.cmake b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
index 6a1bc64c0..77fb7a0f3 100644
--- a/Tests/RunCMake/try_compile/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_compile/RunCMakeTest.cmake
@@ -25,6 +25,13 @@ run_cmake(TargetTypeExe)
run_cmake(TargetTypeInvalid)
run_cmake(TargetTypeStatic)
+if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
+ CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|Clang|AppleClang)$")
+ set (RunCMake_TEST_OPTIONS -DRunCMake_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
+ run_cmake(LinkOptions)
+ unset (RunCMake_TEST_OPTIONS)
+endif()
+
if(CMAKE_C_STANDARD_DEFAULT)
run_cmake(CStandard)
elseif(DEFINED CMAKE_C_STANDARD_DEFAULT)
diff --git a/Tests/RunCMake/try_compile/src.c b/Tests/RunCMake/try_compile/src.c
index 5e513825c..beed9b14d 100644
--- a/Tests/RunCMake/try_compile/src.c
+++ b/Tests/RunCMake/try_compile/src.c
@@ -3,5 +3,5 @@ int main(void)
return 0;
}
#ifdef PP_ERROR
-#error PP_ERROR is defined
+# error PP_ERROR is defined
#endif
diff --git a/Tests/RunCMake/try_run/RunCMakeTest.cmake b/Tests/RunCMake/try_run/RunCMakeTest.cmake
index 1ec9a55aa..368956295 100644
--- a/Tests/RunCMake/try_run/RunCMakeTest.cmake
+++ b/Tests/RunCMake/try_run/RunCMakeTest.cmake
@@ -1,3 +1,10 @@
include(RunCMake)
run_cmake(BadLinkLibraries)
+
+if (CMAKE_SYSTEM_NAME MATCHES "^(Linux|Darwin|Windows)$" AND
+ CMAKE_C_COMPILER_ID MATCHES "^(MSVC|GNU|Clang|AppleClang)$")
+ set (RunCMake_TEST_OPTIONS -DRunCMake_C_COMPILER_ID=${CMAKE_C_COMPILER_ID})
+ run_cmake(LinkOptions)
+ unset (RunCMake_TEST_OPTIONS)
+endif()
diff --git a/Tests/RunCMake/variable_watch/RunCMakeTest.cmake b/Tests/RunCMake/variable_watch/RunCMakeTest.cmake
index 9becb4cd7..3883999c6 100644
--- a/Tests/RunCMake/variable_watch/RunCMakeTest.cmake
+++ b/Tests/RunCMake/variable_watch/RunCMakeTest.cmake
@@ -3,3 +3,5 @@ include(RunCMake)
run_cmake(ModifiedAccess)
run_cmake(NoWatcher)
run_cmake(WatchTwice)
+run_cmake(ModifyWatchInCallback)
+run_cmake(RaiseInParentScope)
diff --git a/Tests/Server/CMakeLists.txt b/Tests/Server/CMakeLists.txt
index e7eaa8d72..8321edb1d 100644
--- a/Tests/Server/CMakeLists.txt
+++ b/Tests/Server/CMakeLists.txt
@@ -1,12 +1,12 @@
cmake_minimum_required(VERSION 3.4)
project(Server CXX)
-find_package(PythonInterp REQUIRED)
+find_package(Python REQUIRED)
-macro(do_test bsname file)
- execute_process(COMMAND ${PYTHON_EXECUTABLE}
+macro(do_test bsname file type)
+ execute_process(COMMAND ${Python_EXECUTABLE}
-B # no .pyc files
- "${CMAKE_SOURCE_DIR}/server-test.py"
+ "${CMAKE_SOURCE_DIR}/${type}-test.py"
"${CMAKE_COMMAND}"
"${CMAKE_SOURCE_DIR}/${file}"
"${CMAKE_SOURCE_DIR}"
@@ -16,12 +16,13 @@ macro(do_test bsname file)
)
if (NOT test_result EQUAL 0)
- message(SEND_ERROR "TEST FAILED")
+ message(SEND_ERROR "TEST FAILED: ${test_result}")
endif()
endmacro()
-do_test("test_handshake" "tc_handshake.json")
-do_test("test_globalSettings" "tc_globalSettings.json")
-do_test("test_buildsystem1" "tc_buildsystem1.json")
+do_test("test_cache" "tc_cache.json" "server")
+do_test("test_handshake" "tc_handshake.json" "server")
+do_test("test_globalSettings" "tc_globalSettings.json" "server")
+do_test("test_buildsystem1" "tc_buildsystem1.json" "server")
add_executable(Server empty.cpp)
diff --git a/Tests/Server/cmakelib.py b/Tests/Server/cmakelib.py
index 78450d5bf..546ae4cc5 100644
--- a/Tests/Server/cmakelib.py
+++ b/Tests/Server/cmakelib.py
@@ -1,5 +1,5 @@
from __future__ import print_function
-import sys, subprocess, json
+import sys, subprocess, json, os, select, shutil, time, socket
termwidth = 150
@@ -38,11 +38,50 @@ def col_print(title, array):
for index in range(numRows):
print(indent + pad.join(item.ljust(maxitemwidth) for item in array[index::numRows]))
+filterPacket = lambda x: x
+
+STDIN = 0
+PIPE = 1
+
+communicationMethods = [STDIN]
+
+if hasattr(socket, 'AF_UNIX'):
+ communicationMethods.append(PIPE)
+
+def defaultExitWithError(proc):
+ data = ""
+ try:
+ while select.select([proc.outPipe], [], [], 3.)[0]:
+ data = data + proc.outPipe.read(1)
+ if len(data):
+ print("Rest of raw buffer from server:")
+ printServer(data)
+ except:
+ pass
+ proc.outPipe.close()
+ proc.inPipe.close()
+ proc.kill()
+ sys.exit(1)
+
+exitWithError = lambda proc: defaultExitWithError(proc)
+
+serverTag = "SERVER"
+
+def printServer(*args):
+ print(serverTag + ">", *args)
+ print()
+ sys.stdout.flush()
+
+def printClient(*args):
+ print("CLIENT>", *args)
+ print()
+ sys.stdout.flush()
+
def waitForRawMessage(cmakeCommand):
stdoutdata = ""
payload = ""
while not cmakeCommand.poll():
- stdoutdataLine = cmakeCommand.stdout.readline()
+ stdoutdataLine = cmakeCommand.outPipe.readline()
if stdoutdataLine:
stdoutdata += stdoutdataLine.decode('utf-8')
else:
@@ -50,12 +89,24 @@ def waitForRawMessage(cmakeCommand):
begin = stdoutdata.find('[== "CMake Server" ==[\n')
end = stdoutdata.find(']== "CMake Server" ==]')
- if (begin != -1 and end != -1):
+ if begin != -1 and end != -1:
begin += len('[== "CMake Server" ==[\n')
payload = stdoutdata[begin:end]
- if print_communication:
- print("\nSERVER>", json.loads(payload), "\n")
- return json.loads(payload)
+ jsonPayload = json.loads(payload)
+ filteredPayload = filterPacket(jsonPayload)
+ if print_communication and filteredPayload:
+ printServer(filteredPayload)
+ if filteredPayload is not None or jsonPayload is None:
+ return jsonPayload
+ stdoutdata = stdoutdata[(end+len(']== "CMake Server" ==]')):]
+
+# Python2 has no problem writing the output of encodes directly,
+# but Python3 returns only 'int's for encode and so must be turned
+# into bytes. We use the existence of 'to_bytes' on an int to
+# determine which behavior is appropriate. It might be more clear
+# to do this in the code which uses the flag, but introducing
+# this lookup cost at every byte sent isn't ideal.
+has_to_bytes = "to_bytes" in dir(10)
def writeRawData(cmakeCommand, content):
writeRawData.counter += 1
@@ -71,36 +122,96 @@ def writeRawData(cmakeCommand, content):
payload = payload.replace('\n', '\r\n')
if print_communication:
- print("\nCLIENT>", content, "(Use \\r\\n:", rn, ")\n")
- cmakeCommand.stdin.write(payload.encode('utf-8'))
- cmakeCommand.stdin.flush()
+ printClient(content, "(Use \\r\\n:", rn, ")")
+
+ # To stress test how cmake deals with fragmentation in the
+ # communication channel, we send only one byte at a time.
+ # Certain communication methods / platforms might still buffer
+ # it all into one message since its so close together, but in
+ # general this will catch places where we assume full buffers
+ # come in all at once.
+ encoded_payload = payload.encode('utf-8')
+
+ # Python version 3+ can't write ints directly; but 'to_bytes'
+ # for int was only added in python 3.2. If this is a 3+ version
+ # of python without that conversion function; just write the whole
+ # thing out at once.
+ if sys.version_info[0] > 2 and not has_to_bytes:
+ cmakeCommand.write(encoded_payload)
+ else:
+ for c in encoded_payload:
+ if has_to_bytes:
+ c = c.to_bytes(1, byteorder='big')
+ cmakeCommand.write(c)
+
writeRawData.counter = 0
def writePayload(cmakeCommand, obj):
writeRawData(cmakeCommand, json.dumps(obj))
-def initProc(cmakeCommand):
- cmakeCommand = subprocess.Popen([cmakeCommand, "-E", "server", "--experimental", "--debug"],
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE)
+def getPipeName():
+ return "/tmp/server-test-socket"
+
+def attachPipe(cmakeCommand, pipeName):
+ time.sleep(1)
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.connect(pipeName)
+ global serverTag
+ serverTag = "SERVER(PIPE)"
+ cmakeCommand.outPipe = sock.makefile()
+ cmakeCommand.inPipe = sock
+ cmakeCommand.write = cmakeCommand.inPipe.sendall
+
+def writeAndFlush(pipe, val):
+ pipe.write(val)
+ pipe.flush()
+
+def initServerProc(cmakeCommand, comm):
+ if comm == PIPE:
+ pipeName = getPipeName()
+ cmakeCommand = subprocess.Popen([cmakeCommand, "-E", "server", "--experimental", "--pipe=" + pipeName])
+ attachPipe(cmakeCommand, pipeName)
+ else:
+ cmakeCommand = subprocess.Popen([cmakeCommand, "-E", "server", "--experimental", "--debug"],
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE)
+ cmakeCommand.outPipe = cmakeCommand.stdout
+ cmakeCommand.inPipe = cmakeCommand.stdin
+ cmakeCommand.write = lambda val: writeAndFlush(cmakeCommand.inPipe, val)
packet = waitForRawMessage(cmakeCommand)
if packet == None:
print("Not in server mode")
- sys.exit(1)
+ sys.exit(2)
if packet['type'] != 'hello':
print("No hello message")
- sys.exit(1)
+ sys.exit(3)
return cmakeCommand
+def exitProc(cmakeCommand):
+ # Tell the server to exit.
+ cmakeCommand.stdin.close()
+ cmakeCommand.stdout.close()
+
+ # Wait for the server to exit.
+ # If this version of python supports it, terminate the server after a timeout.
+ try:
+ cmakeCommand.wait(timeout=5)
+ except TypeError:
+ cmakeCommand.wait()
+ except:
+ cmakeCommand.terminate()
+ raise
+
def waitForMessage(cmakeCommand, expected):
data = ordered(expected)
packet = ordered(waitForRawMessage(cmakeCommand))
if packet != data:
- sys.exit(-1)
+ print ("Received unexpected message; test failed")
+ exitWithError(cmakeCommand)
return packet
def waitForReply(cmakeCommand, originalType, cookie, skipProgress):
@@ -109,25 +220,27 @@ def waitForReply(cmakeCommand, originalType, cookie, skipProgress):
packet = waitForRawMessage(cmakeCommand)
t = packet['type']
if packet['cookie'] != cookie or packet['inReplyTo'] != originalType:
- sys.exit(1)
+ print("cookie or inReplyTo mismatch")
+ sys.exit(4)
if t == 'message' or t == 'progress':
if skipProgress:
continue
if t == 'reply':
break
- sys.exit(1)
+ print("Unrecognized message", packet)
+ sys.exit(5)
return packet
def waitForError(cmakeCommand, originalType, cookie, message):
packet = waitForRawMessage(cmakeCommand)
if packet['cookie'] != cookie or packet['type'] != 'error' or packet['inReplyTo'] != originalType or packet['errorMessage'] != message:
- sys.exit(1)
+ sys.exit(6)
def waitForProgress(cmakeCommand, originalType, cookie, current, message):
packet = waitForRawMessage(cmakeCommand)
if packet['cookie'] != cookie or packet['type'] != 'progress' or packet['inReplyTo'] != originalType or packet['progressCurrent'] != current or packet['progressMessage'] != message:
- sys.exit(1)
+ sys.exit(7)
def handshake(cmakeCommand, major, minor, source, build, generator, extraGenerator):
version = { 'major': major }
@@ -152,9 +265,9 @@ def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data):
versionString = version['string']
vs = str(version['major']) + '.' + str(version['minor']) + '.' + str(version['patch'])
if (versionString != vs and not versionString.startswith(vs + '-')):
- sys.exit(1)
+ sys.exit(8)
if (versionString != cmakeVersion):
- sys.exit(1)
+ sys.exit(9)
# validate generators:
generatorObjects = capabilities['generators']
@@ -163,6 +276,10 @@ def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data):
index = cmakeoutput.index('\nGenerators\n\n')
cmakeGenerators = []
for line in cmakeoutput[index + 12:].splitlines():
+ if not line:
+ continue
+ if line[0] == '*': # default generator marker
+ line = ' ' + line[1:]
if not line.startswith(' '):
continue
if line.startswith(' '):
@@ -175,7 +292,7 @@ def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data):
tmp = line.strip()
if tmp.endswith(" [arch]"):
tmp = tmp[0:len(tmp) - 7]
- if (len(tmp) > 0) and (" - " not in tmp) and (tmp != 'KDevelop3'):
+ if (len(tmp) > 0) and (" - " not in tmp):
cmakeGenerators.append(tmp)
generators = []
@@ -187,13 +304,77 @@ def validateGlobalSettings(cmakeCommand, cmakeCommandPath, data):
for gen in cmakeGenerators:
if (not gen in generators):
- sys.exit(1)
+ sys.exit(10)
gen = packet['generator']
if (gen != '' and not (gen in generators)):
- sys.exit(1)
+ sys.exit(11)
for i in data:
print("Validating", i)
if (packet[i] != data[i]):
+ sys.exit(12)
+
+def validateCache(cmakeCommand, data):
+ packet = waitForReply(cmakeCommand, 'cache', '', False)
+
+ cache = packet['cache']
+
+ if (data['isEmpty']):
+ if (cache != []):
+ print('Expected empty cache, but got data.\n')
sys.exit(1)
+ return;
+
+ if (cache == []):
+ print('Expected cache contents, but got none.\n')
+ sys.exit(1)
+
+ hadHomeDir = False
+ for value in cache:
+ if (value['key'] == 'CMAKE_HOME_DIRECTORY'):
+ hadHomeDir = True
+
+ if (not hadHomeDir):
+ print('No CMAKE_HOME_DIRECTORY found in cache.')
+ sys.exit(1)
+
+def handleBasicMessage(proc, obj, debug):
+ if 'sendRaw' in obj:
+ data = obj['sendRaw']
+ if debug: print("Sending raw:", data)
+ writeRawData(proc, data)
+ return True
+ elif 'send' in obj:
+ data = obj['send']
+ if debug: print("Sending:", json.dumps(data))
+ writePayload(proc, data)
+ return True
+ elif 'recv' in obj:
+ data = obj['recv']
+ if debug: print("Waiting for:", json.dumps(data))
+ waitForMessage(proc, data)
+ return True
+ elif 'message' in obj:
+ print("MESSAGE:", obj["message"])
+ sys.stdout.flush()
+ return True
+ return False
+
+def shutdownProc(proc):
+ # Tell the server to exit.
+ proc.inPipe.close()
+ proc.outPipe.close()
+
+ # Wait for the server to exit.
+ # If this version of python supports it, terminate the server after a timeout.
+ try:
+ proc.wait(timeout=5)
+ except TypeError:
+ proc.wait()
+ except:
+ proc.terminate()
+ raise
+
+ print('cmake-server exited: %d' % proc.returncode)
+ sys.exit(proc.returncode)
diff --git a/Tests/Server/server-test.py b/Tests/Server/server-test.py
index 62d9008b2..701c6e945 100644
--- a/Tests/Server/server-test.py
+++ b/Tests/Server/server-test.py
@@ -9,7 +9,7 @@ sourceDir = sys.argv[3]
buildDir = sys.argv[4] + "/" + os.path.splitext(os.path.basename(testFile))[0]
cmakeGenerator = sys.argv[5]
-print("Test:", testFile,
+print("Server Test:", testFile,
"\n-- SourceDir:", sourceDir,
"\n-- BuildDir:", buildDir,
"\n-- Generator:", cmakeGenerator)
@@ -17,104 +17,89 @@ print("Test:", testFile,
if os.path.exists(buildDir):
shutil.rmtree(buildDir)
-proc = cmakelib.initProc(cmakeCommand)
+cmakelib.filterBase = sourceDir
with open(testFile) as f:
testData = json.loads(f.read())
-for obj in testData:
- if 'sendRaw' in obj:
- data = obj['sendRaw']
- if debug: print("Sending raw:", data)
- cmakelib.writeRawData(proc, data)
- elif 'send' in obj:
- data = obj['send']
- if debug: print("Sending:", json.dumps(data))
- cmakelib.writePayload(proc, data)
- elif 'recv' in obj:
- data = obj['recv']
- if debug: print("Waiting for:", json.dumps(data))
- cmakelib.waitForMessage(proc, data)
- elif 'reply' in obj:
- data = obj['reply']
- if debug: print("Waiting for reply:", json.dumps(data))
- originalType = ""
- cookie = ""
- skipProgress = False;
- if 'cookie' in data: cookie = data['cookie']
- if 'type' in data: originalType = data['type']
- if 'skipProgress' in data: skipProgress = data['skipProgress']
- cmakelib.waitForReply(proc, originalType, cookie, skipProgress)
- elif 'error' in obj:
- data = obj['error']
- if debug: print("Waiting for error:", json.dumps(data))
- originalType = ""
- cookie = ""
- message = ""
- if 'cookie' in data: cookie = data['cookie']
- if 'type' in data: originalType = data['type']
- if 'message' in data: message = data['message']
- cmakelib.waitForError(proc, originalType, cookie, message)
- elif 'progress' in obj:
- data = obj['progress']
- if debug: print("Waiting for progress:", json.dumps(data))
- originalType = ''
- cookie = ""
- current = 0
- message = ""
- if 'cookie' in data: cookie = data['cookie']
- if 'type' in data: originalType = data['type']
- if 'current' in data: current = data['current']
- if 'message' in data: message = data['message']
- cmakelib.waitForProgress(proc, originalType, cookie, current, message)
- elif 'handshake' in obj:
- data = obj['handshake']
- if debug: print("Doing handshake:", json.dumps(data))
- major = -1
- minor = -1
- generator = cmakeGenerator
- extraGenerator = ''
- sourceDirectory = sourceDir
- buildDirectory = buildDir
- if 'major' in data: major = data['major']
- if 'minor' in data: minor = data['minor']
- if 'buildDirectory' in data: buildDirectory = data['buildDirectory']
- if 'sourceDirectory' in data: sourceDirectory = data['sourceDirectory']
- if 'generator' in data: generator = data['generator']
- if 'extraGenerator' in data: extraGenerator = data['extraGenerator']
- if not os.path.isabs(buildDirectory):
- buildDirectory = buildDir + "/" + buildDirectory
- if not os.path.isabs(sourceDirectory):
- sourceDirectory = sourceDir + "/" + sourceDirectory
- cmakelib.handshake(proc, major, minor, sourceDirectory, buildDirectory,
- generator, extraGenerator)
- elif 'validateGlobalSettings' in obj:
- data = obj['validateGlobalSettings']
- if not 'buildDirectory' in data: data['buildDirectory'] = buildDir
- if not 'sourceDirectory' in data: data['sourceDirectory'] = sourceDir
- if not 'generator' in data: data['generator'] = cmakeGenerator
- if not 'extraGenerator' in data: data['extraGenerator'] = ''
- cmakelib.validateGlobalSettings(proc, cmakeCommand, data)
- elif 'message' in obj:
- print("MESSAGE:", obj["message"])
- else:
- print("Unknown command:", json.dumps(obj))
- sys.exit(2)
+for communicationMethod in cmakelib.communicationMethods:
+ proc = cmakelib.initServerProc(cmakeCommand, communicationMethod)
+ if proc is None:
+ continue
- print("Completed")
-
-# Tell the server to exit.
-proc.stdin.close()
-proc.stdout.close()
+ for obj in testData:
+ if cmakelib.handleBasicMessage(proc, obj, debug):
+ pass
+ elif 'reply' in obj:
+ data = obj['reply']
+ if debug: print("Waiting for reply:", json.dumps(data))
+ originalType = ""
+ cookie = ""
+ skipProgress = False;
+ if 'cookie' in data: cookie = data['cookie']
+ if 'type' in data: originalType = data['type']
+ if 'skipProgress' in data: skipProgress = data['skipProgress']
+ cmakelib.waitForReply(proc, originalType, cookie, skipProgress)
+ elif 'error' in obj:
+ data = obj['error']
+ if debug: print("Waiting for error:", json.dumps(data))
+ originalType = ""
+ cookie = ""
+ message = ""
+ if 'cookie' in data: cookie = data['cookie']
+ if 'type' in data: originalType = data['type']
+ if 'message' in data: message = data['message']
+ cmakelib.waitForError(proc, originalType, cookie, message)
+ elif 'progress' in obj:
+ data = obj['progress']
+ if debug: print("Waiting for progress:", json.dumps(data))
+ originalType = ''
+ cookie = ""
+ current = 0
+ message = ""
+ if 'cookie' in data: cookie = data['cookie']
+ if 'type' in data: originalType = data['type']
+ if 'current' in data: current = data['current']
+ if 'message' in data: message = data['message']
+ cmakelib.waitForProgress(proc, originalType, cookie, current, message)
+ elif 'handshake' in obj:
+ data = obj['handshake']
+ if debug: print("Doing handshake:", json.dumps(data))
+ major = -1
+ minor = -1
+ generator = cmakeGenerator
+ extraGenerator = ''
+ sourceDirectory = sourceDir
+ buildDirectory = buildDir
+ if 'major' in data: major = data['major']
+ if 'minor' in data: minor = data['minor']
+ if 'buildDirectory' in data: buildDirectory = data['buildDirectory']
+ if 'sourceDirectory' in data: sourceDirectory = data['sourceDirectory']
+ if 'generator' in data: generator = data['generator']
+ if 'extraGenerator' in data: extraGenerator = data['extraGenerator']
-# Wait for the server to exit.
-# If this version of python supports it, terminate the server after a timeout.
-try:
- proc.wait(timeout=5)
-except TypeError:
- proc.wait()
-except:
- proc.terminate()
- raise
-
-sys.exit(0)
+ if not os.path.isabs(buildDirectory):
+ buildDirectory = buildDir + "/" + buildDirectory
+ if sourceDirectory != '' and not os.path.isabs(sourceDirectory):
+ sourceDirectory = sourceDir + "/" + sourceDirectory
+ cmakelib.handshake(proc, major, minor, sourceDirectory, buildDirectory,
+ generator, extraGenerator)
+ elif 'validateGlobalSettings' in obj:
+ data = obj['validateGlobalSettings']
+ if not 'buildDirectory' in data: data['buildDirectory'] = buildDir
+ if not 'sourceDirectory' in data: data['sourceDirectory'] = sourceDir
+ if not 'generator' in data: data['generator'] = cmakeGenerator
+ if not 'extraGenerator' in data: data['extraGenerator'] = ''
+ cmakelib.validateGlobalSettings(proc, cmakeCommand, data)
+ elif 'validateCache' in obj:
+ data = obj['validateCache']
+ if not 'isEmpty' in data: data['isEmpty'] = false
+ cmakelib.validateCache(proc, data)
+ elif 'reconnect' in obj:
+ cmakelib.exitProc(proc)
+ proc = cmakelib.initServerProc(cmakeCommand, communicationMethod)
+ else:
+ print("Unknown command:", json.dumps(obj))
+ sys.exit(2)
+ cmakelib.shutdownProc(proc)
+ print("Completed")
diff --git a/Tests/Server/tc_handshake.json b/Tests/Server/tc_handshake.json
index 975bb3d32..4bb7fa7ac 100644
--- a/Tests/Server/tc_handshake.json
+++ b/Tests/Server/tc_handshake.json
@@ -11,6 +11,10 @@
{ "send": {"test": "sometext","cookie":"monster"} },
{ "recv": {"cookie":"monster","errorMessage":"No type given in request.","inReplyTo":"","type":"error"} },
+{ "message": "Testing commands before handshake" },
+{ "send": {"type": "cache","cookie":"monster"} },
+{ "recv": {"cookie":"monster","errorMessage":"Waiting for type \"handshake\".","inReplyTo":"cache","type":"error"} },
+
{ "message": "Testing handshake" },
{ "send": {"type": "sometype","cookie":"monster2"} },
{ "recv": {"cookie":"monster2","errorMessage":"Waiting for type \"handshake\".","inReplyTo":"sometype","type":"error"} },
diff --git a/Tests/SourceGroups/CMakeLists.txt b/Tests/SourceGroups/CMakeLists.txt
index 4e4a030ce..a5740bba9 100644
--- a/Tests/SourceGroups/CMakeLists.txt
+++ b/Tests/SourceGroups/CMakeLists.txt
@@ -39,9 +39,23 @@ set(tree_files_without_prefix ${root}/sub1/tree_bar.c
set(tree_files_with_prefix ${root}/tree_prefix_foo.c
tree_prefix_bar.c)
+set(tree_files_with_empty_prefix ${root}/tree_empty_prefix_foo.c
+ tree_empty_prefix_bar.c)
+
+set(tree_files_which_are_actually_directories ${root}
+ ${root}/
+ ${root}/sub1
+ ${root}/sub1/)
+
source_group(TREE ${root} FILES ${tree_files_without_prefix})
-source_group(TREE ${root} PREFIX tree_root/subgroup FILES ${tree_files_with_prefix})
+# Should not crash and not add any files - just silently ignore the directories
+source_group(TREE ${root} FILES ${tree_files_which_are_actually_directories})
+
+source_group(FILES ${tree_files_with_prefix} PREFIX tree_root/subgroup TREE ${root})
+
+source_group(PREFIX "" FILES ${tree_files_with_empty_prefix} TREE ${root})
add_executable(SourceGroups main.c bar.c foo.c sub1/foo.c sub1/foobar.c baz.c
- ${tree_files_with_prefix} ${tree_files_without_prefix} README.txt)
+ ${tree_files_with_prefix} ${tree_files_without_prefix}
+ ${tree_files_with_empty_prefix} README.txt)
diff --git a/Tests/SourceGroups/main.c b/Tests/SourceGroups/main.c
index 4d84cf20e..87225f546 100644
--- a/Tests/SourceGroups/main.c
+++ b/Tests/SourceGroups/main.c
@@ -7,6 +7,8 @@ extern int barbar(void);
extern int baz(void);
extern int tree_prefix_foo(void);
extern int tree_prefix_bar(void);
+extern int tree_empty_prefix_foo(void);
+extern int tree_empty_prefix_bar(void);
extern int tree_bar(void);
extern int tree_foobar(void);
extern int tree_baz(void);
@@ -17,8 +19,9 @@ int main()
foobar(), barbar(), baz());
printf("tree_prefix_foo: %d tree_prefix_bar: %d tree_bar: %d tree_foobar: "
- "%d tree_baz: %d\n",
+ "%d tree_baz: %d tree_empty_prefix_foo: %d "
+ "tree_empty_prefix_bar: %d\n",
tree_prefix_foo(), tree_prefix_bar(), tree_bar(), tree_foobar(),
- tree_baz());
+ tree_baz(), tree_empty_prefix_foo(), tree_empty_prefix_bar());
return 0;
}
diff --git a/Tests/StagingPrefix/CMakeLists.txt b/Tests/StagingPrefix/CMakeLists.txt
index 49ff7fee7..8d2519ea3 100644
--- a/Tests/StagingPrefix/CMakeLists.txt
+++ b/Tests/StagingPrefix/CMakeLists.txt
@@ -1,15 +1,16 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.9)
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
+ COMMAND ${CMAKE_COMMAND} -E remove_directory
+ ${CMAKE_BINARY_DIR}/ConsumerBuild
+ ${CMAKE_BINARY_DIR}/ProducerBuild
+ ${CMAKE_BINARY_DIR}/stage
+ ${CMAKE_BINARY_DIR}/prefix
+ ${CMAKE_BINARY_DIR}/ignored
)
add_custom_target(CleanupTarget ALL DEPENDS ${CMAKE_BINARY_DIR}/CleanupProject)
set_property(
@@ -17,7 +18,8 @@ set_property(
PROPERTY SYMBOLIC 1
)
-if(CMAKE_CONFIGURATION_TYPES)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
else()
if(CMAKE_BUILD_TYPE)
diff --git a/Tests/SubDir/Executable/test.cxx b/Tests/SubDir/Executable/test.cxx
index 06aed018b..01d928085 100644
--- a/Tests/SubDir/Executable/test.cxx
+++ b/Tests/SubDir/Executable/test.cxx
@@ -1,19 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
-#include <io.h>
+# include <io.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
// return true if the file exists
int FileExists(const char* filename)
{
#ifdef _MSC_VER
-#define access _access
+# define access _access
#endif
#ifndef F_OK
-#define F_OK 0
+# define F_OK 0
#endif
if (access(filename, F_OK) != 0) {
return false;
diff --git a/Tests/SubDirSpaces/CMakeLists.txt b/Tests/SubDirSpaces/CMakeLists.txt
index 40c265e5f..0d45db85c 100644
--- a/Tests/SubDirSpaces/CMakeLists.txt
+++ b/Tests/SubDirSpaces/CMakeLists.txt
@@ -2,7 +2,7 @@ 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")
+if(CMAKE_SYSTEM_NAME MATCHES "QNX")
set(CMAKE_SKIP_BUILD_RPATH 1)
endif()
diff --git a/Tests/SubDirSpaces/Executable Sources/test.cxx b/Tests/SubDirSpaces/Executable Sources/test.cxx
index 06aed018b..01d928085 100644
--- a/Tests/SubDirSpaces/Executable Sources/test.cxx
+++ b/Tests/SubDirSpaces/Executable Sources/test.cxx
@@ -1,19 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
-#include <io.h>
+# include <io.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
// return true if the file exists
int FileExists(const char* filename)
{
#ifdef _MSC_VER
-#define access _access
+# define access _access
#endif
#ifndef F_OK
-#define F_OK 0
+# define F_OK 0
#endif
if (access(filename, F_OK) != 0) {
return false;
diff --git a/Tests/SubDirSpaces/Executable/test.cxx b/Tests/SubDirSpaces/Executable/test.cxx
index 06aed018b..01d928085 100644
--- a/Tests/SubDirSpaces/Executable/test.cxx
+++ b/Tests/SubDirSpaces/Executable/test.cxx
@@ -1,19 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
-#include <io.h>
+# include <io.h>
#else
-#include <unistd.h>
+# include <unistd.h>
#endif
// return true if the file exists
int FileExists(const char* filename)
{
#ifdef _MSC_VER
-#define access _access
+# define access _access
#endif
#ifndef F_OK
-#define F_OK 0
+# define F_OK 0
#endif
if (access(filename, F_OK) != 0) {
return false;
diff --git a/Tests/SwiftMix/CMain.c b/Tests/SwiftMix/CMain.c
index 8877da430..519058efe 100644
--- a/Tests/SwiftMix/CMain.c
+++ b/Tests/SwiftMix/CMain.c
@@ -1,5 +1,5 @@
-extern int ObjCMain(int argc, char const* const argv[]);
-int main(int argc, char* argv[])
+extern int ObjCMain(void);
+int main(void)
{
- return ObjCMain(argc, argv);
+ return ObjCMain();
}
diff --git a/Tests/SwiftMix/CMakeLists.txt b/Tests/SwiftMix/CMakeLists.txt
index 5e50470f6..6d8e48bd0 100644
--- a/Tests/SwiftMix/CMakeLists.txt
+++ b/Tests/SwiftMix/CMakeLists.txt
@@ -3,3 +3,4 @@ project(SwiftMix C Swift)
add_executable(SwiftMix CMain.c ObjCMain.m SwiftMain.swift ObjC-Swift.h)
set_property(TARGET SwiftMix PROPERTY XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "ObjC-Swift.h")
+target_compile_options(SwiftMix PRIVATE "$<$<COMPILE_LANGUAGE:C>:-Werror=objc-method-access>")
diff --git a/Tests/SwiftMix/ObjCMain.m b/Tests/SwiftMix/ObjCMain.m
index 20f0bf1ee..afc924380 100644
--- a/Tests/SwiftMix/ObjCMain.m
+++ b/Tests/SwiftMix/ObjCMain.m
@@ -1,4 +1,4 @@
#import "SwiftMix-Swift.h"
-int ObjCMain(int argc, char const* const argv[]) {
+int ObjCMain(void) {
return [SwiftMainClass SwiftMain];
}
diff --git a/Tests/SwiftMix/SwiftMain.swift b/Tests/SwiftMix/SwiftMain.swift
index a4a0a62b4..d9c8cd756 100644
--- a/Tests/SwiftMix/SwiftMain.swift
+++ b/Tests/SwiftMix/SwiftMain.swift
@@ -1,7 +1,7 @@
import Foundation
@objc class SwiftMainClass : NSObject {
- class func SwiftMain() -> Int32 {
+ @objc class func SwiftMain() -> Int32 {
dump("Hello World!");
return 0;
}
diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt
index cf4463ccf..f4cbac212 100644
--- a/Tests/SwiftOnly/CMakeLists.txt
+++ b/Tests/SwiftOnly/CMakeLists.txt
@@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 3.3)
project(SwiftOnly Swift)
-if(NOT XCODE_VERSION VERSION_LESS 8.0)
+if(NOT XCODE_VERSION VERSION_LESS 10.2)
+ set(CMAKE_Swift_LANGUAGE_VERSION 5.0)
+elseif(NOT XCODE_VERSION VERSION_LESS 8.0)
set(CMAKE_Swift_LANGUAGE_VERSION 3.0)
endif()
add_executable(SwiftOnly main.swift)
+
+# Dummy to make sure generation works with such targets.
+add_library(SwiftIface INTERFACE)
diff --git a/Tests/TestsWorkingDirectory/main.c b/Tests/TestsWorkingDirectory/main.c
index 11dd4ff7c..8755c0ef3 100644
--- a/Tests/TestsWorkingDirectory/main.c
+++ b/Tests/TestsWorkingDirectory/main.c
@@ -3,16 +3,17 @@
#include <stdlib.h>
#include <string.h>
-#if defined(_WIN32) && (defined(_MSC_VER) || defined(__WATCOMC__) || \
- defined(__BORLANDC__) || defined(__MINGW32__))
+#if defined(_WIN32) && \
+ (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || \
+ defined(__MINGW32__))
-#include <direct.h>
-#include <io.h>
+# include <direct.h>
+# include <io.h>
-#if defined(__WATCOMC__)
-#include <direct.h>
-#define _getcwd getcwd
-#endif
+# if defined(__WATCOMC__)
+# include <direct.h>
+# define _getcwd getcwd
+# endif
static const char* Getcwd(char* buf, unsigned int len)
{
@@ -35,9 +36,9 @@ static const char* Getcwd(char* buf, unsigned int len)
}
#else
-#include <fcntl.h>
-#include <sys/types.h>
-#include <unistd.h>
+# include <fcntl.h>
+# include <sys/types.h>
+# include <unistd.h>
static const char* Getcwd(char* buf, unsigned int len)
{
diff --git a/Tests/TryCompile/CMakeLists.txt b/Tests/TryCompile/CMakeLists.txt
index 2f8e4fb3c..54e96a208 100644
--- a/Tests/TryCompile/CMakeLists.txt
+++ b/Tests/TryCompile/CMakeLists.txt
@@ -165,6 +165,35 @@ try_compile(TEST_INNER
OUTPUT_VARIABLE output)
TEST_ASSERT(TEST_INNER "try_compile project mode failed:\n${output}")
+try_compile(COMPILE_DEFINITIONS_LIST_EXPANDED
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/check_a_b.c
+ OUTPUT_VARIABLE output
+ COMPILE_DEFINITIONS "-DDEF_A;-DDEF_B"
+ )
+if(COMPILE_DEFINITIONS_LIST_EXPANDED)
+ message(STATUS "COMPILE_DEFINITIONS list expanded correctly")
+else()
+ string(REPLACE "\n" "\n " output " ${output}")
+ message(SEND_ERROR "COMPILE_DEFINITIONS list did not expand correctly\n${output}")
+endif()
+
+try_compile(SHOULD_FAIL_DUE_TO_BAD_SOURCE
+ ${TryCompile_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp
+ ${TryCompile_SOURCE_DIR}/pass.c
+ OUTPUT_VARIABLE output
+ COMPILE_DEFINITIONS "bad#source.c"
+ )
+if(SHOULD_FAIL_DUE_TO_BAD_SOURCE AND NOT CMAKE_GENERATOR MATCHES "Watcom WMake|NMake Makefiles")
+ string(REPLACE "\n" "\n " output " ${output}")
+ message(SEND_ERROR "try_compile with bad#source.c did not fail:\n${output}")
+elseif(NOT output MATCHES [[(bad#source\.c|bad\\)]])
+ string(REPLACE "\n" "\n " output " ${output}")
+ message(SEND_ERROR "try_compile with bad#source.c failed without mentioning bad source:\n${output}")
+else()
+ message(STATUS "try_compile with bad#source.c correctly failed")
+endif()
+
add_executable(TryCompile pass.c)
######################################
@@ -242,7 +271,7 @@ include(CheckCXXSourceCompiles)
include(CheckCSourceRuns)
include(CheckCXXSourceRuns)
-CHECK_C_SOURCE_COMPILES("I dont build" C_BUILD_SHOULD_FAIL)
+CHECK_C_SOURCE_COMPILES("I don't 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)
@@ -252,7 +281,7 @@ 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("I don't 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)
diff --git a/Tests/TryCompile/testdef.c b/Tests/TryCompile/testdef.c
index b05f070d0..72301dd4e 100644
--- a/Tests/TryCompile/testdef.c
+++ b/Tests/TryCompile/testdef.c
@@ -1,5 +1,5 @@
#ifndef TESTDEF
-#error "TESTDEF should be defined!"
+# error "TESTDEF should be defined!"
#endif
int main(void)
{
diff --git a/Tests/Tutorial/Step1/CMakeLists.txt b/Tests/Tutorial/Step1/CMakeLists.txt
index e461d3c8b..141f0c27a 100644
--- a/Tests/Tutorial/Step1/CMakeLists.txt
+++ b/Tests/Tutorial/Step1/CMakeLists.txt
@@ -1,20 +1,3 @@
-cmake_minimum_required (VERSION 2.6)
-project (Tutorial)
+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/tutorial.cxx b/Tests/Tutorial/Step1/tutorial.cxx
index 7a13376cb..f8dd0c6c8 100644
--- a/Tests/Tutorial/Step1/tutorial.cxx
+++ b/Tests/Tutorial/Step1/tutorial.cxx
@@ -1,19 +1,20 @@
// A simple program that computes the square root of a number
-#include "TutorialConfig.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdlib>
+#include <iostream>
+#include <string>
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]);
+ std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
+
double inputValue = atof(argv[1]);
+
double outputValue = sqrt(inputValue);
- fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
+ std::cout << "The square root of " << inputValue << " is " << outputValue
+ << std::endl;
return 0;
}
diff --git a/Tests/Tutorial/Step2/CMakeLists.txt b/Tests/Tutorial/Step2/CMakeLists.txt
index cf1d30ee2..48afaa327 100644
--- a/Tests/Tutorial/Step2/CMakeLists.txt
+++ b/Tests/Tutorial/Step2/CMakeLists.txt
@@ -1,31 +1,25 @@
-cmake_minimum_required (VERSION 2.6)
-project (Tutorial)
+cmake_minimum_required(VERSION 3.3)
+project(Tutorial)
-# The version number.
-set (Tutorial_VERSION_MAJOR 1)
-set (Tutorial_VERSION_MINOR 0)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
-# should we use our own math functions
-option(USE_MYMATH "Use tutorial provided math implementation" ON)
+# 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 (
+configure_file(
"${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
"${PROJECT_BINARY_DIR}/TutorialConfig.h"
)
+# add the executable
+add_executable(Tutorial tutorial.cxx)
+
# 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})
+target_include_directories(Tutorial PUBLIC
+ "${PROJECT_BINARY_DIR}"
+ )
diff --git a/Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx
index 2710f9220..7d9379e43 100644
--- a/Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx
+++ b/Tests/Tutorial/Step2/MathFunctions/mysqrt.cxx
@@ -1,5 +1,5 @@
#include "MathFunctions.h"
-#include <stdio.h>
+#include <iostream>
// a hack square root calculation using simple operations
double mysqrt(double x)
@@ -8,19 +8,16 @@ double mysqrt(double x)
return 0;
}
- double result;
- double delta;
- result = x;
+ double result = x;
// do ten iterations
- int i;
- for (i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
- delta = x - (result * result);
+ double delta = x - (result * result);
result = result + 0.5 * delta / result;
- fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result);
+ std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
return result;
}
diff --git a/Tests/Tutorial/Step2/TutorialConfig.h.in b/Tests/Tutorial/Step2/TutorialConfig.h.in
index 25a06020a..5395a0671 100644
--- a/Tests/Tutorial/Step2/TutorialConfig.h.in
+++ b/Tests/Tutorial/Step2/TutorialConfig.h.in
@@ -1,5 +1,4 @@
// 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
index 2fae364d4..75b7d67b0 100644
--- a/Tests/Tutorial/Step2/tutorial.cxx
+++ b/Tests/Tutorial/Step2/tutorial.cxx
@@ -1,33 +1,23 @@
// A simple program that computes the square root of a number
-#include "TutorialConfig.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cmath>
+#include <iostream>
+#include <string>
-#ifdef USE_MYMATH
-#include "MathFunctions.h"
-#endif
+#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]);
+ std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
+ << Tutorial_VERSION_MAJOR << std::endl;
+ std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
- double inputValue = atof(argv[1]);
- double outputValue = 0;
-
- if (inputValue >= 0) {
-#ifdef USE_MYMATH
- outputValue = mysqrt(inputValue);
-#else
- outputValue = sqrt(inputValue);
-#endif
- }
+ double inputValue = std::stod(argv[1]);
- fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
+ double outputValue = sqrt(inputValue);
+ std::cout << "The square root of " << inputValue << " is " << outputValue
+ << std::endl;
return 0;
}
diff --git a/Tests/Tutorial/Step3/CMakeLists.txt b/Tests/Tutorial/Step3/CMakeLists.txt
index 762302bc5..f904ea748 100644
--- a/Tests/Tutorial/Step3/CMakeLists.txt
+++ b/Tests/Tutorial/Step3/CMakeLists.txt
@@ -1,68 +1,38 @@
-cmake_minimum_required (VERSION 2.6)
-project (Tutorial)
+cmake_minimum_required(VERSION 3.3)
+project(Tutorial)
-# The version number.
-set (Tutorial_VERSION_MAJOR 1)
-set (Tutorial_VERSION_MINOR 0)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
+# 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 (
+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 ()
+if(USE_MYMATH)
+ add_subdirectory(MathFunctions)
+ list(APPEND EXTRA_LIBS MathFunctions)
+ list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions")
+endif(USE_MYMATH)
# 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)
+add_executable(Tutorial tutorial.cxx)
-# 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"
- )
+target_link_libraries(Tutorial ${EXTRA_LIBS})
-# does the usage message work?
-add_test (TutorialUsage Tutorial)
-set_tests_properties (TutorialUsage
- PROPERTIES
- PASS_REGULAR_EXPRESSION "Usage:.*number"
- )
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+target_include_directories(Tutorial PUBLIC
+ "${PROJECT_BINARY_DIR}"
+ ${EXTRA_INCLUDES}
+ )
diff --git a/Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt
index f386036c3..8b443a659 100644
--- a/Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt
+++ b/Tests/Tutorial/Step3/MathFunctions/CMakeLists.txt
@@ -1,4 +1 @@
add_library(MathFunctions mysqrt.cxx)
-
-install (TARGETS MathFunctions DESTINATION bin)
-install (FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx
index 2710f9220..7d9379e43 100644
--- a/Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx
+++ b/Tests/Tutorial/Step3/MathFunctions/mysqrt.cxx
@@ -1,5 +1,5 @@
#include "MathFunctions.h"
-#include <stdio.h>
+#include <iostream>
// a hack square root calculation using simple operations
double mysqrt(double x)
@@ -8,19 +8,16 @@ double mysqrt(double x)
return 0;
}
- double result;
- double delta;
- result = x;
+ double result = x;
// do ten iterations
- int i;
- for (i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
- delta = x - (result * result);
+ double delta = x - (result * result);
result = result + 0.5 * delta / result;
- fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result);
+ std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
return result;
}
diff --git a/Tests/Tutorial/Step3/tutorial.cxx b/Tests/Tutorial/Step3/tutorial.cxx
index 2fae364d4..1d5742d2d 100644
--- a/Tests/Tutorial/Step3/tutorial.cxx
+++ b/Tests/Tutorial/Step3/tutorial.cxx
@@ -1,33 +1,32 @@
// A simple program that computes the square root of a number
+#include <cmath>
+#include <iostream>
+#include <string>
+
#include "TutorialConfig.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
#ifdef USE_MYMATH
-#include "MathFunctions.h"
+# 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]);
+ std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
+ << Tutorial_VERSION_MAJOR << std::endl;
+ std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
- double inputValue = atof(argv[1]);
- double outputValue = 0;
+ double inputValue = std::stod(argv[1]);
- if (inputValue >= 0) {
#ifdef USE_MYMATH
- outputValue = mysqrt(inputValue);
+ double outputValue = mysqrt(inputValue);
#else
- outputValue = sqrt(inputValue);
+ double outputValue = sqrt(inputValue);
#endif
- }
- fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
+ std::cout << "The square root of " << inputValue << " is " << outputValue
+ << std::endl;
return 0;
}
diff --git a/Tests/Tutorial/Step4/CMakeLists.txt b/Tests/Tutorial/Step4/CMakeLists.txt
index 6994aa1ce..34eab5558 100644
--- a/Tests/Tutorial/Step4/CMakeLists.txt
+++ b/Tests/Tutorial/Step4/CMakeLists.txt
@@ -1,68 +1,36 @@
-cmake_minimum_required (VERSION 2.6)
-project (Tutorial)
+cmake_minimum_required(VERSION 3.3)
+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)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
+# 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 (
+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 ()
+if(USE_MYMATH)
+ add_subdirectory(MathFunctions)
+ list(APPEND EXTRA_LIBS MathFunctions)
+endif(USE_MYMATH)
# 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 ()
+add_executable(Tutorial tutorial.cxx)
-# 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")
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+target_include_directories(Tutorial PUBLIC
+ "${PROJECT_BINARY_DIR}"
+ )
diff --git a/Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt
index f386036c3..0515852a0 100644
--- a/Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt
+++ b/Tests/Tutorial/Step4/MathFunctions/CMakeLists.txt
@@ -1,4 +1,7 @@
add_library(MathFunctions mysqrt.cxx)
-install (TARGETS MathFunctions DESTINATION bin)
-install (FILES MathFunctions.h DESTINATION include)
+# state that anybody linking to us needs to include the current source dir
+# to find MathFunctions.h, while we don't.
+target_include_directories(MathFunctions
+ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+ )
diff --git a/Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx
index 6ca264f76..7d9379e43 100644
--- a/Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx
+++ b/Tests/Tutorial/Step4/MathFunctions/mysqrt.cxx
@@ -1,8 +1,5 @@
#include "MathFunctions.h"
-#include "TutorialConfig.h"
-#include <stdio.h>
-
-#include <math.h>
+#include <iostream>
// a hack square root calculation using simple operations
double mysqrt(double x)
@@ -11,26 +8,16 @@ double mysqrt(double x)
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;
+ double result = x;
// do ten iterations
- int i;
- for (i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
- delta = x - (result * result);
+ double delta = x - (result * result);
result = result + 0.5 * delta / result;
- fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result);
+ std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
-#endif
return result;
}
diff --git a/Tests/Tutorial/Step4/TutorialConfig.h.in b/Tests/Tutorial/Step4/TutorialConfig.h.in
index a0912656a..25a06020a 100644
--- a/Tests/Tutorial/Step4/TutorialConfig.h.in
+++ b/Tests/Tutorial/Step4/TutorialConfig.h.in
@@ -3,7 +3,3 @@
#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
index 2fae364d4..1d5742d2d 100644
--- a/Tests/Tutorial/Step4/tutorial.cxx
+++ b/Tests/Tutorial/Step4/tutorial.cxx
@@ -1,33 +1,32 @@
// A simple program that computes the square root of a number
+#include <cmath>
+#include <iostream>
+#include <string>
+
#include "TutorialConfig.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
#ifdef USE_MYMATH
-#include "MathFunctions.h"
+# 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]);
+ std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
+ << Tutorial_VERSION_MAJOR << std::endl;
+ std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
- double inputValue = atof(argv[1]);
- double outputValue = 0;
+ double inputValue = std::stod(argv[1]);
- if (inputValue >= 0) {
#ifdef USE_MYMATH
- outputValue = mysqrt(inputValue);
+ double outputValue = mysqrt(inputValue);
#else
- outputValue = sqrt(inputValue);
+ double outputValue = sqrt(inputValue);
#endif
- }
- fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
+ std::cout << "The square root of " << inputValue << " is " << outputValue
+ << std::endl;
return 0;
}
diff --git a/Tests/Tutorial/Step5/CMakeLists.txt b/Tests/Tutorial/Step5/CMakeLists.txt
index e40b676b4..63e541056 100644
--- a/Tests/Tutorial/Step5/CMakeLists.txt
+++ b/Tests/Tutorial/Step5/CMakeLists.txt
@@ -1,72 +1,70 @@
-cmake_minimum_required (VERSION 2.6)
-project (Tutorial)
+cmake_minimum_required(VERSION 3.3)
+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)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
+# 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 (
+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 ()
+if(USE_MYMATH)
+ add_subdirectory(MathFunctions)
+ list(APPEND EXTRA_LIBS MathFunctions)
+endif()
# add the executable
-add_executable (Tutorial tutorial.cxx)
-target_link_libraries (Tutorial ${EXTRA_LIBS})
+add_executable(Tutorial tutorial.cxx)
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+target_include_directories(Tutorial PUBLIC
+ "${PROJECT_BINARY_DIR}"
+ )
# add the install targets
-install (TARGETS Tutorial DESTINATION bin)
-install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
- DESTINATION include)
+install(TARGETS Tutorial DESTINATION bin)
+install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include
+ )
# enable testing
-enable_testing ()
+enable_testing()
# does the application run
-add_test (TutorialRuns Tutorial 25)
+add_test(NAME Runs COMMAND Tutorial 25)
# does the usage message work?
-add_test (TutorialUsage Tutorial)
-set_tests_properties (TutorialUsage
- PROPERTIES
- PASS_REGULAR_EXPRESSION "Usage:.*number"
+add_test(NAME Usage COMMAND Tutorial)
+set_tests_properties(Usage
+ 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}
+# define a function to simplify adding tests
+function(do_test target arg result)
+ add_test(NAME Comp${arg} COMMAND ${target} ${arg})
+ set_tests_properties(Comp${arg}
PROPERTIES PASS_REGULAR_EXPRESSION ${result}
)
-endmacro ()
+endfunction(do_test)
# 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")
-
+do_test(Tutorial 4 "4 is 2")
+do_test(Tutorial 9 "9 is 3")
+do_test(Tutorial 5 "5 is 2.236")
+do_test(Tutorial 7 "7 is 2.645")
+do_test(Tutorial 25 "25 is 5")
+do_test(Tutorial -25 "-25 is [-nan|nan|0]")
+do_test(Tutorial 0.0001 "0.0001 is 0.01")
diff --git a/Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt
index 453a46332..11cf4127b 100644
--- a/Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt
+++ b/Tests/Tutorial/Step5/MathFunctions/CMakeLists.txt
@@ -1,17 +1,10 @@
-# 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_library(MathFunctions mysqrt.cxx)
-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
- )
+# state that anybody linking to us needs to include the current source dir
+# to find MathFunctions.h, while we don't.
+target_include_directories(MathFunctions
+ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+ )
-# 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)
+install(TARGETS MathFunctions DESTINATION lib)
+install(FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx
index cebd50fcc..ee585568c 100644
--- a/Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx
+++ b/Tests/Tutorial/Step5/MathFunctions/MakeTable.cxx
@@ -1,32 +1,25 @@
// A simple program that builds a sqrt table
-#include <math.h>
-#include <stdio.h>
+#include <cmath>
+#include <fstream>
+#include <iostream>
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;
+ std::ofstream fout(argv[1], std::ios_base::out);
+ const bool fileOpen = fout.is_open();
+ if (fileOpen) {
+ fout << "double sqrtTable[] = {" << std::endl;
+ for (int i = 0; i < 10; ++i) {
+ fout << sqrt(static_cast<double>(i)) << "," << std::endl;
+ }
+ // close the table with a zero
+ fout << "0};" << std::endl;
+ fout.close();
}
-
- // 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;
+ return fileOpen ? 0 : 1; // return 0 if wrote the file
}
diff --git a/Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx
index 458ed63a1..7d9379e43 100644
--- a/Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx
+++ b/Tests/Tutorial/Step5/MathFunctions/mysqrt.cxx
@@ -1,11 +1,5 @@
#include "MathFunctions.h"
-#include "TutorialConfig.h"
-#include <stdio.h>
-
-// include the generated table
-#include "Table.h"
-
-#include <math.h>
+#include <iostream>
// a hack square root calculation using simple operations
double mysqrt(double x)
@@ -14,27 +8,16 @@ double mysqrt(double x)
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)];
- }
+ double result = x;
// do ten iterations
- int i;
- for (i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
- delta = x - (result * result);
+ double delta = x - (result * result);
result = result + 0.5 * delta / result;
- fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result);
+ std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
-
return result;
}
diff --git a/Tests/Tutorial/Step5/TutorialConfig.h.in b/Tests/Tutorial/Step5/TutorialConfig.h.in
index a0912656a..25a06020a 100644
--- a/Tests/Tutorial/Step5/TutorialConfig.h.in
+++ b/Tests/Tutorial/Step5/TutorialConfig.h.in
@@ -3,7 +3,3 @@
#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
index 2fae364d4..1d5742d2d 100644
--- a/Tests/Tutorial/Step5/tutorial.cxx
+++ b/Tests/Tutorial/Step5/tutorial.cxx
@@ -1,33 +1,32 @@
// A simple program that computes the square root of a number
+#include <cmath>
+#include <iostream>
+#include <string>
+
#include "TutorialConfig.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
#ifdef USE_MYMATH
-#include "MathFunctions.h"
+# 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]);
+ std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
+ << Tutorial_VERSION_MAJOR << std::endl;
+ std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
- double inputValue = atof(argv[1]);
- double outputValue = 0;
+ double inputValue = std::stod(argv[1]);
- if (inputValue >= 0) {
#ifdef USE_MYMATH
- outputValue = mysqrt(inputValue);
+ double outputValue = mysqrt(inputValue);
#else
- outputValue = sqrt(inputValue);
+ double outputValue = sqrt(inputValue);
#endif
- }
- fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
+ std::cout << "The square root of " << inputValue << " is " << outputValue
+ << std::endl;
return 0;
}
diff --git a/Tests/Tutorial/Step6/CMakeLists.txt b/Tests/Tutorial/Step6/CMakeLists.txt
index 0fb7cac5f..503a31290 100644
--- a/Tests/Tutorial/Step6/CMakeLists.txt
+++ b/Tests/Tutorial/Step6/CMakeLists.txt
@@ -1,78 +1,76 @@
-cmake_minimum_required (VERSION 2.6)
-project (Tutorial)
+cmake_minimum_required(VERSION 3.3)
+project(Tutorial)
-# The version number.
-set (Tutorial_VERSION_MAJOR 1)
-set (Tutorial_VERSION_MINOR 0)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
+
+# 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)
+include(CheckSymbolExists)
+set(CMAKE_REQUIRED_LIBRARIES "m")
+check_symbol_exists(log "math.h" HAVE_LOG)
+check_symbol_exists(exp "math.h" 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 (
+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 ()
+if(USE_MYMATH)
+ add_subdirectory(MathFunctions)
+ list(APPEND EXTRA_LIBS MathFunctions)
+endif()
# add the executable
-add_executable (Tutorial tutorial.cxx)
-target_link_libraries (Tutorial ${EXTRA_LIBS})
+add_executable(Tutorial tutorial.cxx)
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+target_include_directories(Tutorial PUBLIC
+ "${PROJECT_BINARY_DIR}"
+ )
# add the install targets
-install (TARGETS Tutorial DESTINATION bin)
-install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
- DESTINATION include)
+install(TARGETS Tutorial DESTINATION bin)
+install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include
+ )
# enable testing
-enable_testing ()
+enable_testing()
# does the application run
-add_test (TutorialRuns Tutorial 25)
+add_test(NAME Runs COMMAND Tutorial 25)
# does the usage message work?
-add_test (TutorialUsage Tutorial)
-set_tests_properties (TutorialUsage
- PROPERTIES
- PASS_REGULAR_EXPRESSION "Usage:.*number"
+add_test(NAME Usage COMMAND Tutorial)
+set_tests_properties(Usage
+ 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}
+# define a function to simplify adding tests
+function(do_test target arg result)
+ add_test(NAME Comp${arg} COMMAND ${target} ${arg})
+ set_tests_properties(Comp${arg}
PROPERTIES PASS_REGULAR_EXPRESSION ${result}
)
-endmacro ()
+endfunction(do_test)
# 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)
+do_test(Tutorial 4 "4 is 2")
+do_test(Tutorial 9 "9 is 3")
+do_test(Tutorial 5 "5 is 2.236")
+do_test(Tutorial 7 "7 is 2.645")
+do_test(Tutorial 25 "25 is 5")
+do_test(Tutorial -25 "-25 is [-nan|nan|0]")
+do_test(Tutorial 0.0001 "0.0001 is 0.01")
diff --git a/Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt
index 70a35f662..2946075f1 100644
--- a/Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt
+++ b/Tests/Tutorial/Step6/MathFunctions/CMakeLists.txt
@@ -1,24 +1,14 @@
-# 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_library(MathFunctions mysqrt.cxx)
-# add the binary tree directory to the search path for include files
-include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
+# state that anybody linking to us needs to include the current source dir
+# to find MathFunctions.h, while we don't.
+# state that we depend on Tutorial_BINARY_DIR but consumers don't, as the
+# TutorialConfig.h include is an implementation detail
-# add the main library
-add_library(MathFunctions mysqrt.cxx)
+target_include_directories(MathFunctions
+ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+ PRIVATE ${Tutorial_BINARY_DIR}
+ )
-install (TARGETS MathFunctions DESTINATION bin)
-install (FILES MathFunctions.h DESTINATION include)
+install(TARGETS MathFunctions DESTINATION lib)
+install(FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx
index cebd50fcc..ee585568c 100644
--- a/Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx
+++ b/Tests/Tutorial/Step6/MathFunctions/MakeTable.cxx
@@ -1,32 +1,25 @@
// A simple program that builds a sqrt table
-#include <math.h>
-#include <stdio.h>
+#include <cmath>
+#include <fstream>
+#include <iostream>
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;
+ std::ofstream fout(argv[1], std::ios_base::out);
+ const bool fileOpen = fout.is_open();
+ if (fileOpen) {
+ fout << "double sqrtTable[] = {" << std::endl;
+ for (int i = 0; i < 10; ++i) {
+ fout << sqrt(static_cast<double>(i)) << "," << std::endl;
+ }
+ // close the table with a zero
+ fout << "0};" << std::endl;
+ fout.close();
}
-
- // 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;
+ return fileOpen ? 0 : 1; // return 0 if wrote the file
}
diff --git a/Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx
index 458ed63a1..b9ad20a84 100644
--- a/Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx
+++ b/Tests/Tutorial/Step6/MathFunctions/mysqrt.cxx
@@ -1,11 +1,8 @@
#include "MathFunctions.h"
#include "TutorialConfig.h"
-#include <stdio.h>
+#include <iostream>
-// include the generated table
-#include "Table.h"
-
-#include <math.h>
+#include <cmath>
// a hack square root calculation using simple operations
double mysqrt(double x)
@@ -14,27 +11,23 @@ double mysqrt(double x)
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)];
- }
+#if defined(HAVE_LOG) && defined(HAVE_EXP)
+ double result = exp(log(x) * 0.5);
+ std::cout << "Computing sqrt of " << x << " to be " << result << " using log"
+ << std::endl;
+#else
+ double result = x;
// do ten iterations
- int i;
- for (i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
- delta = x - (result * result);
+ double delta = x - (result * result);
result = result + 0.5 * delta / result;
- fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result);
+ std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
-
+#endif
return result;
}
diff --git a/Tests/Tutorial/Step6/tutorial.cxx b/Tests/Tutorial/Step6/tutorial.cxx
index 2fae364d4..1d5742d2d 100644
--- a/Tests/Tutorial/Step6/tutorial.cxx
+++ b/Tests/Tutorial/Step6/tutorial.cxx
@@ -1,33 +1,32 @@
// A simple program that computes the square root of a number
+#include <cmath>
+#include <iostream>
+#include <string>
+
#include "TutorialConfig.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
#ifdef USE_MYMATH
-#include "MathFunctions.h"
+# 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]);
+ std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
+ << Tutorial_VERSION_MAJOR << std::endl;
+ std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
- double inputValue = atof(argv[1]);
- double outputValue = 0;
+ double inputValue = std::stod(argv[1]);
- if (inputValue >= 0) {
#ifdef USE_MYMATH
- outputValue = mysqrt(inputValue);
+ double outputValue = mysqrt(inputValue);
#else
- outputValue = sqrt(inputValue);
+ double outputValue = sqrt(inputValue);
#endif
- }
- fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
+ std::cout << "The square root of " << inputValue << " is " << outputValue
+ << std::endl;
return 0;
}
diff --git a/Tests/Tutorial/Step7/CMakeLists.txt b/Tests/Tutorial/Step7/CMakeLists.txt
index d9a92fbef..f2d3839b7 100644
--- a/Tests/Tutorial/Step7/CMakeLists.txt
+++ b/Tests/Tutorial/Step7/CMakeLists.txt
@@ -1,82 +1,76 @@
-cmake_minimum_required (VERSION 2.6)
-project (Tutorial)
+cmake_minimum_required(VERSION 3.3)
+project(Tutorial)
-# The version number.
-set (Tutorial_VERSION_MAJOR 1)
-set (Tutorial_VERSION_MINOR 0)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED True)
+
+# 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)
+include(CheckSymbolExists)
+set(CMAKE_REQUIRED_LIBRARIES "m")
+check_symbol_exists(log "math.h" HAVE_LOG)
+check_symbol_exists(exp "math.h" 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 (
+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 ()
+if(USE_MYMATH)
+ add_subdirectory(MathFunctions)
+ list(APPEND EXTRA_LIBS MathFunctions)
+endif(USE_MYMATH)
# add the executable
-add_executable (Tutorial tutorial.cxx)
-target_link_libraries (Tutorial ${EXTRA_LIBS})
+add_executable(Tutorial tutorial.cxx)
+target_link_libraries(Tutorial PUBLIC ${EXTRA_LIBS})
+
+# add the binary tree to the search path for include files
+# so that we will find TutorialConfig.h
+target_include_directories(Tutorial PUBLIC
+ "${PROJECT_BINARY_DIR}"
+ )
# add the install targets
-install (TARGETS Tutorial DESTINATION bin)
-install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
- DESTINATION include)
+install(TARGETS Tutorial DESTINATION bin)
+install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"
+ DESTINATION include
+ )
# enable testing
-enable_testing ()
+enable_testing()
# does the application run
-add_test (TutorialRuns Tutorial 25)
+add_test(NAME Runs COMMAND Tutorial 25)
# does the usage message work?
-add_test (TutorialUsage Tutorial)
-set_tests_properties (TutorialUsage
- PROPERTIES
- PASS_REGULAR_EXPRESSION "Usage:.*number"
+add_test(NAME Usage COMMAND Tutorial)
+set_tests_properties(Usage
+ 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}
+# define a function to simplify adding tests
+function(do_test target arg result)
+ add_test(NAME Comp${arg} COMMAND ${target} ${arg})
+ set_tests_properties(Comp${arg}
PROPERTIES PASS_REGULAR_EXPRESSION ${result}
)
-endmacro ()
+endfunction(do_test)
# 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)
+do_test(Tutorial 4 "4 is 2")
+do_test(Tutorial 9 "9 is 3")
+do_test(Tutorial 5 "5 is 2.236")
+do_test(Tutorial 7 "7 is 2.645")
+do_test(Tutorial 25 "25 is 5")
+do_test(Tutorial -25 "-25 is [-nan|nan|0]")
+do_test(Tutorial 0.0001 "0.0001 is 0.01")
diff --git a/Tests/Tutorial/Step7/License.txt b/Tests/Tutorial/Step7/License.txt
index 673d72453..c62d00b9e 100644
--- a/Tests/Tutorial/Step7/License.txt
+++ b/Tests/Tutorial/Step7/License.txt
@@ -1,2 +1,2 @@
This is the open source License.txt file introduced in
-CMake/Tests/Tutorial/Step6...
+CMake/Tutorial/Step7...
diff --git a/Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt b/Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt
index 70a35f662..dc3eb9822 100644
--- a/Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt
+++ b/Tests/Tutorial/Step7/MathFunctions/CMakeLists.txt
@@ -2,23 +2,28 @@
add_executable(MakeTable MakeTable.cxx)
# add the command to generate the source code
-add_custom_command (
+add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ COMMAND MakeTable ${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)
+add_library(MathFunctions
+ mysqrt.cxx
+ ${CMAKE_CURRENT_BINARY_DIR}/Table.h
+ )
+
+# state that anybody linking to us needs to include the current source dir
+# to find MathFunctions.h, while we don't.
+# state that we depend on Tutorial_BINARY_DIR but consumers don't, as the
+# TutorialConfig.h include is an implementation detail
+# state that we depend on our binary dir to find Table.h
+target_include_directories(MathFunctions
+ INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
+ PRIVATE ${Tutorial_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ )
-install (TARGETS MathFunctions DESTINATION bin)
-install (FILES MathFunctions.h DESTINATION include)
+install(TARGETS MathFunctions DESTINATION lib)
+install(FILES MathFunctions.h DESTINATION include)
diff --git a/Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx b/Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx
index cebd50fcc..ee585568c 100644
--- a/Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx
+++ b/Tests/Tutorial/Step7/MathFunctions/MakeTable.cxx
@@ -1,32 +1,25 @@
// A simple program that builds a sqrt table
-#include <math.h>
-#include <stdio.h>
+#include <cmath>
+#include <fstream>
+#include <iostream>
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;
+ std::ofstream fout(argv[1], std::ios_base::out);
+ const bool fileOpen = fout.is_open();
+ if (fileOpen) {
+ fout << "double sqrtTable[] = {" << std::endl;
+ for (int i = 0; i < 10; ++i) {
+ fout << sqrt(static_cast<double>(i)) << "," << std::endl;
+ }
+ // close the table with a zero
+ fout << "0};" << std::endl;
+ fout.close();
}
-
- // 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;
+ return fileOpen ? 0 : 1; // return 0 if wrote the file
}
diff --git a/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx b/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx
index 458ed63a1..5272f56f2 100644
--- a/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx
+++ b/Tests/Tutorial/Step7/MathFunctions/mysqrt.cxx
@@ -1,11 +1,11 @@
#include "MathFunctions.h"
#include "TutorialConfig.h"
-#include <stdio.h>
+#include <iostream>
// include the generated table
#include "Table.h"
-#include <math.h>
+#include <cmath>
// a hack square root calculation using simple operations
double mysqrt(double x)
@@ -14,26 +14,20 @@ double mysqrt(double x)
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;
+ double result = x;
if (x >= 1 && x < 10) {
result = sqrtTable[static_cast<int>(x)];
}
// do ten iterations
- int i;
- for (i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10; ++i) {
if (result <= 0) {
result = 0.1;
}
- delta = x - (result * result);
+ double delta = x - (result * result);
result = result + 0.5 * delta / result;
- fprintf(stdout, "Computing sqrt of %g to be %g\n", x, result);
+ std::cout << "Computing sqrt of " << x << " to be " << result << std::endl;
}
return result;
diff --git a/Tests/Tutorial/Step7/tutorial.cxx b/Tests/Tutorial/Step7/tutorial.cxx
index 2fae364d4..1d5742d2d 100644
--- a/Tests/Tutorial/Step7/tutorial.cxx
+++ b/Tests/Tutorial/Step7/tutorial.cxx
@@ -1,33 +1,32 @@
// A simple program that computes the square root of a number
+#include <cmath>
+#include <iostream>
+#include <string>
+
#include "TutorialConfig.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
#ifdef USE_MYMATH
-#include "MathFunctions.h"
+# 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]);
+ std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
+ << Tutorial_VERSION_MAJOR << std::endl;
+ std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
- double inputValue = atof(argv[1]);
- double outputValue = 0;
+ double inputValue = std::stod(argv[1]);
- if (inputValue >= 0) {
#ifdef USE_MYMATH
- outputValue = mysqrt(inputValue);
+ double outputValue = mysqrt(inputValue);
#else
- outputValue = sqrt(inputValue);
+ double outputValue = sqrt(inputValue);
#endif
- }
- fprintf(stdout, "The square root of %g is %g\n", inputValue, outputValue);
+ std::cout << "The square root of " << inputValue << " is " << outputValue
+ << std::endl;
return 0;
}
diff --git a/Tests/Unset/CMakeLists.txt b/Tests/Unset/CMakeLists.txt
index 07aa68e7a..a40367bbe 100644
--- a/Tests/Unset/CMakeLists.txt
+++ b/Tests/Unset/CMakeLists.txt
@@ -21,17 +21,26 @@ set(x 43)
if(NOT x EQUAL 43)
message(FATAL_ERROR "x!=43")
endif()
+if(DEFINED CACHE{x})
+ message(FATAL_ERROR "x shouldn't be found in the cache")
+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()
+if(NOT DEFINED CACHE{BAR})
+ message(FATAL_ERROR "BAR could not be found by CACHE{BAR}")
+endif()
+
# Test interaction of cache entries with variables.
set(BAR "test-var")
if(NOT "$CACHE{BAR}" STREQUAL "test")
diff --git a/Tests/VSExternalInclude/CMakeLists.txt b/Tests/VSExternalInclude/CMakeLists.txt
index 7465243bd..8ca725249 100644
--- a/Tests/VSExternalInclude/CMakeLists.txt
+++ b/Tests/VSExternalInclude/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 2.6)
project(VSExternalInclude)
-if(${CMAKE_GENERATOR} MATCHES "Visual Studio 1[01245]")
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio 1[012456]")
set(PROJECT_EXT vcxproj)
else()
set(PROJECT_EXT vcproj)
@@ -55,7 +55,7 @@ add_dependencies(VSExternalInclude lib2)
# 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[01245]")
+if(${CMAKE_GENERATOR} MATCHES "Visual Studio 1[012456]")
add_dependencies(VSExternalInclude lib1)
endif()
diff --git a/Tests/VSGNUFortran/CMakeLists.txt b/Tests/VSGNUFortran/CMakeLists.txt
index 229c3156c..993d0d65f 100644
--- a/Tests/VSGNUFortran/CMakeLists.txt
+++ b/Tests/VSGNUFortran/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.9)
project(VSGNUFortran)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
@@ -9,7 +9,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
# 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)
+get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(_isMultiConfig)
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config}
diff --git a/Tests/VSGNUFortran/runtest.cmake.in b/Tests/VSGNUFortran/runtest.cmake.in
index 987207bc4..fc05715d3 100644
--- a/Tests/VSGNUFortran/runtest.cmake.in
+++ b/Tests/VSGNUFortran/runtest.cmake.in
@@ -14,7 +14,7 @@ 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})
+set(ENV{PATH} "${MINGW_PATH};$ENV{PATH}")
message("run ${test_exe}")
execute_process(COMMAND "${test_exe}"
RESULT_VARIABLE res)
diff --git a/Tests/VSNASM/CMakeLists.txt b/Tests/VSNASM/CMakeLists.txt
index c2e29df25..821d0227e 100644
--- a/Tests/VSNASM/CMakeLists.txt
+++ b/Tests/VSNASM/CMakeLists.txt
@@ -1,10 +1,20 @@
cmake_minimum_required(VERSION 2.8.12)
project(VSNASM C ASM_NASM)
+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_definitions(-DTESTx64)
string(APPEND CMAKE_ASM_NASM_FLAGS " -DTEST2x64")
else()
add_definitions(-DTESTi386)
endif()
+
+# Test quoting for definitions with spaces.
+add_definitions("-DEAX_COMMA_SPACE_ZERO=eax, 0")
+
+# Test quoting for file names with spaces. The file is generated because CMake
+# itself cannot have files with spaces.
+file(READ bar.asm BAR_ASM_CONTENTS)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/bar baz.asm" "${BAR_ASM_CONTENTS}")
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
-add_executable(VSNASM main.c foo.asm)
+add_executable(VSNASM main.c foo.asm "${CMAKE_CURRENT_BINARY_DIR}/bar baz.asm")
diff --git a/Tests/VSNASM/include/foo-proc.asm b/Tests/VSNASM/include/foo-proc.asm
index 450a7919b..eb5bb2b06 100644
--- a/Tests/VSNASM/include/foo-proc.asm
+++ b/Tests/VSNASM/include/foo-proc.asm
@@ -3,5 +3,5 @@ foo:
%else
_foo:
%endif
- mov eax, 0
+ mov EAX_COMMA_SPACE_ZERO
ret
diff --git a/Tests/VSNASM/main.c b/Tests/VSNASM/main.c
index 18ddb7826..b1401b698 100644
--- a/Tests/VSNASM/main.c
+++ b/Tests/VSNASM/main.c
@@ -1,5 +1,6 @@
extern int foo(void);
+extern int bar(void);
int main(void)
{
- return foo();
+ return foo() + bar();
}
diff --git a/Tests/VSResource/CMakeLists.txt b/Tests/VSResource/CMakeLists.txt
index 718e62441..fb47c7e13 100644
--- a/Tests/VSResource/CMakeLists.txt
+++ b/Tests/VSResource/CMakeLists.txt
@@ -56,3 +56,10 @@ endif()
set_property(TARGET VSResource
PROPERTY VS_GLOBAL_CMakeTestVsGlobalVariable "test val")
+
+if(CMAKE_GENERATOR MATCHES "Ninja|Visual Studio")
+ cmake_policy(PUSH)
+ cmake_policy(SET CMP0037 OLD)
+ add_library("My ResourceLib" lib.cpp lib.rc)
+ cmake_policy(POP)
+endif()
diff --git a/Tests/VSWinStorePhone/CMakeLists.txt b/Tests/VSWinStorePhone/CMakeLists.txt
index 2b0c47806..efc77601d 100644
--- a/Tests/VSWinStorePhone/CMakeLists.txt
+++ b/Tests/VSWinStorePhone/CMakeLists.txt
@@ -8,6 +8,8 @@ elseif(MSVC_VERSION GREATER 1600)
set(COMPILER_VERSION "11")
endif()
+add_subdirectory(WinRT)
+
set (APP_MANIFEST_NAME Package.appxmanifest)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsPhone")
set(PLATFORM WP)
@@ -116,12 +118,14 @@ set_property(SOURCE ${RELEASE_CONTENT_FILES} PROPERTY
set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_TYPE Pixel)
set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_ENTRYPOINT mainPS)
set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_MODEL 4.0_level_9_3)
-set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_FLAGS "/DFLAGS_ADDED /Fh \"$(OutDir)%(Filename).h\"")
+set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_FLAGS "/DFLAGS_ADDED")
+set_property(SOURCE ${PIXELSHADER_FILES} PROPERTY VS_SHADER_OUTPUT_HEADER_FILE "$(OutDir)%(Filename).h")
set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_TYPE Vertex)
set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_ENTRYPOINT mainVS)
set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_MODEL 4.0_level_9_3)
-set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_FLAGS "/DFLAGS_ADDED /Fh \"$(OutDir)%(Filename).h\"")
+set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_FLAGS "/DFLAGS_ADDED")
+set_property(SOURCE ${VERTEXSHADER_FILES} PROPERTY VS_SHADER_OUTPUT_HEADER_FILE "$(OutDir)%(Filename).h")
source_group("Source Files" FILES ${SOURCE_FILES})
@@ -137,11 +141,14 @@ if("${SHORT_VERSION}" STREQUAL "10.0")
message(STATUS "Targeting Windows 10. Setting Extensions to version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
set_property(TARGET ${EXE_NAME} PROPERTY VS_DESKTOP_EXTENSIONS_VERSION "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
set_property(TARGET ${EXE_NAME} PROPERTY VS_MOBILE_EXTENSIONS_VERSION "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
- set_property(TARGET ${EXE_NAME} PROPERTY VS_IOT_EXTENSIONS_VERSION "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
+
+ # The last IOT reference is on 10.0.17134.0, so only add it if supported
+ if("${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" VERSION_LESS "10.0.17135.0")
+ set_property(TARGET ${EXE_NAME} PROPERTY VS_IOT_EXTENSIONS_VERSION "${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
+ endif()
# Add a reference to an SDK
set_property(TARGET ${EXE_NAME} PROPERTY VS_SDK_REFERENCES "Microsoft.UniversalCRT.Debug, Version=${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()
-
-target_link_libraries(${EXE_NAME} d3d11)
+target_link_libraries(${EXE_NAME} d3d11 JusticeLeagueWinRT)
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.png
index 7d95d4e08..c715e1bc7 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/ApplicationIcon.png
+++ 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
index e26771cb3..65f91ac0f 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Logo.png
+++ 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
index 1eb0d9d52..460c0222d 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo.png
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo44x44.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo44x44.png
index 28810b7c0..c2374581a 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo44x44.png
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SmallLogo44x44.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.png b/Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.png
index c951e031b..834256580 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/SplashScreen.png
+++ 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
index dcb672712..508c8a809 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/StoreLogo.png
+++ 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
index e0c59ac01..fcdbaf4ac 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileLarge.png
+++ 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
index e93b89d60..06425c4b1 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileMedium.png
+++ 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
index 550b1b5e8..4cef0eb30 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/FlipCycleTileSmall.png
+++ 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
index 686e6b53f..253503f04 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileMediumLarge.png
+++ 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
index d4b5ede1b..2ef050fb3 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileSmall.png
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Assets/Tiles/IconicTileSmall.png
Binary files differ
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp
index 1c969cd2f..3ba35fa43 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp
+++ b/Tests/VSWinStorePhone/Direct3DApp1/CubeRenderer.cpp
@@ -6,11 +6,15 @@ using namespace DirectX;
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::UI::Core;
+using namespace JusticeLeagueWinRT;
CubeRenderer::CubeRenderer()
: m_loadingComplete(false)
, m_indexCount(0)
{
+ // Create a new WinRT object to validate that we can link properly
+ Batman ^ hero = ref new Batman();
+ hero->savePeople();
}
void CubeRenderer::CreateDeviceResources()
diff --git a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp
index 8f3452c06..0662fbe64 100644
--- a/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp
+++ b/Tests/VSWinStorePhone/Direct3DApp1/Direct3DBase.cpp
@@ -101,12 +101,12 @@ void Direct3DBase::CreateWindowSizeDependentResources()
#if WINVER > 0x0602
m_orientation = DisplayInformation::GetForCurrentView()->CurrentOrientation;
#else
-#if PHONE
+# if PHONE
// WP8 doesn't support rotations so always make it landscape
m_orientation = DisplayOrientations::Landscape;
-#else
+# else
m_orientation = DisplayProperties::CurrentOrientation;
-#endif
+# endif
#endif
bool swapDimensions = m_orientation == DisplayOrientations::Portrait ||
m_orientation == DisplayOrientations::PortraitFlipped;
diff --git a/Tests/VSXaml/Assets/Logo.scale-100.png b/Tests/VSXaml/Assets/Logo.scale-100.png
index e26771cb3..65f91ac0f 100644
--- a/Tests/VSXaml/Assets/Logo.scale-100.png
+++ b/Tests/VSXaml/Assets/Logo.scale-100.png
Binary files differ
diff --git a/Tests/VSXaml/Assets/SmallLogo.scale-100.png b/Tests/VSXaml/Assets/SmallLogo.scale-100.png
index 1eb0d9d52..460c0222d 100644
--- a/Tests/VSXaml/Assets/SmallLogo.scale-100.png
+++ b/Tests/VSXaml/Assets/SmallLogo.scale-100.png
Binary files differ
diff --git a/Tests/VSXaml/Assets/SplashScreen.scale-100.png b/Tests/VSXaml/Assets/SplashScreen.scale-100.png
index c951e031b..834256580 100644
--- a/Tests/VSXaml/Assets/SplashScreen.scale-100.png
+++ b/Tests/VSXaml/Assets/SplashScreen.scale-100.png
Binary files differ
diff --git a/Tests/VSXaml/Assets/StoreLogo.scale-100.png b/Tests/VSXaml/Assets/StoreLogo.scale-100.png
index dcb672712..508c8a809 100644
--- a/Tests/VSXaml/Assets/StoreLogo.scale-100.png
+++ b/Tests/VSXaml/Assets/StoreLogo.scale-100.png
Binary files differ
diff --git a/Tests/WarnUnusedCliUnused/CMakeLists.txt b/Tests/WarnUnusedCliUnused/CMakeLists.txt
index 7ed69bf3c..a149f043f 100644
--- a/Tests/WarnUnusedCliUnused/CMakeLists.txt
+++ b/Tests/WarnUnusedCliUnused/CMakeLists.txt
@@ -1,9 +1,9 @@
-cmake_minimum_required(VERSION 2.8)
+cmake_minimum_required(VERSION 3.14)
project(WarnUnusedCliUnused)
-set_directory_properties(PROPERTIES
- ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}/CMakeCache.txt"
-)
+# Remove UNUSED_CLI_VARIABLE from the cache to trigger the
+# CMake warning message on re-builds as well.
+unset(UNUSED_CLI_VARIABLE CACHE)
add_library(dummy empty.cpp)
diff --git a/Tests/Wrapping/fakefluid.cxx b/Tests/Wrapping/fakefluid.cxx
index a118bbd43..f5fb3fb25 100644
--- a/Tests/Wrapping/fakefluid.cxx
+++ b/Tests/Wrapping/fakefluid.cxx
@@ -6,9 +6,10 @@ int main(int ac, char** av)
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, "// Solaris needs non-empty content so ensure\n"
- "// we have at least one symbol\n"
- "int Solaris_requires_a_symbol_here = 0;\n");
+ fprintf(file,
+ "// Solaris needs non-empty content so ensure\n"
+ "// we have at least one symbol\n"
+ "int Solaris_requires_a_symbol_here = 0;\n");
fclose(file);
}
}
diff --git a/Tests/Wrapping/qtwrappingmain.cxx b/Tests/Wrapping/qtwrappingmain.cxx
index 37234d900..d4951eef2 100644
--- a/Tests/Wrapping/qtwrappingmain.cxx
+++ b/Tests/Wrapping/qtwrappingmain.cxx
@@ -2,8 +2,8 @@
#include <qapplication.h>
#ifndef _WIN32
-#include <stdio.h>
-#include <stdlib.h>
+# include <stdio.h>
+# include <stdlib.h>
#endif
int main(int argc, char* argv[])
diff --git a/Tests/X11/HelloWorldX11.cxx b/Tests/X11/HelloWorldX11.cxx
index 0863f7bb7..e59248b49 100644
--- a/Tests/X11/HelloWorldX11.cxx
+++ b/Tests/X11/HelloWorldX11.cxx
@@ -11,15 +11,15 @@
*/
#ifndef MAIN_H
-#define MAIN_H 1
+# define MAIN_H 1
-#include <iostream>
-#include <stdlib.h>
+# include <iostream>
+# include <stdlib.h>
/* include the X library headers */
-#include <X11/Xlib.h>
-#include <X11/Xos.h>
-#include <X11/Xutil.h>
+# include <X11/Xlib.h>
+# include <X11/Xos.h>
+# include <X11/Xutil.h>
class Main
{
diff --git a/Tests/X11/X11.c b/Tests/X11/X11.c
index b802ed8b9..3a6f9f0b3 100644
--- a/Tests/X11/X11.c
+++ b/Tests/X11/X11.c
@@ -1,8 +1,8 @@
#include "stdio.h"
#ifdef CMAKE_HAS_X
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
+# include <X11/Xlib.h>
+# include <X11/Xutil.h>
int main()
{
diff --git a/Tests/XCTest/CMakeLists.txt b/Tests/XCTest/CMakeLists.txt
index d40c40e2a..d0b07ea1c 100644
--- a/Tests/XCTest/CMakeLists.txt
+++ b/Tests/XCTest/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.1)
-project(XCTest)
+project(XCTest C)
enable_testing()
find_package(XCTest REQUIRED)
diff --git a/Tests/bootstrap.bat.in b/Tests/bootstrap.bat.in
index aeb24b1ca..85e79ef00 100644
--- a/Tests/bootstrap.bat.in
+++ b/Tests/bootstrap.bat.in
@@ -1,2 +1,2 @@
-@echo off
-sh "@CMake_SOURCE_DIR@/bootstrap" %*
+@echo off
+sh "@CMake_SOURCE_DIR@/bootstrap" %*
diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt
index f1e8f95e7..ce4cfaf4b 100644
--- a/Utilities/Doxygen/CMakeLists.txt
+++ b/Utilities/Doxygen/CMakeLists.txt
@@ -3,7 +3,7 @@
if(NOT CMake_SOURCE_DIR)
set(CMakeDeveloperReference_STANDALONE 1)
- cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR)
+ cmake_minimum_required(VERSION 3.1...3.14 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)
diff --git a/Utilities/GitSetup/setup-hooks b/Utilities/GitSetup/setup-hooks
index ca07712d5..6a17b10e2 100755
--- a/Utilities/GitSetup/setup-hooks
+++ b/Utilities/GitSetup/setup-hooks
@@ -26,7 +26,7 @@
# hooks.url = Repository URL publishing "hooks" branch
# hooks.branch = Repository branch instead of "hooks"
-egrep-q() {
+egrep_q() {
egrep "$@" >/dev/null 2>/dev/null
}
@@ -42,7 +42,7 @@ 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
+ 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
diff --git a/Utilities/GitSetup/tips b/Utilities/GitSetup/tips
index 784e1ed89..f47d84cf5 100755
--- a/Utilities/GitSetup/tips
+++ b/Utilities/GitSetup/tips
@@ -19,7 +19,7 @@
# Project configuration instructions: NONE
-egrep-q() {
+egrep_q() {
egrep "$@" >/dev/null 2>/dev/null
}
@@ -33,7 +33,7 @@ One may enable color output from Git commands with
fi
# Suggest bash completion.
-if ! bash -i -c 'echo $PS1' | egrep-q '__git_ps1'; then
+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
diff --git a/Utilities/IWYU/mapping.imp b/Utilities/IWYU/mapping.imp
index fe0f7df71..0393ff199 100644
--- a/Utilities/IWYU/mapping.imp
+++ b/Utilities/IWYU/mapping.imp
@@ -21,9 +21,13 @@
{ include: [ "<wctype.h>", public, "<cwctype>", public ] },
# HACK: check whether this can be removed with next iwyu release.
+ { include: [ "<bits/shared_ptr.h>", private, "<memory>", public ] },
{ include: [ "<bits/std_function.h>", private, "<functional>", public ] },
+ { include: [ "<bits/stdint-intn.h>", private, "<stdint.h>", public ] },
+ { include: [ "<bits/stdint-uintn.h>", private, "<stdint.h>", public ] },
{ include: [ "<bits/time.h>", private, "<time.h>", public ] },
{ include: [ "<bits/types/clock_t.h>", private, "<time.h>", public ] },
+ { include: [ "<bits/types/mbstate_t.h>", private, "<wchar.h>", public ] },
{ include: [ "<bits/types/struct_timespec.h>", private, "<time.h>", public ] },
{ include: [ "<bits/types/struct_timeval.h>", private, "<time.h>", public ] },
{ include: [ "<bits/types/struct_tm.h>", private, "<time.h>", public ] },
@@ -48,36 +52,32 @@
#{ symbol: [ "std::pair", private, "<map>", public ] },
#{ symbol: [ "std::pair", private, "<set>", public ] },
- # IWYU wrongly suggests to include "cm_auto_ptr.hxx" in some places. This
- # might be a misinterpretation of a template specialization in <utility>.
- # As a workaround, map the symbol auto_ptr to "cmConfigure.h".
- # This will still correctly require "cm_auto_ptr.hxx" for CM_AUTO_PTR.
- { symbol: [ "cm::auto_ptr", private, "\"cmConfigure.h\"", public ] },
+ # HACK: iwyu wrongly thinks that <system_error> is needed for std::hash
+ { symbol: [ "std::hash", private, "<functional>", public ] },
+
+ # HACK: iwyu thinks we use a libstdc++ private type
+ { symbol: [ "__gnu_cxx::size_t", private, "<cstddef>", public ] },
# __decay_and_strip is used internally in the C++11 standard library.
# IWYU does not classify it as internal and suggests to add <type_traits>.
# To ignore it, we simply map it to a file that is included anyway.
+ # Use '-Xiwyu -v7' to see the fully qualified names that need this.
# TODO: Can this be simplified with an @-expression?
#{ symbol: [ "@std::__decay_and_strip<.*>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<cmCommand *&>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<cmGeneratorTarget *&>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<cmFindCommon::PathLabel &>::__type", private, "\"cmConfigure.h\"", public ] },
+ { symbol: [ "std::__decay_and_strip<cmSearchPath>::__type", private, "\"cmConfigure.h\"", public ] },
+ { symbol: [ "std::__decay_and_strip<cm::string_view>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<std::basic_string<char> &>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<const std::basic_string<char> &>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<cmFindPackageCommand::PathLabel &>::__type", private, "\"cmConfigure.h\"", public ] },
{ symbol: [ "std::__decay_and_strip<__gnu_cxx::__normal_iterator<const cmCTestTestHandler::cmCTestTestProperties *, std::vector<cmCTestTestHandler::cmCTestTestProperties, std::allocator<cmCTestTestHandler::cmCTestTestProperties> > > &>::__type", private, "\"cmConfigure.h\"", public ] },
-
- # Wrappers for headers added in TR1 / C++11
- # { include: [ "<array>", public, "\"cm_array.hxx\"", public ] },
- # { include: [ "<functional>", public, "\"cm_functional.hxx\"", public ] },
- # { include: [ "<memory>", public, "\"cm_memory.hxx\"", public ] },
- { include: [ "<unordered_map>", public, "\"cm_unordered_map.hxx\"", public ] },
- { include: [ "<unordered_set>", public, "\"cm_unordered_set.hxx\"", public ] },
- # { include: [ "<tr1/array>", public, "\"cm_array.hxx\"", public ] },
- # { include: [ "<tr1/functional>", public, "\"cm_functional.hxx\"", public ] },
- # { include: [ "<tr1/memory>", public, "\"cm_memory.hxx\"", public ] },
- { include: [ "<tr1/unordered_map>", public, "\"cm_unordered_map.hxx\"", public ] },
- { include: [ "<tr1/unordered_set>", public, "\"cm_unordered_set.hxx\"", public ] },
+ { symbol: [ "std::__success_type<std::chrono::duration<double, std::ratio<1, 1> > >::type", private, "\"cmConfigure.h\"", public ] },
+ { symbol: [ "std::__success_type<std::chrono::duration<long, std::ratio<1, 1000000000> > >::type", private, "\"cmConfigure.h\"", public ] },
+ { symbol: [ "std::enable_if<true, std::chrono::duration<long, std::ratio<1, 1> > >::type", private, "\"cmConfigure.h\"", public ] },
+ { symbol: [ "std::enable_if<true, std::chrono::duration<long, std::ratio<60, 1> > >::type", private, "\"cmConfigure.h\"", public ] },
+ { symbol: [ "std::enable_if<true, std::chrono::duration<long, std::ratio<1, 1000> > >::type", private, "\"cmConfigure.h\"", public ] },
# KWIML
{ include: [ "<stdint.h>", public, "\"cm_kwiml.h\"", public ] },
@@ -87,14 +87,6 @@
{ include: [ "<sys/stat.h>", public, "\"cm_sys_stat.h\"", public ] },
{ symbol: [ "mode_t", private, "\"cm_sys_stat.h\"", public ] },
- # TODO: remove once TR1 / C++11 is required.
- { include: [ "\"cmsys/hash_fun.hxx\"", private, "\"cm_unordered_map.hxx\"", public ] },
- { include: [ "\"cmsys/hash_fun.hxx\"", private, "\"cm_unordered_set.hxx\"", public ] },
- { include: [ "\"cmsys/hash_map.hxx\"", private, "\"cm_unordered_map.hxx\"", public ] },
- { include: [ "\"cmsys/hash_set.hxx\"", private, "\"cm_unordered_set.hxx\"", public ] },
- { include: [ "\"cmsys/hashtable.hxx\"", private, "\"cm_unordered_map.hxx\"", public ] },
- { include: [ "\"cmsys/hashtable.hxx\"", private, "\"cm_unordered_set.hxx\"", public ] },
-
# Wrappers for 3rd-party libraries used from the system.
{ include: [ "<archive.h>", private, "\"cm_libarchive.h\"", public ] },
{ include: [ "<archive_entry.h>", private, "\"cm_libarchive.h\"", public ] },
@@ -106,12 +98,9 @@
{ include: [ "<json/writer.h>", private, "\"cm_jsoncpp_writer.h\"", public ] },
{ include: [ "<rhash.h>", private, "\"cm_rhash.h\"", public ] },
{ include: [ "<uv.h>", private, "\"cm_uv.h\"", public ] },
- { include: [ "@<uv-.+\\.h>", private, "\"cm_uv.h\"", public ] },
+ { include: [ "@<uv[/-].+\\.h>", private, "\"cm_uv.h\"", public ] },
{ include: [ "<kwiml/abi.h>", private, "\"cm_kwiml.h\"", public ] },
{ include: [ "<kwiml/int.h>", private, "\"cm_kwiml.h\"", public ] },
- { include: [ "<xmlrpc.h>", private, "\"cm_xmlrpc.h\"", public ] },
- { include: [ "<xmlrpc_client.h>", private, "\"cm_xmlrpc.h\"", public ] },
- { include: [ "@<xmlrpc-c/.+\\.h>", private, "\"cm_xmlrpc.h\"", public ] },
{ include: [ "<zconf.h>", private, "\"cm_zlib.h\"", public ] },
{ include: [ "<zlib.h>", private, "\"cm_zlib.h\"", public ] },
@@ -126,7 +115,7 @@
{ include: [ "\"cmjsoncpp/include/json/writer.h\"", private, "\"cm_jsoncpp_writer.h\"", public ] },
{ include: [ "\"cmlibrhash/librhash/rhash.h\"", private, "\"cm_rhash.h\"", public ] },
{ include: [ "\"cmlibuv/include/uv.h\"", private, "\"cm_uv.h\"", public ] },
- { include: [ "@\"cmlibuv/include/uv-.+\\.h\"", private, "\"cm_uv.h\"", public ] },
+ { include: [ "@\"cmlibuv/include/uv/.+\\.h\"", private, "\"cm_uv.h\"", public ] },
{ include: [ "\"KWIML/include/kwiml/abi.h\"", private, "\"cm_kwiml.h\"", public ] },
{ include: [ "\"KWIML/include/kwiml/int.h\"", private, "\"cm_kwiml.h\"", public ] },
{ include: [ "\"cmzlib/cm_zlib_mangle.h\"", private, "\"cm_zlib.h\"", public ] },
@@ -138,6 +127,8 @@
{ symbol: [ "SIGINT", private, "\"cm_uv.h\"", public ] },
{ symbol: [ "ssize_t", private, "\"cm_uv.h\"", public ] },
+ { symbol: [ "Json::ArrayIndex", private, "\"cm_jsoncpp_value.h\"", public ] },
+
{ symbol: [ "std::ifstream", private, "\"cmsys/FStream.hxx\"", public ] },
{ symbol: [ "std::ofstream", private, "\"cmsys/FStream.hxx\"", public ] },
{ symbol: [ "cmsys::ifstream", private, "\"cmsys/FStream.hxx\"", public ] },
diff --git a/Utilities/KWIML/Copyright.txt b/Utilities/KWIML/Copyright.txt
index 515c4ebc4..fffd6d13e 100644
--- a/Utilities/KWIML/Copyright.txt
+++ b/Utilities/KWIML/Copyright.txt
@@ -1,5 +1,5 @@
Kitware Information Macro Library
-Copyright 2010-2016 Kitware, Inc.
+Copyright 2010-2018 Kitware, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/Utilities/KWIML/include/kwiml/abi.h b/Utilities/KWIML/include/kwiml/abi.h
index 5ffd542cf..da525fdcb 100644
--- a/Utilities/KWIML/include/kwiml/abi.h
+++ b/Utilities/KWIML/include/kwiml/abi.h
@@ -1,6 +1,6 @@
/*============================================================================
Kitware Information Macro Library
- Copyright 2010-2016 Kitware, Inc.
+ Copyright 2010-2018 Kitware, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -468,7 +468,7 @@ suppression macro KWIML_ABI_NO_VERIFY was defined.
# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
/* RISC-V */
-#elif defined(__riscv__)
+#elif defined(__riscv) || defined(__riscv__)
# define KWIML_ABI_ENDIAN_ID KWIML_ABI_ENDIAN_ID_LITTLE
/* Unknown CPU */
@@ -484,9 +484,16 @@ suppression macro KWIML_ABI_NO_VERIFY was defined.
#if defined(_MSC_VER)
# pragma warning (push)
+# pragma warning (disable:4309) /* static_cast trunction of constant value */
# pragma warning (disable:4310) /* cast truncates constant value */
#endif
+#if defined(__cplusplus) && !defined(__BORLANDC__)
+#define KWIML_ABI_private_STATIC_CAST(t,v) static_cast<t>(v)
+#else
+#define KWIML_ABI_private_STATIC_CAST(t,v) (t)(v)
+#endif
+
#define KWIML_ABI_private_VERIFY(n, x, y) KWIML_ABI_private_VERIFY_0(KWIML_ABI_private_VERSION, n, x, y)
#define KWIML_ABI_private_VERIFY_0(V, n, x, y) KWIML_ABI_private_VERIFY_1(V, n, x, y)
#define KWIML_ABI_private_VERIFY_1(V, n, x, y) extern int (*n##_v##V)[x]; extern int (*n##_v##V)[y]
@@ -535,9 +542,11 @@ KWIML_ABI_private_VERIFY_DIFF(KWIML_ABI___INT64_NOT_LONG_LONG, __int64, long lon
#endif
#if defined(KWIML_ABI_CHAR_IS_UNSIGNED)
-KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_UNSIGNED, (char)0x80 > 0);
+KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_UNSIGNED,
+ KWIML_ABI_private_STATIC_CAST(char, 0x80) > 0);
#elif defined(KWIML_ABI_CHAR_IS_SIGNED)
-KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_SIGNED, (char)0x80 < 0);
+KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_SIGNED,
+ KWIML_ABI_private_STATIC_CAST(char, 0x80) < 0);
#endif
#undef KWIML_ABI_private_VERIFY_DIFF
@@ -557,6 +566,8 @@ KWIML_ABI_private_VERIFY_BOOL(KWIML_ABI_CHAR_IS_SIGNED, (char)0x80 < 0);
#undef KWIML_ABI_private_VERIFY_0
#undef KWIML_ABI_private_VERIFY
+#undef KWIML_ABI_private_STATIC_CAST
+
#if defined(_MSC_VER)
# pragma warning (pop)
#endif
diff --git a/Utilities/KWIML/include/kwiml/int.h b/Utilities/KWIML/include/kwiml/int.h
index 489c60325..b2e14d5f2 100644
--- a/Utilities/KWIML/include/kwiml/int.h
+++ b/Utilities/KWIML/include/kwiml/int.h
@@ -1,6 +1,6 @@
/*============================================================================
Kitware Information Macro Library
- Copyright 2010-2016 Kitware, Inc.
+ Copyright 2010-2018 Kitware, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -1003,16 +1003,25 @@ An includer may test the following macros after inclusion:
#if defined(_MSC_VER)
# pragma warning (push)
+# pragma warning (disable:4309) /* static_cast trunction of constant value */
# pragma warning (disable:4310) /* cast truncates constant value */
#endif
+#if defined(__cplusplus) && !defined(__BORLANDC__)
+#define KWIML_INT_private_STATIC_CAST(t,v) static_cast<t>(v)
+#else
+#define KWIML_INT_private_STATIC_CAST(t,v) (t)(v)
+#endif
+
#define KWIML_INT_private_VERIFY(n, x, y) KWIML_INT_private_VERIFY_0(KWIML_INT_private_VERSION, n, x, y)
#define KWIML_INT_private_VERIFY_0(V, n, x, y) KWIML_INT_private_VERIFY_1(V, n, x, y)
#define KWIML_INT_private_VERIFY_1(V, n, x, y) extern int (*n##_v##V)[x]; extern int (*n##_v##V)[y]
#define KWIML_INT_private_VERIFY_BOOL(m, b) KWIML_INT_private_VERIFY(KWIML_INT_detail_VERIFY_##m, 2, (b)?2:3)
#define KWIML_INT_private_VERIFY_TYPE(t, s) KWIML_INT_private_VERIFY(KWIML_INT_detail_VERIFY_##t, s, sizeof(t))
-#define KWIML_INT_private_VERIFY_SIGN(t, u, o) KWIML_INT_private_VERIFY_BOOL(SIGN_##t, (t)((u)1 << ((sizeof(t)<<3)-1)) o 0)
+#define KWIML_INT_private_VERIFY_SIGN(t, u, o) \
+ KWIML_INT_private_VERIFY_BOOL(SIGN_##t, KWIML_INT_private_STATIC_CAST( \
+ t, KWIML_INT_private_STATIC_CAST(u, 1) << ((sizeof(t)<<3)-1)) o 0)
KWIML_INT_private_VERIFY_TYPE(KWIML_INT_int8_t, 1);
KWIML_INT_private_VERIFY_TYPE(KWIML_INT_uint8_t, 1);
@@ -1060,6 +1069,8 @@ KWIML_INT_private_VERIFY_SIGN(KWIML_INT_uintptr_t, KWIML_INT_uintptr_t, >);
#undef KWIML_INT_private_VERIFY_0
#undef KWIML_INT_private_VERIFY
+#undef KWIML_INT_private_STATIC_CAST
+
#if defined(_MSC_VER)
# pragma warning (pop)
#endif
diff --git a/Utilities/KWIML/src/version.h.in b/Utilities/KWIML/src/version.h.in
index 0ac8854f2..5c566bb2e 100644
--- a/Utilities/KWIML/src/version.h.in
+++ b/Utilities/KWIML/src/version.h.in
@@ -1,6 +1,6 @@
/*============================================================================
Kitware Information Macro Library
- Copyright 2010-2016 Kitware, Inc.
+ Copyright 2010-2018 Kitware, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/Utilities/KWIML/test/test_int_format.h b/Utilities/KWIML/test/test_int_format.h
index 24dcdfba6..2e0310ce4 100644
--- a/Utilities/KWIML/test/test_int_format.h
+++ b/Utilities/KWIML/test/test_int_format.h
@@ -8,6 +8,7 @@
#if defined(_MSC_VER)
# pragma warning (push)
+# pragma warning (disable:4309) /* static_cast trunction of constant value */
# pragma warning (disable:4310) /* cast truncates constant value */
#endif
@@ -17,7 +18,13 @@
# define LANG "C "
#endif
-#define VALUE(T, U) (T)((U)0xab << ((sizeof(T)-1)<<3))
+#if defined(__cplusplus) && !defined(__BORLANDC__)
+# define STATIC_CAST(t,v) static_cast<t>(v)
+#else
+# define STATIC_CAST(t,v) (t)(v)
+#endif
+
+#define VALUE(T, U) STATIC_CAST(T, STATIC_CAST(U, 0xab) << ((sizeof(T)-1)<<3))
#define TEST_C_(C, V, PRI, T, U) \
{ \
diff --git a/Utilities/Release/CMakeLogo.ico b/Utilities/Release/CMakeLogo.ico
index e13bb156f..c1006122b 100644
--- a/Utilities/Release/CMakeLogo.ico
+++ b/Utilities/Release/CMakeLogo.ico
Binary files differ
diff --git a/Utilities/Release/WiX/WIX.template.in b/Utilities/Release/WiX/WIX.template.in
index fe176ca90..8abf9d8f2 100644
--- a/Utilities/Release/WiX/WIX.template.in
+++ b/Utilities/Release/WiX/WIX.template.in
@@ -20,6 +20,8 @@
Schedule="afterInstallInitialize"
AllowDowngrades="yes"/>
+ <Property Id="REINSTALLMODE" Value="amus"/>
+
<WixVariable Id="WixUILicenseRtf" Value="$(var.CPACK_WIX_LICENSE_RTF)"/>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALL_ROOT"/>
diff --git a/Utilities/Release/create-cmake-release.cmake b/Utilities/Release/create-cmake-release.cmake
index 3af1b035f..b3cc35232 100644
--- a/Utilities/Release/create-cmake-release.cmake
+++ b/Utilities/Release/create-cmake-release.cmake
@@ -54,7 +54,7 @@ cd \${name}-build &&
-DCMAKE_INSTALL_PREFIX=\"\$inst/\" \\
-DCMAKE_DOC_DIR=doc/cmake \\
-DSPHINX_EXECUTABLE=\"${SPHINX_EXECUTABLE}\" \\
- -DSPHINX_HTML=ON -DSPHINX_MAN=ON &&
+ -DSPHINX_HTML=ON -DSPHINX_MAN=ON -DSPHINX_QTHELP=ON &&
make install &&
cd .. &&
tar czf \${name}.tar.gz \${name} ||
diff --git a/Utilities/Release/linux64_release.cmake b/Utilities/Release/linux64_release.cmake
index 3d8ddba3c..958ed2544 100644
--- a/Utilities/Release/linux64_release.cmake
+++ b/Utilities/Release/linux64_release.cmake
@@ -3,8 +3,8 @@ set(BOOTSTRAP_ARGS "--docdir=doc/cmake")
set(HOST linux64)
set(MAKE_PROGRAM "make")
set(CPACK_BINARY_GENERATORS "STGZ TGZ")
-set(CC /opt/gcc-6.1.0/bin/gcc)
-set(CXX /opt/gcc-6.1.0/bin/g++)
+set(CC /opt/gcc-8.2.0/bin/gcc)
+set(CXX /opt/gcc-8.2.0/bin/g++)
set(CFLAGS "")
set(CXXFLAGS "")
set(qt_prefix "/home/kitware/qt-5.7.0")
@@ -29,19 +29,22 @@ CURSES_LIBRARY:FILEPATH=/home/kitware/ncurses-5.9/lib/libncurses.a
CURSES_INCLUDE_PATH:PATH=/home/kitware/ncurses-5.9/include
FORM_LIBRARY:FILEPATH=/home/kitware/ncurses-5.9/lib/libform.a
CMAKE_USE_OPENSSL:BOOL=ON
-OPENSSL_CRYPTO_LIBRARY:FILEPATH=/home/kitware/openssl-1.0.2j/lib/libcrypto.a
-OPENSSL_INCLUDE_DIR:PATH=/home/kitware/openssl-1.0.2j/include
-OPENSSL_SSL_LIBRARY:FILEPATH=/home/kitware/openssl-1.0.2j/lib/libssl.a
+OPENSSL_CRYPTO_LIBRARY:STRING=/home/kitware/openssl-1.1.1/lib/libcrypto.a;-pthread
+OPENSSL_INCLUDE_DIR:PATH=/home/kitware/openssl-1.1.1/include
+OPENSSL_SSL_LIBRARY:FILEPATH=/home/kitware/openssl-1.1.1/lib/libssl.a
PYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3
CPACK_SYSTEM_NAME:STRING=Linux-x86_64
-BUILD_QtDialog:BOOL:=TRUE
+BUILD_CursesDialog:BOOL=ON
+BUILD_QtDialog:BOOL=TRUE
CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
-CMake_ENABLE_SERVER_MODE:BOOL=TRUE
CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:STRING=3
-CMake_INSTALL_DEPENDENCIES:BOOL=ON
CMAKE_PREFIX_PATH:STRING=${qt_prefix}
CMake_QT_STATIC_QXcbIntegrationPlugin_LIBRARIES:STRING=${qt_xcb_libs}
")
+set(ENV [[
+export CMAKE_PREFIX_PATH=/opt/binutils-2.31
+]])
+set(SIGN "")
# Exclude Qt5 tests because our Qt5 is static.
set(EXTRA_CTEST_ARGS "-E Qt5")
diff --git a/Utilities/Release/osx_release.cmake b/Utilities/Release/osx_release.cmake
index 36498a7ce..ac35872ea 100644
--- a/Utilities/Release/osx_release.cmake
+++ b/Utilities/Release/osx_release.cmake
@@ -19,8 +19,8 @@ CMAKE_OSX_ARCHITECTURES:STRING=x86_64
CMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.7
CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
CPACK_SYSTEM_NAME:STRING=Darwin-x86_64
+BUILD_CursesDialog:BOOL=ON
BUILD_QtDialog:BOOL=TRUE
-CMake_ENABLE_SERVER_MODE:BOOL=TRUE
CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:STRING=3
CMake_INSTALL_DEPENDENCIES:BOOL=ON
CMAKE_SKIP_RPATH:BOOL=TRUE
@@ -29,5 +29,6 @@ CMake_TEST_NO_FindPackageModeMakefileTest:BOOL=TRUE
set(ENV [[
export CMAKE_PREFIX_PATH='/Users/kitware/SDKs/qt-5.6.2-clang-x64'
]])
+set(SIGN "")
get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/release_cmake.sh.in b/Utilities/Release/release_cmake.sh.in
index f363b3d8a..696a3f445 100755
--- a/Utilities/Release/release_cmake.sh.in
+++ b/Utilities/Release/release_cmake.sh.in
@@ -150,7 +150,7 @@ for GEN in $generators; do
check_exit_value $? "Create $GEN package" || exit 1
done
-
+@SIGN@
echo "End release"
date
diff --git a/Utilities/Release/win32_release.cmake b/Utilities/Release/win32_release.cmake
index df9fe275b..468e5f437 100644
--- a/Utilities/Release/win32_release.cmake
+++ b/Utilities/Release/win32_release.cmake
@@ -1,33 +1,53 @@
-set(CMAKE_RELEASE_DIRECTORY "c:/msys64/home/dashboard/CMakeReleaseDirectory")
+set(CMAKE_RELEASE_DIRECTORY "c:/msys64/home/dashboard/CMakeReleaseDirectory32")
set(CONFIGURE_WITH_CMAKE TRUE)
set(CMAKE_CONFIGURE_PATH "c:/Program\\ Files/CMake/bin/cmake.exe")
-set(PROCESSORS 8)
-set(HOST dash3win7)
+set(PROCESSORS 16)
+set(HOST win32)
set(RUN_LAUNCHER ~/rel/run)
set(CPACK_BINARY_GENERATORS "WIX ZIP")
set(CPACK_SOURCE_GENERATORS "ZIP")
set(MAKE_PROGRAM "ninja")
-set(MAKE "${MAKE_PROGRAM} -j8")
+set(MAKE "${MAKE_PROGRAM} -j16")
+set(qt_prefix "c:/Qt/5.12.1/msvc2017-32-w7-mt")
+set(qt_win_libs
+ ${qt_prefix}/plugins/platforms/qwindows.lib
+ ${qt_prefix}/plugins/styles/qwindowsvistastyle.lib
+ ${qt_prefix}/lib/Qt5EventDispatcherSupport.lib
+ ${qt_prefix}/lib/Qt5FontDatabaseSupport.lib
+ ${qt_prefix}/lib/Qt5ThemeSupport.lib
+ ${qt_prefix}/lib/qtfreetype.lib
+ ${qt_prefix}/lib/qtlibpng.lib
+ imm32.lib
+ wtsapi32.lib
+ )
set(INITIAL_CACHE "CMAKE_BUILD_TYPE:STRING=Release
CMAKE_DOC_DIR:STRING=doc/cmake
CMAKE_USE_OPENSSL:BOOL=OFF
CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
CMAKE_Fortran_COMPILER:FILEPATH=FALSE
CMAKE_GENERATOR:INTERNAL=Ninja
-BUILD_QtDialog:BOOL:=TRUE
-CMake_ENABLE_SERVER_MODE:BOOL=TRUE
+BUILD_QtDialog:BOOL=TRUE
CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:STRING=3
-CMake_INSTALL_DEPENDENCIES:BOOL=ON
-CMAKE_EXE_LINKER_FLAGS:STRING=-machine:x86 -subsystem:console,5.01
+CMAKE_C_FLAGS_RELEASE:STRING=-MT -O2 -Ob2 -DNDEBUG
+CMAKE_CXX_FLAGS_RELEASE:STRING=-MT -O2 -Ob2 -DNDEBUG
+CMAKE_EXE_LINKER_FLAGS:STRING=-machine:x86 -subsystem:console,6.01
+CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES:STRING=${qt_win_libs}
+CMAKE_PREFIX_PATH:STRING=${qt_prefix}
+CMake_TEST_Qt4:BOOL=OFF
+CMake_TEST_Qt5:BOOL=OFF
")
-set(ppflags "-D_WIN32_WINNT=0x501 -DNTDDI_VERSION=0x05010000 -D_USING_V110_SDK71_")
+set(ppflags "-D_WIN32_WINNT=0x601 -DNTDDI_VERSION=0x06010000")
set(CFLAGS "${ppflags}")
set(CXXFLAGS "${ppflags}")
-set(ENV ". ~/rel/env")
+set(ENV ". ~/rel/env32")
get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(GIT_EXTRA "git config core.autocrlf true")
if(CMAKE_CREATE_VERSION STREQUAL "nightly")
# Some tests fail spuriously too often.
- set(EXTRA_CTEST_ARGS "-E 'Qt5Autogen|ConsoleBuf'")
+ set(EXTRA_CTEST_ARGS "-E 'ConsoleBuf|Module.ExternalData'")
+ set(SIGN "")
+else()
+ string(APPEND INITIAL_CACHE "CMake_INSTALL_SIGNTOOL:STRING=signtool\n")
+ set(SIGN [[signtool sign -v -a -tr http://timestamp.digicert.com -fd sha256 -td sha256 -d "CMake Windows Installer" cmake-*.msi]])
endif()
include(${path}/release_cmake.cmake)
diff --git a/Utilities/Release/win64_release.cmake b/Utilities/Release/win64_release.cmake
index ab52d794d..5a93ce6b3 100644
--- a/Utilities/Release/win64_release.cmake
+++ b/Utilities/Release/win64_release.cmake
@@ -1,27 +1,42 @@
set(CMAKE_RELEASE_DIRECTORY "c:/msys64/home/dashboard/CMakeReleaseDirectory64")
set(CONFIGURE_WITH_CMAKE TRUE)
set(CMAKE_CONFIGURE_PATH "c:/Program\\ Files/CMake/bin/cmake.exe")
-set(PROCESSORS 8)
-set(HOST dash3win7)
-set(SCRIPT_NAME dash3win7x64)
+set(PROCESSORS 16)
+set(HOST win64)
set(RUN_LAUNCHER ~/rel/run)
set(CPACK_BINARY_GENERATORS "WIX ZIP")
set(CPACK_SOURCE_GENERATORS "")
set(MAKE_PROGRAM "ninja")
-set(MAKE "${MAKE_PROGRAM} -j8")
+set(MAKE "${MAKE_PROGRAM} -j16")
+set(qt_prefix "c:/Qt/5.12.1/msvc2017-64-w7-mt")
+set(qt_win_libs
+ ${qt_prefix}/plugins/platforms/qwindows.lib
+ ${qt_prefix}/plugins/styles/qwindowsvistastyle.lib
+ ${qt_prefix}/lib/Qt5EventDispatcherSupport.lib
+ ${qt_prefix}/lib/Qt5FontDatabaseSupport.lib
+ ${qt_prefix}/lib/Qt5ThemeSupport.lib
+ ${qt_prefix}/lib/qtfreetype.lib
+ ${qt_prefix}/lib/qtlibpng.lib
+ imm32.lib
+ wtsapi32.lib
+ )
set(INITIAL_CACHE "CMAKE_BUILD_TYPE:STRING=Release
CMAKE_DOC_DIR:STRING=doc/cmake
CMAKE_USE_OPENSSL:BOOL=OFF
CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE
CMAKE_Fortran_COMPILER:FILEPATH=FALSE
CMAKE_GENERATOR:INTERNAL=Ninja
-BUILD_QtDialog:BOOL:=TRUE
-CMake_ENABLE_SERVER_MODE:BOOL=TRUE
+BUILD_QtDialog:BOOL=TRUE
CMake_GUI_DISTRIBUTE_WITH_Qt_LGPL:STRING=3
-CMake_INSTALL_DEPENDENCIES:BOOL=ON
-CMAKE_EXE_LINKER_FLAGS:STRING=-machine:x64 -subsystem:console,5.02
+CMAKE_C_FLAGS_RELEASE:STRING=-MT -O2 -Ob2 -DNDEBUG
+CMAKE_CXX_FLAGS_RELEASE:STRING=-MT -O2 -Ob2 -DNDEBUG
+CMAKE_EXE_LINKER_FLAGS:STRING=-machine:x64 -subsystem:console,6.01
+CMake_QT_STATIC_QWindowsIntegrationPlugin_LIBRARIES:STRING=${qt_win_libs}
+CMAKE_PREFIX_PATH:STRING=${qt_prefix}
+CMake_TEST_Qt4:BOOL=OFF
+CMake_TEST_Qt5:BOOL=OFF
")
-set(ppflags "-D_WIN32_WINNT=0x502 -DNTDDI_VERSION=0x05020000 -D_USING_V110_SDK71_")
+set(ppflags "-D_WIN32_WINNT=0x601 -DNTDDI_VERSION=0x06010000")
set(CFLAGS "${ppflags}")
set(CXXFLAGS "${ppflags}")
set(ENV ". ~/rel/env64")
@@ -29,6 +44,10 @@ get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(GIT_EXTRA "git config core.autocrlf true")
if(CMAKE_CREATE_VERSION STREQUAL "nightly")
# Some tests fail spuriously too often.
- set(EXTRA_CTEST_ARGS "-E 'Qt5Autogen|ConsoleBuf'")
+ set(EXTRA_CTEST_ARGS "-E 'ConsoleBuf|Module.ExternalData'")
+ set(SIGN "")
+else()
+ string(APPEND INITIAL_CACHE "CMake_INSTALL_SIGNTOOL:STRING=signtool\n")
+ set(SIGN [[signtool sign -v -a -tr http://timestamp.digicert.com -fd sha256 -td sha256 -d "CMake Windows Installer" cmake-*.msi]])
endif()
include(${path}/release_cmake.cmake)
diff --git a/Utilities/Scripts/BoostScanDeps.cmake b/Utilities/Scripts/BoostScanDeps.cmake
index 2fd8f8633..28a94ce89 100644
--- a/Utilities/Scripts/BoostScanDeps.cmake
+++ b/Utilities/Scripts/BoostScanDeps.cmake
@@ -39,29 +39,40 @@ function(_Boost_FIND_COMPONENT_DEPENDENCIES component includedir _ret_libs)
# Start by finding all headers for the component; header
# dependencies via #include will be solved by future passes
+ file(GLOB_RECURSE _boost_mpi_python_headers
+ RELATIVE "${includedir}"
+ "${includedir}/boost/mpi/python/*")
+ list(INSERT _boost_mpi_python_headers 0 "boost/mpi/python.hpp")
+
+ file(GLOB_RECURSE _boost_python_numpy_headers
+ RELATIVE "${includedir}"
+ "${includedir}/boost/python/numpy/*")
+ list(INSERT _boost_python_numpy_headers 0 "boost/python/numpy.hpp")
# Special-case since it is part of mpi; look only in boost/mpi/python*
if(component STREQUAL "mpi_python")
- set(_boost_DEPS "python")
+ set(_boost_DEPS "python\${component_python_version}")
set(library_component TRUE)
- file(GLOB_RECURSE _boost_unprocessed_headers
- RELATIVE "${includedir}"
- "${includedir}/boost/mpi/python/*")
- list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/mpi/python.hpp")
+ set(_boost_unprocessed_headers ${_boost_mpi_python_headers})
+ # Special-case since it is part of python; look only in boost/python/numpy*
+ elseif(component STREQUAL "numpy")
+ set(_boost_DEPS "python\${component_python_version}")
+ set(library_component TRUE)
+ set(_boost_unprocessed_headers ${_boost_python_numpy_headers})
# Special-case since it is a serialization variant; look in boost/serialization
elseif(component STREQUAL "wserialization")
set(library_component TRUE)
file(GLOB_RECURSE _boost_unprocessed_headers
RELATIVE "${includedir}"
"${includedir}/boost/serialization/*")
- list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/serialization.hpp")
+ list(INSERT _boost_unprocessed_headers 0 "boost/serialization.hpp")
# Not really a library in its own right, but treat it as one
elseif(component STREQUAL "math")
set(library_component TRUE)
file(GLOB_RECURSE _boost_unprocessed_headers
RELATIVE "${includedir}"
"${includedir}/boost/math/*")
- list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/math.hpp")
+ list(INSERT _boost_unprocessed_headers 0 "boost/math.hpp")
# Single test header
elseif(component STREQUAL "unit_test_framework")
set(library_component TRUE)
@@ -79,7 +90,8 @@ function(_Boost_FIND_COMPONENT_DEPENDENCIES component includedir _ret_libs)
file(GLOB_RECURSE _boost_unprocessed_headers
RELATIVE "${includedir}"
"${includedir}/boost/${component}/*")
- list(INSERT _boost_unprocessed_headers 0 "${includedir}/boost/${component}.hpp")
+ list(INSERT _boost_unprocessed_headers 0 "boost/${component}.hpp")
+ list(REMOVE_ITEM _boost_unprocessed_headers ${_boost_mpi_python_headers} ${_boost_python_numpy_headers})
endif()
while(_boost_unprocessed_headers)
@@ -102,6 +114,8 @@ function(_Boost_FIND_COMPONENT_DEPENDENCIES component includedir _ret_libs)
foreach(line ${_boost_header_deps})
string(REGEX REPLACE "^[ \t]*#[ \t]*define[ \t][ \t]*BOOST_LIB_NAME[ \t][ \t]*boost_([^ \t][^ \t]*).*" "\\1" _boost_component_match "${line}")
+ string(REPLACE "python3" "python" _boost_component_match "${_boost_component_match}")
+ string(REPLACE "numpy3" "numpy" _boost_component_match "${_boost_component_match}")
list(FIND _boost_DEPS "${_boost_component_match}" _boost_dep_found)
if(_boost_component_match STREQUAL "bzip2" OR
_boost_component_match STREQUAL "zlib")
@@ -119,6 +133,12 @@ function(_Boost_FIND_COMPONENT_DEPENDENCIES component includedir _ret_libs)
# hard dependency (handle as special-case for mpi_python).
continue()
endif()
+ if(component STREQUAL "python" AND
+ boost_component_match STREQUAL "numpy")
+ # Optional python dependency; skip to avoid making it a
+ # hard dependency (handle as special-case for numpy).
+ continue()
+ endif()
if (_boost_dep_found EQUAL -1 AND
NOT "${_boost_component_match}" STREQUAL "${component}")
list(APPEND _boost_DEPS "${_boost_component_match}")
@@ -168,6 +188,11 @@ if(IS_DIRECTORY "${BOOST_DIR}/boost/mpi" AND
IS_DIRECTORY "${BOOST_DIR}/boost/python")
list(APPEND boost_components "mpi_python")
endif()
+# Special-case numpy, since it's a part of python
+if(IS_DIRECTORY "${BOOST_DIR}/boost/python" AND
+ IS_DIRECTORY "${BOOST_DIR}/boost/python/numpy")
+ list(APPEND boost_components "numpy")
+endif()
# Special-case wserialization, which is a variant of serialization
if(IS_DIRECTORY "${BOOST_DIR}/boost/serialization")
list(APPEND boost_components "wserialization")
diff --git a/Utilities/Scripts/clang-format.bash b/Utilities/Scripts/clang-format.bash
index edcda77b9..7ca4433a8 100755
--- a/Utilities/Scripts/clang-format.bash
+++ b/Utilities/Scripts/clang-format.bash
@@ -78,8 +78,8 @@ test "$#" = 0 || die "$usage"
# Find a default tool.
tools='
+ clang-format-6.0
clang-format
- clang-format-3.8
'
if test "x$clang_format" = "x"; then
for tool in $tools; do
@@ -92,7 +92,12 @@ fi
# Verify that we have a tool.
if ! type -p "$clang_format" >/dev/null; then
- echo "Unable to locate '$clang_format'"
+ echo "Unable to locate a 'clang-format' tool."
+ exit 1
+fi
+
+if ! "$clang_format" --version | grep 'clang-format version 6\.0' >/dev/null 2>/dev/null; then
+ echo "clang-format version 6.0 is required (exactly)"
exit 1
fi
@@ -110,8 +115,10 @@ esac
$git_ls |
# Select sources with our attribute.
- git check-attr --stdin format.clang-format |
- sed -n '/: format\.clang-format: set$/ {s/:[^:]*:[^:]*$//p}' |
+ git check-attr --stdin format.clang-format-6.0 |
+ grep -e ': format\.clang-format-6\.0: set$' |
+ sed -n 's/:[^:]*:[^:]*$//p' |
# Update sources in-place.
- xargs -d '\n' "$clang_format" -i
+ tr '\n' '\0' |
+ xargs -0 "$clang_format" -i
diff --git a/Utilities/Scripts/update-curl.bash b/Utilities/Scripts/update-curl.bash
index 465841a02..5c2a331c0 100755
--- a/Utilities/Scripts/update-curl.bash
+++ b/Utilities/Scripts/update-curl.bash
@@ -8,14 +8,13 @@ readonly name="curl"
readonly ownership="Curl Upstream <curl-library@cool.haxx.se>"
readonly subtree="Utilities/cmcurl"
readonly repo="https://github.com/curl/curl.git"
-readonly tag="curl-7_54_1"
+readonly tag="curl-7_65_0"
readonly shortlog=false
readonly paths="
CMake/*
CMakeLists.txt
COPYING
include/curl/*.h
- include/curl/curlbuild.h.cmake
lib/*.c
lib/*.h
lib/CMakeLists.txt
@@ -32,6 +31,15 @@ extract_source () {
git_archive
pushd "${extractdir}/${name}-reduced"
rm lib/config-*.h
+ chmod a-x lib/connect.c
+ for f in \
+ lib/cookie.c \
+ lib/krb5.c \
+ lib/security.c \
+ ; do
+ iconv -f LATIN1 -t UTF8 $f -o $f.utf-8
+ mv $f.utf-8 $f
+ done
echo "* -whitespace" > .gitattributes
popd
}
diff --git a/Utilities/Scripts/update-expat.bash b/Utilities/Scripts/update-expat.bash
index 4ac5ef32c..0b52ddc67 100755
--- a/Utilities/Scripts/update-expat.bash
+++ b/Utilities/Scripts/update-expat.bash
@@ -8,7 +8,7 @@ readonly name="expat"
readonly ownership="Expat Upstream <kwrobot@kitware.com>"
readonly subtree="Utilities/cmexpat"
readonly repo="https://github.com/libexpat/libexpat.git"
-readonly tag="R_2_2_3"
+readonly tag="R_2_2_7"
readonly shortlog=false
readonly paths="
expat/lib/asciitab.h
diff --git a/Utilities/Scripts/update-gitsetup.bash b/Utilities/Scripts/update-gitsetup.bash
index 8f0da7682..70fb16511 100755
--- a/Utilities/Scripts/update-gitsetup.bash
+++ b/Utilities/Scripts/update-gitsetup.bash
@@ -11,6 +11,13 @@ readonly repo="https://gitlab.kitware.com/utils/gitsetup.git"
readonly tag="setup"
readonly shortlog=false
readonly paths="
+ .gitattributes
+ LICENSE
+ NOTICE
+ README
+ setup-hooks
+ setup-user
+ tips
"
extract_source () {
diff --git a/Utilities/Scripts/update-libarchive.bash b/Utilities/Scripts/update-libarchive.bash
index 41c6a66d6..31886584f 100755
--- a/Utilities/Scripts/update-libarchive.bash
+++ b/Utilities/Scripts/update-libarchive.bash
@@ -8,7 +8,7 @@ readonly name="LibArchive"
readonly ownership="LibArchive Upstream <libarchive-discuss@googlegroups.com>"
readonly subtree="Utilities/cmlibarchive"
readonly repo="https://github.com/libarchive/libarchive.git"
-readonly tag="v3.3.1"
+readonly tag="v3.3.3"
readonly shortlog=false
readonly paths="
CMakeLists.txt
diff --git a/Utilities/Scripts/update-liblzma.bash b/Utilities/Scripts/update-liblzma.bash
index 088eb91e0..fdf66b3ec 100755
--- a/Utilities/Scripts/update-liblzma.bash
+++ b/Utilities/Scripts/update-liblzma.bash
@@ -7,8 +7,8 @@ shopt -s dotglob
readonly name="liblzma"
readonly ownership="liblzma upstream <xz-devel@tukaani.org>"
readonly subtree="Utilities/cmliblzma"
-readonly repo="http://git.tukaani.org/xz.git"
-readonly tag="v5.0.8"
+readonly repo="https://git.tukaani.org/xz.git"
+readonly tag="v5.2.4"
readonly shortlog=false
readonly paths="
COPYING
@@ -24,6 +24,10 @@ extract_source () {
mv src/common .
mv src/liblzma .
rmdir src
+ rm liblzma/Makefile.*
+ rm liblzma/*/Makefile.*
+ rm liblzma/liblzma.map
+ rm liblzma/validate_map.sh
popd
}
diff --git a/Utilities/Scripts/update-libuv.bash b/Utilities/Scripts/update-libuv.bash
index d7a7d1f28..6d423a764 100755
--- a/Utilities/Scripts/update-libuv.bash
+++ b/Utilities/Scripts/update-libuv.bash
@@ -20,6 +20,8 @@ extract_source () {
git_archive
pushd "${extractdir}/${name}-reduced"
echo "* -whitespace" > .gitattributes
+ echo >> src/unix/aix-common.c
+ echo >> src/unix/ibmi.c
popd
}
diff --git a/Utilities/Scripts/update-third-party.bash b/Utilities/Scripts/update-third-party.bash
index 670946ef4..fcab871bd 100644
--- a/Utilities/Scripts/update-third-party.bash
+++ b/Utilities/Scripts/update-third-party.bash
@@ -71,8 +71,6 @@ warn () {
readonly regex_date='20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
readonly basehash_regex="$name $regex_date ([0-9a-f]*)"
-readonly basehash="$( git rev-list --author="$ownership" --grep="$basehash_regex" -n 1 HEAD )"
-readonly upstream_old_short="$( git cat-file commit "$basehash" | sed -n '/'"$basehash_regex"'/ {s/.*(//;s/)//;p}' | egrep '^[0-9a-f]+$' )"
########################################################################
# Sanity checking
@@ -87,6 +85,18 @@ readonly upstream_old_short="$( git cat-file commit "$basehash" | sed -n '/'"$ba
die "'repo' is empty"
[ -n "$tag" ] || \
die "'tag' is empty"
+
+# Check for an empty destination directory on disk. By checking on disk and
+# not in the repo it allows a library to be freshly re-inialized in a single
+# commit rather than first deleting the old copy in one commit and adding the
+# new copy in a seperate commit.
+if [ ! -d "$(git rev-parse --show-toplevel)/$subtree" ]; then
+ readonly basehash=""
+else
+ readonly basehash="$( git rev-list --author="$ownership" --grep="$basehash_regex" -n 1 HEAD )"
+fi
+readonly upstream_old_short="$( git cat-file commit "$basehash" | sed -n '/'"$basehash_regex"'/ {s/.*(//;s/)//;p}' | egrep '^[0-9a-f]+$' )"
+
[ -n "$basehash" ] || \
warn "'basehash' is empty; performing initial import"
readonly do_shortlog="${shortlog-false}"
@@ -104,6 +114,8 @@ trap "rm -rf '$workdir'" EXIT
git clone "$repo" "$upstreamdir"
if [ -n "$basehash" ]; then
+ # Remove old worktrees
+ git worktree prune
# Use the existing package's history
git worktree add "$extractdir" "$basehash"
# Clear out the working tree
@@ -163,13 +175,17 @@ popd
if [ -n "$basehash" ]; then
git merge --log -s recursive "-Xsubtree=$subtree/" --no-commit "upstream-$name"
else
+ # Note: on Windows 'git merge --help' will open a browser, and the check
+ # will fail, so use the flag by default.
unrelated_histories_flag=""
- if git merge --help | grep -q -e allow-unrelated-histories; then
+ if git --version | grep -q windows; then
+ unrelated_histories_flag="--allow-unrelated-histories "
+ elif git merge --help | grep -q -e allow-unrelated-histories; then
unrelated_histories_flag="--allow-unrelated-histories "
fi
readonly unrelated_histories_flag
- git fetch "$extractdir" "upstream-$name:upstream-$name"
+ git fetch "$extractdir" "+upstream-$name:upstream-$name"
git merge --log -s ours --no-commit $unrelated_histories_flag "upstream-$name"
git read-tree -u --prefix="$subtree/" "upstream-$name"
fi
diff --git a/Utilities/Sphinx/CMakeLists.txt b/Utilities/Sphinx/CMakeLists.txt
index a29380c95..c5b2bfe2e 100644
--- a/Utilities/Sphinx/CMakeLists.txt
+++ b/Utilities/Sphinx/CMakeLists.txt
@@ -3,7 +3,7 @@
if(NOT CMake_SOURCE_DIR)
set(CMakeHelp_STANDALONE 1)
- cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR)
+ cmake_minimum_required(VERSION 3.1...3.14 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)
@@ -17,6 +17,7 @@ if(NOT CMake_SOURCE_DIR)
endif()
project(CMakeHelp NONE)
+option(SPHINX_INFO "Build Info manual with Sphinx" OFF)
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)
@@ -32,7 +33,7 @@ separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
mark_as_advanced(SPHINX_TEXT)
mark_as_advanced(SPHINX_FLAGS)
-if(NOT SPHINX_MAN AND NOT SPHINX_HTML AND NOT SPHINX_SINGLEHTML AND NOT SPHINX_QTHELP AND NOT SPHINX_TEXT)
+if(NOT SPHINX_INFO AND 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!")
@@ -66,6 +67,24 @@ endif()
if(SPHINX_TEXT)
list(APPEND doc_formats text)
endif()
+if(SPHINX_INFO)
+ find_program(MAKEINFO_EXECUTABLE
+ NAMES makeinfo
+ DOC "makeinfo tool"
+ )
+ if (NOT MAKEINFO_EXECUTABLE)
+ message(FATAL_ERROR "MAKEINFO_EXECUTABLE (makeinfo) not found!")
+ endif()
+ list(APPEND doc_formats texinfo)
+
+ # Sphinx texinfo builder supports .info, .txt, .html and .pdf output.
+ # SPHINX_INFO controls the .info output.
+ set(texinfo_extra_commands
+ COMMAND ${MAKEINFO_EXECUTABLE} --no-split -o
+ ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
+ ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.texi
+ )
+endif()
if(SPHINX_QTHELP)
find_package(PythonInterp REQUIRED)
@@ -143,6 +162,14 @@ if(CMake_SPHINX_DEPEND_ON_EXECUTABLES)
endforeach()
endif()
+if(SPHINX_INFO)
+ CMake_OPTIONAL_COMPONENT(sphinx-info)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/texinfo/cmake.info
+ DESTINATION ${CMAKE_INFO_DIR}
+ ${COMPONENT}
+ )
+endif()
+
if(SPHINX_MAN)
file(GLOB man_rst RELATIVE ${CMake_SOURCE_DIR}/Help/manual
${CMake_SOURCE_DIR}/Help/manual/*.[1-9].rst)
diff --git a/Utilities/Sphinx/cmake.py b/Utilities/Sphinx/cmake.py
index cfda2d479..d903dbe39 100644
--- a/Utilities/Sphinx/cmake.py
+++ b/Utilities/Sphinx/cmake.py
@@ -4,14 +4,58 @@
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
+# Override much of pygments' CMakeLexer.
+# We need to parse CMake syntax definitions, not CMake code.
+
+# For hard test cases that use much of the syntax below, see
+# - module/FindPkgConfig.html (with "glib-2.0>=2.10 gtk+-2.0" and similar)
+# - module/ExternalProject.html (with http:// https:// git@; also has command options -E --build)
+# - manual/cmake-buildsystem.7.html (with nested $<..>; relative and absolute paths, "::")
+
from pygments.lexers import CMakeLexer
-from pygments.token import Name, Operator
+from pygments.token import Name, Operator, Punctuation, String, Text, Comment, Generic, Whitespace, Number
from pygments.lexer import bygroups
-CMakeLexer.tokens["args"].append(('(\\$<)(.+?)(>)',
- bygroups(Operator, Name.Variable, Operator)))
+
+# Notes on regular expressions below:
+# - [\.\+-] are needed for string constants like gtk+-2.0
+# - Unix paths are recognized by '/'; support for Windows paths may be added if needed
+# - (\\.) allows for \-escapes (used in manual/cmake-language.7)
+# - $<..$<..$>..> nested occurence in cmake-buildsystem
+# - Nested variable evaluations are only supported in a limited capacity. Only
+# one level of nesting is supported and at most one nested variable can be present.
+
+CMakeLexer.tokens["root"] = [
+ (r'\b(\w+)([ \t]*)(\()', bygroups(Name.Function, Text, Name.Function), '#push'), # fctn(
+ (r'\(', Name.Function, '#push'),
+ (r'\)', Name.Function, '#pop'),
+ (r'\[', Punctuation, '#push'),
+ (r'\]', Punctuation, '#pop'),
+ (r'[|;,.=*\-]', Punctuation),
+ (r'\\\\', Punctuation), # used in commands/source_group
+ (r'[:]', Operator),
+ (r'[<>]=', Punctuation), # used in FindPkgConfig.cmake
+ (r'\$<', Operator, '#push'), # $<...>
+ (r'<[^<|]+?>(\w*\.\.\.)?', Name.Variable), # <expr>
+ (r'(\$\w*\{)([^\}\$]*)?(?:(\$\w*\{)([^\}]+?)(\}))?([^\}]*?)(\})', # ${..} $ENV{..}, possibly nested
+ bygroups(Operator, Name.Tag, Operator, Name.Tag, Operator, Name.Tag, Operator)),
+ (r'([A-Z]+\{)(.+?)(\})', bygroups(Operator, Name.Tag, Operator)), # DATA{ ...}
+ (r'[a-z]+(@|(://))((\\.)|[\w.+-:/\\])+', Name.Attribute), # URL, git@, ...
+ (r'/\w[\w\.\+-/\\]*', Name.Attribute), # absolute path
+ (r'/', Name.Attribute),
+ (r'\w[\w\.\+-]*/[\w.+-/\\]*', Name.Attribute), # relative path
+ (r'[A-Z]((\\.)|[\w.+-])*[a-z]((\\.)|[\w.+-])*', Name.Builtin), # initial A-Z, contains a-z
+ (r'@?[A-Z][A-Z0-9_]*', Name.Constant),
+ (r'[a-z_]((\\;)|(\\ )|[\w.+-])*', Name.Builtin),
+ (r'[0-9][0-9\.]*', Number),
+ (r'(?s)"(\\"|[^"])*"', String), # "string"
+ (r'\.\.\.', Name.Variable),
+ (r'<', Operator, '#push'), # <..|..> is different from <expr>
+ (r'>', Operator, '#pop'),
+ (r'\n', Whitespace),
+ (r'[ \t]+', Whitespace),
+ (r'#.*\n', Comment),
+ # (r'[^<>\])\}\|$"# \t\n]+', Name.Exception), # fallback, for debugging only
+]
# Monkey patch for sphinx generating invalid content for qcollectiongenerator
# https://bitbucket.org/birkenfeld/sphinx/issue/1435/qthelp-builder-should-htmlescape-keywords
@@ -144,6 +188,8 @@ class _cmake_index_entry:
_cmake_index_objs = {
'command': _cmake_index_entry('command'),
+ 'cpack_gen': _cmake_index_entry('cpack generator'),
+ 'envvar': _cmake_index_entry('envvar'),
'generator': _cmake_index_entry('generator'),
'manual': _cmake_index_entry('manual'),
'module': _cmake_index_entry('module'),
@@ -278,7 +324,7 @@ class CMakeXRefRole(XRefRole):
# We cannot insert index nodes using the result_nodes method
# because CMakeXRefRole is processed before substitution_reference
# nodes are evaluated so target nodes (with 'ids' fields) would be
- # duplicated in each evaluted substitution replacement. The
+ # duplicated in each evaluated substitution replacement. The
# docutils substitution transform does not allow this. Instead we
# use our own CMakeXRefTransform below to add index entries after
# substitutions are completed.
@@ -324,6 +370,8 @@ class CMakeDomain(Domain):
label = 'CMake'
object_types = {
'command': ObjType('command', 'command'),
+ 'cpack_gen': ObjType('cpack_gen', 'cpack_gen'),
+ 'envvar': ObjType('envvar', 'envvar'),
'generator': ObjType('generator', 'generator'),
'variable': ObjType('variable', 'variable'),
'module': ObjType('module', 'module'),
@@ -339,6 +387,7 @@ class CMakeDomain(Domain):
}
directives = {
'command': CMakeObject,
+ 'envvar': CMakeObject,
'variable': CMakeObject,
# Other object types cannot be created except by the CMakeTransform
# 'generator': CMakeObject,
@@ -355,6 +404,8 @@ class CMakeDomain(Domain):
}
roles = {
'command': CMakeXRefRole(fix_parens = True, lowercase = True),
+ 'cpack_gen': CMakeXRefRole(),
+ 'envvar': CMakeXRefRole(),
'generator': CMakeXRefRole(),
'variable': CMakeXRefRole(),
'module': CMakeXRefRole(),
diff --git a/Utilities/Sphinx/conf.py.in b/Utilities/Sphinx/conf.py.in
index 7878ad20a..70ba08032 100644
--- a/Utilities/Sphinx/conf.py.in
+++ b/Utilities/Sphinx/conf.py.in
@@ -15,8 +15,10 @@ project = 'CMake'
copyright = '@conf_copyright@'
version = '@conf_version@' # feature version
release = '@conf_release@' # full version string
+pygments_style = 'colors.CMakeTemplateStyle'
primary_domain = 'cmake'
+highlight_language = 'none'
exclude_patterns = [
'dev', # ignore developer-only documentation
diff --git a/Utilities/Sphinx/create_identifiers.py b/Utilities/Sphinx/create_identifiers.py
index 3fe3fcbe5..6716b480d 100755
--- a/Utilities/Sphinx/create_identifiers.py
+++ b/Utilities/Sphinx/create_identifiers.py
@@ -21,7 +21,10 @@ newlines = []
for line in lines:
mapping = (("command", "command"),
+ ("cpack generator", "cpack_gen"),
+ ("envvar", "envvar"),
("variable", "variable"),
+ ("generator", "generator"),
("target property", "prop_tgt"),
("test property", "prop_test"),
("source file property", "prop_sf"),
diff --git a/Utilities/Sphinx/static/cmake-favicon.ico b/Utilities/Sphinx/static/cmake-favicon.ico
index fce8f922f..ae529f54e 100644
--- a/Utilities/Sphinx/static/cmake-favicon.ico
+++ 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
index 2039c25b0..db9458dc1 100644
--- a/Utilities/Sphinx/static/cmake-logo-16.png
+++ 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
index 2a326d47d..b082edec8 100644
--- a/Utilities/Sphinx/static/cmake.css
+++ b/Utilities/Sphinx/static/cmake.css
@@ -6,3 +6,13 @@
div.sphinxsidebarwrapper {
word-wrap: break-word;
}
+
+/* Make links inside parsed-literal blocks more obvious
+ by using a background color and increased line spacing
+ to make them look boxed. */
+.literal-block {
+ line-height: 1.4;
+}
+.literal-block a.reference.internal {
+ background-color: #dfdfdf;
+}
diff --git a/Utilities/cmThirdParty.h.in b/Utilities/cmThirdParty.h.in
index a547f0da7..1456e34c7 100644
--- a/Utilities/cmThirdParty.h.in
+++ b/Utilities/cmThirdParty.h.in
@@ -15,6 +15,6 @@
#cmakedefine CMAKE_USE_SYSTEM_JSONCPP
#cmakedefine CMAKE_USE_SYSTEM_LIBRHASH
#cmakedefine CMAKE_USE_SYSTEM_LIBUV
-#cmakedefine CTEST_USE_XMLRPC
+#cmakedefine CMAKE_USE_SYSTEM_ZSTD
#endif
diff --git a/Utilities/cm_bzlib.h b/Utilities/cm_bzlib.h
index e7f6d8990..8669e9e6e 100644
--- a/Utilities/cm_bzlib.h
+++ b/Utilities/cm_bzlib.h
@@ -6,9 +6,9 @@
/* Use the bzip2 library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_BZIP2
-#include <bzlib.h>
+# include <bzlib.h>
#else
-#include <cmbzip2/bzlib.h>
+# include <cmbzip2/bzlib.h>
#endif
#endif
diff --git a/Utilities/cm_curl.h b/Utilities/cm_curl.h
index fc2b8ab8a..673f8ad95 100644
--- a/Utilities/cm_curl.h
+++ b/Utilities/cm_curl.h
@@ -6,9 +6,9 @@
/* Use the curl library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_CURL
-#include <curl/curl.h>
+# include <curl/curl.h>
#else
-#include <cmcurl/include/curl/curl.h>
+# include <cmcurl/include/curl/curl.h>
#endif
#endif
diff --git a/Utilities/cm_expat.h b/Utilities/cm_expat.h
index d87933715..fc5b39aba 100644
--- a/Utilities/cm_expat.h
+++ b/Utilities/cm_expat.h
@@ -6,9 +6,9 @@
/* Use the expat library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_EXPAT
-#include <expat.h>
+# include <expat.h>
#else
-#include <cmexpat/lib/expat.h>
+# include <cmexpat/lib/expat.h>
#endif
#endif
diff --git a/Utilities/cm_jsoncpp_reader.h b/Utilities/cm_jsoncpp_reader.h
index e78ec1e0c..23af65c61 100644
--- a/Utilities/cm_jsoncpp_reader.h
+++ b/Utilities/cm_jsoncpp_reader.h
@@ -6,9 +6,9 @@
/* Use the jsoncpp library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_JSONCPP
-#include <json/reader.h>
+# include <json/reader.h>
#else
-#include <cmjsoncpp/include/json/reader.h>
+# include <cmjsoncpp/include/json/reader.h>
#endif
#endif
diff --git a/Utilities/cm_jsoncpp_value.h b/Utilities/cm_jsoncpp_value.h
index cf3775859..742d99a01 100644
--- a/Utilities/cm_jsoncpp_value.h
+++ b/Utilities/cm_jsoncpp_value.h
@@ -6,9 +6,9 @@
/* Use the jsoncpp library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_JSONCPP
-#include <json/value.h>
+# include <json/value.h>
#else
-#include <cmjsoncpp/include/json/value.h>
+# include <cmjsoncpp/include/json/value.h>
#endif
#endif
diff --git a/Utilities/cm_jsoncpp_writer.h b/Utilities/cm_jsoncpp_writer.h
index 33b246847..d9e5d8217 100644
--- a/Utilities/cm_jsoncpp_writer.h
+++ b/Utilities/cm_jsoncpp_writer.h
@@ -6,9 +6,9 @@
/* Use the jsoncpp library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_JSONCPP
-#include <json/writer.h>
+# include <json/writer.h>
#else
-#include <cmjsoncpp/include/json/writer.h>
+# include <cmjsoncpp/include/json/writer.h>
#endif
#endif
diff --git a/Utilities/cm_kwiml.h b/Utilities/cm_kwiml.h
index 65cb35f96..566f67e43 100644
--- a/Utilities/cm_kwiml.h
+++ b/Utilities/cm_kwiml.h
@@ -6,11 +6,11 @@
/* Use the KWIML library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_KWIML
-#include <kwiml/abi.h>
-#include <kwiml/int.h>
+# include <kwiml/abi.h>
+# include <kwiml/int.h>
#else
-#include "KWIML/include/kwiml/abi.h"
-#include "KWIML/include/kwiml/int.h"
+# include "KWIML/include/kwiml/abi.h"
+# include "KWIML/include/kwiml/int.h"
#endif
#endif
diff --git a/Utilities/cm_libarchive.h b/Utilities/cm_libarchive.h
index 226952601..ea8e9db62 100644
--- a/Utilities/cm_libarchive.h
+++ b/Utilities/cm_libarchive.h
@@ -6,11 +6,11 @@
/* Use the libarchive configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_LIBARCHIVE
-#include <archive.h>
-#include <archive_entry.h>
+# include <archive.h>
+# include <archive_entry.h>
#else
-#include <cmlibarchive/libarchive/archive.h>
-#include <cmlibarchive/libarchive/archive_entry.h>
+# 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
index 013c724b9..0526036c6 100644
--- a/Utilities/cm_lzma.h
+++ b/Utilities/cm_lzma.h
@@ -6,9 +6,9 @@
/* Use the liblzma configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_LIBLZMA
-#include <lzma.h>
+# include <lzma.h>
#else
-#include <cmliblzma/liblzma/api/lzma.h>
+# include <cmliblzma/liblzma/api/lzma.h>
#endif
#endif
diff --git a/Utilities/cm_rhash.h b/Utilities/cm_rhash.h
index c79362775..03d9871f7 100644
--- a/Utilities/cm_rhash.h
+++ b/Utilities/cm_rhash.h
@@ -6,9 +6,9 @@
/* Use the LibRHash library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_LIBRHASH
-#include <rhash.h>
+# include <rhash.h>
#else
-#include <cmlibrhash/librhash/rhash.h>
+# include <cmlibrhash/librhash/rhash.h>
#endif
#endif
diff --git a/Utilities/cm_uv.h b/Utilities/cm_uv.h
index 6d4813de1..448f30d8d 100644
--- a/Utilities/cm_uv.h
+++ b/Utilities/cm_uv.h
@@ -6,9 +6,9 @@
/* Use the libuv library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_LIBUV
-#include <uv.h>
+# include <uv.h>
#else
-#include <cmlibuv/include/uv.h>
+# include <cmlibuv/include/uv.h>
#endif
#endif
diff --git a/Utilities/cm_zlib.h b/Utilities/cm_zlib.h
index 2aee9f194..2314183b1 100644
--- a/Utilities/cm_zlib.h
+++ b/Utilities/cm_zlib.h
@@ -6,9 +6,9 @@
/* Use the zlib library configured for CMake. */
#include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_ZLIB
-#include <zlib.h>
+# include <zlib.h>
#else
-#include <cmzlib/zlib.h>
+# include <cmzlib/zlib.h>
#endif
#endif
diff --git a/Utilities/cmcurl/CMake/CMakeConfigurableFile.in b/Utilities/cmcurl/CMake/CMakeConfigurableFile.in
index 4cf74a12b..df2c382e9 100644
--- a/Utilities/cmcurl/CMake/CMakeConfigurableFile.in
+++ b/Utilities/cmcurl/CMake/CMakeConfigurableFile.in
@@ -1,2 +1 @@
@CMAKE_CONFIGURABLE_FILE_CONTENT@
-
diff --git a/Utilities/cmcurl/CMake/CurlSymbolHiding.cmake b/Utilities/cmcurl/CMake/CurlSymbolHiding.cmake
index 9f7d29633..15ba46e46 100644
--- a/Utilities/cmcurl/CMake/CurlSymbolHiding.cmake
+++ b/Utilities/cmcurl/CMake/CurlSymbolHiding.cmake
@@ -4,57 +4,57 @@ option(CURL_HIDDEN_SYMBOLS "Set to ON to hide libcurl internal symbols (=hide al
mark_as_advanced(CURL_HIDDEN_SYMBOLS)
if(CURL_HIDDEN_SYMBOLS)
- set(SUPPORTS_SYMBOL_HIDING FALSE)
+ set(SUPPORTS_SYMBOL_HIDING FALSE)
- if(CMAKE_C_COMPILER_ID MATCHES "Clang")
- set(SUPPORTS_SYMBOL_HIDING TRUE)
- set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
- set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
- elseif(CMAKE_COMPILER_IS_GNUCC)
- if(NOT CMAKE_VERSION VERSION_LESS 2.8.10)
- set(GCC_VERSION ${CMAKE_C_COMPILER_VERSION})
- else()
- execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
- OUTPUT_VARIABLE GCC_VERSION)
- endif()
- if(NOT GCC_VERSION VERSION_LESS 3.4)
- # note: this is considered buggy prior to 4.0 but the autotools don't care, so let's ignore that fact
- set(SUPPORTS_SYMBOL_HIDING TRUE)
- set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
- set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
- endif()
- elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
- set(SUPPORTS_SYMBOL_HIDING TRUE)
- set(_SYMBOL_EXTERN "__global")
- set(_CFLAG_SYMBOLS_HIDE "-xldscope=hidden")
- elseif(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
- # note: this should probably just check for version 9.1.045 but I'm not 100% sure
- # so let's to it the same way autotools do.
- set(SUPPORTS_SYMBOL_HIDING TRUE)
- set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
- set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
- check_c_source_compiles("#include <stdio.h>
- int main (void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
- if(NOT _no_bug)
- set(SUPPORTS_SYMBOL_HIDING FALSE)
- set(_SYMBOL_EXTERN "")
- set(_CFLAG_SYMBOLS_HIDE "")
- endif()
- elseif(MSVC)
- set(SUPPORTS_SYMBOL_HIDING TRUE)
+ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
+ set(SUPPORTS_SYMBOL_HIDING TRUE)
+ set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
+ set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
+ elseif(CMAKE_COMPILER_IS_GNUCC)
+ if(NOT CMAKE_VERSION VERSION_LESS 2.8.10)
+ set(GCC_VERSION ${CMAKE_C_COMPILER_VERSION})
+ else()
+ execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
+ OUTPUT_VARIABLE GCC_VERSION)
+ endif()
+ if(NOT GCC_VERSION VERSION_LESS 3.4)
+ # note: this is considered buggy prior to 4.0 but the autotools don't care, so let's ignore that fact
+ set(SUPPORTS_SYMBOL_HIDING TRUE)
+ set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
+ set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
endif()
+ elseif(CMAKE_C_COMPILER_ID MATCHES "SunPro" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 8.0)
+ set(SUPPORTS_SYMBOL_HIDING TRUE)
+ set(_SYMBOL_EXTERN "__global")
+ set(_CFLAG_SYMBOLS_HIDE "-xldscope=hidden")
+ elseif(CMAKE_C_COMPILER_ID MATCHES "Intel" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 9.0)
+ # note: this should probably just check for version 9.1.045 but I'm not 100% sure
+ # so let's to it the same way autotools do.
+ set(SUPPORTS_SYMBOL_HIDING TRUE)
+ set(_SYMBOL_EXTERN "__attribute__ ((__visibility__ (\"default\")))")
+ set(_CFLAG_SYMBOLS_HIDE "-fvisibility=hidden")
+ check_c_source_compiles("#include <stdio.h>
+ int main (void) { printf(\"icc fvisibility bug test\"); return 0; }" _no_bug)
+ if(NOT _no_bug)
+ set(SUPPORTS_SYMBOL_HIDING FALSE)
+ set(_SYMBOL_EXTERN "")
+ set(_CFLAG_SYMBOLS_HIDE "")
+ endif()
+ elseif(MSVC)
+ set(SUPPORTS_SYMBOL_HIDING TRUE)
+ endif()
- set(HIDES_CURL_PRIVATE_SYMBOLS ${SUPPORTS_SYMBOL_HIDING})
+ set(HIDES_CURL_PRIVATE_SYMBOLS ${SUPPORTS_SYMBOL_HIDING})
elseif(MSVC)
- if(NOT CMAKE_VERSION VERSION_LESS 3.7)
- set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) #present since 3.4.3 but broken
- set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
- else()
- message(WARNING "Hiding private symbols regardless CURL_HIDDEN_SYMBOLS being disabled.")
- set(HIDES_CURL_PRIVATE_SYMBOLS TRUE)
- endif()
-elseif()
+ if(NOT CMAKE_VERSION VERSION_LESS 3.7)
+ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) #present since 3.4.3 but broken
set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
+ else()
+ message(WARNING "Hiding private symbols regardless CURL_HIDDEN_SYMBOLS being disabled.")
+ set(HIDES_CURL_PRIVATE_SYMBOLS TRUE)
+ endif()
+elseif()
+ set(HIDES_CURL_PRIVATE_SYMBOLS FALSE)
endif()
set(CURL_CFLAG_SYMBOLS_HIDE ${_CFLAG_SYMBOLS_HIDE})
diff --git a/Utilities/cmcurl/CMake/CurlTests.c b/Utilities/cmcurl/CMake/CurlTests.c
index bc36c8ef7..07b516b4d 100644
--- a/Utilities/cmcurl/CMake/CurlTests.c
+++ b/Utilities/cmcurl/CMake/CurlTests.c
@@ -240,6 +240,7 @@ int main()
#ifndef inet_ntoa_r
func_type func;
func = (func_type)inet_ntoa_r;
+ (void)func;
#endif
return 0;
}
@@ -255,6 +256,7 @@ int main()
#ifndef inet_ntoa_r
func_type func;
func = (func_type)&inet_ntoa_r;
+ (void)func;
#endif
return 0;
}
@@ -507,30 +509,30 @@ main ()
#ifdef HAVE_GLIBC_STRERROR_R
#include <string.h>
#include <errno.h>
+
+void check(char c) {}
+
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;
+ char buffer[1024];
+ /* This will not compile if strerror_r does not return a char* */
+ check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
+ return 0;
}
#endif
#ifdef HAVE_POSIX_STRERROR_R
#include <string.h>
#include <errno.h>
+
+/* float, because a pointer can't be implicitly cast to float */
+void check(float f) {}
+
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;
+ char buffer[1024];
+ /* This will not compile if strerror_r does not return an int */
+ check(strerror_r(EACCES, buffer, sizeof(buffer)));
+ return 0;
}
#endif
#ifdef HAVE_FSETXATTR_6
@@ -549,3 +551,65 @@ main() {
return 0;
}
#endif
+#ifdef HAVE_CLOCK_GETTIME_MONOTONIC
+#include <time.h>
+int
+main() {
+ struct timespec ts = {0, 0};
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return 0;
+}
+#endif
+#ifdef HAVE_BUILTIN_AVAILABLE
+int
+main() {
+ if(__builtin_available(macOS 10.12, *)) {}
+ return 0;
+}
+#endif
+#ifdef HAVE_VARIADIC_MACROS_C99
+#define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
+#define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
+
+int fun3(int arg1, int arg2, int arg3);
+int fun2(int arg1, int arg2);
+
+int fun3(int arg1, int arg2, int arg3) {
+ return arg1 + arg2 + arg3;
+}
+int fun2(int arg1, int arg2) {
+ return arg1 + arg2;
+}
+
+int
+main() {
+ int res3 = c99_vmacro3(1, 2, 3);
+ int res2 = c99_vmacro2(1, 2);
+ (void)res3;
+ (void)res2;
+ return 0;
+}
+#endif
+#ifdef HAVE_VARIADIC_MACROS_GCC
+#define gcc_vmacro3(first, args...) fun3(first, args)
+#define gcc_vmacro2(first, args...) fun2(first, args)
+
+int fun3(int arg1, int arg2, int arg3);
+int fun2(int arg1, int arg2);
+
+int fun3(int arg1, int arg2, int arg3) {
+ return arg1 + arg2 + arg3;
+}
+int fun2(int arg1, int arg2) {
+ return arg1 + arg2;
+}
+
+int
+main() {
+ int res3 = gcc_vmacro3(1, 2, 3);
+ int res2 = gcc_vmacro2(1, 2);
+ (void)res3;
+ (void)res2;
+ return 0;
+}
+#endif
diff --git a/Utilities/cmcurl/CMake/FindCARES.cmake b/Utilities/cmcurl/CMake/FindCARES.cmake
index c4ab5f132..723044a64 100644
--- a/Utilities/cmcurl/CMake/FindCARES.cmake
+++ b/Utilities/cmcurl/CMake/FindCARES.cmake
@@ -7,36 +7,36 @@
# also defined, but not for general use are
# CARES_LIBRARY, where to find the c-ares library.
-FIND_PATH(CARES_INCLUDE_DIR ares.h
+find_path(CARES_INCLUDE_DIR ares.h
/usr/local/include
/usr/include
)
-SET(CARES_NAMES ${CARES_NAMES} cares)
-FIND_LIBRARY(CARES_LIBRARY
+set(CARES_NAMES ${CARES_NAMES} cares)
+find_library(CARES_LIBRARY
NAMES ${CARES_NAMES}
PATHS /usr/lib /usr/local/lib
)
-IF (CARES_LIBRARY AND CARES_INCLUDE_DIR)
- SET(CARES_LIBRARIES ${CARES_LIBRARY})
- SET(CARES_FOUND "YES")
-ELSE (CARES_LIBRARY AND CARES_INCLUDE_DIR)
- SET(CARES_FOUND "NO")
-ENDIF (CARES_LIBRARY AND CARES_INCLUDE_DIR)
+if(CARES_LIBRARY AND CARES_INCLUDE_DIR)
+ set(CARES_LIBRARIES ${CARES_LIBRARY})
+ set(CARES_FOUND "YES")
+else()
+ set(CARES_FOUND "NO")
+endif()
-IF (CARES_FOUND)
- IF (NOT CARES_FIND_QUIETLY)
- MESSAGE(STATUS "Found c-ares: ${CARES_LIBRARIES}")
- ENDIF (NOT CARES_FIND_QUIETLY)
-ELSE (CARES_FOUND)
- IF (CARES_FIND_REQUIRED)
- MESSAGE(FATAL_ERROR "Could not find c-ares library")
- ENDIF (CARES_FIND_REQUIRED)
-ENDIF (CARES_FOUND)
+if(CARES_FOUND)
+ if(NOT CARES_FIND_QUIETLY)
+ message(STATUS "Found c-ares: ${CARES_LIBRARIES}")
+ endif()
+else()
+ if(CARES_FIND_REQUIRED)
+ message(FATAL_ERROR "Could not find c-ares library")
+ endif()
+endif()
-MARK_AS_ADVANCED(
+mark_as_advanced(
CARES_LIBRARY
CARES_INCLUDE_DIR
)
diff --git a/Utilities/cmcurl/CMake/FindGSS.cmake b/Utilities/cmcurl/CMake/FindGSS.cmake
index 60dcb73c9..8a28f2fb6 100644
--- a/Utilities/cmcurl/CMake/FindGSS.cmake
+++ b/Utilities/cmcurl/CMake/FindGSS.cmake
@@ -28,211 +28,209 @@ set(_GSS_ROOT_HINTS
# try to find library using system pkg-config if user didn't specify root dir
if(NOT GSS_ROOT_DIR AND NOT "$ENV{GSS_ROOT_DIR}")
- if(UNIX)
- find_package(PkgConfig QUIET)
- pkg_search_module(_GSS_PKG ${_MIT_MODNAME} ${_HEIMDAL_MODNAME})
- list(APPEND _GSS_ROOT_HINTS "${_GSS_PKG_PREFIX}")
- elseif(WIN32)
- list(APPEND _GSS_ROOT_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos;InstallDir]")
- endif()
+ if(UNIX)
+ find_package(PkgConfig QUIET)
+ pkg_search_module(_GSS_PKG ${_MIT_MODNAME} ${_HEIMDAL_MODNAME})
+ list(APPEND _GSS_ROOT_HINTS "${_GSS_PKG_PREFIX}")
+ elseif(WIN32)
+ list(APPEND _GSS_ROOT_HINTS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos;InstallDir]")
+ endif()
endif()
if(NOT _GSS_FOUND) #not found by pkg-config. Let's take more traditional approach.
- find_file(_GSS_CONFIGURE_SCRIPT
- NAMES
- "krb5-config"
- HINTS
- ${_GSS_ROOT_HINTS}
- PATH_SUFFIXES
- bin
- NO_CMAKE_PATH
- NO_CMAKE_ENVIRONMENT_PATH
+ find_file(_GSS_CONFIGURE_SCRIPT
+ NAMES
+ "krb5-config"
+ HINTS
+ ${_GSS_ROOT_HINTS}
+ PATH_SUFFIXES
+ bin
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ )
+
+ # if not found in user-supplied directories, maybe system knows better
+ find_file(_GSS_CONFIGURE_SCRIPT
+ NAMES
+ "krb5-config"
+ PATH_SUFFIXES
+ bin
+ )
+
+ if(_GSS_CONFIGURE_SCRIPT)
+ execute_process(
+ COMMAND ${_GSS_CONFIGURE_SCRIPT} "--cflags" "gssapi"
+ OUTPUT_VARIABLE _GSS_CFLAGS
+ RESULT_VARIABLE _GSS_CONFIGURE_FAILED
+ )
+ message(STATUS "CFLAGS: ${_GSS_CFLAGS}")
+ if(NOT _GSS_CONFIGURE_FAILED) # 0 means success
+ # should also work in an odd case when multiple directories are given
+ string(STRIP "${_GSS_CFLAGS}" _GSS_CFLAGS)
+ string(REGEX REPLACE " +-I" ";" _GSS_CFLAGS "${_GSS_CFLAGS}")
+ string(REGEX REPLACE " +-([^I][^ \\t;]*)" ";-\\1" _GSS_CFLAGS "${_GSS_CFLAGS}")
+
+ foreach(_flag ${_GSS_CFLAGS})
+ if(_flag MATCHES "^-I.*")
+ string(REGEX REPLACE "^-I" "" _val "${_flag}")
+ list(APPEND _GSS_INCLUDE_DIR "${_val}")
+ else()
+ list(APPEND _GSS_COMPILER_FLAGS "${_flag}")
+ endif()
+ endforeach()
+ endif()
+
+ execute_process(
+ COMMAND ${_GSS_CONFIGURE_SCRIPT} "--libs" "gssapi"
+ OUTPUT_VARIABLE _GSS_LIB_FLAGS
+ RESULT_VARIABLE _GSS_CONFIGURE_FAILED
)
+ message(STATUS "LDFLAGS: ${_GSS_LIB_FLAGS}")
+
+ if(NOT _GSS_CONFIGURE_FAILED) # 0 means success
+ # this script gives us libraries and link directories. Blah. We have to deal with it.
+ string(STRIP "${_GSS_LIB_FLAGS}" _GSS_LIB_FLAGS)
+ string(REGEX REPLACE " +-(L|l)" ";-\\1" _GSS_LIB_FLAGS "${_GSS_LIB_FLAGS}")
+ string(REGEX REPLACE " +-([^Ll][^ \\t;]*)" ";-\\1" _GSS_LIB_FLAGS "${_GSS_LIB_FLAGS}")
+
+ foreach(_flag ${_GSS_LIB_FLAGS})
+ if(_flag MATCHES "^-l.*")
+ string(REGEX REPLACE "^-l" "" _val "${_flag}")
+ list(APPEND _GSS_LIBRARIES "${_val}")
+ elseif(_flag MATCHES "^-L.*")
+ string(REGEX REPLACE "^-L" "" _val "${_flag}")
+ list(APPEND _GSS_LINK_DIRECTORIES "${_val}")
+ else()
+ list(APPEND _GSS_LINKER_FLAGS "${_flag}")
+ endif()
+ endforeach()
+ endif()
- # if not found in user-supplied directories, maybe system knows better
- find_file(_GSS_CONFIGURE_SCRIPT
- NAMES
- "krb5-config"
- PATH_SUFFIXES
- bin
+ execute_process(
+ COMMAND ${_GSS_CONFIGURE_SCRIPT} "--version"
+ OUTPUT_VARIABLE _GSS_VERSION
+ RESULT_VARIABLE _GSS_CONFIGURE_FAILED
)
- if(_GSS_CONFIGURE_SCRIPT)
- execute_process(
- COMMAND ${_GSS_CONFIGURE_SCRIPT} "--cflags" "gssapi"
- OUTPUT_VARIABLE _GSS_CFLAGS
- RESULT_VARIABLE _GSS_CONFIGURE_FAILED
- )
-message(STATUS "CFLAGS: ${_GSS_CFLAGS}")
- if(NOT _GSS_CONFIGURE_FAILED) # 0 means success
- # should also work in an odd case when multiple directories are given
- string(STRIP "${_GSS_CFLAGS}" _GSS_CFLAGS)
- string(REGEX REPLACE " +-I" ";" _GSS_CFLAGS "${_GSS_CFLAGS}")
- string(REGEX REPLACE " +-([^I][^ \\t;]*)" ";-\\1"_GSS_CFLAGS "${_GSS_CFLAGS}")
-
- foreach(_flag ${_GSS_CFLAGS})
- if(_flag MATCHES "^-I.*")
- string(REGEX REPLACE "^-I" "" _val "${_flag}")
- list(APPEND _GSS_INCLUDE_DIR "${_val}")
- else()
- list(APPEND _GSS_COMPILER_FLAGS "${_flag}")
- endif()
- endforeach()
- endif()
+ # older versions may not have the "--version" parameter. In this case we just don't care.
+ if(_GSS_CONFIGURE_FAILED)
+ set(_GSS_VERSION 0)
+ endif()
- execute_process(
- COMMAND ${_GSS_CONFIGURE_SCRIPT} "--libs" "gssapi"
- OUTPUT_VARIABLE _GSS_LIB_FLAGS
- RESULT_VARIABLE _GSS_CONFIGURE_FAILED
- )
-message(STATUS "LDFLAGS: ${_GSS_LIB_FLAGS}")
- if(NOT _GSS_CONFIGURE_FAILED) # 0 means success
- # this script gives us libraries and link directories. Blah. We have to deal with it.
- string(STRIP "${_GSS_LIB_FLAGS}" _GSS_LIB_FLAGS)
- string(REGEX REPLACE " +-(L|l)" ";-\\1" _GSS_LIB_FLAGS "${_GSS_LIB_FLAGS}")
- string(REGEX REPLACE " +-([^Ll][^ \\t;]*)" ";-\\1"_GSS_LIB_FLAGS "${_GSS_LIB_FLAGS}")
-
- foreach(_flag ${_GSS_LIB_FLAGS})
- if(_flag MATCHES "^-l.*")
- string(REGEX REPLACE "^-l" "" _val "${_flag}")
- list(APPEND _GSS_LIBRARIES "${_val}")
- elseif(_flag MATCHES "^-L.*")
- string(REGEX REPLACE "^-L" "" _val "${_flag}")
- list(APPEND _GSS_LINK_DIRECTORIES "${_val}")
- else()
- list(APPEND _GSS_LINKER_FLAGS "${_flag}")
- endif()
- endforeach()
- endif()
+ execute_process(
+ COMMAND ${_GSS_CONFIGURE_SCRIPT} "--vendor"
+ OUTPUT_VARIABLE _GSS_VENDOR
+ RESULT_VARIABLE _GSS_CONFIGURE_FAILED
+ )
+ # older versions may not have the "--vendor" parameter. In this case we just don't care.
+ if(_GSS_CONFIGURE_FAILED)
+ set(GSS_FLAVOUR "Heimdal") # most probably, shouldn't really matter
+ else()
+ if(_GSS_VENDOR MATCHES ".*H|heimdal.*")
+ set(GSS_FLAVOUR "Heimdal")
+ else()
+ set(GSS_FLAVOUR "MIT")
+ endif()
+ endif()
- execute_process(
- COMMAND ${_GSS_CONFIGURE_SCRIPT} "--version"
- OUTPUT_VARIABLE _GSS_VERSION
- RESULT_VARIABLE _GSS_CONFIGURE_FAILED
- )
+ else() # either there is no config script or we are on platform that doesn't provide one (Windows?)
- # older versions may not have the "--version" parameter. In this case we just don't care.
- if(_GSS_CONFIGURE_FAILED)
- set(_GSS_VERSION 0)
- endif()
+ find_path(_GSS_INCLUDE_DIR
+ NAMES
+ "gssapi/gssapi.h"
+ HINTS
+ ${_GSS_ROOT_HINTS}
+ PATH_SUFFIXES
+ include
+ inc
+ )
+ if(_GSS_INCLUDE_DIR) #jay, we've found something
+ set(CMAKE_REQUIRED_INCLUDES "${_GSS_INCLUDE_DIR}")
+ check_include_files( "gssapi/gssapi_generic.h;gssapi/gssapi_krb5.h" _GSS_HAVE_MIT_HEADERS)
- execute_process(
- COMMAND ${_GSS_CONFIGURE_SCRIPT} "--vendor"
- OUTPUT_VARIABLE _GSS_VENDOR
- RESULT_VARIABLE _GSS_CONFIGURE_FAILED
- )
+ if(_GSS_HAVE_MIT_HEADERS)
+ set(GSS_FLAVOUR "MIT")
+ else()
+ # prevent compiling the header - just check if we can include it
+ set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D__ROKEN_H__")
+ check_include_file( "roken.h" _GSS_HAVE_ROKEN_H)
+
+ check_include_file( "heimdal/roken.h" _GSS_HAVE_HEIMDAL_ROKEN_H)
+ if(_GSS_HAVE_ROKEN_H OR _GSS_HAVE_HEIMDAL_ROKEN_H)
+ set(GSS_FLAVOUR "Heimdal")
+ endif()
+ set(CMAKE_REQUIRED_DEFINITIONS "")
+ endif()
+ else()
+ # I'm not convienced if this is the right way but this is what autotools do at the moment
+ find_path(_GSS_INCLUDE_DIR
+ NAMES
+ "gssapi.h"
+ HINTS
+ ${_GSS_ROOT_HINTS}
+ PATH_SUFFIXES
+ include
+ inc
+ )
+
+ if(_GSS_INCLUDE_DIR)
+ set(GSS_FLAVOUR "Heimdal")
+ endif()
+ endif()
+
+ # if we have headers, check if we can link libraries
+ if(GSS_FLAVOUR)
+ set(_GSS_LIBDIR_SUFFIXES "")
+ set(_GSS_LIBDIR_HINTS ${_GSS_ROOT_HINTS})
+ get_filename_component(_GSS_CALCULATED_POTENTIAL_ROOT "${_GSS_INCLUDE_DIR}" PATH)
+ list(APPEND _GSS_LIBDIR_HINTS ${_GSS_CALCULATED_POTENTIAL_ROOT})
- # older versions may not have the "--vendor" parameter. In this case we just don't care.
- if(_GSS_CONFIGURE_FAILED)
- set(GSS_FLAVOUR "Heimdal") # most probably, shouldn't really matter
+ if(WIN32)
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ list(APPEND _GSS_LIBDIR_SUFFIXES "lib/AMD64")
+ if(GSS_FLAVOUR STREQUAL "MIT")
+ set(_GSS_LIBNAME "gssapi64")
+ else()
+ set(_GSS_LIBNAME "libgssapi")
+ endif()
else()
- if(_GSS_VENDOR MATCHES ".*H|heimdal.*")
- set(GSS_FLAVOUR "Heimdal")
- else()
- set(GSS_FLAVOUR "MIT")
- endif()
+ list(APPEND _GSS_LIBDIR_SUFFIXES "lib/i386")
+ if(GSS_FLAVOUR STREQUAL "MIT")
+ set(_GSS_LIBNAME "gssapi32")
+ else()
+ set(_GSS_LIBNAME "libgssapi")
+ endif()
endif()
-
- else() # either there is no config script or we are on platform that doesn't provide one (Windows?)
-
- find_path(_GSS_INCLUDE_DIR
- NAMES
- "gssapi/gssapi.h"
- HINTS
- ${_GSS_ROOT_HINTS}
- PATH_SUFFIXES
- include
- inc
- )
-
- if(_GSS_INCLUDE_DIR) #jay, we've found something
- set(CMAKE_REQUIRED_INCLUDES "${_GSS_INCLUDE_DIR}")
- check_include_files( "gssapi/gssapi_generic.h;gssapi/gssapi_krb5.h" _GSS_HAVE_MIT_HEADERS)
-
- if(_GSS_HAVE_MIT_HEADERS)
- set(GSS_FLAVOUR "MIT")
- else()
- # prevent compiling the header - just check if we can include it
- set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D__ROKEN_H__")
- check_include_file( "roken.h" _GSS_HAVE_ROKEN_H)
-
- check_include_file( "heimdal/roken.h" _GSS_HAVE_HEIMDAL_ROKEN_H)
- if(_GSS_HAVE_ROKEN_H OR _GSS_HAVE_HEIMDAL_ROKEN_H)
- set(GSS_FLAVOUR "Heimdal")
- endif()
- set(CMAKE_REQUIRED_DEFINITIONS "")
- endif()
+ else()
+ list(APPEND _GSS_LIBDIR_SUFFIXES "lib;lib64") # those suffixes are not checked for HINTS
+ if(GSS_FLAVOUR STREQUAL "MIT")
+ set(_GSS_LIBNAME "gssapi_krb5")
else()
- # I'm not convienced if this is the right way but this is what autotools do at the moment
- find_path(_GSS_INCLUDE_DIR
- NAMES
- "gssapi.h"
- HINTS
- ${_GSS_ROOT_HINTS}
- PATH_SUFFIXES
- include
- inc
- )
-
- if(_GSS_INCLUDE_DIR)
- set(GSS_FLAVOUR "Heimdal")
- endif()
+ set(_GSS_LIBNAME "gssapi")
endif()
+ endif()
- # if we have headers, check if we can link libraries
- if(GSS_FLAVOUR)
- set(_GSS_LIBDIR_SUFFIXES "")
- set(_GSS_LIBDIR_HINTS ${_GSS_ROOT_HINTS})
- get_filename_component(_GSS_CALCULATED_POTENTIAL_ROOT "${_GSS_INCLUDE_DIR}" PATH)
- list(APPEND _GSS_LIBDIR_HINTS ${_GSS_CALCULATED_POTENTIAL_ROOT})
-
- if(WIN32)
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- list(APPEND _GSS_LIBDIR_SUFFIXES "lib/AMD64")
- if(GSS_FLAVOUR STREQUAL "MIT")
- set(_GSS_LIBNAME "gssapi64")
- else()
- set(_GSS_LIBNAME "libgssapi")
- endif()
- else()
- list(APPEND _GSS_LIBDIR_SUFFIXES "lib/i386")
- if(GSS_FLAVOUR STREQUAL "MIT")
- set(_GSS_LIBNAME "gssapi32")
- else()
- set(_GSS_LIBNAME "libgssapi")
- endif()
- endif()
- else()
- list(APPEND _GSS_LIBDIR_SUFFIXES "lib;lib64") # those suffixes are not checked for HINTS
- if(GSS_FLAVOUR STREQUAL "MIT")
- set(_GSS_LIBNAME "gssapi_krb5")
- else()
- set(_GSS_LIBNAME "gssapi")
- endif()
- endif()
-
- find_library(_GSS_LIBRARIES
- NAMES
- ${_GSS_LIBNAME}
- HINTS
- ${_GSS_LIBDIR_HINTS}
- PATH_SUFFIXES
- ${_GSS_LIBDIR_SUFFIXES}
- )
-
- endif()
+ find_library(_GSS_LIBRARIES
+ NAMES
+ ${_GSS_LIBNAME}
+ HINTS
+ ${_GSS_LIBDIR_HINTS}
+ PATH_SUFFIXES
+ ${_GSS_LIBDIR_SUFFIXES}
+ )
endif()
+ endif()
else()
- if(_GSS_PKG_${_MIT_MODNAME}_VERSION)
- set(GSS_FLAVOUR "MIT")
- set(_GSS_VERSION _GSS_PKG_${_MIT_MODNAME}_VERSION)
- else()
- set(GSS_FLAVOUR "Heimdal")
- set(_GSS_VERSION _GSS_PKG_${_MIT_HEIMDAL}_VERSION)
- endif()
+ if(_GSS_PKG_${_MIT_MODNAME}_VERSION)
+ set(GSS_FLAVOUR "MIT")
+ set(_GSS_VERSION _GSS_PKG_${_MIT_MODNAME}_VERSION)
+ else()
+ set(GSS_FLAVOUR "Heimdal")
+ set(_GSS_VERSION _GSS_PKG_${_MIT_HEIMDAL}_VERSION)
+ endif()
endif()
set(GSS_INCLUDE_DIR ${_GSS_INCLUDE_DIR})
@@ -243,36 +241,34 @@ set(GSS_COMPILER_FLAGS ${_GSS_COMPILER_FLAGS})
set(GSS_VERSION ${_GSS_VERSION})
if(GSS_FLAVOUR)
+ if(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "Heimdal")
+ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(HEIMDAL_MANIFEST_FILE "Heimdal.Application.amd64.manifest")
+ else()
+ set(HEIMDAL_MANIFEST_FILE "Heimdal.Application.x86.manifest")
+ endif()
- if(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "Heimdal")
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(HEIMDAL_MANIFEST_FILE "Heimdal.Application.amd64.manifest")
- else()
- set(HEIMDAL_MANIFEST_FILE "Heimdal.Application.x86.manifest")
- endif()
-
- if(EXISTS "${GSS_INCLUDE_DIR}/${HEIMDAL_MANIFEST_FILE}")
- file(STRINGS "${GSS_INCLUDE_DIR}/${HEIMDAL_MANIFEST_FILE}" heimdal_version_str
- REGEX "^.*version=\"[0-9]\\.[^\"]+\".*$")
+ if(EXISTS "${GSS_INCLUDE_DIR}/${HEIMDAL_MANIFEST_FILE}")
+ file(STRINGS "${GSS_INCLUDE_DIR}/${HEIMDAL_MANIFEST_FILE}" heimdal_version_str
+ REGEX "^.*version=\"[0-9]\\.[^\"]+\".*$")
- string(REGEX MATCH "[0-9]\\.[^\"]+"
- GSS_VERSION "${heimdal_version_str}")
- endif()
+ string(REGEX MATCH "[0-9]\\.[^\"]+"
+ GSS_VERSION "${heimdal_version_str}")
+ endif()
- if(NOT GSS_VERSION)
- set(GSS_VERSION "Heimdal Unknown")
- endif()
- elseif(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "MIT")
- get_filename_component(_MIT_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos\\SDK\\CurrentVersion;VersionString]" NAME CACHE)
- if(WIN32 AND _MIT_VERSION)
- set(GSS_VERSION "${_MIT_VERSION}")
- else()
- set(GSS_VERSION "MIT Unknown")
- endif()
+ if(NOT GSS_VERSION)
+ set(GSS_VERSION "Heimdal Unknown")
endif()
+ elseif(NOT GSS_VERSION AND GSS_FLAVOUR STREQUAL "MIT")
+ get_filename_component(_MIT_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MIT\\Kerberos\\SDK\\CurrentVersion;VersionString]" NAME CACHE)
+ if(WIN32 AND _MIT_VERSION)
+ set(GSS_VERSION "${_MIT_VERSION}")
+ else()
+ set(GSS_VERSION "MIT Unknown")
+ endif()
+ endif()
endif()
-
include(FindPackageHandleStandardArgs)
set(_GSS_REQUIRED_VARS GSS_LIBRARIES GSS_FLAVOUR)
diff --git a/Utilities/cmcurl/CMake/FindLibSSH2.cmake b/Utilities/cmcurl/CMake/FindLibSSH2.cmake
index 12a7c612b..84822dba7 100644
--- a/Utilities/cmcurl/CMake/FindLibSSH2.cmake
+++ b/Utilities/cmcurl/CMake/FindLibSSH2.cmake
@@ -5,14 +5,14 @@
# LIBSSH2_INCLUDE_DIR - the libssh2 include directory
# LIBSSH2_LIBRARY - the libssh2 library name
-if (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY)
+if(LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY)
set(LibSSH2_FIND_QUIETLY TRUE)
-endif (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY)
+endif()
-FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h
+find_path(LIBSSH2_INCLUDE_DIR libssh2.h
)
-FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2
+find_library(LIBSSH2_LIBRARY NAMES ssh2
)
if(LIBSSH2_INCLUDE_DIR)
@@ -27,9 +27,9 @@ if(LIBSSH2_INCLUDE_DIR)
string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_PATCH "${LIBSSH2_VERSION_PATCH}")
set(LIBSSH2_VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}")
-endif(LIBSSH2_INCLUDE_DIR)
+endif()
include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSSH2 DEFAULT_MSG LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY )
+find_package_handle_standard_args(LibSSH2 DEFAULT_MSG LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY )
-MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY LIBSSH2_VERSION_MAJOR LIBSSH2_VERSION_MINOR LIBSSH2_VERSION_PATCH LIBSSH2_VERSION)
+mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY LIBSSH2_VERSION_MAJOR LIBSSH2_VERSION_MINOR LIBSSH2_VERSION_PATCH LIBSSH2_VERSION)
diff --git a/Utilities/cmcurl/CMake/FindNGHTTP2.cmake b/Utilities/cmcurl/CMake/FindNGHTTP2.cmake
index 4e566cf02..348b9612d 100644
--- a/Utilities/cmcurl/CMake/FindNGHTTP2.cmake
+++ b/Utilities/cmcurl/CMake/FindNGHTTP2.cmake
@@ -14,5 +14,5 @@ find_package_handle_standard_args(NGHTTP2
"Could NOT find NGHTTP2"
)
-set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR} )
+set(NGHTTP2_INCLUDE_DIRS ${NGHTTP2_INCLUDE_DIR})
set(NGHTTP2_LIBRARIES ${NGHTTP2_LIBRARY})
diff --git a/Utilities/cmcurl/CMake/Macros.cmake b/Utilities/cmcurl/CMake/Macros.cmake
index dab005f73..7f7134515 100644
--- a/Utilities/cmcurl/CMake/Macros.cmake
+++ b/Utilities/cmcurl/CMake/Macros.cmake
@@ -5,35 +5,35 @@
# multiple times with a sequence of possibly dependent libraries in
# order of least-to-most-dependent. Some libraries depend on others
# to link correctly.
-macro(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE)
+macro(check_library_exists_concat LIBRARY SYMBOL VARIABLE)
check_library_exists("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "${CMAKE_LIBRARY_PATH}"
${VARIABLE})
if(${VARIABLE})
set(CURL_LIBS ${LIBRARY} ${CURL_LIBS})
- endif(${VARIABLE})
-endmacro(CHECK_LIBRARY_EXISTS_CONCAT)
+ endif()
+endmacro()
# Check if header file exists and add it to the list.
# This macro is intended to be called multiple times with a sequence of
# possibly dependent header files. Some headers depend on others to be
# compiled correctly.
-macro(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
+macro(check_include_file_concat FILE VARIABLE)
check_include_files("${CURL_INCLUDES};${FILE}" ${VARIABLE})
if(${VARIABLE})
set(CURL_INCLUDES ${CURL_INCLUDES} ${FILE})
set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -D${VARIABLE}")
- endif(${VARIABLE})
-endmacro(CHECK_INCLUDE_FILE_CONCAT)
+ endif()
+endmacro()
# For other curl specific tests, use this macro.
-macro(CURL_INTERNAL_TEST CURL_TEST)
+macro(curl_internal_test CURL_TEST)
if(NOT DEFINED "${CURL_TEST}")
set(MACRO_CHECK_FUNCTION_DEFINITIONS
"-D${CURL_TEST} ${CURL_TEST_DEFINES} ${CMAKE_REQUIRED_FLAGS}")
if(CMAKE_REQUIRED_LIBRARIES)
set(CURL_TEST_ADD_LIBRARIES
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
- endif(CMAKE_REQUIRED_LIBRARIES)
+ endif()
message(STATUS "Performing Curl Test ${CURL_TEST}")
try_compile(${CURL_TEST}
@@ -48,48 +48,41 @@ macro(CURL_INTERNAL_TEST CURL_TEST)
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})
+ else()
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()
endif()
-endmacro(CURL_INTERNAL_TEST)
+endmacro()
-macro(CURL_INTERNAL_TEST_RUN CURL_TEST)
- if(NOT DEFINED "${CURL_TEST}_COMPILE")
- 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_run(${CURL_TEST} ${CURL_TEST}_COMPILE
- ${CMAKE_BINARY_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CurlTests.c
- CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_FUNCTION_DEFINITIONS}
- "${CURL_TEST_ADD_LIBRARIES}"
- OUTPUT_VARIABLE OUTPUT)
- if(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
- set(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}")
- message(STATUS "Performing Curl Test ${CURL_TEST} - Success")
- else(${CURL_TEST}_COMPILE AND NOT ${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}")
- if(${CURL_TEST}_COMPILE)
- file(APPEND
- "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
- "There was a problem running this test\n")
- endif(${CURL_TEST}_COMPILE)
- file(APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log"
- "\n\n")
- endif(${CURL_TEST}_COMPILE AND NOT ${CURL_TEST})
+macro(curl_nroff_check)
+ find_program(NROFF NAMES gnroff nroff)
+ if(NROFF)
+ # Need a way to write to stdin, this will do
+ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
+ # Tests for a valid nroff option to generate a manpage
+ foreach(_MANOPT "-man" "-mandoc")
+ execute_process(COMMAND "${NROFF}" ${_MANOPT}
+ OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
+ INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
+ ERROR_QUIET)
+ # Save the option if it was valid
+ if(NROFF_MANOPT_OUTPUT)
+ message("Found *nroff option: -- ${_MANOPT}")
+ set(NROFF_MANOPT ${_MANOPT})
+ set(NROFF_USEFUL ON)
+ break()
+ endif()
+ endforeach()
+ # No need for the temporary file
+ file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
+ if(NOT NROFF_USEFUL)
+ message(WARNING "Found no *nroff option to get plaintext from man pages")
+ endif()
+ else()
+ message(WARNING "Found no *nroff program")
endif()
-endmacro(CURL_INTERNAL_TEST_RUN)
+endmacro()
diff --git a/Utilities/cmcurl/CMake/OtherTests.cmake b/Utilities/cmcurl/CMake/OtherTests.cmake
index 3b203c538..c1c9aa32a 100644
--- a/Utilities/cmcurl/CMake/OtherTests.cmake
+++ b/Utilities/cmcurl/CMake/OtherTests.cmake
@@ -5,8 +5,8 @@ set(_source_epilogue "#undef inline")
macro(add_header_include check header)
if(${check})
set(_source_epilogue "${_source_epilogue}\n#include <${header}>")
- endif(${check})
-endmacro(add_header_include)
+ endif()
+endmacro()
set(signature_call_conv)
if(HAVE_WINDOWS_H)
@@ -19,10 +19,12 @@ if(HAVE_WINDOWS_H)
if(HAVE_LIBWS2_32)
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
endif()
-else(HAVE_WINDOWS_H)
+else()
add_header_include(HAVE_SYS_TYPES_H "sys/types.h")
add_header_include(HAVE_SYS_SOCKET_H "sys/socket.h")
-endif(HAVE_WINDOWS_H)
+endif()
+
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
check_c_source_compiles("${_source_epilogue}
int main(void) {
@@ -32,9 +34,9 @@ int main(void) {
if(curl_cv_recv)
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_arg1 "SOCKET" "int" )
+ foreach(recv_arg2 "char *" "void *" )
+ foreach(recv_arg3 "int" "size_t" "socklen_t" "unsigned int")
foreach(recv_arg4 "int" "unsigned int")
if(NOT curl_cv_func_recv_done)
unset(curl_cv_func_recv_test CACHE)
@@ -64,13 +66,13 @@ if(curl_cv_recv)
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)
+ endif()
+ endif()
+ endforeach()
+ endforeach()
+ endforeach()
+ endforeach()
+ endforeach()
else()
string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG1 "${curl_cv_func_recv_args}")
string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*$" "\\1" RECV_TYPE_ARG2 "${curl_cv_func_recv_args}")
@@ -81,10 +83,10 @@ if(curl_cv_recv)
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)
+ endif()
+else()
message(FATAL_ERROR "Unable to link function recv")
-endif(curl_cv_recv)
+endif()
set(curl_cv_func_recv_args "${curl_cv_func_recv_args}" CACHE INTERNAL "Arguments for recv")
set(HAVE_RECV 1)
@@ -96,9 +98,9 @@ int main(void) {
if(curl_cv_send)
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_arg1 "SOCKET" "int" "ssize_t" )
+ foreach(send_arg2 "const char *" "const void *" "void *" "char *")
+ foreach(send_arg3 "int" "size_t" "socklen_t" "unsigned int")
foreach(send_arg4 "int" "unsigned int")
if(NOT curl_cv_func_send_done)
unset(curl_cv_func_send_test CACHE)
@@ -130,13 +132,13 @@ if(curl_cv_send)
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)
+ endif()
+ endif()
+ endforeach()
+ endforeach()
+ endforeach()
+ endforeach()
+ endforeach()
else()
string(REGEX REPLACE "^([^,]*),[^,]*,[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG1 "${curl_cv_func_send_args}")
string(REGEX REPLACE "^[^,]*,([^,]*),[^,]*,[^,]*,[^,]*,[^,]*$" "\\1" SEND_TYPE_ARG2 "${curl_cv_func_send_args}")
@@ -148,11 +150,11 @@ if(curl_cv_send)
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")
+ endif()
set(SEND_QUAL_ARG2 "const")
-else(curl_cv_send)
+else()
message(FATAL_ERROR "Unable to link function send")
-endif(curl_cv_send)
+endif()
set(curl_cv_func_send_args "${curl_cv_func_send_args}" CACHE INTERNAL "Arguments for send")
set(HAVE_SEND 1)
@@ -177,29 +179,12 @@ int main(void) {
return 0;
}" HAVE_STRUCT_TIMEVAL)
-
-include(CheckCSourceRuns)
-# See HAVE_POLL in CMakeLists.txt for why poll is disabled on macOS
-if(NOT APPLE)
- set(CMAKE_REQUIRED_FLAGS)
- if(HAVE_SYS_POLL_H)
- set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
- endif(HAVE_SYS_POLL_H)
- check_c_source_runs("
- #ifdef HAVE_SYS_POLL_H
- # include <sys/poll.h>
- #endif
- int main(void) {
- return poll((void *)0, 0, 10 /*ms*/);
- }" HAVE_POLL_FINE)
-endif()
-
set(HAVE_SIG_ATOMIC_T 1)
set(CMAKE_REQUIRED_FLAGS)
if(HAVE_SIGNAL_H)
set(CMAKE_REQUIRED_FLAGS "-DHAVE_SIGNAL_H")
set(CMAKE_EXTRA_INCLUDE_FILES "signal.h")
-endif(HAVE_SIGNAL_H)
+endif()
check_type_size("sig_atomic_t" SIZEOF_SIG_ATOMIC_T)
if(HAVE_SIZEOF_SIG_ATOMIC_T)
check_c_source_compiles("
@@ -213,8 +198,8 @@ if(HAVE_SIZEOF_SIG_ATOMIC_T)
}" 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)
+ endif()
+endif()
if(HAVE_WINDOWS_H)
set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
@@ -222,11 +207,58 @@ else()
set(CMAKE_EXTRA_INCLUDE_FILES)
if(HAVE_SYS_SOCKET_H)
set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
- endif(HAVE_SYS_SOCKET_H)
+ endif()
endif()
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)
+endif()
+
+unset(CMAKE_TRY_COMPILE_TARGET_TYPE)
+
+if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
+ # if not cross-compilation...
+ include(CheckCSourceRuns)
+ set(CMAKE_REQUIRED_FLAGS "")
+ if(HAVE_SYS_POLL_H)
+ set(CMAKE_REQUIRED_FLAGS "-DHAVE_SYS_POLL_H")
+ elseif(HAVE_POLL_H)
+ set(CMAKE_REQUIRED_FLAGS "-DHAVE_POLL_H")
+ endif()
+ check_c_source_runs("
+ #include <stdlib.h>
+ #include <sys/time.h>
+
+ #ifdef HAVE_SYS_POLL_H
+ # include <sys/poll.h>
+ #elif HAVE_POLL_H
+ # include <poll.h>
+ #endif
+
+ int main(void)
+ {
+ if(0 != poll(0, 0, 10)) {
+ return 1; /* fail */
+ }
+ else {
+ /* detect the 10.12 poll() breakage */
+ struct timeval before, after;
+ int rc;
+ size_t us;
+
+ gettimeofday(&before, NULL);
+ rc = poll(NULL, 0, 500);
+ gettimeofday(&after, NULL);
+
+ us = (after.tv_sec - before.tv_sec) * 1000000 +
+ (after.tv_usec - before.tv_usec);
+
+ if(us < 400000) {
+ return 1;
+ }
+ }
+ return 0;
+ }" HAVE_POLL_FINE)
+endif()
diff --git a/Utilities/cmcurl/CMake/Platforms/WindowsCache.cmake b/Utilities/cmcurl/CMake/Platforms/WindowsCache.cmake
index 53d0a5e88..2dbe1bbbd 100644
--- a/Utilities/cmcurl/CMake/Platforms/WindowsCache.cmake
+++ b/Utilities/cmcurl/CMake/Platforms/WindowsCache.cmake
@@ -115,8 +115,7 @@ if(NOT UNIX)
set(HAVE_SIGACTION 0)
set(HAVE_MACRO_SIGSETJMP 0)
- else(WIN32)
+ else()
message("This file should be included on Windows platform only")
- endif(WIN32)
-endif(NOT UNIX)
-
+ endif()
+endif()
diff --git a/Utilities/cmcurl/CMake/Utilities.cmake b/Utilities/cmcurl/CMake/Utilities.cmake
index 8b6276df6..5cb1d4497 100644
--- a/Utilities/cmcurl/CMake/Utilities.cmake
+++ b/Utilities/cmcurl/CMake/Utilities.cmake
@@ -1,44 +1,13 @@
# File containing various utilities
-# Converts a CMake list to a string containing elements separated by spaces
-function(TO_LIST_SPACES _LIST_NAME OUTPUT_VAR)
- set(NEW_LIST_SPACE)
- foreach(ITEM ${${_LIST_NAME}})
- set(NEW_LIST_SPACE "${NEW_LIST_SPACE} ${ITEM}")
- endforeach()
- string(STRIP ${NEW_LIST_SPACE} NEW_LIST_SPACE)
- set(${OUTPUT_VAR} "${NEW_LIST_SPACE}" PARENT_SCOPE)
-endfunction()
-
-# Appends a lis of item to a string which is a space-separated list, if they don't already exist.
-function(LIST_SPACES_APPEND_ONCE LIST_NAME)
- string(REPLACE " " ";" _LIST ${${LIST_NAME}})
- list(APPEND _LIST ${ARGN})
- list(REMOVE_DUPLICATES _LIST)
- to_list_spaces(_LIST NEW_LIST_SPACE)
- set(${LIST_NAME} "${NEW_LIST_SPACE}" PARENT_SCOPE)
-endfunction()
-
-# Convinience function that does the same as LIST(FIND ...) but with a TRUE/FALSE return value.
-# Ex: IN_STR_LIST(MY_LIST "Searched item" WAS_FOUND)
-function(IN_STR_LIST LIST_NAME ITEM_SEARCHED RETVAL)
- list(FIND ${LIST_NAME} ${ITEM_SEARCHED} FIND_POS)
- if(${FIND_POS} EQUAL -1)
- set(${RETVAL} FALSE PARENT_SCOPE)
- else()
- set(${RETVAL} TRUE PARENT_SCOPE)
- endif()
-endfunction()
-
# Returns a list of arguments that evaluate to true
-function(collect_true output_var output_count_var)
- set(${output_var})
+function(count_true output_count_var)
+ set(lst)
foreach(option_var IN LISTS ARGN)
if(${option_var})
- list(APPEND ${output_var} ${option_var})
+ list(APPEND lst ${option_var})
endif()
endforeach()
- set(${output_var} ${${output_var}} PARENT_SCOPE)
- list(LENGTH ${output_var} ${output_count_var})
- set(${output_count_var} ${${output_count_var}} PARENT_SCOPE)
+ list(LENGTH lst lst_len)
+ set(${output_count_var} ${lst_len} PARENT_SCOPE)
endfunction()
diff --git a/Utilities/cmcurl/CMakeLists.txt b/Utilities/cmcurl/CMakeLists.txt
index d85f366c0..37522fc10 100644
--- a/Utilities/cmcurl/CMakeLists.txt
+++ b/Utilities/cmcurl/CMakeLists.txt
@@ -2,6 +2,7 @@
set(BUILD_CURL_EXE OFF CACHE INTERNAL "No curl exe")
set(BUILD_DASHBOARD_REPORTS OFF CACHE INTERNAL "No curl dashboard reports")
set(BUILD_RELEASE_DEBUG_DIRS OFF CACHE INTERNAL "No curl release/debug dirs")
+set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Build shared libraries")
set(CMAKE_USE_GSSAPI OFF CACHE INTERNAL "Disable curl gssapi")
set(CMAKE_USE_LIBSSH2 OFF CACHE INTERNAL "Disable curl libssh2")
set(CMAKE_USE_OPENLDAP OFF CACHE INTERNAL "No curl OpenLDAP")
@@ -23,16 +24,17 @@ set(CURL_DISABLE_TELNET ON CACHE INTERNAL "Disable curl telnet protocol?")
set(CURL_DISABLE_TFTP ON CACHE INTERNAL "Disable curl tftp protocol?")
set(CURL_DISABLE_VERBOSE_STRINGS OFF CACHE INTERNAL "Do not disable curl verbosity")
set(CURL_HIDDEN_SYMBOLS OFF CACHE INTERNAL "No curl hidden symbols")
-set(CURL_STATICLIB ON CACHE INTERNAL "Static curl")
+set(CURL_WERROR OFF CACHE INTERNAL "Turn compiler warnings into errors")
set(DISABLED_THREADSAFE OFF CACHE INTERNAL "Curl can use thread-safe functions")
set(ENABLE_ARES OFF CACHE INTERNAL "No curl c-ares support")
set(ENABLE_CURLDEBUG OFF CACHE INTERNAL "No curl TrackMemory features")
set(ENABLE_DEBUG OFF CACHE INTERNAL "No curl debug features")
-set(ENABLE_IPV6 OFF CACHE INTERNAL "No curl IPv6 support")
+set(ENABLE_IPV6 ON CACHE INTERNAL "Enable curl IPv6 support detection")
set(ENABLE_MANUAL OFF CACHE INTERNAL "No curl built-in manual")
set(ENABLE_THREADED_RESOLVER OFF CACHE INTERNAL "No curl POSIX threaded DNS lookup")
set(ENABLE_UNIX_SOCKETS OFF CACHE INTERNAL "No curl Unix domain sockets support")
set(HTTP_ONLY OFF CACHE INTERNAL "Curl is not http-only")
+set(PICKY_COMPILER OFF CACHE INTERNAL "Enable picky compiler options")
set(USE_WIN32_LDAP OFF CACHE INTERNAL "No curl Windows LDAP")
if(CMAKE_USE_OPENSSL)
elseif(WIN32)
@@ -51,10 +53,11 @@ elseif(APPLE)
endif()
if(NOT OSX_VERSION VERSION_LESS 10.6 AND
CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
- set(CMAKE_USE_DARWINSSL ON CACHE INTERNAL "enable Apple OS native SSL/TLS")
+ set(CMAKE_USE_SECTRANSP ON CACHE INTERNAL "enable Apple OS native SSL/TLS")
else()
- set(CMAKE_USE_DARWINSSL OFF CACHE INTERNAL "enable Apple OS native SSL/TLS")
+ set(CMAKE_USE_SECTRANSP OFF CACHE INTERNAL "enable Apple OS native SSL/TLS")
endif()
+ unset(CMAKE_USE_DARWINSSL CACHE)
endif()
set(CMAKE_USE_MBEDTLS OFF CACHE INTERNAL "Enable mbedTLS for SSL/TLS")
@@ -75,7 +78,7 @@ endif(APPLE)
# Disable warnings to avoid changing 3rd party code.
if(CMAKE_C_COMPILER_ID MATCHES
- "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
@@ -88,7 +91,7 @@ endif()
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2019, 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
@@ -121,27 +124,26 @@ endif()
# To check:
# (From Daniel Stenberg) The cmake build selected to run gcc with -fPIC on my box while the plain configure script did not.
# (From Daniel Stenberg) The gcc command line use neither -g nor any -O options. As a developer, I also treasure our configure scripts's --enable-debug option that sets a long range of "picky" compiler options.
-cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
include(Utilities)
include(Macros)
include(CMakeDependentOption)
+include(CheckCCompilerFlag)
-project( CURL C )
+project(CURL C)
if(0) # This code not needed for building within CMake.
message(WARNING "the curl cmake build system is poorly maintained. Be aware")
endif()
-file (READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
-string (REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
+file(READ ${CURL_SOURCE_DIR}/include/curl/curlver.h CURL_VERSION_H_CONTENTS)
+string(REGEX MATCH "#define LIBCURL_VERSION \"[^\"]*"
CURL_VERSION ${CURL_VERSION_H_CONTENTS})
-string (REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
-string (REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
+string(REGEX REPLACE "[^\"]+\"" "" CURL_VERSION ${CURL_VERSION})
+string(REGEX MATCH "#define LIBCURL_VERSION_NUM 0x[0-9a-fA-F]+"
CURL_VERSION_NUM ${CURL_VERSION_H_CONTENTS})
-string (REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
+string(REGEX REPLACE "[^0]+0x" "" CURL_VERSION_NUM ${CURL_VERSION_NUM})
-include_regular_expression("^.*$") # Sukender: Is it necessary?
# Setup package meta-data
# SET(PACKAGE "curl")
@@ -156,56 +158,67 @@ endif()
set(OPERATING_SYSTEM "${CMAKE_SYSTEM_NAME}")
set(OS "\"${CMAKE_SYSTEM_NAME}\"")
-include_directories(${PROJECT_BINARY_DIR}/include/curl)
-include_directories( ${CURL_SOURCE_DIR}/include )
+include_directories(${CURL_SOURCE_DIR}/include)
+option(CURL_WERROR "Turn compiler warnings into errors" OFF)
+option(PICKY_COMPILER "Enable picky compiler options" ON)
option(BUILD_CURL_EXE "Set to ON to build curl executable." ON)
-option(CURL_STATICLIB "Set to ON to build libcurl with static linking." OFF)
+option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ENABLE_ARES "Set to ON to enable c-ares support" OFF)
if(WIN32)
- CMAKE_DEPENDENT_OPTION(ENABLE_THREADED_RESOLVER
- "Set to ON to enable threaded DNS lookup"
- ON "NOT ENABLE_ARES"
- OFF)
-else()
- option(ENABLE_THREADED_RESOLVER "Set to ON to enable POSIX threaded DNS lookup" OFF)
+ option(CURL_STATIC_CRT "Set to ON to build libcurl with static CRT on Windows (/MT)." OFF)
+ option(ENABLE_INET_PTON "Set to OFF to prevent usage of inet_pton when building against modern SDKs while still requiring compatibility with older Windows versions, such as Windows XP, Windows Server 2003 etc." ON)
endif()
+
+if(0) # This code not needed for building within CMake.
+cmake_dependent_option(ENABLE_THREADED_RESOLVER "Set to ON to enable threaded DNS lookup"
+ ON "NOT ENABLE_ARES"
+ OFF)
+endif()
+
option(ENABLE_DEBUG "Set to ON to enable curl debug features" OFF)
option(ENABLE_CURLDEBUG "Set to ON to build with TrackMemory feature enabled" OFF)
-if (ENABLE_DEBUG)
- # DEBUGBUILD will be defined only for Debug builds
- if(NOT CMAKE_VERSION VERSION_LESS 3.0)
- set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
- else()
- set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_DEBUG DEBUGBUILD)
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
+ if(PICKY_COMPILER)
+ foreach(_CCOPT -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wfloat-equal -Wno-multichar -Wsign-compare -Wundef -Wno-format-nonliteral -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wno-sign-conversion -Wvla -Wdouble-promotion -Wno-system-headers -Wno-pedantic-ms-format)
+ # surprisingly, CHECK_C_COMPILER_FLAG needs a new variable to store each new
+ # test result in.
+ check_c_compiler_flag(${_CCOPT} OPT${_CCOPT})
+ if(OPT${_CCOPT})
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
+ endif()
+ endforeach()
endif()
+endif()
+
+if(ENABLE_DEBUG)
+ # DEBUGBUILD will be defined only for Debug builds
+ set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:DEBUGBUILD>)
set(ENABLE_CURLDEBUG ON)
endif()
-if (ENABLE_CURLDEBUG)
+if(ENABLE_CURLDEBUG)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
endif()
+if(0) # This code not needed for building within CMake.
+# For debug libs and exes, add "-d" postfix
+if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
+ set(CMAKE_DEBUG_POSTFIX "-d")
+endif()
+endif()
+
# initialize CURL_LIBS
set(CURL_LIBS "")
-if(ENABLE_THREADED_RESOLVER AND ENABLE_ARES)
- message(FATAL_ERROR "Options ENABLE_THREADED_RESOLVER and ENABLE_ARES are mutually exclusive")
-endif()
-
if(ENABLE_ARES)
set(USE_ARES 1)
find_package(CARES REQUIRED)
- list(APPEND CURL_LIBS ${CARES_LIBRARY} )
+ list(APPEND CURL_LIBS ${CARES_LIBRARY})
set(CURL_LIBS ${CURL_LIBS} ${CARES_LIBRARY})
endif()
-if(MSVC)
- option(BUILD_RELEASE_DEBUG_DIRS "Set OFF to build each configuration to a separate directory" OFF)
- mark_as_advanced(BUILD_RELEASE_DEBUG_DIRS)
-endif()
-
if(0) # This code not needed for building within CMake.
include(CurlSymbolHiding)
endif()
@@ -265,8 +278,6 @@ option(CURL_DISABLE_CRYPTO_AUTH "to disable cryptographic authentication" OFF)
mark_as_advanced(CURL_DISABLE_CRYPTO_AUTH)
option(CURL_DISABLE_VERBOSE_STRINGS "to disable verbose strings" OFF)
mark_as_advanced(CURL_DISABLE_VERBOSE_STRINGS)
-option(DISABLED_THREADSAFE "Set to explicitly specify we don't want to use thread-safe functions" OFF)
-mark_as_advanced(DISABLED_THREADSAFE)
option(ENABLE_IPV6 "Define if you want to enable IPv6 support" ON)
mark_as_advanced(ENABLE_IPV6)
if(ENABLE_IPV6 AND NOT WIN32)
@@ -283,85 +294,67 @@ if(ENABLE_IPV6 AND NOT WIN32)
endif()
endif()
-option(ENABLE_MANUAL "to provide the built-in manual" ON)
-unset(USE_MANUAL CACHE) # TODO: cache NROFF/NROFF_MANOPT/USE_MANUAL vars?
-if(ENABLE_MANUAL)
- find_program(NROFF NAMES gnroff nroff)
- if(NROFF)
- # Need a way to write to stdin, this will do
- file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt" "test")
- # Tests for a valid nroff option to generate a manpage
- foreach(_MANOPT "-man" "-mandoc")
- execute_process(COMMAND "${NROFF}" ${_MANOPT}
- OUTPUT_VARIABLE NROFF_MANOPT_OUTPUT
- INPUT_FILE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt"
- ERROR_QUIET)
- # Save the option if it was valid
- if(NROFF_MANOPT_OUTPUT)
- message("Found *nroff option: -- ${_MANOPT}")
- set(NROFF_MANOPT ${_MANOPT})
- set(USE_MANUAL 1)
- break()
- endif()
- endforeach()
- # No need for the temporary file
- file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/nroff-input.txt")
- if(NOT USE_MANUAL)
- message(WARNING "Found no *nroff option to get plaintext from man pages")
- endif()
- else()
- message(WARNING "Found no *nroff program")
- endif()
-endif()
-
if(0) # This code not needed for building within CMake.
# Required for building manual, docs, tests
-find_package(Perl REQUIRED)
+curl_nroff_check()
+find_package(Perl)
+
+cmake_dependent_option(ENABLE_MANUAL "to provide the built-in manual"
+ ON "NROFF_USEFUL;PERL_FOUND"
+ OFF)
+
+if(NOT PERL_FOUND)
+ message(STATUS "Perl not found, testing disabled.")
+ set(BUILD_TESTING OFF)
+endif()
+if(ENABLE_MANUAL)
+ set(USE_MANUAL ON)
+endif()
endif()
# 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})
+if(CURL_STATIC_CRT)
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
+endif()
+
# Disable warnings on Borland to avoid changing 3rd party code.
if(BORLAND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
-endif(BORLAND)
+endif()
# 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)
+endif()
# Include all the necessary files for macros
-include (CheckFunctionExists)
-include (CheckIncludeFile)
-include (CheckIncludeFiles)
-include (CheckLibraryExists)
-include (CheckSymbolExists)
-include (CheckTypeSize)
-include (CheckCSourceCompiles)
+include(CheckFunctionExists)
+include(CheckIncludeFile)
+include(CheckIncludeFiles)
+include(CheckLibraryExists)
+include(CheckSymbolExists)
+include(CheckTypeSize)
+include(CheckCSourceCompiles)
# On windows preload settings
if(WIN32)
set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_WINSOCKAPI_=")
include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/Platforms/WindowsCache.cmake)
-endif(WIN32)
+endif()
if(ENABLE_THREADED_RESOLVER)
+ find_package(Threads REQUIRED)
if(WIN32)
set(USE_THREADS_WIN32 ON)
else()
- check_include_file_concat("pthread.h" HAVE_PTHREAD_H)
- if(HAVE_PTHREAD_H)
- set(CMAKE_THREAD_PREFER_PTHREAD 1)
- find_package(Threads)
- if(CMAKE_USE_PTHREADS_INIT)
- set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
- set(USE_THREADS_POSIX 1)
- endif()
- endif()
+ set(USE_THREADS_POSIX ${CMAKE_USE_PTHREADS_INIT})
+ set(HAVE_PTHREAD_H ${CMAKE_USE_PTHREADS_INIT})
endif()
+ set(CURL_LIBS ${CURL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()
# Check for all needed libraries
@@ -380,26 +373,27 @@ 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)
+endif()
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)
+endif()
check_function_exists(gethostname HAVE_GETHOSTNAME)
if(WIN32)
check_library_exists_concat("ws2_32" getch HAVE_LIBWS2_32)
check_library_exists_concat("winmm" getch HAVE_LIBWINMM)
+ list(APPEND CURL_LIBS "advapi32")
endif()
# check SSL libraries
-# TODO support GNUTLS, NSS, POLARSSL, AXTLS, CYASSL
+# TODO support GNUTLS, NSS, POLARSSL, CYASSL
if(APPLE)
- option(CMAKE_USE_DARWINSSL "enable Apple OS native SSL/TLS" OFF)
+ option(CMAKE_USE_SECTRANSP "enable Apple OS native SSL/TLS" OFF)
endif()
if(WIN32)
option(CMAKE_USE_WINSSL "enable Windows native SSL/TLS" OFF)
@@ -409,18 +403,18 @@ endif()
option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
set(openssl_default ON)
-if(WIN32 OR CMAKE_USE_DARWINSSL OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
+if(WIN32 OR CMAKE_USE_SECTRANSP OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
set(openssl_default OFF)
endif()
-collect_true(enabled_ssl_options enabled_ssl_options_count
+count_true(enabled_ssl_options_count
CMAKE_USE_WINSSL
- CMAKE_USE_DARWINSSL
+ CMAKE_USE_SECTRANSP
CMAKE_USE_OPENSSL
CMAKE_USE_MBEDTLS
)
-if(enabled_ssl_options_count GREATER 1)
- message(FATAL_ERROR "Multiple SSL options specified: ${enabled_ssl_options}. Please pick at most one and disable the rest.")
+if(enabled_ssl_options_count GREATER "1")
+ set(CURL_WITH_MULTI_SSL ON)
endif()
if(CMAKE_USE_WINSSL)
@@ -435,6 +429,10 @@ if(CURL_WINDOWS_SSPI)
endif()
if(CMAKE_USE_DARWINSSL)
+ message(FATAL_ERROR "The cmake option CMAKE_USE_DARWINSSL was renamed to CMAKE_USE_SECTRANSP.")
+endif()
+
+if(CMAKE_USE_SECTRANSP)
find_library(COREFOUNDATION_FRAMEWORK "CoreFoundation")
if(NOT COREFOUNDATION_FRAMEWORK)
message(FATAL_ERROR "CoreFoundation framework not found")
@@ -446,7 +444,7 @@ if(CMAKE_USE_DARWINSSL)
endif()
set(SSL_ENABLED ON)
- set(USE_DARWINSSL ON)
+ set(USE_SECTRANSP ON)
list(APPEND CURL_LIBS "${COREFOUNDATION_FRAMEWORK}" "${SECURITY_FRAMEWORK}")
endif()
@@ -458,12 +456,11 @@ if(CMAKE_USE_OPENSSL)
set(HAVE_LIBSSL ON)
list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
+
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR})
check_include_file("openssl/crypto.h" HAVE_OPENSSL_CRYPTO_H)
- check_include_file("openssl/engine.h" HAVE_OPENSSL_ENGINE_H)
check_include_file("openssl/err.h" HAVE_OPENSSL_ERR_H)
check_include_file("openssl/pem.h" HAVE_OPENSSL_PEM_H)
- check_include_file("openssl/pkcs12.h" HAVE_OPENSSL_PKCS12_H)
check_include_file("openssl/rsa.h" HAVE_OPENSSL_RSA_H)
check_include_file("openssl/ssl.h" HAVE_OPENSSL_SSL_H)
check_include_file("openssl/x509.h" HAVE_OPENSSL_X509_H)
@@ -582,6 +579,7 @@ if(NOT CURL_DISABLE_LDAP)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
endif()
check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
+ unset(CMAKE_REQUIRED_LIBRARIES)
if(NOT_NEED_LBER_H)
set(NEED_LBER_H OFF)
@@ -590,7 +588,6 @@ if(NOT CURL_DISABLE_LDAP)
endif()
endif()
endif()
-
endif()
# No ldap, no ldaps.
@@ -616,15 +613,23 @@ if(0) # This code not needed for building within CMake.
option(CURL_ZLIB "Set to ON to enable building curl with zlib support." ON)
set(HAVE_LIBZ OFF)
set(HAVE_ZLIB_H OFF)
-set(HAVE_ZLIB OFF)
+set(USE_ZLIB OFF)
if(CURL_ZLIB)
find_package(ZLIB QUIET)
if(ZLIB_FOUND)
set(HAVE_ZLIB_H ON)
- set(HAVE_ZLIB ON)
set(HAVE_LIBZ ON)
- list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
- include_directories(${ZLIB_INCLUDE_DIRS})
+ set(USE_ZLIB ON)
+
+ # Depend on ZLIB via imported targets if supported by the running
+ # version of CMake. This allows our dependents to get our dependencies
+ # transitively.
+ if(NOT CMAKE_VERSION VERSION_LESS 3.4)
+ list(APPEND CURL_LIBS ZLIB::ZLIB)
+ else()
+ list(APPEND CURL_LIBS ${ZLIB_LIBRARIES})
+ include_directories(${ZLIB_INCLUDE_DIRS})
+ endif()
list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
endif()
endif()
@@ -640,6 +645,18 @@ if(CURL_SPECIAL_LIBZ)
set(HAVE_ZLIB_H 0)
endif()
+option(CURL_BROTLI "Set to ON to enable building curl with brotli support." OFF)
+set(HAVE_BROTLI OFF)
+if(CURL_BROTLI)
+ find_package(BROTLI QUIET)
+ if(BROTLI_FOUND)
+ set(HAVE_BROTLI ON)
+ list(APPEND CURL_LIBS ${BROTLI_LIBRARIES})
+ include_directories(${BROTLI_INCLUDE_DIRS})
+ list(APPEND CMAKE_REQUIRED_INCLUDES ${BROTLI_INCLUDE_DIRS})
+ endif()
+endif()
+
#libSSH2
option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON)
mark_as_advanced(CMAKE_USE_LIBSSH2)
@@ -670,9 +687,9 @@ if(CMAKE_USE_LIBSSH2)
check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64)
check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE)
set(CMAKE_EXTRA_INCLUDE_FILES "")
-
- endif(LIBSSH2_FOUND)
-endif(CMAKE_USE_LIBSSH2)
+ unset(CMAKE_REQUIRED_LIBRARIES)
+ endif()
+endif()
option(CMAKE_USE_GSSAPI "Use GSSAPI implementation (right now only Heimdal is supported with CMake build)" OFF)
mark_as_advanced(CMAKE_USE_GSSAPI)
@@ -685,7 +702,7 @@ if(CMAKE_USE_GSSAPI)
message(STATUS "Found ${GSS_FLAVOUR} GSSAPI version: \"${GSS_VERSION}\"")
- list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRECTORIES})
+ list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIR})
check_include_file_concat("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H)
check_include_file_concat("gssapi/gssapi_generic.h" HAVE_GSSAPI_GSSAPI_GENERIC_H)
check_include_file_concat("gssapi/gssapi_krb5.h" HAVE_GSSAPI_GSSAPI_KRB5_H)
@@ -718,10 +735,11 @@ if(CMAKE_USE_GSSAPI)
if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE)
set(HAVE_OLD_GSSMIT ON)
endif()
+ unset(CMAKE_REQUIRED_LIBRARIES)
endif()
- include_directories(${GSS_INCLUDE_DIRECTORIES})
+ include_directories(${GSS_INCLUDE_DIR})
link_directories(${GSS_LINK_DIRECTORIES})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_COMPILER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LINKER_FLAGS}")
@@ -754,68 +772,67 @@ set(CURL_CA_PATH "auto" CACHE STRING
"Location of default CA path. Set 'none' to disable or 'auto' for auto-detection. Defaults to 'auto'.")
if("${CURL_CA_BUNDLE}" STREQUAL "")
- message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
+ message(FATAL_ERROR "Invalid value of CURL_CA_BUNDLE. Use 'none', 'auto' or file path.")
elseif("${CURL_CA_BUNDLE}" STREQUAL "none")
- unset(CURL_CA_BUNDLE CACHE)
+ unset(CURL_CA_BUNDLE CACHE)
elseif("${CURL_CA_BUNDLE}" STREQUAL "auto")
- unset(CURL_CA_BUNDLE CACHE)
- set(CURL_CA_BUNDLE_AUTODETECT TRUE)
+ unset(CURL_CA_BUNDLE CACHE)
+ set(CURL_CA_BUNDLE_AUTODETECT TRUE)
else()
- set(CURL_CA_BUNDLE_SET TRUE)
+ set(CURL_CA_BUNDLE_SET TRUE)
endif()
if("${CURL_CA_PATH}" STREQUAL "")
- message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
+ message(FATAL_ERROR "Invalid value of CURL_CA_PATH. Use 'none', 'auto' or directory path.")
elseif("${CURL_CA_PATH}" STREQUAL "none")
- unset(CURL_CA_PATH CACHE)
+ unset(CURL_CA_PATH CACHE)
elseif("${CURL_CA_PATH}" STREQUAL "auto")
- unset(CURL_CA_PATH CACHE)
- set(CURL_CA_PATH_AUTODETECT TRUE)
+ unset(CURL_CA_PATH CACHE)
+ set(CURL_CA_PATH_AUTODETECT TRUE)
else()
- set(CURL_CA_PATH_SET TRUE)
+ set(CURL_CA_PATH_SET TRUE)
endif()
if(CURL_CA_BUNDLE_SET AND CURL_CA_PATH_AUTODETECT)
- # Skip autodetection of unset CA path because CA bundle is set explicitly
+ # Skip autodetection of unset CA path because CA bundle is set explicitly
elseif(CURL_CA_PATH_SET AND CURL_CA_BUNDLE_AUTODETECT)
- # Skip autodetection of unset CA bundle because CA path is set explicitly
+ # Skip autodetection of unset CA bundle because CA path is set explicitly
elseif(CURL_CA_PATH_AUTODETECT OR CURL_CA_BUNDLE_AUTODETECT)
- # first try autodetecting a CA bundle, then a CA path
-
- if(CURL_CA_BUNDLE_AUTODETECT)
- set(SEARCH_CA_BUNDLE_PATHS
- /etc/ssl/certs/ca-certificates.crt
- /etc/pki/tls/certs/ca-bundle.crt
- /usr/share/ssl/certs/ca-bundle.crt
- /usr/local/share/certs/ca-root-nss.crt
- /etc/ssl/cert.pem)
-
- foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
- if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
- message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
- set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
- set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
- break()
- endif()
- endforeach()
- endif()
+ # first try autodetecting a CA bundle, then a CA path
+
+ if(CURL_CA_BUNDLE_AUTODETECT)
+ set(SEARCH_CA_BUNDLE_PATHS
+ /etc/ssl/certs/ca-certificates.crt
+ /etc/pki/tls/certs/ca-bundle.crt
+ /usr/share/ssl/certs/ca-bundle.crt
+ /usr/local/share/certs/ca-root-nss.crt
+ /etc/ssl/cert.pem)
+
+ foreach(SEARCH_CA_BUNDLE_PATH ${SEARCH_CA_BUNDLE_PATHS})
+ if(EXISTS "${SEARCH_CA_BUNDLE_PATH}")
+ message(STATUS "Found CA bundle: ${SEARCH_CA_BUNDLE_PATH}")
+ set(CURL_CA_BUNDLE "${SEARCH_CA_BUNDLE_PATH}")
+ set(CURL_CA_BUNDLE_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
+ break()
+ endif()
+ endforeach()
+ endif()
- if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
- if(EXISTS "/etc/ssl/certs")
- set(CURL_CA_PATH "/etc/ssl/certs")
- set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
- endif()
+ if(CURL_CA_PATH_AUTODETECT AND (NOT CURL_CA_PATH_SET))
+ if(EXISTS "/etc/ssl/certs")
+ set(CURL_CA_PATH "/etc/ssl/certs")
+ set(CURL_CA_PATH_SET TRUE CACHE BOOL "Path to the CA bundle has been set")
endif()
+ endif()
endif()
if(CURL_CA_PATH_SET AND NOT USE_OPENSSL AND NOT USE_MBEDTLS)
- message(FATAL_ERROR
- "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
- "Set CURL_CA_PATH=none or enable one of those TLS backends.")
+ message(FATAL_ERROR
+ "CA path only supported by OpenSSL, GnuTLS or mbed TLS. "
+ "Set CURL_CA_PATH=none or enable one of those TLS backends.")
endif()
endif()
-
# Check for header files
if(NOT UNIX)
check_include_file_concat("windows.h" HAVE_WINDOWS_H)
@@ -863,7 +880,6 @@ check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H)
check_include_file_concat("io.h" HAVE_IO_H)
check_include_file_concat("krb.h" HAVE_KRB_H)
check_include_file_concat("libgen.h" HAVE_LIBGEN_H)
-check_include_file_concat("limits.h" HAVE_LIMITS_H)
check_include_file_concat("locale.h" HAVE_LOCALE_H)
check_include_file_concat("net/if.h" HAVE_NET_IF_H)
check_include_file_concat("netdb.h" HAVE_NETDB_H)
@@ -911,15 +927,10 @@ check_type_size("int" SIZEOF_INT)
check_type_size("__int64" SIZEOF___INT64)
check_type_size("time_t" SIZEOF_TIME_T)
-# Make public versions of some type sizes for curlbuild.h.
-foreach(t INT LONG LONG_LONG SSIZE_T)
- string(REPLACE "SIZEOF_" "CURL_SIZEOF_" CURL_SIZEOF_${t}_CODE "${SIZEOF_${t}_CODE}")
-endforeach()
-
if(HAVE_SIZEOF_LONG_LONG)
set(HAVE_LONGLONG 1)
set(HAVE_LL 1)
-endif(HAVE_SIZEOF_LONG_LONG)
+endif()
find_file(RANDOM_FILE urandom /dev)
mark_as_advanced(RANDOM_FILE)
@@ -935,12 +946,8 @@ endif()
check_symbol_exists(basename "${CURL_INCLUDES}" HAVE_BASENAME)
check_symbol_exists(socket "${CURL_INCLUDES}" HAVE_SOCKET)
-# poll on macOS is unreliable, it first did not exist, then was broken until
-# fixed in 10.9 only to break again in 10.12.
-if(NOT APPLE)
- check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
-endif()
check_symbol_exists(select "${CURL_INCLUDES}" HAVE_SELECT)
+check_symbol_exists(poll "${CURL_INCLUDES}" HAVE_POLL)
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)
@@ -953,7 +960,7 @@ check_symbol_exists(strncmpi "${CURL_INCLUDES}" HAVE_STRNCMPI)
check_symbol_exists(alarm "${CURL_INCLUDES}" HAVE_ALARM)
if(NOT HAVE_STRNCMPI)
set(HAVE_STRCMPI)
-endif(NOT HAVE_STRNCMPI)
+endif()
check_symbol_exists(gethostbyaddr "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR)
check_symbol_exists(gethostbyaddr_r "${CURL_INCLUDES}" HAVE_GETHOSTBYADDR_R)
check_symbol_exists(gettimeofday "${CURL_INCLUDES}" HAVE_GETTIMEOFDAY)
@@ -969,6 +976,7 @@ check_symbol_exists(sigsetjmp "${CURL_INCLUDES}" HAVE_SIGSETJMP)
check_symbol_exists(getpass_r "${CURL_INCLUDES}" HAVE_GETPASS_R)
check_symbol_exists(strlcat "${CURL_INCLUDES}" HAVE_STRLCAT)
check_symbol_exists(getpwuid "${CURL_INCLUDES}" HAVE_GETPWUID)
+check_symbol_exists(getpwuid_r "${CURL_INCLUDES}" HAVE_GETPWUID_R)
check_symbol_exists(geteuid "${CURL_INCLUDES}" HAVE_GETEUID)
check_symbol_exists(utime "${CURL_INCLUDES}" HAVE_UTIME)
check_symbol_exists(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R)
@@ -981,7 +989,7 @@ 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)
+endif()
check_symbol_exists(uname "${CURL_INCLUDES}" HAVE_UNAME)
check_symbol_exists(strtoll "${CURL_INCLUDES}" HAVE_STRTOLL)
check_symbol_exists(_strtoi64 "${CURL_INCLUDES}" HAVE__STRTOI64)
@@ -995,42 +1003,57 @@ check_symbol_exists(freeifaddrs "${CURL_INCLUDES}" HAVE_FREEIFADDRS)
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(getpeername "${CURL_INCLUDES}" HAVE_GETPEERNAME)
+check_symbol_exists(getsockname "${CURL_INCLUDES}" HAVE_GETSOCKNAME)
check_symbol_exists(getrlimit "${CURL_INCLUDES}" HAVE_GETRLIMIT)
check_symbol_exists(setlocale "${CURL_INCLUDES}" HAVE_SETLOCALE)
+check_symbol_exists(setmode "${CURL_INCLUDES}" HAVE_SETMODE)
check_symbol_exists(setrlimit "${CURL_INCLUDES}" HAVE_SETRLIMIT)
check_symbol_exists(fcntl "${CURL_INCLUDES}" HAVE_FCNTL)
check_symbol_exists(ioctl "${CURL_INCLUDES}" HAVE_IOCTL)
check_symbol_exists(setsockopt "${CURL_INCLUDES}" HAVE_SETSOCKOPT)
+check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME)
# symbol exists in win32, but function does not.
-check_function_exists(inet_pton HAVE_INET_PTON)
+if(WIN32)
+ if(ENABLE_INET_PTON)
+ check_function_exists(inet_pton HAVE_INET_PTON)
+ # _WIN32_WINNT_VISTA (0x0600)
+ add_definitions(-D_WIN32_WINNT=0x0600)
+ else()
+ # _WIN32_WINNT_WINXP (0x0501)
+ add_definitions(-D_WIN32_WINNT=0x0501)
+ endif()
+else()
+ check_function_exists(inet_pton HAVE_INET_PTON)
+endif()
check_symbol_exists(fsetxattr "${CURL_INCLUDES}" HAVE_FSETXATTR)
if(HAVE_FSETXATTR)
foreach(CURL_TEST HAVE_FSETXATTR_5 HAVE_FSETXATTR_6)
- curl_internal_test_run(${CURL_TEST})
- endforeach(CURL_TEST)
-endif(HAVE_FSETXATTR)
+ curl_internal_test(${CURL_TEST})
+ endforeach()
+endif()
# 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)
+endif()
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)
+ endif()
+ endif()
+endif()
# If there is no stricmp(), do not allow LDAP to parse URLs
if(NOT HAVE_STRICMP)
set(HAVE_LDAP_URL_PARSE 1)
-endif(NOT HAVE_STRICMP)
+endif()
# Do curl specific tests
foreach(CURL_TEST
@@ -1057,7 +1080,6 @@ foreach(CURL_TEST
HAVE_GETHOSTBYNAME_R_3_REENTRANT
HAVE_GETHOSTBYNAME_R_5_REENTRANT
HAVE_GETHOSTBYNAME_R_6_REENTRANT
- HAVE_SOCKLEN_T
HAVE_IN_ADDR_T
HAVE_BOOL_T
STDC_HEADERS
@@ -1066,23 +1088,32 @@ foreach(CURL_TEST
HAVE_INET_NTOA_R_DECL_REENTRANT
HAVE_GETADDRINFO
HAVE_FILE_OFFSET_BITS
+ HAVE_VARIADIC_MACROS_C99
+ HAVE_VARIADIC_MACROS_GCC
)
curl_internal_test(${CURL_TEST})
-endforeach(CURL_TEST)
+endforeach()
if(HAVE_FILE_OFFSET_BITS)
set(_FILE_OFFSET_BITS 64)
set(CMAKE_REQUIRED_FLAGS "-D_FILE_OFFSET_BITS=64")
-endif(HAVE_FILE_OFFSET_BITS)
+endif()
check_type_size("off_t" SIZEOF_OFF_T)
+
+# include this header to get the type
+set(CMAKE_REQUIRED_INCLUDES "${CURL_SOURCE_DIR}/include")
+set(CMAKE_EXTRA_INCLUDE_FILES "curl/system.h")
+check_type_size("curl_off_t" SIZEOF_CURL_OFF_T)
+set(CMAKE_EXTRA_INCLUDE_FILES "")
+
set(CMAKE_REQUIRED_FLAGS)
foreach(CURL_TEST
HAVE_GLIBC_STRERROR_R
HAVE_POSIX_STRERROR_R
)
- curl_internal_test_run(${CURL_TEST})
-endforeach(CURL_TEST)
+ curl_internal_test(${CURL_TEST})
+endforeach()
# Check for reentrant
foreach(CURL_TEST
@@ -1096,9 +1127,9 @@ foreach(CURL_TEST
if(NOT ${CURL_TEST})
if(${CURL_TEST}_REENTRANT)
set(NEED_REENTRANT 1)
- endif(${CURL_TEST}_REENTRANT)
- endif(NOT ${CURL_TEST})
-endforeach(CURL_TEST)
+ endif()
+ endif()
+endforeach()
if(NEED_REENTRANT)
foreach(CURL_TEST
@@ -1111,32 +1142,38 @@ if(NEED_REENTRANT)
set(${CURL_TEST} 0)
if(${CURL_TEST}_REENTRANT)
set(${CURL_TEST} 1)
- endif(${CURL_TEST}_REENTRANT)
- endforeach(CURL_TEST)
-endif(NEED_REENTRANT)
+ endif()
+ endforeach()
+endif()
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)
+endif()
+
+# Check clock_gettime(CLOCK_MONOTONIC, x) support
+curl_internal_test(HAVE_CLOCK_GETTIME_MONOTONIC)
+
+# Check compiler support of __builtin_available()
+curl_internal_test(HAVE_BUILTIN_AVAILABLE)
# Some other minor tests
if(NOT HAVE_IN_ADDR_T)
set(in_addr_t "unsigned long")
-endif(NOT HAVE_IN_ADDR_T)
+endif()
# Fix libz / zlib.h
if(NOT CURL_SPECIAL_LIBZ)
if(NOT HAVE_LIBZ)
set(HAVE_ZLIB_H 0)
- endif(NOT HAVE_LIBZ)
+ endif()
if(NOT HAVE_ZLIB_H)
set(HAVE_LIBZ 0)
- endif(NOT HAVE_ZLIB_H)
-endif(NOT CURL_SPECIAL_LIBZ)
+ endif()
+endif()
# Check for nonblocking
set(HAVE_DISABLED_NONBLOCKING 1)
@@ -1145,16 +1182,13 @@ if(HAVE_FIONBIO 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)
+endif()
if(RETSIGTYPE_TEST)
set(RETSIGTYPE void)
-else(RETSIGTYPE_TEST)
+else()
set(RETSIGTYPE int)
-endif(RETSIGTYPE_TEST)
+endif()
if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
include(CheckCCompilerFlag)
@@ -1164,33 +1198,15 @@ if(CMAKE_COMPILER_IS_GNUCC AND APPLE)
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)
+ else()
set(MPRINTF_COMPILE_FLAGS "-Wno-long-double")
- endif(MPRINTF_COMPILE_FLAGS)
+ endif()
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)
-
-if(HAVE_SOCKLEN_T)
- set(CURL_HAVE_SOCKLEN_T 1)
- set(CURL_TYPEOF_CURL_SOCKLEN_T "socklen_t")
- if(WIN32)
- set(CMAKE_EXTRA_INCLUDE_FILES "winsock2.h;ws2tcpip.h")
- elseif(HAVE_SYS_SOCKET_H)
- set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
endif()
- check_type_size("socklen_t" CURL_SIZEOF_CURL_SOCKLEN_T)
- set(CMAKE_EXTRA_INCLUDE_FILES)
- if(NOT HAVE_CURL_SIZEOF_CURL_SOCKLEN_T)
- message(FATAL_ERROR
- "Check for sizeof socklen_t failed, see CMakeFiles/CMakerror.log")
- endif()
-else()
- set(CURL_HAVE_SOCKLEN_T 0)
endif()
-# TODO test which of these headers are required for the typedefs used in curlbuild.h
+# TODO test which of these headers are required
if(WIN32)
set(CURL_PULL_WS2TCPIP_H ${HAVE_WS2TCPIP_H})
else()
@@ -1205,22 +1221,37 @@ include(CMake/OtherTests.cmake)
add_definitions(-DHAVE_CONFIG_H)
-# For windows, do not allow the compiler to use default target (Vista).
-if(WIN32)
- add_definitions(-D_WIN32_WINNT=0x0501)
-endif(WIN32)
-
-# For windows, all compilers used by cmake should support large files
+# For Windows, all compilers used by CMake should support large files
if(WIN32)
set(USE_WIN32_LARGE_FILES ON)
-endif(WIN32)
+
+ # Use the manifest embedded in the Windows Resource
+ set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DCURL_EMBED_MANIFEST")
+endif()
if(MSVC)
+ # Disable default manifest added by CMake
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
+
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
-endif(MSVC)
+ if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
+ string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+ else()
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
+ endif()
+endif()
+
+if(CURL_WERROR)
+ if(MSVC_VERSION)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
+ else()
+ # this assumes clang or gcc style options
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
+ endif()
+endif()
# Ugly (but functional) way to include "Makefile.inc" by transforming it (= regenerate it).
-function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
+function(transform_makefile_inc INPUT_FILE OUTPUT_FILE)
file(READ ${INPUT_FILE} MAKEFILE_INC_TEXT)
string(REPLACE "$(top_srcdir)" "\${CURL_SOURCE_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
string(REPLACE "$(top_builddir)" "\${CURL_BINARY_DIR}" MAKEFILE_INC_TEXT ${MAKEFILE_INC_TEXT})
@@ -1236,20 +1267,32 @@ function(TRANSFORM_MAKEFILE_INC INPUT_FILE OUTPUT_FILE)
endfunction()
if(0) # This code not needed for building within CMake.
-add_subdirectory(docs)
+include(GNUInstallDirs)
+
+set(CURL_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
+set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
+set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
+set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
+set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
endif()
+
+if(USE_MANUAL)
+ add_subdirectory(docs)
+endif()
+
add_subdirectory(lib)
+
if(BUILD_CURL_EXE)
add_subdirectory(src)
endif()
#-----------------------------------------------------------------------------
# CMake-specific curl code.
-add_executable(LIBCURL curltest.c)
-target_link_libraries(LIBCURL cmcurl)
+add_executable(curltest curltest.c)
+target_link_libraries(curltest cmcurl)
-if(CMAKE_CURL_TEST_URL)
- add_test(curl LIBCURL ${CMAKE_CURL_TEST_URL})
+if(BUILD_TESTING AND CMAKE_CURL_TEST_URL)
+ add_test(curl curltest ${CMAKE_CURL_TEST_URL})
endif()
install(FILES COPYING DESTINATION ${CMAKE_DOC_DIR}/cmcurl)
@@ -1272,10 +1315,7 @@ endfunction()
# Clear list and try to detect available features
set(_items)
-_add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
-_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
-_add_if("DarwinSSL" SSL_ENABLED AND USE_DARWINSSL)
-_add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
+_add_if("SSL" SSL_ENABLED)
_add_if("IPv6" ENABLE_IPV6)
_add_if("unix-sockets" USE_UNIX_SOCKETS)
_add_if("libz" HAVE_LIBZ)
@@ -1293,7 +1333,7 @@ _add_if("Kerberos" NOT CURL_DISABLE_CRYPTO_AUTH AND
(HAVE_GSSAPI OR USE_WINDOWS_SSPI))
# NTLM support requires crypto function adaptions from various SSL libs
# TODO alternative SSL libs tests for SSP1, GNUTLS, NSS
-if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_DARWINSSL OR USE_MBEDTLS))
+if(NOT CURL_DISABLE_CRYPTO_AUTH AND (USE_OPENSSL OR USE_WINDOWS_SSPI OR USE_SECTRANSP OR USE_MBEDTLS))
_add_if("NTLM" 1)
# TODO missing option (autoconf: --enable-ntlm-wb)
_add_if("NTLM_WB" NOT CURL_DISABLE_HTTP AND NTLM_WB_ENABLED)
@@ -1332,10 +1372,24 @@ _add_if("SCP" USE_LIBSSH2)
_add_if("SFTP" USE_LIBSSH2)
_add_if("RTSP" NOT CURL_DISABLE_RTSP)
_add_if("RTMP" USE_LIBRTMP)
-list(SORT _items)
+if(_items)
+ list(SORT _items)
+endif()
string(REPLACE ";" " " SUPPORT_PROTOCOLS "${_items}")
message(STATUS "Enabled protocols: ${SUPPORT_PROTOCOLS}")
+# Clear list and collect SSL backends
+set(_items)
+_add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
+_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
+_add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
+_add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
+if(_items)
+ list(SORT _items)
+endif()
+string(REPLACE ";" " " SSL_BACKENDS "${_items}")
+message(STATUS "Enabled SSL backends: ${SSL_BACKENDS}")
+
# curl-config needs the following options to be set.
set(CC "${CMAKE_C_COMPILER}")
# TODO probably put a -D... options here?
@@ -1343,11 +1397,12 @@ set(CONFIGURE_OPTIONS "")
# TODO when to set "-DCURL_STATICLIB" for CPPFLAG_CURL_STATICLIB?
set(CPPFLAG_CURL_STATICLIB "")
set(CURLVERSION "${CURL_VERSION}")
-set(ENABLE_SHARED "yes")
-if(CURL_STATICLIB)
- set(ENABLE_STATIC "yes")
-else()
+if(BUILD_SHARED_LIBS)
+ set(ENABLE_SHARED "yes")
set(ENABLE_STATIC "no")
+else()
+ set(ENABLE_SHARED "no")
+ set(ENABLE_STATIC "yes")
endif()
set(exec_prefix "\${prefix}")
set(includedir "\${prefix}/include")
@@ -1355,7 +1410,7 @@ set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
set(LIBCURL_LIBS "")
set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
- if(_lib MATCHES ".*/.*")
+ if(_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
set(LIBCURL_LIBS "${LIBCURL_LIBS} ${_lib}")
else()
set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
@@ -1371,10 +1426,13 @@ set(REQUIRE_LIB_DEPS "no")
set(VERSIONNUM "${CURL_VERSION_NUM}")
# Finally generate a "curl-config" matching this config
+# Use:
+# * ENABLE_SHARED
+# * ENABLE_STATIC
configure_file("${CURL_SOURCE_DIR}/curl-config.in"
"${CURL_BINARY_DIR}/curl-config" @ONLY)
install(FILES "${CURL_BINARY_DIR}/curl-config"
- DESTINATION bin
+ DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
@@ -1384,23 +1442,38 @@ install(FILES "${CURL_BINARY_DIR}/curl-config"
configure_file("${CURL_SOURCE_DIR}/libcurl.pc.in"
"${CURL_BINARY_DIR}/libcurl.pc" @ONLY)
install(FILES "${CURL_BINARY_DIR}/libcurl.pc"
- DESTINATION lib/pkgconfig)
-
-# This needs to be run very last so other parts of the scripts can take advantage of this.
-if(NOT CURL_CONFIG_HAS_BEEN_RUN_BEFORE)
- set(CURL_CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track whether this is the first time running CMake or if CMake has been configured before")
-endif()
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
-# Installation.
-# First, install generated curlbuild.h
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/include/curl/curlbuild.h"
- DESTINATION include/curl )
-# Next, install other headers excluding curlbuild.h
+# install headers
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/curl"
- DESTINATION include
- FILES_MATCHING PATTERN "*.h"
- PATTERN "curlbuild.h" EXCLUDE)
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+ FILES_MATCHING PATTERN "*.h")
+
+include(CMakePackageConfigHelpers)
+write_basic_package_version_file(
+ "${version_config}"
+ VERSION ${CURL_VERSION}
+ COMPATIBILITY SameMajorVersion
+)
+# Use:
+# * TARGETS_EXPORT_NAME
+# * PROJECT_NAME
+configure_package_config_file(CMake/curl-config.cmake.in
+ "${project_config}"
+ INSTALL_DESTINATION ${CURL_INSTALL_CMAKE_DIR}
+)
+
+install(
+ EXPORT "${TARGETS_EXPORT_NAME}"
+ NAMESPACE "${PROJECT_NAME}::"
+ DESTINATION ${CURL_INSTALL_CMAKE_DIR}
+)
+
+install(
+ FILES ${version_config} ${project_config}
+ DESTINATION ${CURL_INSTALL_CMAKE_DIR}
+)
# Workaround for MSVS10 to avoid the Dialog Hell
# FIXME: This could be removed with future version of CMake.
@@ -1410,4 +1483,15 @@ if(MSVC_VERSION EQUAL 1600)
file(APPEND "${CURL_SLN_FILENAME}" "\n# This should be regenerated!\n")
endif()
endif()
+
+if(NOT TARGET uninstall)
+ configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_uninstall.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake
+ IMMEDIATE @ONLY)
+
+ add_custom_target(uninstall
+ COMMAND ${CMAKE_COMMAND} -P
+ ${CMAKE_CURRENT_BINARY_DIR}/CMake/cmake_uninstall.cmake)
+endif()
endif()
diff --git a/Utilities/cmcurl/COPYING b/Utilities/cmcurl/COPYING
index 1e45a5e2c..3528bd756 100644
--- a/Utilities/cmcurl/COPYING
+++ b/Utilities/cmcurl/COPYING
@@ -1,6 +1,6 @@
COPYRIGHT AND PERMISSION NOTICE
-Copyright (c) 1996 - 2017, Daniel Stenberg, <daniel@haxx.se>, and many
+Copyright (c) 1996 - 2019, Daniel Stenberg, <daniel@haxx.se>, and many
contributors, see the THANKS file.
All rights reserved.
diff --git a/Utilities/cmcurl/curltest.c b/Utilities/cmcurl/curltest.c
index 210868e36..f80e758a0 100644
--- a/Utilities/cmcurl/curltest.c
+++ b/Utilities/cmcurl/curltest.c
@@ -1,159 +1,81 @@
-/* Prevent warnings on Visual Studio */
-struct _RPC_ASYNC_STATE;
-
#include "curl/curl.h"
+
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-int GetFtpFile(void)
+int test_curl(const char* url)
{
- 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;
-
+ CURL* curl;
+ CURLcode r;
char proxy[1024];
int proxy_type = 0;
- if ( getenv("HTTP_PROXY") )
- {
+ if (getenv("HTTP_PROXY")) {
proxy_type = 1;
- if (getenv("HTTP_PROXY_PORT") )
- {
+ if (getenv("HTTP_PROXY_PORT")) {
sprintf(proxy, "%s:%s", getenv("HTTP_PROXY"), getenv("HTTP_PROXY_PORT"));
- }
- else
- {
+ } else {
sprintf(proxy, "%s", getenv("HTTP_PROXY"));
- }
- if ( getenv("HTTP_PROXY_TYPE") )
- {
+ }
+ if (getenv("HTTP_PROXY_TYPE")) {
/* HTTP/SOCKS4/SOCKS5 */
- if ( strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0 )
- {
+ if (strcmp(getenv("HTTP_PROXY_TYPE"), "HTTP") == 0) {
proxy_type = 1;
- }
- else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0 )
- {
+ } else if (strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS4") == 0) {
proxy_type = 2;
- }
- else if ( strcmp(getenv("HTTP_PROXY_TYPE"), "SOCKS5") == 0 )
- {
+ } 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;
- }
+ if (!curl) {
+ fprintf(stderr, "curl_easy_init failed\n");
+ return 1;
+ }
+
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(curl, CURLOPT_HEADER, 1);
+
+ 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 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;
- }
- */
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ r = curl_easy_perform(curl);
+ curl_easy_cleanup(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
- }
- else
- {
- printf("Cannot create curl object\n");
- retVal = 1;
- }
+ if (r != CURLE_OK) {
+ fprintf(stderr, "error: fetching '%s' failed: %s\n", url,
+ curl_easy_strerror(r));
+ return 1;
+ }
- return retVal;
+ return 0;
}
-
-int main(int argc, char **argv)
+int main(int argc, const char* argv[])
{
- int retVal = 0;
-
+ int r;
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 */
-
+ if (argc == 2) {
+ r = test_curl(argv[1]);
+ } else {
+ fprintf(stderr, "error: no URL given as first argument\n");
+ r = 1;
+ }
curl_global_cleanup();
-
- return retVal;
+ return r;
}
diff --git a/Utilities/cmcurl/include/curl/curl.h b/Utilities/cmcurl/include/curl/curl.h
index 395521202..089c427db 100644
--- a/Utilities/cmcurl/include/curl/curl.h
+++ b/Utilities/cmcurl/include/curl/curl.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -36,8 +36,6 @@
#include "curlver.h" /* libcurl version defines */
#include "system.h" /* determine things run-time */
-#include "cmcurl/include/curl/curlbuild.h" /* libcurl build definitions */
-#include "curlrules.h" /* libcurl rules enforcement */
/*
* Define WIN32 when build target is Win32 API
@@ -76,6 +74,7 @@
#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
+ defined(__CYGWIN__) || \
(defined(__FreeBSD_version) && (__FreeBSD_version < 800000))
#include <sys/select.h>
#endif
@@ -92,6 +91,11 @@
#include <support/SupportDefs.h>
#endif
+/* Compatibility for non-Clang compilers */
+#ifndef __has_declspec_attribute
+# define __has_declspec_attribute(x) 0
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -110,7 +114,9 @@ typedef void CURLSH;
#ifdef CURL_STATICLIB
# define CURL_EXTERN
-#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)
+#elif defined(WIN32) || defined(__SYMBIAN32__) || \
+ (__has_declspec_attribute(dllexport) && \
+ __has_declspec_attribute(dllimport))
# if defined(BUILDING_LIBCURL)
# define CURL_EXTERN __declspec(dllexport)
# else
@@ -134,6 +140,31 @@ typedef int curl_socket_t;
#define curl_socket_typedef
#endif /* curl_socket_typedef */
+/* enum for the different supported SSL backends */
+typedef enum {
+ CURLSSLBACKEND_NONE = 0,
+ CURLSSLBACKEND_OPENSSL = 1,
+ CURLSSLBACKEND_GNUTLS = 2,
+ CURLSSLBACKEND_NSS = 3,
+ CURLSSLBACKEND_OBSOLETE4 = 4, /* Was QSOSSL. */
+ CURLSSLBACKEND_GSKIT = 5,
+ CURLSSLBACKEND_POLARSSL = 6,
+ CURLSSLBACKEND_WOLFSSL = 7,
+ CURLSSLBACKEND_SCHANNEL = 8,
+ CURLSSLBACKEND_SECURETRANSPORT = 9,
+ CURLSSLBACKEND_AXTLS = 10, /* never used since 7.63.0 */
+ CURLSSLBACKEND_MBEDTLS = 11,
+ CURLSSLBACKEND_MESALINK = 12
+} curl_sslbackend;
+
+/* aliases for library clones and renames */
+#define CURLSSLBACKEND_LIBRESSL CURLSSLBACKEND_OPENSSL
+#define CURLSSLBACKEND_BORINGSSL CURLSSLBACKEND_OPENSSL
+
+/* deprecated names: */
+#define CURLSSLBACKEND_CYASSL CURLSSLBACKEND_WOLFSSL
+#define CURLSSLBACKEND_DARWINSSL CURLSSLBACKEND_SECURETRANSPORT
+
struct curl_httppost {
struct curl_httppost *next; /* next entry in the list */
char *name; /* pointer to allocated name */
@@ -225,7 +256,9 @@ typedef size_t (*curl_write_callback)(char *buffer,
size_t nitems,
void *outstream);
-
+/* This callback will be called when a new resolver request is made */
+typedef int (*curl_resolver_start_callback)(void *resolver_state,
+ void *reserved, void *userdata);
/* enumeration of file types */
typedef enum {
@@ -257,7 +290,7 @@ typedef enum {
struct curl_fileinfo {
char *filename;
curlfiletype filetype;
- time_t time;
+ time_t time; /* always zero! */
unsigned int perm;
int uid;
int gid;
@@ -332,12 +365,22 @@ typedef int (*curl_seek_callback)(void *instream,
signal libcurl to pause sending data on the current transfer. */
#define CURL_READFUNC_PAUSE 0x10000001
+/* Return code for when the trailing headers' callback has terminated
+ without any errors*/
+#define CURL_TRAILERFUNC_OK 0
+/* Return code for when was an error in the trailing header's list and we
+ want to abort the request */
+#define CURL_TRAILERFUNC_ABORT 1
+
typedef size_t (*curl_read_callback)(char *buffer,
size_t size,
size_t nitems,
void *instream);
-typedef enum {
+typedef int (*curl_trailer_callback)(struct curl_slist **list,
+ void *userdata);
+
+typedef enum {
CURLSOCKTYPE_IPCXN, /* socket created for a specific IP connection */
CURLSOCKTYPE_ACCEPT, /* socket created by accept() call */
CURLSOCKTYPE_LAST /* never use */
@@ -379,7 +422,7 @@ typedef enum {
CURLIOE_LAST /* never use */
} curlioerr;
-typedef enum {
+typedef enum {
CURLIOCMD_NOP, /* no operation */
CURLIOCMD_RESTARTREAD, /* restart the read stream from start */
CURLIOCMD_LAST /* never use */
@@ -495,8 +538,7 @@ typedef enum {
CURLE_UNKNOWN_OPTION, /* 48 - User specified an unknown option */
CURLE_TELNET_OPTION_SYNTAX, /* 49 - Malformed telnet option */
CURLE_OBSOLETE50, /* 50 - NOT USED */
- CURLE_PEER_FAILED_VERIFICATION, /* 51 - peer's certificate or fingerprint
- wasn't verified fine */
+ CURLE_OBSOLETE51, /* 51 - NOT USED */
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
@@ -506,7 +548,8 @@ typedef enum {
CURLE_OBSOLETE57, /* 57 - NOT 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_PEER_FAILED_VERIFICATION, /* 60 - peer's certificate or fingerprint
+ wasn't verified fine */
CURLE_BAD_CONTENT_ENCODING, /* 61 - Unrecognized/bad encoding */
CURLE_LDAP_INVALID_URL, /* 62 - Invalid LDAP URL */
CURLE_FILESIZE_EXCEEDED, /* 63 - Maximum file size exceeded */
@@ -557,6 +600,8 @@ typedef enum {
CURLE_SSL_INVALIDCERTSTATUS, /* 91 - invalid certificate status */
CURLE_HTTP2_STREAM, /* 92 - stream error in HTTP/2 framing layer
*/
+ CURLE_RECURSIVE_API_CALL, /* 93 - an api function was called from
+ inside a callback */
CURL_LAST /* never use! */
} CURLcode;
@@ -574,6 +619,9 @@ typedef enum {
#define CURLOPT_ENCODING CURLOPT_ACCEPT_ENCODING
#define CURLE_FTP_WEIRD_SERVER_REPLY CURLE_WEIRD_SERVER_REPLY
+/* The following were added in 7.62.0 */
+#define CURLE_SSL_CACERT CURLE_PEER_FAILED_VERIFICATION
+
/* The following were added in 7.21.5, April 2011 */
#define CURLE_UNKNOWN_TELNET_OPTION CURLE_UNKNOWN_OPTION
@@ -667,6 +715,7 @@ typedef enum {
* CURLAUTH_NTLM - HTTP NTLM authentication
* CURLAUTH_DIGEST_IE - HTTP Digest authentication with IE flavour
* CURLAUTH_NTLM_WB - HTTP NTLM authentication delegated to winbind helper
+ * CURLAUTH_BEARER - HTTP Bearer token authentication
* CURLAUTH_ONLY - Use together with a single other type to force no
* authentication or just that single type
* CURLAUTH_ANY - All fine types set
@@ -679,9 +728,12 @@ typedef enum {
#define CURLAUTH_NEGOTIATE (((unsigned long)1)<<2)
/* Deprecated since the advent of CURLAUTH_NEGOTIATE */
#define CURLAUTH_GSSNEGOTIATE CURLAUTH_NEGOTIATE
+/* Used for CURLOPT_SOCKS5_AUTH to stay terminologically correct */
+#define CURLAUTH_GSSAPI CURLAUTH_NEGOTIATE
#define CURLAUTH_NTLM (((unsigned long)1)<<3)
#define CURLAUTH_DIGEST_IE (((unsigned long)1)<<4)
#define CURLAUTH_NTLM_WB (((unsigned long)1)<<5)
+#define CURLAUTH_BEARER (((unsigned long)1)<<6)
#define CURLAUTH_ONLY (((unsigned long)1)<<31)
#define CURLAUTH_ANY (~CURLAUTH_DIGEST_IE)
#define CURLAUTH_ANYSAFE (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE))
@@ -693,6 +745,7 @@ typedef enum {
#define CURLSSH_AUTH_HOST (1<<2) /* host key files */
#define CURLSSH_AUTH_KEYBOARD (1<<3) /* keyboard interactive */
#define CURLSSH_AUTH_AGENT (1<<4) /* agent (ssh-agent, pageant...) */
+#define CURLSSH_AUTH_GSSAPI (1<<5) /* gssapi (kerberos, ...) */
#define CURLSSH_AUTH_DEFAULT CURLSSH_AUTH_ANY
#define CURLGSSAPI_DELEGATION_NONE 0 /* no delegation (default) */
@@ -705,7 +758,9 @@ enum curl_khtype {
CURLKHTYPE_UNKNOWN,
CURLKHTYPE_RSA1,
CURLKHTYPE_RSA,
- CURLKHTYPE_DSS
+ CURLKHTYPE_DSS,
+ CURLKHTYPE_ECDSA,
+ CURLKHTYPE_ED25519
};
struct curl_khkey {
@@ -764,6 +819,14 @@ typedef enum {
SSL backends where such behavior is present. */
#define CURLSSLOPT_NO_REVOKE (1<<1)
+/* The default connection attempt delay in milliseconds for happy eyeballs.
+ CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS.3 and happy-eyeballs-timeout-ms.d document
+ this value, keep them in sync. */
+#define CURL_HET_DEFAULT 200L
+
+/* The default connection upkeep interval in milliseconds. */
+#define CURL_UPKEEP_INTERVAL_DEFAULT 60000L
+
#ifndef CURL_NO_OLDIES /* define this to test if your app builds with all
the obsolete stuff removed! */
@@ -818,6 +881,14 @@ typedef enum {
#define CURLHEADER_UNIFIED 0
#define CURLHEADER_SEPARATE (1<<0)
+/* CURLALTSVC_* are bits for the CURLOPT_ALTSVC_CTRL option */
+#define CURLALTSVC_IMMEDIATELY (1<<0)
+#define CURLALTSVC_ALTUSED (1<<1)
+#define CURLALTSVC_READONLYFILE (1<<2)
+#define CURLALTSVC_H1 (1<<3)
+#define CURLALTSVC_H2 (1<<4)
+#define CURLALTSVC_H3 (1<<5)
+
/* CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */
#define CURLPROTO_HTTP (1<<0)
#define CURLPROTO_HTTPS (1<<1)
@@ -913,7 +984,7 @@ typedef enum {
CINIT(READDATA, 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: */
+ * bytes big. */
CINIT(ERRORBUFFER, OBJECTPOINT, 10),
/* Function that will be called to store the output (instead of fwrite). The
@@ -1637,7 +1708,7 @@ typedef enum {
* Only supported by the c-ares DNS backend */
CINIT(DNS_LOCAL_IP4, STRINGPOINT, 222),
- /* Set the local IPv4 address to use for outgoing DNS requests.
+ /* Set the local IPv6 address to use for outgoing DNS requests.
* Only supported by the c-ares DNS backend */
CINIT(DNS_LOCAL_IP6, STRINGPOINT, 223),
@@ -1782,6 +1853,74 @@ typedef enum {
/* Suppress proxy CONNECT response headers from user callbacks */
CINIT(SUPPRESS_CONNECT_HEADERS, LONG, 265),
+ /* The request target, instead of extracted from the URL */
+ CINIT(REQUEST_TARGET, STRINGPOINT, 266),
+
+ /* bitmask of allowed auth methods for connections to SOCKS5 proxies */
+ CINIT(SOCKS5_AUTH, LONG, 267),
+
+ /* Enable/disable SSH compression */
+ CINIT(SSH_COMPRESSION, LONG, 268),
+
+ /* Post MIME data. */
+ CINIT(MIMEPOST, OBJECTPOINT, 269),
+
+ /* Time to use with the CURLOPT_TIMECONDITION. Specified in number of
+ seconds since 1 Jan 1970. */
+ CINIT(TIMEVALUE_LARGE, OFF_T, 270),
+
+ /* Head start in milliseconds to give happy eyeballs. */
+ CINIT(HAPPY_EYEBALLS_TIMEOUT_MS, LONG, 271),
+
+ /* Function that will be called before a resolver request is made */
+ CINIT(RESOLVER_START_FUNCTION, FUNCTIONPOINT, 272),
+
+ /* User data to pass to the resolver start callback. */
+ CINIT(RESOLVER_START_DATA, OBJECTPOINT, 273),
+
+ /* send HAProxy PROXY protocol header? */
+ CINIT(HAPROXYPROTOCOL, LONG, 274),
+
+ /* shuffle addresses before use when DNS returns multiple */
+ CINIT(DNS_SHUFFLE_ADDRESSES, LONG, 275),
+
+ /* Specify which TLS 1.3 ciphers suites to use */
+ CINIT(TLS13_CIPHERS, STRINGPOINT, 276),
+ CINIT(PROXY_TLS13_CIPHERS, STRINGPOINT, 277),
+
+ /* Disallow specifying username/login in URL. */
+ CINIT(DISALLOW_USERNAME_IN_URL, LONG, 278),
+
+ /* DNS-over-HTTPS URL */
+ CINIT(DOH_URL, STRINGPOINT, 279),
+
+ /* Preferred buffer size to use for uploads */
+ CINIT(UPLOAD_BUFFERSIZE, LONG, 280),
+
+ /* Time in ms between connection upkeep calls for long-lived connections. */
+ CINIT(UPKEEP_INTERVAL_MS, LONG, 281),
+
+ /* Specify URL using CURL URL API. */
+ CINIT(CURLU, OBJECTPOINT, 282),
+
+ /* add trailing data just after no more data is available */
+ CINIT(TRAILERFUNCTION, FUNCTIONPOINT, 283),
+
+ /* pointer to be passed to HTTP_TRAILER_FUNCTION */
+ CINIT(TRAILERDATA, OBJECTPOINT, 284),
+
+ /* set this to 1L to allow HTTP/0.9 responses or 0L to disallow */
+ CINIT(HTTP09_ALLOWED, LONG, 285),
+
+ /* alt-svc control bitmask */
+ CINIT(ALTSVC_CTRL, LONG, 286),
+
+ /* alt-svc cache file name to possibly read from/write to */
+ CINIT(ALTSVC, STRINGPOINT, 287),
+
+ /* maximum age of a connection to consider it for reuse (in seconds) */
+ CINIT(MAXAGE_CONN, LONG, 288),
+
CURLOPT_LASTENTRY /* the last unused */
} CURLoption;
@@ -1928,15 +2067,140 @@ typedef enum {
CURL_TIMECOND_LAST
} curl_TimeCond;
+/* Special size_t value signaling a zero-terminated string. */
+#define CURL_ZERO_TERMINATED ((size_t) -1)
/* curl_strequal() and curl_strnequal() are subject for removal in a future
- libcurl, see lib/README.curlx for details
+ release */
+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);
+
+/* Mime/form handling support. */
+typedef struct curl_mime_s curl_mime; /* Mime context. */
+typedef struct curl_mimepart_s curl_mimepart; /* Mime part context. */
+
+/*
+ * NAME curl_mime_init()
+ *
+ * DESCRIPTION
+ *
+ * Create a mime context and return its handle. The easy parameter is the
+ * target handle.
+ */
+CURL_EXTERN curl_mime *curl_mime_init(CURL *easy);
- !checksrc! disable SPACEBEFOREPAREN 2
-*/
-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 curl_mime_free()
+ *
+ * DESCRIPTION
+ *
+ * release a mime handle and its substructures.
+ */
+CURL_EXTERN void curl_mime_free(curl_mime *mime);
+/*
+ * NAME curl_mime_addpart()
+ *
+ * DESCRIPTION
+ *
+ * Append a new empty part to the given mime context and return a handle to
+ * the created part.
+ */
+CURL_EXTERN curl_mimepart *curl_mime_addpart(curl_mime *mime);
+
+/*
+ * NAME curl_mime_name()
+ *
+ * DESCRIPTION
+ *
+ * Set mime/form part name.
+ */
+CURL_EXTERN CURLcode curl_mime_name(curl_mimepart *part, const char *name);
+
+/*
+ * NAME curl_mime_filename()
+ *
+ * DESCRIPTION
+ *
+ * Set mime part remote file name.
+ */
+CURL_EXTERN CURLcode curl_mime_filename(curl_mimepart *part,
+ const char *filename);
+
+/*
+ * NAME curl_mime_type()
+ *
+ * DESCRIPTION
+ *
+ * Set mime part type.
+ */
+CURL_EXTERN CURLcode curl_mime_type(curl_mimepart *part, const char *mimetype);
+
+/*
+ * NAME curl_mime_encoder()
+ *
+ * DESCRIPTION
+ *
+ * Set mime data transfer encoder.
+ */
+CURL_EXTERN CURLcode curl_mime_encoder(curl_mimepart *part,
+ const char *encoding);
+
+/*
+ * NAME curl_mime_data()
+ *
+ * DESCRIPTION
+ *
+ * Set mime part data source from memory data,
+ */
+CURL_EXTERN CURLcode curl_mime_data(curl_mimepart *part,
+ const char *data, size_t datasize);
+
+/*
+ * NAME curl_mime_filedata()
+ *
+ * DESCRIPTION
+ *
+ * Set mime part data source from named file.
+ */
+CURL_EXTERN CURLcode curl_mime_filedata(curl_mimepart *part,
+ const char *filename);
+
+/*
+ * NAME curl_mime_data_cb()
+ *
+ * DESCRIPTION
+ *
+ * Set mime part data source from callback function.
+ */
+CURL_EXTERN CURLcode curl_mime_data_cb(curl_mimepart *part,
+ curl_off_t datasize,
+ curl_read_callback readfunc,
+ curl_seek_callback seekfunc,
+ curl_free_callback freefunc,
+ void *arg);
+
+/*
+ * NAME curl_mime_subparts()
+ *
+ * DESCRIPTION
+ *
+ * Set mime part data source from subparts.
+ */
+CURL_EXTERN CURLcode curl_mime_subparts(curl_mimepart *part,
+ curl_mime *subparts);
+/*
+ * NAME curl_mime_headers()
+ *
+ * DESCRIPTION
+ *
+ * Set mime part headers.
+ */
+CURL_EXTERN CURLcode curl_mime_headers(curl_mimepart *part,
+ struct curl_slist *headers,
+ int take_ownership);
+
+/* Old form API. */
/* name is uppercase CURLFORM_<name> */
#ifdef CFINIT
#undef CFINIT
@@ -2179,6 +2443,47 @@ struct curl_slist {
};
/*
+ * NAME curl_global_sslset()
+ *
+ * DESCRIPTION
+ *
+ * When built with multiple SSL backends, curl_global_sslset() allows to
+ * choose one. This function can only be called once, and it must be called
+ * *before* curl_global_init().
+ *
+ * The backend can be identified by the id (e.g. CURLSSLBACKEND_OPENSSL). The
+ * backend can also be specified via the name parameter (passing -1 as id).
+ * If both id and name are specified, the name will be ignored. If neither id
+ * nor name are specified, the function will fail with
+ * CURLSSLSET_UNKNOWN_BACKEND and set the "avail" pointer to the
+ * NULL-terminated list of available backends.
+ *
+ * Upon success, the function returns CURLSSLSET_OK.
+ *
+ * If the specified SSL backend is not available, the function returns
+ * CURLSSLSET_UNKNOWN_BACKEND and sets the "avail" pointer to a NULL-terminated
+ * list of available SSL backends.
+ *
+ * The SSL backend can be set only once. If it has already been set, a
+ * subsequent attempt to change it will result in a CURLSSLSET_TOO_LATE.
+ */
+
+typedef struct {
+ curl_sslbackend id;
+ const char *name;
+} curl_ssl_backend;
+
+typedef enum {
+ CURLSSLSET_OK = 0,
+ CURLSSLSET_UNKNOWN_BACKEND,
+ CURLSSLSET_TOO_LATE,
+ CURLSSLSET_NO_BACKENDS /* libcurl was built without any SSL support */
+} CURLsslset;
+
+CURL_EXTERN CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
+ const curl_ssl_backend ***avail);
+
+/*
* NAME curl_slist_append()
*
* DESCRIPTION
@@ -2218,27 +2523,6 @@ struct curl_certinfo {
format "name: value" */
};
-/* enum for the different supported SSL backends */
-typedef enum {
- CURLSSLBACKEND_NONE = 0,
- CURLSSLBACKEND_OPENSSL = 1,
- CURLSSLBACKEND_GNUTLS = 2,
- CURLSSLBACKEND_NSS = 3,
- CURLSSLBACKEND_OBSOLETE4 = 4, /* Was QSOSSL. */
- CURLSSLBACKEND_GSKIT = 5,
- CURLSSLBACKEND_POLARSSL = 6,
- CURLSSLBACKEND_CYASSL = 7,
- CURLSSLBACKEND_SCHANNEL = 8,
- CURLSSLBACKEND_DARWINSSL = 9,
- CURLSSLBACKEND_AXTLS = 10,
- CURLSSLBACKEND_MBEDTLS = 11
-} curl_sslbackend;
-
-/* aliases for library clones and renames */
-#define CURLSSLBACKEND_LIBRESSL 1
-#define CURLSSLBACKEND_BORINGSSL 1
-#define CURLSSLBACKEND_WOLFSSL 6
-
/* Information about the SSL library used and the respective internal SSL
handle, which can be used to obtain further information regarding the
connection. Asked for with CURLINFO_TLS_SSL_PTR or CURLINFO_TLS_SESSION. */
@@ -2253,6 +2537,7 @@ struct curl_tlssessioninfo {
#define CURLINFO_SLIST 0x400000
#define CURLINFO_PTR 0x400000 /* same as SLIST */
#define CURLINFO_SOCKET 0x500000
+#define CURLINFO_OFF_T 0x600000
#define CURLINFO_MASK 0x0fffff
#define CURLINFO_TYPEMASK 0xf00000
@@ -2265,15 +2550,22 @@ typedef enum {
CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE + 5,
CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE + 6,
CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE + 7,
+ CURLINFO_SIZE_UPLOAD_T = CURLINFO_OFF_T + 7,
CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE + 8,
+ CURLINFO_SIZE_DOWNLOAD_T = CURLINFO_OFF_T + 8,
CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE + 9,
+ CURLINFO_SPEED_DOWNLOAD_T = CURLINFO_OFF_T + 9,
CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE + 10,
+ CURLINFO_SPEED_UPLOAD_T = CURLINFO_OFF_T + 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_FILETIME_T = CURLINFO_OFF_T + 14,
CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE + 15,
+ CURLINFO_CONTENT_LENGTH_DOWNLOAD_T = CURLINFO_OFF_T + 15,
CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE + 16,
+ CURLINFO_CONTENT_LENGTH_UPLOAD_T = CURLINFO_OFF_T + 16,
CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE + 17,
CURLINFO_CONTENT_TYPE = CURLINFO_STRING + 18,
CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE + 19,
@@ -2309,7 +2601,17 @@ typedef enum {
CURLINFO_SCHEME = CURLINFO_STRING + 49,
/* Fill in new entries below here! */
- CURLINFO_LASTONE = 49
+ /* Preferably these would be defined conditionally based on the
+ sizeof curl_off_t being 64-bits */
+ CURLINFO_TOTAL_TIME_T = CURLINFO_OFF_T + 50,
+ CURLINFO_NAMELOOKUP_TIME_T = CURLINFO_OFF_T + 51,
+ CURLINFO_CONNECT_TIME_T = CURLINFO_OFF_T + 52,
+ CURLINFO_PRETRANSFER_TIME_T = CURLINFO_OFF_T + 53,
+ CURLINFO_STARTTRANSFER_TIME_T = CURLINFO_OFF_T + 54,
+ CURLINFO_REDIRECT_TIME_T = CURLINFO_OFF_T + 55,
+ CURLINFO_APPCONNECT_TIME_T = CURLINFO_OFF_T + 56,
+
+ CURLINFO_LASTONE = 56
} CURLINFO;
/* CURLINFO_RESPONSE_CODE is the new name for the option previously known as
@@ -2328,7 +2630,7 @@ typedef enum {
CURLCLOSEPOLICY_LAST /* last, never use this */
} curl_closepolicy;
-#define CURL_GLOBAL_SSL (1<<0)
+#define CURL_GLOBAL_SSL (1<<0) /* no purpose since since 7.57.0 */
#define CURL_GLOBAL_WIN32 (1<<1)
#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32)
#define CURL_GLOBAL_NOTHING 0
@@ -2352,6 +2654,7 @@ typedef enum {
CURL_LOCK_DATA_DNS,
CURL_LOCK_DATA_SSL_SESSION,
CURL_LOCK_DATA_CONNECT,
+ CURL_LOCK_DATA_PSL,
CURL_LOCK_DATA_LAST
} curl_lock_data;
@@ -2406,6 +2709,7 @@ typedef enum {
CURLVERSION_SECOND,
CURLVERSION_THIRD,
CURLVERSION_FOURTH,
+ CURLVERSION_FIFTH,
CURLVERSION_LAST /* never actually use this */
} CURLversion;
@@ -2414,7 +2718,7 @@ typedef enum {
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
+#define CURLVERSION_NOW CURLVERSION_FIFTH
typedef struct {
CURLversion age; /* age of the returned struct */
@@ -2442,6 +2746,12 @@ typedef struct {
const char *libssh_version; /* human readable string */
+ /* These fields were added in CURLVERSION_FIFTH */
+
+ unsigned int brotli_ver_num; /* Numeric Brotli version
+ (MAJOR << 24) | (MINOR << 12) | PATCH */
+ const char *brotli_version; /* human readable string. */
+
} curl_version_info_data;
#define CURL_VERSION_IPV6 (1<<0) /* IPv6-enabled */
@@ -2471,6 +2781,9 @@ typedef struct {
#define CURL_VERSION_PSL (1<<20) /* Mozilla's Public Suffix List, used
for cookie domain verification */
#define CURL_VERSION_HTTPS_PROXY (1<<21) /* HTTPS-proxy support built-in */
+#define CURL_VERSION_MULTI_SSL (1<<22) /* Multiple SSL backends available */
+#define CURL_VERSION_BROTLI (1<<23) /* Brotli features are present. */
+#define CURL_VERSION_ALTSVC (1<<24) /* Alt-Svc handling built-in */
/*
* NAME curl_version_info()
@@ -2532,6 +2845,7 @@ CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask);
stuff before they can be included! */
#include "easy.h" /* nothing in curl is fun without the easy stuff */
#include "multi.h"
+#include "urlapi.h"
/* the typechecker doesn't work in C++ (yet) */
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \
diff --git a/Utilities/cmcurl/include/curl/curlver.h b/Utilities/cmcurl/include/curl/curlver.h
index 667b7eb13..04efb93ae 100644
--- a/Utilities/cmcurl/include/curl/curlver.h
+++ b/Utilities/cmcurl/include/curl/curlver.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -26,17 +26,17 @@
a script at release-time. This was made its own header file in 7.11.2 */
/* This is the global package copyright */
-#define LIBCURL_COPYRIGHT "1996 - 2017 Daniel Stenberg, <daniel@haxx.se>."
+#define LIBCURL_COPYRIGHT "1996 - 2019 Daniel Stenberg, <daniel@haxx.se>."
/* This is the version number of the libcurl package from which this header
file origins: */
-#define LIBCURL_VERSION "7.54.1"
+#define LIBCURL_VERSION "7.65.0"
/* The numeric version number is also available "in parts" by using these
defines: */
#define LIBCURL_VERSION_MAJOR 7
-#define LIBCURL_VERSION_MINOR 54
-#define LIBCURL_VERSION_PATCH 1
+#define LIBCURL_VERSION_MINOR 65
+#define LIBCURL_VERSION_PATCH 0
/* This is the numeric version of the libcurl version number, meant for easier
parsing and comparions by programs. The LIBCURL_VERSION_NUM define will
@@ -57,7 +57,7 @@
CURL_VERSION_BITS() macro since curl's own configure script greps for it
and needs it to contain the full number.
*/
-#define LIBCURL_VERSION_NUM 0x073601
+#define LIBCURL_VERSION_NUM 0x074100
/*
* This is the date and time when the full source package was created. The
@@ -70,7 +70,7 @@
*/
#define LIBCURL_TIMESTAMP "[unreleased]"
-#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|z)
+#define CURL_VERSION_BITS(x,y,z) ((x)<<16|(y)<<8|(z))
#define CURL_AT_LEAST_VERSION(x,y,z) \
(LIBCURL_VERSION_NUM >= CURL_VERSION_BITS(x, y, z))
diff --git a/Utilities/cmcurl/include/curl/easy.h b/Utilities/cmcurl/include/curl/easy.h
index 752c5049f..f42a8a969 100644
--- a/Utilities/cmcurl/include/curl/easy.h
+++ b/Utilities/cmcurl/include/curl/easy.h
@@ -95,6 +95,16 @@ CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen,
CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer,
size_t buflen, size_t *n);
+
+/*
+ * NAME curl_easy_upkeep()
+ *
+ * DESCRIPTION
+ *
+ * Performs connection upkeep for the given session handle.
+ */
+CURL_EXTERN CURLcode curl_easy_upkeep(CURL *curl);
+
#ifdef __cplusplus
}
#endif
diff --git a/Utilities/cmcurl/include/curl/multi.h b/Utilities/cmcurl/include/curl/multi.h
index f93e511be..b19dbaf79 100644
--- a/Utilities/cmcurl/include/curl/multi.h
+++ b/Utilities/cmcurl/include/curl/multi.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -70,6 +70,8 @@ typedef enum {
CURLM_UNKNOWN_OPTION, /* curl_multi_setopt() with unsupported option */
CURLM_ADDED_ALREADY, /* an easy handle already added to a multi handle was
attempted to get added - again */
+ CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a
+ callback */
CURLM_LAST
} CURLMcode;
@@ -184,8 +186,8 @@ CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
*
* 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.
+ * still have occurred problems on individual transfers even when
+ * this returns OK.
*/
CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
int *running_handles);
diff --git a/Utilities/cmcurl/include/curl/system.h b/Utilities/cmcurl/include/curl/system.h
index ed3a55c95..1e555ec19 100644
--- a/Utilities/cmcurl/include/curl/system.h
+++ b/Utilities/cmcurl/include/curl/system.h
@@ -23,14 +23,6 @@
***************************************************************************/
/*
- * This header is supposed to eventually replace curlbuild.h. This little one
- * is still learning. During the experimental phase, this header files
- * defines symbols using the prefixes CURLSYS_ or curlsys_. When we feel
- * confident enough, we replace curlbuild.h with this file and rename all
- * prefixes to CURL_ and curl_.
- */
-
-/*
* Try to keep one section per platform, compiler and architecture, otherwise,
* if an existing section is reused for a different one and later on the
* original is adjusted, probably the piggybacking one can be adversely
@@ -60,323 +52,291 @@
#if defined(__DJGPP__) || defined(__GO32__)
# if defined(__DJGPP__) && (__DJGPP__ > 1)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# else
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__SALFORDC__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__BORLANDC__)
# if (__BORLANDC__ < 0x520)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# else
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T __int64
-# define CURLSYS_FORMAT_CURL_OFF_T "I64d"
-# define CURLSYS_FORMAT_CURL_OFF_TU "I64u"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T i64
-# define CURLSYS_SUFFIX_CURL_OFF_TU ui64
+# define CURL_TYPEOF_CURL_OFF_T __int64
+# define CURL_FORMAT_CURL_OFF_T "I64d"
+# define CURL_FORMAT_CURL_OFF_TU "I64u"
+# define CURL_SUFFIX_CURL_OFF_T i64
+# define CURL_SUFFIX_CURL_OFF_TU ui64
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__TURBOC__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__WATCOMC__)
# if defined(__386__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T __int64
-# define CURLSYS_FORMAT_CURL_OFF_T "I64d"
-# define CURLSYS_FORMAT_CURL_OFF_TU "I64u"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T i64
-# define CURLSYS_SUFFIX_CURL_OFF_TU ui64
+# define CURL_TYPEOF_CURL_OFF_T __int64
+# define CURL_FORMAT_CURL_OFF_T "I64d"
+# define CURL_FORMAT_CURL_OFF_TU "I64u"
+# define CURL_SUFFIX_CURL_OFF_T i64
+# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__POCC__)
# if (__POCC__ < 280)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# elif defined(_MSC_VER)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T __int64
-# define CURLSYS_FORMAT_CURL_OFF_T "I64d"
-# define CURLSYS_FORMAT_CURL_OFF_TU "I64u"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T i64
-# define CURLSYS_SUFFIX_CURL_OFF_TU ui64
+# define CURL_TYPEOF_CURL_OFF_T __int64
+# define CURL_FORMAT_CURL_OFF_T "I64d"
+# define CURL_FORMAT_CURL_OFF_TU "I64u"
+# define CURL_SUFFIX_CURL_OFF_T i64
+# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__LCC__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__SYMBIAN32__)
# if defined(__EABI__) /* Treat all ARM compilers equally */
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__CW32__)
# pragma longlong on
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__VC32__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T __int64
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T __int64
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T unsigned int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
#elif defined(__MWERKS__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(_WIN32_WCE)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T __int64
-# define CURLSYS_FORMAT_CURL_OFF_T "I64d"
-# define CURLSYS_FORMAT_CURL_OFF_TU "I64u"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T i64
-# define CURLSYS_SUFFIX_CURL_OFF_TU ui64
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_OFF_T __int64
+# define CURL_FORMAT_CURL_OFF_T "I64d"
+# define CURL_FORMAT_CURL_OFF_TU "I64u"
+# define CURL_SUFFIX_CURL_OFF_T i64
+# define CURL_SUFFIX_CURL_OFF_TU ui64
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__MINGW32__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "I64d"
-# define CURLSYS_FORMAT_CURL_OFF_TU "I64u"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
-# define CURLSYS_PULL_SYS_TYPES_H 1
-# define CURLSYS_PULL_WS2TCPIP_H 1
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "I64d"
+# define CURL_FORMAT_CURL_OFF_TU "I64u"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_WS2TCPIP_H 1
#elif defined(__VMS)
# if defined(__VAX)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# else
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T unsigned int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_SOCKLEN_T unsigned int
#elif defined(__OS400__)
# if defined(__ILEC400__)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
-# define CURLSYS_PULL_SYS_TYPES_H 1
-# define CURLSYS_PULL_SYS_SOCKET_H 1
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_SYS_SOCKET_H 1
# endif
#elif defined(__MVS__)
# if defined(__IBMC__) || defined(__IBMCPP__)
# if defined(_ILP32)
-# define CURLSYS_SIZEOF_LONG 4
# elif defined(_LP64)
-# define CURLSYS_SIZEOF_LONG 8
# endif
# if defined(_LONG_LONG)
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(_LP64)
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# else
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
-# define CURLSYS_PULL_SYS_TYPES_H 1
-# define CURLSYS_PULL_SYS_SOCKET_H 1
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_SYS_SOCKET_H 1
# endif
#elif defined(__370__)
# if defined(__IBMC__) || defined(__IBMCPP__)
# if defined(_ILP32)
-# define CURLSYS_SIZEOF_LONG 4
# elif defined(_LP64)
-# define CURLSYS_SIZEOF_LONG 8
# endif
# if defined(_LONG_LONG)
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(_LP64)
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# else
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
-# define CURLSYS_PULL_SYS_TYPES_H 1
-# define CURLSYS_PULL_SYS_SOCKET_H 1
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_SYS_SOCKET_H 1
# endif
#elif defined(TPF)
-# define CURLSYS_SIZEOF_LONG 8
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
#elif defined(__TINYC__) /* also known as tcc */
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t
-# define CURLSYS_PULL_SYS_TYPES_H 1
-# define CURLSYS_PULL_SYS_SOCKET_H 1
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_SYS_SOCKET_H 1
+
+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Oracle Solaris Studio */
+# if !defined(__LP64) && (defined(__ILP32) || \
+ defined(__i386) || \
+ defined(__sparcv8) || \
+ defined(__sparcv8plus))
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
+# elif defined(__LP64) || \
+ defined(__amd64) || defined(__sparcv9)
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
+# endif
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_SYS_SOCKET_H 1
+
+#elif defined(__xlc__) /* IBM xlc compiler */
+# if !defined(_LP64)
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
+# else
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
+# endif
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_SYS_SOCKET_H 1
/* ===================================== */
/* KEEP MSVC THE PENULTIMATE ENTRY */
@@ -384,101 +344,150 @@
#elif defined(_MSC_VER)
# if (_MSC_VER >= 900) && (_INTEGRAL_MAX_BITS >= 64)
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T __int64
-# define CURLSYS_FORMAT_CURL_OFF_T "I64d"
-# define CURLSYS_FORMAT_CURL_OFF_TU "I64u"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T i64
-# define CURLSYS_SUFFIX_CURL_OFF_TU ui64
+# define CURL_TYPEOF_CURL_OFF_T __int64
+# define CURL_FORMAT_CURL_OFF_T "I64d"
+# define CURL_FORMAT_CURL_OFF_TU "I64u"
+# define CURL_SUFFIX_CURL_OFF_T i64
+# define CURL_SUFFIX_CURL_OFF_TU ui64
# else
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
/* ===================================== */
/* KEEP GENERIC GCC THE LAST ENTRY */
/* ===================================== */
-#elif defined(__GNUC__)
-# if !defined(__LP64__) && (defined(__ILP32__) || \
- defined(__i386__) || defined(__ppc__) || defined(__arm__) || \
- defined(__sparc__) || defined(__mips__) || defined(__sh__))
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long long
-# define CURLSYS_FORMAT_CURL_OFF_T "lld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "llu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T LL
-# define CURLSYS_SUFFIX_CURL_OFF_TU ULL
+#elif defined(__GNUC__) && !defined(_SCO_DS)
+# if !defined(__LP64__) && \
+ (defined(__ILP32__) || defined(__i386__) || defined(__hppa__) || \
+ defined(__ppc__) || defined(__powerpc__) || defined(__arm__) || \
+ defined(__sparc__) || defined(__mips__) || defined(__sh__) || \
+ defined(__XTENSA__) || \
+ (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 4) || \
+ (defined(__LONG_MAX__) && __LONG_MAX__ == 2147483647L))
+# define CURL_TYPEOF_CURL_OFF_T long long
+# define CURL_FORMAT_CURL_OFF_T "lld"
+# define CURL_FORMAT_CURL_OFF_TU "llu"
+# define CURL_SUFFIX_CURL_OFF_T LL
+# define CURL_SUFFIX_CURL_OFF_TU ULL
# elif defined(__LP64__) || \
- defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__)
-# define CURLSYS_SIZEOF_LONG 8
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SIZEOF_CURL_OFF_T 8
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
+ defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__) || \
+ (defined(__SIZEOF_LONG__) && __SIZEOF_LONG__ == 8) || \
+ (defined(__LONG_MAX__) && __LONG_MAX__ == 9223372036854775807L)
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
# endif
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T socklen_t
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
-# define CURLSYS_PULL_SYS_TYPES_H 1
-# define CURLSYS_PULL_SYS_SOCKET_H 1
+# define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
+# define CURL_PULL_SYS_TYPES_H 1
+# define CURL_PULL_SYS_SOCKET_H 1
#else
/* generic "safe guess" on old 32 bit style */
-# define CURLSYS_SIZEOF_LONG 4
-# define CURLSYS_SIZEOF_CURL_SOCKLEN_T 4
-# define CURLSYS_SIZEOF_CURL_OFF_T 4
-# define CURLSYS_TYPEOF_CURL_OFF_T long
-# define CURLSYS_FORMAT_CURL_OFF_T "ld"
-# define CURLSYS_FORMAT_CURL_OFF_TU "lu"
-# define CURLSYS_SUFFIX_CURL_OFF_T L
-# define CURLSYS_SUFFIX_CURL_OFF_TU UL
-# define CURLSYS_TYPEOF_CURL_SOCKLEN_T int
+# define CURL_TYPEOF_CURL_OFF_T long
+# define CURL_FORMAT_CURL_OFF_T "ld"
+# define CURL_FORMAT_CURL_OFF_TU "lu"
+# define CURL_SUFFIX_CURL_OFF_T L
+# define CURL_SUFFIX_CURL_OFF_TU UL
+# define CURL_TYPEOF_CURL_SOCKLEN_T int
+#endif
+
+#ifdef _AIX
+/* AIX needs <sys/poll.h> */
+#define CURL_PULL_SYS_POLL_H
#endif
-/* CURLSYS_PULL_WS2TCPIP_H is defined above when inclusion of header file */
+
+/* CURL_PULL_WS2TCPIP_H is defined above when inclusion of header file */
/* ws2tcpip.h is required here to properly make type definitions below. */
-#ifdef CURLSYS_PULL_WS2TCPIP_H
-# ifndef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-# endif
-# include <windows.h>
+#ifdef CURL_PULL_WS2TCPIP_H
# include <winsock2.h>
+# include <windows.h>
# include <ws2tcpip.h>
#endif
-/* CURLSYS_PULL_SYS_TYPES_H is defined above when inclusion of header file */
+/* CURL_PULL_SYS_TYPES_H is defined above when inclusion of header file */
/* sys/types.h is required here to properly make type definitions below. */
-#ifdef CURLSYS_PULL_SYS_TYPES_H
+#ifdef CURL_PULL_SYS_TYPES_H
# include <sys/types.h>
#endif
-/* CURLSYS_PULL_SYS_SOCKET_H is defined above when inclusion of header file */
+/* CURL_PULL_SYS_SOCKET_H is defined above when inclusion of header file */
/* sys/socket.h is required here to properly make type definitions below. */
-#ifdef CURLSYS_PULL_SYS_SOCKET_H
+#ifdef CURL_PULL_SYS_SOCKET_H
# include <sys/socket.h>
#endif
+/* CURL_PULL_SYS_POLL_H is defined above when inclusion of header file */
+/* sys/poll.h is required here to properly make type definitions below. */
+#ifdef CURL_PULL_SYS_POLL_H
+# include <sys/poll.h>
+#endif
+
/* Data type definition of curl_socklen_t. */
-#ifdef CURLSYS_TYPEOF_CURL_SOCKLEN_T
- typedef CURLSYS_TYPEOF_CURL_SOCKLEN_T curlsys_socklen_t;
+#ifdef CURL_TYPEOF_CURL_SOCKLEN_T
+ typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
#endif
/* Data type definition of curl_off_t. */
-#ifdef CURLSYS_TYPEOF_CURL_OFF_T
- typedef CURLSYS_TYPEOF_CURL_OFF_T curlsys_off_t;
+#ifdef CURL_TYPEOF_CURL_OFF_T
+ typedef CURL_TYPEOF_CURL_OFF_T curl_off_t;
#endif
-#endif /* __CURL_SYSTEM_H */
+/*
+ * CURL_ISOCPP and CURL_OFF_T_C definitions are done here in order to allow
+ * these to be visible and exported by the external libcurl interface API,
+ * while also making them visible to the library internals, simply including
+ * curl_setup.h, without actually needing to include curl.h internally.
+ * If some day this section would grow big enough, all this should be moved
+ * to its own header file.
+ */
+
+/*
+ * Figure out if we can use the ## preprocessor 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.
+ */
+
+#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus) || \
+ defined(__HP_aCC) || defined(__BORLANDC__) || defined(__LCC__) || \
+ defined(__POCC__) || defined(__SALFORDC__) || defined(__HIGHC__) || \
+ defined(__ILEC400__)
+ /* 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
+
+/*
+ * Macros for minimum-width signed and unsigned curl_off_t integer constants.
+ */
+
+#if defined(__BORLANDC__) && (__BORLANDC__ == 0x0551)
+# define __CURL_OFF_T_C_HLPR2(x) x
+# define __CURL_OFF_T_C_HLPR1(x) __CURL_OFF_T_C_HLPR2(x)
+# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \
+ __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_T)
+# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val) ## \
+ __CURL_OFF_T_C_HLPR1(CURL_SUFFIX_CURL_OFF_TU)
+#else
+# ifdef CURL_ISOCPP
+# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val ## Suffix
+# else
+# define __CURL_OFF_T_C_HLPR2(Val,Suffix) Val/**/Suffix
+# endif
+# define __CURL_OFF_T_C_HLPR1(Val,Suffix) __CURL_OFF_T_C_HLPR2(Val,Suffix)
+# define CURL_OFF_T_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_T)
+# define CURL_OFF_TU_C(Val) __CURL_OFF_T_C_HLPR1(Val,CURL_SUFFIX_CURL_OFF_TU)
+#endif
+#endif /* __CURL_SYSTEM_H */
diff --git a/Utilities/cmcurl/include/curl/typecheck-gcc.h b/Utilities/cmcurl/include/curl/typecheck-gcc.h
index 10b5de2ab..2d1de4d43 100644
--- a/Utilities/cmcurl/include/curl/typecheck-gcc.h
+++ b/Utilities/cmcurl/include/curl/typecheck-gcc.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -54,6 +54,9 @@ __extension__ ({ \
if(_curl_is_write_cb_option(_curl_opt)) \
if(!_curl_is_write_cb(value)) \
_curl_easy_setopt_err_write_callback(); \
+ if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION) \
+ if(!_curl_is_resolver_start_callback(value)) \
+ _curl_easy_setopt_err_resolver_start_callback(); \
if((_curl_opt) == CURLOPT_READFUNCTION) \
if(!_curl_is_read_cb(value)) \
_curl_easy_setopt_err_read_cb(); \
@@ -96,6 +99,9 @@ __extension__ ({ \
if((_curl_opt) == CURLOPT_HTTPPOST) \
if(!_curl_is_arr((value), struct curl_httppost)) \
_curl_easy_setopt_err_curl_httpost(); \
+ if((_curl_opt) == CURLOPT_MIMEPOST) \
+ if(!_curl_is_ptr((value), curl_mime)) \
+ _curl_easy_setopt_err_curl_mimepost(); \
if(_curl_is_slist_option(_curl_opt)) \
if(!_curl_is_arr((value), struct curl_slist)) \
_curl_easy_setopt_err_curl_slist(); \
@@ -107,10 +113,9 @@ __extension__ ({ \
})
/* wraps curl_easy_getinfo() with typechecking */
-/* FIXME: don't allow const pointers */
#define curl_easy_getinfo(handle, info, arg) \
__extension__ ({ \
- __typeof__(info) _curl_info = info; \
+ __typeof__(info) _curl_info = info; \
if(__builtin_constant_p(_curl_info)) { \
if(_curl_is_string_info(_curl_info)) \
if(!_curl_is_arr((arg), char *)) \
@@ -130,16 +135,18 @@ __extension__ ({ \
if(_curl_is_certinfo_info(_curl_info)) \
if(!_curl_is_arr((arg), struct curl_certinfo *)) \
_curl_easy_getinfo_err_curl_certinfo(); \
- if(_curl_is_socket_info(_curl_info)) \
+ if(_curl_is_socket_info(_curl_info)) \
if(!_curl_is_arr((arg), curl_socket_t)) \
_curl_easy_getinfo_err_curl_socket(); \
+ if(_curl_is_off_t_info(_curl_info)) \
+ if(!_curl_is_arr((arg), curl_off_t)) \
+ _curl_easy_getinfo_err_curl_off_t(); \
} \
curl_easy_getinfo(handle, _curl_info, arg); \
})
-/* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(),
- * for now just make sure that the functions are called with three
- * arguments
+/*
+ * For now, just make sure that the functions are called with three arguments
*/
#define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
#define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)
@@ -164,6 +171,10 @@ _CURL_WARNING(_curl_easy_setopt_err_string,
)
_CURL_WARNING(_curl_easy_setopt_err_write_callback,
"curl_easy_setopt expects a curl_write_callback argument for this option")
+_CURL_WARNING(_curl_easy_setopt_err_resolver_start_callback,
+ "curl_easy_setopt expects a "
+ "curl_resolver_start_callback argument for this option"
+ )
_CURL_WARNING(_curl_easy_setopt_err_read_cb,
"curl_easy_setopt expects a curl_read_callback argument for this option")
_CURL_WARNING(_curl_easy_setopt_err_ioctl_cb,
@@ -197,6 +208,9 @@ _CURL_WARNING(_curl_easy_setopt_err_postfields,
_CURL_WARNING(_curl_easy_setopt_err_curl_httpost,
"curl_easy_setopt expects a 'struct curl_httppost *' "
"argument for this option")
+_CURL_WARNING(_curl_easy_setopt_err_curl_mimepost,
+ "curl_easy_setopt expects a 'curl_mime *' "
+ "argument for this option")
_CURL_WARNING(_curl_easy_setopt_err_curl_slist,
"curl_easy_setopt expects a 'struct curl_slist *' argument for this option")
_CURL_WARNING(_curl_easy_setopt_err_CURLSH,
@@ -218,6 +232,8 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_certinfo,
"'struct curl_certinfo *' for this info")
_CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
"curl_easy_getinfo expects a pointer to curl_socket_t for this info")
+_CURL_WARNING(_curl_easy_getinfo_err_curl_off_t,
+ "curl_easy_getinfo expects a pointer to curl_off_t for this info")
/* groups of curl_easy_setops options that take the same type of argument */
@@ -238,6 +254,7 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
#define _curl_is_string_option(option) \
((option) == CURLOPT_ABSTRACT_UNIX_SOCKET || \
(option) == CURLOPT_ACCEPT_ENCODING || \
+ (option) == CURLOPT_ALTSVC || \
(option) == CURLOPT_CAINFO || \
(option) == CURLOPT_CAPATH || \
(option) == CURLOPT_COOKIE || \
@@ -251,6 +268,7 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
(option) == CURLOPT_DNS_LOCAL_IP4 || \
(option) == CURLOPT_DNS_LOCAL_IP6 || \
(option) == CURLOPT_DNS_SERVERS || \
+ (option) == CURLOPT_DOH_URL || \
(option) == CURLOPT_EGDSOCKET || \
(option) == CURLOPT_FTPPORT || \
(option) == CURLOPT_FTP_ACCOUNT || \
@@ -343,6 +361,8 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
(option) == CURLOPT_SSH_KEYDATA || \
(option) == CURLOPT_SSL_CTX_DATA || \
(option) == CURLOPT_WRITEDATA || \
+ (option) == CURLOPT_RESOLVER_START_DATA || \
+ (option) == CURLOPT_CURLU || \
0)
/* evaluates to true if option takes a POST data argument (void* or char*) */
@@ -391,7 +411,11 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
/* true if info expects a pointer to struct curl_socket_t argument */
#define _curl_is_socket_info(info) \
- (CURLINFO_SOCKET < (info))
+ (CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T)
+
+/* true if info expects a pointer to curl_off_t argument */
+#define _curl_is_off_t_info(info) \
+ (CURLINFO_OFF_T < (info))
/* typecheck helpers -- check whether given expression has requested type*/
@@ -405,7 +429,7 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
* == or whatsoever.
*/
-/* XXX: should evaluate to true iff expr is a pointer */
+/* XXX: should evaluate to true if expr is a pointer */
#define _curl_is_any_ptr(expr) \
(sizeof(expr) == sizeof(void *))
@@ -477,18 +501,20 @@ _CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
/* evaluates to true if expr can be passed as POST data (void* or char*) */
#define _curl_is_postfields(expr) \
(_curl_is_ptr((expr), void) || \
- _curl_is_arr((expr), char))
+ _curl_is_arr((expr), char) || \
+ _curl_is_arr((expr), unsigned char))
-/* FIXME: the whole callback checking is messy...
- * The idea is to tolerate char vs. void and const vs. not const
- * pointers in arguments at least
- */
/* helper: __builtin_types_compatible_p distinguishes between functions and
* function pointers, hide it */
#define _curl_callback_compatible(func, type) \
(__builtin_types_compatible_p(__typeof__(func), type) || \
__builtin_types_compatible_p(__typeof__(func) *, type))
+/* evaluates to true if expr is of type curl_resolver_start_callback */
+#define _curl_is_resolver_start_callback(expr) \
+ (_curl_is_NULL(expr) || \
+ _curl_callback_compatible((expr), curl_resolver_start_callback))
+
/* evaluates to true if expr is of type curl_read_callback or "similar" */
#define _curl_is_read_cb(expr) \
(_curl_is_NULL(expr) || \
diff --git a/Utilities/cmcurl/lib/CMakeLists.txt b/Utilities/cmcurl/lib/CMakeLists.txt
index 76dd6c63c..2a6279c29 100644
--- a/Utilities/cmcurl/lib/CMakeLists.txt
+++ b/Utilities/cmcurl/lib/CMakeLists.txt
@@ -1,7 +1,13 @@
set(LIB_NAME cmcurl)
-configure_file(${CURL_SOURCE_DIR}/include/curl/curlbuild.h.cmake
- ${CURL_BINARY_DIR}/include/curl/curlbuild.h)
+if(BUILD_SHARED_LIBS)
+ set(CURL_STATICLIB NO)
+else()
+ set(CURL_STATICLIB YES)
+endif()
+
+# Use:
+# * CURL_STATICLIB
configure_file(curl_config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
@@ -10,11 +16,11 @@ include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
list(APPEND HHEADERS
${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
- ${CURL_BINARY_DIR}/include/curl/curlbuild.h
)
if(MSVC AND NOT CURL_STATICLIB)
list(APPEND CSOURCES libcurl.rc)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127")
endif()
# SET(CSOURCES
@@ -61,14 +67,6 @@ if(USE_ARES)
include_directories(${CARES_INCLUDE_DIR})
endif()
-if(CURL_STATICLIB)
- # Static lib
- set(CURL_USER_DEFINED_DYNAMIC_OR_STATIC STATIC)
-else()
- # DLL / so dynamic lib
- set(CURL_USER_DEFINED_DYNAMIC_OR_STATIC SHARED)
-endif()
-
# For windows we want to install OPENSSL_LIBRARIES dlls
# and also copy them into the build tree so that testing
# can find them.
@@ -95,16 +93,19 @@ endif()
add_library(
${LIB_NAME}
- ${CURL_USER_DEFINED_DYNAMIC_OR_STATIC}
${HHEADERS} ${CSOURCES}
${CMAKE_CURL_SSL_DLLS}
)
+if(NOT BUILD_SHARED_LIBS)
+ set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
+endif()
+
target_link_libraries(${LIB_NAME} ${CURL_LIBS})
if(0) # This code not needed for building within CMake.
if(WIN32)
- add_definitions( -D_USRDLL )
+ add_definitions(-D_USRDLL)
endif()
endif()
@@ -121,14 +122,26 @@ set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
if(WIN32)
- if(NOT CURL_STATICLIB)
+ if(BUILD_SHARED_LIBS)
# Add "_imp" as a suffix before the extension to avoid conflicting with the statically linked "libcurl.lib"
set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
endif()
endif()
+target_include_directories(${LIB_NAME} INTERFACE
+ $<INSTALL_INTERFACE:include>
+ $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
+
install(TARGETS ${LIB_NAME}
- ARCHIVE DESTINATION lib
- LIBRARY DESTINATION lib
- RUNTIME DESTINATION bin)
+ EXPORT ${TARGETS_EXPORT_NAME}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
+
+export(TARGETS ${LIB_NAME}
+ APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
+ NAMESPACE CURL::
+)
+
endif()
diff --git a/Utilities/cmcurl/lib/Makefile.inc b/Utilities/cmcurl/lib/Makefile.inc
index 19f58000a..235b82b0e 100644
--- a/Utilities/cmcurl/lib/Makefile.inc
+++ b/Utilities/cmcurl/lib/Makefile.inc
@@ -5,7 +5,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2019, 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
@@ -28,14 +28,14 @@ LIB_VAUTH_CFILES = vauth/vauth.c vauth/cleartext.c vauth/cram.c \
LIB_VAUTH_HFILES = vauth/vauth.h vauth/digest.h vauth/ntlm.h
LIB_VTLS_CFILES = vtls/openssl.c vtls/gtls.c vtls/vtls.c vtls/nss.c \
- vtls/polarssl.c vtls/polarssl_threadlock.c vtls/axtls.c \
- vtls/cyassl.c vtls/schannel.c vtls/darwinssl.c vtls/gskit.c \
- vtls/mbedtls.c
+ vtls/polarssl.c vtls/polarssl_threadlock.c \
+ vtls/cyassl.c vtls/schannel.c vtls/schannel_verify.c \
+ vtls/sectransp.c vtls/gskit.c vtls/mbedtls.c vtls/mesalink.c
LIB_VTLS_HFILES = vtls/openssl.h vtls/vtls.h vtls/gtls.h \
- vtls/nssg.h vtls/polarssl.h vtls/polarssl_threadlock.h vtls/axtls.h \
- vtls/cyassl.h vtls/schannel.h vtls/darwinssl.h vtls/gskit.h \
- vtls/mbedtls.h
+ vtls/nssg.h vtls/polarssl.h vtls/polarssl_threadlock.h \
+ vtls/cyassl.h vtls/schannel.h vtls/sectransp.h vtls/gskit.h \
+ vtls/mbedtls.h vtls/mesalink.h
LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
cookie.c http.c sendf.c ftp.c url.c dict.c if2ip.c speedcheck.c \
@@ -46,14 +46,16 @@ LIB_CFILES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
http_digest.c md4.c md5.c http_negotiate.c inet_pton.c strtoofft.c \
strerror.c amigaos.c hostasyn.c hostip4.c hostip6.c hostsyn.c \
inet_ntop.c parsedate.c select.c tftp.c splay.c strdup.c socks.c \
- ssh.c curl_addrinfo.c socks_gssapi.c socks_sspi.c \
+ ssh.c ssh-libssh.c curl_addrinfo.c socks_gssapi.c socks_sspi.c \
curl_sspi.c slist.c nonblock.c curl_memrchr.c imap.c pop3.c smtp.c \
pingpong.c rtsp.c curl_threads.c warnless.c hmac.c curl_rtmp.c \
openldap.c curl_gethostname.c gopher.c idn_win32.c \
http_proxy.c non-ascii.c asyn-ares.c asyn-thread.c curl_gssapi.c \
http_ntlm.c curl_ntlm_wb.c curl_ntlm_core.c curl_sasl.c rand.c \
- curl_multibyte.c hostcheck.c conncache.c pipeline.c dotdot.c \
- x509asn1.c http2.c smb.c curl_endian.c curl_des.c system_win32.c
+ curl_multibyte.c hostcheck.c conncache.c dotdot.c \
+ x509asn1.c http2.c smb.c curl_endian.c curl_des.c system_win32.c \
+ mime.c sha256.c setopt.c curl_path.c curl_ctype.c curl_range.c psl.c \
+ doh.c urlapi.c curl_get_line.c altsvc.c
LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h if2ip.h \
@@ -70,9 +72,11 @@ LIB_HFILES = arpa_telnet.h netrc.h file.h timeval.h hostip.h progress.h \
curl_gethostname.h gopher.h http_proxy.h non-ascii.h asyn.h \
http_ntlm.h curl_gssapi.h curl_ntlm_wb.h curl_ntlm_core.h \
curl_sasl.h curl_multibyte.h hostcheck.h conncache.h \
- curl_setup_once.h multihandle.h setup-vms.h pipeline.h dotdot.h \
+ curl_setup_once.h multihandle.h setup-vms.h dotdot.h \
x509asn1.h http2.h sigpipe.h smb.h curl_endian.h curl_des.h \
- curl_printf.h system_win32.h rand.h
+ curl_printf.h system_win32.h rand.h mime.h curl_sha256.h setopt.h \
+ curl_path.h curl_ctype.h curl_range.h psl.h doh.h urlapi-int.h \
+ curl_get_line.h altsvc.h
LIB_RCFILES = libcurl.rc
diff --git a/Utilities/cmcurl/lib/amigaos.c b/Utilities/cmcurl/lib/amigaos.c
index 4f55b30e7..cf44bdc8d 100644
--- a/Utilities/cmcurl/lib/amigaos.c
+++ b/Utilities/cmcurl/lib/amigaos.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,17 +22,26 @@
#include "curl_setup.h"
-#if defined(__AMIGA__) && !defined(__ixemul__)
-
-#include <amitcp/socketbasetags.h>
+#ifdef __AMIGA__
+# include "amigaos.h"
+# if defined(HAVE_PROTO_BSDSOCKET_H) && !defined(USE_AMISSL)
+# include <amitcp/socketbasetags.h>
+# endif
+# ifdef __libnix__
+# include <stabs.h>
+# endif
+#endif
-#include "amigaos.h"
+/* The last #include files should be: */
+#include "curl_memory.h"
+#include "memdebug.h"
+#ifdef __AMIGA__
+#if defined(HAVE_PROTO_BSDSOCKET_H) && !defined(USE_AMISSL)
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")
@@ -74,4 +83,13 @@ bool Curl_amiga_init()
ADD2EXIT(Curl_amiga_cleanup, -50);
#endif
-#endif /* __AMIGA__ && ! __ixemul__ */
+#endif /* HAVE_PROTO_BSDSOCKET_H */
+
+#ifdef USE_AMISSL
+void Curl_amiga_X509_free(X509 *a)
+{
+ X509_free(a);
+}
+#endif /* USE_AMISSL */
+#endif /* __AMIGA__ */
+
diff --git a/Utilities/cmcurl/lib/amigaos.h b/Utilities/cmcurl/lib/amigaos.h
index 02bee1610..c776c9c9b 100644
--- a/Utilities/cmcurl/lib/amigaos.h
+++ b/Utilities/cmcurl/lib/amigaos.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -23,7 +23,7 @@
***************************************************************************/
#include "curl_setup.h"
-#if defined(__AMIGA__) && !defined(__ixemul__)
+#if defined(__AMIGA__) && defined(HAVE_BSDSOCKET_H) && !defined(USE_AMISSL)
bool Curl_amiga_init();
void Curl_amiga_cleanup();
@@ -35,5 +35,10 @@ void Curl_amiga_cleanup();
#endif
+#ifdef USE_AMISSL
+#include <openssl/x509v3.h>
+void Curl_amiga_X509_free(X509 *a);
+#endif /* USE_AMISSL */
+
#endif /* HEADER_CURL_AMIGAOS_H */
diff --git a/Utilities/cmcurl/lib/arpa_telnet.h b/Utilities/cmcurl/lib/arpa_telnet.h
index ec238729d..232680e7d 100644
--- a/Utilities/cmcurl/lib/arpa_telnet.h
+++ b/Utilities/cmcurl/lib/arpa_telnet.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -37,6 +37,7 @@
#define CURL_NEW_ENV_VAR 0
#define CURL_NEW_ENV_VALUE 1
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
/*
* The telnet options represented as strings
*/
@@ -53,6 +54,7 @@ static const char * const telnetoptions[]=
"TERM SPEED", "LFLOW", "LINEMODE", "XDISPLOC",
"OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON"
};
+#endif
#define CURL_TELOPT_MAXIMUM CURL_TELOPT_NEW_ENVIRON
@@ -76,6 +78,7 @@ static const char * const telnetoptions[]=
#define CURL_DONT 254 /* DON'T use this option! */
#define CURL_IAC 255 /* Interpret As Command */
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
/*
* Then those numbers represented as strings:
*/
@@ -86,6 +89,7 @@ static const char * const telnetcmds[]=
"AYT", "EC", "EL", "GA", "SB",
"WILL", "WONT", "DO", "DONT", "IAC"
};
+#endif
#define CURL_TELCMD_MINIMUM CURL_xEOF /* the first one */
#define CURL_TELCMD_MAXIMUM CURL_IAC /* surprise, 255 is the last one! ;-) */
diff --git a/Utilities/cmcurl/lib/asyn-ares.c b/Utilities/cmcurl/lib/asyn-ares.c
index 11a914f82..8561a4724 100644
--- a/Utilities/cmcurl/lib/asyn-ares.c
+++ b/Utilities/cmcurl/lib/asyn-ares.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,9 +22,15 @@
#include "curl_setup.h"
-#ifdef HAVE_LIMITS_H
+/***********************************************************************
+ * Only for ares-enabled builds
+ * And only for functions that fulfill the asynch resolver backend API
+ * as defined in asyn.h, nothing else belongs in this file!
+ **********************************************************************/
+
+#ifdef CURLRES_ARES
+
#include <limits.h>
-#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -48,14 +54,6 @@
#define in_addr_t unsigned long
#endif
-/***********************************************************************
- * Only for ares-enabled builds
- * And only for functions that fulfill the asynch resolver backend API
- * as defined in asyn.h, nothing else belongs in this file!
- **********************************************************************/
-
-#ifdef CURLRES_ARES
-
#include "urldata.h"
#include "sendf.h"
#include "hostip.h"
@@ -70,7 +68,7 @@
#include "progress.h"
# if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
- (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
+ (defined(WIN32) || defined(__SYMBIAN32__))
# define CARES_STATICLIB
# endif
# include <ares.h>
@@ -91,8 +89,20 @@ struct ResolverResults {
int num_pending; /* number of ares_gethostbyname() requests */
Curl_addrinfo *temp_ai; /* intermediary result while fetching c-ares parts */
int last_status;
+ struct curltime happy_eyeballs_dns_time; /* when this timer started, or 0 */
};
+/* How long we are willing to wait for additional parallel responses after
+ obtaining a "definitive" one.
+
+ This is intended to equal the c-ares default timeout. cURL always uses that
+ default value. Unfortunately, c-ares doesn't expose its default timeout in
+ its API, but it is officially documented as 5 seconds.
+
+ See query_completed_cb() for an explanation of how this is used.
+ */
+#define HAPPY_EYEBALLS_DNS_TIMEOUT 5000
+
/*
* Curl_resolver_global_init() - the generic low-level asynchronous name
* resolve API. Called from curl_global_init() to initialize global resolver
@@ -121,6 +131,17 @@ void Curl_resolver_global_cleanup(void)
#endif
}
+
+static void Curl_ares_sock_state_cb(void *data, ares_socket_t socket_fd,
+ int readable, int writable)
+{
+ struct Curl_easy *easy = data;
+ if(!readable && !writable) {
+ DEBUGASSERT(easy);
+ Curl_multi_closed(easy, socket_fd);
+ }
+}
+
/*
* Curl_resolver_init()
*
@@ -128,9 +149,14 @@ void Curl_resolver_global_cleanup(void)
* URL-state specific environment ('resolver' member of the UrlState
* structure). Fills the passed pointer by the initialized ares_channel.
*/
-CURLcode Curl_resolver_init(void **resolver)
+CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
{
- int status = ares_init((ares_channel*)resolver);
+ int status;
+ struct ares_options options;
+ int optmask = ARES_OPT_SOCK_STATE_CB;
+ options.sock_state_cb = Curl_ares_sock_state_cb;
+ options.sock_state_cb_data = easy;
+ status = ares_init_options((ares_channel*)resolver, &options, optmask);
if(status != ARES_SUCCESS) {
if(status == ARES_ENOMEM)
return CURLE_OUT_OF_MEMORY;
@@ -161,12 +187,15 @@ void Curl_resolver_cleanup(void *resolver)
* environment ('resolver' member of the UrlState structure). Duplicates the
* 'from' ares channel and passes the resulting channel to the 'to' pointer.
*/
-int Curl_resolver_duphandle(void **to, void *from)
+CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to, void *from)
{
- /* Clone the ares channel for the new handle */
- if(ARES_SUCCESS != ares_dup((ares_channel*)to, (ares_channel)from))
- return CURLE_FAILED_INIT;
- return CURLE_OK;
+ (void)from;
+ /*
+ * it would be better to call ares_dup instead, but right now
+ * it is not possible to set 'sock_state_cb_data' outside of
+ * ares_init_options
+ */
+ return Curl_resolver_init(easy, to);
}
static void destroy_async_data(struct Curl_async *async);
@@ -182,6 +211,17 @@ void Curl_resolver_cancel(struct connectdata *conn)
}
/*
+ * We're equivalent to Curl_resolver_cancel() for the c-ares resolver. We
+ * never block.
+ */
+void Curl_resolver_kill(struct connectdata *conn)
+{
+ /* We don't need to check the resolver state because we can be called safely
+ at any time and we always do the same thing. */
+ Curl_resolver_cancel(conn);
+}
+
+/*
* destroy_async_data() cleans up async resolver data.
*/
static void destroy_async_data(struct Curl_async *async)
@@ -260,7 +300,7 @@ static int waitperform(struct connectdata *conn, int timeout_ms)
bitmask = ares_getsock((ares_channel)data->state.resolver, socks,
ARES_GETSOCK_MAXNUM);
- for(i=0; i < ARES_GETSOCK_MAXNUM; i++) {
+ for(i = 0; i < ARES_GETSOCK_MAXNUM; i++) {
pfd[i].events = 0;
pfd[i].revents = 0;
if(ARES_GETSOCK_READABLE(bitmask, i)) {
@@ -289,11 +329,11 @@ static int waitperform(struct connectdata *conn, int timeout_ms)
ARES_SOCKET_BAD);
else {
/* move through the descriptors and ask for processing on them */
- for(i=0; i < num; i++)
+ for(i = 0; i < num; i++)
ares_process_fd((ares_channel)data->state.resolver,
- pfd[i].revents & (POLLRDNORM|POLLIN)?
+ (pfd[i].revents & (POLLRDNORM|POLLIN))?
pfd[i].fd:ARES_SOCKET_BAD,
- pfd[i].revents & (POLLWRNORM|POLLOUT)?
+ (pfd[i].revents & (POLLWRNORM|POLLOUT))?
pfd[i].fd:ARES_SOCKET_BAD);
}
return nfds;
@@ -314,22 +354,48 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
conn->async.os_specific;
CURLcode result = CURLE_OK;
- *dns = NULL;
+ if(dns)
+ *dns = NULL;
waitperform(conn, 0);
+ /* Now that we've checked for any last minute results above, see if there are
+ any responses still pending when the EXPIRE_HAPPY_EYEBALLS_DNS timer
+ expires. */
+ if(res
+ && res->num_pending
+ /* This is only set to non-zero if the timer was started. */
+ && (res->happy_eyeballs_dns_time.tv_sec
+ || res->happy_eyeballs_dns_time.tv_usec)
+ && (Curl_timediff(Curl_now(), res->happy_eyeballs_dns_time)
+ >= HAPPY_EYEBALLS_DNS_TIMEOUT)) {
+ /* Remember that the EXPIRE_HAPPY_EYEBALLS_DNS timer is no longer
+ running. */
+ memset(
+ &res->happy_eyeballs_dns_time, 0, sizeof(res->happy_eyeballs_dns_time));
+
+ /* Cancel the raw c-ares request, which will fire query_completed_cb() with
+ ARES_ECANCELLED synchronously for all pending responses. This will
+ leave us with res->num_pending == 0, which is perfect for the next
+ block. */
+ ares_cancel((ares_channel)data->state.resolver);
+ DEBUGASSERT(res->num_pending == 0);
+ }
+
if(res && !res->num_pending) {
- (void)Curl_addrinfo_callback(conn, res->last_status, res->temp_ai);
- /* temp_ai ownership is moved to the connection, so we need not free-up
- them */
- res->temp_ai = NULL;
+ if(dns) {
+ (void)Curl_addrinfo_callback(conn, res->last_status, res->temp_ai);
+ /* temp_ai ownership is moved to the connection, so we need not free-up
+ them */
+ res->temp_ai = NULL;
+ }
if(!conn->async.dns) {
failf(data, "Could not resolve: %s (%s)",
conn->async.hostname, ares_strerror(conn->async.status));
result = conn->bits.proxy?CURLE_COULDNT_RESOLVE_PROXY:
CURLE_COULDNT_RESOLVE_HOST;
}
- else
+ else if(dns)
*dns = conn->async.dns;
destroy_async_data(&conn->async);
@@ -341,21 +407,21 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
/*
* Curl_resolver_wait_resolv()
*
- * waits for a resolve to finish. This function should be avoided since using
+ * 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.
+ * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
+ * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
*/
CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
struct Curl_dns_entry **entry)
{
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
- long timeout;
- struct timeval now = Curl_tvnow();
+ timediff_t timeout;
+ struct curltime now = Curl_now();
struct Curl_dns_entry *temp_entry;
if(entry)
@@ -392,7 +458,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
timeout_ms = 1000;
waitperform(conn, timeout_ms);
- result = Curl_resolver_is_resolved(conn, &temp_entry);
+ result = Curl_resolver_is_resolved(conn, entry?&temp_entry:NULL);
if(result || conn->async.done)
break;
@@ -400,8 +466,8 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else {
- struct timeval now2 = Curl_tvnow();
- time_t timediff = Curl_tvdiff(now2, now); /* spent time */
+ struct curltime now2 = Curl_now();
+ timediff_t timediff = Curl_timediff(now2, now); /* spent time */
if(timediff <= 0)
timeout -= 1; /* always deduct at least 1 */
else if(timediff > timeout)
@@ -424,9 +490,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
if(result)
/* close the connection, since we can't return failure here without
- cleaning up this connection properly.
- TODO: remove this action from here, it is not a name resolver decision.
- */
+ cleaning up this connection properly. */
connclose(conn, "c-ares resolve failed");
return result;
@@ -474,17 +538,79 @@ static void query_completed_cb(void *arg, /* (struct connectdata *) */
return;
res = (struct ResolverResults *)conn->async.os_specific;
- res->num_pending--;
+ if(res) {
+ res->num_pending--;
- if(CURL_ASYNC_SUCCESS == status) {
- Curl_addrinfo *ai = Curl_he2ai(hostent, conn->async.port);
- if(ai) {
- compound_results(res, ai);
+ if(CURL_ASYNC_SUCCESS == status) {
+ Curl_addrinfo *ai = Curl_he2ai(hostent, conn->async.port);
+ if(ai) {
+ compound_results(res, ai);
+ }
+ }
+ /* A successful result overwrites any previous error */
+ if(res->last_status != ARES_SUCCESS)
+ res->last_status = status;
+
+ /* If there are responses still pending, we presume they must be the
+ complementary IPv4 or IPv6 lookups that we started in parallel in
+ Curl_resolver_getaddrinfo() (for Happy Eyeballs). If we've got a
+ "definitive" response from one of a set of parallel queries, we need to
+ think about how long we're willing to wait for more responses. */
+ if(res->num_pending
+ /* Only these c-ares status values count as "definitive" for these
+ purposes. For example, ARES_ENODATA is what we expect when there is
+ no IPv6 entry for a domain name, and that's not a reason to get more
+ aggressive in our timeouts for the other response. Other errors are
+ either a result of bad input (which should affect all parallel
+ requests), local or network conditions, non-definitive server
+ responses, or us cancelling the request. */
+ && (status == ARES_SUCCESS || status == ARES_ENOTFOUND)) {
+ /* Right now, there can only be up to two parallel queries, so don't
+ bother handling any other cases. */
+ DEBUGASSERT(res->num_pending == 1);
+
+ /* It's possible that one of these parallel queries could succeed
+ quickly, but the other could always fail or timeout (when we're
+ talking to a pool of DNS servers that can only successfully resolve
+ IPv4 address, for example).
+
+ It's also possible that the other request could always just take
+ longer because it needs more time or only the second DNS server can
+ fulfill it successfully. But, to align with the philosophy of Happy
+ Eyeballs, we don't want to wait _too_ long or users will think
+ requests are slow when IPv6 lookups don't actually work (but IPv4 ones
+ do).
+
+ So, now that we have a usable answer (some IPv4 addresses, some IPv6
+ addresses, or "no such domain"), we start a timeout for the remaining
+ pending responses. Even though it is typical that this resolved
+ request came back quickly, that needn't be the case. It might be that
+ this completing request didn't get a result from the first DNS server
+ or even the first round of the whole DNS server pool. So it could
+ already be quite some time after we issued the DNS queries in the
+ first place. Without modifying c-ares, we can't know exactly where in
+ its retry cycle we are. We could guess based on how much time has
+ gone by, but it doesn't really matter. Happy Eyeballs tells us that,
+ given usable information in hand, we simply don't want to wait "too
+ much longer" after we get a result.
+
+ We simply wait an additional amount of time equal to the default
+ c-ares query timeout. That is enough time for a typical parallel
+ response to arrive without being "too long". Even on a network
+ where one of the two types of queries is failing or timing out
+ constantly, this will usually mean we wait a total of the default
+ c-ares timeout (5 seconds) plus the round trip time for the successful
+ request, which seems bearable. The downside is that c-ares might race
+ with us to issue one more retry just before we give up, but it seems
+ better to "waste" that request instead of trying to guess the perfect
+ timeout to prevent it. After all, we don't even know where in the
+ c-ares retry cycle each request is.
+ */
+ res->happy_eyeballs_dns_time = Curl_now();
+ Curl_expire(
+ conn->data, HAPPY_EYEBALLS_DNS_TIMEOUT, EXPIRE_HAPPY_EYEBALLS_DNS);
}
}
- /* A successful result overwrites any previous error */
- if(res->last_status != ARES_SUCCESS)
- res->last_status = status;
}
/*
diff --git a/Utilities/cmcurl/lib/asyn-thread.c b/Utilities/cmcurl/lib/asyn-thread.c
index 65fa6c5be..55e0811c5 100644
--- a/Utilities/cmcurl/lib/asyn-thread.c
+++ b/Utilities/cmcurl/lib/asyn-thread.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -79,6 +79,10 @@
#include "curl_memory.h"
#include "memdebug.h"
+struct resdata {
+ struct curltime start;
+};
+
/*
* Curl_resolver_global_init()
* Called from curl_global_init() to initialize global resolver environment.
@@ -102,11 +106,14 @@ void Curl_resolver_global_cleanup(void)
* Curl_resolver_init()
* Called from curl_easy_init() -> Curl_open() to initialize resolver
* URL-state specific environment ('resolver' member of the UrlState
- * structure). Does nothing here.
+ * structure).
*/
-CURLcode Curl_resolver_init(void **resolver)
+CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver)
{
- (void)resolver;
+ (void)easy;
+ *resolver = calloc(1, sizeof(struct resdata));
+ if(!*resolver)
+ return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
@@ -114,24 +121,22 @@ CURLcode Curl_resolver_init(void **resolver)
* Curl_resolver_cleanup()
* Called from curl_easy_cleanup() -> Curl_close() to cleanup resolver
* URL-state specific environment ('resolver' member of the UrlState
- * structure). Does nothing here.
+ * structure).
*/
void Curl_resolver_cleanup(void *resolver)
{
- (void)resolver;
+ free(resolver);
}
/*
* Curl_resolver_duphandle()
* Called from curl_easy_duphandle() to duplicate resolver URL state-specific
- * environment ('resolver' member of the UrlState structure). Does nothing
- * here.
+ * environment ('resolver' member of the UrlState structure).
*/
-int Curl_resolver_duphandle(void **to, void *from)
+CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to, void *from)
{
- (void)to;
(void)from;
- return CURLE_OK;
+ return Curl_resolver_init(easy, to);
}
static void destroy_async_data(struct Curl_async *);
@@ -178,8 +183,6 @@ static struct thread_sync_data *conn_thread_sync_data(struct connectdata *conn)
return &(((struct thread_data *)conn->async.os_specific)->tsd);
}
-#define CONN_THREAD_SYNC_DATA(conn) &(((conn)->async.os_specific)->tsd);
-
/* Destroy resolver thread synchronization data */
static
void destroy_thread_sync_data(struct thread_sync_data * tsd)
@@ -210,6 +213,10 @@ int init_thread_sync_data(struct thread_data * td,
tsd->td = td;
tsd->port = port;
+ /* Treat the request as done until the thread actually starts so any early
+ * cleanup gets done properly.
+ */
+ tsd->done = 1;
#ifdef HAVE_GETADDRINFO
DEBUGASSERT(hints);
tsd->hints = *hints;
@@ -270,7 +277,7 @@ static unsigned int CURL_STDCALL getaddrinfo_thread(void *arg)
char service[12];
int rc;
- snprintf(service, sizeof(service), "%d", tsd->port);
+ msnprintf(service, sizeof(service), "%d", tsd->port);
rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res);
@@ -380,11 +387,11 @@ static bool init_resolve_thread(struct connectdata *conn,
const struct addrinfo *hints)
{
struct thread_data *td = calloc(1, sizeof(struct thread_data));
- int err = RESOLVER_ENOMEM;
+ int err = ENOMEM;
conn->async.os_specific = (void *)td;
if(!td)
- goto err_exit;
+ goto errno_exit;
conn->async.port = port;
conn->async.done = FALSE;
@@ -392,14 +399,20 @@ static bool init_resolve_thread(struct connectdata *conn,
conn->async.dns = NULL;
td->thread_hnd = curl_thread_t_null;
- if(!init_thread_sync_data(td, hostname, port, hints))
- goto err_exit;
+ if(!init_thread_sync_data(td, hostname, port, hints)) {
+ conn->async.os_specific = NULL;
+ free(td);
+ goto errno_exit;
+ }
free(conn->async.hostname);
conn->async.hostname = strdup(hostname);
if(!conn->async.hostname)
goto err_exit;
+ /* The thread will set this to 1 when complete. */
+ td->tsd.done = 0;
+
#ifdef HAVE_GETADDRINFO
td->thread_hnd = Curl_thread_create(getaddrinfo_thread, &td->tsd);
#else
@@ -407,9 +420,9 @@ static bool init_resolve_thread(struct connectdata *conn,
#endif
if(!td->thread_hnd) {
-#ifndef _WIN32_WCE
+ /* The thread never started, so mark it as done here for proper cleanup. */
+ td->tsd.done = 1;
err = errno;
-#endif
goto err_exit;
}
@@ -418,8 +431,8 @@ static bool init_resolve_thread(struct connectdata *conn,
err_exit:
destroy_async_data(&conn->async);
- SET_ERRNO(err);
-
+ errno_exit:
+ errno = err;
return FALSE;
}
@@ -448,27 +461,21 @@ static CURLcode resolver_error(struct connectdata *conn)
return result;
}
-/*
- * Curl_resolver_wait_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_resolver_wait_resolv(struct connectdata *conn,
- struct Curl_dns_entry **entry)
+static CURLcode thread_wait_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **entry,
+ bool report)
{
struct thread_data *td = (struct thread_data*) conn->async.os_specific;
CURLcode result = CURLE_OK;
DEBUGASSERT(conn && td);
+ DEBUGASSERT(td->thread_hnd != curl_thread_t_null);
/* wait for the thread to resolve the name */
- if(Curl_thread_join(&td->thread_hnd))
- result = getaddrinfo_complete(conn);
+ if(Curl_thread_join(&td->thread_hnd)) {
+ if(entry)
+ result = getaddrinfo_complete(conn);
+ }
else
DEBUGASSERT(0);
@@ -477,18 +484,55 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
if(entry)
*entry = conn->async.dns;
- if(!conn->async.dns)
+ if(!conn->async.dns && report)
/* a name was not resolved, report error */
result = resolver_error(conn);
destroy_async_data(&conn->async);
- if(!conn->async.dns)
+ if(!conn->async.dns && report)
connclose(conn, "asynch resolve failed");
return result;
}
+
+/*
+ * Until we gain a way to signal the resolver threads to stop early, we must
+ * simply wait for them and ignore their results.
+ */
+void Curl_resolver_kill(struct connectdata *conn)
+{
+ struct thread_data *td = (struct thread_data*) conn->async.os_specific;
+
+ /* If we're still resolving, we must wait for the threads to fully clean up,
+ unfortunately. Otherwise, we can simply cancel to clean up any resolver
+ data. */
+ if(td && td->thread_hnd != curl_thread_t_null)
+ (void)thread_wait_resolv(conn, NULL, FALSE);
+ else
+ Curl_resolver_cancel(conn);
+}
+
+/*
+ * Curl_resolver_wait_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,
+ * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
+ *
+ * This is the version for resolves-in-a-thread.
+ */
+CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
+ struct Curl_dns_entry **entry)
+{
+ return thread_wait_resolv(conn, entry, TRUE);
+}
+
/*
* Curl_resolver_is_resolved() is called repeatedly to check if a previous
* name resolve request has completed. It should also make sure to time-out if
@@ -525,7 +569,8 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
}
else {
/* poll for name lookup done with exponential backoff up to 250ms */
- time_t elapsed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
+ timediff_t elapsed = Curl_timediff(Curl_now(),
+ data->progress.t_startsingle);
if(elapsed < 0)
elapsed = 0;
@@ -550,9 +595,22 @@ int Curl_resolver_getsock(struct connectdata *conn,
curl_socket_t *socks,
int numsocks)
{
- (void)conn;
+ time_t milli;
+ timediff_t ms;
+ struct Curl_easy *data = conn->data;
+ struct resdata *reslv = (struct resdata *)data->state.resolver;
(void)socks;
(void)numsocks;
+ ms = Curl_timediff(Curl_now(), reslv->start);
+ if(ms < 3)
+ milli = 0;
+ else if(ms <= 50)
+ milli = ms/3;
+ else if(ms <= 250)
+ milli = 50;
+ else
+ milli = 200;
+ Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
return 0;
}
@@ -566,6 +624,8 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
int *waitp)
{
struct in_addr in;
+ struct Curl_easy *data = conn->data;
+ struct resdata *reslv = (struct resdata *)data->state.resolver;
*waitp = 0; /* default to synchronous response */
@@ -573,14 +633,17 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
/* This is a dotted IP address 123.123.123.123-style */
return Curl_ip2addr(AF_INET, &in, hostname, port);
+ reslv->start = Curl_now();
+
/* fire up a new resolver thread! */
if(init_resolve_thread(conn, hostname, port, NULL)) {
*waitp = 1; /* expect asynchronous response */
return NULL;
}
- /* fall-back to blocking version */
- return Curl_ipv4_resolve_r(hostname, port);
+ failf(conn->data, "getaddrinfo() thread failed\n");
+
+ return NULL;
}
#else /* !HAVE_GETADDRINFO */
@@ -594,28 +657,29 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
int *waitp)
{
struct addrinfo hints;
- struct in_addr in;
- Curl_addrinfo *res;
- int error;
char sbuf[12];
int pf = PF_INET;
-#ifdef CURLRES_IPV6
- struct in6_addr in6;
-#endif /* CURLRES_IPV6 */
+ struct Curl_easy *data = conn->data;
+ struct resdata *reslv = (struct resdata *)data->state.resolver;
*waitp = 0; /* default to synchronous response */
#ifndef USE_RESOLVE_ON_IPS
- /* First check if this is an IPv4 address string */
- if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
- /* This is a dotted IP address 123.123.123.123-style */
- return Curl_ip2addr(AF_INET, &in, hostname, port);
-
+ {
+ struct in_addr in;
+ /* First check if this is an IPv4 address string */
+ if(Curl_inet_pton(AF_INET, hostname, &in) > 0)
+ /* This is a dotted IP address 123.123.123.123-style */
+ return Curl_ip2addr(AF_INET, &in, hostname, port);
+ }
#ifdef CURLRES_IPV6
- /* check if this is an IPv6 address string */
- if(Curl_inet_pton(AF_INET6, hostname, &in6) > 0)
- /* This is an IPv6 address literal */
- return Curl_ip2addr(AF_INET6, &in6, hostname, port);
+ {
+ struct in6_addr in6;
+ /* check if this is an IPv6 address string */
+ if(Curl_inet_pton(AF_INET6, hostname, &in6) > 0)
+ /* This is an IPv6 address literal */
+ return Curl_ip2addr(AF_INET6, &in6, hostname, port);
+ }
#endif /* CURLRES_IPV6 */
#endif /* !USE_RESOLVE_ON_IPS */
@@ -644,29 +708,18 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
hints.ai_family = pf;
hints.ai_socktype = conn->socktype;
- snprintf(sbuf, sizeof(sbuf), "%d", port);
+ msnprintf(sbuf, sizeof(sbuf), "%d", port);
+ reslv->start = Curl_now();
/* fire up a new resolver thread! */
if(init_resolve_thread(conn, hostname, port, &hints)) {
*waitp = 1; /* expect asynchronous response */
return NULL;
}
- /* fall-back to blocking version */
- infof(conn->data, "init_resolve_thread() failed for %s; %s\n",
- hostname, Curl_strerror(conn, ERRNO));
-
- error = Curl_getaddrinfo_ex(hostname, sbuf, &hints, &res);
- if(error) {
- infof(conn->data, "getaddrinfo() failed for %s:%d; %s\n",
- hostname, port, Curl_strerror(conn, SOCKERRNO));
- return NULL;
- }
- else {
- Curl_addrinfo_set_port(res, port);
- }
+ failf(data, "getaddrinfo() thread failed to start\n");
+ return NULL;
- return res;
}
#endif /* !HAVE_GETADDRINFO */
diff --git a/Utilities/cmcurl/lib/asyn.h b/Utilities/cmcurl/lib/asyn.h
index 3adc3664a..ccd4b1f7e 100644
--- a/Utilities/cmcurl/lib/asyn.h
+++ b/Utilities/cmcurl/lib/asyn.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -60,7 +60,7 @@ void Curl_resolver_global_cleanup(void);
* Returning anything else than CURLE_OK fails curl_easy_init() with the
* correspondent code.
*/
-CURLcode Curl_resolver_init(void **resolver);
+CURLcode Curl_resolver_init(struct Curl_easy *easy, void **resolver);
/*
* Curl_resolver_cleanup()
@@ -79,17 +79,33 @@ void Curl_resolver_cleanup(void *resolver);
* pointer. Returning anything else than CURLE_OK causes failed
* curl_easy_duphandle() call.
*/
-int Curl_resolver_duphandle(void **to, void *from);
+CURLcode Curl_resolver_duphandle(struct Curl_easy *easy, void **to,
+ void *from);
/*
* Curl_resolver_cancel().
*
* It is called from inside other functions to cancel currently performing
* resolver request. Should also free any temporary resources allocated to
- * perform a request.
+ * perform a request. This never waits for resolver threads to complete.
+ *
+ * It is safe to call this when conn is in any state.
*/
void Curl_resolver_cancel(struct connectdata *conn);
+/*
+ * Curl_resolver_kill().
+ *
+ * This acts like Curl_resolver_cancel() except it will block until any threads
+ * associated with the resolver are complete. This never blocks for resolvers
+ * that do not use threads. This is intended to be the "last chance" function
+ * that cleans up an in-progress resolver completely (before its owner is about
+ * to die).
+ *
+ * It is safe to call this when conn is in any state.
+ */
+void Curl_resolver_kill(struct connectdata *conn);
+
/* Curl_resolver_getsock()
*
* This function is called from the multi_getsock() function. 'sock' is a
@@ -116,14 +132,13 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
/*
* Curl_resolver_wait_resolv()
*
- * waits for a resolve to finish. This function should be avoided since using
+ * 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.
-
+ * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved,
+ * CURLE_OPERATION_TIMEDOUT if a time-out occurred, or other errors.
*/
CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
struct Curl_dns_entry **dnsentry);
@@ -147,11 +162,12 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
#ifndef CURLRES_ASYNCH
/* convert these functions if an asynch resolver isn't used */
#define Curl_resolver_cancel(x) Curl_nop_stmt
+#define Curl_resolver_kill(x) Curl_nop_stmt
#define Curl_resolver_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
#define Curl_resolver_wait_resolv(x,y) CURLE_COULDNT_RESOLVE_HOST
#define Curl_resolver_getsock(x,y,z) 0
-#define Curl_resolver_duphandle(x,y) CURLE_OK
-#define Curl_resolver_init(x) CURLE_OK
+#define Curl_resolver_duphandle(x,y,z) CURLE_OK
+#define Curl_resolver_init(x,y) CURLE_OK
#define Curl_resolver_global_init() CURLE_OK
#define Curl_resolver_global_cleanup() Curl_nop_stmt
#define Curl_resolver_cleanup(x) Curl_nop_stmt
diff --git a/Utilities/cmcurl/lib/base64.c b/Utilities/cmcurl/lib/base64.c
index 204a2273d..fb081a6bb 100644
--- a/Utilities/cmcurl/lib/base64.c
+++ b/Utilities/cmcurl/lib/base64.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -23,6 +23,11 @@
/* Base64 encoding/decoding */
#include "curl_setup.h"
+
+#if !defined(CURL_DISABLE_HTTP_AUTH) || defined(USE_LIBSSH2) || \
+ defined(USE_LIBSSH) || !defined(CURL_DISABLE_LDAP) || \
+ !defined(CURL_DISABLE_DOH) || defined(USE_SSL)
+
#include "urldata.h" /* for the Curl_easy definition */
#include "warnless.h"
#include "curl_base64.h"
@@ -49,13 +54,12 @@ static size_t decodeQuantum(unsigned char *dest, const char *src)
unsigned long i, x = 0;
for(i = 0, s = src; i < 4; i++, s++) {
- unsigned long v = 0;
-
if(*s == '=') {
x = (x << 6);
padding++;
}
else {
+ unsigned long v = 0;
p = base64;
while(*p && (*p != *s)) {
@@ -234,24 +238,24 @@ static CURLcode base64_encode(const char *table64,
switch(inputparts) {
case 1: /* only one byte read */
- snprintf(output, 5, "%c%c==",
- table64[obuf[0]],
- table64[obuf[1]]);
+ msnprintf(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]]);
+ msnprintf(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]]);
+ msnprintf(output, 5, "%c%c%c%c",
+ table64[obuf[0]],
+ table64[obuf[1]],
+ table64[obuf[2]],
+ table64[obuf[3]]);
break;
}
output += 4;
@@ -318,3 +322,5 @@ CURLcode Curl_base64url_encode(struct Curl_easy *data,
{
return base64_encode(base64url, data, inputbuff, insize, outptr, outlen);
}
+
+#endif /* no users so disabled */
diff --git a/Utilities/cmcurl/lib/conncache.c b/Utilities/cmcurl/lib/conncache.c
index c79d22764..535091996 100644
--- a/Utilities/cmcurl/lib/conncache.c
+++ b/Utilities/cmcurl/lib/conncache.c
@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2012 - 2016, Linus Nielsen Feltzing, <linus@haxx.se>
- * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2019, 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
@@ -31,17 +31,41 @@
#include "multiif.h"
#include "sendf.h"
#include "conncache.h"
+#include "share.h"
+#include "sigpipe.h"
+#include "connect.h"
+
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"
+#ifdef CURLDEBUG
+/* the debug versions of these macros make extra certain that the lock is
+ never doubly locked or unlocked */
+#define CONN_LOCK(x) if((x)->share) { \
+ Curl_share_lock((x), CURL_LOCK_DATA_CONNECT, CURL_LOCK_ACCESS_SINGLE); \
+ DEBUGASSERT(!(x)->state.conncache_lock); \
+ (x)->state.conncache_lock = TRUE; \
+ }
+
+#define CONN_UNLOCK(x) if((x)->share) { \
+ DEBUGASSERT((x)->state.conncache_lock); \
+ (x)->state.conncache_lock = FALSE; \
+ Curl_share_unlock((x), CURL_LOCK_DATA_CONNECT); \
+ }
+#else
+#define CONN_LOCK(x) if((x)->share) \
+ Curl_share_lock((x), CURL_LOCK_DATA_CONNECT, CURL_LOCK_ACCESS_SINGLE)
+#define CONN_UNLOCK(x) if((x)->share) \
+ Curl_share_unlock((x), CURL_LOCK_DATA_CONNECT)
+#endif
+
static void conn_llist_dtor(void *user, void *element)
{
- struct connectdata *data = element;
+ struct connectdata *conn = element;
(void)user;
-
- data->bundle = NULL;
+ conn->bundle = NULL;
}
static CURLcode bundle_create(struct Curl_easy *data,
@@ -71,14 +95,13 @@ static void bundle_destroy(struct connectbundle *cb_ptr)
}
/* Add a connection to a bundle */
-static CURLcode bundle_add_conn(struct connectbundle *cb_ptr,
- struct connectdata *conn)
+static void bundle_add_conn(struct connectbundle *cb_ptr,
+ struct connectdata *conn)
{
Curl_llist_insert_next(&cb_ptr->conn_list, cb_ptr->conn_list.tail, conn,
&conn->bundle_node);
conn->bundle = cb_ptr;
cb_ptr->num_connections++;
- return CURLE_OK;
}
/* Remove a connection from a bundle */
@@ -109,8 +132,23 @@ static void free_bundle_hash_entry(void *freethis)
int Curl_conncache_init(struct conncache *connc, int size)
{
- return Curl_hash_init(&connc->hash, size, Curl_hash_str,
- Curl_str_key_compare, free_bundle_hash_entry);
+ int rc;
+
+ /* allocate a new easy handle to use when closing cached connections */
+ connc->closure_handle = curl_easy_init();
+ if(!connc->closure_handle)
+ return 1; /* bad */
+
+ rc = Curl_hash_init(&connc->hash, size, Curl_hash_str,
+ Curl_str_key_compare, free_bundle_hash_entry);
+ if(rc) {
+ Curl_close(connc->closure_handle);
+ connc->closure_handle = NULL;
+ }
+ else
+ connc->closure_handle->state.conn_cache = connc;
+
+ return rc;
}
void Curl_conncache_destroy(struct conncache *connc)
@@ -137,15 +175,47 @@ static void hashkey(struct connectdata *conn, char *buf,
DEBUGASSERT(len > 32);
/* put the number first so that the hostname gets cut off if too long */
- snprintf(buf, len, "%ld%s", conn->port, hostname);
+ msnprintf(buf, len, "%ld%s", conn->port, hostname);
+}
+
+void Curl_conncache_unlock(struct Curl_easy *data)
+{
+ CONN_UNLOCK(data);
+}
+
+/* Returns number of connections currently held in the connection cache.
+ Locks/unlocks the cache itself!
+*/
+size_t Curl_conncache_size(struct Curl_easy *data)
+{
+ size_t num;
+ CONN_LOCK(data);
+ num = data->state.conn_cache->num_conn;
+ CONN_UNLOCK(data);
+ return num;
+}
+
+/* Returns number of connections currently held in the connections's bundle
+ Locks/unlocks the cache itself!
+*/
+size_t Curl_conncache_bundle_size(struct connectdata *conn)
+{
+ size_t num;
+ CONN_LOCK(conn->data);
+ num = conn->bundle->num_connections;
+ CONN_UNLOCK(conn->data);
+ return num;
}
/* Look up the bundle with all the connections to the same host this
- connectdata struct is setup to use. */
+ connectdata struct is setup to use.
+
+ **NOTE**: When it returns, it holds the connection cache lock! */
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
struct conncache *connc)
{
struct connectbundle *bundle = NULL;
+ CONN_LOCK(conn->data);
if(connc) {
char key[128];
hashkey(conn, key, sizeof(key));
@@ -191,77 +261,94 @@ static void conncache_remove_bundle(struct conncache *connc,
CURLcode Curl_conncache_add_conn(struct conncache *connc,
struct connectdata *conn)
{
- CURLcode result;
+ CURLcode result = CURLE_OK;
struct connectbundle *bundle;
struct connectbundle *new_bundle = NULL;
struct Curl_easy *data = conn->data;
+ /* *find_bundle() locks the connection cache */
bundle = Curl_conncache_find_bundle(conn, data->state.conn_cache);
if(!bundle) {
int rc;
char key[128];
result = bundle_create(data, &new_bundle);
- if(result)
- return result;
+ if(result) {
+ goto unlock;
+ }
hashkey(conn, key, sizeof(key));
rc = conncache_add_bundle(data->state.conn_cache, key, new_bundle);
if(!rc) {
bundle_destroy(new_bundle);
- return CURLE_OUT_OF_MEMORY;
+ result = CURLE_OUT_OF_MEMORY;
+ goto unlock;
}
bundle = new_bundle;
}
- result = bundle_add_conn(bundle, conn);
- if(result) {
- if(new_bundle)
- conncache_remove_bundle(data->state.conn_cache, new_bundle);
- return result;
- }
-
+ bundle_add_conn(bundle, conn);
conn->connection_id = connc->next_connection_id++;
- connc->num_connections++;
+ connc->num_conn++;
DEBUGF(infof(conn->data, "Added connection %ld. "
- "The cache now contains %" CURL_FORMAT_CURL_OFF_TU " members\n",
- conn->connection_id, (curl_off_t) connc->num_connections));
+ "The cache now contains %zu members\n",
+ conn->connection_id, connc->num_conn));
- return CURLE_OK;
+ unlock:
+ CONN_UNLOCK(data);
+
+ return result;
}
-void Curl_conncache_remove_conn(struct conncache *connc,
- struct connectdata *conn)
+/*
+ * Removes the connectdata object from the connection cache *and* clears the
+ * ->data pointer association. Pass TRUE/FALSE in the 'lock' argument
+ * depending on if the parent function already holds the lock or not.
+ */
+void Curl_conncache_remove_conn(struct Curl_easy *data,
+ struct connectdata *conn, bool lock)
{
struct connectbundle *bundle = conn->bundle;
+ struct conncache *connc = data->state.conn_cache;
/* The bundle pointer can be NULL, since this function can be called
due to a failed connection attempt, before being added to a bundle */
if(bundle) {
+ if(lock) {
+ CONN_LOCK(data);
+ }
bundle_remove_conn(bundle, conn);
- if(bundle->num_connections == 0) {
+ if(bundle->num_connections == 0)
conncache_remove_bundle(connc, bundle);
- }
-
+ conn->bundle = NULL; /* removed from it */
if(connc) {
- connc->num_connections--;
-
- DEBUGF(infof(conn->data, "The cache now contains %"
- CURL_FORMAT_CURL_OFF_TU " members\n",
- (curl_off_t) connc->num_connections));
+ connc->num_conn--;
+ DEBUGF(infof(data, "The cache now contains %zu members\n",
+ connc->num_conn));
+ }
+ conn->data = NULL; /* clear the association */
+ if(lock) {
+ CONN_UNLOCK(data);
}
}
}
-/* This function iterates the entire connection cache and calls the
- function func() with the connection pointer as the first argument
- and the supplied 'param' argument as the other,
+/* This function iterates the entire connection cache and calls the function
+ func() with the connection pointer as the first argument and the supplied
+ 'param' argument as the other.
+
+ The conncache lock is still held when the callback is called. It needs it,
+ so that it can safely continue traversing the lists once the callback
+ returns.
+
+ Returns 1 if the loop was aborted due to the callback's return code.
Return 0 from func() to continue the loop, return 1 to abort it.
*/
-void Curl_conncache_foreach(struct conncache *connc,
+bool Curl_conncache_foreach(struct Curl_easy *data,
+ struct conncache *connc,
void *param,
int (*func)(struct connectdata *conn, void *param))
{
@@ -270,8 +357,9 @@ void Curl_conncache_foreach(struct conncache *connc,
struct curl_hash_element *he;
if(!connc)
- return;
+ return FALSE;
+ CONN_LOCK(data);
Curl_hash_start_iterate(&connc->hash, &iter);
he = Curl_hash_next_element(&iter);
@@ -288,16 +376,24 @@ void Curl_conncache_foreach(struct conncache *connc,
struct connectdata *conn = curr->ptr;
curr = curr->next;
- if(1 == func(conn, param))
- return;
+ if(1 == func(conn, param)) {
+ CONN_UNLOCK(data);
+ return TRUE;
+ }
}
}
+ CONN_UNLOCK(data);
+ return FALSE;
}
/* Return the first connection found in the cache. Used when closing all
- connections */
-struct connectdata *
-Curl_conncache_find_first_connection(struct conncache *connc)
+ connections.
+
+ NOTE: no locking is done here as this is presumably only done when cleaning
+ up a cache!
+*/
+static struct connectdata *
+conncache_find_first_connection(struct conncache *connc)
{
struct curl_hash_iterator iter;
struct curl_hash_element *he;
@@ -321,6 +417,181 @@ Curl_conncache_find_first_connection(struct conncache *connc)
return NULL;
}
+/*
+ * Give ownership of a connection back to the connection cache. Might
+ * disconnect the oldest existing in there to make space.
+ *
+ * Return TRUE if stored, FALSE if closed.
+ */
+bool Curl_conncache_return_conn(struct connectdata *conn)
+{
+ struct Curl_easy *data = conn->data;
+
+ /* data->multi->maxconnects can be negative, deal with it. */
+ size_t maxconnects =
+ (data->multi->maxconnects < 0) ? data->multi->num_easy * 4:
+ data->multi->maxconnects;
+ struct connectdata *conn_candidate = NULL;
+
+ conn->data = NULL; /* no owner anymore */
+ conn->lastused = Curl_now(); /* it was used up until now */
+ if(maxconnects > 0 &&
+ Curl_conncache_size(data) > maxconnects) {
+ infof(data, "Connection cache is full, closing the oldest one.\n");
+
+ conn_candidate = Curl_conncache_extract_oldest(data);
+ if(conn_candidate) {
+ /* the winner gets the honour of being disconnected */
+ (void)Curl_disconnect(data, conn_candidate, /* dead_connection */ FALSE);
+ }
+ }
+
+ return (conn_candidate == conn) ? FALSE : TRUE;
+
+}
+
+/*
+ * This function finds the connection in the connection bundle that has been
+ * unused for the longest time.
+ *
+ * Does not lock the connection cache!
+ *
+ * Returns the pointer to the oldest idle connection, or NULL if none was
+ * found.
+ */
+struct connectdata *
+Curl_conncache_extract_bundle(struct Curl_easy *data,
+ struct connectbundle *bundle)
+{
+ struct curl_llist_element *curr;
+ timediff_t highscore = -1;
+ timediff_t score;
+ struct curltime now;
+ struct connectdata *conn_candidate = NULL;
+ struct connectdata *conn;
+
+ (void)data;
+
+ now = Curl_now();
+
+ curr = bundle->conn_list.head;
+ while(curr) {
+ conn = curr->ptr;
+
+ if(!CONN_INUSE(conn) && !conn->data) {
+ /* Set higher score for the age passed since the connection was used */
+ score = Curl_timediff(now, conn->lastused);
+
+ if(score > highscore) {
+ highscore = score;
+ conn_candidate = conn;
+ }
+ }
+ curr = curr->next;
+ }
+ if(conn_candidate) {
+ /* remove it to prevent another thread from nicking it */
+ bundle_remove_conn(bundle, conn_candidate);
+ data->state.conn_cache->num_conn--;
+ DEBUGF(infof(data, "The cache now contains %zu members\n",
+ data->state.conn_cache->num_conn));
+ conn_candidate->data = data; /* associate! */
+ }
+
+ return conn_candidate;
+}
+
+/*
+ * This function finds the connection in the connection cache that has been
+ * unused for the longest time and extracts that from the bundle.
+ *
+ * Returns the pointer to the connection, or NULL if none was found.
+ */
+struct connectdata *
+Curl_conncache_extract_oldest(struct Curl_easy *data)
+{
+ struct conncache *connc = data->state.conn_cache;
+ struct curl_hash_iterator iter;
+ struct curl_llist_element *curr;
+ struct curl_hash_element *he;
+ timediff_t highscore =- 1;
+ timediff_t score;
+ struct curltime now;
+ struct connectdata *conn_candidate = NULL;
+ struct connectbundle *bundle;
+ struct connectbundle *bundle_candidate = NULL;
+
+ now = Curl_now();
+
+ CONN_LOCK(data);
+ Curl_hash_start_iterate(&connc->hash, &iter);
+
+ he = Curl_hash_next_element(&iter);
+ while(he) {
+ struct connectdata *conn;
+
+ bundle = he->ptr;
+
+ curr = bundle->conn_list.head;
+ while(curr) {
+ conn = curr->ptr;
+
+ if(!CONN_INUSE(conn) && !conn->data) {
+ /* Set higher score for the age passed since the connection was used */
+ score = Curl_timediff(now, conn->lastused);
+
+ if(score > highscore) {
+ highscore = score;
+ conn_candidate = conn;
+ bundle_candidate = bundle;
+ }
+ }
+ curr = curr->next;
+ }
+
+ he = Curl_hash_next_element(&iter);
+ }
+ if(conn_candidate) {
+ /* remove it to prevent another thread from nicking it */
+ bundle_remove_conn(bundle_candidate, conn_candidate);
+ connc->num_conn--;
+ DEBUGF(infof(data, "The cache now contains %zu members\n",
+ connc->num_conn));
+ conn_candidate->data = data; /* associate! */
+ }
+ CONN_UNLOCK(data);
+
+ return conn_candidate;
+}
+
+void Curl_conncache_close_all_connections(struct conncache *connc)
+{
+ struct connectdata *conn;
+
+ conn = conncache_find_first_connection(connc);
+ while(conn) {
+ SIGPIPE_VARIABLE(pipe_st);
+ conn->data = connc->closure_handle;
+
+ sigpipe_ignore(conn->data, &pipe_st);
+ /* This will remove the connection from the cache */
+ connclose(conn, "kill all");
+ (void)Curl_disconnect(connc->closure_handle, conn, FALSE);
+ sigpipe_restore(&pipe_st);
+
+ conn = conncache_find_first_connection(connc);
+ }
+
+ if(connc->closure_handle) {
+ SIGPIPE_VARIABLE(pipe_st);
+ sigpipe_ignore(connc->closure_handle, &pipe_st);
+
+ Curl_hostcache_clean(connc->closure_handle,
+ connc->closure_handle->dns.hostcache);
+ Curl_close(connc->closure_handle);
+ sigpipe_restore(&pipe_st);
+ }
+}
#if 0
/* Useful for debugging the connection cache */
diff --git a/Utilities/cmcurl/lib/conncache.h b/Utilities/cmcurl/lib/conncache.h
index f976cfdb4..35be9e0aa 100644
--- a/Utilities/cmcurl/lib/conncache.h
+++ b/Utilities/cmcurl/lib/conncache.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2015 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2015 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2012 - 2014, Linus Nielsen Feltzing, <linus@haxx.se>
*
* This software is licensed as described in the file COPYING, which
@@ -23,16 +23,23 @@
*
***************************************************************************/
+/*
+ * All accesses to struct fields and changing of data in the connection cache
+ * and connectbundles must be done with the conncache LOCKED. The cache might
+ * be shared.
+ */
+
struct conncache {
struct curl_hash hash;
- size_t num_connections;
+ size_t num_conn;
long next_connection_id;
- struct timeval last_cleanup;
+ struct curltime last_cleanup;
+ /* handle used for closing cached connections */
+ struct Curl_easy *closure_handle;
};
#define BUNDLE_NO_MULTIUSE -1
#define BUNDLE_UNKNOWN 0 /* initial value */
-#define BUNDLE_PIPELINING 1
#define BUNDLE_MULTIPLEX 2
struct connectbundle {
@@ -41,21 +48,26 @@ struct connectbundle {
struct curl_llist conn_list; /* The connectdata members of the bundle */
};
+/* returns 1 on error, 0 is fine */
int Curl_conncache_init(struct conncache *, int size);
-
void Curl_conncache_destroy(struct conncache *connc);
/* return the correct bundle, to a host or a proxy */
struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
struct conncache *connc);
+void Curl_conncache_unlock(struct Curl_easy *data);
+/* returns number of connections currently held in the connection cache */
+size_t Curl_conncache_size(struct Curl_easy *data);
+size_t Curl_conncache_bundle_size(struct connectdata *conn);
+bool Curl_conncache_return_conn(struct connectdata *conn);
CURLcode Curl_conncache_add_conn(struct conncache *connc,
- struct connectdata *conn);
-
-void Curl_conncache_remove_conn(struct conncache *connc,
- struct connectdata *conn);
-
-void Curl_conncache_foreach(struct conncache *connc,
+ struct connectdata *conn) WARN_UNUSED_RESULT;
+void Curl_conncache_remove_conn(struct Curl_easy *data,
+ struct connectdata *conn,
+ bool lock);
+bool Curl_conncache_foreach(struct Curl_easy *data,
+ struct conncache *connc,
void *param,
int (*func)(struct connectdata *conn,
void *param));
@@ -63,6 +75,12 @@ void Curl_conncache_foreach(struct conncache *connc,
struct connectdata *
Curl_conncache_find_first_connection(struct conncache *connc);
+struct connectdata *
+Curl_conncache_extract_bundle(struct Curl_easy *data,
+ struct connectbundle *bundle);
+struct connectdata *
+Curl_conncache_extract_oldest(struct Curl_easy *data);
+void Curl_conncache_close_all_connections(struct conncache *connc);
void Curl_conncache_print(struct conncache *connc);
#endif /* HEADER_CURL_CONNCACHE_H */
diff --git a/Utilities/cmcurl/lib/connect.c b/Utilities/cmcurl/lib/connect.c
index d4fd52b99..002535b42 100644
--- a/Utilities/cmcurl/lib/connect.c
+++ b/Utilities/cmcurl/lib/connect.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -28,8 +28,10 @@
#ifdef HAVE_SYS_UN_H
#include <sys/un.h> /* for sockaddr_un */
#endif
-#ifdef HAVE_NETINET_TCP_H
-#include <netinet/tcp.h> /* for TCP_NODELAY */
+#ifdef HAVE_LINUX_TCP_H
+#include <linux/tcp.h>
+#elif defined(HAVE_NETINET_TCP_H)
+#include <netinet/tcp.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
@@ -179,13 +181,13 @@ singleipconnect(struct connectdata *conn,
*
* @unittest: 1303
*/
-time_t Curl_timeleft(struct Curl_easy *data,
- struct timeval *nowp,
- bool duringconnect)
+timediff_t Curl_timeleft(struct Curl_easy *data,
+ struct curltime *nowp,
+ bool duringconnect)
{
int timeout_set = 0;
- time_t timeout_ms = duringconnect?DEFAULT_CONNECT_TIMEOUT:0;
- struct timeval now;
+ timediff_t timeout_ms = duringconnect?DEFAULT_CONNECT_TIMEOUT:0;
+ struct curltime now;
/* if a timeout is set, use the most restrictive one */
@@ -218,17 +220,17 @@ time_t Curl_timeleft(struct Curl_easy *data,
}
if(!nowp) {
- now = Curl_tvnow();
+ now = Curl_now();
nowp = &now;
}
/* subtract elapsed time */
if(duringconnect)
/* since this most recent connect started */
- timeout_ms -= Curl_tvdiff(*nowp, data->progress.t_startsingle);
+ timeout_ms -= Curl_timediff(*nowp, data->progress.t_startsingle);
else
/* since the entire operation started */
- timeout_ms -= Curl_tvdiff(*nowp, data->progress.t_startop);
+ timeout_ms -= Curl_timediff(*nowp, data->progress.t_startop);
if(!timeout_ms)
/* avoid returning 0 as that means no timeout! */
return -1;
@@ -249,7 +251,7 @@ static CURLcode bindlocal(struct connectdata *conn,
struct sockaddr_in6 *si6 = (struct sockaddr_in6 *)&sa;
#endif
- struct Curl_dns_entry *h=NULL;
+ struct Curl_dns_entry *h = NULL;
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 */
@@ -285,6 +287,34 @@ static CURLcode bindlocal(struct connectdata *conn,
/* interface */
if(!is_host) {
+#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.
+ *
+ *
+ * Only bind to the interface when specified as interface, not just
+ * as a hostname or ip address.
+ *
+ * interface might be a VRF, eg: vrf-blue, which means it cannot be
+ * converted to an IP address and would fail Curl_if2ip. Simply try
+ * to use it straight away.
+ */
+ if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
+ dev, (curl_socklen_t)strlen(dev) + 1) == 0) {
+ /* This is typically "errno 1, error: Operation not permitted" if
+ * you're not running as root or another suitable privileged
+ * user.
+ * If it succeeds it means the parameter was a valid interface and
+ * not an IP address. Return immediately.
+ */
+ return CURLE_OK;
+ }
+#endif
+
switch(Curl_if2ip(af, scope, conn->scope_id, dev,
myhost, sizeof(myhost))) {
case IF2IP_NOT_FOUND:
@@ -305,30 +335,6 @@ static CURLcode bindlocal(struct connectdata *conn,
infof(data, "Local Interface %s is ip %s using address family %i\n",
dev, myhost, af);
done = 1;
-
-#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.
- *
- *
- * Only bind to the interface when specified as interface, not just
- * as a hostname or ip address.
- */
- if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
- dev, (curl_socklen_t)strlen(dev)+1) != 0) {
- error = SOCKERRNO;
- infof(data, "SO_BINDTODEVICE %s failed with errno %d: %s;"
- " will do regular bind\n",
- dev, error, Curl_strerror(conn, error));
- /* This is typically "errno 1, error: Operation not permitted" if
- you're not running as root or another suitable privileged
- user */
- }
-#endif
break;
}
}
@@ -351,7 +357,7 @@ static CURLcode bindlocal(struct connectdata *conn,
conn->ip_version = CURL_IPRESOLVE_V6;
#endif
- rc = Curl_resolv(conn, dev, 0, &h);
+ rc = Curl_resolv(conn, dev, 0, FALSE, &h);
if(rc == CURLRESOLV_PENDING)
(void)Curl_resolver_wait_resolv(conn, &h);
conn->ip_version = ipver;
@@ -408,6 +414,10 @@ static CURLcode bindlocal(struct connectdata *conn,
}
if(done < 1) {
+ /* errorbuf is set false so failf will overwrite any message already in
+ the error buffer, so the user receives this error message instead of a
+ generic resolve error. */
+ data->state.errorbuf = FALSE;
failf(data, "Couldn't bind to '%s'", dev);
return CURLE_INTERFACE_FAILED;
}
@@ -436,9 +446,10 @@ static CURLcode bindlocal(struct connectdata *conn,
curl_socklen_t size = sizeof(add);
memset(&add, 0, sizeof(struct Curl_sockaddr_storage));
if(getsockname(sockfd, (struct sockaddr *) &add, &size) < 0) {
+ char buffer[STRERROR_LEN];
data->state.os_errno = error = SOCKERRNO;
failf(data, "getsockname() failed with errno %d: %s",
- error, Curl_strerror(conn, error));
+ error, Curl_strerror(error, buffer, sizeof(buffer)));
return CURLE_INTERFACE_FAILED;
}
infof(data, "Local port: %hu\n", port);
@@ -460,10 +471,12 @@ static CURLcode bindlocal(struct connectdata *conn,
else
break;
}
-
- data->state.os_errno = error = SOCKERRNO;
- failf(data, "bind failed with errno %d: %s",
- error, Curl_strerror(conn, error));
+ {
+ char buffer[STRERROR_LEN];
+ data->state.os_errno = error = SOCKERRNO;
+ failf(data, "bind failed with errno %d: %s",
+ error, Curl_strerror(error, buffer, sizeof(buffer)));
+ }
return CURLE_INTERFACE_FAILED;
}
@@ -512,7 +525,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
err = 0;
}
#endif
-#ifdef __minix
+#if defined(EBADIOCTL) && defined(__minix)
/* Minix 3.1.x doesn't support getsockopt on UDP sockets */
if(EBADIOCTL == err) {
SET_SOCKERRNO(0);
@@ -607,11 +620,14 @@ void Curl_persistconninfo(struct connectdata *conn)
conn->data->info.conn_local_port = conn->local_port;
}
-/* retrieves ip address and port from a sockaddr structure */
-static bool getaddressinfo(struct sockaddr *sa, char *addr,
- long *port)
+UNITTEST bool getaddressinfo(struct sockaddr *sa, char *addr,
+ long *port);
+
+/* retrieves ip address and port from a sockaddr structure.
+ note it calls Curl_inet_ntop which sets errno on fail, not SOCKERRNO. */
+UNITTEST bool getaddressinfo(struct sockaddr *sa, char *addr,
+ long *port)
{
- unsigned short us_port;
struct sockaddr_in *si = NULL;
#ifdef ENABLE_IPV6
struct sockaddr_in6 *si6 = NULL;
@@ -625,7 +641,7 @@ static bool getaddressinfo(struct sockaddr *sa, char *addr,
si = (struct sockaddr_in *)(void *) sa;
if(Curl_inet_ntop(sa->sa_family, &si->sin_addr,
addr, MAX_IPADR_LEN)) {
- us_port = ntohs(si->sin_port);
+ unsigned short us_port = ntohs(si->sin_port);
*port = us_port;
return TRUE;
}
@@ -635,7 +651,7 @@ static bool getaddressinfo(struct sockaddr *sa, char *addr,
si6 = (struct sockaddr_in6 *)(void *) sa;
if(Curl_inet_ntop(sa->sa_family, &si6->sin6_addr,
addr, MAX_IPADR_LEN)) {
- us_port = ntohs(si6->sin6_port);
+ unsigned short us_port = ntohs(si6->sin6_port);
*port = us_port;
return TRUE;
}
@@ -644,7 +660,7 @@ static bool getaddressinfo(struct sockaddr *sa, char *addr,
#if defined(HAVE_SYS_UN_H) && defined(AF_UNIX)
case AF_UNIX:
su = (struct sockaddr_un*)sa;
- snprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path);
+ msnprintf(addr, MAX_IPADR_LEN, "%s", su->sun_path);
*port = 0;
return TRUE;
#endif
@@ -654,7 +670,7 @@ static bool getaddressinfo(struct sockaddr *sa, char *addr,
addr[0] = '\0';
*port = 0;
-
+ errno = EAFNOSUPPORT;
return FALSE;
}
@@ -662,53 +678,57 @@ static bool getaddressinfo(struct sockaddr *sa, char *addr,
connection */
void Curl_updateconninfo(struct connectdata *conn, curl_socket_t sockfd)
{
- curl_socklen_t len;
- struct Curl_sockaddr_storage ssrem;
- struct Curl_sockaddr_storage ssloc;
- struct Curl_easy *data = conn->data;
-
if(conn->socktype == SOCK_DGRAM)
/* there's no connection! */
return;
+#if defined(HAVE_GETPEERNAME) || defined(HAVE_GETSOCKNAME)
if(!conn->bits.reuse && !conn->bits.tcp_fastopen) {
- int error;
-
+ struct Curl_easy *data = conn->data;
+ char buffer[STRERROR_LEN];
+ struct Curl_sockaddr_storage ssrem;
+ struct Curl_sockaddr_storage ssloc;
+ curl_socklen_t len;
+#ifdef HAVE_GETPEERNAME
len = sizeof(struct Curl_sockaddr_storage);
if(getpeername(sockfd, (struct sockaddr*) &ssrem, &len)) {
- error = SOCKERRNO;
+ int error = SOCKERRNO;
failf(data, "getpeername() failed with errno %d: %s",
- error, Curl_strerror(conn, error));
+ error, Curl_strerror(error, buffer, sizeof(buffer)));
return;
}
-
+#endif
+#ifdef HAVE_GETSOCKNAME
len = sizeof(struct Curl_sockaddr_storage);
memset(&ssloc, 0, sizeof(ssloc));
if(getsockname(sockfd, (struct sockaddr*) &ssloc, &len)) {
- error = SOCKERRNO;
+ int error = SOCKERRNO;
failf(data, "getsockname() failed with errno %d: %s",
- error, Curl_strerror(conn, error));
+ error, Curl_strerror(error, buffer, sizeof(buffer)));
return;
}
-
+#endif
+#ifdef HAVE_GETPEERNAME
if(!getaddressinfo((struct sockaddr*)&ssrem,
- conn->primary_ip, &conn->primary_port)) {
- error = ERRNO;
+ conn->primary_ip, &conn->primary_port)) {
failf(data, "ssrem inet_ntop() failed with errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
return;
}
memcpy(conn->ip_addr_str, conn->primary_ip, MAX_IPADR_LEN);
-
+#endif
+#ifdef HAVE_GETSOCKNAME
if(!getaddressinfo((struct sockaddr*)&ssloc,
conn->local_ip, &conn->local_port)) {
- error = ERRNO;
failf(data, "ssloc inet_ntop() failed with errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
return;
}
-
+#endif
}
+#else /* !HAVE_GETSOCKNAME && !HAVE_GETPEERNAME */
+ (void)sockfd; /* unused */
+#endif
/* persist connection info in session handle */
Curl_persistconninfo(conn);
@@ -724,9 +744,9 @@ CURLcode Curl_is_connected(struct connectdata *conn,
{
struct Curl_easy *data = conn->data;
CURLcode result = CURLE_OK;
- time_t allow;
+ timediff_t allow;
int error = 0;
- struct timeval now;
+ struct curltime now;
int rc;
int i;
@@ -740,7 +760,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
return CURLE_OK;
}
- now = Curl_tvnow();
+ now = Curl_now();
/* figure out how long time we have left to connect */
allow = Curl_timeleft(data, &now, TRUE);
@@ -751,7 +771,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
return CURLE_OPERATION_TIMEDOUT;
}
- for(i=0; i<2; i++) {
+ for(i = 0; i<2; i++) {
const int other = i ^ 1;
if(conn->tempsock[i] == CURL_SOCKET_BAD)
continue;
@@ -768,7 +788,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
if(rc == 0) { /* no connection yet */
error = 0;
- if(curlx_tvdiff(now, conn->connecttime) >= conn->timeoutms_per_addr) {
+ if(Curl_timediff(now, conn->connecttime) >= conn->timeoutms_per_addr) {
infof(data, "After %ldms connect time, move on!\n",
conn->timeoutms_per_addr);
error = ETIMEDOUT;
@@ -776,7 +796,8 @@ CURLcode Curl_is_connected(struct connectdata *conn,
/* should we try another protocol family? */
if(i == 0 && conn->tempaddr[1] == NULL &&
- curlx_tvdiff(now, conn->connecttime) >= HAPPY_EYEBALLS_TIMEOUT) {
+ (Curl_timediff(now, conn->connecttime) >=
+ data->set.happy_eyeballs_timeout)) {
trynextip(conn, sockindex, 1);
}
}
@@ -788,6 +809,9 @@ CURLcode Curl_is_connected(struct connectdata *conn,
conn->sock[sockindex] = conn->tempsock[i];
conn->ip_addr = conn->tempaddr[i];
conn->tempsock[i] = CURL_SOCKET_BAD;
+#ifdef ENABLE_IPV6
+ conn->bits.ipv6 = (conn->ip_addr->ai_family == AF_INET6)?TRUE:FALSE;
+#endif
/* close the other socket, if open */
if(conn->tempsock[other] != CURL_SOCKET_BAD) {
@@ -825,9 +849,11 @@ CURLcode Curl_is_connected(struct connectdata *conn,
if(conn->tempaddr[i]) {
CURLcode status;
char ipaddress[MAX_IPADR_LEN];
+ char buffer[STRERROR_LEN];
Curl_printable_address(conn->tempaddr[i], ipaddress, MAX_IPADR_LEN);
infof(data, "connect to %s port %ld failed: %s\n",
- ipaddress, conn->port, Curl_strerror(conn, error));
+ ipaddress, conn->port,
+ Curl_strerror(error, buffer, sizeof(buffer)));
conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?
allow : allow / 2;
@@ -843,8 +869,8 @@ CURLcode Curl_is_connected(struct connectdata *conn,
if(result) {
/* no more addresses to try */
-
const char *hostname;
+ char buffer[STRERROR_LEN];
/* if the first address family runs out of addresses to try before
the happy eyeball timeout, go ahead and try the next family now */
@@ -864,13 +890,14 @@ CURLcode Curl_is_connected(struct connectdata *conn,
hostname = conn->host.name;
failf(data, "Failed to connect to %s port %ld: %s",
- hostname, conn->port, Curl_strerror(conn, error));
+ hostname, conn->port,
+ Curl_strerror(error, buffer, sizeof(buffer)));
}
return result;
}
-void Curl_tcpnodelay(struct connectdata *conn, curl_socket_t sockfd)
+static void tcpnodelay(struct connectdata *conn, curl_socket_t sockfd)
{
#if defined(TCP_NODELAY)
#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
@@ -878,19 +905,7 @@ void Curl_tcpnodelay(struct connectdata *conn, curl_socket_t sockfd)
#endif
curl_socklen_t onoff = (curl_socklen_t) 1;
int level = IPPROTO_TCP;
-
-#if 0
- /* The use of getprotobyname() is disabled since it isn't thread-safe on
- numerous systems. On these getprotobyname_r() should be used instead, but
- that exists in at least one 4 arg version and one 5 arg version, and
- since the proto number rarely changes anyway we now just use the hard
- coded number. The "proper" fix would need a configure check for the
- correct function much in the same style the gethostbyname_r versions are
- detected. */
- struct protoent *pe = getprotobyname("tcp");
- if(pe)
- level = pe->p_proto;
-#endif
+ char buffer[STRERROR_LEN];
#if defined(CURL_DISABLE_VERBOSE_STRINGS)
(void) conn;
@@ -899,7 +914,7 @@ void Curl_tcpnodelay(struct connectdata *conn, curl_socket_t sockfd)
if(setsockopt(sockfd, level, TCP_NODELAY, (void *)&onoff,
sizeof(onoff)) < 0)
infof(data, "Could not set TCP_NODELAY: %s\n",
- Curl_strerror(conn, SOCKERRNO));
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
else
infof(data, "TCP_NODELAY set\n");
#else
@@ -916,12 +931,14 @@ void Curl_tcpnodelay(struct connectdata *conn, curl_socket_t sockfd)
static void nosigpipe(struct connectdata *conn,
curl_socket_t sockfd)
{
- struct Curl_easy *data= conn->data;
+ struct Curl_easy *data = conn->data;
int onoff = 1;
if(setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&onoff,
- sizeof(onoff)) < 0)
+ sizeof(onoff)) < 0) {
+ char buffer[STRERROR_LEN];
infof(data, "Could not set SO_NOSIGPIPE: %s\n",
- Curl_strerror(conn, SOCKERRNO));
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
+ }
}
#else
#define nosigpipe(x,y) Curl_nop_stmt
@@ -994,6 +1011,10 @@ static CURLcode singleipconnect(struct connectdata *conn,
char ipaddress[MAX_IPADR_LEN];
long port;
bool is_tcp;
+#ifdef TCP_FASTOPEN_CONNECT
+ int optval = 1;
+#endif
+ char buffer[STRERROR_LEN];
*sockp = CURL_SOCKET_BAD;
@@ -1008,13 +1029,12 @@ static CURLcode singleipconnect(struct connectdata *conn,
if(!getaddressinfo((struct sockaddr*)&addr.sa_addr,
ipaddress, &port)) {
/* malformed address or bug in inet_ntop, try next address */
- error = ERRNO;
failf(data, "sa_addr inet_ntop() failed with errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
Curl_closesocket(conn, sockfd);
return CURLE_OK;
}
- infof(data, " Trying %s...\n", ipaddress);
+ infof(data, " Trying %s:%ld...\n", ipaddress, port);
#ifdef ENABLE_IPV6
is_tcp = (addr.family == AF_INET || addr.family == AF_INET6) &&
@@ -1023,7 +1043,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
is_tcp = (addr.family == AF_INET) && addr.socktype == SOCK_STREAM;
#endif
if(is_tcp && data->set.tcp_nodelay)
- Curl_tcpnodelay(conn, sockfd);
+ tcpnodelay(conn, sockfd);
nosigpipe(conn, sockfd);
@@ -1034,9 +1054,11 @@ static CURLcode singleipconnect(struct connectdata *conn,
if(data->set.fsockopt) {
/* activate callback for setting socket options */
+ Curl_set_in_callback(data, true);
error = data->set.fsockopt(data->set.sockopt_client,
sockfd,
CURLSOCKTYPE_IPCXN);
+ Curl_set_in_callback(data, false);
if(error == CURL_SOCKOPT_ALREADY_CONNECTED)
isconnected = TRUE;
@@ -1068,25 +1090,45 @@ static CURLcode singleipconnect(struct connectdata *conn,
/* set socket non-blocking */
(void)curlx_nonblock(sockfd, TRUE);
- conn->connecttime = Curl_tvnow();
+ conn->connecttime = Curl_now();
if(conn->num_addr > 1)
Curl_expire(data, conn->timeoutms_per_addr, EXPIRE_DNS_PER_NAME);
/* Connect TCP sockets, bind UDP */
if(!isconnected && (conn->socktype == SOCK_STREAM)) {
if(conn->bits.tcp_fastopen) {
-#if defined(CONNECT_DATA_IDEMPOTENT) /* OS X */
- sa_endpoints_t endpoints;
- endpoints.sae_srcif = 0;
- endpoints.sae_srcaddr = NULL;
- endpoints.sae_srcaddrlen = 0;
- endpoints.sae_dstaddr = &addr.sa_addr;
- endpoints.sae_dstaddrlen = addr.addrlen;
-
- rc = connectx(sockfd, &endpoints, SAE_ASSOCID_ANY,
- CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT,
- NULL, 0, NULL, NULL);
-#elif defined(MSG_FASTOPEN) /* Linux */
+#if defined(CONNECT_DATA_IDEMPOTENT) /* Darwin */
+# if defined(HAVE_BUILTIN_AVAILABLE)
+ /* while connectx function is available since macOS 10.11 / iOS 9,
+ it did not have the interface declared correctly until
+ Xcode 9 / macOS SDK 10.13 */
+ if(__builtin_available(macOS 10.11, iOS 9.0, tvOS 9.0, watchOS 2.0, *)) {
+ sa_endpoints_t endpoints;
+ endpoints.sae_srcif = 0;
+ endpoints.sae_srcaddr = NULL;
+ endpoints.sae_srcaddrlen = 0;
+ endpoints.sae_dstaddr = &addr.sa_addr;
+ endpoints.sae_dstaddrlen = addr.addrlen;
+
+ rc = connectx(sockfd, &endpoints, SAE_ASSOCID_ANY,
+ CONNECT_RESUME_ON_READ_WRITE | CONNECT_DATA_IDEMPOTENT,
+ NULL, 0, NULL, NULL);
+ }
+ else {
+ rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
+ }
+# else
+ rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
+# endif /* HAVE_BUILTIN_AVAILABLE */
+#elif defined(TCP_FASTOPEN_CONNECT) /* Linux >= 4.11 */
+ if(setsockopt(sockfd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
+ (void *)&optval, sizeof(optval)) < 0)
+ infof(data, "Failed to enable TCP Fast Open on fd %d\n", sockfd);
+ else
+ infof(data, "TCP_FASTOPEN_CONNECT set\n");
+
+ rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
+#elif defined(MSG_FASTOPEN) /* old Linux */
if(conn->given->flags & PROTOPT_SSL)
rc = connect(sockfd, &addr.sa_addr, addr.addrlen);
else
@@ -1105,10 +1147,6 @@ static CURLcode singleipconnect(struct connectdata *conn,
return CURLE_OK;
}
-#ifdef ENABLE_IPV6
- conn->bits.ipv6 = (addr.family == AF_INET6)?TRUE:FALSE;
-#endif
-
if(-1 == rc) {
switch(error) {
case EINPROGRESS:
@@ -1128,7 +1166,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
default:
/* unknown error, fallthrough and try another address! */
infof(data, "Immediate connect fail for %s: %s\n",
- ipaddress, Curl_strerror(conn, error));
+ ipaddress, Curl_strerror(error, buffer, sizeof(buffer)));
data->state.os_errno = error;
/* connect failed */
@@ -1153,10 +1191,10 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
const struct Curl_dns_entry *remotehost)
{
struct Curl_easy *data = conn->data;
- struct timeval before = Curl_tvnow();
+ struct curltime before = Curl_now();
CURLcode result = CURLE_COULDNT_CONNECT;
- time_t timeout_ms = Curl_timeleft(data, &before, TRUE);
+ timediff_t timeout_ms = Curl_timeleft(data, &before, TRUE);
if(timeout_ms < 0) {
/* a precaution, no need to continue if time already is up */
@@ -1169,7 +1207,6 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
conn->tempaddr[1] = NULL;
conn->tempsock[0] = CURL_SOCKET_BAD;
conn->tempsock[1] = CURL_SOCKET_BAD;
- Curl_expire(conn->data, HAPPY_EYEBALLS_TIMEOUT, EXPIRE_HAPPY_EYEBALLS);
/* Max time for the next connection attempt */
conn->timeoutms_per_addr =
@@ -1190,6 +1227,8 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
}
data->info.numconnects++; /* to track the number of connections made */
+ Curl_expire(conn->data, data->set.happy_eyeballs_timeout,
+ EXPIRE_HAPPY_EYEBALLS);
return CURLE_OK;
}
@@ -1218,8 +1257,6 @@ static int conn_is_conn(struct connectdata *conn, void *param)
curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
struct connectdata **connp)
{
- curl_socket_t sockfd;
-
DEBUGASSERT(data);
/* this works for an easy handle:
@@ -1233,7 +1270,7 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
find.tofind = data->state.lastconnect;
find.found = FALSE;
- Curl_conncache_foreach(data->multi_easy?
+ Curl_conncache_foreach(data, data->multi_easy?
&data->multi_easy->conn_cache:
&data->multi->conn_cache, &find, conn_is_conn);
@@ -1242,15 +1279,15 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
return CURL_SOCKET_BAD;
}
- if(connp)
+ if(connp) {
/* only store this if the caller cares for it */
*connp = c;
- sockfd = c->sock[FIRSTSOCKET];
+ c->data = data;
+ }
+ return c->sock[FIRSTSOCKET];
}
else
return CURL_SOCKET_BAD;
-
- return sockfd;
}
/*
@@ -1296,14 +1333,18 @@ int Curl_closesocket(struct connectdata *conn,
status */
conn->sock_accepted[SECONDARYSOCKET] = FALSE;
else {
- Curl_multi_closed(conn, sock);
- return conn->fclosesocket(conn->closesocket_client, sock);
+ int rc;
+ Curl_multi_closed(conn->data, sock);
+ Curl_set_in_callback(conn->data, true);
+ rc = conn->fclosesocket(conn->closesocket_client, sock);
+ Curl_set_in_callback(conn->data, false);
+ return rc;
}
}
if(conn)
/* tell the multi-socket code about this */
- Curl_multi_closed(conn, sock);
+ Curl_multi_closed(conn->data, sock);
sclose(sock);
@@ -1341,14 +1382,14 @@ CURLcode Curl_socket(struct connectdata *conn,
addr->family = ai->ai_family;
addr->socktype = conn->socktype;
- addr->protocol = conn->socktype==SOCK_DGRAM?IPPROTO_UDP:ai->ai_protocol;
+ addr->protocol = conn->socktype == SOCK_DGRAM?IPPROTO_UDP:ai->ai_protocol;
addr->addrlen = ai->ai_addrlen;
if(addr->addrlen > sizeof(struct Curl_sockaddr_storage))
addr->addrlen = sizeof(struct Curl_sockaddr_storage);
memcpy(&addr->sa_addr, ai->ai_addr, addr->addrlen);
- if(data->set.fopensocket)
+ if(data->set.fopensocket) {
/*
* If the opensocket callback is set, all the destination address
* information is passed to the callback. Depending on this information the
@@ -1358,9 +1399,12 @@ CURLcode Curl_socket(struct connectdata *conn,
* might have been changed and this 'new' address will actually be used
* here to connect.
*/
+ Curl_set_in_callback(data, true);
*sockfd = data->set.fopensocket(data->set.opensocket_client,
CURLSOCKTYPE_IPCXN,
(struct curl_sockaddr *)addr);
+ Curl_set_in_callback(data, false);
+ }
else
/* opensocket callback not set, so simply create the socket now */
*sockfd = socket(addr->family, addr->socktype, addr->protocol);
@@ -1396,7 +1440,7 @@ void Curl_conncontrol(struct connectdata *conn,
if((ctrl == CONNCTRL_STREAM) &&
(conn->handler->flags & PROTOPT_STREAM))
DEBUGF(infof(conn->data, "Kill stream: %s\n", reason));
- else if(closeit != conn->bits.close) {
+ else if((bit)closeit != conn->bits.close) {
DEBUGF(infof(conn->data, "Marked for [%s]: %s\n",
closeit?"closure":"keep alive", reason));
conn->bits.close = closeit; /* the only place in the source code that
diff --git a/Utilities/cmcurl/lib/connect.h b/Utilities/cmcurl/lib/connect.h
index 44bdb1051..6a5c755cc 100644
--- a/Utilities/cmcurl/lib/connect.h
+++ b/Utilities/cmcurl/lib/connect.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -25,6 +25,7 @@
#include "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */
#include "sockaddr.h"
+#include "timeval.h"
CURLcode Curl_is_connected(struct connectdata *conn,
int sockindex,
@@ -35,13 +36,11 @@ CURLcode Curl_connecthost(struct connectdata *conn,
/* generic function that returns how much time there's left to run, according
to the timeouts set */
-time_t Curl_timeleft(struct Curl_easy *data,
- struct timeval *nowp,
- bool duringconnect);
+timediff_t Curl_timeleft(struct Curl_easy *data,
+ struct curltime *nowp,
+ bool duringconnect);
#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
-#define HAPPY_EYEBALLS_TIMEOUT 200 /* milliseconds to wait between
- IPv4/IPv6 connection attempts */
/*
* Used to extract socket and connectdata struct for the most recent
@@ -107,8 +106,6 @@ CURLcode Curl_socket(struct connectdata *conn,
struct Curl_sockaddr_ex *addr,
curl_socket_t *sockfd);
-void Curl_tcpnodelay(struct connectdata *conn, curl_socket_t sockfd);
-
/*
* Curl_conncontrol() marks the end of a connection/stream. The 'closeit'
* argument specifies if it is the end of a connection or a stream.
diff --git a/Utilities/cmcurl/lib/content_encoding.c b/Utilities/cmcurl/lib/content_encoding.c
index 652ed9764..6d4753788 100644
--- a/Utilities/cmcurl/lib/content_encoding.c
+++ b/Utilities/cmcurl/lib/content_encoding.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -22,22 +22,43 @@
#include "curl_setup.h"
-#ifdef HAVE_LIBZ
-
#include "urldata.h"
#include <curl/curl.h>
+#include <stddef.h>
+
+#ifdef HAVE_ZLIB_H
+#include <zlib.h>
+#ifdef __SYMBIAN32__
+/* zlib pollutes the namespace with this definition */
+#undef WIN32
+#endif
+#endif
+
+#ifdef HAVE_BROTLI
+#include <brotli/decode.h>
+#endif
+
#include "sendf.h"
+#include "http.h"
#include "content_encoding.h"
#include "strdup.h"
+#include "strcase.h"
#include "curl_memory.h"
#include "memdebug.h"
+#define CONTENT_ENCODING_DEFAULT "identity"
+
+#ifndef CURL_DISABLE_HTTP
+
+#define DSIZ CURL_MAX_WRITE_SIZE /* buffer size for decompressed data */
+
+
+#ifdef HAVE_LIBZ
+
/* 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 CURL_MAX_WRITE_SIZE /* buffer size for decompressed data */
-
#define GZIP_MAGIC_0 0x1f
#define GZIP_MAGIC_1 0x8b
@@ -49,6 +70,24 @@
#define COMMENT 0x10 /* bit 4 set: file comment present */
#define RESERVED 0xE0 /* bits 5..7: reserved */
+typedef enum {
+ ZLIB_UNINIT, /* uninitialized */
+ ZLIB_INIT, /* initialized */
+ ZLIB_INFLATING, /* inflating started. */
+ ZLIB_EXTERNAL_TRAILER, /* reading external trailer */
+ ZLIB_GZIP_HEADER, /* reading gzip header */
+ ZLIB_GZIP_INFLATING, /* inflating gzip stream */
+ ZLIB_INIT_GZIP /* initialized in transparent gzip mode */
+} zlibInitState;
+
+/* Writer parameters. */
+typedef struct {
+ zlibInitState zlib_init; /* zlib init state */
+ uInt trailerlen; /* Remaining trailer byte count. */
+ z_stream z; /* State structure for zlib. */
+} zlib_params;
+
+
static voidpf
zalloc_cb(voidpf opaque, unsigned int items, unsigned int size)
{
@@ -79,114 +118,233 @@ process_zlib_error(struct connectdata *conn, z_stream *z)
}
static CURLcode
-exit_zlib(z_stream *z, zlibInitState *zlib_init, CURLcode result)
+exit_zlib(struct connectdata *conn,
+ z_stream *z, zlibInitState *zlib_init, CURLcode result)
{
- inflateEnd(z);
- *zlib_init = ZLIB_UNINIT;
+ if(*zlib_init == ZLIB_GZIP_HEADER)
+ Curl_safefree(z->next_in);
+
+ if(*zlib_init != ZLIB_UNINIT) {
+ if(inflateEnd(z) != Z_OK && result == CURLE_OK)
+ result = process_zlib_error(conn, z);
+ *zlib_init = ZLIB_UNINIT;
+ }
+
return result;
}
-static CURLcode
-inflate_stream(struct connectdata *conn,
- struct SingleRequest *k)
+static CURLcode process_trailer(struct connectdata *conn, zlib_params *zp)
{
- int allow_restart = 1;
- z_stream *z = &k->z; /* zlib state structure */
+ z_stream *z = &zp->z;
+ CURLcode result = CURLE_OK;
+ uInt len = z->avail_in < zp->trailerlen? z->avail_in: zp->trailerlen;
+
+ /* Consume expected trailer bytes. Terminate stream if exhausted.
+ Issue an error if unexpected bytes follow. */
+
+ zp->trailerlen -= len;
+ z->avail_in -= len;
+ z->next_in += len;
+ if(z->avail_in)
+ result = CURLE_WRITE_ERROR;
+ if(result || !zp->trailerlen)
+ result = exit_zlib(conn, z, &zp->zlib_init, result);
+ else {
+ /* Only occurs for gzip with zlib < 1.2.0.4 or raw deflate. */
+ zp->zlib_init = ZLIB_EXTERNAL_TRAILER;
+ }
+ return result;
+}
+
+static CURLcode inflate_stream(struct connectdata *conn,
+ contenc_writer *writer, zlibInitState started)
+{
+ zlib_params *zp = (zlib_params *) &writer->params;
+ z_stream *z = &zp->z; /* zlib state structure */
uInt nread = z->avail_in;
Bytef *orig_in = z->next_in;
- int status; /* zlib status */
+ bool done = FALSE;
CURLcode result = CURLE_OK; /* Curl_client_write status */
char *decomp; /* Put the decompressed data here. */
+ /* Check state. */
+ if(zp->zlib_init != ZLIB_INIT &&
+ zp->zlib_init != ZLIB_INFLATING &&
+ zp->zlib_init != ZLIB_INIT_GZIP &&
+ zp->zlib_init != ZLIB_GZIP_INFLATING)
+ return exit_zlib(conn, z, &zp->zlib_init, CURLE_WRITE_ERROR);
+
/* Dynamically allocate a buffer for decompression because it's uncommonly
large to hold on the stack */
decomp = malloc(DSIZ);
- if(decomp == NULL) {
- return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
- }
+ if(decomp == NULL)
+ return exit_zlib(conn, z, &zp->zlib_init, CURLE_OUT_OF_MEMORY);
/* because the buffer size is fixed, iteratively decompress and transfer to
- the client via client_write. */
- for(;;) {
+ the client via downstream_write function. */
+ while(!done) {
+ int status; /* zlib status */
+ done = TRUE;
+
/* (re)set buffer for decompressed output for every iteration */
- z->next_out = (Bytef *)decomp;
+ z->next_out = (Bytef *) decomp;
z->avail_out = DSIZ;
+#ifdef Z_BLOCK
+ /* Z_BLOCK is only available in zlib ver. >= 1.2.0.5 */
+ status = inflate(z, Z_BLOCK);
+#else
+ /* fallback for zlib ver. < 1.2.0.5 */
status = inflate(z, Z_SYNC_FLUSH);
- if(status == Z_OK || status == Z_STREAM_END) {
- allow_restart = 0;
- if((DSIZ - z->avail_out) && (!k->ignorebody)) {
- result = Curl_client_write(conn, CLIENTWRITE_BODY, decomp,
- DSIZ - z->avail_out);
- /* if !CURLE_OK, clean up, return */
+#endif
+
+ /* Flush output data if some. */
+ if(z->avail_out != DSIZ) {
+ if(status == Z_OK || status == Z_STREAM_END) {
+ zp->zlib_init = started; /* Data started. */
+ result = Curl_unencode_write(conn, writer->downstream, decomp,
+ DSIZ - z->avail_out);
if(result) {
- free(decomp);
- return exit_zlib(z, &k->zlib_init, result);
+ exit_zlib(conn, z, &zp->zlib_init, result);
+ break;
}
}
-
- /* Done? clean up, return */
- if(status == Z_STREAM_END) {
- free(decomp);
- if(inflateEnd(z) == Z_OK)
- return exit_zlib(z, &k->zlib_init, result);
- return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
- }
-
- /* Done with these bytes, exit */
-
- /* status is always Z_OK at this point! */
- if(z->avail_in == 0) {
- free(decomp);
- return result;
- }
}
- else if(allow_restart && status == Z_DATA_ERROR) {
+
+ /* Dispatch by inflate() status. */
+ switch(status) {
+ case Z_OK:
+ /* Always loop: there may be unflushed latched data in zlib state. */
+ done = FALSE;
+ break;
+ case Z_BUF_ERROR:
+ /* No more data to flush: just exit loop. */
+ break;
+ case Z_STREAM_END:
+ result = process_trailer(conn, zp);
+ break;
+ case Z_DATA_ERROR:
/* some servers seem to not generate zlib headers, so this is an attempt
to fix and continue anyway */
-
- (void) inflateEnd(z); /* don't care about the return code */
- if(inflateInit2(z, -MAX_WBITS) != Z_OK) {
- free(decomp);
- return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
+ if(zp->zlib_init == ZLIB_INIT) {
+ /* Do not use inflateReset2(): only available since zlib 1.2.3.4. */
+ (void) inflateEnd(z); /* don't care about the return code */
+ if(inflateInit2(z, -MAX_WBITS) == Z_OK) {
+ z->next_in = orig_in;
+ z->avail_in = nread;
+ zp->zlib_init = ZLIB_INFLATING;
+ zp->trailerlen = 4; /* Tolerate up to 4 unknown trailer bytes. */
+ done = FALSE;
+ break;
+ }
+ zp->zlib_init = ZLIB_UNINIT; /* inflateEnd() already called. */
}
- 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));
+ /* FALLTHROUGH */
+ default:
+ result = exit_zlib(conn, z, &zp->zlib_init, process_zlib_error(conn, z));
+ break;
}
}
- /* Will never get here */
+ free(decomp);
+
+ /* We're about to leave this call so the `nread' data bytes won't be seen
+ again. If we are in a state that would wrongly allow restart in raw mode
+ at the next call, assume output has already started. */
+ if(nread && zp->zlib_init == ZLIB_INIT)
+ zp->zlib_init = started; /* Cannot restart anymore. */
+
+ return result;
}
-CURLcode
-Curl_unencode_deflate_write(struct connectdata *conn,
- struct SingleRequest *k,
- ssize_t nread)
+
+/* Deflate handler. */
+static CURLcode deflate_init_writer(struct connectdata *conn,
+ contenc_writer *writer)
{
- z_stream *z = &k->z; /* zlib state structure */
+ zlib_params *zp = (zlib_params *) &writer->params;
+ z_stream *z = &zp->z; /* zlib state structure */
- /* Initialize zlib? */
- if(k->zlib_init == ZLIB_UNINIT) {
- memset(z, 0, sizeof(z_stream));
- z->zalloc = (alloc_func)zalloc_cb;
- z->zfree = (free_func)zfree_cb;
+ if(!writer->downstream)
+ return CURLE_WRITE_ERROR;
- if(inflateInit(z) != Z_OK)
- return process_zlib_error(conn, z);
- k->zlib_init = ZLIB_INIT;
- }
+ /* Initialize zlib */
+ z->zalloc = (alloc_func) zalloc_cb;
+ z->zfree = (free_func) zfree_cb;
+
+ if(inflateInit(z) != Z_OK)
+ return process_zlib_error(conn, z);
+ zp->zlib_init = ZLIB_INIT;
+ return CURLE_OK;
+}
+
+static CURLcode deflate_unencode_write(struct connectdata *conn,
+ contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ zlib_params *zp = (zlib_params *) &writer->params;
+ z_stream *z = &zp->z; /* zlib state structure */
/* Set the compressed input when this function is called */
- z->next_in = (Bytef *)k->str;
- z->avail_in = (uInt)nread;
+ z->next_in = (Bytef *) buf;
+ z->avail_in = (uInt) nbytes;
+
+ if(zp->zlib_init == ZLIB_EXTERNAL_TRAILER)
+ return process_trailer(conn, zp);
/* Now uncompress the data */
- return inflate_stream(conn, k);
+ return inflate_stream(conn, writer, ZLIB_INFLATING);
+}
+
+static void deflate_close_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ zlib_params *zp = (zlib_params *) &writer->params;
+ z_stream *z = &zp->z; /* zlib state structure */
+
+ exit_zlib(conn, z, &zp->zlib_init, CURLE_OK);
+}
+
+static const content_encoding deflate_encoding = {
+ "deflate",
+ NULL,
+ deflate_init_writer,
+ deflate_unencode_write,
+ deflate_close_writer,
+ sizeof(zlib_params)
+};
+
+
+/* Gzip handler. */
+static CURLcode gzip_init_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ zlib_params *zp = (zlib_params *) &writer->params;
+ z_stream *z = &zp->z; /* zlib state structure */
+
+ if(!writer->downstream)
+ return CURLE_WRITE_ERROR;
+
+ /* Initialize zlib */
+ z->zalloc = (alloc_func) zalloc_cb;
+ z->zfree = (free_func) zfree_cb;
+
+ 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);
+ }
+ zp->zlib_init = ZLIB_INIT_GZIP; /* Transparent gzip decompress state */
+ }
+ else {
+ /* we must parse the gzip header and trailer ourselves */
+ if(inflateInit2(z, -MAX_WBITS) != Z_OK) {
+ return process_zlib_error(conn, z);
+ }
+ zp->trailerlen = 8; /* A CRC-32 and a 32-bit input size (RFC 1952, 2.2) */
+ zp->zlib_init = ZLIB_INIT; /* Initial call state */
+ }
+
+ return CURLE_OK;
}
#ifdef OLD_ZLIB_SUPPORT
@@ -227,7 +385,7 @@ static enum {
extra_len = (data[1] << 8) | data[0];
- if(len < (extra_len+2))
+ if(len < (extra_len + 2))
return GZIP_UNDERFLOW;
len -= (extra_len + 2);
@@ -273,47 +431,25 @@ static enum {
}
#endif
-CURLcode
-Curl_unencode_gzip_write(struct connectdata *conn,
- struct SingleRequest *k,
- ssize_t nread)
+static CURLcode gzip_unencode_write(struct connectdata *conn,
+ contenc_writer *writer,
+ const char *buf, size_t nbytes)
{
- z_stream *z = &k->z; /* zlib state structure */
-
- /* Initialize zlib? */
- if(k->zlib_init == ZLIB_UNINIT) {
- memset(z, 0, sizeof(z_stream));
- z->zalloc = (alloc_func)zalloc_cb;
- z->zfree = (free_func)zfree_cb;
+ zlib_params *zp = (zlib_params *) &writer->params;
+ z_stream *z = &zp->z; /* zlib state structure */
- 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) {
+ if(zp->zlib_init == ZLIB_INIT_GZIP) {
/* Let zlib handle the gzip decompression entirely */
- z->next_in = (Bytef *)k->str;
- z->avail_in = (uInt)nread;
+ z->next_in = (Bytef *) buf;
+ z->avail_in = (uInt) nbytes;
/* Now uncompress the data */
- return inflate_stream(conn, k);
+ return inflate_stream(conn, writer, ZLIB_INIT_GZIP);
}
#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_WRITE_ERROR);
+ return exit_zlib(conn, z, &zp->zlib_init, CURLE_WRITE_ERROR);
#else
/* This next mess is to get around the potential case where there isn't
@@ -326,18 +462,18 @@ Curl_unencode_gzip_write(struct connectdata *conn,
* can handle the gzip header themselves.
*/
- switch(k->zlib_init) {
+ switch(zp->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)) {
+ switch(check_gzip_header((unsigned char *) buf, nbytes, &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 */
+ z->next_in = (Bytef *) buf + hlen;
+ z->avail_in = (uInt) (nbytes - hlen);
+ zp->zlib_init = ZLIB_GZIP_INFLATING; /* Inflating stream state */
break;
case GZIP_UNDERFLOW:
@@ -348,19 +484,19 @@ Curl_unencode_gzip_write(struct connectdata *conn,
* 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->avail_in = (uInt) nbytes;
z->next_in = malloc(z->avail_in);
if(z->next_in == NULL) {
- return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
+ return exit_zlib(conn, z, &zp->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 */
+ memcpy(z->next_in, buf, z->avail_in);
+ zp->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));
+ return exit_zlib(conn, z, &zp->zlib_init, process_zlib_error(conn, z));
}
}
@@ -370,22 +506,22 @@ Curl_unencode_gzip_write(struct connectdata *conn,
{
/* Need more gzip header data state */
ssize_t hlen;
- z->avail_in += (uInt)nread;
+ z->avail_in += (uInt) nbytes;
z->next_in = Curl_saferealloc(z->next_in, z->avail_in);
if(z->next_in == NULL) {
- return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
+ return exit_zlib(conn, z, &zp->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);
+ memcpy(z->next_in + z->avail_in - nbytes, buf, nbytes);
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 */
+ z->next_in = (Bytef *) buf + hlen + nbytes - z->avail_in;
+ z->avail_in = (uInt) (z->avail_in - hlen);
+ zp->zlib_init = ZLIB_GZIP_INFLATING; /* Inflating stream state */
break;
case GZIP_UNDERFLOW:
@@ -394,18 +530,22 @@ Curl_unencode_gzip_write(struct connectdata *conn,
case GZIP_BAD:
default:
- free(z->next_in);
- return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
+ return exit_zlib(conn, z, &zp->zlib_init, process_zlib_error(conn, z));
}
}
break;
+ case ZLIB_EXTERNAL_TRAILER:
+ z->next_in = (Bytef *) buf;
+ z->avail_in = (uInt) nbytes;
+ return process_trailer(conn, zp);
+
case ZLIB_GZIP_INFLATING:
default:
/* Inflating stream state */
- z->next_in = (Bytef *)k->str;
- z->avail_in = (uInt)nread;
+ z->next_in = (Bytef *) buf;
+ z->avail_in = (uInt) nbytes;
break;
}
@@ -415,17 +555,466 @@ Curl_unencode_gzip_write(struct connectdata *conn,
}
/* We've parsed the header, now uncompress the data */
- return inflate_stream(conn, k);
+ return inflate_stream(conn, writer, ZLIB_GZIP_INFLATING);
+#endif
+}
+
+static void gzip_close_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ zlib_params *zp = (zlib_params *) &writer->params;
+ z_stream *z = &zp->z; /* zlib state structure */
+
+ exit_zlib(conn, z, &zp->zlib_init, CURLE_OK);
+}
+
+static const content_encoding gzip_encoding = {
+ "gzip",
+ "x-gzip",
+ gzip_init_writer,
+ gzip_unencode_write,
+ gzip_close_writer,
+ sizeof(zlib_params)
+};
+
+#endif /* HAVE_LIBZ */
+
+
+#ifdef HAVE_BROTLI
+
+/* Writer parameters. */
+typedef struct {
+ BrotliDecoderState *br; /* State structure for brotli. */
+} brotli_params;
+
+
+static CURLcode brotli_map_error(BrotliDecoderErrorCode be)
+{
+ switch(be) {
+ case BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:
+ case BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:
+ case BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:
+ case BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:
+ case BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:
+ case BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:
+ case BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:
+ case BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:
+ case BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:
+ case BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:
+ case BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:
+ case BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:
+ case BROTLI_DECODER_ERROR_FORMAT_PADDING_1:
+ case BROTLI_DECODER_ERROR_FORMAT_PADDING_2:
+#ifdef BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY
+ case BROTLI_DECODER_ERROR_COMPOUND_DICTIONARY:
#endif
+#ifdef BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET
+ case BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:
+#endif
+ case BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:
+ return CURLE_BAD_CONTENT_ENCODING;
+ case BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:
+ case BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:
+ case BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:
+ case BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:
+ case BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:
+ case BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:
+ return CURLE_OUT_OF_MEMORY;
+ default:
+ break;
+ }
+ return CURLE_WRITE_ERROR;
+}
+
+static CURLcode brotli_init_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ brotli_params *bp = (brotli_params *) &writer->params;
+
+ (void) conn;
+
+ if(!writer->downstream)
+ return CURLE_WRITE_ERROR;
+
+ bp->br = BrotliDecoderCreateInstance(NULL, NULL, NULL);
+ return bp->br? CURLE_OK: CURLE_OUT_OF_MEMORY;
}
+static CURLcode brotli_unencode_write(struct connectdata *conn,
+ contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ brotli_params *bp = (brotli_params *) &writer->params;
+ const uint8_t *src = (const uint8_t *) buf;
+ char *decomp;
+ uint8_t *dst;
+ size_t dstleft;
+ CURLcode result = CURLE_OK;
+ BrotliDecoderResult r = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT;
+
+ if(!bp->br)
+ return CURLE_WRITE_ERROR; /* Stream already ended. */
+
+ decomp = malloc(DSIZ);
+ if(!decomp)
+ return CURLE_OUT_OF_MEMORY;
+
+ while((nbytes || r == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) &&
+ result == CURLE_OK) {
+ dst = (uint8_t *) decomp;
+ dstleft = DSIZ;
+ r = BrotliDecoderDecompressStream(bp->br,
+ &nbytes, &src, &dstleft, &dst, NULL);
+ result = Curl_unencode_write(conn, writer->downstream,
+ decomp, DSIZ - dstleft);
+ if(result)
+ break;
+ switch(r) {
+ case BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:
+ case BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:
+ break;
+ case BROTLI_DECODER_RESULT_SUCCESS:
+ BrotliDecoderDestroyInstance(bp->br);
+ bp->br = NULL;
+ if(nbytes)
+ result = CURLE_WRITE_ERROR;
+ break;
+ default:
+ result = brotli_map_error(BrotliDecoderGetErrorCode(bp->br));
+ break;
+ }
+ }
+ free(decomp);
+ return result;
+}
+
+static void brotli_close_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ brotli_params *bp = (brotli_params *) &writer->params;
+
+ (void) conn;
+
+ if(bp->br) {
+ BrotliDecoderDestroyInstance(bp->br);
+ bp->br = NULL;
+ }
+}
+
+static const content_encoding brotli_encoding = {
+ "br",
+ NULL,
+ brotli_init_writer,
+ brotli_unencode_write,
+ brotli_close_writer,
+ sizeof(brotli_params)
+};
+#endif
+
+
+/* Identity handler. */
+static CURLcode identity_init_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ (void) conn;
+ return writer->downstream? CURLE_OK: CURLE_WRITE_ERROR;
+}
+
+static CURLcode identity_unencode_write(struct connectdata *conn,
+ contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ return Curl_unencode_write(conn, writer->downstream, buf, nbytes);
+}
+
+static void identity_close_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ (void) conn;
+ (void) writer;
+}
+
+static const content_encoding identity_encoding = {
+ "identity",
+ "none",
+ identity_init_writer,
+ identity_unencode_write,
+ identity_close_writer,
+ 0
+};
+
+
+/* supported content encodings table. */
+static const content_encoding * const encodings[] = {
+ &identity_encoding,
+#ifdef HAVE_LIBZ
+ &deflate_encoding,
+ &gzip_encoding,
+#endif
+#ifdef HAVE_BROTLI
+ &brotli_encoding,
+#endif
+ NULL
+};
+
+
+/* Return a list of comma-separated names of supported encodings. */
+char *Curl_all_content_encodings(void)
+{
+ size_t len = 0;
+ const content_encoding * const *cep;
+ const content_encoding *ce;
+ char *ace;
+
+ for(cep = encodings; *cep; cep++) {
+ ce = *cep;
+ if(!strcasecompare(ce->name, CONTENT_ENCODING_DEFAULT))
+ len += strlen(ce->name) + 2;
+ }
+
+ if(!len)
+ return strdup(CONTENT_ENCODING_DEFAULT);
+
+ ace = malloc(len);
+ if(ace) {
+ char *p = ace;
+ for(cep = encodings; *cep; cep++) {
+ ce = *cep;
+ if(!strcasecompare(ce->name, CONTENT_ENCODING_DEFAULT)) {
+ strcpy(p, ce->name);
+ p += strlen(p);
+ *p++ = ',';
+ *p++ = ' ';
+ }
+ }
+ p[-2] = '\0';
+ }
+
+ return ace;
+}
+
+
+/* Real client writer: no downstream. */
+static CURLcode client_init_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ (void) conn;
+ return writer->downstream? CURLE_WRITE_ERROR: CURLE_OK;
+}
+
+static CURLcode client_unencode_write(struct connectdata *conn,
+ contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ struct Curl_easy *data = conn->data;
+ struct SingleRequest *k = &data->req;
+
+ (void) writer;
+
+ if(!nbytes || k->ignorebody)
+ return CURLE_OK;
+
+ return Curl_client_write(conn, CLIENTWRITE_BODY, (char *) buf, nbytes);
+}
+
+static void client_close_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ (void) conn;
+ (void) writer;
+}
+
+static const content_encoding client_encoding = {
+ NULL,
+ NULL,
+ client_init_writer,
+ client_unencode_write,
+ client_close_writer,
+ 0
+};
+
+
+/* Deferred error dummy writer. */
+static CURLcode error_init_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ (void) conn;
+ return writer->downstream? CURLE_OK: CURLE_WRITE_ERROR;
+}
+
+static CURLcode error_unencode_write(struct connectdata *conn,
+ contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ char *all = Curl_all_content_encodings();
+
+ (void) writer;
+ (void) buf;
+ (void) nbytes;
+
+ if(!all)
+ return CURLE_OUT_OF_MEMORY;
+ failf(conn->data, "Unrecognized content encoding type. "
+ "libcurl understands %s content encodings.", all);
+ free(all);
+ return CURLE_BAD_CONTENT_ENCODING;
+}
+
+static void error_close_writer(struct connectdata *conn,
+ contenc_writer *writer)
+{
+ (void) conn;
+ (void) writer;
+}
+
+static const content_encoding error_encoding = {
+ NULL,
+ NULL,
+ error_init_writer,
+ error_unencode_write,
+ error_close_writer,
+ 0
+};
+
+/* Create an unencoding writer stage using the given handler. */
+static contenc_writer *new_unencoding_writer(struct connectdata *conn,
+ const content_encoding *handler,
+ contenc_writer *downstream)
+{
+ size_t sz = offsetof(contenc_writer, params) + handler->paramsize;
+ contenc_writer *writer = (contenc_writer *) calloc(1, sz);
+
+ if(writer) {
+ writer->handler = handler;
+ writer->downstream = downstream;
+ if(handler->init_writer(conn, writer)) {
+ free(writer);
+ writer = NULL;
+ }
+ }
+
+ return writer;
+}
+
+/* Write data using an unencoding writer stack. */
+CURLcode Curl_unencode_write(struct connectdata *conn, contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ if(!nbytes)
+ return CURLE_OK;
+ return writer->handler->unencode_write(conn, writer, buf, nbytes);
+}
+
+/* Close and clean-up the connection's writer stack. */
void Curl_unencode_cleanup(struct connectdata *conn)
{
struct Curl_easy *data = conn->data;
struct SingleRequest *k = &data->req;
- z_stream *z = &k->z;
- if(k->zlib_init != ZLIB_UNINIT)
- (void) exit_zlib(z, &k->zlib_init, CURLE_OK);
+ contenc_writer *writer = k->writer_stack;
+
+ while(writer) {
+ k->writer_stack = writer->downstream;
+ writer->handler->close_writer(conn, writer);
+ free(writer);
+ writer = k->writer_stack;
+ }
}
-#endif /* HAVE_LIBZ */
+/* Find the content encoding by name. */
+static const content_encoding *find_encoding(const char *name, size_t len)
+{
+ const content_encoding * const *cep;
+
+ for(cep = encodings; *cep; cep++) {
+ const content_encoding *ce = *cep;
+ if((strncasecompare(name, ce->name, len) && !ce->name[len]) ||
+ (ce->alias && strncasecompare(name, ce->alias, len) && !ce->alias[len]))
+ return ce;
+ }
+ return NULL;
+}
+
+/* Set-up the unencoding stack from the Content-Encoding header value.
+ * See RFC 7231 section 3.1.2.2. */
+CURLcode Curl_build_unencoding_stack(struct connectdata *conn,
+ const char *enclist, int maybechunked)
+{
+ struct Curl_easy *data = conn->data;
+ struct SingleRequest *k = &data->req;
+
+ do {
+ const char *name;
+ size_t namelen;
+
+ /* Parse a single encoding name. */
+ while(ISSPACE(*enclist) || *enclist == ',')
+ enclist++;
+
+ name = enclist;
+
+ for(namelen = 0; *enclist && *enclist != ','; enclist++)
+ if(!ISSPACE(*enclist))
+ namelen = enclist - name + 1;
+
+ /* Special case: chunked encoding is handled at the reader level. */
+ if(maybechunked && namelen == 7 && strncasecompare(name, "chunked", 7)) {
+ k->chunk = TRUE; /* chunks coming our way. */
+ Curl_httpchunk_init(conn); /* init our chunky engine. */
+ }
+ else if(namelen) {
+ const content_encoding *encoding = find_encoding(name, namelen);
+ contenc_writer *writer;
+
+ if(!k->writer_stack) {
+ k->writer_stack = new_unencoding_writer(conn, &client_encoding, NULL);
+
+ if(!k->writer_stack)
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if(!encoding)
+ encoding = &error_encoding; /* Defer error at stack use. */
+
+ /* Stack the unencoding stage. */
+ writer = new_unencoding_writer(conn, encoding, k->writer_stack);
+ if(!writer)
+ return CURLE_OUT_OF_MEMORY;
+ k->writer_stack = writer;
+ }
+ } while(*enclist);
+
+ return CURLE_OK;
+}
+
+#else
+/* Stubs for builds without HTTP. */
+CURLcode Curl_build_unencoding_stack(struct connectdata *conn,
+ const char *enclist, int maybechunked)
+{
+ (void) conn;
+ (void) enclist;
+ (void) maybechunked;
+ return CURLE_NOT_BUILT_IN;
+}
+
+CURLcode Curl_unencode_write(struct connectdata *conn, contenc_writer *writer,
+ const char *buf, size_t nbytes)
+{
+ (void) conn;
+ (void) writer;
+ (void) buf;
+ (void) nbytes;
+ return CURLE_NOT_BUILT_IN;
+}
+
+void Curl_unencode_cleanup(struct connectdata *conn)
+{
+ (void) conn;
+}
+
+char *Curl_all_content_encodings(void)
+{
+ return strdup(CONTENT_ENCODING_DEFAULT); /* Satisfy caller. */
+}
+
+#endif /* CURL_DISABLE_HTTP */
diff --git a/Utilities/cmcurl/lib/content_encoding.h b/Utilities/cmcurl/lib/content_encoding.h
index 3fadd2899..4cd52be62 100644
--- a/Utilities/cmcurl/lib/content_encoding.h
+++ b/Utilities/cmcurl/lib/content_encoding.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -23,26 +23,33 @@
***************************************************************************/
#include "curl_setup.h"
-/*
- * Comma-separated list all supported Content-Encodings ('identity' is implied)
- */
-#ifdef HAVE_LIBZ
-#define ALL_CONTENT_ENCODINGS "deflate, gzip"
-/* force a cleanup */
-void Curl_unencode_cleanup(struct connectdata *conn);
-#else
-#define ALL_CONTENT_ENCODINGS "identity"
-#define Curl_unencode_cleanup(x) Curl_nop_stmt
-#endif
+/* Decoding writer. */
+typedef struct contenc_writer_s contenc_writer;
+typedef struct content_encoding_s content_encoding;
+
+struct contenc_writer_s {
+ const content_encoding *handler; /* Encoding handler. */
+ contenc_writer *downstream; /* Downstream writer. */
+ void *params; /* Encoding-specific storage (variable length). */
+};
-CURLcode Curl_unencode_deflate_write(struct connectdata *conn,
- struct SingleRequest *req,
- ssize_t nread);
+/* Content encoding writer. */
+struct content_encoding_s {
+ const char *name; /* Encoding name. */
+ const char *alias; /* Encoding name alias. */
+ CURLcode (*init_writer)(struct connectdata *conn, contenc_writer *writer);
+ CURLcode (*unencode_write)(struct connectdata *conn, contenc_writer *writer,
+ const char *buf, size_t nbytes);
+ void (*close_writer)(struct connectdata *conn, contenc_writer *writer);
+ size_t paramsize;
+};
-CURLcode
-Curl_unencode_gzip_write(struct connectdata *conn,
- struct SingleRequest *k,
- ssize_t nread);
+CURLcode Curl_build_unencoding_stack(struct connectdata *conn,
+ const char *enclist, int maybechunked);
+CURLcode Curl_unencode_write(struct connectdata *conn, contenc_writer *writer,
+ const char *buf, size_t nbytes);
+void Curl_unencode_cleanup(struct connectdata *conn);
+char *Curl_all_content_encodings(void);
#endif /* HEADER_CURL_CONTENT_ENCODING_H */
diff --git a/Utilities/cmcurl/lib/cookie.c b/Utilities/cmcurl/lib/cookie.c
index 6b678aeb8..9a9e14d01 100644
--- a/Utilities/cmcurl/lib/cookie.c
+++ b/Utilities/cmcurl/lib/cookie.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -40,7 +40,7 @@ struct Cookie *Curl_cookie_add(struct Curl_easy *data,
received from a server.
The function need to replace previously stored lines that this new
- line superceeds.
+ line supersedes.
It may remove lines that are expired.
@@ -84,18 +84,16 @@ Example set of cookies:
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
-#ifdef USE_LIBPSL
-# include <libpsl.h>
-#endif
-
#include "urldata.h"
#include "cookie.h"
+#include "psl.h"
#include "strtok.h"
#include "sendf.h"
#include "slist.h"
#include "share.h"
#include "strtoofft.h"
#include "strcase.h"
+#include "curl_get_line.h"
#include "curl_memrchr.h"
#include "inet_pton.h"
@@ -125,7 +123,7 @@ static bool tailmatch(const char *cooke_domain, const char *hostname)
if(hostname_len < cookie_domain_len)
return FALSE;
- if(!strcasecompare(cooke_domain, hostname+hostname_len-cookie_domain_len))
+ if(!strcasecompare(cooke_domain, hostname + hostname_len-cookie_domain_len))
return FALSE;
/* A lead char of cookie_domain is not '.'.
@@ -143,6 +141,28 @@ static bool tailmatch(const char *cooke_domain, const char *hostname)
}
/*
+ * Return true if the given string is an IP(v4|v6) address.
+ */
+static bool isip(const char *domain)
+{
+ struct in_addr addr;
+#ifdef ENABLE_IPV6
+ struct in6_addr addr6;
+#endif
+
+ if(Curl_inet_pton(AF_INET, domain, &addr)
+#ifdef ENABLE_IPV6
+ || Curl_inet_pton(AF_INET6, domain, &addr6)
+#endif
+ ) {
+ /* domain name given as IP address */
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*
* matching cookie path and url path
* RFC6265 5.1.4 Paths and Path-Match
*/
@@ -204,7 +224,7 @@ static bool pathmatch(const char *cookie_path, const char *request_uri)
goto pathmatched;
}
- /* here, cookie_path_len < url_path_len */
+ /* here, cookie_path_len < uri_path_len */
if(uri_path[cookie_path_len] == '/') {
ret = TRUE;
goto pathmatched;
@@ -218,6 +238,62 @@ pathmatched:
}
/*
+ * Return the top-level domain, for optimal hashing.
+ */
+static const char *get_top_domain(const char * const domain, size_t *outlen)
+{
+ size_t len;
+ const char *first = NULL, *last;
+
+ if(!domain)
+ return NULL;
+
+ len = strlen(domain);
+ last = memrchr(domain, '.', len);
+ if(last) {
+ first = memrchr(domain, '.', (last - domain));
+ if(first)
+ len -= (++first - domain);
+ }
+
+ if(outlen)
+ *outlen = len;
+
+ return first? first: domain;
+}
+
+/*
+ * A case-insensitive hash for the cookie domains.
+ */
+static size_t cookie_hash_domain(const char *domain, const size_t len)
+{
+ const char *end = domain + len;
+ size_t h = 5381;
+
+ while(domain < end) {
+ h += h << 5;
+ h ^= Curl_raw_toupper(*domain++);
+ }
+
+ return (h % COOKIE_HASH_SIZE);
+}
+
+/*
+ * Hash this domain.
+ */
+static size_t cookiehash(const char * const domain)
+{
+ const char *top;
+ size_t len;
+
+ if(!domain || isip(domain))
+ return 0;
+
+ top = get_top_domain(domain, &len);
+ return cookie_hash_domain(top, len);
+}
+
+/*
* cookie path sanitize
*/
static char *sanitize_cookie_path(const char *cookie_path)
@@ -301,50 +377,37 @@ static void strstore(char **str, const char *newstr)
*/
static void remove_expired(struct CookieInfo *cookies)
{
- struct Cookie *co, *nx, *pv;
+ struct Cookie *co, *nx;
curl_off_t now = (curl_off_t)time(NULL);
-
- co = cookies->cookies;
- pv = NULL;
- while(co) {
- nx = co->next;
- if(co->expires && co->expires < now) {
- if(co == cookies->cookies) {
- cookies->cookies = co->next;
+ unsigned int i;
+
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ struct Cookie *pv = NULL;
+ co = cookies->cookies[i];
+ while(co) {
+ nx = co->next;
+ if(co->expires && co->expires < now) {
+ if(!pv) {
+ cookies->cookies[i] = co->next;
+ }
+ else {
+ pv->next = co->next;
+ }
+ cookies->numcookies--;
+ freecookie(co);
}
else {
- pv->next = co->next;
+ pv = co;
}
- cookies->numcookies--;
- freecookie(co);
- }
- else {
- pv = co;
+ co = nx;
}
- co = nx;
}
}
-/*
- * Return true if the given string is an IP(v4|v6) address.
- */
-static bool isip(const char *domain)
+/* Make sure domain contains a dot or is localhost. */
+static bool bad_domain(const char *domain)
{
- struct in_addr addr;
-#ifdef ENABLE_IPV6
- struct in6_addr addr6;
-#endif
-
- if(Curl_inet_pton(AF_INET, domain, &addr)
-#ifdef ENABLE_IPV6
- || Curl_inet_pton(AF_INET6, domain, &addr6)
-#endif
- ) {
- /* domain name given as IP address */
- return TRUE;
- }
-
- return FALSE;
+ return !strchr(domain, '.') && !strcasecompare(domain, "localhost");
}
/****************************************************************************
@@ -368,23 +431,21 @@ Curl_cookie_add(struct Curl_easy *data,
struct CookieInfo *c,
bool httpheader, /* TRUE if HTTP header-style line */
+ bool noexpire, /* if TRUE, skip remove_expired() */
char *lineptr, /* first character of the line */
const char *domain, /* default domain */
- const char *path) /* full path used when this cookie is set,
+ const char *path, /* full path used when this cookie is set,
used to get default path for the cookie
unless set */
+ bool secure) /* TRUE if connection is over secure origin */
{
struct Cookie *clist;
- char name[MAX_NAME];
struct Cookie *co;
- struct Cookie *lastc=NULL;
+ struct Cookie *lastc = NULL;
time_t now = time(NULL);
bool replace_old = FALSE;
bool badcookie = FALSE; /* cookies are good by default. mmmmm yummy */
-
-#ifdef USE_LIBPSL
- const psl_ctx_t *psl;
-#endif
+ size_t myhash;
#ifdef CURL_DISABLE_VERBOSE_STRINGS
(void)data;
@@ -397,17 +458,19 @@ Curl_cookie_add(struct Curl_easy *data,
if(httpheader) {
/* This line was read off a HTTP-header */
+ char name[MAX_NAME];
+ char what[MAX_NAME];
const char *ptr;
const char *semiptr;
- char *what;
- what = malloc(MAX_COOKIE_LINE);
- if(!what) {
+ size_t linelength = strlen(lineptr);
+ if(linelength > MAX_COOKIE_LINE) {
+ /* discard overly long lines at once */
free(co);
return NULL;
}
- semiptr=strchr(lineptr, ';'); /* first, find a semicolon */
+ semiptr = strchr(lineptr, ';'); /* first, find a semicolon */
while(*lineptr && ISBLANK(*lineptr))
lineptr++;
@@ -415,9 +478,9 @@ Curl_cookie_add(struct Curl_easy *data,
ptr = lineptr;
do {
/* we have a <what>=<this> pair or a stand-alone word here */
- name[0]=what[0]=0; /* init the buffers */
+ name[0] = what[0] = 0; /* init the buffers */
if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^;\r\n=] =%"
- MAX_COOKIE_LINE_TXT "[^;\r\n]",
+ MAX_NAME_TXT "[^;\r\n]",
name, what)) {
/* Use strstore() below to properly deal with received cookie
headers that have the same string property set more than once,
@@ -425,10 +488,21 @@ Curl_cookie_add(struct Curl_easy *data,
const char *whatptr;
bool done = FALSE;
bool sep;
- size_t len=strlen(what);
+ size_t len = strlen(what);
size_t nlen = strlen(name);
const char *endofn = &ptr[ nlen ];
+ if(nlen >= (MAX_NAME-1) || len >= (MAX_NAME-1) ||
+ ((nlen + len) > MAX_NAME)) {
+ /* too long individual name or contents, or too long combination of
+ name + contents. Chrome and Firefox support 4095 or 4096 bytes
+ combo. */
+ freecookie(co);
+ infof(data, "oversized cookie dropped, name/val %zu + %zu bytes\n",
+ nlen, len);
+ return NULL;
+ }
+
/* name ends with a '=' ? */
sep = (*endofn == '=')?TRUE:FALSE;
@@ -440,25 +514,44 @@ Curl_cookie_add(struct Curl_easy *data,
endofn--;
nlen--;
}
- name[nlen]=0; /* new end of name */
+ name[nlen] = 0; /* new end of name */
}
}
/* Strip off trailing whitespace from the 'what' */
while(len && ISBLANK(what[len-1])) {
- what[len-1]=0;
+ what[len-1] = 0;
len--;
}
/* Skip leading whitespace from the 'what' */
- whatptr=what;
+ whatptr = what;
while(*whatptr && ISBLANK(*whatptr))
whatptr++;
- if(!co->name && sep) {
+ /*
+ * Check if we have a reserved prefix set before anything else, as we
+ * otherwise have to test for the prefix in both the cookie name and
+ * "the rest". Prefixes must start with '__' and end with a '-', so
+ * only test for names where that can possibly be true.
+ */
+ if(nlen > 3 && name[0] == '_' && name[1] == '_') {
+ if(strncasecompare("__Secure-", name, 9))
+ co->prefix |= COOKIE_PREFIX__SECURE;
+ else if(strncasecompare("__Host-", name, 7))
+ co->prefix |= COOKIE_PREFIX__HOST;
+ }
+
+ if(!co->name) {
/* The very first name/value pair is the actual cookie name */
+ if(!sep) {
+ /* Bad name/value pair. */
+ badcookie = TRUE;
+ break;
+ }
co->name = strdup(name);
co->value = strdup(whatptr);
+ done = TRUE;
if(!co->name || !co->value) {
badcookie = TRUE;
break;
@@ -468,8 +561,20 @@ Curl_cookie_add(struct Curl_easy *data,
/* this was a "<name>=" with no content, and we must allow
'secure' and 'httponly' specified this weirdly */
done = TRUE;
- if(strcasecompare("secure", name))
- co->secure = TRUE;
+ /*
+ * secure cookies are only allowed to be set when the connection is
+ * using a secure protocol, or when the cookie is being set by
+ * reading from file
+ */
+ if(strcasecompare("secure", name)) {
+ if(secure || !c->running) {
+ co->secure = TRUE;
+ }
+ else {
+ badcookie = TRUE;
+ break;
+ }
+ }
else if(strcasecompare("httponly", name))
co->httponly = TRUE;
else if(sep)
@@ -484,6 +589,7 @@ Curl_cookie_add(struct Curl_easy *data,
badcookie = TRUE; /* out of memory bad */
break;
}
+ free(co->spath); /* if this is set again */
co->spath = sanitize_cookie_path(co->path);
if(!co->spath) {
badcookie = TRUE; /* out of memory bad */
@@ -505,13 +611,8 @@ Curl_cookie_add(struct Curl_easy *data,
* TLD or otherwise "protected" suffix. To reduce risk, we require a
* dot OR the exact host name being "localhost".
*/
- {
- const char *dotp;
- /* check for more dots */
- dotp = strchr(whatptr, '.');
- if(!dotp && !strcasecompare("localhost", whatptr))
- domain=":";
- }
+ if(bad_domain(whatptr))
+ domain = ":";
#endif
is_ip = isip(domain ? domain : whatptr);
@@ -525,14 +626,14 @@ Curl_cookie_add(struct Curl_easy *data,
break;
}
if(!is_ip)
- co->tailmatch=TRUE; /* we always do that if the domain name was
- given */
+ 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;
+ badcookie = TRUE;
infof(data, "skipped cookie with bad tailmatch domain: %s\n",
whatptr);
}
@@ -581,26 +682,35 @@ Curl_cookie_add(struct Curl_easy *data,
continue;
}
- ptr=semiptr+1;
+ ptr = semiptr + 1;
while(*ptr && ISBLANK(*ptr))
ptr++;
- semiptr=strchr(ptr, ';'); /* now, find the next semicolon */
+ 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');
+ semiptr = strchr(ptr, '\0');
} while(semiptr);
if(co->maxage) {
- co->expires =
- curlx_strtoofft((*co->maxage=='\"')?
- &co->maxage[1]:&co->maxage[0], NULL, 10);
- if(CURL_OFF_T_MAX - now < co->expires)
- /* avoid overflow */
+ CURLofft offt;
+ offt = curlx_strtoofft((*co->maxage == '\"')?
+ &co->maxage[1]:&co->maxage[0], NULL, 10,
+ &co->expires);
+ if(offt == CURL_OFFT_FLOW)
+ /* overflow, used max value */
co->expires = CURL_OFF_T_MAX;
- else
- co->expires += now;
+ else if(!offt) {
+ if(!co->expires)
+ /* already expired */
+ co->expires = 1;
+ else if(CURL_OFF_T_MAX - now < co->expires)
+ /* would overflow */
+ co->expires = CURL_OFF_T_MAX;
+ else
+ co->expires += now;
+ }
}
else if(co->expirestr) {
/* Note that if the date couldn't get parsed for whatever reason,
@@ -619,7 +729,7 @@ Curl_cookie_add(struct Curl_easy *data,
if(!badcookie && !co->domain) {
if(domain) {
/* no domain was given in the header line, set the default */
- co->domain=strdup(domain);
+ co->domain = strdup(domain);
if(!co->domain)
badcookie = TRUE;
}
@@ -637,13 +747,13 @@ Curl_cookie_add(struct Curl_easy *data,
if(!queryp)
endslash = strrchr(path, '/');
else
- endslash = memrchr(path, '/', (size_t)(queryp - path));
+ endslash = memrchr(path, '/', (queryp - path));
if(endslash) {
- size_t pathlen = (size_t)(endslash-path+1); /* include ending slash */
- co->path=malloc(pathlen+1); /* one extra for the zero byte */
+ size_t pathlen = (endslash-path + 1); /* include end 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 */
+ co->path[pathlen] = 0; /* zero terminate */
co->spath = sanitize_cookie_path(co->path);
if(!co->spath)
badcookie = TRUE; /* out of memory bad */
@@ -653,8 +763,6 @@ Curl_cookie_add(struct Curl_easy *data,
}
}
- free(what);
-
if(badcookie || !co->name) {
/* we didn't get a cookie name or a bad one,
this is an illegal line, bail out */
@@ -668,7 +776,7 @@ Curl_cookie_add(struct Curl_easy *data,
reading the odd netscape cookies-file format here */
char *ptr;
char *firstptr;
- char *tok_buf=NULL;
+ char *tok_buf = NULL;
int fields;
/* IE introduced HTTP-only cookies to prevent XSS attacks. Cookies
@@ -689,19 +797,19 @@ Curl_cookie_add(struct Curl_easy *data,
return NULL;
}
/* strip off the possible end-of-line characters */
- ptr=strchr(lineptr, '\r');
+ ptr = strchr(lineptr, '\r');
if(ptr)
- *ptr=0; /* clear it */
- ptr=strchr(lineptr, '\n');
+ *ptr = 0; /* clear it */
+ ptr = strchr(lineptr, '\n');
if(ptr)
- *ptr=0; /* clear it */
+ *ptr = 0; /* clear it */
- firstptr=strtok_r(lineptr, "\t", &tok_buf); /* tokenize it on the TAB */
+ firstptr = strtok_r(lineptr, "\t", &tok_buf); /* tokenize it on the TAB */
/* 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++) {
+ for(ptr = firstptr, fields = 0; ptr && !badcookie;
+ ptr = strtok_r(NULL, "\t", &tok_buf), fields++) {
switch(fields) {
case 0:
if(ptr[0]=='.') /* skip preceding dots */
@@ -712,7 +820,7 @@ Curl_cookie_add(struct Curl_easy *data,
break;
case 1:
/* This field got its explanation on the 23rd of May 2001 by
- Andrés García:
+ 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
@@ -726,7 +834,7 @@ Curl_cookie_add(struct Curl_easy *data,
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... */
+ 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);
@@ -750,15 +858,29 @@ Curl_cookie_add(struct Curl_easy *data,
fields++; /* add a field and fall down to secure */
/* FALLTHROUGH */
case 3:
- co->secure = strcasecompare(ptr, "TRUE")?TRUE:FALSE;
+ co->secure = FALSE;
+ if(strcasecompare(ptr, "TRUE")) {
+ if(secure || c->running)
+ co->secure = TRUE;
+ else
+ badcookie = TRUE;
+ }
break;
case 4:
- co->expires = curlx_strtoofft(ptr, NULL, 10);
+ if(curlx_strtoofft(ptr, NULL, 10, &co->expires))
+ badcookie = TRUE;
break;
case 5:
co->name = strdup(ptr);
if(!co->name)
badcookie = TRUE;
+ else {
+ /* For Netscape file format cookies we check prefix on the name */
+ if(strncasecompare("__Secure-", co->name, 9))
+ co->prefix |= COOKIE_PREFIX__SECURE;
+ else if(strncasecompare("__Host-", co->name, 7))
+ co->prefix |= COOKIE_PREFIX__HOST;
+ }
break;
case 6:
co->value = strdup(ptr);
@@ -787,6 +909,26 @@ Curl_cookie_add(struct Curl_easy *data,
}
+ if(co->prefix & COOKIE_PREFIX__SECURE) {
+ /* The __Secure- prefix only requires that the cookie be set secure */
+ if(!co->secure) {
+ freecookie(co);
+ return NULL;
+ }
+ }
+ if(co->prefix & COOKIE_PREFIX__HOST) {
+ /*
+ * The __Host- prefix requires the cookie to be secure, have a "/" path
+ * and not have a domain set.
+ */
+ if(co->secure && co->path && strcmp(co->path, "/") == 0 && !co->tailmatch)
+ ;
+ else {
+ 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! */
@@ -795,30 +937,40 @@ Curl_cookie_add(struct Curl_easy *data,
}
co->livecookie = c->running;
+ co->creationtime = ++c->lastct;
/* 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
+ supersedes an already existing cookie, which it may if the previous have
the same domain and path as this */
/* at first, remove expired cookies */
- remove_expired(c);
+ if(!noexpire)
+ remove_expired(c);
#ifdef USE_LIBPSL
- /* Check if the domain is a Public Suffix and if yes, ignore the cookie.
- This needs a libpsl compiled with builtin data. */
+ /* Check if the domain is a Public Suffix and if yes, ignore the cookie. */
if(domain && co->domain && !isip(co->domain)) {
- psl = psl_builtin();
- if(psl && !psl_is_cookie_domain_acceptable(psl, domain, co->domain)) {
- infof(data,
- "cookie '%s' dropped, domain '%s' must not set cookies for '%s'\n",
- co->name, domain, co->domain);
+ const psl_ctx_t *psl = Curl_psl_use(data);
+ int acceptable;
+
+ if(psl) {
+ acceptable = psl_is_cookie_domain_acceptable(psl, domain, co->domain);
+ Curl_psl_release(data);
+ }
+ else
+ acceptable = !bad_domain(domain);
+
+ if(!acceptable) {
+ infof(data, "cookie '%s' dropped, domain '%s' must not "
+ "set cookies for '%s'\n", co->name, domain, co->domain);
freecookie(co);
return NULL;
}
}
#endif
- clist = c->cookies;
+ myhash = cookiehash(co->domain);
+ clist = c->cookies[myhash];
replace_old = FALSE;
while(clist) {
if(strcasecompare(clist->name, co->name)) {
@@ -828,7 +980,7 @@ Curl_cookie_add(struct Curl_easy *data,
if(strcasecompare(clist->domain, co->domain) &&
(clist->tailmatch == co->tailmatch))
/* The domains are identical */
- replace_old=TRUE;
+ replace_old = TRUE;
}
else if(!clist->domain && !co->domain)
replace_old = TRUE;
@@ -837,9 +989,31 @@ Curl_cookie_add(struct Curl_easy *data,
/* the domains were identical */
if(clist->spath && co->spath) {
- if(strcasecompare(clist->spath, co->spath)) {
- replace_old = TRUE;
+ if(clist->secure && !co->secure && !secure) {
+ size_t cllen;
+ const char *sep;
+
+ /*
+ * A non-secure cookie may not overlay an existing secure cookie.
+ * For an existing cookie "a" with path "/login", refuse a new
+ * cookie "a" with for example path "/login/en", while the path
+ * "/loginhelper" is ok.
+ */
+
+ sep = strchr(clist->spath + 1, '/');
+
+ if(sep)
+ cllen = sep - clist->spath;
+ else
+ cllen = strlen(clist->spath);
+
+ if(strncasecompare(clist->spath, co->spath, cllen)) {
+ freecookie(co);
+ return NULL;
+ }
}
+ else if(strcasecompare(clist->spath, co->spath))
+ replace_old = TRUE;
else
replace_old = FALSE;
}
@@ -864,6 +1038,9 @@ Curl_cookie_add(struct Curl_easy *data,
if(replace_old) {
co->next = clist->next; /* get the next-pointer first */
+ /* when replacing, creationtime is kept from old */
+ co->creationtime = clist->creationtime;
+
/* then free all the old pointers */
free(clist->name);
free(clist->value);
@@ -904,40 +1081,13 @@ Curl_cookie_add(struct Curl_easy *data,
if(lastc)
lastc->next = co;
else
- c->cookies = co;
+ c->cookies[myhash] = co;
c->numcookies++; /* one more cookie in the jar */
}
return co;
}
-/*
- * get_line() makes sure to only return complete whole lines that fit in 'len'
- * bytes and end with a newline.
- */
-static char *get_line(char *buf, int len, FILE *input)
-{
- bool partial = FALSE;
- while(1) {
- char *b = fgets(buf, len, input);
- if(b) {
- size_t rlen = strlen(b);
- if(rlen && (b[rlen-1] == '\n')) {
- if(partial) {
- partial = FALSE;
- continue;
- }
- return b;
- }
- /* read a partial, discard the next piece that ends with newline */
- partial = TRUE;
- }
- else
- break;
- }
- return NULL;
-}
-
/*****************************************************************************
*
@@ -957,7 +1107,7 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
{
struct CookieInfo *c;
FILE *fp = NULL;
- bool fromfile=TRUE;
+ bool fromfile = TRUE;
char *line = NULL;
if(NULL == inc) {
@@ -977,7 +1127,7 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
if(file && !strcmp(file, "-")) {
fp = stdin;
- fromfile=FALSE;
+ fromfile = FALSE;
}
else if(file && !*file) {
/* points to a "" string */
@@ -995,22 +1145,23 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data,
line = malloc(MAX_COOKIE_LINE);
if(!line)
goto fail;
- while(get_line(line, MAX_COOKIE_LINE, fp)) {
+ while(Curl_get_line(line, MAX_COOKIE_LINE, fp)) {
if(checkprefix("Set-Cookie:", line)) {
/* This is a cookie line, get it! */
- lineptr=&line[11];
- headerline=TRUE;
+ lineptr = &line[11];
+ headerline = TRUE;
}
else {
- lineptr=line;
- headerline=FALSE;
+ lineptr = line;
+ headerline = FALSE;
}
while(*lineptr && ISBLANK(*lineptr))
lineptr++;
- Curl_cookie_add(data, c, headerline, lineptr, NULL, NULL);
+ Curl_cookie_add(data, c, headerline, TRUE, lineptr, NULL, NULL, TRUE);
}
free(line); /* free the line buffer */
+ remove_expired(c); /* run this once, not on every cookie */
if(fromfile)
fclose(fp);
@@ -1052,12 +1203,24 @@ static int cookie_sort(const void *p1, const void *p2)
if(l1 != l2)
return (l2 > l1) ? 1 : -1 ; /* avoid size_t <=> int conversions */
- /* 3 - compare cookie names */
- if(c1->name && c2->name)
- return strcmp(c1->name, c2->name);
+ /* 3 - compare cookie name lengths */
+ l1 = c1->name ? strlen(c1->name) : 0;
+ l2 = c2->name ? strlen(c2->name) : 0;
- /* sorry, can't be more deterministic */
- return 0;
+ if(l1 != l2)
+ return (l2 > l1) ? 1 : -1;
+
+ /* 4 - compare cookie creation time */
+ return (c2->creationtime > c1->creationtime) ? 1 : -1;
+}
+
+/* sort cookies only according to creation time */
+static int cookie_sort_ct(const void *p1, const void *p2)
+{
+ struct Cookie *c1 = *(struct Cookie **)p1;
+ struct Cookie *c2 = *(struct Cookie **)p2;
+
+ return (c2->creationtime > c1->creationtime) ? 1 : -1;
}
#define CLONE(field) \
@@ -1086,6 +1249,7 @@ static struct Cookie *dup_cookie(struct Cookie *src)
d->secure = src->secure;
d->livecookie = src->livecookie;
d->httponly = src->httponly;
+ d->creationtime = src->creationtime;
}
return d;
@@ -1112,12 +1276,12 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
{
struct Cookie *newco;
struct Cookie *co;
- time_t now = time(NULL);
- struct Cookie *mainco=NULL;
+ struct Cookie *mainco = NULL;
size_t matches = 0;
bool is_ip;
+ const size_t myhash = cookiehash(host);
- if(!c || !c->cookies)
+ if(!c || !c->cookies[myhash])
return NULL; /* no cookie struct or no cookies in the struct */
/* at first, remove expired cookies */
@@ -1126,14 +1290,11 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
/* check if host is an IP(v4|v6) address */
is_ip = isip(host);
- co = c->cookies;
+ co = c->cookies[myhash];
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 || (co->expires > now)) &&
- (co->secure?secure:TRUE)) {
+ /* if the cookie requires we're secure we must only continue if we are! */
+ if(co->secure?secure:TRUE) {
/* now check if the domain is correct */
if(!co->domain ||
@@ -1159,12 +1320,8 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
matches++;
}
- else {
- fail:
- /* failure, clear up the allocated chain and return NULL */
- Curl_cookie_freelist(mainco);
- return NULL;
- }
+ else
+ goto fail;
}
}
}
@@ -1185,7 +1342,7 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
co = mainco;
- for(i=0; co; co = co->next)
+ for(i = 0; co; co = co->next)
array[i++] = co;
/* now sort the cookie pointers in path length order */
@@ -1194,14 +1351,19 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
/* remake the linked list order according to the new order */
mainco = array[0]; /* start here */
- for(i=0; i<matches-1; i++)
- array[i]->next = array[i+1];
+ for(i = 0; i<matches-1; i++)
+ array[i]->next = array[i + 1];
array[matches-1]->next = NULL; /* terminate the list */
free(array); /* remove the temporary data again */
}
return mainco; /* return the new list */
+
+fail:
+ /* failure, clear up the allocated chain and return NULL */
+ Curl_cookie_freelist(mainco);
+ return NULL;
}
/*****************************************************************************
@@ -1214,8 +1376,11 @@ struct Cookie *Curl_cookie_getlist(struct CookieInfo *c,
void Curl_cookie_clearall(struct CookieInfo *cookies)
{
if(cookies) {
- Curl_cookie_freelist(cookies->cookies);
- cookies->cookies = NULL;
+ unsigned int i;
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ Curl_cookie_freelist(cookies->cookies[i]);
+ cookies->cookies[i] = NULL;
+ }
cookies->numcookies = 0;
}
}
@@ -1249,31 +1414,37 @@ void Curl_cookie_freelist(struct Cookie *co)
void Curl_cookie_clearsess(struct CookieInfo *cookies)
{
struct Cookie *first, *curr, *next, *prev = NULL;
+ unsigned int i;
- if(!cookies || !cookies->cookies)
+ if(!cookies)
return;
- first = curr = prev = cookies->cookies;
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ if(!cookies->cookies[i])
+ continue;
- for(; curr; curr = next) {
- next = curr->next;
- if(!curr->expires) {
- if(first == curr)
- first = next;
+ first = curr = prev = cookies->cookies[i];
- if(prev == curr)
- prev = next;
- else
- prev->next = next;
+ for(; curr; curr = next) {
+ next = curr->next;
+ if(!curr->expires) {
+ if(first == curr)
+ first = next;
- freecookie(curr);
- cookies->numcookies--;
+ if(prev == curr)
+ prev = next;
+ else
+ prev->next = next;
+
+ freecookie(curr);
+ cookies->numcookies--;
+ }
+ else
+ prev = curr;
}
- else
- prev = curr;
- }
- cookies->cookies = first;
+ cookies->cookies[i] = first;
+ }
}
@@ -1287,8 +1458,10 @@ void Curl_cookie_clearsess(struct CookieInfo *cookies)
void Curl_cookie_cleanup(struct CookieInfo *c)
{
if(c) {
+ unsigned int i;
free(c->filename);
- Curl_cookie_freelist(c->cookies);
+ for(i = 0; i < COOKIE_HASH_SIZE; i++)
+ Curl_cookie_freelist(c->cookies[i]);
free(c); /* free the base struct as well */
}
}
@@ -1335,12 +1508,10 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
{
struct Cookie *co;
FILE *out;
- bool use_stdout=FALSE;
- char *format_ptr;
+ 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 */
+ if(!c)
+ /* no cookie engine alive */
return 0;
/* at first, remove expired cookies */
@@ -1349,12 +1520,13 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
if(!strcmp("-", dumphere)) {
/* use stdout */
out = stdout;
- use_stdout=TRUE;
+ use_stdout = TRUE;
}
else {
out = fopen(dumphere, FOPEN_WRITETEXT);
- if(!out)
+ if(!out) {
return 1; /* failure */
+ }
}
fputs("# Netscape HTTP Cookie File\n"
@@ -1362,57 +1534,93 @@ static int cookie_output(struct CookieInfo *c, const char *dumphere)
"# This file was generated by libcurl! Edit at your own risk.\n\n",
out);
- for(co = c->cookies; co; co = co->next) {
- if(!co->domain)
- continue;
- format_ptr = get_netscape_format(co);
- if(format_ptr == NULL) {
- fprintf(out, "#\n# Fatal libcurl error\n");
+ if(c->numcookies) {
+ unsigned int i;
+ unsigned int j;
+ struct Cookie **array;
+
+ array = malloc(sizeof(struct Cookie *) * c->numcookies);
+ if(!array) {
if(!use_stdout)
fclose(out);
return 1;
}
- fprintf(out, "%s\n", format_ptr);
- free(format_ptr);
- }
+ j = 0;
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ for(co = c->cookies[i]; co; co = co->next) {
+ if(!co->domain)
+ continue;
+ array[j++] = co;
+ }
+ }
+
+ qsort(array, c->numcookies, sizeof(struct Cookie *), cookie_sort_ct);
+
+ for(i = 0; i < j; i++) {
+ char *format_ptr = get_netscape_format(array[i]);
+ if(format_ptr == NULL) {
+ fprintf(out, "#\n# Fatal libcurl error\n");
+ free(array);
+ if(!use_stdout)
+ fclose(out);
+ return 1;
+ }
+ fprintf(out, "%s\n", format_ptr);
+ free(format_ptr);
+ }
+
+ free(array);
+ }
if(!use_stdout)
fclose(out);
return 0;
}
-struct curl_slist *Curl_cookie_list(struct Curl_easy *data)
+static struct curl_slist *cookie_list(struct Curl_easy *data)
{
struct curl_slist *list = NULL;
struct curl_slist *beg;
struct Cookie *c;
char *line;
+ unsigned int i;
if((data->cookies == NULL) ||
(data->cookies->numcookies == 0))
return NULL;
- for(c = data->cookies->cookies; c; c = c->next) {
- if(!c->domain)
- continue;
- line = get_netscape_format(c);
- if(!line) {
- curl_slist_free_all(list);
- return NULL;
- }
- beg = Curl_slist_append_nodup(list, line);
- if(!beg) {
- free(line);
- curl_slist_free_all(list);
- return NULL;
+ for(i = 0; i < COOKIE_HASH_SIZE; i++) {
+ for(c = data->cookies->cookies[i]; c; c = c->next) {
+ if(!c->domain)
+ continue;
+ line = get_netscape_format(c);
+ if(!line) {
+ curl_slist_free_all(list);
+ return NULL;
+ }
+ beg = Curl_slist_append_nodup(list, line);
+ if(!beg) {
+ free(line);
+ curl_slist_free_all(list);
+ return NULL;
+ }
+ list = beg;
}
- list = beg;
}
return list;
}
+struct curl_slist *Curl_cookie_list(struct Curl_easy *data)
+{
+ struct curl_slist *list;
+ Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
+ list = cookie_list(data);
+ Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
+ return list;
+}
+
void Curl_flush_cookies(struct Curl_easy *data, int cleanup)
{
if(data->set.str[STRING_COOKIEJAR]) {
diff --git a/Utilities/cmcurl/lib/cookie.h b/Utilities/cmcurl/lib/cookie.h
index a9a45785c..b2730cfb9 100644
--- a/Utilities/cmcurl/lib/cookie.h
+++ b/Utilities/cmcurl/lib/cookie.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -34,7 +34,7 @@ struct Cookie {
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 */
+ bool tailmatch; /* whether we do tail-matching of the domain name */
/* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */
char *version; /* Version = <value> */
@@ -43,16 +43,28 @@ struct Cookie {
bool secure; /* whether the 'secure' keyword was used */
bool livecookie; /* updated from a server, not a stored file */
bool httponly; /* true if the httponly directive is present */
+ int creationtime; /* time when the cookie was written */
+ unsigned char prefix; /* bitmap fields indicating which prefix are set */
};
+/*
+ * Available cookie prefixes, as defined in
+ * draft-ietf-httpbis-rfc6265bis-02
+ */
+#define COOKIE_PREFIX__SECURE (1<<0)
+#define COOKIE_PREFIX__HOST (1<<1)
+
+#define COOKIE_HASH_SIZE 256
+
struct CookieInfo {
/* linked list of cookies we know of */
- struct Cookie *cookies;
+ struct Cookie *cookies[COOKIE_HASH_SIZE];
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 */
+ int lastct; /* last creation-time used in the jar */
};
/* This is the maximum line length we accept for a cookie line. RFC 2109
@@ -62,13 +74,15 @@ struct CookieInfo {
that comprise the cookie non-terminal in the syntax description of the
Set-Cookie header)"
+ We allow max 5000 bytes cookie header. Max 4095 bytes length per cookie
+ name and value. Name + value may not exceed 4096 bytes.
+
*/
#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"
+/* This is the maximum length of a cookie name or content we deal with: */
+#define MAX_NAME 4096
+#define MAX_NAME_TXT "4095"
struct Curl_easy;
/*
@@ -77,8 +91,10 @@ struct Curl_easy;
*/
struct Cookie *Curl_cookie_add(struct Curl_easy *data,
- struct CookieInfo *, bool header, char *lineptr,
- const char *domain, const char *path);
+ struct CookieInfo *, bool header, bool noexpiry,
+ char *lineptr,
+ const char *domain, const char *path,
+ bool secure);
struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *,
const char *, bool);
diff --git a/Utilities/cmcurl/lib/curl_addrinfo.c b/Utilities/cmcurl/lib/curl_addrinfo.c
index 1adf3198a..16c4779c1 100644
--- a/Utilities/cmcurl/lib/curl_addrinfo.c
+++ b/Utilities/cmcurl/lib/curl_addrinfo.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -27,6 +27,9 @@
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
+#ifdef HAVE_NETINET_IN6_H
+# include <netinet/in6.h>
+#endif
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif
@@ -47,6 +50,10 @@
# define in_addr_t unsigned long
#endif
+#if defined(WIN32) && defined(USE_UNIX_SOCKETS)
+#include <afunix.h>
+#endif
+
#include <stddef.h>
#include "curl_addrinfo.h"
@@ -286,7 +293,7 @@ Curl_he2ai(const struct hostent *he, int port)
DEBUGASSERT((he->h_name != NULL) && (he->h_addr_list != NULL));
- for(i=0; (curr = he->h_addr_list[i]) != NULL; i++) {
+ for(i = 0; (curr = he->h_addr_list[i]) != NULL; i++) {
size_t ss_size;
#ifdef ENABLE_IPV6
@@ -338,7 +345,7 @@ Curl_he2ai(const struct hostent *he, int port)
addr = (void *)ai->ai_addr; /* storage area for this info */
memcpy(&addr->sin_addr, curr, sizeof(struct in_addr));
- addr->sin_family = (unsigned short)(he->h_addrtype);
+ addr->sin_family = (CURL_SA_FAMILY_T)(he->h_addrtype);
addr->sin_port = htons((unsigned short)port);
break;
@@ -347,7 +354,7 @@ Curl_he2ai(const struct hostent *he, int port)
addr6 = (void *)ai->ai_addr; /* storage area for this info */
memcpy(&addr6->sin6_addr, curr, sizeof(struct in6_addr));
- addr6->sin6_family = (unsigned short)(he->h_addrtype);
+ addr6->sin6_family = (CURL_SA_FAMILY_T)(he->h_addrtype);
addr6->sin6_port = htons((unsigned short)port);
break;
#endif
@@ -529,9 +536,10 @@ Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, bool abstract)
}
#endif
-#if defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO)
+#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \
+ defined(HAVE_FREEADDRINFO)
/*
- * curl_dofreeaddrinfo()
+ * curl_dbg_freeaddrinfo()
*
* This is 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
@@ -539,23 +547,23 @@ Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, bool abstract)
*/
void
-curl_dofreeaddrinfo(struct addrinfo *freethis,
- int line, const char *source)
+curl_dbg_freeaddrinfo(struct addrinfo *freethis,
+ int line, const char *source)
{
+ curl_dbg_log("ADDR %s:%d freeaddrinfo(%p)\n",
+ source, line, (void *)freethis);
#ifdef USE_LWIPSOCK
lwip_freeaddrinfo(freethis);
#else
(freeaddrinfo)(freethis);
#endif
- curl_memlog("ADDR %s:%d freeaddrinfo(%p)\n",
- source, line, (void *)freethis);
}
#endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO)
/*
- * curl_dogetaddrinfo()
+ * curl_dbg_getaddrinfo()
*
* This is 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
@@ -563,24 +571,24 @@ curl_dofreeaddrinfo(struct addrinfo *freethis,
*/
int
-curl_dogetaddrinfo(const char *hostname,
- const char *service,
- const struct addrinfo *hints,
- struct addrinfo **result,
- int line, const char *source)
+curl_dbg_getaddrinfo(const char *hostname,
+ const char *service,
+ const struct addrinfo *hints,
+ struct addrinfo **result,
+ int line, const char *source)
{
#ifdef USE_LWIPSOCK
- int res=lwip_getaddrinfo(hostname, service, hints, result);
+ int res = lwip_getaddrinfo(hostname, service, hints, result);
#else
- int res=(getaddrinfo)(hostname, service, hints, result);
+ int res = (getaddrinfo)(hostname, service, hints, result);
#endif
if(0 == res)
/* success */
- curl_memlog("ADDR %s:%d getaddrinfo() = %p\n",
- source, line, (void *)*result);
+ curl_dbg_log("ADDR %s:%d getaddrinfo() = %p\n",
+ source, line, (void *)*result);
else
- curl_memlog("ADDR %s:%d getaddrinfo() failed\n",
- source, line);
+ curl_dbg_log("ADDR %s:%d getaddrinfo() failed\n",
+ source, line);
return res;
}
#endif /* defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) */
diff --git a/Utilities/cmcurl/lib/curl_addrinfo.h b/Utilities/cmcurl/lib/curl_addrinfo.h
index 8f6f3d106..205e121ea 100644
--- a/Utilities/cmcurl/lib/curl_addrinfo.h
+++ b/Utilities/cmcurl/lib/curl_addrinfo.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -86,17 +86,14 @@ Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, bool abstract);
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \
defined(HAVE_FREEADDRINFO)
void
-curl_dofreeaddrinfo(struct addrinfo *freethis,
- int line, const char *source);
+curl_dbg_freeaddrinfo(struct addrinfo *freethis, int line, const char *source);
#endif
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO)
int
-curl_dogetaddrinfo(const char *hostname,
- const char *service,
- const struct addrinfo *hints,
- struct addrinfo **result,
- int line, const char *source);
+curl_dbg_getaddrinfo(const char *hostname, const char *service,
+ const struct addrinfo *hints, struct addrinfo **result,
+ int line, const char *source);
#endif
#ifdef HAVE_GETADDRINFO
diff --git a/Utilities/cmcurl/lib/curl_config.h.cmake b/Utilities/cmcurl/lib/curl_config.h.cmake
index f9d54b4bd..b285c3fdd 100644
--- a/Utilities/cmcurl/lib/curl_config.h.cmake
+++ b/Utilities/cmcurl/lib/curl_config.h.cmake
@@ -42,9 +42,6 @@
/* to disable RTSP */
#cmakedefine CURL_DISABLE_RTSP 1
-/* to disable RTMP */
-#cmakedefine CURL_DISABLE_RTMP 1
-
/* to disable SMB */
#cmakedefine CURL_DISABLE_SMB 1
@@ -73,9 +70,6 @@
/* when not building a shared library */
#cmakedefine CURL_STATICLIB 1
-/* Set to explicitly specify we don't want to use thread-safe functions */
-#cmakedefine DISABLED_THREADSAFE 1
-
/* your Entropy Gathering Daemon socket pathname */
#cmakedefine EGD_SOCKET ${EGD_SOCKET}
@@ -124,6 +118,9 @@
/* Define to 1 if bool is an available type. */
#cmakedefine HAVE_BOOL_T 1
+/* Define to 1 if you have the __builtin_available function. */
+#cmakedefine HAVE_BUILTIN_AVAILABLE 1
+
/* Define to 1 if you have the clock_gettime function and monotonic timer. */
#cmakedefine HAVE_CLOCK_GETTIME_MONOTONIC 1
@@ -229,9 +226,18 @@
/* Define to 1 if you have the `getprotobyname' function. */
#cmakedefine HAVE_GETPROTOBYNAME 1
+/* Define to 1 if you have the `getpeername' function. */
+#cmakedefine HAVE_GETPEERNAME 1
+
+/* Define to 1 if you have the `getsockname' function. */
+#cmakedefine HAVE_GETSOCKNAME 1
+
/* Define to 1 if you have the `getpwuid' function. */
#cmakedefine HAVE_GETPWUID 1
+/* Define to 1 if you have the `getpwuid_r' function. */
+#cmakedefine HAVE_GETPWUID_R 1
+
/* Define to 1 if you have the `getrlimit' function. */
#cmakedefine HAVE_GETRLIMIT 1
@@ -395,8 +401,8 @@
/* if zlib is available */
#cmakedefine HAVE_LIBZ 1
-/* Define to 1 if you have the <limits.h> header file. */
-#cmakedefine HAVE_LIMITS_H 1
+/* if brotli is available */
+#cmakedefine HAVE_BROTLI 1
/* if your compiler supports LL */
#cmakedefine HAVE_LL 1
@@ -882,9 +888,18 @@
/* 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 `off_t', as computed by sizeof. */
@SIZEOF_OFF_T_CODE@
+/* The size of `curl_off_t', as computed by sizeof. */
+@SIZEOF_CURL_OFF_T_CODE@
+
/* The size of `size_t', as computed by sizeof. */
@SIZEOF_SIZE_T_CODE@
@@ -921,8 +936,8 @@
/* if PolarSSL is enabled */
#cmakedefine USE_POLARSSL 1
-/* if DarwinSSL is enabled */
-#cmakedefine USE_DARWINSSL 1
+/* if Secure Transport is enabled */
+#cmakedefine USE_SECTRANSP 1
/* if mbedTLS is enabled */
#cmakedefine USE_MBEDTLS 1
@@ -954,15 +969,15 @@
/* to enable Windows SSL */
#cmakedefine USE_SCHANNEL 1
+/* enable multiple SSL backends */
+#cmakedefine CURL_WITH_MULTI_SSL 1
+
/* Define to 1 if using yaSSL in OpenSSL compatibility mode. */
#cmakedefine USE_YASSLEMUL 1
/* Version number of package */
#cmakedefine VERSION ${VERSION}
-/* Define to avoid automatic inclusion of winsock.h */
-#cmakedefine WIN32_LEAN_AND_MEAN 1
-
/* Define to 1 if OS is AIX. */
#ifndef _ALL_SOURCE
# undef _ALL_SOURCE
@@ -1004,3 +1019,6 @@
typedef int ssize_t;
# endif
#endif
+
+/* Define to 1 if you have the mach_absolute_time function. */
+#cmakedefine HAVE_MACH_ABSOLUTE_TIME 1
diff --git a/Utilities/cmcurl/lib/curl_endian.c b/Utilities/cmcurl/lib/curl_endian.c
index c25db4956..b7563b3de 100644
--- a/Utilities/cmcurl/lib/curl_endian.c
+++ b/Utilities/cmcurl/lib/curl_endian.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -82,7 +82,7 @@ unsigned short Curl_read16_be(const unsigned char *buf)
}
/*
- * Curl_write32_le()
+ * write32_le()
*
* This function converts a 32-bit integer from the native endian format,
* to little endian format ready for sending down the wire.
@@ -92,7 +92,7 @@ unsigned short Curl_read16_be(const unsigned char *buf)
* value [in] - The 32-bit integer value.
* buffer [in] - A pointer to the output buffer.
*/
-void Curl_write32_le(const int value, unsigned char *buffer)
+static void write32_le(const int value, unsigned char *buffer)
{
buffer[0] = (char)(value & 0x000000FF);
buffer[1] = (char)((value & 0x0000FF00) >> 8);
@@ -118,7 +118,7 @@ void Curl_write64_le(const long long value, unsigned char *buffer)
void Curl_write64_le(const __int64 value, unsigned char *buffer)
#endif
{
- Curl_write32_le((int)value, buffer);
- Curl_write32_le((int)(value >> 32), buffer + 4);
+ write32_le((int)value, buffer);
+ write32_le((int)(value >> 32), buffer + 4);
}
#endif /* CURL_SIZEOF_CURL_OFF_T > 4 */
diff --git a/Utilities/cmcurl/lib/curl_fnmatch.c b/Utilities/cmcurl/lib/curl_fnmatch.c
index 46d3ada1e..ab3e7428d 100644
--- a/Utilities/cmcurl/lib/curl_fnmatch.c
+++ b/Utilities/cmcurl/lib/curl_fnmatch.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -21,7 +21,7 @@
***************************************************************************/
#include "curl_setup.h"
-
+#ifndef CURL_DISABLE_FTP
#include <curl/curl.h>
#include "curl_fnmatch.h"
@@ -30,6 +30,8 @@
/* The last #include file should be: */
#include "memdebug.h"
+#ifndef HAVE_FNMATCH
+
#define CURLFNM_CHARSET_LEN (sizeof(char) * 256)
#define CURLFNM_CHSET_SIZE (CURLFNM_CHARSET_LEN + 15)
@@ -47,14 +49,7 @@
#define CURLFNM_UPPER (CURLFNM_CHARSET_LEN + 10)
typedef enum {
- CURLFNM_LOOP_DEFAULT = 0,
- CURLFNM_LOOP_BACKSLASH
-} loop_state;
-
-typedef enum {
CURLFNM_SCHS_DEFAULT = 0,
- CURLFNM_SCHS_MAYRANGE,
- CURLFNM_SCHS_MAYRANGE2,
CURLFNM_SCHS_RIGHTBR,
CURLFNM_SCHS_RIGHTBRLEFTBR
} setcharset_state;
@@ -64,6 +59,13 @@ typedef enum {
CURLFNM_PKW_DDOT
} parsekey_state;
+typedef enum {
+ CCLASS_OTHER = 0,
+ CCLASS_DIGIT,
+ CCLASS_UPPER,
+ CCLASS_LOWER
+} char_class;
+
#define SETCHARSET_OK 1
#define SETCHARSET_FAIL 0
@@ -81,12 +83,12 @@ static int parsekeyword(unsigned char **pattern, unsigned char *charset)
return SETCHARSET_FAIL;
switch(state) {
case CURLFNM_PKW_INIT:
- if(ISALPHA(c) && ISLOWER(c))
+ if(ISLOWER(c))
keyword[i] = c;
else if(c == ':')
state = CURLFNM_PKW_DDOT;
else
- return 0;
+ return SETCHARSET_FAIL;
break;
case CURLFNM_PKW_DDOT:
if(c == ']')
@@ -123,26 +125,56 @@ static int parsekeyword(unsigned char **pattern, unsigned char *charset)
return SETCHARSET_OK;
}
+/* Return the character class. */
+static char_class charclass(unsigned char c)
+{
+ if(ISUPPER(c))
+ return CCLASS_UPPER;
+ if(ISLOWER(c))
+ return CCLASS_LOWER;
+ if(ISDIGIT(c))
+ return CCLASS_DIGIT;
+ return CCLASS_OTHER;
+}
+
+/* Include a character or a range in set. */
+static void setcharorrange(unsigned char **pp, unsigned char *charset)
+{
+ unsigned char *p = (*pp)++;
+ unsigned char c = *p++;
+
+ charset[c] = 1;
+ if(ISALNUM(c) && *p++ == '-') {
+ char_class cc = charclass(c);
+ unsigned char endrange = *p++;
+
+ if(endrange == '\\')
+ endrange = *p++;
+ if(endrange >= c && charclass(endrange) == cc) {
+ while(c++ != endrange)
+ if(charclass(c) == cc) /* Chars in class may be not consecutive. */
+ charset[c] = 1;
+ *pp = p;
+ }
+ }
+}
+
/* returns 1 (true) if pattern is OK, 0 if is bad ("p" is pattern pointer) */
static int setcharset(unsigned char **p, unsigned char *charset)
{
setcharset_state state = CURLFNM_SCHS_DEFAULT;
- unsigned char rangestart = 0;
- unsigned char lastchar = 0;
bool something_found = FALSE;
unsigned char c;
+
+ memset(charset, 0, CURLFNM_CHSET_SIZE);
for(;;) {
c = **p;
+ if(!c)
+ return SETCHARSET_FAIL;
+
switch(state) {
case CURLFNM_SCHS_DEFAULT:
- if(ISALNUM(c)) { /* ASCII value */
- rangestart = c;
- charset[c] = 1;
- (*p)++;
- state = CURLFNM_SCHS_MAYRANGE;
- something_found = TRUE;
- }
- else if(c == ']') {
+ if(c == ']') {
if(something_found)
return SETCHARSET_OK;
something_found = TRUE;
@@ -151,26 +183,16 @@ static int setcharset(unsigned char **p, unsigned char *charset)
(*p)++;
}
else if(c == '[') {
- char c2 = *((*p)+1);
- if(c2 == ':') { /* there has to be a keyword */
- (*p) += 2;
- if(parsekeyword(p, charset)) {
- state = CURLFNM_SCHS_DEFAULT;
- }
- else
- return SETCHARSET_FAIL;
- }
+ unsigned char *pp = *p + 1;
+
+ if(*pp++ == ':' && parsekeyword(&pp, charset))
+ *p = pp;
else {
charset[c] = 1;
(*p)++;
}
something_found = TRUE;
}
- else if(c == '?' || c == '*') {
- something_found = TRUE;
- charset[c] = 1;
- (*p)++;
- }
else if(c == '^' || c == '!') {
if(!something_found) {
if(charset[CURLFNM_NEGATE]) {
@@ -186,88 +208,17 @@ static int setcharset(unsigned char **p, unsigned char *charset)
}
else if(c == '\\') {
c = *(++(*p));
- if(ISPRINT((c))) {
- something_found = TRUE;
- state = CURLFNM_SCHS_MAYRANGE;
- charset[c] = 1;
- rangestart = c;
- (*p)++;
- }
+ if(c)
+ setcharorrange(p, charset);
else
- return SETCHARSET_FAIL;
- }
- else if(c == '\0') {
- return SETCHARSET_FAIL;
+ charset['\\'] = 1;
+ something_found = TRUE;
}
else {
- charset[c] = 1;
- (*p)++;
+ setcharorrange(p, charset);
something_found = TRUE;
}
break;
- case CURLFNM_SCHS_MAYRANGE:
- if(c == '-') {
- charset[c] = 1;
- (*p)++;
- lastchar = '-';
- state = CURLFNM_SCHS_MAYRANGE2;
- }
- else if(c == '[') {
- state = CURLFNM_SCHS_DEFAULT;
- }
- else if(ISALNUM(c)) {
- charset[c] = 1;
- (*p)++;
- }
- else if(c == '\\') {
- c = *(++(*p));
- if(ISPRINT(c)) {
- charset[c] = 1;
- (*p)++;
- }
- else
- return SETCHARSET_FAIL;
- }
- else if(c == ']') {
- return SETCHARSET_OK;
- }
- else
- return SETCHARSET_FAIL;
- break;
- case CURLFNM_SCHS_MAYRANGE2:
- if(c == '\\') {
- c = *(++(*p));
- if(!ISPRINT(c))
- return SETCHARSET_FAIL;
- }
- if(c == ']') {
- return SETCHARSET_OK;
- }
- if(c == '\\') {
- c = *(++(*p));
- if(ISPRINT(c)) {
- charset[c] = 1;
- state = CURLFNM_SCHS_DEFAULT;
- (*p)++;
- }
- else
- return SETCHARSET_FAIL;
- }
- if(c >= rangestart) {
- if((ISLOWER(c) && ISLOWER(rangestart)) ||
- (ISDIGIT(c) && ISDIGIT(rangestart)) ||
- (ISUPPER(c) && ISUPPER(rangestart))) {
- charset[lastchar] = 0;
- rangestart++;
- while(rangestart++ <= c)
- charset[rangestart-1] = 1;
- (*p)++;
- state = CURLFNM_SCHS_DEFAULT;
- }
- else
- return SETCHARSET_FAIL;
- }
- break;
case CURLFNM_SCHS_RIGHTBR:
if(c == '[') {
state = CURLFNM_SCHS_RIGHTBRLEFTBR;
@@ -277,9 +228,6 @@ static int setcharset(unsigned char **p, unsigned char *charset)
else if(c == ']') {
return SETCHARSET_OK;
}
- else if(c == '\0') {
- return SETCHARSET_FAIL;
- }
else if(ISPRINT(c)) {
charset[c] = 1;
(*p)++;
@@ -292,14 +240,11 @@ static int setcharset(unsigned char **p, unsigned char *charset)
goto fail;
break;
case CURLFNM_SCHS_RIGHTBRLEFTBR:
- if(c == ']') {
+ if(c == ']')
return SETCHARSET_OK;
- }
- else {
- state = CURLFNM_SCHS_DEFAULT;
- charset[c] = 1;
- (*p)++;
- }
+ state = CURLFNM_SCHS_DEFAULT;
+ charset[c] = 1;
+ (*p)++;
break;
}
}
@@ -307,104 +252,96 @@ fail:
return SETCHARSET_FAIL;
}
-static int loop(const unsigned char *pattern, const unsigned char *string)
+static int loop(const unsigned char *pattern, const unsigned char *string,
+ int maxstars)
{
- loop_state state = CURLFNM_LOOP_DEFAULT;
unsigned char *p = (unsigned char *)pattern;
unsigned char *s = (unsigned char *)string;
unsigned char charset[CURLFNM_CHSET_SIZE] = { 0 };
- int rc = 0;
for(;;) {
- switch(state) {
- case CURLFNM_LOOP_DEFAULT:
- if(*p == '*') {
- while(*(p+1) == '*') /* eliminate multiple stars */
- p++;
- if(*s == '\0' && *(p+1) == '\0')
- return CURL_FNMATCH_MATCH;
- rc = loop(p + 1, s); /* *.txt matches .txt <=> .txt matches .txt */
- if(rc == CURL_FNMATCH_MATCH)
+ unsigned char *pp;
+
+ switch(*p) {
+ case '*':
+ if(!maxstars)
+ return CURL_FNMATCH_NOMATCH;
+ /* Regroup consecutive stars and question marks. This can be done because
+ '*?*?*' can be expressed as '??*'. */
+ for(;;) {
+ if(*++p == '\0')
return CURL_FNMATCH_MATCH;
- if(*s) /* let the star eat up one character */
- s++;
- else
- return CURL_FNMATCH_NOMATCH;
- }
- else if(*p == '?') {
- if(ISPRINT(*s)) {
- s++;
- p++;
+ if(*p == '?') {
+ if(!*s++)
+ return CURL_FNMATCH_NOMATCH;
}
- else if(*s == '\0')
- return CURL_FNMATCH_NOMATCH;
- else
- return CURL_FNMATCH_FAIL; /* cannot deal with other character */
+ else if(*p != '*')
+ break;
}
- else if(*p == '\0') {
- if(*s == '\0')
+ /* Skip string characters until we find a match with pattern suffix. */
+ for(maxstars--; *s; s++) {
+ if(loop(p, s, maxstars) == CURL_FNMATCH_MATCH)
return CURL_FNMATCH_MATCH;
- return CURL_FNMATCH_NOMATCH;
}
- else if(*p == '\\') {
- state = CURLFNM_LOOP_BACKSLASH;
+ return CURL_FNMATCH_NOMATCH;
+ case '?':
+ if(!*s)
+ return CURL_FNMATCH_NOMATCH;
+ s++;
+ p++;
+ break;
+ case '\0':
+ return *s? CURL_FNMATCH_NOMATCH: CURL_FNMATCH_MATCH;
+ case '\\':
+ if(p[1])
p++;
- }
- else if(*p == '[') {
- unsigned char *pp = p+1; /* cannot handle with pointer to register */
- if(setcharset(&pp, charset)) {
- int found = FALSE;
- if(charset[(unsigned int)*s])
- found = TRUE;
- else if(charset[CURLFNM_ALNUM])
- found = ISALNUM(*s);
- else if(charset[CURLFNM_ALPHA])
- found = ISALPHA(*s);
- else if(charset[CURLFNM_DIGIT])
- found = ISDIGIT(*s);
- else if(charset[CURLFNM_XDIGIT])
- found = ISXDIGIT(*s);
- else if(charset[CURLFNM_PRINT])
- found = ISPRINT(*s);
- else if(charset[CURLFNM_SPACE])
- found = ISSPACE(*s);
- else if(charset[CURLFNM_UPPER])
- found = ISUPPER(*s);
- else if(charset[CURLFNM_LOWER])
- found = ISLOWER(*s);
- else if(charset[CURLFNM_BLANK])
- found = ISBLANK(*s);
- else if(charset[CURLFNM_GRAPH])
- found = ISGRAPH(*s);
+ if(*s++ != *p++)
+ return CURL_FNMATCH_NOMATCH;
+ break;
+ case '[':
+ pp = p + 1; /* Copy in case of syntax error in set. */
+ if(setcharset(&pp, charset)) {
+ int found = FALSE;
+ if(!*s)
+ return CURL_FNMATCH_NOMATCH;
+ if(charset[(unsigned int)*s])
+ found = TRUE;
+ else if(charset[CURLFNM_ALNUM])
+ found = ISALNUM(*s);
+ else if(charset[CURLFNM_ALPHA])
+ found = ISALPHA(*s);
+ else if(charset[CURLFNM_DIGIT])
+ found = ISDIGIT(*s);
+ else if(charset[CURLFNM_XDIGIT])
+ found = ISXDIGIT(*s);
+ else if(charset[CURLFNM_PRINT])
+ found = ISPRINT(*s);
+ else if(charset[CURLFNM_SPACE])
+ found = ISSPACE(*s);
+ else if(charset[CURLFNM_UPPER])
+ found = ISUPPER(*s);
+ else if(charset[CURLFNM_LOWER])
+ found = ISLOWER(*s);
+ else if(charset[CURLFNM_BLANK])
+ found = ISBLANK(*s);
+ else if(charset[CURLFNM_GRAPH])
+ found = ISGRAPH(*s);
- if(charset[CURLFNM_NEGATE])
- found = !found;
+ if(charset[CURLFNM_NEGATE])
+ found = !found;
- if(found) {
- p = pp+1;
- s++;
- memset(charset, 0, CURLFNM_CHSET_SIZE);
- }
- else
- return CURL_FNMATCH_NOMATCH;
- }
- else
- return CURL_FNMATCH_FAIL;
- }
- else {
- if(*p++ != *s++)
- return CURL_FNMATCH_NOMATCH;
- }
- break;
- case CURLFNM_LOOP_BACKSLASH:
- if(ISPRINT(*p)) {
- if(*p++ == *s++)
- state = CURLFNM_LOOP_DEFAULT;
- else
+ if(!found)
return CURL_FNMATCH_NOMATCH;
+ p = pp + 1;
+ s++;
+ break;
}
- else
- return CURL_FNMATCH_FAIL;
+ /* Syntax error in set; mismatch! */
+ return CURL_FNMATCH_NOMATCH;
+
+ default:
+ if(*p++ != *s++)
+ return CURL_FNMATCH_NOMATCH;
break;
}
}
@@ -420,5 +357,33 @@ int Curl_fnmatch(void *ptr, const char *pattern, const char *string)
if(!pattern || !string) {
return CURL_FNMATCH_FAIL;
}
- return loop((unsigned char *)pattern, (unsigned char *)string);
+ return loop((unsigned char *)pattern, (unsigned char *)string, 2);
}
+#else
+#include <fnmatch.h>
+/*
+ * @unittest: 1307
+ */
+int Curl_fnmatch(void *ptr, const char *pattern, const char *string)
+{
+ int rc;
+ (void)ptr; /* the argument is specified by the curl_fnmatch_callback
+ prototype, but not used by Curl_fnmatch() */
+ if(!pattern || !string) {
+ return CURL_FNMATCH_FAIL;
+ }
+ rc = fnmatch(pattern, string, 0);
+ switch(rc) {
+ case 0:
+ return CURL_FNMATCH_MATCH;
+ case FNM_NOMATCH:
+ return CURL_FNMATCH_NOMATCH;
+ default:
+ return CURL_FNMATCH_FAIL;
+ }
+ /* not reached */
+}
+
+#endif
+
+#endif /* if FTP is disabled */
diff --git a/Utilities/cmcurl/lib/curl_gssapi.c b/Utilities/cmcurl/lib/curl_gssapi.c
index 83f3fa0c4..d854ab0c7 100644
--- a/Utilities/cmcurl/lib/curl_gssapi.c
+++ b/Utilities/cmcurl/lib/curl_gssapi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2011 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2011 - 2018, 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
@@ -27,6 +27,11 @@
#include "curl_gssapi.h"
#include "sendf.h"
+/* The last 3 #include files should be in this order */
+#include "curl_printf.h"
+#include "curl_memory.h"
+#include "memdebug.h"
+
static char spnego_oid_bytes[] = "\x2b\x06\x01\x05\x05\x02";
gss_OID_desc Curl_spnego_mech_oid = { 6, &spnego_oid_bytes };
static char krb5_oid_bytes[] = "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02";
@@ -92,9 +97,9 @@ static size_t display_gss_error(OM_uint32 status, int type,
&msg_ctx,
&status_string);
if(GSS_LOG_BUFFER_LEN > len + status_string.length + 3) {
- len += snprintf(buf + len, GSS_LOG_BUFFER_LEN - len,
- "%.*s. ", (int)status_string.length,
- (char *)status_string.value);
+ len += msnprintf(buf + len, GSS_LOG_BUFFER_LEN - len,
+ "%.*s. ", (int)status_string.length,
+ (char *)status_string.value);
}
gss_release_buffer(&min_stat, &status_string);
} while(!GSS_ERROR(maj_stat) && msg_ctx != 0);
diff --git a/Utilities/cmcurl/lib/curl_gssapi.h b/Utilities/cmcurl/lib/curl_gssapi.h
index 9700a2817..88f68dbbb 100644
--- a/Utilities/cmcurl/lib/curl_gssapi.h
+++ b/Utilities/cmcurl/lib/curl_gssapi.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2011 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2011 - 2019, 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
@@ -26,19 +26,6 @@
#include "urldata.h"
#ifdef HAVE_GSSAPI
-
-#ifdef HAVE_GSSGNU
-# include <gss.h>
-#elif defined HAVE_GSSMIT
- /* MIT style */
-# include <gssapi/gssapi.h>
-# include <gssapi/gssapi_generic.h>
-# include <gssapi/gssapi_krb5.h>
-#else
- /* Heimdal-style */
-# include <gssapi.h>
-#endif
-
extern gss_OID_desc Curl_spnego_mech_oid;
extern gss_OID_desc Curl_krb5_mech_oid;
@@ -71,5 +58,4 @@ void Curl_gss_log_error(struct Curl_easy *data, const char *prefix,
#define GSSAUTH_P_PRIVACY 4
#endif /* HAVE_GSSAPI */
-
#endif /* HEADER_CURL_GSSAPI_H */
diff --git a/Utilities/cmcurl/lib/curl_ldap.h b/Utilities/cmcurl/lib/curl_ldap.h
index 27d03810f..94c002948 100644
--- a/Utilities/cmcurl/lib/curl_ldap.h
+++ b/Utilities/cmcurl/lib/curl_ldap.h
@@ -32,4 +32,3 @@ extern const struct Curl_handler Curl_handler_ldaps;
#endif
#endif /* HEADER_CURL_LDAP_H */
-
diff --git a/Utilities/cmcurl/lib/curl_md4.h b/Utilities/cmcurl/lib/curl_md4.h
index e0690416d..392203f9e 100644
--- a/Utilities/cmcurl/lib/curl_md4.h
+++ b/Utilities/cmcurl/lib/curl_md4.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -25,11 +25,13 @@
#include "curl_setup.h"
#if defined(USE_NSS) || defined(USE_OS400CRYPTO) || \
+ (defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
void Curl_md4it(unsigned char *output, const unsigned char *input, size_t len);
#endif /* defined(USE_NSS) || defined(USE_OS400CRYPTO) ||
+ (defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) ||
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
#endif /* HEADER_CURL_MD4_H */
diff --git a/Utilities/cmcurl/lib/curl_md5.h b/Utilities/cmcurl/lib/curl_md5.h
index 5f70c9634..aaf25f61b 100644
--- a/Utilities/cmcurl/lib/curl_md5.h
+++ b/Utilities/cmcurl/lib/curl_md5.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -53,10 +53,10 @@ void Curl_md5it(unsigned char *output,
const unsigned char *input);
MD5_context * Curl_MD5_init(const MD5_params *md5params);
-int Curl_MD5_update(MD5_context *context,
- const unsigned char *data,
- unsigned int len);
-int Curl_MD5_final(MD5_context *context, unsigned char *result);
+CURLcode Curl_MD5_update(MD5_context *context,
+ const unsigned char *data,
+ unsigned int len);
+CURLcode Curl_MD5_final(MD5_context *context, unsigned char *result);
#endif
diff --git a/Utilities/cmcurl/lib/curl_memory.h b/Utilities/cmcurl/lib/curl_memory.h
index fccf46879..ce38a08cd 100644
--- a/Utilities/cmcurl/lib/curl_memory.h
+++ b/Utilities/cmcurl/lib/curl_memory.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -39,7 +39,7 @@
*
* File lib/strdup.c is an exception, given that it provides a strdup
* clone implementation while using malloc. Extra care needed inside
- * this one. TODO: revisit this paragraph and related code.
+ * this one.
*
* The need for curl_memory.h inclusion is due to libcurl's feature
* of allowing library user to provide memory replacement functions,
diff --git a/Utilities/cmcurl/lib/curl_memrchr.c b/Utilities/cmcurl/lib/curl_memrchr.c
index c521497b2..eeb3044a9 100644
--- a/Utilities/cmcurl/lib/curl_memrchr.c
+++ b/Utilities/cmcurl/lib/curl_memrchr.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -44,17 +44,18 @@
void *
Curl_memrchr(const void *s, int c, size_t n)
{
- const unsigned char *p = s;
- const unsigned char *q = s;
+ if(n > 0) {
+ const unsigned char *p = s;
+ const unsigned char *q = s;
- p += n - 1;
+ p += n - 1;
- while(p >= q) {
- if(*p == (unsigned char)c)
- return (void *)p;
- p--;
+ while(p >= q) {
+ if(*p == (unsigned char)c)
+ return (void *)p;
+ p--;
+ }
}
-
return NULL;
}
diff --git a/Utilities/cmcurl/lib/curl_multibyte.c b/Utilities/cmcurl/lib/curl_multibyte.c
index e78bb5002..e48334faf 100644
--- a/Utilities/cmcurl/lib/curl_multibyte.c
+++ b/Utilities/cmcurl/lib/curl_multibyte.c
@@ -64,13 +64,13 @@ char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w)
char *str_utf8 = NULL;
if(str_w) {
- int str_utf8_len = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL,
- 0, NULL, NULL);
- if(str_utf8_len > 0) {
- str_utf8 = malloc(str_utf8_len * sizeof(wchar_t));
+ int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1,
+ NULL, 0, NULL, NULL);
+ if(bytes > 0) {
+ str_utf8 = malloc(bytes);
if(str_utf8) {
- if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, str_utf8_len,
- NULL, FALSE) == 0) {
+ if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes,
+ NULL, NULL) == 0) {
free(str_utf8);
return NULL;
}
diff --git a/Utilities/cmcurl/lib/curl_ntlm_core.c b/Utilities/cmcurl/lib/curl_ntlm_core.c
index aea545295..b6df38f71 100644
--- a/Utilities/cmcurl/lib/curl_ntlm_core.c
+++ b/Utilities/cmcurl/lib/curl_ntlm_core.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -31,27 +31,38 @@
* https://www.innovation.ch/java/ntlm.html
*/
+/* Please keep the SSL backend-specific #if branches in this order:
+
+ 1. USE_OPENSSL
+ 2. USE_GNUTLS_NETTLE
+ 3. USE_GNUTLS
+ 4. USE_NSS
+ 5. USE_MBEDTLS
+ 6. USE_SECTRANSP
+ 7. USE_OS400CRYPTO
+ 8. USE_WIN32_CRYPTO
+
+ This ensures that:
+ - the same SSL branch gets activated throughout this source
+ file even if multiple backends are enabled at the same time.
+ - OpenSSL and NSS have higher priority than Windows Crypt, due
+ to issues with the latter supporting NTLM2Session responses
+ in NTLM type-3 messages.
+ */
+
#if !defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO)
#ifdef USE_OPENSSL
-# ifdef USE_OPENSSL
-# include <openssl/des.h>
-# ifndef OPENSSL_NO_MD4
-# include <openssl/md4.h>
-# endif
-# include <openssl/md5.h>
-# include <openssl/ssl.h>
-# include <openssl/rand.h>
+# include <openssl/des.h>
+# ifndef OPENSSL_NO_MD4
+# include <openssl/md4.h>
# else
-# include <des.h>
-# ifndef OPENSSL_NO_MD4
-# include <md4.h>
-# endif
-# include <md5.h>
-# include <ssl.h>
-# include <rand.h>
+# include "curl_md4.h"
# endif
+# 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
@@ -76,14 +87,6 @@
# define MD5_DIGEST_LENGTH 16
# define MD4_DIGEST_LENGTH 16
-#elif defined(USE_MBEDTLS)
-
-# include <mbedtls/des.h>
-# include <mbedtls/md4.h>
-# if !defined(MBEDTLS_MD4_C)
-# include "curl_md4.h"
-# endif
-
#elif defined(USE_NSS)
# include <nss.h>
@@ -92,7 +95,15 @@
# include "curl_md4.h"
# define MD5_DIGEST_LENGTH MD5_LENGTH
-#elif defined(USE_DARWINSSL)
+#elif defined(USE_MBEDTLS)
+
+# include <mbedtls/des.h>
+# include <mbedtls/md4.h>
+# if !defined(MBEDTLS_MD4_C)
+# include "curl_md4.h"
+# endif
+
+#elif defined(USE_SECTRANSP)
# include <CommonCrypto/CommonCryptor.h>
# include <CommonCrypto/CommonDigest.h>
@@ -196,26 +207,6 @@ static void setup_des_key(const unsigned char *key_56,
gcry_cipher_setkey(*des, key, sizeof(key));
}
-#elif defined(USE_MBEDTLS)
-
-static bool encrypt_des(const unsigned char *in, unsigned char *out,
- const unsigned char *key_56)
-{
- mbedtls_des_context ctx;
- char key[8];
-
- /* Expand the 56-bit key to 64-bits */
- extend_key_56_to_64(key_56, key);
-
- /* Set the key parity to odd */
- mbedtls_des_key_set_parity((unsigned char *) key);
-
- /* Perform the encryption */
- mbedtls_des_init(&ctx);
- mbedtls_des_setkey_enc(&ctx, (unsigned char *) key);
- return mbedtls_des_crypt_ecb(&ctx, in, out) == 0;
-}
-
#elif defined(USE_NSS)
/*
@@ -281,7 +272,27 @@ fail:
return rv;
}
-#elif defined(USE_DARWINSSL)
+#elif defined(USE_MBEDTLS)
+
+static bool encrypt_des(const unsigned char *in, unsigned char *out,
+ const unsigned char *key_56)
+{
+ mbedtls_des_context ctx;
+ char key[8];
+
+ /* Expand the 56-bit key to 64-bits */
+ extend_key_56_to_64(key_56, key);
+
+ /* Set the key parity to odd */
+ mbedtls_des_key_set_parity((unsigned char *) key);
+
+ /* Perform the encryption */
+ mbedtls_des_init(&ctx);
+ mbedtls_des_setkey_enc(&ctx, (unsigned char *) key);
+ return mbedtls_des_crypt_ecb(&ctx, in, out) == 0;
+}
+
+#elif defined(USE_SECTRANSP)
static bool encrypt_des(const unsigned char *in, unsigned char *out,
const unsigned char *key_56)
@@ -428,7 +439,7 @@ void Curl_ntlm_core_lm_resp(const unsigned char *keys,
setup_des_key(keys + 14, &des);
gcry_cipher_encrypt(des, results + 16, 8, plaintext, 8);
gcry_cipher_close(des);
-#elif defined(USE_MBEDTLS) || defined(USE_NSS) || defined(USE_DARWINSSL) \
+#elif defined(USE_NSS) || defined(USE_MBEDTLS) || defined(USE_SECTRANSP) \
|| defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO)
encrypt_des(plaintext, results, keys);
encrypt_des(plaintext, results + 8, keys + 7);
@@ -492,7 +503,7 @@ CURLcode Curl_ntlm_core_mk_lm_hash(struct Curl_easy *data,
setup_des_key(pw + 7, &des);
gcry_cipher_encrypt(des, lmbuffer + 8, 8, magic, 8);
gcry_cipher_close(des);
-#elif defined(USE_MBEDTLS) || defined(USE_NSS) || defined(USE_DARWINSSL) \
+#elif defined(USE_NSS) || defined(USE_MBEDTLS) || defined(USE_SECTRANSP) \
|| defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO)
encrypt_des(magic, lmbuffer, pw);
encrypt_des(magic, lmbuffer + 8, pw + 7);
@@ -538,8 +549,11 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct Curl_easy *data,
unsigned char *ntbuffer /* 21 bytes */)
{
size_t len = strlen(password);
- unsigned char *pw = malloc(len * 2);
+ unsigned char *pw;
CURLcode result;
+ if(len > SIZE_T_MAX/2) /* avoid integer overflow */
+ return CURLE_OUT_OF_MEMORY;
+ pw = len ? malloc(len * 2) : strdup("");
if(!pw)
return CURLE_OUT_OF_MEMORY;
@@ -556,10 +570,14 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct Curl_easy *data,
{
/* Create NT hashed password. */
#ifdef USE_OPENSSL
+#if !defined(OPENSSL_NO_MD4)
MD4_CTX MD4pw;
MD4_Init(&MD4pw);
MD4_Update(&MD4pw, pw, 2 * len);
MD4_Final(ntbuffer, &MD4pw);
+#else
+ Curl_md4it(ntbuffer, pw, 2 * len);
+#endif
#elif defined(USE_GNUTLS_NETTLE)
struct md4_ctx MD4pw;
md4_init(&MD4pw);
@@ -571,13 +589,18 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct Curl_easy *data,
gcry_md_write(MD4pw, pw, 2 * len);
memcpy(ntbuffer, gcry_md_read(MD4pw, 0), MD4_DIGEST_LENGTH);
gcry_md_close(MD4pw);
-#elif defined(USE_NSS) || defined(USE_OS400CRYPTO) || \
- (defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
+#elif defined(USE_NSS)
Curl_md4it(ntbuffer, pw, 2 * len);
#elif defined(USE_MBEDTLS)
+#if defined(MBEDTLS_MD4_C)
mbedtls_md4(pw, 2 * len, ntbuffer);
-#elif defined(USE_DARWINSSL)
+#else
+ Curl_md4it(ntbuffer, pw, 2 * len);
+#endif
+#elif defined(USE_SECTRANSP)
(void)CC_MD4(pw, (CC_LONG)(2 * len), ntbuffer);
+#elif defined(USE_OS400CRYPTO)
+ Curl_md4it(ntbuffer, pw, 2 * len);
#elif defined(USE_WIN32_CRYPTO)
HCRYPTPROV hprov;
if(CryptAcquireContext(&hprov, NULL, NULL, PROV_RSA_FULL,
@@ -604,9 +627,9 @@ CURLcode Curl_ntlm_core_mk_nt_hash(struct Curl_easy *data,
#if defined(USE_NTLM_V2) && !defined(USE_WINDOWS_SSPI)
/* This returns the HMAC MD5 digest */
-CURLcode Curl_hmac_md5(const unsigned char *key, unsigned int keylen,
- const unsigned char *data, unsigned int datalen,
- unsigned char *output)
+static CURLcode hmac_md5(const unsigned char *key, unsigned int keylen,
+ const unsigned char *data, unsigned int datalen,
+ unsigned char *output)
{
HMAC_context *ctxt = Curl_HMAC_init(Curl_HMAC_MD5, key, keylen);
@@ -631,19 +654,28 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen,
unsigned char *ntlmv2hash)
{
/* Unicode representation */
- size_t identity_len = (userlen + domlen) * 2;
- unsigned char *identity = malloc(identity_len);
+ size_t identity_len;
+ unsigned char *identity;
CURLcode result = CURLE_OK;
+ /* we do the length checks below separately to avoid integer overflow risk
+ on extreme data lengths */
+ if((userlen > SIZE_T_MAX/2) ||
+ (domlen > SIZE_T_MAX/2) ||
+ ((userlen + domlen) > SIZE_T_MAX/2))
+ return CURLE_OUT_OF_MEMORY;
+
+ identity_len = (userlen + domlen) * 2;
+ identity = malloc(identity_len);
+
if(!identity)
return CURLE_OUT_OF_MEMORY;
ascii_uppercase_to_unicode_le(identity, user, userlen);
ascii_to_unicode_le(identity + (userlen << 1), domain, domlen);
- result = Curl_hmac_md5(ntlmhash, 16, identity, curlx_uztoui(identity_len),
- ntlmv2hash);
-
+ result = hmac_md5(ntlmhash, 16, identity, curlx_uztoui(identity_len),
+ ntlmv2hash);
free(identity);
return result;
@@ -711,19 +743,17 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash,
len = NTLM_HMAC_MD5_LEN + NTLMv2_BLOB_LEN;
/* Allocate the response */
- ptr = malloc(len);
+ ptr = calloc(1, len);
if(!ptr)
return CURLE_OUT_OF_MEMORY;
- memset(ptr, 0, len);
-
/* Create the BLOB structure */
- snprintf((char *)ptr + NTLM_HMAC_MD5_LEN, NTLMv2_BLOB_LEN,
- "%c%c%c%c" /* NTLMv2_BLOB_SIGNATURE */
- "%c%c%c%c", /* Reserved = 0 */
- NTLMv2_BLOB_SIGNATURE[0], NTLMv2_BLOB_SIGNATURE[1],
- NTLMv2_BLOB_SIGNATURE[2], NTLMv2_BLOB_SIGNATURE[3],
- 0, 0, 0, 0);
+ msnprintf((char *)ptr + NTLM_HMAC_MD5_LEN, NTLMv2_BLOB_LEN,
+ "%c%c%c%c" /* NTLMv2_BLOB_SIGNATURE */
+ "%c%c%c%c", /* Reserved = 0 */
+ NTLMv2_BLOB_SIGNATURE[0], NTLMv2_BLOB_SIGNATURE[1],
+ NTLMv2_BLOB_SIGNATURE[2], NTLMv2_BLOB_SIGNATURE[3],
+ 0, 0, 0, 0);
Curl_write64_le(tw, ptr + 24);
memcpy(ptr + 32, challenge_client, 8);
@@ -731,8 +761,8 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash,
/* Concatenate the Type 2 challenge with the BLOB and do HMAC MD5 */
memcpy(ptr + 8, &ntlm->nonce[0], 8);
- result = Curl_hmac_md5(ntlmv2hash, NTLM_HMAC_MD5_LEN, ptr + 8,
- NTLMv2_BLOB_LEN + 8, hmac_output);
+ result = hmac_md5(ntlmv2hash, NTLM_HMAC_MD5_LEN, ptr + 8,
+ NTLMv2_BLOB_LEN + 8, hmac_output);
if(result) {
free(ptr);
return result;
@@ -774,13 +804,13 @@ CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash,
memcpy(&data[0], challenge_server, 8);
memcpy(&data[8], challenge_client, 8);
- result = Curl_hmac_md5(ntlmv2hash, 16, &data[0], 16, hmac_output);
+ result = hmac_md5(ntlmv2hash, 16, &data[0], 16, hmac_output);
if(result)
return result;
/* Concatenate the HMAC MD5 output with the client nonce */
memcpy(lmresp, hmac_output, 16);
- memcpy(lmresp+16, challenge_client, 8);
+ memcpy(lmresp + 16, challenge_client, 8);
return result;
}
diff --git a/Utilities/cmcurl/lib/curl_ntlm_core.h b/Utilities/cmcurl/lib/curl_ntlm_core.h
index 4a83d40bc..3b4b8053c 100644
--- a/Utilities/cmcurl/lib/curl_ntlm_core.h
+++ b/Utilities/cmcurl/lib/curl_ntlm_core.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -26,20 +26,24 @@
#if defined(USE_NTLM)
+/* If NSS is the first available SSL backend (see order in curl_ntlm_core.c)
+ then it must be initialized to be used by NTLM. */
+#if !defined(USE_OPENSSL) && \
+ !defined(USE_GNUTLS_NETTLE) && \
+ !defined(USE_GNUTLS) && \
+ defined(USE_NSS)
+#define NTLM_NEEDS_NSS_INIT
+#endif
+
#if !defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO)
#ifdef USE_OPENSSL
-# if !defined(OPENSSL_VERSION_NUMBER) && \
- !defined(HEADER_SSL_H) && !defined(HEADER_MD5_H)
-# error "curl_ntlm_core.h shall not be included before OpenSSL headers."
-# endif
+# include <openssl/ssl.h>
#endif
/* Define USE_NTRESPONSES in order to make the type-3 message include
* the NT response message. */
-#if !defined(USE_OPENSSL) || !defined(OPENSSL_NO_MD4)
#define USE_NTRESPONSES
-#endif
/* Define USE_NTLM2SESSION in order to make the type-3 message include the
NTLM2Session response message, requires USE_NTRESPONSES defined to 1 and a
diff --git a/Utilities/cmcurl/lib/curl_ntlm_wb.c b/Utilities/cmcurl/lib/curl_ntlm_wb.c
index 9f5b87bc3..80266e2a4 100644
--- a/Utilities/cmcurl/lib/curl_ntlm_wb.c
+++ b/Utilities/cmcurl/lib/curl_ntlm_wb.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -48,10 +48,13 @@
#include "sendf.h"
#include "select.h"
#include "vauth/ntlm.h"
+#include "curl_ntlm_core.h"
#include "curl_ntlm_wb.h"
#include "url.h"
#include "strerror.h"
#include "strdup.h"
+#include "strcase.h"
+
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -73,7 +76,7 @@
# define sclose_nolog(x) close((x))
#endif
-void Curl_ntlm_wb_cleanup(struct connectdata *conn)
+void Curl_http_auth_cleanup_ntlm_wb(struct connectdata *conn)
{
if(conn->ntlm_auth_hlpr_socket != CURL_SOCKET_BAD) {
sclose(conn->ntlm_auth_hlpr_socket);
@@ -123,7 +126,7 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, const char *userp)
struct passwd pw, *pw_res;
char pwbuf[1024];
#endif
- int error;
+ char buffer[STRERROR_LEN];
/* Return if communication with ntlm_auth already set up */
if(conn->ntlm_auth_hlpr_socket != CURL_SOCKET_BAD ||
@@ -178,26 +181,23 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, const char *userp)
ntlm_auth = NTLM_WB_FILE;
if(access(ntlm_auth, X_OK) != 0) {
- error = ERRNO;
failf(conn->data, "Could not access ntlm_auth: %s errno %d: %s",
- ntlm_auth, error, Curl_strerror(conn, error));
+ ntlm_auth, errno, Curl_strerror(errno, buffer, sizeof(buffer)));
goto done;
}
if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds)) {
- error = ERRNO;
failf(conn->data, "Could not open socket pair. errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
goto done;
}
child_pid = fork();
if(child_pid == -1) {
- error = ERRNO;
sclose(sockfds[0]);
sclose(sockfds[1]);
failf(conn->data, "Could not fork. errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
goto done;
}
else if(!child_pid) {
@@ -208,16 +208,14 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, const char *userp)
/* Don't use sclose in the child since it fools the socket leak detector */
sclose_nolog(sockfds[0]);
if(dup2(sockfds[1], STDIN_FILENO) == -1) {
- error = ERRNO;
failf(conn->data, "Could not redirect child stdin. errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
exit(1);
}
if(dup2(sockfds[1], STDOUT_FILENO) == -1) {
- error = ERRNO;
failf(conn->data, "Could not redirect child stdout. errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
exit(1);
}
@@ -235,10 +233,9 @@ static CURLcode ntlm_wb_init(struct connectdata *conn, const char *userp)
"--username", username,
NULL);
- error = ERRNO;
sclose_nolog(sockfds[1]);
failf(conn->data, "Could not execl(). errno %d: %s",
- error, Curl_strerror(conn, error));
+ errno, Curl_strerror(errno, buffer, sizeof(buffer)));
exit(1);
}
@@ -255,6 +252,9 @@ done:
return CURLE_REMOTE_ACCESS_DENIED;
}
+/* if larger than this, something is seriously wrong */
+#define MAX_NTLM_WB_RESPONSE 100000
+
static CURLcode ntlm_wb_response(struct connectdata *conn,
const char *input, curlntlm state)
{
@@ -295,6 +295,13 @@ static CURLcode ntlm_wb_response(struct connectdata *conn,
buf[len_out - 1] = '\0';
break;
}
+
+ if(len_out > MAX_NTLM_WB_RESPONSE) {
+ failf(conn->data, "too large ntlm_wb response!");
+ free(buf);
+ return CURLE_OUT_OF_MEMORY;
+ }
+
newbuf = Curl_saferealloc(buf, len_out + NTLM_BUFSIZE);
if(!newbuf)
return CURLE_OUT_OF_MEMORY;
@@ -320,12 +327,56 @@ static CURLcode ntlm_wb_response(struct connectdata *conn,
conn->response_header = aprintf("NTLM %.*s", len_out - 4, buf + 3);
free(buf);
+ if(!conn->response_header)
+ return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
done:
free(buf);
return CURLE_REMOTE_ACCESS_DENIED;
}
+CURLcode Curl_input_ntlm_wb(struct connectdata *conn,
+ bool proxy,
+ const char *header)
+{
+ curlntlm *state = proxy ? &conn->proxy_ntlm_state : &conn->http_ntlm_state;
+
+ if(!checkprefix("NTLM", header))
+ return CURLE_BAD_CONTENT_ENCODING;
+
+ header += strlen("NTLM");
+ while(*header && ISSPACE(*header))
+ header++;
+
+ if(*header) {
+ conn->challenge_header = strdup(header);
+ if(!conn->challenge_header)
+ return CURLE_OUT_OF_MEMORY;
+
+ *state = NTLMSTATE_TYPE2; /* We got a type-2 message */
+ }
+ else {
+ if(*state == NTLMSTATE_LAST) {
+ infof(conn->data, "NTLM auth restarted\n");
+ Curl_http_auth_cleanup_ntlm_wb(conn);
+ }
+ else if(*state == NTLMSTATE_TYPE3) {
+ infof(conn->data, "NTLM handshake rejected\n");
+ Curl_http_auth_cleanup_ntlm_wb(conn);
+ *state = NTLMSTATE_NONE;
+ return CURLE_REMOTE_ACCESS_DENIED;
+ }
+ else if(*state >= NTLMSTATE_TYPE1) {
+ infof(conn->data, "NTLM handshake failure (internal error)\n");
+ return CURLE_REMOTE_ACCESS_DENIED;
+ }
+
+ *state = NTLMSTATE_TYPE1; /* We should send away a type-1 */
+ }
+
+ return CURLE_OK;
+}
+
/*
* This is for creating ntlm header output by delegating challenge/response
* to Samba's winbind daemon helper ntlm_auth.
@@ -338,8 +389,7 @@ CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
char **allocuserpwd;
/* point to the name and password for this */
const char *userp;
- /* point to the correct struct with this */
- struct ntlmdata *ntlm;
+ curlntlm *state;
struct auth *authp;
CURLcode res = CURLE_OK;
@@ -351,26 +401,26 @@ CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
if(proxy) {
allocuserpwd = &conn->allocptr.proxyuserpwd;
userp = conn->http_proxy.user;
- ntlm = &conn->proxyntlm;
+ state = &conn->proxy_ntlm_state;
authp = &conn->data->state.authproxy;
}
else {
allocuserpwd = &conn->allocptr.userpwd;
userp = conn->user;
- ntlm = &conn->ntlm;
+ state = &conn->http_ntlm_state;
authp = &conn->data->state.authhost;
}
authp->done = FALSE;
/* not set means empty */
if(!userp)
- userp="";
+ userp = "";
- switch(ntlm->state) {
+ switch(*state) {
case NTLMSTATE_TYPE1:
default:
/* Use Samba's 'winbind' daemon to support NTLM authentication,
- * by delegating the NTLM challenge/response protocal to a helper
+ * by delegating the NTLM challenge/response protocol to a helper
* in ntlm_auth.
* http://devel.squid-cache.org/ntlm/squid_helper_protocol.html
* https://www.samba.org/samba/docs/man/manpages-3/winbindd.8.html
@@ -385,7 +435,7 @@ CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
res = ntlm_wb_init(conn, userp);
if(res)
return res;
- res = ntlm_wb_response(conn, "YR\n", ntlm->state);
+ res = ntlm_wb_response(conn, "YR\n", *state);
if(res)
return res;
@@ -395,13 +445,16 @@ CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
conn->response_header);
DEBUG_OUT(fprintf(stderr, "**** Header %s\n ", *allocuserpwd));
free(conn->response_header);
+ if(!*allocuserpwd)
+ return CURLE_OUT_OF_MEMORY;
conn->response_header = NULL;
break;
+
case NTLMSTATE_TYPE2:
input = aprintf("TT %s\n", conn->challenge_header);
if(!input)
return CURLE_OUT_OF_MEMORY;
- res = ntlm_wb_response(conn, input, ntlm->state);
+ res = ntlm_wb_response(conn, input, *state);
free(input);
input = NULL;
if(res)
@@ -412,15 +465,20 @@ CURLcode Curl_output_ntlm_wb(struct connectdata *conn,
proxy ? "Proxy-" : "",
conn->response_header);
DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
- ntlm->state = NTLMSTATE_TYPE3; /* we sent a type-3 */
+ *state = NTLMSTATE_TYPE3; /* we sent a type-3 */
authp->done = TRUE;
- Curl_ntlm_wb_cleanup(conn);
+ Curl_http_auth_cleanup_ntlm_wb(conn);
+ if(!*allocuserpwd)
+ return CURLE_OUT_OF_MEMORY;
break;
+
case NTLMSTATE_TYPE3:
/* connection is already authenticated,
* don't send a header in future requests */
- free(*allocuserpwd);
- *allocuserpwd=NULL;
+ *state = NTLMSTATE_LAST;
+ /* FALLTHROUGH */
+ case NTLMSTATE_LAST:
+ Curl_safefree(*allocuserpwd);
authp->done = TRUE;
break;
}
diff --git a/Utilities/cmcurl/lib/curl_ntlm_wb.h b/Utilities/cmcurl/lib/curl_ntlm_wb.h
index aba3d469c..3cf841cf2 100644
--- a/Utilities/cmcurl/lib/curl_ntlm_wb.h
+++ b/Utilities/cmcurl/lib/curl_ntlm_wb.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -27,11 +27,14 @@
#if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
defined(NTLM_WB_ENABLED)
-/* this is for creating ntlm header output by delegating challenge/response
- to Samba's winbind daemon helper ntlm_auth */
+/* this is for ntlm header input */
+CURLcode Curl_input_ntlm_wb(struct connectdata *conn, bool proxy,
+ const char *header);
+
+/* this is for creating ntlm header output */
CURLcode Curl_output_ntlm_wb(struct connectdata *conn, bool proxy);
-void Curl_ntlm_wb_cleanup(struct connectdata *conn);
+void Curl_http_auth_cleanup_ntlm_wb(struct connectdata *conn);
#endif /* !CURL_DISABLE_HTTP && USE_NTLM && NTLM_WB_ENABLED */
diff --git a/Utilities/cmcurl/lib/curl_printf.h b/Utilities/cmcurl/lib/curl_printf.h
index 49857cdb0..0d37b8e57 100644
--- a/Utilities/cmcurl/lib/curl_printf.h
+++ b/Utilities/cmcurl/lib/curl_printf.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -31,7 +31,7 @@
# undef printf
# undef fprintf
-# undef snprintf
+# undef msnprintf
# undef vprintf
# undef vfprintf
# undef vsnprintf
@@ -39,18 +39,10 @@
# undef vaprintf
# define printf curl_mprintf
# define fprintf curl_mfprintf
-# define snprintf curl_msnprintf
+# define msnprintf curl_msnprintf
# define vprintf curl_mvprintf
# define vfprintf curl_mvfprintf
-# define vsnprintf curl_mvsnprintf
+# define mvsnprintf curl_mvsnprintf
# define aprintf curl_maprintf
# define vaprintf curl_mvaprintf
-
-/* We define away the sprintf functions unconditonally since we don't want
- internal code to be using them, intentionally or by mistake!*/
-# undef sprintf
-# undef vsprintf
-# define sprintf sprintf_was_used
-# define vsprintf vsprintf_was_used
-
#endif /* HEADER_CURL_PRINTF_H */
diff --git a/Utilities/cmcurl/lib/curl_rtmp.c b/Utilities/cmcurl/lib/curl_rtmp.c
index 87a6caf9e..16b1de1ae 100644
--- a/Utilities/cmcurl/lib/curl_rtmp.c
+++ b/Utilities/cmcurl/lib/curl_rtmp.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2010, Howard Chu, <hyc@highlandsun.com>
*
* This software is licensed as described in the file COPYING, which
@@ -37,9 +37,11 @@
/* The last #include file should be: */
#include "memdebug.h"
-#ifdef _WIN32
+#if defined(WIN32) && !defined(USE_LWIPSOCK)
#define setsockopt(a,b,c,d,e) (setsockopt)(a,b,c,(const char *)d,(int)e)
#define SET_RCVTIMEO(tv,s) int tv = s*1000
+#elif defined(LWIP_SO_SNDRCVTIMEO_NONSTANDARD)
+#define SET_RCVTIMEO(tv,s) int tv = s*1000
#else
#define SET_RCVTIMEO(tv,s) struct timeval tv = {s,0}
#endif
@@ -74,6 +76,7 @@ const struct Curl_handler Curl_handler_rtmp = {
ZERO_NULL, /* perform_getsock */
rtmp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_RTMP, /* defport */
CURLPROTO_RTMP, /* protocol */
PROTOPT_NONE /* flags*/
@@ -94,6 +97,7 @@ const struct Curl_handler Curl_handler_rtmpt = {
ZERO_NULL, /* perform_getsock */
rtmp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_RTMPT, /* defport */
CURLPROTO_RTMPT, /* protocol */
PROTOPT_NONE /* flags*/
@@ -114,6 +118,7 @@ const struct Curl_handler Curl_handler_rtmpe = {
ZERO_NULL, /* perform_getsock */
rtmp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_RTMP, /* defport */
CURLPROTO_RTMPE, /* protocol */
PROTOPT_NONE /* flags*/
@@ -134,6 +139,7 @@ const struct Curl_handler Curl_handler_rtmpte = {
ZERO_NULL, /* perform_getsock */
rtmp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_RTMPT, /* defport */
CURLPROTO_RTMPTE, /* protocol */
PROTOPT_NONE /* flags*/
@@ -154,6 +160,7 @@ const struct Curl_handler Curl_handler_rtmps = {
ZERO_NULL, /* perform_getsock */
rtmp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_RTMPS, /* defport */
CURLPROTO_RTMPS, /* protocol */
PROTOPT_NONE /* flags*/
@@ -174,6 +181,7 @@ const struct Curl_handler Curl_handler_rtmpts = {
ZERO_NULL, /* perform_getsock */
rtmp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_RTMPS, /* defport */
CURLPROTO_RTMPTS, /* protocol */
PROTOPT_NONE /* flags*/
@@ -200,7 +208,7 @@ static CURLcode rtmp_connect(struct connectdata *conn, bool *done)
RTMP *r = conn->proto.generic;
SET_RCVTIMEO(tv, 10);
- r->m_sb.sb_socket = conn->sock[FIRSTSOCKET];
+ r->m_sb.sb_socket = (int)conn->sock[FIRSTSOCKET];
/* We have to know if it's a write before we send the
* connect request packet
@@ -231,17 +239,18 @@ static CURLcode rtmp_connect(struct connectdata *conn, bool *done)
static CURLcode rtmp_do(struct connectdata *conn, bool *done)
{
+ struct Curl_easy *data = conn->data;
RTMP *r = conn->proto.generic;
if(!RTMP_ConnectStream(r, 0))
return CURLE_FAILED_INIT;
if(conn->data->set.upload) {
- Curl_pgrsSetUploadSize(conn->data, conn->data->state.infilesize);
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
+ Curl_pgrsSetUploadSize(data, data->state.infilesize);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
}
else
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
*done = TRUE;
return CURLE_OK;
}
diff --git a/Utilities/cmcurl/lib/curl_sasl.c b/Utilities/cmcurl/lib/curl_sasl.c
index bd574b5e2..018e4228b 100644
--- a/Utilities/cmcurl/lib/curl_sasl.c
+++ b/Utilities/cmcurl/lib/curl_sasl.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2019, 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
@@ -31,6 +31,9 @@
#include "curl_setup.h"
+#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \
+ !defined(CURL_DISABLE_POP3)
+
#include <curl/curl.h>
#include "urldata.h"
@@ -83,14 +86,14 @@ void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused)
#if defined(USE_KERBEROS5)
/* Cleanup the gssapi structure */
if(authused == SASL_MECH_GSSAPI) {
- Curl_auth_gssapi_cleanup(&conn->krb5);
+ Curl_auth_cleanup_gssapi(&conn->krb5);
}
#endif
#if defined(USE_NTLM)
/* Cleanup the NTLM structure */
if(authused == SASL_MECH_NTLM) {
- Curl_auth_ntlm_cleanup(&conn->ntlm);
+ Curl_auth_cleanup_ntlm(&conn->ntlm);
}
#endif
@@ -146,7 +149,6 @@ CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
const char *value, size_t len)
{
CURLcode result = CURLE_OK;
- unsigned int mechbit;
size_t mechlen;
if(!len)
@@ -160,7 +162,7 @@ CURLcode Curl_sasl_parse_url_auth_option(struct SASL *sasl,
if(!strncmp(value, "*", len))
sasl->prefmech = SASL_AUTH_DEFAULT;
else {
- mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
+ unsigned int mechbit = Curl_sasl_decode_mech(value, len, &mechlen);
if(mechbit && mechlen == len)
sasl->prefmech |= mechbit;
else
@@ -265,7 +267,7 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
-#if defined(USE_KERBEROS5)
+#if defined(USE_KERBEROS5) || defined(USE_NTLM)
const char *service = data->set.str[STRING_SERVICE_NAME] ?
data->set.str[STRING_SERVICE_NAME] :
sasl->params->service;
@@ -291,7 +293,7 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
#if defined(USE_KERBEROS5)
if((enabledmechs & SASL_MECH_GSSAPI) && Curl_auth_is_gssapi_supported() &&
Curl_auth_user_contains_domain(conn->user)) {
- sasl->mutual_auth = FALSE; /* TODO: Calculate mutual authentication */
+ sasl->mutual_auth = FALSE;
mech = SASL_MECH_STRING_GSSAPI;
state1 = SASL_GSSAPI;
state2 = SASL_GSSAPI_TOKEN;
@@ -301,8 +303,7 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
result = Curl_auth_create_gssapi_user_message(data, conn->user,
conn->passwd,
service,
- data->easy_conn->
- host.name,
+ data->conn->host.name,
sasl->mutual_auth,
NULL, &conn->krb5,
&resp, &len);
@@ -331,8 +332,12 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
sasl->authused = SASL_MECH_NTLM;
if(force_ir || data->set.sasl_ir)
- result = Curl_auth_create_ntlm_type1_message(conn->user, conn->passwd,
- &conn->ntlm, &resp, &len);
+ result = Curl_auth_create_ntlm_type1_message(data,
+ conn->user, conn->passwd,
+ service,
+ hostname,
+ &conn->ntlm, &resp,
+ &len);
}
else
#endif
@@ -355,10 +360,18 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
sasl->authused = SASL_MECH_XOAUTH2;
if(force_ir || data->set.sasl_ir)
- result = Curl_auth_create_oauth_bearer_message(data, conn->user,
- NULL, 0,
- conn->oauth_bearer,
- &resp, &len);
+ result = Curl_auth_create_xoauth_bearer_message(data, conn->user,
+ conn->oauth_bearer,
+ &resp, &len);
+ }
+ else if(enabledmechs & SASL_MECH_PLAIN) {
+ mech = SASL_MECH_STRING_PLAIN;
+ state1 = SASL_PLAIN;
+ sasl->authused = SASL_MECH_PLAIN;
+
+ if(force_ir || data->set.sasl_ir)
+ result = Curl_auth_create_plain_message(data, NULL, conn->user,
+ conn->passwd, &resp, &len);
}
else if(enabledmechs & SASL_MECH_LOGIN) {
mech = SASL_MECH_STRING_LOGIN;
@@ -369,15 +382,6 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct connectdata *conn,
if(force_ir || data->set.sasl_ir)
result = Curl_auth_create_login_message(data, conn->user, &resp, &len);
}
- else if(enabledmechs & SASL_MECH_PLAIN) {
- mech = SASL_MECH_STRING_PLAIN;
- state1 = SASL_PLAIN;
- sasl->authused = SASL_MECH_PLAIN;
-
- if(force_ir || data->set.sasl_ir)
- result = Curl_auth_create_plain_message(data, conn->user, conn->passwd,
- &resp, &len);
- }
}
if(!result && mech) {
@@ -418,13 +422,11 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
char *chlg = NULL;
size_t chlglen = 0;
#endif
-#if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5)
+#if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
+ defined(USE_NTLM)
const char *service = data->set.str[STRING_SERVICE_NAME] ?
data->set.str[STRING_SERVICE_NAME] :
sasl->params->service;
-#endif
-#if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
- defined(USE_NTLM)
char *serverdata;
#endif
size_t len = 0;
@@ -451,9 +453,8 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
*progress = SASL_DONE;
return result;
case SASL_PLAIN:
- result = Curl_auth_create_plain_message(data, conn->user, conn->passwd,
- &resp,
- &len);
+ result = Curl_auth_create_plain_message(data, NULL, conn->user,
+ conn->passwd, &resp, &len);
break;
case SASL_LOGIN:
result = Curl_auth_create_login_message(data, conn->user, &resp, &len);
@@ -493,7 +494,9 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
#ifdef USE_NTLM
case SASL_NTLM:
/* Create the type-1 message */
- result = Curl_auth_create_ntlm_type1_message(conn->user, conn->passwd,
+ result = Curl_auth_create_ntlm_type1_message(data,
+ conn->user, conn->passwd,
+ service, hostname,
&conn->ntlm, &resp, &len);
newstate = SASL_NTLM_TYPE2MSG;
break;
@@ -514,7 +517,7 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
result = Curl_auth_create_gssapi_user_message(data, conn->user,
conn->passwd,
service,
- data->easy_conn->host.name,
+ data->conn->host.name,
sasl->mutual_auth, NULL,
&conn->krb5,
&resp, &len);
@@ -560,10 +563,9 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
newstate = SASL_OAUTH2_RESP;
}
else
- result = Curl_auth_create_oauth_bearer_message(data, conn->user,
- NULL, 0,
- conn->oauth_bearer,
- &resp, &len);
+ result = Curl_auth_create_xoauth_bearer_message(data, conn->user,
+ conn->oauth_bearer,
+ &resp, &len);
break;
case SASL_OAUTH2_RESP:
@@ -624,3 +626,4 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct connectdata *conn,
return result;
}
+#endif /* protocols are enabled that use SASL */
diff --git a/Utilities/cmcurl/lib/curl_setup.h b/Utilities/cmcurl/lib/curl_setup.h
index a6268adf2..efba5ddec 100644
--- a/Utilities/cmcurl/lib/curl_setup.h
+++ b/Utilities/cmcurl/lib/curl_setup.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,6 +22,10 @@
*
***************************************************************************/
+#if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES)
+#define CURL_NO_OLDIES
+#endif
+
/*
* Define WIN32 when build target is Win32 API
*/
@@ -31,6 +35,20 @@
#define WIN32
#endif
+#ifdef WIN32
+/*
+ * Don't include unneeded stuff in Windows headers to avoid compiler
+ * warnings and macro clashes.
+ * Make sure to define this macro before including any Windows headers.
+ */
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# ifndef NOGDI
+# define NOGDI
+# endif
+#endif
+
/*
* Include configuration script results or hand-crafted
* configuration file for platforms which lack config tool.
@@ -130,14 +148,7 @@
#include <curl/curl.h>
-/*
- * Ensure that no one is using the old SIZEOF_CURL_OFF_T macro
- */
-
-#ifdef SIZEOF_CURL_OFF_T
-# error "SIZEOF_CURL_OFF_T shall not be defined!"
- Error Compilation_aborted_SIZEOF_CURL_OFF_T_shall_not_be_defined
-#endif
+#define CURL_SIZEOF_CURL_OFF_T SIZEOF_CURL_OFF_T
/*
* Disable other protocols when http is the only one desired.
@@ -174,9 +185,6 @@
# ifndef CURL_DISABLE_SMTP
# define CURL_DISABLE_SMTP
# endif
-# ifndef CURL_DISABLE_RTMP
-# define CURL_DISABLE_RTMP
-# endif
# ifndef CURL_DISABLE_GOPHER
# define CURL_DISABLE_GOPHER
# endif
@@ -195,7 +203,7 @@
/* ================================================================ */
/* No system header file shall be included in this file before this */
-/* point. The only allowed ones are those included from curlbuild.h */
+/* point. The only allowed ones are those included from curl/system.h */
/* ================================================================ */
/*
@@ -216,7 +224,7 @@
/*
* Use getaddrinfo to resolve the IPv4 address literal. If the current network
- * interface doesn’t support IPv4, but supports IPv6, NAT64, and DNS64,
+ * interface doesn't support IPv4, but supports IPv6, NAT64, and DNS64,
* performing this task will result in a synthesized IPv6 address.
*/
#ifdef __APPLE__
@@ -241,9 +249,7 @@
# if defined(_UNICODE) && !defined(UNICODE)
# define UNICODE
# endif
-# ifndef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-# endif
+# include <winerror.h>
# include <windows.h>
# ifdef HAVE_WINSOCK2_H
# include <winsock2.h>
@@ -308,11 +314,12 @@
#endif
#ifdef __AMIGA__
-# ifndef __ixemul__
-# include <exec/types.h>
-# include <exec/execbase.h>
-# include <proto/exec.h>
-# include <proto/dos.h>
+# include <exec/types.h>
+# include <exec/execbase.h>
+# include <proto/exec.h>
+# include <proto/dos.h>
+# ifdef HAVE_PROTO_BSDSOCKET_H
+# include <proto/bsdsocket.h> /* ensure bsdsocket.library use */
# define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
# endif
#endif
@@ -402,6 +409,11 @@
# define LSEEK_ERROR (off_t)-1
#endif
+#ifndef SIZEOF_TIME_T
+/* assume default size of time_t to be 32 bit */
+#define SIZEOF_TIME_T 4
+#endif
+
/*
* Default sizeof(off_t) in case it hasn't been defined in config file.
*/
@@ -429,6 +441,41 @@
# endif
#endif
+#if (SIZEOF_CURL_OFF_T == 4)
+# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
+#else
+ /* assume CURL_SIZEOF_CURL_OFF_T == 8 */
+# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
+#endif
+#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
+
+#if (SIZEOF_TIME_T == 4)
+# ifdef HAVE_TIME_T_UNSIGNED
+# define TIME_T_MAX UINT_MAX
+# define TIME_T_MIN 0
+# else
+# define TIME_T_MAX INT_MAX
+# define TIME_T_MIN INT_MIN
+# endif
+#else
+# ifdef HAVE_TIME_T_UNSIGNED
+# define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
+# define TIME_T_MIN 0
+# else
+# define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
+# define TIME_T_MIN (-TIME_T_MAX - 1)
+# endif
+#endif
+
+#ifndef SIZE_T_MAX
+/* some limits.h headers have this defined, some don't */
+#if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
+#define SIZE_T_MAX 18446744073709551615U
+#else
+#define SIZE_T_MAX 4294967295U
+#endif
+#endif
+
/*
* Arg 2 type for gethostname in case it hasn't been defined in config file.
*/
@@ -612,17 +659,12 @@ int netware_init(void);
#error "Both libidn2 and WinIDN are enabled, choose one."
#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"
#if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_NSS) || \
- defined(USE_POLARSSL) || defined(USE_AXTLS) || defined(USE_MBEDTLS) || \
+ defined(USE_POLARSSL) || defined(USE_MBEDTLS) || \
defined(USE_CYASSL) || defined(USE_SCHANNEL) || \
- defined(USE_DARWINSSL) || defined(USE_GSKIT)
+ defined(USE_SECTRANSP) || defined(USE_GSKIT) || defined(USE_MESALINK)
#define USE_SSL /* SSL support has been enabled */
#endif
@@ -641,7 +683,7 @@ int netware_init(void);
/* Single point where USE_NTLM definition might be defined */
#if !defined(CURL_DISABLE_NTLM) && !defined(CURL_DISABLE_CRYPTO_AUTH)
#if defined(USE_OPENSSL) || defined(USE_WINDOWS_SSPI) || \
- defined(USE_GNUTLS) || defined(USE_NSS) || defined(USE_DARWINSSL) || \
+ defined(USE_GNUTLS) || defined(USE_NSS) || defined(USE_SECTRANSP) || \
defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
defined(USE_MBEDTLS)
@@ -655,9 +697,12 @@ int netware_init(void);
#endif
#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")
+#ifdef CURL_WANTS_CA_BUNDLE_ENV
+#error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
+#endif
+
+#if defined(USE_LIBSSH2) || defined(USE_LIBSSH) || defined(USE_WOLFSSH)
+#define USE_SSH
#endif
/*
@@ -731,6 +776,7 @@ Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
#if defined(WIN32) || defined(MSDOS)
#define FOPEN_READTEXT "rt"
#define FOPEN_WRITETEXT "wt"
+#define FOPEN_APPENDTEXT "at"
#elif defined(__CYGWIN__)
/* Cygwin has specific behavior we need to address when WIN32 is not defined.
https://cygwin.com/cygwin-ug-net/using-textbinary.html
@@ -740,9 +786,11 @@ endings either CRLF or LF so 't' is appropriate.
*/
#define FOPEN_READTEXT "rt"
#define FOPEN_WRITETEXT "w"
+#define FOPEN_APPENDTEXT "a"
#else
#define FOPEN_READTEXT "r"
#define FOPEN_WRITETEXT "w"
+#define FOPEN_APPENDTEXT "a"
#endif
/* WinSock destroys recv() buffer when send() failed.
@@ -754,20 +802,44 @@ endings either CRLF or LF so 't' is appropriate.
# if defined(WIN32) || defined(__CYGWIN__)
# define USE_RECV_BEFORE_SEND_WORKAROUND
# endif
-#else /* DONT_USE_RECV_BEFORE_SEND_WORKAROUNDS */
+#else /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
# ifdef USE_RECV_BEFORE_SEND_WORKAROUND
# undef USE_RECV_BEFORE_SEND_WORKAROUND
# endif
-#endif /* DONT_USE_RECV_BEFORE_SEND_WORKAROUNDS */
+#endif /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
/* Detect Windows App environment which has a restricted access
* to the Win32 APIs. */
-# if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
+# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
+ defined(WINAPI_FAMILY)
# include <winapifamily.h>
-# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
+# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define CURL_WINDOWS_APP
# endif
# endif
+/* for systems that don't detect this in configure, use a sensible default */
+#ifndef CURL_SA_FAMILY_T
+#define CURL_SA_FAMILY_T unsigned short
+#endif
+
+/* Some convenience macros to get the larger/smaller value out of two given.
+ We prefix with CURL to prevent name collisions. */
+#define CURLMAX(x,y) ((x)>(y)?(x):(y))
+#define CURLMIN(x,y) ((x)<(y)?(x):(y))
+
+/* Some versions of the Android SDK is missing the declaration */
+#if defined(HAVE_GETPWUID_R) && defined(HAVE_DECL_GETPWUID_R_MISSING)
+struct passwd;
+int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
+ size_t buflen, struct passwd **result);
+#endif
+
+#ifdef DEBUGBUILD
+#define UNITTEST
+#else
+#define UNITTEST static
+#endif
+
#endif /* HEADER_CURL_SETUP_H */
diff --git a/Utilities/cmcurl/lib/curl_setup_once.h b/Utilities/cmcurl/lib/curl_setup_once.h
index 684187cae..413ccea91 100644
--- a/Utilities/cmcurl/lib/curl_setup_once.h
+++ b/Utilities/cmcurl/lib/curl_setup_once.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -101,7 +101,6 @@
# endif
#endif
-
/*
* Definition of timeval struct for platforms that don't have it.
*/
@@ -274,25 +273,6 @@ struct timeval {
# define sfcntl fcntl
#endif
-/*
- * 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)))
-#define ISUPPER(x) (isupper((int) ((unsigned char)x)))
-#define ISLOWER(x) (islower((int) ((unsigned char)x)))
-#define ISASCII(x) (isascii((int) ((unsigned char)x)))
-
-#define ISBLANK(x) (int)((((unsigned char)x) == ' ') || \
- (((unsigned char)x) == '\t'))
-
#define TOLOWER(x) (tolower((int) ((unsigned char)x)))
@@ -347,6 +327,7 @@ struct timeval {
#define FALSE false
#endif
+#include "curl_ctype.h"
/*
* Macro WHILE_FALSE may be used to build single-iteration do-while loops,
@@ -436,20 +417,6 @@ typedef int sig_atomic_t;
/*
- * Macro ERRNO / SET_ERRNO() returns / sets the NOT *socket-related* errno
- * (or equivalent) on this platform to hide platform details to code using it.
- */
-
-#if defined(WIN32) && !defined(USE_LWIPSOCK)
-#define ERRNO ((int)GetLastError())
-#define SET_ERRNO(x) (SetLastError((DWORD)(x)))
-#else
-#define ERRNO (errno)
-#define SET_ERRNO(x) (errno = (x))
-#endif
-
-
-/*
* Portable error number symbolic names defined to Winsock error codes.
*/
@@ -548,4 +515,3 @@ typedef int sig_atomic_t;
#endif /* HEADER_CURL_SETUP_ONCE_H */
-
diff --git a/Utilities/cmcurl/lib/curl_sspi.c b/Utilities/cmcurl/lib/curl_sspi.c
index 11a7120a9..1d0de4ed3 100644
--- a/Utilities/cmcurl/lib/curl_sspi.c
+++ b/Utilities/cmcurl/lib/curl_sspi.c
@@ -90,8 +90,9 @@ CURLcode Curl_sspi_global_init(void)
return CURLE_FAILED_INIT;
/* Get address of the InitSecurityInterfaceA function from the SSPI dll */
- pInitSecurityInterface = (INITSECURITYINTERFACE_FN)
- GetProcAddress(s_hSecDll, SECURITYENTRYPOINT);
+ pInitSecurityInterface =
+ CURLX_FUNCTION_CAST(INITSECURITYINTERFACE_FN,
+ (GetProcAddress(s_hSecDll, SECURITYENTRYPOINT)));
if(!pInitSecurityInterface)
return CURLE_FAILED_INIT;
@@ -131,7 +132,7 @@ void Curl_sspi_global_cleanup(void)
* Parameters:
*
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* identity [in/out] - The identity structure.
*
* Returns CURLE_OK on success.
diff --git a/Utilities/cmcurl/lib/curl_threads.c b/Utilities/cmcurl/lib/curl_threads.c
index a78eff5c2..8e5937aa0 100644
--- a/Utilities/cmcurl/lib/curl_threads.c
+++ b/Utilities/cmcurl/lib/curl_threads.c
@@ -105,14 +105,30 @@ curl_thread_t Curl_thread_create(unsigned int (CURL_STDCALL *func) (void *),
void *arg)
{
#ifdef _WIN32_WCE
- return CreateThread(NULL, 0, func, arg, 0, NULL);
+ typedef HANDLE curl_win_thread_handle_t;
+#elif defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
+ typedef unsigned long curl_win_thread_handle_t;
#else
+ typedef uintptr_t curl_win_thread_handle_t;
+#endif
curl_thread_t t;
- t = (curl_thread_t)_beginthreadex(NULL, 0, func, arg, 0, NULL);
- if((t == 0) || (t == (curl_thread_t)-1L))
+ curl_win_thread_handle_t thread_handle;
+#ifdef _WIN32_WCE
+ thread_handle = CreateThread(NULL, 0, func, arg, 0, NULL);
+#else
+ thread_handle = _beginthreadex(NULL, 0, func, arg, 0, NULL);
+#endif
+ t = (curl_thread_t)thread_handle;
+ if((t == 0) || (t == LongToHandle(-1L))) {
+#ifdef _WIN32_WCE
+ DWORD gle = GetLastError();
+ errno = ((gle == ERROR_ACCESS_DENIED ||
+ gle == ERROR_NOT_ENOUGH_MEMORY) ?
+ EACCES : EINVAL);
+#endif
return curl_thread_t_null;
+ }
return t;
-#endif
}
void Curl_thread_destroy(curl_thread_t hnd)
diff --git a/Utilities/cmcurl/lib/curl_threads.h b/Utilities/cmcurl/lib/curl_threads.h
index 9e0d14a30..2a93644c5 100644
--- a/Utilities/cmcurl/lib/curl_threads.h
+++ b/Utilities/cmcurl/lib/curl_threads.h
@@ -38,7 +38,8 @@
# define curl_thread_t HANDLE
# define curl_thread_t_null (HANDLE)0
# if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_VISTA) || \
- (_WIN32_WINNT < _WIN32_WINNT_VISTA)
+ (_WIN32_WINNT < _WIN32_WINNT_VISTA) || \
+ (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR))
# define Curl_mutex_init(m) InitializeCriticalSection(m)
# else
# define Curl_mutex_init(m) InitializeCriticalSectionEx(m, 0, 1)
diff --git a/Utilities/cmcurl/lib/curlx.h b/Utilities/cmcurl/lib/curlx.h
index 6168dc119..3e9b516f8 100644
--- a/Utilities/cmcurl/lib/curlx.h
+++ b/Utilities/cmcurl/lib/curlx.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -42,16 +42,6 @@
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()
-*/
-
#include "nonblock.h"
/* "nonblock.h" provides curlx_nonblock() */
@@ -91,25 +81,23 @@
# undef printf
# undef fprintf
# undef sprintf
-# undef snprintf
+# undef msnprintf
# undef vprintf
# undef vfprintf
# undef vsprintf
-# undef vsnprintf
+# undef mvsnprintf
# undef aprintf
# undef vaprintf
# define printf curlx_mprintf
# define fprintf curlx_mfprintf
# define sprintf curlx_msprintf
-# define snprintf curlx_msnprintf
+# define msnprintf curlx_msnprintf
# define vprintf curlx_mvprintf
# define vfprintf curlx_mvfprintf
-# define vsprintf curlx_mvsprintf
-# define vsnprintf curlx_mvsnprintf
+# define mvsnprintf curlx_mvsnprintf
# define aprintf curlx_maprintf
# define vaprintf curlx_mvaprintf
#endif /* ENABLE_CURLX_PRINTF */
#endif /* HEADER_CURL_CURLX_H */
-
diff --git a/Utilities/cmcurl/lib/dict.c b/Utilities/cmcurl/lib/dict.c
index 451ec389a..208a2336f 100644
--- a/Utilities/cmcurl/lib/dict.c
+++ b/Utilities/cmcurl/lib/dict.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -85,6 +85,7 @@ const struct Curl_handler Curl_handler_dict = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_DICT, /* defport */
CURLPROTO_DICT, /* protocol */
PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */
@@ -94,17 +95,17 @@ static char *unescape_word(struct Curl_easy *data, const char *inputbuff)
{
char *newp = NULL;
char *dictp;
- char *ptr;
size_t len;
- char ch;
- int olen=0;
CURLcode result = Curl_urldecode(data, inputbuff, 0, &newp, &len, FALSE);
if(!newp || result)
return NULL;
- dictp = malloc(((size_t)len)*2 + 1); /* add one for terminating zero */
+ dictp = malloc(len*2 + 1); /* add one for terminating zero */
if(dictp) {
+ char *ptr;
+ char ch;
+ int olen = 0;
/* According to RFC2229 section 2.2, these letters need to be escaped with
\[letter] */
for(ptr = newp;
@@ -116,7 +117,7 @@ static char *unescape_word(struct Curl_easy *data, const char *inputbuff)
}
dictp[olen++] = ch;
}
- dictp[olen]=0;
+ dictp[olen] = 0;
}
free(newp);
return dictp;
@@ -131,12 +132,11 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
char *strategy = NULL;
char *nthdef = NULL; /* This is not part of the protocol, but required
by RFC 2229 */
- CURLcode result=CURLE_OK;
- struct Curl_easy *data=conn->data;
+ CURLcode result = CURLE_OK;
+ struct Curl_easy *data = conn->data;
curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
- char *path = data->state.path;
- curl_off_t *bytecount = &data->req.bytecount;
+ char *path = data->state.up.path;
*done = TRUE; /* unconditionally */
@@ -167,7 +167,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
if((word == NULL) || (*word == (char)0)) {
infof(data, "lookup word is missing\n");
- word=(char *)"default";
+ word = (char *)"default";
}
if((database == NULL) || (*database == (char)0)) {
database = (char *)"!";
@@ -199,8 +199,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
failf(data, "Failed sending DICT request");
return result;
}
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
- -1, NULL); /* no upload */
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1); /* no upload */
}
else if(strncasecompare(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
strncasecompare(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
@@ -221,7 +220,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
if((word == NULL) || (*word == (char)0)) {
infof(data, "lookup word is missing\n");
- word=(char *)"default";
+ word = (char *)"default";
}
if((database == NULL) || (*database == (char)0)) {
database = (char *)"!";
@@ -246,8 +245,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
failf(data, "Failed sending DICT request");
return result;
}
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
- -1, NULL); /* no upload */
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
}
else {
@@ -269,7 +267,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
return result;
}
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
}
}
diff --git a/Utilities/cmcurl/lib/dotdot.c b/Utilities/cmcurl/lib/dotdot.c
index 20603bcab..2c6177aea 100644
--- a/Utilities/cmcurl/lib/dotdot.c
+++ b/Utilities/cmcurl/lib/dotdot.c
@@ -55,13 +55,15 @@ char *Curl_dedotdotify(const char *input)
size_t inlen = strlen(input);
char *clone;
size_t clen = inlen; /* the length of the cloned input */
- char *out = malloc(inlen+1);
+ char *out = malloc(inlen + 1);
char *outptr;
char *orgclone;
char *queryp;
if(!out)
return NULL; /* out of memory */
+ *out = 0; /* zero terminates, for inputs like "./" */
+
/* get a cloned copy of the input */
clone = strdup(input);
if(!clone) {
@@ -92,25 +94,25 @@ char *Curl_dedotdotify(const char *input)
remove that prefix from the input buffer; otherwise, */
if(!strncmp("./", clone, 2)) {
- clone+=2;
- clen-=2;
+ clone += 2;
+ clen -= 2;
}
else if(!strncmp("../", clone, 3)) {
- clone+=3;
- clen-=3;
+ clone += 3;
+ clen -= 3;
}
/* B. if the input buffer begins with a prefix of "/./" or "/.", where
"." is a complete path segment, then replace that prefix with "/" in
the input buffer; otherwise, */
else if(!strncmp("/./", clone, 3)) {
- clone+=2;
- clen-=2;
+ clone += 2;
+ clen -= 2;
}
else if(!strcmp("/.", clone)) {
clone[1]='/';
clone++;
- clen-=1;
+ clen -= 1;
}
/* C. if the input buffer begins with a prefix of "/../" or "/..", where
@@ -119,8 +121,8 @@ char *Curl_dedotdotify(const char *input)
any) from the output buffer; otherwise, */
else if(!strncmp("/../", clone, 4)) {
- clone+=3;
- clen-=3;
+ clone += 3;
+ clen -= 3;
/* remove the last segment from the output buffer */
while(outptr > out) {
outptr--;
@@ -131,8 +133,8 @@ char *Curl_dedotdotify(const char *input)
}
else if(!strcmp("/..", clone)) {
clone[2]='/';
- clone+=2;
- clen-=2;
+ clone += 2;
+ clen -= 2;
/* remove the last segment from the output buffer */
while(outptr > out) {
outptr--;
@@ -146,8 +148,8 @@ char *Curl_dedotdotify(const char *input)
that from the input buffer; otherwise, */
else if(!strcmp(".", clone) || !strcmp("..", clone)) {
- *clone=0;
- *out=0;
+ *clone = 0;
+ *out = 0;
}
else {
@@ -172,7 +174,7 @@ char *Curl_dedotdotify(const char *input)
from the correct index. */
size_t oindex = queryp - orgclone;
qlen = strlen(&input[oindex]);
- memcpy(outptr, &input[oindex], qlen+1); /* include the ending zero byte */
+ memcpy(outptr, &input[oindex], qlen + 1); /* include the end zero byte */
}
free(orgclone);
diff --git a/Utilities/cmcurl/lib/dotdot.h b/Utilities/cmcurl/lib/dotdot.h
index fac8e6f2a..125af4367 100644
--- a/Utilities/cmcurl/lib/dotdot.h
+++ b/Utilities/cmcurl/lib/dotdot.h
@@ -22,4 +22,4 @@
*
***************************************************************************/
char *Curl_dedotdotify(const char *input);
-#endif
+#endif /* HEADER_CURL_DOTDOT_H */
diff --git a/Utilities/cmcurl/lib/easy.c b/Utilities/cmcurl/lib/easy.c
index 2b1ce9e8a..4a6f96567 100644
--- a/Utilities/cmcurl/lib/easy.c
+++ b/Utilities/cmcurl/lib/easy.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -61,17 +61,22 @@
#include "strdup.h"
#include "progress.h"
#include "easyif.h"
+#include "multiif.h"
#include "select.h"
#include "sendf.h" /* for failf function prototype */
#include "connect.h" /* for Curl_getconnectinfo */
#include "slist.h"
+#include "mime.h"
#include "amigaos.h"
#include "non-ascii.h"
#include "warnless.h"
-#include "conncache.h"
#include "multiif.h"
#include "sigpipe.h"
#include "ssh.h"
+#include "setopt.h"
+#include "http_digest.h"
+#include "system_win32.h"
+
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -79,70 +84,6 @@
void Curl_version_init(void);
-/* win32_cleanup() is for win32 socket cleanup functionality, the opposite
- of win32_init() */
-static void win32_cleanup(void)
-{
-#ifdef USE_WINSOCK
- WSACleanup();
-#endif
-#ifdef USE_WINDOWS_SSPI
- Curl_sspi_global_cleanup();
-#endif
-}
-
-/* win32_init() performs win32 socket initialization to properly setup the
- stack to allow networking */
-static CURLcode win32_init(void)
-{
-#ifdef USE_WINSOCK
- WORD wVersionRequested;
- WSADATA wsaData;
- int res;
-
-#if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
- Error IPV6_requires_winsock2
-#endif
-
- wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
-
- res = WSAStartup(wVersionRequested, &wsaData);
-
- if(res != 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. */
-#elif defined(USE_LWIPSOCK)
- lwip_init();
-#endif
-
-#ifdef USE_WINDOWS_SSPI
- {
- CURLcode result = Curl_sspi_global_init();
- if(result)
- return result;
- }
-#endif
-
- return CURLE_OK;
-}
-
/* true globals -- for curl_global_init() and curl_global_cleanup() */
static unsigned int initialized;
static long init_flags;
@@ -214,17 +155,17 @@ static CURLcode global_init(long flags, bool memoryfuncs)
#endif
}
- if(flags & CURL_GLOBAL_SSL)
- if(!Curl_ssl_init()) {
- DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
- return CURLE_FAILED_INIT;
- }
+ if(!Curl_ssl_init()) {
+ DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
+ return CURLE_FAILED_INIT;
+ }
- if(flags & CURL_GLOBAL_WIN32)
- if(win32_init()) {
- DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
- return CURLE_FAILED_INIT;
- }
+#ifdef WIN32
+ if(Curl_win32_init(flags)) {
+ DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
+ return CURLE_FAILED_INIT;
+ }
+#endif
#ifdef __AMIGA__
if(!Curl_amiga_init()) {
@@ -253,6 +194,13 @@ static CURLcode global_init(long flags, bool memoryfuncs)
}
#endif
+#if defined(USE_LIBSSH)
+ if(ssh_init()) {
+ DEBUGF(fprintf(stderr, "Error: libssh_init failed\n"));
+ return CURLE_FAILED_INIT;
+ }
+#endif
+
if(flags & CURL_GLOBAL_ACK_EINTR)
Curl_ack_eintr = 1;
@@ -317,15 +265,12 @@ void curl_global_cleanup(void)
if(--initialized)
return;
- Curl_global_host_cache_dtor();
-
- if(init_flags & CURL_GLOBAL_SSL)
- Curl_ssl_cleanup();
-
+ Curl_ssl_cleanup();
Curl_resolver_global_cleanup();
- if(init_flags & CURL_GLOBAL_WIN32)
- win32_cleanup();
+#ifdef WIN32
+ Curl_win32_cleanup(init_flags);
+#endif
Curl_amiga_cleanup();
@@ -333,6 +278,10 @@ void curl_global_cleanup(void)
(void)libssh2_exit();
#endif
+#if defined(USE_LIBSSH)
+ (void)ssh_finalize();
+#endif
+
init_flags = 0;
}
@@ -365,28 +314,6 @@ struct Curl_easy *curl_easy_init(void)
return data;
}
-/*
- * curl_easy_setopt() is the external interface for setting options on an
- * easy handle.
- */
-
-#undef curl_easy_setopt
-CURLcode curl_easy_setopt(struct Curl_easy *data, CURLoption tag, ...)
-{
- va_list arg;
- CURLcode result;
-
- if(!data)
- return CURLE_BAD_FUNCTION_ARGUMENT;
-
- va_start(arg, tag);
-
- result = Curl_setopt(data, tag, arg);
-
- va_end(arg);
- return result;
-}
-
#ifdef CURLDEBUG
struct socketmonitor {
@@ -433,7 +360,7 @@ static int events_timer(struct Curl_multi *multi, /* multi handle */
*/
static int poll2cselect(int pollmask)
{
- int omask=0;
+ int omask = 0;
if(pollmask & POLLIN)
omask |= CURL_CSELECT_IN;
if(pollmask & POLLOUT)
@@ -450,7 +377,7 @@ static int poll2cselect(int pollmask)
*/
static short socketcb2poll(int pollmask)
{
- short omask=0;
+ short omask = 0;
if(pollmask & CURL_POLL_IN)
omask |= POLLIN;
if(pollmask & CURL_POLL_OUT)
@@ -473,7 +400,7 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */
{
struct events *ev = userp;
struct socketmonitor *m;
- struct socketmonitor *prev=NULL;
+ struct socketmonitor *prev = NULL;
#if defined(CURL_DISABLE_VERBOSE_STRINGS)
(void) easy;
@@ -500,8 +427,8 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */
mask. Convert from libcurl bitmask to the poll one. */
m->socket.events = socketcb2poll(what);
infof(easy, "socket cb: socket %d UPDATED as %s%s\n", s,
- what&CURL_POLL_IN?"IN":"",
- what&CURL_POLL_OUT?"OUT":"");
+ (what&CURL_POLL_IN)?"IN":"",
+ (what&CURL_POLL_OUT)?"OUT":"");
}
break;
}
@@ -524,8 +451,8 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */
m->socket.revents = 0;
ev->list = m;
infof(easy, "socket cb: socket %d ADDED as %s%s\n", s,
- what&CURL_POLL_IN?"IN":"",
- what&CURL_POLL_OUT?"OUT":"");
+ (what&CURL_POLL_IN)?"IN":"",
+ (what&CURL_POLL_OUT)?"OUT":"");
}
else
return CURLE_OUT_OF_MEMORY;
@@ -569,14 +496,14 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
struct socketmonitor *m;
struct pollfd *f;
struct pollfd fds[4];
- int numfds=0;
+ int numfds = 0;
int pollrc;
int i;
- struct timeval before;
- struct timeval after;
+ struct curltime before;
+ struct curltime after;
/* populate the fds[] array */
- for(m = ev->list, f=&fds[0]; m; m = m->next) {
+ for(m = ev->list, f = &fds[0]; m; m = m->next) {
f->fd = m->socket.fd;
f->events = m->socket.events;
f->revents = 0;
@@ -586,12 +513,12 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
}
/* get the time stamp to use to figure out how long poll takes */
- before = curlx_tvnow();
+ before = Curl_now();
/* wait for activity or timeout */
pollrc = Curl_poll(fds, numfds, (int)ev->ms);
- after = curlx_tvnow();
+ after = Curl_now();
ev->msbump = FALSE; /* reset here */
@@ -619,7 +546,7 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
/* If nothing updated the timeout, we decrease it by the spent time.
* If it was updated, it has the new timeout time stored already.
*/
- time_t timediff = curlx_tvdiff(after, before);
+ timediff_t timediff = Curl_timediff(after, before);
if(timediff > 0) {
if(timediff > ev->ms)
ev->ms = 0;
@@ -632,7 +559,7 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
return CURLE_RECV_ERROR;
if(mcode)
- return CURLE_URL_MALFORMAT; /* TODO: return a proper error! */
+ return CURLE_URL_MALFORMAT;
/* we don't really care about the "msgs_in_queue" value returned in the
second argument */
@@ -653,7 +580,9 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
*/
static CURLcode easy_events(struct Curl_multi *multi)
{
- struct events evs= {2, FALSE, 0, NULL, 0};
+ /* this struct is made static to allow it to be used after this function
+ returns and curl_multi_remove_handle() is called */
+ static struct events evs = {2, FALSE, 0, NULL, 0};
/* if running event-based, do some further multi inits */
events_setup(multi, &evs);
@@ -670,44 +599,34 @@ static CURLcode easy_transfer(struct Curl_multi *multi)
bool done = FALSE;
CURLMcode mcode = CURLM_OK;
CURLcode result = CURLE_OK;
- struct timeval before;
- int without_fds = 0; /* count number of consecutive returns from
- curl_multi_wait() without any filedescriptors */
while(!done && !mcode) {
int still_running = 0;
- int rc;
+ bool gotsocket = FALSE;
- before = curlx_tvnow();
- mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
+ mcode = Curl_multi_wait(multi, NULL, 0, 1000, NULL, &gotsocket);
if(!mcode) {
- if(!rc) {
- struct timeval after = curlx_tvnow();
+ if(!gotsocket) {
+ long sleep_ms;
/* If it returns without any filedescriptor instantly, we need to
avoid busy-looping during periods where it has nothing particular
to wait for */
- if(curlx_tvdiff(after, before) <= 10) {
- without_fds++;
- if(without_fds > 2) {
- int sleep_ms = without_fds < 10 ? (1 << (without_fds - 1)) : 1000;
- Curl_wait_ms(sleep_ms);
- }
+ curl_multi_timeout(multi, &sleep_ms);
+ if(sleep_ms) {
+ if(sleep_ms > 1000)
+ sleep_ms = 1000;
+ Curl_wait_ms((int)sleep_ms);
}
- else
- /* it wasn't "instant", restart counter */
- without_fds = 0;
}
- else
- /* got file descriptor, restart counter */
- without_fds = 0;
mcode = curl_multi_perform(multi, &still_running);
}
/* only read 'still_running' if curl_multi_perform() return OK */
if(!mcode && !still_running) {
+ int rc;
CURLMsg *msg = curl_multi_info_read(multi, &rc);
if(msg) {
result = msg->data.result;
@@ -755,6 +674,10 @@ static CURLcode easy_perform(struct Curl_easy *data, bool events)
if(!data)
return CURLE_BAD_FUNCTION_ARGUMENT;
+ if(data->set.errorbuffer)
+ /* clear this as early as possible */
+ data->set.errorbuffer[0] = 0;
+
if(data->multi) {
failf(data, "easy handle already used in multi handle");
return CURLE_FAILED_INIT;
@@ -771,6 +694,9 @@ static CURLcode easy_perform(struct Curl_easy *data, bool events)
data->multi_easy = multi;
}
+ if(multi->in_callback)
+ return CURLE_RECURSIVE_API_CALL;
+
/* Copy the MAXCONNECTS option to the multi handle */
curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, data->set.maxconnects);
@@ -859,6 +785,47 @@ CURLcode curl_easy_getinfo(struct Curl_easy *data, CURLINFO info, ...)
return result;
}
+static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
+{
+ CURLcode result = CURLE_OK;
+ enum dupstring i;
+
+ /* Copy src->set into dst->set first, then deal with the strings
+ afterwards */
+ dst->set = src->set;
+ Curl_mime_initpart(&dst->set.mimepost, dst);
+
+ /* clear all string pointers first */
+ memset(dst->set.str, 0, STRING_LAST * sizeof(char *));
+
+ /* duplicate all strings */
+ for(i = (enum dupstring)0; i< STRING_LASTZEROTERMINATED; i++) {
+ result = Curl_setstropt(&dst->set.str[i], src->set.str[i]);
+ if(result)
+ return result;
+ }
+
+ /* duplicate memory areas pointed to */
+ i = STRING_COPYPOSTFIELDS;
+ if(src->set.postfieldsize && src->set.str[i]) {
+ /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
+ dst->set.str[i] = Curl_memdup(src->set.str[i],
+ curlx_sotouz(src->set.postfieldsize));
+ if(!dst->set.str[i])
+ return CURLE_OUT_OF_MEMORY;
+ /* point to the new copy */
+ dst->set.postfields = dst->set.str[i];
+ }
+
+ /* Duplicate mime data. */
+ result = Curl_mime_duppart(&dst->set.mimepost, &src->set.mimepost);
+
+ if(src->set.resolve)
+ dst->change.resolve = dst->set.resolve;
+
+ return result;
+}
+
/*
* 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
@@ -886,7 +853,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
outcurl->state.headersize = HEADERSIZE;
/* copy all userdefined values */
- if(Curl_dupset(outcurl, data))
+ if(dupset(outcurl, data))
goto fail;
/* the connection cache is setup on demand */
@@ -930,8 +897,16 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
outcurl->change.referer_alloc = TRUE;
}
+ /* Reinitialize an SSL engine for the new handle
+ * note: the engine name has already been copied by dupset */
+ if(outcurl->set.str[STRING_SSL_ENGINE]) {
+ if(Curl_ssl_set_engine(outcurl, outcurl->set.str[STRING_SSL_ENGINE]))
+ goto fail;
+ }
+
/* Clone the resolver handle, if present, for the new handle */
- if(Curl_resolver_duphandle(&outcurl->state.resolver,
+ if(Curl_resolver_duphandle(outcurl,
+ &outcurl->state.resolver,
data->state.resolver))
goto fail;
@@ -967,16 +942,12 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data)
*/
void curl_easy_reset(struct Curl_easy *data)
{
- Curl_safefree(data->state.pathbuffer);
-
- data->state.path = NULL;
-
Curl_free_request_state(data);
/* zero out UserDefined data: */
Curl_freeset(data);
memset(&data->set, 0, sizeof(struct UserDefined));
- (void)Curl_init_userdefined(&data->set);
+ (void)Curl_init_userdefined(data);
/* zero out Progress data: */
memset(&data->progress, 0, sizeof(struct Progress));
@@ -990,6 +961,10 @@ void curl_easy_reset(struct Curl_easy *data)
/* zero out authentication data: */
memset(&data->state.authhost, 0, sizeof(struct auth));
memset(&data->state.authproxy, 0, sizeof(struct auth));
+
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
+ Curl_http_auth_cleanup_digest(data);
+#endif
}
/*
@@ -1001,6 +976,9 @@ void curl_easy_reset(struct Curl_easy *data)
* the pausing, you may get your write callback called at this point.
*
* Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
+ *
+ * NOTE: This is one of few API functions that are allowed to be called from
+ * within a callback.
*/
CURLcode curl_easy_pause(struct Curl_easy *data, int action)
{
@@ -1023,24 +1001,35 @@ CURLcode curl_easy_pause(struct Curl_easy *data, int action)
unsigned int i;
unsigned int count = data->state.tempcount;
struct tempbuf writebuf[3]; /* there can only be three */
+ struct connectdata *conn = data->conn;
+ struct Curl_easy *saved_data = NULL;
/* copy the structs to allow for immediate re-pausing */
- for(i=0; i < data->state.tempcount; i++) {
+ for(i = 0; i < data->state.tempcount; i++) {
writebuf[i] = data->state.tempwrite[i];
data->state.tempwrite[i].buf = NULL;
}
data->state.tempcount = 0;
- for(i=0; i < count; i++) {
+ /* set the connection's current owner */
+ if(conn->data != data) {
+ saved_data = conn->data;
+ conn->data = data;
+ }
+
+ for(i = 0; i < count; i++) {
/* even if one function returns error, this loops through and frees all
buffers */
if(!result)
- result = Curl_client_chop_write(data->easy_conn,
- writebuf[i].type,
- writebuf[i].buf,
- writebuf[i].len);
+ result = Curl_client_write(conn, writebuf[i].type, writebuf[i].buf,
+ writebuf[i].len);
free(writebuf[i].buf);
}
+
+ /* recover previous owner of the connection */
+ if(saved_data)
+ conn->data = saved_data;
+
if(result)
return result;
}
@@ -1052,6 +1041,10 @@ CURLcode curl_easy_pause(struct Curl_easy *data, int action)
(KEEP_RECV_PAUSE|KEEP_SEND_PAUSE)) )
Curl_expire(data, 0, EXPIRE_RUN_NOW); /* get this handle going again */
+ /* This transfer may have been moved in or out of the bundle, update
+ the corresponding socket callback, if used */
+ Curl_updatesocket(data);
+
return result;
}
@@ -1092,6 +1085,9 @@ CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
ssize_t n1;
struct connectdata *c;
+ if(Curl_is_in_callback(data))
+ return CURLE_RECURSIVE_API_CALL;
+
result = easy_connection(data, &sfd, &c);
if(result)
return result;
@@ -1119,6 +1115,9 @@ CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
ssize_t n1;
struct connectdata *c = NULL;
+ if(Curl_is_in_callback(data))
+ return CURLE_RECURSIVE_API_CALL;
+
result = easy_connection(data, &sfd, &c);
if(result)
return result;
@@ -1137,3 +1136,22 @@ CURLcode curl_easy_send(struct Curl_easy *data, const void *buffer,
return result;
}
+
+/*
+ * Performs connection upkeep for the given session handle.
+ */
+CURLcode curl_easy_upkeep(struct Curl_easy *data)
+{
+ /* Verify that we got an easy handle we can work with. */
+ if(!GOOD_EASY_HANDLE(data))
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ if(data->multi_easy) {
+ /* Use the common function to keep connections alive. */
+ return Curl_upkeep(&data->multi_easy->conn_cache, data);
+ }
+ else {
+ /* No connections, so just return success */
+ return CURLE_OK;
+ }
+}
diff --git a/Utilities/cmcurl/lib/easyif.h b/Utilities/cmcurl/lib/easyif.h
index f6132cc70..6ba7e549d 100644
--- a/Utilities/cmcurl/lib/easyif.h
+++ b/Utilities/cmcurl/lib/easyif.h
@@ -30,4 +30,3 @@ CURL_EXTERN CURLcode curl_easy_perform_ev(struct Curl_easy *easy);
#endif
#endif /* HEADER_CURL_EASYIF_H */
-
diff --git a/Utilities/cmcurl/lib/escape.c b/Utilities/cmcurl/lib/escape.c
index 973aeb6ea..7121db31c 100644
--- a/Utilities/cmcurl/lib/escape.c
+++ b/Utilities/cmcurl/lib/escape.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -41,7 +41,7 @@
its behavior is altered by the current locale.
See https://tools.ietf.org/html/rfc3986#section-2.3
*/
-static bool Curl_isunreserved(unsigned char in)
+bool Curl_isunreserved(unsigned char in)
{
switch(in) {
case '0': case '1': case '2': case '3': case '4':
@@ -82,16 +82,15 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string,
size_t alloc;
char *ns;
char *testing_ptr = NULL;
- unsigned char in; /* we need to treat the characters unsigned */
size_t newlen;
- size_t strindex=0;
+ size_t strindex = 0;
size_t length;
CURLcode result;
if(inlength < 0)
return NULL;
- alloc = (inlength?(size_t)inlength:strlen(string))+1;
+ alloc = (inlength?(size_t)inlength:strlen(string)) + 1;
newlen = alloc;
ns = malloc(alloc);
@@ -100,11 +99,11 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string,
length = alloc-1;
while(length--) {
- in = *string;
+ unsigned char in = *string; /* we need to treat the characters unsigned */
if(Curl_isunreserved(in))
/* just copy this */
- ns[strindex++]=in;
+ ns[strindex++] = in;
else {
/* encode it */
newlen += 2; /* the size grows with two, since this'll become a %XX */
@@ -116,20 +115,20 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string,
ns = testing_ptr;
}
- result = Curl_convert_to_network(data, &in, 1);
+ result = Curl_convert_to_network(data, (char *)&in, 1);
if(result) {
/* Curl_convert_to_network calls failf if unsuccessful */
free(ns);
return NULL;
}
- snprintf(&ns[strindex], 4, "%%%02X", in);
+ msnprintf(&ns[strindex], 4, "%%%02X", in);
- strindex+=3;
+ strindex += 3;
}
string++;
}
- ns[strindex]=0; /* terminate it */
+ ns[strindex] = 0; /* terminate it */
return ns;
}
@@ -142,24 +141,25 @@ char *curl_easy_escape(struct Curl_easy *data, const char *string,
* Returns a pointer to a malloced string in *ostring with length given in
* *olen. If length == 0, the length is assumed to be strlen(string).
*
+ * 'data' can be set to NULL but then this function can't convert network
+ * data to host for non-ascii.
*/
CURLcode Curl_urldecode(struct Curl_easy *data,
const char *string, size_t length,
char **ostring, size_t *olen,
bool reject_ctrl)
{
- size_t alloc = (length?length:strlen(string))+1;
+ size_t alloc = (length?length:strlen(string)) + 1;
char *ns = malloc(alloc);
- unsigned char in;
- size_t strindex=0;
+ size_t strindex = 0;
unsigned long hex;
- CURLcode result;
+ CURLcode result = CURLE_OK;
if(!ns)
return CURLE_OUT_OF_MEMORY;
while(--alloc > 0) {
- in = *string;
+ unsigned char in = *string;
if(('%' == in) && (alloc > 2) &&
ISXDIGIT(string[1]) && ISXDIGIT(string[2])) {
/* this is two hexadecimal digits following a '%' */
@@ -173,15 +173,17 @@ CURLcode Curl_urldecode(struct Curl_easy *data,
in = curlx_ultouc(hex); /* this long is never bigger than 255 anyway */
- result = Curl_convert_from_network(data, &in, 1);
- if(result) {
- /* Curl_convert_from_network calls failf if unsuccessful */
- free(ns);
- return result;
+ if(data) {
+ result = Curl_convert_from_network(data, (char *)&in, 1);
+ if(result) {
+ /* Curl_convert_from_network calls failf if unsuccessful */
+ free(ns);
+ return result;
+ }
}
- string+=2;
- alloc-=2;
+ string += 2;
+ alloc -= 2;
}
if(reject_ctrl && (in < 0x20)) {
@@ -192,7 +194,7 @@ CURLcode Curl_urldecode(struct Curl_easy *data,
ns[strindex++] = in;
string++;
}
- ns[strindex]=0; /* terminate it */
+ ns[strindex] = 0; /* terminate it */
if(olen)
/* store output size */
diff --git a/Utilities/cmcurl/lib/escape.h b/Utilities/cmcurl/lib/escape.h
index 638666f03..d8bbe5cb0 100644
--- a/Utilities/cmcurl/lib/escape.h
+++ b/Utilities/cmcurl/lib/escape.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -24,10 +24,10 @@
/* Escape and unescape URL encoding in strings. The functions return a new
* allocated string or NULL if an error occurred. */
+bool Curl_isunreserved(unsigned char in);
CURLcode Curl_urldecode(struct Curl_easy *data,
const char *string, size_t length,
char **ostring, size_t *olen,
bool reject_crlf);
#endif /* HEADER_CURL_ESCAPE_H */
-
diff --git a/Utilities/cmcurl/lib/file.c b/Utilities/cmcurl/lib/file.c
index c804d75e1..d349cd924 100644
--- a/Utilities/cmcurl/lib/file.c
+++ b/Utilities/cmcurl/lib/file.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -61,6 +61,7 @@
#include "url.h"
#include "parsedate.h" /* for the week day and month names */
#include "warnless.h"
+#include "curl_range.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -108,6 +109,7 @@ const struct Curl_handler Curl_handler_file = {
ZERO_NULL, /* perform_getsock */
file_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
0, /* defport */
CURLPROTO_FILE, /* protocol */
PROTOPT_NONETWORK | PROTOPT_NOURLQUERY /* flags */
@@ -124,60 +126,6 @@ static CURLcode file_setup_connection(struct connectdata *conn)
return CURLE_OK;
}
- /*
- Check if this is a range download, and if so, set the internal variables
- properly. This code is copied from the FTP implementation and might as
- well be factored out.
- */
-static CURLcode file_range(struct connectdata *conn)
-{
- curl_off_t from, to;
- curl_off_t totalsize=-1;
- char *ptr;
- char *ptr2;
- struct Curl_easy *data = conn->data;
-
- if(data->state.use_range && data->state.range) {
- from=curlx_strtoofft(data->state.range, &ptr, 0);
- while(*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->state.resume_from = from;
- DEBUGF(infof(data, "RANGE %" CURL_FORMAT_CURL_OFF_T " to end of file\n",
- from));
- }
- else if(from < 0) {
- /* -Y */
- data->req.maxdownload = -from;
- data->state.resume_from = from;
- DEBUGF(infof(data, "RANGE the last %" CURL_FORMAT_CURL_OFF_T " bytes\n",
- -from));
- }
- else {
- /* X-Y */
- totalsize = to-from;
- data->req.maxdownload = totalsize+1; /* include last byte */
- data->state.resume_from = from;
- DEBUGF(infof(data, "RANGE from %" CURL_FORMAT_CURL_OFF_T
- " getting %" CURL_FORMAT_CURL_OFF_T " bytes\n",
- from, data->req.maxdownload));
- }
- DEBUGF(infof(data, "range-download from %" CURL_FORMAT_CURL_OFF_T
- " to %" CURL_FORMAT_CURL_OFF_T ", totally %"
- CURL_FORMAT_CURL_OFF_T " bytes\n",
- from, to, data->req.maxdownload));
- }
- else
- data->req.maxdownload = -1;
- return CURLE_OK;
-}
-
/*
* file_connect() gets called from Curl_protocol_connect() to allow us to
* do protocol-specific actions at connect-time. We emulate a
@@ -195,7 +143,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
#endif
size_t real_path_len;
- CURLcode result = Curl_urldecode(data, data->state.path, 0, &real_path,
+ CURLcode result = Curl_urldecode(data, data->state.up.path, 0, &real_path,
&real_path_len, FALSE);
if(result)
return result;
@@ -225,7 +173,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
}
/* change path separators from '/' to '\\' for DOS, Windows and OS/2 */
- for(i=0; i < real_path_len; ++i)
+ for(i = 0; i < real_path_len; ++i)
if(actual_path[i] == '/')
actual_path[i] = '\\';
else if(!actual_path[i]) { /* binary zero */
@@ -249,7 +197,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
file->fd = fd;
if(!data->set.upload && (fd == -1)) {
- failf(data, "Couldn't open file %s", data->state.path);
+ failf(data, "Couldn't open file %s", data->state.up.path);
file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE);
return CURLE_FILE_COULDNT_READ_FILE;
}
@@ -308,8 +256,6 @@ static CURLcode file_upload(struct connectdata *conn)
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
char *buf = data->state.buffer;
- size_t nread;
- size_t nwrite;
curl_off_t bytecount = 0;
struct_stat file_stat;
const char *buf2;
@@ -358,15 +304,17 @@ static CURLcode file_upload(struct connectdata *conn)
}
while(!result) {
- int readcount;
- result = Curl_fillreadbuffer(conn, (int)data->set.buffer_size, &readcount);
+ size_t nread;
+ size_t nwrite;
+ size_t readcount;
+ result = Curl_fillreadbuffer(conn, data->set.buffer_size, &readcount);
if(result)
break;
- if(readcount <= 0) /* fix questionable compare error. curlvms */
+ if(!readcount)
break;
- nread = (size_t)readcount;
+ nread = readcount;
/*skip bytes before resume point*/
if(data->state.resume_from) {
@@ -398,7 +346,7 @@ static CURLcode file_upload(struct connectdata *conn)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
- result = Curl_speedcheck(data, Curl_tvnow());
+ result = Curl_speedcheck(data, Curl_now());
}
if(!result && Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
@@ -427,10 +375,9 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
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;
+ curl_off_t expected_size = 0;
bool size_known;
- bool fstated=FALSE;
- ssize_t nread;
+ bool fstated = FALSE;
struct Curl_easy *data = conn->data;
char *buf = data->state.buffer;
curl_off_t bytecount = 0;
@@ -439,7 +386,6 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
*done = TRUE; /* unconditionally */
- Curl_initinfo(data);
Curl_pgrsStartNow(data);
if(data->set.upload)
@@ -455,32 +401,30 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
/* we could stat it, then read out the size */
expected_size = statbuf.st_size;
/* and store the modification time */
- data->info.filetime = (long)statbuf.st_mtime;
+ data->info.filetime = statbuf.st_mtime;
fstated = TRUE;
}
if(fstated && !data->state.range && data->set.timecondition) {
- if(!Curl_meets_timecondition(data, (time_t)data->info.filetime)) {
+ if(!Curl_meets_timecondition(data, data->info.filetime)) {
*done = TRUE;
return CURLE_OK;
}
}
- /* 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(data->set.opt_no_body && data->set.include_header && fstated) {
+ if(fstated) {
time_t filetime;
struct tm buffer;
const struct tm *tm = &buffer;
char header[80];
- snprintf(header, sizeof(header),
- "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size);
- result = Curl_client_write(conn, CLIENTWRITE_BOTH, header, 0);
+ msnprintf(header, sizeof(header),
+ "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n",
+ expected_size);
+ result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0);
if(result)
return result;
- result = Curl_client_write(conn, CLIENTWRITE_BOTH,
+ result = Curl_client_write(conn, CLIENTWRITE_HEADER,
(char *)"Accept-ranges: bytes\r\n", 0);
if(result)
return result;
@@ -491,27 +435,32 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
return result;
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
- snprintf(header, sizeof(header),
- "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)
- /* set the file size to make it available post transfer */
- Curl_pgrsSetDownloadSize(data, expected_size);
- return result;
+ msnprintf(header, sizeof(header),
+ "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n%s",
+ 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,
+ data->set.opt_no_body ? "": "\r\n");
+ result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0);
+ if(result)
+ return result;
+ /* set the file size to make it available post transfer */
+ Curl_pgrsSetDownloadSize(data, expected_size);
+ if(data->set.opt_no_body)
+ return result;
}
/* Check whether file range has been specified */
- file_range(conn);
+ result = Curl_range(conn);
+ if(result)
+ return result;
/* Adjust the start offset in case we want to get the N last bytes
- * of the stream iff the filesize could be determined */
+ * of the stream if the filesize could be determined */
if(data->state.resume_from < 0) {
if(!fstated) {
failf(data, "Can't get the size of file.");
@@ -552,6 +501,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
while(!result) {
+ ssize_t nread;
/* Don't fill a whole buffer if we want less than all data */
size_t bytestoread;
@@ -583,7 +533,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
- result = Curl_speedcheck(data, Curl_tvnow());
+ result = Curl_speedcheck(data, Curl_now());
}
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
diff --git a/Utilities/cmcurl/lib/file.h b/Utilities/cmcurl/lib/file.h
index c12ae0e09..20828ad4a 100644
--- a/Utilities/cmcurl/lib/file.h
+++ b/Utilities/cmcurl/lib/file.h
@@ -38,4 +38,3 @@ extern const struct Curl_handler Curl_handler_file;
#endif
#endif /* HEADER_CURL_FILE_H */
-
diff --git a/Utilities/cmcurl/lib/fileinfo.c b/Utilities/cmcurl/lib/fileinfo.c
index 387298847..2630c9e46 100644
--- a/Utilities/cmcurl/lib/fileinfo.c
+++ b/Utilities/cmcurl/lib/fileinfo.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2010 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2010 - 2019, 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
@@ -21,7 +21,7 @@
***************************************************************************/
#include "curl_setup.h"
-
+#ifndef CURL_DISABLE_FTP
#include "strdup.h"
#include "fileinfo.h"
#include "curl_memory.h"
@@ -33,14 +33,12 @@ struct fileinfo *Curl_fileinfo_alloc(void)
return calloc(1, sizeof(struct fileinfo));
}
-void Curl_fileinfo_dtor(void *user, void *element)
+void Curl_fileinfo_cleanup(struct fileinfo *finfo)
{
- struct fileinfo *finfo = element;
- (void) user;
if(!finfo)
return;
Curl_safefree(finfo->info.b_data);
-
free(finfo);
}
+#endif
diff --git a/Utilities/cmcurl/lib/fileinfo.h b/Utilities/cmcurl/lib/fileinfo.h
index c5d0ee5b6..f4d8f3b90 100644
--- a/Utilities/cmcurl/lib/fileinfo.h
+++ b/Utilities/cmcurl/lib/fileinfo.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2010, 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2010 - 2018, 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
@@ -31,7 +31,6 @@ struct fileinfo {
};
struct fileinfo *Curl_fileinfo_alloc(void);
-
-void Curl_fileinfo_dtor(void *, void *);
+void Curl_fileinfo_cleanup(struct fileinfo *finfo);
#endif /* HEADER_CURL_FILEINFO_H */
diff --git a/Utilities/cmcurl/lib/formdata.c b/Utilities/cmcurl/lib/formdata.c
index e48a6276c..429d479da 100644
--- a/Utilities/cmcurl/lib/formdata.c
+++ b/Utilities/cmcurl/lib/formdata.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -24,35 +24,27 @@
#include <curl/curl.h>
-#ifndef CURL_DISABLE_HTTP
+#include "formdata.h"
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_MIME)
#if defined(HAVE_LIBGEN_H) && defined(HAVE_BASENAME)
#include <libgen.h>
#endif
#include "urldata.h" /* for struct Curl_easy */
-#include "formdata.h"
+#include "mime.h"
+#include "non-ascii.h"
#include "vtls/vtls.h"
#include "strcase.h"
#include "sendf.h"
#include "strdup.h"
#include "rand.h"
+#include "warnless.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"
-#ifndef HAVE_BASENAME
-static char *Curl_basename(char *path);
-#define basename(x) Curl_basename((x))
-#endif
-
-static size_t readfromfile(struct Form *form, char *buffer, size_t size);
-static CURLcode formboundary(struct Curl_easy *data, char *buffer, size_t len);
-
-/* What kind of Content-Type to use on un-specified files with unrecognized
- extensions. */
-#define HTTPPOST_CONTENTTYPE_DEFAULT "application/octet-stream"
#define HTTPPOST_PTRNAME CURL_HTTPPOST_PTRNAME
#define HTTPPOST_FILENAME CURL_HTTPPOST_FILENAME
@@ -160,60 +152,6 @@ static FormInfo * AddFormInfo(char *value,
/***************************************************************************
*
- * 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"},
- {".xml", "application/xml"}
- };
-
- if(prevtype)
- /* default to the previously set/used! */
- contenttype = prevtype;
- else
- contenttype = HTTPPOST_CONTENTTYPE_DEFAULT;
-
- if(filename) { /* in case a NULL was passed in */
- for(i=0; i<sizeof(ctts)/sizeof(ctts[0]); i++) {
- if(strlen(filename) >= strlen(ctts[i].extension)) {
- if(strcasecompare(filename +
- strlen(filename) - strlen(ctts[i].extension),
- ctts[i].extension)) {
- contenttype = ctts[i].type;
- break;
- }
- }
- }
- }
- /* we have a contenttype by now */
- return contenttype;
-}
-
-/***************************************************************************
- *
* FormAdd()
*
* Stores a formpost parameter and builds the appropriate linked list.
@@ -272,7 +210,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
struct curl_httppost *post = NULL;
CURLformoption option;
struct curl_forms *forms = NULL;
- char *array_value=NULL; /* value read from an array */
+ 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
@@ -364,7 +302,8 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
* Set the contents property.
*/
case CURLFORM_PTRCONTENTS:
- current_form->flags |= HTTPPOST_PTRCONTENTS; /* fall through */
+ current_form->flags |= HTTPPOST_PTRCONTENTS;
+ /* FALLTHROUGH */
case CURLFORM_COPYCONTENTS:
if(current_form->value)
return_value = CURL_FORMADD_OPTION_TWICE;
@@ -630,26 +569,43 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
if(((form->flags & HTTPPOST_FILENAME) ||
(form->flags & HTTPPOST_BUFFER)) &&
!form->contenttype) {
- char *f = form->flags & HTTPPOST_BUFFER?
+ char *f = (form->flags & HTTPPOST_BUFFER)?
form->showfilename : form->value;
+ char const *type;
+ type = Curl_mime_contenttype(f);
+ if(!type)
+ type = prevtype;
+ if(!type)
+ type = FILE_CONTENTTYPE_DEFAULT;
/* our contenttype is missing */
- form->contenttype = strdup(ContentTypeForFilename(f, prevtype));
+ form->contenttype = strdup(type);
if(!form->contenttype) {
return_value = CURL_FORMADD_MEMORY;
break;
}
form->contenttype_alloc = TRUE;
}
+ if(form->name && form->namelength) {
+ /* Name should not contain nul bytes. */
+ size_t i;
+ for(i = 0; i < form->namelength; i++)
+ if(!form->name[i]) {
+ return_value = CURL_FORMADD_NULL;
+ break;
+ }
+ if(return_value != CURL_FORMADD_OK)
+ break;
+ }
if(!(form->flags & HTTPPOST_PTRNAME) &&
(form == first_form) ) {
/* Note that there's small risk that form->name is NULL here if the
app passed in a bad combo, so we better check for that first. */
if(form->name) {
- /* copy name (without strdup; possibly contains null characters) */
+ /* copy name (without strdup; possibly not nul-terminated) */
form->name = Curl_memdup(form->name, form->namelength?
form->namelength:
- strlen(form->name)+1);
+ strlen(form->name) + 1);
}
if(!form->name) {
return_value = CURL_FORMADD_MEMORY;
@@ -663,7 +619,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
/* copy value (without strdup; possibly contains null characters) */
size_t clen = (size_t) form->contentslength;
if(!clen)
- clen = strlen(form->value)+1;
+ clen = strlen(form->value) + 1;
form->value = Curl_memdup(form->value, clen);
@@ -746,211 +702,6 @@ CURLFORMcode curl_formadd(struct curl_httppost **httppost,
return result;
}
-#ifdef __VMS
-#include <fabdef.h>
-/*
- * get_vms_file_size does what it takes to get the real size of the file
- *
- * For fixed files, find out the size of the EOF block and adjust.
- *
- * For all others, have to read the entire file in, discarding the contents.
- * Most posted text files will be small, and binary files like zlib archives
- * and CD/DVD images should be either a STREAM_LF format or a fixed format.
- *
- */
-curl_off_t VmsRealFileSize(const char *name,
- const struct_stat *stat_buf)
-{
- char buffer[8192];
- curl_off_t count;
- int ret_stat;
- FILE * file;
-
- file = fopen(name, FOPEN_READTEXT); /* VMS */
- if(file == NULL)
- return 0;
-
- count = 0;
- ret_stat = 1;
- while(ret_stat > 0) {
- ret_stat = fread(buffer, 1, sizeof(buffer), file);
- if(ret_stat != 0)
- count += ret_stat;
- }
- fclose(file);
-
- return count;
-}
-
-/*
- *
- * VmsSpecialSize checks to see if the stat st_size can be trusted and
- * if not to call a routine to get the correct size.
- *
- */
-static curl_off_t VmsSpecialSize(const char *name,
- const struct_stat *stat_buf)
-{
- switch(stat_buf->st_fab_rfm) {
- case FAB$C_VAR:
- case FAB$C_VFC:
- return VmsRealFileSize(name, stat_buf);
- break;
- default:
- return stat_buf->st_size;
- }
-}
-
-#endif
-
-#ifndef __VMS
-#define filesize(name, stat_data) (stat_data.st_size)
-#else
- /* Getting the expected file size needs help on VMS */
-#define filesize(name, stat_data) VmsSpecialSize(name, &stat_data)
-#endif
-
-/*
- * 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,
- curl_off_t length,
- curl_off_t *size)
-{
- struct FormData *newform;
- char *alloc2 = NULL;
- CURLcode result = CURLE_OK;
- if(length < 0 || (size && *size < 0))
- return CURLE_BAD_FUNCTION_ARGUMENT;
-
- newform = malloc(sizeof(struct FormData));
- if(!newform)
- return CURLE_OUT_OF_MEMORY;
- newform->next = NULL;
-
- if(type <= FORM_CONTENT) {
- /* we make it easier for plain strings: */
- if(!length)
- length = strlen((char *)line);
-#if (SIZEOF_SIZE_T < CURL_SIZEOF_CURL_OFF_T)
- else if(length >= (curl_off_t)(size_t)-1) {
- result = CURLE_BAD_FUNCTION_ARGUMENT;
- goto error;
- }
-#endif
- if(type != FORM_DATAMEM) {
- newform->line = malloc((size_t)length+1);
- if(!newform->line) {
- result = CURLE_OUT_OF_MEMORY;
- goto error;
- }
- alloc2 = newform->line;
- memcpy(newform->line, line, (size_t)length);
-
- /* zero terminate for easier debugging */
- newform->line[(size_t)length]=0;
- }
- else {
- newform->line = (char *)line;
- type = FORM_DATA; /* in all other aspects this is just FORM_DATA */
- }
- newform->length = (size_t)length;
- }
- else
- /* For callbacks and files we don't have any actual data so we just keep a
- pointer to whatever this points to */
- newform->line = (char *)line;
-
- newform->type = type;
-
- if(size) {
- if(type != FORM_FILE)
- /* for static content as well as callback data we add the size given
- as input argument */
- *size += length;
- else {
- /* Since this is a file to be uploaded here, add the size of the actual
- file */
- if(strcmp("-", newform->line)) {
- struct_stat file;
- if(!stat(newform->line, &file) && !S_ISDIR(file.st_mode))
- *size += filesize(newform->line, file);
- else {
- result = CURLE_BAD_FUNCTION_ARGUMENT;
- goto error;
- }
- }
- }
- }
-
- if(*formp) {
- (*formp)->next = newform;
- *formp = newform;
- }
- else
- *formp = newform;
-
- return CURLE_OK;
- error:
- if(newform)
- free(newform);
- if(alloc2)
- free(alloc2);
- return result;
-}
-
-/*
- * 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;
- CURLcode result;
- va_list ap;
- va_start(ap, fmt);
- s = curl_mvaprintf(fmt, ap);
- va_end(ap);
-
- if(!s)
- return CURLE_OUT_OF_MEMORY;
-
- result = AddFormData(formp, FORM_DATAMEM, s, 0, size);
- if(result)
- free(s);
-
- return result;
-}
-
-/*
- * 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 */
- if(form->type <= FORM_CONTENT)
- free(form->line); /* free the line */
- free(form); /* free the struct */
- form = next;
- } while(form); /* continue */
-
- *form_ptr = NULL;
-}
-
/*
* curl_formget()
* Serialize a curl_httppost struct.
@@ -962,42 +713,34 @@ int curl_formget(struct curl_httppost *form, void *arg,
curl_formget_callback append)
{
CURLcode result;
- curl_off_t size;
- struct FormData *data, *ptr;
+ curl_mimepart toppart;
- result = Curl_getformdata(NULL, &data, form, NULL, &size);
- if(result)
- return (int)result;
-
- for(ptr = data; ptr; ptr = ptr->next) {
- if((ptr->type == FORM_FILE) || (ptr->type == FORM_CALLBACK)) {
- char buffer[8192];
- size_t nread;
- struct Form temp;
-
- Curl_FormInit(&temp, ptr);
-
- do {
- nread = readfromfile(&temp, buffer, sizeof(buffer));
- if((nread == (size_t) -1) ||
- (nread > sizeof(buffer)) ||
- (nread != append(arg, buffer, nread))) {
- if(temp.fp)
- fclose(temp.fp);
- Curl_formclean(&data);
- return -1;
- }
- } while(nread);
- }
- else {
- if(ptr->length != append(arg, ptr->line, ptr->length)) {
- Curl_formclean(&data);
- return -1;
- }
+ Curl_mime_initpart(&toppart, NULL); /* default form is empty */
+ result = Curl_getformdata(NULL, &toppart, form, NULL);
+ if(!result)
+ result = Curl_mime_prepare_headers(&toppart, "multipart/form-data",
+ NULL, MIMESTRATEGY_FORM);
+
+ while(!result) {
+ char buffer[8192];
+ size_t nread = Curl_mime_read(buffer, 1, sizeof(buffer), &toppart);
+
+ if(!nread)
+ break;
+
+ switch(nread) {
+ default:
+ if(append(arg, buffer, nread) != nread)
+ result = CURLE_READ_ERROR;
+ break;
+ case CURL_READFUNC_ABORT:
+ case CURL_READFUNC_PAUSE:
+ break;
}
}
- Curl_formclean(&data);
- return 0;
+
+ Curl_mime_cleanpart(&toppart);
+ return (int) result;
}
/*
@@ -1013,7 +756,7 @@ void curl_formfree(struct curl_httppost *form)
return;
do {
- next=form->next; /* the following form line */
+ next = form->next; /* the following form line */
/* recurse to sub-contents */
curl_formfree(form->more);
@@ -1031,118 +774,29 @@ void curl_formfree(struct curl_httppost *form)
} while(form); /* 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 *Curl_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(const 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 or NULL ! */
-}
-static CURLcode formdata_add_filename(const struct curl_httppost *file,
- struct FormData **form,
- curl_off_t *size)
+/* Set mime part name, taking care of non nul-terminated name string. */
+static CURLcode setname(curl_mimepart *part, const char *name, size_t len)
{
- CURLcode result = CURLE_OK;
- char *filename = file->showfilename;
- char *filebasename = NULL;
- char *filename_escaped = NULL;
-
- if(!filename) {
- filebasename = strippath(file->contents);
- if(!filebasename)
- return CURLE_OUT_OF_MEMORY;
- filename = filebasename;
- }
+ char *zname;
+ CURLcode res;
- if(strchr(filename, '\\') || strchr(filename, '"')) {
- char *p0, *p1;
-
- /* filename need be escaped */
- filename_escaped = malloc(strlen(filename)*2+1);
- if(!filename_escaped) {
- free(filebasename);
- return CURLE_OUT_OF_MEMORY;
- }
- p0 = filename_escaped;
- p1 = filename;
- while(*p1) {
- if(*p1 == '\\' || *p1 == '"')
- *p0++ = '\\';
- *p0++ = *p1++;
- }
- *p0 = '\0';
- filename = filename_escaped;
- }
- result = AddFormDataf(form, size,
- "; filename=\"%s\"",
- filename);
- free(filename_escaped);
- free(filebasename);
- return result;
+ if(!name || !len)
+ return curl_mime_name(part, name);
+ zname = malloc(len + 1);
+ if(!zname)
+ return CURLE_OUT_OF_MEMORY;
+ memcpy(zname, name, len);
+ zname[len] = '\0';
+ res = curl_mime_name(part, zname);
+ free(zname);
+ return res;
}
/*
- * 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'.
+ * Curl_getformdata() converts a linked list of "meta data" into a mime
+ * structure. The input list is in 'post', while the output is stored in
+ * mime part at '*finalform'.
*
* This function will not do a failf() for the potential memory failures but
* should for all other errors it spots. Just note that this function MAY get
@@ -1150,423 +804,125 @@ static CURLcode formdata_add_filename(const struct curl_httppost *file,
*/
CURLcode Curl_getformdata(struct Curl_easy *data,
- struct FormData **finalform,
+ curl_mimepart *finalform,
struct curl_httppost *post,
- const char *custom_content_type,
- curl_off_t *sizep)
+ curl_read_callback fread_func)
{
- 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 fileboundary[42];
- struct curl_slist *curList;
- char boundary[42];
+ curl_mime *form = NULL;
+ curl_mimepart *part;
+ struct curl_httppost *file;
- *finalform = NULL; /* default form is empty */
+ Curl_mime_cleanpart(finalform); /* default form is empty */
if(!post)
return result; /* no input => no output! */
- result = formboundary(data, boundary, sizeof(boundary));
- if(result)
- return result;
-
- /* 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) {
- 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;
+ form = curl_mime_init(data);
+ if(!form)
+ result = CURLE_OUT_OF_MEMORY;
- result = AddFormDataf(&form, &size, "\"");
- if(result)
- break;
+ if(!result)
+ result = curl_mime_subparts(finalform, form);
+ /* Process each top part. */
+ for(; !result && post; post = post->next) {
+ /* If we have more than a file here, create a mime subpart and fill it. */
+ curl_mime *multipart = form;
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 */
-
- result = formboundary(data, fileboundary, sizeof(fileboundary));
- if(result) {
- break;
+ part = curl_mime_addpart(form);
+ if(!part)
+ result = CURLE_OUT_OF_MEMORY;
+ if(!result)
+ result = setname(part, post->name, post->namelength);
+ if(!result) {
+ multipart = curl_mime_init(data);
+ if(!multipart)
+ result = CURLE_OUT_OF_MEMORY;
}
-
- result = AddFormDataf(&form, &size,
- "\r\nContent-Type: multipart/mixed;"
- " boundary=%s\r\n",
- fileboundary);
- if(result)
- break;
+ if(!result)
+ result = curl_mime_subparts(part, multipart);
}
- 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 */
- result = AddFormDataf(&form, &size,
- "\r\n--%s\r\nContent-Disposition: "
- "attachment",
- fileboundary);
- if(result)
- break;
- result = formdata_add_filename(file, &form, &size);
- if(result)
- break;
- }
- else if(post->flags & (HTTPPOST_FILENAME|HTTPPOST_BUFFER|
- HTTPPOST_CALLBACK)) {
- /* it should be noted that for the HTTPPOST_FILENAME and
- HTTPPOST_CALLBACK cases the ->showfilename struct member is always
- assigned at this point */
- if(post->showfilename || (post->flags & HTTPPOST_FILENAME)) {
- result = formdata_add_filename(post, &form, &size);
- }
+ /* Generate all the part contents. */
+ for(file = post; !result && file; file = file->more) {
+ /* Create the part. */
+ part = curl_mime_addpart(multipart);
+ if(!part)
+ result = CURLE_OUT_OF_MEMORY;
- if(result)
- break;
- }
+ /* Set the headers. */
+ if(!result)
+ result = curl_mime_headers(part, file->contentheader, 0);
- if(file->contenttype) {
- /* we have a specified type */
- result = AddFormDataf(&form, &size,
- "\r\nContent-Type: %s",
- file->contenttype);
- if(result)
- break;
- }
+ /* Set the content type. */
+ if(!result && file->contenttype)
+ result = curl_mime_type(part, file->contenttype);
- 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)
- break;
+ /* Set field name. */
+ if(!result && !post->more)
+ result = setname(part, post->name, post->namelength);
- result = AddFormDataf(&form, &size, "\r\n\r\n");
- if(result)
- break;
+ /* Process contents. */
+ if(!result) {
+ curl_off_t clen = post->contentslength;
- if((post->flags & HTTPPOST_FILENAME) ||
- (post->flags & HTTPPOST_READFILE)) {
- /* we should include the contents from the specified file */
- FILE *fileread;
-
- fileread = !strcmp("-", 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 */
- 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 || feof(fileread) || ferror(fileread))
- break;
- }
+ if(post->flags & CURL_HTTPPOST_LARGE)
+ clen = post->contentlen;
+ if(!clen)
+ clen = -1;
+
+ if(post->flags & (HTTPPOST_FILENAME | HTTPPOST_READFILE)) {
+ if(!strcmp(file->contents, "-")) {
+ /* There are a few cases where the code below won't work; in
+ particular, freopen(stdin) by the caller is not guaranteed
+ to result as expected. This feature has been kept for backward
+ compatibility: use of "-" pseudo file name should be avoided. */
+ result = curl_mime_data_cb(part, (curl_off_t) -1,
+ (curl_read_callback) fread,
+ CURLX_FUNCTION_CAST(curl_seek_callback,
+ fseek),
+ NULL, (void *) stdin);
}
+ else
+ result = curl_mime_filedata(part, file->contents);
+ if(!result && (post->flags & HTTPPOST_READFILE))
+ result = curl_mime_filename(part, NULL);
}
+ else if(post->flags & HTTPPOST_BUFFER)
+ result = curl_mime_data(part, post->buffer,
+ post->bufferlength? post->bufferlength: -1);
+ else if(post->flags & HTTPPOST_CALLBACK)
+ /* the contents should be read with the callback and the size is set
+ with the contentslength */
+ result = curl_mime_data_cb(part, clen,
+ fread_func, NULL, NULL, post->userp);
else {
- if(data)
- failf(data, "couldn't open file \"%s\"", file->contents);
- *finalform = NULL;
- result = CURLE_READ_ERROR;
+ result = curl_mime_data(part, post->contents, (ssize_t) clen);
+#ifdef CURL_DOES_CONVERSIONS
+ /* Convert textual contents now. */
+ if(!result && data && part->datasize)
+ result = Curl_convert_to_network(data, part->data, part->datasize);
+#endif
}
}
- else if(post->flags & HTTPPOST_BUFFER)
- /* include contents of buffer */
- result = AddFormData(&form, FORM_CONTENT, post->buffer,
- post->bufferlength, &size);
- else if(post->flags & HTTPPOST_CALLBACK)
- /* the contents should be read with the callback and the size is set
- with the contentslength */
- result = AddFormData(&form, FORM_CALLBACK, post->userp,
- post->flags&CURL_HTTPPOST_LARGE?
- post->contentlen:post->contentslength, &size);
- else
- /* include the contents we got */
- result = AddFormData(&form, FORM_CONTENT, post->contents,
- post->flags&CURL_HTTPPOST_LARGE?
- post->contentlen:post->contentslength, &size);
- file = file->more;
- } while(file && !result); /* for each specified file for this field */
-
- if(result)
- break;
- if(post->more) {
- /* this was a multiple-file inclusion, make a termination file
- boundary: */
- result = AddFormDataf(&form, &size,
- "\r\n--%s--",
- fileboundary);
- if(result)
- break;
+ /* Set fake file name. */
+ if(!result && post->showfilename)
+ if(post->more || (post->flags & (HTTPPOST_FILENAME | HTTPPOST_BUFFER |
+ HTTPPOST_CALLBACK)))
+ result = curl_mime_filename(part, post->showfilename);
}
- post = post->next;
- } while(post); /* for each field */
-
- /* end-boundary for everything */
- if(!result)
- result = AddFormDataf(&form, &size, "\r\n--%s--\r\n", boundary);
-
- if(result) {
- Curl_formclean(&firstform);
- return result;
}
- *sizep = size;
- *finalform = firstform;
+ if(result)
+ Curl_mime_cleanpart(finalform);
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;
- form->fread_func = ZERO_NULL;
-
- return 0;
-}
-
-#ifndef __VMS
-# define fopen_read fopen
#else
- /*
- * vmsfopenread
- *
- * For upload to work as expected on VMS, different optional
- * parameters must be added to the fopen command based on
- * record format of the file.
- *
- */
-# define fopen_read vmsfopenread
-static FILE * vmsfopenread(const char *file, const char *mode)
-{
- struct_stat statbuf;
- int result;
-
- result = stat(file, &statbuf);
-
- switch(statbuf.st_fab_rfm) {
- case FAB$C_VAR:
- case FAB$C_VFC:
- case FAB$C_STMCR:
- return fopen(file, FOPEN_READTEXT); /* VMS */
- break;
- default:
- return fopen(file, FOPEN_READTEXT, "rfm=stmlf", "ctx=stm");
- }
-}
-#endif
-
-/*
- * readfromfile()
- *
- * The read callback that this function may use can return a value larger than
- * 'size' (which then this function returns) that indicates a problem and it
- * must be properly dealt with
- */
-static size_t readfromfile(struct Form *form, char *buffer,
- size_t size)
-{
- size_t nread;
- bool callback = (form->data->type == FORM_CALLBACK)?TRUE:FALSE;
-
- if(callback) {
- if(form->fread_func == ZERO_NULL)
- return 0;
- nread = form->fread_func(buffer, 1, size, form->data->line);
- }
- else {
- if(!form->fp) {
- /* this file hasn't yet been opened */
- form->fp = fopen_read(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) {
- /* this is the last chunk from the file, move on */
- if(form->fp) {
- 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) ||
- (form->data->type == FORM_CALLBACK)) {
- 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_CALLBACK));
- /* 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. */
-
- 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 NULL; /* nothing, ERROR! */
-
- header = form->data->line;
- *len = form->data->length;
-
- form->data = form->data->next; /* advance */
-
- return header;
-}
-
-/*
- * formboundary() creates a suitable boundary string and returns an allocated
- * one.
- */
-static CURLcode formboundary(struct Curl_easy *data,
- char *buffer, size_t buflen)
-{
- /* 24 dashes and 16 hexadecimal digits makes 64 bit (18446744073709551615)
- combinations */
- if(buflen < 41)
- return CURLE_BAD_FUNCTION_ARGUMENT;
-
- memset(buffer, '-', 24);
- Curl_rand_hex(data, (unsigned char *)&buffer[24], 17);
-
- return CURLE_OK;
-}
-
-#else /* CURL_DISABLE_HTTP */
+/* if disabled */
CURLFORMcode curl_formadd(struct curl_httppost **httppost,
struct curl_httppost **last_post,
...)
@@ -1591,5 +947,4 @@ void curl_formfree(struct curl_httppost *form)
/* does nothing HTTP is disabled */
}
-
-#endif /* !defined(CURL_DISABLE_HTTP) */
+#endif /* if disabled */
diff --git a/Utilities/cmcurl/lib/formdata.h b/Utilities/cmcurl/lib/formdata.h
index 69629f628..cb20805f5 100644
--- a/Utilities/cmcurl/lib/formdata.h
+++ b/Utilities/cmcurl/lib/formdata.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,31 +22,9 @@
*
***************************************************************************/
-enum formtype {
- FORM_DATAMEM, /* already allocated FORM_DATA memory */
- FORM_DATA, /* form metadata (convert to network encoding if necessary) */
- FORM_CONTENT, /* form content (never convert) */
- FORM_CALLBACK, /* 'line' points to the custom pointer we pass to the callback
- */
- FORM_FILE /* 'line' points to a file name we should read from
- to create the form data (never convert) */
-};
+#include "curl_setup.h"
-/* 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 */
- curl_read_callback fread_func; /* fread callback pointer */
-};
+#ifndef CURL_DISABLE_MIME
/* used by FormAdd for temporary storage */
typedef struct FormInfo {
@@ -69,31 +47,14 @@ typedef struct FormInfo {
struct FormInfo *more;
} FormInfo;
-int Curl_FormInit(struct Form *form, struct FormData *formdata);
-
CURLcode Curl_getformdata(struct Curl_easy *data,
- struct FormData **,
+ curl_mimepart *,
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 **);
+ curl_read_callback fread_func);
+#else
+/* disabled */
+#define Curl_getformdata(a,b,c,d) CURLE_NOT_BUILT_IN
+#endif
-CURLcode Curl_formconvert(struct Curl_easy *, struct FormData *);
#endif /* HEADER_CURL_FORMDATA_H */
diff --git a/Utilities/cmcurl/lib/ftp.c b/Utilities/cmcurl/lib/ftp.c
index 783dbe124..53510f821 100644
--- a/Utilities/cmcurl/lib/ftp.c
+++ b/Utilities/cmcurl/lib/ftp.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -59,6 +59,7 @@
#include "ftp.h"
#include "fileinfo.h"
#include "ftplistparser.h"
+#include "curl_range.h"
#include "curl_sec.h"
#include "strtoofft.h"
#include "strcase.h"
@@ -178,10 +179,12 @@ const struct Curl_handler Curl_handler_ftp = {
ZERO_NULL, /* perform_getsock */
ftp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_FTP, /* defport */
CURLPROTO_FTP, /* protocol */
- PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD
- | PROTOPT_NOURLQUERY /* flags */
+ PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD |
+ PROTOPT_NOURLQUERY | PROTOPT_PROXY_AS_HTTP |
+ PROTOPT_WILDCARD /* flags */
};
@@ -205,66 +208,14 @@ const struct Curl_handler Curl_handler_ftps = {
ZERO_NULL, /* perform_getsock */
ftp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_FTPS, /* defport */
CURLPROTO_FTPS, /* protocol */
PROTOPT_SSL | PROTOPT_DUAL | PROTOPT_CLOSEACTION |
- PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY /* flags */
+ PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_WILDCARD /* flags */
};
#endif
-#ifndef CURL_DISABLE_HTTP
-/*
- * HTTP-proxyed FTP protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_ftp_proxy = {
- "FTP", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_FTP, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-
-
-#ifdef USE_SSL
-/*
- * HTTP-proxyed FTPS protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_ftps_proxy = {
- "FTPS", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_FTPS, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-#endif
-#endif
-
static void close_secondarysocket(struct connectdata *conn)
{
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET]) {
@@ -272,7 +223,6 @@ static void close_secondarysocket(struct connectdata *conn)
conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD;
}
conn->bits.tcpconnect[SECONDARYSOCKET] = FALSE;
- conn->tunnel_state[SECONDARYSOCKET] = TUNNEL_INIT;
}
/*
@@ -289,11 +239,11 @@ static void close_secondarysocket(struct connectdata *conn)
static void freedirs(struct ftp_conn *ftpc)
{
- int i;
if(ftpc->dirs) {
- for(i=0; i < ftpc->dirdepth; i++) {
+ int i;
+ for(i = 0; i < ftpc->dirdepth; i++) {
free(ftpc->dirs[i]);
- ftpc->dirs[i]=NULL;
+ ftpc->dirs[i] = NULL;
}
free(ftpc->dirs);
ftpc->dirs = NULL;
@@ -340,7 +290,7 @@ static CURLcode AcceptServerConnect(struct connectdata *conn)
if(0 == getsockname(sock, (struct sockaddr *) &add, &size)) {
size = sizeof(add);
- s=accept(sock, (struct sockaddr *) &add, &size);
+ s = accept(sock, (struct sockaddr *) &add, &size);
}
Curl_closesocket(conn, sock); /* close the first socket */
@@ -361,9 +311,11 @@ static CURLcode AcceptServerConnect(struct connectdata *conn)
int error = 0;
/* activate callback for setting socket options */
+ Curl_set_in_callback(data, true);
error = data->set.fsockopt(data->set.sockopt_client,
s,
CURLSOCKTYPE_ACCEPT);
+ Curl_set_in_callback(data, false);
if(error) {
close_secondarysocket(conn);
@@ -384,16 +336,16 @@ static CURLcode AcceptServerConnect(struct connectdata *conn)
* Curl_pgrsTime(..., TIMER_STARTACCEPT);
*
*/
-static time_t ftp_timeleft_accept(struct Curl_easy *data)
+static timediff_t ftp_timeleft_accept(struct Curl_easy *data)
{
- time_t timeout_ms = DEFAULT_ACCEPT_TIMEOUT;
- time_t other;
- struct timeval now;
+ timediff_t timeout_ms = DEFAULT_ACCEPT_TIMEOUT;
+ timediff_t other;
+ struct curltime now;
if(data->set.accepttimeout > 0)
timeout_ms = data->set.accepttimeout;
- now = Curl_tvnow();
+ now = Curl_now();
/* check if the generic timeout possibly is set shorter */
other = Curl_timeleft(data, &now, FALSE);
@@ -403,7 +355,7 @@ static time_t ftp_timeleft_accept(struct Curl_easy *data)
timeout_ms = other;
else {
/* subtract elapsed time */
- timeout_ms -= Curl_tvdiff(now, data->progress.t_acceptdata);
+ timeout_ms -= Curl_timediff(now, data->progress.t_acceptdata);
if(!timeout_ms)
/* avoid returning 0 as that means no timeout! */
return -1;
@@ -496,7 +448,6 @@ static CURLcode ReceivedServerConnect(struct connectdata *conn, bool *received)
static CURLcode InitiateTransfer(struct connectdata *conn)
{
struct Curl_easy *data = conn->data;
- struct FTP *ftp = data->req.protop;
CURLcode result = CURLE_OK;
if(conn->bits.ftp_use_data_ssl) {
@@ -509,24 +460,19 @@ static CURLcode InitiateTransfer(struct connectdata *conn)
}
if(conn->proto.ftpc.state_saved == FTP_STOR) {
- *(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->state.infilesize);
/* set the SO_SNDBUF for the secondary socket for those who need it */
Curl_sndbufset(conn->sock[SECONDARYSOCKET]);
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, /* no download */
- SECONDARYSOCKET, ftp->bytecountp);
+ Curl_setup_transfer(data, -1, -1, FALSE, SECONDARYSOCKET);
}
else {
/* FTP download: */
- Curl_setup_transfer(conn, SECONDARYSOCKET,
- conn->proto.ftpc.retr_size_saved, FALSE,
- ftp->bytecountp, -1, NULL); /* no upload here */
+ Curl_setup_transfer(data, SECONDARYSOCKET,
+ conn->proto.ftpc.retr_size_saved, FALSE, -1);
}
conn->proto.ftpc.pp.pending_resp = TRUE; /* expect server response */
@@ -626,7 +572,6 @@ static CURLcode ftp_readresp(curl_socket_t sockfd,
#if defined(HAVE_GSSAPI)
/* handle the security-oriented responses 6xx ***/
- /* FIXME: some errorchecking perhaps... ***/
switch(code) {
case 631:
code = Curl_sec_read_msg(conn, buf, PROT_SAFE);
@@ -644,7 +589,7 @@ static CURLcode ftp_readresp(curl_socket_t sockfd,
#endif
/* store the latest code for later retrieval */
- data->info.httpcode=code;
+ data->info.httpcode = code;
if(ftpcode)
*ftpcode = code;
@@ -685,15 +630,13 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
* line in a response or continue reading. */
curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
- time_t timeout; /* timeout in milliseconds */
- time_t interval_ms;
struct Curl_easy *data = conn->data;
CURLcode result = CURLE_OK;
struct ftp_conn *ftpc = &conn->proto.ftpc;
struct pingpong *pp = &ftpc->pp;
size_t nread;
- int cache_skip=0;
- int value_to_be_ignored=0;
+ int cache_skip = 0;
+ int value_to_be_ignored = 0;
if(ftpcode)
*ftpcode = 0; /* 0 for errors */
@@ -701,13 +644,14 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
/* make the pointer point to something for the rest of this function */
ftpcode = &value_to_be_ignored;
- *nreadp=0;
+ *nreadp = 0;
while(!*ftpcode && !result) {
/* check and reset timeout value every lap */
- timeout = Curl_pp_state_timeout(pp);
+ time_t timeout = Curl_pp_state_timeout(pp, FALSE);
+ time_t interval_ms;
- if(timeout <=0) {
+ if(timeout <= 0) {
failf(data, "FTP response timeout");
return CURLE_OPERATION_TIMEDOUT; /* already too little time */
}
@@ -765,7 +709,7 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
else
/* when we got data or there is no cache left, we reset the cache skip
counter */
- cache_skip=0;
+ cache_skip = 0;
*nreadp += nread;
@@ -900,7 +844,7 @@ static int ftp_domore_getsock(struct connectdata *conn, curl_socket_t *socks,
int i;
/* PORT is used to tell the server to connect to us, and during that we
don't do happy eyeballs, but we do if we connect to the server */
- for(s=1, i=0; i<2; i++) {
+ for(s = 1, i = 0; i<2; i++) {
if(conn->tempsock[i] != CURL_SOCKET_BAD) {
socks[s] = conn->tempsock[i];
bits |= GETSOCK_WRITESOCK(s++);
@@ -937,23 +881,26 @@ static CURLcode ftp_state_cwd(struct connectdata *conn)
/* count3 is set to allow a MKD to fail once. In the case when first CWD
fails and then MKD fails (due to another session raced it to create the
dir) this then allows for a second try to CWD to it */
- ftpc->count3 = (conn->data->set.ftp_create_missing_dirs==2)?1:0;
+ ftpc->count3 = (conn->data->set.ftp_create_missing_dirs == 2)?1:0;
- if(conn->bits.reuse && ftpc->entrypath) {
+ if((conn->data->set.ftp_filemethod == FTPFILE_NOCWD) && !ftpc->cwdcount)
+ /* No CWD necessary */
+ result = ftp_state_mdtm(conn);
+ else 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 */
+ ftpc->cwdcount = 0; /* we count this as the first path, then we add one
+ for all upcoming ones in the ftp->dirs[] array */
PPSENDF(&conn->proto.ftpc.pp, "CWD %s", ftpc->entrypath);
state(conn, FTP_CWD);
}
else {
if(ftpc->dirdepth) {
- ftpc->count1 = 1;
+ ftpc->cwdcount = 1;
/* issue the first CWD, the rest is sent when the CWD responses are
received... */
- PPSENDF(&conn->proto.ftpc.pp, "CWD %s", ftpc->dirs[ftpc->count1 -1]);
+ PPSENDF(&conn->proto.ftpc.pp, "CWD %s", ftpc->dirs[ftpc->cwdcount -1]);
state(conn, FTP_CWD);
}
else {
@@ -977,15 +924,15 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct ftp_conn *ftpc = &conn->proto.ftpc;
- struct Curl_easy *data=conn->data;
- curl_socket_t portsock= CURL_SOCKET_BAD;
+ struct Curl_easy *data = conn->data;
+ curl_socket_t portsock = CURL_SOCKET_BAD;
char myhost[256] = "";
struct Curl_sockaddr_storage ss;
Curl_addrinfo *res, *ai;
curl_socklen_t sslen;
char hbuf[NI_MAXHOST];
- struct sockaddr *sa=(struct sockaddr *)&ss;
+ struct sockaddr *sa = (struct sockaddr *)&ss;
struct sockaddr_in * const sa4 = (void *)sa;
#ifdef ENABLE_IPV6
struct sockaddr_in6 * const sa6 = (void *)sa;
@@ -996,12 +943,12 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
int error;
char *host = NULL;
char *string_ftpport = data->set.str[STRING_FTPPORT];
- struct Curl_dns_entry *h=NULL;
+ struct Curl_dns_entry *h = NULL;
unsigned short port_min = 0;
unsigned short port_max = 0;
unsigned short port;
bool possibly_non_local = TRUE;
-
+ char buffer[STRERROR_LEN];
char *addr = NULL;
/* Step 1, figure out what is requested,
@@ -1024,7 +971,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
char *port_start = NULL;
char *port_sep = NULL;
- addr = calloc(addrlen+1, 1);
+ addr = calloc(addrlen + 1, 1);
if(!addr)
return CURLE_OUT_OF_MEMORY;
@@ -1067,7 +1014,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if(ip_end != NULL) {
port_start = strchr(ip_end, ':');
if(port_start) {
- port_min = curlx_ultous(strtoul(port_start+1, NULL, 10));
+ port_min = curlx_ultous(strtoul(port_start + 1, NULL, 10));
port_sep = strchr(port_start, '-');
if(port_sep) {
port_max = curlx_ultous(strtoul(port_sep + 1, NULL, 10));
@@ -1110,11 +1057,10 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
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], sa, &sslen)) {
failf(data, "getsockname() failed: %s",
- Curl_strerror(conn, SOCKERRNO) );
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
free(addr);
return CURLE_FTP_PORT_FAILED;
}
@@ -1133,7 +1079,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
}
/* resolv ip/host to ip */
- rc = Curl_resolv(conn, host, 0, &h);
+ rc = Curl_resolv(conn, host, 0, FALSE, &h);
if(rc == CURLRESOLV_PENDING)
(void)Curl_resolver_wait_resolv(conn, &h);
if(h) {
@@ -1167,7 +1113,8 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
break;
}
if(!ai) {
- failf(data, "socket failure: %s", Curl_strerror(conn, error));
+ failf(data, "socket failure: %s",
+ Curl_strerror(error, buffer, sizeof(buffer)));
return CURLE_FTP_PORT_FAILED;
}
@@ -1191,14 +1138,13 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* The requested bind address is not local. Use the address used for
* the control connection instead and restart the port loop
*/
-
infof(data, "bind(port=%hu) on non-local address failed: %s\n", port,
- Curl_strerror(conn, error) );
+ Curl_strerror(error, buffer, sizeof(buffer)));
sslen = sizeof(ss);
if(getsockname(conn->sock[FIRSTSOCKET], sa, &sslen)) {
failf(data, "getsockname() failed: %s",
- Curl_strerror(conn, SOCKERRNO) );
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
Curl_closesocket(conn, portsock);
return CURLE_FTP_PORT_FAILED;
}
@@ -1208,7 +1154,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
}
if(error != EADDRINUSE && error != EACCES) {
failf(data, "bind(port=%hu) failed: %s", port,
- Curl_strerror(conn, error) );
+ Curl_strerror(error, buffer, sizeof(buffer)));
Curl_closesocket(conn, portsock);
return CURLE_FTP_PORT_FAILED;
}
@@ -1231,7 +1177,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
sslen = sizeof(ss);
if(getsockname(portsock, (struct sockaddr *)sa, &sslen)) {
failf(data, "getsockname() failed: %s",
- Curl_strerror(conn, SOCKERRNO) );
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
Curl_closesocket(conn, portsock);
return CURLE_FTP_PORT_FAILED;
}
@@ -1239,7 +1185,8 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* step 4, listen on the socket */
if(listen(portsock, 1)) {
- failf(data, "socket failure: %s", Curl_strerror(conn, SOCKERRNO));
+ failf(data, "socket failure: %s",
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
Curl_closesocket(conn, portsock);
return CURLE_FTP_PORT_FAILED;
}
@@ -1311,14 +1258,14 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* translate x.x.x.x to x,x,x,x */
while(source && *source) {
if(*source == '.')
- *dest=',';
+ *dest = ',';
else
*dest = *source;
dest++;
source++;
}
*dest = 0;
- snprintf(dest, 20, ",%d,%d", (int)(port>>8), (int)(port&0xff));
+ msnprintf(dest, 20, ",%d,%d", (int)(port>>8), (int)(port&0xff));
result = Curl_pp_sendf(&ftpc->pp, "%s %s", mode[fcmd], tmp);
if(result) {
@@ -1490,6 +1437,7 @@ static CURLcode ftp_state_list(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
+ struct FTP *ftp = data->req.protop;
/* 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
@@ -1506,25 +1454,22 @@ static CURLcode ftp_state_list(struct connectdata *conn)
then just do LIST (in that case: nothing to do here)
*/
char *cmd, *lstArg, *slashPos;
+ const char *inpath = ftp->path;
lstArg = NULL;
if((data->set.ftp_filemethod == FTPFILE_NOCWD) &&
- data->state.path &&
- data->state.path[0] &&
- strchr(data->state.path, '/')) {
-
- lstArg = strdup(data->state.path);
- if(!lstArg)
- return CURLE_OUT_OF_MEMORY;
+ inpath && inpath[0] && strchr(inpath, '/')) {
+ size_t n = strlen(inpath);
/* Check if path does not end with /, as then we cut off the file part */
- if(lstArg[strlen(lstArg) - 1] != '/') {
-
+ if(inpath[n - 1] != '/') {
/* chop off the file part if format is dir/dir/file */
- slashPos = strrchr(lstArg, '/');
- if(slashPos)
- *(slashPos+1) = '\0';
+ slashPos = strrchr(inpath, '/');
+ n = slashPos - inpath;
}
+ result = Curl_urldecode(data, inpath, n, &lstArg, NULL, TRUE);
+ if(result)
+ return result;
}
cmd = aprintf("%s%s%s",
@@ -1586,7 +1531,7 @@ static CURLcode ftp_state_type(struct connectdata *conn)
date. */
if(data->set.opt_no_body && ftpc->file &&
ftp_need_type(conn, data->set.prefer_ascii)) {
- /* The SIZE command is _not_ RFC 959 specified, and therefor many servers
+ /* The SIZE command is _not_ RFC 959 specified, and therefore many servers
may not support it! It is however the only way we have to get a file's
size! */
@@ -1637,7 +1582,6 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
struct FTP *ftp = conn->data->req.protop;
struct Curl_easy *data = conn->data;
struct ftp_conn *ftpc = &conn->proto.ftpc;
- int seekerr = CURL_SEEKFUNC_OK;
if((data->state.resume_from && !sizechecked) ||
((data->state.resume_from > 0) && sizechecked)) {
@@ -1653,6 +1597,7 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
/* 3. pass file-size number of bytes in the source file */
/* 4. lower the infilesize counter */
/* => transfer as usual */
+ int seekerr = CURL_SEEKFUNC_OK;
if(data->state.resume_from < 0) {
/* Got no given size to start from, figure it out */
@@ -1666,12 +1611,14 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
/* Let's read off the proper amount of bytes from the input. */
if(conn->seek_func) {
+ Curl_set_in_callback(data, true);
seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
SEEK_SET);
+ Curl_set_in_callback(data, false);
}
if(seekerr != CURL_SEEKFUNC_OK) {
- curl_off_t passed=0;
+ curl_off_t passed = 0;
if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
failf(data, "Could not seek stream");
return CURLE_FTP_COULDNT_USE_REST;
@@ -1704,7 +1651,7 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
infof(data, "File already completely uploaded\n");
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
/* Set ->transfer so that we won't get any error in
* ftp_done() because we didn't transfer anything! */
@@ -1733,7 +1680,7 @@ static CURLcode ftp_state_quote(struct connectdata *conn,
struct Curl_easy *data = conn->data;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
- bool quote=FALSE;
+ bool quote = FALSE;
struct curl_slist *item;
switch(instate) {
@@ -1834,7 +1781,7 @@ static CURLcode ftp_epsv_disable(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
- if(conn->bits.ipv6) {
+ if(conn->bits.ipv6 && !(conn->bits.tunnel_proxy || conn->bits.socksproxy)) {
/* We can't disable EPSV when doing IPv6, so this is instead a fail */
failf(conn->data, "Failed EPSV attempt, exiting\n");
return CURLE_WEIRD_SERVER_REPLY;
@@ -1870,11 +1817,11 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
{
struct ftp_conn *ftpc = &conn->proto.ftpc;
CURLcode result;
- struct Curl_easy *data=conn->data;
- struct Curl_dns_entry *addr=NULL;
+ struct Curl_easy *data = conn->data;
+ struct Curl_dns_entry *addr = NULL;
int rc;
unsigned short connectport; /* the local port connect() should use! */
- char *str=&data->state.buffer[4]; /* start on the first letter */
+ char *str = &data->state.buffer[4]; /* start on the first letter */
/* if we come here again, make sure the former name is cleared */
Curl_safefree(ftpc->newhost);
@@ -1898,9 +1845,9 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
/* 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++) {
+ for(i = 1; i<4; i++) {
if(separator[i] != sep1) {
- ptr=NULL; /* set to NULL to signal error */
+ ptr = NULL; /* set to NULL to signal error */
break;
}
}
@@ -1916,7 +1863,7 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
}
}
else
- ptr=NULL;
+ ptr = NULL;
}
if(!ptr) {
failf(data, "Weirdly formatted EPSV reply");
@@ -1926,8 +1873,8 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
else if((ftpc->count1 == 1) &&
(ftpcode == 227)) {
/* positive PASV response */
- int ip[4];
- int port[2];
+ unsigned int ip[4];
+ unsigned int port[2];
/*
* Scan for a sequence of six comma-separated numbers and use them as
@@ -1939,14 +1886,15 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
* "227 Entering passive mode. 127,0,0,1,4,51"
*/
while(*str) {
- if(6 == sscanf(str, "%d,%d,%d,%d,%d,%d",
+ if(6 == sscanf(str, "%u,%u,%u,%u,%u,%u",
&ip[0], &ip[1], &ip[2], &ip[3],
&port[0], &port[1]))
break;
str++;
}
- if(!*str) {
+ if(!*str || (ip[0] > 255) || (ip[1] > 255) || (ip[2] > 255) ||
+ (ip[3] > 255) || (port[0] > 255) || (port[1] > 255) ) {
failf(data, "Couldn't interpret the 227-response");
return CURLE_FTP_WEIRD_227_FORMAT;
}
@@ -1955,13 +1903,13 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
if(data->set.ftp_skip_ip) {
/* told to ignore the remotely given IP but instead use the host we used
for the control connection */
- infof(data, "Skip %d.%d.%d.%d for data connection, re-use %s instead\n",
+ infof(data, "Skip %u.%u.%u.%u for data connection, re-use %s instead\n",
ip[0], ip[1], ip[2], ip[3],
conn->host.name);
ftpc->newhost = strdup(control_address(conn));
}
else
- ftpc->newhost = aprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ ftpc->newhost = aprintf("%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
if(!ftpc->newhost)
return CURLE_OUT_OF_MEMORY;
@@ -1985,7 +1933,7 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
*/
const char * const host_name = conn->bits.socksproxy ?
conn->socks_proxy.host.name : conn->http_proxy.host.name;
- rc = Curl_resolv(conn, host_name, (int)conn->port, &addr);
+ rc = Curl_resolv(conn, host_name, (int)conn->port, FALSE, &addr);
if(rc == CURLRESOLV_PENDING)
/* BLOCKING, ignores the return code but 'addr' will be NULL in
case of failure */
@@ -2001,7 +1949,7 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
}
else {
/* normal, direct, ftp connection */
- rc = Curl_resolv(conn, ftpc->newhost, ftpc->newport, &addr);
+ rc = Curl_resolv(conn, ftpc->newhost, ftpc->newport, FALSE, &addr);
if(rc == CURLRESOLV_PENDING)
/* BLOCKING */
(void)Curl_resolver_wait_resolv(conn, &addr);
@@ -2090,7 +2038,7 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
int ftpcode)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
@@ -2104,13 +2052,13 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
&year, &month, &day, &hour, &minute, &second)) {
/* we have a time, reformat it */
char timebuf[24];
- time_t secs=time(NULL);
+ time_t secs = time(NULL);
- snprintf(timebuf, sizeof(timebuf),
- "%04d%02d%02d %02d:%02d:%02d GMT",
- year, month, day, hour, minute, second);
+ msnprintf(timebuf, sizeof(timebuf),
+ "%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(timebuf, &secs);
+ data->info.filetime = curl_getdate(timebuf, &secs);
}
#ifdef CURL_FTP_HTTPSTYLE_HEAD
@@ -2120,9 +2068,9 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
if(data->set.opt_no_body &&
ftpc->file &&
data->set.get_filetime &&
- (data->info.filetime>=0) ) {
+ (data->info.filetime >= 0) ) {
char headerbuf[128];
- time_t filetime = (time_t)data->info.filetime;
+ time_t filetime = data->info.filetime;
struct tm buffer;
const struct tm *tm = &buffer;
@@ -2131,15 +2079,15 @@ static CURLcode ftp_state_mdtm_resp(struct connectdata *conn,
return result;
/* format: "Tue, 15 Nov 1994 12:45:26" */
- snprintf(headerbuf, sizeof(headerbuf),
- "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);
+ msnprintf(headerbuf, sizeof(headerbuf),
+ "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, headerbuf, 0);
if(result)
return result;
@@ -2196,7 +2144,7 @@ static CURLcode ftp_state_type_resp(struct connectdata *conn,
ftpstate instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
if(ftpcode/100 != 2) {
/* "sasserftpd" and "(u)r(x)bot ftpd" both responds with 226 after a
@@ -2225,7 +2173,7 @@ static CURLcode ftp_state_retr(struct connectdata *conn,
curl_off_t filesize)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
@@ -2275,7 +2223,7 @@ static CURLcode ftp_state_retr(struct connectdata *conn,
if(ftp->downloadsize == 0) {
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
infof(data, "File already completely downloaded\n");
/* Set ->transfer so that we won't get any error in ftp_done()
@@ -2308,19 +2256,21 @@ static CURLcode ftp_state_size_resp(struct connectdata *conn,
ftpstate instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data=conn->data;
- curl_off_t filesize;
+ struct Curl_easy *data = conn->data;
+ curl_off_t filesize = -1;
char *buf = data->state.buffer;
/* get the size from the ascii string: */
- filesize = (ftpcode == 213)?curlx_strtoofft(buf+4, NULL, 0):-1;
+ if(ftpcode == 213)
+ /* ignores parsing errors, which will make the size remain unknown */
+ (void)curlx_strtoofft(buf + 4, NULL, 0, &filesize);
if(instate == FTP_SIZE) {
#ifdef CURL_FTP_HTTPSTYLE_HEAD
if(-1 != filesize) {
char clbuf[128];
- snprintf(clbuf, sizeof(clbuf),
- "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", filesize);
+ msnprintf(clbuf, sizeof(clbuf),
+ "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", filesize);
result = Curl_client_write(conn, CLIENTWRITE_BOTH, clbuf, 0);
if(result)
return result;
@@ -2383,7 +2333,7 @@ static CURLcode ftp_state_stor_resp(struct connectdata *conn,
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
- if(ftpcode>=400) {
+ if(ftpcode >= 400) {
failf(data, "Failed FTP upload: %0d", ftpcode);
state(conn, FTP_STOP);
/* oops, we never close the sockets! */
@@ -2441,7 +2391,7 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
E:
125 Data connection already open; Transfer starting. */
- curl_off_t size=-1; /* default unknown size */
+ curl_off_t size = -1; /* default unknown size */
/*
@@ -2465,9 +2415,9 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
* Example D above makes this parsing a little tricky */
char *bytes;
char *buf = data->state.buffer;
- bytes=strstr(buf, " bytes");
- if(bytes--) {
- long in=(long)(bytes-buf);
+ 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 */
@@ -2475,7 +2425,7 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
break;
/* skip only digits */
if(!ISDIGIT(*bytes)) {
- bytes=NULL;
+ bytes = NULL;
break;
}
/* one more estep backwards */
@@ -2484,7 +2434,7 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
/* if we have nothing but digits: */
if(bytes++) {
/* get the number! */
- size = curlx_strtoofft(bytes, NULL, 0);
+ (void)curlx_strtoofft(bytes, NULL, 0, &size);
}
}
}
@@ -2647,7 +2597,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
{
CURLcode result;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
int ftpcode;
struct ftp_conn *ftpc = &conn->proto.ftpc;
struct pingpong *pp = &ftpc->pp;
@@ -2699,7 +2649,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
/* We don't have a SSL/TLS connection yet, but FTPS is
requested. Try a FTPS connection now */
- ftpc->count3=0;
+ ftpc->count3 = 0;
switch(data->set.ftpsslauth) {
case CURLFTPAUTH_DEFAULT:
case CURLFTPAUTH_SSL:
@@ -2822,10 +2772,10 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
case FTP_PWD:
if(ftpcode == 257) {
- char *ptr=&data->state.buffer[4]; /* start on the first letter */
+ char *ptr = &data->state.buffer[4]; /* start on the first letter */
const size_t buf_size = data->set.buffer_size;
char *dir;
- char *store;
+ bool entry_extracted = FALSE;
dir = malloc(nread + 1);
if(!dir)
@@ -2847,6 +2797,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
if('\"' == *ptr) {
/* it started good */
+ char *store;
ptr++;
for(store = dir; *ptr;) {
if('\"' == *ptr) {
@@ -2857,7 +2808,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
}
else {
/* end of path */
- *store = '\0'; /* zero terminate */
+ entry_extracted = TRUE;
break; /* get out of this loop */
}
}
@@ -2866,7 +2817,9 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
store++;
ptr++;
}
-
+ *store = '\0'; /* zero terminate */
+ }
+ if(entry_extracted) {
/* If the path name does not look like an absolute path (i.e.: it
does not start with a '/'), we probably need some server-dependent
adjustments. For example, this is the case when connecting to
@@ -2913,7 +2866,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
case FTP_SYST:
if(ftpcode == 215) {
- char *ptr=&data->state.buffer[4]; /* start on the first letter */
+ char *ptr = &data->state.buffer[4]; /* start on the first letter */
char *os;
char *store;
@@ -2988,10 +2941,10 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
if(ftpcode/100 != 2) {
/* failure to CWD there */
if(conn->data->set.ftp_create_missing_dirs &&
- ftpc->count1 && !ftpc->count2) {
+ ftpc->cwdcount && !ftpc->count2) {
/* try making it */
ftpc->count2++; /* counter to prevent CWD-MKD loops */
- PPSENDF(&ftpc->pp, "MKD %s", ftpc->dirs[ftpc->count1 - 1]);
+ PPSENDF(&ftpc->pp, "MKD %s", ftpc->dirs[ftpc->cwdcount - 1]);
state(conn, FTP_MKD);
}
else {
@@ -3004,10 +2957,10 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
}
else {
/* success */
- ftpc->count2=0;
- if(++ftpc->count1 <= ftpc->dirdepth) {
+ ftpc->count2 = 0;
+ if(++ftpc->cwdcount <= ftpc->dirdepth) {
/* send next CWD */
- PPSENDF(&ftpc->pp, "CWD %s", ftpc->dirs[ftpc->count1 - 1]);
+ PPSENDF(&ftpc->pp, "CWD %s", ftpc->dirs[ftpc->cwdcount - 1]);
}
else {
result = ftp_state_mdtm(conn);
@@ -3025,7 +2978,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
}
state(conn, FTP_CWD);
/* send CWD */
- PPSENDF(&ftpc->pp, "CWD %s", ftpc->dirs[ftpc->count1 - 1]);
+ PPSENDF(&ftpc->pp, "CWD %s", ftpc->dirs[ftpc->cwdcount - 1]);
break;
case FTP_MDTM:
@@ -3094,7 +3047,7 @@ static CURLcode ftp_multi_statemach(struct connectdata *conn,
bool *done)
{
struct ftp_conn *ftpc = &conn->proto.ftpc;
- CURLcode result = Curl_pp_statemach(&ftpc->pp, FALSE);
+ CURLcode result = Curl_pp_statemach(&ftpc->pp, FALSE, FALSE);
/* Check for the state outside of the Curl_socket_check() return code checks
since at times we are in fact already in this state when this function
@@ -3111,7 +3064,7 @@ static CURLcode ftp_block_statemach(struct connectdata *conn)
CURLcode result = CURLE_OK;
while(ftpc->state != FTP_STOP) {
- result = Curl_pp_statemach(pp, TRUE);
+ result = Curl_pp_statemach(pp, TRUE, TRUE /* disconnecting */);
if(result)
break;
}
@@ -3182,7 +3135,6 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
int ftpcode;
CURLcode result = CURLE_OK;
char *path = NULL;
- const char *path_to_use = data->state.path;
if(!ftp)
return CURLE_OK;
@@ -3223,16 +3175,18 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
/* now store a copy of the directory we are in */
free(ftpc->prevpath);
- if(data->set.wildcardmatch) {
+ if(data->state.wildcardmatch) {
if(data->set.chunk_end && ftpc->file) {
+ Curl_set_in_callback(data, true);
data->set.chunk_end(data->wildcard.customptr);
+ Curl_set_in_callback(data, false);
}
ftpc->known_filesize = -1;
}
if(!result)
/* get the "raw" path */
- result = Curl_urldecode(data, path_to_use, 0, &path, NULL, FALSE);
+ result = Curl_urldecode(data, ftp->path, 0, &path, NULL, TRUE);
if(result) {
/* We can limp along anyway (and should try to since we may already be in
* the error path) */
@@ -3244,16 +3198,19 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
size_t flen = ftpc->file?strlen(ftpc->file):0; /* file is "raw" already */
size_t dlen = strlen(path)-flen;
if(!ftpc->cwdfail) {
+ ftpc->prevmethod = data->set.ftp_filemethod;
if(dlen && (data->set.ftp_filemethod != FTPFILE_NOCWD)) {
ftpc->prevpath = path;
if(flen)
/* if 'path' is not the whole string */
- ftpc->prevpath[dlen]=0; /* terminate */
+ ftpc->prevpath[dlen] = 0; /* terminate */
}
else {
- /* we never changed dir */
- ftpc->prevpath=strdup("");
free(path);
+ /* we never changed dir */
+ ftpc->prevpath = strdup("");
+ if(!ftpc->prevpath)
+ return CURLE_OUT_OF_MEMORY;
}
if(ftpc->prevpath)
infof(data, "Remembering we are in dir \"%s\"\n", ftpc->prevpath);
@@ -3306,7 +3263,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
long old_time = pp->response_time;
pp->response_time = 60*1000; /* give it only a minute for now */
- pp->response = Curl_tvnow(); /* timeout relative now */
+ pp->response = Curl_now(); /* timeout relative now */
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
@@ -3344,33 +3301,33 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
;
else if(data->set.upload) {
if((-1 != data->state.infilesize) &&
- (data->state.infilesize != *ftp->bytecountp) &&
+ (data->state.infilesize != data->req.writebytecount) &&
!data->set.crlf &&
(ftp->transfer == FTPTRANSFER_BODY)) {
failf(data, "Uploaded unaligned file size (%" CURL_FORMAT_CURL_OFF_T
" out of %" CURL_FORMAT_CURL_OFF_T " bytes)",
- *ftp->bytecountp, data->state.infilesize);
+ data->req.bytecount, data->state.infilesize);
result = CURLE_PARTIAL_FILE;
}
}
else {
if((-1 != data->req.size) &&
- (data->req.size != *ftp->bytecountp) &&
+ (data->req.size != data->req.bytecount) &&
#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.
*/
((data->req.size + data->state.crlf_conversions) !=
- *ftp->bytecountp) &&
+ data->req.bytecount) &&
#endif /* CURL_DO_LINEEND_CONV */
- (data->req.maxdownload != *ftp->bytecountp)) {
+ (data->req.maxdownload != data->req.bytecount)) {
failf(data, "Received only partial file: %" CURL_FORMAT_CURL_OFF_T
- " bytes", *ftp->bytecountp);
+ " bytes", data->req.bytecount);
result = CURLE_PARTIAL_FILE;
}
else if(!ftpc->dont_check &&
- !*ftp->bytecountp &&
+ !data->req.bytecount &&
(data->req.size>0)) {
failf(data, "No data was received!");
result = CURLE_FTP_COULDNT_RETR_FILE;
@@ -3384,7 +3341,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
/* Send any post-transfer QUOTE strings? */
if(!status && !result && !premature && data->set.postquote)
result = ftp_sendquote(conn, data->set.postquote);
-
+ Curl_safefree(ftp->pathalloc);
return result;
}
@@ -3426,7 +3383,7 @@ CURLcode ftp_sendquote(struct connectdata *conn, struct curl_slist *quote)
PPSENDF(&conn->proto.ftpc.pp, "%s", cmd);
- pp->response = Curl_tvnow(); /* timeout relative now */
+ pp->response = Curl_now(); /* timeout relative now */
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if(result)
@@ -3507,61 +3464,6 @@ ftp_pasv_verbose(struct connectdata *conn,
#endif
/*
- 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;
- char *ptr;
- char *ptr2;
- struct Curl_easy *data = conn->data;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
-
- if(data->state.use_range && data->state.range) {
- from=curlx_strtoofft(data->state.range, &ptr, 0);
- while(*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->state.resume_from = from;
- DEBUGF(infof(conn->data, "FTP RANGE %" CURL_FORMAT_CURL_OFF_T
- " to end of file\n", from));
- }
- else if(from < 0) {
- /* -Y */
- data->req.maxdownload = -from;
- data->state.resume_from = from;
- DEBUGF(infof(conn->data, "FTP RANGE the last %" CURL_FORMAT_CURL_OFF_T
- " bytes\n", -from));
- }
- else {
- /* X-Y */
- data->req.maxdownload = (to-from)+1; /* include last byte */
- data->state.resume_from = from;
- DEBUGF(infof(conn->data, "FTP RANGE from %" CURL_FORMAT_CURL_OFF_T
- " getting %" CURL_FORMAT_CURL_OFF_T " bytes\n",
- from, data->req.maxdownload));
- }
- DEBUGF(infof(conn->data, "range-download from %" CURL_FORMAT_CURL_OFF_T
- " to %" CURL_FORMAT_CURL_OFF_T ", totally %"
- CURL_FORMAT_CURL_OFF_T " bytes\n",
- from, to, data->req.maxdownload));
- ftpc->dont_check = TRUE; /* don't check for successful transfer */
- }
- else
- data->req.maxdownload = -1;
- return CURLE_OK;
-}
-
-
-/*
* ftp_do_more()
*
* This function shall be called when the second FTP (data) connection is
@@ -3574,7 +3476,7 @@ static CURLcode ftp_range(struct connectdata *conn)
static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
{
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
struct ftp_conn *ftpc = &conn->proto.ftpc;
CURLcode result = CURLE_OK;
bool connected = FALSE;
@@ -3585,9 +3487,9 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
/* if the second connection isn't done yet, wait for it */
if(!conn->bits.tcpconnect[SECONDARYSOCKET]) {
- if(conn->tunnel_state[SECONDARYSOCKET] == TUNNEL_CONNECT) {
+ if(Curl_connect_ongoing(conn)) {
/* As we're in TUNNEL_CONNECT state now, we know the proxy name and port
- aren't used so we blank their arguments. TODO: make this nicer */
+ aren't used so we blank their arguments. */
result = Curl_proxyCONNECT(conn, SECONDARYSOCKET, NULL, 0);
return result;
@@ -3617,7 +3519,7 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
return result;
if(conn->bits.tunnel_proxy && conn->bits.httpproxy &&
- conn->tunnel_state[SECONDARYSOCKET] != TUNNEL_COMPLETE)
+ Curl_connect_ongoing(conn))
return result;
@@ -3683,7 +3585,13 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
/* download */
ftp->downloadsize = -1; /* unknown as of yet */
- result = ftp_range(conn);
+ result = Curl_range(conn);
+
+ if(result == CURLE_OK && data->req.maxdownload >= 0) {
+ /* Don't check for successful transfer */
+ ftpc->dont_check = TRUE;
+ }
+
if(result)
;
else if(data->set.ftp_list_only || !ftpc->file) {
@@ -3714,7 +3622,7 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
if(!result && (ftp->transfer != FTPTRANSFER_BODY))
/* no data to transfer. FIX: it feels like a kludge to have this here
too! */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
if(!ftpc->wait_data_conn) {
/* no waiting for the data connection so this is now complete */
@@ -3741,7 +3649,7 @@ CURLcode ftp_perform(struct connectdata *conn,
bool *dophase_done)
{
/* this is FTP and no proxy */
- CURLcode result=CURLE_OK;
+ CURLcode result = CURLE_OK;
DEBUGF(infof(conn->data, "DO phase starts\n"));
@@ -3774,21 +3682,22 @@ CURLcode ftp_perform(struct connectdata *conn,
static void wc_data_dtor(void *ptr)
{
- struct ftp_wc_tmpdata *tmp = ptr;
- if(tmp)
- Curl_ftp_parselist_data_free(&tmp->parser);
- free(tmp);
+ struct ftp_wc *ftpwc = ptr;
+ if(ftpwc && ftpwc->parser)
+ Curl_ftp_parselist_data_free(&ftpwc->parser);
+ free(ftpwc);
}
static CURLcode init_wc_data(struct connectdata *conn)
{
char *last_slash;
- char *path = conn->data->state.path;
+ struct FTP *ftp = conn->data->req.protop;
+ char *path = ftp->path;
struct WildcardData *wildcard = &(conn->data->wildcard);
CURLcode result = CURLE_OK;
- struct ftp_wc_tmpdata *ftp_tmp;
+ struct ftp_wc *ftpwc = NULL;
- last_slash = strrchr(conn->data->state.path, '/');
+ last_slash = strrchr(ftp->path, '/');
if(last_slash) {
last_slash++;
if(last_slash[0] == '\0') {
@@ -3818,23 +3727,22 @@ static CURLcode init_wc_data(struct connectdata *conn)
/* program continues only if URL is not ending with slash, allocate needed
resources for wildcard transfer */
- /* allocate ftp protocol specific temporary wildcard data */
- ftp_tmp = calloc(1, sizeof(struct ftp_wc_tmpdata));
- if(!ftp_tmp) {
- Curl_safefree(wildcard->pattern);
- return CURLE_OUT_OF_MEMORY;
+ /* allocate ftp protocol specific wildcard data */
+ ftpwc = calloc(1, sizeof(struct ftp_wc));
+ if(!ftpwc) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
}
/* INITIALIZE parselist structure */
- ftp_tmp->parser = Curl_ftp_parselist_data_alloc();
- if(!ftp_tmp->parser) {
- Curl_safefree(wildcard->pattern);
- free(ftp_tmp);
- return CURLE_OUT_OF_MEMORY;
+ ftpwc->parser = Curl_ftp_parselist_data_alloc();
+ if(!ftpwc->parser) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
}
- wildcard->tmp = ftp_tmp; /* put it to the WildcardData tmp pointer */
- wildcard->tmp_dtor = wc_data_dtor;
+ wildcard->protdata = ftpwc; /* put it to the WildcardData tmp pointer */
+ wildcard->dtor = wc_data_dtor;
/* wildcard does not support NOCWD option (assert it?) */
if(conn->data->set.ftp_filemethod == FTPFILE_NOCWD)
@@ -3843,33 +3751,36 @@ static CURLcode init_wc_data(struct connectdata *conn)
/* try to parse ftp url */
result = ftp_parse_url_path(conn);
if(result) {
- Curl_safefree(wildcard->pattern);
- wildcard->tmp_dtor(wildcard->tmp);
- wildcard->tmp_dtor = ZERO_NULL;
- wildcard->tmp = NULL;
- return result;
+ goto fail;
}
- wildcard->path = strdup(conn->data->state.path);
+ wildcard->path = strdup(ftp->path);
if(!wildcard->path) {
- Curl_safefree(wildcard->pattern);
- wildcard->tmp_dtor(wildcard->tmp);
- wildcard->tmp_dtor = ZERO_NULL;
- wildcard->tmp = NULL;
- return CURLE_OUT_OF_MEMORY;
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
}
/* backup old write_function */
- ftp_tmp->backup.write_function = conn->data->set.fwrite_func;
+ ftpwc->backup.write_function = conn->data->set.fwrite_func;
/* parsing write function */
conn->data->set.fwrite_func = Curl_ftp_parselist;
/* backup old file descriptor */
- ftp_tmp->backup.file_descriptor = conn->data->set.out;
+ ftpwc->backup.file_descriptor = conn->data->set.out;
/* let the writefunc callback know what curl pointer is working with */
conn->data->set.out = conn;
infof(conn->data, "Wildcard - Parsing started\n");
return CURLE_OK;
+
+ fail:
+ if(ftpwc) {
+ Curl_ftp_parselist_data_free(&ftpwc->parser);
+ free(ftpwc);
+ }
+ Curl_safefree(wildcard->pattern);
+ wildcard->dtor = ZERO_NULL;
+ wildcard->protdata = NULL;
+ return result;
}
/* This is called recursively */
@@ -3890,14 +3801,14 @@ static CURLcode wc_statemach(struct connectdata *conn)
case CURLWC_MATCHING: {
/* In this state is LIST response successfully parsed, so lets restore
previous WRITEFUNCTION callback and WRITEDATA pointer */
- struct ftp_wc_tmpdata *ftp_tmp = wildcard->tmp;
- conn->data->set.fwrite_func = ftp_tmp->backup.write_function;
- conn->data->set.out = ftp_tmp->backup.file_descriptor;
- ftp_tmp->backup.write_function = ZERO_NULL;
- ftp_tmp->backup.file_descriptor = NULL;
+ struct ftp_wc *ftpwc = wildcard->protdata;
+ conn->data->set.fwrite_func = ftpwc->backup.write_function;
+ conn->data->set.out = ftpwc->backup.file_descriptor;
+ ftpwc->backup.write_function = ZERO_NULL;
+ ftpwc->backup.file_descriptor = NULL;
wildcard->state = CURLWC_DOWNLOADING;
- if(Curl_ftp_parselist_geterror(ftp_tmp->parser)) {
+ if(Curl_ftp_parselist_geterror(ftpwc->parser)) {
/* error found in LIST parsing */
wildcard->state = CURLWC_CLEAN;
return wc_statemach(conn);
@@ -3914,21 +3825,23 @@ static CURLcode wc_statemach(struct connectdata *conn)
/* filelist has at least one file, lets get first one */
struct ftp_conn *ftpc = &conn->proto.ftpc;
struct curl_fileinfo *finfo = wildcard->filelist.head->ptr;
+ struct FTP *ftp = conn->data->req.protop;
char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename);
if(!tmp_path)
return CURLE_OUT_OF_MEMORY;
- /* switch default "state.pathbuffer" and tmp_path, good to see
- ftp_parse_url_path function to understand this trick */
- Curl_safefree(conn->data->state.pathbuffer);
- conn->data->state.pathbuffer = tmp_path;
- conn->data->state.path = tmp_path;
+ /* switch default ftp->path and tmp_path */
+ free(ftp->pathalloc);
+ ftp->pathalloc = ftp->path = tmp_path;
infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename);
if(conn->data->set.chunk_bgn) {
- long userresponse = conn->data->set.chunk_bgn(
+ long userresponse;
+ Curl_set_in_callback(conn->data, true);
+ userresponse = conn->data->set.chunk_bgn(
finfo, wildcard->customptr, (int)wildcard->filelist.size);
+ Curl_set_in_callback(conn->data, false);
switch(userresponse) {
case CURL_CHUNK_BGN_FUNC_SKIP:
infof(conn->data, "Wildcard - \"%s\" skipped by user\n",
@@ -3964,8 +3877,11 @@ static CURLcode wc_statemach(struct connectdata *conn)
} break;
case CURLWC_SKIP: {
- if(conn->data->set.chunk_end)
+ if(conn->data->set.chunk_end) {
+ Curl_set_in_callback(conn->data, true);
conn->data->set.chunk_end(conn->data->wildcard.customptr);
+ Curl_set_in_callback(conn->data, false);
+ }
Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL);
wildcard->state = (wildcard->filelist.size == 0) ?
CURLWC_CLEAN : CURLWC_DOWNLOADING;
@@ -3973,10 +3889,10 @@ static CURLcode wc_statemach(struct connectdata *conn)
}
case CURLWC_CLEAN: {
- struct ftp_wc_tmpdata *ftp_tmp = wildcard->tmp;
+ struct ftp_wc *ftpwc = wildcard->protdata;
result = CURLE_OK;
- if(ftp_tmp)
- result = Curl_ftp_parselist_geterror(ftp_tmp->parser);
+ if(ftpwc)
+ result = Curl_ftp_parselist_geterror(ftpwc->parser);
wildcard->state = result ? CURLWC_ERROR : CURLWC_DONE;
} break;
@@ -3984,6 +3900,8 @@ static CURLcode wc_statemach(struct connectdata *conn)
case CURLWC_DONE:
case CURLWC_ERROR:
case CURLWC_CLEAR:
+ if(wildcard->dtor)
+ wildcard->dtor(wildcard->protdata);
break;
}
@@ -4007,7 +3925,7 @@ static CURLcode ftp_do(struct connectdata *conn, bool *done)
*done = FALSE; /* default to false */
ftpc->wait_data_conn = FALSE; /* default to no such wait */
- if(conn->data->set.wildcardmatch) {
+ if(conn->data->state.wildcardmatch) {
result = wc_statemach(conn);
if(conn->data->wildcard.state == CURLWC_SKIP ||
conn->data->wildcard.state == CURLWC_DONE) {
@@ -4035,20 +3953,23 @@ CURLcode Curl_ftpsend(struct connectdata *conn, const char *cmd)
#define SBUF_SIZE 1024
char s[SBUF_SIZE];
size_t write_len;
- char *sptr=s;
+ char *sptr = s;
CURLcode result = CURLE_OK;
#ifdef HAVE_GSSAPI
enum protection_level data_sec = conn->data_prot;
#endif
+ if(!cmd)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
write_len = strlen(cmd);
- if(write_len > (sizeof(s) -3))
+ if(!write_len || write_len > (sizeof(s) -3))
return CURLE_BAD_FUNCTION_ARGUMENT;
+ memcpy(&s, cmd, write_len);
strcpy(&s[write_len], "\r\n"); /* append a trailing CRLF */
- write_len +=2;
-
- bytes_written=0;
+ write_len += 2;
+ bytes_written = 0;
result = Curl_convert_to_network(conn->data, s, write_len);
/* Curl_convert_to_network calls failf if unsuccessful */
@@ -4070,8 +3991,7 @@ CURLcode Curl_ftpsend(struct connectdata *conn, const char *cmd)
break;
if(conn->data->set.verbose)
- Curl_debug(conn->data, CURLINFO_HEADER_OUT,
- sptr, (size_t)bytes_written, conn);
+ Curl_debug(conn->data, CURLINFO_HEADER_OUT, sptr, (size_t)bytes_written);
if(bytes_written != (ssize_t)write_len) {
write_len -= bytes_written;
@@ -4126,7 +4046,7 @@ static CURLcode ftp_quit(struct connectdata *conn)
*/
static CURLcode ftp_disconnect(struct connectdata *conn, bool dead_connection)
{
- struct ftp_conn *ftpc= &conn->proto.ftpc;
+ struct ftp_conn *ftpc = &conn->proto.ftpc;
struct pingpong *pp = &ftpc->pp;
/* We cannot send quit unconditionally. If this connection is stale or
@@ -4181,7 +4101,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
struct FTP *ftp = data->req.protop;
struct ftp_conn *ftpc = &conn->proto.ftpc;
const char *slash_pos; /* position of the first '/' char in curpos */
- const char *path_to_use = data->state.path;
+ const char *path_to_use = ftp->path;
const char *cur_pos;
const char *filename = NULL;
@@ -4222,7 +4142,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
ftpc->dirdepth = 0;
break;
}
- slash_pos=strrchr(cur_pos, '/');
+ slash_pos = strrchr(cur_pos, '/');
if(slash_pos || !*cur_pos) {
size_t dirlen = slash_pos-cur_pos;
CURLcode result;
@@ -4237,13 +4157,13 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
result = Curl_urldecode(conn->data, slash_pos ? cur_pos : "/",
slash_pos ? dirlen : 1,
&ftpc->dirs[0], NULL,
- FALSE);
+ TRUE);
if(result) {
freedirs(ftpc);
return result;
}
ftpc->dirdepth = 1; /* we consider it to be a single dir */
- filename = slash_pos ? slash_pos+1 : cur_pos; /* rest is file name */
+ filename = slash_pos ? slash_pos + 1 : cur_pos; /* rest is file name */
}
else
filename = cur_pos; /* this is a file name only */
@@ -4267,7 +4187,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
/* parse the URL path into separate path components */
while((slash_pos = strchr(cur_pos, '/')) != NULL) {
/* 1 or 0 pointer offset to indicate absolute directory */
- ssize_t absolute_dir = ((cur_pos - data->state.path > 0) &&
+ ssize_t absolute_dir = ((cur_pos - ftp->path > 0) &&
(ftpc->dirdepth == 0))?1:0;
/* seek out the next path component */
@@ -4327,8 +4247,8 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
}
}
else
- ftpc->file=NULL; /* instead of point to a zero byte, we make it a NULL
- pointer */
+ ftpc->file = NULL; /* instead of point to a zero byte, we make it a NULL
+ pointer */
if(data->set.upload && !ftpc->file && (ftp->transfer == FTPTRANSFER_BODY)) {
/* We need a file name when uploading. Return error! */
@@ -4344,7 +4264,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
size_t dlen;
char *path;
CURLcode result =
- Curl_urldecode(conn->data, data->state.path, 0, &path, &dlen, FALSE);
+ Curl_urldecode(conn->data, ftp->path, 0, &path, &dlen, TRUE);
if(result) {
freedirs(ftpc);
return result;
@@ -4352,7 +4272,8 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
dlen -= ftpc->file?strlen(ftpc->file):0;
if((dlen == strlen(ftpc->prevpath)) &&
- !strncmp(path, ftpc->prevpath, dlen)) {
+ !strncmp(path, ftpc->prevpath, dlen) &&
+ (ftpc->prevmethod == data->set.ftp_filemethod)) {
infof(data, "Request has same path as previous transfer\n");
ftpc->cwddone = TRUE;
}
@@ -4381,7 +4302,7 @@ static CURLcode ftp_dophase_done(struct connectdata *conn,
if(ftp->transfer != FTPTRANSFER_BODY)
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(conn->data, -1, -1, FALSE, -1);
else if(!connected)
/* since we didn't connect now, we want do_more to get called */
conn->bits.do_more = TRUE;
@@ -4423,8 +4344,8 @@ static
CURLcode ftp_regular_transfer(struct connectdata *conn,
bool *dophase_done)
{
- CURLcode result=CURLE_OK;
- bool connected=FALSE;
+ CURLcode result = CURLE_OK;
+ bool connected = FALSE;
struct Curl_easy *data = conn->data;
struct ftp_conn *ftpc = &conn->proto.ftpc;
data->req.size = -1; /* make sure this is unknown at this point */
@@ -4461,46 +4382,23 @@ static CURLcode ftp_setup_connection(struct connectdata *conn)
{
struct Curl_easy *data = conn->data;
char *type;
- char command;
struct FTP *ftp;
- if(conn->bits.httpproxy && !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
- if(conn->handler == &Curl_handler_ftp)
- conn->handler = &Curl_handler_ftp_proxy;
- else {
-#ifdef USE_SSL
- conn->handler = &Curl_handler_ftps_proxy;
-#else
- failf(data, "FTPS not supported!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
- /* set it up as a HTTP connection instead */
- return conn->handler->setup_connection(conn);
-#else
- failf(data, "FTP over http proxy requires HTTP support built-in!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
-
- conn->data->req.protop = ftp = malloc(sizeof(struct FTP));
+ conn->data->req.protop = ftp = calloc(sizeof(struct FTP), 1);
if(NULL == ftp)
return CURLE_OUT_OF_MEMORY;
- data->state.path++; /* don't include the initial slash */
- data->state.slash_removed = TRUE; /* we've skipped the slash */
+ ftp->path = &data->state.up.path[1]; /* don't include the initial slash */
/* FTP URLs support an extension like ";type=<typecode>" that
* we'll try to get now! */
- type = strstr(data->state.path, ";type=");
+ type = strstr(ftp->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 = Curl_raw_toupper(type[6]);
conn->bits.type_set = TRUE;
@@ -4523,7 +4421,6 @@ static CURLcode ftp_setup_connection(struct connectdata *conn)
}
/* get some initial data into the ftp struct */
- ftp->bytecountp = &conn->data->req.bytecount;
ftp->transfer = FTPTRANSFER_BODY;
ftp->downloadsize = 0;
diff --git a/Utilities/cmcurl/lib/ftp.h b/Utilities/cmcurl/lib/ftp.h
index 3bbf26206..828d69a21 100644
--- a/Utilities/cmcurl/lib/ftp.h
+++ b/Utilities/cmcurl/lib/ftp.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -81,7 +81,7 @@ typedef enum {
struct ftp_parselist_data; /* defined later in ftplistparser.c */
-struct ftp_wc_tmpdata {
+struct ftp_wc {
struct ftp_parselist_data *parser;
struct {
@@ -102,9 +102,10 @@ typedef enum {
perhaps the Curl_easy 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 *path; /* points to the urlpieces struct field */
+ char *pathalloc; /* if non-NULL a pointer to an allocated path */
/* transfer a file/body or not, done as a typedefed enum just to make
debuggers display the full symbol and not just the numerical value */
@@ -130,10 +131,12 @@ struct ftp_conn {
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 */
+ int cwdcount; /* number of CWD commands issued */
bool cwdfail; /* set TRUE if a CWD command fails, as then we must prevent
caching the current directory */
bool wait_data_conn; /* this is set TRUE if data connection is waited */
char *prevpath; /* conn->path from the previous transfer */
+ curl_ftpfile prevmethod; /* ftp method in previous transfer */
char transfertype; /* set by ftp_transfertype for use by Curl_client_write()a
and others (A/I or zero) */
int count1; /* general purpose counter for the state machine */
diff --git a/Utilities/cmcurl/lib/ftplistparser.c b/Utilities/cmcurl/lib/ftplistparser.c
index 2acce31d8..c4eb43732 100644
--- a/Utilities/cmcurl/lib/ftplistparser.c
+++ b/Utilities/cmcurl/lib/ftplistparser.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -49,6 +49,7 @@
#include "ftplistparser.h"
#include "curl_fnmatch.h"
#include "curl_memory.h"
+#include "multiif.h"
/* The last #include file should be: */
#include "memdebug.h"
@@ -184,10 +185,13 @@ struct ftp_parselist_data *Curl_ftp_parselist_data_alloc(void)
}
-void Curl_ftp_parselist_data_free(struct ftp_parselist_data **pl_data)
+void Curl_ftp_parselist_data_free(struct ftp_parselist_data **parserp)
{
- free(*pl_data);
- *pl_data = NULL;
+ struct ftp_parselist_data *parser = *parserp;
+ if(parser)
+ Curl_fileinfo_cleanup(parser->file_data);
+ free(parser);
+ *parserp = NULL;
}
@@ -264,24 +268,14 @@ static int ftp_pl_get_permission(const char *str)
return permissions;
}
-static void PL_ERROR(struct connectdata *conn, CURLcode err)
-{
- struct ftp_wc_tmpdata *tmpdata = conn->data->wildcard.tmp;
- struct ftp_parselist_data *parser = tmpdata->parser;
- if(parser->file_data)
- Curl_fileinfo_dtor(NULL, parser->file_data);
- parser->file_data = NULL;
- parser->error = err;
-}
-
static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
struct fileinfo *infop)
{
curl_fnmatch_callback compare;
struct WildcardData *wc = &conn->data->wildcard;
- struct ftp_wc_tmpdata *tmpdata = wc->tmp;
+ struct ftp_wc *ftpwc = wc->protdata;
struct curl_llist *llist = &wc->filelist;
- struct ftp_parselist_data *parser = tmpdata->parser;
+ struct ftp_parselist_data *parser = ftpwc->parser;
bool add = TRUE;
struct curl_fileinfo *finfo = &infop->info;
@@ -304,6 +298,7 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
compare = Curl_fnmatch;
/* filter pattern-corresponding filenames */
+ Curl_set_in_callback(conn->data, true);
if(compare(conn->data->set.fnmatch_data, wc->pattern,
finfo->filename) == 0) {
/* discard symlink which is containing multiple " -> " */
@@ -315,15 +310,16 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
else {
add = FALSE;
}
+ Curl_set_in_callback(conn->data, false);
if(add) {
Curl_llist_insert_next(llist, llist->tail, finfo, &infop->list);
}
else {
- Curl_fileinfo_dtor(NULL, finfo);
+ Curl_fileinfo_cleanup(infop);
}
- tmpdata->parser->file_data = NULL;
+ ftpwc->parser->file_data = NULL;
return CURLE_OK;
}
@@ -332,12 +328,13 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
{
size_t bufflen = size*nmemb;
struct connectdata *conn = (struct connectdata *)connptr;
- struct ftp_wc_tmpdata *tmpdata = conn->data->wildcard.tmp;
- struct ftp_parselist_data *parser = tmpdata->parser;
+ struct ftp_wc *ftpwc = conn->data->wildcard.protdata;
+ struct ftp_parselist_data *parser = ftpwc->parser;
struct fileinfo *infop;
struct curl_fileinfo *finfo;
unsigned long i = 0;
CURLcode result;
+ size_t retsize = bufflen;
if(parser->error) { /* error in previous call */
/* scenario:
@@ -346,7 +343,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
* 3. (last) call => is skipped RIGHT HERE and the error is hadled later
* in wc_statemach()
*/
- return bufflen;
+ goto fail;
}
if(parser->os_type == OS_TYPE_UNKNOWN && bufflen > 0) {
@@ -362,12 +359,12 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->file_data = Curl_fileinfo_alloc();
if(!parser->file_data) {
parser->error = CURLE_OUT_OF_MEMORY;
- return bufflen;
+ goto fail;
}
parser->file_data->info.b_data = malloc(FTP_BUFFER_ALLOCSIZE);
if(!parser->file_data->info.b_data) {
- PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
- return bufflen;
+ parser->error = CURLE_OUT_OF_MEMORY;
+ goto fail;
}
parser->file_data->info.b_size = FTP_BUFFER_ALLOCSIZE;
parser->item_offset = 0;
@@ -387,11 +384,10 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
finfo->b_data = tmp;
}
else {
- Curl_fileinfo_dtor(NULL, parser->file_data);
+ Curl_fileinfo_cleanup(parser->file_data);
parser->file_data = NULL;
parser->error = CURLE_OUT_OF_MEMORY;
- PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
- return bufflen;
+ goto fail;
}
}
@@ -409,7 +405,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.main = PL_UNIX_FILETYPE;
/* start FSM again not considering size of directory */
finfo->b_used = 0;
- i--;
+ continue;
}
break;
case PL_UNIX_TOTALSIZE_READING:
@@ -421,7 +417,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
else if(c == '\n') {
finfo->b_data[parser->item_length - 1] = 0;
if(strncmp("total ", finfo->b_data, 6) == 0) {
- char *endptr = finfo->b_data+6;
+ char *endptr = finfo->b_data + 6;
/* here we can deal with directory size, pass the leading white
spaces and then the digits */
while(ISSPACE(*endptr))
@@ -429,15 +425,15 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
while(ISDIGIT(*endptr))
endptr++;
if(*endptr != 0) {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
parser->state.UNIX.main = PL_UNIX_FILETYPE;
finfo->b_used = 0;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
break;
@@ -470,8 +466,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
finfo->filetype = CURLFILETYPE_DOOR;
break;
default:
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
parser->state.UNIX.main = PL_UNIX_PERMISSION;
parser->item_length = 0;
@@ -481,21 +477,21 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length++;
if(parser->item_length <= 9) {
if(!strchr("rwx-tTsS", c)) {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
else if(parser->item_length == 10) {
unsigned int perm;
if(c != ' ') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
finfo->b_data[10] = 0; /* terminate permissions */
perm = ftp_pl_get_permission(finfo->b_data + parser->item_offset);
if(perm & FTP_LP_MALFORMATED_PERM) {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
parser->file_data->info.flags |= CURLFINFOFLAG_KNOWN_PERM;
parser->file_data->info.perm = perm;
@@ -516,8 +512,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.hlinks = PL_UNIX_HLINKS_NUMBER;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
break;
@@ -538,8 +534,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.user = PL_UNIX_USER_PRESPACE;
}
else if(c < '0' || c > '9') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
}
@@ -598,8 +594,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.size = PL_UNIX_SIZE_NUMBER;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
break;
@@ -609,20 +605,22 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
char *p;
curl_off_t fsize;
finfo->b_data[parser->item_offset + parser->item_length - 1] = 0;
- fsize = curlx_strtoofft(finfo->b_data+parser->item_offset, &p, 10);
- if(p[0] == '\0' && fsize != CURL_OFF_T_MAX &&
- fsize != CURL_OFF_T_MIN) {
- parser->file_data->info.flags |= CURLFINFOFLAG_KNOWN_SIZE;
- parser->file_data->info.size = fsize;
+ if(!curlx_strtoofft(finfo->b_data + parser->item_offset,
+ &p, 10, &fsize)) {
+ if(p[0] == '\0' && fsize != CURL_OFF_T_MAX &&
+ fsize != CURL_OFF_T_MIN) {
+ parser->file_data->info.flags |= CURLFINFOFLAG_KNOWN_SIZE;
+ parser->file_data->info.size = fsize;
+ }
+ parser->item_length = 0;
+ parser->item_offset = 0;
+ parser->state.UNIX.main = PL_UNIX_TIME;
+ parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART1;
}
- parser->item_length = 0;
- parser->item_offset = 0;
- parser->state.UNIX.main = PL_UNIX_TIME;
- parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART1;
}
else if(!ISDIGIT(c)) {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
}
@@ -637,8 +635,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PART1;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
break;
@@ -648,8 +646,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART2;
}
else if(!ISALNUM(c) && c != '.') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
case PL_UNIX_TIME_PREPART2:
@@ -659,8 +657,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PART2;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
break;
@@ -670,8 +668,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART3;
}
else if(!ISALNUM(c) && c != '.') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
case PL_UNIX_TIME_PREPART3:
@@ -681,8 +679,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PART3;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
break;
@@ -706,8 +704,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
}
}
else if(!ISALNUM(c) && c != '.' && c != ':') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
}
@@ -732,8 +730,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.main = PL_UNIX_FILETYPE;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
- PL_ERROR(conn, result);
- return bufflen;
+ parser->error = result;
+ goto fail;
}
}
break;
@@ -744,13 +742,13 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.main = PL_UNIX_FILETYPE;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
- PL_ERROR(conn, result);
- return bufflen;
+ parser->error = result;
+ goto fail;
}
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
}
@@ -770,8 +768,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET1;
}
else if(c == '\r' || c == '\n') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
case PL_UNIX_SYMLINK_PRETARGET1:
@@ -780,8 +778,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET2;
}
else if(c == '\r' || c == '\n') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
@@ -793,8 +791,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET3;
}
else if(c == '\r' || c == '\n') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
@@ -811,8 +809,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_offset = 0;
}
else if(c == '\r' || c == '\n') {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
@@ -825,8 +823,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length = 1;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
case PL_UNIX_SYMLINK_TARGET:
@@ -839,8 +837,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.symlink_target = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
- PL_ERROR(conn, result);
- return bufflen;
+ parser->error = result;
+ goto fail;
}
parser->state.UNIX.main = PL_UNIX_FILETYPE;
}
@@ -851,14 +849,14 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.symlink_target = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
- PL_ERROR(conn, result);
- return bufflen;
+ parser->error = result;
+ goto fail;
}
parser->state.UNIX.main = PL_UNIX_FILETYPE;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
}
@@ -871,8 +869,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length++;
if(parser->item_length < 9) {
if(!strchr("0123456789-", c)) { /* only simple control */
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
else if(parser->item_length == 9) {
@@ -881,13 +879,13 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.NT.sub.time = PL_WINNT_TIME_PRESPACE;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
case PL_WINNT_TIME:
@@ -907,8 +905,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length = 0;
}
else if(!strchr("APM0123456789:", c)) {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
}
@@ -916,10 +914,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
case PL_WINNT_DIRORSIZE:
switch(parser->state.NT.sub.dirorsize) {
case PL_WINNT_DIRORSIZE_PRESPACE:
- if(c == ' ') {
-
- }
- else {
+ if(c != ' ') {
parser->item_offset = finfo->b_used - 1;
parser->item_length = 1;
parser->state.NT.sub.dirorsize = PL_WINNT_DIRORSIZE_CONTENT;
@@ -935,21 +930,11 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
}
else {
char *endptr;
- finfo->size = curlx_strtoofft(finfo->b_data +
- parser->item_offset,
- &endptr, 10);
- if(!*endptr) {
- if(finfo->size == CURL_OFF_T_MAX ||
- finfo->size == CURL_OFF_T_MIN) {
- if(errno == ERANGE) {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
- }
- }
- }
- else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ if(curlx_strtoofft(finfo->b_data +
+ parser->item_offset,
+ &endptr, 10, &finfo->size)) {
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
/* correct file type */
parser->file_data->info.filetype = CURLFILETYPE_FILE;
@@ -984,8 +969,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.filename = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
- PL_ERROR(conn, result);
- return bufflen;
+ parser->error = result;
+ goto fail;
}
parser->state.NT.main = PL_WINNT_DATE;
parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE;
@@ -996,15 +981,15 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.filename = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
- PL_ERROR(conn, result);
- return bufflen;
+ parser->error = result;
+ goto fail;
}
parser->state.NT.main = PL_WINNT_DATE;
parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE;
}
else {
- PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ parser->error = CURLE_FTP_BAD_FILE_LIST;
+ goto fail;
}
break;
}
@@ -1012,13 +997,23 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
}
break;
default:
- return bufflen + 1;
+ retsize = bufflen + 1;
+ goto fail;
}
i++;
}
+ return retsize;
+
+fail:
+
+ /* Clean up any allocated memory. */
+ if(parser->file_data) {
+ Curl_fileinfo_cleanup(parser->file_data);
+ parser->file_data = NULL;
+ }
- return bufflen;
+ return retsize;
}
#endif /* CURL_DISABLE_FTP */
diff --git a/Utilities/cmcurl/lib/getinfo.c b/Utilities/cmcurl/lib/getinfo.c
index a1ce5058e..e118da80d 100644
--- a/Utilities/cmcurl/lib/getinfo.c
+++ b/Utilities/cmcurl/lib/getinfo.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -54,6 +54,7 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
pro->t_starttransfer = 0;
pro->timespent = 0;
pro->t_redirect = 0;
+ pro->is_t_startransfer_set = false;
info->httpcode = 0;
info->httpproxycode = 0;
@@ -84,7 +85,6 @@ CURLcode Curl_initinfo(struct Curl_easy *data)
#ifdef USE_SSL
Curl_ssl_free_certinfo(data);
#endif
-
return CURLE_OK;
}
@@ -155,13 +155,18 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info,
*param_longp = data->info.httpproxycode;
break;
case CURLINFO_FILETIME:
- *param_longp = data->info.filetime;
+ if(data->info.filetime > LONG_MAX)
+ *param_longp = LONG_MAX;
+ else if(data->info.filetime < LONG_MIN)
+ *param_longp = LONG_MIN;
+ else
+ *param_longp = (long)data->info.filetime;
break;
case CURLINFO_HEADER_SIZE:
- *param_longp = data->info.header_size;
+ *param_longp = (long)data->info.header_size;
break;
case CURLINFO_REQUEST_SIZE:
- *param_longp = data->info.request_size;
+ *param_longp = (long)data->info.request_size;
break;
case CURLINFO_SSL_VERIFYRESULT:
*param_longp = data->set.ssl.certverifyresult;
@@ -246,27 +251,85 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info,
return CURLE_OK;
}
+#define DOUBLE_SECS(x) (double)(x)/1000000
+
+static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info,
+ curl_off_t *param_offt)
+{
+ switch(info) {
+ case CURLINFO_FILETIME_T:
+ *param_offt = (curl_off_t)data->info.filetime;
+ break;
+ case CURLINFO_SIZE_UPLOAD_T:
+ *param_offt = data->progress.uploaded;
+ break;
+ case CURLINFO_SIZE_DOWNLOAD_T:
+ *param_offt = data->progress.downloaded;
+ break;
+ case CURLINFO_SPEED_DOWNLOAD_T:
+ *param_offt = data->progress.dlspeed;
+ break;
+ case CURLINFO_SPEED_UPLOAD_T:
+ *param_offt = data->progress.ulspeed;
+ break;
+ case CURLINFO_CONTENT_LENGTH_DOWNLOAD_T:
+ *param_offt = (data->progress.flags & PGRS_DL_SIZE_KNOWN)?
+ data->progress.size_dl:-1;
+ break;
+ case CURLINFO_CONTENT_LENGTH_UPLOAD_T:
+ *param_offt = (data->progress.flags & PGRS_UL_SIZE_KNOWN)?
+ data->progress.size_ul:-1;
+ break;
+ case CURLINFO_TOTAL_TIME_T:
+ *param_offt = data->progress.timespent;
+ break;
+ case CURLINFO_NAMELOOKUP_TIME_T:
+ *param_offt = data->progress.t_nslookup;
+ break;
+ case CURLINFO_CONNECT_TIME_T:
+ *param_offt = data->progress.t_connect;
+ break;
+ case CURLINFO_APPCONNECT_TIME_T:
+ *param_offt = data->progress.t_appconnect;
+ break;
+ case CURLINFO_PRETRANSFER_TIME_T:
+ *param_offt = data->progress.t_pretransfer;
+ break;
+ case CURLINFO_STARTTRANSFER_TIME_T:
+ *param_offt = data->progress.t_starttransfer;
+ break;
+ case CURLINFO_REDIRECT_TIME_T:
+ *param_offt = data->progress.t_redirect;
+ break;
+
+ default:
+ return CURLE_UNKNOWN_OPTION;
+ }
+
+ return CURLE_OK;
+}
+
static CURLcode getinfo_double(struct Curl_easy *data, CURLINFO info,
double *param_doublep)
{
switch(info) {
case CURLINFO_TOTAL_TIME:
- *param_doublep = data->progress.timespent;
+ *param_doublep = DOUBLE_SECS(data->progress.timespent);
break;
case CURLINFO_NAMELOOKUP_TIME:
- *param_doublep = data->progress.t_nslookup;
+ *param_doublep = DOUBLE_SECS(data->progress.t_nslookup);
break;
case CURLINFO_CONNECT_TIME:
- *param_doublep = data->progress.t_connect;
+ *param_doublep = DOUBLE_SECS(data->progress.t_connect);
break;
case CURLINFO_APPCONNECT_TIME:
- *param_doublep = data->progress.t_appconnect;
+ *param_doublep = DOUBLE_SECS(data->progress.t_appconnect);
break;
case CURLINFO_PRETRANSFER_TIME:
- *param_doublep = data->progress.t_pretransfer;
+ *param_doublep = DOUBLE_SECS(data->progress.t_pretransfer);
break;
case CURLINFO_STARTTRANSFER_TIME:
- *param_doublep = data->progress.t_starttransfer;
+ *param_doublep = DOUBLE_SECS(data->progress.t_starttransfer);
break;
case CURLINFO_SIZE_UPLOAD:
*param_doublep = (double)data->progress.uploaded;
@@ -289,7 +352,7 @@ static CURLcode getinfo_double(struct Curl_easy *data, CURLINFO info,
(double)data->progress.size_ul:-1;
break;
case CURLINFO_REDIRECT_TIME:
- *param_doublep = data->progress.t_redirect;
+ *param_doublep = DOUBLE_SECS(data->progress.t_redirect);
break;
default:
@@ -326,46 +389,25 @@ static CURLcode getinfo_slist(struct Curl_easy *data, CURLINFO info,
struct curl_tlssessioninfo **tsip = (struct curl_tlssessioninfo **)
param_slistp;
struct curl_tlssessioninfo *tsi = &data->tsi;
- struct connectdata *conn = data->easy_conn;
+#ifdef USE_SSL
+ struct connectdata *conn = data->conn;
+#endif
*tsip = tsi;
tsi->backend = Curl_ssl_backend();
tsi->internals = NULL;
+#ifdef USE_SSL
if(conn && tsi->backend != CURLSSLBACKEND_NONE) {
unsigned int i;
for(i = 0; i < (sizeof(conn->ssl) / sizeof(conn->ssl[0])); ++i) {
if(conn->ssl[i].use) {
-#if defined(USE_AXTLS)
- tsi->internals = (void *)conn->ssl[i].ssl;
-#elif defined(USE_CYASSL)
- tsi->internals = (void *)conn->ssl[i].handle;
-#elif defined(USE_DARWINSSL)
- tsi->internals = (void *)conn->ssl[i].ssl_ctx;
-#elif defined(USE_GNUTLS)
- tsi->internals = (void *)conn->ssl[i].session;
-#elif defined(USE_GSKIT)
- tsi->internals = (void *)conn->ssl[i].handle;
-#elif defined(USE_MBEDTLS)
- tsi->internals = (void *)&conn->ssl[i].ssl;
-#elif defined(USE_NSS)
- tsi->internals = (void *)conn->ssl[i].handle;
-#elif defined(USE_OPENSSL)
- /* Legacy: CURLINFO_TLS_SESSION must return an SSL_CTX pointer. */
- tsi->internals = ((info == CURLINFO_TLS_SESSION) ?
- (void *)conn->ssl[i].ctx :
- (void *)conn->ssl[i].handle);
-#elif defined(USE_POLARSSL)
- tsi->internals = (void *)&conn->ssl[i].ssl;
-#elif defined(USE_SCHANNEL)
- tsi->internals = (void *)&conn->ssl[i].ctxt->ctxt_handle;
-#elif defined(USE_SSL)
-#error "SSL backend specific information missing for CURLINFO_TLS_SSL_PTR"
-#endif
+ tsi->internals = Curl_ssl->get_internals(&conn->ssl[i], info);
break;
}
}
}
+#endif
}
break;
default:
@@ -394,6 +436,7 @@ CURLcode Curl_getinfo(struct Curl_easy *data, CURLINFO info, ...)
va_list arg;
long *param_longp = NULL;
double *param_doublep = NULL;
+ curl_off_t *param_offt = NULL;
const char **param_charp = NULL;
struct curl_slist **param_slistp = NULL;
curl_socket_t *param_socketp = NULL;
@@ -422,6 +465,11 @@ CURLcode Curl_getinfo(struct Curl_easy *data, CURLINFO info, ...)
if(param_doublep)
result = getinfo_double(data, info, param_doublep);
break;
+ case CURLINFO_OFF_T:
+ param_offt = va_arg(arg, curl_off_t *);
+ if(param_offt)
+ result = getinfo_offt(data, info, param_offt);
+ break;
case CURLINFO_SLIST:
param_slistp = va_arg(arg, struct curl_slist **);
if(param_slistp)
diff --git a/Utilities/cmcurl/lib/gopher.c b/Utilities/cmcurl/lib/gopher.c
index e6d274648..b296c62d1 100644
--- a/Utilities/cmcurl/lib/gopher.c
+++ b/Utilities/cmcurl/lib/gopher.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -31,9 +31,11 @@
#include "progress.h"
#include "gopher.h"
#include "select.h"
+#include "strdup.h"
#include "url.h"
#include "escape.h"
#include "warnless.h"
+#include "curl_printf.h"
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
@@ -65,6 +67,7 @@ const struct Curl_handler Curl_handler_gopher = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_GOPHER, /* defport */
CURLPROTO_GOPHER, /* protocol */
PROTOPT_NONE /* flags */
@@ -72,12 +75,12 @@ const struct Curl_handler Curl_handler_gopher = {
static CURLcode gopher_do(struct connectdata *conn, bool *done)
{
- CURLcode result=CURLE_OK;
- struct Curl_easy *data=conn->data;
+ CURLcode result = CURLE_OK;
+ struct Curl_easy *data = conn->data;
curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
-
- curl_off_t *bytecount = &data->req.bytecount;
- char *path = data->state.path;
+ char *gopherpath;
+ char *path = data->state.up.path;
+ char *query = data->state.up.query;
char *sel = NULL;
char *sel_org = NULL;
ssize_t amount, k;
@@ -85,27 +88,33 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
*done = TRUE; /* unconditionally */
+ /* path is guaranteed non-NULL */
+ DEBUGASSERT(path);
+
+ if(query)
+ gopherpath = aprintf("%s?%s", path, query);
+ else
+ gopherpath = strdup(path);
+
+ if(!gopherpath)
+ return CURLE_OUT_OF_MEMORY;
+
/* Create selector. Degenerate cases: / and /1 => convert to "" */
- if(strlen(path) <= 2) {
+ if(strlen(gopherpath) <= 2) {
sel = (char *)"";
- len = (int)strlen(sel);
+ len = strlen(sel);
+ free(gopherpath);
}
else {
char *newp;
- size_t j, i;
/* Otherwise, drop / and the first character (i.e., item type) ... */
- newp = path;
- newp+=2;
-
- /* ... then turn ? into TAB for search servers, Veronica, etc. ... */
- j = strlen(newp);
- for(i=0; i<j; i++)
- if(newp[i] == '?')
- newp[i] = '\x09';
+ newp = gopherpath;
+ newp += 2;
/* ... and finally unescape */
result = Curl_urldecode(data, newp, 0, &sel, &len, FALSE);
+ free(gopherpath);
if(result)
return result;
sel_org = sel;
@@ -159,8 +168,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
if(result)
return result;
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
- -1, NULL); /* no upload */
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
return CURLE_OK;
}
#endif /*CURL_DISABLE_GOPHER*/
diff --git a/Utilities/cmcurl/lib/hash.c b/Utilities/cmcurl/lib/hash.c
index 6afeaa12c..421d68f76 100644
--- a/Utilities/cmcurl/lib/hash.c
+++ b/Utilities/cmcurl/lib/hash.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -60,8 +60,6 @@ Curl_hash_init(struct curl_hash *h,
comp_function comparator,
curl_hash_dtor dtor)
{
- int i;
-
if(!slots || !hfunc || !comparator ||!dtor) {
return 1; /* failure */
}
@@ -74,6 +72,7 @@ Curl_hash_init(struct curl_hash *h,
h->table = malloc(slots * sizeof(struct curl_llist));
if(h->table) {
+ int i;
for(i = 0; i < slots; ++i)
Curl_llist_init(&h->table[i], (curl_llist_dtor) hash_element_dtor);
return 0; /* fine */
@@ -140,11 +139,10 @@ Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p)
int Curl_hash_delete(struct curl_hash *h, void *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;
+ struct curl_hash_element *he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) {
Curl_llist_remove(l, le, (void *) h);
--h->size;
@@ -162,13 +160,12 @@ void *
Curl_hash_pick(struct curl_hash *h, void *key, size_t key_len)
{
struct curl_llist_element *le;
- struct curl_hash_element *he;
struct curl_llist *l;
if(h) {
l = FETCH_LIST(h, key, key_len);
for(le = l->head; le; le = le->next) {
- he = le->ptr;
+ struct curl_hash_element *he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) {
return he->ptr;
}
@@ -261,11 +258,11 @@ size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num)
{
const char *key_str = (const char *) key;
const char *end = key_str + key_length;
- unsigned long h = 5381;
+ size_t h = 5381;
while(key_str < end) {
h += h << 5;
- h ^= (unsigned long) *key_str++;
+ h ^= *key_str++;
}
return (h % slots_num);
@@ -291,7 +288,6 @@ void Curl_hash_start_iterate(struct curl_hash *hash,
struct curl_hash_element *
Curl_hash_next_element(struct curl_hash_iterator *iter)
{
- int i;
struct curl_hash *h = iter->hash;
/* Get the next element in the current list, if any */
@@ -300,10 +296,11 @@ Curl_hash_next_element(struct curl_hash_iterator *iter)
/* If we have reached the end of the list, find the next one */
if(!iter->current_element) {
- for(i = iter->slot_index;i < h->slots;i++) {
+ int i;
+ for(i = iter->slot_index; i < h->slots; i++) {
if(h->table[i].head) {
iter->current_element = h->table[i].head;
- iter->slot_index = i+1;
+ iter->slot_index = i + 1;
break;
}
}
diff --git a/Utilities/cmcurl/lib/hmac.c b/Utilities/cmcurl/lib/hmac.c
index dae95054b..bf49ebec5 100644
--- a/Utilities/cmcurl/lib/hmac.c
+++ b/Utilities/cmcurl/lib/hmac.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -58,7 +58,7 @@ Curl_HMAC_init(const HMAC_params * hashparams,
unsigned char b;
/* Create HMAC context. */
- i = sizeof *ctxt + 2 * hashparams->hmac_ctxtsize +
+ i = sizeof(*ctxt) + 2 * hashparams->hmac_ctxtsize +
hashparams->hmac_resultlen;
ctxt = malloc(i);
diff --git a/Utilities/cmcurl/lib/hostasyn.c b/Utilities/cmcurl/lib/hostasyn.c
index 28bdf7a48..99d872b35 100644
--- a/Utilities/cmcurl/lib/hostasyn.c
+++ b/Utilities/cmcurl/lib/hostasyn.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,6 +22,11 @@
#include "curl_setup.h"
+/***********************************************************************
+ * Only for builds using asynchronous name resolves
+ **********************************************************************/
+#ifdef CURLRES_ASYNCH
+
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -51,11 +56,6 @@
/* The last #include file should be: */
#include "memdebug.h"
-/***********************************************************************
- * Only for builds using asynchronous name resolves
- **********************************************************************/
-#ifdef CURLRES_ASYNCH
-
/*
* Curl_addrinfo_callback() gets called by ares, gethostbyname_thread()
* or getaddrinfo_thread() when we got the name resolved (or not!).
@@ -85,14 +85,14 @@ CURLcode Curl_addrinfo_callback(struct connectdata *conn,
dns = Curl_cache_addr(data, ai,
conn->async.hostname,
conn->async.port);
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+
if(!dns) {
/* failed to store, cleanup and return error */
Curl_freeaddrinfo(ai);
result = CURLE_OUT_OF_MEMORY;
}
-
- if(data->share)
- Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
}
else {
result = CURLE_OUT_OF_MEMORY;
@@ -111,31 +111,6 @@ CURLcode Curl_addrinfo_callback(struct connectdata *conn,
return result;
}
-/* 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)
-{
- CURLcode result;
-
- if(conn->async.dns) {
- conn->dns_entry = conn->async.dns;
- conn->async.dns = NULL;
- }
-
- result = Curl_setup_conn(conn, protocol_done);
-
- if(result)
- /* We're not allowed to return failure with memory left allocated
- in the connectdata struct, free those here */
- Curl_disconnect(conn, FALSE); /* close the connection */
-
- return result;
-}
-
/*
* Curl_getaddrinfo() is the generic low-level name resolve API within this
* source file. There are several versions of this function - for different
diff --git a/Utilities/cmcurl/lib/hostcheck.c b/Utilities/cmcurl/lib/hostcheck.c
index 156091ca8..115d24b2e 100644
--- a/Utilities/cmcurl/lib/hostcheck.c
+++ b/Utilities/cmcurl/lib/hostcheck.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -23,14 +23,16 @@
#include "curl_setup.h"
#if defined(USE_OPENSSL) \
- || defined(USE_AXTLS) \
|| defined(USE_GSKIT) \
- || (defined(USE_SCHANNEL) && defined(_WIN32_WCE))
+ || defined(USE_SCHANNEL)
/* these backends use functions from this file */
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
+#ifdef HAVE_NETINET_IN6_H
+#include <netinet/in6.h>
+#endif
#include "hostcheck.h"
#include "strcase.h"
@@ -73,10 +75,10 @@ static int hostmatch(char *hostname, char *pattern)
/* normalize pattern and hostname by stripping off trailing dots */
size_t len = strlen(hostname);
if(hostname[len-1]=='.')
- hostname[len-1]=0;
+ hostname[len-1] = 0;
len = strlen(pattern);
if(pattern[len-1]=='.')
- pattern[len-1]=0;
+ pattern[len-1] = 0;
pattern_wildcard = strchr(pattern, '*');
if(pattern_wildcard == NULL)
@@ -95,7 +97,7 @@ static int hostmatch(char *hostname, char *pattern)
match. */
wildcard_enabled = 1;
pattern_label_end = strchr(pattern, '.');
- if(pattern_label_end == NULL || strchr(pattern_label_end+1, '.') == NULL ||
+ if(pattern_label_end == NULL || strchr(pattern_label_end + 1, '.') == NULL ||
pattern_wildcard > pattern_label_end ||
strncasecompare(pattern, "xn--", 4)) {
wildcard_enabled = 0;
@@ -116,28 +118,26 @@ static int hostmatch(char *hostname, char *pattern)
return CURL_HOST_NOMATCH;
prefixlen = pattern_wildcard - pattern;
- suffixlen = pattern_label_end - (pattern_wildcard+1);
+ suffixlen = pattern_label_end - (pattern_wildcard + 1);
return strncasecompare(pattern, hostname, prefixlen) &&
- strncasecompare(pattern_wildcard+1, hostname_label_end - suffixlen,
+ strncasecompare(pattern_wildcard + 1, hostname_label_end - suffixlen,
suffixlen) ?
CURL_HOST_MATCH : CURL_HOST_NOMATCH;
}
int Curl_cert_hostcheck(const char *match_pattern, const char *hostname)
{
- char *matchp;
- char *hostp;
int res = 0;
if(!match_pattern || !*match_pattern ||
!hostname || !*hostname) /* sanity check */
;
else {
- matchp = strdup(match_pattern);
+ char *matchp = strdup(match_pattern);
if(matchp) {
- hostp = strdup(hostname);
+ char *hostp = strdup(hostname);
if(hostp) {
if(hostmatch(hostp, matchp) == CURL_HOST_MATCH)
- res= 1;
+ res = 1;
free(hostp);
}
free(matchp);
@@ -147,4 +147,4 @@ int Curl_cert_hostcheck(const char *match_pattern, const char *hostname)
return res;
}
-#endif /* OPENSSL, AXTLS, GSKIT or schannel+wince */
+#endif /* OPENSSL, GSKIT or schannel+wince */
diff --git a/Utilities/cmcurl/lib/hostcheck.h b/Utilities/cmcurl/lib/hostcheck.h
index 86e3b96a9..f562df9ae 100644
--- a/Utilities/cmcurl/lib/hostcheck.h
+++ b/Utilities/cmcurl/lib/hostcheck.h
@@ -29,4 +29,3 @@
int Curl_cert_hostcheck(const char *match_pattern, const char *hostname);
#endif /* HEADER_CURL_HOSTCHECK_H */
-
diff --git a/Utilities/cmcurl/lib/hostip.c b/Utilities/cmcurl/lib/hostip.c
index 619ec84b5..cf33ed8f4 100644
--- a/Utilities/cmcurl/lib/hostip.c
+++ b/Utilities/cmcurl/lib/hostip.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -25,6 +25,9 @@
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
+#ifdef HAVE_NETINET_IN6_H
+#include <netinet/in6.h>
+#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
@@ -51,10 +54,13 @@
#include "sendf.h"
#include "hostip.h"
#include "hash.h"
+#include "rand.h"
#include "share.h"
#include "strerror.h"
#include "url.h"
#include "inet_ntop.h"
+#include "multiif.h"
+#include "doh.h"
#include "warnless.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -67,6 +73,8 @@
#define USE_ALARM_TIMEOUT
#endif
+#define MAX_HOSTCACHE_LEN (255 + 7) /* max FQDN + colon + port number + zero */
+
/*
* hostip.c explained
* ==================
@@ -106,43 +114,9 @@
* CURLRES_* defines based on the config*.h and curl_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!
- *
- * Returns a struct curl_hash pointer on success, NULL on failure.
- */
-struct curl_hash *Curl_global_host_cache_init(void)
-{
- int rc = 0;
- if(!host_cache_initialized) {
- rc = Curl_hash_init(&hostname_cache, 7, Curl_hash_str,
- Curl_str_key_compare, freednsentry);
- if(!rc)
- host_cache_initialized = 1;
- }
- return rc?NULL:&hostname_cache;
-}
-
-/*
- * Destroy and cleanup the global DNS cache
- */
-void Curl_global_host_cache_dtor(void)
-{
- if(host_cache_initialized) {
- Curl_hash_destroy(&hostname_cache);
- host_cache_initialized = 0;
- }
-}
-
-/*
* Return # of addresses in a Curl_addrinfo struct
*/
int Curl_num_addresses(const Curl_addrinfo *addr)
@@ -192,23 +166,19 @@ Curl_printable_address(const Curl_addrinfo *ai, char *buf, size_t bufsize)
}
/*
- * Return a hostcache id string for the provided host + port, to be used by
- * the DNS caching.
+ * Create a hostcache id string for the provided host + port, to be used by
+ * the DNS caching. Without alloc.
*/
-static char *
-create_hostcache_id(const char *name, int port)
+static void
+create_hostcache_id(const char *name, int port, char *ptr, size_t buflen)
{
- /* create and return the new allocated entry */
- char *id = aprintf("%s:%d", name, port);
- char *ptr = id;
- if(ptr) {
- /* lower case the name part */
- while(*ptr && (*ptr != ':')) {
- *ptr = (char)TOLOWER(*ptr);
- ptr++;
- }
- }
- return id;
+ size_t len = strlen(name);
+ if(len > (buflen - 7))
+ len = buflen - 7;
+ /* store and lower case the name */
+ while(len--)
+ *ptr++ = (char)TOLOWER(*name++);
+ msnprintf(ptr, 7, ":%u", port);
}
struct hostcache_prune_data {
@@ -290,23 +260,28 @@ fetch_addr(struct connectdata *conn,
const char *hostname,
int port)
{
- char *entry_id = NULL;
struct Curl_dns_entry *dns = NULL;
size_t entry_len;
struct Curl_easy *data = conn->data;
+ char entry_id[MAX_HOSTCACHE_LEN];
/* 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 dns;
-
+ create_hostcache_id(hostname, port, entry_id, sizeof(entry_id));
entry_len = strlen(entry_id);
/* See if its already in our dns cache */
- dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len+1);
+ dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1);
+
+ /* No entry found in cache, check if we might have a wildcard entry */
+ if(!dns && data->change.wildcard_resolve) {
+ create_hostcache_id("*", port, entry_id, sizeof(entry_id));
+ entry_len = strlen(entry_id);
+
+ /* See if it's already in our dns cache */
+ dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1);
+ }
- if(dns && (data->set.dns_cache_timeout != -1)) {
+ if(dns && (data->set.dns_cache_timeout != -1)) {
/* See whether the returned entry is stale. Done before we release lock */
struct hostcache_prune_data user;
@@ -316,13 +291,10 @@ fetch_addr(struct connectdata *conn,
if(hostcache_timestamp_remove(&user, dns)) {
infof(data, "Hostname in DNS cache was stale, zapped\n");
dns = NULL; /* the memory deallocation is being handled by the hash */
- Curl_hash_delete(data->dns.hostcache, entry_id, entry_len+1);
+ Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1);
}
}
- /* free the allocated entry_id again */
- free(entry_id);
-
return dns;
}
@@ -362,6 +334,75 @@ Curl_fetch_addr(struct connectdata *conn,
return dns;
}
+#ifndef CURL_DISABLE_SHUFFLE_DNS
+UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data,
+ Curl_addrinfo **addr);
+/*
+ * Curl_shuffle_addr() shuffles the order of addresses in a 'Curl_addrinfo'
+ * struct by re-linking its linked list.
+ *
+ * The addr argument should be the address of a pointer to the head node of a
+ * `Curl_addrinfo` list and it will be modified to point to the new head after
+ * shuffling.
+ *
+ * Not declared static only to make it easy to use in a unit test!
+ *
+ * @unittest: 1608
+ */
+UNITTEST CURLcode Curl_shuffle_addr(struct Curl_easy *data,
+ Curl_addrinfo **addr)
+{
+ CURLcode result = CURLE_OK;
+ const int num_addrs = Curl_num_addresses(*addr);
+
+ if(num_addrs > 1) {
+ Curl_addrinfo **nodes;
+ infof(data, "Shuffling %i addresses", num_addrs);
+
+ nodes = malloc(num_addrs*sizeof(*nodes));
+ if(nodes) {
+ int i;
+ unsigned int *rnd;
+ const size_t rnd_size = num_addrs * sizeof(*rnd);
+
+ /* build a plain array of Curl_addrinfo pointers */
+ nodes[0] = *addr;
+ for(i = 1; i < num_addrs; i++) {
+ nodes[i] = nodes[i-1]->ai_next;
+ }
+
+ rnd = malloc(rnd_size);
+ if(rnd) {
+ /* Fisher-Yates shuffle */
+ if(Curl_rand(data, (unsigned char *)rnd, rnd_size) == CURLE_OK) {
+ Curl_addrinfo *swap_tmp;
+ for(i = num_addrs - 1; i > 0; i--) {
+ swap_tmp = nodes[rnd[i] % (i + 1)];
+ nodes[rnd[i] % (i + 1)] = nodes[i];
+ nodes[i] = swap_tmp;
+ }
+
+ /* relink list in the new order */
+ for(i = 1; i < num_addrs; i++) {
+ nodes[i-1]->ai_next = nodes[i];
+ }
+
+ nodes[num_addrs-1]->ai_next = NULL;
+ *addr = nodes[0];
+ }
+ free(rnd);
+ }
+ else
+ result = CURLE_OUT_OF_MEMORY;
+ free(nodes);
+ }
+ else
+ result = CURLE_OUT_OF_MEMORY;
+ }
+ return result;
+}
+#endif
+
/*
* Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
*
@@ -377,25 +418,30 @@ Curl_cache_addr(struct Curl_easy *data,
const char *hostname,
int port)
{
- char *entry_id;
+ char entry_id[MAX_HOSTCACHE_LEN];
size_t entry_len;
struct Curl_dns_entry *dns;
struct Curl_dns_entry *dns2;
- /* 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);
+#ifndef CURL_DISABLE_SHUFFLE_DNS
+ /* shuffle addresses if requested */
+ if(data->set.dns_shuffle_addresses) {
+ CURLcode result = Curl_shuffle_addr(data, &addr);
+ if(result)
+ return NULL;
+ }
+#endif
/* Create a new cache entry */
dns = calloc(1, sizeof(struct Curl_dns_entry));
if(!dns) {
- free(entry_id);
return NULL;
}
+ /* Create an entry id, based upon the hostname and port */
+ create_hostcache_id(hostname, port, entry_id, sizeof(entry_id));
+ entry_len = strlen(entry_id);
+
dns->inuse = 1; /* the cache has the first reference */
dns->addr = addr; /* this is the address(es) */
time(&dns->timestamp);
@@ -403,20 +449,15 @@ Curl_cache_addr(struct Curl_easy *data,
dns->timestamp = 1; /* zero indicates CURLOPT_RESOLVE entry */
/* Store the resolved data in our DNS cache. */
- dns2 = Curl_hash_add(data->dns.hostcache, entry_id, entry_len+1,
+ dns2 = Curl_hash_add(data->dns.hostcache, entry_id, entry_len + 1,
(void *)dns);
if(!dns2) {
free(dns);
- free(entry_id);
return NULL;
}
dns = dns2;
dns->inuse++; /* mark entry as in-use */
-
- /* free the allocated entry_id */
- free(entry_id);
-
return dns;
}
@@ -444,6 +485,7 @@ Curl_cache_addr(struct Curl_easy *data,
int Curl_resolv(struct connectdata *conn,
const char *hostname,
int port,
+ bool allowDOH,
struct Curl_dns_entry **entry)
{
struct Curl_dns_entry *dns = NULL;
@@ -471,30 +513,45 @@ int Curl_resolv(struct connectdata *conn,
/* The entry was not in the cache. Resolve it to IP address */
Curl_addrinfo *addr;
- int respwait;
+ int respwait = 0;
/* Check what IP specifics the app has requested and if we can provide it.
* If not, bail out. */
if(!Curl_ipvalid(conn))
return CURLRESOLV_ERROR;
- /* If Curl_getaddrinfo() returns NULL, 'respwait' 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,
+ /* notify the resolver start callback */
+ if(data->set.resolver_start) {
+ int st;
+ Curl_set_in_callback(data, true);
+ st = data->set.resolver_start(data->state.resolver, NULL,
+ data->set.resolver_start_client);
+ Curl_set_in_callback(data, false);
+ if(st)
+ return CURLRESOLV_ERROR;
+ }
+
+ if(allowDOH && data->set.doh) {
+ addr = Curl_doh(conn, hostname, port, &respwait);
+ }
+ else {
+ /* If Curl_getaddrinfo() returns NULL, 'respwait' 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,
#ifdef DEBUGBUILD
- (data->set.str[STRING_DEVICE]
- && !strcmp(data->set.str[STRING_DEVICE],
- "LocalHost"))?"localhost":
+ (data->set.str[STRING_DEVICE]
+ && !strcmp(data->set.str[STRING_DEVICE],
+ "LocalHost"))?"localhost":
#endif
- hostname, port, &respwait);
-
+ hostname, port, &respwait);
+ }
if(!addr) {
if(respwait) {
/* 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_resolver_is_resolved(conn, &dns);
+ result = Curl_resolv_check(conn, &dns);
if(result) /* error detected */
return CURLRESOLV_ERROR;
if(dns)
@@ -600,7 +657,7 @@ int Curl_resolv_timeout(struct connectdata *conn,
if(!timeout)
/* USE_ALARM_TIMEOUT defined, but no timeout actually requested */
- return Curl_resolv(conn, hostname, port, entry);
+ return Curl_resolv(conn, hostname, port, TRUE, entry);
if(timeout < 1000) {
/* The alarm() function only provides integer second resolution, so if
@@ -662,7 +719,7 @@ int Curl_resolv_timeout(struct connectdata *conn,
/* Perform the actual name resolution. This might be interrupted by an
* alarm if it takes too long.
*/
- rc = Curl_resolv(conn, hostname, port, entry);
+ rc = Curl_resolv(conn, hostname, port, TRUE, entry);
#ifdef USE_ALARM_TIMEOUT
clean_up:
@@ -688,8 +745,8 @@ clean_up:
the time we spent until now! */
if(prev_alarm) {
/* there was an alarm() set before us, now put it back */
- unsigned long elapsed_secs = (unsigned long) (Curl_tvdiff(Curl_tvnow(),
- conn->created) / 1000);
+ timediff_t elapsed_secs = Curl_timediff(Curl_now(),
+ conn->created) / 1000;
/* the alarm period is counted in even number of seconds */
unsigned long alarm_set = prev_alarm - elapsed_secs;
@@ -778,14 +835,16 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
{
struct curl_slist *hostp;
char hostname[256];
- char address[256];
- int port;
+ int port = 0;
+
+ /* Default is no wildcard found */
+ data->change.wildcard_resolve = false;
for(hostp = data->change.resolve; hostp; hostp = hostp->next) {
+ char entry_id[MAX_HOSTCACHE_LEN];
if(!hostp->data)
continue;
if(hostp->data[0] == '-') {
- char *entry_id;
size_t entry_len;
if(2 != sscanf(hostp->data + 1, "%255[^:]:%d", hostname, &port)) {
@@ -795,90 +854,217 @@ CURLcode Curl_loadhostpairs(struct Curl_easy *data)
}
/* 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 CURLE_OUT_OF_MEMORY;
- }
-
+ create_hostcache_id(hostname, port, entry_id, sizeof(entry_id));
entry_len = strlen(entry_id);
if(data->share)
Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
/* delete entry, ignore if it didn't exist */
- Curl_hash_delete(data->dns.hostcache, entry_id, entry_len+1);
+ Curl_hash_delete(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);
}
else {
struct Curl_dns_entry *dns;
- Curl_addrinfo *addr;
- char *entry_id;
+ Curl_addrinfo *head = NULL, *tail = NULL;
size_t entry_len;
+ char address[64];
+#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
+ char *addresses = NULL;
+#endif
+ char *addr_begin;
+ char *addr_end;
+ char *port_ptr;
+ char *end_ptr;
+ char *host_end;
+ unsigned long tmp_port;
+ bool error = true;
+
+ host_end = strchr(hostp->data, ':');
+ if(!host_end ||
+ ((host_end - hostp->data) >= (ptrdiff_t)sizeof(hostname)))
+ goto err;
+
+ memcpy(hostname, hostp->data, host_end - hostp->data);
+ hostname[host_end - hostp->data] = '\0';
+
+ port_ptr = host_end + 1;
+ tmp_port = strtoul(port_ptr, &end_ptr, 10);
+ if(tmp_port > USHRT_MAX || end_ptr == port_ptr || *end_ptr != ':')
+ goto err;
+
+ port = (int)tmp_port;
+#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
+ addresses = end_ptr + 1;
+#endif
- if(3 != sscanf(hostp->data, "%255[^:]:%d:%255s", hostname, &port,
- address)) {
- infof(data, "Couldn't parse CURLOPT_RESOLVE entry '%s'!\n",
- hostp->data);
- continue;
+ while(*end_ptr) {
+ size_t alen;
+ Curl_addrinfo *ai;
+
+ addr_begin = end_ptr + 1;
+ addr_end = strchr(addr_begin, ',');
+ if(!addr_end)
+ addr_end = addr_begin + strlen(addr_begin);
+ end_ptr = addr_end;
+
+ /* allow IP(v6) address within [brackets] */
+ if(*addr_begin == '[') {
+ if(addr_end == addr_begin || *(addr_end - 1) != ']')
+ goto err;
+ ++addr_begin;
+ --addr_end;
+ }
+
+ alen = addr_end - addr_begin;
+ if(!alen)
+ continue;
+
+ if(alen >= sizeof(address))
+ goto err;
+
+ memcpy(address, addr_begin, alen);
+ address[alen] = '\0';
+
+#ifndef ENABLE_IPV6
+ if(strchr(address, ':')) {
+ infof(data, "Ignoring resolve address '%s', missing IPv6 support.\n",
+ address);
+ continue;
+ }
+#endif
+
+ ai = Curl_str2addr(address, port);
+ if(!ai) {
+ infof(data, "Resolve address '%s' found illegal!\n", address);
+ goto err;
+ }
+
+ if(tail) {
+ tail->ai_next = ai;
+ tail = tail->ai_next;
+ }
+ else {
+ head = tail = ai;
+ }
}
- addr = Curl_str2addr(address, port);
- if(!addr) {
- infof(data, "Address in '%s' found illegal!\n", hostp->data);
+ if(!head)
+ goto err;
+
+ error = false;
+ err:
+ if(error) {
+ infof(data, "Couldn't parse CURLOPT_RESOLVE entry '%s'!\n",
+ hostp->data);
+ Curl_freeaddrinfo(head);
continue;
}
/* 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) {
- Curl_freeaddrinfo(addr);
- return CURLE_OUT_OF_MEMORY;
- }
-
+ create_hostcache_id(hostname, port, entry_id, sizeof(entry_id));
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);
-
- /* free the allocated entry_id again */
- free(entry_id);
+ dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len + 1);
+
+ if(dns) {
+ infof(data, "RESOLVE %s:%d is - old addresses discarded!\n",
+ hostname, port);
+ /* delete old entry entry, there are two reasons for this
+ 1. old entry may have different addresses.
+ 2. even if entry with correct addresses is already in the cache,
+ but if it is close to expire, then by the time next http
+ request is made, it can get expired and pruned because old
+ entry is not necessarily marked as added by CURLOPT_RESOLVE. */
+
+ Curl_hash_delete(data->dns.hostcache, entry_id, entry_len + 1);
+ }
- if(!dns) {
- /* if not in the cache already, put this host in the cache */
- dns = Curl_cache_addr(data, addr, hostname, port);
- if(dns) {
- dns->timestamp = 0; /* mark as added by CURLOPT_RESOLVE */
- /* release the returned reference; the cache itself will keep the
- * entry alive: */
- dns->inuse--;
- }
+ /* put this new host in the cache */
+ dns = Curl_cache_addr(data, head, hostname, port);
+ if(dns) {
+ dns->timestamp = 0; /* mark as added by CURLOPT_RESOLVE */
+ /* release the returned reference; the cache itself will keep the
+ * entry alive: */
+ dns->inuse--;
}
- else
- /* this is a duplicate, free it again */
- Curl_freeaddrinfo(addr);
if(data->share)
Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
if(!dns) {
- Curl_freeaddrinfo(addr);
+ Curl_freeaddrinfo(head);
return CURLE_OUT_OF_MEMORY;
}
infof(data, "Added %s:%d:%s to DNS cache\n",
- hostname, port, address);
+ hostname, port, addresses);
+
+ /* Wildcard hostname */
+ if(hostname[0] == '*' && hostname[1] == '\0') {
+ infof(data, "RESOLVE %s:%d is wildcard, enabling wildcard checks\n",
+ hostname, port);
+ data->change.wildcard_resolve = true;
+ }
}
}
data->change.resolve = NULL; /* dealt with now */
return CURLE_OK;
}
+
+CURLcode Curl_resolv_check(struct connectdata *conn,
+ struct Curl_dns_entry **dns)
+{
+ if(conn->data->set.doh)
+ return Curl_doh_is_resolved(conn, dns);
+ return Curl_resolver_is_resolved(conn, dns);
+}
+
+int Curl_resolv_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks)
+{
+#ifdef CURLRES_ASYNCH
+ if(conn->data->set.doh)
+ /* nothing to wait for during DOH resolve, those handles have their own
+ sockets */
+ return GETSOCK_BLANK;
+ return Curl_resolver_getsock(conn, socks, numsocks);
+#else
+ (void)conn;
+ (void)socks;
+ (void)numsocks;
+ return GETSOCK_BLANK;
+#endif
+}
+
+/* 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_once_resolved(struct connectdata *conn,
+ bool *protocol_done)
+{
+ CURLcode result;
+
+ if(conn->async.dns) {
+ conn->dns_entry = conn->async.dns;
+ conn->async.dns = NULL;
+ }
+
+ result = Curl_setup_conn(conn, protocol_done);
+
+ if(result)
+ /* We're not allowed to return failure with memory left allocated
+ in the connectdata struct, free those here */
+ Curl_disconnect(conn->data, conn, TRUE); /* close the connection */
+
+ return result;
+}
diff --git a/Utilities/cmcurl/lib/hostip.h b/Utilities/cmcurl/lib/hostip.h
index 298eeeee3..9dc0d5a17 100644
--- a/Utilities/cmcurl/lib/hostip.h
+++ b/Utilities/cmcurl/lib/hostip.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -83,8 +83,11 @@ struct Curl_dns_entry {
#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);
+int Curl_resolv(struct connectdata *conn,
+ const char *hostname,
+ int port,
+ bool allowDOH,
+ struct Curl_dns_entry **dnsentry);
int Curl_resolv_timeout(struct connectdata *conn, const char *hostname,
int port, struct Curl_dns_entry **dnsentry,
time_t timeoutms);
@@ -145,12 +148,7 @@ int curl_dogetnameinfo(GETNAMEINFO_QUAL_ARG1 GETNAMEINFO_TYPE_ARG1 sa,
/* IPv4 threadsafe resolve function used for synch and asynch builds */
Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port);
-CURLcode Curl_async_resolved(struct connectdata *conn,
- bool *protocol_connect);
-
-#ifndef CURLRES_ASYNCH
-#define Curl_async_resolved(x,y) CURLE_OK
-#endif
+CURLcode Curl_once_resolved(struct connectdata *conn, bool *protocol_connect);
/*
* Curl_addrinfo_callback() is used when we build with any asynch specialty.
@@ -182,6 +180,7 @@ struct Curl_dns_entry *
Curl_fetch_addr(struct connectdata *conn,
const char *hostname,
int port);
+
/*
* Curl_cache_addr() stores a 'Curl_addrinfo' struct in the DNS cache.
*
@@ -247,4 +246,10 @@ void Curl_hostcache_destroy(struct Curl_easy *data);
*/
CURLcode Curl_loadhostpairs(struct Curl_easy *data);
+CURLcode Curl_resolv_check(struct connectdata *conn,
+ struct Curl_dns_entry **dns);
+int Curl_resolv_getsock(struct connectdata *conn,
+ curl_socket_t *socks,
+ int numsocks);
+
#endif /* HEADER_CURL_HOSTIP_H */
diff --git a/Utilities/cmcurl/lib/hostip4.c b/Utilities/cmcurl/lib/hostip4.c
index e459328ac..e6ba710d8 100644
--- a/Utilities/cmcurl/lib/hostip4.c
+++ b/Utilities/cmcurl/lib/hostip4.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -22,6 +22,11 @@
#include "curl_setup.h"
+/***********************************************************************
+ * Only for plain IPv4 builds
+ **********************************************************************/
+#ifdef CURLRES_IPV4 /* plain IPv4 code coming up */
+
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -53,10 +58,6 @@
#include "curl_memory.h"
#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.
@@ -144,7 +145,7 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_STREAM;
if(port) {
- snprintf(sbuf, sizeof(sbuf), "%d", port);
+ msnprintf(sbuf, sizeof(sbuf), "%d", port);
sbufptr = sbuf;
}
@@ -249,7 +250,7 @@ Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
*/
if(CURL_HOSTENT_SIZE >=
- (sizeof(struct hostent)+sizeof(struct hostent_data))) {
+ (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
diff --git a/Utilities/cmcurl/lib/hostip6.c b/Utilities/cmcurl/lib/hostip6.c
index 4ebfc2dcf..5511f1aab 100644
--- a/Utilities/cmcurl/lib/hostip6.c
+++ b/Utilities/cmcurl/lib/hostip6.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,6 +22,11 @@
#include "curl_setup.h"
+/***********************************************************************
+ * Only for IPv6-enabled builds
+ **********************************************************************/
+#ifdef CURLRES_IPV6
+
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -54,44 +59,6 @@
#include "curl_memory.h"
#include "memdebug.h"
-/***********************************************************************
- * Only for IPv6-enabled builds
- **********************************************************************/
-#ifdef CURLRES_IPV6
-
-#if defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO)
-/* 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 want to include in memdebug.c
- */
-
-/*
- * For CURLRES_ARS, this should be written using ares_gethostbyaddr()
- * (ignoring the fact c-ares doesn't return 'serv').
- */
-
-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 */
- curl_memlog("GETNAME %s:%d getnameinfo()\n",
- source, line);
- else
- curl_memlog("GETNAME %s:%d getnameinfo() failed = %d\n",
- source, line, res);
- return res;
-}
-#endif /* defined(CURLDEBUG) && defined(HAVE_GETNAMEINFO) */
-
/*
* Curl_ipv6works() returns TRUE if IPv6 seems to work.
*/
@@ -134,14 +101,16 @@ static void dump_addrinfo(struct connectdata *conn, const Curl_addrinfo *ai)
{
printf("dump_addrinfo:\n");
for(; ai; ai = ai->ai_next) {
- char buf[INET6_ADDRSTRLEN];
-
+ 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, SOCKERRNO));
+ else {
+ char buffer[STRERROR_LEN];
+ printf("failed; %s\n",
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
+ }
}
}
#else
@@ -211,8 +180,8 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
#endif
if(port) {
- snprintf(sbuf, sizeof(sbuf), "%d", port);
- sbufptr=sbuf;
+ msnprintf(sbuf, sizeof(sbuf), "%d", port);
+ sbufptr = sbuf;
}
error = Curl_getaddrinfo_ex(hostname, sbufptr, &hints, &res);
diff --git a/Utilities/cmcurl/lib/hostsyn.c b/Utilities/cmcurl/lib/hostsyn.c
index 1a95263c6..3de6746f5 100644
--- a/Utilities/cmcurl/lib/hostsyn.c
+++ b/Utilities/cmcurl/lib/hostsyn.c
@@ -22,6 +22,11 @@
#include "curl_setup.h"
+/***********************************************************************
+ * Only for builds using synchronous name resolves
+ **********************************************************************/
+#ifdef CURLRES_SYNCH
+
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -51,11 +56,6 @@
/* The last #include file should be: */
#include "memdebug.h"
-/***********************************************************************
- * Only for builds using synchronous name resolves
- **********************************************************************/
-#ifdef CURLRES_SYNCH
-
/*
* Function provided by the resolver backend to set DNS servers to use.
*/
diff --git a/Utilities/cmcurl/lib/http.c b/Utilities/cmcurl/lib/http.c
index 21574e21d..338c59a22 100644
--- a/Utilities/cmcurl/lib/http.c
+++ b/Utilities/cmcurl/lib/http.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -50,6 +50,7 @@
#include "transfer.h"
#include "sendf.h"
#include "formdata.h"
+#include "mime.h"
#include "progress.h"
#include "curl_base64.h"
#include "cookie.h"
@@ -72,11 +73,10 @@
#include "http_proxy.h"
#include "warnless.h"
#include "non-ascii.h"
-#include "conncache.h"
-#include "pipeline.h"
#include "http2.h"
#include "connect.h"
#include "strdup.h"
+#include "altsvc.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -92,6 +92,10 @@ static int http_getsock_do(struct connectdata *conn,
int numsocks);
static int http_should_fail(struct connectdata *conn);
+#ifndef CURL_DISABLE_PROXY
+static CURLcode add_haproxy_protocol_header(struct connectdata *conn);
+#endif
+
#ifdef USE_SSL
static CURLcode https_connecting(struct connectdata *conn, bool *done);
static int https_getsock(struct connectdata *conn,
@@ -100,13 +104,14 @@ static int https_getsock(struct connectdata *conn,
#else
#define https_connecting(x,y) CURLE_COULDNT_CONNECT
#endif
+static CURLcode http_setup_conn(struct connectdata *conn);
/*
* HTTP handler interface.
*/
const struct Curl_handler Curl_handler_http = {
"HTTP", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
+ http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
@@ -119,6 +124,7 @@ const struct Curl_handler Curl_handler_http = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_HTTP, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_CREDSPERREQUEST /* flags */
@@ -130,7 +136,7 @@ const struct Curl_handler Curl_handler_http = {
*/
const struct Curl_handler Curl_handler_https = {
"HTTPS", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
+ http_setup_conn, /* setup_connection */
Curl_http, /* do_it */
Curl_http_done, /* done */
ZERO_NULL, /* do_more */
@@ -143,60 +149,44 @@ const struct Curl_handler Curl_handler_https = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_HTTPS, /* defport */
CURLPROTO_HTTPS, /* protocol */
PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | PROTOPT_ALPN_NPN /* flags */
};
#endif
-CURLcode Curl_http_setup_conn(struct connectdata *conn)
+static CURLcode http_setup_conn(struct connectdata *conn)
{
/* allocate the HTTP-specific struct for the Curl_easy, only to survive
during this request */
struct HTTP *http;
- DEBUGASSERT(conn->data->req.protop == NULL);
+ struct Curl_easy *data = conn->data;
+ DEBUGASSERT(data->req.protop == NULL);
http = calloc(1, sizeof(struct HTTP));
if(!http)
return CURLE_OUT_OF_MEMORY;
- conn->data->req.protop = http;
-
- Curl_http2_setup_conn(conn);
- Curl_http2_setup_req(conn->data);
+ Curl_mime_initpart(&http->form, conn->data);
+ data->req.protop = http;
+ if(!CONN_INUSE(conn))
+ /* if not already multi-using, setup connection details */
+ Curl_http2_setup_conn(conn);
+ Curl_http2_setup_req(data);
return CURLE_OK;
}
-/*
- * 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.
- */
-char *Curl_checkheaders(const struct connectdata *conn,
- const char *thisheader)
-{
- struct curl_slist *head;
- size_t thislen = strlen(thisheader);
- struct Curl_easy *data = conn->data;
-
- for(head = data->set.headers;head; head=head->next) {
- if(strncasecompare(head->data, thisheader, thislen))
- return head->data;
- }
-
- return NULL;
-}
-
+#ifndef CURL_DISABLE_PROXY
/*
* checkProxyHeaders() checks the linked list of custom proxy headers
* if proxy headers are not available, then it will lookup into http header
* link list
*
- * It takes a connectdata struct as input instead of the Curl_easy simply
- * to know if this is a proxy request or not, as it then might check a
- * different header list.
+ * It takes a connectdata struct as input instead of the Curl_easy simply to
+ * know if this is a proxy request or not, as it then might check a different
+ * header list. Provide the header prefix without colon!.
*/
char *Curl_checkProxyheaders(const struct connectdata *conn,
const char *thisheader)
@@ -207,13 +197,18 @@ char *Curl_checkProxyheaders(const struct connectdata *conn,
for(head = (conn->bits.proxy && data->set.sep_headers) ?
data->set.proxyheaders : data->set.headers;
- head; head=head->next) {
- if(strncasecompare(head->data, thisheader, thislen))
+ head; head = head->next) {
+ if(strncasecompare(head->data, thisheader, thislen) &&
+ Curl_headersep(head->data[thislen]))
return head->data;
}
return NULL;
}
+#else
+/* disabled */
+#define Curl_checkProxyheaders(x,y) NULL
+#endif
/*
* Strip off leading and trailing whitespace from the value in the
@@ -228,8 +223,6 @@ char *Curl_copy_header_value(const char *header)
char *value;
size_t len;
- DEBUGASSERT(header);
-
/* Find the end of the header name */
while(*header && (*header != ':'))
++header;
@@ -270,6 +263,7 @@ char *Curl_copy_header_value(const char *header)
return value;
}
+#ifndef CURL_DISABLE_HTTP_AUTH
/*
* http_output_basic() sets up an Authorization: header (or the proxy version)
* for HTTP Basic authentication.
@@ -326,22 +320,51 @@ static CURLcode http_output_basic(struct connectdata *conn, bool proxy)
return result;
}
+/*
+ * http_output_bearer() sets up an Authorization: header
+ * for HTTP Bearer authentication.
+ *
+ * Returns CURLcode.
+ */
+static CURLcode http_output_bearer(struct connectdata *conn)
+{
+ char **userp;
+ CURLcode result = CURLE_OK;
+
+ userp = &conn->allocptr.userpwd;
+ free(*userp);
+ *userp = aprintf("Authorization: Bearer %s\r\n",
+ conn->oauth_bearer);
+
+ if(!*userp) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto fail;
+ }
+
+ fail:
+ return result;
+}
+
+#endif
+
/* 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)
+static bool pickoneauth(struct auth *pick, unsigned long mask)
{
bool picked;
/* only deal with authentication we want */
- unsigned long avail = pick->avail & pick->want;
+ unsigned long avail = pick->avail & pick->want & mask;
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_NEGOTIATE)
pick->picked = CURLAUTH_NEGOTIATE;
+ else if(avail & CURLAUTH_BEARER)
+ pick->picked = CURLAUTH_BEARER;
else if(avail & CURLAUTH_DIGEST)
pick->picked = CURLAUTH_DIGEST;
else if(avail & CURLAUTH_NTLM)
@@ -402,7 +425,7 @@ static CURLcode http_perhapsrewind(struct connectdata *conn)
break;
}
- bytessent = http->writebytecount;
+ bytessent = data->req.writebytecount;
if(conn->bits.authneg) {
/* This is a state where we are known to be negotiating and we don't send
@@ -425,6 +448,7 @@ static CURLcode http_perhapsrewind(struct connectdata *conn)
expectsend = data->state.infilesize;
break;
case HTTPREQ_POST_FORM:
+ case HTTPREQ_POST_MIME:
expectsend = http->postsize;
break;
default:
@@ -442,13 +466,13 @@ static CURLcode http_perhapsrewind(struct connectdata *conn)
(data->state.authproxy.picked == CURLAUTH_NTLM_WB) ||
(data->state.authhost.picked == CURLAUTH_NTLM_WB)) {
if(((expectsend - bytessent) < 2000) ||
- (conn->ntlm.state != NTLMSTATE_NONE) ||
- (conn->proxyntlm.state != NTLMSTATE_NONE)) {
+ (conn->http_ntlm_state != NTLMSTATE_NONE) ||
+ (conn->proxy_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) {
+ if(!conn->bits.authneg && (conn->writesockfd != CURL_SOCKET_BAD)) {
conn->bits.rewindaftersend = TRUE;
infof(data, "Rewind stream after send\n");
}
@@ -465,8 +489,36 @@ static CURLcode http_perhapsrewind(struct connectdata *conn)
(curl_off_t)(expectsend - bytessent));
}
#endif
+#if defined(USE_SPNEGO)
+ /* There is still data left to send */
+ if((data->state.authproxy.picked == CURLAUTH_NEGOTIATE) ||
+ (data->state.authhost.picked == CURLAUTH_NEGOTIATE)) {
+ if(((expectsend - bytessent) < 2000) ||
+ (conn->http_negotiate_state != GSS_AUTHNONE) ||
+ (conn->proxy_negotiate_state != GSS_AUTHNONE)) {
+ /* The NEGOTIATE-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->writesockfd != CURL_SOCKET_BAD)) {
+ conn->bits.rewindaftersend = TRUE;
+ infof(data, "Rewind stream after send\n");
+ }
- /* This is not NTLM or many bytes left to send: close */
+ return CURLE_OK;
+ }
+
+ if(conn->bits.close)
+ /* this is already marked to get closed */
+ return CURLE_OK;
+
+ infof(data, "NEGOTIATE send, close instead of sending %"
+ CURL_FORMAT_CURL_OFF_T " bytes\n",
+ (curl_off_t)(expectsend - bytessent));
+ }
+#endif
+
+ /* This is not NEGOTIATE/NTLM or many bytes left to send: close */
streamclose(conn, "Mid-auth HTTP and much data left to send");
data->req.size = 0; /* don't download any more than 0 bytes */
@@ -494,6 +546,10 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
bool pickhost = FALSE;
bool pickproxy = FALSE;
CURLcode result = CURLE_OK;
+ unsigned long authmask = ~0ul;
+
+ if(!conn->oauth_bearer)
+ authmask &= (unsigned long)~CURLAUTH_BEARER;
if(100 <= data->req.httpcode && 199 >= data->req.httpcode)
/* this is a transient response code, ignore */
@@ -502,30 +558,29 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
if(data->state.authproblem)
return data->set.http_fail_on_error?CURLE_HTTP_RETURNED_ERROR:CURLE_OK;
- if(conn->bits.user_passwd &&
+ if((conn->bits.user_passwd || conn->oauth_bearer) &&
((data->req.httpcode == 401) ||
(conn->bits.authneg && data->req.httpcode < 300))) {
- pickhost = pickoneauth(&data->state.authhost);
+ pickhost = pickoneauth(&data->state.authhost, authmask);
if(!pickhost)
data->state.authproblem = TRUE;
+ if(data->state.authhost.picked == CURLAUTH_NTLM &&
+ conn->httpversion > 11) {
+ infof(data, "Forcing HTTP/1.1 for NTLM");
+ connclose(conn, "Force HTTP/1.1 connection");
+ conn->data->set.httpversion = CURL_HTTP_VERSION_1_1;
+ }
}
if(conn->bits.proxy_user_passwd &&
((data->req.httpcode == 407) ||
(conn->bits.authneg && data->req.httpcode < 300))) {
- pickproxy = pickoneauth(&data->state.authproxy);
+ pickproxy = pickoneauth(&data->state.authproxy,
+ authmask & ~CURLAUTH_BEARER);
if(!pickproxy)
data->state.authproblem = TRUE;
}
if(pickhost || pickproxy) {
- /* In case this is GSS auth, the newurl field is already allocated so
- we must make sure to free it before allocating a new one. As figured
- out in bug #2284386 */
- Curl_safefree(data->req.newurl);
- data->req.newurl = strdup(data->change.url); /* clone URL */
- if(!data->req.newurl)
- return CURLE_OUT_OF_MEMORY;
-
if((data->set.httpreq != HTTPREQ_GET) &&
(data->set.httpreq != HTTPREQ_HEAD) &&
!conn->bits.rewindaftersend) {
@@ -533,6 +588,13 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
if(result)
return result;
}
+ /* In case this is GSS auth, the newurl field is already allocated so
+ we must make sure to free it before allocating a new one. As figured
+ out in bug #2284386 */
+ Curl_safefree(data->req.newurl);
+ data->req.newurl = strdup(data->change.url); /* clone URL */
+ if(!data->req.newurl)
+ return CURLE_OUT_OF_MEMORY;
}
else if((data->req.httpcode < 300) &&
(!data->state.authhost.done) &&
@@ -558,6 +620,7 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
return result;
}
+#ifndef CURL_DISABLE_HTTP_AUTH
/*
* Output the correct authentication header depending on the auth type
* and whether or not it is to a proxy.
@@ -574,10 +637,6 @@ output_auth_headers(struct connectdata *conn,
#if !defined(CURL_DISABLE_VERBOSE_STRINGS) || defined(USE_SPNEGO)
struct Curl_easy *data = conn->data;
#endif
-#ifdef USE_SPNEGO
- struct negotiatedata *negdata = proxy ?
- &data->state.proxyneg : &data->state.negotiate;
-#endif
#ifdef CURL_DISABLE_CRYPTO_AUTH
(void)request;
@@ -585,15 +644,11 @@ output_auth_headers(struct connectdata *conn,
#endif
#ifdef USE_SPNEGO
- negdata->state = GSS_AUTHNONE;
- if((authstatus->picked == CURLAUTH_NEGOTIATE) &&
- negdata->context && !GSS_ERROR(negdata->status)) {
+ if((authstatus->picked == CURLAUTH_NEGOTIATE)) {
auth = "Negotiate";
result = Curl_output_negotiate(conn, proxy);
if(result)
return result;
- authstatus->done = TRUE;
- negdata->state = GSS_AUTHSENT;
}
else
#endif
@@ -608,7 +663,7 @@ output_auth_headers(struct connectdata *conn,
#endif
#if defined(USE_NTLM) && defined(NTLM_WB_ENABLED)
if(authstatus->picked == CURLAUTH_NTLM_WB) {
- auth="NTLM_WB";
+ auth = "NTLM_WB";
result = Curl_output_ntlm_wb(conn, proxy);
if(result)
return result;
@@ -630,9 +685,9 @@ output_auth_headers(struct connectdata *conn,
if(authstatus->picked == CURLAUTH_BASIC) {
/* Basic */
if((proxy && conn->bits.proxy_user_passwd &&
- !Curl_checkProxyheaders(conn, "Proxy-authorization:")) ||
+ !Curl_checkProxyheaders(conn, "Proxy-authorization")) ||
(!proxy && conn->bits.user_passwd &&
- !Curl_checkheaders(conn, "Authorization:"))) {
+ !Curl_checkheaders(conn, "Authorization"))) {
auth = "Basic";
result = http_output_basic(conn, proxy);
if(result)
@@ -643,6 +698,20 @@ output_auth_headers(struct connectdata *conn,
functions work that way */
authstatus->done = TRUE;
}
+ if(authstatus->picked == CURLAUTH_BEARER) {
+ /* Bearer */
+ if((!proxy && conn->oauth_bearer &&
+ !Curl_checkheaders(conn, "Authorization:"))) {
+ auth = "Bearer";
+ result = http_output_bearer(conn);
+ if(result)
+ return result;
+ }
+
+ /* NOTE: this function should set 'done' TRUE, as the other auth
+ functions work that way */
+ authstatus->done = TRUE;
+ }
if(auth) {
infof(data, "%s auth using %s with user '%s'\n",
@@ -665,7 +734,7 @@ output_auth_headers(struct connectdata *conn,
*
* @param conn all information about the current connection
* @param request pointer to the request keyword
- * @param path pointer to the requested path
+ * @param path pointer to the requested path; should include query part
* @param proxytunnel boolean if this is the request setting up a "proxy
* tunnel"
*
@@ -689,7 +758,7 @@ Curl_http_output_auth(struct connectdata *conn,
authproxy = &data->state.authproxy;
if((conn->bits.httpproxy && conn->bits.proxy_user_passwd) ||
- conn->bits.user_passwd)
+ conn->bits.user_passwd || conn->oauth_bearer)
/* continue please */;
else {
authhost->done = TRUE;
@@ -712,7 +781,7 @@ Curl_http_output_auth(struct connectdata *conn,
#ifndef CURL_DISABLE_PROXY
/* Send proxy authentication header if needed */
if(conn->bits.httpproxy &&
- (conn->bits.tunnel_proxy == proxytunnel)) {
+ (conn->bits.tunnel_proxy == (bit)proxytunnel)) {
result = output_auth_headers(conn, authproxy, request, path, TRUE);
if(result)
return result;
@@ -730,7 +799,7 @@ Curl_http_output_auth(struct connectdata *conn,
if(!data->state.this_is_a_follow ||
conn->bits.netrc ||
!data->state.first_host ||
- data->set.http_disable_hostname_check_before_authentication ||
+ data->set.allow_auth_to_other_hosts ||
strcasecompare(data->state.first_host, conn->host.name)) {
result = output_auth_headers(conn, authhost, request, path, FALSE);
}
@@ -740,6 +809,22 @@ Curl_http_output_auth(struct connectdata *conn,
return result;
}
+#else
+/* when disabled */
+CURLcode
+Curl_http_output_auth(struct connectdata *conn,
+ const char *request,
+ const char *path,
+ bool proxytunnel)
+{
+ (void)conn;
+ (void)request;
+ (void)path;
+ (void)proxytunnel;
+ return CURLE_OK;
+}
+#endif
+
/*
* 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
@@ -755,8 +840,8 @@ CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
struct Curl_easy *data = conn->data;
#ifdef USE_SPNEGO
- struct negotiatedata *negdata = proxy?
- &data->state.proxyneg:&data->state.negotiate;
+ curlnegotiate *negstate = proxy ? &conn->proxy_negotiate_state :
+ &conn->http_negotiate_state;
#endif
unsigned long *availp;
struct auth *authp;
@@ -795,21 +880,18 @@ CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
authp->avail |= CURLAUTH_NEGOTIATE;
if(authp->picked == CURLAUTH_NEGOTIATE) {
- if(negdata->state == GSS_AUTHSENT ||
- negdata->state == GSS_AUTHNONE) {
- CURLcode result = Curl_input_negotiate(conn, proxy, auth);
- if(!result) {
- DEBUGASSERT(!data->req.newurl);
- data->req.newurl = strdup(data->change.url);
- if(!data->req.newurl)
- return CURLE_OUT_OF_MEMORY;
- data->state.authproblem = FALSE;
- /* we received a GSS auth token and we dealt with it fine */
- negdata->state = GSS_AUTHRECV;
- }
- else
- data->state.authproblem = TRUE;
+ CURLcode result = Curl_input_negotiate(conn, proxy, auth);
+ if(!result) {
+ DEBUGASSERT(!data->req.newurl);
+ data->req.newurl = strdup(data->change.url);
+ if(!data->req.newurl)
+ return CURLE_OUT_OF_MEMORY;
+ data->state.authproblem = FALSE;
+ /* we received a GSS auth token and we dealt with it fine */
+ *negstate = GSS_AUTHRECV;
}
+ else
+ data->state.authproblem = TRUE;
}
}
}
@@ -837,19 +919,10 @@ CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
*availp |= CURLAUTH_NTLM_WB;
authp->avail |= CURLAUTH_NTLM_WB;
- /* Get the challenge-message which will be passed to
- * ntlm_auth for generating the type 3 message later */
- while(*auth && ISSPACE(*auth))
- auth++;
- if(checkprefix("NTLM", auth)) {
- auth += strlen("NTLM");
- while(*auth && ISSPACE(*auth))
- auth++;
- if(*auth) {
- conn->challenge_header = strdup(auth);
- if(!conn->challenge_header)
- return CURLE_OUT_OF_MEMORY;
- }
+ result = Curl_input_ntlm_wb(conn, proxy, auth);
+ if(result) {
+ infof(data, "Authentication problem. Ignoring this.\n");
+ data->state.authproblem = TRUE;
}
}
#endif
@@ -898,6 +971,18 @@ CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
data->state.authproblem = TRUE;
}
}
+ else
+ if(checkprefix("Bearer", auth)) {
+ *availp |= CURLAUTH_BEARER;
+ authp->avail |= CURLAUTH_BEARER;
+ if(authp->picked == CURLAUTH_BEARER) {
+ /* We asked for Bearer authentication but got a 40X back
+ anyway, which basically means our token isn't valid. */
+ authp->avail = CURLAUTH_NONE;
+ infof(data, "Authentication problem. Ignoring this.\n");
+ data->state.authproblem = TRUE;
+ }
+ }
/* there may be multiple methods on one line, so keep reading */
while(*auth && *auth != ',') /* read up to the next comma */
@@ -1020,7 +1105,7 @@ static size_t readmoredata(char *buffer,
http->sending++; /* move one step up */
- http->backup.postsize=0;
+ http->backup.postsize = 0;
}
else
http->postsize = 0;
@@ -1049,11 +1134,13 @@ Curl_send_buffer *Curl_add_buffer_init(void)
/*
* Curl_add_buffer_free() frees all associated resources.
*/
-void Curl_add_buffer_free(Curl_send_buffer *buff)
+void Curl_add_buffer_free(Curl_send_buffer **inp)
{
- if(buff) /* deal with NULL input */
- free(buff->buffer);
- free(buff);
+ Curl_send_buffer *in = *inp;
+ if(in) /* deal with NULL input */
+ free(in->buffer);
+ free(in);
+ *inp = NULL;
}
/*
@@ -1062,26 +1149,27 @@ void Curl_add_buffer_free(Curl_send_buffer *buff)
*
* Returns CURLcode
*/
-CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
+CURLcode Curl_add_buffer_send(Curl_send_buffer **inp,
struct connectdata *conn,
- /* add the number of sent bytes to this
- counter */
- long *bytes_written,
+ /* add the number of sent bytes to this
+ counter */
+ curl_off_t *bytes_written,
- /* how much of the buffer contains body data */
+ /* how much of the buffer contains body data */
size_t included_body_bytes,
int socketindex)
-
{
ssize_t amount;
CURLcode result;
char *ptr;
size_t size;
- struct HTTP *http = conn->data->req.protop;
+ struct Curl_easy *data = conn->data;
+ struct HTTP *http = data->req.protop;
size_t sendsize;
curl_socket_t sockfd;
size_t headersize;
+ Curl_send_buffer *in = *inp;
DEBUGASSERT(socketindex <= SECONDARYSOCKET);
@@ -1098,11 +1186,11 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
DEBUGASSERT(size > included_body_bytes);
- result = Curl_convert_to_network(conn->data, ptr, headersize);
+ result = Curl_convert_to_network(data, ptr, headersize);
/* Curl_convert_to_network calls failf if unsuccessful */
if(result) {
/* conversion failed, free memory and return to the caller */
- Curl_add_buffer_free(in);
+ Curl_add_buffer_free(inp);
return result;
}
@@ -1123,8 +1211,14 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
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;
+ result = Curl_get_upload_buffer(data);
+ if(result) {
+ /* malloc failed, free memory and return to the caller */
+ Curl_add_buffer_free(&in);
+ return result;
+ }
+ memcpy(data->state.ulbuf, ptr, sendsize);
+ ptr = data->state.ulbuf;
}
else
sendsize = size;
@@ -1141,14 +1235,14 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
size_t headlen = (size_t)amount>headersize ? headersize : (size_t)amount;
size_t bodylen = amount - headlen;
- if(conn->data->set.verbose) {
+ if(data->set.verbose) {
/* this data _may_ contain binary stuff */
- Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr, headlen, conn);
+ Curl_debug(data, CURLINFO_HEADER_OUT, ptr, headlen);
if(bodylen) {
/* there was body data sent beyond the initial header part, pass that
on to the debug callback too */
- Curl_debug(conn->data, CURLINFO_DATA_OUT,
- ptr+headlen, bodylen, conn);
+ Curl_debug(data, CURLINFO_DATA_OUT,
+ ptr + headlen, bodylen);
}
}
@@ -1160,7 +1254,8 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
if(http) {
/* if we sent a piece of the body here, up the byte counter for it
accordingly */
- http->writebytecount += bodylen;
+ data->req.writebytecount += bodylen;
+ Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
if((size_t)amount != size) {
/* The whole request could not be sent in one system call. We must
@@ -1172,14 +1267,14 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
ptr = in->buffer + amount;
/* backup the currently set pointers */
- http->backup.fread_func = conn->data->state.fread_func;
- http->backup.fread_in = conn->data->state.in;
+ http->backup.fread_func = data->state.fread_func;
+ http->backup.fread_in = data->state.in;
http->backup.postdata = http->postdata;
http->backup.postsize = http->postsize;
/* set the new pointers for the request-sending */
- conn->data->state.fread_func = (curl_read_callback)readmoredata;
- conn->data->state.in = (void *)conn;
+ data->state.fread_func = (curl_read_callback)readmoredata;
+ data->state.in = (void *)conn;
http->postdata = ptr;
http->postsize = (curl_off_t)size;
@@ -1201,10 +1296,9 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
This needs FIXing.
*/
return CURLE_SEND_ERROR;
- Curl_pipeline_leave_write(conn);
}
}
- Curl_add_buffer_free(in);
+ Curl_add_buffer_free(&in);
return result;
}
@@ -1213,32 +1307,35 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
/*
* add_bufferf() add the formatted input to the buffer.
*/
-CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...)
+CURLcode Curl_add_bufferf(Curl_send_buffer **inp, const char *fmt, ...)
{
char *s;
va_list ap;
+ Curl_send_buffer *in = *inp;
va_start(ap, fmt);
s = vaprintf(fmt, ap); /* this allocs a new string to append */
va_end(ap);
if(s) {
- CURLcode result = Curl_add_buffer(in, s, strlen(s));
+ CURLcode result = Curl_add_buffer(inp, s, strlen(s));
free(s);
return result;
}
/* If we failed, we cleanup the whole buffer and return error */
free(in->buffer);
free(in);
+ *inp = NULL;
return CURLE_OUT_OF_MEMORY;
}
/*
- * add_buffer() appends a memory chunk to the existing buffer
+ * Curl_add_buffer() appends a memory chunk to the existing buffer
*/
-CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size)
+CURLcode Curl_add_buffer(Curl_send_buffer **inp, const void *inptr,
+ size_t size)
{
char *new_rb;
- size_t new_size;
+ Curl_send_buffer *in = *inp;
if(~size < in->size_used) {
/* If resulting used size of send buffer would wrap size_t, cleanup
@@ -1246,21 +1343,22 @@ CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size)
size will fit into a single allocatable memory chunk */
Curl_safefree(in->buffer);
free(in);
+ *inp = NULL;
return CURLE_OUT_OF_MEMORY;
}
if(!in->buffer ||
((in->size_used + size) > (in->size_max - 1))) {
-
/* If current buffer size isn't enough to hold the result, use a
buffer size that doubles the required size. If this new size
would wrap size_t, then just use the largest possible one */
+ size_t new_size;
if((size > (size_t)-1 / 2) || (in->size_used > (size_t)-1 / 2) ||
(~(size * 2) < (in->size_used * 2)))
new_size = (size_t)-1;
else
- new_size = (in->size_used+size) * 2;
+ new_size = (in->size_used + size) * 2;
if(in->buffer)
/* we have a buffer, enlarge the existing one */
@@ -1272,6 +1370,7 @@ CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size)
if(!new_rb) {
/* If we failed, we cleanup the whole buffer and return error */
free(in);
+ *inp = NULL;
return CURLE_OUT_OF_MEMORY;
}
@@ -1337,7 +1436,7 @@ Curl_compareheader(const char *headerline, /* line to check */
clen = strlen(content); /* length of the word to find */
/* find the content string in the rest of the line */
- for(;len>=clen;len--, start++) {
+ for(; len >= clen; len--, start++) {
if(strncasecompare(start, content, clen))
return TRUE; /* match! */
}
@@ -1369,10 +1468,19 @@ CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
if(CONNECT_FIRSTSOCKET_PROXY_SSL())
return CURLE_OK; /* wait for HTTPS proxy SSL initialization to complete */
- if(conn->tunnel_state[FIRSTSOCKET] == TUNNEL_CONNECT)
+ if(Curl_connect_ongoing(conn))
/* nothing else to do except wait right now - we're not done here. */
return CURLE_OK;
+#ifndef CURL_DISABLE_PROXY
+ if(conn->data->set.haproxyprotocol) {
+ /* add HAProxy PROXY protocol header */
+ result = add_haproxy_protocol_header(conn);
+ if(result)
+ return result;
+ }
+#endif
+
if(conn->given->protocol & CURLPROTO_HTTPS) {
/* perform SSL initialization */
result = https_connecting(conn, done);
@@ -1398,6 +1506,49 @@ static int http_getsock_do(struct connectdata *conn,
return GETSOCK_WRITESOCK(0);
}
+#ifndef CURL_DISABLE_PROXY
+static CURLcode add_haproxy_protocol_header(struct connectdata *conn)
+{
+ char proxy_header[128];
+ Curl_send_buffer *req_buffer;
+ CURLcode result;
+ char tcp_version[5];
+
+ /* Emit the correct prefix for IPv6 */
+ if(conn->bits.ipv6) {
+ strcpy(tcp_version, "TCP6");
+ }
+ else {
+ strcpy(tcp_version, "TCP4");
+ }
+
+ msnprintf(proxy_header,
+ sizeof(proxy_header),
+ "PROXY %s %s %s %li %li\r\n",
+ tcp_version,
+ conn->data->info.conn_local_ip,
+ conn->data->info.conn_primary_ip,
+ conn->data->info.conn_local_port,
+ conn->data->info.conn_primary_port);
+
+ req_buffer = Curl_add_buffer_init();
+ if(!req_buffer)
+ return CURLE_OUT_OF_MEMORY;
+
+ result = Curl_add_bufferf(&req_buffer, proxy_header);
+ if(result)
+ return result;
+
+ result = Curl_add_buffer_send(&req_buffer,
+ conn,
+ &conn->data->info.request_size,
+ 0,
+ FIRSTSOCKET);
+
+ return result;
+}
+#endif
+
#ifdef USE_SSL
static CURLcode https_connecting(struct connectdata *conn, bool *done)
{
@@ -1440,20 +1591,6 @@ CURLcode Curl_http_done(struct connectdata *conn,
Curl_unencode_cleanup(conn);
-#ifdef USE_SPNEGO
- if(data->state.proxyneg.state == GSS_AUTHSENT ||
- data->state.negotiate.state == GSS_AUTHSENT) {
- /* add forbid re-use if http-code != 401/407 as a WA only needed for
- * 401/407 that signal auth failure (empty) otherwise state will be RECV
- * with current code.
- * Do not close CONNECT_ONLY connections. */
- if((data->req.httpcode != 401) && (data->req.httpcode != 407) &&
- !data->set.connect_only)
- streamclose(conn, "Negotiate transfer completed");
- Curl_cleanup_negotiate(data);
- }
-#endif
-
/* set the proper values (possibly modified on POST) */
conn->seek_func = data->set.seek_func; /* restore */
conn->seek_client = data->set.seek_client; /* restore */
@@ -1462,24 +1599,12 @@ CURLcode Curl_http_done(struct connectdata *conn,
return CURLE_OK;
if(http->send_buffer) {
- Curl_add_buffer_free(http->send_buffer);
- http->send_buffer = NULL; /* clear the pointer */
+ Curl_add_buffer_free(&http->send_buffer);
}
Curl_http2_done(conn, premature);
- if(HTTPREQ_POST_FORM == data->set.httpreq) {
- data->req.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)
- data->req.bytecount = http->readbytecount + http->writebytecount;
+ Curl_mime_cleanpart(&http->form);
if(status)
return status;
@@ -1488,7 +1613,7 @@ CURLcode Curl_http_done(struct connectdata *conn,
entire operation is complete */
!conn->bits.retry &&
!data->set.connect_only &&
- (http->readbytecount +
+ (data->req.bytecount +
data->req.headerbytecount -
data->req.deductheadercount) <= 0) {
/* If this connection isn't simply closed to be retried, AND nothing was
@@ -1542,7 +1667,6 @@ static CURLcode expect100(struct Curl_easy *data,
Curl_send_buffer *req_buffer)
{
CURLcode result = CURLE_OK;
- const char *ptr;
data->state.expect100header = FALSE; /* default to false unless it is set
to TRUE below */
if(use_http_1_1plus(data, conn) &&
@@ -1550,14 +1674,14 @@ static CURLcode expect100(struct Curl_easy *data,
/* if not doing HTTP 1.0 or version 2, or disabled explicitly, we add an
Expect: 100-continue to the headers which actually speeds up post
operations (as there is one packet coming back from the web server) */
- ptr = Curl_checkheaders(conn, "Expect:");
+ const char *ptr = Curl_checkheaders(conn, "Expect");
if(ptr) {
data->state.expect100header =
Curl_compareheader(ptr, "Expect:", "100-continue");
}
else {
- result = Curl_add_bufferf(req_buffer,
- "Expect: 100-continue\r\n");
+ result = Curl_add_bufferf(&req_buffer,
+ "Expect: 100-continue\r\n");
if(!result)
data->state.expect100header = TRUE;
}
@@ -1572,6 +1696,50 @@ enum proxy_use {
HEADER_CONNECT /* sending CONNECT to a proxy */
};
+/* used to compile the provided trailers into one buffer
+ will return an error code if one of the headers is
+ not formatted correctly */
+CURLcode Curl_http_compile_trailers(struct curl_slist *trailers,
+ Curl_send_buffer *buffer,
+ struct Curl_easy *handle)
+{
+ char *ptr = NULL;
+ CURLcode result = CURLE_OK;
+ const char *endofline_native = NULL;
+ const char *endofline_network = NULL;
+
+ if(
+#ifdef CURL_DO_LINEEND_CONV
+ (handle->set.prefer_ascii) ||
+#endif
+ (handle->set.crlf)) {
+ /* \n will become \r\n later on */
+ endofline_native = "\n";
+ endofline_network = "\x0a";
+ }
+ else {
+ endofline_native = "\r\n";
+ endofline_network = "\x0d\x0a";
+ }
+
+ while(trailers) {
+ /* only add correctly formatted trailers */
+ ptr = strchr(trailers->data, ':');
+ if(ptr && *(ptr + 1) == ' ') {
+ result = Curl_add_bufferf(&buffer, "%s%s", trailers->data,
+ endofline_native);
+ if(result)
+ return result;
+ }
+ else
+ infof(handle, "Malformatted trailing header ! Skipping trailer.");
+ trailers = trailers->next;
+ }
+ result = Curl_add_buffer(&buffer, endofline_network,
+ strlen(endofline_network));
+ return result;
+}
+
CURLcode Curl_add_custom_headers(struct connectdata *conn,
bool is_connect,
Curl_send_buffer *req_buffer)
@@ -1579,7 +1747,7 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
char *ptr;
struct curl_slist *h[2];
struct curl_slist *headers;
- int numlists=1; /* by default */
+ int numlists = 1; /* by default */
struct Curl_easy *data = conn->data;
int i;
@@ -1611,11 +1779,43 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
}
/* loop through one or two lists */
- for(i=0; i < numlists; i++) {
+ for(i = 0; i < numlists; i++) {
headers = h[i];
while(headers) {
+ char *semicolonp = NULL;
ptr = strchr(headers->data, ':');
+ if(!ptr) {
+ char *optr;
+ /* no colon, semicolon? */
+ ptr = strchr(headers->data, ';');
+ if(ptr) {
+ optr = ptr;
+ ptr++; /* pass the semicolon */
+ while(*ptr && ISSPACE(*ptr))
+ ptr++;
+
+ if(*ptr) {
+ /* this may be used for something else in the future */
+ optr = NULL;
+ }
+ else {
+ if(*(--ptr) == ';') {
+ /* copy the source */
+ semicolonp = strdup(headers->data);
+ if(!semicolonp) {
+ Curl_add_buffer_free(&req_buffer);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ /* put a colon where the semicolon is */
+ semicolonp[ptr - headers->data] = ':';
+ /* point at the colon */
+ optr = &semicolonp [ptr - headers->data];
+ }
+ }
+ ptr = optr;
+ }
+ }
if(ptr) {
/* we require a colon for this to be a true header */
@@ -1623,63 +1823,54 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
while(*ptr && ISSPACE(*ptr))
ptr++;
- if(*ptr) {
- /* only send this if the contents was non-blank */
+ if(*ptr || semicolonp) {
+ /* only send this if the contents was non-blank or done special */
+ CURLcode result = CURLE_OK;
+ char *compare = semicolonp ? semicolonp : headers->data;
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! */
- checkprefix("Host:", headers->data))
+ checkprefix("Host:", compare))
;
else if(data->set.httpreq == HTTPREQ_POST_FORM &&
/* this header (extended by formdata.c) is sent later */
- checkprefix("Content-Type:", headers->data))
+ checkprefix("Content-Type:", compare))
+ ;
+ else if(data->set.httpreq == HTTPREQ_POST_MIME &&
+ /* this header is sent later */
+ checkprefix("Content-Type:", compare))
;
else if(conn->bits.authneg &&
/* while doing auth neg, don't allow the custom length since
we will force length zero then */
- checkprefix("Content-Length", headers->data))
+ checkprefix("Content-Length:", compare))
;
else if(conn->allocptr.te &&
/* when asking for Transfer-Encoding, don't pass on a custom
Connection: */
- checkprefix("Connection", headers->data))
+ checkprefix("Connection:", compare))
;
else if((conn->httpversion == 20) &&
- checkprefix("Transfer-Encoding:", headers->data))
+ checkprefix("Transfer-Encoding:", compare))
/* HTTP/2 doesn't support chunked requests */
;
+ else if((checkprefix("Authorization:", compare) ||
+ checkprefix("Cookie:", compare)) &&
+ /* be careful of sending this potentially sensitive header to
+ other hosts */
+ (data->state.this_is_a_follow &&
+ data->state.first_host &&
+ !data->set.allow_auth_to_other_hosts &&
+ !strcasecompare(data->state.first_host, conn->host.name)))
+ ;
else {
- CURLcode result = Curl_add_bufferf(req_buffer, "%s\r\n",
- headers->data);
- if(result)
- return result;
- }
- }
- }
- else {
- ptr = strchr(headers->data, ';');
- if(ptr) {
-
- ptr++; /* pass the semicolon */
- while(*ptr && ISSPACE(*ptr))
- ptr++;
-
- if(*ptr) {
- /* this may be used for something else in the future */
- }
- else {
- if(*(--ptr) == ';') {
- CURLcode result;
-
- /* send no-value custom header if terminated by semicolon */
- *ptr = ':';
- result = Curl_add_bufferf(req_buffer, "%s\r\n",
- headers->data);
- if(result)
- return result;
- }
+ result = Curl_add_bufferf(&req_buffer, "%s\r\n", compare);
}
+ if(semicolonp)
+ free(semicolonp);
+ if(result)
+ return result;
}
}
headers = headers->next;
@@ -1689,6 +1880,7 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
return CURLE_OK;
}
+#ifndef CURL_DISABLE_PARSEDATE
CURLcode Curl_add_timecondition(struct Curl_easy *data,
Curl_send_buffer *req_buffer)
{
@@ -1732,21 +1924,31 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
*/
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
- snprintf(datestr, sizeof(datestr),
- "%s: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
- condp,
- 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_add_buffer(req_buffer, datestr, strlen(datestr));
+ msnprintf(datestr, sizeof(datestr),
+ "%s: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
+ condp,
+ 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_add_buffer(&req_buffer, datestr, strlen(datestr));
return result;
}
+#else
+/* disabled */
+CURLcode Curl_add_timecondition(struct Curl_easy *data,
+ Curl_send_buffer *req_buffer)
+{
+ (void)data;
+ (void)req_buffer;
+ return CURLE_OK;
+}
+#endif
/*
* Curl_http() gets called from the generic multi_do() function when a HTTP
@@ -1758,7 +1960,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
struct Curl_easy *data = conn->data;
CURLcode result = CURLE_OK;
struct HTTP *http;
- const char *ppath = data->state.path;
+ const char *path = data->state.up.path;
+ const char *query = data->state.up.query;
bool paste_ftp_userpwd = FALSE;
char ftp_typecode[sizeof("/;type=?")] = "";
const char *host = conn->host.name;
@@ -1773,7 +1976,6 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
const char *httpstring;
Curl_send_buffer *req_buffer;
curl_off_t postsize = 0; /* curl_off_t to handle large file sizes */
- int seekerr = CURL_SEEKFUNC_OK;
/* 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
@@ -1798,6 +2000,13 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
#ifdef USE_NGHTTP2
if(conn->data->set.httpversion ==
CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE) {
+ if(conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
+ /* We don't support HTTP/2 proxies yet. Also it's debatable whether
+ or not this setting should apply to HTTP/2 proxies. */
+ infof(data, "Ignoring HTTP/2 prior knowledge due to proxy\n");
+ break;
+ }
+
DEBUGF(infof(data, "HTTP/2 over clean TCP\n"));
conn->httpversion = 20;
@@ -1817,6 +2026,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
http = data->req.protop;
+ DEBUGASSERT(http);
if(!data->state.this_is_a_follow) {
/* Free to avoid leaking memory on multiple requests*/
@@ -1828,7 +2038,6 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
data->state.first_remote_port = conn->remote_port;
}
- http->writebytecount = http->readbytecount = 0;
if((conn->handler->protocol&(PROTO_FAMILY_HTTP|CURLPROTO_FTP)) &&
data->set.upload) {
@@ -1846,11 +2055,15 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
switch(httpreq) {
case HTTPREQ_POST:
case HTTPREQ_POST_FORM:
+ case HTTPREQ_POST_MIME:
request = "POST";
break;
case HTTPREQ_PUT:
request = "PUT";
break;
+ case HTTPREQ_OPTIONS:
+ request = "OPTIONS";
+ break;
default: /* this should never happen */
case HTTPREQ_GET:
request = "GET";
@@ -1866,17 +2079,27 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
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(Curl_checkheaders(conn, "User-Agent:")) {
+ if(Curl_checkheaders(conn, "User-Agent")) {
free(conn->allocptr.uagent);
- conn->allocptr.uagent=NULL;
+ conn->allocptr.uagent = NULL;
}
/* setup the authentication headers */
- result = Curl_http_output_auth(conn, request, ppath, FALSE);
- if(result)
- return result;
+ {
+ char *pq = NULL;
+ if(query && *query) {
+ pq = aprintf("%s?%s", path, query);
+ if(!pq)
+ return CURLE_OUT_OF_MEMORY;
+ }
+ result = Curl_http_output_auth(conn, request, (pq ? pq : path), FALSE);
+ free(pq);
+ if(result)
+ return result;
+ }
- if((data->state.authhost.multipass || data->state.authproxy.multipass) &&
+ if(((data->state.authhost.multipass && !data->state.authhost.done)
+ || (data->state.authproxy.multipass && !data->state.authproxy.done)) &&
(httpreq != HTTPREQ_GET) &&
(httpreq != HTTPREQ_HEAD)) {
/* Auth is required and we are not authenticated yet. Make a PUT or POST
@@ -1887,7 +2110,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
conn->bits.authneg = FALSE;
Curl_safefree(conn->allocptr.ref);
- if(data->change.referer && !Curl_checkheaders(conn, "Referer:")) {
+ if(data->change.referer && !Curl_checkheaders(conn, "Referer")) {
conn->allocptr.ref = aprintf("Referer: %s\r\n", data->change.referer);
if(!conn->allocptr.ref)
return CURLE_OUT_OF_MEMORY;
@@ -1896,11 +2119,11 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
conn->allocptr.ref = NULL;
#if !defined(CURL_DISABLE_COOKIES)
- if(data->set.str[STRING_COOKIE] && !Curl_checkheaders(conn, "Cookie:"))
+ if(data->set.str[STRING_COOKIE] && !Curl_checkheaders(conn, "Cookie"))
addcookies = data->set.str[STRING_COOKIE];
#endif
- if(!Curl_checkheaders(conn, "Accept-Encoding:") &&
+ if(!Curl_checkheaders(conn, "Accept-Encoding") &&
data->set.str[STRING_ENCODING]) {
Curl_safefree(conn->allocptr.accept_encoding);
conn->allocptr.accept_encoding =
@@ -1916,37 +2139,89 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
#ifdef HAVE_LIBZ
/* we only consider transfer-encoding magic if libz support is built-in */
- if(!Curl_checkheaders(conn, "TE:") &&
+ if(!Curl_checkheaders(conn, "TE") &&
data->set.http_transfer_encoding) {
/* When we are to insert a TE: header in the request, we must also insert
TE in a Connection: header, so we need to merge the custom provided
Connection: header and prevent the original to get sent. Note that if
the user has inserted his/hers own TE: header we don't do this magic
but then assume that the user will handle it all! */
- char *cptr = Curl_checkheaders(conn, "Connection:");
+ char *cptr = Curl_checkheaders(conn, "Connection");
#define TE_HEADER "TE: gzip\r\n"
Curl_safefree(conn->allocptr.te);
+ if(cptr) {
+ cptr = Curl_copy_header_value(cptr);
+ if(!cptr)
+ return CURLE_OUT_OF_MEMORY;
+ }
+
/* Create the (updated) Connection: header */
- conn->allocptr.te = cptr? aprintf("%s, TE\r\n" TE_HEADER, cptr):
- strdup("Connection: TE\r\n" TE_HEADER);
+ conn->allocptr.te = aprintf("Connection: %s%sTE\r\n" TE_HEADER,
+ cptr ? cptr : "", (cptr && *cptr) ? ", ":"");
+ free(cptr);
if(!conn->allocptr.te)
return CURLE_OUT_OF_MEMORY;
}
#endif
- ptr = Curl_checkheaders(conn, "Transfer-Encoding:");
+ switch(httpreq) {
+ case HTTPREQ_POST_MIME:
+ http->sendit = &data->set.mimepost;
+ break;
+ case HTTPREQ_POST_FORM:
+ /* Convert the form structure into a mime structure. */
+ Curl_mime_cleanpart(&http->form);
+ result = Curl_getformdata(data, &http->form, data->set.httppost,
+ data->state.fread_func);
+ if(result)
+ return result;
+ http->sendit = &http->form;
+ break;
+ default:
+ http->sendit = NULL;
+ }
+
+#ifndef CURL_DISABLE_MIME
+ if(http->sendit) {
+ const char *cthdr = Curl_checkheaders(conn, "Content-Type");
+
+ /* Read and seek body only. */
+ http->sendit->flags |= MIME_BODY_ONLY;
+
+ /* Prepare the mime structure headers & set content type. */
+
+ if(cthdr)
+ for(cthdr += 13; *cthdr == ' '; cthdr++)
+ ;
+ else if(http->sendit->kind == MIMEKIND_MULTIPART)
+ cthdr = "multipart/form-data";
+
+ curl_mime_headers(http->sendit, data->set.headers, 0);
+ result = Curl_mime_prepare_headers(http->sendit, cthdr,
+ NULL, MIMESTRATEGY_FORM);
+ curl_mime_headers(http->sendit, NULL, 0);
+ if(!result)
+ result = Curl_mime_rewind(http->sendit);
+ if(result)
+ return result;
+ http->postsize = Curl_mime_size(http->sendit);
+ }
+#endif
+
+ ptr = Curl_checkheaders(conn, "Transfer-Encoding");
if(ptr) {
/* Some kind of TE is requested, check if 'chunked' is chosen */
data->req.upload_chunky =
Curl_compareheader(ptr, "Transfer-Encoding:", "chunked");
}
else {
- if((conn->handler->protocol&PROTO_FAMILY_HTTP) &&
- data->set.upload &&
- (data->state.infilesize == -1)) {
+ if((conn->handler->protocol & PROTO_FAMILY_HTTP) &&
+ (((httpreq == HTTPREQ_POST_MIME || httpreq == HTTPREQ_POST_FORM) &&
+ http->postsize < 0) ||
+ (data->set.upload && data->state.infilesize == -1))) {
if(conn->bits.authneg)
/* don't enable chunked during auth neg */
;
@@ -1970,7 +2245,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
Curl_safefree(conn->allocptr.host);
- ptr = Curl_checkheaders(conn, "Host:");
+ ptr = Curl_checkheaders(conn, "Host");
if(ptr && (!data->state.this_is_a_follow ||
strcasecompare(data->state.first_host, conn->host.name))) {
#if !defined(CURL_DISABLE_COOKIES)
@@ -1988,7 +2263,6 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
else {
/* If the host begins with '[', we start searching for the port after
the bracket has been closed */
- int startsearch = 0;
if(*cookiehost == '[') {
char *closingbracket;
/* since the 'cookiehost' is an allocated memory area that will be
@@ -1999,6 +2273,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
*closingbracket = 0;
}
else {
+ int startsearch = 0;
char *colon = strchr(cookiehost + startsearch, ':');
if(colon)
*colon = 0; /* The host must not include an embedded port number */
@@ -2009,7 +2284,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
#endif
if(strcmp("Host:", ptr)) {
- conn->allocptr.host = aprintf("%s\r\n", ptr);
+ conn->allocptr.host = aprintf("Host:%s\r\n", &ptr[5]);
if(!conn->allocptr.host)
return CURLE_OUT_OF_MEMORY;
}
@@ -2032,7 +2307,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
host,
conn->bits.ipv6_ip?"]":"");
else
- conn->allocptr.host = aprintf("Host: %s%s%s:%hu\r\n",
+ conn->allocptr.host = aprintf("Host: %s%s%s:%d\r\n",
conn->bits.ipv6_ip?"[":"",
host,
conn->bits.ipv6_ip?"]":"",
@@ -2044,53 +2319,65 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
#ifndef CURL_DISABLE_PROXY
- if(conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
+ 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! */
+
+ /* and no fragment part */
+ CURLUcode uc;
+ char *url;
+ CURLU *h = curl_url_dup(data->state.uh);
+ if(!h)
+ return CURLE_OUT_OF_MEMORY;
+
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) {
- Curl_safefree(data->change.url);
- data->change.url_alloc = FALSE;
- }
- data->change.url = newurl;
- data->change.url_alloc = TRUE;
- }
- else
- return CURLE_OUT_OF_MEMORY;
+ uc = curl_url_set(h, CURLUPART_HOST, conn->host.name, 0);
+ if(uc) {
+ curl_url_cleanup(h);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ }
+ uc = curl_url_set(h, CURLUPART_FRAGMENT, NULL, 0);
+ if(uc) {
+ curl_url_cleanup(h);
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if(strcasecompare("http", data->state.up.scheme)) {
+ /* when getting HTTP, we don't want the userinfo the URL */
+ uc = curl_url_set(h, CURLUPART_USER, NULL, 0);
+ if(uc) {
+ curl_url_cleanup(h);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ uc = curl_url_set(h, CURLUPART_PASSWORD, NULL, 0);
+ if(uc) {
+ curl_url_cleanup(h);
+ return CURLE_OUT_OF_MEMORY;
}
}
- ppath = data->change.url;
- if(checkprefix("ftp://", ppath)) {
+ /* now extract the new version of the URL */
+ uc = curl_url_get(h, CURLUPART_URL, &url, 0);
+ if(uc) {
+ curl_url_cleanup(h);
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if(data->change.url_alloc)
+ free(data->change.url);
+
+ data->change.url = url;
+ data->change.url_alloc = TRUE;
+
+ curl_url_cleanup(h);
+
+ if(strcasecompare("ftp", data->state.up.scheme)) {
if(data->set.proxy_transfer_mode) {
/* when doing ftp, append ;type=<a|i> if not present */
- char *type = strstr(ppath, ";type=");
+ char *type = strstr(path, ";type=");
if(type && type[6] && type[7] == 0) {
switch(Curl_raw_toupper(type[6])) {
case 'A':
@@ -2105,11 +2392,11 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
char *p = ftp_typecode;
/* avoid sending invalid URLs like ftp://example.com;type=i if the
* user specified ftp://example.com without the slash */
- if(!*data->state.path && ppath[strlen(ppath) - 1] != '/') {
+ if(!*data->state.up.path && path[strlen(path) - 1] != '/') {
*p++ = '/';
}
- snprintf(p, sizeof(ftp_typecode) - 1, ";type=%c",
- data->set.prefer_ascii ? 'a' : 'i');
+ msnprintf(p, sizeof(ftp_typecode) - 1, ";type=%c",
+ data->set.prefer_ascii ? 'a' : 'i');
}
}
if(conn->bits.user_passwd && !conn->bits.userpwd_in_url)
@@ -2118,21 +2405,9 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
#endif /* CURL_DISABLE_PROXY */
- if(HTTPREQ_POST_FORM == httpreq) {
- /* we must build the whole post sequence first, so that we have a size of
- the whole transfer before we start to send it */
- result = Curl_getformdata(data, &http->sendit, data->set.httppost,
- Curl_checkheaders(conn, "Content-Type:"),
- &http->postsize);
- if(result)
- return result;
- }
-
- http->p_accept = Curl_checkheaders(conn, "Accept:")?NULL:"Accept: */*\r\n";
+ http->p_accept = Curl_checkheaders(conn, "Accept")?NULL:"Accept: */*\r\n";
- if(( (HTTPREQ_POST == httpreq) ||
- (HTTPREQ_POST_FORM == httpreq) ||
- (HTTPREQ_PUT == httpreq) ) &&
+ if((HTTPREQ_POST == httpreq || HTTPREQ_PUT == httpreq) &&
data->state.resume_from) {
/**********************************************************************
* Resuming upload in HTTP means that we PUT or POST and that we have
@@ -2140,6 +2415,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
* 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.
+ * Resuming mime/form posting at an offset > 0 has no sense and is ignored.
*********************************************************************/
if(data->state.resume_from < 0) {
@@ -2155,13 +2431,16 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* Now, let's read off the proper amount of bytes from the
input. */
+ int seekerr = CURL_SEEKFUNC_CANTSEEK;
if(conn->seek_func) {
+ Curl_set_in_callback(data, true);
seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
SEEK_SET);
+ Curl_set_in_callback(data, false);
}
if(seekerr != CURL_SEEKFUNC_OK) {
- curl_off_t passed=0;
+ curl_off_t passed = 0;
if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
failf(data, "Could not seek stream");
@@ -2208,14 +2487,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
* ones if any such are specified.
*/
if(((httpreq == HTTPREQ_GET) || (httpreq == HTTPREQ_HEAD)) &&
- !Curl_checkheaders(conn, "Range:")) {
+ !Curl_checkheaders(conn, "Range")) {
/* if a line like this was already allocated, free the previous one */
free(conn->allocptr.rangeline);
conn->allocptr.rangeline = aprintf("Range: bytes=%s\r\n",
data->state.range);
}
- else if((httpreq != HTTPREQ_GET) &&
- !Curl_checkheaders(conn, "Content-Range:")) {
+ else if((httpreq == HTTPREQ_POST || httpreq == HTTPREQ_PUT) &&
+ !Curl_checkheaders(conn, "Content-Range")) {
/* if a line like this was already allocated, free the previous one */
free(conn->allocptr.rangeline);
@@ -2232,7 +2511,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
else if(data->state.resume_from) {
/* This is because "resume" was selected */
- curl_off_t total_expected_size=
+ curl_off_t total_expected_size =
data->state.resume_from + data->state.infilesize;
conn->allocptr.rangeline =
aprintf("Content-Range: bytes %s%" CURL_FORMAT_CURL_OFF_T
@@ -2262,22 +2541,36 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* add the main request stuff */
/* GET/HEAD/POST/PUT */
- result = Curl_add_bufferf(req_buffer, "%s ", request);
+ result = Curl_add_bufferf(&req_buffer, "%s ", request);
if(result)
return result;
+ if(data->set.str[STRING_TARGET]) {
+ path = data->set.str[STRING_TARGET];
+ query = NULL;
+ }
+
/* url */
- if(paste_ftp_userpwd)
- result = Curl_add_bufferf(req_buffer, "ftp://%s:%s@%s",
+ if(conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
+ char *url = data->change.url;
+ result = Curl_add_buffer(&req_buffer, url, strlen(url));
+ }
+ else if(paste_ftp_userpwd)
+ result = Curl_add_bufferf(&req_buffer, "ftp://%s:%s@%s",
conn->user, conn->passwd,
- ppath + sizeof("ftp://") - 1);
- else
- result = Curl_add_buffer(req_buffer, ppath, strlen(ppath));
+ path + sizeof("ftp://") - 1);
+ else {
+ result = Curl_add_buffer(&req_buffer, path, strlen(path));
+ if(result)
+ return result;
+ if(query)
+ result = Curl_add_bufferf(&req_buffer, "?%s", query);
+ }
if(result)
return result;
result =
- Curl_add_bufferf(req_buffer,
+ Curl_add_bufferf(&req_buffer,
"%s" /* ftp typecode (;type=x) */
" HTTP/%s\r\n" /* HTTP version */
"%s" /* host */
@@ -2314,7 +2607,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
conn->allocptr.ref:"" /* Referer: <data> */,
(conn->bits.httpproxy &&
!conn->bits.tunnel_proxy &&
- !Curl_checkProxyheaders(conn, "Proxy-Connection:"))?
+ !Curl_checkProxyheaders(conn, "Proxy-Connection"))?
"Proxy-Connection: Keep-Alive\r\n":"",
te
);
@@ -2339,30 +2632,30 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
#if !defined(CURL_DISABLE_COOKIES)
if(data->cookies || addcookies) {
- struct Cookie *co=NULL; /* no cookies from start */
- int count=0;
+ 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->state.path,
+ data->state.up.path,
(conn->handler->protocol&CURLPROTO_HTTPS)?
TRUE:FALSE);
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
}
if(co) {
- struct Cookie *store=co;
+ struct Cookie *store = co;
/* now loop through all cookies that matched */
while(co) {
if(co->value) {
if(0 == count) {
- result = Curl_add_bufferf(req_buffer, "Cookie: ");
+ result = Curl_add_bufferf(&req_buffer, "Cookie: ");
if(result)
break;
}
- result = Curl_add_bufferf(req_buffer,
+ result = Curl_add_bufferf(&req_buffer,
"%s%s=%s", count?"; ":"",
co->name, co->value);
if(result)
@@ -2375,15 +2668,15 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
if(addcookies && !result) {
if(!count)
- result = Curl_add_bufferf(req_buffer, "Cookie: ");
+ result = Curl_add_bufferf(&req_buffer, "Cookie: ");
if(!result) {
- result = Curl_add_bufferf(req_buffer, "%s%s", count?"; ":"",
+ result = Curl_add_bufferf(&req_buffer, "%s%s", count?"; ":"",
addcookies);
count++;
}
}
if(count && !result)
- result = Curl_add_buffer(req_buffer, "\r\n", 2);
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2);
if(result)
return result;
@@ -2407,149 +2700,139 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
switch(httpreq) {
- case HTTPREQ_POST_FORM:
- if(!http->sendit || conn->bits.authneg) {
- /* nothing to post! */
- result = Curl_add_bufferf(req_buffer, "Content-Length: 0\r\n\r\n");
- if(result)
- return result;
-
- result = Curl_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 */
- 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;
- }
-
- /* Get the currently set callback function pointer and store that in the
- form struct since we might want the actual user-provided callback later
- on. The data->set.fread_func pointer itself will be changed for the
- multipart case to the function that returns a multipart formatted
- stream. */
- http->form.fread_func = data->state.fread_func;
-
- /* Set the read function to read from the generated form data */
- data->state.fread_func = (curl_read_callback)Curl_FormReader;
- data->state.in = &http->form;
+ case HTTPREQ_PUT: /* Let's PUT the data to the server! */
- http->sending = HTTPSEND_BODY;
+ if(conn->bits.authneg)
+ postsize = 0;
+ else
+ postsize = data->state.infilesize;
- if(!data->req.upload_chunky &&
- !Curl_checkheaders(conn, "Content-Length:")) {
+ if((postsize != -1) && !data->req.upload_chunky &&
+ (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length"))) {
/* only add Content-Length if not uploading chunked */
- result = Curl_add_bufferf(req_buffer,
+ result = Curl_add_bufferf(&req_buffer,
"Content-Length: %" CURL_FORMAT_CURL_OFF_T
- "\r\n", http->postsize);
+ "\r\n", postsize);
if(result)
return result;
}
- result = expect100(data, conn, 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 = Curl_add_buffer(req_buffer, contentType, linelength);
+ if(postsize != 0) {
+ result = expect100(data, conn, req_buffer);
if(result)
return result;
}
- /* make the request end in a true CRLF */
- result = Curl_add_buffer(req_buffer, "\r\n", 2);
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2); /* end of headers */
if(result)
return result;
- /* set upload size to the progress meter */
- Curl_pgrsSetUploadSize(data, http->postsize);
+ /* set the upload size to the progress meter */
+ Curl_pgrsSetUploadSize(data, postsize);
- /* fire away the whole request to the server */
- result = Curl_add_buffer_send(req_buffer, conn,
+ /* this sends the buffer and frees all the buffer resources */
+ result = Curl_add_buffer_send(&req_buffer, conn,
&data->info.request_size, 0, FIRSTSOCKET);
if(result)
- failf(data, "Failed sending POST request");
+ failf(data, "Failed sending PUT request");
else
- /* setup variables for the upcoming transfer */
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
- &http->readbytecount, FIRSTSOCKET,
- &http->writebytecount);
-
- if(result) {
- Curl_formclean(&http->sendit); /* free that whole lot */
- return result;
- }
-
- /* convert the form data */
- result = Curl_convert_form(data, http->sendit);
- if(result) {
- Curl_formclean(&http->sendit); /* free that whole lot */
+ /* prepare for transfer */
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, TRUE,
+ postsize?FIRSTSOCKET:-1);
+ if(result)
return result;
- }
-
break;
- case HTTPREQ_PUT: /* Let's PUT the data to the server! */
+ case HTTPREQ_POST_FORM:
+ case HTTPREQ_POST_MIME:
+ /* This is form posting using mime data. */
+ if(conn->bits.authneg) {
+ /* nothing to post! */
+ result = Curl_add_bufferf(&req_buffer, "Content-Length: 0\r\n\r\n");
+ if(result)
+ return result;
- if(conn->bits.authneg)
- postsize = 0;
- else
- postsize = data->state.infilesize;
+ result = Curl_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 */
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, TRUE, -1);
+ break;
+ }
- if((postsize != -1) && !data->req.upload_chunky &&
- (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length:"))) {
- /* only add Content-Length if not uploading chunked */
- result = Curl_add_bufferf(req_buffer,
+ data->state.infilesize = postsize = http->postsize;
+
+ /* 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(postsize != -1 && !data->req.upload_chunky &&
+ (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length"))) {
+ /* we allow replacing this header if not during auth negotiation,
+ although it isn't very wise to actually set your own */
+ result = Curl_add_bufferf(&req_buffer,
"Content-Length: %" CURL_FORMAT_CURL_OFF_T
"\r\n", postsize);
if(result)
return result;
}
- if(postsize != 0) {
+#ifndef CURL_DISABLE_MIME
+ /* Output mime-generated headers. */
+ {
+ struct curl_slist *hdr;
+
+ for(hdr = http->sendit->curlheaders; hdr; hdr = hdr->next) {
+ result = Curl_add_bufferf(&req_buffer, "%s\r\n", hdr->data);
+ if(result)
+ return result;
+ }
+ }
+#endif
+
+ /* 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. Just make
+ sure that the expect100header is always set to the preferred value
+ here. */
+ ptr = Curl_checkheaders(conn, "Expect");
+ if(ptr) {
+ data->state.expect100header =
+ Curl_compareheader(ptr, "Expect:", "100-continue");
+ }
+ else if(postsize > EXPECT_100_THRESHOLD || postsize < 0) {
result = expect100(data, conn, req_buffer);
if(result)
return result;
}
+ else
+ data->state.expect100header = FALSE;
- result = Curl_add_buffer(req_buffer, "\r\n", 2); /* end of headers */
+ /* make the request end in a true CRLF */
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2);
if(result)
return result;
/* set the upload size to the progress meter */
Curl_pgrsSetUploadSize(data, postsize);
+ /* Read from mime structure. */
+ data->state.fread_func = (curl_read_callback) Curl_mime_read;
+ data->state.in = (void *) http->sendit;
+ http->sending = HTTPSEND_BODY;
+
/* this sends the buffer and frees all the buffer resources */
- result = Curl_add_buffer_send(req_buffer, conn,
+ result = Curl_add_buffer_send(&req_buffer, conn,
&data->info.request_size, 0, FIRSTSOCKET);
if(result)
- failf(data, "Failed sending PUT request");
+ failf(data, "Failed sending POST request");
else
/* prepare for transfer */
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
- &http->readbytecount, postsize?FIRSTSOCKET:-1,
- postsize?&http->writebytecount:NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, TRUE,
+ postsize?FIRSTSOCKET:-1);
if(result)
return result;
+
break;
case HTTPREQ_POST:
@@ -2565,18 +2848,18 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
we don't upload data chunked, as RFC2616 forbids us to set both
kinds of headers (Transfer-Encoding: chunked and Content-Length) */
if((postsize != -1) && !data->req.upload_chunky &&
- (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length:"))) {
+ (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length"))) {
/* we allow replacing this header if not during auth negotiation,
although it isn't very wise to actually set your own */
- result = Curl_add_bufferf(req_buffer,
+ result = Curl_add_bufferf(&req_buffer,
"Content-Length: %" CURL_FORMAT_CURL_OFF_T
"\r\n", postsize);
if(result)
return result;
}
- if(!Curl_checkheaders(conn, "Content-Type:")) {
- result = Curl_add_bufferf(req_buffer,
+ if(!Curl_checkheaders(conn, "Content-Type")) {
+ result = Curl_add_bufferf(&req_buffer,
"Content-Type: application/"
"x-www-form-urlencoded\r\n");
if(result)
@@ -2587,12 +2870,12 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
the somewhat bigger ones we allow the app to disable it. Just make
sure that the expect100header is always set to the preferred value
here. */
- ptr = Curl_checkheaders(conn, "Expect:");
+ ptr = Curl_checkheaders(conn, "Expect");
if(ptr) {
data->state.expect100header =
Curl_compareheader(ptr, "Expect:", "100-continue");
}
- else if(postsize > TINY_INITIAL_POST_SIZE || postsize < 0) {
+ else if(postsize > EXPECT_100_THRESHOLD || postsize < 0) {
result = expect100(data, conn, req_buffer);
if(result)
return result;
@@ -2606,7 +2889,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
its size. */
if(conn->httpversion != 20 &&
!data->state.expect100header &&
- (postsize < MAX_INITIAL_POST_SIZE)) {
+ (postsize < MAX_INITIAL_POST_SIZE)) {
/* if we don't use expect: 100 AND
postsize is less than MAX_INITIAL_POST_SIZE
@@ -2614,31 +2897,31 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
is no magic limit but only set to prevent really huge POSTs to
get the data duplicated with malloc() and family. */
- result = Curl_add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2); /* end of headers! */
if(result)
return result;
if(!data->req.upload_chunky) {
/* We're not sending it 'chunked', append it to the request
already now to reduce the number if send() calls */
- result = Curl_add_buffer(req_buffer, data->set.postfields,
+ result = Curl_add_buffer(&req_buffer, data->set.postfields,
(size_t)postsize);
included_body = postsize;
}
else {
if(postsize) {
/* Append the POST data chunky-style */
- result = Curl_add_bufferf(req_buffer, "%x\r\n", (int)postsize);
+ result = Curl_add_bufferf(&req_buffer, "%x\r\n", (int)postsize);
if(!result) {
- result = Curl_add_buffer(req_buffer, data->set.postfields,
+ result = Curl_add_buffer(&req_buffer, data->set.postfields,
(size_t)postsize);
if(!result)
- result = Curl_add_buffer(req_buffer, "\r\n", 2);
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2);
included_body = postsize + 2;
}
}
if(!result)
- result = Curl_add_buffer(req_buffer, "\x30\x0d\x0a\x0d\x0a", 5);
+ result = Curl_add_buffer(&req_buffer, "\x30\x0d\x0a\x0d\x0a", 5);
/* 0 CR LF CR LF */
included_body += 5;
}
@@ -2660,20 +2943,20 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* set the upload size to the progress meter */
Curl_pgrsSetUploadSize(data, http->postsize);
- result = Curl_add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2); /* end of headers! */
if(result)
return result;
}
}
else {
- result = Curl_add_buffer(req_buffer, "\r\n", 2); /* end of headers! */
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2); /* end of headers! */
if(result)
return result;
if(data->req.upload_chunky && conn->bits.authneg) {
/* Chunky upload is selected and we're negotiating auth still, send
end-of-data only */
- result = Curl_add_buffer(req_buffer,
+ result = Curl_add_buffer(&req_buffer,
"\x30\x0d\x0a\x0d\x0a", 5);
/* 0 CR LF CR LF */
if(result)
@@ -2694,50 +2977,48 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
}
}
/* issue the request */
- result = Curl_add_buffer_send(req_buffer, conn, &data->info.request_size,
+ result = Curl_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
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
- &http->readbytecount, http->postdata?FIRSTSOCKET:-1,
- http->postdata?&http->writebytecount:NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, TRUE,
+ http->postdata?FIRSTSOCKET:-1);
break;
default:
- result = Curl_add_buffer(req_buffer, "\r\n", 2);
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2);
if(result)
return result;
/* issue the request */
- result = Curl_add_buffer_send(req_buffer, conn,
+ result = Curl_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: */
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, &http->readbytecount,
- http->postdata?FIRSTSOCKET:-1,
- http->postdata?&http->writebytecount:NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, TRUE,
+ http->postdata?FIRSTSOCKET:-1);
}
if(result)
return result;
- if(http->writebytecount) {
+ if(data->req.writebytecount) {
/* if a request-body has been sent off, we make sure this progress is noted
properly */
- Curl_pgrsSetUploadCounter(data, http->writebytecount);
+ Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
- if(http->writebytecount >= postsize) {
+ if(data->req.writebytecount >= postsize) {
/* already sent the entire request body, mark the "upload" as
complete */
infof(data, "upload completely sent off: %" CURL_FORMAT_CURL_OFF_T
" out of %" CURL_FORMAT_CURL_OFF_T " bytes\n",
- http->writebytecount, postsize);
+ data->req.writebytecount, postsize);
data->req.upload_done = TRUE;
data->req.keepon &= ~KEEP_SEND; /* we're done writing */
data->req.exp100 = EXP100_SEND_DATA; /* already sent */
@@ -2753,17 +3034,32 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
return result;
}
+typedef enum {
+ STATUS_UNKNOWN, /* not enough data to tell yet */
+ STATUS_DONE, /* a status line was read */
+ STATUS_BAD /* not a status line */
+} statusline;
+
+
+/* Check a string for a prefix. Check no more than 'len' bytes */
+static bool checkprefixmax(const char *prefix, const char *buffer, size_t len)
+{
+ size_t ch = CURLMIN(strlen(prefix), len);
+ return curl_strnequal(prefix, buffer, ch);
+}
+
/*
* checkhttpprefix()
*
* Returns TRUE if member of the list matches prefix of string
*/
-static bool
+static statusline
checkhttpprefix(struct Curl_easy *data,
- const char *s)
+ const char *s, size_t len)
{
struct curl_slist *head = data->set.http200aliases;
- bool rc = FALSE;
+ statusline rc = STATUS_BAD;
+ statusline onmatch = len >= 5? STATUS_DONE : STATUS_UNKNOWN;
#ifdef CURL_DOES_CONVERSIONS
/* convert from the network encoding using a scratch area */
char *scratch = strdup(s);
@@ -2771,7 +3067,7 @@ checkhttpprefix(struct Curl_easy *data,
failf(data, "Failed to allocate memory for conversion!");
return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */
}
- if(CURLE_OK != Curl_convert_from_network(data, scratch, strlen(s)+1)) {
+ 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 */
@@ -2780,15 +3076,15 @@ checkhttpprefix(struct Curl_easy *data,
#endif /* CURL_DOES_CONVERSIONS */
while(head) {
- if(checkprefix(head->data, s)) {
- rc = TRUE;
+ if(checkprefixmax(head->data, s, len)) {
+ rc = onmatch;
break;
}
head = head->next;
}
- if(!rc && (checkprefix("HTTP/", s)))
- rc = TRUE;
+ if((rc != STATUS_DONE) && (checkprefixmax("HTTP/", s, len)))
+ rc = onmatch;
#ifdef CURL_DOES_CONVERSIONS
free(scratch);
@@ -2797,10 +3093,12 @@ checkhttpprefix(struct Curl_easy *data,
}
#ifndef CURL_DISABLE_RTSP
-static bool
+static statusline
checkrtspprefix(struct Curl_easy *data,
- const char *s)
+ const char *s, size_t len)
{
+ statusline result = STATUS_BAD;
+ statusline onmatch = len >= 5? STATUS_DONE : STATUS_UNKNOWN;
#ifdef CURL_DOES_CONVERSIONS
/* convert from the network encoding using a scratch area */
@@ -2809,33 +3107,35 @@ checkrtspprefix(struct Curl_easy *data,
failf(data, "Failed to allocate memory for conversion!");
return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */
}
- if(CURLE_OK != Curl_convert_from_network(data, scratch, strlen(s)+1)) {
+ 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 */
+ result = FALSE; /* can't return CURLE_foobar so return FALSE */
}
- s = scratch;
+ else if(checkprefixmax("RTSP/", scratch, len))
+ result = onmatch;
+ free(scratch);
#else
(void)data; /* unused */
+ if(checkprefixmax("RTSP/", s, len))
+ result = onmatch;
#endif /* CURL_DOES_CONVERSIONS */
- if(checkprefix("RTSP/", s))
- return TRUE;
- return FALSE;
+
+ return result;
}
#endif /* CURL_DISABLE_RTSP */
-static bool
+static statusline
checkprotoprefix(struct Curl_easy *data, struct connectdata *conn,
- const char *s)
+ const char *s, size_t len)
{
#ifndef CURL_DISABLE_RTSP
if(conn->handler->protocol & CURLPROTO_RTSP)
- return checkrtspprefix(data, s);
+ return checkrtspprefix(data, s, len);
#else
(void)conn;
#endif /* CURL_DISABLE_RTSP */
- return checkhttpprefix(data, s);
+ return checkhttpprefix(data, s, len);
}
/*
@@ -2847,29 +3147,28 @@ static CURLcode header_append(struct Curl_easy *data,
struct SingleRequest *k,
size_t length)
{
- if(k->hbuflen + length >= data->state.headersize) {
+ size_t newsize = k->hbuflen + length;
+ if(newsize > CURL_MAX_HTTP_HEADER) {
+ /* The reason to have a max limit for this is to avoid the risk of a bad
+ server feeding libcurl with a never-ending header that will cause
+ reallocs infinitely */
+ failf(data, "Rejected %zu bytes header (max is %d)!", newsize,
+ CURL_MAX_HTTP_HEADER);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ if(newsize >= data->state.headersize) {
/* We enlarge the header buffer as it is too small */
char *newbuff;
size_t hbufp_index;
- size_t newsize;
-
- if(k->hbuflen + length > CURL_MAX_HTTP_HEADER) {
- /* The reason to have a max limit for this is to avoid the risk of a bad
- server feeding libcurl with a never-ending header that will cause
- reallocs infinitely */
- failf(data, "Avoided giant realloc for header (max is %d)!",
- CURL_MAX_HTTP_HEADER);
- return CURLE_OUT_OF_MEMORY;
- }
- newsize=CURLMAX((k->hbuflen+ length)*3/2, data->state.headersize*2);
+ newsize = CURLMAX((k->hbuflen + length) * 3 / 2, data->state.headersize*2);
hbufp_index = k->hbufp - data->state.headerbuff;
newbuff = 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.headersize = newsize;
data->state.headerbuff = newbuff;
k->hbufp = data->state.headerbuff + hbufp_index;
}
@@ -2928,6 +3227,8 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
{
CURLcode result;
struct SingleRequest *k = &data->req;
+ ssize_t onread = *nread;
+ char *ostr = k->str;
/* header line within buffer loop */
do {
@@ -2948,12 +3249,19 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
if(result)
return result;
- if(!k->headerline && (k->hbuflen>5)) {
- /* make a first check that this looks like a protocol header */
- if(!checkprotoprefix(data, conn, data->state.headerbuff)) {
+ if(!k->headerline) {
+ /* check if this looks like a protocol header */
+ statusline st = checkprotoprefix(data, conn, data->state.headerbuff,
+ k->hbuflen);
+ if(st == STATUS_BAD) {
/* this is not the beginning of a protocol first header line */
k->header = FALSE;
k->badheader = HEADER_ALLBAD;
+ streamclose(conn, "bad HTTP: No end-of-message indicator");
+ if(!data->set.http09_allowed) {
+ failf(data, "Received HTTP/0.9 when not allowed\n");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+ }
break;
}
}
@@ -2962,7 +3270,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
}
/* decrease the size of the remaining (supposed) header line */
- rest_length = (k->end_ptr - k->str)+1;
+ rest_length = (k->end_ptr - k->str) + 1;
*nread -= (ssize_t)rest_length;
k->str = k->end_ptr + 1; /* move past new line */
@@ -2982,9 +3290,15 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
if(!k->headerline) {
/* the first read header */
- if((k->hbuflen>5) &&
- !checkprotoprefix(data, conn, data->state.headerbuff)) {
+ statusline st = checkprotoprefix(data, conn, data->state.headerbuff,
+ k->hbuflen);
+ if(st == STATUS_BAD) {
+ streamclose(conn, "bad HTTP: No end-of-message indicator");
/* this is not the beginning of a protocol first header line */
+ if(!data->set.http09_allowed) {
+ failf(data, "Received HTTP/0.9 when not allowed\n");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+ }
k->header = FALSE;
if(*nread)
/* since there's more, this is a partial bad header */
@@ -2992,7 +3306,9 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
else {
/* this was all we read so it's all a bad header */
k->badheader = HEADER_ALLBAD;
- *nread = (ssize_t)rest_length;
+ *nread = onread;
+ k->str = ostr;
+ return CURLE_OK;
}
break;
}
@@ -3080,7 +3396,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
!(conn->handler->protocol & CURLPROTO_RTSP) &&
data->set.httpreq != HTTPREQ_HEAD) {
/* On HTTP 1.1, when connection is not to get closed, but no
- Content-Length nor Content-Encoding chunked have been
+ Content-Length nor Transfer-Encoding chunked have been
received, according to RFC2616 section 4.4 point 5, we
assume that the server will close the connection to
signal the end of the document. */
@@ -3095,14 +3411,31 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
#if defined(USE_NTLM)
if(conn->bits.close &&
(((data->req.httpcode == 401) &&
- (conn->ntlm.state == NTLMSTATE_TYPE2)) ||
+ (conn->http_ntlm_state == NTLMSTATE_TYPE2)) ||
((data->req.httpcode == 407) &&
- (conn->proxyntlm.state == NTLMSTATE_TYPE2)))) {
+ (conn->proxy_ntlm_state == NTLMSTATE_TYPE2)))) {
infof(data, "Connection closure while negotiating auth (HTTP 1.0?)\n");
data->state.authproblem = TRUE;
}
#endif
-
+#if defined(USE_SPNEGO)
+ if(conn->bits.close &&
+ (((data->req.httpcode == 401) &&
+ (conn->http_negotiate_state == GSS_AUTHRECV)) ||
+ ((data->req.httpcode == 407) &&
+ (conn->proxy_negotiate_state == GSS_AUTHRECV)))) {
+ infof(data, "Connection closure while negotiating auth (HTTP 1.0?)\n");
+ data->state.authproblem = TRUE;
+ }
+ if((conn->http_negotiate_state == GSS_AUTHDONE) &&
+ (data->req.httpcode != 401)) {
+ conn->http_negotiate_state = GSS_AUTHSUCC;
+ }
+ if((conn->proxy_negotiate_state == GSS_AUTHDONE) &&
+ (data->req.httpcode != 407)) {
+ conn->proxy_negotiate_state = GSS_AUTHSUCC;
+ }
+#endif
/*
* When all the headers have been parsed, see if we should give
* up and return an error.
@@ -3161,6 +3494,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
case HTTPREQ_PUT:
case HTTPREQ_POST:
case HTTPREQ_POST_FORM:
+ case HTTPREQ_POST_MIME:
/* We got an error response. If this happened before the whole
* request body has been sent we stop sending and mark the
* connection for closure after we've read the entire response.
@@ -3263,7 +3597,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN,
- k->str_start, headerlen, conn);
+ k->str_start, headerlen);
break; /* exit header line loop */
}
@@ -3288,7 +3622,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
#define HEADER1 scratch
#define SCRATCHSIZE 21
CURLcode res;
- char scratch[SCRATCHSIZE+1]; /* "HTTP/major.minor 123" */
+ 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,
@@ -3314,19 +3648,22 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
* says. We try to allow any number here, but we cannot make
* guarantees on future behaviors since it isn't within the protocol.
*/
+ char separator;
nc = sscanf(HEADER1,
- " HTTP/%d.%d %d",
+ " HTTP/%1d.%1d%c%3d",
&httpversion_major,
&conn->httpversion,
+ &separator,
&k->httpcode);
if(nc == 1 && httpversion_major == 2 &&
1 == sscanf(HEADER1, " HTTP/2 %d", &k->httpcode)) {
conn->httpversion = 0;
- nc = 3;
+ nc = 4;
+ separator = ' ';
}
- if(nc==3) {
+ if((nc == 4) && (' ' == separator)) {
conn->httpversion += 10 * httpversion_major;
if(k->upgr101 == UPGR101_RECEIVED) {
@@ -3334,38 +3671,47 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
if(conn->httpversion != 20)
infof(data, "Lying server, not serving HTTP/2\n");
}
+ if(conn->httpversion < 20) {
+ conn->bundle->multiuse = BUNDLE_NO_MULTIUSE;
+ infof(data, "Mark bundle as not supporting multiuse\n");
+ }
}
- else {
+ else if(!nc) {
/* 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);
+ nc = sscanf(HEADER1, " HTTP %3d", &k->httpcode);
conn->httpversion = 10;
/* If user has set option HTTP200ALIASES,
compare header line against list of aliases
*/
if(!nc) {
- if(checkhttpprefix(data, k->p)) {
+ if(checkhttpprefix(data, k->p, k->hbuflen) == STATUS_DONE) {
nc = 1;
k->httpcode = 200;
conn->httpversion = 10;
}
}
}
+ else {
+ failf(data, "Unsupported HTTP version in response\n");
+ return CURLE_UNSUPPORTED_PROTOCOL;
+ }
}
else if(conn->handler->protocol & CURLPROTO_RTSP) {
+ char separator;
nc = sscanf(HEADER1,
- " RTSP/%d.%d %3d",
+ " RTSP/%1d.%1d%c%3d",
&rtspversion_major,
&conn->rtspversion,
+ &separator,
&k->httpcode);
- if(nc==3) {
+ if((nc == 4) && (' ' == separator)) {
conn->rtspversion += 10 * rtspversion_major;
conn->httpversion = 11; /* For us, RTSP acts like HTTP 1.1 */
}
else {
- /* TODO: do we care about the other cases here? */
nc = 0;
}
}
@@ -3387,21 +3733,18 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
* 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) &&
+ if(data->state.resume_from && data->set.httpreq == HTTPREQ_GET &&
+ k->httpcode == 416) {
+ /* "Requested Range Not Satisfiable", just proceed and
+ pretend this is no error */
+ k->ignorebody = TRUE; /* Avoid appending error msg to good data. */
+ }
+ else if(data->set.http_fail_on_error && (k->httpcode >= 400) &&
((k->httpcode != 401) || !conn->bits.user_passwd) &&
((k->httpcode != 407) || !conn->bits.proxy_user_passwd) ) {
-
- if(data->state.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! */
- print_http_error(data);
- return CURLE_HTTP_RETURNED_ERROR;
- }
+ /* serious error, go home! */
+ print_http_error(data);
+ return CURLE_HTTP_RETURNED_ERROR;
}
if(conn->httpversion == 10) {
@@ -3421,26 +3764,12 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
}
else if(conn->httpversion >= 11 &&
!conn->bits.close) {
- /* If HTTP version is >= 1.1 and connection is persistent
- server supports pipelining. */
+ /* If HTTP version is >= 1.1 and connection is persistent */
DEBUGF(infof(data,
- "HTTP 1.1 or later with persistent connection, "
- "pipelining supported\n"));
- /* Activate pipelining if needed */
- if(conn->bundle) {
- if(!Curl_pipeline_site_blacklisted(data, conn))
- conn->bundle->multiuse = BUNDLE_PIPELINING;
- }
+ "HTTP 1.1 or later with persistent connection\n"));
}
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 304:
/* (quote from RFC2616, section 10.3.5): The 304 response
* MUST NOT contain a message-body, and thus is always
@@ -3448,8 +3777,15 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
* fields. */
if(data->set.timecondition)
data->info.timecond = TRUE;
- k->size=0;
- k->maxdownload=0;
+ /* FALLTHROUGH */
+ 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. */
+ k->size = 0;
+ k->maxdownload = 0;
k->ignorecl = TRUE; /* ignore Content-Length headers */
break;
default:
@@ -3471,13 +3807,15 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
/* Check for Content-Length: header lines to get size */
if(!k->ignorecl && !data->set.ignorecl &&
checkprefix("Content-Length:", k->p)) {
- curl_off_t 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) {
+ curl_off_t contentlength;
+ CURLofft offt = curlx_strtoofft(k->p + 15, NULL, 10, &contentlength);
+
+ if(offt == CURL_OFFT_OK) {
+ if(data->set.max_filesize &&
+ contentlength > data->set.max_filesize) {
+ failf(data, "Maximum file size exceeded");
+ return CURLE_FILESIZE_EXCEEDED;
+ }
k->size = contentlength;
k->maxdownload = k->size;
/* we set the progress download size already at this point
@@ -3485,13 +3823,19 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
info as soon as possible */
Curl_pgrsSetDownloadSize(data, k->size);
}
+ else if(offt == CURL_OFFT_FLOW) {
+ /* out of range */
+ if(data->set.max_filesize) {
+ failf(data, "Maximum file size exceeded");
+ return CURLE_FILESIZE_EXCEEDED;
+ }
+ streamclose(conn, "overflow content-length");
+ infof(data, "Overflow Content-Length: value!\n");
+ }
else {
- /* Negative Content-Length is really odd, and we know it
- happens for example when older Apache servers send large
- files */
- streamclose(conn, "negative content-length");
- infof(data, "Negative content-length: %" CURL_FORMAT_CURL_OFF_T
- ", closing after transfer\n", contentlength);
+ /* negative or just rubbish - bad HTTP */
+ failf(data, "Invalid Content-Length: value");
+ return CURLE_WEIRD_SERVER_REPLY;
}
}
/* check for Content-Type: header lines to get the MIME-type */
@@ -3507,19 +3851,6 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
data->info.contenttype = contenttype;
}
}
- else if(checkprefix("Server:", k->p)) {
- if(conn->httpversion < 20) {
- /* only do this for non-h2 servers */
- char *server_name = Curl_copy_header_value(k->p);
-
- /* Turn off pipelining if the server version is blacklisted */
- if(conn->bundle && (conn->bundle->multiuse == BUNDLE_PIPELINING)) {
- if(Curl_pipeline_server_blacklisted(data, server_name))
- conn->bundle->multiuse = BUNDLE_NO_MULTIUSE;
- }
- free(server_name);
- }
- }
else if((conn->httpversion == 10) &&
conn->bits.httpproxy &&
Curl_compareheader(k->p,
@@ -3576,51 +3907,9 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
* of chunks, and a chunk-data set to zero signals the
* end-of-chunks. */
- char *start;
-
- /* Find the first non-space letter */
- start = k->p + 18;
-
- for(;;) {
- /* skip whitespaces and commas */
- while(*start && (ISSPACE(*start) || (*start == ',')))
- start++;
-
- if(checkprefix("chunked", start)) {
- k->chunk = TRUE; /* chunks coming our way */
-
- /* init our chunky engine */
- Curl_httpchunk_init(conn);
-
- start += 7;
- }
-
- if(k->auto_decoding)
- /* TODO: we only support the first mentioned compression for now */
- break;
-
- if(checkprefix("identity", start)) {
- k->auto_decoding = IDENTITY;
- start += 8;
- }
- else if(checkprefix("deflate", start)) {
- k->auto_decoding = DEFLATE;
- start += 7;
- }
- else if(checkprefix("gzip", start)) {
- k->auto_decoding = GZIP;
- start += 4;
- }
- else if(checkprefix("x-gzip", start)) {
- k->auto_decoding = GZIP;
- start += 6;
- }
- else
- /* unknown! */
- break;
-
- }
-
+ result = Curl_build_unencoding_stack(conn, k->p + 18, TRUE);
+ if(result)
+ return result;
}
else if(checkprefix("Content-Encoding:", k->p) &&
data->set.str[STRING_ENCODING]) {
@@ -3631,21 +3920,9 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
* 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 */
- start = k->p + 17;
- while(*start && ISSPACE(*start))
- start++;
-
- /* Record the content-encoding for later use */
- if(checkprefix("identity", start))
- k->auto_decoding = IDENTITY;
- else if(checkprefix("deflate", start))
- k->auto_decoding = DEFLATE;
- else if(checkprefix("gzip", start)
- || checkprefix("x-gzip", start))
- k->auto_decoding = GZIP;
+ result = Curl_build_unencoding_stack(conn, k->p + 17, FALSE);
+ if(result)
+ return result;
}
else if(checkprefix("Content-Range:", k->p)) {
/* Content-Range: bytes [num]-
@@ -3667,11 +3944,11 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
/* if it truly stopped on a digit */
if(ISDIGIT(*ptr)) {
- k->offset = curlx_strtoofft(ptr, NULL, 10);
-
- if(data->state.resume_from == k->offset)
- /* we asked for a resume and we got it */
- k->content_range = TRUE;
+ if(!curlx_strtoofft(ptr, NULL, 10, &k->offset)) {
+ if(data->state.resume_from == k->offset)
+ /* we asked for a resume and we got it */
+ k->content_range = TRUE;
+ }
}
else
data->state.resume_from = 0; /* get everything */
@@ -3682,22 +3959,24 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE,
CURL_LOCK_ACCESS_SINGLE);
Curl_cookie_add(data,
- data->cookies, TRUE, k->p+11,
+ data->cookies, TRUE, FALSE, 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->state.path);
+ data->state.up.path,
+ (conn->handler->protocol&CURLPROTO_HTTPS)?
+ TRUE:FALSE);
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:"),
+ 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;
+ data->info.filetime = k->timeofdoc;
}
else if((checkprefix("WWW-Authenticate:", k->p) &&
(401 == k->httpcode)) ||
@@ -3716,6 +3995,22 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
if(result)
return result;
}
+ #ifdef USE_SPNEGO
+ else if(checkprefix("Persistent-Auth", k->p)) {
+ struct negotiatedata *negdata = &conn->negotiate;
+ struct auth *authp = &data->state.authhost;
+ if(authp->picked == CURLAUTH_NEGOTIATE) {
+ char *persistentauth = Curl_copy_header_value(k->p);
+ if(!persistentauth)
+ return CURLE_OUT_OF_MEMORY;
+ negdata->noauthpersist = checkprefix("false", persistentauth);
+ negdata->havenoauthpersist = TRUE;
+ infof(data, "Negotiate: noauthpersist -> %d, header part: %s",
+ negdata->noauthpersist, persistentauth);
+ free(persistentauth);
+ }
+ }
+ #endif
else if((k->httpcode >= 300 && k->httpcode < 400) &&
checkprefix("Location:", k->p) &&
!data->req.location) {
@@ -3743,6 +4038,27 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
}
}
}
+#ifdef USE_ALTSVC
+ /* If enabled, the header is incoming and this is over HTTPS */
+ else if(data->asi && checkprefix("Alt-Svc:", k->p) &&
+ ((conn->handler->flags & PROTOPT_SSL) ||
+#ifdef CURLDEBUG
+ /* allow debug builds to circumvent the HTTPS restriction */
+ getenv("CURL_ALTSVC_HTTP")
+#else
+ 0
+#endif
+ )) {
+ /* the ALPN of the current request */
+ enum alpnid id = (conn->httpversion == 20) ? ALPN_h2 : ALPN_h1;
+ result = Curl_altsvc_parse(data, data->asi,
+ &k->p[ strlen("Alt-Svc:") ],
+ id, conn->host.name,
+ curlx_uitous(conn->remote_port));
+ if(result)
+ return result;
+ }
+#endif
else if(conn->handler->protocol & CURLPROTO_RTSP) {
result = Curl_rtsp_parseheader(conn, k->p);
if(result)
@@ -3758,8 +4074,7 @@ CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
writetype |= CLIENTWRITE_BODY;
if(data->set.verbose)
- Curl_debug(data, CURLINFO_HEADER_IN,
- k->p, (size_t)k->hbuflen, conn);
+ Curl_debug(data, CURLINFO_HEADER_IN, k->p, (size_t)k->hbuflen);
result = Curl_client_write(conn, writetype, k->p, k->hbuflen);
if(result)
diff --git a/Utilities/cmcurl/lib/http.h b/Utilities/cmcurl/lib/http.h
index 7ce4bd9a0..a59fe7af0 100644
--- a/Utilities/cmcurl/lib/http.h
+++ b/Utilities/cmcurl/lib/http.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -40,8 +40,6 @@ bool Curl_compareheader(const char *headerline, /* line to check */
const char *header, /* header keyword _with_ colon */
const char *content); /* content string to find */
-char *Curl_checkheaders(const struct connectdata *conn,
- const char *thisheader);
char *Curl_copy_header_value(const char *header);
char *Curl_checkProxyheaders(const struct connectdata *conn,
@@ -60,12 +58,14 @@ struct Curl_send_buffer {
typedef struct Curl_send_buffer Curl_send_buffer;
Curl_send_buffer *Curl_add_buffer_init(void);
-void Curl_add_buffer_free(Curl_send_buffer *buff);
-CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...);
-CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size);
-CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
+void Curl_add_buffer_free(Curl_send_buffer **inp);
+CURLcode Curl_add_bufferf(Curl_send_buffer **inp, const char *fmt, ...)
+ WARN_UNUSED_RESULT;
+CURLcode Curl_add_buffer(Curl_send_buffer **inp, const void *inptr,
+ size_t size) WARN_UNUSED_RESULT;
+CURLcode Curl_add_buffer_send(Curl_send_buffer **inp,
struct connectdata *conn,
- long *bytes_written,
+ curl_off_t *bytes_written,
size_t included_body_bytes,
int socketindex);
@@ -74,6 +74,9 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
CURLcode Curl_add_custom_headers(struct connectdata *conn,
bool is_connect,
Curl_send_buffer *req_buffer);
+CURLcode Curl_http_compile_trailers(struct curl_slist *trailers,
+ Curl_send_buffer *buffer,
+ struct Curl_easy *handle);
/* protocol-specific functions set up to be called by the main engine */
CURLcode Curl_http(struct connectdata *conn, bool *done);
@@ -106,7 +109,7 @@ CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
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
+ will always be unconditionally 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.
@@ -115,8 +118,13 @@ CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
#define MAX_INITIAL_POST_SIZE (64*1024)
#endif
-#ifndef TINY_INITIAL_POST_SIZE
-#define TINY_INITIAL_POST_SIZE 1024
+/* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will
+ * automatically add an "Expect: 100-continue" header in HTTP requests. When
+ * the size is unknown, it will always add it.
+ *
+ */
+#ifndef EXPECT_100_THRESHOLD
+#define EXPECT_100_THRESHOLD 1024
#endif
#endif /* CURL_DISABLE_HTTP */
@@ -125,17 +133,15 @@ CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
* HTTP unique setup
***************************************************************************/
struct HTTP {
- struct FormData *sendit;
+ curl_mimepart *sendit;
curl_off_t postsize; /* off_t to handle large file sizes */
const 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;
+ curl_mimepart form;
struct back {
curl_read_callback fread_func; /* backup storage for fread pointer */
@@ -151,9 +157,11 @@ struct HTTP {
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 */
-
+#ifndef CURL_DISABLE_HTTP
+ Curl_send_buffer *send_buffer; /* used if the request couldn't be sent in
+ one chunk, points to an allocated
+ send_buffer struct */
+#endif
#ifdef USE_NGHTTP2
/*********** for HTTP/2 we store stream-local data here *************/
int32_t stream_id; /* stream we are interested in */
@@ -169,8 +177,6 @@ struct HTTP {
size_t pauselen; /* the number of bytes left in data */
bool closed; /* TRUE on HTTP2 stream close */
bool close_handled; /* TRUE if stream closure is handled by libcurl */
- uint32_t error_code; /* HTTP/2 error code */
-
char *mem; /* points to a buffer in memory to store received data */
size_t len; /* size of the buffer 'mem' points to */
size_t memlen; /* size of data copied to mem */
@@ -185,9 +191,6 @@ struct HTTP {
#endif
};
-typedef int (*sending)(void); /* Curl_send */
-typedef int (*recving)(void); /* Curl_recv */
-
#ifdef USE_NGHTTP2
/* h2 settings for this connection */
struct h2settings {
@@ -196,15 +199,14 @@ struct h2settings {
};
#endif
-
struct http_conn {
#ifdef USE_NGHTTP2
#define H2_BINSETTINGS_LEN 80
nghttp2_session *h2;
uint8_t binsettings[H2_BINSETTINGS_LEN];
size_t binlen; /* length of the binsettings data */
- sending send_underlying; /* underlying send Curl_send callback */
- recving recv_underlying; /* underlying recv Curl_recv callback */
+ Curl_send *send_underlying; /* underlying send Curl_send callback */
+ Curl_recv *recv_underlying; /* underlying recv Curl_recv callback */
char *inbuf; /* buffer to receive data from underlying socket */
size_t inbuflen; /* number of bytes filled in inbuf */
size_t nread_inbuf; /* number of bytes read from in inbuf */
@@ -223,6 +225,7 @@ struct http_conn {
/* list of settings that will be sent */
nghttp2_settings_entry local_settings[3];
size_t local_settings_num;
+ uint32_t error_code; /* HTTP/2 error code */
#else
int unused; /* prevent a compiler warning */
#endif
@@ -255,4 +258,3 @@ Curl_http_output_auth(struct connectdata *conn,
up the proxy tunnel */
#endif /* HEADER_CURL_HTTP_H */
-
diff --git a/Utilities/cmcurl/lib/http2.c b/Utilities/cmcurl/lib/http2.c
index f8e23c517..8e7bc217e 100644
--- a/Utilities/cmcurl/lib/http2.c
+++ b/Utilities/cmcurl/lib/http2.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -28,10 +28,10 @@
#include "http2.h"
#include "http.h"
#include "sendf.h"
+#include "select.h"
#include "curl_base64.h"
#include "strcase.h"
#include "multiif.h"
-#include "conncache.h"
#include "url.h"
#include "connect.h"
#include "strtoofft.h"
@@ -41,7 +41,7 @@
#include "curl_memory.h"
#include "memdebug.h"
-#define MIN(x,y) ((x)<(y)?(x):(y))
+#define H2_BUFSIZE 32768
#if (NGHTTP2_VERSION_NUM < 0x010000)
#error too old nghttp2 version, upgrade!
@@ -65,6 +65,22 @@
#define HTTP2_HUGE_WINDOW_SIZE (1 << 30)
+#ifdef DEBUG_HTTP2
+#define H2BUGF(x) x
+#else
+#define H2BUGF(x) do { } WHILE_FALSE
+#endif
+
+
+static ssize_t http2_recv(struct connectdata *conn, int sockindex,
+ char *mem, size_t len, CURLcode *err);
+static bool http2_connisdead(struct connectdata *conn);
+static int h2_session_send(struct Curl_easy *data,
+ nghttp2_session *h2);
+static int h2_process_pending_input(struct connectdata *conn,
+ struct http_conn *httpc,
+ CURLcode *err);
+
/*
* Curl_http2_init_state() is called when the easy handle is created and
* allows for HTTP/2 specific init of state.
@@ -91,18 +107,19 @@ static int http2_perform_getsock(const struct connectdata *conn,
int numsocks)
{
const struct http_conn *c = &conn->proto.httpc;
+ struct SingleRequest *k = &conn->data->req;
int bitmap = GETSOCK_BLANK;
(void)numsocks;
- /* TODO We should check underlying socket state if it is SSL socket
- because of renegotiation. */
sock[0] = conn->sock[FIRSTSOCKET];
/* in a HTTP/2 connection we can basically always get a frame so we should
always be ready for one */
bitmap |= GETSOCK_READSOCK(FIRSTSOCKET);
- if(nghttp2_session_want_write(c->h2))
+ /* we're still uploading or the HTTP/2 layer wants to send data */
+ if(((k->keepon & (KEEP_SEND|KEEP_SEND_PAUSE)) == KEEP_SEND) ||
+ nghttp2_session_want_write(c->h2))
bitmap |= GETSOCK_WRITESOCK(FIRSTSOCKET);
return bitmap;
@@ -122,10 +139,8 @@ static int http2_getsock(struct connectdata *conn,
static void http2_stream_free(struct HTTP *http)
{
if(http) {
- Curl_add_buffer_free(http->header_recvbuf);
- http->header_recvbuf = NULL; /* clear the pointer */
- Curl_add_buffer_free(http->trailer_recvbuf);
- http->trailer_recvbuf = NULL; /* clear the pointer */
+ Curl_add_buffer_free(&http->header_recvbuf);
+ Curl_add_buffer_free(&http->trailer_recvbuf);
for(; http->push_headers_used > 0; --http->push_headers_used) {
free(http->push_headers[http->push_headers_used - 1]);
}
@@ -134,23 +149,126 @@ static void http2_stream_free(struct HTTP *http)
}
}
+/*
+ * Disconnects *a* connection used for HTTP/2. It might be an old one from the
+ * connection cache and not the "main" one. Don't touch the easy handle!
+ */
+
static CURLcode http2_disconnect(struct connectdata *conn,
bool dead_connection)
{
struct http_conn *c = &conn->proto.httpc;
(void)dead_connection;
- DEBUGF(infof(conn->data, "HTTP/2 DISCONNECT starts now\n"));
+ H2BUGF(infof(conn->data, "HTTP/2 DISCONNECT starts now\n"));
nghttp2_session_del(c->h2);
Curl_safefree(c->inbuf);
- http2_stream_free(conn->data->req.protop);
- DEBUGF(infof(conn->data, "HTTP/2 DISCONNECT done\n"));
+ H2BUGF(infof(conn->data, "HTTP/2 DISCONNECT done\n"));
return CURLE_OK;
}
+/*
+ * The server may send us data at any point (e.g. PING frames). Therefore,
+ * we cannot assume that an HTTP/2 socket is dead just because it is readable.
+ *
+ * Instead, if it is readable, run Curl_connalive() to peek at the socket
+ * and distinguish between closed and data.
+ */
+static bool http2_connisdead(struct connectdata *conn)
+{
+ int sval;
+ bool dead = TRUE;
+
+ if(conn->bits.close)
+ return TRUE;
+
+ sval = SOCKET_READABLE(conn->sock[FIRSTSOCKET], 0);
+ if(sval == 0) {
+ /* timeout */
+ dead = FALSE;
+ }
+ else if(sval & CURL_CSELECT_ERR) {
+ /* socket is in an error state */
+ dead = TRUE;
+ }
+ else if(sval & CURL_CSELECT_IN) {
+ /* readable with no error. could still be closed */
+ dead = !Curl_connalive(conn);
+ if(!dead) {
+ /* This happens before we've sent off a request and the connection is
+ not in use by any other transfer, there shouldn't be any data here,
+ only "protocol frames" */
+ CURLcode result;
+ struct http_conn *httpc = &conn->proto.httpc;
+ ssize_t nread = -1;
+ if(httpc->recv_underlying)
+ /* if called "too early", this pointer isn't setup yet! */
+ nread = ((Curl_recv *)httpc->recv_underlying)(
+ conn, FIRSTSOCKET, httpc->inbuf, H2_BUFSIZE, &result);
+ if(nread != -1) {
+ infof(conn->data,
+ "%d bytes stray data read before trying h2 connection\n",
+ (int)nread);
+ httpc->nread_inbuf = 0;
+ httpc->inbuflen = nread;
+ (void)h2_process_pending_input(conn, httpc, &result);
+ }
+ else
+ /* the read failed so let's say this is dead anyway */
+ dead = TRUE;
+ }
+ }
+
+ return dead;
+}
+
+static unsigned int http2_conncheck(struct connectdata *check,
+ unsigned int checks_to_perform)
+{
+ unsigned int ret_val = CONNRESULT_NONE;
+ struct http_conn *c = &check->proto.httpc;
+ int rc;
+ bool send_frames = false;
+
+ if(checks_to_perform & CONNCHECK_ISDEAD) {
+ if(http2_connisdead(check))
+ ret_val |= CONNRESULT_DEAD;
+ }
+
+ if(checks_to_perform & CONNCHECK_KEEPALIVE) {
+ struct curltime now = Curl_now();
+ time_t elapsed = Curl_timediff(now, check->keepalive);
+
+ if(elapsed > check->upkeep_interval_ms) {
+ /* Perform an HTTP/2 PING */
+ rc = nghttp2_submit_ping(c->h2, 0, ZERO_NULL);
+ if(!rc) {
+ /* Successfully added a PING frame to the session. Need to flag this
+ so the frame is sent. */
+ send_frames = true;
+ }
+ else {
+ failf(check->data, "nghttp2_submit_ping() failed: %s(%d)",
+ nghttp2_strerror(rc), rc);
+ }
+
+ check->keepalive = now;
+ }
+ }
+
+ if(send_frames) {
+ rc = nghttp2_session_send(c->h2);
+ if(rc)
+ failf(check->data, "nghttp2_session_send() failed: %s(%d)",
+ nghttp2_strerror(rc), rc);
+ }
+
+ return ret_val;
+}
+
/* called from Curl_http_setup_conn */
void Curl_http2_setup_req(struct Curl_easy *data)
{
@@ -161,7 +279,6 @@ void Curl_http2_setup_req(struct Curl_easy *data)
http->status_code = -1;
http->pausedata = NULL;
http->pauselen = 0;
- http->error_code = NGHTTP2_NO_ERROR;
http->closed = FALSE;
http->close_handled = FALSE;
http->mem = data->state.buffer;
@@ -174,6 +291,7 @@ void Curl_http2_setup_conn(struct connectdata *conn)
{
conn->proto.httpc.settings.max_concurrent_streams =
DEFAULT_MAX_CONCURRENT_STREAMS;
+ conn->proto.httpc.error_code = NGHTTP2_NO_ERROR;
}
/*
@@ -196,6 +314,7 @@ static const struct Curl_handler Curl_handler_http2 = {
http2_perform_getsock, /* perform_getsock */
http2_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ http2_conncheck, /* connection_check */
PORT_HTTP, /* defport */
CURLPROTO_HTTP, /* protocol */
PROTOPT_STREAM /* flags */
@@ -216,6 +335,7 @@ static const struct Curl_handler Curl_handler_http2_ssl = {
http2_perform_getsock, /* perform_getsock */
http2_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ http2_conncheck, /* connection_check */
PORT_HTTP, /* defport */
CURLPROTO_HTTPS, /* protocol */
PROTOPT_SSL | PROTOPT_STREAM /* flags */
@@ -228,14 +348,14 @@ static const struct Curl_handler Curl_handler_http2_ssl = {
int Curl_http2_ver(char *p, size_t len)
{
nghttp2_info *h2 = nghttp2_version(0);
- return snprintf(p, len, " nghttp2/%s", h2->version_str);
+ return msnprintf(p, len, " nghttp2/%s", h2->version_str);
}
/* HTTP/2 error code to name based on the Error Code Registry.
https://tools.ietf.org/html/rfc7540#page-77
nghttp2_error_code enums are identical.
*/
-const char *Curl_http2_strerror(uint32_t err)
+static const char *http2_strerror(uint32_t err)
{
#ifndef NGHTTP2_HAS_HTTP2_STRERROR
const char *str[] = {
@@ -254,7 +374,7 @@ const char *Curl_http2_strerror(uint32_t err)
"INADEQUATE_SECURITY", /* 0xC */
"HTTP_1_1_REQUIRED" /* 0xD */
};
- return (err < sizeof str / sizeof str[0]) ? str[err] : "unknown";
+ return (err < sizeof(str) / sizeof(str[0])) ? str[err] : "unknown";
#else
return nghttp2_http2_strerror(err);
#endif
@@ -277,6 +397,10 @@ static ssize_t send_callback(nghttp2_session *h2,
(void)h2;
(void)flags;
+ if(!c->send_underlying)
+ /* called before setup properly! */
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+
written = ((Curl_send*)c->send_underlying)(conn, FIRSTSOCKET,
data, length, &result);
@@ -338,18 +462,40 @@ char *curl_pushheader_byname(struct curl_pushheaders *h, const char *header)
struct HTTP *stream = h->data->req.protop;
size_t len = strlen(header);
size_t i;
- for(i=0; i<stream->push_headers_used; i++) {
+ for(i = 0; i<stream->push_headers_used; i++) {
if(!strncmp(header, stream->push_headers[i], len)) {
/* sub-match, make sure that it is followed by a colon */
if(stream->push_headers[i][len] != ':')
continue;
- return &stream->push_headers[i][len+1];
+ return &stream->push_headers[i][len + 1];
}
}
}
return NULL;
}
+/*
+ * This specific transfer on this connection has been "drained".
+ */
+static void drained_transfer(struct Curl_easy *data,
+ struct http_conn *httpc)
+{
+ DEBUGASSERT(httpc->drain_total >= data->state.drain);
+ httpc->drain_total -= data->state.drain;
+ data->state.drain = 0;
+}
+
+/*
+ * Mark this transfer to get "drained".
+ */
+static void drain_this(struct Curl_easy *data,
+ struct http_conn *httpc)
+{
+ data->state.drain++;
+ httpc->drain_total++;
+ DEBUGASSERT(httpc->drain_total >= data->state.drain);
+}
+
static struct Curl_easy *duphandle(struct Curl_easy *data)
{
struct Curl_easy *second = curl_easy_duphandle(data);
@@ -383,7 +529,7 @@ static int push_promise(struct Curl_easy *data,
const nghttp2_push_promise *frame)
{
int rv;
- DEBUGF(infof(data, "PUSH_PROMISE received, stream %u!\n",
+ H2BUGF(infof(data, "PUSH_PROMISE received, stream %u!\n",
frame->promised_stream_id));
if(data->multi->push_cb) {
struct HTTP *stream;
@@ -403,7 +549,7 @@ static int push_promise(struct Curl_easy *data,
heads.data = data;
heads.frame = frame;
/* ask the application */
- DEBUGF(infof(data, "Got PUSH_PROMISE, ask application!\n"));
+ H2BUGF(infof(data, "Got PUSH_PROMISE, ask application!\n"));
stream = data->req.protop;
if(!stream) {
@@ -413,12 +559,14 @@ static int push_promise(struct Curl_easy *data,
goto fail;
}
+ Curl_set_in_callback(data, true);
rv = data->multi->push_cb(data, newhandle,
stream->push_headers_used, &heads,
data->multi->push_userp);
+ Curl_set_in_callback(data, false);
/* free the headers again */
- for(i=0; i<stream->push_headers_used; i++)
+ for(i = 0; i<stream->push_headers_used; i++)
free(stream->push_headers[i]);
free(stream->push_headers);
stream->push_headers = NULL;
@@ -427,6 +575,7 @@ static int push_promise(struct Curl_easy *data,
if(rv) {
/* denied, kill off the new handle again */
http2_stream_free(newhandle->req.protop);
+ newhandle->req.protop = NULL;
(void)Curl_close(newhandle);
goto fail;
}
@@ -442,23 +591,43 @@ static int push_promise(struct Curl_easy *data,
if(rc) {
infof(data, "failed to add handle to multi\n");
http2_stream_free(newhandle->req.protop);
+ newhandle->req.protop = NULL;
Curl_close(newhandle);
rv = 1;
goto fail;
}
httpc = &conn->proto.httpc;
- nghttp2_session_set_stream_user_data(httpc->h2,
- frame->promised_stream_id, newhandle);
+ rv = nghttp2_session_set_stream_user_data(httpc->h2,
+ frame->promised_stream_id,
+ newhandle);
+ if(rv) {
+ infof(data, "failed to set user_data for stream %d\n",
+ frame->promised_stream_id);
+ DEBUGASSERT(0);
+ goto fail;
+ }
}
else {
- DEBUGF(infof(data, "Got PUSH_PROMISE, ignore it!\n"));
+ H2BUGF(infof(data, "Got PUSH_PROMISE, ignore it!\n"));
rv = 1;
}
fail:
return rv;
}
+/*
+ * multi_connchanged() is called to tell that there is a connection in
+ * this multi handle that has changed state (multiplexing become possible, the
+ * number of allowed streams changed or similar), and a subsequent use of this
+ * multi handle should move CONNECT_PEND handles back to CONNECT to have them
+ * retry.
+ */
+static void multi_connchanged(struct Curl_multi *multi)
+{
+ multi->recheckstate = TRUE;
+}
+
static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
void *userp)
{
@@ -466,41 +635,39 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
struct http_conn *httpc = &conn->proto.httpc;
struct Curl_easy *data_s = NULL;
struct HTTP *stream = NULL;
- static int lastStream = -1;
int rv;
size_t left, ncopy;
int32_t stream_id = frame->hd.stream_id;
+ CURLcode result;
if(!stream_id) {
/* stream ID zero is for connection-oriented stuff */
if(frame->hd.type == NGHTTP2_SETTINGS) {
uint32_t max_conn = httpc->settings.max_concurrent_streams;
- DEBUGF(infof(conn->data, "Got SETTINGS\n"));
+ H2BUGF(infof(conn->data, "Got SETTINGS\n"));
httpc->settings.max_concurrent_streams =
nghttp2_session_get_remote_settings(
session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS);
httpc->settings.enable_push =
nghttp2_session_get_remote_settings(
session, NGHTTP2_SETTINGS_ENABLE_PUSH);
- DEBUGF(infof(conn->data, "MAX_CONCURRENT_STREAMS == %d\n",
+ H2BUGF(infof(conn->data, "MAX_CONCURRENT_STREAMS == %d\n",
httpc->settings.max_concurrent_streams));
- DEBUGF(infof(conn->data, "ENABLE_PUSH == %s\n",
+ H2BUGF(infof(conn->data, "ENABLE_PUSH == %s\n",
httpc->settings.enable_push?"TRUE":"false"));
if(max_conn != httpc->settings.max_concurrent_streams) {
/* only signal change if the value actually changed */
infof(conn->data,
- "Connection state changed (MAX_CONCURRENT_STREAMS updated)!\n");
- Curl_multi_connchanged(conn->data->multi);
+ "Connection state changed (MAX_CONCURRENT_STREAMS == %u)!\n",
+ httpc->settings.max_concurrent_streams);
+ multi_connchanged(conn->data->multi);
}
}
return 0;
}
data_s = nghttp2_session_get_stream_user_data(session, stream_id);
- if(lastStream != stream_id) {
- lastStream = stream_id;
- }
if(!data_s) {
- DEBUGF(infof(conn->data,
+ H2BUGF(infof(conn->data,
"No Curl_easy associated with stream: %x\n",
stream_id));
return 0;
@@ -508,12 +675,12 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
stream = data_s->req.protop;
if(!stream) {
- DEBUGF(infof(conn->data, "No proto pointer for stream: %x\n",
+ H2BUGF(infof(data_s, "No proto pointer for stream: %x\n",
stream_id));
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
- DEBUGF(infof(data_s, "on_frame_recv() header %x stream %x\n",
+ H2BUGF(infof(data_s, "on_frame_recv() header %x stream %x\n",
frame->hd.type, stream_id));
switch(frame->hd.type) {
@@ -536,8 +703,10 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
}
/* nghttp2 guarantees that :status is received, and we store it to
- stream->status_code */
- DEBUGASSERT(stream->status_code != -1);
+ stream->status_code. Fuzzing has proven this can still be reached
+ without status code having been set. */
+ if(stream->status_code == -1)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
/* Only final status code signals the end of header */
if(stream->status_code / 100 != 1) {
@@ -545,24 +714,25 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
stream->status_code = -1;
}
- Curl_add_buffer(stream->header_recvbuf, "\r\n", 2);
+ result = Curl_add_buffer(&stream->header_recvbuf, "\r\n", 2);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
left = stream->header_recvbuf->size_used - stream->nread_header_recvbuf;
- ncopy = MIN(stream->len, left);
+ ncopy = CURLMIN(stream->len, left);
memcpy(&stream->mem[stream->memlen],
stream->header_recvbuf->buffer + stream->nread_header_recvbuf,
ncopy);
stream->nread_header_recvbuf += ncopy;
- DEBUGF(infof(data_s, "Store %zu bytes headers from stream %u at %p\n",
+ H2BUGF(infof(data_s, "Store %zu bytes headers from stream %u at %p\n",
ncopy, stream_id, stream->mem));
stream->len -= ncopy;
stream->memlen += ncopy;
- data_s->state.drain++;
- httpc->drain_total++;
+ drain_this(data_s, httpc);
{
/* get the pointer from userp again since it was re-assigned above */
struct connectdata *conn_s = (struct connectdata *)userp;
@@ -584,32 +754,13 @@ static int on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame,
}
break;
default:
- DEBUGF(infof(conn->data, "Got frame type %x for stream %u!\n",
+ H2BUGF(infof(data_s, "Got frame type %x for stream %u!\n",
frame->hd.type, stream_id));
break;
}
return 0;
}
-static int on_invalid_frame_recv(nghttp2_session *session,
- const nghttp2_frame *frame,
- int lib_error_code, void *userp)
-{
- struct Curl_easy *data_s = NULL;
- (void)userp;
-#if !defined(DEBUGBUILD) || defined(CURL_DISABLE_VERBOSE_STRINGS)
- (void)lib_error_code;
-#endif
-
- data_s = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id);
- if(data_s) {
- DEBUGF(infof(data_s,
- "on_invalid_frame_recv() was called, error=%d:%s\n",
- lib_error_code, nghttp2_strerror(lib_error_code)));
- }
- return 0;
-}
-
static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
int32_t stream_id,
const uint8_t *data, size_t len, void *userp)
@@ -635,20 +786,19 @@ static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
if(!stream)
return NGHTTP2_ERR_CALLBACK_FAILURE;
- nread = MIN(stream->len, len);
+ nread = CURLMIN(stream->len, len);
memcpy(&stream->mem[stream->memlen], data, nread);
stream->len -= nread;
stream->memlen += nread;
- data_s->state.drain++;
- conn->proto.httpc.drain_total++;
+ drain_this(data_s, &conn->proto.httpc);
/* if we receive data for another handle, wake that up */
if(conn->data != data_s)
Curl_expire(data_s, 0, EXPIRE_RUN_NOW);
- DEBUGF(infof(data_s, "%zu data received for stream %u "
+ H2BUGF(infof(data_s, "%zu data received for stream %u "
"(%zu left in buffer %p, total %zu)\n",
nread, stream_id,
stream->len, stream->mem,
@@ -657,10 +807,10 @@ static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
if(nread < len) {
stream->pausedata = data + nread;
stream->pauselen = len - nread;
- DEBUGF(infof(data_s, "NGHTTP2_ERR_PAUSE - %zu bytes out of buffer"
+ H2BUGF(infof(data_s, "NGHTTP2_ERR_PAUSE - %zu bytes out of buffer"
", stream %u\n",
len - nread, stream_id));
- data_s->easy_conn->proto.httpc.pause_stream_id = stream_id;
+ data_s->conn->proto.httpc.pause_stream_id = stream_id;
return NGHTTP2_ERR_PAUSE;
}
@@ -668,7 +818,7 @@ static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
/* pause execution of nghttp2 if we received data for another handle
in order to process them first. */
if(conn->data != data_s) {
- data_s->easy_conn->proto.httpc.pause_stream_id = stream_id;
+ data_s->conn->proto.httpc.pause_stream_id = stream_id;
return NGHTTP2_ERR_PAUSE;
}
@@ -676,62 +826,18 @@ static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags,
return 0;
}
-static int before_frame_send(nghttp2_session *session,
- const nghttp2_frame *frame,
- void *userp)
-{
- struct Curl_easy *data_s;
- (void)userp;
-
- data_s = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id);
- if(data_s) {
- DEBUGF(infof(data_s, "before_frame_send() was called\n"));
- }
-
- return 0;
-}
-static int on_frame_send(nghttp2_session *session,
- const nghttp2_frame *frame,
- void *userp)
-{
- struct Curl_easy *data_s;
- (void)userp;
-
- data_s = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id);
- if(data_s) {
- DEBUGF(infof(data_s, "on_frame_send() was called, length = %zd\n",
- frame->hd.length));
- }
- return 0;
-}
-static int on_frame_not_send(nghttp2_session *session,
- const nghttp2_frame *frame,
- int lib_error_code, void *userp)
-{
- struct Curl_easy *data_s;
- (void)userp;
-#if !defined(DEBUGBUILD) || defined(CURL_DISABLE_VERBOSE_STRINGS)
- (void)lib_error_code;
-#endif
-
- data_s = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id);
- if(data_s) {
- DEBUGF(infof(data_s,
- "on_frame_not_send() was called, lib_error_code = %d\n",
- lib_error_code));
- }
- return 0;
-}
static int on_stream_close(nghttp2_session *session, int32_t stream_id,
uint32_t error_code, void *userp)
{
struct Curl_easy *data_s;
struct HTTP *stream;
struct connectdata *conn = (struct connectdata *)userp;
+ int rv;
(void)session;
(void)stream_id;
if(stream_id) {
+ struct http_conn *httpc;
/* get the stream from the hash based on Stream ID, stream ID zero is for
connection-oriented stuff */
data_s = nghttp2_session_get_stream_user_data(session, stream_id);
@@ -740,20 +846,30 @@ static int on_stream_close(nghttp2_session *session, int32_t stream_id,
decided to reject stream (e.g., PUSH_PROMISE). */
return 0;
}
- DEBUGF(infof(data_s, "on_stream_close(), %s (err %d), stream %u\n",
- Curl_http2_strerror(error_code), error_code, stream_id));
+ H2BUGF(infof(data_s, "on_stream_close(), %s (err %d), stream %u\n",
+ http2_strerror(error_code), error_code, stream_id));
stream = data_s->req.protop;
if(!stream)
return NGHTTP2_ERR_CALLBACK_FAILURE;
- stream->error_code = error_code;
stream->closed = TRUE;
- data_s->state.drain++;
- conn->proto.httpc.drain_total++;
+ httpc = &conn->proto.httpc;
+ drain_this(data_s, httpc);
+ httpc->error_code = error_code;
/* remove the entry from the hash as the stream is now gone */
- nghttp2_session_set_stream_user_data(session, stream_id, 0);
- DEBUGF(infof(data_s, "Removed stream %u hash!\n", stream_id));
+ rv = nghttp2_session_set_stream_user_data(session, stream_id, 0);
+ if(rv) {
+ infof(data_s, "http/2: failed to clear user_data for stream %d!\n",
+ stream_id);
+ DEBUGASSERT(0);
+ }
+ if(stream_id == httpc->pause_stream_id) {
+ H2BUGF(infof(data_s, "Stopped the pause stream!\n"));
+ httpc->pause_stream_id = 0;
+ }
+ H2BUGF(infof(data_s, "Removed stream %u hash!\n", stream_id));
+ stream->stream_id = 0; /* cleared */
}
return 0;
}
@@ -770,7 +886,7 @@ static int on_begin_headers(nghttp2_session *session,
return 0;
}
- DEBUGF(infof(data_s, "on_begin_headers() was called\n"));
+ H2BUGF(infof(data_s, "on_begin_headers() was called\n"));
if(frame->hd.type != NGHTTP2_HEADERS) {
return 0;
@@ -781,16 +897,12 @@ static int on_begin_headers(nghttp2_session *session,
return 0;
}
- /* This is trailer HEADERS started. Allocate buffer for them. */
- DEBUGF(infof(data_s, "trailer field started\n"));
-
- DEBUGASSERT(stream->trailer_recvbuf == NULL);
-
- stream->trailer_recvbuf = Curl_add_buffer_init();
if(!stream->trailer_recvbuf) {
- return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
+ stream->trailer_recvbuf = Curl_add_buffer_init();
+ if(!stream->trailer_recvbuf) {
+ return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
+ }
}
-
return 0;
}
@@ -832,6 +944,7 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
struct Curl_easy *data_s;
int32_t stream_id = frame->hd.stream_id;
struct connectdata *conn = (struct connectdata *)userp;
+ CURLcode result;
(void)flags;
DEBUGASSERT(stream_id); /* should never be a zero stream ID here */
@@ -854,10 +967,34 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
if(frame->hd.type == NGHTTP2_PUSH_PROMISE) {
char *h;
+ if(!strcmp(":authority", (const char *)name)) {
+ /* pseudo headers are lower case */
+ int rc = 0;
+ char *check = aprintf("%s:%d", conn->host.name, conn->remote_port);
+ if(!check)
+ /* no memory */
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ if(!Curl_strcasecompare(check, (const char *)value)) {
+ /* This is push is not for the same authority that was asked for in
+ * the URL. RFC 7540 section 8.2 says: "A client MUST treat a
+ * PUSH_PROMISE for which the server is not authoritative as a stream
+ * error of type PROTOCOL_ERROR."
+ */
+ (void)nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE,
+ stream_id, NGHTTP2_PROTOCOL_ERROR);
+ rc = NGHTTP2_ERR_CALLBACK_FAILURE;
+ }
+ free(check);
+ if(rc)
+ return rc;
+ }
+
if(!stream->push_headers) {
stream->push_headers_alloc = 10;
stream->push_headers = malloc(stream->push_headers_alloc *
sizeof(char *));
+ if(!stream->push_headers)
+ return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
stream->push_headers_used = 0;
}
else if(stream->push_headers_used ==
@@ -880,17 +1017,27 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
if(stream->bodystarted) {
/* This is trailer fields. */
- /* 3 is for ":" and "\r\n". */
- uint32_t n = (uint32_t)(namelen + valuelen + 3);
+ /* 4 is for ": " and "\r\n". */
+ uint32_t n = (uint32_t)(namelen + valuelen + 4);
- DEBUGF(infof(data_s, "h2 trailer: %.*s: %.*s\n", namelen, name, valuelen,
+ H2BUGF(infof(data_s, "h2 trailer: %.*s: %.*s\n", namelen, name, valuelen,
value));
- Curl_add_buffer(stream->trailer_recvbuf, &n, sizeof(n));
- Curl_add_buffer(stream->trailer_recvbuf, name, namelen);
- Curl_add_buffer(stream->trailer_recvbuf, ": ", 2);
- Curl_add_buffer(stream->trailer_recvbuf, value, valuelen);
- Curl_add_buffer(stream->trailer_recvbuf, "\r\n\0", 3);
+ result = Curl_add_buffer(&stream->trailer_recvbuf, &n, sizeof(n));
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->trailer_recvbuf, name, namelen);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->trailer_recvbuf, ": ", 2);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->trailer_recvbuf, value, valuelen);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->trailer_recvbuf, "\r\n\0", 3);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
return 0;
}
@@ -903,15 +1050,21 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
stream->status_code = decode_status_code(value, valuelen);
DEBUGASSERT(stream->status_code != -1);
- Curl_add_buffer(stream->header_recvbuf, "HTTP/2 ", 7);
- Curl_add_buffer(stream->header_recvbuf, value, valuelen);
+ result = Curl_add_buffer(&stream->header_recvbuf, "HTTP/2 ", 7);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->header_recvbuf, value, valuelen);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
/* the space character after the status code is mandatory */
- Curl_add_buffer(stream->header_recvbuf, " \r\n", 3);
+ result = Curl_add_buffer(&stream->header_recvbuf, " \r\n", 3);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
/* if we receive data for another handle, wake that up */
if(conn->data != data_s)
Curl_expire(data_s, 0, EXPIRE_RUN_NOW);
- DEBUGF(infof(data_s, "h2 status: HTTP/2 %03d (easy %p)\n",
+ H2BUGF(infof(data_s, "h2 status: HTTP/2 %03d (easy %p)\n",
stream->status_code, data_s));
return 0;
}
@@ -919,15 +1072,23 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
/* nghttp2 guarantees that namelen > 0, and :status was already
received, and this is not pseudo-header field . */
/* convert to a HTTP1-style header */
- Curl_add_buffer(stream->header_recvbuf, name, namelen);
- Curl_add_buffer(stream->header_recvbuf, ": ", 2);
- Curl_add_buffer(stream->header_recvbuf, value, valuelen);
- Curl_add_buffer(stream->header_recvbuf, "\r\n", 2);
+ result = Curl_add_buffer(&stream->header_recvbuf, name, namelen);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->header_recvbuf, ": ", 2);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->header_recvbuf, value, valuelen);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
+ result = Curl_add_buffer(&stream->header_recvbuf, "\r\n", 2);
+ if(result)
+ return NGHTTP2_ERR_CALLBACK_FAILURE;
/* if we receive data for another handle, wake that up */
if(conn->data != data_s)
Curl_expire(data_s, 0, EXPIRE_RUN_NOW);
- DEBUGF(infof(data_s, "h2 header: %.*s: %.*s\n", namelen, name, valuelen,
+ H2BUGF(infof(data_s, "h2 header: %.*s: %.*s\n", namelen, name, valuelen,
value));
return 0; /* 0 is successful */
@@ -962,7 +1123,7 @@ static ssize_t data_source_read_callback(nghttp2_session *session,
else
return NGHTTP2_ERR_INVALID_ARGUMENT;
- nread = MIN(stream->upload_len, length);
+ nread = CURLMIN(stream->upload_len, length);
if(nread > 0) {
memcpy(buf, stream->upload_mem, nread);
stream->upload_mem += nread;
@@ -976,16 +1137,15 @@ static ssize_t data_source_read_callback(nghttp2_session *session,
else if(nread == 0)
return NGHTTP2_ERR_DEFERRED;
- DEBUGF(infof(data_s, "data_source_read_callback: "
+ H2BUGF(infof(data_s, "data_source_read_callback: "
"returns %zu bytes stream %u\n",
nread, stream_id));
return nread;
}
-#define H2_BUFSIZE 32768
-
-#ifdef NGHTTP2_HAS_ERROR_CALLBACK
+#if defined(NGHTTP2_HAS_ERROR_CALLBACK) && \
+ !defined(CURL_DISABLE_VERBOSE_STRINGS)
static int error_callback(nghttp2_session *session,
const char *msg,
size_t len,
@@ -1021,12 +1181,11 @@ void Curl_http2_done(struct connectdata *conn, bool premature)
struct HTTP *http = data->req.protop;
struct http_conn *httpc = &conn->proto.httpc;
+ /* there might be allocated resources done before this got the 'h2' pointer
+ setup */
if(http->header_recvbuf) {
- DEBUGF(infof(data, "free header_recvbuf!!\n"));
- Curl_add_buffer_free(http->header_recvbuf);
- http->header_recvbuf = NULL; /* clear the pointer */
- Curl_add_buffer_free(http->trailer_recvbuf);
- http->trailer_recvbuf = NULL; /* clear the pointer */
+ Curl_add_buffer_free(&http->header_recvbuf);
+ Curl_add_buffer_free(&http->trailer_recvbuf);
if(http->push_headers) {
/* if they weren't used and then freed before */
for(; http->push_headers_used > 0; --http->push_headers_used) {
@@ -1037,17 +1196,32 @@ void Curl_http2_done(struct connectdata *conn, bool premature)
}
}
+ if(!httpc->h2) /* not HTTP/2 ? */
+ return;
+
+ if(data->state.drain)
+ drained_transfer(data, httpc);
+
if(premature) {
/* RST_STREAM */
- nghttp2_submit_rst_stream(httpc->h2, NGHTTP2_FLAG_NONE, http->stream_id,
- NGHTTP2_STREAM_CLOSED);
+ if(!nghttp2_submit_rst_stream(httpc->h2, NGHTTP2_FLAG_NONE,
+ http->stream_id, NGHTTP2_STREAM_CLOSED))
+ (void)nghttp2_session_send(httpc->h2);
+
if(http->stream_id == httpc->pause_stream_id) {
infof(data, "stopped the pause stream!\n");
httpc->pause_stream_id = 0;
}
}
- if(http->stream_id) {
- nghttp2_session_set_stream_user_data(httpc->h2, http->stream_id, 0);
+ /* -1 means unassigned and 0 means cleared */
+ if(http->stream_id > 0) {
+ int rv = nghttp2_session_set_stream_user_data(httpc->h2,
+ http->stream_id, 0);
+ if(rv) {
+ infof(data, "http/2: failed to clear user_data for stream %d!\n",
+ http->stream_id);
+ DEBUGASSERT(0);
+ }
http->stream_id = 0;
}
}
@@ -1055,7 +1229,7 @@ void Curl_http2_done(struct connectdata *conn, bool premature)
/*
* Initialize nghttp2 for a Curl connection
*/
-CURLcode Curl_http2_init(struct connectdata *conn)
+static CURLcode http2_init(struct connectdata *conn)
{
if(!conn->proto.httpc.h2) {
int rc;
@@ -1077,21 +1251,9 @@ CURLcode Curl_http2_init(struct connectdata *conn)
/* nghttp2_on_frame_recv_callback */
nghttp2_session_callbacks_set_on_frame_recv_callback
(callbacks, on_frame_recv);
- /* nghttp2_on_invalid_frame_recv_callback */
- nghttp2_session_callbacks_set_on_invalid_frame_recv_callback
- (callbacks, on_invalid_frame_recv);
/* nghttp2_on_data_chunk_recv_callback */
nghttp2_session_callbacks_set_on_data_chunk_recv_callback
(callbacks, on_data_chunk_recv);
- /* nghttp2_before_frame_send_callback */
- nghttp2_session_callbacks_set_before_frame_send_callback
- (callbacks, before_frame_send);
- /* nghttp2_on_frame_send_callback */
- nghttp2_session_callbacks_set_on_frame_send_callback
- (callbacks, on_frame_send);
- /* nghttp2_on_frame_not_send_callback */
- nghttp2_session_callbacks_set_on_frame_not_send_callback
- (callbacks, on_frame_not_send);
/* nghttp2_on_stream_close_callback */
nghttp2_session_callbacks_set_on_stream_close_callback
(callbacks, on_stream_close);
@@ -1101,7 +1263,9 @@ CURLcode Curl_http2_init(struct connectdata *conn)
/* nghttp2_on_header_callback */
nghttp2_session_callbacks_set_on_header_callback(callbacks, on_header);
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
nghttp2_session_callbacks_set_error_callback(callbacks, error_callback);
+#endif
/* The nghttp2 session is not yet setup, do it */
rc = nghttp2_session_client_new(&conn->proto.httpc.h2, callbacks, conn);
@@ -1138,16 +1302,19 @@ CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
httpc->local_settings_num);
if(!binlen) {
failf(conn->data, "nghttp2 unexpectedly failed on pack_settings_payload");
+ Curl_add_buffer_free(&req);
return CURLE_FAILED_INIT;
}
conn->proto.httpc.binlen = binlen;
result = Curl_base64url_encode(conn->data, (const char *)binsettings, binlen,
&base64, &blen);
- if(result)
+ if(result) {
+ Curl_add_buffer_free(&req);
return result;
+ }
- result = Curl_add_bufferf(req,
+ result = Curl_add_bufferf(&req,
"Connection: Upgrade, HTTP2-Settings\r\n"
"Upgrade: %s\r\n"
"HTTP2-Settings: %s\r\n",
@@ -1168,22 +1335,20 @@ static int should_close_session(struct http_conn *httpc)
!nghttp2_session_want_write(httpc->h2);
}
-static int h2_session_send(struct Curl_easy *data,
- nghttp2_session *h2);
-
/*
* h2_process_pending_input() processes pending input left in
* httpc->inbuf. Then, call h2_session_send() to send pending data.
* This function returns 0 if it succeeds, or -1 and error code will
* be assigned to *err.
*/
-static int h2_process_pending_input(struct Curl_easy *data,
+static int h2_process_pending_input(struct connectdata *conn,
struct http_conn *httpc,
CURLcode *err)
{
ssize_t nread;
char *inbuf;
ssize_t rv;
+ struct Curl_easy *data = conn->data;
nread = httpc->inbuflen - httpc->nread_inbuf;
inbuf = httpc->inbuf + httpc->nread_inbuf;
@@ -1192,13 +1357,13 @@ static int h2_process_pending_input(struct Curl_easy *data,
if(rv < 0) {
failf(data,
"h2_process_pending_input: nghttp2_session_mem_recv() returned "
- "%d:%s\n", rv, nghttp2_strerror((int)rv));
+ "%zd:%s\n", rv, nghttp2_strerror((int)rv));
*err = CURLE_RECV_ERROR;
return -1;
}
if(nread == rv) {
- DEBUGF(infof(data,
+ H2BUGF(infof(data,
"h2_process_pending_input: All data in connection buffer "
"processed\n"));
httpc->inbuflen = 0;
@@ -1206,7 +1371,7 @@ static int h2_process_pending_input(struct Curl_easy *data,
}
else {
httpc->nread_inbuf += rv;
- DEBUGF(infof(data,
+ H2BUGF(infof(data,
"h2_process_pending_input: %zu bytes left in connection "
"buffer\n",
httpc->inbuflen - httpc->nread_inbuf));
@@ -1219,9 +1384,15 @@ static int h2_process_pending_input(struct Curl_easy *data,
}
if(should_close_session(httpc)) {
- DEBUGF(infof(data,
+ H2BUGF(infof(data,
"h2_process_pending_input: nothing to do in this session\n"));
- *err = CURLE_HTTP2;
+ if(httpc->error_code)
+ *err = CURLE_HTTP2;
+ else {
+ /* not an error per se, but should still close the connection */
+ connclose(conn, "GOAWAY received");
+ *err = CURLE_OK;
+ }
return -1;
}
@@ -1252,13 +1423,12 @@ CURLcode Curl_http2_done_sending(struct connectdata *conn)
that it can signal EOF to nghttp2 */
(void)nghttp2_session_resume_data(h2, stream->stream_id);
- (void)h2_process_pending_input(conn->data, httpc, &result);
+ (void)h2_process_pending_input(conn, httpc, &result);
}
}
return result;
}
-
static ssize_t http2_handle_stream_close(struct connectdata *conn,
struct Curl_easy *data,
struct HTTP *stream, CURLcode *err)
@@ -1271,12 +1441,10 @@ static ssize_t http2_handle_stream_close(struct connectdata *conn,
httpc->pause_stream_id = 0;
}
- DEBUGASSERT(httpc->drain_total >= data->state.drain);
- httpc->drain_total -= data->state.drain;
- data->state.drain = 0;
+ drained_transfer(data, httpc);
if(httpc->pause_stream_id == 0) {
- if(h2_process_pending_input(data, httpc, err) != 0) {
+ if(h2_process_pending_input(conn, httpc, err) != 0) {
return -1;
}
}
@@ -1285,17 +1453,25 @@ static ssize_t http2_handle_stream_close(struct connectdata *conn,
/* Reset to FALSE to prevent infinite loop in readwrite_data function. */
stream->closed = FALSE;
- if(stream->error_code != NGHTTP2_NO_ERROR) {
- failf(data, "HTTP/2 stream %u was not closed cleanly: %s (err %d)",
- stream->stream_id, Curl_http2_strerror(stream->error_code),
- stream->error_code);
+ if(httpc->error_code == NGHTTP2_REFUSED_STREAM) {
+ H2BUGF(infof(data, "REFUSED_STREAM (%d), try again on a new connection!\n",
+ stream->stream_id));
+ connclose(conn, "REFUSED_STREAM"); /* don't use this anymore */
+ data->state.refused_stream = TRUE;
+ *err = CURLE_RECV_ERROR; /* trigger Curl_retry_request() later */
+ return -1;
+ }
+ else if(httpc->error_code != NGHTTP2_NO_ERROR) {
+ failf(data, "HTTP/2 stream %d was not closed cleanly: %s (err %u)",
+ stream->stream_id, http2_strerror(httpc->error_code),
+ httpc->error_code);
*err = CURLE_HTTP2_STREAM;
return -1;
}
if(!stream->bodystarted) {
- failf(data, "HTTP/2 stream %u was closed cleanly, but before getting "
- " all response header fields, teated as error",
+ failf(data, "HTTP/2 stream %d was closed cleanly, but before getting "
+ " all response header fields, treated as error",
stream->stream_id);
*err = CURLE_HTTP2_STREAM;
return -1;
@@ -1322,7 +1498,7 @@ static ssize_t http2_handle_stream_close(struct connectdata *conn,
stream->close_handled = TRUE;
- DEBUGF(infof(data, "http2_recv returns 0, http2_handle_stream_close\n"));
+ H2BUGF(infof(data, "http2_recv returns 0, http2_handle_stream_close\n"));
return 0;
}
@@ -1363,7 +1539,7 @@ static int h2_session_send(struct Curl_easy *data,
h2_pri_spec(data, &pri_spec);
- DEBUGF(infof(data, "Queuing PRIORITY on stream %u (easy %p)\n",
+ H2BUGF(infof(data, "Queuing PRIORITY on stream %u (easy %p)\n",
stream->stream_id, data));
rv = nghttp2_submit_priority(h2, NGHTTP2_FLAG_NONE, stream->stream_id,
&pri_spec);
@@ -1387,7 +1563,7 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
(void)sockindex; /* we always do HTTP2 on sockindex 0 */
if(should_close_session(httpc)) {
- DEBUGF(infof(data,
+ H2BUGF(infof(data,
"http2_recv: nothing to do in this session\n"));
*err = CURLE_HTTP2;
return -1;
@@ -1408,21 +1584,21 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
/* If there is body data pending for this stream to return, do that */
size_t left =
stream->header_recvbuf->size_used - stream->nread_header_recvbuf;
- size_t ncopy = MIN(len, left);
+ size_t ncopy = CURLMIN(len, left);
memcpy(mem, stream->header_recvbuf->buffer + stream->nread_header_recvbuf,
ncopy);
stream->nread_header_recvbuf += ncopy;
- DEBUGF(infof(data, "http2_recv: Got %d bytes from header_recvbuf\n",
+ H2BUGF(infof(data, "http2_recv: Got %d bytes from header_recvbuf\n",
(int)ncopy));
return ncopy;
}
- DEBUGF(infof(data, "http2_recv: easy %p (stream %u)\n",
+ H2BUGF(infof(data, "http2_recv: easy %p (stream %u)\n",
data, stream->stream_id));
if((data->state.drain) && stream->memlen) {
- DEBUGF(infof(data, "http2_recv: DRAIN %zu bytes stream %u!! (%p => %p)\n",
+ H2BUGF(infof(data, "http2_recv: DRAIN %zu bytes stream %u!! (%p => %p)\n",
stream->memlen, stream->stream_id,
stream->mem, mem));
if(mem != stream->mem) {
@@ -1436,7 +1612,7 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
/* We have paused nghttp2, but we have no pause data (see
on_data_chunk_recv). */
httpc->pause_stream_id = 0;
- if(h2_process_pending_input(data, httpc, &result) != 0) {
+ if(h2_process_pending_input(conn, httpc, &result) != 0) {
*err = result;
return -1;
}
@@ -1444,15 +1620,15 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
}
else if(stream->pausedata) {
DEBUGASSERT(httpc->pause_stream_id == stream->stream_id);
- nread = MIN(len, stream->pauselen);
+ nread = CURLMIN(len, stream->pauselen);
memcpy(mem, stream->pausedata, nread);
stream->pausedata += nread;
stream->pauselen -= nread;
- infof(data, "%zu data bytes written\n", nread);
+ infof(data, "%zd data bytes written\n", nread);
if(stream->pauselen == 0) {
- DEBUGF(infof(data, "Unpaused by stream %u\n", stream->stream_id));
+ H2BUGF(infof(data, "Unpaused by stream %u\n", stream->stream_id));
DEBUGASSERT(httpc->pause_stream_id == stream->stream_id);
httpc->pause_stream_id = 0;
@@ -1466,12 +1642,12 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
frames, then we have to call it again with 0-length data.
Without this, on_stream_close callback will not be called,
and stream could be hanged. */
- if(h2_process_pending_input(data, httpc, &result) != 0) {
+ if(h2_process_pending_input(conn, httpc, &result) != 0) {
*err = result;
return -1;
}
}
- DEBUGF(infof(data, "http2_recv: returns unpaused %zd bytes on stream %u\n",
+ H2BUGF(infof(data, "http2_recv: returns unpaused %zd bytes on stream %u\n",
nread, stream->stream_id));
return nread;
}
@@ -1484,7 +1660,7 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
socket is not read. But it seems that usually streams are
notified with its drain property, and socket is read again
quickly. */
- DEBUGF(infof(data, "stream %x is paused, pause id: %x\n",
+ H2BUGF(infof(data, "stream %x is paused, pause id: %x\n",
stream->stream_id, httpc->pause_stream_id));
*err = CURLE_AGAIN;
return -1;
@@ -1513,12 +1689,12 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
}
if(nread == 0) {
- failf(data, "Unexpected EOF");
- *err = CURLE_RECV_ERROR;
- return -1;
+ H2BUGF(infof(data, "end of stream\n"));
+ *err = CURLE_OK;
+ return 0;
}
- DEBUGF(infof(data, "nread=%zd\n", nread));
+ H2BUGF(infof(data, "nread=%zd\n", nread));
httpc->inbuflen = nread;
inbuf = httpc->inbuf;
@@ -1527,26 +1703,26 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
nread = httpc->inbuflen - httpc->nread_inbuf;
inbuf = httpc->inbuf + httpc->nread_inbuf;
- DEBUGF(infof(data, "Use data left in connection buffer, nread=%zd\n",
+ H2BUGF(infof(data, "Use data left in connection buffer, nread=%zd\n",
nread));
}
rv = nghttp2_session_mem_recv(httpc->h2, (const uint8_t *)inbuf, nread);
if(nghttp2_is_fatal((int)rv)) {
- failf(data, "nghttp2_session_mem_recv() returned %d:%s\n",
+ failf(data, "nghttp2_session_mem_recv() returned %zd:%s\n",
rv, nghttp2_strerror((int)rv));
*err = CURLE_RECV_ERROR;
- return 0;
+ return -1;
}
- DEBUGF(infof(data, "nghttp2_session_mem_recv() returns %zd\n", rv));
+ H2BUGF(infof(data, "nghttp2_session_mem_recv() returns %zd\n", rv));
if(nread == rv) {
- DEBUGF(infof(data, "All data in connection buffer processed\n"));
+ H2BUGF(infof(data, "All data in connection buffer processed\n"));
httpc->inbuflen = 0;
httpc->nread_inbuf = 0;
}
else {
httpc->nread_inbuf += rv;
- DEBUGF(infof(data, "%zu bytes left in connection buffer\n",
+ H2BUGF(infof(data, "%zu bytes left in connection buffer\n",
httpc->inbuflen - httpc->nread_inbuf));
}
/* Always send pending frames in nghttp2 session, because
@@ -1554,31 +1730,29 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
rv = h2_session_send(data, httpc->h2);
if(rv != 0) {
*err = CURLE_SEND_ERROR;
- return 0;
+ return -1;
}
if(should_close_session(httpc)) {
- DEBUGF(infof(data, "http2_recv: nothing to do in this session\n"));
+ H2BUGF(infof(data, "http2_recv: nothing to do in this session\n"));
*err = CURLE_HTTP2;
return -1;
}
}
if(stream->memlen) {
ssize_t retlen = stream->memlen;
- DEBUGF(infof(data, "http2_recv: returns %zd for stream %u\n",
+ H2BUGF(infof(data, "http2_recv: returns %zd for stream %u\n",
retlen, stream->stream_id));
stream->memlen = 0;
if(httpc->pause_stream_id == stream->stream_id) {
/* data for this stream is returned now, but this stream caused a pause
already so we need it called again asap */
- DEBUGF(infof(data, "Data returned for PAUSED stream %u\n",
+ H2BUGF(infof(data, "Data returned for PAUSED stream %u\n",
stream->stream_id));
}
else if(!stream->closed) {
- DEBUGASSERT(httpc->drain_total >= data->state.drain);
- httpc->drain_total -= data->state.drain;
- data->state.drain = 0; /* this stream is hereby drained */
+ drained_transfer(data, httpc);
}
return retlen;
@@ -1589,7 +1763,7 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
return http2_handle_stream_close(conn, data, stream, err);
}
*err = CURLE_AGAIN;
- DEBUGF(infof(data, "http2_recv returns AGAIN for stream %u\n",
+ H2BUGF(infof(data, "http2_recv returns AGAIN for stream %u\n",
stream->stream_id));
return -1;
}
@@ -1671,9 +1845,9 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
const void *mem, size_t len, CURLcode *err)
{
/*
- * BIG TODO: Currently, we send request in this function, but this
- * function is also used to send request body. It would be nice to
- * add dedicated function for request.
+ * Currently, we send request in this function, but this function is also
+ * used to send request body. It would be nice to add dedicated function for
+ * request.
*/
int rv;
struct http_conn *httpc = &conn->proto.httpc;
@@ -1691,7 +1865,7 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
(void)sockindex;
- DEBUGF(infof(conn->data, "http2_send len=%zu\n", len));
+ H2BUGF(infof(conn->data, "http2_send len=%zu\n", len));
if(stream->stream_id != -1) {
if(stream->close_handled) {
@@ -1720,7 +1894,7 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
stream->upload_len = 0;
if(should_close_session(httpc)) {
- DEBUGF(infof(conn->data, "http2_send: nothing to do in this session\n"));
+ H2BUGF(infof(conn->data, "http2_send: nothing to do in this session\n"));
*err = CURLE_HTTP2;
return -1;
}
@@ -1733,7 +1907,7 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
nghttp2_session_resume_data(h2, stream->stream_id);
}
- DEBUGF(infof(conn->data, "http2_send returns %zu for stream %u\n", len,
+ H2BUGF(infof(conn->data, "http2_send returns %zu for stream %u\n", len,
stream->stream_id));
return len;
}
@@ -1761,8 +1935,11 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
return -1;
}
- /* Extract :method, :path from request line */
- line_end = strstr(hdbuf, "\r\n");
+ /* Extract :method, :path from request line
+ We do line endings with CRLF so checking for CR is enough */
+ line_end = memchr(hdbuf, '\r', len);
+ if(!line_end)
+ goto fail;
/* Method does not contain spaces */
end = memchr(hdbuf, ' ', line_end - hdbuf);
@@ -1800,9 +1977,6 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
goto fail;
}
- hdbuf = end + 1;
-
- end = line_end;
nva[2].name = (unsigned char *)":scheme";
nva[2].namelen = strlen((char *)nva[2].name);
if(conn->handler->flags & PROTOPT_SSL)
@@ -1823,8 +1997,10 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
hdbuf = line_end + 2;
- line_end = strstr(hdbuf, "\r\n");
- if(line_end == hdbuf)
+ /* check for next CR, but only within the piece of data left in the given
+ buffer */
+ line_end = memchr(hdbuf, '\r', len - (hdbuf - (char *)mem));
+ if(!line_end || (line_end == hdbuf))
goto fail;
/* header continuation lines are not supported */
@@ -1892,7 +2068,7 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
for(i = 0; i < nheader; ++i) {
acc += nva[i].namelen + nva[i].valuelen;
- DEBUGF(infof(conn->data, "h2 header: %.*s:%.*s\n",
+ H2BUGF(infof(conn->data, "h2 header: %.*s:%.*s\n",
nva[i].namelen, nva[i].name,
nva[i].valuelen, nva[i].value));
}
@@ -1909,6 +2085,7 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
switch(conn->data->set.httpreq) {
case HTTPREQ_POST:
case HTTPREQ_POST_FORM:
+ case HTTPREQ_POST_MIME:
case HTTPREQ_PUT:
if(conn->data->state.infilesize != -1)
stream->upload_left = conn->data->state.infilesize;
@@ -1929,13 +2106,13 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
Curl_safefree(nva);
if(stream_id < 0) {
- DEBUGF(infof(conn->data, "http2_send() send error\n"));
+ H2BUGF(infof(conn->data, "http2_send() send error\n"));
*err = CURLE_SEND_ERROR;
return -1;
}
infof(conn->data, "Using Stream ID: %x (easy handle %p)\n",
- stream_id, conn->data);
+ stream_id, (void *)conn->data);
stream->stream_id = stream_id;
/* this does not call h2_session_send() since there can not have been any
@@ -1948,7 +2125,7 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
}
if(should_close_session(httpc)) {
- DEBUGF(infof(conn->data, "http2_send: nothing to do in this session\n"));
+ H2BUGF(infof(conn->data, "http2_send: nothing to do in this session\n"));
*err = CURLE_HTTP2;
return -1;
}
@@ -1981,8 +2158,11 @@ CURLcode Curl_http2_setup(struct connectdata *conn)
stream->stream_id = -1;
- if(!stream->header_recvbuf)
+ if(!stream->header_recvbuf) {
stream->header_recvbuf = Curl_add_buffer_init();
+ if(!stream->header_recvbuf)
+ return CURLE_OUT_OF_MEMORY;
+ }
if((conn->handler == &Curl_handler_http2_ssl) ||
(conn->handler == &Curl_handler_http2))
@@ -1993,9 +2173,11 @@ CURLcode Curl_http2_setup(struct connectdata *conn)
else
conn->handler = &Curl_handler_http2;
- result = Curl_http2_init(conn);
- if(result)
+ result = http2_init(conn);
+ if(result) {
+ Curl_add_buffer_free(&stream->header_recvbuf);
return result;
+ }
infof(conn->data, "Using HTTP2, server supports multi-use\n");
stream->upload_left = 0;
@@ -2013,7 +2195,7 @@ CURLcode Curl_http2_setup(struct connectdata *conn)
conn->bundle->multiuse = BUNDLE_MULTIPLEX;
infof(conn->data, "Connection state changed (HTTP/2 confirmed)\n");
- Curl_multi_connchanged(conn->data->multi);
+ multi_connchanged(conn->data->multi);
return CURLE_OK;
}
@@ -2032,8 +2214,8 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
if(result)
return result;
- httpc->recv_underlying = (recving)conn->recv[FIRSTSOCKET];
- httpc->send_underlying = (sending)conn->send[FIRSTSOCKET];
+ httpc->recv_underlying = conn->recv[FIRSTSOCKET];
+ httpc->send_underlying = conn->send[FIRSTSOCKET];
conn->recv[FIRSTSOCKET] = http2_recv;
conn->send[FIRSTSOCKET] = http2_send;
@@ -2049,9 +2231,14 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
return CURLE_HTTP2;
}
- nghttp2_session_set_stream_user_data(httpc->h2,
- stream->stream_id,
- conn->data);
+ rv = nghttp2_session_set_stream_user_data(httpc->h2,
+ stream->stream_id,
+ data);
+ if(rv) {
+ infof(data, "http/2: failed to set user_data for stream %d!\n",
+ stream->stream_id);
+ DEBUGASSERT(0);
+ }
}
else {
populate_settings(conn, httpc);
@@ -2106,7 +2293,7 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
return CURLE_HTTP2;
}
- DEBUGF(infof(data, "nghttp2_session_mem_recv() returns %zd\n", nproc));
+ H2BUGF(infof(data, "nghttp2_session_mem_recv() returns %zd\n", nproc));
if((ssize_t)nread == nproc) {
httpc->inbuflen = 0;
@@ -2126,7 +2313,7 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
}
if(should_close_session(httpc)) {
- DEBUGF(infof(data,
+ H2BUGF(infof(data,
"nghttp2_session_send(): nothing to do in this session\n"));
return CURLE_HTTP2;
}
@@ -2134,12 +2321,15 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
return CURLE_OK;
}
-void Curl_http2_add_child(struct Curl_easy *parent, struct Curl_easy *child,
- bool exclusive)
+CURLcode Curl_http2_add_child(struct Curl_easy *parent,
+ struct Curl_easy *child,
+ bool exclusive)
{
if(parent) {
struct Curl_http2_dep **tail;
struct Curl_http2_dep *dep = calloc(1, sizeof(struct Curl_http2_dep));
+ if(!dep)
+ return CURLE_OUT_OF_MEMORY;
dep->data = child;
if(parent->set.stream_dependents && exclusive) {
@@ -2170,6 +2360,7 @@ void Curl_http2_add_child(struct Curl_easy *parent, struct Curl_easy *child,
child->set.stream_depends_on = parent;
child->set.stream_depends_e = exclusive;
+ return CURLE_OK;
}
void Curl_http2_remove_child(struct Curl_easy *parent, struct Curl_easy *child)
@@ -2212,6 +2403,14 @@ void Curl_http2_cleanup_dependencies(struct Curl_easy *data)
Curl_http2_remove_child(data->set.stream_depends_on, data);
}
+/* Only call this function for a transfer that already got a HTTP/2
+ CURLE_HTTP2_STREAM error! */
+bool Curl_h2_http_1_1_error(struct connectdata *conn)
+{
+ struct http_conn *httpc = &conn->proto.httpc;
+ return (httpc->error_code == NGHTTP2_HTTP_1_1_REQUIRED);
+}
+
#else /* !USE_NGHTTP2 */
/* Satisfy external references even if http2 is not compiled in. */
diff --git a/Utilities/cmcurl/lib/http2.h b/Utilities/cmcurl/lib/http2.h
index f405b3aeb..db6217b11 100644
--- a/Utilities/cmcurl/lib/http2.h
+++ b/Utilities/cmcurl/lib/http2.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -53,18 +53,21 @@ void Curl_http2_setup_conn(struct connectdata *conn);
void Curl_http2_setup_req(struct Curl_easy *data);
void Curl_http2_done(struct connectdata *conn, bool premature);
CURLcode Curl_http2_done_sending(struct connectdata *conn);
-void Curl_http2_add_child(struct Curl_easy *parent, struct Curl_easy *child,
- bool exclusive);
+CURLcode Curl_http2_add_child(struct Curl_easy *parent,
+ struct Curl_easy *child,
+ bool exclusive);
void Curl_http2_remove_child(struct Curl_easy *parent,
struct Curl_easy *child);
void Curl_http2_cleanup_dependencies(struct Curl_easy *data);
+
+/* returns true if the HTTP/2 stream error was HTTP_1_1_REQUIRED */
+bool Curl_h2_http_1_1_error(struct connectdata *conn);
#else /* USE_NGHTTP2 */
-#define Curl_http2_init(x) CURLE_UNSUPPORTED_PROTOCOL
#define Curl_http2_send_request(x) CURLE_UNSUPPORTED_PROTOCOL
#define Curl_http2_request_upgrade(x,y) CURLE_UNSUPPORTED_PROTOCOL
#define Curl_http2_setup(x) CURLE_UNSUPPORTED_PROTOCOL
#define Curl_http2_switched(x,y,z) CURLE_UNSUPPORTED_PROTOCOL
-#define Curl_http2_setup_conn(x)
+#define Curl_http2_setup_conn(x) Curl_nop_stmt
#define Curl_http2_setup_req(x)
#define Curl_http2_init_state(x)
#define Curl_http2_init_userset(x)
@@ -73,7 +76,7 @@ void Curl_http2_cleanup_dependencies(struct Curl_easy *data);
#define Curl_http2_add_child(x, y, z)
#define Curl_http2_remove_child(x, y)
#define Curl_http2_cleanup_dependencies(x)
+#define Curl_h2_http_1_1_error(x) 0
#endif
#endif /* HEADER_CURL_HTTP2_H */
-
diff --git a/Utilities/cmcurl/lib/http_chunks.c b/Utilities/cmcurl/lib/http_chunks.c
index 1bdf6974c..18dfcb282 100644
--- a/Utilities/cmcurl/lib/http_chunks.c
+++ b/Utilities/cmcurl/lib/http_chunks.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -74,20 +74,24 @@
*/
+#ifdef CURL_DOES_CONVERSIONS
/* Check for an ASCII hex digit.
- We avoid the use of isxdigit to accommodate non-ASCII hosts. */
-static bool Curl_isxdigit(char digit)
+ We avoid the use of ISXDIGIT to accommodate non-ASCII hosts. */
+static bool Curl_isxdigit_ascii(char digit)
{
- return ( (digit >= 0x30 && digit <= 0x39) /* 0-9 */
+ return (digit >= 0x30 && digit <= 0x39) /* 0-9 */
|| (digit >= 0x41 && digit <= 0x46) /* A-F */
- || (digit >= 0x61 && digit <= 0x66) /* a-f */) ? TRUE : FALSE;
+ || (digit >= 0x61 && digit <= 0x66); /* a-f */
}
+#else
+#define Curl_isxdigit_ascii(x) Curl_isxdigit(x)
+#endif
void Curl_httpchunk_init(struct connectdata *conn)
{
struct Curl_chunker *chunk = &conn->chunk;
- chunk->hexindex=0; /* start at 0 */
- chunk->dataleft=0; /* no data left yet! */
+ chunk->hexindex = 0; /* start at 0 */
+ chunk->dataleft = 0; /* no data left yet! */
chunk->state = CHUNK_HEX; /* we get hex first! */
}
@@ -107,7 +111,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
ssize_t datalen,
ssize_t *wrotep)
{
- CURLcode result=CURLE_OK;
+ CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
struct Curl_chunker *ch = &conn->chunk;
struct SingleRequest *k = &data->req;
@@ -128,7 +132,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
while(length) {
switch(ch->state) {
case CHUNK_HEX:
- if(Curl_isxdigit(*datap)) {
+ if(Curl_isxdigit_ascii(*datap)) {
if(ch->hexindex < MAXNUM_SIZE) {
ch->hexbuffer[ch->hexindex] = *datap;
datap++;
@@ -147,7 +151,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
return CHUNKE_ILLEGAL_HEX;
/* length and datap are unmodified */
- ch->hexbuffer[ch->hexindex]=0;
+ ch->hexbuffer[ch->hexindex] = 0;
/* convert to host encoding before calling strtoul */
result = Curl_convert_from_network(conn->data, ch->hexbuffer,
@@ -158,9 +162,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
return CHUNKE_ILLEGAL_HEX;
}
- ch->datasize=curlx_strtoofft(ch->hexbuffer, &endptr, 16);
- if((ch->datasize == CURL_OFF_T_MAX) && (errno == ERANGE))
- /* overflow is an error */
+ if(curlx_strtoofft(ch->hexbuffer, &endptr, 16, &ch->datasize))
return CHUNKE_ILLEGAL_HEX;
ch->state = CHUNK_LF; /* now wait for the CRLF */
}
@@ -172,7 +174,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
/* we're now expecting data to come, unless size was zero! */
if(0 == ch->datasize) {
ch->state = CHUNK_TRAILER; /* now check for trailers */
- conn->trlPos=0;
+ conn->trlPos = 0;
}
else
ch->state = CHUNK_DATA;
@@ -189,49 +191,17 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
piece = curlx_sotouz((ch->datasize >= length)?length:ch->datasize);
/* Write the data portion available */
-#ifdef HAVE_LIBZ
- switch(conn->data->set.http_ce_skip?
- IDENTITY : data->req.auto_decoding) {
- case IDENTITY:
-#endif
- if(!k->ignorebody) {
- if(!data->set.http_te_skip)
- result = Curl_client_write(conn, CLIENTWRITE_BODY, datap,
- piece);
- else
- result = CURLE_OK;
- }
-#ifdef HAVE_LIBZ
- break;
-
- case DEFLATE:
- /* update data->req.keep.str to point to the chunk data. */
- data->req.str = datap;
- result = Curl_unencode_deflate_write(conn, &data->req,
- (ssize_t)piece);
- break;
-
- case GZIP:
- /* update data->req.keep.str to point to the chunk data. */
- data->req.str = datap;
- result = Curl_unencode_gzip_write(conn, &data->req,
- (ssize_t)piece);
- break;
+ if(!conn->data->set.http_te_skip && !k->ignorebody) {
+ if(!conn->data->set.http_ce_skip && k->writer_stack)
+ result = Curl_unencode_write(conn, k->writer_stack, datap, piece);
+ else
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, datap, piece);
- default:
- failf(conn->data,
- "Unrecognized content encoding type. "
- "libcurl understands `identity', `deflate' and `gzip' "
- "content encodings.");
- return CHUNKE_BAD_ENCODING;
+ if(result)
+ return CHUNKE_WRITE_ERROR;
}
-#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 */
@@ -259,9 +229,9 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
if(conn->trlPos) {
/* we allocate trailer with 3 bytes extra room to fit this */
- conn->trailer[conn->trlPos++]=0x0d;
- conn->trailer[conn->trlPos++]=0x0a;
- conn->trailer[conn->trlPos]=0;
+ conn->trailer[conn->trlPos++] = 0x0d;
+ conn->trailer[conn->trlPos++] = 0x0a;
+ conn->trailer[conn->trlPos] = 0;
/* Convert to host encoding before calling Curl_client_write */
result = Curl_convert_from_network(conn->data, conn->trailer,
@@ -277,7 +247,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
if(result)
return CHUNKE_WRITE_ERROR;
}
- conn->trlPos=0;
+ conn->trlPos = 0;
ch->state = CHUNK_TRAILER_CR;
if(*datap == 0x0a)
/* already on the LF */
@@ -301,7 +271,7 @@ CHUNKcode Curl_httpchunk_read(struct connectdata *conn,
ptr = realloc(conn->trailer, conn->trlMax + 3);
}
else {
- conn->trlMax=128;
+ conn->trlMax = 128;
ptr = malloc(conn->trlMax + 3);
}
if(!ptr)
diff --git a/Utilities/cmcurl/lib/http_chunks.h b/Utilities/cmcurl/lib/http_chunks.h
index 3a8b4ddf3..b969c5590 100644
--- a/Utilities/cmcurl/lib/http_chunks.h
+++ b/Utilities/cmcurl/lib/http_chunks.h
@@ -88,4 +88,3 @@ struct Curl_chunker {
};
#endif /* HEADER_CURL_HTTP_CHUNKS_H */
-
diff --git a/Utilities/cmcurl/lib/http_digest.c b/Utilities/cmcurl/lib/http_digest.c
index e2d865b0a..9616c30ed 100644
--- a/Utilities/cmcurl/lib/http_digest.c
+++ b/Utilities/cmcurl/lib/http_digest.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -28,6 +28,7 @@
#include "strcase.h"
#include "vauth/vauth.h"
#include "http_digest.h"
+
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -171,7 +172,7 @@ CURLcode Curl_output_digest(struct connectdata *conn,
return CURLE_OK;
}
-void Curl_digest_cleanup(struct Curl_easy *data)
+void Curl_http_auth_cleanup_digest(struct Curl_easy *data)
{
Curl_auth_digest_cleanup(&data->state.digest);
Curl_auth_digest_cleanup(&data->state.proxydigest);
diff --git a/Utilities/cmcurl/lib/http_digest.h b/Utilities/cmcurl/lib/http_digest.h
index fd225c7c1..73410ae88 100644
--- a/Utilities/cmcurl/lib/http_digest.h
+++ b/Utilities/cmcurl/lib/http_digest.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -23,6 +23,8 @@
***************************************************************************/
#include "curl_setup.h"
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
+
/* this is for digest header input */
CURLcode Curl_input_digest(struct connectdata *conn,
bool proxy, const char *header);
@@ -33,10 +35,8 @@ CURLcode Curl_output_digest(struct connectdata *conn,
const unsigned char *request,
const unsigned char *uripath);
-#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
-void Curl_digest_cleanup(struct Curl_easy *data);
-#else
-#define Curl_digest_cleanup(x) Curl_nop_stmt
-#endif
+void Curl_http_auth_cleanup_digest(struct Curl_easy *data);
+
+#endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_CRYPTO_AUTH */
#endif /* HEADER_CURL_HTTP_DIGEST_H */
diff --git a/Utilities/cmcurl/lib/http_negotiate.c b/Utilities/cmcurl/lib/http_negotiate.c
index 51375e81d..c8f406444 100644
--- a/Utilities/cmcurl/lib/http_negotiate.c
+++ b/Utilities/cmcurl/lib/http_negotiate.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -49,6 +49,7 @@ CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
/* Point to the correct struct with this */
struct negotiatedata *neg_ctx;
+ curlnegotiate state;
if(proxy) {
userp = conn->http_proxy.user;
@@ -56,7 +57,8 @@ CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
service = data->set.str[STRING_PROXY_SERVICE_NAME] ?
data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
host = conn->http_proxy.host.name;
- neg_ctx = &data->state.proxyneg;
+ neg_ctx = &conn->proxyneg;
+ state = conn->proxy_negotiate_state;
}
else {
userp = conn->user;
@@ -64,7 +66,8 @@ CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
service = data->set.str[STRING_SERVICE_NAME] ?
data->set.str[STRING_SERVICE_NAME] : "HTTP";
host = conn->host.name;
- neg_ctx = &data->state.negotiate;
+ neg_ctx = &conn->negotiate;
+ state = conn->http_negotiate_state;
}
/* Not set means empty */
@@ -80,59 +83,138 @@ CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
header++;
len = strlen(header);
+ neg_ctx->havenegdata = len != 0;
if(!len) {
- /* Is this the first call in a new negotiation? */
- if(neg_ctx->context) {
- /* The server rejected our authentication and hasn't suppled any more
+ if(state == GSS_AUTHSUCC) {
+ infof(conn->data, "Negotiate auth restarted\n");
+ Curl_http_auth_cleanup_negotiate(conn);
+ }
+ else if(state != GSS_AUTHNONE) {
+ /* The server rejected our authentication and hasn't supplied any more
negotiation mechanisms */
+ Curl_http_auth_cleanup_negotiate(conn);
return CURLE_LOGIN_DENIED;
}
}
- /* Initilise the security context and decode our challenge */
+ /* Supports SSL channel binding for Windows ISS extended protection */
+#if defined(USE_WINDOWS_SSPI) && defined(SECPKG_ATTR_ENDPOINT_BINDINGS)
+ neg_ctx->sslContext = conn->sslContext;
+#endif
+
+ /* Initialize the security context and decode our challenge */
result = Curl_auth_decode_spnego_message(data, userp, passwdp, service,
host, header, neg_ctx);
if(result)
- Curl_auth_spnego_cleanup(neg_ctx);
+ Curl_http_auth_cleanup_negotiate(conn);
return result;
}
CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
{
- struct negotiatedata *neg_ctx = proxy ? &conn->data->state.proxyneg :
- &conn->data->state.negotiate;
+ struct negotiatedata *neg_ctx = proxy ? &conn->proxyneg :
+ &conn->negotiate;
+ struct auth *authp = proxy ? &conn->data->state.authproxy :
+ &conn->data->state.authhost;
+ curlnegotiate *state = proxy ? &conn->proxy_negotiate_state :
+ &conn->http_negotiate_state;
char *base64 = NULL;
size_t len = 0;
char *userp;
CURLcode result;
- result = Curl_auth_create_spnego_message(conn->data, neg_ctx, &base64, &len);
- if(result)
- return result;
+ authp->done = FALSE;
- userp = aprintf("%sAuthorization: Negotiate %s\r\n", proxy ? "Proxy-" : "",
- base64);
+ if(*state == GSS_AUTHRECV) {
+ if(neg_ctx->havenegdata) {
+ neg_ctx->havemultiplerequests = TRUE;
+ }
+ }
+ else if(*state == GSS_AUTHSUCC) {
+ if(!neg_ctx->havenoauthpersist) {
+ neg_ctx->noauthpersist = !neg_ctx->havemultiplerequests;
+ }
+ }
- if(proxy) {
- Curl_safefree(conn->allocptr.proxyuserpwd);
- conn->allocptr.proxyuserpwd = userp;
+ if(neg_ctx->noauthpersist ||
+ (*state != GSS_AUTHDONE && *state != GSS_AUTHSUCC)) {
+
+ if(neg_ctx->noauthpersist && *state == GSS_AUTHSUCC) {
+ infof(conn->data, "Curl_output_negotiate, "
+ "no persistent authentication: cleanup existing context");
+ Curl_http_auth_cleanup_negotiate(conn);
+ }
+ if(!neg_ctx->context) {
+ result = Curl_input_negotiate(conn, proxy, "Negotiate");
+ if(result == CURLE_LOGIN_DENIED) {
+ /* negotiate auth failed, let's continue unauthenticated to stay
+ * compatible with the behavior before curl-7_64_0-158-g6c6035532 */
+ conn->data->state.authproblem = TRUE;
+ return CURLE_OK;
+ }
+ else if(result)
+ return result;
+ }
+
+ result = Curl_auth_create_spnego_message(conn->data,
+ neg_ctx, &base64, &len);
+ if(result)
+ return result;
+
+ userp = aprintf("%sAuthorization: Negotiate %s\r\n", proxy ? "Proxy-" : "",
+ base64);
+
+ if(proxy) {
+ Curl_safefree(conn->allocptr.proxyuserpwd);
+ conn->allocptr.proxyuserpwd = userp;
+ }
+ else {
+ Curl_safefree(conn->allocptr.userpwd);
+ conn->allocptr.userpwd = userp;
+ }
+
+ free(base64);
+
+ if(userp == NULL) {
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ *state = GSS_AUTHSENT;
+ #ifdef HAVE_GSSAPI
+ if(neg_ctx->status == GSS_S_COMPLETE ||
+ neg_ctx->status == GSS_S_CONTINUE_NEEDED) {
+ *state = GSS_AUTHDONE;
+ }
+ #else
+ #ifdef USE_WINDOWS_SSPI
+ if(neg_ctx->status == SEC_E_OK ||
+ neg_ctx->status == SEC_I_CONTINUE_NEEDED) {
+ *state = GSS_AUTHDONE;
+ }
+ #endif
+ #endif
}
- else {
- Curl_safefree(conn->allocptr.userpwd);
- conn->allocptr.userpwd = userp;
+
+ if(*state == GSS_AUTHDONE || *state == GSS_AUTHSUCC) {
+ /* connection is already authenticated,
+ * don't send a header in future requests */
+ authp->done = TRUE;
}
- free(base64);
+ neg_ctx->havenegdata = FALSE;
- return (userp == NULL) ? CURLE_OUT_OF_MEMORY : CURLE_OK;
+ return CURLE_OK;
}
-void Curl_cleanup_negotiate(struct Curl_easy *data)
+void Curl_http_auth_cleanup_negotiate(struct connectdata *conn)
{
- Curl_auth_spnego_cleanup(&data->state.negotiate);
- Curl_auth_spnego_cleanup(&data->state.proxyneg);
+ conn->http_negotiate_state = GSS_AUTHNONE;
+ conn->proxy_negotiate_state = GSS_AUTHNONE;
+
+ Curl_auth_cleanup_spnego(&conn->negotiate);
+ Curl_auth_cleanup_spnego(&conn->proxyneg);
}
#endif /* !CURL_DISABLE_HTTP && USE_SPNEGO */
diff --git a/Utilities/cmcurl/lib/http_negotiate.h b/Utilities/cmcurl/lib/http_negotiate.h
index c64e54825..4f0ac1686 100644
--- a/Utilities/cmcurl/lib/http_negotiate.h
+++ b/Utilities/cmcurl/lib/http_negotiate.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,7 +22,7 @@
*
***************************************************************************/
-#ifdef USE_SPNEGO
+#if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO)
/* this is for Negotiate header input */
CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
@@ -31,8 +31,8 @@ CURLcode Curl_input_negotiate(struct connectdata *conn, bool proxy,
/* this is for creating Negotiate header output */
CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy);
-void Curl_cleanup_negotiate(struct Curl_easy *data);
+void Curl_http_auth_cleanup_negotiate(struct connectdata *conn);
-#endif /* USE_SPNEGO */
+#endif /* !CURL_DISABLE_HTTP && USE_SPNEGO */
#endif /* HEADER_CURL_HTTP_NEGOTIATE_H */
diff --git a/Utilities/cmcurl/lib/http_ntlm.c b/Utilities/cmcurl/lib/http_ntlm.c
index 8a78bd293..e4a4fe05d 100644
--- a/Utilities/cmcurl/lib/http_ntlm.c
+++ b/Utilities/cmcurl/lib/http_ntlm.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -37,11 +37,14 @@
#include "sendf.h"
#include "strcase.h"
#include "http_ntlm.h"
+#include "curl_ntlm_core.h"
#include "curl_ntlm_wb.h"
#include "vauth/vauth.h"
#include "url.h"
-#if defined(USE_NSS)
+/* SSL backend-specific #if branches in this file must be kept in the order
+ documented in curl_ntlm_core. */
+#if defined(NTLM_NEEDS_NSS_INIT)
#include "vtls/nssg.h"
#elif defined(USE_WINDOWS_SSPI)
#include "curl_sspi.h"
@@ -65,9 +68,11 @@ CURLcode Curl_input_ntlm(struct connectdata *conn,
{
/* point to the correct struct with this */
struct ntlmdata *ntlm;
+ curlntlm *state;
CURLcode result = CURLE_OK;
ntlm = proxy ? &conn->proxyntlm : &conn->ntlm;
+ state = proxy ? &conn->proxy_ntlm_state : &conn->http_ntlm_state;
if(checkprefix("NTLM", header)) {
header += strlen("NTLM");
@@ -80,25 +85,25 @@ CURLcode Curl_input_ntlm(struct connectdata *conn,
if(result)
return result;
- ntlm->state = NTLMSTATE_TYPE2; /* We got a type-2 message */
+ *state = NTLMSTATE_TYPE2; /* We got a type-2 message */
}
else {
- if(ntlm->state == NTLMSTATE_LAST) {
+ if(*state == NTLMSTATE_LAST) {
infof(conn->data, "NTLM auth restarted\n");
- Curl_http_ntlm_cleanup(conn);
+ Curl_http_auth_cleanup_ntlm(conn);
}
- else if(ntlm->state == NTLMSTATE_TYPE3) {
+ else if(*state == NTLMSTATE_TYPE3) {
infof(conn->data, "NTLM handshake rejected\n");
- Curl_http_ntlm_cleanup(conn);
- ntlm->state = NTLMSTATE_NONE;
+ Curl_http_auth_cleanup_ntlm(conn);
+ *state = NTLMSTATE_NONE;
return CURLE_REMOTE_ACCESS_DENIED;
}
- else if(ntlm->state >= NTLMSTATE_TYPE1) {
+ else if(*state >= NTLMSTATE_TYPE1) {
infof(conn->data, "NTLM handshake failure (internal error)\n");
return CURLE_REMOTE_ACCESS_DENIED;
}
- ntlm->state = NTLMSTATE_TYPE1; /* We should send away a type-1 */
+ *state = NTLMSTATE_TYPE1; /* We should send away a type-1 */
}
}
@@ -118,18 +123,21 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
server, which is for a plain host or for a HTTP proxy */
char **allocuserpwd;
- /* point to the name and password for this */
+ /* point to the username, password, service and host */
const char *userp;
const char *passwdp;
+ const char *service = NULL;
+ const char *hostname = NULL;
/* point to the correct struct with this */
struct ntlmdata *ntlm;
+ curlntlm *state;
struct auth *authp;
DEBUGASSERT(conn);
DEBUGASSERT(conn->data);
-#ifdef USE_NSS
+#if defined(NTLM_NEEDS_NSS_INIT)
if(CURLE_OK != Curl_nss_force_init(conn->data))
return CURLE_OUT_OF_MEMORY;
#endif
@@ -138,14 +146,22 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
allocuserpwd = &conn->allocptr.proxyuserpwd;
userp = conn->http_proxy.user;
passwdp = conn->http_proxy.passwd;
+ service = conn->data->set.str[STRING_PROXY_SERVICE_NAME] ?
+ conn->data->set.str[STRING_PROXY_SERVICE_NAME] : "HTTP";
+ hostname = conn->http_proxy.host.name;
ntlm = &conn->proxyntlm;
+ state = &conn->proxy_ntlm_state;
authp = &conn->data->state.authproxy;
}
else {
allocuserpwd = &conn->allocptr.userpwd;
userp = conn->user;
passwdp = conn->passwd;
+ service = conn->data->set.str[STRING_SERVICE_NAME] ?
+ conn->data->set.str[STRING_SERVICE_NAME] : "HTTP";
+ hostname = conn->host.name;
ntlm = &conn->ntlm;
+ state = &conn->http_ntlm_state;
authp = &conn->data->state.authhost;
}
authp->done = FALSE;
@@ -164,13 +180,18 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
if(s_hSecDll == NULL)
return err;
}
+#ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
+ ntlm->sslContext = conn->sslContext;
+#endif
#endif
- switch(ntlm->state) {
+ switch(*state) {
case NTLMSTATE_TYPE1:
default: /* for the weird cases we (re)start here */
/* Create a type-1 message */
- result = Curl_auth_create_ntlm_type1_message(userp, passwdp, ntlm, &base64,
+ result = Curl_auth_create_ntlm_type1_message(conn->data, userp, passwdp,
+ service, hostname,
+ ntlm, &base64,
&len);
if(result)
return result;
@@ -206,7 +227,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
DEBUG_OUT(fprintf(stderr, "**** %s\n ", *allocuserpwd));
- ntlm->state = NTLMSTATE_TYPE3; /* we send a type-3 */
+ *state = NTLMSTATE_TYPE3; /* we send a type-3 */
authp->done = TRUE;
}
break;
@@ -214,8 +235,8 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
case NTLMSTATE_TYPE3:
/* connection is already authenticated,
* don't send a header in future requests */
- ntlm->state = NTLMSTATE_LAST;
- /* fall-through */
+ *state = NTLMSTATE_LAST;
+ /* FALLTHROUGH */
case NTLMSTATE_LAST:
Curl_safefree(*allocuserpwd);
authp->done = TRUE;
@@ -225,13 +246,13 @@ CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy)
return CURLE_OK;
}
-void Curl_http_ntlm_cleanup(struct connectdata *conn)
+void Curl_http_auth_cleanup_ntlm(struct connectdata *conn)
{
- Curl_auth_ntlm_cleanup(&conn->ntlm);
- Curl_auth_ntlm_cleanup(&conn->proxyntlm);
+ Curl_auth_cleanup_ntlm(&conn->ntlm);
+ Curl_auth_cleanup_ntlm(&conn->proxyntlm);
#if defined(NTLM_WB_ENABLED)
- Curl_ntlm_wb_cleanup(conn);
+ Curl_http_auth_cleanup_ntlm_wb(conn);
#endif
}
diff --git a/Utilities/cmcurl/lib/http_ntlm.h b/Utilities/cmcurl/lib/http_ntlm.h
index d186bbe37..003714dbd 100644
--- a/Utilities/cmcurl/lib/http_ntlm.h
+++ b/Utilities/cmcurl/lib/http_ntlm.h
@@ -1,5 +1,5 @@
-#ifndef HEADER_CURL_NTLM_H
-#define HEADER_CURL_NTLM_H
+#ifndef HEADER_CURL_HTTP_NTLM_H
+#define HEADER_CURL_HTTP_NTLM_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -33,8 +33,8 @@ CURLcode Curl_input_ntlm(struct connectdata *conn, bool proxy,
/* this is for creating ntlm header output */
CURLcode Curl_output_ntlm(struct connectdata *conn, bool proxy);
-void Curl_http_ntlm_cleanup(struct connectdata *conn);
+void Curl_http_auth_cleanup_ntlm(struct connectdata *conn);
#endif /* !CURL_DISABLE_HTTP && USE_NTLM */
-#endif /* HEADER_CURL_NTLM_H */
+#endif /* HEADER_CURL_HTTP_NTLM_H */
diff --git a/Utilities/cmcurl/lib/http_proxy.c b/Utilities/cmcurl/lib/http_proxy.c
index 9894e2e5f..d7ed11761 100644
--- a/Utilities/cmcurl/lib/http_proxy.c
+++ b/Utilities/cmcurl/lib/http_proxy.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,11 +22,11 @@
#include "curl_setup.h"
+#include "http_proxy.h"
+
#if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
-#include "urldata.h"
#include <curl/curl.h>
-#include "http_proxy.h"
#include "sendf.h"
#include "http.h"
#include "url.h"
@@ -135,40 +135,77 @@ CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex)
return CURLE_OK;
}
-#define CONNECT_BUFFER_SIZE 16384
+bool Curl_connect_complete(struct connectdata *conn)
+{
+ return !conn->connect_state ||
+ (conn->connect_state->tunnel_state == TUNNEL_COMPLETE);
+}
+
+bool Curl_connect_ongoing(struct connectdata *conn)
+{
+ return conn->connect_state &&
+ (conn->connect_state->tunnel_state != TUNNEL_COMPLETE);
+}
+
+static CURLcode connect_init(struct connectdata *conn, bool reinit)
+{
+ struct http_connect_state *s;
+ if(!reinit) {
+ DEBUGASSERT(!conn->connect_state);
+ s = calloc(1, sizeof(struct http_connect_state));
+ if(!s)
+ return CURLE_OUT_OF_MEMORY;
+ infof(conn->data, "allocate connect buffer!\n");
+ conn->connect_state = s;
+ }
+ else {
+ DEBUGASSERT(conn->connect_state);
+ s = conn->connect_state;
+ }
+ s->tunnel_state = TUNNEL_INIT;
+ s->keepon = TRUE;
+ s->line_start = s->connect_buffer;
+ s->ptr = s->line_start;
+ s->cl = 0;
+ s->close_connection = FALSE;
+ return CURLE_OK;
+}
+
+static void connect_done(struct connectdata *conn)
+{
+ struct http_connect_state *s = conn->connect_state;
+ s->tunnel_state = TUNNEL_COMPLETE;
+ infof(conn->data, "CONNECT phase completed!\n");
+}
static CURLcode CONNECT(struct connectdata *conn,
int sockindex,
const char *hostname,
int remote_port)
{
- int subversion=0;
- struct Curl_easy *data=conn->data;
+ int subversion = 0;
+ struct Curl_easy *data = conn->data;
struct SingleRequest *k = &data->req;
CURLcode result;
curl_socket_t tunnelsocket = conn->sock[sockindex];
- curl_off_t cl=0;
- bool closeConnection = FALSE;
- bool chunked_encoding = FALSE;
- time_t check;
+ struct http_connect_state *s = conn->connect_state;
#define SELECT_OK 0
#define SELECT_ERROR 1
-#define SELECT_TIMEOUT 2
- int error = SELECT_OK;
- if(conn->tunnel_state[sockindex] == TUNNEL_COMPLETE)
+ if(Curl_connect_complete(conn))
return CURLE_OK; /* CONNECT is already completed */
conn->bits.proxy_connect_closed = FALSE;
do {
- if(TUNNEL_INIT == conn->tunnel_state[sockindex]) {
+ timediff_t check;
+ if(TUNNEL_INIT == s->tunnel_state) {
/* BEGIN CONNECT PHASE */
char *host_port;
Curl_send_buffer *req_buffer;
- infof(data, "Establish HTTP proxy tunnel to %s:%hu\n",
+ infof(data, "Establish HTTP proxy tunnel to %s:%d\n",
hostname, remote_port);
/* This only happens if we've looped here due to authentication
@@ -183,9 +220,9 @@ static CURLcode CONNECT(struct connectdata *conn,
if(!req_buffer)
return CURLE_OUT_OF_MEMORY;
- host_port = aprintf("%s:%hu", hostname, remote_port);
+ host_port = aprintf("%s:%d", hostname, remote_port);
if(!host_port) {
- Curl_add_buffer_free(req_buffer);
+ Curl_add_buffer_free(&req_buffer);
return CURLE_OUT_OF_MEMORY;
}
@@ -196,8 +233,8 @@ static CURLcode CONNECT(struct connectdata *conn,
if(!result) {
char *host = NULL;
- const char *proxyconn="";
- const char *useragent="";
+ const char *proxyconn = "";
+ const char *useragent = "";
const char *http = (conn->http_proxy.proxytype == CURLPROXY_HTTP_1_0) ?
"1.0" : "1.1";
bool ipv6_ip = conn->bits.ipv6_ip;
@@ -206,31 +243,31 @@ static CURLcode CONNECT(struct connectdata *conn,
/* the hostname may be different */
if(hostname != conn->host.name)
ipv6_ip = (strchr(hostname, ':') != NULL);
- hostheader= /* host:port with IPv6 support */
- aprintf("%s%s%s:%hu", ipv6_ip?"[":"", hostname, ipv6_ip?"]":"",
+ hostheader = /* host:port with IPv6 support */
+ aprintf("%s%s%s:%d", ipv6_ip?"[":"", hostname, ipv6_ip?"]":"",
remote_port);
if(!hostheader) {
- Curl_add_buffer_free(req_buffer);
+ Curl_add_buffer_free(&req_buffer);
return CURLE_OUT_OF_MEMORY;
}
- if(!Curl_checkProxyheaders(conn, "Host:")) {
+ if(!Curl_checkProxyheaders(conn, "Host")) {
host = aprintf("Host: %s\r\n", hostheader);
if(!host) {
free(hostheader);
- Curl_add_buffer_free(req_buffer);
+ Curl_add_buffer_free(&req_buffer);
return CURLE_OUT_OF_MEMORY;
}
}
- if(!Curl_checkProxyheaders(conn, "Proxy-Connection:"))
+ if(!Curl_checkProxyheaders(conn, "Proxy-Connection"))
proxyconn = "Proxy-Connection: Keep-Alive\r\n";
- if(!Curl_checkProxyheaders(conn, "User-Agent:") &&
+ if(!Curl_checkProxyheaders(conn, "User-Agent") &&
data->set.str[STRING_USERAGENT])
useragent = conn->allocptr.uagent;
result =
- Curl_add_bufferf(req_buffer,
+ Curl_add_bufferf(&req_buffer,
"CONNECT %s HTTP/%s\r\n"
"%s" /* Host: */
"%s" /* Proxy-Authorization */
@@ -253,13 +290,13 @@ static CURLcode CONNECT(struct connectdata *conn,
if(!result)
/* CRLF terminate the request */
- result = Curl_add_bufferf(req_buffer, "\r\n");
+ result = Curl_add_bufferf(&req_buffer, "\r\n");
if(!result) {
/* Send the connect request to the proxy */
/* BLOCKING */
result =
- Curl_add_buffer_send(req_buffer, conn,
+ Curl_add_buffer_send(&req_buffer, conn,
&data->info.request_size, 0, sockindex);
}
req_buffer = NULL;
@@ -267,69 +304,50 @@ static CURLcode CONNECT(struct connectdata *conn,
failf(data, "Failed sending CONNECT to proxy");
}
- Curl_add_buffer_free(req_buffer);
+ Curl_add_buffer_free(&req_buffer);
if(result)
return result;
- conn->tunnel_state[sockindex] = TUNNEL_CONNECT;
+ s->tunnel_state = TUNNEL_CONNECT;
+ s->perline = 0;
} /* END CONNECT PHASE */
check = Curl_timeleft(data, NULL, TRUE);
if(check <= 0) {
failf(data, "Proxy CONNECT aborted due to timeout");
- return CURLE_RECV_ERROR;
+ return CURLE_OPERATION_TIMEDOUT;
}
if(!Curl_conn_data_pending(conn, sockindex))
/* return so we'll be called again polling-style */
return CURLE_OK;
- DEBUGF(infof(data, "Read response immediately from proxy CONNECT\n"));
/* at this point, the tunnel_connecting phase is over. */
{ /* READING RESPONSE PHASE */
- size_t nread; /* total size read */
- int perline; /* count bytes per line */
- int keepon=TRUE;
- ssize_t gotbytes;
- char *ptr;
- char *line_start;
+ int error = SELECT_OK;
- ptr = conn->connect_buffer;
- line_start = ptr;
+ while(s->keepon && !error) {
+ ssize_t gotbytes;
- nread = 0;
- perline = 0;
-
- while(nread < (size_t)CONNECT_BUFFER_SIZE && keepon && !error) {
- if(Curl_pgrsUpdate(conn))
- return CURLE_ABORTED_BY_CALLBACK;
-
- if(ptr >= &conn->connect_buffer[CONNECT_BUFFER_SIZE]) {
+ /* make sure we have space to read more data */
+ if(s->ptr >= &s->connect_buffer[CONNECT_BUFFER_SIZE]) {
failf(data, "CONNECT response too large!");
return CURLE_RECV_ERROR;
}
- check = Curl_timeleft(data, NULL, TRUE);
- if(check <= 0) {
- failf(data, "Proxy CONNECT aborted due to timeout");
- error = SELECT_TIMEOUT; /* already too little time */
- break;
- }
-
/* Read one byte at a time to avoid a race condition. Wait at most one
second before looping to ensure continuous pgrsUpdates. */
- result = Curl_read(conn, tunnelsocket, ptr, 1, &gotbytes);
- if(result == CURLE_AGAIN) {
- if(SOCKET_READABLE(tunnelsocket, check<1000L?check:1000) == -1) {
- error = SELECT_ERROR;
- failf(data, "Proxy CONNECT aborted due to select/poll error");
- break;
- }
- continue;
- }
+ result = Curl_read(conn, tunnelsocket, s->ptr, 1, &gotbytes);
+ if(result == CURLE_AGAIN)
+ /* socket buffer drained, return */
+ return CURLE_OK;
+
+ if(Curl_pgrsUpdate(conn))
+ return CURLE_ABORTED_BY_CALLBACK;
+
if(result) {
- keepon = FALSE;
+ s->keepon = FALSE;
break;
}
else if(gotbytes <= 0) {
@@ -343,24 +361,22 @@ static CURLcode CONNECT(struct connectdata *conn,
error = SELECT_ERROR;
failf(data, "Proxy CONNECT aborted");
}
- keepon = FALSE;
+ s->keepon = FALSE;
break;
}
- /* We got a byte of data */
- nread++;
- if(keepon > TRUE) {
+ if(s->keepon > TRUE) {
/* This means we are currently ignoring a response-body */
- nread = 0; /* make next read start over in the read buffer */
- ptr = conn->connect_buffer;
- if(cl) {
+ s->ptr = s->connect_buffer;
+ if(s->cl) {
/* A Content-Length based body: simply count down the counter
and make sure to break out of the loop when we're done! */
- cl--;
- if(cl <= 0) {
- keepon = FALSE;
+ s->cl--;
+ if(s->cl <= 0) {
+ s->keepon = FALSE;
+ s->tunnel_state = TUNNEL_COMPLETE;
break;
}
}
@@ -372,28 +388,29 @@ static CURLcode CONNECT(struct connectdata *conn,
/* now parse the chunked piece of data so that we can
properly tell when the stream ends */
- r = Curl_httpchunk_read(conn, ptr, 1, &tookcareof);
+ r = Curl_httpchunk_read(conn, s->ptr, 1, &tookcareof);
if(r == CHUNKE_STOP) {
/* we're done reading chunks! */
infof(data, "chunk reading DONE\n");
- keepon = FALSE;
+ s->keepon = FALSE;
/* we did the full CONNECT treatment, go COMPLETE */
- conn->tunnel_state[sockindex] = TUNNEL_COMPLETE;
+ s->tunnel_state = TUNNEL_COMPLETE;
}
}
continue;
}
- perline++; /* amount of bytes in this line so far */
+ s->perline++; /* amount of bytes in this line so far */
/* if this is not the end of a header line then continue */
- if(*ptr != 0x0a) {
- ptr++;
+ if(*s->ptr != 0x0a) {
+ s->ptr++;
continue;
}
/* convert from the network encoding */
- result = Curl_convert_from_network(data, line_start, perline);
+ result = Curl_convert_from_network(data, s->line_start,
+ (size_t)s->perline);
/* Curl_convert_from_network calls failf if unsuccessful */
if(result)
return result;
@@ -401,7 +418,7 @@ static CURLcode CONNECT(struct connectdata *conn,
/* output debug if that is requested */
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN,
- line_start, (size_t)perline, conn);
+ s->line_start, (size_t)s->perline);
if(!data->set.suppress_connect_headers) {
/* send the header to the callback */
@@ -409,35 +426,34 @@ static CURLcode CONNECT(struct connectdata *conn,
if(data->set.include_header)
writetype |= CLIENTWRITE_BODY;
- result = Curl_client_write(conn, writetype, line_start, perline);
+ result = Curl_client_write(conn, writetype,
+ s->line_start, s->perline);
if(result)
return result;
}
- data->info.header_size += (long)perline;
- data->req.headerbytecount += (long)perline;
+ data->info.header_size += (long)s->perline;
+ data->req.headerbytecount += (long)s->perline;
/* 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])) {
+ if(('\r' == s->line_start[0]) ||
+ ('\n' == s->line_start[0])) {
/* end of response-headers from the proxy */
- nread = 0; /* make next read start over in the read
- buffer */
- ptr = conn->connect_buffer;
+ s->ptr = s->connect_buffer;
if((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;
+ s->keepon = 2;
- if(cl) {
+ if(s->cl) {
infof(data, "Ignore %" CURL_FORMAT_CURL_OFF_T
- " bytes of response-body\n", cl);
+ " bytes of response-body\n", s->cl);
}
- else if(chunked_encoding) {
+ else if(s->chunked_encoding) {
CHUNKcode r;
infof(data, "Ignore chunked response-body\n");
@@ -448,46 +464,46 @@ static CURLcode CONNECT(struct connectdata *conn,
function returns! */
k->ignorebody = TRUE;
- if(line_start[1] == '\n') {
+ if(s->line_start[1] == '\n') {
/* this can only be a LF if the letter at index 0
was a CR */
- line_start++;
+ s->line_start++;
}
/* now parse the chunked piece of data so that we can
properly tell when the stream ends */
- r = Curl_httpchunk_read(conn, line_start + 1, 1, &gotbytes);
+ r = Curl_httpchunk_read(conn, s->line_start + 1, 1, &gotbytes);
if(r == CHUNKE_STOP) {
/* we're done reading chunks! */
infof(data, "chunk reading DONE\n");
- keepon = FALSE;
- /* we did the full CONNECT treatment, go to
- COMPLETE */
- conn->tunnel_state[sockindex] = TUNNEL_COMPLETE;
+ s->keepon = FALSE;
+ /* we did the full CONNECT treatment, go to COMPLETE */
+ s->tunnel_state = TUNNEL_COMPLETE;
}
}
else {
/* without content-length or chunked encoding, we
can't keep the connection alive since the close is
the end signal so we bail out at once instead */
- keepon = FALSE;
+ s->keepon = FALSE;
}
}
else
- keepon = FALSE;
- /* we did the full CONNECT treatment, go to COMPLETE */
- conn->tunnel_state[sockindex] = TUNNEL_COMPLETE;
+ s->keepon = FALSE;
+ if(!s->cl)
+ /* we did the full CONNECT treatment, go to COMPLETE */
+ s->tunnel_state = TUNNEL_COMPLETE;
continue;
}
- line_start[perline] = 0; /* zero terminate the buffer */
- if((checkprefix("WWW-Authenticate:", line_start) &&
+ s->line_start[s->perline] = 0; /* zero terminate the buffer */
+ if((checkprefix("WWW-Authenticate:", s->line_start) &&
(401 == k->httpcode)) ||
- (checkprefix("Proxy-authenticate:", line_start) &&
+ (checkprefix("Proxy-authenticate:", s->line_start) &&
(407 == k->httpcode))) {
bool proxy = (k->httpcode == 407) ? TRUE : FALSE;
- char *auth = Curl_copy_header_value(line_start);
+ char *auth = Curl_copy_header_value(s->line_start);
if(!auth)
return CURLE_OUT_OF_MEMORY;
@@ -498,7 +514,7 @@ static CURLcode CONNECT(struct connectdata *conn,
if(result)
return result;
}
- else if(checkprefix("Content-Length:", line_start)) {
+ else if(checkprefix("Content-Length:", s->line_start)) {
if(k->httpcode/100 == 2) {
/* A client MUST ignore any Content-Length or Transfer-Encoding
header fields received in a successful response to CONNECT.
@@ -507,13 +523,13 @@ static CURLcode CONNECT(struct connectdata *conn,
k->httpcode);
}
else {
- cl = curlx_strtoofft(line_start +
- strlen("Content-Length:"), NULL, 10);
+ (void)curlx_strtoofft(s->line_start +
+ strlen("Content-Length:"), NULL, 10, &s->cl);
}
}
- else if(Curl_compareheader(line_start, "Connection:", "close"))
- closeConnection = TRUE;
- else if(checkprefix("Transfer-Encoding:", line_start)) {
+ else if(Curl_compareheader(s->line_start, "Connection:", "close"))
+ s->close_connection = TRUE;
+ else if(checkprefix("Transfer-Encoding:", s->line_start)) {
if(k->httpcode/100 == 2) {
/* A client MUST ignore any Content-Length or Transfer-Encoding
header fields received in a successful response to CONNECT.
@@ -521,26 +537,27 @@ static CURLcode CONNECT(struct connectdata *conn,
infof(data, "Ignoring Transfer-Encoding in "
"CONNECT %03d response\n", k->httpcode);
}
- else if(Curl_compareheader(line_start,
+ else if(Curl_compareheader(s->line_start,
"Transfer-Encoding:", "chunked")) {
infof(data, "CONNECT responded chunked\n");
- chunked_encoding = TRUE;
+ s->chunked_encoding = TRUE;
/* init our chunky engine */
Curl_httpchunk_init(conn);
}
}
- else if(Curl_compareheader(line_start, "Proxy-Connection:", "close"))
- closeConnection = TRUE;
- else if(2 == sscanf(line_start, "HTTP/1.%d %d",
+ else if(Curl_compareheader(s->line_start,
+ "Proxy-Connection:", "close"))
+ s->close_connection = TRUE;
+ else if(2 == sscanf(s->line_start, "HTTP/1.%d %d",
&subversion,
&k->httpcode)) {
/* store the HTTP code from the proxy */
data->info.httpproxycode = k->httpcode;
}
- perline = 0; /* line starts over here */
- ptr = conn->connect_buffer;
- line_start = ptr;
+ s->perline = 0; /* line starts over here */
+ s->ptr = s->connect_buffer;
+ s->line_start = s->ptr;
} /* while there's buffer left and loop is requested */
if(Curl_pgrsUpdate(conn))
@@ -549,7 +566,7 @@ static CURLcode CONNECT(struct connectdata *conn,
if(error)
return CURLE_RECV_ERROR;
- if(data->info.httpproxycode != 200) {
+ if(data->info.httpproxycode/100 != 2) {
/* Deal with the possibly already received authenticate
headers. 'newurl' is set to a new URL if we must loop. */
result = Curl_http_auth_act(conn);
@@ -560,10 +577,10 @@ static CURLcode CONNECT(struct connectdata *conn,
/* the connection has been marked for closure, most likely in the
Curl_http_auth_act() function and thus we can kill it at once
below */
- closeConnection = TRUE;
+ s->close_connection = TRUE;
}
- if(closeConnection && data->req.newurl) {
+ if(s->close_connection && data->req.newurl) {
/* Connection closed by server. Don't use it anymore */
Curl_closesocket(conn, conn->sock[sockindex]);
conn->sock[sockindex] = CURL_SOCKET_BAD;
@@ -574,19 +591,17 @@ static CURLcode CONNECT(struct connectdata *conn,
/* If we are supposed to continue and request a new URL, which basically
* means the HTTP authentication is still going on so if the tunnel
* is complete we start over in INIT state */
- if(data->req.newurl &&
- (TUNNEL_COMPLETE == conn->tunnel_state[sockindex])) {
- conn->tunnel_state[sockindex] = TUNNEL_INIT;
- infof(data, "TUNNEL_STATE switched to: %d\n",
- conn->tunnel_state[sockindex]);
+ if(data->req.newurl && (TUNNEL_COMPLETE == s->tunnel_state)) {
+ connect_init(conn, TRUE); /* reinit */
}
} while(data->req.newurl);
- if(200 != data->req.httpcode) {
- if(closeConnection && data->req.newurl) {
+ if(data->info.httpproxycode/100 != 2) {
+ if(s->close_connection && data->req.newurl) {
conn->bits.proxy_connect_closed = TRUE;
infof(data, "Connect me again please\n");
+ connect_done(conn);
}
else {
free(data->req.newurl);
@@ -598,7 +613,7 @@ static CURLcode CONNECT(struct connectdata *conn,
}
/* to back to init state */
- conn->tunnel_state[sockindex] = TUNNEL_INIT;
+ s->tunnel_state = TUNNEL_INIT;
if(conn->bits.proxy_connect_closed)
/* this is not an error, just part of the connection negotiation */
@@ -608,7 +623,7 @@ static CURLcode CONNECT(struct connectdata *conn,
return CURLE_RECV_ERROR;
}
- conn->tunnel_state[sockindex] = TUNNEL_COMPLETE;
+ s->tunnel_state = TUNNEL_COMPLETE;
/* 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
@@ -618,13 +633,24 @@ static CURLcode CONNECT(struct connectdata *conn,
data->state.authproxy.done = TRUE;
- infof(data, "Proxy replied OK to CONNECT request\n");
+ infof(data, "Proxy replied %d to CONNECT request\n",
+ data->info.httpproxycode);
data->req.ignorebody = FALSE; /* put it (back) to non-ignore state */
conn->bits.rewindaftersend = FALSE; /* make sure this isn't set for the
document request */
return CURLE_OK;
}
+void Curl_connect_free(struct Curl_easy *data)
+{
+ struct connectdata *conn = data->conn;
+ struct http_connect_state *s = conn->connect_state;
+ if(s) {
+ free(s);
+ conn->connect_state = NULL;
+ }
+}
+
/*
* Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
* function will issue the necessary commands to get a seamless tunnel through
@@ -637,20 +663,23 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
int remote_port)
{
CURLcode result;
- if(TUNNEL_INIT == conn->tunnel_state[sockindex]) {
- if(!conn->connect_buffer) {
- conn->connect_buffer = malloc(CONNECT_BUFFER_SIZE);
- if(!conn->connect_buffer)
- return CURLE_OUT_OF_MEMORY;
- }
+ if(!conn->connect_state) {
+ result = connect_init(conn, FALSE);
+ if(result)
+ return result;
}
result = CONNECT(conn, sockindex, hostname, remote_port);
- if(result || (TUNNEL_COMPLETE == conn->tunnel_state[sockindex]))
- Curl_safefree(conn->connect_buffer);
+ if(result || Curl_connect_complete(conn))
+ connect_done(conn);
return result;
}
+#else
+void Curl_connect_free(struct Curl_easy *data)
+{
+ (void)data;
+}
#endif /* CURL_DISABLE_PROXY */
diff --git a/Utilities/cmcurl/lib/http_proxy.h b/Utilities/cmcurl/lib/http_proxy.h
index cbb1ab421..e19fa859a 100644
--- a/Utilities/cmcurl/lib/http_proxy.h
+++ b/Utilities/cmcurl/lib/http_proxy.h
@@ -22,6 +22,9 @@
*
***************************************************************************/
+#include "curl_setup.h"
+#include "urldata.h"
+
#if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
/* ftp can use this as well */
CURLcode Curl_proxyCONNECT(struct connectdata *conn,
@@ -33,9 +36,16 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex);
+bool Curl_connect_complete(struct connectdata *conn);
+bool Curl_connect_ongoing(struct connectdata *conn);
+
#else
#define Curl_proxyCONNECT(x,y,z,w) CURLE_NOT_BUILT_IN
#define Curl_proxy_connect(x,y) CURLE_OK
+#define Curl_connect_complete(x) CURLE_OK
+#define Curl_connect_ongoing(x) FALSE
#endif
+void Curl_connect_free(struct Curl_easy *data);
+
#endif /* HEADER_CURL_HTTP_PROXY_H */
diff --git a/Utilities/cmcurl/lib/if2ip.c b/Utilities/cmcurl/lib/if2ip.c
index 4de81be60..d003de678 100644
--- a/Utilities/cmcurl/lib/if2ip.c
+++ b/Utilities/cmcurl/lib/if2ip.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -71,6 +71,8 @@ unsigned int Curl_ipv6_scope(const struct sockaddr *sa)
const unsigned char *b = sa6->sin6_addr.s6_addr;
unsigned short w = (unsigned short) ((b[0] << 8) | b[1]);
+ if((b[0] & 0xFE) == 0xFC) /* Handle ULAs */
+ return IPV6_SCOPE_UNIQUELOCAL;
switch(w & 0xFFC0) {
case 0xFE80:
return IPV6_SCOPE_LINKLOCAL;
@@ -94,26 +96,8 @@ unsigned int Curl_ipv6_scope(const struct sockaddr *sa)
#if defined(HAVE_GETIFADDRS)
-bool Curl_if_is_interface_name(const char *interf)
-{
- bool result = FALSE;
-
- struct ifaddrs *iface, *head;
-
- if(getifaddrs(&head) >= 0) {
- for(iface=head; iface != NULL; iface=iface->ifa_next) {
- if(strcasecompare(iface->ifa_name, interf)) {
- result = TRUE;
- break;
- }
- }
- freeifaddrs(head);
- }
- return result;
-}
-
if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
- unsigned int remote_scope_id, const char *interf,
+ unsigned int local_scope_id, const char *interf,
char *buf, int buf_size)
{
struct ifaddrs *iface, *head;
@@ -121,15 +105,15 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
#ifndef ENABLE_IPV6
(void) remote_scope;
-
-#ifndef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
- (void) remote_scope_id;
#endif
+#if !defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) || \
+ !defined(ENABLE_IPV6)
+ (void) local_scope_id;
#endif
if(getifaddrs(&head) >= 0) {
- for(iface = head; iface != NULL; iface=iface->ifa_next) {
+ for(iface = head; iface != NULL; iface = iface->ifa_next) {
if(iface->ifa_addr != NULL) {
if(iface->ifa_addr->sa_family == af) {
if(strcasecompare(iface->ifa_name, interf)) {
@@ -139,7 +123,9 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
char ipstr[64];
#ifdef ENABLE_IPV6
if(af == AF_INET6) {
+#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
unsigned int scopeid = 0;
+#endif
unsigned int ifscope = Curl_ipv6_scope(iface->ifa_addr);
if(ifscope != remote_scope) {
@@ -159,15 +145,16 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
->sin6_scope_id;
/* If given, scope id should match. */
- if(remote_scope_id && scopeid != remote_scope_id) {
+ if(local_scope_id && scopeid != local_scope_id) {
if(res == IF2IP_NOT_FOUND)
res = IF2IP_AF_NOT_SUPPORTED;
continue;
}
-#endif
+
if(scopeid)
- snprintf(scope, sizeof(scope), "%%%u", scopeid);
+ msnprintf(scope, sizeof(scope), "%%%u", scopeid);
+#endif
}
else
#endif
@@ -175,7 +162,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
&((struct sockaddr_in *)(void *)iface->ifa_addr)->sin_addr;
res = IF2IP_FOUND;
ip = (char *) Curl_inet_ntop(af, addr, ipstr, sizeof(ipstr));
- snprintf(buf, buf_size, "%s%s", ip, scope);
+ msnprintf(buf, buf_size, "%s%s", ip, scope);
break;
}
}
@@ -194,17 +181,8 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
#elif defined(HAVE_IOCTL_SIOCGIFADDR)
-bool Curl_if_is_interface_name(const char *interf)
-{
- /* This is here just to support the old interfaces */
- char buf[256];
-
- return (Curl_if2ip(AF_INET, 0 /* unused */, 0, interf, buf, sizeof(buf)) ==
- IF2IP_NOT_FOUND) ? FALSE : TRUE;
-}
-
if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
- unsigned int remote_scope_id, const char *interf,
+ unsigned int local_scope_id, const char *interf,
char *buf, int buf_size)
{
struct ifreq req;
@@ -214,7 +192,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
size_t len;
(void)remote_scope;
- (void)remote_scope_id;
+ (void)local_scope_id;
if(!interf || (af != AF_INET))
return IF2IP_NOT_FOUND;
@@ -228,7 +206,7 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
return IF2IP_NOT_FOUND;
memset(&req, 0, sizeof(req));
- memcpy(req.ifr_name, interf, len+1);
+ memcpy(req.ifr_name, interf, len + 1);
req.ifr_addr.sa_family = AF_INET;
if(ioctl(dummy, SIOCGIFADDR, &req) < 0) {
@@ -249,20 +227,13 @@ if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
#else
-bool Curl_if_is_interface_name(const char *interf)
-{
- (void) interf;
-
- return FALSE;
-}
-
if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
- unsigned int remote_scope_id, const char *interf,
+ unsigned int local_scope_id, const char *interf,
char *buf, int buf_size)
{
(void) af;
(void) remote_scope;
- (void) remote_scope_id;
+ (void) local_scope_id;
(void) interf;
(void) buf;
(void) buf_size;
diff --git a/Utilities/cmcurl/lib/if2ip.h b/Utilities/cmcurl/lib/if2ip.h
index f3a7ff0b2..f193d4257 100644
--- a/Utilities/cmcurl/lib/if2ip.h
+++ b/Utilities/cmcurl/lib/if2ip.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -27,12 +27,11 @@
#define IPV6_SCOPE_GLOBAL 0 /* Global scope. */
#define IPV6_SCOPE_LINKLOCAL 1 /* Link-local scope. */
#define IPV6_SCOPE_SITELOCAL 2 /* Site-local scope (deprecated). */
-#define IPV6_SCOPE_NODELOCAL 3 /* Loopback. */
+#define IPV6_SCOPE_UNIQUELOCAL 3 /* Unique local */
+#define IPV6_SCOPE_NODELOCAL 4 /* Loopback. */
unsigned int Curl_ipv6_scope(const struct sockaddr *sa);
-bool Curl_if_is_interface_name(const char *interf);
-
typedef enum {
IF2IP_NOT_FOUND = 0, /* Interface not found */
IF2IP_AF_NOT_SUPPORTED = 1, /* Int. exists but has no address for this af */
@@ -40,7 +39,7 @@ typedef enum {
} if2ip_result_t;
if2ip_result_t Curl_if2ip(int af, unsigned int remote_scope,
- unsigned int remote_scope_id, const char *interf,
+ unsigned int local_scope_id, const char *interf,
char *buf, int buf_size);
#ifdef __INTERIX
diff --git a/Utilities/cmcurl/lib/imap.c b/Utilities/cmcurl/lib/imap.c
index b528f77d9..bdcc69c67 100644
--- a/Utilities/cmcurl/lib/imap.c
+++ b/Utilities/cmcurl/lib/imap.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -28,6 +28,7 @@
* RFC4959 IMAP Extension for SASL Initial Client Response
* RFC5092 IMAP URL Scheme
* RFC6749 OAuth 2.0 Authorization Framework
+ * RFC8314 Use of TLS for Email Submission and Access
* Draft LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
*
***************************************************************************/
@@ -68,6 +69,7 @@
#include "http.h" /* for HTTP proxy tunnel stuff */
#include "socks.h"
#include "imap.h"
+#include "mime.h"
#include "strtoofft.h"
#include "strcase.h"
#include "vtls/vtls.h"
@@ -128,6 +130,7 @@ const struct Curl_handler Curl_handler_imap = {
ZERO_NULL, /* perform_getsock */
imap_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_IMAP, /* defport */
CURLPROTO_IMAP, /* protocol */
PROTOPT_CLOSEACTION| /* flags */
@@ -154,69 +157,23 @@ const struct Curl_handler Curl_handler_imaps = {
ZERO_NULL, /* perform_getsock */
imap_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_IMAPS, /* defport */
CURLPROTO_IMAPS, /* protocol */
- PROTOPT_CLOSEACTION | PROTOPT_SSL /* flags */
+ PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */
+ PROTOPT_URLOPTIONS
};
#endif
-#ifndef CURL_DISABLE_HTTP
-/*
- * HTTP-proxyed IMAP protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_imap_proxy = {
- "IMAP", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_IMAP, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-
-#ifdef USE_SSL
-/*
- * HTTP-proxyed IMAPS protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_imaps_proxy = {
- "IMAPS", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_IMAPS, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-#endif
-#endif
+#define IMAP_RESP_OK 1
+#define IMAP_RESP_NOT_OK 2
+#define IMAP_RESP_PREAUTH 3
/* SASL parameters for the imap protocol */
static const struct SASLproto saslimap = {
"imap", /* The service name */
'+', /* Code received when continuation is expected */
- 'O', /* Code to receive upon authentication success */
+ IMAP_RESP_OK, /* Code to receive upon authentication success */
0, /* Maximum initial response length (no max) */
imap_perform_authenticate, /* Send authentication command */
imap_continue_authenticate, /* Send authentication continuation */
@@ -299,15 +256,11 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
len -= id_len + 1;
if(len >= 2 && !memcmp(line, "OK", 2))
- *resp = 'O';
- else if(len >= 2 && !memcmp(line, "NO", 2))
- *resp = 'N';
- else if(len >= 3 && !memcmp(line, "BAD", 3))
- *resp = 'B';
- else {
- failf(conn->data, "Bad tagged response");
- *resp = -1;
- }
+ *resp = IMAP_RESP_OK;
+ else if(len >= 7 && !memcmp(line, "PREAUTH", 7))
+ *resp = IMAP_RESP_PREAUTH;
+ else
+ *resp = IMAP_RESP_NOT_OK;
return TRUE;
}
@@ -324,15 +277,15 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
case IMAP_LIST:
if((!imap->custom && !imap_matchresp(line, len, "LIST")) ||
(imap->custom && !imap_matchresp(line, len, imap->custom) &&
- (strcmp(imap->custom, "STORE") ||
+ (!strcasecompare(imap->custom, "STORE") ||
!imap_matchresp(line, len, "FETCH")) &&
- strcmp(imap->custom, "SELECT") &&
- strcmp(imap->custom, "EXAMINE") &&
- strcmp(imap->custom, "SEARCH") &&
- strcmp(imap->custom, "EXPUNGE") &&
- strcmp(imap->custom, "LSUB") &&
- strcmp(imap->custom, "UID") &&
- strcmp(imap->custom, "NOOP")))
+ !strcasecompare(imap->custom, "SELECT") &&
+ !strcasecompare(imap->custom, "EXAMINE") &&
+ !strcasecompare(imap->custom, "SEARCH") &&
+ !strcasecompare(imap->custom, "EXPUNGE") &&
+ !strcasecompare(imap->custom, "LSUB") &&
+ !strcasecompare(imap->custom, "UID") &&
+ !strcasecompare(imap->custom, "NOOP")))
return FALSE;
break;
@@ -364,7 +317,7 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
a space and optionally some text as per RFC-3501 for the AUTHENTICATE and
APPEND commands and as outlined in Section 4. Examples of RFC-4959 but
some e-mail servers ignore this and only send a single + instead. */
- if(imap && !imap->custom && ((len == 3 && !memcmp("+", line, 1)) ||
+ if(imap && !imap->custom && ((len == 3 && line[0] == '+') ||
(len >= 2 && !memcmp("+ ", line, 2)))) {
switch(imapc->state) {
/* States which are interested in continuation responses */
@@ -393,23 +346,30 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
*/
static void imap_get_message(char *buffer, char **outptr)
{
- size_t len = 0;
+ size_t len = strlen(buffer);
char *message = NULL;
- /* Find the start of the message */
- for(message = buffer + 2; *message == ' ' || *message == '\t'; message++)
- ;
-
- /* Find the end of the message */
- for(len = strlen(message); len--;)
- if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
- message[len] != '\t')
- break;
+ if(len > 2) {
+ /* Find the start of the message */
+ len -= 2;
+ for(message = buffer + 2; *message == ' ' || *message == '\t';
+ message++, len--)
+ ;
+
+ /* Find the end of the message */
+ for(; len--;)
+ if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
+ message[len] != '\t')
+ break;
- /* Terminate the message */
- if(++len) {
- message[len] = '\0';
+ /* Terminate the message */
+ if(++len) {
+ message[len] = '\0';
+ }
}
+ else
+ /* junk input => zero length output */
+ message = &buffer[len];
*outptr = message;
}
@@ -463,7 +423,6 @@ static CURLcode imap_perform_capability(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct imap_conn *imapc = &conn->proto.imapc;
-
imapc->sasl.authmechs = SASL_AUTH_NONE; /* No known auth. mechanisms yet */
imapc->sasl.authused = SASL_AUTH_NONE; /* Clear the auth. mechanism used */
imapc->tls_supported = FALSE; /* Clear the TLS capability */
@@ -613,9 +572,10 @@ static CURLcode imap_perform_authentication(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
saslprogress progress;
- /* Check we have enough data to authenticate with and end the
- connect phase if we don't */
- if(!Curl_sasl_can_authenticate(&imapc->sasl, conn)) {
+ /* Check if already authenticated OR if there is enough data to authenticate
+ with and end the connect phase if we don't */
+ if(imapc->preauth ||
+ !Curl_sasl_can_authenticate(&imapc->sasl, conn)) {
state(conn, IMAP_STOP);
return result;
}
@@ -650,7 +610,6 @@ static CURLcode imap_perform_list(struct connectdata *conn)
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
struct IMAP *imap = data->req.protop;
- char *mailbox;
if(imap->custom)
/* Send the custom request */
@@ -658,7 +617,8 @@ static CURLcode imap_perform_list(struct connectdata *conn)
imap->custom_params ? imap->custom_params : "");
else {
/* Make sure the mailbox is in the correct atom format if necessary */
- mailbox = imap->mailbox ? imap_atom(imap->mailbox, true) : strdup("");
+ char *mailbox = imap->mailbox ? imap_atom(imap->mailbox, true)
+ : strdup("");
if(!mailbox)
return CURLE_OUT_OF_MEMORY;
@@ -724,24 +684,37 @@ static CURLcode imap_perform_fetch(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct IMAP *imap = conn->data->req.protop;
-
/* Check we have a UID */
- if(!imap->uid) {
- failf(conn->data, "Cannot FETCH without a UID.");
- return CURLE_URL_MALFORMAT;
+ if(imap->uid) {
+
+ /* Send the FETCH command */
+ if(imap->partial)
+ result = imap_sendf(conn, "UID FETCH %s BODY[%s]<%s>",
+ imap->uid,
+ imap->section ? imap->section : "",
+ imap->partial);
+ else
+ result = imap_sendf(conn, "UID FETCH %s BODY[%s]",
+ imap->uid,
+ imap->section ? imap->section : "");
+ }
+ else if(imap->mindex) {
+
+ /* Send the FETCH command */
+ if(imap->partial)
+ result = imap_sendf(conn, "FETCH %s BODY[%s]<%s>",
+ imap->mindex,
+ imap->section ? imap->section : "",
+ imap->partial);
+ else
+ result = imap_sendf(conn, "FETCH %s BODY[%s]",
+ imap->mindex,
+ imap->section ? imap->section : "");
+ }
+ else {
+ failf(conn->data, "Cannot FETCH without a UID.");
+ return CURLE_URL_MALFORMAT;
}
-
- /* Send the FETCH command */
- if(imap->partial)
- result = imap_sendf(conn, "FETCH %s BODY[%s]<%s>",
- imap->uid,
- imap->section ? imap->section : "",
- imap->partial);
- else
- result = imap_sendf(conn, "FETCH %s BODY[%s]",
- imap->uid,
- imap->section ? imap->section : "");
-
if(!result)
state(conn, IMAP_FETCH);
@@ -757,18 +730,48 @@ static CURLcode imap_perform_fetch(struct connectdata *conn)
static CURLcode imap_perform_append(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
- struct IMAP *imap = conn->data->req.protop;
+ struct Curl_easy *data = conn->data;
+ struct IMAP *imap = data->req.protop;
char *mailbox;
/* Check we have a mailbox */
if(!imap->mailbox) {
- failf(conn->data, "Cannot APPEND without a mailbox.");
+ failf(data, "Cannot APPEND without a mailbox.");
return CURLE_URL_MALFORMAT;
}
+ /* Prepare the mime data if some. */
+ if(data->set.mimepost.kind != MIMEKIND_NONE) {
+ /* Use the whole structure as data. */
+ data->set.mimepost.flags &= ~MIME_BODY_ONLY;
+
+ /* Add external headers and mime version. */
+ curl_mime_headers(&data->set.mimepost, data->set.headers, 0);
+ result = Curl_mime_prepare_headers(&data->set.mimepost, NULL,
+ NULL, MIMESTRATEGY_MAIL);
+
+ if(!result)
+ if(!Curl_checkheaders(conn, "Mime-Version"))
+ result = Curl_mime_add_header(&data->set.mimepost.curlheaders,
+ "Mime-Version: 1.0");
+
+ /* Make sure we will read the entire mime structure. */
+ if(!result)
+ result = Curl_mime_rewind(&data->set.mimepost);
+
+ if(result)
+ return result;
+
+ data->state.infilesize = Curl_mime_size(&data->set.mimepost);
+
+ /* Read from mime structure. */
+ data->state.fread_func = (curl_read_callback) Curl_mime_read;
+ data->state.in = (void *) &data->set.mimepost;
+ }
+
/* Check we know the size of the upload */
- if(conn->data->state.infilesize < 0) {
- failf(conn->data, "Cannot APPEND with unknown input file size\n");
+ if(data->state.infilesize < 0) {
+ failf(data, "Cannot APPEND with unknown input file size\n");
return CURLE_UPLOAD_FAILED;
}
@@ -779,7 +782,7 @@ static CURLcode imap_perform_append(struct connectdata *conn)
/* Send the APPEND command */
result = imap_sendf(conn, "APPEND %s (\\Seen) {%" CURL_FORMAT_CURL_OFF_T "}",
- mailbox, conn->data->state.infilesize);
+ mailbox, data->state.infilesize);
free(mailbox);
@@ -839,19 +842,21 @@ static CURLcode imap_state_servergreet_resp(struct connectdata *conn,
int imapcode,
imapstate instate)
{
- CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
-
(void)instate; /* no use for this yet */
- if(imapcode != 'O') {
+ if(imapcode == IMAP_RESP_PREAUTH) {
+ /* PREAUTH */
+ struct imap_conn *imapc = &conn->proto.imapc;
+ imapc->preauth = TRUE;
+ infof(data, "PREAUTH connection, already authenticated!\n");
+ }
+ else if(imapcode != IMAP_RESP_OK) {
failf(data, "Got unexpected imap-server response");
- result = CURLE_WEIRD_SERVER_REPLY;
+ return CURLE_WEIRD_SERVER_REPLY;
}
- else
- result = imap_perform_capability(conn);
- return result;
+ return imap_perform_capability(conn);
}
/* For CAPABILITY responses */
@@ -863,7 +868,6 @@ static CURLcode imap_state_capability_resp(struct connectdata *conn,
struct Curl_easy *data = conn->data;
struct imap_conn *imapc = &conn->proto.imapc;
const char *line = data->state.buffer;
- size_t wordlen;
(void)instate; /* no use for this yet */
@@ -873,6 +877,7 @@ static CURLcode imap_state_capability_resp(struct connectdata *conn,
/* Loop through the data line */
for(;;) {
+ size_t wordlen;
while(*line &&
(*line == ' ' || *line == '\t' ||
*line == '\r' || *line == '\n')) {
@@ -918,7 +923,7 @@ static CURLcode imap_state_capability_resp(struct connectdata *conn,
line += wordlen;
}
}
- else if(imapcode == 'O') {
+ else if(imapcode == IMAP_RESP_OK) {
if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
/* We don't have a SSL/TLS connection yet, but SSL is requested */
if(imapc->tls_supported)
@@ -951,7 +956,7 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn,
(void)instate; /* no use for this yet */
- if(imapcode != 'O') {
+ if(imapcode != IMAP_RESP_OK) {
if(data->set.use_ssl != CURLUSESSL_TRY) {
failf(data, "STARTTLS denied");
result = CURLE_USE_SSL_FAILED;
@@ -1009,7 +1014,7 @@ static CURLcode imap_state_login_resp(struct connectdata *conn,
(void)instate; /* no use for this yet */
- if(imapcode != 'O') {
+ if(imapcode != IMAP_RESP_OK) {
failf(data, "Access denied. %c", imapcode);
result = CURLE_LOGIN_DENIED;
}
@@ -1037,8 +1042,8 @@ static CURLcode imap_state_listsearch_resp(struct connectdata *conn,
result = Curl_client_write(conn, CLIENTWRITE_BODY, line, len + 1);
line[len] = '\0';
}
- else if(imapcode != 'O')
- result = CURLE_QUOTE_ERROR; /* TODO: Fix error code */
+ else if(imapcode != IMAP_RESP_OK)
+ result = CURLE_QUOTE_ERROR;
else
/* End of DO phase */
state(conn, IMAP_STOP);
@@ -1055,21 +1060,21 @@ static CURLcode imap_state_select_resp(struct connectdata *conn, int imapcode,
struct IMAP *imap = conn->data->req.protop;
struct imap_conn *imapc = &conn->proto.imapc;
const char *line = data->state.buffer;
- char tmp[20];
(void)instate; /* no use for this yet */
if(imapcode == '*') {
/* See if this is an UIDVALIDITY response */
+ char tmp[20];
if(sscanf(line + 2, "OK [UIDVALIDITY %19[0123456789]]", tmp) == 1) {
Curl_safefree(imapc->mailbox_uidvalidity);
imapc->mailbox_uidvalidity = strdup(tmp);
}
}
- else if(imapcode == 'O') {
+ else if(imapcode == IMAP_RESP_OK) {
/* Check if the UIDVALIDITY has been specified and matches */
if(imap->uidvalidity && imapc->mailbox_uidvalidity &&
- strcmp(imap->uidvalidity, imapc->mailbox_uidvalidity)) {
+ !strcasecompare(imap->uidvalidity, imapc->mailbox_uidvalidity)) {
failf(conn->data, "Mailbox UIDVALIDITY has changed");
result = CURLE_REMOTE_FILE_NOT_FOUND;
}
@@ -1110,7 +1115,7 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn, int imapcode,
if(imapcode != '*') {
Curl_pgrsSetDownloadSize(data, -1);
state(conn, IMAP_STOP);
- return CURLE_REMOTE_FILE_NOT_FOUND; /* TODO: Fix error code */
+ return CURLE_REMOTE_FILE_NOT_FOUND;
}
/* Something like this is received "* 1 FETCH (BODY[TEXT] {2021}\r" so parse
@@ -1120,14 +1125,15 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn, int imapcode,
if(*ptr == '{') {
char *endptr;
- size = curlx_strtoofft(ptr + 1, &endptr, 10);
- if(endptr - ptr > 1 && endptr[0] == '}' &&
- endptr[1] == '\r' && endptr[2] == '\0')
- parsed = TRUE;
+ if(!curlx_strtoofft(ptr + 1, &endptr, 10, &size)) {
+ if(endptr - ptr > 1 && endptr[0] == '}' &&
+ endptr[1] == '\r' && endptr[2] == '\0')
+ parsed = TRUE;
+ }
}
if(parsed) {
- infof(data, "Found %" CURL_FORMAT_CURL_OFF_TU " bytes to download\n",
+ infof(data, "Found %" CURL_FORMAT_CURL_OFF_T " bytes to download\n",
size);
Curl_pgrsSetDownloadSize(data, size);
@@ -1141,16 +1147,19 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn, int imapcode,
/* The conversion from curl_off_t to size_t is always fine here */
chunk = (size_t)size;
+ if(!chunk) {
+ /* no size, we're done with the data */
+ state(conn, IMAP_STOP);
+ return CURLE_OK;
+ }
result = Curl_client_write(conn, CLIENTWRITE_BODY, pp->cache, chunk);
if(result)
return result;
data->req.bytecount += chunk;
- infof(data, "Written %" CURL_FORMAT_CURL_OFF_TU
- " bytes, %" CURL_FORMAT_CURL_OFF_TU
- " bytes are left for transfer\n", (curl_off_t)chunk,
- size - chunk);
+ infof(data, "Written %zu bytes, %" CURL_FORMAT_CURL_OFF_TU
+ " bytes are left for transfer\n", chunk, size - chunk);
/* Have we used the entire cache or just part of it?*/
if(pp->cache_size > chunk) {
@@ -1169,11 +1178,11 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn, int imapcode,
if(data->req.bytecount == size)
/* The entire data is already transferred! */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
else {
/* IMAP download */
data->req.maxdownload = size;
- Curl_setup_transfer(conn, FIRSTSOCKET, size, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, size, FALSE, -1);
}
}
else {
@@ -1197,7 +1206,7 @@ static CURLcode imap_state_fetch_final_resp(struct connectdata *conn,
(void)instate; /* No use for this yet */
- if(imapcode != 'O')
+ if(imapcode != IMAP_RESP_OK)
result = CURLE_WEIRD_SERVER_REPLY;
else
/* End of DONE phase */
@@ -1223,7 +1232,7 @@ static CURLcode imap_state_append_resp(struct connectdata *conn, int imapcode,
Curl_pgrsSetUploadSize(data, data->state.infilesize);
/* IMAP upload */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
/* End of DO phase */
state(conn, IMAP_STOP);
@@ -1241,7 +1250,7 @@ static CURLcode imap_state_append_final_resp(struct connectdata *conn,
(void)instate; /* No use for this yet */
- if(imapcode != 'O')
+ if(imapcode != IMAP_RESP_OK)
result = CURLE_UPLOAD_FAILED;
else
/* End of DONE phase */
@@ -1354,19 +1363,20 @@ static CURLcode imap_multi_statemach(struct connectdata *conn, bool *done)
return result;
}
- result = Curl_pp_statemach(&imapc->pp, FALSE);
+ result = Curl_pp_statemach(&imapc->pp, FALSE, FALSE);
*done = (imapc->state == IMAP_STOP) ? TRUE : FALSE;
return result;
}
-static CURLcode imap_block_statemach(struct connectdata *conn)
+static CURLcode imap_block_statemach(struct connectdata *conn,
+ bool disconnecting)
{
CURLcode result = CURLE_OK;
struct imap_conn *imapc = &conn->proto.imapc;
while(imapc->state != IMAP_STOP && !result)
- result = Curl_pp_statemach(&imapc->pp, TRUE);
+ result = Curl_pp_statemach(&imapc->pp, TRUE, disconnecting);
return result;
}
@@ -1469,9 +1479,11 @@ static CURLcode imap_done(struct connectdata *conn, CURLcode status,
result = status; /* use the already set error code */
}
else if(!data->set.connect_only && !imap->custom &&
- (imap->uid || data->set.upload)) {
+ (imap->uid || imap->mindex || data->set.upload ||
+ data->set.mimepost.kind != MIMEKIND_NONE)) {
/* Handle responses after FETCH or APPEND transfer has finished */
- if(!data->set.upload)
+
+ if(!data->set.upload && data->set.mimepost.kind == MIMEKIND_NONE)
state(conn, IMAP_FETCH_FINAL);
else {
/* End the APPEND command first by sending an empty line */
@@ -1480,20 +1492,16 @@ static CURLcode imap_done(struct connectdata *conn, CURLcode status,
state(conn, IMAP_APPEND_FINAL);
}
- /* Run the state-machine
-
- TODO: when the multi interface is used, this _really_ should be using
- the imap_multi_statemach function but we have no general support for
- non-blocking DONE operations!
- */
+ /* Run the state-machine */
if(!result)
- result = imap_block_statemach(conn);
+ result = imap_block_statemach(conn, FALSE);
}
/* Cleanup our per-request based variables */
Curl_safefree(imap->mailbox);
Curl_safefree(imap->uidvalidity);
Curl_safefree(imap->uid);
+ Curl_safefree(imap->mindex);
Curl_safefree(imap->section);
Curl_safefree(imap->partial);
Curl_safefree(imap->query);
@@ -1535,26 +1543,26 @@ static CURLcode imap_perform(struct connectdata *conn, bool *connected,
/* Determine if the requested mailbox (with the same UIDVALIDITY if set)
has already been selected on this connection */
if(imap->mailbox && imapc->mailbox &&
- !strcmp(imap->mailbox, imapc->mailbox) &&
+ strcasecompare(imap->mailbox, imapc->mailbox) &&
(!imap->uidvalidity || !imapc->mailbox_uidvalidity ||
- !strcmp(imap->uidvalidity, imapc->mailbox_uidvalidity)))
+ strcasecompare(imap->uidvalidity, imapc->mailbox_uidvalidity)))
selected = TRUE;
/* Start the first command in the DO phase */
- if(conn->data->set.upload)
+ if(conn->data->set.upload || data->set.mimepost.kind != MIMEKIND_NONE)
/* APPEND can be executed directly */
result = imap_perform_append(conn);
else if(imap->custom && (selected || !imap->mailbox))
/* Custom command using the same mailbox or no mailbox */
result = imap_perform_list(conn);
- else if(!imap->custom && selected && imap->uid)
+ else if(!imap->custom && selected && (imap->uid || imap->mindex))
/* FETCH from the same mailbox */
result = imap_perform_fetch(conn);
else if(!imap->custom && selected && imap->query)
/* SEARCH the current mailbox */
result = imap_perform_search(conn);
else if(imap->mailbox && !selected &&
- (imap->custom || imap->uid || imap->query))
+ (imap->custom || imap->uid || imap->mindex || imap->query))
/* SELECT the mailbox */
result = imap_perform_select(conn);
else
@@ -1624,7 +1632,7 @@ static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection)
point! */
if(!dead_connection && imapc->pp.conn && imapc->pp.conn->bits.protoconnstart)
if(!imap_perform_logout(conn))
- (void)imap_block_statemach(conn); /* ignore errors on LOGOUT */
+ (void)imap_block_statemach(conn, TRUE); /* ignore errors on LOGOUT */
/* Disconnect from the server */
Curl_pp_disconnect(&imapc->pp);
@@ -1648,7 +1656,7 @@ static CURLcode imap_dophase_done(struct connectdata *conn, bool connected)
if(imap->transfer != FTPTRANSFER_BODY)
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(conn->data, -1, -1, FALSE, -1);
return CURLE_OK;
}
@@ -1706,8 +1714,6 @@ static CURLcode imap_regular_transfer(struct connectdata *conn,
static CURLcode imap_setup_connection(struct connectdata *conn)
{
- struct Curl_easy *data = conn->data;
-
/* Initialise the IMAP layer */
CURLcode result = imap_init(conn);
if(result)
@@ -1716,32 +1722,6 @@ static CURLcode imap_setup_connection(struct connectdata *conn)
/* Clear the TLS upgraded flag */
conn->tls_upgraded = FALSE;
- /* Set up the proxy if necessary */
- if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
- /* Unless we have asked to tunnel IMAP operations through the proxy, we
- switch and use HTTP operations only */
-#ifndef CURL_DISABLE_HTTP
- if(conn->handler == &Curl_handler_imap)
- conn->handler = &Curl_handler_imap_proxy;
- else {
-#ifdef USE_SSL
- conn->handler = &Curl_handler_imaps_proxy;
-#else
- failf(data, "IMAPS not supported!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
-
- /* set it up as an HTTP connection instead */
- return conn->handler->setup_connection(conn);
-#else
- failf(data, "IMAP over http proxy requires HTTP support built-in!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
-
- data->state.path++; /* don't include the initial slash */
-
return CURLE_OK;
}
@@ -1766,8 +1746,8 @@ static CURLcode imap_sendf(struct connectdata *conn, const char *fmt, ...)
imapc->cmdid = (imapc->cmdid + 1) % 1000;
/* Calculate the tag based on the connection ID and command ID */
- snprintf(imapc->resptag, sizeof(imapc->resptag), "%c%03d",
- 'A' + curlx_sltosi(conn->connection_id % 26), imapc->cmdid);
+ msnprintf(imapc->resptag, sizeof(imapc->resptag), "%c%03d",
+ 'A' + curlx_sltosi(conn->connection_id % 26), imapc->cmdid);
/* Prefix the format with the tag */
taggedfmt = aprintf("%s %s", imapc->resptag, fmt);
@@ -1810,7 +1790,7 @@ static char *imap_atom(const char *str, bool escape_only)
return NULL;
/* Look for "atom-specials", counting the backslash and quote characters as
- these will need escapping */
+ these will need escaping */
p1 = str;
while(*p1) {
if(*p1 == '\\')
@@ -1836,7 +1816,7 @@ static char *imap_atom(const char *str, bool escape_only)
return strdup(str);
/* Calculate the new string length */
- newlen = strlen(str) + backsp_count + quote_count + (others_exists ? 2 : 0);
+ newlen = strlen(str) + backsp_count + quote_count + (escape_only ? 0 : 2);
/* Allocate the new string */
newstr = (char *) malloc((newlen + 1) * sizeof(char));
@@ -1845,7 +1825,7 @@ static char *imap_atom(const char *str, bool escape_only)
/* Surround the string in quotes if necessary */
p2 = newstr;
- if(others_exists) {
+ if(!escape_only) {
newstr[0] = '"';
newstr[newlen - 1] = '"';
p2++;
@@ -1973,7 +1953,7 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
struct IMAP *imap = data->req.protop;
- const char *begin = data->state.path;
+ const char *begin = &data->state.up.path[1]; /* skip leading slash */
const char *ptr = begin;
/* See how much of the URL is a valid path and decode it */
@@ -2045,6 +2025,13 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
imap->uid = value;
value = NULL;
}
+ else if(strcasecompare(name, "MAILINDEX") && !imap->mindex) {
+ if(valuelen > 0 && value[valuelen - 1] == '/')
+ value[valuelen - 1] = '\0';
+
+ imap->mindex = value;
+ value = NULL;
+ }
else if(strcasecompare(name, "SECTION") && !imap->section) {
if(valuelen > 0 && value[valuelen - 1] == '/')
value[valuelen - 1] = '\0';
@@ -2072,17 +2059,10 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
/* Does the URL contain a query parameter? Only valid when we have a mailbox
and no UID as per RFC-5092 */
- if(imap->mailbox && !imap->uid && *ptr == '?') {
- /* Find the length of the query parameter */
- begin = ++ptr;
- while(imap_is_bchar(*ptr))
- ptr++;
-
- /* Decode the query parameter */
- result = Curl_urldecode(data, begin, ptr - begin, &imap->query, NULL,
- TRUE);
- if(result)
- return result;
+ if(imap->mailbox && !imap->uid && !imap->mindex) {
+ /* Get the query parameter, URL decoded */
+ (void)curl_url_get(data->state.uh, CURLUPART_QUERY, &imap->query,
+ CURLU_URLDECODE);
}
/* Any extra stuff at the end of the URL is an error */
diff --git a/Utilities/cmcurl/lib/imap.h b/Utilities/cmcurl/lib/imap.h
index 5e0e228f5..0efcfd293 100644
--- a/Utilities/cmcurl/lib/imap.h
+++ b/Utilities/cmcurl/lib/imap.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2009 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2009 - 2017, 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
@@ -58,6 +58,7 @@ struct IMAP {
char *mailbox; /* Mailbox to select */
char *uidvalidity; /* UIDVALIDITY to check in select */
char *uid; /* Message UID to fetch */
+ char *mindex; /* Index in mail box of mail to fetch */
char *section; /* Message SECTION to fetch */
char *partial; /* Message PARTIAL to fetch */
char *query; /* Query to search for */
@@ -71,6 +72,7 @@ struct imap_conn {
struct pingpong pp;
imapstate state; /* Always use imap.c:state() to change state! */
bool ssldone; /* Is connect() over SSL done? */
+ bool preauth; /* Is this connection PREAUTH? */
struct SASL sasl; /* SASL-related parameters */
unsigned int preftype; /* Preferred authentication type */
int cmdid; /* Last used command ID */
diff --git a/Utilities/cmcurl/lib/inet_ntop.c b/Utilities/cmcurl/lib/inet_ntop.c
index 9afbdbb32..855981c66 100644
--- a/Utilities/cmcurl/lib/inet_ntop.c
+++ b/Utilities/cmcurl/lib/inet_ntop.c
@@ -49,21 +49,21 @@
*/
static char *inet_ntop4 (const unsigned char *src, char *dst, size_t size)
{
- char tmp[sizeof "255.255.255.255"];
+ char tmp[sizeof("255.255.255.255")];
size_t len;
DEBUGASSERT(size >= 16);
tmp[0] = '\0';
- (void)snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d",
- ((int)((unsigned char)src[0])) & 0xff,
- ((int)((unsigned char)src[1])) & 0xff,
- ((int)((unsigned char)src[2])) & 0xff,
- ((int)((unsigned char)src[3])) & 0xff);
+ (void)msnprintf(tmp, sizeof(tmp), "%d.%d.%d.%d",
+ ((int)((unsigned char)src[0])) & 0xff,
+ ((int)((unsigned char)src[1])) & 0xff,
+ ((int)((unsigned char)src[2])) & 0xff,
+ ((int)((unsigned char)src[3])) & 0xff);
len = strlen(tmp);
if(len == 0 || len >= size) {
- SET_ERRNO(ENOSPC);
+ errno = ENOSPC;
return (NULL);
}
strcpy(dst, tmp);
@@ -141,14 +141,14 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
*/
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);
+ if(!inet_ntop4(src + 12, tp, sizeof(tmp) - (tp - tmp))) {
+ errno = ENOSPC;
return (NULL);
}
tp += strlen(tp);
break;
}
- tp += snprintf(tp, 5, "%lx", words[i]);
+ tp += msnprintf(tp, 5, "%lx", words[i]);
}
/* Was it a trailing run of 0x00's?
@@ -160,7 +160,7 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
/* Check for overflow, copy, and we're done.
*/
if((size_t)(tp - tmp) > size) {
- SET_ERRNO(ENOSPC);
+ errno = ENOSPC;
return (NULL);
}
strcpy(dst, tmp);
@@ -177,8 +177,8 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
*
* On Windows we store the error in the thread errno, not
* in the winsock error code. This is to avoid losing the
- * actual last winsock error. So use macro ERRNO to fetch the
- * errno this function sets when returning NULL, not SOCKERRNO.
+ * actual last winsock error. So when this function returns
+ * NULL, check errno not SOCKERRNO.
*/
char *Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
{
@@ -190,7 +190,7 @@ char *Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
return inet_ntop6((const unsigned char *)src, buf, size);
#endif
default:
- SET_ERRNO(EAFNOSUPPORT);
+ errno = EAFNOSUPPORT;
return NULL;
}
}
diff --git a/Utilities/cmcurl/lib/inet_ntop.h b/Utilities/cmcurl/lib/inet_ntop.h
index 9f4461271..d150bb693 100644
--- a/Utilities/cmcurl/lib/inet_ntop.h
+++ b/Utilities/cmcurl/lib/inet_ntop.h
@@ -35,4 +35,3 @@ char *Curl_inet_ntop(int af, const void *addr, char *buf, size_t size);
#endif
#endif /* HEADER_CURL_INET_NTOP_H */
-
diff --git a/Utilities/cmcurl/lib/inet_pton.c b/Utilities/cmcurl/lib/inet_pton.c
index 475f44abc..0d65ae0ec 100644
--- a/Utilities/cmcurl/lib/inet_pton.c
+++ b/Utilities/cmcurl/lib/inet_pton.c
@@ -57,8 +57,8 @@ static int inet_pton6(const char *src, unsigned char *dst);
* notice:
* On Windows we store the error in the thread errno, not
* in the winsock error code. This is to avoid losing the
- * actual last winsock error. So use macro ERRNO to fetch the
- * errno this function sets when returning (-1), not SOCKERRNO.
+ * actual last winsock error. So when this function returns
+ * -1, check errno not SOCKERRNO.
* author:
* Paul Vixie, 1996.
*/
@@ -73,7 +73,7 @@ Curl_inet_pton(int af, const char *src, void *dst)
return (inet_pton6(src, (unsigned char *)dst));
#endif
default:
- SET_ERRNO(EAFNOSUPPORT);
+ errno = EAFNOSUPPORT;
return (-1);
}
/* NOTREACHED */
@@ -153,7 +153,7 @@ 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;
+ const char *curtok;
int ch, saw_xdigit;
size_t val;
@@ -168,6 +168,7 @@ inet_pton6(const char *src, unsigned char *dst)
saw_xdigit = 0;
val = 0;
while((ch = *src++) != '\0') {
+ const char *xdigits;
const char *pch;
pch = strchr((xdigits = xdigits_l), ch);
diff --git a/Utilities/cmcurl/lib/inet_pton.h b/Utilities/cmcurl/lib/inet_pton.h
index 9188d9598..0209b9b7b 100644
--- a/Utilities/cmcurl/lib/inet_pton.h
+++ b/Utilities/cmcurl/lib/inet_pton.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -29,9 +29,11 @@ int Curl_inet_pton(int, const char *, void *);
#ifdef HAVE_INET_PTON
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
+#elif defined(HAVE_WS2TCPIP_H)
+/* inet_pton() exists in Vista or later */
+#include <ws2tcpip.h>
#endif
#define Curl_inet_pton(x,y,z) inet_pton(x,y,z)
#endif
#endif /* HEADER_CURL_INET_PTON_H */
-
diff --git a/Utilities/cmcurl/lib/krb5.c b/Utilities/cmcurl/lib/krb5.c
index 69a35979a..147ab024e 100644
--- a/Utilities/cmcurl/lib/krb5.c
+++ b/Utilities/cmcurl/lib/krb5.c
@@ -1,8 +1,8 @@
/* GSSAPI/krb5 support for FTP - loosely based on old krb4.c
*
- * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
+ * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
- * Copyright (c) 2004 - 2016 Daniel Stenberg
+ * Copyright (c) 2004 - 2017 Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -85,7 +85,7 @@ krb5_decode(void *app_data, void *buf, int len,
enc.value = buf;
enc.length = len;
- maj = gss_unseal(&min, *context, &enc, &dec, NULL, NULL);
+ maj = gss_unwrap(&min, *context, &enc, &dec, NULL, NULL);
if(maj != GSS_S_COMPLETE) {
if(len >= 4)
strcpy(buf, "599 ");
@@ -119,11 +119,11 @@ krb5_encode(void *app_data, const void *from, int length, int level, void **to)
int len;
/* NOTE that the cast is safe, neither of the krb5, gnu gss and heimdal
- * libraries modify the input buffer in gss_seal()
+ * libraries modify the input buffer in gss_wrap()
*/
dec.value = (void *)from;
dec.length = length;
- maj = gss_seal(&min, *context,
+ maj = gss_wrap(&min, *context,
level == PROT_PRIVATE,
GSS_C_QOP_DEFAULT,
&dec, &state, &enc);
@@ -206,7 +206,7 @@ krb5_auth(void *app_data, struct connectdata *conn)
if(maj != GSS_S_COMPLETE) {
gss_release_name(&min, &gssname);
if(service == srv_host) {
- Curl_failf(data, "Error importing service name %s@%s", service, host);
+ failf(data, "Error importing service name %s@%s", service, host);
return AUTH_ERROR;
}
service = srv_host;
@@ -265,6 +265,7 @@ krb5_auth(void *app_data, struct connectdata *conn)
result = CURLE_OUT_OF_MEMORY;
free(p);
+ free(cmd);
if(result) {
ret = -2;
@@ -282,6 +283,7 @@ krb5_auth(void *app_data, struct connectdata *conn)
break;
}
+ _gssresp.value = NULL; /* make sure it is initialized */
p = data->state.buffer + 4;
p = strstr(p, "ADAT=");
if(p) {
@@ -289,8 +291,7 @@ krb5_auth(void *app_data, struct connectdata *conn)
(unsigned char **)&_gssresp.value,
&_gssresp.length);
if(result) {
- Curl_failf(data, "base64-decoding: %s",
- curl_easy_strerror(result));
+ failf(data, "base64-decoding: %s", curl_easy_strerror(result));
ret = AUTH_CONTINUE;
break;
}
diff --git a/Utilities/cmcurl/lib/ldap.c b/Utilities/cmcurl/lib/ldap.c
index 79e84d94e..fd31faa3e 100644
--- a/Utilities/cmcurl/lib/ldap.c
+++ b/Utilities/cmcurl/lib/ldap.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -54,15 +54,6 @@
# endif /* HAVE_LDAP_SSL && HAVE_LDAP_SSL_H */
#endif
-/* These are macros in both <wincrypt.h> (in above <winldap.h>) and typedefs
- * in BoringSSL's <openssl/x509.h>
- */
-#ifdef HAVE_BORINGSSL
-# undef X509_NAME
-# undef X509_CERT_PAIR
-# undef X509_EXTENSIONS
-#endif
-
#include "urldata.h"
#include <curl/curl.h>
#include "sendf.h"
@@ -150,6 +141,7 @@ const struct Curl_handler Curl_handler_ldap = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_LDAP, /* defport */
CURLPROTO_LDAP, /* protocol */
PROTOPT_NONE /* flags */
@@ -175,6 +167,7 @@ const struct Curl_handler Curl_handler_ldaps = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_LDAPS, /* defport */
CURLPROTO_LDAPS, /* protocol */
PROTOPT_SSL /* flags */
@@ -188,9 +181,11 @@ static int ldap_win_bind_auth(LDAP *server, const char *user,
const char *passwd, unsigned long authflags)
{
ULONG method = 0;
- SEC_WINNT_AUTH_IDENTITY cred = { 0, };
+ SEC_WINNT_AUTH_IDENTITY cred;
int rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
+ memset(&cred, 0, sizeof(cred));
+
#if defined(USE_SPNEGO)
if(authflags & CURLAUTH_NEGOTIATE) {
method = LDAP_AUTH_NEGOTIATE;
@@ -233,7 +228,6 @@ static int ldap_win_bind(struct connectdata *conn, LDAP *server,
const char *user, const char *passwd)
{
int rc = LDAP_INVALID_CREDENTIALS;
- ULONG method = LDAP_AUTH_SIMPLE;
PTCHAR inuser = NULL;
PTCHAR inpass = NULL;
@@ -242,7 +236,7 @@ static int ldap_win_bind(struct connectdata *conn, LDAP *server,
inuser = Curl_convert_UTF8_to_tchar((char *) user);
inpass = Curl_convert_UTF8_to_tchar((char *) passwd);
- rc = ldap_bind_s(server, inuser, inpass, method);
+ rc = ldap_simple_bind_s(server, inuser, inpass);
Curl_unicodefree(inuser);
Curl_unicodefree(inpass);
@@ -266,7 +260,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
LDAPMessage *ldapmsg = NULL;
LDAPMessage *entryIterator;
int num = 0;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
int ldap_proto = LDAP_VERSION3;
int ldap_ssl = 0;
char *val_b64 = NULL;
@@ -480,7 +474,13 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
#endif
}
if(rc != 0) {
- failf(data, "LDAP local: ldap_simple_bind_s %s", ldap_err2string(rc));
+#ifdef USE_WIN32_LDAP
+ failf(data, "LDAP local: bind via ldap_win_bind %s",
+ ldap_err2string(rc));
+#else
+ failf(data, "LDAP local: bind via ldap_simple_bind_s %s",
+ ldap_err2string(rc));
+#endif
result = CURLE_LDAP_CANNOT_BIND;
goto quit;
}
@@ -744,7 +744,7 @@ quit:
#endif
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
connclose(conn, "LDAP connection always disable re-use");
return result;
@@ -839,14 +839,15 @@ static int _ldap_url_parse2(const struct connectdata *conn, LDAPURLDesc *ludp)
{
int rc = LDAP_SUCCESS;
char *path;
+ char *query;
char *p;
char *q;
size_t i;
if(!conn->data ||
- !conn->data->state.path ||
- conn->data->state.path[0] != '/' ||
- !checkprefix("LDAP", conn->data->change.url))
+ !conn->data->state.up.path ||
+ conn->data->state.up.path[0] != '/' ||
+ !strncasecompare("LDAP", conn->data->state.up.scheme, 4))
return LDAP_INVALID_SYNTAX;
ludp->lud_scope = LDAP_SCOPE_BASE;
@@ -854,15 +855,18 @@ static int _ldap_url_parse2(const struct connectdata *conn, LDAPURLDesc *ludp)
ludp->lud_host = conn->host.name;
/* Duplicate the path */
- p = path = strdup(conn->data->state.path + 1);
+ p = path = strdup(conn->data->state.up.path + 1);
if(!path)
return LDAP_NO_MEMORY;
- /* Parse the DN (Distinguished Name) */
- q = strchr(p, '?');
- if(q)
- *q++ = '\0';
+ /* Duplicate the query */
+ q = query = strdup(conn->data->state.up.query);
+ if(!query) {
+ free(path);
+ return LDAP_NO_MEMORY;
+ }
+ /* Parse the DN (Distinguished Name) */
if(*p) {
char *dn = p;
char *unescaped;
@@ -1039,6 +1043,7 @@ static int _ldap_url_parse2(const struct connectdata *conn, LDAPURLDesc *ludp)
quit:
free(path);
+ free(query);
return rc;
}
@@ -1064,8 +1069,6 @@ static int _ldap_url_parse(const struct connectdata *conn,
static void _ldap_free_urldesc(LDAPURLDesc *ludp)
{
- size_t i;
-
if(!ludp)
return;
@@ -1073,6 +1076,7 @@ static void _ldap_free_urldesc(LDAPURLDesc *ludp)
free(ludp->lud_filter);
if(ludp->lud_attrs) {
+ size_t i;
for(i = 0; i < ludp->lud_attrs_dups; i++)
free(ludp->lud_attrs[i]);
free(ludp->lud_attrs);
diff --git a/Utilities/cmcurl/lib/libcurl.rc b/Utilities/cmcurl/lib/libcurl.rc
index 3316fba19..4839d0a65 100644
--- a/Utilities/cmcurl/lib/libcurl.rc
+++ b/Utilities/cmcurl/lib/libcurl.rc
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -22,22 +22,22 @@
#include <winver.h>
#include "../include/curl/curlver.h"
-LANGUAGE 0x09,0x01
+LANGUAGE 0, 0
#define RC_VERSION LIBCURL_VERSION_MAJOR, LIBCURL_VERSION_MINOR, LIBCURL_VERSION_PATCH, 0
VS_VERSION_INFO VERSIONINFO
FILEVERSION RC_VERSION
PRODUCTVERSION RC_VERSION
- FILEFLAGSMASK 0x3fL
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#if defined(DEBUGBUILD) || defined(_DEBUG)
- FILEFLAGS 1
+ FILEFLAGS VS_FF_DEBUG
#else
- FILEFLAGS 0
+ FILEFLAGS 0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
- FILESUBTYPE 0x0L
+ FILESUBTYPE 0L
BEGIN
BLOCK "StringFileInfo"
diff --git a/Utilities/cmcurl/lib/llist.c b/Utilities/cmcurl/lib/llist.c
index 4bb0a51b8..f8769c2af 100644
--- a/Utilities/cmcurl/lib/llist.c
+++ b/Utilities/cmcurl/lib/llist.c
@@ -106,7 +106,11 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
e->next->prev = NULL;
}
else {
- e->prev->next = e->next;
+ if(!e->prev)
+ list->head = e->next;
+ else
+ e->prev->next = e->next;
+
if(!e->next)
list->tail = e->prev;
else
diff --git a/Utilities/cmcurl/lib/llist.h b/Utilities/cmcurl/lib/llist.h
index 6b644b99c..b9d4c89a9 100644
--- a/Utilities/cmcurl/lib/llist.h
+++ b/Utilities/cmcurl/lib/llist.h
@@ -51,4 +51,3 @@ void Curl_llist_move(struct curl_llist *, struct curl_llist_element *,
struct curl_llist *, struct curl_llist_element *);
#endif /* HEADER_CURL_LLIST_H */
-
diff --git a/Utilities/cmcurl/lib/md4.c b/Utilities/cmcurl/lib/md4.c
index 2bb7dcc25..e7c77bc36 100644
--- a/Utilities/cmcurl/lib/md4.c
+++ b/Utilities/cmcurl/lib/md4.c
@@ -1,9 +1,10 @@
/*
+ * !checksrc! disable COPYRIGHT
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
* MD4 Message-Digest Algorithm (RFC 1320).
*
* Homepage:
- http://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
+ https://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
*
* Author:
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
@@ -37,9 +38,11 @@
#include "curl_setup.h"
-/* The NSS, OS/400 and sometimes mbed TLS crypto libraries do not provide the
- * MD4 hash algorithm, so we have a local implementation of it */
+/* The NSS, OS/400, and when not included, OpenSSL and mbed TLS crypto
+ * libraries do not provide the MD4 hash algorithm, so we use this
+ * implementation of it */
#if defined(USE_NSS) || defined(USE_OS400CRYPTO) || \
+ (defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) || \
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C))
#include "curl_md4.h"
@@ -112,7 +115,6 @@ static const void *body(MD4_CTX *ctx, const void *data, unsigned long size)
{
const unsigned char *ptr;
MD4_u32plus a, b, c, d;
- MD4_u32plus saved_a, saved_b, saved_c, saved_d;
ptr = (const unsigned char *)data;
@@ -122,6 +124,8 @@ static const void *body(MD4_CTX *ctx, const void *data, unsigned long size)
d = ctx->d;
do {
+ MD4_u32plus saved_a, saved_b, saved_c, saved_d;
+
saved_a = a;
saved_b = b;
saved_c = c;
@@ -129,59 +133,59 @@ static const void *body(MD4_CTX *ctx, const void *data, unsigned long size)
/* Round 1 */
STEP(F, a, b, c, d, SET(0), 3)
- STEP(F, d, a, b, c, SET(1), 7)
- STEP(F, c, d, a, b, SET(2), 11)
- STEP(F, b, c, d, a, SET(3), 19)
- STEP(F, a, b, c, d, SET(4), 3)
- STEP(F, d, a, b, c, SET(5), 7)
- STEP(F, c, d, a, b, SET(6), 11)
- STEP(F, b, c, d, a, SET(7), 19)
- STEP(F, a, b, c, d, SET(8), 3)
- STEP(F, d, a, b, c, SET(9), 7)
- STEP(F, c, d, a, b, SET(10), 11)
- STEP(F, b, c, d, a, SET(11), 19)
- STEP(F, a, b, c, d, SET(12), 3)
- STEP(F, d, a, b, c, SET(13), 7)
- STEP(F, c, d, a, b, SET(14), 11)
- STEP(F, b, c, d, a, SET(15), 19)
+ STEP(F, d, a, b, c, SET(1), 7)
+ STEP(F, c, d, a, b, SET(2), 11)
+ STEP(F, b, c, d, a, SET(3), 19)
+ STEP(F, a, b, c, d, SET(4), 3)
+ STEP(F, d, a, b, c, SET(5), 7)
+ STEP(F, c, d, a, b, SET(6), 11)
+ STEP(F, b, c, d, a, SET(7), 19)
+ STEP(F, a, b, c, d, SET(8), 3)
+ STEP(F, d, a, b, c, SET(9), 7)
+ STEP(F, c, d, a, b, SET(10), 11)
+ STEP(F, b, c, d, a, SET(11), 19)
+ STEP(F, a, b, c, d, SET(12), 3)
+ STEP(F, d, a, b, c, SET(13), 7)
+ STEP(F, c, d, a, b, SET(14), 11)
+ STEP(F, b, c, d, a, SET(15), 19)
/* Round 2 */
- STEP(G, a, b, c, d, GET(0) + 0x5a827999, 3)
- STEP(G, d, a, b, c, GET(4) + 0x5a827999, 5)
- STEP(G, c, d, a, b, GET(8) + 0x5a827999, 9)
- STEP(G, b, c, d, a, GET(12) + 0x5a827999, 13)
- STEP(G, a, b, c, d, GET(1) + 0x5a827999, 3)
- STEP(G, d, a, b, c, GET(5) + 0x5a827999, 5)
- STEP(G, c, d, a, b, GET(9) + 0x5a827999, 9)
- STEP(G, b, c, d, a, GET(13) + 0x5a827999, 13)
- STEP(G, a, b, c, d, GET(2) + 0x5a827999, 3)
- STEP(G, d, a, b, c, GET(6) + 0x5a827999, 5)
- STEP(G, c, d, a, b, GET(10) + 0x5a827999, 9)
- STEP(G, b, c, d, a, GET(14) + 0x5a827999, 13)
- STEP(G, a, b, c, d, GET(3) + 0x5a827999, 3)
- STEP(G, d, a, b, c, GET(7) + 0x5a827999, 5)
- STEP(G, c, d, a, b, GET(11) + 0x5a827999, 9)
- STEP(G, b, c, d, a, GET(15) + 0x5a827999, 13)
+ STEP(G, a, b, c, d, GET(0) + 0x5a827999, 3)
+ STEP(G, d, a, b, c, GET(4) + 0x5a827999, 5)
+ STEP(G, c, d, a, b, GET(8) + 0x5a827999, 9)
+ STEP(G, b, c, d, a, GET(12) + 0x5a827999, 13)
+ STEP(G, a, b, c, d, GET(1) + 0x5a827999, 3)
+ STEP(G, d, a, b, c, GET(5) + 0x5a827999, 5)
+ STEP(G, c, d, a, b, GET(9) + 0x5a827999, 9)
+ STEP(G, b, c, d, a, GET(13) + 0x5a827999, 13)
+ STEP(G, a, b, c, d, GET(2) + 0x5a827999, 3)
+ STEP(G, d, a, b, c, GET(6) + 0x5a827999, 5)
+ STEP(G, c, d, a, b, GET(10) + 0x5a827999, 9)
+ STEP(G, b, c, d, a, GET(14) + 0x5a827999, 13)
+ STEP(G, a, b, c, d, GET(3) + 0x5a827999, 3)
+ STEP(G, d, a, b, c, GET(7) + 0x5a827999, 5)
+ STEP(G, c, d, a, b, GET(11) + 0x5a827999, 9)
+ STEP(G, b, c, d, a, GET(15) + 0x5a827999, 13)
/* Round 3 */
- STEP(H, a, b, c, d, GET(0) + 0x6ed9eba1, 3)
- STEP(H, d, a, b, c, GET(8) + 0x6ed9eba1, 9)
- STEP(H, c, d, a, b, GET(4) + 0x6ed9eba1, 11)
- STEP(H, b, c, d, a, GET(12) + 0x6ed9eba1, 15)
- STEP(H, a, b, c, d, GET(2) + 0x6ed9eba1, 3)
- STEP(H, d, a, b, c, GET(10) + 0x6ed9eba1, 9)
- STEP(H, c, d, a, b, GET(6) + 0x6ed9eba1, 11)
- STEP(H, b, c, d, a, GET(14) + 0x6ed9eba1, 15)
- STEP(H, a, b, c, d, GET(1) + 0x6ed9eba1, 3)
- STEP(H, d, a, b, c, GET(9) + 0x6ed9eba1, 9)
- STEP(H, c, d, a, b, GET(5) + 0x6ed9eba1, 11)
- STEP(H, b, c, d, a, GET(13) + 0x6ed9eba1, 15)
- STEP(H, a, b, c, d, GET(3) + 0x6ed9eba1, 3)
- STEP(H, d, a, b, c, GET(11) + 0x6ed9eba1, 9)
- STEP(H, c, d, a, b, GET(7) + 0x6ed9eba1, 11)
- STEP(H, b, c, d, a, GET(15) + 0x6ed9eba1, 15)
-
- a += saved_a;
+ STEP(H, a, b, c, d, GET(0) + 0x6ed9eba1, 3)
+ STEP(H, d, a, b, c, GET(8) + 0x6ed9eba1, 9)
+ STEP(H, c, d, a, b, GET(4) + 0x6ed9eba1, 11)
+ STEP(H, b, c, d, a, GET(12) + 0x6ed9eba1, 15)
+ STEP(H, a, b, c, d, GET(2) + 0x6ed9eba1, 3)
+ STEP(H, d, a, b, c, GET(10) + 0x6ed9eba1, 9)
+ STEP(H, c, d, a, b, GET(6) + 0x6ed9eba1, 11)
+ STEP(H, b, c, d, a, GET(14) + 0x6ed9eba1, 15)
+ STEP(H, a, b, c, d, GET(1) + 0x6ed9eba1, 3)
+ STEP(H, d, a, b, c, GET(9) + 0x6ed9eba1, 9)
+ STEP(H, c, d, a, b, GET(5) + 0x6ed9eba1, 11)
+ STEP(H, b, c, d, a, GET(13) + 0x6ed9eba1, 15)
+ STEP(H, a, b, c, d, GET(3) + 0x6ed9eba1, 3)
+ STEP(H, d, a, b, c, GET(11) + 0x6ed9eba1, 9)
+ STEP(H, c, d, a, b, GET(7) + 0x6ed9eba1, 11)
+ STEP(H, b, c, d, a, GET(15) + 0x6ed9eba1, 15)
+
+ a += saved_a;
b += saved_b;
c += saved_c;
d += saved_d;
@@ -211,7 +215,7 @@ static void MD4_Init(MD4_CTX *ctx)
static void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size)
{
MD4_u32plus saved_lo;
- unsigned long used, available;
+ unsigned long used;
saved_lo = ctx->lo;
ctx->lo = (saved_lo + size) & 0x1fffffff;
@@ -222,7 +226,7 @@ static void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size)
used = saved_lo & 0x3f;
if(used) {
- available = 64 - used;
+ unsigned long available = 64 - used;
if(size < available) {
memcpy(&ctx->buffer[used], data, size);
@@ -303,5 +307,7 @@ void Curl_md4it(unsigned char *output, const unsigned char *input, size_t len)
MD4_Update(&ctx, input, curlx_uztoui(len));
MD4_Final(output, &ctx);
}
+
#endif /* defined(USE_NSS) || defined(USE_OS400CRYPTO) ||
+ (defined(USE_OPENSSL) && defined(OPENSSL_NO_MD4)) ||
(defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) */
diff --git a/Utilities/cmcurl/lib/md5.c b/Utilities/cmcurl/lib/md5.c
index 80301a141..2b81ca455 100644
--- a/Utilities/cmcurl/lib/md5.c
+++ b/Utilities/cmcurl/lib/md5.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -39,19 +39,19 @@
typedef struct md5_ctx MD5_CTX;
-static void MD5_Init(MD5_CTX * ctx)
+static void MD5_Init(MD5_CTX *ctx)
{
md5_init(ctx);
}
-static void MD5_Update(MD5_CTX * ctx,
+static void MD5_Update(MD5_CTX *ctx,
const unsigned char *input,
unsigned int inputLen)
{
md5_update(ctx, inputLen, input);
}
-static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
+static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
{
md5_digest(ctx, 16, digest);
}
@@ -65,25 +65,25 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
typedef gcry_md_hd_t MD5_CTX;
-static void MD5_Init(MD5_CTX * ctx)
+static void MD5_Init(MD5_CTX *ctx)
{
gcry_md_open(ctx, GCRY_MD_MD5, 0);
}
-static void MD5_Update(MD5_CTX * ctx,
+static void MD5_Update(MD5_CTX *ctx,
const unsigned char *input,
unsigned int inputLen)
{
gcry_md_write(*ctx, input, inputLen);
}
-static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
+static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
{
memcpy(digest, gcry_md_read(*ctx, 0), 16);
gcry_md_close(*ctx);
}
-#elif defined(USE_OPENSSL)
+#elif defined(USE_OPENSSL) && !defined(USE_AMISSL)
/* When OpenSSL is available we use the MD5-function from OpenSSL */
#include <openssl/md5.h>
#include "curl_memory.h"
@@ -124,7 +124,7 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
CC_MD5_Final(digest, ctx);
}
-#elif defined(_WIN32) && !defined(CURL_WINDOWS_APP)
+#elif defined(WIN32) && !defined(CURL_WINDOWS_APP)
#include <wincrypt.h>
#include "curl_memory.h"
@@ -163,13 +163,6 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
CryptReleaseContext(ctx->hCryptProv, 0);
}
-#elif defined(USE_AXTLS)
-#include <axTLS/config.h>
-#include <axTLS/os_int.h>
-#include <axTLS/crypto.h>
-#include "curl_memory.h"
-/* The last #include file should be: */
-#include "memdebug.h"
#else
/* When no other crypto library is available we use this code segment */
/*
@@ -177,7 +170,7 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
* MD5 Message-Digest Algorithm (RFC 1321).
*
* Homepage:
- http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
+ https://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
*
* Author:
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
@@ -282,7 +275,6 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
{
const unsigned char *ptr;
MD5_u32plus a, b, c, d;
- MD5_u32plus saved_a, saved_b, saved_c, saved_d;
ptr = (const unsigned char *)data;
@@ -292,6 +284,8 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
d = ctx->d;
do {
+ MD5_u32plus saved_a, saved_b, saved_c, saved_d;
+
saved_a = a;
saved_b = b;
saved_c = c;
@@ -299,77 +293,77 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
/* Round 1 */
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
- STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
- STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
- STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
- STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
- STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
- STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
- STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
- STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
- STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
- STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
- STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
- STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
- STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
- STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
- STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
+ STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
+ STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
+ STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
+ STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
+ STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
+ STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
+ STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
+ STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
+ STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
+ STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
+ STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
+ STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
+ STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
+ STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
+ STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
/* Round 2 */
- STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
- STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
- STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
- STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
- STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
- STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
- STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
- STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
- STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
- STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
- STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
- STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
- STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
- STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
- STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
- STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
+ STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
+ STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
+ STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
+ STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
+ STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
+ STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
+ STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
+ STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
+ STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
+ STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
+ STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
+ STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
+ STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
+ STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
+ STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
+ STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
/* Round 3 */
- STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
- STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
- STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
- STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
- STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
- STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
- STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
- STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
- STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
- STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
- STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
- STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
- STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
- STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
- STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
- STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
+ STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
+ STEP(H2, d, a, b, c, GET(8), 0x8771f681, 11)
+ STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
+ STEP(H2, b, c, d, a, GET(14), 0xfde5380c, 23)
+ STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
+ STEP(H2, d, a, b, c, GET(4), 0x4bdecfa9, 11)
+ STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
+ STEP(H2, b, c, d, a, GET(10), 0xbebfbc70, 23)
+ STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
+ STEP(H2, d, a, b, c, GET(0), 0xeaa127fa, 11)
+ STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
+ STEP(H2, b, c, d, a, GET(6), 0x04881d05, 23)
+ STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
+ STEP(H2, d, a, b, c, GET(12), 0xe6db99e5, 11)
+ STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
+ STEP(H2, b, c, d, a, GET(2), 0xc4ac5665, 23)
/* Round 4 */
- STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
- STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
- STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
- STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
- STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
- STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
- STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
- STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
- STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
- STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
- STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
- STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
- STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
- STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
- STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
- STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
-
- a += saved_a;
+ STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
+ STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
+ STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
+ STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
+ STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
+ STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
+ STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
+ STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
+ STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
+ STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
+ STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
+ STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
+ STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
+ STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
+ STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
+ STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
+
+ a += saved_a;
b += saved_b;
c += saved_c;
d += saved_d;
@@ -399,7 +393,7 @@ static void MD5_Init(MD5_CTX *ctx)
static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
{
MD5_u32plus saved_lo;
- unsigned long used, available;
+ unsigned long used;
saved_lo = ctx->lo;
ctx->lo = (saved_lo + size) & 0x1fffffff;
@@ -410,7 +404,7 @@ static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
used = saved_lo & 0x3f;
if(used) {
- available = 64 - used;
+ unsigned long available = 64 - used;
if(size < available) {
memcpy(&ctx->buffer[used], data, size);
@@ -486,22 +480,33 @@ static void MD5_Final(unsigned char *result, MD5_CTX *ctx)
const HMAC_params Curl_HMAC_MD5[] = {
{
- (HMAC_hinit_func) MD5_Init, /* Hash initialization function. */
- (HMAC_hupdate_func) MD5_Update, /* Hash update function. */
- (HMAC_hfinal_func) MD5_Final, /* Hash computation end function. */
- sizeof(MD5_CTX), /* Size of hash context structure. */
- 64, /* Maximum key length. */
- 16 /* Result size. */
+ /* Hash initialization function. */
+ CURLX_FUNCTION_CAST(HMAC_hinit_func, MD5_Init),
+ /* Hash update function. */
+ CURLX_FUNCTION_CAST(HMAC_hupdate_func, MD5_Update),
+ /* Hash computation end function. */
+ CURLX_FUNCTION_CAST(HMAC_hfinal_func, MD5_Final),
+ /* Size of hash context structure. */
+ sizeof(MD5_CTX),
+ /* Maximum key length. */
+ 64,
+ /* Result size. */
+ 16
}
};
const MD5_params Curl_DIGEST_MD5[] = {
{
- (Curl_MD5_init_func) MD5_Init, /* Digest initialization function */
- (Curl_MD5_update_func) MD5_Update, /* Digest update function */
- (Curl_MD5_final_func) MD5_Final, /* Digest computation end function */
- sizeof(MD5_CTX), /* Size of digest context struct */
- 16 /* Result size */
+ /* Digest initialization function */
+ CURLX_FUNCTION_CAST(Curl_MD5_init_func, MD5_Init),
+ /* Digest update function */
+ CURLX_FUNCTION_CAST(Curl_MD5_update_func, MD5_Update),
+ /* Digest computation end function */
+ CURLX_FUNCTION_CAST(Curl_MD5_final_func, MD5_Final),
+ /* Size of digest context struct */
+ sizeof(MD5_CTX),
+ /* Result size */
+ 16
}
};
@@ -522,7 +527,7 @@ MD5_context *Curl_MD5_init(const MD5_params *md5params)
MD5_context *ctxt;
/* Create MD5 context */
- ctxt = malloc(sizeof *ctxt);
+ ctxt = malloc(sizeof(*ctxt));
if(!ctxt)
return ctxt;
@@ -541,23 +546,23 @@ MD5_context *Curl_MD5_init(const MD5_params *md5params)
return ctxt;
}
-int Curl_MD5_update(MD5_context *context,
- const unsigned char *data,
- unsigned int len)
+CURLcode Curl_MD5_update(MD5_context *context,
+ const unsigned char *data,
+ unsigned int len)
{
(*context->md5_hash->md5_update_func)(context->md5_hashctx, data, len);
- return 0;
+ return CURLE_OK;
}
-int Curl_MD5_final(MD5_context *context, unsigned char *result)
+CURLcode Curl_MD5_final(MD5_context *context, unsigned char *result)
{
(*context->md5_hash->md5_final_func)(result, context->md5_hashctx);
free(context->md5_hashctx);
free(context);
- return 0;
+ return CURLE_OK;
}
#endif /* CURL_DISABLE_CRYPTO_AUTH */
diff --git a/Utilities/cmcurl/lib/memdebug.c b/Utilities/cmcurl/lib/memdebug.c
index 2b8808ab0..ede60094b 100644
--- a/Utilities/cmcurl/lib/memdebug.c
+++ b/Utilities/cmcurl/lib/memdebug.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -100,29 +100,29 @@ struct memdebug {
* Don't use these with multithreaded test programs!
*/
-#define logfile curl_debuglogfile
-FILE *curl_debuglogfile = NULL;
+FILE *curl_dbg_logfile = 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)
+void curl_dbg_memdebug(const char *logname)
{
- if(!logfile) {
+ if(!curl_dbg_logfile) {
if(logname && *logname)
- logfile = fopen(logname, FOPEN_WRITETEXT);
+ curl_dbg_logfile = fopen(logname, FOPEN_WRITETEXT);
else
- logfile = stderr;
+ curl_dbg_logfile = stderr;
#ifdef MEMDEBUG_LOG_SYNC
/* Flush the log file after every line so the log isn't lost in a crash */
- setbuf(logfile, (char *)NULL);
+ if(curl_dbg_logfile)
+ setbuf(curl_dbg_logfile, (char *)NULL);
#endif
}
}
/* This function sets the number of malloc() calls that should return
successfully! */
-void curl_memlimit(long limit)
+void curl_dbg_memlimit(long limit)
{
if(!memlimit) {
memlimit = TRUE;
@@ -139,14 +139,14 @@ static bool countcheck(const char *func, int line, const char *source)
if(!memsize) {
if(source) {
/* log to file */
- curl_memlog("LIMIT %s:%d %s reached memlimit\n",
- source, line, func);
+ curl_dbg_log("LIMIT %s:%d %s reached memlimit\n",
+ source, line, func);
/* log to stderr also */
fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
source, line, func);
- fflush(logfile); /* because it might crash now */
+ fflush(curl_dbg_logfile); /* because it might crash now */
}
- SET_ERRNO(ENOMEM);
+ errno = ENOMEM;
return TRUE; /* RETURN ERROR! */
}
else
@@ -158,7 +158,7 @@ static bool countcheck(const char *func, int line, const char *source)
return FALSE; /* allow this */
}
-void *curl_domalloc(size_t wantedsize, int line, const char *source)
+void *curl_dbg_malloc(size_t wantedsize, int line, const char *source)
{
struct memdebug *mem;
size_t size;
@@ -169,7 +169,7 @@ void *curl_domalloc(size_t wantedsize, int line, const char *source)
return NULL;
/* alloc at least 64 bytes */
- size = sizeof(struct memdebug)+wantedsize;
+ size = sizeof(struct memdebug) + wantedsize;
mem = (Curl_cmalloc)(size);
if(mem) {
@@ -179,15 +179,15 @@ void *curl_domalloc(size_t wantedsize, int line, const char *source)
}
if(source)
- curl_memlog("MEM %s:%d malloc(%zu) = %p\n",
- source, line, wantedsize,
- mem ? (void *)mem->mem : (void *)0);
+ curl_dbg_log("MEM %s:%d malloc(%zu) = %p\n",
+ source, line, wantedsize,
+ mem ? (void *)mem->mem : (void *)0);
return (mem ? mem->mem : NULL);
}
-void *curl_docalloc(size_t wanted_elements, size_t wanted_size,
- int line, const char *source)
+void *curl_dbg_calloc(size_t wanted_elements, size_t wanted_size,
+ int line, const char *source)
{
struct memdebug *mem;
size_t size, user_size;
@@ -207,14 +207,14 @@ void *curl_docalloc(size_t wanted_elements, size_t wanted_size,
mem->size = user_size;
if(source)
- curl_memlog("MEM %s:%d calloc(%zu,%zu) = %p\n",
- source, line, wanted_elements, wanted_size,
- mem ? (void *)mem->mem : (void *)0);
+ curl_dbg_log("MEM %s:%d calloc(%zu,%zu) = %p\n",
+ source, line, wanted_elements, wanted_size,
+ mem ? (void *)mem->mem : (void *)0);
return (mem ? mem->mem : NULL);
}
-char *curl_dostrdup(const char *str, int line, const char *source)
+char *curl_dbg_strdup(const char *str, int line, const char *source)
{
char *mem;
size_t len;
@@ -224,21 +224,21 @@ char *curl_dostrdup(const char *str, int line, const char *source)
if(countcheck("strdup", line, source))
return NULL;
- len=strlen(str)+1;
+ len = strlen(str) + 1;
- mem=curl_domalloc(len, 0, NULL); /* NULL prevents logging */
+ mem = curl_dbg_malloc(len, 0, NULL); /* NULL prevents logging */
if(mem)
memcpy(mem, str, len);
if(source)
- curl_memlog("MEM %s:%d strdup(%p) (%zu) = %p\n",
- source, line, (const void *)str, len, (const void *)mem);
+ curl_dbg_log("MEM %s:%d strdup(%p) (%zu) = %p\n",
+ source, line, (const void *)str, len, (const void *)mem);
return mem;
}
#if defined(WIN32) && defined(UNICODE)
-wchar_t *curl_dowcsdup(const wchar_t *str, int line, const char *source)
+wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source)
{
wchar_t *mem;
size_t wsiz, bsiz;
@@ -251,12 +251,12 @@ wchar_t *curl_dowcsdup(const wchar_t *str, int line, const char *source)
wsiz = wcslen(str) + 1;
bsiz = wsiz * sizeof(wchar_t);
- mem = curl_domalloc(bsiz, 0, NULL); /* NULL prevents logging */
+ mem = curl_dbg_malloc(bsiz, 0, NULL); /* NULL prevents logging */
if(mem)
memcpy(mem, str, bsiz);
if(source)
- curl_memlog("MEM %s:%d wcsdup(%p) (%zu) = %p\n",
+ curl_dbg_log("MEM %s:%d wcsdup(%p) (%zu) = %p\n",
source, line, (void *)str, bsiz, (void *)mem);
return mem;
@@ -265,12 +265,12 @@ wchar_t *curl_dowcsdup(const wchar_t *str, int line, const char *source)
/* 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)
+void *curl_dbg_realloc(void *ptr, size_t wantedsize,
+ int line, const char *source)
{
- struct memdebug *mem=NULL;
+ struct memdebug *mem = NULL;
- size_t size = sizeof(struct memdebug)+wantedsize;
+ size_t size = sizeof(struct memdebug) + wantedsize;
DEBUGASSERT(wantedsize != 0);
@@ -292,7 +292,7 @@ void *curl_dorealloc(void *ptr, size_t wantedsize,
mem = (Curl_crealloc)(mem, size);
if(source)
- curl_memlog("MEM %s:%d realloc(%p, %zu) = %p\n",
+ curl_dbg_log("MEM %s:%d realloc(%p, %zu) = %p\n",
source, line, (void *)ptr, wantedsize,
mem ? (void *)mem->mem : (void *)0);
@@ -304,11 +304,10 @@ void *curl_dorealloc(void *ptr, size_t wantedsize,
return NULL;
}
-void curl_dofree(void *ptr, int line, const char *source)
+void curl_dbg_free(void *ptr, int line, const char *source)
{
- struct memdebug *mem;
-
if(ptr) {
+ struct memdebug *mem;
#ifdef __INTEL_COMPILER
# pragma warning(push)
@@ -330,11 +329,11 @@ void curl_dofree(void *ptr, int line, const char *source)
}
if(source)
- curl_memlog("MEM %s:%d free(%p)\n", source, line, (void *)ptr);
+ curl_dbg_log("MEM %s:%d free(%p)\n", source, line, (void *)ptr);
}
-curl_socket_t curl_socket(int domain, int type, int protocol,
- int line, const char *source)
+curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
+ int line, const char *source)
{
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d socket() = %d\n" :
@@ -342,18 +341,52 @@ curl_socket_t curl_socket(int domain, int type, int protocol,
"FD %s:%d socket() = %ld\n" :
"FD %s:%d socket() = %zd\n";
- curl_socket_t sockfd = socket(domain, type, protocol);
+ curl_socket_t sockfd;
+
+ if(countcheck("socket", line, source))
+ return CURL_SOCKET_BAD;
+
+ sockfd = socket(domain, type, protocol);
if(source && (sockfd != CURL_SOCKET_BAD))
- curl_memlog(fmt, source, line, sockfd);
+ curl_dbg_log(fmt, source, line, sockfd);
return sockfd;
}
+SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd,
+ SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf,
+ SEND_TYPE_ARG3 len, SEND_TYPE_ARG4 flags, int line,
+ const char *source)
+{
+ SEND_TYPE_RETV rc;
+ if(countcheck("send", line, source))
+ return -1;
+ rc = send(sockfd, buf, len, flags);
+ if(source)
+ curl_dbg_log("SEND %s:%d send(%lu) = %ld\n",
+ source, line, (unsigned long)len, (long)rc);
+ return rc;
+}
+
+RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd, RECV_TYPE_ARG2 buf,
+ RECV_TYPE_ARG3 len, RECV_TYPE_ARG4 flags, int line,
+ const char *source)
+{
+ RECV_TYPE_RETV rc;
+ if(countcheck("recv", line, source))
+ return -1;
+ rc = recv(sockfd, buf, len, flags);
+ if(source)
+ curl_dbg_log("RECV %s:%d recv(%lu) = %ld\n",
+ source, line, (unsigned long)len, (long)rc);
+ return rc;
+}
+
#ifdef HAVE_SOCKETPAIR
-int curl_socketpair(int domain, int type, int protocol,
- curl_socket_t socket_vector[2],
- int line, const char *source)
+int curl_dbg_socketpair(int domain, int type, int protocol,
+ curl_socket_t socket_vector[2],
+ int line, const char *source)
{
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d socketpair() = %d %d\n" :
@@ -364,14 +397,14 @@ int curl_socketpair(int domain, int type, int protocol,
int res = socketpair(domain, type, protocol, socket_vector);
if(source && (0 == res))
- curl_memlog(fmt, source, line, socket_vector[0], socket_vector[1]);
+ curl_dbg_log(fmt, source, line, socket_vector[0], socket_vector[1]);
return res;
}
#endif
-curl_socket_t curl_accept(curl_socket_t s, void *saddr, void *saddrlen,
- int line, const char *source)
+curl_socket_t curl_dbg_accept(curl_socket_t s, void *saddr, void *saddrlen,
+ int line, const char *source)
{
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d accept() = %d\n" :
@@ -385,13 +418,13 @@ curl_socket_t curl_accept(curl_socket_t s, void *saddr, void *saddrlen,
curl_socket_t sockfd = accept(s, addr, addrlen);
if(source && (sockfd != CURL_SOCKET_BAD))
- curl_memlog(fmt, source, line, sockfd);
+ curl_dbg_log(fmt, source, line, sockfd);
return sockfd;
}
/* separate function to allow libcurl to mark a "faked" close */
-void curl_mark_sclose(curl_socket_t sockfd, int line, const char *source)
+void curl_dbg_mark_sclose(curl_socket_t sockfd, int line, const char *source)
{
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d sclose(%d)\n":
@@ -400,54 +433,40 @@ void curl_mark_sclose(curl_socket_t sockfd, int line, const char *source)
"FD %s:%d sclose(%zd)\n";
if(source)
- curl_memlog(fmt, source, line, sockfd);
+ curl_dbg_log(fmt, source, line, sockfd);
}
/* this is our own defined way to close sockets on *ALL* platforms */
-int curl_sclose(curl_socket_t sockfd, int line, const char *source)
+int curl_dbg_sclose(curl_socket_t sockfd, int line, const char *source)
{
- int res=sclose(sockfd);
- curl_mark_sclose(sockfd, line, source);
+ int res = sclose(sockfd);
+ curl_dbg_mark_sclose(sockfd, line, source);
return res;
}
-FILE *curl_fopen(const char *file, const char *mode,
- int line, const char *source)
+FILE *curl_dbg_fopen(const char *file, const char *mode,
+ int line, const char *source)
{
- FILE *res=fopen(file, mode);
+ FILE *res = fopen(file, mode);
if(source)
- curl_memlog("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
+ curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
source, line, file, mode, (void *)res);
return res;
}
-#ifdef HAVE_FDOPEN
-FILE *curl_fdopen(int filedes, const char *mode,
- int line, const char *source)
-{
- FILE *res=fdopen(filedes, mode);
-
- if(source)
- curl_memlog("FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n",
- source, line, filedes, mode, (void *)res);
-
- return res;
-}
-#endif
-
-int curl_fclose(FILE *file, int line, const char *source)
+int curl_dbg_fclose(FILE *file, int line, const char *source)
{
int res;
DEBUGASSERT(file != NULL);
- res=fclose(file);
-
if(source)
- curl_memlog("FILE %s:%d fclose(%p)\n",
- source, line, (void *)file);
+ curl_dbg_log("FILE %s:%d fclose(%p)\n",
+ source, line, (void *)file);
+
+ res = fclose(file);
return res;
}
@@ -455,13 +474,13 @@ int curl_fclose(FILE *file, int line, const char *source)
#define LOGLINE_BUFSIZE 1024
/* this does the writing to the memory tracking log file */
-void curl_memlog(const char *format, ...)
+void curl_dbg_log(const char *format, ...)
{
char *buf;
int nchars;
va_list ap;
- if(!logfile)
+ if(!curl_dbg_logfile)
return;
buf = (Curl_cmalloc)(LOGLINE_BUFSIZE);
@@ -469,14 +488,14 @@ void curl_memlog(const char *format, ...)
return;
va_start(ap, format);
- nchars = vsnprintf(buf, LOGLINE_BUFSIZE, format, ap);
+ nchars = mvsnprintf(buf, LOGLINE_BUFSIZE, format, ap);
va_end(ap);
if(nchars > LOGLINE_BUFSIZE - 1)
nchars = LOGLINE_BUFSIZE - 1;
if(nchars > 0)
- fwrite(buf, 1, (size_t)nchars, logfile);
+ fwrite(buf, 1, (size_t)nchars, curl_dbg_logfile);
(Curl_cfree)(buf);
}
diff --git a/Utilities/cmcurl/lib/memdebug.h b/Utilities/cmcurl/lib/memdebug.h
index 835dab38c..5236f60fa 100644
--- a/Utilities/cmcurl/lib/memdebug.h
+++ b/Utilities/cmcurl/lib/memdebug.h
@@ -8,7 +8,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -30,84 +30,92 @@
#define CURL_MT_LOGFNAME_BUFSIZE 512
-#define logfile curl_debuglogfile
-
-extern FILE *logfile;
+extern FILE *curl_dbg_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);
-#if defined(WIN32) && defined(UNICODE)
-CURL_EXTERN wchar_t *curl_dowcsdup(const wchar_t *str, int line,
+CURL_EXTERN void *curl_dbg_malloc(size_t size, int line, const char *source);
+CURL_EXTERN void *curl_dbg_calloc(size_t elements, size_t size, int line,
+ const char *source);
+CURL_EXTERN void *curl_dbg_realloc(void *ptr, size_t size, int line,
const char *source);
+CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source);
+CURL_EXTERN char *curl_dbg_strdup(const char *str, int line, const char *src);
+#if defined(WIN32) && defined(UNICODE)
+CURL_EXTERN wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line,
+ const char *source);
#endif
-CURL_EXTERN void curl_memdebug(const char *logname);
-CURL_EXTERN void curl_memlimit(long limit);
-CURL_EXTERN void curl_memlog(const char *format, ...);
+CURL_EXTERN void curl_dbg_memdebug(const char *logname);
+CURL_EXTERN void curl_dbg_memlimit(long limit);
+CURL_EXTERN void curl_dbg_log(const char *format, ...);
/* file descriptor manipulators */
-CURL_EXTERN curl_socket_t curl_socket(int domain, int type, int protocol,
- int line, const char *source);
-CURL_EXTERN void curl_mark_sclose(curl_socket_t sockfd,
- int line, const char *source);
-CURL_EXTERN int curl_sclose(curl_socket_t sockfd,
- int line, const char *source);
-CURL_EXTERN curl_socket_t curl_accept(curl_socket_t s, void *a, void *alen,
+CURL_EXTERN curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
+ int line, const char *source);
+CURL_EXTERN void curl_dbg_mark_sclose(curl_socket_t sockfd,
int line, const char *source);
-#ifdef HAVE_SOCKETPAIR
-CURL_EXTERN int curl_socketpair(int domain, int type, int protocol,
- curl_socket_t socket_vector[2],
+CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd,
int line, const char *source);
+CURL_EXTERN curl_socket_t curl_dbg_accept(curl_socket_t s, void *a, void *alen,
+ int line, const char *source);
+#ifdef HAVE_SOCKETPAIR
+CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol,
+ curl_socket_t socket_vector[2],
+ int line, const char *source);
#endif
+/* send/receive sockets */
+CURL_EXTERN SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd,
+ SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf,
+ SEND_TYPE_ARG3 len,
+ SEND_TYPE_ARG4 flags, int line,
+ const char *source);
+CURL_EXTERN RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd,
+ RECV_TYPE_ARG2 buf,
+ RECV_TYPE_ARG3 len,
+ RECV_TYPE_ARG4 flags, int line,
+ const char *source);
+
/* FILE functions */
-CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
- const char *source);
-#ifdef HAVE_FDOPEN
-CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line,
- const char *source);
-#endif
-CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
+CURL_EXTERN FILE *curl_dbg_fopen(const char *file, const char *mode, int line,
+ const char *source);
+CURL_EXTERN int curl_dbg_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 strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
+#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
+#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
+#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
+#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
+#define send(a,b,c,d) curl_dbg_send(a,b,c,d, __LINE__, __FILE__)
+#define recv(a,b,c,d) curl_dbg_recv(a,b,c,d, __LINE__, __FILE__)
#ifdef WIN32
# ifdef UNICODE
# undef wcsdup
-# define wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
+# define wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# undef _wcsdup
-# define _wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
+# define _wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# undef _tcsdup
-# define _tcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
+# define _tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# else
# undef _tcsdup
-# define _tcsdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
+# define _tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
# endif
#endif
#undef socket
#define socket(domain,type,protocol)\
- curl_socket(domain, type, protocol, __LINE__, __FILE__)
+ curl_dbg_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__)
+ curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
#ifdef HAVE_SOCKETPAIR
#define socketpair(domain,type,protocol,socket_vector)\
- curl_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__)
+ curl_dbg_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__)
#endif
#ifdef HAVE_GETADDRINFO
@@ -116,38 +124,31 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
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__)
+ curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
#else
#undef getaddrinfo
#define getaddrinfo(host,serv,hint,res) \
- curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
+ curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
#endif
#endif /* HAVE_GETADDRINFO */
-#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 /* HAVE_GETNAMEINFO */
-
#ifdef HAVE_FREEADDRINFO
#undef freeaddrinfo
#define freeaddrinfo(data) \
- curl_dofreeaddrinfo(data, __LINE__, __FILE__)
+ curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
#endif /* HAVE_FREEADDRINFO */
/* sclose is probably already defined, redefine it! */
#undef sclose
-#define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
+#define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__)
-#define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__)
+#define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd,__LINE__,__FILE__)
#undef fopen
-#define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
+#define fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__)
#undef fdopen
-#define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__)
-#define fclose(file) curl_fclose(file,__LINE__,__FILE__)
+#define fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__)
+#define fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__)
#endif /* MEMDEBUG_NODEFINES */
diff --git a/Utilities/cmcurl/lib/mprintf.c b/Utilities/cmcurl/lib/mprintf.c
index eb7ee0c6b..e19093678 100644
--- a/Utilities/cmcurl/lib/mprintf.c
+++ b/Utilities/cmcurl/lib/mprintf.c
@@ -46,10 +46,6 @@
* If SIZEOF_SIZE_T has not been defined, default to the size of long.
*/
-#ifndef SIZEOF_SIZE_T
-# define SIZEOF_SIZE_T CURL_SIZEOF_LONG
-#endif
-
#ifdef HAVE_LONGLONG
# define LONG_LONG_TYPE long long
# define HAVE_LONG_LONG_TYPE
@@ -111,7 +107,7 @@ static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
} WHILE_FALSE
/* Data type to read from the arglist */
-typedef enum {
+typedef enum {
FORMAT_UNKNOWN = 0,
FORMAT_STRING,
FORMAT_PTR,
@@ -181,7 +177,7 @@ struct asprintf {
static long dprintf_DollarString(char *input, char **end)
{
- int number=0;
+ int number = 0;
while(ISDIGIT(*input)) {
number *= 10;
number += *input-'0';
@@ -237,7 +233,7 @@ static int dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
long width;
long precision;
int flags;
- long max_param=0;
+ long max_param = 0;
long i;
while(*fmt) {
@@ -326,7 +322,7 @@ static int dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
break;
#if defined(MP_HAVE_INT_EXTENSIONS)
case 'I':
-#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
+#if (SIZEOF_CURL_OFF_T > SIZEOF_LONG)
flags |= FLAGS_LONGLONG;
#else
flags |= FLAGS_LONG;
@@ -348,14 +344,14 @@ static int dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
case 'z':
/* the code below generates a warning if -Wunreachable-code is
used */
-#if (SIZEOF_SIZE_T > CURL_SIZEOF_LONG)
+#if (SIZEOF_SIZE_T > SIZEOF_LONG)
flags |= FLAGS_LONGLONG;
#else
flags |= FLAGS_LONG;
#endif
break;
case 'O':
-#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
+#if (SIZEOF_CURL_OFF_T > SIZEOF_LONG)
flags |= FLAGS_LONGLONG;
#else
flags |= FLAGS_LONG;
@@ -380,7 +376,7 @@ static int dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
else
width = param_num;
if(width > max_param)
- max_param=width;
+ max_param = width;
break;
default:
break;
@@ -486,7 +482,7 @@ static int dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
}
/* Read the arg list parameters into our data list */
- for(i=0; i<max_param; i++) {
+ for(i = 0; i<max_param; i++) {
/* Width/precision arguments must be read before the main argument
they are attached to */
if(vto[i].flags & FLAGS_WIDTHPARAM) {
@@ -573,7 +569,7 @@ static int dprintf_formatf(
int done = 0;
long param; /* current parameter to read */
- long param_num=0; /* parameter counter */
+ long param_num = 0; /* parameter counter */
va_stack_t vto[MAX_PARAMETERS];
char *endpos[MAX_PARAMETERS];
@@ -643,7 +639,7 @@ static int dprintf_formatf(
/* If this is a positional parameter, the position must follow immediately
after the %, thus create a %<num>$ sequence */
- param=dprintf_DollarString(f, &f);
+ param = dprintf_DollarString(f, &f);
if(!param)
param = param_num;
@@ -839,7 +835,7 @@ static int dprintf_formatf(
while(width-- > 0)
OUTCHAR(' ');
- while((len-- > 0) && *str)
+ for(; len && *str; len--)
OUTCHAR(*str++);
if(p->flags&FLAGS_LEFT)
while(width-- > 0)
@@ -952,7 +948,7 @@ static int dprintf_formatf(
output characters */
(sprintf)(work, formatbuf, p->data.dnum);
DEBUGASSERT(strlen(work) <= sizeof(work));
- for(fptr=work; *fptr; fptr++)
+ for(fptr = work; *fptr; fptr++)
OUTCHAR(*fptr);
}
break;
@@ -984,7 +980,7 @@ static int dprintf_formatf(
/* fputc() look-alike */
static int addbyter(int output, FILE *data)
{
- struct nsprintf *infop=(struct nsprintf *)data;
+ struct nsprintf *infop = (struct nsprintf *)data;
unsigned char outc = (unsigned char)output;
if(infop->length < infop->max) {
@@ -1032,7 +1028,7 @@ int curl_msnprintf(char *buffer, size_t maxlength, const char *format, ...)
/* fputc() look-alike */
static int alloc_addbyter(int output, FILE *data)
{
- struct asprintf *infop=(struct asprintf *)data;
+ struct asprintf *infop = (struct asprintf *)data;
unsigned char outc = (unsigned char)output;
if(!infop->buffer) {
@@ -1042,9 +1038,9 @@ static int alloc_addbyter(int output, FILE *data)
return -1; /* fail */
}
infop->alloc = 32;
- infop->len =0;
+ infop->len = 0;
}
- else if(infop->len+1 >= infop->alloc) {
+ else if(infop->len + 1 >= infop->alloc) {
char *newptr = NULL;
size_t newsize = infop->alloc*2;
@@ -1133,7 +1129,7 @@ int curl_msprintf(char *buffer, const char *format, ...)
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 */
+ *buffer = 0; /* we terminate this with a zero byte */
return retcode;
}
@@ -1162,7 +1158,7 @@ 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 */
+ *buffer = 0; /* we terminate this with a zero byte */
return retcode;
}
diff --git a/Utilities/cmcurl/lib/multi.c b/Utilities/cmcurl/lib/multi.c
index c3a0d122c..c7c46eefc 100644
--- a/Utilities/cmcurl/lib/multi.c
+++ b/Utilities/cmcurl/lib/multi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -31,6 +31,7 @@
#include "progress.h"
#include "easyif.h"
#include "share.h"
+#include "psl.h"
#include "multiif.h"
#include "sendf.h"
#include "timeval.h"
@@ -40,10 +41,11 @@
#include "speedcheck.h"
#include "conncache.h"
#include "multihandle.h"
-#include "pipeline.h"
#include "sigpipe.h"
#include "vtls/vtls.h"
#include "connect.h"
+#include "http_proxy.h"
+#include "http2.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
@@ -58,22 +60,26 @@
#define CURL_SOCKET_HASH_TABLE_SIZE 911
#endif
+#ifndef CURL_CONNECTION_HASH_SIZE
#define CURL_CONNECTION_HASH_SIZE 97
+#endif
#define CURL_MULTI_HANDLE 0x000bab1e
#define GOOD_MULTI_HANDLE(x) \
((x) && (x)->type == CURL_MULTI_HANDLE)
-static void singlesocket(struct Curl_multi *multi,
- struct Curl_easy *data);
+static CURLMcode singlesocket(struct Curl_multi *multi,
+ struct Curl_easy *data);
static int update_timer(struct Curl_multi *multi);
-static CURLMcode add_next_timeout(struct timeval now,
+static CURLMcode add_next_timeout(struct curltime now,
struct Curl_multi *multi,
struct Curl_easy *d);
static CURLMcode multi_timeout(struct Curl_multi *multi,
long *timeout_ms);
+static void process_pending_handles(struct Curl_multi *multi);
+static void detach_connnection(struct Curl_easy *data);
#ifdef DEBUGBUILD
static const char * const statename[]={
@@ -85,12 +91,10 @@ static const char * const statename[]={
"WAITPROXYCONNECT",
"SENDPROTOCONNECT",
"PROTOCONNECT",
- "WAITDO",
"DO",
"DOING",
"DO_MORE",
"DO_DONE",
- "WAITPERFORM",
"PERFORM",
"TOOFAST",
"DONE",
@@ -102,6 +106,16 @@ static const char * const statename[]={
/* function pointer called once when switching TO a state */
typedef void (*init_multistate_func)(struct Curl_easy *data);
+static void Curl_init_completed(struct Curl_easy *data)
+{
+ /* this is a completed transfer */
+
+ /* Important: reset the conn pointer so that we don't point to memory
+ that could be freed anytime */
+ detach_connnection(data);
+ Curl_expire_clear(data); /* stop all timers */
+}
+
/* always use this function to change state, to make debugging easier */
static void mstate(struct Curl_easy *data, CURLMstate state
#ifdef DEBUGBUILD
@@ -111,10 +125,23 @@ static void mstate(struct Curl_easy *data, CURLMstate state
{
CURLMstate oldstate = data->mstate;
static const init_multistate_func finit[CURLM_STATE_LAST] = {
- NULL,
- NULL,
+ NULL, /* INIT */
+ NULL, /* CONNECT_PEND */
Curl_init_CONNECT, /* CONNECT */
- /* the rest is NULL too */
+ NULL, /* WAITRESOLVE */
+ NULL, /* WAITCONNECT */
+ NULL, /* WAITPROXYCONNECT */
+ NULL, /* SENDPROTOCONNECT */
+ NULL, /* PROTOCONNECT */
+ Curl_connect_free, /* DO */
+ NULL, /* DOING */
+ NULL, /* DO_MORE */
+ NULL, /* DO_DONE */
+ NULL, /* PERFORM */
+ NULL, /* TOOFAST */
+ NULL, /* DONE */
+ Curl_init_completed, /* COMPLETED */
+ NULL /* MSGSENT */
};
#if defined(DEBUGBUILD) && defined(CURL_DISABLE_VERBOSE_STRINGS)
@@ -132,8 +159,8 @@ static void mstate(struct Curl_easy *data, CURLMstate state
data->mstate < CURLM_STATE_COMPLETED) {
long connection_id = -5000;
- if(data->easy_conn)
- connection_id = data->easy_conn->connection_id;
+ if(data->conn)
+ connection_id = data->conn->connection_id;
infof(data,
"STATE: %s => %s handle %p; line %d (connection #%ld)\n",
@@ -158,14 +185,17 @@ static void mstate(struct Curl_easy *data, CURLMstate state
#endif
/*
- * We add one of these structs to the sockhash for a particular socket
+ * We add one of these structs to the sockhash for each socket
*/
struct Curl_sh_entry {
- struct Curl_easy *easy;
- int action; /* what action READ/WRITE this socket waits for */
- curl_socket_t socket; /* mainly to ease debugging */
+ struct curl_llist list; /* list of easy handles using this socket */
+ unsigned int action; /* what combined action READ/WRITE this socket waits
+ for */
void *socketp; /* settable by users with curl_multi_assign() */
+ unsigned int users; /* number of transfers using this */
+ unsigned int readers; /* this many transfers want to read */
+ unsigned int writers; /* this many transfers want to write */
};
/* bits for 'action' having no bits means this socket is not expecting any
action */
@@ -184,8 +214,7 @@ static struct Curl_sh_entry *sh_getentry(struct curl_hash *sh,
/* 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 Curl_easy *data)
+ curl_socket_t s)
{
struct Curl_sh_entry *there = sh_getentry(sh, s);
struct Curl_sh_entry *check;
@@ -199,8 +228,7 @@ static struct Curl_sh_entry *sh_addentry(struct curl_hash *sh,
if(!check)
return NULL; /* major failure */
- check->easy = data;
- check->socket = s;
+ Curl_llist_init(&check->list, NULL);
/* make/add new hash entry */
if(!Curl_hash_add(sh, (char *)&s, sizeof(curl_socket_t), check)) {
@@ -316,16 +344,6 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
Curl_llist_init(&multi->msglist, multi_freeamsg);
Curl_llist_init(&multi->pending, multi_freeamsg);
- /* allocate a new easy handle to use when closing cached connections */
- multi->closure_handle = curl_easy_init();
- if(!multi->closure_handle)
- goto error;
-
- multi->closure_handle->multi = multi;
- multi->closure_handle->state.conn_cache = &multi->conn_cache;
-
- multi->max_pipeline_length = 5;
-
/* -1 means it not set by user, use the default value */
multi->maxconnects = -1;
return multi;
@@ -335,8 +353,6 @@ struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
Curl_hash_destroy(&multi->sockhash);
Curl_hash_destroy(&multi->hostcache);
Curl_conncache_destroy(&multi->conn_cache);
- Curl_close(multi->closure_handle);
- multi->closure_handle = NULL;
Curl_llist_destroy(&multi->msglist, NULL);
Curl_llist_destroy(&multi->pending, NULL);
@@ -366,6 +382,9 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
if(data->multi)
return CURLM_ADDED_ALREADY;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
/* Initialize timeout list for this handle */
Curl_llist_init(&data->state.timeoutlist, NULL);
@@ -375,37 +394,35 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
* potential multi's connection cache growing which won't be undone in this
* function no matter what.
*/
+ if(data->set.errorbuffer)
+ data->set.errorbuffer[0] = 0;
/* set the easy handle */
multistate(data, CURLM_STATE_INIT);
- if((data->set.global_dns_cache) &&
- (data->dns.hostcachetype != HCACHE_GLOBAL)) {
- /* global dns cache was requested but still isn't */
- struct curl_hash *global = Curl_global_host_cache_init();
- if(global) {
- /* only do this if the global cache init works */
- data->dns.hostcache = global;
- data->dns.hostcachetype = HCACHE_GLOBAL;
- }
- }
/* for multi interface connections, we share DNS cache automatically if the
easy handle's one is currently not set. */
- else if(!data->dns.hostcache ||
+ if(!data->dns.hostcache ||
(data->dns.hostcachetype == HCACHE_NONE)) {
data->dns.hostcache = &multi->hostcache;
data->dns.hostcachetype = HCACHE_MULTI;
}
- /* Point to the multi's connection cache */
- data->state.conn_cache = &multi->conn_cache;
-
- /* This adds the new entry at the 'end' of the doubly-linked circular
- list of Curl_easy structs to try and maintain a FIFO queue so
- the pipelined requests are in order. */
+ /* Point to the shared or multi handle connection cache */
+ if(data->share && (data->share->specifier & (1<< CURL_LOCK_DATA_CONNECT)))
+ data->state.conn_cache = &data->share->conn_cache;
+ else
+ data->state.conn_cache = &multi->conn_cache;
- /* We add this new entry last in the list. */
+#ifdef USE_LIBPSL
+ /* Do the same for PSL. */
+ if(data->share && (data->share->specifier & (1 << CURL_LOCK_DATA_PSL)))
+ data->psl = &data->share->psl;
+ else
+ data->psl = &multi->psl;
+#endif
+ /* We add the new entry last in the list. */
data->next = NULL; /* end of the line */
if(multi->easyp) {
struct Curl_easy *last = multi->easylp;
@@ -440,7 +457,7 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
happens if the lastcall time is set to the same time when the handle is
removed as when the next handle is added, as then the check in
update_timer() that prevents calling the application multiple times with
- the same timer infor will not trigger and then the new handle's timeout
+ the same timer info will not trigger and then the new handle's timeout
will not be notified to the app.
The work-around is thus simply to clear the 'lastcall' variable to force
@@ -452,9 +469,11 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi,
state somewhat we clone the timeouts from each added handle so that the
closure handle always has the same timeouts as the most recently added
easy handle. */
- multi->closure_handle->set.timeout = data->set.timeout;
- multi->closure_handle->set.server_response_timeout =
+ data->state.conn_cache->closure_handle->set.timeout = data->set.timeout;
+ data->state.conn_cache->closure_handle->set.server_response_timeout =
data->set.server_response_timeout;
+ data->state.conn_cache->closure_handle->set.no_signal =
+ data->set.no_signal;
update_timer(multi);
return CURLM_OK;
@@ -476,66 +495,27 @@ static void debug_print_sock_hash(void *p)
}
#endif
-/* Mark the connection as 'idle', or close it if the cache is full.
- Returns TRUE if the connection is kept, or FALSE if it was closed. */
-static bool
-ConnectionDone(struct Curl_easy *data, struct connectdata *conn)
-{
- /* data->multi->maxconnects can be negative, deal with it. */
- size_t maxconnects =
- (data->multi->maxconnects < 0) ? data->multi->num_easy * 4:
- data->multi->maxconnects;
- struct connectdata *conn_candidate = NULL;
-
- /* Mark the current connection as 'unused' */
- conn->inuse = FALSE;
-
- if(maxconnects > 0 &&
- data->state.conn_cache->num_connections > maxconnects) {
- infof(data, "Connection cache is full, closing the oldest one.\n");
-
- conn_candidate = Curl_oldest_idle_connection(data);
-
- if(conn_candidate) {
- /* Set the connection's owner correctly */
- conn_candidate->data = data;
-
- /* the winner gets the honour of being disconnected */
- (void)Curl_disconnect(conn_candidate, /* dead_connection */ FALSE);
- }
- }
-
- return (conn_candidate == conn) ? FALSE : TRUE;
-}
-
-static CURLcode multi_done(struct connectdata **connp,
- CURLcode status, /* an error if this is called
- after an error was detected */
- bool premature)
+static CURLcode multi_done(struct Curl_easy *data,
+ CURLcode status, /* an error if this is called
+ after an error was detected */
+ bool premature)
{
CURLcode result;
- struct connectdata *conn;
- struct Curl_easy *data;
+ struct connectdata *conn = data->conn;
unsigned int i;
- DEBUGASSERT(*connp);
-
- conn = *connp;
- data = conn->data;
-
DEBUGF(infof(data, "multi_done\n"));
if(data->state.done)
/* Stop if multi_done() has already been called */
return CURLE_OK;
- Curl_getoff_all_pipelines(data, conn);
+ /* Stop the resolver and free its own resources (but not dns_entry yet). */
+ Curl_resolver_kill(conn);
/* Cleanup possible redirect junk */
- free(data->req.newurl);
- data->req.newurl = NULL;
- free(data->req.location);
- data->req.location = NULL;
+ Curl_safefree(data->req.newurl);
+ Curl_safefree(data->req.location);
switch(status) {
case CURLE_ABORTED_BY_CALLBACK:
@@ -564,34 +544,36 @@ static CURLcode multi_done(struct connectdata **connp,
result = CURLE_ABORTED_BY_CALLBACK;
}
- if(conn->send_pipe.size + conn->recv_pipe.size != 0 &&
- !data->set.reuse_forbid &&
- !conn->bits.close) {
- /* Stop if pipeline is not empty and we do not have to close
- connection. */
- data->easy_conn = NULL;
- DEBUGF(infof(data, "Connection still in use, no more multi_done now!\n"));
+ process_pending_handles(data->multi); /* connection / multiplex */
+
+ detach_connnection(data);
+ if(CONN_INUSE(conn)) {
+ /* Stop if still used. */
+ DEBUGF(infof(data, "Connection still in use %zu, "
+ "no more multi_done now!\n",
+ conn->easyq.size));
return CURLE_OK;
}
data->state.done = TRUE; /* called just now! */
- Curl_resolver_cancel(conn);
if(conn->dns_entry) {
Curl_resolv_unlock(data, conn->dns_entry); /* done with this */
conn->dns_entry = NULL;
}
+ Curl_hostcache_prune(data);
+ Curl_safefree(data->state.ulbuf);
/* if the transfer was completed in a paused state there can be buffered
data left to free */
- for(i=0; i < data->state.tempcount; i++) {
+ for(i = 0; i < data->state.tempcount; i++) {
free(data->state.tempwrite[i].buf);
}
data->state.tempcount = 0;
/* if data->set.reuse_forbid is TRUE, it means the libcurl client has
forced us to close this connection. This is ignored for requests taking
- place in a NTLM authentication handshake
+ place in a NTLM/NEGOTIATE authentication handshake
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
@@ -606,11 +588,16 @@ static CURLcode multi_done(struct connectdata **connp,
if((data->set.reuse_forbid
#if defined(USE_NTLM)
- && !(conn->ntlm.state == NTLMSTATE_TYPE2 ||
- conn->proxyntlm.state == NTLMSTATE_TYPE2)
+ && !(conn->http_ntlm_state == NTLMSTATE_TYPE2 ||
+ conn->proxy_ntlm_state == NTLMSTATE_TYPE2)
+#endif
+#if defined(USE_SPNEGO)
+ && !(conn->http_negotiate_state == GSS_AUTHRECV ||
+ conn->proxy_negotiate_state == GSS_AUTHRECV)
#endif
- ) || conn->bits.close || premature) {
- CURLcode res2 = Curl_disconnect(conn, premature); /* close connection */
+ ) || conn->bits.close
+ || (premature && !(conn->handler->flags & PROTOPT_STREAM))) {
+ CURLcode res2 = Curl_disconnect(data, conn, premature);
/* If we had an error already, make sure we return that one. But
if we got a new error, return that. */
@@ -618,28 +605,27 @@ static CURLcode multi_done(struct connectdata **connp,
result = res2;
}
else {
- /* the connection is no longer in use */
- if(ConnectionDone(data, conn)) {
+ char buffer[256];
+ /* create string before returning the connection */
+ msnprintf(buffer, sizeof(buffer),
+ "Connection #%ld to host %s left intact",
+ conn->connection_id,
+ conn->bits.socksproxy ? conn->socks_proxy.host.dispname :
+ conn->bits.httpproxy ? conn->http_proxy.host.dispname :
+ conn->bits.conn_to_host ? conn->conn_to_host.dispname :
+ conn->host.dispname);
+
+ /* the connection is no longer in use by this transfer */
+ if(Curl_conncache_return_conn(conn)) {
/* remember the most recently used connection */
data->state.lastconnect = conn;
-
- infof(data, "Connection #%ld to host %s left intact\n",
- conn->connection_id,
- conn->bits.socksproxy ? conn->socks_proxy.host.dispname :
- conn->bits.httpproxy ? conn->http_proxy.host.dispname :
- conn->bits.conn_to_host ? conn->conn_to_host.dispname :
- conn->host.dispname);
+ infof(data, "%s\n", buffer);
}
else
data->state.lastconnect = NULL;
}
- *connp = NULL; /* to make the caller of this function better detect that
- this was either closed or handed over to the connection
- cache here, and therefore cannot be used from this point on
- */
Curl_free_request_state(data);
-
return result;
}
@@ -663,8 +649,11 @@ CURLMcode curl_multi_remove_handle(struct Curl_multi *multi,
if(!data->multi)
return CURLM_OK; /* it is already removed so let's say it is fine! */
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
premature = (data->mstate < CURLM_STATE_COMPLETED) ? TRUE : FALSE;
- easy_owns_conn = (data->easy_conn && (data->easy_conn->data == easy)) ?
+ easy_owns_conn = (data->conn && (data->conn->data == easy)) ?
TRUE : FALSE;
/* If the 'state' is not INIT or COMPLETED, we might need to do something
@@ -673,22 +662,15 @@ CURLMcode curl_multi_remove_handle(struct Curl_multi *multi,
/* this handle is "alive" so we need to count down the total number of
alive connections when this is removed */
multi->num_alive--;
-
- /* When this handle gets removed, other handles may be able to get the
- connection */
- Curl_multi_process_pending_handles(multi);
}
- if(data->easy_conn &&
+ if(data->conn &&
data->mstate > CURLM_STATE_DO &&
data->mstate < CURLM_STATE_COMPLETED) {
/* Set connection owner so that the DONE function closes it. We can
safely do this here since connection is killed. */
- data->easy_conn->data = easy;
- /* If the handle is in a pipeline and has started sending off its
- request but not received its response yet, we need to close
- connection. */
- streamclose(data->easy_conn, "Removed with partial response");
+ data->conn->data = easy;
+ streamclose(data->conn, "Removed with partial response");
easy_owns_conn = TRUE;
}
@@ -697,13 +679,7 @@ CURLMcode curl_multi_remove_handle(struct Curl_multi *multi,
curl_easy_cleanup is called. */
Curl_expire_clear(data);
- if(data->dns.hostcachetype == HCACHE_MULTI) {
- /* stop using the multi handle's DNS cache */
- data->dns.hostcache = NULL;
- data->dns.hostcachetype = HCACHE_NONE;
- }
-
- if(data->easy_conn) {
+ if(data->conn) {
/* we must call multi_done() here (if we still own the connection) so that
we don't leave a half-baked one around */
@@ -714,11 +690,20 @@ CURLMcode curl_multi_remove_handle(struct Curl_multi *multi,
Note that this ignores the return code simply because there's
nothing really useful to do with it anyway! */
- (void)multi_done(&data->easy_conn, data->result, premature);
+ (void)multi_done(data, data->result, premature);
}
- else
- /* Clear connection pipelines, if multi_done above was not called */
- Curl_getoff_all_pipelines(data, data->easy_conn);
+ }
+
+ if(data->connect_queue.ptr)
+ /* the handle was in the pending list waiting for an available connection,
+ so go ahead and remove it */
+ Curl_llist_remove(&multi->pending, &data->connect_queue, NULL);
+
+ if(data->dns.hostcachetype == HCACHE_MULTI) {
+ /* stop using the multi handle's DNS cache, *after* the possible
+ multi_done() call above */
+ data->dns.hostcache = NULL;
+ data->dns.hostcachetype = HCACHE_NONE;
}
Curl_wildcard_dtor(&data->wildcard);
@@ -738,11 +723,17 @@ CURLMcode curl_multi_remove_handle(struct Curl_multi *multi,
vanish with this handle */
/* Remove the association between the connection and the handle */
- if(data->easy_conn) {
- data->easy_conn->data = NULL;
- data->easy_conn = NULL;
+ if(data->conn) {
+ data->conn->data = NULL;
+ detach_connnection(data);
}
+#ifdef USE_LIBPSL
+ /* Remove the PSL association. */
+ if(data->psl == &multi->psl)
+ data->psl = NULL;
+#endif
+
data->multi = NULL; /* clear the association to this multi handle */
/* make sure there's no pending message in the queue sent from this easy
@@ -778,15 +769,31 @@ CURLMcode curl_multi_remove_handle(struct Curl_multi *multi,
return CURLM_OK;
}
-/* Return TRUE if the application asked for a certain set of pipelining */
-bool Curl_pipeline_wanted(const struct Curl_multi *multi, int bits)
+/* Return TRUE if the application asked for multiplexing */
+bool Curl_multiplex_wanted(const struct Curl_multi *multi)
{
- return (multi && (multi->pipelining & bits)) ? TRUE : FALSE;
+ return (multi && (multi->multiplexing));
}
-void Curl_multi_handlePipeBreak(struct Curl_easy *data)
+/* This is the only function that should clear data->conn. This will
+ occasionally be called with the pointer already cleared. */
+static void detach_connnection(struct Curl_easy *data)
{
- data->easy_conn = NULL;
+ struct connectdata *conn = data->conn;
+ if(conn)
+ Curl_llist_remove(&conn->easyq, &data->conn_queue, NULL);
+ data->conn = NULL;
+}
+
+/* This is the only function that should assign data->conn */
+void Curl_attach_connnection(struct Curl_easy *data,
+ struct connectdata *conn)
+{
+ DEBUGASSERT(!data->conn);
+ DEBUGASSERT(conn);
+ data->conn = conn;
+ Curl_llist_insert_next(&conn->easyq, conn->easyq.tail, data,
+ &data->conn_queue);
}
static int waitconnect_getsock(struct connectdata *conn,
@@ -794,8 +801,8 @@ static int waitconnect_getsock(struct connectdata *conn,
int numsocks)
{
int i;
- int s=0;
- int rc=0;
+ int s = 0;
+ int rc = 0;
if(!numsocks)
return GETSOCK_BLANK;
@@ -805,7 +812,7 @@ static int waitconnect_getsock(struct connectdata *conn,
return Curl_ssl_getsock(conn, sock, numsocks);
#endif
- for(i=0; i<2; i++) {
+ for(i = 0; i<2; i++) {
if(conn->tempsock[i] != CURL_SOCKET_BAD) {
sock[s] = conn->tempsock[i];
rc |= GETSOCK_WRITESOCK(s++);
@@ -826,7 +833,7 @@ static int waitproxyconnect_getsock(struct connectdata *conn,
/* when we've sent a CONNECT to a proxy, we should rather wait for the
socket to become readable to be able to get the response headers */
- if(conn->tunnel_state[FIRSTSOCKET] == TUNNEL_CONNECT)
+ if(conn->connect_state)
return GETSOCK_READSOCK(0);
return GETSOCK_WRITESOCK(0);
@@ -847,18 +854,16 @@ static int multi_getsock(struct Curl_easy *data,
of sockets */
int numsocks)
{
- /* If the pipe broke, or if there's no connection left for this easy handle,
- then we MUST bail out now with no bitmask set. The no connection case can
- happen when this is called from curl_multi_remove_handle() =>
- singlesocket() => multi_getsock().
+ /* The no connection case can happen when this is called from
+ curl_multi_remove_handle() => singlesocket() => multi_getsock().
*/
- if(data->state.pipe_broke || !data->easy_conn)
+ if(!data->conn)
return 0;
if(data->mstate > CURLM_STATE_CONNECT &&
data->mstate < CURLM_STATE_COMPLETED) {
/* Set up ownership correctly */
- data->easy_conn->data = data;
+ data->conn->data = data;
}
switch(data->mstate) {
@@ -879,31 +884,30 @@ static int multi_getsock(struct Curl_easy *data,
return 0;
case CURLM_STATE_WAITRESOLVE:
- return Curl_resolver_getsock(data->easy_conn, socks, numsocks);
+ return Curl_resolv_getsock(data->conn, socks, numsocks);
case CURLM_STATE_PROTOCONNECT:
case CURLM_STATE_SENDPROTOCONNECT:
- return Curl_protocol_getsock(data->easy_conn, socks, numsocks);
+ return Curl_protocol_getsock(data->conn, socks, numsocks);
case CURLM_STATE_DO:
case CURLM_STATE_DOING:
- return Curl_doing_getsock(data->easy_conn, socks, numsocks);
+ return Curl_doing_getsock(data->conn, socks, numsocks);
case CURLM_STATE_WAITPROXYCONNECT:
- return waitproxyconnect_getsock(data->easy_conn, socks, numsocks);
+ return waitproxyconnect_getsock(data->conn, socks, numsocks);
case CURLM_STATE_WAITCONNECT:
- return waitconnect_getsock(data->easy_conn, socks, numsocks);
+ return waitconnect_getsock(data->conn, socks, numsocks);
case CURLM_STATE_DO_MORE:
- return domore_getsock(data->easy_conn, socks, numsocks);
+ return domore_getsock(data->conn, socks, numsocks);
case CURLM_STATE_DO_DONE: /* since is set after DO is completed, we switch
to waiting for the same as the *PERFORM
states */
case CURLM_STATE_PERFORM:
- case CURLM_STATE_WAITPERFORM:
- return Curl_single_getsock(data->easy_conn, socks, numsocks);
+ return Curl_single_getsock(data->conn, socks, numsocks);
}
}
@@ -916,20 +920,22 @@ CURLMcode curl_multi_fdset(struct Curl_multi *multi,
Some easy handles may not have connected to the remote host yet,
and then we must make sure that is done. */
struct Curl_easy *data;
- int this_max_fd=-1;
+ 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;
- data=multi->easyp;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
+ data = multi->easyp;
while(data) {
- bitmap = multi_getsock(data, sockbunch, MAX_SOCKSPEREASYHANDLE);
+ int bitmap = multi_getsock(data, sockbunch, MAX_SOCKSPEREASYHANDLE);
- for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
+ for(i = 0; i< MAX_SOCKSPEREASYHANDLE; i++) {
curl_socket_t s = CURL_SOCKET_BAD;
if((bitmap & GETSOCK_READSOCK(i)) && VALID_SOCK((sockbunch[i]))) {
@@ -957,11 +963,12 @@ CURLMcode curl_multi_fdset(struct Curl_multi *multi,
#define NUM_POLLS_ON_STACK 10
-CURLMcode curl_multi_wait(struct Curl_multi *multi,
+CURLMcode Curl_multi_wait(struct Curl_multi *multi,
struct curl_waitfd extra_fds[],
unsigned int extra_nfds,
int timeout_ms,
- int *ret)
+ int *ret,
+ bool *gotsocket) /* if any socket was checked */
{
struct Curl_easy *data;
curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
@@ -969,28 +976,27 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
unsigned int i;
unsigned int nfds = 0;
unsigned int curlfds;
- struct pollfd *ufds = NULL;
bool ufds_malloc = FALSE;
long timeout_internal;
int retcode = 0;
struct pollfd a_few_on_stack[NUM_POLLS_ON_STACK];
+ struct pollfd *ufds = &a_few_on_stack[0];
+
+ if(gotsocket)
+ *gotsocket = FALSE;
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;
- /* If the internally desired timeout is actually shorter than requested from
- the outside, then use the shorter time! But only if the internal timer
- is actually larger than -1! */
- (void)multi_timeout(multi, &timeout_internal);
- if((timeout_internal >= 0) && (timeout_internal < (long)timeout_ms))
- timeout_ms = (int)timeout_internal;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
/* Count up how many fds we have from the multi handle */
- data=multi->easyp;
+ data = multi->easyp;
while(data) {
bitmap = multi_getsock(data, sockbunch, MAX_SOCKSPEREASYHANDLE);
- for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
+ for(i = 0; i< MAX_SOCKSPEREASYHANDLE; i++) {
curl_socket_t s = CURL_SOCKET_BAD;
if(bitmap & GETSOCK_READSOCK(i)) {
@@ -1009,18 +1015,25 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
data = data->next; /* check next handle */
}
+ /* If the internally desired timeout is actually shorter than requested from
+ the outside, then use the shorter time! But only if the internal timer
+ is actually larger than -1! */
+ (void)multi_timeout(multi, &timeout_internal);
+ if((timeout_internal >= 0) && (timeout_internal < (long)timeout_ms))
+ timeout_ms = (int)timeout_internal;
+
curlfds = nfds; /* number of internal file descriptors */
nfds += extra_nfds; /* add the externally provided ones */
- if(nfds) {
- if(nfds > NUM_POLLS_ON_STACK) {
- ufds = malloc(nfds * sizeof(struct pollfd));
- if(!ufds)
- return CURLM_OUT_OF_MEMORY;
- ufds_malloc = TRUE;
- }
- else
- ufds = &a_few_on_stack[0];
+ if(nfds > NUM_POLLS_ON_STACK) {
+ /* 'nfds' is a 32 bit value and 'struct pollfd' is typically 8 bytes
+ big, so at 2^29 sockets this value might wrap. When a process gets
+ the capability to actually handle over 500 million sockets this
+ calculation needs a integer overflow check. */
+ ufds = malloc(nfds * sizeof(struct pollfd));
+ if(!ufds)
+ return CURLM_OUT_OF_MEMORY;
+ ufds_malloc = TRUE;
}
nfds = 0;
@@ -1029,11 +1042,11 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
if(curlfds) {
/* Add the curl handles to our pollfds first */
- data=multi->easyp;
+ data = multi->easyp;
while(data) {
bitmap = multi_getsock(data, sockbunch, MAX_SOCKSPEREASYHANDLE);
- for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++) {
+ for(i = 0; i< MAX_SOCKSPEREASYHANDLE; i++) {
curl_socket_t s = CURL_SOCKET_BAD;
if(bitmap & GETSOCK_READSOCK(i)) {
@@ -1074,8 +1087,6 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
int pollrc;
/* wait... */
pollrc = Curl_poll(ufds, nfds, timeout_ms);
- DEBUGF(infof(data, "Curl_poll(%d ds, %d ms) == %d\n",
- nfds, timeout_ms, pollrc));
if(pollrc > 0) {
retcode = pollrc;
@@ -1102,19 +1113,20 @@ CURLMcode curl_multi_wait(struct Curl_multi *multi,
free(ufds);
if(ret)
*ret = retcode;
+ if(gotsocket && (extra_fds || curlfds))
+ /* if any socket was checked */
+ *gotsocket = TRUE;
+
return CURLM_OK;
}
-/*
- * Curl_multi_connchanged() is called to tell that there is a connection in
- * this multi handle that has changed state (pipelining become possible, the
- * number of allowed streams changed or similar), and a subsequent use of this
- * multi handle should move CONNECT_PEND handles back to CONNECT to have them
- * retry.
- */
-void Curl_multi_connchanged(struct Curl_multi *multi)
+CURLMcode curl_multi_wait(struct Curl_multi *multi,
+ struct curl_waitfd extra_fds[],
+ unsigned int extra_nfds,
+ int timeout_ms,
+ int *ret)
{
- multi->recheckstate = TRUE;
+ return Curl_multi_wait(multi, extra_fds, extra_nfds, timeout_ms, ret, NULL);
}
/*
@@ -1139,6 +1151,9 @@ CURLMcode Curl_multi_add_perform(struct Curl_multi *multi,
{
CURLMcode rc;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
rc = curl_multi_add_handle(multi, data);
if(!rc) {
struct SingleRequest *k = &data->req;
@@ -1149,111 +1164,36 @@ CURLMcode Curl_multi_add_perform(struct Curl_multi *multi,
/* take this handle to the perform state right away */
multistate(data, CURLM_STATE_PERFORM);
- data->easy_conn = conn;
+ Curl_attach_connnection(data, conn);
k->keepon |= KEEP_RECV; /* setup to receive! */
}
return rc;
}
-static CURLcode multi_reconnect_request(struct connectdata **connp)
-{
- CURLcode result = CURLE_OK;
- struct connectdata *conn = *connp;
- struct Curl_easy *data = conn->data;
-
- /* 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");
-
- connclose(conn, "Reconnect dead connection"); /* enforce close */
- result = multi_done(&conn, result, FALSE); /* we are so done with this */
-
- /* conn may no longer be a good pointer, clear it to avoid mistakes by
- parent functions */
- *connp = NULL;
-
- /*
- * We need to check for CURLE_SEND_ERROR here as well. This could happen
- * when the request failed on a FTP connection and thus multi_done() itself
- * tried to use the connection (again).
- */
- if(!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(!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_resolver_wait_resolv(conn, NULL);
- if(result)
- return result;
-
- /* Resolved, continue with the connection */
- result = Curl_async_resolved(conn, &protocol_done);
- if(result)
- return result;
- }
- }
- }
-
- return result;
-}
-
/*
* do_complete is called when the DO actions are complete.
*
* We init chunking and trailer bits to their default values here immediately
- * before receiving any header data for the current request in the pipeline.
+ * before receiving any header data for the current request.
*/
static void do_complete(struct connectdata *conn)
{
- conn->data->req.chunk=FALSE;
- conn->data->req.maxfd = (conn->sockfd>conn->writesockfd?
- conn->sockfd:conn->writesockfd)+1;
+ conn->data->req.chunk = FALSE;
Curl_pgrsTime(conn->data, TIMER_PRETRANSFER);
}
-static CURLcode multi_do(struct connectdata **connp, bool *done)
+static CURLcode multi_do(struct Curl_easy *data, bool *done)
{
- CURLcode result=CURLE_OK;
- struct connectdata *conn = *connp;
- struct Curl_easy *data = conn->data;
+ CURLcode result = CURLE_OK;
+ struct connectdata *conn = data->conn;
+
+ DEBUGASSERT(conn);
+ DEBUGASSERT(conn->handler);
if(conn->handler->do_it) {
/* generic protocol-specific function pointer set in curl_connect() */
result = conn->handler->do_it(conn, done);
- /* This was formerly done in transfer.c, but we better do it here */
- if((CURLE_SEND_ERROR == result) && conn->bits.reuse) {
- /*
- * If the connection is using an easy handle, call reconnect
- * to re-establish the connection. Otherwise, let the multi logic
- * figure out how to re-establish the connection.
- */
- if(!data->multi) {
- result = multi_reconnect_request(connp);
-
- if(!result) {
- /* ... finally back to actually retry the DO phase */
- conn = *connp; /* re-assign conn since multi_reconnect_request
- creates a new connection */
- result = conn->handler->do_it(conn, done);
- }
- }
- else
- return result;
- }
-
if(!result && *done)
/* do_complete must be called after the protocol-specific DO function */
do_complete(conn);
@@ -1266,15 +1206,13 @@ static CURLcode multi_do(struct connectdata **connp, bool *done)
* second stage DO state which (wrongly) was introduced to support FTP's
* second connection.
*
- * TODO: A future libcurl should be able to work away this state.
- *
* 'complete' can return 0 for incomplete, 1 for done and -1 for go back to
* DOING state there's more work to do!
*/
static CURLcode multi_do_more(struct connectdata *conn, int *complete)
{
- CURLcode result=CURLE_OK;
+ CURLcode result = CURLE_OK;
*complete = 0;
@@ -1289,7 +1227,7 @@ static CURLcode multi_do_more(struct connectdata *conn, int *complete)
}
static CURLMcode multi_runsingle(struct Curl_multi *multi,
- struct timeval now,
+ struct curltime now,
struct Curl_easy *data)
{
struct Curl_message *msg = NULL;
@@ -1300,10 +1238,9 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
bool done = FALSE;
CURLMcode rc;
CURLcode result = CURLE_OK;
- struct SingleRequest *k;
- time_t timeout_ms;
- time_t recv_timeout_ms;
- time_t send_timeout_ms;
+ timediff_t timeout_ms;
+ timediff_t recv_timeout_ms;
+ timediff_t send_timeout_ms;
int control;
if(!GOOD_EASY_HANDLE(data))
@@ -1315,86 +1252,71 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
bool stream_error = FALSE;
rc = CURLM_OK;
- /* Handle the case when the pipe breaks, i.e., the connection
- we're using gets cleaned up and we're left with nothing. */
- if(data->state.pipe_broke) {
- infof(data, "Pipe broke: handle %p, url = %s\n",
- (void *)data, data->state.path);
-
- if(data->mstate < CURLM_STATE_COMPLETED) {
- /* Head back to the CONNECT state */
- multistate(data, CURLM_STATE_CONNECT);
- rc = CURLM_CALL_MULTI_PERFORM;
- result = CURLE_OK;
- }
-
- data->state.pipe_broke = FALSE;
- data->easy_conn = NULL;
- continue;
- }
-
- if(!data->easy_conn &&
+ if(!data->conn &&
data->mstate > CURLM_STATE_CONNECT &&
data->mstate < CURLM_STATE_DONE) {
- /* In all these states, the code will blindly access 'data->easy_conn'
+ /* In all these states, the code will blindly access 'data->conn'
so this is precaution that it isn't NULL. And it silences static
analyzers. */
- failf(data, "In state %d with no easy_conn, bail out!\n", data->mstate);
+ failf(data, "In state %d with no conn, bail out!\n", data->mstate);
return CURLM_INTERNAL_ERROR;
}
if(multi_ischanged(multi, TRUE)) {
DEBUGF(infof(data, "multi changed, check CONNECT_PEND queue!\n"));
- Curl_multi_process_pending_handles(multi);
+ process_pending_handles(multi); /* multiplexed */
}
- if(data->easy_conn && data->mstate > CURLM_STATE_CONNECT &&
- data->mstate < CURLM_STATE_COMPLETED)
+ if(data->conn && data->mstate > CURLM_STATE_CONNECT &&
+ data->mstate < CURLM_STATE_COMPLETED) {
/* Make sure we set the connection's current owner */
- data->easy_conn->data = data;
+ data->conn->data = data;
+ }
- if(data->easy_conn &&
+ if(data->conn &&
(data->mstate >= CURLM_STATE_CONNECT) &&
(data->mstate < CURLM_STATE_COMPLETED)) {
/* we need to wait for the connect state as only then is the start time
stored, but we must not check already completed handles */
-
timeout_ms = Curl_timeleft(data, &now,
- (data->mstate <= CURLM_STATE_WAITDO)?
+ (data->mstate <= CURLM_STATE_DO)?
TRUE:FALSE);
if(timeout_ms < 0) {
/* Handle timed out */
if(data->mstate == CURLM_STATE_WAITRESOLVE)
- failf(data, "Resolving timed out after %ld milliseconds",
- Curl_tvdiff(now, data->progress.t_startsingle));
+ failf(data, "Resolving timed out after %" CURL_FORMAT_TIMEDIFF_T
+ " milliseconds",
+ Curl_timediff(now, data->progress.t_startsingle));
else if(data->mstate == CURLM_STATE_WAITCONNECT)
- failf(data, "Connection timed out after %ld milliseconds",
- Curl_tvdiff(now, data->progress.t_startsingle));
+ failf(data, "Connection timed out after %" CURL_FORMAT_TIMEDIFF_T
+ " milliseconds",
+ Curl_timediff(now, data->progress.t_startsingle));
else {
- k = &data->req;
+ struct SingleRequest *k = &data->req;
if(k->size != -1) {
- failf(data, "Operation timed out after %ld milliseconds with %"
- CURL_FORMAT_CURL_OFF_T " out of %"
+ failf(data, "Operation timed out after %" CURL_FORMAT_TIMEDIFF_T
+ " milliseconds with %" CURL_FORMAT_CURL_OFF_T " out of %"
CURL_FORMAT_CURL_OFF_T " bytes received",
- Curl_tvdiff(now, data->progress.t_startsingle),
+ Curl_timediff(now, data->progress.t_startsingle),
k->bytecount, k->size);
}
else {
- failf(data, "Operation timed out after %ld milliseconds with %"
- CURL_FORMAT_CURL_OFF_T " bytes received",
- Curl_tvdiff(now, data->progress.t_startsingle),
+ failf(data, "Operation timed out after %" CURL_FORMAT_TIMEDIFF_T
+ " milliseconds with %" CURL_FORMAT_CURL_OFF_T
+ " bytes received",
+ Curl_timediff(now, data->progress.t_startsingle),
k->bytecount);
}
}
/* Force connection closed if the connection has indeed been used */
if(data->mstate > CURLM_STATE_DO) {
- streamclose(data->easy_conn, "Disconnected with pending data");
+ streamclose(data->conn, "Disconnected with pending data");
stream_error = TRUE;
}
result = CURLE_OPERATION_TIMEDOUT;
- (void)multi_done(&data->easy_conn, result, TRUE);
+ (void)multi_done(data, result, TRUE);
/* Skip the statemachine and go directly to error handling section. */
goto statemachine_end;
}
@@ -1403,7 +1325,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
switch(data->mstate) {
case CURLM_STATE_INIT:
/* init this transfer. */
- result=Curl_pretransfer(data);
+ result = Curl_pretransfer(data);
if(!result) {
/* after init, go CONNECT */
@@ -1421,8 +1343,13 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
case CURLM_STATE_CONNECT:
/* Connect. We want to get a connection identifier filled in. */
Curl_pgrsTime(data, TIMER_STARTSINGLE);
- result = Curl_connect(data, &data->easy_conn,
- &async, &protocol_connect);
+ if(data->set.timeout)
+ Curl_expire(data, data->set.timeout, EXPIRE_TIMEOUT);
+
+ if(data->set.connecttimeout)
+ Curl_expire(data, data->set.connecttimeout, EXPIRE_CONNECTTIMEOUT);
+
+ result = Curl_connect(data, &async, &protocol_connect);
if(CURLE_NO_CONNECTION_AVAILABLE == result) {
/* There was no connection available. We will go to the pending
state and wait for an available connection. */
@@ -1434,33 +1361,31 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
result = CURLE_OK;
break;
}
+ else if(data->state.previouslypending) {
+ /* this transfer comes from the pending queue so try move another */
+ infof(data, "Transfer was pending, now try another\n");
+ process_pending_handles(data->multi);
+ }
if(!result) {
- /* Add this handle to the send or pend pipeline */
- result = Curl_add_handle_to_pipeline(data, data->easy_conn);
- if(result)
- stream_error = TRUE;
+ if(async)
+ /* We're now waiting for an asynchronous name lookup */
+ multistate(data, CURLM_STATE_WAITRESOLVE);
else {
- if(async)
- /* We're now waiting for an asynchronous name lookup */
- multistate(data, 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 or DO! */
- rc = CURLM_CALL_MULTI_PERFORM;
+ /* after the connect has been sent off, go WAITCONNECT unless the
+ protocol connect is already done and we can go directly to
+ WAITDO or DO! */
+ rc = CURLM_CALL_MULTI_PERFORM;
- if(protocol_connect)
- multistate(data, Curl_pipeline_wanted(multi, CURLPIPE_HTTP1)?
- CURLM_STATE_WAITDO:CURLM_STATE_DO);
- else {
+ if(protocol_connect)
+ multistate(data, CURLM_STATE_DO);
+ else {
#ifndef CURL_DISABLE_HTTP
- if(data->easy_conn->tunnel_state[FIRSTSOCKET] == TUNNEL_CONNECT)
- multistate(data, CURLM_STATE_WAITPROXYCONNECT);
- else
+ if(Curl_connect_ongoing(data->conn))
+ multistate(data, CURLM_STATE_WAITPROXYCONNECT);
+ else
#endif
- multistate(data, CURLM_STATE_WAITCONNECT);
- }
+ multistate(data, CURLM_STATE_WAITCONNECT);
}
}
}
@@ -1470,9 +1395,10 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
/* awaiting an asynch name resolve to complete */
{
struct Curl_dns_entry *dns = NULL;
- struct connectdata *conn = data->easy_conn;
+ struct connectdata *conn = data->conn;
const char *hostname;
+ DEBUGASSERT(conn);
if(conn->bits.httpproxy)
hostname = conn->http_proxy.host.name;
else if(conn->bits.conn_to_host)
@@ -1493,7 +1419,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
}
if(!dns)
- result = Curl_resolver_is_resolved(data->easy_conn, &dns);
+ result = Curl_resolv_check(data->conn, &dns);
/* Update sockets here, because the socket(s) may have been
closed and the application thus needs to be told, even if it
@@ -1506,21 +1432,20 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
if(dns) {
/* Perform the next step in the connection phase, and then move on
to the WAITCONNECT state */
- result = Curl_async_resolved(data->easy_conn, &protocol_connect);
+ result = Curl_once_resolved(data->conn, &protocol_connect);
if(result)
- /* if Curl_async_resolved() returns failure, the connection struct
+ /* if Curl_once_resolved() returns failure, the connection struct
is already freed and gone */
- data->easy_conn = NULL; /* no more connection */
+ data->conn = NULL; /* no more connection */
else {
/* call again please so that we get the next socket setup */
rc = CURLM_CALL_MULTI_PERFORM;
if(protocol_connect)
- multistate(data, Curl_pipeline_wanted(multi, CURLPIPE_HTTP1)?
- CURLM_STATE_WAITDO:CURLM_STATE_DO);
+ multistate(data, CURLM_STATE_DO);
else {
#ifndef CURL_DISABLE_HTTP
- if(data->easy_conn->tunnel_state[FIRSTSOCKET] == TUNNEL_CONNECT)
+ if(Curl_connect_ongoing(data->conn))
multistate(data, CURLM_STATE_WAITPROXYCONNECT);
else
#endif
@@ -1540,124 +1465,120 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
#ifndef CURL_DISABLE_HTTP
case CURLM_STATE_WAITPROXYCONNECT:
/* this is HTTP-specific, but sending CONNECT to a proxy is HTTP... */
- result = Curl_http_connect(data->easy_conn, &protocol_connect);
+ DEBUGASSERT(data->conn);
+ result = Curl_http_connect(data->conn, &protocol_connect);
- if(data->easy_conn->bits.proxy_connect_closed) {
+ if(data->conn->bits.proxy_connect_closed) {
rc = CURLM_CALL_MULTI_PERFORM;
/* connect back to proxy again */
result = CURLE_OK;
- multi_done(&data->easy_conn, CURLE_OK, FALSE);
+ multi_done(data, CURLE_OK, FALSE);
multistate(data, CURLM_STATE_CONNECT);
}
else if(!result) {
- if((data->easy_conn->http_proxy.proxytype != CURLPROXY_HTTPS ||
- data->easy_conn->bits.proxy_ssl_connected[FIRSTSOCKET]) &&
- (data->easy_conn->tunnel_state[FIRSTSOCKET] != TUNNEL_CONNECT)) {
+ if((data->conn->http_proxy.proxytype != CURLPROXY_HTTPS ||
+ data->conn->bits.proxy_ssl_connected[FIRSTSOCKET]) &&
+ Curl_connect_complete(data->conn)) {
rc = CURLM_CALL_MULTI_PERFORM;
/* initiate protocol connect phase */
multistate(data, CURLM_STATE_SENDPROTOCONNECT);
}
}
+ else if(result)
+ stream_error = TRUE;
break;
#endif
case CURLM_STATE_WAITCONNECT:
/* awaiting a completion of an asynch TCP connect */
- result = Curl_is_connected(data->easy_conn, FIRSTSOCKET, &connected);
+ DEBUGASSERT(data->conn);
+ result = Curl_is_connected(data->conn, FIRSTSOCKET, &connected);
if(connected && !result) {
#ifndef CURL_DISABLE_HTTP
- if((data->easy_conn->http_proxy.proxytype == CURLPROXY_HTTPS &&
- !data->easy_conn->bits.proxy_ssl_connected[FIRSTSOCKET]) ||
- (data->easy_conn->tunnel_state[FIRSTSOCKET] == TUNNEL_CONNECT)) {
+ if((data->conn->http_proxy.proxytype == CURLPROXY_HTTPS &&
+ !data->conn->bits.proxy_ssl_connected[FIRSTSOCKET]) ||
+ Curl_connect_ongoing(data->conn)) {
multistate(data, CURLM_STATE_WAITPROXYCONNECT);
break;
}
#endif
rc = CURLM_CALL_MULTI_PERFORM;
- multistate(data, data->easy_conn->bits.tunnel_proxy?
+ multistate(data, data->conn->bits.tunnel_proxy?
CURLM_STATE_WAITPROXYCONNECT:
CURLM_STATE_SENDPROTOCONNECT);
}
else if(result) {
/* failure detected */
- /* Just break, the cleaning up is handled all in one place */
+ Curl_posttransfer(data);
+ multi_done(data, result, TRUE);
stream_error = TRUE;
break;
}
break;
case CURLM_STATE_SENDPROTOCONNECT:
- result = Curl_protocol_connect(data->easy_conn, &protocol_connect);
- if(!protocol_connect)
+ result = Curl_protocol_connect(data->conn, &protocol_connect);
+ if(!result && !protocol_connect)
/* switch to waiting state */
multistate(data, CURLM_STATE_PROTOCONNECT);
else if(!result) {
/* protocol connect has completed, go WAITDO or DO */
- multistate(data, Curl_pipeline_wanted(multi, CURLPIPE_HTTP1)?
- CURLM_STATE_WAITDO:CURLM_STATE_DO);
+ multistate(data, CURLM_STATE_DO);
rc = CURLM_CALL_MULTI_PERFORM;
}
else if(result) {
/* failure detected */
Curl_posttransfer(data);
- multi_done(&data->easy_conn, result, TRUE);
+ multi_done(data, result, TRUE);
stream_error = TRUE;
}
break;
case CURLM_STATE_PROTOCONNECT:
/* protocol-specific connect phase */
- result = Curl_protocol_connecting(data->easy_conn, &protocol_connect);
+ result = Curl_protocol_connecting(data->conn, &protocol_connect);
if(!result && protocol_connect) {
/* after the connect has completed, go WAITDO or DO */
- multistate(data, Curl_pipeline_wanted(multi, CURLPIPE_HTTP1)?
- CURLM_STATE_WAITDO:CURLM_STATE_DO);
+ multistate(data, CURLM_STATE_DO);
rc = CURLM_CALL_MULTI_PERFORM;
}
else if(result) {
/* failure detected */
Curl_posttransfer(data);
- multi_done(&data->easy_conn, result, TRUE);
+ multi_done(data, result, TRUE);
stream_error = TRUE;
}
break;
- case CURLM_STATE_WAITDO:
- /* Wait for our turn to DO when we're pipelining requests */
- if(Curl_pipeline_checkget_write(data, data->easy_conn)) {
- /* Grabbed the channel */
- multistate(data, CURLM_STATE_DO);
- rc = CURLM_CALL_MULTI_PERFORM;
- }
- break;
-
case CURLM_STATE_DO:
if(data->set.connect_only) {
/* keep connection open for application to use the socket */
- connkeep(data->easy_conn, "CONNECT_ONLY");
+ connkeep(data->conn, "CONNECT_ONLY");
multistate(data, CURLM_STATE_DONE);
result = CURLE_OK;
rc = CURLM_CALL_MULTI_PERFORM;
}
else {
/* Perform the protocol's DO action */
- result = multi_do(&data->easy_conn, &dophase_done);
+ result = multi_do(data, &dophase_done);
- /* When multi_do() returns failure, data->easy_conn might be NULL! */
+ /* When multi_do() returns failure, data->conn might be NULL! */
if(!result) {
if(!dophase_done) {
+#ifndef CURL_DISABLE_FTP
/* some steps needed for wildcard matching */
- if(data->set.wildcardmatch) {
+ if(data->state.wildcardmatch) {
struct WildcardData *wc = &data->wildcard;
if(wc->state == CURLWC_DONE || wc->state == CURLWC_SKIP) {
/* skip some states if it is important */
- multi_done(&data->easy_conn, CURLE_OK, FALSE);
+ multi_done(data, CURLE_OK, FALSE);
multistate(data, CURLM_STATE_DONE);
rc = CURLM_CALL_MULTI_PERFORM;
break;
}
}
+#endif
/* DO was not completed in one function call, we must continue
DOING... */
multistate(data, CURLM_STATE_DOING);
@@ -1665,7 +1586,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
}
/* after DO, go DO_DONE... or DO_MORE */
- else if(data->easy_conn->bits.do_more) {
+ else if(data->conn->bits.do_more) {
/* we're supposed to do more, but we need to sit down, relax
and wait a little while first */
multistate(data, CURLM_STATE_DO_MORE);
@@ -1678,32 +1599,29 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
}
}
else if((CURLE_SEND_ERROR == result) &&
- data->easy_conn->bits.reuse) {
+ data->conn->bits.reuse) {
/*
* In this situation, a connection that we were trying to use
* may have unexpectedly died. If possible, send the connection
* back to the CONNECT phase so we can try again.
*/
char *newurl = NULL;
- followtype follow=FOLLOW_NONE;
+ followtype follow = FOLLOW_NONE;
CURLcode drc;
- bool retry = FALSE;
- drc = Curl_retry_request(data->easy_conn, &newurl);
+ drc = Curl_retry_request(data->conn, &newurl);
if(drc) {
/* a failure here pretty much implies an out of memory */
result = drc;
stream_error = TRUE;
}
- else
- retry = (newurl)?TRUE:FALSE;
Curl_posttransfer(data);
- drc = multi_done(&data->easy_conn, result, FALSE);
+ drc = multi_done(data, result, FALSE);
/* When set to retry the connection, we must to go back to
* the CONNECT state */
- if(retry) {
+ if(newurl) {
if(!drc || (drc == CURLE_SEND_ERROR)) {
follow = FOLLOW_RETRY;
drc = Curl_follow(data, newurl, follow);
@@ -1731,8 +1649,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
else {
/* failure detected */
Curl_posttransfer(data);
- if(data->easy_conn)
- multi_done(&data->easy_conn, result, FALSE);
+ if(data->conn)
+ multi_done(data, result, FALSE);
stream_error = TRUE;
}
}
@@ -1740,12 +1658,13 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
case CURLM_STATE_DOING:
/* we continue DOING until the DO phase is complete */
- result = Curl_protocol_doing(data->easy_conn,
+ DEBUGASSERT(data->conn);
+ result = Curl_protocol_doing(data->conn,
&dophase_done);
if(!result) {
if(dophase_done) {
/* after DO, go DO_DONE or DO_MORE */
- multistate(data, data->easy_conn->bits.do_more?
+ multistate(data, data->conn->bits.do_more?
CURLM_STATE_DO_MORE:
CURLM_STATE_DO_DONE);
rc = CURLM_CALL_MULTI_PERFORM;
@@ -1754,7 +1673,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
else {
/* failure detected */
Curl_posttransfer(data);
- multi_done(&data->easy_conn, result, FALSE);
+ multi_done(data, result, FALSE);
stream_error = TRUE;
}
break;
@@ -1763,15 +1682,14 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
/*
* When we are connected, DO MORE and then go DO_DONE
*/
- result = multi_do_more(data->easy_conn, &control);
+ DEBUGASSERT(data->conn);
+ result = multi_do_more(data->conn, &control);
- /* No need to remove this handle from the send pipeline here since that
- is done in multi_done() */
if(!result) {
if(control) {
/* if positive, advance to DO_DONE
if negative, go back to DOING */
- multistate(data, control==1?
+ multistate(data, control == 1?
CURLM_STATE_DO_DONE:
CURLM_STATE_DOING);
rc = CURLM_CALL_MULTI_PERFORM;
@@ -1783,39 +1701,38 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
else {
/* failure detected */
Curl_posttransfer(data);
- multi_done(&data->easy_conn, result, FALSE);
+ multi_done(data, result, FALSE);
stream_error = TRUE;
}
break;
case CURLM_STATE_DO_DONE:
- /* Move ourselves from the send to recv pipeline */
- Curl_move_handle_from_send_to_recv_pipe(data, data->easy_conn);
- /* Check if we can move pending requests to send pipe */
- Curl_multi_process_pending_handles(multi);
+ DEBUGASSERT(data->conn);
+ if(data->conn->bits.multiplex)
+ /* Check if we can move pending requests to send pipe */
+ process_pending_handles(multi); /* multiplexed */
/* Only perform the transfer if there's a good socket to work with.
Having both BAD is a signal to skip immediately to DONE */
- if((data->easy_conn->sockfd != CURL_SOCKET_BAD) ||
- (data->easy_conn->writesockfd != CURL_SOCKET_BAD))
- multistate(data, CURLM_STATE_WAITPERFORM);
- else
- multistate(data, CURLM_STATE_DONE);
- rc = CURLM_CALL_MULTI_PERFORM;
- break;
-
- case CURLM_STATE_WAITPERFORM:
- /* Wait for our turn to PERFORM */
- if(Curl_pipeline_checkget_read(data, data->easy_conn)) {
- /* Grabbed the channel */
+ if((data->conn->sockfd != CURL_SOCKET_BAD) ||
+ (data->conn->writesockfd != CURL_SOCKET_BAD))
multistate(data, CURLM_STATE_PERFORM);
- rc = CURLM_CALL_MULTI_PERFORM;
+ else {
+#ifndef CURL_DISABLE_FTP
+ if(data->state.wildcardmatch &&
+ ((data->conn->handler->flags & PROTOPT_WILDCARD) == 0)) {
+ data->wildcard.state = CURLWC_DONE;
+ }
+#endif
+ multistate(data, CURLM_STATE_DONE);
}
+ rc = CURLM_CALL_MULTI_PERFORM;
break;
case CURLM_STATE_TOOFAST: /* limit-rate exceeded in either direction */
+ DEBUGASSERT(data->conn);
/* if both rates are within spec, resume transfer */
- if(Curl_pgrsUpdate(data->easy_conn))
+ if(Curl_pgrsUpdate(data->conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
result = Curl_speedcheck(data, now);
@@ -1823,22 +1740,26 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
if(!result) {
send_timeout_ms = 0;
if(data->set.max_send_speed > 0)
- send_timeout_ms = Curl_pgrsLimitWaitTime(data->progress.uploaded,
- data->progress.ul_limit_size,
- data->set.max_send_speed,
- data->progress.ul_limit_start,
- now);
+ send_timeout_ms =
+ Curl_pgrsLimitWaitTime(data->progress.uploaded,
+ data->progress.ul_limit_size,
+ data->set.max_send_speed,
+ data->progress.ul_limit_start,
+ now);
recv_timeout_ms = 0;
if(data->set.max_recv_speed > 0)
- recv_timeout_ms = Curl_pgrsLimitWaitTime(data->progress.downloaded,
- data->progress.dl_limit_size,
- data->set.max_recv_speed,
- data->progress.dl_limit_start,
- now);
-
- if(send_timeout_ms <= 0 && recv_timeout_ms <= 0)
+ recv_timeout_ms =
+ Curl_pgrsLimitWaitTime(data->progress.downloaded,
+ data->progress.dl_limit_size,
+ data->set.max_recv_speed,
+ data->progress.dl_limit_start,
+ now);
+
+ if(!send_timeout_ms && !recv_timeout_ms) {
multistate(data, CURLM_STATE_PERFORM);
+ Curl_ratelimit(data, now);
+ }
else if(send_timeout_ms >= recv_timeout_ms)
Curl_expire(data, send_timeout_ms, EXPIRE_TOOFAST);
else
@@ -1870,7 +1791,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
data->progress.dl_limit_start,
now);
- if(send_timeout_ms > 0 || recv_timeout_ms > 0) {
+ if(send_timeout_ms || recv_timeout_ms) {
+ Curl_ratelimit(data, now);
multistate(data, CURLM_STATE_TOOFAST);
if(send_timeout_ms >= recv_timeout_ms)
Curl_expire(data, send_timeout_ms, EXPIRE_TOOFAST);
@@ -1880,26 +1802,18 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
}
/* read/write data if it is ready to do so */
- result = Curl_readwrite(data->easy_conn, data, &done, &comeback);
-
- k = &data->req;
-
- if(!(k->keepon & KEEP_RECV))
- /* We're done receiving */
- Curl_pipeline_leave_read(data->easy_conn);
-
- if(!(k->keepon & KEEP_SEND))
- /* We're done sending */
- Curl_pipeline_leave_write(data->easy_conn);
+ result = Curl_readwrite(data->conn, data, &done, &comeback);
if(done || (result == CURLE_RECV_ERROR)) {
/* If CURLE_RECV_ERROR happens early enough, we assume it was a race
* condition and the server closed the re-used connection exactly when
* we wanted to use it, so figure out if that is indeed the case.
*/
- CURLcode ret = Curl_retry_request(data->easy_conn, &newurl);
+ CURLcode ret = Curl_retry_request(data->conn, &newurl);
if(!ret)
retry = (newurl)?TRUE:FALSE;
+ else if(!result)
+ result = ret;
if(retry) {
/* if we are to retry, set the result to OK and consider the
@@ -1908,6 +1822,27 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
done = TRUE;
}
}
+ else if((CURLE_HTTP2_STREAM == result) &&
+ Curl_h2_http_1_1_error(data->conn)) {
+ CURLcode ret = Curl_retry_request(data->conn, &newurl);
+
+ if(!ret) {
+ infof(data, "Downgrades to HTTP/1.1!\n");
+ data->set.httpversion = CURL_HTTP_VERSION_1_1;
+ /* clear the error message bit too as we ignore the one we got */
+ data->state.errorbuf = FALSE;
+ if(!newurl)
+ /* typically for HTTP_1_1_REQUIRED error on first flight */
+ newurl = strdup(data->change.url);
+ /* if we are to retry, set the result to OK and consider the request
+ as done */
+ retry = TRUE;
+ result = CURLE_OK;
+ done = TRUE;
+ }
+ else
+ result = ret;
+ }
if(result) {
/*
@@ -1918,29 +1853,19 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
* happened in the data connection.
*/
- if(!(data->easy_conn->handler->flags & PROTOPT_DUAL) &&
+ if(!(data->conn->handler->flags & PROTOPT_DUAL) &&
result != CURLE_HTTP2_STREAM)
- streamclose(data->easy_conn, "Transfer returned error");
+ streamclose(data->conn, "Transfer returned error");
Curl_posttransfer(data);
- multi_done(&data->easy_conn, result, TRUE);
+ multi_done(data, result, TRUE);
}
else if(done) {
- followtype follow=FOLLOW_NONE;
+ followtype follow = FOLLOW_NONE;
/* call this even if the readwrite function returned error */
Curl_posttransfer(data);
- /* we're no longer receiving */
- Curl_removeHandleFromPipeline(data, &data->easy_conn->recv_pipe);
-
- /* expire the new receiving pipeline head */
- if(data->easy_conn->recv_pipe.head)
- Curl_expire(data->easy_conn->recv_pipe.head->ptr, 0, EXPIRE_RUN_NOW);
-
- /* Check if we can move pending requests to send pipe */
- Curl_multi_process_pending_handles(multi);
-
/* When we follow redirects or is set to retry the connection, we must
to go back to the CONNECT state */
if(data->req.newurl || retry) {
@@ -1954,14 +1879,14 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
}
else
follow = FOLLOW_RETRY;
- result = multi_done(&data->easy_conn, CURLE_OK, FALSE);
+ (void)multi_done(data, CURLE_OK, FALSE);
+ /* multi_done() might return CURLE_GOT_NOTHING */
+ result = Curl_follow(data, newurl, follow);
if(!result) {
- result = Curl_follow(data, newurl, follow);
- if(!result) {
- multistate(data, CURLM_STATE_CONNECT);
- rc = CURLM_CALL_MULTI_PERFORM;
- }
+ multistate(data, CURLM_STATE_CONNECT);
+ rc = CURLM_CALL_MULTI_PERFORM;
}
+ free(newurl);
}
else {
/* after the transfer is done, go DONE */
@@ -1973,18 +1898,21 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
newurl = data->req.location;
data->req.location = NULL;
result = Curl_follow(data, newurl, FOLLOW_FAKE);
- if(result)
+ free(newurl);
+ if(result) {
stream_error = TRUE;
+ result = multi_done(data, result, TRUE);
+ }
}
- multistate(data, CURLM_STATE_DONE);
- rc = CURLM_CALL_MULTI_PERFORM;
+ if(!result) {
+ multistate(data, CURLM_STATE_DONE);
+ rc = CURLM_CALL_MULTI_PERFORM;
+ }
}
}
else if(comeback)
rc = CURLM_CALL_MULTI_PERFORM;
-
- free(newurl);
break;
}
@@ -1992,32 +1920,32 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
/* this state is highly transient, so run another loop after this */
rc = CURLM_CALL_MULTI_PERFORM;
- if(data->easy_conn) {
+ if(data->conn) {
CURLcode res;
- /* Remove ourselves from the receive pipeline, if we are there. */
- Curl_removeHandleFromPipeline(data, &data->easy_conn->recv_pipe);
- /* Check if we can move pending requests to send pipe */
- Curl_multi_process_pending_handles(multi);
+ if(data->conn->bits.multiplex)
+ /* Check if we can move pending requests to connection */
+ process_pending_handles(multi); /* multiplexing */
/* post-transfer command */
- res = multi_done(&data->easy_conn, result, FALSE);
+ res = multi_done(data, result, FALSE);
/* allow a previously set error code take precedence */
if(!result)
result = res;
/*
- * If there are other handles on the pipeline, multi_done won't set
- * easy_conn to NULL. In such a case, curl_multi_remove_handle() can
+ * If there are other handles on the connection, multi_done won't set
+ * conn to NULL. In such a case, curl_multi_remove_handle() can
* access free'd data, if the connection is free'd and the handle
* removed before we perform the processing in CURLM_STATE_COMPLETED
*/
- if(data->easy_conn)
- data->easy_conn = NULL;
+ if(data->conn)
+ detach_connnection(data);
}
- if(data->set.wildcardmatch) {
+#ifndef CURL_DISABLE_FTP
+ if(data->state.wildcardmatch) {
if(data->wildcard.state != CURLWC_DONE) {
/* if a wildcard is set and we are not ending -> lets start again
with CURLM_STATE_INIT */
@@ -2025,23 +1953,13 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
break;
}
}
-
+#endif
/* after we have DONE what we're supposed to do, go COMPLETED, and
it doesn't matter what the multi_done() returned! */
multistate(data, CURLM_STATE_COMPLETED);
break;
case CURLM_STATE_COMPLETED:
- /* 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. */
-
- /* Important: reset the conn pointer so that we don't point to memory
- that could be freed anytime */
- data->easy_conn = NULL;
-
- Curl_expire_clear(data); /* stop all timers */
break;
case CURLM_STATE_MSGSENT:
@@ -2063,28 +1981,20 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
/* NOTE: no attempt to disconnect connections must be made
in the case blocks above - cleanup happens only here */
- data->state.pipe_broke = FALSE;
-
/* Check if we can move pending requests to send pipe */
- Curl_multi_process_pending_handles(multi);
-
- if(data->easy_conn) {
- /* if this has a connection, unsubscribe from the pipelines */
- Curl_pipeline_leave_write(data->easy_conn);
- Curl_pipeline_leave_read(data->easy_conn);
- Curl_removeHandleFromPipeline(data, &data->easy_conn->send_pipe);
- Curl_removeHandleFromPipeline(data, &data->easy_conn->recv_pipe);
+ process_pending_handles(multi); /* connection */
+ if(data->conn) {
if(stream_error) {
/* Don't attempt to send data over a connection that timed out */
bool dead_connection = result == CURLE_OPERATION_TIMEDOUT;
/* disconnect properly */
- Curl_disconnect(data->easy_conn, dead_connection);
+ Curl_disconnect(data, data->conn, dead_connection);
- /* This is where we make sure that the easy_conn pointer is reset.
+ /* This is where we make sure that the conn pointer is reset.
We don't have to do this in every case block above where a
failure is detected */
- data->easy_conn = NULL;
+ detach_connnection(data);
}
}
else if(data->mstate == CURLM_STATE_CONNECT) {
@@ -2093,13 +2003,14 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
}
multistate(data, CURLM_STATE_COMPLETED);
+ rc = CURLM_CALL_MULTI_PERFORM;
}
/* if there's still a connection to use, call the progress function */
- else if(data->easy_conn && Curl_pgrsUpdate(data->easy_conn)) {
+ else if(data->conn && Curl_pgrsUpdate(data->conn)) {
/* aborted due to progress callback return code must close the
connection */
result = CURLE_ABORTED_BY_CALLBACK;
- streamclose(data->easy_conn, "Aborted by callback");
+ streamclose(data->conn, "Aborted by callback");
/* if not yet in DONE state, go there, otherwise COMPLETED */
multistate(data, (data->mstate < CURLM_STATE_DONE)?
@@ -2109,22 +2020,26 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
}
if(CURLM_STATE_COMPLETED == data->mstate) {
- /* now fill in the Curl_message with this info */
- msg = &data->msg;
-
- msg->extmsg.msg = CURLMSG_DONE;
- msg->extmsg.easy_handle = data;
- msg->extmsg.data.result = result;
+ if(data->set.fmultidone) {
+ /* signal via callback instead */
+ data->set.fmultidone(data, result);
+ }
+ else {
+ /* now fill in the Curl_message with this info */
+ msg = &data->msg;
- rc = multi_addmsg(multi, msg);
+ msg->extmsg.msg = CURLMSG_DONE;
+ msg->extmsg.easy_handle = data;
+ msg->extmsg.data.result = result;
+ rc = multi_addmsg(multi, msg);
+ DEBUGASSERT(!data->conn);
+ }
multistate(data, CURLM_STATE_MSGSENT);
}
} while((rc == CURLM_CALL_MULTI_PERFORM) || multi_ischanged(multi, FALSE));
data->result = result;
-
-
return rc;
}
@@ -2132,14 +2047,17 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
CURLMcode curl_multi_perform(struct Curl_multi *multi, int *running_handles)
{
struct Curl_easy *data;
- CURLMcode returncode=CURLM_OK;
+ CURLMcode returncode = CURLM_OK;
struct Curl_tree *t;
- struct timeval now = Curl_tvnow();
+ struct curltime now = Curl_now();
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;
- data=multi->easyp;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
+ data = multi->easyp;
while(data) {
CURLMcode result;
SIGPIPE_VARIABLE(pipe_st);
@@ -2180,61 +2098,24 @@ CURLMcode curl_multi_perform(struct Curl_multi *multi, int *running_handles)
return returncode;
}
-static void close_all_connections(struct Curl_multi *multi)
-{
- struct connectdata *conn;
-
- conn = Curl_conncache_find_first_connection(&multi->conn_cache);
- while(conn) {
- SIGPIPE_VARIABLE(pipe_st);
- conn->data = multi->closure_handle;
-
- sigpipe_ignore(conn->data, &pipe_st);
- conn->data->easy_conn = NULL; /* clear the easy handle's connection
- pointer */
- /* This will remove the connection from the cache */
- connclose(conn, "kill all");
- (void)Curl_disconnect(conn, FALSE);
- sigpipe_restore(&pipe_st);
-
- conn = Curl_conncache_find_first_connection(&multi->conn_cache);
- }
-}
-
CURLMcode curl_multi_cleanup(struct Curl_multi *multi)
{
struct Curl_easy *data;
struct Curl_easy *nextdata;
if(GOOD_MULTI_HANDLE(multi)) {
- bool restore_pipe = FALSE;
- SIGPIPE_VARIABLE(pipe_st);
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
multi->type = 0; /* not good anymore */
- /* Close all the connections in the connection cache */
- close_all_connections(multi);
-
- if(multi->closure_handle) {
- sigpipe_ignore(multi->closure_handle, &pipe_st);
- restore_pipe = TRUE;
-
- multi->closure_handle->dns.hostcache = &multi->hostcache;
- Curl_hostcache_clean(multi->closure_handle,
- multi->closure_handle->dns.hostcache);
-
- Curl_close(multi->closure_handle);
- }
-
- Curl_hash_destroy(&multi->sockhash);
- Curl_conncache_destroy(&multi->conn_cache);
- Curl_llist_destroy(&multi->msglist, NULL);
- Curl_llist_destroy(&multi->pending, NULL);
-
- /* remove all easy handles */
+ /* Firsrt remove all remaining easy handles */
data = multi->easyp;
while(data) {
- nextdata=data->next;
+ nextdata = data->next;
+ if(!data->state.done && data->conn)
+ /* if DONE was never called for this handle */
+ (void)multi_done(data, CURLE_OK, TRUE);
if(data->dns.hostcachetype == HCACHE_MULTI) {
/* clear out the usage of the shared DNS cache */
Curl_hostcache_clean(data, data->dns.hostcache);
@@ -2246,18 +2127,25 @@ CURLMcode curl_multi_cleanup(struct Curl_multi *multi)
data->state.conn_cache = NULL;
data->multi = NULL; /* clear the association */
+#ifdef USE_LIBPSL
+ if(data->psl == &multi->psl)
+ data->psl = NULL;
+#endif
+
data = nextdata;
}
- Curl_hash_destroy(&multi->hostcache);
+ /* Close all the connections in the connection cache */
+ Curl_conncache_close_all_connections(&multi->conn_cache);
- /* Free the blacklists by setting them to NULL */
- Curl_pipeline_set_site_blacklist(NULL, &multi->pipelining_site_bl);
- Curl_pipeline_set_server_blacklist(NULL, &multi->pipelining_server_bl);
+ Curl_hash_destroy(&multi->sockhash);
+ Curl_conncache_destroy(&multi->conn_cache);
+ Curl_llist_destroy(&multi->msglist, NULL);
+ Curl_llist_destroy(&multi->pending, NULL);
+ Curl_hash_destroy(&multi->hostcache);
+ Curl_psl_destroy(&multi->psl);
free(multi);
- if(restore_pipe)
- sigpipe_restore(&pipe_st);
return CURLM_OK;
}
@@ -2280,7 +2168,9 @@ CURLMsg *curl_multi_info_read(struct Curl_multi *multi, int *msgs_in_queue)
*msgs_in_queue = 0; /* default to none */
- if(GOOD_MULTI_HANDLE(multi) && Curl_llist_count(&multi->msglist)) {
+ if(GOOD_MULTI_HANDLE(multi) &&
+ !multi->in_callback &&
+ Curl_llist_count(&multi->msglist)) {
/* there is one or more messages in the list */
struct curl_llist_element *e;
@@ -2304,8 +2194,8 @@ CURLMsg *curl_multi_info_read(struct Curl_multi *multi, int *msgs_in_queue)
* 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_easy *data)
+static CURLMcode singlesocket(struct Curl_multi *multi,
+ struct Curl_easy *data)
{
curl_socket_t socks[MAX_SOCKSPEREASYHANDLE];
int i;
@@ -2313,8 +2203,9 @@ static void singlesocket(struct Curl_multi *multi,
curl_socket_t s;
int num;
unsigned int curraction;
+ int actions[MAX_SOCKSPEREASYHANDLE];
- for(i=0; i< MAX_SOCKSPEREASYHANDLE; i++)
+ 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
@@ -2326,10 +2217,13 @@ static void singlesocket(struct Curl_multi *multi,
longer supervised ones and add new ones */
/* walk over the sockets we got right now */
- for(i=0; (i< MAX_SOCKSPEREASYHANDLE) &&
+ for(i = 0; (i< MAX_SOCKSPEREASYHANDLE) &&
(curraction & (GETSOCK_READSOCK(i) | GETSOCK_WRITESOCK(i)));
i++) {
- int action = CURL_POLL_NONE;
+ unsigned int action = CURL_POLL_NONE;
+ unsigned int prevaction = 0;
+ unsigned int comboaction;
+ bool sincebefore = FALSE;
s = socks[i];
@@ -2341,107 +2235,127 @@ static void singlesocket(struct Curl_multi *multi,
if(curraction & GETSOCK_WRITESOCK(i))
action |= CURL_POLL_OUT;
+ actions[i] = action;
if(entry) {
- /* yeps, already present so check if it has the same action set */
- if(entry->action == action)
- /* same, continue */
- continue;
+ /* check if new for this transfer */
+ for(i = 0; i< data->numsocks; i++) {
+ if(s == data->sockets[i]) {
+ prevaction = data->actions[i];
+ sincebefore = TRUE;
+ break;
+ }
+ }
+
}
else {
- /* this is a socket we didn't have before, add it! */
- entry = sh_addentry(&multi->sockhash, s, data);
+ /* this is a socket we didn't have before, add it to the hash! */
+ entry = sh_addentry(&multi->sockhash, s);
if(!entry)
/* fatal */
- return;
+ return CURLM_OUT_OF_MEMORY;
+ }
+ if(sincebefore && (prevaction != action)) {
+ /* Socket was used already, but different action now */
+ if(prevaction & CURL_POLL_IN)
+ entry->readers--;
+ if(prevaction & CURL_POLL_OUT)
+ entry->writers--;
+ if(action & CURL_POLL_IN)
+ entry->readers++;
+ if(action & CURL_POLL_OUT)
+ entry->writers++;
}
+ else if(!sincebefore) {
+ /* a new user */
+ entry->users++;
+ if(action & CURL_POLL_IN)
+ entry->readers++;
+ if(action & CURL_POLL_OUT)
+ entry->writers++;
+
+ /* add 'data' to the list of handles using this socket! */
+ Curl_llist_insert_next(&entry->list, entry->list.tail,
+ data, &data->sh_queue);
+ }
+
+ comboaction = (entry->writers? CURL_POLL_OUT : 0) |
+ (entry->readers ? CURL_POLL_IN : 0);
+
+#if 0
+ infof(data, "--- Comboaction: %u readers %u writers\n",
+ entry->readers, entry->writers);
+#endif
+ /* check if it has the same action set */
+ if(entry->action == comboaction)
+ /* same, continue */
+ continue;
/* we know (entry != NULL) at this point, see the logic above */
if(multi->socket_cb)
multi->socket_cb(data,
s,
- action,
+ comboaction,
multi->socket_userp,
entry->socketp);
- entry->action = action; /* store the current action state */
+ entry->action = comboaction; /* 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< data->numsocks; i++) {
+ for(i = 0; i< data->numsocks; i++) {
int j;
+ bool stillused = FALSE;
s = data->sockets[i];
- for(j=0; j<num; j++) {
+ for(j = 0; j < num; j++) {
if(s == socks[j]) {
/* this is still supervised */
- s = CURL_SOCKET_BAD;
+ stillused = TRUE;
break;
}
}
+ if(stillused)
+ continue;
entry = sh_getentry(&multi->sockhash, s);
+ /* if this is NULL here, the socket has been closed and notified so
+ already by Curl_multi_closed() */
if(entry) {
- /* this socket has been removed. Tell the app to remove it */
- bool remove_sock_from_hash = TRUE;
-
- /* check if the socket to be removed serves a connection which has
- other easy-s in a pipeline. In this case the socket should not be
- removed. */
- struct connectdata *easy_conn = data->easy_conn;
- if(easy_conn) {
- if(easy_conn->recv_pipe.size > 1) {
- /* the handle should not be removed from the pipe yet */
- remove_sock_from_hash = FALSE;
-
- /* Update the sockhash entry to instead point to the next in line
- for the recv_pipe, or the first (in case this particular easy
- isn't already) */
- if(entry->easy == data) {
- if(Curl_recvpipe_head(data, easy_conn))
- entry->easy = easy_conn->recv_pipe.head->next->ptr;
- else
- entry->easy = easy_conn->recv_pipe.head->ptr;
- }
- }
- if(easy_conn->send_pipe.size > 1) {
- /* the handle should not be removed from the pipe yet */
- remove_sock_from_hash = FALSE;
-
- /* Update the sockhash entry to instead point to the next in line
- for the send_pipe, or the first (in case this particular easy
- isn't already) */
- if(entry->easy == data) {
- if(Curl_sendpipe_head(data, easy_conn))
- entry->easy = easy_conn->send_pipe.head->next->ptr;
- else
- entry->easy = easy_conn->send_pipe.head->ptr;
- }
- }
- /* Don't worry about overwriting recv_pipe head with send_pipe_head,
- when action will be asked on the socket (see multi_socket()), the
- head of the correct pipe will be taken according to the
- action. */
- }
-
- if(remove_sock_from_hash) {
- /* in this case 'entry' is always non-NULL */
+ int oldactions = data->actions[i];
+ /* this socket has been removed. Decrease user count */
+ entry->users--;
+ if(oldactions & CURL_POLL_OUT)
+ entry->writers--;
+ if(oldactions & CURL_POLL_IN)
+ entry->readers--;
+ if(!entry->users) {
if(multi->socket_cb)
- multi->socket_cb(data,
- s,
- CURL_POLL_REMOVE,
+ multi->socket_cb(data, s, CURL_POLL_REMOVE,
multi->socket_userp,
entry->socketp);
sh_delentry(&multi->sockhash, s);
}
- } /* if sockhash entry existed */
+ else {
+ /* remove this transfer as a user of this socket */
+ Curl_llist_remove(&entry->list, &data->sh_queue, NULL);
+ }
+ }
} /* for loop over numsocks */
memcpy(data->sockets, socks, num*sizeof(curl_socket_t));
+ memcpy(data->actions, actions, num*sizeof(int));
data->numsocks = num;
+ return CURLM_OK;
}
+void Curl_updatesocket(struct Curl_easy *data)
+{
+ singlesocket(data->multi, data);
+}
+
+
/*
* Curl_multi_closed()
*
@@ -2452,22 +2366,25 @@ static void singlesocket(struct Curl_multi *multi,
* socket again and it gets the same file descriptor number.
*/
-void Curl_multi_closed(struct connectdata *conn, curl_socket_t s)
+void Curl_multi_closed(struct Curl_easy *data, curl_socket_t s)
{
- struct Curl_multi *multi = conn->data->multi;
- if(multi) {
- /* this is set if this connection is part of a handle that is added to
- a multi handle, and only then this is necessary */
- struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);
-
- if(entry) {
- if(multi->socket_cb)
- multi->socket_cb(conn->data, s, CURL_POLL_REMOVE,
- multi->socket_userp,
- entry->socketp);
+ if(data) {
+ /* if there's still an easy handle associated with this connection */
+ struct Curl_multi *multi = data->multi;
+ if(multi) {
+ /* this is set if this connection is part of a handle that is added to
+ a multi handle, and only then this is necessary */
+ struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);
+
+ if(entry) {
+ if(multi->socket_cb)
+ multi->socket_cb(data, s, CURL_POLL_REMOVE,
+ multi->socket_userp,
+ entry->socketp);
- /* now remove it from the socket hash */
- sh_delentry(&multi->sockhash, s);
+ /* now remove it from the socket hash */
+ sh_delentry(&multi->sockhash, s);
+ }
}
}
}
@@ -2484,11 +2401,11 @@ void Curl_multi_closed(struct connectdata *conn, curl_socket_t s)
* The splay tree only has each sessionhandle as a single node and the nearest
* timeout is used to sort it on.
*/
-static CURLMcode add_next_timeout(struct timeval now,
+static CURLMcode add_next_timeout(struct curltime now,
struct Curl_multi *multi,
struct Curl_easy *d)
{
- struct timeval *tv = &d->state.expiretime;
+ struct curltime *tv = &d->state.expiretime;
struct curl_llist *list = &d->state.timeoutlist;
struct curl_llist_element *e;
struct time_node *node = NULL;
@@ -2498,9 +2415,9 @@ static CURLMcode add_next_timeout(struct timeval now,
timeout in *tv */
for(e = list->head; e;) {
struct curl_llist_element *n = e->next;
- time_t diff;
+ timediff_t diff;
node = (struct time_node *)e->ptr;
- diff = curlx_tvdiff(node->time, now);
+ diff = Curl_timediff(node->time, now);
if(diff <= 0)
/* remove outdated entry */
Curl_llist_remove(list, e, NULL);
@@ -2520,10 +2437,8 @@ static CURLMcode add_next_timeout(struct timeval now,
/* copy the first entry to 'tv' */
memcpy(tv, &node->time, sizeof(*tv));
- /* remove first entry from list */
- Curl_llist_remove(list, e, NULL);
-
- /* insert this node again into the splay */
+ /* Insert this node again into the splay. Keep the timer in the list in
+ case we need to recompute future timers. */
multi->timetree = Curl_splayinsert(*tv, multi->timetree,
&d->state.timenode);
}
@@ -2539,7 +2454,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
CURLMcode result = CURLM_OK;
struct Curl_easy *data = NULL;
struct Curl_tree *t;
- struct timeval now = Curl_tvnow();
+ struct curltime now = Curl_now();
if(checkall) {
/* *perform() deals with running_handles on its own */
@@ -2548,9 +2463,9 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
/* walk through each easy handle and do the socket state change magic
and callbacks */
if(result != CURLM_BAD_HANDLE) {
- data=multi->easyp;
- while(data) {
- singlesocket(multi, data);
+ data = multi->easyp;
+ while(data && !result) {
+ result = singlesocket(multi, data);
data = data->next;
}
}
@@ -2570,44 +2485,38 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
and just move on. */
;
else {
+ struct curl_llist *list = &entry->list;
+ struct curl_llist_element *e;
SIGPIPE_VARIABLE(pipe_st);
- data = entry->easy;
-
- if(data->magic != CURLEASY_MAGIC_NUMBER)
- /* bad bad bad bad bad bad bad */
- return CURLM_INTERNAL_ERROR;
-
- /* If the pipeline is enabled, take the handle which is in the head of
- the pipeline. If we should write into the socket, take the send_pipe
- head. If we should read from the socket, take the recv_pipe head. */
- if(data->easy_conn) {
- if((ev_bitmask & CURL_POLL_OUT) &&
- data->easy_conn->send_pipe.head)
- data = data->easy_conn->send_pipe.head->ptr;
- else if((ev_bitmask & CURL_POLL_IN) &&
- data->easy_conn->recv_pipe.head)
- data = data->easy_conn->recv_pipe.head->ptr;
- }
+ /* the socket can be shared by many transfers, iterate */
+ for(e = list->head; e; e = e->next) {
+ data = (struct Curl_easy *)e->ptr;
- if(data->easy_conn &&
- !(data->easy_conn->handler->flags & PROTOPT_DIRLOCK))
- /* set socket event bitmask if they're not locked */
- data->easy_conn->cselect_bits = ev_bitmask;
+ if(data->magic != CURLEASY_MAGIC_NUMBER)
+ /* bad bad bad bad bad bad bad */
+ return CURLM_INTERNAL_ERROR;
- sigpipe_ignore(data, &pipe_st);
- result = multi_runsingle(multi, now, data);
- sigpipe_restore(&pipe_st);
+ if(data->conn && !(data->conn->handler->flags & PROTOPT_DIRLOCK))
+ /* set socket event bitmask if they're not locked */
+ data->conn->cselect_bits = ev_bitmask;
- if(data->easy_conn &&
- !(data->easy_conn->handler->flags & PROTOPT_DIRLOCK))
- /* clear the bitmask only if not locked */
- data->easy_conn->cselect_bits = 0;
+ sigpipe_ignore(data, &pipe_st);
+ result = multi_runsingle(multi, now, data);
+ sigpipe_restore(&pipe_st);
- if(CURLM_OK >= result)
- /* get the socket(s) and check if the state has been changed since
- last */
- singlesocket(multi, data);
+ if(data->conn && !(data->conn->handler->flags & PROTOPT_DIRLOCK))
+ /* clear the bitmask only if not locked */
+ data->conn->cselect_bits = 0;
+
+ if(CURLM_OK >= result) {
+ /* get the socket(s) and check if the state has been changed since
+ last */
+ result = singlesocket(multi, data);
+ if(result)
+ return result;
+ }
+ }
/* 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
@@ -2615,8 +2524,8 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
data = NULL; /* set data to NULL again to avoid calling
multi_runsingle() in case there's no need to */
- now = Curl_tvnow(); /* get a newer time since the multi_runsingle() loop
- may have taken some time */
+ now = Curl_now(); /* get a newer time since the multi_runsingle() loop
+ may have taken some time */
}
}
else {
@@ -2641,10 +2550,13 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
result = multi_runsingle(multi, now, data);
sigpipe_restore(&pipe_st);
- if(CURLM_OK >= result)
+ if(CURLM_OK >= result) {
/* get the socket(s) and check if the state has been changed since
last */
- singlesocket(multi, data);
+ result = singlesocket(multi, data);
+ if(result)
+ return result;
+ }
}
/* Check if there's one (more) expired timer to deal with! This function
@@ -2672,6 +2584,9 @@ CURLMcode curl_multi_setopt(struct Curl_multi *multi,
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
va_start(param, option);
switch(option) {
@@ -2688,7 +2603,7 @@ CURLMcode curl_multi_setopt(struct Curl_multi *multi,
multi->push_userp = va_arg(param, void *);
break;
case CURLMOPT_PIPELINING:
- multi->pipelining = va_arg(param, long);
+ multi->multiplexing = va_arg(param, long) & CURLPIPE_MULTIPLEX;
break;
case CURLMOPT_TIMERFUNCTION:
multi->timer_cb = va_arg(param, curl_multi_timer_callback);
@@ -2702,25 +2617,19 @@ CURLMcode curl_multi_setopt(struct Curl_multi *multi,
case CURLMOPT_MAX_HOST_CONNECTIONS:
multi->max_host_connections = va_arg(param, long);
break;
+ case CURLMOPT_MAX_TOTAL_CONNECTIONS:
+ multi->max_total_connections = va_arg(param, long);
+ break;
+ /* options formerly used for pipelining */
case CURLMOPT_MAX_PIPELINE_LENGTH:
- multi->max_pipeline_length = va_arg(param, long);
break;
case CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE:
- multi->content_length_penalty_size = va_arg(param, long);
break;
case CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE:
- multi->chunk_length_penalty_size = va_arg(param, long);
break;
case CURLMOPT_PIPELINING_SITE_BL:
- res = Curl_pipeline_set_site_blacklist(va_arg(param, char **),
- &multi->pipelining_site_bl);
break;
case CURLMOPT_PIPELINING_SERVER_BL:
- res = Curl_pipeline_set_server_blacklist(va_arg(param, char **),
- &multi->pipelining_server_bl);
- break;
- case CURLMOPT_MAX_TOTAL_CONNECTIONS:
- multi->max_total_connections = va_arg(param, long);
break;
default:
res = CURLM_UNKNOWN_OPTION;
@@ -2736,7 +2645,10 @@ CURLMcode curl_multi_setopt(struct Curl_multi *multi,
CURLMcode curl_multi_socket(struct Curl_multi *multi, curl_socket_t s,
int *running_handles)
{
- CURLMcode result = multi_socket(multi, FALSE, s, 0, running_handles);
+ CURLMcode result;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+ result = multi_socket(multi, FALSE, s, 0, running_handles);
if(CURLM_OK >= result)
update_timer(multi);
return result;
@@ -2745,8 +2657,10 @@ CURLMcode curl_multi_socket(struct Curl_multi *multi, curl_socket_t s,
CURLMcode curl_multi_socket_action(struct Curl_multi *multi, curl_socket_t s,
int ev_bitmask, int *running_handles)
{
- CURLMcode result = multi_socket(multi, FALSE, s,
- ev_bitmask, running_handles);
+ CURLMcode result;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+ result = multi_socket(multi, FALSE, s, ev_bitmask, running_handles);
if(CURLM_OK >= result)
update_timer(multi);
return result;
@@ -2755,8 +2669,10 @@ CURLMcode curl_multi_socket_action(struct Curl_multi *multi, curl_socket_t s,
CURLMcode curl_multi_socket_all(struct Curl_multi *multi, int *running_handles)
{
- CURLMcode result = multi_socket(multi, TRUE, CURL_SOCKET_BAD, 0,
- running_handles);
+ CURLMcode result;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+ result = multi_socket(multi, TRUE, CURL_SOCKET_BAD, 0, running_handles);
if(CURLM_OK >= result)
update_timer(multi);
return result;
@@ -2765,19 +2681,19 @@ CURLMcode curl_multi_socket_all(struct Curl_multi *multi, int *running_handles)
static CURLMcode multi_timeout(struct Curl_multi *multi,
long *timeout_ms)
{
- static struct timeval tv_zero = {0, 0};
+ static struct curltime tv_zero = {0, 0};
if(multi->timetree) {
/* we have a tree of expire times */
- struct timeval now = Curl_tvnow();
+ struct curltime now = Curl_now();
/* splay the lowest to the bottom */
multi->timetree = Curl_splay(tv_zero, multi->timetree);
if(Curl_splaycomparekeys(multi->timetree->key, now) > 0) {
/* some time left before expiration */
- *timeout_ms = (long)curlx_tvdiff(multi->timetree->key, now);
- if(!*timeout_ms)
+ timediff_t diff = Curl_timediff(multi->timetree->key, now);
+ if(diff <= 0)
/*
* Since we only provide millisecond resolution on the returned value
* and the diff might be less than one millisecond here, we don't
@@ -2785,7 +2701,11 @@ static CURLMcode multi_timeout(struct Curl_multi *multi,
* processors while the diff is still present but less than one
* millisecond! instead we return 1 until the time is ripe.
*/
- *timeout_ms=1;
+ *timeout_ms = 1;
+ else
+ /* this should be safe even on 64 bit archs, as we don't use that
+ overly long timeouts */
+ *timeout_ms = (long)diff;
}
else
/* 0 means immediately */
@@ -2804,6 +2724,9 @@ CURLMcode curl_multi_timeout(struct Curl_multi *multi,
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
return multi_timeout(multi, timeout_ms);
}
@@ -2821,7 +2744,7 @@ static int update_timer(struct Curl_multi *multi)
return -1;
}
if(timeout_ms < 0) {
- static const struct timeval none={0, 0};
+ static const struct curltime none = {0, 0};
if(Curl_splaycomparekeys(none, multi->timer_lastcall)) {
multi->timer_lastcall = none;
/* there's no timeout now but there was one previously, tell the app to
@@ -2872,7 +2795,7 @@ multi_deltimeout(struct Curl_easy *data, expire_id eid)
*/
static CURLMcode
multi_addtimeout(struct Curl_easy *data,
- struct timeval *stamp,
+ struct curltime *stamp,
expire_id eid)
{
struct curl_llist_element *e;
@@ -2892,7 +2815,7 @@ multi_addtimeout(struct Curl_easy *data,
/* find the correct spot in the list */
for(e = timeoutlist->head; e; e = e->next) {
struct time_node *check = (struct time_node *)e->ptr;
- time_t diff = curlx_tvdiff(check->time, node->time);
+ timediff_t diff = Curl_timediff(check->time, node->time);
if(diff > 0)
break;
prev = e;
@@ -2920,9 +2843,8 @@ multi_addtimeout(struct Curl_easy *data,
void Curl_expire(struct Curl_easy *data, time_t milli, expire_id id)
{
struct Curl_multi *multi = data->multi;
- struct timeval *nowp = &data->state.expiretime;
- int rc;
- struct timeval set;
+ struct curltime *nowp = &data->state.expiretime;
+ struct curltime set;
/* this is only interesting while there is still an associated multi struct
remaining! */
@@ -2931,35 +2853,35 @@ void Curl_expire(struct Curl_easy *data, time_t milli, expire_id id)
DEBUGASSERT(id < EXPIRE_LAST);
- set = Curl_tvnow();
- set.tv_sec += (long)(milli/1000);
- set.tv_usec += (long)(milli%1000)*1000;
+ set = Curl_now();
+ set.tv_sec += milli/1000;
+ set.tv_usec += (unsigned int)(milli%1000)*1000;
if(set.tv_usec >= 1000000) {
set.tv_sec++;
set.tv_usec -= 1000000;
}
+ /* Remove any timer with the same id just in case. */
+ multi_deltimeout(data, id);
+
+ /* Add it to the timer list. It must stay in the list until it has expired
+ in case we need to recompute the minimum timer later. */
+ multi_addtimeout(data, &set, id);
+
if(nowp->tv_sec || nowp->tv_usec) {
/* 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. */
- time_t diff = curlx_tvdiff(set, *nowp);
-
- /* remove the previous timer first, if there */
- multi_deltimeout(data, id);
+ timediff_t diff = Curl_timediff(set, *nowp);
+ int rc;
if(diff > 0) {
- /* the new expire time was later so just add it to the queue
- and get out */
- multi_addtimeout(data, &set, id);
+ /* The current splay tree entry is sooner than this new expiry time.
+ We don't need to update our splay tree entry. */
return;
}
- /* the new time is newer than the presently set one, so add the current
- to the queue and update the head */
- multi_addtimeout(data, nowp, id);
-
/* 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,
@@ -2969,6 +2891,8 @@ void Curl_expire(struct Curl_easy *data, time_t milli, expire_id id)
infof(data, "Internal error removing splay node = %d\n", rc);
}
+ /* Indicate that we are in the splay tree and insert the new timer expiry
+ value since it is our local minimum. */
*nowp = set;
data->state.timenode.payload = data;
multi->timetree = Curl_splayinsert(*nowp, multi->timetree,
@@ -2995,8 +2919,7 @@ void Curl_expire_done(struct Curl_easy *data, expire_id id)
void Curl_expire_clear(struct Curl_easy *data)
{
struct Curl_multi *multi = data->multi;
- struct timeval *nowp = &data->state.expiretime;
- int rc;
+ struct curltime *nowp = &data->state.expiretime;
/* this is only interesting while there is still an associated multi struct
remaining! */
@@ -3007,6 +2930,7 @@ void Curl_expire_clear(struct Curl_easy *data)
/* Since this is an cleared time, we must remove the previous entry from
the splay tree */
struct curl_llist *list = &data->state.timeoutlist;
+ int rc;
rc = Curl_splayremovebyaddr(multi->timetree,
&data->state.timenode,
@@ -3020,7 +2944,7 @@ void Curl_expire_clear(struct Curl_easy *data)
}
#ifdef DEBUGBUILD
- infof(data, "Expire cleared\n");
+ infof(data, "Expire cleared (transfer %p)\n", data);
#endif
nowp->tv_sec = 0;
nowp->tv_usec = 0;
@@ -3035,6 +2959,9 @@ CURLMcode curl_multi_assign(struct Curl_multi *multi, curl_socket_t s,
{
struct Curl_sh_entry *there = NULL;
+ if(multi->in_callback)
+ return CURLM_RECURSIVE_API_CALL;
+
there = sh_getentry(&multi->sockhash, s);
if(!there)
@@ -3055,48 +2982,60 @@ size_t Curl_multi_max_total_connections(struct Curl_multi *multi)
return multi ? multi->max_total_connections : 0;
}
-curl_off_t Curl_multi_content_length_penalty_size(struct Curl_multi *multi)
-{
- return multi ? multi->content_length_penalty_size : 0;
-}
-
-curl_off_t Curl_multi_chunk_length_penalty_size(struct Curl_multi *multi)
-{
- return multi ? multi->chunk_length_penalty_size : 0;
-}
+/*
+ * When information about a connection has appeared, call this!
+ */
-struct curl_llist *Curl_multi_pipelining_site_bl(struct Curl_multi *multi)
+void Curl_multiuse_state(struct connectdata *conn,
+ int bundlestate) /* use BUNDLE_* defines */
{
- return &multi->pipelining_site_bl;
-}
+ DEBUGASSERT(conn);
+ DEBUGASSERT(conn->bundle);
+ DEBUGASSERT(conn->data);
+ DEBUGASSERT(conn->data->multi);
-struct curl_llist *Curl_multi_pipelining_server_bl(struct Curl_multi *multi)
-{
- return &multi->pipelining_server_bl;
+ conn->bundle->multiuse = bundlestate;
+ process_pending_handles(conn->data->multi);
}
-void Curl_multi_process_pending_handles(struct Curl_multi *multi)
+static void process_pending_handles(struct Curl_multi *multi)
{
struct curl_llist_element *e = multi->pending.head;
-
- while(e) {
+ if(e) {
struct Curl_easy *data = e->ptr;
- struct curl_llist_element *next = e->next;
- if(data->mstate == CURLM_STATE_CONNECT_PEND) {
- multistate(data, CURLM_STATE_CONNECT);
+ DEBUGASSERT(data->mstate == CURLM_STATE_CONNECT_PEND);
- /* Remove this node from the list */
- Curl_llist_remove(&multi->pending, e, NULL);
+ multistate(data, CURLM_STATE_CONNECT);
- /* Make sure that the handle will be processed soonish. */
- Curl_expire(data, 0, EXPIRE_RUN_NOW);
- }
+ /* Remove this node from the list */
+ Curl_llist_remove(&multi->pending, e, NULL);
+
+ /* Make sure that the handle will be processed soonish. */
+ Curl_expire(data, 0, EXPIRE_RUN_NOW);
+
+ /* mark this as having been in the pending queue */
+ data->state.previouslypending = TRUE;
+ }
+}
- e = next; /* operate on next handle */
+void Curl_set_in_callback(struct Curl_easy *data, bool value)
+{
+ /* might get called when there is no data pointer! */
+ if(data) {
+ if(data->multi_easy)
+ data->multi_easy->in_callback = value;
+ else if(data->multi)
+ data->multi->in_callback = value;
}
}
+bool Curl_is_in_callback(struct Curl_easy *easy)
+{
+ return ((easy->multi && easy->multi->in_callback) ||
+ (easy->multi_easy && easy->multi_easy->in_callback));
+}
+
#ifdef DEBUGBUILD
void Curl_multi_dump(struct Curl_multi *multi)
{
@@ -3104,13 +3043,13 @@ void Curl_multi_dump(struct Curl_multi *multi)
int i;
fprintf(stderr, "* Multi status: %d handles, %d alive\n",
multi->num_easy, multi->num_alive);
- for(data=multi->easyp; data; data = data->next) {
+ for(data = multi->easyp; data; data = data->next) {
if(data->mstate < CURLM_STATE_COMPLETED) {
/* only display handles that are not completed */
fprintf(stderr, "handle %p, state %s, %d sockets\n",
(void *)data,
statename[data->mstate], data->numsocks);
- for(i=0; i < data->numsocks; i++) {
+ for(i = 0; i < data->numsocks; i++) {
curl_socket_t s = data->sockets[i];
struct Curl_sh_entry *entry = sh_getentry(&multi->sockhash, s);
@@ -3120,8 +3059,8 @@ void Curl_multi_dump(struct Curl_multi *multi)
continue;
}
fprintf(stderr, "[%s %s] ",
- entry->action&CURL_POLL_IN?"RECVING":"",
- entry->action&CURL_POLL_OUT?"SENDING":"");
+ (entry->action&CURL_POLL_IN)?"RECVING":"",
+ (entry->action&CURL_POLL_OUT)?"SENDING":"");
}
if(data->numsocks)
fprintf(stderr, "\n");
diff --git a/Utilities/cmcurl/lib/multihandle.h b/Utilities/cmcurl/lib/multihandle.h
index e6ffbf5b6..279379ae0 100644
--- a/Utilities/cmcurl/lib/multihandle.h
+++ b/Utilities/cmcurl/lib/multihandle.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -23,6 +23,7 @@
***************************************************************************/
#include "conncache.h"
+#include "psl.h"
struct Curl_message {
struct curl_llist_element list;
@@ -45,18 +46,16 @@ typedef enum {
CURLM_STATE_SENDPROTOCONNECT, /* 6 - initiate protocol connect procedure */
CURLM_STATE_PROTOCONNECT, /* 7 - completing the protocol-specific connect
phase */
- CURLM_STATE_WAITDO, /* 8 - wait for our turn to send the request */
- CURLM_STATE_DO, /* 9 - start send off the request (part 1) */
- CURLM_STATE_DOING, /* 10 - sending off the request (part 1) */
- CURLM_STATE_DO_MORE, /* 11 - send off the request (part 2) */
- CURLM_STATE_DO_DONE, /* 12 - done sending off request */
- CURLM_STATE_WAITPERFORM, /* 13 - wait for our turn to read the response */
- CURLM_STATE_PERFORM, /* 14 - transfer data */
- CURLM_STATE_TOOFAST, /* 15 - wait because limit-rate exceeded */
- CURLM_STATE_DONE, /* 16 - post data transfer operation */
- CURLM_STATE_COMPLETED, /* 17 - operation complete */
- CURLM_STATE_MSGSENT, /* 18 - the operation complete message is sent */
- CURLM_STATE_LAST /* 19 - not a true state, never use this */
+ CURLM_STATE_DO, /* 8 - start send off the request (part 1) */
+ CURLM_STATE_DOING, /* 9 - sending off the request (part 1) */
+ CURLM_STATE_DO_MORE, /* 10 - send off the request (part 2) */
+ CURLM_STATE_DO_DONE, /* 11 - done sending off request */
+ CURLM_STATE_PERFORM, /* 12 - transfer data */
+ CURLM_STATE_TOOFAST, /* 13 - wait because limit-rate exceeded */
+ CURLM_STATE_DONE, /* 14 - post data transfer operation */
+ CURLM_STATE_COMPLETED, /* 15 - operation complete */
+ CURLM_STATE_MSGSENT, /* 16 - the operation complete message is sent */
+ CURLM_STATE_LAST /* 17 - not a true state, never use this */
} CURLMstate;
/* we support N sockets per easy handle. Set the corresponding bit to what
@@ -65,7 +64,7 @@ typedef enum {
#define GETSOCK_READABLE (0x00ff)
#define GETSOCK_WRITABLE (0xff00)
-#define CURLPIPE_ANY (CURLPIPE_HTTP1 | CURLPIPE_MULTIPLEX)
+#define CURLPIPE_ANY (CURLPIPE_MULTIPLEX)
/* This is the struct known as CURLM on the outside */
struct Curl_multi {
@@ -97,6 +96,11 @@ struct Curl_multi {
/* Hostname cache */
struct curl_hash hostcache;
+#ifdef USE_LIBPSL
+ /* PSL cache. */
+ struct PslCache psl;
+#endif
+
/* timetree points to the splay-tree of time nodes to figure out expire
times of all currently set timers */
struct Curl_tree *timetree;
@@ -106,18 +110,14 @@ struct Curl_multi {
same actual socket) */
struct curl_hash sockhash;
- /* pipelining wanted bits (CURLPIPE*) */
- long pipelining;
+ /* multiplexing wanted */
+ bool multiplexing;
bool recheckstate; /* see Curl_multi_connchanged */
/* Shared connection cache (bundles)*/
struct conncache conn_cache;
- /* This handle will be used for closing the cached connections in
- curl_multi_cleanup() */
- struct Curl_easy *closure_handle;
-
long maxconnects; /* if >0, a fixed limit of the maximum number of entries
we're allowed to grow the connection cache to */
@@ -127,29 +127,12 @@ struct Curl_multi {
long max_total_connections; /* if >0, a fixed limit of the maximum number
of connections in total */
- long max_pipeline_length; /* if >0, maximum number of requests in a
- pipeline */
-
- long content_length_penalty_size; /* a connection with a
- content-length bigger than
- this is not considered
- for pipelining */
-
- long chunk_length_penalty_size; /* a connection with a chunk length
- bigger than this is not
- considered for pipelining */
-
- struct curl_llist pipelining_site_bl; /* List of sites that are blacklisted
- from pipelining */
-
- struct curl_llist pipelining_server_bl; /* List of server types that are
- blacklisted from pipelining */
-
/* timer callback and user data pointer for the *socket() API */
curl_multi_timer_callback timer_cb;
void *timer_userp;
- struct timeval timer_lastcall; /* the fixed time for the timeout for the
+ struct curltime timer_lastcall; /* the fixed time for the timeout for the
previous callback */
+ bool in_callback; /* true while executing a callback */
};
#endif /* HEADER_CURL_MULTIHANDLE_H */
diff --git a/Utilities/cmcurl/lib/multiif.h b/Utilities/cmcurl/lib/multiif.h
index a877571a0..e8a5e7062 100644
--- a/Utilities/cmcurl/lib/multiif.h
+++ b/Utilities/cmcurl/lib/multiif.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -26,11 +26,16 @@
* Prototypes for library-wide functions provided by multi.c
*/
+void Curl_updatesocket(struct Curl_easy *data);
void Curl_expire(struct Curl_easy *data, time_t milli, expire_id);
void Curl_expire_clear(struct Curl_easy *data);
void Curl_expire_done(struct Curl_easy *data, expire_id id);
-bool Curl_pipeline_wanted(const struct Curl_multi* multi, int bits);
-void Curl_multi_handlePipeBreak(struct Curl_easy *data);
+void Curl_detach_connnection(struct Curl_easy *data);
+void Curl_attach_connnection(struct Curl_easy *data,
+ struct connectdata *conn);
+bool Curl_multiplex_wanted(const struct Curl_multi *multi);
+void Curl_set_in_callback(struct Curl_easy *data, bool value);
+bool Curl_is_in_callback(struct Curl_easy *easy);
/* Internal version of curl_multi_init() accepts size parameters for the
socket and connection hashes */
@@ -56,27 +61,14 @@ struct Curl_multi *Curl_multi_handle(int hashsize, int chashsize);
void Curl_multi_dump(struct Curl_multi *multi);
#endif
-void Curl_multi_process_pending_handles(struct Curl_multi *multi);
-
/* Return the value of the CURLMOPT_MAX_HOST_CONNECTIONS option */
size_t Curl_multi_max_host_connections(struct Curl_multi *multi);
-/* Return the value of the CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE option */
-curl_off_t Curl_multi_content_length_penalty_size(struct Curl_multi *multi);
-
-/* Return the value of the CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE option */
-curl_off_t Curl_multi_chunk_length_penalty_size(struct Curl_multi *multi);
-
-/* Return the value of the CURLMOPT_PIPELINING_SITE_BL option */
-struct curl_llist *Curl_multi_pipelining_site_bl(struct Curl_multi *multi);
-
-/* Return the value of the CURLMOPT_PIPELINING_SERVER_BL option */
-struct curl_llist *Curl_multi_pipelining_server_bl(struct Curl_multi *multi);
-
/* Return the value of the CURLMOPT_MAX_TOTAL_CONNECTIONS option */
size_t Curl_multi_max_total_connections(struct Curl_multi *multi);
-void Curl_multi_connchanged(struct Curl_multi *multi);
+void Curl_multiuse_state(struct connectdata *conn,
+ int bundlestate); /* use BUNDLE_* defines */
/*
* Curl_multi_closed()
@@ -88,7 +80,7 @@ void Curl_multi_connchanged(struct Curl_multi *multi);
* socket again and it gets the same file descriptor number.
*/
-void Curl_multi_closed(struct connectdata *conn, curl_socket_t s);
+void Curl_multi_closed(struct Curl_easy *data, curl_socket_t s);
/*
* Add a handle and move it into PERFORM state at once. For pushed streams.
@@ -96,4 +88,12 @@ void Curl_multi_closed(struct connectdata *conn, curl_socket_t s);
CURLMcode Curl_multi_add_perform(struct Curl_multi *multi,
struct Curl_easy *data,
struct connectdata *conn);
+
+CURLMcode Curl_multi_wait(struct Curl_multi *multi,
+ struct curl_waitfd extra_fds[],
+ unsigned int extra_nfds,
+ int timeout_ms,
+ int *ret,
+ bool *gotsocket); /* if any socket was checked */
+
#endif /* HEADER_CURL_MULTIIF_H */
diff --git a/Utilities/cmcurl/lib/netrc.c b/Utilities/cmcurl/lib/netrc.c
index 996711d11..1bd998f9c 100644
--- a/Utilities/cmcurl/lib/netrc.c
+++ b/Utilities/cmcurl/lib/netrc.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -21,6 +21,7 @@
***************************************************************************/
#include "curl_setup.h"
+#ifndef CURL_DISABLE_NETRC
#ifdef HAVE_PWD_H
#include <pwd.h>
@@ -53,17 +54,24 @@ enum host_lookup_state {
int Curl_parsenetrc(const char *host,
char **loginp,
char **passwordp,
+ bool *login_changed,
+ bool *password_changed,
char *netrcfile)
{
FILE *file;
- int retcode=1;
- int specific_login = (*loginp && **loginp != 0);
+ int retcode = 1;
+ char *login = *loginp;
+ char *password = *passwordp;
+ bool specific_login = (login && *login != 0);
+ bool login_alloc = FALSE;
+ bool password_alloc = FALSE;
bool netrc_alloc = FALSE;
- enum host_lookup_state state=NOTHING;
+ enum host_lookup_state 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 */
+ 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"
@@ -88,7 +96,7 @@ int Curl_parsenetrc(const char *host,
}
else {
struct passwd *pw;
- pw= getpwuid(geteuid());
+ pw = getpwuid(geteuid());
if(pw) {
home = pw->pw_dir;
}
@@ -113,16 +121,19 @@ int Curl_parsenetrc(const char *host,
if(file) {
char *tok;
char *tok_buf;
- bool done=FALSE;
- char netrcbuffer[256];
+ bool done = FALSE;
+ char netrcbuffer[4096];
int netrcbuffsize = (int)sizeof(netrcbuffer);
while(!done && fgets(netrcbuffer, netrcbuffsize, file)) {
- tok=strtok_r(netrcbuffer, " \t\n", &tok_buf);
+ tok = strtok_r(netrcbuffer, " \t\n", &tok_buf);
+ if(tok && *tok == '#')
+ /* treat an initial hash as a comment line */
+ continue;
while(!done && tok) {
- if((*loginp && **loginp) && (*passwordp && **passwordp)) {
- done=TRUE;
+ if((login && *login) && (password && *password)) {
+ done = TRUE;
break;
}
@@ -133,54 +144,63 @@ int Curl_parsenetrc(const char *host,
delimiter that starts the stuff entered for this machine,
after this we need to search for 'login' and
'password'. */
- state=HOSTFOUND;
+ state = HOSTFOUND;
}
else if(strcasecompare("default", tok)) {
- state=HOSTVALID;
- retcode=0; /* we did find our host */
+ state = HOSTVALID;
+ retcode = 0; /* we did find our host */
}
break;
case HOSTFOUND:
if(strcasecompare(host, tok)) {
/* and yes, this is our host! */
- state=HOSTVALID;
- retcode=0; /* we did find our host */
+ state = HOSTVALID;
+ retcode = 0; /* we did find our host */
}
else
/* not our host */
- state=NOTHING;
+ state = NOTHING;
break;
case HOSTVALID:
/* we are now parsing sub-keywords concerning "our" host */
if(state_login) {
if(specific_login) {
- state_our_login = strcasecompare(*loginp, tok);
+ state_our_login = strcasecompare(login, tok);
}
- else {
- free(*loginp);
- *loginp = strdup(tok);
- if(!*loginp) {
+ else if(!login || strcmp(login, tok)) {
+ if(login_alloc) {
+ free(login);
+ login_alloc = FALSE;
+ }
+ login = strdup(tok);
+ if(!login) {
retcode = -1; /* allocation failed */
goto out;
}
+ login_alloc = TRUE;
}
- state_login=0;
+ state_login = 0;
}
else if(state_password) {
- if(state_our_login || !specific_login) {
- free(*passwordp);
- *passwordp = strdup(tok);
- if(!*passwordp) {
+ if((state_our_login || !specific_login)
+ && (!password || strcmp(password, tok))) {
+ if(password_alloc) {
+ free(password);
+ password_alloc = FALSE;
+ }
+ password = strdup(tok);
+ if(!password) {
retcode = -1; /* allocation failed */
goto out;
}
+ password_alloc = TRUE;
}
- state_password=0;
+ state_password = 0;
}
else if(strcasecompare("login", tok))
- state_login=1;
+ state_login = 1;
else if(strcasecompare("password", tok))
- state_password=1;
+ state_password = 1;
else if(strcasecompare("machine", tok)) {
/* ok, there's machine here go => */
state = HOSTFOUND;
@@ -194,8 +214,32 @@ int Curl_parsenetrc(const char *host,
} /* while fgets() */
out:
+ if(!retcode) {
+ *login_changed = FALSE;
+ *password_changed = FALSE;
+ if(login_alloc) {
+ if(*loginp)
+ free(*loginp);
+ *loginp = login;
+ *login_changed = TRUE;
+ }
+ if(password_alloc) {
+ if(*passwordp)
+ free(*passwordp);
+ *passwordp = password;
+ *password_changed = TRUE;
+ }
+ }
+ else {
+ if(login_alloc)
+ free(login);
+ if(password_alloc)
+ free(password);
+ }
fclose(file);
}
return retcode;
}
+
+#endif
diff --git a/Utilities/cmcurl/lib/netrc.h b/Utilities/cmcurl/lib/netrc.h
index d980166e6..7f56c4b4d 100644
--- a/Utilities/cmcurl/lib/netrc.h
+++ b/Utilities/cmcurl/lib/netrc.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,15 +22,24 @@
*
***************************************************************************/
+#include "curl_setup.h"
+#ifndef CURL_DISABLE_NETRC
+
/* returns -1 on failure, 0 if the host is found, 1 is the host isn't found */
int Curl_parsenetrc(const char *host,
char **loginp,
char **passwordp,
+ bool *login_changed,
+ bool *password_changed,
char *filename);
/* Assume: (*passwordp)[0]=0, host[0] != 0.
* If (*loginp)[0] = 0, search for login and password within a machine
* section in the netrc.
* If (*loginp)[0] != 0, search for password within machine and login.
*/
+#else
+/* disabled */
+#define Curl_parsenetrc(a,b,c,d,e,f) 1
+#endif
#endif /* HEADER_CURL_NETRC_H */
diff --git a/Utilities/cmcurl/lib/non-ascii.c b/Utilities/cmcurl/lib/non-ascii.c
index 2f5de4c68..42beaec45 100644
--- a/Utilities/cmcurl/lib/non-ascii.c
+++ b/Utilities/cmcurl/lib/non-ascii.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -30,6 +30,7 @@
#include "formdata.h"
#include "sendf.h"
#include "urldata.h"
+#include "multiif.h"
#include "curl_memory.h"
/* The last #include file should be: */
@@ -77,14 +78,17 @@ CURLcode Curl_convert_clone(struct Curl_easy *data,
/*
* Curl_convert_to_network() is an internal function for performing ASCII
- * conversions on non-ASCII platforms. It convers the buffer _in place_.
+ * conversions on non-ASCII platforms. It converts the buffer _in place_.
*/
CURLcode Curl_convert_to_network(struct Curl_easy *data,
char *buffer, size_t length)
{
- if(data->set.convtonetwork) {
+ if(data && data->set.convtonetwork) {
/* use translation callback */
- CURLcode result = data->set.convtonetwork(buffer, length);
+ CURLcode result;
+ Curl_set_in_callback(data, true);
+ result = data->set.convtonetwork(buffer, length);
+ Curl_set_in_callback(data, false);
if(result) {
failf(data,
"CURLOPT_CONV_TO_NETWORK_FUNCTION callback returned %d: %s",
@@ -96,34 +100,37 @@ CURLcode Curl_convert_to_network(struct Curl_easy *data,
else {
#ifdef HAVE_ICONV
/* do the translation ourselves */
+ iconv_t tmpcd = (iconv_t) -1;
+ iconv_t *cd = &tmpcd;
char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc;
- int error;
/* 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) {
- error = ERRNO;
+ if(data)
+ cd = &data->outbound_cd;
+ if(*cd == (iconv_t)-1) {
+ *cd = iconv_open(CURL_ICONV_CODESET_OF_NETWORK,
+ CURL_ICONV_CODESET_OF_HOST);
+ if(*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,
- error, strerror(error));
+ 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,
+ rc = iconv(*cd, &input_ptr, &in_bytes,
&output_ptr, &out_bytes);
+ if(!data)
+ iconv_close(tmpcd);
if((rc == ICONV_ERROR) || (in_bytes != 0)) {
- error = ERRNO;
failf(data,
"The Curl_convert_to_network iconv call failed with errno %i: %s",
- error, strerror(error));
+ errno, strerror(errno));
return CURLE_CONV_FAILED;
}
#else
@@ -137,14 +144,17 @@ CURLcode Curl_convert_to_network(struct Curl_easy *data,
/*
* Curl_convert_from_network() is an internal function for performing ASCII
- * conversions on non-ASCII platforms. It convers the buffer _in place_.
+ * conversions on non-ASCII platforms. It converts the buffer _in place_.
*/
CURLcode Curl_convert_from_network(struct Curl_easy *data,
char *buffer, size_t length)
{
- if(data->set.convfromnetwork) {
+ if(data && data->set.convfromnetwork) {
/* use translation callback */
- CURLcode result = data->set.convfromnetwork(buffer, length);
+ CURLcode result;
+ Curl_set_in_callback(data, true);
+ result = data->set.convfromnetwork(buffer, length);
+ Curl_set_in_callback(data, false);
if(result) {
failf(data,
"CURLOPT_CONV_FROM_NETWORK_FUNCTION callback returned %d: %s",
@@ -156,34 +166,37 @@ CURLcode Curl_convert_from_network(struct Curl_easy *data,
else {
#ifdef HAVE_ICONV
/* do the translation ourselves */
+ iconv_t tmpcd = (iconv_t) -1;
+ iconv_t *cd = &tmpcd;
char *input_ptr, *output_ptr;
size_t in_bytes, out_bytes, rc;
- int error;
/* 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) {
- error = ERRNO;
+ if(data)
+ cd = &data->inbound_cd;
+ if(*cd == (iconv_t)-1) {
+ *cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_OF_NETWORK);
+ if(*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,
- error, strerror(error));
+ 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,
+ rc = iconv(*cd, &input_ptr, &in_bytes,
&output_ptr, &out_bytes);
+ if(!data)
+ iconv_close(tmpcd);
if((rc == ICONV_ERROR) || (in_bytes != 0)) {
- error = ERRNO;
failf(data,
"Curl_convert_from_network iconv call failed with errno %i: %s",
- error, strerror(error));
+ errno, strerror(errno));
return CURLE_CONV_FAILED;
}
#else
@@ -202,9 +215,12 @@ CURLcode Curl_convert_from_network(struct Curl_easy *data,
CURLcode Curl_convert_from_utf8(struct Curl_easy *data,
char *buffer, size_t length)
{
- if(data->set.convfromutf8) {
+ if(data && data->set.convfromutf8) {
/* use translation callback */
- CURLcode result = data->set.convfromutf8(buffer, length);
+ CURLcode result;
+ Curl_set_in_callback(data, true);
+ result = data->set.convfromutf8(buffer, length);
+ Curl_set_in_callback(data, false);
if(result) {
failf(data,
"CURLOPT_CONV_FROM_UTF8_FUNCTION callback returned %d: %s",
@@ -216,35 +232,38 @@ CURLcode Curl_convert_from_utf8(struct Curl_easy *data,
else {
#ifdef HAVE_ICONV
/* do the translation ourselves */
- const char *input_ptr;
+ iconv_t tmpcd = (iconv_t) -1;
+ iconv_t *cd = &tmpcd;
+ char *input_ptr;
char *output_ptr;
size_t in_bytes, out_bytes, rc;
- int error;
/* 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) {
- error = ERRNO;
+ if(data)
+ cd = &data->utf8_cd;
+ if(*cd == (iconv_t)-1) {
+ *cd = iconv_open(CURL_ICONV_CODESET_OF_HOST,
+ CURL_ICONV_CODESET_FOR_UTF8);
+ if(*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,
- error, strerror(error));
+ errno, strerror(errno));
return CURLE_CONV_FAILED;
}
}
/* call iconv */
input_ptr = output_ptr = buffer;
in_bytes = out_bytes = length;
- rc = iconv(data->utf8_cd, &input_ptr, &in_bytes,
+ rc = iconv(*cd, &input_ptr, &in_bytes,
&output_ptr, &out_bytes);
+ if(!data)
+ iconv_close(tmpcd);
if((rc == ICONV_ERROR) || (in_bytes != 0)) {
- error = ERRNO;
failf(data,
"The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
- error, strerror(error));
+ errno, strerror(errno));
return CURLE_CONV_FAILED;
}
if(output_ptr < input_ptr) {
@@ -310,29 +329,4 @@ void Curl_convert_close(struct Curl_easy *data)
#endif /* HAVE_ICONV */
}
-/*
- * Curl_convert_form() 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_convert_form(struct Curl_easy *data, struct FormData *form)
-{
- CURLcode result;
-
- if(!data)
- return CURLE_BAD_FUNCTION_ARGUMENT;
-
- while(form) {
- if(form->type == FORM_DATA) {
- result = Curl_convert_to_network(data, form->line, form->length);
- /* Curl_convert_to_network calls failf if unsuccessful */
- if(result)
- return result;
- }
-
- form = form->next;
- }
-
- return CURLE_OK;
-}
-
#endif /* CURL_DOES_CONVERSIONS */
diff --git a/Utilities/cmcurl/lib/non-ascii.h b/Utilities/cmcurl/lib/non-ascii.h
index e27f1f41f..5fb5771e0 100644
--- a/Utilities/cmcurl/lib/non-ascii.h
+++ b/Utilities/cmcurl/lib/non-ascii.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -48,7 +48,6 @@ CURLcode Curl_convert_from_network(struct Curl_easy *data,
char *buffer, size_t length);
CURLcode Curl_convert_from_utf8(struct Curl_easy *data,
char *buffer, size_t length);
-CURLcode Curl_convert_form(struct Curl_easy *data, struct FormData *form);
#else
#define Curl_convert_clone(a,b,c,d) ((void)a, CURLE_OK)
#define Curl_convert_init(x) Curl_nop_stmt
@@ -57,7 +56,6 @@ CURLcode Curl_convert_form(struct Curl_easy *data, struct FormData *form);
#define Curl_convert_to_network(a,b,c) ((void)a, CURLE_OK)
#define Curl_convert_from_network(a,b,c) ((void)a, CURLE_OK)
#define Curl_convert_from_utf8(a,b,c) ((void)a, CURLE_OK)
-#define Curl_convert_form(a,b) CURLE_OK
#endif
#endif /* HEADER_CURL_NON_ASCII_H */
diff --git a/Utilities/cmcurl/lib/nonblock.c b/Utilities/cmcurl/lib/nonblock.c
index 5959281e5..4d105c1fe 100644
--- a/Utilities/cmcurl/lib/nonblock.c
+++ b/Utilities/cmcurl/lib/nonblock.c
@@ -48,7 +48,8 @@ int curlx_nonblock(curl_socket_t sockfd, /* operate on this */
int nonblock /* TRUE or FALSE */)
{
#if defined(USE_BLOCKING_SOCKETS)
-
+ (void)sockfd;
+ (void)nonblock;
return 0; /* returns success */
#elif defined(HAVE_FCNTL_O_NONBLOCK)
diff --git a/Utilities/cmcurl/lib/nonblock.h b/Utilities/cmcurl/lib/nonblock.h
index 98cdc25ab..eb18ea1c3 100644
--- a/Utilities/cmcurl/lib/nonblock.h
+++ b/Utilities/cmcurl/lib/nonblock.h
@@ -28,4 +28,3 @@ int curlx_nonblock(curl_socket_t sockfd, /* operate on this */
int nonblock /* TRUE or FALSE */);
#endif /* HEADER_CURL_NONBLOCK_H */
-
diff --git a/Utilities/cmcurl/lib/nwlib.c b/Utilities/cmcurl/lib/nwlib.c
index 290cbe31f..7bf5f51c3 100644
--- a/Utilities/cmcurl/lib/nwlib.c
+++ b/Utilities/cmcurl/lib/nwlib.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -186,18 +186,16 @@ int GetOrSetUpData(int id, libdata_t **appData,
app_data = (libdata_t *) get_app_data(id);
if(!app_data) {
- app_data = malloc(sizeof(libdata_t));
+ app_data = calloc(1, 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->tenbytes);
free(app_data);
app_data = (libdata_t *) NULL;
err = ENOMEM;
@@ -215,6 +213,9 @@ int GetOrSetUpData(int id, libdata_t **appData,
err = set_app_data(gLibId, app_data);
if(err) {
+ if(app_data->lock)
+ NXMutexFree(app_data->lock);
+ free(app_data->tenbytes);
free(app_data);
app_data = (libdata_t *) NULL;
err = ENOMEM;
diff --git a/Utilities/cmcurl/lib/openldap.c b/Utilities/cmcurl/lib/openldap.c
index 4b8cfb9c2..eeab2c7a7 100644
--- a/Utilities/cmcurl/lib/openldap.c
+++ b/Utilities/cmcurl/lib/openldap.c
@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2010, Howard Chu, <hyc@openldap.org>
- * Copyright (C) 2011 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2011 - 2019, 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
@@ -51,6 +51,25 @@
#include "curl_memory.h"
#include "memdebug.h"
+/*
+ * Uncommenting this will enable the built-in debug logging of the openldap
+ * library. The debug log level can be set using the CURL_OPENLDAP_TRACE
+ * environment variable. The debug output is written to stderr.
+ *
+ * The library supports the following debug flags:
+ * LDAP_DEBUG_NONE 0x0000
+ * LDAP_DEBUG_TRACE 0x0001
+ * LDAP_DEBUG_CONSTRUCT 0x0002
+ * LDAP_DEBUG_DESTROY 0x0004
+ * LDAP_DEBUG_PARAMETER 0x0008
+ * LDAP_DEBUG_ANY 0xffff
+ *
+ * For example, use CURL_OPENLDAP_TRACE=0 for no debug,
+ * CURL_OPENLDAP_TRACE=2 for LDAP_DEBUG_CONSTRUCT messages only,
+ * CURL_OPENLDAP_TRACE=65535 for all debug message levels.
+ */
+/* #define CURL_OPENLDAP_DEBUG */
+
#ifndef _LDAP_PVT_H
extern int ldap_pvt_url_scheme2proto(const char *);
extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url,
@@ -85,6 +104,7 @@ const struct Curl_handler Curl_handler_ldap = {
ZERO_NULL, /* perform_getsock */
ldap_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_LDAP, /* defport */
CURLPROTO_LDAP, /* protocol */
PROTOPT_NONE /* flags */
@@ -110,6 +130,7 @@ const struct Curl_handler Curl_handler_ldaps = {
ZERO_NULL, /* perform_getsock */
ldap_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_LDAPS, /* defport */
CURLPROTO_LDAP, /* protocol */
PROTOPT_SSL /* flags */
@@ -150,7 +171,7 @@ static CURLcode ldap_setup_connection(struct connectdata *conn)
{
ldapconninfo *li;
LDAPURLDesc *lud;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
int rc, proto;
CURLcode status;
@@ -175,9 +196,6 @@ static CURLcode ldap_setup_connection(struct connectdata *conn)
li->proto = proto;
conn->proto.generic = li;
connkeep(conn, "OpenLDAP default");
- /* TODO:
- * - provide option to choose SASL Binds instead of Simple
- */
return CURLE_OK;
}
@@ -196,11 +214,20 @@ static CURLcode ldap_connect(struct connectdata *conn, bool *done)
(void)done;
strcpy(hosturl, "ldap");
- ptr = hosturl+4;
+ ptr = hosturl + 4;
if(conn->handler->flags & PROTOPT_SSL)
*ptr++ = 's';
- snprintf(ptr, sizeof(hosturl)-(ptr-hosturl), "://%s:%d",
- conn->host.name, conn->remote_port);
+ msnprintf(ptr, sizeof(hosturl)-(ptr-hosturl), "://%s:%d",
+ conn->host.name, conn->remote_port);
+
+#ifdef CURL_OPENLDAP_DEBUG
+ static int do_trace = 0;
+ const char *env = getenv("CURL_OPENLDAP_TRACE");
+ do_trace = (env && strtol(env, NULL, 10) > 0);
+ if(do_trace) {
+ ldap_set_option(li->ld, LDAP_OPT_DEBUG_LEVEL, &do_trace);
+ }
+#endif
rc = ldap_init_fd(conn->sock[FIRSTSOCKET], li->proto, hosturl, &li->ld);
if(rc) {
@@ -256,7 +283,7 @@ static CURLcode ldap_connecting(struct connectdata *conn, bool *done)
tvp = &tv;
-retry:
+ retry:
if(!li->didbind) {
char *binddn;
struct berval passwd;
@@ -352,7 +379,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done)
int rc = 0;
LDAPURLDesc *ludp = NULL;
int msgid;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
connkeep(conn, "OpenLDAP do");
@@ -384,7 +411,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done)
return CURLE_OUT_OF_MEMORY;
lr->msgid = msgid;
data->req.protop = lr;
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
*done = TRUE;
return CURLE_OK;
}
@@ -442,8 +469,8 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
return ret;
for(ent = ldap_first_message(li->ld, msg); ent;
- ent = ldap_next_message(li->ld, ent)) {
- struct berval bv, *bvals, **bvp = &bvals;
+ ent = ldap_next_message(li->ld, ent)) {
+ struct berval bv, *bvals;
int binary = 0, msgtype;
CURLcode writeerr;
@@ -480,8 +507,6 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
lr->nument++;
rc = ldap_get_dn_ber(li->ld, ent, &ber, &bv);
if(rc < 0) {
- /* TODO: verify that this is really how this return code should be
- handled */
*err = CURLE_RECV_ERROR;
return -1;
}
@@ -505,19 +530,41 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
}
data->req.bytecount += bv.bv_len + 5;
- for(rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp);
- rc == LDAP_SUCCESS;
- rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp)) {
+ for(rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, &bvals);
+ rc == LDAP_SUCCESS;
+ rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, &bvals)) {
int i;
- if(bv.bv_val == NULL) break;
+ if(bv.bv_val == NULL)
+ break;
if(bv.bv_len > 7 && !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7))
binary = 1;
else
binary = 0;
- for(i=0; bvals[i].bv_val != NULL; i++) {
+ if(bvals == NULL) {
+ writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\t", 1);
+ if(writeerr) {
+ *err = writeerr;
+ return -1;
+ }
+ writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)bv.bv_val,
+ bv.bv_len);
+ if(writeerr) {
+ *err = writeerr;
+ return -1;
+ }
+ writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)":\n", 2);
+ if(writeerr) {
+ *err = writeerr;
+ return -1;
+ }
+ data->req.bytecount += bv.bv_len + 3;
+ continue;
+ }
+
+ for(i = 0; bvals[i].bv_val != NULL; i++) {
int binval = 0;
writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\t", 1);
if(writeerr) {
@@ -525,29 +572,29 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
return -1;
}
- writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)bv.bv_val,
- bv.bv_len);
- if(writeerr) {
- *err = writeerr;
- return -1;
- }
+ writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)bv.bv_val,
+ bv.bv_len);
+ if(writeerr) {
+ *err = writeerr;
+ return -1;
+ }
writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)":", 1);
- if(writeerr) {
- *err = writeerr;
- return -1;
- }
+ if(writeerr) {
+ *err = writeerr;
+ return -1;
+ }
data->req.bytecount += bv.bv_len + 2;
if(!binary) {
/* check for leading or trailing whitespace */
if(ISSPACE(bvals[i].bv_val[0]) ||
- ISSPACE(bvals[i].bv_val[bvals[i].bv_len-1]))
+ ISSPACE(bvals[i].bv_val[bvals[i].bv_len-1]))
binval = 1;
else {
/* check for unprintable characters */
unsigned int j;
- for(j=0; j<bvals[i].bv_len; j++)
+ for(j = 0; j<bvals[i].bv_len; j++)
if(!ISPRINT(bvals[i].bv_val[j])) {
binval = 1;
break;
@@ -580,7 +627,7 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
data->req.bytecount += 2;
if(val_b64_sz > 0) {
writeerr = Curl_client_write(conn, CLIENTWRITE_BODY, val_b64,
- val_b64_sz);
+ val_b64_sz);
if(writeerr) {
*err = writeerr;
return -1;
@@ -675,7 +722,7 @@ ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
ber_slen_t ret;
CURLcode err = CURLE_RECV_ERROR;
- ret = li->recv(conn, FIRSTSOCKET, buf, len, &err);
+ ret = (li->recv)(conn, FIRSTSOCKET, buf, len, &err);
if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK);
}
@@ -690,7 +737,7 @@ ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
ber_slen_t ret;
CURLcode err = CURLE_SEND_ERROR;
- ret = li->send(conn, FIRSTSOCKET, buf, len, &err);
+ ret = (li->send)(conn, FIRSTSOCKET, buf, len, &err);
if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK);
}
diff --git a/Utilities/cmcurl/lib/parsedate.c b/Utilities/cmcurl/lib/parsedate.c
index 3c783be48..7ae5eb8cd 100644
--- a/Utilities/cmcurl/lib/parsedate.c
+++ b/Utilities/cmcurl/lib/parsedate.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -75,29 +75,13 @@
#include "curl_setup.h"
-#ifdef HAVE_LIMITS_H
#include <limits.h>
-#endif
#include <curl/curl.h>
#include "strcase.h"
#include "warnless.h"
#include "parsedate.h"
-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 {
- char name[5];
- int offset; /* +/- in minutes */
-};
-
/*
* parsedate()
*
@@ -116,11 +100,28 @@ static int parsedate(const char *date, time_t *output);
#define PARSEDATE_LATER 1
#define PARSEDATE_SOONER 2
+#ifndef CURL_DISABLE_PARSEDATE
+
+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 {
+ char name[5];
+ 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 */
+ {"UT", 0}, /* Universal Time */
{"UTC", 0}, /* Universal (Coordinated) */
{"WET", 0}, /* Western European */
{"BST", 0 tDAYZONE}, /* British Summer */
@@ -167,20 +168,20 @@ static const struct tzinfo tz[]= {
RFC 1123) had their signs wrong. Here we use the correct signs to match
actual military usage.
*/
- {"A", +1 * 60}, /* Alpha */
- {"B", +2 * 60}, /* Bravo */
- {"C", +3 * 60}, /* Charlie */
- {"D", +4 * 60}, /* Delta */
- {"E", +5 * 60}, /* Echo */
- {"F", +6 * 60}, /* Foxtrot */
- {"G", +7 * 60}, /* Golf */
- {"H", +8 * 60}, /* Hotel */
- {"I", +9 * 60}, /* India */
+ {"A", 1 * 60}, /* Alpha */
+ {"B", 2 * 60}, /* Bravo */
+ {"C", 3 * 60}, /* Charlie */
+ {"D", 4 * 60}, /* Delta */
+ {"E", 5 * 60}, /* Echo */
+ {"F", 6 * 60}, /* Foxtrot */
+ {"G", 7 * 60}, /* Golf */
+ {"H", 8 * 60}, /* Hotel */
+ {"I", 9 * 60}, /* India */
/* "J", Juliet is not used as a timezone, to indicate the observer's local
time */
- {"K", +10 * 60}, /* Kilo */
- {"L", +11 * 60}, /* Lima */
- {"M", +12 * 60}, /* Mike */
+ {"K", 10 * 60}, /* Kilo */
+ {"L", 11 * 60}, /* Lima */
+ {"M", 12 * 60}, /* Mike */
{"N", -1 * 60}, /* November */
{"O", -2 * 60}, /* Oscar */
{"P", -3 * 60}, /* Papa */
@@ -205,14 +206,14 @@ static int checkday(const char *check, size_t len)
{
int i;
const char * const *what;
- bool found= FALSE;
+ bool found = FALSE;
if(len > 3)
what = &weekday[0];
else
what = &Curl_wkday[0];
- for(i=0; i<7; i++) {
+ for(i = 0; i<7; i++) {
if(strcasecompare(check, what[0])) {
- found=TRUE;
+ found = TRUE;
break;
}
what++;
@@ -224,12 +225,12 @@ static int checkmonth(const char *check)
{
int i;
const char * const *what;
- bool found= FALSE;
+ bool found = FALSE;
what = &Curl_month[0];
- for(i=0; i<12; i++) {
+ for(i = 0; i<12; i++) {
if(strcasecompare(check, what[0])) {
- found=TRUE;
+ found = TRUE;
break;
}
what++;
@@ -244,12 +245,12 @@ static int checktz(const char *check)
{
unsigned int i;
const struct tzinfo *what;
- bool found= FALSE;
+ bool found = FALSE;
what = tz;
- for(i=0; i< sizeof(tz)/sizeof(tz[0]); i++) {
+ for(i = 0; i< sizeof(tz)/sizeof(tz[0]); i++) {
if(strcasecompare(check, what->name)) {
- found=TRUE;
+ found = TRUE;
break;
}
what++;
@@ -278,26 +279,23 @@ struct my_tm {
int tm_hour;
int tm_mday;
int tm_mon;
- int tm_year;
+ int tm_year; /* full year */
};
/* struct tm to time since epoch in GMT time zone.
* This is similar to the standard mktime function but for GMT only, and
* doesn't suffer from the various bugs and portability problems that
* some systems' implementations have.
+ *
+ * Returns 0 on success, otherwise non-zero.
*/
-static time_t my_timegm(struct my_tm *tm)
+static void my_timegm(struct my_tm *tm, time_t *t)
{
static const int month_days_cumulative [12] =
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
int month, year, leap_days;
- if(tm->tm_year < 70)
- /* we don't support years before 1970 as they will cause this function
- to return a negative value */
- return -1;
-
- year = tm->tm_year + 1900;
+ year = tm->tm_year;
month = tm->tm_mon;
if(month < 0) {
year += (11 - month) / 12;
@@ -312,9 +310,9 @@ static time_t my_timegm(struct my_tm *tm)
leap_days = ((leap_days / 4) - (leap_days / 100) + (leap_days / 400)
- (1969 / 4) + (1969 / 100) - (1969 / 400));
- return ((((time_t) (year - 1970) * 365
- + leap_days + month_days_cumulative [month] + tm->tm_mday - 1) * 24
- + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
+ *t = ((((time_t) (year - 1970) * 365
+ + leap_days + month_days_cumulative[month] + tm->tm_mday - 1) * 24
+ + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
}
/*
@@ -331,21 +329,21 @@ static time_t my_timegm(struct my_tm *tm)
static int parsedate(const char *date, time_t *output)
{
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;
+ 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 my_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;
+ bool found = FALSE;
skip(&date);
@@ -386,7 +384,7 @@ static int parsedate(const char *date, time_t *output)
/* a digit */
int val;
char *end;
- int len=0;
+ int len = 0;
if((secnum == -1) &&
(3 == sscanf(date, "%02d:%02d:%02d%n",
&hournum, &minnum, &secnum, &len))) {
@@ -404,12 +402,12 @@ static int parsedate(const char *date, time_t *output)
int error;
int old_errno;
- old_errno = ERRNO;
- SET_ERRNO(0);
+ old_errno = errno;
+ errno = 0;
lval = strtol(date, &end, 10);
- error = ERRNO;
- if(error != old_errno)
- SET_ERRNO(old_errno);
+ error = errno;
+ if(errno != old_errno)
+ errno = old_errno;
if(error)
return PARSEDATE_FAIL;
@@ -438,7 +436,7 @@ static int parsedate(const char *date, time_t *output)
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 */
+ this we need their reversed math to get what we want */
tzoff = date[-1]=='+'?-tzoff:tzoff;
}
@@ -464,7 +462,7 @@ static int parsedate(const char *date, time_t *output)
if(!found && (dignext == DATE_YEAR) && (yearnum == -1)) {
yearnum = val;
found = TRUE;
- if(yearnum < 1900) {
+ if(yearnum < 100) {
if(yearnum > 70)
yearnum += 1900;
else
@@ -493,18 +491,39 @@ static int parsedate(const char *date, time_t *output)
/* lacks vital info, fail */
return PARSEDATE_FAIL;
-#if SIZEOF_TIME_T < 5
- /* 32 bit time_t can only hold dates to the beginning of 2038 */
- if(yearnum > 2037) {
- *output = 0x7fffffff;
- return PARSEDATE_LATER;
+#ifdef HAVE_TIME_T_UNSIGNED
+ if(yearnum < 1970) {
+ /* only positive numbers cannot return earlier */
+ *output = TIME_T_MIN;
+ return PARSEDATE_SOONER;
}
#endif
- if(yearnum < 1970) {
- *output = 0;
+#if (SIZEOF_TIME_T < 5)
+
+#ifdef HAVE_TIME_T_UNSIGNED
+ /* an unsigned 32 bit time_t can only hold dates to 2106 */
+ if(yearnum > 2105) {
+ *output = TIME_T_MAX;
+ return PARSEDATE_LATER;
+ }
+#else
+ /* a signed 32 bit time_t can only hold dates to the beginning of 2038 */
+ if(yearnum > 2037) {
+ *output = TIME_T_MAX;
+ return PARSEDATE_LATER;
+ }
+ if(yearnum < 1903) {
+ *output = TIME_T_MIN;
return PARSEDATE_SOONER;
}
+#endif
+
+#else
+ /* The Gregorian calendar was introduced 1582 */
+ if(yearnum < 1583)
+ return PARSEDATE_FAIL;
+#endif
if((mdaynum > 31) || (monnum > 11) ||
(hournum > 23) || (minnum > 59) || (secnum > 60))
@@ -515,35 +534,38 @@ static int parsedate(const char *date, time_t *output)
tm.tm_hour = hournum;
tm.tm_mday = mdaynum;
tm.tm_mon = monnum;
- tm.tm_year = yearnum - 1900;
+ tm.tm_year = yearnum;
- /* my_timegm() 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 on some of the systems with 64 bit time_t mktime() returns -1 for
- dates beyond 03:14:07 UTC, January 19, 2038. (Such as AIX 5100-06)
+ /* my_timegm() returns a time_t. time_t is often 32 bits, sometimes even on
+ architectures that feature 64 bit 'long' but ultimately time_t is the
+ correct data type to use.
*/
- t = my_timegm(&tm);
-
- /* time zone adjust (cast t to int to compare to negative one) */
- if(-1 != (int)t) {
-
- /* Add the time zone diff between local time zone and GMT. */
- long delta = (long)(tzoff!=-1?tzoff:0);
+ my_timegm(&tm, &t);
- if((delta>0) && (t > LONG_MAX - delta)) {
- *output = 0x7fffffff;
- return PARSEDATE_LATER; /* time_t overflow */
- }
+ /* Add the time zone diff between local time zone and GMT. */
+ if(tzoff == -1)
+ tzoff = 0;
- t += delta;
+ if((tzoff > 0) && (t > TIME_T_MAX - tzoff)) {
+ *output = TIME_T_MAX;
+ return PARSEDATE_LATER; /* time_t overflow */
}
+ t += tzoff;
+
*output = t;
return PARSEDATE_OK;
}
+#else
+/* disabled */
+static int parsedate(const char *date, time_t *output)
+{
+ (void)date;
+ *output = 0;
+ return PARSEDATE_OK; /* a lie */
+}
+#endif
time_t curl_getdate(const char *p, const time_t *now)
{
@@ -551,10 +573,10 @@ time_t curl_getdate(const char *p, const time_t *now)
int rc = parsedate(p, &parsed);
(void)now; /* legacy argument from the past that we ignore */
- switch(rc) {
- case PARSEDATE_OK:
- case PARSEDATE_LATER:
- case PARSEDATE_SOONER:
+ if(rc == PARSEDATE_OK) {
+ if(parsed == -1)
+ /* avoid returning -1 for a working scenario */
+ parsed++;
return parsed;
}
/* everything else is fail */
diff --git a/Utilities/cmcurl/lib/parsedate.h b/Utilities/cmcurl/lib/parsedate.h
index 2e59eb17c..8dc3b90ec 100644
--- a/Utilities/cmcurl/lib/parsedate.h
+++ b/Utilities/cmcurl/lib/parsedate.h
@@ -28,4 +28,3 @@ extern const char * const Curl_month[12];
CURLcode Curl_gmtime(time_t intime, struct tm *store);
#endif /* HEADER_CURL_PARSEDATE_H */
-
diff --git a/Utilities/cmcurl/lib/pingpong.c b/Utilities/cmcurl/lib/pingpong.c
index 5ed79b718..e9568ee3d 100644
--- a/Utilities/cmcurl/lib/pingpong.c
+++ b/Utilities/cmcurl/lib/pingpong.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -44,13 +44,12 @@
/* Returns timeout in ms. 0 or negative number means the timeout has already
triggered */
-time_t Curl_pp_state_timeout(struct pingpong *pp)
+time_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting)
{
struct connectdata *conn = pp->conn;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
time_t timeout_ms; /* in milliseconds */
- time_t timeout2_ms; /* in milliseconds */
- long response_time= (data->set.server_response_timeout)?
+ long response_time = (data->set.server_response_timeout)?
data->set.server_response_timeout: pp->response_time;
/* if CURLOPT_SERVER_RESPONSE_TIMEOUT is set, use that to determine
@@ -61,12 +60,12 @@ time_t Curl_pp_state_timeout(struct pingpong *pp)
/* Without a requested timeout, we only wait 'response_time' seconds for the
full response to arrive before we bail out */
timeout_ms = response_time -
- Curl_tvdiff(Curl_tvnow(), pp->response); /* spent time */
+ Curl_timediff(Curl_now(), pp->response); /* spent time */
- if(data->set.timeout) {
+ if(data->set.timeout && !disconnecting) {
/* if timeout is requested, find out how much remaining time we have */
- timeout2_ms = data->set.timeout - /* timeout time */
- Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */
+ time_t timeout2_ms = data->set.timeout - /* timeout time */
+ Curl_timediff(Curl_now(), conn->now); /* spent time */
/* pick the lowest number */
timeout_ms = CURLMIN(timeout_ms, timeout2_ms);
@@ -78,17 +77,18 @@ time_t Curl_pp_state_timeout(struct pingpong *pp)
/*
* Curl_pp_statemach()
*/
-CURLcode Curl_pp_statemach(struct pingpong *pp, bool block)
+CURLcode Curl_pp_statemach(struct pingpong *pp, bool block,
+ bool disconnecting)
{
struct connectdata *conn = pp->conn;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
int rc;
time_t interval_ms;
- time_t timeout_ms = Curl_pp_state_timeout(pp);
- struct Curl_easy *data=conn->data;
+ time_t timeout_ms = Curl_pp_state_timeout(pp, disconnecting);
+ struct Curl_easy *data = conn->data;
CURLcode result = CURLE_OK;
- if(timeout_ms <=0) {
+ if(timeout_ms <= 0) {
failf(data, "server response timeout");
return CURLE_OPERATION_TIMEDOUT; /* already too little time */
}
@@ -120,7 +120,7 @@ CURLcode Curl_pp_statemach(struct pingpong *pp, bool block)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
- result = Curl_speedcheck(data, Curl_tvnow());
+ result = Curl_speedcheck(data, Curl_now());
if(result)
return result;
@@ -143,7 +143,7 @@ void Curl_pp_init(struct pingpong *pp)
pp->nread_resp = 0;
pp->linestart_resp = conn->data->state.buffer;
pp->pending_resp = TRUE;
- pp->response = Curl_tvnow(); /* start response time-out now! */
+ pp->response = Curl_now(); /* start response time-out now! */
}
@@ -168,16 +168,22 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
char *s;
CURLcode result;
struct connectdata *conn = pp->conn;
- struct Curl_easy *data = conn->data;
+ struct Curl_easy *data;
#ifdef HAVE_GSSAPI
- enum protection_level data_sec = conn->data_prot;
+ enum protection_level data_sec;
#endif
DEBUGASSERT(pp->sendleft == 0);
DEBUGASSERT(pp->sendsize == 0);
DEBUGASSERT(pp->sendthis == NULL);
+ if(!conn)
+ /* can't send without a connection! */
+ return CURLE_SEND_ERROR;
+
+ data = conn->data;
+
fmt_crlf = aprintf("%s\r\n", fmt); /* append a trailing CRLF */
if(!fmt_crlf)
return CURLE_OUT_OF_MEMORY;
@@ -205,6 +211,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
result = Curl_write(conn, conn->sock[FIRSTSOCKET], s, write_len,
&bytes_written);
#ifdef HAVE_GSSAPI
+ data_sec = conn->data_prot;
DEBUGASSERT(data_sec > PROT_NONE && data_sec < PROT_LAST);
conn->data_prot = data_sec;
#endif
@@ -215,8 +222,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
}
if(conn->data->set.verbose)
- Curl_debug(conn->data, CURLINFO_HEADER_OUT,
- s, (size_t)bytes_written, conn);
+ Curl_debug(conn->data, CURLINFO_HEADER_OUT, s, (size_t)bytes_written);
if(bytes_written != (ssize_t)write_len) {
/* the whole chunk was not sent, keep it around and adjust sizes */
@@ -228,7 +234,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
free(s);
pp->sendthis = NULL;
pp->sendleft = pp->sendsize = 0;
- pp->response = Curl_tvnow();
+ pp->response = Curl_now();
}
return CURLE_OK;
@@ -270,7 +276,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
size_t *size) /* size of the response */
{
ssize_t perline; /* count bytes per line */
- bool keepon=TRUE;
+ bool keepon = TRUE;
ssize_t gotbytes;
char *ptr;
struct connectdata *conn = pp->conn;
@@ -281,7 +287,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
*code = 0; /* 0 for errors or not done */
*size = 0;
- ptr=buf + pp->nread_resp;
+ ptr = buf + pp->nread_resp;
/* number of bytes in the current line, so far */
perline = (ssize_t)(ptr-pp->linestart_resp);
@@ -297,7 +303,10 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
* it would have been populated with something of size int to begin
* with, even though its datatype may be larger than an int.
*/
- DEBUGASSERT((ptr+pp->cache_size) <= (buf+data->set.buffer_size+1));
+ if((ptr + pp->cache_size) > (buf + data->set.buffer_size + 1)) {
+ failf(data, "cached response data too big to handle");
+ return CURLE_RECV_ERROR;
+ }
memcpy(ptr, pp->cache, pp->cache_size);
gotbytes = (ssize_t)pp->cache_size;
free(pp->cache); /* free the cache */
@@ -351,7 +360,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
pp->nread_resp += gotbytes;
for(i = 0; i < gotbytes; ptr++, i++) {
perline++;
- if(*ptr=='\n') {
+ if(*ptr == '\n') {
/* a newline is CRLF in pp-talk, so the CR is ignored as
the line isn't really terminated until the LF comes */
@@ -361,7 +370,7 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
#endif
if(data->set.verbose)
Curl_debug(data, CURLINFO_HEADER_IN,
- pp->linestart_resp, (size_t)perline, conn);
+ pp->linestart_resp, (size_t)perline);
/*
* We pass all response-lines to the callback function registered
@@ -378,17 +387,17 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
start of the buffer and zero terminate, for old times sake */
size_t n = ptr - pp->linestart_resp;
memmove(buf, pp->linestart_resp, n);
- buf[n]=0; /* zero terminate */
- keepon=FALSE;
- pp->linestart_resp = ptr+1; /* advance pointer */
+ buf[n] = 0; /* zero terminate */
+ keepon = FALSE;
+ pp->linestart_resp = ptr + 1; /* advance pointer */
i++; /* skip this before getting out */
*size = pp->nread_resp; /* size of the response */
pp->nread_resp = 0; /* restart */
break;
}
- perline=0; /* line starts over here */
- pp->linestart_resp = ptr+1;
+ perline = 0; /* line starts over here */
+ pp->linestart_resp = ptr + 1;
}
}
@@ -490,9 +499,9 @@ CURLcode Curl_pp_flushsend(struct pingpong *pp)
}
else {
free(pp->sendthis);
- pp->sendthis=NULL;
+ pp->sendthis = NULL;
pp->sendleft = pp->sendsize = 0;
- pp->response = Curl_tvnow();
+ pp->response = Curl_now();
}
return CURLE_OK;
}
diff --git a/Utilities/cmcurl/lib/pingpong.h b/Utilities/cmcurl/lib/pingpong.h
index ee1a59b51..dbe1f8d3d 100644
--- a/Utilities/cmcurl/lib/pingpong.h
+++ b/Utilities/cmcurl/lib/pingpong.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -58,8 +58,8 @@ struct pingpong {
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 */
+ struct curltime response; /* set to Curl_now() when a command has been sent
+ off, used to time-out response reading */
long response_time; /* When no timeout is given, this is the amount of
milliseconds we await for a server response. */
@@ -81,14 +81,15 @@ struct pingpong {
* called repeatedly until done. Set 'wait' to make it wait a while on the
* socket if there's no traffic.
*/
-CURLcode Curl_pp_statemach(struct pingpong *pp, bool block);
+CURLcode Curl_pp_statemach(struct pingpong *pp, bool block,
+ bool disconnecting);
/* initialize stuff to prepare for reading a fresh new response */
void Curl_pp_init(struct pingpong *pp);
/* Returns timeout in ms. 0 or negative number means the timeout has already
triggered */
-time_t Curl_pp_state_timeout(struct pingpong *pp);
+time_t Curl_pp_state_timeout(struct pingpong *pp, bool disconnecting);
/***********************************************************************
diff --git a/Utilities/cmcurl/lib/pop3.c b/Utilities/cmcurl/lib/pop3.c
index 3feb3be83..c8f3965e4 100644
--- a/Utilities/cmcurl/lib/pop3.c
+++ b/Utilities/cmcurl/lib/pop3.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -30,6 +30,7 @@
* RFC4752 The Kerberos V5 ("GSSAPI") SASL Mechanism
* RFC5034 POP3 SASL Authentication Mechanism
* RFC6749 OAuth 2.0 Authorization Framework
+ * RFC8314 Use of TLS for Email Submission and Access
* Draft LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
*
***************************************************************************/
@@ -125,6 +126,7 @@ const struct Curl_handler Curl_handler_pop3 = {
ZERO_NULL, /* perform_getsock */
pop3_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_POP3, /* defport */
CURLPROTO_POP3, /* protocol */
PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */
@@ -151,6 +153,7 @@ const struct Curl_handler Curl_handler_pop3s = {
ZERO_NULL, /* perform_getsock */
pop3_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_POP3S, /* defport */
CURLPROTO_POP3S, /* protocol */
PROTOPT_CLOSEACTION | PROTOPT_SSL
@@ -158,58 +161,6 @@ const struct Curl_handler Curl_handler_pop3s = {
};
#endif
-#ifndef CURL_DISABLE_HTTP
-/*
- * HTTP-proxyed POP3 protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_pop3_proxy = {
- "POP3", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_POP3, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-
-#ifdef USE_SSL
-/*
- * HTTP-proxyed POP3S protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_pop3s_proxy = {
- "POP3S", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_POP3S, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-#endif
-#endif
-
/* SASL parameters for the pop3 protocol */
static const struct SASLproto saslpop3 = {
"pop", /* The service name */
@@ -258,7 +209,7 @@ static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
/* Are we processing CAPA command responses? */
if(pop3c->state == POP3_CAPA) {
/* Do we have the terminating line? */
- if(len >= 1 && !memcmp(line, ".", 1))
+ if(len >= 1 && line[0] == '.')
/* Treat the response as a success */
*resp = '+';
else
@@ -276,7 +227,7 @@ static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
}
/* Do we have a continuation response? */
- if(len >= 1 && !memcmp("+", line, 1)) {
+ if(len >= 1 && line[0] == '+') {
*resp = '*';
return TRUE;
@@ -293,23 +244,30 @@ static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
*/
static void pop3_get_message(char *buffer, char **outptr)
{
- size_t len = 0;
+ size_t len = strlen(buffer);
char *message = NULL;
- /* Find the start of the message */
- for(message = buffer + 2; *message == ' ' || *message == '\t'; message++)
- ;
-
- /* Find the end of the message */
- for(len = strlen(message); len--;)
- if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
- message[len] != '\t')
- break;
-
- /* Terminate the message */
- if(++len) {
- message[len] = '\0';
+ if(len > 2) {
+ /* Find the start of the message */
+ len -= 2;
+ for(message = buffer + 2; *message == ' ' || *message == '\t';
+ message++, len--)
+ ;
+
+ /* Find the end of the message */
+ for(; len--;)
+ if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
+ message[len] != '\t')
+ break;
+
+ /* Terminate the message */
+ if(++len) {
+ message[len] = '\0';
+ }
}
+ else
+ /* junk input => zero length output */
+ message = &buffer[len];
*outptr = message;
}
@@ -486,7 +444,7 @@ static CURLcode pop3_perform_apop(struct connectdata *conn)
/* Convert the calculated 16 octet digest into a 32 byte hex string */
for(i = 0; i < MD5_DIGEST_LEN; i++)
- snprintf(&secret[2 * i], 3, "%02x", digest[i]);
+ msnprintf(&secret[2 * i], 3, "%02x", digest[i]);
result = Curl_pp_sendf(&pop3c->pp, "APOP %s %s", conn->user, secret);
@@ -656,7 +614,6 @@ static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
struct pop3_conn *pop3c = &conn->proto.pop3c;
const char *line = data->state.buffer;
size_t len = strlen(line);
- size_t i;
(void)instate; /* no use for this yet */
@@ -668,10 +625,12 @@ static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
/* Does the server support APOP authentication? */
if(len >= 4 && line[len - 2] == '>') {
/* Look for the APOP timestamp */
+ size_t i;
for(i = 3; i < len - 2; ++i) {
if(line[i] == '<') {
/* Calculate the length of the timestamp */
size_t timestamplen = len - 1 - i;
+ char *at;
if(!timestamplen)
break;
@@ -685,8 +644,15 @@ static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
memcpy(pop3c->apoptimestamp, line + i, timestamplen);
pop3c->apoptimestamp[timestamplen] = '\0';
- /* Store the APOP capability */
- pop3c->authtypes |= POP3_TYPE_APOP;
+ /* If the timestamp does not contain '@' it is not (as required by
+ RFC-1939) conformant to the RFC-822 message id syntax, and we
+ therefore do not use APOP authentication. */
+ at = strchr(pop3c->apoptimestamp, '@');
+ if(!at)
+ Curl_safefree(pop3c->apoptimestamp);
+ else
+ /* Store the APOP capability */
+ pop3c->authtypes |= POP3_TYPE_APOP;
break;
}
}
@@ -707,7 +673,6 @@ static CURLcode pop3_state_capa_resp(struct connectdata *conn, int pop3code,
struct pop3_conn *pop3c = &conn->proto.pop3c;
const char *line = data->state.buffer;
size_t len = strlen(line);
- size_t wordlen;
(void)instate; /* no use for this yet */
@@ -732,6 +697,7 @@ static CURLcode pop3_state_capa_resp(struct connectdata *conn, int pop3code,
/* Loop through the data line */
for(;;) {
size_t llen;
+ size_t wordlen;
unsigned int mechbit;
while(len &&
@@ -947,7 +913,7 @@ static CURLcode pop3_state_command_resp(struct connectdata *conn,
if(pop3->transfer == FTPTRANSFER_BODY) {
/* POP3 download */
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
if(pp->cache) {
/* The header "cache" contains a bunch of data that is actually body
@@ -1060,19 +1026,20 @@ static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done)
return result;
}
- result = Curl_pp_statemach(&pop3c->pp, FALSE);
+ result = Curl_pp_statemach(&pop3c->pp, FALSE, FALSE);
*done = (pop3c->state == POP3_STOP) ? TRUE : FALSE;
return result;
}
-static CURLcode pop3_block_statemach(struct connectdata *conn)
+static CURLcode pop3_block_statemach(struct connectdata *conn,
+ bool disconnecting)
{
CURLcode result = CURLE_OK;
struct pop3_conn *pop3c = &conn->proto.pop3c;
while(pop3c->state != POP3_STOP && !result)
- result = Curl_pp_statemach(&pop3c->pp, TRUE);
+ result = Curl_pp_statemach(&pop3c->pp, TRUE, disconnecting);
return result;
}
@@ -1270,7 +1237,7 @@ static CURLcode pop3_disconnect(struct connectdata *conn, bool dead_connection)
point! */
if(!dead_connection && pop3c->pp.conn && pop3c->pp.conn->bits.protoconnstart)
if(!pop3_perform_quit(conn))
- (void)pop3_block_statemach(conn); /* ignore errors on QUIT */
+ (void)pop3_block_statemach(conn, TRUE); /* ignore errors on QUIT */
/* Disconnect from the server */
Curl_pp_disconnect(&pop3c->pp);
@@ -1346,8 +1313,6 @@ static CURLcode pop3_regular_transfer(struct connectdata *conn,
static CURLcode pop3_setup_connection(struct connectdata *conn)
{
- struct Curl_easy *data = conn->data;
-
/* Initialise the POP3 layer */
CURLcode result = pop3_init(conn);
if(result)
@@ -1356,32 +1321,6 @@ static CURLcode pop3_setup_connection(struct connectdata *conn)
/* Clear the TLS upgraded flag */
conn->tls_upgraded = FALSE;
- /* Set up the proxy if necessary */
- if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
- /* Unless we have asked to tunnel POP3 operations through the proxy, we
- switch and use HTTP operations only */
-#ifndef CURL_DISABLE_HTTP
- if(conn->handler == &Curl_handler_pop3)
- conn->handler = &Curl_handler_pop3_proxy;
- else {
-#ifdef USE_SSL
- conn->handler = &Curl_handler_pop3s_proxy;
-#else
- failf(data, "POP3S not supported!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
-
- /* set it up as an HTTP connection instead */
- return conn->handler->setup_connection(conn);
-#else
- failf(data, "POP3 over http proxy requires HTTP support built-in!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
-
- data->state.path++; /* don't include the initial slash */
-
return CURLE_OK;
}
@@ -1455,7 +1394,7 @@ static CURLcode pop3_parse_url_path(struct connectdata *conn)
/* The POP3 struct is already initialised in pop3_connect() */
struct Curl_easy *data = conn->data;
struct POP3 *pop3 = data->req.protop;
- const char *path = data->state.path;
+ const char *path = &data->state.up.path[1]; /* skip leading path */
/* URL decode the path for the message ID */
return Curl_urldecode(data, path, 0, &pop3->id, NULL, TRUE);
diff --git a/Utilities/cmcurl/lib/progress.c b/Utilities/cmcurl/lib/progress.c
index cfaf4049e..f586d59b4 100644
--- a/Utilities/cmcurl/lib/progress.c
+++ b/Utilities/cmcurl/lib/progress.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -24,35 +24,40 @@
#include "urldata.h"
#include "sendf.h"
+#include "multiif.h"
#include "progress.h"
#include "curl_printf.h"
+/* check rate limits within this many recent milliseconds, at minimum. */
+#define MIN_RATE_LIMIT_PERIOD 3000
+
+#ifndef CURL_DISABLE_PROGRESS_METER
/* Provide a string that is 2 + 1 + 2 + 1 + 2 = 8 letters long (plus the zero
byte) */
static void time2str(char *r, curl_off_t seconds)
{
- curl_off_t d, h, m, s;
+ curl_off_t h;
if(seconds <= 0) {
strcpy(r, "--:--:--");
return;
}
h = seconds / CURL_OFF_T_C(3600);
if(h <= CURL_OFF_T_C(99)) {
- m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
- s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
- snprintf(r, 9, "%2" CURL_FORMAT_CURL_OFF_T ":%02" CURL_FORMAT_CURL_OFF_T
- ":%02" CURL_FORMAT_CURL_OFF_T, h, m, s);
+ curl_off_t m = (seconds - (h*CURL_OFF_T_C(3600))) / CURL_OFF_T_C(60);
+ curl_off_t s = (seconds - (h*CURL_OFF_T_C(3600))) - (m*CURL_OFF_T_C(60));
+ msnprintf(r, 9, "%2" CURL_FORMAT_CURL_OFF_T ":%02" CURL_FORMAT_CURL_OFF_T
+ ":%02" CURL_FORMAT_CURL_OFF_T, h, m, s);
}
else {
/* this equals to more than 99 hours, switch to a more suitable output
format to fit within the limits. */
- d = seconds / CURL_OFF_T_C(86400);
+ curl_off_t d = seconds / CURL_OFF_T_C(86400);
h = (seconds - (d*CURL_OFF_T_C(86400))) / CURL_OFF_T_C(3600);
if(d <= CURL_OFF_T_C(999))
- snprintf(r, 9, "%3" CURL_FORMAT_CURL_OFF_T
- "d %02" CURL_FORMAT_CURL_OFF_T "h", d, h);
+ msnprintf(r, 9, "%3" CURL_FORMAT_CURL_OFF_T
+ "d %02" CURL_FORMAT_CURL_OFF_T "h", d, h);
else
- snprintf(r, 9, "%7" CURL_FORMAT_CURL_OFF_T "d", d);
+ msnprintf(r, 9, "%7" CURL_FORMAT_CURL_OFF_T "d", d);
}
}
@@ -68,40 +73,40 @@ static char *max5data(curl_off_t bytes, char *max5)
#define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE)
if(bytes < CURL_OFF_T_C(100000))
- snprintf(max5, 6, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
+ msnprintf(max5, 6, "%5" CURL_FORMAT_CURL_OFF_T, bytes);
else if(bytes < CURL_OFF_T_C(10000) * ONE_KILOBYTE)
- snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "k", bytes/ONE_KILOBYTE);
+ msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "k", bytes/ONE_KILOBYTE);
else if(bytes < CURL_OFF_T_C(100) * ONE_MEGABYTE)
/* 'XX.XM' is good as long as we're less than 100 megs */
- snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
- CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE,
- (bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) );
+ msnprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
+ CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE,
+ (bytes%ONE_MEGABYTE) / (ONE_MEGABYTE/CURL_OFF_T_C(10)) );
#if (CURL_SIZEOF_CURL_OFF_T > 4)
else if(bytes < CURL_OFF_T_C(10000) * ONE_MEGABYTE)
/* 'XXXXM' is good until we're at 10000MB or above */
- snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE);
+ msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE);
else if(bytes < CURL_OFF_T_C(100) * ONE_GIGABYTE)
/* 10000 MB - 100 GB, we show it as XX.XG */
- snprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
- CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE,
- (bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) );
+ msnprintf(max5, 6, "%2" CURL_FORMAT_CURL_OFF_T ".%0"
+ CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE,
+ (bytes%ONE_GIGABYTE) / (ONE_GIGABYTE/CURL_OFF_T_C(10)) );
else if(bytes < CURL_OFF_T_C(10000) * ONE_GIGABYTE)
/* up to 10000GB, display without decimal: XXXXG */
- snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE);
+ msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "G", bytes/ONE_GIGABYTE);
else if(bytes < CURL_OFF_T_C(10000) * ONE_TERABYTE)
/* up to 10000TB, display without decimal: XXXXT */
- snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "T", bytes/ONE_TERABYTE);
+ msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "T", bytes/ONE_TERABYTE);
else
/* up to 10000PB, display without decimal: XXXXP */
- snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "P", bytes/ONE_PETABYTE);
+ msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "P", bytes/ONE_PETABYTE);
/* 16384 petabytes (16 exabytes) is the maximum a 64 bit unsigned number
can hold, but our data type is signed so 8192PB will be the maximum. */
@@ -109,12 +114,13 @@ static char *max5data(curl_off_t bytes, char *max5)
#else
else
- snprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE);
+ msnprintf(max5, 6, "%4" CURL_FORMAT_CURL_OFF_T "M", bytes/ONE_MEGABYTE);
#endif
return max5;
}
+#endif
/*
@@ -134,7 +140,7 @@ int Curl_pgrsDone(struct connectdata *conn)
{
int rc;
struct Curl_easy *data = conn->data;
- data->progress.lastshow=0;
+ data->progress.lastshow = 0;
rc = Curl_pgrsUpdate(conn); /* the final (forced) update */
if(rc)
return rc;
@@ -149,21 +155,20 @@ int Curl_pgrsDone(struct connectdata *conn)
return 0;
}
-/* reset all times except redirect, and reset the known transfer sizes */
-void Curl_pgrsResetTimesSizes(struct Curl_easy *data)
+/* reset the known transfer sizes */
+void Curl_pgrsResetTransferSizes(struct Curl_easy *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;
-
Curl_pgrsSetDownloadSize(data, -1);
Curl_pgrsSetUploadSize(data, -1);
}
+/*
+ * @unittest: 1399
+ */
void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
{
- struct timeval now = Curl_tvnow();
+ struct curltime now = Curl_now();
+ time_t *delta = NULL;
switch(timer) {
default:
@@ -177,56 +182,70 @@ void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
case TIMER_STARTSINGLE:
/* This is set at the start of each single fetch */
data->progress.t_startsingle = now;
+ data->progress.is_t_startransfer_set = false;
break;
-
case TIMER_STARTACCEPT:
- data->progress.t_acceptdata = Curl_tvnow();
+ data->progress.t_acceptdata = now;
break;
-
case TIMER_NAMELOOKUP:
- data->progress.t_nslookup =
- Curl_tvdiff_secs(now, data->progress.t_startsingle);
+ delta = &data->progress.t_nslookup;
break;
case TIMER_CONNECT:
- data->progress.t_connect =
- Curl_tvdiff_secs(now, data->progress.t_startsingle);
+ delta = &data->progress.t_connect;
break;
case TIMER_APPCONNECT:
- data->progress.t_appconnect =
- Curl_tvdiff_secs(now, data->progress.t_startsingle);
+ delta = &data->progress.t_appconnect;
break;
case TIMER_PRETRANSFER:
- data->progress.t_pretransfer =
- Curl_tvdiff_secs(now, data->progress.t_startsingle);
+ delta = &data->progress.t_pretransfer;
break;
case TIMER_STARTTRANSFER:
- data->progress.t_starttransfer =
- Curl_tvdiff_secs(now, data->progress.t_startsingle);
- break;
+ delta = &data->progress.t_starttransfer;
+ /* prevent updating t_starttransfer unless:
+ * 1) this is the first time we're setting t_starttransfer
+ * 2) a redirect has occurred since the last time t_starttransfer was set
+ * This prevents repeated invocations of the function from incorrectly
+ * changing the t_starttransfer time.
+ */
+ if(data->progress.is_t_startransfer_set) {
+ return;
+ }
+ else {
+ data->progress.is_t_startransfer_set = true;
+ break;
+ }
case TIMER_POSTRANSFER:
/* this is the normal end-of-transfer thing */
break;
case TIMER_REDIRECT:
- data->progress.t_redirect = Curl_tvdiff_secs(now, data->progress.start);
+ data->progress.t_redirect = Curl_timediff_us(now, data->progress.start);
break;
}
+ if(delta) {
+ timediff_t us = Curl_timediff_us(now, data->progress.t_startsingle);
+ if(us < 1)
+ us = 1; /* make sure at least one microsecond passed */
+ *delta += us;
+ }
}
void Curl_pgrsStartNow(struct Curl_easy *data)
{
data->progress.speeder_c = 0; /* reset the progress meter display */
- data->progress.start = Curl_tvnow();
+ data->progress.start = Curl_now();
+ data->progress.is_t_startransfer_set = false;
data->progress.ul_limit_start.tv_sec = 0;
data->progress.ul_limit_start.tv_usec = 0;
data->progress.dl_limit_start.tv_sec = 0;
data->progress.dl_limit_start.tv_usec = 0;
/* clear all bits except HIDE and HEADERS_OUT */
data->progress.flags &= PGRS_HIDE|PGRS_HEADERS_OUT;
+ Curl_ratelimit(data, data->progress.start);
}
/*
- * This is used to handle speed limits, calculating how much milliseconds we
- * need to wait until we're back under the speed limit, if needed.
+ * This is used to handle speed limits, calculating how many milliseconds to
+ * wait until we're back under the speed limit, if needed.
*
* The way it works is by having a "starting point" (time & amount of data
* transferred by then) used in the speed computation, to be used instead of
@@ -238,73 +257,87 @@ void Curl_pgrsStartNow(struct Curl_easy *data)
* the starting point, the limit (in bytes/s), the time of the starting point
* and the current time.
*
- * Returns -1 if no waiting is needed (not enough data transferred since
- * starting point yet), 0 when no waiting is needed but the starting point
- * should be reset (to current), or the number of milliseconds to wait to get
- * back under the speed limit.
+ * Returns 0 if no waiting is needed or when no waiting is needed but the
+ * starting point should be reset (to current); or the number of milliseconds
+ * to wait to get back under the speed limit.
*/
-long Curl_pgrsLimitWaitTime(curl_off_t cursize,
- curl_off_t startsize,
- curl_off_t limit,
- struct timeval start,
- struct timeval now)
+timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize,
+ curl_off_t startsize,
+ curl_off_t limit,
+ struct curltime start,
+ struct curltime now)
{
curl_off_t size = cursize - startsize;
time_t minimum;
time_t actual;
- /* we don't have a starting point yet -- return 0 so it gets (re)set */
- if(start.tv_sec == 0 && start.tv_usec == 0)
+ if(!limit || !size)
return 0;
- /* not enough data yet */
- if(size < limit)
- return -1;
-
- minimum = (time_t) (CURL_OFF_T_C(1000) * size / limit);
- actual = Curl_tvdiff(now, start);
+ /*
+ * 'minimum' is the number of milliseconds 'size' should take to download to
+ * stay below 'limit'.
+ */
+ if(size < CURL_OFF_T_MAX/1000)
+ minimum = (time_t) (CURL_OFF_T_C(1000) * size / limit);
+ else {
+ minimum = (time_t) (size / limit);
+ if(minimum < TIME_T_MAX/1000)
+ minimum *= 1000;
+ else
+ minimum = TIME_T_MAX;
+ }
- if(actual < minimum)
- /* this is a conversion on some systems (64bit time_t => 32bit long) */
- return (long)(minimum - actual);
+ /*
+ * 'actual' is the time in milliseconds it took to actually download the
+ * last 'size' bytes.
+ */
+ actual = Curl_timediff(now, start);
+ if(actual < minimum) {
+ /* if it downloaded the data faster than the limit, make it wait the
+ difference */
+ return (minimum - actual);
+ }
return 0;
}
+/*
+ * Set the number of downloaded bytes so far.
+ */
void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
{
- struct timeval now = Curl_tvnow();
-
data->progress.downloaded = size;
+}
- /* download speed limit */
- if((data->set.max_recv_speed > 0) &&
- (Curl_pgrsLimitWaitTime(data->progress.downloaded,
- data->progress.dl_limit_size,
- data->set.max_recv_speed,
- data->progress.dl_limit_start,
- now) == 0)) {
- data->progress.dl_limit_start = now;
- data->progress.dl_limit_size = size;
+/*
+ * Update the timestamp and sizestamp to use for rate limit calculations.
+ */
+void Curl_ratelimit(struct Curl_easy *data, struct curltime now)
+{
+ /* don't set a new stamp unless the time since last update is long enough */
+ if(data->set.max_recv_speed > 0) {
+ if(Curl_timediff(now, data->progress.dl_limit_start) >=
+ MIN_RATE_LIMIT_PERIOD) {
+ data->progress.dl_limit_start = now;
+ data->progress.dl_limit_size = data->progress.downloaded;
+ }
+ }
+ if(data->set.max_send_speed > 0) {
+ if(Curl_timediff(now, data->progress.ul_limit_start) >=
+ MIN_RATE_LIMIT_PERIOD) {
+ data->progress.ul_limit_start = now;
+ data->progress.ul_limit_size = data->progress.uploaded;
+ }
}
}
+/*
+ * Set the number of uploaded bytes so far.
+ */
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size)
{
- struct timeval now = Curl_tvnow();
-
data->progress.uploaded = size;
-
- /* upload speed limit */
- if((data->set.max_send_speed > 0) &&
- (Curl_pgrsLimitWaitTime(data->progress.uploaded,
- data->progress.ul_limit_size,
- data->set.max_send_speed,
- data->progress.ul_limit_start,
- now) == 0)) {
- data->progress.ul_limit_start = now;
- data->progress.ul_limit_size = size;
- }
}
void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size)
@@ -331,60 +364,49 @@ void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
}
}
-/*
- * Curl_pgrsUpdate() returns 0 for success or the value returned by the
- * progress callback!
- */
-int Curl_pgrsUpdate(struct connectdata *conn)
+#ifndef CURL_DISABLE_PROGRESS_METER
+static void progress_meter(struct connectdata *conn)
{
- struct timeval now;
- int result;
- char max5[6][10];
- curl_off_t dlpercen=0;
- curl_off_t ulpercen=0;
- curl_off_t total_percen=0;
- curl_off_t total_transfer;
- curl_off_t total_expected_transfer;
+ struct curltime now;
curl_off_t timespent;
+ curl_off_t timespent_ms; /* milliseconds */
struct Curl_easy *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];
- curl_off_t ulestimate=0;
- curl_off_t dlestimate=0;
- curl_off_t total_estimate;
- bool shownow=FALSE;
-
- now = Curl_tvnow(); /* what time is it */
+ bool shownow = FALSE;
+ curl_off_t dl = data->progress.downloaded;
+ curl_off_t ul = data->progress.uploaded;
+
+ now = Curl_now(); /* what time is it */
/* The time spent so far (from the start) */
- data->progress.timespent = curlx_tvdiff_secs(now, data->progress.start);
- timespent = (curl_off_t)data->progress.timespent;
+ data->progress.timespent = Curl_timediff_us(now, data->progress.start);
+ timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */
+ timespent_ms = (curl_off_t)data->progress.timespent/1000; /* ms */
/* The average download speed this far */
- data->progress.dlspeed = (curl_off_t)
- ((double)data->progress.downloaded/
- (data->progress.timespent>0?data->progress.timespent:1));
+ if(dl < CURL_OFF_T_MAX/1000)
+ data->progress.dlspeed = (dl * 1000 / (timespent_ms>0?timespent_ms:1));
+ else
+ data->progress.dlspeed = (dl / (timespent>0?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(ul < CURL_OFF_T_MAX/1000)
+ data->progress.ulspeed = (ul * 1000 / (timespent_ms>0?timespent_ms:1));
+ else
+ data->progress.ulspeed = (ul / (timespent>0?timespent:1));
/* Calculations done at most once a second, unless end is reached */
if(data->progress.lastshow != now.tv_sec) {
- shownow = TRUE;
+ int countindex; /* amount of seconds stored in the speeder array */
+ int nowindex = data->progress.speeder_c% CURR_TIME;
+ if(!(data->progress.flags & PGRS_HIDE))
+ shownow = TRUE;
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 faster speed at entry 'nowindex'. */
+ /* Let's do the "current speed" thing, with the dl + ul speeds
+ combined. Store the speed at entry 'nowindex'. */
data->progress.speeder[ nowindex ] =
- data->progress.downloaded>data->progress.uploaded?
- 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;
@@ -397,24 +419,25 @@ int Curl_pgrsUpdate(struct connectdata *conn)
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)?
+ 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) {
- time_t span_ms;
+ int checkindex;
+ timediff_t 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)?
+ 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]);
+ span_ms = Curl_timediff(now,
+ data->progress.speeder_time[checkindex]);
if(0 == span_ms)
- span_ms=1; /* at least one millisecond MUST have passed */
+ span_ms = 1; /* at least one millisecond MUST have passed */
/* Calculate the average speed the last 'span_ms' milliseconds */
{
@@ -433,45 +456,30 @@ int Curl_pgrsUpdate(struct connectdata *conn)
}
}
else
- /* the first second we use the main average */
+ /* the first second we use the average */
data->progress.current_speed =
- (data->progress.ulspeed>data->progress.dlspeed)?
- data->progress.ulspeed:data->progress.dlspeed;
+ data->progress.ulspeed + data->progress.dlspeed;
} /* Calculations end */
-
- if(!(data->progress.flags & PGRS_HIDE)) {
- /* progress meter has not been shut off */
-
- if(data->set.fxferinfo) {
- /* There's a callback set, call that */
- result= data->set.fxferinfo(data->set.progress_client,
- data->progress.size_dl,
- data->progress.downloaded,
- data->progress.size_ul,
- data->progress.uploaded);
- if(result)
- failf(data, "Callback aborted");
- return result;
- }
- if(data->set.fprogress) {
- /* The older deprecated callback is set, call that */
- 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;
- }
-
- if(!shownow)
- /* only show the internal progress meter once per second */
- return 0;
-
+ if(!shownow)
+ /* only show the internal progress meter once per second */
+ return;
+ else {
/* If there's no external callback set, use internal code to show
progress */
+ /* progress meter has not been shut off */
+ char max5[6][10];
+ curl_off_t dlpercen = 0;
+ curl_off_t ulpercen = 0;
+ curl_off_t total_percen = 0;
+ curl_off_t total_transfer;
+ curl_off_t total_expected_transfer;
+ char time_left[10];
+ char time_total[10];
+ char time_spent[10];
+ curl_off_t ulestimate = 0;
+ curl_off_t dlestimate = 0;
+ curl_off_t total_estimate;
if(!(data->progress.flags & PGRS_HEADERS_OUT)) {
if(data->state.resume_from) {
@@ -524,9 +532,9 @@ int Curl_pgrsUpdate(struct connectdata *conn)
/* Get the total amount of data expected to get transferred */
total_expected_transfer =
- (data->progress.flags & PGRS_UL_SIZE_KNOWN?
+ ((data->progress.flags & PGRS_UL_SIZE_KNOWN)?
data->progress.size_ul:data->progress.uploaded)+
- (data->progress.flags & PGRS_DL_SIZE_KNOWN?
+ ((data->progress.flags & PGRS_DL_SIZE_KNOWN)?
data->progress.size_dl:data->progress.downloaded);
/* We have transferred this much so far */
@@ -555,13 +563,57 @@ int Curl_pgrsUpdate(struct connectdata *conn)
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 */
- );
+ max5data(data->progress.current_speed, max5[5])
+ );
/* we flush the output stream to make it appear as soon as possible */
fflush(data->set.err);
+ } /* don't show now */
+}
+#else
+ /* progress bar disabled */
+#define progress_meter(x)
+#endif
+
- } /* !(data->progress.flags & PGRS_HIDE) */
+/*
+ * Curl_pgrsUpdate() returns 0 for success or the value returned by the
+ * progress callback!
+ */
+int Curl_pgrsUpdate(struct connectdata *conn)
+{
+ struct Curl_easy *data = conn->data;
+ if(!(data->progress.flags & PGRS_HIDE)) {
+ if(data->set.fxferinfo) {
+ int result;
+ /* There's a callback set, call that */
+ Curl_set_in_callback(data, true);
+ result = data->set.fxferinfo(data->set.progress_client,
+ data->progress.size_dl,
+ data->progress.downloaded,
+ data->progress.size_ul,
+ data->progress.uploaded);
+ Curl_set_in_callback(data, false);
+ if(result)
+ failf(data, "Callback aborted");
+ return result;
+ }
+ if(data->set.fprogress) {
+ int result;
+ /* The older deprecated callback is set, call that */
+ Curl_set_in_callback(data, true);
+ 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);
+ Curl_set_in_callback(data, false);
+ if(result)
+ failf(data, "Callback aborted");
+ return result;
+ }
+ }
+ progress_meter(conn);
return 0;
}
diff --git a/Utilities/cmcurl/lib/progress.h b/Utilities/cmcurl/lib/progress.h
index 155ff04fe..3515ac6d5 100644
--- a/Utilities/cmcurl/lib/progress.h
+++ b/Utilities/cmcurl/lib/progress.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -46,32 +46,19 @@ void Curl_pgrsSetDownloadSize(struct Curl_easy *data, curl_off_t size);
void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size);
void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size);
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size);
+void Curl_ratelimit(struct Curl_easy *data, struct curltime now);
int Curl_pgrsUpdate(struct connectdata *);
-void Curl_pgrsResetTimesSizes(struct Curl_easy *data);
+void Curl_pgrsResetTransferSizes(struct Curl_easy *data);
void Curl_pgrsTime(struct Curl_easy *data, timerid timer);
-long Curl_pgrsLimitWaitTime(curl_off_t cursize,
- curl_off_t startsize,
- curl_off_t limit,
- struct timeval start,
- struct timeval now);
+timediff_t Curl_pgrsLimitWaitTime(curl_off_t cursize,
+ curl_off_t startsize,
+ curl_off_t limit,
+ struct curltime start,
+ struct curltime now);
-/* 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 /* HEADER_CURL_PROGRESS_H */
-
diff --git a/Utilities/cmcurl/lib/rand.c b/Utilities/cmcurl/lib/rand.c
index b6f40ac0a..6ee45feb1 100644
--- a/Utilities/cmcurl/lib/rand.c
+++ b/Utilities/cmcurl/lib/rand.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -86,7 +86,7 @@ static CURLcode randit(struct Curl_easy *data, unsigned int *rnd)
#endif
if(!seeded) {
- struct timeval now = curlx_tvnow();
+ struct curltime now = Curl_now();
infof(data, "WARNING: Using weak random seed\n");
randseed += (unsigned int)now.tv_usec + (unsigned int)now.tv_sec;
randseed = randseed * 1103515245 + 12345;
@@ -157,6 +157,12 @@ CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd,
unsigned char *bufp = buffer;
DEBUGASSERT(num > 1);
+#ifdef __clang_analyzer__
+ /* This silences a scan-build warning about accessing this buffer with
+ uninitialized memory. */
+ memset(buffer, 0, sizeof(buffer));
+#endif
+
if((num/2 >= sizeof(buffer)) || !(num&1))
/* make sure it fits in the local buffer and that it is an odd number! */
return CURLE_BAD_FUNCTION_ARGUMENT;
@@ -168,6 +174,8 @@ CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd,
return result;
while(num) {
+ /* clang-tidy warns on this line without this comment: */
+ /* NOLINTNEXTLINE(clang-analyzer-core.UndefinedBinaryOperatorResult) */
*rnd++ = hex[(*bufp & 0xF0)>>4];
*rnd++ = hex[*bufp & 0x0F];
bufp++;
diff --git a/Utilities/cmcurl/lib/rand.h b/Utilities/cmcurl/lib/rand.h
index c6fae3553..5deb04161 100644
--- a/Utilities/cmcurl/lib/rand.h
+++ b/Utilities/cmcurl/lib/rand.h
@@ -39,8 +39,11 @@
*/
CURLcode Curl_rand(struct Curl_easy *data, unsigned char *rnd, size_t num);
-/* Same as above but outputs only random lowercase hex characters.
- Does NOT terminate.*/
+/*
+ * Curl_rand_hex() fills the 'rnd' buffer with a given 'num' size with random
+ * hexadecimal digits PLUS a zero terminating byte. It must be an odd number
+ * size.
+ */
CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd,
size_t num);
diff --git a/Utilities/cmcurl/lib/rtsp.c b/Utilities/cmcurl/lib/rtsp.c
index 1810cdafb..74cf23244 100644
--- a/Utilities/cmcurl/lib/rtsp.c
+++ b/Utilities/cmcurl/lib/rtsp.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -42,16 +42,6 @@
#include "curl_memory.h"
#include "memdebug.h"
-/*
- * TODO (general)
- * -incoming server requests
- * -server CSeq counter
- * -digest authentication
- * -connect thru proxy
- * -pipelining?
- */
-
-
#define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
#define RTP_PKT_LENGTH(p) ((((int)((unsigned char)((p)[2]))) << 8) | \
@@ -80,7 +70,8 @@ static CURLcode rtsp_rtp_readwrite(struct Curl_easy *data,
bool *readmore);
static CURLcode rtsp_setup_connection(struct connectdata *conn);
-
+static unsigned int rtsp_conncheck(struct connectdata *check,
+ unsigned int checks_to_perform);
/* this returns the socket to wait for in the DO and DOING state for the multi
interface and then we're always _sending_ a request and thus we wait for
@@ -117,6 +108,7 @@ const struct Curl_handler Curl_handler_rtsp = {
ZERO_NULL, /* perform_getsock */
rtsp_disconnect, /* disconnect */
rtsp_rtp_readwrite, /* readwrite */
+ rtsp_conncheck, /* connection_check */
PORT_RTSP, /* defport */
CURLPROTO_RTSP, /* protocol */
PROTOPT_NONE /* flags */
@@ -143,7 +135,7 @@ static CURLcode rtsp_setup_connection(struct connectdata *conn)
* Instead, if it is readable, run Curl_connalive() to peek at the socket
* and distinguish between closed and data.
*/
-bool Curl_rtsp_connisdead(struct connectdata *check)
+static bool rtsp_connisdead(struct connectdata *check)
{
int sval;
bool ret_val = TRUE;
@@ -165,6 +157,23 @@ bool Curl_rtsp_connisdead(struct connectdata *check)
return ret_val;
}
+/*
+ * Function to check on various aspects of a connection.
+ */
+static unsigned int rtsp_conncheck(struct connectdata *check,
+ unsigned int checks_to_perform)
+{
+ unsigned int ret_val = CONNRESULT_NONE;
+
+ if(checks_to_perform & CONNCHECK_ISDEAD) {
+ if(rtsp_connisdead(check))
+ ret_val |= CONNRESULT_DEAD;
+ }
+
+ return ret_val;
+}
+
+
static CURLcode rtsp_connect(struct connectdata *conn, bool *done)
{
CURLcode httpStatus;
@@ -197,8 +206,6 @@ static CURLcode rtsp_done(struct connectdata *conn,
struct Curl_easy *data = conn->data;
struct RTSP *rtsp = data->req.protop;
CURLcode httpStatus;
- long CSeq_sent;
- long CSeq_recv;
/* Bypass HTTP empty-reply checks on receive */
if(data->set.rtspreq == RTSPREQ_RECEIVE)
@@ -208,8 +215,8 @@ static CURLcode rtsp_done(struct connectdata *conn,
if(rtsp) {
/* Check the sequence numbers */
- CSeq_sent = rtsp->CSeq_sent;
- CSeq_recv = rtsp->CSeq_recv;
+ long CSeq_sent = rtsp->CSeq_sent;
+ long CSeq_recv = rtsp->CSeq_recv;
if((data->set.rtspreq != RTSPREQ_RECEIVE) && (CSeq_sent != CSeq_recv)) {
failf(data,
"The CSeq of this request %ld did not match the response %ld",
@@ -219,7 +226,6 @@ static CURLcode rtsp_done(struct connectdata *conn,
if(data->set.rtspreq == RTSPREQ_RECEIVE &&
(conn->proto.rtspc.rtp_channel == -1)) {
infof(data, "Got an RTP Receive with a CSeq of %ld\n", CSeq_recv);
- /* TODO CPC: Server -> Client logic here */
}
}
@@ -229,10 +235,9 @@ static CURLcode rtsp_done(struct connectdata *conn,
static CURLcode rtsp_do(struct connectdata *conn, bool *done)
{
struct Curl_easy *data = conn->data;
- CURLcode result=CURLE_OK;
+ CURLcode result = CURLE_OK;
Curl_RtspReq rtspreq = data->set.rtspreq;
struct RTSP *rtsp = data->req.protop;
- struct HTTP *http;
Curl_send_buffer *req_buffer;
curl_off_t postsize = 0; /* for ANNOUNCE and SET_PARAMETER */
curl_off_t putsize = 0; /* for ANNOUNCE and SET_PARAMETER */
@@ -251,10 +256,6 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
*done = TRUE;
- http = &(rtsp->http_wrapper);
- /* Assert that no one has changed the RTSP struct in an evil way */
- DEBUGASSERT((void *)http == (void *)rtsp);
-
rtsp->CSeq_sent = data->state.rtsp_next_client_CSeq;
rtsp->CSeq_recv = 0;
@@ -311,8 +312,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
}
if(rtspreq == RTSPREQ_RECEIVE) {
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE,
- &http->readbytecount, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, TRUE, -1);
return result;
}
@@ -325,8 +325,6 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
return CURLE_BAD_FUNCTION_ARGUMENT;
}
- /* TODO: proxy? */
-
/* Stream URI. Default to server '*' if not specified */
if(data->set.str[STRING_RTSP_STREAM_URI]) {
p_stream_uri = data->set.str[STRING_RTSP_STREAM_URI];
@@ -336,7 +334,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
}
/* Transport Header for SETUP requests */
- p_transport = Curl_checkheaders(conn, "Transport:");
+ p_transport = Curl_checkheaders(conn, "Transport");
if(rtspreq == RTSPREQ_SETUP && !p_transport) {
/* New Transport: setting? */
if(data->set.str[STRING_RTSP_TRANSPORT]) {
@@ -360,11 +358,11 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
/* Accept Headers for DESCRIBE requests */
if(rtspreq == RTSPREQ_DESCRIBE) {
/* Accept Header */
- p_accept = Curl_checkheaders(conn, "Accept:")?
+ p_accept = Curl_checkheaders(conn, "Accept")?
NULL:"Accept: application/sdp\r\n";
/* Accept-Encoding header */
- if(!Curl_checkheaders(conn, "Accept-Encoding:") &&
+ if(!Curl_checkheaders(conn, "Accept-Encoding") &&
data->set.str[STRING_ENCODING]) {
Curl_safefree(conn->allocptr.accept_encoding);
conn->allocptr.accept_encoding =
@@ -381,11 +379,11 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
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(Curl_checkheaders(conn, "User-Agent:") && conn->allocptr.uagent) {
+ if(Curl_checkheaders(conn, "User-Agent") && conn->allocptr.uagent) {
Curl_safefree(conn->allocptr.uagent);
conn->allocptr.uagent = NULL;
}
- else if(!Curl_checkheaders(conn, "User-Agent:") &&
+ else if(!Curl_checkheaders(conn, "User-Agent") &&
data->set.str[STRING_USERAGENT]) {
p_uagent = conn->allocptr.uagent;
}
@@ -400,7 +398,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
/* Referrer */
Curl_safefree(conn->allocptr.ref);
- if(data->change.referer && !Curl_checkheaders(conn, "Referer:"))
+ if(data->change.referer && !Curl_checkheaders(conn, "Referer"))
conn->allocptr.ref = aprintf("Referer: %s\r\n", data->change.referer);
else
conn->allocptr.ref = NULL;
@@ -417,7 +415,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
(rtspreq & (RTSPREQ_PLAY | RTSPREQ_PAUSE | RTSPREQ_RECORD))) {
/* Check to see if there is a range set in the custom headers */
- if(!Curl_checkheaders(conn, "Range:") && data->state.range) {
+ if(!Curl_checkheaders(conn, "Range") && data->state.range) {
Curl_safefree(conn->allocptr.rangeline);
conn->allocptr.rangeline = aprintf("Range: %s\r\n", data->state.range);
p_range = conn->allocptr.rangeline;
@@ -427,11 +425,11 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
/*
* Sanity check the custom headers
*/
- if(Curl_checkheaders(conn, "CSeq:")) {
+ if(Curl_checkheaders(conn, "CSeq")) {
failf(data, "CSeq cannot be set as a custom header.");
return CURLE_RTSP_CSEQ_ERROR;
}
- if(Curl_checkheaders(conn, "Session:")) {
+ if(Curl_checkheaders(conn, "Session")) {
failf(data, "Session ID cannot be set as a custom header.");
return CURLE_BAD_FUNCTION_ARGUMENT;
}
@@ -443,7 +441,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
return CURLE_OUT_OF_MEMORY;
result =
- Curl_add_bufferf(req_buffer,
+ Curl_add_bufferf(&req_buffer,
"%s %s RTSP/1.0\r\n" /* Request Stream-URI RTSP/1.0 */
"CSeq: %ld\r\n", /* CSeq */
p_request, p_stream_uri, rtsp->CSeq_sent);
@@ -455,7 +453,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
* to make comparison easier
*/
if(p_session_id) {
- result = Curl_add_bufferf(req_buffer, "Session: %s\r\n", p_session_id);
+ result = Curl_add_bufferf(&req_buffer, "Session: %s\r\n", p_session_id);
if(result)
return result;
}
@@ -463,7 +461,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
/*
* Shared HTTP-like options
*/
- result = Curl_add_bufferf(req_buffer,
+ result = Curl_add_bufferf(&req_buffer,
"%s" /* transport */
"%s" /* accept */
"%s" /* accept-encoding */
@@ -521,28 +519,29 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
if(putsize > 0 || postsize > 0) {
/* As stated in the http comments, it is probably not wise to
* actually set a custom Content-Length in the headers */
- if(!Curl_checkheaders(conn, "Content-Length:")) {
- result = Curl_add_bufferf(req_buffer,
- "Content-Length: %" CURL_FORMAT_CURL_OFF_T"\r\n",
- (data->set.upload ? putsize : postsize));
+ if(!Curl_checkheaders(conn, "Content-Length")) {
+ result =
+ Curl_add_bufferf(&req_buffer,
+ "Content-Length: %" CURL_FORMAT_CURL_OFF_T"\r\n",
+ (data->set.upload ? putsize : postsize));
if(result)
return result;
}
if(rtspreq == RTSPREQ_SET_PARAMETER ||
rtspreq == RTSPREQ_GET_PARAMETER) {
- if(!Curl_checkheaders(conn, "Content-Type:")) {
- result = Curl_add_bufferf(req_buffer,
- "Content-Type: text/parameters\r\n");
+ if(!Curl_checkheaders(conn, "Content-Type")) {
+ result = Curl_add_bufferf(&req_buffer,
+ "Content-Type: text/parameters\r\n");
if(result)
return result;
}
}
if(rtspreq == RTSPREQ_ANNOUNCE) {
- if(!Curl_checkheaders(conn, "Content-Type:")) {
- result = Curl_add_bufferf(req_buffer,
- "Content-Type: application/sdp\r\n");
+ if(!Curl_checkheaders(conn, "Content-Type")) {
+ result = Curl_add_bufferf(&req_buffer,
+ "Content-Type: application/sdp\r\n");
if(result)
return result;
}
@@ -560,36 +559,34 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done)
/* RTSP never allows chunked transfer */
data->req.forbidchunk = TRUE;
/* Finish the request buffer */
- result = Curl_add_buffer(req_buffer, "\r\n", 2);
+ result = Curl_add_buffer(&req_buffer, "\r\n", 2);
if(result)
return result;
if(postsize > 0) {
- result = Curl_add_buffer(req_buffer, data->set.postfields,
+ result = Curl_add_buffer(&req_buffer, data->set.postfields,
(size_t)postsize);
if(result)
return result;
}
/* issue the request */
- result = Curl_add_buffer_send(req_buffer, conn,
+ result = Curl_add_buffer_send(&req_buffer, conn,
&data->info.request_size, 0, FIRSTSOCKET);
if(result) {
failf(data, "Failed sending RTSP request");
return result;
}
- Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, &http->readbytecount,
- putsize?FIRSTSOCKET:-1,
- putsize?&http->writebytecount:NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, -1, TRUE, putsize?FIRSTSOCKET:-1);
/* Increment the CSeq on success */
data->state.rtsp_next_client_CSeq++;
- if(http->writebytecount) {
+ if(data->req.writebytecount) {
/* if a request-body has been sent off, we make sure this progress is
noted properly */
- Curl_pgrsSetUploadCounter(data, http->writebytecount);
+ Curl_pgrsSetUploadCounter(data, data->req.writebytecount);
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
}
@@ -728,14 +725,29 @@ CURLcode rtp_client_write(struct connectdata *conn, char *ptr, size_t len)
struct Curl_easy *data = conn->data;
size_t wrote;
curl_write_callback writeit;
+ void *user_ptr;
if(len == 0) {
failf(data, "Cannot write a 0 size RTP packet.");
return CURLE_WRITE_ERROR;
}
- writeit = data->set.fwrite_rtp?data->set.fwrite_rtp:data->set.fwrite_func;
- wrote = writeit(ptr, 1, len, data->set.rtp_out);
+ /* If the user has configured CURLOPT_INTERLEAVEFUNCTION then use that
+ function and any configured CURLOPT_INTERLEAVEDATA to write out the RTP
+ data. Otherwise, use the CURLOPT_WRITEFUNCTION with the CURLOPT_WRITEDATA
+ pointer to write out the RTP data. */
+ if(data->set.fwrite_rtp) {
+ writeit = data->set.fwrite_rtp;
+ user_ptr = data->set.rtp_out;
+ }
+ else {
+ writeit = data->set.fwrite_func;
+ user_ptr = data->set.out;
+ }
+
+ Curl_set_in_callback(data, true);
+ wrote = writeit(ptr, 1, len, user_ptr);
+ Curl_set_in_callback(data, false);
if(CURL_WRITEFUNC_PAUSE == wrote) {
failf(data, "Cannot pause RTP");
diff --git a/Utilities/cmcurl/lib/rtsp.h b/Utilities/cmcurl/lib/rtsp.h
index 5a8d5556f..2f9cc32c8 100644
--- a/Utilities/cmcurl/lib/rtsp.h
+++ b/Utilities/cmcurl/lib/rtsp.h
@@ -25,13 +25,11 @@
extern const struct Curl_handler Curl_handler_rtsp;
-bool Curl_rtsp_connisdead(struct connectdata *check);
CURLcode Curl_rtsp_parseheader(struct connectdata *conn, char *header);
#else
/* disabled */
#define Curl_rtsp_parseheader(x,y) CURLE_NOT_BUILT_IN
-#define Curl_rtsp_connisdead(x) TRUE
#endif /* CURL_DISABLE_RTSP */
@@ -66,4 +64,3 @@ struct RTSP {
#endif /* HEADER_CURL_RTSP_H */
-
diff --git a/Utilities/cmcurl/lib/security.c b/Utilities/cmcurl/lib/security.c
index f4a876341..76951548d 100644
--- a/Utilities/cmcurl/lib/security.c
+++ b/Utilities/cmcurl/lib/security.c
@@ -7,10 +7,10 @@
* rewrite to work around the paragraph 2 in the BSD licenses as explained
* below.
*
- * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan
+ * Copyright (c) 1998, 1999, 2017 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
*
- * Copyright (C) 2001 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2001 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* All rights reserved.
*
@@ -50,9 +50,7 @@
#include <netdb.h>
#endif
-#ifdef HAVE_LIMITS_H
#include <limits.h>
-#endif
#include "urldata.h"
#include "curl_base64.h"
@@ -63,7 +61,9 @@
#include "strcase.h"
#include "warnless.h"
#include "strdup.h"
-/* The last #include file should be: */
+/* The last 3 #include files should be in this order */
+#include "curl_printf.h"
+#include "curl_memory.h"
#include "memdebug.h"
static const struct {
@@ -115,12 +115,12 @@ static char level_to_char(int level)
static int ftp_send_command(struct connectdata *conn, const char *message, ...)
{
int ftp_code;
- ssize_t nread=0;
+ ssize_t nread = 0;
va_list args;
char print_buffer[50];
va_start(args, message);
- vsnprintf(print_buffer, sizeof(print_buffer), message, args);
+ mvsnprintf(print_buffer, sizeof(print_buffer), message, args);
va_end(args);
if(Curl_ftpsend(conn, print_buffer)) {
@@ -142,7 +142,7 @@ socket_read(curl_socket_t fd, void *to, size_t len)
{
char *to_p = to;
CURLcode result;
- ssize_t nread;
+ ssize_t nread = 0;
while(len > 0) {
result = Curl_read_plain(fd, to_p, len, &nread);
@@ -151,7 +151,6 @@ socket_read(curl_socket_t fd, void *to, size_t len)
to_p += nread;
}
else {
- /* FIXME: We are doing a busy wait */
if(result == CURLE_AGAIN)
continue;
return result;
@@ -179,7 +178,6 @@ socket_write(struct connectdata *conn, curl_socket_t fd, const void *to,
to_p += written;
}
else {
- /* FIXME: We are doing a busy wait */
if(result == CURLE_AGAIN)
continue;
return result;
@@ -265,13 +263,11 @@ static ssize_t sec_recv(struct connectdata *conn, int sockindex,
total_read += bytes_read;
buffer += bytes_read;
}
- /* FIXME: Check for overflow */
return total_read;
}
/* Send |length| bytes from |from| to the |fd| socket taking care of encoding
and negociating with the server. |from| can be NULL. */
-/* FIXME: We don't check for errors nor report any! */
static void do_sec_send(struct connectdata *conn, curl_socket_t fd,
const char *from, int length)
{
@@ -392,7 +388,7 @@ int Curl_sec_read_msg(struct connectdata *conn, char *buffer,
if(conn->data->set.verbose) {
buf[decoded_len] = '\n';
- Curl_debug(conn->data, CURLINFO_HEADER_IN, buf, decoded_len + 1, conn);
+ Curl_debug(conn->data, CURLINFO_HEADER_IN, buf, decoded_len + 1);
}
buf[decoded_len] = '\0';
@@ -406,25 +402,21 @@ int Curl_sec_read_msg(struct connectdata *conn, char *buffer,
if(buf[decoded_len - 1] == '\n')
buf[decoded_len - 1] = '\0';
- /* FIXME: Is |buffer| length always greater than |decoded_len|? */
strcpy(buffer, buf);
free(buf);
return ret_code;
}
-/* FIXME: The error code returned here is never checked. */
static int sec_set_protection_level(struct connectdata *conn)
{
int code;
- char *pbsz;
- static unsigned int buffer_size = 1 << 20; /* 1048576 */
enum protection_level level = conn->request_data_prot;
DEBUGASSERT(level > PROT_NONE && level < PROT_LAST);
if(!conn->sec_complete) {
infof(conn->data, "Trying to change the protection level after the"
- "completion of the data exchange.\n");
+ " completion of the data exchange.\n");
return -1;
}
@@ -433,6 +425,9 @@ static int sec_set_protection_level(struct connectdata *conn)
return 0;
if(level) {
+ char *pbsz;
+ static unsigned int buffer_size = 1 << 20; /* 1048576 */
+
code = ftp_send_command(conn, "PBSZ %u", buffer_size);
if(code < 0)
return -1;
@@ -490,7 +485,7 @@ static CURLcode choose_mech(struct connectdata *conn)
tmp_allocation = realloc(conn->app_data, mech->size);
if(tmp_allocation == NULL) {
- failf(data, "Failed realloc of size %u", mech->size);
+ failf(data, "Failed realloc of size %zu", mech->size);
mech = NULL;
return CURLE_OUT_OF_MEMORY;
}
@@ -508,7 +503,6 @@ static CURLcode choose_mech(struct connectdata *conn)
infof(data, "Trying mechanism %s...\n", mech->name);
ret = ftp_send_command(conn, "AUTH %s", mech->name);
if(ret < 0)
- /* FIXME: This error is too generic but it is OK for now. */
return CURLE_COULDNT_CONNECT;
if(ret/100 != 3) {
@@ -575,7 +569,6 @@ Curl_sec_end(struct connectdata *conn)
conn->in_buffer.data = NULL;
conn->in_buffer.size = 0;
conn->in_buffer.index = 0;
- /* FIXME: Is this really needed? */
conn->in_buffer.eof_flag = 0;
}
conn->sec_complete = 0;
diff --git a/Utilities/cmcurl/lib/select.c b/Utilities/cmcurl/lib/select.c
index 443007227..6e7389015 100644
--- a/Utilities/cmcurl/lib/select.c
+++ b/Utilities/cmcurl/lib/select.c
@@ -51,7 +51,7 @@
#include "warnless.h"
/* Convenience local macros */
-#define ELAPSED_MS() (int)curlx_tvdiff(curlx_tvnow(), initial_tv)
+#define ELAPSED_MS() (int)Curl_timediff(Curl_now(), initial_tv)
int Curl_ack_eintr = 0;
#define ERROR_NOT_EINTR(error) (Curl_ack_eintr || error != EINTR)
@@ -78,9 +78,8 @@ int Curl_wait_ms(int timeout_ms)
#ifndef HAVE_POLL_FINE
struct timeval pending_tv;
#endif
- struct timeval initial_tv;
+ struct curltime initial_tv;
int pending_ms;
- int error;
#endif
int r = 0;
@@ -96,8 +95,9 @@ int Curl_wait_ms(int timeout_ms)
Sleep(timeout_ms);
#else
pending_ms = timeout_ms;
- initial_tv = curlx_tvnow();
+ initial_tv = Curl_now();
do {
+ int error;
#if defined(HAVE_POLL_FINE)
r = poll(NULL, 0, pending_ms);
#else
@@ -158,9 +158,8 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
fd_set fds_err;
curl_socket_t maxfd;
#endif
- struct timeval initial_tv = {0, 0};
+ struct curltime initial_tv = {0, 0};
int pending_ms = 0;
- int error;
int r;
int ret;
@@ -177,14 +176,14 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
return r;
}
- /* Avoid initial timestamp, avoid curlx_tvnow() call, when elapsed
+ /* Avoid initial timestamp, avoid Curl_now() call, when elapsed
time in this function does not need to be measured. This happens
when function is called with a zero timeout or a negative timeout
value indicating a blocking call should be performed. */
if(timeout_ms > 0) {
pending_ms = (int)timeout_ms;
- initial_tv = curlx_tvnow();
+ initial_tv = Curl_now();
}
#ifdef HAVE_POLL_FINE
@@ -210,6 +209,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
}
do {
+ int error;
if(timeout_ms < 0)
pending_ms = -1;
else if(!timeout_ms)
@@ -291,6 +291,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
do {
+ int error;
if(timeout_ms > 0) {
pending_tv.tv_sec = pending_ms / 1000;
pending_tv.tv_usec = (pending_ms % 1000) * 1000;
@@ -398,11 +399,10 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
fd_set fds_err;
curl_socket_t maxfd;
#endif
- struct timeval initial_tv = {0, 0};
+ struct curltime initial_tv = {0, 0};
bool fds_none = TRUE;
unsigned int i;
int pending_ms = 0;
- int error;
int r;
if(ufds) {
@@ -418,19 +418,20 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
return r;
}
- /* Avoid initial timestamp, avoid curlx_tvnow() call, when elapsed
+ /* Avoid initial timestamp, avoid Curl_now() call, when elapsed
time in this function does not need to be measured. This happens
when function is called with a zero timeout or a negative timeout
value indicating a blocking call should be performed. */
if(timeout_ms > 0) {
pending_ms = timeout_ms;
- initial_tv = curlx_tvnow();
+ initial_tv = Curl_now();
}
#ifdef HAVE_POLL_FINE
do {
+ int error;
if(timeout_ms < 0)
pending_ms = -1;
else if(!timeout_ms)
@@ -502,6 +503,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
do {
+ int error;
if(timeout_ms > 0) {
pending_tv.tv_sec = pending_ms / 1000;
pending_tv.tv_usec = (pending_ms % 1000) * 1000;
@@ -571,8 +573,8 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
*
* 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 tpf_select_libcurl(int maxfds, fd_set *reads, fd_set *writes,
+ fd_set *excepts, struct timeval *tv)
{
int rc;
diff --git a/Utilities/cmcurl/lib/select.h b/Utilities/cmcurl/lib/select.h
index 4ed5dd2f8..9a1ba45a7 100644
--- a/Utilities/cmcurl/lib/select.h
+++ b/Utilities/cmcurl/lib/select.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -36,7 +36,8 @@
#if !defined(HAVE_STRUCT_POLLFD) && \
!defined(HAVE_SYS_POLL_H) && \
- !defined(HAVE_POLL_H)
+ !defined(HAVE_POLL_H) && \
+ !defined(POLLIN)
#define POLLIN 0x01
#define POLLPRI 0x02
@@ -112,4 +113,3 @@ int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
#endif
#endif /* HEADER_CURL_SELECT_H */
-
diff --git a/Utilities/cmcurl/lib/sendf.c b/Utilities/cmcurl/lib/sendf.c
index 595c36177..5913ea406 100644
--- a/Utilities/cmcurl/lib/sendf.c
+++ b/Utilities/cmcurl/lib/sendf.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,6 +22,14 @@
#include "curl_setup.h"
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_LINUX_TCP_H
+#include <linux/tcp.h>
+#endif
+
#include <curl/curl.h>
#include "urldata.h"
@@ -29,6 +37,7 @@
#include "connect.h"
#include "vtls/vtls.h"
#include "ssh.h"
+#include "easyif.h"
#include "multiif.h"
#include "non-ascii.h"
#include "strerror.h"
@@ -63,7 +72,7 @@ static size_t convert_lineends(struct Curl_easy *data,
if(*startPtr == '\n') {
/* This block of incoming data starts with the
previous block's LF so get rid of it */
- memmove(startPtr, startPtr+1, size-1);
+ memmove(startPtr, startPtr + 1, size-1);
size--;
/* and it wasn't a bare CR but a CRLF conversion instead */
data->state.crlf_conversions++;
@@ -75,7 +84,7 @@ static size_t convert_lineends(struct Curl_easy *data,
inPtr = outPtr = memchr(startPtr, '\r', size);
if(inPtr) {
/* at least one CR, now look for CRLF */
- while(inPtr < (startPtr+size-1)) {
+ 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 */
@@ -98,7 +107,7 @@ static size_t convert_lineends(struct Curl_easy *data,
inPtr++;
} /* end of while loop */
- if(inPtr < startPtr+size) {
+ if(inPtr < startPtr + size) {
/* handle last byte */
if(*inPtr == '\r') {
/* deal with a CR at the end of the buffer */
@@ -112,7 +121,7 @@ static size_t convert_lineends(struct Curl_easy *data,
}
outPtr++;
}
- if(outPtr < startPtr+size)
+ if(outPtr < startPtr + size)
/* tidy up by null terminating the now shorter data */
*outPtr = '\0';
@@ -228,10 +237,21 @@ void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
size_t len;
char print_buffer[2048 + 1];
va_start(ap, fmt);
- vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
+ len = mvsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
+ /*
+ * Indicate truncation of the input by replacing the last 3 characters
+ * with "...", and transfer the newline over in case the format had one.
+ */
+ if(len >= sizeof(print_buffer)) {
+ len = strlen(fmt);
+ if(fmt[--len] == '\n')
+ msnprintf(print_buffer + (sizeof(print_buffer) - 5), 5, "...\n");
+ else
+ msnprintf(print_buffer + (sizeof(print_buffer) - 4), 4, "...");
+ }
va_end(ap);
len = strlen(print_buffer);
- Curl_debug(data, CURLINFO_TEXT, print_buffer, len, NULL);
+ Curl_debug(data, CURLINFO_TEXT, print_buffer, len);
}
}
@@ -241,25 +261,25 @@ void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
void Curl_failf(struct Curl_easy *data, const char *fmt, ...)
{
- va_list ap;
- size_t len;
- char error[CURL_ERROR_SIZE + 2];
- va_start(ap, fmt);
-
- vsnprintf(error, CURL_ERROR_SIZE, fmt, ap);
- len = strlen(error);
+ if(data->set.verbose || data->set.errorbuffer) {
+ va_list ap;
+ size_t len;
+ char error[CURL_ERROR_SIZE + 2];
+ va_start(ap, fmt);
+ mvsnprintf(error, CURL_ERROR_SIZE, fmt, ap);
+ len = strlen(error);
- if(data->set.errorbuffer && !data->state.errorbuf) {
- strcpy(data->set.errorbuffer, error);
- data->state.errorbuf = TRUE; /* wrote error string */
- }
- if(data->set.verbose) {
- error[len] = '\n';
- error[++len] = '\0';
- Curl_debug(data, CURLINFO_TEXT, error, len, NULL);
+ if(data->set.errorbuffer && !data->state.errorbuf) {
+ strcpy(data->set.errorbuffer, error);
+ data->state.errorbuf = TRUE; /* wrote error string */
+ }
+ if(data->set.verbose) {
+ error[len] = '\n';
+ error[++len] = '\0';
+ Curl_debug(data, CURLINFO_TEXT, error, len);
+ }
+ va_end(ap);
}
-
- va_end(ap);
}
/* Curl_sendf() sends formatted data to the server */
@@ -279,7 +299,7 @@ CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn,
if(!s)
return CURLE_OUT_OF_MEMORY; /* failure */
- bytes_written=0;
+ bytes_written = 0;
write_len = strlen(s);
sptr = s;
@@ -291,7 +311,7 @@ CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn,
break;
if(data->set.verbose)
- Curl_debug(data, CURLINFO_DATA_OUT, sptr, (size_t)bytes_written, conn);
+ Curl_debug(data, CURLINFO_DATA_OUT, sptr, (size_t)bytes_written);
if((size_t)bytes_written != write_len) {
/* if not all was written at once, we must advance the pointer, decrease
@@ -360,7 +380,7 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num,
available. */
pre_receive_plain(conn, num);
-#ifdef MSG_FASTOPEN /* Linux */
+#if defined(MSG_FASTOPEN) && !defined(TCP_FASTOPEN_CONNECT) /* Linux */
if(conn->bits.tcp_fastopen) {
bytes_written = sendto(sockfd, mem, len, MSG_FASTOPEN,
conn->ip_addr->ai_addr, conn->ip_addr->ai_addrlen);
@@ -380,19 +400,20 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num,
(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
+ due to its inability to send off data without blocking. We therefore
treat both error codes the same here */
(EWOULDBLOCK == err) || (EAGAIN == err) || (EINTR == err) ||
(EINPROGRESS == err)
#endif
) {
/* this is just a case of EWOULDBLOCK */
- bytes_written=0;
+ bytes_written = 0;
*code = CURLE_AGAIN;
}
else {
+ char buffer[STRERROR_LEN];
failf(conn->data, "Send failure: %s",
- Curl_strerror(conn, err));
+ Curl_strerror(err, buffer, sizeof(buffer)));
conn->data->state.os_errno = err;
*code = CURLE_SEND_ERROR;
}
@@ -447,7 +468,7 @@ ssize_t Curl_recv_plain(struct connectdata *conn, int num, char *buf,
(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
+ due to its inability to send off data without blocking. We therefore
treat both error codes the same here */
(EWOULDBLOCK == err) || (EAGAIN == err) || (EINTR == err)
#endif
@@ -456,8 +477,9 @@ ssize_t Curl_recv_plain(struct connectdata *conn, int num, char *buf,
*code = CURLE_AGAIN;
}
else {
+ char buffer[STRERROR_LEN];
failf(conn->data, "Recv failure: %s",
- Curl_strerror(conn, err));
+ Curl_strerror(err, buffer, sizeof(buffer)));
conn->data->state.os_errno = err;
*code = CURLE_RECV_ERROR;
}
@@ -480,7 +502,7 @@ static CURLcode pausewrite(struct Curl_easy *data,
bool newtype = TRUE;
if(s->tempcount) {
- for(i=0; i< s->tempcount; i++) {
+ for(i = 0; i< s->tempcount; i++) {
if(s->tempwrite[i].type == type) {
/* data for this type exists */
newtype = FALSE;
@@ -532,18 +554,20 @@ static CURLcode pausewrite(struct Curl_easy *data,
}
-/* Curl_client_chop_write() writes chunks of data not larger than
- * CURL_MAX_WRITE_SIZE via client write callback(s) and
- * takes care of pause requests from the callbacks.
+/* chop_write() writes chunks of data not larger than CURL_MAX_WRITE_SIZE via
+ * client write callback(s) and takes care of pause requests from the
+ * callbacks.
*/
-CURLcode Curl_client_chop_write(struct connectdata *conn,
- int type,
- char *ptr,
- size_t len)
+static CURLcode chop_write(struct connectdata *conn,
+ int type,
+ char *optr,
+ size_t olen)
{
struct Curl_easy *data = conn->data;
curl_write_callback writeheader = NULL;
curl_write_callback writebody = NULL;
+ char *ptr = optr;
+ size_t len = olen;
if(!len)
return CURLE_OK;
@@ -571,7 +595,10 @@ CURLcode Curl_client_chop_write(struct connectdata *conn,
size_t chunklen = len <= CURL_MAX_WRITE_SIZE? len: CURL_MAX_WRITE_SIZE;
if(writebody) {
- size_t wrote = writebody(ptr, 1, chunklen, data->set.out);
+ size_t wrote;
+ Curl_set_in_callback(data, true);
+ wrote = writebody(ptr, 1, chunklen, data->set.out);
+ Curl_set_in_callback(data, false);
if(CURL_WRITEFUNC_PAUSE == wrote) {
if(conn->handler->flags & PROTOPT_NONETWORK) {
@@ -589,25 +616,30 @@ CURLcode Curl_client_chop_write(struct connectdata *conn,
}
}
- if(writeheader) {
- size_t wrote = writeheader(ptr, 1, chunklen, data->set.writeheader);
-
- if(CURL_WRITEFUNC_PAUSE == wrote)
- /* here we pass in the HEADER bit only since if this was body as well
- then it was passed already and clearly that didn't trigger the
- pause, so this is saved for later with the HEADER bit only */
- return pausewrite(data, CLIENTWRITE_HEADER, ptr, len);
-
- if(wrote != chunklen) {
- failf(data, "Failed writing header");
- return CURLE_WRITE_ERROR;
- }
- }
-
ptr += chunklen;
len -= chunklen;
}
+ if(writeheader) {
+ size_t wrote;
+ ptr = optr;
+ len = olen;
+ Curl_set_in_callback(data, true);
+ wrote = writeheader(ptr, 1, len, data->set.writeheader);
+ Curl_set_in_callback(data, false);
+
+ if(CURL_WRITEFUNC_PAUSE == wrote)
+ /* here we pass in the HEADER bit only since if this was body as well
+ then it was passed already and clearly that didn't trigger the
+ pause, so this is saved for later with the HEADER bit only */
+ return pausewrite(data, CLIENTWRITE_HEADER, ptr, len);
+
+ if(wrote != len) {
+ failf(data, "Failed writing header");
+ return CURLE_WRITE_ERROR;
+ }
+ }
+
return CURLE_OK;
}
@@ -649,7 +681,7 @@ CURLcode Curl_client_write(struct connectdata *conn,
#endif /* CURL_DO_LINEEND_CONV */
}
- return Curl_client_chop_write(conn, type, ptr, len);
+ return chop_write(conn, type, ptr, len);
}
CURLcode Curl_read_plain(curl_socket_t sockfd,
@@ -695,59 +727,28 @@ CURLcode Curl_read(struct connectdata *conn, /* connection data */
char *buffertofill = NULL;
struct Curl_easy *data = conn->data;
- /* if HTTP/1 pipelining is both wanted and possible */
- bool pipelining = Curl_pipeline_wanted(data->multi, CURLPIPE_HTTP1) &&
- (conn->bundle->multiuse == BUNDLE_PIPELINING);
-
/* 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 = CURLMIN(conn->buf_len - conn->read_pos,
- sizerequested);
+ *n = 0; /* reset amount to zero */
- /* 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 = CURLMIN(sizerequested, MASTERBUF_SIZE);
- buffertofill = conn->master_buffer;
- }
- else {
- bytesfromsocket = CURLMIN(sizerequested, (size_t)data->set.buffer_size);
- buffertofill = buf;
- }
+ bytesfromsocket = CURLMIN(sizerequested, (size_t)data->set.buffer_size);
+ buffertofill = buf;
nread = conn->recv[num](conn, num, buffertofill, bytesfromsocket, &result);
if(nread < 0)
return result;
- 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 Curl_easy *data, curl_infotype type,
- char *ptr, size_t size)
+int Curl_debug(struct Curl_easy *data, curl_infotype type,
+ char *ptr, size_t size)
{
static const char s_infotype[CURLINFO_END][3] = {
"* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
@@ -790,8 +791,11 @@ static int showit(struct Curl_easy *data, curl_infotype type,
}
#endif /* CURL_DOES_CONVERSIONS */
- if(data->set.fdebug)
+ if(data->set.fdebug) {
+ Curl_set_in_callback(data, true);
rc = (*data->set.fdebug)(data, type, ptr, size, data->set.debugdata);
+ Curl_set_in_callback(data, false);
+ }
else {
switch(type) {
case CURLINFO_TEXT:
@@ -815,41 +819,3 @@ static int showit(struct Curl_easy *data, curl_infotype type,
#endif
return rc;
}
-
-int Curl_debug(struct Curl_easy *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";
- /* FALLTHROUGH */
- case CURLINFO_DATA_IN:
- t = "from";
- break;
- case CURLINFO_HEADER_OUT:
- w = "Header";
- /* FALLTHROUGH */
- 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/lib/sendf.h b/Utilities/cmcurl/lib/sendf.h
index fbe4f99c8..c68b017da 100644
--- a/Utilities/cmcurl/lib/sendf.h
+++ b/Utilities/cmcurl/lib/sendf.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -36,7 +36,7 @@ void Curl_failf(struct Curl_easy *, const char *fmt, ...);
#elif defined(HAVE_VARIADIC_MACROS_GCC)
#define infof(x...) Curl_nop_stmt
#else
-#define infof (void)
+#error "missing VARIADIC macro define, fix and rebuild!"
#endif
#else /* CURL_DISABLE_VERBOSE_STRINGS */
@@ -51,8 +51,6 @@ void Curl_failf(struct Curl_easy *, const char *fmt, ...);
#define CLIENTWRITE_HEADER (1<<1)
#define CLIENTWRITE_BOTH (CLIENTWRITE_BODY|CLIENTWRITE_HEADER)
-CURLcode Curl_client_chop_write(struct connectdata *conn, int type, char *ptr,
- size_t len) WARN_UNUSED_RESULT;
CURLcode Curl_client_write(struct connectdata *conn, int type, char *ptr,
size_t len) WARN_UNUSED_RESULT;
@@ -86,9 +84,8 @@ CURLcode Curl_write_plain(struct connectdata *conn,
ssize_t *written);
/* the function used to output verbose information */
-int Curl_debug(struct Curl_easy *handle, curl_infotype type,
- char *data, size_t size,
- struct connectdata *conn);
+int Curl_debug(struct Curl_easy *data, curl_infotype type,
+ char *ptr, size_t size);
#endif /* HEADER_CURL_SENDF_H */
diff --git a/Utilities/cmcurl/lib/share.c b/Utilities/cmcurl/lib/share.c
index 5b3957fcf..3d5108610 100644
--- a/Utilities/cmcurl/lib/share.c
+++ b/Utilities/cmcurl/lib/share.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -25,6 +25,7 @@
#include <curl/curl.h>
#include "urldata.h"
#include "share.h"
+#include "psl.h"
#include "vtls/vtls.h"
#include "curl_memory.h"
@@ -102,6 +103,14 @@ curl_share_setopt(struct Curl_share *share, CURLSHoption option, ...)
break;
case CURL_LOCK_DATA_CONNECT: /* not supported (yet) */
+ if(Curl_conncache_init(&share->conn_cache, 103))
+ res = CURLSHE_NOMEM;
+ break;
+
+ case CURL_LOCK_DATA_PSL:
+#ifndef USE_LIBPSL
+ res = CURLSHE_NOT_BUILT_IN;
+#endif
break;
default:
@@ -186,6 +195,8 @@ curl_share_cleanup(struct Curl_share *share)
return CURLSHE_IN_USE;
}
+ Curl_conncache_close_all_connections(&share->conn_cache);
+ Curl_conncache_destroy(&share->conn_cache);
Curl_hash_destroy(&share->hostcache);
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
@@ -201,6 +212,8 @@ curl_share_cleanup(struct Curl_share *share)
}
#endif
+ Curl_psl_destroy(&share->psl);
+
if(share->unlockfunc)
share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata);
free(share);
diff --git a/Utilities/cmcurl/lib/share.h b/Utilities/cmcurl/lib/share.h
index c039a16cb..a7dea41ad 100644
--- a/Utilities/cmcurl/lib/share.h
+++ b/Utilities/cmcurl/lib/share.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -25,7 +25,9 @@
#include "curl_setup.h"
#include <curl/curl.h>
#include "cookie.h"
+#include "psl.h"
#include "urldata.h"
+#include "conncache.h"
/* SalfordC says "A structure member may not be volatile". Hence:
*/
@@ -43,11 +45,14 @@ struct Curl_share {
curl_lock_function lockfunc;
curl_unlock_function unlockfunc;
void *clientdata;
-
+ struct conncache conn_cache;
struct curl_hash hostcache;
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
struct CookieInfo *cookies;
#endif
+#ifdef USE_LIBPSL
+ struct PslCache psl;
+#endif
struct curl_ssl_session *sslsession;
size_t max_ssl_sessions;
diff --git a/Utilities/cmcurl/lib/sigpipe.h b/Utilities/cmcurl/lib/sigpipe.h
index 800f9d3b4..3960a139d 100644
--- a/Utilities/cmcurl/lib/sigpipe.h
+++ b/Utilities/cmcurl/lib/sigpipe.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -23,7 +23,8 @@
***************************************************************************/
#include "curl_setup.h"
-#if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGACTION) && defined(USE_OPENSSL)
+#if defined(HAVE_SIGNAL_H) && defined(HAVE_SIGACTION) && \
+ (defined(USE_OPENSSL) || defined(USE_MBEDTLS))
#include <signal.h>
struct sigpipe_ignore {
diff --git a/Utilities/cmcurl/lib/slist.c b/Utilities/cmcurl/lib/slist.c
index e5adc0e71..392b84d13 100644
--- a/Utilities/cmcurl/lib/slist.c
+++ b/Utilities/cmcurl/lib/slist.c
@@ -142,4 +142,3 @@ void curl_slist_free_all(struct curl_slist *list)
item = next;
} while(next);
}
-
diff --git a/Utilities/cmcurl/lib/slist.h b/Utilities/cmcurl/lib/slist.h
index b3f498c35..d73dbf672 100644
--- a/Utilities/cmcurl/lib/slist.h
+++ b/Utilities/cmcurl/lib/slist.h
@@ -37,4 +37,3 @@ struct curl_slist *Curl_slist_append_nodup(struct curl_slist *list,
char *data);
#endif /* HEADER_CURL_SLIST_H */
-
diff --git a/Utilities/cmcurl/lib/smb.c b/Utilities/cmcurl/lib/smb.c
index 5b1ffa9b7..76c99a230 100644
--- a/Utilities/cmcurl/lib/smb.c
+++ b/Utilities/cmcurl/lib/smb.c
@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2014, Bill Nagel <wnagel@tycoint.com>, Exacq Technologies
- * Copyright (C) 2016-2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2016-2018, 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
@@ -34,7 +34,7 @@
#include <process.h>
#ifdef CURL_WINDOWS_APP
#define getpid GetCurrentProcessId
-#else
+#elif !defined(MSDOS)
#define getpid _getpid
#endif
#endif
@@ -59,6 +59,7 @@
static CURLcode smb_setup_connection(struct connectdata *conn);
static CURLcode smb_connect(struct connectdata *conn, bool *done);
static CURLcode smb_connection_state(struct connectdata *conn, bool *done);
+static CURLcode smb_do(struct connectdata *conn, bool *done);
static CURLcode smb_request_state(struct connectdata *conn, bool *done);
static CURLcode smb_done(struct connectdata *conn, CURLcode status,
bool premature);
@@ -73,7 +74,7 @@ static CURLcode smb_parse_url_path(struct connectdata *conn);
const struct Curl_handler Curl_handler_smb = {
"SMB", /* scheme */
smb_setup_connection, /* setup_connection */
- ZERO_NULL, /* do_it */
+ smb_do, /* do_it */
smb_done, /* done */
ZERO_NULL, /* do_more */
smb_connect, /* connect_it */
@@ -85,6 +86,7 @@ const struct Curl_handler Curl_handler_smb = {
ZERO_NULL, /* perform_getsock */
smb_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_SMB, /* defport */
CURLPROTO_SMB, /* protocol */
PROTOPT_NONE /* flags */
@@ -97,7 +99,7 @@ const struct Curl_handler Curl_handler_smb = {
const struct Curl_handler Curl_handler_smbs = {
"SMBS", /* scheme */
smb_setup_connection, /* setup_connection */
- ZERO_NULL, /* do_it */
+ smb_do, /* do_it */
smb_done, /* done */
ZERO_NULL, /* do_more */
smb_connect, /* connect_it */
@@ -109,6 +111,7 @@ const struct Curl_handler Curl_handler_smbs = {
ZERO_NULL, /* perform_getsock */
smb_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_SMBS, /* defport */
CURLPROTO_SMBS, /* protocol */
PROTOPT_SSL /* flags */
@@ -144,19 +147,12 @@ static unsigned int smb_swap32(unsigned int x)
((x >> 24) & 0xff);
}
-#ifdef HAVE_LONGLONG
-static unsigned long long smb_swap64(unsigned long long x)
+static curl_off_t smb_swap64(curl_off_t x)
{
- return ((unsigned long long) smb_swap32((unsigned int) x) << 32) |
+ return ((curl_off_t) smb_swap32((unsigned int) x) << 32) |
smb_swap32((unsigned int) (x >> 32));
}
-#else
-static unsigned __int64 smb_swap64(unsigned __int64 x)
-{
- return ((unsigned __int64) smb_swap32((unsigned int) x) << 32) |
- smb_swap32((unsigned int) (x >> 32));
-}
-#endif
+
#else
# define smb_swap16(x) (x)
# define smb_swap32(x) (x)
@@ -178,7 +174,6 @@ enum smb_req_state {
/* SMB request data */
struct smb_request {
enum smb_req_state state;
- char *share;
char *path;
unsigned short tid; /* Even if we connect to the same tree as another */
unsigned short fid; /* request, the tid will be different */
@@ -187,7 +182,7 @@ struct smb_request {
static void conn_state(struct connectdata *conn, enum smb_conn_state newstate)
{
- struct smb_conn *smb = &conn->proto.smbc;
+ struct smb_conn *smbc = &conn->proto.smbc;
#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
/* For debug purposes */
static const char * const names[] = {
@@ -199,12 +194,12 @@ static void conn_state(struct connectdata *conn, enum smb_conn_state newstate)
/* LAST */
};
- if(smb->state != newstate)
+ if(smbc->state != newstate)
infof(conn->data, "SMB conn %p state change from %s to %s\n",
- (void *)smb, names[smb->state], names[newstate]);
+ (void *)smbc, names[smbc->state], names[newstate]);
#endif
- smb->state = newstate;
+ smbc->state = newstate;
}
static void request_state(struct connectdata *conn,
@@ -233,6 +228,8 @@ static void request_state(struct connectdata *conn,
req->state = newstate;
}
+/* this should setup things in the connection, not in the easy
+ handle */
static CURLcode smb_setup_connection(struct connectdata *conn)
{
struct smb_request *req;
@@ -258,7 +255,6 @@ static CURLcode smb_connect(struct connectdata *conn, bool *done)
return CURLE_LOGIN_DENIED;
/* Initialize the connection state */
- memset(smbc, 0, sizeof(*smbc));
smbc->state = SMB_CONNECTING;
smbc->recv_buf = malloc(MAX_MESSAGE_SIZE);
if(!smbc->recv_buf)
@@ -371,7 +367,7 @@ static CURLcode smb_send(struct connectdata *conn, ssize_t len,
ssize_t bytes_written;
CURLcode result;
- result = Curl_write(conn, FIRSTSOCKET, conn->data->state.uploadbuffer,
+ result = Curl_write(conn, FIRSTSOCKET, conn->data->state.ulbuf,
len, &bytes_written);
if(result)
return result;
@@ -397,7 +393,7 @@ static CURLcode smb_flush(struct connectdata *conn)
return CURLE_OK;
result = Curl_write(conn, FIRSTSOCKET,
- conn->data->state.uploadbuffer + smbc->sent,
+ conn->data->state.ulbuf + smbc->sent,
len, &bytes_written);
if(result)
return result;
@@ -413,9 +409,12 @@ static CURLcode smb_flush(struct connectdata *conn)
static CURLcode smb_send_message(struct connectdata *conn, unsigned char cmd,
const void *msg, size_t msg_len)
{
- smb_format_message(conn, (struct smb_header *)conn->data->state.uploadbuffer,
+ CURLcode result = Curl_get_upload_buffer(conn->data);
+ if(result)
+ return result;
+ smb_format_message(conn, (struct smb_header *)conn->data->state.ulbuf,
cmd, msg_len);
- memcpy(conn->data->state.uploadbuffer + sizeof(struct smb_header),
+ memcpy(conn->data->state.ulbuf + sizeof(struct smb_header),
msg, msg_len);
return smb_send(conn, sizeof(struct smb_header) + msg_len, 0);
@@ -480,11 +479,11 @@ static CURLcode smb_send_setup(struct connectdata *conn)
static CURLcode smb_send_tree_connect(struct connectdata *conn)
{
- struct smb_request *req = conn->data->req.protop;
struct smb_tree_connect msg;
+ struct smb_conn *smbc = &conn->proto.smbc;
char *p = msg.bytes;
- size_t byte_count = strlen(conn->host.name) + strlen(req->share);
+ size_t byte_count = strlen(conn->host.name) + strlen(smbc->share);
byte_count += strlen(SERVICENAME) + 5; /* 2 nulls and 3 backslashes */
if(byte_count > sizeof(msg.bytes))
return CURLE_FILESIZE_EXCEEDED;
@@ -496,7 +495,7 @@ static CURLcode smb_send_tree_connect(struct connectdata *conn)
MSGCAT("\\\\");
MSGCAT(conn->host.name);
MSGCAT("\\");
- MSGCATNULL(req->share);
+ MSGCATNULL(smbc->share);
MSGCATNULL(SERVICENAME); /* Match any type of service */
byte_count = p - msg.bytes;
msg.byte_count = smb_swap16((unsigned short)byte_count);
@@ -576,11 +575,15 @@ static CURLcode smb_send_read(struct connectdata *conn)
static CURLcode smb_send_write(struct connectdata *conn)
{
- struct smb_write *msg = (struct smb_write *)conn->data->state.uploadbuffer;
+ struct smb_write *msg;
struct smb_request *req = conn->data->req.protop;
curl_off_t offset = conn->data->req.offset;
-
curl_off_t upload_size = conn->data->req.size - conn->data->req.bytecount;
+ CURLcode result = Curl_get_upload_buffer(conn->data);
+ if(result)
+ return result;
+ msg = (struct smb_write *)conn->data->state.ulbuf;
+
if(upload_size >= MAX_PAYLOAD_SIZE - 1) /* There is one byte of padding */
upload_size = MAX_PAYLOAD_SIZE - 1;
@@ -607,9 +610,10 @@ static CURLcode smb_send_and_recv(struct connectdata *conn, void **msg)
/* Check if there is data in the transfer buffer */
if(!smbc->send_size && smbc->upload_size) {
- int nread = smbc->upload_size > UPLOAD_BUFSIZE ? UPLOAD_BUFSIZE :
- (int) smbc->upload_size;
- conn->data->req.upload_fromhere = conn->data->state.uploadbuffer;
+ size_t nread = smbc->upload_size > conn->data->set.upload_buffer_size ?
+ conn->data->set.upload_buffer_size :
+ smbc->upload_size;
+ conn->data->req.upload_fromhere = conn->data->state.ulbuf;
result = Curl_fillreadbuffer(conn, nread, &nread);
if(result && result != CURLE_AGAIN)
return result;
@@ -646,7 +650,7 @@ static CURLcode smb_connection_state(struct connectdata *conn, bool *done)
if(smbc->state == SMB_CONNECTING) {
#ifdef USE_SSL
if((conn->handler->flags & PROTOPT_SSL)) {
- bool ssl_done;
+ bool ssl_done = FALSE;
result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &ssl_done);
if(result && result != CURLE_AGAIN)
return result;
@@ -713,6 +717,24 @@ static CURLcode smb_connection_state(struct connectdata *conn, bool *done)
return CURLE_OK;
}
+/*
+ * Convert a timestamp from the Windows world (100 nsec units from 1 Jan 1601)
+ * to Posix time. Cap the output to fit within a time_t.
+ */
+static void get_posix_time(time_t *out, curl_off_t timestamp)
+{
+ timestamp -= 116444736000000000;
+ timestamp /= 10000000;
+#if SIZEOF_TIME_T < SIZEOF_CURL_OFF_T
+ if(timestamp > TIME_T_MAX)
+ *out = TIME_T_MAX;
+ else if(timestamp < TIME_T_MIN)
+ *out = TIME_T_MIN;
+ else
+#endif
+ *out = (time_t) timestamp;
+}
+
static CURLcode smb_request_state(struct connectdata *conn, bool *done)
{
struct smb_request *req = conn->data->req.protop;
@@ -723,6 +745,7 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done)
unsigned short off;
CURLcode result;
void *msg = NULL;
+ const struct smb_nt_create_response *smb_m;
/* Start the request */
if(req->state == SMB_REQUESTING) {
@@ -765,7 +788,8 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done)
next_state = SMB_TREE_DISCONNECT;
break;
}
- req->fid = smb_swap16(((struct smb_nt_create_response *)msg)->fid);
+ smb_m = (const struct smb_nt_create_response*) msg;
+ req->fid = smb_swap16(smb_m->fid);
conn->data->req.offset = 0;
if(conn->data->set.upload) {
conn->data->req.size = conn->data->state.infilesize;
@@ -773,10 +797,18 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done)
next_state = SMB_UPLOAD;
}
else {
- conn->data->req.size =
- smb_swap64(((struct smb_nt_create_response *)msg)->end_of_file);
- Curl_pgrsSetDownloadSize(conn->data, conn->data->req.size);
- next_state = SMB_DOWNLOAD;
+ smb_m = (const struct smb_nt_create_response*) msg;
+ conn->data->req.size = smb_swap64(smb_m->end_of_file);
+ if(conn->data->req.size < 0) {
+ req->result = CURLE_WEIRD_SERVER_REPLY;
+ next_state = SMB_CLOSE;
+ }
+ else {
+ Curl_pgrsSetDownloadSize(conn->data, conn->data->req.size);
+ if(conn->data->set.get_filetime)
+ get_posix_time(&conn->data->info.filetime, smb_m->last_change_time);
+ next_state = SMB_DOWNLOAD;
+ }
}
break;
@@ -887,48 +919,40 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done)
static CURLcode smb_done(struct connectdata *conn, CURLcode status,
bool premature)
{
- struct smb_request *req = conn->data->req.protop;
-
(void) premature;
-
- Curl_safefree(req->share);
Curl_safefree(conn->data->req.protop);
-
return status;
}
static CURLcode smb_disconnect(struct connectdata *conn, bool dead)
{
struct smb_conn *smbc = &conn->proto.smbc;
- struct smb_request *req = conn->data->req.protop;
-
(void) dead;
-
+ Curl_safefree(smbc->share);
Curl_safefree(smbc->domain);
Curl_safefree(smbc->recv_buf);
-
- /* smb_done is not always called, so cleanup the request */
- if(req) {
- Curl_safefree(req->share);
- }
-
return CURLE_OK;
}
static int smb_getsock(struct connectdata *conn, curl_socket_t *socks,
int numsocks)
{
- struct smb_conn *smbc = &conn->proto.smbc;
-
if(!numsocks)
return GETSOCK_BLANK;
socks[0] = conn->sock[FIRSTSOCKET];
+ return GETSOCK_READSOCK(0) | GETSOCK_WRITESOCK(0);
+}
- if(smbc->send_size || smbc->upload_size)
- return GETSOCK_WRITESOCK(0);
+static CURLcode smb_do(struct connectdata *conn, bool *done)
+{
+ struct smb_conn *smbc = &conn->proto.smbc;
- return GETSOCK_READSOCK(0);
+ *done = FALSE;
+ if(smbc->share) {
+ return CURLE_OK;
+ }
+ return CURLE_URL_MALFORMAT;
}
static CURLcode smb_parse_url_path(struct connectdata *conn)
@@ -936,30 +960,28 @@ static CURLcode smb_parse_url_path(struct connectdata *conn)
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
struct smb_request *req = data->req.protop;
+ struct smb_conn *smbc = &conn->proto.smbc;
char *path;
char *slash;
/* URL decode the path */
- result = Curl_urldecode(data, data->state.path, 0, &path, NULL, TRUE);
+ result = Curl_urldecode(data, data->state.up.path, 0, &path, NULL, TRUE);
if(result)
return result;
/* Parse the path for the share */
- req->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path);
- if(!req->share) {
- free(path);
-
+ smbc->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path);
+ free(path);
+ if(!smbc->share)
return CURLE_OUT_OF_MEMORY;
- }
- slash = strchr(req->share, '/');
+ slash = strchr(smbc->share, '/');
if(!slash)
- slash = strchr(req->share, '\\');
+ slash = strchr(smbc->share, '\\');
/* The share must be present */
if(!slash) {
- free(path);
-
+ Curl_safefree(smbc->share);
return CURLE_URL_MALFORMAT;
}
@@ -967,13 +989,11 @@ static CURLcode smb_parse_url_path(struct connectdata *conn)
backslashes */
*slash++ = 0;
req->path = slash;
+
for(; *slash; slash++) {
if(*slash == '/')
*slash = '\\';
}
-
- free(path);
-
return CURLE_OK;
}
diff --git a/Utilities/cmcurl/lib/smb.h b/Utilities/cmcurl/lib/smb.h
index 1a4f66e5a..9ce6b5615 100644
--- a/Utilities/cmcurl/lib/smb.h
+++ b/Utilities/cmcurl/lib/smb.h
@@ -8,6 +8,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2014, Bill Nagel <wnagel@tycoint.com>, Exacq Technologies
+ * Copyright (C) 2018, 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
@@ -34,6 +35,7 @@ struct smb_conn {
enum smb_conn_state state;
char *user;
char *domain;
+ char *share;
unsigned char challenge[8];
unsigned int session_key;
unsigned short uid;
@@ -165,11 +167,7 @@ struct smb_nt_create {
unsigned int flags;
unsigned int root_fid;
unsigned int access;
-#ifdef HAVE_LONGLONG
- unsigned long long allocation_size;
-#else
- unsigned __int64 allocation_size;
-#endif
+ curl_off_t allocation_size;
unsigned int ext_file_attributes;
unsigned int share_access;
unsigned int create_disposition;
@@ -187,25 +185,15 @@ struct smb_nt_create_response {
unsigned char op_lock_level;
unsigned short fid;
unsigned int create_disposition;
-#ifdef HAVE_LONGLONG
- unsigned long long create_time;
- unsigned long long last_access_time;
- unsigned long long last_write_time;
- unsigned long long last_change_time;
-#else
- unsigned __int64 create_time;
- unsigned __int64 last_access_time;
- unsigned __int64 last_write_time;
- unsigned __int64 last_change_time;
-#endif
+
+ curl_off_t create_time;
+ curl_off_t last_access_time;
+ curl_off_t last_write_time;
+ curl_off_t last_change_time;
unsigned int ext_file_attributes;
-#ifdef HAVE_LONGLONG
- unsigned long long allocation_size;
- unsigned long long end_of_file;
-#else
- unsigned __int64 allocation_size;
- unsigned __int64 end_of_file;
-#endif
+ curl_off_t allocation_size;
+ curl_off_t end_of_file;
+
} PACK;
struct smb_read {
diff --git a/Utilities/cmcurl/lib/smtp.c b/Utilities/cmcurl/lib/smtp.c
index fe064cb2f..4a3462b84 100644
--- a/Utilities/cmcurl/lib/smtp.c
+++ b/Utilities/cmcurl/lib/smtp.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -28,6 +28,7 @@
* RFC4954 SMTP Authentication
* RFC5321 SMTP protocol
* RFC6749 OAuth 2.0 Authorization Framework
+ * RFC8314 Use of TLS for Email Submission and Access
* Draft SMTP URL Interface <draft-earhart-url-smtp-00.txt>
* Draft LOGIN SASL Mechanism <draft-murchison-sasl-login-00.txt>
*
@@ -67,6 +68,7 @@
#include "transfer.h"
#include "escape.h"
#include "http.h" /* for HTTP proxy tunnel stuff */
+#include "mime.h"
#include "socks.h"
#include "smtp.h"
#include "strtoofft.h"
@@ -124,6 +126,7 @@ const struct Curl_handler Curl_handler_smtp = {
ZERO_NULL, /* perform_getsock */
smtp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_SMTP, /* defport */
CURLPROTO_SMTP, /* protocol */
PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */
@@ -150,6 +153,7 @@ const struct Curl_handler Curl_handler_smtps = {
ZERO_NULL, /* perform_getsock */
smtp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_SMTPS, /* defport */
CURLPROTO_SMTPS, /* protocol */
PROTOPT_CLOSEACTION | PROTOPT_SSL
@@ -157,58 +161,6 @@ const struct Curl_handler Curl_handler_smtps = {
};
#endif
-#ifndef CURL_DISABLE_HTTP
-/*
- * HTTP-proxyed SMTP protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_smtp_proxy = {
- "SMTP", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_SMTP, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-
-#ifdef USE_SSL
-/*
- * HTTP-proxyed SMTPS protocol handler.
- */
-
-static const struct Curl_handler Curl_handler_smtps_proxy = {
- "SMTPS", /* scheme */
- Curl_http_setup_conn, /* setup_connection */
- Curl_http, /* do_it */
- Curl_http_done, /* done */
- ZERO_NULL, /* do_more */
- ZERO_NULL, /* connect_it */
- ZERO_NULL, /* connecting */
- ZERO_NULL, /* doing */
- ZERO_NULL, /* proto_getsock */
- ZERO_NULL, /* doing_getsock */
- ZERO_NULL, /* domore_getsock */
- ZERO_NULL, /* perform_getsock */
- ZERO_NULL, /* disconnect */
- ZERO_NULL, /* readwrite */
- PORT_SMTPS, /* defport */
- CURLPROTO_HTTP, /* protocol */
- PROTOPT_NONE /* flags */
-};
-#endif
-#endif
-
/* SASL parameters for the smtp protocol */
static const struct SASLproto saslsmtp = {
"smtp", /* The service name */
@@ -256,8 +208,12 @@ static bool smtp_endofresp(struct connectdata *conn, char *line, size_t len,
Section 4. Examples of RFC-4954 but some e-mail servers ignore this and
only send the response code instead as per Section 4.2. */
if(line[3] == ' ' || len == 5) {
+ char tmpline[6];
+
result = TRUE;
- *resp = curlx_sltosi(strtol(line, NULL, 10));
+ memset(tmpline, '\0', sizeof(tmpline));
+ memcpy(tmpline, line, (len == 5 ? 5 : 3));
+ *resp = curlx_sltosi(strtol(tmpline, NULL, 10));
/* Make sure real server never sends internal value */
if(*resp == 1)
@@ -281,23 +237,30 @@ static bool smtp_endofresp(struct connectdata *conn, char *line, size_t len,
*/
static void smtp_get_message(char *buffer, char **outptr)
{
- size_t len = 0;
+ size_t len = strlen(buffer);
char *message = NULL;
- /* Find the start of the message */
- for(message = buffer + 4; *message == ' ' || *message == '\t'; message++)
- ;
-
- /* Find the end of the message */
- for(len = strlen(message); len--;)
- if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
- message[len] != '\t')
- break;
-
- /* Terminate the message */
- if(++len) {
- message[len] = '\0';
+ if(len > 4) {
+ /* Find the start of the message */
+ len -= 4;
+ for(message = buffer + 4; *message == ' ' || *message == '\t';
+ message++, len--)
+ ;
+
+ /* Find the end of the message */
+ for(; len--;)
+ if(message[len] != '\r' && message[len] != '\n' && message[len] != ' ' &&
+ message[len] != '\t')
+ break;
+
+ /* Terminate the message */
+ if(++len) {
+ message[len] = '\0';
+ }
}
+ else
+ /* junk input => zero length output */
+ message = &buffer[len];
*outptr = message;
}
@@ -580,8 +543,40 @@ static CURLcode smtp_perform_mail(struct connectdata *conn)
}
}
+ /* Prepare the mime data if some. */
+ if(data->set.mimepost.kind != MIMEKIND_NONE) {
+ /* Use the whole structure as data. */
+ data->set.mimepost.flags &= ~MIME_BODY_ONLY;
+
+ /* Add external headers and mime version. */
+ curl_mime_headers(&data->set.mimepost, data->set.headers, 0);
+ result = Curl_mime_prepare_headers(&data->set.mimepost, NULL,
+ NULL, MIMESTRATEGY_MAIL);
+
+ if(!result)
+ if(!Curl_checkheaders(conn, "Mime-Version"))
+ result = Curl_mime_add_header(&data->set.mimepost.curlheaders,
+ "Mime-Version: 1.0");
+
+ /* Make sure we will read the entire mime structure. */
+ if(!result)
+ result = Curl_mime_rewind(&data->set.mimepost);
+
+ if(result) {
+ free(from);
+ free(auth);
+ return result;
+ }
+
+ data->state.infilesize = Curl_mime_size(&data->set.mimepost);
+
+ /* Read from mime structure. */
+ data->state.fread_func = (curl_read_callback) Curl_mime_read;
+ data->state.in = (void *) &data->set.mimepost;
+ }
+
/* Calculate the optional SIZE parameter */
- if(conn->proto.smtpc.size_supported && conn->data->state.infilesize > 0) {
+ if(conn->proto.smtpc.size_supported && data->state.infilesize > 0) {
size = aprintf("%" CURL_FORMAT_CURL_OFF_T, data->state.infilesize);
if(!size) {
@@ -714,7 +709,6 @@ static CURLcode smtp_state_ehlo_resp(struct connectdata *conn, int smtpcode,
struct smtp_conn *smtpc = &conn->proto.smtpc;
const char *line = data->state.buffer;
size_t len = strlen(line);
- size_t wordlen;
(void)instate; /* no use for this yet */
@@ -749,6 +743,7 @@ static CURLcode smtp_state_ehlo_resp(struct connectdata *conn, int smtpcode,
/* Loop through the data line */
for(;;) {
size_t llen;
+ size_t wordlen;
unsigned int mechbit;
while(len &&
@@ -965,7 +960,7 @@ static CURLcode smtp_state_data_resp(struct connectdata *conn, int smtpcode,
Curl_pgrsSetUploadSize(data, data->state.infilesize);
/* SMTP upload */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
/* End of DO phase */
state(conn, SMTP_STOP);
@@ -1090,19 +1085,20 @@ static CURLcode smtp_multi_statemach(struct connectdata *conn, bool *done)
return result;
}
- result = Curl_pp_statemach(&smtpc->pp, FALSE);
+ result = Curl_pp_statemach(&smtpc->pp, FALSE, FALSE);
*done = (smtpc->state == SMTP_STOP) ? TRUE : FALSE;
return result;
}
-static CURLcode smtp_block_statemach(struct connectdata *conn)
+static CURLcode smtp_block_statemach(struct connectdata *conn,
+ bool disconnecting)
{
CURLcode result = CURLE_OK;
struct smtp_conn *smtpc = &conn->proto.smtpc;
while(smtpc->state != SMTP_STOP && !result)
- result = Curl_pp_statemach(&smtpc->pp, TRUE);
+ result = Curl_pp_statemach(&smtpc->pp, TRUE, disconnecting);
return result;
}
@@ -1205,11 +1201,15 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
if(!smtp || !pp->conn)
return CURLE_OK;
+ /* Cleanup our per-request based variables */
+ Curl_safefree(smtp->custom);
+
if(status) {
connclose(conn, "SMTP done with bad status"); /* marked for closure */
result = status; /* use the already set error code */
}
- else if(!data->set.connect_only && data->set.upload && data->set.mail_rcpt) {
+ else if(!data->set.connect_only && data->set.mail_rcpt &&
+ (data->set.upload || data->set.mimepost.kind)) {
/* Calculate the EOB taking into account any terminating CRLF from the
previous line of the email or the CRLF of the DATA command when there
is "no mail data". RFC-5321, sect. 4.1.1.4.
@@ -1219,7 +1219,7 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
returned CURLE_AGAIN, we duplicate the EOB now rather than when the
bytes written doesn't equal len. */
if(smtp->trailing_crlf || !conn->data->state.infilesize) {
- eob = strdup(SMTP_EOB + 2);
+ eob = strdup(&SMTP_EOB[2]);
len = SMTP_EOB_LEN - 2;
}
else {
@@ -1246,25 +1246,17 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
}
else {
/* Successfully sent so adjust the response timeout relative to now */
- pp->response = Curl_tvnow();
+ pp->response = Curl_now();
free(eob);
}
state(conn, SMTP_POSTDATA);
- /* Run the state-machine
-
- TODO: when the multi interface is used, this _really_ should be using
- the smtp_multi_statemach function but we have no general support for
- non-blocking DONE operations!
- */
- result = smtp_block_statemach(conn);
+ /* Run the state-machine */
+ result = smtp_block_statemach(conn, FALSE);
}
- /* Cleanup our per-request based variables */
- Curl_safefree(smtp->custom);
-
/* Clear the transfer mode for the next request */
smtp->transfer = FTPTRANSFER_BODY;
@@ -1298,8 +1290,13 @@ static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
/* Store the first recipient (or NULL if not specified) */
smtp->rcpt = data->set.mail_rcpt;
+ /* Initial data character is the first character in line: it is implicitly
+ preceded by a virtual CRLF. */
+ smtp->trailing_crlf = TRUE;
+ smtp->eob = 2;
+
/* Start the first command in the DO phase */
- if(data->set.upload && data->set.mail_rcpt)
+ if((data->set.upload || data->set.mimepost.kind) && data->set.mail_rcpt)
/* MAIL transfer */
result = smtp_perform_mail(conn);
else
@@ -1364,7 +1361,7 @@ static CURLcode smtp_disconnect(struct connectdata *conn, bool dead_connection)
point! */
if(!dead_connection && smtpc->pp.conn && smtpc->pp.conn->bits.protoconnstart)
if(!smtp_perform_quit(conn))
- (void)smtp_block_statemach(conn); /* ignore errors on QUIT */
+ (void)smtp_block_statemach(conn, TRUE); /* ignore errors on QUIT */
/* Disconnect from the server */
Curl_pp_disconnect(&smtpc->pp);
@@ -1387,7 +1384,7 @@ static CURLcode smtp_dophase_done(struct connectdata *conn, bool connected)
if(smtp->transfer != FTPTRANSFER_BODY)
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(conn->data, -1, -1, FALSE, -1);
return CURLE_OK;
}
@@ -1445,43 +1442,16 @@ static CURLcode smtp_regular_transfer(struct connectdata *conn,
static CURLcode smtp_setup_connection(struct connectdata *conn)
{
- struct Curl_easy *data = conn->data;
CURLcode result;
/* Clear the TLS upgraded flag */
conn->tls_upgraded = FALSE;
- /* Set up the proxy if necessary */
- if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
- /* Unless we have asked to tunnel SMTP operations through the proxy, we
- switch and use HTTP operations only */
-#ifndef CURL_DISABLE_HTTP
- if(conn->handler == &Curl_handler_smtp)
- conn->handler = &Curl_handler_smtp_proxy;
- else {
-#ifdef USE_SSL
- conn->handler = &Curl_handler_smtps_proxy;
-#else
- failf(data, "SMTPS not supported!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
- /* set it up as a HTTP connection instead */
- return conn->handler->setup_connection(conn);
-
-#else
- failf(data, "SMTP over http proxy requires HTTP support built-in!");
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- }
-
/* Initialise the SMTP layer */
result = smtp_init(conn);
if(result)
return result;
- data->state.path++; /* don't include the initial slash */
-
return CURLE_OK;
}
@@ -1535,7 +1505,7 @@ static CURLcode smtp_parse_url_path(struct connectdata *conn)
/* The SMTP struct is already initialised in smtp_connect() */
struct Curl_easy *data = conn->data;
struct smtp_conn *smtpc = &conn->proto.smtpc;
- const char *path = data->state.path;
+ const char *path = &data->state.up.path[1]; /* skip leading path */
char localhost[HOSTNAME_MAX + 1];
/* Calculate the path if necessary */
@@ -1591,13 +1561,14 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, const ssize_t nread)
if(!scratch || data->set.crlf) {
oldscratch = scratch;
- scratch = newscratch = malloc(2 * data->set.buffer_size);
+ scratch = newscratch = malloc(2 * data->set.upload_buffer_size);
if(!newscratch) {
failf(data, "Failed to alloc scratch buffer!");
return CURLE_OUT_OF_MEMORY;
}
}
+ DEBUGASSERT(data->set.upload_buffer_size >= (size_t)nread);
/* Have we already sent part of the EOB? */
eob_sent = smtp->eob;
diff --git a/Utilities/cmcurl/lib/sockaddr.h b/Utilities/cmcurl/lib/sockaddr.h
index 95ba4c3c9..db146803a 100644
--- a/Utilities/cmcurl/lib/sockaddr.h
+++ b/Utilities/cmcurl/lib/sockaddr.h
@@ -40,4 +40,3 @@ struct Curl_sockaddr_storage {
};
#endif /* HEADER_CURL_SOCKADDR_H */
-
diff --git a/Utilities/cmcurl/lib/socks.c b/Utilities/cmcurl/lib/socks.c
index 97a44b296..d8fcc3bbb 100644
--- a/Utilities/cmcurl/lib/socks.c
+++ b/Utilities/cmcurl/lib/socks.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -54,13 +54,12 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
ssize_t buffersize, /* max amount to read */
ssize_t *n) /* amount bytes read */
{
- ssize_t nread;
+ ssize_t nread = 0;
ssize_t allread = 0;
int result;
- time_t timeleft;
*n = 0;
for(;;) {
- timeleft = Curl_timeleft(conn->data, NULL, TRUE);
+ timediff_t timeleft = Curl_timeleft(conn->data, NULL, TRUE);
if(timeleft < 0) {
/* we already got the timeout */
result = CURLE_OPERATION_TIMEDOUT;
@@ -99,13 +98,13 @@ int Curl_blockread_all(struct connectdata *conn, /* connection data */
* destination server.
*
* Reference :
-* http://socks.permeo.com/protocol/socks4.protocol
+* https://www.openssh.com/txt/socks4.protocol
*
* Note :
* Set protocol4a=true for "SOCKS 4A (Simple Extension to SOCKS 4 Protocol)"
* Nonsupport "Identification Protocol (RFC1413)"
*/
-CURLcode Curl_SOCKS4(const char *proxy_name,
+CURLcode Curl_SOCKS4(const char *proxy_user,
const char *hostname,
int remote_port,
int sockindex,
@@ -116,7 +115,6 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
#define SOCKS4REQLEN 262
unsigned char socksreq[SOCKS4REQLEN]; /* room for SOCKS4 request incl. user
id */
- int result;
CURLcode code;
curl_socket_t sock = conn->sock[sockindex];
struct Curl_easy *data = conn->data;
@@ -154,10 +152,10 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
/* DNS resolve only for SOCKS4, not SOCKS4a */
if(!protocol4a) {
struct Curl_dns_entry *dns;
- Curl_addrinfo *hp=NULL;
+ Curl_addrinfo *hp = NULL;
int rc;
- rc = Curl_resolv(conn, hostname, remote_port, &dns);
+ rc = Curl_resolv(conn, hostname, remote_port, FALSE, &dns);
if(rc == CURLRESOLV_ERROR)
return CURLE_COULDNT_RESOLVE_PROXY;
@@ -171,7 +169,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
* returns a Curl_addrinfo pointer that may not always look the same.
*/
if(dns)
- hp=dns->addr;
+ hp = dns->addr;
if(hp) {
char buf[64];
Curl_printable_address(hp, buf, sizeof(buf));
@@ -206,25 +204,26 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
* 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(proxy_user) {
+ size_t plen = strlen(proxy_user);
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);
+ memcpy(socksreq + 8, proxy_user, plen + 1);
}
/*
* Make connection
*/
{
+ int result;
ssize_t actualread;
ssize_t written;
ssize_t hostnamelen = 0;
- int packetsize = 9 +
- (int)strlen((char *)socksreq + 8); /* size including NUL */
+ ssize_t packetsize = 9 +
+ strlen((char *)socksreq + 8); /* size including NUL */
/* If SOCKS4a, set special invalid IP address 0.0.0.x */
if(protocol4a) {
@@ -291,7 +290,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
/* wrong version ? */
if(socksreq[0] != 0) {
failf(data,
- "SOCKS4 reply has wrong version, version should be 4.");
+ "SOCKS4 reply has wrong version, version should be 0.");
return CURLE_COULDNT_CONNECT;
}
@@ -306,7 +305,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
", request rejected or failed.",
(unsigned char)socksreq[4], (unsigned char)socksreq[5],
(unsigned char)socksreq[6], (unsigned char)socksreq[7],
- (((unsigned char)socksreq[8] << 8) | (unsigned char)socksreq[9]),
+ (((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLE_COULDNT_CONNECT;
case 92:
@@ -316,7 +315,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
"identd on the client.",
(unsigned char)socksreq[4], (unsigned char)socksreq[5],
(unsigned char)socksreq[6], (unsigned char)socksreq[7],
- (((unsigned char)socksreq[8] << 8) | (unsigned char)socksreq[9]),
+ (((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLE_COULDNT_CONNECT;
case 93:
@@ -326,7 +325,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
"report different user-ids.",
(unsigned char)socksreq[4], (unsigned char)socksreq[5],
(unsigned char)socksreq[6], (unsigned char)socksreq[7],
- (((unsigned char)socksreq[8] << 8) | (unsigned char)socksreq[9]),
+ (((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLE_COULDNT_CONNECT;
default:
@@ -335,7 +334,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
", Unknown.",
(unsigned char)socksreq[4], (unsigned char)socksreq[5],
(unsigned char)socksreq[6], (unsigned char)socksreq[7],
- (((unsigned char)socksreq[8] << 8) | (unsigned char)socksreq[9]),
+ (((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLE_COULDNT_CONNECT;
}
@@ -350,7 +349,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
* This function logs in to a SOCKS5 proxy and sends the specifics to the final
* destination server.
*/
-CURLcode Curl_SOCKS5(const char *proxy_name,
+CURLcode Curl_SOCKS5(const char *proxy_user,
const char *proxy_password,
const char *hostname,
int remote_port,
@@ -375,17 +374,20 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
*/
unsigned char socksreq[600]; /* room for large user/pw (255 max each) */
+ int idx;
ssize_t actualread;
ssize_t written;
int result;
CURLcode code;
curl_socket_t sock = conn->sock[sockindex];
struct Curl_easy *data = conn->data;
- time_t timeout;
+ timediff_t timeout;
bool socks5_resolve_local =
(conn->socks_proxy.proxytype == CURLPROXY_SOCKS5) ? TRUE : FALSE;
const size_t hostname_len = strlen(hostname);
ssize_t len = 0;
+ const unsigned long auth = data->set.socks5auth;
+ bool allow_gssapi = FALSE;
if(conn->bits.httpproxy)
infof(conn->data, "SOCKS5: connecting to HTTP proxy %s port %d\n",
@@ -426,18 +428,29 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
return CURLE_COULDNT_CONNECT;
}
- socksreq[0] = 5; /* version */
+ if(auth & ~(CURLAUTH_BASIC | CURLAUTH_GSSAPI))
+ infof(conn->data,
+ "warning: unsupported value passed to CURLOPT_SOCKS5_AUTH: %lu\n",
+ auth);
+ if(!(auth & CURLAUTH_BASIC))
+ /* disable username/password auth */
+ proxy_user = NULL;
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
- socksreq[1] = (char)(proxy_name ? 3 : 2); /* number of methods (below) */
- socksreq[2] = 0; /* no authentication */
- socksreq[3] = 1; /* GSS-API */
- socksreq[4] = 2; /* username/password */
-#else
- socksreq[1] = (char)(proxy_name ? 2 : 1); /* number of methods (below) */
- socksreq[2] = 0; /* no authentication */
- socksreq[3] = 2; /* username/password */
+ if(auth & CURLAUTH_GSSAPI)
+ allow_gssapi = TRUE;
#endif
+ idx = 0;
+ socksreq[idx++] = 5; /* version */
+ idx++; /* reserve for the number of authentication methods */
+ socksreq[idx++] = 0; /* no authentication */
+ if(allow_gssapi)
+ socksreq[idx++] = 1; /* GSS-API */
+ if(proxy_user)
+ socksreq[idx++] = 2; /* username/password */
+ /* write the number of authentication methods */
+ socksreq[1] = (unsigned char) (idx - 2);
+
(void)curlx_nonblock(sock, FALSE);
infof(data, "SOCKS5 communication to %s:%d\n", hostname, remote_port);
@@ -469,7 +482,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
(void)curlx_nonblock(sock, FALSE);
- result=Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread);
+ result = Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread);
if(result || (actualread != 2)) {
failf(data, "Unable to receive initial SOCKS5 response.");
return CURLE_COULDNT_CONNECT;
@@ -484,7 +497,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
;
}
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
- else if(socksreq[1] == 1) {
+ else if(allow_gssapi && (socksreq[1] == 1)) {
code = Curl_SOCKS5_gssapi_negotiate(sockindex, conn);
if(code) {
failf(data, "Unable to negotiate SOCKS5 GSS-API context.");
@@ -494,13 +507,13 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
#endif
else if(socksreq[1] == 2) {
/* Needs user name and password */
- size_t proxy_name_len, proxy_password_len;
- if(proxy_name && proxy_password) {
- proxy_name_len = strlen(proxy_name);
+ size_t proxy_user_len, proxy_password_len;
+ if(proxy_user && proxy_password) {
+ proxy_user_len = strlen(proxy_user);
proxy_password_len = strlen(proxy_password);
}
else {
- proxy_name_len = 0;
+ proxy_user_len = 0;
proxy_password_len = 0;
}
@@ -513,13 +526,25 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
*/
len = 0;
socksreq[len++] = 1; /* username/pw subnegotiation version */
- socksreq[len++] = (unsigned char) proxy_name_len;
- if(proxy_name && proxy_name_len)
- memcpy(socksreq + len, proxy_name, proxy_name_len);
- len += proxy_name_len;
+ socksreq[len++] = (unsigned char) proxy_user_len;
+ if(proxy_user && proxy_user_len) {
+ /* the length must fit in a single byte */
+ if(proxy_user_len >= 255) {
+ failf(data, "Excessive user name length for proxy auth");
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ }
+ memcpy(socksreq + len, proxy_user, proxy_user_len);
+ }
+ len += proxy_user_len;
socksreq[len++] = (unsigned char) proxy_password_len;
- if(proxy_password && proxy_password_len)
+ if(proxy_password && proxy_password_len) {
+ /* the length must fit in a single byte */
+ if(proxy_password_len > 255) {
+ failf(data, "Excessive password length for proxy auth");
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ }
memcpy(socksreq + len, proxy_password, proxy_password_len);
+ }
len += proxy_password_len;
code = Curl_write_plain(conn, sock, (char *)socksreq, len, &written);
@@ -528,7 +553,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
return CURLE_COULDNT_CONNECT;
}
- result=Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread);
+ result = Curl_blockread_all(conn, sock, (char *)socksreq, 2, &actualread);
if(result || (actualread != 2)) {
failf(data, "Unable to receive SOCKS5 sub-negotiation response.");
return CURLE_COULDNT_CONNECT;
@@ -545,17 +570,13 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
}
else {
/* error */
-#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
- if(socksreq[1] == 255) {
-#else
- if(socksreq[1] == 1) {
+ if(!allow_gssapi && (socksreq[1] == 1)) {
failf(data,
"SOCKS5 GSSAPI per-message authentication is not supported.");
return CURLE_COULDNT_CONNECT;
}
if(socksreq[1] == 255) {
-#endif
- if(!proxy_name || !*proxy_name) {
+ if(!proxy_user || !*proxy_user) {
failf(data,
"No authentication method was acceptable. (It is quite likely"
" that the SOCKS5 server wanted a username/password, since none"
@@ -588,7 +609,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
else {
struct Curl_dns_entry *dns;
Curl_addrinfo *hp = NULL;
- int rc = Curl_resolv(conn, hostname, remote_port, &dns);
+ int rc = Curl_resolv(conn, hostname, remote_port, FALSE, &dns);
if(rc == CURLRESOLV_ERROR)
return CURLE_COULDNT_RESOLVE_HOST;
@@ -605,13 +626,13 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
* returns a Curl_addrinfo pointer that may not always look the same.
*/
if(dns)
- hp=dns->addr;
+ hp = dns->addr;
if(hp) {
- int i;
char buf[64];
Curl_printable_address(hp, buf, sizeof(buf));
if(hp->ai_family == AF_INET) {
+ int i;
struct sockaddr_in *saddr_in;
socksreq[len++] = 1; /* ATYP: IPv4 = 1 */
@@ -624,6 +645,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
}
#ifdef ENABLE_IPV6
else if(hp->ai_family == AF_INET6) {
+ int i;
struct sockaddr_in6 *saddr_in6;
socksreq[len++] = 4; /* ATYP: IPv6 = 4 */
@@ -779,4 +801,3 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
}
#endif /* CURL_DISABLE_PROXY */
-
diff --git a/Utilities/cmcurl/lib/socks.h b/Utilities/cmcurl/lib/socks.h
index 348707e74..daa07c127 100644
--- a/Utilities/cmcurl/lib/socks.h
+++ b/Utilities/cmcurl/lib/socks.h
@@ -73,4 +73,3 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
#endif /* CURL_DISABLE_PROXY */
#endif /* HEADER_CURL_SOCKS_H */
-
diff --git a/Utilities/cmcurl/lib/socks_gssapi.c b/Utilities/cmcurl/lib/socks_gssapi.c
index 54d063504..65294bbeb 100644
--- a/Utilities/cmcurl/lib/socks_gssapi.c
+++ b/Utilities/cmcurl/lib/socks_gssapi.c
@@ -5,8 +5,8 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2009, 2011, Markus Moeller, <markus_moeller@compuserve.com>
- * Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2009, Markus Moeller, <markus_moeller@compuserve.com>
+ * Copyright (C) 2012 - 2018, 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
@@ -65,7 +65,7 @@ static int check_gss_err(struct Curl_easy *data,
&msg_ctx, &status_string);
if(maj_stat == GSS_S_COMPLETE) {
if(sizeof(buf) > len + status_string.length + 1) {
- strcpy(buf+len, (char *) status_string.value);
+ strcpy(buf + len, (char *) status_string.value);
len += status_string.length;
}
gss_release_buffer(&min_stat, &status_string);
@@ -74,7 +74,7 @@ static int check_gss_err(struct Curl_easy *data,
gss_release_buffer(&min_stat, &status_string);
}
if(sizeof(buf) > len + 3) {
- strcpy(buf+len, ".\n");
+ strcpy(buf + len, ".\n");
len += 2;
}
msg_ctx = 0;
@@ -86,7 +86,7 @@ static int check_gss_err(struct Curl_easy *data,
&msg_ctx, &status_string);
if(maj_stat == GSS_S_COMPLETE) {
if(sizeof(buf) > len + status_string.length)
- strcpy(buf+len, (char *) status_string.value);
+ strcpy(buf + len, (char *) status_string.value);
gss_release_buffer(&min_stat, &status_string);
break;
}
@@ -119,7 +119,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
gss_name_t server = GSS_C_NO_NAME;
gss_name_t gss_client_name = GSS_C_NO_NAME;
unsigned short us_length;
- char *user=NULL;
+ char *user = NULL;
unsigned char socksreq[4]; /* room for GSS-API exchange header only */
const char *serviceptr = data->set.str[STRING_PROXY_SERVICE_NAME] ?
data->set.str[STRING_PROXY_SERVICE_NAME] : "rcmd";
@@ -146,12 +146,13 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
}
else {
service.value = malloc(serviceptr_length +
- strlen(conn->socks_proxy.host.name)+2);
+ strlen(conn->socks_proxy.host.name) + 2);
if(!service.value)
return CURLE_OUT_OF_MEMORY;
- service.length = serviceptr_length + strlen(conn->socks_proxy.host.name)+1;
- snprintf(service.value, service.length+1, "%s@%s",
- serviceptr, conn->socks_proxy.host.name);
+ service.length = serviceptr_length +
+ strlen(conn->socks_proxy.host.name) + 1;
+ msnprintf(service.value, service.length + 1, "%s@%s",
+ serviceptr, conn->socks_proxy.host.name);
gss_major_status = gss_import_name(&gss_minor_status, &service,
GSS_C_NT_HOSTBASED_SERVICE, &server);
@@ -196,7 +197,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
socksreq[0] = 1; /* GSS-API subnegotiation version */
socksreq[1] = 1; /* authentication message type */
us_length = htons((short)gss_send_token.length);
- memcpy(socksreq+2, &us_length, sizeof(short));
+ memcpy(socksreq + 2, &us_length, sizeof(short));
code = Curl_write_plain(conn, sock, (char *)socksreq, 4, &written);
if(code || (4 != written)) {
@@ -236,7 +237,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
* +----+------+-----+----------------+
*/
- result=Curl_blockread_all(conn, sock, (char *)socksreq, 4, &actualread);
+ result = Curl_blockread_all(conn, sock, (char *)socksreq, 4, &actualread);
if(result || (actualread != 4)) {
failf(data, "Failed to receive GSS-API authentication response.");
gss_release_name(&gss_status, &server);
@@ -261,11 +262,11 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
return CURLE_COULDNT_CONNECT;
}
- memcpy(&us_length, socksreq+2, sizeof(short));
+ memcpy(&us_length, socksreq + 2, sizeof(short));
us_length = ntohs(us_length);
- gss_recv_token.length=us_length;
- gss_recv_token.value=malloc(us_length);
+ gss_recv_token.length = us_length;
+ gss_recv_token.value = malloc(us_length);
if(!gss_recv_token.value) {
failf(data,
"Could not allocate memory for GSS-API authentication "
@@ -275,8 +276,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
return CURLE_OUT_OF_MEMORY;
}
- result=Curl_blockread_all(conn, sock, (char *)gss_recv_token.value,
- gss_recv_token.length, &actualread);
+ result = Curl_blockread_all(conn, sock, (char *)gss_recv_token.value,
+ gss_recv_token.length, &actualread);
if(result || (actualread != us_length)) {
failf(data, "Failed to receive GSS-API authentication token.");
@@ -312,7 +313,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
failf(data, "Failed to determine user name.");
return CURLE_COULDNT_CONNECT;
}
- user=malloc(gss_send_token.length+1);
+ user = malloc(gss_send_token.length + 1);
if(!user) {
gss_delete_sec_context(&gss_status, &gss_context, NULL);
gss_release_name(&gss_status, &gss_client_name);
@@ -326,7 +327,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
gss_release_buffer(&gss_status, &gss_send_token);
infof(data, "SOCKS5 server authencticated user %s with GSS-API.\n",user);
free(user);
- user=NULL;
+ user = NULL;
/* Do encryption */
socksreq[0] = 1; /* GSS-API subnegotiation version */
@@ -341,7 +342,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
gss_enc = 1;
infof(data, "SOCKS5 server supports GSS-API %s data protection.\n",
- (gss_enc==0)?"no":((gss_enc==1)?"integrity":"confidentiality"));
+ (gss_enc == 0)?"no":((gss_enc==1)?"integrity":"confidentiality"));
/* force for the moment to no data protection */
gss_enc = 0;
/*
@@ -376,7 +377,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
*/
if(data->set.socks5_gssapi_nec) {
us_length = htons((short)1);
- memcpy(socksreq+2, &us_length, sizeof(short));
+ memcpy(socksreq + 2, &us_length, sizeof(short));
}
else {
gss_send_token.length = 1;
@@ -401,7 +402,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
gss_release_buffer(&gss_status, &gss_send_token);
us_length = htons((short)gss_w_token.length);
- memcpy(socksreq+2, &us_length, sizeof(short));
+ memcpy(socksreq + 2, &us_length, sizeof(short));
}
code = Curl_write_plain(conn, sock, (char *)socksreq, 4, &written);
@@ -433,7 +434,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
gss_release_buffer(&gss_status, &gss_w_token);
}
- result=Curl_blockread_all(conn, sock, (char *)socksreq, 4, &actualread);
+ result = Curl_blockread_all(conn, sock, (char *)socksreq, 4, &actualread);
if(result || (actualread != 4)) {
failf(data, "Failed to receive GSS-API encryption response.");
gss_delete_sec_context(&gss_status, &gss_context, NULL);
@@ -455,17 +456,17 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
return CURLE_COULDNT_CONNECT;
}
- memcpy(&us_length, socksreq+2, sizeof(short));
+ memcpy(&us_length, socksreq + 2, sizeof(short));
us_length = ntohs(us_length);
- gss_recv_token.length= us_length;
- gss_recv_token.value=malloc(gss_recv_token.length);
+ gss_recv_token.length = us_length;
+ gss_recv_token.value = malloc(gss_recv_token.length);
if(!gss_recv_token.value) {
gss_delete_sec_context(&gss_status, &gss_context, NULL);
return CURLE_OUT_OF_MEMORY;
}
- result=Curl_blockread_all(conn, sock, (char *)gss_recv_token.value,
- gss_recv_token.length, &actualread);
+ result = Curl_blockread_all(conn, sock, (char *)gss_recv_token.value,
+ gss_recv_token.length, &actualread);
if(result || (actualread != us_length)) {
failf(data, "Failed to receive GSS-API encryptrion type.");
@@ -513,8 +514,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
}
infof(data, "SOCKS5 access with%s protection granted.\n",
- (socksreq[0]==0)?"out GSS-API data":
- ((socksreq[0]==1)?" GSS-API integrity":" GSS-API confidentiality"));
+ (socksreq[0] == 0)?"out GSS-API data":
+ ((socksreq[0] == 1)?" GSS-API integrity":" GSS-API confidentiality"));
conn->socks5_gssapi_enctype = socksreq[0];
if(socksreq[0] == 0)
diff --git a/Utilities/cmcurl/lib/socks_sspi.c b/Utilities/cmcurl/lib/socks_sspi.c
index edc73ad2e..57027ef68 100644
--- a/Utilities/cmcurl/lib/socks_sspi.c
+++ b/Utilities/cmcurl/lib/socks_sspi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2009, 2011, Markus Moeller, <markus_moeller@compuserve.com>
*
* This software is licensed as described in the file COPYING, which
@@ -51,8 +51,9 @@ static int check_sspi_err(struct connectdata *conn,
status != SEC_I_COMPLETE_AND_CONTINUE &&
status != SEC_I_COMPLETE_NEEDED &&
status != SEC_I_CONTINUE_NEEDED) {
+ char buffer[STRERROR_LEN];
failf(conn->data, "SSPI error: %s failed: %s", function,
- Curl_sspi_strerror(conn, status));
+ Curl_sspi_strerror(status, buffer, sizeof(buffer)));
return 1;
}
return 0;
@@ -107,9 +108,9 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
strlen(conn->socks_proxy.host.name) + 2);
if(!service_name)
return CURLE_OUT_OF_MEMORY;
- snprintf(service_name, service_length +
- strlen(conn->socks_proxy.host.name)+2, "%s/%s",
- service, conn->socks_proxy.host.name);
+ msnprintf(service_name, service_length +
+ strlen(conn->socks_proxy.host.name) + 2, "%s/%s",
+ service, conn->socks_proxy.host.name);
}
input_desc.cBuffers = 1;
@@ -199,7 +200,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
socksreq[0] = 1; /* GSS-API subnegotiation version */
socksreq[1] = 1; /* authentication message type */
us_length = htons((short)sspi_send_token.cbBuffer);
- memcpy(socksreq+2, &us_length, sizeof(short));
+ memcpy(socksreq + 2, &us_length, sizeof(short));
code = Curl_write_plain(conn, sock, (char *)socksreq, 4, &written);
if(code || (4 != written)) {
@@ -283,7 +284,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
return CURLE_COULDNT_CONNECT;
}
- memcpy(&us_length, socksreq+2, sizeof(short));
+ memcpy(&us_length, socksreq + 2, sizeof(short));
us_length = ntohs(us_length);
sspi_recv_token.cbBuffer = us_length;
@@ -341,7 +342,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
gss_enc = 1;
infof(data, "SOCKS5 server supports GSS-API %s data protection.\n",
- (gss_enc==0)?"no":((gss_enc==1)?"integrity":"confidentiality") );
+ (gss_enc == 0)?"no":((gss_enc == 1)?"integrity":"confidentiality") );
/* force to no data protection, avoid encryption/decryption for now */
gss_enc = 0;
/*
@@ -377,7 +378,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
if(data->set.socks5_gssapi_nec) {
us_length = htons((short)1);
- memcpy(socksreq+2, &us_length, sizeof(short));
+ memcpy(socksreq + 2, &us_length, sizeof(short));
}
else {
status = s_pSecFn->QueryContextAttributes(&sspi_context,
@@ -445,8 +446,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
memcpy((PUCHAR) sspi_send_token.pvBuffer +(int)sspi_w_token[0].cbBuffer,
sspi_w_token[1].pvBuffer, sspi_w_token[1].cbBuffer);
memcpy((PUCHAR) sspi_send_token.pvBuffer
- +sspi_w_token[0].cbBuffer
- +sspi_w_token[1].cbBuffer,
+ + sspi_w_token[0].cbBuffer
+ + sspi_w_token[1].cbBuffer,
sspi_w_token[2].pvBuffer, sspi_w_token[2].cbBuffer);
s_pSecFn->FreeContextBuffer(sspi_w_token[0].pvBuffer);
@@ -460,7 +461,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
sspi_w_token[2].cbBuffer = 0;
us_length = htons((short)sspi_send_token.cbBuffer);
- memcpy(socksreq+2, &us_length, sizeof(short));
+ memcpy(socksreq + 2, &us_length, sizeof(short));
}
code = Curl_write_plain(conn, sock, (char *)socksreq, 4, &written);
@@ -517,7 +518,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
return CURLE_COULDNT_CONNECT;
}
- memcpy(&us_length, socksreq+2, sizeof(short));
+ memcpy(&us_length, socksreq + 2, sizeof(short));
us_length = ntohs(us_length);
sspi_w_token[0].cbBuffer = us_length;
@@ -588,8 +589,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
}
infof(data, "SOCKS5 access with%s protection granted.\n",
- (socksreq[0]==0)?"out GSS-API data":
- ((socksreq[0]==1)?" GSS-API integrity":" GSS-API confidentiality"));
+ (socksreq[0] == 0)?"out GSS-API data":
+ ((socksreq[0] == 1)?" GSS-API integrity":" GSS-API confidentiality"));
/* For later use if encryption is required
conn->socks5_gssapi_enctype = socksreq[0];
diff --git a/Utilities/cmcurl/lib/speedcheck.c b/Utilities/cmcurl/lib/speedcheck.c
index 8addedde5..3aeea9111 100644
--- a/Utilities/cmcurl/lib/speedcheck.c
+++ b/Utilities/cmcurl/lib/speedcheck.c
@@ -30,14 +30,14 @@
void Curl_speedinit(struct Curl_easy *data)
{
- memset(&data->state.keeps_speed, 0, sizeof(struct timeval));
+ memset(&data->state.keeps_speed, 0, sizeof(struct curltime));
}
/*
* @unittest: 1606
*/
CURLcode Curl_speedcheck(struct Curl_easy *data,
- struct timeval now)
+ struct curltime now)
{
if((data->progress.current_speed >= 0) && data->set.low_speed_time) {
if(data->progress.current_speed < data->set.low_speed_limit) {
@@ -46,7 +46,7 @@ CURLcode Curl_speedcheck(struct Curl_easy *data,
data->state.keeps_speed = now;
else {
/* how long has it been under the limit */
- time_t howlong = Curl_tvdiff(now, data->state.keeps_speed);
+ timediff_t howlong = Curl_timediff(now, data->state.keeps_speed);
if(howlong >= data->set.low_speed_time * 1000) {
/* too long */
diff --git a/Utilities/cmcurl/lib/speedcheck.h b/Utilities/cmcurl/lib/speedcheck.h
index 7dbe3d6d7..5c2dc9a22 100644
--- a/Utilities/cmcurl/lib/speedcheck.h
+++ b/Utilities/cmcurl/lib/speedcheck.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -28,6 +28,6 @@
void Curl_speedinit(struct Curl_easy *data);
CURLcode Curl_speedcheck(struct Curl_easy *data,
- struct timeval now);
+ struct curltime now);
#endif /* HEADER_CURL_SPEEDCHECK_H */
diff --git a/Utilities/cmcurl/lib/splay.c b/Utilities/cmcurl/lib/splay.c
index 1b301f95d..0f5fcd1e8 100644
--- a/Utilities/cmcurl/lib/splay.c
+++ b/Utilities/cmcurl/lib/splay.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1997 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1997 - 2019, 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
@@ -37,11 +37,10 @@
* Splay using the key i (which may or may not be in the tree.) The starting
* root is t.
*/
-struct Curl_tree *Curl_splay(struct timeval i,
+struct Curl_tree *Curl_splay(struct curltime i,
struct Curl_tree *t)
{
struct Curl_tree N, *l, *r, *y;
- long comp;
if(t == NULL)
return t;
@@ -49,7 +48,7 @@ struct Curl_tree *Curl_splay(struct timeval i,
l = r = &N;
for(;;) {
- comp = compare(i, t->key);
+ long comp = compare(i, t->key);
if(comp < 0) {
if(t->smaller == NULL)
break;
@@ -97,24 +96,26 @@ struct Curl_tree *Curl_splay(struct timeval i,
*
* @unittest: 1309
*/
-struct Curl_tree *Curl_splayinsert(struct timeval i,
+struct Curl_tree *Curl_splayinsert(struct curltime i,
struct Curl_tree *t,
struct Curl_tree *node)
{
- static const struct timeval KEY_NOTUSED = {-1, -1}; /* will *NEVER* appear */
+ static const struct curltime KEY_NOTUSED = {
+ (time_t)-1, (unsigned int)-1
+ }; /* will *NEVER* appear */
if(node == NULL)
return t;
if(t != NULL) {
t = Curl_splay(i, t);
- if(compare(i, t->key)==0) {
+ if(compare(i, t->key) == 0) {
/* There already exists a node in the tree with the very same key. Build
a doubly-linked circular list of nodes. We add the new 'node' struct
to the end of this list. */
node->key = KEY_NOTUSED; /* we set the key in the sub node to NOTUSED
- to quickly identify this node as a subnode */
+ to quickly identify this node as a subnode */
node->samen = t;
node->samep = t->samep;
t->samep->samen = node;
@@ -149,11 +150,11 @@ struct Curl_tree *Curl_splayinsert(struct timeval i,
/* Finds and deletes the best-fit node from the tree. Return a pointer to the
resulting tree. best-fit means the smallest node if it is not larger than
the key */
-struct Curl_tree *Curl_splaygetbest(struct timeval i,
- struct Curl_tree *t,
- struct Curl_tree **removed)
+struct Curl_tree *Curl_splaygetbest(struct curltime i,
+ struct Curl_tree *t,
+ struct Curl_tree **removed)
{
- static struct timeval tv_zero = {0, 0};
+ static struct curltime tv_zero = {0, 0};
struct Curl_tree *x;
if(!t) {
@@ -197,7 +198,7 @@ struct Curl_tree *Curl_splaygetbest(struct timeval i,
/* 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.
+ * Returns zero on success and non-zero on errors!
* 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
@@ -209,7 +210,9 @@ int Curl_splayremovebyaddr(struct Curl_tree *t,
struct Curl_tree *removenode,
struct Curl_tree **newroot)
{
- static const struct timeval KEY_NOTUSED = {-1, -1}; /* will *NEVER* appear */
+ static const struct curltime KEY_NOTUSED = {
+ (time_t)-1, (unsigned int)-1
+ }; /* will *NEVER* appear */
struct Curl_tree *x;
if(!t || !removenode)
@@ -271,4 +274,3 @@ int Curl_splayremovebyaddr(struct Curl_tree *t,
return 0;
}
-
diff --git a/Utilities/cmcurl/lib/splay.h b/Utilities/cmcurl/lib/splay.h
index da81894d1..4612ec271 100644
--- a/Utilities/cmcurl/lib/splay.h
+++ b/Utilities/cmcurl/lib/splay.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1997 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1997 - 2017, 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
@@ -22,30 +22,31 @@
*
***************************************************************************/
#include "curl_setup.h"
+#include "timeval.h"
struct Curl_tree {
struct Curl_tree *smaller; /* smaller node */
struct Curl_tree *larger; /* larger node */
struct Curl_tree *samen; /* points to the next node with identical key */
struct Curl_tree *samep; /* points to the prev node with identical key */
- struct timeval key; /* this node's "sort" key */
+ struct curltime key; /* this node's "sort" key */
void *payload; /* data the splay code doesn't care about */
};
-struct Curl_tree *Curl_splay(struct timeval i,
+struct Curl_tree *Curl_splay(struct curltime i,
struct Curl_tree *t);
-struct Curl_tree *Curl_splayinsert(struct timeval key,
+struct Curl_tree *Curl_splayinsert(struct curltime key,
struct Curl_tree *t,
struct Curl_tree *newnode);
#if 0
-struct Curl_tree *Curl_splayremove(struct timeval key,
+struct Curl_tree *Curl_splayremove(struct curltime key,
struct Curl_tree *t,
struct Curl_tree **removed);
#endif
-struct Curl_tree *Curl_splaygetbest(struct timeval key,
+struct Curl_tree *Curl_splaygetbest(struct curltime key,
struct Curl_tree *t,
struct Curl_tree **removed);
@@ -53,8 +54,8 @@ int Curl_splayremovebyaddr(struct Curl_tree *t,
struct Curl_tree *removenode,
struct Curl_tree **newroot);
-#define Curl_splaycomparekeys(i,j) ( ((i.tv_sec) < (j.tv_sec)) ? -1 : \
- ( ((i.tv_sec) > (j.tv_sec)) ? 1 : \
+#define Curl_splaycomparekeys(i,j) ( ((i.tv_sec) < (j.tv_sec)) ? -1 : \
+ ( ((i.tv_sec) > (j.tv_sec)) ? 1 : \
( ((i.tv_usec) < (j.tv_usec)) ? -1 : \
( ((i.tv_usec) > (j.tv_usec)) ? 1 : 0))))
diff --git a/Utilities/cmcurl/lib/ssh.c b/Utilities/cmcurl/lib/ssh.c
index 00aeca978..a265c3c9a 100644
--- a/Utilities/cmcurl/lib/ssh.c
+++ b/Utilities/cmcurl/lib/ssh.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -26,9 +26,7 @@
#ifdef USE_LIBSSH2
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
+#include <limits.h>
#include <libssh2.h>
#include <libssh2_sftp.h>
@@ -83,25 +81,13 @@
#include "multiif.h"
#include "select.h"
#include "warnless.h"
+#include "curl_path.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"
-#ifdef WIN32
-# undef PATH_MAX
-# define PATH_MAX MAX_PATH
-# ifndef R_OK
-# define R_OK 4
-# endif
-#endif
-
-#ifndef PATH_MAX
-#define PATH_MAX 1024 /* just an extra precaution since there are systems that
- have their definition hidden well */
-#endif
-
#if LIBSSH2_VERSION_NUM >= 0x010206
/* libssh2_sftp_statvfs and friends were added in 1.2.6 */
#define HAS_STATVFS_SUPPORT 1
@@ -120,16 +106,10 @@ static LIBSSH2_ALLOC_FUNC(my_libssh2_malloc);
static LIBSSH2_REALLOC_FUNC(my_libssh2_realloc);
static LIBSSH2_FREE_FUNC(my_libssh2_free);
-static CURLcode get_pathname(const char **cpp, char **path);
-
static CURLcode ssh_connect(struct connectdata *conn, bool *done);
static CURLcode ssh_multi_statemach(struct connectdata *conn, bool *done);
static CURLcode ssh_do(struct connectdata *conn, bool *done);
-static CURLcode ssh_getworkingpath(struct connectdata *conn,
- char *homedir, /* when SFTP is used */
- char **path);
-
static CURLcode scp_done(struct connectdata *conn,
CURLcode, bool premature);
static CURLcode scp_doing(struct connectdata *conn,
@@ -177,6 +157,7 @@ const struct Curl_handler Curl_handler_scp = {
ssh_perform_getsock, /* perform_getsock */
scp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_SSH, /* defport */
CURLPROTO_SCP, /* protocol */
PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION
@@ -203,6 +184,7 @@ const struct Curl_handler Curl_handler_sftp = {
ssh_perform_getsock, /* perform_getsock */
sftp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_SSH, /* defport */
CURLPROTO_SFTP, /* protocol */
PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION
@@ -277,6 +259,11 @@ static CURLcode libssh2_session_error_to_CURLE(int err)
case LIBSSH2_ERROR_NONE:
return CURLE_OK;
+ /* This is the error returned by libssh2_scp_recv2
+ * on unknown file */
+ case LIBSSH2_ERROR_SCP_PROTOCOL:
+ return CURLE_REMOTE_FILE_NOT_FOUND;
+
case LIBSSH2_ERROR_SOCKET_NONE:
return CURLE_COULDNT_CONNECT;
@@ -303,10 +290,6 @@ static CURLcode libssh2_session_error_to_CURLE(int err)
return CURLE_AGAIN;
}
- /* TODO: map some more 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;
}
@@ -355,6 +338,7 @@ static void state(struct connectdata *conn, sshstate nowstate)
"SSH_AUTH_HOST",
"SSH_AUTH_KEY_INIT",
"SSH_AUTH_KEY",
+ "SSH_AUTH_GSSAPI",
"SSH_AUTH_DONE",
"SSH_SFTP_INIT",
"SSH_SFTP_REALPATH",
@@ -389,6 +373,7 @@ static void state(struct connectdata *conn, sshstate nowstate)
"SSH_SCP_TRANS_INIT",
"SSH_SCP_UPLOAD_INIT",
"SSH_SCP_DOWNLOAD_INIT",
+ "SSH_SCP_DOWNLOAD",
"SSH_SCP_DONE",
"SSH_SCP_SEND_EOF",
"SSH_SCP_WAIT_EOF",
@@ -399,6 +384,9 @@ static void state(struct connectdata *conn, sshstate nowstate)
"QUIT"
};
+ /* a precaution to make sure the lists are in sync */
+ DEBUGASSERT(sizeof(names)/sizeof(names[0]) == SSH_LAST);
+
if(sshc->state != nowstate) {
infof(conn->data, "SFTP %p state change from %s to %s\n",
(void *)sshc, names[sshc->state], names[nowstate]);
@@ -408,70 +396,6 @@ static void state(struct connectdata *conn, sshstate nowstate)
sshc->state = nowstate;
}
-/* figure out the path to work with in this particular request */
-static CURLcode ssh_getworkingpath(struct connectdata *conn,
- char *homedir, /* when SFTP is used */
- char **path) /* returns the allocated
- real path to work with */
-{
- struct Curl_easy *data = conn->data;
- char *real_path = NULL;
- char *working_path;
- size_t working_path_len;
- CURLcode result =
- Curl_urldecode(data, data->state.path, 0, &working_path,
- &working_path_len, FALSE);
- if(result)
- return result;
-
- /* Check for /~/, indicating relative to the user's home directory */
- if(conn->handler->protocol & CURLPROTO_SCP) {
- real_path = malloc(working_path_len+1);
- if(real_path == NULL) {
- free(working_path);
- return CURLE_OUT_OF_MEMORY;
- }
- if((working_path_len > 3) && (!memcmp(working_path, "/~/", 3)))
- /* It is referenced to the home directory, so strip the leading '/~/' */
- memcpy(real_path, working_path+3, 4 + working_path_len-3);
- else
- memcpy(real_path, working_path, 1 + working_path_len);
- }
- else if(conn->handler->protocol & CURLPROTO_SFTP) {
- if((working_path_len > 1) && (working_path[1] == '~')) {
- size_t homelen = strlen(homedir);
- real_path = malloc(homelen + working_path_len + 1);
- if(real_path == NULL) {
- free(working_path);
- return CURLE_OUT_OF_MEMORY;
- }
- /* It is referenced to the home directory, so strip the
- leading '/' */
- memcpy(real_path, homedir, homelen);
- real_path[homelen] = '/';
- real_path[homelen+1] = '\0';
- if(working_path_len > 3) {
- memcpy(real_path+homelen+1, working_path + 3,
- 1 + working_path_len -3);
- }
- }
- else {
- real_path = malloc(working_path_len+1);
- if(real_path == NULL) {
- free(working_path);
- return CURLE_OUT_OF_MEMORY;
- }
- memcpy(real_path, working_path, 1+working_path_len);
- }
- }
-
- free(working_path);
-
- /* store the pointer for the caller to receive */
- *path = real_path;
-
- return CURLE_OK;
-}
#ifdef HAVE_LIBSSH2_KNOWNHOST_API
static int sshkeycallback(struct Curl_easy *easy,
@@ -600,9 +524,11 @@ static CURLcode ssh_knownhost(struct connectdata *conn)
keymatch = (enum curl_khmatch)keycheck;
/* Ask the callback how to behave */
+ Curl_set_in_callback(data, true);
rc = func(data, knownkeyp, /* from the knownhosts file */
&foundkey, /* from the remote host */
keymatch, data->set.ssh_keyfunc_userp);
+ Curl_set_in_callback(data, false);
}
else
/* no remotekey means failure! */
@@ -661,15 +587,15 @@ static CURLcode ssh_check_fingerprint(struct connectdata *conn)
struct Curl_easy *data = conn->data;
const char *pubkey_md5 = data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5];
char md5buffer[33];
- int i;
const char *fingerprint = libssh2_hostkey_hash(sshc->ssh_session,
LIBSSH2_HOSTKEY_HASH_MD5);
if(fingerprint) {
/* The fingerprint points to static storage (!), don't free() it. */
+ int i;
for(i = 0; i < 16; i++)
- snprintf(&md5buffer[i*2], 3, "%02x", (unsigned char) fingerprint[i]);
+ msnprintf(&md5buffer[i*2], 3, "%02x", (unsigned char) fingerprint[i]);
infof(data, "SSH MD5 fingerprint: %s\n", md5buffer);
}
@@ -729,7 +655,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
libssh2_session_set_blocking(sshc->ssh_session, 0);
state(conn, SSH_S_STARTUP);
- /* fall-through */
+ /* FALLTHROUGH */
case SSH_S_STARTUP:
rc = libssh2_session_startup(sshc->ssh_session, (int)sock);
@@ -737,7 +663,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc) {
- failf(data, "Failure establishing ssh session");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session, &err_msg, NULL, 0);
+ failf(data, "Failure establishing ssh session: %d, %s", rc, err_msg);
+
state(conn, SSH_SESSION_FREE);
sshc->actualcode = CURLE_FAILED_INIT;
break;
@@ -745,7 +674,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_HOSTKEY);
- /* fall-through */
+ /* FALLTHROUGH */
case SSH_HOSTKEY:
/*
* Before we authenticate we should check the hostkey's fingerprint
@@ -804,18 +733,17 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if((data->set.ssh_auth_types & CURLSSH_AUTH_PUBLICKEY) &&
(strstr(sshc->authlist, "publickey") != NULL)) {
- char *home = NULL;
bool out_of_memory = FALSE;
sshc->rsa_pub = sshc->rsa = NULL;
- /* To ponder about: should really the lib be messing about with the
- HOME environment variable etc? */
- home = curl_getenv("HOME");
-
if(data->set.str[STRING_SSH_PRIVATE_KEY])
sshc->rsa = strdup(data->set.str[STRING_SSH_PRIVATE_KEY]);
else {
+ /* To ponder about: should really the lib be messing about with the
+ HOME environment variable etc? */
+ char *home = curl_getenv("HOME");
+
/* If no private key file is specified, try some common paths. */
if(home) {
/* Try ~/.ssh first. */
@@ -831,6 +759,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
Curl_safefree(sshc->rsa);
}
}
+ free(home);
}
if(!out_of_memory && !sshc->rsa) {
/* Nothing found; try the current dir. */
@@ -854,15 +783,14 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
* This is done by simply passing sshc->rsa_pub = NULL.
*/
if(data->set.str[STRING_SSH_PUBLIC_KEY]
- /* treat empty string the same way as NULL */
- && data->set.str[STRING_SSH_PUBLIC_KEY][0]) {
+ /* treat empty string the same way as NULL */
+ && data->set.str[STRING_SSH_PUBLIC_KEY][0]) {
sshc->rsa_pub = strdup(data->set.str[STRING_SSH_PUBLIC_KEY]);
if(!sshc->rsa_pub)
out_of_memory = TRUE;
}
if(out_of_memory || sshc->rsa == NULL) {
- free(home);
Curl_safefree(sshc->rsa);
Curl_safefree(sshc->rsa_pub);
state(conn, SSH_SESSION_FREE);
@@ -874,8 +802,6 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(!sshc->passphrase)
sshc->passphrase = "";
- free(home);
-
if(sshc->rsa_pub)
infof(data, "Using SSH public key file '%s'\n", sshc->rsa_pub);
infof(data, "Using SSH private key file '%s'\n", sshc->rsa);
@@ -909,7 +835,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_AUTH_DONE);
}
else {
- char *err_msg;
+ char *err_msg = NULL;
(void)libssh2_session_last_error(sshc->ssh_session,
&err_msg, NULL, 0);
infof(data, "SSH public key authentication failed: %s\n", err_msg);
@@ -1032,11 +958,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
sshc->sshagent_identity);
if(rc < 0) {
- if(rc != LIBSSH2_ERROR_EAGAIN)
+ if(rc != LIBSSH2_ERROR_EAGAIN) {
/* tried and failed? go to next identity */
sshc->sshagent_prev_identity = sshc->sshagent_identity;
- else
- break;
+ }
+ break;
}
}
@@ -1116,7 +1042,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
*/
sshc->sftp_session = libssh2_sftp_init(sshc->ssh_session);
if(!sshc->sftp_session) {
- char *err_msg;
+ char *err_msg = NULL;
if(libssh2_session_last_errno(sshc->ssh_session) ==
LIBSSH2_ERROR_EAGAIN) {
rc = LIBSSH2_ERROR_EAGAIN;
@@ -1182,7 +1108,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
case SSH_SFTP_QUOTE_INIT:
- result = ssh_getworkingpath(conn, sshc->homedir, &sftp_scp->path);
+ result = Curl_getworkingpath(conn, sshc->homedir, &sftp_scp->path);
if(result) {
sshc->actualcode = result;
state(conn, SSH_STOP);
@@ -1217,6 +1143,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/*
* Support some of the "FTP" commands
+ *
+ * 'sshc->quote_item' is already verified to be non-NULL before it
+ * switched to this state.
*/
char *cmd = sshc->quote_item->data;
sshc->acceptfail = FALSE;
@@ -1242,8 +1171,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(data->set.verbose) {
- Curl_debug(data, CURLINFO_HEADER_OUT, (char *)"PWD\n", 4, conn);
- Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp), conn);
+ Curl_debug(data, CURLINFO_HEADER_OUT, (char *)"PWD\n", 4);
+ Curl_debug(data, CURLINFO_HEADER_IN, tmp, strlen(tmp));
}
/* this sends an FTP-like "header" to the header callback so that the
current directory can be read very similar to how it is read when
@@ -1259,7 +1188,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
state(conn, SSH_SFTP_NEXT_QUOTE);
break;
}
- if(cmd) {
+ {
/*
* the arguments following the command must be separated from the
* command with a space so we can check for it unconditionally
@@ -1277,7 +1206,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
* also, every command takes at least one argument so we get that
* first argument right now
*/
- result = get_pathname(&cp, &sshc->quote_path1);
+ result = Curl_get_pathname(&cp, &sshc->quote_path1, sshc->homedir);
if(result) {
if(result == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -1302,7 +1231,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* sshc->quote_path1 contains the mode to set */
/* get the destination */
- result = get_pathname(&cp, &sshc->quote_path2);
+ result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
if(result) {
if(result == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -1320,11 +1249,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(strncasecompare(cmd, "ln ", 3) ||
- strncasecompare(cmd, "symlink ", 8)) {
+ strncasecompare(cmd, "symlink ", 8)) {
/* symbolic linking */
/* sshc->quote_path1 is the source */
/* get the destination */
- result = get_pathname(&cp, &sshc->quote_path2);
+ result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
if(result) {
if(result == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -1349,7 +1278,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* rename file */
/* first param is the source path */
/* second param is the dest. path */
- result = get_pathname(&cp, &sshc->quote_path2);
+ result = Curl_get_pathname(&cp, &sshc->quote_path2, sshc->homedir);
if(result) {
if(result == CURLE_OUT_OF_MEMORY)
failf(data, "Out of memory");
@@ -1389,9 +1318,6 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
}
- if(!sshc->quote_item) {
- state(conn, SSH_SFTP_GETINFO);
- }
break;
case SSH_SFTP_NEXT_QUOTE:
@@ -1704,7 +1630,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc == 0) {
- data->info.filetime = (long)attrs.mtime;
+ data->info.filetime = attrs.mtime;
}
state(conn, SSH_SFTP_TRANS_INIT);
@@ -1811,7 +1737,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
zero even though libssh2_sftp_open() failed previously! We need
to work around that! */
sshc->actualcode = CURLE_SSH;
- err=-1;
+ err = -1;
}
failf(data, "Upload failed: %s (%d/%d)",
err>= LIBSSH2_FX_OK?sftp_libssh2_strerror(err):"ssh error",
@@ -1824,12 +1750,14 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(data->state.resume_from > 0) {
/* Let's read off the proper amount of bytes from the input. */
if(conn->seek_func) {
+ Curl_set_in_callback(data, true);
seekerr = conn->seek_func(conn->seek_client, data->state.resume_from,
SEEK_SET);
+ Curl_set_in_callback(data, false);
}
if(seekerr != CURL_SEEKFUNC_OK) {
- curl_off_t passed=0;
+ curl_off_t passed = 0;
if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
failf(data, "Could not seek stream");
@@ -1842,9 +1770,12 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
(size_t)data->set.buffer_size :
curlx_sotouz(data->state.resume_from - passed);
- size_t actuallyread =
- data->state.fread_func(data->state.buffer, 1,
- readthisamountnow, data->state.in);
+ size_t actuallyread;
+ Curl_set_in_callback(data, true);
+ actuallyread = data->state.fread_func(data->state.buffer, 1,
+ readthisamountnow,
+ data->state.in);
+ Curl_set_in_callback(data, false);
passed += actuallyread;
if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
@@ -1870,7 +1801,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
Curl_pgrsSetUploadSize(data, data->state.infilesize);
}
/* upload data */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
/* not set by Curl_setup_transfer to preserve keepon bits */
conn->sockfd = conn->writesockfd;
@@ -1981,13 +1912,13 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
sshc->actualcode = result?result:CURLE_SSH;
break;
}
- sshc->readdir_filename = malloc(PATH_MAX+1);
+ sshc->readdir_filename = malloc(PATH_MAX + 1);
if(!sshc->readdir_filename) {
state(conn, SSH_SFTP_CLOSE);
sshc->actualcode = CURLE_OUT_OF_MEMORY;
break;
}
- sshc->readdir_longentry = malloc(PATH_MAX+1);
+ sshc->readdir_longentry = malloc(PATH_MAX + 1);
if(!sshc->readdir_longentry) {
Curl_safefree(sshc->readdir_filename);
state(conn, SSH_SFTP_CLOSE);
@@ -1998,17 +1929,17 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
case SSH_SFTP_READDIR:
- sshc->readdir_len = libssh2_sftp_readdir_ex(sshc->sftp_handle,
- sshc->readdir_filename,
- PATH_MAX,
- sshc->readdir_longentry,
- PATH_MAX,
- &sshc->readdir_attrs);
- if(sshc->readdir_len == LIBSSH2_ERROR_EAGAIN) {
- rc = LIBSSH2_ERROR_EAGAIN;
+ rc = libssh2_sftp_readdir_ex(sshc->sftp_handle,
+ sshc->readdir_filename,
+ PATH_MAX,
+ sshc->readdir_longentry,
+ PATH_MAX,
+ &sshc->readdir_attrs);
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
- if(sshc->readdir_len > 0) {
+ if(rc > 0) {
+ sshc->readdir_len = (size_t) rc;
sshc->readdir_filename[sshc->readdir_len] = '\0';
if(data->set.ftp_list_only) {
@@ -2021,7 +1952,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
result = Curl_client_write(conn, CLIENTWRITE_BODY,
- tmpLine, sshc->readdir_len+1);
+ tmpLine, sshc->readdir_len + 1);
free(tmpLine);
if(result) {
@@ -2030,16 +1961,16 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
}
/* since this counts what we send to the client, we include the
newline in this counter */
- data->req.bytecount += sshc->readdir_len+1;
+ data->req.bytecount += sshc->readdir_len + 1;
/* output debug output if that is requested */
if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_filename,
- sshc->readdir_len, conn);
+ sshc->readdir_len);
}
}
else {
- sshc->readdir_currLen = (int)strlen(sshc->readdir_longentry);
+ sshc->readdir_currLen = strlen(sshc->readdir_longentry);
sshc->readdir_totalLen = 80 + sshc->readdir_currLen;
sshc->readdir_line = calloc(sshc->readdir_totalLen, 1);
if(!sshc->readdir_line) {
@@ -2064,8 +1995,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
- snprintf(sshc->readdir_linkPath, PATH_MAX, "%s%s", sftp_scp->path,
- sshc->readdir_filename);
+ msnprintf(sshc->readdir_linkPath, PATH_MAX, "%s%s", sftp_scp->path,
+ sshc->readdir_filename);
state(conn, SSH_SFTP_READDIR_LINK);
break;
}
@@ -2073,13 +2004,13 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
}
- else if(sshc->readdir_len == 0) {
+ else if(rc == 0) {
Curl_safefree(sshc->readdir_filename);
Curl_safefree(sshc->readdir_longentry);
state(conn, SSH_SFTP_READDIR_DONE);
break;
}
- else if(sshc->readdir_len <= 0) {
+ else if(rc < 0) {
err = sftp_libssh2_last_error(sshc->sftp_session);
result = sftp_libssh2_error_to_CURLE(err);
sshc->actualcode = result?result:CURLE_SSH;
@@ -2094,16 +2025,16 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
case SSH_SFTP_READDIR_LINK:
- sshc->readdir_len =
+ rc =
libssh2_sftp_symlink_ex(sshc->sftp_session,
sshc->readdir_linkPath,
curlx_uztoui(strlen(sshc->readdir_linkPath)),
sshc->readdir_filename,
PATH_MAX, LIBSSH2_SFTP_READLINK);
- if(sshc->readdir_len == LIBSSH2_ERROR_EAGAIN) {
- rc = LIBSSH2_ERROR_EAGAIN;
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
+ sshc->readdir_len = (size_t) rc;
Curl_safefree(sshc->readdir_linkPath);
/* get room for the filename and extra output */
@@ -2120,21 +2051,21 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
}
sshc->readdir_line = new_readdir_line;
- sshc->readdir_currLen += snprintf(sshc->readdir_line +
- sshc->readdir_currLen,
- sshc->readdir_totalLen -
- sshc->readdir_currLen,
- " -> %s",
- sshc->readdir_filename);
+ sshc->readdir_currLen += msnprintf(sshc->readdir_line +
+ sshc->readdir_currLen,
+ sshc->readdir_totalLen -
+ sshc->readdir_currLen,
+ " -> %s",
+ sshc->readdir_filename);
state(conn, SSH_SFTP_READDIR_BOTTOM);
break;
case SSH_SFTP_READDIR_BOTTOM:
- sshc->readdir_currLen += snprintf(sshc->readdir_line +
- sshc->readdir_currLen,
- sshc->readdir_totalLen -
- sshc->readdir_currLen, "\n");
+ sshc->readdir_currLen += msnprintf(sshc->readdir_line +
+ sshc->readdir_currLen,
+ sshc->readdir_totalLen -
+ sshc->readdir_currLen, "\n");
result = Curl_client_write(conn, CLIENTWRITE_BODY,
sshc->readdir_line,
sshc->readdir_currLen);
@@ -2144,7 +2075,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* output debug output if that is requested */
if(data->set.verbose) {
Curl_debug(data, CURLINFO_DATA_OUT, sshc->readdir_line,
- sshc->readdir_currLen, conn);
+ sshc->readdir_currLen);
}
data->req.bytecount += sshc->readdir_currLen;
}
@@ -2167,7 +2098,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
Curl_safefree(sshc->readdir_longentry);
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
state(conn, SSH_STOP);
break;
@@ -2208,8 +2139,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc ||
- !(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) ||
- (attrs.filesize == 0)) {
+ !(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) ||
+ (attrs.filesize == 0)) {
/*
* libssh2_sftp_open() didn't return an error, so maybe the server
* just doesn't support stat()
@@ -2231,18 +2162,25 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
curl_off_t from, to;
char *ptr;
char *ptr2;
+ CURLofft to_t;
+ CURLofft from_t;
- from=curlx_strtoofft(conn->data->state.range, &ptr, 0);
- while(*ptr && (ISSPACE(*ptr) || (*ptr=='-')))
+ from_t = curlx_strtoofft(conn->data->state.range, &ptr, 0, &from);
+ if(from_t == CURL_OFFT_FLOW)
+ return CURLE_RANGE_ERROR;
+ while(*ptr && (ISSPACE(*ptr) || (*ptr == '-')))
ptr++;
- to=curlx_strtoofft(ptr, &ptr2, 0);
- if((ptr == ptr2) /* no "to" value given */
+ to_t = curlx_strtoofft(ptr, &ptr2, 0, &to);
+ if(to_t == CURL_OFFT_FLOW)
+ return CURLE_RANGE_ERROR;
+ if((to_t == CURL_OFFT_INVAL) /* no "to" value given */
|| (to >= size)) {
to = size - 1;
}
- if(from < 0) {
+ if(from_t) {
/* from is relative to end of file */
- from += size;
+ from = size - to;
+ to = size - 1;
}
if(from > size) {
failf(data, "Offset (%"
@@ -2300,13 +2238,12 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* Setup the actual download */
if(data->req.size == 0) {
/* no data to transfer */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
infof(data, "File already completely downloaded\n");
state(conn, SSH_STOP);
break;
}
- Curl_setup_transfer(conn, FIRSTSOCKET, data->req.size,
- FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, data->req.size, FALSE, -1);
/* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd;
@@ -2334,12 +2271,15 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc < 0) {
- infof(data, "Failed to close libssh2 file\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to close libssh2 file: %d %s\n", rc, err_msg);
}
sshc->sftp_handle = NULL;
}
- if(sftp_scp)
- Curl_safefree(sftp_scp->path);
+
+ Curl_safefree(sftp_scp->path);
DEBUGF(infof(data, "SFTP DONE done\n"));
@@ -2368,7 +2308,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc < 0) {
- infof(data, "Failed to close libssh2 file\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session, &err_msg,
+ NULL, 0);
+ infof(data, "Failed to close libssh2 file: %d %s\n", rc, err_msg);
}
sshc->sftp_handle = NULL;
}
@@ -2390,7 +2333,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
case SSH_SCP_TRANS_INIT:
- result = ssh_getworkingpath(conn, sshc->homedir, &sftp_scp->path);
+ result = Curl_getworkingpath(conn, sshc->homedir, &sftp_scp->path);
if(result) {
sshc->actualcode = result;
state(conn, SSH_STOP);
@@ -2423,7 +2366,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
data->state.infilesize);
if(!sshc->ssh_channel) {
int ssh_err;
- char *err_msg;
+ char *err_msg = NULL;
if(libssh2_session_last_errno(sshc->ssh_session) ==
LIBSSH2_ERROR_EAGAIN) {
@@ -2436,12 +2379,15 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
failf(conn->data, "%s", err_msg);
state(conn, SSH_SCP_CHANNEL_FREE);
sshc->actualcode = libssh2_session_error_to_CURLE(ssh_err);
+ /* Map generic errors to upload failed */
+ if(sshc->actualcode == CURLE_SSH ||
+ sshc->actualcode == CURLE_REMOTE_FILE_NOT_FOUND)
+ sshc->actualcode = CURLE_UPLOAD_FAILED;
break;
}
/* upload data */
- Curl_setup_transfer(conn, -1, data->req.size, FALSE, NULL,
- FIRSTSOCKET, NULL);
+ Curl_setup_transfer(data, -1, data->req.size, FALSE, FIRSTSOCKET);
/* not set by Curl_setup_transfer to preserve keepon bits */
conn->sockfd = conn->writesockfd;
@@ -2473,9 +2419,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
* be set in sb
*/
- /*
- * If support for >2GB files exists, use it.
- */
+ /*
+ * If support for >2GB files exists, use it.
+ */
/* get a fresh new channel from the ssh layer */
#if LIBSSH2_VERSION_NUM < 0x010700
@@ -2492,7 +2438,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(!sshc->ssh_channel) {
int ssh_err;
- char *err_msg;
+ char *err_msg = NULL;
if(libssh2_session_last_errno(sshc->ssh_session) ==
LIBSSH2_ERROR_EAGAIN) {
@@ -2512,7 +2458,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* download data */
bytecount = (curl_off_t)sb.st_size;
data->req.maxdownload = (curl_off_t)sb.st_size;
- Curl_setup_transfer(conn, FIRSTSOCKET, bytecount, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, FIRSTSOCKET, bytecount, FALSE, -1);
/* not set by Curl_setup_transfer to preserve keepon bits */
conn->writesockfd = conn->sockfd;
@@ -2545,7 +2491,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc) {
- infof(data, "Failed to send libssh2 channel EOF\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to send libssh2 channel EOF: %d %s\n",
+ rc, err_msg);
}
}
state(conn, SSH_SCP_WAIT_EOF);
@@ -2558,7 +2508,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc) {
- infof(data, "Failed to get channel EOF: %d\n", rc);
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to get channel EOF: %d %s\n", rc, err_msg);
}
}
state(conn, SSH_SCP_WAIT_CLOSE);
@@ -2571,7 +2524,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc) {
- infof(data, "Channel failed to close: %d\n", rc);
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Channel failed to close: %d %s\n", rc, err_msg);
}
}
state(conn, SSH_SCP_CHANNEL_FREE);
@@ -2584,7 +2540,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc < 0) {
- infof(data, "Failed to free libssh2 scp subsystem\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to free libssh2 scp subsystem: %d %s\n",
+ rc, err_msg);
}
sshc->ssh_channel = NULL;
}
@@ -2606,7 +2566,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc < 0) {
- infof(data, "Failed to free libssh2 scp subsystem\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to free libssh2 scp subsystem: %d %s\n",
+ rc, err_msg);
}
sshc->ssh_channel = NULL;
}
@@ -2617,7 +2581,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc < 0) {
- infof(data, "Failed to disconnect libssh2 session\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to disconnect libssh2 session: %d %s\n",
+ rc, err_msg);
}
}
@@ -2642,7 +2610,11 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc < 0) {
- infof(data, "Failed to disconnect from libssh2 agent\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to disconnect from libssh2 agent: %d %s\n",
+ rc, err_msg);
}
libssh2_agent_free(sshc->ssh_agent);
sshc->ssh_agent = NULL;
@@ -2660,7 +2632,10 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
break;
}
if(rc < 0) {
- infof(data, "Failed to free libssh2 session\n");
+ char *err_msg = NULL;
+ (void)libssh2_session_last_error(sshc->ssh_session,
+ &err_msg, NULL, 0);
+ infof(data, "Failed to free libssh2 session: %d %s\n", rc, err_msg);
}
sshc->ssh_session = NULL;
}
@@ -2807,9 +2782,12 @@ static CURLcode ssh_multi_statemach(struct connectdata *conn, bool *done)
CURLcode result = CURLE_OK;
bool block; /* we store the status and use that to provide a ssh_getsock()
implementation */
-
- result = ssh_statemach_act(conn, &block);
- *done = (sshc->state == SSH_STOP) ? TRUE : FALSE;
+ do {
+ result = ssh_statemach_act(conn, &block);
+ *done = (sshc->state == SSH_STOP) ? TRUE : FALSE;
+ /* if there's no error, it isn't done and it didn't EWOULDBLOCK, then
+ try again */
+ } while(!result && !*done && !block);
ssh_block2waitfor(conn, block);
return result;
@@ -2824,8 +2802,8 @@ static CURLcode ssh_block_statemach(struct connectdata *conn,
while((sshc->state != SSH_STOP) && !result) {
bool block;
- time_t left = 1000;
- struct timeval now = Curl_tvnow();
+ timediff_t left = 1000;
+ struct curltime now = Curl_now();
result = ssh_statemach_act(conn, &block);
if(result)
@@ -2933,12 +2911,19 @@ static CURLcode ssh_connect(struct connectdata *conn, bool *done)
return CURLE_FAILED_INIT;
}
+ if(data->set.ssh_compression) {
+#if LIBSSH2_VERSION_NUM >= 0x010208
+ if(libssh2_session_flag(ssh->ssh_session, LIBSSH2_FLAG_COMPRESS, 1) < 0)
+#endif
+ infof(data, "Failed to enable compression for ssh session\n");
+ }
+
#ifdef HAVE_LIBSSH2_KNOWNHOST_API
if(data->set.str[STRING_SSH_KNOWNHOSTS]) {
int rc;
ssh->kh = libssh2_knownhost_init(ssh->ssh_session);
if(!ssh->kh) {
- /* eeek. TODO: free the ssh_session! */
+ libssh2_session_free(ssh->ssh_session);
return CURLE_FAILED_INIT;
}
@@ -3029,8 +3014,8 @@ static CURLcode ssh_do(struct connectdata *conn, bool *done)
data->req.size = -1; /* make sure this is unknown at this point */
sshc->actualcode = CURLE_OK; /* reset error code */
- sshc->secondCreateDirs =0; /* reset the create dir attempt state
- variable */
+ sshc->secondCreateDirs = 0; /* reset the create dir attempt state
+ variable */
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
@@ -3073,12 +3058,7 @@ static CURLcode ssh_done(struct connectdata *conn, CURLcode status)
struct SSHPROTO *sftp_scp = conn->data->req.protop;
if(!status) {
- /* run the state-machine
-
- TODO: when the multi interface is used, this _really_ should be using
- the ssh_multi_statemach function but we have no general support for
- non-blocking DONE operations!
- */
+ /* run the state-machine */
result = ssh_block_statemach(conn, FALSE);
}
else
@@ -3231,12 +3211,9 @@ static CURLcode sftp_done(struct connectdata *conn, CURLcode status,
/* Post quote commands are executed after the SFTP_CLOSE state to avoid
errors that could happen due to open file handles during POSTQUOTE
operation */
- if(!status && !premature && conn->data->set.postquote) {
+ if(!premature && conn->data->set.postquote && !conn->bits.retry)
sshc->nextstate = SSH_SFTP_POSTQUOTE_INIT;
- state(conn, SSH_SFTP_CLOSE);
- }
- else
- state(conn, SSH_SFTP_CLOSE);
+ state(conn, SSH_SFTP_CLOSE);
}
return ssh_done(conn, status);
}
@@ -3291,93 +3268,6 @@ static ssize_t sftp_recv(struct connectdata *conn, int sockindex,
return nread;
}
-/* The get_pathname() function is being borrowed from OpenSSH sftp.c
- version 4.6p1. */
-/*
- * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-static CURLcode
-get_pathname(const char **cpp, char **path)
-{
- const char *cp = *cpp, *end;
- char quot;
- unsigned int i, j;
- static const char WHITESPACE[] = " \t\r\n";
-
- cp += strspn(cp, WHITESPACE);
- if(!*cp) {
- *cpp = cp;
- *path = NULL;
- return CURLE_QUOTE_ERROR;
- }
-
- *path = malloc(strlen(cp) + 1);
- if(*path == NULL)
- return CURLE_OUT_OF_MEMORY;
-
- /* Check for quoted filenames */
- if(*cp == '\"' || *cp == '\'') {
- quot = *cp++;
-
- /* Search for terminating quote, unescape some chars */
- for(i = j = 0; i <= strlen(cp); i++) {
- if(cp[i] == quot) { /* Found quote */
- i++;
- (*path)[j] = '\0';
- break;
- }
- if(cp[i] == '\0') { /* End of string */
- /*error("Unterminated quote");*/
- goto fail;
- }
- if(cp[i] == '\\') { /* Escaped characters */
- i++;
- if(cp[i] != '\'' && cp[i] != '\"' &&
- cp[i] != '\\') {
- /*error("Bad escaped character '\\%c'",
- cp[i]);*/
- goto fail;
- }
- }
- (*path)[j++] = cp[i];
- }
-
- if(j == 0) {
- /*error("Empty quotes");*/
- goto fail;
- }
- *cpp = cp + i + strspn(cp + i, WHITESPACE);
- }
- else {
- /* Read to end of filename */
- end = strpbrk(cp, WHITESPACE);
- if(end == NULL)
- end = strchr(cp, '\0');
- *cpp = end + strspn(end, WHITESPACE);
-
- memcpy(*path, cp, end - cp);
- (*path)[end - cp] = '\0';
- }
- return CURLE_OK;
-
- fail:
- Curl_safefree(*path);
- return CURLE_QUOTE_ERROR;
-}
-
-
static const char *sftp_libssh2_strerror(int err)
{
switch(err) {
diff --git a/Utilities/cmcurl/lib/ssh.h b/Utilities/cmcurl/lib/ssh.h
index b350dcf3a..0620aac32 100644
--- a/Utilities/cmcurl/lib/ssh.h
+++ b/Utilities/cmcurl/lib/ssh.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -24,9 +24,12 @@
#include "curl_setup.h"
-#ifdef HAVE_LIBSSH2_H
+#if defined(HAVE_LIBSSH2_H)
#include <libssh2.h>
#include <libssh2_sftp.h>
+#elif defined(HAVE_LIBSSH_LIBSSH_H)
+#include <libssh/libssh.h>
+#include <libssh/sftp.h>
#endif /* HAVE_LIBSSH2_H */
/****************************************************************************
@@ -51,6 +54,7 @@ typedef enum {
SSH_AUTH_HOST,
SSH_AUTH_KEY_INIT,
SSH_AUTH_KEY,
+ SSH_AUTH_GSSAPI,
SSH_AUTH_DONE,
SSH_SFTP_INIT,
SSH_SFTP_REALPATH, /* Last state in SSH-CONNECT */
@@ -86,6 +90,7 @@ typedef enum {
SSH_SCP_TRANS_INIT, /* First state in SCP-DO */
SSH_SCP_UPLOAD_INIT,
SSH_SCP_DOWNLOAD_INIT,
+ SSH_SCP_DOWNLOAD,
SSH_SCP_DONE,
SSH_SCP_SEND_EOF,
SSH_SCP_WAIT_EOF,
@@ -109,7 +114,8 @@ struct SSHPROTO {
struct */
struct ssh_conn {
const char *authlist; /* List of auth. methods, managed by libssh2 */
-#ifdef USE_LIBSSH2
+
+ /* common */
const char *passphrase; /* pass-phrase to use */
char *rsa_pub; /* path name */
char *rsa; /* path name */
@@ -120,17 +126,12 @@ struct ssh_conn {
struct curl_slist *quote_item; /* for the quote option */
char *quote_path1; /* two generic pointers for the QUOTE stuff */
char *quote_path2;
- LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */
+
bool acceptfail; /* used by the SFTP_QUOTE (continue if
quote command fails) */
char *homedir; /* when doing SFTP we figure out home dir in the
connect phase */
-
- /* Here's a set of struct members used by the SFTP_READDIR state */
- LIBSSH2_SFTP_ATTRIBUTES readdir_attrs;
- char *readdir_filename;
- char *readdir_longentry;
- int readdir_len, readdir_totalLen, readdir_currLen;
+ size_t readdir_len, readdir_totalLen, readdir_currLen;
char *readdir_line;
char *readdir_linkPath;
/* end of READDIR stuff */
@@ -139,11 +140,42 @@ struct ssh_conn {
second attempt has been made to change
to/create a directory */
char *slash_pos; /* used by the SFTP_CREATE_DIRS state */
+
+ int orig_waitfor; /* default READ/WRITE bits wait for */
+
+#if defined(USE_LIBSSH)
+/* our variables */
+ unsigned kbd_state; /* 0 or 1 */
+ ssh_key privkey;
+ ssh_key pubkey;
+ int auth_methods;
+ ssh_session ssh_session;
+ ssh_scp scp_session;
+ sftp_session sftp_session;
+ sftp_file sftp_file;
+ sftp_dir sftp_dir;
+
+ unsigned sftp_recv_state; /* 0 or 1 */
+ int sftp_file_index; /* for async read */
+ sftp_attributes readdir_attrs; /* used by the SFTP readdir actions */
+ sftp_attributes readdir_link_attrs; /* used by the SFTP readdir actions */
+ sftp_attributes quote_attrs; /* used by the SFTP_QUOTE state */
+
+ const char *readdir_filename; /* points within readdir_attrs */
+ const char *readdir_longentry;
+ char *readdir_tmp;
+#elif defined(USE_LIBSSH2)
+ char *readdir_filename;
+ char *readdir_longentry;
+
+ LIBSSH2_SFTP_ATTRIBUTES quote_attrs; /* used by the SFTP_QUOTE state */
+
+ /* Here's a set of struct members used by the SFTP_READDIR state */
+ LIBSSH2_SFTP_ATTRIBUTES readdir_attrs;
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;
- int orig_waitfor; /* default READ/WRITE bits wait for */
#ifdef HAVE_LIBSSH2_AGENT_API
LIBSSH2_AGENT *ssh_agent; /* proxy to ssh-agent/pageant */
@@ -156,10 +188,17 @@ struct ssh_conn {
#ifdef HAVE_LIBSSH2_KNOWNHOST_API
LIBSSH2_KNOWNHOSTS *kh;
#endif
-#endif /* USE_LIBSSH2 */
+#endif /* USE_LIBSSH */
};
-#ifdef USE_LIBSSH2
+#if defined(USE_LIBSSH)
+
+#define CURL_LIBSSH_VERSION ssh_version(0)
+
+extern const struct Curl_handler Curl_handler_scp;
+extern const struct Curl_handler Curl_handler_sftp;
+
+#elif defined(USE_LIBSSH2)
/* Feature detection based on version numbers to better work with
non-configure platforms */
@@ -190,6 +229,14 @@ struct ssh_conn {
#define HAVE_LIBSSH2_SESSION_HANDSHAKE 1
#endif
+#ifdef HAVE_LIBSSH2_VERSION
+/* get it run-time if possible */
+#define CURL_LIBSSH2_VERSION libssh2_version(0)
+#else
+/* use build-time if run-time not possible */
+#define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
+#endif
+
extern const struct Curl_handler Curl_handler_scp;
extern const struct Curl_handler Curl_handler_sftp;
diff --git a/Utilities/cmcurl/lib/strcase.c b/Utilities/cmcurl/lib/strcase.c
index a74a4be57..24bcca932 100644
--- a/Utilities/cmcurl/lib/strcase.c
+++ b/Utilities/cmcurl/lib/strcase.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -94,10 +94,11 @@ char Curl_raw_toupper(char in)
}
/*
- * Curl_raw_equal() is for doing "raw" case insensitive strings. This is meant
- * to be locale independent and only compare strings we know are safe for
- * this. See https://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for
- * some further explanation to why this function is necessary.
+ * Curl_strcasecompare() is for doing "raw" case insensitive strings. This is
+ * meant to be locale independent and only compare strings we know are safe
+ * for this. See
+ * https://daniel.haxx.se/blog/2008/10/15/strcasecmp-in-turkish/ for some
+ * further explanation to why this function is necessary.
*
* The function is capable of comparing a-z case insensitively even for
* non-ascii.
diff --git a/Utilities/cmcurl/lib/strcase.h b/Utilities/cmcurl/lib/strcase.h
index ea2abc8b6..6fee3840e 100644
--- a/Utilities/cmcurl/lib/strcase.h
+++ b/Utilities/cmcurl/lib/strcase.h
@@ -46,6 +46,5 @@ char Curl_raw_toupper(char in);
#define checkprefix(a,b) curl_strnequal(a,b,strlen(a))
void Curl_strntoupper(char *dest, const char *src, size_t n);
-char Curl_raw_toupper(char in);
#endif /* HEADER_CURL_STRCASE_H */
diff --git a/Utilities/cmcurl/lib/strdup.c b/Utilities/cmcurl/lib/strdup.c
index 136b69377..51e7978b7 100644
--- a/Utilities/cmcurl/lib/strdup.c
+++ b/Utilities/cmcurl/lib/strdup.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -44,11 +44,11 @@ char *curlx_strdup(const char *str)
if(len >= ((size_t)-1) / sizeof(char))
return (char *)NULL;
- newstr = malloc((len+1)*sizeof(char));
+ newstr = malloc((len + 1)*sizeof(char));
if(!newstr)
return (char *)NULL;
- memcpy(newstr, str, (len+1)*sizeof(char));
+ memcpy(newstr, str, (len + 1)*sizeof(char));
return newstr;
@@ -81,7 +81,7 @@ void *Curl_memdup(const void *src, size_t length)
* Curl_saferealloc(ptr, size)
*
* Does a normal realloc(), but will free the data pointer if the realloc
- * fails. If 'size' is zero, it will free the data and return a failure.
+ * fails. If 'size' is non-zero, it will free the data and return a failure.
*
* This convenience function is provided and used to help us avoid a common
* mistake pattern when we could pass in a zero, catch the NULL return and end
diff --git a/Utilities/cmcurl/lib/strerror.c b/Utilities/cmcurl/lib/strerror.c
index 7e5cde47b..e273f3765 100644
--- a/Utilities/cmcurl/lib/strerror.c
+++ b/Utilities/cmcurl/lib/strerror.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2004 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2004 - 2019, 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
@@ -49,6 +49,10 @@
#include "curl_memory.h"
#include "memdebug.h"
+#if defined(WIN32) || defined(_WIN32_WCE)
+#define PRESERVE_WINDOWS_ERROR_CODE
+#endif
+
const char *
curl_easy_strerror(CURLcode error)
{
@@ -187,9 +191,6 @@ curl_easy_strerror(CURLcode error)
case CURLE_TELNET_OPTION_SYNTAX :
return "Malformed telnet option";
- case CURLE_PEER_FAILED_VERIFICATION:
- return "SSL peer certificate or SSH remote key was not OK";
-
case CURLE_GOT_NOTHING:
return "Server returned nothing (no headers, no data)";
@@ -214,9 +215,8 @@ curl_easy_strerror(CURLcode error)
case CURLE_SSL_CIPHER:
return "Couldn't use specified SSL cipher";
- case CURLE_SSL_CACERT:
- return "Peer certificate cannot be authenticated with given CA "
- "certificates";
+ case CURLE_PEER_FAILED_VERIFICATION:
+ return "SSL peer certificate or SSH remote key was not OK";
case CURLE_SSL_CACERT_BADFILE:
return "Problem with the SSL CA cert (path? access rights?)";
@@ -308,6 +308,9 @@ curl_easy_strerror(CURLcode error)
case CURLE_HTTP2_STREAM:
return "Stream error in the HTTP/2 framing layer";
+ case CURLE_RECURSIVE_API_CALL:
+ return "API function called from within callback";
+
/* error codes not used by current libcurl */
case CURLE_OBSOLETE20:
case CURLE_OBSOLETE24:
@@ -317,6 +320,7 @@ curl_easy_strerror(CURLcode error)
case CURLE_OBSOLETE44:
case CURLE_OBSOLETE46:
case CURLE_OBSOLETE50:
+ case CURLE_OBSOLETE51:
case CURLE_OBSOLETE57:
case CURL_LAST:
break;
@@ -376,6 +380,9 @@ curl_multi_strerror(CURLMcode error)
case CURLM_ADDED_ALREADY:
return "The easy handle is already added to a multi handle";
+ case CURLM_RECURSIVE_API_CALL:
+ return "API function called from within callback";
+
case CURLM_LAST:
break;
}
@@ -432,6 +439,10 @@ curl_share_strerror(CURLSHcode error)
static const char *
get_winsock_error (int err, char *buf, size_t len)
{
+#ifdef PRESERVE_WINDOWS_ERROR_CODE
+ DWORD old_win_err = GetLastError();
+#endif
+ int old_errno = errno;
const char *p;
#ifndef CURL_DISABLE_VERBOSE_STRINGS
@@ -611,6 +622,15 @@ get_winsock_error (int err, char *buf, size_t len)
#endif
strncpy(buf, p, len);
buf [len-1] = '\0';
+
+ if(errno != old_errno)
+ errno = old_errno;
+
+#ifdef PRESERVE_WINDOWS_ERROR_CODE
+ if(old_win_err != GetLastError())
+ SetLastError(old_win_err);
+#endif
+
return buf;
}
#endif /* USE_WINSOCK */
@@ -626,17 +646,18 @@ get_winsock_error (int err, char *buf, size_t len)
* 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)
+const char *Curl_strerror(int err, char *buf, size_t buflen)
{
- char *buf, *p;
+#ifdef PRESERVE_WINDOWS_ERROR_CODE
+ DWORD old_win_err = GetLastError();
+#endif
+ int old_errno = errno;
+ char *p;
size_t max;
- int old_errno = ERRNO;
- DEBUGASSERT(conn);
DEBUGASSERT(err >= 0);
- buf = conn->syserr_buf;
- max = sizeof(conn->syserr_buf)-1;
+ max = buflen - 1;
*buf = '\0';
#ifdef USE_WINSOCK
@@ -658,7 +679,7 @@ const char *Curl_strerror(struct connectdata *conn, int err)
if(!get_winsock_error(err, buf, max) &&
!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
LANG_NEUTRAL, buf, (DWORD)max, NULL))
- snprintf(buf, max, "Unknown error %d (%#x)", err, err);
+ msnprintf(buf, max, "Unknown error %d (%#x)", err, err);
}
#endif
@@ -672,7 +693,7 @@ const char *Curl_strerror(struct connectdata *conn, int err)
*/
if(0 != strerror_r(err, buf, max)) {
if('\0' == buf[0])
- snprintf(buf, max, "Unknown error %d", err);
+ msnprintf(buf, max, "Unknown error %d", err);
}
#elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
/*
@@ -686,7 +707,7 @@ const char *Curl_strerror(struct connectdata *conn, int err)
if(msg)
strncpy(buf, msg, max);
else
- snprintf(buf, max, "Unknown error %d", err);
+ msnprintf(buf, max, "Unknown error %d", err);
}
#elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
/*
@@ -698,7 +719,7 @@ const char *Curl_strerror(struct connectdata *conn, int err)
if(OK == strerror_r(err, buffer))
strncpy(buf, buffer, max);
else
- snprintf(buf, max, "Unknown error %d", err);
+ msnprintf(buf, max, "Unknown error %d", err);
}
#else
{
@@ -706,7 +727,7 @@ const char *Curl_strerror(struct connectdata *conn, int err)
if(msg)
strncpy(buf, msg, max);
else
- snprintf(buf, max, "Unknown error %d", err);
+ msnprintf(buf, max, "Unknown error %d", err);
}
#endif
@@ -722,36 +743,40 @@ const char *Curl_strerror(struct connectdata *conn, int err)
if(p && (p - buf) >= 1)
*p = '\0';
- if(old_errno != ERRNO)
- SET_ERRNO(old_errno);
+ if(errno != old_errno)
+ errno = old_errno;
+
+#ifdef PRESERVE_WINDOWS_ERROR_CODE
+ if(old_win_err != GetLastError())
+ SetLastError(old_win_err);
+#endif
return buf;
}
#ifdef USE_WINDOWS_SSPI
-const char *Curl_sspi_strerror (struct connectdata *conn, int err)
+const char *Curl_sspi_strerror(int err, char *buf, size_t buflen)
{
+#ifdef PRESERVE_WINDOWS_ERROR_CODE
+ DWORD old_win_err = GetLastError();
+#endif
+ int old_errno = errno;
+ const char *txt;
+ char *outbuf;
+ size_t outmax;
#ifndef CURL_DISABLE_VERBOSE_STRINGS
char txtbuf[80];
- char msgbuf[sizeof(conn->syserr_buf)];
+ char msgbuf[256];
char *p, *str, *msg = NULL;
bool msg_formatted = FALSE;
- int old_errno;
#endif
- const char *txt;
- char *outbuf;
- size_t outmax;
-
- DEBUGASSERT(conn);
- outbuf = conn->syserr_buf;
- outmax = sizeof(conn->syserr_buf)-1;
+ outbuf = buf;
+ outmax = buflen - 1;
*outbuf = '\0';
#ifndef CURL_DISABLE_VERBOSE_STRINGS
- old_errno = ERRNO;
-
switch(err) {
case SEC_E_OK:
txt = "No error";
@@ -1003,14 +1028,14 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err)
if(err == SEC_E_OK)
strncpy(outbuf, txt, outmax);
else if(err == SEC_E_ILLEGAL_MESSAGE)
- snprintf(outbuf, outmax,
- "SEC_E_ILLEGAL_MESSAGE (0x%08X) - This error usually occurs "
- "when a fatal SSL/TLS alert is received (e.g. handshake failed). "
- "More detail may be available in the Windows System event log.",
- err);
+ msnprintf(outbuf, outmax,
+ "SEC_E_ILLEGAL_MESSAGE (0x%08X) - This error usually occurs "
+ "when a fatal SSL/TLS alert is received (e.g. handshake failed)."
+ " More detail may be available in the Windows System event log.",
+ err);
else {
str = txtbuf;
- snprintf(txtbuf, sizeof(txtbuf), "%s (0x%08X)", txt, err);
+ msnprintf(txtbuf, sizeof(txtbuf), "%s (0x%08X)", txt, err);
txtbuf[sizeof(txtbuf)-1] = '\0';
#ifdef _WIN32_WCE
@@ -1046,14 +1071,11 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err)
msg = msgbuf;
}
if(msg)
- snprintf(outbuf, outmax, "%s - %s", str, msg);
+ msnprintf(outbuf, outmax, "%s - %s", str, msg);
else
strncpy(outbuf, str, outmax);
}
- if(old_errno != ERRNO)
- SET_ERRNO(old_errno);
-
#else
if(err == SEC_E_OK)
@@ -1067,6 +1089,14 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err)
outbuf[outmax] = '\0';
+ if(errno != old_errno)
+ errno = old_errno;
+
+#ifdef PRESERVE_WINDOWS_ERROR_CODE
+ if(old_win_err != GetLastError())
+ SetLastError(old_win_err);
+#endif
+
return outbuf;
}
#endif /* USE_WINDOWS_SSPI */
diff --git a/Utilities/cmcurl/lib/strerror.h b/Utilities/cmcurl/lib/strerror.h
index 627273eb2..683b5b4a3 100644
--- a/Utilities/cmcurl/lib/strerror.h
+++ b/Utilities/cmcurl/lib/strerror.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -24,14 +24,11 @@
#include "urldata.h"
-const char *Curl_strerror (struct connectdata *conn, int err);
-
-#ifdef USE_LIBIDN2
-const char *Curl_idn_strerror (struct connectdata *conn, int err);
-#endif
+#define STRERROR_LEN 128 /* a suitable length */
+const char *Curl_strerror(int err, char *buf, size_t buflen);
#ifdef USE_WINDOWS_SSPI
-const char *Curl_sspi_strerror (struct connectdata *conn, int err);
+const char *Curl_sspi_strerror(int err, char *buf, size_t buflen);
#endif
#endif /* HEADER_CURL_STRERROR_H */
diff --git a/Utilities/cmcurl/lib/strtoofft.c b/Utilities/cmcurl/lib/strtoofft.c
index b854bf4de..546a3ff75 100644
--- a/Utilities/cmcurl/lib/strtoofft.c
+++ b/Utilities/cmcurl/lib/strtoofft.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, 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
@@ -20,6 +20,7 @@
*
***************************************************************************/
+#include <errno.h>
#include "curl_setup.h"
#include "strtoofft.h"
@@ -29,10 +30,32 @@
*
* 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
+ * https://www.opengroup.org/onlinepubs/009695399/functions/strtoimax.html
*/
-#ifdef NEED_CURL_STRTOLL
+#if (SIZEOF_CURL_OFF_T > SIZEOF_LONG)
+# ifdef HAVE_STRTOLL
+# define strtooff strtoll
+# else
+# if defined(_MSC_VER) && (_MSC_VER >= 1300) && (_INTEGRAL_MAX_BITS >= 64)
+# if defined(_SAL_VERSION)
+ _Check_return_ _CRTIMP __int64 __cdecl _strtoi64(
+ _In_z_ const char *_String,
+ _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix);
+# else
+ _CRTIMP __int64 __cdecl _strtoi64(const char *_String,
+ char **_EndPtr, int _Radix);
+# endif
+# define strtooff _strtoi64
+# else
+# define PRIVATE_STRTOOFF 1
+# endif
+# endif
+#else
+# define strtooff strtol
+#endif
+
+#ifdef PRIVATE_STRTOOFF
/* Range tests can be used for alphanum decoding if characters are consecutive,
like in ASCII. Else an array is scanned. Determine this condition now. */
@@ -48,11 +71,10 @@ static const char valchars[] =
static int get_char(char c, int base);
/**
- * Emulated version of the strtoll function. This extracts a long long
+ * Custom version of the strtooff function. This extracts a curl_off_t
* value from the given input string and returns it.
*/
-curl_off_t
-curlx_strtoll(const char *nptr, char **endptr, int base)
+static curl_off_t strtooff(const char *nptr, char **endptr, int base)
{
char *end;
int is_negative = 0;
@@ -132,7 +154,7 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
else
value = CURL_OFF_T_MAX;
- SET_ERRNO(ERANGE);
+ errno = ERANGE;
}
if(endptr)
@@ -186,3 +208,35 @@ static int get_char(char c, int base)
return value;
}
#endif /* Only present if we need strtoll, but don't have it. */
+
+/*
+ * Parse a *positive* up to 64 bit number written in ascii.
+ */
+CURLofft curlx_strtoofft(const char *str, char **endp, int base,
+ curl_off_t *num)
+{
+ char *end;
+ curl_off_t number;
+ errno = 0;
+ *num = 0; /* clear by default */
+
+ while(*str && ISSPACE(*str))
+ str++;
+ if('-' == *str) {
+ if(endp)
+ *endp = (char *)str; /* didn't actually move */
+ return CURL_OFFT_INVAL; /* nothing parsed */
+ }
+ number = strtooff(str, &end, base);
+ if(endp)
+ *endp = end;
+ if(errno == ERANGE)
+ /* overflow/underflow */
+ return CURL_OFFT_FLOW;
+ else if(str == end)
+ /* nothing parsed */
+ return CURL_OFFT_INVAL;
+
+ *num = number;
+ return CURL_OFFT_OK;
+}
diff --git a/Utilities/cmcurl/lib/strtoofft.h b/Utilities/cmcurl/lib/strtoofft.h
index f4039f3a3..be19cd716 100644
--- a/Utilities/cmcurl/lib/strtoofft.h
+++ b/Utilities/cmcurl/lib/strtoofft.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -40,36 +40,13 @@
* of 'long' the conversion function to use is strtol().
*/
-#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
-# ifdef HAVE_STRTOLL
-# define curlx_strtoofft strtoll
-# else
-# if defined(_MSC_VER) && (_MSC_VER >= 1300) && (_INTEGRAL_MAX_BITS >= 64)
-# if defined(_SAL_VERSION)
- _Check_return_ _CRTIMP __int64 __cdecl _strtoi64(
- _In_z_ const char *_String,
- _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix);
-# else
- _CRTIMP __int64 __cdecl _strtoi64(const char *_String,
- char **_EndPtr, int _Radix);
-# endif
-# define curlx_strtoofft _strtoi64
-# else
- curl_off_t curlx_strtoll(const char *nptr, char **endptr, int base);
-# define curlx_strtoofft curlx_strtoll
-# define NEED_CURL_STRTOLL 1
-# endif
-# endif
-#else
-# define curlx_strtoofft strtol
-#endif
+typedef enum {
+ CURL_OFFT_OK, /* parsed fine */
+ CURL_OFFT_FLOW, /* over or underflow */
+ CURL_OFFT_INVAL /* nothing was parsed */
+} CURLofft;
-#if (CURL_SIZEOF_CURL_OFF_T == 4)
-# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
-#else
- /* assume CURL_SIZEOF_CURL_OFF_T == 8 */
-# define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
-#endif
-#define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
+CURLofft curlx_strtoofft(const char *str, char **endp, int base,
+ curl_off_t *num);
#endif /* HEADER_CURL_STRTOOFFT_H */
diff --git a/Utilities/cmcurl/lib/system_win32.c b/Utilities/cmcurl/lib/system_win32.c
index cfbbf3279..f7f817dd4 100644
--- a/Utilities/cmcurl/lib/system_win32.c
+++ b/Utilities/cmcurl/lib/system_win32.c
@@ -26,11 +26,94 @@
#include <curl/curl.h>
#include "system_win32.h"
+#include "curl_sspi.h"
+#include "warnless.h"
/* The last #include files should be: */
#include "curl_memory.h"
#include "memdebug.h"
+LARGE_INTEGER Curl_freq;
+bool Curl_isVistaOrGreater;
+
+/* Curl_win32_init() performs win32 global initialization */
+CURLcode Curl_win32_init(long flags)
+{
+ /* CURL_GLOBAL_WIN32 controls the *optional* part of the initialization which
+ is just for Winsock at the moment. Any required win32 initialization
+ should take place after this block. */
+ if(flags & CURL_GLOBAL_WIN32) {
+#ifdef USE_WINSOCK
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int res;
+
+#if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
+#error IPV6_requires_winsock2
+#endif
+
+ wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
+
+ res = WSAStartup(wVersionRequested, &wsaData);
+
+ if(res != 0)
+ /* Tell the user that we couldn't find a usable */
+ /* 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 usable */
+
+ /* winsock.dll. */
+ WSACleanup();
+ return CURLE_FAILED_INIT;
+ }
+ /* The Windows Sockets DLL is acceptable. Proceed. */
+ #elif defined(USE_LWIPSOCK)
+ lwip_init();
+ #endif
+ } /* CURL_GLOBAL_WIN32 */
+
+#ifdef USE_WINDOWS_SSPI
+ {
+ CURLcode result = Curl_sspi_global_init();
+ if(result)
+ return result;
+ }
+#endif
+
+ if(Curl_verify_windows_version(6, 0, PLATFORM_WINNT,
+ VERSION_GREATER_THAN_EQUAL)) {
+ Curl_isVistaOrGreater = TRUE;
+ QueryPerformanceFrequency(&Curl_freq);
+ }
+ else
+ Curl_isVistaOrGreater = FALSE;
+
+ return CURLE_OK;
+}
+
+/* Curl_win32_cleanup() is the opposite of Curl_win32_init() */
+void Curl_win32_cleanup(long init_flags)
+{
+#ifdef USE_WINDOWS_SSPI
+ Curl_sspi_global_cleanup();
+#endif
+
+ if(init_flags & CURL_GLOBAL_WIN32) {
+#ifdef USE_WINSOCK
+ WSACleanup();
+#endif
+ }
+}
+
#if defined(USE_WINDOWS_SSPI) || (!defined(CURL_DISABLE_TELNET) && \
defined(USE_WINSOCK))
@@ -134,8 +217,9 @@ bool Curl_verify_windows_version(const unsigned int majorVersion,
break;
case VERSION_LESS_THAN_EQUAL:
- if(osver.dwMajorVersion <= majorVersion &&
- osver.dwMinorVersion <= minorVersion)
+ if(osver.dwMajorVersion < majorVersion ||
+ (osver.dwMajorVersion == majorVersion &&
+ osver.dwMinorVersion <= minorVersion))
matched = TRUE;
break;
@@ -146,8 +230,9 @@ bool Curl_verify_windows_version(const unsigned int majorVersion,
break;
case VERSION_GREATER_THAN_EQUAL:
- if(osver.dwMajorVersion >= majorVersion &&
- osver.dwMinorVersion >= minorVersion)
+ if(osver.dwMajorVersion > majorVersion ||
+ (osver.dwMajorVersion == majorVersion &&
+ osver.dwMinorVersion >= minorVersion))
matched = TRUE;
break;
@@ -278,7 +363,9 @@ HMODULE Curl_load_library(LPCTSTR filename)
/* Attempt to find LoadLibraryEx() which is only available on Windows 2000
and above */
- pLoadLibraryEx = (LOADLIBRARYEX_FN) GetProcAddress(hKernel32, LOADLIBARYEX);
+ pLoadLibraryEx =
+ CURLX_FUNCTION_CAST(LOADLIBRARYEX_FN,
+ (GetProcAddress(hKernel32, LOADLIBARYEX)));
/* Detect if there's already a path in the filename and load the library if
there is. Note: Both back slashes and forward slashes have been supported
diff --git a/Utilities/cmcurl/lib/system_win32.h b/Utilities/cmcurl/lib/system_win32.h
index 1e772856b..926328a9a 100644
--- a/Utilities/cmcurl/lib/system_win32.h
+++ b/Utilities/cmcurl/lib/system_win32.h
@@ -26,6 +26,12 @@
#if defined(WIN32)
+extern LARGE_INTEGER Curl_freq;
+extern bool Curl_isVistaOrGreater;
+
+CURLcode Curl_win32_init(long flags);
+void Curl_win32_cleanup(long init_flags);
+
/* Version condition */
typedef enum {
VERSION_LESS_THAN,
diff --git a/Utilities/cmcurl/lib/telnet.c b/Utilities/cmcurl/lib/telnet.c
index 155d4b260..955255c36 100644
--- a/Utilities/cmcurl/lib/telnet.c
+++ b/Utilities/cmcurl/lib/telnet.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -52,10 +52,6 @@
#include "connect.h"
#include "progress.h"
#include "system_win32.h"
-
-#define TELOPTS
-#define TELCMDS
-
#include "arpa_telnet.h"
#include "select.h"
#include "strcase.h"
@@ -74,10 +70,10 @@
x->subend = x->subpointer; \
CURL_SB_CLEAR(x); \
} WHILE_FALSE
-#define CURL_SB_ACCUM(x,c) \
- do { \
- if(x->subpointer < (x->subbuffer+sizeof x->subbuffer)) \
- *x->subpointer++ = (c); \
+#define CURL_SB_ACCUM(x,c) \
+ do { \
+ if(x->subpointer < (x->subbuffer + sizeof(x->subbuffer))) \
+ *x->subpointer++ = (c); \
} WHILE_FALSE
#define CURL_SB_GET(x) ((*x->subpointer++)&0xff)
@@ -92,6 +88,7 @@
#endif
#ifdef USE_WINSOCK
+typedef WSAEVENT (WINAPI *WSOCK2_EVENT)(void);
typedef FARPROC WSOCK2_FUNC;
static CURLcode check_wsock2(struct Curl_easy *data);
#endif
@@ -109,8 +106,10 @@ static void printoption(struct Curl_easy *data,
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 set_local_option(struct connectdata *conn,
+ int option, int newstate);
+static void set_remote_option(struct connectdata *conn,
+ int option, int newstate);
static void printsub(struct Curl_easy *data,
int direction, unsigned char *pointer,
@@ -192,6 +191,7 @@ const struct Curl_handler Curl_handler_telnet = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_TELNET, /* defport */
CURLPROTO_TELNET, /* protocol */
PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */
@@ -294,8 +294,8 @@ static void negotiate(struct connectdata *conn)
int i;
struct TELNET *tn = (struct TELNET *) conn->data->req.protop;
- for(i = 0;i < CURL_NTELOPTS;i++) {
- if(i==CURL_TELOPT_ECHO)
+ for(i = 0; i < CURL_NTELOPTS; i++) {
+ if(i == CURL_TELOPT_ECHO)
continue;
if(tn->us_preferred[i] == CURL_YES)
@@ -310,9 +310,6 @@ static void negotiate(struct connectdata *conn)
static void printoption(struct Curl_easy *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))
@@ -321,9 +318,12 @@ static void printoption(struct Curl_easy *data,
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;
+ const char *fmt = (cmd == CURL_WILL) ? "WILL" :
+ (cmd == CURL_WONT) ? "WONT" :
+ (cmd == CURL_DO) ? "DO" :
+ (cmd == CURL_DONT) ? "DONT" : 0;
if(fmt) {
+ const char *opt;
if(CURL_TELOPT_OK(option))
opt = CURL_TELOPT(option);
else if(option == CURL_TELOPT_EXOPL)
@@ -347,7 +347,6 @@ static void send_negotiation(struct connectdata *conn, int cmd, int option)
{
unsigned char buf[3];
ssize_t bytes_written;
- int err;
struct Curl_easy *data = conn->data;
buf[0] = CURL_IAC;
@@ -356,7 +355,7 @@ static void send_negotiation(struct connectdata *conn, int cmd, int option)
bytes_written = swrite(conn->sock[FIRSTSOCKET], buf, 3);
if(bytes_written < 0) {
- err = SOCKERRNO;
+ int err = SOCKERRNO;
failf(data,"Sending data failed (%d)",err);
}
@@ -709,9 +708,8 @@ static void printsub(struct Curl_easy *data,
unsigned char *pointer, /* where suboption data is */
size_t length) /* length of suboption data */
{
- unsigned int i = 0;
-
if(data->set.verbose) {
+ unsigned int i = 0;
if(direction) {
infof(data, "%s IAC SB ", (direction == '<')? "RCVD":"SENT");
if(length >= 3) {
@@ -763,7 +761,7 @@ static void printsub(struct Curl_easy *data,
switch(pointer[0]) {
case CURL_TELOPT_NAWS:
if(length > 4)
- infof(data, "Width: %hu ; Height: %hu", (pointer[1]<<8) | pointer[2],
+ infof(data, "Width: %d ; Height: %d", (pointer[1]<<8) | pointer[2],
(pointer[3]<<8) | pointer[4]);
break;
default:
@@ -791,7 +789,7 @@ static void printsub(struct Curl_easy *data,
case CURL_TELOPT_NEW_ENVIRON:
if(pointer[1] == CURL_TELQUAL_IS) {
infof(data, " ");
- for(i = 3;i < length;i++) {
+ for(i = 3; i < length; i++) {
switch(pointer[i]) {
case CURL_NEW_ENV_VAR:
infof(data, ", ");
@@ -831,7 +829,7 @@ static CURLcode check_telnet_options(struct connectdata *conn)
/* 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);
+ msnprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user);
beg = curl_slist_append(tn->telnet_vars, option_arg);
if(!beg) {
curl_slist_free_all(tn->telnet_vars);
@@ -842,7 +840,7 @@ static CURLcode check_telnet_options(struct connectdata *conn)
tn->us_preferred[CURL_TELOPT_NEW_ENVIRON] = CURL_YES;
}
- for(head = data->set.telnet_options; head; head=head->next) {
+ for(head = data->set.telnet_options; head; head = head->next) {
if(sscanf(head->data, "%127[^= ]%*[ =]%255s",
option_keyword, option_arg) == 2) {
@@ -889,8 +887,8 @@ static CURLcode check_telnet_options(struct connectdata *conn)
/* To take care or not of the 8th bit in data exchange */
if(strcasecompare(option_keyword, "BINARY")) {
- binary_option=atoi(option_arg);
- if(binary_option!=1) {
+ binary_option = atoi(option_arg);
+ if(binary_option != 1) {
tn->us_preferred[CURL_TELOPT_BINARY] = CURL_NO;
tn->him_preferred[CURL_TELOPT_BINARY] = CURL_NO;
}
@@ -898,7 +896,7 @@ static CURLcode check_telnet_options(struct connectdata *conn)
}
failf(data, "Unknown telnet option %s", head->data);
- result = CURLE_UNKNOWN_TELNET_OPTION;
+ result = CURLE_UNKNOWN_OPTION;
break;
}
failf(data, "Syntax error in telnet option: %s", head->data);
@@ -927,20 +925,19 @@ static void suboption(struct connectdata *conn)
unsigned char temp[2048];
ssize_t bytes_written;
size_t len;
- size_t tmplen;
int err;
char varname[128] = "";
char varval[128] = "";
struct Curl_easy *data = conn->data;
struct TELNET *tn = (struct TELNET *)data->req.protop;
- printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn)+2);
+ 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);
+ msnprintf((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 = SOCKERRNO;
@@ -950,9 +947,9 @@ static void suboption(struct connectdata *conn)
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);
+ msnprintf((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 = SOCKERRNO;
@@ -961,25 +958,25 @@ static void suboption(struct connectdata *conn)
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);
+ msnprintf((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);
+ for(v = tn->telnet_vars; v; v = v->next) {
+ size_t tmplen = (strlen(v->data) + 1);
/* Add the variable only if it fits */
if(len + tmplen < (int)sizeof(temp)-6) {
if(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);
+ msnprintf((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);
+ msnprintf((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) {
@@ -1016,10 +1013,10 @@ static void sendsuboption(struct connectdata *conn, int option)
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, CURL_SB);
CURL_SB_ACCUM(tn, CURL_TELOPT_NAWS);
- /* We must deal either with litte or big endian processors */
+ /* We must deal either with little or big endian processors */
/* Window size must be sent according to the 'network order' */
- x=htons(tn->subopt_wsx);
- y=htons(tn->subopt_wsy);
+ x = htons(tn->subopt_wsx);
+ y = htons(tn->subopt_wsy);
uc1 = (unsigned char *)&x;
uc2 = (unsigned char *)&y;
CURL_SB_ACCUM(tn, uc1[0]);
@@ -1032,7 +1029,7 @@ static void sendsuboption(struct connectdata *conn, int option)
CURL_SB_TERM(tn);
/* data suboption is now ready */
- printsub(data, '>', (unsigned char *)tn->subbuffer+2,
+ printsub(data, '>', (unsigned char *)tn->subbuffer + 2,
CURL_SB_LEN(tn)-2);
/* we send the header of the suboption... */
@@ -1043,9 +1040,9 @@ static void sendsuboption(struct connectdata *conn, int option)
}
/* ... then the window size with the send_telnet_data() function
to deal with 0xFF cases ... */
- send_telnet_data(conn, (char *)tn->subbuffer+3, 4);
+ send_telnet_data(conn, (char *)tn->subbuffer + 3, 4);
/* ... and the footer */
- bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer+7, 2);
+ bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer + 7, 2);
if(bytes_written < 0) {
err = SOCKERRNO;
failf(data, "Sending data failed (%d)", err);
@@ -1063,7 +1060,7 @@ CURLcode telrcv(struct connectdata *conn,
unsigned char c;
CURLcode result;
int in = 0;
- int startwrite=-1;
+ int startwrite = -1;
struct Curl_easy *data = conn->data;
struct TELNET *tn = (struct TELNET *)data->req.protop;
@@ -1202,8 +1199,7 @@ CURLcode telrcv(struct connectdata *conn,
CURL_SB_ACCUM(tn, c);
tn->telrcv_state = CURL_TS_SB;
}
- else
- {
+ else {
CURL_SB_ACCUM(tn, CURL_IAC);
CURL_SB_ACCUM(tn, CURL_SE);
tn->subpointer -= 2;
@@ -1223,7 +1219,7 @@ CURLcode telrcv(struct connectdata *conn,
static CURLcode send_telnet_data(struct connectdata *conn,
char *buffer, ssize_t nread)
{
- ssize_t escapes, i, j, outlen;
+ ssize_t escapes, i, outlen;
unsigned char *outbuf = NULL;
CURLcode result = CURLE_OK;
ssize_t bytes_written, total_written;
@@ -1238,6 +1234,7 @@ static CURLcode send_telnet_data(struct connectdata *conn,
if(outlen == nread)
outbuf = (unsigned char *)buffer;
else {
+ ssize_t j;
outbuf = malloc(nread + escapes + 1);
if(!outbuf)
return CURLE_OUT_OF_MEMORY;
@@ -1306,7 +1303,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
#ifdef USE_WINSOCK
HMODULE wsock2;
WSOCK2_FUNC close_event_func;
- WSOCK2_FUNC create_event_func;
+ WSOCK2_EVENT create_event_func;
WSOCK2_FUNC event_select_func;
WSOCK2_FUNC enum_netevents_func;
WSAEVENT event_handle;
@@ -1315,7 +1312,6 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
HANDLE objs[2];
DWORD obj_count;
DWORD wait_timeout;
- DWORD waitret;
DWORD readfile_read;
int err;
#else
@@ -1326,7 +1322,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
curl_off_t total_ul = 0;
#endif
ssize_t nread;
- struct timeval now;
+ struct curltime now;
bool keepon = TRUE;
char *buf = data->state.buffer;
struct TELNET *tn;
@@ -1356,14 +1352,16 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
/* load ws2_32.dll and get the function pointers we need. */
wsock2 = Curl_load_library(TEXT("WS2_32.DLL"));
if(wsock2 == NULL) {
- failf(data, "failed to load WS2_32.DLL (%d)", ERRNO);
+ failf(data, "failed to load WS2_32.DLL (%u)", GetLastError());
return CURLE_FAILED_INIT;
}
/* Grab a pointer to WSACreateEvent */
- create_event_func = GetProcAddress(wsock2, "WSACreateEvent");
+ create_event_func =
+ CURLX_FUNCTION_CAST(WSOCK2_EVENT,
+ (GetProcAddress(wsock2, "WSACreateEvent")));
if(create_event_func == NULL) {
- failf(data, "failed to find WSACreateEvent function (%d)", ERRNO);
+ failf(data, "failed to find WSACreateEvent function (%u)", GetLastError());
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@@ -1371,7 +1369,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
/* And WSACloseEvent */
close_event_func = GetProcAddress(wsock2, "WSACloseEvent");
if(close_event_func == NULL) {
- failf(data, "failed to find WSACloseEvent function (%d)", ERRNO);
+ failf(data, "failed to find WSACloseEvent function (%u)", GetLastError());
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@@ -1379,7 +1377,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
/* And WSAEventSelect */
event_select_func = GetProcAddress(wsock2, "WSAEventSelect");
if(event_select_func == NULL) {
- failf(data, "failed to find WSAEventSelect function (%d)", ERRNO);
+ failf(data, "failed to find WSAEventSelect function (%u)", GetLastError());
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@@ -1387,7 +1385,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
/* And WSAEnumNetworkEvents */
enum_netevents_func = GetProcAddress(wsock2, "WSAEnumNetworkEvents");
if(enum_netevents_func == NULL) {
- failf(data, "failed to find WSAEnumNetworkEvents function (%d)", ERRNO);
+ failf(data, "failed to find WSAEnumNetworkEvents function (%u)",
+ GetLastError());
FreeLibrary(wsock2);
return CURLE_FAILED_INIT;
}
@@ -1437,7 +1436,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
/* Keep on listening and act on events */
while(keepon) {
const DWORD buf_size = (DWORD)data->set.buffer_size;
- waitret = WaitForMultipleObjects(obj_count, objs, FALSE, wait_timeout);
+ DWORD waitret = WaitForMultipleObjects(obj_count, objs,
+ FALSE, wait_timeout);
switch(waitret) {
case WAIT_TIMEOUT:
{
@@ -1458,7 +1458,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
if(n == 0) /* no bytes */
break;
- readfile_read = (DWORD)n; /* fall thru with number of bytes read */
+ /* fall through with number of bytes read */
+ readfile_read = (DWORD)n;
}
else {
/* read from stdin */
@@ -1558,8 +1559,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
}
if(data->set.timeout) {
- now = Curl_tvnow();
- if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {
+ now = Curl_now();
+ if(Curl_timediff(now, conn->created) >= data->set.timeout) {
failf(data, "Time-out");
result = CURLE_OPERATION_TIMEDOUT;
keepon = FALSE;
@@ -1580,7 +1581,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
/* We called LoadLibrary, so call FreeLibrary */
if(!FreeLibrary(wsock2))
- infof(data, "FreeLibrary(wsock2) failed (%d)", ERRNO);
+ infof(data, "FreeLibrary(wsock2) failed (%u)", GetLastError());
#else
pfd[0].fd = sockfd;
pfd[0].events = POLLIN;
@@ -1605,7 +1606,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
case 0: /* timeout */
pfd[0].revents = 0;
pfd[1].revents = 0;
- /* fall through */
+ /* FALLTHROUGH */
default: /* read! */
if(pfd[0].revents & POLLIN) {
/* read data from network */
@@ -1676,8 +1677,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
} /* poll switch statement */
if(data->set.timeout) {
- now = Curl_tvnow();
- if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {
+ now = Curl_now();
+ if(Curl_timediff(now, conn->created) >= data->set.timeout) {
failf(data, "Time-out");
result = CURLE_OPERATION_TIMEDOUT;
keepon = FALSE;
@@ -1691,7 +1692,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
}
#endif
/* mark this as "no further transfer wanted" */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
return result;
}
diff --git a/Utilities/cmcurl/lib/telnet.h b/Utilities/cmcurl/lib/telnet.h
index 419a399b7..668a78a13 100644
--- a/Utilities/cmcurl/lib/telnet.h
+++ b/Utilities/cmcurl/lib/telnet.h
@@ -26,4 +26,3 @@ extern const struct Curl_handler Curl_handler_telnet;
#endif
#endif /* HEADER_CURL_TELNET_H */
-
diff --git a/Utilities/cmcurl/lib/tftp.c b/Utilities/cmcurl/lib/tftp.c
index b2b3efe0c..289cda282 100644
--- a/Utilities/cmcurl/lib/tftp.c
+++ b/Utilities/cmcurl/lib/tftp.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -76,12 +76,12 @@
#define TFTP_OPTION_INTERVAL "timeout"
typedef enum {
- TFTP_MODE_NETASCII=0,
+ TFTP_MODE_NETASCII = 0,
TFTP_MODE_OCTET
} tftp_mode_t;
typedef enum {
- TFTP_STATE_START=0,
+ TFTP_STATE_START = 0,
TFTP_STATE_RX,
TFTP_STATE_TX,
TFTP_STATE_FIN
@@ -100,7 +100,7 @@ typedef enum {
} tftp_event_t;
typedef enum {
- TFTP_ERR_UNDEF=0,
+ TFTP_ERR_UNDEF = 0,
TFTP_ERR_NOTFOUND,
TFTP_ERR_PERM,
TFTP_ERR_DISKFULL,
@@ -181,6 +181,7 @@ const struct Curl_handler Curl_handler_tftp = {
ZERO_NULL, /* perform_getsock */
tftp_disconnect, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
PORT_TFTP, /* defport */
CURLPROTO_TFTP, /* protocol */
PROTOPT_NONE | PROTOPT_NOURLQUERY /* flags */
@@ -199,7 +200,7 @@ const struct Curl_handler Curl_handler_tftp = {
static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
{
time_t maxtime, timeout;
- time_t timeout_ms;
+ timediff_t timeout_ms;
bool start = (state->state == TFTP_STATE_START) ? TRUE : FALSE;
time(&state->start_time);
@@ -216,7 +217,7 @@ static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
if(start) {
maxtime = (time_t)(timeout_ms + 500) / 1000;
- state->max_time = state->start_time+maxtime;
+ state->max_time = state->start_time + maxtime;
/* Set per-block timeout to total */
timeout = maxtime;
@@ -231,7 +232,7 @@ static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
/* 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;
+ state->retry_time = 1;
}
else {
@@ -240,7 +241,7 @@ static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
else
maxtime = 3600;
- state->max_time = state->start_time+maxtime;
+ state->max_time = state->start_time + maxtime;
/* Set per-block timeout to total */
timeout = maxtime;
@@ -250,15 +251,15 @@ static CURLcode tftp_set_timeouts(tftp_state_data_t *state)
}
/* But bound the total number */
if(state->retry_max<3)
- state->retry_max=3;
+ state->retry_max = 3;
if(state->retry_max>50)
- 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;
+ state->retry_time = 1;
infof(state->conn->data,
"set timeouts for state %d; Total %ld, retry %d maxtry %d\n",
@@ -320,7 +321,7 @@ static const char *tftp_option_get(const char *buf, size_t len,
return NULL;
*option = buf;
- loc += Curl_strnlen(buf+loc, len-loc);
+ loc += Curl_strnlen(buf + loc, len-loc);
loc++; /* NULL term */
if(loc > len)
@@ -450,7 +451,6 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
ssize_t senddata;
const char *mode = "octet";
char *filename;
- char buf[64];
struct Curl_easy *data = state->conn->data;
CURLcode result = CURLE_OK;
@@ -474,7 +474,7 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
/* If we are uploading, send an WRQ */
setpacketevent(&state->spacket, TFTP_EVENT_WRQ);
state->conn->data->req.upload_fromhere =
- (char *)state->spacket.data+4;
+ (char *)state->spacket.data + 4;
if(data->state.infilesize != -1)
Curl_pgrsSetUploadSize(data, data->state.infilesize);
}
@@ -485,45 +485,52 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
/* 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. */
- result = Curl_urldecode(data, &state->conn->data->state.path[1], 0,
+ result = Curl_urldecode(data, &state->conn->data->state.up.path[1], 0,
&filename, NULL, FALSE);
if(result)
return result;
- snprintf((char *)state->spacket.data+2,
- state->blksize,
- "%s%c%s%c", filename, '\0', mode, '\0');
+ if(strlen(filename) > (state->blksize - strlen(mode) - 4)) {
+ failf(data, "TFTP file name too long\n");
+ free(filename);
+ return CURLE_TFTP_ILLEGAL; /* too long file name field */
+ }
+
+ msnprintf((char *)state->spacket.data + 2,
+ state->blksize,
+ "%s%c%s%c", filename, '\0', mode, '\0');
sbytes = 4 + strlen(filename) + strlen(mode);
/* optional addition of TFTP options */
if(!data->set.tftp_no_options) {
+ char buf[64];
/* add tsize option */
if(data->set.upload && (data->state.infilesize != -1))
- snprintf(buf, sizeof(buf), "%" CURL_FORMAT_CURL_OFF_T,
- data->state.infilesize);
+ msnprintf(buf, sizeof(buf), "%" CURL_FORMAT_CURL_OFF_T,
+ data->state.infilesize);
else
strcpy(buf, "0"); /* the destination is large enough */
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes,
+ (char *)state->spacket.data + sbytes,
TFTP_OPTION_TSIZE);
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes, buf);
+ (char *)state->spacket.data + sbytes, buf);
/* add blksize option */
- snprintf(buf, sizeof(buf), "%d", state->requested_blksize);
+ msnprintf(buf, sizeof(buf), "%d", state->requested_blksize);
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes,
+ (char *)state->spacket.data + sbytes,
TFTP_OPTION_BLKSIZE);
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes, buf);
+ (char *)state->spacket.data + sbytes, buf);
/* add timeout option */
- snprintf(buf, sizeof(buf), "%d", state->retry_time);
+ msnprintf(buf, sizeof(buf), "%d", state->retry_time);
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes,
+ (char *)state->spacket.data + sbytes,
TFTP_OPTION_INTERVAL);
sbytes += tftp_option_add(state, sbytes,
- (char *)state->spacket.data+sbytes, buf);
+ (char *)state->spacket.data + sbytes, buf);
}
/* the typecase for the 3rd argument is mostly for systems that do
@@ -533,7 +540,8 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
state->conn->ip_addr->ai_addr,
state->conn->ip_addr->ai_addrlen);
if(senddata != (ssize_t)sbytes) {
- failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
+ char buffer[STRERROR_LEN];
+ failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
}
free(filename);
break;
@@ -569,7 +577,7 @@ static CURLcode tftp_send_first(tftp_state_data_t *state, tftp_event_t event)
/* the next blocknum is x + 1 but it needs to wrap at an unsigned 16bit
boundary */
-#define NEXT_BLOCKNUM(x) (((x)+1)&0xffff)
+#define NEXT_BLOCKNUM(x) (((x) + 1)&0xffff)
/**********************************************************
*
@@ -583,6 +591,7 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
ssize_t sbytes;
int rblock;
struct Curl_easy *data = state->conn->data;
+ char buffer[STRERROR_LEN];
switch(event) {
@@ -615,12 +624,12 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
if(sbytes < 0) {
- failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
+ failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
return CURLE_SEND_ERROR;
}
/* Check if completed (That is, a less than full packet is received) */
- if(state->rbytes < (ssize_t)state->blksize+4) {
+ if(state->rbytes < (ssize_t)state->blksize + 4) {
state->state = TFTP_STATE_FIN;
}
else {
@@ -640,7 +649,7 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
if(sbytes < 0) {
- failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
+ failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
return CURLE_SEND_ERROR;
}
@@ -666,7 +675,7 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event)
(struct sockaddr *)&state->remote_addr,
state->remote_addrlen);
if(sbytes<0) {
- failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
+ failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
return CURLE_SEND_ERROR;
}
}
@@ -703,10 +712,10 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
{
struct Curl_easy *data = state->conn->data;
ssize_t sbytes;
- int rblock;
CURLcode result = CURLE_OK;
struct SingleRequest *k = &data->req;
- int cb; /* Bytes currently read */
+ size_t cb; /* Bytes currently read */
+ char buffer[STRERROR_LEN];
switch(event) {
@@ -714,7 +723,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
case TFTP_EVENT_OACK:
if(event == TFTP_EVENT_ACK) {
/* Ack the packet */
- rblock = getrpacketblock(&state->rpacket);
+ int rblock = getrpacketblock(&state->rpacket);
if(rblock != state->block &&
/* There's a bug in tftpd-hpa that causes it to send us an ack for
@@ -736,12 +745,13 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
else {
/* Re-send the data packet */
sbytes = sendto(state->sockfd, (void *)state->spacket.data,
- 4+state->sbytes, SEND_4TH_ARG,
+ 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", Curl_strerror(state->conn, SOCKERRNO));
+ failf(data, "%s", Curl_strerror(SOCKERRNO,
+ buffer, sizeof(buffer)));
result = CURLE_SEND_ERROR;
}
}
@@ -759,7 +769,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->retries = 0;
setpacketevent(&state->spacket, TFTP_EVENT_DATA);
setpacketblock(&state->spacket, state->block);
- if(state->block > 1 && state->sbytes < (int)state->blksize) {
+ if(state->block > 1 && state->sbytes < state->blksize) {
state->state = TFTP_STATE_FIN;
return CURLE_OK;
}
@@ -769,13 +779,13 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
* data block.
* */
state->sbytes = 0;
- state->conn->data->req.upload_fromhere = (char *)state->spacket.data+4;
+ state->conn->data->req.upload_fromhere = (char *)state->spacket.data + 4;
do {
result = Curl_fillreadbuffer(state->conn, state->blksize - state->sbytes,
&cb);
if(result)
return result;
- state->sbytes += cb;
+ state->sbytes += (int)cb;
state->conn->data->req.upload_fromhere += cb;
} while(state->sbytes < state->blksize && cb != 0);
@@ -785,7 +795,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
state->remote_addrlen);
/* Check all sbytes were sent */
if(sbytes<0) {
- failf(data, "%s", Curl_strerror(state->conn, SOCKERRNO));
+ failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
return CURLE_SEND_ERROR;
}
/* Update the progress meter */
@@ -806,12 +816,12 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
else {
/* Re-send the data packet */
sbytes = sendto(state->sockfd, (void *)state->spacket.data,
- 4+state->sbytes, SEND_4TH_ARG,
+ 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", Curl_strerror(state->conn, SOCKERRNO));
+ failf(data, "%s", Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
return CURLE_SEND_ERROR;
}
/* since this was a re-send, we remain at the still byte position */
@@ -962,7 +972,7 @@ static CURLcode tftp_disconnect(struct connectdata *conn, bool dead_connection)
static CURLcode tftp_connect(struct connectdata *conn, bool *done)
{
tftp_state_data_t *state;
- int blksize, rc;
+ int blksize;
blksize = TFTP_BLKSIZE_DEFAULT;
@@ -999,11 +1009,11 @@ static CURLcode tftp_connect(struct connectdata *conn, bool *done)
state->sockfd = state->conn->sock[FIRSTSOCKET];
state->state = TFTP_STATE_START;
state->error = TFTP_ERR_NONE;
- state->blksize = TFTP_BLKSIZE_DEFAULT;
+ state->blksize = blksize;
state->requested_blksize = blksize;
((struct sockaddr *)&state->local_addr)->sa_family =
- (unsigned short)(conn->ip_addr->ai_family);
+ (CURL_SA_FAMILY_T)(conn->ip_addr->ai_family);
tftp_set_timeouts(state);
@@ -1021,11 +1031,12 @@ static CURLcode tftp_connect(struct connectdata *conn, bool *done)
* 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);
+ int rc = bind(state->sockfd, (struct sockaddr *)&state->local_addr,
+ conn->ip_addr->ai_addrlen);
if(rc) {
+ char buffer[STRERROR_LEN];
failf(conn->data, "bind() failed; %s",
- Curl_strerror(conn, SOCKERRNO));
+ Curl_strerror(SOCKERRNO, buffer, sizeof(buffer)));
return CURLE_COULDNT_CONNECT;
}
conn->bits.bound = TRUE;
@@ -1102,11 +1113,11 @@ static CURLcode tftp_receive_packet(struct connectdata *conn)
fromlen = sizeof(fromaddr);
state->rbytes = (int)recvfrom(state->sockfd,
(void *)state->rpacket.data,
- state->blksize+4,
+ state->blksize + 4,
0,
(struct sockaddr *)&fromaddr,
&fromlen);
- if(state->remote_addrlen==0) {
+ if(state->remote_addrlen == 0) {
memcpy(&state->remote_addr, &fromaddr, fromlen);
state->remote_addrlen = fromlen;
}
@@ -1128,7 +1139,7 @@ static CURLcode tftp_receive_packet(struct connectdata *conn)
if(state->rbytes > 4 &&
(NEXT_BLOCKNUM(state->block) == getrpacketblock(&state->rpacket))) {
result = Curl_client_write(conn, CLIENTWRITE_BODY,
- (char *)state->rpacket.data+4,
+ (char *)state->rpacket.data + 4,
state->rbytes-4);
if(result) {
tftp_state_machine(state, TFTP_EVENT_ERROR);
@@ -1141,15 +1152,18 @@ static CURLcode tftp_receive_packet(struct connectdata *conn)
case TFTP_EVENT_ERROR:
{
unsigned short error = getrpacketblock(&state->rpacket);
+ char *str = (char *)state->rpacket.data + 4;
+ size_t strn = state->rbytes - 4;
state->error = (tftp_error_t)error;
- infof(data, "%s\n", (const char *)state->rpacket.data+4);
+ if(Curl_strnlen(str, strn) < strn)
+ infof(data, "TFTP error: %s\n", str);
break;
}
case TFTP_EVENT_ACK:
break;
case TFTP_EVENT_OACK:
result = tftp_parse_option_ack(state,
- (const char *)state->rpacket.data+2,
+ (const char *)state->rpacket.data + 2,
state->rbytes-2);
if(result)
return result;
@@ -1193,7 +1207,7 @@ static long tftp_state_timeout(struct connectdata *conn, tftp_event_t *event)
state->state = TFTP_STATE_FIN;
return 0;
}
- if(current > state->rx_time+state->retry_time) {
+ if(current > state->rx_time + state->retry_time) {
if(event)
*event = TFTP_EVENT_TIMEOUT;
time(&state->rx_time); /* update even though we received nothing */
@@ -1214,7 +1228,6 @@ static long tftp_state_timeout(struct connectdata *conn, tftp_event_t *event)
**********************************************************/
static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done)
{
- int rc;
tftp_event_t event;
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
@@ -1234,16 +1247,17 @@ static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done)
*done = (state->state == TFTP_STATE_FIN) ? TRUE : FALSE;
if(*done)
/* Tell curl we're done */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
}
else {
/* no timeouts to handle, check our socket */
- rc = SOCKET_READABLE(state->sockfd, 0);
+ int rc = SOCKET_READABLE(state->sockfd, 0);
if(rc == -1) {
/* bail out */
int error = SOCKERRNO;
- failf(data, "%s", Curl_strerror(conn, error));
+ char buffer[STRERROR_LEN];
+ failf(data, "%s", Curl_strerror(error, buffer, sizeof(buffer)));
state->event = TFTP_EVENT_ERROR;
}
else if(rc != 0) {
@@ -1256,7 +1270,7 @@ static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done)
*done = (state->state == TFTP_STATE_FIN) ? TRUE : FALSE;
if(*done)
/* Tell curl we're done */
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
}
/* if rc == 0, then select() timed out */
}
@@ -1286,7 +1300,7 @@ static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
- result = Curl_speedcheck(conn->data, Curl_tvnow());
+ result = Curl_speedcheck(conn->data, Curl_now());
}
return result;
}
@@ -1344,7 +1358,7 @@ static CURLcode tftp_do(struct connectdata *conn, bool *done)
state = (tftp_state_data_t *)conn->proto.tftpc;
if(!state)
- return CURLE_BAD_CALLING_ORDER;
+ return CURLE_TFTP_ILLEGAL;
result = tftp_perform(conn, done);
@@ -1361,18 +1375,18 @@ static CURLcode tftp_setup_connection(struct connectdata * conn)
{
struct Curl_easy *data = conn->data;
char *type;
- char command;
conn->socktype = SOCK_DGRAM; /* UDP datagram based */
/* TFTP URLs support an extension like ";mode=<typecode>" that
* we'll try to get now! */
- type = strstr(data->state.path, ";mode=");
+ type = strstr(data->state.up.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 = Curl_raw_toupper(type[6]);
diff --git a/Utilities/cmcurl/lib/tftp.h b/Utilities/cmcurl/lib/tftp.h
index c2325b232..1335f64bd 100644
--- a/Utilities/cmcurl/lib/tftp.h
+++ b/Utilities/cmcurl/lib/tftp.h
@@ -26,4 +26,3 @@ extern const struct Curl_handler Curl_handler_tftp;
#endif
#endif /* HEADER_CURL_TFTP_H */
-
diff --git a/Utilities/cmcurl/lib/timeval.c b/Utilities/cmcurl/lib/timeval.c
index bed44c573..e2bd7fd14 100644
--- a/Utilities/cmcurl/lib/timeval.c
+++ b/Utilities/cmcurl/lib/timeval.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -24,31 +24,40 @@
#if defined(WIN32) && !defined(MSDOS)
-struct timeval curlx_tvnow(void)
+/* set in win32_init() */
+extern LARGE_INTEGER Curl_freq;
+extern bool Curl_isVistaOrGreater;
+
+struct curltime Curl_now(void)
{
- /*
- ** GetTickCount() is available on _all_ Windows versions from W95 up
- ** to nowadays. Returns milliseconds elapsed since last system boot,
- ** increases monotonically and wraps once 49.7 days have elapsed.
- */
- struct timeval now;
-#if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_VISTA) || \
- (_WIN32_WINNT < _WIN32_WINNT_VISTA)
- DWORD milliseconds = GetTickCount();
- now.tv_sec = milliseconds / 1000;
- now.tv_usec = (milliseconds % 1000) * 1000;
-#else
- ULONGLONG milliseconds = GetTickCount64();
- now.tv_sec = (long) (milliseconds / 1000);
- now.tv_usec = (long) (milliseconds % 1000) * 1000;
+ struct curltime now;
+ if(Curl_isVistaOrGreater) { /* QPC timer might have issues pre-Vista */
+ LARGE_INTEGER count;
+ QueryPerformanceCounter(&count);
+ now.tv_sec = (time_t)(count.QuadPart / Curl_freq.QuadPart);
+ now.tv_usec = (int)((count.QuadPart % Curl_freq.QuadPart) * 1000000 /
+ Curl_freq.QuadPart);
+ }
+ else {
+ /* Disable /analyze warning that GetTickCount64 is preferred */
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable:28159)
+#endif
+ DWORD milliseconds = GetTickCount();
+#if defined(_MSC_VER)
+#pragma warning(pop)
#endif
+ now.tv_sec = milliseconds / 1000;
+ now.tv_usec = (milliseconds % 1000) * 1000;
+ }
return now;
}
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
-struct timeval curlx_tvnow(void)
+struct curltime Curl_now(void)
{
/*
** clock_gettime() is granted to be increased monotonically when the
@@ -57,11 +66,30 @@ struct timeval curlx_tvnow(void)
** in any case the time starting point does not change once that the
** system has started up.
*/
+#ifdef HAVE_GETTIMEOFDAY
struct timeval now;
+#endif
+ struct curltime cnow;
struct timespec tsnow;
- if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
- now.tv_sec = tsnow.tv_sec;
- now.tv_usec = tsnow.tv_nsec / 1000;
+
+ /*
+ ** clock_gettime() may be defined by Apple's SDK as weak symbol thus
+ ** code compiles but fails during run-time if clock_gettime() is
+ ** called on unsupported OS version.
+ */
+#if defined(__APPLE__) && (HAVE_BUILTIN_AVAILABLE == 1)
+ bool have_clock_gettime = FALSE;
+ if(__builtin_available(macOS 10.12, iOS 10, tvOS 10, watchOS 3, *))
+ have_clock_gettime = TRUE;
+#endif
+
+ if(
+#if defined(__APPLE__) && (HAVE_BUILTIN_AVAILABLE == 1)
+ have_clock_gettime &&
+#endif
+ (0 == clock_gettime(CLOCK_MONOTONIC, &tsnow))) {
+ cnow.tv_sec = tsnow.tv_sec;
+ cnow.tv_usec = (unsigned int)(tsnow.tv_nsec / 1000);
}
/*
** Even when the configure process has truly detected monotonic clock
@@ -69,20 +97,54 @@ struct timeval curlx_tvnow(void)
** run-time. When this occurs simply fallback to other time source.
*/
#ifdef HAVE_GETTIMEOFDAY
- else
+ else {
(void)gettimeofday(&now, NULL);
+ cnow.tv_sec = now.tv_sec;
+ cnow.tv_usec = (unsigned int)now.tv_usec;
+ }
#else
else {
- now.tv_sec = (long)time(NULL);
- now.tv_usec = 0;
+ cnow.tv_sec = time(NULL);
+ cnow.tv_usec = 0;
}
#endif
- return now;
+ return cnow;
+}
+
+#elif defined(HAVE_MACH_ABSOLUTE_TIME)
+
+#include <stdint.h>
+#include <mach/mach_time.h>
+
+struct curltime Curl_now(void)
+{
+ /*
+ ** Monotonic timer on Mac OS is provided by mach_absolute_time(), which
+ ** returns time in Mach "absolute time units," which are platform-dependent.
+ ** To convert to nanoseconds, one must use conversion factors specified by
+ ** mach_timebase_info().
+ */
+ static mach_timebase_info_data_t timebase;
+ struct curltime cnow;
+ uint64_t usecs;
+
+ if(0 == timebase.denom)
+ (void) mach_timebase_info(&timebase);
+
+ usecs = mach_absolute_time();
+ usecs *= timebase.numer;
+ usecs /= timebase.denom;
+ usecs /= 1000;
+
+ cnow.tv_sec = usecs / 1000000;
+ cnow.tv_usec = (int)(usecs % 1000000);
+
+ return cnow;
}
#elif defined(HAVE_GETTIMEOFDAY)
-struct timeval curlx_tvnow(void)
+struct curltime Curl_now(void)
{
/*
** gettimeofday() is not granted to be increased monotonically, due to
@@ -90,54 +152,62 @@ struct timeval curlx_tvnow(void)
** forward or backward in time.
*/
struct timeval now;
+ struct curltime ret;
(void)gettimeofday(&now, NULL);
- return now;
+ ret.tv_sec = now.tv_sec;
+ ret.tv_usec = (int)now.tv_usec;
+ return ret;
}
#else
-struct timeval curlx_tvnow(void)
+struct curltime Curl_now(void)
{
/*
** time() returns the value of time in seconds since the Epoch.
*/
- struct timeval now;
- now.tv_sec = (long)time(NULL);
+ struct curltime now;
+ now.tv_sec = time(NULL);
now.tv_usec = 0;
return now;
}
#endif
+#if SIZEOF_TIME_T < 8
+#define TIME_MAX INT_MAX
+#define TIME_MIN INT_MIN
+#else
+#define TIME_MAX 9223372036854775807LL
+#define TIME_MIN -9223372036854775807LL
+#endif
+
/*
- * Make sure that the first argument is the more recent time, as otherwise
- * we'll get a weird negative time-diff back...
+ * Returns: time difference in number of milliseconds. For too large diffs it
+ * returns max value.
*
- * Returns: the time difference in number of milliseconds. For large diffs it
- * returns 0x7fffffff on 32bit time_t systems.
+ * @unittest: 1323
*/
-time_t curlx_tvdiff(struct timeval newer, struct timeval older)
+timediff_t Curl_timediff(struct curltime newer, struct curltime older)
{
-#if SIZEOF_TIME_T < 8
- /* for 32bit time_t systems, add a precaution to avoid overflow for really
- big time differences */
- time_t diff = newer.tv_sec-older.tv_sec;
- if(diff >= (0x7fffffff/1000))
- return 0x7fffffff;
-#endif
- return (newer.tv_sec-older.tv_sec)*1000+
- (time_t)(newer.tv_usec-older.tv_usec)/1000;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
+ if(diff >= (TIME_MAX/1000))
+ return TIME_MAX;
+ else if(diff <= (TIME_MIN/1000))
+ return TIME_MIN;
+ return diff * 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.
+ * Returns: time difference in number of microseconds. For too large diffs it
+ * returns max value.
*/
-double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
+timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
{
- if(newer.tv_sec != older.tv_sec)
- return (double)(newer.tv_sec-older.tv_sec)+
- (double)(newer.tv_usec-older.tv_usec)/1000000.0;
- return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
+ timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
+ if(diff >= (TIME_MAX/1000000))
+ return TIME_MAX;
+ else if(diff <= (TIME_MIN/1000000))
+ return TIME_MIN;
+ return diff * 1000000 + newer.tv_usec-older.tv_usec;
}
diff --git a/Utilities/cmcurl/lib/timeval.h b/Utilities/cmcurl/lib/timeval.h
index 33969354d..96867d713 100644
--- a/Utilities/cmcurl/lib/timeval.h
+++ b/Utilities/cmcurl/lib/timeval.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,14 +22,22 @@
*
***************************************************************************/
-/*
- * 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 "curl_setup.h"
-struct timeval curlx_tvnow(void);
+#if SIZEOF_TIME_T < 8
+typedef int timediff_t;
+#define CURL_FORMAT_TIMEDIFF_T "d"
+#else
+typedef curl_off_t timediff_t;
+#define CURL_FORMAT_TIMEDIFF_T CURL_FORMAT_CURL_OFF_T
+#endif
+
+struct curltime {
+ time_t tv_sec; /* seconds */
+ int tv_usec; /* microseconds */
+};
+
+struct curltime Curl_now(void);
/*
* Make sure that the first argument (t1) is the more recent time and t2 is
@@ -37,20 +45,14 @@ struct timeval curlx_tvnow(void);
*
* Returns: the time difference in number of milliseconds.
*/
-time_t curlx_tvdiff(struct timeval t1, struct timeval t2);
+timediff_t Curl_timediff(struct curltime t1, struct curltime t2);
/*
- * Same as curlx_tvdiff but with full usec resolution.
+ * 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 seconds with subsecond resolution.
+ * Returns: the time difference in number of microseconds.
*/
-double curlx_tvdiff_secs(struct timeval t1, struct timeval t2);
-
-/* 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)
+timediff_t Curl_timediff_us(struct curltime newer, struct curltime older);
#endif /* HEADER_CURL_TIMEVAL_H */
-
diff --git a/Utilities/cmcurl/lib/transfer.c b/Utilities/cmcurl/lib/transfer.c
index 43e8f64aa..514330e8c 100644
--- a/Utilities/cmcurl/lib/transfer.c
+++ b/Utilities/cmcurl/lib/transfer.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -73,21 +73,93 @@
#include "connect.h"
#include "non-ascii.h"
#include "http2.h"
+#include "mime.h"
+#include "strcase.h"
+#include "urlapi-int.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"
+#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \
+ !defined(CURL_DISABLE_IMAP)
+/*
+ * checkheaders() checks the linked list of custom headers for a
+ * particular header (prefix). Provide the prefix without colon!
+ *
+ * Returns a pointer to the first matching header or NULL if none matched.
+ */
+char *Curl_checkheaders(const struct connectdata *conn,
+ const char *thisheader)
+{
+ struct curl_slist *head;
+ size_t thislen = strlen(thisheader);
+ struct Curl_easy *data = conn->data;
+
+ for(head = data->set.headers; head; head = head->next) {
+ if(strncasecompare(head->data, thisheader, thislen) &&
+ Curl_headersep(head->data[thislen]) )
+ return head->data;
+ }
+
+ return NULL;
+}
+#endif
+
+CURLcode Curl_get_upload_buffer(struct Curl_easy *data)
+{
+ if(!data->state.ulbuf) {
+ data->state.ulbuf = malloc(data->set.upload_buffer_size);
+ if(!data->state.ulbuf)
+ return CURLE_OUT_OF_MEMORY;
+ }
+ return CURLE_OK;
+}
+
+#ifndef CURL_DISABLE_HTTP
+/*
+ * This function will be called to loop through the trailers buffer
+ * until no more data is available for sending.
+ */
+static size_t Curl_trailers_read(char *buffer, size_t size, size_t nitems,
+ void *raw)
+{
+ struct Curl_easy *data = (struct Curl_easy *)raw;
+ Curl_send_buffer *trailers_buf = data->state.trailers_buf;
+ size_t bytes_left = trailers_buf->size_used-data->state.trailers_bytes_sent;
+ size_t to_copy = (size*nitems < bytes_left) ? size*nitems : bytes_left;
+ if(to_copy) {
+ memcpy(buffer,
+ &trailers_buf->buffer[data->state.trailers_bytes_sent],
+ to_copy);
+ data->state.trailers_bytes_sent += to_copy;
+ }
+ return to_copy;
+}
+
+static size_t Curl_trailers_left(void *raw)
+{
+ struct Curl_easy *data = (struct Curl_easy *)raw;
+ Curl_send_buffer *trailers_buf = data->state.trailers_buf;
+ return trailers_buf->size_used - data->state.trailers_bytes_sent;
+}
+#endif
+
/*
* 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)
+CURLcode Curl_fillreadbuffer(struct connectdata *conn, size_t bytes,
+ size_t *nreadp)
{
struct Curl_easy *data = conn->data;
- size_t buffersize = (size_t)bytes;
- int nread;
+ size_t buffersize = bytes;
+ size_t nread;
+
+ curl_read_callback readfunc = NULL;
+ void *extra_data = NULL;
+
#ifdef CURL_DOES_CONVERSIONS
bool sending_http_headers = FALSE;
@@ -101,16 +173,76 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
}
#endif
- if(data->req.upload_chunky) {
+#ifndef CURL_DISABLE_HTTP
+ if(data->state.trailers_state == TRAILERS_INITIALIZED) {
+ struct curl_slist *trailers = NULL;
+ CURLcode c;
+ int trailers_ret_code;
+
+ /* at this point we already verified that the callback exists
+ so we compile and store the trailers buffer, then proceed */
+ infof(data,
+ "Moving trailers state machine from initialized to sending.\n");
+ data->state.trailers_state = TRAILERS_SENDING;
+ data->state.trailers_buf = Curl_add_buffer_init();
+ if(!data->state.trailers_buf) {
+ failf(data, "Unable to allocate trailing headers buffer !");
+ return CURLE_OUT_OF_MEMORY;
+ }
+ data->state.trailers_bytes_sent = 0;
+ Curl_set_in_callback(data, true);
+ trailers_ret_code = data->set.trailer_callback(&trailers,
+ data->set.trailer_data);
+ Curl_set_in_callback(data, false);
+ if(trailers_ret_code == CURL_TRAILERFUNC_OK) {
+ c = Curl_http_compile_trailers(trailers, data->state.trailers_buf, data);
+ }
+ else {
+ failf(data, "operation aborted by trailing headers callback");
+ *nreadp = 0;
+ c = CURLE_ABORTED_BY_CALLBACK;
+ }
+ if(c != CURLE_OK) {
+ Curl_add_buffer_free(&data->state.trailers_buf);
+ curl_slist_free_all(trailers);
+ return c;
+ }
+ infof(data, "Successfully compiled trailers.\r\n");
+ curl_slist_free_all(trailers);
+ }
+#endif
+
+ /* if we are transmitting trailing data, we don't need to write
+ a chunk size so we skip this */
+ if(data->req.upload_chunky &&
+ data->state.trailers_state == TRAILERS_NONE) {
/* if chunked Transfer-Encoding */
buffersize -= (8 + 2 + 2); /* 32bit hex + CRLF + CRLF */
data->req.upload_fromhere += (8 + 2); /* 32bit hex + CRLF */
}
- /* this function returns a size_t, so we typecast to int to prevent warnings
- with picky compilers */
- nread = (int)data->state.fread_func(data->req.upload_fromhere, 1,
- buffersize, data->state.in);
+#ifndef CURL_DISABLE_HTTP
+ if(data->state.trailers_state == TRAILERS_SENDING) {
+ /* if we're here then that means that we already sent the last empty chunk
+ but we didn't send a final CR LF, so we sent 0 CR LF. We then start
+ pulling trailing data until we ²have no more at which point we
+ simply return to the previous point in the state machine as if
+ nothing happened.
+ */
+ readfunc = Curl_trailers_read;
+ extra_data = (void *)data;
+ }
+ else
+#endif
+ {
+ readfunc = data->state.fread_func;
+ extra_data = data->state.in;
+ }
+
+ Curl_set_in_callback(data, true);
+ nread = readfunc(data->req.upload_fromhere, 1,
+ buffersize, extra_data);
+ Curl_set_in_callback(data, false);
if(nread == CURL_READFUNC_ABORT) {
failf(data, "operation aborted by callback");
@@ -138,7 +270,7 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
return CURLE_OK; /* nothing was read */
}
- else if((size_t)nread > buffersize) {
+ else if(nread > buffersize) {
/* the read function returned a too large value */
*nreadp = 0;
failf(data, "read function returned funny value");
@@ -161,10 +293,10 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
here, knowing they'll become CRLFs later on.
*/
- char hexbuffer[11];
+ bool added_crlf = FALSE;
+ int hexlen = 0;
const char *endofline_native;
const char *endofline_network;
- int hexlen;
if(
#ifdef CURL_DO_LINEEND_CONV
@@ -179,43 +311,81 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
endofline_native = "\r\n";
endofline_network = "\x0d\x0a";
}
- hexlen = snprintf(hexbuffer, sizeof(hexbuffer),
- "%x%s", nread, endofline_native);
- /* move buffer pointer */
- data->req.upload_fromhere -= hexlen;
- nread += hexlen;
+ /* if we're not handling trailing data, proceed as usual */
+ if(data->state.trailers_state != TRAILERS_SENDING) {
+ char hexbuffer[11] = "";
+ hexlen = msnprintf(hexbuffer, sizeof(hexbuffer),
+ "%zx%s", nread, endofline_native);
- /* copy the prefix to the buffer, leaving out the NUL */
- memcpy(data->req.upload_fromhere, hexbuffer, hexlen);
+ /* move buffer pointer */
+ data->req.upload_fromhere -= hexlen;
+ nread += hexlen;
- /* always append ASCII CRLF to the data */
- memcpy(data->req.upload_fromhere + nread,
- endofline_network,
- strlen(endofline_network));
+ /* copy the prefix to the buffer, leaving out the NUL */
+ memcpy(data->req.upload_fromhere, hexbuffer, hexlen);
-#ifdef CURL_DOES_CONVERSIONS
- CURLcode result;
- int length;
- if(data->set.prefer_ascii) {
- /* translate the protocol and data */
- length = nread;
+ /* always append ASCII CRLF to the data unless
+ we have a valid trailer callback */
+#ifndef CURL_DISABLE_HTTP
+ if((nread-hexlen) == 0 &&
+ data->set.trailer_callback != NULL &&
+ data->state.trailers_state == TRAILERS_NONE) {
+ data->state.trailers_state = TRAILERS_INITIALIZED;
+ }
+ else
+#endif
+ {
+ memcpy(data->req.upload_fromhere + nread,
+ endofline_network,
+ strlen(endofline_network));
+ added_crlf = TRUE;
+ }
}
- else {
- /* just translate the protocol portion */
- length = strlen(hexbuffer);
+
+#ifdef CURL_DOES_CONVERSIONS
+ {
+ CURLcode result;
+ size_t length;
+ if(data->set.prefer_ascii)
+ /* translate the protocol and data */
+ length = nread;
+ else
+ /* just translate the protocol portion */
+ length = hexlen;
+ if(length) {
+ result = Curl_convert_to_network(data, data->req.upload_fromhere,
+ length);
+ /* Curl_convert_to_network calls failf if unsuccessful */
+ if(result)
+ return result;
+ }
}
- result = Curl_convert_to_network(data, data->req.upload_fromhere, length);
- /* Curl_convert_to_network calls failf if unsuccessful */
- if(result)
- return result;
#endif /* CURL_DOES_CONVERSIONS */
- if((nread - hexlen) == 0)
- /* mark this as done once this chunk is transferred */
+#ifndef CURL_DISABLE_HTTP
+ if(data->state.trailers_state == TRAILERS_SENDING &&
+ !Curl_trailers_left(data)) {
+ Curl_add_buffer_free(&data->state.trailers_buf);
+ data->state.trailers_state = TRAILERS_DONE;
+ data->set.trailer_data = NULL;
+ data->set.trailer_callback = NULL;
+ /* mark the transfer as done */
data->req.upload_done = TRUE;
+ infof(data, "Signaling end of chunked upload after trailers.\n");
+ }
+ else
+#endif
+ if((nread - hexlen) == 0 &&
+ data->state.trailers_state != TRAILERS_INITIALIZED) {
+ /* mark this as done once this chunk is transferred */
+ data->req.upload_done = TRUE;
+ infof(data,
+ "Signaling end of chunked upload via terminating chunk.\n");
+ }
- nread+=(int)strlen(endofline_native); /* for the added end of line */
+ if(added_crlf)
+ nread += strlen(endofline_network); /* for the added end of line */
}
#ifdef CURL_DOES_CONVERSIONS
else if((data->set.prefer_ascii) && (!sending_http_headers)) {
@@ -241,6 +411,7 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
CURLcode Curl_readrewind(struct connectdata *conn)
{
struct Curl_easy *data = conn->data;
+ curl_mimepart *mimepart = &data->set.mimepost;
conn->bits.rewindaftersend = FALSE; /* we rewind now */
@@ -253,14 +424,28 @@ CURLcode Curl_readrewind(struct connectdata *conn)
/* 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))
+ if(conn->handler->protocol & PROTO_FAMILY_HTTP) {
+ struct HTTP *http = data->req.protop;
+
+ if(http->sendit)
+ mimepart = http->sendit;
+ }
+ if(data->set.postfields)
; /* do nothing */
+ else if(data->set.httpreq == HTTPREQ_POST_MIME ||
+ data->set.httpreq == HTTPREQ_POST_FORM) {
+ if(Curl_mime_rewind(mimepart)) {
+ failf(data, "Cannot rewind mime/post data");
+ return CURLE_SEND_FAIL_REWIND;
+ }
+ }
else {
if(data->set.seek_func) {
int err;
+ Curl_set_in_callback(data, true);
err = (data->set.seek_func)(data->set.seek_client, 0, SEEK_SET);
+ Curl_set_in_callback(data, false);
if(err) {
failf(data, "seek callback returned error %d", (int)err);
return CURLE_SEND_FAIL_REWIND;
@@ -269,12 +454,13 @@ CURLcode Curl_readrewind(struct connectdata *conn)
else if(data->set.ioctl_func) {
curlioerr err;
+ Curl_set_in_callback(data, true);
err = (data->set.ioctl_func)(data, CURLIOCMD_RESTARTREAD,
data->set.ioctl_client);
+ Curl_set_in_callback(data, false);
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", (int)err);
return CURLE_SEND_FAIL_REWIND;
}
@@ -304,7 +490,7 @@ static int data_pending(const struct connectdata *conn)
return conn->handler->protocol&(CURLPROTO_SCP|CURLPROTO_SFTP) ||
#if defined(USE_NGHTTP2)
Curl_ssl_data_pending(conn, FIRSTSOCKET) ||
- /* For HTTP/2, we may read up everything including responde body
+ /* For HTTP/2, we may read up everything including response body
with header fields in Curl_http_readwrite_headers. If no
content-length is provided, curl waits for the connection
close, which we emulate it using conn->proto.httpc.closed =
@@ -317,35 +503,6 @@ static int data_pending(const struct connectdata *conn)
#endif
}
-static void read_rewind(struct connectdata *conn,
- size_t thismuch)
-{
- DEBUGASSERT(conn->read_pos >= thismuch);
-
- conn->read_pos -= thismuch;
- conn->bits.stream_was_rewound = TRUE;
-
-#ifdef DEBUGBUILD
- {
- char buf[512 + 1];
- size_t show;
-
- show = CURLMIN(conn->buf_len - conn->read_pos, sizeof(buf)-1);
- if(conn->master_buffer) {
- memcpy(buf, conn->master_buffer + conn->read_pos, show);
- buf[show] = '\0';
- }
- else {
- buf[0] = '\0';
- }
-
- DEBUGF(infof(conn->data,
- "Buffer after stream rewind (read_pos = %zu): [%s]\n",
- conn->read_pos, buf));
- }
-#endif
-}
-
/*
* Check to see if CURLOPT_TIMECONDITION was met by comparing the time of the
* remote document with the time provided by CURLOPT_TIMEVAL
@@ -395,7 +552,6 @@ static CURLcode readwrite_data(struct Curl_easy *data,
CURLcode result = CURLE_OK;
ssize_t nread; /* number of bytes read */
size_t excess = 0; /* excess bytes read */
- bool is_empty_data = FALSE;
bool readmore = FALSE; /* used by RTP to signal for more data */
int maxloops = 100;
@@ -405,6 +561,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
/* This is where we loop until we have read everything there is to
read or we get a CURLE_AGAIN */
do {
+ bool is_empty_data = FALSE;
size_t buffersize = data->set.buffer_size;
size_t bytestoread = buffersize;
@@ -420,9 +577,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
conn->httpversion == 20) &&
#endif
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! */
+ /* make sure we don't read too much */
curl_off_t totalleft = k->size - k->bytecount;
if(totalleft < (curl_off_t)bytestoread)
bytestoread = (size_t)totalleft;
@@ -450,7 +605,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
if(k->exp100 > EXP100_SEND_DATA)
/* set time stamp to compare with when waiting for the 100 */
- k->start100 = Curl_tvnow();
+ k->start100 = Curl_now();
}
*didwhat |= KEEP_RECV;
@@ -461,7 +616,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
if(0 < nread || is_empty_data) {
k->buf[nread] = 0;
}
- else if(0 >= nread) {
+ else {
/* if we receive 0 or less here, the server closed the connection
and we bail out from this! */
DEBUGF(infof(data, "nread <= 0, server closed connection, bailing\n"));
@@ -504,20 +659,11 @@ static CURLcode readwrite_data(struct Curl_easy *data,
/* We've stopped dealing with input, get out of the do-while loop */
if(nread > 0) {
- if(Curl_pipeline_wanted(conn->data->multi, CURLPIPE_HTTP1)) {
- infof(data,
- "Rewinding stream by : %zd"
- " bytes on url %s (zero-length body)\n",
- nread, data->state.path);
- read_rewind(conn, (size_t)nread);
- }
- else {
- infof(data,
- "Excess found in a non pipelined read:"
- " excess = %zd"
- " url = %s (zero-length body)\n",
- nread, data->state.path);
- }
+ infof(data,
+ "Excess found:"
+ " excess = %zd"
+ " url = %s (zero-length body)\n",
+ nread, data->state.up.path);
}
break;
@@ -560,7 +706,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
infof(data, "Ignoring the response-body\n");
}
if(data->state.resume_from && !k->content_range &&
- (data->set.httpreq==HTTPREQ_GET) &&
+ (data->set.httpreq == HTTPREQ_GET) &&
!k->ignorebody) {
if(k->size == data->state.resume_from) {
@@ -611,14 +757,14 @@ static CURLcode readwrite_data(struct Curl_easy *data,
if(data->set.verbose) {
if(k->badheader) {
Curl_debug(data, CURLINFO_DATA_IN, data->state.headerbuff,
- (size_t)k->hbuflen, conn);
+ (size_t)k->hbuflen);
if(k->badheader == HEADER_PARTHEADER)
Curl_debug(data, CURLINFO_DATA_IN,
- k->str, (size_t)nread, conn);
+ k->str, (size_t)nread);
}
else
Curl_debug(data, CURLINFO_DATA_IN,
- k->str, (size_t)nread, conn);
+ k->str, (size_t)nread);
}
#ifndef CURL_DISABLE_HTTP
@@ -648,19 +794,12 @@ static CURLcode readwrite_data(struct Curl_easy *data,
/* There are now possibly N number of bytes at the end of the
str buffer that weren't written to the client.
-
- We DO care about this data if we are pipelining.
Push it back to be read on the next pass. */
dataleft = conn->chunk.dataleft;
if(dataleft != 0) {
infof(conn->data, "Leftovers after chunking: %zu bytes\n",
dataleft);
- if(Curl_pipeline_wanted(conn->data->multi, CURLPIPE_HTTP1)) {
- /* only attempt the rewind if we truly are pipelining */
- infof(conn->data, "Rewinding %zu bytes\n",dataleft);
- read_rewind(conn, dataleft);
- }
}
}
/* If it returned OK, we just keep going */
@@ -668,7 +807,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
#endif /* CURL_DISABLE_HTTP */
/* Account for body content stored in the header buffer */
- if(k->badheader && !k->ignorebody) {
+ if((k->badheader == HEADER_PARTHEADER) && !k->ignorebody) {
DEBUGF(infof(data, "Increasing bytecount by %zu from hbuflen\n",
k->hbuflen));
k->bytecount += k->hbuflen;
@@ -679,25 +818,13 @@ static CURLcode readwrite_data(struct Curl_easy *data,
excess = (size_t)(k->bytecount + nread - k->maxdownload);
if(excess > 0 && !k->ignorebody) {
- if(Curl_pipeline_wanted(conn->data->multi, CURLPIPE_HTTP1)) {
- infof(data,
- "Rewinding stream by : %zu"
- " bytes on url %s (size = %" CURL_FORMAT_CURL_OFF_T
- ", maxdownload = %" CURL_FORMAT_CURL_OFF_T
- ", bytecount = %" CURL_FORMAT_CURL_OFF_T ", nread = %zd)\n",
- excess, data->state.path,
- k->size, k->maxdownload, k->bytecount, nread);
- read_rewind(conn, excess);
- }
- else {
- infof(data,
- "Excess found in a non pipelined read:"
- " excess = %zu"
- ", size = %" CURL_FORMAT_CURL_OFF_T
- ", maxdownload = %" CURL_FORMAT_CURL_OFF_T
- ", bytecount = %" CURL_FORMAT_CURL_OFF_T "\n",
- excess, k->size, k->maxdownload, k->bytecount);
- }
+ infof(data,
+ "Excess found in a read:"
+ " excess = %zu"
+ ", size = %" CURL_FORMAT_CURL_OFF_T
+ ", maxdownload = %" CURL_FORMAT_CURL_OFF_T
+ ", bytecount = %" CURL_FORMAT_CURL_OFF_T "\n",
+ excess, k->size, k->maxdownload, k->bytecount);
}
nread = (ssize_t) (k->maxdownload - k->bytecount);
@@ -737,48 +864,19 @@ static CURLcode readwrite_data(struct Curl_easy *data,
in http_chunks.c.
Make sure that ALL_CONTENT_ENCODINGS contains all the
encodings handled here. */
-#ifdef HAVE_LIBZ
- switch(conn->data->set.http_ce_skip ?
- IDENTITY : k->auto_decoding) {
- case IDENTITY:
-#endif
- /* This is the default when the server sends no
- Content-Encoding header. See Curl_readwrite_init; the
- memset() call initializes k->auto_decoding to zero. */
+ if(conn->data->set.http_ce_skip || !k->writer_stack) {
if(!k->ignorebody) {
-
#ifndef CURL_DISABLE_POP3
- if(conn->handler->protocol&PROTO_FAMILY_POP3)
+ if(conn->handler->protocol & PROTO_FAMILY_POP3)
result = Curl_pop3_write(conn, k->str, nread);
else
#endif /* CURL_DISABLE_POP3 */
-
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;
-
- default:
- failf(data, "Unrecognized content encoding type. "
- "libcurl understands `identity', `deflate' and `gzip' "
- "content encodings.");
- result = CURLE_BAD_CONTENT_ENCODING;
- break;
}
-#endif
+ else if(!k->ignorebody)
+ result = Curl_unencode_write(conn, k->writer_stack, k->str, nread);
}
k->badheader = HEADER_NORMAL; /* taken care of now */
@@ -788,10 +886,15 @@ static CURLcode readwrite_data(struct Curl_easy *data,
} /* if(!header and data to read) */
- if(conn->handler->readwrite &&
- (excess > 0 && !conn->bits.stream_was_rewound)) {
+ if(conn->handler->readwrite && excess && !conn->bits.stream_was_rewound) {
/* Parse the excess data */
k->str += nread;
+
+ if(&k->str[excess] > &k->buf[data->set.buffer_size]) {
+ /* the excess amount was too excessive(!), make sure
+ it doesn't read out of buffer */
+ excess = &k->buf[data->set.buffer_size] - k->str;
+ }
nread = (ssize_t)excess;
result = conn->handler->readwrite(data, conn, &nread, &readmore);
@@ -809,6 +912,11 @@ static CURLcode readwrite_data(struct Curl_easy *data,
k->keepon &= ~KEEP_RECV;
}
+ if(k->keepon & KEEP_RECV_PAUSE) {
+ /* this is a paused transfer */
+ break;
+ }
+
} while(data_pending(conn) && maxloops--);
if(maxloops <= 0) {
@@ -844,6 +952,26 @@ static CURLcode done_sending(struct connectdata *conn,
return CURLE_OK;
}
+#if defined(WIN32) && !defined(USE_LWIPSOCK)
+#ifndef SIO_IDEAL_SEND_BACKLOG_QUERY
+#define SIO_IDEAL_SEND_BACKLOG_QUERY 0x4004747B
+#endif
+
+static void win_update_buffer_size(curl_socket_t sockfd)
+{
+ int result;
+ ULONG ideal;
+ DWORD ideallen;
+ result = WSAIoctl(sockfd, SIO_IDEAL_SEND_BACKLOG_QUERY, 0, 0,
+ &ideal, sizeof(ideal), &ideallen, 0, 0);
+ if(result == 0) {
+ setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF,
+ (const char *)&ideal, sizeof(ideal));
+ }
+}
+#else
+#define win_update_buffer_size(x)
+#endif
/*
* Send data to upload to the server, when the socket is writable.
@@ -865,17 +993,19 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
*didwhat |= KEEP_SEND;
do {
-
/* only read more data if there's no upload data already
present in the upload buffer */
if(0 == k->upload_present) {
+ result = Curl_get_upload_buffer(data);
+ if(result)
+ return result;
/* init the "upload from here" pointer */
- k->upload_fromhere = data->state.uploadbuffer;
+ k->upload_fromhere = data->state.ulbuf;
if(!k->upload_done) {
/* HTTP pollution, this should be written nicer to become more
protocol agnostic. */
- int fillcount;
+ size_t fillcount;
struct HTTP *http = k->protop;
if((k->exp100 == EXP100_SENDING_REQUEST) &&
@@ -885,9 +1015,8 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
go into the Expect: 100 state and await such a header */
k->exp100 = EXP100_AWAITING_CONTINUE; /* wait for the header */
k->keepon &= ~KEEP_SEND; /* disable writing */
- k->start100 = Curl_tvnow(); /* timeout count starts now */
+ k->start100 = Curl_now(); /* timeout count starts now */
*didwhat &= ~KEEP_SEND; /* we didn't write anything actually */
-
/* set a timeout for the multi interface */
Curl_expire(data, data->set.expect_100_timeout, EXPIRE_100_TIMEOUT);
break;
@@ -902,11 +1031,12 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
sending_http_headers = FALSE;
}
- result = Curl_fillreadbuffer(conn, UPLOAD_BUFSIZE, &fillcount);
+ result = Curl_fillreadbuffer(conn, data->set.upload_buffer_size,
+ &fillcount);
if(result)
return result;
- nread = (ssize_t)fillcount;
+ nread = fillcount;
}
else
nread = 0; /* we're done uploading/reading */
@@ -915,7 +1045,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
/* this is a paused transfer */
break;
}
- if(nread<=0) {
+ if(nread <= 0) {
result = done_sending(conn, k);
if(result)
return result;
@@ -934,7 +1064,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
(data->set.crlf))) {
/* Do we need to allocate a scratch buffer? */
if(!data->state.scratch) {
- data->state.scratch = malloc(2 * data->set.buffer_size);
+ data->state.scratch = malloc(2 * data->set.upload_buffer_size);
if(!data->state.scratch) {
failf(data, "Failed to alloc scratch buffer!");
@@ -995,18 +1125,21 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
k->upload_fromhere, /* buffer pointer */
k->upload_present, /* buffer size */
&bytes_written); /* actually sent */
-
if(result)
return result;
+ win_update_buffer_size(conn->writesockfd);
+
if(data->set.verbose)
/* show the data before we change the pointer upload_fromhere */
Curl_debug(data, CURLINFO_DATA_OUT, k->upload_fromhere,
- (size_t)bytes_written, conn);
+ (size_t)bytes_written);
k->writebytecount += bytes_written;
+ Curl_pgrsSetUploadCounter(data, k->writebytecount);
- if(k->writebytecount == data->state.infilesize) {
+ if((!k->upload_chunky || k->forbidchunk) &&
+ (k->writebytecount == data->state.infilesize)) {
/* we have sent all data we were supposed to */
k->upload_done = TRUE;
infof(data, "We are completely uploaded and fine\n");
@@ -1024,7 +1157,10 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
}
else {
/* we've uploaded that buffer now */
- k->upload_fromhere = data->state.uploadbuffer;
+ result = Curl_get_upload_buffer(data);
+ if(result)
+ return result;
+ k->upload_fromhere = data->state.ulbuf;
k->upload_present = 0; /* no more bytes left */
if(k->upload_done) {
@@ -1034,7 +1170,6 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
}
}
- Curl_pgrsSetUploadCounter(data, k->writebytecount);
} WHILE_FALSE; /* just to break out from! */
@@ -1055,7 +1190,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
{
struct SingleRequest *k = &data->req;
CURLcode result;
- int didwhat=0;
+ int didwhat = 0;
curl_socket_t fd_read;
curl_socket_t fd_write;
@@ -1110,13 +1245,9 @@ CURLcode Curl_readwrite(struct connectdata *conn,
return result;
}
- k->now = Curl_tvnow();
+ k->now = Curl_now();
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? */
@@ -1134,7 +1265,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
*/
- time_t ms = Curl_tvdiff(k->now, k->start100);
+ timediff_t ms = Curl_timediff(k->now, k->start100);
if(ms >= data->set.expect_100_timeout) {
/* we've waited long enough, continue anyway */
k->exp100 = EXP100_SEND_DATA;
@@ -1155,16 +1286,17 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if(k->keepon) {
if(0 > Curl_timeleft(data, &k->now, FALSE)) {
if(k->size != -1) {
- failf(data, "Operation timed out after %ld milliseconds with %"
- CURL_FORMAT_CURL_OFF_T " out of %"
+ failf(data, "Operation timed out after %" CURL_FORMAT_TIMEDIFF_T
+ " milliseconds with %" CURL_FORMAT_CURL_OFF_T " out of %"
CURL_FORMAT_CURL_OFF_T " bytes received",
- Curl_tvdiff(k->now, data->progress.t_startsingle), k->bytecount,
- k->size);
+ Curl_timediff(k->now, data->progress.t_startsingle),
+ k->bytecount, k->size);
}
else {
- failf(data, "Operation timed out after %ld milliseconds with %"
- CURL_FORMAT_CURL_OFF_T " bytes received",
- Curl_tvdiff(k->now, data->progress.t_startsingle), k->bytecount);
+ failf(data, "Operation timed out after %" CURL_FORMAT_TIMEDIFF_T
+ " milliseconds with %" CURL_FORMAT_CURL_OFF_T " bytes received",
+ Curl_timediff(k->now, data->progress.t_startsingle),
+ k->bytecount);
}
return CURLE_OPERATION_TIMEDOUT;
}
@@ -1283,12 +1415,32 @@ void Curl_init_CONNECT(struct Curl_easy *data)
CURLcode Curl_pretransfer(struct Curl_easy *data)
{
CURLcode result;
- if(!data->change.url) {
+
+ if(!data->change.url && !data->set.uh) {
/* we can't do anything without URL */
failf(data, "No URL set!");
return CURLE_URL_MALFORMAT;
}
+ /* since the URL may have been redirected in a previous use of this handle */
+ if(data->change.url_alloc) {
+ /* the already set URL is allocated, free it first! */
+ Curl_safefree(data->change.url);
+ data->change.url_alloc = FALSE;
+ }
+
+ if(!data->change.url && data->set.uh) {
+ CURLUcode uc;
+ uc = curl_url_get(data->set.uh,
+ CURLUPART_URL, &data->set.str[STRING_SET_URL], 0);
+ if(uc) {
+ failf(data, "No URL set!");
+ return CURLE_URL_MALFORMAT;
+ }
+ }
+
+ data->change.url = data->set.str[STRING_SET_URL];
+
/* Init the SSL session ID cache here. We do it here since we want to do it
after the *_setopt() calls (that could specify the size of the cache) but
before any transfer takes place. */
@@ -1296,7 +1448,8 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
if(result)
return result;
- data->set.followlocation=0; /* reset the location-follow counter */
+ data->state.wildcardmatch = data->set.wildcard_enabled;
+ 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.httpversion = 0; /* don't assume any particular server version */
@@ -1309,11 +1462,14 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
if(data->set.httpreq == HTTPREQ_PUT)
data->state.infilesize = data->set.filesize;
- else {
+ else if((data->set.httpreq != HTTPREQ_GET) &&
+ (data->set.httpreq != HTTPREQ_HEAD)) {
data->state.infilesize = data->set.postfieldsize;
if(data->set.postfields && (data->state.infilesize == -1))
data->state.infilesize = (curl_off_t)strlen(data->set.postfields);
}
+ else
+ data->state.infilesize = 0;
/* If there is a list of cookie files to read, do it now! */
if(data->change.cookielist)
@@ -1338,22 +1494,17 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
#endif
Curl_initinfo(data); /* reset session-specific information "variables" */
- Curl_pgrsResetTimesSizes(data);
+ Curl_pgrsResetTransferSizes(data);
Curl_pgrsStartNow(data);
- if(data->set.timeout)
- Curl_expire(data, data->set.timeout, EXPIRE_TIMEOUT);
-
- if(data->set.connecttimeout)
- Curl_expire(data, data->set.connecttimeout, EXPIRE_CONNECTTIMEOUT);
-
/* In case the handle is re-used and an authentication method was picked
in the session we need to make sure we only use the one(s) we now
consider to be fine */
data->state.authhost.picked &= data->state.authhost.want;
data->state.authproxy.picked &= data->state.authproxy.want;
- if(data->set.wildcardmatch) {
+#ifndef CURL_DISABLE_FTP
+ if(data->state.wildcardmatch) {
struct WildcardData *wc = &data->wildcard;
if(wc->state < CURLWC_INIT) {
result = Curl_wildcard_init(wc); /* init wildcard structures */
@@ -1361,6 +1512,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
return CURLE_OUT_OF_MEMORY;
}
}
+#endif
}
return result;
@@ -1382,249 +1534,11 @@ CURLcode Curl_posttransfer(struct Curl_easy *data)
return CURLE_OK;
}
-#ifndef CURL_DISABLE_HTTP
-/*
- * strlen_url() returns the length of the given URL if the spaces within the
- * URL were properly URL encoded.
- */
-static size_t strlen_url(const char *url)
-{
- const unsigned char *ptr;
- size_t newlen=0;
- bool left=TRUE; /* left side of the ? */
-
- for(ptr=(unsigned char *)url; *ptr; ptr++) {
- switch(*ptr) {
- case '?':
- left=FALSE;
- /* fall through */
- default:
- if(*ptr >= 0x80)
- newlen += 2;
- 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, const char *url)
-{
- /* we must add this with whitespace-replacing */
- bool left=TRUE;
- const unsigned char *iptr;
- char *optr = output;
- for(iptr = (unsigned char *)url; /* read from here */
- *iptr; /* until zero byte */
- iptr++) {
- switch(*iptr) {
- case '?':
- left=FALSE;
- /* fall through */
- default:
- if(*iptr >= 0x80) {
- snprintf(optr, 4, "%%%02x", *iptr);
- optr += 3;
- }
- else
- *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 */
-
-}
-
-/*
- * Returns true if the given URL is absolute (as opposed to relative)
- */
-static bool is_absolute_url(const char *url)
-{
- char prot[16]; /* URL protocol string storage */
- char letter; /* used for a silly sscanf */
-
- return (2 == sscanf(url, "%15[^?&/:]://%c", prot, &letter)) ? TRUE : FALSE;
-}
-
-/*
- * Concatenate a relative URL to a base URL making it absolute.
- * URL-encodes any spaces.
- * The returned pointer must be freed by the caller unless NULL
- * (returns NULL on out of memory).
- */
-static char *concat_url(const char *base, const char *relurl)
-{
- /***
- 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 *newest;
- char *protsep;
- char *pathsep;
- size_t newlen;
-
- const char *useurl = relurl;
- 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(base);
-
- if(!url_clone)
- return NULL; /* 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('/' != relurl[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, or if the new URL is just a query string (starts with a
- '?') we append the new one at the end of the entire currently worked
- out URL */
- if(useurl[0] != '?') {
- 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 */
-
- if((relurl[0] == '/') && (relurl[1] == '/')) {
- /* the new URL starts with //, just keep the protocol part from the
- original one */
- *protsep=0;
- useurl = &relurl[2]; /* we keep the slashes from the original, so we
- skip the new ones */
- }
- else {
- /* cut off the original URL from the first slash, or deal with URLs
- without 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 = malloc(urllen + 1 + /* possible slash */
- newlen + 1 /* zero byte */);
-
- if(!newest) {
- free(url_clone); /* don't leak this */
- return NULL;
- }
-
- /* copy over the root url part */
- memcpy(newest, url_clone, urllen);
-
- /* check if we need to append a slash */
- if(('/' == useurl[0]) || (protsep && !*protsep) || ('?' == useurl[0]))
- ;
- else
- newest[urllen++]='/';
-
- /* then append the new piece on the right side */
- strcpy_url(&newest[urllen], useurl);
-
- free(url_clone);
-
- return newest;
-}
-#endif /* CURL_DISABLE_HTTP */
-
/*
* 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.
+ *
+ * This function DOES NOT FREE the given url.
*/
CURLcode Curl_follow(struct Curl_easy *data,
char *newurl, /* the Location: string */
@@ -1641,6 +1555,7 @@ CURLcode Curl_follow(struct Curl_easy *data,
/* Location: redirect */
bool disallowport = FALSE;
bool reachedmax = FALSE;
+ CURLUcode uc;
if(type == FOLLOW_REDIR) {
if((data->set.maxredirs != -1) &&
@@ -1673,31 +1588,28 @@ CURLcode Curl_follow(struct Curl_easy *data,
}
}
- if(!is_absolute_url(newurl)) {
- /***
- *DANG* this is an RFC 2068 violation. The URL is supposed
- to be absolute and this doesn't seem to be that!
- */
- char *absolute = concat_url(data->change.url, newurl);
- if(!absolute)
- return CURLE_OUT_OF_MEMORY;
- newurl = absolute;
- }
- else {
- /* The new URL MAY contain space or high byte values, that means a mighty
- stupid redirect URL but we still make an effort to do "right". */
- char *newest;
- size_t newlen = strlen_url(newurl);
-
+ if(Curl_is_absolute_url(newurl, NULL, MAX_SCHEME_LEN))
/* This is an absolute URL, don't allow the custom port number */
disallowport = TRUE;
- newest = malloc(newlen+1); /* get memory for this */
- if(!newest)
+ DEBUGASSERT(data->state.uh);
+ uc = curl_url_set(data->state.uh, CURLUPART_URL, newurl,
+ (type == FOLLOW_FAKE) ? CURLU_NON_SUPPORT_SCHEME : 0);
+ if(uc) {
+ if(type != FOLLOW_FAKE)
+ return Curl_uc_to_curlcode(uc);
+
+ /* the URL could not be parsed for some reason, but since this is FAKE
+ mode, just duplicate the field as-is */
+ newurl = strdup(newurl);
+ if(!newurl)
return CURLE_OUT_OF_MEMORY;
- strcpy_url(newest, newurl); /* create a space-free URL */
- newurl = newest; /* use this instead now */
+ }
+ else {
+ uc = curl_url_get(data->state.uh, CURLUPART_URL, &newurl, 0);
+ if(uc)
+ return Curl_uc_to_curlcode(uc);
}
if(type == FOLLOW_FAKE) {
@@ -1715,10 +1627,8 @@ CURLcode Curl_follow(struct Curl_easy *data,
if(disallowport)
data->state.allow_port = FALSE;
- if(data->change.url_alloc) {
+ if(data->change.url_alloc)
Curl_safefree(data->change.url);
- data->change.url_alloc = FALSE;
- }
data->change.url = newurl;
data->change.url_alloc = TRUE;
@@ -1763,7 +1673,8 @@ CURLcode Curl_follow(struct Curl_easy *data,
* can be overridden with CURLOPT_POSTREDIR.
*/
if((data->set.httpreq == HTTPREQ_POST
- || data->set.httpreq == HTTPREQ_POST_FORM)
+ || data->set.httpreq == HTTPREQ_POST_FORM
+ || data->set.httpreq == HTTPREQ_POST_MIME)
&& !(data->set.keep_post & CURL_REDIR_POST_301)) {
infof(data, "Switch from POST to GET\n");
data->set.httpreq = HTTPREQ_GET;
@@ -1787,7 +1698,8 @@ CURLcode Curl_follow(struct Curl_easy *data,
* can be overridden with CURLOPT_POSTREDIR.
*/
if((data->set.httpreq == HTTPREQ_POST
- || data->set.httpreq == HTTPREQ_POST_FORM)
+ || data->set.httpreq == HTTPREQ_POST_FORM
+ || data->set.httpreq == HTTPREQ_POST_MIME)
&& !(data->set.keep_post & CURL_REDIR_POST_302)) {
infof(data, "Switch from POST to GET\n");
data->set.httpreq = HTTPREQ_GET;
@@ -1820,7 +1732,7 @@ CURLcode Curl_follow(struct Curl_easy *data,
break;
}
Curl_pgrsTime(data, TIMER_REDIRECT);
- Curl_pgrsResetTimesSizes(data);
+ Curl_pgrsResetTransferSizes(data);
return CURLE_OK;
#endif /* CURL_DISABLE_HTTP */
@@ -1833,7 +1745,7 @@ CURLcode Curl_retry_request(struct connectdata *conn,
char **url)
{
struct Curl_easy *data = conn->data;
-
+ bool retry = FALSE;
*url = NULL;
/* if we're talking upload, we can't do the checks below, unless the protocol
@@ -1846,7 +1758,7 @@ CURLcode Curl_retry_request(struct connectdata *conn,
conn->bits.reuse &&
(!data->set.opt_no_body
|| (conn->handler->protocol & PROTO_FAMILY_HTTP)) &&
- (data->set.rtspreq != RTSPREQ_RECEIVE)) {
+ (data->set.rtspreq != RTSPREQ_RECEIVE))
/* We got no data, we attempted to re-use a connection. For HTTP this
can be a retry so we try again regardless if we expected a body.
For other protocols we only try again only if we expected a body.
@@ -1854,6 +1766,19 @@ CURLcode Curl_retry_request(struct connectdata *conn,
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! */
+ retry = TRUE;
+ else if(data->state.refused_stream &&
+ (data->req.bytecount + data->req.headerbytecount == 0) ) {
+ /* This was sent on a refused stream, safe to rerun. A refused stream
+ error can typically only happen on HTTP/2 level if the stream is safe
+ to issue again, but the nghttp2 API can deliver the message to other
+ streams as well, which is why this adds the check the data counters
+ too. */
+ infof(conn->data, "REFUSED_STREAM, retrying a fresh connect\n");
+ data->state.refused_stream = FALSE; /* clear again */
+ retry = TRUE;
+ }
+ if(retry) {
infof(conn->data, "Connection died, retrying a fresh connect\n");
*url = strdup(conn->data->change.url);
if(!*url)
@@ -1868,9 +1793,13 @@ CURLcode Curl_retry_request(struct connectdata *conn,
if(conn->handler->protocol&PROTO_FAMILY_HTTP) {
- struct HTTP *http = data->req.protop;
- if(http->writebytecount)
- return Curl_readrewind(conn);
+ if(data->req.writebytecount) {
+ CURLcode result = Curl_readrewind(conn);
+ if(result) {
+ Curl_safefree(*url);
+ return result;
+ }
+ }
}
}
return CURLE_OK;
@@ -1882,36 +1811,35 @@ CURLcode Curl_retry_request(struct connectdata *conn,
*/
void
Curl_setup_transfer(
- struct connectdata *conn, /* connection data */
+ struct Curl_easy *data, /* transfer */
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
+ 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 Curl_easy *data;
- struct SingleRequest *k;
-
+ struct SingleRequest *k = &data->req;
+ struct connectdata *conn = data->conn;
DEBUGASSERT(conn != NULL);
-
- data = conn->data;
- k = &data->req;
-
DEBUGASSERT((sockindex <= 1) && (sockindex >= -1));
- /* now copy all input parameters */
- conn->sockfd = sockindex == -1 ?
+ if(conn->bits.multiplex || conn->httpversion == 20) {
+ /* when multiplexing, the read/write sockets need to be the same! */
+ conn->sockfd = sockindex == -1 ?
+ ((writesockindex == -1 ? CURL_SOCKET_BAD : conn->sock[writesockindex])) :
+ conn->sock[sockindex];
+ conn->writesockfd = conn->sockfd;
+ }
+ else {
+ conn->sockfd = sockindex == -1 ?
CURL_SOCKET_BAD : conn->sock[sockindex];
- conn->writesockfd = writesockindex == -1 ?
+ conn->writesockfd = writesockindex == -1 ?
CURL_SOCKET_BAD:conn->sock[writesockindex];
+ }
k->getheader = getheader;
k->size = size;
- k->bytecountp = bytecountp;
- k->writebytecountp = writecountp;
/* The code sequence below is placed in this function just because all
necessary input is not always known in do_complete() as this function may
@@ -1925,10 +1853,10 @@ Curl_setup_transfer(
/* we want header and/or body, if neither then don't do this! */
if(k->getheader || !data->set.opt_no_body) {
- if(conn->sockfd != CURL_SOCKET_BAD)
+ if(sockindex != -1)
k->keepon |= KEEP_RECV;
- if(conn->writesockfd != CURL_SOCKET_BAD) {
+ if(writesockindex != -1) {
struct HTTP *http = data->req.protop;
/* HTTP 1.1 magic:
@@ -1944,7 +1872,7 @@ Curl_setup_transfer(
(http->sending == HTTPSEND_BODY)) {
/* wait with write until we either got 100-continue or a timeout */
k->exp100 = EXP100_AWAITING_CONTINUE;
- k->start100 = Curl_tvnow();
+ k->start100 = Curl_now();
/* Set a timeout for the multi interface. Add the inaccuracy margin so
that we don't fire slightly too early and get denied to run. */
@@ -1959,7 +1887,7 @@ Curl_setup_transfer(
/* enable the write bit when we're not waiting for continue */
k->keepon |= KEEP_SEND;
}
- } /* if(conn->writesockfd != CURL_SOCKET_BAD) */
+ } /* if(writesockindex != -1) */
} /* if(k->getheader || !data->set.opt_no_body) */
}
diff --git a/Utilities/cmcurl/lib/transfer.h b/Utilities/cmcurl/lib/transfer.h
index 518967260..a9bff6348 100644
--- a/Utilities/cmcurl/lib/transfer.h
+++ b/Utilities/cmcurl/lib/transfer.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,6 +22,10 @@
*
***************************************************************************/
+#define Curl_headersep(x) ((((x)==':') || ((x)==';')))
+char *Curl_checkheaders(const struct connectdata *conn,
+ const char *thisheader);
+
void Curl_init_CONNECT(struct Curl_easy *data);
CURLcode Curl_pretransfer(struct Curl_easy *data);
@@ -47,22 +51,21 @@ int Curl_single_getsock(const struct connectdata *conn,
curl_socket_t *socks,
int numsocks);
CURLcode Curl_readrewind(struct connectdata *conn);
-CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp);
+CURLcode Curl_fillreadbuffer(struct connectdata *conn, size_t bytes,
+ size_t *nreadp);
CURLcode Curl_retry_request(struct connectdata *conn, char **url);
bool Curl_meets_timecondition(struct Curl_easy *data, time_t timeofdoc);
+CURLcode Curl_get_upload_buffer(struct Curl_easy *data);
/* This sets up a forthcoming transfer */
void
-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 */
-);
+Curl_setup_transfer (struct Curl_easy *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 */
+ int writesockindex /* socket index to write to. May be
+ the same we read from. -1
+ disables */
+ );
#endif /* HEADER_CURL_TRANSFER_H */
-
diff --git a/Utilities/cmcurl/lib/url.c b/Utilities/cmcurl/lib/url.c
index 87446dbca..c441ae716 100644
--- a/Utilities/cmcurl/lib/url.c
+++ b/Utilities/cmcurl/lib/url.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -55,9 +55,7 @@
#error "We can't compile without socket() support!"
#endif
-#ifdef HAVE_LIMITS_H
#include <limits.h>
-#endif
#ifdef USE_LIBIDN2
#include <idn2.h>
@@ -71,6 +69,7 @@ bool curl_win32_idn_to_ascii(const char *in, char **out);
#include "netrc.h"
#include "formdata.h"
+#include "mime.h"
#include "vtls/vtls.h"
#include "hostip.h"
#include "transfer.h"
@@ -93,6 +92,7 @@ bool curl_win32_idn_to_ascii(const char *in, char **out);
#include "non-ascii.h"
#include "inet_pton.h"
#include "getinfo.h"
+#include "urlapi-int.h"
/* And now for the protocols */
#include "ftp.h"
@@ -109,41 +109,26 @@ bool curl_win32_idn_to_ascii(const char *in, char **out);
#include "connect.h"
#include "inet_ntop.h"
#include "http_ntlm.h"
-#include "curl_ntlm_wb.h"
#include "socks.h"
#include "curl_rtmp.h"
#include "gopher.h"
#include "http_proxy.h"
#include "conncache.h"
#include "multihandle.h"
-#include "pipeline.h"
#include "dotdot.h"
#include "strdup.h"
+#include "setopt.h"
+#include "altsvc.h"
+
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
#include "memdebug.h"
-/* Local static prototypes */
-static struct connectdata *
-find_oldest_idle_connection_in_bundle(struct Curl_easy *data,
- struct connectbundle *bundle);
static void conn_free(struct connectdata *conn);
-static void free_fixed_hostname(struct hostname *host);
-static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke);
-static CURLcode parse_url_login(struct Curl_easy *data,
- struct connectdata *conn,
- char **userptr, char **passwdptr,
- char **optionsptr);
-static CURLcode parse_login_details(const char *login, const size_t len,
- char **userptr, char **passwdptr,
- char **optionsptr);
+static void free_idnconverted_hostname(struct hostname *host);
static unsigned int get_protocol_family(unsigned int protocol);
-#define READBUFFER_SIZE CURL_MAX_WRITE_SIZE
-#define READBUFFER_MAX CURL_MAX_READ_SIZE
-#define READBUFFER_MIN 1024
-
/* Some parts of the code (e.g. chunked encoding) assume this buffer has at
* more than just a few bytes to play with. Don't let it become too small or
* bad things will happen.
@@ -200,8 +185,11 @@ static const struct Curl_handler * const protocols[] = {
&Curl_handler_tftp,
#endif
-#ifdef USE_LIBSSH2
+#if defined(USE_SSH)
&Curl_handler_scp,
+#endif
+
+#if defined(USE_SSH)
&Curl_handler_sftp,
#endif
@@ -274,6 +262,7 @@ static const struct Curl_handler Curl_handler_dummy = {
ZERO_NULL, /* perform_getsock */
ZERO_NULL, /* disconnect */
ZERO_NULL, /* readwrite */
+ ZERO_NULL, /* connection_check */
0, /* defport */
0, /* protocol */
PROTOPT_NONE /* flags */
@@ -283,7 +272,7 @@ void Curl_freeset(struct Curl_easy *data)
{
/* Free all dynamic strings stored in the data->set substructure. */
enum dupstring i;
- for(i=(enum dupstring)0; i < STRING_LAST; i++) {
+ for(i = (enum dupstring)0; i < STRING_LAST; i++) {
Curl_safefree(data->set.str[i]);
}
@@ -297,98 +286,24 @@ void Curl_freeset(struct Curl_easy *data)
data->change.url_alloc = FALSE;
}
data->change.url = NULL;
-}
-
-static CURLcode setstropt(char **charp, const char *s)
-{
- /* Release the previous storage at `charp' and replace by a dynamic storage
- copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */
-
- Curl_safefree(*charp);
-
- if(s) {
- char *str = strdup(s);
-
- if(!str)
- return CURLE_OUT_OF_MEMORY;
-
- *charp = str;
- }
- return CURLE_OK;
+ Curl_mime_cleanpart(&data->set.mimepost);
}
-static CURLcode setstropt_userpwd(char *option, char **userp, char **passwdp)
+/* free the URL pieces */
+static void up_free(struct Curl_easy *data)
{
- CURLcode result = CURLE_OK;
- char *user = NULL;
- char *passwd = NULL;
-
- /* Parse the login details if specified. It not then we treat NULL as a hint
- to clear the existing data */
- if(option) {
- result = parse_login_details(option, strlen(option),
- (userp ? &user : NULL),
- (passwdp ? &passwd : NULL),
- NULL);
- }
-
- if(!result) {
- /* Store the username part of option if required */
- if(userp) {
- if(!user && option && option[0] == ':') {
- /* Allocate an empty string instead of returning NULL as user name */
- user = strdup("");
- if(!user)
- result = CURLE_OUT_OF_MEMORY;
- }
-
- Curl_safefree(*userp);
- *userp = user;
- }
-
- /* Store the password part of option if required */
- if(passwdp) {
- Curl_safefree(*passwdp);
- *passwdp = passwd;
- }
- }
-
- return result;
-}
-
-CURLcode Curl_dupset(struct Curl_easy *dst, struct Curl_easy *src)
-{
- CURLcode result = CURLE_OK;
- enum dupstring i;
-
- /* Copy src->set into dst->set first, then deal with the strings
- afterwards */
- dst->set = src->set;
-
- /* clear all string pointers first */
- memset(dst->set.str, 0, STRING_LAST * sizeof(char *));
-
- /* duplicate all strings */
- for(i=(enum dupstring)0; i< STRING_LASTZEROTERMINATED; i++) {
- result = setstropt(&dst->set.str[i], src->set.str[i]);
- if(result)
- return result;
- }
-
- /* duplicate memory areas pointed to */
- i = STRING_COPYPOSTFIELDS;
- if(src->set.postfieldsize && src->set.str[i]) {
- /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
- dst->set.str[i] = Curl_memdup(src->set.str[i],
- curlx_sotouz(src->set.postfieldsize));
- if(!dst->set.str[i])
- return CURLE_OUT_OF_MEMORY;
- /* point to the new copy */
- dst->set.postfields = dst->set.str[i];
- }
-
- return CURLE_OK;
+ struct urlpieces *up = &data->state.up;
+ Curl_safefree(up->scheme);
+ Curl_safefree(up->hostname);
+ Curl_safefree(up->port);
+ Curl_safefree(up->user);
+ Curl_safefree(up->password);
+ Curl_safefree(up->options);
+ Curl_safefree(up->path);
+ Curl_safefree(up->query);
+ curl_url_cleanup(data->state.uh);
+ data->state.uh = NULL;
}
/*
@@ -410,16 +325,17 @@ CURLcode Curl_close(struct Curl_easy *data)
Curl_expire_clear(data); /* shut off timers */
m = data->multi;
-
if(m)
/* This handle is still part of a multi handle, take care of this first
and detach this handle from there. */
curl_multi_remove_handle(data->multi, data);
- if(data->multi_easy)
+ if(data->multi_easy) {
/* when curl_easy_perform() is used, it creates its own multi handle to
use and this is the one */
curl_multi_cleanup(data->multi_easy);
+ data->multi_easy = NULL;
+ }
/* Destroy the timeout list that is held in the easy handle. It is
/normally/ done by curl_multi_remove_handle() but this is "just in
@@ -433,10 +349,6 @@ CURLcode Curl_close(struct Curl_easy *data)
if(data->state.rangestringalloc)
free(data->state.range);
- /* Free the pathbuffer */
- Curl_safefree(data->state.pathbuffer);
- data->state.path = NULL;
-
/* freed here just in case DONE wasn't called */
Curl_free_request_state(data);
@@ -456,19 +368,19 @@ CURLcode Curl_close(struct Curl_easy *data)
}
data->change.referer = NULL;
- if(data->change.url_alloc) {
- Curl_safefree(data->change.url);
- data->change.url_alloc = FALSE;
- }
- data->change.url = NULL;
-
+ up_free(data);
Curl_safefree(data->state.buffer);
Curl_safefree(data->state.headerbuff);
-
+ Curl_safefree(data->state.ulbuf);
Curl_flush_cookies(data, 1);
-
- Curl_digest_cleanup(data);
-
+#ifdef USE_ALTSVC
+ Curl_altsvc_save(data->asi, data->set.str[STRING_ALTSVC]);
+ Curl_altsvc_cleanup(data->asi);
+ data->asi = NULL;
+#endif
+#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_CRYPTO_AUTH)
+ Curl_http_auth_cleanup_digest(data);
+#endif
Curl_safefree(data->info.contenttype);
Curl_safefree(data->info.wouldredirect);
@@ -485,12 +397,8 @@ CURLcode Curl_close(struct Curl_easy *data)
Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
}
- if(data->set.wildcardmatch) {
- /* destruct wildcard structures if it is needed */
- struct WildcardData *wc = &data->wildcard;
- Curl_wildcard_dtor(wc);
- }
-
+ /* destruct wildcard structures if it is needed */
+ Curl_wildcard_dtor(&data->wildcard);
Curl_freeset(data);
free(data);
return CURLE_OK;
@@ -500,8 +408,9 @@ CURLcode Curl_close(struct Curl_easy *data)
* Initialize the UserDefined fields within a Curl_easy.
* This may be safely called on a new or existing Curl_easy.
*/
-CURLcode Curl_init_userdefined(struct UserDefined *set)
+CURLcode Curl_init_userdefined(struct Curl_easy *data)
{
+ struct UserDefined *set = &data->set;
CURLcode result = CURLE_OK;
set->out = stdout; /* default output to stdout */
@@ -530,11 +439,12 @@ CURLcode Curl_init_userdefined(struct UserDefined *set)
set->httpreq = HTTPREQ_GET; /* Default HTTP request */
set->rtspreq = RTSPREQ_OPTIONS; /* Default RTSP request */
+#ifndef CURL_DISABLE_FILE
set->ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
set->ftp_use_pret = FALSE; /* mainly useful for drftpd servers */
set->ftp_filemethod = FTPFILE_MULTICWD;
-
+#endif
set->dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
/* Set the default size of the SSL session ID cache */
@@ -545,9 +455,14 @@ CURLcode Curl_init_userdefined(struct UserDefined *set)
set->httpauth = CURLAUTH_BASIC; /* defaults to basic */
set->proxyauth = CURLAUTH_BASIC; /* defaults to basic */
+ /* SOCKS5 proxy auth defaults to username/password + GSS-API */
+ set->socks5auth = CURLAUTH_BASIC | CURLAUTH_GSSAPI;
+
/* make libcurl quiet by default: */
set->hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
+ Curl_mime_initpart(&set->mimepost, data);
+
/*
* libcurl 7.10 introduced SSL verification *by default*! This needs to be
* switched off unless wanted.
@@ -582,46 +497,61 @@ CURLcode Curl_init_userdefined(struct UserDefined *set)
set->socks5_gssapi_nec = FALSE;
#endif
- /* This is our preferred CA cert bundle/path since install time */
+ /* Set the default CA cert bundle/path detected/specified at build time.
+ *
+ * If Schannel is the selected SSL backend then these locations are
+ * ignored. We allow setting CA location for schannel only when explicitly
+ * specified by the user via CURLOPT_CAINFO / --cacert.
+ */
+ if(Curl_ssl_backend() != CURLSSLBACKEND_SCHANNEL) {
#if defined(CURL_CA_BUNDLE)
- result = setstropt(&set->str[STRING_SSL_CAFILE_ORIG], CURL_CA_BUNDLE);
- if(result)
- return result;
+ result = Curl_setstropt(&set->str[STRING_SSL_CAFILE_ORIG], CURL_CA_BUNDLE);
+ if(result)
+ return result;
- result = setstropt(&set->str[STRING_SSL_CAFILE_PROXY], CURL_CA_BUNDLE);
- if(result)
- return result;
+ result = Curl_setstropt(&set->str[STRING_SSL_CAFILE_PROXY],
+ CURL_CA_BUNDLE);
+ if(result)
+ return result;
#endif
#if defined(CURL_CA_PATH)
- result = setstropt(&set->str[STRING_SSL_CAPATH_ORIG], CURL_CA_PATH);
- if(result)
- return result;
+ result = Curl_setstropt(&set->str[STRING_SSL_CAPATH_ORIG], CURL_CA_PATH);
+ if(result)
+ return result;
- result = setstropt(&set->str[STRING_SSL_CAPATH_PROXY], CURL_CA_PATH);
- if(result)
- return result;
+ result = Curl_setstropt(&set->str[STRING_SSL_CAPATH_PROXY], CURL_CA_PATH);
+ if(result)
+ return result;
#endif
+ }
- set->wildcardmatch = FALSE;
+ set->wildcard_enabled = FALSE;
set->chunk_bgn = ZERO_NULL;
set->chunk_end = ZERO_NULL;
-
- /* tcp keepalives are disabled by default, but provide reasonable values for
- * the interval and idle times.
- */
set->tcp_keepalive = FALSE;
set->tcp_keepintvl = 60;
set->tcp_keepidle = 60;
set->tcp_fastopen = FALSE;
set->tcp_nodelay = TRUE;
-
set->ssl_enable_npn = TRUE;
set->ssl_enable_alpn = TRUE;
-
set->expect_100_timeout = 1000L; /* Wait for a second by default. */
set->sep_headers = TRUE; /* separated header lists by default */
set->buffer_size = READBUFFER_SIZE;
-
+ set->upload_buffer_size = UPLOADBUFFER_DEFAULT;
+ set->happy_eyeballs_timeout = CURL_HET_DEFAULT;
+ set->fnmatch = ZERO_NULL;
+ set->upkeep_interval_ms = CURL_UPKEEP_INTERVAL_DEFAULT;
+ set->maxconnects = DEFAULT_CONNCACHE_SIZE; /* for easy handles */
+ set->maxage_conn = 118;
+ set->http09_allowed = TRUE;
+ set->httpversion =
+#ifdef USE_NGHTTP2
+ CURL_HTTP_VERSION_2TLS
+#else
+ CURL_HTTP_VERSION_1_1
+#endif
+ ;
Curl_http2_init_userset(set);
return result;
}
@@ -649,7 +579,7 @@ CURLcode Curl_open(struct Curl_easy **curl)
data->magic = CURLEASY_MAGIC_NUMBER;
- result = Curl_resolver_init(&data->state.resolver);
+ result = Curl_resolver_init(data, &data->state.resolver);
if(result) {
DEBUGF(fprintf(stderr, "Error: resolver_init failed\n"));
free(data);
@@ -663,30 +593,27 @@ CURLcode Curl_open(struct Curl_easy **curl)
DEBUGF(fprintf(stderr, "Error: malloc of buffer failed\n"));
result = CURLE_OUT_OF_MEMORY;
}
-
- data->state.headerbuff = malloc(HEADERSIZE);
- if(!data->state.headerbuff) {
- DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
- result = CURLE_OUT_OF_MEMORY;
- }
else {
- result = Curl_init_userdefined(&data->set);
-
- data->state.headersize=HEADERSIZE;
-
- Curl_convert_init(data);
+ data->state.headerbuff = malloc(HEADERSIZE);
+ if(!data->state.headerbuff) {
+ DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
+ result = CURLE_OUT_OF_MEMORY;
+ }
+ else {
+ result = Curl_init_userdefined(data);
- Curl_initinfo(data);
+ data->state.headersize = HEADERSIZE;
+ Curl_convert_init(data);
+ Curl_initinfo(data);
- /* most recent connection is not yet defined */
- data->state.lastconnect = NULL;
+ /* most recent connection is not yet defined */
+ data->state.lastconnect = NULL;
- data->progress.flags |= PGRS_HIDE;
- data->state.current_speed = -1; /* init to negative == impossible */
- data->set.fnmatch = ZERO_NULL;
- data->set.maxconnects = DEFAULT_CONNCACHE_SIZE; /* for easy handles */
+ data->progress.flags |= PGRS_HIDE;
+ data->state.current_speed = -1; /* init to negative == impossible */
- Curl_http2_init_state(&data->state);
+ Curl_http2_init_state(&data->state);
+ }
}
if(result) {
@@ -703,2235 +630,6 @@ CURLcode Curl_open(struct Curl_easy **curl)
return result;
}
-#define C_SSLVERSION_VALUE(x) (x & 0xffff)
-#define C_SSLVERSION_MAX_VALUE(x) (x & 0xffff0000)
-
-CURLcode Curl_setopt(struct Curl_easy *data, CURLoption option,
- va_list param)
-{
- char *argptr;
- CURLcode result = CURLE_OK;
- long arg;
-#ifndef CURL_DISABLE_HTTP
- curl_off_t bigsize;
-#endif
-
- switch(option) {
- case CURLOPT_DNS_CACHE_TIMEOUT:
- data->set.dns_cache_timeout = va_arg(param, long);
- break;
- case CURLOPT_DNS_USE_GLOBAL_CACHE:
- /* remember we want this enabled */
- arg = va_arg(param, long);
- data->set.global_dns_cache = (0 != arg) ? TRUE : FALSE;
- break;
- case CURLOPT_SSL_CIPHER_LIST:
- /* set a list of cipher we want to use in the SSL connection */
- result = setstropt(&data->set.str[STRING_SSL_CIPHER_LIST_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_SSL_CIPHER_LIST:
- /* set a list of cipher we want to use in the SSL connection for proxy */
- result = setstropt(&data->set.str[STRING_SSL_CIPHER_LIST_PROXY],
- 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.
- */
- result = setstropt(&data->set.str[STRING_SSL_RANDOM_FILE],
- va_arg(param, char *));
- break;
- case CURLOPT_EGDSOCKET:
- /*
- * The Entropy Gathering Daemon socket pathname
- */
- result = setstropt(&data->set.str[STRING_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.
- */
- data->set.maxconnects = 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_HEADER:
- /*
- * Set to include the header in the general data output stream.
- */
- data->set.include_header = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_NOPROGRESS:
- /*
- * Shut off the internal supported progress meter
- */
- data->set.hide_progress = (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_FAILONERROR:
- /*
- * Don't output the >=400 error code HTML-page, but instead only
- * return error.
- */
- data->set.http_fail_on_error = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_KEEP_SENDING_ON_ERROR:
- data->set.http_keep_sending_on_error = (0 != va_arg(param, long)) ?
- TRUE : FALSE;
- 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- if(data->set.upload) {
- /* If this is HTTP, PUT is what's needed to "upload" */
- data->set.httpreq = HTTPREQ_PUT;
- data->set.opt_no_body = FALSE; /* this is implied */
- }
- else
- /* In HTTP, the opposite of upload is GET (unless NOBODY is true as
- then this can be changed to HEAD later on) */
- data->set.httpreq = HTTPREQ_GET;
- 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_FTP_CREATE_MISSING_DIRS:
- /*
- * An FTP option that modifies an upload to create missing directories on
- * the server.
- */
- switch(va_arg(param, long)) {
- case 0:
- data->set.ftp_create_missing_dirs = 0;
- break;
- case 1:
- data->set.ftp_create_missing_dirs = 1;
- break;
- case 2:
- data->set.ftp_create_missing_dirs = 2;
- break;
- default:
- /* reserve other values for future use */
- result = CURLE_UNKNOWN_OPTION;
- break;
- }
- break;
- case CURLOPT_SERVER_RESPONSE_TIMEOUT:
- /*
- * Option that specifies how quickly an server response must be obtained
- * before it is considered failure. For pingpong protocols.
- */
- data->set.server_response_timeout = va_arg(param, long) * 1000;
- break;
- case CURLOPT_TFTP_NO_OPTIONS:
- /*
- * Option that prevents libcurl from sending TFTP option requests to the
- * server.
- */
- data->set.tftp_no_options = va_arg(param, long) != 0;
- break;
- case CURLOPT_TFTP_BLKSIZE:
- /*
- * TFTP option that specifies the block size to use for data transmission.
- */
- data->set.tftp_blksize = va_arg(param, long);
- break;
- case CURLOPT_DIRLISTONLY:
- /*
- * An option that changes the command to one that asks for a list
- * only, no file info details.
- */
- data->set.ftp_list_only = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_APPEND:
- /*
- * We want to upload and append to an existing file.
- */
- data->set.ftp_append = (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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
- */
- result = setstropt(&data->set.str[STRING_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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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.
- */
-#ifdef USE_SSL
- arg = va_arg(param, long);
- data->set.ssl.primary.version = C_SSLVERSION_VALUE(arg);
- data->set.ssl.primary.version_max = C_SSLVERSION_MAX_VALUE(arg);
-#else
- result = CURLE_UNKNOWN_OPTION;
-#endif
- break;
- case CURLOPT_PROXY_SSLVERSION:
- /*
- * Set explicit SSL version to try to connect with for proxy, as some SSL
- * implementations are lame.
- */
-#ifdef USE_SSL
- arg = va_arg(param, long);
- data->set.proxy_ssl.primary.version = C_SSLVERSION_VALUE(arg);
- data->set.proxy_ssl.primary.version_max = C_SSLVERSION_MAX_VALUE(arg);
-#else
- result = CURLE_UNKNOWN_OPTION;
-#endif
- break;
-
-#ifndef CURL_DISABLE_HTTP
- case CURLOPT_AUTOREFERER:
- /*
- * Switch on automatic referer that gets set if curl follows locations.
- */
- data->set.http_auto_referer = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_ACCEPT_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.
- *
- */
- argptr = va_arg(param, char *);
- result = setstropt(&data->set.str[STRING_ENCODING],
- (argptr && !*argptr)?
- ALL_CONTENT_ENCODINGS: argptr);
- break;
-
- case CURLOPT_TRANSFER_ENCODING:
- data->set.http_transfer_encoding = (0 != va_arg(param, long)) ?
- TRUE : FALSE;
- break;
-
- case CURLOPT_FOLLOWLOCATION:
- /*
- * Follow Location: header hints on a HTTP-server.
- */
- data->set.http_follow_location = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_UNRESTRICTED_AUTH:
- /*
- * Send authentication (user+password) when following locations, even when
- * hostname changed.
- */
- data->set.http_disable_hostname_check_before_authentication =
- (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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_POSTREDIR:
- {
- /*
- * Set the behaviour of POST when redirecting
- * CURL_REDIR_GET_ALL - POST is changed to GET after 301 and 302
- * CURL_REDIR_POST_301 - POST is kept as POST after 301
- * CURL_REDIR_POST_302 - POST is kept as POST after 302
- * CURL_REDIR_POST_303 - POST is kept as POST after 303
- * CURL_REDIR_POST_ALL - POST is kept as POST after 301, 302 and 303
- * other - POST is kept as POST after 301 and 302
- */
- arg = va_arg(param, long);
- data->set.keep_post = arg & CURL_REDIR_POST_ALL;
- }
- 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_COPYPOSTFIELDS:
- /*
- * A string with POST data. Makes curl HTTP POST. Even if it is NULL.
- * If needed, CURLOPT_POSTFIELDSIZE must have been set prior to
- * CURLOPT_COPYPOSTFIELDS and not altered later.
- */
- argptr = va_arg(param, char *);
-
- if(!argptr || data->set.postfieldsize == -1)
- result = setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
- else {
- /*
- * Check that requested length does not overflow the size_t type.
- */
-
- if((data->set.postfieldsize < 0) ||
- ((sizeof(curl_off_t) != sizeof(size_t)) &&
- (data->set.postfieldsize > (curl_off_t)((size_t)-1))))
- result = CURLE_OUT_OF_MEMORY;
- else {
- char *p;
-
- (void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
-
- /* Allocate even when size == 0. This satisfies the need of possible
- later address compare to detect the COPYPOSTFIELDS mode, and
- to mark that postfields is used rather than read function or
- form data.
- */
- p = malloc((size_t)(data->set.postfieldsize?
- data->set.postfieldsize:1));
-
- if(!p)
- result = CURLE_OUT_OF_MEMORY;
- else {
- if(data->set.postfieldsize)
- memcpy(p, argptr, (size_t)data->set.postfieldsize);
-
- data->set.str[STRING_COPYPOSTFIELDS] = p;
- }
- }
- }
-
- data->set.postfields = data->set.str[STRING_COPYPOSTFIELDS];
- data->set.httpreq = HTTPREQ_POST;
- break;
-
- case CURLOPT_POSTFIELDS:
- /*
- * Like above, but use static data instead of copying it.
- */
- data->set.postfields = va_arg(param, void *);
- /* Release old copied data. */
- (void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
- 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.
- */
- bigsize = va_arg(param, long);
-
- if(data->set.postfieldsize < bigsize &&
- data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
- /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
- (void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
- data->set.postfields = NULL;
- }
-
- data->set.postfieldsize = bigsize;
- break;
-
- case CURLOPT_POSTFIELDSIZE_LARGE:
- /*
- * The size of the POSTFIELD data to prevent libcurl to do strlen() to
- * figure it out. Enables binary posts.
- */
- bigsize = va_arg(param, curl_off_t);
-
- if(data->set.postfieldsize < bigsize &&
- data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
- /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
- (void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
- data->set.postfields = NULL;
- }
-
- data->set.postfieldsize = bigsize;
- 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) {
- Curl_safefree(data->change.referer);
- data->change.referer_alloc = FALSE;
- }
- result = setstropt(&data->set.str[STRING_SET_REFERER],
- va_arg(param, char *));
- data->change.referer = data->set.str[STRING_SET_REFERER];
- break;
-
- case CURLOPT_USERAGENT:
- /*
- * String to use in the HTTP User-Agent field
- */
- result = setstropt(&data->set.str[STRING_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_PROXYHEADER:
- /*
- * Set a list with proxy headers to use (or replace internals with)
- *
- * Since CURLOPT_HTTPHEADER was the only way to set HTTP headers for a
- * long time we remain doing it this way until CURLOPT_PROXYHEADER is
- * used. As soon as this option has been used, if set to anything but
- * NULL, custom headers for proxies are only picked from this list.
- *
- * Set this option to NULL to restore the previous behavior.
- */
- data->set.proxyheaders = va_arg(param, struct curl_slist *);
- break;
-
- case CURLOPT_HEADEROPT:
- /*
- * Set header option.
- */
- arg = va_arg(param, long);
- data->set.sep_headers = (arg & CURLHEADER_SEPARATE)? TRUE: FALSE;
- 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.
- */
- result = setstropt(&data->set.str[STRING_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) {
- curl_slist_free_all(data->change.cookielist);
- data->change.cookielist = NULL;
- return CURLE_OUT_OF_MEMORY;
- }
- data->change.cookielist = cl; /* store the list for later use */
- }
- break;
-
- case CURLOPT_COOKIEJAR:
- /*
- * Set cookie file name to dump all cookies to when we're done.
- */
- {
- struct CookieInfo *newcookies;
- result = setstropt(&data->set.str[STRING_COOKIEJAR],
- va_arg(param, char *));
-
- /*
- * Activate the cookie parser. This may or may not already
- * have been made.
- */
- newcookies = Curl_cookie_init(data, NULL, data->cookies,
- data->set.cookiesession);
- if(!newcookies)
- result = CURLE_OUT_OF_MEMORY;
- data->cookies = newcookies;
- }
- 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_COOKIELIST:
- argptr = va_arg(param, char *);
-
- if(argptr == NULL)
- break;
-
- if(strcasecompare(argptr, "ALL")) {
- /* clear all cookies */
- Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
- Curl_cookie_clearall(data->cookies);
- Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
- }
- else if(strcasecompare(argptr, "SESS")) {
- /* clear session cookies */
- Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
- Curl_cookie_clearsess(data->cookies);
- Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
- }
- else if(strcasecompare(argptr, "FLUSH")) {
- /* flush cookies to file, takes care of the locking */
- Curl_flush_cookies(data, 0);
- }
- else if(strcasecompare(argptr, "RELOAD")) {
- /* reload cookies from file */
- Curl_cookie_loadfiles(data);
- break;
- }
- else {
- 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 || !data->cookies) {
- result = CURLE_OUT_OF_MEMORY;
- free(argptr);
- }
- else {
- Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
-
- 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);
-
- Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
- 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.
- */
- arg = va_arg(param, long);
-#ifndef USE_NGHTTP2
- if(arg >= CURL_HTTP_VERSION_2)
- return CURLE_UNSUPPORTED_PROTOCOL;
-#endif
- data->set.httpversion = arg;
- break;
-
- case CURLOPT_HTTPAUTH:
- /*
- * Set HTTP Authentication type BITMASK.
- */
- {
- int bitcheck;
- bool authbits;
- unsigned long auth = va_arg(param, unsigned long);
-
- if(auth == CURLAUTH_NONE) {
- data->set.httpauth = auth;
- break;
- }
-
- /* the DIGEST_IE bit is only used to set a special marker, for all the
- rest we need to handle it as normal DIGEST */
- data->state.authhost.iestyle = (auth & CURLAUTH_DIGEST_IE) ? TRUE : FALSE;
-
- if(auth & CURLAUTH_DIGEST_IE) {
- auth |= CURLAUTH_DIGEST; /* set standard digest bit */
- auth &= ~CURLAUTH_DIGEST_IE; /* unset ie digest bit */
- }
-
- /* switch off bits we can't support */
-#ifndef USE_NTLM
- auth &= ~CURLAUTH_NTLM; /* no NTLM support */
- auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
-#elif !defined(NTLM_WB_ENABLED)
- auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
-#endif
-#ifndef USE_SPNEGO
- auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without
- GSS-API or SSPI */
-#endif
-
- /* check if any auth bit lower than CURLAUTH_ONLY is still set */
- bitcheck = 0;
- authbits = FALSE;
- while(bitcheck < 31) {
- if(auth & (1UL << bitcheck++)) {
- authbits = TRUE;
- break;
- }
- }
- if(!authbits)
- return CURLE_NOT_BUILT_IN; /* no supported types left! */
-
- data->set.httpauth = auth;
- }
- break;
-
- case CURLOPT_EXPECT_100_TIMEOUT_MS:
- /*
- * Time to wait for a response to a HTTP request containing an
- * Expect: 100-continue header before sending the data anyway.
- */
- data->set.expect_100_timeout = va_arg(param, long);
- break;
-
-#endif /* CURL_DISABLE_HTTP */
-
- case CURLOPT_CUSTOMREQUEST:
- /*
- * Set a custom string to use as request
- */
- result = setstropt(&data->set.str[STRING_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;
-
-#ifndef CURL_DISABLE_PROXY
- case CURLOPT_HTTPPROXYTUNNEL:
- /*
- * Tunnel operations through the proxy instead of normal proxy use
- */
- data->set.tunnel_thru_httpproxy = (0 != va_arg(param, long)) ?
- TRUE : FALSE;
- break;
-
- case CURLOPT_PROXYPORT:
- /*
- * Explicitly set HTTP proxy port number.
- */
- data->set.proxyport = va_arg(param, long);
- break;
-
- case CURLOPT_PROXYAUTH:
- /*
- * Set HTTP Authentication type BITMASK.
- */
- {
- int bitcheck;
- bool authbits;
- unsigned long auth = va_arg(param, unsigned long);
-
- if(auth == CURLAUTH_NONE) {
- data->set.proxyauth = auth;
- break;
- }
-
- /* the DIGEST_IE bit is only used to set a special marker, for all the
- rest we need to handle it as normal DIGEST */
- data->state.authproxy.iestyle = (auth & CURLAUTH_DIGEST_IE) ? TRUE : FALSE;
-
- if(auth & CURLAUTH_DIGEST_IE) {
- auth |= CURLAUTH_DIGEST; /* set standard digest bit */
- auth &= ~CURLAUTH_DIGEST_IE; /* unset ie digest bit */
- }
- /* switch off bits we can't support */
-#ifndef USE_NTLM
- auth &= ~CURLAUTH_NTLM; /* no NTLM support */
- auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
-#elif !defined(NTLM_WB_ENABLED)
- auth &= ~CURLAUTH_NTLM_WB; /* no NTLM_WB support */
-#endif
-#ifndef USE_SPNEGO
- auth &= ~CURLAUTH_NEGOTIATE; /* no Negotiate (SPNEGO) auth without
- GSS-API or SSPI */
-#endif
-
- /* check if any auth bit lower than CURLAUTH_ONLY is still set */
- bitcheck = 0;
- authbits = FALSE;
- while(bitcheck < 31) {
- if(auth & (1UL << bitcheck++)) {
- authbits = TRUE;
- break;
- }
- }
- if(!authbits)
- return CURLE_NOT_BUILT_IN; /* no supported types left! */
-
- data->set.proxyauth = auth;
- }
- break;
-
- case CURLOPT_PROXY:
- /*
- * Set proxy server:port to use as proxy.
- *
- * If the proxy is set to "" (and CURLOPT_SOCKS_PROXY is set to "" or NULL)
- * 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 (if CURLOPT_SOCKS_PROXY setting it to NULL).
- */
- result = setstropt(&data->set.str[STRING_PROXY],
- va_arg(param, char *));
- break;
-
- case CURLOPT_PRE_PROXY:
- /*
- * Set proxy server:port to use as SOCKS proxy.
- *
- * If the proxy is set to "" or NULL we explicitly say that we don't want
- * to use the socks proxy.
- */
- result = setstropt(&data->set.str[STRING_PRE_PROXY],
- va_arg(param, char *));
- break;
-
- case CURLOPT_PROXYTYPE:
- /*
- * Set proxy type. HTTP/HTTP_1_0/SOCKS4/SOCKS4a/SOCKS5/SOCKS5_HOSTNAME
- */
- data->set.proxytype = (curl_proxytype)va_arg(param, long);
- break;
-
- case CURLOPT_PROXY_TRANSFER_MODE:
- /*
- * set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy
- */
- switch(va_arg(param, long)) {
- case 0:
- data->set.proxy_transfer_mode = FALSE;
- break;
- case 1:
- data->set.proxy_transfer_mode = TRUE;
- break;
- default:
- /* reserve other values for future use */
- result = CURLE_UNKNOWN_OPTION;
- break;
- }
- break;
-#endif /* CURL_DISABLE_PROXY */
-
-#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
- case CURLOPT_SOCKS5_GSSAPI_NEC:
- /*
- * Set flag for NEC SOCK5 support
- */
- data->set.socks5_gssapi_nec = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_SOCKS5_GSSAPI_SERVICE:
- case CURLOPT_PROXY_SERVICE_NAME:
- /*
- * Set proxy authentication service name for Kerberos 5 and SPNEGO
- */
- result = setstropt(&data->set.str[STRING_PROXY_SERVICE_NAME],
- va_arg(param, char *));
- break;
-#endif
-
-#if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
- defined(USE_SPNEGO)
- case CURLOPT_SERVICE_NAME:
- /*
- * Set authentication service name for DIGEST-MD5, Kerberos 5 and SPNEGO
- */
- result = setstropt(&data->set.str[STRING_SERVICE_NAME],
- va_arg(param, char *));
- break;
-
-#endif
-
- case CURLOPT_HEADERDATA:
- /*
- * 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_WRITEDATA:
- /*
- * FILE pointer to write to. Or possibly
- * used as argument to the write callback.
- */
- data->set.out = va_arg(param, void *);
- break;
- case CURLOPT_FTPPORT:
- /*
- * Use FTP PORT, this also specifies which IP address to use
- */
- result = setstropt(&data->set.str[STRING_FTPPORT],
- va_arg(param, char *));
- data->set.ftp_use_port = (data->set.str[STRING_FTPPORT]) ? TRUE : FALSE;
- break;
-
- case CURLOPT_FTP_USE_EPRT:
- data->set.ftp_use_eprt = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_FTP_USE_EPSV:
- data->set.ftp_use_epsv = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_FTP_USE_PRET:
- data->set.ftp_use_pret = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_FTP_SSL_CCC:
- data->set.ftp_ccc = (curl_ftpccc)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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_READDATA:
- /*
- * FILE pointer to read the file to be uploaded from. Or possibly
- * used as argument to the read callback.
- */
- data->set.in_set = va_arg(param, void *);
- break;
- case CURLOPT_INFILESIZE:
- /*
- * If known, this should inform curl about the file size of the
- * to-be-uploaded file.
- */
- data->set.filesize = 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.filesize = 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:
- /*
- * When transfer uploads are faster then CURLOPT_MAX_SEND_SPEED_LARGE
- * 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:
- /*
- * When receiving data faster than CURLOPT_MAX_RECV_SPEED_LARGE 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! */
- Curl_safefree(data->change.url);
- data->change.url_alloc = FALSE;
- }
- result = setstropt(&data->set.str[STRING_SET_URL],
- va_arg(param, char *));
- data->change.url = data->set.str[STRING_SET_URL];
- 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) * 1000L;
- break;
-
- case CURLOPT_TIMEOUT_MS:
- 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) * 1000L;
- break;
-
- case CURLOPT_CONNECTTIMEOUT_MS:
- data->set.connecttimeout = va_arg(param, long);
- break;
-
- case CURLOPT_ACCEPTTIMEOUT_MS:
- /*
- * The maximum time you allow curl to wait for server connect
- */
- data->set.accepttimeout = va_arg(param, long);
- break;
-
- case CURLOPT_USERPWD:
- /*
- * user:password to use in the operation
- */
- result = setstropt_userpwd(va_arg(param, char *),
- &data->set.str[STRING_USERNAME],
- &data->set.str[STRING_PASSWORD]);
- break;
-
- case CURLOPT_USERNAME:
- /*
- * authentication user name to use in the operation
- */
- result = setstropt(&data->set.str[STRING_USERNAME],
- va_arg(param, char *));
- break;
-
- case CURLOPT_PASSWORD:
- /*
- * authentication password to use in the operation
- */
- result = setstropt(&data->set.str[STRING_PASSWORD],
- va_arg(param, char *));
- break;
-
- case CURLOPT_LOGIN_OPTIONS:
- /*
- * authentication options to use in the operation
- */
- result = setstropt(&data->set.str[STRING_OPTIONS],
- va_arg(param, char *));
- break;
-
- case CURLOPT_XOAUTH2_BEARER:
- /*
- * OAuth 2.0 bearer token to use in the operation
- */
- result = setstropt(&data->set.str[STRING_BEARER],
- 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_RESOLVE:
- /*
- * List of NAME:[address] names to populate the DNS cache with
- * Prefix the NAME with dash (-) to _remove_ the name from the cache.
- *
- * Names added with this API will remain in the cache until explicitly
- * removed or the handle is cleaned up.
- *
- * This API can remove any name from the DNS cache, but only entries
- * that aren't actually in use right now will be pruned immediately.
- */
- data->set.resolve = va_arg(param, struct curl_slist *);
- data->change.resolve = data->set.resolve;
- 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_XFERINFOFUNCTION:
- /*
- * Transfer info callback function
- */
- data->set.fxferinfo = va_arg(param, curl_xferinfo_callback);
- if(data->set.fxferinfo)
- 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;
-
-#ifndef CURL_DISABLE_PROXY
- case CURLOPT_PROXYUSERPWD:
- /*
- * user:password needed to use the proxy
- */
- result = setstropt_userpwd(va_arg(param, char *),
- &data->set.str[STRING_PROXYUSERNAME],
- &data->set.str[STRING_PROXYPASSWORD]);
- break;
- case CURLOPT_PROXYUSERNAME:
- /*
- * authentication user name to use in the operation
- */
- result = setstropt(&data->set.str[STRING_PROXYUSERNAME],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXYPASSWORD:
- /*
- * authentication password to use in the operation
- */
- result = setstropt(&data->set.str[STRING_PROXYPASSWORD],
- va_arg(param, char *));
- break;
- case CURLOPT_NOPROXY:
- /*
- * proxy exception list
- */
- result = setstropt(&data->set.str[STRING_NOPROXY],
- va_arg(param, char *));
- break;
-#endif
-
- case CURLOPT_RANGE:
- /*
- * What range of the file you want to transfer
- */
- result = setstropt(&data->set.str[STRING_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_func = va_arg(param, curl_write_callback);
- if(!data->set.fwrite_func) {
- data->set.is_fwrite_set = 0;
- /* When set to NULL, reset to our internal default function */
- data->set.fwrite_func = (curl_write_callback)fwrite;
- }
- else
- data->set.is_fwrite_set = 1;
- break;
- case CURLOPT_READFUNCTION:
- /*
- * Read data callback
- */
- data->set.fread_func_set = va_arg(param, curl_read_callback);
- if(!data->set.fread_func_set) {
- data->set.is_fread_set = 0;
- /* When set to NULL, reset to our internal default function */
- data->set.fread_func_set = (curl_read_callback)fread;
- }
- else
- data->set.is_fread_set = 1;
- break;
- case CURLOPT_SEEKFUNCTION:
- /*
- * Seek callback. Might be NULL.
- */
- data->set.seek_func = va_arg(param, curl_seek_callback);
- break;
- case CURLOPT_SEEKDATA:
- /*
- * Seek control callback. Might be NULL.
- */
- data->set.seek_client = va_arg(param, void *);
- 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_func = 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
- */
- result = setstropt(&data->set.str[STRING_CERT_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_SSLCERT:
- /*
- * String that holds file name of the SSL certificate to use for proxy
- */
- result = setstropt(&data->set.str[STRING_CERT_PROXY],
- va_arg(param, char *));
- break;
- case CURLOPT_SSLCERTTYPE:
- /*
- * String that holds file type of the SSL certificate to use
- */
- result = setstropt(&data->set.str[STRING_CERT_TYPE_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_SSLCERTTYPE:
- /*
- * String that holds file type of the SSL certificate to use for proxy
- */
- result = setstropt(&data->set.str[STRING_CERT_TYPE_PROXY],
- va_arg(param, char *));
- break;
- case CURLOPT_SSLKEY:
- /*
- * String that holds file name of the SSL key to use
- */
- result = setstropt(&data->set.str[STRING_KEY_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_SSLKEY:
- /*
- * String that holds file name of the SSL key to use for proxy
- */
- result = setstropt(&data->set.str[STRING_KEY_PROXY],
- va_arg(param, char *));
- break;
- case CURLOPT_SSLKEYTYPE:
- /*
- * String that holds file type of the SSL key to use
- */
- result = setstropt(&data->set.str[STRING_KEY_TYPE_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_SSLKEYTYPE:
- /*
- * String that holds file type of the SSL key to use for proxy
- */
- result = setstropt(&data->set.str[STRING_KEY_TYPE_PROXY],
- va_arg(param, char *));
- break;
- case CURLOPT_KEYPASSWD:
- /*
- * String that holds the SSL or SSH private key password.
- */
- result = setstropt(&data->set.str[STRING_KEY_PASSWD_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_KEYPASSWD:
- /*
- * String that holds the SSL private key password for proxy.
- */
- result = setstropt(&data->set.str[STRING_KEY_PASSWD_PROXY],
- 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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.
- */
- result = setstropt(&data->set.str[STRING_DEVICE],
- va_arg(param, char *));
- break;
- case CURLOPT_LOCALPORT:
- /*
- * Set what local port to bind the socket to when performing an operation.
- */
- arg = va_arg(param, long);
- if((arg < 0) || (arg > 65535))
- return CURLE_BAD_FUNCTION_ARGUMENT;
- data->set.localport = curlx_sltous(arg);
- break;
- case CURLOPT_LOCALPORTRANGE:
- /*
- * Set number of local ports to try, starting with CURLOPT_LOCALPORT.
- */
- arg = va_arg(param, long);
- if((arg < 0) || (arg > 65535))
- return CURLE_BAD_FUNCTION_ARGUMENT;
- data->set.localportrange = curlx_sltosi(arg);
- break;
- case CURLOPT_KRBLEVEL:
- /*
- * A string that defines the kerberos security level.
- */
- result = setstropt(&data->set.str[STRING_KRB_LEVEL],
- va_arg(param, char *));
- data->set.krb = (data->set.str[STRING_KRB_LEVEL]) ? TRUE : FALSE;
- break;
- case CURLOPT_GSSAPI_DELEGATION:
- /*
- * GSS-API credential delegation
- */
- data->set.gssapi_delegation = va_arg(param, long);
- break;
- case CURLOPT_SSL_VERIFYPEER:
- /*
- * Enable peer SSL verifying.
- */
- data->set.ssl.primary.verifypeer = (0 != va_arg(param, long)) ?
- TRUE : FALSE;
- break;
- case CURLOPT_PROXY_SSL_VERIFYPEER:
- /*
- * Enable peer SSL verifying for proxy.
- */
- data->set.proxy_ssl.primary.verifypeer =
- (0 != va_arg(param, long))?TRUE:FALSE;
- break;
- case CURLOPT_SSL_VERIFYHOST:
- /*
- * Enable verification of the host name in the peer certificate
- */
- arg = va_arg(param, long);
-
- /* Obviously people are not reading documentation and too many thought
- this argument took a boolean when it wasn't and misused it. We thus ban
- 1 as a sensible input and we warn about its use. Then we only have the
- 2 action internally stored as TRUE. */
-
- if(1 == arg) {
- failf(data, "CURLOPT_SSL_VERIFYHOST no longer supports 1 as value!");
- return CURLE_BAD_FUNCTION_ARGUMENT;
- }
-
- data->set.ssl.primary.verifyhost = (0 != arg) ? TRUE : FALSE;
- break;
- case CURLOPT_PROXY_SSL_VERIFYHOST:
- /*
- * Enable verification of the host name in the peer certificate for proxy
- */
- arg = va_arg(param, long);
-
- /* Obviously people are not reading documentation and too many thought
- this argument took a boolean when it wasn't and misused it. We thus ban
- 1 as a sensible input and we warn about its use. Then we only have the
- 2 action internally stored as TRUE. */
-
- if(1 == arg) {
- failf(data, "CURLOPT_SSL_VERIFYHOST no longer supports 1 as value!");
- return CURLE_BAD_FUNCTION_ARGUMENT;
- }
-
- data->set.proxy_ssl.primary.verifyhost = (0 != arg)?TRUE:FALSE;
- break;
- case CURLOPT_SSL_VERIFYSTATUS:
- /*
- * Enable certificate status verifying.
- */
- if(!Curl_ssl_cert_status_request()) {
- result = CURLE_NOT_BUILT_IN;
- break;
- }
-
- data->set.ssl.primary.verifystatus = (0 != va_arg(param, long)) ?
- TRUE : FALSE;
- break;
- case CURLOPT_SSL_CTX_FUNCTION:
-#ifdef have_curlssl_ssl_ctx
- /*
- * Set a SSL_CTX callback
- */
- data->set.ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback);
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_SSL_CTX_DATA:
-#ifdef have_curlssl_ssl_ctx
- /*
- * Set a SSL_CTX callback parameter pointer
- */
- data->set.ssl.fsslctxp = va_arg(param, void *);
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_SSL_FALSESTART:
- /*
- * Enable TLS false start.
- */
- if(!Curl_ssl_false_start()) {
- result = CURLE_NOT_BUILT_IN;
- break;
- }
-
- data->set.ssl.falsestart = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_CERTINFO:
-#ifdef have_curlssl_certinfo
- data->set.ssl.certinfo = (0 != va_arg(param, long)) ? TRUE : FALSE;
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_PINNEDPUBLICKEY:
-#ifdef have_curlssl_pinnedpubkey /* only by supported backends */
- /*
- * Set pinned public key for SSL connection.
- * Specify file name of the public key in DER format.
- */
- result = setstropt(&data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG],
- va_arg(param, char *));
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_PROXY_PINNEDPUBLICKEY:
-#ifdef have_curlssl_pinnedpubkey /* only by supported backends */
- /*
- * Set pinned public key for SSL connection.
- * Specify file name of the public key in DER format.
- */
- result = setstropt(&data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY],
- va_arg(param, char *));
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_CAINFO:
- /*
- * Set CA info for SSL connection. Specify file name of the CA certificate
- */
- result = setstropt(&data->set.str[STRING_SSL_CAFILE_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_CAINFO:
- /*
- * Set CA info SSL connection for proxy. Specify file name of the
- * CA certificate
- */
- result = setstropt(&data->set.str[STRING_SSL_CAFILE_PROXY],
- va_arg(param, char *));
- break;
- case CURLOPT_CAPATH:
-#ifdef have_curlssl_ca_path /* not supported by all backends */
- /*
- * 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. */
- result = setstropt(&data->set.str[STRING_SSL_CAPATH_ORIG],
- va_arg(param, char *));
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_PROXY_CAPATH:
-#ifdef have_curlssl_ca_path /* not supported by all backends */
- /*
- * Set CA path info for SSL connection proxy. Specify directory name of the
- * CA certificates which have been prepared using openssl c_rehash utility.
- */
- /* This does not work on windows. */
- result = setstropt(&data->set.str[STRING_SSL_CAPATH_PROXY],
- va_arg(param, char *));
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_CRLFILE:
- /*
- * Set CRL file info for SSL connection. Specify file name of the CRL
- * to check certificates revocation
- */
- result = setstropt(&data->set.str[STRING_SSL_CRLFILE_ORIG],
- va_arg(param, char *));
- break;
- case CURLOPT_PROXY_CRLFILE:
- /*
- * Set CRL file info for SSL connection for proxy. Specify file name of the
- * CRL to check certificates revocation
- */
- result = setstropt(&data->set.str[STRING_SSL_CRLFILE_PROXY],
- va_arg(param, char *));
- break;
- case CURLOPT_ISSUERCERT:
- /*
- * Set Issuer certificate file
- * to check certificates issuer
- */
- result = setstropt(&data->set.str[STRING_SSL_ISSUERCERT_ORIG],
- 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.
- */
- arg = va_arg(param, long);
-
- if(arg > READBUFFER_MAX)
- arg = READBUFFER_MAX;
- else if(arg < 1)
- arg = READBUFFER_SIZE;
- else if(arg < READBUFFER_MIN)
- arg = READBUFFER_MIN;
-
- /* Resize if new size */
- if(arg != data->set.buffer_size) {
- char *newbuff = realloc(data->state.buffer, arg + 1);
- if(!newbuff) {
- DEBUGF(fprintf(stderr, "Error: realloc of buffer failed\n"));
- result = CURLE_OUT_OF_MEMORY;
- }
- else
- data->state.buffer = newbuff;
- }
- data->set.buffer_size = arg;
-
- break;
-
- case CURLOPT_NOSIGNAL:
- /*
- * The application asks not to set any signal() or alarm() handlers,
- * even when using a timeout.
- */
- data->set.no_signal = (0 != va_arg(param, long)) ? TRUE : FALSE;
- 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 !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
- if(data->share->cookies == data->cookies)
- data->cookies = NULL;
-#endif
-
- if(data->share->sslsession == data->state.session)
- data->state.session = 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->specifier & (1<< CURL_LOCK_DATA_DNS)) {
- /* use shared host cache */
- 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 */
- Curl_cookie_cleanup(data->cookies);
- /* enable cookies since we now use a share that uses cookies! */
- data->cookies = data->share->cookies;
- }
-#endif /* CURL_DISABLE_HTTP */
- if(data->share->sslsession) {
- data->set.general_ssl.max_ssl_sessions = data->share->max_ssl_sessions;
- data->state.session = data->share->sslsession;
- }
- Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
-
- }
- /* check for host cache not needed,
- * it will be done by curl_easy_perform */
- }
- break;
-
- case CURLOPT_PRIVATE:
- /*
- * Set private data pointer.
- */
- data->set.private_data = va_arg(param, void *);
- break;
-
- case CURLOPT_MAXFILESIZE:
- /*
- * Set the maximum size of a file to download.
- */
- data->set.max_filesize = va_arg(param, long);
- break;
-
-#ifdef USE_SSL
- case CURLOPT_USE_SSL:
- /*
- * Make transfers attempt to use SSL/TLS.
- */
- data->set.use_ssl = (curl_usessl)va_arg(param, long);
- break;
-
- case CURLOPT_SSL_OPTIONS:
- arg = va_arg(param, long);
- data->set.ssl.enable_beast = arg&CURLSSLOPT_ALLOW_BEAST?TRUE:FALSE;
- data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
- break;
-
- case CURLOPT_PROXY_SSL_OPTIONS:
- arg = va_arg(param, long);
- data->set.proxy_ssl.enable_beast = arg&CURLSSLOPT_ALLOW_BEAST?TRUE:FALSE;
- data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
- break;
-
-#endif
- 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.ipver = 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 = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_FTP_ACCOUNT:
- result = setstropt(&data->set.str[STRING_FTP_ACCOUNT],
- va_arg(param, char *));
- break;
-
- case CURLOPT_IGNORE_CONTENT_LENGTH:
- data->set.ignorecl = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_CONNECT_ONLY:
- /*
- * No data transfer, set up connection and let application use the socket
- */
- data->set.connect_only = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_FTP_ALTERNATIVE_TO_USER:
- result = setstropt(&data->set.str[STRING_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_OPENSOCKETFUNCTION:
- /*
- * open/create socket callback function: called instead of socket(),
- * before connect()
- */
- data->set.fopensocket = va_arg(param, curl_opensocket_callback);
- break;
-
- case CURLOPT_OPENSOCKETDATA:
- /*
- * socket callback data pointer. Might be NULL.
- */
- data->set.opensocket_client = va_arg(param, void *);
- break;
-
- case CURLOPT_CLOSESOCKETFUNCTION:
- /*
- * close socket callback function: called instead of close()
- * when shutting down a connection
- */
- data->set.fclosesocket = va_arg(param, curl_closesocket_callback);
- break;
-
- case CURLOPT_CLOSESOCKETDATA:
- /*
- * socket callback data pointer. Might be NULL.
- */
- data->set.closesocket_client = va_arg(param, void *);
- break;
-
- case CURLOPT_SSL_SESSIONID_CACHE:
- data->set.ssl.primary.sessionid = (0 != va_arg(param, long)) ?
- TRUE : FALSE;
- data->set.proxy_ssl.primary.sessionid = data->set.ssl.primary.sessionid;
- break;
-
-#ifdef USE_LIBSSH2
- /* we only include SSH options if explicitly built to support SSH */
- 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
- */
- result = setstropt(&data->set.str[STRING_SSH_PUBLIC_KEY],
- va_arg(param, char *));
- break;
-
- case CURLOPT_SSH_PRIVATE_KEYFILE:
- /*
- * Use this file instead of the $HOME/.ssh/id_dsa file
- */
- result = setstropt(&data->set.str[STRING_SSH_PRIVATE_KEY],
- va_arg(param, char *));
- break;
- case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
- /*
- * Option to allow for the MD5 of the host public key to be checked
- * for validation purposes.
- */
- result = setstropt(&data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5],
- va_arg(param, char *));
- break;
-#ifdef HAVE_LIBSSH2_KNOWNHOST_API
- case CURLOPT_SSH_KNOWNHOSTS:
- /*
- * Store the file name to read known hosts from.
- */
- result = setstropt(&data->set.str[STRING_SSH_KNOWNHOSTS],
- va_arg(param, char *));
- break;
-
- case CURLOPT_SSH_KEYFUNCTION:
- /* setting to NULL is fine since the ssh.c functions themselves will
- then rever to use the internal default */
- data->set.ssh_keyfunc = va_arg(param, curl_sshkeycallback);
- break;
-
- case CURLOPT_SSH_KEYDATA:
- /*
- * Custom client data to pass to the SSH keyfunc callback
- */
- data->set.ssh_keyfunc_userp = va_arg(param, void *);
- break;
-#endif /* HAVE_LIBSSH2_KNOWNHOST_API */
-
-#endif /* USE_LIBSSH2 */
-
- case CURLOPT_HTTP_TRANSFER_DECODING:
- /*
- * disable libcurl transfer encoding is used
- */
- data->set.http_te_skip = (0 == va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_HTTP_CONTENT_DECODING:
- /*
- * raw data passed to the application when content encoding is used
- */
- data->set.http_ce_skip = (0 == va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_NEW_FILE_PERMS:
- /*
- * Uses these permissions instead of 0644
- */
- data->set.new_file_perms = va_arg(param, long);
- break;
-
- case CURLOPT_NEW_DIRECTORY_PERMS:
- /*
- * Uses these permissions instead of 0755
- */
- data->set.new_directory_perms = va_arg(param, long);
- break;
-
- case CURLOPT_ADDRESS_SCOPE:
- /*
- * We always get longs when passed plain numericals, but for this value we
- * know that an unsigned int will always hold the value so we blindly
- * typecast to this type
- */
- arg = va_arg(param, long);
- if((arg < 0) || (arg > 0xf))
- return CURLE_BAD_FUNCTION_ARGUMENT;
- data->set.scope_id = curlx_sltoui(arg);
- break;
-
- case CURLOPT_PROTOCOLS:
- /* set the bitmask for the protocols that are allowed to be used for the
- transfer, which thus helps the app which takes URLs from users or other
- external inputs and want to restrict what protocol(s) to deal
- with. Defaults to CURLPROTO_ALL. */
- data->set.allowed_protocols = va_arg(param, long);
- break;
-
- case CURLOPT_REDIR_PROTOCOLS:
- /* set the bitmask for the protocols that libcurl is allowed to follow to,
- as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs
- to be set in both bitmasks to be allowed to get redirected to. Defaults
- to all protocols except FILE and SCP. */
- data->set.redir_protocols = va_arg(param, long);
- break;
-
- case CURLOPT_DEFAULT_PROTOCOL:
- /* Set the protocol to use when the URL doesn't include any protocol */
- result = setstropt(&data->set.str[STRING_DEFAULT_PROTOCOL],
- va_arg(param, char *));
- break;
-
- case CURLOPT_MAIL_FROM:
- /* Set the SMTP mail originator */
- result = setstropt(&data->set.str[STRING_MAIL_FROM],
- va_arg(param, char *));
- break;
-
- case CURLOPT_MAIL_AUTH:
- /* Set the SMTP auth originator */
- result = setstropt(&data->set.str[STRING_MAIL_AUTH],
- va_arg(param, char *));
- break;
-
- case CURLOPT_MAIL_RCPT:
- /* Set the list of mail recipients */
- data->set.mail_rcpt = va_arg(param, struct curl_slist *);
- break;
-
- case CURLOPT_SASL_IR:
- /* Enable/disable SASL initial response */
- data->set.sasl_ir = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
- case CURLOPT_RTSP_REQUEST:
- {
- /*
- * Set the RTSP request method (OPTIONS, SETUP, PLAY, etc...)
- * Would this be better if the RTSPREQ_* were just moved into here?
- */
- long curl_rtspreq = va_arg(param, long);
- Curl_RtspReq rtspreq = RTSPREQ_NONE;
- switch(curl_rtspreq) {
- case CURL_RTSPREQ_OPTIONS:
- rtspreq = RTSPREQ_OPTIONS;
- break;
-
- case CURL_RTSPREQ_DESCRIBE:
- rtspreq = RTSPREQ_DESCRIBE;
- break;
-
- case CURL_RTSPREQ_ANNOUNCE:
- rtspreq = RTSPREQ_ANNOUNCE;
- break;
-
- case CURL_RTSPREQ_SETUP:
- rtspreq = RTSPREQ_SETUP;
- break;
-
- case CURL_RTSPREQ_PLAY:
- rtspreq = RTSPREQ_PLAY;
- break;
-
- case CURL_RTSPREQ_PAUSE:
- rtspreq = RTSPREQ_PAUSE;
- break;
-
- case CURL_RTSPREQ_TEARDOWN:
- rtspreq = RTSPREQ_TEARDOWN;
- break;
-
- case CURL_RTSPREQ_GET_PARAMETER:
- rtspreq = RTSPREQ_GET_PARAMETER;
- break;
-
- case CURL_RTSPREQ_SET_PARAMETER:
- rtspreq = RTSPREQ_SET_PARAMETER;
- break;
-
- case CURL_RTSPREQ_RECORD:
- rtspreq = RTSPREQ_RECORD;
- break;
-
- case CURL_RTSPREQ_RECEIVE:
- rtspreq = RTSPREQ_RECEIVE;
- break;
- default:
- rtspreq = RTSPREQ_NONE;
- }
-
- data->set.rtspreq = rtspreq;
- break;
- }
-
-
- case CURLOPT_RTSP_SESSION_ID:
- /*
- * Set the RTSP Session ID manually. Useful if the application is
- * resuming a previously established RTSP session
- */
- result = setstropt(&data->set.str[STRING_RTSP_SESSION_ID],
- va_arg(param, char *));
- break;
-
- case CURLOPT_RTSP_STREAM_URI:
- /*
- * Set the Stream URI for the RTSP request. Unless the request is
- * for generic server options, the application will need to set this.
- */
- result = setstropt(&data->set.str[STRING_RTSP_STREAM_URI],
- va_arg(param, char *));
- break;
-
- case CURLOPT_RTSP_TRANSPORT:
- /*
- * The content of the Transport: header for the RTSP request
- */
- result = setstropt(&data->set.str[STRING_RTSP_TRANSPORT],
- va_arg(param, char *));
- break;
-
- case CURLOPT_RTSP_CLIENT_CSEQ:
- /*
- * Set the CSEQ number to issue for the next RTSP request. Useful if the
- * application is resuming a previously broken connection. The CSEQ
- * will increment from this new number henceforth.
- */
- data->state.rtsp_next_client_CSeq = va_arg(param, long);
- break;
-
- case CURLOPT_RTSP_SERVER_CSEQ:
- /* Same as the above, but for server-initiated requests */
- data->state.rtsp_next_client_CSeq = va_arg(param, long);
- break;
-
- case CURLOPT_INTERLEAVEDATA:
- data->set.rtp_out = va_arg(param, void *);
- break;
- case CURLOPT_INTERLEAVEFUNCTION:
- /* Set the user defined RTP write function */
- data->set.fwrite_rtp = va_arg(param, curl_write_callback);
- break;
-
- case CURLOPT_WILDCARDMATCH:
- data->set.wildcardmatch = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_CHUNK_BGN_FUNCTION:
- data->set.chunk_bgn = va_arg(param, curl_chunk_bgn_callback);
- break;
- case CURLOPT_CHUNK_END_FUNCTION:
- data->set.chunk_end = va_arg(param, curl_chunk_end_callback);
- break;
- case CURLOPT_FNMATCH_FUNCTION:
- data->set.fnmatch = va_arg(param, curl_fnmatch_callback);
- break;
- case CURLOPT_CHUNK_DATA:
- data->wildcard.customptr = va_arg(param, void *);
- break;
- case CURLOPT_FNMATCH_DATA:
- data->set.fnmatch_data = va_arg(param, void *);
- break;
-#ifdef USE_TLS_SRP
- case CURLOPT_TLSAUTH_USERNAME:
- result = setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_ORIG],
- va_arg(param, char *));
- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype)
- data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
- break;
- case CURLOPT_PROXY_TLSAUTH_USERNAME:
- result = setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_PROXY],
- va_arg(param, char *));
- if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] &&
- !data->set.proxy_ssl.authtype)
- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
- break;
- case CURLOPT_TLSAUTH_PASSWORD:
- result = setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_ORIG],
- va_arg(param, char *));
- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype)
- data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
- break;
- case CURLOPT_PROXY_TLSAUTH_PASSWORD:
- result = setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_PROXY],
- va_arg(param, char *));
- if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] &&
- !data->set.proxy_ssl.authtype)
- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
- break;
- case CURLOPT_TLSAUTH_TYPE:
- argptr = va_arg(param, char *);
- if(!argptr ||
- strncasecompare(argptr, "SRP", strlen("SRP")))
- data->set.ssl.authtype = CURL_TLSAUTH_SRP;
- else
- data->set.ssl.authtype = CURL_TLSAUTH_NONE;
- break;
- case CURLOPT_PROXY_TLSAUTH_TYPE:
- argptr = va_arg(param, char *);
- if(!argptr ||
- strncasecompare(argptr, "SRP", strlen("SRP")))
- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP;
- else
- data->set.proxy_ssl.authtype = CURL_TLSAUTH_NONE;
- break;
-#endif
- case CURLOPT_DNS_SERVERS:
- result = Curl_set_dns_servers(data, va_arg(param, char *));
- break;
- case CURLOPT_DNS_INTERFACE:
- result = Curl_set_dns_interface(data, va_arg(param, char *));
- break;
- case CURLOPT_DNS_LOCAL_IP4:
- result = Curl_set_dns_local_ip4(data, va_arg(param, char *));
- break;
- case CURLOPT_DNS_LOCAL_IP6:
- result = Curl_set_dns_local_ip6(data, va_arg(param, char *));
- break;
-
- case CURLOPT_TCP_KEEPALIVE:
- data->set.tcp_keepalive = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_TCP_KEEPIDLE:
- data->set.tcp_keepidle = va_arg(param, long);
- break;
- case CURLOPT_TCP_KEEPINTVL:
- data->set.tcp_keepintvl = va_arg(param, long);
- break;
- case CURLOPT_TCP_FASTOPEN:
-#if defined(CONNECT_DATA_IDEMPOTENT) || defined(MSG_FASTOPEN)
- data->set.tcp_fastopen = (0 != va_arg(param, long))?TRUE:FALSE;
-#else
- result = CURLE_NOT_BUILT_IN;
-#endif
- break;
- case CURLOPT_SSL_ENABLE_NPN:
- data->set.ssl_enable_npn = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_SSL_ENABLE_ALPN:
- data->set.ssl_enable_alpn = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
-
-#ifdef USE_UNIX_SOCKETS
- case CURLOPT_UNIX_SOCKET_PATH:
- data->set.abstract_unix_socket = FALSE;
- result = setstropt(&data->set.str[STRING_UNIX_SOCKET_PATH],
- va_arg(param, char *));
- break;
- case CURLOPT_ABSTRACT_UNIX_SOCKET:
- data->set.abstract_unix_socket = TRUE;
- result = setstropt(&data->set.str[STRING_UNIX_SOCKET_PATH],
- va_arg(param, char *));
- break;
-#endif
-
- case CURLOPT_PATH_AS_IS:
- data->set.path_as_is = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_PIPEWAIT:
- data->set.pipewait = (0 != va_arg(param, long)) ? TRUE : FALSE;
- break;
- case CURLOPT_STREAM_WEIGHT:
-#ifndef USE_NGHTTP2
- return CURLE_NOT_BUILT_IN;
-#else
- arg = va_arg(param, long);
- if((arg>=1) && (arg <= 256))
- data->set.stream_weight = (int)arg;
- break;
-#endif
- case CURLOPT_STREAM_DEPENDS:
- case CURLOPT_STREAM_DEPENDS_E:
- {
-#ifndef USE_NGHTTP2
- return CURLE_NOT_BUILT_IN;
-#else
- struct Curl_easy *dep = va_arg(param, struct Curl_easy *);
- if(!dep || GOOD_EASY_HANDLE(dep)) {
- if(data->set.stream_depends_on) {
- Curl_http2_remove_child(data->set.stream_depends_on, data);
- }
- Curl_http2_add_child(dep, data, (option == CURLOPT_STREAM_DEPENDS_E));
- }
- break;
-#endif
- }
- case CURLOPT_CONNECT_TO:
- data->set.connect_to = va_arg(param, struct curl_slist *);
- break;
- case CURLOPT_SUPPRESS_CONNECT_HEADERS:
- data->set.suppress_connect_headers = (0 != va_arg(param, long))?TRUE:FALSE;
- break;
- default:
- /* unknown tag and its companion, just ignore: */
- result = CURLE_UNKNOWN_OPTION;
- break;
- }
-
- return result;
-}
-
#ifdef USE_RECV_BEFORE_SEND_WORKAROUND
static void conn_reset_postponed_data(struct connectdata *conn, int num)
{
@@ -2970,11 +668,15 @@ static void conn_reset_all_postponed_data(struct connectdata *conn)
#define conn_reset_all_postponed_data(c) do {} WHILE_FALSE
#endif /* ! USE_RECV_BEFORE_SEND_WORKAROUND */
-static void conn_free(struct connectdata *conn)
+
+static void conn_shutdown(struct connectdata *conn)
{
if(!conn)
return;
+ infof(conn->data, "Closing connection %ld\n", conn->connection_id);
+ DEBUGASSERT(conn->data);
+
/* possible left-overs from the async name resolvers */
Curl_resolver_cancel(conn);
@@ -2993,10 +695,20 @@ static void conn_free(struct connectdata *conn)
if(CURL_SOCKET_BAD != conn->tempsock[1])
Curl_closesocket(conn, conn->tempsock[1]);
-#if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
- defined(NTLM_WB_ENABLED)
- Curl_ntlm_wb_cleanup(conn);
-#endif
+ /* unlink ourselves. this should be called last since other shutdown
+ procedures need a valid conn->data and this may clear it. */
+ Curl_conncache_remove_conn(conn->data, conn, TRUE);
+}
+
+static void conn_free(struct connectdata *conn)
+{
+ if(!conn)
+ return;
+
+ free_idnconverted_hostname(&conn->host);
+ free_idnconverted_hostname(&conn->conn_to_host);
+ free_idnconverted_hostname(&conn->http_proxy.host);
+ free_idnconverted_hostname(&conn->socks_proxy.host);
Curl_safefree(conn->user);
Curl_safefree(conn->passwd);
@@ -3019,17 +731,14 @@ static void conn_free(struct connectdata *conn)
Curl_safefree(conn->trailer);
Curl_safefree(conn->host.rawalloc); /* host name buffer */
Curl_safefree(conn->conn_to_host.rawalloc); /* host name buffer */
+ Curl_safefree(conn->hostname_resolve);
Curl_safefree(conn->secondaryhostname);
Curl_safefree(conn->http_proxy.host.rawalloc); /* http proxy name buffer */
Curl_safefree(conn->socks_proxy.host.rawalloc); /* socks proxy name buffer */
- Curl_safefree(conn->master_buffer);
- Curl_safefree(conn->connect_buffer);
+ Curl_safefree(conn->connect_state);
conn_reset_all_postponed_data(conn);
-
- Curl_llist_destroy(&conn->send_pipe, NULL);
- Curl_llist_destroy(&conn->recv_pipe, NULL);
-
+ Curl_llist_destroy(&conn->easyq, NULL);
Curl_safefree(conn->localdev);
Curl_free_primary_ssl_config(&conn->ssl_config);
Curl_free_primary_ssl_config(&conn->proxy_ssl_config);
@@ -3038,6 +747,9 @@ static void conn_free(struct connectdata *conn)
Curl_safefree(conn->unix_domain_socket);
#endif
+#ifdef USE_SSL
+ Curl_safefree(conn->ssl_extra);
+#endif
free(conn); /* free all the connection oriented data */
}
@@ -3046,20 +758,23 @@ static void conn_free(struct connectdata *conn)
* primary connection, like when freeing room in the connection cache or
* killing of a dead old connection.
*
+ * A connection needs an easy handle when closing down. We support this passed
+ * in separately since the connection to get closed here is often already
+ * disassociated from an easy handle.
+ *
* This function MUST NOT reset state in the Curl_easy struct if that
* isn't strictly bound to the life-time of *this* particular connection.
*
*/
-CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection)
+CURLcode Curl_disconnect(struct Curl_easy *data,
+ struct connectdata *conn, bool dead_connection)
{
- struct Curl_easy *data;
if(!conn)
return CURLE_OK; /* this is closed and fine already */
- data = conn->data;
if(!data) {
- DEBUGF(fprintf(stderr, "DISCONNECT without easy handle, ignoring\n"));
+ DEBUGF(infof(data, "DISCONNECT without easy handle, ignoring\n"));
return CURLE_OK;
}
@@ -3067,10 +782,8 @@ CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection)
* If this connection isn't marked to force-close, leave it open if there
* are other users of it
*/
- if(!conn->bits.close &&
- (conn->send_pipe.size + conn->recv_pipe.size)) {
- DEBUGF(infof(data, "Curl_disconnect, usecounter: %d\n",
- conn->send_pipe.size + conn->recv_pipe.size));
+ if(CONN_INUSE(conn) && !dead_connection) {
+ DEBUGF(infof(data, "Curl_disconnect when inuse: %zu\n", CONN_INUSE(conn)));
return CURLE_OK;
}
@@ -3083,32 +796,27 @@ CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection)
#if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM)
/* Cleanup NTLM connection-related data */
- Curl_http_ntlm_cleanup(conn);
+ Curl_http_auth_cleanup_ntlm(conn);
#endif
+#if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO)
+ /* Cleanup NEGOTIATE connection-related data */
+ Curl_http_auth_cleanup_negotiate(conn);
+#endif
+
+ /* the protocol specific disconnect handler and conn_shutdown need a transfer
+ for the connection! */
+ conn->data = data;
+
+ if(conn->bits.connect_only)
+ /* treat the connection as dead in CONNECT_ONLY situations */
+ dead_connection = TRUE;
if(conn->handler->disconnect)
/* This is set if protocol-specific cleanups should be made */
conn->handler->disconnect(conn, dead_connection);
- /* unlink ourselves! */
- infof(data, "Closing connection %ld\n", conn->connection_id);
- Curl_conncache_remove_conn(data->state.conn_cache, conn);
-
- free_fixed_hostname(&conn->host);
- free_fixed_hostname(&conn->conn_to_host);
- free_fixed_hostname(&conn->http_proxy.host);
- free_fixed_hostname(&conn->socks_proxy.host);
-
- Curl_ssl_close(conn, FIRSTSOCKET);
-
- /* Indicate to all handles on the pipe that we're dead */
- if(Curl_pipeline_wanted(data->multi, CURLPIPE_ANY)) {
- signalPipeClose(&conn->send_pipe, TRUE);
- signalPipeClose(&conn->recv_pipe, TRUE);
- }
-
+ conn_shutdown(conn);
conn_free(conn);
-
return CURLE_OK;
}
@@ -3131,28 +839,21 @@ static bool SocketIsDead(curl_socket_t sock)
}
/*
- * IsPipeliningPossible()
+ * IsMultiplexingPossible()
*
- * Return a bitmask with the available pipelining and multiplexing options for
- * the given requested connection.
+ * Return a bitmask with the available multiplexing options for the given
+ * requested connection.
*/
-static int IsPipeliningPossible(const struct Curl_easy *handle,
- const struct connectdata *conn)
+static int IsMultiplexingPossible(const struct Curl_easy *handle,
+ const struct connectdata *conn)
{
int avail = 0;
- /* If a HTTP protocol and pipelining is enabled */
+ /* If a HTTP protocol and multiplexing is enabled */
if((conn->handler->protocol & PROTO_FAMILY_HTTP) &&
(!conn->bits.protoconnstart || !conn->bits.close)) {
- if(Curl_pipeline_wanted(handle->multi, CURLPIPE_HTTP1) &&
- (handle->set.httpversion != CURL_HTTP_VERSION_1_0) &&
- (handle->set.httpreq == HTTPREQ_GET ||
- handle->set.httpreq == HTTPREQ_HEAD))
- /* didn't ask for HTTP/1.0 and a GET or HEAD */
- avail |= CURLPIPE_HTTP1;
-
- if(Curl_pipeline_wanted(handle->multi, CURLPIPE_MULTIPLEX) &&
+ if(Curl_multiplex_wanted(handle->multi) &&
(handle->set.httpversion >= CURL_HTTP_VERSION_2))
/* allows HTTP/2 */
avail |= CURLPIPE_MULTIPLEX;
@@ -3160,144 +861,7 @@ static int IsPipeliningPossible(const struct Curl_easy *handle,
return avail;
}
-int Curl_removeHandleFromPipeline(struct Curl_easy *handle,
- struct curl_llist *pipeline)
-{
- if(pipeline) {
- struct curl_llist_element *curr;
-
- curr = pipeline->head;
- while(curr) {
- if(curr->ptr == handle) {
- Curl_llist_remove(pipeline, 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 *pipeline)
-{
- struct curl_llist_element *curr;
-
- curr = pipeline->head;
- while(curr) {
- struct Curl_easy *data = (struct Curl_easy *) curr->ptr;
- infof(data, "Handle in pipeline: %s\n", data->state.path);
- curr = curr->next;
- }
-}
-#endif
-
-static struct Curl_easy* gethandleathead(struct curl_llist *pipeline)
-{
- struct curl_llist_element *curr = pipeline->head;
- if(curr) {
- return (struct Curl_easy *) curr->ptr;
- }
-
- return NULL;
-}
-
-/* remove the specified connection from all (possible) pipelines and related
- queues */
-void Curl_getoff_all_pipelines(struct Curl_easy *data,
- struct connectdata *conn)
-{
- bool recv_head = (conn->readchannel_inuse &&
- Curl_recvpipe_head(data, conn));
- bool send_head = (conn->writechannel_inuse &&
- Curl_sendpipe_head(data, conn));
-
- if(Curl_removeHandleFromPipeline(data, &conn->recv_pipe) && recv_head)
- Curl_pipeline_leave_read(conn);
- if(Curl_removeHandleFromPipeline(data, &conn->send_pipe) && send_head)
- Curl_pipeline_leave_write(conn);
-}
-
-static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke)
-{
- struct curl_llist_element *curr;
-
- if(!pipeline)
- return;
-
- curr = pipeline->head;
- while(curr) {
- struct curl_llist_element *next = curr->next;
- struct Curl_easy *data = (struct Curl_easy *) curr->ptr;
-
-#ifdef DEBUGBUILD /* debug-only code */
- if(data->magic != CURLEASY_MAGIC_NUMBER) {
- /* MAJOR BADNESS */
- infof(data, "signalPipeClose() found BAAD easy handle\n");
- }
-#endif
-
- if(pipe_broke)
- data->state.pipe_broke = TRUE;
- Curl_multi_handlePipeBreak(data);
- Curl_llist_remove(pipeline, curr, NULL);
- curr = next;
- }
-}
-
-/*
- * This function finds the connection in the connection
- * cache that has been unused for the longest time.
- *
- * Returns the pointer to the oldest idle connection, or NULL if none was
- * found.
- */
-struct connectdata *
-Curl_oldest_idle_connection(struct Curl_easy *data)
-{
- struct conncache *bc = data->state.conn_cache;
- struct curl_hash_iterator iter;
- struct curl_llist_element *curr;
- struct curl_hash_element *he;
- time_t highscore=-1;
- time_t score;
- struct timeval now;
- struct connectdata *conn_candidate = NULL;
- struct connectbundle *bundle;
-
- now = Curl_tvnow();
-
- Curl_hash_start_iterate(&bc->hash, &iter);
-
- he = Curl_hash_next_element(&iter);
- while(he) {
- struct connectdata *conn;
-
- bundle = he->ptr;
-
- curr = bundle->conn_list.head;
- while(curr) {
- conn = curr->ptr;
-
- if(!conn->inuse) {
- /* Set higher score for the age passed since the connection was used */
- score = Curl_tvdiff(now, conn->now);
-
- if(score > highscore) {
- highscore = score;
- conn_candidate = conn;
- }
- }
- curr = curr->next;
- }
-
- he = Curl_hash_next_element(&iter);
- }
-
- return conn_candidate;
-}
-
+#ifndef CURL_DISABLE_PROXY
static bool
proxy_info_matches(const struct proxy_info* data,
const struct proxy_info* needle)
@@ -3309,92 +873,68 @@ proxy_info_matches(const struct proxy_info* data,
return FALSE;
}
-
+#else
+/* disabled, won't get called */
+#define proxy_info_matches(x,y) FALSE
+#endif
/*
- * This function finds the connection in the connection
- * bundle that has been unused for the longest time.
+ * This function checks if the given connection is dead and extracts it from
+ * the connection cache if so.
*
- * Returns the pointer to the oldest idle connection, or NULL if none was
- * found.
- */
-static struct connectdata *
-find_oldest_idle_connection_in_bundle(struct Curl_easy *data,
- struct connectbundle *bundle)
-{
- struct curl_llist_element *curr;
- time_t highscore=-1;
- time_t score;
- struct timeval now;
- struct connectdata *conn_candidate = NULL;
- struct connectdata *conn;
-
- (void)data;
-
- now = Curl_tvnow();
-
- curr = bundle->conn_list.head;
- while(curr) {
- conn = curr->ptr;
-
- if(!conn->inuse) {
- /* Set higher score for the age passed since the connection was used */
- score = Curl_tvdiff(now, conn->now);
-
- if(score > highscore) {
- highscore = score;
- conn_candidate = conn;
- }
- }
- curr = curr->next;
- }
-
- return conn_candidate;
-}
-
-/*
- * This function checks if given connection is dead and disconnects if so.
- * (That also removes it from the connection cache.)
+ * When this is called as a Curl_conncache_foreach() callback, the connection
+ * cache lock is held!
*
- * Returns TRUE if the connection actually was dead and disconnected.
+ * Returns TRUE if the connection was dead and extracted.
*/
-static bool disconnect_if_dead(struct connectdata *conn,
- struct Curl_easy *data)
+static bool extract_if_dead(struct connectdata *conn,
+ struct Curl_easy *data)
{
- size_t pipeLen = conn->send_pipe.size + conn->recv_pipe.size;
- if(!pipeLen && !conn->inuse) {
- /* The check for a dead socket makes sense only if there are no
- handles in pipeline and the connection isn't already marked in
+ if(!CONN_INUSE(conn) && !conn->data) {
+ /* The check for a dead socket makes sense only if the connection isn't in
use */
bool dead;
- if(conn->handler->protocol & CURLPROTO_RTSP)
- /* RTSP is a special case due to RTP interleaving */
- dead = Curl_rtsp_connisdead(conn);
- else
+ if(conn->handler->connection_check) {
+ /* The protocol has a special method for checking the state of the
+ connection. Use it to check if the connection is dead. */
+ unsigned int state;
+ struct Curl_easy *olddata = conn->data;
+ conn->data = data; /* use this transfer for now */
+ state = conn->handler->connection_check(conn, CONNCHECK_ISDEAD);
+ conn->data = olddata;
+ dead = (state & CONNRESULT_DEAD);
+ }
+ else {
+ /* Use the general method for determining the death of a connection */
dead = SocketIsDead(conn->sock[FIRSTSOCKET]);
+ }
if(dead) {
- conn->data = data;
infof(data, "Connection %ld seems to be dead!\n", conn->connection_id);
-
- /* disconnect resources */
- Curl_disconnect(conn, /* dead_connection */TRUE);
+ Curl_conncache_remove_conn(data, conn, FALSE);
return TRUE;
}
}
return FALSE;
}
+struct prunedead {
+ struct Curl_easy *data;
+ struct connectdata *extracted;
+};
+
/*
- * Wrapper to use disconnect_if_dead() function in Curl_conncache_foreach()
+ * Wrapper to use extract_if_dead() function in Curl_conncache_foreach()
*
- * Returns always 0.
*/
-static int call_disconnect_if_dead(struct connectdata *conn,
- void *param)
+static int call_extract_if_dead(struct connectdata *conn, void *param)
{
- struct Curl_easy* data = (struct Curl_easy*)param;
- disconnect_if_dead(conn, data);
+ struct prunedead *p = (struct prunedead *)param;
+ if(extract_if_dead(conn, p->data)) {
+ /* stop the iteration here, pass back the connection that was extracted */
+ p->extracted = conn;
+ return 1;
+ }
return 0; /* continue iteration */
}
@@ -3405,23 +945,41 @@ static int call_disconnect_if_dead(struct connectdata *conn,
*/
static void prune_dead_connections(struct Curl_easy *data)
{
- struct timeval now = Curl_tvnow();
- time_t elapsed = Curl_tvdiff(now, data->state.conn_cache->last_cleanup);
+ struct curltime now = Curl_now();
+ time_t elapsed = Curl_timediff(now, data->state.conn_cache->last_cleanup);
if(elapsed >= 1000L) {
- Curl_conncache_foreach(data->state.conn_cache, data,
- call_disconnect_if_dead);
+ struct prunedead prune;
+ prune.data = data;
+ prune.extracted = NULL;
+ while(Curl_conncache_foreach(data, data->state.conn_cache, &prune,
+ call_extract_if_dead)) {
+ /* disconnect it */
+ (void)Curl_disconnect(data, prune.extracted, /* dead_connection */TRUE);
+ }
data->state.conn_cache->last_cleanup = now;
}
}
+/* A connection has to have been idle for a shorter time than 'maxage_conn' to
+ be subject for reuse. The success rate is just too low after this. */
-static size_t max_pipeline_length(struct Curl_multi *multi)
+static bool conn_maxage(struct Curl_easy *data,
+ struct connectdata *conn,
+ struct curltime now)
{
- return multi ? multi->max_pipeline_length : 0;
-}
-
+ if(!conn->data) {
+ timediff_t idletime = Curl_timediff(now, conn->lastused);
+ idletime /= 1000; /* integer seconds is fine */
+ if(idletime/1000 > data->set.maxage_conn) {
+ infof(data, "Too old connection (%ld seconds), disconnect it\n",
+ idletime);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
/*
* Given one filled in connection struct (named needle), this function should
* detect if there already is one that has all the significant details
@@ -3431,8 +989,7 @@ static size_t max_pipeline_length(struct Curl_multi *multi)
* connection as 'in-use'. It must later be called with ConnectionDone() to
* return back to 'idle' (unused) state.
*
- * The force_reuse flag is set if the connection must be used, even if
- * the pipelining strategy wants to open a new connection instead of reusing.
+ * The force_reuse flag is set if the connection must be used.
*/
static bool
ConnectionExists(struct Curl_easy *data,
@@ -3444,8 +1001,9 @@ ConnectionExists(struct Curl_easy *data,
struct connectdata *check;
struct connectdata *chosen = 0;
bool foundPendingCandidate = FALSE;
- int canpipe = IsPipeliningPossible(data, needle);
+ bool canmultiplex = IsMultiplexingPossible(data, needle);
struct connectbundle *bundle;
+ struct curltime now = Curl_now();
#ifdef USE_NTLM
bool wantNTLMhttp = ((data->state.authhost.want &
@@ -3460,58 +1018,47 @@ ConnectionExists(struct Curl_easy *data,
*force_reuse = FALSE;
*waitpipe = FALSE;
- /* We can't pipeline if the site is blacklisted */
- if((canpipe & CURLPIPE_HTTP1) &&
- Curl_pipeline_site_blacklisted(data, needle))
- canpipe &= ~ CURLPIPE_HTTP1;
-
- /* Look up the bundle with all the connections to this
- particular host */
+ /* Look up the bundle with all the connections to this particular host.
+ Locks the connection cache, beware of early returns! */
bundle = Curl_conncache_find_bundle(needle, data->state.conn_cache);
if(bundle) {
/* Max pipe length is zero (unlimited) for multiplexed connections */
- size_t max_pipe_len = (bundle->multiuse != BUNDLE_MULTIPLEX)?
- max_pipeline_length(data->multi):0;
- size_t best_pipe_len = max_pipe_len;
struct curl_llist_element *curr;
infof(data, "Found bundle for host %s: %p [%s]\n",
(needle->bits.conn_to_host ? needle->conn_to_host.name :
needle->host.name), (void *)bundle,
- (bundle->multiuse == BUNDLE_PIPELINING ?
- "can pipeline" :
- (bundle->multiuse == BUNDLE_MULTIPLEX ?
- "can multiplex" : "serially")));
-
- /* We can't pipeline if we don't know anything about the server */
- if(canpipe) {
- if(bundle->multiuse <= BUNDLE_UNKNOWN) {
+ (bundle->multiuse == BUNDLE_MULTIPLEX ?
+ "can multiplex" : "serially"));
+
+ /* We can't multiplex if we don't know anything about the server */
+ if(canmultiplex) {
+ if(bundle->multiuse == BUNDLE_UNKNOWN) {
if((bundle->multiuse == BUNDLE_UNKNOWN) && data->set.pipewait) {
- infof(data, "Server doesn't support multi-use yet, wait\n");
+ infof(data, "Server doesn't support multiplex yet, wait\n");
*waitpipe = TRUE;
+ Curl_conncache_unlock(data);
return FALSE; /* no re-use */
}
- infof(data, "Server doesn't support multi-use (yet)\n");
- canpipe = 0;
+ infof(data, "Server doesn't support multiplex (yet)\n");
+ canmultiplex = FALSE;
}
- if((bundle->multiuse == BUNDLE_PIPELINING) &&
- !Curl_pipeline_wanted(data->multi, CURLPIPE_HTTP1)) {
- /* not asked for, switch off */
- infof(data, "Could pipeline, but not asked to!\n");
- canpipe = 0;
- }
- else if((bundle->multiuse == BUNDLE_MULTIPLEX) &&
- !Curl_pipeline_wanted(data->multi, CURLPIPE_MULTIPLEX)) {
+ if((bundle->multiuse == BUNDLE_MULTIPLEX) &&
+ !Curl_multiplex_wanted(data->multi)) {
infof(data, "Could multiplex, but not asked to!\n");
- canpipe = 0;
+ canmultiplex = FALSE;
+ }
+ if(bundle->multiuse == BUNDLE_NO_MULTIUSE) {
+ infof(data, "Can not multiplex, even if we wanted to!\n");
+ canmultiplex = FALSE;
}
}
curr = bundle->conn_list.head;
while(curr) {
bool match = FALSE;
- size_t pipeLen;
+ size_t multiplexed;
/*
* Note that if we use a HTTP proxy in normal mode (no tunneling), we
@@ -3520,32 +1067,25 @@ ConnectionExists(struct Curl_easy *data,
check = curr->ptr;
curr = curr->next;
- if(disconnect_if_dead(check, data))
+ if(check->bits.connect_only)
+ /* connect-only connections will not be reused */
continue;
- pipeLen = check->send_pipe.size + check->recv_pipe.size;
+ if(conn_maxage(data, check, now) || extract_if_dead(check, data)) {
+ /* disconnect it */
+ (void)Curl_disconnect(data, check, /* dead_connection */TRUE);
+ continue;
+ }
+
+ multiplexed = CONN_INUSE(check) &&
+ (bundle->multiuse == BUNDLE_MULTIPLEX);
- if(canpipe) {
+ if(canmultiplex) {
if(check->bits.protoconnstart && check->bits.close)
continue;
-
- if(!check->bits.multiplex) {
- /* If not multiplexing, make sure the connection is fine for HTTP/1
- pipelining */
- struct Curl_easy* sh = gethandleathead(&check->send_pipe);
- struct Curl_easy* rh = gethandleathead(&check->recv_pipe);
- if(sh) {
- if(!(IsPipeliningPossible(sh, check) & CURLPIPE_HTTP1))
- continue;
- }
- else if(rh) {
- if(!(IsPipeliningPossible(rh, check) & CURLPIPE_HTTP1))
- continue;
- }
- }
}
else {
- if(pipeLen > 0) {
+ if(multiplexed) {
/* can only happen within multi handles, and means that another easy
handle is using this connection */
continue;
@@ -3570,13 +1110,6 @@ ConnectionExists(struct Curl_easy *data,
to get closed. */
infof(data, "Connection #%ld isn't open enough, can't reuse\n",
check->connection_id);
-#ifdef DEBUGBUILD
- if(check->recv_pipe.size > 0) {
- infof(data,
- "BAD! Unconnected #%ld has a non-empty recv pipeline!\n",
- check->connection_id);
- }
-#endif
continue;
}
}
@@ -3647,11 +1180,17 @@ ConnectionExists(struct Curl_easy *data,
}
}
- if(!canpipe && check->inuse)
- /* this request can't be pipelined but the checked connection is
+ if(!canmultiplex && check->data)
+ /* this request can't be multiplexed but the checked connection is
already in use so we skip it */
continue;
+ if(CONN_INUSE(check) && check->data &&
+ (check->data->multi != needle->data->multi))
+ /* this could be subject for multiplex use, but only if they belong to
+ * the same multi handle */
+ continue;
+
if(needle->localdev || needle->localport) {
/* If we are bound to a specific local end (IP+port), we must not
re-use a random other one, although if we didn't ask for a
@@ -3740,7 +1279,7 @@ ConnectionExists(struct Curl_easy *data,
strcmp(needle->passwd, check->passwd))
continue;
}
- else if(check->ntlm.state != NTLMSTATE_NONE) {
+ else if(check->http_ntlm_state != NTLMSTATE_NONE) {
/* Connection is using NTLM auth but we don't want NTLM */
continue;
}
@@ -3756,7 +1295,7 @@ ConnectionExists(struct Curl_easy *data,
strcmp(needle->http_proxy.passwd, check->http_proxy.passwd))
continue;
}
- else if(check->proxyntlm.state != NTLMSTATE_NONE) {
+ else if(check->proxy_ntlm_state != NTLMSTATE_NONE) {
/* Proxy connection is using NTLM auth but we don't want NTLM */
continue;
}
@@ -3766,9 +1305,9 @@ ConnectionExists(struct Curl_easy *data,
chosen = check;
if((wantNTLMhttp &&
- (check->ntlm.state != NTLMSTATE_NONE)) ||
+ (check->http_ntlm_state != NTLMSTATE_NONE)) ||
(wantProxyNTLMhttp &&
- (check->proxyntlm.state != NTLMSTATE_NONE))) {
+ (check->proxy_ntlm_state != NTLMSTATE_NONE))) {
/* We must use this connection, no other */
*force_reuse = TRUE;
break;
@@ -3778,55 +1317,32 @@ ConnectionExists(struct Curl_easy *data,
continue;
}
#endif
- if(canpipe) {
- /* We can pipeline if we want to. Let's continue looking for
- the optimal connection to use, i.e the shortest pipe that is not
- blacklisted. */
+ if(canmultiplex) {
+ /* We can multiplex if we want to. Let's continue looking for
+ the optimal connection to use. */
- if(pipeLen == 0) {
+ if(!multiplexed) {
/* We have the optimal connection. Let's stop looking. */
chosen = check;
break;
}
- /* We can't use the connection if the pipe is full */
- if(max_pipe_len && (pipeLen >= max_pipe_len)) {
- infof(data, "Pipe is full, skip (%zu)\n", pipeLen);
- continue;
- }
#ifdef USE_NGHTTP2
/* If multiplexed, make sure we don't go over concurrency limit */
if(check->bits.multiplex) {
/* Multiplexed connections can only be HTTP/2 for now */
struct http_conn *httpc = &check->proto.httpc;
- if(pipeLen >= httpc->settings.max_concurrent_streams) {
+ if(multiplexed >= httpc->settings.max_concurrent_streams) {
infof(data, "MAX_CONCURRENT_STREAMS reached, skip (%zu)\n",
- pipeLen);
+ multiplexed);
continue;
}
}
#endif
- /* We can't use the connection if the pipe is penalized */
- if(Curl_pipeline_penalized(data, check)) {
- infof(data, "Penalized, skip\n");
- continue;
- }
-
- if(max_pipe_len) {
- if(pipeLen < best_pipe_len) {
- /* This connection has a shorter pipe so far. We'll pick this
- and continue searching */
- chosen = check;
- best_pipe_len = pipeLen;
- continue;
- }
- }
- else {
- /* When not pipelining (== multiplexed), we have a match here! */
- chosen = check;
- infof(data, "Multiplexed connection found!\n");
- break;
- }
+ /* When not multiplexed, we have a match here! */
+ chosen = check;
+ infof(data, "Multiplexed connection found!\n");
+ break;
}
else {
/* We have found a connection. Let's stop searching. */
@@ -3838,9 +1354,13 @@ ConnectionExists(struct Curl_easy *data,
}
if(chosen) {
+ /* mark it as used before releasing the lock */
+ chosen->data = data; /* own it! */
+ Curl_conncache_unlock(data);
*usethis = chosen;
return TRUE; /* yes, we found one to use! */
}
+ Curl_conncache_unlock(data);
if(foundPendingCandidate && data->set.pipewait) {
infof(data,
@@ -3925,7 +1445,11 @@ int Curl_protocol_getsock(struct connectdata *conn,
{
if(conn->handler->proto_getsock)
return conn->handler->proto_getsock(conn, socks, numsocks);
- return GETSOCK_BLANK;
+ /* Backup getsock logic. Since there is a live socket in use, we must wait
+ for it or it will be removed from watching when the multi_socket API is
+ used. */
+ socks[0] = conn->sock[FIRSTSOCKET];
+ return GETSOCK_READSOCK(0) | GETSOCK_WRITESOCK(0);
}
int Curl_doing_getsock(struct connectdata *conn,
@@ -3946,7 +1470,7 @@ int Curl_doing_getsock(struct connectdata *conn,
CURLcode Curl_protocol_connecting(struct connectdata *conn,
bool *done)
{
- CURLcode result=CURLE_OK;
+ CURLcode result = CURLE_OK;
if(conn && conn->handler->connecting) {
*done = FALSE;
@@ -3965,7 +1489,7 @@ CURLcode Curl_protocol_connecting(struct connectdata *conn,
CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done)
{
- CURLcode result=CURLE_OK;
+ CURLcode result = CURLE_OK;
if(conn && conn->handler->doing) {
*done = FALSE;
@@ -3985,7 +1509,7 @@ CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done)
CURLcode Curl_protocol_connect(struct connectdata *conn,
bool *protocol_done)
{
- CURLcode result=CURLE_OK;
+ CURLcode result = CURLE_OK;
*protocol_done = FALSE;
@@ -4013,7 +1537,7 @@ CURLcode Curl_protocol_connect(struct connectdata *conn,
return CURLE_OK;
if(conn->bits.tunnel_proxy && conn->bits.httpproxy &&
- (conn->tunnel_state[FIRSTSOCKET] != TUNNEL_COMPLETE))
+ Curl_connect_ongoing(conn))
/* when using an HTTP tunnel proxy, await complete tunnel establishment
before proceeding further. Return CURLE_OK so we'll be called again */
return CURLE_OK;
@@ -4051,11 +1575,25 @@ static bool is_ASCII_name(const char *hostname)
}
/*
- * Perform any necessary IDN conversion of hostname
+ * Strip single trailing dot in the hostname,
+ * primarily for SNI and http host header.
*/
-static void fix_hostname(struct connectdata *conn, struct hostname *host)
+static void strip_trailing_dot(struct hostname *host)
{
size_t len;
+ if(!host || !host->name)
+ return;
+ len = strlen(host->name);
+ if(len && (host->name[len-1] == '.'))
+ host->name[len-1] = 0;
+}
+
+/*
+ * Perform any necessary IDN conversion of hostname
+ */
+static CURLcode idnconvert_hostname(struct connectdata *conn,
+ struct hostname *host)
+{
struct Curl_easy *data = conn->data;
#ifndef USE_LIBIDN2
@@ -4068,12 +1606,6 @@ static void fix_hostname(struct connectdata *conn, struct hostname *host)
/* set the name we use to display the host name */
host->dispname = host->name;
- len = strlen(host->name);
- if(len && (host->name[len-1] == '.'))
- /* strip off a single trailing dot if present, primarily for SNI but
- there's no use for it */
- host->name[len-1]=0;
-
/* Check name for non-ASCII and convert hostname to ACE form if we can */
if(!is_ASCII_name(host->name)) {
#ifdef USE_LIBIDN2
@@ -4093,9 +1625,11 @@ static void fix_hostname(struct connectdata *conn, struct hostname *host)
/* change the name pointer to point to the encoded hostname */
host->name = host->encalloc;
}
- else
- infof(data, "Failed to convert %s to ACE; %s\n", host->name,
+ else {
+ failf(data, "Failed to convert %s to ACE; %s\n", host->name,
idn2_strerror(rc));
+ return CURLE_URL_MALFORMAT;
+ }
}
#elif defined(USE_WIN32_IDN)
char *ace_hostname = NULL;
@@ -4105,18 +1639,21 @@ static void fix_hostname(struct connectdata *conn, struct hostname *host)
/* change the name pointer to point to the encoded hostname */
host->name = host->encalloc;
}
- else
- infof(data, "Failed to convert %s to ACE;\n", host->name);
+ else {
+ failf(data, "Failed to convert %s to ACE;\n", host->name);
+ return CURLE_URL_MALFORMAT;
+ }
#else
infof(data, "IDN support not present, can't parse Unicode domains\n");
#endif
}
+ return CURLE_OK;
}
/*
- * Frees data allocated by fix_hostname()
+ * Frees data allocated by idnconvert_hostname()
*/
-static void free_fixed_hostname(struct hostname *host)
+static void free_idnconverted_hostname(struct hostname *host)
{
#if defined(USE_LIBIDN2)
if(host->encalloc) {
@@ -4125,7 +1662,7 @@ static void free_fixed_hostname(struct hostname *host)
host->encalloc = NULL;
}
#elif defined(USE_WIN32_IDN)
- free(host->encalloc); /* must be freed withidn_free() since this was
+ free(host->encalloc); /* must be freed with free() since this was
allocated by curl_win32_idn_to_ascii */
host->encalloc = NULL;
#else
@@ -4149,6 +1686,26 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
if(!conn)
return NULL;
+#ifdef USE_SSL
+ /* The SSL backend-specific data (ssl_backend_data) objects are allocated as
+ a separate array to ensure suitable alignment.
+ Note that these backend pointers can be swapped by vtls (eg ssl backend
+ data becomes proxy backend data). */
+ {
+ size_t sslsize = Curl_ssl->sizeof_ssl_backend_data;
+ char *ssl = calloc(4, sslsize);
+ if(!ssl) {
+ free(conn);
+ return NULL;
+ }
+ conn->ssl_extra = ssl;
+ conn->ssl[0].backend = (void *)ssl;
+ conn->ssl[1].backend = (void *)(ssl + sslsize);
+ conn->proxy_ssl[0].backend = (void *)(ssl + 2 * sslsize);
+ conn->proxy_ssl[1].backend = (void *)(ssl + 3 * sslsize);
+ }
+#endif
+
conn->handler = &Curl_handler_dummy; /* Be sure we have a handler defined
already from start to avoid NULL
situations and checks */
@@ -4173,7 +1730,13 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
connclose(conn, "Default to force-close");
/* Store creation time to help future close decision making */
- conn->created = Curl_tvnow();
+ conn->created = Curl_now();
+
+ /* Store current time to give a baseline to keepalive connection times. */
+ conn->keepalive = Curl_now();
+
+ /* Store off the configured connection upkeep time. */
+ conn->upkeep_interval_ms = data->set.upkeep_interval_ms;
conn->data = data; /* Setup the association between this connection
and the Curl_easy */
@@ -4181,16 +1744,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
conn->http_proxy.proxytype = data->set.proxytype;
conn->socks_proxy.proxytype = CURLPROXY_SOCKS4;
-#ifdef CURL_DISABLE_PROXY
-
- conn->bits.proxy = FALSE;
- conn->bits.httpproxy = FALSE;
- conn->bits.socksproxy = FALSE;
- conn->bits.proxy_user_passwd = FALSE;
- conn->bits.tunnel_proxy = FALSE;
-
-#else /* CURL_DISABLE_PROXY */
-
+#if !defined(CURL_DISABLE_PROXY)
/* note that these two proxy bits are now just on what looks to be
requested, they may be altered down the road */
conn->bits.proxy = (data->set.str[STRING_PROXY] &&
@@ -4211,13 +1765,13 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
conn->bits.proxy_user_passwd =
(data->set.str[STRING_PROXYUSERNAME]) ? TRUE : FALSE;
conn->bits.tunnel_proxy = data->set.tunnel_thru_httpproxy;
-
#endif /* CURL_DISABLE_PROXY */
conn->bits.user_passwd = (data->set.str[STRING_USERNAME]) ? TRUE : FALSE;
+#ifndef CURL_DISABLE_FTP
conn->bits.ftp_use_epsv = data->set.ftp_use_epsv;
conn->bits.ftp_use_eprt = data->set.ftp_use_eprt;
-
+#endif
conn->ssl_config.verifystatus = data->set.ssl.primary.verifystatus;
conn->ssl_config.verifypeer = data->set.ssl.primary.verifypeer;
conn->ssl_config.verifyhost = data->set.ssl.primary.verifyhost;
@@ -4225,28 +1779,16 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
data->set.proxy_ssl.primary.verifystatus;
conn->proxy_ssl_config.verifypeer = data->set.proxy_ssl.primary.verifypeer;
conn->proxy_ssl_config.verifyhost = data->set.proxy_ssl.primary.verifyhost;
-
conn->ip_version = data->set.ipver;
+ conn->bits.connect_only = data->set.connect_only;
#if !defined(CURL_DISABLE_HTTP) && defined(USE_NTLM) && \
defined(NTLM_WB_ENABLED)
conn->ntlm_auth_hlpr_socket = CURL_SOCKET_BAD;
- conn->ntlm_auth_hlpr_pid = 0;
- conn->challenge_header = NULL;
- conn->response_header = NULL;
#endif
- if(Curl_pipeline_wanted(data->multi, CURLPIPE_HTTP1) &&
- !conn->master_buffer) {
- /* Allocate master_buffer to be used for HTTP/1 pipelining */
- conn->master_buffer = calloc(MASTERBUF_SIZE, sizeof(char));
- if(!conn->master_buffer)
- goto error;
- }
-
- /* Initialize the pipeline lists */
- Curl_llist_init(&conn->send_pipe, (curl_llist_dtor) llist_dtor);
- Curl_llist_init(&conn->recv_pipe, (curl_llist_dtor) llist_dtor);
+ /* Initialize the easy handle list */
+ Curl_llist_init(&conn->easyq, (curl_llist_dtor) llist_dtor);
#ifdef HAVE_GSSAPI
conn->data_prot = PROT_CLEAR;
@@ -4269,39 +1811,46 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
return conn;
error:
- Curl_llist_destroy(&conn->send_pipe, NULL);
- Curl_llist_destroy(&conn->recv_pipe, NULL);
-
- free(conn->master_buffer);
+ Curl_llist_destroy(&conn->easyq, NULL);
free(conn->localdev);
+#ifdef USE_SSL
+ free(conn->ssl_extra);
+#endif
free(conn);
return NULL;
}
-static CURLcode findprotocol(struct Curl_easy *data,
- struct connectdata *conn,
- const char *protostr)
+/* returns the handler if the given scheme is built-in */
+const struct Curl_handler *Curl_builtin_scheme(const char *scheme)
{
const struct Curl_handler * const *pp;
const struct Curl_handler *p;
-
- /* Scan protocol handler table and match against 'protostr' to set a few
- variables based on the URL. Now that the handler may be changed later
- when the protocol specific setup function is called. */
- for(pp = protocols; (p = *pp) != NULL; pp++) {
- if(strcasecompare(p->scheme, protostr)) {
+ /* Scan protocol handler table and match against 'scheme'. The handler may
+ be changed later when the protocol specific setup function is called. */
+ for(pp = protocols; (p = *pp) != NULL; pp++)
+ if(strcasecompare(p->scheme, scheme))
/* Protocol found in table. Check if allowed */
- if(!(data->set.allowed_protocols & p->protocol))
- /* nope, get out */
- break;
+ return p;
+ return NULL; /* not found */
+}
- /* it is allowed for "normal" request, now do an extra check if this is
- the result of a redirect */
- if(data->state.this_is_a_follow &&
- !(data->set.redir_protocols & p->protocol))
- /* nope, get out */
- break;
+static CURLcode findprotocol(struct Curl_easy *data,
+ struct connectdata *conn,
+ const char *protostr)
+{
+ const struct Curl_handler *p = Curl_builtin_scheme(protostr);
+
+ if(p && /* Protocol found in table. Check if allowed */
+ (data->set.allowed_protocols & p->protocol)) {
+
+ /* it is allowed for "normal" request, now do an extra check if this is
+ the result of a redirect */
+ if(data->state.this_is_a_follow &&
+ !(data->set.redir_protocols & p->protocol))
+ /* nope, get out */
+ ;
+ else {
/* Perform setup complement if some. */
conn->handler = conn->given = p;
@@ -4310,7 +1859,6 @@ static CURLcode findprotocol(struct Curl_easy *data,
}
}
-
/* The protocol was not found in the table, but we don't have to assign it
to anything since it is already assigned to a dummy-struct in the
create_conn() function when the connectdata struct is allocated. */
@@ -4320,454 +1868,190 @@ static CURLcode findprotocol(struct Curl_easy *data,
return CURLE_UNSUPPORTED_PROTOCOL;
}
+
+CURLcode Curl_uc_to_curlcode(CURLUcode uc)
+{
+ switch(uc) {
+ default:
+ return CURLE_URL_MALFORMAT;
+ case CURLUE_UNSUPPORTED_SCHEME:
+ return CURLE_UNSUPPORTED_PROTOCOL;
+ case CURLUE_OUT_OF_MEMORY:
+ return CURLE_OUT_OF_MEMORY;
+ case CURLUE_USER_NOT_ALLOWED:
+ return CURLE_LOGIN_DENIED;
+ }
+}
+
/*
* Parse URL and fill in the relevant members of the connection struct.
*/
static CURLcode parseurlandfillconn(struct Curl_easy *data,
- struct connectdata *conn,
- bool *prot_missing,
- char **userp, char **passwdp,
- char **optionsp)
+ struct connectdata *conn)
{
- char *at;
- char *fragment;
- char *path = data->state.path;
- char *query;
- int i;
- int rc;
- const char *protop = "";
CURLcode result;
- bool rebuild_url = FALSE;
- bool url_has_scheme = FALSE;
- char protobuf[16];
-
- *prot_missing = FALSE;
+ CURLU *uh;
+ CURLUcode uc;
+ char *hostname;
- /* We might pass the entire URL into the request so we need to make sure
- * there are no bad characters in there.*/
- if(strpbrk(data->change.url, "\r\n")) {
- failf(data, "Illegal characters found in URL");
- return CURLE_URL_MALFORMAT;
- }
+ up_free(data); /* cleanup previous leftovers first */
- /*************************************************************
- * 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(data->change.url[0] == ':') {
- failf(data, "Bad URL, colon is first character");
- return CURLE_URL_MALFORMAT;
+ /* parse the URL */
+ if(data->set.uh) {
+ uh = data->state.uh = curl_url_dup(data->set.uh);
}
-
- /* Make sure we don't mistake a drive letter for a scheme, for example:
- curld --proto-default file c:/foo/bar.txt */
- if((('a' <= data->change.url[0] && data->change.url[0] <= 'z') ||
- ('A' <= data->change.url[0] && data->change.url[0] <= 'Z')) &&
- data->change.url[1] == ':' && data->set.str[STRING_DEFAULT_PROTOCOL] &&
- strcasecompare(data->set.str[STRING_DEFAULT_PROTOCOL], "file")) {
- ; /* do nothing */
- }
- else { /* check for a scheme */
- for(i = 0; i < 16 && data->change.url[i]; ++i) {
- if(data->change.url[i] == '/')
- break;
- if(data->change.url[i] == ':') {
- url_has_scheme = TRUE;
- break;
- }
- }
+ else {
+ uh = data->state.uh = curl_url();
}
- /* handle the file: scheme */
- if((url_has_scheme && strncasecompare(data->change.url, "file:", 5)) ||
- (!url_has_scheme && data->set.str[STRING_DEFAULT_PROTOCOL] &&
- strcasecompare(data->set.str[STRING_DEFAULT_PROTOCOL], "file"))) {
- bool path_has_drive = FALSE;
-
- if(url_has_scheme)
- rc = sscanf(data->change.url, "%*15[^\n/:]:%[^\n]", path);
- else
- rc = sscanf(data->change.url, "%[^\n]", path);
-
- if(rc != 1) {
- failf(data, "Bad URL");
- return CURLE_URL_MALFORMAT;
- }
-
- if(url_has_scheme && 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);
- }
-
- /* the path may start with a drive letter. for backwards compatibility
- we skip some processing on those paths. */
- path_has_drive = (('a' <= path[0] && path[0] <= 'z') ||
- ('A' <= path[0] && path[0] <= 'Z')) && path[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] != '/' && !path_has_drive) {
- /* the URL includes a host name, it must match "localhost" or
- "127.0.0.1" to be valid */
- char *ptr;
- if(!checkprefix("localhost/", path) &&
- !checkprefix("127.0.0.1/", path)) {
- failf(data, "Invalid file://hostname/, "
- "expected localhost or 127.0.0.1 or none");
- return CURLE_URL_MALFORMAT;
- }
- ptr = &path[9]; /* now points to the slash after the host */
-
- /* there was a host name and 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])
- /* 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);
-
- path_has_drive = (('a' <= path[0] && path[0] <= 'z') ||
- ('A' <= path[0] && path[0] <= 'Z')) && path[1] == ':';
- }
+ if(!uh)
+ return CURLE_OUT_OF_MEMORY;
-#if !defined(MSDOS) && !defined(WIN32) && !defined(__CYGWIN__)
- if(path_has_drive) {
- failf(data, "File drive letters are only accepted in MSDOS/Windows.");
- return CURLE_URL_MALFORMAT;
+ if(data->set.str[STRING_DEFAULT_PROTOCOL] &&
+ !Curl_is_absolute_url(data->change.url, NULL, MAX_SCHEME_LEN)) {
+ char *url;
+ if(data->change.url_alloc)
+ free(data->change.url);
+ url = aprintf("%s://%s", data->set.str[STRING_DEFAULT_PROTOCOL],
+ data->change.url);
+ if(!url)
+ return CURLE_OUT_OF_MEMORY;
+ data->change.url = url;
+ data->change.url_alloc = TRUE;
+ }
+
+ if(!data->set.uh) {
+ uc = curl_url_set(uh, CURLUPART_URL, data->change.url,
+ CURLU_GUESS_SCHEME |
+ CURLU_NON_SUPPORT_SCHEME |
+ (data->set.disallow_username_in_url ?
+ CURLU_DISALLOW_USER : 0) |
+ (data->set.path_as_is ? CURLU_PATH_AS_IS : 0));
+ if(uc) {
+ DEBUGF(infof(data, "curl_url_set rejected %s\n", data->change.url));
+ return Curl_uc_to_curlcode(uc);
}
-#endif
-
- protop = "file"; /* protocol string */
- *prot_missing = !url_has_scheme;
}
- else {
- /* clear path */
- char slashbuf[4];
- path[0]=0;
-
- rc = sscanf(data->change.url,
- "%15[^\n/:]:%3[/]%[^\n/?#]%[^\n]",
- protobuf, slashbuf, conn->host.name, path);
- if(2 == rc) {
- failf(data, "Bad URL");
- return CURLE_URL_MALFORMAT;
- }
- if(3 > rc) {
-
- /*
- * The URL was badly formatted, let's try the browser-style _without_
- * protocol specified like 'http://'.
- */
- rc = sscanf(data->change.url, "%[^\n/?#]%[^\n]", conn->host.name, path);
- if(1 > rc) {
- /*
- * We couldn't even get this format.
- * djgpp 2.04 has a sscanf() bug where 'conn->host.name' is
- * assigned, but the return value is EOF!
- */
-#if defined(__DJGPP__) && (DJGPP_MINOR == 4)
- if(!(rc == -1 && *conn->host.name))
-#endif
- {
- failf(data, "<url> malformed");
- return CURLE_URL_MALFORMAT;
- }
- }
- /*
- * Since there was no protocol part specified in the URL use the
- * user-specified default protocol. If we weren't given a default make a
- * guess by matching some protocols against the host's outermost
- * sub-domain name. Finally if there was no match use HTTP.
- */
+ uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0);
+ if(uc)
+ return Curl_uc_to_curlcode(uc);
- protop = data->set.str[STRING_DEFAULT_PROTOCOL];
- if(!protop) {
- /* Note: if you add a new protocol, please update the list in
- * lib/version.c too! */
- if(checkprefix("FTP.", conn->host.name))
- protop = "ftp";
- else if(checkprefix("DICT.", conn->host.name))
- protop = "DICT";
- else if(checkprefix("LDAP.", conn->host.name))
- protop = "LDAP";
- else if(checkprefix("IMAP.", conn->host.name))
- protop = "IMAP";
- else if(checkprefix("SMTP.", conn->host.name))
- protop = "smtp";
- else if(checkprefix("POP3.", conn->host.name))
- protop = "pop3";
- else
- protop = "http";
- }
+ result = findprotocol(data, conn, data->state.up.scheme);
+ if(result)
+ return result;
- *prot_missing = TRUE; /* not given in URL */
- }
- else {
- size_t s = strlen(slashbuf);
- protop = protobuf;
- if(s != 2) {
- infof(data, "Unwillingly accepted illegal URL using %d slash%s!\n",
- s, s>1?"es":"");
-
- if(data->change.url_alloc)
- free(data->change.url);
- /* repair the URL to use two slashes */
- data->change.url = aprintf("%s://%s%s",
- protobuf, conn->host.name, path);
- if(!data->change.url)
- return CURLE_OUT_OF_MEMORY;
- data->change.url_alloc = TRUE;
- }
- }
+ uc = curl_url_get(uh, CURLUPART_USER, &data->state.up.user,
+ CURLU_URLDECODE);
+ if(!uc) {
+ conn->user = strdup(data->state.up.user);
+ if(!conn->user)
+ return CURLE_OUT_OF_MEMORY;
+ conn->bits.user_passwd = TRUE;
}
+ else if(uc != CURLUE_NO_USER)
+ return Curl_uc_to_curlcode(uc);
- /* 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)
- query = strchr(at+1, '?');
- else
- query = strchr(conn->host.name, '?');
-
- if(query) {
- /* 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(query);
- 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, query, hostlen);
-
- path[0]='/'; /* prepend the missing slash */
- rebuild_url = TRUE;
-
- *query=0; /* now cut off the hostname at the ? */
- }
- else if(!path[0]) {
- /* if there's no path set, use a single slash */
- strcpy(path, "/");
- rebuild_url = TRUE;
+ uc = curl_url_get(uh, CURLUPART_PASSWORD, &data->state.up.password,
+ CURLU_URLDECODE);
+ if(!uc) {
+ conn->passwd = strdup(data->state.up.password);
+ if(!conn->passwd)
+ return CURLE_OUT_OF_MEMORY;
+ conn->bits.user_passwd = TRUE;
}
+ else if(uc != CURLUE_NO_PASSWORD)
+ return Curl_uc_to_curlcode(uc);
- /* If the URL is malformatted (missing a '/' after hostname before path) we
- * insert a slash here. The only letters except '/' that can start a path is
- * '?' and '#' - as controlled by the two sscanf() patterns above.
- */
- 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] = '/';
- rebuild_url = TRUE;
- }
- else if(!data->set.path_as_is) {
- /* sanitise paths and remove ../ and ./ sequences according to RFC3986 */
- char *newp = Curl_dedotdotify(path);
- if(!newp)
+ uc = curl_url_get(uh, CURLUPART_OPTIONS, &data->state.up.options,
+ CURLU_URLDECODE);
+ if(!uc) {
+ conn->options = strdup(data->state.up.options);
+ if(!conn->options)
return CURLE_OUT_OF_MEMORY;
-
- if(strcmp(newp, path)) {
- rebuild_url = TRUE;
- free(data->state.pathbuffer);
- data->state.pathbuffer = newp;
- data->state.path = newp;
- path = newp;
- }
- else
- free(newp);
}
+ else if(uc != CURLUE_NO_OPTIONS)
+ return Curl_uc_to_curlcode(uc);
- /*
- * "rebuild_url" means that one or more URL components have been modified so
- * we need to generate an updated full version. We need the corrected URL
- * when communicating over HTTP proxy and we don't know at this point if
- * we're using a proxy or not.
- */
- if(rebuild_url) {
- char *reurl;
-
- size_t plen = strlen(path); /* new path, should be 1 byte longer than
- the original */
- size_t prefixlen = strlen(conn->host.name);
-
- if(!*prot_missing) {
- size_t protolen = strlen(protop);
-
- if(curl_strnequal(protop, data->change.url, protolen))
- prefixlen += protolen;
- else {
- failf(data, "<url> malformed");
- return CURLE_URL_MALFORMAT;
- }
-
- if(curl_strnequal("://", &data->change.url[protolen], 3))
- prefixlen += 3;
- /* only file: is allowed to omit one or both slashes */
- else if(curl_strnequal("file:", data->change.url, 5))
- prefixlen += 1 + (data->change.url[5] == '/');
- else {
- failf(data, "<url> malformed");
- return CURLE_URL_MALFORMAT;
- }
- }
-
- reurl = malloc(prefixlen + plen + 1);
- if(!reurl)
+ uc = curl_url_get(uh, CURLUPART_HOST, &data->state.up.hostname, 0);
+ if(uc) {
+ if(!strcasecompare("file", data->state.up.scheme))
return CURLE_OUT_OF_MEMORY;
+ }
- /* copy the prefix */
- memcpy(reurl, data->change.url, prefixlen);
-
- /* append the trailing piece + zerobyte */
- memcpy(&reurl[prefixlen], path, plen + 1);
-
- /* possible free the old one */
- if(data->change.url_alloc) {
- Curl_safefree(data->change.url);
- data->change.url_alloc = FALSE;
- }
-
- infof(data, "Rebuilt URL to: %s\n", reurl);
+ uc = curl_url_get(uh, CURLUPART_PATH, &data->state.up.path, 0);
+ if(uc)
+ return Curl_uc_to_curlcode(uc);
- data->change.url = reurl;
- data->change.url_alloc = TRUE; /* free this later */
+ uc = curl_url_get(uh, CURLUPART_PORT, &data->state.up.port,
+ CURLU_DEFAULT_PORT);
+ if(uc) {
+ if(!strcasecompare("file", data->state.up.scheme))
+ return CURLE_OUT_OF_MEMORY;
+ }
+ else {
+ unsigned long port = strtoul(data->state.up.port, NULL, 10);
+ conn->remote_port = curlx_ultous(port);
}
- result = findprotocol(data, conn, protop);
- if(result)
- return result;
+ (void)curl_url_get(uh, CURLUPART_QUERY, &data->state.up.query, 0);
- /*
- * Parse the login details from the URL and strip them out of
- * the host name
- */
- result = parse_url_login(data, conn, userp, passwdp, optionsp);
- if(result)
- return result;
+ hostname = data->state.up.hostname;
+ if(!hostname)
+ /* this is for file:// transfers, get a dummy made */
+ hostname = (char *)"";
- if(conn->host.name[0] == '[') {
- /* This looks like an IPv6 address literal. See if there is an address
- scope if there is no location header */
- char *percent = strchr(conn->host.name, '%');
- if(percent) {
- unsigned int identifier_offset = 3;
+ if(hostname[0] == '[') {
+ /* This looks like an IPv6 address literal. See if there is an address
+ scope. */
+ char *zoneid;
+ size_t hlen;
+ uc = curl_url_get(uh, CURLUPART_ZONEID, &zoneid, 0);
+ conn->bits.ipv6_ip = TRUE;
+
+ /* cut off the brackets! */
+ hostname++;
+ hlen = strlen(hostname);
+ hostname[hlen - 1] = 0;
+ if(!uc && zoneid) {
char *endp;
unsigned long scope;
- if(strncmp("%25", percent, 3) != 0) {
- infof(data,
- "Please URL encode %% as %%25, see RFC 6874.\n");
- identifier_offset = 1;
- }
- scope = strtoul(percent + identifier_offset, &endp, 10);
- if(*endp == ']') {
- /* The address scope was well formed. Knock it out of the
- hostname. */
- memmove(percent, endp, strlen(endp)+1);
+ scope = strtoul(zoneid, &endp, 10);
+ if(!*endp && (scope < UINT_MAX)) {
+ /* A plain number, use it direcly as a scope id. */
conn->scope_id = (unsigned int)scope;
}
+#ifdef HAVE_IF_NAMETOINDEX
else {
/* Zone identifier is not numeric */
-#if defined(HAVE_NET_IF_H) && defined(IFNAMSIZ) && defined(HAVE_IF_NAMETOINDEX)
- char ifname[IFNAMSIZ + 2];
- char *square_bracket;
unsigned int scopeidx = 0;
- strncpy(ifname, percent + identifier_offset, IFNAMSIZ + 2);
- /* Ensure nullbyte termination */
- ifname[IFNAMSIZ + 1] = '\0';
- square_bracket = strchr(ifname, ']');
- if(square_bracket) {
- /* Remove ']' */
- *square_bracket = '\0';
- scopeidx = if_nametoindex(ifname);
- if(scopeidx == 0) {
- infof(data, "Invalid network interface: %s; %s\n", ifname,
- strerror(errno));
- }
- }
- if(scopeidx > 0) {
- char *p = percent + identifier_offset + strlen(ifname);
-
- /* Remove zone identifier from hostname */
- memmove(percent, p, strlen(p) + 1);
- conn->scope_id = scopeidx;
- }
+ scopeidx = if_nametoindex(zoneid);
+ if(!scopeidx)
+ infof(data, "Invalid zoneid id: %s; %s\n", zoneid,
+ strerror(errno));
else
-#endif /* HAVE_NET_IF_H && IFNAMSIZ */
- infof(data, "Invalid IPv6 address format\n");
+ conn->scope_id = scopeidx;
+
}
+#endif /* HAVE_IF_NAMETOINDEX */
+ free(zoneid);
}
}
+ /* make sure the connect struct gets its own copy of the host name */
+ conn->host.rawalloc = strdup(hostname);
+ if(!conn->host.rawalloc)
+ return CURLE_OUT_OF_MEMORY;
+ conn->host.name = conn->host.rawalloc;
+
if(data->set.scope_id)
/* Override any scope that was set above. */
conn->scope_id = data->set.scope_id;
- /* Remove the fragment part of the path. Per RFC 2396, this is always the
- last part of the URI. We are looking for the first '#' so that we deal
- gracefully with non conformant URI such as http://example.com#foo#bar. */
- fragment = strchr(path, '#');
- if(fragment) {
- *fragment = 0;
-
- /* we know the path part ended with a fragment, so we know the full URL
- string does too and we need to cut it off from there so it isn't used
- over proxy */
- fragment = strchr(data->change.url, '#');
- if(fragment)
- *fragment = 0;
- }
-
- /*
- * So if the URL was A://B/C#D,
- * protop is A
- * conn->host.name is B
- * data->state.path is /C
- */
return CURLE_OK;
}
+
/*
* If we're doing a resumed transfer, we need to setup our stuff
* properly.
@@ -4781,7 +2065,7 @@ static CURLcode setup_range(struct Curl_easy *data)
free(s->range);
if(s->resume_from)
- s->range = aprintf("%" CURL_FORMAT_CURL_OFF_TU "-", s->resume_from);
+ s->range = aprintf("%" CURL_FORMAT_CURL_OFF_T "-", s->resume_from);
else
s->range = strdup(data->set.str[STRING_SET_RANGE]);
@@ -4813,18 +2097,6 @@ static CURLcode setup_connection_internals(struct connectdata *conn)
{
const struct Curl_handler * p;
CURLcode result;
- struct Curl_easy *data = conn->data;
-
- /* in some case in the multi state-machine, we go back to the CONNECT state
- and then a second (or third or...) call to this function will be made
- without doing a DISCONNECT or DONE in between (since the connection is
- yet in place) and therefore this function needs to first make sure
- there's no lingering previous data allocated. */
- Curl_free_request_state(data);
-
- memset(&data->req, 0, sizeof(struct SingleRequest));
- data->req.maxdownload = -1;
-
conn->socktype = SOCK_STREAM; /* most of them are TCP streams */
/* Perform setup complement if some. */
@@ -4871,14 +2143,13 @@ static bool check_noproxy(const char *name, const char *no_proxy)
* not be proxied, or an asterisk to override
* all proxy variables)
*/
- size_t tok_start;
- size_t tok_end;
- const char *separator = ", ";
- size_t no_proxy_len;
- size_t namelen;
- char *endptr;
-
if(no_proxy && no_proxy[0]) {
+ size_t tok_start;
+ size_t tok_end;
+ const char *separator = ", ";
+ size_t no_proxy_len;
+ size_t namelen;
+ char *endptr;
if(strcasecompare("*", no_proxy)) {
return TRUE;
}
@@ -4886,9 +2157,14 @@ static bool check_noproxy(const char *name, const char *no_proxy)
/* NO_PROXY was specified and it wasn't just an asterisk */
no_proxy_len = strlen(no_proxy);
- endptr = strchr(name, ':');
- if(endptr)
+ if(name[0] == '[') {
+ /* IPv6 numerical address */
+ endptr = strchr(name, ']');
+ if(!endptr)
+ return FALSE;
+ name++;
namelen = endptr - name;
+ }
else
namelen = strlen(name);
@@ -4974,7 +2250,7 @@ static char *detect_proxy(struct connectdata *conn)
strcpy(envp, "_proxy");
/* read the protocol proxy: */
- prox=curl_getenv(proxy_env);
+ prox = curl_getenv(proxy_env);
/*
* We don't try the uppercase version of HTTP_PROXY because of
@@ -4991,16 +2267,23 @@ static char *detect_proxy(struct connectdata *conn)
if(!prox && !strcasecompare("http_proxy", proxy_env)) {
/* There was no lowercase variable, try the uppercase version: */
Curl_strntoupper(proxy_env, proxy_env, sizeof(proxy_env));
- prox=curl_getenv(proxy_env);
+ prox = curl_getenv(proxy_env);
}
- if(prox)
+ envp = proxy_env;
+ if(prox) {
proxy = prox; /* use this */
+ }
else {
- proxy = curl_getenv("all_proxy"); /* default proxy to use */
- if(!proxy)
- proxy=curl_getenv("ALL_PROXY");
+ envp = (char *)"all_proxy";
+ proxy = curl_getenv(envp); /* default proxy to use */
+ if(!proxy) {
+ envp = (char *)"ALL_PROXY";
+ proxy = curl_getenv(envp);
+ }
}
+ if(proxy)
+ infof(conn->data, "Uses proxy env variable %s == '%s'\n", envp, proxy);
return proxy;
}
@@ -5015,136 +2298,100 @@ static CURLcode parse_proxy(struct Curl_easy *data,
struct connectdata *conn, char *proxy,
curl_proxytype proxytype)
{
- char *prox_portno;
- char *endofprot;
-
- /* We use 'proxyptr' to point to the proxy name from now on... */
- char *proxyptr;
char *portptr;
- char *atsign;
long port = -1;
char *proxyuser = NULL;
char *proxypasswd = NULL;
+ char *host;
bool sockstype;
+ CURLUcode uc;
+ struct proxy_info *proxyinfo;
+ CURLU *uhp = curl_url();
+ CURLcode result = CURLE_OK;
+ char *scheme = NULL;
+
+ /* When parsing the proxy, allowing non-supported schemes since we have
+ these made up ones for proxies. Guess scheme for URLs without it. */
+ uc = curl_url_set(uhp, CURLUPART_URL, proxy,
+ CURLU_NON_SUPPORT_SCHEME|CURLU_GUESS_SCHEME);
+ if(!uc) {
+ /* parsed okay as a URL */
+ uc = curl_url_get(uhp, CURLUPART_SCHEME, &scheme, 0);
+ if(uc) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto error;
+ }
- /* We do the proxy host string parsing here. We want the host name and the
- * port name. Accept a protocol:// prefix
- */
-
- /* Parse the protocol part if present */
- endofprot = strstr(proxy, "://");
- if(endofprot) {
- proxyptr = endofprot+3;
- if(checkprefix("https", proxy))
+ if(strcasecompare("https", scheme))
proxytype = CURLPROXY_HTTPS;
- else if(checkprefix("socks5h", proxy))
+ else if(strcasecompare("socks5h", scheme))
proxytype = CURLPROXY_SOCKS5_HOSTNAME;
- else if(checkprefix("socks5", proxy))
+ else if(strcasecompare("socks5", scheme))
proxytype = CURLPROXY_SOCKS5;
- else if(checkprefix("socks4a", proxy))
+ else if(strcasecompare("socks4a", scheme))
proxytype = CURLPROXY_SOCKS4A;
- else if(checkprefix("socks4", proxy) || checkprefix("socks", proxy))
+ else if(strcasecompare("socks4", scheme) ||
+ strcasecompare("socks", scheme))
proxytype = CURLPROXY_SOCKS4;
- else if(checkprefix("http:", proxy))
+ else if(strcasecompare("http", scheme))
; /* leave it as HTTP or HTTP/1.0 */
else {
/* Any other xxx:// reject! */
failf(data, "Unsupported proxy scheme for \'%s\'", proxy);
- return CURLE_COULDNT_CONNECT;
+ result = CURLE_COULDNT_CONNECT;
+ goto error;
}
}
- else
- proxyptr = proxy; /* No xxx:// head: It's a HTTP proxy */
-
-#ifndef HTTPS_PROXY_SUPPORT
- if(proxytype == CURLPROXY_HTTPS) {
- failf(data, "Unsupported proxy \'%s\'"
- ", libcurl is built without the HTTPS-proxy support.", proxy);
- return CURLE_NOT_BUILT_IN;
+ else {
+ failf(data, "Unsupported proxy syntax in \'%s\'", proxy);
+ result = CURLE_COULDNT_RESOLVE_PROXY;
+ goto error;
}
-#endif
- sockstype = proxytype == CURLPROXY_SOCKS5_HOSTNAME ||
- proxytype == CURLPROXY_SOCKS5 ||
- proxytype == CURLPROXY_SOCKS4A ||
- proxytype == CURLPROXY_SOCKS4;
+#ifdef USE_SSL
+ if(!(Curl_ssl->supports & SSLSUPP_HTTPS_PROXY))
+#endif
+ if(proxytype == CURLPROXY_HTTPS) {
+ failf(data, "Unsupported proxy \'%s\', libcurl is built without the "
+ "HTTPS-proxy support.", proxy);
+ result = CURLE_NOT_BUILT_IN;
+ goto error;
+ }
- /* Is there a username and password given in this proxy url? */
- atsign = strchr(proxyptr, '@');
- if(atsign) {
- CURLcode result =
- parse_login_details(proxyptr, atsign - proxyptr,
- &proxyuser, &proxypasswd, NULL);
- if(result)
- return result;
- proxyptr = atsign + 1;
- }
+ sockstype =
+ proxytype == CURLPROXY_SOCKS5_HOSTNAME ||
+ proxytype == CURLPROXY_SOCKS5 ||
+ proxytype == CURLPROXY_SOCKS4A ||
+ proxytype == CURLPROXY_SOCKS4;
- /* start scanning for port number at this point */
- portptr = proxyptr;
+ proxyinfo = sockstype ? &conn->socks_proxy : &conn->http_proxy;
+ proxyinfo->proxytype = proxytype;
- /* detect and extract RFC6874-style IPv6-addresses */
- if(*proxyptr == '[') {
- char *ptr = ++proxyptr; /* advance beyond the initial bracket */
- while(*ptr && (ISXDIGIT(*ptr) || (*ptr == ':') || (*ptr == '.')))
- ptr++;
- if(*ptr == '%') {
- /* There might be a zone identifier */
- if(strncmp("%25", ptr, 3))
- infof(data, "Please URL encode %% as %%25, see RFC 6874.\n");
- ptr++;
- /* Allow unreserved characters as defined in RFC 3986 */
- while(*ptr && (ISALPHA(*ptr) || ISXDIGIT(*ptr) || (*ptr == '-') ||
- (*ptr == '.') || (*ptr == '_') || (*ptr == '~')))
- ptr++;
+ /* Is there a username and password given in this proxy url? */
+ curl_url_get(uhp, CURLUPART_USER, &proxyuser, CURLU_URLDECODE);
+ curl_url_get(uhp, CURLUPART_PASSWORD, &proxypasswd, CURLU_URLDECODE);
+ if(proxyuser || proxypasswd) {
+ Curl_safefree(proxyinfo->user);
+ proxyinfo->user = proxyuser;
+ Curl_safefree(proxyinfo->passwd);
+ if(!proxypasswd) {
+ proxypasswd = strdup("");
+ if(!proxypasswd) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto error;
+ }
}
- if(*ptr == ']')
- /* yeps, it ended nicely with a bracket as well */
- *ptr++ = 0;
- else
- infof(data, "Invalid IPv6 address format\n");
- portptr = ptr;
- /* 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.
- */
+ proxyinfo->passwd = proxypasswd;
+ conn->bits.proxy_user_passwd = TRUE; /* enable it */
}
- /* Get port number off proxy.server.com:1080 */
- prox_portno = strchr(portptr, ':');
- if(prox_portno) {
- char *endp = NULL;
+ curl_url_get(uhp, CURLUPART_PORT, &portptr, 0);
- *prox_portno = 0x0; /* cut off number from host name */
- prox_portno ++;
- /* now set the local port number */
- port = strtol(prox_portno, &endp, 10);
- if((endp && *endp && (*endp != '/') && (*endp != ' ')) ||
- (port < 0) || (port > 65535)) {
- /* meant to detect for example invalid IPv6 numerical addresses without
- brackets: "2a00:fac0:a000::7:13". Accept a trailing slash only
- because we then allow "URL style" with the number followed by a
- slash, used in curl test cases already. Space is also an acceptable
- terminating symbol. */
- infof(data, "No valid port number in proxy string (%s)\n",
- prox_portno);
- }
- else
- conn->port = port;
+ if(portptr) {
+ port = strtol(portptr, NULL, 10);
+ free(portptr);
}
else {
- if(proxyptr[0]=='/')
- /* If the first character in the proxy string is a slash, fail
- immediately. The following code will otherwise clear the string which
- will lead to code running as if no proxy was set! */
- return CURLE_COULDNT_RESOLVE_PROXY;
-
- /* without a port number after the host name, some people seem to use
- a slash so we strip everything from the first slash */
- atsign = strchr(proxyptr, '/');
- if(atsign)
- *atsign = '\0'; /* cut off path part from host name */
-
if(data->set.proxyport)
/* None given in the proxy string, then get the default one if it is
given */
@@ -5156,57 +2403,32 @@ static CURLcode parse_proxy(struct Curl_easy *data,
port = CURL_DEFAULT_PROXY_PORT;
}
}
-
- if(*proxyptr) {
- struct proxy_info *proxyinfo =
- sockstype ? &conn->socks_proxy : &conn->http_proxy;
- proxyinfo->proxytype = proxytype;
-
- if(proxyuser) {
- /* 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(proxyinfo->user);
- proxyinfo->user = curl_easy_unescape(data, proxyuser, 0, NULL);
- Curl_safefree(proxyuser);
-
- if(!proxyinfo->user) {
- Curl_safefree(proxypasswd);
- return CURLE_OUT_OF_MEMORY;
- }
-
- Curl_safefree(proxyinfo->passwd);
- if(proxypasswd && strlen(proxypasswd) < MAX_CURL_PASSWORD_LENGTH)
- proxyinfo->passwd = curl_easy_unescape(data, proxypasswd, 0, NULL);
- else
- proxyinfo->passwd = strdup("");
- Curl_safefree(proxypasswd);
-
- if(!proxyinfo->passwd)
- return CURLE_OUT_OF_MEMORY;
-
- conn->bits.proxy_user_passwd = TRUE; /* enable it */
- }
-
- if(port >= 0) {
- proxyinfo->port = port;
- if(conn->port < 0 || sockstype || !conn->socks_proxy.host.rawalloc)
- conn->port = port;
- }
-
- /* now, clone the cleaned proxy host name */
- Curl_safefree(proxyinfo->host.rawalloc);
- proxyinfo->host.rawalloc = strdup(proxyptr);
- proxyinfo->host.name = proxyinfo->host.rawalloc;
-
- if(!proxyinfo->host.rawalloc)
- return CURLE_OUT_OF_MEMORY;
+ if(port >= 0) {
+ proxyinfo->port = port;
+ if(conn->port < 0 || sockstype || !conn->socks_proxy.host.rawalloc)
+ conn->port = port;
}
- Curl_safefree(proxyuser);
- Curl_safefree(proxypasswd);
+ /* now, clone the proxy host name */
+ uc = curl_url_get(uhp, CURLUPART_HOST, &host, CURLU_URLDECODE);
+ if(uc) {
+ result = CURLE_OUT_OF_MEMORY;
+ goto error;
+ }
+ Curl_safefree(proxyinfo->host.rawalloc);
+ proxyinfo->host.rawalloc = host;
+ if(host[0] == '[') {
+ /* this is a numerical IPv6, strip off the brackets */
+ size_t len = strlen(host);
+ host[len-1] = 0; /* clear the trailing bracket */
+ host++;
+ }
+ proxyinfo->host.name = host;
- return CURLE_OK;
+ error:
+ free(scheme);
+ curl_url_cleanup(uhp);
+ return result;
}
/*
@@ -5280,22 +2502,27 @@ static CURLcode create_conn_helper_init_proxy(struct connectdata *conn)
}
}
- no_proxy = curl_getenv("no_proxy");
- if(!no_proxy)
- no_proxy = curl_getenv("NO_PROXY");
+ if(!data->set.str[STRING_NOPROXY]) {
+ const char *p = "no_proxy";
+ no_proxy = curl_getenv(p);
+ if(!no_proxy) {
+ p = "NO_PROXY";
+ no_proxy = curl_getenv(p);
+ }
+ if(no_proxy) {
+ infof(conn->data, "Uses proxy env variable %s == '%s'\n", p, no_proxy);
+ }
+ }
- if(check_noproxy(conn->host.name, data->set.str[STRING_NOPROXY]) ||
- (!data->set.str[STRING_NOPROXY] &&
- check_noproxy(conn->host.name, no_proxy))) {
+ if(check_noproxy(conn->host.name, data->set.str[STRING_NOPROXY] ?
+ data->set.str[STRING_NOPROXY] : no_proxy)) {
Curl_safefree(proxy);
Curl_safefree(socksproxy);
}
- else if(!proxy && !socksproxy)
#ifndef CURL_DISABLE_HTTP
+ else if(!proxy && !socksproxy)
/* if the host is not in the noproxy list, detect proxy. */
proxy = detect_proxy(conn);
-#else /* !CURL_DISABLE_HTTP */
- proxy = NULL;
#endif /* CURL_DISABLE_HTTP */
Curl_safefree(no_proxy);
@@ -5348,12 +2575,15 @@ static CURLcode create_conn_helper_init_proxy(struct connectdata *conn)
result = CURLE_UNSUPPORTED_PROTOCOL;
goto out;
#else
- /* force this connection's protocol to become HTTP if not already
- compatible - if it isn't tunneling through */
- if(!(conn->handler->protocol & PROTO_FAMILY_HTTP) &&
- !conn->bits.tunnel_proxy)
- conn->handler = &Curl_handler_http;
-
+ /* force this connection's protocol to become HTTP if compatible */
+ if(!(conn->handler->protocol & PROTO_FAMILY_HTTP)) {
+ if((conn->handler->flags & PROTOPT_PROXY_AS_HTTP) &&
+ !conn->bits.tunnel_proxy)
+ conn->handler = &Curl_handler_http;
+ else
+ /* if not converting to HTTP over the proxy, enforce tunneling */
+ conn->bits.tunnel_proxy = TRUE;
+ }
conn->bits.httpproxy = TRUE;
#endif
}
@@ -5402,124 +2632,7 @@ out:
#endif /* CURL_DISABLE_PROXY */
/*
- * parse_url_login()
- *
- * Parse the login details (user name, password and options) from the URL and
- * strip them out of the host name
- *
- * Inputs: data->set.use_netrc (CURLOPT_NETRC)
- * conn->host.name
- *
- * Outputs: (almost :- all currently undefined)
- * conn->bits.user_passwd - non-zero if non-default passwords exist
- * user - non-zero length if defined
- * passwd - non-zero length if defined
- * options - non-zero length if defined
- * conn->host.name - remove user name and password
- */
-static CURLcode parse_url_login(struct Curl_easy *data,
- struct connectdata *conn,
- char **user, char **passwd, char **options)
-{
- CURLcode result = CURLE_OK;
- char *userp = NULL;
- char *passwdp = NULL;
- char *optionsp = NULL;
-
- /* 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][;options]]@]hostname
- *
- * We need somewhere to put the embedded details, so do that first.
- */
-
- char *ptr = strchr(conn->host.name, '@');
- char *login = conn->host.name;
-
- DEBUGASSERT(!**user);
- DEBUGASSERT(!**passwd);
- DEBUGASSERT(!**options);
- DEBUGASSERT(conn->handler);
-
- if(!ptr)
- goto out;
-
- /* We will now try to extract the
- * possible login information in a string like:
- * ftp://user:password@ftp.my.site:8021/README */
- 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)
- goto out;
-
- /* We could use the login information in the URL so extract it. Only parse
- options if the handler says we should. */
- result = parse_login_details(login, ptr - login - 1,
- &userp, &passwdp,
- (conn->handler->flags & PROTOPT_URLOPTIONS)?
- &optionsp:NULL);
- if(result)
- goto out;
-
- if(userp) {
- char *newname;
-
- /* We have a user in the URL */
- conn->bits.userpwd_in_url = TRUE;
- conn->bits.user_passwd = TRUE; /* enable user+password */
-
- /* Decode the user */
- result = Curl_urldecode(data, userp, 0, &newname, NULL, FALSE);
- if(result) {
- goto out;
- }
-
- free(*user);
- *user = newname;
- }
-
- if(passwdp) {
- /* We have a password in the URL so decode it */
- char *newpasswd;
- result = Curl_urldecode(data, passwdp, 0, &newpasswd, NULL, FALSE);
- if(result) {
- goto out;
- }
-
- free(*passwd);
- *passwd = newpasswd;
- }
-
- if(optionsp) {
- /* We have an options list in the URL so decode it */
- char *newoptions;
- result = Curl_urldecode(data, optionsp, 0, &newoptions, NULL, FALSE);
- if(result) {
- goto out;
- }
-
- free(*options);
- *options = newoptions;
- }
-
-
- out:
-
- free(userp);
- free(passwdp);
- free(optionsp);
-
- return result;
-}
-
-/*
- * parse_login_details()
+ * Curl_parse_login_details()
*
* This is used to parse a login string for user name, password and options in
* the following formats:
@@ -5540,16 +2653,16 @@ static CURLcode parse_url_login(struct Curl_easy *data,
* len [in] - The length of the login string.
* userp [in/out] - The address where a pointer to newly allocated memory
* holding the user will be stored upon completion.
- * passdwp [in/out] - The address where a pointer to newly allocated memory
+ * passwdp [in/out] - The address where a pointer to newly allocated memory
* holding the password will be stored upon completion.
* optionsp [in/out] - The address where a pointer to newly allocated memory
* holding the options will be stored upon completion.
*
* Returns CURLE_OK on success.
*/
-static CURLcode parse_login_details(const char *login, const size_t len,
- char **userp, char **passwdp,
- char **optionsp)
+CURLcode Curl_parse_login_details(const char *login, const size_t len,
+ char **userp, char **passwdp,
+ char **optionsp)
{
CURLcode result = CURLE_OK;
char *ubuf = NULL;
@@ -5651,125 +2764,23 @@ static CURLcode parse_login_details(const char *login, const size_t len,
* 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.
- *
* The port number embedded in the URL is replaced, if necessary.
*************************************************************/
static CURLcode parse_remote_port(struct Curl_easy *data,
struct connectdata *conn)
{
- char *portptr;
- char endbracket;
-
- /* Note that at this point, the IPv6 address cannot contain any scope
- suffix as that has already been removed in the parseurlandfillconn()
- function */
- if((1 == sscanf(conn->host.name, "[%*45[0123456789abcdefABCDEF:.]%c",
- &endbracket)) &&
- (']' == endbracket)) {
- /* this is a RFC2732-style specified IP-address */
- conn->bits.ipv6_ip = TRUE;
-
- conn->host.name++; /* skip over the starting bracket */
- portptr = strchr(conn->host.name, ']');
- if(portptr) {
- *portptr++ = '\0'; /* zero terminate, killing the bracket */
- if(':' != *portptr)
- portptr = NULL; /* no port number available */
- }
- }
- else {
-#ifdef ENABLE_IPV6
- struct in6_addr in6;
- if(Curl_inet_pton(AF_INET6, conn->host.name, &in6) > 0) {
- /* This is a numerical IPv6 address, meaning this is a wrongly formatted
- URL */
- failf(data, "IPv6 numerical address used in URL without brackets");
- return CURLE_URL_MALFORMAT;
- }
-#endif
-
- portptr = strchr(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 */
+ /* if set, we use this instead of the port possibly given in the URL */
+ char portbuf[16];
+ CURLUcode uc;
conn->remote_port = (unsigned short)data->set.use_port;
- if(portptr)
- *portptr = '\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;
- char type[12]="";
-
- if(conn->bits.type_set)
- snprintf(type, sizeof(type), ";type=%c",
- data->set.prefer_ascii?'A':
- (data->set.ftp_list_only?'D':'I'));
-
- /*
- * This synthesized URL isn't always right--suffixes like ;type=A are
- * stripped off. It would be better to work directly from the original
- * URL and simply replace the port part of it.
- */
- url = aprintf("%s://%s%s%s:%hu%s%s%s", conn->given->scheme,
- conn->bits.ipv6_ip?"[":"", conn->host.name,
- conn->bits.ipv6_ip?"]":"", conn->remote_port,
- data->state.slash_removed?"/":"", data->state.path,
- type);
- if(!url)
- return CURLE_OUT_OF_MEMORY;
-
- if(data->change.url_alloc) {
- Curl_safefree(data->change.url);
- data->change.url_alloc = FALSE;
- }
-
- data->change.url = url;
- data->change.url_alloc = TRUE;
- }
- }
- else if(portptr) {
- /* no CURLOPT_PORT given, extract the one from the URL */
-
- char *rest;
- long port;
-
- port=strtol(portptr+1, &rest, 10); /* Port number must be decimal */
-
- if((port < 0) || (port > 0xffff)) {
- /* Single unix standard says port numbers are 16 bits long */
- failf(data, "Port number out of range");
- return CURLE_URL_MALFORMAT;
- }
-
- if(rest[0]) {
- failf(data, "Port number ended with '%c'", rest[0]);
- return CURLE_URL_MALFORMAT;
- }
-
- if(rest != &portptr[1]) {
- *portptr = '\0'; /* cut off the name there */
- conn->remote_port = curlx_ultous(port);
- }
- else {
- /* Browser behavior adaptation. If there's a colon with no digits after,
- just cut off the name there which makes us ignore the colon and just
- use the default port. Firefox and Chrome both do that. */
- *portptr = '\0';
- }
+ msnprintf(portbuf, sizeof(portbuf), "%d", conn->remote_port);
+ uc = curl_url_set(data->state.uh, CURLUPART_PORT, portbuf, 0);
+ if(uc)
+ return CURLE_OUT_OF_MEMORY;
}
- /* only if remote_port was not already parsed off the URL we use the
- default port number */
- if(conn->remote_port < 0)
- conn->remote_port = (unsigned short)conn->given->defport;
-
return CURLE_OK;
}
@@ -5781,11 +2792,30 @@ static CURLcode override_login(struct Curl_easy *data,
struct connectdata *conn,
char **userp, char **passwdp, char **optionsp)
{
+ bool user_changed = FALSE;
+ bool passwd_changed = FALSE;
+ CURLUcode uc;
+
+ if(data->set.use_netrc == CURL_NETRC_REQUIRED && conn->bits.user_passwd) {
+ /* ignore user+password in the URL */
+ if(*userp) {
+ Curl_safefree(*userp);
+ user_changed = TRUE;
+ }
+ if(*passwdp) {
+ Curl_safefree(*passwdp);
+ passwd_changed = TRUE;
+ }
+ conn->bits.user_passwd = FALSE; /* disable user+password */
+ }
+
if(data->set.str[STRING_USERNAME]) {
free(*userp);
*userp = strdup(data->set.str[STRING_USERNAME]);
if(!*userp)
return CURLE_OUT_OF_MEMORY;
+ conn->bits.user_passwd = TRUE; /* enable user+password */
+ user_changed = TRUE;
}
if(data->set.str[STRING_PASSWORD]) {
@@ -5793,6 +2823,8 @@ static CURLcode override_login(struct Curl_easy *data,
*passwdp = strdup(data->set.str[STRING_PASSWORD]);
if(!*passwdp)
return CURLE_OUT_OF_MEMORY;
+ conn->bits.user_passwd = TRUE; /* enable user+password */
+ passwd_changed = TRUE;
}
if(data->set.str[STRING_OPTIONS]) {
@@ -5803,10 +2835,16 @@ static CURLcode override_login(struct Curl_easy *data,
}
conn->bits.netrc = FALSE;
- if(data->set.use_netrc != CURL_NETRC_IGNORED) {
- int ret = Curl_parsenetrc(conn->host.name,
- userp, passwdp,
- data->set.str[STRING_NETRC_FILE]);
+ if(data->set.use_netrc != CURL_NETRC_IGNORED &&
+ (!*userp || !**userp || !*passwdp || !**passwdp)) {
+ bool netrc_user_changed = FALSE;
+ bool netrc_passwd_changed = FALSE;
+ int ret;
+
+ ret = Curl_parsenetrc(conn->host.name,
+ userp, passwdp,
+ &netrc_user_changed, &netrc_passwd_changed,
+ data->set.str[STRING_NETRC_FILE]);
if(ret > 0) {
infof(data, "Couldn't find host %s in the "
DOT_CHAR "netrc file; using defaults\n",
@@ -5820,55 +2858,65 @@ static CURLcode override_login(struct Curl_easy *data,
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 = TRUE; /* enable user+password */
+
+ if(netrc_user_changed) {
+ user_changed = TRUE;
+ }
+ if(netrc_passwd_changed) {
+ passwd_changed = TRUE;
+ }
}
}
+ /* for updated strings, we update them in the URL */
+ if(user_changed) {
+ uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, 0);
+ if(uc)
+ return Curl_uc_to_curlcode(uc);
+ }
+ if(passwd_changed) {
+ uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, 0);
+ if(uc)
+ return Curl_uc_to_curlcode(uc);
+ }
return CURLE_OK;
}
/*
* Set the login details so they're available in the connection
*/
-static CURLcode set_login(struct connectdata *conn,
- const char *user, const char *passwd,
- const char *options)
+static CURLcode set_login(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
+ const char *setuser = CURL_DEFAULT_USER;
+ const char *setpasswd = CURL_DEFAULT_PASSWORD;
/* If our protocol needs a password and we have none, use the defaults */
- if((conn->handler->flags & PROTOPT_NEEDSPWD) && !conn->bits.user_passwd) {
- /* Store the default user */
- conn->user = strdup(CURL_DEFAULT_USER);
-
- /* Store the default password */
- if(conn->user)
- conn->passwd = strdup(CURL_DEFAULT_PASSWORD);
- else
- conn->passwd = NULL;
-
- /* This is the default password, so DON'T set conn->bits.user_passwd */
- }
+ if((conn->handler->flags & PROTOPT_NEEDSPWD) && !conn->bits.user_passwd)
+ ;
else {
- /* Store the user, zero-length if not set */
- conn->user = strdup(user);
-
- /* Store the password (only if user is present), zero-length if not set */
- if(conn->user)
- conn->passwd = strdup(passwd);
- else
- conn->passwd = NULL;
+ setuser = "";
+ setpasswd = "";
+ }
+ /* Store the default user */
+ if(!conn->user) {
+ conn->user = strdup(setuser);
+ if(!conn->user)
+ return CURLE_OUT_OF_MEMORY;
}
- if(!conn->user || !conn->passwd)
- result = CURLE_OUT_OF_MEMORY;
-
- /* Store the options, null if not set */
- if(!result && options[0]) {
- conn->options = strdup(options);
+ /* Store the default password */
+ if(!conn->passwd) {
+ conn->passwd = strdup(setpasswd);
+ if(!conn->passwd)
+ result = CURLE_OUT_OF_MEMORY;
+ }
- if(!conn->options)
+ /* if there's a user without password, consider password blank */
+ if(conn->user && !conn->passwd) {
+ conn->passwd = strdup("");
+ if(!conn->passwd)
result = CURLE_OUT_OF_MEMORY;
}
@@ -5912,6 +2960,7 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data,
/* detect and extract RFC6874-style IPv6-addresses */
if(*hostptr == '[') {
+#ifdef ENABLE_IPV6
char *ptr = ++hostptr; /* advance beyond the initial bracket */
while(*ptr && (ISXDIGIT(*ptr) || (*ptr == ':') || (*ptr == '.')))
ptr++;
@@ -5935,6 +2984,11 @@ static CURLcode parse_connect_to_host_port(struct Curl_easy *data,
* hostptr first, but I can't see anything wrong with that as no host
* name nor a numeric can legally start with a bracket.
*/
+#else
+ failf(data, "Use of IPv6 in *_CONNECT_TO without IPv6 support built-in!");
+ free(host_dup);
+ return CURLE_NOT_BUILT_IN;
+#endif
}
/* Get port number off server.com:1080 */
@@ -6086,6 +3140,34 @@ static CURLcode parse_connect_to_slist(struct Curl_easy *data,
conn_to_host = conn_to_host->next;
}
+#ifdef USE_ALTSVC
+ if(data->asi && !host && (port == -1) &&
+ (conn->handler->protocol == CURLPROTO_HTTPS)) {
+ /* no connect_to match, try alt-svc! */
+ const char *nhost;
+ int nport;
+ enum alpnid nalpnid;
+ bool hit;
+ host = conn->host.rawalloc;
+ hit = Curl_altsvc_lookup(data->asi,
+ ALPN_h1, host, conn->remote_port, /* from */
+ &nalpnid, &nhost, &nport /* to */);
+ if(hit) {
+ char *hostd = strdup((char *)nhost);
+ if(!hostd)
+ return CURLE_OUT_OF_MEMORY;
+ conn->conn_to_host.rawalloc = hostd;
+ conn->conn_to_host.name = hostd;
+ conn->bits.conn_to_host = TRUE;
+ conn->conn_to_port = nport;
+ conn->bits.conn_to_port = TRUE;
+ infof(data, "Alt-svc connecting from [%s]%s:%d to [%s]%s:%d\n",
+ Curl_alpnid2str(ALPN_h1), host, conn->remote_port,
+ Curl_alpnid2str(nalpnid), hostd, nport);
+ }
+ }
+#endif
+
return result;
}
@@ -6096,15 +3178,17 @@ static CURLcode resolve_server(struct Curl_easy *data,
struct connectdata *conn,
bool *async)
{
- CURLcode result=CURLE_OK;
- time_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
+ CURLcode result = CURLE_OK;
+ timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
+ DEBUGASSERT(conn);
+ DEBUGASSERT(data);
/*************************************************************
* Resolve the name of the server or proxy
*************************************************************/
if(conn->bits.reuse)
/* We're reusing the connection - no need to resolve anything, and
- fix_hostname() was called already in create_conn() for the re-use
+ idnconvert_hostname() was called already in create_conn() for the re-use
case. */
*async = FALSE;
@@ -6159,7 +3243,10 @@ static CURLcode resolve_server(struct Curl_easy *data,
conn->port = conn->remote_port;
/* Resolve target host right on */
- rc = Curl_resolv_timeout(conn, connhost->name, (int)conn->port,
+ conn->hostname_resolve = strdup(connhost->name);
+ if(!conn->hostname_resolve)
+ return CURLE_OUT_OF_MEMORY;
+ rc = Curl_resolv_timeout(conn, conn->hostname_resolve, (int)conn->port,
&hostaddr, timeout_ms);
if(rc == CURLRESOLV_PENDING)
*async = TRUE;
@@ -6180,7 +3267,10 @@ static CURLcode resolve_server(struct Curl_easy *data,
&conn->socks_proxy.host : &conn->http_proxy.host;
/* resolve proxy */
- rc = Curl_resolv_timeout(conn, host->name, (int)conn->port,
+ conn->hostname_resolve = strdup(host->name);
+ if(!conn->hostname_resolve)
+ return CURLE_OUT_OF_MEMORY;
+ rc = Curl_resolv_timeout(conn, conn->hostname_resolve, (int)conn->port,
&hostaddr, timeout_ms);
if(rc == CURLRESOLV_PENDING)
@@ -6210,8 +3300,8 @@ static CURLcode resolve_server(struct Curl_easy *data,
static void reuse_conn(struct connectdata *old_conn,
struct connectdata *conn)
{
- free_fixed_hostname(&old_conn->http_proxy.host);
- free_fixed_hostname(&old_conn->socks_proxy.host);
+ free_idnconverted_hostname(&old_conn->http_proxy.host);
+ free_idnconverted_hostname(&old_conn->socks_proxy.host);
free(old_conn->http_proxy.host.rawalloc);
free(old_conn->socks_proxy.host.rawalloc);
@@ -6255,15 +3345,18 @@ static void reuse_conn(struct connectdata *old_conn,
/* host can change, when doing keepalive with a proxy or if the case is
different this time etc */
- free_fixed_hostname(&conn->host);
- free_fixed_hostname(&conn->conn_to_host);
+ free_idnconverted_hostname(&conn->host);
+ free_idnconverted_hostname(&conn->conn_to_host);
Curl_safefree(conn->host.rawalloc);
Curl_safefree(conn->conn_to_host.rawalloc);
- conn->host=old_conn->host;
- conn->bits.conn_to_host = old_conn->bits.conn_to_host;
+ conn->host = old_conn->host;
conn->conn_to_host = old_conn->conn_to_host;
- conn->bits.conn_to_port = old_conn->bits.conn_to_port;
conn->conn_to_port = old_conn->conn_to_port;
+ conn->remote_port = old_conn->remote_port;
+ Curl_safefree(conn->hostname_resolve);
+
+ conn->hostname_resolve = old_conn->hostname_resolve;
+ old_conn->hostname_resolve = NULL;
/* persist connection info in session handle */
Curl_persistconninfo(conn);
@@ -6275,16 +3368,13 @@ static void reuse_conn(struct connectdata *old_conn,
Curl_safefree(old_conn->user);
Curl_safefree(old_conn->passwd);
+ Curl_safefree(old_conn->options);
Curl_safefree(old_conn->http_proxy.user);
Curl_safefree(old_conn->socks_proxy.user);
Curl_safefree(old_conn->http_proxy.passwd);
Curl_safefree(old_conn->socks_proxy.passwd);
Curl_safefree(old_conn->localdev);
-
- Curl_llist_destroy(&old_conn->send_pipe, NULL);
- Curl_llist_destroy(&old_conn->recv_pipe, NULL);
-
- Curl_safefree(old_conn->master_buffer);
+ Curl_llist_destroy(&old_conn->easyq, NULL);
#ifdef USE_UNIX_SOCKETS
Curl_safefree(old_conn->unix_domain_socket);
@@ -6314,12 +3404,7 @@ static CURLcode create_conn(struct Curl_easy *data,
CURLcode result = CURLE_OK;
struct connectdata *conn;
struct connectdata *conn_temp = NULL;
- size_t urllen;
- char *user = NULL;
- char *passwd = NULL;
- char *options = NULL;
bool reuse;
- bool prot_missing = FALSE;
bool connections_available = TRUE;
bool force_reuse = FALSE;
bool waitpipe = FALSE;
@@ -6327,11 +3412,11 @@ static CURLcode create_conn(struct Curl_easy *data,
size_t max_total_connections = Curl_multi_max_total_connections(data->multi);
*async = FALSE;
+ *in_connect = NULL;
/*************************************************************
* Check input data
*************************************************************/
-
if(!data->change.url) {
result = CURLE_URL_MALFORMAT;
goto out;
@@ -6353,107 +3438,10 @@ static CURLcode create_conn(struct Curl_easy *data,
any failure */
*in_connect = conn;
- /* 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;
-
- /*
- * We malloc() the buffers below urllen+2 to make room for 2 possibilities:
- * 1 - an extra terminating zero
- * 2 - an extra slash (in case a syntax like "www.host.com?moo" is used)
- */
-
- Curl_safefree(data->state.pathbuffer);
- data->state.path = NULL;
-
- data->state.pathbuffer = malloc(urllen+2);
- if(NULL == data->state.pathbuffer) {
- result = CURLE_OUT_OF_MEMORY; /* really bad error */
- goto out;
- }
- data->state.path = data->state.pathbuffer;
-
- conn->host.rawalloc = malloc(urllen+2);
- if(NULL == conn->host.rawalloc) {
- Curl_safefree(data->state.pathbuffer);
- data->state.path = NULL;
- result = CURLE_OUT_OF_MEMORY;
- goto out;
- }
-
- conn->host.name = conn->host.rawalloc;
- conn->host.name[0] = 0;
-
- user = strdup("");
- passwd = strdup("");
- options = strdup("");
- if(!user || !passwd || !options) {
- result = CURLE_OUT_OF_MEMORY;
- goto out;
- }
-
- result = parseurlandfillconn(data, conn, &prot_missing, &user, &passwd,
- &options);
+ result = parseurlandfillconn(data, conn);
if(result)
goto out;
- /*************************************************************
- * No protocol part in URL was used, add it!
- *************************************************************/
- if(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;
- char *ch_lower;
-
- reurl = aprintf("%s://%s", conn->handler->scheme, data->change.url);
-
- if(!reurl) {
- result = CURLE_OUT_OF_MEMORY;
- goto out;
- }
-
- /* Change protocol prefix to lower-case */
- for(ch_lower = reurl; *ch_lower != ':'; ch_lower++)
- *ch_lower = (char)TOLOWER(*ch_lower);
-
- if(data->change.url_alloc) {
- Curl_safefree(data->change.url);
- data->change.url_alloc = FALSE;
- }
-
- data->change.url = reurl;
- data->change.url_alloc = TRUE; /* free this later */
- }
-
- /*************************************************************
- * If the protocol can't handle url query strings, then cut
- * off the unhandable part
- *************************************************************/
- if((conn->given->flags&PROTOPT_NOURLQUERY)) {
- char *path_q_sep = strchr(conn->data->state.path, '?');
- if(path_q_sep) {
- /* according to rfc3986, allow the query (?foo=bar)
- also on protocols that can't handle it.
-
- cut the string-part after '?'
- */
-
- /* terminate the string */
- path_q_sep[0] = 0;
- }
- }
-
if(data->set.str[STRING_BEARER]) {
conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]);
if(!conn->oauth_bearer) {
@@ -6497,10 +3485,12 @@ static CURLcode create_conn(struct Curl_easy *data,
/* Check for overridden login details and set them accordingly so they
they are known when protocol->setup_connection is called! */
- result = override_login(data, conn, &user, &passwd, &options);
+ result = override_login(data, conn, &conn->user, &conn->passwd,
+ &conn->options);
if(result)
goto out;
- result = set_login(conn, user, passwd, options);
+
+ result = set_login(conn); /* default credentials */
if(result)
goto out;
@@ -6513,19 +3503,30 @@ static CURLcode create_conn(struct Curl_easy *data,
goto out;
/*************************************************************
- * IDN-fix the hostnames
+ * IDN-convert the hostnames
*************************************************************/
- fix_hostname(conn, &conn->host);
- if(conn->bits.conn_to_host)
- fix_hostname(conn, &conn->conn_to_host);
- if(conn->bits.httpproxy)
- fix_hostname(conn, &conn->http_proxy.host);
- if(conn->bits.socksproxy)
- fix_hostname(conn, &conn->socks_proxy.host);
+ result = idnconvert_hostname(conn, &conn->host);
+ if(result)
+ goto out;
+ if(conn->bits.conn_to_host) {
+ result = idnconvert_hostname(conn, &conn->conn_to_host);
+ if(result)
+ goto out;
+ }
+ if(conn->bits.httpproxy) {
+ result = idnconvert_hostname(conn, &conn->http_proxy.host);
+ if(result)
+ goto out;
+ }
+ if(conn->bits.socksproxy) {
+ result = idnconvert_hostname(conn, &conn->socks_proxy.host);
+ if(result)
+ goto out;
+ }
/*************************************************************
* Check whether the host and the "connect to host" are equal.
- * Do this after the hostnames have been IDN-fixed.
+ * Do this after the hostnames have been IDN-converted.
*************************************************************/
if(conn->bits.conn_to_host &&
strcasecompare(conn->conn_to_host.name, conn->host.name)) {
@@ -6572,14 +3573,16 @@ static CURLcode create_conn(struct Curl_easy *data,
/* this is supposed to be the connect function so we better at least check
that the file is present here! */
DEBUGASSERT(conn->handler->connect_it);
+ Curl_persistconninfo(conn);
result = conn->handler->connect_it(conn, &done);
/* Setup a "faked" transfer that'll do nothing */
if(!result) {
- conn->data = data;
conn->bits.tcpconnect[FIRSTSOCKET] = TRUE; /* we are "connected */
- Curl_conncache_add_conn(data->state.conn_cache, conn);
+ result = Curl_conncache_add_conn(data->state.conn_cache, conn);
+ if(result)
+ goto out;
/*
* Setup whatever necessary for a resumed transfer
@@ -6591,9 +3594,8 @@ static CURLcode create_conn(struct Curl_easy *data,
(void)conn->handler->done(conn, result, FALSE);
goto out;
}
-
- Curl_setup_transfer(conn, -1, -1, FALSE, NULL, /* no download */
- -1, NULL); /* no upload */
+ Curl_attach_connnection(data, conn);
+ Curl_setup_transfer(data, -1, -1, FALSE, -1);
}
/* since we skip do_init() */
@@ -6625,6 +3627,10 @@ static CURLcode create_conn(struct Curl_easy *data,
data->set.str[STRING_SSL_CIPHER_LIST_ORIG];
data->set.proxy_ssl.primary.cipher_list =
data->set.str[STRING_SSL_CIPHER_LIST_PROXY];
+ data->set.ssl.primary.cipher_list13 =
+ data->set.str[STRING_SSL_CIPHER13_LIST_ORIG];
+ data->set.proxy_ssl.primary.cipher_list13 =
+ data->set.str[STRING_SSL_CIPHER13_LIST_PROXY];
data->set.ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG];
data->set.proxy_ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_PROXY];
@@ -6669,29 +3675,34 @@ static CURLcode create_conn(struct Curl_easy *data,
* new one.
*************************************************************/
+ DEBUGASSERT(conn->user);
+ DEBUGASSERT(conn->passwd);
+
/* 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)
+ authentication phase). CONNECT_ONLY transfers also refuse reuse. */
+ if((data->set.reuse_fresh && !data->state.this_is_a_follow) ||
+ data->set.connect_only)
reuse = FALSE;
else
reuse = ConnectionExists(data, conn, &conn_temp, &force_reuse, &waitpipe);
- /* If we found a reusable connection, we may still want to
- open a new connection if we are pipelining. */
- if(reuse && !force_reuse && IsPipeliningPossible(data, conn_temp)) {
- size_t pipelen = conn_temp->send_pipe.size + conn_temp->recv_pipe.size;
- if(pipelen > 0) {
- infof(data, "Found connection %ld, with requests in the pipe (%zu)\n",
- conn_temp->connection_id, pipelen);
+ /* If we found a reusable connection that is now marked as in use, we may
+ still want to open a new connection if we are multiplexing. */
+ if(reuse && !force_reuse && IsMultiplexingPossible(data, conn_temp)) {
+ size_t multiplexed = CONN_INUSE(conn_temp);
+ if(multiplexed > 0) {
+ infof(data, "Found connection %ld, with %zu requests on it\n",
+ conn_temp->connection_id, multiplexed);
- if(conn_temp->bundle->num_connections < max_host_connections &&
- data->state.conn_cache->num_connections < max_total_connections) {
+ if(Curl_conncache_bundle_size(conn_temp) < max_host_connections &&
+ Curl_conncache_size(data) < max_total_connections) {
/* We want a new connection anyway */
reuse = FALSE;
infof(data, "We can reuse, but we want a new connection anyway\n");
+ Curl_conncache_return_conn(conn_temp);
}
}
}
@@ -6703,9 +3714,10 @@ static CURLcode create_conn(struct Curl_easy *data,
* just allocated before we can move along and use the previously
* existing one.
*/
- conn_temp->inuse = TRUE; /* mark this as being in use so that no other
- handle in a multi stack may nick it */
reuse_conn(conn, conn_temp);
+#ifdef USE_SSL
+ free(conn->ssl_extra);
+#endif
free(conn); /* we don't need this anymore */
conn = conn_temp;
*in_connect = conn;
@@ -6721,7 +3733,6 @@ static CURLcode create_conn(struct Curl_easy *data,
/* We have decided that we want a new connection. However, we may not
be able to do that if we have reached the limit of how many
connections we are allowed to open. */
- struct connectbundle *bundle = NULL;
if(conn->handler->flags & PROTOPT_ALPN_NPN) {
/* The protocol wants it, so set the bits if enabled in the easy handle
@@ -6733,44 +3744,46 @@ static CURLcode create_conn(struct Curl_easy *data,
}
if(waitpipe)
- /* There is a connection that *might* become usable for pipelining
+ /* There is a connection that *might* become usable for multiplexing
"soon", and we wait for that */
connections_available = FALSE;
- else
- bundle = Curl_conncache_find_bundle(conn, data->state.conn_cache);
+ else {
+ /* this gets a lock on the conncache */
+ struct connectbundle *bundle =
+ Curl_conncache_find_bundle(conn, data->state.conn_cache);
- if(max_host_connections > 0 && bundle &&
- (bundle->num_connections >= max_host_connections)) {
- struct connectdata *conn_candidate;
+ if(max_host_connections > 0 && bundle &&
+ (bundle->num_connections >= max_host_connections)) {
+ struct connectdata *conn_candidate;
- /* The bundle is full. Let's see if we can kill a connection. */
- conn_candidate = find_oldest_idle_connection_in_bundle(data, bundle);
+ /* The bundle is full. Extract the oldest connection. */
+ conn_candidate = Curl_conncache_extract_bundle(data, bundle);
+ Curl_conncache_unlock(data);
- if(conn_candidate) {
- /* Set the connection's owner correctly, then kill it */
- conn_candidate->data = data;
- (void)Curl_disconnect(conn_candidate, /* dead_connection */ FALSE);
- }
- else {
- infof(data, "No more connections allowed to host: %d\n",
- max_host_connections);
- connections_available = FALSE;
+ if(conn_candidate)
+ (void)Curl_disconnect(data, conn_candidate,
+ /* dead_connection */ FALSE);
+ else {
+ infof(data, "No more connections allowed to host: %zu\n",
+ max_host_connections);
+ connections_available = FALSE;
+ }
}
+ else
+ Curl_conncache_unlock(data);
+
}
if(connections_available &&
(max_total_connections > 0) &&
- (data->state.conn_cache->num_connections >= max_total_connections)) {
+ (Curl_conncache_size(data) >= max_total_connections)) {
struct connectdata *conn_candidate;
/* The cache is full. Let's see if we can kill a connection. */
- conn_candidate = Curl_oldest_idle_connection(data);
-
- if(conn_candidate) {
- /* Set the connection's owner correctly, then kill it */
- conn_candidate->data = data;
- (void)Curl_disconnect(conn_candidate, /* dead_connection */ FALSE);
- }
+ conn_candidate = Curl_conncache_extract_oldest(data);
+ if(conn_candidate)
+ (void)Curl_disconnect(data, conn_candidate,
+ /* dead_connection */ FALSE);
else {
infof(data, "No connections available in cache\n");
connections_available = FALSE;
@@ -6791,7 +3804,9 @@ static CURLcode create_conn(struct Curl_easy *data,
* This is a brand new connection, so let's store it in the connection
* cache of ours!
*/
- Curl_conncache_add_conn(data->state.conn_cache, conn);
+ result = Curl_conncache_add_conn(data->state.conn_cache, conn);
+ if(result)
+ goto out;
}
#if defined(USE_NTLM)
@@ -6814,9 +3829,6 @@ static CURLcode create_conn(struct Curl_easy *data,
#endif
}
- /* Mark the connection as used */
- conn->inuse = TRUE;
-
/* Setup and init stuff before DO starts, in preparing for the transfer. */
Curl_init_do(data, conn);
@@ -6841,11 +3853,16 @@ static CURLcode create_conn(struct Curl_easy *data,
*************************************************************/
result = resolve_server(data, conn, async);
-out:
+ /* Strip trailing dots. resolve_server copied the name. */
+ strip_trailing_dot(&conn->host);
+ if(conn->bits.httpproxy)
+ strip_trailing_dot(&conn->http_proxy.host);
+ if(conn->bits.socksproxy)
+ strip_trailing_dot(&conn->socks_proxy.host);
+ if(conn->bits.conn_to_host)
+ strip_trailing_dot(&conn->conn_to_host);
- free(options);
- free(passwd);
- free(user);
+out:
return result;
}
@@ -6899,7 +3916,7 @@ CURLcode Curl_setup_conn(struct connectdata *conn,
/* 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();
+ conn->now = Curl_now();
if(CURL_SOCKET_BAD == conn->sock[FIRSTSOCKET]) {
conn->bits.tcpconnect[FIRSTSOCKET] = FALSE;
@@ -6916,61 +3933,51 @@ CURLcode Curl_setup_conn(struct connectdata *conn,
Curl_verboseconnect(conn);
}
- conn->now = Curl_tvnow(); /* time this *after* the connect is done, we
- set this here perhaps a second time */
-
-#ifdef __EMX__
- /*
- * This 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
-
+ conn->now = Curl_now(); /* time this *after* the connect is done, we set
+ this here perhaps a second time */
return result;
}
CURLcode Curl_connect(struct Curl_easy *data,
- struct connectdata **in_connect,
bool *asyncp,
bool *protocol_done)
{
CURLcode result;
+ struct connectdata *conn;
*asyncp = FALSE; /* assume synchronous resolves by default */
+ /* init the single-transfer specific data */
+ Curl_free_request_state(data);
+ memset(&data->req, 0, sizeof(struct SingleRequest));
+ data->req.maxdownload = -1;
+
/* call the stuff that needs to be called */
- result = create_conn(data, in_connect, asyncp);
+ result = create_conn(data, &conn, asyncp);
if(!result) {
- /* no error */
- if((*in_connect)->send_pipe.size || (*in_connect)->recv_pipe.size)
- /* pipelining */
+ if(CONN_INUSE(conn))
+ /* multiplexed */
*protocol_done = TRUE;
else if(!*asyncp) {
/* DNS resolution is done: that's either because this is a reused
connection, in which case DNS was unnecessary, or because DNS
really did finish already (synch resolver/fast async resolve) */
- result = Curl_setup_conn(*in_connect, protocol_done);
+ result = Curl_setup_conn(conn, protocol_done);
}
}
if(result == CURLE_NO_CONNECTION_AVAILABLE) {
- *in_connect = NULL;
return result;
}
-
- if(result && *in_connect) {
- /* We're not allowed to return failure with memory left allocated
- in the connectdata struct, free those here */
- Curl_disconnect(*in_connect, FALSE); /* close the connection */
- *in_connect = NULL; /* return a NULL */
+ else if(result && conn) {
+ /* We're not allowed to return failure with memory left allocated in the
+ connectdata struct, free those here */
+ Curl_disconnect(data, conn, TRUE);
}
+ else if(!result && !data->conn)
+ /* FILE: transfers already have the connection attached */
+ Curl_attach_connnection(data, conn);
return result;
}
@@ -6989,13 +3996,19 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
{
struct SingleRequest *k = &data->req;
- if(conn)
+ if(conn) {
conn->bits.do_more = FALSE; /* by default there's no curl_do_more() to
- * use */
+ use */
+ /* if the protocol used doesn't support wildcards, switch it off */
+ if(data->state.wildcardmatch &&
+ !(conn->handler->flags & PROTOPT_WILDCARD))
+ data->state.wildcardmatch = FALSE;
+ }
data->state.done = FALSE; /* *_done() is not called yet */
data->state.expect100header = FALSE;
+
if(data->set.opt_no_body)
/* in HTTP lingo, no body means using the HEAD request... */
data->set.httpreq = HTTPREQ_HEAD;
@@ -7007,7 +4020,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
HTTP. */
data->set.httpreq = HTTPREQ_GET;
- k->start = Curl_tvnow(); /* start time */
+ k->start = Curl_now(); /* start time */
k->now = k->start; /* current time is now */
k->header = TRUE; /* assume header */
@@ -7015,7 +4028,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
k->buf = data->state.buffer;
k->hbufp = data->state.headerbuff;
- k->ignorebody=FALSE;
+ k->ignorebody = FALSE;
Curl_speedinit(data);
@@ -7134,3 +4147,34 @@ static unsigned int get_protocol_family(unsigned int protocol)
return family;
}
+
+
+/*
+ * Wrapper to call functions in Curl_conncache_foreach()
+ *
+ * Returns always 0.
+ */
+static int conn_upkeep(struct connectdata *conn,
+ void *param)
+{
+ /* Param is unused. */
+ (void)param;
+
+ if(conn->handler->connection_check) {
+ /* Do a protocol-specific keepalive check on the connection. */
+ conn->handler->connection_check(conn, CONNCHECK_KEEPALIVE);
+ }
+
+ return 0; /* continue iteration */
+}
+
+CURLcode Curl_upkeep(struct conncache *conn_cache,
+ void *data)
+{
+ /* Loop over every connection and make connection alive. */
+ Curl_conncache_foreach(data,
+ conn_cache,
+ data,
+ conn_upkeep);
+ return CURLE_OK;
+}
diff --git a/Utilities/cmcurl/lib/url.h b/Utilities/cmcurl/lib/url.h
index f13c8e664..4db9e8653 100644
--- a/Utilities/cmcurl/lib/url.h
+++ b/Utilities/cmcurl/lib/url.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -23,21 +23,38 @@
***************************************************************************/
#include "curl_setup.h"
+#define READBUFFER_SIZE CURL_MAX_WRITE_SIZE
+#define READBUFFER_MAX CURL_MAX_READ_SIZE
+#define READBUFFER_MIN 1024
+
+/* The default upload buffer size, should not be smaller than
+ CURL_MAX_WRITE_SIZE, as it needs to hold a full buffer as could be sent in
+ a write callback.
+
+ The size was 16KB for many years but was bumped to 64KB because it makes
+ libcurl able to do significantly faster uploads in some circumstances. Even
+ larger buffers can help further, but this is deemed a fair memory/speed
+ compromise. */
+#define UPLOADBUFFER_DEFAULT 65536
+#define UPLOADBUFFER_MAX (2*1024*1024)
+#define UPLOADBUFFER_MIN CURL_MAX_WRITE_SIZE
+
/*
* Prototypes for library-wide functions provided by url.c
*/
CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn);
CURLcode Curl_open(struct Curl_easy **curl);
-CURLcode Curl_init_userdefined(struct UserDefined *set);
-CURLcode Curl_setopt(struct Curl_easy *data, CURLoption option,
- va_list arg);
-CURLcode Curl_dupset(struct Curl_easy * dst, struct Curl_easy * src);
+CURLcode Curl_init_userdefined(struct Curl_easy *data);
+
void Curl_freeset(struct Curl_easy * data);
+/* free the URL pieces */
+void Curl_up_free(struct Curl_easy *data);
+CURLcode Curl_uc_to_curlcode(CURLUcode uc);
CURLcode Curl_close(struct Curl_easy *data); /* opposite of curl_open() */
-CURLcode Curl_connect(struct Curl_easy *, struct connectdata **,
- bool *async, bool *protocol_connect);
-CURLcode Curl_disconnect(struct connectdata *, bool dead_connection);
+CURLcode Curl_connect(struct Curl_easy *, bool *async, bool *protocol_connect);
+CURLcode Curl_disconnect(struct Curl_easy *data,
+ struct connectdata *, bool dead_connection);
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);
@@ -51,20 +68,13 @@ int Curl_protocol_getsock(struct connectdata *conn,
int Curl_doing_getsock(struct connectdata *conn,
curl_socket_t *socks,
int numsocks);
-
-bool Curl_isPipeliningEnabled(const struct Curl_easy *handle);
-CURLcode Curl_addHandleToPipeline(struct Curl_easy *handle,
- struct curl_llist *pipeline);
-int Curl_removeHandleFromPipeline(struct Curl_easy *handle,
- struct curl_llist *pipeline);
-struct connectdata *
-Curl_oldest_idle_connection(struct Curl_easy *data);
-/* remove the specified connection from all (possible) pipelines and related
- queues */
-void Curl_getoff_all_pipelines(struct Curl_easy *data,
- struct connectdata *conn);
-
+CURLcode Curl_parse_login_details(const char *login, const size_t len,
+ char **userptr, char **passwdptr,
+ char **optionsptr);
void Curl_close_connections(struct Curl_easy *data);
+CURLcode Curl_upkeep(struct conncache *conn_cache, void *data);
+
+const struct Curl_handler *Curl_builtin_scheme(const char *scheme);
#define CURL_DEFAULT_PROXY_PORT 1080 /* default proxy port unless specified */
#define CURL_DEFAULT_HTTPS_PROXY_PORT 443 /* default https proxy port unless
diff --git a/Utilities/cmcurl/lib/urldata.h b/Utilities/cmcurl/lib/urldata.h
index d4a4a98dc..d759592d9 100644
--- a/Utilities/cmcurl/lib/urldata.h
+++ b/Utilities/cmcurl/lib/urldata.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -77,94 +77,25 @@
/* Default FTP/IMAP etc response timeout in milliseconds.
Symbian OS panics when given a timeout much greater than 1/2 hour.
*/
-#define RESP_TIMEOUT (1800*1000)
+#define RESP_TIMEOUT (120*1000)
+
+/* Max string intput length is a precaution against abuse and to detect junk
+ input easier and better. */
+#define CURL_MAX_INPUT_LENGTH 8000000
#include "cookie.h"
+#include "psl.h"
#include "formdata.h"
-#ifdef USE_OPENSSL
-#include <openssl/ssl.h>
-#ifdef HAVE_OPENSSL_ENGINE_H
-#include <openssl/engine.h>
-#endif
-#endif /* USE_OPENSSL */
-
-#ifdef USE_GNUTLS
-#include <gnutls/gnutls.h>
-#endif
-
-#ifdef USE_MBEDTLS
-
-#include <mbedtls/ssl.h>
-#include <mbedtls/version.h>
-#include <mbedtls/entropy.h>
-#include <mbedtls/ctr_drbg.h>
-
-#elif defined USE_POLARSSL
-
-#include <polarssl/ssl.h>
-#include <polarssl/version.h>
-#if POLARSSL_VERSION_NUMBER<0x01010000
-#include <polarssl/havege.h>
-#else
-#include <polarssl/entropy.h>
-#include <polarssl/ctr_drbg.h>
-#endif /* POLARSSL_VERSION_NUMBER<0x01010000 */
-
-#endif /* USE_POLARSSL */
-
-#ifdef USE_CYASSL
-#undef OCSP_REQUEST /* avoid cyassl/openssl/ssl.h clash with wincrypt.h */
-#undef OCSP_RESPONSE /* avoid cyassl/openssl/ssl.h clash with wincrypt.h */
-#include <cyassl/openssl/ssl.h>
-#endif
-
-#ifdef USE_NSS
-#include <nspr.h>
-#include <pk11pub.h>
-#endif
-
-#ifdef USE_GSKIT
-#include <gskssl.h>
-#endif
-
-#ifdef USE_AXTLS
-#include <axTLS/config.h>
-#include <axTLS/ssl.h>
-#undef malloc
-#undef calloc
-#undef realloc
-#endif /* USE_AXTLS */
-
-#if defined(USE_SCHANNEL) || defined(USE_WINDOWS_SSPI)
-#include "curl_sspi.h"
-#endif
-#ifdef USE_SCHANNEL
-#include <schnlsp.h>
-#include <schannel.h>
-#endif
-
-#ifdef USE_DARWINSSL
-#include <Security/Security.h>
-/* For some reason, when building for iOS, the omnibus header above does
- * not include SecureTransport.h as of iOS SDK 5.1. */
-#include <Security/SecureTransport.h>
-#endif
-
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
+#ifdef HAVE_NETINET_IN6_H
+#include <netinet/in6.h>
+#endif
#include "timeval.h"
-#ifdef HAVE_ZLIB_H
-#include <zlib.h> /* for content-encoding */
-#ifdef __SYMBIAN32__
-/* zlib pollutes the namespace with this definition */
-#undef WIN32
-#endif
-#endif
-
#include <curl/curl.h>
#include "http_chunks.h" /* for the structs and enum stuff */
@@ -172,6 +103,21 @@
#include "hash.h"
#include "splay.h"
+/* return the count of bytes sent, or -1 on error */
+typedef ssize_t (Curl_send)(struct connectdata *conn, /* connection data */
+ int sockindex, /* socketindex */
+ const void *buf, /* data to write */
+ size_t len, /* max amount to write */
+ CURLcode *err); /* error to return */
+
+/* return the count of bytes read, or -1 on error */
+typedef ssize_t (Curl_recv)(struct connectdata *conn, /* connection data */
+ int sockindex, /* socketindex */
+ char *buf, /* store data here */
+ size_t len, /* max amount to read */
+ CURLcode *err); /* error to return */
+
+#include "mime.h"
#include "imap.h"
#include "pop3.h"
#include "smtp.h"
@@ -187,12 +133,14 @@
#ifdef HAVE_GSSAPI
# ifdef HAVE_GSSGNU
# include <gss.h>
-# elif defined HAVE_GSSMIT
+# elif defined HAVE_GSSAPI_GSSAPI_H
# include <gssapi/gssapi.h>
-# include <gssapi/gssapi_generic.h>
# else
# include <gssapi.h>
# endif
+# ifdef HAVE_GSSAPI_GSSAPI_GENERIC_H
+# include <gssapi/gssapi_generic.h>
+# endif
#endif
#ifdef HAVE_LIBSSH2_H
@@ -200,13 +148,6 @@
#include <libssh2_sftp.h>
#endif /* HAVE_LIBSSH2_H */
-/* The upload buffer size, should not be smaller than CURL_MAX_WRITE_SIZE, as
- it needs to hold a full buffer as could be sent in a write callback */
-#define UPLOAD_BUFSIZE CURL_MAX_WRITE_SIZE
-
-/* The "master buffer" is for HTTP pipelining */
-#define MASTERBUF_SIZE 16384
-
/* Initial size of the buffer to store headers in, it'll be enlarged in case
of need. */
#define HEADERSIZE 256
@@ -215,10 +156,8 @@
#define GOOD_EASY_HANDLE(x) \
((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))
-/* Some convenience macros to get the larger/smaller value out of two given.
- We prefix with CURL to prevent name collisions. */
-#define CURLMAX(x,y) ((x)>(y)?(x):(y))
-#define CURLMIN(x,y) ((x)<(y)?(x):(y))
+/* the type we use for storing a single boolean bit */
+typedef unsigned int bit;
#ifdef HAVE_GSSAPI
/* Types needed for krb5-ftp connections */
@@ -226,7 +165,7 @@ struct krb5buffer {
void *data;
size_t size;
size_t index;
- int eof_flag;
+ bit eof_flag:1;
};
enum protection_level {
@@ -240,20 +179,6 @@ enum protection_level {
};
#endif
-#ifdef USE_SCHANNEL
-/* Structs to store Schannel handles */
-struct curl_schannel_cred {
- CredHandle cred_handle;
- TimeStamp time_stamp;
- int refcount;
-};
-
-struct curl_schannel_ctxt {
- CtxtHandle ctxt_handle;
- TimeStamp time_stamp;
-};
-#endif
-
/* enum for the nonblocking SSL connection state machine */
typedef enum {
ssl_connect_1,
@@ -270,128 +195,59 @@ typedef enum {
ssl_connection_complete
} ssl_connection_state;
+/* SSL backend-specific data; declared differently by each SSL backend */
+struct ssl_backend_data;
+
/* struct for data related to each SSL connection */
struct ssl_connect_data {
/* Use ssl encrypted communications TRUE/FALSE, not necessarily using it atm
but at least asked to or meaning to use it. See 'state' for the exact
current state of the connection. */
- bool use;
ssl_connection_state state;
ssl_connect_state connecting_state;
-#if defined(USE_OPENSSL)
- /* these ones requires specific SSL-types */
- SSL_CTX* ctx;
- SSL* handle;
- X509* server_cert;
-#elif defined(USE_GNUTLS)
- gnutls_session_t session;
- gnutls_certificate_credentials_t cred;
-#ifdef USE_TLS_SRP
- gnutls_srp_client_credentials_t srp_client_cred;
-#endif
-#elif defined(USE_MBEDTLS)
- mbedtls_ctr_drbg_context ctr_drbg;
- mbedtls_entropy_context entropy;
- mbedtls_ssl_context ssl;
- int server_fd;
- mbedtls_x509_crt cacert;
- mbedtls_x509_crt clicert;
- mbedtls_x509_crl crl;
- mbedtls_pk_context pk;
- mbedtls_ssl_config config;
- const char *protocols[3];
-#elif defined(USE_POLARSSL)
- ctr_drbg_context ctr_drbg;
- entropy_context entropy;
- ssl_context ssl;
- int server_fd;
- x509_crt cacert;
- x509_crt clicert;
- x509_crl crl;
- rsa_context rsa;
-#elif defined(USE_CYASSL)
- SSL_CTX* ctx;
- SSL* handle;
-#elif defined(USE_NSS)
- PRFileDesc *handle;
- char *client_nickname;
- struct Curl_easy *data;
- struct curl_llist obj_list;
- PK11GenericObject *obj_clicert;
-#elif defined(USE_GSKIT)
- gsk_handle handle;
- int iocport;
- int localfd;
- int remotefd;
-#elif defined(USE_AXTLS)
- SSL_CTX* ssl_ctx;
- SSL* ssl;
-#elif defined(USE_SCHANNEL)
- struct curl_schannel_cred *cred;
- struct curl_schannel_ctxt *ctxt;
- SecPkgContext_StreamSizes stream_sizes;
- size_t encdata_length, decdata_length;
- size_t encdata_offset, decdata_offset;
- unsigned char *encdata_buffer, *decdata_buffer;
- /* encdata_is_incomplete: if encdata contains only a partial record that
- can't be decrypted without another Curl_read_plain (that is, status is
- SEC_E_INCOMPLETE_MESSAGE) then set this true. after Curl_read_plain writes
- more bytes into encdata then set this back to false. */
- bool encdata_is_incomplete;
- unsigned long req_flags, ret_flags;
- CURLcode recv_unrecoverable_err; /* schannel_recv had an unrecoverable err */
- bool recv_sspi_close_notify; /* true if connection closed by close_notify */
- bool recv_connection_closed; /* true if connection closed, regardless how */
- bool use_alpn; /* true if ALPN is used for this connection */
-#elif defined(USE_DARWINSSL)
- SSLContextRef ssl_ctx;
- curl_socket_t ssl_sockfd;
- bool ssl_direction; /* true if writing, false if reading */
- size_t ssl_write_buffered_length;
-#elif defined(USE_SSL)
-#error "SSL backend specific information missing from ssl_connect_data"
+#if defined(USE_SSL)
+ struct ssl_backend_data *backend;
#endif
+ bit use:1;
};
struct ssl_primary_config {
long version; /* what version the client wants to use */
long version_max; /* max supported version the client wants to use*/
- bool verifypeer; /* set TRUE if this is desired */
- bool verifyhost; /* set TRUE if CN/SAN must match hostname */
- bool verifystatus; /* set TRUE if certificate status must be checked */
char *CApath; /* certificate dir (doesn't work on windows) */
char *CAfile; /* certificate to verify peer against */
char *clientcert;
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 */
- bool sessionid; /* cache session IDs or not */
+ char *cipher_list13; /* list of TLS 1.3 cipher suites to use */
+ bit verifypeer:1; /* set TRUE if this is desired */
+ bit verifyhost:1; /* set TRUE if CN/SAN must match hostname */
+ bit verifystatus:1; /* set TRUE if certificate status must be checked */
+ bit sessionid:1; /* cache session IDs or not */
};
struct ssl_config_data {
struct ssl_primary_config primary;
- bool enable_beast; /* especially allow this flaw for interoperability's
- sake*/
- bool no_revoke; /* disable SSL certificate revocation checks */
long certverifyresult; /* result from the certificate verification */
char *CRLfile; /* CRL to check certificate revocation */
char *issuercert;/* optional issuer certificate filename */
curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */
void *fsslctxp; /* parameter for call back */
- bool certinfo; /* gather lots of certificate info */
- bool falsestart;
-
char *cert; /* client certificate file name */
char *cert_type; /* format for certificate (default: PEM)*/
char *key; /* private key file name */
char *key_type; /* format for private key (default: PEM) */
char *key_passwd; /* plain text private key password */
-
#ifdef USE_TLS_SRP
char *username; /* TLS username (for, e.g., SRP) */
char *password; /* TLS password (for, e.g., SRP) */
enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */
#endif
+ bit certinfo:1; /* gather lots of certificate info */
+ bit falsestart:1;
+ bit enable_beast:1; /* allow this flaw for interoperability's sake*/
+ bit no_revoke:1; /* disable SSL certificate revocation checks */
};
struct ssl_general_config {
@@ -411,22 +267,31 @@ struct curl_ssl_session {
struct ssl_primary_config ssl_config; /* setup for this session */
};
+#ifdef USE_WINDOWS_SSPI
+#include "curl_sspi.h"
+#endif
+
/* Struct used for Digest challenge-response authentication */
struct digestdata {
#if defined(USE_WINDOWS_SSPI)
BYTE *input_token;
size_t input_token_len;
CtxtHandle *http_context;
+ /* copy of user/passwd used to make the identity for http_context.
+ either may be NULL. */
+ char *user;
+ char *passwd;
#else
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 */
+ bit stale:1; /* set true for re-negotiation */
+ bit userhash:1;
#endif
};
@@ -438,9 +303,13 @@ typedef enum {
NTLMSTATE_LAST
} curlntlm;
-#ifdef USE_WINDOWS_SSPI
-#include "curl_sspi.h"
-#endif
+typedef enum {
+ GSS_AUTHNONE,
+ GSS_AUTHRECV,
+ GSS_AUTHSENT,
+ GSS_AUTHDONE,
+ GSS_AUTHSUCC
+} curlnegotiate;
#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
#include <iconv.h>
@@ -467,8 +336,13 @@ struct kerberos5data {
/* Struct used for NTLM challenge-response authentication */
#if defined(USE_NTLM)
struct ntlmdata {
- curlntlm state;
#ifdef USE_WINDOWS_SSPI
+/* The sslContext is used for the Schannel bindings. The
+ * api is available on the Windows 7 SDK and later.
+ */
+#ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
+ CtxtHandle *sslContext;
+#endif
CredHandle *credentials;
CtxtHandle *context;
SEC_WINNT_AUTH_IDENTITY identity;
@@ -477,6 +351,7 @@ struct ntlmdata {
BYTE *output_token;
BYTE *input_token;
size_t input_token_len;
+ TCHAR *spn;
#else
unsigned int flags;
unsigned char nonce[8];
@@ -486,11 +361,9 @@ struct ntlmdata {
};
#endif
+/* Struct used for Negotiate (SPNEGO) authentication */
#ifdef USE_SPNEGO
struct negotiatedata {
- /* When doing Negotiate (SPNEGO) auth, we first need to send a token
- and then validate the received one. */
- enum { GSS_AUTHNONE, GSS_AUTHRECV, GSS_AUTHSENT } state;
#ifdef HAVE_GSSAPI
OM_uint32 status;
gss_ctx_id_t context;
@@ -498,6 +371,9 @@ struct negotiatedata {
gss_buffer_desc output_token;
#else
#ifdef USE_WINDOWS_SSPI
+#ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
+ CtxtHandle *sslContext;
+#endif
DWORD status;
CredHandle *credentials;
CtxtHandle *context;
@@ -509,6 +385,10 @@ struct negotiatedata {
size_t output_token_length;
#endif
#endif
+ bool noauthpersist;
+ bool havenoauthpersist;
+ bool havenegdata;
+ bool havemultiplerequests;
};
#endif
@@ -518,69 +398,67 @@ struct negotiatedata {
*/
struct ConnectBits {
/* always modify bits.close with the connclose() and connkeep() macros! */
- bool close; /* if set, we close the connection after this request */
- bool reuse; /* if set, this is a re-used connection */
- bool conn_to_host; /* if set, this connection has a "connect to host"
- that overrides the host in the URL */
- bool conn_to_port; /* if set, this connection has a "connect to port"
- that overrides the port in the URL (remote port) */
- bool proxy; /* if set, this transfer is done through a proxy - any type */
- bool httpproxy; /* if set, this transfer is done through a http proxy */
- bool socksproxy; /* if set, this transfer is done through a socks 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 tcpconnect[2]; /* the TCP layer (or similar) 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 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 ftp_use_data_ssl; /* Enabled SSL for the data connection */
- bool netrc; /* name+password provided by netrc */
- bool userpwd_in_url; /* name+password found in url */
- 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. */
- bool bound; /* set true if bind() has already been done on this socket/
- connection */
- bool type_set; /* type= was used in the URL */
- bool multiplex; /* connection is multiplexed */
-
- bool tcp_fastopen; /* use TCP Fast Open */
- bool tls_enable_npn; /* TLS NPN extension? */
- bool tls_enable_alpn; /* TLS ALPN extension? */
bool proxy_ssl_connected[2]; /* TRUE when SSL initialization for HTTPS proxy
is complete */
- bool socksproxy_connecting; /* connecting through a socks proxy */
+ bool tcpconnect[2]; /* the TCP layer (or similar) is connected, this is set
+ the first time on the first connect function call */
+ bit close:1; /* if set, we close the connection after this request */
+ bit reuse:1; /* if set, this is a re-used connection */
+ bit conn_to_host:1; /* if set, this connection has a "connect to host"
+ that overrides the host in the URL */
+ bit conn_to_port:1; /* if set, this connection has a "connect to port"
+ that overrides the port in the URL (remote port) */
+ bit proxy:1; /* if set, this transfer is done through a proxy - any type */
+ bit httpproxy:1; /* if set, this transfer is done through a http proxy */
+ bit socksproxy:1; /* if set, this transfer is done through a socks proxy */
+ bit user_passwd:1; /* do we use user+password for this connection? */
+ bit proxy_user_passwd:1; /* user+password for the proxy? */
+ bit ipv6_ip:1; /* we communicate with a remote site specified with pure IPv6
+ IP address */
+ bit ipv6:1; /* we communicate with a site using an IPv6 address */
+ bit do_more:1; /* this is set TRUE if the ->curl_do_more() function is
+ supposed to be called, after ->curl_do() */
+ bit protoconnstart:1;/* the protocol layer has STARTED its operation after
+ the TCP layer connect */
+ bit retry:1; /* this connection is about to get closed and then
+ re-attempted at another connection. */
+ bit tunnel_proxy:1; /* 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 */
+ bit authneg:1; /* 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. */
+ bit rewindaftersend:1;/* 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. */
+#ifndef CURL_DISABLE_FTP
+ bit ftp_use_epsv:1; /* As set with CURLOPT_FTP_USE_EPSV, but if we find out
+ EPSV doesn't work we disable it for the forthcoming
+ requests */
+ bit ftp_use_eprt:1; /* As set with CURLOPT_FTP_USE_EPRT, but if we find out
+ EPRT doesn't work we disable it for the forthcoming
+ requests */
+ bit ftp_use_data_ssl:1; /* Enabled SSL for the data connection */
+#endif
+ bit netrc:1; /* name+password provided by netrc */
+ bit userpwd_in_url:1; /* name+password found in url */
+ bit stream_was_rewound:1; /* The stream was rewound after a request read
+ past the end of its response byte boundary */
+ bit proxy_connect_closed:1; /* TRUE if a proxy disconnected the connection
+ in a CONNECT request with auth, so that
+ libcurl should reconnect and continue. */
+ bit bound:1; /* set true if bind() has already been done on this socket/
+ connection */
+ bit type_set:1; /* type= was used in the URL */
+ bit multiplex:1; /* connection is multiplexed */
+ bit tcp_fastopen:1; /* use TCP Fast Open */
+ bit tls_enable_npn:1; /* TLS NPN extension? */
+ bit tls_enable_alpn:1; /* TLS ALPN extension? */
+ bit socksproxy_connecting:1; /* connecting through a socks proxy */
+ bit connect_only:1;
};
struct hostname {
@@ -607,27 +485,14 @@ struct hostname {
#define KEEP_RECVBITS (KEEP_RECV | KEEP_RECV_HOLD | KEEP_RECV_PAUSE)
#define KEEP_SENDBITS (KEEP_SEND | KEEP_SEND_HOLD | KEEP_SEND_PAUSE)
-
-#ifdef HAVE_LIBZ
-typedef enum {
- 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 */
-} zlibInitState;
-#endif
-
-#ifdef CURLRES_ASYNCH
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 */
+ bit done:1; /* set TRUE when the lookup is complete */
};
-#endif
#define FIRSTSOCKET 0
#define SECONDARYSOCKET 1
@@ -653,6 +518,28 @@ enum upgrade101 {
UPGR101_WORKING /* talking upgraded protocol */
};
+struct dohresponse {
+ unsigned char *memory;
+ size_t size;
+};
+
+/* one of these for each DoH request */
+struct dnsprobe {
+ CURL *easy;
+ int dnstype;
+ unsigned char dohbuffer[512];
+ size_t dohlen;
+ struct dohresponse serverdoh;
+};
+
+struct dohdata {
+ struct curl_slist *headers;
+ struct dnsprobe probe[2];
+ unsigned int pending; /* still outstanding requests */
+ const char *host;
+ int port;
+};
+
/*
* Request specific data in the easy handle (Curl_easy). Previously,
* these members were on the connectdata struct but since a conn struct may
@@ -662,25 +549,21 @@ enum upgrade101 {
*/
struct SingleRequest {
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,
-1 means unlimited */
- curl_off_t *writebytecountp; /* return number of bytes written or NULL */
-
curl_off_t bytecount; /* total number of bytes read */
curl_off_t writebytecount; /* number of bytes written */
- long headerbytecount; /* only count received headers */
- long deductheadercount; /* this amount of bytes doesn't count when we check
- if anything has been transferred 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 */
+ curl_off_t headerbytecount; /* only count received headers */
+ curl_off_t deductheadercount; /* this amount of bytes doesn't count when we
+ check if anything has been transferred 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 */
- struct timeval start; /* transfer started at this time */
- struct timeval now; /* current time */
- bool header; /* incoming data has HTTP header */
+ struct curltime start; /* transfer started at this time */
+ struct curltime now; /* current time */
enum {
HEADER_NORMAL, /* no bad header at all */
HEADER_PARTHEADER, /* part of the chunk is a bad header, the rest
@@ -696,42 +579,20 @@ struct SingleRequest {
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' or
'RTSP/1.? XXX' line */
- struct timeval start100; /* time stamp to wait for the 100 code from */
+ struct curltime start100; /* time stamp to wait for the 100 code from */
enum expect100 exp100; /* expect 100 continue state */
enum upgrade101 upgr101; /* 101 upgrade state */
- int auto_decoding; /* What content encoding. sec 3.5, RFC2616. */
-
-#define IDENTITY 0 /* No encoding */
-#define DEFLATE 1 /* zlib deflate [RFC 1950 & 1951] */
-#define GZIP 2 /* gzip algorithm [RFC 1952] */
-
-#ifdef HAVE_LIBZ
- zlibInitState zlib_init; /* possible zlib init state;
- undefined if Content-Encoding header. */
- z_stream z; /* State structure for zlib. */
-#endif
-
+ struct contenc_writer_s *writer_stack; /* Content unencoding stack. */
+ /* See sec 3.5, RFC2616. */
time_t timeofdoc;
long bodywrites;
-
char *buf;
- 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 */
-
char *location; /* This points to an allocated version of the Location:
header data */
char *newurl; /* Set to the new URL to use when a redirect or a retry is
@@ -741,23 +602,30 @@ struct SingleRequest {
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 */
+ /* '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;
-
- bool chunk; /* if set, this is a chunked transfer-encoding */
- 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. */
-
void *protop; /* Allocated protocol-specific data. Each protocol
handler makes sure this points to data it needs. */
+#ifndef CURL_DISABLE_DOH
+ struct dohdata doh; /* DoH specific data for this request */
+#endif
+ bit header:1; /* incoming data has HTTP header */
+ bit content_range:1; /* set TRUE if Content-Range: was found */
+ bit upload_done:1; /* set to TRUE when doing chunked transfer-encoding
+ upload and we're uploading the last chunk */
+ bit ignorebody:1; /* we read a response-body but we ignore it! */
+ bit ignorecl:1; /* This HTTP response has no body so we ignore the
+ Content-Length: header */
+ bit chunk:1; /* if set, this is a chunked transfer-encoding */
+ bit upload_chunky:1; /* set TRUE if we are doing chunked transfer-encoding
+ on upload */
+ bit getheader:1; /* TRUE if header parsing is wanted */
+ bit forbidchunk:1; /* used only to explicitly forbid chunk-upload for
+ specific upload buffers. See readmoredata() in http.c
+ for details. */
};
/*
@@ -788,7 +656,7 @@ struct Curl_handler {
*/
CURLcode (*connect_it)(struct connectdata *, bool *done);
- /* See above. Currently only used for FTP. */
+ /* See above. */
CURLcode (*connecting)(struct connectdata *, bool *done);
CURLcode (*doing)(struct connectdata *, bool *done);
@@ -829,6 +697,12 @@ struct Curl_handler {
CURLcode (*readwrite)(struct Curl_easy *data, struct connectdata *conn,
ssize_t *nread, bool *readmore);
+ /* This function can perform various checks on the connection. See
+ CONNCHECK_* for more information about the checks that can be performed,
+ and CONNRESULT_* for the results that can be returned. */
+ unsigned int (*connection_check)(struct connectdata *conn,
+ unsigned int checks_to_perform);
+
long defport; /* Default port. */
unsigned int protocol; /* See CURLPROTO_* - this needs to be the single
specific protocol bit */
@@ -855,20 +729,17 @@ struct Curl_handler {
#define PROTOPT_STREAM (1<<9) /* a protocol with individual logical streams */
#define PROTOPT_URLOPTIONS (1<<10) /* allow options part in the userinfo field
of the URL */
+#define PROTOPT_PROXY_AS_HTTP (1<<11) /* allow this non-HTTP scheme over a
+ HTTP proxy as HTTP proxies may know
+ this protocol and act as a gateway */
+#define PROTOPT_WILDCARD (1<<12) /* protocol supports wildcard matching */
-/* return the count of bytes sent, or -1 on error */
-typedef ssize_t (Curl_send)(struct connectdata *conn, /* connection data */
- int sockindex, /* socketindex */
- const void *buf, /* data to write */
- size_t len, /* max amount to write */
- CURLcode *err); /* error to return */
+#define CONNCHECK_NONE 0 /* No checks */
+#define CONNCHECK_ISDEAD (1<<0) /* Check if the connection is dead. */
+#define CONNCHECK_KEEPALIVE (1<<1) /* Perform any keepalive function. */
-/* return the count of bytes read, or -1 on error */
-typedef ssize_t (Curl_recv)(struct connectdata *conn, /* connection data */
- int sockindex, /* socketindex */
- char *buf, /* store data here */
- size_t len, /* max amount to read */
- CURLcode *err); /* error to return */
+#define CONNRESULT_NONE 0 /* No extra information. */
+#define CONNRESULT_DEAD (1<<0) /* The connection is dead. */
#ifdef USE_RECV_BEFORE_SEND_WORKAROUND
struct postponed_data {
@@ -892,6 +763,25 @@ struct proxy_info {
char *passwd; /* proxy password string, allocated */
};
+#define CONNECT_BUFFER_SIZE 16384
+
+/* struct for HTTP CONNECT state data */
+struct http_connect_state {
+ char connect_buffer[CONNECT_BUFFER_SIZE];
+ int perline; /* count bytes per line */
+ int keepon;
+ char *line_start;
+ char *ptr; /* where to store more data */
+ curl_off_t cl; /* size of content to read and ignore */
+ enum {
+ TUNNEL_INIT, /* init/default/no tunnel state */
+ TUNNEL_CONNECT, /* CONNECT has been sent off */
+ TUNNEL_COMPLETE /* CONNECT response received completely */
+ } tunnel_state;
+ bit chunked_encoding:1;
+ bit close_connection:1;
+};
+
/*
* The connectdata struct contains all fields and variables that should be
* unique for an entire connection.
@@ -912,10 +802,11 @@ struct connectdata {
curl_closesocket_callback fclosesocket; /* function closing the socket(s) */
void *closesocket_client;
- 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). */
+ /* This is used by the connection cache logic. If this returns TRUE, this
+ handle is still used by one or more easy handles and can only used by any
+ other easy handle without careful consideration (== only for
+ multiplexing) and it cannot be used by another multi handle! */
+#define CONN_INUSE(c) ((c)->easyq.size)
/**** Fields set when inited and not modified again */
long connection_id; /* Contains a unique number to make it easier to
@@ -943,6 +834,7 @@ struct connectdata {
int socktype; /* SOCK_STREAM or SOCK_DGRAM */
struct hostname host;
+ char *hostname_resolve; /* host name to resolve to address, allocated */
char *secondaryhostname; /* secondary socket host name (ftp) */
struct hostname conn_to_host; /* the host to connect to. valid only if
bits.conn_to_host is set */
@@ -983,8 +875,9 @@ struct connectdata {
int httpversion; /* the HTTP version*10 reported by the server */
int rtspversion; /* the RTSP version*10 reported by the server */
- struct timeval now; /* "current" time */
- struct timeval created; /* creation time */
+ struct curltime now; /* "current" time */
+ struct curltime created; /* creation time */
+ struct curltime lastused; /* when returned to the connection cache */
curl_socket_t sock[2]; /* two sockets, the second is used for the data
transfer when doing FTP */
curl_socket_t tempsock[2]; /* temporary sockets for happy eyeballs */
@@ -998,16 +891,17 @@ struct connectdata {
#endif /* USE_RECV_BEFORE_SEND_WORKAROUND */
struct ssl_connect_data ssl[2]; /* this is for ssl-stuff */
struct ssl_connect_data proxy_ssl[2]; /* this is for proxy ssl-stuff */
+#ifdef USE_SSL
+ void *ssl_extra; /* separately allocated backend-specific data */
+#endif
struct ssl_primary_config ssl_config;
struct ssl_primary_config proxy_ssl_config;
- bool tls_upgraded;
-
struct ConnectBits bits; /* various state-flags for this connection */
/* connecttime: when connect() is called on the current IP address. Used to
be able to track when to move on to try next IP - but only when the multi
interface is used. */
- struct timeval connecttime;
+ struct curltime connecttime;
/* The two fields below get set in Curl_connecthost */
int num_addr; /* number of addresses to try to connect to */
time_t timeoutms_per_addr; /* how long time in milliseconds to spend on
@@ -1018,6 +912,13 @@ struct connectdata {
long ip_version; /* copied from the Curl_easy at creation time */
+ /* Protocols can use a custom keepalive mechanism to keep connections alive.
+ This allows those protocols to track the last time the keepalive mechanism
+ was used on this connection. */
+ struct curltime keepalive;
+
+ long upkeep_interval_ms; /* Time between calls for connection upkeep. */
+
/**** curl_get() phase fields */
curl_socket_t sockfd; /* socket to read from or CURL_SOCKET_BAD */
@@ -1025,7 +926,7 @@ struct connectdata {
well be the same we read from.
CURL_SOCKET_BAD disables */
- /** Dynamicly allocated strings, MUST be freed before this **/
+ /** Dynamically allocated strings, MUST be freed before this **/
/** struct is killed. **/
struct dynamically_allocated_data {
char *proxyuserpwd;
@@ -1041,7 +942,7 @@ struct connectdata {
} allocptr;
#ifdef HAVE_GSSAPI
- int sec_complete; /* if Kerberos is enabled for this connection */
+ bit sec_complete:1; /* if Kerberos is enabled for this connection */
enum protection_level command_prot;
enum protection_level data_prot;
enum protection_level request_data_prot;
@@ -1056,30 +957,19 @@ struct connectdata {
struct kerberos5data krb5; /* variables into the structure definition, */
#endif /* however, some of them are ftp specific. */
- /* the two following *_inuse fields are only flags, not counters in any way.
- If TRUE it means the channel is in use, and if FALSE it means the channel
- is up for grabs by one. */
-
- 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 */
- 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; /* The master buffer allocated on-demand;
- used for pipelining. */
- size_t read_pos; /* Current read position in the master buffer */
- size_t buf_len; /* Length of the buffer?? */
-
-
+ struct curl_llist easyq; /* List of easy handles using this connection */
curl_seek_callback seek_func; /* function that seeks the input */
void *seek_client; /* pointer to pass to the seek() above */
/*************** Request - specific items ************/
+#if defined(USE_WINDOWS_SSPI) && defined(SECPKG_ATTR_ENDPOINT_BINDINGS)
+ CtxtHandle *sslContext;
+#endif
#if defined(USE_NTLM)
+ curlntlm http_ntlm_state;
+ curlntlm proxy_ntlm_state;
+
struct ntlmdata ntlm; /* NTLM differs from other authentication schemes
because it authenticates connections, not
single requests! */
@@ -1094,12 +984,16 @@ struct connectdata {
#endif
#endif
- char syserr_buf [256]; /* buffer for Curl_strerror() */
+#ifdef USE_SPNEGO
+ curlnegotiate http_negotiate_state;
+ curlnegotiate proxy_negotiate_state;
+
+ struct negotiatedata negotiate; /* state data for host Negotiate auth */
+ struct negotiatedata proxyneg; /* state data for proxy Negotiate auth */
+#endif
-#ifdef CURLRES_ASYNCH
/* 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 */
@@ -1134,22 +1028,22 @@ struct connectdata {
char *localdev;
unsigned short localport;
int localportrange;
-
- /* tunnel as in tunnel through a HTTP proxy with CONNECT */
- enum {
- TUNNEL_INIT, /* init/default/no tunnel state */
- TUNNEL_CONNECT, /* CONNECT has been sent off */
- TUNNEL_COMPLETE /* CONNECT response received completely */
- } tunnel_state[2]; /* two separate ones to allow FTP */
+ struct http_connect_state *connect_state; /* for HTTP CONNECT */
struct connectbundle *bundle; /* The bundle we are member of */
-
int negnpn; /* APLN or NPN TLS negotiated protocol, CURL_HTTP_VERSION* */
- char *connect_buffer; /* for CONNECT business */
#ifdef USE_UNIX_SOCKETS
char *unix_domain_socket;
- bool abstract_unix_socket;
+ bit abstract_unix_socket:1;
#endif
+ bit tls_upgraded:1;
+ /* the two following *_inuse fields are only flags, not counters in any way.
+ If TRUE it means the channel is in use, and if FALSE it means the channel
+ is up for grabs by one. */
+ bit readchannel_inuse:1; /* whether the read channel is in use by an easy
+ handle */
+ bit writechannel_inuse:1; /* whether the write channel is in use by an easy
+ handle */
};
/* The end of connectdata. */
@@ -1162,14 +1056,10 @@ struct PureInfo {
int httpcode; /* Recent HTTP, FTP, RTSP or SMTP response code */
int httpproxycode; /* response code from proxy when received separate */
int httpversion; /* the http version number X.Y = X*10+Y */
- 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. */
- bool timecond; /* set to TRUE if the time condition didn't match, which
- thus made the document NOT get fetched */
- long header_size; /* size of read header(s) in bytes */
- long request_size; /* the amount of bytes sent in the request(s) */
+ time_t filetime; /* If requested, this is might get set. Set to -1 if the
+ time was unretrievable. */
+ curl_off_t header_size; /* size of read header(s) in bytes */
+ curl_off_t request_size; /* the amount of bytes sent in the request(s) */
unsigned long proxyauthavail; /* what proxy auth types were announced */
unsigned long httpauthavail; /* what host auth types were announced */
long numconnects; /* how many new connection did libcurl created */
@@ -1186,16 +1076,16 @@ struct PureInfo {
char conn_primary_ip[MAX_IPADR_LEN];
long conn_primary_port;
-
char conn_local_ip[MAX_IPADR_LEN];
long conn_local_port;
-
const char *conn_scheme;
unsigned int conn_protocol;
-
struct curl_certinfo certs; /* info about the certs, only populated in
OpenSSL builds. Asked for with
CURLOPT_CERTINFO / CURLINFO_CERTINFO */
+
+ bit timecond:1; /* set to TRUE if the time condition didn't match, which
+ thus made the document NOT get fetched */
};
@@ -1209,39 +1099,41 @@ struct Progress {
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;
+ time_t timespent;
curl_off_t dlspeed;
curl_off_t ulspeed;
- double t_nslookup;
- double t_connect;
- double t_appconnect;
- double t_pretransfer;
- double t_starttransfer;
- double t_redirect;
+ time_t t_nslookup;
+ time_t t_connect;
+ time_t t_appconnect;
+ time_t t_pretransfer;
+ time_t t_starttransfer;
+ time_t t_redirect;
+
+ struct curltime start;
+ struct curltime t_startsingle;
+ struct curltime t_startop;
+ struct curltime t_acceptdata;
- struct timeval start;
- struct timeval t_startsingle;
- struct timeval t_startop;
- struct timeval t_acceptdata;
/* upload speed limit */
- struct timeval ul_limit_start;
+ struct curltime ul_limit_start;
curl_off_t ul_limit_size;
/* download speed limit */
- struct timeval dl_limit_start;
+ struct curltime dl_limit_start;
curl_off_t dl_limit_size;
-#define CURR_TIME (5+1) /* 6 entries for 5 seconds */
+#define CURR_TIME (5 + 1) /* 6 entries for 5 seconds */
curl_off_t speeder[ CURR_TIME ];
- struct timeval speeder_time[ CURR_TIME ];
+ struct curltime speeder_time[ CURR_TIME ];
int speeder_c;
+ bit callback:1; /* set when progress callback is used */
+ bit is_t_startransfer_set:1;
};
typedef enum {
@@ -1249,9 +1141,10 @@ typedef enum {
HTTPREQ_GET,
HTTPREQ_POST,
HTTPREQ_POST_FORM, /* we make a difference internally */
+ HTTPREQ_POST_MIME, /* we make a difference internally */
HTTPREQ_PUT,
HTTPREQ_HEAD,
- HTTPREQ_CUSTOM,
+ HTTPREQ_OPTIONS,
HTTPREQ_LAST /* last in list */
} Curl_HttpReq;
@@ -1288,12 +1181,12 @@ struct auth {
unsigned long picked;
unsigned 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 multipass; /* TRUE if this is not yet authenticated but within the
- auth multipass negotiation */
- bool iestyle; /* TRUE if digest should be done IE-style or FALSE if it should
- be RFC compliant */
+ bit done:1; /* TRUE when the auth phase is done and ready to do the
+ *actual* request */
+ bit multipass:1; /* TRUE if this is not yet authenticated but within the
+ auth multipass negotiation */
+ bit iestyle:1; /* TRUE if digest should be done IE-style or FALSE if it
+ should be RFC compliant */
};
struct Curl_http2_dep {
@@ -1302,7 +1195,7 @@ struct Curl_http2_dep {
};
/*
- * This struct is for holding data that was attemped to get sent to the user's
+ * This struct is for holding data that was attempted to get sent to the user's
* callback but is held due to pausing. One instance per type (BOTH, HEADER,
* BODY).
*/
@@ -1320,6 +1213,7 @@ typedef enum {
EXPIRE_ASYNC_NAME,
EXPIRE_CONNECTTIMEOUT,
EXPIRE_DNS_PER_NAME,
+ EXPIRE_HAPPY_EYEBALLS_DNS, /* See asyn-ares.c */
EXPIRE_HAPPY_EYEBALLS,
EXPIRE_MULTI_PENDING,
EXPIRE_RUN_NOW,
@@ -1329,27 +1223,43 @@ typedef enum {
EXPIRE_LAST /* not an actual timer, used as a marker only */
} expire_id;
+
+typedef enum {
+ TRAILERS_NONE,
+ TRAILERS_INITIALIZED,
+ TRAILERS_SENDING,
+ TRAILERS_DONE
+} trailers_state;
+
+
/*
* One instance for each timeout an easy handle can set.
*/
struct time_node {
struct curl_llist_element list;
- struct timeval time;
+ struct curltime time;
expire_id eid;
};
+/* individual pieces of the URL */
+struct urlpieces {
+ char *scheme;
+ char *hostname;
+ char *port;
+ char *user;
+ char *password;
+ char *options;
+ char *path;
+ char *query;
+};
+
struct UrlState {
/* Points to the connection cache */
struct conncache *conn_cache;
- /* when curl_easy_perform() is called, the multi handle is "owned" by
- the easy handle so curl_easy_cleanup() on such an easy handle will
- also close the multi handle! */
- bool multi_owned_by_easy;
-
/* buffers to store authentication data in, as parsed from input options */
- struct timeval keeps_speed; /* for the progress meter really */
+ struct curltime keeps_speed; /* for the progress meter really */
struct connectdata *lastconnect; /* The last connection, NULL if undefined */
@@ -1357,11 +1267,9 @@ struct UrlState {
size_t headersize; /* size of the allocation */
char *buffer; /* download buffer */
- char uploadbuffer[UPLOAD_BUFSIZE+1]; /* upload buffer */
+ char *ulbuf; /* allocated upload buffer or NULL */
curl_off_t current_speed; /* the ProgressShow() function sets this,
bytes / second */
- bool this_is_a_follow; /* this is a followed Location: request */
-
char *first_host; /* host name of the first (not followed) request.
if set, this should be the host name that we will
sent authorization to, no else. Used to make Location:
@@ -1374,36 +1282,24 @@ struct UrlState {
unsigned int tempcount; /* number of entries in use in tempwrite, 0 - 3 */
struct tempbuf tempwrite[3]; /* BOTH, HEADER, BODY */
char *scratch; /* huge buffer[set.buffer_size*2] for 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; /* state data for host Digest auth */
struct digestdata proxydigest; /* state data for proxy Digest auth */
-#ifdef USE_SPNEGO
- struct negotiatedata negotiate; /* state data for host Negotiate auth */
- struct negotiatedata proxyneg; /* state data for proxy Negotiate auth */
-#endif
-
struct auth authhost; /* auth details for host */
struct auth authproxy; /* auth details for proxy */
-
- bool authproblem; /* TRUE if there's some problem authenticating */
-
void *resolver; /* resolver state, if it is used in the URL state -
ares_channel f.e. */
-#if defined(USE_OPENSSL) && defined(HAVE_OPENSSL_ENGINE_H)
- ENGINE *engine;
+#if defined(USE_OPENSSL)
+ /* void instead of ENGINE to avoid bleeding OpenSSL into this header */
+ void *engine;
#endif /* USE_OPENSSL */
- struct timeval expiretime; /* set this with Curl_expire() only */
+ struct curltime expiretime; /* set this with Curl_expire() only */
struct Curl_tree timenode; /* for the splay stuff */
struct curl_llist timeoutlist; /* list of pending timeouts */
struct time_node expires[EXPIRE_LAST]; /* nodes for each expire type */
@@ -1411,33 +1307,18 @@ struct UrlState {
/* a place to store the most recently set FTP entrypath */
char *most_recent_ftp_entrypath;
- /* set after initial USER failure, to prevent an authentication loop */
- bool ftp_trying_alternative;
-
int httpversion; /* the lowest HTTP version*10 reported by any server
involved in this request */
- 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 */
#if !defined(WIN32) && !defined(MSDOS) && !defined(__EMX__) && \
!defined(__SYMBIAN32__)
/* 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;
+ bit prev_block_had_trailing_cr:1;
/* for FTP downloads: how many CRLFs did we converted to LFs? */
curl_off_t crlf_conversions;
#endif
- char *pathbuffer;/* allocated buffer to store the URL's path part in */
- char *path; /* path to use, points to somewhere within the pathbuffer
- area */
- bool slash_removed; /* set TRUE if the 'path' points to a path where the
- initial URL slash separator has been taken off */
- 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 */
@@ -1453,16 +1334,48 @@ struct UrlState {
size_t drain; /* Increased when this stream has data to read, even if its
socket is not necessarily is readable. Decreased when
checked. */
- bool done; /* set to FALSE when Curl_init_do() is called and set to TRUE
- when multi_done() is called, to prevent multi_done() to get
- invoked twice when the multi interface is used. */
curl_read_callback fread_func; /* read callback/function */
void *in; /* CURLOPT_READDATA */
struct Curl_easy *stream_depends_on;
- bool stream_depends_e; /* set or don't set the Exclusive bit */
int stream_weight;
+ CURLU *uh; /* URL handle for the current parsed URL */
+ struct urlpieces up;
+#ifndef CURL_DISABLE_HTTP
+ size_t trailers_bytes_sent;
+ Curl_send_buffer *trailers_buf; /* a buffer containing the compiled trailing
+ headers */
+#endif
+ trailers_state trailers_state; /* whether we are sending trailers
+ and what stage are we at */
+#ifdef CURLDEBUG
+ bit conncache_lock:1;
+#endif
+ /* when curl_easy_perform() is called, the multi handle is "owned" by
+ the easy handle so curl_easy_cleanup() on such an easy handle will
+ also close the multi handle! */
+ bit multi_owned_by_easy:1;
+
+ bit this_is_a_follow:1; /* this is a followed Location: request */
+ bit refused_stream:1; /* this was refused, try again */
+ bit errorbuf:1; /* Set to TRUE if the error buffer is already filled in.
+ This must be set to FALSE every time _easy_perform() is
+ called. */
+ bit allow_port:1; /* Is set.use_port allowed to take effect or not. This
+ is always set TRUE when curl_easy_perform() is called. */
+ bit authproblem:1; /* TRUE if there's some problem authenticating */
+ /* set after initial USER failure, to prevent an authentication loop */
+ bit ftp_trying_alternative:1;
+ bit wildcardmatch:1; /* enable wildcard matching */
+ bit expect100header:1; /* TRUE if we added Expect: 100-continue */
+ bit use_range:1;
+ bit rangestringalloc:1; /* the range string is malloc()'ed */
+ bit done:1; /* set to FALSE when Curl_init_do() is called and set to TRUE
+ when multi_done() is called, to prevent multi_done() to get
+ invoked twice when the multi interface is used. */
+ bit stream_depends_e:1; /* set or don't set the Exclusive bit */
+ bit previouslypending:1; /* this transfer WAS in the multi->pending queue */
};
@@ -1475,13 +1388,15 @@ struct UrlState {
struct DynamicStatic {
char *url; /* work URL, copied from UserDefined */
- bool url_alloc; /* URL string is malloc()'ed */
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 */
struct curl_slist *resolve; /* set to point to the set.resolve list when
this should be dealt with in pretransfer */
+ bit url_alloc:1; /* URL string is malloc()'ed */
+ bit referer_alloc:1; /* referer string is malloc()ed */
+ bit wildcard_resolve:1; /* Set to true if any resolve change is a
+ wildcard */
};
/*
@@ -1531,6 +1446,8 @@ enum dupstring {
STRING_SSL_PINNEDPUBLICKEY_PROXY, /* public key file to verify proxy */
STRING_SSL_CIPHER_LIST_ORIG, /* list of ciphers to use */
STRING_SSL_CIPHER_LIST_PROXY, /* list of ciphers to use */
+ STRING_SSL_CIPHER13_LIST_ORIG, /* list of TLS 1.3 ciphers to use */
+ STRING_SSL_CIPHER13_LIST_PROXY, /* list of TLS 1.3 ciphers to use */
STRING_SSL_EGDSOCKET, /* path to file containing the EGD daemon socket */
STRING_SSL_RANDOM_FILE, /* path to file containing "random" data */
STRING_USERAGENT, /* User-Agent string */
@@ -1538,6 +1455,7 @@ enum dupstring {
STRING_SSL_CRLFILE_PROXY, /* crl file to check certificate */
STRING_SSL_ISSUERCERT_ORIG, /* issuer cert file to check certificate */
STRING_SSL_ISSUERCERT_PROXY, /* issuer cert file to check certificate */
+ STRING_SSL_ENGINE, /* name of ssl engine */
STRING_USERNAME, /* <username>, if used */
STRING_PASSWORD, /* <password>, if used */
STRING_OPTIONS, /* <options>, if used */
@@ -1548,19 +1466,14 @@ enum dupstring {
STRING_RTSP_SESSION_ID, /* Session ID to use */
STRING_RTSP_STREAM_URI, /* Stream URI for this request */
STRING_RTSP_TRANSPORT, /* Transport for this session */
-#ifdef USE_LIBSSH2
+#ifdef USE_SSH
STRING_SSH_PRIVATE_KEY, /* path to the private key file for auth */
STRING_SSH_PUBLIC_KEY, /* path to the public key file for auth */
STRING_SSH_HOST_PUBLIC_KEY_MD5, /* md5 of host public key in ascii hex */
STRING_SSH_KNOWNHOSTS, /* file name of knownhosts file */
#endif
-#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
STRING_PROXY_SERVICE_NAME, /* Proxy service name */
-#endif
-#if !defined(CURL_DISABLE_CRYPTO_AUTH) || defined(USE_KERBEROS5) || \
- defined(USE_SPNEGO)
STRING_SERVICE_NAME, /* Service name */
-#endif
STRING_MAIL_FROM,
STRING_MAIL_AUTH,
@@ -1574,19 +1487,27 @@ enum dupstring {
#ifdef USE_UNIX_SOCKETS
STRING_UNIX_SOCKET_PATH, /* path to Unix socket, if used */
#endif
-
+ STRING_TARGET, /* CURLOPT_REQUEST_TARGET */
+ STRING_DOH, /* CURLOPT_DOH_URL */
+#ifdef USE_ALTSVC
+ STRING_ALTSVC, /* CURLOPT_ALTSVC */
+#endif
/* -- end of zero-terminated strings -- */
STRING_LASTZEROTERMINATED,
- /* -- below this are pointers to binary data that cannot be strdup'ed.
- Each such pointer must be added manually to Curl_dupset() --- */
+ /* -- below this are pointers to binary data that cannot be strdup'ed. --- */
STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */
STRING_LAST /* not used, just an end-of-list marker */
};
+/* callback that gets called when this easy handle is completed within a multi
+ handle. Only used for internally created transfers, like for example
+ DoH. */
+typedef int (*multidone_func)(struct Curl_easy *easy, CURLcode result);
+
struct UserDefined {
FILE *err; /* the stderr user data goes here */
void *debugdata; /* the data that will be passed to fdebug */
@@ -1601,14 +1522,13 @@ struct UserDefined {
long use_port; /* which port to use (when not using default) */
unsigned long httpauth; /* kind of HTTP authentication to use (bitmask) */
unsigned long proxyauth; /* kind of proxy authentication to use (bitmask) */
+ unsigned long socks5auth;/* kind of SOCKS5 authentication to use (bitmask) */
long followlocation; /* as in HTTP Location: */
long maxredirs; /* maximum no. of http(s) redirects to follow, set to -1
for infinity */
int keep_post; /* keep POSTs as POSTs after a 30x request; each
bit represents a request, from 301 to 303 */
- bool free_referer; /* set TRUE if 'referer' points to a string we
- allocated */
void *postfields; /* if POST, set the fields' values here */
curl_seek_callback seek_func; /* function that seeks the input */
curl_off_t postfieldsize; /* if POST, this might have a size to use instead
@@ -1621,8 +1541,6 @@ struct UserDefined {
curl_write_callback fwrite_header; /* function that stores headers */
curl_write_callback fwrite_rtp; /* function that stores interleaved RTP */
curl_read_callback fread_func_set; /* function that reads the input */
- int is_fread_set; /* boolean, has read callback been set to non-NULL? */
- int is_fwrite_set; /* boolean, has write callback been set to non-NULL? */
curl_progress_callback fprogress; /* OLD and deprecated progress callback */
curl_xferinfo_callback fxferinfo; /* progress callback */
curl_debug_callback fdebug; /* function that write informational data */
@@ -1651,9 +1569,11 @@ struct UserDefined {
long timeout; /* in milliseconds, 0 means no timeout */
long connecttimeout; /* in milliseconds, 0 means no timeout */
long accepttimeout; /* in milliseconds, 0 means no timeout */
+ long happy_eyeballs_timeout; /* in milliseconds, 0 is a valid value */
long server_response_timeout; /* in milliseconds, 0 means no timeout */
+ long maxage_conn; /* in seconds, max idle time to allow a connection that
+ is to be reused */
long tftp_blksize; /* in bytes, 0 means use default */
- bool tftp_no_options; /* do not send TFTP options requests */
curl_off_t filesize; /* size of file to upload, -1 means unknown */
long low_speed_limit; /* bytes/second */
long low_speed_time; /* number of seconds */
@@ -1663,10 +1583,8 @@ struct UserDefined {
curl_off_t set_resume_from; /* continue [ftp] transfer from here */
struct curl_slist *headers; /* linked list of extra headers */
struct curl_slist *proxyheaders; /* linked list of extra CONNECT headers */
- struct curl_httppost *httppost; /* linked list of POST data */
- bool sep_headers; /* handle host and proxy headers separately */
- bool cookiesession; /* new cookie session? */
- bool crlf; /* convert crlf on ftp upload(?) */
+ struct curl_httppost *httppost; /* linked list of old POST data */
+ curl_mimepart mimepost; /* MIME/POST data. */
struct curl_slist *quote; /* after connection is established */
struct curl_slist *postquote; /* after the transfer */
struct curl_slist *prequote; /* before the transfer, after type */
@@ -1691,89 +1609,38 @@ struct UserDefined {
curl_proxytype proxytype; /* what kind of proxy that is in use */
long dns_cache_timeout; /* DNS cache timeout */
long buffer_size; /* size of receive buffer to use */
+ size_t upload_buffer_size; /* size of upload buffer to use,
+ keep it >= CURL_MAX_WRITE_SIZE */
void *private_data; /* application-private data */
-
struct curl_slist *http200aliases; /* linked list of aliases for http200 */
-
long ipver; /* the CURL_IPRESOLVE_* defines in the public header file
0 - whatever, 1 - v2, 2 - v6 */
-
curl_off_t max_filesize; /* Maximum file size to download */
-
+#ifndef CURL_DISABLE_FTP
curl_ftpfile ftp_filemethod; /* how to get to a file when FTP is used */
-
+ curl_ftpauth ftpsslauth; /* what AUTH XXX to be attempted */
+ curl_ftpccc ftp_ccc; /* FTP CCC options */
+#endif
int ftp_create_missing_dirs; /* 1 - create directories that don't exist
2 - the same but also allow MKD to fail once
*/
-
curl_sshkeycallback ssh_keyfunc; /* key matching callback */
void *ssh_keyfunc_userp; /* custom pointer to callback */
-
-/* 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; /* get the time and get of the remote file */
- bool tunnel_thru_httpproxy; /* use CONNECT through a HTTP proxy */
- bool prefer_ascii; /* ASCII rather than binary */
- bool ftp_append; /* append, not overwrite, on upload */
- bool ftp_list_only; /* switch FTP command for listing directories */
- bool ftp_use_port; /* use the FTP PORT command */
- bool hide_progress; /* don't use the progress meter */
- bool http_fail_on_error; /* fail on HTTP error codes >= 400 */
- bool http_keep_sending_on_error; /* for HTTP status codes >= 300 */
- bool http_follow_location; /* follow HTTP redirects */
- bool http_transfer_encoding; /* request compressed HTTP transfer-encoding */
- bool http_disable_hostname_check_before_authentication;
- bool include_header; /* include received protocol headers in data output */
- bool http_set_referer; /* is a custom referer used */
- bool http_auto_referer; /* set "correct" referer when following location: */
- bool opt_no_body; /* as set with CURLOPT_NOBODY */
- bool upload; /* upload request */
enum CURL_NETRC_OPTION
use_netrc; /* defined in include/curl.h */
- bool verbose; /* output verbosity */
- bool krb; /* Kerberos 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_pret; /* if PRET is to be used before PASV or not */
-
curl_usessl use_ssl; /* if AUTH TLS is to be attempted etc, for FTP or
IMAP or POP3 or others! */
- curl_ftpauth ftpsslauth; /* what AUTH XXX to be attempted */
- curl_ftpccc ftp_ccc; /* FTP CCC options */
- 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 */
- bool http_te_skip; /* pass the raw body data to the user, even when
- transfer-encoded (chunked, compressed) */
- bool http_ce_skip; /* pass the raw body data to the user, even when
- content-encoded (chunked, compressed) */
long new_file_perms; /* Permissions to use when creating remote files */
long new_directory_perms; /* Permissions to use when creating remote dirs */
- bool proxy_transfer_mode; /* set transfer mode (;type=<a|i>) when doing FTP
- via an HTTP proxy */
+ long ssh_auth_types; /* allowed SSH auth types */
char *str[STRING_LAST]; /* array of strings, pointing to allocated memory */
unsigned int scope_id; /* Scope id for IPv6 */
long allowed_protocols;
long redir_protocols;
-#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
- bool socks5_gssapi_nec; /* Flag to support NEC SOCKS5 server */
-#endif
struct curl_slist *mail_rcpt; /* linked list of mail recipients */
- bool sasl_ir; /* Enable/disable SASL initial response */
/* Common RTSP header options */
Curl_RtspReq rtspreq; /* RTSP request type */
long rtspversion; /* like httpversion, for RTSP */
- bool wildcardmatch; /* enable wildcard matching */
curl_chunk_bgn_callback chunk_bgn; /* called before part of transfer
starts */
curl_chunk_end_callback chunk_end; /* called after part transferring
@@ -1785,36 +1652,109 @@ struct UserDefined {
long gssapi_delegation; /* GSS-API credential delegation, see the
documentation of CURLOPT_GSSAPI_DELEGATION */
- bool tcp_keepalive; /* use TCP keepalives */
long tcp_keepidle; /* seconds in idle before sending keepalive probe */
long tcp_keepintvl; /* seconds between TCP keepalive probes */
- bool tcp_fastopen; /* use TCP Fast Open */
- size_t maxconnects; /* Max idle connections in the connection cache */
+ size_t maxconnects; /* Max idle connections in the connection cache */
- bool ssl_enable_npn; /* TLS NPN extension? */
- bool ssl_enable_alpn; /* TLS ALPN extension? */
- bool path_as_is; /* allow dotdots? */
- bool pipewait; /* wait for pipe/multiplex status before starting a
- new connection */
long expect_100_timeout; /* in milliseconds */
- bool suppress_connect_headers; /* suppress proxy CONNECT response headers
- from user callbacks */
-
struct Curl_easy *stream_depends_on;
- bool stream_depends_e; /* set or don't set the Exclusive bit */
int stream_weight;
-
struct Curl_http2_dep *stream_dependents;
- bool abstract_unix_socket;
+ curl_resolver_start_callback resolver_start; /* optional callback called
+ before resolver start */
+ void *resolver_start_client; /* pointer to pass to resolver start callback */
+ long upkeep_interval_ms; /* Time between calls for connection upkeep. */
+ multidone_func fmultidone;
+ struct Curl_easy *dohfor; /* this is a DoH request for that transfer */
+ CURLU *uh; /* URL handle for the current parsed URL */
+ void *trailer_data; /* pointer to pass to trailer data callback */
+ curl_trailer_callback trailer_callback; /* trailing data callback */
+ bit is_fread_set:1; /* has read callback been set to non-NULL? */
+ bit is_fwrite_set:1; /* has write callback been set to non-NULL? */
+ bit free_referer:1; /* set TRUE if 'referer' points to a string we
+ allocated */
+ bit tftp_no_options:1; /* do not send TFTP options requests */
+ bit sep_headers:1; /* handle host and proxy headers separately */
+ bit cookiesession:1; /* new cookie session? */
+ bit crlf:1; /* convert crlf on ftp upload(?) */
+ bit strip_path_slash:1; /* strip off initial slash from path */
+ bit ssh_compression:1; /* enable SSH compression */
+
+/* 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. */
+ bit get_filetime:1; /* get the time and get of the remote file */
+ bit tunnel_thru_httpproxy:1; /* use CONNECT through a HTTP proxy */
+ bit prefer_ascii:1; /* ASCII rather than binary */
+ bit ftp_append:1; /* append, not overwrite, on upload */
+ bit ftp_list_only:1; /* switch FTP command for listing directories */
+#ifndef CURL_DISABLE_FTP
+ bit ftp_use_port:1; /* use the FTP PORT command */
+ bit ftp_use_epsv:1; /* if EPSV is to be attempted or not */
+ bit ftp_use_eprt:1; /* if EPRT is to be attempted or not */
+ bit ftp_use_pret:1; /* if PRET is to be used before PASV or not */
+ bit ftp_skip_ip:1; /* skip the IP address the FTP server passes on to
+ us */
+#endif
+ bit hide_progress:1; /* don't use the progress meter */
+ bit http_fail_on_error:1; /* fail on HTTP error codes >= 400 */
+ bit http_keep_sending_on_error:1; /* for HTTP status codes >= 300 */
+ bit http_follow_location:1; /* follow HTTP redirects */
+ bit http_transfer_encoding:1; /* request compressed HTTP
+ transfer-encoding */
+ bit allow_auth_to_other_hosts:1;
+ bit include_header:1; /* include received protocol headers in data output */
+ bit http_set_referer:1; /* is a custom referer used */
+ bit http_auto_referer:1; /* set "correct" referer when following
+ location: */
+ bit opt_no_body:1; /* as set with CURLOPT_NOBODY */
+ bit upload:1; /* upload request */
+ bit verbose:1; /* output verbosity */
+ bit krb:1; /* Kerberos connection requested */
+ bit reuse_forbid:1; /* forbidden to be reused, close after use */
+ bit reuse_fresh:1; /* do not re-use an existing connection */
+
+ bit no_signal:1; /* do not use any signal/alarm handler */
+ bit tcp_nodelay:1; /* whether to enable TCP_NODELAY or not */
+ bit ignorecl:1; /* ignore content length */
+ bit connect_only:1; /* make connection, let application use the socket */
+ bit http_te_skip:1; /* pass the raw body data to the user, even when
+ transfer-encoded (chunked, compressed) */
+ bit http_ce_skip:1; /* pass the raw body data to the user, even when
+ content-encoded (chunked, compressed) */
+ bit proxy_transfer_mode:1; /* set transfer mode (;type=<a|i>) when doing
+ FTP via an HTTP proxy */
+#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
+ bit socks5_gssapi_nec:1; /* Flag to support NEC SOCKS5 server */
+#endif
+ bit sasl_ir:1; /* Enable/disable SASL initial response */
+ bit wildcard_enabled:1; /* enable wildcard matching */
+ bit tcp_keepalive:1; /* use TCP keepalives */
+ bit tcp_fastopen:1; /* use TCP Fast Open */
+ bit ssl_enable_npn:1; /* TLS NPN extension? */
+ bit ssl_enable_alpn:1;/* TLS ALPN extension? */
+ bit path_as_is:1; /* allow dotdots? */
+ bit pipewait:1; /* wait for multiplex status before starting a new
+ connection */
+ bit suppress_connect_headers:1; /* suppress proxy CONNECT response headers
+ from user callbacks */
+ bit dns_shuffle_addresses:1; /* whether to shuffle addresses before use */
+ bit stream_depends_e:1; /* set or don't set the Exclusive bit */
+ bit haproxyprotocol:1; /* whether to send HAProxy PROXY protocol v1
+ header */
+ bit abstract_unix_socket:1;
+ bit disallow_username_in_url:1; /* disallow username in url */
+ bit doh:1; /* DNS-over-HTTPS enabled */
+ bit doh_get:1; /* use GET for DoH requests, instead of POST */
+ bit http09_allowed:1; /* allow HTTP/0.9 responses */
};
struct Names {
struct curl_hash *hostcache;
enum {
HCACHE_NONE, /* not pointing to anything */
- 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;
@@ -1835,9 +1775,10 @@ struct Curl_easy {
struct Curl_easy *next;
struct Curl_easy *prev;
- struct connectdata *easy_conn; /* the "unit's" connection */
+ struct connectdata *conn;
struct curl_llist_element connect_queue;
- struct curl_llist_element pipeline_queue;
+ struct curl_llist_element sh_queue; /* list per Curl_sh_entry */
+ struct curl_llist_element conn_queue; /* list per connectdata */
CURLMstate mstate; /* the handle's state */
CURLcode result; /* previous result */
@@ -1849,6 +1790,8 @@ struct Curl_easy {
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 actions[MAX_SOCKSPEREASYHANDLE]; /* action for each socket in
+ sockets[] */
int numsocks;
struct Names dns;
@@ -1859,6 +1802,9 @@ struct Curl_easy {
struct to which this "belongs" when used
by the easy interface */
struct Curl_share *share; /* Share, handles global variable mutexing */
+#ifdef USE_LIBPSL
+ struct PslCache *psl; /* The associated PSL cache. */
+#endif
struct SingleRequest req; /* Request-specific data */
struct UserDefined set; /* values set by the libcurl user */
struct DynamicStatic change; /* possibly modified userdefined data */
@@ -1866,10 +1812,15 @@ struct Curl_easy {
NOTE that the 'cookie' field in the
UserDefined struct defines if the "engine"
is to be used or not. */
+#ifdef USE_ALTSVC
+ struct altsvcinfo *asi; /* the alt-svc cache */
+#endif
struct Progress progress; /* for all the progress meter data */
struct UrlState state; /* struct for fields used for state info and
other dynamic purposes */
+#ifndef CURL_DISABLE_FTP
struct WildcardData wildcard; /* wildcard download state info */
+#endif
struct PureInfo info; /* stats, reports and info data */
struct curl_tlssessioninfo tsi; /* Information about the TLS session, only
valid after a client has asked for it */
diff --git a/Utilities/cmcurl/lib/vauth/cleartext.c b/Utilities/cmcurl/lib/vauth/cleartext.c
index a761ae784..6f452c169 100644
--- a/Utilities/cmcurl/lib/vauth/cleartext.c
+++ b/Utilities/cmcurl/lib/vauth/cleartext.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -25,6 +25,9 @@
#include "curl_setup.h"
+#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \
+ !defined(CURL_DISABLE_POP3)
+
#include <curl/curl.h>
#include "urldata.h"
@@ -49,8 +52,9 @@
* Parameters:
*
* data [in] - The session handle.
- * userp [in] - The user name.
- * passdwp [in] - The user's password.
+ * authzid [in] - The authorization identity.
+ * authcid [in] - The authentication identity.
+ * passwd [in] - The password.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
* outlen [out] - The length of the output message.
@@ -58,42 +62,40 @@
* Returns CURLE_OK on success.
*/
CURLcode Curl_auth_create_plain_message(struct Curl_easy *data,
- const char *userp,
- const char *passwdp,
+ const char *authzid,
+ const char *authcid,
+ const char *passwd,
char **outptr, size_t *outlen)
{
CURLcode result;
char *plainauth;
- size_t ulen;
+ size_t zlen;
+ size_t clen;
size_t plen;
size_t plainlen;
*outlen = 0;
*outptr = NULL;
- ulen = strlen(userp);
- plen = strlen(passwdp);
+ zlen = (authzid == NULL ? 0 : strlen(authzid));
+ clen = strlen(authcid);
+ plen = strlen(passwd);
- /* Compute binary message length, checking for overflows. */
- plainlen = 2 * ulen;
- if(plainlen < ulen)
- return CURLE_OUT_OF_MEMORY;
- plainlen += plen;
- if(plainlen < plen)
- return CURLE_OUT_OF_MEMORY;
- plainlen += 2;
- if(plainlen < 2)
+ /* Compute binary message length. Check for overflows. */
+ if(((zlen + clen) > SIZE_T_MAX/4) || (plen > (SIZE_T_MAX/2 - 2)))
return CURLE_OUT_OF_MEMORY;
+ plainlen = zlen + clen + plen + 2;
plainauth = malloc(plainlen);
if(!plainauth)
return CURLE_OUT_OF_MEMORY;
/* Calculate the reply */
- memcpy(plainauth, userp, ulen);
- plainauth[ulen] = '\0';
- memcpy(plainauth + ulen + 1, userp, ulen);
- plainauth[2 * ulen + 1] = '\0';
- memcpy(plainauth + 2 * ulen + 2, passwdp, plen);
+ if(zlen != 0)
+ memcpy(plainauth, authzid, zlen);
+ plainauth[zlen] = '\0';
+ memcpy(plainauth + zlen + 1, authcid, clen);
+ plainauth[zlen + clen + 1] = '\0';
+ memcpy(plainauth + zlen + clen + 2, passwd, plen);
/* Base64 encode the reply */
result = Curl_base64_encode(data, plainauth, plainlen, outptr, outlen);
@@ -163,3 +165,5 @@ CURLcode Curl_auth_create_external_message(struct Curl_easy *data,
/* This is the same formatting as the login message */
return Curl_auth_create_login_message(data, user, outptr, outlen);
}
+
+#endif /* if no users */
diff --git a/Utilities/cmcurl/lib/vauth/cram.c b/Utilities/cmcurl/lib/vauth/cram.c
index 3074a163a..d148618b0 100644
--- a/Utilities/cmcurl/lib/vauth/cram.c
+++ b/Utilities/cmcurl/lib/vauth/cram.c
@@ -81,7 +81,7 @@ CURLcode Curl_auth_decode_cram_md5_message(const char *chlg64, char **outptr,
* data [in] - The session handle.
* chlg [in] - The challenge.
* userp [in] - The user name.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
* outlen [out] - The length of the output message.
diff --git a/Utilities/cmcurl/lib/vauth/digest.c b/Utilities/cmcurl/lib/vauth/digest.c
index 185098ed6..f9cdc9dd0 100644
--- a/Utilities/cmcurl/lib/vauth/digest.c
+++ b/Utilities/cmcurl/lib/vauth/digest.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -19,6 +19,7 @@
* KIND, either express or implied.
*
* RFC2831 DIGEST-MD5 authentication
+ * RFC7616 DIGEST-SHA256, DIGEST-SHA512-256 authentication
*
***************************************************************************/
@@ -34,6 +35,7 @@
#include "curl_base64.h"
#include "curl_hmac.h"
#include "curl_md5.h"
+#include "curl_sha256.h"
#include "vtls/vtls.h"
#include "warnless.h"
#include "strtok.h"
@@ -141,13 +143,22 @@ static void auth_digest_md5_to_ascii(unsigned char *source, /* 16 bytes */
{
int i;
for(i = 0; i < 16; i++)
- snprintf((char *) &dest[i * 2], 3, "%02x", source[i]);
+ msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]);
+}
+
+/* Convert sha256 chunk to RFC7616 -suitable ascii string*/
+static void auth_digest_sha256_to_ascii(unsigned char *source, /* 32 bytes */
+ unsigned char *dest) /* 65 bytes */
+{
+ int i;
+ for(i = 0; i < 32; i++)
+ msnprintf((char *) &dest[i * 2], 3, "%02x", source[i]);
}
/* Perform quoted-string escaping as described in RFC2616 and its errata */
static char *auth_digest_string_quoted(const char *source)
{
- char *dest, *d;
+ char *dest;
const char *s = source;
size_t n = 1; /* null terminator */
@@ -162,8 +173,8 @@ static char *auth_digest_string_quoted(const char *source)
dest = malloc(n);
if(dest) {
+ char *d = dest;
s = source;
- d = dest;
while(*s) {
if(*s == '"' || *s == '\\') {
*d++ = '\\';
@@ -331,7 +342,7 @@ bool Curl_auth_is_digest_supported(void)
* data [in] - The session handle.
* chlg64 [in] - The base64 encoded challenge message.
* userp [in] - The user name.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* service [in] - The service type such as http, smtp, pop or imap.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -421,7 +432,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
/* Convert calculated 16 octet hex into 32 bytes string */
for(i = 0; i < MD5_DIGEST_LEN; i++)
- snprintf(&HA1_hex[2 * i], 3, "%02x", digest[i]);
+ msnprintf(&HA1_hex[2 * i], 3, "%02x", digest[i]);
/* Generate our SPN */
spn = Curl_auth_build_spn(service, realm, NULL);
@@ -444,7 +455,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
Curl_MD5_final(ctxt, digest);
for(i = 0; i < MD5_DIGEST_LEN; i++)
- snprintf(&HA2_hex[2 * i], 3, "%02x", digest[i]);
+ msnprintf(&HA2_hex[2 * i], 3, "%02x", digest[i]);
/* Now calculate the response hash */
ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
@@ -474,7 +485,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
Curl_MD5_final(ctxt, digest);
for(i = 0; i < MD5_DIGEST_LEN; i++)
- snprintf(&resp_hash_hex[2 * i], 3, "%02x", digest[i]);
+ msnprintf(&resp_hash_hex[2 * i], 3, "%02x", digest[i]);
/* Generate the response */
response = aprintf("username=\"%s\",realm=\"%s\",nonce=\"%s\","
@@ -602,9 +613,22 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
digest->algo = CURLDIGESTALGO_MD5SESS;
else if(strcasecompare(content, "MD5"))
digest->algo = CURLDIGESTALGO_MD5;
+ else if(strcasecompare(content, "SHA-256"))
+ digest->algo = CURLDIGESTALGO_SHA256;
+ else if(strcasecompare(content, "SHA-256-SESS"))
+ digest->algo = CURLDIGESTALGO_SHA256SESS;
+ else if(strcasecompare(content, "SHA-512-256"))
+ digest->algo = CURLDIGESTALGO_SHA512_256;
+ else if(strcasecompare(content, "SHA-512-256-SESS"))
+ digest->algo = CURLDIGESTALGO_SHA512_256SESS;
else
return CURLE_BAD_CONTENT_ENCODING;
}
+ else if(strcasecompare(value, "userhash")) {
+ if(strcasecompare(content, "true")) {
+ digest->userhash = TRUE;
+ }
+ }
else {
/* Unknown specifier, ignore it! */
}
@@ -635,7 +659,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
}
/*
- * Curl_auth_create_digest_http_message()
+ * _Curl_auth_create_digest_http_message()
*
* This is used to generate a HTTP DIGEST response message ready for sending
* to the recipient.
@@ -644,7 +668,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
*
* data [in] - The session handle.
* userp [in] - The user name.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* request [in] - The HTTP request.
* uripath [in] - The path of the HTTP uri.
* digest [in/out] - The digest data struct being used and modified.
@@ -654,21 +678,24 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
*
* Returns CURLE_OK on success.
*/
-CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
- const char *userp,
- const char *passwdp,
- const unsigned char *request,
- const unsigned char *uripath,
- struct digestdata *digest,
- char **outptr, size_t *outlen)
+static CURLcode _Curl_auth_create_digest_http_message(
+ struct Curl_easy *data,
+ const char *userp,
+ const char *passwdp,
+ const unsigned char *request,
+ const unsigned char *uripath,
+ struct digestdata *digest,
+ char **outptr, size_t *outlen,
+ void (*convert_to_ascii)(unsigned char *, unsigned char *),
+ void (*hash)(unsigned char *, const unsigned char *))
{
CURLcode result;
- unsigned char md5buf[16]; /* 16 bytes/128 bits */
- unsigned char request_digest[33];
- unsigned char *md5this;
- unsigned char ha1[33]; /* 32 digits and 1 zero byte */
- unsigned char ha2[33]; /* 32 digits and 1 zero byte */
- char cnoncebuf[33];
+ unsigned char hashbuf[32]; /* 32 bytes/256 bits */
+ unsigned char request_digest[65];
+ unsigned char *hashthis;
+ unsigned char ha1[65]; /* 64 digits and 1 zero byte */
+ unsigned char ha2[65]; /* 64 digits and 1 zero byte */
+ char userh[65];
char *cnonce = NULL;
size_t cnonce_sz = 0;
char *userp_quoted;
@@ -679,6 +706,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
digest->nc = 1;
if(!digest->cnonce) {
+ char cnoncebuf[33];
result = Curl_rand_hex(data, (unsigned char *)cnoncebuf,
sizeof(cnoncebuf));
if(result)
@@ -692,6 +720,17 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
digest->cnonce = cnonce;
}
+ if(digest->userhash) {
+ hashthis = (unsigned char *) aprintf("%s:%s", userp, digest->realm);
+ if(!hashthis)
+ return CURLE_OUT_OF_MEMORY;
+
+ CURL_OUTPUT_DIGEST_CONV(data, hashthis);
+ hash(hashbuf, hashthis);
+ free(hashthis);
+ convert_to_ascii(hashbuf, (unsigned char *)userh);
+ }
+
/*
If the algorithm is "MD5" or unspecified (which then defaults to MD5):
@@ -703,26 +742,29 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
unq(nonce-value) ":" unq(cnonce-value)
*/
- md5this = (unsigned char *)
- aprintf("%s:%s:%s", userp, digest->realm, passwdp);
- if(!md5this)
+ hashthis = (unsigned char *)
+ aprintf("%s:%s:%s", digest->userhash ? userh : userp,
+ digest->realm, passwdp);
+ if(!hashthis)
return CURLE_OUT_OF_MEMORY;
- CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
- Curl_md5it(md5buf, md5this);
- free(md5this);
- auth_digest_md5_to_ascii(md5buf, ha1);
+ CURL_OUTPUT_DIGEST_CONV(data, hashthis); /* convert on non-ASCII machines */
+ hash(hashbuf, hashthis);
+ free(hashthis);
+ convert_to_ascii(hashbuf, ha1);
- if(digest->algo == CURLDIGESTALGO_MD5SESS) {
+ if(digest->algo == CURLDIGESTALGO_MD5SESS ||
+ digest->algo == CURLDIGESTALGO_SHA256SESS ||
+ digest->algo == CURLDIGESTALGO_SHA512_256SESS) {
/* nonce and cnonce are OUTSIDE the hash */
tmp = aprintf("%s:%s:%s", ha1, digest->nonce, digest->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);
+ hash(hashbuf, (unsigned char *) tmp);
free(tmp);
- auth_digest_md5_to_ascii(md5buf, ha1);
+ convert_to_ascii(hashbuf, ha1);
}
/*
@@ -738,27 +780,33 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
5.1.1 of RFC 2616)
*/
- md5this = (unsigned char *) aprintf("%s:%s", request, uripath);
+ hashthis = (unsigned char *) aprintf("%s:%s", request, uripath);
+ if(!hashthis)
+ return CURLE_OUT_OF_MEMORY;
if(digest->qop && strcasecompare(digest->qop, "auth-int")) {
- /* We don't support auth-int for PUT or POST at the moment.
- TODO: replace md5 of empty string with entity-body for PUT/POST */
- unsigned char *md5this2 = (unsigned char *)
- aprintf("%s:%s", md5this, "d41d8cd98f00b204e9800998ecf8427e");
- free(md5this);
- md5this = md5this2;
+ /* We don't support auth-int for PUT or POST */
+ char hashed[65];
+ unsigned char *hashthis2;
+
+ hash(hashbuf, (const unsigned char *)"");
+ convert_to_ascii(hashbuf, (unsigned char *)hashed);
+
+ hashthis2 = (unsigned char *)aprintf("%s:%s", hashthis, hashed);
+ free(hashthis);
+ hashthis = hashthis2;
}
- if(!md5this)
+ if(!hashthis)
return CURLE_OUT_OF_MEMORY;
- CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
- Curl_md5it(md5buf, md5this);
- free(md5this);
- auth_digest_md5_to_ascii(md5buf, ha2);
+ CURL_OUTPUT_DIGEST_CONV(data, hashthis); /* convert on non-ASCII machines */
+ hash(hashbuf, hashthis);
+ free(hashthis);
+ convert_to_ascii(hashbuf, ha2);
if(digest->qop) {
- md5this = (unsigned char *) aprintf("%s:%s:%08x:%s:%s:%s",
+ hashthis = (unsigned char *) aprintf("%s:%s:%08x:%s:%s:%s",
ha1,
digest->nonce,
digest->nc,
@@ -767,19 +815,19 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
ha2);
}
else {
- md5this = (unsigned char *) aprintf("%s:%s:%s",
+ hashthis = (unsigned char *) aprintf("%s:%s:%s",
ha1,
digest->nonce,
ha2);
}
- if(!md5this)
+ if(!hashthis)
return CURLE_OUT_OF_MEMORY;
- CURL_OUTPUT_DIGEST_CONV(data, md5this); /* convert on non-ASCII machines */
- Curl_md5it(md5buf, md5this);
- free(md5this);
- auth_digest_md5_to_ascii(md5buf, request_digest);
+ CURL_OUTPUT_DIGEST_CONV(data, hashthis); /* convert on non-ASCII machines */
+ hash(hashbuf, hashthis);
+ free(hashthis);
+ convert_to_ascii(hashbuf, request_digest);
/* For test case 64 (snooped from a Mozilla 1.3a request)
@@ -794,7 +842,7 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
characters. algorithm and qop with standard values only contain web-safe
characters.
*/
- userp_quoted = auth_digest_string_quoted(userp);
+ userp_quoted = auth_digest_string_quoted(digest->userhash ? userh : userp);
if(!userp_quoted)
return CURLE_OUT_OF_MEMORY;
@@ -858,6 +906,16 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
response = tmp;
}
+ if(digest->userhash) {
+ /* Append the userhash */
+ tmp = aprintf("%s, userhash=true", response);
+ free(response);
+ if(!tmp)
+ return CURLE_OUT_OF_MEMORY;
+
+ response = tmp;
+ }
+
/* Return the output */
*outptr = response;
*outlen = strlen(response);
@@ -866,6 +924,58 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
}
/*
+ * Curl_auth_create_digest_http_message()
+ *
+ * This is used to generate a HTTP DIGEST response message ready for sending
+ * to the recipient.
+ *
+ * Parameters:
+ *
+ * data [in] - The session handle.
+ * userp [in] - The user name.
+ * passwdp [in] - The user's password.
+ * request [in] - The HTTP request.
+ * uripath [in] - The path of the HTTP uri.
+ * digest [in/out] - The digest data struct being used and modified.
+ * outptr [in/out] - The address where a pointer to newly allocated memory
+ * holding the result will be stored upon completion.
+ * outlen [out] - The length of the output message.
+ *
+ * Returns CURLE_OK on success.
+ */
+CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
+ const char *userp,
+ const char *passwdp,
+ const unsigned char *request,
+ const unsigned char *uripath,
+ struct digestdata *digest,
+ char **outptr, size_t *outlen)
+{
+ switch(digest->algo) {
+ case CURLDIGESTALGO_MD5:
+ case CURLDIGESTALGO_MD5SESS:
+ return _Curl_auth_create_digest_http_message(data, userp, passwdp,
+ request, uripath, digest,
+ outptr, outlen,
+ auth_digest_md5_to_ascii,
+ Curl_md5it);
+
+ case CURLDIGESTALGO_SHA256:
+ case CURLDIGESTALGO_SHA256SESS:
+ case CURLDIGESTALGO_SHA512_256:
+ case CURLDIGESTALGO_SHA512_256SESS:
+ return _Curl_auth_create_digest_http_message(data, userp, passwdp,
+ request, uripath, digest,
+ outptr, outlen,
+ auth_digest_sha256_to_ascii,
+ Curl_sha256it);
+
+ default:
+ return CURLE_UNSUPPORTED_PROTOCOL;
+ }
+}
+
+/*
* Curl_auth_digest_cleanup()
*
* This is used to clean up the digest specific data.
@@ -887,6 +997,7 @@ void Curl_auth_digest_cleanup(struct digestdata *digest)
digest->nc = 0;
digest->algo = CURLDIGESTALGO_MD5; /* default algorithm */
digest->stale = FALSE; /* default means normal, not stale */
+ digest->userhash = FALSE;
}
#endif /* !USE_WINDOWS_SSPI */
diff --git a/Utilities/cmcurl/lib/vauth/digest.h b/Utilities/cmcurl/lib/vauth/digest.h
index 5722dcece..8686c44a4 100644
--- a/Utilities/cmcurl/lib/vauth/digest.h
+++ b/Utilities/cmcurl/lib/vauth/digest.h
@@ -31,7 +31,11 @@
enum {
CURLDIGESTALGO_MD5,
- CURLDIGESTALGO_MD5SESS
+ CURLDIGESTALGO_MD5SESS,
+ CURLDIGESTALGO_SHA256,
+ CURLDIGESTALGO_SHA256SESS,
+ CURLDIGESTALGO_SHA512_256,
+ CURLDIGESTALGO_SHA512_256SESS
};
/* This is used to extract the realm from a challenge message */
diff --git a/Utilities/cmcurl/lib/vauth/digest_sspi.c b/Utilities/cmcurl/lib/vauth/digest_sspi.c
index 0bd94442d..fe8093e8b 100644
--- a/Utilities/cmcurl/lib/vauth/digest_sspi.c
+++ b/Utilities/cmcurl/lib/vauth/digest_sspi.c
@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
- * Copyright (C) 2015 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2015 - 2019, 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
@@ -75,7 +75,7 @@ bool Curl_auth_is_digest_supported(void)
* data [in] - The session handle.
* chlg64 [in] - The base64 encoded challenge message.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* service [in] - The service type such as http, smtp, pop or imap.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -146,7 +146,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
}
/* Generate our SPN */
- spn = Curl_auth_build_spn(service, data->easy_conn->host.name, NULL);
+ spn = Curl_auth_build_spn(service, data->conn->host.name, NULL);
if(!spn) {
free(output_token);
free(input_token);
@@ -352,8 +352,8 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
if(!Curl_auth_digest_get_pair(p, value, content, &p))
break;
- if(Curl_strcasecompare(value, "stale")
- && Curl_strcasecompare(content, "true")) {
+ if(strcasecompare(value, "stale") &&
+ strcasecompare(content, "true")) {
stale = true;
break;
}
@@ -391,7 +391,7 @@ CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
*
* data [in] - The session handle.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* request [in] - The HTTP request.
* uripath [in] - The path of the HTTP uri.
* digest [in/out] - The digest data struct being used and modified.
@@ -438,6 +438,20 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
return CURLE_OUT_OF_MEMORY;
}
+ /* If the user/passwd that was used to make the identity for http_context
+ has changed then delete that context. */
+ if((userp && !digest->user) || (!userp && digest->user) ||
+ (passwdp && !digest->passwd) || (!passwdp && digest->passwd) ||
+ (userp && digest->user && strcmp(userp, digest->user)) ||
+ (passwdp && digest->passwd && strcmp(passwdp, digest->passwd))) {
+ if(digest->http_context) {
+ s_pSecFn->DeleteSecurityContext(digest->http_context);
+ Curl_safefree(digest->http_context);
+ }
+ Curl_safefree(digest->user);
+ Curl_safefree(digest->passwd);
+ }
+
if(digest->http_context) {
chlg_desc.ulVersion = SECBUFFER_VERSION;
chlg_desc.cBuffers = 5;
@@ -479,6 +493,10 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
TimeStamp expiry; /* For Windows 9x compatibility of SSPI calls */
TCHAR *spn;
+ /* free the copy of user/passwd used to make the previous identity */
+ Curl_safefree(digest->user);
+ Curl_safefree(digest->passwd);
+
if(userp && *userp) {
/* Populate our identity structure */
if(Curl_create_sspi_identity(userp, passwdp, &identity)) {
@@ -500,6 +518,25 @@ CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
/* Use the current Windows user */
p_identity = NULL;
+ if(userp) {
+ digest->user = strdup(userp);
+
+ if(!digest->user) {
+ free(output_token);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ }
+
+ if(passwdp) {
+ digest->passwd = strdup(passwdp);
+
+ if(!digest->passwd) {
+ free(output_token);
+ Curl_safefree(digest->user);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ }
+
/* Acquire our credentials handle */
status = s_pSecFn->AcquireCredentialsHandle(NULL,
(TCHAR *) TEXT(SP_NAME_DIGEST),
@@ -623,6 +660,10 @@ void Curl_auth_digest_cleanup(struct digestdata *digest)
s_pSecFn->DeleteSecurityContext(digest->http_context);
Curl_safefree(digest->http_context);
}
+
+ /* Free the copy of user/passwd used to make the identity for http_context */
+ Curl_safefree(digest->user);
+ Curl_safefree(digest->passwd);
}
#endif /* USE_WINDOWS_SSPI && !CURL_DISABLE_CRYPTO_AUTH */
diff --git a/Utilities/cmcurl/lib/vauth/krb5_gssapi.c b/Utilities/cmcurl/lib/vauth/krb5_gssapi.c
index 560ecc5bc..ea0a5f189 100644
--- a/Utilities/cmcurl/lib/vauth/krb5_gssapi.c
+++ b/Utilities/cmcurl/lib/vauth/krb5_gssapi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2014 - 2017, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (C) 2014 - 2019, Steve Holme, <steve_holme@hotmail.com>.
* Copyright (C) 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
@@ -65,7 +65,7 @@ bool Curl_auth_is_gssapi_supported(void)
*
* data [in] - The session handle.
* userp [in] - The user name.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* service [in] - The service type such as http, smtp, pop or imap.
* host [in[ - The host name.
* mutual_auth [in] - Flag specifying whether or not mutual authentication
@@ -372,7 +372,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
}
/*
- * Curl_auth_gssapi_cleanup()
+ * Curl_auth_cleanup_gssapi()
*
* This is used to clean up the GSSAPI (Kerberos V5) specific data.
*
@@ -381,7 +381,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
* krb5 [in/out] - The Kerberos 5 data struct being cleaned up.
*
*/
-void Curl_auth_gssapi_cleanup(struct kerberos5data *krb5)
+void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5)
{
OM_uint32 minor_status;
diff --git a/Utilities/cmcurl/lib/vauth/krb5_sspi.c b/Utilities/cmcurl/lib/vauth/krb5_sspi.c
index 1b4cef486..1f6e462bf 100644
--- a/Utilities/cmcurl/lib/vauth/krb5_sspi.c
+++ b/Utilities/cmcurl/lib/vauth/krb5_sspi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2014 - 2017, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (C) 2014 - 2019, Steve Holme, <steve_holme@hotmail.com>.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -71,7 +71,7 @@ bool Curl_auth_is_gssapi_supported(void)
*
* data [in] - The session handle.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* service [in] - The service type such as http, smtp, pop or imap.
* host [in] - The host name.
* mutual_auth [in] - Flag specifying whether or not mutual authentication
@@ -135,7 +135,7 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
}
if(!krb5->credentials) {
- /* Do we have credientials to use or are we using single sign-on? */
+ /* Do we have credentials to use or are we using single sign-on? */
if(userp && *userp) {
/* Populate our identity structure */
result = Curl_create_sspi_identity(userp, passwdp, &krb5->identity);
@@ -150,12 +150,10 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
krb5->p_identity = NULL;
/* Allocate our credentials handle */
- krb5->credentials = malloc(sizeof(CredHandle));
+ krb5->credentials = calloc(1, sizeof(CredHandle));
if(!krb5->credentials)
return CURLE_OUT_OF_MEMORY;
- memset(krb5->credentials, 0, sizeof(CredHandle));
-
/* Acquire our credentials handle */
status = s_pSecFn->AcquireCredentialsHandle(NULL,
(TCHAR *)
@@ -167,11 +165,9 @@ CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
return CURLE_LOGIN_DENIED;
/* Allocate our new context handle */
- krb5->context = malloc(sizeof(CtxtHandle));
+ krb5->context = calloc(1, sizeof(CtxtHandle));
if(!krb5->context)
return CURLE_OUT_OF_MEMORY;
-
- memset(krb5->context, 0, sizeof(CtxtHandle));
}
if(chlg64 && *chlg64) {
@@ -478,7 +474,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
}
/*
- * Curl_auth_gssapi_cleanup()
+ * Curl_auth_cleanup_gssapi()
*
* This is used to clean up the GSSAPI (Kerberos V5) specific data.
*
@@ -487,7 +483,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
* krb5 [in/out] - The Kerberos 5 data struct being cleaned up.
*
*/
-void Curl_auth_gssapi_cleanup(struct kerberos5data *krb5)
+void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5)
{
/* Free our security context */
if(krb5->context) {
diff --git a/Utilities/cmcurl/lib/vauth/ntlm.c b/Utilities/cmcurl/lib/vauth/ntlm.c
index 42196455f..047c2b5a3 100644
--- a/Utilities/cmcurl/lib/vauth/ntlm.c
+++ b/Utilities/cmcurl/lib/vauth/ntlm.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -44,7 +44,9 @@
#include "rand.h"
#include "vtls/vtls.h"
-#ifdef USE_NSS
+/* SSL backend-specific #if branches in this file must be kept in the order
+ documented in curl_ntlm_core. */
+#if defined(NTLM_NEEDS_NSS_INIT)
#include "vtls/nssg.h" /* for Curl_nss_force_init() */
#endif
@@ -61,9 +63,9 @@
/* "NTLMSSP" signature is always in ASCII regardless of the platform */
#define NTLMSSP_SIGNATURE "\x4e\x54\x4c\x4d\x53\x53\x50"
-#define SHORTPAIR(x) ((x) & 0xff), (((x) >> 8) & 0xff)
-#define LONGQUARTET(x) ((x) & 0xff), (((x) >> 8) & 0xff), \
- (((x) >> 16) & 0xff), (((x) >> 24) & 0xff)
+#define SHORTPAIR(x) ((int)((x) & 0xff)), ((int)(((x) >> 8) & 0xff))
+#define LONGQUARTET(x) ((int)((x) & 0xff)), ((int)(((x) >> 8) & 0xff)), \
+ ((int)(((x) >> 16) & 0xff)), ((int)(((x) >> 24) & 0xff))
#if DEBUG_ME
# define DEBUG_OUT(x) x
@@ -180,10 +182,11 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data,
target_info_len = Curl_read16_le(&buffer[40]);
target_info_offset = Curl_read32_le(&buffer[44]);
if(target_info_len > 0) {
- if(((target_info_offset + target_info_len) > size) ||
+ if((target_info_offset >= size) ||
+ ((target_info_offset + target_info_len) > size) ||
(target_info_offset < 48)) {
infof(data, "NTLM handshake failure (bad type-2 message). "
- "Target Info Offset Len is set incorrect by the peer\n");
+ "Target Info Offset Len is set incorrect by the peer\n");
return CURLE_BAD_CONTENT_ENCODING;
}
@@ -272,7 +275,7 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
unsigned char *type2 = NULL;
size_t type2_len = 0;
-#if defined(USE_NSS)
+#if defined(NTLM_NEEDS_NSS_INIT)
/* Make sure the crypto backend is initialized */
result = Curl_nss_force_init(data);
if(result)
@@ -350,8 +353,11 @@ static void unicodecpy(unsigned char *dest, const char *src, size_t length)
*
* Parameters:
*
+ * data [in] - The session handle.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
+ * service [in] - The service type such as http, smtp, pop or imap.
+ * host [in] - The host name.
* ntlm [in/out] - The NTLM data struct being used and modified.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -359,8 +365,11 @@ static void unicodecpy(unsigned char *dest, const char *src, size_t length)
*
* Returns CURLE_OK on success.
*/
-CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
+CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
+ const char *userp,
const char *passwdp,
+ const char *service,
+ const char *hostname,
struct ntlmdata *ntlm,
char **outptr, size_t *outlen)
{
@@ -390,47 +399,49 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
domain are empty */
(void)userp;
(void)passwdp;
+ (void)service,
+ (void)hostname,
/* Clean up any former leftovers and initialise to defaults */
- Curl_auth_ntlm_cleanup(ntlm);
+ Curl_auth_cleanup_ntlm(ntlm);
#if defined(USE_NTRESPONSES) && defined(USE_NTLM2SESSION)
#define NTLM2FLAG NTLMFLAG_NEGOTIATE_NTLM2_KEY
#else
#define NTLM2FLAG 0
#endif
- snprintf((char *)ntlmbuf, NTLM_BUFSIZE,
- 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 */);
+ msnprintf((char *)ntlmbuf, NTLM_BUFSIZE,
+ 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;
@@ -458,7 +469,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
});
/* Return with binary blob encoded into base64 */
- return Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, outlen);
+ return Curl_base64_encode(data, (char *)ntlmbuf, size, outptr, outlen);
}
/*
@@ -471,7 +482,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
*
* data [in] - The session handle.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* ntlm [in/out] - The NTLM data struct being used and modified.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -539,8 +550,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
else
user = userp;
- if(user)
- userlen = strlen(user);
+ userlen = strlen(user);
/* Get the machine's un-qualified host name as NTLM doesn't like the fully
qualified domain name */
@@ -553,7 +563,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
}
#if defined(USE_NTRESPONSES) && defined(USE_NTLM_V2)
- if(ntlm->target_info_len) {
+ if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) {
unsigned char ntbuffer[0x18];
unsigned char entropy[8];
unsigned char ntlmv2hash[0x18];
@@ -590,7 +600,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
#if defined(USE_NTRESPONSES) && defined(USE_NTLM2SESSION)
/* We don't support NTLM2 if we don't have USE_NTRESPONSES */
- if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) {
+ if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM_KEY) {
unsigned char ntbuffer[0x18];
unsigned char tmp[0x18];
unsigned char md5sum[MD5_DIGEST_LENGTH];
@@ -622,7 +632,9 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
Curl_ntlm_core_lm_resp(ntbuffer, md5sum, ntresp);
/* End of NTLM2 Session code */
-
+ /* NTLM v2 session security is a misnomer because it is not NTLM v2.
+ It is NTLM v1 using the extended session security that is also
+ in NTLM v2 */
}
else
#endif
@@ -669,88 +681,88 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
hostoff = useroff + userlen;
/* Create the big type-3 message binary blob */
- size = snprintf((char *)ntlmbuf, NTLM_BUFSIZE,
- NTLMSSP_SIGNATURE "%c"
- "\x03%c%c%c" /* 32-bit type = 3 */
-
- "%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,
+ size = msnprintf((char *)ntlmbuf, NTLM_BUFSIZE,
+ NTLMSSP_SIGNATURE "%c"
+ "\x03%c%c%c" /* 32-bit type = 3 */
+
+ "%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,
#ifdef USE_NTRESPONSES
- SHORTPAIR(ntresplen), /* NT-response length, twice */
- SHORTPAIR(ntresplen),
- SHORTPAIR(ntrespoff),
- 0x0, 0x0,
+ SHORTPAIR(ntresplen), /* NT-response length, twice */
+ SHORTPAIR(ntresplen),
+ SHORTPAIR(ntrespoff),
+ 0x0, 0x0,
#else
- 0x0, 0x0,
- 0x0, 0x0,
- 0x0, 0x0,
- 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
#endif
- SHORTPAIR(domlen),
- SHORTPAIR(domlen),
- SHORTPAIR(domoff),
- 0x0, 0x0,
+ SHORTPAIR(domlen),
+ SHORTPAIR(domlen),
+ SHORTPAIR(domoff),
+ 0x0, 0x0,
- SHORTPAIR(userlen),
- SHORTPAIR(userlen),
- SHORTPAIR(useroff),
- 0x0, 0x0,
+ SHORTPAIR(userlen),
+ SHORTPAIR(userlen),
+ SHORTPAIR(useroff),
+ 0x0, 0x0,
- SHORTPAIR(hostlen),
- SHORTPAIR(hostlen),
- SHORTPAIR(hostoff),
- 0x0, 0x0,
+ SHORTPAIR(hostlen),
+ SHORTPAIR(hostlen),
+ SHORTPAIR(hostoff),
+ 0x0, 0x0,
- 0x0, 0x0,
- 0x0, 0x0,
- 0x0, 0x0,
- 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
+ 0x0, 0x0,
- LONGQUARTET(ntlm->flags));
+ LONGQUARTET(ntlm->flags));
DEBUGASSERT(size == 64);
DEBUGASSERT(size == (size_t)lmrespoff);
@@ -767,11 +779,14 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
});
#ifdef USE_NTRESPONSES
- if(size < (NTLM_BUFSIZE - ntresplen)) {
- DEBUGASSERT(size == (size_t)ntrespoff);
- memcpy(&ntlmbuf[size], ptr_ntresp, ntresplen);
- size += ntresplen;
+ /* ntresplen + size should not be risking an integer overflow here */
+ if(ntresplen + size > sizeof(ntlmbuf)) {
+ failf(data, "incoming NTLM message too big");
+ return CURLE_OUT_OF_MEMORY;
}
+ DEBUGASSERT(size == (size_t)ntrespoff);
+ memcpy(&ntlmbuf[size], ptr_ntresp, ntresplen);
+ size += ntresplen;
DEBUG_OUT({
fprintf(stderr, "\n ntresp=");
@@ -827,24 +842,24 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
return CURLE_CONV_FAILED;
/* Return with binary blob encoded into base64 */
- result = Curl_base64_encode(NULL, (char *)ntlmbuf, size, outptr, outlen);
+ result = Curl_base64_encode(data, (char *)ntlmbuf, size, outptr, outlen);
- Curl_auth_ntlm_cleanup(ntlm);
+ Curl_auth_cleanup_ntlm(ntlm);
return result;
}
/*
-* Curl_auth_ntlm_cleanup()
-*
-* This is used to clean up the NTLM specific data.
-*
-* Parameters:
-*
-* ntlm [in/out] - The NTLM data struct being cleaned up.
-*
-*/
-void Curl_auth_ntlm_cleanup(struct ntlmdata *ntlm)
+ * Curl_auth_cleanup_ntlm()
+ *
+ * This is used to clean up the NTLM specific data.
+ *
+ * Parameters:
+ *
+ * ntlm [in/out] - The NTLM data struct being cleaned up.
+ *
+ */
+void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm)
{
/* Free the target info */
Curl_safefree(ntlm->target_info);
diff --git a/Utilities/cmcurl/lib/vauth/ntlm.h b/Utilities/cmcurl/lib/vauth/ntlm.h
index f906a3c7a..1136b0f8d 100644
--- a/Utilities/cmcurl/lib/vauth/ntlm.h
+++ b/Utilities/cmcurl/lib/vauth/ntlm.h
@@ -1,5 +1,5 @@
-#ifndef HEADER_CURL_NTLM_H
-#define HEADER_CURL_NTLM_H
+#ifndef HEADER_VAUTH_NTLM_H
+#define HEADER_VAUTH_NTLM_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -140,4 +140,4 @@
#endif /* USE_NTLM */
-#endif /* HEADER_CURL_NTLM_H */
+#endif /* HEADER_VAUTH_NTLM_H */
diff --git a/Utilities/cmcurl/lib/vauth/ntlm_sspi.c b/Utilities/cmcurl/lib/vauth/ntlm_sspi.c
index c3305176d..589cca16c 100644
--- a/Utilities/cmcurl/lib/vauth/ntlm_sspi.c
+++ b/Utilities/cmcurl/lib/vauth/ntlm_sspi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -29,6 +29,7 @@
#include "vauth/vauth.h"
#include "urldata.h"
#include "curl_base64.h"
+#include "curl_ntlm_core.h"
#include "warnless.h"
#include "curl_multibyte.h"
#include "sendf.h"
@@ -66,8 +67,11 @@ bool Curl_auth_is_ntlm_supported(void)
*
* Parameters:
*
+ * data [in] - The session handle.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
+ * service [in] - The service type such as http, smtp, pop or imap.
+ * host [in] - The host name.
* ntlm [in/out] - The NTLM data struct being used and modified.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -75,8 +79,11 @@ bool Curl_auth_is_ntlm_supported(void)
*
* Returns CURLE_OK on success.
*/
-CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
+CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
+ const char *userp,
const char *passwdp,
+ const char *service,
+ const char *host,
struct ntlmdata *ntlm,
char **outptr, size_t *outlen)
{
@@ -88,7 +95,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
TimeStamp expiry; /* For Windows 9x compatibility of SSPI calls */
/* Clean up any former leftovers and initialise to defaults */
- Curl_auth_ntlm_cleanup(ntlm);
+ Curl_auth_cleanup_ntlm(ntlm);
/* Query the security package for NTLM */
status = s_pSecFn->QuerySecurityPackageInfo((TCHAR *) TEXT(SP_NAME_NTLM),
@@ -122,12 +129,10 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
ntlm->p_identity = NULL;
/* Allocate our credentials handle */
- ntlm->credentials = malloc(sizeof(CredHandle));
+ ntlm->credentials = calloc(1, sizeof(CredHandle));
if(!ntlm->credentials)
return CURLE_OUT_OF_MEMORY;
- memset(ntlm->credentials, 0, sizeof(CredHandle));
-
/* Acquire our credentials handle */
status = s_pSecFn->AcquireCredentialsHandle(NULL,
(TCHAR *) TEXT(SP_NAME_NTLM),
@@ -138,11 +143,13 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
return CURLE_LOGIN_DENIED;
/* Allocate our new context handle */
- ntlm->context = malloc(sizeof(CtxtHandle));
+ ntlm->context = calloc(1, sizeof(CtxtHandle));
if(!ntlm->context)
return CURLE_OUT_OF_MEMORY;
- memset(ntlm->context, 0, sizeof(CtxtHandle));
+ ntlm->spn = Curl_auth_build_spn(service, host, NULL);
+ if(!ntlm->spn)
+ return CURLE_OUT_OF_MEMORY;
/* Setup the type-1 "output" security buffer */
type_1_desc.ulVersion = SECBUFFER_VERSION;
@@ -154,7 +161,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
/* Generate our type-1 message */
status = s_pSecFn->InitializeSecurityContext(ntlm->credentials, NULL,
- (TCHAR *) TEXT(""),
+ ntlm->spn,
0, 0, SECURITY_NETWORK_DREP,
NULL, 0,
ntlm->context, &type_1_desc,
@@ -166,7 +173,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
return CURLE_RECV_ERROR;
/* Base64 encode the response */
- return Curl_base64_encode(NULL, (char *) ntlm->output_token,
+ return Curl_base64_encode(data, (char *) ntlm->output_token,
type_1_buf.cbBuffer, outptr, outlen);
}
@@ -227,7 +234,7 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
*
* data [in] - The session handle.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* ntlm [in/out] - The NTLM data struct being used and modified.
* outptr [in/out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -242,7 +249,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
char **outptr, size_t *outlen)
{
CURLcode result = CURLE_OK;
- SecBuffer type_2_buf;
+ SecBuffer type_2_bufs[2];
SecBuffer type_3_buf;
SecBufferDesc type_2_desc;
SecBufferDesc type_3_desc;
@@ -254,12 +261,39 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
(void) userp;
/* Setup the type-2 "input" security buffer */
- type_2_desc.ulVersion = SECBUFFER_VERSION;
- type_2_desc.cBuffers = 1;
- type_2_desc.pBuffers = &type_2_buf;
- type_2_buf.BufferType = SECBUFFER_TOKEN;
- type_2_buf.pvBuffer = ntlm->input_token;
- type_2_buf.cbBuffer = curlx_uztoul(ntlm->input_token_len);
+ type_2_desc.ulVersion = SECBUFFER_VERSION;
+ type_2_desc.cBuffers = 1;
+ type_2_desc.pBuffers = &type_2_bufs[0];
+ type_2_bufs[0].BufferType = SECBUFFER_TOKEN;
+ type_2_bufs[0].pvBuffer = ntlm->input_token;
+ type_2_bufs[0].cbBuffer = curlx_uztoul(ntlm->input_token_len);
+
+#ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
+ /* ssl context comes from schannel.
+ * When extended protection is used in IIS server,
+ * we have to pass a second SecBuffer to the SecBufferDesc
+ * otherwise IIS will not pass the authentication (401 response).
+ * Minimum supported version is Windows 7.
+ * https://docs.microsoft.com/en-us/security-updates
+ * /SecurityAdvisories/2009/973811
+ */
+ if(ntlm->sslContext) {
+ SEC_CHANNEL_BINDINGS channelBindings;
+ SecPkgContext_Bindings pkgBindings;
+ pkgBindings.Bindings = &channelBindings;
+ status = s_pSecFn->QueryContextAttributes(
+ ntlm->sslContext,
+ SECPKG_ATTR_ENDPOINT_BINDINGS,
+ &pkgBindings
+ );
+ if(status == SEC_E_OK) {
+ type_2_desc.cBuffers++;
+ type_2_bufs[1].BufferType = SECBUFFER_CHANNEL_BINDINGS;
+ type_2_bufs[1].cbBuffer = pkgBindings.BindingsLength;
+ type_2_bufs[1].pvBuffer = pkgBindings.Bindings;
+ }
+ }
+#endif
/* Setup the type-3 "output" security buffer */
type_3_desc.ulVersion = SECBUFFER_VERSION;
@@ -272,7 +306,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
/* Generate our type-3 message */
status = s_pSecFn->InitializeSecurityContext(ntlm->credentials,
ntlm->context,
- (TCHAR *) TEXT(""),
+ ntlm->spn,
0, 0, SECURITY_NETWORK_DREP,
&type_2_desc,
0, ntlm->context,
@@ -289,13 +323,13 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
result = Curl_base64_encode(data, (char *) ntlm->output_token,
type_3_buf.cbBuffer, outptr, outlen);
- Curl_auth_ntlm_cleanup(ntlm);
+ Curl_auth_cleanup_ntlm(ntlm);
return result;
}
/*
- * Curl_auth_ntlm_cleanup()
+ * Curl_auth_cleanup_ntlm()
*
* This is used to clean up the NTLM specific data.
*
@@ -304,7 +338,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
* ntlm [in/out] - The NTLM data struct being cleaned up.
*
*/
-void Curl_auth_ntlm_cleanup(struct ntlmdata *ntlm)
+void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm)
{
/* Free our security context */
if(ntlm->context) {
@@ -330,6 +364,8 @@ void Curl_auth_ntlm_cleanup(struct ntlmdata *ntlm)
/* Reset any variables */
ntlm->token_max = 0;
+
+ Curl_safefree(ntlm->spn);
}
#endif /* USE_WINDOWS_SSPI && USE_NTLM */
diff --git a/Utilities/cmcurl/lib/vauth/oauth2.c b/Utilities/cmcurl/lib/vauth/oauth2.c
index 6288f89a3..b4e9f8e70 100644
--- a/Utilities/cmcurl/lib/vauth/oauth2.c
+++ b/Utilities/cmcurl/lib/vauth/oauth2.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -24,6 +24,9 @@
#include "curl_setup.h"
+#if !defined(CURL_DISABLE_IMAP) || !defined(CURL_DISABLE_SMTP) || \
+ !defined(CURL_DISABLE_POP3)
+
#include <curl/curl.h>
#include "urldata.h"
@@ -46,8 +49,8 @@
*
* data[in] - The session handle.
* user[in] - The user name.
- * host[in] - The host name(for OAUTHBEARER).
- * port[in] - The port(for OAUTHBEARER when not Port 80).
+ * host[in] - The host name.
+ * port[in] - The port(when not Port 80).
* bearer[in] - The bearer token.
* outptr[in / out] - The address where a pointer to newly allocated memory
* holding the result will be stored upon completion.
@@ -66,13 +69,11 @@ CURLcode Curl_auth_create_oauth_bearer_message(struct Curl_easy *data,
char *oauth = NULL;
/* Generate the message */
- if(host == NULL && (port == 0 || port == 80))
- oauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
- else if(port == 0 || port == 80)
- oauth = aprintf("user=%s\1host=%s\1auth=Bearer %s\1\1", user, host,
+ if(port == 0 || port == 80)
+ oauth = aprintf("n,a=%s,\1host=%s\1auth=Bearer %s\1\1", user, host,
bearer);
else
- oauth = aprintf("user=%s\1host=%s\1port=%ld\1auth=Bearer %s\1\1", user,
+ oauth = aprintf("n,a=%s,\1host=%s\1port=%ld\1auth=Bearer %s\1\1", user,
host, port, bearer);
if(!oauth)
return CURLE_OUT_OF_MEMORY;
@@ -84,3 +85,42 @@ CURLcode Curl_auth_create_oauth_bearer_message(struct Curl_easy *data,
return result;
}
+
+/*
+ * Curl_auth_create_xoauth_bearer_message()
+ *
+ * This is used to generate an already encoded XOAuth 2.0 message ready for
+ * sending to the recipient.
+ *
+ * Parameters:
+ *
+ * data[in] - The session handle.
+ * user[in] - The user name.
+ * bearer[in] - The bearer token.
+ * outptr[in / out] - The address where a pointer to newly allocated memory
+ * holding the result will be stored upon completion.
+ * outlen[out] - The length of the output message.
+ *
+ * Returns CURLE_OK on success.
+ */
+CURLcode Curl_auth_create_xoauth_bearer_message(struct Curl_easy *data,
+ const char *user,
+ const char *bearer,
+ char **outptr, size_t *outlen)
+{
+ CURLcode result = CURLE_OK;
+
+ /* Generate the message */
+ char *xoauth = aprintf("user=%s\1auth=Bearer %s\1\1", user, bearer);
+ if(!xoauth)
+ return CURLE_OUT_OF_MEMORY;
+
+ /* Base64 encode the reply */
+ result = Curl_base64_encode(data, xoauth, strlen(xoauth), outptr, outlen);
+
+ free(xoauth);
+
+ return result;
+}
+#endif /* disabled, no users */
+
diff --git a/Utilities/cmcurl/lib/vauth/spnego_gssapi.c b/Utilities/cmcurl/lib/vauth/spnego_gssapi.c
index 8840db8fd..5d43e1100 100644
--- a/Utilities/cmcurl/lib/vauth/spnego_gssapi.c
+++ b/Utilities/cmcurl/lib/vauth/spnego_gssapi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -64,7 +64,7 @@ bool Curl_auth_is_spnego_supported(void)
*
* data [in] - The session handle.
* userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * passwdp [in] - The user's password.
* service [in] - The service type such as http, smtp, pop or imap.
* host [in] - The host name.
* chlg64 [in] - The optional base64 encoded challenge message.
@@ -97,7 +97,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
/* We finished successfully 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_auth_spnego_cleanup(nego);
+ Curl_auth_cleanup_spnego(nego);
return CURLE_LOGIN_DENIED;
}
@@ -170,7 +170,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
Curl_gss_log_error(data, "gss_init_sec_context() failed: ",
major_status, minor_status);
- return CURLE_OUT_OF_MEMORY;
+ return CURLE_LOGIN_DENIED;
}
if(!output_token.value || !output_token.length) {
@@ -180,6 +180,10 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
return CURLE_OUT_OF_MEMORY;
}
+ /* Free previous token */
+ if(nego->output_token.length && nego->output_token.value)
+ gss_release_buffer(&unused_status, &nego->output_token);
+
nego->output_token = output_token;
return CURLE_OK;
@@ -234,7 +238,7 @@ CURLcode Curl_auth_create_spnego_message(struct Curl_easy *data,
}
/*
- * Curl_auth_spnego_cleanup()
+ * Curl_auth_cleanup_spnego()
*
* This is used to clean up the SPNEGO (Negotiate) specific data.
*
@@ -243,7 +247,7 @@ CURLcode Curl_auth_create_spnego_message(struct Curl_easy *data,
* nego [in/out] - The Negotiate data struct being cleaned up.
*
*/
-void Curl_auth_spnego_cleanup(struct negotiatedata *nego)
+void Curl_auth_cleanup_spnego(struct negotiatedata *nego)
{
OM_uint32 minor_status;
@@ -269,6 +273,10 @@ void Curl_auth_spnego_cleanup(struct negotiatedata *nego)
/* Reset any variables */
nego->status = 0;
+ nego->noauthpersist = FALSE;
+ nego->havenoauthpersist = FALSE;
+ nego->havenegdata = FALSE;
+ nego->havemultiplerequests = FALSE;
}
#endif /* HAVE_GSSAPI && USE_SPNEGO */
diff --git a/Utilities/cmcurl/lib/vauth/spnego_sspi.c b/Utilities/cmcurl/lib/vauth/spnego_sspi.c
index a6797cdaf..4b21cc769 100644
--- a/Utilities/cmcurl/lib/vauth/spnego_sspi.c
+++ b/Utilities/cmcurl/lib/vauth/spnego_sspi.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -71,8 +71,8 @@ bool Curl_auth_is_spnego_supported(void)
* Parameters:
*
* data [in] - The session handle.
- * userp [in] - The user name in the format User or Domain\User.
- * passdwp [in] - The user's password.
+ * user [in] - The user name in the format User or Domain\User.
+ * password [in] - The user's password.
* service [in] - The service type such as http, smtp, pop or imap.
* host [in] - The host name.
* chlg64 [in] - The optional base64 encoded challenge message.
@@ -92,7 +92,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
size_t chlglen = 0;
unsigned char *chlg = NULL;
PSecPkgInfo SecurityPackage;
- SecBuffer chlg_buf;
+ SecBuffer chlg_buf[2];
SecBuffer resp_buf;
SecBufferDesc chlg_desc;
SecBufferDesc resp_desc;
@@ -107,7 +107,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
/* We finished successfully 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_auth_spnego_cleanup(nego);
+ Curl_auth_cleanup_spnego(nego);
return CURLE_LOGIN_DENIED;
}
@@ -138,7 +138,7 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
}
if(!nego->credentials) {
- /* Do we have credientials to use or are we using single sign-on? */
+ /* Do we have credentials to use or are we using single sign-on? */
if(user && *user) {
/* Populate our identity structure */
result = Curl_create_sspi_identity(user, password, &nego->identity);
@@ -153,12 +153,10 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
nego->p_identity = NULL;
/* Allocate our credentials handle */
- nego->credentials = malloc(sizeof(CredHandle));
+ nego->credentials = calloc(1, sizeof(CredHandle));
if(!nego->credentials)
return CURLE_OUT_OF_MEMORY;
- memset(nego->credentials, 0, sizeof(CredHandle));
-
/* Acquire our credentials handle */
nego->status =
s_pSecFn->AcquireCredentialsHandle(NULL,
@@ -170,11 +168,9 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
return CURLE_LOGIN_DENIED;
/* Allocate our new context handle */
- nego->context = malloc(sizeof(CtxtHandle));
+ nego->context = calloc(1, sizeof(CtxtHandle));
if(!nego->context)
return CURLE_OUT_OF_MEMORY;
-
- memset(nego->context, 0, sizeof(CtxtHandle));
}
if(chlg64 && *chlg64) {
@@ -193,12 +189,39 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
}
/* Setup the challenge "input" security buffer */
- chlg_desc.ulVersion = SECBUFFER_VERSION;
- chlg_desc.cBuffers = 1;
- chlg_desc.pBuffers = &chlg_buf;
- chlg_buf.BufferType = SECBUFFER_TOKEN;
- chlg_buf.pvBuffer = chlg;
- chlg_buf.cbBuffer = curlx_uztoul(chlglen);
+ chlg_desc.ulVersion = SECBUFFER_VERSION;
+ chlg_desc.cBuffers = 1;
+ chlg_desc.pBuffers = &chlg_buf[0];
+ chlg_buf[0].BufferType = SECBUFFER_TOKEN;
+ chlg_buf[0].pvBuffer = chlg;
+ chlg_buf[0].cbBuffer = curlx_uztoul(chlglen);
+
+#ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
+ /* ssl context comes from Schannel.
+ * When extended protection is used in IIS server,
+ * we have to pass a second SecBuffer to the SecBufferDesc
+ * otherwise IIS will not pass the authentication (401 response).
+ * Minimum supported version is Windows 7.
+ * https://docs.microsoft.com/en-us/security-updates
+ * /SecurityAdvisories/2009/973811
+ */
+ if(nego->sslContext) {
+ SEC_CHANNEL_BINDINGS channelBindings;
+ SecPkgContext_Bindings pkgBindings;
+ pkgBindings.Bindings = &channelBindings;
+ nego->status = s_pSecFn->QueryContextAttributes(
+ nego->sslContext,
+ SECPKG_ATTR_ENDPOINT_BINDINGS,
+ &pkgBindings
+ );
+ if(nego->status == SEC_E_OK) {
+ chlg_desc.cBuffers++;
+ chlg_buf[1].BufferType = SECBUFFER_CHANNEL_BINDINGS;
+ chlg_buf[1].cbBuffer = pkgBindings.BindingsLength;
+ chlg_buf[1].pvBuffer = pkgBindings.Bindings;
+ }
+ }
+#endif
}
/* Setup the response "output" security buffer */
@@ -225,8 +248,9 @@ CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
free(chlg);
if(GSS_ERROR(nego->status)) {
+ char buffer[STRERROR_LEN];
failf(data, "InitializeSecurityContext failed: %s",
- Curl_sspi_strerror(data->easy_conn, nego->status));
+ Curl_sspi_strerror(nego->status, buffer, sizeof(buffer)));
return CURLE_OUT_OF_MEMORY;
}
@@ -283,7 +307,7 @@ CURLcode Curl_auth_create_spnego_message(struct Curl_easy *data,
}
/*
- * Curl_auth_spnego_cleanup()
+ * Curl_auth_cleanup_spnego()
*
* This is used to clean up the SPNEGO (Negotiate) specific data.
*
@@ -292,7 +316,7 @@ CURLcode Curl_auth_create_spnego_message(struct Curl_easy *data,
* nego [in/out] - The Negotiate data struct being cleaned up.
*
*/
-void Curl_auth_spnego_cleanup(struct negotiatedata *nego)
+void Curl_auth_cleanup_spnego(struct negotiatedata *nego)
{
/* Free our security context */
if(nego->context) {
@@ -319,6 +343,10 @@ void Curl_auth_spnego_cleanup(struct negotiatedata *nego)
/* Reset any variables */
nego->status = 0;
nego->token_max = 0;
+ nego->noauthpersist = FALSE;
+ nego->havenoauthpersist = FALSE;
+ nego->havenegdata = FALSE;
+ nego->havemultiplerequests = FALSE;
}
#endif /* USE_WINDOWS_SSPI && USE_SPNEGO */
diff --git a/Utilities/cmcurl/lib/vauth/vauth.c b/Utilities/cmcurl/lib/vauth/vauth.c
index b995f34e2..a9c5c9c4f 100644
--- a/Utilities/cmcurl/lib/vauth/vauth.c
+++ b/Utilities/cmcurl/lib/vauth/vauth.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (C) 2014 - 2019, Steve Holme, <steve_holme@hotmail.com>.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -105,26 +105,26 @@ TCHAR *Curl_auth_build_spn(const char *service, const char *host,
#endif /* USE_WINDOWS_SSPI */
/*
-* Curl_auth_user_contains_domain()
-*
-* This is used to test if the specified user contains a Windows domain name as
-* follows:
-*
-* User\Domain (Down-level Logon Name)
-* User/Domain (curl Down-level format - for compatibility with existing code)
-* User@Domain (User Principal Name)
-*
-* Note: The user name may be empty when using a GSS-API library or Windows SSPI
-* as the user and domain are either obtained from the credientals cache when
-* using GSS-API or via the currently logged in user's credientals when using
-* Windows SSPI.
-*
-* Parameters:
-*
-* user [in] - The user name.
-*
-* Returns TRUE on success; otherwise FALSE.
-*/
+ * Curl_auth_user_contains_domain()
+ *
+ * This is used to test if the specified user contains a Windows domain name as
+ * follows:
+ *
+ * Domain\User (Down-level Logon Name)
+ * Domain/User (curl Down-level format - for compatibility with existing code)
+ * User@Domain (User Principal Name)
+ *
+ * Note: The user name may be empty when using a GSS-API library or Windows
+ * SSPI as the user and domain are either obtained from the credentials cache
+ * when using GSS-API or via the currently logged in user's credentials when
+ * using Windows SSPI.
+ *
+ * Parameters:
+ *
+ * user [in] - The user name.
+ *
+ * Returns TRUE on success; otherwise FALSE.
+ */
bool Curl_auth_user_contains_domain(const char *user)
{
bool valid = FALSE;
@@ -138,7 +138,7 @@ bool Curl_auth_user_contains_domain(const char *user)
}
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
else
- /* User and domain are obtained from the GSS-API credientials cache or the
+ /* User and domain are obtained from the GSS-API credentials cache or the
currently logged in user from Windows */
valid = TRUE;
#endif
diff --git a/Utilities/cmcurl/lib/vauth/vauth.h b/Utilities/cmcurl/lib/vauth/vauth.h
index 9d61228c3..73bd25ed5 100644
--- a/Utilities/cmcurl/lib/vauth/vauth.h
+++ b/Utilities/cmcurl/lib/vauth/vauth.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (C) 2014 - 2019, Steve Holme, <steve_holme@hotmail.com>.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -60,8 +60,9 @@ bool Curl_auth_user_contains_domain(const char *user);
/* This is used to generate a base64 encoded PLAIN cleartext message */
CURLcode Curl_auth_create_plain_message(struct Curl_easy *data,
- const char *userp,
- const char *passwdp,
+ const char *authzid,
+ const char *authcid,
+ const char *passwd,
char **outptr, size_t *outlen);
/* This is used to generate a base64 encoded LOGIN cleartext message */
@@ -119,8 +120,11 @@ void Curl_auth_digest_cleanup(struct digestdata *digest);
bool Curl_auth_is_ntlm_supported(void);
/* This is used to generate a base64 encoded NTLM type-1 message */
-CURLcode Curl_auth_create_ntlm_type1_message(const char *userp,
+CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
+ const char *userp,
const char *passwdp,
+ const char *service,
+ const char *host,
struct ntlmdata *ntlm,
char **outptr,
size_t *outlen);
@@ -138,7 +142,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
char **outptr, size_t *outlen);
/* This is used to clean up the NTLM specific data */
-void Curl_auth_ntlm_cleanup(struct ntlmdata *ntlm);
+void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm);
#endif /* USE_NTLM */
/* This is used to generate a base64 encoded OAuth 2.0 message */
@@ -148,6 +152,13 @@ CURLcode Curl_auth_create_oauth_bearer_message(struct Curl_easy *data,
const long port,
const char *bearer,
char **outptr, size_t *outlen);
+
+/* This is used to generate a base64 encoded XOAuth 2.0 message */
+CURLcode Curl_auth_create_xoauth_bearer_message(struct Curl_easy *data,
+ const char *user,
+ const char *bearer,
+ char **outptr, size_t *outlen);
+
#if defined(USE_KERBEROS5)
/* This is used to evaluate if GSSAPI (Kerberos V5) is supported */
bool Curl_auth_is_gssapi_supported(void);
@@ -173,7 +184,7 @@ CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
size_t *outlen);
/* This is used to clean up the GSSAPI specific data */
-void Curl_auth_gssapi_cleanup(struct kerberos5data *krb5);
+void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5);
#endif /* USE_KERBEROS5 */
#if defined(USE_SPNEGO)
@@ -197,7 +208,7 @@ CURLcode Curl_auth_create_spnego_message(struct Curl_easy *data,
char **outptr, size_t *outlen);
/* This is used to clean up the SPNEGO specifiec data */
-void Curl_auth_spnego_cleanup(struct negotiatedata *nego);
+void Curl_auth_cleanup_spnego(struct negotiatedata *nego);
#endif /* USE_SPNEGO */
diff --git a/Utilities/cmcurl/lib/version.c b/Utilities/cmcurl/lib/version.c
index 3d1776813..14b0531d3 100644
--- a/Utilities/cmcurl/lib/version.c
+++ b/Utilities/cmcurl/lib/version.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -26,11 +26,12 @@
#include "urldata.h"
#include "vtls/vtls.h"
#include "http2.h"
+#include "ssh.h"
#include "curl_printf.h"
#ifdef USE_ARES
# if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && \
- (defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__))
+ (defined(WIN32) || defined(__SYMBIAN32__))
# define CARES_STATICLIB
# endif
# include <ares.h>
@@ -64,6 +65,18 @@
#define CURL_LIBSSH2_VERSION LIBSSH2_VERSION
#endif
+#ifdef HAVE_ZLIB_H
+#include <zlib.h>
+#ifdef __SYMBIAN32__
+/* zlib pollutes the namespace with this definition */
+#undef WIN32
+#endif
+#endif
+
+#ifdef HAVE_BROTLI
+#include <brotli/decode.h>
+#endif
+
void Curl_version_init(void);
/* For thread safety purposes this function is called by global_init so that
@@ -74,6 +87,18 @@ void Curl_version_init(void)
curl_version_info(CURLVERSION_NOW);
}
+#ifdef HAVE_BROTLI
+static size_t brotli_version(char *buf, size_t bufsz)
+{
+ uint32_t brotli_version = BrotliDecoderVersion();
+ unsigned int major = brotli_version >> 24;
+ unsigned int minor = (brotli_version & 0x00FFFFFF) >> 12;
+ unsigned int patch = brotli_version & 0x00000FFF;
+
+ return msnprintf(buf, bufsz, "%u.%u.%u", major, minor, patch);
+}
+#endif
+
char *curl_version(void)
{
static bool initialized;
@@ -101,46 +126,59 @@ char *curl_version(void)
}
#ifdef HAVE_LIBZ
- len = snprintf(ptr, left, " zlib/%s", zlibVersion());
+ len = msnprintf(ptr, left, " zlib/%s", zlibVersion());
+ left -= len;
+ ptr += len;
+#endif
+#ifdef HAVE_BROTLI
+ len = msnprintf(ptr, left, "%s", " brotli/");
+ left -= len;
+ ptr += len;
+ len = brotli_version(ptr, left);
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));
+ len = msnprintf(ptr, left, " c-ares/%s", ares_version(NULL));
left -= len;
ptr += len;
#endif
#ifdef USE_LIBIDN2
if(idn2_check_version(IDN2_VERSION)) {
- len = snprintf(ptr, left, " libidn2/%s", idn2_check_version(NULL));
+ len = msnprintf(ptr, left, " libidn2/%s", idn2_check_version(NULL));
left -= len;
ptr += len;
}
#endif
#ifdef USE_LIBPSL
- len = snprintf(ptr, left, " libpsl/%s", psl_get_version());
+ len = msnprintf(ptr, left, " libpsl/%s", psl_get_version());
left -= len;
ptr += len;
#endif
#ifdef USE_WIN32_IDN
- len = snprintf(ptr, left, " WinIDN");
+ len = msnprintf(ptr, left, " WinIDN");
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);
+ len = msnprintf(ptr, left, " iconv/%d.%d",
+ _LIBICONV_VERSION >> 8, _LIBICONV_VERSION & 255);
#else
/* version unknown */
- len = snprintf(ptr, left, " iconv");
+ len = msnprintf(ptr, left, " iconv");
#endif /* _LIBICONV_VERSION */
left -= len;
ptr += len;
#endif
#ifdef USE_LIBSSH2
- len = snprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
+ len = msnprintf(ptr, left, " libssh2/%s", CURL_LIBSSH2_VERSION);
+ left -= len;
+ ptr += len;
+#endif
+#ifdef USE_LIBSSH
+ len = msnprintf(ptr, left, " libssh/%s", CURL_LIBSSH_VERSION);
left -= len;
ptr += len;
#endif
@@ -159,14 +197,14 @@ char *curl_version(void)
else
suff[0] = '\0';
- snprintf(ptr, left, " librtmp/%d.%d%s",
- RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
- suff);
+ msnprintf(ptr, left, " librtmp/%d.%d%s",
+ RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff,
+ suff);
/*
If another lib version is added below this one, this code would
also have to do:
- len = what snprintf() returned
+ len = what msnprintf() returned
left -= len;
ptr += len;
@@ -174,6 +212,10 @@ char *curl_version(void)
}
#endif
+ /* Silent scan-build even if librtmp is not enabled. */
+ (void) left;
+ (void) ptr;
+
initialized = true;
return version;
}
@@ -232,10 +274,8 @@ static const char * const protocols[] = {
#ifndef CURL_DISABLE_RTSP
"rtsp",
#endif
-#ifdef USE_LIBSSH2
+#if defined(USE_SSH)
"scp",
-#endif
-#ifdef USE_LIBSSH2
"sftp",
#endif
#if !defined(CURL_DISABLE_SMB) && defined(USE_NTLM) && \
@@ -324,8 +364,14 @@ static curl_version_info_data version_info = {
#if defined(USE_LIBPSL)
| CURL_VERSION_PSL
#endif
-#if defined(HTTPS_PROXY_SUPPORT)
- | CURL_VERSION_HTTPS_PROXY
+#if defined(CURL_WITH_MULTI_SSL)
+ | CURL_VERSION_MULTI_SSL
+#endif
+#if defined(HAVE_BROTLI)
+ | CURL_VERSION_BROTLI
+#endif
+#if defined(USE_ALTSVC)
+ | CURL_VERSION_ALTSVC
#endif
,
NULL, /* ssl_version */
@@ -337,17 +383,26 @@ static curl_version_info_data version_info = {
NULL, /* libidn version */
0, /* iconv version */
NULL, /* ssh lib version */
+ 0, /* brotli_ver_num */
+ NULL, /* brotli version */
};
curl_version_info_data *curl_version_info(CURLversion stamp)
{
static bool initialized;
-#ifdef USE_LIBSSH2
+#if defined(USE_SSH)
static char ssh_buffer[80];
#endif
#ifdef USE_SSL
+#ifdef CURL_WITH_MULTI_SSL
+ static char ssl_buffer[200];
+#else
static char ssl_buffer[80];
#endif
+#endif
+#ifdef HAVE_BROTLI
+ static char brotli_buffer[80];
+#endif
if(initialized)
return &version_info;
@@ -355,6 +410,10 @@ curl_version_info_data *curl_version_info(CURLversion stamp)
#ifdef USE_SSL
Curl_ssl_version(ssl_buffer, sizeof(ssl_buffer));
version_info.ssl_version = ssl_buffer;
+ if(Curl_ssl->supports & SSLSUPP_HTTPS_PROXY)
+ version_info.features |= CURL_VERSION_HTTPS_PROXY;
+ else
+ version_info.features &= ~CURL_VERSION_HTTPS_PROXY;
#endif
#ifdef HAVE_LIBZ
@@ -387,11 +446,20 @@ curl_version_info_data *curl_version_info(CURLversion stamp)
#endif /* _LIBICONV_VERSION */
#endif
-#ifdef USE_LIBSSH2
- snprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
+#if defined(USE_LIBSSH2)
+ msnprintf(ssh_buffer, sizeof(ssh_buffer), "libssh2/%s", LIBSSH2_VERSION);
+ version_info.libssh_version = ssh_buffer;
+#elif defined(USE_LIBSSH)
+ msnprintf(ssh_buffer, sizeof(ssh_buffer), "libssh/%s", CURL_LIBSSH_VERSION);
version_info.libssh_version = ssh_buffer;
#endif
+#ifdef HAVE_BROTLI
+ version_info.brotli_ver_num = BrotliDecoderVersion();
+ brotli_version(brotli_buffer, sizeof(brotli_buffer));
+ version_info.brotli_version = brotli_buffer;
+#endif
+
(void)stamp; /* avoid compiler warnings, we don't use this */
initialized = true;
diff --git a/Utilities/cmcurl/lib/vtls/cyassl.c b/Utilities/cmcurl/lib/vtls/cyassl.c
index 01bfdabd1..44a2bdda6 100644
--- a/Utilities/cmcurl/lib/vtls/cyassl.c
+++ b/Utilities/cmcurl/lib/vtls/cyassl.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -67,18 +67,7 @@ and that's a problem since options.h hasn't been included yet. */
#endif
#endif
-/* HAVE_SUPPORTED_CURVES is wolfSSL's build time symbol for enabling the ECC
- supported curve extension in options.h. Note ECC is enabled separately. */
-#ifndef HAVE_SUPPORTED_CURVES
-#if defined(HAVE_CYASSL_CTX_USESUPPORTEDCURVE) || \
- defined(HAVE_WOLFSSL_CTX_USESUPPORTEDCURVE)
-#define HAVE_SUPPORTED_CURVES
-#endif
-#endif
-
-#ifdef HAVE_LIMITS_H
#include <limits.h>
-#endif
#include "urldata.h"
#include "sendf.h"
@@ -90,7 +79,9 @@ and that's a problem since options.h hasn't been included yet. */
#include "strcase.h"
#include "x509asn1.h"
#include "curl_printf.h"
+#include "multiif.h"
+#include <cyassl/openssl/ssl.h>
#include <cyassl/ssl.h>
#ifdef HAVE_CYASSL_ERROR_SSL_H
#include <cyassl/error-ssl.h>
@@ -110,6 +101,25 @@ and that's a problem since options.h hasn't been included yet. */
#define CYASSL_MAX_ERROR_SZ 80
#endif
+/* KEEP_PEER_CERT is a product of the presence of build time symbol
+ OPENSSL_EXTRA without NO_CERTS, depending on the version. KEEP_PEER_CERT is
+ in wolfSSL's settings.h, and the latter two are build time symbols in
+ options.h. */
+#ifndef KEEP_PEER_CERT
+#if defined(HAVE_CYASSL_GET_PEER_CERTIFICATE) || \
+ defined(HAVE_WOLFSSL_GET_PEER_CERTIFICATE) || \
+ (defined(OPENSSL_EXTRA) && !defined(NO_CERTS))
+#define KEEP_PEER_CERT
+#endif
+#endif
+
+struct ssl_backend_data {
+ SSL_CTX* ctx;
+ SSL* handle;
+};
+
+#define BACKEND connssl->backend
+
static Curl_recv cyassl_recv;
static Curl_send cyassl_send;
@@ -133,10 +143,9 @@ static CURLcode
cyassl_connect_step1(struct connectdata *conn,
int sockindex)
{
- char error_buffer[CYASSL_MAX_ERROR_SZ];
char *ciphers;
struct Curl_easy *data = conn->data;
- struct ssl_connect_data* conssl = &conn->ssl[sockindex];
+ struct ssl_connect_data* connssl = &conn->ssl[sockindex];
SSL_METHOD* req_method = NULL;
curl_socket_t sockfd = conn->sock[sockindex];
#ifdef HAVE_SNI
@@ -146,7 +155,7 @@ cyassl_connect_step1(struct connectdata *conn,
#define use_sni(x) Curl_nop_stmt
#endif
- if(conssl->state == ssl_connection_complete)
+ if(connssl->state == ssl_connection_complete)
return CURLE_OK;
if(SSL_CONN_CONFIG(version_max) != CURL_SSLVERSION_MAX_NONE) {
@@ -169,8 +178,13 @@ cyassl_connect_step1(struct connectdata *conn,
use_sni(TRUE);
break;
case CURL_SSLVERSION_TLSv1_0:
+#ifdef WOLFSSL_ALLOW_TLSV10
req_method = TLSv1_client_method();
use_sni(TRUE);
+#else
+ failf(data, "CyaSSL does not support TLS 1.0");
+ return CURLE_NOT_BUILT_IN;
+#endif
break;
case CURL_SSLVERSION_TLSv1_1:
req_method = TLSv1_1_client_method();
@@ -181,8 +195,14 @@ cyassl_connect_step1(struct connectdata *conn,
use_sni(TRUE);
break;
case CURL_SSLVERSION_TLSv1_3:
+#ifdef WOLFSSL_TLS13
+ req_method = wolfTLSv1_3_client_method();
+ use_sni(TRUE);
+ break;
+#else
failf(data, "CyaSSL: TLS 1.3 is not yet supported");
return CURLE_SSL_CONNECT_ERROR;
+#endif
case CURL_SSLVERSION_SSLv3:
#ifdef WOLFSSL_ALLOW_SSLV3
req_method = SSLv3_client_method();
@@ -205,11 +225,11 @@ cyassl_connect_step1(struct connectdata *conn,
return CURLE_OUT_OF_MEMORY;
}
- if(conssl->ctx)
- SSL_CTX_free(conssl->ctx);
- conssl->ctx = SSL_CTX_new(req_method);
+ if(BACKEND->ctx)
+ SSL_CTX_free(BACKEND->ctx);
+ BACKEND->ctx = SSL_CTX_new(req_method);
- if(!conssl->ctx) {
+ if(!BACKEND->ctx) {
failf(data, "SSL: couldn't create a context!");
return CURLE_OUT_OF_MEMORY;
}
@@ -225,9 +245,13 @@ cyassl_connect_step1(struct connectdata *conn,
version. We use wolfSSL_CTX_SetMinVersion and not CyaSSL_SetMinVersion
because only the former will work before the user's CTX callback is called.
*/
- if((wolfSSL_CTX_SetMinVersion(conssl->ctx, WOLFSSL_TLSV1) != 1) &&
- (wolfSSL_CTX_SetMinVersion(conssl->ctx, WOLFSSL_TLSV1_1) != 1) &&
- (wolfSSL_CTX_SetMinVersion(conssl->ctx, WOLFSSL_TLSV1_2) != 1)) {
+ if((wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1) != 1) &&
+ (wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1_1) != 1) &&
+ (wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1_2) != 1)
+#ifdef WOLFSSL_TLS13
+ && (wolfSSL_CTX_SetMinVersion(BACKEND->ctx, WOLFSSL_TLSV1_3) != 1)
+#endif
+ ) {
failf(data, "SSL: couldn't set the minimum protocol version");
return CURLE_SSL_CONNECT_ERROR;
}
@@ -237,7 +261,7 @@ cyassl_connect_step1(struct connectdata *conn,
ciphers = SSL_CONN_CONFIG(cipher_list);
if(ciphers) {
- if(!SSL_CTX_set_cipher_list(conssl->ctx, ciphers)) {
+ if(!SSL_CTX_set_cipher_list(BACKEND->ctx, ciphers)) {
failf(data, "failed setting cipher list: %s", ciphers);
return CURLE_SSL_CIPHER;
}
@@ -247,7 +271,7 @@ cyassl_connect_step1(struct connectdata *conn,
#ifndef NO_FILESYSTEM
/* load trusted cacert */
if(SSL_CONN_CONFIG(CAfile)) {
- if(1 != SSL_CTX_load_verify_locations(conssl->ctx,
+ if(1 != SSL_CTX_load_verify_locations(BACKEND->ctx,
SSL_CONN_CONFIG(CAfile),
SSL_CONN_CONFIG(CApath))) {
if(SSL_CONN_CONFIG(verifypeer)) {
@@ -284,7 +308,7 @@ cyassl_connect_step1(struct connectdata *conn,
if(SSL_SET_OPTION(cert) && SSL_SET_OPTION(key)) {
int file_type = do_file_type(SSL_SET_OPTION(cert_type));
- if(SSL_CTX_use_certificate_file(conssl->ctx, SSL_SET_OPTION(cert),
+ if(SSL_CTX_use_certificate_file(BACKEND->ctx, SSL_SET_OPTION(cert),
file_type) != 1) {
failf(data, "unable to use client certificate (no key or wrong pass"
" phrase?)");
@@ -292,7 +316,7 @@ cyassl_connect_step1(struct connectdata *conn,
}
file_type = do_file_type(SSL_SET_OPTION(key_type));
- if(SSL_CTX_use_PrivateKey_file(conssl->ctx, SSL_SET_OPTION(key),
+ if(SSL_CTX_use_PrivateKey_file(BACKEND->ctx, SSL_SET_OPTION(key),
file_type) != 1) {
failf(data, "unable to set private key");
return CURLE_SSL_CONNECT_ERROR;
@@ -304,7 +328,7 @@ cyassl_connect_step1(struct connectdata *conn,
* 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(conssl->ctx,
+ SSL_CTX_set_verify(BACKEND->ctx,
SSL_CONN_CONFIG(verifypeer)?SSL_VERIFY_PEER:
SSL_VERIFY_NONE,
NULL);
@@ -323,7 +347,7 @@ cyassl_connect_step1(struct connectdata *conn,
#ifdef ENABLE_IPV6
(0 == Curl_inet_pton(AF_INET6, hostname, &addr6)) &&
#endif
- (CyaSSL_CTX_UseSNI(conssl->ctx, CYASSL_SNI_HOST_NAME, hostname,
+ (CyaSSL_CTX_UseSNI(BACKEND->ctx, CYASSL_SNI_HOST_NAME, hostname,
(unsigned short)hostname_len) != 1)) {
infof(data, "WARNING: failed to configure server name indication (SNI) "
"TLS extension\n");
@@ -331,20 +355,10 @@ cyassl_connect_step1(struct connectdata *conn,
}
#endif
-#ifdef HAVE_SUPPORTED_CURVES
- /* CyaSSL/wolfSSL does not send the supported ECC curves ext automatically:
- https://github.com/wolfSSL/wolfssl/issues/366
- The supported curves below are those also supported by OpenSSL 1.0.2 and
- in the same order. */
- CyaSSL_CTX_UseSupportedCurve(conssl->ctx, 0x17); /* secp256r1 */
- CyaSSL_CTX_UseSupportedCurve(conssl->ctx, 0x19); /* secp521r1 */
- CyaSSL_CTX_UseSupportedCurve(conssl->ctx, 0x18); /* secp384r1 */
-#endif
-
/* give application a chance to interfere with SSL set up. */
if(data->set.ssl.fsslctx) {
CURLcode result = CURLE_OK;
- result = (*data->set.ssl.fsslctx)(data, conssl->ctx,
+ result = (*data->set.ssl.fsslctx)(data, BACKEND->ctx,
data->set.ssl.fsslctxp);
if(result) {
failf(data, "error signaled by ssl ctx callback");
@@ -362,10 +376,10 @@ cyassl_connect_step1(struct connectdata *conn,
#endif
/* Let's make an SSL structure */
- if(conssl->handle)
- SSL_free(conssl->handle);
- conssl->handle = SSL_new(conssl->ctx);
- if(!conssl->handle) {
+ if(BACKEND->handle)
+ SSL_free(BACKEND->handle);
+ BACKEND->handle = SSL_new(BACKEND->ctx);
+ if(!BACKEND->handle) {
failf(data, "SSL: couldn't create a context (handle)!");
return CURLE_OUT_OF_MEMORY;
}
@@ -388,7 +402,7 @@ cyassl_connect_step1(struct connectdata *conn,
strcpy(protocols + strlen(protocols), ALPN_HTTP_1_1);
infof(data, "ALPN, offering %s\n", ALPN_HTTP_1_1);
- if(wolfSSL_UseALPN(conssl->handle, protocols,
+ if(wolfSSL_UseALPN(BACKEND->handle, protocols,
(unsigned)strlen(protocols),
WOLFSSL_ALPN_CONTINUE_ON_MISMATCH) != SSL_SUCCESS) {
failf(data, "SSL: failed setting ALPN protocols");
@@ -404,10 +418,11 @@ cyassl_connect_step1(struct connectdata *conn,
Curl_ssl_sessionid_lock(conn);
if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) {
/* we got a session id, use it! */
- if(!SSL_set_session(conssl->handle, ssl_sessionid)) {
+ if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) {
+ char error_buffer[CYASSL_MAX_ERROR_SZ];
Curl_ssl_sessionid_unlock(conn);
failf(data, "SSL: SSL_set_session failed: %s",
- ERR_error_string(SSL_get_error(conssl->handle, 0),
+ ERR_error_string(SSL_get_error(BACKEND->handle, 0),
error_buffer));
return CURLE_SSL_CONNECT_ERROR;
}
@@ -418,12 +433,12 @@ cyassl_connect_step1(struct connectdata *conn,
}
/* pass the raw socket into the SSL layer */
- if(!SSL_set_fd(conssl->handle, (int)sockfd)) {
+ if(!SSL_set_fd(BACKEND->handle, (int)sockfd)) {
failf(data, "SSL: SSL_set_fd failed");
return CURLE_SSL_CONNECT_ERROR;
}
- conssl->connecting_state = ssl_connect_2;
+ connssl->connecting_state = ssl_connect_2;
return CURLE_OK;
}
@@ -434,7 +449,7 @@ cyassl_connect_step2(struct connectdata *conn,
{
int ret = -1;
struct Curl_easy *data = conn->data;
- struct ssl_connect_data* conssl = &conn->ssl[sockindex];
+ struct ssl_connect_data* connssl = &conn->ssl[sockindex];
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
const char * const dispname = SSL_IS_PROXY() ?
@@ -448,22 +463,22 @@ cyassl_connect_step2(struct connectdata *conn,
/* Enable RFC2818 checks */
if(SSL_CONN_CONFIG(verifyhost)) {
- ret = CyaSSL_check_domain_name(conssl->handle, hostname);
+ ret = CyaSSL_check_domain_name(BACKEND->handle, hostname);
if(ret == SSL_FAILURE)
return CURLE_OUT_OF_MEMORY;
}
- ret = SSL_connect(conssl->handle);
+ ret = SSL_connect(BACKEND->handle);
if(ret != 1) {
char error_buffer[CYASSL_MAX_ERROR_SZ];
- int detail = SSL_get_error(conssl->handle, ret);
+ int detail = SSL_get_error(BACKEND->handle, ret);
if(SSL_ERROR_WANT_READ == detail) {
- conssl->connecting_state = ssl_connect_2_reading;
+ connssl->connecting_state = ssl_connect_2_reading;
return CURLE_OK;
}
else if(SSL_ERROR_WANT_WRITE == detail) {
- conssl->connecting_state = ssl_connect_2_writing;
+ connssl->connecting_state = ssl_connect_2_writing;
return CURLE_OK;
}
/* There is no easy way to override only the CN matching.
@@ -524,7 +539,7 @@ cyassl_connect_step2(struct connectdata *conn,
curl_asn1Element *pubkey;
CURLcode result;
- x509 = SSL_get_peer_certificate(conssl->handle);
+ x509 = SSL_get_peer_certificate(BACKEND->handle);
if(!x509) {
failf(data, "SSL: failed retrieving server certificate");
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
@@ -536,7 +551,7 @@ cyassl_connect_step2(struct connectdata *conn,
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
}
- memset(&x509_parsed, 0, sizeof x509_parsed);
+ memset(&x509_parsed, 0, sizeof(x509_parsed));
if(Curl_parseX509(&x509_parsed, x509_der, x509_der + x509_der_len))
return CURLE_SSL_PINNEDPUBKEYNOTMATCH;
@@ -566,7 +581,7 @@ cyassl_connect_step2(struct connectdata *conn,
char *protocol = NULL;
unsigned short protocol_len = 0;
- rc = wolfSSL_ALPN_GetProtocol(conssl->handle, &protocol, &protocol_len);
+ rc = wolfSSL_ALPN_GetProtocol(BACKEND->handle, &protocol, &protocol_len);
if(rc == SSL_SUCCESS) {
infof(data, "ALPN, server accepted to use %.*s\n", protocol_len,
@@ -585,6 +600,8 @@ cyassl_connect_step2(struct connectdata *conn,
else
infof(data, "ALPN, unrecognized protocol %.*s\n", protocol_len,
protocol);
+ Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
+ BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
}
else if(rc == SSL_ALPN_NOT_FOUND)
infof(data, "ALPN, server did not agree to a protocol\n");
@@ -595,11 +612,11 @@ cyassl_connect_step2(struct connectdata *conn,
}
#endif /* HAVE_ALPN */
- conssl->connecting_state = ssl_connect_3;
+ connssl->connecting_state = ssl_connect_3;
#if (LIBCYASSL_VERSION_HEX >= 0x03009010)
infof(data, "SSL connection using %s / %s\n",
- wolfSSL_get_version(conssl->handle),
- wolfSSL_get_cipher_name(conssl->handle));
+ wolfSSL_get_version(BACKEND->handle),
+ wolfSSL_get_cipher_name(BACKEND->handle));
#else
infof(data, "SSL connected\n");
#endif
@@ -623,7 +640,7 @@ cyassl_connect_step3(struct connectdata *conn,
SSL_SESSION *our_ssl_sessionid;
void *old_ssl_sessionid = NULL;
- our_ssl_sessionid = SSL_get_session(connssl->handle);
+ our_ssl_sessionid = SSL_get_session(BACKEND->handle);
Curl_ssl_sessionid_lock(conn);
incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL,
@@ -660,12 +677,13 @@ static ssize_t cyassl_send(struct connectdata *conn,
size_t len,
CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
char error_buffer[CYASSL_MAX_ERROR_SZ];
int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
- int rc = SSL_write(conn->ssl[sockindex].handle, mem, memlen);
+ int rc = SSL_write(BACKEND->handle, mem, memlen);
if(rc < 0) {
- int err = SSL_get_error(conn->ssl[sockindex].handle, rc);
+ int err = SSL_get_error(BACKEND->handle, rc);
switch(err) {
case SSL_ERROR_WANT_READ:
@@ -684,18 +702,18 @@ static ssize_t cyassl_send(struct connectdata *conn,
return rc;
}
-void Curl_cyassl_close(struct connectdata *conn, int sockindex)
+static void Curl_cyassl_close(struct connectdata *conn, int sockindex)
{
- struct ssl_connect_data *conssl = &conn->ssl[sockindex];
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
- if(conssl->handle) {
- (void)SSL_shutdown(conssl->handle);
- SSL_free(conssl->handle);
- conssl->handle = NULL;
+ if(BACKEND->handle) {
+ (void)SSL_shutdown(BACKEND->handle);
+ SSL_free(BACKEND->handle);
+ BACKEND->handle = NULL;
}
- if(conssl->ctx) {
- SSL_CTX_free(conssl->ctx);
- conssl->ctx = NULL;
+ if(BACKEND->ctx) {
+ SSL_CTX_free(BACKEND->ctx);
+ BACKEND->ctx = NULL;
}
}
@@ -705,12 +723,13 @@ static ssize_t cyassl_recv(struct connectdata *conn,
size_t buffersize,
CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[num];
char error_buffer[CYASSL_MAX_ERROR_SZ];
int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
- int nread = SSL_read(conn->ssl[num].handle, buf, buffsize);
+ int nread = SSL_read(BACKEND->handle, buf, buffsize);
if(nread < 0) {
- int err = SSL_get_error(conn->ssl[num].handle, nread);
+ int err = SSL_get_error(BACKEND->handle, nread);
switch(err) {
case SSL_ERROR_ZERO_RETURN: /* no more data */
@@ -732,37 +751,45 @@ static ssize_t cyassl_recv(struct connectdata *conn,
}
-void Curl_cyassl_session_free(void *ptr)
+static void Curl_cyassl_session_free(void *ptr)
{
(void)ptr;
/* CyaSSL reuses sessions on own, no free */
}
-size_t Curl_cyassl_version(char *buffer, size_t size)
+static size_t Curl_cyassl_version(char *buffer, size_t size)
{
#if LIBCYASSL_VERSION_HEX >= 0x03006000
- return snprintf(buffer, size, "wolfSSL/%s", wolfSSL_lib_version());
+ return msnprintf(buffer, size, "wolfSSL/%s", wolfSSL_lib_version());
#elif defined(WOLFSSL_VERSION)
- return snprintf(buffer, size, "wolfSSL/%s", WOLFSSL_VERSION);
+ return msnprintf(buffer, size, "wolfSSL/%s", WOLFSSL_VERSION);
#elif defined(CYASSL_VERSION)
- return snprintf(buffer, size, "CyaSSL/%s", CYASSL_VERSION);
+ return msnprintf(buffer, size, "CyaSSL/%s", CYASSL_VERSION);
#else
- return snprintf(buffer, size, "CyaSSL/%s", "<1.8.8");
+ return msnprintf(buffer, size, "CyaSSL/%s", "<1.8.8");
#endif
}
-int Curl_cyassl_init(void)
+static int Curl_cyassl_init(void)
{
return (CyaSSL_Init() == SSL_SUCCESS);
}
-bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex)
+static void Curl_cyassl_cleanup(void)
{
- if(conn->ssl[connindex].handle) /* SSL is in use */
- return (0 != SSL_pending(conn->ssl[connindex].handle)) ? TRUE : FALSE;
+ CyaSSL_Cleanup();
+}
+
+
+static bool Curl_cyassl_data_pending(const struct connectdata* conn,
+ int connindex)
+{
+ const struct ssl_connect_data *connssl = &conn->ssl[connindex];
+ if(BACKEND->handle) /* SSL is in use */
+ return (0 != SSL_pending(BACKEND->handle)) ? TRUE : FALSE;
else
return FALSE;
}
@@ -772,14 +799,14 @@ bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex)
* This function is called to shut down the SSL layer but keep the
* socket open (CCC - Clear Command Channel)
*/
-int Curl_cyassl_shutdown(struct connectdata *conn, int sockindex)
+static int Curl_cyassl_shutdown(struct connectdata *conn, int sockindex)
{
int retval = 0;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
- if(connssl->handle) {
- SSL_free(connssl->handle);
- connssl->handle = NULL;
+ if(BACKEND->handle) {
+ SSL_free(BACKEND->handle);
+ BACKEND->handle = NULL;
}
return retval;
}
@@ -804,7 +831,7 @@ cyassl_connect_common(struct connectdata *conn,
return CURLE_OK;
}
- if(ssl_connect_1==connssl->connecting_state) {
+ if(ssl_connect_1 == connssl->connecting_state) {
/* Find out how much more time we're allowed */
timeout_ms = Curl_timeleft(data, NULL, TRUE);
@@ -836,9 +863,9 @@ cyassl_connect_common(struct connectdata *conn,
if(connssl->connecting_state == ssl_connect_2_reading
|| connssl->connecting_state == ssl_connect_2_writing) {
- curl_socket_t writefd = ssl_connect_2_writing==
+ curl_socket_t writefd = ssl_connect_2_writing ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
- curl_socket_t readfd = ssl_connect_2_reading==
+ curl_socket_t readfd = ssl_connect_2_reading ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
@@ -899,18 +926,14 @@ cyassl_connect_common(struct connectdata *conn,
}
-CURLcode
-Curl_cyassl_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done)
+static CURLcode Curl_cyassl_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
{
return cyassl_connect_common(conn, sockindex, TRUE, done);
}
-CURLcode
-Curl_cyassl_connect(struct connectdata *conn,
- int sockindex)
+static CURLcode Curl_cyassl_connect(struct connectdata *conn, int sockindex)
{
CURLcode result;
bool done = FALSE;
@@ -924,9 +947,8 @@ Curl_cyassl_connect(struct connectdata *conn,
return CURLE_OK;
}
-CURLcode Curl_cyassl_random(struct Curl_easy *data,
- unsigned char *entropy,
- size_t length)
+static CURLcode Curl_cyassl_random(struct Curl_easy *data,
+ unsigned char *entropy, size_t length)
{
RNG rng;
(void)data;
@@ -936,19 +958,61 @@ CURLcode Curl_cyassl_random(struct Curl_easy *data,
return CURLE_FAILED_INIT;
if(RNG_GenerateBlock(&rng, entropy, (unsigned)length))
return CURLE_FAILED_INIT;
+ if(FreeRng(&rng))
+ return CURLE_FAILED_INIT;
return CURLE_OK;
}
-void Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum /* output */,
- size_t unused)
+static CURLcode Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
+ size_t tmplen,
+ unsigned char *sha256sum /* output */,
+ size_t unused)
{
Sha256 SHA256pw;
(void)unused;
InitSha256(&SHA256pw);
Sha256Update(&SHA256pw, tmp, (word32)tmplen);
Sha256Final(&SHA256pw, sha256sum);
+ return CURLE_OK;
+}
+
+static void *Curl_cyassl_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info UNUSED_PARAM)
+{
+ (void)info;
+ return BACKEND->handle;
}
+const struct Curl_ssl Curl_ssl_cyassl = {
+ { CURLSSLBACKEND_WOLFSSL, "WolfSSL" }, /* info */
+
+#ifdef KEEP_PEER_CERT
+ SSLSUPP_PINNEDPUBKEY |
+#endif
+ SSLSUPP_SSL_CTX,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_cyassl_init, /* init */
+ Curl_cyassl_cleanup, /* cleanup */
+ Curl_cyassl_version, /* version */
+ Curl_none_check_cxn, /* check_cxn */
+ Curl_cyassl_shutdown, /* shutdown */
+ Curl_cyassl_data_pending, /* data_pending */
+ Curl_cyassl_random, /* random */
+ Curl_none_cert_status_request, /* cert_status_request */
+ Curl_cyassl_connect, /* connect */
+ Curl_cyassl_connect_nonblocking, /* connect_nonblocking */
+ Curl_cyassl_get_internals, /* get_internals */
+ Curl_cyassl_close, /* close_one */
+ Curl_none_close_all, /* close_all */
+ Curl_cyassl_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_none_md5sum, /* md5sum */
+ Curl_cyassl_sha256sum /* sha256sum */
+};
+
#endif
diff --git a/Utilities/cmcurl/lib/vtls/cyassl.h b/Utilities/cmcurl/lib/vtls/cyassl.h
index f47719e4e..01e11cc23 100644
--- a/Utilities/cmcurl/lib/vtls/cyassl.h
+++ b/Utilities/cmcurl/lib/vtls/cyassl.h
@@ -25,68 +25,7 @@
#ifdef USE_CYASSL
-/* KEEP_PEER_CERT is a product of the presence of build time symbol
- OPENSSL_EXTRA without NO_CERTS, depending on the version. KEEP_PEER_CERT is
- in wolfSSL's settings.h, and the latter two are build time symbols in
- options.h. */
-#ifndef KEEP_PEER_CERT
-#if defined(HAVE_CYASSL_GET_PEER_CERTIFICATE) || \
- defined(HAVE_WOLFSSL_GET_PEER_CERTIFICATE) || \
- (defined(OPENSSL_EXTRA) && !defined(NO_CERTS))
-#define KEEP_PEER_CERT
-#endif
-#endif
-
-CURLcode Curl_cyassl_connect(struct connectdata *conn, int sockindex);
-bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex);
-int Curl_cyassl_shutdown(struct connectdata* conn, int sockindex);
-
- /* close a SSL connection */
-void Curl_cyassl_close(struct connectdata *conn, int sockindex);
-
-void Curl_cyassl_session_free(void *ptr);
-size_t Curl_cyassl_version(char *buffer, size_t size);
-int Curl_cyassl_shutdown(struct connectdata *conn, int sockindex);
-int Curl_cyassl_init(void);
-CURLcode Curl_cyassl_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done);
-CURLcode Curl_cyassl_random(struct Curl_easy *data,
- unsigned char *entropy,
- size_t length);
-void Curl_cyassl_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum, /* output */
- size_t unused);
-
-/* Set the API backend definition to CyaSSL */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_CYASSL
-
-/* this backend supports CURLOPT_SSL_CTX_* */
-#define have_curlssl_ssl_ctx 1
-
-#ifdef KEEP_PEER_CERT
-/* this backend supports CURLOPT_PINNEDPUBLICKEY */
-#define have_curlssl_pinnedpubkey 1
-#endif
-
-/* API setup for CyaSSL */
-#define curlssl_init Curl_cyassl_init
-#define curlssl_cleanup() Curl_nop_stmt
-#define curlssl_connect Curl_cyassl_connect
-#define curlssl_connect_nonblocking Curl_cyassl_connect_nonblocking
-#define curlssl_session_free(x) Curl_cyassl_session_free(x)
-#define curlssl_close_all(x) ((void)x)
-#define curlssl_close Curl_cyassl_close
-#define curlssl_shutdown(x,y) Curl_cyassl_shutdown(x,y)
-#define curlssl_set_engine(x,y) ((void)x, (void)y, CURLE_NOT_BUILT_IN)
-#define curlssl_set_engine_default(x) ((void)x, CURLE_NOT_BUILT_IN)
-#define curlssl_engines_list(x) ((void)x, (struct curl_slist *)NULL)
-#define curlssl_version Curl_cyassl_version
-#define curlssl_check_cxn(x) ((void)x, -1)
-#define curlssl_data_pending(x,y) Curl_cyassl_data_pending(x,y)
-#define curlssl_random(x,y,z) Curl_cyassl_random(x,y,z)
-#define curlssl_sha256sum(a,b,c,d) Curl_cyassl_sha256sum(a,b,c,d)
+extern const struct Curl_ssl Curl_ssl_cyassl;
#endif /* USE_CYASSL */
#endif /* HEADER_CURL_CYASSL_H */
diff --git a/Utilities/cmcurl/lib/vtls/gskit.c b/Utilities/cmcurl/lib/vtls/gskit.c
index bf75bddc2..b93ff5d4f 100644
--- a/Utilities/cmcurl/lib/vtls/gskit.c
+++ b/Utilities/cmcurl/lib/vtls/gskit.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, 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
@@ -61,9 +61,7 @@
#endif
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
+#include <limits.h>
#include <curl/curl.h>
#include "urldata.h"
@@ -98,6 +96,14 @@
#define CURL_GSKPROTO_TLSV12_MASK (1 << CURL_GSKPROTO_TLSV12)
#define CURL_GSKPROTO_LAST 5
+struct ssl_backend_data {
+ gsk_handle handle;
+ int iocport;
+ int localfd;
+ int remotefd;
+};
+
+#define BACKEND connssl->backend
/* Supported ciphers. */
typedef struct {
@@ -322,7 +328,7 @@ static CURLcode set_ciphers(struct connectdata *conn,
GSKit tokens are always shorter than their cipher names, allocated buffers
will always be large enough to accommodate the result. */
l = strlen(cipherlist) + 1;
- memset((char *) ciphers, 0, sizeof ciphers);
+ memset((char *) ciphers, 0, sizeof(ciphers));
for(i = 0; i < CURL_GSKPROTO_LAST; i++) {
ciphers[i].buf = malloc(l);
if(!ciphers[i].buf) {
@@ -427,7 +433,7 @@ static CURLcode set_ciphers(struct connectdata *conn,
}
-int Curl_gskit_init(void)
+static int Curl_gskit_init(void)
{
/* No initialisation needed. */
@@ -435,7 +441,7 @@ int Curl_gskit_init(void)
}
-void Curl_gskit_cleanup(void)
+static void Curl_gskit_cleanup(void)
{
/* Nothing to do. */
}
@@ -495,14 +501,14 @@ static void cancel_async_handshake(struct connectdata *conn, int sockindex)
Qso_OverlappedIO_t cstat;
if(QsoCancelOperation(conn->sock[sockindex], 0) > 0)
- QsoWaitForIOCompletion(connssl->iocport, &cstat, (struct timeval *) NULL);
+ QsoWaitForIOCompletion(BACKEND->iocport, &cstat, (struct timeval *) NULL);
}
static void close_async_handshake(struct ssl_connect_data *connssl)
{
- QsoDestroyIOCompletionPort(connssl->iocport);
- connssl->iocport = -1;
+ QsoDestroyIOCompletionPort(BACKEND->iocport);
+ BACKEND->iocport = -1;
}
/* SSL over SSL
@@ -530,18 +536,18 @@ inetsocketpair(int sv[2])
lfd = socket(AF_INET, SOCK_STREAM, 0);
if(lfd < 0)
return -1;
- memset((char *) &addr1, 0, sizeof addr1);
+ memset((char *) &addr1, 0, sizeof(addr1));
addr1.sin_family = AF_INET;
addr1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr1.sin_port = 0;
- if(bind(lfd, (struct sockaddr *) &addr1, sizeof addr1) ||
+ if(bind(lfd, (struct sockaddr *) &addr1, sizeof(addr1)) ||
listen(lfd, 2) < 0) {
close(lfd);
return -1;
}
/* Get the allocated port. */
- len = sizeof addr1;
+ len = sizeof(addr1);
if(getsockname(lfd, (struct sockaddr *) &addr1, &len) < 0) {
close(lfd);
return -1;
@@ -556,7 +562,7 @@ inetsocketpair(int sv[2])
/* Request unblocking connection to the listening socket. */
curlx_nonblock(cfd, TRUE);
- if(connect(cfd, (struct sockaddr *) &addr1, sizeof addr1) < 0 &&
+ if(connect(cfd, (struct sockaddr *) &addr1, sizeof(addr1)) < 0 &&
errno != EINPROGRESS) {
close(lfd);
close(cfd);
@@ -564,7 +570,7 @@ inetsocketpair(int sv[2])
}
/* Get the client dynamic port for intrusion check below. */
- len = sizeof addr2;
+ len = sizeof(addr2);
if(getsockname(cfd, (struct sockaddr *) &addr2, &len) < 0) {
close(lfd);
close(cfd);
@@ -574,7 +580,7 @@ inetsocketpair(int sv[2])
/* Accept the incoming connection and get the server socket. */
curlx_nonblock(lfd, TRUE);
for(;;) {
- len = sizeof addr1;
+ len = sizeof(addr1);
sfd = accept(lfd, (struct sockaddr *) &addr1, &len);
if(sfd < 0) {
close(lfd);
@@ -620,12 +626,12 @@ static int pipe_ssloverssl(struct connectdata *conn, int sockindex,
FD_ZERO(&fds_write);
n = -1;
if(directions & SOS_READ) {
- FD_SET(connssl->remotefd, &fds_write);
- n = connssl->remotefd;
+ FD_SET(BACKEND->remotefd, &fds_write);
+ n = BACKEND->remotefd;
}
if(directions & SOS_WRITE) {
- FD_SET(connssl->remotefd, &fds_read);
- n = connssl->remotefd;
+ FD_SET(BACKEND->remotefd, &fds_read);
+ n = BACKEND->remotefd;
FD_SET(conn->sock[sockindex], &fds_write);
if(n < conn->sock[sockindex])
n = conn->sock[sockindex];
@@ -634,14 +640,15 @@ static int pipe_ssloverssl(struct connectdata *conn, int sockindex,
if(i < 0)
return -1; /* Select error. */
- if(FD_ISSET(connssl->remotefd, &fds_write)) {
+ if(FD_ISSET(BACKEND->remotefd, &fds_write)) {
/* Try getting data from HTTPS proxy and pipe it upstream. */
n = 0;
- i = gsk_secure_soc_read(connproxyssl->handle, buf, sizeof buf, &n);
+ i = gsk_secure_soc_read(connproxyssl->backend->handle,
+ buf, sizeof(buf), &n);
switch(i) {
case GSK_OK:
if(n) {
- i = write(connssl->remotefd, buf, n);
+ i = write(BACKEND->remotefd, buf, n);
if(i < 0)
return -1;
ret = 1;
@@ -655,14 +662,14 @@ static int pipe_ssloverssl(struct connectdata *conn, int sockindex,
}
}
- if(FD_ISSET(connssl->remotefd, &fds_read) &&
+ if(FD_ISSET(BACKEND->remotefd, &fds_read) &&
FD_ISSET(conn->sock[sockindex], &fds_write)) {
/* Pipe data to HTTPS proxy. */
- n = read(connssl->remotefd, buf, sizeof buf);
+ n = read(BACKEND->remotefd, buf, sizeof(buf));
if(n < 0)
return -1;
if(n) {
- i = gsk_secure_soc_write(connproxyssl->handle, buf, n, &m);
+ i = gsk_secure_soc_write(connproxyssl->backend->handle, buf, n, &m);
if(i != GSK_OK || n != m)
return -1;
ret = 1;
@@ -676,23 +683,23 @@ static int pipe_ssloverssl(struct connectdata *conn, int sockindex,
static void close_one(struct ssl_connect_data *connssl,
struct connectdata *conn, int sockindex)
{
- if(connssl->handle) {
- gskit_status(conn->data, gsk_secure_soc_close(&connssl->handle),
+ if(BACKEND->handle) {
+ gskit_status(conn->data, gsk_secure_soc_close(&BACKEND->handle),
"gsk_secure_soc_close()", 0);
/* Last chance to drain output. */
while(pipe_ssloverssl(conn, sockindex, SOS_WRITE) > 0)
;
- connssl->handle = (gsk_handle) NULL;
- if(connssl->localfd >= 0) {
- close(connssl->localfd);
- connssl->localfd = -1;
+ BACKEND->handle = (gsk_handle) NULL;
+ if(BACKEND->localfd >= 0) {
+ close(BACKEND->localfd);
+ BACKEND->localfd = -1;
}
- if(connssl->remotefd >= 0) {
- close(connssl->remotefd);
- connssl->remotefd = -1;
+ if(BACKEND->remotefd >= 0) {
+ close(BACKEND->remotefd);
+ BACKEND->remotefd = -1;
}
}
- if(connssl->iocport >= 0)
+ if(BACKEND->iocport >= 0)
close_async_handshake(connssl);
}
@@ -700,13 +707,14 @@ static void close_one(struct ssl_connect_data *connssl,
static ssize_t gskit_send(struct connectdata *conn, int sockindex,
const void *mem, size_t len, CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
struct Curl_easy *data = conn->data;
CURLcode cc = CURLE_SEND_ERROR;
int written;
if(pipe_ssloverssl(conn, sockindex, SOS_WRITE) >= 0) {
cc = gskit_status(data,
- gsk_secure_soc_write(conn->ssl[sockindex].handle,
+ gsk_secure_soc_write(BACKEND->handle,
(char *) mem, (int) len, &written),
"gsk_secure_soc_write()", CURLE_SEND_ERROR);
if(cc == CURLE_OK)
@@ -724,14 +732,14 @@ static ssize_t gskit_send(struct connectdata *conn, int sockindex,
static ssize_t gskit_recv(struct connectdata *conn, int num, char *buf,
size_t buffersize, CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[num];
struct Curl_easy *data = conn->data;
- int buffsize;
int nread;
CURLcode cc = CURLE_RECV_ERROR;
if(pipe_ssloverssl(conn, num, SOS_READ) >= 0) {
- buffsize = buffersize > (size_t) INT_MAX? INT_MAX: (int) buffersize;
- cc = gskit_status(data, gsk_secure_soc_read(conn->ssl[num].handle,
+ int buffsize = buffersize > (size_t) INT_MAX? INT_MAX: (int) buffersize;
+ cc = gskit_status(data, gsk_secure_soc_read(BACKEND->handle,
buf, buffsize, &nread),
"gsk_secure_soc_read()", CURLE_RECV_ERROR);
}
@@ -757,8 +765,6 @@ set_ssl_version_min_max(unsigned int *protoflags, struct connectdata *conn)
long i = ssl_version;
switch(ssl_version_max) {
case CURL_SSLVERSION_MAX_NONE:
- ssl_version_max = ssl_version;
- break;
case CURL_SSLVERSION_MAX_DEFAULT:
ssl_version_max = CURL_SSLVERSION_TLSv1_2;
break;
@@ -799,17 +805,16 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
conn->host.name;
const char *sni;
unsigned int protoflags = 0;
- long timeout;
Qso_OverlappedIO_t commarea;
int sockpair[2];
static const int sobufsize = CURL_MAX_WRITE_SIZE;
/* Create SSL environment, start (preferably asynchronous) handshake. */
- connssl->handle = (gsk_handle) NULL;
- connssl->iocport = -1;
- connssl->localfd = -1;
- connssl->remotefd = -1;
+ BACKEND->handle = (gsk_handle) NULL;
+ BACKEND->iocport = -1;
+ BACKEND->localfd = -1;
+ BACKEND->remotefd = -1;
/* GSKit supports two ways of specifying an SSL context: either by
* application identifier (that should have been defined at the system
@@ -842,7 +847,7 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
}
/* Create secure session. */
- result = gskit_status(data, gsk_secure_soc_open(envir, &connssl->handle),
+ result = gskit_status(data, gsk_secure_soc_open(envir, &BACKEND->handle),
"gsk_secure_soc_open()", CURLE_SSL_CONNECT_ERROR);
gsk_environment_close(&envir);
if(result)
@@ -852,18 +857,18 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
if(conn->proxy_ssl[sockindex].use) {
if(inetsocketpair(sockpair))
return CURLE_SSL_CONNECT_ERROR;
- connssl->localfd = sockpair[0];
- connssl->remotefd = sockpair[1];
- setsockopt(connssl->localfd, SOL_SOCKET, SO_RCVBUF,
- (void *) sobufsize, sizeof sobufsize);
- setsockopt(connssl->remotefd, SOL_SOCKET, SO_RCVBUF,
- (void *) sobufsize, sizeof sobufsize);
- setsockopt(connssl->localfd, SOL_SOCKET, SO_SNDBUF,
- (void *) sobufsize, sizeof sobufsize);
- setsockopt(connssl->remotefd, SOL_SOCKET, SO_SNDBUF,
- (void *) sobufsize, sizeof sobufsize);
- curlx_nonblock(connssl->localfd, TRUE);
- curlx_nonblock(connssl->remotefd, TRUE);
+ BACKEND->localfd = sockpair[0];
+ BACKEND->remotefd = sockpair[1];
+ setsockopt(BACKEND->localfd, SOL_SOCKET, SO_RCVBUF,
+ (void *) sobufsize, sizeof(sobufsize));
+ setsockopt(BACKEND->remotefd, SOL_SOCKET, SO_RCVBUF,
+ (void *) sobufsize, sizeof(sobufsize));
+ setsockopt(BACKEND->localfd, SOL_SOCKET, SO_SNDBUF,
+ (void *) sobufsize, sizeof(sobufsize));
+ setsockopt(BACKEND->remotefd, SOL_SOCKET, SO_SNDBUF,
+ (void *) sobufsize, sizeof(sobufsize));
+ curlx_nonblock(BACKEND->localfd, TRUE);
+ curlx_nonblock(BACKEND->remotefd, TRUE);
}
/* Determine which SSL/TLS version should be enabled. */
@@ -897,7 +902,7 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
/* Process SNI. Ignore if not supported (on OS400 < V7R1). */
if(sni) {
- result = set_buffer(data, connssl->handle,
+ result = set_buffer(data, BACKEND->handle,
GSK_SSL_EXTN_SERVERNAME_REQUEST, sni, TRUE);
if(result == CURLE_UNSUPPORTED_PROTOCOL)
result = CURLE_OK;
@@ -907,38 +912,38 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
if(!result) {
/* Compute the handshake timeout. Since GSKit granularity is 1 second,
we round up the required value. */
- timeout = Curl_timeleft(data, NULL, TRUE);
+ long timeout = Curl_timeleft(data, NULL, TRUE);
if(timeout < 0)
result = CURLE_OPERATION_TIMEDOUT;
else
- result = set_numeric(data, connssl->handle, GSK_HANDSHAKE_TIMEOUT,
+ result = set_numeric(data, BACKEND->handle, GSK_HANDSHAKE_TIMEOUT,
(timeout + 999) / 1000);
}
if(!result)
- result = set_numeric(data, connssl->handle, GSK_OS400_READ_TIMEOUT, 1);
+ result = set_numeric(data, BACKEND->handle, GSK_OS400_READ_TIMEOUT, 1);
if(!result)
- result = set_numeric(data, connssl->handle, GSK_FD, connssl->localfd >= 0?
- connssl->localfd: conn->sock[sockindex]);
+ result = set_numeric(data, BACKEND->handle, GSK_FD, BACKEND->localfd >= 0?
+ BACKEND->localfd: conn->sock[sockindex]);
if(!result)
- result = set_ciphers(conn, connssl->handle, &protoflags);
+ result = set_ciphers(conn, BACKEND->handle, &protoflags);
if(!protoflags) {
failf(data, "No SSL protocol/cipher combination enabled");
result = CURLE_SSL_CIPHER;
}
if(!result)
- result = set_enum(data, connssl->handle, GSK_PROTOCOL_SSLV2,
+ result = set_enum(data, BACKEND->handle, GSK_PROTOCOL_SSLV2,
(protoflags & CURL_GSKPROTO_SSLV2_MASK)?
GSK_PROTOCOL_SSLV2_ON: GSK_PROTOCOL_SSLV2_OFF, FALSE);
if(!result)
- result = set_enum(data, connssl->handle, GSK_PROTOCOL_SSLV3,
+ result = set_enum(data, BACKEND->handle, GSK_PROTOCOL_SSLV3,
(protoflags & CURL_GSKPROTO_SSLV3_MASK)?
GSK_PROTOCOL_SSLV3_ON: GSK_PROTOCOL_SSLV3_OFF, FALSE);
if(!result)
- result = set_enum(data, connssl->handle, GSK_PROTOCOL_TLSV1,
+ result = set_enum(data, BACKEND->handle, GSK_PROTOCOL_TLSV1,
(protoflags & CURL_GSKPROTO_TLSV10_MASK)?
GSK_PROTOCOL_TLSV1_ON: GSK_PROTOCOL_TLSV1_OFF, FALSE);
if(!result) {
- result = set_enum(data, connssl->handle, GSK_PROTOCOL_TLSV11,
+ result = set_enum(data, BACKEND->handle, GSK_PROTOCOL_TLSV11,
(protoflags & CURL_GSKPROTO_TLSV11_MASK)?
GSK_TRUE: GSK_FALSE, TRUE);
if(result == CURLE_UNSUPPORTED_PROTOCOL) {
@@ -950,7 +955,7 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
}
}
if(!result) {
- result = set_enum(data, connssl->handle, GSK_PROTOCOL_TLSV12,
+ result = set_enum(data, BACKEND->handle, GSK_PROTOCOL_TLSV12,
(protoflags & CURL_GSKPROTO_TLSV12_MASK)?
GSK_TRUE: GSK_FALSE, TRUE);
if(result == CURLE_UNSUPPORTED_PROTOCOL) {
@@ -962,18 +967,18 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
}
}
if(!result)
- result = set_enum(data, connssl->handle, GSK_SERVER_AUTH_TYPE,
+ result = set_enum(data, BACKEND->handle, GSK_SERVER_AUTH_TYPE,
verifypeer? GSK_SERVER_AUTH_FULL:
GSK_SERVER_AUTH_PASSTHRU, FALSE);
if(!result) {
/* Start handshake. Try asynchronous first. */
- memset(&commarea, 0, sizeof commarea);
- connssl->iocport = QsoCreateIOCompletionPort();
- if(connssl->iocport != -1) {
+ memset(&commarea, 0, sizeof(commarea));
+ BACKEND->iocport = QsoCreateIOCompletionPort();
+ if(BACKEND->iocport != -1) {
result = gskit_status(data,
- gsk_secure_soc_startInit(connssl->handle,
- connssl->iocport,
+ gsk_secure_soc_startInit(BACKEND->handle,
+ BACKEND->iocport,
&commarea),
"gsk_secure_soc_startInit()",
CURLE_SSL_CONNECT_ERROR);
@@ -993,7 +998,7 @@ static CURLcode gskit_connect_step1(struct connectdata *conn, int sockindex)
}
else {
/* No more completion port available. Use synchronous IO. */
- result = gskit_status(data, gsk_secure_soc_init(connssl->handle),
+ result = gskit_status(data, gsk_secure_soc_init(BACKEND->handle),
"gsk_secure_soc_init()", CURLE_SSL_CONNECT_ERROR);
if(!result) {
connssl->connecting_state = ssl_connect_3;
@@ -1014,19 +1019,18 @@ static CURLcode gskit_connect_step2(struct connectdata *conn, int sockindex,
struct Curl_easy *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
Qso_OverlappedIO_t cstat;
- long timeout_ms;
struct timeval stmv;
CURLcode result;
/* Poll or wait for end of SSL asynchronous handshake. */
for(;;) {
- timeout_ms = nonblocking? 0: Curl_timeleft(data, NULL, TRUE);
+ long timeout_ms = nonblocking? 0: Curl_timeleft(data, NULL, TRUE);
if(timeout_ms < 0)
timeout_ms = 0;
stmv.tv_sec = timeout_ms / 1000;
stmv.tv_usec = (timeout_ms - stmv.tv_sec * 1000) * 1000;
- switch(QsoWaitForIOCompletion(connssl->iocport, &cstat, &stmv)) {
+ switch(QsoWaitForIOCompletion(BACKEND->iocport, &cstat, &stmv)) {
case 1: /* Operation complete. */
break;
case -1: /* An error occurred: handshake still in progress. */
@@ -1070,16 +1074,17 @@ static CURLcode gskit_connect_step3(struct connectdata *conn, int sockindex)
const char *cert = (const char *) NULL;
const char *certend;
const char *ptr;
- int i;
CURLcode result;
/* SSL handshake done: gather certificate info and verify host. */
- if(gskit_status(data, gsk_attribute_get_cert_info(connssl->handle,
+ if(gskit_status(data, gsk_attribute_get_cert_info(BACKEND->handle,
GSK_PARTNER_CERT_INFO,
&cdev, &cdec),
"gsk_attribute_get_cert_info()", CURLE_SSL_CONNECT_ERROR) ==
CURLE_OK) {
+ int i;
+
infof(data, "Server certificate:\n");
p = cdev;
for(i = 0; i++ < cdec; p++)
@@ -1153,7 +1158,6 @@ static CURLcode gskit_connect_common(struct connectdata *conn, int sockindex,
struct Curl_easy *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
long timeout_ms;
- Qso_OverlappedIO_t cstat;
CURLcode result = CURLE_OK;
*done = connssl->state == ssl_connection_complete;
@@ -1216,9 +1220,8 @@ static CURLcode gskit_connect_common(struct connectdata *conn, int sockindex,
}
-CURLcode Curl_gskit_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done)
+static CURLcode Curl_gskit_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
{
CURLcode result;
@@ -1229,7 +1232,7 @@ CURLcode Curl_gskit_connect_nonblocking(struct connectdata *conn,
}
-CURLcode Curl_gskit_connect(struct connectdata *conn, int sockindex)
+static CURLcode Curl_gskit_connect(struct connectdata *conn, int sockindex)
{
CURLcode result;
bool done;
@@ -1245,27 +1248,28 @@ CURLcode Curl_gskit_connect(struct connectdata *conn, int sockindex)
}
-void Curl_gskit_close(struct connectdata *conn, int sockindex)
+static void Curl_gskit_close(struct connectdata *conn, int sockindex)
{
close_one(&conn->ssl[sockindex], conn, sockindex);
close_one(&conn->proxy_ssl[sockindex], conn, sockindex);
}
-int Curl_gskit_shutdown(struct connectdata *conn, int sockindex)
+static int Curl_gskit_shutdown(struct connectdata *conn, int sockindex)
{
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
struct Curl_easy *data = conn->data;
- ssize_t nread;
int what;
int rc;
char buf[120];
- if(!connssl->handle)
+ if(!BACKEND->handle)
return 0;
+#ifndef CURL_DISABLE_FTP
if(data->set.ftp_ccc != CURLFTPSSL_CCC_ACTIVE)
return 0;
+#endif
close_one(connssl, conn, sockindex);
rc = 0;
@@ -1273,6 +1277,8 @@ int Curl_gskit_shutdown(struct connectdata *conn, int sockindex)
SSL_SHUTDOWN_TIMEOUT);
for(;;) {
+ ssize_t nread;
+
if(what < 0) {
/* anything that gets here is fatally bad */
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
@@ -1306,32 +1312,70 @@ int Curl_gskit_shutdown(struct connectdata *conn, int sockindex)
}
-size_t Curl_gskit_version(char *buffer, size_t size)
+static size_t Curl_gskit_version(char *buffer, size_t size)
{
- strncpy(buffer, "GSKit", size);
- return strlen(buffer);
+ return msnprintf(buffer, size, "GSKit");
}
-int Curl_gskit_check_cxn(struct connectdata *cxn)
+static int Curl_gskit_check_cxn(struct connectdata *cxn)
{
+ struct ssl_connect_data *connssl = &cxn->ssl[FIRSTSOCKET];
int err;
int errlen;
/* The only thing that can be tested here is at the socket level. */
- if(!cxn->ssl[FIRSTSOCKET].handle)
+ if(!BACKEND->handle)
return 0; /* connection has been closed */
err = 0;
- errlen = sizeof err;
+ errlen = sizeof(err);
if(getsockopt(cxn->sock[FIRSTSOCKET], SOL_SOCKET, SO_ERROR,
(unsigned char *) &err, &errlen) ||
- errlen != sizeof err || err)
+ errlen != sizeof(err) || err)
return 0; /* connection has been closed */
return -1; /* connection status unknown */
}
+static void *Curl_gskit_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info UNUSED_PARAM)
+{
+ (void)info;
+ return BACKEND->handle;
+}
+
+const struct Curl_ssl Curl_ssl_gskit = {
+ { CURLSSLBACKEND_GSKIT, "gskit" }, /* info */
+
+ SSLSUPP_CERTINFO |
+ SSLSUPP_PINNEDPUBKEY,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_gskit_init, /* init */
+ Curl_gskit_cleanup, /* cleanup */
+ Curl_gskit_version, /* version */
+ Curl_gskit_check_cxn, /* check_cxn */
+ Curl_gskit_shutdown, /* shutdown */
+ Curl_none_data_pending, /* data_pending */
+ Curl_none_random, /* random */
+ Curl_none_cert_status_request, /* cert_status_request */
+ Curl_gskit_connect, /* connect */
+ Curl_gskit_connect_nonblocking, /* connect_nonblocking */
+ Curl_gskit_get_internals, /* get_internals */
+ Curl_gskit_close, /* close_one */
+ Curl_none_close_all, /* close_all */
+ /* No session handling for GSKit */
+ Curl_none_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_none_md5sum, /* md5sum */
+ NULL /* sha256sum */
+};
+
#endif /* USE_GSKIT */
diff --git a/Utilities/cmcurl/lib/vtls/gskit.h b/Utilities/cmcurl/lib/vtls/gskit.h
index 229759217..466ee4d9d 100644
--- a/Utilities/cmcurl/lib/vtls/gskit.h
+++ b/Utilities/cmcurl/lib/vtls/gskit.h
@@ -30,44 +30,8 @@
#include "urldata.h"
#ifdef USE_GSKIT
-int Curl_gskit_init(void);
-void Curl_gskit_cleanup(void);
-CURLcode Curl_gskit_connect(struct connectdata *conn, int sockindex);
-CURLcode Curl_gskit_connect_nonblocking(struct connectdata *conn,
- int sockindex, bool *done);
-void Curl_gskit_close(struct connectdata *conn, int sockindex);
-int Curl_gskit_shutdown(struct connectdata *conn, int sockindex);
-size_t Curl_gskit_version(char *buffer, size_t size);
-int Curl_gskit_check_cxn(struct connectdata *cxn);
-
-/* Support HTTPS-proxy */
-/* TODO: add '#define HTTPS_PROXY_SUPPORT 1' and fix test #1014 (if need) */
-
-/* Set the API backend definition to GSKit */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_GSKIT
-
-/* this backend supports CURLOPT_CERTINFO */
-#define have_curlssl_certinfo 1
-
-/* API setup for GSKit */
-#define curlssl_init Curl_gskit_init
-#define curlssl_cleanup Curl_gskit_cleanup
-#define curlssl_connect Curl_gskit_connect
-#define curlssl_connect_nonblocking Curl_gskit_connect_nonblocking
-
-/* No session handling for GSKit */
-#define curlssl_session_free(x) Curl_nop_stmt
-#define curlssl_close_all(x) ((void)x)
-#define curlssl_close Curl_gskit_close
-#define curlssl_shutdown(x,y) Curl_gskit_shutdown(x,y)
-#define curlssl_set_engine(x,y) CURLE_NOT_BUILT_IN
-#define curlssl_set_engine_default(x) CURLE_NOT_BUILT_IN
-#define curlssl_engines_list(x) NULL
-#define curlssl_version Curl_gskit_version
-#define curlssl_check_cxn(x) Curl_gskit_check_cxn(x)
-#define curlssl_data_pending(x,y) 0
-#define curlssl_random(x,y,z) (x=x, y=y, z=z, CURLE_NOT_BUILT_IN)
+extern const struct Curl_ssl Curl_ssl_gskit;
#endif /* USE_GSKIT */
diff --git a/Utilities/cmcurl/lib/vtls/gtls.c b/Utilities/cmcurl/lib/vtls/gtls.c
index 844be2de1..8693cdce3 100644
--- a/Utilities/cmcurl/lib/vtls/gtls.c
+++ b/Utilities/cmcurl/lib/vtls/gtls.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -55,22 +55,12 @@
#include "strcase.h"
#include "warnless.h"
#include "x509asn1.h"
+#include "multiif.h"
#include "curl_printf.h"
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
-/*
- Some hackish cast macros based on:
- https://developer.gnome.org/glib/unstable/glib-Type-Conversion-Macros.html
-*/
-#ifndef GNUTLS_POINTER_TO_INT_CAST
-#define GNUTLS_POINTER_TO_INT_CAST(p) ((int) (long) (p))
-#endif
-#ifndef GNUTLS_INT_TO_POINTER_CAST
-#define GNUTLS_INT_TO_POINTER_CAST(i) ((void *) (long) (i))
-#endif
-
/* Enable GnuTLS debugging by defining GTLSDEBUG */
/*#define GTLSDEBUG */
@@ -105,10 +95,24 @@ static bool gtls_inited = FALSE;
# endif
#endif
+#if (GNUTLS_VERSION_NUMBER >= 0x030603)
+#define HAS_TLS13
+#endif
+
#ifdef HAS_OCSP
# include <gnutls/ocsp.h>
#endif
+struct ssl_backend_data {
+ gnutls_session_t session;
+ gnutls_certificate_credentials_t cred;
+#ifdef USE_TLS_SRP
+ gnutls_srp_client_credentials_t srp_client_cred;
+#endif
+};
+
+#define BACKEND connssl->backend
+
/*
* 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()
@@ -153,7 +157,8 @@ static int gtls_mapped_sockerrno(void)
static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len)
{
- ssize_t ret = swrite(GNUTLS_POINTER_TO_INT_CAST(s), buf, len);
+ curl_socket_t sock = *(curl_socket_t *)s;
+ ssize_t ret = swrite(sock, buf, len);
#if defined(USE_WINSOCK) && !defined(GNUTLS_MAPS_WINSOCK_ERRORS)
if(ret < 0)
gnutls_transport_set_global_errno(gtls_mapped_sockerrno());
@@ -163,7 +168,8 @@ static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len)
static ssize_t Curl_gtls_pull(void *s, void *buf, size_t len)
{
- ssize_t ret = sread(GNUTLS_POINTER_TO_INT_CAST(s), buf, len);
+ curl_socket_t sock = *(curl_socket_t *)s;
+ ssize_t ret = sread(sock, buf, len);
#if defined(USE_WINSOCK) && !defined(GNUTLS_MAPS_WINSOCK_ERRORS)
if(ret < 0)
gnutls_transport_set_global_errno(gtls_mapped_sockerrno());
@@ -188,7 +194,7 @@ static ssize_t Curl_gtls_pull_ssl(void *s, void *buf, size_t len)
* must only be called from within curl_global_init() to keep the thread
* situation under control!
*/
-int Curl_gtls_init(void)
+static int Curl_gtls_init(void)
{
int ret = 1;
if(!gtls_inited) {
@@ -202,13 +208,12 @@ int Curl_gtls_init(void)
return ret;
}
-int Curl_gtls_cleanup(void)
+static void Curl_gtls_cleanup(void)
{
if(gtls_inited) {
gnutls_global_deinit();
gtls_inited = FALSE;
}
- return 1;
}
#ifndef CURL_DISABLE_VERBOSE_STRINGS
@@ -223,17 +228,17 @@ static void showtime(struct Curl_easy *data,
if(result)
return;
- snprintf(str,
- sizeof(str),
- "\t %s: %s, %02d %s %4d %02d:%02d:%02d GMT",
- 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);
+ msnprintf(str,
+ sizeof(str),
+ "\t %s: %s, %02d %s %4d %02d:%02d:%02d GMT",
+ 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\n", str);
}
#endif
@@ -279,13 +284,13 @@ static CURLcode handshake(struct connectdata *conn,
{
struct Curl_easy *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
- gnutls_session_t session = conn->ssl[sockindex].session;
+ gnutls_session_t session = BACKEND->session;
curl_socket_t sockfd = conn->sock[sockindex];
- time_t timeout_ms;
- int rc;
- int what;
for(;;) {
+ time_t timeout_ms;
+ int rc;
+
/* check allowed time left */
timeout_ms = Curl_timeleft(data, NULL, duringconnect);
@@ -298,10 +303,10 @@ static CURLcode handshake(struct connectdata *conn,
/* 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) {
-
- curl_socket_t writefd = ssl_connect_2_writing==
+ int what;
+ curl_socket_t writefd = ssl_connect_2_writing ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
- curl_socket_t readfd = ssl_connect_2_reading==
+ curl_socket_t readfd = ssl_connect_2_reading ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
@@ -390,9 +395,10 @@ set_ssl_version_min_max(int *list, size_t list_size, struct connectdata *conn)
switch(ssl_version_max) {
case CURL_SSLVERSION_MAX_NONE:
- ssl_version_max = ssl_version << 16;
- break;
case CURL_SSLVERSION_MAX_DEFAULT:
+#ifdef HAS_TLS13
+ ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_3;
+#endif
ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_2;
break;
}
@@ -410,8 +416,13 @@ set_ssl_version_min_max(int *list, size_t list_size, struct connectdata *conn)
protocol_priority[protocol_priority_idx++] = GNUTLS_TLS1_2;
break;
case CURL_SSLVERSION_TLSv1_3:
+#ifdef HAS_TLS13
+ protocol_priority[protocol_priority_idx++] = GNUTLS_TLS1_3;
+ break;
+#else
failf(data, "GnuTLS: TLS 1.3 is not yet supported");
return CURLE_SSL_CONNECT_ERROR;
+#endif
}
}
return CURLE_OK;
@@ -429,13 +440,9 @@ set_ssl_version_min_max(const char **prioritylist, struct connectdata *conn)
struct Curl_easy *data = conn->data;
long ssl_version = SSL_CONN_CONFIG(version);
long ssl_version_max = SSL_CONN_CONFIG(version_max);
- if(ssl_version == CURL_SSLVERSION_TLSv1_3 ||
- ssl_version_max == CURL_SSLVERSION_MAX_TLSv1_3) {
- failf(data, "GnuTLS: TLS 1.3 is not yet supported");
- return CURLE_SSL_CONNECT_ERROR;
- }
+
if(ssl_version_max == CURL_SSLVERSION_MAX_NONE) {
- ssl_version_max = ssl_version << 16;
+ ssl_version_max = CURL_SSLVERSION_MAX_DEFAULT;
}
switch(ssl_version | ssl_version_max) {
case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_0:
@@ -447,7 +454,6 @@ set_ssl_version_min_max(const char **prioritylist, struct connectdata *conn)
"+VERS-TLS1.0:+VERS-TLS1.1:" GNUTLS_SRP;
return CURLE_OK;
case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_2:
- case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_DEFAULT:
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
"+VERS-TLS1.0:+VERS-TLS1.1:+VERS-TLS1.2:" GNUTLS_SRP;
return CURLE_OK;
@@ -456,15 +462,54 @@ set_ssl_version_min_max(const char **prioritylist, struct connectdata *conn)
"+VERS-TLS1.1:" GNUTLS_SRP;
return CURLE_OK;
case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_TLSv1_2:
- case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_DEFAULT:
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
"+VERS-TLS1.1:+VERS-TLS1.2:" GNUTLS_SRP;
return CURLE_OK;
case CURL_SSLVERSION_TLSv1_2 | CURL_SSLVERSION_MAX_TLSv1_2:
- case CURL_SSLVERSION_TLSv1_2 | CURL_SSLVERSION_MAX_DEFAULT:
*prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
"+VERS-TLS1.2:" GNUTLS_SRP;
return CURLE_OK;
+ case CURL_SSLVERSION_TLSv1_3 | CURL_SSLVERSION_MAX_TLSv1_3:
+#ifdef HAS_TLS13
+ *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
+ "+VERS-TLS1.3:" GNUTLS_SRP;
+ return CURLE_OK;
+#else
+ failf(data, "GnuTLS: TLS 1.3 is not yet supported");
+ return CURLE_SSL_CONNECT_ERROR;
+#endif
+ case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_DEFAULT:
+ *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
+ "+VERS-TLS1.0:+VERS-TLS1.1:+VERS-TLS1.2:"
+#ifdef HAS_TLS13
+ "+VERS-TLS1.3:"
+#endif
+ GNUTLS_SRP;
+ return CURLE_OK;
+ case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_DEFAULT:
+ *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
+ "+VERS-TLS1.1:+VERS-TLS1.2:"
+#ifdef HAS_TLS13
+ "+VERS-TLS1.3:"
+#endif
+ GNUTLS_SRP;
+ return CURLE_OK;
+ case CURL_SSLVERSION_TLSv1_2 | CURL_SSLVERSION_MAX_DEFAULT:
+ *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
+ "+VERS-TLS1.2:"
+#ifdef HAS_TLS13
+ "+VERS-TLS1.3:"
+#endif
+ GNUTLS_SRP;
+ return CURLE_OK;
+ case CURL_SSLVERSION_TLSv1_3 | CURL_SSLVERSION_MAX_DEFAULT:
+ *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
+ "+VERS-TLS1.2:"
+#ifdef HAS_TLS13
+ "+VERS-TLS1.3:"
+#endif
+ GNUTLS_SRP;
+ return CURLE_OK;
}
failf(data, "GnuTLS: cannot set ssl protocol");
@@ -477,6 +522,7 @@ gtls_connect_step1(struct connectdata *conn,
int sockindex)
{
struct Curl_easy *data = conn->data;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
unsigned int init_flags;
gnutls_session_t session;
int rc;
@@ -512,7 +558,7 @@ gtls_connect_step1(struct connectdata *conn,
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
- if(conn->ssl[sockindex].state == ssl_connection_complete)
+ if(connssl->state == ssl_connection_complete)
/* to make us tolerant against being called more than once for the
same connection */
return CURLE_OK;
@@ -528,7 +574,7 @@ gtls_connect_step1(struct connectdata *conn,
sni = FALSE; /* SSLv3 has no SNI */
/* allocate a cred struct */
- rc = gnutls_certificate_allocate_credentials(&conn->ssl[sockindex].cred);
+ rc = gnutls_certificate_allocate_credentials(&BACKEND->cred);
if(rc != GNUTLS_E_SUCCESS) {
failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc));
return CURLE_SSL_CONNECT_ERROR;
@@ -539,15 +585,14 @@ gtls_connect_step1(struct connectdata *conn,
infof(data, "Using TLS-SRP username: %s\n", SSL_SET_OPTION(username));
rc = gnutls_srp_allocate_client_credentials(
- &conn->ssl[sockindex].srp_client_cred);
+ &BACKEND->srp_client_cred);
if(rc != GNUTLS_E_SUCCESS) {
failf(data, "gnutls_srp_allocate_client_cred() failed: %s",
gnutls_strerror(rc));
return CURLE_OUT_OF_MEMORY;
}
- rc = gnutls_srp_set_client_credentials(conn->ssl[sockindex].
- srp_client_cred,
+ rc = gnutls_srp_set_client_credentials(BACKEND->srp_client_cred,
SSL_SET_OPTION(username),
SSL_SET_OPTION(password));
if(rc != GNUTLS_E_SUCCESS) {
@@ -560,10 +605,10 @@ gtls_connect_step1(struct connectdata *conn,
if(SSL_CONN_CONFIG(CAfile)) {
/* set the trusted CA cert bundle file */
- gnutls_certificate_set_verify_flags(conn->ssl[sockindex].cred,
+ gnutls_certificate_set_verify_flags(BACKEND->cred,
GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
- rc = gnutls_certificate_set_x509_trust_file(conn->ssl[sockindex].cred,
+ rc = gnutls_certificate_set_x509_trust_file(BACKEND->cred,
SSL_CONN_CONFIG(CAfile),
GNUTLS_X509_FMT_PEM);
if(rc < 0) {
@@ -580,7 +625,7 @@ gtls_connect_step1(struct connectdata *conn,
#ifdef HAS_CAPATH
if(SSL_CONN_CONFIG(CApath)) {
/* set the trusted CA cert directory */
- rc = gnutls_certificate_set_x509_trust_dir(conn->ssl[sockindex].cred,
+ rc = gnutls_certificate_set_x509_trust_dir(BACKEND->cred,
SSL_CONN_CONFIG(CApath),
GNUTLS_X509_FMT_PEM);
if(rc < 0) {
@@ -599,13 +644,13 @@ gtls_connect_step1(struct connectdata *conn,
/* use system ca certificate store as fallback */
if(SSL_CONN_CONFIG(verifypeer) &&
!(SSL_CONN_CONFIG(CAfile) || SSL_CONN_CONFIG(CApath))) {
- gnutls_certificate_set_x509_system_trust(conn->ssl[sockindex].cred);
+ gnutls_certificate_set_x509_system_trust(BACKEND->cred);
}
#endif
if(SSL_SET_OPTION(CRLfile)) {
/* set the CRL list file */
- rc = gnutls_certificate_set_x509_crl_file(conn->ssl[sockindex].cred,
+ rc = gnutls_certificate_set_x509_crl_file(BACKEND->cred,
SSL_SET_OPTION(CRLfile),
GNUTLS_X509_FMT_PEM);
if(rc < 0) {
@@ -626,14 +671,14 @@ gtls_connect_step1(struct connectdata *conn,
init_flags |= GNUTLS_NO_TICKETS;
#endif
- rc = gnutls_init(&conn->ssl[sockindex].session, init_flags);
+ rc = gnutls_init(&BACKEND->session, init_flags);
if(rc != GNUTLS_E_SUCCESS) {
failf(data, "gnutls_init() failed: %d", rc);
return CURLE_SSL_CONNECT_ERROR;
}
/* convenient assign */
- session = conn->ssl[sockindex].session;
+ session = BACKEND->session;
if((0 == Curl_inet_pton(AF_INET, hostname, &addr)) &&
#ifdef ENABLE_IPV6
@@ -677,6 +722,9 @@ gtls_connect_step1(struct connectdata *conn,
protocol_priority[0] = GNUTLS_TLS1_0;
protocol_priority[1] = GNUTLS_TLS1_1;
protocol_priority[2] = GNUTLS_TLS1_2;
+#ifdef HAS_TLS13
+ protocol_priority[3] = GNUTLS_TLS1_3;
+#endif
break;
case CURL_SSLVERSION_TLSv1_0:
case CURL_SSLVERSION_TLSv1_1:
@@ -709,11 +757,14 @@ gtls_connect_step1(struct connectdata *conn,
switch(SSL_CONN_CONFIG(version)) {
case CURL_SSLVERSION_SSLv3:
prioritylist = GNUTLS_CIPHERS ":-VERS-TLS-ALL:+VERS-SSL3.0";
- sni = false;
break;
case CURL_SSLVERSION_DEFAULT:
case CURL_SSLVERSION_TLSv1:
- prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:" GNUTLS_SRP;
+ prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:"
+#ifdef HAS_TLS13
+ "+VERS-TLS1.3:"
+#endif
+ GNUTLS_SRP;
break;
case CURL_SSLVERSION_TLSv1_0:
case CURL_SSLVERSION_TLSv1_1:
@@ -763,7 +814,8 @@ gtls_connect_step1(struct connectdata *conn,
gnutls_datum_t protocols[2];
#ifdef USE_NGHTTP2
- if(data->set.httpversion >= CURL_HTTP_VERSION_2) {
+ if(data->set.httpversion >= CURL_HTTP_VERSION_2 &&
+ (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) {
protocols[cur].data = (unsigned char *)NGHTTP2_PROTO_VERSION_ID;
protocols[cur].size = NGHTTP2_PROTO_VERSION_ID_LEN;
cur++;
@@ -789,7 +841,7 @@ gtls_connect_step1(struct connectdata *conn,
GNUTLS_PKCS_USE_PBES2_AES_128 | GNUTLS_PKCS_USE_PBES2_AES_192 |
GNUTLS_PKCS_USE_PBES2_AES_256;
rc = gnutls_certificate_set_x509_key_file2(
- conn->ssl[sockindex].cred,
+ BACKEND->cred,
SSL_SET_OPTION(cert),
SSL_SET_OPTION(key) ?
SSL_SET_OPTION(key) : SSL_SET_OPTION(cert),
@@ -809,7 +861,7 @@ gtls_connect_step1(struct connectdata *conn,
}
else {
if(gnutls_certificate_set_x509_key_file(
- conn->ssl[sockindex].cred,
+ BACKEND->cred,
SSL_SET_OPTION(cert),
SSL_SET_OPTION(key) ?
SSL_SET_OPTION(key) : SSL_SET_OPTION(cert),
@@ -825,7 +877,7 @@ gtls_connect_step1(struct connectdata *conn,
/* put the credentials to the current session */
if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) {
rc = gnutls_credentials_set(session, GNUTLS_CRD_SRP,
- conn->ssl[sockindex].srp_client_cred);
+ BACKEND->srp_client_cred);
if(rc != GNUTLS_E_SUCCESS) {
failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc));
return CURLE_SSL_CONNECT_ERROR;
@@ -835,7 +887,7 @@ gtls_connect_step1(struct connectdata *conn,
#endif
{
rc = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE,
- conn->ssl[sockindex].cred);
+ BACKEND->cred);
if(rc != GNUTLS_E_SUCCESS) {
failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc));
return CURLE_SSL_CONNECT_ERROR;
@@ -843,13 +895,13 @@ gtls_connect_step1(struct connectdata *conn,
}
if(conn->proxy_ssl[sockindex].use) {
- transport_ptr = conn->proxy_ssl[sockindex].session;
+ transport_ptr = conn->proxy_ssl[sockindex].backend->session;
gnutls_transport_push = Curl_gtls_push_ssl;
gnutls_transport_pull = Curl_gtls_pull_ssl;
}
else {
/* file descriptor for the socket */
- transport_ptr = GNUTLS_INT_TO_POINTER_CAST(conn->sock[sockindex]);
+ transport_ptr = &conn->sock[sockindex];
gnutls_transport_push = Curl_gtls_push;
gnutls_transport_pull = Curl_gtls_pull;
}
@@ -905,7 +957,6 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
gnutls_pubkey_t key = NULL;
/* Result is returned to caller */
- int ret = 0;
CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
/* if a path wasn't specified, don't pin */
@@ -916,6 +967,8 @@ static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
return result;
do {
+ int ret;
+
/* Begin Gyrations to get the public key */
gnutls_pubkey_init(&key);
@@ -968,7 +1021,8 @@ gtls_connect_step3(struct connectdata *conn,
time_t certclock;
const char *ptr;
struct Curl_easy *data = conn->data;
- gnutls_session_t session = conn->ssl[sockindex].session;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ gnutls_session_t session = BACKEND->session;
int rc;
#ifdef HAS_ALPN
gnutls_datum_t proto;
@@ -1058,7 +1112,7 @@ gtls_connect_step3(struct connectdata *conn,
"CRLfile: %s", SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile):
"none",
SSL_SET_OPTION(CRLfile)?SSL_SET_OPTION(CRLfile):"none");
- return CURLE_SSL_CACERT;
+ return CURLE_PEER_FAILED_VERIFICATION;
}
else
infof(data, "\t server certificate verification FAILED\n");
@@ -1100,8 +1154,8 @@ gtls_connect_step3(struct connectdata *conn,
return CURLE_SSL_INVALIDCERTSTATUS;
}
- rc = gnutls_ocsp_resp_get_single(ocsp_resp, 0, NULL, NULL, NULL, NULL,
- &status, NULL, NULL, NULL, &reason);
+ (void)gnutls_ocsp_resp_get_single(ocsp_resp, 0, NULL, NULL, NULL, NULL,
+ &status, NULL, NULL, NULL, &reason);
switch(status) {
case GNUTLS_OCSP_CERT_GOOD:
@@ -1199,7 +1253,7 @@ gtls_connect_step3(struct connectdata *conn,
SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none");
}
- size=sizeof(certbuf);
+ 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,
@@ -1226,10 +1280,7 @@ gtls_connect_step3(struct connectdata *conn,
#define use_addr in_addr
#endif
unsigned char addrbuf[sizeof(struct use_addr)];
- unsigned char certaddr[sizeof(struct use_addr)];
- size_t addrlen = 0, certaddrlen;
- int i;
- int ret = 0;
+ size_t addrlen = 0;
if(Curl_inet_pton(AF_INET, hostname, addrbuf) > 0)
addrlen = 4;
@@ -1239,10 +1290,13 @@ gtls_connect_step3(struct connectdata *conn,
#endif
if(addrlen) {
- for(i=0; ; i++) {
- certaddrlen = sizeof(certaddr);
- ret = gnutls_x509_crt_get_subject_alt_name(x509_cert, i, certaddr,
- &certaddrlen, NULL);
+ unsigned char certaddr[sizeof(struct use_addr)];
+ int i;
+
+ for(i = 0; ; i++) {
+ size_t certaddrlen = sizeof(certaddr);
+ int ret = gnutls_x509_crt_get_subject_alt_name(x509_cert, i, certaddr,
+ &certaddrlen, NULL);
/* If this happens, it wasn't an IP address. */
if(ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
continue;
@@ -1371,11 +1425,6 @@ gtls_connect_step3(struct connectdata *conn,
size = sizeof(certbuf);
gnutls_x509_crt_get_issuer_dn(x509_cert, certbuf, &size);
infof(data, "\t issuer: %s\n", certbuf);
-
- /* 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);
#endif
gnutls_x509_crt_deinit(x509_cert);
@@ -1402,6 +1451,9 @@ gtls_connect_step3(struct connectdata *conn,
}
else
infof(data, "ALPN, server did not agree to a protocol\n");
+
+ Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
+ BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
}
#endif
@@ -1414,8 +1466,6 @@ gtls_connect_step3(struct connectdata *conn,
already got it from the cache and asked to use it in the connection, it
might've been rejected and then a new one is in use now and we need to
detect that. */
- bool incache;
- void *ssl_sessionid;
void *connect_sessionid;
size_t connect_idsize = 0;
@@ -1424,6 +1474,9 @@ gtls_connect_step3(struct connectdata *conn,
connect_sessionid = malloc(connect_idsize); /* get a buffer for it */
if(connect_sessionid) {
+ bool incache;
+ void *ssl_sessionid;
+
/* extract session ID to the allocated buffer */
gnutls_session_get_data(session, connect_sessionid, &connect_idsize);
@@ -1472,7 +1525,7 @@ gtls_connect_common(struct connectdata *conn,
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
/* Initiate the connection, if not already done */
- if(ssl_connect_1==connssl->connecting_state) {
+ if(ssl_connect_1 == connssl->connecting_state) {
rc = gtls_connect_step1(conn, sockindex);
if(rc)
return rc;
@@ -1484,29 +1537,24 @@ gtls_connect_common(struct connectdata *conn,
return rc;
/* Finish connecting once the handshake is done */
- if(ssl_connect_1==connssl->connecting_state) {
+ if(ssl_connect_1 == connssl->connecting_state) {
rc = gtls_connect_step3(conn, sockindex);
if(rc)
return rc;
}
- *done = ssl_connect_1==connssl->connecting_state;
+ *done = ssl_connect_1 == connssl->connecting_state;
return CURLE_OK;
}
-CURLcode
-Curl_gtls_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done)
+static CURLcode Curl_gtls_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
{
return gtls_connect_common(conn, sockindex, TRUE, done);
}
-CURLcode
-Curl_gtls_connect(struct connectdata *conn,
- int sockindex)
-
+static CURLcode Curl_gtls_connect(struct connectdata *conn, int sockindex)
{
CURLcode result;
bool done = FALSE;
@@ -1520,15 +1568,18 @@ Curl_gtls_connect(struct connectdata *conn,
return CURLE_OK;
}
-bool Curl_gtls_data_pending(const struct connectdata *conn, int connindex)
+static bool Curl_gtls_data_pending(const struct connectdata *conn,
+ int connindex)
{
+ const struct ssl_connect_data *connssl = &conn->ssl[connindex];
bool res = FALSE;
- if(conn->ssl[connindex].session &&
- 0 != gnutls_record_check_pending(conn->ssl[connindex].session))
+ if(BACKEND->session &&
+ 0 != gnutls_record_check_pending(BACKEND->session))
res = TRUE;
- if(conn->proxy_ssl[connindex].session &&
- 0 != gnutls_record_check_pending(conn->proxy_ssl[connindex].session))
+ connssl = &conn->proxy_ssl[connindex];
+ if(BACKEND->session &&
+ 0 != gnutls_record_check_pending(BACKEND->session))
res = TRUE;
return res;
@@ -1540,7 +1591,8 @@ static ssize_t gtls_send(struct connectdata *conn,
size_t len,
CURLcode *curlcode)
{
- ssize_t rc = gnutls_record_send(conn->ssl[sockindex].session, mem, len);
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ ssize_t rc = gnutls_record_send(BACKEND->session, mem, len);
if(rc < 0) {
*curlcode = (rc == GNUTLS_E_AGAIN)
@@ -1553,26 +1605,26 @@ static ssize_t gtls_send(struct connectdata *conn,
return rc;
}
-static void close_one(struct ssl_connect_data *ssl)
+static void close_one(struct ssl_connect_data *connssl)
{
- if(ssl->session) {
- gnutls_bye(ssl->session, GNUTLS_SHUT_RDWR);
- gnutls_deinit(ssl->session);
- ssl->session = NULL;
+ if(BACKEND->session) {
+ gnutls_bye(BACKEND->session, GNUTLS_SHUT_RDWR);
+ gnutls_deinit(BACKEND->session);
+ BACKEND->session = NULL;
}
- if(ssl->cred) {
- gnutls_certificate_free_credentials(ssl->cred);
- ssl->cred = NULL;
+ if(BACKEND->cred) {
+ gnutls_certificate_free_credentials(BACKEND->cred);
+ BACKEND->cred = NULL;
}
#ifdef USE_TLS_SRP
- if(ssl->srp_client_cred) {
- gnutls_srp_free_client_credentials(ssl->srp_client_cred);
- ssl->srp_client_cred = NULL;
+ if(BACKEND->srp_client_cred) {
+ gnutls_srp_free_client_credentials(BACKEND->srp_client_cred);
+ BACKEND->srp_client_cred = NULL;
}
#endif
}
-void Curl_gtls_close(struct connectdata *conn, int sockindex)
+static void Curl_gtls_close(struct connectdata *conn, int sockindex)
{
close_one(&conn->ssl[sockindex]);
close_one(&conn->proxy_ssl[sockindex]);
@@ -1582,36 +1634,40 @@ void Curl_gtls_close(struct connectdata *conn, int sockindex)
* 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)
+static int Curl_gtls_shutdown(struct connectdata *conn, int sockindex)
{
- ssize_t result;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
int retval = 0;
struct Curl_easy *data = conn->data;
- int done = 0;
- char buf[120];
+#ifndef CURL_DISABLE_FTP
/* 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(data->set.ftp_ccc == CURLFTPSSL_CCC_ACTIVE)
- gnutls_bye(conn->ssl[sockindex].session, GNUTLS_SHUT_WR);
+ gnutls_bye(BACKEND->session, GNUTLS_SHUT_WR);
+#endif
+
+ if(BACKEND->session) {
+ ssize_t result;
+ bool done = FALSE;
+ char buf[120];
- if(conn->ssl[sockindex].session) {
while(!done) {
int what = SOCKET_READABLE(conn->sock[sockindex],
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,
+ result = gnutls_record_recv(BACKEND->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;
+ done = TRUE;
break;
case GNUTLS_E_AGAIN:
case GNUTLS_E_INTERRUPTED:
@@ -1619,35 +1675,34 @@ int Curl_gtls_shutdown(struct connectdata *conn, int sockindex)
break;
default:
retval = -1;
- done = 1;
+ done = TRUE;
break;
}
}
else if(0 == what) {
/* timeout */
failf(data, "SSL shutdown timeout");
- done = 1;
- break;
+ done = TRUE;
}
else {
/* anything that gets here is fatally bad */
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
retval = -1;
- done = 1;
+ done = TRUE;
}
}
- gnutls_deinit(conn->ssl[sockindex].session);
+ gnutls_deinit(BACKEND->session);
}
- gnutls_certificate_free_credentials(conn->ssl[sockindex].cred);
+ gnutls_certificate_free_credentials(BACKEND->cred);
#ifdef USE_TLS_SRP
if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP
&& SSL_SET_OPTION(username) != NULL)
- gnutls_srp_free_client_credentials(conn->ssl[sockindex].srp_client_cred);
+ gnutls_srp_free_client_credentials(BACKEND->srp_client_cred);
#endif
- conn->ssl[sockindex].cred = NULL;
- conn->ssl[sockindex].session = NULL;
+ BACKEND->cred = NULL;
+ BACKEND->session = NULL;
return retval;
}
@@ -1658,9 +1713,10 @@ static ssize_t gtls_recv(struct connectdata *conn, /* connection data */
size_t buffersize, /* max amount to read */
CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[num];
ssize_t ret;
- ret = gnutls_record_recv(conn->ssl[num].session, buf, buffersize);
+ ret = gnutls_record_recv(BACKEND->session, buf, buffersize);
if((ret == GNUTLS_E_AGAIN) || (ret == GNUTLS_E_INTERRUPTED)) {
*curlcode = CURLE_AGAIN;
return -1;
@@ -1680,6 +1736,7 @@ static ssize_t gtls_recv(struct connectdata *conn, /* connection data */
if(ret < 0) {
failf(conn->data, "GnuTLS recv error (%d): %s",
+
(int)ret, gnutls_strerror((int)ret));
*curlcode = CURLE_RECV_ERROR;
return -1;
@@ -1688,14 +1745,14 @@ static ssize_t gtls_recv(struct connectdata *conn, /* connection data */
return ret;
}
-void Curl_gtls_session_free(void *ptr)
+static void Curl_gtls_session_free(void *ptr)
{
free(ptr);
}
-size_t Curl_gtls_version(char *buffer, size_t size)
+static size_t Curl_gtls_version(char *buffer, size_t size)
{
- return snprintf(buffer, size, "GnuTLS/%s", gnutls_check_version(NULL));
+ return msnprintf(buffer, size, "GnuTLS/%s", gnutls_check_version(NULL));
}
#ifndef USE_GNUTLS_NETTLE
@@ -1710,12 +1767,6 @@ static int Curl_gtls_seed(struct Curl_easy *data)
if(!ssl_seeded || data->set.str[STRING_SSL_RANDOM_FILE] ||
data->set.str[STRING_SSL_EGDSOCKET]) {
-
- /* TODO: to a good job seeding the RNG
- This may involve the gcry_control function and these options:
- GCRYCTL_SET_RANDOM_SEED_FILE
- GCRYCTL_SET_RNDEGD_SOCKET
- */
ssl_seeded = TRUE;
}
return 0;
@@ -1723,9 +1774,8 @@ static int Curl_gtls_seed(struct Curl_easy *data)
#endif
/* data might be NULL! */
-CURLcode Curl_gtls_random(struct Curl_easy *data,
- unsigned char *entropy,
- size_t length)
+static CURLcode Curl_gtls_random(struct Curl_easy *data,
+ unsigned char *entropy, size_t length)
{
#if defined(USE_GNUTLS_NETTLE)
int rc;
@@ -1740,10 +1790,10 @@ CURLcode Curl_gtls_random(struct Curl_easy *data,
return CURLE_OK;
}
-void Curl_gtls_md5sum(unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *md5sum, /* output */
- size_t md5len)
+static CURLcode Curl_gtls_md5sum(unsigned char *tmp, /* input */
+ size_t tmplen,
+ unsigned char *md5sum, /* output */
+ size_t md5len)
{
#if defined(USE_GNUTLS_NETTLE)
struct md5_ctx MD5pw;
@@ -1757,12 +1807,13 @@ void Curl_gtls_md5sum(unsigned char *tmp, /* input */
memcpy(md5sum, gcry_md_read(MD5pw, 0), md5len);
gcry_md_close(MD5pw);
#endif
+ return CURLE_OK;
}
-void Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum, /* output */
- size_t sha256len)
+static CURLcode Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
+ size_t tmplen,
+ unsigned char *sha256sum, /* output */
+ size_t sha256len)
{
#if defined(USE_GNUTLS_NETTLE)
struct sha256_ctx SHA256pw;
@@ -1776,9 +1827,10 @@ void Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
memcpy(sha256sum, gcry_md_read(SHA256pw, 0), sha256len);
gcry_md_close(SHA256pw);
#endif
+ return CURLE_OK;
}
-bool Curl_gtls_cert_status_request(void)
+static bool Curl_gtls_cert_status_request(void)
{
#ifdef HAS_OCSP
return TRUE;
@@ -1787,4 +1839,43 @@ bool Curl_gtls_cert_status_request(void)
#endif
}
+static void *Curl_gtls_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info UNUSED_PARAM)
+{
+ (void)info;
+ return BACKEND->session;
+}
+
+const struct Curl_ssl Curl_ssl_gnutls = {
+ { CURLSSLBACKEND_GNUTLS, "gnutls" }, /* info */
+
+ SSLSUPP_CA_PATH |
+ SSLSUPP_CERTINFO |
+ SSLSUPP_PINNEDPUBKEY |
+ SSLSUPP_HTTPS_PROXY,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_gtls_init, /* init */
+ Curl_gtls_cleanup, /* cleanup */
+ Curl_gtls_version, /* version */
+ Curl_none_check_cxn, /* check_cxn */
+ Curl_gtls_shutdown, /* shutdown */
+ Curl_gtls_data_pending, /* data_pending */
+ Curl_gtls_random, /* random */
+ Curl_gtls_cert_status_request, /* cert_status_request */
+ Curl_gtls_connect, /* connect */
+ Curl_gtls_connect_nonblocking, /* connect_nonblocking */
+ Curl_gtls_get_internals, /* get_internals */
+ Curl_gtls_close, /* close_one */
+ Curl_none_close_all, /* close_all */
+ Curl_gtls_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_gtls_md5sum, /* md5sum */
+ Curl_gtls_sha256sum /* sha256sum */
+};
+
#endif /* USE_GNUTLS */
diff --git a/Utilities/cmcurl/lib/vtls/gtls.h b/Utilities/cmcurl/lib/vtls/gtls.h
index 462c04853..780fc109d 100644
--- a/Utilities/cmcurl/lib/vtls/gtls.h
+++ b/Utilities/cmcurl/lib/vtls/gtls.h
@@ -28,69 +28,7 @@
#include "urldata.h"
-int Curl_gtls_init(void);
-int Curl_gtls_cleanup(void);
-CURLcode Curl_gtls_connect(struct connectdata *conn, int sockindex);
-CURLcode Curl_gtls_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done);
-bool Curl_gtls_data_pending(const struct connectdata *conn,
- int connindex);
-
- /* close a SSL connection */
-void Curl_gtls_close(struct connectdata *conn, int sockindex);
-
-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);
-CURLcode Curl_gtls_random(struct Curl_easy *data,
- unsigned char *entropy,
- size_t length);
-void Curl_gtls_md5sum(unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *md5sum, /* output */
- size_t md5len);
-void Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum, /* output */
- size_t sha256len);
-
-bool Curl_gtls_cert_status_request(void);
-
-/* Support HTTPS-proxy */
-#define HTTPS_PROXY_SUPPORT 1
-
-/* Set the API backend definition to GnuTLS */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_GNUTLS
-
-/* this backend supports the CAPATH option */
-#define have_curlssl_ca_path 1
-
-/* this backend supports CURLOPT_CERTINFO */
-#define have_curlssl_certinfo 1
-
-/* this backend supports CURLOPT_PINNEDPUBLICKEY */
-#define have_curlssl_pinnedpubkey 1
-
-/* API setup for GnuTLS */
-#define curlssl_init Curl_gtls_init
-#define curlssl_cleanup Curl_gtls_cleanup
-#define curlssl_connect Curl_gtls_connect
-#define curlssl_connect_nonblocking Curl_gtls_connect_nonblocking
-#define curlssl_session_free(x) Curl_gtls_session_free(x)
-#define curlssl_close_all(x) ((void)x)
-#define curlssl_close Curl_gtls_close
-#define curlssl_shutdown(x,y) Curl_gtls_shutdown(x,y)
-#define curlssl_set_engine(x,y) ((void)x, (void)y, CURLE_NOT_BUILT_IN)
-#define curlssl_set_engine_default(x) ((void)x, CURLE_NOT_BUILT_IN)
-#define curlssl_engines_list(x) ((void)x, (struct curl_slist *)NULL)
-#define curlssl_version Curl_gtls_version
-#define curlssl_check_cxn(x) ((void)x, -1)
-#define curlssl_data_pending(x,y) Curl_gtls_data_pending(x,y)
-#define curlssl_random(x,y,z) Curl_gtls_random(x,y,z)
-#define curlssl_md5sum(a,b,c,d) Curl_gtls_md5sum(a,b,c,d)
-#define curlssl_sha256sum(a,b,c,d) Curl_gtls_sha256sum(a,b,c,d)
-#define curlssl_cert_status_request() Curl_gtls_cert_status_request()
+extern const struct Curl_ssl Curl_ssl_gnutls;
#endif /* USE_GNUTLS */
#endif /* HEADER_CURL_GTLS_H */
diff --git a/Utilities/cmcurl/lib/vtls/mbedtls.c b/Utilities/cmcurl/lib/vtls/mbedtls.c
index 037babe38..63d1f4c81 100644
--- a/Utilities/cmcurl/lib/vtls/mbedtls.c
+++ b/Utilities/cmcurl/lib/vtls/mbedtls.c
@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2010 - 2011, Hoi-Ho Chan, <hoiho.chan@gmail.com>
- * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2019, 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
@@ -54,6 +54,7 @@
#include "parsedate.h"
#include "connect.h" /* for the connect timeout */
#include "select.h"
+#include "multiif.h"
#include "polarssl_threadlock.h"
/* The last 3 #include files should be in this order */
@@ -61,6 +62,21 @@
#include "curl_memory.h"
#include "memdebug.h"
+struct ssl_backend_data {
+ mbedtls_ctr_drbg_context ctr_drbg;
+ mbedtls_entropy_context entropy;
+ mbedtls_ssl_context ssl;
+ int server_fd;
+ mbedtls_x509_crt cacert;
+ mbedtls_x509_crt clicert;
+ mbedtls_x509_crl crl;
+ mbedtls_pk_context pk;
+ mbedtls_ssl_config config;
+ const char *protocols[3];
+};
+
+#define BACKEND connssl->backend
+
/* apply threading? */
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
#define THREADING_SUPPORT
@@ -190,14 +206,11 @@ set_ssl_version_min_max(struct connectdata *conn, int sockindex)
case CURL_SSLVERSION_DEFAULT:
case CURL_SSLVERSION_TLSv1:
ssl_version = CURL_SSLVERSION_TLSv1_0;
- ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_2;
break;
}
switch(ssl_version_max) {
case CURL_SSLVERSION_MAX_NONE:
- ssl_version_max = ssl_version << 16;
- break;
case CURL_SSLVERSION_MAX_DEFAULT:
ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_2;
break;
@@ -214,9 +227,9 @@ set_ssl_version_min_max(struct connectdata *conn, int sockindex)
return result;
}
- mbedtls_ssl_conf_min_version(&connssl->config, MBEDTLS_SSL_MAJOR_VERSION_3,
+ mbedtls_ssl_conf_min_version(&BACKEND->config, MBEDTLS_SSL_MAJOR_VERSION_3,
mbedtls_ver_min);
- mbedtls_ssl_conf_max_version(&connssl->config, MBEDTLS_SSL_MAJOR_VERSION_3,
+ mbedtls_ssl_conf_max_version(&BACKEND->config, MBEDTLS_SSL_MAJOR_VERSION_3,
mbedtls_ver_max);
return result;
@@ -238,7 +251,7 @@ mbed_connect_step1(struct connectdata *conn,
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
int ret = -1;
char errorbuf[128];
- errorbuf[0]=0;
+ errorbuf[0] = 0;
/* mbedTLS only supports SSLv3 and TLSv1 */
if(SSL_CONN_CONFIG(version) == CURL_SSLVERSION_SSLv2) {
@@ -248,9 +261,9 @@ mbed_connect_step1(struct connectdata *conn,
#ifdef THREADING_SUPPORT
entropy_init_mutex(&ts_entropy);
- mbedtls_ctr_drbg_init(&connssl->ctr_drbg);
+ mbedtls_ctr_drbg_init(&BACKEND->ctr_drbg);
- ret = mbedtls_ctr_drbg_seed(&connssl->ctr_drbg, entropy_func_mutex,
+ ret = mbedtls_ctr_drbg_seed(&BACKEND->ctr_drbg, entropy_func_mutex,
&ts_entropy, NULL, 0);
if(ret) {
#ifdef MBEDTLS_ERROR_C
@@ -260,11 +273,11 @@ mbed_connect_step1(struct connectdata *conn,
-ret, errorbuf);
}
#else
- mbedtls_entropy_init(&connssl->entropy);
- mbedtls_ctr_drbg_init(&connssl->ctr_drbg);
+ mbedtls_entropy_init(&BACKEND->entropy);
+ mbedtls_ctr_drbg_init(&BACKEND->ctr_drbg);
- ret = mbedtls_ctr_drbg_seed(&connssl->ctr_drbg, mbedtls_entropy_func,
- &connssl->entropy, NULL, 0);
+ ret = mbedtls_ctr_drbg_seed(&BACKEND->ctr_drbg, mbedtls_entropy_func,
+ &BACKEND->entropy, NULL, 0);
if(ret) {
#ifdef MBEDTLS_ERROR_C
mbedtls_strerror(ret, errorbuf, sizeof(errorbuf));
@@ -275,10 +288,10 @@ mbed_connect_step1(struct connectdata *conn,
#endif /* THREADING_SUPPORT */
/* Load the trusted CA */
- mbedtls_x509_crt_init(&connssl->cacert);
+ mbedtls_x509_crt_init(&BACKEND->cacert);
if(ssl_cafile) {
- ret = mbedtls_x509_crt_parse_file(&connssl->cacert, ssl_cafile);
+ ret = mbedtls_x509_crt_parse_file(&BACKEND->cacert, ssl_cafile);
if(ret<0) {
#ifdef MBEDTLS_ERROR_C
@@ -293,7 +306,7 @@ mbed_connect_step1(struct connectdata *conn,
}
if(ssl_capath) {
- ret = mbedtls_x509_crt_parse_path(&connssl->cacert, ssl_capath);
+ ret = mbedtls_x509_crt_parse_path(&BACKEND->cacert, ssl_capath);
if(ret<0) {
#ifdef MBEDTLS_ERROR_C
@@ -308,10 +321,10 @@ mbed_connect_step1(struct connectdata *conn,
}
/* Load the client certificate */
- mbedtls_x509_crt_init(&connssl->clicert);
+ mbedtls_x509_crt_init(&BACKEND->clicert);
if(ssl_cert) {
- ret = mbedtls_x509_crt_parse_file(&connssl->clicert, ssl_cert);
+ ret = mbedtls_x509_crt_parse_file(&BACKEND->clicert, ssl_cert);
if(ret) {
#ifdef MBEDTLS_ERROR_C
@@ -325,12 +338,13 @@ mbed_connect_step1(struct connectdata *conn,
}
/* Load the client private key */
- mbedtls_pk_init(&connssl->pk);
+ mbedtls_pk_init(&BACKEND->pk);
if(SSL_SET_OPTION(key)) {
- ret = mbedtls_pk_parse_keyfile(&connssl->pk, SSL_SET_OPTION(key),
+ ret = mbedtls_pk_parse_keyfile(&BACKEND->pk, SSL_SET_OPTION(key),
SSL_SET_OPTION(key_passwd));
- if(ret == 0 && !mbedtls_pk_can_do(&connssl->pk, MBEDTLS_PK_RSA))
+ if(ret == 0 && !(mbedtls_pk_can_do(&BACKEND->pk, MBEDTLS_PK_RSA) ||
+ mbedtls_pk_can_do(&BACKEND->pk, MBEDTLS_PK_ECKEY)))
ret = MBEDTLS_ERR_PK_TYPE_MISMATCH;
if(ret) {
@@ -345,10 +359,10 @@ mbed_connect_step1(struct connectdata *conn,
}
/* Load the CRL */
- mbedtls_x509_crl_init(&connssl->crl);
+ mbedtls_x509_crl_init(&BACKEND->crl);
if(ssl_crlfile) {
- ret = mbedtls_x509_crl_parse_file(&connssl->crl, ssl_crlfile);
+ ret = mbedtls_x509_crl_parse_file(&BACKEND->crl, ssl_crlfile);
if(ret) {
#ifdef MBEDTLS_ERROR_C
@@ -361,16 +375,16 @@ mbed_connect_step1(struct connectdata *conn,
}
}
- infof(data, "mbedTLS: Connecting to %s:%d\n", hostname, port);
+ infof(data, "mbedTLS: Connecting to %s:%ld\n", hostname, port);
- mbedtls_ssl_config_init(&connssl->config);
+ mbedtls_ssl_config_init(&BACKEND->config);
- mbedtls_ssl_init(&connssl->ssl);
- if(mbedtls_ssl_setup(&connssl->ssl, &connssl->config)) {
+ mbedtls_ssl_init(&BACKEND->ssl);
+ if(mbedtls_ssl_setup(&BACKEND->ssl, &BACKEND->config)) {
failf(data, "mbedTLS: ssl_init failed");
return CURLE_SSL_CONNECT_ERROR;
}
- ret = mbedtls_ssl_config_defaults(&connssl->config,
+ ret = mbedtls_ssl_config_defaults(&BACKEND->config,
MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT);
@@ -380,20 +394,20 @@ mbed_connect_step1(struct connectdata *conn,
}
/* new profile with RSA min key len = 1024 ... */
- mbedtls_ssl_conf_cert_profile(&connssl->config,
+ mbedtls_ssl_conf_cert_profile(&BACKEND->config,
&mbedtls_x509_crt_profile_fr);
switch(SSL_CONN_CONFIG(version)) {
case CURL_SSLVERSION_DEFAULT:
case CURL_SSLVERSION_TLSv1:
- mbedtls_ssl_conf_min_version(&connssl->config, MBEDTLS_SSL_MAJOR_VERSION_3,
+ mbedtls_ssl_conf_min_version(&BACKEND->config, MBEDTLS_SSL_MAJOR_VERSION_3,
MBEDTLS_SSL_MINOR_VERSION_1);
infof(data, "mbedTLS: Set min SSL version to TLS 1.0\n");
break;
case CURL_SSLVERSION_SSLv3:
- mbedtls_ssl_conf_min_version(&connssl->config, MBEDTLS_SSL_MAJOR_VERSION_3,
+ mbedtls_ssl_conf_min_version(&BACKEND->config, MBEDTLS_SSL_MAJOR_VERSION_3,
MBEDTLS_SSL_MINOR_VERSION_0);
- mbedtls_ssl_conf_max_version(&connssl->config, MBEDTLS_SSL_MAJOR_VERSION_3,
+ mbedtls_ssl_conf_max_version(&BACKEND->config, MBEDTLS_SSL_MAJOR_VERSION_3,
MBEDTLS_SSL_MINOR_VERSION_0);
infof(data, "mbedTLS: Set SSL version to SSLv3\n");
break;
@@ -412,25 +426,25 @@ mbed_connect_step1(struct connectdata *conn,
return CURLE_SSL_CONNECT_ERROR;
}
- mbedtls_ssl_conf_authmode(&connssl->config, MBEDTLS_SSL_VERIFY_OPTIONAL);
+ mbedtls_ssl_conf_authmode(&BACKEND->config, MBEDTLS_SSL_VERIFY_OPTIONAL);
- mbedtls_ssl_conf_rng(&connssl->config, mbedtls_ctr_drbg_random,
- &connssl->ctr_drbg);
- mbedtls_ssl_set_bio(&connssl->ssl, &conn->sock[sockindex],
+ mbedtls_ssl_conf_rng(&BACKEND->config, mbedtls_ctr_drbg_random,
+ &BACKEND->ctr_drbg);
+ mbedtls_ssl_set_bio(&BACKEND->ssl, &conn->sock[sockindex],
mbedtls_net_send,
mbedtls_net_recv,
NULL /* rev_timeout() */);
- mbedtls_ssl_conf_ciphersuites(&connssl->config,
+ mbedtls_ssl_conf_ciphersuites(&BACKEND->config,
mbedtls_ssl_list_ciphersuites());
#if defined(MBEDTLS_SSL_RENEGOTIATION)
- mbedtls_ssl_conf_renegotiation(&connssl->config,
+ mbedtls_ssl_conf_renegotiation(&BACKEND->config,
MBEDTLS_SSL_RENEGOTIATION_ENABLED);
#endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
- mbedtls_ssl_conf_session_tickets(&connssl->config,
+ mbedtls_ssl_conf_session_tickets(&BACKEND->config,
MBEDTLS_SSL_SESSION_TICKETS_DISABLED);
#endif
@@ -440,7 +454,7 @@ mbed_connect_step1(struct connectdata *conn,
Curl_ssl_sessionid_lock(conn);
if(!Curl_ssl_getsessionid(conn, &old_session, NULL, sockindex)) {
- ret = mbedtls_ssl_set_session(&connssl->ssl, old_session);
+ ret = mbedtls_ssl_set_session(&BACKEND->ssl, old_session);
if(ret) {
Curl_ssl_sessionid_unlock(conn);
failf(data, "mbedtls_ssl_set_session returned -0x%x", -ret);
@@ -451,15 +465,15 @@ mbed_connect_step1(struct connectdata *conn,
Curl_ssl_sessionid_unlock(conn);
}
- mbedtls_ssl_conf_ca_chain(&connssl->config,
- &connssl->cacert,
- &connssl->crl);
+ mbedtls_ssl_conf_ca_chain(&BACKEND->config,
+ &BACKEND->cacert,
+ &BACKEND->crl);
if(SSL_SET_OPTION(key)) {
- mbedtls_ssl_conf_own_cert(&connssl->config,
- &connssl->clicert, &connssl->pk);
+ mbedtls_ssl_conf_own_cert(&BACKEND->config,
+ &BACKEND->clicert, &BACKEND->pk);
}
- if(mbedtls_ssl_set_hostname(&connssl->ssl, hostname)) {
+ if(mbedtls_ssl_set_hostname(&BACKEND->ssl, hostname)) {
/* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks *and*
the name to set in the SNI extension. So even if curl connects to a
host specified as an IP address, this function must be used. */
@@ -469,7 +483,7 @@ mbed_connect_step1(struct connectdata *conn,
#ifdef HAS_ALPN
if(conn->bits.tls_enable_alpn) {
- const char **p = &connssl->protocols[0];
+ const char **p = &BACKEND->protocols[0];
#ifdef USE_NGHTTP2
if(data->set.httpversion >= CURL_HTTP_VERSION_2)
*p++ = NGHTTP2_PROTO_VERSION_ID;
@@ -478,19 +492,19 @@ mbed_connect_step1(struct connectdata *conn,
*p = NULL;
/* this function doesn't clone the protocols array, which is why we need
to keep it around */
- if(mbedtls_ssl_conf_alpn_protocols(&connssl->config,
- &connssl->protocols[0])) {
+ if(mbedtls_ssl_conf_alpn_protocols(&BACKEND->config,
+ &BACKEND->protocols[0])) {
failf(data, "Failed setting ALPN protocols");
return CURLE_SSL_CONNECT_ERROR;
}
- for(p = &connssl->protocols[0]; *p; ++p)
+ for(p = &BACKEND->protocols[0]; *p; ++p)
infof(data, "ALPN, offering %s\n", *p);
}
#endif
#ifdef MBEDTLS_DEBUG
/* In order to make that work in mbedtls MBEDTLS_DEBUG_C must be defined. */
- mbedtls_ssl_conf_dbg(&connssl->config, mbed_debug, data);
+ mbedtls_ssl_conf_dbg(&BACKEND->config, mbed_debug, data);
/* - 0 No debug
* - 1 Error
* - 2 State change
@@ -502,7 +516,7 @@ mbed_connect_step1(struct connectdata *conn,
/* give application a chance to interfere with mbedTLS set up. */
if(data->set.ssl.fsslctx) {
- ret = (*data->set.ssl.fsslctx)(data, &connssl->config,
+ ret = (*data->set.ssl.fsslctx)(data, &BACKEND->config,
data->set.ssl.fsslctxp);
if(ret) {
failf(data, "error signaled by ssl ctx callback");
@@ -527,17 +541,10 @@ mbed_connect_step2(struct connectdata *conn,
data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG];
-#ifdef HAS_ALPN
- const char *next_protocol;
-#endif
-
- char errorbuf[128];
- errorbuf[0] = 0;
-
conn->recv[sockindex] = mbed_recv;
conn->send[sockindex] = mbed_send;
- ret = mbedtls_ssl_handshake(&connssl->ssl);
+ ret = mbedtls_ssl_handshake(&BACKEND->ssl);
if(ret == MBEDTLS_ERR_SSL_WANT_READ) {
connssl->connecting_state = ssl_connect_2_reading;
@@ -548,6 +555,8 @@ mbed_connect_step2(struct connectdata *conn,
return CURLE_OK;
}
else if(ret) {
+ char errorbuf[128];
+ errorbuf[0] = 0;
#ifdef MBEDTLS_ERROR_C
mbedtls_strerror(ret, errorbuf, sizeof(errorbuf));
#endif /* MBEDTLS_ERROR_C */
@@ -557,30 +566,32 @@ mbed_connect_step2(struct connectdata *conn,
}
infof(data, "mbedTLS: Handshake complete, cipher is %s\n",
- mbedtls_ssl_get_ciphersuite(&conn->ssl[sockindex].ssl)
+ mbedtls_ssl_get_ciphersuite(&BACKEND->ssl)
);
- ret = mbedtls_ssl_get_verify_result(&conn->ssl[sockindex].ssl);
+ ret = mbedtls_ssl_get_verify_result(&BACKEND->ssl);
+
+ if(!SSL_CONN_CONFIG(verifyhost))
+ /* Ignore hostname errors if verifyhost is disabled */
+ ret &= ~MBEDTLS_X509_BADCERT_CN_MISMATCH;
if(ret && SSL_CONN_CONFIG(verifypeer)) {
if(ret & MBEDTLS_X509_BADCERT_EXPIRED)
failf(data, "Cert verify failed: BADCERT_EXPIRED");
- if(ret & MBEDTLS_X509_BADCERT_REVOKED) {
+ else if(ret & MBEDTLS_X509_BADCERT_REVOKED)
failf(data, "Cert verify failed: BADCERT_REVOKED");
- return CURLE_SSL_CACERT;
- }
- if(ret & MBEDTLS_X509_BADCERT_CN_MISMATCH)
+ else if(ret & MBEDTLS_X509_BADCERT_CN_MISMATCH)
failf(data, "Cert verify failed: BADCERT_CN_MISMATCH");
- if(ret & MBEDTLS_X509_BADCERT_NOT_TRUSTED)
+ else if(ret & MBEDTLS_X509_BADCERT_NOT_TRUSTED)
failf(data, "Cert verify failed: BADCERT_NOT_TRUSTED");
return CURLE_PEER_FAILED_VERIFICATION;
}
- peercert = mbedtls_ssl_get_peer_cert(&connssl->ssl);
+ peercert = mbedtls_ssl_get_peer_cert(&BACKEND->ssl);
if(peercert && data->set.verbose) {
const size_t bufsize = 16384;
@@ -650,7 +661,7 @@ mbed_connect_step2(struct connectdata *conn,
#ifdef HAS_ALPN
if(conn->bits.tls_enable_alpn) {
- next_protocol = mbedtls_ssl_get_alpn_protocol(&connssl->ssl);
+ const char *next_protocol = mbedtls_ssl_get_alpn_protocol(&BACKEND->ssl);
if(next_protocol) {
infof(data, "ALPN, server accepted to use %s\n", next_protocol);
@@ -670,6 +681,8 @@ mbed_connect_step2(struct connectdata *conn,
else {
infof(data, "ALPN, server did not agree to a protocol\n");
}
+ Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
+ BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
}
#endif
@@ -700,8 +713,10 @@ mbed_connect_step3(struct connectdata *conn,
mbedtls_ssl_session_init(our_ssl_sessionid);
- ret = mbedtls_ssl_get_session(&connssl->ssl, our_ssl_sessionid);
+ ret = mbedtls_ssl_get_session(&BACKEND->ssl, our_ssl_sessionid);
if(ret) {
+ if(ret != MBEDTLS_ERR_SSL_ALLOC_FAILED)
+ mbedtls_ssl_session_free(our_ssl_sessionid);
free(our_ssl_sessionid);
failf(data, "mbedtls_ssl_get_session returned -0x%x", -ret);
return CURLE_SSL_CONNECT_ERROR;
@@ -715,6 +730,7 @@ mbed_connect_step3(struct connectdata *conn,
retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid, 0, sockindex);
Curl_ssl_sessionid_unlock(conn);
if(retcode) {
+ mbedtls_ssl_session_free(our_ssl_sessionid);
free(our_ssl_sessionid);
failf(data, "failed to store ssl session");
return retcode;
@@ -730,9 +746,10 @@ static ssize_t mbed_send(struct connectdata *conn, int sockindex,
const void *mem, size_t len,
CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
int ret = -1;
- ret = mbedtls_ssl_write(&conn->ssl[sockindex].ssl,
+ ret = mbedtls_ssl_write(&BACKEND->ssl,
(unsigned char *)mem, len);
if(ret < 0) {
@@ -744,22 +761,23 @@ static ssize_t mbed_send(struct connectdata *conn, int sockindex,
return ret;
}
-void Curl_mbedtls_close_all(struct Curl_easy *data)
+static void Curl_mbedtls_close_all(struct Curl_easy *data)
{
(void)data;
}
-void Curl_mbedtls_close(struct connectdata *conn, int sockindex)
+static void Curl_mbedtls_close(struct connectdata *conn, int sockindex)
{
- mbedtls_pk_free(&conn->ssl[sockindex].pk);
- mbedtls_x509_crt_free(&conn->ssl[sockindex].clicert);
- mbedtls_x509_crt_free(&conn->ssl[sockindex].cacert);
- mbedtls_x509_crl_free(&conn->ssl[sockindex].crl);
- mbedtls_ssl_config_free(&conn->ssl[sockindex].config);
- mbedtls_ssl_free(&conn->ssl[sockindex].ssl);
- mbedtls_ctr_drbg_free(&conn->ssl[sockindex].ctr_drbg);
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ mbedtls_pk_free(&BACKEND->pk);
+ mbedtls_x509_crt_free(&BACKEND->clicert);
+ mbedtls_x509_crt_free(&BACKEND->cacert);
+ mbedtls_x509_crl_free(&BACKEND->crl);
+ mbedtls_ssl_config_free(&BACKEND->config);
+ mbedtls_ssl_free(&BACKEND->ssl);
+ mbedtls_ctr_drbg_free(&BACKEND->ctr_drbg);
#ifndef THREADING_SUPPORT
- mbedtls_entropy_free(&conn->ssl[sockindex].entropy);
+ mbedtls_entropy_free(&BACKEND->entropy);
#endif /* THREADING_SUPPORT */
}
@@ -767,11 +785,12 @@ static ssize_t mbed_recv(struct connectdata *conn, int num,
char *buf, size_t buffersize,
CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[num];
int ret = -1;
ssize_t len = -1;
memset(buf, 0, buffersize);
- ret = mbedtls_ssl_read(&conn->ssl[num].ssl, (unsigned char *)buf,
+ ret = mbedtls_ssl_read(&BACKEND->ssl, (unsigned char *)buf,
buffersize);
if(ret <= 0) {
@@ -788,21 +807,26 @@ static ssize_t mbed_recv(struct connectdata *conn, int num,
return len;
}
-void Curl_mbedtls_session_free(void *ptr)
+static void Curl_mbedtls_session_free(void *ptr)
{
mbedtls_ssl_session_free(ptr);
free(ptr);
}
-size_t Curl_mbedtls_version(char *buffer, size_t size)
+static size_t Curl_mbedtls_version(char *buffer, size_t size)
{
+#ifdef MBEDTLS_VERSION_C
+ /* if mbedtls_version_get_number() is available it is better */
unsigned int version = mbedtls_version_get_number();
- return snprintf(buffer, size, "mbedTLS/%d.%d.%d", version>>24,
- (version>>16)&0xff, (version>>8)&0xff);
+ return msnprintf(buffer, size, "mbedTLS/%u.%u.%u", version>>24,
+ (version>>16)&0xff, (version>>8)&0xff);
+#else
+ return msnprintf(buffer, size, "mbedTLS/%s", MBEDTLS_VERSION_STRING);
+#endif
}
-CURLcode Curl_mbedtls_random(struct Curl_easy *data, unsigned char *entropy,
- size_t length)
+static CURLcode Curl_mbedtls_random(struct Curl_easy *data,
+ unsigned char *entropy, size_t length)
{
#if defined(MBEDTLS_CTR_DRBG_C)
int ret = -1;
@@ -811,7 +835,7 @@ CURLcode Curl_mbedtls_random(struct Curl_easy *data, unsigned char *entropy,
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_init(&ctr_entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
- errorbuf[0]=0;
+ errorbuf[0] = 0;
ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func,
&ctr_entropy, NULL, 0);
@@ -869,7 +893,7 @@ mbed_connect_common(struct connectdata *conn,
return CURLE_OK;
}
- if(ssl_connect_1==connssl->connecting_state) {
+ if(ssl_connect_1 == connssl->connecting_state) {
/* Find out how much more time we're allowed */
timeout_ms = Curl_timeleft(data, NULL, TRUE);
@@ -900,9 +924,9 @@ mbed_connect_common(struct connectdata *conn,
if(connssl->connecting_state == ssl_connect_2_reading
|| connssl->connecting_state == ssl_connect_2_writing) {
- curl_socket_t writefd = ssl_connect_2_writing==
+ curl_socket_t writefd = ssl_connect_2_writing ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
- curl_socket_t readfd = ssl_connect_2_reading==
+ curl_socket_t readfd = ssl_connect_2_reading ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
@@ -942,13 +966,13 @@ mbed_connect_common(struct connectdata *conn,
} /* repeat step2 until all transactions are done. */
- if(ssl_connect_3==connssl->connecting_state) {
+ if(ssl_connect_3 == connssl->connecting_state) {
retcode = mbed_connect_step3(conn, sockindex);
if(retcode)
return retcode;
}
- if(ssl_connect_done==connssl->connecting_state) {
+ if(ssl_connect_done == connssl->connecting_state) {
connssl->state = ssl_connection_complete;
conn->recv[sockindex] = mbed_recv;
conn->send[sockindex] = mbed_send;
@@ -963,18 +987,14 @@ mbed_connect_common(struct connectdata *conn,
return CURLE_OK;
}
-CURLcode
-Curl_mbedtls_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done)
+static CURLcode Curl_mbedtls_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
{
return mbed_connect_common(conn, sockindex, TRUE, done);
}
-CURLcode
-Curl_mbedtls_connect(struct connectdata *conn,
- int sockindex)
+static CURLcode Curl_mbedtls_connect(struct connectdata *conn, int sockindex)
{
CURLcode retcode;
bool done = FALSE;
@@ -992,19 +1012,75 @@ Curl_mbedtls_connect(struct connectdata *conn,
* return 0 error initializing SSL
* return 1 SSL initialized successfully
*/
-int Curl_mbedtls_init(void)
+static int Curl_mbedtls_init(void)
{
return Curl_polarsslthreadlock_thread_setup();
}
-void Curl_mbedtls_cleanup(void)
+static void Curl_mbedtls_cleanup(void)
{
(void)Curl_polarsslthreadlock_thread_cleanup();
}
-int Curl_mbedtls_data_pending(const struct connectdata *conn, int sockindex)
+static bool Curl_mbedtls_data_pending(const struct connectdata *conn,
+ int sockindex)
{
- return mbedtls_ssl_get_bytes_avail(&conn->ssl[sockindex].ssl) != 0;
+ const struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ return mbedtls_ssl_get_bytes_avail(&BACKEND->ssl) != 0;
}
+static CURLcode Curl_mbedtls_sha256sum(const unsigned char *input,
+ size_t inputlen,
+ unsigned char *sha256sum,
+ size_t sha256len UNUSED_PARAM)
+{
+ (void)sha256len;
+#if MBEDTLS_VERSION_NUMBER < 0x02070000
+ mbedtls_sha256(input, inputlen, sha256sum, 0);
+#else
+ /* returns 0 on success, otherwise failure */
+ if(mbedtls_sha256_ret(input, inputlen, sha256sum, 0) != 0)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+#endif
+ return CURLE_OK;
+}
+
+static void *Curl_mbedtls_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info UNUSED_PARAM)
+{
+ (void)info;
+ return &BACKEND->ssl;
+}
+
+const struct Curl_ssl Curl_ssl_mbedtls = {
+ { CURLSSLBACKEND_MBEDTLS, "mbedtls" }, /* info */
+
+ SSLSUPP_CA_PATH |
+ SSLSUPP_PINNEDPUBKEY |
+ SSLSUPP_SSL_CTX,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_mbedtls_init, /* init */
+ Curl_mbedtls_cleanup, /* cleanup */
+ Curl_mbedtls_version, /* version */
+ Curl_none_check_cxn, /* check_cxn */
+ Curl_none_shutdown, /* shutdown */
+ Curl_mbedtls_data_pending, /* data_pending */
+ Curl_mbedtls_random, /* random */
+ Curl_none_cert_status_request, /* cert_status_request */
+ Curl_mbedtls_connect, /* connect */
+ Curl_mbedtls_connect_nonblocking, /* connect_nonblocking */
+ Curl_mbedtls_get_internals, /* get_internals */
+ Curl_mbedtls_close, /* close_one */
+ Curl_mbedtls_close_all, /* close_all */
+ Curl_mbedtls_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_none_md5sum, /* md5sum */
+ Curl_mbedtls_sha256sum /* sha256sum */
+};
+
#endif /* USE_MBEDTLS */
diff --git a/Utilities/cmcurl/lib/vtls/mbedtls.h b/Utilities/cmcurl/lib/vtls/mbedtls.h
index 71d17a491..4a938605b 100644
--- a/Utilities/cmcurl/lib/vtls/mbedtls.h
+++ b/Utilities/cmcurl/lib/vtls/mbedtls.h
@@ -26,57 +26,7 @@
#ifdef USE_MBEDTLS
-#include <mbedtls/sha256.h>
-
-/* Called on first use mbedTLS, setup threading if supported */
-int Curl_mbedtls_init(void);
-void Curl_mbedtls_cleanup(void);
-int Curl_mbedtls_data_pending(const struct connectdata *conn, int sockindex);
-
-CURLcode Curl_mbedtls_connect(struct connectdata *conn, int sockindex);
-
-CURLcode Curl_mbedtls_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done);
-
-/* tell mbedTLS to close down all open information regarding connections (and
- thus session ID caching etc) */
-void Curl_mbedtls_close_all(struct Curl_easy *data);
-
- /* close a SSL connection */
-void Curl_mbedtls_close(struct connectdata *conn, int sockindex);
-
-void Curl_mbedtls_session_free(void *ptr);
-size_t Curl_mbedtls_version(char *buffer, size_t size);
-int Curl_mbedtls_shutdown(struct connectdata *conn, int sockindex);
-
-CURLcode Curl_mbedtls_random(struct Curl_easy *data, unsigned char *entropy,
- size_t length);
-
-/* this backends supports CURLOPT_PINNEDPUBLICKEY */
-#define have_curlssl_pinnedpubkey 1
-
-/* this backend supports CURLOPT_SSL_CTX_* */
-#define have_curlssl_ssl_ctx 1
-
-/* API setup for mbedTLS */
-#define curlssl_init() Curl_mbedtls_init()
-#define curlssl_cleanup() Curl_mbedtls_cleanup()
-#define curlssl_connect Curl_mbedtls_connect
-#define curlssl_connect_nonblocking Curl_mbedtls_connect_nonblocking
-#define curlssl_session_free(x) Curl_mbedtls_session_free(x)
-#define curlssl_close_all Curl_mbedtls_close_all
-#define curlssl_close Curl_mbedtls_close
-#define curlssl_shutdown(x,y) 0
-#define curlssl_set_engine(x,y) (x=x, y=y, CURLE_NOT_BUILT_IN)
-#define curlssl_set_engine_default(x) (x=x, CURLE_NOT_BUILT_IN)
-#define curlssl_engines_list(x) (x=x, (struct curl_slist *)NULL)
-#define curlssl_version Curl_mbedtls_version
-#define curlssl_check_cxn(x) (x=x, -1)
-#define curlssl_data_pending(x,y) Curl_mbedtls_data_pending(x, y)
-#define CURL_SSL_BACKEND CURLSSLBACKEND_MBEDTLS
-#define curlssl_sha256sum(a,b,c,d) mbedtls_sha256(a,b,c,0)
-#define curlssl_random(x,y,z) Curl_mbedtls_random(x, y, z)
+extern const struct Curl_ssl Curl_ssl_mbedtls;
#endif /* USE_MBEDTLS */
#endif /* HEADER_CURL_MBEDTLS_H */
diff --git a/Utilities/cmcurl/lib/vtls/nss.c b/Utilities/cmcurl/lib/vtls/nss.c
index cd0138930..491def106 100644
--- a/Utilities/cmcurl/lib/vtls/nss.c
+++ b/Utilities/cmcurl/lib/vtls/nss.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -38,6 +38,7 @@
#include "select.h"
#include "vtls.h"
#include "llist.h"
+#include "multiif.h"
#include "curl_printf.h"
#include "nssg.h"
#include <nspr.h>
@@ -78,6 +79,16 @@
/* enough to fit the string "PEM Token #[0|1]" */
#define SLOTSIZE 13
+struct ssl_backend_data {
+ PRFileDesc *handle;
+ char *client_nickname;
+ struct Curl_easy *data;
+ struct curl_llist obj_list;
+ PK11GenericObject *obj_clicert;
+};
+
+#define BACKEND connssl->backend
+
static PRLock *nss_initlock = NULL;
static PRLock *nss_crllock = NULL;
static PRLock *nss_findslot_lock = NULL;
@@ -207,10 +218,15 @@ static const cipher_s cipherlist[] = {
#endif
};
+#ifdef WIN32
+static const char *pem_library = "nsspem.dll";
+static const char *trust_library = "nssckbi.dll";
+#else
static const char *pem_library = "libnsspem.so";
-static SECMODModule *pem_module = NULL;
-
static const char *trust_library = "libnssckbi.so";
+#endif
+
+static SECMODModule *pem_module = NULL;
static SECMODModule *trust_module = NULL;
/* NSPR I/O layer we use to detect blocking direction during SSL handshake */
@@ -231,6 +247,32 @@ static void nss_print_error_message(struct Curl_easy *data, PRUint32 err)
failf(data, "%s", PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
}
+static char *nss_sslver_to_name(PRUint16 nssver)
+{
+ switch(nssver) {
+ case SSL_LIBRARY_VERSION_2:
+ return strdup("SSLv2");
+ case SSL_LIBRARY_VERSION_3_0:
+ return strdup("SSLv3");
+ case SSL_LIBRARY_VERSION_TLS_1_0:
+ return strdup("TLSv1.0");
+#ifdef SSL_LIBRARY_VERSION_TLS_1_1
+ case SSL_LIBRARY_VERSION_TLS_1_1:
+ return strdup("TLSv1.1");
+#endif
+#ifdef SSL_LIBRARY_VERSION_TLS_1_2
+ case SSL_LIBRARY_VERSION_TLS_1_2:
+ return strdup("TLSv1.2");
+#endif
+#ifdef SSL_LIBRARY_VERSION_TLS_1_3
+ case SSL_LIBRARY_VERSION_TLS_1_3:
+ return strdup("TLSv1.3");
+#endif
+ default:
+ return curl_maprintf("0x%04x", nssver);
+ }
+}
+
static SECStatus set_ciphers(struct Curl_easy *data, PRFileDesc * model,
char *cipher_list)
{
@@ -271,7 +313,7 @@ static SECStatus set_ciphers(struct Curl_easy *data, PRFileDesc * model,
found = PR_FALSE;
- for(i=0; i<NUM_OF_CIPHERS; i++) {
+ for(i = 0; i<NUM_OF_CIPHERS; i++) {
if(strcasecompare(cipher, cipherlist[i].name)) {
cipher_state[i] = PR_TRUE;
found = PR_TRUE;
@@ -290,7 +332,7 @@ static SECStatus set_ciphers(struct Curl_easy *data, PRFileDesc * model,
}
/* Finally actually enable the selected ciphers */
- for(i=0; i<NUM_OF_CIPHERS; i++) {
+ for(i = 0; i<NUM_OF_CIPHERS; i++) {
if(!cipher_state[i])
continue;
@@ -311,7 +353,7 @@ static bool any_cipher_enabled(void)
{
unsigned int i;
- for(i=0; i<NUM_OF_CIPHERS; i++) {
+ for(i = 0; i<NUM_OF_CIPHERS; i++) {
PRInt32 policy = 0;
SSL_CipherPolicyGet(cipherlist[i].num, &policy);
if(policy)
@@ -336,7 +378,7 @@ static int is_file(const char *filename)
return 0;
if(stat(filename, &st) == 0)
- if(S_ISREG(st.st_mode))
+ if(S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISCHR(st.st_mode))
return 1;
return 0;
@@ -384,7 +426,7 @@ static PK11SlotInfo* nss_find_slot_by_name(const char *slot_name)
/* wrap 'ptr' as list node and tail-insert into 'list' */
static CURLcode insert_wrapped_ptr(struct curl_llist *list, void *ptr)
{
- struct ptr_list_wrap *wrap = malloc(sizeof *wrap);
+ struct ptr_list_wrap *wrap = malloc(sizeof(*wrap));
if(!wrap)
return CURLE_OUT_OF_MEMORY;
@@ -396,7 +438,7 @@ static CURLcode insert_wrapped_ptr(struct curl_llist *list, void *ptr)
/* Call PK11_CreateGenericObject() with the given obj_class and filename. If
* the call succeeds, append the object handle to the list of objects so that
* the object can be destroyed in Curl_nss_close(). */
-static CURLcode nss_create_object(struct ssl_connect_data *ssl,
+static CURLcode nss_create_object(struct ssl_connect_data *connssl,
CK_OBJECT_CLASS obj_class,
const char *filename, bool cacert)
{
@@ -430,19 +472,29 @@ static CURLcode nss_create_object(struct ssl_connect_data *ssl,
PK11_SETATTRS(attrs, attr_cnt, CKA_TRUST, pval, sizeof(*pval));
}
- obj = PK11_CreateGenericObject(slot, attrs, attr_cnt, PR_FALSE);
+ /* PK11_CreateManagedGenericObject() was introduced in NSS 3.34 because
+ * PK11_DestroyGenericObject() does not release resources allocated by
+ * PK11_CreateGenericObject() early enough. */
+ obj =
+#ifdef HAVE_PK11_CREATEMANAGEDGENERICOBJECT
+ PK11_CreateManagedGenericObject
+#else
+ PK11_CreateGenericObject
+#endif
+ (slot, attrs, attr_cnt, PR_FALSE);
+
PK11_FreeSlot(slot);
if(!obj)
return result;
- if(insert_wrapped_ptr(&ssl->obj_list, obj) != CURLE_OK) {
+ if(insert_wrapped_ptr(&BACKEND->obj_list, obj) != CURLE_OK) {
PK11_DestroyGenericObject(obj);
return CURLE_OUT_OF_MEMORY;
}
if(!cacert && CKO_CERTIFICATE == obj_class)
/* store reference to a client certificate */
- ssl->obj_clicert = obj;
+ BACKEND->obj_clicert = obj;
return CURLE_OK;
}
@@ -792,6 +844,8 @@ static void HandshakeCallback(PRFileDesc *sock, void *arg)
!memcmp(ALPN_HTTP_1_1, buf, ALPN_HTTP_1_1_LENGTH)) {
conn->negnpn = CURL_HTTP_VERSION_1_1;
}
+ Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
+ BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
}
}
@@ -894,11 +948,11 @@ static CURLcode display_conn_info(struct connectdata *conn, PRFileDesc *sock)
PRTime now;
int i;
- if(SSL_GetChannelInfo(sock, &channel, sizeof channel) ==
- SECSuccess && channel.length == sizeof channel &&
+ if(SSL_GetChannelInfo(sock, &channel, sizeof(channel)) ==
+ SECSuccess && channel.length == sizeof(channel) &&
channel.cipherSuite) {
if(SSL_GetCipherSuiteInfo(channel.cipherSuite,
- &suite, sizeof suite) == SECSuccess) {
+ &suite, sizeof(suite)) == SECSuccess) {
infof(conn->data, "SSL connection using %s\n", suite.cipherSuiteName);
}
}
@@ -992,7 +1046,7 @@ static SECStatus check_issuer_cert(PRFileDesc *sock,
char *issuer_nickname)
{
CERTCertificate *cert, *cert_issuer, *issuer;
- SECStatus res=SECSuccess;
+ SECStatus res = SECSuccess;
void *proto_win = NULL;
cert = SSL_PeerCertificate(sock);
@@ -1004,7 +1058,7 @@ static SECStatus check_issuer_cert(PRFileDesc *sock,
if((!cert_issuer) || (!issuer))
res = SECFailure;
else if(SECITEM_CompareItem(&cert_issuer->derCert,
- &issuer->derCert)!=SECEqual)
+ &issuer->derCert) != SECEqual)
res = SECFailure;
CERT_DestroyCertificate(cert);
@@ -1017,7 +1071,7 @@ static CURLcode cmp_peer_pubkey(struct ssl_connect_data *connssl,
const char *pinnedpubkey)
{
CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
- struct Curl_easy *data = connssl->data;
+ struct Curl_easy *data = BACKEND->data;
CERTCertificate *cert;
if(!pinnedpubkey)
@@ -1025,7 +1079,7 @@ static CURLcode cmp_peer_pubkey(struct ssl_connect_data *connssl,
return CURLE_OK;
/* get peer certificate */
- cert = SSL_PeerCertificate(connssl->handle);
+ cert = SSL_PeerCertificate(BACKEND->handle);
if(cert) {
/* extract public key from peer certificate */
SECKEYPublicKey *pubkey = CERT_ExtractPublicKey(cert);
@@ -1069,11 +1123,11 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
struct SECKEYPrivateKeyStr **pRetKey)
{
struct ssl_connect_data *connssl = (struct ssl_connect_data *)arg;
- struct Curl_easy *data = connssl->data;
- const char *nickname = connssl->client_nickname;
+ struct Curl_easy *data = BACKEND->data;
+ const char *nickname = BACKEND->client_nickname;
static const char pem_slotname[] = "PEM Token #1";
- if(connssl->obj_clicert) {
+ if(BACKEND->obj_clicert) {
/* use the cert/key provided by PEM reader */
SECItem cert_der = { 0, NULL, 0 };
void *proto_win = SSL_RevealPinArg(sock);
@@ -1086,7 +1140,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
return SECFailure;
}
- if(PK11_ReadRawAttribute(PK11_TypeGeneric, connssl->obj_clicert, CKA_VALUE,
+ if(PK11_ReadRawAttribute(PK11_TypeGeneric, BACKEND->obj_clicert, CKA_VALUE,
&cert_der) != SECSuccess) {
failf(data, "NSS: CKA_VALUE not found in PK11 generic object");
PK11_FreeSlot(slot);
@@ -1254,6 +1308,8 @@ static void nss_unload_module(SECMODModule **pmod)
static CURLcode nss_init_core(struct Curl_easy *data, const char *cert_dir)
{
NSSInitParameters initparams;
+ PRErrorCode err;
+ const char *err_name;
if(nss_context != NULL)
return CURLE_OK;
@@ -1274,7 +1330,9 @@ static CURLcode nss_init_core(struct Curl_easy *data, const char *cert_dir)
if(nss_context != NULL)
return CURLE_OK;
- infof(data, "Unable to initialize NSS database\n");
+ err = PR_GetError();
+ err_name = nss_error_to_name(err);
+ infof(data, "Unable to initialize NSS database: %d (%s)\n", err, err_name);
}
infof(data, "Initializing NSS with certpath: none\n");
@@ -1284,7 +1342,9 @@ static CURLcode nss_init_core(struct Curl_easy *data, const char *cert_dir)
if(nss_context != NULL)
return CURLE_OK;
- infof(data, "Unable to initialize NSS\n");
+ err = PR_GetError();
+ err_name = nss_error_to_name(err);
+ failf(data, "Unable to initialize NSS: %d (%s)", err, err_name);
return CURLE_SSL_CACERT_BADFILE;
}
@@ -1325,7 +1385,8 @@ static CURLcode nss_init(struct Curl_easy *data)
return CURLE_OUT_OF_MEMORY;
/* the default methods just call down to the lower I/O layer */
- memcpy(&nspr_io_methods, PR_GetDefaultIOMethods(), sizeof nspr_io_methods);
+ memcpy(&nspr_io_methods, PR_GetDefaultIOMethods(),
+ sizeof(nspr_io_methods));
/* override certain methods in the table by our wrappers */
nspr_io_methods.recv = nspr_io_recv;
@@ -1351,7 +1412,7 @@ static CURLcode nss_init(struct Curl_easy *data)
* @retval 0 error initializing SSL
* @retval 1 SSL initialized successfully
*/
-int Curl_nss_init(void)
+static int Curl_nss_init(void)
{
/* curl_global_init() is not thread-safe so this test is ok */
if(nss_initlock == NULL) {
@@ -1386,7 +1447,7 @@ CURLcode Curl_nss_force_init(struct Curl_easy *data)
}
/* Global cleanup */
-void Curl_nss_cleanup(void)
+static void Curl_nss_cleanup(void)
{
/* This function isn't required to be threadsafe and this is only done
* as a safety feature.
@@ -1426,14 +1487,14 @@ void Curl_nss_cleanup(void)
* 0 means the connection has been closed
* -1 means the connection status is unknown
*/
-int
-Curl_nss_check_cxn(struct connectdata *conn)
+static int Curl_nss_check_cxn(struct connectdata *conn)
{
+ struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET];
int rc;
char buf;
rc =
- PR_Recv(conn->ssl[FIRSTSOCKET].handle, (void *)&buf, 1, PR_MSG_PEEK,
+ PR_Recv(BACKEND->handle, (void *)&buf, 1, PR_MSG_PEEK,
PR_SecondsToInterval(1));
if(rc > 0)
return 1; /* connection still in place */
@@ -1447,48 +1508,49 @@ Curl_nss_check_cxn(struct connectdata *conn)
static void nss_close(struct ssl_connect_data *connssl)
{
/* before the cleanup, check whether we are using a client certificate */
- const bool client_cert = (connssl->client_nickname != NULL)
- || (connssl->obj_clicert != NULL);
+ const bool client_cert = (BACKEND->client_nickname != NULL)
+ || (BACKEND->obj_clicert != NULL);
- free(connssl->client_nickname);
- connssl->client_nickname = NULL;
+ free(BACKEND->client_nickname);
+ BACKEND->client_nickname = NULL;
/* destroy all NSS objects in order to avoid failure of NSS shutdown */
- Curl_llist_destroy(&connssl->obj_list, NULL);
- connssl->obj_clicert = NULL;
+ Curl_llist_destroy(&BACKEND->obj_list, NULL);
+ BACKEND->obj_clicert = NULL;
- if(connssl->handle) {
+ if(BACKEND->handle) {
if(client_cert)
/* A server might require different authentication based on the
* particular path being requested by the client. To support this
* scenario, we must ensure that a connection will never reuse the
* authentication data from a previous connection. */
- SSL_InvalidateSession(connssl->handle);
+ SSL_InvalidateSession(BACKEND->handle);
- PR_Close(connssl->handle);
- connssl->handle = NULL;
+ PR_Close(BACKEND->handle);
+ BACKEND->handle = NULL;
}
}
/*
* This function is called when an SSL connection is closed.
*/
-void Curl_nss_close(struct connectdata *conn, int sockindex)
+static void Curl_nss_close(struct connectdata *conn, int sockindex)
{
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
struct ssl_connect_data *connssl_proxy = &conn->proxy_ssl[sockindex];
- if(connssl->handle || connssl_proxy->handle) {
+ if(BACKEND->handle || connssl_proxy->backend->handle) {
/* NSS closes the socket we previously handed to it, so we must mark it
as closed to avoid double close */
fake_sclose(conn->sock[sockindex]);
conn->sock[sockindex] = CURL_SOCKET_BAD;
}
- if(connssl->handle)
- /* nss_close(connssl) will transitively close also connssl_proxy->handle
- if both are used. Clear it to avoid a double close leading to crash. */
- connssl_proxy->handle = NULL;
+ if(BACKEND->handle)
+ /* nss_close(connssl) will transitively close also
+ connssl_proxy->backend->handle if both are used. Clear it to avoid
+ a double close leading to crash. */
+ connssl_proxy->backend->handle = NULL;
nss_close(connssl);
nss_close(connssl_proxy);
@@ -1500,7 +1562,6 @@ static bool is_nss_error(CURLcode err)
{
switch(err) {
case CURLE_PEER_FAILED_VERIFICATION:
- case CURLE_SSL_CACERT:
case CURLE_SSL_CERTPROBLEM:
case CURLE_SSL_CONNECT_ERROR:
case CURLE_SSL_ISSUER_ERROR:
@@ -1557,8 +1618,9 @@ static CURLcode nss_load_ca_certificates(struct connectdata *conn,
infof(data, "%s %s\n", (result) ? "failed to load" : "loaded",
trust_library);
if(result == CURLE_FAILED_INIT)
- /* make the error non-fatal if we are not going to verify peer */
- result = CURLE_SSL_CACERT_BADFILE;
+ /* If libnssckbi.so is not available (or fails to load), one can still
+ use CA certificates stored in NSS database. Ignore the failure. */
+ result = CURLE_OK;
}
else if(!use_trust_module && trust_module) {
/* libnssckbi.so not needed but already loaded --> unload it! */
@@ -1611,17 +1673,6 @@ static CURLcode nss_load_ca_certificates(struct connectdata *conn,
static CURLcode nss_sslver_from_curl(PRUint16 *nssver, long version)
{
switch(version) {
- case CURL_SSLVERSION_TLSv1:
- /* TODO: set sslver->max to SSL_LIBRARY_VERSION_TLS_1_3 once stable */
-#ifdef SSL_LIBRARY_VERSION_TLS_1_2
- *nssver = SSL_LIBRARY_VERSION_TLS_1_2;
-#elif defined SSL_LIBRARY_VERSION_TLS_1_1
- *nssver = SSL_LIBRARY_VERSION_TLS_1_1;
-#else
- *nssver = SSL_LIBRARY_VERSION_TLS_1_0;
-#endif
- return CURLE_OK;
-
case CURL_SSLVERSION_SSLv2:
*nssver = SSL_LIBRARY_VERSION_2;
return CURLE_OK;
@@ -1682,10 +1733,8 @@ static CURLcode nss_init_sslver(SSLVersionRange *sslver,
}
switch(min) {
- case CURL_SSLVERSION_DEFAULT:
- break;
case CURL_SSLVERSION_TLSv1:
- sslver->min = SSL_LIBRARY_VERSION_TLS_1_0;
+ case CURL_SSLVERSION_DEFAULT:
break;
default:
result = nss_sslver_from_curl(&sslver->min, min);
@@ -1693,8 +1742,6 @@ static CURLcode nss_init_sslver(SSLVersionRange *sslver,
failf(data, "unsupported min version passed via CURLOPT_SSLVERSION");
return result;
}
- if(max == CURL_SSLVERSION_MAX_NONE)
- sslver->max = sslver->min;
}
switch(max) {
@@ -1732,7 +1779,7 @@ static CURLcode nss_fail_connect(struct ssl_connect_data *connssl,
}
/* cleanup on connection failure */
- Curl_llist_destroy(&connssl->obj_list, NULL);
+ Curl_llist_destroy(&BACKEND->obj_list, NULL);
return curlerr;
}
@@ -1746,7 +1793,7 @@ static CURLcode nss_set_blocking(struct ssl_connect_data *connssl,
sock_opt.option = PR_SockOpt_Nonblocking;
sock_opt.value.non_blocking = !blocking;
- if(PR_SetSocketOption(connssl->handle, &sock_opt) != PR_SUCCESS)
+ if(PR_SetSocketOption(BACKEND->handle, &sock_opt) != PR_SUCCESS)
return nss_fail_connect(connssl, data, CURLE_SSL_CONNECT_ERROR);
return CURLE_OK;
@@ -1764,18 +1811,26 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
CURLcode result;
bool second_layer = FALSE;
+ SSLVersionRange sslver_supported;
SSLVersionRange sslver = {
SSL_LIBRARY_VERSION_TLS_1_0, /* min */
- SSL_LIBRARY_VERSION_TLS_1_0 /* max */
+#ifdef SSL_LIBRARY_VERSION_TLS_1_3
+ SSL_LIBRARY_VERSION_TLS_1_3 /* max */
+#elif defined SSL_LIBRARY_VERSION_TLS_1_2
+ SSL_LIBRARY_VERSION_TLS_1_2
+#elif defined SSL_LIBRARY_VERSION_TLS_1_1
+ SSL_LIBRARY_VERSION_TLS_1_1
+#else
+ SSL_LIBRARY_VERSION_TLS_1_0
+#endif
};
- connssl->data = data;
+ BACKEND->data = data;
/* list of all NSS objects we need to destroy in Curl_nss_close() */
- Curl_llist_init(&connssl->obj_list, nss_destroy_object);
+ Curl_llist_init(&BACKEND->obj_list, nss_destroy_object);
- /* FIXME. NSS doesn't support multiple databases open at the same time. */
PR_Lock(nss_initlock);
result = nss_init(conn->data);
if(result) {
@@ -1816,6 +1871,20 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
/* enable/disable the requested SSL version(s) */
if(nss_init_sslver(&sslver, data, conn) != CURLE_OK)
goto error;
+ if(SSL_VersionRangeGetSupported(ssl_variant_stream,
+ &sslver_supported) != SECSuccess)
+ goto error;
+ if(sslver_supported.max < sslver.max && sslver_supported.max >= sslver.min) {
+ char *sslver_req_str, *sslver_supp_str;
+ sslver_req_str = nss_sslver_to_name(sslver.max);
+ sslver_supp_str = nss_sslver_to_name(sslver_supported.max);
+ if(sslver_req_str && sslver_supp_str)
+ infof(data, "Falling back from %s to max supported SSL version (%s)\n",
+ sslver_req_str, sslver_supp_str);
+ free(sslver_req_str);
+ free(sslver_supp_str);
+ sslver.max = sslver_supported.max;
+ }
if(SSL_VersionRangeSet(model, &sslver) != SECSuccess)
goto error;
@@ -1882,7 +1951,7 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
char *nickname = dup_nickname(data, SSL_SET_OPTION(cert));
if(nickname) {
/* we are not going to use libnsspem.so to read the client cert */
- connssl->obj_clicert = NULL;
+ BACKEND->obj_clicert = NULL;
}
else {
CURLcode rv = cert_stuff(conn, sockindex, SSL_SET_OPTION(cert),
@@ -1895,10 +1964,10 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
}
/* store the nickname for SelectClientCert() called during handshake */
- connssl->client_nickname = nickname;
+ BACKEND->client_nickname = nickname;
}
else
- connssl->client_nickname = NULL;
+ BACKEND->client_nickname = NULL;
if(SSL_GetClientAuthDataHook(model, SelectClientCert,
(void *)connssl) != SECSuccess) {
@@ -1908,8 +1977,8 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
if(conn->proxy_ssl[sockindex].use) {
DEBUGASSERT(ssl_connection_complete == conn->proxy_ssl[sockindex].state);
- DEBUGASSERT(conn->proxy_ssl[sockindex].handle != NULL);
- nspr_io = conn->proxy_ssl[sockindex].handle;
+ DEBUGASSERT(conn->proxy_ssl[sockindex].backend->handle != NULL);
+ nspr_io = conn->proxy_ssl[sockindex].backend->handle;
second_layer = TRUE;
}
else {
@@ -1939,8 +2008,8 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
}
/* import our model socket onto the current I/O stack */
- connssl->handle = SSL_ImportFD(model, nspr_io);
- if(!connssl->handle) {
+ BACKEND->handle = SSL_ImportFD(model, nspr_io);
+ if(!BACKEND->handle) {
if(!second_layer)
PR_Close(nspr_io);
goto error;
@@ -1951,36 +2020,36 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
/* This is the password associated with the cert that we're using */
if(SSL_SET_OPTION(key_passwd)) {
- SSL_SetPKCS11PinArg(connssl->handle, SSL_SET_OPTION(key_passwd));
+ SSL_SetPKCS11PinArg(BACKEND->handle, SSL_SET_OPTION(key_passwd));
}
#ifdef SSL_ENABLE_OCSP_STAPLING
if(SSL_CONN_CONFIG(verifystatus)) {
- if(SSL_OptionSet(connssl->handle, SSL_ENABLE_OCSP_STAPLING, PR_TRUE)
+ if(SSL_OptionSet(BACKEND->handle, SSL_ENABLE_OCSP_STAPLING, PR_TRUE)
!= SECSuccess)
goto error;
}
#endif
#ifdef SSL_ENABLE_NPN
- if(SSL_OptionSet(connssl->handle, SSL_ENABLE_NPN, conn->bits.tls_enable_npn
+ if(SSL_OptionSet(BACKEND->handle, SSL_ENABLE_NPN, conn->bits.tls_enable_npn
? PR_TRUE : PR_FALSE) != SECSuccess)
goto error;
#endif
#ifdef SSL_ENABLE_ALPN
- if(SSL_OptionSet(connssl->handle, SSL_ENABLE_ALPN, conn->bits.tls_enable_alpn
+ if(SSL_OptionSet(BACKEND->handle, SSL_ENABLE_ALPN, conn->bits.tls_enable_alpn
? PR_TRUE : PR_FALSE) != SECSuccess)
goto error;
#endif
#if NSSVERNUM >= 0x030f04 /* 3.15.4 */
if(data->set.ssl.falsestart) {
- if(SSL_OptionSet(connssl->handle, SSL_ENABLE_FALSE_START, PR_TRUE)
+ if(SSL_OptionSet(BACKEND->handle, SSL_ENABLE_FALSE_START, PR_TRUE)
!= SECSuccess)
goto error;
- if(SSL_SetCanFalseStartCallback(connssl->handle, CanFalseStartCallback,
+ if(SSL_SetCanFalseStartCallback(BACKEND->handle, CanFalseStartCallback,
conn) != SECSuccess)
goto error;
}
@@ -1992,7 +2061,8 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
unsigned char protocols[128];
#ifdef USE_NGHTTP2
- if(data->set.httpversion >= CURL_HTTP_VERSION_2) {
+ if(data->set.httpversion >= CURL_HTTP_VERSION_2 &&
+ (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) {
protocols[cur++] = NGHTTP2_PROTO_VERSION_ID_LEN;
memcpy(&protocols[cur], NGHTTP2_PROTO_VERSION_ID,
NGHTTP2_PROTO_VERSION_ID_LEN);
@@ -2003,24 +2073,24 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex)
memcpy(&protocols[cur], ALPN_HTTP_1_1, ALPN_HTTP_1_1_LENGTH);
cur += ALPN_HTTP_1_1_LENGTH;
- if(SSL_SetNextProtoNego(connssl->handle, protocols, cur) != SECSuccess)
+ if(SSL_SetNextProtoNego(BACKEND->handle, protocols, cur) != SECSuccess)
goto error;
}
#endif
/* Force handshake on next I/O */
- if(SSL_ResetHandshake(connssl->handle, /* asServer */ PR_FALSE)
+ if(SSL_ResetHandshake(BACKEND->handle, /* asServer */ PR_FALSE)
!= SECSuccess)
goto error;
/* propagate hostname to the TLS layer */
- if(SSL_SetURL(connssl->handle, SSL_IS_PROXY() ? conn->http_proxy.host.name :
+ if(SSL_SetURL(BACKEND->handle, SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name) != SECSuccess)
goto error;
/* prevent NSS from re-using the session for a different hostname */
- if(SSL_SetSockPeerID(connssl->handle, SSL_IS_PROXY() ?
+ if(SSL_SetSockPeerID(BACKEND->handle, SSL_IS_PROXY() ?
conn->http_proxy.host.name : conn->host.name)
!= SECSuccess)
goto error;
@@ -2057,18 +2127,18 @@ static CURLcode nss_do_connect(struct connectdata *conn, int sockindex)
/* Force the handshake now */
timeout = PR_MillisecondsToInterval((PRUint32) time_left);
- if(SSL_ForceHandshakeWithTimeout(connssl->handle, timeout) != SECSuccess) {
+ if(SSL_ForceHandshakeWithTimeout(BACKEND->handle, timeout) != SECSuccess) {
if(PR_GetError() == PR_WOULD_BLOCK_ERROR)
/* blocking direction is updated by nss_update_connecting_state() */
return CURLE_AGAIN;
else if(*certverifyresult == SSL_ERROR_BAD_CERT_DOMAIN)
result = CURLE_PEER_FAILED_VERIFICATION;
else if(*certverifyresult != 0)
- result = CURLE_SSL_CACERT;
+ result = CURLE_PEER_FAILED_VERIFICATION;
goto error;
}
- result = display_conn_info(conn, connssl->handle);
+ result = display_conn_info(conn, BACKEND->handle);
if(result)
goto error;
@@ -2077,7 +2147,7 @@ static CURLcode nss_do_connect(struct connectdata *conn, int sockindex)
char *nickname = dup_nickname(data, SSL_SET_OPTION(issuercert));
if(nickname) {
/* we support only nicknames in case of issuercert for now */
- ret = check_issuer_cert(connssl->handle, nickname);
+ ret = check_issuer_cert(BACKEND->handle, nickname);
free(nickname);
}
@@ -2138,7 +2208,7 @@ static CURLcode nss_connect_common(struct connectdata *conn, int sockindex,
if(!blocking)
/* CURLE_AGAIN in non-blocking mode is not an error */
return CURLE_OK;
- /* fall through */
+ /* FALLTHROUGH */
default:
return result;
}
@@ -2163,13 +2233,13 @@ static CURLcode nss_connect_common(struct connectdata *conn, int sockindex,
return CURLE_OK;
}
-CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
+static CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
{
return nss_connect_common(conn, sockindex, /* blocking */ NULL);
}
-CURLcode Curl_nss_connect_nonblocking(struct connectdata *conn,
- int sockindex, bool *done)
+static CURLcode Curl_nss_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
{
return nss_connect_common(conn, sockindex, done);
}
@@ -2180,8 +2250,14 @@ static ssize_t nss_send(struct connectdata *conn, /* connection data */
size_t len, /* amount to write */
CURLcode *curlcode)
{
- ssize_t rc = PR_Send(conn->ssl[sockindex].handle, mem, (int)len, 0,
- PR_INTERVAL_NO_WAIT);
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ ssize_t rc;
+
+ /* The SelectClientCert() hook uses this for infof() and failf() but the
+ handle stored in nss_setup_connect() could have already been freed. */
+ BACKEND->data = conn->data;
+
+ rc = PR_Send(BACKEND->handle, mem, (int)len, 0, PR_INTERVAL_NO_WAIT);
if(rc < 0) {
PRInt32 err = PR_GetError();
if(err == PR_WOULD_BLOCK_ERROR)
@@ -2205,14 +2281,21 @@ static ssize_t nss_send(struct connectdata *conn, /* connection data */
return rc; /* number of bytes */
}
-static ssize_t nss_recv(struct connectdata * conn, /* connection data */
- int num, /* socketindex */
+static ssize_t nss_recv(struct connectdata *conn, /* connection data */
+ int sockindex, /* socketindex */
char *buf, /* store read data here */
size_t buffersize, /* max amount to read */
CURLcode *curlcode)
{
- ssize_t nread = PR_Recv(conn->ssl[num].handle, buf, (int)buffersize, 0,
- PR_INTERVAL_NO_WAIT);
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ ssize_t nread;
+
+ /* The SelectClientCert() hook uses this for infof() and failf() but the
+ handle stored in nss_setup_connect() could have already been freed. */
+ BACKEND->data = conn->data;
+
+ nread = PR_Recv(BACKEND->handle, buf, (int)buffersize, 0,
+ PR_INTERVAL_NO_WAIT);
if(nread < 0) {
/* failed SSL read */
PRInt32 err = PR_GetError();
@@ -2238,22 +2321,22 @@ static ssize_t nss_recv(struct connectdata * conn, /* connection data */
return nread;
}
-size_t Curl_nss_version(char *buffer, size_t size)
+static size_t Curl_nss_version(char *buffer, size_t size)
{
- return snprintf(buffer, size, "NSS/%s", NSS_VERSION);
+ return msnprintf(buffer, size, "NSS/%s", NSS_VERSION);
}
/* data might be NULL */
-int Curl_nss_seed(struct Curl_easy *data)
+static int Curl_nss_seed(struct Curl_easy *data)
{
/* make sure that NSS is initialized */
return !!Curl_nss_force_init(data);
}
/* data might be NULL */
-CURLcode Curl_nss_random(struct Curl_easy *data,
- unsigned char *entropy,
- size_t length)
+static CURLcode Curl_nss_random(struct Curl_easy *data,
+ unsigned char *entropy,
+ size_t length)
{
Curl_nss_seed(data); /* Initiate the seed if not already done */
@@ -2264,10 +2347,10 @@ CURLcode Curl_nss_random(struct Curl_easy *data,
return CURLE_OK;
}
-void Curl_nss_md5sum(unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *md5sum, /* output */
- size_t md5len)
+static CURLcode Curl_nss_md5sum(unsigned char *tmp, /* input */
+ size_t tmplen,
+ unsigned char *md5sum, /* output */
+ size_t md5len)
{
PK11Context *MD5pw = PK11_CreateDigestContext(SEC_OID_MD5);
unsigned int MD5out;
@@ -2275,12 +2358,14 @@ void Curl_nss_md5sum(unsigned char *tmp, /* input */
PK11_DigestOp(MD5pw, tmp, curlx_uztoui(tmplen));
PK11_DigestFinal(MD5pw, md5sum, &MD5out, curlx_uztoui(md5len));
PK11_DestroyContext(MD5pw, PR_TRUE);
+
+ return CURLE_OK;
}
-void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum, /* output */
- size_t sha256len)
+static CURLcode Curl_nss_sha256sum(const unsigned char *tmp, /* input */
+ size_t tmplen,
+ unsigned char *sha256sum, /* output */
+ size_t sha256len)
{
PK11Context *SHA256pw = PK11_CreateDigestContext(SEC_OID_SHA256);
unsigned int SHA256out;
@@ -2288,9 +2373,11 @@ void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
PK11_DigestOp(SHA256pw, tmp, curlx_uztoui(tmplen));
PK11_DigestFinal(SHA256pw, sha256sum, &SHA256out, curlx_uztoui(sha256len));
PK11_DestroyContext(SHA256pw, PR_TRUE);
+
+ return CURLE_OK;
}
-bool Curl_nss_cert_status_request(void)
+static bool Curl_nss_cert_status_request(void)
{
#ifdef SSL_ENABLE_OCSP_STAPLING
return TRUE;
@@ -2299,7 +2386,7 @@ bool Curl_nss_cert_status_request(void)
#endif
}
-bool Curl_nss_false_start(void)
+static bool Curl_nss_false_start(void)
{
#if NSSVERNUM >= 0x030f04 /* 3.15.4 */
return TRUE;
@@ -2308,4 +2395,45 @@ bool Curl_nss_false_start(void)
#endif
}
+static void *Curl_nss_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info UNUSED_PARAM)
+{
+ (void)info;
+ return BACKEND->handle;
+}
+
+const struct Curl_ssl Curl_ssl_nss = {
+ { CURLSSLBACKEND_NSS, "nss" }, /* info */
+
+ SSLSUPP_CA_PATH |
+ SSLSUPP_CERTINFO |
+ SSLSUPP_PINNEDPUBKEY |
+ SSLSUPP_HTTPS_PROXY,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_nss_init, /* init */
+ Curl_nss_cleanup, /* cleanup */
+ Curl_nss_version, /* version */
+ Curl_nss_check_cxn, /* check_cxn */
+ /* NSS has no shutdown function provided and thus always fail */
+ Curl_none_shutdown, /* shutdown */
+ Curl_none_data_pending, /* data_pending */
+ Curl_nss_random, /* random */
+ Curl_nss_cert_status_request, /* cert_status_request */
+ Curl_nss_connect, /* connect */
+ Curl_nss_connect_nonblocking, /* connect_nonblocking */
+ Curl_nss_get_internals, /* get_internals */
+ Curl_nss_close, /* close_one */
+ Curl_none_close_all, /* close_all */
+ /* NSS has its own session ID cache */
+ Curl_none_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_nss_false_start, /* false_start */
+ Curl_nss_md5sum, /* md5sum */
+ Curl_nss_sha256sum /* sha256sum */
+};
+
#endif /* USE_NSS */
diff --git a/Utilities/cmcurl/lib/vtls/nssg.h b/Utilities/cmcurl/lib/vtls/nssg.h
index 8c46929ff..41e51b021 100644
--- a/Utilities/cmcurl/lib/vtls/nssg.h
+++ b/Utilities/cmcurl/lib/vtls/nssg.h
@@ -30,79 +30,10 @@
#include "urldata.h"
-CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex);
-CURLcode Curl_nss_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done);
-/* close a SSL connection */
-void Curl_nss_close(struct connectdata *conn, int sockindex);
-
-int Curl_nss_init(void);
-void Curl_nss_cleanup(void);
-
-size_t Curl_nss_version(char *buffer, size_t size);
-int Curl_nss_check_cxn(struct connectdata *cxn);
-int Curl_nss_seed(struct Curl_easy *data);
-
/* initialize NSS library if not already */
CURLcode Curl_nss_force_init(struct Curl_easy *data);
-CURLcode Curl_nss_random(struct Curl_easy *data,
- unsigned char *entropy,
- size_t length);
-
-void Curl_nss_md5sum(unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *md5sum, /* output */
- size_t md5len);
-
-void Curl_nss_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum, /* output */
- size_t sha256len);
-
-bool Curl_nss_cert_status_request(void);
-
-bool Curl_nss_false_start(void);
-
-/* Support HTTPS-proxy */
-#define HTTPS_PROXY_SUPPORT 1
-
-/* Set the API backend definition to NSS */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_NSS
-
-/* this backend supports the CAPATH option */
-#define have_curlssl_ca_path 1
-
-/* this backend supports CURLOPT_CERTINFO */
-#define have_curlssl_certinfo 1
-
-/* this backends supports CURLOPT_PINNEDPUBLICKEY */
-#define have_curlssl_pinnedpubkey 1
-
-/* API setup for NSS */
-#define curlssl_init Curl_nss_init
-#define curlssl_cleanup Curl_nss_cleanup
-#define curlssl_connect Curl_nss_connect
-#define curlssl_connect_nonblocking Curl_nss_connect_nonblocking
-
-/* NSS has its own session ID cache */
-#define curlssl_session_free(x) Curl_nop_stmt
-#define curlssl_close_all(x) ((void)x)
-#define curlssl_close Curl_nss_close
-/* NSS has no shutdown function provided and thus always fail */
-#define curlssl_shutdown(x,y) ((void)x, (void)y, 1)
-#define curlssl_set_engine(x,y) ((void)x, (void)y, CURLE_NOT_BUILT_IN)
-#define curlssl_set_engine_default(x) ((void)x, CURLE_NOT_BUILT_IN)
-#define curlssl_engines_list(x) ((void)x, (struct curl_slist *)NULL)
-#define curlssl_version Curl_nss_version
-#define curlssl_check_cxn(x) Curl_nss_check_cxn(x)
-#define curlssl_data_pending(x,y) ((void)x, (void)y, 0)
-#define curlssl_random(x,y,z) Curl_nss_random(x,y,z)
-#define curlssl_md5sum(a,b,c,d) Curl_nss_md5sum(a,b,c,d)
-#define curlssl_sha256sum(a,b,c,d) Curl_nss_sha256sum(a,b,c,d)
-#define curlssl_cert_status_request() Curl_nss_cert_status_request()
-#define curlssl_false_start() Curl_nss_false_start()
+extern const struct Curl_ssl Curl_ssl_nss;
#endif /* USE_NSS */
#endif /* HEADER_CURL_NSSG_H */
diff --git a/Utilities/cmcurl/lib/vtls/openssl.c b/Utilities/cmcurl/lib/vtls/openssl.c
index dbee36929..85e9be616 100644
--- a/Utilities/cmcurl/lib/vtls/openssl.c
+++ b/Utilities/cmcurl/lib/vtls/openssl.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -34,9 +34,7 @@
#ifdef USE_OPENSSL
-#ifdef HAVE_LIMITS_H
#include <limits.h>
-#endif
#include "urldata.h"
#include "sendf.h"
@@ -50,8 +48,8 @@
#include "vtls.h"
#include "strcase.h"
#include "hostcheck.h"
+#include "multiif.h"
#include "curl_printf.h"
-
#include <openssl/ssl.h>
#include <openssl/rand.h>
#include <openssl/x509v3.h>
@@ -64,15 +62,24 @@
#include <openssl/conf.h>
#include <openssl/bn.h>
#include <openssl/rsa.h>
-
-#ifdef HAVE_OPENSSL_PKCS12_H
+#include <openssl/bio.h>
+#include <openssl/buffer.h>
#include <openssl/pkcs12.h>
+
+#ifdef USE_AMISSL
+#include "amigaos.h"
#endif
#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_OCSP)
#include <openssl/ocsp.h>
#endif
+#if (OPENSSL_VERSION_NUMBER >= 0x0090700fL) && /* 0.9.7 or later */ \
+ !defined(OPENSSL_NO_ENGINE)
+#define USE_OPENSSL_ENGINE
+#include <openssl/engine.h>
+#endif
+
#include "warnless.h"
#include "non-ascii.h" /* for Curl_convert_from_utf8 prototype */
@@ -80,11 +87,18 @@
#include "curl_memory.h"
#include "memdebug.h"
+/* Uncomment the ALLOW_RENEG line to a real #define if you want to allow TLS
+ renegotiations when built with BoringSSL. Renegotiating is non-compliant
+ with HTTP/2 and "an extremely dangerous protocol feature". Beware.
+
+#define ALLOW_RENEG 1
+ */
+
#ifndef OPENSSL_VERSION_NUMBER
#error "OPENSSL_VERSION_NUMBER not defined"
#endif
-#if defined(HAVE_OPENSSL_ENGINE_H)
+#ifdef USE_OPENSSL_ENGINE
#include <openssl/ui.h>
#endif
@@ -105,33 +119,40 @@
#endif
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && /* OpenSSL 1.1.0+ */ \
- !defined(LIBRESSL_VERSION_NUMBER)
+ !(defined(LIBRESSL_VERSION_NUMBER) && \
+ LIBRESSL_VERSION_NUMBER < 0x20700000L)
#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
#define HAVE_X509_GET0_EXTENSIONS 1 /* added in 1.1.0 -pre1 */
#define HAVE_OPAQUE_EVP_PKEY 1 /* since 1.1.0 -pre3 */
#define HAVE_OPAQUE_RSA_DSA_DH 1 /* since 1.1.0 -pre5 */
#define CONST_EXTS const
-#define CONST_ASN1_BIT_STRING const
#define HAVE_ERR_REMOVE_THREAD_STATE_DEPRECATED 1
+
+/* funny typecast define due to difference in API */
+#ifdef LIBRESSL_VERSION_NUMBER
+#define ARG2_X509_signature_print (X509_ALGOR *)
+#else
+#define ARG2_X509_signature_print
+#endif
+
#else
/* For OpenSSL before 1.1.0 */
#define ASN1_STRING_get0_data(x) ASN1_STRING_data(x)
#define X509_get0_notBefore(x) X509_get_notBefore(x)
#define X509_get0_notAfter(x) X509_get_notAfter(x)
#define CONST_EXTS /* nope */
-#define CONST_ASN1_BIT_STRING /* nope */
-#ifdef LIBRESSL_VERSION_NUMBER
-static unsigned long OpenSSL_version_num(void)
-{
- return LIBRESSL_VERSION_NUMBER;
-}
-#else
+#ifndef LIBRESSL_VERSION_NUMBER
#define OpenSSL_version_num() SSLeay()
#endif
#endif
+#ifdef LIBRESSL_VERSION_NUMBER
+#define OpenSSL_version_num() LIBRESSL_VERSION_NUMBER
+#endif
+
#if (OPENSSL_VERSION_NUMBER >= 0x1000200fL) && /* 1.0.2 or later */ \
- !defined(LIBRESSL_VERSION_NUMBER)
+ !(defined(LIBRESSL_VERSION_NUMBER) && \
+ LIBRESSL_VERSION_NUMBER < 0x20700000L)
#define HAVE_X509_GET0_SIGNATURE 1
#endif
@@ -146,6 +167,31 @@ static unsigned long OpenSSL_version_num(void)
#define OPENSSL_load_builtin_modules(x)
#endif
+/*
+ * Whether SSL_CTX_set_keylog_callback is available.
+ * OpenSSL: supported since 1.1.1 https://github.com/openssl/openssl/pull/2287
+ * BoringSSL: supported since d28f59c27bac (committed 2015-11-19)
+ * LibreSSL: unsupported in at least 2.7.2 (explicitly check for it since it
+ * lies and pretends to be OpenSSL 2.0.0).
+ */
+#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && \
+ !defined(LIBRESSL_VERSION_NUMBER)) || \
+ defined(OPENSSL_IS_BORINGSSL)
+#define HAVE_KEYLOG_CALLBACK
+#endif
+
+/* Whether SSL_CTX_set_ciphersuites is available.
+ * OpenSSL: supported since 1.1.1 (commit a53b5be6a05)
+ * BoringSSL: no
+ * LibreSSL: no
+ */
+#if ((OPENSSL_VERSION_NUMBER >= 0x10101000L) && \
+ !defined(LIBRESSL_VERSION_NUMBER) && \
+ !defined(OPENSSL_IS_BORINGSSL))
+#define HAVE_SSL_CTX_SET_CIPHERSUITES
+#define HAVE_SSL_CTX_SET_POST_HANDSHAKE_AUTH
+#endif
+
#if defined(LIBRESSL_VERSION_NUMBER)
#define OSSL_PACKAGE "LibreSSL"
#elif defined(OPENSSL_IS_BORINGSSL)
@@ -154,6 +200,40 @@ static unsigned long OpenSSL_version_num(void)
#define OSSL_PACKAGE "OpenSSL"
#endif
+#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
+/* up2date versions of OpenSSL maintain the default reasonably secure without
+ * breaking compatibility, so it is better not to override the default by curl
+ */
+#define DEFAULT_CIPHER_SELECTION NULL
+#else
+/* ... but it is not the case with old versions of OpenSSL */
+#define DEFAULT_CIPHER_SELECTION \
+ "ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH"
+#endif
+
+#define ENABLE_SSLKEYLOGFILE
+
+#ifdef ENABLE_SSLKEYLOGFILE
+typedef struct ssl_tap_state {
+ int master_key_length;
+ unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
+ unsigned char client_random[SSL3_RANDOM_SIZE];
+} ssl_tap_state_t;
+#endif /* ENABLE_SSLKEYLOGFILE */
+
+struct ssl_backend_data {
+ /* these ones requires specific SSL-types */
+ SSL_CTX* ctx;
+ SSL* handle;
+ X509* server_cert;
+#ifdef ENABLE_SSLKEYLOGFILE
+ /* tap_state holds the last seen master key if we're logging them */
+ ssl_tap_state_t tap_state;
+#endif
+};
+
+#define BACKEND connssl->backend
+
/*
* 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
@@ -162,6 +242,114 @@ static unsigned long OpenSSL_version_num(void)
*/
#define RAND_LOAD_LENGTH 1024
+#ifdef ENABLE_SSLKEYLOGFILE
+/* The fp for the open SSLKEYLOGFILE, or NULL if not open */
+static FILE *keylog_file_fp;
+
+#ifdef HAVE_KEYLOG_CALLBACK
+static void ossl_keylog_callback(const SSL *ssl, const char *line)
+{
+ (void)ssl;
+
+ /* Using fputs here instead of fprintf since libcurl's fprintf replacement
+ may not be thread-safe. */
+ if(keylog_file_fp && line && *line) {
+ char stackbuf[256];
+ char *buf;
+ size_t linelen = strlen(line);
+
+ if(linelen <= sizeof(stackbuf) - 2)
+ buf = stackbuf;
+ else {
+ buf = malloc(linelen + 2);
+ if(!buf)
+ return;
+ }
+ memcpy(buf, line, linelen);
+ buf[linelen] = '\n';
+ buf[linelen + 1] = '\0';
+
+ fputs(buf, keylog_file_fp);
+ if(buf != stackbuf)
+ free(buf);
+ }
+}
+#else
+#define KEYLOG_PREFIX "CLIENT_RANDOM "
+#define KEYLOG_PREFIX_LEN (sizeof(KEYLOG_PREFIX) - 1)
+/*
+ * tap_ssl_key is called by libcurl to make the CLIENT_RANDOMs if the OpenSSL
+ * being used doesn't have native support for doing that.
+ */
+static void tap_ssl_key(const SSL *ssl, ssl_tap_state_t *state)
+{
+ const char *hex = "0123456789ABCDEF";
+ int pos, i;
+ char line[KEYLOG_PREFIX_LEN + 2 * SSL3_RANDOM_SIZE + 1 +
+ 2 * SSL_MAX_MASTER_KEY_LENGTH + 1 + 1];
+ const SSL_SESSION *session = SSL_get_session(ssl);
+ unsigned char client_random[SSL3_RANDOM_SIZE];
+ unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
+ int master_key_length = 0;
+
+ if(!session || !keylog_file_fp)
+ return;
+
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \
+ !(defined(LIBRESSL_VERSION_NUMBER) && \
+ LIBRESSL_VERSION_NUMBER < 0x20700000L)
+ /* ssl->s3 is not checked in openssl 1.1.0-pre6, but let's assume that
+ * we have a valid SSL context if we have a non-NULL session. */
+ SSL_get_client_random(ssl, client_random, SSL3_RANDOM_SIZE);
+ master_key_length = (int)
+ SSL_SESSION_get_master_key(session, master_key, SSL_MAX_MASTER_KEY_LENGTH);
+#else
+ if(ssl->s3 && session->master_key_length > 0) {
+ master_key_length = session->master_key_length;
+ memcpy(master_key, session->master_key, session->master_key_length);
+ memcpy(client_random, ssl->s3->client_random, SSL3_RANDOM_SIZE);
+ }
+#endif
+
+ if(master_key_length <= 0)
+ return;
+
+ /* Skip writing keys if there is no key or it did not change. */
+ if(state->master_key_length == master_key_length &&
+ !memcmp(state->master_key, master_key, master_key_length) &&
+ !memcmp(state->client_random, client_random, SSL3_RANDOM_SIZE)) {
+ return;
+ }
+
+ state->master_key_length = master_key_length;
+ memcpy(state->master_key, master_key, master_key_length);
+ memcpy(state->client_random, client_random, SSL3_RANDOM_SIZE);
+
+ memcpy(line, KEYLOG_PREFIX, KEYLOG_PREFIX_LEN);
+ pos = KEYLOG_PREFIX_LEN;
+
+ /* Client Random for SSLv3/TLS */
+ for(i = 0; i < SSL3_RANDOM_SIZE; i++) {
+ line[pos++] = hex[client_random[i] >> 4];
+ line[pos++] = hex[client_random[i] & 0xF];
+ }
+ line[pos++] = ' ';
+
+ /* Master Secret (size is at most SSL_MAX_MASTER_KEY_LENGTH) */
+ for(i = 0; i < master_key_length; i++) {
+ line[pos++] = hex[master_key[i] >> 4];
+ line[pos++] = hex[master_key[i] & 0xF];
+ }
+ line[pos++] = '\n';
+ line[pos] = '\0';
+
+ /* Using fputs here instead of fprintf since libcurl's fprintf replacement
+ may not be thread-safe. */
+ fputs(line, keylog_file_fp);
+}
+#endif /* !HAVE_KEYLOG_CALLBACK */
+#endif /* ENABLE_SSLKEYLOGFILE */
+
static const char *SSL_ERROR_to_str(int err)
{
switch(err) {
@@ -208,6 +396,31 @@ static char *ossl_strerror(unsigned long error, char *buf, size_t size)
return buf;
}
+/* Return an extra data index for the connection data.
+ * This index can be used with SSL_get_ex_data() and SSL_set_ex_data().
+ */
+static int ossl_get_ssl_conn_index(void)
+{
+ static int ssl_ex_data_conn_index = -1;
+ if(ssl_ex_data_conn_index < 0) {
+ ssl_ex_data_conn_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL);
+ }
+ return ssl_ex_data_conn_index;
+}
+
+/* Return an extra data index for the sockindex.
+ * This index can be used with SSL_get_ex_data() and SSL_set_ex_data().
+ */
+static int ossl_get_ssl_sockindex_index(void)
+{
+ static int ssl_ex_data_sockindex_index = -1;
+ if(ssl_ex_data_sockindex_index < 0) {
+ ssl_ex_data_sockindex_index = SSL_get_ex_new_index(0, NULL, NULL, NULL,
+ NULL);
+ }
+ return ssl_ex_data_sockindex_index;
+}
+
static int passwd_callback(char *buf, int num, int encrypting,
void *global_passwd)
{
@@ -216,7 +429,7 @@ static int passwd_callback(char *buf, int num, int encrypting,
if(!encrypting) {
int klen = curlx_uztosi(strlen((char *)global_passwd));
if(num > klen) {
- memcpy(buf, global_passwd, klen+1);
+ memcpy(buf, global_passwd, klen + 1);
return klen;
}
}
@@ -236,7 +449,6 @@ static CURLcode Curl_ossl_seed(struct Curl_easy *data)
/* we have the "SSL is seeded" boolean static to prevent multiple
time-consuming seedings in vain */
static bool ssl_seeded = FALSE;
- int nread=0;
char fname[256];
if(ssl_seeded)
@@ -256,12 +468,12 @@ static CURLcode Curl_ossl_seed(struct Curl_easy *data)
#endif
{
/* let the option override the define */
- nread += RAND_load_file((data->set.str[STRING_SSL_RANDOM_FILE]?
- data->set.str[STRING_SSL_RANDOM_FILE]:
- RANDOM_FILE),
- RAND_LOAD_LENGTH);
+ RAND_load_file((data->set.str[STRING_SSL_RANDOM_FILE]?
+ data->set.str[STRING_SSL_RANDOM_FILE]:
+ RANDOM_FILE),
+ RAND_LOAD_LENGTH);
if(rand_enough())
- return nread;
+ return CURLE_OK;
}
#if defined(HAVE_RAND_EGD)
@@ -279,35 +491,47 @@ static CURLcode Curl_ossl_seed(struct Curl_easy *data)
int ret = RAND_egd(data->set.str[STRING_SSL_EGDSOCKET]?
data->set.str[STRING_SSL_EGDSOCKET]:EGD_SOCKET);
if(-1 != ret) {
- nread += ret;
if(rand_enough())
- return nread;
+ return CURLE_OK;
}
}
#endif
- /* If we get here, it means we need to seed the PRNG using a "silly"
- approach! */
+ /* fallback to a custom seeding of the PRNG using a hash based on a current
+ time */
do {
unsigned char randb[64];
- int len = sizeof(randb);
- if(!RAND_bytes(randb, len))
- break;
- RAND_add(randb, len, (len >> 1));
+ size_t len = sizeof(randb);
+ size_t i, i_max;
+ for(i = 0, i_max = len / sizeof(struct curltime); i < i_max; ++i) {
+ struct curltime tv = Curl_now();
+ Curl_wait_ms(1);
+ tv.tv_sec *= i + 1;
+ tv.tv_usec *= (unsigned int)i + 2;
+ tv.tv_sec ^= ((Curl_now().tv_sec + Curl_now().tv_usec) *
+ (i + 3)) << 8;
+ tv.tv_usec ^= (unsigned int) ((Curl_now().tv_sec +
+ Curl_now().tv_usec) *
+ (i + 4)) << 16;
+ memcpy(&randb[i * sizeof(struct curltime)], &tv,
+ sizeof(struct curltime));
+ }
+ RAND_add(randb, (int)len, (double)len/2);
} while(!rand_enough());
/* generates a default path for the random seed file */
- fname[0]=0; /* blank it first */
+ fname[0] = 0; /* blank it first */
RAND_file_name(fname, sizeof(fname));
if(fname[0]) {
/* we got a file name to try */
- nread += RAND_load_file(fname, RAND_LOAD_LENGTH);
+ RAND_load_file(fname, RAND_LOAD_LENGTH);
if(rand_enough())
- return nread;
+ return CURLE_OK;
}
infof(data, "libcurl is now using a weak random seed!\n");
- return CURLE_SSL_CONNECT_ERROR; /* confusing error code */
+ return (rand_enough() ? CURLE_OK :
+ CURLE_SSL_CONNECT_ERROR /* confusing error code */);
}
#ifndef SSL_FILETYPE_ENGINE
@@ -331,7 +555,7 @@ static int do_file_type(const char *type)
return -1;
}
-#if defined(HAVE_OPENSSL_ENGINE_H)
+#ifdef USE_OPENSSL_ENGINE
/*
* Supply default password to the engine user interface conversation.
* The password is passed by OpenSSL engine from ENGINE_load_private_key()
@@ -371,8 +595,20 @@ static int ssl_ui_writer(UI *ui, UI_STRING *uis)
}
return (UI_method_get_writer(UI_OpenSSL()))(ui, uis);
}
+
+/*
+ * Check if a given string is a PKCS#11 URI
+ */
+static bool is_pkcs11_uri(const char *string)
+{
+ return (string && strncasecompare(string, "pkcs11:", 7));
+}
+
#endif
+static CURLcode Curl_ossl_set_engine(struct Curl_easy *data,
+ const char *engine);
+
static
int cert_stuff(struct connectdata *conn,
SSL_CTX* ctx,
@@ -384,6 +620,7 @@ int cert_stuff(struct connectdata *conn,
{
struct Curl_easy *data = conn->data;
char error_buffer[256];
+ bool check_privkey = TRUE;
int file_type = do_file_type(cert_type);
@@ -432,8 +669,18 @@ int cert_stuff(struct connectdata *conn,
}
break;
case SSL_FILETYPE_ENGINE:
-#if defined(HAVE_OPENSSL_ENGINE_H) && defined(ENGINE_CTRL_GET_CMD_FROM_NAME)
+#if defined(USE_OPENSSL_ENGINE) && defined(ENGINE_CTRL_GET_CMD_FROM_NAME)
{
+ /* Implicitly use pkcs11 engine if none was provided and the
+ * cert_file is a PKCS#11 URI */
+ if(!data->state.engine) {
+ if(is_pkcs11_uri(cert_file)) {
+ if(Curl_ossl_set_engine(data, "pkcs11") != CURLE_OK) {
+ return 0;
+ }
+ }
+ }
+
if(data->state.engine) {
const char *cmd_name = "LOAD_CERT_CTRL";
struct {
@@ -487,19 +734,28 @@ int cert_stuff(struct connectdata *conn,
case SSL_FILETYPE_PKCS12:
{
-#ifdef HAVE_OPENSSL_PKCS12_H
- FILE *f;
- PKCS12 *p12;
+ BIO *fp = NULL;
+ PKCS12 *p12 = NULL;
EVP_PKEY *pri;
STACK_OF(X509) *ca = NULL;
- f = fopen(cert_file, "rb");
- if(!f) {
+ fp = BIO_new(BIO_s_file());
+ if(fp == NULL) {
+ failf(data,
+ "BIO_new return NULL, " OSSL_PACKAGE
+ " error %s",
+ ossl_strerror(ERR_get_error(), error_buffer,
+ sizeof(error_buffer)) );
+ return 0;
+ }
+
+ if(BIO_read_filename(fp, cert_file) <= 0) {
failf(data, "could not open PKCS12 file '%s'", cert_file);
+ BIO_free(fp);
return 0;
}
- p12 = d2i_PKCS12_fp(f, NULL);
- fclose(f);
+ p12 = d2i_PKCS12_bio(fp, NULL);
+ BIO_free(fp);
if(!p12) {
failf(data, "error reading PKCS12 file '%s'", cert_file);
@@ -569,30 +825,29 @@ int cert_stuff(struct connectdata *conn,
fail:
EVP_PKEY_free(pri);
X509_free(x509);
+#ifdef USE_AMISSL
+ sk_X509_pop_free(ca, Curl_amiga_X509_free);
+#else
sk_X509_pop_free(ca, X509_free);
-
+#endif
if(!cert_done)
return 0; /* failure! */
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);
+ if(!key_file)
+ key_file = cert_file;
+ else
+ file_type = do_file_type(key_type);
switch(file_type) {
case SSL_FILETYPE_PEM:
if(cert_done)
break;
- if(!key_file)
- /* cert & key can only be in PEM case in the same file */
- key_file=cert_file;
/* FALLTHROUGH */
case SSL_FILETYPE_ASN1:
if(SSL_CTX_use_PrivateKey_file(ctx, key_file, file_type) != 1) {
@@ -602,9 +857,20 @@ int cert_stuff(struct connectdata *conn,
}
break;
case SSL_FILETYPE_ENGINE:
-#ifdef HAVE_OPENSSL_ENGINE_H
+#ifdef USE_OPENSSL_ENGINE
{ /* XXXX still needs some work */
EVP_PKEY *priv_key = NULL;
+
+ /* Implicitly use pkcs11 engine if none was provided and the
+ * key_file is a PKCS#11 URI */
+ if(!data->state.engine) {
+ if(is_pkcs11_uri(key_file)) {
+ if(Curl_ossl_set_engine(data, "pkcs11") != CURLE_OK) {
+ return 0;
+ }
+ }
+ }
+
if(data->state.engine) {
UI_METHOD *ui_method =
UI_create_method((char *)"curl user interface");
@@ -655,13 +921,13 @@ int cert_stuff(struct connectdata *conn,
return 0;
}
- ssl=SSL_new(ctx);
+ ssl = SSL_new(ctx);
if(!ssl) {
failf(data, "unable to create an SSL structure");
return 0;
}
- x509=SSL_get_certificate(ssl);
+ x509 = SSL_get_certificate(ssl);
/* This version was provided by Evan Jordan and is supposed to not
leak memory as the previous version: */
@@ -671,17 +937,38 @@ int cert_stuff(struct connectdata *conn,
EVP_PKEY_free(pktmp);
}
+#if !defined(OPENSSL_NO_RSA) && !defined(OPENSSL_IS_BORINGSSL)
+ {
+ /* If RSA is used, don't check the private key if its flags indicate
+ * it doesn't support it. */
+ EVP_PKEY *priv_key = SSL_get_privatekey(ssl);
+ int pktype;
+#ifdef HAVE_OPAQUE_EVP_PKEY
+ pktype = EVP_PKEY_id(priv_key);
+#else
+ pktype = priv_key->type;
+#endif
+ if(pktype == EVP_PKEY_RSA) {
+ RSA *rsa = EVP_PKEY_get1_RSA(priv_key);
+ if(RSA_flags(rsa) & RSA_METHOD_FLAG_NO_CHECK)
+ check_privkey = FALSE;
+ RSA_free(rsa); /* Decrement reference count */
+ }
+ }
+#endif
+
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;
+ if(check_privkey == TRUE) {
+ /* 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;
+ }
}
}
return 1;
@@ -709,7 +996,7 @@ static int x509_name_oneline(X509_NAME *a, char *buf, size_t size)
size--; /* don't overwrite the buffer end */
memcpy(buf, biomem->data, size);
- buf[size]=0;
+ buf[size] = 0;
BIO_free(bio_out);
@@ -723,11 +1010,15 @@ static int x509_name_oneline(X509_NAME *a, char *buf, size_t size)
* @retval 0 error initializing SSL
* @retval 1 SSL initialized successfully
*/
-int Curl_ossl_init(void)
+static int Curl_ossl_init(void)
{
+#ifdef ENABLE_SSLKEYLOGFILE
+ char *keylog_file_name;
+#endif
+
OPENSSL_load_builtin_modules();
-#ifdef HAVE_ENGINE_LOAD_BUILTIN_ENGINES
+#ifdef USE_OPENSSL_ENGINE
ENGINE_load_builtin_engines();
#endif
@@ -743,9 +1034,11 @@ int Curl_ossl_init(void)
#define CONF_MFLAGS_DEFAULT_SECTION 0x0
#endif
+#ifndef CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG
CONF_modules_load_file(NULL, NULL,
CONF_MFLAGS_DEFAULT_SECTION|
CONF_MFLAGS_IGNORE_MISSING_FILE);
+#endif
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \
!defined(LIBRESSL_VERSION_NUMBER)
@@ -761,11 +1054,36 @@ int Curl_ossl_init(void)
OpenSSL_add_all_algorithms();
#endif
+#ifdef ENABLE_SSLKEYLOGFILE
+ if(!keylog_file_fp) {
+ keylog_file_name = curl_getenv("SSLKEYLOGFILE");
+ if(keylog_file_name) {
+ keylog_file_fp = fopen(keylog_file_name, FOPEN_APPENDTEXT);
+ if(keylog_file_fp) {
+#ifdef WIN32
+ if(setvbuf(keylog_file_fp, NULL, _IONBF, 0))
+#else
+ if(setvbuf(keylog_file_fp, NULL, _IOLBF, 4096))
+#endif
+ {
+ fclose(keylog_file_fp);
+ keylog_file_fp = NULL;
+ }
+ }
+ Curl_safefree(keylog_file_name);
+ }
+ }
+#endif
+
+ /* Initialize the extra data indexes */
+ if(ossl_get_ssl_conn_index() < 0 || ossl_get_ssl_sockindex_index() < 0)
+ return 0;
+
return 1;
}
/* Global cleanup */
-void Curl_ossl_cleanup(void)
+static void Curl_ossl_cleanup(void)
{
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \
!defined(LIBRESSL_VERSION_NUMBER)
@@ -775,7 +1093,7 @@ void Curl_ossl_cleanup(void)
/* Free ciphers and digests lists */
EVP_cleanup();
-#ifdef HAVE_ENGINE_CLEANUP
+#ifdef USE_OPENSSL_ENGINE
/* Free engine list */
ENGINE_cleanup();
#endif
@@ -797,6 +1115,13 @@ void Curl_ossl_cleanup(void)
SSL_COMP_free_compression_methods();
#endif
#endif
+
+#ifdef ENABLE_SSLKEYLOGFILE
+ if(keylog_file_fp) {
+ fclose(keylog_file_fp);
+ keylog_file_fp = NULL;
+ }
+#endif
}
/*
@@ -807,7 +1132,7 @@ void Curl_ossl_cleanup(void)
* 0 means the connection has been closed
* -1 means the connection status is unknown
*/
-int Curl_ossl_check_cxn(struct connectdata *conn)
+static int Curl_ossl_check_cxn(struct connectdata *conn)
{
/* SSL_peek takes data out of the raw recv buffer without peeking so we use
recv MSG_PEEK instead. Bug #795 */
@@ -853,9 +1178,10 @@ int Curl_ossl_check_cxn(struct connectdata *conn)
/* Selects an OpenSSL crypto engine
*/
-CURLcode Curl_ossl_set_engine(struct Curl_easy *data, const char *engine)
+static CURLcode Curl_ossl_set_engine(struct Curl_easy *data,
+ const char *engine)
{
-#if defined(USE_OPENSSL) && defined(HAVE_OPENSSL_ENGINE_H)
+#ifdef USE_OPENSSL_ENGINE
ENGINE *e;
#if OPENSSL_VERSION_NUMBER >= 0x00909000L
@@ -898,9 +1224,9 @@ CURLcode Curl_ossl_set_engine(struct Curl_easy *data, const char *engine)
/* Sets engine as default for all SSL operations
*/
-CURLcode Curl_ossl_set_engine_default(struct Curl_easy *data)
+static CURLcode Curl_ossl_set_engine_default(struct Curl_easy *data)
{
-#ifdef HAVE_OPENSSL_ENGINE_H
+#ifdef USE_OPENSSL_ENGINE
if(data->state.engine) {
if(ENGINE_set_default(data->state.engine, ENGINE_METHOD_ALL) > 0) {
infof(data, "set default crypto engine '%s'\n",
@@ -920,10 +1246,10 @@ CURLcode Curl_ossl_set_engine_default(struct Curl_easy *data)
/* Return list of OpenSSL crypto engine names.
*/
-struct curl_slist *Curl_ossl_engines_list(struct Curl_easy *data)
+static struct curl_slist *Curl_ossl_engines_list(struct Curl_easy *data)
{
struct curl_slist *list = NULL;
-#if defined(USE_OPENSSL) && defined(HAVE_OPENSSL_ENGINE_H)
+#ifdef USE_OPENSSL_ENGINE
struct curl_slist *beg;
ENGINE *e;
@@ -943,23 +1269,23 @@ struct curl_slist *Curl_ossl_engines_list(struct Curl_easy *data)
static void ossl_close(struct ssl_connect_data *connssl)
{
- if(connssl->handle) {
- (void)SSL_shutdown(connssl->handle);
- SSL_set_connect_state(connssl->handle);
+ if(BACKEND->handle) {
+ (void)SSL_shutdown(BACKEND->handle);
+ SSL_set_connect_state(BACKEND->handle);
- SSL_free(connssl->handle);
- connssl->handle = NULL;
+ SSL_free(BACKEND->handle);
+ BACKEND->handle = NULL;
}
- if(connssl->ctx) {
- SSL_CTX_free(connssl->ctx);
- connssl->ctx = NULL;
+ if(BACKEND->ctx) {
+ SSL_CTX_free(BACKEND->ctx);
+ BACKEND->ctx = NULL;
}
}
/*
* This function is called when an SSL connection is closed.
*/
-void Curl_ossl_close(struct connectdata *conn, int sockindex)
+static void Curl_ossl_close(struct connectdata *conn, int sockindex)
{
ossl_close(&conn->ssl[sockindex]);
ossl_close(&conn->proxy_ssl[sockindex]);
@@ -969,7 +1295,7 @@ void Curl_ossl_close(struct connectdata *conn, int sockindex)
* 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)
+static int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
{
int retval = 0;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
@@ -980,17 +1306,19 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
ssize_t nread;
int buffsize;
int err;
- int done = 0;
+ bool done = FALSE;
+#ifndef CURL_DISABLE_FTP
/* 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(data->set.ftp_ccc == CURLFTPSSL_CCC_ACTIVE)
- (void)SSL_shutdown(connssl->handle);
+ (void)SSL_shutdown(BACKEND->handle);
+#endif
- if(connssl->handle) {
+ if(BACKEND->handle) {
buffsize = (int)sizeof(buf);
while(!done) {
int what = SOCKET_READABLE(conn->sock[sockindex],
@@ -1000,16 +1328,15 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
/* 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,
- buffsize);
- err = SSL_get_error(conn->ssl[sockindex].handle, (int)nread);
+ nread = (ssize_t)SSL_read(BACKEND->handle, buf, buffsize);
+ err = SSL_get_error(BACKEND->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;
+ done = TRUE;
break;
case SSL_ERROR_WANT_READ:
/* there's data pending, re-invoke SSL_read() */
@@ -1018,7 +1345,7 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
case SSL_ERROR_WANT_WRITE:
/* SSL wants a write. Really odd. Let's bail out. */
infof(data, "SSL_ERROR_WANT_WRITE\n");
- done = 1;
+ done = TRUE;
break;
default:
/* openssl/ssl.h says "look at error stack/return value/errno" */
@@ -1028,26 +1355,26 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
ossl_strerror(sslerror, buf, sizeof(buf)) :
SSL_ERROR_to_str(err)),
SOCKERRNO);
- done = 1;
+ done = TRUE;
break;
}
}
else if(0 == what) {
/* timeout */
failf(data, "SSL shutdown timeout");
- done = 1;
+ done = TRUE;
}
else {
/* anything that gets here is fatally bad */
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
retval = -1;
- done = 1;
+ done = TRUE;
}
} /* while()-loop for the select() */
if(data->set.verbose) {
#ifdef HAVE_SSL_GET_SHUTDOWN
- switch(SSL_get_shutdown(connssl->handle)) {
+ switch(SSL_get_shutdown(BACKEND->handle)) {
case SSL_SENT_SHUTDOWN:
infof(data, "SSL_get_shutdown() returned SSL_SENT_SHUTDOWN\n");
break;
@@ -1062,13 +1389,13 @@ int Curl_ossl_shutdown(struct connectdata *conn, int sockindex)
#endif
}
- SSL_free(connssl->handle);
- connssl->handle = NULL;
+ SSL_free(BACKEND->handle);
+ BACKEND->handle = NULL;
}
return retval;
}
-void Curl_ossl_session_free(void *ptr)
+static void Curl_ossl_session_free(void *ptr)
{
/* free the ID */
SSL_SESSION_free(ptr);
@@ -1078,9 +1405,9 @@ void Curl_ossl_session_free(void *ptr)
* This function is called when the 'data' struct is going away. Close
* down everything and free all resources!
*/
-void Curl_ossl_close_all(struct Curl_easy *data)
+static void Curl_ossl_close_all(struct Curl_easy *data)
{
-#ifdef HAVE_OPENSSL_ENGINE_H
+#ifdef USE_OPENSSL_ENGINE
if(data->state.engine) {
ENGINE_finish(data->state.engine);
ENGINE_free(data->state.engine);
@@ -1101,6 +1428,55 @@ void Curl_ossl_close_all(struct Curl_easy *data)
/* ====================================================== */
+/*
+ * Match subjectAltName against the host name. This requires a conversion
+ * in CURL_DOES_CONVERSIONS builds.
+ */
+static bool subj_alt_hostcheck(struct Curl_easy *data,
+ const char *match_pattern, const char *hostname,
+ const char *dispname)
+#ifdef CURL_DOES_CONVERSIONS
+{
+ bool res = FALSE;
+
+ /* Curl_cert_hostcheck uses host encoding, but we get ASCII from
+ OpenSSl.
+ */
+ char *match_pattern2 = strdup(match_pattern);
+
+ if(match_pattern2) {
+ if(Curl_convert_from_network(data, match_pattern2,
+ strlen(match_pattern2)) == CURLE_OK) {
+ if(Curl_cert_hostcheck(match_pattern2, hostname)) {
+ res = TRUE;
+ infof(data,
+ " subjectAltName: host \"%s\" matched cert's \"%s\"\n",
+ dispname, match_pattern2);
+ }
+ }
+ free(match_pattern2);
+ }
+ else {
+ failf(data,
+ "SSL: out of memory when allocating temporary for subjectAltName");
+ }
+ return res;
+}
+#else
+{
+#ifdef CURL_DISABLE_VERBOSE_STRINGS
+ (void)dispname;
+ (void)data;
+#endif
+ if(Curl_cert_hostcheck(match_pattern, hostname)) {
+ infof(data, " subjectAltName: host \"%s\" matched cert's \"%s\"\n",
+ dispname, match_pattern);
+ return TRUE;
+ }
+ return FALSE;
+}
+#endif
+
/* Quote from RFC2818 section 3.1 "Server Identity"
@@ -1170,7 +1546,7 @@ static CURLcode verifyhost(struct connectdata *conn, X509 *server_cert)
numalts = sk_GENERAL_NAME_num(altnames);
/* loop through all alternatives - until a dnsmatch */
- for(i=0; (i < numalts) && !dnsmatched; i++) {
+ for(i = 0; (i < numalts) && !dnsmatched; i++) {
/* get a handle to alternative name number i */
const GENERAL_NAME *check = sk_GENERAL_NAME_value(altnames, i);
@@ -1200,11 +1576,8 @@ static CURLcode verifyhost(struct connectdata *conn, X509 *server_cert)
if((altlen == strlen(altptr)) &&
/* if this isn't true, there was an embedded zero in the name
string and we cannot match it. */
- Curl_cert_hostcheck(altptr, hostname)) {
+ subj_alt_hostcheck(data, altptr, hostname, dispname)) {
dnsmatched = TRUE;
- infof(data,
- " subjectAltName: host \"%s\" matched cert's \"%s\"\n",
- dispname, altptr);
}
break;
@@ -1239,7 +1612,7 @@ static CURLcode verifyhost(struct connectdata *conn, X509 *server_cert)
else {
/* we have to look to the last occurrence of a commonName in the
distinguished one to get the most significant one. */
- int j, i=-1;
+ int j, i = -1;
/* The following is done because of a bug in 0.9.6b */
@@ -1248,14 +1621,14 @@ static CURLcode verifyhost(struct connectdata *conn, X509 *server_cert)
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;
+ 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) {
+ if(i >= 0) {
ASN1_STRING *tmp =
X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i));
@@ -1268,7 +1641,7 @@ static CURLcode verifyhost(struct connectdata *conn, X509 *server_cert)
if(ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) {
j = ASN1_STRING_length(tmp);
if(j >= 0) {
- peer_CN = OPENSSL_malloc(j+1);
+ peer_CN = OPENSSL_malloc(j + 1);
if(peer_CN) {
memcpy(peer_CN, ASN1_STRING_get0_data(tmp), j);
peer_CN[j] = '\0';
@@ -1291,7 +1664,8 @@ static CURLcode verifyhost(struct connectdata *conn, X509 *server_cert)
peer_CN = NULL;
else {
/* convert peer_CN from UTF8 */
- CURLcode rc = Curl_convert_from_utf8(data, peer_CN, strlen(peer_CN));
+ CURLcode rc = Curl_convert_from_utf8(data, (char *)peer_CN,
+ strlen((char *)peer_CN));
/* Curl_convert_from_utf8 calls failf if unsuccessful */
if(rc) {
OPENSSL_free(peer_CN);
@@ -1328,6 +1702,7 @@ static CURLcode verifystatus(struct connectdata *conn,
struct ssl_connect_data *connssl)
{
int i, ocsp_status;
+ unsigned char *status;
const unsigned char *p;
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
@@ -1337,14 +1712,14 @@ static CURLcode verifystatus(struct connectdata *conn,
X509_STORE *st = NULL;
STACK_OF(X509) *ch = NULL;
- long len = SSL_get_tlsext_status_ocsp_resp(connssl->handle, &p);
+ long len = SSL_get_tlsext_status_ocsp_resp(BACKEND->handle, &status);
- if(!p) {
+ if(!status) {
failf(data, "No OCSP response received");
result = CURLE_SSL_INVALIDCERTSTATUS;
goto end;
}
-
+ p = status;
rsp = d2i_OCSP_RESPONSE(NULL, &p, len);
if(!rsp) {
failf(data, "Invalid OCSP response");
@@ -1367,8 +1742,8 @@ static CURLcode verifystatus(struct connectdata *conn,
goto end;
}
- ch = SSL_get_peer_cert_chain(connssl->handle);
- st = SSL_CTX_get_cert_store(connssl->ctx);
+ ch = SSL_get_peer_cert_chain(BACKEND->handle);
+ st = SSL_CTX_get_cert_store(BACKEND->ctx);
#if ((OPENSSL_VERSION_NUMBER <= 0x1000201fL) /* Fixed after 1.0.2a */ || \
(defined(LIBRESSL_VERSION_NUMBER) && \
@@ -1514,6 +1889,26 @@ static const char *ssl_msg_type(int ssl_ver, int msg)
case SSL3_MT_CERTIFICATE_STATUS:
return "Certificate Status";
#endif
+#ifdef SSL3_MT_ENCRYPTED_EXTENSIONS
+ case SSL3_MT_ENCRYPTED_EXTENSIONS:
+ return "Encrypted Extensions";
+#endif
+#ifdef SSL3_MT_END_OF_EARLY_DATA
+ case SSL3_MT_END_OF_EARLY_DATA:
+ return "End of early data";
+#endif
+#ifdef SSL3_MT_KEY_UPDATE
+ case SSL3_MT_KEY_UPDATE:
+ return "Key update";
+#endif
+#ifdef SSL3_MT_NEXT_PROTO
+ case SSL3_MT_NEXT_PROTO:
+ return "Next protocol";
+#endif
+#ifdef SSL3_MT_MESSAGE_HASH
+ case SSL3_MT_MESSAGE_HASH:
+ return "Message hash";
+#endif
}
}
return "Unknown";
@@ -1548,10 +1943,7 @@ static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
void *userp)
{
struct Curl_easy *data;
- const char *msg_name, *tls_rt_name;
- char ssl_buf[1024];
char unknown[32];
- int msg_type, txt_len;
const char *verstr = NULL;
struct connectdata *conn = userp;
@@ -1593,12 +1985,24 @@ static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
case 0:
break;
default:
- snprintf(unknown, sizeof(unknown), "(%x)", ssl_ver);
+ msnprintf(unknown, sizeof(unknown), "(%x)", ssl_ver);
verstr = unknown;
break;
}
- if(ssl_ver) {
+ /* Log progress for interesting records only (like Handshake or Alert), skip
+ * all raw record headers (content_type == SSL3_RT_HEADER or ssl_ver == 0).
+ * For TLS 1.3, skip notification of the decrypted inner Content Type.
+ */
+ if(ssl_ver
+#ifdef SSL3_RT_INNER_CONTENT_TYPE
+ && content_type != SSL3_RT_INNER_CONTENT_TYPE
+#endif
+ ) {
+ const char *msg_name, *tls_rt_name;
+ char ssl_buf[1024];
+ int msg_type, txt_len;
+
/* the info given when the version is zero is not that useful for us */
ssl_ver >>= 8; /* check the upper 8 bits only below */
@@ -1612,17 +2016,29 @@ static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
else
tls_rt_name = "";
- msg_type = *(char *)buf;
- msg_name = ssl_msg_type(ssl_ver, msg_type);
+ if(content_type == SSL3_RT_CHANGE_CIPHER_SPEC) {
+ msg_type = *(char *)buf;
+ msg_name = "Change cipher spec";
+ }
+ else if(content_type == SSL3_RT_ALERT) {
+ msg_type = (((char *)buf)[0] << 8) + ((char *)buf)[1];
+ msg_name = SSL_alert_desc_string_long(msg_type);
+ }
+ else {
+ msg_type = *(char *)buf;
+ msg_name = ssl_msg_type(ssl_ver, msg_type);
+ }
- txt_len = snprintf(ssl_buf, sizeof(ssl_buf), "%s (%s), %s, %s (%d):\n",
- verstr, direction?"OUT":"IN",
- tls_rt_name, msg_name, msg_type);
- Curl_debug(data, CURLINFO_TEXT, ssl_buf, (size_t)txt_len, NULL);
+ txt_len = msnprintf(ssl_buf, sizeof(ssl_buf), "%s (%s), %s, %s (%d):\n",
+ verstr, direction?"OUT":"IN",
+ tls_rt_name, msg_name, msg_type);
+ if(0 <= txt_len && (unsigned)txt_len < sizeof(ssl_buf)) {
+ Curl_debug(data, CURLINFO_TEXT, ssl_buf, (size_t)txt_len);
+ }
}
Curl_debug(data, (direction == 1) ? CURLINFO_SSL_DATA_OUT :
- CURLINFO_SSL_DATA_IN, (char *)buf, len, NULL);
+ CURLINFO_SSL_DATA_IN, (char *)buf, len);
(void) ssl;
}
#endif
@@ -1711,6 +2127,7 @@ select_next_proto_cb(SSL *ssl,
}
#endif /* HAS_NPN */
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
static const char *
get_ssl_version_txt(SSL *ssl)
{
@@ -1737,6 +2154,7 @@ get_ssl_version_txt(SSL *ssl)
}
return "unknown";
}
+#endif
static CURLcode
set_ssl_version_min_max(long *ctx_options, struct connectdata *conn,
@@ -1750,23 +2168,21 @@ set_ssl_version_min_max(long *ctx_options, struct connectdata *conn,
long ssl_version = SSL_CONN_CONFIG(version);
long ssl_version_max = SSL_CONN_CONFIG(version_max);
- if(ssl_version_max == CURL_SSLVERSION_MAX_NONE) {
- ssl_version_max = ssl_version << 16;
- }
-
switch(ssl_version) {
case CURL_SSLVERSION_TLSv1_3:
#ifdef TLS1_3_VERSION
{
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
- SSL_CTX_set_max_proto_version(connssl->ctx, TLS1_3_VERSION);
+ SSL_CTX_set_max_proto_version(BACKEND->ctx, TLS1_3_VERSION);
*ctx_options |= SSL_OP_NO_TLSv1_2;
}
#else
(void)sockindex;
+ (void)ctx_options;
failf(data, OSSL_PACKAGE " was built without TLS 1.3 support");
return CURLE_NOT_BUILT_IN;
#endif
+ /* FALLTHROUGH */
case CURL_SSLVERSION_TLSv1_2:
#if OPENSSL_VERSION_NUMBER >= 0x1000100FL
*ctx_options |= SSL_OP_NO_TLSv1_1;
@@ -1784,8 +2200,7 @@ set_ssl_version_min_max(long *ctx_options, struct connectdata *conn,
#endif
/* FALLTHROUGH */
case CURL_SSLVERSION_TLSv1_0:
- *ctx_options |= SSL_OP_NO_SSLv2;
- *ctx_options |= SSL_OP_NO_SSLv3;
+ case CURL_SSLVERSION_TLSv1:
break;
}
@@ -1801,7 +2216,6 @@ set_ssl_version_min_max(long *ctx_options, struct connectdata *conn,
#endif
/* FALLTHROUGH */
case CURL_SSLVERSION_MAX_TLSv1_2:
- case CURL_SSLVERSION_MAX_DEFAULT:
#ifdef TLS1_3_VERSION
*ctx_options |= SSL_OP_NO_TLSv1_3;
#endif
@@ -1817,6 +2231,62 @@ set_ssl_version_min_max(long *ctx_options, struct connectdata *conn,
return CURLE_OK;
}
+/* The "new session" callback must return zero if the session can be removed
+ * or non-zero if the session has been put into the session cache.
+ */
+static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid)
+{
+ int res = 0;
+ struct connectdata *conn;
+ struct Curl_easy *data;
+ int sockindex;
+ curl_socket_t *sockindex_ptr;
+ int connectdata_idx = ossl_get_ssl_conn_index();
+ int sockindex_idx = ossl_get_ssl_sockindex_index();
+
+ if(connectdata_idx < 0 || sockindex_idx < 0)
+ return 0;
+
+ conn = (struct connectdata*) SSL_get_ex_data(ssl, connectdata_idx);
+ if(!conn)
+ return 0;
+
+ data = conn->data;
+
+ /* The sockindex has been stored as a pointer to an array element */
+ sockindex_ptr = (curl_socket_t*) SSL_get_ex_data(ssl, sockindex_idx);
+ sockindex = (int)(sockindex_ptr - conn->sock);
+
+ if(SSL_SET_OPTION(primary.sessionid)) {
+ bool incache;
+ void *old_ssl_sessionid = NULL;
+
+ Curl_ssl_sessionid_lock(conn);
+ incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL,
+ sockindex));
+ if(incache) {
+ if(old_ssl_sessionid != ssl_sessionid) {
+ infof(data, "old SSL session ID is stale, removing\n");
+ Curl_ssl_delsessionid(conn, old_ssl_sessionid);
+ incache = FALSE;
+ }
+ }
+
+ if(!incache) {
+ if(!Curl_ssl_addsessionid(conn, ssl_sessionid,
+ 0 /* unknown size */, sockindex)) {
+ /* the session has been put into the session cache */
+ res = 1;
+ }
+ else
+ failf(data, "failed to store ssl session");
+ }
+ Curl_ssl_sessionid_unlock(conn);
+ }
+
+ return res;
+}
+
static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
{
CURLcode result = CURLE_OK;
@@ -1870,8 +2340,7 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
case CURL_SSLVERSION_TLSv1_2:
case CURL_SSLVERSION_TLSv1_3:
/* it will be handled later with the context options */
-#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \
- !defined(LIBRESSL_VERSION_NUMBER)
+#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
req_method = TLS_client_method();
#else
req_method = SSLv23_client_method();
@@ -1909,25 +2378,25 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
return CURLE_SSL_CONNECT_ERROR;
}
- if(connssl->ctx)
- SSL_CTX_free(connssl->ctx);
- connssl->ctx = SSL_CTX_new(req_method);
+ if(BACKEND->ctx)
+ SSL_CTX_free(BACKEND->ctx);
+ BACKEND->ctx = SSL_CTX_new(req_method);
- if(!connssl->ctx) {
+ if(!BACKEND->ctx) {
failf(data, "SSL: couldn't create a context: %s",
ossl_strerror(ERR_peek_error(), error_buffer, sizeof(error_buffer)));
return CURLE_OUT_OF_MEMORY;
}
#ifdef SSL_MODE_RELEASE_BUFFERS
- SSL_CTX_set_mode(connssl->ctx, SSL_MODE_RELEASE_BUFFERS);
+ SSL_CTX_set_mode(BACKEND->ctx, SSL_MODE_RELEASE_BUFFERS);
#endif
#ifdef SSL_CTRL_SET_MSG_CALLBACK
if(data->set.fdebug && data->set.verbose) {
/* the SSL trace callback is only used for verbose logging */
- SSL_CTX_set_msg_callback(connssl->ctx, ssl_tls_trace);
- SSL_CTX_set_msg_callback_arg(connssl->ctx, conn);
+ SSL_CTX_set_msg_callback(BACKEND->ctx, ssl_tls_trace);
+ SSL_CTX_set_msg_callback_arg(BACKEND->ctx, conn);
}
#endif
@@ -1991,11 +2460,6 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
switch(ssl_version) {
case CURL_SSLVERSION_SSLv3:
-#ifdef USE_TLS_SRP
- if(ssl_authtype == CURL_TLSAUTH_SRP) {
- infof(data, "Set version TLSv1.x for SRP authorisation\n");
- }
-#endif
ctx_options |= SSL_OP_NO_SSLv2;
ctx_options |= SSL_OP_NO_TLSv1;
#if OPENSSL_VERSION_NUMBER >= 0x1000100FL
@@ -2009,21 +2473,20 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
case CURL_SSLVERSION_DEFAULT:
case CURL_SSLVERSION_TLSv1:
- ctx_options |= SSL_OP_NO_SSLv2;
- ctx_options |= SSL_OP_NO_SSLv3;
- break;
-
case CURL_SSLVERSION_TLSv1_0:
case CURL_SSLVERSION_TLSv1_1:
case CURL_SSLVERSION_TLSv1_2:
case CURL_SSLVERSION_TLSv1_3:
+ /* asking for any TLS version as the minimum, means no SSL versions
+ allowed */
+ ctx_options |= SSL_OP_NO_SSLv2;
+ ctx_options |= SSL_OP_NO_SSLv3;
result = set_ssl_version_min_max(&ctx_options, conn, sockindex);
if(result != CURLE_OK)
return result;
break;
case CURL_SSLVERSION_SSLv2:
-#ifndef OPENSSL_NO_SSL2
ctx_options |= SSL_OP_NO_SSLv3;
ctx_options |= SSL_OP_NO_TLSv1;
#if OPENSSL_VERSION_NUMBER >= 0x1000100FL
@@ -2034,21 +2497,17 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
#endif
#endif
break;
-#else
- failf(data, OSSL_PACKAGE " was built without SSLv2 support");
- return CURLE_NOT_BUILT_IN;
-#endif
default:
failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
return CURLE_SSL_CONNECT_ERROR;
}
- SSL_CTX_set_options(connssl->ctx, ctx_options);
+ SSL_CTX_set_options(BACKEND->ctx, ctx_options);
#ifdef HAS_NPN
if(conn->bits.tls_enable_npn)
- SSL_CTX_set_next_proto_select_cb(connssl->ctx, select_next_proto_cb, conn);
+ SSL_CTX_set_next_proto_select_cb(BACKEND->ctx, select_next_proto_cb, conn);
#endif
#ifdef HAS_ALPN
@@ -2057,7 +2516,8 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
unsigned char protocols[128];
#ifdef USE_NGHTTP2
- if(data->set.httpversion >= CURL_HTTP_VERSION_2) {
+ if(data->set.httpversion >= CURL_HTTP_VERSION_2 &&
+ (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) {
protocols[cur++] = NGHTTP2_PROTO_VERSION_ID_LEN;
memcpy(&protocols[cur], NGHTTP2_PROTO_VERSION_ID,
@@ -2075,12 +2535,12 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
/* expects length prefixed preference ordered list of protocols in wire
* format
*/
- SSL_CTX_set_alpn_protos(connssl->ctx, protocols, cur);
+ SSL_CTX_set_alpn_protos(BACKEND->ctx, protocols, cur);
}
#endif
if(ssl_cert || ssl_cert_type) {
- if(!cert_stuff(conn, connssl->ctx, ssl_cert, ssl_cert_type,
+ if(!cert_stuff(conn, BACKEND->ctx, ssl_cert, ssl_cert_type,
SSL_SET_OPTION(key), SSL_SET_OPTION(key_type),
SSL_SET_OPTION(key_passwd))) {
/* failf() is already done in cert_stuff() */
@@ -2091,11 +2551,31 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
ciphers = SSL_CONN_CONFIG(cipher_list);
if(!ciphers)
ciphers = (char *)DEFAULT_CIPHER_SELECTION;
- if(!SSL_CTX_set_cipher_list(connssl->ctx, ciphers)) {
- failf(data, "failed setting cipher list: %s", ciphers);
- return CURLE_SSL_CIPHER;
+ if(ciphers) {
+ if(!SSL_CTX_set_cipher_list(BACKEND->ctx, ciphers)) {
+ failf(data, "failed setting cipher list: %s", ciphers);
+ return CURLE_SSL_CIPHER;
+ }
+ infof(data, "Cipher selection: %s\n", ciphers);
+ }
+
+#ifdef HAVE_SSL_CTX_SET_CIPHERSUITES
+ {
+ char *ciphers13 = SSL_CONN_CONFIG(cipher_list13);
+ if(ciphers13) {
+ if(!SSL_CTX_set_ciphersuites(BACKEND->ctx, ciphers13)) {
+ failf(data, "failed setting TLS 1.3 cipher suite: %s", ciphers13);
+ return CURLE_SSL_CIPHER;
+ }
+ infof(data, "TLS 1.3 cipher selection: %s\n", ciphers13);
+ }
}
- infof(data, "Cipher selection: %s\n", ciphers);
+#endif
+
+#ifdef HAVE_SSL_CTX_SET_POST_HANDSHAKE_AUTH
+ /* OpenSSL 1.1.1 requires clients to opt-in for PHA */
+ SSL_CTX_set_post_handshake_auth(BACKEND->ctx, 1);
+#endif
#ifdef USE_TLS_SRP
if(ssl_authtype == CURL_TLSAUTH_SRP) {
@@ -2103,18 +2583,18 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
infof(data, "Using TLS-SRP username: %s\n", ssl_username);
- if(!SSL_CTX_set_srp_username(connssl->ctx, ssl_username)) {
+ if(!SSL_CTX_set_srp_username(BACKEND->ctx, ssl_username)) {
failf(data, "Unable to set SRP user name");
return CURLE_BAD_FUNCTION_ARGUMENT;
}
- if(!SSL_CTX_set_srp_password(connssl->ctx, SSL_SET_OPTION(password))) {
+ if(!SSL_CTX_set_srp_password(BACKEND->ctx, SSL_SET_OPTION(password))) {
failf(data, "failed setting SRP password");
return CURLE_BAD_FUNCTION_ARGUMENT;
}
if(!SSL_CONN_CONFIG(cipher_list)) {
infof(data, "Setting cipher list SRP\n");
- if(!SSL_CTX_set_cipher_list(connssl->ctx, "SRP")) {
+ if(!SSL_CTX_set_cipher_list(BACKEND->ctx, "SRP")) {
failf(data, "failed setting SRP cipher list");
return CURLE_SSL_CIPHER;
}
@@ -2125,7 +2605,7 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
if(ssl_cafile || 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, ssl_cafile, ssl_capath)) {
+ if(!SSL_CTX_load_verify_locations(BACKEND->ctx, ssl_cafile, ssl_capath)) {
if(verifypeer) {
/* Fail if we insist on successfully verifying the server. */
failf(data, "error setting certificate verify locations:\n"
@@ -2151,16 +2631,16 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
}
#ifdef CURL_CA_FALLBACK
else if(verifypeer) {
- /* verfying the peer without any CA certificates won't
+ /* verifying the peer without any CA certificates won't
work so use openssl's built in default as fallback */
- SSL_CTX_set_default_verify_paths(connssl->ctx);
+ SSL_CTX_set_default_verify_paths(BACKEND->ctx);
}
#endif
if(ssl_crlfile) {
/* tell SSL where to find CRL file that is used to check certificate
* revocation */
- lookup=X509_STORE_add_lookup(SSL_CTX_get_cert_store(connssl->ctx),
+ lookup = X509_STORE_add_lookup(SSL_CTX_get_cert_store(BACKEND->ctx),
X509_LOOKUP_file());
if(!lookup ||
(!X509_load_crl_file(lookup, ssl_crlfile, X509_FILETYPE_PEM)) ) {
@@ -2169,7 +2649,7 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
}
/* Everything is fine. */
infof(data, "successfully load CRL file:\n");
- X509_STORE_set_flags(SSL_CTX_get_cert_store(connssl->ctx),
+ X509_STORE_set_flags(SSL_CTX_get_cert_store(BACKEND->ctx),
X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL);
infof(data, " CRLfile: %s\n", ssl_crlfile);
@@ -2184,7 +2664,7 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
*/
#if defined(X509_V_FLAG_TRUSTED_FIRST) && !defined(X509_V_FLAG_NO_ALT_CHAINS)
if(verifypeer) {
- X509_STORE_set_flags(SSL_CTX_get_cert_store(connssl->ctx),
+ X509_STORE_set_flags(SSL_CTX_get_cert_store(BACKEND->ctx),
X509_V_FLAG_TRUSTED_FIRST);
}
#endif
@@ -2193,12 +2673,27 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
* 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,
+ SSL_CTX_set_verify(BACKEND->ctx,
verifypeer ? SSL_VERIFY_PEER : SSL_VERIFY_NONE, NULL);
+ /* Enable logging of secrets to the file specified in env SSLKEYLOGFILE. */
+#if defined(ENABLE_SSLKEYLOGFILE) && defined(HAVE_KEYLOG_CALLBACK)
+ if(keylog_file_fp) {
+ SSL_CTX_set_keylog_callback(BACKEND->ctx, ossl_keylog_callback);
+ }
+#endif
+
+ /* Enable the session cache because it's a prerequisite for the "new session"
+ * callback. Use the "external storage" mode to avoid that OpenSSL creates
+ * an internal session cache.
+ */
+ SSL_CTX_set_session_cache_mode(BACKEND->ctx,
+ SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL);
+ SSL_CTX_sess_set_new_cb(BACKEND->ctx, ossl_new_session_cb);
+
/* give application a chance to interfere with SSL set up. */
if(data->set.ssl.fsslctx) {
- result = (*data->set.ssl.fsslctx)(data, connssl->ctx,
+ result = (*data->set.ssl.fsslctx)(data, BACKEND->ctx,
data->set.ssl.fsslctxp);
if(result) {
failf(data, "error signaled by ssl ctx callback");
@@ -2207,10 +2702,10 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
}
/* Lets make an SSL structure */
- if(connssl->handle)
- SSL_free(connssl->handle);
- connssl->handle = SSL_new(connssl->ctx);
- if(!connssl->handle) {
+ if(BACKEND->handle)
+ SSL_free(BACKEND->handle);
+ BACKEND->handle = SSL_new(BACKEND->ctx);
+ if(!BACKEND->handle) {
failf(data, "SSL: couldn't create a context (handle)!");
return CURLE_OUT_OF_MEMORY;
}
@@ -2218,19 +2713,23 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_TLSEXT) && \
!defined(OPENSSL_NO_OCSP)
if(SSL_CONN_CONFIG(verifystatus))
- SSL_set_tlsext_status_type(connssl->handle, TLSEXT_STATUSTYPE_ocsp);
+ SSL_set_tlsext_status_type(BACKEND->handle, TLSEXT_STATUSTYPE_ocsp);
+#endif
+
+#if defined(OPENSSL_IS_BORINGSSL) && defined(ALLOW_RENEG)
+ SSL_set_renegotiate_mode(BACKEND->handle, ssl_renegotiate_freely);
#endif
- SSL_set_connect_state(connssl->handle);
+ SSL_set_connect_state(BACKEND->handle);
- connssl->server_cert = 0x0;
+ BACKEND->server_cert = 0x0;
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
if((0 == Curl_inet_pton(AF_INET, hostname, &addr)) &&
#ifdef ENABLE_IPV6
(0 == Curl_inet_pton(AF_INET6, hostname, &addr)) &&
#endif
sni &&
- !SSL_set_tlsext_host_name(connssl->handle, hostname))
+ !SSL_set_tlsext_host_name(BACKEND->handle, hostname))
infof(data, "WARNING: failed to configure server name indication (SNI) "
"TLS extension\n");
#endif
@@ -2238,11 +2737,20 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
/* Check if there's a cached ID we can/should use here! */
if(SSL_SET_OPTION(primary.sessionid)) {
void *ssl_sessionid = NULL;
+ int connectdata_idx = ossl_get_ssl_conn_index();
+ int sockindex_idx = ossl_get_ssl_sockindex_index();
+
+ if(connectdata_idx >= 0 && sockindex_idx >= 0) {
+ /* Store the data needed for the "new session" callback.
+ * The sockindex is stored as a pointer to an array element. */
+ SSL_set_ex_data(BACKEND->handle, connectdata_idx, conn);
+ SSL_set_ex_data(BACKEND->handle, sockindex_idx, conn->sock + sockindex);
+ }
Curl_ssl_sessionid_lock(conn);
if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) {
/* we got a session id, use it! */
- if(!SSL_set_session(connssl->handle, ssl_sessionid)) {
+ if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) {
Curl_ssl_sessionid_unlock(conn);
failf(data, "SSL: SSL_set_session failed: %s",
ossl_strerror(ERR_get_error(), error_buffer,
@@ -2257,13 +2765,14 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
if(conn->proxy_ssl[sockindex].use) {
BIO *const bio = BIO_new(BIO_f_ssl());
+ SSL *handle = conn->proxy_ssl[sockindex].backend->handle;
DEBUGASSERT(ssl_connection_complete == conn->proxy_ssl[sockindex].state);
- DEBUGASSERT(conn->proxy_ssl[sockindex].handle != NULL);
+ DEBUGASSERT(handle != NULL);
DEBUGASSERT(bio != NULL);
- BIO_set_ssl(bio, conn->proxy_ssl[sockindex].handle, FALSE);
- SSL_set_bio(connssl->handle, bio, bio);
+ BIO_set_ssl(bio, handle, FALSE);
+ SSL_set_bio(BACKEND->handle, bio, bio);
}
- else if(!SSL_set_fd(connssl->handle, (int)sockfd)) {
+ else if(!SSL_set_fd(BACKEND->handle, (int)sockfd)) {
/* pass the raw socket into the SSL layers */
failf(data, "SSL: SSL_set_fd failed: %s",
ossl_strerror(ERR_get_error(), error_buffer, sizeof(error_buffer)));
@@ -2288,13 +2797,18 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
ERR_clear_error();
- err = SSL_connect(connssl->handle);
+ err = SSL_connect(BACKEND->handle);
+ /* If keylogging is enabled but the keylog callback is not supported then log
+ secrets here, immediately after SSL_connect by using tap_ssl_key. */
+#if defined(ENABLE_SSLKEYLOGFILE) && !defined(HAVE_KEYLOG_CALLBACK)
+ tap_ssl_key(BACKEND->handle, &BACKEND->tap_state);
+#endif
/* 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);
+ int detail = SSL_get_error(BACKEND->handle, err);
if(SSL_ERROR_WANT_READ == detail) {
connssl->connecting_state = ssl_connect_2_reading;
@@ -2304,6 +2818,12 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
connssl->connecting_state = ssl_connect_2_writing;
return CURLE_OK;
}
+#ifdef SSL_ERROR_WANT_ASYNC
+ if(SSL_ERROR_WANT_ASYNC == detail) {
+ connssl->connecting_state = ssl_connect_2;
+ return CURLE_OK;
+ }
+#endif
else {
/* untreated error */
unsigned long errdetail;
@@ -2326,14 +2846,14 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
if((lib == ERR_LIB_SSL) &&
(reason == SSL_R_CERTIFICATE_VERIFY_FAILED)) {
- result = CURLE_SSL_CACERT;
+ result = CURLE_PEER_FAILED_VERIFICATION;
- lerr = SSL_get_verify_result(connssl->handle);
+ lerr = SSL_get_verify_result(BACKEND->handle);
if(lerr != X509_V_OK) {
*certverifyresult = lerr;
- snprintf(error_buffer, sizeof(error_buffer),
- "SSL certificate problem: %s",
- X509_verify_cert_error_string(lerr));
+ msnprintf(error_buffer, sizeof(error_buffer),
+ "SSL certificate problem: %s",
+ X509_verify_cert_error_string(lerr));
}
else
/* strcpy() is fine here as long as the string fits within
@@ -2372,8 +2892,8 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
/* Informational message */
infof(data, "SSL connection using %s / %s\n",
- get_ssl_version_txt(connssl->handle),
- SSL_get_cipher(connssl->handle));
+ get_ssl_version_txt(BACKEND->handle),
+ SSL_get_cipher(BACKEND->handle));
#ifdef HAS_ALPN
/* Sets data and len to negotiated protocol, len is 0 if no protocol was
@@ -2382,7 +2902,7 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
if(conn->bits.tls_enable_alpn) {
const unsigned char *neg_protocol;
unsigned int len;
- SSL_get0_alpn_selected(connssl->handle, &neg_protocol, &len);
+ SSL_get0_alpn_selected(BACKEND->handle, &neg_protocol, &len);
if(len != 0) {
infof(data, "ALPN, server accepted to use %.*s\n", len, neg_protocol);
@@ -2400,6 +2920,9 @@ static CURLcode ossl_connect_step2(struct connectdata *conn, int sockindex)
}
else
infof(data, "ALPN, server did not agree to a protocol\n");
+
+ Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
+ BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
}
#endif
@@ -2427,7 +2950,7 @@ static int asn1_object_dump(ASN1_OBJECT *a, char *buf, size_t len)
do { \
long info_len = BIO_get_mem_data(mem, &ptr); \
Curl_ssl_push_certinfo_len(data, _num, _label, ptr, info_len); \
- if(1!=BIO_reset(mem)) \
+ if(1 != BIO_reset(mem)) \
break; \
} WHILE_FALSE
@@ -2444,7 +2967,7 @@ static void pubkey_show(struct Curl_easy *data,
char *ptr;
char namebuf[32];
- snprintf(namebuf, sizeof(namebuf), "%s(%s)", type, name);
+ msnprintf(namebuf, sizeof(namebuf), "%s(%s)", type, name);
if(bn)
BN_print(mem, bn);
@@ -2475,12 +2998,12 @@ static int X509V3_ext(struct Curl_easy *data,
/* no extensions, bail out */
return 1;
- for(i=0; i < (int)sk_X509_EXTENSION_num(exts); i++) {
+ for(i = 0; i < (int)sk_X509_EXTENSION_num(exts); i++) {
ASN1_OBJECT *obj;
X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
BUF_MEM *biomem;
char buf[512];
- char *ptr=buf;
+ char *ptr = buf;
char namebuf[128];
BIO *bio_out = BIO_new(BIO_s_mem());
@@ -2497,16 +3020,16 @@ static int X509V3_ext(struct Curl_easy *data,
BIO_get_mem_ptr(bio_out, &biomem);
for(j = 0; j < (size_t)biomem->length; j++) {
- const char *sep="";
+ const char *sep = "";
if(biomem->data[j] == '\n') {
- sep=", ";
+ sep = ", ";
j++; /* skip the newline */
};
while((j<(size_t)biomem->length) && (biomem->data[j] == ' '))
j++;
if(j<(size_t)biomem->length)
- ptr+=snprintf(ptr, sizeof(buf)-(ptr-buf), "%s%c", sep,
- biomem->data[j]);
+ ptr += msnprintf(ptr, sizeof(buf)-(ptr-buf), "%s%c", sep,
+ biomem->data[j]);
}
Curl_ssl_push_certinfo(data, certnum, namebuf, buf);
@@ -2528,7 +3051,7 @@ static CURLcode get_cert_chain(struct connectdata *conn,
int numcerts;
BIO *mem;
- sk = SSL_get_peer_cert_chain(connssl->handle);
+ sk = SSL_get_peer_cert_chain(BACKEND->handle);
if(!sk) {
return CURLE_OUT_OF_MEMORY;
}
@@ -2545,10 +3068,10 @@ static CURLcode get_cert_chain(struct connectdata *conn,
for(i = 0; i < numcerts; i++) {
ASN1_INTEGER *num;
X509 *x = sk_X509_value(sk, i);
- EVP_PKEY *pubkey=NULL;
+ EVP_PKEY *pubkey = NULL;
int j;
char *ptr;
- CONST_ASN1_BIT_STRING ASN1_BIT_STRING *psig = NULL;
+ const ASN1_BIT_STRING *psig = NULL;
X509_NAME_print_ex(mem, X509_get_subject_name(x), 0, XN_FLAG_ONELINE);
push_certinfo("Subject", i);
@@ -2572,7 +3095,7 @@ static CURLcode get_cert_chain(struct connectdata *conn,
ASN1_STRING *a = ASN1_STRING_new();
if(a) {
X509_get0_signature(&psig, &palg, x);
- X509_signature_print(mem, palg, a);
+ X509_signature_print(mem, ARG2_X509_signature_print palg, a);
ASN1_STRING_free(a);
if(palg) {
@@ -2706,11 +3229,6 @@ static CURLcode get_cert_chain(struct connectdata *conn,
#endif
break;
}
-#if 0
- case EVP_PKEY_EC: /* symbol not present in OpenSSL 0.9.6 */
- /* left TODO */
- break;
-#endif
}
EVP_PKEY_free(pubkey);
}
@@ -2804,10 +3322,11 @@ static CURLcode servercert(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
int rc;
- long lerr, len;
+ long lerr;
struct Curl_easy *data = conn->data;
X509 *issuer;
- FILE *fp;
+ BIO *fp = NULL;
+ char error_buffer[256]="";
char buffer[2048];
const char *ptr;
long * const certverifyresult = SSL_IS_PROXY() ?
@@ -2818,8 +3337,8 @@ static CURLcode servercert(struct connectdata *conn,
/* we've been asked to gather certificate info! */
(void)get_cert_chain(conn, connssl);
- connssl->server_cert = SSL_get_peer_certificate(connssl->handle);
- if(!connssl->server_cert) {
+ BACKEND->server_cert = SSL_get_peer_certificate(BACKEND->handle);
+ if(!BACKEND->server_cert) {
BIO_free(mem);
if(!strict)
return CURLE_OK;
@@ -2830,37 +3349,42 @@ static CURLcode servercert(struct connectdata *conn,
infof(data, "%s certificate:\n", SSL_IS_PROXY() ? "Proxy" : "Server");
- rc = x509_name_oneline(X509_get_subject_name(connssl->server_cert),
+ rc = x509_name_oneline(X509_get_subject_name(BACKEND->server_cert),
buffer, sizeof(buffer));
infof(data, " subject: %s\n", rc?"[NONE]":buffer);
- ASN1_TIME_print(mem, X509_get0_notBefore(connssl->server_cert));
- len = BIO_get_mem_data(mem, (char **) &ptr);
- infof(data, " start date: %.*s\n", len, ptr);
- rc = BIO_reset(mem);
+#ifndef CURL_DISABLE_VERBOSE_STRINGS
+ {
+ long len;
+ ASN1_TIME_print(mem, X509_get0_notBefore(BACKEND->server_cert));
+ len = BIO_get_mem_data(mem, (char **) &ptr);
+ infof(data, " start date: %.*s\n", len, ptr);
+ (void)BIO_reset(mem);
- ASN1_TIME_print(mem, X509_get0_notAfter(connssl->server_cert));
- len = BIO_get_mem_data(mem, (char **) &ptr);
- infof(data, " expire date: %.*s\n", len, ptr);
- rc = BIO_reset(mem);
+ ASN1_TIME_print(mem, X509_get0_notAfter(BACKEND->server_cert));
+ len = BIO_get_mem_data(mem, (char **) &ptr);
+ infof(data, " expire date: %.*s\n", len, ptr);
+ (void)BIO_reset(mem);
+ }
+#endif
BIO_free(mem);
if(SSL_CONN_CONFIG(verifyhost)) {
- result = verifyhost(conn, connssl->server_cert);
+ result = verifyhost(conn, BACKEND->server_cert);
if(result) {
- X509_free(connssl->server_cert);
- connssl->server_cert = NULL;
+ X509_free(BACKEND->server_cert);
+ BACKEND->server_cert = NULL;
return result;
}
}
- rc = x509_name_oneline(X509_get_issuer_name(connssl->server_cert),
+ rc = x509_name_oneline(X509_get_issuer_name(BACKEND->server_cert),
buffer, sizeof(buffer));
if(rc) {
if(strict)
failf(data, "SSL: couldn't get X509-issuer name!");
- result = CURLE_SSL_CONNECT_ERROR;
+ result = CURLE_PEER_FAILED_VERIFICATION;
}
else {
infof(data, " issuer: %s\n", buffer);
@@ -2870,45 +3394,58 @@ static CURLcode servercert(struct connectdata *conn,
/* e.g. match issuer name with provided issuer certificate */
if(SSL_SET_OPTION(issuercert)) {
- fp = fopen(SSL_SET_OPTION(issuercert), FOPEN_READTEXT);
- if(!fp) {
+ fp = BIO_new(BIO_s_file());
+ if(fp == NULL) {
+ failf(data,
+ "BIO_new return NULL, " OSSL_PACKAGE
+ " error %s",
+ ossl_strerror(ERR_get_error(), error_buffer,
+ sizeof(error_buffer)) );
+ X509_free(BACKEND->server_cert);
+ BACKEND->server_cert = NULL;
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ if(BIO_read_filename(fp, SSL_SET_OPTION(issuercert)) <= 0) {
if(strict)
failf(data, "SSL: Unable to open issuer cert (%s)",
SSL_SET_OPTION(issuercert));
- X509_free(connssl->server_cert);
- connssl->server_cert = NULL;
+ BIO_free(fp);
+ X509_free(BACKEND->server_cert);
+ BACKEND->server_cert = NULL;
return CURLE_SSL_ISSUER_ERROR;
}
- issuer = PEM_read_X509(fp, NULL, ZERO_NULL, NULL);
+ issuer = PEM_read_bio_X509(fp, NULL, ZERO_NULL, NULL);
if(!issuer) {
if(strict)
failf(data, "SSL: Unable to read issuer cert (%s)",
SSL_SET_OPTION(issuercert));
- X509_free(connssl->server_cert);
+ BIO_free(fp);
X509_free(issuer);
- fclose(fp);
+ X509_free(BACKEND->server_cert);
+ BACKEND->server_cert = NULL;
return CURLE_SSL_ISSUER_ERROR;
}
- fclose(fp);
-
- if(X509_check_issued(issuer, connssl->server_cert) != X509_V_OK) {
+ if(X509_check_issued(issuer, BACKEND->server_cert) != X509_V_OK) {
if(strict)
failf(data, "SSL: Certificate issuer check failed (%s)",
SSL_SET_OPTION(issuercert));
- X509_free(connssl->server_cert);
+ BIO_free(fp);
X509_free(issuer);
- connssl->server_cert = NULL;
+ X509_free(BACKEND->server_cert);
+ BACKEND->server_cert = NULL;
return CURLE_SSL_ISSUER_ERROR;
}
infof(data, " SSL certificate issuer check ok (%s)\n",
SSL_SET_OPTION(issuercert));
+ BIO_free(fp);
X509_free(issuer);
}
- lerr = *certverifyresult = SSL_get_verify_result(connssl->handle);
+ lerr = *certverifyresult = SSL_get_verify_result(BACKEND->handle);
if(*certverifyresult != X509_V_OK) {
if(SSL_CONN_CONFIG(verifypeer)) {
@@ -2933,8 +3470,8 @@ static CURLcode servercert(struct connectdata *conn,
if(SSL_CONN_CONFIG(verifystatus)) {
result = verifystatus(conn, connssl);
if(result) {
- X509_free(connssl->server_cert);
- connssl->server_cert = NULL;
+ X509_free(BACKEND->server_cert);
+ BACKEND->server_cert = NULL;
return result;
}
}
@@ -2947,13 +3484,13 @@ static CURLcode servercert(struct connectdata *conn,
ptr = SSL_IS_PROXY() ? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG];
if(!result && ptr) {
- result = pkp_pin_peer_pubkey(data, connssl->server_cert, ptr);
+ result = pkp_pin_peer_pubkey(data, BACKEND->server_cert, ptr);
if(result)
failf(data, "SSL: public key does not match pinned public key!");
}
- X509_free(connssl->server_cert);
- connssl->server_cert = NULL;
+ X509_free(BACKEND->server_cert);
+ BACKEND->server_cert = NULL;
connssl->connecting_state = ssl_connect_done;
return result;
@@ -2962,52 +3499,10 @@ static CURLcode servercert(struct connectdata *conn,
static CURLcode ossl_connect_step3(struct connectdata *conn, int sockindex)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
- if(SSL_SET_OPTION(primary.sessionid)) {
- bool incache;
- SSL_SESSION *our_ssl_sessionid;
- void *old_ssl_sessionid = NULL;
-
- 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. */
-
- Curl_ssl_sessionid_lock(conn);
- incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL,
- sockindex));
- if(incache) {
- if(old_ssl_sessionid != our_ssl_sessionid) {
- infof(data, "old SSL session ID is stale, removing\n");
- Curl_ssl_delsessionid(conn, old_ssl_sessionid);
- incache = FALSE;
- }
- }
-
- if(!incache) {
- result = Curl_ssl_addsessionid(conn, our_ssl_sessionid,
- 0 /* unknown size */, sockindex);
- if(result) {
- Curl_ssl_sessionid_unlock(conn);
- failf(data, "failed to store ssl session");
- return result;
- }
- }
- else {
- /* Session was incache, so refcount already incremented earlier.
- * Avoid further increments with each SSL_get1_session() call.
- * This does not free the session as refcount remains > 0
- */
- SSL_SESSION_free(our_ssl_sessionid);
- }
- Curl_ssl_sessionid_unlock(conn);
- }
-
/*
* We check certificates to authenticate the server; otherwise we risk
* man-in-the-middle attack; NEVERTHELESS, if we're told explicitly not to
@@ -3077,9 +3572,9 @@ static CURLcode ossl_connect_common(struct connectdata *conn,
if(connssl->connecting_state == ssl_connect_2_reading ||
connssl->connecting_state == ssl_connect_2_writing) {
- curl_socket_t writefd = ssl_connect_2_writing==
+ curl_socket_t writefd = ssl_connect_2_writing ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
- curl_socket_t readfd = ssl_connect_2_reading==
+ curl_socket_t readfd = ssl_connect_2_reading ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
@@ -3137,14 +3632,14 @@ static CURLcode ossl_connect_common(struct connectdata *conn,
return CURLE_OK;
}
-CURLcode Curl_ossl_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done)
+static CURLcode Curl_ossl_connect_nonblocking(struct connectdata *conn,
+ int sockindex,
+ bool *done)
{
return ossl_connect_common(conn, sockindex, TRUE, done);
}
-CURLcode Curl_ossl_connect(struct connectdata *conn, int sockindex)
+static CURLcode Curl_ossl_connect(struct connectdata *conn, int sockindex)
{
CURLcode result;
bool done = FALSE;
@@ -3158,17 +3653,23 @@ CURLcode Curl_ossl_connect(struct connectdata *conn, int sockindex)
return CURLE_OK;
}
-bool Curl_ossl_data_pending(const struct connectdata *conn, int connindex)
+static bool Curl_ossl_data_pending(const struct connectdata *conn,
+ int connindex)
{
- if(conn->ssl[connindex].handle)
- /* SSL is in use */
- return (0 != SSL_pending(conn->ssl[connindex].handle) ||
- (conn->proxy_ssl[connindex].handle &&
- 0 != SSL_pending(conn->proxy_ssl[connindex].handle))) ?
- TRUE : FALSE;
+ const struct ssl_connect_data *connssl = &conn->ssl[connindex];
+ const struct ssl_connect_data *proxyssl = &conn->proxy_ssl[connindex];
+
+ if(connssl->backend->handle && SSL_pending(connssl->backend->handle))
+ return TRUE;
+
+ if(proxyssl->backend->handle && SSL_pending(proxyssl->backend->handle))
+ return TRUE;
+
return FALSE;
}
+static size_t Curl_ossl_version(char *buffer, size_t size);
+
static ssize_t ossl_send(struct connectdata *conn,
int sockindex,
const void *mem,
@@ -3182,14 +3683,15 @@ static ssize_t ossl_send(struct connectdata *conn,
unsigned long sslerror;
int memlen;
int rc;
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
ERR_clear_error();
memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
- rc = SSL_write(conn->ssl[sockindex].handle, mem, memlen);
+ rc = SSL_write(BACKEND->handle, mem, memlen);
if(rc <= 0) {
- err = SSL_get_error(conn->ssl[sockindex].handle, rc);
+ err = SSL_get_error(BACKEND->handle, rc);
switch(err) {
case SSL_ERROR_WANT_READ:
@@ -3243,18 +3745,22 @@ static ssize_t ossl_recv(struct connectdata *conn, /* connection data */
unsigned long sslerror;
ssize_t nread;
int buffsize;
+ struct ssl_connect_data *connssl = &conn->ssl[num];
ERR_clear_error();
buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
- nread = (ssize_t)SSL_read(conn->ssl[num].handle, buf, buffsize);
+ nread = (ssize_t)SSL_read(BACKEND->handle, buf, buffsize);
if(nread <= 0) {
/* failed SSL_read */
- int err = SSL_get_error(conn->ssl[num].handle, (int)nread);
+ int err = SSL_get_error(BACKEND->handle, (int)nread);
switch(err) {
case SSL_ERROR_NONE: /* this is not an error */
+ break;
case SSL_ERROR_ZERO_RETURN: /* no more data */
+ /* close_notify alert */
+ connclose(conn, "TLS close_notify");
break;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
@@ -3282,18 +3788,23 @@ static ssize_t ossl_recv(struct connectdata *conn, /* connection data */
return nread;
}
-size_t Curl_ossl_version(char *buffer, size_t size)
+static size_t Curl_ossl_version(char *buffer, size_t size)
{
#ifdef OPENSSL_IS_BORINGSSL
- return snprintf(buffer, size, OSSL_PACKAGE);
-#else /* OPENSSL_IS_BORINGSSL */
+ return msnprintf(buffer, size, OSSL_PACKAGE);
+#elif defined(HAVE_OPENSSL_VERSION) && defined(OPENSSL_VERSION_STRING)
+ return msnprintf(buffer, size, "%s/%s",
+ OSSL_PACKAGE, OpenSSL_version(OPENSSL_VERSION_STRING));
+#else
+ /* not BoringSSL and not using OpenSSL_version */
+
char sub[3];
unsigned long ssleay_value;
sub[2]='\0';
sub[1]='\0';
- ssleay_value=OpenSSL_version_num();
+ ssleay_value = OpenSSL_version_num();
if(ssleay_value < 0x906000) {
- ssleay_value=SSLEAY_VERSION_NUMBER;
+ ssleay_value = SSLEAY_VERSION_NUMBER;
sub[0]='\0';
}
else {
@@ -3312,18 +3823,22 @@ size_t Curl_ossl_version(char *buffer, size_t size)
sub[0]='\0';
}
- return snprintf(buffer, size, "%s/%lx.%lx.%lx%s",
- OSSL_PACKAGE,
- (ssleay_value>>28)&0xf,
- (ssleay_value>>20)&0xff,
- (ssleay_value>>12)&0xff,
- sub);
+ return msnprintf(buffer, size, "%s/%lx.%lx.%lx%s"
+#ifdef OPENSSL_FIPS
+ "-fips"
+#endif
+ ,
+ OSSL_PACKAGE,
+ (ssleay_value>>28)&0xf,
+ (ssleay_value>>20)&0xff,
+ (ssleay_value>>12)&0xff,
+ sub);
#endif /* OPENSSL_IS_BORINGSSL */
}
/* can be called with data == NULL */
-CURLcode Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
- size_t length)
+static CURLcode Curl_ossl_random(struct Curl_easy *data,
+ unsigned char *entropy, size_t length)
{
int rc;
if(data) {
@@ -3339,33 +3854,43 @@ CURLcode Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
return (rc == 1 ? CURLE_OK : CURLE_FAILED_INIT);
}
-void Curl_ossl_md5sum(unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *md5sum /* output */,
- size_t unused)
+static CURLcode Curl_ossl_md5sum(unsigned char *tmp, /* input */
+ size_t tmplen,
+ unsigned char *md5sum /* output */,
+ size_t unused)
{
- MD5_CTX MD5pw;
- (void)unused;
- MD5_Init(&MD5pw);
- MD5_Update(&MD5pw, tmp, tmplen);
- MD5_Final(md5sum, &MD5pw);
+ EVP_MD_CTX *mdctx;
+ unsigned int len = 0;
+ (void) unused;
+
+ mdctx = EVP_MD_CTX_create();
+ EVP_DigestInit_ex(mdctx, EVP_md5(), NULL);
+ EVP_DigestUpdate(mdctx, tmp, tmplen);
+ EVP_DigestFinal_ex(mdctx, md5sum, &len);
+ EVP_MD_CTX_destroy(mdctx);
+ return CURLE_OK;
}
#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
-void Curl_ossl_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum /* output */,
- size_t unused)
+static CURLcode Curl_ossl_sha256sum(const unsigned char *tmp, /* input */
+ size_t tmplen,
+ unsigned char *sha256sum /* output */,
+ size_t unused)
{
- SHA256_CTX SHA256pw;
- (void)unused;
- SHA256_Init(&SHA256pw);
- SHA256_Update(&SHA256pw, tmp, tmplen);
- SHA256_Final(sha256sum, &SHA256pw);
+ EVP_MD_CTX *mdctx;
+ unsigned int len = 0;
+ (void) unused;
+
+ mdctx = EVP_MD_CTX_create();
+ EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL);
+ EVP_DigestUpdate(mdctx, tmp, tmplen);
+ EVP_DigestFinal_ex(mdctx, sha256sum, &len);
+ EVP_MD_CTX_destroy(mdctx);
+ return CURLE_OK;
}
#endif
-bool Curl_ossl_cert_status_request(void)
+static bool Curl_ossl_cert_status_request(void)
{
#if (OPENSSL_VERSION_NUMBER >= 0x0090808fL) && !defined(OPENSSL_NO_TLSEXT) && \
!defined(OPENSSL_NO_OCSP)
@@ -3374,4 +3899,53 @@ bool Curl_ossl_cert_status_request(void)
return FALSE;
#endif
}
+
+static void *Curl_ossl_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info)
+{
+ /* Legacy: CURLINFO_TLS_SESSION must return an SSL_CTX pointer. */
+ return info == CURLINFO_TLS_SESSION ?
+ (void *)BACKEND->ctx : (void *)BACKEND->handle;
+}
+
+const struct Curl_ssl Curl_ssl_openssl = {
+ { CURLSSLBACKEND_OPENSSL, "openssl" }, /* info */
+
+ SSLSUPP_CA_PATH |
+ SSLSUPP_CERTINFO |
+ SSLSUPP_PINNEDPUBKEY |
+ SSLSUPP_SSL_CTX |
+#ifdef HAVE_SSL_CTX_SET_CIPHERSUITES
+ SSLSUPP_TLS13_CIPHERSUITES |
+#endif
+ SSLSUPP_HTTPS_PROXY,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_ossl_init, /* init */
+ Curl_ossl_cleanup, /* cleanup */
+ Curl_ossl_version, /* version */
+ Curl_ossl_check_cxn, /* check_cxn */
+ Curl_ossl_shutdown, /* shutdown */
+ Curl_ossl_data_pending, /* data_pending */
+ Curl_ossl_random, /* random */
+ Curl_ossl_cert_status_request, /* cert_status_request */
+ Curl_ossl_connect, /* connect */
+ Curl_ossl_connect_nonblocking, /* connect_nonblocking */
+ Curl_ossl_get_internals, /* get_internals */
+ Curl_ossl_close, /* close_one */
+ Curl_ossl_close_all, /* close_all */
+ Curl_ossl_session_free, /* session_free */
+ Curl_ossl_set_engine, /* set_engine */
+ Curl_ossl_set_engine_default, /* set_engine_default */
+ Curl_ossl_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_ossl_md5sum, /* md5sum */
+#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
+ Curl_ossl_sha256sum /* sha256sum */
+#else
+ NULL /* sha256sum */
+#endif
+};
+
#endif /* USE_OPENSSL */
diff --git a/Utilities/cmcurl/lib/vtls/openssl.h b/Utilities/cmcurl/lib/vtls/openssl.h
index b9648d514..114dc4bae 100644
--- a/Utilities/cmcurl/lib/vtls/openssl.h
+++ b/Utilities/cmcurl/lib/vtls/openssl.h
@@ -31,96 +31,7 @@
#include "urldata.h"
-CURLcode Curl_ossl_connect(struct connectdata *conn, int sockindex);
-CURLcode Curl_ossl_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done);
-
-/* close a SSL connection */
-void Curl_ossl_close(struct connectdata *conn, int sockindex);
-
-/* tell OpenSSL to close down all open information regarding connections (and
- thus session ID caching etc) */
-void Curl_ossl_close_all(struct Curl_easy *data);
-
-/* Sets an OpenSSL engine */
-CURLcode Curl_ossl_set_engine(struct Curl_easy *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 Curl_easy *data);
-
-/* Build list of OpenSSL engines */
-struct curl_slist *Curl_ossl_engines_list(struct Curl_easy *data);
-
-int Curl_ossl_init(void);
-void Curl_ossl_cleanup(void);
-
-size_t Curl_ossl_version(char *buffer, size_t size);
-int Curl_ossl_check_cxn(struct connectdata *cxn);
-int Curl_ossl_shutdown(struct connectdata *conn, int sockindex);
-bool Curl_ossl_data_pending(const struct connectdata *conn,
- int connindex);
-
-/* return 0 if a find random is filled in */
-CURLcode Curl_ossl_random(struct Curl_easy *data, unsigned char *entropy,
- size_t length);
-void Curl_ossl_md5sum(unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *md5sum /* output */,
- size_t unused);
-void Curl_ossl_sha256sum(const unsigned char *tmp, /* input */
- size_t tmplen,
- unsigned char *sha256sum /* output */,
- size_t unused);
-
-bool Curl_ossl_cert_status_request(void);
-
-/* Support HTTPS-proxy */
-#define HTTPS_PROXY_SUPPORT 1
-
-/* Set the API backend definition to OpenSSL */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_OPENSSL
-
-/* this backend supports the CAPATH option */
-#define have_curlssl_ca_path 1
-
-/* this backend supports CURLOPT_CERTINFO */
-#define have_curlssl_certinfo 1
-
-/* this backend supports CURLOPT_SSL_CTX_* */
-#define have_curlssl_ssl_ctx 1
-
-/* this backend supports CURLOPT_PINNEDPUBLICKEY */
-#define have_curlssl_pinnedpubkey 1
-
-/* API setup for OpenSSL */
-#define curlssl_init Curl_ossl_init
-#define curlssl_cleanup Curl_ossl_cleanup
-#define curlssl_connect Curl_ossl_connect
-#define curlssl_connect_nonblocking Curl_ossl_connect_nonblocking
-#define curlssl_session_free(x) Curl_ossl_session_free(x)
-#define curlssl_close_all Curl_ossl_close_all
-#define curlssl_close Curl_ossl_close
-#define curlssl_shutdown(x,y) Curl_ossl_shutdown(x,y)
-#define curlssl_set_engine(x,y) Curl_ossl_set_engine(x,y)
-#define curlssl_set_engine_default(x) Curl_ossl_set_engine_default(x)
-#define curlssl_engines_list(x) Curl_ossl_engines_list(x)
-#define curlssl_version Curl_ossl_version
-#define curlssl_check_cxn Curl_ossl_check_cxn
-#define curlssl_data_pending(x,y) Curl_ossl_data_pending(x,y)
-#define curlssl_random(x,y,z) Curl_ossl_random(x,y,z)
-#define curlssl_md5sum(a,b,c,d) Curl_ossl_md5sum(a,b,c,d)
-#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
-#define curlssl_sha256sum(a,b,c,d) Curl_ossl_sha256sum(a,b,c,d)
-#endif
-#define curlssl_cert_status_request() Curl_ossl_cert_status_request()
-
-#define DEFAULT_CIPHER_SELECTION \
- "ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH"
+extern const struct Curl_ssl Curl_ssl_openssl;
#endif /* USE_OPENSSL */
#endif /* HEADER_CURL_SSLUSE_H */
diff --git a/Utilities/cmcurl/lib/vtls/polarssl.c b/Utilities/cmcurl/lib/vtls/polarssl.c
index 669091cb5..7ea26b442 100644
--- a/Utilities/cmcurl/lib/vtls/polarssl.c
+++ b/Utilities/cmcurl/lib/vtls/polarssl.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2010 - 2011, Hoi-Ho Chan, <hoiho.chan@gmail.com>
*
* This software is licensed as described in the file COPYING, which
@@ -30,7 +30,6 @@
#include "curl_setup.h"
#ifdef USE_POLARSSL
-
#include <polarssl/net.h>
#include <polarssl/ssl.h>
#include <polarssl/certs.h>
@@ -56,6 +55,7 @@
#include "select.h"
#include "strcase.h"
#include "polarssl_threadlock.h"
+#include "multiif.h"
#include "curl_printf.h"
#include "curl_memory.h"
/* The last #include file should be: */
@@ -70,6 +70,19 @@
#define PUB_DER_MAX_BYTES (RSA_PUB_DER_MAX_BYTES > ECP_PUB_DER_MAX_BYTES ? \
RSA_PUB_DER_MAX_BYTES : ECP_PUB_DER_MAX_BYTES)
+struct ssl_backend_data {
+ ctr_drbg_context ctr_drbg;
+ entropy_context entropy;
+ ssl_context ssl;
+ int server_fd;
+ x509_crt cacert;
+ x509_crt clicert;
+ x509_crl crl;
+ rsa_context rsa;
+};
+
+#define BACKEND connssl->backend
+
/* apply threading? */
#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
#define THREADING_SUPPORT
@@ -173,14 +186,11 @@ set_ssl_version_min_max(struct connectdata *conn, int sockindex)
case CURL_SSLVERSION_DEFAULT:
case CURL_SSLVERSION_TLSv1:
ssl_version = CURL_SSLVERSION_TLSv1_0;
- ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_2;
break;
}
switch(ssl_version_max) {
case CURL_SSLVERSION_MAX_NONE:
- ssl_version_max = ssl_version << 16;
- break;
case CURL_SSLVERSION_MAX_DEFAULT:
ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_2;
break;
@@ -197,8 +207,8 @@ set_ssl_version_min_max(struct connectdata *conn, int sockindex)
return result;
}
- ssl_set_min_version(&connssl->ssl, SSL_MAJOR_VERSION_3, ssl_min_ver);
- ssl_set_max_version(&connssl->ssl, SSL_MAJOR_VERSION_3, ssl_max_ver);
+ ssl_set_min_version(&BACKEND->ssl, SSL_MAJOR_VERSION_3, ssl_min_ver);
+ ssl_set_max_version(&BACKEND->ssl, SSL_MAJOR_VERSION_3, ssl_max_ver);
return result;
}
@@ -215,7 +225,7 @@ polarssl_connect_step1(struct connectdata *conn,
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
int ret = -1;
char errorbuf[128];
- errorbuf[0]=0;
+ errorbuf[0] = 0;
/* PolarSSL only supports SSLv3 and TLSv1 */
if(SSL_CONN_CONFIG(version) == CURL_SSLVERSION_SSLv2) {
@@ -226,16 +236,16 @@ polarssl_connect_step1(struct connectdata *conn,
#ifdef THREADING_SUPPORT
entropy_init_mutex(&entropy);
- if((ret = ctr_drbg_init(&connssl->ctr_drbg, entropy_func_mutex, &entropy,
+ if((ret = ctr_drbg_init(&BACKEND->ctr_drbg, entropy_func_mutex, &entropy,
NULL, 0)) != 0) {
error_strerror(ret, errorbuf, sizeof(errorbuf));
failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n",
-ret, errorbuf);
}
#else
- entropy_init(&connssl->entropy);
+ entropy_init(&BACKEND->entropy);
- if((ret = ctr_drbg_init(&connssl->ctr_drbg, entropy_func, &connssl->entropy,
+ if((ret = ctr_drbg_init(&BACKEND->ctr_drbg, entropy_func, &BACKEND->entropy,
NULL, 0)) != 0) {
error_strerror(ret, errorbuf, sizeof(errorbuf));
failf(data, "Failed - PolarSSL: ctr_drbg_init returned (-0x%04X) %s\n",
@@ -244,10 +254,10 @@ polarssl_connect_step1(struct connectdata *conn,
#endif /* THREADING_SUPPORT */
/* Load the trusted CA */
- memset(&connssl->cacert, 0, sizeof(x509_crt));
+ memset(&BACKEND->cacert, 0, sizeof(x509_crt));
if(SSL_CONN_CONFIG(CAfile)) {
- ret = x509_crt_parse_file(&connssl->cacert,
+ ret = x509_crt_parse_file(&BACKEND->cacert,
SSL_CONN_CONFIG(CAfile));
if(ret<0) {
@@ -261,7 +271,7 @@ polarssl_connect_step1(struct connectdata *conn,
}
if(capath) {
- ret = x509_crt_parse_path(&connssl->cacert, capath);
+ ret = x509_crt_parse_path(&BACKEND->cacert, capath);
if(ret<0) {
error_strerror(ret, errorbuf, sizeof(errorbuf));
@@ -274,10 +284,10 @@ polarssl_connect_step1(struct connectdata *conn,
}
/* Load the client certificate */
- memset(&connssl->clicert, 0, sizeof(x509_crt));
+ memset(&BACKEND->clicert, 0, sizeof(x509_crt));
if(SSL_SET_OPTION(cert)) {
- ret = x509_crt_parse_file(&connssl->clicert,
+ ret = x509_crt_parse_file(&BACKEND->clicert,
SSL_SET_OPTION(cert));
if(ret) {
@@ -298,9 +308,9 @@ polarssl_connect_step1(struct connectdata *conn,
if(ret == 0 && !pk_can_do(&pk, POLARSSL_PK_RSA))
ret = POLARSSL_ERR_PK_TYPE_MISMATCH;
if(ret == 0)
- rsa_copy(&connssl->rsa, pk_rsa(pk));
+ rsa_copy(&BACKEND->rsa, pk_rsa(pk));
else
- rsa_free(&connssl->rsa);
+ rsa_free(&BACKEND->rsa);
pk_free(&pk);
if(ret) {
@@ -313,10 +323,10 @@ polarssl_connect_step1(struct connectdata *conn,
}
/* Load the CRL */
- memset(&connssl->crl, 0, sizeof(x509_crl));
+ memset(&BACKEND->crl, 0, sizeof(x509_crl));
if(SSL_SET_OPTION(CRLfile)) {
- ret = x509_crl_parse_file(&connssl->crl,
+ ret = x509_crl_parse_file(&BACKEND->crl,
SSL_SET_OPTION(CRLfile));
if(ret) {
@@ -330,7 +340,7 @@ polarssl_connect_step1(struct connectdata *conn,
infof(data, "PolarSSL: Connecting to %s:%d\n", hostname, port);
- if(ssl_init(&connssl->ssl)) {
+ if(ssl_init(&BACKEND->ssl)) {
failf(data, "PolarSSL: ssl_init failed");
return CURLE_SSL_CONNECT_ERROR;
}
@@ -338,13 +348,13 @@ polarssl_connect_step1(struct connectdata *conn,
switch(SSL_CONN_CONFIG(version)) {
case CURL_SSLVERSION_DEFAULT:
case CURL_SSLVERSION_TLSv1:
- ssl_set_min_version(&connssl->ssl, SSL_MAJOR_VERSION_3,
+ ssl_set_min_version(&BACKEND->ssl, SSL_MAJOR_VERSION_3,
SSL_MINOR_VERSION_1);
break;
case CURL_SSLVERSION_SSLv3:
- ssl_set_min_version(&connssl->ssl, SSL_MAJOR_VERSION_3,
+ ssl_set_min_version(&BACKEND->ssl, SSL_MAJOR_VERSION_3,
SSL_MINOR_VERSION_0);
- ssl_set_max_version(&connssl->ssl, SSL_MAJOR_VERSION_3,
+ ssl_set_max_version(&BACKEND->ssl, SSL_MAJOR_VERSION_3,
SSL_MINOR_VERSION_0);
infof(data, "PolarSSL: Forced min. SSL Version to be SSLv3\n");
break;
@@ -363,16 +373,16 @@ polarssl_connect_step1(struct connectdata *conn,
return CURLE_SSL_CONNECT_ERROR;
}
- ssl_set_endpoint(&connssl->ssl, SSL_IS_CLIENT);
- ssl_set_authmode(&connssl->ssl, SSL_VERIFY_OPTIONAL);
+ ssl_set_endpoint(&BACKEND->ssl, SSL_IS_CLIENT);
+ ssl_set_authmode(&BACKEND->ssl, SSL_VERIFY_OPTIONAL);
- ssl_set_rng(&connssl->ssl, ctr_drbg_random,
- &connssl->ctr_drbg);
- ssl_set_bio(&connssl->ssl,
+ ssl_set_rng(&BACKEND->ssl, ctr_drbg_random,
+ &BACKEND->ctr_drbg);
+ ssl_set_bio(&BACKEND->ssl,
net_recv, &conn->sock[sockindex],
net_send, &conn->sock[sockindex]);
- ssl_set_ciphersuites(&connssl->ssl, ssl_list_ciphersuites());
+ ssl_set_ciphersuites(&BACKEND->ssl, ssl_list_ciphersuites());
/* Check if there's a cached ID we can/should use here! */
if(SSL_SET_OPTION(primary.sessionid)) {
@@ -380,7 +390,7 @@ polarssl_connect_step1(struct connectdata *conn,
Curl_ssl_sessionid_lock(conn);
if(!Curl_ssl_getsessionid(conn, &old_session, NULL, sockindex)) {
- ret = ssl_set_session(&connssl->ssl, old_session);
+ ret = ssl_set_session(&BACKEND->ssl, old_session);
if(ret) {
Curl_ssl_sessionid_unlock(conn);
failf(data, "ssl_set_session returned -0x%x", -ret);
@@ -391,15 +401,15 @@ polarssl_connect_step1(struct connectdata *conn,
Curl_ssl_sessionid_unlock(conn);
}
- ssl_set_ca_chain(&connssl->ssl,
- &connssl->cacert,
- &connssl->crl,
+ ssl_set_ca_chain(&BACKEND->ssl,
+ &BACKEND->cacert,
+ &BACKEND->crl,
hostname);
- ssl_set_own_cert_rsa(&connssl->ssl,
- &connssl->clicert, &connssl->rsa);
+ ssl_set_own_cert_rsa(&BACKEND->ssl,
+ &BACKEND->clicert, &BACKEND->rsa);
- if(ssl_set_hostname(&connssl->ssl, hostname)) {
+ if(ssl_set_hostname(&BACKEND->ssl, hostname)) {
/* ssl_set_hostname() sets the name to use in CN/SAN checks *and* the name
to set in the SNI extension. So even if curl connects to a host
specified as an IP address, this function must be used. */
@@ -424,12 +434,12 @@ polarssl_connect_step1(struct connectdata *conn,
protocols[cur] = NULL;
- ssl_set_alpn_protocols(&connssl->ssl, protocols);
+ ssl_set_alpn_protocols(&BACKEND->ssl, protocols);
}
#endif
#ifdef POLARSSL_DEBUG
- ssl_set_dbg(&connssl->ssl, polarssl_debug, data);
+ ssl_set_dbg(&BACKEND->ssl, polarssl_debug, data);
#endif
connssl->connecting_state = ssl_connect_2;
@@ -456,7 +466,7 @@ polarssl_connect_step2(struct connectdata *conn,
conn->recv[sockindex] = polarssl_recv;
conn->send[sockindex] = polarssl_send;
- ret = ssl_handshake(&connssl->ssl);
+ ret = ssl_handshake(&BACKEND->ssl);
switch(ret) {
case 0:
@@ -478,9 +488,9 @@ polarssl_connect_step2(struct connectdata *conn,
}
infof(data, "PolarSSL: Handshake complete, cipher is %s\n",
- ssl_get_ciphersuite(&conn->ssl[sockindex].ssl) );
+ ssl_get_ciphersuite(&BACKEND->ssl) );
- ret = ssl_get_verify_result(&conn->ssl[sockindex].ssl);
+ ret = ssl_get_verify_result(&BACKEND->ssl);
if(ret && SSL_CONN_CONFIG(verifypeer)) {
if(ret & BADCERT_EXPIRED)
@@ -488,7 +498,7 @@ polarssl_connect_step2(struct connectdata *conn,
if(ret & BADCERT_REVOKED) {
failf(data, "Cert verify failed: BADCERT_REVOKED");
- return CURLE_SSL_CACERT;
+ return CURLE_PEER_FAILED_VERIFICATION;
}
if(ret & BADCERT_CN_MISMATCH)
@@ -500,12 +510,12 @@ polarssl_connect_step2(struct connectdata *conn,
return CURLE_PEER_FAILED_VERIFICATION;
}
- if(ssl_get_peer_cert(&(connssl->ssl))) {
+ if(ssl_get_peer_cert(&(BACKEND->ssl))) {
/* If the session was resumed, there will be no peer certs */
memset(buffer, 0, sizeof(buffer));
if(x509_crt_info(buffer, sizeof(buffer), (char *)"* ",
- ssl_get_peer_cert(&(connssl->ssl))) != -1)
+ ssl_get_peer_cert(&(BACKEND->ssl))) != -1)
infof(data, "Dumping cert info:\n%s\n", buffer);
}
@@ -517,7 +527,7 @@ polarssl_connect_step2(struct connectdata *conn,
unsigned char pubkey[PUB_DER_MAX_BYTES];
const x509_crt *peercert;
- peercert = ssl_get_peer_cert(&connssl->ssl);
+ peercert = ssl_get_peer_cert(&BACKEND->ssl);
if(!peercert || !peercert->raw.p || !peercert->raw.len) {
failf(data, "Failed due to missing peer certificate");
@@ -566,7 +576,7 @@ polarssl_connect_step2(struct connectdata *conn,
#ifdef HAS_ALPN
if(conn->bits.tls_enable_alpn) {
- const char *next_protocol = ssl_get_alpn_protocol(&connssl->ssl);
+ const char *next_protocol = ssl_get_alpn_protocol(&BACKEND->ssl);
if(next_protocol != NULL) {
infof(data, "ALPN, server accepted to use %s\n", next_protocol);
@@ -584,6 +594,8 @@ polarssl_connect_step2(struct connectdata *conn,
}
else
infof(data, "ALPN, server did not agree to a protocol\n");
+ Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
+ BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
}
#endif
@@ -608,13 +620,11 @@ polarssl_connect_step3(struct connectdata *conn,
ssl_session *our_ssl_sessionid;
void *old_ssl_sessionid = NULL;
- our_ssl_sessionid = malloc(sizeof(ssl_session));
+ our_ssl_sessionid = calloc(1, sizeof(ssl_session));
if(!our_ssl_sessionid)
return CURLE_OUT_OF_MEMORY;
- memset(our_ssl_sessionid, 0, sizeof(ssl_session));
-
- ret = ssl_get_session(&connssl->ssl, our_ssl_sessionid);
+ ret = ssl_get_session(&BACKEND->ssl, our_ssl_sessionid);
if(ret) {
failf(data, "ssl_get_session returned -0x%x", -ret);
return CURLE_SSL_CONNECT_ERROR;
@@ -645,9 +655,10 @@ static ssize_t polarssl_send(struct connectdata *conn,
size_t len,
CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
int ret = -1;
- ret = ssl_write(&conn->ssl[sockindex].ssl,
+ ret = ssl_write(&BACKEND->ssl,
(unsigned char *)mem, len);
if(ret < 0) {
@@ -659,13 +670,14 @@ static ssize_t polarssl_send(struct connectdata *conn,
return ret;
}
-void Curl_polarssl_close(struct connectdata *conn, int sockindex)
+static void Curl_polarssl_close(struct connectdata *conn, int sockindex)
{
- rsa_free(&conn->ssl[sockindex].rsa);
- x509_crt_free(&conn->ssl[sockindex].clicert);
- x509_crt_free(&conn->ssl[sockindex].cacert);
- x509_crl_free(&conn->ssl[sockindex].crl);
- ssl_free(&conn->ssl[sockindex].ssl);
+ struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ rsa_free(&BACKEND->rsa);
+ x509_crt_free(&BACKEND->clicert);
+ x509_crt_free(&BACKEND->cacert);
+ x509_crl_free(&BACKEND->crl);
+ ssl_free(&BACKEND->ssl);
}
static ssize_t polarssl_recv(struct connectdata *conn,
@@ -674,11 +686,12 @@ static ssize_t polarssl_recv(struct connectdata *conn,
size_t buffersize,
CURLcode *curlcode)
{
+ struct ssl_connect_data *connssl = &conn->ssl[num];
int ret = -1;
ssize_t len = -1;
memset(buf, 0, buffersize);
- ret = ssl_read(&conn->ssl[num].ssl, (unsigned char *)buf, buffersize);
+ ret = ssl_read(&BACKEND->ssl, (unsigned char *)buf, buffersize);
if(ret <= 0) {
if(ret == POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY)
@@ -694,7 +707,7 @@ static ssize_t polarssl_recv(struct connectdata *conn,
return len;
}
-void Curl_polarssl_session_free(void *ptr)
+static void Curl_polarssl_session_free(void *ptr)
{
ssl_session_free(ptr);
free(ptr);
@@ -703,12 +716,12 @@ void Curl_polarssl_session_free(void *ptr)
/* 1.3.10 was the first rebranded version. All new releases (in 1.3 branch and
higher) will be mbed TLS branded.. */
-size_t Curl_polarssl_version(char *buffer, size_t size)
+static size_t Curl_polarssl_version(char *buffer, size_t size)
{
unsigned int version = version_get_number();
- return snprintf(buffer, size, "%s/%d.%d.%d",
- version >= 0x01030A00?"mbedTLS":"PolarSSL",
- version>>24, (version>>16)&0xff, (version>>8)&0xff);
+ return msnprintf(buffer, size, "%s/%d.%d.%d",
+ version >= 0x01030A00?"mbedTLS":"PolarSSL",
+ version>>24, (version>>16)&0xff, (version>>8)&0xff);
}
static CURLcode
@@ -762,9 +775,9 @@ polarssl_connect_common(struct connectdata *conn,
if(connssl->connecting_state == ssl_connect_2_reading ||
connssl->connecting_state == ssl_connect_2_writing) {
- curl_socket_t writefd = ssl_connect_2_writing==
+ curl_socket_t writefd = ssl_connect_2_writing ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
- curl_socket_t readfd = ssl_connect_2_reading==
+ curl_socket_t readfd = ssl_connect_2_reading ==
connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
@@ -825,18 +838,14 @@ polarssl_connect_common(struct connectdata *conn,
return CURLE_OK;
}
-CURLcode
-Curl_polarssl_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done)
+static CURLcode Curl_polarssl_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
{
return polarssl_connect_common(conn, sockindex, TRUE, done);
}
-CURLcode
-Curl_polarssl_connect(struct connectdata *conn,
- int sockindex)
+static CURLcode Curl_polarssl_connect(struct connectdata *conn, int sockindex)
{
CURLcode result;
bool done = FALSE;
@@ -854,20 +863,69 @@ Curl_polarssl_connect(struct connectdata *conn,
* return 0 error initializing SSL
* return 1 SSL initialized successfully
*/
-int Curl_polarssl_init(void)
+static int Curl_polarssl_init(void)
{
return Curl_polarsslthreadlock_thread_setup();
}
-void Curl_polarssl_cleanup(void)
+static void Curl_polarssl_cleanup(void)
{
(void)Curl_polarsslthreadlock_thread_cleanup();
}
+static bool Curl_polarssl_data_pending(const struct connectdata *conn,
+ int sockindex)
+{
+ const struct ssl_connect_data *connssl = &conn->ssl[sockindex];
+ return ssl_get_bytes_avail(&BACKEND->ssl) != 0;
+}
+
+static CURLcode Curl_polarssl_sha256sum(const unsigned char *input,
+ size_t inputlen,
+ unsigned char *sha256sum,
+ size_t sha256len UNUSED_PARAM)
+{
+ (void)sha256len;
+ sha256(input, inputlen, sha256sum, 0);
+ return CURLE_OK;
+}
-int Curl_polarssl_data_pending(const struct connectdata *conn, int sockindex)
+static void *Curl_polarssl_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info UNUSED_PARAM)
{
- return ssl_get_bytes_avail(&conn->ssl[sockindex].ssl) != 0;
+ (void)info;
+ return &BACKEND->ssl;
}
+const struct Curl_ssl Curl_ssl_polarssl = {
+ { CURLSSLBACKEND_POLARSSL, "polarssl" }, /* info */
+
+ SSLSUPP_CA_PATH |
+ SSLSUPP_PINNEDPUBKEY,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_polarssl_init, /* init */
+ Curl_polarssl_cleanup, /* cleanup */
+ Curl_polarssl_version, /* version */
+ Curl_none_check_cxn, /* check_cxn */
+ Curl_none_shutdown, /* shutdown */
+ Curl_polarssl_data_pending, /* data_pending */
+ /* This might cause libcurl to use a weeker random! */
+ Curl_none_random, /* random */
+ Curl_none_cert_status_request, /* cert_status_request */
+ Curl_polarssl_connect, /* connect */
+ Curl_polarssl_connect_nonblocking, /* connect_nonblocking */
+ Curl_polarssl_get_internals, /* get_internals */
+ Curl_polarssl_close, /* close_one */
+ Curl_none_close_all, /* close_all */
+ Curl_polarssl_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_none_md5sum, /* md5sum */
+ Curl_polarssl_sha256sum /* sha256sum */
+};
+
#endif /* USE_POLARSSL */
diff --git a/Utilities/cmcurl/lib/vtls/polarssl.h b/Utilities/cmcurl/lib/vtls/polarssl.h
index 47af7b417..23c3636ee 100644
--- a/Utilities/cmcurl/lib/vtls/polarssl.h
+++ b/Utilities/cmcurl/lib/vtls/polarssl.h
@@ -26,57 +26,7 @@
#ifdef USE_POLARSSL
-#include <polarssl/sha256.h>
-
-/* Called on first use PolarSSL, setup threading if supported */
-int Curl_polarssl_init(void);
-void Curl_polarssl_cleanup(void);
-int Curl_polarssl_data_pending(const struct connectdata *conn, int sockindex);
-
-
-CURLcode Curl_polarssl_connect(struct connectdata *conn, int sockindex);
-
-CURLcode Curl_polarssl_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done);
-
- /* close a SSL connection */
-void Curl_polarssl_close(struct connectdata *conn, int sockindex);
-
-void Curl_polarssl_session_free(void *ptr);
-size_t Curl_polarssl_version(char *buffer, size_t size);
-int Curl_polarssl_shutdown(struct connectdata *conn, int sockindex);
-
-/* Set the API backend definition to PolarSSL */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_POLARSSL
-
-/* this backend supports the CAPATH option */
-#define have_curlssl_ca_path 1
-
-/* this backends supports CURLOPT_PINNEDPUBLICKEY */
-#define have_curlssl_pinnedpubkey 1
-
-/* API setup for PolarSSL */
-#define curlssl_init() Curl_polarssl_init()
-#define curlssl_cleanup() Curl_polarssl_cleanup()
-#define curlssl_connect Curl_polarssl_connect
-#define curlssl_connect_nonblocking Curl_polarssl_connect_nonblocking
-#define curlssl_session_free(x) Curl_polarssl_session_free(x)
-#define curlssl_close_all(x) ((void)x)
-#define curlssl_close Curl_polarssl_close
-#define curlssl_shutdown(x,y) 0
-#define curlssl_set_engine(x,y) ((void)x, (void)y, CURLE_NOT_BUILT_IN)
-#define curlssl_set_engine_default(x) ((void)x, CURLE_NOT_BUILT_IN)
-#define curlssl_engines_list(x) ((void)x, (struct curl_slist *)NULL)
-#define curlssl_version Curl_polarssl_version
-#define curlssl_check_cxn(x) ((void)x, -1)
-#define curlssl_data_pending(x,y) Curl_polarssl_data_pending(x, y)
-#define curlssl_sha256sum(a,b,c,d) sha256(a,b,c,0)
-
-/* This might cause libcurl to use a weeker random!
- TODO: implement proper use of Polarssl's CTR-DRBG or HMAC-DRBG and use that
-*/
-#define curlssl_random(x,y,z) ((void)x, (void)y, (void)z, CURLE_NOT_BUILT_IN)
+extern const struct Curl_ssl Curl_ssl_polarssl;
#endif /* USE_POLARSSL */
#endif /* HEADER_CURL_POLARSSL_H */
diff --git a/Utilities/cmcurl/lib/vtls/polarssl_threadlock.c b/Utilities/cmcurl/lib/vtls/polarssl_threadlock.c
index b1eb7b746..27c94b11e 100644
--- a/Utilities/cmcurl/lib/vtls/polarssl_threadlock.c
+++ b/Utilities/cmcurl/lib/vtls/polarssl_threadlock.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2013-2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2013-2017, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2010, 2011, Hoi-Ho Chan, <hoiho.chan@gmail.com>
*
* This software is licensed as described in the file COPYING, which
@@ -23,16 +23,15 @@
#include "curl_setup.h"
#if (defined(USE_POLARSSL) || defined(USE_MBEDTLS)) && \
- (defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32))
-
-#if defined(USE_THREADS_POSIX)
-# ifdef HAVE_PTHREAD_H
-# include <pthread.h>
-# endif
-#elif defined(USE_THREADS_WIN32)
-# ifdef HAVE_PROCESS_H
-# include <process.h>
-# endif
+ ((defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \
+ (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)))
+
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
+# include <pthread.h>
+# define POLARSSL_MUTEX_T pthread_mutex_t
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
+# include <process.h>
+# define POLARSSL_MUTEX_T HANDLE
#endif
#include "polarssl_threadlock.h"
@@ -50,25 +49,23 @@ static POLARSSL_MUTEX_T *mutex_buf = NULL;
int Curl_polarsslthreadlock_thread_setup(void)
{
int i;
- int ret;
mutex_buf = calloc(NUMT * sizeof(POLARSSL_MUTEX_T), 1);
if(!mutex_buf)
return 0; /* error, no number of threads defined */
-#ifdef HAVE_PTHREAD_H
for(i = 0; i < NUMT; i++) {
+ int ret;
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
ret = pthread_mutex_init(&mutex_buf[i], NULL);
if(ret)
return 0; /* pthread_mutex_init failed */
- }
-#elif defined(HAVE_PROCESS_H)
- for(i = 0; i < NUMT; i++) {
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
mutex_buf[i] = CreateMutex(0, FALSE, 0);
if(mutex_buf[i] == 0)
return 0; /* CreateMutex failed */
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
}
-#endif /* HAVE_PTHREAD_H */
return 1; /* OK */
}
@@ -76,24 +73,22 @@ int Curl_polarsslthreadlock_thread_setup(void)
int Curl_polarsslthreadlock_thread_cleanup(void)
{
int i;
- int ret;
if(!mutex_buf)
return 0; /* error, no threads locks defined */
-#ifdef HAVE_PTHREAD_H
for(i = 0; i < NUMT; i++) {
+ int ret;
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
ret = pthread_mutex_destroy(&mutex_buf[i]);
if(ret)
return 0; /* pthread_mutex_destroy failed */
- }
-#elif defined(HAVE_PROCESS_H)
- for(i = 0; i < NUMT; i++) {
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
ret = CloseHandle(mutex_buf[i]);
if(!ret)
return 0; /* CloseHandle failed */
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
}
-#endif /* HAVE_PTHREAD_H */
free(mutex_buf);
mutex_buf = NULL;
@@ -102,51 +97,47 @@ int Curl_polarsslthreadlock_thread_cleanup(void)
int Curl_polarsslthreadlock_lock_function(int n)
{
- int ret;
-#ifdef HAVE_PTHREAD_H
if(n < NUMT) {
+ int ret;
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
ret = pthread_mutex_lock(&mutex_buf[n]);
if(ret) {
DEBUGF(fprintf(stderr,
"Error: polarsslthreadlock_lock_function failed\n"));
return 0; /* pthread_mutex_lock failed */
}
- }
-#elif defined(HAVE_PROCESS_H)
- if(n < NUMT) {
- ret = (WaitForSingleObject(mutex_buf[n], INFINITE)==WAIT_FAILED?1:0);
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
+ ret = (WaitForSingleObject(mutex_buf[n], INFINITE) == WAIT_FAILED?1:0);
if(ret) {
DEBUGF(fprintf(stderr,
"Error: polarsslthreadlock_lock_function failed\n"));
return 0; /* pthread_mutex_lock failed */
}
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
}
-#endif /* HAVE_PTHREAD_H */
return 1; /* OK */
}
int Curl_polarsslthreadlock_unlock_function(int n)
{
- int ret;
-#ifdef HAVE_PTHREAD_H
if(n < NUMT) {
+ int ret;
+#if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
ret = pthread_mutex_unlock(&mutex_buf[n]);
if(ret) {
DEBUGF(fprintf(stderr,
"Error: polarsslthreadlock_unlock_function failed\n"));
return 0; /* pthread_mutex_unlock failed */
}
- }
-#elif defined(HAVE_PROCESS_H)
- if(n < NUMT) {
+#elif defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H)
ret = ReleaseMutex(mutex_buf[n]);
if(!ret) {
DEBUGF(fprintf(stderr,
"Error: polarsslthreadlock_unlock_function failed\n"));
return 0; /* pthread_mutex_lock failed */
}
+#endif /* USE_THREADS_POSIX && HAVE_PTHREAD_H */
}
-#endif /* HAVE_PTHREAD_H */
return 1; /* OK */
}
diff --git a/Utilities/cmcurl/lib/vtls/polarssl_threadlock.h b/Utilities/cmcurl/lib/vtls/polarssl_threadlock.h
index dda5359b8..122647528 100644
--- a/Utilities/cmcurl/lib/vtls/polarssl_threadlock.h
+++ b/Utilities/cmcurl/lib/vtls/polarssl_threadlock.h
@@ -26,13 +26,8 @@
#if (defined USE_POLARSSL) || (defined USE_MBEDTLS)
-#if defined(USE_THREADS_POSIX)
-# define POLARSSL_MUTEX_T pthread_mutex_t
-#elif defined(USE_THREADS_WIN32)
-# define POLARSSL_MUTEX_T HANDLE
-#endif
-
-#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
+#if (defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)) || \
+ (defined(USE_THREADS_WIN32) && defined(HAVE_PROCESS_H))
int Curl_polarsslthreadlock_thread_setup(void);
int Curl_polarsslthreadlock_thread_cleanup(void);
diff --git a/Utilities/cmcurl/lib/vtls/schannel.c b/Utilities/cmcurl/lib/vtls/schannel.c
index 94603018b..0f6f734fd 100644
--- a/Utilities/cmcurl/lib/vtls/schannel.c
+++ b/Utilities/cmcurl/lib/vtls/schannel.c
@@ -7,7 +7,7 @@
*
* Copyright (C) 2012 - 2016, Marc Hoersken, <info@marc-hoersken.de>
* Copyright (C) 2012, Mark Salisbury, <mark.salisbury@hp.com>
- * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2019, 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
@@ -23,9 +23,8 @@
***************************************************************************/
/*
- * Source file for all SChannel-specific code for the TLS/SSL layer. No code
+ * Source file for all Schannel-specific code for the TLS/SSL layer. No code
* but vtls.c should ever call or use these functions.
- *
*/
/*
@@ -42,11 +41,12 @@
#ifdef USE_SCHANNEL
+#define EXPOSE_SCHANNEL_INTERNAL_STRUCTS
+
#ifndef USE_WINDOWS_SSPI
# error "Can't compile SCHANNEL support without SSPI."
#endif
-#include "curl_sspi.h"
#include "schannel.h"
#include "vtls.h"
#include "sendf.h"
@@ -58,8 +58,8 @@
#include "warnless.h"
#include "x509asn1.h"
#include "curl_printf.h"
+#include "multiif.h"
#include "system_win32.h"
-#include "hostcheck.h"
/* The last #include file should be: */
#include "curl_memory.h"
@@ -74,17 +74,85 @@
# define HAS_ALPN 1
#endif
+#ifndef UNISP_NAME_A
+#define UNISP_NAME_A "Microsoft Unified Security Protocol Provider"
+#endif
+
+#ifndef UNISP_NAME_W
+#define UNISP_NAME_W L"Microsoft Unified Security Protocol Provider"
+#endif
+
+#ifndef UNISP_NAME
+#ifdef UNICODE
+#define UNISP_NAME UNISP_NAME_W
+#else
+#define UNISP_NAME UNISP_NAME_A
+#endif
+#endif
+
+#if defined(CryptStringToBinary) && defined(CRYPT_STRING_HEX)
+#define HAS_CLIENT_CERT_PATH
+#endif
+
+#ifdef HAS_CLIENT_CERT_PATH
+#ifdef UNICODE
+#define CURL_CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_W
+#else
+#define CURL_CERT_STORE_PROV_SYSTEM CERT_STORE_PROV_SYSTEM_A
+#endif
+#endif
+
+#ifndef SP_PROT_SSL2_CLIENT
+#define SP_PROT_SSL2_CLIENT 0x00000008
+#endif
+
+#ifndef SP_PROT_SSL3_CLIENT
+#define SP_PROT_SSL3_CLIENT 0x00000008
+#endif
+
+#ifndef SP_PROT_TLS1_CLIENT
+#define SP_PROT_TLS1_CLIENT 0x00000080
+#endif
+
+#ifndef SP_PROT_TLS1_0_CLIENT
+#define SP_PROT_TLS1_0_CLIENT SP_PROT_TLS1_CLIENT
+#endif
+
+#ifndef SP_PROT_TLS1_1_CLIENT
+#define SP_PROT_TLS1_1_CLIENT 0x00000200
+#endif
+
+#ifndef SP_PROT_TLS1_2_CLIENT
+#define SP_PROT_TLS1_2_CLIENT 0x00000800
+#endif
+
+#ifndef SECBUFFER_ALERT
+#define SECBUFFER_ALERT 17
+#endif
+
+/* Both schannel buffer sizes must be > 0 */
+#define CURL_SCHANNEL_BUFFER_INIT_SIZE 4096
+#define CURL_SCHANNEL_BUFFER_FREE_SIZE 1024
+
+#define CERT_THUMBPRINT_STR_LEN 40
+#define CERT_THUMBPRINT_DATA_LEN 20
+
/* Uncomment to force verbose output
* #define infof(x, y, ...) printf(y, __VA_ARGS__)
* #define failf(x, y, ...) printf(y, __VA_ARGS__)
*/
+#ifndef CALG_SHA_256
+# define CALG_SHA_256 0x0000800c
+#endif
+
+#define BACKEND connssl->backend
+
static Curl_recv schannel_recv;
static Curl_send schannel_send;
-#ifdef _WIN32_WCE
-static CURLcode verify_certificate(struct connectdata *conn, int sockindex);
-#endif
+static CURLcode pkp_pin_peer_pubkey(struct connectdata *conn, int sockindex,
+ const char *pinnedpubkey);
static void InitSecBuffer(SecBuffer *buffer, unsigned long BufType,
void *BufDataPtr, unsigned long BufByteSize)
@@ -112,8 +180,6 @@ set_ssl_version_min_max(SCHANNEL_CRED *schannel_cred, struct connectdata *conn)
switch(ssl_version_max) {
case CURL_SSLVERSION_MAX_NONE:
- ssl_version_max = ssl_version << 16;
- break;
case CURL_SSLVERSION_MAX_DEFAULT:
ssl_version_max = CURL_SSLVERSION_MAX_TLSv1_2;
break;
@@ -130,13 +196,221 @@ set_ssl_version_min_max(SCHANNEL_CRED *schannel_cred, struct connectdata *conn)
schannel_cred->grbitEnabledProtocols |= SP_PROT_TLS1_2_CLIENT;
break;
case CURL_SSLVERSION_TLSv1_3:
- failf(data, "Schannel: TLS 1.3 is not yet supported");
+ failf(data, "schannel: TLS 1.3 is not yet supported");
return CURLE_SSL_CONNECT_ERROR;
}
}
return CURLE_OK;
}
+/*longest is 26, buffer is slightly bigger*/
+#define LONGEST_ALG_ID 32
+#define CIPHEROPTION(X) \
+if(strcmp(#X, tmp) == 0) \
+ return X
+
+static int
+get_alg_id_by_name(char *name)
+{
+ char tmp[LONGEST_ALG_ID] = { 0 };
+ char *nameEnd = strchr(name, ':');
+ size_t n = nameEnd ? min((size_t)(nameEnd - name), LONGEST_ALG_ID - 1) : \
+ min(strlen(name), LONGEST_ALG_ID - 1);
+ strncpy(tmp, name, n);
+ tmp[n] = 0;
+ CIPHEROPTION(CALG_MD2);
+ CIPHEROPTION(CALG_MD4);
+ CIPHEROPTION(CALG_MD5);
+ CIPHEROPTION(CALG_SHA);
+ CIPHEROPTION(CALG_SHA1);
+ CIPHEROPTION(CALG_MAC);
+ CIPHEROPTION(CALG_RSA_SIGN);
+ CIPHEROPTION(CALG_DSS_SIGN);
+/*ifdefs for the options that are defined conditionally in wincrypt.h*/
+#ifdef CALG_NO_SIGN
+ CIPHEROPTION(CALG_NO_SIGN);
+#endif
+ CIPHEROPTION(CALG_RSA_KEYX);
+ CIPHEROPTION(CALG_DES);
+#ifdef CALG_3DES_112
+ CIPHEROPTION(CALG_3DES_112);
+#endif
+ CIPHEROPTION(CALG_3DES);
+ CIPHEROPTION(CALG_DESX);
+ CIPHEROPTION(CALG_RC2);
+ CIPHEROPTION(CALG_RC4);
+ CIPHEROPTION(CALG_SEAL);
+#ifdef CALG_DH_SF
+ CIPHEROPTION(CALG_DH_SF);
+#endif
+ CIPHEROPTION(CALG_DH_EPHEM);
+#ifdef CALG_AGREEDKEY_ANY
+ CIPHEROPTION(CALG_AGREEDKEY_ANY);
+#endif
+#ifdef CALG_HUGHES_MD5
+ CIPHEROPTION(CALG_HUGHES_MD5);
+#endif
+ CIPHEROPTION(CALG_SKIPJACK);
+#ifdef CALG_TEK
+ CIPHEROPTION(CALG_TEK);
+#endif
+ CIPHEROPTION(CALG_CYLINK_MEK);
+ CIPHEROPTION(CALG_SSL3_SHAMD5);
+#ifdef CALG_SSL3_MASTER
+ CIPHEROPTION(CALG_SSL3_MASTER);
+#endif
+#ifdef CALG_SCHANNEL_MASTER_HASH
+ CIPHEROPTION(CALG_SCHANNEL_MASTER_HASH);
+#endif
+#ifdef CALG_SCHANNEL_MAC_KEY
+ CIPHEROPTION(CALG_SCHANNEL_MAC_KEY);
+#endif
+#ifdef CALG_SCHANNEL_ENC_KEY
+ CIPHEROPTION(CALG_SCHANNEL_ENC_KEY);
+#endif
+#ifdef CALG_PCT1_MASTER
+ CIPHEROPTION(CALG_PCT1_MASTER);
+#endif
+#ifdef CALG_SSL2_MASTER
+ CIPHEROPTION(CALG_SSL2_MASTER);
+#endif
+#ifdef CALG_TLS1_MASTER
+ CIPHEROPTION(CALG_TLS1_MASTER);
+#endif
+#ifdef CALG_RC5
+ CIPHEROPTION(CALG_RC5);
+#endif
+#ifdef CALG_HMAC
+ CIPHEROPTION(CALG_HMAC);
+#endif
+#if !defined(__W32API_MAJOR_VERSION) || \
+ !defined(__W32API_MINOR_VERSION) || \
+ defined(__MINGW64_VERSION_MAJOR) || \
+ (__W32API_MAJOR_VERSION > 5) || \
+ ((__W32API_MAJOR_VERSION == 5) && (__W32API_MINOR_VERSION > 0))
+ /* CALG_TLS1PRF has a syntax error in MinGW's w32api up to version 5.0,
+ see https://osdn.net/projects/mingw/ticket/38391 */
+ CIPHEROPTION(CALG_TLS1PRF);
+#endif
+#ifdef CALG_HASH_REPLACE_OWF
+ CIPHEROPTION(CALG_HASH_REPLACE_OWF);
+#endif
+#ifdef CALG_AES_128
+ CIPHEROPTION(CALG_AES_128);
+#endif
+#ifdef CALG_AES_192
+ CIPHEROPTION(CALG_AES_192);
+#endif
+#ifdef CALG_AES_256
+ CIPHEROPTION(CALG_AES_256);
+#endif
+#ifdef CALG_AES
+ CIPHEROPTION(CALG_AES);
+#endif
+#ifdef CALG_SHA_256
+ CIPHEROPTION(CALG_SHA_256);
+#endif
+#ifdef CALG_SHA_384
+ CIPHEROPTION(CALG_SHA_384);
+#endif
+#ifdef CALG_SHA_512
+ CIPHEROPTION(CALG_SHA_512);
+#endif
+#ifdef CALG_ECDH
+ CIPHEROPTION(CALG_ECDH);
+#endif
+#ifdef CALG_ECMQV
+ CIPHEROPTION(CALG_ECMQV);
+#endif
+#ifdef CALG_ECDSA
+ CIPHEROPTION(CALG_ECDSA);
+#endif
+#ifdef CALG_ECDH_EPHEM
+ CIPHEROPTION(CALG_ECDH_EPHEM);
+#endif
+ return 0;
+}
+
+static CURLcode
+set_ssl_ciphers(SCHANNEL_CRED *schannel_cred, char *ciphers)
+{
+ char *startCur = ciphers;
+ int algCount = 0;
+ static ALG_ID algIds[45]; /*There are 45 listed in the MS headers*/
+ while(startCur && (0 != *startCur) && (algCount < 45)) {
+ long alg = strtol(startCur, 0, 0);
+ if(!alg)
+ alg = get_alg_id_by_name(startCur);
+ if(alg)
+ algIds[algCount++] = alg;
+ else
+ return CURLE_SSL_CIPHER;
+ startCur = strchr(startCur, ':');
+ if(startCur)
+ startCur++;
+ }
+ schannel_cred->palgSupportedAlgs = algIds;
+ schannel_cred->cSupportedAlgs = algCount;
+ return CURLE_OK;
+}
+
+#ifdef HAS_CLIENT_CERT_PATH
+static CURLcode
+get_cert_location(TCHAR *path, DWORD *store_name, TCHAR **store_path,
+ TCHAR **thumbprint)
+{
+ TCHAR *sep;
+ TCHAR *store_path_start;
+ size_t store_name_len;
+
+ sep = _tcschr(path, TEXT('\\'));
+ if(sep == NULL)
+ return CURLE_SSL_CERTPROBLEM;
+
+ store_name_len = sep - path;
+
+ if(_tcsnccmp(path, TEXT("CurrentUser"), store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_CURRENT_USER;
+ else if(_tcsnccmp(path, TEXT("LocalMachine"), store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_LOCAL_MACHINE;
+ else if(_tcsnccmp(path, TEXT("CurrentService"), store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_CURRENT_SERVICE;
+ else if(_tcsnccmp(path, TEXT("Services"), store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_SERVICES;
+ else if(_tcsnccmp(path, TEXT("Users"), store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_USERS;
+ else if(_tcsnccmp(path, TEXT("CurrentUserGroupPolicy"),
+ store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY;
+ else if(_tcsnccmp(path, TEXT("LocalMachineGroupPolicy"),
+ store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY;
+ else if(_tcsnccmp(path, TEXT("LocalMachineEnterprise"),
+ store_name_len) == 0)
+ *store_name = CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE;
+ else
+ return CURLE_SSL_CERTPROBLEM;
+
+ store_path_start = sep + 1;
+
+ sep = _tcschr(store_path_start, TEXT('\\'));
+ if(sep == NULL)
+ return CURLE_SSL_CERTPROBLEM;
+
+ *sep = TEXT('\0');
+ *store_path = _tcsdup(store_path_start);
+ *sep = TEXT('\\');
+ if(*store_path == NULL)
+ return CURLE_OUT_OF_MEMORY;
+
+ *thumbprint = sep + 1;
+ if(_tcslen(*thumbprint) != CERT_THUMBPRINT_STR_LEN)
+ return CURLE_SSL_CERTPROBLEM;
+
+ return CURLE_OK;
+}
+#endif
+
static CURLcode
schannel_connect_step1(struct connectdata *conn, int sockindex)
{
@@ -151,6 +425,7 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
unsigned char alpn_buffer[128];
#endif
SCHANNEL_CRED schannel_cred;
+ PCCERT_CONTEXT client_certs[1] = { NULL };
SECURITY_STATUS sspi_status = SEC_E_OK;
struct curl_schannel_cred *old_cred = NULL;
struct in_addr addr;
@@ -162,85 +437,118 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
- infof(data, "schannel: SSL/TLS connection with %s port %hu (step 1/3)\n",
- hostname, conn->remote_port);
+ DEBUGF(infof(data,
+ "schannel: SSL/TLS connection with %s port %hu (step 1/3)\n",
+ hostname, conn->remote_port));
if(Curl_verify_windows_version(5, 1, PLATFORM_WINNT,
VERSION_LESS_THAN_EQUAL)) {
- /* SChannel in Windows XP (OS version 5.1) uses legacy handshakes and
+ /* Schannel in Windows XP (OS version 5.1) uses legacy handshakes and
algorithms that may not be supported by all servers. */
- infof(data, "schannel: WinSSL version is old and may not be able to "
+ infof(data, "schannel: Windows version is old and may not be able to "
"connect to some servers due to lack of SNI, algorithms, etc.\n");
}
#ifdef HAS_ALPN
/* ALPN is only supported on Windows 8.1 / Server 2012 R2 and above.
Also it doesn't seem to be supported for Wine, see curl bug #983. */
- connssl->use_alpn = conn->bits.tls_enable_alpn &&
+ BACKEND->use_alpn = conn->bits.tls_enable_alpn &&
!GetProcAddress(GetModuleHandleA("ntdll"),
"wine_get_version") &&
Curl_verify_windows_version(6, 3, PLATFORM_WINNT,
VERSION_GREATER_THAN_EQUAL);
#else
- connssl->use_alpn = false;
+ BACKEND->use_alpn = false;
+#endif
+
+#ifdef _WIN32_WCE
+#ifdef HAS_MANUAL_VERIFY_API
+ /* certificate validation on CE doesn't seem to work right; we'll
+ * do it following a more manual process. */
+ BACKEND->use_manual_cred_validation = true;
+#else
+#error "compiler too old to support requisite manual cert verify for Win CE"
+#endif
+#else
+#ifdef HAS_MANUAL_VERIFY_API
+ if(SSL_CONN_CONFIG(CAfile)) {
+ if(Curl_verify_windows_version(6, 1, PLATFORM_WINNT,
+ VERSION_GREATER_THAN_EQUAL)) {
+ BACKEND->use_manual_cred_validation = true;
+ }
+ else {
+ failf(data, "schannel: this version of Windows is too old to support "
+ "certificate verification via CA bundle file.");
+ return CURLE_SSL_CACERT_BADFILE;
+ }
+ }
+ else
+ BACKEND->use_manual_cred_validation = false;
+#else
+ if(SSL_CONN_CONFIG(CAfile)) {
+ failf(data, "schannel: CA cert support not built in");
+ return CURLE_NOT_BUILT_IN;
+ }
+#endif
#endif
- connssl->cred = NULL;
+ BACKEND->cred = NULL;
/* check for an existing re-usable credential handle */
if(SSL_SET_OPTION(primary.sessionid)) {
Curl_ssl_sessionid_lock(conn);
if(!Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, sockindex)) {
- connssl->cred = old_cred;
- infof(data, "schannel: re-using existing credential handle\n");
+ BACKEND->cred = old_cred;
+ DEBUGF(infof(data, "schannel: re-using existing credential handle\n"));
/* increment the reference counter of the credential/session handle */
- connssl->cred->refcount++;
- infof(data, "schannel: incremented credential handle refcount = %d\n",
- connssl->cred->refcount);
+ BACKEND->cred->refcount++;
+ DEBUGF(infof(data,
+ "schannel: incremented credential handle refcount = %d\n",
+ BACKEND->cred->refcount));
}
Curl_ssl_sessionid_unlock(conn);
}
- if(!connssl->cred) {
+ if(!BACKEND->cred) {
/* setup Schannel API options */
memset(&schannel_cred, 0, sizeof(schannel_cred));
schannel_cred.dwVersion = SCHANNEL_CRED_VERSION;
if(conn->ssl_config.verifypeer) {
-#ifdef _WIN32_WCE
- /* certificate validation on CE doesn't seem to work right; we'll
- do it following a more manual process. */
- schannel_cred.dwFlags = SCH_CRED_MANUAL_CRED_VALIDATION |
- SCH_CRED_IGNORE_NO_REVOCATION_CHECK |
- SCH_CRED_IGNORE_REVOCATION_OFFLINE;
-#else
- schannel_cred.dwFlags = SCH_CRED_AUTO_CRED_VALIDATION;
- /* TODO s/data->set.ssl.no_revoke/SSL_SET_OPTION(no_revoke)/g */
- if(data->set.ssl.no_revoke)
- schannel_cred.dwFlags |= SCH_CRED_IGNORE_NO_REVOCATION_CHECK |
- SCH_CRED_IGNORE_REVOCATION_OFFLINE;
+#ifdef HAS_MANUAL_VERIFY_API
+ if(BACKEND->use_manual_cred_validation)
+ schannel_cred.dwFlags = SCH_CRED_MANUAL_CRED_VALIDATION;
else
- schannel_cred.dwFlags |= SCH_CRED_REVOCATION_CHECK_CHAIN;
#endif
- if(data->set.ssl.no_revoke)
- infof(data, "schannel: disabled server certificate revocation "
- "checks\n");
- else
- infof(data, "schannel: checking server certificate revocation\n");
+ schannel_cred.dwFlags = SCH_CRED_AUTO_CRED_VALIDATION;
+
+ if(data->set.ssl.no_revoke) {
+ schannel_cred.dwFlags |= SCH_CRED_IGNORE_NO_REVOCATION_CHECK |
+ SCH_CRED_IGNORE_REVOCATION_OFFLINE;
+
+ DEBUGF(infof(data, "schannel: disabled server certificate revocation "
+ "checks\n"));
+ }
+ else {
+ schannel_cred.dwFlags |= SCH_CRED_REVOCATION_CHECK_CHAIN;
+ DEBUGF(infof(data,
+ "schannel: checking server certificate revocation\n"));
+ }
}
else {
schannel_cred.dwFlags = SCH_CRED_MANUAL_CRED_VALIDATION |
SCH_CRED_IGNORE_NO_REVOCATION_CHECK |
SCH_CRED_IGNORE_REVOCATION_OFFLINE;
- infof(data, "schannel: disabled server certificate revocation checks\n");
+ DEBUGF(infof(data,
+ "schannel: disabled server cert revocation checks\n"));
}
if(!conn->ssl_config.verifyhost) {
schannel_cred.dwFlags |= SCH_CRED_NO_SERVERNAME_CHECK;
- infof(data, "schannel: verifyhost setting prevents Schannel from "
- "comparing the supplied target name with the subject "
- "names in server certificates.\n");
+ DEBUGF(infof(data, "schannel: verifyhost setting prevents Schannel from "
+ "comparing the supplied target name with the subject "
+ "names in server certificates.\n"));
}
switch(conn->ssl_config.version) {
@@ -271,15 +579,100 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
return CURLE_SSL_CONNECT_ERROR;
}
+ if(SSL_CONN_CONFIG(cipher_list)) {
+ result = set_ssl_ciphers(&schannel_cred, SSL_CONN_CONFIG(cipher_list));
+ if(CURLE_OK != result) {
+ failf(data, "Unable to set ciphers to passed via SSL_CONN_CONFIG");
+ return result;
+ }
+ }
+
+
+#ifdef HAS_CLIENT_CERT_PATH
+ /* client certificate */
+ if(data->set.ssl.cert) {
+ DWORD cert_store_name;
+ TCHAR *cert_store_path;
+ TCHAR *cert_thumbprint_str;
+ CRYPT_HASH_BLOB cert_thumbprint;
+ BYTE cert_thumbprint_data[CERT_THUMBPRINT_DATA_LEN];
+ HCERTSTORE cert_store;
+
+ TCHAR *cert_path = Curl_convert_UTF8_to_tchar(data->set.ssl.cert);
+ if(!cert_path)
+ return CURLE_OUT_OF_MEMORY;
+
+ result = get_cert_location(cert_path, &cert_store_name,
+ &cert_store_path, &cert_thumbprint_str);
+ if(result != CURLE_OK) {
+ failf(data, "schannel: Failed to get certificate location for %s",
+ cert_path);
+ Curl_unicodefree(cert_path);
+ return result;
+ }
+
+ cert_store =
+ CertOpenStore(CURL_CERT_STORE_PROV_SYSTEM, 0,
+ (HCRYPTPROV)NULL,
+ CERT_STORE_OPEN_EXISTING_FLAG | cert_store_name,
+ cert_store_path);
+ if(!cert_store) {
+ failf(data, "schannel: Failed to open cert store %x %s, "
+ "last error is %x",
+ cert_store_name, cert_store_path, GetLastError());
+ free(cert_store_path);
+ Curl_unicodefree(cert_path);
+ return CURLE_SSL_CERTPROBLEM;
+ }
+ free(cert_store_path);
+
+ cert_thumbprint.pbData = cert_thumbprint_data;
+ cert_thumbprint.cbData = CERT_THUMBPRINT_DATA_LEN;
+
+ if(!CryptStringToBinary(cert_thumbprint_str, CERT_THUMBPRINT_STR_LEN,
+ CRYPT_STRING_HEX,
+ cert_thumbprint_data, &cert_thumbprint.cbData,
+ NULL, NULL)) {
+ Curl_unicodefree(cert_path);
+ return CURLE_SSL_CERTPROBLEM;
+ }
+
+ client_certs[0] = CertFindCertificateInStore(
+ cert_store, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0,
+ CERT_FIND_HASH, &cert_thumbprint, NULL);
+
+ Curl_unicodefree(cert_path);
+
+ if(client_certs[0]) {
+ schannel_cred.cCreds = 1;
+ schannel_cred.paCred = client_certs;
+ }
+ else {
+ /* CRYPT_E_NOT_FOUND / E_INVALIDARG */
+ return CURLE_SSL_CERTPROBLEM;
+ }
+
+ CertCloseStore(cert_store, 0);
+ }
+#else
+ if(data->set.ssl.cert) {
+ failf(data, "schannel: client cert support not built in");
+ return CURLE_NOT_BUILT_IN;
+ }
+#endif
+
/* allocate memory for the re-usable credential handle */
- connssl->cred = (struct curl_schannel_cred *)
- malloc(sizeof(struct curl_schannel_cred));
- if(!connssl->cred) {
+ BACKEND->cred = (struct curl_schannel_cred *)
+ calloc(1, sizeof(struct curl_schannel_cred));
+ if(!BACKEND->cred) {
failf(data, "schannel: unable to allocate memory");
+
+ if(client_certs[0])
+ CertFreeCertificateContext(client_certs[0]);
+
return CURLE_OUT_OF_MEMORY;
}
- memset(connssl->cred, 0, sizeof(struct curl_schannel_cred));
- connssl->cred->refcount = 1;
+ BACKEND->cred->refcount = 1;
/* https://msdn.microsoft.com/en-us/library/windows/desktop/aa374716.aspx
*/
@@ -287,18 +680,28 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
s_pSecFn->AcquireCredentialsHandle(NULL, (TCHAR *)UNISP_NAME,
SECPKG_CRED_OUTBOUND, NULL,
&schannel_cred, NULL, NULL,
- &connssl->cred->cred_handle,
- &connssl->cred->time_stamp);
+ &BACKEND->cred->cred_handle,
+ &BACKEND->cred->time_stamp);
+
+ if(client_certs[0])
+ CertFreeCertificateContext(client_certs[0]);
if(sspi_status != SEC_E_OK) {
- if(sspi_status == SEC_E_WRONG_PRINCIPAL)
- failf(data, "schannel: SNI or certificate check failed: %s",
- Curl_sspi_strerror(conn, sspi_status));
- else
- failf(data, "schannel: AcquireCredentialsHandle failed: %s",
- Curl_sspi_strerror(conn, sspi_status));
- Curl_safefree(connssl->cred);
- return CURLE_SSL_CONNECT_ERROR;
+ char buffer[STRERROR_LEN];
+ failf(data, "schannel: AcquireCredentialsHandle failed: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ Curl_safefree(BACKEND->cred);
+ switch(sspi_status) {
+ case SEC_E_INSUFFICIENT_MEMORY:
+ return CURLE_OUT_OF_MEMORY;
+ case SEC_E_NO_CREDENTIALS:
+ case SEC_E_SECPKG_NOT_FOUND:
+ case SEC_E_NOT_OWNER:
+ case SEC_E_UNKNOWN_CREDENTIALS:
+ case SEC_E_INTERNAL_ERROR:
+ default:
+ return CURLE_SSL_CONNECT_ERROR;
+ }
}
}
@@ -312,7 +715,7 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
}
#ifdef HAS_ALPN
- if(connssl->use_alpn) {
+ if(BACKEND->use_alpn) {
int cur = 0;
int list_start_index = 0;
unsigned int *extension_len = NULL;
@@ -355,8 +758,7 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
InitSecBuffer(&inbuf, SECBUFFER_APPLICATION_PROTOCOLS, alpn_buffer, cur);
InitSecBufferDesc(&inbuf_desc, &inbuf, 1);
}
- else
- {
+ else {
InitSecBuffer(&inbuf, SECBUFFER_EMPTY, NULL, 0);
InitSecBufferDesc(&inbuf_desc, &inbuf, 1);
}
@@ -370,18 +772,17 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
InitSecBufferDesc(&outbuf_desc, &outbuf, 1);
/* setup request flags */
- connssl->req_flags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT |
+ BACKEND->req_flags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT |
ISC_REQ_CONFIDENTIALITY | ISC_REQ_ALLOCATE_MEMORY |
ISC_REQ_STREAM;
/* allocate memory for the security context handle */
- connssl->ctxt = (struct curl_schannel_ctxt *)
- malloc(sizeof(struct curl_schannel_ctxt));
- if(!connssl->ctxt) {
+ BACKEND->ctxt = (struct curl_schannel_ctxt *)
+ calloc(1, sizeof(struct curl_schannel_ctxt));
+ if(!BACKEND->ctxt) {
failf(data, "schannel: unable to allocate memory");
return CURLE_OUT_OF_MEMORY;
}
- memset(connssl->ctxt, 0, sizeof(struct curl_schannel_ctxt));
host_name = Curl_convert_UTF8_to_tchar(hostname);
if(!host_name)
@@ -395,26 +796,45 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
us problems with inbuf regardless. https://github.com/curl/curl/issues/983
*/
sspi_status = s_pSecFn->InitializeSecurityContext(
- &connssl->cred->cred_handle, NULL, host_name, connssl->req_flags, 0, 0,
- (connssl->use_alpn ? &inbuf_desc : NULL),
- 0, &connssl->ctxt->ctxt_handle,
- &outbuf_desc, &connssl->ret_flags, &connssl->ctxt->time_stamp);
+ &BACKEND->cred->cred_handle, NULL, host_name, BACKEND->req_flags, 0, 0,
+ (BACKEND->use_alpn ? &inbuf_desc : NULL),
+ 0, &BACKEND->ctxt->ctxt_handle,
+ &outbuf_desc, &BACKEND->ret_flags, &BACKEND->ctxt->time_stamp);
Curl_unicodefree(host_name);
if(sspi_status != SEC_I_CONTINUE_NEEDED) {
- if(sspi_status == SEC_E_WRONG_PRINCIPAL)
- failf(data, "schannel: SNI or certificate check failed: %s",
- Curl_sspi_strerror(conn, sspi_status));
- else
- failf(data, "schannel: initial InitializeSecurityContext failed: %s",
- Curl_sspi_strerror(conn, sspi_status));
- Curl_safefree(connssl->ctxt);
- return CURLE_SSL_CONNECT_ERROR;
+ char buffer[STRERROR_LEN];
+ Curl_safefree(BACKEND->ctxt);
+ switch(sspi_status) {
+ case SEC_E_INSUFFICIENT_MEMORY:
+ failf(data, "schannel: initial InitializeSecurityContext failed: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ return CURLE_OUT_OF_MEMORY;
+ case SEC_E_WRONG_PRINCIPAL:
+ failf(data, "schannel: SNI or certificate check failed: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ return CURLE_PEER_FAILED_VERIFICATION;
+ /*
+ case SEC_E_INVALID_HANDLE:
+ case SEC_E_INVALID_TOKEN:
+ case SEC_E_LOGON_DENIED:
+ case SEC_E_TARGET_UNKNOWN:
+ case SEC_E_NO_AUTHENTICATING_AUTHORITY:
+ case SEC_E_INTERNAL_ERROR:
+ case SEC_E_NO_CREDENTIALS:
+ case SEC_E_UNSUPPORTED_FUNCTION:
+ case SEC_E_APPLICATION_PROTOCOL_MISMATCH:
+ */
+ default:
+ failf(data, "schannel: initial InitializeSecurityContext failed: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ return CURLE_SSL_CONNECT_ERROR;
+ }
}
- infof(data, "schannel: sending initial handshake data: "
- "sending %lu bytes...\n", outbuf.cbBuffer);
+ DEBUGF(infof(data, "schannel: sending initial handshake data: "
+ "sending %lu bytes...\n", outbuf.cbBuffer));
/* send initial handshake data which is now stored in output buffer */
result = Curl_write_plain(conn, conn->sock[sockindex], outbuf.pvBuffer,
@@ -426,13 +846,13 @@ schannel_connect_step1(struct connectdata *conn, int sockindex)
return CURLE_SSL_CONNECT_ERROR;
}
- infof(data, "schannel: sent initial handshake data: "
- "sent %zd bytes\n", written);
+ DEBUGF(infof(data, "schannel: sent initial handshake data: "
+ "sent %zd bytes\n", written));
- connssl->recv_unrecoverable_err = CURLE_OK;
- connssl->recv_sspi_close_notify = false;
- connssl->recv_connection_closed = false;
- connssl->encdata_is_incomplete = false;
+ BACKEND->recv_unrecoverable_err = CURLE_OK;
+ BACKEND->recv_sspi_close_notify = false;
+ BACKEND->recv_connection_closed = false;
+ BACKEND->encdata_is_incomplete = false;
/* continue to second handshake step */
connssl->connecting_state = ssl_connect_2;
@@ -448,56 +868,56 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
struct Curl_easy *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
unsigned char *reallocated_buffer;
- size_t reallocated_length;
SecBuffer outbuf[3];
SecBufferDesc outbuf_desc;
SecBuffer inbuf[2];
SecBufferDesc inbuf_desc;
SECURITY_STATUS sspi_status = SEC_E_OK;
- TCHAR *host_name;
CURLcode result;
bool doread;
char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
+ const char *pubkey_ptr;
doread = (connssl->connecting_state != ssl_connect_2_writing) ? TRUE : FALSE;
- infof(data, "schannel: SSL/TLS connection with %s port %hu (step 2/3)\n",
- hostname, conn->remote_port);
+ DEBUGF(infof(data,
+ "schannel: SSL/TLS connection with %s port %hu (step 2/3)\n",
+ hostname, conn->remote_port));
- if(!connssl->cred || !connssl->ctxt)
+ if(!BACKEND->cred || !BACKEND->ctxt)
return CURLE_SSL_CONNECT_ERROR;
/* buffer to store previously received and decrypted data */
- if(connssl->decdata_buffer == NULL) {
- connssl->decdata_offset = 0;
- connssl->decdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE;
- connssl->decdata_buffer = malloc(connssl->decdata_length);
- if(connssl->decdata_buffer == NULL) {
+ if(BACKEND->decdata_buffer == NULL) {
+ BACKEND->decdata_offset = 0;
+ BACKEND->decdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE;
+ BACKEND->decdata_buffer = malloc(BACKEND->decdata_length);
+ if(BACKEND->decdata_buffer == NULL) {
failf(data, "schannel: unable to allocate memory");
return CURLE_OUT_OF_MEMORY;
}
}
/* buffer to store previously received and encrypted data */
- if(connssl->encdata_buffer == NULL) {
- connssl->encdata_is_incomplete = false;
- connssl->encdata_offset = 0;
- connssl->encdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE;
- connssl->encdata_buffer = malloc(connssl->encdata_length);
- if(connssl->encdata_buffer == NULL) {
+ if(BACKEND->encdata_buffer == NULL) {
+ BACKEND->encdata_is_incomplete = false;
+ BACKEND->encdata_offset = 0;
+ BACKEND->encdata_length = CURL_SCHANNEL_BUFFER_INIT_SIZE;
+ BACKEND->encdata_buffer = malloc(BACKEND->encdata_length);
+ if(BACKEND->encdata_buffer == NULL) {
failf(data, "schannel: unable to allocate memory");
return CURLE_OUT_OF_MEMORY;
}
}
/* if we need a bigger buffer to read a full message, increase buffer now */
- if(connssl->encdata_length - connssl->encdata_offset <
+ if(BACKEND->encdata_length - BACKEND->encdata_offset <
CURL_SCHANNEL_BUFFER_FREE_SIZE) {
/* increase internal encrypted data buffer */
- reallocated_length = connssl->encdata_offset +
+ size_t reallocated_length = BACKEND->encdata_offset +
CURL_SCHANNEL_BUFFER_FREE_SIZE;
- reallocated_buffer = realloc(connssl->encdata_buffer,
+ reallocated_buffer = realloc(BACKEND->encdata_buffer,
reallocated_length);
if(reallocated_buffer == NULL) {
@@ -505,25 +925,26 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
return CURLE_OUT_OF_MEMORY;
}
else {
- connssl->encdata_buffer = reallocated_buffer;
- connssl->encdata_length = reallocated_length;
+ BACKEND->encdata_buffer = reallocated_buffer;
+ BACKEND->encdata_length = reallocated_length;
}
}
for(;;) {
+ TCHAR *host_name;
if(doread) {
/* read encrypted handshake data from socket */
result = Curl_read_plain(conn->sock[sockindex],
- (char *) (connssl->encdata_buffer +
- connssl->encdata_offset),
- connssl->encdata_length -
- connssl->encdata_offset,
+ (char *) (BACKEND->encdata_buffer +
+ BACKEND->encdata_offset),
+ BACKEND->encdata_length -
+ BACKEND->encdata_offset,
&nread);
if(result == CURLE_AGAIN) {
if(connssl->connecting_state != ssl_connect_2_writing)
connssl->connecting_state = ssl_connect_2_reading;
- infof(data, "schannel: failed to receive handshake, "
- "need more data\n");
+ DEBUGF(infof(data, "schannel: failed to receive handshake, "
+ "need more data\n"));
return CURLE_OK;
}
else if((result != CURLE_OK) || (nread == 0)) {
@@ -533,17 +954,18 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
}
/* increase encrypted data buffer offset */
- connssl->encdata_offset += nread;
- connssl->encdata_is_incomplete = false;
- infof(data, "schannel: encrypted data got %zd\n", nread);
+ BACKEND->encdata_offset += nread;
+ BACKEND->encdata_is_incomplete = false;
+ DEBUGF(infof(data, "schannel: encrypted data got %zd\n", nread));
}
- infof(data, "schannel: encrypted data buffer: offset %zu length %zu\n",
- connssl->encdata_offset, connssl->encdata_length);
+ DEBUGF(infof(data,
+ "schannel: encrypted data buffer: offset %zu length %zu\n",
+ BACKEND->encdata_offset, BACKEND->encdata_length));
/* setup input buffers */
- InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, malloc(connssl->encdata_offset),
- curlx_uztoul(connssl->encdata_offset));
+ InitSecBuffer(&inbuf[0], SECBUFFER_TOKEN, malloc(BACKEND->encdata_offset),
+ curlx_uztoul(BACKEND->encdata_offset));
InitSecBuffer(&inbuf[1], SECBUFFER_EMPTY, NULL, 0);
InitSecBufferDesc(&inbuf_desc, inbuf, 2);
@@ -559,8 +981,8 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
}
/* copy received handshake data into input buffer */
- memcpy(inbuf[0].pvBuffer, connssl->encdata_buffer,
- connssl->encdata_offset);
+ memcpy(inbuf[0].pvBuffer, BACKEND->encdata_buffer,
+ BACKEND->encdata_offset);
host_name = Curl_convert_UTF8_to_tchar(hostname);
if(!host_name)
@@ -569,9 +991,9 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
/* https://msdn.microsoft.com/en-us/library/windows/desktop/aa375924.aspx
*/
sspi_status = s_pSecFn->InitializeSecurityContext(
- &connssl->cred->cred_handle, &connssl->ctxt->ctxt_handle,
- host_name, connssl->req_flags, 0, 0, &inbuf_desc, 0, NULL,
- &outbuf_desc, &connssl->ret_flags, &connssl->ctxt->time_stamp);
+ &BACKEND->cred->cred_handle, &BACKEND->ctxt->ctxt_handle,
+ host_name, BACKEND->req_flags, 0, 0, &inbuf_desc, 0, NULL,
+ &outbuf_desc, &BACKEND->ret_flags, &BACKEND->ctxt->time_stamp);
Curl_unicodefree(host_name);
@@ -580,9 +1002,10 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
/* check if the handshake was incomplete */
if(sspi_status == SEC_E_INCOMPLETE_MESSAGE) {
- connssl->encdata_is_incomplete = true;
+ BACKEND->encdata_is_incomplete = true;
connssl->connecting_state = ssl_connect_2_reading;
- infof(data, "schannel: received incomplete message, need more data\n");
+ DEBUGF(infof(data,
+ "schannel: received incomplete message, need more data\n"));
return CURLE_OK;
}
@@ -590,10 +1013,11 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
the handshake without one. This will allow connections to servers which
request a client certificate but do not require it. */
if(sspi_status == SEC_I_INCOMPLETE_CREDENTIALS &&
- !(connssl->req_flags & ISC_REQ_USE_SUPPLIED_CREDS)) {
- connssl->req_flags |= ISC_REQ_USE_SUPPLIED_CREDS;
+ !(BACKEND->req_flags & ISC_REQ_USE_SUPPLIED_CREDS)) {
+ BACKEND->req_flags |= ISC_REQ_USE_SUPPLIED_CREDS;
connssl->connecting_state = ssl_connect_2_writing;
- infof(data, "schannel: a client certificate has been requested\n");
+ DEBUGF(infof(data,
+ "schannel: a client certificate has been requested\n"));
return CURLE_OK;
}
@@ -602,8 +1026,8 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
for(i = 0; i < 3; i++) {
/* search for handshake tokens that need to be send */
if(outbuf[i].BufferType == SECBUFFER_TOKEN && outbuf[i].cbBuffer > 0) {
- infof(data, "schannel: sending next handshake data: "
- "sending %lu bytes...\n", outbuf[i].cbBuffer);
+ DEBUGF(infof(data, "schannel: sending next handshake data: "
+ "sending %lu bytes...\n", outbuf[i].cbBuffer));
/* send handshake token to server */
result = Curl_write_plain(conn, conn->sock[sockindex],
@@ -624,19 +1048,38 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
}
}
else {
- if(sspi_status == SEC_E_WRONG_PRINCIPAL)
- failf(data, "schannel: SNI or certificate check failed: %s",
- Curl_sspi_strerror(conn, sspi_status));
- else
- failf(data, "schannel: next InitializeSecurityContext failed: %s",
- Curl_sspi_strerror(conn, sspi_status));
- return sspi_status == SEC_E_UNTRUSTED_ROOT ?
- CURLE_SSL_CACERT_BADFILE : CURLE_SSL_CONNECT_ERROR;
+ char buffer[STRERROR_LEN];
+ switch(sspi_status) {
+ case SEC_E_INSUFFICIENT_MEMORY:
+ failf(data, "schannel: next InitializeSecurityContext failed: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ return CURLE_OUT_OF_MEMORY;
+ case SEC_E_WRONG_PRINCIPAL:
+ failf(data, "schannel: SNI or certificate check failed: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ return CURLE_PEER_FAILED_VERIFICATION;
+ /*
+ case SEC_E_INVALID_HANDLE:
+ case SEC_E_INVALID_TOKEN:
+ case SEC_E_LOGON_DENIED:
+ case SEC_E_TARGET_UNKNOWN:
+ case SEC_E_NO_AUTHENTICATING_AUTHORITY:
+ case SEC_E_INTERNAL_ERROR:
+ case SEC_E_NO_CREDENTIALS:
+ case SEC_E_UNSUPPORTED_FUNCTION:
+ case SEC_E_APPLICATION_PROTOCOL_MISMATCH:
+ */
+ default:
+ failf(data, "schannel: next InitializeSecurityContext failed: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ return CURLE_SSL_CONNECT_ERROR;
+ }
}
/* check if there was additional remaining encrypted data */
if(inbuf[1].BufferType == SECBUFFER_EXTRA && inbuf[1].cbBuffer > 0) {
- infof(data, "schannel: encrypted data length: %lu\n", inbuf[1].cbBuffer);
+ DEBUGF(infof(data, "schannel: encrypted data length: %lu\n",
+ inbuf[1].cbBuffer));
/*
There are two cases where we could be getting extra data here:
1) If we're renegotiating a connection and the handshake is already
@@ -649,11 +1092,11 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
*/
/* check if the remaining data is less than the total amount
and therefore begins after the already processed data */
- if(connssl->encdata_offset > inbuf[1].cbBuffer) {
- memmove(connssl->encdata_buffer,
- (connssl->encdata_buffer + connssl->encdata_offset) -
+ if(BACKEND->encdata_offset > inbuf[1].cbBuffer) {
+ memmove(BACKEND->encdata_buffer,
+ (BACKEND->encdata_buffer + BACKEND->encdata_offset) -
inbuf[1].cbBuffer, inbuf[1].cbBuffer);
- connssl->encdata_offset = inbuf[1].cbBuffer;
+ BACKEND->encdata_offset = inbuf[1].cbBuffer;
if(sspi_status == SEC_I_CONTINUE_NEEDED) {
doread = FALSE;
continue;
@@ -661,7 +1104,7 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
}
}
else {
- connssl->encdata_offset = 0;
+ BACKEND->encdata_offset = 0;
}
break;
}
@@ -675,19 +1118,84 @@ schannel_connect_step2(struct connectdata *conn, int sockindex)
/* check if the handshake is complete */
if(sspi_status == SEC_E_OK) {
connssl->connecting_state = ssl_connect_3;
- infof(data, "schannel: SSL/TLS handshake complete\n");
+ DEBUGF(infof(data, "schannel: SSL/TLS handshake complete\n"));
}
-#ifdef _WIN32_WCE
- /* Windows CE doesn't do any server certificate validation.
- We have to do it manually. */
- if(conn->ssl_config.verifypeer)
- return verify_certificate(conn, sockindex);
+ pubkey_ptr = SSL_IS_PROXY() ?
+ data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
+ data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG];
+ if(pubkey_ptr) {
+ result = pkp_pin_peer_pubkey(conn, sockindex, pubkey_ptr);
+ if(result) {
+ failf(data, "SSL: public key does not match pinned public key!");
+ return result;
+ }
+ }
+
+#ifdef HAS_MANUAL_VERIFY_API
+ if(conn->ssl_config.verifypeer && BACKEND->use_manual_cred_validation) {
+ return Curl_verify_certificate(conn, sockindex);
+ }
#endif
return CURLE_OK;
}
+static bool
+valid_cert_encoding(const CERT_CONTEXT *cert_context)
+{
+ return (cert_context != NULL) &&
+ ((cert_context->dwCertEncodingType & X509_ASN_ENCODING) != 0) &&
+ (cert_context->pbCertEncoded != NULL) &&
+ (cert_context->cbCertEncoded > 0);
+}
+
+typedef bool(*Read_crt_func)(const CERT_CONTEXT *ccert_context, void *arg);
+
+static void
+traverse_cert_store(const CERT_CONTEXT *context, Read_crt_func func,
+ void *arg)
+{
+ const CERT_CONTEXT *current_context = NULL;
+ bool should_continue = true;
+ while(should_continue &&
+ (current_context = CertEnumCertificatesInStore(
+ context->hCertStore,
+ current_context)) != NULL)
+ should_continue = func(current_context, arg);
+
+ if(current_context)
+ CertFreeCertificateContext(current_context);
+}
+
+static bool
+cert_counter_callback(const CERT_CONTEXT *ccert_context, void *certs_count)
+{
+ if(valid_cert_encoding(ccert_context))
+ (*(int *)certs_count)++;
+ return true;
+}
+
+struct Adder_args
+{
+ struct connectdata *conn;
+ CURLcode result;
+ int idx;
+};
+
+static bool
+add_cert_to_certinfo(const CERT_CONTEXT *ccert_context, void *raw_arg)
+{
+ struct Adder_args *args = (struct Adder_args*)raw_arg;
+ args->result = CURLE_OK;
+ if(valid_cert_encoding(ccert_context)) {
+ const char *beg = (const char *) ccert_context->pbCertEncoded;
+ const char *end = beg + ccert_context->cbCertEncoded;
+ args->result = Curl_extract_certinfo(args->conn, (args->idx)++, beg, end);
+ }
+ return args->result == CURLE_OK;
+}
+
static CURLcode
schannel_connect_step3(struct connectdata *conn, int sockindex)
{
@@ -696,7 +1204,7 @@ schannel_connect_step3(struct connectdata *conn, int sockindex)
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
SECURITY_STATUS sspi_status = SEC_E_OK;
CERT_CONTEXT *ccert_context = NULL;
-#ifndef CURL_DISABLE_VERBOSE_STRINGS
+#ifdef DEBUGBUILD
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
#endif
@@ -706,30 +1214,31 @@ schannel_connect_step3(struct connectdata *conn, int sockindex)
DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
- infof(data, "schannel: SSL/TLS connection with %s port %hu (step 3/3)\n",
- hostname, conn->remote_port);
+ DEBUGF(infof(data,
+ "schannel: SSL/TLS connection with %s port %hu (step 3/3)\n",
+ hostname, conn->remote_port));
- if(!connssl->cred)
+ if(!BACKEND->cred)
return CURLE_SSL_CONNECT_ERROR;
/* check if the required context attributes are met */
- if(connssl->ret_flags != connssl->req_flags) {
- if(!(connssl->ret_flags & ISC_RET_SEQUENCE_DETECT))
+ if(BACKEND->ret_flags != BACKEND->req_flags) {
+ if(!(BACKEND->ret_flags & ISC_RET_SEQUENCE_DETECT))
failf(data, "schannel: failed to setup sequence detection");
- if(!(connssl->ret_flags & ISC_RET_REPLAY_DETECT))
+ if(!(BACKEND->ret_flags & ISC_RET_REPLAY_DETECT))
failf(data, "schannel: failed to setup replay detection");
- if(!(connssl->ret_flags & ISC_RET_CONFIDENTIALITY))
+ if(!(BACKEND->ret_flags & ISC_RET_CONFIDENTIALITY))
failf(data, "schannel: failed to setup confidentiality");
- if(!(connssl->ret_flags & ISC_RET_ALLOCATED_MEMORY))
+ if(!(BACKEND->ret_flags & ISC_RET_ALLOCATED_MEMORY))
failf(data, "schannel: failed to setup memory allocation");
- if(!(connssl->ret_flags & ISC_RET_STREAM))
+ if(!(BACKEND->ret_flags & ISC_RET_STREAM))
failf(data, "schannel: failed to setup stream orientation");
return CURLE_SSL_CONNECT_ERROR;
}
#ifdef HAS_ALPN
- if(connssl->use_alpn) {
- sspi_status = s_pSecFn->QueryContextAttributes(&connssl->ctxt->ctxt_handle,
+ if(BACKEND->use_alpn) {
+ sspi_status = s_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
SECPKG_ATTR_APPLICATION_PROTOCOL, &alpn_result);
if(sspi_status != SEC_E_OK) {
@@ -759,6 +1268,8 @@ schannel_connect_step3(struct connectdata *conn, int sockindex)
}
else
infof(data, "ALPN, server did not agree to a protocol\n");
+ Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
+ BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
}
#endif
@@ -771,15 +1282,16 @@ schannel_connect_step3(struct connectdata *conn, int sockindex)
incache = !(Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL,
sockindex));
if(incache) {
- if(old_cred != connssl->cred) {
- infof(data, "schannel: old credential handle is stale, removing\n");
+ if(old_cred != BACKEND->cred) {
+ DEBUGF(infof(data,
+ "schannel: old credential handle is stale, removing\n"));
/* we're not taking old_cred ownership here, no refcount++ is needed */
Curl_ssl_delsessionid(conn, (void *)old_cred);
incache = FALSE;
}
}
if(!incache) {
- result = Curl_ssl_addsessionid(conn, (void *)connssl->cred,
+ result = Curl_ssl_addsessionid(conn, (void *)BACKEND->cred,
sizeof(struct curl_schannel_cred),
sockindex);
if(result) {
@@ -789,31 +1301,33 @@ schannel_connect_step3(struct connectdata *conn, int sockindex)
}
else {
/* this cred session is now also referenced by sessionid cache */
- connssl->cred->refcount++;
- infof(data, "schannel: stored credential handle in session cache\n");
+ BACKEND->cred->refcount++;
+ DEBUGF(infof(data,
+ "schannel: stored credential handle in session cache\n"));
}
}
Curl_ssl_sessionid_unlock(conn);
}
if(data->set.ssl.certinfo) {
- sspi_status = s_pSecFn->QueryContextAttributes(&connssl->ctxt->ctxt_handle,
+ int certs_count = 0;
+ sspi_status = s_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
SECPKG_ATTR_REMOTE_CERT_CONTEXT, &ccert_context);
if((sspi_status != SEC_E_OK) || (ccert_context == NULL)) {
failf(data, "schannel: failed to retrieve remote cert context");
- return CURLE_SSL_CONNECT_ERROR;
+ return CURLE_PEER_FAILED_VERIFICATION;
}
- result = Curl_ssl_init_certinfo(data, 1);
- if(!result) {
- if(((ccert_context->dwCertEncodingType & X509_ASN_ENCODING) != 0) &&
- (ccert_context->cbCertEncoded > 0)) {
+ traverse_cert_store(ccert_context, cert_counter_callback, &certs_count);
- const char *beg = (const char *) ccert_context->pbCertEncoded;
- const char *end = beg + ccert_context->cbCertEncoded;
- result = Curl_extract_certinfo(conn, 0, beg, end);
- }
+ result = Curl_ssl_init_certinfo(data, certs_count);
+ if(!result) {
+ struct Adder_args args;
+ args.conn = conn;
+ args.idx = 0;
+ traverse_cert_store(ccert_context, add_cert_to_certinfo, &args);
+ result = args.result;
}
CertFreeCertificateContext(ccert_context);
if(result)
@@ -926,6 +1440,16 @@ schannel_connect_common(struct connectdata *conn, int sockindex,
connssl->state = ssl_connection_complete;
conn->recv[sockindex] = schannel_recv;
conn->send[sockindex] = schannel_send;
+
+#ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
+ /* When SSPI is used in combination with Schannel
+ * we need the Schannel context to create the Schannel
+ * binding to pass the IIS extended protection checks.
+ * Available on Windows 7 or later.
+ */
+ conn->sslContext = &BACKEND->ctxt->ctxt_handle;
+#endif
+
*done = TRUE;
}
else
@@ -951,11 +1475,11 @@ schannel_send(struct connectdata *conn, int sockindex,
CURLcode result;
/* check if the maximum stream sizes were queried */
- if(connssl->stream_sizes.cbMaximumMessage == 0) {
+ if(BACKEND->stream_sizes.cbMaximumMessage == 0) {
sspi_status = s_pSecFn->QueryContextAttributes(
- &connssl->ctxt->ctxt_handle,
+ &BACKEND->ctxt->ctxt_handle,
SECPKG_ATTR_STREAM_SIZES,
- &connssl->stream_sizes);
+ &BACKEND->stream_sizes);
if(sspi_status != SEC_E_OK) {
*err = CURLE_SEND_ERROR;
return -1;
@@ -963,14 +1487,13 @@ schannel_send(struct connectdata *conn, int sockindex,
}
/* check if the buffer is longer than the maximum message length */
- if(len > connssl->stream_sizes.cbMaximumMessage) {
- *err = CURLE_SEND_ERROR;
- return -1;
+ if(len > BACKEND->stream_sizes.cbMaximumMessage) {
+ len = BACKEND->stream_sizes.cbMaximumMessage;
}
/* calculate the complete message length and allocate a buffer for it */
- data_len = connssl->stream_sizes.cbHeader + len +
- connssl->stream_sizes.cbTrailer;
+ data_len = BACKEND->stream_sizes.cbHeader + len +
+ BACKEND->stream_sizes.cbTrailer;
data = (unsigned char *) malloc(data_len);
if(data == NULL) {
*err = CURLE_OUT_OF_MEMORY;
@@ -979,12 +1502,12 @@ schannel_send(struct connectdata *conn, int sockindex,
/* setup output buffers (header, data, trailer, empty) */
InitSecBuffer(&outbuf[0], SECBUFFER_STREAM_HEADER,
- data, connssl->stream_sizes.cbHeader);
+ data, BACKEND->stream_sizes.cbHeader);
InitSecBuffer(&outbuf[1], SECBUFFER_DATA,
- data + connssl->stream_sizes.cbHeader, curlx_uztoul(len));
+ data + BACKEND->stream_sizes.cbHeader, curlx_uztoul(len));
InitSecBuffer(&outbuf[2], SECBUFFER_STREAM_TRAILER,
- data + connssl->stream_sizes.cbHeader + len,
- connssl->stream_sizes.cbTrailer);
+ data + BACKEND->stream_sizes.cbHeader + len,
+ BACKEND->stream_sizes.cbTrailer);
InitSecBuffer(&outbuf[3], SECBUFFER_EMPTY, NULL, 0);
InitSecBufferDesc(&outbuf_desc, outbuf, 4);
@@ -992,7 +1515,7 @@ schannel_send(struct connectdata *conn, int sockindex,
memcpy(outbuf[1].pvBuffer, buf, len);
/* https://msdn.microsoft.com/en-us/library/windows/desktop/aa375390.aspx */
- sspi_status = s_pSecFn->EncryptMessage(&connssl->ctxt->ctxt_handle, 0,
+ sspi_status = s_pSecFn->EncryptMessage(&BACKEND->ctxt->ctxt_handle, 0,
&outbuf_desc, 0);
/* check if the message was encrypted */
@@ -1102,7 +1625,7 @@ schannel_recv(struct connectdata *conn, int sockindex,
size_t min_encdata_length = len + CURL_SCHANNEL_BUFFER_FREE_SIZE;
/****************************************************************************
- * Don't return or set connssl->recv_unrecoverable_err unless in the cleanup.
+ * Don't return or set BACKEND->recv_unrecoverable_err unless in the cleanup.
* The pattern for return error is set *err, optional infof, goto cleanup.
*
* Our priority is to always return as much decrypted data to the caller as
@@ -1111,19 +1634,19 @@ schannel_recv(struct connectdata *conn, int sockindex,
* handled in the cleanup.
*/
- infof(data, "schannel: client wants to read %zu bytes\n", len);
+ DEBUGF(infof(data, "schannel: client wants to read %zu bytes\n", len));
*err = CURLE_OK;
- if(len && len <= connssl->decdata_offset) {
+ if(len && len <= BACKEND->decdata_offset) {
infof(data, "schannel: enough decrypted data is already available\n");
goto cleanup;
}
- else if(connssl->recv_unrecoverable_err) {
- *err = connssl->recv_unrecoverable_err;
+ else if(BACKEND->recv_unrecoverable_err) {
+ *err = BACKEND->recv_unrecoverable_err;
infof(data, "schannel: an unrecoverable error occurred in a prior call\n");
goto cleanup;
}
- else if(connssl->recv_sspi_close_notify) {
+ else if(BACKEND->recv_sspi_close_notify) {
/* once a server has indicated shutdown there is no more encrypted data */
infof(data, "schannel: server indicated shutdown in a prior call\n");
goto cleanup;
@@ -1135,17 +1658,17 @@ schannel_recv(struct connectdata *conn, int sockindex,
*/
; /* do nothing */
}
- else if(!connssl->recv_connection_closed) {
+ else if(!BACKEND->recv_connection_closed) {
/* increase enc buffer in order to fit the requested amount of data */
- size = connssl->encdata_length - connssl->encdata_offset;
+ size = BACKEND->encdata_length - BACKEND->encdata_offset;
if(size < CURL_SCHANNEL_BUFFER_FREE_SIZE ||
- connssl->encdata_length < min_encdata_length) {
- reallocated_length = connssl->encdata_offset +
+ BACKEND->encdata_length < min_encdata_length) {
+ reallocated_length = BACKEND->encdata_offset +
CURL_SCHANNEL_BUFFER_FREE_SIZE;
if(reallocated_length < min_encdata_length) {
reallocated_length = min_encdata_length;
}
- reallocated_buffer = realloc(connssl->encdata_buffer,
+ reallocated_buffer = realloc(BACKEND->encdata_buffer,
reallocated_length);
if(reallocated_buffer == NULL) {
*err = CURLE_OUT_OF_MEMORY;
@@ -1153,51 +1676,54 @@ schannel_recv(struct connectdata *conn, int sockindex,
goto cleanup;
}
- connssl->encdata_buffer = reallocated_buffer;
- connssl->encdata_length = reallocated_length;
- size = connssl->encdata_length - connssl->encdata_offset;
- infof(data, "schannel: encdata_buffer resized %zu\n",
- connssl->encdata_length);
+ BACKEND->encdata_buffer = reallocated_buffer;
+ BACKEND->encdata_length = reallocated_length;
+ size = BACKEND->encdata_length - BACKEND->encdata_offset;
+ DEBUGF(infof(data, "schannel: encdata_buffer resized %zu\n",
+ BACKEND->encdata_length));
}
- infof(data, "schannel: encrypted data buffer: offset %zu length %zu\n",
- connssl->encdata_offset, connssl->encdata_length);
+ DEBUGF(infof(data,
+ "schannel: encrypted data buffer: offset %zu length %zu\n",
+ BACKEND->encdata_offset, BACKEND->encdata_length));
/* read encrypted data from socket */
*err = Curl_read_plain(conn->sock[sockindex],
- (char *)(connssl->encdata_buffer +
- connssl->encdata_offset),
+ (char *)(BACKEND->encdata_buffer +
+ BACKEND->encdata_offset),
size, &nread);
if(*err) {
nread = -1;
if(*err == CURLE_AGAIN)
- infof(data, "schannel: Curl_read_plain returned CURLE_AGAIN\n");
+ DEBUGF(infof(data,
+ "schannel: Curl_read_plain returned CURLE_AGAIN\n"));
else if(*err == CURLE_RECV_ERROR)
infof(data, "schannel: Curl_read_plain returned CURLE_RECV_ERROR\n");
else
infof(data, "schannel: Curl_read_plain returned error %d\n", *err);
}
else if(nread == 0) {
- connssl->recv_connection_closed = true;
- infof(data, "schannel: server closed the connection\n");
+ BACKEND->recv_connection_closed = true;
+ DEBUGF(infof(data, "schannel: server closed the connection\n"));
}
else if(nread > 0) {
- connssl->encdata_offset += (size_t)nread;
- connssl->encdata_is_incomplete = false;
- infof(data, "schannel: encrypted data got %zd\n", nread);
+ BACKEND->encdata_offset += (size_t)nread;
+ BACKEND->encdata_is_incomplete = false;
+ DEBUGF(infof(data, "schannel: encrypted data got %zd\n", nread));
}
}
- infof(data, "schannel: encrypted data buffer: offset %zu length %zu\n",
- connssl->encdata_offset, connssl->encdata_length);
+ DEBUGF(infof(data,
+ "schannel: encrypted data buffer: offset %zu length %zu\n",
+ BACKEND->encdata_offset, BACKEND->encdata_length));
/* decrypt loop */
- while(connssl->encdata_offset > 0 && sspi_status == SEC_E_OK &&
- (!len || connssl->decdata_offset < len ||
- connssl->recv_connection_closed)) {
+ while(BACKEND->encdata_offset > 0 && sspi_status == SEC_E_OK &&
+ (!len || BACKEND->decdata_offset < len ||
+ BACKEND->recv_connection_closed)) {
/* prepare data buffer for DecryptMessage call */
- InitSecBuffer(&inbuf[0], SECBUFFER_DATA, connssl->encdata_buffer,
- curlx_uztoul(connssl->encdata_offset));
+ InitSecBuffer(&inbuf[0], SECBUFFER_DATA, BACKEND->encdata_buffer,
+ curlx_uztoul(BACKEND->encdata_offset));
/* we need 3 more empty input buffers for possible output */
InitSecBuffer(&inbuf[1], SECBUFFER_EMPTY, NULL, 0);
@@ -1207,7 +1733,7 @@ schannel_recv(struct connectdata *conn, int sockindex,
/* https://msdn.microsoft.com/en-us/library/windows/desktop/aa375348.aspx
*/
- sspi_status = s_pSecFn->DecryptMessage(&connssl->ctxt->ctxt_handle,
+ sspi_status = s_pSecFn->DecryptMessage(&BACKEND->ctxt->ctxt_handle,
&inbuf_desc, 0, NULL);
/* check if everything went fine (server may want to renegotiate
@@ -1217,67 +1743,69 @@ schannel_recv(struct connectdata *conn, int sockindex,
/* check for successfully decrypted data, even before actual
renegotiation or shutdown of the connection context */
if(inbuf[1].BufferType == SECBUFFER_DATA) {
- infof(data, "schannel: decrypted data length: %lu\n",
- inbuf[1].cbBuffer);
+ DEBUGF(infof(data, "schannel: decrypted data length: %lu\n",
+ inbuf[1].cbBuffer));
/* increase buffer in order to fit the received amount of data */
size = inbuf[1].cbBuffer > CURL_SCHANNEL_BUFFER_FREE_SIZE ?
inbuf[1].cbBuffer : CURL_SCHANNEL_BUFFER_FREE_SIZE;
- if(connssl->decdata_length - connssl->decdata_offset < size ||
- connssl->decdata_length < len) {
+ if(BACKEND->decdata_length - BACKEND->decdata_offset < size ||
+ BACKEND->decdata_length < len) {
/* increase internal decrypted data buffer */
- reallocated_length = connssl->decdata_offset + size;
+ reallocated_length = BACKEND->decdata_offset + size;
/* make sure that the requested amount of data fits */
if(reallocated_length < len) {
reallocated_length = len;
}
- reallocated_buffer = realloc(connssl->decdata_buffer,
+ reallocated_buffer = realloc(BACKEND->decdata_buffer,
reallocated_length);
if(reallocated_buffer == NULL) {
*err = CURLE_OUT_OF_MEMORY;
failf(data, "schannel: unable to re-allocate memory");
goto cleanup;
}
- connssl->decdata_buffer = reallocated_buffer;
- connssl->decdata_length = reallocated_length;
+ BACKEND->decdata_buffer = reallocated_buffer;
+ BACKEND->decdata_length = reallocated_length;
}
/* copy decrypted data to internal buffer */
size = inbuf[1].cbBuffer;
if(size) {
- memcpy(connssl->decdata_buffer + connssl->decdata_offset,
+ memcpy(BACKEND->decdata_buffer + BACKEND->decdata_offset,
inbuf[1].pvBuffer, size);
- connssl->decdata_offset += size;
+ BACKEND->decdata_offset += size;
}
- infof(data, "schannel: decrypted data added: %zu\n", size);
- infof(data, "schannel: decrypted data cached: offset %zu length %zu\n",
- connssl->decdata_offset, connssl->decdata_length);
+ DEBUGF(infof(data, "schannel: decrypted data added: %zu\n", size));
+ DEBUGF(infof(data,
+ "schannel: decrypted cached: offset %zu length %zu\n",
+ BACKEND->decdata_offset, BACKEND->decdata_length));
}
/* check for remaining encrypted data */
if(inbuf[3].BufferType == SECBUFFER_EXTRA && inbuf[3].cbBuffer > 0) {
- infof(data, "schannel: encrypted data length: %lu\n",
- inbuf[3].cbBuffer);
+ DEBUGF(infof(data, "schannel: encrypted data length: %lu\n",
+ inbuf[3].cbBuffer));
/* check if the remaining data is less than the total amount
* and therefore begins after the already processed data
*/
- if(connssl->encdata_offset > inbuf[3].cbBuffer) {
+ if(BACKEND->encdata_offset > inbuf[3].cbBuffer) {
/* move remaining encrypted data forward to the beginning of
buffer */
- memmove(connssl->encdata_buffer,
- (connssl->encdata_buffer + connssl->encdata_offset) -
+ memmove(BACKEND->encdata_buffer,
+ (BACKEND->encdata_buffer + BACKEND->encdata_offset) -
inbuf[3].cbBuffer, inbuf[3].cbBuffer);
- connssl->encdata_offset = inbuf[3].cbBuffer;
+ BACKEND->encdata_offset = inbuf[3].cbBuffer;
}
- infof(data, "schannel: encrypted data cached: offset %zu length %zu\n",
- connssl->encdata_offset, connssl->encdata_length);
+ DEBUGF(infof(data,
+ "schannel: encrypted cached: offset %zu length %zu\n",
+ BACKEND->encdata_offset, BACKEND->encdata_length));
}
else {
/* reset encrypted buffer offset, because there is no data remaining */
- connssl->encdata_offset = 0;
+ BACKEND->encdata_offset = 0;
}
/* check if server wants to renegotiate the connection context */
@@ -1287,7 +1815,7 @@ schannel_recv(struct connectdata *conn, int sockindex,
infof(data, "schannel: can't renogotiate, an error is pending\n");
goto cleanup;
}
- if(connssl->encdata_offset) {
+ if(BACKEND->encdata_offset) {
*err = CURLE_RECV_ERROR;
infof(data, "schannel: can't renogotiate, "
"encrypted data available\n");
@@ -1311,38 +1839,41 @@ schannel_recv(struct connectdata *conn, int sockindex,
else if(sspi_status == SEC_I_CONTEXT_EXPIRED) {
/* In Windows 2000 SEC_I_CONTEXT_EXPIRED (close_notify) is not
returned so we have to work around that in cleanup. */
- connssl->recv_sspi_close_notify = true;
- if(!connssl->recv_connection_closed) {
- connssl->recv_connection_closed = true;
+ BACKEND->recv_sspi_close_notify = true;
+ if(!BACKEND->recv_connection_closed) {
+ BACKEND->recv_connection_closed = true;
infof(data, "schannel: server closed the connection\n");
}
goto cleanup;
}
}
else if(sspi_status == SEC_E_INCOMPLETE_MESSAGE) {
- connssl->encdata_is_incomplete = true;
+ BACKEND->encdata_is_incomplete = true;
if(!*err)
*err = CURLE_AGAIN;
infof(data, "schannel: failed to decrypt data, need more data\n");
goto cleanup;
}
else {
+ char buffer[STRERROR_LEN];
*err = CURLE_RECV_ERROR;
infof(data, "schannel: failed to read data from server: %s\n",
- Curl_sspi_strerror(conn, sspi_status));
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
goto cleanup;
}
}
- infof(data, "schannel: encrypted data buffer: offset %zu length %zu\n",
- connssl->encdata_offset, connssl->encdata_length);
+ DEBUGF(infof(data,
+ "schannel: encrypted data buffer: offset %zu length %zu\n",
+ BACKEND->encdata_offset, BACKEND->encdata_length));
- infof(data, "schannel: decrypted data buffer: offset %zu length %zu\n",
- connssl->decdata_offset, connssl->decdata_length);
+ DEBUGF(infof(data,
+ "schannel: decrypted data buffer: offset %zu length %zu\n",
+ BACKEND->decdata_offset, BACKEND->decdata_length));
cleanup:
/* Warning- there is no guarantee the encdata state is valid at this point */
- infof(data, "schannel: schannel_recv cleanup\n");
+ DEBUGF(infof(data, "schannel: schannel_recv cleanup\n"));
/* Error if the connection has closed without a close_notify.
Behavior here is a matter of debate. We don't want to be vulnerable to a
@@ -1352,13 +1883,13 @@ cleanup:
return close_notify. In that case if the connection was closed we assume it
was graceful (close_notify) since there doesn't seem to be a way to tell.
*/
- if(len && !connssl->decdata_offset && connssl->recv_connection_closed &&
- !connssl->recv_sspi_close_notify) {
+ if(len && !BACKEND->decdata_offset && BACKEND->recv_connection_closed &&
+ !BACKEND->recv_sspi_close_notify) {
bool isWin2k = Curl_verify_windows_version(5, 0, PLATFORM_WINNT,
VERSION_EQUAL);
if(isWin2k && sspi_status == SEC_E_OK)
- connssl->recv_sspi_close_notify = true;
+ BACKEND->recv_sspi_close_notify = true;
else {
*err = CURLE_RECV_ERROR;
infof(data, "schannel: server closed abruptly (missing close_notify)\n");
@@ -1367,23 +1898,23 @@ cleanup:
/* Any error other than CURLE_AGAIN is an unrecoverable error. */
if(*err && *err != CURLE_AGAIN)
- connssl->recv_unrecoverable_err = *err;
+ BACKEND->recv_unrecoverable_err = *err;
- size = len < connssl->decdata_offset ? len : connssl->decdata_offset;
+ size = len < BACKEND->decdata_offset ? len : BACKEND->decdata_offset;
if(size) {
- memcpy(buf, connssl->decdata_buffer, size);
- memmove(connssl->decdata_buffer, connssl->decdata_buffer + size,
- connssl->decdata_offset - size);
- connssl->decdata_offset -= size;
-
- infof(data, "schannel: decrypted data returned %zu\n", size);
- infof(data, "schannel: decrypted data buffer: offset %zu length %zu\n",
- connssl->decdata_offset, connssl->decdata_length);
+ memcpy(buf, BACKEND->decdata_buffer, size);
+ memmove(BACKEND->decdata_buffer, BACKEND->decdata_buffer + size,
+ BACKEND->decdata_offset - size);
+ BACKEND->decdata_offset -= size;
+ DEBUGF(infof(data, "schannel: decrypted data returned %zu\n", size));
+ DEBUGF(infof(data,
+ "schannel: decrypted data buffer: offset %zu length %zu\n",
+ BACKEND->decdata_offset, BACKEND->decdata_length));
*err = CURLE_OK;
return (ssize_t)size;
}
- if(!*err && !connssl->recv_connection_closed)
+ if(!*err && !BACKEND->recv_connection_closed)
*err = CURLE_AGAIN;
/* It's debatable what to return when !len. We could return whatever error we
@@ -1395,15 +1926,13 @@ cleanup:
return *err ? -1 : 0;
}
-CURLcode
-Curl_schannel_connect_nonblocking(struct connectdata *conn, int sockindex,
- bool *done)
+static CURLcode Curl_schannel_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
{
return schannel_connect_common(conn, sockindex, TRUE, done);
}
-CURLcode
-Curl_schannel_connect(struct connectdata *conn, int sockindex)
+static CURLcode Curl_schannel_connect(struct connectdata *conn, int sockindex)
{
CURLcode result;
bool done = FALSE;
@@ -1417,25 +1946,38 @@ Curl_schannel_connect(struct connectdata *conn, int sockindex)
return CURLE_OK;
}
-bool Curl_schannel_data_pending(const struct connectdata *conn, int sockindex)
+static bool Curl_schannel_data_pending(const struct connectdata *conn,
+ int sockindex)
{
const struct ssl_connect_data *connssl = &conn->ssl[sockindex];
if(connssl->use) /* SSL/TLS is in use */
- return (connssl->decdata_offset > 0 ||
- (connssl->encdata_offset > 0 && !connssl->encdata_is_incomplete));
+ return (BACKEND->decdata_offset > 0 ||
+ (BACKEND->encdata_offset > 0 && !BACKEND->encdata_is_incomplete));
else
return FALSE;
}
-void Curl_schannel_close(struct connectdata *conn, int sockindex)
+static void Curl_schannel_close(struct connectdata *conn, int sockindex)
{
if(conn->ssl[sockindex].use)
/* if the SSL/TLS channel hasn't been shut down yet, do that now. */
Curl_ssl_shutdown(conn, sockindex);
}
-int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
+static void Curl_schannel_session_free(void *ptr)
+{
+ /* this is expected to be called under sessionid lock */
+ struct curl_schannel_cred *cred = ptr;
+
+ cred->refcount--;
+ if(cred->refcount == 0) {
+ s_pSecFn->FreeCredentialsHandle(&cred->cred_handle);
+ Curl_safefree(cred);
+ }
+}
+
+static int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
{
/* See https://msdn.microsoft.com/en-us/library/windows/desktop/aa380138.aspx
* Shutting Down an Schannel Connection
@@ -1445,10 +1987,12 @@ int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
+ DEBUGASSERT(data);
+
infof(data, "schannel: shutting down SSL/TLS connection with %s port %hu\n",
hostname, conn->remote_port);
- if(connssl->cred && connssl->ctxt) {
+ if(BACKEND->cred && BACKEND->ctxt) {
SecBufferDesc BuffDesc;
SecBuffer Buffer;
SECURITY_STATUS sspi_status;
@@ -1461,12 +2005,14 @@ int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
InitSecBuffer(&Buffer, SECBUFFER_TOKEN, &dwshut, sizeof(dwshut));
InitSecBufferDesc(&BuffDesc, &Buffer, 1);
- sspi_status = s_pSecFn->ApplyControlToken(&connssl->ctxt->ctxt_handle,
+ sspi_status = s_pSecFn->ApplyControlToken(&BACKEND->ctxt->ctxt_handle,
&BuffDesc);
- if(sspi_status != SEC_E_OK)
+ if(sspi_status != SEC_E_OK) {
+ char buffer[STRERROR_LEN];
failf(data, "schannel: ApplyControlToken failure: %s",
- Curl_sspi_strerror(conn, sspi_status));
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ }
host_name = Curl_convert_UTF8_to_tchar(hostname);
if(!host_name)
@@ -1477,18 +2023,18 @@ int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
InitSecBufferDesc(&outbuf_desc, &outbuf, 1);
sspi_status = s_pSecFn->InitializeSecurityContext(
- &connssl->cred->cred_handle,
- &connssl->ctxt->ctxt_handle,
+ &BACKEND->cred->cred_handle,
+ &BACKEND->ctxt->ctxt_handle,
host_name,
- connssl->req_flags,
+ BACKEND->req_flags,
0,
0,
NULL,
0,
- &connssl->ctxt->ctxt_handle,
+ &BACKEND->ctxt->ctxt_handle,
&outbuf_desc,
- &connssl->ret_flags,
- &connssl->ctxt->time_stamp);
+ &BACKEND->ret_flags,
+ &BACKEND->ctxt->time_stamp);
Curl_unicodefree(host_name);
@@ -1507,71 +2053,67 @@ int Curl_schannel_shutdown(struct connectdata *conn, int sockindex)
}
/* free SSPI Schannel API security context handle */
- if(connssl->ctxt) {
- infof(data, "schannel: clear security context handle\n");
- s_pSecFn->DeleteSecurityContext(&connssl->ctxt->ctxt_handle);
- Curl_safefree(connssl->ctxt);
+ if(BACKEND->ctxt) {
+ DEBUGF(infof(data, "schannel: clear security context handle\n"));
+ s_pSecFn->DeleteSecurityContext(&BACKEND->ctxt->ctxt_handle);
+ Curl_safefree(BACKEND->ctxt);
}
/* free SSPI Schannel API credential handle */
- if(connssl->cred) {
+ if(BACKEND->cred) {
+ /*
+ * When this function is called from Curl_schannel_close() the connection
+ * might not have an associated transfer so the check for conn->data is
+ * necessary.
+ */
Curl_ssl_sessionid_lock(conn);
- Curl_schannel_session_free(connssl->cred);
+ Curl_schannel_session_free(BACKEND->cred);
Curl_ssl_sessionid_unlock(conn);
- connssl->cred = NULL;
+ BACKEND->cred = NULL;
}
/* free internal buffer for received encrypted data */
- if(connssl->encdata_buffer != NULL) {
- Curl_safefree(connssl->encdata_buffer);
- connssl->encdata_length = 0;
- connssl->encdata_offset = 0;
- connssl->encdata_is_incomplete = false;
+ if(BACKEND->encdata_buffer != NULL) {
+ Curl_safefree(BACKEND->encdata_buffer);
+ BACKEND->encdata_length = 0;
+ BACKEND->encdata_offset = 0;
+ BACKEND->encdata_is_incomplete = false;
}
/* free internal buffer for received decrypted data */
- if(connssl->decdata_buffer != NULL) {
- Curl_safefree(connssl->decdata_buffer);
- connssl->decdata_length = 0;
- connssl->decdata_offset = 0;
+ if(BACKEND->decdata_buffer != NULL) {
+ Curl_safefree(BACKEND->decdata_buffer);
+ BACKEND->decdata_length = 0;
+ BACKEND->decdata_offset = 0;
}
return CURLE_OK;
}
-void Curl_schannel_session_free(void *ptr)
-{
- /* this is expected to be called under sessionid lock */
- struct curl_schannel_cred *cred = ptr;
-
- cred->refcount--;
- if(cred->refcount == 0) {
- s_pSecFn->FreeCredentialsHandle(&cred->cred_handle);
- Curl_safefree(cred);
- }
-}
-
-int Curl_schannel_init(void)
+static int Curl_schannel_init(void)
{
return (Curl_sspi_global_init() == CURLE_OK ? 1 : 0);
}
-void Curl_schannel_cleanup(void)
+static void Curl_schannel_cleanup(void)
{
Curl_sspi_global_cleanup();
}
-size_t Curl_schannel_version(char *buffer, size_t size)
+static size_t Curl_schannel_version(char *buffer, size_t size)
{
- size = snprintf(buffer, size, "WinSSL");
+ size = msnprintf(buffer, size, "Schannel");
return size;
}
-CURLcode Curl_schannel_random(unsigned char *entropy, size_t length)
+static CURLcode Curl_schannel_random(struct Curl_easy *data UNUSED_PARAM,
+ unsigned char *entropy, size_t length)
{
HCRYPTPROV hCryptProv = 0;
+ (void)data;
+
if(!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
return CURLE_FAILED_INIT;
@@ -1585,144 +2127,176 @@ CURLcode Curl_schannel_random(unsigned char *entropy, size_t length)
return CURLE_OK;
}
-#ifdef _WIN32_WCE
-static CURLcode verify_certificate(struct connectdata *conn, int sockindex)
+static CURLcode pkp_pin_peer_pubkey(struct connectdata *conn, int sockindex,
+ const char *pinnedpubkey)
{
- SECURITY_STATUS status;
struct Curl_easy *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
- CURLcode result = CURLE_OK;
CERT_CONTEXT *pCertContextServer = NULL;
- const CERT_CHAIN_CONTEXT *pChainContext = NULL;
- const char * const conn_hostname = SSL_IS_PROXY() ?
- conn->http_proxy.host.name :
- conn->host.name;
- status = s_pSecFn->QueryContextAttributes(&connssl->ctxt->ctxt_handle,
- SECPKG_ATTR_REMOTE_CERT_CONTEXT,
- &pCertContextServer);
+ /* Result is returned to caller */
+ CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
- if((status != SEC_E_OK) || (pCertContextServer == NULL)) {
- failf(data, "schannel: Failed to read remote certificate context: %s",
- Curl_sspi_strerror(conn, status));
- result = CURLE_PEER_FAILED_VERIFICATION;
- }
+ /* if a path wasn't specified, don't pin */
+ if(!pinnedpubkey)
+ return CURLE_OK;
- if(result == CURLE_OK) {
- CERT_CHAIN_PARA ChainPara;
- memset(&ChainPara, 0, sizeof(ChainPara));
- ChainPara.cbSize = sizeof(ChainPara);
-
- if(!CertGetCertificateChain(NULL,
- pCertContextServer,
- NULL,
- pCertContextServer->hCertStore,
- &ChainPara,
- (data->set.ssl.no_revoke ? 0 :
- CERT_CHAIN_REVOCATION_CHECK_CHAIN),
- NULL,
- &pChainContext)) {
- failf(data, "schannel: CertGetCertificateChain failed: %s",
- Curl_sspi_strerror(conn, GetLastError()));
- pChainContext = NULL;
- result = CURLE_PEER_FAILED_VERIFICATION;
- }
+ do {
+ SECURITY_STATUS sspi_status;
+ const char *x509_der;
+ DWORD x509_der_len;
+ curl_X509certificate x509_parsed;
+ curl_asn1Element *pubkey;
- if(result == CURLE_OK) {
- CERT_SIMPLE_CHAIN *pSimpleChain = pChainContext->rgpChain[0];
- DWORD dwTrustErrorMask = ~(DWORD)(CERT_TRUST_IS_NOT_TIME_NESTED);
- dwTrustErrorMask &= pSimpleChain->TrustStatus.dwErrorStatus;
- if(dwTrustErrorMask) {
- if(dwTrustErrorMask & CERT_TRUST_IS_REVOKED)
- failf(data, "schannel: CertGetCertificateChain trust error"
- " CERT_TRUST_IS_REVOKED");
- else if(dwTrustErrorMask & CERT_TRUST_IS_PARTIAL_CHAIN)
- failf(data, "schannel: CertGetCertificateChain trust error"
- " CERT_TRUST_IS_PARTIAL_CHAIN");
- else if(dwTrustErrorMask & CERT_TRUST_IS_UNTRUSTED_ROOT)
- failf(data, "schannel: CertGetCertificateChain trust error"
- " CERT_TRUST_IS_UNTRUSTED_ROOT");
- else if(dwTrustErrorMask & CERT_TRUST_IS_NOT_TIME_VALID)
- failf(data, "schannel: CertGetCertificateChain trust error"
- " CERT_TRUST_IS_NOT_TIME_VALID");
- else
- failf(data, "schannel: CertGetCertificateChain error mask: 0x%08x",
- dwTrustErrorMask);
- result = CURLE_PEER_FAILED_VERIFICATION;
- }
+ sspi_status =
+ s_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
+ SECPKG_ATTR_REMOTE_CERT_CONTEXT,
+ &pCertContextServer);
+
+ if((sspi_status != SEC_E_OK) || (pCertContextServer == NULL)) {
+ char buffer[STRERROR_LEN];
+ failf(data, "schannel: Failed to read remote certificate context: %s",
+ Curl_sspi_strerror(sspi_status, buffer, sizeof(buffer)));
+ break; /* failed */
}
- }
- if(result == CURLE_OK) {
- if(conn->ssl_config.verifyhost) {
- TCHAR cert_hostname_buff[256];
- DWORD len;
-
- /* TODO: Fix this for certificates with multiple alternative names.
- Right now we're only asking for the first preferred alternative name.
- Instead we'd need to do all via CERT_NAME_SEARCH_ALL_NAMES_FLAG
- (if WinCE supports that?) and run this section in a loop for each.
- https://msdn.microsoft.com/en-us/library/windows/desktop/aa376086.aspx
- curl: (51) schannel: CertGetNameString() certificate hostname
- (.google.com) did not match connection (google.com)
- */
- len = CertGetNameString(pCertContextServer,
- CERT_NAME_DNS_TYPE,
- CERT_NAME_DISABLE_IE4_UTF8_FLAG,
- NULL,
- cert_hostname_buff,
- 256);
- if(len > 0) {
- const char *cert_hostname;
-
- /* Comparing the cert name and the connection hostname encoded as UTF-8
- * is acceptable since both values are assumed to use ASCII
- * (or some equivalent) encoding
- */
- cert_hostname = Curl_convert_tchar_to_UTF8(cert_hostname_buff);
- if(!cert_hostname) {
- result = CURLE_OUT_OF_MEMORY;
- }
- else{
- int match_result;
-
- match_result = Curl_cert_hostcheck(cert_hostname, conn->host.name);
- if(match_result == CURL_HOST_MATCH) {
- infof(data,
- "schannel: connection hostname (%s) validated "
- "against certificate name (%s)\n",
- conn->host.name,
- cert_hostname);
- result = CURLE_OK;
- }
- else{
- failf(data,
- "schannel: connection hostname (%s) "
- "does not match certificate name (%s)",
- conn->host.name,
- cert_hostname);
- result = CURLE_PEER_FAILED_VERIFICATION;
- }
- Curl_unicodefree(cert_hostname);
- }
- }
- else {
- failf(data,
- "schannel: CertGetNameString did not provide any "
- "certificate name information");
- result = CURLE_PEER_FAILED_VERIFICATION;
- }
+
+ if(!(((pCertContextServer->dwCertEncodingType & X509_ASN_ENCODING) != 0) &&
+ (pCertContextServer->cbCertEncoded > 0)))
+ break;
+
+ x509_der = (const char *)pCertContextServer->pbCertEncoded;
+ x509_der_len = pCertContextServer->cbCertEncoded;
+ memset(&x509_parsed, 0, sizeof(x509_parsed));
+ if(Curl_parseX509(&x509_parsed, x509_der, x509_der + x509_der_len))
+ break;
+
+ pubkey = &x509_parsed.subjectPublicKeyInfo;
+ if(!pubkey->header || pubkey->end <= pubkey->header) {
+ failf(data, "SSL: failed retrieving public key from server certificate");
+ break;
}
- }
- if(pChainContext)
- CertFreeCertificateChain(pChainContext);
+ result = Curl_pin_peer_pubkey(data,
+ pinnedpubkey,
+ (const unsigned char *)pubkey->header,
+ (size_t)(pubkey->end - pubkey->header));
+ if(result) {
+ failf(data, "SSL: public key does not match pinned public key!");
+ }
+ } while(0);
if(pCertContextServer)
CertFreeCertificateContext(pCertContextServer);
return result;
}
-#endif /* _WIN32_WCE */
+
+static void Curl_schannel_checksum(const unsigned char *input,
+ size_t inputlen,
+ unsigned char *checksum,
+ size_t checksumlen,
+ DWORD provType,
+ const unsigned int algId)
+{
+ HCRYPTPROV hProv = 0;
+ HCRYPTHASH hHash = 0;
+ DWORD cbHashSize = 0;
+ DWORD dwHashSizeLen = (DWORD)sizeof(cbHashSize);
+ DWORD dwChecksumLen = (DWORD)checksumlen;
+
+ /* since this can fail in multiple ways, zero memory first so we never
+ * return old data
+ */
+ memset(checksum, 0, checksumlen);
+
+ if(!CryptAcquireContext(&hProv, NULL, NULL, provType,
+ CRYPT_VERIFYCONTEXT))
+ return; /* failed */
+
+ do {
+ if(!CryptCreateHash(hProv, algId, 0, 0, &hHash))
+ break; /* failed */
+
+ /* workaround for original MinGW, should be (const BYTE*) */
+ if(!CryptHashData(hHash, (BYTE*)input, (DWORD)inputlen, 0))
+ break; /* failed */
+
+ /* get hash size */
+ if(!CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE *)&cbHashSize,
+ &dwHashSizeLen, 0))
+ break; /* failed */
+
+ /* check hash size */
+ if(checksumlen < cbHashSize)
+ break; /* failed */
+
+ if(CryptGetHashParam(hHash, HP_HASHVAL, checksum, &dwChecksumLen, 0))
+ break; /* failed */
+ } while(0);
+
+ if(hHash)
+ CryptDestroyHash(hHash);
+
+ if(hProv)
+ CryptReleaseContext(hProv, 0);
+}
+
+static CURLcode Curl_schannel_md5sum(unsigned char *input,
+ size_t inputlen,
+ unsigned char *md5sum,
+ size_t md5len)
+{
+ Curl_schannel_checksum(input, inputlen, md5sum, md5len,
+ PROV_RSA_FULL, CALG_MD5);
+ return CURLE_OK;
+}
+
+static CURLcode Curl_schannel_sha256sum(const unsigned char *input,
+ size_t inputlen,
+ unsigned char *sha256sum,
+ size_t sha256len)
+{
+ Curl_schannel_checksum(input, inputlen, sha256sum, sha256len,
+ PROV_RSA_AES, CALG_SHA_256);
+ return CURLE_OK;
+}
+
+static void *Curl_schannel_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info UNUSED_PARAM)
+{
+ (void)info;
+ return &BACKEND->ctxt->ctxt_handle;
+}
+
+const struct Curl_ssl Curl_ssl_schannel = {
+ { CURLSSLBACKEND_SCHANNEL, "schannel" }, /* info */
+
+ SSLSUPP_CERTINFO |
+ SSLSUPP_PINNEDPUBKEY,
+
+ sizeof(struct ssl_backend_data),
+
+ Curl_schannel_init, /* init */
+ Curl_schannel_cleanup, /* cleanup */
+ Curl_schannel_version, /* version */
+ Curl_none_check_cxn, /* check_cxn */
+ Curl_schannel_shutdown, /* shutdown */
+ Curl_schannel_data_pending, /* data_pending */
+ Curl_schannel_random, /* random */
+ Curl_none_cert_status_request, /* cert_status_request */
+ Curl_schannel_connect, /* connect */
+ Curl_schannel_connect_nonblocking, /* connect_nonblocking */
+ Curl_schannel_get_internals, /* get_internals */
+ Curl_schannel_close, /* close_one */
+ Curl_none_close_all, /* close_all */
+ Curl_schannel_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_schannel_md5sum, /* md5sum */
+ Curl_schannel_sha256sum /* sha256sum */
+};
#endif /* USE_SCHANNEL */
diff --git a/Utilities/cmcurl/lib/vtls/schannel.h b/Utilities/cmcurl/lib/vtls/schannel.h
index 8627c63c9..ee8d7d47a 100644
--- a/Utilities/cmcurl/lib/vtls/schannel.h
+++ b/Utilities/cmcurl/lib/vtls/schannel.h
@@ -8,7 +8,7 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2012, Marc Hoersken, <info@marc-hoersken.de>, et al.
- * Copyright (C) 2012 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2012 - 2018, 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
@@ -26,96 +26,83 @@
#ifdef USE_SCHANNEL
-#include "urldata.h"
-
-#ifndef UNISP_NAME_A
-#define UNISP_NAME_A "Microsoft Unified Security Protocol Provider"
-#endif
+#include <schnlsp.h>
+#include <schannel.h>
+#include "curl_sspi.h"
-#ifndef UNISP_NAME_W
-#define UNISP_NAME_W L"Microsoft Unified Security Protocol Provider"
-#endif
+#include "urldata.h"
-#ifndef UNISP_NAME
-#ifdef UNICODE
-#define UNISP_NAME UNISP_NAME_W
-#else
-#define UNISP_NAME UNISP_NAME_A
-#endif
+/* <wincrypt.h> has been included via the above <schnlsp.h>.
+ * Or in case of ldap.c, it was included via <winldap.h>.
+ * And since <wincrypt.h> has this:
+ * #define X509_NAME ((LPCSTR) 7)
+ *
+ * And in BoringSSL's <openssl/base.h> there is:
+ * typedef struct X509_name_st X509_NAME;
+ * etc.
+ *
+ * this will cause all kinds of C-preprocessing paste errors in
+ * BoringSSL's <openssl/x509.h>: So just undefine those defines here
+ * (and only here).
+ */
+#if defined(HAVE_BORINGSSL) || defined(OPENSSL_IS_BORINGSSL)
+# undef X509_NAME
+# undef X509_CERT_PAIR
+# undef X509_EXTENSIONS
#endif
-#ifndef SP_PROT_SSL2_CLIENT
-#define SP_PROT_SSL2_CLIENT 0x00000008
-#endif
+extern const struct Curl_ssl Curl_ssl_schannel;
-#ifndef SP_PROT_SSL3_CLIENT
-#define SP_PROT_SSL3_CLIENT 0x00000008
-#endif
+CURLcode Curl_verify_certificate(struct connectdata *conn, int sockindex);
-#ifndef SP_PROT_TLS1_CLIENT
-#define SP_PROT_TLS1_CLIENT 0x00000080
-#endif
+/* structs to expose only in schannel.c and schannel_verify.c */
+#ifdef EXPOSE_SCHANNEL_INTERNAL_STRUCTS
-#ifndef SP_PROT_TLS1_0_CLIENT
-#define SP_PROT_TLS1_0_CLIENT SP_PROT_TLS1_CLIENT
+#ifdef __MINGW32__
+#include <_mingw.h>
+#ifdef __MINGW64_VERSION_MAJOR
+#define HAS_MANUAL_VERIFY_API
#endif
-
-#ifndef SP_PROT_TLS1_1_CLIENT
-#define SP_PROT_TLS1_1_CLIENT 0x00000200
+#else
+#include <wincrypt.h>
+#ifdef CERT_CHAIN_REVOCATION_CHECK_CHAIN
+#define HAS_MANUAL_VERIFY_API
#endif
-
-#ifndef SP_PROT_TLS1_2_CLIENT
-#define SP_PROT_TLS1_2_CLIENT 0x00000800
#endif
-#ifndef SECBUFFER_ALERT
-#define SECBUFFER_ALERT 17
+struct curl_schannel_cred {
+ CredHandle cred_handle;
+ TimeStamp time_stamp;
+ int refcount;
+};
+
+struct curl_schannel_ctxt {
+ CtxtHandle ctxt_handle;
+ TimeStamp time_stamp;
+};
+
+struct ssl_backend_data {
+ struct curl_schannel_cred *cred;
+ struct curl_schannel_ctxt *ctxt;
+ SecPkgContext_StreamSizes stream_sizes;
+ size_t encdata_length, decdata_length;
+ size_t encdata_offset, decdata_offset;
+ unsigned char *encdata_buffer, *decdata_buffer;
+ /* encdata_is_incomplete: if encdata contains only a partial record that
+ can't be decrypted without another Curl_read_plain (that is, status is
+ SEC_E_INCOMPLETE_MESSAGE) then set this true. after Curl_read_plain writes
+ more bytes into encdata then set this back to false. */
+ bool encdata_is_incomplete;
+ unsigned long req_flags, ret_flags;
+ CURLcode recv_unrecoverable_err; /* schannel_recv had an unrecoverable err */
+ bool recv_sspi_close_notify; /* true if connection closed by close_notify */
+ bool recv_connection_closed; /* true if connection closed, regardless how */
+ bool use_alpn; /* true if ALPN is used for this connection */
+#ifdef HAS_MANUAL_VERIFY_API
+ bool use_manual_cred_validation; /* true if manual cred validation is used */
#endif
-
-/* Both schannel buffer sizes must be > 0 */
-#define CURL_SCHANNEL_BUFFER_INIT_SIZE 4096
-#define CURL_SCHANNEL_BUFFER_FREE_SIZE 1024
-
-
-CURLcode Curl_schannel_connect(struct connectdata *conn, int sockindex);
-
-CURLcode Curl_schannel_connect_nonblocking(struct connectdata *conn,
- int sockindex,
- bool *done);
-
-bool Curl_schannel_data_pending(const struct connectdata *conn, int sockindex);
-void Curl_schannel_close(struct connectdata *conn, int sockindex);
-int Curl_schannel_shutdown(struct connectdata *conn, int sockindex);
-void Curl_schannel_session_free(void *ptr);
-
-int Curl_schannel_init(void);
-void Curl_schannel_cleanup(void);
-size_t Curl_schannel_version(char *buffer, size_t size);
-
-CURLcode Curl_schannel_random(unsigned char *entropy, size_t length);
-
-/* Set the API backend definition to Schannel */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_SCHANNEL
-
-/* this backend supports CURLOPT_CERTINFO */
-#define have_curlssl_certinfo 1
-
-/* API setup for Schannel */
-#define curlssl_init Curl_schannel_init
-#define curlssl_cleanup Curl_schannel_cleanup
-#define curlssl_connect Curl_schannel_connect
-#define curlssl_connect_nonblocking Curl_schannel_connect_nonblocking
-#define curlssl_session_free Curl_schannel_session_free
-#define curlssl_close_all(x) ((void)x)
-#define curlssl_close Curl_schannel_close
-#define curlssl_shutdown Curl_schannel_shutdown
-#define curlssl_set_engine(x,y) ((void)x, (void)y, CURLE_NOT_BUILT_IN)
-#define curlssl_set_engine_default(x) ((void)x, CURLE_NOT_BUILT_IN)
-#define curlssl_engines_list(x) ((void)x, (struct curl_slist *)NULL)
-#define curlssl_version Curl_schannel_version
-#define curlssl_check_cxn(x) ((void)x, -1)
-#define curlssl_data_pending Curl_schannel_data_pending
-#define curlssl_random(x,y,z) ((void)x, Curl_schannel_random(y,z))
+};
+#endif /* EXPOSE_SCHANNEL_INTERNAL_STRUCTS */
#endif /* USE_SCHANNEL */
#endif /* HEADER_CURL_SCHANNEL_H */
diff --git a/Utilities/cmcurl/lib/vtls/vtls.c b/Utilities/cmcurl/lib/vtls/vtls.c
index d5d0971c4..a7452dcd5 100644
--- a/Utilities/cmcurl/lib/vtls/vtls.c
+++ b/Utilities/cmcurl/lib/vtls/vtls.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -28,17 +28,9 @@
to any specific SSL-layer.
Curl_ssl_ - prefix for generic ones
- Curl_ossl_ - prefix for OpenSSL ones
- Curl_gtls_ - prefix for GnuTLS ones
- Curl_nss_ - prefix for NSS ones
- Curl_gskit_ - prefix for GSKit ones
- Curl_polarssl_ - prefix for PolarSSL ones
- Curl_cyassl_ - prefix for CyaSSL ones
- Curl_schannel_ - prefix for Schannel SSPI ones
- Curl_darwinssl_ - prefix for SecureTransport (Darwin) ones
-
- Note that this source code uses curlssl_* functions, and they are all
- defines/macros #defined by the lib-specific header files.
+
+ Note that this source code uses the functions of the configured SSL
+ backend via the global Curl_ssl instance.
"SSL/TLS Strong Encryption: An Introduction"
https://httpd.apache.org/docs/2.0/ssl/ssl_intro.html
@@ -98,10 +90,14 @@ Curl_ssl_config_matches(struct ssl_primary_config* data,
(data->version_max == needle->version_max) &&
(data->verifypeer == needle->verifypeer) &&
(data->verifyhost == needle->verifyhost) &&
+ (data->verifystatus == needle->verifystatus) &&
Curl_safe_strcasecompare(data->CApath, needle->CApath) &&
Curl_safe_strcasecompare(data->CAfile, needle->CAfile) &&
Curl_safe_strcasecompare(data->clientcert, needle->clientcert) &&
- Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list))
+ Curl_safe_strcasecompare(data->random_file, needle->random_file) &&
+ Curl_safe_strcasecompare(data->egdsocket, needle->egdsocket) &&
+ Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list) &&
+ Curl_safe_strcasecompare(data->cipher_list13, needle->cipher_list13))
return TRUE;
return FALSE;
@@ -111,42 +107,53 @@ bool
Curl_clone_primary_ssl_config(struct ssl_primary_config *source,
struct ssl_primary_config *dest)
{
- dest->verifyhost = source->verifyhost;
- dest->verifypeer = source->verifypeer;
dest->version = source->version;
dest->version_max = source->version_max;
+ dest->verifypeer = source->verifypeer;
+ dest->verifyhost = source->verifyhost;
+ dest->verifystatus = source->verifystatus;
+ dest->sessionid = source->sessionid;
- CLONE_STRING(CAfile);
CLONE_STRING(CApath);
- CLONE_STRING(cipher_list);
- CLONE_STRING(egdsocket);
- CLONE_STRING(random_file);
+ CLONE_STRING(CAfile);
CLONE_STRING(clientcert);
+ CLONE_STRING(random_file);
+ CLONE_STRING(egdsocket);
+ CLONE_STRING(cipher_list);
+ CLONE_STRING(cipher_list13);
- /* Disable dest sessionid cache if a client cert is used, CVE-2016-5419. */
- dest->sessionid = (dest->clientcert ? false : source->sessionid);
return TRUE;
}
void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc)
{
- Curl_safefree(sslc->CAfile);
Curl_safefree(sslc->CApath);
- Curl_safefree(sslc->cipher_list);
- Curl_safefree(sslc->egdsocket);
- Curl_safefree(sslc->random_file);
+ Curl_safefree(sslc->CAfile);
Curl_safefree(sslc->clientcert);
+ Curl_safefree(sslc->random_file);
+ Curl_safefree(sslc->egdsocket);
+ Curl_safefree(sslc->cipher_list);
+ Curl_safefree(sslc->cipher_list13);
}
+#ifdef USE_SSL
+static int multissl_init(const struct Curl_ssl *backend);
+#endif
+
int Curl_ssl_backend(void)
{
- return (int)CURL_SSL_BACKEND;
+#ifdef USE_SSL
+ multissl_init(NULL);
+ return Curl_ssl->info.id;
+#else
+ return (int)CURLSSLBACKEND_NONE;
+#endif
}
#ifdef USE_SSL
/* "global" init done? */
-static bool init_ssl=FALSE;
+static bool init_ssl = FALSE;
/**
* Global SSL init
@@ -161,7 +168,7 @@ int Curl_ssl_init(void)
return 1;
init_ssl = TRUE; /* never again */
- return curlssl_init();
+ return Curl_ssl->init();
}
@@ -170,7 +177,7 @@ void Curl_ssl_cleanup(void)
{
if(init_ssl) {
/* only cleanup if we did a previous init */
- curlssl_cleanup();
+ Curl_ssl->cleanup();
init_ssl = FALSE;
}
}
@@ -205,12 +212,20 @@ ssl_connect_init_proxy(struct connectdata *conn, int sockindex)
DEBUGASSERT(conn->bits.proxy_ssl_connected[sockindex]);
if(ssl_connection_complete == conn->ssl[sockindex].state &&
!conn->proxy_ssl[sockindex].use) {
-#if defined(HTTPS_PROXY_SUPPORT)
+ struct ssl_backend_data *pbdata;
+
+ if(!(Curl_ssl->supports & SSLSUPP_HTTPS_PROXY))
+ return CURLE_NOT_BUILT_IN;
+
+ /* The pointers to the ssl backend data, which is opaque here, are swapped
+ rather than move the contents. */
+ pbdata = conn->proxy_ssl[sockindex].backend;
conn->proxy_ssl[sockindex] = conn->ssl[sockindex];
+
memset(&conn->ssl[sockindex], 0, sizeof(conn->ssl[sockindex]));
-#else
- return CURLE_NOT_BUILT_IN;
-#endif
+ memset(pbdata, 0, Curl_ssl->sizeof_ssl_backend_data);
+
+ conn->ssl[sockindex].backend = pbdata;
}
return CURLE_OK;
}
@@ -233,7 +248,7 @@ Curl_ssl_connect(struct connectdata *conn, int sockindex)
conn->ssl[sockindex].use = TRUE;
conn->ssl[sockindex].state = ssl_connection_negotiating;
- result = curlssl_connect(conn, sockindex);
+ result = Curl_ssl->connect_blocking(conn, sockindex);
if(!result)
Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
@@ -257,12 +272,7 @@ Curl_ssl_connect_nonblocking(struct connectdata *conn, int sockindex,
/* mark this is being ssl requested from here on. */
conn->ssl[sockindex].use = TRUE;
-#ifdef curlssl_connect_nonblocking
- result = curlssl_connect_nonblocking(conn, sockindex, done);
-#else
- *done = TRUE; /* fallback to BLOCKING */
- result = curlssl_connect(conn, sockindex);
-#endif /* non-blocking connect support */
+ result = Curl_ssl->connect_nonblocking(conn, sockindex, done);
if(!result && *done)
Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
return result;
@@ -361,7 +371,7 @@ void Curl_ssl_kill_session(struct curl_ssl_session *session)
/* defensive check */
/* free the ID the SSL-layer specific way */
- curlssl_session_free(session->sessionid);
+ Curl_ssl->session_free(session->sessionid);
session->sessionid = NULL;
session->age = 0; /* fresh */
@@ -379,7 +389,7 @@ void Curl_ssl_kill_session(struct curl_ssl_session *session)
void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
{
size_t i;
- struct Curl_easy *data=conn->data;
+ struct Curl_easy *data = conn->data;
for(i = 0; i < data->set.general_ssl.max_ssl_sessions; i++) {
struct curl_ssl_session *check = &data->state.session[i];
@@ -403,9 +413,9 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
int sockindex)
{
size_t i;
- struct Curl_easy *data=conn->data; /* the mother of all structs */
+ struct Curl_easy *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 */
+ long oldest_age = data->state.session[0].age; /* zero if unused */
char *clone_host;
char *clone_conn_to_host;
int conn_to_port;
@@ -488,9 +498,9 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
void Curl_ssl_close_all(struct Curl_easy *data)
{
- size_t i;
/* kill the session ID cache if not shared */
if(data->state.session && !SSLSESSION_SHARED(data)) {
+ size_t i;
for(i = 0; i < data->set.general_ssl.max_ssl_sessions; i++)
/* the single-killer function handles empty table slots */
Curl_ssl_kill_session(&data->state.session[i]);
@@ -499,12 +509,12 @@ void Curl_ssl_close_all(struct Curl_easy *data)
Curl_safefree(data->state.session);
}
- curlssl_close_all(data);
+ Curl_ssl->close_all(data);
}
#if defined(USE_OPENSSL) || defined(USE_GNUTLS) || defined(USE_SCHANNEL) || \
- defined(USE_DARWINSSL) || defined(USE_POLARSSL) || defined(USE_NSS) || \
- defined(USE_MBEDTLS)
+ defined(USE_SECTRANSP) || defined(USE_POLARSSL) || defined(USE_NSS) || \
+ defined(USE_MBEDTLS) || defined(USE_CYASSL)
int Curl_ssl_getsock(struct connectdata *conn, curl_socket_t *socks,
int numsocks)
{
@@ -536,18 +546,18 @@ int Curl_ssl_getsock(struct connectdata *conn,
(void)numsocks;
return GETSOCK_BLANK;
}
-/* USE_OPENSSL || USE_GNUTLS || USE_SCHANNEL || USE_DARWINSSL || USE_NSS */
+/* USE_OPENSSL || USE_GNUTLS || USE_SCHANNEL || USE_SECTRANSP || USE_NSS */
#endif
void Curl_ssl_close(struct connectdata *conn, int sockindex)
{
DEBUGASSERT((sockindex <= 1) && (sockindex >= -1));
- curlssl_close(conn, sockindex);
+ Curl_ssl->close_one(conn, sockindex);
}
CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex)
{
- if(curlssl_shutdown(conn, sockindex))
+ if(Curl_ssl->shut_down(conn, sockindex))
return CURLE_SSL_SHUTDOWN_FAILED;
conn->ssl[sockindex].use = FALSE; /* get back to ordinary socket usage */
@@ -563,20 +573,20 @@ CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex)
*/
CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine)
{
- return curlssl_set_engine(data, engine);
+ return Curl_ssl->set_engine(data, engine);
}
/* Selects the default SSL crypto engine
*/
CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data)
{
- return curlssl_set_engine_default(data);
+ return Curl_ssl->set_engine_default(data);
}
/* Return list of OpenSSL crypto engine names. */
struct curl_slist *Curl_ssl_engines_list(struct Curl_easy *data)
{
- return curlssl_engines_list(data);
+ return Curl_ssl->engines_list(data);
}
/*
@@ -602,9 +612,15 @@ CURLcode Curl_ssl_initsessions(struct Curl_easy *data, size_t amount)
return CURLE_OK;
}
+static size_t Curl_multissl_version(char *buffer, size_t size);
+
size_t Curl_ssl_version(char *buffer, size_t size)
{
- return curlssl_version(buffer, size);
+#ifdef CURL_WITH_MULTI_SSL
+ return Curl_multissl_version(buffer, size);
+#else
+ return Curl_ssl->version(buffer, size);
+#endif
}
/*
@@ -617,23 +633,23 @@ size_t Curl_ssl_version(char *buffer, size_t size)
*/
int Curl_ssl_check_cxn(struct connectdata *conn)
{
- return curlssl_check_cxn(conn);
+ return Curl_ssl->check_cxn(conn);
}
bool Curl_ssl_data_pending(const struct connectdata *conn,
int connindex)
{
- return curlssl_data_pending(conn, connindex);
+ return Curl_ssl->data_pending(conn, connindex);
}
void Curl_ssl_free_certinfo(struct Curl_easy *data)
{
- int i;
struct curl_certinfo *ci = &data->info.certs;
if(ci->num_of_certs) {
/* free all individual lists used */
- for(i=0; i<ci->num_of_certs; i++) {
+ int i;
+ for(i = 0; i<ci->num_of_certs; i++) {
curl_slist_free_all(ci->certinfo[i]);
ci->certinfo[i] = NULL;
}
@@ -684,10 +700,10 @@ CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data,
return CURLE_OUT_OF_MEMORY;
/* sprintf the label and colon */
- snprintf(output, outlen, "%s:", label);
+ msnprintf(output, outlen, "%s:", label);
/* memcpy the value (it might not be zero terminated) */
- memcpy(&output[labellen+1], value, valuelen);
+ memcpy(&output[labellen + 1], value, valuelen);
/* zero terminate the output */
output[labellen + 1 + valuelen] = 0;
@@ -721,7 +737,7 @@ CURLcode Curl_ssl_random(struct Curl_easy *data,
unsigned char *entropy,
size_t length)
{
- return curlssl_random(data, entropy, length);
+ return Curl_ssl->random(data, entropy, length);
}
/*
@@ -792,16 +808,7 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
{
FILE *fp;
unsigned char *buf = NULL, *pem_ptr = NULL;
- long filesize;
- size_t size, pem_len;
- CURLcode pem_read;
CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
-#ifdef curlssl_sha256sum
- CURLcode encode;
- size_t encodedlen, pinkeylen;
- char *encoded, *pinkeycopy, *begin_pos, *end_pos;
- unsigned char *sha256sumdigest = NULL;
-#endif
/* if a path wasn't specified, don't pin */
if(!pinnedpubkey)
@@ -811,15 +818,29 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
/* only do this if pinnedpubkey starts with "sha256//", length 8 */
if(strncmp(pinnedpubkey, "sha256//", 8) == 0) {
-#ifdef curlssl_sha256sum
+ CURLcode encode;
+ size_t encodedlen, pinkeylen;
+ char *encoded, *pinkeycopy, *begin_pos, *end_pos;
+ unsigned char *sha256sumdigest;
+
+ if(!Curl_ssl->sha256sum) {
+ /* without sha256 support, this cannot match */
+ return result;
+ }
+
/* compute sha256sum of public key */
- sha256sumdigest = malloc(SHA256_DIGEST_LENGTH);
+ sha256sumdigest = malloc(CURL_SHA256_DIGEST_LENGTH);
if(!sha256sumdigest)
return CURLE_OUT_OF_MEMORY;
- curlssl_sha256sum(pubkey, pubkeylen,
- sha256sumdigest, SHA256_DIGEST_LENGTH);
+ encode = Curl_ssl->sha256sum(pubkey, pubkeylen,
+ sha256sumdigest, CURL_SHA256_DIGEST_LENGTH);
+
+ if(encode != CURLE_OK)
+ return encode;
+
encode = Curl_base64_encode(data, (char *)sha256sumdigest,
- SHA256_DIGEST_LENGTH, &encoded, &encodedlen);
+ CURL_SHA256_DIGEST_LENGTH, &encoded,
+ &encodedlen);
Curl_safefree(sha256sumdigest);
if(encode)
@@ -864,10 +885,6 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
} while(end_pos && begin_pos);
Curl_safefree(encoded);
Curl_safefree(pinkeycopy);
-#else
- /* without sha256 support, this cannot match */
- (void)data;
-#endif
return result;
}
@@ -876,6 +893,10 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
return result;
do {
+ long filesize;
+ size_t size, pem_len;
+ CURLcode pem_read;
+
/* Determine the file's size */
if(fseek(fp, 0, SEEK_END))
break;
@@ -943,45 +964,386 @@ CURLcode Curl_ssl_md5sum(unsigned char *tmp, /* input */
unsigned char *md5sum, /* output */
size_t md5len)
{
-#ifdef curlssl_md5sum
- curlssl_md5sum(tmp, tmplen, md5sum, md5len);
-#else
+ return Curl_ssl->md5sum(tmp, tmplen, md5sum, md5len);
+}
+#endif
+
+/*
+ * Check whether the SSL backend supports the status_request extension.
+ */
+bool Curl_ssl_cert_status_request(void)
+{
+ return Curl_ssl->cert_status_request();
+}
+
+/*
+ * Check whether the SSL backend supports false start.
+ */
+bool Curl_ssl_false_start(void)
+{
+ return Curl_ssl->false_start();
+}
+
+/*
+ * Check whether the SSL backend supports setting TLS 1.3 cipher suites
+ */
+bool Curl_ssl_tls13_ciphersuites(void)
+{
+ return Curl_ssl->supports & SSLSUPP_TLS13_CIPHERSUITES;
+}
+
+/*
+ * Default implementations for unsupported functions.
+ */
+
+int Curl_none_init(void)
+{
+ return 1;
+}
+
+void Curl_none_cleanup(void)
+{ }
+
+int Curl_none_shutdown(struct connectdata *conn UNUSED_PARAM,
+ int sockindex UNUSED_PARAM)
+{
+ (void)conn;
+ (void)sockindex;
+ return 0;
+}
+
+int Curl_none_check_cxn(struct connectdata *conn UNUSED_PARAM)
+{
+ (void)conn;
+ return -1;
+}
+
+CURLcode Curl_none_random(struct Curl_easy *data UNUSED_PARAM,
+ unsigned char *entropy UNUSED_PARAM,
+ size_t length UNUSED_PARAM)
+{
+ (void)data;
+ (void)entropy;
+ (void)length;
+ return CURLE_NOT_BUILT_IN;
+}
+
+void Curl_none_close_all(struct Curl_easy *data UNUSED_PARAM)
+{
+ (void)data;
+}
+
+void Curl_none_session_free(void *ptr UNUSED_PARAM)
+{
+ (void)ptr;
+}
+
+bool Curl_none_data_pending(const struct connectdata *conn UNUSED_PARAM,
+ int connindex UNUSED_PARAM)
+{
+ (void)conn;
+ (void)connindex;
+ return 0;
+}
+
+bool Curl_none_cert_status_request(void)
+{
+ return FALSE;
+}
+
+CURLcode Curl_none_set_engine(struct Curl_easy *data UNUSED_PARAM,
+ const char *engine UNUSED_PARAM)
+{
+ (void)data;
+ (void)engine;
+ return CURLE_NOT_BUILT_IN;
+}
+
+CURLcode Curl_none_set_engine_default(struct Curl_easy *data UNUSED_PARAM)
+{
+ (void)data;
+ return CURLE_NOT_BUILT_IN;
+}
+
+struct curl_slist *Curl_none_engines_list(struct Curl_easy *data UNUSED_PARAM)
+{
+ (void)data;
+ return (struct curl_slist *)NULL;
+}
+
+bool Curl_none_false_start(void)
+{
+ return FALSE;
+}
+
+#ifndef CURL_DISABLE_CRYPTO_AUTH
+CURLcode Curl_none_md5sum(unsigned char *input, size_t inputlen,
+ unsigned char *md5sum, size_t md5len UNUSED_PARAM)
+{
MD5_context *MD5pw;
- (void) md5len;
+ (void)md5len;
MD5pw = Curl_MD5_init(Curl_DIGEST_MD5);
if(!MD5pw)
return CURLE_OUT_OF_MEMORY;
- Curl_MD5_update(MD5pw, tmp, curlx_uztoui(tmplen));
+ Curl_MD5_update(MD5pw, input, curlx_uztoui(inputlen));
Curl_MD5_final(MD5pw, md5sum);
-#endif
return CURLE_OK;
}
+#else
+CURLcode Curl_none_md5sum(unsigned char *input UNUSED_PARAM,
+ size_t inputlen UNUSED_PARAM,
+ unsigned char *md5sum UNUSED_PARAM,
+ size_t md5len UNUSED_PARAM)
+{
+ (void)input;
+ (void)inputlen;
+ (void)md5sum;
+ (void)md5len;
+ return CURLE_NOT_BUILT_IN;
+}
#endif
-/*
- * Check whether the SSL backend supports the status_request extension.
- */
-bool Curl_ssl_cert_status_request(void)
+static int Curl_multissl_init(void)
+{
+ if(multissl_init(NULL))
+ return 1;
+ return Curl_ssl->init();
+}
+
+static CURLcode Curl_multissl_connect(struct connectdata *conn, int sockindex)
+{
+ if(multissl_init(NULL))
+ return CURLE_FAILED_INIT;
+ return Curl_ssl->connect_blocking(conn, sockindex);
+}
+
+static CURLcode Curl_multissl_connect_nonblocking(struct connectdata *conn,
+ int sockindex, bool *done)
+{
+ if(multissl_init(NULL))
+ return CURLE_FAILED_INIT;
+ return Curl_ssl->connect_nonblocking(conn, sockindex, done);
+}
+
+static void *Curl_multissl_get_internals(struct ssl_connect_data *connssl,
+ CURLINFO info)
+{
+ if(multissl_init(NULL))
+ return NULL;
+ return Curl_ssl->get_internals(connssl, info);
+}
+
+static void Curl_multissl_close(struct connectdata *conn, int sockindex)
{
-#ifdef curlssl_cert_status_request
- return curlssl_cert_status_request();
+ if(multissl_init(NULL))
+ return;
+ Curl_ssl->close_one(conn, sockindex);
+}
+
+static const struct Curl_ssl Curl_ssl_multi = {
+ { CURLSSLBACKEND_NONE, "multi" }, /* info */
+ 0, /* supports nothing */
+ (size_t)-1, /* something insanely large to be on the safe side */
+
+ Curl_multissl_init, /* init */
+ Curl_none_cleanup, /* cleanup */
+ Curl_multissl_version, /* version */
+ Curl_none_check_cxn, /* check_cxn */
+ Curl_none_shutdown, /* shutdown */
+ Curl_none_data_pending, /* data_pending */
+ Curl_none_random, /* random */
+ Curl_none_cert_status_request, /* cert_status_request */
+ Curl_multissl_connect, /* connect */
+ Curl_multissl_connect_nonblocking, /* connect_nonblocking */
+ Curl_multissl_get_internals, /* get_internals */
+ Curl_multissl_close, /* close_one */
+ Curl_none_close_all, /* close_all */
+ Curl_none_session_free, /* session_free */
+ Curl_none_set_engine, /* set_engine */
+ Curl_none_set_engine_default, /* set_engine_default */
+ Curl_none_engines_list, /* engines_list */
+ Curl_none_false_start, /* false_start */
+ Curl_none_md5sum, /* md5sum */
+ NULL /* sha256sum */
+};
+
+const struct Curl_ssl *Curl_ssl =
+#if defined(CURL_WITH_MULTI_SSL)
+ &Curl_ssl_multi;
+#elif defined(USE_CYASSL)
+ &Curl_ssl_cyassl;
+#elif defined(USE_SECTRANSP)
+ &Curl_ssl_sectransp;
+#elif defined(USE_GNUTLS)
+ &Curl_ssl_gnutls;
+#elif defined(USE_GSKIT)
+ &Curl_ssl_gskit;
+#elif defined(USE_MBEDTLS)
+ &Curl_ssl_mbedtls;
+#elif defined(USE_NSS)
+ &Curl_ssl_nss;
+#elif defined(USE_OPENSSL)
+ &Curl_ssl_openssl;
+#elif defined(USE_POLARSSL)
+ &Curl_ssl_polarssl;
+#elif defined(USE_SCHANNEL)
+ &Curl_ssl_schannel;
+#elif defined(USE_MESALINK)
+ &Curl_ssl_mesalink;
#else
- return FALSE;
+#error "Missing struct Curl_ssl for selected SSL backend"
#endif
+
+static const struct Curl_ssl *available_backends[] = {
+#if defined(USE_CYASSL)
+ &Curl_ssl_cyassl,
+#endif
+#if defined(USE_SECTRANSP)
+ &Curl_ssl_sectransp,
+#endif
+#if defined(USE_GNUTLS)
+ &Curl_ssl_gnutls,
+#endif
+#if defined(USE_GSKIT)
+ &Curl_ssl_gskit,
+#endif
+#if defined(USE_MBEDTLS)
+ &Curl_ssl_mbedtls,
+#endif
+#if defined(USE_NSS)
+ &Curl_ssl_nss,
+#endif
+#if defined(USE_OPENSSL)
+ &Curl_ssl_openssl,
+#endif
+#if defined(USE_POLARSSL)
+ &Curl_ssl_polarssl,
+#endif
+#if defined(USE_SCHANNEL)
+ &Curl_ssl_schannel,
+#endif
+#if defined(USE_MESALINK)
+ &Curl_ssl_mesalink,
+#endif
+ NULL
+};
+
+static size_t Curl_multissl_version(char *buffer, size_t size)
+{
+ static const struct Curl_ssl *selected;
+ static char backends[200];
+ static size_t total;
+ const struct Curl_ssl *current;
+
+ current = Curl_ssl == &Curl_ssl_multi ? available_backends[0] : Curl_ssl;
+
+ if(current != selected) {
+ char *p = backends;
+ char *end = backends + sizeof(backends);
+ int i;
+
+ selected = current;
+
+ for(i = 0; available_backends[i] && p < (end - 4); i++) {
+ if(i)
+ *(p++) = ' ';
+ if(selected != available_backends[i])
+ *(p++) = '(';
+ p += available_backends[i]->version(p, end - p - 2);
+ if(selected != available_backends[i])
+ *(p++) = ')';
+ }
+ *p = '\0';
+ total = p - backends;
+ }
+
+ if(size > total)
+ memcpy(buffer, backends, total + 1);
+ else {
+ memcpy(buffer, backends, size - 1);
+ buffer[size - 1] = '\0';
+ }
+
+ return CURLMIN(size - 1, total);
}
-/*
- * Check whether the SSL backend supports false start.
- */
-bool Curl_ssl_false_start(void)
+static int multissl_init(const struct Curl_ssl *backend)
+{
+ const char *env;
+ char *env_tmp;
+
+ if(Curl_ssl != &Curl_ssl_multi)
+ return 1;
+
+ if(backend) {
+ Curl_ssl = backend;
+ return 0;
+ }
+
+ if(!available_backends[0])
+ return 1;
+
+ env = env_tmp = curl_getenv("CURL_SSL_BACKEND");
+#ifdef CURL_DEFAULT_SSL_BACKEND
+ if(!env)
+ env = CURL_DEFAULT_SSL_BACKEND;
+#endif
+ if(env) {
+ int i;
+ for(i = 0; available_backends[i]; i++) {
+ if(strcasecompare(env, available_backends[i]->info.name)) {
+ Curl_ssl = available_backends[i];
+ curl_free(env_tmp);
+ return 0;
+ }
+ }
+ }
+
+ /* Fall back to first available backend */
+ Curl_ssl = available_backends[0];
+ curl_free(env_tmp);
+ return 0;
+}
+
+CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
+ const curl_ssl_backend ***avail)
{
-#ifdef curlssl_false_start
- return curlssl_false_start();
+ int i;
+
+ if(avail)
+ *avail = (const curl_ssl_backend **)&available_backends;
+
+ if(Curl_ssl != &Curl_ssl_multi)
+ return id == Curl_ssl->info.id ||
+ (name && strcasecompare(name, Curl_ssl->info.name)) ?
+ CURLSSLSET_OK :
+#if defined(CURL_WITH_MULTI_SSL)
+ CURLSSLSET_TOO_LATE;
#else
- return FALSE;
+ CURLSSLSET_UNKNOWN_BACKEND;
#endif
+
+ for(i = 0; available_backends[i]; i++) {
+ if(available_backends[i]->info.id == id ||
+ (name && strcasecompare(available_backends[i]->info.name, name))) {
+ multissl_init(available_backends[i]);
+ return CURLSSLSET_OK;
+ }
+ }
+
+ return CURLSSLSET_UNKNOWN_BACKEND;
+}
+
+#else /* USE_SSL */
+CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
+ const curl_ssl_backend ***avail)
+{
+ (void)id;
+ (void)name;
+ (void)avail;
+ return CURLSSLSET_NO_BACKENDS;
}
-#endif /* USE_SSL */
+#endif /* !USE_SSL */
diff --git a/Utilities/cmcurl/lib/vtls/vtls.h b/Utilities/cmcurl/lib/vtls/vtls.h
index 2aabeda20..2a87ca1f7 100644
--- a/Utilities/cmcurl/lib/vtls/vtls.h
+++ b/Utilities/cmcurl/lib/vtls/vtls.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -23,27 +23,104 @@
***************************************************************************/
#include "curl_setup.h"
+struct connectdata;
+struct ssl_connect_data;
+
+#define SSLSUPP_CA_PATH (1<<0) /* supports CAPATH */
+#define SSLSUPP_CERTINFO (1<<1) /* supports CURLOPT_CERTINFO */
+#define SSLSUPP_PINNEDPUBKEY (1<<2) /* supports CURLOPT_PINNEDPUBLICKEY */
+#define SSLSUPP_SSL_CTX (1<<3) /* supports CURLOPT_SSL_CTX */
+#define SSLSUPP_HTTPS_PROXY (1<<4) /* supports access via HTTPS proxies */
+#define SSLSUPP_TLS13_CIPHERSUITES (1<<5) /* supports TLS 1.3 ciphersuites */
+
+struct Curl_ssl {
+ /*
+ * This *must* be the first entry to allow returning the list of available
+ * backends in curl_global_sslset().
+ */
+ curl_ssl_backend info;
+ unsigned int supports; /* bitfield, see above */
+ size_t sizeof_ssl_backend_data;
+
+ int (*init)(void);
+ void (*cleanup)(void);
+
+ size_t (*version)(char *buffer, size_t size);
+ int (*check_cxn)(struct connectdata *cxn);
+ int (*shut_down)(struct connectdata *conn, int sockindex);
+ bool (*data_pending)(const struct connectdata *conn,
+ int connindex);
+
+ /* return 0 if a find random is filled in */
+ CURLcode (*random)(struct Curl_easy *data, unsigned char *entropy,
+ size_t length);
+ bool (*cert_status_request)(void);
+
+ CURLcode (*connect_blocking)(struct connectdata *conn, int sockindex);
+ CURLcode (*connect_nonblocking)(struct connectdata *conn, int sockindex,
+ bool *done);
+ void *(*get_internals)(struct ssl_connect_data *connssl, CURLINFO info);
+ void (*close_one)(struct connectdata *conn, int sockindex);
+ void (*close_all)(struct Curl_easy *data);
+ void (*session_free)(void *ptr);
+
+ CURLcode (*set_engine)(struct Curl_easy *data, const char *engine);
+ CURLcode (*set_engine_default)(struct Curl_easy *data);
+ struct curl_slist *(*engines_list)(struct Curl_easy *data);
+
+ bool (*false_start)(void);
+
+ CURLcode (*md5sum)(unsigned char *input, size_t inputlen,
+ unsigned char *md5sum, size_t md5sumlen);
+ CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen,
+ unsigned char *sha256sum, size_t sha256sumlen);
+};
+
+#ifdef USE_SSL
+extern const struct Curl_ssl *Curl_ssl;
+#endif
+
+int Curl_none_init(void);
+void Curl_none_cleanup(void);
+int Curl_none_shutdown(struct connectdata *conn, int sockindex);
+int Curl_none_check_cxn(struct connectdata *conn);
+CURLcode Curl_none_random(struct Curl_easy *data, unsigned char *entropy,
+ size_t length);
+void Curl_none_close_all(struct Curl_easy *data);
+void Curl_none_session_free(void *ptr);
+bool Curl_none_data_pending(const struct connectdata *conn, int connindex);
+bool Curl_none_cert_status_request(void);
+CURLcode Curl_none_set_engine(struct Curl_easy *data, const char *engine);
+CURLcode Curl_none_set_engine_default(struct Curl_easy *data);
+struct curl_slist *Curl_none_engines_list(struct Curl_easy *data);
+bool Curl_none_false_start(void);
+bool Curl_ssl_tls13_ciphersuites(void);
+CURLcode Curl_none_md5sum(unsigned char *input, size_t inputlen,
+ unsigned char *md5sum, size_t md5len);
+
#include "openssl.h" /* OpenSSL versions */
#include "gtls.h" /* GnuTLS versions */
#include "nssg.h" /* NSS versions */
#include "gskit.h" /* Global Secure ToolKit versions */
#include "polarssl.h" /* PolarSSL versions */
-#include "axtls.h" /* axTLS versions */
#include "cyassl.h" /* CyaSSL versions */
#include "schannel.h" /* Schannel SSPI version */
-#include "darwinssl.h" /* SecureTransport (Darwin) version */
+#include "sectransp.h" /* SecureTransport (Darwin) version */
#include "mbedtls.h" /* mbedTLS versions */
+#include "mesalink.h" /* MesaLink versions */
#ifndef MAX_PINNED_PUBKEY_SIZE
#define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1MB */
#endif
#ifndef MD5_DIGEST_LENGTH
+#ifndef LIBWOLFSSL_VERSION_HEX /* because WolfSSL borks this */
#define MD5_DIGEST_LENGTH 16 /* fixed size */
#endif
+#endif
-#ifndef SHA256_DIGEST_LENGTH
-#define SHA256_DIGEST_LENGTH 32 /* fixed size */
+#ifndef CURL_SHA256_DIGEST_LENGTH
+#define CURL_SHA256_DIGEST_LENGTH 32 /* fixed size */
#endif
/* see https://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg-04 */
@@ -171,9 +248,7 @@ bool Curl_ssl_false_start(void);
#define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
-#else
-/* Set the API backend definition to none */
-#define CURL_SSL_BACKEND CURLSSLBACKEND_NONE
+#else /* if not USE_SSL */
/* When SSL support is not present, just define away these function calls */
#define Curl_ssl_init() 1
@@ -197,6 +272,7 @@ bool Curl_ssl_false_start(void);
#define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN)
#define Curl_ssl_cert_status_request() FALSE
#define Curl_ssl_false_start() FALSE
+#define Curl_ssl_tls13_ciphersuites() FALSE
#endif
#endif /* HEADER_CURL_VTLS_H */
diff --git a/Utilities/cmcurl/lib/warnless.c b/Utilities/cmcurl/lib/warnless.c
index fb085c86d..cfd5e8e14 100644
--- a/Utilities/cmcurl/lib/warnless.c
+++ b/Utilities/cmcurl/lib/warnless.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -69,36 +69,36 @@
# error "SIZEOF_INT not defined"
#endif
-#if (CURL_SIZEOF_LONG == 2)
+#if (SIZEOF_LONG == 2)
# define CURL_MASK_SLONG 0x7FFFL
# define CURL_MASK_ULONG 0xFFFFUL
-#elif (CURL_SIZEOF_LONG == 4)
+#elif (SIZEOF_LONG == 4)
# define CURL_MASK_SLONG 0x7FFFFFFFL
# define CURL_MASK_ULONG 0xFFFFFFFFUL
-#elif (CURL_SIZEOF_LONG == 8)
+#elif (SIZEOF_LONG == 8)
# define CURL_MASK_SLONG 0x7FFFFFFFFFFFFFFFL
# define CURL_MASK_ULONG 0xFFFFFFFFFFFFFFFFUL
-#elif (CURL_SIZEOF_LONG == 16)
+#elif (SIZEOF_LONG == 16)
# define CURL_MASK_SLONG 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
# define CURL_MASK_ULONG 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
#else
-# error "CURL_SIZEOF_LONG not defined"
+# error "SIZEOF_LONG not defined"
#endif
-#if (CURL_SIZEOF_CURL_OFF_T == 2)
+#if (SIZEOF_CURL_OFF_T == 2)
# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFF)
# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFF)
-#elif (CURL_SIZEOF_CURL_OFF_T == 4)
+#elif (SIZEOF_CURL_OFF_T == 4)
# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFFFFFF)
# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFFFFFF)
-#elif (CURL_SIZEOF_CURL_OFF_T == 8)
+#elif (SIZEOF_CURL_OFF_T == 8)
# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFF)
-#elif (CURL_SIZEOF_CURL_OFF_T == 16)
+#elif (SIZEOF_CURL_OFF_T == 16)
# define CURL_MASK_SCOFFT CURL_OFF_T_C(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
# define CURL_MASK_UCOFFT CURL_OFF_TU_C(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
#else
-# error "CURL_SIZEOF_CURL_OFF_T not defined"
+# error "SIZEOF_CURL_OFF_T not defined"
#endif
#if (SIZEOF_SIZE_T == SIZEOF_SHORT)
@@ -107,10 +107,10 @@
#elif (SIZEOF_SIZE_T == SIZEOF_INT)
# define CURL_MASK_SSIZE_T CURL_MASK_SINT
# define CURL_MASK_USIZE_T CURL_MASK_UINT
-#elif (SIZEOF_SIZE_T == CURL_SIZEOF_LONG)
+#elif (SIZEOF_SIZE_T == SIZEOF_LONG)
# define CURL_MASK_SSIZE_T CURL_MASK_SLONG
# define CURL_MASK_USIZE_T CURL_MASK_ULONG
-#elif (SIZEOF_SIZE_T == CURL_SIZEOF_CURL_OFF_T)
+#elif (SIZEOF_SIZE_T == SIZEOF_CURL_OFF_T)
# define CURL_MASK_SSIZE_T CURL_MASK_SCOFFT
# define CURL_MASK_USIZE_T CURL_MASK_UCOFFT
#else
@@ -226,7 +226,7 @@ unsigned long curlx_uztoul(size_t uznum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
-#if (CURL_SIZEOF_LONG < SIZEOF_SIZE_T)
+#if (SIZEOF_LONG < SIZEOF_SIZE_T)
DEBUGASSERT(uznum <= (size_t) CURL_MASK_ULONG);
#endif
return (unsigned long)(uznum & (size_t) CURL_MASK_ULONG);
@@ -269,7 +269,7 @@ int curlx_sltosi(long slnum)
#endif
DEBUGASSERT(slnum >= 0);
-#if (SIZEOF_INT < CURL_SIZEOF_LONG)
+#if (SIZEOF_INT < SIZEOF_LONG)
DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_SINT);
#endif
return (int)(slnum & (long) CURL_MASK_SINT);
@@ -291,7 +291,7 @@ unsigned int curlx_sltoui(long slnum)
#endif
DEBUGASSERT(slnum >= 0);
-#if (SIZEOF_INT < CURL_SIZEOF_LONG)
+#if (SIZEOF_INT < SIZEOF_LONG)
DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_UINT);
#endif
return (unsigned int)(slnum & (long) CURL_MASK_UINT);
@@ -401,44 +401,6 @@ unsigned short curlx_uitous(unsigned int uinum)
}
/*
-** unsigned int to unsigned char
-*/
-
-unsigned char curlx_uitouc(unsigned int uinum)
-{
-#ifdef __INTEL_COMPILER
-# pragma warning(push)
-# pragma warning(disable:810) /* conversion may lose significant bits */
-#endif
-
- DEBUGASSERT(uinum <= (unsigned int) CURL_MASK_UCHAR);
- return (unsigned char) (uinum & (unsigned int) CURL_MASK_UCHAR);
-
-#ifdef __INTEL_COMPILER
-# pragma warning(pop)
-#endif
-}
-
-/*
-** unsigned int to signed int
-*/
-
-int curlx_uitosi(unsigned int uinum)
-{
-#ifdef __INTEL_COMPILER
-# pragma warning(push)
-# pragma warning(disable:810) /* conversion may lose significant bits */
-#endif
-
- DEBUGASSERT(uinum <= (unsigned int) CURL_MASK_SINT);
- return (int) (uinum & (unsigned int) CURL_MASK_SINT);
-
-#ifdef __INTEL_COMPILER
-# pragma warning(pop)
-#endif
-}
-
-/*
** signed int to unsigned size_t
*/
diff --git a/Utilities/cmcurl/lib/warnless.h b/Utilities/cmcurl/lib/warnless.h
index ab6d29998..ea4c4395d 100644
--- a/Utilities/cmcurl/lib/warnless.h
+++ b/Utilities/cmcurl/lib/warnless.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -26,6 +26,9 @@
#include <curl/curl.h> /* for curl_socket_t */
#endif
+#define CURLX_FUNCTION_CAST(target_type, func) \
+ (target_type)(void (*) (void))(func)
+
unsigned short curlx_ultous(unsigned long ulnum);
unsigned char curlx_ultouc(unsigned long ulnum);
@@ -54,10 +57,6 @@ int curlx_sztosi(ssize_t sznum);
unsigned short curlx_uitous(unsigned int uinum);
-unsigned char curlx_uitouc(unsigned int uinum);
-
-int curlx_uitosi(unsigned int uinum);
-
size_t curlx_sitouz(int sinum);
#ifdef USE_WINSOCK
diff --git a/Utilities/cmcurl/lib/wildcard.c b/Utilities/cmcurl/lib/wildcard.c
index af45c79bd..e94d3c544 100644
--- a/Utilities/cmcurl/lib/wildcard.c
+++ b/Utilities/cmcurl/lib/wildcard.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -22,6 +22,8 @@
#include "curl_setup.h"
+#ifndef CURL_DISABLE_FTP
+
#include "wildcard.h"
#include "llist.h"
#include "fileinfo.h"
@@ -30,9 +32,15 @@
#include "curl_memory.h"
#include "memdebug.h"
+static void fileinfo_dtor(void *user, void *element)
+{
+ (void)user;
+ Curl_fileinfo_cleanup(element);
+}
+
CURLcode Curl_wildcard_init(struct WildcardData *wc)
{
- Curl_llist_init(&wc->filelist, Curl_fileinfo_dtor);
+ Curl_llist_init(&wc->filelist, fileinfo_dtor);
wc->state = CURLWC_INIT;
return CURLE_OK;
@@ -43,12 +51,12 @@ void Curl_wildcard_dtor(struct WildcardData *wc)
if(!wc)
return;
- if(wc->tmp_dtor) {
- wc->tmp_dtor(wc->tmp);
- wc->tmp_dtor = ZERO_NULL;
- wc->tmp = NULL;
+ if(wc->dtor) {
+ wc->dtor(wc->protdata);
+ wc->dtor = ZERO_NULL;
+ wc->protdata = NULL;
}
- DEBUGASSERT(wc->tmp == NULL);
+ DEBUGASSERT(wc->protdata == NULL);
Curl_llist_destroy(&wc->filelist, NULL);
@@ -61,3 +69,5 @@ void Curl_wildcard_dtor(struct WildcardData *wc)
wc->customptr = NULL;
wc->state = CURLWC_INIT;
}
+
+#endif /* if disabled */
diff --git a/Utilities/cmcurl/lib/wildcard.h b/Utilities/cmcurl/lib/wildcard.h
index 8a5e4b769..306c8c99f 100644
--- a/Utilities/cmcurl/lib/wildcard.h
+++ b/Utilities/cmcurl/lib/wildcard.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2010 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2010 - 2019, 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
@@ -22,8 +22,9 @@
*
***************************************************************************/
-#include <curl/curl.h>
+#include "curl_setup.h"
+#ifndef CURL_DISABLE_FTP
#include "llist.h"
/* list of wildcard process states */
@@ -40,7 +41,7 @@ typedef enum {
will end */
} curl_wildcard_states;
-typedef void (*curl_wildcard_tmp_dtor)(void *ptr);
+typedef void (*curl_wildcard_dtor)(void *ptr);
/* struct keeping information about wildcard download process */
struct WildcardData {
@@ -48,8 +49,8 @@ struct WildcardData {
char *path; /* path to the directory, where we trying wildcard-match */
char *pattern; /* wildcard pattern */
struct curl_llist filelist; /* llist with struct Curl_fileinfo */
- void *tmp; /* pointer to protocol specific temporary data */
- curl_wildcard_tmp_dtor tmp_dtor;
+ void *protdata; /* pointer to protocol specific temporary data */
+ curl_wildcard_dtor dtor;
void *customptr; /* for CURLOPT_CHUNK_DATA pointer */
};
@@ -58,4 +59,9 @@ void Curl_wildcard_dtor(struct WildcardData *wc);
struct Curl_easy;
+#else
+/* FTP is disabled */
+#define Curl_wildcard_dtor(x)
+#endif
+
#endif /* HEADER_CURL_WILDCARD_H */
diff --git a/Utilities/cmcurl/lib/x509asn1.c b/Utilities/cmcurl/lib/x509asn1.c
index bba20233f..0c1256ba8 100644
--- a/Utilities/cmcurl/lib/x509asn1.c
+++ b/Utilities/cmcurl/lib/x509asn1.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2019, 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
@@ -40,10 +40,6 @@
#include "curl_memory.h"
#include "memdebug.h"
-/* For overflow checks. */
-#define CURL_SIZE_T_MAX ((size_t)-1)
-
-
/* ASN.1 OIDs. */
static const char cnOID[] = "2.5.4.3"; /* Common name. */
static const char sanOID[] = "2.5.29.17"; /* Subject alternative name. */
@@ -107,9 +103,12 @@ static const curl_OID OIDtable[] = {
* Please note there is no pretention here to rewrite a full SSL library.
*/
+static const char *getASN1Element(curl_asn1Element *elem,
+ const char *beg, const char *end)
+ WARN_UNUSED_RESULT;
-const char *Curl_getASN1Element(curl_asn1Element *elem,
- const char *beg, const char *end)
+static const char *getASN1Element(curl_asn1Element *elem,
+ const char *beg, const char *end)
{
unsigned char b;
unsigned long len;
@@ -121,7 +120,7 @@ const char *Curl_getASN1Element(curl_asn1Element *elem,
if an error occurs. */
if(!beg || !end || beg >= end || !*beg ||
(size_t)(end - beg) > CURL_ASN1_MAX)
- return (const char *) NULL;
+ return NULL;
/* Process header byte. */
elem->header = beg;
@@ -130,12 +129,12 @@ const char *Curl_getASN1Element(curl_asn1Element *elem,
elem->class = (b >> 6) & 3;
b &= 0x1F;
if(b == 0x1F)
- return (const char *) NULL; /* Long tag values not supported here. */
+ return NULL; /* Long tag values not supported here. */
elem->tag = b;
/* Process length. */
if(beg >= end)
- return (const char *) NULL;
+ return NULL;
b = (unsigned char) *beg++;
if(!(b & 0x80))
len = b;
@@ -143,74 +142,77 @@ const char *Curl_getASN1Element(curl_asn1Element *elem,
/* Unspecified length. Since we have all the data, we can determine the
effective length by skipping element until an end element is found. */
if(!elem->constructed)
- return (const char *) NULL;
+ return NULL;
elem->beg = beg;
while(beg < end && *beg) {
- beg = Curl_getASN1Element(&lelem, beg, end);
+ beg = getASN1Element(&lelem, beg, end);
if(!beg)
- return (const char *) NULL;
+ return NULL;
}
if(beg >= end)
- return (const char *) NULL;
+ return NULL;
elem->end = beg;
return beg + 1;
}
else if((unsigned)b > (size_t)(end - beg))
- return (const char *) NULL; /* Does not fit in source. */
+ return NULL; /* Does not fit in source. */
else {
/* Get long length. */
len = 0;
do {
if(len & 0xFF000000L)
- return (const char *) NULL; /* Lengths > 32 bits are not supported. */
+ return NULL; /* Lengths > 32 bits are not supported. */
len = (len << 8) | (unsigned char) *beg++;
} while(--b);
}
if(len > (size_t)(end - beg))
- return (const char *) NULL; /* Element data does not fit in source. */
+ return NULL; /* Element data does not fit in source. */
elem->beg = beg;
elem->end = beg + len;
return elem->end;
}
+/*
+ * Search the null terminated OID or OID identifier in local table.
+ * Return the table entry pointer or NULL if not found.
+ */
static const curl_OID * searchOID(const char *oid)
{
const curl_OID *op;
-
- /* Search the null terminated OID or OID identifier in local table.
- Return the table entry pointer or NULL if not found. */
-
for(op = OIDtable; op->numoid; op++)
if(!strcmp(op->numoid, oid) || strcasecompare(op->textoid, oid))
return op;
- return (const curl_OID *) NULL;
+ return NULL;
}
+/*
+ * Convert an ASN.1 Boolean value into its string representation. Return the
+ * dynamically allocated string, or NULL if source is not an ASN.1 Boolean
+ * value.
+ */
+
static const char *bool2str(const char *beg, const char *end)
{
- /* Convert an ASN.1 Boolean value into its string representation.
- Return the dynamically allocated string, or NULL if source is not an
- ASN.1 Boolean value. */
-
if(end - beg != 1)
- return (const char *) NULL;
+ return NULL;
return strdup(*beg? "TRUE": "FALSE");
}
+/*
+ * Convert an ASN.1 octet string to a printable string.
+ * Return the dynamically allocated string, or NULL if an error occurs.
+ */
static const char *octet2str(const char *beg, const char *end)
{
size_t n = end - beg;
char *buf = NULL;
- /* Convert an ASN.1 octet string to a printable string.
- Return the dynamically allocated string, or NULL if an error occurs. */
-
- if(n <= (CURL_SIZE_T_MAX - 1) / 3) {
+ if(n <= (SIZE_T_MAX - 1) / 3) {
buf = malloc(3 * n + 1);
if(buf)
for(n = 0; beg < end; n += 3)
- snprintf(buf + n, 4, "%02x:", *(const unsigned char *) beg++);
+ msnprintf(buf + n, 4, "%02x:", *(const unsigned char *) beg++);
}
return buf;
}
@@ -221,21 +223,22 @@ static const char *bit2str(const char *beg, const char *end)
Return the dynamically allocated string, or NULL if an error occurs. */
if(++beg > end)
- return (const char *) NULL;
+ return NULL;
return octet2str(beg, end);
}
+/*
+ * Convert an ASN.1 integer value into its string representation.
+ * Return the dynamically allocated string, or NULL if source is not an
+ * ASN.1 integer value.
+ */
static const char *int2str(const char *beg, const char *end)
{
- long val = 0;
+ unsigned long val = 0;
size_t n = end - beg;
- /* Convert an ASN.1 integer value into its string representation.
- Return the dynamically allocated string, or NULL if source is not an
- ASN.1 integer value. */
-
if(!n)
- return (const char *) NULL;
+ return NULL;
if(n > 4)
return octet2str(beg, end);
@@ -247,26 +250,25 @@ static const char *int2str(const char *beg, const char *end)
do
val = (val << 8) | *(const unsigned char *) beg++;
while(beg < end);
- return curl_maprintf("%s%lx", (val < 0 || val >= 10)? "0x": "", val);
+ return curl_maprintf("%s%lx", val >= 10? "0x": "", val);
}
+/*
+ * Perform a lazy conversion from an ASN.1 typed string to UTF8. Allocate the
+ * destination buffer dynamically. The allocation size will normally be too
+ * large: this is to avoid buffer overflows.
+ * Terminate the string with a nul byte and return the converted
+ * string length.
+ */
static ssize_t
utf8asn1str(char **to, int type, const char *from, const char *end)
{
size_t inlength = end - from;
int size = 1;
size_t outlength;
- int charsize;
- unsigned int wc;
char *buf;
- /* Perform a lazy conversion from an ASN.1 typed string to UTF8. Allocate the
- destination buffer dynamically. The allocation size will normally be too
- large: this is to avoid buffer overflows.
- Terminate the string with a nul byte and return the converted
- string length. */
-
- *to = (char *) NULL;
+ *to = NULL;
switch(type) {
case CURL_ASN1_BMP_STRING:
size = 2;
@@ -287,7 +289,7 @@ utf8asn1str(char **to, int type, const char *from, const char *end)
if(inlength % size)
return -1; /* Length inconsistent with character size. */
- if(inlength / size > (CURL_SIZE_T_MAX - 1) / 4)
+ if(inlength / size > (SIZE_T_MAX - 1) / 4)
return -1; /* Too big. */
buf = malloc(4 * (inlength / size) + 1);
if(!buf)
@@ -301,15 +303,18 @@ utf8asn1str(char **to, int type, const char *from, const char *end)
}
else {
for(outlength = 0; from < end;) {
+ int charsize;
+ unsigned int wc;
+
wc = 0;
switch(size) {
case 4:
wc = (wc << 8) | *(const unsigned char *) from++;
wc = (wc << 8) | *(const unsigned char *) from++;
- /* fallthrough */
+ /* FALLTHROUGH */
case 2:
wc = (wc << 8) | *(const unsigned char *) from++;
- /* fallthrough */
+ /* FALLTHROUGH */
default: /* case 1: */
wc = (wc << 8) | *(const unsigned char *) from++;
}
@@ -342,96 +347,105 @@ utf8asn1str(char **to, int type, const char *from, const char *end)
return outlength;
}
+/*
+ * Convert an ASN.1 String into its UTF-8 string representation.
+ * Return the dynamically allocated string, or NULL if an error occurs.
+ */
static const char *string2str(int type, const char *beg, const char *end)
{
char *buf;
-
- /* Convert an ASN.1 String into its UTF-8 string representation.
- Return the dynamically allocated string, or NULL if an error occurs. */
-
if(utf8asn1str(&buf, type, beg, end) < 0)
- return (const char *) NULL;
+ return NULL;
return buf;
}
-static int encodeUint(char *buf, int n, unsigned int x)
+/*
+ * Decimal ASCII encode unsigned integer `x' into the buflen sized buffer at
+ * buf. Return the total number of encoded digits, even if larger than
+ * `buflen'.
+ */
+static size_t encodeUint(char *buf, size_t buflen, unsigned int x)
{
- int i = 0;
+ size_t i = 0;
unsigned int y = x / 10;
- /* Decimal ASCII encode unsigned integer `x' in the `n'-byte buffer at `buf'.
- Return the total number of encoded digits, even if larger than `n'. */
-
if(y) {
- i += encodeUint(buf, n, y);
+ i = encodeUint(buf, buflen, y);
x -= y * 10;
}
- if(i < n)
+ if(i < buflen)
buf[i] = (char) ('0' + x);
i++;
- if(i < n)
+ if(i < buflen)
buf[i] = '\0'; /* Store a terminator if possible. */
return i;
}
-static int encodeOID(char *buf, int n, const char *beg, const char *end)
+/*
+ * Convert an ASN.1 OID into its dotted string representation.
+ * Store the result in th `n'-byte buffer at `buf'.
+ * Return the converted string length, or 0 on errors.
+ */
+static size_t encodeOID(char *buf, size_t buflen,
+ const char *beg, const char *end)
{
- int i = 0;
+ size_t i;
unsigned int x;
unsigned int y;
- /* Convert an ASN.1 OID into its dotted string representation.
- Store the result in th `n'-byte buffer at `buf'.
- Return the converted string length, or -1 if an error occurs. */
-
/* Process the first two numbers. */
y = *(const unsigned char *) beg++;
x = y / 40;
y -= x * 40;
- i += encodeUint(buf + i, n - i, x);
- if(i < n)
+ i = encodeUint(buf, buflen, x);
+ if(i < buflen)
buf[i] = '.';
i++;
- i += encodeUint(buf + i, n - i, y);
+ if(i >= buflen)
+ i += encodeUint(NULL, 0, y);
+ else
+ i += encodeUint(buf + i, buflen - i, y);
/* Process the trailing numbers. */
while(beg < end) {
- if(i < n)
+ if(i < buflen)
buf[i] = '.';
i++;
x = 0;
do {
if(x & 0xFF000000)
- return -1;
+ return 0;
y = *(const unsigned char *) beg++;
x = (x << 7) | (y & 0x7F);
} while(y & 0x80);
- i += encodeUint(buf + i, n - i, x);
+ if(i >= buflen)
+ i += encodeUint(NULL, 0, x);
+ else
+ i += encodeUint(buf + i, buflen - i, x);
}
- if(i < n)
+ if(i < buflen)
buf[i] = '\0';
return i;
}
+/*
+ * Convert an ASN.1 OID into its dotted or symbolic string representation.
+ * Return the dynamically allocated string, or NULL if an error occurs.
+ */
+
static const char *OID2str(const char *beg, const char *end, bool symbolic)
{
- char *buf = (char *) NULL;
- const curl_OID * op;
- int n;
-
- /* Convert an ASN.1 OID into its dotted or symbolic string representation.
- Return the dynamically allocated string, or NULL if an error occurs. */
-
+ char *buf = NULL;
if(beg < end) {
- n = encodeOID((char *) NULL, -1, beg, end);
- if(n >= 0) {
- buf = malloc(n + 1);
+ size_t buflen = encodeOID(NULL, 0, beg, end);
+ if(buflen) {
+ buf = malloc(buflen + 1); /* one extra for the zero byte */
if(buf) {
- encodeOID(buf, n, beg, end);
- buf[n] = '\0';
+ encodeOID(buf, buflen, beg, end);
+ buf[buflen] = '\0';
if(symbolic) {
- op = searchOID(buf);
+ const curl_OID *op = searchOID(buf);
if(op) {
free(buf);
buf = strdup(op->textoid);
@@ -471,7 +485,7 @@ static const char *GTime2str(const char *beg, const char *end)
sec2 = fracp[-1];
break;
default:
- return (const char *) NULL;
+ return NULL;
}
/* Scan for timezone, measure fractional seconds. */
@@ -507,15 +521,16 @@ static const char *GTime2str(const char *beg, const char *end)
sep, tzl, tzp);
}
+/*
+ * Convert an ASN.1 UTC time to a printable string.
+ * Return the dynamically allocated string, or NULL if an error occurs.
+ */
static const char *UTime2str(const char *beg, const char *end)
{
const char *tzp;
size_t tzl;
const char *sec;
- /* Convert an ASN.1 UTC time to a printable string.
- Return the dynamically allocated string, or NULL if an error occurs. */
-
for(tzp = beg; tzp < end && *tzp >= '0' && *tzp <= '9'; tzp++)
;
/* Get the seconds. */
@@ -526,12 +541,12 @@ static const char *UTime2str(const char *beg, const char *end)
case 2:
break;
default:
- return (const char *) NULL;
+ return NULL;
}
/* Process timezone. */
if(tzp >= end)
- return (const char *) NULL;
+ return NULL;
if(*tzp == 'Z') {
tzp = "GMT";
end = tzp + 3;
@@ -546,13 +561,14 @@ static const char *UTime2str(const char *beg, const char *end)
tzl, tzp);
}
-const char *Curl_ASN1tostr(curl_asn1Element *elem, int type)
+/*
+ * Convert an ASN.1 element to a printable string.
+ * Return the dynamically allocated string, or NULL if an error occurs.
+ */
+static const char *ASN1tostr(curl_asn1Element *elem, int type)
{
- /* Convert an ASN.1 element to a printable string.
- Return the dynamically allocated string, or NULL if an error occurs. */
-
if(elem->constructed)
- return (const char *) NULL; /* No conversion of structured elements. */
+ return NULL; /* No conversion of structured elements. */
if(!type)
type = elem->tag; /* Type not forced: use element tag as type. */
@@ -586,10 +602,14 @@ const char *Curl_ASN1tostr(curl_asn1Element *elem, int type)
return string2str(type, elem->beg, elem->end);
}
- return (const char *) NULL; /* Unsupported. */
+ return NULL; /* Unsupported. */
}
-static ssize_t encodeDN(char *buf, size_t n, curl_asn1Element *dn)
+/*
+ * ASCII encode distinguished name at `dn' into the `buflen'-sized buffer at
+ * `buf'. Return the total string length, even if larger than `buflen'.
+ */
+static ssize_t encodeDN(char *buf, size_t buflen, curl_asn1Element *dn)
{
curl_asn1Element rdn;
curl_asn1Element atv;
@@ -601,16 +621,20 @@ static ssize_t encodeDN(char *buf, size_t n, curl_asn1Element *dn)
const char *p3;
const char *str;
- /* ASCII encode distinguished name at `dn' into the `n'-byte buffer at `buf'.
- Return the total string length, even if larger than `n'. */
-
for(p1 = dn->beg; p1 < dn->end;) {
- p1 = Curl_getASN1Element(&rdn, p1, dn->end);
+ p1 = getASN1Element(&rdn, p1, dn->end);
+ if(!p1)
+ return -1;
for(p2 = rdn.beg; p2 < rdn.end;) {
- p2 = Curl_getASN1Element(&atv, p2, rdn.end);
- p3 = Curl_getASN1Element(&oid, atv.beg, atv.end);
- Curl_getASN1Element(&value, p3, atv.end);
- str = Curl_ASN1tostr(&oid, 0);
+ p2 = getASN1Element(&atv, p2, rdn.end);
+ if(!p2)
+ return -1;
+ p3 = getASN1Element(&oid, atv.beg, atv.end);
+ if(!p3)
+ return -1;
+ if(!getASN1Element(&value, p3, atv.end))
+ return -1;
+ str = ASN1tostr(&oid, 0);
if(!str)
return -1;
@@ -620,7 +644,7 @@ static ssize_t encodeDN(char *buf, size_t n, curl_asn1Element *dn)
for(p3 = str; isupper(*p3); p3++)
;
for(p3 = (*p3 || p3 - str > 2)? "/": ", "; *p3; p3++) {
- if(l < n)
+ if(l < buflen)
buf[l] = *p3;
l++;
}
@@ -628,23 +652,23 @@ static ssize_t encodeDN(char *buf, size_t n, curl_asn1Element *dn)
/* Encode attribute name. */
for(p3 = str; *p3; p3++) {
- if(l < n)
+ if(l < buflen)
buf[l] = *p3;
l++;
}
free((char *) str);
/* Generate equal sign. */
- if(l < n)
+ if(l < buflen)
buf[l] = '=';
l++;
/* Generate value. */
- str = Curl_ASN1tostr(&value, 0);
+ str = ASN1tostr(&value, 0);
if(!str)
return -1;
for(p3 = str; *p3; p3++) {
- if(l < n)
+ if(l < buflen)
buf[l] = *p3;
l++;
}
@@ -655,28 +679,30 @@ static ssize_t encodeDN(char *buf, size_t n, curl_asn1Element *dn)
return l;
}
-const char *Curl_DNtostr(curl_asn1Element *dn)
+/*
+ * Convert an ASN.1 distinguished name into a printable string.
+ * Return the dynamically allocated string, or NULL if an error occurs.
+ */
+static const char *DNtostr(curl_asn1Element *dn)
{
- char *buf = (char *) NULL;
- ssize_t n = encodeDN(buf, 0, dn);
-
- /* Convert an ASN.1 distinguished name into a printable string.
- Return the dynamically allocated string, or NULL if an error occurs. */
+ char *buf = NULL;
+ ssize_t buflen = encodeDN(NULL, 0, dn);
- if(n >= 0) {
- buf = malloc(n + 1);
+ if(buflen >= 0) {
+ buf = malloc(buflen + 1);
if(buf) {
- encodeDN(buf, n + 1, dn);
- buf[n] = '\0';
+ encodeDN(buf, buflen + 1, dn);
+ buf[buflen] = '\0';
}
}
- return (const char *) buf;
+ return buf;
}
/*
- * X509 parser.
+ * ASN.1 parse an X509 certificate into structure subfields.
+ * Syntax is assumed to have already been checked by the SSL backend.
+ * See RFC 5280.
*/
-
int Curl_parseX509(curl_X509certificate *cert,
const char *beg, const char *end)
{
@@ -685,26 +711,27 @@ int Curl_parseX509(curl_X509certificate *cert,
const char *ccp;
static const char defaultVersion = 0; /* v1. */
- /* ASN.1 parse an X509 certificate into structure subfields.
- Syntax is assumed to have already been checked by the SSL backend.
- See RFC 5280. */
-
cert->certificate.header = NULL;
cert->certificate.beg = beg;
cert->certificate.end = end;
/* Get the sequence content. */
- if(!Curl_getASN1Element(&elem, beg, end))
+ if(!getASN1Element(&elem, beg, end))
return -1; /* Invalid bounds/size. */
beg = elem.beg;
end = elem.end;
/* Get tbsCertificate. */
- beg = Curl_getASN1Element(&tbsCertificate, beg, end);
+ beg = getASN1Element(&tbsCertificate, beg, end);
+ if(!beg)
+ return -1;
/* Skip the signatureAlgorithm. */
- beg = Curl_getASN1Element(&cert->signatureAlgorithm, beg, end);
+ beg = getASN1Element(&cert->signatureAlgorithm, beg, end);
+ if(!beg)
+ return -1;
/* Get the signatureValue. */
- Curl_getASN1Element(&cert->signature, beg, end);
+ if(!getASN1Element(&cert->signature, beg, end))
+ return -1;
/* Parse TBSCertificate. */
beg = tbsCertificate.beg;
@@ -712,30 +739,49 @@ int Curl_parseX509(curl_X509certificate *cert,
/* Get optional version, get serialNumber. */
cert->version.header = NULL;
cert->version.beg = &defaultVersion;
- cert->version.end = &defaultVersion + sizeof defaultVersion;;
- beg = Curl_getASN1Element(&elem, beg, end);
+ cert->version.end = &defaultVersion + sizeof(defaultVersion);
+ beg = getASN1Element(&elem, beg, end);
+ if(!beg)
+ return -1;
if(elem.tag == 0) {
- Curl_getASN1Element(&cert->version, elem.beg, elem.end);
- beg = Curl_getASN1Element(&elem, beg, end);
+ if(!getASN1Element(&cert->version, elem.beg, elem.end))
+ return -1;
+ beg = getASN1Element(&elem, beg, end);
+ if(!beg)
+ return -1;
}
cert->serialNumber = elem;
/* Get signature algorithm. */
- beg = Curl_getASN1Element(&cert->signatureAlgorithm, beg, end);
+ beg = getASN1Element(&cert->signatureAlgorithm, beg, end);
/* Get issuer. */
- beg = Curl_getASN1Element(&cert->issuer, beg, end);
+ beg = getASN1Element(&cert->issuer, beg, end);
+ if(!beg)
+ return -1;
/* Get notBefore and notAfter. */
- beg = Curl_getASN1Element(&elem, beg, end);
- ccp = Curl_getASN1Element(&cert->notBefore, elem.beg, elem.end);
- Curl_getASN1Element(&cert->notAfter, ccp, elem.end);
+ beg = getASN1Element(&elem, beg, end);
+ if(!beg)
+ return -1;
+ ccp = getASN1Element(&cert->notBefore, elem.beg, elem.end);
+ if(!ccp)
+ return -1;
+ if(!getASN1Element(&cert->notAfter, ccp, elem.end))
+ return -1;
/* Get subject. */
- beg = Curl_getASN1Element(&cert->subject, beg, end);
+ beg = getASN1Element(&cert->subject, beg, end);
+ if(!beg)
+ return -1;
/* Get subjectPublicKeyAlgorithm and subjectPublicKey. */
- beg = Curl_getASN1Element(&cert->subjectPublicKeyInfo, beg, end);
- ccp = Curl_getASN1Element(&cert->subjectPublicKeyAlgorithm,
- cert->subjectPublicKeyInfo.beg,
- cert->subjectPublicKeyInfo.end);
- Curl_getASN1Element(&cert->subjectPublicKey, ccp,
- cert->subjectPublicKeyInfo.end);
+ beg = getASN1Element(&cert->subjectPublicKeyInfo, beg, end);
+ if(!beg)
+ return -1;
+ ccp = getASN1Element(&cert->subjectPublicKeyAlgorithm,
+ cert->subjectPublicKeyInfo.beg,
+ cert->subjectPublicKeyInfo.end);
+ if(!ccp)
+ return -1;
+ if(!getASN1Element(&cert->subjectPublicKey, ccp,
+ cert->subjectPublicKeyInfo.end))
+ return -1;
/* Get optional issuerUiqueID, subjectUniqueID and extensions. */
cert->issuerUniqueID.tag = cert->subjectUniqueID.tag = 0;
cert->extensions.tag = elem.tag = 0;
@@ -744,30 +790,41 @@ int Curl_parseX509(curl_X509certificate *cert,
cert->subjectUniqueID.beg = cert->subjectUniqueID.end = "";
cert->extensions.header = NULL;
cert->extensions.beg = cert->extensions.end = "";
- if(beg < end)
- beg = Curl_getASN1Element(&elem, beg, end);
+ if(beg < end) {
+ beg = getASN1Element(&elem, beg, end);
+ if(!beg)
+ return -1;
+ }
if(elem.tag == 1) {
cert->issuerUniqueID = elem;
- if(beg < end)
- beg = Curl_getASN1Element(&elem, beg, end);
+ if(beg < end) {
+ beg = getASN1Element(&elem, beg, end);
+ if(!beg)
+ return -1;
+ }
}
if(elem.tag == 2) {
cert->subjectUniqueID = elem;
- if(beg < end)
- beg = Curl_getASN1Element(&elem, beg, end);
+ if(beg < end) {
+ beg = getASN1Element(&elem, beg, end);
+ if(!beg)
+ return -1;
+ }
}
if(elem.tag == 3)
- Curl_getASN1Element(&cert->extensions, elem.beg, elem.end);
+ if(!getASN1Element(&cert->extensions, elem.beg, elem.end))
+ return -1;
return 0;
}
+
+/*
+ * Copy at most 64-characters, terminate with a newline and returns the
+ * effective number of stored characters.
+ */
static size_t copySubstring(char *to, const char *from)
{
size_t i;
-
- /* Copy at most 64-characters, terminate with a newline and returns the
- effective number of stored characters. */
-
for(i = 0; i < 64; i++) {
to[i] = *from;
if(!*from++)
@@ -785,12 +842,15 @@ static const char *dumpAlgo(curl_asn1Element *param,
/* Get algorithm parameters and return algorithm name. */
- beg = Curl_getASN1Element(&oid, beg, end);
+ beg = getASN1Element(&oid, beg, end);
+ if(!beg)
+ return NULL;
param->header = NULL;
param->tag = 0;
param->beg = param->end = end;
if(beg < end)
- Curl_getASN1Element(param, beg, end);
+ if(!getASN1Element(param, beg, end))
+ return NULL;
return OID2str(oid.beg, oid.end, TRUE);
}
@@ -801,7 +861,7 @@ static void do_pubkey_field(struct Curl_easy *data, int certnum,
/* Generate a certificate information record for the public key. */
- output = Curl_ASN1tostr(elem, 0);
+ output = ASN1tostr(elem, 0);
if(output) {
if(data->set.ssl.certinfo)
Curl_ssl_push_certinfo(data, certnum, label, output);
@@ -818,24 +878,30 @@ static void do_pubkey(struct Curl_easy *data, int certnum,
curl_asn1Element elem;
curl_asn1Element pk;
const char *p;
- const char *q;
- unsigned long len;
- unsigned int i;
/* Generate all information records for the public key. */
/* Get the public key (single element). */
- Curl_getASN1Element(&pk, pubkey->beg + 1, pubkey->end);
+ if(!getASN1Element(&pk, pubkey->beg + 1, pubkey->end))
+ return;
if(strcasecompare(algo, "rsaEncryption")) {
- p = Curl_getASN1Element(&elem, pk.beg, pk.end);
+ const char *q;
+ unsigned long len;
+
+ p = getASN1Element(&elem, pk.beg, pk.end);
+ if(!p)
+ return;
+
/* Compute key length. */
for(q = elem.beg; !*q && q < elem.end; q++)
;
len = (unsigned long)((elem.end - q) * 8);
- if(len)
+ if(len) {
+ unsigned int i;
for(i = *(unsigned char *) q; !(i & 0x80); i <<= 1)
len--;
+ }
if(len > 32)
elem.beg = q; /* Strip leading zero bytes. */
if(!certnum)
@@ -849,30 +915,34 @@ static void do_pubkey(struct Curl_easy *data, int certnum,
}
/* Generate coefficients. */
do_pubkey_field(data, certnum, "rsa(n)", &elem);
- Curl_getASN1Element(&elem, p, pk.end);
+ if(!getASN1Element(&elem, p, pk.end))
+ return;
do_pubkey_field(data, certnum, "rsa(e)", &elem);
}
else if(strcasecompare(algo, "dsa")) {
- p = Curl_getASN1Element(&elem, param->beg, param->end);
- do_pubkey_field(data, certnum, "dsa(p)", &elem);
- p = Curl_getASN1Element(&elem, p, param->end);
- do_pubkey_field(data, certnum, "dsa(q)", &elem);
- Curl_getASN1Element(&elem, p, param->end);
- do_pubkey_field(data, certnum, "dsa(g)", &elem);
- do_pubkey_field(data, certnum, "dsa(pub_key)", &pk);
+ p = getASN1Element(&elem, param->beg, param->end);
+ if(p) {
+ do_pubkey_field(data, certnum, "dsa(p)", &elem);
+ p = getASN1Element(&elem, p, param->end);
+ if(p) {
+ do_pubkey_field(data, certnum, "dsa(q)", &elem);
+ if(getASN1Element(&elem, p, param->end)) {
+ do_pubkey_field(data, certnum, "dsa(g)", &elem);
+ do_pubkey_field(data, certnum, "dsa(pub_key)", &pk);
+ }
+ }
+ }
}
else if(strcasecompare(algo, "dhpublicnumber")) {
- p = Curl_getASN1Element(&elem, param->beg, param->end);
- do_pubkey_field(data, certnum, "dh(p)", &elem);
- Curl_getASN1Element(&elem, param->beg, param->end);
- do_pubkey_field(data, certnum, "dh(g)", &elem);
- do_pubkey_field(data, certnum, "dh(pub_key)", &pk);
- }
-#if 0 /* Patent-encumbered. */
- else if(strcasecompare(algo, "ecPublicKey")) {
- /* Left TODO. */
+ p = getASN1Element(&elem, param->beg, param->end);
+ if(p) {
+ do_pubkey_field(data, certnum, "dh(p)", &elem);
+ if(getASN1Element(&elem, param->beg, param->end)) {
+ do_pubkey_field(data, certnum, "dh(g)", &elem);
+ do_pubkey_field(data, certnum, "dh(pub_key)", &pk);
+ }
+ }
}
-#endif
}
CURLcode Curl_extract_certinfo(struct connectdata *conn,
@@ -900,10 +970,10 @@ CURLcode Curl_extract_certinfo(struct connectdata *conn,
/* Extract the certificate ASN.1 elements. */
if(Curl_parseX509(&cert, beg, end))
- return CURLE_OUT_OF_MEMORY;
+ return CURLE_PEER_FAILED_VERIFICATION;
/* Subject. */
- ccp = Curl_DNtostr(&cert.subject);
+ ccp = DNtostr(&cert.subject);
if(!ccp)
return CURLE_OUT_OF_MEMORY;
if(data->set.ssl.certinfo)
@@ -913,7 +983,7 @@ CURLcode Curl_extract_certinfo(struct connectdata *conn,
free((char *) ccp);
/* Issuer. */
- ccp = Curl_DNtostr(&cert.issuer);
+ ccp = DNtostr(&cert.issuer);
if(!ccp)
return CURLE_OUT_OF_MEMORY;
if(data->set.ssl.certinfo)
@@ -937,7 +1007,7 @@ CURLcode Curl_extract_certinfo(struct connectdata *conn,
infof(data, " Version: %lu (0x%lx)\n", version + 1, version);
/* Serial number. */
- ccp = Curl_ASN1tostr(&cert.serialNumber, 0);
+ ccp = ASN1tostr(&cert.serialNumber, 0);
if(!ccp)
return CURLE_OUT_OF_MEMORY;
if(data->set.ssl.certinfo)
@@ -958,7 +1028,7 @@ CURLcode Curl_extract_certinfo(struct connectdata *conn,
free((char *) ccp);
/* Start Date. */
- ccp = Curl_ASN1tostr(&cert.notBefore, 0);
+ ccp = ASN1tostr(&cert.notBefore, 0);
if(!ccp)
return CURLE_OUT_OF_MEMORY;
if(data->set.ssl.certinfo)
@@ -968,7 +1038,7 @@ CURLcode Curl_extract_certinfo(struct connectdata *conn,
free((char *) ccp);
/* Expire Date. */
- ccp = Curl_ASN1tostr(&cert.notAfter, 0);
+ ccp = ASN1tostr(&cert.notAfter, 0);
if(!ccp)
return CURLE_OUT_OF_MEMORY;
if(data->set.ssl.certinfo)
@@ -989,10 +1059,8 @@ CURLcode Curl_extract_certinfo(struct connectdata *conn,
do_pubkey(data, certnum, ccp, &param, &cert.subjectPublicKey);
free((char *) ccp);
-/* TODO: extensions. */
-
/* Signature. */
- ccp = Curl_ASN1tostr(&cert.signature, 0);
+ ccp = ASN1tostr(&cert.signature, 0);
if(!ccp)
return CURLE_OUT_OF_MEMORY;
if(data->set.ssl.certinfo)
@@ -1051,17 +1119,17 @@ static const char *checkOID(const char *beg, const char *end,
/* Check if first ASN.1 element at `beg' is the given OID.
Return a pointer in the source after the OID if found, else NULL. */
- ccp = Curl_getASN1Element(&e, beg, end);
+ ccp = getASN1Element(&e, beg, end);
if(!ccp || e.tag != CURL_ASN1_OBJECT_IDENTIFIER)
- return (const char *) NULL;
+ return NULL;
p = OID2str(e.beg, e.end, FALSE);
if(!p)
- return (const char *) NULL;
+ return NULL;
matched = !strcmp(p, oid);
free((char *) p);
- return matched? ccp: (const char *) NULL;
+ return matched? ccp: NULL;
}
CURLcode Curl_verifyhost(struct connectdata *conn,
@@ -1110,19 +1178,30 @@ CURLcode Curl_verifyhost(struct connectdata *conn,
/* Process extensions. */
for(p = cert.extensions.beg; p < cert.extensions.end && matched != 1;) {
- p = Curl_getASN1Element(&ext, p, cert.extensions.end);
+ p = getASN1Element(&ext, p, cert.extensions.end);
+ if(!p)
+ return CURLE_PEER_FAILED_VERIFICATION;
+
/* Check if extension is a subjectAlternativeName. */
ext.beg = checkOID(ext.beg, ext.end, sanOID);
if(ext.beg) {
- ext.beg = Curl_getASN1Element(&elem, ext.beg, ext.end);
+ ext.beg = getASN1Element(&elem, ext.beg, ext.end);
+ if(!ext.beg)
+ return CURLE_PEER_FAILED_VERIFICATION;
/* Skip critical if present. */
- if(elem.tag == CURL_ASN1_BOOLEAN)
- ext.beg = Curl_getASN1Element(&elem, ext.beg, ext.end);
+ if(elem.tag == CURL_ASN1_BOOLEAN) {
+ ext.beg = getASN1Element(&elem, ext.beg, ext.end);
+ if(!ext.beg)
+ return CURLE_PEER_FAILED_VERIFICATION;
+ }
/* Parse the octet string contents: is a single sequence. */
- Curl_getASN1Element(&elem, elem.beg, elem.end);
+ if(!getASN1Element(&elem, elem.beg, elem.end))
+ return CURLE_PEER_FAILED_VERIFICATION;
/* Check all GeneralNames. */
for(q = elem.beg; matched != 1 && q < elem.end;) {
- q = Curl_getASN1Element(&name, q, elem.end);
+ q = getASN1Element(&name, q, elem.end);
+ if(!q)
+ break;
switch(name.tag) {
case 2: /* DNS name. */
len = utf8asn1str(&dnsname, CURL_ASN1_IA5_STRING,
@@ -1135,8 +1214,8 @@ CURLcode Curl_verifyhost(struct connectdata *conn,
break;
case 7: /* IP address. */
- matched = (size_t) (name.end - q) == addrlen &&
- !memcmp(&addr, q, addrlen);
+ matched = (size_t) (name.end - name.beg) == addrlen &&
+ !memcmp(&addr, name.beg, addrlen);
break;
}
}
@@ -1162,9 +1241,13 @@ CURLcode Curl_verifyhost(struct connectdata *conn,
/* we have to look to the last occurrence of a commonName in the
distinguished one to get the most significant one. */
while(q < cert.subject.end) {
- q = Curl_getASN1Element(&dn, q, cert.subject.end);
+ q = getASN1Element(&dn, q, cert.subject.end);
+ if(!q)
+ break;
for(p = dn.beg; p < dn.end;) {
- p = Curl_getASN1Element(&elem, p, dn.end);
+ p = getASN1Element(&elem, p, dn.end);
+ if(!p)
+ return CURLE_PEER_FAILED_VERIFICATION;
/* We have a DN's AttributeTypeAndValue: check it in case it's a CN. */
elem.beg = checkOID(elem.beg, elem.end, cnOID);
if(elem.beg)
@@ -1173,7 +1256,7 @@ CURLcode Curl_verifyhost(struct connectdata *conn,
}
/* Check the CN if found. */
- if(!Curl_getASN1Element(&elem, name.beg, name.end))
+ if(!getASN1Element(&elem, name.beg, name.end))
failf(data, "SSL: unable to obtain common name from peer certificate");
else {
len = utf8asn1str(&dnsname, elem.tag, elem.beg, elem.end);
diff --git a/Utilities/cmexpat/CMakeLists.txt b/Utilities/cmexpat/CMakeLists.txt
index 470fcba99..13eb56dd4 100644
--- a/Utilities/cmexpat/CMakeLists.txt
+++ b/Utilities/cmexpat/CMakeLists.txt
@@ -1,6 +1,6 @@
# Disable warnings to avoid changing 3rd party code.
IF(CMAKE_C_COMPILER_ID MATCHES
- "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
diff --git a/Utilities/cmexpat/ConfigureChecks.cmake b/Utilities/cmexpat/ConfigureChecks.cmake
index 057cfa58d..b2edc3e0a 100644
--- a/Utilities/cmexpat/ConfigureChecks.cmake
+++ b/Utilities/cmexpat/ConfigureChecks.cmake
@@ -1,6 +1,7 @@
+include(CheckCCompilerFlag)
+include(CheckCSourceCompiles)
include(CheckIncludeFile)
include(CheckIncludeFiles)
-include(CheckFunctionExists)
include(CheckSymbolExists)
include(TestBigEndian)
@@ -16,10 +17,21 @@ check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
-check_function_exists("getpagesize" HAVE_GETPAGESIZE)
-check_function_exists("bcopy" HAVE_BCOPY)
-check_symbol_exists("memmove" "string.h" HAVE_MEMMOVE)
-check_function_exists("mmap" HAVE_MMAP)
+check_symbol_exists("getpagesize" "unistd.h" HAVE_GETPAGESIZE)
+check_symbol_exists("mmap" "sys/mman.h" HAVE_MMAP)
+check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM)
+
+if(USE_libbsd)
+ set(CMAKE_REQUIRED_LIBRARIES "${LIB_BSD}")
+ set(_bsd "bsd/")
+else()
+ set(_bsd "")
+endif()
+check_symbol_exists("arc4random_buf" "${_bsd}stdlib.h" HAVE_ARC4RANDOM_BUF)
+if(NOT HAVE_ARC4RANDOM_BUF)
+ check_symbol_exists("arc4random" "${_bsd}stdlib.h" HAVE_ARC4RANDOM)
+endif()
+set(CMAKE_REQUIRED_LIBRARIES)
#/* Define to 1 if you have the ANSI C header files. */
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
@@ -40,5 +52,18 @@ else(HAVE_SYS_TYPES_H)
set(SIZE_T "unsigned")
endif(HAVE_SYS_TYPES_H)
+check_c_source_compiles("
+ #include <stdlib.h> /* for NULL */
+ #include <unistd.h> /* for syscall */
+ #include <sys/syscall.h> /* for SYS_getrandom */
+ int main() {
+ syscall(SYS_getrandom, NULL, 0, 0);
+ return 0;
+ }"
+ HAVE_SYSCALL_GETRANDOM)
+
configure_file(expat_config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/expat_config.h")
add_definitions(-DHAVE_EXPAT_CONFIG_H)
+
+check_c_compiler_flag("-fno-strict-aliasing" FLAG_NO_STRICT_ALIASING)
+check_c_compiler_flag("-fvisibility=hidden" FLAG_VISIBILITY)
diff --git a/Utilities/cmexpat/README.md b/Utilities/cmexpat/README.md
index 0a1777e7e..fd3911ebc 100644
--- a/Utilities/cmexpat/README.md
+++ b/Utilities/cmexpat/README.md
@@ -1,4 +1,9 @@
-# Expat, Release 2.2.3
+[![Travis CI Build Status](https://travis-ci.org/libexpat/libexpat.svg?branch=master)](https://travis-ci.org/libexpat/libexpat)
+[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/libexpat/libexpat?svg=true)](https://ci.appveyor.com/project/libexpat/libexpat)
+[![Packaging status](https://repology.org/badge/tiny-repos/expat.svg)](https://repology.org/metapackage/expat/versions)
+
+
+# Expat, Release 2.2.7
This is Expat, a C library for parsing XML, started by
[James Clark](https://en.wikipedia.org/wiki/James_Clark_(programmer)) in 1997.
@@ -72,47 +77,43 @@ the directories into which things will be installed.
If you are interested in building Expat to provide document
information in UTF-16 encoding rather than the default UTF-8, follow
-these instructions (after having run `make distclean`):
+these instructions (after having run `make distclean`).
+Please note that we configure with `--without-xmlwf` as xmlwf does not
+support this mode of compilation (yet):
+
+1. Mass-patch `Makefile.am` files to use `libexpatw.la` for a library name:
+ <br/>
+ `find -name Makefile.am -exec sed
+ -e 's,libexpat\.la,libexpatw.la,'
+ -e 's,libexpat_la,libexpatw_la,'
+ -i {} +`
+
+1. Run `automake` to re-write `Makefile.in` files:<br/>
+ `automake`
1. For UTF-16 output as unsigned short (and version/error strings as char),
run:<br/>
- `./configure CPPFLAGS=-DXML_UNICODE`<br/>
+ `./configure CPPFLAGS=-DXML_UNICODE --without-xmlwf`<br/>
For UTF-16 output as `wchar_t` (incl. version/error strings), run:<br/>
- `./configure CFLAGS="-g -O2 -fshort-wchar" CPPFLAGS=-DXML_UNICODE_WCHAR_T`
+ `./configure CFLAGS="-g -O2 -fshort-wchar" CPPFLAGS=-DXML_UNICODE_WCHAR_T
+ --without-xmlwf`
<br/>Note: The latter requires libc compiled with `-fshort-wchar`, as well.
-1. Edit `Makefile`, changing:<br/>
- `LIBRARY = libexpat.la`<br/>
- to:<br/>
- `LIBRARY = libexpatw.la`<br/>
- (Note the additional "w" in the library name.)
+1. Run `make` (which excludes xmlwf).
-1. Run `make buildlib` (which builds the library only).
- Or, to save step 2, run `make buildlib LIBRARY=libexpatw.la`.
+1. Run `make install` (again, excludes xmlwf).
-1. Run `make installlib` (which installs the library only).
- Or, if step 2 was omitted, run `make installlib LIBRARY=libexpatw.la`.
-
-Using `DESTDIR` or `INSTALL_ROOT` is enabled, with `INSTALL_ROOT` being the
-default value for `DESTDIR`, and the rest of the make file using only
-`DESTDIR`. It works as follows:
+Using `DESTDIR` is supported. It works as follows:
```console
make install DESTDIR=/path/to/image
```
-overrides the in-makefile set `DESTDIR`, while both
-
-```console
-INSTALL_ROOT=/path/to/image make install
-make install INSTALL_ROOT=/path/to/image
-```
+overrides the in-makefile set `DESTDIR`, because variable-setting priority is
-use `DESTDIR=$(INSTALL_ROOT)`, even if `DESTDIR` eventually is defined in the
-environment, because variable-setting priority is
1. commandline
-2. in-makefile
-3. environment
+1. in-makefile
+1. environment
Note: This only applies to the Expat library itself, building UTF-16 versions
of xmlwf and the tests is currently not supported.
diff --git a/Utilities/cmexpat/expat_config.h.cmake b/Utilities/cmexpat/expat_config.h.cmake
index ad540d604..899d3a615 100644
--- a/Utilities/cmexpat/expat_config.h.cmake
+++ b/Utilities/cmexpat/expat_config.h.cmake
@@ -1,10 +1,13 @@
-/* expat_config.h.in. Generated from configure.in by autoheader. */
+/* expat_config.h.cmake. Based upon generated expat_config.h.in. */
/* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */
#cmakedefine BYTEORDER @BYTEORDER@
-/* Define to 1 if you have the `bcopy' function. */
-#cmakedefine HAVE_BCOPY
+/* Define to 1 if you have the `arc4random' function. */
+#cmakedefine HAVE_ARC4RANDOM
+
+/* Define to 1 if you have the `arc4random_buf' function. */
+#cmakedefine HAVE_ARC4RANDOM_BUF
/* Define to 1 if you have the <dlfcn.h> header file. */
#cmakedefine HAVE_DLFCN_H
@@ -15,11 +18,14 @@
/* Define to 1 if you have the `getpagesize' function. */
#cmakedefine HAVE_GETPAGESIZE
+/* Define to 1 if you have the `getrandom' function. */
+#cmakedefine HAVE_GETRANDOM
+
/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H
-/* Define to 1 if you have the `memmove' function. */
-#cmakedefine HAVE_MEMMOVE
+/* Define to 1 if you have the `bsd' library (-lbsd). */
+#cmakedefine HAVE_LIBBSD
/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H
@@ -39,6 +45,9 @@
/* Define to 1 if you have the <string.h> header file. */
#cmakedefine HAVE_STRING_H
+/* Define to 1 if you have `syscall' and `SYS_getrandom'. */
+#cmakedefine HAVE_SYSCALL_GETRANDOM
+
/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H
@@ -64,6 +73,17 @@
/* Define to make XML Namespaces functionality available. */
/* #undef XML_NS */
+#if ! defined(_WIN32)
+/* Define to extract entropy from /dev/urandom. */
+#cmakedefine XML_DEV_URANDOM
+#endif
+
+/* Define to use UTF-16 chars (two bytes). */
+#cmakedefine XML_UNICODE
+
+/* Define to use wchar_t as UTF-16 char type instead of unsigned short. */
+#cmakedefine XML_UNICODE_WCHAR_T
+
/* Define to __FUNCTION__ or "" if `__func__' does not conform to ANSI C. */
#ifdef _MSC_VER
# define __func__ __FUNCTION__
diff --git a/Utilities/cmexpat/lib/ascii.h b/Utilities/cmexpat/lib/ascii.h
index d10530b09..c3587e573 100644
--- a/Utilities/cmexpat/lib/ascii.h
+++ b/Utilities/cmexpat/lib/ascii.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#define ASCII_A 0x41
diff --git a/Utilities/cmexpat/lib/asciitab.h b/Utilities/cmexpat/lib/asciitab.h
index 79a15c28c..2f59fd929 100644
--- a/Utilities/cmexpat/lib/asciitab.h
+++ b/Utilities/cmexpat/lib/asciitab.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML,
diff --git a/Utilities/cmexpat/lib/expat.h b/Utilities/cmexpat/lib/expat.h
index 7e5bbb7e3..c050f1d91 100644
--- a/Utilities/cmexpat/lib/expat.h
+++ b/Utilities/cmexpat/lib/expat.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#ifndef Expat_INCLUDED
@@ -236,7 +264,7 @@ XML_ParserCreate_MM(const XML_Char *encoding,
const XML_Char *namespaceSeparator);
/* Prepare a parser object to be re-used. This is particularly
- valuable when memory allocation overhead is disproportionatly high,
+ valuable when memory allocation overhead is disproportionately high,
such as when a large number of small documnents need to be parsed.
All handlers are cleared from the parser, except for the
unknownEncodingHandler. The parser's external state is re-initialized
@@ -1048,7 +1076,7 @@ XML_GetFeatureList(void);
*/
#define XML_MAJOR_VERSION 2
#define XML_MINOR_VERSION 2
-#define XML_MICRO_VERSION 3
+#define XML_MICRO_VERSION 7
#ifdef __cplusplus
}
diff --git a/Utilities/cmexpat/lib/expat_external.h b/Utilities/cmexpat/lib/expat_external.h
index d60eeccfb..4e14470e8 100644
--- a/Utilities/cmexpat/lib/expat_external.h
+++ b/Utilities/cmexpat/lib/expat_external.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#ifndef Expat_External_INCLUDED
@@ -8,7 +36,7 @@
/* External API definitions */
#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__)
-#define XML_USE_MSC_EXTENSIONS 1
+# define XML_USE_MSC_EXTENSIONS 1
#endif
/* Expat tries very hard to make the API boundary very specifically
@@ -34,11 +62,11 @@
system headers may assume the cdecl convention.
*/
#ifndef XMLCALL
-#if defined(_MSC_VER)
-#define XMLCALL __cdecl
-#elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER)
-#define XMLCALL __attribute__((cdecl))
-#else
+# if defined(_MSC_VER)
+# define XMLCALL __cdecl
+# elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER)
+# define XMLCALL __attribute__((cdecl))
+# else
/* For any platform which uses this definition and supports more than
one calling convention, we need to extend this definition to
declare the convention used on that platform, if it's possible to
@@ -49,43 +77,47 @@
pre-processor and how to specify the same calling convention as the
platform's malloc() implementation.
*/
-#define XMLCALL
-#endif
+# define XMLCALL
+# endif
#endif /* not defined XMLCALL */
/* Build within CMake hard-codes use of a static library. */
#define XML_STATIC
#if !defined(XML_STATIC) && !defined(XMLIMPORT)
-#ifndef XML_BUILDING_EXPAT
+# ifndef XML_BUILDING_EXPAT
/* using Expat from an application */
-#ifdef XML_USE_MSC_EXTENSIONS
-#define XMLIMPORT __declspec(dllimport)
-#endif
+# ifdef XML_USE_MSC_EXTENSIONS
+# define XMLIMPORT __declspec(dllimport)
+# endif
-#endif
+# endif
#endif /* not defined XML_STATIC */
-#if !defined(XMLIMPORT) && defined(__GNUC__) && (__GNUC__ >= 4)
-#define XMLIMPORT __attribute__ ((visibility ("default")))
+#ifndef XML_ENABLE_VISIBILITY
+# define XML_ENABLE_VISIBILITY 0
+#endif
+
+#if !defined(XMLIMPORT) && XML_ENABLE_VISIBILITY
+# define XMLIMPORT __attribute__ ((visibility ("default")))
#endif
/* If we didn't define it above, define it away: */
#ifndef XMLIMPORT
-#define XMLIMPORT
+# define XMLIMPORT
#endif
#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
-#define XML_ATTR_MALLOC __attribute__((__malloc__))
+# define XML_ATTR_MALLOC __attribute__((__malloc__))
#else
-#define XML_ATTR_MALLOC
+# define XML_ATTR_MALLOC
#endif
#if defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
-#define XML_ATTR_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
+# define XML_ATTR_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
#else
-#define XML_ATTR_ALLOC_SIZE(x)
+# define XML_ATTR_ALLOC_SIZE(x)
#endif
#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL
@@ -95,33 +127,35 @@ extern "C" {
#endif
#ifdef XML_UNICODE_WCHAR_T
-# define XML_UNICODE
+# ifndef XML_UNICODE
+# define XML_UNICODE
+# endif
# if defined(__SIZEOF_WCHAR_T__) && (__SIZEOF_WCHAR_T__ != 2)
# error "sizeof(wchar_t) != 2; Need -fshort-wchar for both Expat and libc"
# endif
#endif
#ifdef XML_UNICODE /* Information is UTF-16 encoded. */
-#ifdef XML_UNICODE_WCHAR_T
+# ifdef XML_UNICODE_WCHAR_T
typedef wchar_t XML_Char;
typedef wchar_t XML_LChar;
-#else
+# else
typedef unsigned short XML_Char;
typedef char XML_LChar;
-#endif /* XML_UNICODE_WCHAR_T */
+# endif /* XML_UNICODE_WCHAR_T */
#else /* Information is UTF-8 encoded. */
typedef char XML_Char;
typedef char XML_LChar;
#endif /* XML_UNICODE */
#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */
-#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
+# if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
typedef __int64 XML_Index;
typedef unsigned __int64 XML_Size;
-#else
+# else
typedef long long XML_Index;
typedef unsigned long long XML_Size;
-#endif
+# endif
#else
typedef long XML_Index;
typedef unsigned long XML_Size;
diff --git a/Utilities/cmexpat/lib/iasciitab.h b/Utilities/cmexpat/lib/iasciitab.h
index 24a1d5ccc..ce4a4bf7e 100644
--- a/Utilities/cmexpat/lib/iasciitab.h
+++ b/Utilities/cmexpat/lib/iasciitab.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */
diff --git a/Utilities/cmexpat/lib/internal.h b/Utilities/cmexpat/lib/internal.h
index 94cb98e15..dc4ef0c7e 100644
--- a/Utilities/cmexpat/lib/internal.h
+++ b/Utilities/cmexpat/lib/internal.h
@@ -18,6 +18,35 @@
Note: Use of these macros is based on judgement, not hard rules,
and therefore subject to change.
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#if defined(__GNUC__) && defined(__i386__) && !defined(__MINGW32__)
@@ -86,8 +115,13 @@ extern "C" {
#endif
+#ifdef XML_ENABLE_VISIBILITY
+#if XML_ENABLE_VISIBILITY
+__attribute__ ((visibility ("default")))
+#endif
+#endif
void
-align_limit_to_full_utf8_characters(const char * from, const char ** fromLimRef);
+_INTERNAL_trim_to_complete_utf8_characters(const char * from, const char ** fromLimRef);
#ifdef __cplusplus
diff --git a/Utilities/cmexpat/lib/latin1tab.h b/Utilities/cmexpat/lib/latin1tab.h
index 53c25d76b..95dfa52b1 100644
--- a/Utilities/cmexpat/lib/latin1tab.h
+++ b/Utilities/cmexpat/lib/latin1tab.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER,
diff --git a/Utilities/cmexpat/lib/loadlibrary.c b/Utilities/cmexpat/lib/loadlibrary.c
index ffce86839..35fdf98bc 100644
--- a/Utilities/cmexpat/lib/loadlibrary.c
+++ b/Utilities/cmexpat/lib/loadlibrary.c
@@ -6,8 +6,10 @@
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2016 - 2017, Steve Holme, <steve_holme@hotmail.com>.
+ * Copyright (C) 2017, Expat development team
*
* All rights reserved.
+ * Licensed under the MIT license:
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -82,7 +84,7 @@ HMODULE _Expat_LoadLibrary(LPCTSTR filename)
/* Get a handle to kernel32 so we can access it's functions at runtime */
HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32"));
if(!hKernel32)
- return NULL;
+ return NULL; /* LCOV_EXCL_LINE */
/* Attempt to find LoadLibraryEx() which is only available on Windows 2000
and above */
diff --git a/Utilities/cmexpat/lib/nametab.h b/Utilities/cmexpat/lib/nametab.h
index b05e62c77..bfa2bd38c 100644
--- a/Utilities/cmexpat/lib/nametab.h
+++ b/Utilities/cmexpat/lib/nametab.h
@@ -1,3 +1,35 @@
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
+*/
+
static const unsigned namingBitmap[] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
diff --git a/Utilities/cmexpat/lib/siphash.h b/Utilities/cmexpat/lib/siphash.h
index 1684b251d..3caabebe2 100644
--- a/Utilities/cmexpat/lib/siphash.h
+++ b/Utilities/cmexpat/lib/siphash.h
@@ -11,6 +11,12 @@
* --------------------------------------------------------------------------
* HISTORY:
*
+ * 2018-07-08 (Anton Maklakov)
+ * - Add "fall through" markers for GCC's -Wimplicit-fallthrough
+ *
+ * 2017-11-03 (Sebastian Pipping)
+ * - Hide sip_tobin and sip_binof unless SIPHASH_TOBIN macro is defined
+ *
* 2017-07-25 (Vadim Zeitlin)
* - Fix use of SIPHASH_MAIN macro
*
@@ -154,6 +160,8 @@ static struct sipkey *sip_tokey(struct sipkey *key, const void *src) {
} /* sip_tokey() */
+#ifdef SIPHASH_TOBIN
+
#define sip_binof(v) sip_tobin((unsigned char[8]){ 0 }, (v))
static void *sip_tobin(void *dst, uint64_t u64) {
@@ -161,6 +169,8 @@ static void *sip_tobin(void *dst, uint64_t u64) {
return dst;
} /* sip_tobin() */
+#endif /* SIPHASH_TOBIN */
+
static void sip_round(struct siphash *H, const int rounds) {
int i;
@@ -234,12 +244,19 @@ static uint64_t sip24_final(struct siphash *H) {
switch (left) {
case 7: b |= (uint64_t)H->buf[6] << 48;
+ /* fall through */
case 6: b |= (uint64_t)H->buf[5] << 40;
+ /* fall through */
case 5: b |= (uint64_t)H->buf[4] << 32;
+ /* fall through */
case 4: b |= (uint64_t)H->buf[3] << 24;
+ /* fall through */
case 3: b |= (uint64_t)H->buf[2] << 16;
+ /* fall through */
case 2: b |= (uint64_t)H->buf[1] << 8;
+ /* fall through */
case 1: b |= (uint64_t)H->buf[0] << 0;
+ /* fall through */
case 0: break;
}
diff --git a/Utilities/cmexpat/lib/utf8tab.h b/Utilities/cmexpat/lib/utf8tab.h
index 7bb3e7760..fa0bed6f5 100644
--- a/Utilities/cmexpat/lib/utf8tab.h
+++ b/Utilities/cmexpat/lib/utf8tab.h
@@ -1,7 +1,34 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
-*/
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
+*/
/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL,
diff --git a/Utilities/cmexpat/lib/winconfig.h b/Utilities/cmexpat/lib/winconfig.h
index c9dbfea85..1af28822c 100644
--- a/Utilities/cmexpat/lib/winconfig.h
+++ b/Utilities/cmexpat/lib/winconfig.h
@@ -1,10 +1,33 @@
-/*================================================================
-** Copyright 2000, Clark Cooper
-** All rights reserved.
-**
-** This is free software. You are permitted to copy, distribute, or modify
-** it under the terms of the MIT/X license (contained in the COPYING file
-** with this distribution.)
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#ifndef WINCONFIG_H
@@ -30,10 +53,6 @@
/* we will assume all Windows platforms are little endian */
#define BYTEORDER 1234
-/* Windows has memmove() available. */
-#define HAVE_MEMMOVE
-
-
#endif /* !defined(HAVE_EXPAT_CONFIG_H) */
#if defined(_MSC_VER)
diff --git a/Utilities/cmexpat/lib/xmlparse.c b/Utilities/cmexpat/lib/xmlparse.c
index b703e61a0..9c0987f4f 100644
--- a/Utilities/cmexpat/lib/xmlparse.c
+++ b/Utilities/cmexpat/lib/xmlparse.c
@@ -1,7 +1,33 @@
-/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
-
- 101bfd65d1ff3d1511cf6671e6aae65f82cd97df6f4da137d46d510731830ad9 (2.2.3+)
+/* 69df5be70289a11fb834869ce4a91c23c1d9dd04baffcbd10e86742d149a080c (2.2.7+)
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#if !defined(_GNU_SOURCE)
@@ -80,9 +106,6 @@
If insist on not using any of these, bypass this error by defining \
XML_POOR_ENTROPY; you have been warned. \
\
- For CMake, one way to pass the define is: \
- cmake -DCMAKE_C_FLAGS="-pipe -O2 -DHAVE_SYSCALL_GETRANDOM" . \
- \
If you have reasons to patch this detection code away or need changes \
to the build system, please open a bug. Thank you!
#endif
@@ -138,14 +161,8 @@ typedef char ICHAR;
/* 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))
-/* Handle the case where memmove() doesn't exist. */
-#ifndef HAVE_MEMMOVE
-#ifdef HAVE_BCOPY
-#define memmove(d,s,l) bcopy((s),(d),(l))
-#else
-#error memmove does not exist on this platform, nor is a substitute available
-#endif /* HAVE_BCOPY */
-#endif /* HAVE_MEMMOVE */
+/* Do safe (NULL-aware) pointer arithmetic */
+#define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0)
#include "internal.h"
#include "xmltok.h"
@@ -447,7 +464,7 @@ setContext(XML_Parser parser, const XML_Char *context);
static void FASTCALL normalizePublicId(XML_Char *s);
static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms);
-/* do not call if parentParser != NULL */
+/* do not call if m_parentParser != NULL */
static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms);
static void
dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms);
@@ -519,7 +536,7 @@ parserInit(XML_Parser parser, const XML_Char *encodingName);
: ((*((pool)->ptr)++ = c), 1))
struct XML_ParserStruct {
- /* The first member must be userData so that the XML_GetUserData
+ /* The first member must be m_userData so that the XML_GetUserData
macro works. */
void *m_userData;
void *m_handlerArg;
@@ -529,7 +546,7 @@ struct XML_ParserStruct {
const char *m_bufferPtr;
/* past last character to be parsed */
char *m_bufferEnd;
- /* allocated end of buffer */
+ /* allocated end of m_buffer */
const char *m_bufferLim;
XML_Index m_parseEndByteIndex;
const char *m_parseEndPtr;
@@ -621,113 +638,10 @@ struct XML_ParserStruct {
unsigned long m_hash_secret_salt;
};
-#define MALLOC(s) (parser->m_mem.malloc_fcn((s)))
-#define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s)))
-#define FREE(p) (parser->m_mem.free_fcn((p)))
-
-#define userData (parser->m_userData)
-#define handlerArg (parser->m_handlerArg)
-#define startElementHandler (parser->m_startElementHandler)
-#define endElementHandler (parser->m_endElementHandler)
-#define characterDataHandler (parser->m_characterDataHandler)
-#define processingInstructionHandler \
- (parser->m_processingInstructionHandler)
-#define commentHandler (parser->m_commentHandler)
-#define startCdataSectionHandler \
- (parser->m_startCdataSectionHandler)
-#define endCdataSectionHandler (parser->m_endCdataSectionHandler)
-#define defaultHandler (parser->m_defaultHandler)
-#define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler)
-#define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler)
-#define unparsedEntityDeclHandler \
- (parser->m_unparsedEntityDeclHandler)
-#define notationDeclHandler (parser->m_notationDeclHandler)
-#define startNamespaceDeclHandler \
- (parser->m_startNamespaceDeclHandler)
-#define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler)
-#define notStandaloneHandler (parser->m_notStandaloneHandler)
-#define externalEntityRefHandler \
- (parser->m_externalEntityRefHandler)
-#define externalEntityRefHandlerArg \
- (parser->m_externalEntityRefHandlerArg)
-#define internalEntityRefHandler \
- (parser->m_internalEntityRefHandler)
-#define skippedEntityHandler (parser->m_skippedEntityHandler)
-#define unknownEncodingHandler (parser->m_unknownEncodingHandler)
-#define elementDeclHandler (parser->m_elementDeclHandler)
-#define attlistDeclHandler (parser->m_attlistDeclHandler)
-#define entityDeclHandler (parser->m_entityDeclHandler)
-#define xmlDeclHandler (parser->m_xmlDeclHandler)
-#define encoding (parser->m_encoding)
-#define initEncoding (parser->m_initEncoding)
-#define internalEncoding (parser->m_internalEncoding)
-#define unknownEncodingMem (parser->m_unknownEncodingMem)
-#define unknownEncodingData (parser->m_unknownEncodingData)
-#define unknownEncodingHandlerData \
- (parser->m_unknownEncodingHandlerData)
-#define unknownEncodingRelease (parser->m_unknownEncodingRelease)
-#define protocolEncodingName (parser->m_protocolEncodingName)
-#define ns (parser->m_ns)
-#define ns_triplets (parser->m_ns_triplets)
-#define prologState (parser->m_prologState)
-#define processor (parser->m_processor)
-#define errorCode (parser->m_errorCode)
-#define eventPtr (parser->m_eventPtr)
-#define eventEndPtr (parser->m_eventEndPtr)
-#define positionPtr (parser->m_positionPtr)
-#define position (parser->m_position)
-#define openInternalEntities (parser->m_openInternalEntities)
-#define freeInternalEntities (parser->m_freeInternalEntities)
-#define defaultExpandInternalEntities \
- (parser->m_defaultExpandInternalEntities)
-#define tagLevel (parser->m_tagLevel)
-#define buffer (parser->m_buffer)
-#define bufferPtr (parser->m_bufferPtr)
-#define bufferEnd (parser->m_bufferEnd)
-#define parseEndByteIndex (parser->m_parseEndByteIndex)
-#define parseEndPtr (parser->m_parseEndPtr)
-#define bufferLim (parser->m_bufferLim)
-#define dataBuf (parser->m_dataBuf)
-#define dataBufEnd (parser->m_dataBufEnd)
-#define _dtd (parser->m_dtd)
-#define curBase (parser->m_curBase)
-#define declEntity (parser->m_declEntity)
-#define doctypeName (parser->m_doctypeName)
-#define doctypeSysid (parser->m_doctypeSysid)
-#define doctypePubid (parser->m_doctypePubid)
-#define declAttributeType (parser->m_declAttributeType)
-#define declNotationName (parser->m_declNotationName)
-#define declNotationPublicId (parser->m_declNotationPublicId)
-#define declElementType (parser->m_declElementType)
-#define declAttributeId (parser->m_declAttributeId)
-#define declAttributeIsCdata (parser->m_declAttributeIsCdata)
-#define declAttributeIsId (parser->m_declAttributeIsId)
-#define freeTagList (parser->m_freeTagList)
-#define freeBindingList (parser->m_freeBindingList)
-#define inheritedBindings (parser->m_inheritedBindings)
-#define tagStack (parser->m_tagStack)
-#define atts (parser->m_atts)
-#define attsSize (parser->m_attsSize)
-#define nSpecifiedAtts (parser->m_nSpecifiedAtts)
-#define idAttIndex (parser->m_idAttIndex)
-#define nsAtts (parser->m_nsAtts)
-#define nsAttsVersion (parser->m_nsAttsVersion)
-#define nsAttsPower (parser->m_nsAttsPower)
-#define attInfo (parser->m_attInfo)
-#define tempPool (parser->m_tempPool)
-#define temp2Pool (parser->m_temp2Pool)
-#define groupConnector (parser->m_groupConnector)
-#define groupSize (parser->m_groupSize)
-#define namespaceSeparator (parser->m_namespaceSeparator)
-#define parentParser (parser->m_parentParser)
-#define ps_parsing (parser->m_parsingStatus.parsing)
-#define ps_finalBuffer (parser->m_parsingStatus.finalBuffer)
-#ifdef XML_DTD
-#define isParamEntity (parser->m_isParamEntity)
-#define useForeignDTD (parser->m_useForeignDTD)
-#define paramEntityParsing (parser->m_paramEntityParsing)
-#endif /* XML_DTD */
-#define hash_secret_salt (parser->m_hash_secret_salt)
+#define MALLOC(parser, s) (parser->m_mem.malloc_fcn((s)))
+#define REALLOC(parser, p, s) (parser->m_mem.realloc_fcn((p),(s)))
+#define FREE(parser, p) (parser->m_mem.free_fcn((p)))
+
XML_Parser XMLCALL
XML_ParserCreate(const XML_Char *encodingName)
@@ -753,6 +667,9 @@ static const XML_Char implicitContext[] = {
};
+/* To avoid warnings about unused functions: */
+#if ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM)
+
#if defined(HAVE_GETRANDOM) || defined(HAVE_SYSCALL_GETRANDOM)
/* Obtain entropy on Linux 3.17+ */
@@ -818,8 +735,10 @@ writeRandomBytes_dev_urandom(void * target, size_t count) {
#endif /* ! defined(_WIN32) && defined(XML_DEV_URANDOM) */
+#endif /* ! defined(HAVE_ARC4RANDOM_BUF) && ! defined(HAVE_ARC4RANDOM) */
+
-#if defined(HAVE_ARC4RANDOM)
+#if defined(HAVE_ARC4RANDOM) && ! defined(HAVE_ARC4RANDOM_BUF)
static void
writeRandomBytes_arc4random(void * target, size_t count) {
@@ -837,7 +756,7 @@ writeRandomBytes_arc4random(void * target, size_t count) {
}
}
-#endif /* defined(HAVE_ARC4RANDOM) */
+#endif /* defined(HAVE_ARC4RANDOM) && ! defined(HAVE_ARC4RANDOM_BUF) */
#ifdef _WIN32
@@ -919,6 +838,8 @@ generate_hash_secret_salt(XML_Parser parser)
{
unsigned long entropy;
(void)parser;
+
+ /* "Failproof" high quality providers: */
#if defined(HAVE_ARC4RANDOM_BUF)
arc4random_buf(&entropy, sizeof(entropy));
return ENTROPY_DEBUG("arc4random_buf", entropy);
@@ -967,9 +888,9 @@ static XML_Bool /* only valid for root parser */
startParsing(XML_Parser parser)
{
/* hash functions must be initialized before setContext() is called */
- if (hash_secret_salt == 0)
- hash_secret_salt = generate_hash_secret_salt(parser);
- if (ns) {
+ if (parser->m_hash_secret_salt == 0)
+ parser->m_hash_secret_salt = generate_hash_secret_salt(parser);
+ if (parser->m_ns) {
/* implicit context only set for root parser, since child
parsers (i.e. external entity parsers) will inherit it
*/
@@ -1019,85 +940,85 @@ parserCreate(const XML_Char *encodingName,
if (!parser)
return parser;
- buffer = NULL;
- bufferLim = NULL;
+ parser->m_buffer = NULL;
+ parser->m_bufferLim = NULL;
- attsSize = INIT_ATTS_SIZE;
- atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE));
- if (atts == NULL) {
- FREE(parser);
+ parser->m_attsSize = INIT_ATTS_SIZE;
+ parser->m_atts = (ATTRIBUTE *)MALLOC(parser, parser->m_attsSize * sizeof(ATTRIBUTE));
+ if (parser->m_atts == NULL) {
+ FREE(parser, parser);
return NULL;
}
#ifdef XML_ATTR_INFO
- attInfo = (XML_AttrInfo*)MALLOC(attsSize * sizeof(XML_AttrInfo));
- if (attInfo == NULL) {
- FREE(atts);
- FREE(parser);
+ parser->m_attInfo = (XML_AttrInfo*)MALLOC(parser, parser->m_attsSize * sizeof(XML_AttrInfo));
+ if (parser->m_attInfo == NULL) {
+ FREE(parser, parser->m_atts);
+ FREE(parser, parser);
return NULL;
}
#endif
- dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
- if (dataBuf == NULL) {
- FREE(atts);
+ parser->m_dataBuf = (XML_Char *)MALLOC(parser, INIT_DATA_BUF_SIZE * sizeof(XML_Char));
+ if (parser->m_dataBuf == NULL) {
+ FREE(parser, parser->m_atts);
#ifdef XML_ATTR_INFO
- FREE(attInfo);
+ FREE(parser, parser->m_attInfo);
#endif
- FREE(parser);
+ FREE(parser, parser);
return NULL;
}
- dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;
+ parser->m_dataBufEnd = parser->m_dataBuf + INIT_DATA_BUF_SIZE;
if (dtd)
- _dtd = dtd;
+ parser->m_dtd = dtd;
else {
- _dtd = dtdCreate(&parser->m_mem);
- if (_dtd == NULL) {
- FREE(dataBuf);
- FREE(atts);
+ parser->m_dtd = dtdCreate(&parser->m_mem);
+ if (parser->m_dtd == NULL) {
+ FREE(parser, parser->m_dataBuf);
+ FREE(parser, parser->m_atts);
#ifdef XML_ATTR_INFO
- FREE(attInfo);
+ FREE(parser, parser->m_attInfo);
#endif
- FREE(parser);
+ FREE(parser, parser);
return NULL;
}
}
- freeBindingList = NULL;
- freeTagList = NULL;
- freeInternalEntities = NULL;
+ parser->m_freeBindingList = NULL;
+ parser->m_freeTagList = NULL;
+ parser->m_freeInternalEntities = NULL;
- groupSize = 0;
- groupConnector = NULL;
+ parser->m_groupSize = 0;
+ parser->m_groupConnector = NULL;
- unknownEncodingHandler = NULL;
- unknownEncodingHandlerData = NULL;
+ parser->m_unknownEncodingHandler = NULL;
+ parser->m_unknownEncodingHandlerData = NULL;
- namespaceSeparator = ASCII_EXCL;
- ns = XML_FALSE;
- ns_triplets = XML_FALSE;
+ parser->m_namespaceSeparator = ASCII_EXCL;
+ parser->m_ns = XML_FALSE;
+ parser->m_ns_triplets = XML_FALSE;
- nsAtts = NULL;
- nsAttsVersion = 0;
- nsAttsPower = 0;
+ parser->m_nsAtts = NULL;
+ parser->m_nsAttsVersion = 0;
+ parser->m_nsAttsPower = 0;
- protocolEncodingName = NULL;
+ parser->m_protocolEncodingName = NULL;
- poolInit(&tempPool, &(parser->m_mem));
- poolInit(&temp2Pool, &(parser->m_mem));
+ poolInit(&parser->m_tempPool, &(parser->m_mem));
+ poolInit(&parser->m_temp2Pool, &(parser->m_mem));
parserInit(parser, encodingName);
- if (encodingName && !protocolEncodingName) {
+ if (encodingName && !parser->m_protocolEncodingName) {
XML_ParserFree(parser);
return NULL;
}
if (nameSep) {
- ns = XML_TRUE;
- internalEncoding = XmlGetInternalEncodingNS();
- namespaceSeparator = *nameSep;
+ parser->m_ns = XML_TRUE;
+ parser->m_internalEncoding = XmlGetInternalEncodingNS();
+ parser->m_namespaceSeparator = *nameSep;
}
else {
- internalEncoding = XmlGetInternalEncoding();
+ parser->m_internalEncoding = XmlGetInternalEncoding();
}
return parser;
@@ -1106,85 +1027,85 @@ parserCreate(const XML_Char *encodingName,
static void
parserInit(XML_Parser parser, const XML_Char *encodingName)
{
- processor = prologInitProcessor;
- XmlPrologStateInit(&prologState);
+ parser->m_processor = prologInitProcessor;
+ XmlPrologStateInit(&parser->m_prologState);
if (encodingName != NULL) {
- protocolEncodingName = copyString(encodingName, &(parser->m_mem));
- }
- curBase = NULL;
- XmlInitEncoding(&initEncoding, &encoding, 0);
- userData = NULL;
- handlerArg = NULL;
- startElementHandler = NULL;
- endElementHandler = NULL;
- characterDataHandler = NULL;
- processingInstructionHandler = NULL;
- commentHandler = NULL;
- startCdataSectionHandler = NULL;
- endCdataSectionHandler = NULL;
- defaultHandler = NULL;
- startDoctypeDeclHandler = NULL;
- endDoctypeDeclHandler = NULL;
- unparsedEntityDeclHandler = NULL;
- notationDeclHandler = NULL;
- startNamespaceDeclHandler = NULL;
- endNamespaceDeclHandler = NULL;
- notStandaloneHandler = NULL;
- externalEntityRefHandler = NULL;
- externalEntityRefHandlerArg = parser;
- skippedEntityHandler = NULL;
- elementDeclHandler = NULL;
- attlistDeclHandler = NULL;
- entityDeclHandler = NULL;
- xmlDeclHandler = NULL;
- bufferPtr = buffer;
- bufferEnd = buffer;
- parseEndByteIndex = 0;
- parseEndPtr = NULL;
- declElementType = NULL;
- declAttributeId = NULL;
- declEntity = NULL;
- doctypeName = NULL;
- doctypeSysid = NULL;
- doctypePubid = NULL;
- declAttributeType = NULL;
- declNotationName = NULL;
- declNotationPublicId = NULL;
- declAttributeIsCdata = XML_FALSE;
- declAttributeIsId = XML_FALSE;
- memset(&position, 0, sizeof(POSITION));
- errorCode = XML_ERROR_NONE;
- eventPtr = NULL;
- eventEndPtr = NULL;
- positionPtr = NULL;
- openInternalEntities = NULL;
- defaultExpandInternalEntities = XML_TRUE;
- tagLevel = 0;
- tagStack = NULL;
- inheritedBindings = NULL;
- nSpecifiedAtts = 0;
- unknownEncodingMem = NULL;
- unknownEncodingRelease = NULL;
- unknownEncodingData = NULL;
- parentParser = NULL;
- ps_parsing = XML_INITIALIZED;
+ parser->m_protocolEncodingName = copyString(encodingName, &(parser->m_mem));
+ }
+ parser->m_curBase = NULL;
+ XmlInitEncoding(&parser->m_initEncoding, &parser->m_encoding, 0);
+ parser->m_userData = NULL;
+ parser->m_handlerArg = NULL;
+ parser->m_startElementHandler = NULL;
+ parser->m_endElementHandler = NULL;
+ parser->m_characterDataHandler = NULL;
+ parser->m_processingInstructionHandler = NULL;
+ parser->m_commentHandler = NULL;
+ parser->m_startCdataSectionHandler = NULL;
+ parser->m_endCdataSectionHandler = NULL;
+ parser->m_defaultHandler = NULL;
+ parser->m_startDoctypeDeclHandler = NULL;
+ parser->m_endDoctypeDeclHandler = NULL;
+ parser->m_unparsedEntityDeclHandler = NULL;
+ parser->m_notationDeclHandler = NULL;
+ parser->m_startNamespaceDeclHandler = NULL;
+ parser->m_endNamespaceDeclHandler = NULL;
+ parser->m_notStandaloneHandler = NULL;
+ parser->m_externalEntityRefHandler = NULL;
+ parser->m_externalEntityRefHandlerArg = parser;
+ parser->m_skippedEntityHandler = NULL;
+ parser->m_elementDeclHandler = NULL;
+ parser->m_attlistDeclHandler = NULL;
+ parser->m_entityDeclHandler = NULL;
+ parser->m_xmlDeclHandler = NULL;
+ parser->m_bufferPtr = parser->m_buffer;
+ parser->m_bufferEnd = parser->m_buffer;
+ parser->m_parseEndByteIndex = 0;
+ parser->m_parseEndPtr = NULL;
+ parser->m_declElementType = NULL;
+ parser->m_declAttributeId = NULL;
+ parser->m_declEntity = NULL;
+ parser->m_doctypeName = NULL;
+ parser->m_doctypeSysid = NULL;
+ parser->m_doctypePubid = NULL;
+ parser->m_declAttributeType = NULL;
+ parser->m_declNotationName = NULL;
+ parser->m_declNotationPublicId = NULL;
+ parser->m_declAttributeIsCdata = XML_FALSE;
+ parser->m_declAttributeIsId = XML_FALSE;
+ memset(&parser->m_position, 0, sizeof(POSITION));
+ parser->m_errorCode = XML_ERROR_NONE;
+ parser->m_eventPtr = NULL;
+ parser->m_eventEndPtr = NULL;
+ parser->m_positionPtr = NULL;
+ parser->m_openInternalEntities = NULL;
+ parser->m_defaultExpandInternalEntities = XML_TRUE;
+ parser->m_tagLevel = 0;
+ parser->m_tagStack = NULL;
+ parser->m_inheritedBindings = NULL;
+ parser->m_nSpecifiedAtts = 0;
+ parser->m_unknownEncodingMem = NULL;
+ parser->m_unknownEncodingRelease = NULL;
+ parser->m_unknownEncodingData = NULL;
+ parser->m_parentParser = NULL;
+ parser->m_parsingStatus.parsing = XML_INITIALIZED;
#ifdef XML_DTD
- isParamEntity = XML_FALSE;
- useForeignDTD = XML_FALSE;
- paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
+ parser->m_isParamEntity = XML_FALSE;
+ parser->m_useForeignDTD = XML_FALSE;
+ parser->m_paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
#endif
- hash_secret_salt = 0;
+ parser->m_hash_secret_salt = 0;
}
-/* moves list of bindings to freeBindingList */
+/* moves list of bindings to m_freeBindingList */
static void FASTCALL
moveToFreeBindingList(XML_Parser parser, BINDING *bindings)
{
while (bindings) {
BINDING *b = bindings;
bindings = bindings->nextTagBinding;
- b->nextTagBinding = freeBindingList;
- freeBindingList = b;
+ b->nextTagBinding = parser->m_freeBindingList;
+ parser->m_freeBindingList = b;
}
}
@@ -1197,36 +1118,36 @@ XML_ParserReset(XML_Parser parser, const XML_Char *encodingName)
if (parser == NULL)
return XML_FALSE;
- if (parentParser)
+ if (parser->m_parentParser)
return XML_FALSE;
- /* move tagStack to freeTagList */
- tStk = tagStack;
+ /* move m_tagStack to m_freeTagList */
+ tStk = parser->m_tagStack;
while (tStk) {
TAG *tag = tStk;
tStk = tStk->parent;
- tag->parent = freeTagList;
+ tag->parent = parser->m_freeTagList;
moveToFreeBindingList(parser, tag->bindings);
tag->bindings = NULL;
- freeTagList = tag;
+ parser->m_freeTagList = tag;
}
- /* move openInternalEntities to freeInternalEntities */
- openEntityList = openInternalEntities;
+ /* move m_openInternalEntities to m_freeInternalEntities */
+ openEntityList = parser->m_openInternalEntities;
while (openEntityList) {
OPEN_INTERNAL_ENTITY *openEntity = openEntityList;
openEntityList = openEntity->next;
- openEntity->next = freeInternalEntities;
- freeInternalEntities = openEntity;
- }
- moveToFreeBindingList(parser, inheritedBindings);
- FREE(unknownEncodingMem);
- if (unknownEncodingRelease)
- unknownEncodingRelease(unknownEncodingData);
- poolClear(&tempPool);
- poolClear(&temp2Pool);
- FREE((void *)protocolEncodingName);
- protocolEncodingName = NULL;
+ openEntity->next = parser->m_freeInternalEntities;
+ parser->m_freeInternalEntities = openEntity;
+ }
+ moveToFreeBindingList(parser, parser->m_inheritedBindings);
+ FREE(parser, parser->m_unknownEncodingMem);
+ if (parser->m_unknownEncodingRelease)
+ parser->m_unknownEncodingRelease(parser->m_unknownEncodingData);
+ poolClear(&parser->m_tempPool);
+ poolClear(&parser->m_temp2Pool);
+ FREE(parser, (void *)parser->m_protocolEncodingName);
+ parser->m_protocolEncodingName = NULL;
parserInit(parser, encodingName);
- dtdReset(_dtd, &parser->m_mem);
+ dtdReset(parser->m_dtd, &parser->m_mem);
return XML_TRUE;
}
@@ -1239,19 +1160,19 @@ XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName)
XXX There's no way for the caller to determine which of the
XXX possible error cases caused the XML_STATUS_ERROR return.
*/
- if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
+ if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED)
return XML_STATUS_ERROR;
/* Get rid of any previous encoding name */
- FREE((void *)protocolEncodingName);
+ FREE(parser, (void *)parser->m_protocolEncodingName);
if (encodingName == NULL)
/* No new encoding name */
- protocolEncodingName = NULL;
+ parser->m_protocolEncodingName = NULL;
else {
/* Copy the new encoding name into allocated memory */
- protocolEncodingName = copyString(encodingName, &(parser->m_mem));
- if (!protocolEncodingName)
+ parser->m_protocolEncodingName = copyString(encodingName, &(parser->m_mem));
+ if (!parser->m_protocolEncodingName)
return XML_STATUS_ERROR;
}
return XML_STATUS_OK;
@@ -1308,44 +1229,44 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser,
return NULL;
/* Stash the original parser contents on the stack */
- oldDtd = _dtd;
- oldStartElementHandler = startElementHandler;
- oldEndElementHandler = endElementHandler;
- oldCharacterDataHandler = characterDataHandler;
- oldProcessingInstructionHandler = processingInstructionHandler;
- oldCommentHandler = commentHandler;
- oldStartCdataSectionHandler = startCdataSectionHandler;
- oldEndCdataSectionHandler = endCdataSectionHandler;
- oldDefaultHandler = defaultHandler;
- oldUnparsedEntityDeclHandler = unparsedEntityDeclHandler;
- oldNotationDeclHandler = notationDeclHandler;
- oldStartNamespaceDeclHandler = startNamespaceDeclHandler;
- oldEndNamespaceDeclHandler = endNamespaceDeclHandler;
- oldNotStandaloneHandler = notStandaloneHandler;
- oldExternalEntityRefHandler = externalEntityRefHandler;
- oldSkippedEntityHandler = skippedEntityHandler;
- oldUnknownEncodingHandler = unknownEncodingHandler;
- oldElementDeclHandler = elementDeclHandler;
- oldAttlistDeclHandler = attlistDeclHandler;
- oldEntityDeclHandler = entityDeclHandler;
- oldXmlDeclHandler = xmlDeclHandler;
- oldDeclElementType = declElementType;
-
- oldUserData = userData;
- oldHandlerArg = handlerArg;
- oldDefaultExpandInternalEntities = defaultExpandInternalEntities;
- oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg;
+ oldDtd = parser->m_dtd;
+ oldStartElementHandler = parser->m_startElementHandler;
+ oldEndElementHandler = parser->m_endElementHandler;
+ oldCharacterDataHandler = parser->m_characterDataHandler;
+ oldProcessingInstructionHandler = parser->m_processingInstructionHandler;
+ oldCommentHandler = parser->m_commentHandler;
+ oldStartCdataSectionHandler = parser->m_startCdataSectionHandler;
+ oldEndCdataSectionHandler = parser->m_endCdataSectionHandler;
+ oldDefaultHandler = parser->m_defaultHandler;
+ oldUnparsedEntityDeclHandler = parser->m_unparsedEntityDeclHandler;
+ oldNotationDeclHandler = parser->m_notationDeclHandler;
+ oldStartNamespaceDeclHandler = parser->m_startNamespaceDeclHandler;
+ oldEndNamespaceDeclHandler = parser->m_endNamespaceDeclHandler;
+ oldNotStandaloneHandler = parser->m_notStandaloneHandler;
+ oldExternalEntityRefHandler = parser->m_externalEntityRefHandler;
+ oldSkippedEntityHandler = parser->m_skippedEntityHandler;
+ oldUnknownEncodingHandler = parser->m_unknownEncodingHandler;
+ oldElementDeclHandler = parser->m_elementDeclHandler;
+ oldAttlistDeclHandler = parser->m_attlistDeclHandler;
+ oldEntityDeclHandler = parser->m_entityDeclHandler;
+ oldXmlDeclHandler = parser->m_xmlDeclHandler;
+ oldDeclElementType = parser->m_declElementType;
+
+ oldUserData = parser->m_userData;
+ oldHandlerArg = parser->m_handlerArg;
+ oldDefaultExpandInternalEntities = parser->m_defaultExpandInternalEntities;
+ oldExternalEntityRefHandlerArg = parser->m_externalEntityRefHandlerArg;
#ifdef XML_DTD
- oldParamEntityParsing = paramEntityParsing;
- oldInEntityValue = prologState.inEntityValue;
+ oldParamEntityParsing = parser->m_paramEntityParsing;
+ oldInEntityValue = parser->m_prologState.inEntityValue;
#endif
- oldns_triplets = ns_triplets;
+ oldns_triplets = parser->m_ns_triplets;
/* Note that the new parser shares the same hash secret as the old
parser, so that dtdCopy and copyEntityTable can lookup values
from hash tables associated with either parser without us having
to worry which hash secrets each table has.
*/
- oldhash_secret_salt = hash_secret_salt;
+ oldhash_secret_salt = parser->m_hash_secret_salt;
#ifdef XML_DTD
if (!context)
@@ -1357,9 +1278,9 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser,
here. This makes this function more painful to follow than it
would be otherwise.
*/
- if (ns) {
+ if (parser->m_ns) {
XML_Char tmp[2];
- *tmp = namespaceSeparator;
+ *tmp = parser->m_namespaceSeparator;
parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd);
}
else {
@@ -1369,62 +1290,62 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser,
if (!parser)
return NULL;
- 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;
- skippedEntityHandler = oldSkippedEntityHandler;
- unknownEncodingHandler = oldUnknownEncodingHandler;
- elementDeclHandler = oldElementDeclHandler;
- attlistDeclHandler = oldAttlistDeclHandler;
- entityDeclHandler = oldEntityDeclHandler;
- xmlDeclHandler = oldXmlDeclHandler;
- declElementType = oldDeclElementType;
- userData = oldUserData;
+ parser->m_startElementHandler = oldStartElementHandler;
+ parser->m_endElementHandler = oldEndElementHandler;
+ parser->m_characterDataHandler = oldCharacterDataHandler;
+ parser->m_processingInstructionHandler = oldProcessingInstructionHandler;
+ parser->m_commentHandler = oldCommentHandler;
+ parser->m_startCdataSectionHandler = oldStartCdataSectionHandler;
+ parser->m_endCdataSectionHandler = oldEndCdataSectionHandler;
+ parser->m_defaultHandler = oldDefaultHandler;
+ parser->m_unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler;
+ parser->m_notationDeclHandler = oldNotationDeclHandler;
+ parser->m_startNamespaceDeclHandler = oldStartNamespaceDeclHandler;
+ parser->m_endNamespaceDeclHandler = oldEndNamespaceDeclHandler;
+ parser->m_notStandaloneHandler = oldNotStandaloneHandler;
+ parser->m_externalEntityRefHandler = oldExternalEntityRefHandler;
+ parser->m_skippedEntityHandler = oldSkippedEntityHandler;
+ parser->m_unknownEncodingHandler = oldUnknownEncodingHandler;
+ parser->m_elementDeclHandler = oldElementDeclHandler;
+ parser->m_attlistDeclHandler = oldAttlistDeclHandler;
+ parser->m_entityDeclHandler = oldEntityDeclHandler;
+ parser->m_xmlDeclHandler = oldXmlDeclHandler;
+ parser->m_declElementType = oldDeclElementType;
+ parser->m_userData = oldUserData;
if (oldUserData == oldHandlerArg)
- handlerArg = userData;
+ parser->m_handlerArg = parser->m_userData;
else
- handlerArg = parser;
+ parser->m_handlerArg = parser;
if (oldExternalEntityRefHandlerArg != oldParser)
- externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;
- defaultExpandInternalEntities = oldDefaultExpandInternalEntities;
- ns_triplets = oldns_triplets;
- hash_secret_salt = oldhash_secret_salt;
- parentParser = oldParser;
+ parser->m_externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;
+ parser->m_defaultExpandInternalEntities = oldDefaultExpandInternalEntities;
+ parser->m_ns_triplets = oldns_triplets;
+ parser->m_hash_secret_salt = oldhash_secret_salt;
+ parser->m_parentParser = oldParser;
#ifdef XML_DTD
- paramEntityParsing = oldParamEntityParsing;
- prologState.inEntityValue = oldInEntityValue;
+ parser->m_paramEntityParsing = oldParamEntityParsing;
+ parser->m_prologState.inEntityValue = oldInEntityValue;
if (context) {
#endif /* XML_DTD */
- if (!dtdCopy(oldParser, _dtd, oldDtd, &parser->m_mem)
+ if (!dtdCopy(oldParser, parser->m_dtd, oldDtd, &parser->m_mem)
|| !setContext(parser, context)) {
XML_ParserFree(parser);
return NULL;
}
- processor = externalEntityInitProcessor;
+ parser->m_processor = externalEntityInitProcessor;
#ifdef XML_DTD
}
else {
- /* The DTD instance referenced by _dtd is shared between the document's
+ /* The DTD instance referenced by parser->m_dtd is shared between the document's
root parser and external PE parsers, therefore one does not need to
call setContext. In addition, one also *must* not call setContext,
because this would overwrite existing prefix->binding pointers in
- _dtd with ones that get destroyed with the external PE parser.
+ parser->m_dtd with ones that get destroyed with the external PE parser.
This would leave those prefixes with dangling pointers.
*/
- isParamEntity = XML_TRUE;
- XmlPrologStateInitExternalEntity(&prologState);
- processor = externalParEntInitProcessor;
+ parser->m_isParamEntity = XML_TRUE;
+ XmlPrologStateInitExternalEntity(&parser->m_prologState);
+ parser->m_processor = externalParEntInitProcessor;
}
#endif /* XML_DTD */
return parser;
@@ -1438,8 +1359,8 @@ destroyBindings(BINDING *bindings, XML_Parser parser)
if (!b)
break;
bindings = b->nextTagBinding;
- FREE(b->uri);
- FREE(b);
+ FREE(parser, b->uri);
+ FREE(parser, b);
}
}
@@ -1450,70 +1371,70 @@ XML_ParserFree(XML_Parser parser)
OPEN_INTERNAL_ENTITY *entityList;
if (parser == NULL)
return;
- /* free tagStack and freeTagList */
- tagList = tagStack;
+ /* free m_tagStack and m_freeTagList */
+ tagList = parser->m_tagStack;
for (;;) {
TAG *p;
if (tagList == NULL) {
- if (freeTagList == NULL)
+ if (parser->m_freeTagList == NULL)
break;
- tagList = freeTagList;
- freeTagList = NULL;
+ tagList = parser->m_freeTagList;
+ parser->m_freeTagList = NULL;
}
p = tagList;
tagList = tagList->parent;
- FREE(p->buf);
+ FREE(parser, p->buf);
destroyBindings(p->bindings, parser);
- FREE(p);
+ FREE(parser, p);
}
- /* free openInternalEntities and freeInternalEntities */
- entityList = openInternalEntities;
+ /* free m_openInternalEntities and m_freeInternalEntities */
+ entityList = parser->m_openInternalEntities;
for (;;) {
OPEN_INTERNAL_ENTITY *openEntity;
if (entityList == NULL) {
- if (freeInternalEntities == NULL)
+ if (parser->m_freeInternalEntities == NULL)
break;
- entityList = freeInternalEntities;
- freeInternalEntities = NULL;
+ entityList = parser->m_freeInternalEntities;
+ parser->m_freeInternalEntities = NULL;
}
openEntity = entityList;
entityList = entityList->next;
- FREE(openEntity);
+ FREE(parser, openEntity);
}
- destroyBindings(freeBindingList, parser);
- destroyBindings(inheritedBindings, parser);
- poolDestroy(&tempPool);
- poolDestroy(&temp2Pool);
- FREE((void *)protocolEncodingName);
+ destroyBindings(parser->m_freeBindingList, parser);
+ destroyBindings(parser->m_inheritedBindings, parser);
+ poolDestroy(&parser->m_tempPool);
+ poolDestroy(&parser->m_temp2Pool);
+ FREE(parser, (void *)parser->m_protocolEncodingName);
#ifdef XML_DTD
/* external parameter entity parsers share the DTD structure
parser->m_dtd with the root parser, so we must not destroy it
*/
- if (!isParamEntity && _dtd)
+ if (!parser->m_isParamEntity && parser->m_dtd)
#else
- if (_dtd)
+ if (parser->m_dtd)
#endif /* XML_DTD */
- dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem);
- FREE((void *)atts);
+ dtdDestroy(parser->m_dtd, (XML_Bool)!parser->m_parentParser, &parser->m_mem);
+ FREE(parser, (void *)parser->m_atts);
#ifdef XML_ATTR_INFO
- FREE((void *)attInfo);
+ FREE(parser, (void *)parser->m_attInfo);
#endif
- FREE(groupConnector);
- FREE(buffer);
- FREE(dataBuf);
- FREE(nsAtts);
- FREE(unknownEncodingMem);
- if (unknownEncodingRelease)
- unknownEncodingRelease(unknownEncodingData);
- FREE(parser);
+ FREE(parser, parser->m_groupConnector);
+ FREE(parser, parser->m_buffer);
+ FREE(parser, parser->m_dataBuf);
+ FREE(parser, parser->m_nsAtts);
+ FREE(parser, parser->m_unknownEncodingMem);
+ if (parser->m_unknownEncodingRelease)
+ parser->m_unknownEncodingRelease(parser->m_unknownEncodingData);
+ FREE(parser, parser);
}
void XMLCALL
XML_UseParserAsHandlerArg(XML_Parser parser)
{
if (parser != NULL)
- handlerArg = parser;
+ parser->m_handlerArg = parser;
}
enum XML_Error XMLCALL
@@ -1523,9 +1444,9 @@ XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD)
return XML_ERROR_INVALID_ARGUMENT;
#ifdef XML_DTD
/* block after XML_Parse()/XML_ParseBuffer() has been called */
- if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
+ if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED)
return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING;
- useForeignDTD = useDTD;
+ parser->m_useForeignDTD = useDTD;
return XML_ERROR_NONE;
#else
return XML_ERROR_FEATURE_REQUIRES_XML_DTD;
@@ -1538,9 +1459,9 @@ XML_SetReturnNSTriplet(XML_Parser parser, int do_nst)
if (parser == NULL)
return;
/* block after XML_Parse()/XML_ParseBuffer() has been called */
- if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
+ if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED)
return;
- ns_triplets = do_nst ? XML_TRUE : XML_FALSE;
+ parser->m_ns_triplets = do_nst ? XML_TRUE : XML_FALSE;
}
void XMLCALL
@@ -1548,10 +1469,10 @@ XML_SetUserData(XML_Parser parser, void *p)
{
if (parser == NULL)
return;
- if (handlerArg == userData)
- handlerArg = userData = p;
+ if (parser->m_handlerArg == parser->m_userData)
+ parser->m_handlerArg = parser->m_userData = p;
else
- userData = p;
+ parser->m_userData = p;
}
enum XML_Status XMLCALL
@@ -1560,13 +1481,13 @@ XML_SetBase(XML_Parser parser, const XML_Char *p)
if (parser == NULL)
return XML_STATUS_ERROR;
if (p) {
- p = poolCopyString(&_dtd->pool, p);
+ p = poolCopyString(&parser->m_dtd->pool, p);
if (!p)
return XML_STATUS_ERROR;
- curBase = p;
+ parser->m_curBase = p;
}
else
- curBase = NULL;
+ parser->m_curBase = NULL;
return XML_STATUS_OK;
}
@@ -1575,7 +1496,7 @@ XML_GetBase(XML_Parser parser)
{
if (parser == NULL)
return NULL;
- return curBase;
+ return parser->m_curBase;
}
int XMLCALL
@@ -1583,7 +1504,7 @@ XML_GetSpecifiedAttributeCount(XML_Parser parser)
{
if (parser == NULL)
return -1;
- return nSpecifiedAtts;
+ return parser->m_nSpecifiedAtts;
}
int XMLCALL
@@ -1591,7 +1512,7 @@ XML_GetIdAttributeIndex(XML_Parser parser)
{
if (parser == NULL)
return -1;
- return idAttIndex;
+ return parser->m_idAttIndex;
}
#ifdef XML_ATTR_INFO
@@ -1600,7 +1521,7 @@ XML_GetAttributeInfo(XML_Parser parser)
{
if (parser == NULL)
return NULL;
- return attInfo;
+ return parser->m_attInfo;
}
#endif
@@ -1611,22 +1532,22 @@ XML_SetElementHandler(XML_Parser parser,
{
if (parser == NULL)
return;
- startElementHandler = start;
- endElementHandler = end;
+ parser->m_startElementHandler = start;
+ parser->m_endElementHandler = end;
}
void XMLCALL
XML_SetStartElementHandler(XML_Parser parser,
XML_StartElementHandler start) {
if (parser != NULL)
- startElementHandler = start;
+ parser->m_startElementHandler = start;
}
void XMLCALL
XML_SetEndElementHandler(XML_Parser parser,
XML_EndElementHandler end) {
if (parser != NULL)
- endElementHandler = end;
+ parser->m_endElementHandler = end;
}
void XMLCALL
@@ -1634,7 +1555,7 @@ XML_SetCharacterDataHandler(XML_Parser parser,
XML_CharacterDataHandler handler)
{
if (parser != NULL)
- characterDataHandler = handler;
+ parser->m_characterDataHandler = handler;
}
void XMLCALL
@@ -1642,7 +1563,7 @@ XML_SetProcessingInstructionHandler(XML_Parser parser,
XML_ProcessingInstructionHandler handler)
{
if (parser != NULL)
- processingInstructionHandler = handler;
+ parser->m_processingInstructionHandler = handler;
}
void XMLCALL
@@ -1650,7 +1571,7 @@ XML_SetCommentHandler(XML_Parser parser,
XML_CommentHandler handler)
{
if (parser != NULL)
- commentHandler = handler;
+ parser->m_commentHandler = handler;
}
void XMLCALL
@@ -1660,22 +1581,22 @@ XML_SetCdataSectionHandler(XML_Parser parser,
{
if (parser == NULL)
return;
- startCdataSectionHandler = start;
- endCdataSectionHandler = end;
+ parser->m_startCdataSectionHandler = start;
+ parser->m_endCdataSectionHandler = end;
}
void XMLCALL
XML_SetStartCdataSectionHandler(XML_Parser parser,
XML_StartCdataSectionHandler start) {
if (parser != NULL)
- startCdataSectionHandler = start;
+ parser->m_startCdataSectionHandler = start;
}
void XMLCALL
XML_SetEndCdataSectionHandler(XML_Parser parser,
XML_EndCdataSectionHandler end) {
if (parser != NULL)
- endCdataSectionHandler = end;
+ parser->m_endCdataSectionHandler = end;
}
void XMLCALL
@@ -1684,8 +1605,8 @@ XML_SetDefaultHandler(XML_Parser parser,
{
if (parser == NULL)
return;
- defaultHandler = handler;
- defaultExpandInternalEntities = XML_FALSE;
+ parser->m_defaultHandler = handler;
+ parser->m_defaultExpandInternalEntities = XML_FALSE;
}
void XMLCALL
@@ -1694,8 +1615,8 @@ XML_SetDefaultHandlerExpand(XML_Parser parser,
{
if (parser == NULL)
return;
- defaultHandler = handler;
- defaultExpandInternalEntities = XML_TRUE;
+ parser->m_defaultHandler = handler;
+ parser->m_defaultExpandInternalEntities = XML_TRUE;
}
void XMLCALL
@@ -1705,22 +1626,22 @@ XML_SetDoctypeDeclHandler(XML_Parser parser,
{
if (parser == NULL)
return;
- startDoctypeDeclHandler = start;
- endDoctypeDeclHandler = end;
+ parser->m_startDoctypeDeclHandler = start;
+ parser->m_endDoctypeDeclHandler = end;
}
void XMLCALL
XML_SetStartDoctypeDeclHandler(XML_Parser parser,
XML_StartDoctypeDeclHandler start) {
if (parser != NULL)
- startDoctypeDeclHandler = start;
+ parser->m_startDoctypeDeclHandler = start;
}
void XMLCALL
XML_SetEndDoctypeDeclHandler(XML_Parser parser,
XML_EndDoctypeDeclHandler end) {
if (parser != NULL)
- endDoctypeDeclHandler = end;
+ parser->m_endDoctypeDeclHandler = end;
}
void XMLCALL
@@ -1728,7 +1649,7 @@ XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
XML_UnparsedEntityDeclHandler handler)
{
if (parser != NULL)
- unparsedEntityDeclHandler = handler;
+ parser->m_unparsedEntityDeclHandler = handler;
}
void XMLCALL
@@ -1736,7 +1657,7 @@ XML_SetNotationDeclHandler(XML_Parser parser,
XML_NotationDeclHandler handler)
{
if (parser != NULL)
- notationDeclHandler = handler;
+ parser->m_notationDeclHandler = handler;
}
void XMLCALL
@@ -1746,22 +1667,22 @@ XML_SetNamespaceDeclHandler(XML_Parser parser,
{
if (parser == NULL)
return;
- startNamespaceDeclHandler = start;
- endNamespaceDeclHandler = end;
+ parser->m_startNamespaceDeclHandler = start;
+ parser->m_endNamespaceDeclHandler = end;
}
void XMLCALL
XML_SetStartNamespaceDeclHandler(XML_Parser parser,
XML_StartNamespaceDeclHandler start) {
if (parser != NULL)
- startNamespaceDeclHandler = start;
+ parser->m_startNamespaceDeclHandler = start;
}
void XMLCALL
XML_SetEndNamespaceDeclHandler(XML_Parser parser,
XML_EndNamespaceDeclHandler end) {
if (parser != NULL)
- endNamespaceDeclHandler = end;
+ parser->m_endNamespaceDeclHandler = end;
}
void XMLCALL
@@ -1769,7 +1690,7 @@ XML_SetNotStandaloneHandler(XML_Parser parser,
XML_NotStandaloneHandler handler)
{
if (parser != NULL)
- notStandaloneHandler = handler;
+ parser->m_notStandaloneHandler = handler;
}
void XMLCALL
@@ -1777,7 +1698,7 @@ XML_SetExternalEntityRefHandler(XML_Parser parser,
XML_ExternalEntityRefHandler handler)
{
if (parser != NULL)
- externalEntityRefHandler = handler;
+ parser->m_externalEntityRefHandler = handler;
}
void XMLCALL
@@ -1786,9 +1707,9 @@ XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg)
if (parser == NULL)
return;
if (arg)
- externalEntityRefHandlerArg = (XML_Parser)arg;
+ parser->m_externalEntityRefHandlerArg = (XML_Parser)arg;
else
- externalEntityRefHandlerArg = parser;
+ parser->m_externalEntityRefHandlerArg = parser;
}
void XMLCALL
@@ -1796,7 +1717,7 @@ XML_SetSkippedEntityHandler(XML_Parser parser,
XML_SkippedEntityHandler handler)
{
if (parser != NULL)
- skippedEntityHandler = handler;
+ parser->m_skippedEntityHandler = handler;
}
void XMLCALL
@@ -1806,8 +1727,8 @@ XML_SetUnknownEncodingHandler(XML_Parser parser,
{
if (parser == NULL)
return;
- unknownEncodingHandler = handler;
- unknownEncodingHandlerData = data;
+ parser->m_unknownEncodingHandler = handler;
+ parser->m_unknownEncodingHandlerData = data;
}
void XMLCALL
@@ -1815,7 +1736,7 @@ XML_SetElementDeclHandler(XML_Parser parser,
XML_ElementDeclHandler eldecl)
{
if (parser != NULL)
- elementDeclHandler = eldecl;
+ parser->m_elementDeclHandler = eldecl;
}
void XMLCALL
@@ -1823,7 +1744,7 @@ XML_SetAttlistDeclHandler(XML_Parser parser,
XML_AttlistDeclHandler attdecl)
{
if (parser != NULL)
- attlistDeclHandler = attdecl;
+ parser->m_attlistDeclHandler = attdecl;
}
void XMLCALL
@@ -1831,14 +1752,14 @@ XML_SetEntityDeclHandler(XML_Parser parser,
XML_EntityDeclHandler handler)
{
if (parser != NULL)
- entityDeclHandler = handler;
+ parser->m_entityDeclHandler = handler;
}
void XMLCALL
XML_SetXmlDeclHandler(XML_Parser parser,
XML_XmlDeclHandler handler) {
if (parser != NULL)
- xmlDeclHandler = handler;
+ parser->m_xmlDeclHandler = handler;
}
int XMLCALL
@@ -1848,10 +1769,10 @@ XML_SetParamEntityParsing(XML_Parser parser,
if (parser == NULL)
return 0;
/* block after XML_Parse()/XML_ParseBuffer() has been called */
- if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
+ if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED)
return 0;
#ifdef XML_DTD
- paramEntityParsing = peParsing;
+ parser->m_paramEntityParsing = peParsing;
return 1;
#else
return peParsing == XML_PARAM_ENTITY_PARSING_NEVER;
@@ -1867,9 +1788,9 @@ XML_SetHashSalt(XML_Parser parser,
if (parser->m_parentParser)
return XML_SetHashSalt(parser->m_parentParser, hash_salt);
/* block after XML_Parse()/XML_ParseBuffer() has been called */
- if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
+ if (parser->m_parsingStatus.parsing == XML_PARSING || parser->m_parsingStatus.parsing == XML_SUSPENDED)
return 0;
- hash_secret_salt = hash_salt;
+ parser->m_hash_secret_salt = hash_salt;
return 1;
}
@@ -1881,37 +1802,38 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
parser->m_errorCode = XML_ERROR_INVALID_ARGUMENT;
return XML_STATUS_ERROR;
}
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
- errorCode = XML_ERROR_SUSPENDED;
+ parser->m_errorCode = XML_ERROR_SUSPENDED;
return XML_STATUS_ERROR;
case XML_FINISHED:
- errorCode = XML_ERROR_FINISHED;
+ parser->m_errorCode = XML_ERROR_FINISHED;
return XML_STATUS_ERROR;
case XML_INITIALIZED:
- if (parentParser == NULL && !startParsing(parser)) {
- errorCode = XML_ERROR_NO_MEMORY;
+ if (parser->m_parentParser == NULL && !startParsing(parser)) {
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
return XML_STATUS_ERROR;
}
+ /* fall through */
default:
- ps_parsing = XML_PARSING;
+ parser->m_parsingStatus.parsing = XML_PARSING;
}
if (len == 0) {
- ps_finalBuffer = (XML_Bool)isFinal;
+ parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal;
if (!isFinal)
return XML_STATUS_OK;
- positionPtr = bufferPtr;
- parseEndPtr = bufferEnd;
+ parser->m_positionPtr = parser->m_bufferPtr;
+ parser->m_parseEndPtr = parser->m_bufferEnd;
/* If data are left over from last buffer, and we now know that these
data are the final chunk of input, then we have to check them again
to detect errors based on that fact.
*/
- errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);
+ parser->m_errorCode = parser->m_processor(parser, parser->m_bufferPtr, parser->m_parseEndPtr, &parser->m_bufferPtr);
- if (errorCode == XML_ERROR_NONE) {
- switch (ps_parsing) {
+ if (parser->m_errorCode == XML_ERROR_NONE) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
/* It is hard to be certain, but it seems that this case
* cannot occur. This code is cleaning up a previous parse
@@ -1925,54 +1847,54 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
*
* LCOV_EXCL_START
*/
- XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
- positionPtr = bufferPtr;
+ XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_bufferPtr, &parser->m_position);
+ parser->m_positionPtr = parser->m_bufferPtr;
return XML_STATUS_SUSPENDED;
/* LCOV_EXCL_STOP */
case XML_INITIALIZED:
case XML_PARSING:
- ps_parsing = XML_FINISHED;
+ parser->m_parsingStatus.parsing = XML_FINISHED;
/* fall through */
default:
return XML_STATUS_OK;
}
}
- eventEndPtr = eventPtr;
- processor = errorProcessor;
+ parser->m_eventEndPtr = parser->m_eventPtr;
+ parser->m_processor = errorProcessor;
return XML_STATUS_ERROR;
}
#ifndef XML_CONTEXT_BYTES
- else if (bufferPtr == bufferEnd) {
+ else if (parser->m_bufferPtr == parser->m_bufferEnd) {
const char *end;
int nLeftOver;
enum XML_Status result;
/* Detect overflow (a+b > MAX <==> b > MAX-a) */
- if (len > ((XML_Size)-1) / 2 - parseEndByteIndex) {
- errorCode = XML_ERROR_NO_MEMORY;
- eventPtr = eventEndPtr = NULL;
- processor = errorProcessor;
+ if (len > ((XML_Size)-1) / 2 - parser->m_parseEndByteIndex) {
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
+ parser->m_eventPtr = parser->m_eventEndPtr = NULL;
+ parser->m_processor = errorProcessor;
return XML_STATUS_ERROR;
}
- parseEndByteIndex += len;
- positionPtr = s;
- ps_finalBuffer = (XML_Bool)isFinal;
+ parser->m_parseEndByteIndex += len;
+ parser->m_positionPtr = s;
+ parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal;
- errorCode = processor(parser, s, parseEndPtr = s + len, &end);
+ parser->m_errorCode = parser->m_processor(parser, s, parser->m_parseEndPtr = s + len, &end);
- if (errorCode != XML_ERROR_NONE) {
- eventEndPtr = eventPtr;
- processor = errorProcessor;
+ if (parser->m_errorCode != XML_ERROR_NONE) {
+ parser->m_eventEndPtr = parser->m_eventPtr;
+ parser->m_processor = errorProcessor;
return XML_STATUS_ERROR;
}
else {
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
result = XML_STATUS_SUSPENDED;
break;
case XML_INITIALIZED:
case XML_PARSING:
if (isFinal) {
- ps_parsing = XML_FINISHED;
+ parser->m_parsingStatus.parsing = XML_FINISHED;
return XML_STATUS_OK;
}
/* fall through */
@@ -1981,35 +1903,33 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
}
}
- XmlUpdatePosition(encoding, positionPtr, end, &position);
+ XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, end, &parser->m_position);
nLeftOver = s + len - end;
if (nLeftOver) {
- if (buffer == NULL || nLeftOver > bufferLim - buffer) {
+ if (parser->m_buffer == NULL || nLeftOver > parser->m_bufferLim - parser->m_buffer) {
/* avoid _signed_ integer overflow */
char *temp = NULL;
const int bytesToAllocate = (int)((unsigned)len * 2U);
if (bytesToAllocate > 0) {
- temp = (buffer == NULL
- ? (char *)MALLOC(bytesToAllocate)
- : (char *)REALLOC(buffer, bytesToAllocate));
+ temp = (char *)REALLOC(parser, parser->m_buffer, bytesToAllocate);
}
if (temp == NULL) {
- errorCode = XML_ERROR_NO_MEMORY;
- eventPtr = eventEndPtr = NULL;
- processor = errorProcessor;
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
+ parser->m_eventPtr = parser->m_eventEndPtr = NULL;
+ parser->m_processor = errorProcessor;
return XML_STATUS_ERROR;
}
- buffer = temp;
- bufferLim = buffer + bytesToAllocate;
+ parser->m_buffer = temp;
+ parser->m_bufferLim = parser->m_buffer + bytesToAllocate;
}
- memcpy(buffer, end, nLeftOver);
+ memcpy(parser->m_buffer, end, nLeftOver);
}
- bufferPtr = buffer;
- bufferEnd = buffer + nLeftOver;
- positionPtr = bufferPtr;
- parseEndPtr = bufferEnd;
- eventPtr = bufferPtr;
- eventEndPtr = bufferPtr;
+ parser->m_bufferPtr = parser->m_buffer;
+ parser->m_bufferEnd = parser->m_buffer + nLeftOver;
+ parser->m_positionPtr = parser->m_bufferPtr;
+ parser->m_parseEndPtr = parser->m_bufferEnd;
+ parser->m_eventPtr = parser->m_bufferPtr;
+ parser->m_eventEndPtr = parser->m_bufferPtr;
return result;
}
#endif /* not defined XML_CONTEXT_BYTES */
@@ -2032,53 +1952,54 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
if (parser == NULL)
return XML_STATUS_ERROR;
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
- errorCode = XML_ERROR_SUSPENDED;
+ parser->m_errorCode = XML_ERROR_SUSPENDED;
return XML_STATUS_ERROR;
case XML_FINISHED:
- errorCode = XML_ERROR_FINISHED;
+ parser->m_errorCode = XML_ERROR_FINISHED;
return XML_STATUS_ERROR;
case XML_INITIALIZED:
- if (parentParser == NULL && !startParsing(parser)) {
- errorCode = XML_ERROR_NO_MEMORY;
+ if (parser->m_parentParser == NULL && !startParsing(parser)) {
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
return XML_STATUS_ERROR;
}
+ /* fall through */
default:
- ps_parsing = XML_PARSING;
+ parser->m_parsingStatus.parsing = XML_PARSING;
}
- start = bufferPtr;
- positionPtr = start;
- bufferEnd += len;
- parseEndPtr = bufferEnd;
- parseEndByteIndex += len;
- ps_finalBuffer = (XML_Bool)isFinal;
+ start = parser->m_bufferPtr;
+ parser->m_positionPtr = start;
+ parser->m_bufferEnd += len;
+ parser->m_parseEndPtr = parser->m_bufferEnd;
+ parser->m_parseEndByteIndex += len;
+ parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal;
- errorCode = processor(parser, start, parseEndPtr, &bufferPtr);
+ parser->m_errorCode = parser->m_processor(parser, start, parser->m_parseEndPtr, &parser->m_bufferPtr);
- if (errorCode != XML_ERROR_NONE) {
- eventEndPtr = eventPtr;
- processor = errorProcessor;
+ if (parser->m_errorCode != XML_ERROR_NONE) {
+ parser->m_eventEndPtr = parser->m_eventPtr;
+ parser->m_processor = errorProcessor;
return XML_STATUS_ERROR;
}
else {
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
result = XML_STATUS_SUSPENDED;
break;
case XML_INITIALIZED:
case XML_PARSING:
if (isFinal) {
- ps_parsing = XML_FINISHED;
+ parser->m_parsingStatus.parsing = XML_FINISHED;
return result;
}
default: ; /* should not happen */
}
}
- XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
- positionPtr = bufferPtr;
+ XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_bufferPtr, &parser->m_position);
+ parser->m_positionPtr = parser->m_bufferPtr;
return result;
}
@@ -2088,52 +2009,59 @@ XML_GetBuffer(XML_Parser parser, int len)
if (parser == NULL)
return NULL;
if (len < 0) {
- errorCode = XML_ERROR_NO_MEMORY;
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
return NULL;
}
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
- errorCode = XML_ERROR_SUSPENDED;
+ parser->m_errorCode = XML_ERROR_SUSPENDED;
return NULL;
case XML_FINISHED:
- errorCode = XML_ERROR_FINISHED;
+ parser->m_errorCode = XML_ERROR_FINISHED;
return NULL;
default: ;
}
- if (len > bufferLim - bufferEnd) {
+ if (len > EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferEnd)) {
#ifdef XML_CONTEXT_BYTES
int keep;
#endif /* defined XML_CONTEXT_BYTES */
/* Do not invoke signed arithmetic overflow: */
- int neededSize = (int) ((unsigned)len + (unsigned)(bufferEnd - bufferPtr));
+ int neededSize = (int) ((unsigned)len +
+ (unsigned)EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd,
+ parser->m_bufferPtr));
if (neededSize < 0) {
- errorCode = XML_ERROR_NO_MEMORY;
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
return NULL;
}
#ifdef XML_CONTEXT_BYTES
- keep = (int)(bufferPtr - buffer);
+ keep = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer);
if (keep > XML_CONTEXT_BYTES)
keep = XML_CONTEXT_BYTES;
neededSize += keep;
#endif /* defined XML_CONTEXT_BYTES */
- if (neededSize <= bufferLim - buffer) {
+ if (neededSize <= EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_buffer)) {
#ifdef XML_CONTEXT_BYTES
- if (keep < bufferPtr - buffer) {
- int offset = (int)(bufferPtr - buffer) - keep;
- memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep);
- bufferEnd -= offset;
- bufferPtr -= offset;
+ if (keep < EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer)) {
+ int offset = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer) - keep;
+ /* The buffer pointers cannot be NULL here; we have at least some bytes in the buffer */
+ memmove(parser->m_buffer, &parser->m_buffer[offset], parser->m_bufferEnd - parser->m_bufferPtr + keep);
+ parser->m_bufferEnd -= offset;
+ parser->m_bufferPtr -= offset;
}
#else
- memmove(buffer, bufferPtr, bufferEnd - bufferPtr);
- bufferEnd = buffer + (bufferEnd - bufferPtr);
- bufferPtr = buffer;
+ if (parser->m_buffer && parser->m_bufferPtr) {
+ memmove(parser->m_buffer, parser->m_bufferPtr,
+ EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr));
+ parser->m_bufferEnd = parser->m_buffer +
+ EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr);
+ parser->m_bufferPtr = parser->m_buffer;
+ }
#endif /* not defined XML_CONTEXT_BYTES */
}
else {
char *newBuf;
- int bufferSize = (int)(bufferLim - bufferPtr);
+ int bufferSize = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferPtr);
if (bufferSize == 0)
bufferSize = INIT_BUFFER_SIZE;
do {
@@ -2141,43 +2069,52 @@ XML_GetBuffer(XML_Parser parser, int len)
bufferSize = (int) (2U * (unsigned) bufferSize);
} while (bufferSize < neededSize && bufferSize > 0);
if (bufferSize <= 0) {
- errorCode = XML_ERROR_NO_MEMORY;
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
return NULL;
}
- newBuf = (char *)MALLOC(bufferSize);
+ newBuf = (char *)MALLOC(parser, bufferSize);
if (newBuf == 0) {
- errorCode = XML_ERROR_NO_MEMORY;
+ parser->m_errorCode = XML_ERROR_NO_MEMORY;
return NULL;
}
- bufferLim = newBuf + bufferSize;
+ parser->m_bufferLim = newBuf + bufferSize;
#ifdef XML_CONTEXT_BYTES
- if (bufferPtr) {
- int keep = (int)(bufferPtr - buffer);
+ if (parser->m_bufferPtr) {
+ int keep = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer);
if (keep > XML_CONTEXT_BYTES)
keep = XML_CONTEXT_BYTES;
- memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep);
- FREE(buffer);
- buffer = newBuf;
- bufferEnd = buffer + (bufferEnd - bufferPtr) + keep;
- bufferPtr = buffer + keep;
+ memcpy(newBuf, &parser->m_bufferPtr[-keep],
+ EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + keep);
+ FREE(parser, parser->m_buffer);
+ parser->m_buffer = newBuf;
+ parser->m_bufferEnd = parser->m_buffer +
+ EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) + keep;
+ parser->m_bufferPtr = parser->m_buffer + keep;
}
else {
- bufferEnd = newBuf + (bufferEnd - bufferPtr);
- bufferPtr = buffer = newBuf;
+ /* This must be a brand new buffer with no data in it yet */
+ parser->m_bufferEnd = newBuf;
+ parser->m_bufferPtr = parser->m_buffer = newBuf;
}
#else
- if (bufferPtr) {
- memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr);
- FREE(buffer);
+ if (parser->m_bufferPtr) {
+ memcpy(newBuf, parser->m_bufferPtr,
+ EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr));
+ FREE(parser, parser->m_buffer);
+ parser->m_bufferEnd = newBuf +
+ EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr);
+ }
+ else {
+ /* This must be a brand new buffer with no data in it yet */
+ parser->m_bufferEnd = newBuf;
}
- bufferEnd = newBuf + (bufferEnd - bufferPtr);
- bufferPtr = buffer = newBuf;
+ parser->m_bufferPtr = parser->m_buffer = newBuf;
#endif /* not defined XML_CONTEXT_BYTES */
}
- eventPtr = eventEndPtr = NULL;
- positionPtr = NULL;
+ parser->m_eventPtr = parser->m_eventEndPtr = NULL;
+ parser->m_positionPtr = NULL;
}
- return bufferEnd;
+ return parser->m_bufferEnd;
}
enum XML_Status XMLCALL
@@ -2185,29 +2122,29 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable)
{
if (parser == NULL)
return XML_STATUS_ERROR;
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
if (resumable) {
- errorCode = XML_ERROR_SUSPENDED;
+ parser->m_errorCode = XML_ERROR_SUSPENDED;
return XML_STATUS_ERROR;
}
- ps_parsing = XML_FINISHED;
+ parser->m_parsingStatus.parsing = XML_FINISHED;
break;
case XML_FINISHED:
- errorCode = XML_ERROR_FINISHED;
+ parser->m_errorCode = XML_ERROR_FINISHED;
return XML_STATUS_ERROR;
default:
if (resumable) {
#ifdef XML_DTD
- if (isParamEntity) {
- errorCode = XML_ERROR_SUSPEND_PE;
+ if (parser->m_isParamEntity) {
+ parser->m_errorCode = XML_ERROR_SUSPEND_PE;
return XML_STATUS_ERROR;
}
#endif
- ps_parsing = XML_SUSPENDED;
+ parser->m_parsingStatus.parsing = XML_SUSPENDED;
}
else
- ps_parsing = XML_FINISHED;
+ parser->m_parsingStatus.parsing = XML_FINISHED;
}
return XML_STATUS_OK;
}
@@ -2219,36 +2156,36 @@ XML_ResumeParser(XML_Parser parser)
if (parser == NULL)
return XML_STATUS_ERROR;
- if (ps_parsing != XML_SUSPENDED) {
- errorCode = XML_ERROR_NOT_SUSPENDED;
+ if (parser->m_parsingStatus.parsing != XML_SUSPENDED) {
+ parser->m_errorCode = XML_ERROR_NOT_SUSPENDED;
return XML_STATUS_ERROR;
}
- ps_parsing = XML_PARSING;
+ parser->m_parsingStatus.parsing = XML_PARSING;
- errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr);
+ parser->m_errorCode = parser->m_processor(parser, parser->m_bufferPtr, parser->m_parseEndPtr, &parser->m_bufferPtr);
- if (errorCode != XML_ERROR_NONE) {
- eventEndPtr = eventPtr;
- processor = errorProcessor;
+ if (parser->m_errorCode != XML_ERROR_NONE) {
+ parser->m_eventEndPtr = parser->m_eventPtr;
+ parser->m_processor = errorProcessor;
return XML_STATUS_ERROR;
}
else {
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
result = XML_STATUS_SUSPENDED;
break;
case XML_INITIALIZED:
case XML_PARSING:
- if (ps_finalBuffer) {
- ps_parsing = XML_FINISHED;
+ if (parser->m_parsingStatus.finalBuffer) {
+ parser->m_parsingStatus.parsing = XML_FINISHED;
return result;
}
default: ;
}
}
- XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
- positionPtr = bufferPtr;
+ XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_bufferPtr, &parser->m_position);
+ parser->m_positionPtr = parser->m_bufferPtr;
return result;
}
@@ -2266,7 +2203,7 @@ XML_GetErrorCode(XML_Parser parser)
{
if (parser == NULL)
return XML_ERROR_INVALID_ARGUMENT;
- return errorCode;
+ return parser->m_errorCode;
}
XML_Index XMLCALL
@@ -2274,8 +2211,8 @@ XML_GetCurrentByteIndex(XML_Parser parser)
{
if (parser == NULL)
return -1;
- if (eventPtr)
- return (XML_Index)(parseEndByteIndex - (parseEndPtr - eventPtr));
+ if (parser->m_eventPtr)
+ return (XML_Index)(parser->m_parseEndByteIndex - (parser->m_parseEndPtr - parser->m_eventPtr));
return -1;
}
@@ -2284,8 +2221,8 @@ XML_GetCurrentByteCount(XML_Parser parser)
{
if (parser == NULL)
return 0;
- if (eventEndPtr && eventPtr)
- return (int)(eventEndPtr - eventPtr);
+ if (parser->m_eventEndPtr && parser->m_eventPtr)
+ return (int)(parser->m_eventEndPtr - parser->m_eventPtr);
return 0;
}
@@ -2295,12 +2232,12 @@ XML_GetInputContext(XML_Parser parser, int *offset, int *size)
#ifdef XML_CONTEXT_BYTES
if (parser == NULL)
return NULL;
- if (eventPtr && buffer) {
+ if (parser->m_eventPtr && parser->m_buffer) {
if (offset != NULL)
- *offset = (int)(eventPtr - buffer);
+ *offset = (int)(parser->m_eventPtr - parser->m_buffer);
if (size != NULL)
- *size = (int)(bufferEnd - buffer);
- return buffer;
+ *size = (int)(parser->m_bufferEnd - parser->m_buffer);
+ return parser->m_buffer;
}
#else
(void)parser;
@@ -2315,11 +2252,11 @@ XML_GetCurrentLineNumber(XML_Parser parser)
{
if (parser == NULL)
return 0;
- if (eventPtr && eventPtr >= positionPtr) {
- XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);
- positionPtr = eventPtr;
+ if (parser->m_eventPtr && parser->m_eventPtr >= parser->m_positionPtr) {
+ XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_eventPtr, &parser->m_position);
+ parser->m_positionPtr = parser->m_eventPtr;
}
- return position.lineNumber + 1;
+ return parser->m_position.lineNumber + 1;
}
XML_Size XMLCALL
@@ -2327,18 +2264,18 @@ XML_GetCurrentColumnNumber(XML_Parser parser)
{
if (parser == NULL)
return 0;
- if (eventPtr && eventPtr >= positionPtr) {
- XmlUpdatePosition(encoding, positionPtr, eventPtr, &position);
- positionPtr = eventPtr;
+ if (parser->m_eventPtr && parser->m_eventPtr >= parser->m_positionPtr) {
+ XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, parser->m_eventPtr, &parser->m_position);
+ parser->m_positionPtr = parser->m_eventPtr;
}
- return position.columnNumber;
+ return parser->m_position.columnNumber;
}
void XMLCALL
XML_FreeContentModel(XML_Parser parser, XML_Content *model)
{
if (parser != NULL)
- FREE(model);
+ FREE(parser, model);
}
void * XMLCALL
@@ -2346,7 +2283,7 @@ XML_MemMalloc(XML_Parser parser, size_t size)
{
if (parser == NULL)
return NULL;
- return MALLOC(size);
+ return MALLOC(parser, size);
}
void * XMLCALL
@@ -2354,14 +2291,14 @@ XML_MemRealloc(XML_Parser parser, void *ptr, size_t size)
{
if (parser == NULL)
return NULL;
- return REALLOC(ptr, size);
+ return REALLOC(parser, ptr, size);
}
void XMLCALL
XML_MemFree(XML_Parser parser, void *ptr)
{
if (parser != NULL)
- FREE(ptr);
+ FREE(parser, ptr);
}
void XMLCALL
@@ -2369,65 +2306,110 @@ XML_DefaultCurrent(XML_Parser parser)
{
if (parser == NULL)
return;
- if (defaultHandler) {
- if (openInternalEntities)
+ if (parser->m_defaultHandler) {
+ if (parser->m_openInternalEntities)
reportDefault(parser,
- internalEncoding,
- openInternalEntities->internalEventPtr,
- openInternalEntities->internalEventEndPtr);
+ parser->m_internalEncoding,
+ parser->m_openInternalEntities->internalEventPtr,
+ parser->m_openInternalEntities->internalEventEndPtr);
else
- reportDefault(parser, encoding, eventPtr, eventEndPtr);
+ reportDefault(parser, parser->m_encoding, parser->m_eventPtr, parser->m_eventEndPtr);
}
}
const XML_LChar * XMLCALL
XML_ErrorString(enum XML_Error code)
{
- static const XML_LChar* const message[] = {
- 0,
- XML_L("out of memory"),
- XML_L("syntax error"),
- XML_L("no element found"),
- XML_L("not well-formed (invalid token)"),
- XML_L("unclosed token"),
- XML_L("partial character"),
- XML_L("mismatched tag"),
- XML_L("duplicate attribute"),
- XML_L("junk after document element"),
- XML_L("illegal parameter entity reference"),
- XML_L("undefined entity"),
- XML_L("recursive entity reference"),
- XML_L("asynchronous entity"),
- XML_L("reference to invalid character number"),
- XML_L("reference to binary entity"),
- XML_L("reference to external entity in attribute"),
- XML_L("XML or text declaration not at start of entity"),
- XML_L("unknown encoding"),
- XML_L("encoding specified in XML declaration is incorrect"),
- XML_L("unclosed CDATA section"),
- XML_L("error in processing external entity reference"),
- XML_L("document is not standalone"),
- XML_L("unexpected parser state - please send a bug report"),
- XML_L("entity declared in parameter entity"),
- XML_L("requested feature requires XML_DTD support in Expat"),
- XML_L("cannot change setting once parsing has begun"),
- XML_L("unbound prefix"),
- XML_L("must not undeclare prefix"),
- XML_L("incomplete markup in parameter entity"),
- XML_L("XML declaration not well-formed"),
- XML_L("text declaration not well-formed"),
- XML_L("illegal character(s) in public id"),
- XML_L("parser suspended"),
- XML_L("parser not suspended"),
- XML_L("parsing aborted"),
- XML_L("parsing finished"),
- XML_L("cannot suspend in external parameter entity"),
- XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"),
- XML_L("reserved prefix (xmlns) must not be declared or undeclared"),
- XML_L("prefix must not be bound to one of the reserved namespace names")
- };
- if (code > 0 && code < sizeof(message)/sizeof(message[0]))
- return message[code];
+ switch (code) {
+ case XML_ERROR_NONE:
+ return NULL;
+ case XML_ERROR_NO_MEMORY:
+ return XML_L("out of memory");
+ case XML_ERROR_SYNTAX:
+ return XML_L("syntax error");
+ case XML_ERROR_NO_ELEMENTS:
+ return XML_L("no element found");
+ case XML_ERROR_INVALID_TOKEN:
+ return XML_L("not well-formed (invalid token)");
+ case XML_ERROR_UNCLOSED_TOKEN:
+ return XML_L("unclosed token");
+ case XML_ERROR_PARTIAL_CHAR:
+ return XML_L("partial character");
+ case XML_ERROR_TAG_MISMATCH:
+ return XML_L("mismatched tag");
+ case XML_ERROR_DUPLICATE_ATTRIBUTE:
+ return XML_L("duplicate attribute");
+ case XML_ERROR_JUNK_AFTER_DOC_ELEMENT:
+ return XML_L("junk after document element");
+ case XML_ERROR_PARAM_ENTITY_REF:
+ return XML_L("illegal parameter entity reference");
+ case XML_ERROR_UNDEFINED_ENTITY:
+ return XML_L("undefined entity");
+ case XML_ERROR_RECURSIVE_ENTITY_REF:
+ return XML_L("recursive entity reference");
+ case XML_ERROR_ASYNC_ENTITY:
+ return XML_L("asynchronous entity");
+ case XML_ERROR_BAD_CHAR_REF:
+ return XML_L("reference to invalid character number");
+ case XML_ERROR_BINARY_ENTITY_REF:
+ return XML_L("reference to binary entity");
+ case XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF:
+ return XML_L("reference to external entity in attribute");
+ case XML_ERROR_MISPLACED_XML_PI:
+ return XML_L("XML or text declaration not at start of entity");
+ case XML_ERROR_UNKNOWN_ENCODING:
+ return XML_L("unknown encoding");
+ case XML_ERROR_INCORRECT_ENCODING:
+ return XML_L("encoding specified in XML declaration is incorrect");
+ case XML_ERROR_UNCLOSED_CDATA_SECTION:
+ return XML_L("unclosed CDATA section");
+ case XML_ERROR_EXTERNAL_ENTITY_HANDLING:
+ return XML_L("error in processing external entity reference");
+ case XML_ERROR_NOT_STANDALONE:
+ return XML_L("document is not standalone");
+ case XML_ERROR_UNEXPECTED_STATE:
+ return XML_L("unexpected parser state - please send a bug report");
+ case XML_ERROR_ENTITY_DECLARED_IN_PE:
+ return XML_L("entity declared in parameter entity");
+ case XML_ERROR_FEATURE_REQUIRES_XML_DTD:
+ return XML_L("requested feature requires XML_DTD support in Expat");
+ case XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING:
+ return XML_L("cannot change setting once parsing has begun");
+ /* Added in 1.95.7. */
+ case XML_ERROR_UNBOUND_PREFIX:
+ return XML_L("unbound prefix");
+ /* Added in 1.95.8. */
+ case XML_ERROR_UNDECLARING_PREFIX:
+ return XML_L("must not undeclare prefix");
+ case XML_ERROR_INCOMPLETE_PE:
+ return XML_L("incomplete markup in parameter entity");
+ case XML_ERROR_XML_DECL:
+ return XML_L("XML declaration not well-formed");
+ case XML_ERROR_TEXT_DECL:
+ return XML_L("text declaration not well-formed");
+ case XML_ERROR_PUBLICID:
+ return XML_L("illegal character(s) in public id");
+ case XML_ERROR_SUSPENDED:
+ return XML_L("parser suspended");
+ case XML_ERROR_NOT_SUSPENDED:
+ return XML_L("parser not suspended");
+ case XML_ERROR_ABORTED:
+ return XML_L("parsing aborted");
+ case XML_ERROR_FINISHED:
+ return XML_L("parsing finished");
+ case XML_ERROR_SUSPEND_PE:
+ return XML_L("cannot suspend in external parameter entity");
+ /* Added in 2.0.0. */
+ case XML_ERROR_RESERVED_PREFIX_XML:
+ return XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name");
+ case XML_ERROR_RESERVED_PREFIX_XMLNS:
+ return XML_L("reserved prefix (xmlns) must not be declared or undeclared");
+ case XML_ERROR_RESERVED_NAMESPACE_URI:
+ return XML_L("prefix must not be bound to one of the reserved namespace names");
+ /* Added in 2.2.5. */
+ case XML_ERROR_INVALID_ARGUMENT: /* Constant added in 2.2.1, already */
+ return XML_L("invalid argument");
+ }
return NULL;
}
@@ -2510,12 +2492,12 @@ XML_GetFeatureList(void)
static XML_Bool
storeRawNames(XML_Parser parser)
{
- TAG *tag = tagStack;
+ TAG *tag = parser->m_tagStack;
while (tag) {
int bufSize;
int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1);
char *rawNameBuf = tag->buf + nameLen;
- /* Stop if already stored. Since tagStack is a stack, we can stop
+ /* Stop if already stored. Since m_tagStack is a stack, we can stop
at the first entry that has already been copied; everything
below it in the stack is already been accounted for in a
previous call to this function.
@@ -2527,7 +2509,7 @@ storeRawNames(XML_Parser parser)
*/
bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char));
if (bufSize > tag->bufEnd - tag->buf) {
- char *temp = (char *)REALLOC(tag->buf, bufSize);
+ char *temp = (char *)REALLOC(parser, tag->buf, bufSize);
if (temp == NULL)
return XML_FALSE;
/* if tag->name.str points to tag->buf (only when namespace
@@ -2558,8 +2540,8 @@ contentProcessor(XML_Parser parser,
const char *end,
const char **endPtr)
{
- enum XML_Error result = doContent(parser, 0, encoding, start, end,
- endPtr, (XML_Bool)!ps_finalBuffer);
+ enum XML_Error result = doContent(parser, 0, parser->m_encoding, start, end,
+ endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer);
if (result == XML_ERROR_NONE) {
if (!storeRawNames(parser))
return XML_ERROR_NO_MEMORY;
@@ -2576,7 +2558,7 @@ externalEntityInitProcessor(XML_Parser parser,
enum XML_Error result = initializeEncoding(parser);
if (result != XML_ERROR_NONE)
return result;
- processor = externalEntityInitProcessor2;
+ parser->m_processor = externalEntityInitProcessor2;
return externalEntityInitProcessor2(parser, start, end, endPtr);
}
@@ -2587,7 +2569,7 @@ externalEntityInitProcessor2(XML_Parser parser,
const char **endPtr)
{
const char *next = start; /* XmlContentTok doesn't always set the last arg */
- int tok = XmlContentTok(encoding, start, end, &next);
+ int tok = XmlContentTok(parser->m_encoding, start, end, &next);
switch (tok) {
case XML_TOK_BOM:
/* If we are at the end of the buffer, this would cause the next stage,
@@ -2595,28 +2577,28 @@ externalEntityInitProcessor2(XML_Parser parser,
doContent (by detecting XML_TOK_NONE) without processing any xml text
declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent.
*/
- if (next == end && !ps_finalBuffer) {
+ if (next == end && !parser->m_parsingStatus.finalBuffer) {
*endPtr = next;
return XML_ERROR_NONE;
}
start = next;
break;
case XML_TOK_PARTIAL:
- if (!ps_finalBuffer) {
+ if (!parser->m_parsingStatus.finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
- eventPtr = start;
+ parser->m_eventPtr = start;
return XML_ERROR_UNCLOSED_TOKEN;
case XML_TOK_PARTIAL_CHAR:
- if (!ps_finalBuffer) {
+ if (!parser->m_parsingStatus.finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
- eventPtr = start;
+ parser->m_eventPtr = start;
return XML_ERROR_PARTIAL_CHAR;
}
- processor = externalEntityInitProcessor3;
+ parser->m_processor = externalEntityInitProcessor3;
return externalEntityInitProcessor3(parser, start, end, endPtr);
}
@@ -2628,9 +2610,9 @@ externalEntityInitProcessor3(XML_Parser parser,
{
int tok;
const char *next = start; /* XmlContentTok doesn't always set the last arg */
- eventPtr = start;
- tok = XmlContentTok(encoding, start, end, &next);
- eventEndPtr = next;
+ parser->m_eventPtr = start;
+ tok = XmlContentTok(parser->m_encoding, start, end, &next);
+ parser->m_eventEndPtr = next;
switch (tok) {
case XML_TOK_XML_DECL:
@@ -2639,7 +2621,7 @@ externalEntityInitProcessor3(XML_Parser parser,
result = processXmlDecl(parser, 1, start, next);
if (result != XML_ERROR_NONE)
return result;
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
*endPtr = next;
return XML_ERROR_NONE;
@@ -2651,20 +2633,20 @@ externalEntityInitProcessor3(XML_Parser parser,
}
break;
case XML_TOK_PARTIAL:
- if (!ps_finalBuffer) {
+ if (!parser->m_parsingStatus.finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
return XML_ERROR_UNCLOSED_TOKEN;
case XML_TOK_PARTIAL_CHAR:
- if (!ps_finalBuffer) {
+ if (!parser->m_parsingStatus.finalBuffer) {
*endPtr = start;
return XML_ERROR_NONE;
}
return XML_ERROR_PARTIAL_CHAR;
}
- processor = externalEntityContentProcessor;
- tagLevel = 1;
+ parser->m_processor = externalEntityContentProcessor;
+ parser->m_tagLevel = 1;
return externalEntityContentProcessor(parser, start, end, endPtr);
}
@@ -2674,8 +2656,8 @@ externalEntityContentProcessor(XML_Parser parser,
const char *end,
const char **endPtr)
{
- enum XML_Error result = doContent(parser, 1, encoding, start, end,
- endPtr, (XML_Bool)!ps_finalBuffer);
+ enum XML_Error result = doContent(parser, 1, parser->m_encoding, start, end,
+ endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer);
if (result == XML_ERROR_NONE) {
if (!storeRawNames(parser))
return XML_ERROR_NO_MEMORY;
@@ -2693,17 +2675,17 @@ doContent(XML_Parser parser,
XML_Bool haveMore)
{
/* save one level of indirection */
- DTD * const dtd = _dtd;
+ DTD * const dtd = parser->m_dtd;
const char **eventPP;
const char **eventEndPP;
- if (enc == encoding) {
- eventPP = &eventPtr;
- eventEndPP = &eventEndPtr;
+ if (enc == parser->m_encoding) {
+ eventPP = &parser->m_eventPtr;
+ eventEndPP = &parser->m_eventEndPtr;
}
else {
- eventPP = &(openInternalEntities->internalEventPtr);
- eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ eventPP = &(parser->m_openInternalEntities->internalEventPtr);
+ eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr);
}
*eventPP = s;
@@ -2718,18 +2700,18 @@ doContent(XML_Parser parser,
return XML_ERROR_NONE;
}
*eventEndPP = end;
- if (characterDataHandler) {
+ if (parser->m_characterDataHandler) {
XML_Char c = 0xA;
- characterDataHandler(handlerArg, &c, 1);
+ parser->m_characterDataHandler(parser->m_handlerArg, &c, 1);
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, end);
/* We are at the end of the final buffer, should we check for
XML_SUSPENDED, XML_FINISHED?
*/
if (startTagLevel == 0)
return XML_ERROR_NO_ELEMENTS;
- if (tagLevel != startTagLevel)
+ if (parser->m_tagLevel != startTagLevel)
return XML_ERROR_ASYNC_ENTITY;
*nextPtr = end;
return XML_ERROR_NONE;
@@ -2739,7 +2721,7 @@ doContent(XML_Parser parser,
return XML_ERROR_NONE;
}
if (startTagLevel > 0) {
- if (tagLevel != startTagLevel)
+ if (parser->m_tagLevel != startTagLevel)
return XML_ERROR_ASYNC_ENTITY;
*nextPtr = s;
return XML_ERROR_NONE;
@@ -2768,9 +2750,9 @@ doContent(XML_Parser parser,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar);
if (ch) {
- if (characterDataHandler)
- characterDataHandler(handlerArg, &ch, 1);
- else if (defaultHandler)
+ if (parser->m_characterDataHandler)
+ parser->m_characterDataHandler(parser->m_handlerArg, &ch, 1);
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
break;
}
@@ -2792,9 +2774,9 @@ doContent(XML_Parser parser,
return XML_ERROR_ENTITY_DECLARED_IN_PE;
}
else if (!entity) {
- if (skippedEntityHandler)
- skippedEntityHandler(handlerArg, name, 0);
- else if (defaultHandler)
+ if (parser->m_skippedEntityHandler)
+ parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0);
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
break;
}
@@ -2804,10 +2786,10 @@ doContent(XML_Parser parser,
return XML_ERROR_BINARY_ENTITY_REF;
if (entity->textPtr) {
enum XML_Error result;
- if (!defaultExpandInternalEntities) {
- if (skippedEntityHandler)
- skippedEntityHandler(handlerArg, entity->name, 0);
- else if (defaultHandler)
+ if (!parser->m_defaultExpandInternalEntities) {
+ if (parser->m_skippedEntityHandler)
+ parser->m_skippedEntityHandler(parser->m_handlerArg, entity->name, 0);
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
break;
}
@@ -2815,22 +2797,22 @@ doContent(XML_Parser parser,
if (result != XML_ERROR_NONE)
return result;
}
- else if (externalEntityRefHandler) {
+ else if (parser->m_externalEntityRefHandler) {
const XML_Char *context;
entity->open = XML_TRUE;
context = getContext(parser);
entity->open = XML_FALSE;
if (!context)
return XML_ERROR_NO_MEMORY;
- if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg,
context,
entity->base,
entity->systemId,
entity->publicId))
return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
- poolDiscard(&tempPool);
+ poolDiscard(&parser->m_tempPool);
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
break;
}
@@ -2841,29 +2823,29 @@ doContent(XML_Parser parser,
TAG *tag;
enum XML_Error result;
XML_Char *toPtr;
- if (freeTagList) {
- tag = freeTagList;
- freeTagList = freeTagList->parent;
+ if (parser->m_freeTagList) {
+ tag = parser->m_freeTagList;
+ parser->m_freeTagList = parser->m_freeTagList->parent;
}
else {
- tag = (TAG *)MALLOC(sizeof(TAG));
+ tag = (TAG *)MALLOC(parser, sizeof(TAG));
if (!tag)
return XML_ERROR_NO_MEMORY;
- tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE);
+ tag->buf = (char *)MALLOC(parser, INIT_TAG_BUF_SIZE);
if (!tag->buf) {
- FREE(tag);
+ FREE(parser, tag);
return XML_ERROR_NO_MEMORY;
}
tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE;
}
tag->bindings = NULL;
- tag->parent = tagStack;
- tagStack = tag;
+ tag->parent = parser->m_tagStack;
+ parser->m_tagStack = tag;
tag->name.localPart = NULL;
tag->name.prefix = NULL;
tag->rawName = s + enc->minBytesPerChar;
tag->rawNameLength = XmlNameLength(enc, tag->rawName);
- ++tagLevel;
+ ++parser->m_tagLevel;
{
const char *rawNameEnd = tag->rawName + tag->rawNameLength;
const char *fromPtr = tag->rawName;
@@ -2881,7 +2863,7 @@ doContent(XML_Parser parser,
}
bufSize = (int)(tag->bufEnd - tag->buf) << 1;
{
- char *temp = (char *)REALLOC(tag->buf, bufSize);
+ char *temp = (char *)REALLOC(parser, tag->buf, bufSize);
if (temp == NULL)
return XML_ERROR_NO_MEMORY;
tag->buf = temp;
@@ -2895,12 +2877,12 @@ doContent(XML_Parser parser,
result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
if (result)
return result;
- if (startElementHandler)
- startElementHandler(handlerArg, tag->name.str,
- (const XML_Char **)atts);
- else if (defaultHandler)
+ if (parser->m_startElementHandler)
+ parser->m_startElementHandler(parser->m_handlerArg, tag->name.str,
+ (const XML_Char **)parser->m_atts);
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
- poolClear(&tempPool);
+ poolClear(&parser->m_tempPool);
break;
}
case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
@@ -2912,45 +2894,49 @@ doContent(XML_Parser parser,
BINDING *bindings = NULL;
XML_Bool noElmHandlers = XML_TRUE;
TAG_NAME name;
- name.str = poolStoreString(&tempPool, enc, rawName,
+ name.str = poolStoreString(&parser->m_tempPool, enc, rawName,
rawName + XmlNameLength(enc, rawName));
if (!name.str)
return XML_ERROR_NO_MEMORY;
- poolFinish(&tempPool);
+ poolFinish(&parser->m_tempPool);
result = storeAtts(parser, enc, s, &name, &bindings);
if (result != XML_ERROR_NONE) {
freeBindings(parser, bindings);
return result;
}
- poolFinish(&tempPool);
- if (startElementHandler) {
- startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
+ poolFinish(&parser->m_tempPool);
+ if (parser->m_startElementHandler) {
+ parser->m_startElementHandler(parser->m_handlerArg, name.str, (const XML_Char **)parser->m_atts);
noElmHandlers = XML_FALSE;
}
- if (endElementHandler) {
- if (startElementHandler)
+ if (parser->m_endElementHandler) {
+ if (parser->m_startElementHandler)
*eventPP = *eventEndPP;
- endElementHandler(handlerArg, name.str);
+ parser->m_endElementHandler(parser->m_handlerArg, name.str);
noElmHandlers = XML_FALSE;
}
- if (noElmHandlers && defaultHandler)
+ if (noElmHandlers && parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
- poolClear(&tempPool);
+ poolClear(&parser->m_tempPool);
freeBindings(parser, bindings);
}
- if (tagLevel == 0)
- return epilogProcessor(parser, next, end, nextPtr);
+ if ((parser->m_tagLevel == 0) && (parser->m_parsingStatus.parsing != XML_FINISHED)) {
+ if (parser->m_parsingStatus.parsing == XML_SUSPENDED)
+ parser->m_processor = epilogProcessor;
+ else
+ return epilogProcessor(parser, next, end, nextPtr);
+ }
break;
case XML_TOK_END_TAG:
- if (tagLevel == startTagLevel)
+ if (parser->m_tagLevel == startTagLevel)
return XML_ERROR_ASYNC_ENTITY;
else {
int len;
const char *rawName;
- TAG *tag = tagStack;
- tagStack = tag->parent;
- tag->parent = freeTagList;
- freeTagList = tag;
+ TAG *tag = parser->m_tagStack;
+ parser->m_tagStack = tag->parent;
+ tag->parent = parser->m_freeTagList;
+ parser->m_freeTagList = tag;
rawName = s + enc->minBytesPerChar*2;
len = XmlNameLength(enc, rawName);
if (len != tag->rawNameLength
@@ -2958,13 +2944,13 @@ doContent(XML_Parser parser,
*eventPP = rawName;
return XML_ERROR_TAG_MISMATCH;
}
- --tagLevel;
- if (endElementHandler) {
+ --parser->m_tagLevel;
+ if (parser->m_endElementHandler) {
const XML_Char *localPart;
const XML_Char *prefix;
XML_Char *uri;
localPart = tag->name.localPart;
- if (ns && localPart) {
+ if (parser->m_ns && localPart) {
/* localPart and prefix may have been overwritten in
tag->name.str, since this points to the binding->uri
buffer which gets re-used; so we have to add them again
@@ -2973,26 +2959,26 @@ doContent(XML_Parser parser,
/* don't need to check for space - already done in storeAtts() */
while (*localPart) *uri++ = *localPart++;
prefix = (XML_Char *)tag->name.prefix;
- if (ns_triplets && prefix) {
- *uri++ = namespaceSeparator;
+ if (parser->m_ns_triplets && prefix) {
+ *uri++ = parser->m_namespaceSeparator;
while (*prefix) *uri++ = *prefix++;
}
*uri = XML_T('\0');
}
- endElementHandler(handlerArg, tag->name.str);
+ parser->m_endElementHandler(parser->m_handlerArg, tag->name.str);
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
while (tag->bindings) {
BINDING *b = tag->bindings;
- if (endNamespaceDeclHandler)
- endNamespaceDeclHandler(handlerArg, b->prefix->name);
+ if (parser->m_endNamespaceDeclHandler)
+ parser->m_endNamespaceDeclHandler(parser->m_handlerArg, b->prefix->name);
tag->bindings = tag->bindings->nextTagBinding;
- b->nextTagBinding = freeBindingList;
- freeBindingList = b;
+ b->nextTagBinding = parser->m_freeBindingList;
+ parser->m_freeBindingList = b;
b->prefix->binding = b->prevPrefixBinding;
}
- if (tagLevel == 0)
+ if (parser->m_tagLevel == 0)
return epilogProcessor(parser, next, end, nextPtr);
}
break;
@@ -3001,30 +2987,30 @@ doContent(XML_Parser parser,
int n = XmlCharRefNumber(enc, s);
if (n < 0)
return XML_ERROR_BAD_CHAR_REF;
- if (characterDataHandler) {
+ if (parser->m_characterDataHandler) {
XML_Char buf[XML_ENCODE_MAX];
- characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf));
+ parser->m_characterDataHandler(parser->m_handlerArg, buf, XmlEncode(n, (ICHAR *)buf));
}
- else if (defaultHandler)
+ else if (parser->m_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) {
+ if (parser->m_characterDataHandler) {
XML_Char c = 0xA;
- characterDataHandler(handlerArg, &c, 1);
+ parser->m_characterDataHandler(parser->m_handlerArg, &c, 1);
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
break;
case XML_TOK_CDATA_SECT_OPEN:
{
enum XML_Error result;
- if (startCdataSectionHandler)
- startCdataSectionHandler(handlerArg);
-#if 0
+ if (parser->m_startCdataSectionHandler)
+ parser->m_startCdataSectionHandler(parser->m_handlerArg);
+/* BEGIN disabled code */
/* 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
@@ -3037,16 +3023,16 @@ doContent(XML_Parser parser,
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)
+ else if (0 && parser->m_characterDataHandler)
+ parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, 0);
+/* END disabled code */
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore);
if (result != XML_ERROR_NONE)
return result;
else if (!next) {
- processor = cdataSectionProcessor;
+ parser->m_processor = cdataSectionProcessor;
return result;
}
}
@@ -3056,19 +3042,19 @@ doContent(XML_Parser parser,
*nextPtr = s;
return XML_ERROR_NONE;
}
- if (characterDataHandler) {
+ if (parser->m_characterDataHandler) {
if (MUST_CONVERT(enc, s)) {
- ICHAR *dataPtr = (ICHAR *)dataBuf;
- XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
- characterDataHandler(handlerArg, dataBuf,
- (int)(dataPtr - (ICHAR *)dataBuf));
+ ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf;
+ XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)parser->m_dataBufEnd);
+ parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf,
+ (int)(dataPtr - (ICHAR *)parser->m_dataBuf));
}
else
- characterDataHandler(handlerArg,
+ parser->m_characterDataHandler(parser->m_handlerArg,
(XML_Char *)s,
(int)((XML_Char *)end - (XML_Char *)s));
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, end);
/* We are at the end of the final buffer, should we check for
XML_SUSPENDED, XML_FINISHED?
@@ -3077,7 +3063,7 @@ doContent(XML_Parser parser,
*eventPP = end;
return XML_ERROR_NO_ELEMENTS;
}
- if (tagLevel != startTagLevel) {
+ if (parser->m_tagLevel != startTagLevel) {
*eventPP = end;
return XML_ERROR_ASYNC_ENTITY;
}
@@ -3085,26 +3071,26 @@ doContent(XML_Parser parser,
return XML_ERROR_NONE;
case XML_TOK_DATA_CHARS:
{
- XML_CharacterDataHandler charDataHandler = characterDataHandler;
+ XML_CharacterDataHandler charDataHandler = parser->m_characterDataHandler;
if (charDataHandler) {
if (MUST_CONVERT(enc, s)) {
for (;;) {
- ICHAR *dataPtr = (ICHAR *)dataBuf;
- const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
+ ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf;
+ const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)parser->m_dataBufEnd);
*eventEndPP = s;
- charDataHandler(handlerArg, dataBuf,
- (int)(dataPtr - (ICHAR *)dataBuf));
+ charDataHandler(parser->m_handlerArg, parser->m_dataBuf,
+ (int)(dataPtr - (ICHAR *)parser->m_dataBuf));
if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE))
break;
*eventPP = s;
}
}
else
- charDataHandler(handlerArg,
+ charDataHandler(parser->m_handlerArg,
(XML_Char *)s,
(int)((XML_Char *)next - (XML_Char *)s));
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
}
break;
@@ -3124,13 +3110,13 @@ doContent(XML_Parser parser,
*
* LCOV_EXCL_START
*/
- if (defaultHandler)
+ if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
break;
/* LCOV_EXCL_STOP */
}
*eventPP = s = next;
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -3143,7 +3129,7 @@ doContent(XML_Parser parser,
}
/* This function does not call free() on the allocated memory, merely
- * moving it to the parser's freeBindingList where it can be freed or
+ * moving it to the parser's m_freeBindingList where it can be freed or
* reused as appropriate.
*/
static void
@@ -3152,15 +3138,15 @@ freeBindings(XML_Parser parser, BINDING *bindings)
while (bindings) {
BINDING *b = bindings;
- /* startNamespaceDeclHandler will have been called for this
+ /* m_startNamespaceDeclHandler will have been called for this
* binding in addBindings(), so call the end handler now.
*/
- if (endNamespaceDeclHandler)
- endNamespaceDeclHandler(handlerArg, b->prefix->name);
+ if (parser->m_endNamespaceDeclHandler)
+ parser->m_endNamespaceDeclHandler(parser->m_handlerArg, b->prefix->name);
bindings = bindings->nextTagBinding;
- b->nextTagBinding = freeBindingList;
- freeBindingList = b;
+ b->nextTagBinding = parser->m_freeBindingList;
+ parser->m_freeBindingList = b;
b->prefix->binding = b->prevPrefixBinding;
}
}
@@ -3180,7 +3166,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
const char *attStr, TAG_NAME *tagNamePtr,
BINDING **bindingsPtr)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
ELEMENT_TYPE *elementType;
int nDefaultAtts;
const XML_Char **appAtts; /* the attribute list for the application */
@@ -3203,43 +3189,43 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
sizeof(ELEMENT_TYPE));
if (!elementType)
return XML_ERROR_NO_MEMORY;
- if (ns && !setElementTypePrefix(parser, elementType))
+ if (parser->m_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;
+ n = XmlGetAttributes(enc, attStr, parser->m_attsSize, parser->m_atts);
+ if (n + nDefaultAtts > parser->m_attsSize) {
+ int oldAttsSize = parser->m_attsSize;
ATTRIBUTE *temp;
#ifdef XML_ATTR_INFO
XML_AttrInfo *temp2;
#endif
- attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
- temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));
+ parser->m_attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
+ temp = (ATTRIBUTE *)REALLOC(parser, (void *)parser->m_atts, parser->m_attsSize * sizeof(ATTRIBUTE));
if (temp == NULL) {
- attsSize = oldAttsSize;
+ parser->m_attsSize = oldAttsSize;
return XML_ERROR_NO_MEMORY;
}
- atts = temp;
+ parser->m_atts = temp;
#ifdef XML_ATTR_INFO
- temp2 = (XML_AttrInfo *)REALLOC((void *)attInfo, attsSize * sizeof(XML_AttrInfo));
+ temp2 = (XML_AttrInfo *)REALLOC(parser, (void *)parser->m_attInfo, parser->m_attsSize * sizeof(XML_AttrInfo));
if (temp2 == NULL) {
- attsSize = oldAttsSize;
+ parser->m_attsSize = oldAttsSize;
return XML_ERROR_NO_MEMORY;
}
- attInfo = temp2;
+ parser->m_attInfo = temp2;
#endif
if (n > oldAttsSize)
- XmlGetAttributes(enc, attStr, n, atts);
+ XmlGetAttributes(enc, attStr, n, parser->m_atts);
}
- appAtts = (const XML_Char **)atts;
+ appAtts = (const XML_Char **)parser->m_atts;
for (i = 0; i < n; i++) {
- ATTRIBUTE *currAtt = &atts[i];
+ ATTRIBUTE *currAtt = &parser->m_atts[i];
#ifdef XML_ATTR_INFO
- XML_AttrInfo *currAttInfo = &attInfo[i];
+ XML_AttrInfo *currAttInfo = &parser->m_attInfo[i];
#endif
/* add the name and value to the attribute list */
ATTRIBUTE_ID *attId = getAttributeId(parser, enc, currAtt->name,
@@ -3248,25 +3234,25 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
if (!attId)
return XML_ERROR_NO_MEMORY;
#ifdef XML_ATTR_INFO
- currAttInfo->nameStart = parseEndByteIndex - (parseEndPtr - currAtt->name);
+ currAttInfo->nameStart = parser->m_parseEndByteIndex - (parser->m_parseEndPtr - currAtt->name);
currAttInfo->nameEnd = currAttInfo->nameStart +
XmlNameLength(enc, currAtt->name);
- currAttInfo->valueStart = parseEndByteIndex -
- (parseEndPtr - currAtt->valuePtr);
- currAttInfo->valueEnd = parseEndByteIndex - (parseEndPtr - currAtt->valueEnd);
+ currAttInfo->valueStart = parser->m_parseEndByteIndex -
+ (parser->m_parseEndPtr - currAtt->valuePtr);
+ currAttInfo->valueEnd = parser->m_parseEndByteIndex - (parser->m_parseEndPtr - currAtt->valueEnd);
#endif
/* Detect duplicate attributes by their QNames. This does not work when
namespace processing is turned on and different prefixes for the same
namespace are used. For this case we have a check further down.
*/
if ((attId->name)[-1]) {
- if (enc == encoding)
- eventPtr = atts[i].name;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = parser->m_atts[i].name;
return XML_ERROR_DUPLICATE_ATTRIBUTE;
}
(attId->name)[-1] = 1;
appAtts[attIndex++] = attId->name;
- if (!atts[i].normalized) {
+ if (!parser->m_atts[i].normalized) {
enum XML_Error result;
XML_Bool isCdata = XML_TRUE;
@@ -3283,20 +3269,20 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
/* normalize the attribute value */
result = storeAttributeValue(parser, enc, isCdata,
- atts[i].valuePtr, atts[i].valueEnd,
- &tempPool);
+ parser->m_atts[i].valuePtr, parser->m_atts[i].valueEnd,
+ &parser->m_tempPool);
if (result)
return result;
- appAtts[attIndex] = poolStart(&tempPool);
- poolFinish(&tempPool);
+ appAtts[attIndex] = poolStart(&parser->m_tempPool);
+ poolFinish(&parser->m_tempPool);
}
else {
/* the value did not need normalizing */
- appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr,
- atts[i].valueEnd);
+ appAtts[attIndex] = poolStoreString(&parser->m_tempPool, enc, parser->m_atts[i].valuePtr,
+ parser->m_atts[i].valueEnd);
if (appAtts[attIndex] == 0)
return XML_ERROR_NO_MEMORY;
- poolFinish(&tempPool);
+ poolFinish(&parser->m_tempPool);
}
/* handle prefixed attribute names */
if (attId->prefix) {
@@ -3320,16 +3306,16 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
}
/* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */
- nSpecifiedAtts = attIndex;
+ parser->m_nSpecifiedAtts = attIndex;
if (elementType->idAtt && (elementType->idAtt->name)[-1]) {
for (i = 0; i < attIndex; i += 2)
if (appAtts[i] == elementType->idAtt->name) {
- idAttIndex = i;
+ parser->m_idAttIndex = i;
break;
}
}
else
- idAttIndex = -1;
+ parser->m_idAttIndex = -1;
/* do attribute defaulting */
for (i = 0; i < nDefaultAtts; i++) {
@@ -3363,33 +3349,33 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
i = 0;
if (nPrefixes) {
int j; /* hash table index */
- unsigned long version = nsAttsVersion;
- int nsAttsSize = (int)1 << nsAttsPower;
- unsigned char oldNsAttsPower = nsAttsPower;
+ unsigned long version = parser->m_nsAttsVersion;
+ int nsAttsSize = (int)1 << parser->m_nsAttsPower;
+ unsigned char oldNsAttsPower = parser->m_nsAttsPower;
/* size of hash table must be at least 2 * (# of prefixed attributes) */
- if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */
+ if ((nPrefixes << 1) >> parser->m_nsAttsPower) { /* true for m_nsAttsPower = 0 */
NS_ATT *temp;
/* hash table size must also be a power of 2 and >= 8 */
- while (nPrefixes >> nsAttsPower++);
- if (nsAttsPower < 3)
- nsAttsPower = 3;
- nsAttsSize = (int)1 << nsAttsPower;
- temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT));
+ while (nPrefixes >> parser->m_nsAttsPower++);
+ if (parser->m_nsAttsPower < 3)
+ parser->m_nsAttsPower = 3;
+ nsAttsSize = (int)1 << parser->m_nsAttsPower;
+ temp = (NS_ATT *)REALLOC(parser, parser->m_nsAtts, nsAttsSize * sizeof(NS_ATT));
if (!temp) {
- /* Restore actual size of memory in nsAtts */
- nsAttsPower = oldNsAttsPower;
+ /* Restore actual size of memory in m_nsAtts */
+ parser->m_nsAttsPower = oldNsAttsPower;
return XML_ERROR_NO_MEMORY;
}
- nsAtts = temp;
- version = 0; /* force re-initialization of nsAtts hash table */
+ parser->m_nsAtts = temp;
+ version = 0; /* force re-initialization of m_nsAtts hash table */
}
- /* using a version flag saves us from initializing nsAtts every time */
+ /* using a version flag saves us from initializing m_nsAtts every time */
if (!version) { /* initialize version flags when version wraps around */
version = INIT_ATTS_VERSION;
for (j = nsAttsSize; j != 0; )
- nsAtts[--j].version = version;
+ parser->m_nsAtts[--j].version = version;
}
- nsAttsVersion = --version;
+ parser->m_nsAttsVersion = --version;
/* expand prefixed names and check for duplicates */
for (; i < attIndex; i += 2) {
@@ -3429,7 +3415,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
for (j = 0; j < b->uriLen; j++) {
const XML_Char c = b->uri[j];
- if (!poolAppendChar(&tempPool, c))
+ if (!poolAppendChar(&parser->m_tempPool, c))
return XML_ERROR_NO_MEMORY;
}
@@ -3441,7 +3427,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
sip24_update(&sip_state, s, keylen(s) * sizeof(XML_Char));
do { /* copies null terminator */
- if (!poolAppendChar(&tempPool, *s))
+ if (!poolAppendChar(&parser->m_tempPool, *s))
return XML_ERROR_NO_MEMORY;
} while (*s++);
@@ -3453,40 +3439,40 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
unsigned char step = 0;
unsigned long mask = nsAttsSize - 1;
j = uriHash & mask; /* index into hash table */
- while (nsAtts[j].version == version) {
+ while (parser->m_nsAtts[j].version == version) {
/* for speed we compare stored hash values first */
- if (uriHash == nsAtts[j].hash) {
- const XML_Char *s1 = poolStart(&tempPool);
- const XML_Char *s2 = nsAtts[j].uriName;
+ if (uriHash == parser->m_nsAtts[j].hash) {
+ const XML_Char *s1 = poolStart(&parser->m_tempPool);
+ const XML_Char *s2 = parser->m_nsAtts[j].uriName;
/* s1 is null terminated, but not s2 */
for (; *s1 == *s2 && *s1 != 0; s1++, s2++);
if (*s1 == 0)
return XML_ERROR_DUPLICATE_ATTRIBUTE;
}
if (!step)
- step = PROBE_STEP(uriHash, mask, nsAttsPower);
+ step = PROBE_STEP(uriHash, mask, parser->m_nsAttsPower);
j < step ? (j += nsAttsSize - step) : (j -= step);
}
}
- if (ns_triplets) { /* append namespace separator and prefix */
- tempPool.ptr[-1] = namespaceSeparator;
+ if (parser->m_ns_triplets) { /* append namespace separator and prefix */
+ parser->m_tempPool.ptr[-1] = parser->m_namespaceSeparator;
s = b->prefix->name;
do {
- if (!poolAppendChar(&tempPool, *s))
+ if (!poolAppendChar(&parser->m_tempPool, *s))
return XML_ERROR_NO_MEMORY;
} while (*s++);
}
/* store expanded name in attribute list */
- s = poolStart(&tempPool);
- poolFinish(&tempPool);
+ s = poolStart(&parser->m_tempPool);
+ poolFinish(&parser->m_tempPool);
appAtts[i] = s;
/* fill empty slot with new version, uriName and hash value */
- nsAtts[j].version = version;
- nsAtts[j].hash = uriHash;
- nsAtts[j].uriName = s;
+ parser->m_nsAtts[j].version = version;
+ parser->m_nsAtts[j].hash = uriHash;
+ parser->m_nsAtts[j].uriName = s;
if (!--nPrefixes) {
i += 2;
@@ -3503,7 +3489,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)
binding->attId->name[-1] = 0;
- if (!ns)
+ if (!parser->m_ns)
return XML_ERROR_NONE;
/* expand the element type name */
@@ -3522,7 +3508,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
else
return XML_ERROR_NONE;
prefixLen = 0;
- if (ns_triplets && binding->prefix->name) {
+ if (parser->m_ns_triplets && binding->prefix->name) {
for (; binding->prefix->name[prefixLen++];)
; /* prefixLen includes null terminator */
}
@@ -3535,24 +3521,24 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
n = i + binding->uriLen + prefixLen;
if (n > binding->uriAlloc) {
TAG *p;
- uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char));
+ uri = (XML_Char *)MALLOC(parser, (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)
+ for (p = parser->m_tagStack; p; p = p->parent)
if (p->name.str == binding->uri)
p->name.str = uri;
- FREE(binding->uri);
+ FREE(parser, binding->uri);
binding->uri = uri;
}
- /* if namespaceSeparator != '\0' then uri includes it already */
+ /* if m_namespaceSeparator != '\0' then uri includes it already */
uri = binding->uri + binding->uriLen;
memcpy(uri, localPart, i * sizeof(XML_Char));
/* we always have a namespace separator between localPart and prefix */
if (prefixLen) {
uri += i - 1;
- *uri = namespaceSeparator; /* replace null terminator */
+ *uri = parser->m_namespaceSeparator; /* replace null terminator */
memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char));
}
tagNamePtr->str = binding->uri;
@@ -3630,48 +3616,48 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
if (isXMLNS)
return XML_ERROR_RESERVED_NAMESPACE_URI;
- if (namespaceSeparator)
+ if (parser->m_namespaceSeparator)
len++;
- if (freeBindingList) {
- b = freeBindingList;
+ if (parser->m_freeBindingList) {
+ b = parser->m_freeBindingList;
if (len > b->uriAlloc) {
- XML_Char *temp = (XML_Char *)REALLOC(b->uri,
+ XML_Char *temp = (XML_Char *)REALLOC(parser, b->uri,
sizeof(XML_Char) * (len + EXPAND_SPARE));
if (temp == NULL)
return XML_ERROR_NO_MEMORY;
b->uri = temp;
b->uriAlloc = len + EXPAND_SPARE;
}
- freeBindingList = b->nextTagBinding;
+ parser->m_freeBindingList = b->nextTagBinding;
}
else {
- b = (BINDING *)MALLOC(sizeof(BINDING));
+ b = (BINDING *)MALLOC(parser, sizeof(BINDING));
if (!b)
return XML_ERROR_NO_MEMORY;
- b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE));
+ b->uri = (XML_Char *)MALLOC(parser, sizeof(XML_Char) * (len + EXPAND_SPARE));
if (!b->uri) {
- FREE(b);
+ FREE(parser, b);
return XML_ERROR_NO_MEMORY;
}
b->uriAlloc = len + EXPAND_SPARE;
}
b->uriLen = len;
memcpy(b->uri, uri, len * sizeof(XML_Char));
- if (namespaceSeparator)
- b->uri[len - 1] = namespaceSeparator;
+ if (parser->m_namespaceSeparator)
+ b->uri[len - 1] = parser->m_namespaceSeparator;
b->prefix = prefix;
b->attId = attId;
b->prevPrefixBinding = prefix->binding;
/* NULL binding when default namespace undeclared */
- if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix)
+ if (*uri == XML_T('\0') && prefix == &parser->m_dtd->defaultPrefix)
prefix->binding = NULL;
else
prefix->binding = b;
b->nextTagBinding = *bindingsPtr;
*bindingsPtr = b;
/* if attId == NULL then we are not starting a namespace scope */
- if (attId && startNamespaceDeclHandler)
- startNamespaceDeclHandler(handlerArg, prefix->name,
+ if (attId && parser->m_startNamespaceDeclHandler)
+ parser->m_startNamespaceDeclHandler(parser->m_handlerArg, prefix->name,
prefix->binding ? uri : 0);
return XML_ERROR_NONE;
}
@@ -3685,17 +3671,17 @@ cdataSectionProcessor(XML_Parser parser,
const char *end,
const char **endPtr)
{
- enum XML_Error result = doCdataSection(parser, encoding, &start, end,
- endPtr, (XML_Bool)!ps_finalBuffer);
+ enum XML_Error result = doCdataSection(parser, parser->m_encoding, &start, end,
+ endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer);
if (result != XML_ERROR_NONE)
return result;
if (start) {
- if (parentParser) { /* we are parsing an external entity */
- processor = externalEntityContentProcessor;
+ if (parser->m_parentParser) { /* we are parsing an external entity */
+ parser->m_processor = externalEntityContentProcessor;
return externalEntityContentProcessor(parser, start, end, endPtr);
}
else {
- processor = contentProcessor;
+ parser->m_processor = contentProcessor;
return contentProcessor(parser, start, end, endPtr);
}
}
@@ -3716,14 +3702,14 @@ doCdataSection(XML_Parser parser,
const char *s = *startPtr;
const char **eventPP;
const char **eventEndPP;
- if (enc == encoding) {
- eventPP = &eventPtr;
+ if (enc == parser->m_encoding) {
+ eventPP = &parser->m_eventPtr;
*eventPP = s;
- eventEndPP = &eventEndPtr;
+ eventEndPP = &parser->m_eventEndPtr;
}
else {
- eventPP = &(openInternalEntities->internalEventPtr);
- eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ eventPP = &(parser->m_openInternalEntities->internalEventPtr);
+ eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr);
}
*eventPP = s;
*startPtr = NULL;
@@ -3734,51 +3720,51 @@ doCdataSection(XML_Parser parser,
*eventEndPP = next;
switch (tok) {
case XML_TOK_CDATA_SECT_CLOSE:
- if (endCdataSectionHandler)
- endCdataSectionHandler(handlerArg);
-#if 0
+ if (parser->m_endCdataSectionHandler)
+ parser->m_endCdataSectionHandler(parser->m_handlerArg);
+/* BEGIN disabled code */
/* see comment under XML_TOK_CDATA_SECT_OPEN */
- else if (characterDataHandler)
- characterDataHandler(handlerArg, dataBuf, 0);
-#endif
- else if (defaultHandler)
+ else if (0 && parser->m_characterDataHandler)
+ parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, 0);
+/* END disabled code */
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
*startPtr = next;
*nextPtr = next;
- if (ps_parsing == XML_FINISHED)
+ if (parser->m_parsingStatus.parsing == XML_FINISHED)
return XML_ERROR_ABORTED;
else
return XML_ERROR_NONE;
case XML_TOK_DATA_NEWLINE:
- if (characterDataHandler) {
+ if (parser->m_characterDataHandler) {
XML_Char c = 0xA;
- characterDataHandler(handlerArg, &c, 1);
+ parser->m_characterDataHandler(parser->m_handlerArg, &c, 1);
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
break;
case XML_TOK_DATA_CHARS:
{
- XML_CharacterDataHandler charDataHandler = characterDataHandler;
+ XML_CharacterDataHandler charDataHandler = parser->m_characterDataHandler;
if (charDataHandler) {
if (MUST_CONVERT(enc, s)) {
for (;;) {
- ICHAR *dataPtr = (ICHAR *)dataBuf;
- const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);
+ ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf;
+ const enum XML_Convert_Result convert_res = XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)parser->m_dataBufEnd);
*eventEndPP = next;
- charDataHandler(handlerArg, dataBuf,
- (int)(dataPtr - (ICHAR *)dataBuf));
+ charDataHandler(parser->m_handlerArg, parser->m_dataBuf,
+ (int)(dataPtr - (ICHAR *)parser->m_dataBuf));
if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE))
break;
*eventPP = s;
}
}
else
- charDataHandler(handlerArg,
+ charDataHandler(parser->m_handlerArg,
(XML_Char *)s,
(int)((XML_Char *)next - (XML_Char *)s));
}
- else if (defaultHandler)
+ else if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
}
break;
@@ -3812,7 +3798,7 @@ doCdataSection(XML_Parser parser,
}
*eventPP = s = next;
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -3835,12 +3821,12 @@ ignoreSectionProcessor(XML_Parser parser,
const char *end,
const char **endPtr)
{
- enum XML_Error result = doIgnoreSection(parser, encoding, &start, end,
- endPtr, (XML_Bool)!ps_finalBuffer);
+ enum XML_Error result = doIgnoreSection(parser, parser->m_encoding, &start, end,
+ endPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer);
if (result != XML_ERROR_NONE)
return result;
if (start) {
- processor = prologProcessor;
+ parser->m_processor = prologProcessor;
return prologProcessor(parser, start, end, endPtr);
}
return result;
@@ -3862,15 +3848,15 @@ doIgnoreSection(XML_Parser parser,
const char *s = *startPtr;
const char **eventPP;
const char **eventEndPP;
- if (enc == encoding) {
- eventPP = &eventPtr;
+ if (enc == parser->m_encoding) {
+ eventPP = &parser->m_eventPtr;
*eventPP = s;
- eventEndPP = &eventEndPtr;
+ eventEndPP = &parser->m_eventEndPtr;
}
else {
/* It's not entirely clear, but it seems the following two lines
* of code cannot be executed. The only occasions on which 'enc'
- * is not 'parser->m_encoding' are when this function is called
+ * is not 'encoding' are when this function is called
* from the internal entity processing, and IGNORE sections are an
* error in internal entities.
*
@@ -3879,8 +3865,8 @@ doIgnoreSection(XML_Parser parser,
*
* LCOV_EXCL_START
*/
- eventPP = &(openInternalEntities->internalEventPtr);
- eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ eventPP = &(parser->m_openInternalEntities->internalEventPtr);
+ eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr);
/* LCOV_EXCL_STOP */
}
*eventPP = s;
@@ -3889,11 +3875,11 @@ doIgnoreSection(XML_Parser parser,
*eventEndPP = next;
switch (tok) {
case XML_TOK_IGNORE_SECT:
- if (defaultHandler)
+ if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
*startPtr = next;
*nextPtr = next;
- if (ps_parsing == XML_FINISHED)
+ if (parser->m_parsingStatus.parsing == XML_FINISHED)
return XML_ERROR_ABORTED;
else
return XML_ERROR_NONE;
@@ -3937,27 +3923,27 @@ initializeEncoding(XML_Parser parser)
#ifdef XML_UNICODE
char encodingBuf[128];
/* See comments abount `protoclEncodingName` in parserInit() */
- if (!protocolEncodingName)
+ if (!parser->m_protocolEncodingName)
s = NULL;
else {
int i;
- for (i = 0; protocolEncodingName[i]; i++) {
+ for (i = 0; parser->m_protocolEncodingName[i]; i++) {
if (i == sizeof(encodingBuf) - 1
- || (protocolEncodingName[i] & ~0x7f) != 0) {
+ || (parser->m_protocolEncodingName[i] & ~0x7f) != 0) {
encodingBuf[0] = '\0';
break;
}
- encodingBuf[i] = (char)protocolEncodingName[i];
+ encodingBuf[i] = (char)parser->m_protocolEncodingName[i];
}
encodingBuf[i] = '\0';
s = encodingBuf;
}
#else
- s = protocolEncodingName;
+ s = parser->m_protocolEncodingName;
#endif
- if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s))
+ if ((parser->m_ns ? XmlInitEncodingNS : XmlInitEncoding)(&parser->m_initEncoding, &parser->m_encoding, s))
return XML_ERROR_NONE;
- return handleUnknownEncoding(parser, protocolEncodingName);
+ return handleUnknownEncoding(parser, parser->m_protocolEncodingName);
}
static enum XML_Error
@@ -3971,13 +3957,13 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
const char *versionend;
const XML_Char *storedversion = NULL;
int standalone = -1;
- if (!(ns
+ if (!(parser->m_ns
? XmlParseXmlDeclNS
: XmlParseXmlDecl)(isGeneralTextEntity,
- encoding,
+ parser->m_encoding,
s,
next,
- &eventPtr,
+ &parser->m_eventPtr,
&version,
&versionend,
&encodingName,
@@ -3989,69 +3975,69 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
return XML_ERROR_XML_DECL;
}
if (!isGeneralTextEntity && standalone == 1) {
- _dtd->standalone = XML_TRUE;
+ parser->m_dtd->standalone = XML_TRUE;
#ifdef XML_DTD
- if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
- paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
+ if (parser->m_paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
+ parser->m_paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
#endif /* XML_DTD */
}
- if (xmlDeclHandler) {
+ if (parser->m_xmlDeclHandler) {
if (encodingName != NULL) {
- storedEncName = poolStoreString(&temp2Pool,
- encoding,
+ storedEncName = poolStoreString(&parser->m_temp2Pool,
+ parser->m_encoding,
encodingName,
encodingName
- + XmlNameLength(encoding, encodingName));
+ + XmlNameLength(parser->m_encoding, encodingName));
if (!storedEncName)
return XML_ERROR_NO_MEMORY;
- poolFinish(&temp2Pool);
+ poolFinish(&parser->m_temp2Pool);
}
if (version) {
- storedversion = poolStoreString(&temp2Pool,
- encoding,
+ storedversion = poolStoreString(&parser->m_temp2Pool,
+ parser->m_encoding,
version,
- versionend - encoding->minBytesPerChar);
+ versionend - parser->m_encoding->minBytesPerChar);
if (!storedversion)
return XML_ERROR_NO_MEMORY;
}
- xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone);
+ parser->m_xmlDeclHandler(parser->m_handlerArg, storedversion, storedEncName, standalone);
}
- else if (defaultHandler)
- reportDefault(parser, encoding, s, next);
- if (protocolEncodingName == NULL) {
+ else if (parser->m_defaultHandler)
+ reportDefault(parser, parser->m_encoding, s, next);
+ if (parser->m_protocolEncodingName == NULL) {
if (newEncoding) {
/* Check that the specified encoding does not conflict with what
* the parser has already deduced. Do we have the same number
* of bytes in the smallest representation of a character? If
* this is UTF-16, is it the same endianness?
*/
- if (newEncoding->minBytesPerChar != encoding->minBytesPerChar
+ if (newEncoding->minBytesPerChar != parser->m_encoding->minBytesPerChar
|| (newEncoding->minBytesPerChar == 2 &&
- newEncoding != encoding)) {
- eventPtr = encodingName;
+ newEncoding != parser->m_encoding)) {
+ parser->m_eventPtr = encodingName;
return XML_ERROR_INCORRECT_ENCODING;
}
- encoding = newEncoding;
+ parser->m_encoding = newEncoding;
}
else if (encodingName) {
enum XML_Error result;
if (!storedEncName) {
storedEncName = poolStoreString(
- &temp2Pool, encoding, encodingName,
- encodingName + XmlNameLength(encoding, encodingName));
+ &parser->m_temp2Pool, parser->m_encoding, encodingName,
+ encodingName + XmlNameLength(parser->m_encoding, encodingName));
if (!storedEncName)
return XML_ERROR_NO_MEMORY;
}
result = handleUnknownEncoding(parser, storedEncName);
- poolClear(&temp2Pool);
+ poolClear(&parser->m_temp2Pool);
if (result == XML_ERROR_UNKNOWN_ENCODING)
- eventPtr = encodingName;
+ parser->m_eventPtr = encodingName;
return result;
}
}
if (storedEncName || storedversion)
- poolClear(&temp2Pool);
+ poolClear(&parser->m_temp2Pool);
return XML_ERROR_NONE;
}
@@ -4059,7 +4045,7 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
static enum XML_Error
handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName)
{
- if (unknownEncodingHandler) {
+ if (parser->m_unknownEncodingHandler) {
XML_Encoding info;
int i;
for (i = 0; i < 256; i++)
@@ -4067,25 +4053,25 @@ handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName)
info.convert = NULL;
info.data = NULL;
info.release = NULL;
- if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName,
+ if (parser->m_unknownEncodingHandler(parser->m_unknownEncodingHandlerData, encodingName,
&info)) {
ENCODING *enc;
- unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding());
- if (!unknownEncodingMem) {
+ parser->m_unknownEncodingMem = MALLOC(parser, XmlSizeOfUnknownEncoding());
+ if (!parser->m_unknownEncodingMem) {
if (info.release)
info.release(info.data);
return XML_ERROR_NO_MEMORY;
}
- enc = (ns
+ enc = (parser->m_ns
? XmlInitUnknownEncodingNS
- : XmlInitUnknownEncoding)(unknownEncodingMem,
+ : XmlInitUnknownEncoding)(parser->m_unknownEncodingMem,
info.map,
info.convert,
info.data);
if (enc) {
- unknownEncodingData = info.data;
- unknownEncodingRelease = info.release;
- encoding = enc;
+ parser->m_unknownEncodingData = info.data;
+ parser->m_unknownEncodingRelease = info.release;
+ parser->m_encoding = enc;
return XML_ERROR_NONE;
}
}
@@ -4104,7 +4090,7 @@ prologInitProcessor(XML_Parser parser,
enum XML_Error result = initializeEncoding(parser);
if (result != XML_ERROR_NONE)
return result;
- processor = prologProcessor;
+ parser->m_processor = prologProcessor;
return prologProcessor(parser, s, end, nextPtr);
}
@@ -4122,14 +4108,14 @@ externalParEntInitProcessor(XML_Parser parser,
/* we know now that XML_Parse(Buffer) has been called,
so we consider the external parameter entity read */
- _dtd->paramEntityRead = XML_TRUE;
+ parser->m_dtd->paramEntityRead = XML_TRUE;
- if (prologState.inEntityValue) {
- processor = entityValueInitProcessor;
+ if (parser->m_prologState.inEntityValue) {
+ parser->m_processor = entityValueInitProcessor;
return entityValueInitProcessor(parser, s, end, nextPtr);
}
else {
- processor = externalParEntProcessor;
+ parser->m_processor = externalParEntProcessor;
return externalParEntProcessor(parser, s, end, nextPtr);
}
}
@@ -4143,13 +4129,13 @@ entityValueInitProcessor(XML_Parser parser,
int tok;
const char *start = s;
const char *next = start;
- eventPtr = start;
+ parser->m_eventPtr = start;
for (;;) {
- tok = XmlPrologTok(encoding, start, end, &next);
- eventEndPtr = next;
+ tok = XmlPrologTok(parser->m_encoding, start, end, &next);
+ parser->m_eventEndPtr = next;
if (tok <= 0) {
- if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
+ if (!parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -4165,23 +4151,23 @@ entityValueInitProcessor(XML_Parser parser,
break;
}
/* found end of entity value - can store it now */
- return storeEntityValue(parser, encoding, s, end);
+ return storeEntityValue(parser, parser->m_encoding, s, end);
}
else if (tok == XML_TOK_XML_DECL) {
enum XML_Error result;
result = processXmlDecl(parser, 0, start, next);
if (result != XML_ERROR_NONE)
return result;
- /* At this point, ps_parsing cannot be XML_SUSPENDED. For that
+ /* At this point, m_parsingStatus.parsing cannot be XML_SUSPENDED. For that
* to happen, a parameter entity parsing handler must have
* attempted to suspend the parser, which fails and raises an
* error. The parser can be aborted, but can't be suspended.
*/
- if (ps_parsing == XML_FINISHED)
+ if (parser->m_parsingStatus.parsing == XML_FINISHED)
return XML_ERROR_ABORTED;
*nextPtr = next;
/* stop scanning for text declaration - we found one */
- processor = entityValueProcessor;
+ parser->m_processor = entityValueProcessor;
return entityValueProcessor(parser, next, end, nextPtr);
}
/* If we are at the end of the buffer, this would cause XmlPrologTok to
@@ -4191,7 +4177,7 @@ entityValueInitProcessor(XML_Parser parser,
then, when this routine is entered the next time, XmlPrologTok will
return XML_TOK_INVALID, since the BOM is still in the buffer
*/
- else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) {
+ else if (tok == XML_TOK_BOM && next == end && !parser->m_parsingStatus.finalBuffer) {
*nextPtr = next;
return XML_ERROR_NONE;
}
@@ -4204,7 +4190,7 @@ entityValueInitProcessor(XML_Parser parser,
return XML_ERROR_SYNTAX;
}
start = next;
- eventPtr = start;
+ parser->m_eventPtr = start;
}
}
@@ -4217,9 +4203,9 @@ externalParEntProcessor(XML_Parser parser,
const char *next = s;
int tok;
- tok = XmlPrologTok(encoding, s, end, &next);
+ tok = XmlPrologTok(parser->m_encoding, s, end, &next);
if (tok <= 0) {
- if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
+ if (!parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -4241,12 +4227,12 @@ externalParEntProcessor(XML_Parser parser,
*/
else if (tok == XML_TOK_BOM) {
s = next;
- tok = XmlPrologTok(encoding, s, end, &next);
+ tok = XmlPrologTok(parser->m_encoding, s, end, &next);
}
- processor = prologProcessor;
- return doProlog(parser, encoding, s, end, tok, next,
- nextPtr, (XML_Bool)!ps_finalBuffer);
+ parser->m_processor = prologProcessor;
+ return doProlog(parser, parser->m_encoding, s, end, tok, next,
+ nextPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer);
}
static enum XML_Error PTRCALL
@@ -4257,13 +4243,13 @@ entityValueProcessor(XML_Parser parser,
{
const char *start = s;
const char *next = s;
- const ENCODING *enc = encoding;
+ const ENCODING *enc = parser->m_encoding;
int tok;
for (;;) {
tok = XmlPrologTok(enc, start, end, &next);
if (tok <= 0) {
- if (!ps_finalBuffer && tok != XML_TOK_INVALID) {
+ if (!parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -4294,9 +4280,9 @@ prologProcessor(XML_Parser parser,
const char **nextPtr)
{
const char *next = s;
- int tok = XmlPrologTok(encoding, s, end, &next);
- return doProlog(parser, encoding, s, end, tok, next,
- nextPtr, (XML_Bool)!ps_finalBuffer);
+ int tok = XmlPrologTok(parser->m_encoding, s, end, &next);
+ return doProlog(parser, parser->m_encoding, s, end, tok, next,
+ nextPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer);
}
static enum XML_Error
@@ -4333,19 +4319,19 @@ doProlog(XML_Parser parser,
static const XML_Char enumValueStart[] = { ASCII_LPAREN, '\0' };
/* save one level of indirection */
- DTD * const dtd = _dtd;
+ DTD * const dtd = parser->m_dtd;
const char **eventPP;
const char **eventEndPP;
enum XML_Content_Quant quant;
- if (enc == encoding) {
- eventPP = &eventPtr;
- eventEndPP = &eventEndPtr;
+ if (enc == parser->m_encoding) {
+ eventPP = &parser->m_eventPtr;
+ eventEndPP = &parser->m_eventEndPtr;
}
else {
- eventPP = &(openInternalEntities->internalEventPtr);
- eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ eventPP = &(parser->m_openInternalEntities->internalEventPtr);
+ eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr);
}
for (;;) {
@@ -4372,7 +4358,7 @@ doProlog(XML_Parser parser,
case XML_TOK_NONE:
#ifdef XML_DTD
/* for internal PE NOT referenced between declarations */
- if (enc != encoding && !openInternalEntities->betweenDecl) {
+ if (enc != parser->m_encoding && !parser->m_openInternalEntities->betweenDecl) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -4380,8 +4366,8 @@ doProlog(XML_Parser parser,
complete markup, not only for external PEs, but also for
internal PEs if the reference occurs between declarations.
*/
- if (isParamEntity || enc != encoding) {
- if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc)
+ if (parser->m_isParamEntity || enc != parser->m_encoding) {
+ if (XmlTokenRole(&parser->m_prologState, XML_TOK_NONE, end, end, enc)
== XML_ROLE_ERROR)
return XML_ERROR_INCOMPLETE_PE;
*nextPtr = s;
@@ -4395,34 +4381,34 @@ doProlog(XML_Parser parser,
break;
}
}
- role = XmlTokenRole(&prologState, tok, s, next, enc);
+ role = XmlTokenRole(&parser->m_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;
+ enc = parser->m_encoding;
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_DOCTYPE_NAME:
- if (startDoctypeDeclHandler) {
- doctypeName = poolStoreString(&tempPool, enc, s, next);
- if (!doctypeName)
+ if (parser->m_startDoctypeDeclHandler) {
+ parser->m_doctypeName = poolStoreString(&parser->m_tempPool, enc, s, next);
+ if (!parser->m_doctypeName)
return XML_ERROR_NO_MEMORY;
- poolFinish(&tempPool);
- doctypePubid = NULL;
+ poolFinish(&parser->m_tempPool);
+ parser->m_doctypePubid = NULL;
handleDefault = XML_FALSE;
}
- doctypeSysid = NULL; /* always initialize to NULL */
+ parser->m_doctypeSysid = NULL; /* always initialize to NULL */
break;
case XML_ROLE_DOCTYPE_INTERNAL_SUBSET:
- if (startDoctypeDeclHandler) {
- startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid,
- doctypePubid, 1);
- doctypeName = NULL;
- poolClear(&tempPool);
+ if (parser->m_startDoctypeDeclHandler) {
+ parser->m_startDoctypeDeclHandler(parser->m_handlerArg, parser->m_doctypeName, parser->m_doctypeSysid,
+ parser->m_doctypePubid, 1);
+ parser->m_doctypeName = NULL;
+ poolClear(&parser->m_tempPool);
handleDefault = XML_FALSE;
}
break;
@@ -4432,34 +4418,34 @@ doProlog(XML_Parser parser,
enum XML_Error result = processXmlDecl(parser, 1, s, next);
if (result != XML_ERROR_NONE)
return result;
- enc = encoding;
+ enc = parser->m_encoding;
handleDefault = XML_FALSE;
}
break;
#endif /* XML_DTD */
case XML_ROLE_DOCTYPE_PUBLIC_ID:
#ifdef XML_DTD
- useForeignDTD = XML_FALSE;
- declEntity = (ENTITY *)lookup(parser,
+ parser->m_useForeignDTD = XML_FALSE;
+ parser->m_declEntity = (ENTITY *)lookup(parser,
&dtd->paramEntities,
externalSubsetName,
sizeof(ENTITY));
- if (!declEntity)
+ if (!parser->m_declEntity)
return XML_ERROR_NO_MEMORY;
#endif /* XML_DTD */
dtd->hasParamEntityRefs = XML_TRUE;
- if (startDoctypeDeclHandler) {
+ if (parser->m_startDoctypeDeclHandler) {
XML_Char *pubId;
if (!XmlIsPublicId(enc, s, next, eventPP))
return XML_ERROR_PUBLICID;
- pubId = poolStoreString(&tempPool, enc,
+ pubId = poolStoreString(&parser->m_tempPool, enc,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar);
if (!pubId)
return XML_ERROR_NO_MEMORY;
normalizePublicId(pubId);
- poolFinish(&tempPool);
- doctypePubid = pubId;
+ poolFinish(&parser->m_tempPool);
+ parser->m_doctypePubid = pubId;
handleDefault = XML_FALSE;
goto alreadyChecked;
}
@@ -4468,7 +4454,7 @@ doProlog(XML_Parser parser,
if (!XmlIsPublicId(enc, s, next, eventPP))
return XML_ERROR_PUBLICID;
alreadyChecked:
- if (dtd->keepProcessing && declEntity) {
+ if (dtd->keepProcessing && parser->m_declEntity) {
XML_Char *tem = poolStoreString(&dtd->pool,
enc,
s + enc->minBytesPerChar,
@@ -4476,28 +4462,31 @@ doProlog(XML_Parser parser,
if (!tem)
return XML_ERROR_NO_MEMORY;
normalizePublicId(tem);
- declEntity->publicId = tem;
+ parser->m_declEntity->publicId = tem;
poolFinish(&dtd->pool);
- if (entityDeclHandler)
+ /* Don't suppress the default handler if we fell through from
+ * the XML_ROLE_DOCTYPE_PUBLIC_ID case.
+ */
+ if (parser->m_entityDeclHandler && role == XML_ROLE_ENTITY_PUBLIC_ID)
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_DOCTYPE_CLOSE:
- if (doctypeName) {
- startDoctypeDeclHandler(handlerArg, doctypeName,
- doctypeSysid, doctypePubid, 0);
- poolClear(&tempPool);
+ if (parser->m_doctypeName) {
+ parser->m_startDoctypeDeclHandler(parser->m_handlerArg, parser->m_doctypeName,
+ parser->m_doctypeSysid, parser->m_doctypePubid, 0);
+ poolClear(&parser->m_tempPool);
handleDefault = XML_FALSE;
}
- /* doctypeSysid will be non-NULL in the case of a previous
- XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler
+ /* parser->m_doctypeSysid will be non-NULL in the case of a previous
+ XML_ROLE_DOCTYPE_SYSTEM_ID, even if parser->m_startDoctypeDeclHandler
was not set, indicating an external subset
*/
#ifdef XML_DTD
- if (doctypeSysid || useForeignDTD) {
+ if (parser->m_doctypeSysid || parser->m_useForeignDTD) {
XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
dtd->hasParamEntityRefs = XML_TRUE;
- if (paramEntityParsing && externalEntityRefHandler) {
+ if (parser->m_paramEntityParsing && parser->m_externalEntityRefHandler) {
ENTITY *entity = (ENTITY *)lookup(parser,
&dtd->paramEntities,
externalSubsetName,
@@ -4510,10 +4499,10 @@ doProlog(XML_Parser parser,
*/
return XML_ERROR_NO_MEMORY; /* LCOV_EXCL_LINE */
}
- if (useForeignDTD)
- entity->base = curBase;
+ if (parser->m_useForeignDTD)
+ entity->base = parser->m_curBase;
dtd->paramEntityRead = XML_FALSE;
- if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg,
0,
entity->base,
entity->systemId,
@@ -4521,22 +4510,22 @@ doProlog(XML_Parser parser,
return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
if (dtd->paramEntityRead) {
if (!dtd->standalone &&
- notStandaloneHandler &&
- !notStandaloneHandler(handlerArg))
+ parser->m_notStandaloneHandler &&
+ !parser->m_notStandaloneHandler(parser->m_handlerArg))
return XML_ERROR_NOT_STANDALONE;
}
/* if we didn't read the foreign DTD then this means that there
is no external subset and we must reset dtd->hasParamEntityRefs
*/
- else if (!doctypeSysid)
+ else if (!parser->m_doctypeSysid)
dtd->hasParamEntityRefs = hadParamEntityRefs;
/* end of DTD - no need to update dtd->keepProcessing */
}
- useForeignDTD = XML_FALSE;
+ parser->m_useForeignDTD = XML_FALSE;
}
#endif /* XML_DTD */
- if (endDoctypeDeclHandler) {
- endDoctypeDeclHandler(handlerArg);
+ if (parser->m_endDoctypeDeclHandler) {
+ parser->m_endDoctypeDeclHandler(parser->m_handlerArg);
handleDefault = XML_FALSE;
}
break;
@@ -4545,18 +4534,18 @@ doProlog(XML_Parser parser,
/* if there is no DOCTYPE declaration then now is the
last chance to read the foreign DTD
*/
- if (useForeignDTD) {
+ if (parser->m_useForeignDTD) {
XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
dtd->hasParamEntityRefs = XML_TRUE;
- if (paramEntityParsing && externalEntityRefHandler) {
+ if (parser->m_paramEntityParsing && parser->m_externalEntityRefHandler) {
ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities,
externalSubsetName,
sizeof(ENTITY));
if (!entity)
return XML_ERROR_NO_MEMORY;
- entity->base = curBase;
+ entity->base = parser->m_curBase;
dtd->paramEntityRead = XML_FALSE;
- if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg,
0,
entity->base,
entity->systemId,
@@ -4564,8 +4553,8 @@ doProlog(XML_Parser parser,
return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
if (dtd->paramEntityRead) {
if (!dtd->standalone &&
- notStandaloneHandler &&
- !notStandaloneHandler(handlerArg))
+ parser->m_notStandaloneHandler &&
+ !parser->m_notStandaloneHandler(parser->m_handlerArg))
return XML_ERROR_NOT_STANDALONE;
}
/* if we didn't read the foreign DTD then this means that there
@@ -4577,55 +4566,55 @@ doProlog(XML_Parser parser,
}
}
#endif /* XML_DTD */
- processor = contentProcessor;
+ parser->m_processor = contentProcessor;
return contentProcessor(parser, s, end, nextPtr);
case XML_ROLE_ATTLIST_ELEMENT_NAME:
- declElementType = getElementType(parser, enc, s, next);
- if (!declElementType)
+ parser->m_declElementType = getElementType(parser, enc, s, next);
+ if (!parser->m_declElementType)
return XML_ERROR_NO_MEMORY;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_NAME:
- declAttributeId = getAttributeId(parser, enc, s, next);
- if (!declAttributeId)
+ parser->m_declAttributeId = getAttributeId(parser, enc, s, next);
+ if (!parser->m_declAttributeId)
return XML_ERROR_NO_MEMORY;
- declAttributeIsCdata = XML_FALSE;
- declAttributeType = NULL;
- declAttributeIsId = XML_FALSE;
+ parser->m_declAttributeIsCdata = XML_FALSE;
+ parser->m_declAttributeType = NULL;
+ parser->m_declAttributeIsId = XML_FALSE;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_CDATA:
- declAttributeIsCdata = XML_TRUE;
- declAttributeType = atypeCDATA;
+ parser->m_declAttributeIsCdata = XML_TRUE;
+ parser->m_declAttributeType = atypeCDATA;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_ID:
- declAttributeIsId = XML_TRUE;
- declAttributeType = atypeID;
+ parser->m_declAttributeIsId = XML_TRUE;
+ parser->m_declAttributeType = atypeID;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_IDREF:
- declAttributeType = atypeIDREF;
+ parser->m_declAttributeType = atypeIDREF;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_IDREFS:
- declAttributeType = atypeIDREFS;
+ parser->m_declAttributeType = atypeIDREFS;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_ENTITY:
- declAttributeType = atypeENTITY;
+ parser->m_declAttributeType = atypeENTITY;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES:
- declAttributeType = atypeENTITIES;
+ parser->m_declAttributeType = atypeENTITIES;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN:
- declAttributeType = atypeNMTOKEN;
+ parser->m_declAttributeType = atypeNMTOKEN;
goto checkAttListDeclHandler;
case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS:
- declAttributeType = atypeNMTOKENS;
+ parser->m_declAttributeType = atypeNMTOKENS;
checkAttListDeclHandler:
- if (dtd->keepProcessing && attlistDeclHandler)
+ if (dtd->keepProcessing && parser->m_attlistDeclHandler)
handleDefault = XML_FALSE;
break;
case XML_ROLE_ATTRIBUTE_ENUM_VALUE:
case XML_ROLE_ATTRIBUTE_NOTATION_VALUE:
- if (dtd->keepProcessing && attlistDeclHandler) {
+ if (dtd->keepProcessing && parser->m_attlistDeclHandler) {
const XML_Char *prefix;
- if (declAttributeType) {
+ if (parser->m_declAttributeType) {
prefix = enumValueSep;
}
else {
@@ -4633,37 +4622,37 @@ doProlog(XML_Parser parser,
? notationPrefix
: enumValueStart);
}
- if (!poolAppendString(&tempPool, prefix))
+ if (!poolAppendString(&parser->m_tempPool, prefix))
return XML_ERROR_NO_MEMORY;
- if (!poolAppend(&tempPool, enc, s, next))
+ if (!poolAppend(&parser->m_tempPool, enc, s, next))
return XML_ERROR_NO_MEMORY;
- declAttributeType = tempPool.start;
+ parser->m_declAttributeType = parser->m_tempPool.start;
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE:
case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE:
if (dtd->keepProcessing) {
- if (!defineAttribute(declElementType, declAttributeId,
- declAttributeIsCdata, declAttributeIsId,
+ if (!defineAttribute(parser->m_declElementType, parser->m_declAttributeId,
+ parser->m_declAttributeIsCdata, parser->m_declAttributeIsId,
0, parser))
return XML_ERROR_NO_MEMORY;
- if (attlistDeclHandler && declAttributeType) {
- if (*declAttributeType == XML_T(ASCII_LPAREN)
- || (*declAttributeType == XML_T(ASCII_N)
- && declAttributeType[1] == XML_T(ASCII_O))) {
+ if (parser->m_attlistDeclHandler && parser->m_declAttributeType) {
+ if (*parser->m_declAttributeType == XML_T(ASCII_LPAREN)
+ || (*parser->m_declAttributeType == XML_T(ASCII_N)
+ && parser->m_declAttributeType[1] == XML_T(ASCII_O))) {
/* Enumerated or Notation type */
- if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN))
- || !poolAppendChar(&tempPool, XML_T('\0')))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_RPAREN))
+ || !poolAppendChar(&parser->m_tempPool, XML_T('\0')))
return XML_ERROR_NO_MEMORY;
- declAttributeType = tempPool.start;
- poolFinish(&tempPool);
+ parser->m_declAttributeType = parser->m_tempPool.start;
+ poolFinish(&parser->m_tempPool);
}
*eventEndPP = s;
- attlistDeclHandler(handlerArg, declElementType->name,
- declAttributeId->name, declAttributeType,
+ parser->m_attlistDeclHandler(parser->m_handlerArg, parser->m_declElementType->name,
+ parser->m_declAttributeId->name, parser->m_declAttributeType,
0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE);
- poolClear(&tempPool);
+ poolClear(&parser->m_tempPool);
handleDefault = XML_FALSE;
}
}
@@ -4673,7 +4662,7 @@ doProlog(XML_Parser parser,
if (dtd->keepProcessing) {
const XML_Char *attVal;
enum XML_Error result =
- storeAttributeValue(parser, enc, declAttributeIsCdata,
+ storeAttributeValue(parser, enc, parser->m_declAttributeIsCdata,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar,
&dtd->pool);
@@ -4682,26 +4671,26 @@ doProlog(XML_Parser parser,
attVal = poolStart(&dtd->pool);
poolFinish(&dtd->pool);
/* ID attributes aren't allowed to have a default */
- if (!defineAttribute(declElementType, declAttributeId,
- declAttributeIsCdata, XML_FALSE, attVal, parser))
+ if (!defineAttribute(parser->m_declElementType, parser->m_declAttributeId,
+ parser->m_declAttributeIsCdata, XML_FALSE, attVal, parser))
return XML_ERROR_NO_MEMORY;
- if (attlistDeclHandler && declAttributeType) {
- if (*declAttributeType == XML_T(ASCII_LPAREN)
- || (*declAttributeType == XML_T(ASCII_N)
- && declAttributeType[1] == XML_T(ASCII_O))) {
+ if (parser->m_attlistDeclHandler && parser->m_declAttributeType) {
+ if (*parser->m_declAttributeType == XML_T(ASCII_LPAREN)
+ || (*parser->m_declAttributeType == XML_T(ASCII_N)
+ && parser->m_declAttributeType[1] == XML_T(ASCII_O))) {
/* Enumerated or Notation type */
- if (!poolAppendChar(&tempPool, XML_T(ASCII_RPAREN))
- || !poolAppendChar(&tempPool, XML_T('\0')))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_RPAREN))
+ || !poolAppendChar(&parser->m_tempPool, XML_T('\0')))
return XML_ERROR_NO_MEMORY;
- declAttributeType = tempPool.start;
- poolFinish(&tempPool);
+ parser->m_declAttributeType = parser->m_tempPool.start;
+ poolFinish(&parser->m_tempPool);
}
*eventEndPP = s;
- attlistDeclHandler(handlerArg, declElementType->name,
- declAttributeId->name, declAttributeType,
+ parser->m_attlistDeclHandler(parser->m_handlerArg, parser->m_declElementType->name,
+ parser->m_declAttributeId->name, parser->m_declAttributeType,
attVal,
role == XML_ROLE_FIXED_ATTRIBUTE_VALUE);
- poolClear(&tempPool);
+ poolClear(&parser->m_tempPool);
handleDefault = XML_FALSE;
}
}
@@ -4711,18 +4700,18 @@ doProlog(XML_Parser parser,
enum XML_Error result = storeEntityValue(parser, enc,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar);
- if (declEntity) {
- declEntity->textPtr = poolStart(&dtd->entityValuePool);
- declEntity->textLen = (int)(poolLength(&dtd->entityValuePool));
+ if (parser->m_declEntity) {
+ parser->m_declEntity->textPtr = poolStart(&dtd->entityValuePool);
+ parser->m_declEntity->textLen = (int)(poolLength(&dtd->entityValuePool));
poolFinish(&dtd->entityValuePool);
- if (entityDeclHandler) {
+ if (parser->m_entityDeclHandler) {
*eventEndPP = s;
- entityDeclHandler(handlerArg,
- declEntity->name,
- declEntity->is_param,
- declEntity->textPtr,
- declEntity->textLen,
- curBase, 0, 0, 0);
+ parser->m_entityDeclHandler(parser->m_handlerArg,
+ parser->m_declEntity->name,
+ parser->m_declEntity->is_param,
+ parser->m_declEntity->textPtr,
+ parser->m_declEntity->textLen,
+ parser->m_curBase, 0, 0, 0);
handleDefault = XML_FALSE;
}
}
@@ -4734,97 +4723,100 @@ doProlog(XML_Parser parser,
break;
case XML_ROLE_DOCTYPE_SYSTEM_ID:
#ifdef XML_DTD
- useForeignDTD = XML_FALSE;
+ parser->m_useForeignDTD = XML_FALSE;
#endif /* XML_DTD */
dtd->hasParamEntityRefs = XML_TRUE;
- if (startDoctypeDeclHandler) {
- doctypeSysid = poolStoreString(&tempPool, enc,
+ if (parser->m_startDoctypeDeclHandler) {
+ parser->m_doctypeSysid = poolStoreString(&parser->m_tempPool, enc,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar);
- if (doctypeSysid == NULL)
+ if (parser->m_doctypeSysid == NULL)
return XML_ERROR_NO_MEMORY;
- poolFinish(&tempPool);
+ poolFinish(&parser->m_tempPool);
handleDefault = XML_FALSE;
}
#ifdef XML_DTD
else
- /* use externalSubsetName to make doctypeSysid non-NULL
- for the case where no startDoctypeDeclHandler is set */
- doctypeSysid = externalSubsetName;
+ /* use externalSubsetName to make parser->m_doctypeSysid non-NULL
+ for the case where no parser->m_startDoctypeDeclHandler is set */
+ parser->m_doctypeSysid = externalSubsetName;
#endif /* XML_DTD */
if (!dtd->standalone
#ifdef XML_DTD
- && !paramEntityParsing
+ && !parser->m_paramEntityParsing
#endif /* XML_DTD */
- && notStandaloneHandler
- && !notStandaloneHandler(handlerArg))
+ && parser->m_notStandaloneHandler
+ && !parser->m_notStandaloneHandler(parser->m_handlerArg))
return XML_ERROR_NOT_STANDALONE;
#ifndef XML_DTD
break;
#else /* XML_DTD */
- if (!declEntity) {
- declEntity = (ENTITY *)lookup(parser,
+ if (!parser->m_declEntity) {
+ parser->m_declEntity = (ENTITY *)lookup(parser,
&dtd->paramEntities,
externalSubsetName,
sizeof(ENTITY));
- if (!declEntity)
+ if (!parser->m_declEntity)
return XML_ERROR_NO_MEMORY;
- declEntity->publicId = NULL;
+ parser->m_declEntity->publicId = NULL;
}
- /* fall through */
#endif /* XML_DTD */
+ /* fall through */
case XML_ROLE_ENTITY_SYSTEM_ID:
- if (dtd->keepProcessing && declEntity) {
- declEntity->systemId = poolStoreString(&dtd->pool, enc,
+ if (dtd->keepProcessing && parser->m_declEntity) {
+ parser->m_declEntity->systemId = poolStoreString(&dtd->pool, enc,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar);
- if (!declEntity->systemId)
+ if (!parser->m_declEntity->systemId)
return XML_ERROR_NO_MEMORY;
- declEntity->base = curBase;
+ parser->m_declEntity->base = parser->m_curBase;
poolFinish(&dtd->pool);
- if (entityDeclHandler)
+ /* Don't suppress the default handler if we fell through from
+ * the XML_ROLE_DOCTYPE_SYSTEM_ID case.
+ */
+ if (parser->m_entityDeclHandler && role == XML_ROLE_ENTITY_SYSTEM_ID)
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_ENTITY_COMPLETE:
- if (dtd->keepProcessing && declEntity && entityDeclHandler) {
+ if (dtd->keepProcessing && parser->m_declEntity && parser->m_entityDeclHandler) {
*eventEndPP = s;
- entityDeclHandler(handlerArg,
- declEntity->name,
- declEntity->is_param,
+ parser->m_entityDeclHandler(parser->m_handlerArg,
+ parser->m_declEntity->name,
+ parser->m_declEntity->is_param,
0,0,
- declEntity->base,
- declEntity->systemId,
- declEntity->publicId,
+ parser->m_declEntity->base,
+ parser->m_declEntity->systemId,
+ parser->m_declEntity->publicId,
0);
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_ENTITY_NOTATION_NAME:
- if (dtd->keepProcessing && declEntity) {
- declEntity->notation = poolStoreString(&dtd->pool, enc, s, next);
- if (!declEntity->notation)
+ if (dtd->keepProcessing && parser->m_declEntity) {
+ parser->m_declEntity->notation = poolStoreString(&dtd->pool, enc, s, next);
+ if (!parser->m_declEntity->notation)
return XML_ERROR_NO_MEMORY;
poolFinish(&dtd->pool);
- if (unparsedEntityDeclHandler) {
+ if (parser->m_unparsedEntityDeclHandler) {
*eventEndPP = s;
- unparsedEntityDeclHandler(handlerArg,
- declEntity->name,
- declEntity->base,
- declEntity->systemId,
- declEntity->publicId,
- declEntity->notation);
+ parser->m_unparsedEntityDeclHandler(parser->m_handlerArg,
+ parser->m_declEntity->name,
+ parser->m_declEntity->base,
+ parser->m_declEntity->systemId,
+ parser->m_declEntity->publicId,
+ parser->m_declEntity->notation);
handleDefault = XML_FALSE;
}
- else if (entityDeclHandler) {
+ else if (parser->m_entityDeclHandler) {
*eventEndPP = s;
- entityDeclHandler(handlerArg,
- declEntity->name,
+ parser->m_entityDeclHandler(parser->m_handlerArg,
+ parser->m_declEntity->name,
0,0,0,
- declEntity->base,
- declEntity->systemId,
- declEntity->publicId,
- declEntity->notation);
+ parser->m_declEntity->base,
+ parser->m_declEntity->systemId,
+ parser->m_declEntity->publicId,
+ parser->m_declEntity->notation);
handleDefault = XML_FALSE;
}
}
@@ -4832,36 +4824,36 @@ doProlog(XML_Parser parser,
case XML_ROLE_GENERAL_ENTITY_NAME:
{
if (XmlPredefinedEntityName(enc, s, next)) {
- declEntity = NULL;
+ parser->m_declEntity = NULL;
break;
}
if (dtd->keepProcessing) {
const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
if (!name)
return XML_ERROR_NO_MEMORY;
- declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name,
+ parser->m_declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name,
sizeof(ENTITY));
- if (!declEntity)
+ if (!parser->m_declEntity)
return XML_ERROR_NO_MEMORY;
- if (declEntity->name != name) {
+ if (parser->m_declEntity->name != name) {
poolDiscard(&dtd->pool);
- declEntity = NULL;
+ parser->m_declEntity = NULL;
}
else {
poolFinish(&dtd->pool);
- declEntity->publicId = NULL;
- declEntity->is_param = XML_FALSE;
+ parser->m_declEntity->publicId = NULL;
+ parser->m_declEntity->is_param = XML_FALSE;
/* if we have a parent parser or are reading an internal parameter
entity, then the entity declaration is not considered "internal"
*/
- declEntity->is_internal = !(parentParser || openInternalEntities);
- if (entityDeclHandler)
+ parser->m_declEntity->is_internal = !(parser->m_parentParser || parser->m_openInternalEntities);
+ if (parser->m_entityDeclHandler)
handleDefault = XML_FALSE;
}
}
else {
poolDiscard(&dtd->pool);
- declEntity = NULL;
+ parser->m_declEntity = NULL;
}
}
break;
@@ -4871,90 +4863,90 @@ doProlog(XML_Parser parser,
const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
if (!name)
return XML_ERROR_NO_MEMORY;
- declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities,
+ parser->m_declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities,
name, sizeof(ENTITY));
- if (!declEntity)
+ if (!parser->m_declEntity)
return XML_ERROR_NO_MEMORY;
- if (declEntity->name != name) {
+ if (parser->m_declEntity->name != name) {
poolDiscard(&dtd->pool);
- declEntity = NULL;
+ parser->m_declEntity = NULL;
}
else {
poolFinish(&dtd->pool);
- declEntity->publicId = NULL;
- declEntity->is_param = XML_TRUE;
+ parser->m_declEntity->publicId = NULL;
+ parser->m_declEntity->is_param = XML_TRUE;
/* if we have a parent parser or are reading an internal parameter
entity, then the entity declaration is not considered "internal"
*/
- declEntity->is_internal = !(parentParser || openInternalEntities);
- if (entityDeclHandler)
+ parser->m_declEntity->is_internal = !(parser->m_parentParser || parser->m_openInternalEntities);
+ if (parser->m_entityDeclHandler)
handleDefault = XML_FALSE;
}
}
else {
poolDiscard(&dtd->pool);
- declEntity = NULL;
+ parser->m_declEntity = NULL;
}
#else /* not XML_DTD */
- declEntity = NULL;
+ parser->m_declEntity = NULL;
#endif /* XML_DTD */
break;
case XML_ROLE_NOTATION_NAME:
- declNotationPublicId = NULL;
- declNotationName = NULL;
- if (notationDeclHandler) {
- declNotationName = poolStoreString(&tempPool, enc, s, next);
- if (!declNotationName)
+ parser->m_declNotationPublicId = NULL;
+ parser->m_declNotationName = NULL;
+ if (parser->m_notationDeclHandler) {
+ parser->m_declNotationName = poolStoreString(&parser->m_tempPool, enc, s, next);
+ if (!parser->m_declNotationName)
return XML_ERROR_NO_MEMORY;
- poolFinish(&tempPool);
+ poolFinish(&parser->m_tempPool);
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_NOTATION_PUBLIC_ID:
if (!XmlIsPublicId(enc, s, next, eventPP))
return XML_ERROR_PUBLICID;
- if (declNotationName) { /* means notationDeclHandler != NULL */
- XML_Char *tem = poolStoreString(&tempPool,
+ if (parser->m_declNotationName) { /* means m_notationDeclHandler != NULL */
+ XML_Char *tem = poolStoreString(&parser->m_tempPool,
enc,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar);
if (!tem)
return XML_ERROR_NO_MEMORY;
normalizePublicId(tem);
- declNotationPublicId = tem;
- poolFinish(&tempPool);
+ parser->m_declNotationPublicId = tem;
+ poolFinish(&parser->m_tempPool);
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_NOTATION_SYSTEM_ID:
- if (declNotationName && notationDeclHandler) {
+ if (parser->m_declNotationName && parser->m_notationDeclHandler) {
const XML_Char *systemId
- = poolStoreString(&tempPool, enc,
+ = poolStoreString(&parser->m_tempPool, enc,
s + enc->minBytesPerChar,
next - enc->minBytesPerChar);
if (!systemId)
return XML_ERROR_NO_MEMORY;
*eventEndPP = s;
- notationDeclHandler(handlerArg,
- declNotationName,
- curBase,
+ parser->m_notationDeclHandler(parser->m_handlerArg,
+ parser->m_declNotationName,
+ parser->m_curBase,
systemId,
- declNotationPublicId);
+ parser->m_declNotationPublicId);
handleDefault = XML_FALSE;
}
- poolClear(&tempPool);
+ poolClear(&parser->m_tempPool);
break;
case XML_ROLE_NOTATION_NO_SYSTEM_ID:
- if (declNotationPublicId && notationDeclHandler) {
+ if (parser->m_declNotationPublicId && parser->m_notationDeclHandler) {
*eventEndPP = s;
- notationDeclHandler(handlerArg,
- declNotationName,
- curBase,
+ parser->m_notationDeclHandler(parser->m_handlerArg,
+ parser->m_declNotationName,
+ parser->m_curBase,
0,
- declNotationPublicId);
+ parser->m_declNotationPublicId);
handleDefault = XML_FALSE;
}
- poolClear(&tempPool);
+ poolClear(&parser->m_tempPool);
break;
case XML_ROLE_ERROR:
switch (tok) {
@@ -4971,45 +4963,45 @@ doProlog(XML_Parser parser,
case XML_ROLE_IGNORE_SECT:
{
enum XML_Error result;
- if (defaultHandler)
+ if (parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
handleDefault = XML_FALSE;
result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore);
if (result != XML_ERROR_NONE)
return result;
else if (!next) {
- processor = ignoreSectionProcessor;
+ parser->m_processor = ignoreSectionProcessor;
return result;
}
}
break;
#endif /* XML_DTD */
case XML_ROLE_GROUP_OPEN:
- if (prologState.level >= groupSize) {
- if (groupSize) {
- char *temp = (char *)REALLOC(groupConnector, groupSize *= 2);
+ if (parser->m_prologState.level >= parser->m_groupSize) {
+ if (parser->m_groupSize) {
+ char *temp = (char *)REALLOC(parser, parser->m_groupConnector, parser->m_groupSize *= 2);
if (temp == NULL) {
- groupSize /= 2;
+ parser->m_groupSize /= 2;
return XML_ERROR_NO_MEMORY;
}
- groupConnector = temp;
+ parser->m_groupConnector = temp;
if (dtd->scaffIndex) {
- int *temp = (int *)REALLOC(dtd->scaffIndex,
- groupSize * sizeof(int));
+ int *temp = (int *)REALLOC(parser, dtd->scaffIndex,
+ parser->m_groupSize * sizeof(int));
if (temp == NULL)
return XML_ERROR_NO_MEMORY;
dtd->scaffIndex = temp;
}
}
else {
- groupConnector = (char *)MALLOC(groupSize = 32);
- if (!groupConnector) {
- groupSize = 0;
+ parser->m_groupConnector = (char *)MALLOC(parser, parser->m_groupSize = 32);
+ if (!parser->m_groupConnector) {
+ parser->m_groupSize = 0;
return XML_ERROR_NO_MEMORY;
}
}
}
- groupConnector[prologState.level] = 0;
+ parser->m_groupConnector[parser->m_prologState.level] = 0;
if (dtd->in_eldecl) {
int myindex = nextScaffoldPart(parser);
if (myindex < 0)
@@ -5017,37 +5009,37 @@ doProlog(XML_Parser parser,
dtd->scaffIndex[dtd->scaffLevel] = myindex;
dtd->scaffLevel++;
dtd->scaffold[myindex].type = XML_CTYPE_SEQ;
- if (elementDeclHandler)
+ if (parser->m_elementDeclHandler)
handleDefault = XML_FALSE;
}
break;
case XML_ROLE_GROUP_SEQUENCE:
- if (groupConnector[prologState.level] == ASCII_PIPE)
+ if (parser->m_groupConnector[parser->m_prologState.level] == ASCII_PIPE)
return XML_ERROR_SYNTAX;
- groupConnector[prologState.level] = ASCII_COMMA;
- if (dtd->in_eldecl && elementDeclHandler)
+ parser->m_groupConnector[parser->m_prologState.level] = ASCII_COMMA;
+ if (dtd->in_eldecl && parser->m_elementDeclHandler)
handleDefault = XML_FALSE;
break;
case XML_ROLE_GROUP_CHOICE:
- if (groupConnector[prologState.level] == ASCII_COMMA)
+ if (parser->m_groupConnector[parser->m_prologState.level] == ASCII_COMMA)
return XML_ERROR_SYNTAX;
if (dtd->in_eldecl
- && !groupConnector[prologState.level]
+ && !parser->m_groupConnector[parser->m_prologState.level]
&& (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type
!= XML_CTYPE_MIXED)
) {
dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type
= XML_CTYPE_CHOICE;
- if (elementDeclHandler)
+ if (parser->m_elementDeclHandler)
handleDefault = XML_FALSE;
}
- groupConnector[prologState.level] = ASCII_PIPE;
+ parser->m_groupConnector[parser->m_prologState.level] = ASCII_PIPE;
break;
case XML_ROLE_PARAM_ENTITY_REF:
#ifdef XML_DTD
case XML_ROLE_INNER_PARAM_ENTITY_REF:
dtd->hasParamEntityRefs = XML_TRUE;
- if (!paramEntityParsing)
+ if (!parser->m_paramEntityParsing)
dtd->keepProcessing = dtd->standalone;
else {
const XML_Char *name;
@@ -5063,9 +5055,9 @@ doProlog(XML_Parser parser,
if yes, check that the entity exists, and that it is internal,
otherwise call the skipped entity handler
*/
- if (prologState.documentEntity &&
+ if (parser->m_prologState.documentEntity &&
(dtd->standalone
- ? !openInternalEntities
+ ? !parser->m_openInternalEntities
: !dtd->hasParamEntityRefs)) {
if (!entity)
return XML_ERROR_UNDEFINED_ENTITY;
@@ -5096,8 +5088,8 @@ doProlog(XML_Parser parser,
else if (!entity) {
dtd->keepProcessing = dtd->standalone;
/* cannot report skipped entities in declarations */
- if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) {
- skippedEntityHandler(handlerArg, name, 1);
+ if ((role == XML_ROLE_PARAM_ENTITY_REF) && parser->m_skippedEntityHandler) {
+ parser->m_skippedEntityHandler(parser->m_handlerArg, name, 1);
handleDefault = XML_FALSE;
}
break;
@@ -5114,10 +5106,10 @@ doProlog(XML_Parser parser,
handleDefault = XML_FALSE;
break;
}
- if (externalEntityRefHandler) {
+ if (parser->m_externalEntityRefHandler) {
dtd->paramEntityRead = XML_FALSE;
entity->open = XML_TRUE;
- if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg,
0,
entity->base,
entity->systemId,
@@ -5139,17 +5131,17 @@ doProlog(XML_Parser parser,
}
#endif /* XML_DTD */
if (!dtd->standalone &&
- notStandaloneHandler &&
- !notStandaloneHandler(handlerArg))
+ parser->m_notStandaloneHandler &&
+ !parser->m_notStandaloneHandler(parser->m_handlerArg))
return XML_ERROR_NOT_STANDALONE;
break;
/* Element declaration stuff */
case XML_ROLE_ELEMENT_NAME:
- if (elementDeclHandler) {
- declElementType = getElementType(parser, enc, s, next);
- if (!declElementType)
+ if (parser->m_elementDeclHandler) {
+ parser->m_declElementType = getElementType(parser, enc, s, next);
+ if (!parser->m_declElementType)
return XML_ERROR_NO_MEMORY;
dtd->scaffLevel = 0;
dtd->scaffCount = 0;
@@ -5161,8 +5153,8 @@ doProlog(XML_Parser parser,
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 (parser->m_elementDeclHandler) {
+ XML_Content * content = (XML_Content *) MALLOC(parser, sizeof(XML_Content));
if (!content)
return XML_ERROR_NO_MEMORY;
content->quant = XML_CQUANT_NONE;
@@ -5173,7 +5165,7 @@ doProlog(XML_Parser parser,
XML_CTYPE_ANY :
XML_CTYPE_EMPTY);
*eventEndPP = s;
- elementDeclHandler(handlerArg, declElementType->name, content);
+ parser->m_elementDeclHandler(parser->m_handlerArg, parser->m_declElementType->name, content);
handleDefault = XML_FALSE;
}
dtd->in_eldecl = XML_FALSE;
@@ -5184,7 +5176,7 @@ doProlog(XML_Parser parser,
if (dtd->in_eldecl) {
dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type
= XML_CTYPE_MIXED;
- if (elementDeclHandler)
+ if (parser->m_elementDeclHandler)
handleDefault = XML_FALSE;
}
break;
@@ -5221,7 +5213,7 @@ doProlog(XML_Parser parser,
nameLen = 0;
for (; name[nameLen++]; );
dtd->contentStringLen += nameLen;
- if (elementDeclHandler)
+ if (parser->m_elementDeclHandler)
handleDefault = XML_FALSE;
}
break;
@@ -5239,7 +5231,7 @@ doProlog(XML_Parser parser,
quant = XML_CQUANT_PLUS;
closeGroup:
if (dtd->in_eldecl) {
- if (elementDeclHandler)
+ if (parser->m_elementDeclHandler)
handleDefault = XML_FALSE;
dtd->scaffLevel--;
dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant;
@@ -5249,7 +5241,7 @@ doProlog(XML_Parser parser,
if (!model)
return XML_ERROR_NO_MEMORY;
*eventEndPP = s;
- elementDeclHandler(handlerArg, declElementType->name, model);
+ parser->m_elementDeclHandler(parser->m_handlerArg, parser->m_declElementType->name, model);
}
dtd->in_eldecl = XML_FALSE;
dtd->contentStringLen = 0;
@@ -5276,31 +5268,31 @@ doProlog(XML_Parser parser,
}
break;
case XML_ROLE_DOCTYPE_NONE:
- if (startDoctypeDeclHandler)
+ if (parser->m_startDoctypeDeclHandler)
handleDefault = XML_FALSE;
break;
case XML_ROLE_ENTITY_NONE:
- if (dtd->keepProcessing && entityDeclHandler)
+ if (dtd->keepProcessing && parser->m_entityDeclHandler)
handleDefault = XML_FALSE;
break;
case XML_ROLE_NOTATION_NONE:
- if (notationDeclHandler)
+ if (parser->m_notationDeclHandler)
handleDefault = XML_FALSE;
break;
case XML_ROLE_ATTLIST_NONE:
- if (dtd->keepProcessing && attlistDeclHandler)
+ if (dtd->keepProcessing && parser->m_attlistDeclHandler)
handleDefault = XML_FALSE;
break;
case XML_ROLE_ELEMENT_NONE:
- if (elementDeclHandler)
+ if (parser->m_elementDeclHandler)
handleDefault = XML_FALSE;
break;
} /* end of big switch */
- if (handleDefault && defaultHandler)
+ if (handleDefault && parser->m_defaultHandler)
reportDefault(parser, enc, s, next);
- switch (ps_parsing) {
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -5320,18 +5312,18 @@ epilogProcessor(XML_Parser parser,
const char *end,
const char **nextPtr)
{
- processor = epilogProcessor;
- eventPtr = s;
+ parser->m_processor = epilogProcessor;
+ parser->m_eventPtr = s;
for (;;) {
const char *next = NULL;
- int tok = XmlPrologTok(encoding, s, end, &next);
- eventEndPtr = next;
+ int tok = XmlPrologTok(parser->m_encoding, s, end, &next);
+ parser->m_eventEndPtr = next;
switch (tok) {
/* report partial linebreak - it might be the last token */
case -XML_TOK_PROLOG_S:
- if (defaultHandler) {
- reportDefault(parser, encoding, s, next);
- if (ps_parsing == XML_FINISHED)
+ if (parser->m_defaultHandler) {
+ reportDefault(parser, parser->m_encoding, s, next);
+ if (parser->m_parsingStatus.parsing == XML_FINISHED)
return XML_ERROR_ABORTED;
}
*nextPtr = next;
@@ -5340,28 +5332,28 @@ epilogProcessor(XML_Parser parser,
*nextPtr = s;
return XML_ERROR_NONE;
case XML_TOK_PROLOG_S:
- if (defaultHandler)
- reportDefault(parser, encoding, s, next);
+ if (parser->m_defaultHandler)
+ reportDefault(parser, parser->m_encoding, s, next);
break;
case XML_TOK_PI:
- if (!reportProcessingInstruction(parser, encoding, s, next))
+ if (!reportProcessingInstruction(parser, parser->m_encoding, s, next))
return XML_ERROR_NO_MEMORY;
break;
case XML_TOK_COMMENT:
- if (!reportComment(parser, encoding, s, next))
+ if (!reportComment(parser, parser->m_encoding, s, next))
return XML_ERROR_NO_MEMORY;
break;
case XML_TOK_INVALID:
- eventPtr = next;
+ parser->m_eventPtr = next;
return XML_ERROR_INVALID_TOKEN;
case XML_TOK_PARTIAL:
- if (!ps_finalBuffer) {
+ if (!parser->m_parsingStatus.finalBuffer) {
*nextPtr = s;
return XML_ERROR_NONE;
}
return XML_ERROR_UNCLOSED_TOKEN;
case XML_TOK_PARTIAL_CHAR:
- if (!ps_finalBuffer) {
+ if (!parser->m_parsingStatus.finalBuffer) {
*nextPtr = s;
return XML_ERROR_NONE;
}
@@ -5369,8 +5361,8 @@ epilogProcessor(XML_Parser parser,
default:
return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;
}
- eventPtr = s = next;
- switch (ps_parsing) {
+ parser->m_eventPtr = s = next;
+ switch (parser->m_parsingStatus.parsing) {
case XML_SUSPENDED:
*nextPtr = next;
return XML_ERROR_NONE;
@@ -5390,21 +5382,21 @@ processInternalEntity(XML_Parser parser, ENTITY *entity,
enum XML_Error result;
OPEN_INTERNAL_ENTITY *openEntity;
- if (freeInternalEntities) {
- openEntity = freeInternalEntities;
- freeInternalEntities = openEntity->next;
+ if (parser->m_freeInternalEntities) {
+ openEntity = parser->m_freeInternalEntities;
+ parser->m_freeInternalEntities = openEntity->next;
}
else {
- openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY));
+ openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(parser, sizeof(OPEN_INTERNAL_ENTITY));
if (!openEntity)
return XML_ERROR_NO_MEMORY;
}
entity->open = XML_TRUE;
entity->processed = 0;
- openEntity->next = openInternalEntities;
- openInternalEntities = openEntity;
+ openEntity->next = parser->m_openInternalEntities;
+ parser->m_openInternalEntities = openEntity;
openEntity->entity = entity;
- openEntity->startTagLevel = tagLevel;
+ openEntity->startTagLevel = parser->m_tagLevel;
openEntity->betweenDecl = betweenDecl;
openEntity->internalEventPtr = NULL;
openEntity->internalEventEndPtr = NULL;
@@ -5415,26 +5407,26 @@ processInternalEntity(XML_Parser parser, ENTITY *entity,
#ifdef XML_DTD
if (entity->is_param) {
- int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
- result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
+ int tok = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next);
+ result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, tok,
next, &next, XML_FALSE);
}
else
#endif /* XML_DTD */
- result = doContent(parser, tagLevel, internalEncoding, textStart,
+ result = doContent(parser, parser->m_tagLevel, parser->m_internalEncoding, textStart,
textEnd, &next, XML_FALSE);
if (result == XML_ERROR_NONE) {
- if (textEnd != next && ps_parsing == XML_SUSPENDED) {
+ if (textEnd != next && parser->m_parsingStatus.parsing == XML_SUSPENDED) {
entity->processed = (int)(next - textStart);
- processor = internalEntityProcessor;
+ parser->m_processor = internalEntityProcessor;
}
else {
entity->open = XML_FALSE;
- openInternalEntities = openEntity->next;
+ parser->m_openInternalEntities = openEntity->next;
/* put openEntity back in list of free instances */
- openEntity->next = freeInternalEntities;
- freeInternalEntities = openEntity;
+ openEntity->next = parser->m_freeInternalEntities;
+ parser->m_freeInternalEntities = openEntity;
}
}
return result;
@@ -5450,7 +5442,7 @@ internalEntityProcessor(XML_Parser parser,
const char *textStart, *textEnd;
const char *next;
enum XML_Error result;
- OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities;
+ OPEN_INTERNAL_ENTITY *openEntity = parser->m_openInternalEntities;
if (!openEntity)
return XML_ERROR_UNEXPECTED_STATE;
@@ -5462,44 +5454,44 @@ internalEntityProcessor(XML_Parser parser,
#ifdef XML_DTD
if (entity->is_param) {
- int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next);
- result = doProlog(parser, internalEncoding, textStart, textEnd, tok,
+ int tok = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next);
+ result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, tok,
next, &next, XML_FALSE);
}
else
#endif /* XML_DTD */
- result = doContent(parser, openEntity->startTagLevel, internalEncoding,
+ result = doContent(parser, openEntity->startTagLevel, parser->m_internalEncoding,
textStart, textEnd, &next, XML_FALSE);
if (result != XML_ERROR_NONE)
return result;
- else if (textEnd != next && ps_parsing == XML_SUSPENDED) {
+ else if (textEnd != next && parser->m_parsingStatus.parsing == XML_SUSPENDED) {
entity->processed = (int)(next - (char *)entity->textPtr);
return result;
}
else {
entity->open = XML_FALSE;
- openInternalEntities = openEntity->next;
+ parser->m_openInternalEntities = openEntity->next;
/* put openEntity back in list of free instances */
- openEntity->next = freeInternalEntities;
- freeInternalEntities = openEntity;
+ openEntity->next = parser->m_freeInternalEntities;
+ parser->m_freeInternalEntities = openEntity;
}
#ifdef XML_DTD
if (entity->is_param) {
int tok;
- processor = prologProcessor;
- tok = XmlPrologTok(encoding, s, end, &next);
- return doProlog(parser, encoding, s, end, tok, next, nextPtr,
- (XML_Bool)!ps_finalBuffer);
+ parser->m_processor = prologProcessor;
+ tok = XmlPrologTok(parser->m_encoding, s, end, &next);
+ return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr,
+ (XML_Bool)!parser->m_parsingStatus.finalBuffer);
}
else
#endif /* XML_DTD */
{
- processor = contentProcessor;
+ parser->m_processor = contentProcessor;
/* see externalEntityContentProcessor vs contentProcessor */
- return doContent(parser, parentParser ? 1 : 0, encoding, s, end,
- nextPtr, (XML_Bool)!ps_finalBuffer);
+ return doContent(parser, parser->m_parentParser ? 1 : 0, parser->m_encoding, s, end,
+ nextPtr, (XML_Bool)!parser->m_parsingStatus.finalBuffer);
}
}
@@ -5509,7 +5501,7 @@ errorProcessor(XML_Parser parser,
const char *UNUSED_P(end),
const char **UNUSED_P(nextPtr))
{
- return errorCode;
+ return parser->m_errorCode;
}
static enum XML_Error
@@ -5533,7 +5525,7 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
const char *ptr, const char *end,
STRING_POOL *pool)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
for (;;) {
const char *next;
int tok = XmlAttributeValueTok(enc, ptr, end, &next);
@@ -5541,12 +5533,12 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
case XML_TOK_NONE:
return XML_ERROR_NONE;
case XML_TOK_INVALID:
- if (enc == encoding)
- eventPtr = next;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = next;
return XML_ERROR_INVALID_TOKEN;
case XML_TOK_PARTIAL:
- if (enc == encoding)
- eventPtr = ptr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = ptr;
return XML_ERROR_INVALID_TOKEN;
case XML_TOK_CHAR_REF:
{
@@ -5554,8 +5546,8 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
int i;
int n = XmlCharRefNumber(enc, ptr);
if (n < 0) {
- if (enc == encoding)
- eventPtr = ptr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = ptr;
return XML_ERROR_BAD_CHAR_REF;
}
if (!isCdata
@@ -5605,25 +5597,25 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
return XML_ERROR_NO_MEMORY;
break;
}
- name = poolStoreString(&temp2Pool, enc,
+ name = poolStoreString(&parser->m_temp2Pool, enc,
ptr + enc->minBytesPerChar,
next - enc->minBytesPerChar);
if (!name)
return XML_ERROR_NO_MEMORY;
entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0);
- poolDiscard(&temp2Pool);
+ poolDiscard(&parser->m_temp2Pool);
/* First, determine if a check for an existing declaration is needed;
if yes, check that the entity exists, and that it is internal.
*/
if (pool == &dtd->pool) /* are we called from prolog? */
checkEntityDecl =
#ifdef XML_DTD
- prologState.documentEntity &&
+ parser->m_prologState.documentEntity &&
#endif /* XML_DTD */
(dtd->standalone
- ? !openInternalEntities
+ ? !parser->m_openInternalEntities
: !dtd->hasParamEntityRefs);
- else /* if (pool == &tempPool): we are called from content */
+ else /* if (pool == &parser->m_tempPool): we are called from content */
checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone;
if (checkEntityDecl) {
if (!entity)
@@ -5633,19 +5625,19 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
}
else if (!entity) {
/* Cannot report skipped entity here - see comments on
- skippedEntityHandler.
- if (skippedEntityHandler)
- skippedEntityHandler(handlerArg, name, 0);
+ parser->m_skippedEntityHandler.
+ if (parser->m_skippedEntityHandler)
+ parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0);
*/
/* Cannot call the default handler because this would be
out of sync with the call to the startElementHandler.
- if ((pool == &tempPool) && defaultHandler)
+ if ((pool == &parser->m_tempPool) && parser->m_defaultHandler)
reportDefault(parser, enc, ptr, next);
*/
break;
}
if (entity->open) {
- if (enc == encoding) {
+ if (enc == parser->m_encoding) {
/* It does not appear that this line can be executed.
*
* The "if (entity->open)" check catches recursive entity
@@ -5663,25 +5655,25 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
* we keep the line and merely exclude it from coverage
* tests.
*/
- eventPtr = ptr; /* LCOV_EXCL_LINE */
+ parser->m_eventPtr = ptr; /* LCOV_EXCL_LINE */
}
return XML_ERROR_RECURSIVE_ENTITY_REF;
}
if (entity->notation) {
- if (enc == encoding)
- eventPtr = ptr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = ptr;
return XML_ERROR_BINARY_ENTITY_REF;
}
if (!entity->textPtr) {
- if (enc == encoding)
- eventPtr = ptr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = ptr;
return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;
}
else {
enum XML_Error result;
const XML_Char *textEnd = entity->textPtr + entity->textLen;
entity->open = XML_TRUE;
- result = appendAttributeValue(parser, internalEncoding, isCdata,
+ result = appendAttributeValue(parser, parser->m_internalEncoding, isCdata,
(char *)entity->textPtr,
(char *)textEnd, pool);
entity->open = XML_FALSE;
@@ -5702,8 +5694,8 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata,
*
* LCOV_EXCL_START
*/
- if (enc == encoding)
- eventPtr = ptr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = ptr;
return XML_ERROR_UNEXPECTED_STATE;
/* LCOV_EXCL_STOP */
}
@@ -5718,12 +5710,12 @@ storeEntityValue(XML_Parser parser,
const char *entityTextPtr,
const char *entityTextEnd)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
STRING_POOL *pool = &(dtd->entityValuePool);
enum XML_Error result = XML_ERROR_NONE;
#ifdef XML_DTD
- int oldInEntityValue = prologState.inEntityValue;
- prologState.inEntityValue = 1;
+ int oldInEntityValue = parser->m_prologState.inEntityValue;
+ parser->m_prologState.inEntityValue = 1;
#endif /* XML_DTD */
/* never return Null for the value argument in EntityDeclHandler,
since this would indicate an external entity; therefore we
@@ -5739,10 +5731,10 @@ storeEntityValue(XML_Parser parser,
switch (tok) {
case XML_TOK_PARAM_ENTITY_REF:
#ifdef XML_DTD
- if (isParamEntity || enc != encoding) {
+ if (parser->m_isParamEntity || enc != parser->m_encoding) {
const XML_Char *name;
ENTITY *entity;
- name = poolStoreString(&tempPool, enc,
+ name = poolStoreString(&parser->m_tempPool, enc,
entityTextPtr + enc->minBytesPerChar,
next - enc->minBytesPerChar);
if (!name) {
@@ -5750,28 +5742,28 @@ storeEntityValue(XML_Parser parser,
goto endEntityValue;
}
entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0);
- poolDiscard(&tempPool);
+ poolDiscard(&parser->m_tempPool);
if (!entity) {
/* not a well-formedness error - see XML 1.0: WFC Entity Declared */
/* cannot report skipped entity here - see comments on
- skippedEntityHandler
- if (skippedEntityHandler)
- skippedEntityHandler(handlerArg, name, 0);
+ parser->m_skippedEntityHandler
+ if (parser->m_skippedEntityHandler)
+ parser->m_skippedEntityHandler(parser->m_handlerArg, name, 0);
*/
dtd->keepProcessing = dtd->standalone;
goto endEntityValue;
}
if (entity->open) {
- if (enc == encoding)
- eventPtr = entityTextPtr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = entityTextPtr;
result = XML_ERROR_RECURSIVE_ENTITY_REF;
goto endEntityValue;
}
if (entity->systemId) {
- if (externalEntityRefHandler) {
+ if (parser->m_externalEntityRefHandler) {
dtd->paramEntityRead = XML_FALSE;
entity->open = XML_TRUE;
- if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+ if (!parser->m_externalEntityRefHandler(parser->m_externalEntityRefHandlerArg,
0,
entity->base,
entity->systemId,
@@ -5790,7 +5782,7 @@ storeEntityValue(XML_Parser parser,
else {
entity->open = XML_TRUE;
result = storeEntityValue(parser,
- internalEncoding,
+ parser->m_internalEncoding,
(char *)entity->textPtr,
(char *)(entity->textPtr
+ entity->textLen));
@@ -5803,7 +5795,7 @@ storeEntityValue(XML_Parser parser,
#endif /* XML_DTD */
/* In the internal subset, PE references are not legal
within markup declarations, e.g entity values in this case. */
- eventPtr = entityTextPtr;
+ parser->m_eventPtr = entityTextPtr;
result = XML_ERROR_PARAM_ENTITY_REF;
goto endEntityValue;
case XML_TOK_NONE:
@@ -5832,8 +5824,8 @@ storeEntityValue(XML_Parser parser,
int i;
int n = XmlCharRefNumber(enc, entityTextPtr);
if (n < 0) {
- if (enc == encoding)
- eventPtr = entityTextPtr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = entityTextPtr;
result = XML_ERROR_BAD_CHAR_REF;
goto endEntityValue;
}
@@ -5857,13 +5849,13 @@ storeEntityValue(XML_Parser parser,
}
break;
case XML_TOK_PARTIAL:
- if (enc == encoding)
- eventPtr = entityTextPtr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = entityTextPtr;
result = XML_ERROR_INVALID_TOKEN;
goto endEntityValue;
case XML_TOK_INVALID:
- if (enc == encoding)
- eventPtr = next;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = next;
result = XML_ERROR_INVALID_TOKEN;
goto endEntityValue;
default:
@@ -5874,8 +5866,8 @@ storeEntityValue(XML_Parser parser,
*
* LCOV_EXCL_START
*/
- if (enc == encoding)
- eventPtr = entityTextPtr;
+ if (enc == parser->m_encoding)
+ parser->m_eventPtr = entityTextPtr;
result = XML_ERROR_UNEXPECTED_STATE;
goto endEntityValue;
/* LCOV_EXCL_STOP */
@@ -5884,7 +5876,7 @@ storeEntityValue(XML_Parser parser,
}
endEntityValue:
#ifdef XML_DTD
- prologState.inEntityValue = oldInEntityValue;
+ parser->m_prologState.inEntityValue = oldInEntityValue;
#endif /* XML_DTD */
return result;
}
@@ -5919,25 +5911,25 @@ reportProcessingInstruction(XML_Parser parser, const ENCODING *enc,
const XML_Char *target;
XML_Char *data;
const char *tem;
- if (!processingInstructionHandler) {
- if (defaultHandler)
+ if (!parser->m_processingInstructionHandler) {
+ if (parser->m_defaultHandler)
reportDefault(parser, enc, start, end);
return 1;
}
start += enc->minBytesPerChar * 2;
tem = start + XmlNameLength(enc, start);
- target = poolStoreString(&tempPool, enc, start, tem);
+ target = poolStoreString(&parser->m_tempPool, enc, start, tem);
if (!target)
return 0;
- poolFinish(&tempPool);
- data = poolStoreString(&tempPool, enc,
+ poolFinish(&parser->m_tempPool);
+ data = poolStoreString(&parser->m_tempPool, enc,
XmlSkipS(enc, tem),
end - enc->minBytesPerChar*2);
if (!data)
return 0;
normalizeLines(data);
- processingInstructionHandler(handlerArg, target, data);
- poolClear(&tempPool);
+ parser->m_processingInstructionHandler(parser->m_handlerArg, target, data);
+ poolClear(&parser->m_tempPool);
return 1;
}
@@ -5946,20 +5938,20 @@ reportComment(XML_Parser parser, const ENCODING *enc,
const char *start, const char *end)
{
XML_Char *data;
- if (!commentHandler) {
- if (defaultHandler)
+ if (!parser->m_commentHandler) {
+ if (parser->m_defaultHandler)
reportDefault(parser, enc, start, end);
return 1;
}
- data = poolStoreString(&tempPool,
+ data = poolStoreString(&parser->m_tempPool,
enc,
start + enc->minBytesPerChar * 4,
end - enc->minBytesPerChar * 3);
if (!data)
return 0;
normalizeLines(data);
- commentHandler(handlerArg, data);
- poolClear(&tempPool);
+ parser->m_commentHandler(parser->m_handlerArg, data);
+ poolClear(&parser->m_tempPool);
return 1;
}
@@ -5971,9 +5963,9 @@ reportDefault(XML_Parser parser, const ENCODING *enc,
enum XML_Convert_Result convert_res;
const char **eventPP;
const char **eventEndPP;
- if (enc == encoding) {
- eventPP = &eventPtr;
- eventEndPP = &eventEndPtr;
+ if (enc == parser->m_encoding) {
+ eventPP = &parser->m_eventPtr;
+ eventEndPP = &parser->m_eventEndPtr;
}
else {
/* To get here, two things must be true; the parser must be
@@ -5992,20 +5984,20 @@ reportDefault(XML_Parser parser, const ENCODING *enc,
*
* LCOV_EXCL_START
*/
- eventPP = &(openInternalEntities->internalEventPtr);
- eventEndPP = &(openInternalEntities->internalEventEndPtr);
+ eventPP = &(parser->m_openInternalEntities->internalEventPtr);
+ eventEndPP = &(parser->m_openInternalEntities->internalEventEndPtr);
/* LCOV_EXCL_STOP */
}
do {
- ICHAR *dataPtr = (ICHAR *)dataBuf;
- convert_res = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
+ ICHAR *dataPtr = (ICHAR *)parser->m_dataBuf;
+ convert_res = XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)parser->m_dataBufEnd);
*eventEndPP = s;
- defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf));
+ parser->m_defaultHandler(parser->m_handlerArg, parser->m_dataBuf, (int)(dataPtr - (ICHAR *)parser->m_dataBuf));
*eventPP = s;
} while ((convert_res != XML_CONVERT_COMPLETED) && (convert_res != XML_CONVERT_INPUT_INCOMPLETE));
}
else
- defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s));
+ parser->m_defaultHandler(parser->m_handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s));
}
@@ -6027,16 +6019,18 @@ defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata,
if (type->nDefaultAtts == type->allocDefaultAtts) {
if (type->allocDefaultAtts == 0) {
type->allocDefaultAtts = 8;
- type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts
+ type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(parser, type->allocDefaultAtts
* sizeof(DEFAULT_ATTRIBUTE));
- if (!type->defaultAtts)
+ if (!type->defaultAtts) {
+ type->allocDefaultAtts = 0;
return 0;
+ }
}
else {
DEFAULT_ATTRIBUTE *temp;
int count = type->allocDefaultAtts * 2;
temp = (DEFAULT_ATTRIBUTE *)
- REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE)));
+ REALLOC(parser, type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE)));
if (temp == NULL)
return 0;
type->allocDefaultAtts = count;
@@ -6056,7 +6050,7 @@ defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata,
static int
setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
const XML_Char *name;
for (name = elementType->name; *name; name++) {
if (*name == XML_T(ASCII_COLON)) {
@@ -6077,7 +6071,7 @@ setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType)
else
poolDiscard(&dtd->pool);
elementType->prefix = prefix;
-
+ break;
}
}
return 1;
@@ -6087,7 +6081,7 @@ static ATTRIBUTE_ID *
getAttributeId(XML_Parser parser, const ENCODING *enc,
const char *start, const char *end)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
ATTRIBUTE_ID *id;
const XML_Char *name;
if (!poolAppendChar(&dtd->pool, XML_T('\0')))
@@ -6104,7 +6098,7 @@ getAttributeId(XML_Parser parser, const ENCODING *enc,
poolDiscard(&dtd->pool);
else {
poolFinish(&dtd->pool);
- if (!ns)
+ if (!parser->m_ns)
;
else if (name[0] == XML_T(ASCII_x)
&& name[1] == XML_T(ASCII_m)
@@ -6151,20 +6145,20 @@ getAttributeId(XML_Parser parser, const ENCODING *enc,
static const XML_Char *
getContext(XML_Parser parser)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
HASH_TABLE_ITER iter;
XML_Bool needSep = XML_FALSE;
if (dtd->defaultPrefix.binding) {
int i;
int len;
- if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS)))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_EQUALS)))
return NULL;
len = dtd->defaultPrefix.binding->uriLen;
- if (namespaceSeparator)
+ if (parser->m_namespaceSeparator)
len--;
for (i = 0; i < len; i++) {
- if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i])) {
+ if (!poolAppendChar(&parser->m_tempPool, dtd->defaultPrefix.binding->uri[i])) {
/* Because of memory caching, I don't believe this line can be
* executed.
*
@@ -6207,18 +6201,18 @@ getContext(XML_Parser parser)
*/
continue; /* LCOV_EXCL_LINE */
}
- if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP))
+ if (needSep && !poolAppendChar(&parser->m_tempPool, CONTEXT_SEP))
return NULL;
for (s = prefix->name; *s; s++)
- if (!poolAppendChar(&tempPool, *s))
+ if (!poolAppendChar(&parser->m_tempPool, *s))
return NULL;
- if (!poolAppendChar(&tempPool, XML_T(ASCII_EQUALS)))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T(ASCII_EQUALS)))
return NULL;
len = prefix->binding->uriLen;
- if (namespaceSeparator)
+ if (parser->m_namespaceSeparator)
len--;
for (i = 0; i < len; i++)
- if (!poolAppendChar(&tempPool, prefix->binding->uri[i]))
+ if (!poolAppendChar(&parser->m_tempPool, prefix->binding->uri[i]))
return NULL;
needSep = XML_TRUE;
}
@@ -6232,73 +6226,73 @@ getContext(XML_Parser parser)
break;
if (!e->open)
continue;
- if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP))
+ if (needSep && !poolAppendChar(&parser->m_tempPool, CONTEXT_SEP))
return NULL;
for (s = e->name; *s; s++)
- if (!poolAppendChar(&tempPool, *s))
+ if (!poolAppendChar(&parser->m_tempPool, *s))
return 0;
needSep = XML_TRUE;
}
- if (!poolAppendChar(&tempPool, XML_T('\0')))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T('\0')))
return NULL;
- return tempPool.start;
+ return parser->m_tempPool.start;
}
static XML_Bool
setContext(XML_Parser parser, const XML_Char *context)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
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')))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T('\0')))
return XML_FALSE;
- e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&tempPool), 0);
+ e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&parser->m_tempPool), 0);
if (e)
e->open = XML_TRUE;
if (*s != XML_T('\0'))
s++;
context = s;
- poolDiscard(&tempPool);
+ poolDiscard(&parser->m_tempPool);
}
else if (*s == XML_T(ASCII_EQUALS)) {
PREFIX *prefix;
- if (poolLength(&tempPool) == 0)
+ if (poolLength(&parser->m_tempPool) == 0)
prefix = &dtd->defaultPrefix;
else {
- if (!poolAppendChar(&tempPool, XML_T('\0')))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T('\0')))
return XML_FALSE;
- prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&tempPool),
+ prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&parser->m_tempPool),
sizeof(PREFIX));
if (!prefix)
return XML_FALSE;
- if (prefix->name == poolStart(&tempPool)) {
+ if (prefix->name == poolStart(&parser->m_tempPool)) {
prefix->name = poolCopyString(&dtd->pool, prefix->name);
if (!prefix->name)
return XML_FALSE;
}
- poolDiscard(&tempPool);
+ poolDiscard(&parser->m_tempPool);
}
for (context = s + 1;
*context != CONTEXT_SEP && *context != XML_T('\0');
context++)
- if (!poolAppendChar(&tempPool, *context))
+ if (!poolAppendChar(&parser->m_tempPool, *context))
return XML_FALSE;
- if (!poolAppendChar(&tempPool, XML_T('\0')))
+ if (!poolAppendChar(&parser->m_tempPool, XML_T('\0')))
return XML_FALSE;
- if (addBinding(parser, prefix, NULL, poolStart(&tempPool),
- &inheritedBindings) != XML_ERROR_NONE)
+ if (addBinding(parser, prefix, NULL, poolStart(&parser->m_tempPool),
+ &parser->m_inheritedBindings) != XML_ERROR_NONE)
return XML_FALSE;
- poolDiscard(&tempPool);
+ poolDiscard(&parser->m_tempPool);
if (*context != XML_T('\0'))
++context;
s = context;
}
else {
- if (!poolAppendChar(&tempPool, *s))
+ if (!poolAppendChar(&parser->m_tempPool, *s))
return XML_FALSE;
s++;
}
@@ -6663,7 +6657,6 @@ hash(XML_Parser parser, KEY s)
{
struct siphash state;
struct sipkey key;
- (void)sip_tobin;
(void)sip24_valid;
copy_salt_to_sipkey(parser, &key);
sip24_init(&state, &key);
@@ -6983,8 +6976,8 @@ poolGrow(STRING_POOL *pool)
int blockSize = (int)((unsigned)(pool->end - pool->start)*2U);
size_t bytesToAllocate;
- // NOTE: Needs to be calculated prior to calling `realloc`
- // to avoid dangling pointers:
+ /* NOTE: Needs to be calculated prior to calling `realloc`
+ to avoid dangling pointers: */
const ptrdiff_t offsetInsideBlock = pool->ptr - pool->start;
if (blockSize < 0) {
@@ -7062,12 +7055,12 @@ poolGrow(STRING_POOL *pool)
static int FASTCALL
nextScaffoldPart(XML_Parser parser)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
CONTENT_SCAFFOLD * me;
int next;
if (!dtd->scaffIndex) {
- dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int));
+ dtd->scaffIndex = (int *)MALLOC(parser, parser->m_groupSize * sizeof(int));
if (!dtd->scaffIndex)
return -1;
dtd->scaffIndex[0] = 0;
@@ -7077,13 +7070,13 @@ nextScaffoldPart(XML_Parser parser)
CONTENT_SCAFFOLD *temp;
if (dtd->scaffold) {
temp = (CONTENT_SCAFFOLD *)
- REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD));
+ REALLOC(parser, dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD));
if (temp == NULL)
return -1;
dtd->scaffSize *= 2;
}
else {
- temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS
+ temp = (CONTENT_SCAFFOLD *)MALLOC(parser, INIT_SCAFFOLD_ELEMENTS
* sizeof(CONTENT_SCAFFOLD));
if (temp == NULL)
return -1;
@@ -7114,7 +7107,7 @@ build_node(XML_Parser parser,
XML_Content **contpos,
XML_Char **strpos)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
dest->type = dtd->scaffold[src_node].type;
dest->quant = dtd->scaffold[src_node].quant;
if (dest->type == XML_CTYPE_NAME) {
@@ -7148,14 +7141,14 @@ build_node(XML_Parser parser,
static XML_Content *
build_model (XML_Parser parser)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
XML_Content *ret;
XML_Content *cpos;
XML_Char * str;
int allocsize = (dtd->scaffCount * sizeof(XML_Content)
+ (dtd->contentStringLen * sizeof(XML_Char)));
- ret = (XML_Content *)MALLOC(allocsize);
+ ret = (XML_Content *)MALLOC(parser, allocsize);
if (!ret)
return NULL;
@@ -7172,7 +7165,7 @@ getElementType(XML_Parser parser,
const char *ptr,
const char *end)
{
- DTD * const dtd = _dtd; /* save one level of indirection */
+ DTD * const dtd = parser->m_dtd; /* save one level of indirection */
const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end);
ELEMENT_TYPE *ret;
diff --git a/Utilities/cmexpat/lib/xmlrole.c b/Utilities/cmexpat/lib/xmlrole.c
index c809ee514..708507d57 100644
--- a/Utilities/cmexpat/lib/xmlrole.c
+++ b/Utilities/cmexpat/lib/xmlrole.c
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#include <stddef.h>
diff --git a/Utilities/cmexpat/lib/xmlrole.h b/Utilities/cmexpat/lib/xmlrole.h
index 4dd9f06f9..e5f048eab 100644
--- a/Utilities/cmexpat/lib/xmlrole.h
+++ b/Utilities/cmexpat/lib/xmlrole.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#ifndef XmlRole_INCLUDED
diff --git a/Utilities/cmexpat/lib/xmltok.c b/Utilities/cmexpat/lib/xmltok.c
index db4a5c8ca..6b415d839 100644
--- a/Utilities/cmexpat/lib/xmltok.c
+++ b/Utilities/cmexpat/lib/xmltok.c
@@ -1,8 +1,47 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#include <stddef.h>
+#include <string.h> /* memcpy */
+
+#if defined(_MSC_VER) && (_MSC_VER <= 1700)
+ /* for vs2012/11.0/1700 and earlier Visual Studio compilers */
+# define bool int
+# define false 0
+# define true 1
+#else
+# include <stdbool.h>
+#endif
+
#ifdef _WIN32
#include "winconfig.h"
@@ -27,7 +66,6 @@
{ PREFIX(prologTok), PREFIX(contentTok), \
PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \
{ PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \
- PREFIX(sameName), \
PREFIX(nameMatchesAscii), \
PREFIX(nameLength), \
PREFIX(skipS), \
@@ -324,7 +362,7 @@ enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */
};
void
-align_limit_to_full_utf8_characters(const char * from, const char ** fromLimRef)
+_INTERNAL_trim_to_complete_utf8_characters(const char * from, const char ** fromLimRef)
{
const char * fromLim = *fromLimRef;
size_t walked = 0;
@@ -363,22 +401,37 @@ utf8_toUtf8(const ENCODING *UNUSED_P(enc),
const char **fromP, const char *fromLim,
char **toP, const char *toLim)
{
- char *to;
- const char *from;
- const char *fromLimInitial = fromLim;
+ bool input_incomplete = false;
+ bool output_exhausted = false;
+
+ /* Avoid copying partial characters (due to limited space). */
+ const ptrdiff_t bytesAvailable = fromLim - *fromP;
+ const ptrdiff_t bytesStorable = toLim - *toP;
+ if (bytesAvailable > bytesStorable) {
+ fromLim = *fromP + bytesStorable;
+ output_exhausted = true;
+ }
- /* Avoid copying partial characters. */
- align_limit_to_full_utf8_characters(*fromP, &fromLim);
+ /* Avoid copying partial characters (from incomplete input). */
+ {
+ const char * const fromLimBefore = fromLim;
+ _INTERNAL_trim_to_complete_utf8_characters(*fromP, &fromLim);
+ if (fromLim < fromLimBefore) {
+ input_incomplete = true;
+ }
+ }
- for (to = *toP, from = *fromP; (from < fromLim) && (to < toLim); from++, to++)
- *to = *from;
- *fromP = from;
- *toP = to;
+ {
+ const ptrdiff_t bytesToCopy = fromLim - *fromP;
+ memcpy(*toP, *fromP, bytesToCopy);
+ *fromP += bytesToCopy;
+ *toP += bytesToCopy;
+ }
- if (fromLim < fromLimInitial)
- return XML_CONVERT_INPUT_INCOMPLETE;
- else if ((to == toLim) && (from < fromLim))
+ if (output_exhausted) /* needs to go first */
return XML_CONVERT_OUTPUT_EXHAUSTED;
+ else if (input_incomplete)
+ return XML_CONVERT_INPUT_INCOMPLETE;
else
return XML_CONVERT_COMPLETED;
}
@@ -1411,9 +1464,8 @@ unknown_toUtf8(const ENCODING *enc,
return XML_CONVERT_OUTPUT_EXHAUSTED;
(*fromP)++;
}
- do {
- *(*toP)++ = *utf8++;
- } while (--n != 0);
+ memcpy(*toP, utf8, n);
+ *toP += n;
}
}
diff --git a/Utilities/cmexpat/lib/xmltok.h b/Utilities/cmexpat/lib/xmltok.h
index 752007e8b..50926f38a 100644
--- a/Utilities/cmexpat/lib/xmltok.h
+++ b/Utilities/cmexpat/lib/xmltok.h
@@ -1,5 +1,33 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/*
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
#ifndef XmlTok_INCLUDED
@@ -139,9 +167,6 @@ enum XML_Convert_Result {
struct encoding {
SCANNER scanners[XML_N_STATES];
SCANNER literalScanners[XML_N_LITERAL_TYPES];
- int (PTRCALL *sameName)(const ENCODING *,
- const char *,
- const char *);
int (PTRCALL *nameMatchesAscii)(const ENCODING *,
const char *,
const char *,
@@ -232,8 +257,6 @@ struct encoding {
#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))
diff --git a/Utilities/cmexpat/lib/xmltok_impl.c b/Utilities/cmexpat/lib/xmltok_impl.c
index 4fa1ff679..4d9ae7dc3 100644
--- a/Utilities/cmexpat/lib/xmltok_impl.c
+++ b/Utilities/cmexpat/lib/xmltok_impl.c
@@ -1,8 +1,35 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/* This file is included!
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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 is included! */
#ifdef XML_TOK_IMPL_C
#ifndef IS_INVALID_CHAR
@@ -47,6 +74,7 @@
*nextTokPtr = ptr; \
return XML_TOK_INVALID; \
} \
+ /* fall through */ \
case BT_NMSTRT: \
case BT_HEX: \
case BT_DIGIT: \
@@ -75,6 +103,7 @@
*nextTokPtr = ptr; \
return XML_TOK_INVALID; \
} \
+ /* fall through */ \
case BT_NMSTRT: \
case BT_HEX: \
ptr += MINBPC(enc); \
@@ -575,7 +604,7 @@ PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end,
return XML_TOK_INVALID;
}
}
- /* fall through */
+ /* fall through */
case BT_EQUALS:
{
int open;
@@ -1415,6 +1444,7 @@ PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
case BT_NMSTRT:
if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f))
break;
+ /* fall through */
default:
switch (BYTE_TO_ASCII(enc, ptr)) {
case 0x24: /* $ */
@@ -1626,87 +1656,14 @@ PREFIX(predefinedEntityName)(const ENCODING *UNUSED_P(enc), const char *ptr,
return 0;
}
-/* This function does not appear to be called from anywhere within the
- * library code. It is used via the macro XmlSameName(), which is
- * defined but never used. Since it appears in the encoding function
- * table, removing it is not a thing to be undertaken lightly. For
- * the moment, we simply exclude it from coverage tests.
- *
- * LCOV_EXCL_START
- */
-static int PTRCALL
-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 */
-}
-/* LCOV_EXCL_STOP */
-
static int PTRCALL
PREFIX(nameMatchesAscii)(const ENCODING *UNUSED_P(enc), const char *ptr1,
const char *end1, const char *ptr2)
{
for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
if (end1 - ptr1 < MINBPC(enc)) {
- /* This line cannot be executed. THe incoming data has already
- * been tokenized once, so imcomplete characters like this have
+ /* This line cannot be executed. The incoming data has already
+ * been tokenized once, so incomplete characters like this have
* already been eliminated from the input. Retaining the
* paranoia check is still valuable, however.
*/
diff --git a/Utilities/cmexpat/lib/xmltok_impl.h b/Utilities/cmexpat/lib/xmltok_impl.h
index da0ea60a6..a6420f48e 100644
--- a/Utilities/cmexpat/lib/xmltok_impl.h
+++ b/Utilities/cmexpat/lib/xmltok_impl.h
@@ -1,6 +1,33 @@
/*
-Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
-See the file COPYING for copying permission.
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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.
*/
enum {
diff --git a/Utilities/cmexpat/lib/xmltok_ns.c b/Utilities/cmexpat/lib/xmltok_ns.c
index c3b88fdf4..23d31e8e4 100644
--- a/Utilities/cmexpat/lib/xmltok_ns.c
+++ b/Utilities/cmexpat/lib/xmltok_ns.c
@@ -1,8 +1,35 @@
-/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
- See the file COPYING for copying permission.
+/* This file is included!
+ __ __ _
+ ___\ \/ /_ __ __ _| |_
+ / _ \\ /| '_ \ / _` | __|
+ | __// \| |_) | (_| | |_
+ \___/_/\_\ .__/ \__,_|\__|
+ |_| XML parser
+
+ Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
+ Copyright (c) 2000-2017 Expat development team
+ Licensed under the MIT license:
+
+ 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 is included! */
#ifdef XML_TOK_NS_C
const ENCODING *
diff --git a/Utilities/cmjsoncpp/CMakeLists.txt b/Utilities/cmjsoncpp/CMakeLists.txt
index bc9076e8e..764be8d55 100644
--- a/Utilities/cmjsoncpp/CMakeLists.txt
+++ b/Utilities/cmjsoncpp/CMakeLists.txt
@@ -2,18 +2,16 @@ project(JsonCpp CXX)
# Disable warnings to avoid changing 3rd party code.
if(CMAKE_CXX_COMPILER_ID MATCHES
- "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "PathScale")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -woffall")
endif()
set(JSONCPP_SOURCES
- src/lib_json/json_batchallocator.h
src/lib_json/json_reader.cpp
src/lib_json/json_tool.h
src/lib_json/json_value.cpp
- src/lib_json/json_valueiterator.inl
src/lib_json/json_writer.cpp
)
diff --git a/Utilities/cmjsoncpp/LICENSE b/Utilities/cmjsoncpp/LICENSE
index ca2bfe1a0..89280a6c4 100644
--- a/Utilities/cmjsoncpp/LICENSE
+++ b/Utilities/cmjsoncpp/LICENSE
@@ -2,13 +2,13 @@ The JsonCpp library's source code, including accompanying documentation,
tests and demonstration applications, are licensed under the following
conditions...
-The author (Baptiste Lepilleur) explicitly disclaims copyright in all
+Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain.
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
-2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
-released under the terms of the MIT License (see below).
+2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
+The JsonCpp Authors, and is released under the terms of the MIT License (see below).
In jurisdictions which recognize Public Domain property, the user of this
software may choose to accept it either as 1) Public Domain, 2) under the
@@ -23,7 +23,7 @@ described in clear, concise terms at:
The full text of the MIT License follows:
========================================================================
-Copyright (c) 2007-2010 Baptiste Lepilleur
+Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
diff --git a/Utilities/cmjsoncpp/include/json/assertions.h b/Utilities/cmjsoncpp/include/json/assertions.h
index 37a3ff553..f64913fbe 100644
--- a/Utilities/cmjsoncpp/include/json/assertions.h
+++ b/Utilities/cmjsoncpp/include/json/assertions.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -11,31 +11,44 @@
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <stdlib.h>
+#include <sstream>
+/** It should not be possible for a maliciously designed file to
+ * cause an abort() or seg-fault, so these macros are used only
+ * for pre-condition violations and internal logic errors.
+ */
#if JSON_USE_EXCEPTION
-#include <stdexcept>
-#define JSON_ASSERT(condition) \
- assert(condition); // @todo <= change this into an exception throw
-#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message);
+
+// @todo <= add detail about condition in exception
+# define JSON_ASSERT(condition) \
+ {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
+
+# define JSON_FAIL_MESSAGE(message) \
+ { \
+ JSONCPP_OSTRINGSTREAM oss; oss << message; \
+ Json::throwLogicError(oss.str()); \
+ abort(); \
+ }
+
#else // JSON_USE_EXCEPTION
-#define JSON_ASSERT(condition) assert(condition);
+
+# define JSON_ASSERT(condition) assert(condition)
// The call to assert() will show the failure message in debug builds. In
-// release bugs we write to invalid memory in order to crash hard, so that a
-// debugger or crash reporter gets the chance to take over. We still call exit()
-// afterward in order to tell the compiler that this macro doesn't return.
-#define JSON_FAIL_MESSAGE(message) \
+// release builds we abort, for a core-dump or debugger.
+# define JSON_FAIL_MESSAGE(message) \
{ \
- assert(false&& message); \
- strcpy(reinterpret_cast<char*>(666), message); \
- exit(123); \
+ JSONCPP_OSTRINGSTREAM oss; oss << message; \
+ assert(false && oss.str().c_str()); \
+ abort(); \
}
+
#endif
#define JSON_ASSERT_MESSAGE(condition, message) \
if (!(condition)) { \
- JSON_FAIL_MESSAGE(message) \
+ JSON_FAIL_MESSAGE(message); \
}
#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
diff --git a/Utilities/cmjsoncpp/include/json/config.h b/Utilities/cmjsoncpp/include/json/config.h
index 6847ceba8..2cc8462b3 100644
--- a/Utilities/cmjsoncpp/include/json/config.h
+++ b/Utilities/cmjsoncpp/include/json/config.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -9,6 +9,10 @@
// Include KWSys Large File Support configuration.
#include <cmsys/Configure.h>
+#include <stddef.h>
+#include <string> //typedef String
+#include <stdint.h> //typedef int64_t, uint64_t
+
#if defined(_MSC_VER)
# pragma warning(push,1)
#endif
@@ -22,17 +26,6 @@
/// std::map
/// as Value container.
//# define JSON_USE_CPPTL_SMALLMAP 1
-/// If defined, indicates that Json specific container should be used
-/// (hash table & simple deque container with customizable allocator).
-/// THIS FEATURE IS STILL EXPERIMENTAL! There is know bugs: See #3177332
-//# define JSON_VALUE_USE_INTERNAL_MAP 1
-/// Force usage of standard new/malloc based allocator instead of memory pool
-/// based allocator.
-/// The memory pools allocator used optimization (initializing Value and
-/// ValueInternalLink
-/// as if it was a POD) that may cause some validation tool to report errors.
-/// Only has effects if JSON_VALUE_USE_INTERNAL_MAP is defined.
-//# define JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1
// If non-zero, the library uses exceptions to report bad input instead of C
// assertion macros. The default is to use exceptions.
@@ -55,12 +48,12 @@
#ifdef JSON_IN_CPPTL
#define JSON_API CPPTL_API
#elif defined(JSON_DLL_BUILD)
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__MINGW32__)
#define JSON_API __declspec(dllexport)
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#endif // if defined(_MSC_VER)
#elif defined(JSON_DLL)
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) || defined(__MINGW32__)
#define JSON_API __declspec(dllimport)
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
#endif // if defined(_MSC_VER)
@@ -74,26 +67,95 @@
// Storages, and 64 bits integer support is disabled.
// #define JSON_NO_INT64 1
-#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
-// Microsoft Visual Studio 6 only support conversion from __int64 to double
-// (no conversion from unsigned __int64).
-#define JSON_USE_INT64_DOUBLE_CONVERSION 1
-// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
-// characters in the debug information)
-// All projects I've ever seen with VS6 were using this globally (not bothering
-// with pragma push/pop).
-#pragma warning(disable : 4786)
-#endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
-
-#if defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
-/// Indicates that the following function is deprecated.
-#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
+#if defined(_MSC_VER) // MSVC
+# if _MSC_VER <= 1200 // MSVC 6
+ // Microsoft Visual Studio 6 only support conversion from __int64 to double
+ // (no conversion from unsigned __int64).
+# define JSON_USE_INT64_DOUBLE_CONVERSION 1
+ // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
+ // characters in the debug information)
+ // All projects I've ever seen with VS6 were using this globally (not bothering
+ // with pragma push/pop).
+# pragma warning(disable : 4786)
+# endif // MSVC 6
+
+#endif // defined(_MSC_VER)
+
+// In c++11 the override keyword allows you to explicity define that a function
+// is intended to override the base-class version. This makes the code more
+// managable and fixes a set of common hard-to-find bugs.
+#if __cplusplus >= 201103L
+# define JSONCPP_OVERRIDE override
+# define JSONCPP_NOEXCEPT noexcept
+#elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900
+# define JSONCPP_OVERRIDE override
+# define JSONCPP_NOEXCEPT throw()
+#elif defined(_MSC_VER) && _MSC_VER >= 1900
+# define JSONCPP_OVERRIDE override
+# define JSONCPP_NOEXCEPT noexcept
+#else
+# define JSONCPP_OVERRIDE
+# define JSONCPP_NOEXCEPT throw()
+#endif
+
+#ifndef JSON_HAS_RVALUE_REFERENCES
+
+#if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010
+#define JSON_HAS_RVALUE_REFERENCES 1
+#endif // MSVC >= 2010
+
+#ifdef __clang__
+#if __has_feature(cxx_rvalue_references)
+#define JSON_HAS_RVALUE_REFERENCES 1
+#endif // has_feature
+
+#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
+#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
+#define JSON_HAS_RVALUE_REFERENCES 1
+#endif // GXX_EXPERIMENTAL
+
+#endif // __clang__ || __GNUC__
+
+#endif // not defined JSON_HAS_RVALUE_REFERENCES
+
+#ifndef JSON_HAS_RVALUE_REFERENCES
+#define JSON_HAS_RVALUE_REFERENCES 0
#endif
+#ifdef __clang__
+# if __has_extension(attribute_deprecated_with_message)
+# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
+# endif
+#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
+# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
+# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
+# elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+# define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
+# endif // GNUC version
+#elif defined(_MSC_VER) && _MSC_VER >= 1500 // MSVC 2008
+ /// Indicates that the following function is deprecated.
+# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
+#endif // __clang__ || __GNUC__ || _MSC_VER
+
+#undef JSONCPP_DEPRECATED // no deprecations in CMake copy
#if !defined(JSONCPP_DEPRECATED)
#define JSONCPP_DEPRECATED(message)
#endif // if !defined(JSONCPP_DEPRECATED)
+#if __GNUC__ >= 6
+# define JSON_USE_INT64_DOUBLE_CONVERSION 1
+#endif
+
+#if !defined(JSON_IS_AMALGAMATION)
+
+# include "version.h"
+
+# if JSONCPP_USING_SECURE_MEMORY
+# include "allocator.h" //typedef Allocator
+# endif
+
+#endif // if !defined(JSON_IS_AMALGAMATION)
+
namespace Json {
typedef int Int;
typedef unsigned int UInt;
@@ -107,13 +169,26 @@ typedef unsigned int LargestUInt;
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else // if defined(_MSC_VER) // Other platforms, use long long
-typedef long long int Int64;
-typedef unsigned long long int UInt64;
+typedef int64_t Int64;
+typedef uint64_t UInt64;
#endif // if defined(_MSC_VER)
typedef Int64 LargestInt;
typedef UInt64 LargestUInt;
#define JSON_HAS_INT64
#endif // if defined(JSON_NO_INT64)
+#if JSONCPP_USING_SECURE_MEMORY
+#define JSONCPP_STRING std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
+#define JSONCPP_OSTRINGSTREAM std::basic_ostringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
+#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char>>
+#define JSONCPP_ISTRINGSTREAM std::basic_istringstream<char, std::char_traits<char>, Json::SecureAllocator<char> >
+#define JSONCPP_ISTREAM std::istream
+#else
+#define JSONCPP_STRING std::string
+#define JSONCPP_OSTRINGSTREAM std::ostringstream
+#define JSONCPP_OSTREAM std::ostream
+#define JSONCPP_ISTRINGSTREAM std::istringstream
+#define JSONCPP_ISTREAM std::istream
+#endif // if JSONCPP_USING_SECURE_MEMORY
} // end namespace Json
#endif // JSON_CONFIG_H_INCLUDED
diff --git a/Utilities/cmjsoncpp/include/json/features.h b/Utilities/cmjsoncpp/include/json/features.h
index 1bb7bb614..365abb356 100644
--- a/Utilities/cmjsoncpp/include/json/features.h
+++ b/Utilities/cmjsoncpp/include/json/features.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -10,6 +10,10 @@
#include "forwards.h"
#endif // if !defined(JSON_IS_AMALGAMATION)
+#if !defined(__SUNPRO_CC)
+#pragma pack(push, 8)
+#endif
+
namespace Json {
/** \brief Configuration passed to reader and writer.
@@ -54,4 +58,8 @@ public:
} // namespace Json
+#if !defined(__SUNPRO_CC)
+#pragma pack(pop)
+#endif
+
#endif // CPPTL_JSON_FEATURES_H_INCLUDED
diff --git a/Utilities/cmjsoncpp/include/json/forwards.h b/Utilities/cmjsoncpp/include/json/forwards.h
index 84a26cd2f..70bbe191c 100644
--- a/Utilities/cmjsoncpp/include/json/forwards.h
+++ b/Utilities/cmjsoncpp/include/json/forwards.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -31,12 +31,6 @@ class Value;
class ValueIteratorBase;
class ValueIterator;
class ValueConstIterator;
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
-class ValueMapAllocator;
-class ValueInternalLink;
-class ValueInternalArray;
-class ValueInternalMap;
-#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
} // namespace Json
diff --git a/Utilities/cmjsoncpp/include/json/json.h b/Utilities/cmjsoncpp/include/json/json.h
index f89bc6270..59646723b 100644
--- a/Utilities/cmjsoncpp/include/json/json.h
+++ b/Utilities/cmjsoncpp/include/json/json.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
diff --git a/Utilities/cmjsoncpp/include/json/reader.h b/Utilities/cmjsoncpp/include/json/reader.h
index 95237d168..667246a0b 100644
--- a/Utilities/cmjsoncpp/include/json/reader.h
+++ b/Utilities/cmjsoncpp/include/json/reader.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -14,6 +14,7 @@
#include <iosfwd>
#include <stack>
#include <string>
+#include <istream>
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
// be used by...
@@ -22,13 +23,18 @@
#pragma warning(disable : 4251)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#if !defined(__SUNPRO_CC)
+#pragma pack(push, 8)
+#endif
+
namespace Json {
/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
*Value.
*
+ * deprecated Use CharReader and CharReaderBuilder.
*/
-class JSON_API Reader {
+class JSONCPP_DEPRECATED("Use CharReader and CharReaderBuilder instead") JSON_API Reader {
public:
typedef char Char;
typedef const Char* Location;
@@ -40,9 +46,9 @@ public:
*
*/
struct StructuredError {
- size_t offset_start;
- size_t offset_limit;
- std::string message;
+ ptrdiff_t offset_start;
+ ptrdiff_t offset_limit;
+ JSONCPP_STRING message;
};
/** \brief Constructs a Reader allowing all features
@@ -78,7 +84,7 @@ public:
document to read.
* \param endDoc Pointer on the end of the UTF-8 encoded string of the
document to read.
- \ Must be >= beginDoc.
+ * Must be >= beginDoc.
* \param root [out] Contains the root value of the document if it was
* successfully parsed.
* \param collectComments \c true to collect comment and allow writing them
@@ -97,7 +103,7 @@ public:
/// \brief Parse from input stream.
/// \see Json::operator>>(std::istream&, Json::Value&).
- bool parse(std::istream& is, Value& root, bool collectComments = true);
+ bool parse(JSONCPP_ISTREAM& is, Value& root, bool collectComments = true);
/** \brief Returns a user friendly string that list errors in the parsed
* document.
@@ -106,8 +112,10 @@ public:
* the parsed document. An empty string is returned if no error
* occurred
* during parsing.
+ * deprecated Use getFormattedErrorMessages() instead (typo fix).
*/
- std::string getFormatedErrorMessages() const;
+ JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
+ JSONCPP_STRING getFormatedErrorMessages() const;
/** \brief Returns a user friendly string that list errors in the parsed
* document.
@@ -117,7 +125,7 @@ public:
* occurred
* during parsing.
*/
- std::string getFormattedErrorMessages() const;
+ JSONCPP_STRING getFormattedErrorMessages() const;
/** \brief Returns a vector of structured erros encounted while parsing.
* \return A (possibly empty) vector of StructuredError objects. Currently
@@ -134,7 +142,7 @@ public:
* \return \c true if the error was successfully added, \c false if the
* Value offset exceeds the document size.
*/
- bool pushError(const Value& value, const std::string& message);
+ bool pushError(const Value& value, const JSONCPP_STRING& message);
/** \brief Add a semantic error message with extra context.
* \param value JSON Value location associated with the error
@@ -143,7 +151,7 @@ public:
* \return \c true if the error was successfully added, \c false if either
* Value offset exceeds the document size.
*/
- bool pushError(const Value& value, const std::string& message, const Value& extra);
+ bool pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra);
/** \brief Return whether there are any errors.
* \return \c true if there are no errors to report \c false if
@@ -179,13 +187,12 @@ private:
class ErrorInfo {
public:
Token token_;
- std::string message_;
+ JSONCPP_STRING message_;
Location extra_;
};
typedef std::deque<ErrorInfo> Errors;
- bool expectToken(TokenType type, Token& token, const char* message);
bool readToken(Token& token);
void skipSpaces();
bool match(Location pattern, int patternLength);
@@ -200,7 +207,7 @@ private:
bool decodeNumber(Token& token);
bool decodeNumber(Token& token, Value& decoded);
bool decodeString(Token& token);
- bool decodeString(Token& token, std::string& decoded);
+ bool decodeString(Token& token, JSONCPP_STRING& decoded);
bool decodeDouble(Token& token);
bool decodeDouble(Token& token, Value& decoded);
bool decodeUnicodeCodePoint(Token& token,
@@ -211,9 +218,9 @@ private:
Location& current,
Location end,
unsigned int& unicode);
- bool addError(const std::string& message, Token& token, Location extra = 0);
+ bool addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
bool recoverFromError(TokenType skipUntilToken);
- bool addErrorAndRecover(const std::string& message,
+ bool addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
TokenType skipUntilToken);
void skipUntilSpace();
@@ -221,24 +228,154 @@ private:
Char getNextChar();
void
getLocationLineAndColumn(Location location, int& line, int& column) const;
- std::string getLocationLineAndColumn(Location location) const;
+ JSONCPP_STRING getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);
+ static bool containsNewLine(Location begin, Location end);
+ static JSONCPP_STRING normalizeEOL(Location begin, Location end);
+
typedef std::stack<Value*> Nodes;
Nodes nodes_;
Errors errors_;
- std::string document_;
+ JSONCPP_STRING document_;
Location begin_;
Location end_;
Location current_;
Location lastValueEnd_;
Value* lastValue_;
- std::string commentsBefore_;
+ JSONCPP_STRING commentsBefore_;
Features features_;
bool collectComments_;
+}; // Reader
+
+/** Interface for reading JSON from a char array.
+ */
+class JSON_API CharReader {
+public:
+ virtual ~CharReader() {}
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
+ document.
+ * The document must be a UTF-8 encoded string containing the document to read.
+ *
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
+ document to read.
+ * \param endDoc Pointer on the end of the UTF-8 encoded string of the
+ document to read.
+ * Must be >= beginDoc.
+ * \param root [out] Contains the root value of the document if it was
+ * successfully parsed.
+ * \param errs [out] Formatted error messages (if not NULL)
+ * a user friendly string that lists errors in the parsed
+ * document.
+ * \return \c true if the document was successfully parsed, \c false if an
+ error occurred.
+ */
+ virtual bool parse(
+ char const* beginDoc, char const* endDoc,
+ Value* root, JSONCPP_STRING* errs) = 0;
+
+ class JSON_API Factory {
+ public:
+ virtual ~Factory() {}
+ /** \brief Allocate a CharReader via operator new().
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
+ */
+ virtual CharReader* newCharReader() const = 0;
+ }; // Factory
+}; // CharReader
+
+/** \brief Build a CharReader implementation.
+
+Usage:
+\code
+ using namespace Json;
+ CharReaderBuilder builder;
+ builder["collectComments"] = false;
+ Value value;
+ JSONCPP_STRING errs;
+ bool ok = parseFromStream(builder, std::cin, &value, &errs);
+\endcode
+*/
+class JSON_API CharReaderBuilder : public CharReader::Factory {
+public:
+ // Note: We use a Json::Value so that we can add data-members to this class
+ // without a major version bump.
+ /** Configuration of this builder.
+ These are case-sensitive.
+ Available settings (case-sensitive):
+ - `"collectComments": false or true`
+ - true to collect comment and allow writing them
+ back during serialization, false to discard comments.
+ This parameter is ignored if allowComments is false.
+ - `"allowComments": false or true`
+ - true if comments are allowed.
+ - `"strictRoot": false or true`
+ - true if root must be either an array or an object value
+ - `"allowDroppedNullPlaceholders": false or true`
+ - true if dropped null placeholders are allowed. (See StreamWriterBuilder.)
+ - `"allowNumericKeys": false or true`
+ - true if numeric object keys are allowed.
+ - `"allowSingleQuotes": false or true`
+ - true if '' are allowed for strings (both keys and values)
+ - `"stackLimit": integer`
+ - Exceeding stackLimit (recursive depth of `readValue()`) will
+ cause an exception.
+ - This is a security issue (seg-faults caused by deeply nested JSON),
+ so the default is low.
+ - `"failIfExtra": false or true`
+ - If true, `parse()` returns false when extra non-whitespace trails
+ the JSON value in the input string.
+ - `"rejectDupKeys": false or true`
+ - If true, `parse()` returns false when a key is duplicated within an object.
+ - `"allowSpecialFloats": false or true`
+ - If true, special float values (NaNs and infinities) are allowed
+ and their values are lossfree restorable.
+
+ You can examine 'settings_` yourself
+ to see the defaults. You can also write and read them just like any
+ JSON Value.
+ \sa setDefaults()
+ */
+ Json::Value settings_;
+
+ CharReaderBuilder();
+ ~CharReaderBuilder() JSONCPP_OVERRIDE;
+
+ CharReader* newCharReader() const JSONCPP_OVERRIDE;
+
+ /** \return true if 'settings' are legal and consistent;
+ * otherwise, indicate bad settings via 'invalid'.
+ */
+ bool validate(Json::Value* invalid) const;
+
+ /** A simple way to update a specific setting.
+ */
+ Value& operator[](JSONCPP_STRING key);
+
+ /** Called by ctor, but you can use this to reset settings_.
+ * \pre 'settings' != NULL (but Json::null is fine)
+ * \remark Defaults:
+ * snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
+ */
+ static void setDefaults(Json::Value* settings);
+ /** Same as old Features::strictMode().
+ * \pre 'settings' != NULL (but Json::null is fine)
+ * \remark Defaults:
+ * snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
+ */
+ static void strictMode(Json::Value* settings);
};
+/** Consume entire stream and use its begin/end.
+ * Someday we might have a real StreamReader, but for now this
+ * is convenient.
+ */
+bool JSON_API parseFromStream(
+ CharReader::Factory const&,
+ JSONCPP_ISTREAM&,
+ Value* root, std::string* errs);
+
/** \brief Read from 'sin' into 'root'.
Always keep comments from the input JSON.
@@ -263,10 +400,14 @@ private:
\throw std::exception on parse error.
\see Json::operator<<()
*/
-JSON_API std::istream& operator>>(std::istream&, Value&);
+JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
} // namespace Json
+#if !defined(__SUNPRO_CC)
+#pragma pack(pop)
+#endif
+
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(pop)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
diff --git a/Utilities/cmjsoncpp/include/json/value.h b/Utilities/cmjsoncpp/include/json/value.h
index 197a85614..7b90c5a1a 100644
--- a/Utilities/cmjsoncpp/include/json/value.h
+++ b/Utilities/cmjsoncpp/include/json/value.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -11,6 +11,7 @@
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <string>
#include <vector>
+#include <exception>
#ifndef JSON_USE_CPPTL_SMALLMAP
#include <map>
@@ -21,6 +22,19 @@
#include <cpptl/forwards.h>
#endif
+//Conditional NORETURN attribute on the throw functions would:
+// a) suppress false positives from static code analysis
+// b) possibly improve optimization opportunities.
+#if !defined(JSONCPP_NORETURN)
+# if defined(_MSC_VER)
+# define JSONCPP_NORETURN __declspec(noreturn)
+# elif defined(__GNUC__)
+# define JSONCPP_NORETURN __attribute__ ((__noreturn__))
+# else
+# define JSONCPP_NORETURN
+# endif
+#endif
+
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
// be used by...
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
@@ -28,10 +42,54 @@
#pragma warning(disable : 4251)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#if !defined(__SUNPRO_CC)
+#pragma pack(push, 8)
+#endif
+
/** \brief JSON (JavaScript Object Notation).
*/
namespace Json {
+/** Base class for all exceptions we throw.
+ *
+ * We use nothing but these internally. Of course, STL can throw others.
+ */
+class JSON_API Exception : public std::exception {
+public:
+ Exception(JSONCPP_STRING const& msg);
+ ~Exception() JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
+ char const* what() const JSONCPP_NOEXCEPT JSONCPP_OVERRIDE;
+protected:
+ JSONCPP_STRING msg_;
+};
+
+/** Exceptions which the user cannot easily avoid.
+ *
+ * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
+ *
+ * \remark derived from Json::Exception
+ */
+class JSON_API RuntimeError : public Exception {
+public:
+ RuntimeError(JSONCPP_STRING const& msg);
+};
+
+/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
+ *
+ * These are precondition-violations (user bugs) and internal errors (our bugs).
+ *
+ * \remark derived from Json::Exception
+ */
+class JSON_API LogicError : public Exception {
+public:
+ LogicError(JSONCPP_STRING const& msg);
+};
+
+/// used internally
+JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg);
+/// used internally
+JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg);
+
/** \brief Type of the value held by a Value object.
*/
enum ValueType {
@@ -74,14 +132,14 @@ enum CommentPlacement {
*/
class JSON_API StaticString {
public:
- explicit StaticString(const char* czstring) : str_(czstring) {}
+ explicit StaticString(const char* czstring) : c_str_(czstring) {}
- operator const char*() const { return str_; }
+ operator const char*() const { return c_str_; }
- const char* c_str() const { return str_; }
+ const char* c_str() const { return c_str_; }
private:
- const char* str_;
+ const char* c_str_;
};
/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
@@ -99,28 +157,29 @@ private:
* The type of the held value is represented by a #ValueType and
* can be obtained using type().
*
- * values of an #objectValue or #arrayValue can be accessed using operator[]()
- *methods.
- * Non const methods will automatically create the a #nullValue element
+ * Values of an #objectValue or #arrayValue can be accessed using operator[]()
+ * methods.
+ * Non-const methods will automatically create the a #nullValue element
* if it does not exist.
- * The sequence of an #arrayValue will be automatically resize and initialized
+ * The sequence of an #arrayValue will be automatically resized and initialized
* with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
*
- * The get() methods can be used to obtanis default value in the case the
- *required element
- * does not exist.
+ * The get() methods can be used to obtain default value in the case the
+ * required element does not exist.
*
* It is possible to iterate over the list of a #objectValue values using
* the getMemberNames() method.
+ *
+ * \note #Value string-length fit in size_t, but keys must be < 2^30.
+ * (The reason is an implementation detail.) A #CharReader will raise an
+ * exception if a bound is exceeded to avoid security holes in your app,
+ * but the Value API does *not* check bounds. That is the responsibility
+ * of the caller.
*/
class JSON_API Value {
friend class ValueIteratorBase;
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- friend class ValueInternalLink;
- friend class ValueInternalMap;
-#endif
public:
- typedef std::vector<std::string> Members;
+ typedef std::vector<JSONCPP_STRING> Members;
typedef ValueIterator iterator;
typedef ValueConstIterator const_iterator;
typedef Json::UInt UInt;
@@ -133,7 +192,10 @@ public:
typedef Json::LargestUInt LargestUInt;
typedef Json::ArrayIndex ArrayIndex;
- static const Value& null;
+ static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().
+ static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null
+ static Value const& nullSingleton(); ///< Prefer this to null or nullRef.
+
/// Minimum signed integer value that can be stored in a Json::Value.
static const LargestInt minLargestInt;
/// Maximum signed integer value that can be stored in a Json::Value.
@@ -159,7 +221,6 @@ public:
private:
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
class CZString {
public:
enum DuplicationPolicy {
@@ -168,20 +229,39 @@ private:
duplicateOnCopy
};
CZString(ArrayIndex index);
- CZString(const char* cstr, DuplicationPolicy allocate);
- CZString(const CZString& other);
+ CZString(char const* str, unsigned length, DuplicationPolicy allocate);
+ CZString(CZString const& other);
+#if JSON_HAS_RVALUE_REFERENCES
+ CZString(CZString&& other);
+#endif
~CZString();
- CZString& operator=(CZString other);
- bool operator<(const CZString& other) const;
- bool operator==(const CZString& other) const;
+ CZString& operator=(const CZString& other);
+
+#if JSON_HAS_RVALUE_REFERENCES
+ CZString& operator=(CZString&& other);
+#endif
+
+ bool operator<(CZString const& other) const;
+ bool operator==(CZString const& other) const;
ArrayIndex index() const;
- const char* c_str() const;
+ //const char* c_str() const; ///< deprecated
+ char const* data() const;
+ unsigned length() const;
bool isStaticString() const;
private:
void swap(CZString& other);
- const char* cstr_;
- ArrayIndex index_;
+
+ struct StringStorage {
+ unsigned policy_: 2;
+ unsigned length_: 30; // 1GB max
+ };
+
+ char const* cstr_; // actually, a prefixed string, unless policy is noDup
+ union {
+ ArrayIndex index_;
+ StringStorage storage_;
+ };
};
public:
@@ -190,7 +270,6 @@ public:
#else
typedef CppTL::SmallMap<CZString, Value> ObjectValues;
#endif // ifndef JSON_USE_CPPTL_SMALLMAP
-#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
public:
@@ -217,47 +296,72 @@ Json::Value obj_value(Json::objectValue); // {}
Value(UInt64 value);
#endif // if defined(JSON_HAS_INT64)
Value(double value);
- Value(const char* value);
- Value(const char* beginValue, const char* endValue);
+ Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
+ Value(const char* begin, const char* end); ///< Copy all, incl zeroes.
/** \brief Constructs a value from a static string.
* Like other value string constructor but do not duplicate the string for
* internal storage. The given string must remain alive after the call to this
* constructor.
+ * \note This works only for null-terminated strings. (We cannot change the
+ * size of this class, so we have nowhere to store the length,
+ * which might be computed later for various operations.)
+ *
* Example of usage:
* \code
- * Json::Value aValue( StaticString("some text") );
+ * static StaticString foo("some text");
+ * Json::Value aValue(foo);
* \endcode
*/
Value(const StaticString& value);
- Value(const std::string& value);
+ Value(const JSONCPP_STRING& value); ///< Copy data() til size(). Embedded zeroes too.
#ifdef JSON_USE_CPPTL
Value(const CppTL::ConstString& value);
#endif
Value(bool value);
+ /// Deep copy.
Value(const Value& other);
+#if JSON_HAS_RVALUE_REFERENCES
+ /// Move constructor
+ Value(Value&& other);
+#endif
~Value();
+ /// Deep copy, then swap(other).
+ /// \note Over-write existing comments. To preserve comments, use #swapPayload().
Value& operator=(Value other);
- /// Swap values.
- /// \note Currently, comments are intentionally not swapped, for
- /// both logic and efficiency.
+
+ /// Swap everything.
void swap(Value& other);
+ /// Swap values but leave comments and source offsets in place.
+ void swapPayload(Value& other);
+
+ /// copy everything.
+ void copy(const Value& other);
+ /// copy values but leave comments and source offsets in place.
+ void copyPayload(const Value& other);
ValueType type() const;
+ /// Compare payload only, not comments etc.
bool operator<(const Value& other) const;
bool operator<=(const Value& other) const;
bool operator>=(const Value& other) const;
bool operator>(const Value& other) const;
-
bool operator==(const Value& other) const;
bool operator!=(const Value& other) const;
-
int compare(const Value& other) const;
- const char* asCString() const;
- std::string asString() const;
+ const char* asCString() const; ///< Embedded zeroes could cause you trouble!
+#if JSONCPP_USING_SECURE_MEMORY
+ unsigned getCStringLength() const; //Allows you to understand the length of the CString
+#endif
+ JSONCPP_STRING asString() const; ///< Embedded zeroes are possible.
+ /** Get raw char* of string-value.
+ * \return false if !string. (Seg-fault if str or end are NULL.)
+ */
+ bool getString(
+ char const** begin, char const** end) const;
#ifdef JSON_USE_CPPTL
CppTL::ConstString asConstString() const;
#endif
@@ -347,20 +451,28 @@ Json::Value obj_value(Json::objectValue); // {}
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
Value& append(const Value& value);
+#if JSON_HAS_RVALUE_REFERENCES
+ Value& append(Value&& value);
+#endif
+
/// Access an object value by name, create a null member if it does not exist.
+ /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
+ /// Exceeding that will cause an exception.
Value& operator[](const char* key);
/// Access an object value by name, returns null if there is no member with
/// that name.
const Value& operator[](const char* key) const;
/// Access an object value by name, create a null member if it does not exist.
- Value& operator[](const std::string& key);
+ /// \param key may contain embedded nulls.
+ Value& operator[](const JSONCPP_STRING& key);
/// Access an object value by name, returns null if there is no member with
/// that name.
- const Value& operator[](const std::string& key) const;
+ /// \param key may contain embedded nulls.
+ const Value& operator[](const JSONCPP_STRING& key) const;
/** \brief Access an object value by name, create a null member if it does not
exist.
- * If the object as no entry for that name, then the member name used to store
+ * If the object has no entry for that name, then the member name used to store
* the new entry is not duplicated.
* Example of use:
* \code
@@ -378,27 +490,71 @@ Json::Value obj_value(Json::objectValue); // {}
const Value& operator[](const CppTL::ConstString& key) const;
#endif
/// Return the member named key if it exist, defaultValue otherwise.
+ /// \note deep copy
Value get(const char* key, const Value& defaultValue) const;
/// Return the member named key if it exist, defaultValue otherwise.
- Value get(const std::string& key, const Value& defaultValue) const;
+ /// \note deep copy
+ /// \note key may contain embedded nulls.
+ Value get(const char* begin, const char* end, const Value& defaultValue) const;
+ /// Return the member named key if it exist, defaultValue otherwise.
+ /// \note deep copy
+ /// \param key may contain embedded nulls.
+ Value get(const JSONCPP_STRING& key, const Value& defaultValue) const;
#ifdef JSON_USE_CPPTL
/// Return the member named key if it exist, defaultValue otherwise.
+ /// \note deep copy
Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
#endif
+ /// Most general and efficient version of isMember()const, get()const,
+ /// and operator[]const
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
+ Value const* find(char const* begin, char const* end) const;
+ /// Most general and efficient version of object-mutators.
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
+ /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
+ Value const* demand(char const* begin, char const* end);
/// \brief Remove and return the named member.
///
/// Do nothing if it did not exist.
/// \return the removed Value, or null.
/// \pre type() is objectValue or nullValue
/// \post type() is unchanged
+ /// deprecated
+ JSONCPP_DEPRECATED("")
Value removeMember(const char* key);
/// Same as removeMember(const char*)
- Value removeMember(const std::string& key);
+ /// \param key may contain embedded nulls.
+ /// deprecated
+ JSONCPP_DEPRECATED("")
+ Value removeMember(const JSONCPP_STRING& key);
+ /// Same as removeMember(const char* begin, const char* end, Value* removed),
+ /// but 'key' is null-terminated.
+ bool removeMember(const char* key, Value* removed);
+ /** \brief Remove the named map member.
+
+ Update 'removed' iff removed.
+ \param key may contain embedded nulls.
+ \return true iff removed (no exceptions)
+ */
+ bool removeMember(JSONCPP_STRING const& key, Value* removed);
+ /// Same as removeMember(JSONCPP_STRING const& key, Value* removed)
+ bool removeMember(const char* begin, const char* end, Value* removed);
+ /** \brief Remove the indexed array element.
+
+ O(n) expensive operations.
+ Update 'removed' iff removed.
+ \return true iff removed (no exceptions)
+ */
+ bool removeIndex(ArrayIndex i, Value* removed);
/// Return true if the object has a member named key.
+ /// \note 'key' must be null-terminated.
bool isMember(const char* key) const;
/// Return true if the object has a member named key.
- bool isMember(const std::string& key) const;
+ /// \param key may contain embedded nulls.
+ bool isMember(const JSONCPP_STRING& key) const;
+ /// Same as isMember(JSONCPP_STRING const& key)const
+ bool isMember(const char* begin, const char* end) const;
#ifdef JSON_USE_CPPTL
/// Return true if the object has a member named key.
bool isMember(const CppTL::ConstString& key) const;
@@ -416,15 +572,18 @@ Json::Value obj_value(Json::objectValue); // {}
// EnumValues enumValues() const;
//# endif
- /// Comments must be //... or /* ... */
+ /// deprecated Always pass len.
+ JSONCPP_DEPRECATED("Use setComment(JSONCPP_STRING const&) instead.")
void setComment(const char* comment, CommentPlacement placement);
/// Comments must be //... or /* ... */
- void setComment(const std::string& comment, CommentPlacement placement);
+ void setComment(const char* comment, size_t len, CommentPlacement placement);
+ /// Comments must be //... or /* ... */
+ void setComment(const JSONCPP_STRING& comment, CommentPlacement placement);
bool hasComment(CommentPlacement placement) const;
/// Include delimiters and embedded newlines.
- std::string getComment(CommentPlacement placement) const;
+ JSONCPP_STRING getComment(CommentPlacement placement) const;
- std::string toStyledString() const;
+ JSONCPP_STRING toStyledString() const;
const_iterator begin() const;
const_iterator end() const;
@@ -434,34 +593,22 @@ Json::Value obj_value(Json::objectValue); // {}
// Accessors for the [start, limit) range of bytes within the JSON text from
// which this value was parsed, if any.
- void setOffsetStart(size_t start);
- void setOffsetLimit(size_t limit);
- size_t getOffsetStart() const;
- size_t getOffsetLimit() const;
+ void setOffsetStart(ptrdiff_t start);
+ void setOffsetLimit(ptrdiff_t limit);
+ ptrdiff_t getOffsetStart() const;
+ ptrdiff_t getOffsetLimit() const;
private:
void initBasic(ValueType type, bool allocated = false);
- Value& resolveReference(const char* key, bool isStatic);
-
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- inline bool isItemAvailable() const { return itemIsUsed_ == 0; }
+ Value& resolveReference(const char* key);
+ Value& resolveReference(const char* key, const char* end);
- inline void setItemUsed(bool isUsed = true) { itemIsUsed_ = isUsed ? 1 : 0; }
-
- inline bool isMemberNameStatic() const { return memberNameIsStatic_ == 0; }
-
- inline void setMemberNameIsStatic(bool isStatic) {
- memberNameIsStatic_ = isStatic ? 1 : 0;
- }
-#endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
-
-private:
struct CommentInfo {
CommentInfo();
~CommentInfo();
- void setComment(const char* text);
+ void setComment(const char* text, size_t len);
char* comment_;
};
@@ -480,26 +627,18 @@ private:
LargestUInt uint_;
double real_;
bool bool_;
- char* string_;
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- ValueInternalArray* array_;
- ValueInternalMap* map_;
-#else
+ char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
ObjectValues* map_;
-#endif
} value_;
ValueType type_ : 8;
- int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- unsigned int itemIsUsed_ : 1; // used by the ValueInternalMap container.
- int memberNameIsStatic_ : 1; // used by the ValueInternalMap container.
-#endif
+ unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
+ // If not allocated_, string_ must be null-terminated.
CommentInfo* comments_;
// [start, limit) byte offsets in the source JSON text from which this Value
// was extracted.
- size_t start_;
- size_t limit_;
+ ptrdiff_t start_;
+ ptrdiff_t limit_;
};
/** \brief Experimental and untested: represents an element of the "path" to
@@ -512,7 +651,7 @@ public:
PathArgument();
PathArgument(ArrayIndex index);
PathArgument(const char* key);
- PathArgument(const std::string& key);
+ PathArgument(const JSONCPP_STRING& key);
private:
enum Kind {
@@ -520,7 +659,7 @@ private:
kindIndex,
kindKey
};
- std::string key_;
+ JSONCPP_STRING key_;
ArrayIndex index_;
Kind kind_;
};
@@ -538,7 +677,7 @@ private:
*/
class JSON_API Path {
public:
- Path(const std::string& path,
+ Path(const JSONCPP_STRING& path,
const PathArgument& a1 = PathArgument(),
const PathArgument& a2 = PathArgument(),
const PathArgument& a3 = PathArgument(),
@@ -555,355 +694,16 @@ private:
typedef std::vector<const PathArgument*> InArgs;
typedef std::vector<PathArgument> Args;
- void makePath(const std::string& path, const InArgs& in);
- void addPathInArg(const std::string& path,
+ void makePath(const JSONCPP_STRING& path, const InArgs& in);
+ void addPathInArg(const JSONCPP_STRING& path,
const InArgs& in,
InArgs::const_iterator& itInArg,
PathArgument::Kind kind);
- void invalidPath(const std::string& path, int location);
+ void invalidPath(const JSONCPP_STRING& path, int location);
Args args_;
};
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
-/** \brief Allocator to customize Value internal map.
- * Below is an example of a simple implementation (default implementation
- actually
- * use memory pool for speed).
- * \code
- class DefaultValueMapAllocator : public ValueMapAllocator
- {
- public: // overridden from ValueMapAllocator
- virtual ValueInternalMap *newMap()
- {
- return new ValueInternalMap();
- }
-
- virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other )
- {
- return new ValueInternalMap( other );
- }
-
- virtual void destructMap( ValueInternalMap *map )
- {
- delete map;
- }
-
- virtual ValueInternalLink *allocateMapBuckets( unsigned int size )
- {
- return new ValueInternalLink[size];
- }
-
- virtual void releaseMapBuckets( ValueInternalLink *links )
- {
- delete [] links;
- }
-
- virtual ValueInternalLink *allocateMapLink()
- {
- return new ValueInternalLink();
- }
-
- virtual void releaseMapLink( ValueInternalLink *link )
- {
- delete link;
- }
- };
- * \endcode
- */
-class JSON_API ValueMapAllocator {
-public:
- virtual ~ValueMapAllocator();
- virtual ValueInternalMap* newMap() = 0;
- virtual ValueInternalMap* newMapCopy(const ValueInternalMap& other) = 0;
- virtual void destructMap(ValueInternalMap* map) = 0;
- virtual ValueInternalLink* allocateMapBuckets(unsigned int size) = 0;
- virtual void releaseMapBuckets(ValueInternalLink* links) = 0;
- virtual ValueInternalLink* allocateMapLink() = 0;
- virtual void releaseMapLink(ValueInternalLink* link) = 0;
-};
-
-/** \brief ValueInternalMap hash-map bucket chain link (for internal use only).
- * \internal previous_ & next_ allows for bidirectional traversal.
- */
-class JSON_API ValueInternalLink {
-public:
- enum {
- itemPerLink = 6
- }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
- enum InternalFlags {
- flagAvailable = 0,
- flagUsed = 1
- };
-
- ValueInternalLink();
-
- ~ValueInternalLink();
-
- Value items_[itemPerLink];
- char* keys_[itemPerLink];
- ValueInternalLink* previous_;
- ValueInternalLink* next_;
-};
-
-/** \brief A linked page based hash-table implementation used internally by
- *Value.
- * \internal ValueInternalMap is a tradional bucket based hash-table, with a
- *linked
- * list in each bucket to handle collision. There is an addional twist in that
- * each node of the collision linked list is a page containing a fixed amount of
- * value. This provides a better compromise between memory usage and speed.
- *
- * Each bucket is made up of a chained list of ValueInternalLink. The last
- * link of a given bucket can be found in the 'previous_' field of the following
- *bucket.
- * The last link of the last bucket is stored in tailLink_ as it has no
- *following bucket.
- * Only the last link of a bucket may contains 'available' item. The last link
- *always
- * contains at least one element unless is it the bucket one very first link.
- */
-class JSON_API ValueInternalMap {
- friend class ValueIteratorBase;
- friend class Value;
-
-public:
- typedef unsigned int HashKey;
- typedef unsigned int BucketIndex;
-
-#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
- struct IteratorState {
- IteratorState() : map_(0), link_(0), itemIndex_(0), bucketIndex_(0) {}
- ValueInternalMap* map_;
- ValueInternalLink* link_;
- BucketIndex itemIndex_;
- BucketIndex bucketIndex_;
- };
-#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
-
- ValueInternalMap();
- ValueInternalMap(const ValueInternalMap& other);
- ValueInternalMap& operator=(ValueInternalMap other);
- ~ValueInternalMap();
-
- void swap(ValueInternalMap& other);
-
- BucketIndex size() const;
-
- void clear();
-
- bool reserveDelta(BucketIndex growth);
-
- bool reserve(BucketIndex newItemCount);
-
- const Value* find(const char* key) const;
-
- Value* find(const char* key);
-
- Value& resolveReference(const char* key, bool isStatic);
-
- void remove(const char* key);
-
- void doActualRemove(ValueInternalLink* link,
- BucketIndex index,
- BucketIndex bucketIndex);
-
- ValueInternalLink*& getLastLinkInBucket(BucketIndex bucketIndex);
-
- Value& setNewItem(const char* key,
- bool isStatic,
- ValueInternalLink* link,
- BucketIndex index);
-
- Value& unsafeAdd(const char* key, bool isStatic, HashKey hashedKey);
-
- HashKey hash(const char* key) const;
-
- int compare(const ValueInternalMap& other) const;
-
-private:
- void makeBeginIterator(IteratorState& it) const;
- void makeEndIterator(IteratorState& it) const;
- static bool equals(const IteratorState& x, const IteratorState& other);
- static void increment(IteratorState& iterator);
- static void incrementBucket(IteratorState& iterator);
- static void decrement(IteratorState& iterator);
- static const char* key(const IteratorState& iterator);
- static const char* key(const IteratorState& iterator, bool& isStatic);
- static Value& value(const IteratorState& iterator);
- static int distance(const IteratorState& x, const IteratorState& y);
-
-private:
- ValueInternalLink* buckets_;
- ValueInternalLink* tailLink_;
- BucketIndex bucketsSize_;
- BucketIndex itemCount_;
-};
-
-/** \brief A simplified deque implementation used internally by Value.
-* \internal
-* It is based on a list of fixed "page", each page contains a fixed number of
-*items.
-* Instead of using a linked-list, a array of pointer is used for fast item
-*look-up.
-* Look-up for an element is as follow:
-* - compute page index: pageIndex = itemIndex / itemsPerPage
-* - look-up item in page: pages_[pageIndex][itemIndex % itemsPerPage]
-*
-* Insertion is amortized constant time (only the array containing the index of
-*pointers
-* need to be reallocated when items are appended).
-*/
-class JSON_API ValueInternalArray {
- friend class Value;
- friend class ValueIteratorBase;
-
-public:
- enum {
- itemsPerPage = 8
- }; // should be a power of 2 for fast divide and modulo.
- typedef Value::ArrayIndex ArrayIndex;
- typedef unsigned int PageIndex;
-
-#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
- struct IteratorState // Must be a POD
- {
- IteratorState() : array_(0), currentPageIndex_(0), currentItemIndex_(0) {}
- ValueInternalArray* array_;
- Value** currentPageIndex_;
- unsigned int currentItemIndex_;
- };
-#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
-
- ValueInternalArray();
- ValueInternalArray(const ValueInternalArray& other);
- ValueInternalArray& operator=(ValueInternalArray other);
- ~ValueInternalArray();
- void swap(ValueInternalArray& other);
-
- void clear();
- void resize(ArrayIndex newSize);
-
- Value& resolveReference(ArrayIndex index);
-
- Value* find(ArrayIndex index) const;
-
- ArrayIndex size() const;
-
- int compare(const ValueInternalArray& other) const;
-
-private:
- static bool equals(const IteratorState& x, const IteratorState& other);
- static void increment(IteratorState& iterator);
- static void decrement(IteratorState& iterator);
- static Value& dereference(const IteratorState& iterator);
- static Value& unsafeDereference(const IteratorState& iterator);
- static int distance(const IteratorState& x, const IteratorState& y);
- static ArrayIndex indexOf(const IteratorState& iterator);
- void makeBeginIterator(IteratorState& it) const;
- void makeEndIterator(IteratorState& it) const;
- void makeIterator(IteratorState& it, ArrayIndex index) const;
-
- void makeIndexValid(ArrayIndex index);
-
- Value** pages_;
- ArrayIndex size_;
- PageIndex pageCount_;
-};
-
-/** \brief Experimental: do not use. Allocator to customize Value internal
-array.
- * Below is an example of a simple implementation (actual implementation use
- * memory pool).
- \code
-class DefaultValueArrayAllocator : public ValueArrayAllocator
-{
-public: // overridden from ValueArrayAllocator
-virtual ~DefaultValueArrayAllocator()
-{
-}
-
-virtual ValueInternalArray *newArray()
-{
- return new ValueInternalArray();
-}
-
-virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other )
-{
- return new ValueInternalArray( other );
-}
-
-virtual void destruct( ValueInternalArray *array )
-{
- delete array;
-}
-
-virtual void reallocateArrayPageIndex( Value **&indexes,
- ValueInternalArray::PageIndex
-&indexCount,
- ValueInternalArray::PageIndex
-minNewIndexCount )
-{
- ValueInternalArray::PageIndex newIndexCount = (indexCount*3)/2 + 1;
- if ( minNewIndexCount > newIndexCount )
- newIndexCount = minNewIndexCount;
- void *newIndexes = realloc( indexes, sizeof(Value*) * newIndexCount );
- if ( !newIndexes )
- throw std::bad_alloc();
- indexCount = newIndexCount;
- indexes = static_cast<Value **>( newIndexes );
-}
-virtual void releaseArrayPageIndex( Value **indexes,
- ValueInternalArray::PageIndex indexCount )
-{
- if ( indexes )
- free( indexes );
-}
-
-virtual Value *allocateArrayPage()
-{
- return static_cast<Value *>( malloc( sizeof(Value) *
-ValueInternalArray::itemsPerPage ) );
-}
-
-virtual void releaseArrayPage( Value *value )
-{
- if ( value )
- free( value );
-}
-};
- \endcode
- */
-class JSON_API ValueArrayAllocator {
-public:
- virtual ~ValueArrayAllocator();
- virtual ValueInternalArray* newArray() = 0;
- virtual ValueInternalArray* newArrayCopy(const ValueInternalArray& other) = 0;
- virtual void destructArray(ValueInternalArray* array) = 0;
- /** \brief Reallocate array page index.
- * Reallocates an array of pointer on each page.
- * \param indexes [input] pointer on the current index. May be \c NULL.
- * [output] pointer on the new index of at least
- * \a minNewIndexCount pages.
- * \param indexCount [input] current number of pages in the index.
- * [output] number of page the reallocated index can handle.
- * \b MUST be >= \a minNewIndexCount.
- * \param minNewIndexCount Minimum number of page the new index must be able
- * to
- * handle.
- */
- virtual void
- reallocateArrayPageIndex(Value**& indexes,
- ValueInternalArray::PageIndex& indexCount,
- ValueInternalArray::PageIndex minNewIndexCount) = 0;
- virtual void
- releaseArrayPageIndex(Value** indexes,
- ValueInternalArray::PageIndex indexCount) = 0;
- virtual Value* allocateArrayPage() = 0;
- virtual void releaseArrayPage(Value* value) = 0;
-};
-#endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
-
/** \brief base class for Value iterators.
*
*/
@@ -914,32 +714,35 @@ public:
typedef int difference_type;
typedef ValueIteratorBase SelfType;
- ValueIteratorBase();
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
- explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
-#else
- ValueIteratorBase(const ValueInternalArray::IteratorState& state);
- ValueIteratorBase(const ValueInternalMap::IteratorState& state);
-#endif
-
bool operator==(const SelfType& other) const { return isEqual(other); }
bool operator!=(const SelfType& other) const { return !isEqual(other); }
difference_type operator-(const SelfType& other) const {
- return computeDistance(other);
+ return other.computeDistance(*this);
}
/// Return either the index or the member name of the referenced value as a
/// Value.
Value key() const;
- /// Return the index of the referenced Value. -1 if it is not an arrayValue.
+ /// Return the index of the referenced Value, or -1 if it is not an arrayValue.
UInt index() const;
+ /// Return the member name of the referenced Value, or "" if it is not an
+ /// objectValue.
+ /// \note Avoid `c_str()` on result, as embedded zeroes are possible.
+ JSONCPP_STRING name() const;
+
/// Return the member name of the referenced Value. "" if it is not an
/// objectValue.
- const char* memberName() const;
+ /// deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
+ JSONCPP_DEPRECATED("Use `key = name();` instead.")
+ char const* memberName() const;
+ /// Return the member name of the referenced Value, or NULL if it is not an
+ /// objectValue.
+ /// \note Better version than memberName(). Allows embedded nulls.
+ char const* memberName(char const** end) const;
protected:
Value& deref() const;
@@ -955,17 +758,15 @@ protected:
void copy(const SelfType& other);
private:
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
Value::ObjectValues::iterator current_;
// Indicates that iterator is for a null value.
bool isNull_;
-#else
- union {
- ValueInternalArray::IteratorState array_;
- ValueInternalMap::IteratorState map_;
- } iterator_;
- bool isArray_;
-#endif
+
+public:
+ // For some reason, BORLAND needs these at the end, rather
+ // than earlier. No idea why.
+ ValueIteratorBase();
+ explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
};
/** \brief const iterator for object and array value.
@@ -976,23 +777,19 @@ class JSON_API ValueConstIterator : public ValueIteratorBase {
public:
typedef const Value value_type;
- typedef unsigned int size_t;
- typedef int difference_type;
+ //typedef unsigned int size_t;
+ //typedef int difference_type;
typedef const Value& reference;
typedef const Value* pointer;
typedef ValueConstIterator SelfType;
ValueConstIterator();
+ ValueConstIterator(ValueIterator const& other);
private:
-/*! \internal Use by Value to create an iterator.
+/*! internal Use by Value to create an iterator.
*/
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
-#else
- ValueConstIterator(const ValueInternalArray::IteratorState& state);
- ValueConstIterator(const ValueInternalMap::IteratorState& state);
-#endif
public:
SelfType& operator=(const ValueIteratorBase& other);
@@ -1037,18 +834,13 @@ public:
typedef ValueIterator SelfType;
ValueIterator();
- ValueIterator(const ValueConstIterator& other);
+ explicit ValueIterator(const ValueConstIterator& other);
ValueIterator(const ValueIterator& other);
private:
-/*! \internal Use by Value to create an iterator.
+/*! internal Use by Value to create an iterator.
*/
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
explicit ValueIterator(const Value::ObjectValues::iterator& current);
-#else
- ValueIterator(const ValueInternalArray::IteratorState& state);
- ValueIterator(const ValueInternalMap::IteratorState& state);
-#endif
public:
SelfType& operator=(const SelfType& other);
@@ -1081,6 +873,17 @@ public:
} // namespace Json
+
+namespace std {
+/// Specialize std::swap() for Json::Value.
+template<>
+inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
+}
+
+#if !defined(__SUNPRO_CC)
+#pragma pack(pop)
+#endif
+
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(pop)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
diff --git a/Utilities/cmjsoncpp/include/json/version.h b/Utilities/cmjsoncpp/include/json/version.h
index 6fe06824d..d95396189 100644
--- a/Utilities/cmjsoncpp/include/json/version.h
+++ b/Utilities/cmjsoncpp/include/json/version.h
@@ -1,14 +1,20 @@
-// DO NOT EDIT. This file is generated by CMake from "version"
-// and "version.h.in" files.
+// DO NOT EDIT. This file (and "version") is generated by CMake.
// Run CMake configure step to update it.
#ifndef JSON_VERSION_H_INCLUDED
# define JSON_VERSION_H_INCLUDED
-# define JSONCPP_VERSION_STRING "1.0.0"
+# define JSONCPP_VERSION_STRING "1.8.2"
# define JSONCPP_VERSION_MAJOR 1
-# define JSONCPP_VERSION_MINOR 0
-# define JSONCPP_VERSION_PATCH 0
+# define JSONCPP_VERSION_MINOR 8
+# define JSONCPP_VERSION_PATCH 2
# define JSONCPP_VERSION_QUALIFIER
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
+#ifdef JSONCPP_USING_SECURE_MEMORY
+#undef JSONCPP_USING_SECURE_MEMORY
+#endif
+#define JSONCPP_USING_SECURE_MEMORY 0
+// If non-zero, the library zeroes any memory that it has allocated before
+// it frees its memory.
+
#endif // JSON_VERSION_H_INCLUDED
diff --git a/Utilities/cmjsoncpp/include/json/writer.h b/Utilities/cmjsoncpp/include/json/writer.h
index 10863b078..d3ae62b28 100644
--- a/Utilities/cmjsoncpp/include/json/writer.h
+++ b/Utilities/cmjsoncpp/include/json/writer.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -12,6 +12,7 @@
#include <iosfwd>
#include <vector>
#include <string>
+#include <ostream>
// Disable warning C4251: <data member>: <type> needs to have dll-interface to
// be used by...
@@ -20,17 +21,133 @@
#pragma warning(disable : 4251)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#if !defined(__SUNPRO_CC)
+#pragma pack(push, 8)
+#endif
+
namespace Json {
class Value;
+/**
+
+Usage:
+\code
+ using namespace Json;
+ void writeToStdout(StreamWriter::Factory const& factory, Value const& value) {
+ std::unique_ptr<StreamWriter> const writer(
+ factory.newStreamWriter());
+ writer->write(value, &std::cout);
+ std::cout << std::endl; // add lf and flush
+ }
+\endcode
+*/
+class JSON_API StreamWriter {
+protected:
+ JSONCPP_OSTREAM* sout_; // not owned; will not delete
+public:
+ StreamWriter();
+ virtual ~StreamWriter();
+ /** Write Value into document as configured in sub-class.
+ Do not take ownership of sout, but maintain a reference during function.
+ \pre sout != NULL
+ \return zero on success (For now, we always return zero, so check the stream instead.)
+ \throw std::exception possibly, depending on configuration
+ */
+ virtual int write(Value const& root, JSONCPP_OSTREAM* sout) = 0;
+
+ /** \brief A simple abstract factory.
+ */
+ class JSON_API Factory {
+ public:
+ virtual ~Factory();
+ /** \brief Allocate a CharReader via operator new().
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
+ */
+ virtual StreamWriter* newStreamWriter() const = 0;
+ }; // Factory
+}; // StreamWriter
+
+/** \brief Write into stringstream, then return string, for convenience.
+ * A StreamWriter will be created from the factory, used, and then deleted.
+ */
+JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory, Value const& root);
+
+
+/** \brief Build a StreamWriter implementation.
+
+Usage:
+\code
+ using namespace Json;
+ Value value = ...;
+ StreamWriterBuilder builder;
+ builder["commentStyle"] = "None";
+ builder["indentation"] = " "; // or whatever you like
+ std::unique_ptr<Json::StreamWriter> writer(
+ builder.newStreamWriter());
+ writer->write(value, &std::cout);
+ std::cout << std::endl; // add lf and flush
+\endcode
+*/
+class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
+public:
+ // Note: We use a Json::Value so that we can add data-members to this class
+ // without a major version bump.
+ /** Configuration of this builder.
+ Available settings (case-sensitive):
+ - "commentStyle": "None" or "All"
+ - "indentation": "<anything>"
+ - "enableYAMLCompatibility": false or true
+ - slightly change the whitespace around colons
+ - "dropNullPlaceholders": false or true
+ - Drop the "null" string from the writer's output for nullValues.
+ Strictly speaking, this is not valid JSON. But when the output is being
+ fed to a browser's Javascript, it makes for smaller output and the
+ browser can handle the output just fine.
+ - "useSpecialFloats": false or true
+ - If true, outputs non-finite floating point values in the following way:
+ NaN values as "NaN", positive infinity as "Infinity", and negative infinity
+ as "-Infinity".
+
+ You can examine 'settings_` yourself
+ to see the defaults. You can also write and read them just like any
+ JSON Value.
+ \sa setDefaults()
+ */
+ Json::Value settings_;
+
+ StreamWriterBuilder();
+ ~StreamWriterBuilder() JSONCPP_OVERRIDE;
+
+ /**
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
+ */
+ StreamWriter* newStreamWriter() const JSONCPP_OVERRIDE;
+
+ /** \return true if 'settings' are legal and consistent;
+ * otherwise, indicate bad settings via 'invalid'.
+ */
+ bool validate(Json::Value* invalid) const;
+ /** A simple way to update a specific setting.
+ */
+ Value& operator[](JSONCPP_STRING key);
+
+ /** Called by ctor, but you can use this to reset settings_.
+ * \pre 'settings' != NULL (but Json::null is fine)
+ * \remark Defaults:
+ * snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults
+ */
+ static void setDefaults(Json::Value* settings);
+};
+
/** \brief Abstract class for writers.
+ * deprecated Use StreamWriter. (And really, this is an implementation detail.)
*/
-class JSON_API Writer {
+class JSONCPP_DEPRECATED("Use StreamWriter instead") JSON_API Writer {
public:
virtual ~Writer();
- virtual std::string write(const Value& root) = 0;
+ virtual JSONCPP_STRING write(const Value& root) = 0;
};
/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format
@@ -40,11 +157,13 @@ public:
*consumption,
* but may be usefull to support feature such as RPC where bandwith is limited.
* \sa Reader, Value
+ * deprecated Use StreamWriterBuilder.
*/
-class JSON_API FastWriter : public Writer {
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API FastWriter : public Writer {
+
public:
FastWriter();
- virtual ~FastWriter() {}
+ ~FastWriter() JSONCPP_OVERRIDE {}
void enableYAMLCompatibility();
@@ -58,12 +177,12 @@ public:
void omitEndingLineFeed();
public: // overridden from Writer
- virtual std::string write(const Value& root);
+ JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;
private:
void writeValue(const Value& value);
- std::string document_;
+ JSONCPP_STRING document_;
bool yamlCompatiblityEnabled_;
bool dropNullPlaceholders_;
bool omitEndingLineFeed_;
@@ -91,40 +210,41 @@ private:
*#CommentPlacement.
*
* \sa Reader, Value, Value::setComment()
+ * deprecated Use StreamWriterBuilder.
*/
-class JSON_API StyledWriter : public Writer {
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledWriter : public Writer {
public:
StyledWriter();
- virtual ~StyledWriter() {}
+ ~StyledWriter() JSONCPP_OVERRIDE {}
public: // overridden from Writer
/** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
* \param root Value to serialize.
* \return String containing the JSON document that represents the root value.
*/
- virtual std::string write(const Value& root);
+ JSONCPP_STRING write(const Value& root) JSONCPP_OVERRIDE;
private:
void writeValue(const Value& value);
void writeArrayValue(const Value& value);
bool isMultineArray(const Value& value);
- void pushValue(const std::string& value);
+ void pushValue(const JSONCPP_STRING& value);
void writeIndent();
- void writeWithIndent(const std::string& value);
+ void writeWithIndent(const JSONCPP_STRING& value);
void indent();
void unindent();
void writeCommentBeforeValue(const Value& root);
void writeCommentAfterValueOnSameLine(const Value& root);
bool hasCommentForValue(const Value& value);
- static std::string normalizeEOL(const std::string& text);
+ static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
- typedef std::vector<std::string> ChildValues;
+ typedef std::vector<JSONCPP_STRING> ChildValues;
ChildValues childValues_;
- std::string document_;
- std::string indentString_;
- int rightMargin_;
- int indentSize_;
+ JSONCPP_STRING document_;
+ JSONCPP_STRING indentString_;
+ unsigned int rightMargin_;
+ unsigned int indentSize_;
bool addChildValues_;
};
@@ -151,10 +271,14 @@ private:
#CommentPlacement.
*
* \sa Reader, Value, Value::setComment()
+ * deprecated Use StreamWriterBuilder.
*/
-class JSON_API StyledStreamWriter {
+class JSONCPP_DEPRECATED("Use StreamWriterBuilder instead") JSON_API StyledStreamWriter {
public:
- StyledStreamWriter(std::string indentation = "\t");
+/**
+ * \param indentation Each level will be indented by this amount extra.
+ */
+ StyledStreamWriter(JSONCPP_STRING indentation = "\t");
~StyledStreamWriter() {}
public:
@@ -164,48 +288,53 @@ public:
* \note There is no point in deriving from Writer, since write() should not
* return a value.
*/
- void write(std::ostream& out, const Value& root);
+ void write(JSONCPP_OSTREAM& out, const Value& root);
private:
void writeValue(const Value& value);
void writeArrayValue(const Value& value);
bool isMultineArray(const Value& value);
- void pushValue(const std::string& value);
+ void pushValue(const JSONCPP_STRING& value);
void writeIndent();
- void writeWithIndent(const std::string& value);
+ void writeWithIndent(const JSONCPP_STRING& value);
void indent();
void unindent();
void writeCommentBeforeValue(const Value& root);
void writeCommentAfterValueOnSameLine(const Value& root);
bool hasCommentForValue(const Value& value);
- static std::string normalizeEOL(const std::string& text);
+ static JSONCPP_STRING normalizeEOL(const JSONCPP_STRING& text);
- typedef std::vector<std::string> ChildValues;
+ typedef std::vector<JSONCPP_STRING> ChildValues;
ChildValues childValues_;
- std::ostream* document_;
- std::string indentString_;
- int rightMargin_;
- std::string indentation_;
- bool addChildValues_;
+ JSONCPP_OSTREAM* document_;
+ JSONCPP_STRING indentString_;
+ unsigned int rightMargin_;
+ JSONCPP_STRING indentation_;
+ bool addChildValues_ : 1;
+ bool indented_ : 1;
};
#if defined(JSON_HAS_INT64)
-std::string JSON_API valueToString(Int value);
-std::string JSON_API valueToString(UInt value);
+JSONCPP_STRING JSON_API valueToString(Int value);
+JSONCPP_STRING JSON_API valueToString(UInt value);
#endif // if defined(JSON_HAS_INT64)
-std::string JSON_API valueToString(LargestInt value);
-std::string JSON_API valueToString(LargestUInt value);
-std::string JSON_API valueToString(double value);
-std::string JSON_API valueToString(bool value);
-std::string JSON_API valueToQuotedString(const char* value);
+JSONCPP_STRING JSON_API valueToString(LargestInt value);
+JSONCPP_STRING JSON_API valueToString(LargestUInt value);
+JSONCPP_STRING JSON_API valueToString(double value);
+JSONCPP_STRING JSON_API valueToString(bool value);
+JSONCPP_STRING JSON_API valueToQuotedString(const char* value);
/// \brief Output using the StyledStreamWriter.
/// \see Json::operator>>()
-JSON_API std::ostream& operator<<(std::ostream&, const Value& root);
+JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
} // namespace Json
+#if !defined(__SUNPRO_CC)
+#pragma pack(pop)
+#endif
+
#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
#pragma warning(pop)
#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
diff --git a/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp b/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp
index 7b338285c..6eeba0e65 100644
--- a/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp
+++ b/Utilities/cmjsoncpp/src/lib_json/json_reader.cpp
@@ -1,4 +1,5 @@
-// Copyright 2007-2011 Baptiste Lepilleur
+// Copyright 2007-2011 Baptiste Lepilleur and The JsonCpp Authors
+// Copyright (C) 2016 InfoTeCS JSC. All rights reserved.
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -14,18 +15,51 @@
#include <assert.h>
#include <string.h>
#include <istream>
-
-#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below
+#include <sstream>
+#include <memory>
+#include <set>
+#include <limits>
+
+#if defined(_MSC_VER)
+#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
+#define snprintf sprintf_s
+#elif _MSC_VER >= 1900 // VC++ 14.0 and above
+#define snprintf std::snprintf
+#else
#define snprintf _snprintf
#endif
+#elif defined(__ANDROID__) || defined(__QNXNTO__)
+#define snprintf snprintf
+#elif __cplusplus >= 201103L
+#if !defined(__MINGW32__) && !defined(__CYGWIN__)
+#define snprintf std::snprintf
+#endif
+#endif
+
+#if defined(__QNXNTO__)
+#define sscanf std::sscanf
+#endif
#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
// Disable warning about strdup being deprecated.
#pragma warning(disable : 4996)
#endif
+// Define JSONCPP_DEPRECATED_STACK_LIMIT as an appropriate integer at compile time to change the stack limit
+#if !defined(JSONCPP_DEPRECATED_STACK_LIMIT)
+#define JSONCPP_DEPRECATED_STACK_LIMIT 1000
+#endif
+
+static size_t const stackLimit_g = JSONCPP_DEPRECATED_STACK_LIMIT; // see readValue()
+
namespace Json {
+#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
+typedef std::unique_ptr<CharReader> CharReaderPtr;
+#else
+typedef std::auto_ptr<CharReader> CharReaderPtr;
+#endif
+
// Implementation of class Features
// ////////////////////////////////
@@ -47,24 +81,7 @@ Features Features::strictMode() {
// Implementation of class Reader
// ////////////////////////////////
-static inline bool in(Reader::Char c,
- Reader::Char c1,
- Reader::Char c2,
- Reader::Char c3,
- Reader::Char c4) {
- return c == c1 || c == c2 || c == c3 || c == c4;
-}
-
-static inline bool in(Reader::Char c,
- Reader::Char c1,
- Reader::Char c2,
- Reader::Char c3,
- Reader::Char c4,
- Reader::Char c5) {
- return c == c1 || c == c2 || c == c3 || c == c4 || c == c5;
-}
-
-static bool containsNewLine(Reader::Location begin, Reader::Location end) {
+bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) {
for (; begin < end; ++begin)
if (*begin == '\n' || *begin == '\r')
return true;
@@ -86,7 +103,7 @@ Reader::Reader(const Features& features)
bool
Reader::parse(const std::string& document, Value& root, bool collectComments) {
- document_ = document;
+ document_.assign(document.begin(), document.end());
const char* begin = document_.c_str();
const char* end = begin + document_.length();
return parse(begin, end, root, collectComments);
@@ -98,11 +115,11 @@ bool Reader::parse(std::istream& sin, Value& root, bool collectComments) {
// Those would allow streamed input from a file, if parse() were a
// template function.
- // Since std::string is reference-counted, this at least does not
+ // Since JSONCPP_STRING is reference-counted, this at least does not
// create an extra copy.
- std::string doc;
+ JSONCPP_STRING doc;
std::getline(sin, doc, (char)EOF);
- return parse(doc, root, collectComments);
+ return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
}
bool Reader::parse(const char* beginDoc,
@@ -119,7 +136,7 @@ bool Reader::parse(const char* beginDoc,
current_ = begin_;
lastValueEnd_ = 0;
lastValue_ = 0;
- commentsBefore_ = "";
+ commentsBefore_.clear();
errors_.clear();
while (!nodes_.empty())
nodes_.pop();
@@ -147,21 +164,18 @@ bool Reader::parse(const char* beginDoc,
}
bool Reader::readValue() {
+ // readValue() may call itself only if it calls readObject() or ReadArray().
+ // These methods execute nodes_.push() just before and nodes_.pop)() just after calling readValue().
+ // parse() executes one nodes_.push(), so > instead of >=.
+ if (nodes_.size() > stackLimit_g) throwRuntimeError("Exceeded stackLimit in readValue().");
+
Token token;
skipCommentTokens(token);
bool successful = true;
if (collectComments_ && !commentsBefore_.empty()) {
- // Remove newline characters at the end of the comments
- size_t lastNonNewline = commentsBefore_.find_last_not_of("\r\n");
- if (lastNonNewline != std::string::npos) {
- commentsBefore_.erase(lastNonNewline + 1);
- } else {
- commentsBefore_.clear();
- }
-
currentValue().setComment(commentsBefore_, commentBefore);
- commentsBefore_ = "";
+ commentsBefore_.clear();
}
switch (token.type_) {
@@ -180,31 +194,42 @@ bool Reader::readValue() {
successful = decodeString(token);
break;
case tokenTrue:
- currentValue() = true;
+ {
+ Value v(true);
+ currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
+ }
break;
case tokenFalse:
- currentValue() = false;
+ {
+ Value v(false);
+ currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
+ }
break;
case tokenNull:
- currentValue() = Value();
+ {
+ Value v;
+ currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
+ }
break;
case tokenArraySeparator:
+ case tokenObjectEnd:
+ case tokenArrayEnd:
if (features_.allowDroppedNullPlaceholders_) {
// "Un-read" the current token and mark the current value as a null
// token.
current_--;
- currentValue() = Value();
+ Value v;
+ currentValue().swapPayload(v);
currentValue().setOffsetStart(current_ - begin_ - 1);
currentValue().setOffsetLimit(current_ - begin_);
break;
- }
- // Else, fall through...
+ } // Else, fall through...
default:
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
@@ -229,13 +254,6 @@ void Reader::skipCommentTokens(Token& token) {
}
}
-bool Reader::expectToken(TokenType type, Token& token, const char* message) {
- readToken(token);
- if (token.type_ != type)
- return addError(message, token);
- return true;
-}
-
bool Reader::readToken(Token& token) {
skipSpaces();
token.start_ = current_;
@@ -351,19 +369,39 @@ bool Reader::readComment() {
return true;
}
+JSONCPP_STRING Reader::normalizeEOL(Reader::Location begin, Reader::Location end) {
+ JSONCPP_STRING normalized;
+ normalized.reserve(static_cast<size_t>(end - begin));
+ Reader::Location current = begin;
+ while (current != end) {
+ char c = *current++;
+ if (c == '\r') {
+ if (current != end && *current == '\n')
+ // convert dos EOL
+ ++current;
+ // convert Mac EOL
+ normalized += '\n';
+ } else {
+ normalized += c;
+ }
+ }
+ return normalized;
+}
+
void
Reader::addComment(Location begin, Location end, CommentPlacement placement) {
assert(collectComments_);
+ const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) {
assert(lastValue_ != 0);
- lastValue_->setComment(std::string(begin, end), placement);
+ lastValue_->setComment(normalized, placement);
} else {
- commentsBefore_ += std::string(begin, end);
+ commentsBefore_ += normalized;
}
}
bool Reader::readCStyleComment() {
- while (current_ != end_) {
+ while ((current_ + 1) < end_) {
Char c = getNextChar();
if (c == '*' && *current_ == '/')
break;
@@ -374,23 +412,43 @@ bool Reader::readCStyleComment() {
bool Reader::readCppStyleComment() {
while (current_ != end_) {
Char c = getNextChar();
- if (c == '\r' || c == '\n')
+ if (c == '\n')
break;
+ if (c == '\r') {
+ // Consume DOS EOL. It will be normalized in addComment.
+ if (current_ != end_ && *current_ == '\n')
+ getNextChar();
+ // Break on Moc OS 9 EOL.
+ break;
+ }
}
return true;
}
void Reader::readNumber() {
- while (current_ != end_) {
- if (!(*current_ >= '0' && *current_ <= '9') &&
- !in(*current_, '.', 'e', 'E', '+', '-'))
- break;
- ++current_;
+ const char *p = current_;
+ char c = '0'; // stopgap for already consumed character
+ // integral part
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ // fractional part
+ if (c == '.') {
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ }
+ // exponential part
+ if (c == 'e' || c == 'E') {
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ if (c == '+' || c == '-')
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : '\0';
}
}
bool Reader::readString() {
- Char c = 0;
+ Char c = '\0';
while (current_ != end_) {
c = getNextChar();
if (c == '\\')
@@ -403,8 +461,9 @@ bool Reader::readString() {
bool Reader::readObject(Token& tokenStart) {
Token tokenName;
- std::string name;
- currentValue() = Value(objectValue);
+ JSONCPP_STRING name;
+ Value init(objectValue);
+ currentValue().swapPayload(init);
currentValue().setOffsetStart(tokenStart.start_ - begin_);
while (readToken(tokenName)) {
bool initialTokenOk = true;
@@ -414,7 +473,7 @@ bool Reader::readObject(Token& tokenStart) {
break;
if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
return true;
- name = "";
+ name.clear();
if (tokenName.type_ == tokenString) {
if (!decodeString(tokenName, name))
return recoverFromError(tokenObjectEnd);
@@ -422,7 +481,7 @@ bool Reader::readObject(Token& tokenStart) {
Value numberName;
if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd);
- name = numberName.asString();
+ name = JSONCPP_STRING(numberName.asCString());
} else {
break;
}
@@ -457,10 +516,11 @@ bool Reader::readObject(Token& tokenStart) {
}
bool Reader::readArray(Token& tokenStart) {
- currentValue() = Value(arrayValue);
+ Value init(arrayValue);
+ currentValue().swapPayload(init);
currentValue().setOffsetStart(tokenStart.start_ - begin_);
skipSpaces();
- if (*current_ == ']') // empty array
+ if (current_ != end_ && *current_ == ']') // empty array
{
Token endArray;
readToken(endArray);
@@ -497,20 +557,13 @@ bool Reader::decodeNumber(Token& token) {
Value decoded;
if (!decodeNumber(token, decoded))
return false;
- currentValue() = decoded;
+ currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
bool Reader::decodeNumber(Token& token, Value& decoded) {
- bool isDouble = false;
- for (Location inspect = token.start_; inspect != token.end_; ++inspect) {
- isDouble = isDouble || in(*inspect, '.', 'e', 'E', '+') ||
- (*inspect == '-' && inspect != token.start_);
- }
- if (isDouble)
- return decodeDouble(token, decoded);
// Attempts to parse the number as an integer. If the number is
// larger than the maximum supported value of an integer then
// we decode the number as a double.
@@ -518,17 +571,16 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
bool isNegative = *current == '-';
if (isNegative)
++current;
+ // TODO: Help the compiler do the div and mod at compile time or get rid of them.
Value::LargestUInt maxIntegerValue =
- isNegative ? Value::LargestUInt(-Value::minLargestInt)
+ isNegative ? Value::LargestUInt(Value::maxLargestInt) + 1
: Value::maxLargestUInt;
Value::LargestUInt threshold = maxIntegerValue / 10;
Value::LargestUInt value = 0;
while (current < token.end_) {
Char c = *current++;
if (c < '0' || c > '9')
- return addError("'" + std::string(token.start_, token.end_) +
- "' is not a number.",
- token);
+ return decodeDouble(token, decoded);
Value::UInt digit(static_cast<Value::UInt>(c - '0'));
if (value >= threshold) {
// We've hit or exceeded the max value divided by 10 (rounded down). If
@@ -542,7 +594,9 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
}
value = value * 10 + digit;
}
- if (isNegative)
+ if (isNegative && value == maxIntegerValue)
+ decoded = Value::minLargestInt;
+ else if (isNegative)
decoded = -Value::LargestInt(value);
else if (value <= Value::LargestUInt(Value::maxInt))
decoded = Value::LargestInt(value);
@@ -555,7 +609,7 @@ bool Reader::decodeDouble(Token& token) {
Value decoded;
if (!decodeDouble(token, decoded))
return false;
- currentValue() = decoded;
+ currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
@@ -563,14 +617,1021 @@ bool Reader::decodeDouble(Token& token) {
bool Reader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
+ JSONCPP_STRING buffer(token.start_, token.end_);
+ JSONCPP_ISTRINGSTREAM is(buffer);
+ if (!(is >> value))
+ return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
+ "' is not a number.",
+ token);
+ decoded = value;
+ return true;
+}
+
+bool Reader::decodeString(Token& token) {
+ JSONCPP_STRING decoded_string;
+ if (!decodeString(token, decoded_string))
+ return false;
+ Value decoded(decoded_string);
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool Reader::decodeString(Token& token, JSONCPP_STRING& decoded) {
+ decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
+ Location current = token.start_ + 1; // skip '"'
+ Location end = token.end_ - 1; // do not include '"'
+ while (current != end) {
+ Char c = *current++;
+ if (c == '"')
+ break;
+ else if (c == '\\') {
+ if (current == end)
+ return addError("Empty escape sequence in string", token, current);
+ Char escape = *current++;
+ switch (escape) {
+ case '"':
+ decoded += '"';
+ break;
+ case '/':
+ decoded += '/';
+ break;
+ case '\\':
+ decoded += '\\';
+ break;
+ case 'b':
+ decoded += '\b';
+ break;
+ case 'f':
+ decoded += '\f';
+ break;
+ case 'n':
+ decoded += '\n';
+ break;
+ case 'r':
+ decoded += '\r';
+ break;
+ case 't':
+ decoded += '\t';
+ break;
+ case 'u': {
+ unsigned int unicode;
+ if (!decodeUnicodeCodePoint(token, current, end, unicode))
+ return false;
+ decoded += codePointToUTF8(unicode);
+ } break;
+ default:
+ return addError("Bad escape sequence in string", token, current);
+ }
+ } else {
+ decoded += c;
+ }
+ }
+ return true;
+}
+
+bool Reader::decodeUnicodeCodePoint(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode) {
+
+ if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
+ return false;
+ if (unicode >= 0xD800 && unicode <= 0xDBFF) {
+ // surrogate pairs
+ if (end - current < 6)
+ return addError(
+ "additional six characters expected to parse unicode surrogate pair.",
+ token,
+ current);
+ unsigned int surrogatePair;
+ if (*(current++) == '\\' && *(current++) == 'u') {
+ if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) {
+ unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
+ } else
+ return false;
+ } else
+ return addError("expecting another \\u token to begin the second half of "
+ "a unicode surrogate pair",
+ token,
+ current);
+ }
+ return true;
+}
+
+bool Reader::decodeUnicodeEscapeSequence(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& ret_unicode) {
+ if (end - current < 4)
+ return addError(
+ "Bad unicode escape sequence in string: four digits expected.",
+ token,
+ current);
+ int unicode = 0;
+ for (int index = 0; index < 4; ++index) {
+ Char c = *current++;
+ unicode *= 16;
+ if (c >= '0' && c <= '9')
+ unicode += c - '0';
+ else if (c >= 'a' && c <= 'f')
+ unicode += c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ unicode += c - 'A' + 10;
+ else
+ return addError(
+ "Bad unicode escape sequence in string: hexadecimal digit expected.",
+ token,
+ current);
+ }
+ ret_unicode = static_cast<unsigned int>(unicode);
+ return true;
+}
+
+bool
+Reader::addError(const JSONCPP_STRING& message, Token& token, Location extra) {
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = extra;
+ errors_.push_back(info);
+ return false;
+}
+
+bool Reader::recoverFromError(TokenType skipUntilToken) {
+ size_t const errorCount = errors_.size();
+ Token skip;
+ for (;;) {
+ if (!readToken(skip))
+ errors_.resize(errorCount); // discard errors caused by recovery
+ if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream)
+ break;
+ }
+ errors_.resize(errorCount);
+ return false;
+}
+
+bool Reader::addErrorAndRecover(const JSONCPP_STRING& message,
+ Token& token,
+ TokenType skipUntilToken) {
+ addError(message, token);
+ return recoverFromError(skipUntilToken);
+}
+
+Value& Reader::currentValue() { return *(nodes_.top()); }
+
+Reader::Char Reader::getNextChar() {
+ if (current_ == end_)
+ return 0;
+ return *current_++;
+}
+
+void Reader::getLocationLineAndColumn(Location location,
+ int& line,
+ int& column) const {
+ Location current = begin_;
+ Location lastLineStart = current;
+ line = 0;
+ while (current < location && current != end_) {
+ Char c = *current++;
+ if (c == '\r') {
+ if (*current == '\n')
+ ++current;
+ lastLineStart = current;
+ ++line;
+ } else if (c == '\n') {
+ lastLineStart = current;
+ ++line;
+ }
+ }
+ // column & line start at 1
+ column = int(location - lastLineStart) + 1;
+ ++line;
+}
+
+JSONCPP_STRING Reader::getLocationLineAndColumn(Location location) const {
+ int line, column;
+ getLocationLineAndColumn(location, line, column);
+ char buffer[18 + 16 + 16 + 1];
+ snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
+ return buffer;
+}
+
+// Deprecated. Preserved for backward compatibility
+JSONCPP_STRING Reader::getFormatedErrorMessages() const {
+ return getFormattedErrorMessages();
+}
+
+JSONCPP_STRING Reader::getFormattedErrorMessages() const {
+ JSONCPP_STRING formattedMessage;
+ for (Errors::const_iterator itError = errors_.begin();
+ itError != errors_.end();
+ ++itError) {
+ const ErrorInfo& error = *itError;
+ formattedMessage +=
+ "* " + getLocationLineAndColumn(error.token_.start_) + "\n";
+ formattedMessage += " " + error.message_ + "\n";
+ if (error.extra_)
+ formattedMessage +=
+ "See " + getLocationLineAndColumn(error.extra_) + " for detail.\n";
+ }
+ return formattedMessage;
+}
+
+std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
+ std::vector<Reader::StructuredError> allErrors;
+ for (Errors::const_iterator itError = errors_.begin();
+ itError != errors_.end();
+ ++itError) {
+ const ErrorInfo& error = *itError;
+ Reader::StructuredError structured;
+ structured.offset_start = error.token_.start_ - begin_;
+ structured.offset_limit = error.token_.end_ - begin_;
+ structured.message = error.message_;
+ allErrors.push_back(structured);
+ }
+ return allErrors;
+}
+
+bool Reader::pushError(const Value& value, const JSONCPP_STRING& message) {
+ ptrdiff_t const length = end_ - begin_;
+ if(value.getOffsetStart() > length
+ || value.getOffsetLimit() > length)
+ return false;
+ Token token;
+ token.type_ = tokenError;
+ token.start_ = begin_ + value.getOffsetStart();
+ token.end_ = end_ + value.getOffsetLimit();
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = 0;
+ errors_.push_back(info);
+ return true;
+}
+
+bool Reader::pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra) {
+ ptrdiff_t const length = end_ - begin_;
+ if(value.getOffsetStart() > length
+ || value.getOffsetLimit() > length
+ || extra.getOffsetLimit() > length)
+ return false;
+ Token token;
+ token.type_ = tokenError;
+ token.start_ = begin_ + value.getOffsetStart();
+ token.end_ = begin_ + value.getOffsetLimit();
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = begin_ + extra.getOffsetStart();
+ errors_.push_back(info);
+ return true;
+}
+
+bool Reader::good() const {
+ return !errors_.size();
+}
+
+// exact copy of Features
+class OurFeatures {
+public:
+ static OurFeatures all();
+ bool allowComments_;
+ bool strictRoot_;
+ bool allowDroppedNullPlaceholders_;
+ bool allowNumericKeys_;
+ bool allowSingleQuotes_;
+ bool failIfExtra_;
+ bool rejectDupKeys_;
+ bool allowSpecialFloats_;
+ int stackLimit_;
+}; // OurFeatures
+
+// exact copy of Implementation of class Features
+// ////////////////////////////////
+
+OurFeatures OurFeatures::all() { return OurFeatures(); }
+
+// Implementation of class Reader
+// ////////////////////////////////
+
+// exact copy of Reader, renamed to OurReader
+class OurReader {
+public:
+ typedef char Char;
+ typedef const Char* Location;
+ struct StructuredError {
+ ptrdiff_t offset_start;
+ ptrdiff_t offset_limit;
+ JSONCPP_STRING message;
+ };
+
+ OurReader(OurFeatures const& features);
+ bool parse(const char* beginDoc,
+ const char* endDoc,
+ Value& root,
+ bool collectComments = true);
+ JSONCPP_STRING getFormattedErrorMessages() const;
+ std::vector<StructuredError> getStructuredErrors() const;
+ bool pushError(const Value& value, const JSONCPP_STRING& message);
+ bool pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra);
+ bool good() const;
+
+private:
+ OurReader(OurReader const&); // no impl
+ void operator=(OurReader const&); // no impl
+
+ enum TokenType {
+ tokenEndOfStream = 0,
+ tokenObjectBegin,
+ tokenObjectEnd,
+ tokenArrayBegin,
+ tokenArrayEnd,
+ tokenString,
+ tokenNumber,
+ tokenTrue,
+ tokenFalse,
+ tokenNull,
+ tokenNaN,
+ tokenPosInf,
+ tokenNegInf,
+ tokenArraySeparator,
+ tokenMemberSeparator,
+ tokenComment,
+ tokenError
+ };
+
+ class Token {
+ public:
+ TokenType type_;
+ Location start_;
+ Location end_;
+ };
+
+ class ErrorInfo {
+ public:
+ Token token_;
+ JSONCPP_STRING message_;
+ Location extra_;
+ };
+
+ typedef std::deque<ErrorInfo> Errors;
+
+ bool readToken(Token& token);
+ void skipSpaces();
+ bool match(Location pattern, int patternLength);
+ bool readComment();
+ bool readCStyleComment();
+ bool readCppStyleComment();
+ bool readString();
+ bool readStringSingleQuote();
+ bool readNumber(bool checkInf);
+ bool readValue();
+ bool readObject(Token& token);
+ bool readArray(Token& token);
+ bool decodeNumber(Token& token);
+ bool decodeNumber(Token& token, Value& decoded);
+ bool decodeString(Token& token);
+ bool decodeString(Token& token, JSONCPP_STRING& decoded);
+ bool decodeDouble(Token& token);
+ bool decodeDouble(Token& token, Value& decoded);
+ bool decodeUnicodeCodePoint(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode);
+ bool decodeUnicodeEscapeSequence(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode);
+ bool addError(const JSONCPP_STRING& message, Token& token, Location extra = 0);
+ bool recoverFromError(TokenType skipUntilToken);
+ bool addErrorAndRecover(const JSONCPP_STRING& message,
+ Token& token,
+ TokenType skipUntilToken);
+ void skipUntilSpace();
+ Value& currentValue();
+ Char getNextChar();
+ void
+ getLocationLineAndColumn(Location location, int& line, int& column) const;
+ JSONCPP_STRING getLocationLineAndColumn(Location location) const;
+ void addComment(Location begin, Location end, CommentPlacement placement);
+ void skipCommentTokens(Token& token);
+
+ static JSONCPP_STRING normalizeEOL(Location begin, Location end);
+ static bool containsNewLine(Location begin, Location end);
+
+ typedef std::stack<Value*> Nodes;
+ Nodes nodes_;
+ Errors errors_;
+ JSONCPP_STRING document_;
+ Location begin_;
+ Location end_;
+ Location current_;
+ Location lastValueEnd_;
+ Value* lastValue_;
+ JSONCPP_STRING commentsBefore_;
+
+ OurFeatures const features_;
+ bool collectComments_;
+}; // OurReader
+
+// complete copy of Read impl, for OurReader
+
+bool OurReader::containsNewLine(OurReader::Location begin, OurReader::Location end) {
+ for (; begin < end; ++begin)
+ if (*begin == '\n' || *begin == '\r')
+ return true;
+ return false;
+}
+
+OurReader::OurReader(OurFeatures const& features)
+ : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
+ lastValue_(), commentsBefore_(),
+ features_(features), collectComments_() {
+}
+
+bool OurReader::parse(const char* beginDoc,
+ const char* endDoc,
+ Value& root,
+ bool collectComments) {
+ if (!features_.allowComments_) {
+ collectComments = false;
+ }
+
+ begin_ = beginDoc;
+ end_ = endDoc;
+ collectComments_ = collectComments;
+ current_ = begin_;
+ lastValueEnd_ = 0;
+ lastValue_ = 0;
+ commentsBefore_.clear();
+ errors_.clear();
+ while (!nodes_.empty())
+ nodes_.pop();
+ nodes_.push(&root);
+
+ bool successful = readValue();
+ Token token;
+ skipCommentTokens(token);
+ if (features_.failIfExtra_) {
+ if ((features_.strictRoot_ || token.type_ != tokenError) && token.type_ != tokenEndOfStream) {
+ addError("Extra non-whitespace after JSON value.", token);
+ return false;
+ }
+ }
+ if (collectComments_ && !commentsBefore_.empty())
+ root.setComment(commentsBefore_, commentAfter);
+ if (features_.strictRoot_) {
+ if (!root.isArray() && !root.isObject()) {
+ // Set error location to start of doc, ideally should be first token found
+ // in doc
+ token.type_ = tokenError;
+ token.start_ = beginDoc;
+ token.end_ = endDoc;
+ addError(
+ "A valid JSON document must be either an array or an object value.",
+ token);
+ return false;
+ }
+ }
+ return successful;
+}
+
+bool OurReader::readValue() {
+ // To preserve the old behaviour we cast size_t to int.
+ if (static_cast<int>(nodes_.size()) > features_.stackLimit_) throwRuntimeError("Exceeded stackLimit in readValue().");
+ Token token;
+ skipCommentTokens(token);
+ bool successful = true;
+
+ if (collectComments_ && !commentsBefore_.empty()) {
+ currentValue().setComment(commentsBefore_, commentBefore);
+ commentsBefore_.clear();
+ }
+
+ switch (token.type_) {
+ case tokenObjectBegin:
+ successful = readObject(token);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ case tokenArrayBegin:
+ successful = readArray(token);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ case tokenNumber:
+ successful = decodeNumber(token);
+ break;
+ case tokenString:
+ successful = decodeString(token);
+ break;
+ case tokenTrue:
+ {
+ Value v(true);
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenFalse:
+ {
+ Value v(false);
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenNull:
+ {
+ Value v;
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenNaN:
+ {
+ Value v(std::numeric_limits<double>::quiet_NaN());
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenPosInf:
+ {
+ Value v(std::numeric_limits<double>::infinity());
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenNegInf:
+ {
+ Value v(-std::numeric_limits<double>::infinity());
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenArraySeparator:
+ case tokenObjectEnd:
+ case tokenArrayEnd:
+ if (features_.allowDroppedNullPlaceholders_) {
+ // "Un-read" the current token and mark the current value as a null
+ // token.
+ current_--;
+ Value v;
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(current_ - begin_ - 1);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ } // else, fall through ...
+ default:
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return addError("Syntax error: value, object or array expected.", token);
+ }
+
+ if (collectComments_) {
+ lastValueEnd_ = current_;
+ lastValue_ = &currentValue();
+ }
+
+ return successful;
+}
+
+void OurReader::skipCommentTokens(Token& token) {
+ if (features_.allowComments_) {
+ do {
+ readToken(token);
+ } while (token.type_ == tokenComment);
+ } else {
+ readToken(token);
+ }
+}
+
+bool OurReader::readToken(Token& token) {
+ skipSpaces();
+ token.start_ = current_;
+ Char c = getNextChar();
+ bool ok = true;
+ switch (c) {
+ case '{':
+ token.type_ = tokenObjectBegin;
+ break;
+ case '}':
+ token.type_ = tokenObjectEnd;
+ break;
+ case '[':
+ token.type_ = tokenArrayBegin;
+ break;
+ case ']':
+ token.type_ = tokenArrayEnd;
+ break;
+ case '"':
+ token.type_ = tokenString;
+ ok = readString();
+ break;
+ case '\'':
+ if (features_.allowSingleQuotes_) {
+ token.type_ = tokenString;
+ ok = readStringSingleQuote();
+ break;
+ } // else continue
+ case '/':
+ token.type_ = tokenComment;
+ ok = readComment();
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ token.type_ = tokenNumber;
+ readNumber(false);
+ break;
+ case '-':
+ if (readNumber(true)) {
+ token.type_ = tokenNumber;
+ } else {
+ token.type_ = tokenNegInf;
+ ok = features_.allowSpecialFloats_ && match("nfinity", 7);
+ }
+ break;
+ case 't':
+ token.type_ = tokenTrue;
+ ok = match("rue", 3);
+ break;
+ case 'f':
+ token.type_ = tokenFalse;
+ ok = match("alse", 4);
+ break;
+ case 'n':
+ token.type_ = tokenNull;
+ ok = match("ull", 3);
+ break;
+ case 'N':
+ if (features_.allowSpecialFloats_) {
+ token.type_ = tokenNaN;
+ ok = match("aN", 2);
+ } else {
+ ok = false;
+ }
+ break;
+ case 'I':
+ if (features_.allowSpecialFloats_) {
+ token.type_ = tokenPosInf;
+ ok = match("nfinity", 7);
+ } else {
+ ok = false;
+ }
+ break;
+ case ',':
+ token.type_ = tokenArraySeparator;
+ break;
+ case ':':
+ token.type_ = tokenMemberSeparator;
+ break;
+ case 0:
+ token.type_ = tokenEndOfStream;
+ break;
+ default:
+ ok = false;
+ break;
+ }
+ if (!ok)
+ token.type_ = tokenError;
+ token.end_ = current_;
+ return true;
+}
+
+void OurReader::skipSpaces() {
+ while (current_ != end_) {
+ Char c = *current_;
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
+ ++current_;
+ else
+ break;
+ }
+}
+
+bool OurReader::match(Location pattern, int patternLength) {
+ if (end_ - current_ < patternLength)
+ return false;
+ int index = patternLength;
+ while (index--)
+ if (current_[index] != pattern[index])
+ return false;
+ current_ += patternLength;
+ return true;
+}
+
+bool OurReader::readComment() {
+ Location commentBegin = current_ - 1;
+ Char c = getNextChar();
+ bool successful = false;
+ if (c == '*')
+ successful = readCStyleComment();
+ else if (c == '/')
+ successful = readCppStyleComment();
+ if (!successful)
+ return false;
+
+ if (collectComments_) {
+ CommentPlacement placement = commentBefore;
+ if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) {
+ if (c != '*' || !containsNewLine(commentBegin, current_))
+ placement = commentAfterOnSameLine;
+ }
+
+ addComment(commentBegin, current_, placement);
+ }
+ return true;
+}
+
+JSONCPP_STRING OurReader::normalizeEOL(OurReader::Location begin, OurReader::Location end) {
+ JSONCPP_STRING normalized;
+ normalized.reserve(static_cast<size_t>(end - begin));
+ OurReader::Location current = begin;
+ while (current != end) {
+ char c = *current++;
+ if (c == '\r') {
+ if (current != end && *current == '\n')
+ // convert dos EOL
+ ++current;
+ // convert Mac EOL
+ normalized += '\n';
+ } else {
+ normalized += c;
+ }
+ }
+ return normalized;
+}
+
+void
+OurReader::addComment(Location begin, Location end, CommentPlacement placement) {
+ assert(collectComments_);
+ const JSONCPP_STRING& normalized = normalizeEOL(begin, end);
+ if (placement == commentAfterOnSameLine) {
+ assert(lastValue_ != 0);
+ lastValue_->setComment(normalized, placement);
+ } else {
+ commentsBefore_ += normalized;
+ }
+}
+
+bool OurReader::readCStyleComment() {
+ while ((current_ + 1) < end_) {
+ Char c = getNextChar();
+ if (c == '*' && *current_ == '/')
+ break;
+ }
+ return getNextChar() == '/';
+}
+
+bool OurReader::readCppStyleComment() {
+ while (current_ != end_) {
+ Char c = getNextChar();
+ if (c == '\n')
+ break;
+ if (c == '\r') {
+ // Consume DOS EOL. It will be normalized in addComment.
+ if (current_ != end_ && *current_ == '\n')
+ getNextChar();
+ // Break on Moc OS 9 EOL.
+ break;
+ }
+ }
+ return true;
+}
+
+bool OurReader::readNumber(bool checkInf) {
+ const char *p = current_;
+ if (checkInf && p != end_ && *p == 'I') {
+ current_ = ++p;
+ return false;
+ }
+ char c = '0'; // stopgap for already consumed character
+ // integral part
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ // fractional part
+ if (c == '.') {
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ }
+ // exponential part
+ if (c == 'e' || c == 'E') {
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ if (c == '+' || c == '-')
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : '\0';
+ }
+ return true;
+}
+bool OurReader::readString() {
+ Char c = 0;
+ while (current_ != end_) {
+ c = getNextChar();
+ if (c == '\\')
+ getNextChar();
+ else if (c == '"')
+ break;
+ }
+ return c == '"';
+}
+
+
+bool OurReader::readStringSingleQuote() {
+ Char c = 0;
+ while (current_ != end_) {
+ c = getNextChar();
+ if (c == '\\')
+ getNextChar();
+ else if (c == '\'')
+ break;
+ }
+ return c == '\'';
+}
+
+bool OurReader::readObject(Token& tokenStart) {
+ Token tokenName;
+ JSONCPP_STRING name;
+ Value init(objectValue);
+ currentValue().swapPayload(init);
+ currentValue().setOffsetStart(tokenStart.start_ - begin_);
+ while (readToken(tokenName)) {
+ bool initialTokenOk = true;
+ while (tokenName.type_ == tokenComment && initialTokenOk)
+ initialTokenOk = readToken(tokenName);
+ if (!initialTokenOk)
+ break;
+ if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
+ return true;
+ name.clear();
+ if (tokenName.type_ == tokenString) {
+ if (!decodeString(tokenName, name))
+ return recoverFromError(tokenObjectEnd);
+ } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) {
+ Value numberName;
+ if (!decodeNumber(tokenName, numberName))
+ return recoverFromError(tokenObjectEnd);
+ name = numberName.asString();
+ } else {
+ break;
+ }
+
+ Token colon;
+ if (!readToken(colon) || colon.type_ != tokenMemberSeparator) {
+ return addErrorAndRecover(
+ "Missing ':' after object member name", colon, tokenObjectEnd);
+ }
+ if (name.length() >= (1U<<30)) throwRuntimeError("keylength >= 2^30");
+ if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
+ JSONCPP_STRING msg = "Duplicate key: '" + name + "'";
+ return addErrorAndRecover(
+ msg, tokenName, tokenObjectEnd);
+ }
+ Value& value = currentValue()[name];
+ nodes_.push(&value);
+ bool ok = readValue();
+ nodes_.pop();
+ if (!ok) // error already set
+ return recoverFromError(tokenObjectEnd);
+
+ Token comma;
+ if (!readToken(comma) ||
+ (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator &&
+ comma.type_ != tokenComment)) {
+ return addErrorAndRecover(
+ "Missing ',' or '}' in object declaration", comma, tokenObjectEnd);
+ }
+ bool finalizeTokenOk = true;
+ while (comma.type_ == tokenComment && finalizeTokenOk)
+ finalizeTokenOk = readToken(comma);
+ if (comma.type_ == tokenObjectEnd)
+ return true;
+ }
+ return addErrorAndRecover(
+ "Missing '}' or object member name", tokenName, tokenObjectEnd);
+}
+
+bool OurReader::readArray(Token& tokenStart) {
+ Value init(arrayValue);
+ currentValue().swapPayload(init);
+ currentValue().setOffsetStart(tokenStart.start_ - begin_);
+ skipSpaces();
+ if (current_ != end_ && *current_ == ']') // empty array
+ {
+ Token endArray;
+ readToken(endArray);
+ return true;
+ }
+ int index = 0;
+ for (;;) {
+ Value& value = currentValue()[index++];
+ nodes_.push(&value);
+ bool ok = readValue();
+ nodes_.pop();
+ if (!ok) // error already set
+ return recoverFromError(tokenArrayEnd);
+
+ Token token;
+ // Accept Comment after last item in the array.
+ ok = readToken(token);
+ while (token.type_ == tokenComment && ok) {
+ ok = readToken(token);
+ }
+ bool badTokenType =
+ (token.type_ != tokenArraySeparator && token.type_ != tokenArrayEnd);
+ if (!ok || badTokenType) {
+ return addErrorAndRecover(
+ "Missing ',' or ']' in array declaration", token, tokenArrayEnd);
+ }
+ if (token.type_ == tokenArrayEnd)
+ break;
+ }
+ return true;
+}
+
+bool OurReader::decodeNumber(Token& token) {
+ Value decoded;
+ if (!decodeNumber(token, decoded))
+ return false;
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool OurReader::decodeNumber(Token& token, Value& decoded) {
+ // Attempts to parse the number as an integer. If the number is
+ // larger than the maximum supported value of an integer then
+ // we decode the number as a double.
+ Location current = token.start_;
+ bool isNegative = *current == '-';
+ if (isNegative)
+ ++current;
+ // TODO: Help the compiler do the div and mod at compile time or get rid of them.
+ Value::LargestUInt maxIntegerValue =
+ isNegative ? Value::LargestUInt(Value::minLargestInt)
+ : Value::maxLargestUInt;
+ Value::LargestUInt threshold = maxIntegerValue / 10;
+ Value::LargestUInt value = 0;
+ while (current < token.end_) {
+ Char c = *current++;
+ if (c < '0' || c > '9')
+ return decodeDouble(token, decoded);
+ Value::UInt digit(static_cast<Value::UInt>(c - '0'));
+ if (value >= threshold) {
+ // We've hit or exceeded the max value divided by 10 (rounded down). If
+ // a) we've only just touched the limit, b) this is the last digit, and
+ // c) it's small enough to fit in that rounding delta, we're okay.
+ // Otherwise treat this number as a double to avoid overflow.
+ if (value > threshold || current != token.end_ ||
+ digit > maxIntegerValue % 10) {
+ return decodeDouble(token, decoded);
+ }
+ }
+ value = value * 10 + digit;
+ }
+ if (isNegative)
+ decoded = -Value::LargestInt(value);
+ else if (value <= Value::LargestUInt(Value::maxInt))
+ decoded = Value::LargestInt(value);
+ else
+ decoded = value;
+ return true;
+}
+
+bool OurReader::decodeDouble(Token& token) {
+ Value decoded;
+ if (!decodeDouble(token, decoded))
+ return false;
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool OurReader::decodeDouble(Token& token, Value& decoded) {
+ double value = 0;
const int bufferSize = 32;
int count;
- int length = int(token.end_ - token.start_);
+ ptrdiff_t const length = token.end_ - token.start_;
// Sanity check to avoid buffer overflow exploits.
if (length < 0) {
return addError("Unable to parse token length", token);
}
+ size_t const ulength = static_cast<size_t>(length);
// Avoid using a string constant for the format control string given to
// sscanf, as this can cause hard to debug crashes on OS X. See here for more
@@ -581,34 +1642,36 @@ bool Reader::decodeDouble(Token& token, Value& decoded) {
if (length <= bufferSize) {
Char buffer[bufferSize + 1];
- memcpy(buffer, token.start_, length);
+ memcpy(buffer, token.start_, ulength);
buffer[length] = 0;
+ fixNumericLocaleInput(buffer, buffer + length);
count = sscanf(buffer, format, &value);
} else {
- std::string buffer(token.start_, token.end_);
+ JSONCPP_STRING buffer(token.start_, token.end_);
count = sscanf(buffer.c_str(), format, &value);
}
if (count != 1)
- return addError("'" + std::string(token.start_, token.end_) +
+ return addError("'" + JSONCPP_STRING(token.start_, token.end_) +
"' is not a number.",
token);
decoded = value;
return true;
}
-bool Reader::decodeString(Token& token) {
- std::string decoded;
- if (!decodeString(token, decoded))
+bool OurReader::decodeString(Token& token) {
+ JSONCPP_STRING decoded_string;
+ if (!decodeString(token, decoded_string))
return false;
- currentValue() = decoded;
+ Value decoded(decoded_string);
+ currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
-bool Reader::decodeString(Token& token, std::string& decoded) {
- decoded.reserve(token.end_ - token.start_ - 2);
+bool OurReader::decodeString(Token& token, JSONCPP_STRING& decoded) {
+ decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"'
while (current != end) {
@@ -660,11 +1723,12 @@ bool Reader::decodeString(Token& token, std::string& decoded) {
return true;
}
-bool Reader::decodeUnicodeCodePoint(Token& token,
+bool OurReader::decodeUnicodeCodePoint(Token& token,
Location& current,
Location end,
unsigned int& unicode) {
+ unicode = 0; // Convince scanbuild this is always initialized before use.
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
return false;
if (unicode >= 0xD800 && unicode <= 0xDBFF) {
@@ -689,16 +1753,16 @@ bool Reader::decodeUnicodeCodePoint(Token& token,
return true;
}
-bool Reader::decodeUnicodeEscapeSequence(Token& token,
+bool OurReader::decodeUnicodeEscapeSequence(Token& token,
Location& current,
Location end,
- unsigned int& unicode) {
+ unsigned int& ret_unicode) {
if (end - current < 4)
return addError(
"Bad unicode escape sequence in string: four digits expected.",
token,
current);
- unicode = 0;
+ int unicode = 0;
for (int index = 0; index < 4; ++index) {
Char c = *current++;
unicode *= 16;
@@ -714,11 +1778,12 @@ bool Reader::decodeUnicodeEscapeSequence(Token& token,
token,
current);
}
+ ret_unicode = static_cast<unsigned int>(unicode);
return true;
}
bool
-Reader::addError(const std::string& message, Token& token, Location extra) {
+OurReader::addError(const JSONCPP_STRING& message, Token& token, Location extra) {
ErrorInfo info;
info.token_ = token;
info.message_ = message;
@@ -727,8 +1792,8 @@ Reader::addError(const std::string& message, Token& token, Location extra) {
return false;
}
-bool Reader::recoverFromError(TokenType skipUntilToken) {
- int errorCount = int(errors_.size());
+bool OurReader::recoverFromError(TokenType skipUntilToken) {
+ size_t errorCount = errors_.size();
Token skip;
for (;;) {
if (!readToken(skip))
@@ -740,22 +1805,22 @@ bool Reader::recoverFromError(TokenType skipUntilToken) {
return false;
}
-bool Reader::addErrorAndRecover(const std::string& message,
+bool OurReader::addErrorAndRecover(const JSONCPP_STRING& message,
Token& token,
TokenType skipUntilToken) {
addError(message, token);
return recoverFromError(skipUntilToken);
}
-Value& Reader::currentValue() { return *(nodes_.top()); }
+Value& OurReader::currentValue() { return *(nodes_.top()); }
-Reader::Char Reader::getNextChar() {
+OurReader::Char OurReader::getNextChar() {
if (current_ == end_)
return 0;
return *current_++;
}
-void Reader::getLocationLineAndColumn(Location location,
+void OurReader::getLocationLineAndColumn(Location location,
int& line,
int& column) const {
Location current = begin_;
@@ -778,29 +1843,16 @@ void Reader::getLocationLineAndColumn(Location location,
++line;
}
-std::string Reader::getLocationLineAndColumn(Location location) const {
+JSONCPP_STRING OurReader::getLocationLineAndColumn(Location location) const {
int line, column;
getLocationLineAndColumn(location, line, column);
char buffer[18 + 16 + 16 + 1];
-#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
-#if defined(WINCE)
- _snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
-#else
- sprintf_s(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
-#endif
-#else
snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
-#endif
return buffer;
}
-// Deprecated. Preserved for backward compatibility
-std::string Reader::getFormatedErrorMessages() const {
- return getFormattedErrorMessages();
-}
-
-std::string Reader::getFormattedErrorMessages() const {
- std::string formattedMessage;
+JSONCPP_STRING OurReader::getFormattedErrorMessages() const {
+ JSONCPP_STRING formattedMessage;
for (Errors::const_iterator itError = errors_.begin();
itError != errors_.end();
++itError) {
@@ -815,13 +1867,13 @@ std::string Reader::getFormattedErrorMessages() const {
return formattedMessage;
}
-std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
- std::vector<Reader::StructuredError> allErrors;
+std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
+ std::vector<OurReader::StructuredError> allErrors;
for (Errors::const_iterator itError = errors_.begin();
itError != errors_.end();
++itError) {
const ErrorInfo& error = *itError;
- Reader::StructuredError structured;
+ OurReader::StructuredError structured;
structured.offset_start = error.token_.start_ - begin_;
structured.offset_limit = error.token_.end_ - begin_;
structured.message = error.message_;
@@ -830,8 +1882,8 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
return allErrors;
}
-bool Reader::pushError(const Value& value, const std::string& message) {
- size_t length = end_ - begin_;
+bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message) {
+ ptrdiff_t length = end_ - begin_;
if(value.getOffsetStart() > length
|| value.getOffsetLimit() > length)
return false;
@@ -847,8 +1899,8 @@ bool Reader::pushError(const Value& value, const std::string& message) {
return true;
}
-bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) {
- size_t length = end_ - begin_;
+bool OurReader::pushError(const Value& value, const JSONCPP_STRING& message, const Value& extra) {
+ ptrdiff_t length = end_ - begin_;
if(value.getOffsetStart() > length
|| value.getOffsetLimit() > length
|| extra.getOffsetLimit() > length)
@@ -865,19 +1917,147 @@ bool Reader::pushError(const Value& value, const std::string& message, const Val
return true;
}
-bool Reader::good() const {
+bool OurReader::good() const {
return !errors_.size();
}
-std::istream& operator>>(std::istream& sin, Value& root) {
- Json::Reader reader;
- bool ok = reader.parse(sin, root, true);
+
+class OurCharReader : public CharReader {
+ bool const collectComments_;
+ OurReader reader_;
+public:
+ OurCharReader(
+ bool collectComments,
+ OurFeatures const& features)
+ : collectComments_(collectComments)
+ , reader_(features)
+ {}
+ bool parse(
+ char const* beginDoc, char const* endDoc,
+ Value* root, JSONCPP_STRING* errs) JSONCPP_OVERRIDE {
+ bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
+ if (errs) {
+ *errs = reader_.getFormattedErrorMessages();
+ }
+ return ok;
+ }
+};
+
+CharReaderBuilder::CharReaderBuilder()
+{
+ setDefaults(&settings_);
+}
+CharReaderBuilder::~CharReaderBuilder()
+{}
+CharReader* CharReaderBuilder::newCharReader() const
+{
+ bool collectComments = settings_["collectComments"].asBool();
+ OurFeatures features = OurFeatures::all();
+ features.allowComments_ = settings_["allowComments"].asBool();
+ features.strictRoot_ = settings_["strictRoot"].asBool();
+ features.allowDroppedNullPlaceholders_ = settings_["allowDroppedNullPlaceholders"].asBool();
+ features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool();
+ features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool();
+ features.stackLimit_ = settings_["stackLimit"].asInt();
+ features.failIfExtra_ = settings_["failIfExtra"].asBool();
+ features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
+ features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
+ return new OurCharReader(collectComments, features);
+}
+static void getValidReaderKeys(std::set<JSONCPP_STRING>* valid_keys)
+{
+ valid_keys->clear();
+ valid_keys->insert("collectComments");
+ valid_keys->insert("allowComments");
+ valid_keys->insert("strictRoot");
+ valid_keys->insert("allowDroppedNullPlaceholders");
+ valid_keys->insert("allowNumericKeys");
+ valid_keys->insert("allowSingleQuotes");
+ valid_keys->insert("stackLimit");
+ valid_keys->insert("failIfExtra");
+ valid_keys->insert("rejectDupKeys");
+ valid_keys->insert("allowSpecialFloats");
+}
+bool CharReaderBuilder::validate(Json::Value* invalid) const
+{
+ Json::Value my_invalid;
+ if (!invalid) invalid = &my_invalid; // so we do not need to test for NULL
+ Json::Value& inv = *invalid;
+ std::set<JSONCPP_STRING> valid_keys;
+ getValidReaderKeys(&valid_keys);
+ Value::Members keys = settings_.getMemberNames();
+ size_t n = keys.size();
+ for (size_t i = 0; i < n; ++i) {
+ JSONCPP_STRING const& key = keys[i];
+ if (valid_keys.find(key) == valid_keys.end()) {
+ inv[key] = settings_[key];
+ }
+ }
+ return 0u == inv.size();
+}
+Value& CharReaderBuilder::operator[](JSONCPP_STRING key)
+{
+ return settings_[key];
+}
+// static
+void CharReaderBuilder::strictMode(Json::Value* settings)
+{
+//! [CharReaderBuilderStrictMode]
+ (*settings)["allowComments"] = false;
+ (*settings)["strictRoot"] = true;
+ (*settings)["allowDroppedNullPlaceholders"] = false;
+ (*settings)["allowNumericKeys"] = false;
+ (*settings)["allowSingleQuotes"] = false;
+ (*settings)["stackLimit"] = 1000;
+ (*settings)["failIfExtra"] = true;
+ (*settings)["rejectDupKeys"] = true;
+ (*settings)["allowSpecialFloats"] = false;
+//! [CharReaderBuilderStrictMode]
+}
+// static
+void CharReaderBuilder::setDefaults(Json::Value* settings)
+{
+//! [CharReaderBuilderDefaults]
+ (*settings)["collectComments"] = true;
+ (*settings)["allowComments"] = true;
+ (*settings)["strictRoot"] = false;
+ (*settings)["allowDroppedNullPlaceholders"] = false;
+ (*settings)["allowNumericKeys"] = false;
+ (*settings)["allowSingleQuotes"] = false;
+ (*settings)["stackLimit"] = 1000;
+ (*settings)["failIfExtra"] = false;
+ (*settings)["rejectDupKeys"] = false;
+ (*settings)["allowSpecialFloats"] = false;
+//! [CharReaderBuilderDefaults]
+}
+
+//////////////////////////////////
+// global functions
+
+bool parseFromStream(
+ CharReader::Factory const& fact, JSONCPP_ISTREAM& sin,
+ Value* root, JSONCPP_STRING* errs)
+{
+ JSONCPP_OSTRINGSTREAM ssin;
+ ssin << sin.rdbuf();
+ JSONCPP_STRING doc = ssin.str();
+ char const* begin = doc.data();
+ char const* end = begin + doc.size();
+ // Note that we do not actually need a null-terminator.
+ CharReaderPtr const reader(fact.newCharReader());
+ return reader->parse(begin, end, root, errs);
+}
+
+JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM& sin, Value& root) {
+ CharReaderBuilder b;
+ JSONCPP_STRING errs;
+ bool ok = parseFromStream(b, sin, &root, &errs);
if (!ok) {
fprintf(stderr,
"Error from reader: %s",
- reader.getFormattedErrorMessages().c_str());
+ errs.c_str());
- JSON_FAIL_MESSAGE("reader error");
+ throwRuntimeError(errs);
}
return sin;
}
diff --git a/Utilities/cmjsoncpp/src/lib_json/json_tool.h b/Utilities/cmjsoncpp/src/lib_json/json_tool.h
index f9b61c38c..431617830 100644
--- a/Utilities/cmjsoncpp/src/lib_json/json_tool.h
+++ b/Utilities/cmjsoncpp/src/lib_json/json_tool.h
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -6,6 +6,16 @@
#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
+
+// Also support old flag NO_LOCALE_SUPPORT
+#ifdef NO_LOCALE_SUPPORT
+#define JSONCPP_NO_LOCALE_SUPPORT
+#endif
+
+#ifndef JSONCPP_NO_LOCALE_SUPPORT
+#include <clocale>
+#endif
+
/* This header provides common string manipulation support, such as UTF-8,
* portable conversion from/to string...
*
@@ -13,10 +23,18 @@
*/
namespace Json {
+static char getDecimalPoint() {
+#ifdef JSONCPP_NO_LOCALE_SUPPORT
+ return '\0';
+#else
+ struct lconv* lc = localeconv();
+ return lc ? *(lc->decimal_point) : '\0';
+#endif
+}
/// Converts a unicode code-point to UTF-8.
-static inline std::string codePointToUTF8(unsigned int cp) {
- std::string result;
+static inline JSONCPP_STRING codePointToUTF8(unsigned int cp) {
+ JSONCPP_STRING result;
// based on description from http://en.wikipedia.org/wiki/UTF-8
@@ -30,8 +48,8 @@ static inline std::string codePointToUTF8(unsigned int cp) {
} else if (cp <= 0xFFFF) {
result.resize(3);
result[2] = static_cast<char>(0x80 | (0x3f & cp));
- result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
- result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
+ result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
+ result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
} else if (cp <= 0x10FFFF) {
result.resize(4);
result[3] = static_cast<char>(0x80 | (0x3f & cp));
@@ -43,7 +61,7 @@ static inline std::string codePointToUTF8(unsigned int cp) {
return result;
}
-/// Returns true if ch is a control character (in range [0,32[).
+/// Returns true if ch is a control character (in range [1,31]).
static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; }
enum {
@@ -63,7 +81,7 @@ typedef char UIntToStringBuffer[uintToStringBufferSize];
static inline void uintToString(LargestUInt value, char*& current) {
*--current = 0;
do {
- *--current = char(value % 10) + '0';
+ *--current = static_cast<char>(value % 10U + static_cast<unsigned>('0'));
value /= 10;
} while (value != 0);
}
@@ -82,6 +100,18 @@ static inline void fixNumericLocale(char* begin, char* end) {
}
}
+static inline void fixNumericLocaleInput(char* begin, char* end) {
+ char decimalPoint = getDecimalPoint();
+ if (decimalPoint != '\0' && decimalPoint != '.') {
+ while (begin < end) {
+ if (*begin == '.') {
+ *begin = decimalPoint;
+ }
+ ++begin;
+ }
+ }
+}
+
} // namespace Json {
#endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED
diff --git a/Utilities/cmjsoncpp/src/lib_json/json_value.cpp b/Utilities/cmjsoncpp/src/lib_json/json_value.cpp
index 478afe102..f271e5731 100644
--- a/Utilities/cmjsoncpp/src/lib_json/json_value.cpp
+++ b/Utilities/cmjsoncpp/src/lib_json/json_value.cpp
@@ -1,4 +1,4 @@
-// Copyright 2011 Baptiste Lepilleur
+// Copyright 2011 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -7,9 +7,6 @@
#include <json/assertions.h>
#include <json/value.h>
#include <json/writer.h>
-#ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
-#include "json_batchallocator.h"
-#endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <math.h>
#include <sstream>
@@ -20,6 +17,7 @@
#include <cpptl/conststring.h>
#endif
#include <cstddef> // size_t
+#include <algorithm> // min()
#define JSON_ASSERT_UNREACHABLE assert(false)
@@ -33,9 +31,22 @@ namespace Json {
#else
#define ALIGNAS(byte_alignment)
#endif
-static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
-const unsigned char& kNullRef = kNull[0];
-const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
+//static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
+//const unsigned char& kNullRef = kNull[0];
+//const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
+//const Value& Value::nullRef = null;
+
+// static
+Value const& Value::nullSingleton()
+{
+ static Value const nullStatic;
+ return nullStatic;
+}
+
+// for backwards compatibility, we'll leave these global references around, but DO NOT
+// use them in JSONCPP library code any more!
+Value const& Value::null = Value::nullSingleton();
+Value const& Value::nullRef = Value::nullSingleton();
const Int Value::minInt = Int(~(UInt(-1) / 2));
const Int Value::maxInt = Int(UInt(-1) / 2);
@@ -53,17 +64,17 @@ const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2);
const LargestUInt Value::maxLargestUInt = LargestUInt(-1);
-/// Unknown size marker
-static const unsigned int unknown = (unsigned)-1;
-
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
template <typename T, typename U>
static inline bool InRange(double d, T min, U max) {
+ // The casts can lose precision, but we are looking only for
+ // an approximate range. Might fail on edge cases though. ~cdunn
+ //return d >= static_cast<double>(min) && d <= static_cast<double>(max);
return d >= min && d <= max;
}
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
static inline double integerToDouble(Json::UInt64 value) {
- return static_cast<double>(Int64(value / 2)) * 2.0 + Int64(value & 1);
+ return static_cast<double>(Int64(value / 2)) * 2.0 + static_cast<double>(Int64(value & 1));
}
template <typename T> static inline double integerToDouble(T value) {
@@ -84,27 +95,84 @@ static inline bool InRange(double d, T min, U max) {
* @return Pointer on the duplicate instance of string.
*/
static inline char* duplicateStringValue(const char* value,
- unsigned int length = unknown) {
- if (length == unknown)
- length = (unsigned int)strlen(value);
-
+ size_t length)
+{
// Avoid an integer overflow in the call to malloc below by limiting length
// to a sane value.
- if (length >= (unsigned)Value::maxInt)
+ if (length >= static_cast<size_t>(Value::maxInt))
length = Value::maxInt - 1;
char* newString = static_cast<char*>(malloc(length + 1));
- JSON_ASSERT_MESSAGE(newString != 0,
- "in Json::Value::duplicateStringValue(): "
- "Failed to allocate string value buffer");
+ if (newString == NULL) {
+ throwRuntimeError(
+ "in Json::Value::duplicateStringValue(): "
+ "Failed to allocate string value buffer");
+ }
memcpy(newString, value, length);
newString[length] = 0;
return newString;
}
-/** Free the string duplicated by duplicateStringValue().
+/* Record the length as a prefix.
+ */
+static inline char* duplicateAndPrefixStringValue(
+ const char* value,
+ unsigned int length)
+{
+ // Avoid an integer overflow in the call to malloc below by limiting length
+ // to a sane value.
+ JSON_ASSERT_MESSAGE(length <= static_cast<unsigned>(Value::maxInt) - sizeof(unsigned) - 1U,
+ "in Json::Value::duplicateAndPrefixStringValue(): "
+ "length too big for prefixing");
+ unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
+ char* newString = static_cast<char*>(malloc(actualLength));
+ if (newString == 0) {
+ throwRuntimeError(
+ "in Json::Value::duplicateAndPrefixStringValue(): "
+ "Failed to allocate string value buffer");
+ }
+ *reinterpret_cast<unsigned*>(newString) = length;
+ memcpy(newString + sizeof(unsigned), value, length);
+ newString[actualLength - 1U] = 0; // to avoid buffer over-run accidents by users later
+ return newString;
+}
+inline static void decodePrefixedString(
+ bool isPrefixed, char const* prefixed,
+ unsigned* length, char const** value)
+{
+ if (!isPrefixed) {
+ *length = static_cast<unsigned>(strlen(prefixed));
+ *value = prefixed;
+ } else {
+ *length = *reinterpret_cast<unsigned const*>(prefixed);
+ *value = prefixed + sizeof(unsigned);
+ }
+}
+/** Free the string duplicated by duplicateStringValue()/duplicateAndPrefixStringValue().
*/
-static inline void releaseStringValue(char* value) { free(value); }
+#if JSONCPP_USING_SECURE_MEMORY
+static inline void releasePrefixedStringValue(char* value) {
+ unsigned length = 0;
+ char const* valueDecoded;
+ decodePrefixedString(true, value, &length, &valueDecoded);
+ size_t const size = sizeof(unsigned) + length + 1U;
+ memset(value, 0, size);
+ free(value);
+}
+static inline void releaseStringValue(char* value, unsigned length) {
+ // length==0 => we allocated the strings memory
+ size_t size = (length==0) ? strlen(value) : length;
+ memset(value, 0, size);
+ free(value);
+}
+#else // !JSONCPP_USING_SECURE_MEMORY
+static inline void releasePrefixedStringValue(char* value) {
+ free(value);
+}
+static inline void releaseStringValue(char* value, unsigned) {
+ free(value);
+}
+#endif // JSONCPP_USING_SECURE_MEMORY
} // namespace Json
@@ -116,16 +184,36 @@ static inline void releaseStringValue(char* value) { free(value); }
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
#if !defined(JSON_IS_AMALGAMATION)
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
-#include "json_internalarray.inl"
-#include "json_internalmap.inl"
-#endif // JSON_VALUE_USE_INTERNAL_MAP
#include "json_valueiterator.inl"
#endif // if !defined(JSON_IS_AMALGAMATION)
namespace Json {
+Exception::Exception(JSONCPP_STRING const& msg)
+ : msg_(msg)
+{}
+Exception::~Exception() JSONCPP_NOEXCEPT
+{}
+char const* Exception::what() const JSONCPP_NOEXCEPT
+{
+ return msg_.c_str();
+}
+RuntimeError::RuntimeError(JSONCPP_STRING const& msg)
+ : Exception(msg)
+{}
+LogicError::LogicError(JSONCPP_STRING const& msg)
+ : Exception(msg)
+{}
+JSONCPP_NORETURN void throwRuntimeError(JSONCPP_STRING const& msg)
+{
+ throw RuntimeError(msg);
+}
+JSONCPP_NORETURN void throwLogicError(JSONCPP_STRING const& msg)
+{
+ throw LogicError(msg);
+}
+
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
@@ -134,22 +222,25 @@ namespace Json {
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
-Value::CommentInfo::CommentInfo() : comment_(0) {}
+Value::CommentInfo::CommentInfo() : comment_(0)
+{}
Value::CommentInfo::~CommentInfo() {
if (comment_)
- releaseStringValue(comment_);
+ releaseStringValue(comment_, 0u);
}
-void Value::CommentInfo::setComment(const char* text) {
- if (comment_)
- releaseStringValue(comment_);
+void Value::CommentInfo::setComment(const char* text, size_t len) {
+ if (comment_) {
+ releaseStringValue(comment_, 0u);
+ comment_ = 0;
+ }
JSON_ASSERT(text != 0);
JSON_ASSERT_MESSAGE(
text[0] == '\0' || text[0] == '/',
"in Json::Value::setComment(): Comments must start with /");
// It seems that /**/ style comments are acceptable as well.
- comment_ = duplicateStringValue(text);
+ comment_ = duplicateStringValue(text, len);
}
// //////////////////////////////////////////////////////////////////
@@ -159,29 +250,41 @@ void Value::CommentInfo::setComment(const char* text) {
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
-// Notes: index_ indicates if the string was allocated when
+// Notes: policy_ indicates if the string was allocated when
// a string is stored.
-Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
+Value::CZString::CZString(ArrayIndex aindex) : cstr_(0), index_(aindex) {}
-Value::CZString::CZString(const char* cstr, DuplicationPolicy allocate)
- : cstr_(allocate == duplicate ? duplicateStringValue(cstr) : cstr),
- index_(allocate) {}
+Value::CZString::CZString(char const* str, unsigned ulength, DuplicationPolicy allocate)
+ : cstr_(str) {
+ // allocate != duplicate
+ storage_.policy_ = allocate & 0x3;
+ storage_.length_ = ulength & 0x3FFFFFFF;
+}
-Value::CZString::CZString(const CZString& other)
- : cstr_(other.index_ != noDuplication && other.cstr_ != 0
- ? duplicateStringValue(other.cstr_)
- : other.cstr_),
- index_(other.cstr_
- ? static_cast<ArrayIndex>(other.index_ == noDuplication
+Value::CZString::CZString(const CZString& other) {
+ cstr_ = (other.storage_.policy_ != noDuplication && other.cstr_ != 0
+ ? duplicateStringValue(other.cstr_, other.storage_.length_)
+ : other.cstr_);
+ storage_.policy_ = static_cast<unsigned>(other.cstr_
+ ? (static_cast<DuplicationPolicy>(other.storage_.policy_) == noDuplication
? noDuplication : duplicate)
- : other.index_) {}
+ : static_cast<DuplicationPolicy>(other.storage_.policy_)) & 3U;
+ storage_.length_ = other.storage_.length_;
+}
+
+#if JSON_HAS_RVALUE_REFERENCES
+Value::CZString::CZString(CZString&& other)
+ : cstr_(other.cstr_), index_(other.index_) {
+ other.cstr_ = nullptr;
+}
+#endif
Value::CZString::~CZString() {
- if (cstr_ && index_ == duplicate)
- releaseStringValue(const_cast<char*>(cstr_));
+ if (cstr_ && storage_.policy_ == duplicate) {
+ releaseStringValue(const_cast<char*>(cstr_), storage_.length_ + 1u); //+1 for null terminating character for sake of completeness but not actually necessary
+ }
}
void Value::CZString::swap(CZString& other) {
@@ -189,34 +292,53 @@ void Value::CZString::swap(CZString& other) {
std::swap(index_, other.index_);
}
-Value::CZString& Value::CZString::operator=(CZString other) {
- swap(other);
+Value::CZString& Value::CZString::operator=(const CZString& other) {
+ cstr_ = other.cstr_;
+ index_ = other.index_;
return *this;
}
+#if JSON_HAS_RVALUE_REFERENCES
+Value::CZString& Value::CZString::operator=(CZString&& other) {
+ cstr_ = other.cstr_;
+ index_ = other.index_;
+ other.cstr_ = nullptr;
+ return *this;
+}
+#endif
+
bool Value::CZString::operator<(const CZString& other) const {
- if (cstr_) {
- assert(other.cstr_);
- return strcmp(cstr_, other.cstr_) < 0;
- }
- return index_ < other.index_;
+ if (!cstr_) return index_ < other.index_;
+ //return strcmp(cstr_, other.cstr_) < 0;
+ // Assume both are strings.
+ unsigned this_len = this->storage_.length_;
+ unsigned other_len = other.storage_.length_;
+ unsigned min_len = std::min<unsigned>(this_len, other_len);
+ JSON_ASSERT(this->cstr_ && other.cstr_);
+ int comp = memcmp(this->cstr_, other.cstr_, min_len);
+ if (comp < 0) return true;
+ if (comp > 0) return false;
+ return (this_len < other_len);
}
bool Value::CZString::operator==(const CZString& other) const {
- if (cstr_) {
- assert(other.cstr_);
- return strcmp(cstr_, other.cstr_) == 0;
- }
- return index_ == other.index_;
+ if (!cstr_) return index_ == other.index_;
+ //return strcmp(cstr_, other.cstr_) == 0;
+ // Assume both are strings.
+ unsigned this_len = this->storage_.length_;
+ unsigned other_len = other.storage_.length_;
+ if (this_len != other_len) return false;
+ JSON_ASSERT(this->cstr_ && other.cstr_);
+ int comp = memcmp(this->cstr_, other.cstr_, this_len);
+ return comp == 0;
}
ArrayIndex Value::CZString::index() const { return index_; }
-const char* Value::CZString::c_str() const { return cstr_; }
-
-bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
-
-#endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
+//const char* Value::CZString::c_str() const { return cstr_; }
+const char* Value::CZString::data() const { return cstr_; }
+unsigned Value::CZString::length() const { return storage_.length_; }
+bool Value::CZString::isStaticString() const { return storage_.policy_ == noDuplication; }
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
@@ -226,13 +348,14 @@ bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
-/*! \internal Default constructor initialization must be equivalent to:
+/*! internal Default constructor initialization must be equivalent to:
* memset( this, 0, sizeof(Value) )
* This optimization is used in ValueInternalMap fast allocator.
*/
-Value::Value(ValueType type) {
- initBasic(type);
- switch (type) {
+Value::Value(ValueType vtype) {
+ static char const emptyString[] = "";
+ initBasic(vtype);
+ switch (vtype) {
case nullValue:
break;
case intValue:
@@ -243,21 +366,13 @@ Value::Value(ValueType type) {
value_.real_ = 0.0;
break;
case stringValue:
- value_.string_ = 0;
+ // allocated_ == false, so this is safe.
+ value_.string_ = const_cast<char*>(static_cast<char const*>(emptyString));
break;
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
value_.map_ = new ObjectValues();
break;
-#else
- case arrayValue:
- value_.array_ = arrayAllocator()->newArray();
- break;
- case objectValue:
- value_.map_ = mapAllocator()->newMap();
- break;
-#endif
case booleanValue:
value_.bool_ = false;
break;
@@ -293,19 +408,20 @@ Value::Value(double value) {
Value::Value(const char* value) {
initBasic(stringValue, true);
- value_.string_ = duplicateStringValue(value);
+ JSON_ASSERT_MESSAGE(value != NULL, "Null Value Passed to Value Constructor");
+ value_.string_ = duplicateAndPrefixStringValue(value, static_cast<unsigned>(strlen(value)));
}
Value::Value(const char* beginValue, const char* endValue) {
initBasic(stringValue, true);
value_.string_ =
- duplicateStringValue(beginValue, (unsigned int)(endValue - beginValue));
+ duplicateAndPrefixStringValue(beginValue, static_cast<unsigned>(endValue - beginValue));
}
-Value::Value(const std::string& value) {
+Value::Value(const JSONCPP_STRING& value) {
initBasic(stringValue, true);
value_.string_ =
- duplicateStringValue(value.c_str(), (unsigned int)value.length());
+ duplicateAndPrefixStringValue(value.data(), static_cast<unsigned>(value.length()));
}
Value::Value(const StaticString& value) {
@@ -316,7 +432,7 @@ Value::Value(const StaticString& value) {
#ifdef JSON_USE_CPPTL
Value::Value(const CppTL::ConstString& value) {
initBasic(stringValue, true);
- value_.string_ = duplicateStringValue(value, value.length());
+ value_.string_ = duplicateAndPrefixStringValue(value, static_cast<unsigned>(value.length()));
}
#endif
@@ -325,14 +441,11 @@ Value::Value(bool value) {
value_.bool_ = value;
}
-Value::Value(const Value& other)
+Value::Value(Value const& other)
: type_(other.type_), allocated_(false)
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
,
- itemIsUsed_(0)
-#endif
- ,
- comments_(0), start_(other.start_), limit_(other.limit_) {
+ comments_(0), start_(other.start_), limit_(other.limit_)
+{
switch (type_) {
case nullValue:
case intValue:
@@ -342,27 +455,22 @@ Value::Value(const Value& other)
value_ = other.value_;
break;
case stringValue:
- if (other.value_.string_) {
- value_.string_ = duplicateStringValue(other.value_.string_);
+ if (other.value_.string_ && other.allocated_) {
+ unsigned len;
+ char const* str;
+ decodePrefixedString(other.allocated_, other.value_.string_,
+ &len, &str);
+ value_.string_ = duplicateAndPrefixStringValue(str, len);
allocated_ = true;
} else {
- value_.string_ = 0;
+ value_.string_ = other.value_.string_;
allocated_ = false;
}
break;
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
value_.map_ = new ObjectValues(*other.value_.map_);
break;
-#else
- case arrayValue:
- value_.array_ = arrayAllocator()->newArrayCopy(*other.value_.array_);
- break;
- case objectValue:
- value_.map_ = mapAllocator()->newMapCopy(*other.value_.map_);
- break;
-#endif
default:
JSON_ASSERT_UNREACHABLE;
}
@@ -371,11 +479,20 @@ Value::Value(const Value& other)
for (int comment = 0; comment < numberOfCommentPlacement; ++comment) {
const CommentInfo& otherComment = other.comments_[comment];
if (otherComment.comment_)
- comments_[comment].setComment(otherComment.comment_);
+ comments_[comment].setComment(
+ otherComment.comment_, strlen(otherComment.comment_));
}
}
}
+#if JSON_HAS_RVALUE_REFERENCES
+// Move constructor
+Value::Value(Value&& other) {
+ initBasic(nullValue);
+ swap(other);
+}
+#endif
+
Value::~Value() {
switch (type_) {
case nullValue:
@@ -386,27 +503,19 @@ Value::~Value() {
break;
case stringValue:
if (allocated_)
- releaseStringValue(value_.string_);
+ releasePrefixedStringValue(value_.string_);
break;
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
delete value_.map_;
break;
-#else
- case arrayValue:
- arrayAllocator()->destructArray(value_.array_);
- break;
- case objectValue:
- mapAllocator()->destructMap(value_.map_);
- break;
-#endif
default:
JSON_ASSERT_UNREACHABLE;
}
- if (comments_)
- delete[] comments_;
+ delete[] comments_;
+
+ value_.uint_ = 0;
}
Value& Value::operator=(Value other) {
@@ -414,18 +523,36 @@ Value& Value::operator=(Value other) {
return *this;
}
-void Value::swap(Value& other) {
+void Value::swapPayload(Value& other) {
ValueType temp = type_;
type_ = other.type_;
other.type_ = temp;
std::swap(value_, other.value_);
int temp2 = allocated_;
allocated_ = other.allocated_;
- other.allocated_ = temp2;
+ other.allocated_ = temp2 & 0x1;
+}
+
+void Value::copyPayload(const Value& other) {
+ type_ = other.type_;
+ value_ = other.value_;
+ allocated_ = other.allocated_;
+}
+
+void Value::swap(Value& other) {
+ swapPayload(other);
+ std::swap(comments_, other.comments_);
std::swap(start_, other.start_);
std::swap(limit_, other.limit_);
}
+void Value::copy(const Value& other) {
+ copyPayload(other);
+ comments_ = other.comments_;
+ start_ = other.start_;
+ limit_ = other.limit_;
+}
+
ValueType Value::type() const { return type_; }
int Value::compare(const Value& other) const {
@@ -452,10 +579,24 @@ bool Value::operator<(const Value& other) const {
case booleanValue:
return value_.bool_ < other.value_.bool_;
case stringValue:
- return (value_.string_ == 0 && other.value_.string_) ||
- (other.value_.string_ && value_.string_ &&
- strcmp(value_.string_, other.value_.string_) < 0);
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
+ {
+ if ((value_.string_ == 0) || (other.value_.string_ == 0)) {
+ if (other.value_.string_) return true;
+ else return false;
+ }
+ unsigned this_len;
+ unsigned other_len;
+ char const* this_str;
+ char const* other_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str);
+ unsigned min_len = std::min<unsigned>(this_len, other_len);
+ JSON_ASSERT(this_str && other_str);
+ int comp = memcmp(this_str, other_str, min_len);
+ if (comp < 0) return true;
+ if (comp > 0) return false;
+ return (this_len < other_len);
+ }
case arrayValue:
case objectValue: {
int delta = int(value_.map_->size() - other.value_.map_->size());
@@ -463,12 +604,6 @@ bool Value::operator<(const Value& other) const {
return delta < 0;
return (*value_.map_) < (*other.value_.map_);
}
-#else
- case arrayValue:
- return value_.array_->compare(*(other.value_.array_)) < 0;
- case objectValue:
- return value_.map_->compare(*(other.value_.map_)) < 0;
-#endif
default:
JSON_ASSERT_UNREACHABLE;
}
@@ -501,20 +636,25 @@ bool Value::operator==(const Value& other) const {
case booleanValue:
return value_.bool_ == other.value_.bool_;
case stringValue:
- return (value_.string_ == other.value_.string_) ||
- (other.value_.string_ && value_.string_ &&
- strcmp(value_.string_, other.value_.string_) == 0);
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
+ {
+ if ((value_.string_ == 0) || (other.value_.string_ == 0)) {
+ return (value_.string_ == other.value_.string_);
+ }
+ unsigned this_len;
+ unsigned other_len;
+ char const* this_str;
+ char const* other_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str);
+ if (this_len != other_len) return false;
+ JSON_ASSERT(this_str && other_str);
+ int comp = memcmp(this_str, other_str, this_len);
+ return comp == 0;
+ }
case arrayValue:
case objectValue:
return value_.map_->size() == other.value_.map_->size() &&
(*value_.map_) == (*other.value_.map_);
-#else
- case arrayValue:
- return value_.array_->compare(*(other.value_.array_)) == 0;
- case objectValue:
- return value_.map_->compare(*(other.value_.map_)) == 0;
-#endif
default:
JSON_ASSERT_UNREACHABLE;
}
@@ -526,15 +666,46 @@ bool Value::operator!=(const Value& other) const { return !(*this == other); }
const char* Value::asCString() const {
JSON_ASSERT_MESSAGE(type_ == stringValue,
"in Json::Value::asCString(): requires stringValue");
- return value_.string_;
+ if (value_.string_ == 0) return 0;
+ unsigned this_len;
+ char const* this_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ return this_str;
+}
+
+#if JSONCPP_USING_SECURE_MEMORY
+unsigned Value::getCStringLength() const {
+ JSON_ASSERT_MESSAGE(type_ == stringValue,
+ "in Json::Value::asCString(): requires stringValue");
+ if (value_.string_ == 0) return 0;
+ unsigned this_len;
+ char const* this_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ return this_len;
+}
+#endif
+
+bool Value::getString(char const** str, char const** cend) const {
+ if (type_ != stringValue) return false;
+ if (value_.string_ == 0) return false;
+ unsigned length;
+ decodePrefixedString(this->allocated_, this->value_.string_, &length, str);
+ *cend = *str + length;
+ return true;
}
-std::string Value::asString() const {
+JSONCPP_STRING Value::asString() const {
switch (type_) {
case nullValue:
return "";
case stringValue:
- return value_.string_ ? value_.string_ : "";
+ {
+ if (value_.string_ == 0) return "";
+ unsigned this_len;
+ char const* this_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ return JSONCPP_STRING(this_str, this_len);
+ }
case booleanValue:
return value_.bool_ ? "true" : "false";
case intValue:
@@ -550,7 +721,11 @@ std::string Value::asString() const {
#ifdef JSON_USE_CPPTL
CppTL::ConstString Value::asConstString() const {
- return CppTL::ConstString(asString().c_str());
+ unsigned len;
+ char const* str;
+ decodePrefixedString(allocated_, value_.string_,
+ &len, &str);
+ return CppTL::ConstString(str, len);
}
#endif
@@ -689,7 +864,8 @@ float Value::asFloat() const {
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
return static_cast<float>(value_.uint_);
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
- return integerToDouble(value_.uint_);
+ // This can fail (silently?) if the value is bigger than MAX_FLOAT.
+ return static_cast<float>(integerToDouble(value_.uint_));
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
case realValue:
return static_cast<float>(value_.real_);
@@ -714,7 +890,8 @@ bool Value::asBool() const {
case uintValue:
return value_.uint_ ? true : false;
case realValue:
- return value_.real_ ? true : false;
+ // This is kind of strange. Not recommended.
+ return (value_.real_ != 0.0) ? true : false;
default:
break;
}
@@ -726,7 +903,7 @@ bool Value::isConvertibleTo(ValueType other) const {
case nullValue:
return (isNumeric() && asDouble() == 0.0) ||
(type_ == booleanValue && value_.bool_ == false) ||
- (type_ == stringValue && asString() == "") ||
+ (type_ == stringValue && asString().empty()) ||
(type_ == arrayValue && value_.map_->size() == 0) ||
(type_ == objectValue && value_.map_->size() == 0) ||
type_ == nullValue;
@@ -764,7 +941,6 @@ ArrayIndex Value::size() const {
case booleanValue:
case stringValue:
return 0;
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue: // size of the array is highest index + 1
if (!value_.map_->empty()) {
ObjectValues::const_iterator itLast = value_.map_->end();
@@ -774,12 +950,6 @@ ArrayIndex Value::size() const {
return 0;
case objectValue:
return ArrayIndex(value_.map_->size());
-#else
- case arrayValue:
- return Int(value_.array_->size());
- case objectValue:
- return Int(value_.map_->size());
-#endif
}
JSON_ASSERT_UNREACHABLE;
return 0; // unreachable;
@@ -801,19 +971,10 @@ void Value::clear() {
start_ = 0;
limit_ = 0;
switch (type_) {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
case arrayValue:
case objectValue:
value_.map_->clear();
break;
-#else
- case arrayValue:
- value_.array_->clear();
- break;
- case objectValue:
- value_.map_->clear();
- break;
-#endif
default:
break;
}
@@ -824,7 +985,6 @@ void Value::resize(ArrayIndex newSize) {
"in Json::Value::resize(): requires arrayValue");
if (type_ == nullValue)
*this = Value(arrayValue);
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
ArrayIndex oldSize = size();
if (newSize == 0)
clear();
@@ -834,11 +994,8 @@ void Value::resize(ArrayIndex newSize) {
for (ArrayIndex index = newSize; index < oldSize; ++index) {
value_.map_->erase(index);
}
- assert(size() == newSize);
+ JSON_ASSERT(size() == newSize);
}
-#else
- value_.array_->resize(newSize);
-#endif
}
Value& Value::operator[](ArrayIndex index) {
@@ -847,18 +1004,14 @@ Value& Value::operator[](ArrayIndex index) {
"in Json::Value::operator[](ArrayIndex): requires arrayValue");
if (type_ == nullValue)
*this = Value(arrayValue);
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString key(index);
ObjectValues::iterator it = value_.map_->lower_bound(key);
if (it != value_.map_->end() && (*it).first == key)
return (*it).second;
- ObjectValues::value_type defaultValue(key, null);
+ ObjectValues::value_type defaultValue(key, nullSingleton());
it = value_.map_->insert(it, defaultValue);
return (*it).second;
-#else
- return value_.array_->resolveReference(index);
-#endif
}
Value& Value::operator[](int index) {
@@ -873,17 +1026,12 @@ const Value& Value::operator[](ArrayIndex index) const {
type_ == nullValue || type_ == arrayValue,
"in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
if (type_ == nullValue)
- return null;
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
+ return nullSingleton();
CZString key(index);
ObjectValues::const_iterator it = value_.map_->find(key);
if (it == value_.map_->end())
- return null;
+ return nullSingleton();
return (*it).second;
-#else
- Value* value = value_.array_->find(index);
- return value ? *value : null;
-#endif
}
const Value& Value::operator[](int index) const {
@@ -893,149 +1041,215 @@ const Value& Value::operator[](int index) const {
return (*this)[ArrayIndex(index)];
}
-Value& Value::operator[](const char* key) {
- return resolveReference(key, false);
-}
-
-void Value::initBasic(ValueType type, bool allocated) {
- type_ = type;
+void Value::initBasic(ValueType vtype, bool allocated) {
+ type_ = vtype;
allocated_ = allocated;
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- itemIsUsed_ = 0;
-#endif
comments_ = 0;
start_ = 0;
limit_ = 0;
}
-Value& Value::resolveReference(const char* key, bool isStatic) {
+// Access an object value by name, create a null member if it does not exist.
+// @pre Type of '*this' is object or null.
+// @param key is null-terminated.
+Value& Value::resolveReference(const char* key) {
JSON_ASSERT_MESSAGE(
type_ == nullValue || type_ == objectValue,
"in Json::Value::resolveReference(): requires objectValue");
if (type_ == nullValue)
*this = Value(objectValue);
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
CZString actualKey(
- key, isStatic ? CZString::noDuplication : CZString::duplicateOnCopy);
+ key, static_cast<unsigned>(strlen(key)), CZString::noDuplication); // NOTE!
ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second;
- ObjectValues::value_type defaultValue(actualKey, null);
+ ObjectValues::value_type defaultValue(actualKey, nullSingleton());
+ it = value_.map_->insert(it, defaultValue);
+ Value& value = (*it).second;
+ return value;
+}
+
+// @param key is not null-terminated.
+Value& Value::resolveReference(char const* key, char const* cend)
+{
+ JSON_ASSERT_MESSAGE(
+ type_ == nullValue || type_ == objectValue,
+ "in Json::Value::resolveReference(key, end): requires objectValue");
+ if (type_ == nullValue)
+ *this = Value(objectValue);
+ CZString actualKey(
+ key, static_cast<unsigned>(cend-key), CZString::duplicateOnCopy);
+ ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
+ if (it != value_.map_->end() && (*it).first == actualKey)
+ return (*it).second;
+
+ ObjectValues::value_type defaultValue(actualKey, nullSingleton());
it = value_.map_->insert(it, defaultValue);
Value& value = (*it).second;
return value;
-#else
- return value_.map_->resolveReference(key, isStatic);
-#endif
}
Value Value::get(ArrayIndex index, const Value& defaultValue) const {
const Value* value = &((*this)[index]);
- return value == &null ? defaultValue : *value;
+ return value == &nullSingleton() ? defaultValue : *value;
}
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
-const Value& Value::operator[](const char* key) const {
+Value const* Value::find(char const* key, char const* cend) const
+{
JSON_ASSERT_MESSAGE(
type_ == nullValue || type_ == objectValue,
- "in Json::Value::operator[](char const*)const: requires objectValue");
- if (type_ == nullValue)
- return null;
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
- CZString actualKey(key, CZString::noDuplication);
+ "in Json::Value::find(key, end, found): requires objectValue or nullValue");
+ if (type_ == nullValue) return NULL;
+ CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
ObjectValues::const_iterator it = value_.map_->find(actualKey);
- if (it == value_.map_->end())
- return null;
- return (*it).second;
-#else
- const Value* value = value_.map_->find(key);
- return value ? *value : null;
-#endif
+ if (it == value_.map_->end()) return NULL;
+ return &(*it).second;
+}
+const Value& Value::operator[](const char* key) const
+{
+ Value const* found = find(key, key + strlen(key));
+ if (!found) return nullSingleton();
+ return *found;
+}
+Value const& Value::operator[](JSONCPP_STRING const& key) const
+{
+ Value const* found = find(key.data(), key.data() + key.length());
+ if (!found) return nullSingleton();
+ return *found;
}
-Value& Value::operator[](const std::string& key) {
- return (*this)[key.c_str()];
+Value& Value::operator[](const char* key) {
+ return resolveReference(key, key + strlen(key));
}
-const Value& Value::operator[](const std::string& key) const {
- return (*this)[key.c_str()];
+Value& Value::operator[](const JSONCPP_STRING& key) {
+ return resolveReference(key.data(), key.data() + key.length());
}
Value& Value::operator[](const StaticString& key) {
- return resolveReference(key, true);
+ return resolveReference(key.c_str());
}
#ifdef JSON_USE_CPPTL
Value& Value::operator[](const CppTL::ConstString& key) {
- return (*this)[key.c_str()];
+ return resolveReference(key.c_str(), key.end_c_str());
}
-
-const Value& Value::operator[](const CppTL::ConstString& key) const {
- return (*this)[key.c_str()];
+Value const& Value::operator[](CppTL::ConstString const& key) const
+{
+ Value const* found = find(key.c_str(), key.end_c_str());
+ if (!found) return nullSingleton();
+ return *found;
}
#endif
Value& Value::append(const Value& value) { return (*this)[size()] = value; }
-Value Value::get(const char* key, const Value& defaultValue) const {
- const Value* value = &((*this)[key]);
- return value == &null ? defaultValue : *value;
-}
+#if JSON_HAS_RVALUE_REFERENCES
+ Value& Value::append(Value&& value) { return (*this)[size()] = value; }
+#endif
-Value Value::get(const std::string& key, const Value& defaultValue) const {
- return get(key.c_str(), defaultValue);
+Value Value::get(char const* key, char const* cend, Value const& defaultValue) const
+{
+ Value const* found = find(key, cend);
+ return !found ? defaultValue : *found;
+}
+Value Value::get(char const* key, Value const& defaultValue) const
+{
+ return get(key, key + strlen(key), defaultValue);
+}
+Value Value::get(JSONCPP_STRING const& key, Value const& defaultValue) const
+{
+ return get(key.data(), key.data() + key.length(), defaultValue);
}
-Value Value::removeMember(const char* key) {
- JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue,
- "in Json::Value::removeMember(): requires objectValue");
- if (type_ == nullValue)
- return null;
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
- CZString actualKey(key, CZString::noDuplication);
+
+bool Value::removeMember(const char* key, const char* cend, Value* removed)
+{
+ if (type_ != objectValue) {
+ return false;
+ }
+ CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
ObjectValues::iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end())
- return null;
- Value old(it->second);
+ return false;
+ *removed = it->second;
value_.map_->erase(it);
- return old;
-#else
- Value* value = value_.map_->find(key);
- if (value) {
- Value old(*value);
- value_.map_.remove(key);
- return old;
- } else {
- return null;
- }
-#endif
+ return true;
+}
+bool Value::removeMember(const char* key, Value* removed)
+{
+ return removeMember(key, key + strlen(key), removed);
}
+bool Value::removeMember(JSONCPP_STRING const& key, Value* removed)
+{
+ return removeMember(key.data(), key.data() + key.length(), removed);
+}
+Value Value::removeMember(const char* key)
+{
+ JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue,
+ "in Json::Value::removeMember(): requires objectValue");
+ if (type_ == nullValue)
+ return nullSingleton();
-Value Value::removeMember(const std::string& key) {
+ Value removed; // null
+ removeMember(key, key + strlen(key), &removed);
+ return removed; // still null if removeMember() did nothing
+}
+Value Value::removeMember(const JSONCPP_STRING& key)
+{
return removeMember(key.c_str());
}
+bool Value::removeIndex(ArrayIndex index, Value* removed) {
+ if (type_ != arrayValue) {
+ return false;
+ }
+ CZString key(index);
+ ObjectValues::iterator it = value_.map_->find(key);
+ if (it == value_.map_->end()) {
+ return false;
+ }
+ *removed = it->second;
+ ArrayIndex oldSize = size();
+ // shift left all items left, into the place of the "removed"
+ for (ArrayIndex i = index; i < (oldSize - 1); ++i){
+ CZString keey(i);
+ (*value_.map_)[keey] = (*this)[i + 1];
+ }
+ // erase the last one ("leftover")
+ CZString keyLast(oldSize - 1);
+ ObjectValues::iterator itLast = value_.map_->find(keyLast);
+ value_.map_->erase(itLast);
+ return true;
+}
+
#ifdef JSON_USE_CPPTL
Value Value::get(const CppTL::ConstString& key,
const Value& defaultValue) const {
- return get(key.c_str(), defaultValue);
+ return get(key.c_str(), key.end_c_str(), defaultValue);
}
#endif
-bool Value::isMember(const char* key) const {
- const Value* value = &((*this)[key]);
- return value != &null;
+bool Value::isMember(char const* key, char const* cend) const
+{
+ Value const* value = find(key, cend);
+ return NULL != value;
}
-
-bool Value::isMember(const std::string& key) const {
- return isMember(key.c_str());
+bool Value::isMember(char const* key) const
+{
+ return isMember(key, key + strlen(key));
+}
+bool Value::isMember(JSONCPP_STRING const& key) const
+{
+ return isMember(key.data(), key.data() + key.length());
}
#ifdef JSON_USE_CPPTL
bool Value::isMember(const CppTL::ConstString& key) const {
- return isMember(key.c_str());
+ return isMember(key.c_str(), key.end_c_str());
}
#endif
@@ -1047,19 +1261,12 @@ Value::Members Value::getMemberNames() const {
return Value::Members();
Members members;
members.reserve(value_.map_->size());
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
ObjectValues::const_iterator it = value_.map_->begin();
ObjectValues::const_iterator itEnd = value_.map_->end();
- for (; it != itEnd; ++it)
- members.push_back(std::string((*it).first.c_str()));
-#else
- ValueInternalMap::IteratorState it;
- ValueInternalMap::IteratorState itEnd;
- value_.map_->makeBeginIterator(it);
- value_.map_->makeEndIterator(itEnd);
- for (; !ValueInternalMap::equals(it, itEnd); ValueInternalMap::increment(it))
- members.push_back(std::string(ValueInternalMap::key(it)));
-#endif
+ for (; it != itEnd; ++it) {
+ members.push_back(JSONCPP_STRING((*it).first.data(),
+ (*it).first.length()));
+ }
return members;
}
//
@@ -1100,7 +1307,11 @@ bool Value::isBool() const { return type_ == booleanValue; }
bool Value::isInt() const {
switch (type_) {
case intValue:
+#if defined(JSON_HAS_INT64)
return value_.int_ >= minInt && value_.int_ <= maxInt;
+#else
+ return true;
+#endif
case uintValue:
return value_.uint_ <= UInt(maxInt);
case realValue:
@@ -1115,9 +1326,17 @@ bool Value::isInt() const {
bool Value::isUInt() const {
switch (type_) {
case intValue:
+#if defined(JSON_HAS_INT64)
return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt);
+#else
+ return value_.int_ >= 0;
+#endif
case uintValue:
+#if defined(JSON_HAS_INT64)
return value_.uint_ <= maxUInt;
+#else
+ return true;
+#endif
case realValue:
return value_.real_ >= 0 && value_.real_ <= maxUInt &&
IsIntegral(value_.real_);
@@ -1168,16 +1387,28 @@ bool Value::isUInt64() const {
}
bool Value::isIntegral() const {
+ switch (type_) {
+ case intValue:
+ case uintValue:
+ return true;
+ case realValue:
#if defined(JSON_HAS_INT64)
- return isInt64() || isUInt64();
+ // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
+ // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
+ // require the value to be strictly less than the limit.
+ return value_.real_ >= double(minInt64) && value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
#else
- return isInt() || isUInt();
-#endif
+ return value_.real_ >= minInt && value_.real_ <= maxUInt && IsIntegral(value_.real_);
+#endif // JSON_HAS_INT64
+ default:
+ break;
+ }
+ return false;
}
-bool Value::isDouble() const { return type_ == realValue || isIntegral(); }
+bool Value::isDouble() const { return type_ == intValue || type_ == uintValue || type_ == realValue; }
-bool Value::isNumeric() const { return isIntegral() || isDouble(); }
+bool Value::isNumeric() const { return isDouble(); }
bool Value::isString() const { return type_ == stringValue; }
@@ -1185,63 +1416,59 @@ bool Value::isArray() const { return type_ == arrayValue; }
bool Value::isObject() const { return type_ == objectValue; }
-void Value::setComment(const char* comment, CommentPlacement placement) {
+void Value::setComment(const char* comment, size_t len, CommentPlacement placement) {
if (!comments_)
comments_ = new CommentInfo[numberOfCommentPlacement];
- comments_[placement].setComment(comment);
+ if ((len > 0) && (comment[len-1] == '\n')) {
+ // Always discard trailing newline, to aid indentation.
+ len -= 1;
+ }
+ comments_[placement].setComment(comment, len);
+}
+
+void Value::setComment(const char* comment, CommentPlacement placement) {
+ setComment(comment, strlen(comment), placement);
}
-void Value::setComment(const std::string& comment, CommentPlacement placement) {
- setComment(comment.c_str(), placement);
+void Value::setComment(const JSONCPP_STRING& comment, CommentPlacement placement) {
+ setComment(comment.c_str(), comment.length(), placement);
}
bool Value::hasComment(CommentPlacement placement) const {
return comments_ != 0 && comments_[placement].comment_ != 0;
}
-std::string Value::getComment(CommentPlacement placement) const {
+JSONCPP_STRING Value::getComment(CommentPlacement placement) const {
if (hasComment(placement))
return comments_[placement].comment_;
return "";
}
-void Value::setOffsetStart(size_t start) { start_ = start; }
+void Value::setOffsetStart(ptrdiff_t start) { start_ = start; }
+
+void Value::setOffsetLimit(ptrdiff_t limit) { limit_ = limit; }
-void Value::setOffsetLimit(size_t limit) { limit_ = limit; }
+ptrdiff_t Value::getOffsetStart() const { return start_; }
-size_t Value::getOffsetStart() const { return start_; }
+ptrdiff_t Value::getOffsetLimit() const { return limit_; }
-size_t Value::getOffsetLimit() const { return limit_; }
+JSONCPP_STRING Value::toStyledString() const {
+ StreamWriterBuilder builder;
-std::string Value::toStyledString() const {
- StyledWriter writer;
- return writer.write(*this);
+ JSONCPP_STRING out = this->hasComment(commentBefore) ? "\n" : "";
+ out += Json::writeString(builder, *this);
+ out += "\n";
+
+ return out;
}
Value::const_iterator Value::begin() const {
switch (type_) {
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- case arrayValue:
- if (value_.array_) {
- ValueInternalArray::IteratorState it;
- value_.array_->makeBeginIterator(it);
- return const_iterator(it);
- }
- break;
- case objectValue:
- if (value_.map_) {
- ValueInternalMap::IteratorState it;
- value_.map_->makeBeginIterator(it);
- return const_iterator(it);
- }
- break;
-#else
case arrayValue:
case objectValue:
if (value_.map_)
return const_iterator(value_.map_->begin());
break;
-#endif
default:
break;
}
@@ -1250,28 +1477,11 @@ Value::const_iterator Value::begin() const {
Value::const_iterator Value::end() const {
switch (type_) {
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- case arrayValue:
- if (value_.array_) {
- ValueInternalArray::IteratorState it;
- value_.array_->makeEndIterator(it);
- return const_iterator(it);
- }
- break;
- case objectValue:
- if (value_.map_) {
- ValueInternalMap::IteratorState it;
- value_.map_->makeEndIterator(it);
- return const_iterator(it);
- }
- break;
-#else
case arrayValue:
case objectValue:
if (value_.map_)
return const_iterator(value_.map_->end());
break;
-#endif
default:
break;
}
@@ -1280,28 +1490,11 @@ Value::const_iterator Value::end() const {
Value::iterator Value::begin() {
switch (type_) {
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- case arrayValue:
- if (value_.array_) {
- ValueInternalArray::IteratorState it;
- value_.array_->makeBeginIterator(it);
- return iterator(it);
- }
- break;
- case objectValue:
- if (value_.map_) {
- ValueInternalMap::IteratorState it;
- value_.map_->makeBeginIterator(it);
- return iterator(it);
- }
- break;
-#else
case arrayValue:
case objectValue:
if (value_.map_)
return iterator(value_.map_->begin());
break;
-#endif
default:
break;
}
@@ -1310,28 +1503,11 @@ Value::iterator Value::begin() {
Value::iterator Value::end() {
switch (type_) {
-#ifdef JSON_VALUE_USE_INTERNAL_MAP
- case arrayValue:
- if (value_.array_) {
- ValueInternalArray::IteratorState it;
- value_.array_->makeEndIterator(it);
- return iterator(it);
- }
- break;
- case objectValue:
- if (value_.map_) {
- ValueInternalMap::IteratorState it;
- value_.map_->makeEndIterator(it);
- return iterator(it);
- }
- break;
-#else
case arrayValue:
case objectValue:
if (value_.map_)
return iterator(value_.map_->end());
break;
-#endif
default:
break;
}
@@ -1349,19 +1525,20 @@ PathArgument::PathArgument(ArrayIndex index)
PathArgument::PathArgument(const char* key)
: key_(key), index_(), kind_(kindKey) {}
-PathArgument::PathArgument(const std::string& key)
+PathArgument::PathArgument(const JSONCPP_STRING& key)
: key_(key.c_str()), index_(), kind_(kindKey) {}
// class Path
// //////////////////////////////////////////////////////////////////
-Path::Path(const std::string& path,
+Path::Path(const JSONCPP_STRING& path,
const PathArgument& a1,
const PathArgument& a2,
const PathArgument& a3,
const PathArgument& a4,
const PathArgument& a5) {
InArgs in;
+ in.reserve(5);
in.push_back(&a1);
in.push_back(&a2);
in.push_back(&a3);
@@ -1370,7 +1547,7 @@ Path::Path(const std::string& path,
makePath(path, in);
}
-void Path::makePath(const std::string& path, const InArgs& in) {
+void Path::makePath(const JSONCPP_STRING& path, const InArgs& in) {
const char* current = path.c_str();
const char* end = current + path.length();
InArgs::const_iterator itInArg = in.begin();
@@ -1385,23 +1562,23 @@ void Path::makePath(const std::string& path, const InArgs& in) {
index = index * 10 + ArrayIndex(*current - '0');
args_.push_back(index);
}
- if (current == end || *current++ != ']')
+ if (current == end || *++current != ']')
invalidPath(path, int(current - path.c_str()));
} else if (*current == '%') {
addPathInArg(path, in, itInArg, PathArgument::kindKey);
++current;
- } else if (*current == '.') {
+ } else if (*current == '.' || *current == ']') {
++current;
} else {
const char* beginName = current;
while (current != end && !strchr("[.", *current))
++current;
- args_.push_back(std::string(beginName, current));
+ args_.push_back(JSONCPP_STRING(beginName, current));
}
}
}
-void Path::addPathInArg(const std::string& /*path*/,
+void Path::addPathInArg(const JSONCPP_STRING& /*path*/,
const InArgs& in,
InArgs::const_iterator& itInArg,
PathArgument::Kind kind) {
@@ -1410,11 +1587,11 @@ void Path::addPathInArg(const std::string& /*path*/,
} else if ((*itInArg)->kind_ != kind) {
// Error: bad argument type
} else {
- args_.push_back(**itInArg);
+ args_.push_back(**itInArg++);
}
}
-void Path::invalidPath(const std::string& /*path*/, int /*location*/) {
+void Path::invalidPath(const JSONCPP_STRING& /*path*/, int /*location*/) {
// Error: invalid path.
}
@@ -1425,16 +1602,19 @@ const Value& Path::resolve(const Value& root) const {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
// Error: unable to resolve path (array value expected at position...
+ return Value::null;
}
node = &((*node)[arg.index_]);
} else if (arg.kind_ == PathArgument::kindKey) {
if (!node->isObject()) {
// Error: unable to resolve path (object value expected at position...)
+ return Value::null;
}
node = &((*node)[arg.key_]);
- if (node == &Value::null) {
+ if (node == &Value::nullSingleton()) {
// Error: unable to resolve path (object has no member named '' at
// position...)
+ return Value::null;
}
}
}
@@ -1453,7 +1633,7 @@ Value Path::resolve(const Value& root, const Value& defaultValue) const {
if (!node->isObject())
return defaultValue;
node = &((*node)[arg.key_]);
- if (node == &Value::null)
+ if (node == &Value::nullSingleton())
return defaultValue;
}
}
diff --git a/Utilities/cmjsoncpp/src/lib_json/json_valueiterator.inl b/Utilities/cmjsoncpp/src/lib_json/json_valueiterator.inl
index a9f7df63a..5243bfe4b 100644
--- a/Utilities/cmjsoncpp/src/lib_json/json_valueiterator.inl
+++ b/Utilities/cmjsoncpp/src/lib_json/json_valueiterator.inl
@@ -1,4 +1,4 @@
-// Copyright 2007-2010 Baptiste Lepilleur
+// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -16,68 +16,29 @@ namespace Json {
// //////////////////////////////////////////////////////////////////
ValueIteratorBase::ValueIteratorBase()
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
: current_(), isNull_(true) {
}
-#else
- : isArray_(true), isNull_(true) {
- iterator_.array_ = ValueInternalArray::IteratorState();
-}
-#endif
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
ValueIteratorBase::ValueIteratorBase(
const Value::ObjectValues::iterator& current)
: current_(current), isNull_(false) {}
-#else
-ValueIteratorBase::ValueIteratorBase(
- const ValueInternalArray::IteratorState& state)
- : isArray_(true) {
- iterator_.array_ = state;
-}
-
-ValueIteratorBase::ValueIteratorBase(
- const ValueInternalMap::IteratorState& state)
- : isArray_(false) {
- iterator_.map_ = state;
-}
-#endif
Value& ValueIteratorBase::deref() const {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
return current_->second;
-#else
- if (isArray_)
- return ValueInternalArray::dereference(iterator_.array_);
- return ValueInternalMap::value(iterator_.map_);
-#endif
}
void ValueIteratorBase::increment() {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
++current_;
-#else
- if (isArray_)
- ValueInternalArray::increment(iterator_.array_);
- ValueInternalMap::increment(iterator_.map_);
-#endif
}
void ValueIteratorBase::decrement() {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
--current_;
-#else
- if (isArray_)
- ValueInternalArray::decrement(iterator_.array_);
- ValueInternalMap::decrement(iterator_.map_);
-#endif
}
ValueIteratorBase::difference_type
ValueIteratorBase::computeDistance(const SelfType& other) const {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
#ifdef JSON_USE_CPPTL_SMALLMAP
- return current_ - other.current_;
+ return other.current_ - current_;
#else
// Iterator for null value are initialized using the default
// constructor, which initialize current_ to the default
@@ -100,80 +61,58 @@ ValueIteratorBase::computeDistance(const SelfType& other) const {
}
return myDistance;
#endif
-#else
- if (isArray_)
- return ValueInternalArray::distance(iterator_.array_,
- other.iterator_.array_);
- return ValueInternalMap::distance(iterator_.map_, other.iterator_.map_);
-#endif
}
bool ValueIteratorBase::isEqual(const SelfType& other) const {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
if (isNull_) {
return other.isNull_;
}
return current_ == other.current_;
-#else
- if (isArray_)
- return ValueInternalArray::equals(iterator_.array_, other.iterator_.array_);
- return ValueInternalMap::equals(iterator_.map_, other.iterator_.map_);
-#endif
}
void ValueIteratorBase::copy(const SelfType& other) {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
current_ = other.current_;
isNull_ = other.isNull_;
-#else
- if (isArray_)
- iterator_.array_ = other.iterator_.array_;
- iterator_.map_ = other.iterator_.map_;
-#endif
}
Value ValueIteratorBase::key() const {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
const Value::CZString czstring = (*current_).first;
- if (czstring.c_str()) {
+ if (czstring.data()) {
if (czstring.isStaticString())
- return Value(StaticString(czstring.c_str()));
- return Value(czstring.c_str());
+ return Value(StaticString(czstring.data()));
+ return Value(czstring.data(), czstring.data() + czstring.length());
}
return Value(czstring.index());
-#else
- if (isArray_)
- return Value(ValueInternalArray::indexOf(iterator_.array_));
- bool isStatic;
- const char* memberName = ValueInternalMap::key(iterator_.map_, isStatic);
- if (isStatic)
- return Value(StaticString(memberName));
- return Value(memberName);
-#endif
}
UInt ValueIteratorBase::index() const {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
const Value::CZString czstring = (*current_).first;
- if (!czstring.c_str())
+ if (!czstring.data())
return czstring.index();
return Value::UInt(-1);
-#else
- if (isArray_)
- return Value::UInt(ValueInternalArray::indexOf(iterator_.array_));
- return Value::UInt(-1);
-#endif
}
-const char* ValueIteratorBase::memberName() const {
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
- const char* name = (*current_).first.c_str();
- return name ? name : "";
-#else
- if (!isArray_)
- return ValueInternalMap::key(iterator_.map_);
- return "";
-#endif
+JSONCPP_STRING ValueIteratorBase::name() const {
+ char const* keey;
+ char const* end;
+ keey = memberName(&end);
+ if (!keey) return JSONCPP_STRING();
+ return JSONCPP_STRING(keey, end);
+}
+
+char const* ValueIteratorBase::memberName() const {
+ const char* cname = (*current_).first.data();
+ return cname ? cname : "";
+}
+
+char const* ValueIteratorBase::memberName(char const** end) const {
+ const char* cname = (*current_).first.data();
+ if (!cname) {
+ *end = NULL;
+ return NULL;
+ }
+ *end = cname + (*current_).first.length();
+ return cname;
}
// //////////////////////////////////////////////////////////////////
@@ -186,19 +125,12 @@ const char* ValueIteratorBase::memberName() const {
ValueConstIterator::ValueConstIterator() {}
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
ValueConstIterator::ValueConstIterator(
const Value::ObjectValues::iterator& current)
: ValueIteratorBase(current) {}
-#else
-ValueConstIterator::ValueConstIterator(
- const ValueInternalArray::IteratorState& state)
- : ValueIteratorBase(state) {}
-ValueConstIterator::ValueConstIterator(
- const ValueInternalMap::IteratorState& state)
- : ValueIteratorBase(state) {}
-#endif
+ValueConstIterator::ValueConstIterator(ValueIterator const& other)
+ : ValueIteratorBase(other) {}
ValueConstIterator& ValueConstIterator::
operator=(const ValueIteratorBase& other) {
@@ -216,19 +148,13 @@ operator=(const ValueIteratorBase& other) {
ValueIterator::ValueIterator() {}
-#ifndef JSON_VALUE_USE_INTERNAL_MAP
ValueIterator::ValueIterator(const Value::ObjectValues::iterator& current)
: ValueIteratorBase(current) {}
-#else
-ValueIterator::ValueIterator(const ValueInternalArray::IteratorState& state)
- : ValueIteratorBase(state) {}
-
-ValueIterator::ValueIterator(const ValueInternalMap::IteratorState& state)
- : ValueIteratorBase(state) {}
-#endif
ValueIterator::ValueIterator(const ValueConstIterator& other)
- : ValueIteratorBase(other) {}
+ : ValueIteratorBase(other) {
+ throwRuntimeError("ConstIterator to Iterator should never be allowed.");
+}
ValueIterator::ValueIterator(const ValueIterator& other)
: ValueIteratorBase(other) {}
diff --git a/Utilities/cmjsoncpp/src/lib_json/json_writer.cpp b/Utilities/cmjsoncpp/src/lib_json/json_writer.cpp
index e3f4e53cf..6e6e57e1f 100644
--- a/Utilities/cmjsoncpp/src/lib_json/json_writer.cpp
+++ b/Utilities/cmjsoncpp/src/lib_json/json_writer.cpp
@@ -1,4 +1,4 @@
-// Copyright 2011 Baptiste Lepilleur
+// Copyright 2011 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
@@ -7,15 +7,62 @@
#include <json/writer.h>
#include "json_tool.h"
#endif // if !defined(JSON_IS_AMALGAMATION)
-#include <utility>
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <sstream>
#include <iomanip>
+#include <memory>
+#include <sstream>
+#include <utility>
+#include <set>
+#include <cassert>
+#include <cstring>
+#include <cstdio>
+
+#if defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1800 // Between VC++ 6.0 and VC++ 11.0
+#include <float.h>
+#define isfinite _finite
+#elif defined(__sun) && defined(__SVR4) //Solaris
+#if !defined(isfinite)
+#include <ieeefp.h>
+#define isfinite finite
+#endif
+#elif defined(_AIX)
+#if !defined(isfinite)
#include <math.h>
+#define isfinite finite
+#endif
+#elif defined(__hpux)
+#if !defined(isfinite)
+#if defined(__ia64) && !defined(finite)
+#define isfinite(x) ((sizeof(x) == sizeof(float) ? \
+ _Isfinitef(x) : _IsFinite(x)))
+#else
+#include <math.h>
+#define isfinite finite
+#endif
+#endif
+#else
+#include <cmath>
+#if !(defined(__QNXNTO__)) // QNX already defines isfinite
+#define isfinite std::isfinite
+#endif
+#endif
+
+#if defined(_MSC_VER)
+#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
+#define snprintf sprintf_s
+#elif _MSC_VER >= 1900 // VC++ 14.0 and above
+#define snprintf std::snprintf
+#else
+#define snprintf _snprintf
+#endif
+#elif defined(__ANDROID__) || defined(__QNXNTO__)
+#define snprintf snprintf
+#elif __cplusplus >= 201103L
+#if !defined(__MINGW32__) && !defined(__CYGWIN__)
+#define snprintf std::snprintf
+#endif
+#endif
-#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below
+#if defined(__BORLANDC__)
#include <float.h>
#define isfinite _finite
#define snprintf _snprintf
@@ -62,6 +109,12 @@
namespace Json {
+#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
+typedef std::unique_ptr<StreamWriter> StreamWriterPtr;
+#else
+typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
+#endif
+
static bool containsControlCharacter(const char* str) {
while (*str) {
if (isControlCharacter(*(str++)))
@@ -70,20 +123,33 @@ static bool containsControlCharacter(const char* str) {
return false;
}
-std::string valueToString(LargestInt value) {
+static bool containsControlCharacter0(const char* str, unsigned len) {
+ char const* end = str + len;
+ while (end != str) {
+ if (isControlCharacter(*str) || 0==*str)
+ return true;
+ ++str;
+ }
+ return false;
+}
+
+JSONCPP_STRING valueToString(LargestInt value) {
UIntToStringBuffer buffer;
char* current = buffer + sizeof(buffer);
- bool isNegative = value < 0;
- if (isNegative)
- value = -value;
- uintToString(LargestUInt(value), current);
- if (isNegative)
+ if (value == Value::minLargestInt) {
+ uintToString(LargestUInt(Value::maxLargestInt) + 1, current);
*--current = '-';
+ } else if (value < 0) {
+ uintToString(LargestUInt(-value), current);
+ *--current = '-';
+ } else {
+ uintToString(LargestUInt(value), current);
+ }
assert(current >= buffer);
return current;
}
-std::string valueToString(LargestUInt value) {
+JSONCPP_STRING valueToString(LargestUInt value) {
UIntToStringBuffer buffer;
char* current = buffer + sizeof(buffer);
uintToString(value, current);
@@ -93,68 +159,70 @@ std::string valueToString(LargestUInt value) {
#if defined(JSON_HAS_INT64)
-std::string valueToString(Int value) {
+JSONCPP_STRING valueToString(Int value) {
return valueToString(LargestInt(value));
}
-std::string valueToString(UInt value) {
+JSONCPP_STRING valueToString(UInt value) {
return valueToString(LargestUInt(value));
}
#endif // # if defined(JSON_HAS_INT64)
-std::string valueToString(double value) {
+namespace {
+JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int precision) {
// Allocate a buffer that is more than large enough to store the 16 digits of
// precision requested below.
- char buffer[32];
+ char buffer[36];
int len = -1;
-// Print into the buffer. We need not request the alternative representation
-// that always has a decimal point because JSON doesn't distingish the
-// concepts of reals and integers.
-#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with
- // visual studio 2005 to
- // avoid warning.
-#if defined(WINCE)
- len = _snprintf(buffer, sizeof(buffer), "%.16g", value);
-#else
- len = sprintf_s(buffer, sizeof(buffer), "%.16g", value);
-#endif
-#else
+ char formatString[15];
+ snprintf(formatString, sizeof(formatString), "%%.%dg", precision);
+
+ // Print into the buffer. We need not request the alternative representation
+ // that always has a decimal point because JSON doesn't distingish the
+ // concepts of reals and integers.
if (isfinite(value)) {
- len = snprintf(buffer, sizeof(buffer), "%.16g", value);
+ len = snprintf(buffer, sizeof(buffer), formatString, value);
+ fixNumericLocale(buffer, buffer + len);
+
+ // try to ensure we preserve the fact that this was given to us as a double on input
+ if (!strchr(buffer, '.') && !strchr(buffer, 'e')) {
+ strcat(buffer, ".0");
+ }
+
} else {
// IEEE standard states that NaN values will not compare to themselves
if (value != value) {
- len = snprintf(buffer, sizeof(buffer), "null");
+ len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "NaN" : "null");
} else if (value < 0) {
- len = snprintf(buffer, sizeof(buffer), "-1e+9999");
+ len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "-Infinity" : "-1e+9999");
} else {
- len = snprintf(buffer, sizeof(buffer), "1e+9999");
+ len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999");
}
- // For those, we do not need to call fixNumLoc, but it is fast.
}
-#endif
assert(len >= 0);
- fixNumericLocale(buffer, buffer + len);
return buffer;
}
+}
+
+JSONCPP_STRING valueToString(double value) { return valueToString(value, false, 17); }
-std::string valueToString(bool value) { return value ? "true" : "false"; }
+JSONCPP_STRING valueToString(bool value) { return value ? "true" : "false"; }
-std::string valueToQuotedString(const char* value) {
+JSONCPP_STRING valueToQuotedString(const char* value) {
if (value == NULL)
return "";
// Not sure how to handle unicode...
if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL &&
!containsControlCharacter(value))
- return std::string("\"") + value + "\"";
+ return JSONCPP_STRING("\"") + value + "\"";
// We have to walk value and escape any special characters.
- // Appending to std::string is not efficient, but this should be rare.
+ // Appending to JSONCPP_STRING is not efficient, but this should be rare.
// (Note: forward slashes are *not* rare, but I am not escaping them.)
- std::string::size_type maxsize =
+ JSONCPP_STRING::size_type maxsize =
strlen(value) * 2 + 3; // allescaped+quotes+NULL
- std::string result;
+ JSONCPP_STRING result;
result.reserve(maxsize); // to avoid lots of mallocs
result += "\"";
for (const char* c = value; *c != 0; ++c) {
@@ -190,7 +258,85 @@ std::string valueToQuotedString(const char* value) {
// sequence from occurring.
default:
if (isControlCharacter(*c)) {
- std::ostringstream oss;
+ JSONCPP_OSTRINGSTREAM oss;
+ oss << "\\u" << std::hex << std::uppercase << std::setfill('0')
+ << std::setw(4) << static_cast<int>(*c);
+ result += oss.str();
+ } else {
+ result += *c;
+ }
+ break;
+ }
+ }
+ result += "\"";
+ return result;
+}
+
+// https://github.com/upcaste/upcaste/blob/master/src/upcore/src/cstring/strnpbrk.cpp
+static char const* strnpbrk(char const* s, char const* accept, size_t n) {
+ assert((s || !n) && accept);
+
+ char const* const end = s + n;
+ for (char const* cur = s; cur < end; ++cur) {
+ int const c = *cur;
+ for (char const* a = accept; *a; ++a) {
+ if (*a == c) {
+ return cur;
+ }
+ }
+ }
+ return NULL;
+}
+static JSONCPP_STRING valueToQuotedStringN(const char* value, unsigned length) {
+ if (value == NULL)
+ return "";
+ // Not sure how to handle unicode...
+ if (strnpbrk(value, "\"\\\b\f\n\r\t", length) == NULL &&
+ !containsControlCharacter0(value, length))
+ return JSONCPP_STRING("\"") + value + "\"";
+ // We have to walk value and escape any special characters.
+ // Appending to JSONCPP_STRING is not efficient, but this should be rare.
+ // (Note: forward slashes are *not* rare, but I am not escaping them.)
+ JSONCPP_STRING::size_type maxsize =
+ length * 2 + 3; // allescaped+quotes+NULL
+ JSONCPP_STRING result;
+ result.reserve(maxsize); // to avoid lots of mallocs
+ result += "\"";
+ char const* end = value + length;
+ for (const char* c = value; c != end; ++c) {
+ switch (*c) {
+ case '\"':
+ result += "\\\"";
+ break;
+ case '\\':
+ result += "\\\\";
+ break;
+ case '\b':
+ result += "\\b";
+ break;
+ case '\f':
+ result += "\\f";
+ break;
+ case '\n':
+ result += "\\n";
+ break;
+ case '\r':
+ result += "\\r";
+ break;
+ case '\t':
+ result += "\\t";
+ break;
+ // case '/':
+ // Even though \/ is considered a legal escape in JSON, a bare
+ // slash is also legal, so I see no reason to escape it.
+ // (I hope I am not misunderstanding something.)
+ // blep notes: actually escaping \/ may be useful in javascript to avoid </
+ // sequence.
+ // Should add a flag to allow this compatibility mode and prevent this
+ // sequence from occurring.
+ default:
+ if ((isControlCharacter(*c)) || (*c == 0)) {
+ JSONCPP_OSTRINGSTREAM oss;
oss << "\\u" << std::hex << std::uppercase << std::setfill('0')
<< std::setw(4) << static_cast<int>(*c);
result += oss.str();
@@ -221,8 +367,8 @@ void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
-std::string FastWriter::write(const Value& root) {
- document_ = "";
+JSONCPP_STRING FastWriter::write(const Value& root) {
+ document_.clear();
writeValue(root);
if (!omitEndingLineFeed_)
document_ += "\n";
@@ -245,15 +391,21 @@ void FastWriter::writeValue(const Value& value) {
document_ += valueToString(value.asDouble());
break;
case stringValue:
- document_ += valueToQuotedString(value.asCString());
+ {
+ // Is NULL possible for value.string_? No.
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) document_ += valueToQuotedStringN(str, static_cast<unsigned>(end-str));
break;
+ }
case booleanValue:
document_ += valueToString(value.asBool());
break;
case arrayValue: {
document_ += '[';
- int size = value.size();
- for (int index = 0; index < size; ++index) {
+ ArrayIndex size = value.size();
+ for (ArrayIndex index = 0; index < size; ++index) {
if (index > 0)
document_ += ',';
writeValue(value[index]);
@@ -265,10 +417,10 @@ void FastWriter::writeValue(const Value& value) {
document_ += '{';
for (Value::Members::iterator it = members.begin(); it != members.end();
++it) {
- const std::string& name = *it;
+ const JSONCPP_STRING& name = *it;
if (it != members.begin())
document_ += ',';
- document_ += valueToQuotedString(name.c_str());
+ document_ += valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length()));
document_ += yamlCompatiblityEnabled_ ? ": " : ":";
writeValue(value[name]);
}
@@ -283,10 +435,10 @@ void FastWriter::writeValue(const Value& value) {
StyledWriter::StyledWriter()
: rightMargin_(74), indentSize_(3), addChildValues_() {}
-std::string StyledWriter::write(const Value& root) {
- document_ = "";
+JSONCPP_STRING StyledWriter::write(const Value& root) {
+ document_.clear();
addChildValues_ = false;
- indentString_ = "";
+ indentString_.clear();
writeCommentBeforeValue(root);
writeValue(root);
writeCommentAfterValueOnSameLine(root);
@@ -309,8 +461,15 @@ void StyledWriter::writeValue(const Value& value) {
pushValue(valueToString(value.asDouble()));
break;
case stringValue:
- pushValue(valueToQuotedString(value.asCString()));
+ {
+ // Is NULL possible for value.string_? No.
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
+ else pushValue("");
break;
+ }
case booleanValue:
pushValue(valueToString(value.asBool()));
break;
@@ -326,7 +485,7 @@ void StyledWriter::writeValue(const Value& value) {
indent();
Value::Members::iterator it = members.begin();
for (;;) {
- const std::string& name = *it;
+ const JSONCPP_STRING& name = *it;
const Value& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedString(name.c_str()));
@@ -390,23 +549,25 @@ void StyledWriter::writeArrayValue(const Value& value) {
}
bool StyledWriter::isMultineArray(const Value& value) {
- int size = value.size();
+ ArrayIndex const size = value.size();
bool isMultiLine = size * 3 >= rightMargin_;
childValues_.clear();
- for (int index = 0; index < size && !isMultiLine; ++index) {
+ for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
const Value& childValue = value[index];
- isMultiLine =
- isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
+ isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
childValue.size() > 0);
}
if (!isMultiLine) // check if line length > max line length
{
childValues_.reserve(size);
addChildValues_ = true;
- int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
- for (int index = 0; index < size; ++index) {
+ ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
+ for (ArrayIndex index = 0; index < size; ++index) {
+ if (hasCommentForValue(value[index])) {
+ isMultiLine = true;
+ }
writeValue(value[index]);
- lineLength += int(childValues_[index].length());
+ lineLength += static_cast<ArrayIndex>(childValues_[index].length());
}
addChildValues_ = false;
isMultiLine = isMultiLine || lineLength >= rightMargin_;
@@ -414,7 +575,7 @@ bool StyledWriter::isMultineArray(const Value& value) {
return isMultiLine;
}
-void StyledWriter::pushValue(const std::string& value) {
+void StyledWriter::pushValue(const JSONCPP_STRING& value) {
if (addChildValues_)
childValues_.push_back(value);
else
@@ -432,15 +593,15 @@ void StyledWriter::writeIndent() {
document_ += indentString_;
}
-void StyledWriter::writeWithIndent(const std::string& value) {
+void StyledWriter::writeWithIndent(const JSONCPP_STRING& value) {
writeIndent();
document_ += value;
}
-void StyledWriter::indent() { indentString_ += std::string(indentSize_, ' '); }
+void StyledWriter::indent() { indentString_ += JSONCPP_STRING(indentSize_, ' '); }
void StyledWriter::unindent() {
- assert(int(indentString_.size()) >= indentSize_);
+ assert(indentString_.size() >= indentSize_);
indentString_.resize(indentString_.size() - indentSize_);
}
@@ -450,26 +611,27 @@ void StyledWriter::writeCommentBeforeValue(const Value& root) {
document_ += "\n";
writeIndent();
- std::string normalizedComment = normalizeEOL(root.getComment(commentBefore));
- std::string::const_iterator iter = normalizedComment.begin();
- while (iter != normalizedComment.end()) {
+ const JSONCPP_STRING& comment = root.getComment(commentBefore);
+ JSONCPP_STRING::const_iterator iter = comment.begin();
+ while (iter != comment.end()) {
document_ += *iter;
- if (*iter == '\n' && *(iter + 1) == '/')
+ if (*iter == '\n' &&
+ (iter != comment.end() && *(iter + 1) == '/'))
writeIndent();
++iter;
}
- // Comments are stripped of newlines, so add one here
+ // Comments are stripped of trailing newlines, so add one here
document_ += "\n";
}
void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) {
if (root.hasComment(commentAfterOnSameLine))
- document_ += " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
+ document_ += " " + root.getComment(commentAfterOnSameLine);
if (root.hasComment(commentAfter)) {
document_ += "\n";
- document_ += normalizeEOL(root.getComment(commentAfter));
+ document_ += root.getComment(commentAfter);
document_ += "\n";
}
}
@@ -480,37 +642,21 @@ bool StyledWriter::hasCommentForValue(const Value& value) {
value.hasComment(commentAfter);
}
-std::string StyledWriter::normalizeEOL(const std::string& text) {
- std::string normalized;
- normalized.reserve(text.length());
- const char* begin = text.c_str();
- const char* end = begin + text.length();
- const char* current = begin;
- while (current != end) {
- char c = *current++;
- if (c == '\r') // mac or dos EOL
- {
- if (*current == '\n') // convert dos EOL
- ++current;
- normalized += '\n';
- } else // handle unix EOL & other char
- normalized += c;
- }
- return normalized;
-}
-
// Class StyledStreamWriter
// //////////////////////////////////////////////////////////////////
-StyledStreamWriter::StyledStreamWriter(std::string indentation)
+StyledStreamWriter::StyledStreamWriter(JSONCPP_STRING indentation)
: document_(NULL), rightMargin_(74), indentation_(indentation),
addChildValues_() {}
-void StyledStreamWriter::write(std::ostream& out, const Value& root) {
+void StyledStreamWriter::write(JSONCPP_OSTREAM& out, const Value& root) {
document_ = &out;
addChildValues_ = false;
- indentString_ = "";
+ indentString_.clear();
+ indented_ = true;
writeCommentBeforeValue(root);
+ if (!indented_) writeIndent();
+ indented_ = true;
writeValue(root);
writeCommentAfterValueOnSameLine(root);
*document_ << "\n";
@@ -532,8 +678,15 @@ void StyledStreamWriter::writeValue(const Value& value) {
pushValue(valueToString(value.asDouble()));
break;
case stringValue:
- pushValue(valueToQuotedString(value.asCString()));
+ {
+ // Is NULL possible for value.string_? No.
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
+ else pushValue("");
break;
+ }
case booleanValue:
pushValue(valueToString(value.asBool()));
break;
@@ -549,7 +702,7 @@ void StyledStreamWriter::writeValue(const Value& value) {
indent();
Value::Members::iterator it = members.begin();
for (;;) {
- const std::string& name = *it;
+ const JSONCPP_STRING& name = *it;
const Value& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedString(name.c_str()));
@@ -586,8 +739,10 @@ void StyledStreamWriter::writeArrayValue(const Value& value) {
if (hasChildValue)
writeWithIndent(childValues_[index]);
else {
- writeIndent();
+ if (!indented_) writeIndent();
+ indented_ = true;
writeValue(childValue);
+ indented_ = false;
}
if (++index == size) {
writeCommentAfterValueOnSameLine(childValue);
@@ -613,23 +768,25 @@ void StyledStreamWriter::writeArrayValue(const Value& value) {
}
bool StyledStreamWriter::isMultineArray(const Value& value) {
- int size = value.size();
+ ArrayIndex const size = value.size();
bool isMultiLine = size * 3 >= rightMargin_;
childValues_.clear();
- for (int index = 0; index < size && !isMultiLine; ++index) {
+ for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
const Value& childValue = value[index];
- isMultiLine =
- isMultiLine || ((childValue.isArray() || childValue.isObject()) &&
+ isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
childValue.size() > 0);
}
if (!isMultiLine) // check if line length > max line length
{
childValues_.reserve(size);
addChildValues_ = true;
- int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
- for (int index = 0; index < size; ++index) {
+ ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
+ for (ArrayIndex index = 0; index < size; ++index) {
+ if (hasCommentForValue(value[index])) {
+ isMultiLine = true;
+ }
writeValue(value[index]);
- lineLength += int(childValues_[index].length());
+ lineLength += static_cast<ArrayIndex>(childValues_[index].length());
}
addChildValues_ = false;
isMultiLine = isMultiLine || lineLength >= rightMargin_;
@@ -637,7 +794,7 @@ bool StyledStreamWriter::isMultineArray(const Value& value) {
return isMultiLine;
}
-void StyledStreamWriter::pushValue(const std::string& value) {
+void StyledStreamWriter::pushValue(const JSONCPP_STRING& value) {
if (addChildValues_)
childValues_.push_back(value);
else
@@ -645,24 +802,17 @@ void StyledStreamWriter::pushValue(const std::string& value) {
}
void StyledStreamWriter::writeIndent() {
- /*
- Some comments in this method would have been nice. ;-)
-
- if ( !document_.empty() )
- {
- char last = document_[document_.length()-1];
- if ( last == ' ' ) // already indented
- return;
- if ( last != '\n' ) // Comments may add new-line
- *document_ << '\n';
- }
- */
+ // blep intended this to look at the so-far-written string
+ // to determine whether we are already indented, but
+ // with a stream we cannot do that. So we rely on some saved state.
+ // The caller checks indented_.
*document_ << '\n' << indentString_;
}
-void StyledStreamWriter::writeWithIndent(const std::string& value) {
- writeIndent();
+void StyledStreamWriter::writeWithIndent(const JSONCPP_STRING& value) {
+ if (!indented_) writeIndent();
*document_ << value;
+ indented_ = false;
}
void StyledStreamWriter::indent() { indentString_ += indentation_; }
@@ -675,19 +825,30 @@ void StyledStreamWriter::unindent() {
void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
if (!root.hasComment(commentBefore))
return;
- *document_ << normalizeEOL(root.getComment(commentBefore));
- *document_ << "\n";
+
+ if (!indented_) writeIndent();
+ const JSONCPP_STRING& comment = root.getComment(commentBefore);
+ JSONCPP_STRING::const_iterator iter = comment.begin();
+ while (iter != comment.end()) {
+ *document_ << *iter;
+ if (*iter == '\n' &&
+ (iter != comment.end() && *(iter + 1) == '/'))
+ // writeIndent(); // would include newline
+ *document_ << indentString_;
+ ++iter;
+ }
+ indented_ = false;
}
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
if (root.hasComment(commentAfterOnSameLine))
- *document_ << " " + normalizeEOL(root.getComment(commentAfterOnSameLine));
+ *document_ << ' ' << root.getComment(commentAfterOnSameLine);
if (root.hasComment(commentAfter)) {
- *document_ << "\n";
- *document_ << normalizeEOL(root.getComment(commentAfter));
- *document_ << "\n";
+ writeIndent();
+ *document_ << root.getComment(commentAfter);
}
+ indented_ = false;
}
bool StyledStreamWriter::hasCommentForValue(const Value& value) {
@@ -696,28 +857,400 @@ bool StyledStreamWriter::hasCommentForValue(const Value& value) {
value.hasComment(commentAfter);
}
-std::string StyledStreamWriter::normalizeEOL(const std::string& text) {
- std::string normalized;
- normalized.reserve(text.length());
- const char* begin = text.c_str();
- const char* end = begin + text.length();
- const char* current = begin;
- while (current != end) {
- char c = *current++;
- if (c == '\r') // mac or dos EOL
+//////////////////////////
+// BuiltStyledStreamWriter
+
+/// Scoped enums are not available until C++11.
+struct CommentStyle {
+ /// Decide whether to write comments.
+ enum Enum {
+ None, ///< Drop all comments.
+ Most, ///< Recover odd behavior of previous versions (not implemented yet).
+ All ///< Keep all comments.
+ };
+};
+
+struct BuiltStyledStreamWriter : public StreamWriter
+{
+ BuiltStyledStreamWriter(
+ JSONCPP_STRING const& indentation,
+ CommentStyle::Enum cs,
+ JSONCPP_STRING const& colonSymbol,
+ JSONCPP_STRING const& nullSymbol,
+ JSONCPP_STRING const& endingLineFeedSymbol,
+ bool useSpecialFloats,
+ unsigned int precision);
+ int write(Value const& root, JSONCPP_OSTREAM* sout) JSONCPP_OVERRIDE;
+private:
+ void writeValue(Value const& value);
+ void writeArrayValue(Value const& value);
+ bool isMultineArray(Value const& value);
+ void pushValue(JSONCPP_STRING const& value);
+ void writeIndent();
+ void writeWithIndent(JSONCPP_STRING const& value);
+ void indent();
+ void unindent();
+ void writeCommentBeforeValue(Value const& root);
+ void writeCommentAfterValueOnSameLine(Value const& root);
+ static bool hasCommentForValue(const Value& value);
+
+ typedef std::vector<JSONCPP_STRING> ChildValues;
+
+ ChildValues childValues_;
+ JSONCPP_STRING indentString_;
+ unsigned int rightMargin_;
+ JSONCPP_STRING indentation_;
+ CommentStyle::Enum cs_;
+ JSONCPP_STRING colonSymbol_;
+ JSONCPP_STRING nullSymbol_;
+ JSONCPP_STRING endingLineFeedSymbol_;
+ bool addChildValues_ : 1;
+ bool indented_ : 1;
+ bool useSpecialFloats_ : 1;
+ unsigned int precision_;
+};
+BuiltStyledStreamWriter::BuiltStyledStreamWriter(
+ JSONCPP_STRING const& indentation,
+ CommentStyle::Enum cs,
+ JSONCPP_STRING const& colonSymbol,
+ JSONCPP_STRING const& nullSymbol,
+ JSONCPP_STRING const& endingLineFeedSymbol,
+ bool useSpecialFloats,
+ unsigned int precision)
+ : rightMargin_(74)
+ , indentation_(indentation)
+ , cs_(cs)
+ , colonSymbol_(colonSymbol)
+ , nullSymbol_(nullSymbol)
+ , endingLineFeedSymbol_(endingLineFeedSymbol)
+ , addChildValues_(false)
+ , indented_(false)
+ , useSpecialFloats_(useSpecialFloats)
+ , precision_(precision)
+{
+}
+int BuiltStyledStreamWriter::write(Value const& root, JSONCPP_OSTREAM* sout)
+{
+ sout_ = sout;
+ addChildValues_ = false;
+ indented_ = true;
+ indentString_.clear();
+ writeCommentBeforeValue(root);
+ if (!indented_) writeIndent();
+ indented_ = true;
+ writeValue(root);
+ writeCommentAfterValueOnSameLine(root);
+ *sout_ << endingLineFeedSymbol_;
+ sout_ = NULL;
+ return 0;
+}
+void BuiltStyledStreamWriter::writeValue(Value const& value) {
+ switch (value.type()) {
+ case nullValue:
+ pushValue(nullSymbol_);
+ break;
+ case intValue:
+ pushValue(valueToString(value.asLargestInt()));
+ break;
+ case uintValue:
+ pushValue(valueToString(value.asLargestUInt()));
+ break;
+ case realValue:
+ pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_));
+ break;
+ case stringValue:
+ {
+ // Is NULL is possible for value.string_? No.
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
+ else pushValue("");
+ break;
+ }
+ case booleanValue:
+ pushValue(valueToString(value.asBool()));
+ break;
+ case arrayValue:
+ writeArrayValue(value);
+ break;
+ case objectValue: {
+ Value::Members members(value.getMemberNames());
+ if (members.empty())
+ pushValue("{}");
+ else {
+ writeWithIndent("{");
+ indent();
+ Value::Members::iterator it = members.begin();
+ for (;;) {
+ JSONCPP_STRING const& name = *it;
+ Value const& childValue = value[name];
+ writeCommentBeforeValue(childValue);
+ writeWithIndent(valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length())));
+ *sout_ << colonSymbol_;
+ writeValue(childValue);
+ if (++it == members.end()) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ *sout_ << ",";
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("}");
+ }
+ } break;
+ }
+}
+
+void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
+ unsigned size = value.size();
+ if (size == 0)
+ pushValue("[]");
+ else {
+ bool isMultiLine = (cs_ == CommentStyle::All) || isMultineArray(value);
+ if (isMultiLine) {
+ writeWithIndent("[");
+ indent();
+ bool hasChildValue = !childValues_.empty();
+ unsigned index = 0;
+ for (;;) {
+ Value const& childValue = value[index];
+ writeCommentBeforeValue(childValue);
+ if (hasChildValue)
+ writeWithIndent(childValues_[index]);
+ else {
+ if (!indented_) writeIndent();
+ indented_ = true;
+ writeValue(childValue);
+ indented_ = false;
+ }
+ if (++index == size) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ *sout_ << ",";
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("]");
+ } else // output on a single line
{
- if (*current == '\n') // convert dos EOL
- ++current;
- normalized += '\n';
- } else // handle unix EOL & other char
- normalized += c;
+ assert(childValues_.size() == size);
+ *sout_ << "[";
+ if (!indentation_.empty()) *sout_ << " ";
+ for (unsigned index = 0; index < size; ++index) {
+ if (index > 0)
+ *sout_ << ((!indentation_.empty()) ? ", " : ",");
+ *sout_ << childValues_[index];
+ }
+ if (!indentation_.empty()) *sout_ << " ";
+ *sout_ << "]";
+ }
+ }
+}
+
+bool BuiltStyledStreamWriter::isMultineArray(Value const& value) {
+ ArrayIndex const size = value.size();
+ bool isMultiLine = size * 3 >= rightMargin_;
+ childValues_.clear();
+ for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
+ Value const& childValue = value[index];
+ isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
+ childValue.size() > 0);
+ }
+ if (!isMultiLine) // check if line length > max line length
+ {
+ childValues_.reserve(size);
+ addChildValues_ = true;
+ ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
+ for (ArrayIndex index = 0; index < size; ++index) {
+ if (hasCommentForValue(value[index])) {
+ isMultiLine = true;
+ }
+ writeValue(value[index]);
+ lineLength += static_cast<ArrayIndex>(childValues_[index].length());
+ }
+ addChildValues_ = false;
+ isMultiLine = isMultiLine || lineLength >= rightMargin_;
+ }
+ return isMultiLine;
+}
+
+void BuiltStyledStreamWriter::pushValue(JSONCPP_STRING const& value) {
+ if (addChildValues_)
+ childValues_.push_back(value);
+ else
+ *sout_ << value;
+}
+
+void BuiltStyledStreamWriter::writeIndent() {
+ // blep intended this to look at the so-far-written string
+ // to determine whether we are already indented, but
+ // with a stream we cannot do that. So we rely on some saved state.
+ // The caller checks indented_.
+
+ if (!indentation_.empty()) {
+ // In this case, drop newlines too.
+ *sout_ << '\n' << indentString_;
+ }
+}
+
+void BuiltStyledStreamWriter::writeWithIndent(JSONCPP_STRING const& value) {
+ if (!indented_) writeIndent();
+ *sout_ << value;
+ indented_ = false;
+}
+
+void BuiltStyledStreamWriter::indent() { indentString_ += indentation_; }
+
+void BuiltStyledStreamWriter::unindent() {
+ assert(indentString_.size() >= indentation_.size());
+ indentString_.resize(indentString_.size() - indentation_.size());
+}
+
+void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
+ if (cs_ == CommentStyle::None) return;
+ if (!root.hasComment(commentBefore))
+ return;
+
+ if (!indented_) writeIndent();
+ const JSONCPP_STRING& comment = root.getComment(commentBefore);
+ JSONCPP_STRING::const_iterator iter = comment.begin();
+ while (iter != comment.end()) {
+ *sout_ << *iter;
+ if (*iter == '\n' &&
+ (iter != comment.end() && *(iter + 1) == '/'))
+ // writeIndent(); // would write extra newline
+ *sout_ << indentString_;
+ ++iter;
}
- return normalized;
+ indented_ = false;
+}
+
+void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(Value const& root) {
+ if (cs_ == CommentStyle::None) return;
+ if (root.hasComment(commentAfterOnSameLine))
+ *sout_ << " " + root.getComment(commentAfterOnSameLine);
+
+ if (root.hasComment(commentAfter)) {
+ writeIndent();
+ *sout_ << root.getComment(commentAfter);
+ }
+}
+
+// static
+bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) {
+ return value.hasComment(commentBefore) ||
+ value.hasComment(commentAfterOnSameLine) ||
+ value.hasComment(commentAfter);
+}
+
+///////////////
+// StreamWriter
+
+StreamWriter::StreamWriter()
+ : sout_(NULL)
+{
+}
+StreamWriter::~StreamWriter()
+{
+}
+StreamWriter::Factory::~Factory()
+{}
+StreamWriterBuilder::StreamWriterBuilder()
+{
+ setDefaults(&settings_);
+}
+StreamWriterBuilder::~StreamWriterBuilder()
+{}
+StreamWriter* StreamWriterBuilder::newStreamWriter() const
+{
+ JSONCPP_STRING indentation = settings_["indentation"].asString();
+ JSONCPP_STRING cs_str = settings_["commentStyle"].asString();
+ bool eyc = settings_["enableYAMLCompatibility"].asBool();
+ bool dnp = settings_["dropNullPlaceholders"].asBool();
+ bool usf = settings_["useSpecialFloats"].asBool();
+ unsigned int pre = settings_["precision"].asUInt();
+ CommentStyle::Enum cs = CommentStyle::All;
+ if (cs_str == "All") {
+ cs = CommentStyle::All;
+ } else if (cs_str == "None") {
+ cs = CommentStyle::None;
+ } else {
+ throwRuntimeError("commentStyle must be 'All' or 'None'");
+ }
+ JSONCPP_STRING colonSymbol = " : ";
+ if (eyc) {
+ colonSymbol = ": ";
+ } else if (indentation.empty()) {
+ colonSymbol = ":";
+ }
+ JSONCPP_STRING nullSymbol = "null";
+ if (dnp) {
+ nullSymbol.clear();
+ }
+ if (pre > 17) pre = 17;
+ JSONCPP_STRING endingLineFeedSymbol;
+ return new BuiltStyledStreamWriter(
+ indentation, cs,
+ colonSymbol, nullSymbol, endingLineFeedSymbol, usf, pre);
+}
+static void getValidWriterKeys(std::set<JSONCPP_STRING>* valid_keys)
+{
+ valid_keys->clear();
+ valid_keys->insert("indentation");
+ valid_keys->insert("commentStyle");
+ valid_keys->insert("enableYAMLCompatibility");
+ valid_keys->insert("dropNullPlaceholders");
+ valid_keys->insert("useSpecialFloats");
+ valid_keys->insert("precision");
+}
+bool StreamWriterBuilder::validate(Json::Value* invalid) const
+{
+ Json::Value my_invalid;
+ if (!invalid) invalid = &my_invalid; // so we do not need to test for NULL
+ Json::Value& inv = *invalid;
+ std::set<JSONCPP_STRING> valid_keys;
+ getValidWriterKeys(&valid_keys);
+ Value::Members keys = settings_.getMemberNames();
+ size_t n = keys.size();
+ for (size_t i = 0; i < n; ++i) {
+ JSONCPP_STRING const& key = keys[i];
+ if (valid_keys.find(key) == valid_keys.end()) {
+ inv[key] = settings_[key];
+ }
+ }
+ return 0u == inv.size();
+}
+Value& StreamWriterBuilder::operator[](JSONCPP_STRING key)
+{
+ return settings_[key];
+}
+// static
+void StreamWriterBuilder::setDefaults(Json::Value* settings)
+{
+ //! [StreamWriterBuilderDefaults]
+ (*settings)["commentStyle"] = "All";
+ (*settings)["indentation"] = "\t";
+ (*settings)["enableYAMLCompatibility"] = false;
+ (*settings)["dropNullPlaceholders"] = false;
+ (*settings)["useSpecialFloats"] = false;
+ (*settings)["precision"] = 17;
+ //! [StreamWriterBuilderDefaults]
+}
+
+JSONCPP_STRING writeString(StreamWriter::Factory const& builder, Value const& root) {
+ JSONCPP_OSTRINGSTREAM sout;
+ StreamWriterPtr const writer(builder.newStreamWriter());
+ writer->write(root, &sout);
+ return sout.str();
}
-std::ostream& operator<<(std::ostream& sout, const Value& root) {
- Json::StyledStreamWriter writer;
- writer.write(sout, root);
+JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM& sout, Value const& root) {
+ StreamWriterBuilder builder;
+ StreamWriterPtr const writer(builder.newStreamWriter());
+ writer->write(root, &sout);
return sout;
}
diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt
index bfe6b131e..60c8316e3 100644
--- a/Utilities/cmlibarchive/CMakeLists.txt
+++ b/Utilities/cmlibarchive/CMakeLists.txt
@@ -60,7 +60,7 @@ 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)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
@@ -71,6 +71,7 @@ include(CTest)
OPTION(ENABLE_NETTLE "Enable use of Nettle" ON)
OPTION(ENABLE_OPENSSL "Enable use of OpenSSL" ON)
+OPTION(ENABLE_LZ4 "Enable the use of the system LZ4 library if found" ON)
OPTION(ENABLE_LZO "Enable the use of the system LZO library if found" OFF)
OPTION(ENABLE_LZMA "Enable the use of the system LZMA library if found" ON)
@@ -328,7 +329,7 @@ IF(ENABLE_LZO)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZO2 DEFAULT_MSG LZO2_LIBRARY LZO2_INCLUDE_DIR)
ELSE(ENABLE_LZO)
- SET(LIBZMA_FOUND FALSE) # Override cached value
+ SET(LZO2_FOUND FALSE) # Override cached value
ENDIF(ENABLE_LZO)
IF(LZO2_FOUND)
SET(HAVE_LIBLZO2 1)
@@ -347,15 +348,19 @@ IF(0) # CMake does not need LZ4 support in libarchive
#
# Find LZ4
#
-IF (LZ4_INCLUDE_DIR)
- # Already in cache, be silent
- SET(LZ4_FIND_QUIETLY TRUE)
-ENDIF (LZ4_INCLUDE_DIR)
+IF(ENABLE_LZ4)
+ IF (LZ4_INCLUDE_DIR)
+ # Already in cache, be silent
+ SET(LZ4_FIND_QUIETLY TRUE)
+ ENDIF (LZ4_INCLUDE_DIR)
-FIND_PATH(LZ4_INCLUDE_DIR lz4.h)
-FIND_LIBRARY(LZ4_LIBRARY NAMES lz4 liblz4)
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR)
+ FIND_PATH(LZ4_INCLUDE_DIR lz4.h)
+ FIND_LIBRARY(LZ4_LIBRARY NAMES lz4 liblz4)
+ INCLUDE(FindPackageHandleStandardArgs)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LZ4 DEFAULT_MSG LZ4_LIBRARY LZ4_INCLUDE_DIR)
+ELSE(ENABLE_LZ4)
+ SET(LZ4_FOUND FALSE) # Override cached value
+ENDIF(ENABLE_LZ4)
IF(LZ4_FOUND)
SET(HAVE_LIBLZ4 1)
SET(HAVE_LZ4_H 1)
@@ -372,6 +377,29 @@ ENDIF(LZ4_FOUND)
MARK_AS_ADVANCED(CLEAR LZ4_INCLUDE_DIR)
MARK_AS_ADVANCED(CLEAR LZ4_LIBRARY)
ENDIF()
+#
+# Find Zstd
+#
+IF (ZSTD_INCLUDE_DIR)
+ # Already in cache, be silent
+ SET(ZSTD_FIND_QUIETLY TRUE)
+ENDIF (ZSTD_INCLUDE_DIR)
+
+FIND_PATH(ZSTD_INCLUDE_DIR zstd.h)
+FIND_LIBRARY(ZSTD_LIBRARY NAMES zstd libzstd)
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZSTD DEFAULT_MSG ZSTD_LIBRARY ZSTD_INCLUDE_DIR)
+IF(ZSTD_FOUND)
+ SET(HAVE_ZSTD_H 1)
+ INCLUDE_DIRECTORIES(${ZSTD_INCLUDE_DIR})
+ LIST(APPEND ADDITIONAL_LIBS ${ZSTD_LIBRARY})
+ SET(HAVE_LIBZSTD 1)
+ #
+ # TODO: test for static library.
+ #
+ENDIF(ZSTD_FOUND)
+MARK_AS_ADVANCED(CLEAR ZSTD_INCLUDE_DIR)
+MARK_AS_ADVANCED(CLEAR ZSTD_LIBRARY)
#
# Check headers
@@ -422,6 +450,7 @@ int main(void) { return FS_IOC_GETFLAGS; }" HAVE_WORKING_FS_IOC_GETFLAGS)
LA_CHECK_INCLUDE_FILE("linux/magic.h" HAVE_LINUX_MAGIC_H)
LA_CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H)
+LA_CHECK_INCLUDE_FILE("membership.h" HAVE_MEMBERSHIP_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)
@@ -439,20 +468,24 @@ 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/extattr.h" HAVE_SYS_EXTATTR_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/richacl.h" HAVE_SYS_RICHACL_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/sysmacros.h" HAVE_SYS_SYSMACROS_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("sys/xattr.h" HAVE_SYS_XATTR_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)
@@ -461,6 +494,9 @@ LA_CHECK_INCLUDE_FILE("wctype.h" HAVE_WCTYPE_H)
LA_CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H)
IF(ENABLE_CNG)
LA_CHECK_INCLUDE_FILE("Bcrypt.h" HAVE_BCRYPT_H)
+ IF(HAVE_BCRYPT_H)
+ LIST(APPEND ADDITIONAL_LIBS "Bcrypt")
+ ENDIF(HAVE_BCRYPT_H)
ELSE(ENABLE_CNG)
UNSET(HAVE_BCRYPT_H CACHE)
ENDIF(ENABLE_CNG)
@@ -924,7 +960,6 @@ 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)
@@ -1024,6 +1059,10 @@ 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)
+# dirfd can be either a function or a macro.
+CHECK_C_SOURCE_COMPILES(
+ "#include <dirent.h>\nint main() {DIR *d = opendir(\".\"); return dirfd(d);}"
+ HAVE_DIRFD)
# Only detect readlinkat() if we also have AT_FDCWD in unistd.h.
# NOTE: linux requires fcntl.h for AT_FDCWD.
@@ -1256,60 +1295,105 @@ 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)
+ CHECK_SYMBOL_EXISTS(XATTR_NOFOLLOW "sys/xattr.h" HAVE_DECL_XATTR_NOFOLLOW)
+ IF(HAVE_SYS_XATTR_H AND HAVE_DECL_XATTR_NOFOLLOW)
+ CHECK_FUNCTION_EXISTS(fgetxattr HAVE_FGETXATTR)
+ CHECK_FUNCTION_EXISTS(flistxattr HAVE_FLISTXATTR)
+ CHECK_FUNCTION_EXISTS(fsetxattr HAVE_FSETXATTR)
+ CHECK_FUNCTION_EXISTS(getxattr HAVE_GETXATTR)
+ CHECK_FUNCTION_EXISTS(listxattr HAVE_LISTXATTR)
+ CHECK_FUNCTION_EXISTS(setxattr HAVE_SETXATTR)
+ IF(HAVE_FGETXATTR AND
+ HAVE_FLISTXATTR AND
+ HAVE_FSETXATTR AND
+ HAVE_GETXATTR AND
+ HAVE_LISTXATTR AND
+ HAVE_SETXATTR)
+ SET(ARCHIVE_XATTR_DARWIN TRUE)
+ ENDIF()
+ ELSEIF(HAVE_SYS_EXTATTR_H AND HAVE_DECL_EXTATTR_NAMESPACE_USER)
+ # FreeBSD xattr support
+ CHECK_FUNCTION_EXISTS(extattr_get_fd HAVE_EXTATTR_GET_FD)
+ CHECK_FUNCTION_EXISTS(extattr_get_file HAVE_EXTATTR_GET_FILE)
+ CHECK_FUNCTION_EXISTS(extattr_get_link HAVE_EXTATTR_GET_LINK)
+ CHECK_FUNCTION_EXISTS(extattr_list_fd HAVE_EXTATTR_LIST_FD)
+ CHECK_FUNCTION_EXISTS(extattr_list_file HAVE_EXTATTR_LIST_FILE)
+ CHECK_FUNCTION_EXISTS(extattr_list_link HAVE_EXTATTR_LIST_LINK)
+ CHECK_FUNCTION_EXISTS(extattr_set_fd HAVE_EXTATTR_SET_FD)
+ CHECK_FUNCTION_EXISTS(extattr_set_link HAVE_EXTATTR_SET_LINK)
+ IF(HAVE_EXTATTR_GET_FD AND
+ HAVE_EXTATTR_GET_FILE AND
+ HAVE_EXTATTR_GET_LINK AND
+ HAVE_EXTATTR_LIST_FD AND
+ HAVE_EXTATTR_LIST_FILE AND
+ HAVE_EXTATTR_LIST_LINK AND
+ HAVE_EXTATTR_SET_FD AND
+ HAVE_EXTATTR_SET_LINK)
+ SET(ARCHIVE_XATTR_FREEBSD TRUE)
+ ENDIF()
+ ELSEIF(HAVE_SYS_XATTR_H OR HAVE_ATTR_XATTR_H)
+ # Linux xattr support
+ 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)
+ IF(HAVE_FGETXATTR AND
+ HAVE_FLISTXATTR AND
+ HAVE_FSETXATTR AND
+ HAVE_GETXATTR AND
+ HAVE_LGETXATTR AND
+ HAVE_LISTXATTR AND
+ HAVE_LLISTXATTR AND
+ HAVE_LSETXATTR)
+ SET(ARCHIVE_XATTR_LINUX TRUE)
+ ENDIF()
+ ELSEIF(HAVE_SYS_EA_H)
+ # AIX xattr support
+ CHECK_FUNCTION_EXISTS(fgetea HAVE_FGETEA)
+ CHECK_FUNCTION_EXISTS(flistea HAVE_FLISTEA)
+ CHECK_FUNCTION_EXISTS(fsetea HAVE_FSETEA)
+ CHECK_FUNCTION_EXISTS(getea HAVE_GETEA)
+ CHECK_FUNCTION_EXISTS(lgetea HAVE_LGETEA)
+ CHECK_FUNCTION_EXISTS(listea HAVE_LISTEA)
+ CHECK_FUNCTION_EXISTS(llistea HAVE_LLISTEA)
+ CHECK_FUNCTION_EXISTS(lsetea HAVE_LSETEA)
+ IF(HAVE_FGETEA AND
+ HAVE_FLISTEA AND
+ HAVE_FSETEA AND
+ HAVE_GETEA AND
+ HAVE_LGETEA AND
+ HAVE_LISTEA AND
+ HAVE_LLISTEA AND
+ HAVE_LSETEA)
+ SET(ARCHIVE_XATTR_AIX TRUE)
+ ENDIF()
+ ENDIF()
+
+ IF(ARCHIVE_XATTR_DARWIN)
+ MESSAGE(STATUS "Extended attributes support: Darwin")
+ ELSEIF(ARCHIVE_XATTR_FREEBSD)
+ MESSAGE(STATUS "Extended attributes support: FreeBSD")
+ ELSEIF(ARCHIVE_XATTR_LINUX)
+ MESSAGE(STATUS "Extended attributes support: Linux")
+ ELSEIF(ARCHIVE_XATTR_AIX)
+ MESSAGE(STATUS "Extended attributes support: AIX")
+ ELSE()
+ MESSAGE(STATUS "Extended attributes support: none")
+ ENDIF()
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)
+ SET(ARCHIVE_XATTR_DARWIN FALSE)
+ SET(ARCHIVE_XATTR_FREEBSD FALSE)
+ SET(ARCHIVE_XATTR_LINUX FALSE)
+ SET(ARCHIVE_XATTR_AIX FALSE)
ENDIF(ENABLE_XATTR)
#
@@ -1321,78 +1405,212 @@ ENDIF(ENABLE_XATTR)
# which makes the following checks rather more complex than I would like.
#
IF(ENABLE_ACL)
+ # Solaris and derivates ACLs
+ CHECK_FUNCTION_EXISTS(acl HAVE_ACL)
+ CHECK_FUNCTION_EXISTS(facl HAVE_FACL)
+
+ # Libacl
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_fd_np HAVE_ACL_GET_FD_NP)
- 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)
- CHECK_SYMBOL_EXISTS(ACL_TYPE_NFS4 "${INCLUDES}" HAVE_ACL_TYPE_NFS4)
-
- # 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)
- CHECK_C_SOURCE_COMPILES("#include <sys/types.h>
+
+ CHECK_TYPE_EXISTS(acl_t "sys/types.h;sys/acl.h" HAVE_ACL_T)
+ CHECK_TYPE_EXISTS(acl_entry_t "sys/types.h;sys/acl.h" HAVE_ACL_ENTRY_T)
+ CHECK_TYPE_EXISTS(acl_permset_t "sys/types.h;sys/acl.h" HAVE_ACL_PERMSET_T)
+ CHECK_TYPE_EXISTS(acl_tag_t "sys/types.h;sys/acl.h" HAVE_ACL_TAG_T)
+
+ IF(HAVE_ACL AND HAVE_FACL)
+ CHECK_TYPE_EXISTS(aclent_t "sys/acl.h" HAVE_ACLENT_T)
+ IF(HAVE_ACLENT_T)
+ CHECK_SYMBOL_EXISTS(GETACL "sys/acl.h" HAVE_DECL_GETACL)
+ CHECK_SYMBOL_EXISTS(GETACLCNT "sys/acl.h" HAVE_DECL_GETACLCNT)
+ CHECK_SYMBOL_EXISTS(SETACL "sys/acl.h" HAVE_DECL_SETACL)
+ IF(HAVE_DECL_GETACL AND
+ HAVE_DECL_GETACLCNT AND
+ HAVE_DECL_SETACL)
+ SET(ARCHIVE_ACL_SUNOS TRUE)
+ ENDIF()
+ CHECK_TYPE_EXISTS(ace_t "sys/acl.h" HAVE_ACE_T)
+ IF(HAVE_ACE_T)
+ CHECK_SYMBOL_EXISTS(ACE_GETACL "sys/acl.h" HAVE_DECL_ACE_GETACL)
+ CHECK_SYMBOL_EXISTS(ACE_GETACLCNT "sys/acl.h" HAVE_DECL_ACE_GETACLCNT)
+ CHECK_SYMBOL_EXISTS(ACE_SETACL "sys/acl.h" HAVE_DECL_ACE_SETACL)
+ IF(HAVE_DECL_ACE_GETACL AND
+ HAVE_DECL_ACE_GETACLCNT AND
+ HAVE_DECL_ACE_SETACL)
+ SET(ARCHIVE_ACL_SUNOS_NFS4 TRUE)
+ ENDIF()
+ ENDIF(HAVE_ACE_T)
+ ENDIF(HAVE_ACLENT_T)
+ ENDIF(HAVE_ACL AND HAVE_FACL)
+
+ IF(HAVE_ACL_T AND HAVE_ACL_ENTRY_T AND HAVE_ACL_PERMSET_T AND HAVE_ACL_TAG_T)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_add_perm HAVE_ACL_ADD_PERM)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_clear_perms HAVE_ACL_CLEAR_PERMS)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_create_entry HAVE_ACL_CREATE_ENTRY)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_delete_def_file HAVE_ACL_DELETE_DEF_FILE)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_free HAVE_ACL_FREE)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_get_entry HAVE_ACL_GET_ENTRY)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_get_fd HAVE_ACL_GET_FD)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_get_file HAVE_ACL_GET_FILE)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_get_permset HAVE_ACL_GET_PERMSET)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_get_qualifier HAVE_ACL_GET_QUALIFIER)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_get_tag_type HAVE_ACL_GET_TAG_TYPE)
+ 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_file HAVE_ACL_SET_FILE)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_set_qualifier HAVE_ACL_SET_QUALIFIER)
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_set_tag_type HAVE_ACL_SET_TAG_TYPE)
+ IF(HAVE_ACL_ADD_PERM AND
+ HAVE_ACL_CLEAR_PERMS AND
+ HAVE_ACL_CREATE_ENTRY AND
+ HAVE_ACL_DELETE_DEF_FILE AND
+ HAVE_ACL_FREE AND
+ HAVE_ACL_GET_ENTRY AND
+ HAVE_ACL_GET_FD AND
+ HAVE_ACL_GET_FILE AND
+ HAVE_ACL_GET_PERMSET AND
+ HAVE_ACL_GET_QUALIFIER AND
+ HAVE_ACL_GET_TAG_TYPE AND
+ HAVE_ACL_INIT AND
+ HAVE_ACL_SET_FD AND
+ HAVE_ACL_SET_FILE AND
+ HAVE_ACL_SET_QUALIFIER AND
+ HAVE_ACL_SET_TAG_TYPE)
+ SET(HAVE_POSIX_ACL_FUNCS 1)
+ ENDIF()
+
+ CHECK_FUNCTION_EXISTS_GLIBC(acl_get_perm HAVE_ACL_GET_PERM)
+
+ IF(HAVE_POSIX_ACL_FUNCS AND HAVE_ACL_LIBACL_H AND HAVE_LIBACL AND
+ HAVE_ACL_GET_PERM)
+ SET(ARCHIVE_ACL_LIBACL TRUE)
+ ELSE()
+ CHECK_FUNCTION_EXISTS(acl_add_flag_np HAVE_ACL_ADD_FLAG_NP)
+ CHECK_FUNCTION_EXISTS(acl_clear_flags_np HAVE_ACL_CLEAR_FLAGS_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_brand_np HAVE_ACL_GET_BRAND_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_entry_type_np HAVE_ACL_GET_ENTRY_TYPE_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_flag_np HAVE_ACL_GET_FLAG_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_flagset_np HAVE_ACL_GET_FLAGSET_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_fd_np HAVE_ACL_GET_FD_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_link_np HAVE_ACL_GET_LINK_NP)
+ CHECK_FUNCTION_EXISTS(acl_get_perm_np HAVE_ACL_GET_PERM_NP)
+ CHECK_FUNCTION_EXISTS(acl_is_trivial_np HAVE_ACL_IS_TRIVIAL_NP)
+ CHECK_FUNCTION_EXISTS(acl_set_entry_type_np HAVE_ACL_SET_ENTRY_TYPE_NP)
+ CHECK_FUNCTION_EXISTS(acl_set_fd_np HAVE_ACL_SET_FD_NP)
+ CHECK_FUNCTION_EXISTS(acl_set_link_np HAVE_ACL_SET_LINK_NP)
+ CHECK_FUNCTION_EXISTS(mbr_gid_to_uuid HAVE_MBR_GID_TO_UUID)
+ CHECK_FUNCTION_EXISTS(mbr_uid_to_uuid HAVE_MBR_UID_TO_UUID)
+ CHECK_FUNCTION_EXISTS(mbr_uuid_to_id HAVE_MBR_UUID_TO_ID)
+
+ CHECK_C_SOURCE_COMPILES("#include <sys/types.h>
+#include <sys/acl.h>
+int main(void) { return ACL_TYPE_EXTENDED; }" HAVE_DECL_ACL_TYPE_EXTENDED)
+ CHECK_C_SOURCE_COMPILES("#include <sys/types.h>
#include <sys/acl.h>
-int main(void) { return ACL_TYPE_EXTENDED; }" HAVE_ACL_TYPE_EXTENDED)
+int main(void) { return ACL_SYNCHRONIZE; }" HAVE_DECL_ACL_SYNCHRONIZE)
+ CHECK_SYMBOL_EXISTS(ACL_TYPE_NFS4 "sys/acl.h" HAVE_DECL_ACL_TYPE_NFS4)
+ CHECK_SYMBOL_EXISTS(ACL_USER "sys/acl.h" HAVE_DECL_ACL_USER)
+
+ IF(HAVE_POSIX_ACL_FUNCS AND
+ HAVE_ACL_GET_FD_NP AND
+ HAVE_ACL_GET_PERM_NP AND
+ NOT HAVE_ACL_GET_PERM AND
+ HAVE_ACL_SET_FD_NP)
+ IF(HAVE_DECL_ACL_USER)
+ SET(ARCHIVE_ACL_FREEBSD TRUE)
+ IF(HAVE_DECL_ACL_TYPE_NFS4 AND
+ HAVE_ACL_ADD_FLAG_NP AND
+ HAVE_ACL_CLEAR_FLAGS_NP AND
+ HAVE_ACL_GET_BRAND_NP AND
+ HAVE_ACL_GET_ENTRY_TYPE_NP AND
+ HAVE_ACL_GET_FLAGSET_NP AND
+ HAVE_ACL_SET_ENTRY_TYPE_NP)
+ SET(ARCHIVE_ACL_FREEBSD_NFS4 TRUE)
+ ENDIF()
+ ELSEIF(HAVE_DECL_ACL_TYPE_EXTENDED AND
+ HAVE_MEMBERSHIP_H AND
+ HAVE_ACL_ADD_FLAG_NP AND
+ HAVE_ACL_CLEAR_FLAGS_NP AND
+ HAVE_ACL_GET_FLAGSET_NP AND
+ HAVE_ACL_GET_LINK_NP AND
+ HAVE_ACL_SET_LINK_NP AND
+ HAVE_MBR_UID_TO_UUID AND
+ HAVE_MBR_GID_TO_UUID AND
+ HAVE_MBR_UUID_TO_ID)
+ SET(ARCHIVE_ACL_DARWIN TRUE)
+ ENDIF()
+ ENDIF()
+ ENDIF()
+ ENDIF(HAVE_ACL_T AND HAVE_ACL_ENTRY_T AND HAVE_ACL_PERMSET_T AND
+ HAVE_ACL_TAG_T)
+
+ # Richacl
+ CHECK_LIBRARY_EXISTS(richacl "richacl_get_file" "" HAVE_LIBRICHACL)
+ IF(HAVE_LIBRICHACL)
+ SET(CMAKE_REQUIRED_LIBRARIES "richacl")
+ FIND_LIBRARY(RICHACL_LIBRARY NAMES richacl)
+ LIST(APPEND ADDITIONAL_LIBS ${RICHACL_LIBRARY})
+ ENDIF(HAVE_LIBRICHACL)
+
+ CHECK_STRUCT_HAS_MEMBER("struct richace" e_type "sys/richacl.h"
+ HAVE_STRUCT_RICHACE)
+ CHECK_STRUCT_HAS_MEMBER("struct richacl" a_flags "sys/richacl.h"
+ HAVE_STRUCT_RICHACL)
+
+ IF(HAVE_LIBRICHACL AND HAVE_STRUCT_RICHACL AND HAVE_STRUCT_RICHACE)
+ CHECK_FUNCTION_EXISTS_GLIBC(richacl_alloc HAVE_RICHACL_ALLOC)
+ CHECK_FUNCTION_EXISTS_GLIBC(richacl_equiv_mode HAVE_RICHACL_EQUIV_MODE)
+ CHECK_FUNCTION_EXISTS_GLIBC(richacl_free HAVE_RICHACL_FREE)
+ CHECK_FUNCTION_EXISTS_GLIBC(richacl_get_fd HAVE_RICHACL_GET_FD)
+ CHECK_FUNCTION_EXISTS_GLIBC(richacl_get_file HAVE_RICHACL_GET_FILE)
+ CHECK_FUNCTION_EXISTS_GLIBC(richacl_set_fd HAVE_RICHACL_SET_FD)
+ CHECK_FUNCTION_EXISTS_GLIBC(richacl_set_file HAVE_RICHACL_SET_FILE)
+ IF(HAVE_RICHACL_ALLOC AND
+ HAVE_RICHACL_EQUIV_MODE AND
+ HAVE_RICHACL_FREE AND
+ HAVE_RICHACL_GET_FD AND
+ HAVE_RICHACL_GET_FILE AND
+ HAVE_RICHACL_SET_FD AND
+ HAVE_RICHACL_SET_FILE)
+ SET(ARCHIVE_ACL_LIBRICHACL TRUE)
+ ENDIF()
+ ENDIF(HAVE_LIBRICHACL AND HAVE_STRUCT_RICHACL AND HAVE_STRUCT_RICHACE)
+
+ IF(ARCHIVE_ACL_DARWIN)
+ MESSAGE(STATUS "ACL support: Darwin (limited NFSv4)")
+ ELSEIF(ARCHIVE_ACL_FREEBSD_NFS4)
+ MESSAGE(STATUS "ACL support: FreeBSD (POSIX.1e and NFSv4)")
+ ELSEIF(ARCHIVE_ACL_FREEBSD)
+ MESSAGE(STATUS "ACL support: FreeBSD (POSIX.1e)")
+ ELSEIF(ARCHIVE_ACL_LIBACL OR ARCHIVE_ACL_LIBRICHACL)
+ IF(ARCHIVE_ACL_LIBACL AND ARCHIVE_ACL_LIBRICHACL)
+ MESSAGE(STATUS "ACL support: libacl (POSIX.1e) + librichacl (NFSv4)")
+ ELSEIF(ARCHIVE_ACL_LIBRICHACL)
+ MESSAGE(STATUS "ACL support: librichacl (NFSv4)")
+ ELSE()
+ MESSAGE(STATUS "ACL support: libacl (POSIX.1e)")
+ ENDIF()
+ ELSEIF(ARCHIVE_ACL_SUNOS_NFS4)
+ MESSAGE(STATUS "ACL support: Solaris (POSIX.1e and NFSv4)")
+ ELSEIF(ARCHIVE_ACL_SUNOS)
+ MESSAGE(STATUS "ACL support: Solaris (POSIX.1e)")
+ ELSE()
+ MESSAGE(STATUS "ACL support: none")
+ ENDIF()
- # Solaris and derivates ACLs
- CHECK_LIBRARY_EXISTS(sec "acl_get" "" HAVE_LIBSEC)
- IF(HAVE_LIBSEC)
- SET(CMAKE_REQUIRED_LIBRARIES "sec")
- FIND_LIBRARY(SEC_LIBRARY NAMES sec)
- LIST(APPEND ADDITIONAL_LIBS ${SEC_LIBRARY})
- ENDIF(HAVE_LIBSEC)
- #
- CHECK_TYPE_EXISTS(aclent_t "${INCLUDES}" HAVE_ACLENT_T)
- CHECK_TYPE_EXISTS(ace_t "${INCLUDES}" HAVE_ACE_T)
- CHECK_FUNCTION_EXISTS(acl_get HAVE_FACL_GET)
- CHECK_FUNCTION_EXISTS(facl_get HAVE_FACL_GET)
- CHECK_FUNCTION_EXISTS(acl_set HAVE_FACL_SET)
- CHECK_FUNCTION_EXISTS(facl_set HAVE_FACL_SET)
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_TYPE_NFS4 FALSE)
- SET(HAVE_ACL_USER FALSE)
- SET(HAVE_ACL_TYPE_EXTENDED FALSE)
- SET(HAVE_ACL_GET FALSE)
- SET(HAVE_ACLENT_T FALSE)
- SET(HAVE_ACE_T FALSE)
- SET(HAVE_FACL_GET FALSE)
- SET(HAVE_ACL_SET FALSE)
- SET(HAVE_FACL_SET FALSE)
+ SET(ARCHIVE_ACL_DARWIN FALSE)
+ SET(ARCHIVE_ACL_FREEBSD FALSE)
+ SET(ARCHIVE_ACL_FREEBSD_NFS4 FALSE)
+ SET(ARCHIVE_ACL_LIBACL FALSE)
+ SET(ARCHIVE_ACL_SUNOS FALSE)
+ SET(ARCHIVE_ACL_SUNOS_NFS4 FALSE)
ENDIF(ENABLE_ACL)
#
diff --git a/Utilities/cmlibarchive/build/cmake/config.h.in b/Utilities/cmlibarchive/build/cmake/config.h.in
index 55e04b9af..1851d81d0 100644
--- a/Utilities/cmlibarchive/build/cmake/config.h.in
+++ b/Utilities/cmlibarchive/build/cmake/config.h.in
@@ -182,6 +182,27 @@ typedef uint64_t uintmax_t;
/* Define ZLIB_WINAPI if zlib was built on Visual Studio. */
#cmakedefine ZLIB_WINAPI 1
+/* Darwin ACL support */
+#cmakedefine ARCHIVE_ACL_DARWIN 1
+
+/* FreeBSD ACL support */
+#cmakedefine ARCHIVE_ACL_FREEBSD 1
+
+/* FreeBSD NFSv4 ACL support */
+#cmakedefine ARCHIVE_ACL_FREEBSD_NFS4 1
+
+/* Linux POSIX.1e ACL support via libacl */
+#cmakedefine ARCHIVE_ACL_LIBACL 1
+
+/* Linux NFSv4 ACL support via librichacl */
+#cmakedefine ARCHIVE_ACL_LIBRICHACL 1
+
+/* Solaris ACL support */
+#cmakedefine ARCHIVE_ACL_SUNOS 1
+
+/* Solaris NFSv4 ACL support */
+#cmakedefine ARCHIVE_ACL_SUNOS_NFS4 1
+
/* MD5 via ARCHIVE_CRYPTO_MD5_LIBC supported. */
#cmakedefine ARCHIVE_CRYPTO_MD5_LIBC 1
@@ -284,6 +305,18 @@ typedef uint64_t uintmax_t;
/* SHA512 via ARCHIVE_CRYPTO_SHA512_WIN supported. */
#cmakedefine ARCHIVE_CRYPTO_SHA512_WIN 1
+/* AIX xattr support */
+#cmakedefine ARCHIVE_XATTR_AIX 1
+
+/* Darwin xattr support */
+#cmakedefine ARCHIVE_XATTR_DARWIN 1
+
+/* FreeBSD xattr support */
+#cmakedefine ARCHIVE_XATTR_FREEBSD 1
+
+/* Linux xattr support */
+#cmakedefine ARCHIVE_XATTR_LINUX 1
+
/* Version number of bsdcpio */
#cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}"
@@ -329,15 +362,6 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `acl_set_file' function. */
#cmakedefine HAVE_ACL_SET_FILE 1
-/* True for FreeBSD with NFSv4 ACL support */
-#cmakedefine HAVE_ACL_TYPE_NFS4 1
-
-/* True for MacOS ACL support */
-#cmakedefine HAVE_ACL_TYPE_EXTENDED 1
-
-/* True for systems with POSIX ACL support */
-#cmakedefine HAVE_ACL_USER 1
-
/* Define to 1 if you have the `arc4random_buf' function. */
#cmakedefine HAVE_ARC4RANDOM_BUF 1
@@ -374,6 +398,34 @@ typedef uint64_t uintmax_t;
/* 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 `ACE_GETACL', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_ACE_GETACL 1
+
+/* Define to 1 if you have the declaration of `ACE_GETACLCNT', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_ACE_GETACLCNT 1
+
+/* Define to 1 if you have the declaration of `ACE_SETACL', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_ACE_SETACL 1
+
+/* Define to 1 if you have the declaration of `ACL_SYNCHRONIZE', and to 0 if
+ you don't. */
+#cmakedefine HAVE_DECL_ACL_SYNCHRONIZE 1
+
+/* Define to 1 if you have the declaration of `ACL_TYPE_EXTENDED', and to 0 if
+ you don't. */
+#cmakedefine HAVE_DECL_ACL_TYPE_EXTENDED 1
+
+/* Define to 1 if you have the declaration of `ACL_TYPE_NFS4', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_ACL_TYPE_NFS4 1
+
+/* Define to 1 if you have the declaration of `ACL_USER', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_ACL_USER 1
+
/* Define to 1 if you have the declaration of `INT32_MAX', and to 0 if you
don't. */
#cmakedefine HAVE_DECL_INT32_MAX 1
@@ -398,6 +450,10 @@ typedef uint64_t uintmax_t;
don't. */
#cmakedefine HAVE_DECL_INTMAX_MIN 1
+/* Define to 1 if you have the declaration of `SETACL', and to 0 if you don't.
+ */
+#cmakedefine HAVE_DECL_SETACL 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
@@ -422,6 +478,10 @@ typedef uint64_t uintmax_t;
don't. */
#cmakedefine HAVE_DECL_UINTMAX_MAX 1
+/* Define to 1 if you have the declaration of `XATTR_NOFOLLOW', and to 0 if
+ you don't. */
+#cmakedefine HAVE_DECL_XATTR_NOFOLLOW 1
+
/* Define to 1 if you have the <direct.h> header file. */
#cmakedefine HAVE_DIRECT_H 1
@@ -471,6 +531,14 @@ typedef uint64_t uintmax_t;
/* 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 declaration of `GETACL', and to 0 if you don't.
+ */
+#cmakedefine HAVE_DECL_GETACL 1
+
+/* Define to 1 if you have the declaration of `GETACLCNT', and to 0 if you
+ don't. */
+#cmakedefine HAVE_DECL_GETACLCNT 1
+
/* Define to 1 if you have the `fchdir' function. */
#cmakedefine HAVE_FCHDIR 1
@@ -660,6 +728,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `z' library (-lz). */
#cmakedefine HAVE_LIBZ 1
+/* Define to 1 if you have the `zstd' library (-lzstd). */
+#cmakedefine HAVE_LIBZSTD 1
+
/* Define to 1 if you have the <limits.h> header file. */
#cmakedefine HAVE_LIMITS_H 1
@@ -748,6 +819,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the `mbrtowc' function. */
#cmakedefine HAVE_MBRTOWC 1
+/* Define to 1 if you have the <membership.h> header file. */
+#cmakedefine HAVE_MEMBERSHIP_H 1
+
/* Define to 1 if you have the `memmove' function. */
#cmakedefine HAVE_MEMMOVE 1
@@ -985,6 +1059,9 @@ typedef uint64_t uintmax_t;
/* 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/richacl.h> header file. */
+#cmakedefine HAVE_SYS_RICHACL_H 1
+
/* Define to 1 if you have the <sys/select.h> header file. */
#cmakedefine HAVE_SYS_SELECT_H 1
@@ -997,6 +1074,10 @@ typedef uint64_t uintmax_t;
/* 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/sysmacros.h> header file. */
+#cmakedefine HAVE_SYS_SYSMACROS_H 1
+
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H 1
@@ -1111,6 +1192,9 @@ typedef uint64_t uintmax_t;
/* Define to 1 if you have the <zlib.h> header file. */
#cmakedefine HAVE_ZLIB_H 1
+/* Define to 1 if you have the <zstd.h> header file. */
+#cmakedefine HAVE_ZSTD_H 1
+
/* Define to 1 if you have the `_ctime64_s' function. */
#cmakedefine HAVE__CTIME64_S 1
diff --git a/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in
index 95d715951..4b631e635 100644
--- a/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in
+++ b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in
@@ -7,5 +7,6 @@ Name: libarchive
Description: library that can create and read several streaming archive formats
Version: @VERSION@
Cflags: -I${includedir}
+Cflags.private: -DLIBARCHIVE_STATIC
Libs: -L${libdir} -larchive
Libs.private: @LIBS@
diff --git a/Utilities/cmlibarchive/build/version b/Utilities/cmlibarchive/build/version
index ef8345726..2427eab0f 100644
--- a/Utilities/cmlibarchive/build/version
+++ b/Utilities/cmlibarchive/build/version
@@ -1 +1 @@
-3003001
+3003003
diff --git a/Utilities/cmlibarchive/libarchive/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
index d412c80dc..e38d66453 100644
--- a/Utilities/cmlibarchive/libarchive/CMakeLists.txt
+++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt
@@ -14,6 +14,7 @@ SET(include_HEADERS
# Sources and private headers
SET(libarchive_SOURCES
archive_acl.c
+ archive_acl_private.h
archive_check_magic.c
archive_cmdline.c
archive_cmdline_private.h
@@ -47,6 +48,8 @@ SET(libarchive_SOURCES
archive_pathmatch.c
archive_pathmatch.h
archive_platform.h
+ archive_platform_acl.h
+ archive_platform_xattr.h
archive_ppmd_private.h
archive_ppmd7.c
archive_ppmd7_private.h
@@ -85,6 +88,7 @@ SET(libarchive_SOURCES
archive_read_support_filter_rpm.c
archive_read_support_filter_uu.c
archive_read_support_filter_xz.c
+ archive_read_support_filter_zstd.c
archive_read_support_format_7zip.c
archive_read_support_format_all.c
archive_read_support_format_ar.c
@@ -106,9 +110,9 @@ SET(libarchive_SOURCES
archive_string_composition.h
archive_string_sprintf.c
archive_util.c
+ archive_version_details.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
@@ -131,6 +135,7 @@ SET(libarchive_SOURCES
archive_write_add_filter_program.c
archive_write_add_filter_uuencode.c
archive_write_add_filter_xz.c
+ archive_write_add_filter_zstd.c
archive_write_set_format.c
archive_write_set_format_7zip.c
archive_write_set_format_ar.c
@@ -210,6 +215,16 @@ IF(WIN32 AND NOT CYGWIN)
LIST(APPEND libarchive_SOURCES filter_fork_windows.c)
ENDIF(WIN32 AND NOT CYGWIN)
+IF(ARCHIVE_ACL_DARWIN)
+ LIST(APPEND libarchive_SOURCES archive_disk_acl_darwin.c)
+ELSEIF(ARCHIVE_ACL_FREEBSD)
+ LIST(APPEND libarchive_SOURCES archive_disk_acl_freebsd.c)
+ELSEIF(ARCHIVE_ACL_LIBACL)
+ LIST(APPEND libarchive_SOURCES archive_disk_acl_linux.c)
+ELSEIF(ARCHIVE_ACL_SUNOS)
+ LIST(APPEND libarchive_SOURCES archive_disk_acl_sunos.c)
+ENDIF()
+
# 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
index cfb5c48b2..f3ebbfe42 100644
--- a/Utilities/cmlibarchive/libarchive/archive.h
+++ b/Utilities/cmlibarchive/libarchive/archive.h
@@ -36,7 +36,7 @@
* assert that ARCHIVE_VERSION_NUMBER >= 2012108.
*/
/* Note: Compiler will complain if this does not match archive_entry.h! */
-#define ARCHIVE_VERSION_NUMBER 3003001
+#define ARCHIVE_VERSION_NUMBER 3003003
#include <sys/stat.h>
#include <stddef.h> /* for wchar_t */
@@ -152,7 +152,7 @@ __LA_DECL int archive_version_number(void);
/*
* Textual name/version of the library, useful for version displays.
*/
-#define ARCHIVE_VERSION_ONLY_STRING "3.3.1"
+#define ARCHIVE_VERSION_ONLY_STRING "3.3.3"
#define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
__LA_DECL const char * archive_version_string(void);
@@ -174,6 +174,7 @@ __LA_DECL const char * archive_zlib_version(void);
__LA_DECL const char * archive_liblzma_version(void);
__LA_DECL const char * archive_bzlib_version(void);
__LA_DECL const char * archive_liblz4_version(void);
+__LA_DECL const char * archive_libzstd_version(void);
/* Declare our basic types. */
struct archive;
@@ -273,6 +274,7 @@ typedef const char *archive_passphrase_callback(struct archive *,
#define ARCHIVE_FILTER_LZOP 11
#define ARCHIVE_FILTER_GRZIP 12
#define ARCHIVE_FILTER_LZ4 13
+#define ARCHIVE_FILTER_ZSTD 14
#if ARCHIVE_VERSION_NUMBER < 4000000
#define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE
@@ -430,6 +432,7 @@ __LA_DECL int archive_read_support_filter_program_signature
__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_filter_zstd(struct archive *);
__LA_DECL int archive_read_support_format_7zip(struct archive *);
__LA_DECL int archive_read_support_format_all(struct archive *);
@@ -775,6 +778,7 @@ __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 *);
+__LA_DECL int archive_write_add_filter_zstd(struct archive *);
/* A convenience function to set the format based on the code or name. */
diff --git a/Utilities/cmlibarchive/libarchive/archive_acl.c b/Utilities/cmlibarchive/libarchive/archive_acl.c
index b8b6b6364..4736531af 100644
--- a/Utilities/cmlibarchive/libarchive/archive_acl.c
+++ b/Utilities/cmlibarchive/libarchive/archive_acl.c
@@ -1159,6 +1159,7 @@ archive_acl_from_text_w(struct archive_acl *acl, const wchar_t *text,
switch (want_type) {
case ARCHIVE_ENTRY_ACL_TYPE_POSIX1E:
want_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
+ __LA_FALLTHROUGH;
case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
numfields = 5;
@@ -1626,6 +1627,7 @@ archive_acl_from_text_l(struct archive_acl *acl, const char *text,
switch (want_type) {
case ARCHIVE_ENTRY_ACL_TYPE_POSIX1E:
want_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
+ __LA_FALLTHROUGH;
case ARCHIVE_ENTRY_ACL_TYPE_ACCESS:
case ARCHIVE_ENTRY_ACL_TYPE_DEFAULT:
numfields = 5;
diff --git a/Utilities/cmlibarchive/libarchive/archive_check_magic.c b/Utilities/cmlibarchive/libarchive/archive_check_magic.c
index c695e582a..288ce2338 100644
--- a/Utilities/cmlibarchive/libarchive/archive_check_magic.c
+++ b/Utilities/cmlibarchive/libarchive/archive_check_magic.c
@@ -62,7 +62,7 @@ errmsg(const char *m)
}
}
-static void
+static __LA_DEAD void
diediedie(void)
{
#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
diff --git a/Utilities/cmlibarchive/libarchive/archive_cmdline.c b/Utilities/cmlibarchive/libarchive/archive_cmdline.c
index 7d3bac53b..5c519cd17 100644
--- a/Utilities/cmlibarchive/libarchive/archive_cmdline.c
+++ b/Utilities/cmlibarchive/libarchive/archive_cmdline.c
@@ -100,10 +100,10 @@ get_argument(struct archive_string *as, const char *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
+ * 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.
+ * Returns ARCHIVE_FATAL if no memory.
*/
int
__archive_cmdline_parse(struct archive_cmdline *data, const char *cmd)
diff --git a/Utilities/cmlibarchive/libarchive/archive_cryptor.c b/Utilities/cmlibarchive/libarchive/archive_cryptor.c
index ced52fd70..71967c9d4 100644
--- a/Utilities/cmlibarchive/libarchive/archive_cryptor.c
+++ b/Utilities/cmlibarchive/libarchive/archive_cryptor.c
@@ -153,7 +153,7 @@ aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
CCCryptorStatus r;
r = CCCryptorReset(ref, NULL);
- if (r != kCCSuccess)
+ if (r != kCCSuccess && r != kCCUnimplemented)
return -1;
r = CCCryptorUpdate(ref, ctx->nonce, AES_BLOCK_SIZE, ctx->encr_buf,
AES_BLOCK_SIZE, NULL);
diff --git a/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
index 0ca544b57..b9759220d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_cryptor_private.h
@@ -64,7 +64,7 @@ typedef struct {
} archive_crypto_ctx;
#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(HAVE_BCRYPT_H)
-#include <Bcrypt.h>
+#include <bcrypt.h>
/* Common in other bcrypt implementations, but missing from VS2008. */
#ifndef BCRYPT_SUCCESS
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.3 b/Utilities/cmlibarchive/libarchive/archive_entry.3
index f5e22af85..f75916c9e 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.3
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd Feburary 2, 2012
+.Dd February 2, 2012
.Dt ARCHIVE_ENTRY 3
.Os
.Sh NAME
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.c b/Utilities/cmlibarchive/libarchive/archive_entry.c
index 10eff11b2..f722bbe85 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry.c
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.c
@@ -401,7 +401,7 @@ archive_entry_fflags_text(struct archive_entry *entry)
return (NULL);
}
-int64_t
+la_int64_t
archive_entry_gid(struct archive_entry *entry)
{
return (entry->ae_stat.aest_gid);
@@ -502,7 +502,7 @@ _archive_entry_hardlink_l(struct archive_entry *entry,
return (archive_mstring_get_mbs_l(&entry->ae_hardlink, p, len, sc));
}
-int64_t
+la_int64_t
archive_entry_ino(struct archive_entry *entry)
{
return (entry->ae_stat.aest_ino);
@@ -514,7 +514,7 @@ archive_entry_ino_is_set(struct archive_entry *entry)
return (entry->ae_set & AE_SET_INO);
}
-int64_t
+la_int64_t
archive_entry_ino64(struct archive_entry *entry)
{
return (entry->ae_stat.aest_ino);
@@ -627,7 +627,7 @@ archive_entry_rdevminor(struct archive_entry *entry)
return minor(entry->ae_stat.aest_rdev);
}
-int64_t
+la_int64_t
archive_entry_size(struct archive_entry *entry)
{
return (entry->ae_stat.aest_size);
@@ -715,7 +715,7 @@ _archive_entry_symlink_l(struct archive_entry *entry,
return (archive_mstring_get_mbs_l( &entry->ae_symlink, p, len, sc));
}
-int64_t
+la_int64_t
archive_entry_uid(struct archive_entry *entry)
{
return (entry->ae_stat.aest_uid);
@@ -819,7 +819,7 @@ archive_entry_copy_fflags_text_w(struct archive_entry *entry,
}
void
-archive_entry_set_gid(struct archive_entry *entry, int64_t g)
+archive_entry_set_gid(struct archive_entry *entry, la_int64_t g)
{
entry->stat_valid = 0;
entry->ae_stat.aest_gid = g;
@@ -868,7 +868,7 @@ _archive_entry_copy_gname_l(struct archive_entry *entry,
}
void
-archive_entry_set_ino(struct archive_entry *entry, int64_t ino)
+archive_entry_set_ino(struct archive_entry *entry, la_int64_t ino)
{
entry->stat_valid = 0;
entry->ae_set |= AE_SET_INO;
@@ -876,7 +876,7 @@ archive_entry_set_ino(struct archive_entry *entry, int64_t ino)
}
void
-archive_entry_set_ino64(struct archive_entry *entry, int64_t ino)
+archive_entry_set_ino64(struct archive_entry *entry, la_int64_t ino)
{
entry->stat_valid = 0;
entry->ae_set |= AE_SET_INO;
@@ -1209,7 +1209,7 @@ archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m)
}
void
-archive_entry_set_size(struct archive_entry *entry, int64_t s)
+archive_entry_set_size(struct archive_entry *entry, la_int64_t s)
{
entry->stat_valid = 0;
entry->ae_stat.aest_size = s;
@@ -1306,7 +1306,7 @@ _archive_entry_copy_symlink_l(struct archive_entry *entry,
}
void
-archive_entry_set_uid(struct archive_entry *entry, int64_t u)
+archive_entry_set_uid(struct archive_entry *entry, la_int64_t u)
{
entry->stat_valid = 0;
entry->ae_stat.aest_uid = u;
@@ -1491,7 +1491,7 @@ archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type,
* the style of the generated ACL.
*/
wchar_t *
-archive_entry_acl_to_text_w(struct archive_entry *entry, ssize_t *len,
+archive_entry_acl_to_text_w(struct archive_entry *entry, la_ssize_t *len,
int flags)
{
return (archive_acl_to_text_w(&entry->acl, len, flags,
@@ -1499,7 +1499,7 @@ archive_entry_acl_to_text_w(struct archive_entry *entry, ssize_t *len,
}
char *
-archive_entry_acl_to_text(struct archive_entry *entry, ssize_t *len,
+archive_entry_acl_to_text(struct archive_entry *entry, la_ssize_t *len,
int flags)
{
return (archive_acl_to_text_l(&entry->acl, len, flags, NULL));
@@ -1638,7 +1638,7 @@ _archive_entry_acl_text_l(struct archive_entry *entry, int flags,
* SUCH DAMAGE.
*/
-static struct flag {
+static const struct flag {
const char *name;
const wchar_t *wname;
unsigned long set;
@@ -1708,6 +1708,9 @@ static struct flag {
#ifdef UF_COMPRESSED
{ "nocompressed",L"nocompressed", UF_COMPRESSED, 0 },
#endif
+#ifdef UF_HIDDEN
+ { "nohidden", L"nohidden", UF_HIDDEN, 0 },
+#endif
#if defined(FS_UNRM_FL)
{ "nouunlink", L"nouunlink", FS_UNRM_FL, 0},
#elif defined(EXT2_UNRM_FL)
@@ -1840,7 +1843,7 @@ ae_fflagstostr(unsigned long bitset, unsigned long bitclear)
char *string, *dp;
const char *sp;
unsigned long bits;
- struct flag *flag;
+ const struct flag *flag;
size_t length;
bits = bitset | bitclear;
@@ -1892,7 +1895,7 @@ static const char *
ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp)
{
const char *start, *end;
- struct flag *flag;
+ const struct flag *flag;
unsigned long set, clear;
const char *failed;
@@ -1960,7 +1963,7 @@ static const wchar_t *
ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp)
{
const wchar_t *start, *end;
- struct flag *flag;
+ const struct flag *flag;
unsigned long set, clear;
const wchar_t *failed;
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.h b/Utilities/cmlibarchive/libarchive/archive_entry.h
index 6e0225b04..a9134f6b6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry.h
+++ b/Utilities/cmlibarchive/libarchive/archive_entry.h
@@ -30,7 +30,7 @@
#define ARCHIVE_ENTRY_H_INCLUDED
/* Note: Compiler will complain if this does not match archive.h! */
-#define ARCHIVE_VERSION_NUMBER 3003001
+#define ARCHIVE_VERSION_NUMBER 3003003
/*
* Note: archive_entry.h is for use outside of libarchive; the
@@ -42,6 +42,7 @@
#include <sys/types.h>
#include <stddef.h> /* for wchar_t */
+#include <stdint.h>
#include <time.h>
#if defined(_WIN32) && !defined(__CYGWIN__)
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
index c5115f727..534dbfac6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3
@@ -32,7 +32,7 @@
.Nm archive_entry_acl_clear ,
.Nm archive_entry_acl_count ,
.Nm archive_entry_acl_from_text ,
-.Nm archive_entry_acl_from_text_w,
+.Nm archive_entry_acl_from_text_w ,
.Nm archive_entry_acl_next ,
.Nm archive_entry_acl_next_w ,
.Nm archive_entry_acl_reset ,
@@ -267,7 +267,7 @@ Only inherit, do not apply the permission on the directory itself.
.It Dv ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT ( Sy n )
Do not propagate inherit flags. Only first-level entries inherit ACLs.
.It Dv ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS ( Sy S )
-Trigger alarm or audit on succesful access.
+Trigger alarm or audit on successful access.
.It Dv ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS ( Sy F )
Trigger alarm or audit on failed access.
.It Dv ARCHIVE_ENTRY_ACL_ENTRY_INHERITED ( Sy I )
@@ -279,7 +279,7 @@ 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. An archive enry cannot contain both POSIX.1e and NFSv4 ACL
+are updated. An archive entry cannot contain both POSIX.1e and NFSv4 ACL
entries.
.Pp
.Fn archive_entry_acl_clear
@@ -303,7 +303,7 @@ for POSIX.1e ACLs and
for NFSv4 ACLs. For POSIX.1e ACLs 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.
+the three non-extended ACLs are added.
.Pp
.Fn archive_entry_acl_from_text
and
@@ -367,7 +367,7 @@ and
.Fn archive_entry_acl_to_text_w
convert the ACL entries for the given type into a
.Pq wide
-string of ACL entries separated by newline. If the the pointer
+string of ACL entries separated by newline. If the pointer
.Fa len_p
is not NULL, then the function shall return the length of the string
.Pq not including the NULL terminator
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
index fd22cf7e2..f647212a9 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3
@@ -31,25 +31,25 @@
.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_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_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_update_pathname_utf8 ,
.Nm archive_entry_sourcepath ,
.Nm archive_entry_copy_sourcepath ,
-.Nm archive_entry_symlink,
-.Nm archive_entry_symlink_w,
+.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
+.Nm archive_entry_update_symlink_utf8
.Nd functions for manipulating path names in archive entry descriptions
.Sh LIBRARY
Streaming Archive Library (libarchive, -larchive)
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
index 340c5ea72..aae3648bb 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3
@@ -34,8 +34,8 @@
.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_uname ,
+.Nm archive_entry_uname_w ,
.Nm archive_entry_set_uname ,
.Nm archive_entry_copy_uname ,
.Nm archive_entry_copy_uname_w ,
diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c
index fed74f512..74917b37b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c
+++ b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c
@@ -51,7 +51,7 @@ archive_entry_sparse_clear(struct archive_entry *entry)
void
archive_entry_sparse_add_entry(struct archive_entry *entry,
- int64_t offset, int64_t length)
+ la_int64_t offset, la_int64_t length)
{
struct ae_sparse *sp;
@@ -135,7 +135,7 @@ archive_entry_sparse_reset(struct archive_entry * entry)
int
archive_entry_sparse_next(struct archive_entry * entry,
- int64_t *offset, int64_t *length)
+ la_int64_t *offset, la_int64_t *length)
{
if (entry->sparse_p) {
*offset = entry->sparse_p->offset;
diff --git a/Utilities/cmlibarchive/libarchive/archive_getdate.c b/Utilities/cmlibarchive/libarchive/archive_getdate.c
index beb0cba2e..030c083ce 100644
--- a/Utilities/cmlibarchive/libarchive/archive_getdate.c
+++ b/Utilities/cmlibarchive/libarchive/archive_getdate.c
@@ -691,7 +691,7 @@ 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] = {
+ signed char DaysInMonth[12] = {
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
time_t Julian;
diff --git a/Utilities/cmlibarchive/libarchive/archive_match.c b/Utilities/cmlibarchive/libarchive/archive_match.c
index be72066ea..f150e8224 100644
--- a/Utilities/cmlibarchive/libarchive/archive_match.c
+++ b/Utilities/cmlibarchive/libarchive/archive_match.c
@@ -1582,7 +1582,7 @@ time_excluded(struct archive_match *a, struct archive_entry *entry)
*/
int
-archive_match_include_uid(struct archive *_a, int64_t uid)
+archive_match_include_uid(struct archive *_a, la_int64_t uid)
{
struct archive_match *a;
@@ -1593,7 +1593,7 @@ archive_match_include_uid(struct archive *_a, int64_t uid)
}
int
-archive_match_include_gid(struct archive *_a, int64_t gid)
+archive_match_include_gid(struct archive *_a, la_int64_t gid)
{
struct archive_match *a;
diff --git a/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
index 2deeb5f55..921249bb9 100644
--- a/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_openssl_hmac_private.h
@@ -28,7 +28,8 @@
#include <openssl/hmac.h>
#include <openssl/opensslv.h>
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if OPENSSL_VERSION_NUMBER < 0x10100000L || \
+ (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
#include <stdlib.h> /* malloc, free */
#include <string.h> /* memset */
static inline HMAC_CTX *HMAC_CTX_new(void)
diff --git a/Utilities/cmlibarchive/libarchive/archive_pack_dev.c b/Utilities/cmlibarchive/libarchive/archive_pack_dev.c
index 6b7b4726d..53bddd790 100644
--- a/Utilities/cmlibarchive/libarchive/archive_pack_dev.c
+++ b/Utilities/cmlibarchive/libarchive/archive_pack_dev.c
@@ -57,6 +57,9 @@ __RCSID("$NetBSD$");
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
+#ifdef HAVE_SYS_SYSMACROS_H
+#include <sys/sysmacros.h>
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -280,7 +283,7 @@ pack_bsdos(int n, unsigned long numbers[], const char **error)
/* list of formats and pack functions */
/* this list must be sorted lexically */
-static struct format {
+static const struct format {
const char *name;
pack_t *pack;
} formats[] = {
diff --git a/Utilities/cmlibarchive/libarchive/archive_platform.h b/Utilities/cmlibarchive/libarchive/archive_platform.h
index 47d144b05..e161e6406 100644
--- a/Utilities/cmlibarchive/libarchive/archive_platform.h
+++ b/Utilities/cmlibarchive/libarchive/archive_platform.h
@@ -52,6 +52,17 @@
#error Oops: No config.h and no pre-built configuration in archive_platform.h.
#endif
+/* On macOS check for some symbols based on the deployment target version. */
+#if defined(__APPLE__)
+# undef HAVE_FUTIMENS
+# undef HAVE_UTIMENSAT
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
+# define HAVE_FUTIMENS 1
+# define HAVE_UTIMENSAT 1
+# endif
+#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
@@ -148,32 +159,6 @@
#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
-#if HAVE_ACL_USER
-#define HAVE_POSIX_ACL 1
-#elif HAVE_ACL_TYPE_EXTENDED
-#define HAVE_DARWIN_ACL 1
-#endif
-#endif
-
-/*
- * If this platform has <sys/acl.h>, acl_get(), facl_get(), acl_set(),
- * facl_set() and types aclent_t and ace_t it uses Solaris-style ACL functions
- */
-#if HAVE_SYS_ACL_H && HAVE_ACL_GET && HAVE_FACL_GET && HAVE_ACL_SET && HAVE_FACL_SET && HAVE_ACLENT_T && HAVE_ACE_T
-#define HAVE_SUN_ACL 1
-#endif
-
-/* Define if platform supports NFSv4 ACLs */
-#if (HAVE_POSIX_ACL && HAVE_ACL_TYPE_NFS4) || HAVE_SUN_ACL || HAVE_DARWIN_ACL
-#define HAVE_NFS4_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.
*/
@@ -211,4 +196,10 @@
#define ARCHIVE_ERRNO_MISC (-1)
#endif
+#if defined(__GNUC__) && (__GNUC__ >= 7)
+#define __LA_FALLTHROUGH __attribute__((fallthrough))
+#else
+#define __LA_FALLTHROUGH
+#endif
+
#endif /* !ARCHIVE_PLATFORM_H_INCLUDED */
diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd7.c b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c
index 1aed922db..d0bacc68c 100644
--- a/Utilities/cmlibarchive/libarchive/archive_ppmd7.c
+++ b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c
@@ -115,14 +115,14 @@ static void Ppmd7_Construct(CPpmd7 *p)
memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);
}
-static void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc)
+static void Ppmd7_Free(CPpmd7 *p)
{
- alloc->Free(alloc, p->Base);
+ free(p->Base);
p->Size = 0;
p->Base = 0;
}
-static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc)
+static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size)
{
if (p->Base == 0 || p->Size != size)
{
@@ -131,14 +131,14 @@ static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc)
if (size < UNIT_SIZE) {
return False;
}
- Ppmd7_Free(p, alloc);
+ Ppmd7_Free(p);
p->AlignOffset =
#ifdef PPMD_32BIT
(4 - size) & 3;
#else
4 - (size & 3);
#endif
- if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size
+ if ((p->Base = (Byte *)malloc(p->AlignOffset + size
#ifndef PPMD_32BIT
+ UNIT_SIZE
#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h b/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h
index 06c99e828..577d6fb43 100644
--- a/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h
@@ -95,8 +95,8 @@ 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);
+ Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size);
+ void (*Ppmd7_Free)(CPpmd7 *p);
void (*Ppmd7_Init)(CPpmd7 *p, unsigned maxOrder);
#define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h b/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h
index e78bde594..a83b8514d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h
@@ -69,13 +69,6 @@ typedef struct
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 ***/
diff --git a/Utilities/cmlibarchive/libarchive/archive_random.c b/Utilities/cmlibarchive/libarchive/archive_random.c
index 90ee7c626..65ea69157 100644
--- a/Utilities/cmlibarchive/libarchive/archive_random.c
+++ b/Utilities/cmlibarchive/libarchive/archive_random.c
@@ -221,7 +221,10 @@ arc4_stir(void)
/*
* Discard early keystream, as per recommendations in:
* "(Not So) Random Shuffles of RC4" by Ilya Mironov.
+ * As per the Network Operations Division, cryptographic requirements
+ * published on wikileaks on March 2017.
*/
+
for (i = 0; i < 3072; i++)
(void)arc4_getbyte();
arc4_count = 1600000;
diff --git a/Utilities/cmlibarchive/libarchive/archive_read.c b/Utilities/cmlibarchive/libarchive/archive_read.c
index d1fecebfd..0e56e76e7 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read.c
@@ -120,7 +120,8 @@ archive_read_new(void)
* 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)
+archive_read_extract_set_skip_file(struct archive *_a, la_int64_t d,
+ la_int64_t i)
{
struct archive_read *a = (struct archive_read *)_a;
@@ -747,7 +748,7 @@ choose_format(struct archive_read *a)
* Return the file offset (within the uncompressed data stream) where
* the last header started.
*/
-int64_t
+la_int64_t
archive_read_header_position(struct archive *_a)
{
struct archive_read *a = (struct archive_read *)_a;
@@ -820,7 +821,7 @@ archive_read_format_capabilities(struct archive *_a)
* DO NOT intermingle calls to this function and archive_read_data_block
* to read a single entry body.
*/
-ssize_t
+la_ssize_t
archive_read_data(struct archive *_a, void *buff, size_t s)
{
struct archive *a = (struct archive *)_a;
@@ -881,7 +882,8 @@ archive_read_data(struct archive *_a, void *buff, size_t s)
len = a->read_data_remaining;
if (len > s)
len = s;
- memcpy(dest, a->read_data_block, len);
+ if (len)
+ memcpy(dest, a->read_data_block, len);
s -= len;
a->read_data_block += len;
a->read_data_remaining -= len;
@@ -942,7 +944,7 @@ archive_read_data_skip(struct archive *_a)
return (r);
}
-int64_t
+la_int64_t
archive_seek_data(struct archive *_a, int64_t offset, int whence)
{
struct archive_read *a = (struct archive_read *)_a;
@@ -1625,7 +1627,8 @@ __archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset,
switch (whence) {
case SEEK_CUR:
/* Adjust the offset and use SEEK_SET instead */
- offset += filter->position;
+ offset += filter->position;
+ __LA_FALLTHROUGH;
case SEEK_SET:
cursor = 0;
while (1)
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c b/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
index 5e4d16307..da7c55b9b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_append_filter.c
@@ -89,6 +89,10 @@ archive_read_append_filter(struct archive *_a, int code)
strcpy(str, "lz4");
r1 = archive_read_support_filter_lz4(_a);
break;
+ case ARCHIVE_FILTER_ZSTD:
+ strcpy(str, "zstd");
+ r1 = archive_read_support_filter_zstd(_a);
+ break;
case ARCHIVE_FILTER_LZIP:
strcpy(str, "lzip");
r1 = archive_read_support_filter_lzip(_a);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk.3 b/Utilities/cmlibarchive/libarchive/archive_read_disk.3
index 2a5c1305e..027f63cb6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk.3
@@ -24,11 +24,12 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 30, 2016
+.Dd April 3, 2017
.Dt ARCHIVE_READ_DISK 3
.Os
.Sh NAME
.Nm archive_read_disk_new ,
+.Nm archive_read_disk_set_behavior ,
.Nm archive_read_disk_set_symlink_logical ,
.Nm archive_read_disk_set_symlink_physical ,
.Nm archive_read_disk_set_symlink_hybrid ,
@@ -37,10 +38,7 @@
.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
+.Nm archive_read_disk_set_standard_lookup
.Nd functions for reading objects from disk
.Sh LIBRARY
Streaming Archive Library (libarchive, -larchive)
@@ -49,6 +47,8 @@ Streaming Archive Library (libarchive, -larchive)
.Ft struct archive *
.Fn archive_read_disk_new "void"
.Ft int
+.Fn archive_read_disk_set_behavior "struct archive *" "int"
+.Ft int
.Fn archive_read_disk_set_symlink_logical "struct archive *"
.Ft int
.Fn archive_read_disk_set_symlink_physical "struct archive *"
@@ -81,12 +81,6 @@ Streaming Archive Library (libarchive, -larchive)
.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.
@@ -98,6 +92,51 @@ objects.
Allocates and initializes a
.Tn struct archive
object suitable for reading object information from disk.
+.It Fn archive_read_disk_set_behavior
+Configures various behavior options when reading entries from disk.
+The flags field consists of a bitwise OR of one or more of the
+following values:
+.Bl -tag -compact -width "indent"
+.It Cm ARCHIVE_READDISK_HONOR_NODUMP
+Skip files and directories with the nodump file attribute (file flag) set.
+By default, the nodump file atrribute is ignored.
+.It Cm ARCHIVE_READDISK_MAC_COPYFILE
+Mac OS X specific. Read metadata (ACLs and extended attributes) with
+.Xr copyfile 3 .
+By default, metadata is read using
+.Xr copyfile 3 .
+.It Cm ARCHIVE_READDISK_NO_ACL
+Do not read Access Control Lists.
+By default, ACLs are read from disk.
+.It Cm ARCHIVE_READDISK_NO_FFLAGS
+Do not read file attributes (file flags).
+By default, file attributes are read from disk.
+See
+.Xr chattr 1
+.Pq Linux
+or
+.Xr chflags 1
+.Pq FreeBSD, Mac OS X
+for more information on file attributes.
+.It Cm ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS
+Do not traverse mount points.
+By defaut, moint points are traversed.
+.It Cm ARCHIVE_READDISK_NO_XATTR
+Do not read extended file attributes (xattrs).
+By default, extended file attributes are read from disk.
+See
+.Xr xattr 7
+.Pq Linux ,
+.Xr xattr 2
+.Pq Mac OS X ,
+or
+.Xr getextattr 8
+.Pq FreeBSD
+for more information on extended file attributes.
+.It Cm ARCHIVE_READDISK_RESTORE_ATIME
+Restore access time of traversed files.
+By default, access time of traversed files is not restored.
+.El
.It Xo
.Fn archive_read_disk_set_symlink_logical ,
.Fn archive_read_disk_set_symlink_physical ,
@@ -181,17 +220,6 @@ 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
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
index b2f1d17d9..1786cff38 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c
@@ -26,23 +26,14 @@
*/
#include "archive_platform.h"
-__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_entry_from_file.c 201084 2009-12-28 02:14:09Z kientzle $");
+__FBSDID("$FreeBSD");
/* 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_DARWIN_ACL
-#include <membership.h>
-#include <grp.h>
-#include <pwd.h>
-#endif
#ifdef HAVE_SYS_EXTATTR_H
#include <sys/extattr.h>
#endif
@@ -63,9 +54,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_entry_from_file.c 2010
#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
@@ -113,27 +101,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_entry_from_file.c 2010
#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
-
-/* NFSv4 platform ACL type */
-#if HAVE_SUN_ACL
-#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACE_T
-#elif HAVE_DARWIN_ACL
-#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACL_TYPE_EXTENDED
-#elif HAVE_ACL_TYPE_NFS4
-#define ARCHIVE_PLATFORM_ACL_TYPE_NFS4 ACL_TYPE_NFS4
-#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 *,
@@ -145,6 +112,45 @@ static int setup_sparse_fiemap(struct archive_read_disk *,
struct archive_entry *, int *fd);
#endif
+#if !ARCHIVE_ACL_SUPPORT
+int
+archive_read_disk_entry_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
+
+/*
+ * Enter working directory and return working pathname of archive_entry.
+ * If a pointer to an integer is provided and its value is below zero
+ * open a file descriptor on this pathname.
+ */
+const char *
+archive_read_disk_entry_setup_path(struct archive_read_disk *a,
+ struct archive_entry *entry, int *fd)
+{
+ const char *path;
+
+ path = archive_entry_sourcepath(entry);
+
+ if (path == NULL || (a->tree != NULL &&
+ a->tree_enter_working_dir(a->tree) != 0))
+ path = archive_entry_pathname(entry);
+ if (path == NULL) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Couldn't determine path");
+ } else if (fd != NULL && *fd < 0 && a->tree != NULL &&
+ (a->follow_symlinks || archive_entry_filetype(entry) != AE_IFLNK)) {
+ *fd = a->open_on_current_dir(a->tree, path,
+ O_RDONLY | O_NONBLOCK);
+ }
+ return (path);
+}
+
int
archive_read_disk_entry_from_file(struct archive *_a,
struct archive_entry *entry,
@@ -279,7 +285,7 @@ archive_read_disk_entry_from_file(struct archive *_a,
r = 0;
if ((a->flags & ARCHIVE_READDISK_NO_ACL) == 0)
- r = setup_acls(a, entry, &fd);
+ r = archive_read_disk_entry_setup_acls(a, entry, &fd);
if ((a->flags & ARCHIVE_READDISK_NO_XATTR) == 0) {
r1 = setup_xattrs(a, entry, &fd);
if (r1 < r)
@@ -328,19 +334,10 @@ setup_mac_metadata(struct archive_read_disk *a,
struct archive_string tempfile;
(void)fd; /* UNUSED */
- name = archive_entry_sourcepath(entry);
+
+ name = archive_read_disk_entry_setup_path(a, entry, NULL);
if (name == NULL)
- name = archive_entry_pathname(entry);
- else if (a->tree != NULL && a->tree_enter_working_dir(a->tree) != 0) {
- archive_set_error(&a->archive, errno,
- "Can't change dir to read extended attributes");
- return (ARCHIVE_FAILED);
- }
- if (name == NULL) {
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Can't open file to read extended attributes: No name");
return (ARCHIVE_WARN);
- }
/* Short-circuit if there's nothing to do. */
have_attrs = copyfile(name, NULL, 0, copyfile_flags | COPYFILE_CHECK);
@@ -426,996 +423,10 @@ setup_mac_metadata(struct archive_read_disk *a,
}
#endif
-#if HAVE_DARWIN_ACL
-static int translate_guid(struct archive *, acl_entry_t,
- int *, int *, const char **);
-
-static void add_trivial_nfs4_acl(struct archive_entry *);
-#endif
-
-#if HAVE_SUN_ACL
-static int
-sun_acl_is_trivial(acl_t *, mode_t, int *trivialp);
-#endif
-
-#if HAVE_POSIX_ACL || HAVE_NFS4_ACL
-static int translate_acl(struct archive_read_disk *a,
- struct archive_entry *entry,
-#if HAVE_SUN_ACL
- acl_t *acl,
-#else
- acl_t acl,
-#endif
- int archive_entry_acl_type);
-
-static int
-setup_acls(struct archive_read_disk *a,
- struct archive_entry *entry, int *fd)
-{
- const char *accpath;
-#if HAVE_SUN_ACL
- acl_t *acl;
-#else
- acl_t acl;
-#endif
- int r;
-
- accpath = NULL;
-
-#if HAVE_SUN_ACL || HAVE_DARWIN_ACL || HAVE_ACL_GET_FD_NP
- if (*fd < 0)
-#else
- /* For default ACLs on Linux we need reachable accpath */
- if (*fd < 0 || S_ISDIR(archive_entry_mode(entry)))
-#endif
- {
- accpath = archive_entry_sourcepath(entry);
- if (accpath == NULL || (a->tree != NULL &&
- a->tree_enter_working_dir(a->tree) != 0))
- accpath = archive_entry_pathname(entry);
- if (accpath == NULL) {
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Couldn't determine file path to read ACLs");
- return (ARCHIVE_WARN);
- }
- if (a->tree != NULL &&
-#if !HAVE_SUN_ACL && !HAVE_DARWIN_ACL && !HAVE_ACL_GET_FD_NP
- *fd < 0 &&
-#endif
- (a->follow_symlinks ||
- archive_entry_filetype(entry) != AE_IFLNK)) {
- *fd = a->open_on_current_dir(a->tree,
- accpath, O_RDONLY | O_NONBLOCK);
- }
- }
-
- archive_entry_acl_clear(entry);
-
- acl = NULL;
-
-#if HAVE_NFS4_ACL
- /* Try NFSv4 ACL first. */
- if (*fd >= 0)
-#if HAVE_SUN_ACL
- /* Solaris reads both POSIX.1e and NFSv4 ACL here */
- facl_get(*fd, 0, &acl);
-#elif HAVE_ACL_GET_FD_NP
- acl = acl_get_fd_np(*fd, ARCHIVE_PLATFORM_ACL_TYPE_NFS4);
-#else
- acl = acl_get_fd(*fd);
-#endif
-#if HAVE_ACL_GET_LINK_NP
- else if (!a->follow_symlinks)
- acl = acl_get_link_np(accpath, ARCHIVE_PLATFORM_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
-#if HAVE_SUN_ACL
- /* Solaris reads both POSIX.1e and NFSv4 ACLs here */
- acl_get(accpath, 0, &acl);
-#else
- acl = acl_get_file(accpath, ARCHIVE_PLATFORM_ACL_TYPE_NFS4);
-#endif
-
-
-#if HAVE_ACL_IS_TRIVIAL_NP || HAVE_SUN_ACL
- /* Ignore "trivial" ACLs that just mirror the file mode. */
- if (acl != NULL) {
-#if HAVE_SUN_ACL
- if (sun_acl_is_trivial(acl, archive_entry_mode(entry),
- &r) == 0 && r == 1)
-#elif HAVE_ACL_IS_TRIVIAL_NP
- if (acl_is_trivial_np(acl, &r) == 0 && r == 1)
-#endif
- {
- acl_free(acl);
- acl = NULL;
- /*
- * Simultaneous NFSv4 and POSIX.1e ACLs for the same
- * entry are not allowed, so we should return here
- */
- return (ARCHIVE_OK);
- }
- }
-#endif /* HAVE_ACL_IS_TRIVIAL_NP || HAVE_SUN_ACL */
- if (acl != NULL) {
- r = translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_NFS4);
- acl_free(acl);
- if (r != ARCHIVE_OK) {
- archive_set_error(&a->archive, errno,
- "Couldn't translate "
-#if !HAVE_SUN_ACL
- "NFSv4 "
-#endif
- "ACLs");
- }
-#if HAVE_DARWIN_ACL
- /*
- * Because Mac OS doesn't support owner@, group@ and everyone@
- * ACLs we need to add NFSv4 ACLs mirroring the file mode to
- * the archive entry. Otherwise extraction on non-Mac platforms
- * would lead to an invalid file mode.
- */
- if ((archive_entry_acl_types(entry) &
- ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0)
- add_trivial_nfs4_acl(entry);
-#endif
- return (r);
- }
-#endif /* HAVE_NFS4_ACL */
-
-#if HAVE_POSIX_ACL
- /* This code path is skipped on MacOS and Solaris */
+#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX
- /* 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 HAVE_ACL_IS_TRIVIAL_NP
- /* Ignore "trivial" ACLs that just mirror the file mode. */
- if (acl != NULL && acl_is_trivial_np(acl, &r) == 0) {
- if (r) {
- acl_free(acl);
- acl = NULL;
- }
- }
-#endif
-
- if (acl != NULL) {
- r = translate_acl(a, entry, acl, ARCHIVE_ENTRY_ACL_TYPE_ACCESS);
- acl_free(acl);
- acl = NULL;
- if (r != ARCHIVE_OK) {
- archive_set_error(&a->archive, errno,
- "Couldn't translate access ACLs");
- return (r);
- }
- }
-
- /* Only directories can have default ACLs. */
- if (S_ISDIR(archive_entry_mode(entry))) {
-#if HAVE_ACL_GET_FD_NP
- if (*fd >= 0)
- acl = acl_get_fd_np(*fd, ACL_TYPE_DEFAULT);
- else
-#endif
- acl = acl_get_file(accpath, ACL_TYPE_DEFAULT);
- if (acl != NULL) {
- r = translate_acl(a, entry, acl,
- ARCHIVE_ENTRY_ACL_TYPE_DEFAULT);
- acl_free(acl);
- if (r != ARCHIVE_OK) {
- archive_set_error(&a->archive, errno,
- "Couldn't translate default ACLs");
- return (r);
- }
- }
- }
-#endif /* HAVE_POSIX_ACL */
- return (ARCHIVE_OK);
-}
-
-/*
- * Translate system ACL permissions into libarchive internal structure
- */
-static const struct {
- const int archive_perm;
- const int platform_perm;
-} acl_perm_map[] = {
-#if HAVE_SUN_ACL /* Solaris NFSv4 ACL permissions */
- {ARCHIVE_ENTRY_ACL_EXECUTE, ACE_EXECUTE},
- {ARCHIVE_ENTRY_ACL_READ_DATA, ACE_READ_DATA},
- {ARCHIVE_ENTRY_ACL_LIST_DIRECTORY, ACE_LIST_DIRECTORY},
- {ARCHIVE_ENTRY_ACL_WRITE_DATA, ACE_WRITE_DATA},
- {ARCHIVE_ENTRY_ACL_ADD_FILE, ACE_ADD_FILE},
- {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACE_APPEND_DATA},
- {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACE_ADD_SUBDIRECTORY},
- {ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS, ACE_READ_NAMED_ATTRS},
- {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACE_WRITE_NAMED_ATTRS},
- {ARCHIVE_ENTRY_ACL_DELETE_CHILD, ACE_DELETE_CHILD},
- {ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES, ACE_READ_ATTRIBUTES},
- {ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES, ACE_WRITE_ATTRIBUTES},
- {ARCHIVE_ENTRY_ACL_DELETE, ACE_DELETE},
- {ARCHIVE_ENTRY_ACL_READ_ACL, ACE_READ_ACL},
- {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACE_WRITE_ACL},
- {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACE_WRITE_OWNER},
- {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACE_SYNCHRONIZE}
-#elif HAVE_DARWIN_ACL /* MacOS ACL permissions */
- {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_EXECUTE, ACL_EXECUTE},
- {ARCHIVE_ENTRY_ACL_DELETE, ACL_DELETE},
- {ARCHIVE_ENTRY_ACL_APPEND_DATA, ACL_APPEND_DATA},
- {ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY, ACL_ADD_SUBDIRECTORY},
- {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_READ_NAMED_ATTRS, ACL_READ_EXTATTRIBUTES},
- {ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS, ACL_WRITE_EXTATTRIBUTES},
- {ARCHIVE_ENTRY_ACL_READ_ACL, ACL_READ_SECURITY},
- {ARCHIVE_ENTRY_ACL_WRITE_ACL, ACL_WRITE_SECURITY},
- {ARCHIVE_ENTRY_ACL_WRITE_OWNER, ACL_CHANGE_OWNER},
- {ARCHIVE_ENTRY_ACL_SYNCHRONIZE, ACL_SYNCHRONIZE}
-#else /* POSIX.1e ACL permissions */
- {ARCHIVE_ENTRY_ACL_EXECUTE, ACL_EXECUTE},
- {ARCHIVE_ENTRY_ACL_WRITE, ACL_WRITE},
- {ARCHIVE_ENTRY_ACL_READ, ACL_READ},
-#if HAVE_ACL_TYPE_NFS4 /* FreeBSD NFSv4 ACL permissions */
- {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
-#endif /* !HAVE_SUN_ACL && !HAVE_DARWIN_ACL */
-};
-
-#if HAVE_NFS4_ACL
-/*
- * Translate system NFSv4 inheritance flags into libarchive internal structure
- */
-static const struct {
- const int archive_inherit;
- const int platform_inherit;
-} acl_inherit_map[] = {
-#if HAVE_SUN_ACL /* Solaris ACL inheritance flags */
- {ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT, ACE_FILE_INHERIT_ACE},
- {ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT, ACE_DIRECTORY_INHERIT_ACE},
- {ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT, ACE_NO_PROPAGATE_INHERIT_ACE},
- {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACE_INHERIT_ONLY_ACE},
- {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACE_SUCCESSFUL_ACCESS_ACE_FLAG},
- {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACE_FAILED_ACCESS_ACE_FLAG},
- {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACE_INHERITED_ACE}
-#elif HAVE_DARWIN_ACL /* MacOS NFSv4 inheritance flags */
- {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED},
- {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_LIMIT_INHERIT},
- {ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY, ACL_ENTRY_ONLY_INHERIT}
-#else /* FreeBSD NFSv4 ACL inheritance flags */
- {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},
- {ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS, ACL_ENTRY_SUCCESSFUL_ACCESS},
- {ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS, ACL_ENTRY_FAILED_ACCESS},
- {ARCHIVE_ENTRY_ACL_ENTRY_INHERITED, ACL_ENTRY_INHERITED}
-#endif /* !HAVE_SUN_ACL && !HAVE_DARWIN_ACL */
-};
-#endif /* HAVE_NFS4_ACL */
-
-#if HAVE_DARWIN_ACL
-static int translate_guid(struct archive *a, acl_entry_t acl_entry,
- int *ae_id, int *ae_tag, const char **ae_name)
-{
- void *q;
- uid_t ugid;
- int r, idtype;
- struct passwd *pwd;
- struct group *grp;
-
- q = acl_get_qualifier(acl_entry);
- if (q == NULL)
- return (1);
- r = mbr_uuid_to_id((const unsigned char *)q, &ugid, &idtype);
- if (r != 0) {
- acl_free(q);
- return (1);
- }
- if (idtype == ID_TYPE_UID) {
- *ae_tag = ARCHIVE_ENTRY_ACL_USER;
- pwd = getpwuuid(q);
- if (pwd == NULL) {
- *ae_id = ugid;
- *ae_name = NULL;
- } else {
- *ae_id = pwd->pw_uid;
- *ae_name = archive_read_disk_uname(a, *ae_id);
- }
- } else if (idtype == ID_TYPE_GID) {
- *ae_tag = ARCHIVE_ENTRY_ACL_GROUP;
- grp = getgruuid(q);
- if (grp == NULL) {
- *ae_id = ugid;
- *ae_name = NULL;
- } else {
- *ae_id = grp->gr_gid;
- *ae_name = archive_read_disk_gname(a, *ae_id);
- }
- } else
- r = 1;
-
- acl_free(q);
- return (r);
-}
-
-/*
- * Add trivial NFSv4 ACL entries from mode
- */
-static void
-add_trivial_nfs4_acl(struct archive_entry *entry)
-{
- mode_t mode;
- int i;
- const int rperm = ARCHIVE_ENTRY_ACL_READ_DATA;
- const int wperm = ARCHIVE_ENTRY_ACL_WRITE_DATA |
- ARCHIVE_ENTRY_ACL_APPEND_DATA;
- const int eperm = ARCHIVE_ENTRY_ACL_EXECUTE;
- const int pubset = ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES |
- ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS |
- ARCHIVE_ENTRY_ACL_READ_ACL |
- ARCHIVE_ENTRY_ACL_SYNCHRONIZE;
- const int ownset = pubset | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES |
- ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS |
- ARCHIVE_ENTRY_ACL_WRITE_ACL |
- ARCHIVE_ENTRY_ACL_WRITE_OWNER;
-
- struct {
- const int type;
- const int tag;
- int permset;
- } tacl_entry[] = {
- {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, 0},
- {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_USER_OBJ, 0},
- {ARCHIVE_ENTRY_ACL_TYPE_DENY, ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0},
- {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_USER_OBJ, ownset},
- {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_GROUP_OBJ, pubset},
- {ARCHIVE_ENTRY_ACL_TYPE_ALLOW, ARCHIVE_ENTRY_ACL_EVERYONE, pubset}
- };
-
- mode = archive_entry_mode(entry);
-
- /* Permissions for everyone@ */
- if (mode & 0004)
- tacl_entry[5].permset |= rperm;
- if (mode & 0002)
- tacl_entry[5].permset |= wperm;
- if (mode & 0001)
- tacl_entry[5].permset |= eperm;
-
- /* Permissions for group@ */
- if (mode & 0040)
- tacl_entry[4].permset |= rperm;
- else if (mode & 0004)
- tacl_entry[2].permset |= rperm;
- if (mode & 0020)
- tacl_entry[4].permset |= wperm;
- else if (mode & 0002)
- tacl_entry[2].permset |= wperm;
- if (mode & 0010)
- tacl_entry[4].permset |= eperm;
- else if (mode & 0001)
- tacl_entry[2].permset |= eperm;
-
- /* Permissions for owner@ */
- if (mode & 0400) {
- tacl_entry[3].permset |= rperm;
- if (!(mode & 0040) && (mode & 0004))
- tacl_entry[0].permset |= rperm;
- } else if ((mode & 0040) || (mode & 0004))
- tacl_entry[1].permset |= rperm;
- if (mode & 0200) {
- tacl_entry[3].permset |= wperm;
- if (!(mode & 0020) && (mode & 0002))
- tacl_entry[0].permset |= wperm;
- } else if ((mode & 0020) || (mode & 0002))
- tacl_entry[1].permset |= wperm;
- if (mode & 0100) {
- tacl_entry[3].permset |= eperm;
- if (!(mode & 0010) && (mode & 0001))
- tacl_entry[0].permset |= eperm;
- } else if ((mode & 0010) || (mode & 0001))
- tacl_entry[1].permset |= eperm;
-
- for (i = 0; i < 6; i++) {
- if (tacl_entry[i].permset != 0) {
- archive_entry_acl_add_entry(entry,
- tacl_entry[i].type, tacl_entry[i].permset,
- tacl_entry[i].tag, -1, NULL);
- }
- }
-
- return;
-}
-#elif HAVE_SUN_ACL
-/*
- * Check if acl is trivial
- * This is a FreeBSD acl_is_trivial_np() implementation for Solaris
- */
-static int
-sun_acl_is_trivial(acl_t *acl, mode_t mode, int *trivialp)
-{
- int i, p;
- const uint32_t rperm = ACE_READ_DATA;
- const uint32_t wperm = ACE_WRITE_DATA | ACE_APPEND_DATA;
- const uint32_t eperm = ACE_EXECUTE;
- const uint32_t pubset = ACE_READ_ATTRIBUTES | ACE_READ_NAMED_ATTRS |
- ACE_READ_ACL | ACE_SYNCHRONIZE;
- const uint32_t ownset = pubset | ACE_WRITE_ATTRIBUTES |
- ACE_WRITE_NAMED_ATTRS | ACE_WRITE_ACL | ACE_WRITE_OWNER;
-
- ace_t *ace;
- ace_t tace[6];
-
- if (acl == NULL || trivialp == NULL)
- return (-1);
-
- *trivialp = 0;
-
- /* ACL_IS_TRIVIAL flag must be set for both POSIX.1e and NFSv4 ACLs */
- if ((acl->acl_flags & ACL_IS_TRIVIAL) == 0)
- return (0);
-
- /*
- * POSIX.1e ACLs marked with ACL_IS_TRIVIAL are compatible with
- * FreeBSD acl_is_trivial_np(). On Solaris they have 4 entries,
- * including mask.
- */
- if (acl->acl_type == ACLENT_T) {
- if (acl->acl_cnt == 4)
- *trivialp = 1;
- return (0);
- }
-
- if (acl->acl_type != ACE_T || acl->acl_entry_size != sizeof(ace_t))
- return (-1);
-
- /*
- * Continue with checking NFSv4 ACLs
- *
- * Create list of trivial ace's to be compared
- */
-
- /* owner@ allow pre */
- tace[0].a_flags = ACE_OWNER;
- tace[0].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE;
- tace[0].a_access_mask = 0;
-
- /* owner@ deny */
- tace[1].a_flags = ACE_OWNER;
- tace[1].a_type = ACE_ACCESS_DENIED_ACE_TYPE;
- tace[1].a_access_mask = 0;
-
- /* group@ deny */
- tace[2].a_flags = ACE_GROUP | ACE_IDENTIFIER_GROUP;
- tace[2].a_type = ACE_ACCESS_DENIED_ACE_TYPE;
- tace[2].a_access_mask = 0;
-
- /* owner@ allow */
- tace[3].a_flags = ACE_OWNER;
- tace[3].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE;
- tace[3].a_access_mask = ownset;
-
- /* group@ allow */
- tace[4].a_flags = ACE_GROUP | ACE_IDENTIFIER_GROUP;
- tace[4].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE;
- tace[4].a_access_mask = pubset;
-
- /* everyone@ allow */
- tace[5].a_flags = ACE_EVERYONE;
- tace[5].a_type = ACE_ACCESS_ALLOWED_ACE_TYPE;
- tace[5].a_access_mask = pubset;
-
- /* Permissions for everyone@ */
- if (mode & 0004)
- tace[5].a_access_mask |= rperm;
- if (mode & 0002)
- tace[5].a_access_mask |= wperm;
- if (mode & 0001)
- tace[5].a_access_mask |= eperm;
-
- /* Permissions for group@ */
- if (mode & 0040)
- tace[4].a_access_mask |= rperm;
- else if (mode & 0004)
- tace[2].a_access_mask |= rperm;
- if (mode & 0020)
- tace[4].a_access_mask |= wperm;
- else if (mode & 0002)
- tace[2].a_access_mask |= wperm;
- if (mode & 0010)
- tace[4].a_access_mask |= eperm;
- else if (mode & 0001)
- tace[2].a_access_mask |= eperm;
-
- /* Permissions for owner@ */
- if (mode & 0400) {
- tace[3].a_access_mask |= rperm;
- if (!(mode & 0040) && (mode & 0004))
- tace[0].a_access_mask |= rperm;
- } else if ((mode & 0040) || (mode & 0004))
- tace[1].a_access_mask |= rperm;
- if (mode & 0200) {
- tace[3].a_access_mask |= wperm;
- if (!(mode & 0020) && (mode & 0002))
- tace[0].a_access_mask |= wperm;
- } else if ((mode & 0020) || (mode & 0002))
- tace[1].a_access_mask |= wperm;
- if (mode & 0100) {
- tace[3].a_access_mask |= eperm;
- if (!(mode & 0010) && (mode & 0001))
- tace[0].a_access_mask |= eperm;
- } else if ((mode & 0010) || (mode & 0001))
- tace[1].a_access_mask |= eperm;
-
- /* Check if the acl count matches */
- p = 3;
- for (i = 0; i < 3; i++) {
- if (tace[i].a_access_mask != 0)
- p++;
- }
- if (acl->acl_cnt != p)
- return (0);
-
- p = 0;
- for (i = 0; i < 6; i++) {
- if (tace[i].a_access_mask != 0) {
- ace = &((ace_t *)acl->acl_aclp)[p];
- /*
- * Illumos added ACE_DELETE_CHILD to write perms for
- * directories. We have to check against that, too.
- */
- if (ace->a_flags != tace[i].a_flags ||
- ace->a_type != tace[i].a_type ||
- (ace->a_access_mask != tace[i].a_access_mask &&
- ((acl->acl_flags & ACL_IS_DIR) == 0 ||
- (tace[i].a_access_mask & wperm) == 0 ||
- ace->a_access_mask !=
- (tace[i].a_access_mask | ACE_DELETE_CHILD))))
- return (0);
- p++;
- }
- }
-
- *trivialp = 1;
- return (0);
-}
-#endif /* HAVE_SUN_ACL */
-
-#if HAVE_SUN_ACL
/*
- * Translate Solaris POSIX.1e and NFSv4 ACLs into libarchive internal ACL
- */
-static int
-translate_acl(struct archive_read_disk *a,
- struct archive_entry *entry, acl_t *acl, int default_entry_acl_type)
-{
- int e, i;
- int ae_id, ae_tag, ae_perm;
- int entry_acl_type;
- const char *ae_name;
- aclent_t *aclent;
- ace_t *ace;
-
- (void)default_entry_acl_type;
-
- if (acl->acl_cnt <= 0)
- return (ARCHIVE_OK);
-
- for (e = 0; e < acl->acl_cnt; e++) {
- ae_name = NULL;
- ae_tag = 0;
- ae_perm = 0;
-
- if (acl->acl_type == ACE_T) {
- ace = &((ace_t *)acl->acl_aclp)[e];
- ae_id = ace->a_who;
-
- switch(ace->a_type) {
- case ACE_ACCESS_ALLOWED_ACE_TYPE:
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW;
- break;
- case ACE_ACCESS_DENIED_ACE_TYPE:
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY;
- break;
- case ACE_SYSTEM_AUDIT_ACE_TYPE:
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
- break;
- case ACE_SYSTEM_ALARM_ACE_TYPE:
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALARM;
- break;
- default:
- /* Unknown entry type, skip */
- continue;
- }
-
- if ((ace->a_flags & ACE_OWNER) != 0)
- ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
- else if ((ace->a_flags & ACE_GROUP) != 0)
- ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
- else if ((ace->a_flags & ACE_EVERYONE) != 0)
- ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE;
- else if ((ace->a_flags & ACE_IDENTIFIER_GROUP) != 0) {
- ae_tag = ARCHIVE_ENTRY_ACL_GROUP;
- ae_name = archive_read_disk_gname(&a->archive,
- ae_id);
- } else {
- ae_tag = ARCHIVE_ENTRY_ACL_USER;
- ae_name = archive_read_disk_uname(&a->archive,
- ae_id);
- }
-
- for (i = 0; i < (int)(sizeof(acl_inherit_map) /
- sizeof(acl_inherit_map[0])); ++i) {
- if ((ace->a_flags &
- acl_inherit_map[i].platform_inherit) != 0)
- ae_perm |=
- acl_inherit_map[i].archive_inherit;
- }
-
- for (i = 0; i < (int)(sizeof(acl_perm_map) /
- sizeof(acl_perm_map[0])); ++i) {
- if ((ace->a_access_mask &
- acl_perm_map[i].platform_perm) != 0)
- ae_perm |=
- acl_perm_map[i].archive_perm;
- }
- } else {
- aclent = &((aclent_t *)acl->acl_aclp)[e];
- if ((aclent->a_type & ACL_DEFAULT) != 0)
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT;
- else
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS;
- ae_id = aclent->a_id;
-
- switch(aclent->a_type) {
- case DEF_USER:
- case USER:
- ae_name = archive_read_disk_uname(&a->archive,
- ae_id);
- ae_tag = ARCHIVE_ENTRY_ACL_USER;
- break;
- case DEF_GROUP:
- case GROUP:
- ae_name = archive_read_disk_gname(&a->archive,
- ae_id);
- ae_tag = ARCHIVE_ENTRY_ACL_GROUP;
- break;
- case DEF_CLASS_OBJ:
- case CLASS_OBJ:
- ae_tag = ARCHIVE_ENTRY_ACL_MASK;
- break;
- case DEF_USER_OBJ:
- case USER_OBJ:
- ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ;
- break;
- case DEF_GROUP_OBJ:
- case GROUP_OBJ:
- ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ;
- break;
- case DEF_OTHER_OBJ:
- case OTHER_OBJ:
- ae_tag = ARCHIVE_ENTRY_ACL_OTHER;
- break;
- default:
- /* Unknown tag type, skip */
- continue;
- }
-
- if ((aclent->a_perm & 1) != 0)
- ae_perm |= ARCHIVE_ENTRY_ACL_EXECUTE;
- if ((aclent->a_perm & 2) != 0)
- ae_perm |= ARCHIVE_ENTRY_ACL_WRITE;
- if ((aclent->a_perm & 4) != 0)
- ae_perm |= ARCHIVE_ENTRY_ACL_READ;
- } /* default_entry_acl_type != ARCHIVE_ENTRY_ACL_TYPE_NFS4 */
-
- archive_entry_acl_add_entry(entry, entry_acl_type,
- ae_perm, ae_tag, ae_id, ae_name);
- }
- return (ARCHIVE_OK);
-}
-#else /* !HAVE_SUN_ACL */
-/*
- * Translate POSIX.1e (Linux), FreeBSD (both POSIX.1e and NFSv4) and
- * MacOS (NFSv4 only) ACLs into libarchive internal structure
- */
-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;
-#if HAVE_ACL_TYPE_NFS4
- acl_entry_type_t acl_type;
- int brand;
-#endif
-#if HAVE_ACL_TYPE_NFS4 || HAVE_DARWIN_ACL
- acl_flagset_t acl_flagset;
-#endif
- acl_entry_t acl_entry;
- acl_permset_t acl_permset;
- int i, entry_acl_type;
- int r, s, ae_id, ae_tag, ae_perm;
-#if !HAVE_DARWIN_ACL
- void *q;
-#endif
- const char *ae_name;
-
-#if HAVE_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.
- if (acl_get_brand_np(acl, &brand) != 0) {
- archive_set_error(&a->archive, errno,
- "Failed to read ACL brand");
- return (ARCHIVE_WARN);
- }
- 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:
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Invalid ACL entry type for POSIX.1e ACL");
- return (ARCHIVE_WARN);
- }
- break;
- case ACL_BRAND_NFS4:
- if (default_entry_acl_type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Invalid ACL entry type for NFSv4 ACL");
- return (ARCHIVE_WARN);
- }
- break;
- default:
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Unknown ACL brand");
- return (ARCHIVE_WARN);
- }
-#endif
-
- s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry);
- if (s == -1) {
- archive_set_error(&a->archive, errno,
- "Failed to get first ACL entry");
- return (ARCHIVE_WARN);
- }
-
-#if HAVE_DARWIN_ACL
- while (s == 0)
-#else /* FreeBSD, Linux */
- while (s == 1)
-#endif
- {
- ae_id = -1;
- ae_name = NULL;
- ae_perm = 0;
-
- if (acl_get_tag_type(acl_entry, &acl_tag) != 0) {
- archive_set_error(&a->archive, errno,
- "Failed to get ACL tag type");
- return (ARCHIVE_WARN);
- }
- switch (acl_tag) {
-#if !HAVE_DARWIN_ACL /* FreeBSD, Linux */
- case ACL_USER:
- q = acl_get_qualifier(acl_entry);
- if (q != NULL) {
- ae_id = (int)*(uid_t *)q;
- acl_free(q);
- ae_name = archive_read_disk_uname(&a->archive,
- ae_id);
- }
- ae_tag = ARCHIVE_ENTRY_ACL_USER;
- break;
- case ACL_GROUP:
- q = acl_get_qualifier(acl_entry);
- if (q != NULL) {
- ae_id = (int)*(gid_t *)q;
- acl_free(q);
- 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;
-#if HAVE_ACL_TYPE_NFS4
- case ACL_EVERYONE:
- ae_tag = ARCHIVE_ENTRY_ACL_EVERYONE;
- break;
-#endif
-#else /* HAVE_DARWIN_ACL */
- case ACL_EXTENDED_ALLOW:
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_ALLOW;
- r = translate_guid(&a->archive, acl_entry, &ae_id,
- &ae_tag, &ae_name);
- break;
- case ACL_EXTENDED_DENY:
- entry_acl_type = ARCHIVE_ENTRY_ACL_TYPE_DENY;
- r = translate_guid(&a->archive, acl_entry, &ae_id,
- &ae_tag, &ae_name);
- break;
-#endif /* HAVE_DARWIN_ACL */
- default:
- /* Skip types that libarchive can't support. */
- s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
- continue;
- }
-
-#if HAVE_DARWIN_ACL
- /* Skip if translate_guid() above failed */
- if (r != 0) {
- s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry);
- continue;
- }
-#endif
-
-#if !HAVE_DARWIN_ACL
- // XXX acl_type maps to allow/deny/audit/YYYY bits
- entry_acl_type = default_entry_acl_type;
-#endif
-#if HAVE_ACL_TYPE_NFS4 || HAVE_DARWIN_ACL
- if (default_entry_acl_type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) {
-#if HAVE_ACL_TYPE_NFS4
- /*
- * acl_get_entry_type_np() fails with non-NFSv4 ACLs
- */
- if (acl_get_entry_type_np(acl_entry, &acl_type) != 0) {
- archive_set_error(&a->archive, errno, "Failed "
- "to get ACL type from a NFSv4 ACL entry");
- return (ARCHIVE_WARN);
- }
- 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;
- default:
- archive_set_error(&a->archive, errno,
- "Invalid NFSv4 ACL entry type");
- return (ARCHIVE_WARN);
- }
-#endif /* HAVE_ACL_TYPE_NFS4 */
-
- /*
- * Libarchive stores "flag" (NFSv4 inheritance bits)
- * in the ae_perm bitmap.
- *
- * acl_get_flagset_np() fails with non-NFSv4 ACLs
- */
- if (acl_get_flagset_np(acl_entry, &acl_flagset) != 0) {
- archive_set_error(&a->archive, errno,
- "Failed to get flagset from a NFSv4 ACL entry");
- return (ARCHIVE_WARN);
- }
- for (i = 0; i < (int)(sizeof(acl_inherit_map) / sizeof(acl_inherit_map[0])); ++i) {
- r = acl_get_flag_np(acl_flagset,
- acl_inherit_map[i].platform_inherit);
- if (r == -1) {
- archive_set_error(&a->archive, errno,
- "Failed to check flag in a NFSv4 "
- "ACL flagset");
- return (ARCHIVE_WARN);
- } else if (r)
- ae_perm |= acl_inherit_map[i].archive_inherit;
- }
- }
-#endif /* HAVE_ACL_TYPE_NFS4 || HAVE_DARWIN_ACL */
-
- if (acl_get_permset(acl_entry, &acl_permset) != 0) {
- archive_set_error(&a->archive, errno,
- "Failed to get ACL permission set");
- return (ARCHIVE_WARN);
- }
- 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.
- */
- r = ACL_GET_PERM(acl_permset, acl_perm_map[i].platform_perm);
- if (r == -1) {
- archive_set_error(&a->archive, errno,
- "Failed to check permission in an ACL permission set");
- return (ARCHIVE_WARN);
- } else if (r)
- 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);
-#if !HAVE_DARWIN_ACL
- if (s == -1) {
- archive_set_error(&a->archive, errno,
- "Failed to get next ACL entry");
- return (ARCHIVE_WARN);
- }
-#endif
- }
- return (ARCHIVE_OK);
-}
-#endif /* !HAVE_SUN_ACL */
-#else /* !HAVE_POSIX_ACL && !HAVE_NFS4_ACL */
-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 /* !HAVE_POSIX_ACL && !HAVE_NFS4_ACL */
-
-#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.
+ * Linux, Darwin 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
@@ -1433,21 +444,32 @@ setup_xattr(struct archive_read_disk *a,
ssize_t size;
void *value = NULL;
-#if HAVE_FGETXATTR
- if (fd >= 0)
+
+ if (fd >= 0) {
+#if ARCHIVE_XATTR_LINUX
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)
+#elif ARCHIVE_XATTR_DARWIN
+ size = fgetxattr(fd, name, NULL, 0, 0, 0);
+#elif ARCHIVE_XATTR_AIX
size = fgetea(fd, name, NULL, 0);
- else if (!a->follow_symlinks)
+#endif
+ } else if (!a->follow_symlinks) {
+#if ARCHIVE_XATTR_LINUX
+ size = lgetxattr(accpath, name, NULL, 0);
+#elif ARCHIVE_XATTR_DARWIN
+ size = getxattr(accpath, name, NULL, 0, 0, XATTR_NOFOLLOW);
+#elif ARCHIVE_XATTR_AIX
size = lgetea(accpath, name, NULL, 0);
- else
+#endif
+ } else {
+#if ARCHIVE_XATTR_LINUX
+ size = getxattr(accpath, name, NULL, 0);
+#elif ARCHIVE_XATTR_DARWIN
+ size = getxattr(accpath, name, NULL, 0, 0, 0);
+#elif ARCHIVE_XATTR_AIX
size = getea(accpath, name, NULL, 0);
#endif
+ }
if (size == -1) {
archive_set_error(&a->archive, errno,
@@ -1460,21 +482,32 @@ setup_xattr(struct archive_read_disk *a,
return (ARCHIVE_FATAL);
}
-#if HAVE_FGETXATTR
- if (fd >= 0)
+
+ if (fd >= 0) {
+#if ARCHIVE_XATTR_LINUX
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)
+#elif ARCHIVE_XATTR_DARWIN
+ size = fgetxattr(fd, name, value, size, 0, 0);
+#elif ARCHIVE_XATTR_AIX
size = fgetea(fd, name, value, size);
- else if (!a->follow_symlinks)
+#endif
+ } else if (!a->follow_symlinks) {
+#if ARCHIVE_XATTR_LINUX
+ size = lgetxattr(accpath, name, value, size);
+#elif ARCHIVE_XATTR_DARWIN
+ size = getxattr(accpath, name, value, size, 0, XATTR_NOFOLLOW);
+#elif ARCHIVE_XATTR_AIX
size = lgetea(accpath, name, value, size);
- else
+#endif
+ } else {
+#if ARCHIVE_XATTR_LINUX
+ size = getxattr(accpath, name, value, size);
+#elif ARCHIVE_XATTR_DARWIN
+ size = getxattr(accpath, name, value, size, 0, 0);
+#elif ARCHIVE_XATTR_AIX
size = getea(accpath, name, value, size);
#endif
+ }
if (size == -1) {
archive_set_error(&a->archive, errno,
@@ -1499,38 +532,36 @@ setup_xattrs(struct archive_read_disk *a,
path = NULL;
if (*fd < 0) {
- path = archive_entry_sourcepath(entry);
- if (path == NULL || (a->tree != NULL &&
- a->tree_enter_working_dir(a->tree) != 0))
- path = archive_entry_pathname(entry);
- if (path == NULL) {
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Couldn't determine file path to read "
- "extended attributes");
+ path = archive_read_disk_entry_setup_path(a, entry, fd);
+ if (path == NULL)
return (ARCHIVE_WARN);
- }
- if (a->tree != NULL && (a->follow_symlinks ||
- archive_entry_filetype(entry) != AE_IFLNK)) {
- *fd = a->open_on_current_dir(a->tree,
- path, O_RDONLY | O_NONBLOCK);
- }
}
-#if HAVE_FLISTXATTR
- if (*fd >= 0)
+ if (*fd >= 0) {
+#if ARCHIVE_XATTR_LINUX
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)
+#elif ARCHIVE_XATTR_DARWIN
+ list_size = flistxattr(*fd, NULL, 0, 0);
+#elif ARCHIVE_XATTR_AIX
list_size = flistea(*fd, NULL, 0);
- else if (!a->follow_symlinks)
+#endif
+ } else if (!a->follow_symlinks) {
+#if ARCHIVE_XATTR_LINUX
+ list_size = llistxattr(path, NULL, 0);
+#elif ARCHIVE_XATTR_DARWIN
+ list_size = listxattr(path, NULL, 0, XATTR_NOFOLLOW);
+#elif ARCHIVE_XATTR_AIX
list_size = llistea(path, NULL, 0);
- else
+#endif
+ } else {
+#if ARCHIVE_XATTR_LINUX
+ list_size = listxattr(path, NULL, 0);
+#elif ARCHIVE_XATTR_DARWIN
+ list_size = listxattr(path, NULL, 0, 0);
+#elif ARCHIVE_XATTR_AIX
list_size = listea(path, NULL, 0);
#endif
+ }
if (list_size == -1) {
if (errno == ENOTSUP || errno == ENOSYS)
@@ -1548,21 +579,31 @@ setup_xattrs(struct archive_read_disk *a,
return (ARCHIVE_FATAL);
}
-#if HAVE_FLISTXATTR
- if (*fd >= 0)
+ if (*fd >= 0) {
+#if ARCHIVE_XATTR_LINUX
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)
+#elif ARCHIVE_XATTR_DARWIN
+ list_size = flistxattr(*fd, list, list_size, 0);
+#elif ARCHIVE_XATTR_AIX
list_size = flistea(*fd, list, list_size);
- else if (!a->follow_symlinks)
+#endif
+ } else if (!a->follow_symlinks) {
+#if ARCHIVE_XATTR_LINUX
+ list_size = llistxattr(path, list, list_size);
+#elif ARCHIVE_XATTR_DARWIN
+ list_size = listxattr(path, list, list_size, XATTR_NOFOLLOW);
+#elif ARCHIVE_XATTR_AIX
list_size = llistea(path, list, list_size);
- else
+#endif
+ } else {
+#if ARCHIVE_XATTR_LINUX
+ list_size = listxattr(path, list, list_size);
+#elif ARCHIVE_XATTR_DARWIN
+ list_size = listxattr(path, list, list_size, 0);
+#elif ARCHIVE_XATTR_AIX
list_size = listea(path, list, list_size);
#endif
+ }
if (list_size == -1) {
archive_set_error(&a->archive, errno,
@@ -1572,9 +613,21 @@ setup_xattrs(struct archive_read_disk *a,
}
for (p = list; (p - list) < list_size; p += strlen(p) + 1) {
- if (strncmp(p, "system.", 7) == 0 ||
- strncmp(p, "xfsroot.", 8) == 0)
+#if ARCHIVE_XATTR_LINUX
+ /* Linux: skip POSIX.1e ACL extended attributes */
+ if (strncmp(p, "system.", 7) == 0 &&
+ (strcmp(p + 7, "posix_acl_access") == 0 ||
+ strcmp(p + 7, "posix_acl_default") == 0))
+ continue;
+ if (strncmp(p, "trusted.SGI_", 12) == 0 &&
+ (strcmp(p + 12, "ACL_DEFAULT") == 0 ||
+ strcmp(p + 12, "ACL_FILE") == 0))
+ continue;
+
+ /* Linux: xfsroot namespace is obsolete and unsupported */
+ if (strncmp(p, "xfsroot.", 8) == 0)
continue;
+#endif
setup_xattr(a, entry, p, *fd, path);
}
@@ -1582,8 +635,7 @@ setup_xattrs(struct archive_read_disk *a,
return (ARCHIVE_OK);
}
-#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE && \
- HAVE_DECL_EXTATTR_NAMESPACE_USER
+#elif ARCHIVE_XATTR_FREEBSD
/*
* FreeBSD extattr interface.
@@ -1658,21 +710,9 @@ setup_xattrs(struct archive_read_disk *a,
path = NULL;
if (*fd < 0) {
- path = archive_entry_sourcepath(entry);
- if (path == NULL || (a->tree != NULL &&
- a->tree_enter_working_dir(a->tree) != 0))
- path = archive_entry_pathname(entry);
- if (path == NULL) {
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Couldn't determine file path to read "
- "extended attributes");
+ path = archive_read_disk_entry_setup_path(a, entry, fd);
+ if (path == NULL)
return (ARCHIVE_WARN);
- }
- if (a->tree != NULL && (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)
@@ -1773,6 +813,7 @@ setup_sparse_fiemap(struct archive_read_disk *a,
int64_t size;
int count, do_fiemap, iters;
int exit_sts = ARCHIVE_OK;
+ const char *path;
if (archive_entry_filetype(entry) != AE_IFREG
|| archive_entry_size(entry) <= 0
@@ -1780,11 +821,10 @@ setup_sparse_fiemap(struct archive_read_disk *a,
return (ARCHIVE_OK);
if (*fd < 0) {
- const char *path;
-
- path = archive_entry_sourcepath(entry);
+ path = archive_read_disk_entry_setup_path(a, entry, NULL);
if (path == NULL)
- path = archive_entry_pathname(entry);
+ return (ARCHIVE_FAILED);
+
if (a->tree != NULL)
*fd = a->open_on_current_dir(a->tree, path,
O_RDONLY | O_NONBLOCK | O_CLOEXEC);
@@ -1880,6 +920,7 @@ setup_sparse(struct archive_read_disk *a,
off_t off_s, off_e;
int exit_sts = ARCHIVE_OK;
int check_fully_sparse = 0;
+ const char *path;
if (archive_entry_filetype(entry) != AE_IFREG
|| archive_entry_size(entry) <= 0
@@ -1887,20 +928,10 @@ setup_sparse(struct archive_read_disk *a,
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)
+ path = archive_read_disk_entry_setup_path(a, entry, fd);
+ else
+ path = NULL;
if (*fd >= 0) {
#ifdef _PC_MIN_HOLE_SIZE
@@ -1911,12 +942,8 @@ setup_sparse(struct archive_read_disk *a,
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);
-
+ return (ARCHIVE_FAILED);
#ifdef _PC_MIN_HOLE_SIZE
if (pathconf(path, _PC_MIN_HOLE_SIZE) <= 0)
return (ARCHIVE_OK);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
index 6961ae6a4..cdf754123 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c
@@ -387,7 +387,7 @@ archive_read_disk_vtable(void)
}
const char *
-archive_read_disk_gname(struct archive *_a, int64_t gid)
+archive_read_disk_gname(struct archive *_a, la_int64_t gid)
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;
if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
@@ -399,7 +399,7 @@ archive_read_disk_gname(struct archive *_a, int64_t gid)
}
const char *
-archive_read_disk_uname(struct archive *_a, int64_t uid)
+archive_read_disk_uname(struct archive *_a, la_int64_t uid)
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;
if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
@@ -413,7 +413,7 @@ archive_read_disk_uname(struct archive *_a, int64_t uid)
int
archive_read_disk_set_gname_lookup(struct archive *_a,
void *private_data,
- const char * (*lookup_gname)(void *private, int64_t gid),
+ const char * (*lookup_gname)(void *private, la_int64_t gid),
void (*cleanup_gname)(void *private))
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;
@@ -432,7 +432,7 @@ archive_read_disk_set_gname_lookup(struct archive *_a,
int
archive_read_disk_set_uname_lookup(struct archive *_a,
void *private_data,
- const char * (*lookup_uname)(void *private, int64_t uid),
+ const char * (*lookup_uname)(void *private, la_int64_t uid),
void (*cleanup_uname)(void *private))
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
index b5a8328b7..f03a0a9cc 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h
@@ -33,6 +33,8 @@
#ifndef ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED
#define ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED
+#include "archive_platform_acl.h"
+
struct tree;
struct archive_entry;
@@ -86,4 +88,11 @@ struct archive_read_disk {
void *excluded_cb_data;
};
+const char *
+archive_read_disk_entry_setup_path(struct archive_read_disk *,
+ struct archive_entry *, int *);
+
+int
+archive_read_disk_entry_setup_acls(struct archive_read_disk *,
+ struct archive_entry *, int *);
#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
index 3b903304f..d82048de2 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c
@@ -117,7 +117,7 @@ struct filesystem {
*/
#define MAX_OVERLAPPED 8
-#define BUFFER_SIZE (1024 * 8)
+#define READ_BUFFER_SIZE (1024 * 64) /* Default to 64KB per https://technet.microsoft.com/en-us/library/cc938632.aspx */
#define DIRECT_IO 0/* Disabled */
#define ASYNC_IO 1/* Enabled */
@@ -320,7 +320,7 @@ archive_read_disk_vtable(void)
}
const char *
-archive_read_disk_gname(struct archive *_a, int64_t gid)
+archive_read_disk_gname(struct archive *_a, la_int64_t gid)
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;
if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
@@ -332,7 +332,7 @@ archive_read_disk_gname(struct archive *_a, int64_t gid)
}
const char *
-archive_read_disk_uname(struct archive *_a, int64_t uid)
+archive_read_disk_uname(struct archive *_a, la_int64_t uid)
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;
if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC,
@@ -346,7 +346,7 @@ archive_read_disk_uname(struct archive *_a, int64_t uid)
int
archive_read_disk_set_gname_lookup(struct archive *_a,
void *private_data,
- const char * (*lookup_gname)(void *private, int64_t gid),
+ const char * (*lookup_gname)(void *private, la_int64_t gid),
void (*cleanup_gname)(void *private))
{
struct archive_read_disk *a = (struct archive_read_disk *)_a;
@@ -567,7 +567,7 @@ start_next_async_read(struct archive_read_disk *a, struct tree *t)
/* Allocate read buffer. */
if (olp->buff == NULL) {
void *p;
- size_t s = (size_t)align_num_per_sector(t, BUFFER_SIZE);
+ size_t s = (size_t)align_num_per_sector(t, READ_BUFFER_SIZE);
p = VirtualAlloc(NULL, s, MEM_COMMIT, PAGE_READWRITE);
if (p == NULL) {
archive_set_error(&a->archive, ENOMEM,
@@ -683,7 +683,7 @@ _archive_read_data_block(struct archive *_a, const void **buff,
break;
} while (r == ARCHIVE_OK && t->ol_num_doing < MAX_OVERLAPPED);
} else {
- if (start_next_async_read(a, t) == ARCHIVE_FATAL)
+ if ((r = start_next_async_read(a, t)) == ARCHIVE_FATAL)
goto abort_read_data;
}
@@ -923,6 +923,7 @@ next_entry(struct archive_read_disk *a, struct tree *t,
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) {
+ la_dosmaperr(GetLastError());
archive_set_error(&a->archive, errno,
"Couldn't open %ls", tree_current_path(a->tree));
return (ARCHIVE_FAILED);
@@ -2275,10 +2276,10 @@ setup_sparse_from_disk(struct archive_read_disk *a,
if (range.Length.QuadPart > 0)
continue;
} else {
- /* The remaining data is hole. */
+ /* The entire file is a hole. Add one data block of size 0 at the end. */
archive_entry_sparse_add_entry(entry,
- range.FileOffset.QuadPart,
- range.Length.QuadPart);
+ entry_size,
+ 0);
}
break;
} else {
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_filter.3 b/Utilities/cmlibarchive/libarchive/archive_read_filter.3
index 7f020e373..ef0a70175 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_filter.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_filter.3
@@ -38,6 +38,7 @@
.Nm archive_read_support_filter_rpm ,
.Nm archive_read_support_filter_uu ,
.Nm archive_read_support_filter_xz ,
+.Nm archive_read_support_filter_zstd ,
.Nm archive_read_support_filter_program ,
.Nm archive_read_support_filter_program_signature
.Nd functions for reading streaming archives
@@ -73,6 +74,8 @@ Streaming Archive Library (libarchive, -larchive)
.Ft int
.Fn archive_read_support_filter_xz "struct archive *"
.Ft int
+.Fn archive_read_support_filter_zstd "struct archive *"
+.Ft int
.Fo archive_read_support_filter_program
.Fa "struct archive *"
.Fa "const char *cmd"
@@ -99,7 +102,8 @@ Streaming Archive Library (libarchive, -larchive)
.Fn archive_read_support_filter_none ,
.Fn archive_read_support_filter_rpm ,
.Fn archive_read_support_filter_uu ,
-.Fn archive_read_support_filter_xz
+.Fn archive_read_support_filter_xz ,
+.Fn archive_read_support_filter_zstd ,
.Xc
Enables auto-detection code and decompression support for the
specified compression.
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_format.3 b/Utilities/cmlibarchive/libarchive/archive_read_format.3
index 53b9a7e0e..91c5d2cfd 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_format.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_format.3
@@ -37,9 +37,9 @@
.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_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
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open.3 b/Utilities/cmlibarchive/libarchive/archive_read_open.3
index 4d8272cac..2278ebc33 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_open.3
+++ b/Utilities/cmlibarchive/libarchive/archive_read_open.3
@@ -33,7 +33,7 @@
.Nm archive_read_open_fd ,
.Nm archive_read_open_FILE ,
.Nm archive_read_open_filename ,
-.Nm archive_read_open_memory ,
+.Nm archive_read_open_memory
.Nd functions for reading streaming archives
.Sh LIBRARY
Streaming Archive Library (libarchive, -larchive)
@@ -67,7 +67,7 @@ Streaming Archive Library (libarchive, -larchive)
.Fa "size_t block_size"
.Fc
.Ft int
-.Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size"
+.Fn archive_read_open_memory "struct archive *" "const void *buff" "size_t size"
.Sh DESCRIPTION
.Bl -tag -compact -width indent
.It Fn archive_read_open
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
index 68c53de41..edb508c1d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c
@@ -71,6 +71,8 @@ archive_read_support_filter_all(struct archive *a)
archive_read_support_filter_grzip(a);
/* Lz4 falls back to "lz4 -d" command-line program. */
archive_read_support_filter_lz4(a);
+ /* Zstd falls back to "zstd -d" command-line program. */
+ archive_read_support_filter_zstd(a);
/* Note: We always return ARCHIVE_OK here, even if some of the
* above return ARCHIVE_WARN. The intent here is to enable
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c
index 663e2d3d6..147f5027f 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_lz4.c
@@ -494,7 +494,7 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
if (read_buf == NULL)
goto truncated_error;
compressed_size = archive_le32dec(read_buf);
- if ((compressed_size & ~(1 << 31)) > state->flags.block_maximum_size)
+ if ((compressed_size & 0x7fffffff) > state->flags.block_maximum_size)
goto malformed_error;
/* A compressed size == 0 means the end of stream blocks. */
if (compressed_size == 0) {
@@ -504,8 +504,8 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p)
checksum_size = state->flags.block_checksum;
/* Check if the block is uncompressed. */
- if (compressed_size & (1 << 31)) {
- compressed_size &= ~(1 << 31);
+ if (compressed_size & 0x80000000U) {
+ compressed_size &= 0x7fffffff;
uncompressed_size = compressed_size;
} else
uncompressed_size = 0;/* Unknown yet. */
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
index 96774f4e3..a885a4c45 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c
@@ -975,18 +975,6 @@ decode_codec_id(const unsigned char *codecId, size_t id_size)
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)
{
@@ -1006,8 +994,6 @@ ppmd_read(void *p)
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)
@@ -1237,7 +1223,7 @@ init_decompression(struct archive_read *a, struct _7zip *zip,
if (zip->ppmd7_valid) {
__archive_ppmd7_functions.Ppmd7_Free(
- &zip->ppmd7_context, &g_szalloc);
+ &zip->ppmd7_context);
zip->ppmd7_valid = 0;
}
@@ -1256,7 +1242,7 @@ init_decompression(struct archive_read *a, struct _7zip *zip,
}
__archive_ppmd7_functions.Ppmd7_Construct(&zip->ppmd7_context);
r = __archive_ppmd7_functions.Ppmd7_Alloc(
- &zip->ppmd7_context, msize, &g_szalloc);
+ &zip->ppmd7_context, msize);
if (r == 0) {
archive_set_error(&a->archive, ENOMEM,
"Coludn't allocate memory for PPMd");
@@ -1636,7 +1622,7 @@ free_decompression(struct archive_read *a, struct _7zip *zip)
#endif
if (zip->ppmd7_valid) {
__archive_ppmd7_functions.Ppmd7_Free(
- &zip->ppmd7_context, &g_szalloc);
+ &zip->ppmd7_context);
zip->ppmd7_valid = 0;
}
return (r);
@@ -2569,6 +2555,7 @@ read_Header(struct archive_read *a, struct _7z_header_info *h,
case kDummy:
if (ll == 0)
break;
+ __LA_FALLTHROUGH;
default:
if (header_bytes(a, ll) == NULL)
return (-1);
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c
index 20eb157f2..51f79fa6b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c
@@ -116,19 +116,11 @@ struct lzx_dec {
* 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;
@@ -187,7 +179,7 @@ struct lzx_stream {
#define CFDATA_cbData 4
#define CFDATA_cbUncomp 6
-static const char *compression_name[] = {
+static const char * const compression_name[] = {
"NONE",
"MSZIP",
"Quantum",
@@ -352,7 +344,6 @@ 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
@@ -3127,7 +3118,6 @@ getdata:
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);
@@ -3138,21 +3128,11 @@ lzx_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits)
} 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]));
+ hf->tbl = malloc(((size_t)1 << tbl_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);
}
@@ -3161,7 +3141,6 @@ lzx_huffman_free(struct huffman *hf)
{
free(hf->bitlen);
free(hf->tbl);
- free(hf->tree);
}
/*
@@ -3174,7 +3153,7 @@ lzx_make_huffman_table(struct huffman *hf)
const unsigned char *bitlen;
int bitptn[17], weight[17];
int i, maxbits = 0, ptn, tbl_size, w;
- int diffbits, len_avail;
+ int len_avail;
/*
* Initialize bit patterns.
@@ -3205,28 +3184,11 @@ lzx_make_huffman_table(struct huffman *hf)
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_size = 1 << hf->tbl_bits;
tbl = hf->tbl;
bitlen = hf->bitlen;
len_avail = hf->len_size;
@@ -3234,120 +3196,32 @@ lzx_make_huffman_table(struct huffman *hf)
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];
+ if (len > tbl_size)
+ return (0);
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;
- }
+ /* 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;
}
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];
+ c = hf->tbl[rbits];
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));
+ return (0);
}
-
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
index ffd4a8580..67d5b21ee 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c
@@ -165,7 +165,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_cpio.c 20116
struct links_entry {
struct links_entry *next;
struct links_entry *previous;
- int links;
+ unsigned int links;
dev_t dev;
int64_t ino;
char *name;
@@ -633,6 +633,13 @@ header_newc(struct archive_read *a, struct cpio *cpio,
/* Pad name to 2 more than a multiple of 4. */
*name_pad = (2 - *namelength) & 3;
+ /* Make sure that the padded name length fits into size_t. */
+ if (*name_pad > SIZE_MAX - *namelength) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "cpio archive has invalid namelength");
+ return (ARCHIVE_FATAL);
+ }
+
/*
* Note: entry_bytes_remaining is at least 64 bits and
* therefore guaranteed to be big enough for a 33-bit file
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
index 354133005..93649f862 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c
@@ -409,7 +409,8 @@ 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);
+ struct file_info *parent, const unsigned char *isodirrec,
+ size_t reclen);
static int parse_rockridge(struct archive_read *a,
struct file_info *file, const unsigned char *start,
const unsigned char *end);
@@ -1022,7 +1023,7 @@ read_children(struct archive_read *a, struct file_info *parent)
if (*(p + DR_name_len_offset) == 1
&& *(p + DR_name_offset) == '\001')
continue;
- child = parse_file_info(a, parent, p);
+ child = parse_file_info(a, parent, p, b - p);
if (child == NULL) {
__archive_read_consume(a, skip_size);
return (ARCHIVE_FATAL);
@@ -1112,7 +1113,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)
*/
seenJoliet = iso9660->seenJoliet;/* Save flag. */
iso9660->seenJoliet = 0;
- file = parse_file_info(a, NULL, block);
+ file = parse_file_info(a, NULL, block, vd->size);
if (file == NULL)
return (ARCHIVE_FATAL);
iso9660->seenJoliet = seenJoliet;
@@ -1144,7 +1145,7 @@ choose_volume(struct archive_read *a, struct iso9660 *iso9660)
return (ARCHIVE_FATAL);
}
iso9660->seenJoliet = 0;
- file = parse_file_info(a, NULL, block);
+ file = parse_file_info(a, NULL, block, vd->size);
if (file == NULL)
return (ARCHIVE_FATAL);
iso9660->seenJoliet = seenJoliet;
@@ -1749,7 +1750,7 @@ archive_read_format_iso9660_cleanup(struct archive_read *a)
*/
static struct file_info *
parse_file_info(struct archive_read *a, struct file_info *parent,
- const unsigned char *isodirrec)
+ const unsigned char *isodirrec, size_t reclen)
{
struct iso9660 *iso9660;
struct file_info *file, *filep;
@@ -1763,16 +1764,20 @@ parse_file_info(struct archive_read *a, struct file_info *parent,
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) {
+ if (reclen != 0)
+ dr_len = (size_t)isodirrec[DR_length_offset];
+ /*
+ * Sanity check that reclen is not zero and dr_len is greater than
+ * reclen but at least 34
+ */
+ if (reclen == 0 || reclen < dr_len || dr_len < 34) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "Invalid length of directory record");
+ "Invalid length of directory record");
return (NULL);
}
+ 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 name_len doesn't exceed dr_len. */
if (dr_len - 33 < name_len || name_len == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -3021,8 +3026,9 @@ heap_add_entry(struct archive_read *a, struct heap_queue *heap,
ENOMEM, "Out of memory");
return (ARCHIVE_FATAL);
}
- memcpy(new_pending_files, heap->files,
- heap->allocated * sizeof(new_pending_files[0]));
+ if (heap->allocated)
+ 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;
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
index ebd7f2ccb..98d02c62d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c
@@ -701,6 +701,12 @@ archive_read_format_lha_read_header(struct archive_read *a,
* Prepare variables used to read a file content.
*/
lha->entry_bytes_remaining = lha->compsize;
+ if (lha->entry_bytes_remaining < 0) {
+ archive_set_error(&a->archive,
+ ARCHIVE_ERRNO_FILE_FORMAT,
+ "Invalid LHa entry size");
+ return (ARCHIVE_FATAL);
+ }
lha->entry_offset = 0;
lha->entry_crc_calculated = 0;
@@ -2480,7 +2486,7 @@ lzh_huffman_free(struct huffman *hf)
free(hf->tree);
}
-static char bitlen_tbl[0x400] = {
+static const char bitlen_tbl[0x400] = {
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c
index 4231ff500..5b0eadc08 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c
@@ -49,6 +49,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011
#include "archive.h"
#include "archive_entry.h"
#include "archive_private.h"
+#include "archive_rb.h"
#include "archive_read_private.h"
#include "archive_string.h"
#include "archive_pack_dev.h"
@@ -75,7 +76,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 2011
#define MTREE_HAS_OPTIONAL 0x0800
#define MTREE_HAS_NOCHANGE 0x1000 /* FreeBSD specific */
-#define MTREE_HASHTABLE_SIZE 1024
+#define MAX_LINE_LEN (1024 * 1024)
struct mtree_option {
struct mtree_option *next;
@@ -83,13 +84,13 @@ struct mtree_option {
};
struct mtree_entry {
+ struct archive_rb_node rbnode;
+ struct mtree_entry *next_dup;
struct mtree_entry *next;
struct mtree_option *options;
char *name;
char full;
char used;
- unsigned int name_hash;
- struct mtree_entry *hashtable_next;
};
struct mtree {
@@ -102,11 +103,12 @@ struct mtree {
const char *archive_format_name;
struct mtree_entry *entries;
struct mtree_entry *this_entry;
- struct mtree_entry *entry_hashtable[MTREE_HASHTABLE_SIZE];
+ struct archive_rb_tree entry_rbtree;
struct archive_string current_dir;
struct archive_string contents_name;
struct archive_entry_linkresolver *resolver;
+ struct archive_rb_tree rbtree;
int64_t cur_size;
char checkfs;
@@ -115,7 +117,6 @@ struct mtree {
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 unsigned int hash(const char *);
static int mtree_bid(struct archive_read *, int);
static int parse_file(struct archive_read *, struct archive_entry *,
struct mtree *, struct mtree_entry *, int *);
@@ -130,9 +131,7 @@ 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 **);
+static int64_t mtree_atol(char **, int base);
/*
* There's no standard for TIME_T_MAX/TIME_T_MIN. So we compute them
@@ -219,9 +218,30 @@ free_options(struct mtree_option *head)
}
}
+static int
+mtree_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(e1->name, e2->name));
+}
+
+static int
+mtree_cmp_key(const struct archive_rb_node *n, const void *key)
+{
+ const struct mtree_entry *e = (const struct mtree_entry *)n;
+
+ return (strcmp(e->name, key));
+}
+
int
archive_read_support_format_mtree(struct archive *_a)
{
+ static const struct archive_rb_tree_ops rb_ops = {
+ mtree_cmp_node, mtree_cmp_key,
+ };
struct archive_read *a = (struct archive_read *)_a;
struct mtree *mtree;
int r;
@@ -237,6 +257,8 @@ archive_read_support_format_mtree(struct archive *_a)
}
mtree->fd = -1;
+ __archive_rb_tree_init(&mtree->rbtree, &rb_ops);
+
r = __archive_read_register_format(a, mtree, "mtree",
mtree_bid, archive_read_format_mtree_options, read_header, read_data, skip, NULL, cleanup, NULL, NULL);
@@ -336,6 +358,14 @@ next_line(struct archive_read *a,
size_t nbytes_req = (*ravail+1023) & ~1023U;
ssize_t tested;
+ /*
+ * Place an arbitrary limit on the line length.
+ * mtree is almost free-form input and without line length limits,
+ * it can consume a lot of memory.
+ */
+ if (len >= MAX_LINE_LEN)
+ return (-1);
+
/* Increase reading bytes if it is not enough to at least
* new two lines. */
if (nbytes_req < (size_t)*ravail + 160)
@@ -399,41 +429,41 @@ bid_keycmp(const char *p, const char *key, ssize_t len)
static int
bid_keyword(const char *p, ssize_t len)
{
- static const char *keys_c[] = {
+ static const char * const keys_c[] = {
"content", "contents", "cksum", NULL
};
- static const char *keys_df[] = {
+ static const char * const keys_df[] = {
"device", "flags", NULL
};
- static const char *keys_g[] = {
+ static const char * const keys_g[] = {
"gid", "gname", NULL
};
- static const char *keys_il[] = {
+ static const char * const keys_il[] = {
"ignore", "inode", "link", NULL
};
- static const char *keys_m[] = {
+ static const char * const keys_m[] = {
"md5", "md5digest", "mode", NULL
};
- static const char *keys_no[] = {
+ static const char * const keys_no[] = {
"nlink", "nochange", "optional", NULL
};
- static const char *keys_r[] = {
+ static const char * const keys_r[] = {
"resdevice", "rmd160", "rmd160digest", NULL
};
- static const char *keys_s[] = {
+ static const char * const keys_s[] = {
"sha1", "sha1digest",
"sha256", "sha256digest",
"sha384", "sha384digest",
"sha512", "sha512digest",
"size", NULL
};
- static const char *keys_t[] = {
+ static const char * const keys_t[] = {
"tags", "time", "type", NULL
};
- static const char *keys_u[] = {
+ static const char * const keys_u[] = {
"uid", "uname", NULL
};
- const char **keys;
+ const char * const *keys;
int i;
switch (*p) {
@@ -867,12 +897,11 @@ 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, *ht_iter;
+ struct mtree_entry *entry;
struct mtree_option *iter;
const char *next, *eq, *name, *end;
size_t name_len, len;
int r, i;
- unsigned int ht_idx;
if ((entry = malloc(sizeof(*entry))) == NULL) {
archive_set_error(&a->archive, errno, "Can't allocate memory");
@@ -883,8 +912,6 @@ process_add_entry(struct archive_read *a, struct mtree *mtree,
entry->name = NULL;
entry->used = 0;
entry->full = 0;
- entry->name_hash = 0;
- entry->hashtable_next = NULL;
/* Add this entry to list. */
if (*last_entry == NULL)
@@ -937,15 +964,17 @@ process_add_entry(struct archive_read *a, struct mtree *mtree,
memcpy(entry->name, name, name_len);
entry->name[name_len] = '\0';
parse_escapes(entry->name, entry);
- entry->name_hash = hash(entry->name);
- ht_idx = entry->name_hash % MTREE_HASHTABLE_SIZE;
- if ((ht_iter = mtree->entry_hashtable[ht_idx]) != NULL) {
- while (ht_iter->hashtable_next)
- ht_iter = ht_iter->hashtable_next;
- ht_iter->hashtable_next = entry;
- } else {
- mtree->entry_hashtable[ht_idx] = entry;
+ entry->next_dup = NULL;
+ if (entry->full) {
+ if (!__archive_rb_tree_insert_node(&mtree->rbtree, &entry->rbnode)) {
+ struct mtree_entry *alt;
+ alt = (struct mtree_entry *)__archive_rb_tree_find_node(
+ &mtree->rbtree, entry->name);
+ while (alt->next_dup)
+ alt = alt->next_dup;
+ alt->next_dup = entry;
+ }
}
for (iter = *global; iter != NULL; iter = iter->next) {
@@ -1140,14 +1169,13 @@ parse_file(struct archive_read *a, struct archive_entry *entry,
* with pathname canonicalization, which is a very
* tricky subject.)
*/
- for (mp = mentry->hashtable_next; mp != NULL; mp = mp->hashtable_next) {
- if (mp->full && !mp->used
- && mentry->name_hash == mp->name_hash
- && strcmp(mentry->name, mp->name) == 0) {
+ mp = (struct mtree_entry *)__archive_rb_tree_find_node(
+ &mtree->rbtree, mentry->name);
+ for (; mp; mp = mp->next_dup) {
+ if (mp->full && !mp->used) {
/* Later lines override earlier ones. */
mp->used = 1;
- r1 = parse_line(a, entry, mtree, mp,
- &parsed_kws);
+ r1 = parse_line(a, entry, mtree, mp, &parsed_kws);
if (r1 < r)
r = r1;
}
@@ -1418,7 +1446,7 @@ parse_device(dev_t *pdev, struct archive *a, char *val)
"Too many arguments");
return ARCHIVE_WARN;
}
- numbers[argc++] = (unsigned long)mtree_atol(&p);
+ numbers[argc++] = (unsigned long)mtree_atol(&p, 0);
}
if (argc < 2) {
archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
@@ -1433,7 +1461,7 @@ parse_device(dev_t *pdev, struct archive *a, char *val)
}
} else {
/* file system raw value. */
- result = (dev_t)mtree_atol(&val);
+ result = (dev_t)mtree_atol(&val, 0);
}
*pdev = result;
return ARCHIVE_OK;
@@ -1491,6 +1519,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
}
if (strcmp(key, "cksum") == 0)
break;
+ __LA_FALLTHROUGH;
case 'd':
if (strcmp(key, "device") == 0) {
/* stat(2) st_rdev field, e.g. the major/minor IDs
@@ -1504,16 +1533,18 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
archive_entry_set_rdev(entry, dev);
return r;
}
+ __LA_FALLTHROUGH;
case 'f':
if (strcmp(key, "flags") == 0) {
*parsed_kws |= MTREE_HAS_FFLAGS;
archive_entry_copy_fflags_text(entry, val);
break;
}
+ __LA_FALLTHROUGH;
case 'g':
if (strcmp(key, "gid") == 0) {
*parsed_kws |= MTREE_HAS_GID;
- archive_entry_set_gid(entry, mtree_atol10(&val));
+ archive_entry_set_gid(entry, mtree_atol(&val, 10));
break;
}
if (strcmp(key, "gname") == 0) {
@@ -1521,39 +1552,44 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
archive_entry_copy_gname(entry, val);
break;
}
+ __LA_FALLTHROUGH;
case 'i':
if (strcmp(key, "inode") == 0) {
- archive_entry_set_ino(entry, mtree_atol10(&val));
+ archive_entry_set_ino(entry, mtree_atol(&val, 10));
break;
}
+ __LA_FALLTHROUGH;
case 'l':
if (strcmp(key, "link") == 0) {
archive_entry_copy_symlink(entry, val);
break;
}
+ __LA_FALLTHROUGH;
case 'm':
if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0)
break;
if (strcmp(key, "mode") == 0) {
- if (val[0] >= '0' && val[0] <= '9') {
+ if (val[0] >= '0' && val[0] <= '7') {
*parsed_kws |= MTREE_HAS_PERM;
archive_entry_set_perm(entry,
- (mode_t)mtree_atol8(&val));
+ (mode_t)mtree_atol(&val, 8));
} else {
archive_set_error(&a->archive,
ARCHIVE_ERRNO_FILE_FORMAT,
- "Symbolic mode \"%s\" unsupported", val);
+ "Symbolic or non-octal mode \"%s\" unsupported", val);
return ARCHIVE_WARN;
}
break;
}
+ __LA_FALLTHROUGH;
case 'n':
if (strcmp(key, "nlink") == 0) {
*parsed_kws |= MTREE_HAS_NLINK;
archive_entry_set_nlink(entry,
- (unsigned int)mtree_atol10(&val));
+ (unsigned int)mtree_atol(&val, 10));
break;
}
+ __LA_FALLTHROUGH;
case 'r':
if (strcmp(key, "resdevice") == 0) {
/* stat(2) st_dev field, e.g. the device ID where the
@@ -1569,6 +1605,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
if (strcmp(key, "rmd160") == 0 ||
strcmp(key, "rmd160digest") == 0)
break;
+ __LA_FALLTHROUGH;
case 's':
if (strcmp(key, "sha1") == 0 || strcmp(key, "sha1digest") == 0)
break;
@@ -1582,9 +1619,10 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
strcmp(key, "sha512digest") == 0)
break;
if (strcmp(key, "size") == 0) {
- archive_entry_set_size(entry, mtree_atol10(&val));
+ archive_entry_set_size(entry, mtree_atol(&val, 10));
break;
}
+ __LA_FALLTHROUGH;
case 't':
if (strcmp(key, "tags") == 0) {
/*
@@ -1601,13 +1639,13 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
long ns = 0;
*parsed_kws |= MTREE_HAS_MTIME;
- m = mtree_atol10(&val);
+ m = mtree_atol(&val, 10);
/* Replicate an old mtree bug:
* 123456789.1 represents 123456789
* seconds and 1 nanosecond. */
if (*val == '.') {
++val;
- ns = (long)mtree_atol10(&val);
+ ns = (long)mtree_atol(&val, 10);
if (ns < 0)
ns = 0;
else if (ns > 999999999)
@@ -1627,18 +1665,21 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
archive_entry_set_filetype(entry, AE_IFBLK);
break;
}
+ __LA_FALLTHROUGH;
case 'c':
if (strcmp(val, "char") == 0) {
archive_entry_set_filetype(entry,
AE_IFCHR);
break;
}
+ __LA_FALLTHROUGH;
case 'd':
if (strcmp(val, "dir") == 0) {
archive_entry_set_filetype(entry,
AE_IFDIR);
break;
}
+ __LA_FALLTHROUGH;
case 'f':
if (strcmp(val, "fifo") == 0) {
archive_entry_set_filetype(entry,
@@ -1650,12 +1691,14 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
AE_IFREG);
break;
}
+ __LA_FALLTHROUGH;
case 'l':
if (strcmp(val, "link") == 0) {
archive_entry_set_filetype(entry,
AE_IFLNK);
break;
}
+ __LA_FALLTHROUGH;
default:
archive_set_error(&a->archive,
ARCHIVE_ERRNO_FILE_FORMAT,
@@ -1667,10 +1710,11 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
*parsed_kws |= MTREE_HAS_TYPE;
break;
}
+ __LA_FALLTHROUGH;
case 'u':
if (strcmp(key, "uid") == 0) {
*parsed_kws |= MTREE_HAS_UID;
- archive_entry_set_uid(entry, mtree_atol10(&val));
+ archive_entry_set_uid(entry, mtree_atol(&val, 10));
break;
}
if (strcmp(key, "uname") == 0) {
@@ -1678,6 +1722,7 @@ parse_keyword(struct archive_read *a, struct mtree *mtree,
archive_entry_copy_uname(entry, val);
break;
}
+ __LA_FALLTHROUGH;
default:
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
"Unrecognized key %s=%s", key, val);
@@ -1825,72 +1870,9 @@ parse_escapes(char *src, struct mtree_entry *mentry)
*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)
+parsedigit(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
@@ -1908,45 +1890,50 @@ parsehex(char c)
* it does obey locale.
*/
static int64_t
-mtree_atol16(char **p)
+mtree_atol(char **p, int base)
{
- int64_t l, limit, last_digit_limit;
- int base, digit, sign;
-
- base = 16;
+ int64_t l, limit;
+ int digit, last_digit_limit;
+
+ if (base == 0) {
+ if (**p != '0')
+ base = 10;
+ else if ((*p)[1] == 'x' || (*p)[1] == 'X') {
+ *p += 2;
+ base = 16;
+ } else {
+ base = 8;
+ }
+ }
if (**p == '-') {
- sign = -1;
- limit = ((uint64_t)(INT64_MAX) + 1) / base;
- last_digit_limit = ((uint64_t)(INT64_MAX) + 1) % base;
+ limit = INT64_MIN / base;
+ last_digit_limit = INT64_MIN % base;
++(*p);
+
+ l = 0;
+ digit = parsedigit(**p);
+ while (digit >= 0 && digit < base) {
+ if (l < limit || (l == limit && digit > last_digit_limit))
+ return INT64_MIN;
+ l = (l * base) - digit;
+ digit = parsedigit(*++(*p));
+ }
+ return l;
} 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);
+ l = 0;
+ digit = parsedigit(**p);
+ while (digit >= 0 && digit < base) {
+ if (l > limit || (l == limit && digit > last_digit_limit))
+ return INT64_MAX;
+ l = (l * base) + digit;
+ digit = parsedigit(*++(*p));
+ }
+ return l;
}
- return mtree_atol8(p);
}
/*
@@ -2022,19 +2009,3 @@ readline(struct archive_read *a, struct mtree *mtree, char **start,
find_off = u - mtree->line.s;
}
}
-
-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_read_support_format_rar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c
index 658d49d50..c68d77b49 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c
@@ -604,20 +604,6 @@ lzss_emit_match(struct rar *rar, int offset, int length)
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)
{
@@ -1038,7 +1024,7 @@ archive_read_format_rar_read_data(struct archive_read *a, const void **buff,
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);
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context);
break;
default:
@@ -1253,7 +1239,7 @@ archive_read_format_rar_cleanup(struct archive_read *a)
free(rar->dbo);
free(rar->unp_buffer);
free(rar->lzss.window);
- __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc);
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context);
free(rar);
(a->format->data) = NULL;
return (ARCHIVE_OK);
@@ -1496,7 +1482,11 @@ read_header(struct archive_read *a, struct archive_entry *entry,
return (ARCHIVE_FATAL);
}
filename[filename_size++] = '\0';
- filename[filename_size++] = '\0';
+ /*
+ * Do not increment filename_size here as the computations below
+ * add the space for the terminating NUL explicitly.
+ */
+ filename[filename_size] = '\0';
/* Decoded unicode form is UTF-16BE, so we have to update a string
* conversion object for it. */
@@ -1654,7 +1644,7 @@ read_header(struct archive_read *a, struct archive_entry *entry,
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);
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context);
rar->ppmd_valid = rar->ppmd_eod = 0;
/* Don't set any archive entries for non-file header types */
@@ -1750,7 +1740,7 @@ read_exttime(const char *p, struct rar *rar, const char *endp)
return (-1);
for (j = 0; j < count; j++)
{
- rem = ((*p) << 16) | (rem >> 8);
+ rem = (((unsigned)(unsigned char)*p) << 16) | (rem >> 8);
p++;
}
tm = localtime(&t);
@@ -2118,7 +2108,7 @@ parse_codes(struct archive_read *a)
/* 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);
+ __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context);
rar->bytein.a = a;
rar->bytein.Read = &ppmd_read;
@@ -2133,7 +2123,7 @@ parse_codes(struct archive_read *a)
}
if (!__archive_ppmd7_functions.Ppmd7_Alloc(&rar->ppmd7_context,
- rar->dictionary_size, &g_szalloc))
+ rar->dictionary_size))
{
archive_set_error(&a->archive, ENOMEM,
"Out of memory");
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
index bd7f13d52..60800bb81 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c
@@ -155,6 +155,7 @@ struct tar {
int compat_2x;
int process_mac_extensions;
int read_concatenated_archives;
+ int realsize_override;
};
static int archive_block_is_null(const char *p);
@@ -250,15 +251,15 @@ archive_read_support_format_tar(struct archive *_a)
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);
}
+#ifdef HAVE_COPYFILE_H
+ /* Set this by default on Mac OS. */
+ tar->process_mac_extensions = 1;
+#endif
r = __archive_read_register_format(a, tar, "tar",
archive_read_format_tar_bid,
@@ -527,6 +528,7 @@ archive_read_format_tar_read_header(struct archive_read *a,
tar->entry_offset = 0;
gnu_clear_sparse_list(tar);
tar->realsize = -1; /* Mark this as "unset" */
+ tar->realsize_override = 0;
/* Setup default string conversion. */
tar->sconv = tar->opt_sconv;
@@ -1894,6 +1896,7 @@ pax_attribute(struct archive_read *a, struct tar *tar,
if (strcmp(key, "GNU.sparse.size") == 0) {
tar->realsize = tar_atol10(value, strlen(value));
archive_entry_set_size(entry, tar->realsize);
+ tar->realsize_override = 1;
}
/* GNU "0.1" sparse pax format. */
@@ -1925,6 +1928,7 @@ pax_attribute(struct archive_read *a, struct tar *tar,
if (strcmp(key, "GNU.sparse.realsize") == 0) {
tar->realsize = tar_atol10(value, strlen(value));
archive_entry_set_size(entry, tar->realsize);
+ tar->realsize_override = 1;
}
break;
case 'L':
@@ -1977,6 +1981,7 @@ pax_attribute(struct archive_read *a, struct tar *tar,
tar_atol10(value, strlen(value)));
} else if (strcmp(key, "SCHILY.realsize") == 0) {
tar->realsize = tar_atol10(value, strlen(value));
+ tar->realsize_override = 1;
archive_entry_set_size(entry, tar->realsize);
} else if (strncmp(key, "SCHILY.xattr.", 13) == 0) {
pax_attribute_schily_xattr(entry, key, value,
@@ -2055,14 +2060,12 @@ pax_attribute(struct archive_read *a, struct tar *tar,
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 ....
+ * The "size" pax header keyword always overrides the
+ * "size" field in the tar header.
+ * GNU.sparse.realsize, GNU.sparse.size and
+ * SCHILY.realsize override this value.
*/
- if (tar->realsize < 0) {
+ if (!tar->realsize_override) {
archive_entry_set_size(entry,
tar->entry_bytes_remaining);
tar->realsize
@@ -2206,6 +2209,7 @@ header_gnutar(struct archive_read *a, struct tar *tar,
tar->realsize
= tar_atol(header->realsize, sizeof(header->realsize));
archive_entry_set_size(entry, tar->realsize);
+ tar->realsize_override = 1;
}
if (header->sparse[0].offset[0] != 0) {
@@ -2237,7 +2241,7 @@ gnu_add_sparse_entry(struct archive_read *a, struct tar *tar,
else
tar->sparse_list = p;
tar->sparse_last = p;
- if (remaining < 0 || offset < 0) {
+ if (remaining < 0 || offset < 0 || offset > INT64_MAX - remaining) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Malformed sparse map data");
return (ARCHIVE_FATAL);
}
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c
index b16246514..e8753853f 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_warc.c
@@ -600,9 +600,10 @@ _warc_rdver(const char *buf, size_t bsz)
/* looks good so far, read the version number for a laugh */
buf += sizeof(magic) - 1U;
- if (isdigit(buf[0U]) && (buf[1U] == '.') && isdigit(buf[2U])) {
+ if (isdigit((unsigned char)buf[0U]) && (buf[1U] == '.') &&
+ isdigit((unsigned char)buf[2U])) {
/* we support a maximum of 2 digits in the minor version */
- if (isdigit(buf[3U]))
+ if (isdigit((unsigned char)buf[3U]))
end = 1U;
/* set up major version */
ver = (buf[0U] - '0') * 10000U;
@@ -686,7 +687,7 @@ _warc_rduri(const char *buf, size_t bsz)
/* spaces inside uri are not allowed, CRLF should follow */
for (p = val; p < eol; p++) {
- if (isspace(*p))
+ if (isspace((unsigned char)*p))
return res;
}
@@ -736,7 +737,7 @@ _warc_rdlen(const char *buf, size_t bsz)
while (val < eol && (*val == ' ' || *val == '\t'))
val++;
/* there must be at least one digit */
- if (!isdigit(*val))
+ if (!isdigit((unsigned char)*val))
return -1;
len = strtol(val, &on, 10);
if (on != eol) {
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
index eeac1c888..9292ed784 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c
@@ -1040,6 +1040,9 @@ atol10(const char *p, size_t char_cnt)
uint64_t l;
int digit;
+ if (char_cnt == 0)
+ return (0);
+
l = 0;
digit = *p - '0';
while (digit >= 0 && digit < 10 && char_cnt-- > 0) {
@@ -1054,7 +1057,10 @@ atol8(const char *p, size_t char_cnt)
{
int64_t l;
int digit;
-
+
+ if (char_cnt == 0)
+ return (0);
+
l = 0;
while (char_cnt-- > 0) {
if (*p >= '0' && *p <= '7')
@@ -2623,6 +2629,14 @@ strappend_base64(struct xar *xar,
archive_strncat(as, (const char *)buff, len);
}
+static int
+is_string(const char *known, const char *data, size_t len)
+{
+ if (strlen(known) != len)
+ return -1;
+ return memcmp(data, known, len);
+}
+
static void
xml_data(void *userData, const char *s, int len)
{
@@ -2674,26 +2688,26 @@ xml_data(void *userData, const char *s, int len)
archive_strncpy(&(xar->file->symlink), s, len);
break;
case FILE_TYPE:
- if (strncmp("file", s, len) == 0 ||
- strncmp("hardlink", s, len) == 0)
+ if (is_string("file", s, len) == 0 ||
+ is_string("hardlink", s, len) == 0)
xar->file->mode =
(xar->file->mode & ~AE_IFMT) | AE_IFREG;
- if (strncmp("directory", s, len) == 0)
+ if (is_string("directory", s, len) == 0)
xar->file->mode =
(xar->file->mode & ~AE_IFMT) | AE_IFDIR;
- if (strncmp("symlink", s, len) == 0)
+ if (is_string("symlink", s, len) == 0)
xar->file->mode =
(xar->file->mode & ~AE_IFMT) | AE_IFLNK;
- if (strncmp("character special", s, len) == 0)
+ if (is_string("character special", s, len) == 0)
xar->file->mode =
(xar->file->mode & ~AE_IFMT) | AE_IFCHR;
- if (strncmp("block special", s, len) == 0)
+ if (is_string("block special", s, len) == 0)
xar->file->mode =
(xar->file->mode & ~AE_IFMT) | AE_IFBLK;
- if (strncmp("socket", s, len) == 0)
+ if (is_string("socket", s, len) == 0)
xar->file->mode =
(xar->file->mode & ~AE_IFMT) | AE_IFSOCK;
- if (strncmp("fifo", s, len) == 0)
+ if (is_string("fifo", s, len) == 0)
xar->file->mode =
(xar->file->mode & ~AE_IFMT) | AE_IFIFO;
xar->file->has |= HAS_TYPE;
diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
index e56bd63ac..7e99b1275 100644
--- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
+++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c
@@ -347,7 +347,7 @@ fake_crc32(unsigned long crc, const void *buff, size_t len)
return 0;
}
-static struct {
+static const struct {
int id;
const char * name;
} compression_methods[] = {
@@ -511,7 +511,13 @@ process_extra(struct archive_read *a, const char *p, size_t extra_length, struct
case 0x5455:
{
/* Extended time field "UT". */
- int flags = p[offset];
+ int flags;
+ if (datasize == 0) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Incomplete extended time field");
+ return ARCHIVE_FAILED;
+ }
+ flags = p[offset];
offset++;
datasize--;
/* Flag bits indicate which dates are present. */
@@ -723,6 +729,11 @@ process_extra(struct archive_read *a, const char *p, size_t extra_length, struct
}
case 0x9901:
/* WinZip AES extra data field. */
+ if (datasize < 6) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "Incomplete AES field");
+ return ARCHIVE_FAILED;
+ }
if (p[offset + 2] == 'A' && p[offset + 3] == 'E') {
/* Vendor version. */
zip_entry->aes_extra.vendor =
@@ -881,6 +892,24 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
zip_entry->mode |= 0664;
}
+ /* Windows archivers sometimes use backslash as the directory separator.
+ Normalize to slash. */
+ if (zip_entry->system == 0 &&
+ (wp = archive_entry_pathname_w(entry)) != NULL) {
+ if (wcschr(wp, L'/') == NULL && wcschr(wp, L'\\') != NULL) {
+ size_t i;
+ struct archive_wstring s;
+ archive_string_init(&s);
+ archive_wstrcpy(&s, wp);
+ for (i = 0; i < archive_strlen(&s); i++) {
+ if (s.s[i] == '\\')
+ s.s[i] = '/';
+ }
+ archive_entry_copy_pathname_w(entry, s.s);
+ archive_wstring_free(&s);
+ }
+ }
+
/* Make sure that entries with a trailing '/' are marked as directories
* even if the External File Attributes contains bogus values. If this
* is not a directory and there is no type, assume regularfile. */
@@ -1056,6 +1085,7 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
zip->end_of_entry = 1;
/* Set up a more descriptive format name. */
+ archive_string_empty(&zip->format_name);
archive_string_sprintf(&zip->format_name, "ZIP %d.%d (%s)",
version / 10, version % 10,
compression_name(zip->entry->compression));
@@ -2407,7 +2437,7 @@ read_eocd(struct zip *zip, const char *p, int64_t current_offset)
* Examine Zip64 EOCD locator: If it's valid, store the information
* from it.
*/
-static void
+static int
read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p)
{
int64_t eocd64_offset;
@@ -2417,35 +2447,37 @@ read_zip64_eocd(struct archive_read *a, struct zip *zip, const char *p)
/* Central dir must be on first volume. */
if (archive_le32dec(p + 4) != 0)
- return;
+ return 0;
/* Must be only a single volume. */
if (archive_le32dec(p + 16) != 1)
- return;
+ return 0;
/* Find the Zip64 EOCD record. */
eocd64_offset = archive_le64dec(p + 8);
if (__archive_read_seek(a, eocd64_offset, SEEK_SET) < 0)
- return;
+ return 0;
if ((p = __archive_read_ahead(a, 56, NULL)) == NULL)
- return;
+ 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;
+ return 0;
if ((p = __archive_read_ahead(a, (size_t)eocd64_size, NULL)) == NULL)
- return;
+ return 0;
/* Sanity-check the EOCD64 */
if (archive_le32dec(p + 16) != 0) /* Must be disk #0 */
- return;
+ return 0;
if (archive_le32dec(p + 20) != 0) /* CD must be on disk #0 */
- return;
+ return 0;
/* CD can't be split. */
if (archive_le64dec(p + 24) != archive_le64dec(p + 32))
- return;
+ return 0;
/* Save the central directory offset for later use. */
zip->central_directory_offset = archive_le64dec(p + 48);
+
+ return 32;
}
static int
@@ -2483,15 +2515,14 @@ archive_read_format_zip_seekable_bid(struct archive_read *a, int best_bid)
if (memcmp(p + i, "PK\005\006", 4) == 0) {
int ret = read_eocd(zip, p + i,
current_offset + i);
- if (ret > 0) {
- /* Zip64 EOCD locator precedes
- * regular EOCD if present. */
- if (i >= 20
- && memcmp(p + i - 20, "PK\006\007", 4) == 0) {
- read_zip64_eocd(a, zip, p + i - 20);
- }
- return (ret);
+ /* Zip64 EOCD locator precedes
+ * regular EOCD if present. */
+ if (i >= 20 && memcmp(p + i - 20, "PK\006\007", 4) == 0) {
+ int ret_zip64 = read_zip64_eocd(a, zip, p + i - 20);
+ if (ret_zip64 > ret)
+ ret = ret_zip64;
}
+ return (ret);
}
i -= 4;
break;
diff --git a/Utilities/cmlibarchive/libarchive/archive_string.c b/Utilities/cmlibarchive/libarchive/archive_string.c
index 592ead2bd..554533ecb 100644
--- a/Utilities/cmlibarchive/libarchive/archive_string.c
+++ b/Utilities/cmlibarchive/libarchive/archive_string.c
@@ -202,7 +202,8 @@ 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);
- memmove(as->s + as->length, p, s);
+ if (s)
+ memmove(as->s + as->length, p, s);
as->length += s;
as->s[as->length] = 0;
return (as);
@@ -213,7 +214,8 @@ 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);
- wmemmove(as->s + as->length, p, s);
+ if (s)
+ wmemmove(as->s + as->length, p, s);
as->length += s;
as->s[as->length] = 0;
return (as);
diff --git a/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c
index 964ea2bea..969a5603a 100644
--- a/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c
+++ b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c
@@ -53,7 +53,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string_sprintf.c 189435 2009-03-
static void
append_uint(struct archive_string *as, uintmax_t d, unsigned base)
{
- static const char *digits = "0123456789abcdef";
+ static const char digits[] = "0123456789abcdef";
if (d >= base)
append_uint(as, d/base, base);
archive_strappend_char(as, digits[d % base]);
diff --git a/Utilities/cmlibarchive/libarchive/archive_util.c b/Utilities/cmlibarchive/libarchive/archive_util.c
index f56ca332d..e5c6e3bff 100644
--- a/Utilities/cmlibarchive/libarchive/archive_util.c
+++ b/Utilities/cmlibarchive/libarchive/archive_util.c
@@ -89,88 +89,6 @@ archive_version_string(void)
return (ARCHIVE_VERSION_STRING);
}
-const char *
-archive_version_details(void)
-{
- static struct archive_string str;
- static int init = 0;
- const char *zlib = archive_zlib_version();
- const char *liblzma = archive_liblzma_version();
- const char *bzlib = archive_bzlib_version();
- const char *liblz4 = archive_liblz4_version();
-
- if (!init) {
- archive_string_init(&str);
-
- archive_strcat(&str, ARCHIVE_VERSION_STRING);
- if (zlib != NULL) {
- archive_strcat(&str, " zlib/");
- archive_strcat(&str, zlib);
- }
- if (liblzma) {
- archive_strcat(&str, " liblzma/");
- archive_strcat(&str, liblzma);
- }
- if (bzlib) {
- const char *p = bzlib;
- const char *sep = strchr(p, ',');
- if (sep == NULL)
- sep = p + strlen(p);
- archive_strcat(&str, " bz2lib/");
- archive_strncat(&str, p, sep - p);
- }
- if (liblz4) {
- archive_strcat(&str, " liblz4/");
- archive_strcat(&str, liblz4);
- }
- }
- return str.s;
-}
-
-const char *
-archive_zlib_version(void)
-{
-#ifdef HAVE_ZLIB_H
- return ZLIB_VERSION;
-#else
- return NULL;
-#endif
-}
-
-const char *
-archive_liblzma_version(void)
-{
-#ifdef HAVE_LZMA_H
- return LZMA_VERSION_STRING;
-#else
- return NULL;
-#endif
-}
-
-const char *
-archive_bzlib_version(void)
-{
-#ifdef HAVE_BZLIB_H
- return BZ2_bzlibVersion();
-#else
- return NULL;
-#endif
-}
-
-const char *
-archive_liblz4_version(void)
-{
-#if defined(HAVE_LZ4_H) && defined(HAVE_LIBLZ4)
-#define str(s) #s
-#define NUMBER(x) str(x)
- return NUMBER(LZ4_VERSION_MAJOR) "." NUMBER(LZ4_VERSION_MINOR) "." NUMBER(LZ4_VERSION_RELEASE);
-#undef NUMBER
-#undef str
-#else
- return NULL;
-#endif
-}
-
int
archive_errno(struct archive *a)
{
@@ -222,7 +140,7 @@ archive_compression_name(struct archive *a)
/*
* Return a count of the number of compressed bytes processed.
*/
-int64_t
+la_int64_t
archive_position_compressed(struct archive *a)
{
return archive_filter_bytes(a, -1);
@@ -231,7 +149,7 @@ archive_position_compressed(struct archive *a)
/*
* Return a count of the number of uncompressed bytes processed.
*/
-int64_t
+la_int64_t
archive_position_uncompressed(struct archive *a)
{
return archive_filter_bytes(a, 0);
@@ -275,7 +193,7 @@ archive_copy_error(struct archive *dest, struct archive *src)
void
__archive_errx(int retvalue, const char *msg)
{
- static const char *msg1 = "Fatal Internal Error in libarchive: ";
+ static const char msg1[] = "Fatal Internal Error in libarchive: ";
size_t s;
s = write(2, msg1, strlen(msg1));
@@ -303,8 +221,8 @@ __archive_errx(int retvalue, const char *msg)
int
__archive_mktemp(const char *tmpdir)
{
- static const wchar_t *prefix = L"libarchive_";
- static const wchar_t *suffix = L"XXXXXXXXXX";
+ static const wchar_t prefix[] = L"libarchive_";
+ static const wchar_t suffix[] = L"XXXXXXXXXX";
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',
diff --git a/Utilities/cmlibarchive/libarchive/archive_virtual.c b/Utilities/cmlibarchive/libarchive/archive_virtual.c
index de2595a9e..f509ee5c6 100644
--- a/Utilities/cmlibarchive/libarchive/archive_virtual.c
+++ b/Utilities/cmlibarchive/libarchive/archive_virtual.c
@@ -48,7 +48,7 @@ archive_filter_name(struct archive *a, int n)
return ((a->vtable->archive_filter_name)(a, n));
}
-int64_t
+la_int64_t
archive_filter_bytes(struct archive *a, int n)
{
return ((a->vtable->archive_filter_bytes)(a, n));
@@ -124,14 +124,15 @@ archive_write_finish_entry(struct archive *a)
return ((a->vtable->archive_write_finish_entry)(a));
}
-ssize_t
+la_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)
+la_ssize_t
+archive_write_data_block(struct archive *a, const void *buff, size_t s,
+ la_int64_t o)
{
if (a->vtable->archive_write_data_block == NULL) {
archive_set_error(a, ARCHIVE_ERRNO_MISC,
@@ -156,7 +157,7 @@ archive_read_next_header2(struct archive *a, struct archive_entry *entry)
int
archive_read_data_block(struct archive *a,
- const void **buff, size_t *s, int64_t *o)
+ const void **buff, size_t *s, la_int64_t *o)
{
return ((a->vtable->archive_read_data_block)(a, buff, s, o));
}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write.3 b/Utilities/cmlibarchive/libarchive/archive_write.3
index 376d71dee..c1164f5b5 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write.3
@@ -71,7 +71,7 @@ support.
.\"
.Ss Set options
See
-.Xr archive_read_set_options 3 .
+.Xr archive_write_set_options 3 .
.\"
.Ss Open archive
See
diff --git a/Utilities/cmlibarchive/libarchive/archive_write.c b/Utilities/cmlibarchive/libarchive/archive_write.c
index 0634a2296..e8daf530d 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write.c
@@ -190,7 +190,7 @@ archive_write_get_bytes_in_last_block(struct archive *_a)
* an archive to itself recursively.
*/
int
-archive_write_set_skip_file(struct archive *_a, int64_t d, int64_t i)
+archive_write_set_skip_file(struct archive *_a, la_int64_t d, la_int64_t i)
{
struct archive_write *a = (struct archive_write *)_a;
archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC,
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
index ad5dc832f..203f4142b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter.c
@@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$");
#include "archive_private.h"
/* A table that maps filter codes to functions. */
-static
+static const
struct { int code; int (*setter)(struct archive *); } codes[] =
{
{ ARCHIVE_FILTER_NONE, archive_write_add_filter_none },
@@ -53,6 +53,7 @@ struct { int code; int (*setter)(struct archive *); } codes[] =
{ ARCHIVE_FILTER_LZOP, archive_write_add_filter_lzip },
{ ARCHIVE_FILTER_UU, archive_write_add_filter_uuencode },
{ ARCHIVE_FILTER_XZ, archive_write_add_filter_xz },
+ { ARCHIVE_FILTER_ZSTD, archive_write_add_filter_zstd },
{ -1, NULL }
};
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c
index 85eb087b0..b46b19a0c 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_b64encode.c
@@ -60,7 +60,7 @@ 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 void la_b64_encode(struct archive_string *, const unsigned char *, size_t);
static int64_t atol8(const char *, size_t);
static const char base64[] = {
@@ -180,7 +180,7 @@ archive_filter_b64encode_open(struct archive_write_filter *f)
}
static void
-b64_encode(struct archive_string *as, const unsigned char *p, size_t len)
+la_b64_encode(struct archive_string *as, const unsigned char *p, size_t len)
{
int c;
@@ -234,12 +234,12 @@ archive_filter_b64encode_write(struct archive_write_filter *f, const void *buff,
}
if (state->hold_len < LBYTES)
return (ret);
- b64_encode(&state->encoded_buff, state->hold, LBYTES);
+ la_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);
+ la_b64_encode(&state->encoded_buff, p, LBYTES);
/* Save remaining bytes. */
if (length > 0) {
@@ -270,7 +270,7 @@ archive_filter_b64encode_close(struct archive_write_filter *f)
/* Flush remaining bytes. */
if (state->hold_len != 0)
- b64_encode(&state->encoded_buff, state->hold, state->hold_len);
+ la_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);
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
index eac4011cb..ffa633c96 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_by_name.c
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD$");
#include "archive_private.h"
/* A table that maps names to functions. */
-static
+static const
struct { const char *name; int (*setter)(struct archive *); } names[] =
{
{ "b64encode", archive_write_add_filter_b64encode },
@@ -57,6 +57,7 @@ struct { const char *name; int (*setter)(struct archive *); } names[] =
{ "lzop", archive_write_add_filter_lzop },
{ "uuencode", archive_write_add_filter_uuencode },
{ "xz", archive_write_add_filter_xz },
+ { "zstd", archive_write_add_filter_zstd },
{ NULL, NULL }
};
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c
index bbcc1789a..986123ad8 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c
@@ -226,7 +226,12 @@ archive_compressor_gzip_open(struct archive_write_filter *f)
data->compressed[7] = (uint8_t)(t>>24)&0xff;
} else
memset(&data->compressed[4], 0, 4);
- data->compressed[8] = 0; /* No deflate options */
+ if (data->compression_level == 9)
+ data->compressed[8] = 2;
+ else if(data->compression_level == 1)
+ data->compressed[8] = 4;
+ else
+ data->compressed[8] = 0;
data->compressed[9] = 3; /* OS=Unix */
data->stream.next_out += 10;
data->stream.avail_out -= 10;
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c
index e6551859c..15fd494a4 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_lz4.c
@@ -225,7 +225,7 @@ archive_filter_lz4_open(struct archive_write_filter *f)
struct private_data *data = (struct private_data *)f->data;
int ret;
size_t required_size;
- static size_t bkmap[] = { 64 * 1024, 256 * 1024, 1 * 1024 * 1024,
+ static size_t const bkmap[] = { 64 * 1024, 256 * 1024, 1 * 1024 * 1024,
4 * 1024 * 1024 };
size_t pre_block_size;
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c
index 55b5e8ecd..660f693f2 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c
@@ -92,7 +92,7 @@ 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: ";
+ static const char prefix[] = "Program: ";
archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
ARCHIVE_STATE_NEW, "archive_write_add_filter_program");
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_data.3 b/Utilities/cmlibarchive/libarchive/archive_write_data.3
index 0cdd25f1f..9c16cd9b4 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_data.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_data.3
@@ -24,11 +24,12 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 2, 2012
+.Dd February 28, 2017
.Dt ARCHIVE_WRITE_DATA 3
.Os
.Sh NAME
-.Nm archive_write_data
+.Nm archive_write_data ,
+.Nm archive_write_data_block
.Nd functions for creating archives
.Sh LIBRARY
Streaming Archive Library (libarchive, -larchive)
@@ -36,8 +37,27 @@ Streaming Archive Library (libarchive, -larchive)
.In archive.h
.Ft la_ssize_t
.Fn archive_write_data "struct archive *" "const void *" "size_t"
+.Ft la_ssize_t
+.Fn archive_write_data_block "struct archive *" "const void *" "size_t size" "int64_t offset"
.Sh DESCRIPTION
+.Bl -tag -width indent
+.It Fn archive_write_data
+Write data corresponding to the header just written.
+.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.
+.El
.\" .Sh EXAMPLE
.\"
.Sh RETURN VALUES
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk.3 b/Utilities/cmlibarchive/libarchive/archive_write_disk.3
index ba6c9706e..949c9ef10 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk.3
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 2, 2012
+.Dd April 3, 2017
.Dt ARCHIVE_WRITE_DISK 3
.Os
.Sh NAME
@@ -33,14 +33,7 @@
.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
+.Nm archive_write_disk_set_user_lookup
.Nd functions for creating objects on disk
.Sh LIBRARY
Streaming Archive Library (libarchive, -larchive)
@@ -68,20 +61,6 @@ Streaming Archive Library (libarchive, -larchive)
.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 la_ssize_t
-.Fn archive_write_data "struct archive *" "const void *" "size_t"
-.Ft la_ssize_t
-.Fn archive_write_data_block "struct archive *" "const void *" "size_t size" "int64_t offset"
-.Ft int
-.Fn archive_write_finish_entry "struct archive *"
-.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
@@ -117,6 +96,33 @@ performance optimization in practice.
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_ACL
+Attempt to restore Access Control Lists.
+By default, extended ACLs are ignored.
+.It Cm ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS
+Before removing a file system object prior to replacing it, clear
+platform-specific file flags which might prevent its removal.
+.It Cm ARCHIVE_EXTRACT_FFLAGS
+Attempt to restore file attributes (file flags).
+By default, file attributes are ignored.
+See
+.Xr chattr 1
+.Pq Linux
+or
+.Xr chflags 1
+.Pq FreeBSD, Mac OS X
+for more information on file attributes.
+.It Cm ARCHIVE_EXTRACT_MAC_METADATA
+Mac OS X specific. Restore metadata using
+.Xr copyfile 3 .
+By default,
+.Xr copyfile 3
+metadata is ignored.
+.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_OWNER
The user and group IDs should be set on the restored file.
By default, the user and group IDs are not restored.
@@ -132,15 +138,37 @@ 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_SECURE_NOABSOLUTEPATHS
+Refuse to extract an absolute path.
+The default is to not refuse such paths.
+.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_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
+.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.
+.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_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.
@@ -148,45 +176,18 @@ 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.
+Attempt to restore extended file 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_SECURE_NOABSOLUTEPATHS
-Refuse to extract an absolute path.
-The default is to not refuse such paths.
-.It Cm ARCHIVE_EXTRACT_SPARSE
-Scan data for blocks of NUL bytes and try to recreate them with holes.
-This results in sparse files, independent of whether the archive format
-supports or uses them.
-.It Cm ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS
-Before removing a file system object prior to replacing it, clear
-platform-specific file flags which might prevent its removal.
+See
+.Xr xattr 7
+.Pq Linux ,
+.Xr xattr 2
+.Pq Mac OS X ,
+or
+.Xr getextattr 8
+.Pq FreeBSD
+for more information on extended file attributes.
.El
.It Xo
.Fn archive_write_disk_set_group_lookup ,
@@ -223,60 +224,6 @@ 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
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
index a5f30671a..affa50381 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c
@@ -39,9 +39,9 @@ __FBSDID("$FreeBSD$");
#ifdef HAVE_SYS_EXTATTR_H
#include <sys/extattr.h>
#endif
-#if defined(HAVE_SYS_XATTR_H)
+#if HAVE_SYS_XATTR_H
#include <sys/xattr.h>
-#elif defined(HAVE_ATTR_XATTR_H)
+#elif HAVE_ATTR_XATTR_H
#include <attr/xattr.h>
#endif
#ifdef HAVE_SYS_EA_H
@@ -575,10 +575,55 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
if (a->flags & ARCHIVE_EXTRACT_TIME)
a->todo |= TODO_TIMES;
if (a->flags & ARCHIVE_EXTRACT_ACL) {
+#if ARCHIVE_ACL_DARWIN
+ /*
+ * On MacOS, platform ACLs get stored in mac_metadata, too.
+ * If we intend to extract mac_metadata and it is present
+ * we skip extracting libarchive NFSv4 ACLs.
+ */
+ size_t metadata_size;
+
+ if ((a->flags & ARCHIVE_EXTRACT_MAC_METADATA) == 0 ||
+ archive_entry_mac_metadata(a->entry,
+ &metadata_size) == NULL || metadata_size == 0)
+#endif
+#if ARCHIVE_ACL_LIBRICHACL
+ /*
+ * RichACLs are stored in an extended attribute.
+ * If we intend to extract extended attributes and have this
+ * attribute we skip extracting libarchive NFSv4 ACLs.
+ */
+ short extract_acls = 1;
+ if (a->flags & ARCHIVE_EXTRACT_XATTR && (
+ archive_entry_acl_types(a->entry) &
+ ARCHIVE_ENTRY_ACL_TYPE_NFS4)) {
+ const char *attr_name;
+ const void *attr_value;
+ size_t attr_size;
+ int i = archive_entry_xattr_reset(a->entry);
+ while (i--) {
+ archive_entry_xattr_next(a->entry, &attr_name,
+ &attr_value, &attr_size);
+ if (attr_name != NULL && attr_value != NULL &&
+ attr_size > 0 && strcmp(attr_name,
+ "trusted.richacl") == 0) {
+ extract_acls = 0;
+ break;
+ }
+ }
+ }
+ if (extract_acls)
+#endif
+#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL
+ {
+#endif
if (archive_entry_filetype(a->entry) == AE_IFDIR)
a->deferred |= TODO_ACLS;
else
a->todo |= TODO_ACLS;
+#if ARCHIVE_ACL_DARWIN || ARCHIVE_ACL_LIBRICHACL
+ }
+#endif
}
if (a->flags & ARCHIVE_EXTRACT_MAC_METADATA) {
if (archive_entry_filetype(a->entry) == AE_IFDIR)
@@ -619,8 +664,21 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
}
#endif
- if (a->flags & ARCHIVE_EXTRACT_XATTR)
+ if (a->flags & ARCHIVE_EXTRACT_XATTR) {
+#if ARCHIVE_XATTR_DARWIN
+ /*
+ * On MacOS, extended attributes get stored in mac_metadata,
+ * too. If we intend to extract mac_metadata and it is present
+ * we skip extracting extended attributes.
+ */
+ size_t metadata_size;
+
+ if ((a->flags & ARCHIVE_EXTRACT_MAC_METADATA) == 0 ||
+ archive_entry_mac_metadata(a->entry,
+ &metadata_size) == NULL || metadata_size == 0)
+#endif
a->todo |= TODO_XATTR;
+ }
if (a->flags & ARCHIVE_EXTRACT_FFLAGS)
a->todo |= TODO_FFLAGS;
if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) {
@@ -777,7 +835,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
}
int
-archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i)
+archive_write_disk_set_skip_file(struct archive *_a, la_int64_t d, la_int64_t i)
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
@@ -1703,25 +1761,11 @@ _archive_write_disk_finish_entry(struct archive *_a)
*/
if (a->todo & TODO_ACLS) {
int r2;
-#ifdef HAVE_DARWIN_ACL
- /*
- * On Mac OS, platform ACLs are stored also in mac_metadata by
- * the operating system. If mac_metadata is present it takes
- * precedence and we skip extracting libarchive NFSv4 ACLs
- */
- const void *metadata;
- size_t metadata_size;
- metadata = archive_entry_mac_metadata(a->entry, &metadata_size);
- if ((a->todo & TODO_MAC_METADATA) == 0 ||
- metadata == NULL || metadata_size == 0) {
-#endif
r2 = archive_write_disk_set_acls(&a->archive, a->fd,
archive_entry_pathname(a->entry),
- archive_entry_acl(a->entry));
+ archive_entry_acl(a->entry),
+ archive_entry_mode(a->entry));
if (r2 < ret) ret = r2;
-#ifdef HAVE_DARWIN_ACL
- }
-#endif
}
finish_metadata:
@@ -1742,7 +1786,7 @@ finish_metadata:
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),
+ la_int64_t (*lookup_gid)(void *private, const char *gname, la_int64_t gid),
void (*cleanup_gid)(void *private))
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
@@ -1778,7 +1822,7 @@ archive_write_disk_set_user_lookup(struct archive *_a,
}
int64_t
-archive_write_disk_gid(struct archive *_a, const char *name, int64_t id)
+archive_write_disk_gid(struct archive *_a, const char *name, la_int64_t id)
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
@@ -1789,7 +1833,7 @@ archive_write_disk_gid(struct archive *_a, const char *name, int64_t id)
}
int64_t
-archive_write_disk_uid(struct archive *_a, const char *name, int64_t id)
+archive_write_disk_uid(struct archive *_a, const char *name, la_int64_t id)
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
@@ -1937,6 +1981,10 @@ restore_entry(struct archive_write_disk *a)
if ((en == EISDIR || en == EEXIST)
&& (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
/* If we're not overwriting, we're done. */
+ if (S_ISDIR(a->mode)) {
+ /* Don't overwrite any settings on existing directories. */
+ a->todo = 0;
+ }
archive_entry_unset_size(a->entry);
return (ARCHIVE_OK);
}
@@ -2293,13 +2341,8 @@ _archive_write_disk_close(struct archive *_a)
if (p->fixup & TODO_MODE_BASE)
chmod(p->name, p->mode);
if (p->fixup & TODO_ACLS)
-#ifdef HAVE_DARWIN_ACL
- if ((p->fixup & TODO_MAC_METADATA) == 0 ||
- p->mac_metadata == NULL ||
- p->mac_metadata_size == 0)
-#endif
- archive_write_disk_set_acls(&a->archive,
- -1, p->name, &p->acl);
+ archive_write_disk_set_acls(&a->archive, -1, p->name,
+ &p->acl, p->mode);
if (p->fixup & TODO_FFLAGS)
set_fflags_platform(a, -1, p->name,
p->mode, p->fflags_set, 0);
@@ -2467,7 +2510,7 @@ fsobj_error(int *a_eno, struct archive_string *a_estr,
if (a_eno)
*a_eno = err;
if (a_estr)
- archive_string_sprintf(a_estr, errstr, path);
+ archive_string_sprintf(a_estr, "%s%s", errstr, path);
}
/*
@@ -2573,7 +2616,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
* with the deep-directory editing.
*/
fsobj_error(a_eno, a_estr, errno,
- "Could not stat %s", path);
+ "Could not stat ", path);
res = ARCHIVE_FAILED;
break;
}
@@ -2582,7 +2625,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
if (chdir(head) != 0) {
tail[0] = c;
fsobj_error(a_eno, a_estr, errno,
- "Could not chdir %s", path);
+ "Could not chdir ", path);
res = (ARCHIVE_FATAL);
break;
}
@@ -2599,7 +2642,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
if (unlink(head)) {
tail[0] = c;
fsobj_error(a_eno, a_estr, errno,
- "Could not remove symlink %s",
+ "Could not remove symlink ",
path);
res = ARCHIVE_FAILED;
break;
@@ -2618,7 +2661,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
/*
if (!S_ISLNK(path)) {
fsobj_error(a_eno, a_estr, 0,
- "Removing symlink %s", path);
+ "Removing symlink ", path);
}
*/
/* Symlink gone. No more problem! */
@@ -2630,7 +2673,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
tail[0] = c;
fsobj_error(a_eno, a_estr, 0,
"Cannot remove intervening "
- "symlink %s", path);
+ "symlink ", path);
res = ARCHIVE_FAILED;
break;
}
@@ -2652,7 +2695,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
} else {
fsobj_error(a_eno, a_estr,
errno,
- "Could not stat %s", path);
+ "Could not stat ", path);
res = (ARCHIVE_FAILED);
break;
}
@@ -2661,7 +2704,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
tail[0] = c;
fsobj_error(a_eno, a_estr,
errno,
- "Could not chdir %s", path);
+ "Could not chdir ", path);
res = (ARCHIVE_FATAL);
break;
}
@@ -2674,14 +2717,14 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr,
tail[0] = c;
fsobj_error(a_eno, a_estr, 0,
"Cannot extract through "
- "symlink %s", path);
+ "symlink ", path);
res = ARCHIVE_FAILED;
break;
}
} else {
tail[0] = c;
fsobj_error(a_eno, a_estr, 0,
- "Cannot extract through symlink %s", path);
+ "Cannot extract through symlink ", path);
res = ARCHIVE_FAILED;
break;
}
@@ -4044,71 +4087,98 @@ skip_appledouble:
}
#endif
-#if HAVE_LSETXATTR || HAVE_LSETEA
+#if ARCHIVE_XATTR_LINUX || ARCHIVE_XATTR_DARWIN || ARCHIVE_XATTR_AIX
/*
- * Restore extended attributes - Linux and AIX implementations:
+ * Restore extended attributes - Linux, Darwin 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;
+ struct archive_string errlist;
int ret = ARCHIVE_OK;
int i = archive_entry_xattr_reset(entry);
+ short fail = 0;
+
+ archive_string_init(&errlist);
while (i--) {
const char *name;
const void *value;
size_t size;
+ int e;
+
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
+
+ if (name == NULL)
+ continue;
+#if ARCHIVE_XATTR_LINUX
+ /* Linux: quietly skip POSIX.1e ACL extended attributes */
+ if (strncmp(name, "system.", 7) == 0 &&
+ (strcmp(name + 7, "posix_acl_access") == 0 ||
+ strcmp(name + 7, "posix_acl_default") == 0))
+ continue;
+ if (strncmp(name, "trusted.SGI_", 12) == 0 &&
+ (strcmp(name + 12, "ACL_DEFAULT") == 0 ||
+ strcmp(name + 12, "ACL_FILE") == 0))
+ continue;
+
+ /* Linux: xfsroot namespace is obsolete and unsupported */
+ if (strncmp(name, "xfsroot.", 8) == 0) {
+ fail = 1;
+ archive_strcat(&errlist, name);
+ archive_strappend_char(&errlist, ' ');
+ continue;
+ }
#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);
+
+ if (a->fd >= 0) {
+#if ARCHIVE_XATTR_LINUX
+ e = fsetxattr(a->fd, name, value, size, 0);
+#elif ARCHIVE_XATTR_DARWIN
+ e = fsetxattr(a->fd, name, value, size, 0, 0);
+#elif ARCHIVE_XATTR_AIX
+ e = fsetea(a->fd, 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");
+#if ARCHIVE_XATTR_LINUX
+ e = lsetxattr(archive_entry_pathname(entry),
+ name, value, size, 0);
+#elif ARCHIVE_XATTR_DARWIN
+ e = setxattr(archive_entry_pathname(entry),
+ name, value, size, 0, XATTR_NOFOLLOW);
+#elif ARCHIVE_XATTR_AIX
+ e = lsetea(archive_entry_pathname(entry),
+ name, value, size, 0);
+#endif
+ }
+ if (e == -1) {
ret = ARCHIVE_WARN;
+ archive_strcat(&errlist, name);
+ archive_strappend_char(&errlist, ' ');
+ if (errno != ENOTSUP && errno != ENOSYS)
+ fail = 1;
}
}
+
+ if (ret == ARCHIVE_WARN) {
+ if (fail && errlist.length > 0) {
+ errlist.length--;
+ errlist.s[errlist.length] = '\0';
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Cannot restore extended attributes: %s",
+ errlist.s);
+ } else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Cannot restore extended "
+ "attributes on this file system.");
+ }
+
+ archive_string_free(&errlist);
return (ret);
}
-#elif HAVE_EXTATTR_SET_FILE && HAVE_DECL_EXTATTR_NAMESPACE_USER
+#elif ARCHIVE_XATTR_FREEBSD
/*
* Restore extended attributes - FreeBSD implementation
*/
@@ -4116,9 +4186,12 @@ static int
set_xattrs(struct archive_write_disk *a)
{
struct archive_entry *entry = a->entry;
- static int warning_done = 0;
+ struct archive_string errlist;
int ret = ARCHIVE_OK;
int i = archive_entry_xattr_reset(entry);
+ short fail = 0;
+
+ archive_string_init(&errlist);
while (i--) {
const char *name;
@@ -4134,46 +4207,47 @@ set_xattrs(struct archive_write_disk *a)
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);
+ /* Other namespaces are unsupported */
+ archive_strcat(&errlist, name);
+ archive_strappend_char(&errlist, ' ');
+ fail = 1;
ret = ARCHIVE_WARN;
continue;
}
- errno = 0;
-#if HAVE_EXTATTR_SET_FD
- if (a->fd >= 0)
+
+ 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(
+ } else {
+ e = extattr_set_link(
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");
- }
-
+ archive_strcat(&errlist, name);
+ archive_strappend_char(&errlist, ' ');
ret = ARCHIVE_WARN;
+ if (errno != ENOTSUP && errno != ENOSYS)
+ fail = 1;
}
}
}
+
+ if (ret == ARCHIVE_WARN) {
+ if (fail && errlist.length > 0) {
+ errlist.length--;
+ errlist.s[errlist.length] = '\0';
+
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Cannot restore extended attributes: %s",
+ errlist.s);
+ } else
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+ "Cannot restore extended "
+ "attributes on this file system.");
+ }
+
+ archive_string_free(&errlist);
return (ret);
}
#else
@@ -4239,5 +4313,19 @@ older(struct stat *st, struct archive_entry *entry)
return (0);
}
+#ifndef ARCHIVE_ACL_SUPPORT
+int
+archive_write_disk_set_acls(struct archive *a, int fd, const char *name,
+ struct archive_acl *abstract_acl, __LA_MODE_T mode)
+{
+ (void)a; /* UNUSED */
+ (void)fd; /* UNUSED */
+ (void)name; /* UNUSED */
+ (void)abstract_acl; /* UNUSED */
+ (void)mode; /* UNUSED */
+ return (ARCHIVE_OK);
+}
+#endif
+
#endif /* !_WIN32 || __CYGWIN__ */
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h
index d84e7e1cd..b655dea2b 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h
@@ -33,11 +33,13 @@
#ifndef ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED
#define ARCHIVE_WRITE_DISK_PRIVATE_H_INCLUDED
+#include "archive_platform_acl.h"
#include "archive_acl_private.h"
+#include "archive_entry.h"
struct archive_write_disk;
-int
-archive_write_disk_set_acls(struct archive *, int /* fd */, const char * /* pathname */, struct archive_acl *);
+int archive_write_disk_set_acls(struct archive *, int, const char *,
+ struct archive_acl *, __LA_MODE_T);
#endif
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
index 94b016edf..78eda4abc 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c
@@ -906,7 +906,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
}
int
-archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i)
+archive_write_disk_set_skip_file(struct archive *_a, la_int64_t d, la_int64_t i)
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
@@ -1156,7 +1156,7 @@ _archive_write_disk_finish_entry(struct archive *_a)
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),
+ la_int64_t (*lookup_gid)(void *private, const char *gname, la_int64_t gid),
void (*cleanup_gid)(void *private))
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
@@ -1192,7 +1192,7 @@ archive_write_disk_set_user_lookup(struct archive *_a,
}
int64_t
-archive_write_disk_gid(struct archive *_a, const char *name, int64_t id)
+archive_write_disk_gid(struct archive *_a, const char *name, la_int64_t id)
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
@@ -1203,7 +1203,7 @@ archive_write_disk_gid(struct archive *_a, const char *name, int64_t id)
}
int64_t
-archive_write_disk_uid(struct archive *_a, const char *name, int64_t id)
+archive_write_disk_uid(struct archive *_a, const char *name, la_int64_t id)
{
struct archive_write_disk *a = (struct archive_write_disk *)_a;
archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC,
@@ -1322,9 +1322,20 @@ restore_entry(struct archive_write_disk *a)
}
}
+ if ((en == ENOENT) && (archive_entry_hardlink(a->entry) != NULL)) {
+ archive_set_error(&a->archive, en,
+ "Hard-link target '%s' does not exist.",
+ archive_entry_hardlink(a->entry));
+ return (ARCHIVE_FAILED);
+ }
+
if ((en == EISDIR || en == EEXIST)
&& (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) {
/* If we're not overwriting, we're done. */
+ if (S_ISDIR(a->mode)) {
+ /* Don't overwrite any settings on existing directories. */
+ a->todo = 0;
+ }
archive_entry_unset_size(a->entry);
return (ARCHIVE_OK);
}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_filter.3 b/Utilities/cmlibarchive/libarchive/archive_write_filter.3
index e1d189150..d6fa07131 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_filter.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_filter.3
@@ -42,7 +42,8 @@
.Nm archive_write_add_filter_none ,
.Nm archive_write_add_filter_program ,
.Nm archive_write_add_filter_uuencode ,
-.Nm archive_write_add_filter_xz
+.Nm archive_write_add_filter_xz ,
+.Nm archive_write_add_filter_zstd ,
.Nd functions enabling output filters
.Sh LIBRARY
Streaming Archive Library (libarchive, -larchive)
@@ -76,6 +77,8 @@ Streaming Archive Library (libarchive, -larchive)
.Fn archive_write_add_filter_uuencode "struct archive *"
.Ft int
.Fn archive_write_add_filter_xz "struct archive *"
+.Ft int
+.Fn archive_write_add_filter_zstd "struct archive *"
.Sh DESCRIPTION
.Bl -tag -width indent
.It Xo
@@ -89,6 +92,7 @@ Streaming Archive Library (libarchive, -larchive)
.Fn archive_write_add_filter_lzma ,
.Fn archive_write_add_filter_lzop ,
.Fn archive_write_add_filter_xz ,
+.Fn archive_write_add_filter_zstd ,
.Xc
The resulting archive will be compressed as specified.
Note that the compressed output is always properly blocked.
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
index c5ef69ebc..dc1b94b82 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd February 2, 2012
+.Dd February 28, 2017
.Dt ARCHIVE_WRITE_FINISH_ENTRY 3
.Os
.Sh NAME
@@ -45,6 +45,9 @@ is called automatically by
and
.Fn archive_write_close
as needed.
+For
+.Tn archive_write_disk
+handles, this flushes pending file attribute changes like modification time.
.\" .Sh EXAMPLE
.Sh RETURN VALUES
This function returns
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_format.3 b/Utilities/cmlibarchive/libarchive/archive_write_format.3
index d4ba6abff..aaafb0a86 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_format.3
+++ b/Utilities/cmlibarchive/libarchive/archive_write_format.3
@@ -108,7 +108,6 @@ Streaming Archive Library (libarchive, -larchive)
These functions set the format that will be used for the archive.
.Pp
The library can write a variety of common archive formats.
-
.Bl -tag -width indent
.It Fn archive_write_set_format
Sets the format based on the format code (see
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
index 744302d06..0f706231a 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c
@@ -38,7 +38,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format.c 201168 2009-1
#include "archive_private.h"
/* A table that maps format codes to functions. */
-static
+static const
struct { int code; int (*setter)(struct archive *); } codes[] =
{
{ ARCHIVE_FORMAT_7ZIP, archive_write_set_format_7zip },
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c
index 3fc5a07d7..2bd4ec41f 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c
@@ -2095,19 +2095,6 @@ compression_init_encoder_lzma2(struct archive *a,
/*
* _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)
{
@@ -2167,7 +2154,7 @@ compression_init_encoder_ppmd(struct archive *a,
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);
+ &strm->ppmd7_context, msize);
if (r == 0) {
free(strm->buff);
free(strm);
@@ -2243,7 +2230,7 @@ compression_end_ppmd(struct archive *a, struct la_zstream *lastrm)
(void)a; /* UNUSED */
strm = (struct ppmd_stream *)lastrm->real_stream;
- __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context, &g_szalloc);
+ __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context);
free(strm->buff);
free(strm);
lastrm->real_stream = NULL;
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c
index c9771d81a..50305ccbe 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c
@@ -180,7 +180,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry)
}
memset(buff, ' ', 60);
- strncpy(&buff[AR_fmag_offset], "`\n", 2);
+ memcpy(&buff[AR_fmag_offset], "`\n", 2);
if (strcmp(pathname, "/") == 0 ) {
/* Entry is archive symbol table in GNU format */
@@ -189,7 +189,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry)
}
if (strcmp(pathname, "__.SYMDEF") == 0) {
/* Entry is archive symbol table in BSD format */
- strncpy(buff + AR_name_offset, "__.SYMDEF", 9);
+ memcpy(buff + AR_name_offset, "__.SYMDEF", 9);
goto stat;
}
if (strcmp(pathname, "//") == 0) {
@@ -225,7 +225,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry)
* actually 15 bytes.
*/
if (strlen(filename) <= 15) {
- strncpy(&buff[AR_name_offset],
+ memcpy(&buff[AR_name_offset],
filename, strlen(filename));
buff[AR_name_offset + strlen(filename)] = '/';
} else {
@@ -248,7 +248,7 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry)
return (ARCHIVE_FATAL);
}
- strncpy(se, filename, strlen(filename));
+ memcpy(se, filename, strlen(filename));
strcpy(se + strlen(filename), "/\n");
ss = strstr(ar->strtab, se);
@@ -285,11 +285,11 @@ archive_write_ar_header(struct archive_write *a, struct archive_entry *entry)
* archive header.
*/
if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) {
- strncpy(&buff[AR_name_offset], filename, strlen(filename));
+ memcpy(&buff[AR_name_offset], filename, strlen(filename));
buff[AR_name_offset + strlen(filename)] = ' ';
}
else {
- strncpy(buff + AR_name_offset, "#1/", 3);
+ memcpy(buff + AR_name_offset, "#1/", 3);
if (format_decimal(strlen(filename),
buff + AR_name_offset + 3,
AR_name_size - 3)) {
@@ -374,13 +374,14 @@ archive_write_ar_data(struct archive_write *a, const void *buff, size_t s)
return (ARCHIVE_WARN);
}
- ar->strtab = (char *)malloc(s);
+ ar->strtab = (char *)malloc(s + 1);
if (ar->strtab == NULL) {
archive_set_error(&a->archive, ENOMEM,
"Can't allocate strtab buffer");
return (ARCHIVE_FATAL);
}
- strncpy(ar->strtab, buff, s);
+ memcpy(ar->strtab, buff, s);
+ ar->strtab[s] = '\0';
ar->has_strtab = 1;
}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
index a2ce7c6cd..86e8621ef 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c
@@ -41,7 +41,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 20116
#include "archive_private.h"
/* A table that maps names to functions. */
-static
+static const
struct { const char *name; int (*setter)(struct archive *); } names[] =
{
{ "7zip", archive_write_set_format_7zip },
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c
index adec9b265..9fe21e454 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_filter_by_ext.c
@@ -42,7 +42,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 20116
#include "archive_private.h"
/* A table that maps names to functions. */
-static
+static const
struct { const char *name; int (*format)(struct archive *); int (*filter)(struct archive *); } names[] =
{
{ ".7z", archive_write_set_format_7zip, archive_write_add_filter_none},
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c
index 6a301ac2d..3cebeae18 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c
@@ -1196,8 +1196,12 @@ archive_write_pax_header(struct archive_write *a,
"GNU.sparse.major", 1);
add_pax_attr_int(&(pax->pax_header),
"GNU.sparse.minor", 0);
+ /*
+ * Make sure to store the original path, since
+ * truncation to ustar limit happened already.
+ */
add_pax_attr(&(pax->pax_header),
- "GNU.sparse.name", entry_name.s);
+ "GNU.sparse.name", path);
add_pax_attr_int(&(pax->pax_header),
"GNU.sparse.realsize",
archive_entry_size(entry_main));
@@ -1650,13 +1654,14 @@ build_pax_attribute_name(char *dest, const char *src)
* GNU PAX Format 1.0 requires the special name, which pattern is:
* <dir>/GNUSparseFile.<pid>/<original file name>
*
+ * Since reproducible archives are more important, use 0 as pid.
+ *
* 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. */
@@ -1682,15 +1687,9 @@ build_gnu_sparse_name(char *dest, const char *src)
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);
+ build_ustar_entry_name(dest, src, p - src, "GNUSparseFile.0");
return (dest);
}
diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c
index 8b6daf942..edad072cf 100644
--- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c
+++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_warc.c
@@ -354,7 +354,7 @@ static ssize_t
_popul_ehdr(struct archive_string *tgt, size_t tsz, warc_essential_hdr_t hdr)
{
static const char _ver[] = "WARC/1.0\r\n";
- static const char *_typ[LAST_WT] = {
+ static const char * const _typ[LAST_WT] = {
NULL, "warcinfo", "metadata", "resource", NULL
};
char std_uuid[48U];
diff --git a/Utilities/cmlibarchive/libarchive/config_freebsd.h b/Utilities/cmlibarchive/libarchive/config_freebsd.h
index 215e886be..be25258f9 100644
--- a/Utilities/cmlibarchive/libarchive/config_freebsd.h
+++ b/Utilities/cmlibarchive/libarchive/config_freebsd.h
@@ -22,141 +22,238 @@
* (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$
*/
-/* FreeBSD 5.0 and later have ACL and extattr support. */
+#include <osreldate.h>
+
+/* FreeBSD 5.0 and later has ACL and extattr support. */
#if __FreeBSD__ > 4
-#define HAVE_ACL_CREATE_ENTRY 1
-#define HAVE_ACL_GET_FD_NP 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_STRUCT_XVFSCONF 1
-#define HAVE_SYS_ACL_H 1
-#define HAVE_SYS_EXTATTR_H 1
-#endif
+#define ARCHIVE_ACL_FREEBSD 1
+#define HAVE_ACL_GET_PERM_NP 1
+#define HAVE_ARC4RANDOM_BUF 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_STRUCT_XVFSCONF 1
+#define HAVE_SYS_ACL_H 1
+#define HAVE_SYS_EXTATTR_H 1
+#if __FreeBSD__ > 7
+/* FreeBSD 8.0 and later has NFSv4 ACL support */
+#define ARCHIVE_ACL_FREEBSD_NFS4 1
+#define HAVE_ACL_GET_LINK_NP 1
+#define HAVE_ACL_IS_TRIVIAL_NP 1
+#define HAVE_ACL_SET_LINK_NP 1
+#endif /* __FreeBSD__ > 7 */
+#endif /* __FreeBSD__ > 4 */
#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
+#define HAVE_LIBCRYPTO 1
+#define HAVE_OPENSSL_EVP_H 1
+#define HAVE_OPENSSL_MD5_H 1
+#define HAVE_OPENSSL_RIPEMD_H 1
+#define HAVE_OPENSSL_SHA_H 1
+#define HAVE_OPENSSL_SHA256_INIT 1
+#define HAVE_OPENSSL_SHA384_INIT 1
+#define HAVE_OPENSSL_SHA512_INIT 1
+#define HAVE_PKCS5_PBKDF2_HMAC_SHA1 1
+#define HAVE_SHA256 1
+#define HAVE_SHA384 1
+#define HAVE_SHA512 1
+#else
+#define HAVE_LIBMD 1
+#define HAVE_MD5_H 1
+#define HAVE_MD5INIT 1
+#define HAVE_RIPEMD_H 1
+#define HAVE_SHA_H 1
+#define HAVE_SHA1 1
+#define HAVE_SHA1_INIT 1
+#define HAVE_SHA256 1
+#define HAVE_SHA256_H 1
+#define HAVE_SHA256_INIT 1
+#define HAVE_SHA512 1
+#define HAVE_SHA512_H 1
+#define HAVE_SHA512_INIT 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
+#define HAVE_BSDXML_H 1
+#define HAVE_BZLIB_H 1
+#define HAVE_CHFLAGS 1
+#define HAVE_CHOWN 1
+#define HAVE_CHROOT 1
+#define HAVE_CTIME_R 1
+#define HAVE_CTYPE_H 1
+#define HAVE_DECL_EXTATTR_NAMESPACE_USER 1
+#define HAVE_DECL_INT32_MAX 1
+#define HAVE_DECL_INT32_MIN 1
+#define HAVE_DECL_INT64_MAX 1
+#define HAVE_DECL_INT64_MIN 1
+#define HAVE_DECL_INTMAX_MAX 1
+#define HAVE_DECL_INTMAX_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_DECL_UINTMAX_MAX 1
+#define HAVE_DIRENT_H 1
+#define HAVE_DLFCN_H 1
+#define HAVE_D_MD_ORDER 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_FDOPENDIR 1
+#define HAVE_FORK 1
+#define HAVE_FSEEKO 1
+#define HAVE_FSTAT 1
+#define HAVE_FSTATAT 1
+#define HAVE_FSTATFS 1
+#define HAVE_FSTATVFS 1
+#define HAVE_FTRUNCATE 1
+#define HAVE_FUTIMES 1
+#define HAVE_FUTIMESAT 1
+#define HAVE_GETEUID 1
+#define HAVE_GETGRGID_R 1
+#define HAVE_GETGRNAM_R 1
+#define HAVE_GETPID 1
+#define HAVE_GETPWNAM_R 1
+#define HAVE_GETPWUID_R 1
+#define HAVE_GETVFSBYNAME 1
+#define HAVE_GMTIME_R 1
+#define HAVE_GRP_H 1
+#define HAVE_INTMAX_T 1
+#define HAVE_INTTYPES_H 1
+#define HAVE_LANGINFO_H 1
+#define HAVE_LCHFLAGS 1
+#define HAVE_LCHMOD 1
+#define HAVE_LCHOWN 1
+#define HAVE_LIBZ 1
+#define HAVE_LIMITS_H 1
+#define HAVE_LINK 1
+#define HAVE_LOCALE_H 1
+#define HAVE_LOCALTIME_R 1
+#define HAVE_LONG_LONG_INT 1
+#define HAVE_LSTAT 1
+#define HAVE_LUTIMES 1
+#define HAVE_MBRTOWC 1
+#define HAVE_MEMMOVE 1
+#define HAVE_MEMORY_H 1
+#define HAVE_MEMSET 1
+#define HAVE_MKDIR 1
+#define HAVE_MKFIFO 1
+#define HAVE_MKNOD 1
+#define HAVE_MKSTEMP 1
+#define HAVE_NL_LANGINFO 1
+#define HAVE_OPENAT 1
+#define HAVE_PATHS_H 1
+#define HAVE_PIPE 1
+#define HAVE_POLL 1
+#define HAVE_POLL_H 1
+#define HAVE_POSIX_SPAWNP 1
+#define HAVE_PTHREAD_H 1
+#define HAVE_PWD_H 1
+#define HAVE_READDIR_R 1
+#define HAVE_READLINK 1
+#define HAVE_READLINKAT 1
+#define HAVE_READPASSPHRASE 1
+#define HAVE_READPASSPHRASE_H 1
+#define HAVE_REGEX_H 1
+#define HAVE_SELECT 1
+#define HAVE_SETENV 1
+#define HAVE_SETLOCALE 1
+#define HAVE_SIGACTION 1
+#define HAVE_SIGNAL_H 1
+#define HAVE_SPAWN_H 1
+#define HAVE_STATFS 1
+#define HAVE_STATVFS 1
+#define HAVE_STDARG_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_STRFTIME 1
+#define HAVE_STRINGS_H 1
+#define HAVE_STRING_H 1
+#define HAVE_STRRCHR 1
+#define HAVE_STRUCT_STATFS_F_NAMEMAX 1
+#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1
+#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1
+#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
+#define HAVE_STRUCT_STAT_ST_FLAGS 1
+#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1
+#define HAVE_STRUCT_STAT_ST_MTIM_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_POLL_H 1
+#define HAVE_SYS_SELECT_H 1
+#define HAVE_SYS_STATVFS_H 1
+#define HAVE_SYS_STAT_H 1
+#define HAVE_SYS_TIME_H 1
+#define HAVE_SYS_TYPES_H 1
+#define HAVE_SYS_UTSNAME_H 1
+#define HAVE_SYS_WAIT_H 1
+#define HAVE_TIMEGM 1
+#define HAVE_TIME_H 1
+#define HAVE_TZSET 1
+#define HAVE_UINTMAX_T 1
+#define HAVE_UNISTD_H 1
+#define HAVE_UNSETENV 1
+#define HAVE_UNSIGNED_LONG_LONG 1
+#define HAVE_UNSIGNED_LONG_LONG_INT 1
+#define HAVE_UTIME 1
+#define HAVE_UTIMES 1
+#define HAVE_UTIME_H 1
+#define HAVE_VFORK 1
+#define HAVE_VPRINTF 1
+#define HAVE_WCHAR_H 1
+#define HAVE_WCHAR_T 1
+#define HAVE_WCRTOMB 1
+#define HAVE_WCSCMP 1
+#define HAVE_WCSCPY 1
+#define HAVE_WCSLEN 1
+#define HAVE_WCTOMB 1
+#define HAVE_WCTYPE_H 1
+#define HAVE_WMEMCMP 1
+#define HAVE_WMEMCPY 1
+#define HAVE_WMEMMOVE 1
+#define HAVE_ZLIB_H 1
+#define TIME_WITH_SYS_TIME 1
+
+#if __FreeBSD_version >= 1100056
+#define HAVE_FUTIMENS 1
+#define HAVE_UTIMENSAT 1
+#endif
/* FreeBSD 4 and earlier lack intmax_t/uintmax_t */
#if __FreeBSD__ < 5
-#define intmax_t int64_t
-#define uintmax_t uint64_t
+#define intmax_t int64_t
+#define uintmax_t uint64_t
+#endif
+
+/* FreeBSD defines for archive_hash.h */
+#ifdef WITH_OPENSSL
+#define ARCHIVE_CRYPTO_MD5_OPENSSL 1
+#define ARCHIVE_CRYPTO_RMD160_OPENSSL 1
+#define ARCHIVE_CRYPTO_SHA1_OPENSSL
+#define ARCHIVE_CRYPTO_SHA256_OPENSSL 1
+#define ARCHIVE_CRYPTO_SHA384_OPENSSL 1
+#define ARCHIVE_CRYPTO_SHA512_OPENSSL 1
+#else
+#define ARCHIVE_CRYPTO_MD5_LIBMD 1
+#define ARCHIVE_CRYPTO_SHA1_LIBMD 1
+#define ARCHIVE_CRYPTO_SHA256_LIBMD 1
+#define ARCHIVE_CRYPTO_SHA512_LIBMD 1
#endif
diff --git a/Utilities/cmlibarchive/libarchive/libarchive_changes.3 b/Utilities/cmlibarchive/libarchive/libarchive_changes.3
index 881a67cdd..adc87febd 100644
--- a/Utilities/cmlibarchive/libarchive/libarchive_changes.3
+++ b/Utilities/cmlibarchive/libarchive/libarchive_changes.3
@@ -28,6 +28,7 @@
.Dt LIBARCHIVE_CHANGES 3
.Os
.Sh NAME
+.Nm libarchive_changes
.Nd changes in libarchive interface
.\"
.Sh CHANGES IN LIBARCHIVE 3
diff --git a/Utilities/cmlibarchive/libarchive/mtree.5 b/Utilities/cmlibarchive/libarchive/mtree.5
index 16c8abec4..e607e4a81 100644
--- a/Utilities/cmlibarchive/libarchive/mtree.5
+++ b/Utilities/cmlibarchive/libarchive/mtree.5
@@ -48,7 +48,7 @@ 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
+encoded as 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
diff --git a/Utilities/cmlibarchive/libarchive/xxhash.c b/Utilities/cmlibarchive/libarchive/xxhash.c
index 6f5ba52fa..70750bae0 100644
--- a/Utilities/cmlibarchive/libarchive/xxhash.c
+++ b/Utilities/cmlibarchive/libarchive/xxhash.c
@@ -141,13 +141,19 @@ typedef struct _U32_S { U32 v; } _PACKED U32_S;
# pragma pack(pop)
#endif
-#define A32(x) (((const U32_S *)(x))->v)
-
/****************************************
** Compiler-specific Functions and Macros
*****************************************/
-#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
+#define GCC_VERSION ((__GNUC__-0) * 100 + (__GNUC_MINOR__ - 0))
+
+#if GCC_VERSION >= 409
+__attribute__((__no_sanitize_undefined__))
+#endif
+static inline U32 A32(const void * x)
+{
+ return (((const U32_S *)(x))->v);
+}
/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
#if defined(_MSC_VER)
diff --git a/Utilities/cmliblzma/CMakeLists.txt b/Utilities/cmliblzma/CMakeLists.txt
index bb3b8a71f..b443fd6bc 100644
--- a/Utilities/cmliblzma/CMakeLists.txt
+++ b/Utilities/cmliblzma/CMakeLists.txt
@@ -6,22 +6,6 @@ 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(
- "static inline int test (void) {return 0;}\nint main (void) {return test();}"
- HAVE_INLINE)
-
-CHECK_C_SOURCE_COMPILES (
- "static __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)
@@ -95,7 +79,7 @@ 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("size_t" SIZE_OF_SIZE_T)
+CHECK_TYPE_SIZE("size_t" SIZEOF_SIZE_T)
CHECK_TYPE_SIZE("__int64" __INT64)
CHECK_TYPE_SIZE("unsigned __int64" UNSIGNED___INT64)
@@ -199,7 +183,7 @@ INCLUDE_DIRECTORIES(
# Disable warnings to avoid changing 3rd party code.
IF(CMAKE_C_COMPILER_ID MATCHES
- "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
diff --git a/Utilities/cmliblzma/COPYING b/Utilities/cmliblzma/COPYING
index 43c90d059..20e60d5b2 100644
--- a/Utilities/cmliblzma/COPYING
+++ b/Utilities/cmliblzma/COPYING
@@ -47,7 +47,7 @@ XZ Utils Licensing
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/>.
+ This software includes code from XZ Utils <https://tukaani.org/xz/>.
The following license texts are included in the following files:
- COPYING.LGPLv2.1: GNU Lesser General Public License version 2.1
diff --git a/Utilities/cmliblzma/common/common_w32res.rc b/Utilities/cmliblzma/common/common_w32res.rc
index fdb88d184..a70de3432 100644
--- a/Utilities/cmliblzma/common/common_w32res.rc
+++ b/Utilities/cmliblzma/common/common_w32res.rc
@@ -17,7 +17,7 @@
#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_COMPANY "The Tukaani Project <https://tukaani.org/>"
#define MY_PRODUCT PACKAGE_NAME " <" PACKAGE_URL ">"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
diff --git a/Utilities/cmliblzma/common/sysdefs.h b/Utilities/cmliblzma/common/sysdefs.h
index a6edea8b0..22f487b9e 100644
--- a/Utilities/cmliblzma/common/sysdefs.h
+++ b/Utilities/cmliblzma/common/sysdefs.h
@@ -18,6 +18,7 @@
#if defined(_MSC_VER)
# pragma warning(push,1)
+# pragma warning(disable: 4028) /* formal parameter different from decl */
# pragma warning(disable: 4142) /* benign redefinition of type */
# pragma warning(disable: 4761) /* integral size mismatch in argument */
#endif
@@ -124,9 +125,9 @@
// The code currently assumes that size_t is either 32-bit or 64-bit.
#ifndef SIZE_MAX
-# if SIZE_OF_SIZE_T == 4
+# if SIZEOF_SIZE_T == 4
# define SIZE_MAX UINT32_MAX
-# elif SIZE_OF_SIZE_T == 8
+# elif SIZEOF_SIZE_T == 8
# define SIZE_MAX UINT64_MAX
# else
# error size_t is not 32-bit or 64-bit
@@ -175,6 +176,16 @@ typedef unsigned char _Bool;
# include <memory.h>
#endif
+// As of MSVC 2013, inline and restrict are supported with
+// non-standard keywords.
+#if defined(_WIN32) && defined(_MSC_VER)
+# ifndef inline
+# define inline __inline
+# endif
+# ifndef restrict
+# define restrict __restrict
+# endif
+#endif
////////////
// Macros //
diff --git a/Utilities/cmliblzma/common/tuklib_integer.h b/Utilities/cmliblzma/common/tuklib_integer.h
index 5e8262a11..5d8268580 100644
--- a/Utilities/cmliblzma/common/tuklib_integer.h
+++ b/Utilities/cmliblzma/common/tuklib_integer.h
@@ -106,6 +106,17 @@
#endif
+////////////////////////////////
+// Compiler-specific features //
+////////////////////////////////
+
+// Newer Intel C compilers require immintrin.h for _bit_scan_reverse()
+// and such functions.
+#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1500)
+# include <immintrin.h>
+#endif
+
+
///////////////////
// Byte swapping //
///////////////////
@@ -329,8 +340,8 @@ unaligned_read32le(const uint8_t *buf)
static inline void
unaligned_write16be(uint8_t *buf, uint16_t num)
{
- buf[0] = num >> 8;
- buf[1] = num;
+ buf[0] = (uint8_t)(num >> 8);
+ buf[1] = (uint8_t)num;
return;
}
@@ -338,8 +349,8 @@ unaligned_write16be(uint8_t *buf, uint16_t num)
static inline void
unaligned_write16le(uint8_t *buf, uint16_t num)
{
- buf[0] = num;
- buf[1] = num >> 8;
+ buf[0] = (uint8_t)num;
+ buf[1] = (uint8_t)(num >> 8);
return;
}
@@ -347,10 +358,10 @@ unaligned_write16le(uint8_t *buf, uint16_t num)
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;
+ buf[0] = (uint8_t)(num >> 24);
+ buf[1] = (uint8_t)(num >> 16);
+ buf[2] = (uint8_t)(num >> 8);
+ buf[3] = (uint8_t)num;
return;
}
@@ -358,10 +369,10 @@ unaligned_write32be(uint8_t *buf, uint32_t num)
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;
+ buf[0] = (uint8_t)num;
+ buf[1] = (uint8_t)(num >> 8);
+ buf[2] = (uint8_t)(num >> 16);
+ buf[3] = (uint8_t)(num >> 24);
return;
}
diff --git a/Utilities/cmliblzma/config.h.in b/Utilities/cmliblzma/config.h.in
index 9c53150bf..06f7fcb37 100644
--- a/Utilities/cmliblzma/config.h.in
+++ b/Utilities/cmliblzma/config.h.in
@@ -29,7 +29,7 @@
@SIZE_OF_UNSIGNED_CODE@
@SIZE_OF_UNSIGNED_LONG_CODE@
@SIZE_OF_UNSIGNED_LONG_LONG_CODE@
-@SIZE_OF_SIZE_T_CODE@
+@SIZEOF_SIZE_T_CODE@
/*
* If we lack int64_t, define it to the first of __int64, int, long, and long long
@@ -180,32 +180,6 @@ typedef uint64_t uintmax_t;
#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
diff --git a/Utilities/cmliblzma/liblzma/api/lzma.h b/Utilities/cmliblzma/liblzma/api/lzma.h
index fb874c3e1..aa88e4243 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma.h
@@ -82,12 +82,20 @@
# 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.
+ * MSVC versions older than 2013 have no C99 support, and
+ * thus they cannot be used to compile liblzma. Using an
+ * existing liblzma.dll with old MSVC can work though(*),
+ * but we need to define the required standard integer
+ * types here in a MSVC-specific way.
+ *
+ * (*) If you do this, the existing liblzma.dll probably uses
+ * a different runtime library than your MSVC-built
+ * application. Mixing runtimes is generally bad, but
+ * in this case it should work as long as you avoid
+ * the few rarely-needed liblzma functions that allocate
+ * memory and expect the caller to free it using free().
*/
-# if defined(_WIN32) && defined(_MSC_VER)
+# if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800
typedef unsigned __int8 uint8_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
@@ -211,7 +219,11 @@
*/
#ifndef lzma_nothrow
# if defined(__cplusplus)
-# define lzma_nothrow throw()
+# if __cplusplus >= 201103L
+# define lzma_nothrow noexcept
+# else
+# define lzma_nothrow throw()
+# endif
# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
# define lzma_nothrow __attribute__((__nothrow__))
# else
@@ -286,7 +298,7 @@ extern "C" {
#include "lzma/filter.h"
#include "lzma/bcj.h"
#include "lzma/delta.h"
-#include "lzma/lzma.h"
+#include "lzma/lzma12.h"
/* Container formats */
#include "lzma/container.h"
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/base.h b/Utilities/cmliblzma/liblzma/api/lzma/base.h
index 43dde8d60..a6005accc 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/base.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/base.h
@@ -240,12 +240,12 @@ typedef enum {
/**
* \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.
+ * After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, LZMA_FULL_BARRIER,
+ * 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,
@@ -293,7 +293,7 @@ typedef enum {
*
* 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
+ * 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.
*
@@ -302,6 +302,29 @@ typedef enum {
* no unfinished Block, no empty Block is created.
*/
+ LZMA_FULL_BARRIER = 4,
+ /**<
+ * \brief Finish encoding of the current Block
+ *
+ * This is like LZMA_FULL_FLUSH except that this doesn't
+ * necessarily wait until all the input has been made
+ * available via the output buffer. That is, lzma_code()
+ * might return LZMA_STREAM_END as soon as all the input
+ * has been consumed (avail_in == 0).
+ *
+ * LZMA_FULL_BARRIER is useful with a threaded encoder if
+ * one wants to split the .xz Stream into Blocks at specific
+ * offsets but doesn't care if the output isn't flushed
+ * immediately. Using LZMA_FULL_BARRIER allows keeping
+ * the threads busy while LZMA_FULL_FLUSH would make
+ * lzma_code() wait until all the threads have finished
+ * until more data could be passed to the encoder.
+ *
+ * With a lzma_stream initialized with the single-threaded
+ * lzma_stream_encoder() or lzma_easy_encoder(),
+ * LZMA_FULL_BARRIER is an alias for LZMA_FULL_FLUSH.
+ */
+
LZMA_FINISH = 3
/**<
* \brief Finish the coding operation
@@ -332,11 +355,19 @@ typedef enum {
* 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).
+ * Single-threaded mode only: 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).
+ *
+ * Multithreaded mode: liblzma might internally store pointers to the
+ * lzma_allocator given via the lzma_stream structure. The application
+ * must not change the allocator pointer in lzma_stream or the contents
+ * of the pointed lzma_allocator structure until lzma_end() has been used
+ * to free the memory associated with that lzma_stream. The allocation
+ * functions might be called simultaneously from multiple threads, and
+ * thus they must be thread safe.
*/
typedef struct {
/**
@@ -448,7 +479,8 @@ typedef struct lzma_internal_s lzma_internal;
*
* 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.
+ * written but aren't used for anything else except as a possible return
+ * values from lzma_get_progress().
*/
typedef struct {
const uint8_t *next_in; /**< Pointer to the next input byte. */
@@ -464,8 +496,10 @@ typedef struct {
*
* In most cases this is NULL which makes liblzma use
* the standard malloc() and free().
+ *
+ * \note In 5.0.x this is not a const pointer.
*/
- lzma_allocator *allocator;
+ const lzma_allocator *allocator;
/** Internal state is not visible to applications. */
lzma_internal *internal;
@@ -547,6 +581,25 @@ extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow;
/**
+ * \brief Get progress information
+ *
+ * In single-threaded mode, applications can get progress information from
+ * strm->total_in and strm->total_out. In multi-threaded mode this is less
+ * useful because a significant amount of both input and output data gets
+ * buffered internally by liblzma. This makes total_in and total_out give
+ * misleading information and also makes the progress indicator updates
+ * non-smooth.
+ *
+ * This function gives realistic progress information also in multi-threaded
+ * mode by taking into account the progress made by each thread. In
+ * single-threaded mode *progress_in and *progress_out are set to
+ * strm->total_in and strm->total_out, respectively.
+ */
+extern LZMA_API(void) lzma_get_progress(lzma_stream *strm,
+ uint64_t *progress_in, uint64_t *progress_out) lzma_nothrow;
+
+
+/**
* \brief Get the memory usage of decoder filter chain
*
* This function is currently supported only when *strm has been initialized
@@ -591,11 +644,16 @@ extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
* This function is supported only when *strm has been initialized with
* a function that takes a memlimit argument.
*
+ * liblzma 5.2.3 and earlier has a bug where memlimit value of 0 causes
+ * this function to do nothing (leaving the limit unchanged) and still
+ * return LZMA_OK. Later versions treat 0 as if 1 had been specified (so
+ * lzma_memlimit_get() will return 1 even if you specify 0 here).
+ *
* \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.
+ * support memory usage limit.
*/
extern LZMA_API(lzma_ret) lzma_memlimit_set(
lzma_stream *strm, uint64_t memlimit) lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/block.h b/Utilities/cmliblzma/liblzma/api/lzma/block.h
index e6710a7bc..7bdcfd7cb 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/block.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/block.h
@@ -31,11 +31,16 @@ 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.
+ * To prevent API and ABI breakages when new features are needed,
+ * a version number is used to indicate which fields in this
+ * structure are in use:
+ * - liblzma >= 5.0.0: version = 0 is supported.
+ * - liblzma >= 5.1.4beta: Support for version = 1 was added,
+ * which adds the ignore_check field.
+ *
+ * If version is greater than one, most Block related functions
+ * will return LZMA_OPTIONS_ERROR (lzma_block_header_decode() works
+ * with any version value).
*
* Read by:
* - All functions that take pointer to lzma_block as argument,
@@ -233,7 +238,28 @@ typedef struct {
lzma_reserved_enum reserved_enum2;
lzma_reserved_enum reserved_enum3;
lzma_reserved_enum reserved_enum4;
- lzma_bool reserved_bool1;
+
+ /**
+ * \brief A flag to Block decoder to not verify the Check field
+ *
+ * This field is supported by liblzma >= 5.1.4beta if .version >= 1.
+ *
+ * If this is set to true, the integrity check won't be calculated
+ * and verified. Unless you know what you are doing, you should
+ * leave this to false. (A reason to set this to true is when the
+ * file integrity is verified externally anyway and you want to
+ * speed up the decompression, which matters mostly when using
+ * SHA-256 as the integrity check.)
+ *
+ * If .version >= 1, read by:
+ * - lzma_block_decoder()
+ * - lzma_block_buffer_decode()
+ *
+ * Written by (.version is ignored):
+ * - lzma_block_header_decode() always sets this to false
+ */
+ lzma_bool ignore_check;
+
lzma_bool reserved_bool2;
lzma_bool reserved_bool3;
lzma_bool reserved_bool4;
@@ -310,10 +336,14 @@ extern LZMA_API(lzma_ret) lzma_block_header_encode(
/**
* \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.
+ * block->version should (usually) be set to the highest value supported
+ * by the application. If the application sets block->version to a value
+ * higher than supported by the current liblzma version, this function will
+ * downgrade block->version to the highest value supported by it. Thus one
+ * should check the value of block->version after calling this function if
+ * block->version was set to a non-zero value and the application doesn't
+ * otherwise know that the liblzma version being used is new enough to
+ * support the specified block->version.
*
* The size of the Block Header must have already been decoded with
* lzma_block_header_size_decode() macro and stored to block->header_size.
@@ -344,7 +374,7 @@ extern LZMA_API(lzma_ret) lzma_block_header_encode(
* 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)
+ const lzma_allocator *allocator, const uint8_t *in)
lzma_nothrow lzma_attr_warn_unused_result;
@@ -493,7 +523,25 @@ extern LZMA_API(size_t) lzma_block_buffer_bound(size_t uncompressed_size)
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_block_buffer_encode(
- lzma_block *block, lzma_allocator *allocator,
+ lzma_block *block, const 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 uncompressed .xz Block encoder
+ *
+ * This is like lzma_block_buffer_encode() except this doesn't try to
+ * compress the data and instead encodes the data using LZMA2 uncompressed
+ * chunks. The required output buffer size can be determined with
+ * lzma_block_buffer_bound().
+ *
+ * Since the data won't be compressed, this function ignores block->filters.
+ * This function doesn't take lzma_allocator because this function doesn't
+ * allocate any memory from the heap.
+ */
+extern LZMA_API(lzma_ret) lzma_block_uncomp_encode(lzma_block *block,
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;
@@ -527,7 +575,7 @@ extern LZMA_API(lzma_ret) lzma_block_buffer_encode(
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_block_buffer_decode(
- lzma_block *block, lzma_allocator *allocator,
+ lzma_block *block, const 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/container.h b/Utilities/cmliblzma/liblzma/api/lzma/container.h
index 7a9ffc645..9fbf4df06 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/container.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/container.h
@@ -61,6 +61,131 @@
/**
+ * \brief Multithreading options
+ */
+typedef struct {
+ /**
+ * \brief Flags
+ *
+ * Set this to zero if no flags are wanted.
+ *
+ * No flags are currently supported.
+ */
+ uint32_t flags;
+
+ /**
+ * \brief Number of worker threads to use
+ */
+ uint32_t threads;
+
+ /**
+ * \brief Maximum uncompressed size of a Block
+ *
+ * The encoder will start a new .xz Block every block_size bytes.
+ * Using LZMA_FULL_FLUSH or LZMA_FULL_BARRIER with lzma_code()
+ * the caller may tell liblzma to start a new Block earlier.
+ *
+ * With LZMA2, a recommended block size is 2-4 times the LZMA2
+ * dictionary size. With very small dictionaries, it is recommended
+ * to use at least 1 MiB block size for good compression ratio, even
+ * if this is more than four times the dictionary size. Note that
+ * these are only recommendations for typical use cases; feel free
+ * to use other values. Just keep in mind that using a block size
+ * less than the LZMA2 dictionary size is waste of RAM.
+ *
+ * Set this to 0 to let liblzma choose the block size depending
+ * on the compression options. For LZMA2 it will be 3*dict_size
+ * or 1 MiB, whichever is more.
+ *
+ * For each thread, about 3 * block_size bytes of memory will be
+ * allocated. This may change in later liblzma versions. If so,
+ * the memory usage will probably be reduced, not increased.
+ */
+ uint64_t block_size;
+
+ /**
+ * \brief Timeout to allow lzma_code() to return early
+ *
+ * Multithreading can make liblzma to consume input and produce
+ * output in a very bursty way: it may first read a lot of input
+ * to fill internal buffers, then no input or output occurs for
+ * a while.
+ *
+ * In single-threaded mode, lzma_code() won't return until it has
+ * either consumed all the input or filled the output buffer. If
+ * this is done in multithreaded mode, it may cause a call
+ * lzma_code() to take even tens of seconds, which isn't acceptable
+ * in all applications.
+ *
+ * To avoid very long blocking times in lzma_code(), a timeout
+ * (in milliseconds) may be set here. If lzma_code() would block
+ * longer than this number of milliseconds, it will return with
+ * LZMA_OK. Reasonable values are 100 ms or more. The xz command
+ * line tool uses 300 ms.
+ *
+ * If long blocking times are fine for you, set timeout to a special
+ * value of 0, which will disable the timeout mechanism and will make
+ * lzma_code() block until all the input is consumed or the output
+ * buffer has been filled.
+ *
+ * \note Even with a timeout, lzma_code() might sometimes take
+ * somewhat long time to return. No timing guarantees
+ * are made.
+ */
+ uint32_t timeout;
+
+ /**
+ * \brief Compression preset (level and possible flags)
+ *
+ * The preset is set just like with lzma_easy_encoder().
+ * The preset is ignored if filters below is non-NULL.
+ */
+ uint32_t preset;
+
+ /**
+ * \brief Filter chain (alternative to a preset)
+ *
+ * If this is NULL, the preset above is used. Otherwise the preset
+ * is ignored and the filter chain specified here is used.
+ */
+ const lzma_filter *filters;
+
+ /**
+ * \brief Integrity check type
+ *
+ * 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 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. These are and will never be used
+ * with the currently supported options, so it is safe to leave these
+ * uninitialized.
+ */
+ lzma_reserved_enum reserved_enum1;
+ lzma_reserved_enum reserved_enum2;
+ lzma_reserved_enum reserved_enum3;
+ uint32_t reserved_int1;
+ uint32_t reserved_int2;
+ uint32_t reserved_int3;
+ uint32_t reserved_int4;
+ uint64_t reserved_int5;
+ uint64_t reserved_int6;
+ uint64_t reserved_int7;
+ uint64_t reserved_int8;
+ void *reserved_ptr1;
+ void *reserved_ptr2;
+ void *reserved_ptr3;
+ void *reserved_ptr4;
+
+} lzma_mt;
+
+
+/**
* \brief Calculate approximate memory usage of easy encoder
*
* This function is a wrapper for lzma_raw_encoder_memusage().
@@ -165,7 +290,8 @@ extern LZMA_API(lzma_ret) lzma_easy_encoder(
*/
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,
+ const lzma_allocator *allocator,
+ const uint8_t *in, size_t in_size,
uint8_t *out, size_t *out_pos, size_t out_size) lzma_nothrow;
@@ -191,6 +317,49 @@ extern LZMA_API(lzma_ret) lzma_stream_encoder(lzma_stream *strm,
/**
+ * \brief Calculate approximate memory usage of multithreaded .xz encoder
+ *
+ * Since doing the encoding in threaded mode doesn't affect the memory
+ * requirements of single-threaded decompressor, you can use
+ * lzma_easy_decoder_memusage(options->preset) or
+ * lzma_raw_decoder_memusage(options->filters) to calculate
+ * the decompressor memory requirements.
+ *
+ * \param options Compression options
+ *
+ * \return Number of bytes of memory required for encoding with the
+ * given options. If an error occurs, for example due to
+ * unsupported preset or filter chain, UINT64_MAX is returned.
+ */
+extern LZMA_API(uint64_t) lzma_stream_encoder_mt_memusage(
+ const lzma_mt *options) lzma_nothrow lzma_attr_pure;
+
+
+/**
+ * \brief Initialize multithreaded .xz Stream encoder
+ *
+ * This provides the functionality of lzma_easy_encoder() and
+ * lzma_stream_encoder() as a single function for multithreaded use.
+ *
+ * The supported actions for lzma_code() are LZMA_RUN, LZMA_FULL_FLUSH,
+ * LZMA_FULL_BARRIER, and LZMA_FINISH. Support for LZMA_SYNC_FLUSH might be
+ * added in the future.
+ *
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param options Pointer to multithreaded compression options
+ *
+ * \return - LZMA_OK
+ * - LZMA_MEM_ERROR
+ * - LZMA_UNSUPPORTED_CHECK
+ * - LZMA_OPTIONS_ERROR
+ * - LZMA_PROG_ERROR
+ */
+extern LZMA_API(lzma_ret) lzma_stream_encoder_mt(
+ lzma_stream *strm, const lzma_mt *options)
+ 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
@@ -269,7 +438,8 @@ extern LZMA_API(size_t) lzma_stream_buffer_bound(size_t uncompressed_size)
*/
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,
+ const 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;
@@ -305,6 +475,30 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
/**
+ * This flag makes lzma_code() not calculate and verify the integrity check
+ * of the compressed data in .xz files. This means that invalid integrity
+ * check values won't be detected and LZMA_DATA_ERROR won't be returned in
+ * such cases.
+ *
+ * This flag only affects the checks of the compressed data itself; the CRC32
+ * values in the .xz headers will still be verified normally.
+ *
+ * Don't use this flag unless you know what you are doing. Possible reasons
+ * to use this flag:
+ *
+ * - Trying to recover data from a corrupt .xz file.
+ *
+ * - Speeding up decompression, which matters mostly with SHA-256
+ * or with files that have compressed extremely well. It's recommended
+ * to not use this flag for this purpose unless the file integrity is
+ * verified externally in some other way.
+ *
+ * Support for this flag was added in liblzma 5.1.4beta.
+ */
+#define LZMA_IGNORE_CHECK UINT32_C(0x10)
+
+
+/**
* 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.
@@ -326,7 +520,10 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
*
* \param strm Pointer to properly prepared lzma_stream
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
- * to effectively disable the limiter.
+ * to effectively disable the limiter. liblzma
+ * 5.2.3 and earlier don't allow 0 here and return
+ * LZMA_PROG_ERROR; later versions treat 0 as if 1
+ * had been specified.
* \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
@@ -350,7 +547,10 @@ extern LZMA_API(lzma_ret) lzma_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.
+ * to effectively disable the limiter. liblzma
+ * 5.2.3 and earlier don't allow 0 here and return
+ * LZMA_PROG_ERROR; later versions treat 0 as if 1
+ * had been specified.
* \param flags Bitwise-or of flags, or zero for no flags.
*
* \return - LZMA_OK: Initialization was successful.
@@ -366,9 +566,16 @@ extern LZMA_API(lzma_ret) lzma_auto_decoder(
/**
* \brief Initialize .lzma decoder (legacy file format)
*
+ * \param strm Pointer to properly prepared lzma_stream
+ * \param memlimit Memory usage limit as bytes. Use UINT64_MAX
+ * to effectively disable the limiter. liblzma
+ * 5.2.3 and earlier don't allow 0 here and return
+ * LZMA_PROG_ERROR; later versions treat 0 as if 1
+ * had been specified.
+ *
* 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.
+ * There is no need to use LZMA_FINISH, but it's allowed because it may
+ * simplify certain types of applications.
*
* \return - LZMA_OK
* - LZMA_MEM_ERROR
@@ -418,7 +625,8 @@ extern LZMA_API(lzma_ret) lzma_alone_decoder(
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_stream_buffer_decode(
- uint64_t *memlimit, uint32_t flags, lzma_allocator *allocator,
+ uint64_t *memlimit, uint32_t flags,
+ const 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/filter.h b/Utilities/cmliblzma/liblzma/api/lzma/filter.h
index e0bc163ad..4e78752b8 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/filter.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/filter.h
@@ -116,8 +116,9 @@ extern LZMA_API(lzma_bool) lzma_filter_decoder_is_supported(lzma_vli id)
* 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;
+extern LZMA_API(lzma_ret) lzma_filters_copy(
+ const lzma_filter *src, lzma_filter *dest,
+ const lzma_allocator *allocator) lzma_nothrow;
/**
@@ -256,7 +257,7 @@ extern LZMA_API(lzma_ret) lzma_filters_update(
* won't necessarily meet that bound.)
*/
extern LZMA_API(lzma_ret) lzma_raw_buffer_encode(
- const lzma_filter *filters, lzma_allocator *allocator,
+ const lzma_filter *filters, const lzma_allocator *allocator,
const uint8_t *in, size_t in_size, uint8_t *out,
size_t *out_pos, size_t out_size) lzma_nothrow;
@@ -280,7 +281,7 @@ extern LZMA_API(lzma_ret) lzma_raw_buffer_encode(
* 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 lzma_filter *filters, const 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;
@@ -356,7 +357,7 @@ extern LZMA_API(lzma_ret) lzma_properties_encode(
* - LZMA_MEM_ERROR
*/
extern LZMA_API(lzma_ret) lzma_properties_decode(
- lzma_filter *filter, lzma_allocator *allocator,
+ lzma_filter *filter, const lzma_allocator *allocator,
const uint8_t *props, size_t props_size) lzma_nothrow;
@@ -419,6 +420,6 @@ extern LZMA_API(lzma_ret) lzma_filter_flags_encode(const lzma_filter *filter,
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_filter_flags_decode(
- lzma_filter *filter, lzma_allocator *allocator,
+ lzma_filter *filter, const 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
index e7dd03c3e..5321d9af8 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/hardware.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/hardware.h
@@ -48,3 +48,17 @@
* of RAM on the specific operating system.
*/
extern LZMA_API(uint64_t) lzma_physmem(void) lzma_nothrow;
+
+
+/**
+ * \brief Get the number of processor cores or threads
+ *
+ * This function may be useful when determining how many threads to use.
+ * If the hardware supports more than one thread per CPU core, the number
+ * of hardware threads is returned if that information is available.
+ *
+ * \brief On success, the number of available CPU threads or cores is
+ * returned. If this information isn't available or an error
+ * occurs, zero is returned.
+ */
+extern LZMA_API(uint32_t) lzma_cputhreads(void) lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/index.h b/Utilities/cmliblzma/liblzma/api/lzma/index.h
index 16bacc287..3dac6fb85 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/index.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/index.h
@@ -303,7 +303,7 @@ extern LZMA_API(uint64_t) lzma_index_memused(const lzma_index *i)
* \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)
+extern LZMA_API(lzma_index *) lzma_index_init(const lzma_allocator *allocator)
lzma_nothrow;
@@ -312,8 +312,8 @@ extern LZMA_API(lzma_index *) lzma_index_init(lzma_allocator *allocator)
*
* If i is NULL, this does nothing.
*/
-extern LZMA_API(void) lzma_index_end(lzma_index *i, lzma_allocator *allocator)
- lzma_nothrow;
+extern LZMA_API(void) lzma_index_end(
+ lzma_index *i, const lzma_allocator *allocator) lzma_nothrow;
/**
@@ -341,7 +341,7 @@ extern LZMA_API(void) lzma_index_end(lzma_index *i, lzma_allocator *allocator)
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_index_append(
- lzma_index *i, lzma_allocator *allocator,
+ lzma_index *i, const lzma_allocator *allocator,
lzma_vli unpadded_size, lzma_vli uncompressed_size)
lzma_nothrow lzma_attr_warn_unused_result;
@@ -564,8 +564,8 @@ extern LZMA_API(lzma_bool) lzma_index_iter_locate(
* - LZMA_MEM_ERROR
* - LZMA_PROG_ERROR
*/
-extern LZMA_API(lzma_ret) lzma_index_cat(
- lzma_index *dest, lzma_index *src, lzma_allocator *allocator)
+extern LZMA_API(lzma_ret) lzma_index_cat(lzma_index *dest, lzma_index *src,
+ const lzma_allocator *allocator)
lzma_nothrow lzma_attr_warn_unused_result;
@@ -575,7 +575,7 @@ extern LZMA_API(lzma_ret) lzma_index_cat(
* \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)
+ const lzma_index *i, const lzma_allocator *allocator)
lzma_nothrow lzma_attr_warn_unused_result;
@@ -586,8 +586,7 @@ extern LZMA_API(lzma_index *) lzma_index_dup(
* \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).
+ * It is enough to use only one of them (you can choose freely).
*
* \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
* - LZMA_MEM_ERROR
@@ -610,16 +609,21 @@ extern LZMA_API(lzma_ret) lzma_index_encoder(
* 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.
+ * allowed to require. liblzma 5.2.3 and earlier
+ * don't allow 0 here and return LZMA_PROG_ERROR;
+ * later versions treat 0 as if 1 had been specified.
*
- * 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).
+ * Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
+ * There is no need to use LZMA_FINISH, but it's allowed because it may
+ * simplify certain types of applications.
*
* \return - LZMA_OK: Initialization succeeded, continue with lzma_code().
* - LZMA_MEM_ERROR
- * - LZMA_MEMLIMIT_ERROR
* - LZMA_PROG_ERROR
+ *
+ * liblzma 5.2.3 and older list also LZMA_MEMLIMIT_ERROR here
+ * but that error code has never been possible from this
+ * initialization function.
*/
extern LZMA_API(lzma_ret) lzma_index_decoder(
lzma_stream *strm, lzma_index **i, uint64_t memlimit)
@@ -677,6 +681,6 @@ extern LZMA_API(lzma_ret) lzma_index_buffer_encode(const lzma_index *i,
* - LZMA_PROG_ERROR
*/
extern LZMA_API(lzma_ret) lzma_index_buffer_decode(lzma_index **i,
- uint64_t *memlimit, lzma_allocator *allocator,
+ uint64_t *memlimit, const 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
index fa2e048d5..9287f1dfd 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/index_hash.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/index_hash.h
@@ -37,7 +37,7 @@ typedef struct lzma_index_hash_s lzma_index_hash;
* 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_index_hash *index_hash, const lzma_allocator *allocator)
lzma_nothrow lzma_attr_warn_unused_result;
@@ -45,7 +45,7 @@ extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
* \brief Deallocate lzma_index_hash structure
*/
extern LZMA_API(void) lzma_index_hash_end(
- lzma_index_hash *index_hash, lzma_allocator *allocator)
+ lzma_index_hash *index_hash, const lzma_allocator *allocator)
lzma_nothrow;
diff --git a/Utilities/cmliblzma/liblzma/api/lzma/version.h b/Utilities/cmliblzma/liblzma/api/lzma/version.h
index 09866b982..143c7dea6 100644
--- a/Utilities/cmliblzma/liblzma/api/lzma/version.h
+++ b/Utilities/cmliblzma/liblzma/api/lzma/version.h
@@ -21,8 +21,8 @@
* Version number split into components
*/
#define LZMA_VERSION_MAJOR 5
-#define LZMA_VERSION_MINOR 0
-#define LZMA_VERSION_PATCH 8
+#define LZMA_VERSION_MINOR 2
+#define LZMA_VERSION_PATCH 4
#define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
#ifndef LZMA_VERSION_COMMIT
diff --git a/Utilities/cmliblzma/liblzma/check/check.c b/Utilities/cmliblzma/liblzma/check/check.c
index 979b0a818..428ddaeb7 100644
--- a/Utilities/cmliblzma/liblzma/check/check.c
+++ b/Utilities/cmliblzma/liblzma/check/check.c
@@ -16,6 +16,9 @@
extern LZMA_API(lzma_bool)
lzma_check_is_supported(lzma_check type)
{
+ if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
+ return false;
+
static const lzma_bool available_checks[LZMA_CHECK_ID_MAX + 1] = {
true, // LZMA_CHECK_NONE
@@ -53,9 +56,6 @@ lzma_check_is_supported(lzma_check type)
false, // Reserved
};
- if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
- return false;
-
return available_checks[(unsigned int)(type)];
}
@@ -63,6 +63,9 @@ lzma_check_is_supported(lzma_check type)
extern LZMA_API(uint32_t)
lzma_check_size(lzma_check type)
{
+ if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
+ return UINT32_MAX;
+
// See file-format.txt section 2.1.1.2.
static const uint8_t check_sizes[LZMA_CHECK_ID_MAX + 1] = {
0,
@@ -73,9 +76,6 @@ lzma_check_size(lzma_check type)
64, 64, 64
};
- if ((unsigned int)(type) > LZMA_CHECK_ID_MAX)
- return UINT32_MAX;
-
return check_sizes[(unsigned int)(type)];
}
diff --git a/Utilities/cmliblzma/liblzma/check/check.h b/Utilities/cmliblzma/liblzma/check/check.h
index e100d2b85..3007d889b 100644
--- a/Utilities/cmliblzma/liblzma/check/check.h
+++ b/Utilities/cmliblzma/liblzma/check/check.h
@@ -15,6 +15,53 @@
#include "common.h"
+// If the function for external SHA-256 is missing, use the internal SHA-256
+// code. Due to how configure works, these defines can only get defined when
+// both a usable header and a type have already been found.
+#if !(defined(HAVE_CC_SHA256_INIT) \
+ || defined(HAVE_SHA256_INIT) \
+ || defined(HAVE_SHA256INIT))
+# define HAVE_INTERNAL_SHA256 1
+#endif
+
+#if defined(HAVE_INTERNAL_SHA256)
+// Nothing
+#elif defined(HAVE_COMMONCRYPTO_COMMONDIGEST_H)
+# include <CommonCrypto/CommonDigest.h>
+#elif defined(HAVE_SHA256_H)
+# include <sys/types.h>
+# include <sha256.h>
+#elif defined(HAVE_SHA2_H)
+# include <sys/types.h>
+# include <sha2.h>
+#endif
+
+#if defined(HAVE_INTERNAL_SHA256)
+/// State for the internal SHA-256 implementation
+typedef struct {
+ /// Internal state
+ uint32_t state[8];
+
+ /// Size of the message excluding padding
+ uint64_t size;
+} lzma_sha256_state;
+#elif defined(HAVE_CC_SHA256_CTX)
+typedef CC_SHA256_CTX lzma_sha256_state;
+#elif defined(HAVE_SHA256_CTX)
+typedef SHA256_CTX lzma_sha256_state;
+#elif defined(HAVE_SHA2_CTX)
+typedef SHA2_CTX lzma_sha256_state;
+#endif
+
+#if defined(HAVE_INTERNAL_SHA256)
+// Nothing
+#elif defined(HAVE_CC_SHA256_INIT)
+# define LZMA_SHA256FUNC(x) CC_SHA256_ ## x
+#elif defined(HAVE_SHA256_INIT)
+# define LZMA_SHA256FUNC(x) SHA256_ ## x
+#elif defined(HAVE_SHA256INIT)
+# define LZMA_SHA256FUNC(x) SHA256 ## x
+#endif
// Index hashing needs the best possible hash function (preferably
// a cryptographic hash) for maximum reliability.
@@ -43,14 +90,7 @@ typedef struct {
union {
uint32_t crc32;
uint64_t crc64;
-
- struct {
- /// Internal state
- uint32_t state[8];
-
- /// Size of the message excluding padding
- uint64_t size;
- } sha256;
+ lzma_sha256_state sha256;
} state;
} lzma_check_state;
@@ -82,6 +122,8 @@ extern void lzma_check_update(lzma_check_state *check, lzma_check type,
extern void lzma_check_finish(lzma_check_state *check, lzma_check type);
+#ifndef LZMA_SHA256FUNC
+
/// Prepare SHA-256 state for new input.
extern void lzma_sha256_init(lzma_check_state *check);
@@ -92,4 +134,39 @@ extern void lzma_sha256_update(
/// Finish the SHA-256 calculation and store the result to check->buffer.u8.
extern void lzma_sha256_finish(lzma_check_state *check);
+
+#else
+
+static inline void
+lzma_sha256_init(lzma_check_state *check)
+{
+ LZMA_SHA256FUNC(Init)(&check->state.sha256);
+}
+
+
+static inline void
+lzma_sha256_update(const uint8_t *buf, size_t size, lzma_check_state *check)
+{
+#if defined(HAVE_CC_SHA256_INIT) && SIZE_MAX > UINT32_MAX
+ // Darwin's CC_SHA256_Update takes uint32_t as the buffer size,
+ // so use a loop to support size_t.
+ while (size > UINT32_MAX) {
+ LZMA_SHA256FUNC(Update)(&check->state.sha256, buf, UINT32_MAX);
+ buf += UINT32_MAX;
+ size -= UINT32_MAX;
+ }
+#endif
+
+ LZMA_SHA256FUNC(Update)(&check->state.sha256, buf, size);
+}
+
+
+static inline void
+lzma_sha256_finish(lzma_check_state *check)
+{
+ LZMA_SHA256FUNC(Final)(check->buffer.u8, &check->state.sha256);
+}
+
+#endif
+
#endif
diff --git a/Utilities/cmliblzma/liblzma/check/crc32_fast.c b/Utilities/cmliblzma/liblzma/check/crc32_fast.c
index c2c3cb79b..3de02638d 100644
--- a/Utilities/cmliblzma/liblzma/check/crc32_fast.c
+++ b/Utilities/cmliblzma/liblzma/check/crc32_fast.c
@@ -33,8 +33,6 @@ lzma_crc32(const uint8_t *buf, size_t size, uint32_t 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) {
@@ -43,7 +41,7 @@ lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
}
// Calculate the position where to stop.
- limit = buf + (size & ~(size_t)(7));
+ const uint8_t *const limit = buf + (size & ~(size_t)(7));
// Calculate how many bytes must be calculated separately
// before returning the result.
@@ -51,8 +49,6 @@ lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
// Calculate the CRC32 using the slice-by-eight algorithm.
while (buf < limit) {
- uint32_t tmp;
-
crc ^= *(const uint32_t *)(buf);
buf += 4;
@@ -61,7 +57,7 @@ lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
^ lzma_crc32_table[5][C(crc)]
^ lzma_crc32_table[4][D(crc)];
- tmp = *(const uint32_t *)(buf);
+ const uint32_t tmp = *(const uint32_t *)(buf);
buf += 4;
// At least with some compilers, it is critical for
diff --git a/Utilities/cmliblzma/liblzma/check/crc64_fast.c b/Utilities/cmliblzma/liblzma/check/crc64_fast.c
index 1436557af..52af29ed4 100644
--- a/Utilities/cmliblzma/liblzma/check/crc64_fast.c
+++ b/Utilities/cmliblzma/liblzma/check/crc64_fast.c
@@ -36,14 +36,12 @@ lzma_crc64(const uint8_t *buf, size_t size, uint64_t 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));
+ const uint8_t *const limit = buf + (size & ~(size_t)(3));
size &= (size_t)(3);
while (buf < limit) {
diff --git a/Utilities/cmliblzma/liblzma/check/sha256.c b/Utilities/cmliblzma/liblzma/check/sha256.c
index 3af6aa67d..5eede5ce0 100644
--- a/Utilities/cmliblzma/liblzma/check/sha256.c
+++ b/Utilities/cmliblzma/liblzma/check/sha256.c
@@ -21,22 +21,22 @@
//
///////////////////////////////////////////////////////////////////////////////
-// 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)))
+// Rotate a uint32_t. GCC can optimize this to a rotate instruction
+// at least on x86.
+static inline uint32_t
+rotr_32(uint32_t num, unsigned amount)
+{
+ return (num >> amount) | (num << (32 - amount));
+}
-#define blk0(i) (W[i] = data[i])
+#define blk0(i) (W[i] = conv32be(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 Maj(x, y, z) ((x & (y ^ z)) + (y & z))
#define a(i) T[(0 - i) & 7]
#define b(i) T[(1 - i) & 7]
@@ -47,16 +47,17 @@
#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)); \
+#define R(i, j, blk) \
+ h(i) += S1(e(i)) + Ch(e(i), f(i), g(i)) + SHA256_K[i + j] + blk; \
d(i) += h(i); \
h(i) += S0(a(i)) + Maj(a(i), b(i), c(i))
+#define R0(i) R(i, 0, blk0(i))
+#define R2(i) R(i, j, blk2(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))
+#define S0(x) rotr_32(x ^ rotr_32(x ^ rotr_32(x, 9), 11), 2)
+#define S1(x) rotr_32(x ^ rotr_32(x ^ rotr_32(x, 14), 5), 6)
+#define s0(x) (rotr_32(x ^ rotr_32(x, 11), 7) ^ (x >> 3))
+#define s1(x) (rotr_32(x ^ rotr_32(x, 2), 17) ^ (x >> 10))
static const uint32_t SHA256_K[64] = {
@@ -84,17 +85,22 @@ transform(uint32_t state[8], const uint32_t data[16])
{
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);
+ // The first 16 operations unrolled
+ R0( 0); R0( 1); R0( 2); R0( 3);
+ R0( 4); R0( 5); R0( 6); R0( 7);
+ R0( 8); R0( 9); R0(10); R0(11);
+ R0(12); R0(13); R0(14); R0(15);
+
+ // The remaining 48 operations partially unrolled
+ for (unsigned int j = 16; j < 64; j += 16) {
+ R2( 0); R2( 1); R2( 2); R2( 3);
+ R2( 4); R2( 5); R2( 6); R2( 7);
+ R2( 8); R2( 9); R2(10); R2(11);
+ R2(12); R2(13); R2(14); R2(15);
}
// Add the working vars back into state[].
@@ -112,19 +118,7 @@ transform(uint32_t state[8], const uint32_t data[16])
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;
}
@@ -174,8 +168,6 @@ lzma_sha256_update(const uint8_t *buf, size_t size, lzma_check_state *check)
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;
@@ -197,7 +189,7 @@ lzma_sha256_finish(lzma_check_state *check)
process(check);
- for (i = 0; i < 8; ++i)
+ for (size_t 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
index 5f5e564ab..77d0a9b10 100644
--- a/Utilities/cmliblzma/liblzma/common/alone_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/alone_decoder.c
@@ -15,7 +15,7 @@
#include "lz_decoder.h"
-struct lzma_coder_s {
+typedef struct {
lzma_next_coder next;
enum {
@@ -46,17 +46,19 @@ struct lzma_coder_s {
/// Options decoded from the header needed to initialize
/// the LZMA decoder
lzma_options_lzma options;
-};
+} lzma_alone_coder;
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,
+alone_decode(void *coder_ptr,
+ const lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size,
lzma_action action)
{
+ lzma_alone_coder *coder = coder_ptr;
+
while (*out_pos < out_size
&& (coder->sequence == SEQ_CODE || *in_pos < in_size))
switch (coder->sequence) {
@@ -126,17 +128,19 @@ alone_decode(lzma_coder *coder,
// Fall through
case SEQ_CODER_INIT: {
- lzma_ret ret;
+ if (coder->memusage > coder->memlimit)
+ return LZMA_MEMLIMIT_ERROR;
lzma_filter_info filters[2] = {
- { 0, &lzma_lzma_decoder_init, &coder->options },
- { 0, NULL, NULL }
+ {
+ .init = &lzma_lzma_decoder_init,
+ .options = &coder->options,
+ }, {
+ .init = NULL,
+ }
};
- if (coder->memusage > coder->memlimit)
- return LZMA_MEMLIMIT_ERROR;
-
- ret = lzma_next_filter_init(&coder->next,
+ const lzma_ret ret = lzma_next_filter_init(&coder->next,
allocator, filters);
if (ret != LZMA_OK)
return ret;
@@ -164,8 +168,9 @@ alone_decode(lzma_coder *coder,
static void
-alone_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+alone_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_alone_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@@ -173,9 +178,11 @@ alone_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-alone_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+alone_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
+ lzma_alone_coder *coder = coder_ptr;
+
*memusage = coder->memusage;
*old_memlimit = coder->memlimit;
@@ -191,34 +198,34 @@ alone_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
extern lzma_ret
-lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_alone_decoder_init(lzma_next_coder *next, const 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;
+ lzma_alone_coder *coder = next->coder;
- if (next->coder == NULL) {
- next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
- if (next->coder == NULL)
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_alone_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
next->code = &alone_decode;
next->end = &alone_decoder_end;
next->memconfig = &alone_decoder_memconfig;
- next->coder->next = LZMA_NEXT_CODER_INIT;
+ 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;
+ coder->sequence = SEQ_PROPERTIES;
+ coder->picky = picky;
+ coder->pos = 0;
+ coder->options.dict_size = 0;
+ coder->options.preset_dict = NULL;
+ coder->options.preset_dict_size = 0;
+ coder->uncompressed_size = 0;
+ coder->memlimit = my_max(1, memlimit);
+ coder->memusage = LZMA_MEMUSAGE_BASE;
return LZMA_OK;
}
@@ -227,7 +234,7 @@ lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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);
+ lzma_next_strm_init(lzma_alone_decoder_init, strm, memlimit, false);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/alone_decoder.h b/Utilities/cmliblzma/liblzma/common/alone_decoder.h
index f666fc382..dfa031aa7 100644
--- a/Utilities/cmliblzma/liblzma/common/alone_decoder.h
+++ b/Utilities/cmliblzma/liblzma/common/alone_decoder.h
@@ -17,7 +17,7 @@
extern lzma_ret lzma_alone_decoder_init(
- lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_next_coder *next, const 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
index 4207b4a52..4853cfd1d 100644
--- a/Utilities/cmliblzma/liblzma/common/alone_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/alone_encoder.c
@@ -17,7 +17,7 @@
#define ALONE_HEADER_SIZE (1 + 4 + 8)
-struct lzma_coder_s {
+typedef struct {
lzma_next_coder next;
enum {
@@ -27,17 +27,19 @@ struct lzma_coder_s {
size_t header_pos;
uint8_t header[ALONE_HEADER_SIZE];
-};
+} lzma_alone_coder;
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,
+alone_encode(void *coder_ptr,
+ const lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size,
lzma_action action)
{
+ lzma_alone_coder *coder = coder_ptr;
+
while (*out_pos < out_size)
switch (coder->sequence) {
case SEQ_HEADER:
@@ -65,8 +67,9 @@ alone_encode(lzma_coder *coder,
static void
-alone_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+alone_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_alone_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@@ -75,36 +78,31 @@ alone_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
// 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,
+alone_encoder_init(lzma_next_coder *next, const 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)
+ lzma_alone_coder *coder = next->coder;
+
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_alone_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
next->code = &alone_encode;
next->end = &alone_encoder_end;
- next->coder->next = LZMA_NEXT_CODER_INIT;
+ coder->next = LZMA_NEXT_CODER_INIT;
}
// Basic initializations
- next->coder->sequence = SEQ_HEADER;
- next->coder->header_pos = 0;
+ coder->sequence = SEQ_HEADER;
+ coder->header_pos = 0;
// Encode the header:
// - Properties (1 byte)
- if (lzma_lzma_lclppb_encode(options, next->coder->header))
+ if (lzma_lzma_lclppb_encode(options, coder->header))
return LZMA_OPTIONS_ERROR;
// - Dictionary size (4 bytes)
@@ -115,7 +113,7 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
// 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;
+ uint32_t d = options->dict_size - 1;
d |= d >> 2;
d |= d >> 3;
d |= d >> 4;
@@ -124,18 +122,28 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
if (d != UINT32_MAX)
++d;
- unaligned_write32le(next->coder->header + 1, d);
+ unaligned_write32le(coder->header + 1, d);
// - Uncompressed size (always unknown and using EOPM)
- memset(next->coder->header + 1 + 4, 0xFF, 8);
+ memset(coder->header + 1 + 4, 0xFF, 8);
+
+ // Initialize the LZMA encoder.
+ const lzma_filter_info filters[2] = {
+ {
+ .init = &lzma_lzma_encoder_init,
+ .options = (void *)(options),
+ }, {
+ .init = NULL,
+ }
+ };
- return lzma_next_filter_init(&next->coder->next, allocator, filters);
+ return lzma_next_filter_init(&coder->next, allocator, filters);
}
/*
extern lzma_ret
-lzma_alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_alone_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_options_alone *options)
{
lzma_next_coder_init(&alone_encoder_init, next, allocator, options);
@@ -146,7 +154,7 @@ lzma_alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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);
+ lzma_next_strm_init(alone_encoder_init, strm, options);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/auto_decoder.c b/Utilities/cmliblzma/liblzma/common/auto_decoder.c
index 24cf48905..6895c7ccf 100644
--- a/Utilities/cmliblzma/liblzma/common/auto_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/auto_decoder.c
@@ -14,7 +14,7 @@
#include "alone_decoder.h"
-struct lzma_coder_s {
+typedef struct {
/// Stream decoder or LZMA_Alone decoder
lzma_next_coder next;
@@ -26,15 +26,17 @@ struct lzma_coder_s {
SEQ_CODE,
SEQ_FINISH,
} sequence;
-};
+} lzma_auto_coder;
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)
+auto_decode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
+ lzma_auto_coder *coder = coder_ptr;
+
switch (coder->sequence) {
case SEQ_INIT:
if (*in_pos >= in_size)
@@ -100,8 +102,9 @@ auto_decode(lzma_coder *coder, lzma_allocator *allocator,
static void
-auto_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+auto_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_auto_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@@ -109,8 +112,10 @@ auto_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_check
-auto_decoder_get_check(const lzma_coder *coder)
+auto_decoder_get_check(const void *coder_ptr)
{
+ const lzma_auto_coder *coder = coder_ptr;
+
// 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);
@@ -118,9 +123,11 @@ auto_decoder_get_check(const lzma_coder *coder)
static lzma_ret
-auto_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+auto_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
+ lzma_auto_coder *coder = coder_ptr;
+
lzma_ret ret;
if (coder->next.memconfig != NULL) {
@@ -132,7 +139,10 @@ auto_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
// the current memory usage.
*memusage = LZMA_MEMUSAGE_BASE;
*old_memlimit = coder->memlimit;
+
ret = LZMA_OK;
+ if (new_memlimit != 0 && new_memlimit < *memusage)
+ ret = LZMA_MEMLIMIT_ERROR;
}
if (ret == LZMA_OK && new_memlimit != 0)
@@ -143,32 +153,31 @@ auto_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
static lzma_ret
-auto_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+auto_decoder_init(lzma_next_coder *next, const 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)
+ lzma_auto_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_auto_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
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;
+ coder->next = LZMA_NEXT_CODER_INIT;
}
- next->coder->memlimit = memlimit;
- next->coder->flags = flags;
- next->coder->sequence = SEQ_INIT;
+ coder->memlimit = my_max(1, memlimit);
+ coder->flags = flags;
+ coder->sequence = SEQ_INIT;
return LZMA_OK;
}
@@ -177,7 +186,7 @@ auto_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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);
+ lzma_next_strm_init(auto_decoder_init, strm, memlimit, flags);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
index b4bd388eb..b0ded90dd 100644
--- a/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_buffer_decoder.c
@@ -14,13 +14,10 @@
extern LZMA_API(lzma_ret)
-lzma_block_buffer_decode(lzma_block *block, lzma_allocator *allocator,
+lzma_block_buffer_decode(lzma_block *block, const 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)
@@ -28,8 +25,9 @@ lzma_block_buffer_decode(lzma_block *block, lzma_allocator *allocator,
return LZMA_PROG_ERROR;
// Initialize the Block decoder.
- block_decoder = LZMA_NEXT_CODER_INIT;
- ret = lzma_block_decoder_init(&block_decoder, allocator, block);
+ lzma_next_coder block_decoder = LZMA_NEXT_CODER_INIT;
+ lzma_ret ret = lzma_block_decoder_init(
+ &block_decoder, allocator, block);
if (ret == LZMA_OK) {
// Save the positions so that we can restore them in case
diff --git a/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
index 136f7f573..39e263aa4 100644
--- a/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_buffer_encoder.c
@@ -10,6 +10,7 @@
//
///////////////////////////////////////////////////////////////////////////////
+#include "block_buffer_encoder.h"
#include "block_encoder.h"
#include "filter_encoder.h"
#include "lzma2_encoder.h"
@@ -28,11 +29,9 @@
+ LZMA_CHECK_SIZE_MAX + 3) & ~3)
-static lzma_vli
-lzma2_bound(lzma_vli uncompressed_size)
+static uint64_t
+lzma2_bound(uint64_t uncompressed_size)
{
- lzma_vli overhead;
-
// Prevent integer overflow in overhead calculation.
if (uncompressed_size > COMPRESSED_SIZE_MAX)
return 0;
@@ -41,7 +40,7 @@ lzma2_bound(lzma_vli uncompressed_size)
// 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)
+ const uint64_t overhead = ((uncompressed_size + LZMA2_CHUNK_MAX - 1)
/ LZMA2_CHUNK_MAX)
* LZMA2_HEADER_UNCOMPRESSED + 1;
@@ -53,30 +52,36 @@ lzma2_bound(lzma_vli uncompressed_size)
}
-extern LZMA_API(size_t)
-lzma_block_buffer_bound(size_t uncompressed_size)
+extern uint64_t
+lzma_block_buffer_bound64(uint64_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 the data doesn't compress, we always use uncompressed
+ // LZMA2 chunks.
+ uint64_t 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);
+ lzma2_size = (lzma2_size + 3) & ~UINT64_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
+ // No risk of integer overflow because lzma2_bound() already takes
// into account the size of the headers in the Block.
- if (SIZE_MAX - HEADERS_BOUND < lzma2_size)
+ return HEADERS_BOUND + lzma2_size;
+}
+
+
+extern LZMA_API(size_t)
+lzma_block_buffer_bound(size_t uncompressed_size)
+{
+ uint64_t ret = lzma_block_buffer_bound64(uncompressed_size);
+
+#if SIZE_MAX < UINT64_MAX
+ // Catch the possible integer overflow on 32-bit systems.
+ if (ret > SIZE_MAX)
return 0;
#endif
- return HEADERS_BOUND + lzma2_size;
+ return ret;
}
@@ -84,17 +89,12 @@ 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_options_lzma lzma2 = {
+ .dict_size = LZMA_DICT_SIZE_MIN,
+ };
lzma_filter filters[2];
filters[0].id = LZMA_FILTER_LZMA2;
@@ -103,7 +103,7 @@ block_encode_uncompressed(lzma_block *block, const uint8_t *in, size_t in_size,
// Set the above filter options to *block temporarily so that we can
// encode the Block Header.
- filters_orig = block->filters;
+ lzma_filter *filters_orig = block->filters;
block->filters = filters;
if (lzma_block_header_size(block) != LZMA_OK) {
@@ -132,17 +132,18 @@ block_encode_uncompressed(lzma_block *block, const uint8_t *in, size_t in_size,
*out_pos += block->header_size;
// Encode the data using LZMA2 uncompressed chunks.
+ size_t in_pos = 0;
+ uint8_t control = 0x01; // Dictionary reset
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);
+ const size_t 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;
@@ -163,27 +164,18 @@ block_encode_uncompressed(lzma_block *block, const uint8_t *in, size_t in_size,
static lzma_ret
-block_encode_normal(lzma_block *block, lzma_allocator *allocator,
+block_encode_normal(lzma_block *block, const 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;
+ const size_t out_start = *out_pos;
*out_pos += block->header_size;
// Limit out_size so that we stop encoding if the output would grow
@@ -193,7 +185,8 @@ block_encode_normal(lzma_block *block, lzma_allocator *allocator,
// TODO: In many common cases this could be optimized to use
// significantly less memory.
- ret = lzma_raw_encoder_init(
+ lzma_next_coder raw_encoder = LZMA_NEXT_CODER_INIT;
+ lzma_ret ret = lzma_raw_encoder_init(
&raw_encoder, allocator, block->filters);
if (ret == LZMA_OK) {
@@ -227,15 +220,12 @@ block_encode_normal(lzma_block *block, lzma_allocator *allocator,
}
-extern LZMA_API(lzma_ret)
-lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
+static lzma_ret
+block_buffer_encode(lzma_block *block, const lzma_allocator *allocator,
const uint8_t *in, size_t in_size,
- uint8_t *out, size_t *out_pos, size_t out_size)
+ uint8_t *out, size_t *out_pos, size_t out_size,
+ bool try_to_compress)
{
- 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)
@@ -243,11 +233,11 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
// The contents of the structure may depend on the version so
// check the version before validating the contents of *block.
- if (block->version != 0)
+ if (block->version > 1)
return LZMA_OPTIONS_ERROR;
if ((unsigned int)(block->check) > LZMA_CHECK_ID_MAX
- || block->filters == NULL)
+ || (try_to_compress && block->filters == NULL))
return LZMA_PROG_ERROR;
if (!lzma_check_is_supported(block->check))
@@ -259,7 +249,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
out_size -= (out_size - *out_pos) & 3;
// Get the size of the Check field.
- check_size = lzma_check_size(block->check);
+ const size_t check_size = lzma_check_size(block->check);
assert(check_size != UINT32_MAX);
// Reserve space for the Check field.
@@ -268,9 +258,19 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
out_size -= check_size;
+ // Initialize block->uncompressed_size and calculate the worst-case
+ // value for block->compressed_size.
+ block->uncompressed_size = in_size;
+ block->compressed_size = lzma2_bound(in_size);
+ if (block->compressed_size == 0)
+ return LZMA_DATA_ERROR;
+
// Do the actual compression.
- ret = block_encode_normal(block, allocator,
- in, in_size, out, out_pos, out_size);
+ lzma_ret ret = LZMA_BUF_ERROR;
+ if (try_to_compress)
+ 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.
@@ -291,7 +291,7 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
// 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) {
+ for (size_t i = (size_t)(block->compressed_size); i & 3; ++i) {
assert(*out_pos < out_size);
out[(*out_pos)++] = 0x00;
}
@@ -313,3 +313,25 @@ lzma_block_buffer_encode(lzma_block *block, lzma_allocator *allocator,
return LZMA_OK;
}
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_buffer_encode(lzma_block *block, const lzma_allocator *allocator,
+ const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ return block_buffer_encode(block, allocator,
+ in, in_size, out, out_pos, out_size, true);
+}
+
+
+extern LZMA_API(lzma_ret)
+lzma_block_uncomp_encode(lzma_block *block,
+ const uint8_t *in, size_t in_size,
+ uint8_t *out, size_t *out_pos, size_t out_size)
+{
+ // It won't allocate any memory from heap so no need
+ // for lzma_allocator.
+ return block_buffer_encode(block, NULL,
+ in, in_size, out, out_pos, out_size, false);
+}
diff --git a/Utilities/cmliblzma/liblzma/common/block_decoder.c b/Utilities/cmliblzma/liblzma/common/block_decoder.c
index 35996e7cf..075bd279f 100644
--- a/Utilities/cmliblzma/liblzma/common/block_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_decoder.c
@@ -15,7 +15,7 @@
#include "check.h"
-struct lzma_coder_s {
+typedef struct {
enum {
SEQ_CODE,
SEQ_PADDING,
@@ -45,7 +45,10 @@ struct lzma_coder_s {
/// Check of the uncompressed data
lzma_check_state check;
-};
+
+ /// True if the integrity check won't be calculated and verified.
+ bool ignore_check;
+} lzma_block_coder;
static inline bool
@@ -71,11 +74,13 @@ is_size_valid(lzma_vli size, lzma_vli reference)
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)
+block_decode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
+ lzma_block_coder *coder = coder_ptr;
+
switch (coder->sequence) {
case SEQ_CODE: {
const size_t in_start = *in_pos;
@@ -97,8 +102,9 @@ block_decode(lzma_coder *coder, lzma_allocator *allocator,
coder->block->uncompressed_size))
return LZMA_DATA_ERROR;
- lzma_check_update(&coder->check, coder->block->check,
- out + out_start, out_used);
+ if (!coder->ignore_check)
+ lzma_check_update(&coder->check, coder->block->check,
+ out + out_start, out_used);
if (ret != LZMA_STREAM_END)
return ret;
@@ -140,7 +146,9 @@ block_decode(lzma_coder *coder, lzma_allocator *allocator,
if (coder->block->check == LZMA_CHECK_NONE)
return LZMA_STREAM_END;
- lzma_check_finish(&coder->check, coder->block->check);
+ if (!coder->ignore_check)
+ lzma_check_finish(&coder->check, coder->block->check);
+
coder->sequence = SEQ_CHECK;
// Fall through
@@ -155,7 +163,8 @@ block_decode(lzma_coder *coder, lzma_allocator *allocator,
// 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)
+ if (!coder->ignore_check
+ && lzma_check_is_supported(coder->block->check)
&& memcmp(coder->block->raw_check,
coder->check.buffer.u8,
check_size) != 0)
@@ -170,8 +179,9 @@ block_decode(lzma_coder *coder, lzma_allocator *allocator,
static void
-block_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+block_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_block_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@@ -179,7 +189,7 @@ block_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
extern lzma_ret
-lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_block_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
lzma_block *block)
{
lzma_next_coder_init(&lzma_block_decoder_init, next, allocator);
@@ -191,27 +201,29 @@ lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
|| !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)
+ // Allocate *next->coder if needed.
+ lzma_block_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_block_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
next->code = &block_decode;
next->end = &block_decoder_end;
- next->coder->next = LZMA_NEXT_CODER_INIT;
+ 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;
+ coder->sequence = SEQ_CODE;
+ coder->block = block;
+ coder->compressed_size = 0;
+ 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
+ coder->compressed_limit
= block->compressed_size == LZMA_VLI_UNKNOWN
? (LZMA_VLI_MAX & ~LZMA_VLI_C(3))
- block->header_size
@@ -221,11 +233,14 @@ lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
// 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);
+ coder->check_pos = 0;
+ lzma_check_init(&coder->check, block->check);
+
+ coder->ignore_check = block->version >= 1
+ ? block->ignore_check : false;
// Initialize the filter chain.
- return lzma_raw_decoder_init(&next->coder->next, allocator,
+ return lzma_raw_decoder_init(&coder->next, allocator,
block->filters);
}
@@ -233,7 +248,7 @@ lzma_block_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern LZMA_API(lzma_ret)
lzma_block_decoder(lzma_stream *strm, lzma_block *block)
{
- lzma_next_strm_init1(lzma_block_decoder_init, strm, block);
+ lzma_next_strm_init(lzma_block_decoder_init, strm, block);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/block_decoder.h b/Utilities/cmliblzma/liblzma/common/block_decoder.h
index 7da9df63f..718c5ced8 100644
--- a/Utilities/cmliblzma/liblzma/common/block_decoder.h
+++ b/Utilities/cmliblzma/liblzma/common/block_decoder.h
@@ -17,6 +17,6 @@
extern lzma_ret lzma_block_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, lzma_block *block);
+ const 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
index ed748273e..168846ad6 100644
--- a/Utilities/cmliblzma/liblzma/common/block_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_encoder.c
@@ -15,7 +15,7 @@
#include "check.h"
-struct lzma_coder_s {
+typedef struct {
/// The filters in the chain; initialized with lzma_raw_decoder_init().
lzma_next_coder next;
@@ -41,15 +41,17 @@ struct lzma_coder_s {
/// Check of the uncompressed data
lzma_check_state check;
-};
+} lzma_block_coder;
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)
+block_encode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
+ lzma_block_coder *coder = coder_ptr;
+
// 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;
@@ -134,8 +136,9 @@ block_encode(lzma_coder *coder, lzma_allocator *allocator,
static void
-block_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+block_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_block_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@@ -143,10 +146,12 @@ block_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-block_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+block_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
+ lzma_block_coder *coder = coder_ptr;
+
if (coder->sequence != SEQ_CODE)
return LZMA_PROG_ERROR;
@@ -156,7 +161,7 @@ block_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
extern lzma_ret
-lzma_block_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_block_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
lzma_block *block)
{
lzma_next_coder_init(&lzma_block_encoder_init, next, allocator);
@@ -166,7 +171,7 @@ lzma_block_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
// The contents of the structure may depend on the version so
// check the version first.
- if (block->version != 0)
+ if (block->version > 1)
return LZMA_OPTIONS_ERROR;
// If the Check ID is not supported, we cannot calculate the check and
@@ -178,37 +183,38 @@ lzma_block_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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)
+ lzma_block_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_block_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
next->code = &block_encode;
next->end = &block_encoder_end;
next->update = &block_encoder_update;
- next->coder->next = LZMA_NEXT_CODER_INIT;
+ 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;
+ coder->sequence = SEQ_CODE;
+ coder->block = block;
+ coder->compressed_size = 0;
+ coder->uncompressed_size = 0;
+ coder->pos = 0;
// Initialize the check
- lzma_check_init(&next->coder->check, block->check);
+ lzma_check_init(&coder->check, block->check);
// Initialize the requested filters.
- return lzma_raw_encoder_init(&next->coder->next, allocator,
- block->filters);
+ return lzma_raw_encoder_init(&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);
+ lzma_next_strm_init(lzma_block_encoder_init, strm, block);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/block_encoder.h b/Utilities/cmliblzma/liblzma/common/block_encoder.h
index b9eff0be2..bd97c186e 100644
--- a/Utilities/cmliblzma/liblzma/common/block_encoder.h
+++ b/Utilities/cmliblzma/liblzma/common/block_encoder.h
@@ -42,6 +42,6 @@
extern lzma_ret lzma_block_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, lzma_block *block);
+ const 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
index f6e470e69..1dd982f6b 100644
--- a/Utilities/cmliblzma/liblzma/common/block_header_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_header_decoder.c
@@ -15,14 +15,12 @@
static void
-free_properties(lzma_block *block, lzma_allocator *allocator)
+free_properties(lzma_block *block, const 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) {
+ for (size_t 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;
@@ -34,15 +32,8 @@ free_properties(lzma_block *block, lzma_allocator *allocator)
extern LZMA_API(lzma_ret)
lzma_block_header_decode(lzma_block *block,
- lzma_allocator *allocator, const uint8_t *in)
+ const 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
@@ -50,13 +41,21 @@ lzma_block_header_decode(lzma_block *block,
// 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) {
+ for (size_t 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;
+ // Versions 0 and 1 are supported. If a newer version was specified,
+ // we need to downgrade it.
+ if (block->version > 1)
+ block->version = 1;
+
+ // This isn't a Block Header option, but since the decompressor will
+ // read it if version >= 1, it's better to initialize it here than
+ // to expect the caller to do it since in almost all cases this
+ // should be false.
+ block->ignore_check = false;
// Validate Block Header Size and Check type. The caller must have
// already set these, so it is a programming error if this test fails.
@@ -65,7 +64,7 @@ lzma_block_header_decode(lzma_block *block,
return LZMA_PROG_ERROR;
// Exclude the CRC32 field.
- in_size = block->header_size - 4;
+ const size_t in_size = block->header_size - 4;
// Verify CRC32
if (lzma_crc32(in, in_size, 0) != unaligned_read32le(in + in_size))
@@ -75,6 +74,9 @@ lzma_block_header_decode(lzma_block *block,
if (in[1] & 0x3C)
return LZMA_OPTIONS_ERROR;
+ // Start after the Block Header Size and Block Flags fields.
+ size_t in_pos = 2;
+
// Compressed Size
if (in[1] & 0x40) {
return_if_error(lzma_vli_decode(&block->compressed_size,
@@ -96,7 +98,8 @@ lzma_block_header_decode(lzma_block *block,
block->uncompressed_size = LZMA_VLI_UNKNOWN;
// Filter Flags
- for (i = 0; i < filter_count; ++i) {
+ const size_t filter_count = (in[1] & 3) + 1;
+ for (size_t i = 0; i < filter_count; ++i) {
const lzma_ret ret = lzma_filter_flags_decode(
&block->filters[i], allocator,
in, &in_pos, in_size);
diff --git a/Utilities/cmliblzma/liblzma/common/block_header_encoder.c b/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
index 650295c00..5c5f5424a 100644
--- a/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/block_header_encoder.c
@@ -17,14 +17,12 @@
extern LZMA_API(lzma_ret)
lzma_block_header_size(lzma_block *block)
{
- size_t i;
+ if (block->version > 1)
+ return LZMA_OPTIONS_ERROR;
// 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);
@@ -47,13 +45,12 @@ lzma_block_header_size(lzma_block *block)
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;
-
+ for (size_t i = 0; block->filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
// Don't allow too many filters.
if (i == LZMA_FILTERS_MAX)
return LZMA_PROG_ERROR;
+ uint32_t add;
return_if_error(lzma_filter_flags_size(&add,
block->filters + i));
@@ -76,23 +73,20 @@ lzma_block_header_size(lzma_block *block)
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;
+ const size_t 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;
+ size_t out_pos = 2;
// Compressed Size
if (block->compressed_size != LZMA_VLI_UNKNOWN) {
@@ -114,6 +108,7 @@ lzma_block_header_encode(const lzma_block *block, uint8_t *out)
if (block->filters == NULL || block->filters[0].id == LZMA_VLI_UNKNOWN)
return LZMA_PROG_ERROR;
+ size_t filter_count = 0;
do {
// There can be a maximum of four filters.
if (filter_count == LZMA_FILTERS_MAX)
diff --git a/Utilities/cmliblzma/liblzma/common/block_util.c b/Utilities/cmliblzma/liblzma/common/block_util.c
index 4cd34d100..00c7fe8d5 100644
--- a/Utilities/cmliblzma/liblzma/common/block_util.c
+++ b/Utilities/cmliblzma/liblzma/common/block_util.c
@@ -17,14 +17,11 @@
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
+ const uint32_t container_size = block->header_size
+ lzma_check_size(block->check);
// Validate that Compressed Size will be greater than zero.
@@ -34,7 +31,7 @@ lzma_block_compressed_size(lzma_block *block, lzma_vli unpadded_size)
// 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;
+ const lzma_vli compressed_size = unpadded_size - container_size;
if (block->compressed_size != LZMA_VLI_UNKNOWN
&& block->compressed_size != compressed_size)
return LZMA_DATA_ERROR;
@@ -48,15 +45,13 @@ lzma_block_compressed_size(lzma_block *block, lzma_vli unpadded_size)
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
+ if (block == NULL || block->version > 1
|| block->header_size < LZMA_BLOCK_HEADER_SIZE_MIN
|| block->header_size > LZMA_BLOCK_HEADER_SIZE_MAX
|| (block->header_size & 3)
@@ -71,7 +66,7 @@ lzma_block_unpadded_size(const lzma_block *block)
return LZMA_VLI_UNKNOWN;
// Calculate Unpadded Size and validate it.
- unpadded_size = block->compressed_size
+ const lzma_vli unpadded_size = block->compressed_size
+ block->header_size
+ lzma_check_size(block->check);
diff --git a/Utilities/cmliblzma/liblzma/common/common.c b/Utilities/cmliblzma/liblzma/common/common.c
index 2e723c8fe..57e3f8ebd 100644
--- a/Utilities/cmliblzma/liblzma/common/common.c
+++ b/Utilities/cmliblzma/liblzma/common/common.c
@@ -36,14 +36,14 @@ lzma_version_string(void)
///////////////////////
extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
-lzma_alloc(size_t size, lzma_allocator *allocator)
+lzma_alloc(size_t size, const lzma_allocator *allocator)
{
- void *ptr;
-
// Some malloc() variants return NULL if called with size == 0.
if (size == 0)
size = 1;
+ void *ptr;
+
if (allocator != NULL && allocator->alloc != NULL)
ptr = allocator->alloc(allocator->opaque, 1, size);
else
@@ -53,8 +53,29 @@ lzma_alloc(size_t size, lzma_allocator *allocator)
}
+extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+lzma_alloc_zero(size_t size, const lzma_allocator *allocator)
+{
+ // Some calloc() variants return NULL if called with size == 0.
+ if (size == 0)
+ size = 1;
+
+ void *ptr;
+
+ if (allocator != NULL && allocator->alloc != NULL) {
+ ptr = allocator->alloc(allocator->opaque, 1, size);
+ if (ptr != NULL)
+ memzero(ptr, size);
+ } else {
+ ptr = calloc(1, size);
+ }
+
+ return ptr;
+}
+
+
extern void
-lzma_free(void *ptr, lzma_allocator *allocator)
+lzma_free(void *ptr, const lzma_allocator *allocator)
{
if (allocator != NULL && allocator->free != NULL)
allocator->free(allocator->opaque, ptr);
@@ -70,9 +91,9 @@ lzma_free(void *ptr, lzma_allocator *allocator)
//////////
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)
+lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *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;
@@ -88,7 +109,7 @@ lzma_bufcpy(const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
extern lzma_ret
-lzma_next_filter_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_next_filter_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
lzma_next_coder_init(filters[0].init, next, allocator);
@@ -99,7 +120,7 @@ lzma_next_filter_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
-lzma_next_filter_update(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_next_filter_update(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter *reversed_filters)
{
// Check that the application isn't trying to change the Filter ID.
@@ -117,7 +138,7 @@ lzma_next_filter_update(lzma_next_coder *next, lzma_allocator *allocator,
extern void
-lzma_next_end(lzma_next_coder *next, lzma_allocator *allocator)
+lzma_next_end(lzma_next_coder *next, const lzma_allocator *allocator)
{
if (next->init != (uintptr_t)(NULL)) {
// To avoid tiny end functions that simply call
@@ -156,10 +177,8 @@ lzma_strm_init(lzma_stream *strm)
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;
+ memzero(strm->internal->supported_actions,
+ sizeof(strm->internal->supported_actions));
strm->internal->sequence = ISEQ_RUN;
strm->internal->allow_buf_error = false;
@@ -173,16 +192,12 @@ lzma_strm_init(lzma_stream *strm)
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
+ || (unsigned int)(action) > LZMA_ACTION_MAX
|| !strm->internal->supported_actions[action])
return LZMA_PROG_ERROR;
@@ -217,6 +232,10 @@ lzma_code(lzma_stream *strm, lzma_action action)
case LZMA_FINISH:
strm->internal->sequence = ISEQ_FINISH;
break;
+
+ case LZMA_FULL_BARRIER:
+ strm->internal->sequence = ISEQ_FULL_BARRIER;
+ break;
}
break;
@@ -244,6 +263,13 @@ lzma_code(lzma_stream *strm, lzma_action action)
break;
+ case ISEQ_FULL_BARRIER:
+ if (action != LZMA_FULL_BARRIER
+ || strm->internal->avail_in != strm->avail_in)
+ return LZMA_PROG_ERROR;
+
+ break;
+
case ISEQ_END:
return LZMA_STREAM_END;
@@ -252,7 +278,9 @@ lzma_code(lzma_stream *strm, lzma_action action)
return LZMA_PROG_ERROR;
}
- ret = strm->internal->next.code(
+ size_t in_pos = 0;
+ size_t out_pos = 0;
+ lzma_ret 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);
@@ -267,7 +295,9 @@ lzma_code(lzma_stream *strm, lzma_action action)
strm->internal->avail_in = strm->avail_in;
- switch (ret) {
+ // Cast is needed to silence a warning about LZMA_TIMED_OUT, which
+ // isn't part of lzma_ret enumeration.
+ switch ((unsigned int)(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
@@ -283,9 +313,16 @@ lzma_code(lzma_stream *strm, lzma_action action)
}
break;
+ case LZMA_TIMED_OUT:
+ strm->internal->allow_buf_error = false;
+ ret = LZMA_OK;
+ break;
+
case LZMA_STREAM_END:
if (strm->internal->sequence == ISEQ_SYNC_FLUSH
- || strm->internal->sequence == ISEQ_FULL_FLUSH)
+ || strm->internal->sequence == ISEQ_FULL_FLUSH
+ || strm->internal->sequence
+ == ISEQ_FULL_BARRIER)
strm->internal->sequence = ISEQ_RUN;
else
strm->internal->sequence = ISEQ_END;
@@ -325,6 +362,22 @@ lzma_end(lzma_stream *strm)
}
+extern LZMA_API(void)
+lzma_get_progress(lzma_stream *strm,
+ uint64_t *progress_in, uint64_t *progress_out)
+{
+ if (strm->internal->next.get_progress != NULL) {
+ strm->internal->next.get_progress(strm->internal->next.coder,
+ progress_in, progress_out);
+ } else {
+ *progress_in = strm->total_in;
+ *progress_out = strm->total_out;
+ }
+
+ return;
+}
+
+
extern LZMA_API(lzma_check)
lzma_get_check(const lzma_stream *strm)
{
@@ -382,8 +435,10 @@ lzma_memlimit_set(lzma_stream *strm, uint64_t new_memlimit)
|| strm->internal->next.memconfig == NULL)
return LZMA_PROG_ERROR;
- if (new_memlimit != 0 && new_memlimit < LZMA_MEMUSAGE_BASE)
- return LZMA_MEMLIMIT_ERROR;
+ // Zero is a special value that cannot be used as an actual limit.
+ // If 0 was specified, use 1 instead.
+ if (new_memlimit == 0)
+ new_memlimit = 1;
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
index a6a28189e..dde3ae0ec 100644
--- a/Utilities/cmliblzma/liblzma/common/common.h
+++ b/Utilities/cmliblzma/liblzma/common/common.h
@@ -48,6 +48,13 @@
#define LZMA_BUFFER_SIZE 4096
+/// Maximum number of worker threads within one multithreaded component.
+/// The limit exists solely to make it simpler to prevent integer overflows
+/// when allocating structures etc. This should be big enough for now...
+/// the code won't scale anywhere close to this number anyway.
+#define LZMA_THREADS_MAX 16384
+
+
/// 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
@@ -65,12 +72,20 @@
( LZMA_TELL_NO_CHECK \
| LZMA_TELL_UNSUPPORTED_CHECK \
| LZMA_TELL_ANY_CHECK \
+ | LZMA_IGNORE_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;
+/// Largest valid lzma_action value as unsigned integer.
+#define LZMA_ACTION_MAX ((unsigned int)(LZMA_FULL_BARRIER))
+
+
+/// Special return value (lzma_ret) to indicate that a timeout was reached
+/// and lzma_code() must not return LZMA_BUF_ERROR. This is converted to
+/// LZMA_OK in lzma_code(). This is not in the lzma_ret enumeration because
+/// there's no need to have it in the public API.
+#define LZMA_TIMED_OUT 32
+
typedef struct lzma_next_coder_s lzma_next_coder;
@@ -79,7 +94,7 @@ 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,
+ lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters);
/// Type of a function to do some kind of coding work (filters, Stream,
@@ -87,15 +102,15 @@ typedef lzma_ret (*lzma_init_function)(
/// 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,
+ void *coder, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *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);
+ void *coder, const lzma_allocator *allocator);
/// Raw coder validates and converts an array of lzma_filter structures to
@@ -118,7 +133,7 @@ struct lzma_filter_info_s {
/// 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;
+ void *coder;
/// Filter ID. This is LZMA_VLI_UNKNOWN when this structure doesn't
/// point to a filter coder.
@@ -138,35 +153,41 @@ struct lzma_next_coder_s {
/// lzma_next_coder.coder.
lzma_end_function end;
+ /// Pointer to a function to get progress information. If this is NULL,
+ /// lzma_stream.total_in and .total_out are used instead.
+ void (*get_progress)(void *coder,
+ uint64_t *progress_in, uint64_t *progress_out);
+
/// 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);
+ lzma_check (*get_check)(const void *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,
+ lzma_ret (*memconfig)(void *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,
+ lzma_ret (*update)(void *coder, const 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,
- };
+/// Macro to initialize lzma_next_coder structure
+#define LZMA_NEXT_CODER_INIT \
+ (lzma_next_coder){ \
+ .coder = NULL, \
+ .init = (uintptr_t)(NULL), \
+ .id = LZMA_VLI_UNKNOWN, \
+ .code = NULL, \
+ .end = NULL, \
+ .get_progress = NULL, \
+ .get_check = NULL, \
+ .memconfig = NULL, \
+ .update = NULL, \
+ }
/// Internal data for lzma_strm_init, lzma_code, and lzma_end. A pointer to
@@ -184,6 +205,7 @@ struct lzma_internal_s {
ISEQ_SYNC_FLUSH,
ISEQ_FULL_FLUSH,
ISEQ_FINISH,
+ ISEQ_FULL_BARRIER,
ISEQ_END,
ISEQ_ERROR,
} sequence;
@@ -194,7 +216,7 @@ struct lzma_internal_s {
size_t avail_in;
/// Indicates which lzma_action values are allowed by next.code.
- bool supported_actions[4];
+ bool supported_actions[LZMA_ACTION_MAX + 1];
/// If true, lzma_code will return LZMA_BUF_ERROR if no progress was
/// made (no input consumed and no output produced by next.code).
@@ -203,15 +225,21 @@ struct lzma_internal_s {
/// Allocates memory
-extern void *lzma_alloc(size_t size, lzma_allocator *allocator)
+extern void *lzma_alloc(size_t size, const lzma_allocator *allocator)
lzma_attribute((__malloc__)) lzma_attr_alloc_size(1);
+/// Allocates memory and zeroes it (like calloc()). This can be faster
+/// than lzma_alloc() + memzero() while being backward compatible with
+/// custom allocators.
+extern void * lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
+ lzma_alloc_zero(size_t size, const lzma_allocator *allocator);
+
/// Frees memory
-extern void lzma_free(void *ptr, lzma_allocator *allocator);
+extern void lzma_free(void *ptr, const 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.
+/// strm->internal. This function is only called via lzma_next_strm_init macro.
extern lzma_ret lzma_strm_init(lzma_stream *strm);
/// Initializes the next filter in the chain, if any. This takes care of
@@ -219,24 +247,26 @@ extern lzma_ret lzma_strm_init(lzma_stream *strm);
/// 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);
+ const 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,
+ lzma_next_coder *next, const 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);
+extern void lzma_next_end(lzma_next_coder *next,
+ const 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);
+extern size_t lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size);
/// \brief Return if expression doesn't evaluate to LZMA_OK
@@ -269,37 +299,15 @@ do { \
/// (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) \
+#define lzma_next_strm_init(func, strm, ...) \
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_; \
- } \
+ return_if_error(lzma_strm_init(strm)); \
+ const lzma_ret ret_ = func(&(strm)->internal->next, \
+ (strm)->allocator, __VA_ARGS__); \
+ 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
index c4be34ccf..48eb56f5c 100644
--- a/Utilities/cmliblzma/liblzma/common/easy_buffer_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/easy_buffer_encoder.c
@@ -15,8 +15,8 @@
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)
+ const 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))
diff --git a/Utilities/cmliblzma/liblzma/common/easy_encoder.c b/Utilities/cmliblzma/liblzma/common/easy_encoder.c
index d13ccd735..5cb492dd0 100644
--- a/Utilities/cmliblzma/liblzma/common/easy_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/easy_encoder.c
@@ -11,7 +11,6 @@
///////////////////////////////////////////////////////////////////////////////
#include "easy_preset.h"
-#include "stream_encoder.h"
extern LZMA_API(lzma_ret)
diff --git a/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
index 65665c17d..6620986ee 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_buffer_decoder.c
@@ -14,30 +14,27 @@
extern LZMA_API(lzma_ret)
-lzma_raw_buffer_decode(const lzma_filter *filters, lzma_allocator *allocator,
+lzma_raw_buffer_decode(
+ const lzma_filter *filters, const 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.
+ lzma_next_coder next = LZMA_NEXT_CODER_INIT;
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;
+ const size_t in_start = *in_pos;
+ const size_t out_start = *out_pos;
// Do the actual decoding and free decoder's memory.
- ret = next.code(next.coder, allocator, in, in_pos, in_size,
+ lzma_ret ret = next.code(next.coder, allocator, in, in_pos, in_size,
out, out_pos, out_size, LZMA_FINISH);
if (ret == LZMA_STREAM_END) {
diff --git a/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
index b23329f3e..dda18e3d8 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_buffer_encoder.c
@@ -14,29 +14,27 @@
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_raw_buffer_encode(
+ const lzma_filter *filters, const 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
+ lzma_next_coder next = LZMA_NEXT_CODER_INIT;
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;
+ const size_t out_start = *out_pos;
// Do the actual encoding and free coder's memory.
- ret = next.code(next.coder, allocator, in, &in_pos, in_size,
+ size_t in_pos = 0;
+ lzma_ret ret = next.code(next.coder, allocator, in, &in_pos, in_size,
out, out_pos, out_size, LZMA_FINISH);
lzma_next_end(&next, allocator);
diff --git a/Utilities/cmliblzma/liblzma/common/filter_common.c b/Utilities/cmliblzma/liblzma/common/filter_common.c
index d2b9e086e..9ad5d5d8e 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_common.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_common.c
@@ -36,101 +36,100 @@ static const struct {
} features[] = {
#if defined (HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1)
{
- LZMA_FILTER_LZMA1,
- sizeof(lzma_options_lzma),
- false,
- true,
- true,
+ .id = LZMA_FILTER_LZMA1,
+ .options_size = sizeof(lzma_options_lzma),
+ .non_last_ok = false,
+ .last_ok = true,
+ .changes_size = true,
},
#endif
#if defined(HAVE_ENCODER_LZMA2) || defined(HAVE_DECODER_LZMA2)
{
- LZMA_FILTER_LZMA2,
- sizeof(lzma_options_lzma),
- false,
- true,
- true,
+ .id = LZMA_FILTER_LZMA2,
+ .options_size = sizeof(lzma_options_lzma),
+ .non_last_ok = false,
+ .last_ok = true,
+ .changes_size = true,
},
#endif
#if defined(HAVE_ENCODER_X86) || defined(HAVE_DECODER_X86)
{
- LZMA_FILTER_X86,
- sizeof(lzma_options_bcj),
- true,
- false,
- false,
+ .id = LZMA_FILTER_X86,
+ .options_size = sizeof(lzma_options_bcj),
+ .non_last_ok = true,
+ .last_ok = false,
+ .changes_size = false,
},
#endif
#if defined(HAVE_ENCODER_POWERPC) || defined(HAVE_DECODER_POWERPC)
{
- LZMA_FILTER_POWERPC,
- sizeof(lzma_options_bcj),
- true,
- false,
- false,
+ .id = LZMA_FILTER_POWERPC,
+ .options_size = sizeof(lzma_options_bcj),
+ .non_last_ok = true,
+ .last_ok = false,
+ .changes_size = false,
},
#endif
#if defined(HAVE_ENCODER_IA64) || defined(HAVE_DECODER_IA64)
{
- LZMA_FILTER_IA64,
- sizeof(lzma_options_bcj),
- true,
- false,
- false,
+ .id = LZMA_FILTER_IA64,
+ .options_size = sizeof(lzma_options_bcj),
+ .non_last_ok = true,
+ .last_ok = false,
+ .changes_size = false,
},
#endif
#if defined(HAVE_ENCODER_ARM) || defined(HAVE_DECODER_ARM)
{
- LZMA_FILTER_ARM,
- sizeof(lzma_options_bcj),
- true,
- false,
- false,
+ .id = LZMA_FILTER_ARM,
+ .options_size = sizeof(lzma_options_bcj),
+ .non_last_ok = true,
+ .last_ok = false,
+ .changes_size = false,
},
#endif
#if defined(HAVE_ENCODER_ARMTHUMB) || defined(HAVE_DECODER_ARMTHUMB)
{
- LZMA_FILTER_ARMTHUMB,
- sizeof(lzma_options_bcj),
- true,
- false,
- false,
+ .id = LZMA_FILTER_ARMTHUMB,
+ .options_size = sizeof(lzma_options_bcj),
+ .non_last_ok = true,
+ .last_ok = false,
+ .changes_size = false,
},
#endif
#if defined(HAVE_ENCODER_SPARC) || defined(HAVE_DECODER_SPARC)
{
- LZMA_FILTER_SPARC,
- sizeof(lzma_options_bcj),
- true,
- false,
- false,
+ .id = LZMA_FILTER_SPARC,
+ .options_size = sizeof(lzma_options_bcj),
+ .non_last_ok = true,
+ .last_ok = false,
+ .changes_size = false,
},
#endif
#if defined(HAVE_ENCODER_DELTA) || defined(HAVE_DECODER_DELTA)
{
- LZMA_FILTER_DELTA,
- sizeof(lzma_options_delta),
- true,
- false,
- false,
+ .id = LZMA_FILTER_DELTA,
+ .options_size = sizeof(lzma_options_delta),
+ .non_last_ok = true,
+ .last_ok = false,
+ .changes_size = false,
},
#endif
{
- LZMA_VLI_UNKNOWN
+ .id = LZMA_VLI_UNKNOWN
}
};
extern LZMA_API(lzma_ret)
lzma_filters_copy(const lzma_filter *src, lzma_filter *dest,
- lzma_allocator *allocator)
+ const lzma_allocator *allocator)
{
- size_t i;
- lzma_ret ret;
-
if (src == NULL || dest == NULL)
return LZMA_PROG_ERROR;
+ lzma_ret ret;
+ size_t i;
for (i = 0; src[i].id != LZMA_VLI_UNKNOWN; ++i) {
// There must be a maximum of four filters plus
// the array terminator.
@@ -194,6 +193,10 @@ error:
static lzma_ret
validate_chain(const lzma_filter *filters, size_t *count)
{
+ // There must be at least one filter.
+ if (filters == NULL || filters[0].id == LZMA_VLI_UNKNOWN)
+ return LZMA_PROG_ERROR;
+
// 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;
@@ -207,11 +210,6 @@ validate_chain(const lzma_filter *filters, size_t *count)
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)
@@ -241,21 +239,18 @@ validate_chain(const lzma_filter *filters, size_t *count)
extern lzma_ret
-lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_raw_coder_init(lzma_next_coder *next, const 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.
+ size_t count;
return_if_error(validate_chain(options, &count));
// Set the filter functions and copy the options pointer.
+ lzma_filter_info filters[LZMA_FILTERS_MAX + 1];
if (is_encoder) {
- for (i = 0; i < count; ++i) {
+ for (size_t i = 0; i < count; ++i) {
// The order of the filters is reversed in the
// encoder. It allows more efficient handling
// of the uncompressed data.
@@ -271,7 +266,7 @@ lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
filters[j].options = options[i].options;
}
} else {
- for (i = 0; i < count; ++i) {
+ for (size_t i = 0; i < count; ++i) {
const lzma_filter_coder *const fc
= coder_find(options[i].id);
if (fc == NULL || fc->init == NULL)
@@ -288,7 +283,7 @@ lzma_raw_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
filters[count].init = NULL;
// Initialize the filters.
- ret = lzma_next_filter_init(next, allocator, filters);
+ const lzma_ret ret = lzma_next_filter_init(next, allocator, filters);
if (ret != LZMA_OK)
lzma_next_end(next, allocator);
@@ -300,9 +295,6 @@ 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;
@@ -310,6 +302,9 @@ lzma_raw_coder_memusage(lzma_filter_find coder_find,
return UINT64_MAX;
}
+ uint64_t total = 0;
+ size_t i = 0;
+
do {
const lzma_filter_coder *const fc
= coder_find(filters[i].id);
diff --git a/Utilities/cmliblzma/liblzma/common/filter_common.h b/Utilities/cmliblzma/liblzma/common/filter_common.h
index cd61fc072..42a26a24a 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_common.h
+++ b/Utilities/cmliblzma/liblzma/common/filter_common.h
@@ -36,7 +36,7 @@ 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,
+ lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter *filters,
lzma_filter_find coder_find, bool is_encoder);
diff --git a/Utilities/cmliblzma/liblzma/common/filter_decoder.c b/Utilities/cmliblzma/liblzma/common/filter_decoder.c
index cce2b30ea..c75b0a89c 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_decoder.c
@@ -35,7 +35,8 @@ typedef struct {
/// \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,
+ lzma_ret (*props_decode)(
+ void **options, const lzma_allocator *allocator,
const uint8_t *props, size_t props_size);
} lzma_filter_decoder;
@@ -44,74 +45,74 @@ typedef struct {
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,
+ .id = LZMA_FILTER_LZMA1,
+ .init = &lzma_lzma_decoder_init,
+ .memusage = &lzma_lzma_decoder_memusage,
+ .props_decode = &lzma_lzma_props_decode,
},
#endif
#ifdef HAVE_DECODER_LZMA2
{
- LZMA_FILTER_LZMA2,
- &lzma_lzma2_decoder_init,
- &lzma_lzma2_decoder_memusage,
- &lzma_lzma2_props_decode,
+ .id = LZMA_FILTER_LZMA2,
+ .init = &lzma_lzma2_decoder_init,
+ .memusage = &lzma_lzma2_decoder_memusage,
+ .props_decode = &lzma_lzma2_props_decode,
},
#endif
#ifdef HAVE_DECODER_X86
{
- LZMA_FILTER_X86,
- &lzma_simple_x86_decoder_init,
- NULL,
- &lzma_simple_props_decode,
+ .id = LZMA_FILTER_X86,
+ .init = &lzma_simple_x86_decoder_init,
+ .memusage = NULL,
+ .props_decode = &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_POWERPC
{
- LZMA_FILTER_POWERPC,
- &lzma_simple_powerpc_decoder_init,
- NULL,
- &lzma_simple_props_decode,
+ .id = LZMA_FILTER_POWERPC,
+ .init = &lzma_simple_powerpc_decoder_init,
+ .memusage = NULL,
+ .props_decode = &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_IA64
{
- LZMA_FILTER_IA64,
- &lzma_simple_ia64_decoder_init,
- NULL,
- &lzma_simple_props_decode,
+ .id = LZMA_FILTER_IA64,
+ .init = &lzma_simple_ia64_decoder_init,
+ .memusage = NULL,
+ .props_decode = &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_ARM
{
- LZMA_FILTER_ARM,
- &lzma_simple_arm_decoder_init,
- NULL,
- &lzma_simple_props_decode,
+ .id = LZMA_FILTER_ARM,
+ .init = &lzma_simple_arm_decoder_init,
+ .memusage = NULL,
+ .props_decode = &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_ARMTHUMB
{
- LZMA_FILTER_ARMTHUMB,
- &lzma_simple_armthumb_decoder_init,
- NULL,
- &lzma_simple_props_decode,
+ .id = LZMA_FILTER_ARMTHUMB,
+ .init = &lzma_simple_armthumb_decoder_init,
+ .memusage = NULL,
+ .props_decode = &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_SPARC
{
- LZMA_FILTER_SPARC,
- &lzma_simple_sparc_decoder_init,
- NULL,
- &lzma_simple_props_decode,
+ .id = LZMA_FILTER_SPARC,
+ .init = &lzma_simple_sparc_decoder_init,
+ .memusage = NULL,
+ .props_decode = &lzma_simple_props_decode,
},
#endif
#ifdef HAVE_DECODER_DELTA
{
- LZMA_FILTER_DELTA,
- &lzma_delta_decoder_init,
- &lzma_delta_coder_memusage,
- &lzma_delta_props_decode,
+ .id = LZMA_FILTER_DELTA,
+ .init = &lzma_delta_decoder_init,
+ .memusage = &lzma_delta_coder_memusage,
+ .props_decode = &lzma_delta_props_decode,
},
#endif
};
@@ -120,8 +121,7 @@ static const lzma_filter_decoder decoders[] = {
static const lzma_filter_decoder *
decoder_find(lzma_vli id)
{
- size_t i;
- for (i = 0; i < ARRAY_SIZE(decoders); ++i)
+ for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i)
if (decoders[i].id == id)
return decoders + i;
@@ -137,7 +137,7 @@ lzma_filter_decoder_is_supported(lzma_vli id)
extern lzma_ret
-lzma_raw_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_raw_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter *options)
{
return lzma_raw_coder_init(next, allocator,
@@ -148,7 +148,7 @@ lzma_raw_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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);
+ lzma_next_strm_init(lzma_raw_decoder_init, strm, options);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
@@ -166,14 +166,13 @@ lzma_raw_decoder_memusage(const lzma_filter *filters)
extern LZMA_API(lzma_ret)
-lzma_properties_decode(lzma_filter *filter, lzma_allocator *allocator,
+lzma_properties_decode(lzma_filter *filter, const 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;
+ const lzma_filter_decoder *const fd = decoder_find(filter->id);
if (fd == NULL)
return LZMA_OPTIONS_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/common/filter_decoder.h b/Utilities/cmliblzma/liblzma/common/filter_decoder.h
index d5c68bdd4..a2e255fe5 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_decoder.h
+++ b/Utilities/cmliblzma/liblzma/common/filter_decoder.h
@@ -17,7 +17,7 @@
extern lzma_ret lzma_raw_decoder_init(
- lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_next_coder *next, const 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
index 9fdb10008..c5d8f3972 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_encoder.c
@@ -30,11 +30,11 @@ typedef struct {
/// 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);
+ /// Calculates the recommended Uncompressed Size for .xz Blocks 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.
+ uint64_t (*block_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
@@ -56,101 +56,95 @@ typedef struct {
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,
+ .id = LZMA_FILTER_LZMA1,
+ .init = &lzma_lzma_encoder_init,
+ .memusage = &lzma_lzma_encoder_memusage,
+ .block_size = NULL, // FIXME
+ .props_size_get = NULL,
+ .props_size_fixed = 5,
+ .props_encode = &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,
+ .id = LZMA_FILTER_LZMA2,
+ .init = &lzma_lzma2_encoder_init,
+ .memusage = &lzma_lzma2_encoder_memusage,
+ .block_size = &lzma_lzma2_block_size, // FIXME
+ .props_size_get = NULL,
+ .props_size_fixed = 1,
+ .props_encode = &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,
+ .id = LZMA_FILTER_X86,
+ .init = &lzma_simple_x86_encoder_init,
+ .memusage = NULL,
+ .block_size = NULL,
+ .props_size_get = &lzma_simple_props_size,
+ .props_encode = &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,
+ .id = LZMA_FILTER_POWERPC,
+ .init = &lzma_simple_powerpc_encoder_init,
+ .memusage = NULL,
+ .block_size = NULL,
+ .props_size_get = &lzma_simple_props_size,
+ .props_encode = &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,
+ .id = LZMA_FILTER_IA64,
+ .init = &lzma_simple_ia64_encoder_init,
+ .memusage = NULL,
+ .block_size = NULL,
+ .props_size_get = &lzma_simple_props_size,
+ .props_encode = &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,
+ .id = LZMA_FILTER_ARM,
+ .init = &lzma_simple_arm_encoder_init,
+ .memusage = NULL,
+ .block_size = NULL,
+ .props_size_get = &lzma_simple_props_size,
+ .props_encode = &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,
+ .id = LZMA_FILTER_ARMTHUMB,
+ .init = &lzma_simple_armthumb_encoder_init,
+ .memusage = NULL,
+ .block_size = NULL,
+ .props_size_get = &lzma_simple_props_size,
+ .props_encode = &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,
+ .id = LZMA_FILTER_SPARC,
+ .init = &lzma_simple_sparc_encoder_init,
+ .memusage = NULL,
+ .block_size = NULL,
+ .props_size_get = &lzma_simple_props_size,
+ .props_encode = &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,
+ .id = LZMA_FILTER_DELTA,
+ .init = &lzma_delta_encoder_init,
+ .memusage = &lzma_delta_coder_memusage,
+ .block_size = NULL,
+ .props_size_get = NULL,
+ .props_size_fixed = 1,
+ .props_encode = &lzma_delta_props_encode,
},
#endif
};
@@ -159,8 +153,7 @@ static const lzma_filter_encoder encoders[] = {
static const lzma_filter_encoder *
encoder_find(lzma_vli id)
{
- size_t i;
- for (i = 0; i < ARRAY_SIZE(encoders); ++i)
+ for (size_t i = 0; i < ARRAY_SIZE(encoders); ++i)
if (encoders[i].id == id)
return encoders + i;
@@ -178,10 +171,6 @@ lzma_filter_encoder_is_supported(lzma_vli id)
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;
@@ -191,10 +180,12 @@ lzma_filters_update(lzma_stream *strm, const lzma_filter *filters)
// The actual filter chain in the encoder is reversed. Some things
// still want the normal order chain, so we provide both.
+ size_t count = 1;
while (filters[count].id != LZMA_VLI_UNKNOWN)
++count;
- for (i = 0; i < count; ++i)
+ lzma_filter reversed_filters[LZMA_FILTERS_MAX + 1];
+ for (size_t i = 0; i < count; ++i)
reversed_filters[count - i - 1] = filters[i];
reversed_filters[count].id = LZMA_VLI_UNKNOWN;
@@ -205,7 +196,7 @@ lzma_filters_update(lzma_stream *strm, const lzma_filter *filters)
extern lzma_ret
-lzma_raw_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_raw_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter *options)
{
return lzma_raw_coder_init(next, allocator,
@@ -216,7 +207,7 @@ lzma_raw_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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_next_strm_init(lzma_raw_coder_init, strm, options,
(lzma_filter_find)(&encoder_find), true);
strm->internal->supported_actions[LZMA_RUN] = true;
@@ -235,20 +226,19 @@ lzma_raw_encoder_memusage(const lzma_filter *filters)
}
-/*
-extern LZMA_API(lzma_vli)
-lzma_chunk_size(const lzma_filter *filters)
+extern uint64_t
+lzma_mt_block_size(const lzma_filter *filters)
{
- lzma_vli max = 0;
+ uint64_t 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 (fe->block_size != NULL) {
+ const uint64_t size
+ = fe->block_size(filters[i].options);
+ if (size == 0)
+ return 0;
if (size > max)
max = size;
@@ -257,7 +247,6 @@ lzma_chunk_size(const lzma_filter *filters)
return max;
}
-*/
extern LZMA_API(lzma_ret)
diff --git a/Utilities/cmliblzma/liblzma/common/filter_encoder.h b/Utilities/cmliblzma/liblzma/common/filter_encoder.h
index 5bc137f64..f1d5683fe 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_encoder.h
+++ b/Utilities/cmliblzma/liblzma/common/filter_encoder.h
@@ -16,12 +16,12 @@
#include "common.h"
-// FIXME: Might become a part of the public API once finished.
-// extern lzma_vli lzma_chunk_size(const lzma_filter *filters);
+// FIXME: Might become a part of the public API.
+extern uint64_t lzma_mt_block_size(const lzma_filter *filters);
extern lzma_ret lzma_raw_encoder_init(
- lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_next_coder *next, const 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
index aa2dbd560..ddfb08594 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_flags_decoder.c
@@ -15,12 +15,9 @@
extern LZMA_API(lzma_ret)
lzma_filter_flags_decode(
- lzma_filter *filter, lzma_allocator *allocator,
+ lzma_filter *filter, const 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;
@@ -32,6 +29,7 @@ lzma_filter_flags_decode(
return LZMA_DATA_ERROR;
// Size of Properties
+ lzma_vli props_size;
return_if_error(lzma_vli_decode(&props_size, NULL,
in, in_pos, in_size));
@@ -39,7 +37,7 @@ lzma_filter_flags_decode(
if (in_size - *in_pos < props_size)
return LZMA_DATA_ERROR;
- ret = lzma_properties_decode(
+ const lzma_ret ret = lzma_properties_decode(
filter, allocator, in + *in_pos, props_size);
*in_pos += props_size;
diff --git a/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c b/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
index 755c407f6..d110566de 100644
--- a/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/filter_flags_encoder.c
@@ -31,8 +31,6 @@ 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;
@@ -41,6 +39,7 @@ lzma_filter_flags_encode(const lzma_filter *filter,
out, out_pos, out_size));
// Size of Properties
+ uint32_t props_size;
return_if_error(lzma_properties_size(&props_size, filter));
return_if_error(lzma_vli_encode(props_size, NULL,
out, out_pos, out_size));
diff --git a/Utilities/cmliblzma/liblzma/common/index.c b/Utilities/cmliblzma/liblzma/common/index.c
index 26135d22c..26e4e519b 100644
--- a/Utilities/cmliblzma/liblzma/common/index.c
+++ b/Utilities/cmliblzma/liblzma/common/index.c
@@ -191,8 +191,8 @@ index_tree_init(index_tree *tree)
/// 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))
+index_tree_node_end(index_tree_node *node, const lzma_allocator *allocator,
+ void (*free_func)(void *node, const 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.
@@ -202,22 +202,21 @@ index_tree_node_end(index_tree_node *node, lzma_allocator *allocator,
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);
+ free_func(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.
+/// Free the memory allocated for a tree. Each node is freed using the
+/// given free_func which is either &lzma_free or &index_stream_end.
+/// The latter 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))
+index_tree_end(index_tree *tree, const lzma_allocator *allocator,
+ void (*free_func)(void *node, const lzma_allocator *allocator))
{
+ assert(free_func != NULL);
+
if (tree->root != NULL)
index_tree_node_end(tree->root, allocator, free_func);
@@ -230,7 +229,6 @@ index_tree_end(index_tree *tree, lzma_allocator *allocator,
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;
@@ -259,10 +257,8 @@ index_tree_append(index_tree *tree, index_tree_node *node)
// 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));
+ uint32_t 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 {
@@ -270,7 +266,7 @@ index_tree_append(index_tree *tree, index_tree_node *node)
} while (--up > 0);
// Rotate left using node as the rotation root.
- pivot = node->right;
+ index_tree_node *pivot = node->right;
if (node->parent == NULL) {
tree->root = pivot;
@@ -342,8 +338,8 @@ index_tree_locate(const index_tree *tree, lzma_vli target)
/// 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)
+ uint32_t stream_number, lzma_vli block_number_base,
+ const lzma_allocator *allocator)
{
index_stream *s = lzma_alloc(sizeof(index_stream), allocator);
if (s == NULL)
@@ -371,16 +367,17 @@ index_stream_init(lzma_vli compressed_base, lzma_vli uncompressed_base,
/// Free the memory allocated for a Stream and its Record groups.
static void
-index_stream_end(void *node, lzma_allocator *allocator)
+index_stream_end(void *node, const lzma_allocator *allocator)
{
index_stream *s = node;
- index_tree_end(&s->groups, allocator, NULL);
+ index_tree_end(&s->groups, allocator, &lzma_free);
+ lzma_free(s, allocator);
return;
}
static lzma_index *
-index_init_plain(lzma_allocator *allocator)
+index_init_plain(const lzma_allocator *allocator)
{
lzma_index *i = lzma_alloc(sizeof(lzma_index), allocator);
if (i != NULL) {
@@ -398,15 +395,13 @@ index_init_plain(lzma_allocator *allocator)
extern LZMA_API(lzma_index *)
-lzma_index_init(lzma_allocator *allocator)
+lzma_index_init(const 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);
+ index_stream *s = index_stream_init(0, 0, 1, 0, allocator);
if (s == NULL) {
lzma_free(i, allocator);
return NULL;
@@ -419,7 +414,7 @@ lzma_index_init(lzma_allocator *allocator)
extern LZMA_API(void)
-lzma_index_end(lzma_index *i, lzma_allocator *allocator)
+lzma_index_end(lzma_index *i, const lzma_allocator *allocator)
{
// NOTE: If you modify this function, check also the bottom
// of lzma_index_cat().
@@ -605,8 +600,6 @@ lzma_index_padding_size(const lzma_index *i)
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;
@@ -614,7 +607,7 @@ lzma_index_stream_flags(lzma_index *i, const lzma_stream_flags *stream_flags)
return_if_error(lzma_stream_flags_compare(
stream_flags, stream_flags));
- s = (index_stream *)(i->streams.rightmost);
+ index_stream *s = (index_stream *)(i->streams.rightmost);
s->stream_flags = *stream_flags;
return LZMA_OK;
@@ -624,17 +617,14 @@ lzma_index_stream_flags(lzma_index *i, const lzma_stream_flags *stream_flags)
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);
+ index_stream *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;
+ const lzma_vli 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;
@@ -647,29 +637,23 @@ lzma_index_stream_padding(lzma_index *i, lzma_vli stream_padding)
extern LZMA_API(lzma_ret)
-lzma_index_append(lzma_index *i, lzma_allocator *allocator,
+lzma_index_append(lzma_index *i, const 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);
+ index_stream *s = (index_stream *)(i->streams.rightmost);
+ index_group *g = (index_group *)(s->groups.rightmost);
- compressed_base = g == NULL ? 0
+ const lzma_vli compressed_base = g == NULL ? 0
: vli_ceil4(g->records[g->last].unpadded_sum);
- uncompressed_base = g == NULL ? 0
+ const lzma_vli uncompressed_base = g == NULL ? 0
: g->records[g->last].uncompressed_sum;
- index_list_size_add = lzma_vli_size(unpadded_size)
+ const uint32_t index_list_size_add = lzma_vli_size(unpadded_size)
+ lzma_vli_size(uncompressed_size);
// Check that the file size will stay within limits.
@@ -780,10 +764,9 @@ index_cat_helper(const index_cat_info *info, index_stream *this)
extern LZMA_API(lzma_ret)
-lzma_index_cat(lzma_index *LZMA_RESTRICT dest, lzma_index *LZMA_RESTRICT src,
- lzma_allocator *allocator)
+lzma_index_cat(lzma_index *restrict dest, lzma_index *restrict src,
+ const 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.
@@ -813,12 +796,10 @@ lzma_index_cat(lzma_index *LZMA_RESTRICT dest, lzma_index *LZMA_RESTRICT 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)
+ index_group *newg = lzma_alloc(sizeof(index_group)
+ (g->last + 1)
* sizeof(index_record),
allocator);
@@ -848,17 +829,21 @@ lzma_index_cat(lzma_index *LZMA_RESTRICT dest, lzma_index *LZMA_RESTRICT src,
s->groups.rightmost = &newg->node;
lzma_free(g, allocator);
+
+ // NOTE: newg isn't leaked here because
+ // newg == (void *)&newg->node.
}
}
// 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;
-
+ const index_cat_info info = {
+ .uncompressed_size = dest->uncompressed_size,
+ .file_size = dest_file_size,
+ .stream_number_add = dest->streams.count,
+ .block_number_add = dest->record_count,
+ .streams = &dest->streams,
+ };
index_cat_helper(&info, (index_stream *)(src->streams.root));
// Update info about all the combined Streams.
@@ -877,26 +862,18 @@ lzma_index_cat(lzma_index *LZMA_RESTRICT dest, lzma_index *LZMA_RESTRICT src,
/// Duplicate an index_stream.
static index_stream *
-index_dup_stream(const index_stream *src, lzma_allocator *allocator)
+index_dup_stream(const index_stream *src, const 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,
+ index_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;
+ if (dest == NULL)
+ return NULL;
// Copy the overall information.
dest->record_count = src->record_count;
@@ -904,10 +881,14 @@ index_dup_stream(const index_stream *src, lzma_allocator *allocator)
dest->stream_flags = src->stream_flags;
dest->stream_padding = src->stream_padding;
+ // Return if there are no groups to duplicate.
+ if (src->groups.leftmost == NULL)
+ return dest;
+
// 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)
+ index_group *destg = lzma_alloc(sizeof(index_group)
+ src->record_count * sizeof(index_record),
allocator);
if (destg == NULL) {
@@ -923,7 +904,8 @@ index_dup_stream(const index_stream *src, lzma_allocator *allocator)
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);
+ const index_group *srcg = (const index_group *)(src->groups.leftmost);
+ size_t i = 0;
do {
memcpy(destg->records + i, srcg->records,
(srcg->last + 1) * sizeof(index_record));
@@ -941,11 +923,8 @@ index_dup_stream(const index_stream *src, lzma_allocator *allocator)
extern LZMA_API(lzma_index *)
-lzma_index_dup(const lzma_index *src, lzma_allocator *allocator)
+lzma_index_dup(const lzma_index *src, const 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)
@@ -958,9 +937,11 @@ lzma_index_dup(const lzma_index *src, lzma_allocator *allocator)
dest->index_list_size = src->index_list_size;
// Copy the Streams and the groups in them.
- srcstream = (index_stream *)(src->streams.leftmost);
+ const index_stream *srcstream
+ = (const index_stream *)(src->streams.leftmost);
do {
- deststream = index_dup_stream(srcstream, allocator);
+ index_stream *deststream = index_dup_stream(
+ srcstream, allocator);
if (deststream == NULL) {
lzma_index_end(dest, allocator);
return NULL;
@@ -1031,6 +1012,8 @@ iter_set_info(lzma_index_iter *iter)
iter->internal[ITER_GROUP].p = NULL;
}
+ // NOTE: lzma_index_iter.stream.number is lzma_vli but we use uint32_t
+ // internally.
iter->stream.number = stream->number;
iter->stream.block_count = stream->record_count;
iter->stream.compressed_offset = stream->node.compressed_base;
@@ -1119,19 +1102,14 @@ lzma_index_iter_rewind(lzma_index_iter *iter)
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;
+ const lzma_index *i = iter->internal[ITER_INDEX].p;
+ const index_stream *stream = iter->internal[ITER_STREAM].p;
+ const index_group *group = NULL;
+ size_t 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
@@ -1231,10 +1209,6 @@ again:
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.
@@ -1242,12 +1216,12 @@ lzma_index_iter_locate(lzma_index_iter *iter, lzma_vli target)
return true;
// Locate the Stream containing the target offset.
- stream = index_tree_locate(&i->streams, target);
+ const index_stream *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);
+ const index_group *group = index_tree_locate(&stream->groups, target);
assert(group != NULL);
// Use binary search to locate the exact Record. It is the first
@@ -1255,8 +1229,8 @@ lzma_index_iter_locate(lzma_index_iter *iter, lzma_vli 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;
+ size_t left = 0;
+ size_t right = group->last;
while (left < right) {
const size_t pos = left + (right - left) / 2;
diff --git a/Utilities/cmliblzma/liblzma/common/index_decoder.c b/Utilities/cmliblzma/liblzma/common/index_decoder.c
index 943cfd58a..cc07a1b8c 100644
--- a/Utilities/cmliblzma/liblzma/common/index_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/index_decoder.c
@@ -14,7 +14,7 @@
#include "check.h"
-struct lzma_coder_s {
+typedef struct {
enum {
SEQ_INDICATOR,
SEQ_COUNT,
@@ -50,18 +50,20 @@ struct lzma_coder_s {
/// CRC32 of the List of Records field
uint32_t crc32;
-};
+} lzma_index_coder;
static lzma_ret
-index_decode(lzma_coder *coder, lzma_allocator *allocator,
- const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+index_decode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size,
- uint8_t *LZMA_RESTRICT out lzma_attribute((__unused__)),
- size_t *LZMA_RESTRICT out_pos lzma_attribute((__unused__)),
+ uint8_t *restrict out lzma_attribute((__unused__)),
+ size_t *restrict out_pos lzma_attribute((__unused__)),
size_t out_size lzma_attribute((__unused__)),
lzma_action action lzma_attribute((__unused__)))
{
+ lzma_index_coder *coder = coder_ptr;
+
// Similar optimization as in index_encoder.c
const size_t in_start = *in_pos;
lzma_ret ret = LZMA_OK;
@@ -207,8 +209,9 @@ out:
static void
-index_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+index_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_index_coder *coder = coder_ptr;
lzma_index_end(coder->index, allocator);
lzma_free(coder, allocator);
return;
@@ -216,9 +219,11 @@ index_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-index_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+index_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
+ lzma_index_coder *coder = coder_ptr;
+
*memusage = lzma_index_memusage(1, coder->count);
*old_memlimit = coder->memlimit;
@@ -234,7 +239,7 @@ index_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
static lzma_ret
-index_decoder_reset(lzma_coder *coder, lzma_allocator *allocator,
+index_decoder_reset(lzma_index_coder *coder, const lzma_allocator *allocator,
lzma_index **i, uint64_t memlimit)
{
// Remember the pointer given by the application. We will set it
@@ -251,7 +256,7 @@ index_decoder_reset(lzma_coder *coder, lzma_allocator *allocator,
// Initialize the rest.
coder->sequence = SEQ_INDICATOR;
- coder->memlimit = memlimit;
+ coder->memlimit = my_max(1, memlimit);
coder->count = 0; // Needs to be initialized due to _memconfig().
coder->pos = 0;
coder->crc32 = 0;
@@ -261,35 +266,37 @@ index_decoder_reset(lzma_coder *coder, lzma_allocator *allocator,
static lzma_ret
-index_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+index_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
lzma_index **i, uint64_t memlimit)
{
lzma_next_coder_init(&index_decoder_init, next, allocator);
- if (i == NULL || memlimit == 0)
+ if (i == NULL)
return LZMA_PROG_ERROR;
- if (next->coder == NULL) {
- next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
- if (next->coder == NULL)
+ lzma_index_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_index_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
next->code = &index_decode;
next->end = &index_decoder_end;
next->memconfig = &index_decoder_memconfig;
- next->coder->index = NULL;
+ coder->index = NULL;
} else {
- lzma_index_end(next->coder->index, allocator);
+ lzma_index_end(coder->index, allocator);
}
- return index_decoder_reset(next->coder, allocator, i, memlimit);
+ return index_decoder_reset(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);
+ lzma_next_strm_init(index_decoder_init, strm, i, memlimit);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
@@ -299,27 +306,25 @@ lzma_index_decoder(lzma_stream *strm, lzma_index **i, uint64_t memlimit)
extern LZMA_API(lzma_ret)
-lzma_index_buffer_decode(
- lzma_index **i, uint64_t *memlimit, lzma_allocator *allocator,
+lzma_index_buffer_decode(lzma_index **i, uint64_t *memlimit,
+ const 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.
+ lzma_index_coder coder;
return_if_error(index_decoder_reset(&coder, allocator, i, *memlimit));
+ // Store the input start position so that we can restore it in case
+ // of an error.
+ const size_t in_start = *in_pos;
+
// Do the actual decoding.
- ret = index_decode(&coder, allocator, in, in_pos, in_size,
+ lzma_ret ret = index_decode(&coder, allocator, in, in_pos, in_size,
NULL, NULL, 0, LZMA_RUN);
if (ret == LZMA_STREAM_END) {
diff --git a/Utilities/cmliblzma/liblzma/common/index_encoder.c b/Utilities/cmliblzma/liblzma/common/index_encoder.c
index 194bf2113..ac97d0ceb 100644
--- a/Utilities/cmliblzma/liblzma/common/index_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/index_encoder.c
@@ -15,7 +15,7 @@
#include "check.h"
-struct lzma_coder_s {
+typedef struct {
enum {
SEQ_INDICATOR,
SEQ_COUNT,
@@ -37,19 +37,21 @@ struct lzma_coder_s {
/// CRC32 of the List of Records field
uint32_t crc32;
-};
+} lzma_index_coder;
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__)),
+index_encode(void *coder_ptr,
+ const lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *restrict in lzma_attribute((__unused__)),
+ size_t *restrict in_pos lzma_attribute((__unused__)),
size_t in_size lzma_attribute((__unused__)),
- uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size,
lzma_action action lzma_attribute((__unused__)))
{
+ lzma_index_coder *coder = coder_ptr;
+
// 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;
@@ -159,7 +161,7 @@ out:
static void
-index_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+index_encoder_end(void *coder, const lzma_allocator *allocator)
{
lzma_free(coder, allocator);
return;
@@ -167,7 +169,7 @@ index_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
static void
-index_encoder_reset(lzma_coder *coder, const lzma_index *i)
+index_encoder_reset(lzma_index_coder *coder, const lzma_index *i)
{
lzma_index_iter_init(&coder->iter, i);
@@ -181,7 +183,7 @@ index_encoder_reset(lzma_coder *coder, const lzma_index *i)
extern lzma_ret
-lzma_index_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_index_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_index *i)
{
lzma_next_coder_init(&lzma_index_encoder_init, next, allocator);
@@ -190,7 +192,7 @@ lzma_index_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
return LZMA_PROG_ERROR;
if (next->coder == NULL) {
- next->coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ next->coder = lzma_alloc(sizeof(lzma_index_coder), allocator);
if (next->coder == NULL)
return LZMA_MEM_ERROR;
@@ -207,7 +209,7 @@ lzma_index_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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);
+ lzma_next_strm_init(lzma_index_encoder_init, strm, i);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
@@ -220,10 +222,6 @@ 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;
@@ -234,12 +232,13 @@ lzma_index_buffer_encode(const lzma_index *i,
// The Index encoder needs just one small data structure so we can
// allocate it on stack.
+ lzma_index_coder coder;
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,
+ const size_t out_start = *out_pos;
+ lzma_ret ret = index_encode(&coder, NULL, NULL, NULL, 0,
out, out_pos, out_size, LZMA_RUN);
if (ret == LZMA_STREAM_END) {
diff --git a/Utilities/cmliblzma/liblzma/common/index_encoder.h b/Utilities/cmliblzma/liblzma/common/index_encoder.h
index a13c94dcd..4d55cd104 100644
--- a/Utilities/cmliblzma/liblzma/common/index_encoder.h
+++ b/Utilities/cmliblzma/liblzma/common/index_encoder.h
@@ -17,7 +17,7 @@
extern lzma_ret lzma_index_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_index *i);
+ const 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
index 0cf86b307..d7a0344b7 100644
--- a/Utilities/cmliblzma/liblzma/common/index_hash.c
+++ b/Utilities/cmliblzma/liblzma/common/index_hash.c
@@ -70,7 +70,8 @@ struct lzma_index_hash_s {
extern LZMA_API(lzma_index_hash *)
-lzma_index_hash_init(lzma_index_hash *index_hash, lzma_allocator *allocator)
+lzma_index_hash_init(lzma_index_hash *index_hash,
+ const lzma_allocator *allocator)
{
if (index_hash == NULL) {
index_hash = lzma_alloc(sizeof(lzma_index_hash), allocator);
@@ -101,7 +102,8 @@ lzma_index_hash_init(lzma_index_hash *index_hash, lzma_allocator *allocator)
extern LZMA_API(void)
-lzma_index_hash_end(lzma_index_hash *index_hash, lzma_allocator *allocator)
+lzma_index_hash_end(lzma_index_hash *index_hash,
+ const lzma_allocator *allocator)
{
lzma_free(index_hash, allocator);
return;
@@ -124,14 +126,13 @@ 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;
+ const lzma_vli sizes[2] = { unpadded_size, uncompressed_size };
lzma_check_update(&info->check, LZMA_CHECK_BEST,
(const uint8_t *)(sizes), sizeof(sizes));
@@ -174,9 +175,6 @@ 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.
@@ -186,8 +184,8 @@ lzma_index_hash_decode(lzma_index_hash *index_hash, const uint8_t *in,
// 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;
+ const size_t in_start = *in_pos;
+ lzma_ret ret = LZMA_OK;
while (*in_pos < in_size)
switch (index_hash->sequence) {
diff --git a/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
index 9e2e1da83..b9745b5db 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_buffer_decoder.c
@@ -15,13 +15,10 @@
extern LZMA_API(lzma_ret)
lzma_stream_buffer_decode(uint64_t *memlimit, uint32_t flags,
- lzma_allocator *allocator,
+ const 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
@@ -36,7 +33,8 @@ lzma_stream_buffer_decode(uint64_t *memlimit, uint32_t flags,
// 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(
+ lzma_next_coder stream_decoder = LZMA_NEXT_CODER_INIT;
+ lzma_ret ret = lzma_stream_decoder_init(
&stream_decoder, allocator, *memlimit, flags);
if (ret == LZMA_OK) {
diff --git a/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
index 8bca87f47..af49554a6 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_buffer_encoder.c
@@ -42,13 +42,10 @@ lzma_stream_buffer_bound(size_t uncompressed_size)
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,
+ const 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
@@ -65,7 +62,7 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
// Use a local copy. We update *out_pos_ptr only if everything
// succeeds.
- out_pos = *out_pos_ptr;
+ size_t out_pos = *out_pos_ptr;
// Check that there's enough space for both Stream Header and
// Stream Footer.
@@ -77,7 +74,10 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
out_size -= LZMA_STREAM_HEADER_SIZE;
// Encode the Stream Header.
- stream_flags.check = check;
+ lzma_stream_flags stream_flags = {
+ .version = 0,
+ .check = check,
+ };
if (lzma_stream_header_encode(&stream_flags, out + out_pos)
!= LZMA_OK)
@@ -86,8 +86,11 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
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;
+ lzma_block block = {
+ .version = 0,
+ .check = check,
+ .filters = filters,
+ };
if (in_size > 0)
return_if_error(lzma_block_buffer_encode(&block, allocator,
@@ -95,8 +98,6 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
// 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.
@@ -104,7 +105,7 @@ lzma_stream_buffer_encode(lzma_filter *filters, lzma_check check,
if (i == NULL)
return LZMA_MEM_ERROR;
- ret = LZMA_OK;
+ lzma_ret ret = LZMA_OK;
if (in_size > 0)
ret = lzma_index_append(i, allocator,
diff --git a/Utilities/cmliblzma/liblzma/common/stream_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_decoder.c
index 5e9a22069..fdd8ff2f9 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_decoder.c
@@ -14,7 +14,7 @@
#include "block_decoder.h"
-struct lzma_coder_s {
+typedef struct {
enum {
SEQ_STREAM_HEADER,
SEQ_BLOCK_HEADER,
@@ -57,6 +57,10 @@ struct lzma_coder_s {
/// If true, LZMA_GET_CHECK is returned after decoding Stream Header.
bool tell_any_check;
+ /// If true, we will tell the Block decoder to skip calculating
+ /// and verifying the integrity check.
+ bool ignore_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
@@ -76,11 +80,11 @@ struct lzma_coder_s {
/// Buffer to hold Stream Header, Block Header, and Stream Footer.
/// Block Header has biggest maximum size.
uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX];
-};
+} lzma_stream_coder;
static lzma_ret
-stream_decoder_reset(lzma_coder *coder, lzma_allocator *allocator)
+stream_decoder_reset(lzma_stream_coder *coder, const lzma_allocator *allocator)
{
// Initialize the Index hash used to verify the Index.
coder->index_hash = lzma_index_hash_init(coder->index_hash, allocator);
@@ -96,18 +100,18 @@ stream_decoder_reset(lzma_coder *coder, lzma_allocator *allocator)
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)
+stream_decode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
+ lzma_stream_coder *coder = coder_ptr;
+
// 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);
@@ -119,7 +123,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
coder->pos = 0;
// Decode the Stream Header.
- ret = lzma_stream_header_decode(
+ const lzma_ret ret = lzma_stream_header_decode(
&coder->stream_flags, coder->buffer);
if (ret != LZMA_OK)
return ret == LZMA_FORMAT_ERROR && !coder->first_stream
@@ -156,11 +160,6 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// 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;
@@ -189,20 +188,28 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
coder->pos = 0;
- // Version 0 is currently the only possible version.
- coder->block_options.version = 0;
+ // Version 1 is needed to support the .ignore_check option.
+ coder->block_options.version = 1;
// 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.
+ lzma_filter filters[LZMA_FILTERS_MAX + 1];
coder->block_options.filters = filters;
// Decode the Block Header.
return_if_error(lzma_block_header_decode(&coder->block_options,
allocator, coder->buffer));
+ // If LZMA_IGNORE_CHECK was used, this flag needs to be set.
+ // It has to be set after lzma_block_header_decode() because
+ // it always resets this to false.
+ coder->block_options.ignore_check = coder->ignore_check;
+
// Check the memory usage limit.
- memusage = lzma_raw_decoder_memusage(filters);
+ const uint64_t memusage = lzma_raw_decoder_memusage(filters);
+ lzma_ret ret;
+
if (memusage == UINT64_MAX) {
// One or more unknown Filter IDs.
ret = LZMA_OPTIONS_ERROR;
@@ -228,7 +235,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// Free the allocated filter options since they are needed
// only to initialize the Block decoder.
- for (i = 0; i < LZMA_FILTERS_MAX; ++i)
+ for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i)
lzma_free(filters[i].options, allocator);
coder->block_options.filters = NULL;
@@ -264,8 +271,6 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
}
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.
@@ -274,7 +279,7 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// 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,
+ const lzma_ret ret = lzma_index_hash_decode(coder->index_hash,
in, in_pos, in_size);
if (ret != LZMA_STREAM_END)
return ret;
@@ -285,9 +290,6 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// 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);
@@ -301,7 +303,8 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
// 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(
+ lzma_stream_flags footer_flags;
+ const lzma_ret ret = lzma_stream_footer_decode(
&footer_flags, coder->buffer);
if (ret != LZMA_OK)
return ret == LZMA_FORMAT_ERROR
@@ -374,8 +377,9 @@ stream_decode(lzma_coder *coder, lzma_allocator *allocator,
static void
-stream_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+stream_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_stream_coder *coder = coder_ptr;
lzma_next_end(&coder->block_decoder, allocator);
lzma_index_hash_end(coder->index_hash, allocator);
lzma_free(coder, allocator);
@@ -384,16 +388,19 @@ stream_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_check
-stream_decoder_get_check(const lzma_coder *coder)
+stream_decoder_get_check(const void *coder_ptr)
{
+ const lzma_stream_coder *coder = coder_ptr;
return coder->stream_flags.check;
}
static lzma_ret
-stream_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
+stream_decoder_memconfig(void *coder_ptr, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit)
{
+ lzma_stream_coder *coder = coder_ptr;
+
*memusage = coder->memusage;
*old_memlimit = coder->memlimit;
@@ -409,48 +416,49 @@ stream_decoder_memconfig(lzma_coder *coder, uint64_t *memusage,
extern lzma_ret
-lzma_stream_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_stream_decoder_init(
+ lzma_next_coder *next, const 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)
+ lzma_stream_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_stream_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
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;
+ coder->block_decoder = LZMA_NEXT_CODER_INIT;
+ 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
+ coder->memlimit = my_max(1, memlimit);
+ coder->memusage = LZMA_MEMUSAGE_BASE;
+ coder->tell_no_check = (flags & LZMA_TELL_NO_CHECK) != 0;
+ 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;
+ coder->tell_any_check = (flags & LZMA_TELL_ANY_CHECK) != 0;
+ coder->ignore_check = (flags & LZMA_IGNORE_CHECK) != 0;
+ coder->concatenated = (flags & LZMA_CONCATENATED) != 0;
+ coder->first_stream = true;
- return stream_decoder_reset(next->coder, allocator);
+ return stream_decoder_reset(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);
+ lzma_next_strm_init(lzma_stream_decoder_init, strm, memlimit, flags);
strm->internal->supported_actions[LZMA_RUN] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
diff --git a/Utilities/cmliblzma/liblzma/common/stream_decoder.h b/Utilities/cmliblzma/liblzma/common/stream_decoder.h
index e54ac28f4..c13c6ba12 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_decoder.h
+++ b/Utilities/cmliblzma/liblzma/common/stream_decoder.h
@@ -15,7 +15,8 @@
#include "common.h"
-extern lzma_ret lzma_stream_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, uint64_t memlimit, uint32_t flags);
+extern lzma_ret lzma_stream_decoder_init(
+ lzma_next_coder *next, const 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
index 1ba45acec..858cba473 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_encoder.c
@@ -10,12 +10,11 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include "stream_encoder.h"
#include "block_encoder.h"
#include "index_encoder.h"
-struct lzma_coder_s {
+typedef struct {
enum {
SEQ_STREAM_HEADER,
SEQ_BLOCK_INIT,
@@ -26,7 +25,7 @@ struct lzma_coder_s {
} sequence;
/// True if Block encoder has been initialized by
- /// lzma_stream_encoder_init() or stream_encoder_update()
+ /// stream_encoder_init() or stream_encoder_update()
/// and thus doesn't need to be initialized in stream_encode().
bool block_encoder_is_initialized;
@@ -56,11 +55,11 @@ struct lzma_coder_s {
/// Buffer to hold Stream Header, Block Header, and Stream Footer.
/// Block Header has biggest maximum size.
uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX];
-};
+} lzma_stream_coder;
static lzma_ret
-block_encoder_init(lzma_coder *coder, lzma_allocator *allocator)
+block_encoder_init(lzma_stream_coder *coder, const lzma_allocator *allocator)
{
// Prepare the Block options. Even though Block encoder doesn't need
// compressed_size, uncompressed_size, and header_size to be
@@ -79,11 +78,13 @@ block_encoder_init(lzma_coder *coder, lzma_allocator *allocator)
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)
+stream_encode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
+ lzma_stream_coder *coder = coder_ptr;
+
// Main loop
while (*out_pos < out_size)
switch (coder->sequence) {
@@ -126,7 +127,7 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
}
// Initialize the Block encoder unless it was already
- // initialized by lzma_stream_encoder_init() or
+ // initialized by stream_encoder_init() or
// stream_encoder_update().
if (!coder->block_encoder_is_initialized)
return_if_error(block_encoder_init(coder, allocator));
@@ -147,13 +148,12 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
}
case SEQ_BLOCK_ENCODE: {
- lzma_vli unpadded_size;
-
- static const lzma_action convert[4] = {
+ static const lzma_action convert[LZMA_ACTION_MAX + 1] = {
LZMA_RUN,
LZMA_SYNC_FLUSH,
LZMA_FINISH,
LZMA_FINISH,
+ LZMA_FINISH,
};
const lzma_ret ret = coder->block_encoder.code(
@@ -164,7 +164,7 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
return ret;
// Add a new Index Record.
- unpadded_size = lzma_block_unpadded_size(
+ const lzma_vli unpadded_size = lzma_block_unpadded_size(
&coder->block_options);
assert(unpadded_size != 0);
return_if_error(lzma_index_append(coder->index, allocator,
@@ -176,12 +176,6 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
}
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(
@@ -192,6 +186,11 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
return ret;
// Encode the Stream Footer into coder->buffer.
+ const lzma_stream_flags stream_flags = {
+ .version = 0,
+ .backward_size = lzma_index_size(coder->index),
+ .check = coder->block_options.check,
+ };
if (lzma_stream_footer_encode(&stream_flags, coder->buffer)
!= LZMA_OK)
@@ -212,15 +211,15 @@ stream_encode(lzma_coder *coder, lzma_allocator *allocator,
static void
-stream_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+stream_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
- size_t i;
+ lzma_stream_coder *coder = coder_ptr;
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)
+ for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i)
lzma_free(coder->filters[i].options, allocator);
lzma_free(coder, allocator);
@@ -229,22 +228,20 @@ stream_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-stream_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+stream_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters,
const lzma_filter *reversed_filters)
{
- size_t i;
+ lzma_stream_coder *coder = coder_ptr;
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);
+ const lzma_ret ret = block_encoder_init(coder, allocator);
coder->block_options.filters = coder->filters;
if (ret != LZMA_OK)
return ret;
@@ -264,62 +261,66 @@ stream_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
}
// 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)
+ for (size_t 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,
+static lzma_ret
+stream_encoder_init(lzma_next_coder *next, const 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);
+ lzma_next_coder_init(&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)
+ lzma_stream_coder *coder = next->coder;
+
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_stream_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
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;
+ coder->filters[0].id = LZMA_VLI_UNKNOWN;
+ coder->block_encoder = LZMA_NEXT_CODER_INIT;
+ coder->index_encoder = LZMA_NEXT_CODER_INIT;
+ coder->index = NULL;
}
// Basic initializations
- next->coder->sequence = SEQ_STREAM_HEADER;
- next->coder->block_options.version = 0;
- next->coder->block_options.check = check;
+ coder->sequence = SEQ_STREAM_HEADER;
+ coder->block_options.version = 0;
+ 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)
+ lzma_index_end(coder->index, allocator);
+ coder->index = lzma_index_init(allocator);
+ if (coder->index == NULL)
return LZMA_MEM_ERROR;
// Encode the Stream Header
+ lzma_stream_flags stream_flags = {
+ .version = 0,
+ .check = check,
+ };
return_if_error(lzma_stream_header_encode(
- &stream_flags, next->coder->buffer));
+ &stream_flags, coder->buffer));
- next->coder->buffer_pos = 0;
- next->coder->buffer_size = LZMA_STREAM_HEADER_SIZE;
+ coder->buffer_pos = 0;
+ 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);
+ return stream_encoder_update(coder, allocator, filters, NULL);
}
@@ -327,11 +328,12 @@ 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);
+ lzma_next_strm_init(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_FULL_BARRIER] = true;
strm->internal->supported_actions[LZMA_FINISH] = true;
return LZMA_OK;
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c b/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
index 8cf48a4ca..1bc2f97c5 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_decoder.c
@@ -30,15 +30,13 @@ stream_flags_decode(lzma_stream_flags *options, const uint8_t *in)
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),
+ const uint32_t 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))
@@ -61,15 +59,13 @@ lzma_stream_header_decode(lzma_stream_flags *options, const uint8_t *in)
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),
+ const uint32_t crc = lzma_crc32(in + sizeof(uint32_t),
sizeof(uint32_t) + LZMA_STREAM_FLAGS_SIZE, 0);
if (crc != unaligned_read32le(in))
return LZMA_DATA_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c b/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
index 290339e08..4e717159f 100644
--- a/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/stream_flags_encoder.c
@@ -29,8 +29,6 @@ stream_flags_encode(const lzma_stream_flags *options, uint8_t *out)
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);
@@ -45,7 +43,7 @@ lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
return LZMA_PROG_ERROR;
// CRC32 of the Stream Header
- crc = lzma_crc32(out + sizeof(lzma_header_magic),
+ const uint32_t crc = lzma_crc32(out + sizeof(lzma_header_magic),
LZMA_STREAM_FLAGS_SIZE, 0);
unaligned_write32le(out + sizeof(lzma_header_magic)
@@ -58,8 +56,6 @@ lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
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);
@@ -77,7 +73,7 @@ lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out)
return LZMA_PROG_ERROR;
// CRC32
- crc = lzma_crc32(
+ const uint32_t crc = lzma_crc32(
out + 4, 4 + LZMA_STREAM_FLAGS_SIZE, 0);
unaligned_write32le(out, crc);
diff --git a/Utilities/cmliblzma/liblzma/common/vli_decoder.c b/Utilities/cmliblzma/liblzma/common/vli_decoder.c
index 1c663844f..c181828bf 100644
--- a/Utilities/cmliblzma/liblzma/common/vli_decoder.c
+++ b/Utilities/cmliblzma/liblzma/common/vli_decoder.c
@@ -14,8 +14,8 @@
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,
+lzma_vli_decode(lzma_vli *restrict vli, size_t *vli_pos,
+ const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size)
{
// If we haven't been given vli_pos, work in single-call mode.
diff --git a/Utilities/cmliblzma/liblzma/common/vli_encoder.c b/Utilities/cmliblzma/liblzma/common/vli_encoder.c
index 09e90cbd7..f8642694e 100644
--- a/Utilities/cmliblzma/liblzma/common/vli_encoder.c
+++ b/Utilities/cmliblzma/liblzma/common/vli_encoder.c
@@ -15,7 +15,7 @@
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,
+ uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size)
{
// If we haven't been given vli_pos, work in single-call mode.
diff --git a/Utilities/cmliblzma/liblzma/common/vli_size.c b/Utilities/cmliblzma/liblzma/common/vli_size.c
index 8b931e40b..ec1b4fa48 100644
--- a/Utilities/cmliblzma/liblzma/common/vli_size.c
+++ b/Utilities/cmliblzma/liblzma/common/vli_size.c
@@ -16,11 +16,10 @@
extern LZMA_API(uint32_t)
lzma_vli_size(lzma_vli vli)
{
- uint32_t i = 0;
-
if (vli > LZMA_VLI_MAX)
return 0;
+ uint32_t i = 0;
do {
vli >>= 7;
++i;
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_common.c b/Utilities/cmliblzma/liblzma/delta/delta_common.c
index 803e674a1..4768201d1 100644
--- a/Utilities/cmliblzma/liblzma/delta/delta_common.c
+++ b/Utilities/cmliblzma/liblzma/delta/delta_common.c
@@ -15,8 +15,9 @@
static void
-delta_coder_end(lzma_coder *coder, lzma_allocator *allocator)
+delta_coder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_delta_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder, allocator);
return;
@@ -24,20 +25,21 @@ delta_coder_end(lzma_coder *coder, lzma_allocator *allocator)
extern lzma_ret
-lzma_delta_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_delta_coder_init(lzma_next_coder *next, const 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)
+ lzma_delta_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_delta_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
+
// End function is the same for encoder and decoder.
next->end = &delta_coder_end;
- next->coder->next = LZMA_NEXT_CODER_INIT;
+ coder->next = LZMA_NEXT_CODER_INIT;
}
// Validate the options.
@@ -45,16 +47,15 @@ lzma_delta_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
return LZMA_OPTIONS_ERROR;
// Set the delta distance.
- opt = filters[0].options;
- next->coder->distance = opt->dist;
+ const lzma_options_delta *opt = filters[0].options;
+ coder->distance = opt->dist;
// Initialize the rest of the variables.
- next->coder->pos = 0;
- memzero(next->coder->history, LZMA_DELTA_DIST_MAX);
+ coder->pos = 0;
+ memzero(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);
+ return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}
@@ -68,5 +69,5 @@ lzma_delta_coder_memusage(const void *options)
|| opt->dist > LZMA_DELTA_DIST_MAX)
return UINT64_MAX;
- return sizeof(lzma_coder);
+ return sizeof(lzma_delta_coder);
}
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_decoder.c b/Utilities/cmliblzma/liblzma/delta/delta_decoder.c
index 28df72735..6859afa5c 100644
--- a/Utilities/cmliblzma/liblzma/delta/delta_decoder.c
+++ b/Utilities/cmliblzma/liblzma/delta/delta_decoder.c
@@ -15,12 +15,11 @@
static void
-decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
+decode_buffer(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
{
- size_t i;
const size_t distance = coder->distance;
- for (i = 0; i < size; ++i) {
+ for (size_t i = 0; i < size; ++i) {
buffer[i] += coder->history[(distance + coder->pos) & 0xFF];
coder->history[coder->pos-- & 0xFF] = buffer[i];
}
@@ -28,17 +27,18 @@ decode_buffer(lzma_coder *coder, uint8_t *buffer, size_t size)
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)
+delta_decode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
- const size_t out_start = *out_pos;
- lzma_ret ret;
+ lzma_delta_coder *coder = coder_ptr;
assert(coder->next.code != NULL);
- ret = coder->next.code(coder->next.coder, allocator,
+ 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);
@@ -49,7 +49,7 @@ delta_decode(lzma_coder *coder, lzma_allocator *allocator,
extern lzma_ret
-lzma_delta_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_delta_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
next->code = &delta_decode;
@@ -58,15 +58,14 @@ lzma_delta_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
-lzma_delta_props_decode(void **options, lzma_allocator *allocator,
+lzma_delta_props_decode(void **options, const 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);
+ lzma_options_delta *opt
+ = lzma_alloc(sizeof(lzma_options_delta), allocator);
if (opt == NULL)
return LZMA_MEM_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_decoder.h b/Utilities/cmliblzma/liblzma/delta/delta_decoder.h
index ae89acc59..ad89cc659 100644
--- a/Utilities/cmliblzma/liblzma/delta/delta_decoder.h
+++ b/Utilities/cmliblzma/liblzma/delta/delta_decoder.h
@@ -16,10 +16,11 @@
#include "delta_common.h"
extern lzma_ret lzma_delta_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters);
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters);
extern lzma_ret lzma_delta_props_decode(
- void **options, lzma_allocator *allocator,
+ void **options, const 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
index a39c154f1..384165151 100644
--- a/Utilities/cmliblzma/liblzma/delta/delta_encoder.c
+++ b/Utilities/cmliblzma/liblzma/delta/delta_encoder.c
@@ -18,13 +18,12 @@
/// 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)
+copy_and_encode(lzma_delta_coder *coder,
+ const uint8_t *restrict in, uint8_t *restrict out, size_t size)
{
- size_t i;
const size_t distance = coder->distance;
- for (i = 0; i < size; ++i) {
+ for (size_t i = 0; i < size; ++i) {
const uint8_t tmp = coder->history[
(distance + coder->pos) & 0xFF];
coder->history[coder->pos-- & 0xFF] = in[i];
@@ -36,12 +35,11 @@ copy_and_encode(lzma_coder *coder,
/// 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)
+encode_in_place(lzma_delta_coder *coder, uint8_t *buffer, size_t size)
{
- size_t i;
const size_t distance = coder->distance;
- for (i = 0; i < size; ++i) {
+ for (size_t i = 0; i < size; ++i) {
const uint8_t tmp = coder->history[
(distance + coder->pos) & 0xFF];
coder->history[coder->pos-- & 0xFF] = buffer[i];
@@ -51,11 +49,13 @@ encode_in_place(lzma_coder *coder, uint8_t *buffer, size_t size)
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)
+delta_encode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
+ lzma_delta_coder *coder = coder_ptr;
+
lzma_ret ret;
if (coder->next.code == NULL) {
@@ -86,10 +86,12 @@ delta_encode(lzma_coder *coder, lzma_allocator *allocator,
static lzma_ret
-delta_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+delta_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters_null lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
+ lzma_delta_coder *coder = coder_ptr;
+
// 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.
@@ -99,7 +101,7 @@ delta_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
extern lzma_ret
-lzma_delta_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_delta_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
next->code = &delta_encode;
@@ -111,13 +113,12 @@ lzma_delta_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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;
+ const lzma_options_delta *opt = options;
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
index a447862f2..4ab984785 100644
--- a/Utilities/cmliblzma/liblzma/delta/delta_encoder.h
+++ b/Utilities/cmliblzma/liblzma/delta/delta_encoder.h
@@ -16,7 +16,8 @@
#include "delta_common.h"
extern lzma_ret lzma_delta_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters);
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters);
extern lzma_ret lzma_delta_props_encode(const void *options, uint8_t *out);
diff --git a/Utilities/cmliblzma/liblzma/delta/delta_private.h b/Utilities/cmliblzma/liblzma/delta/delta_private.h
index 62b7fed86..0d6cb3866 100644
--- a/Utilities/cmliblzma/liblzma/delta/delta_private.h
+++ b/Utilities/cmliblzma/liblzma/delta/delta_private.h
@@ -15,7 +15,7 @@
#include "delta_common.h"
-struct lzma_coder_s {
+typedef struct {
/// Next coder in the chain
lzma_next_coder next;
@@ -27,11 +27,11 @@ struct lzma_coder_s {
/// Buffer to hold history of the original data
uint8_t history[LZMA_DELTA_DIST_MAX];
-};
+} lzma_delta_coder;
extern lzma_ret lzma_delta_coder_init(
- lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_next_coder *next, const 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
index 7f11f1a20..9fa489115 100644
--- a/Utilities/cmliblzma/liblzma/liblzma.pc.in
+++ b/Utilities/cmliblzma/liblzma/liblzma.pc.in
@@ -16,4 +16,4 @@ URL: @PACKAGE_URL@
Version: @PACKAGE_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -llzma
-Libs.private: @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
+Libs.private: @PTHREAD_CFLAGS@ @LIBS@
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_decoder.c b/Utilities/cmliblzma/liblzma/lz/lz_decoder.c
index 9fa1bdc3a..c7086440b 100644
--- a/Utilities/cmliblzma/liblzma/lz/lz_decoder.c
+++ b/Utilities/cmliblzma/liblzma/lz/lz_decoder.c
@@ -20,7 +20,7 @@
#include "lz_decoder.h"
-struct lzma_coder_s {
+typedef struct {
/// Dictionary (history buffer)
lzma_dict dict;
@@ -48,7 +48,7 @@ struct lzma_coder_s {
size_t size;
uint8_t buffer[LZMA_BUFFER_SIZE];
} temp;
-};
+} lzma_coder;
static void
@@ -64,22 +64,18 @@ lz_decoder_reset(lzma_coder *coder)
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)
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *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;
+ const size_t 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
@@ -90,13 +86,13 @@ decode_buffer(lzma_coder *coder,
coder->dict.size - coder->dict.pos);
// Call the coder->lz.code() to do the actual decoding.
- ret = coder->lz.code(
+ const lzma_ret 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;
+ const size_t 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);
@@ -129,13 +125,15 @@ decode_buffer(lzma_coder *coder,
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,
+lz_decode(void *coder_ptr,
+ const lzma_allocator *allocator lzma_attribute((__unused__)),
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size,
lzma_action action)
{
+ lzma_coder *coder = coder_ptr;
+
if (coder->next.code == NULL)
return decode_buffer(coder, in, in_pos, in_size,
out, out_pos, out_size);
@@ -143,15 +141,13 @@ lz_decode(lzma_coder *coder,
// 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(
+ const lzma_ret ret = coder->next.code(
coder->next.coder,
allocator, in, in_pos, in_size,
coder->temp.buffer, &coder->temp.size,
@@ -173,7 +169,7 @@ lz_decode(lzma_coder *coder,
return LZMA_OK;
}
- ret = decode_buffer(coder, coder->temp.buffer,
+ const lzma_ret ret = decode_buffer(coder, coder->temp.buffer,
&coder->temp.pos, coder->temp.size,
out, out_pos, out_size);
@@ -190,8 +186,10 @@ lz_decode(lzma_coder *coder,
static void
-lz_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+lz_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_coder *coder = coder_ptr;
+
lzma_next_end(&coder->next, allocator);
lzma_free(coder->dict.buf, allocator);
@@ -206,32 +204,33 @@ lz_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
extern lzma_ret
-lzma_lz_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_lz_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters,
lzma_ret (*lz_init)(lzma_lz_decoder *lz,
- lzma_allocator *allocator, const void *options,
+ const 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)
+ lzma_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
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;
+ coder->dict.buf = NULL;
+ coder->dict.size = 0;
+ coder->lz = LZMA_LZ_DECODER_INIT;
+ 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,
+ lzma_lz_options lz_options;
+ return_if_error(lz_init(&coder->lz, allocator,
filters[0].options, &lz_options));
// If the dictionary size is very small, increase it to 4096 bytes.
@@ -255,14 +254,14 @@ lzma_lz_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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
+ if (coder->dict.size != lz_options.dict_size) {
+ lzma_free(coder->dict.buf, allocator);
+ coder->dict.buf
= lzma_alloc(lz_options.dict_size, allocator);
- if (next->coder->dict.buf == NULL)
+ if (coder->dict.buf == NULL)
return LZMA_MEM_ERROR;
- next->coder->dict.size = lz_options.dict_size;
+ coder->dict.size = lz_options.dict_size;
}
lz_decoder_reset(next->coder);
@@ -275,21 +274,20 @@ lzma_lz_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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,
+ memcpy(coder->dict.buf, lz_options.preset_dict + offset,
copy_size);
- next->coder->dict.pos = copy_size;
- next->coder->dict.full = copy_size;
+ coder->dict.pos = copy_size;
+ 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;
+ coder->next_finished = false;
+ coder->this_finished = false;
+ coder->temp.pos = 0;
+ coder->temp.size = 0;
// Initialize the next filter in the chain, if any.
- return lzma_next_filter_init(&next->coder->next, allocator,
- filters + 1);
+ return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}
@@ -301,7 +299,8 @@ lzma_lz_decoder_memusage(size_t dictionary_size)
extern void
-lzma_lz_decoder_uncompressed(lzma_coder *coder, lzma_vli uncompressed_size)
+lzma_lz_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
{
+ lzma_coder *coder = coder_ptr;
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
index 76011f2ad..754ccf37c 100644
--- a/Utilities/cmliblzma/liblzma/lz/lz_decoder.h
+++ b/Utilities/cmliblzma/liblzma/lz/lz_decoder.h
@@ -53,45 +53,45 @@ typedef struct {
typedef struct {
/// Data specific to the LZ-based decoder
- lzma_coder *coder;
+ void *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);
+ lzma_ret (*code)(void *coder,
+ lzma_dict *restrict dict, const uint8_t *restrict in,
+ size_t *restrict in_pos, size_t in_size);
- void (*reset)(lzma_coder *coder, const void *options);
+ void (*reset)(void *coder, const void *options);
/// Set the uncompressed size
- void (*set_uncompressed)(lzma_coder *coder,
- lzma_vli uncompressed_size);
+ void (*set_uncompressed)(void *coder, lzma_vli uncompressed_size);
/// Free allocated resources
- void (*end)(lzma_coder *coder, lzma_allocator *allocator);
+ void (*end)(void *coder, const lzma_allocator *allocator);
} lzma_lz_decoder;
-static const lzma_lz_decoder LZMA_LZ_DECODER_INIT =
- {
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- };
+#define LZMA_LZ_DECODER_INIT \
+ (lzma_lz_decoder){ \
+ .coder = NULL, \
+ .code = NULL, \
+ .reset = NULL, \
+ .set_uncompressed = NULL, \
+ .end = NULL, \
+ }
extern lzma_ret lzma_lz_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters,
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters,
lzma_ret (*lz_init)(lzma_lz_decoder *lz,
- lzma_allocator *allocator, const void *options,
+ const 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);
+ void *coder, lzma_vli uncompressed_size);
//////////////////////
@@ -151,15 +151,13 @@ dict_repeat(lzma_dict *dict, uint32_t distance, uint32_t *len)
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;
+ const uint32_t copy_pos
+ = dict->pos - distance - 1 + dict->size;
+ uint32_t copy_size = dict->size - copy_pos;
if (copy_size < left) {
memmove(dict->buf + dict->pos, dict->buf + copy_pos,
@@ -202,9 +200,9 @@ dict_put(lzma_dict *dict, uint8_t byte)
/// 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)
+dict_write(lzma_dict *restrict dict, const uint8_t *restrict in,
+ size_t *restrict in_pos, size_t in_size,
+ size_t *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
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder.c b/Utilities/cmliblzma/liblzma/lz/lz_encoder.c
index 1dae924b4..9a74b7c47 100644
--- a/Utilities/cmliblzma/liblzma/lz/lz_encoder.c
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder.c
@@ -20,8 +20,10 @@
# include "lz_encoder_hash_table.h"
#endif
+#include "memcmplen.h"
-struct lzma_coder_s {
+
+typedef struct {
/// LZ-based encoder e.g. LZMA
lzma_lz_encoder lz;
@@ -30,7 +32,7 @@ struct lzma_coder_s {
/// Next coder in the chain
lzma_next_coder next;
-};
+} lzma_coder;
/// \brief Moves the data in the input window to free space for new data
@@ -43,18 +45,16 @@ struct lzma_coder_s {
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);
+ const uint32_t 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;
+ const size_t move_size = mf->write_pos - move_offset;
assert(move_offset + move_size <= mf->size);
@@ -78,12 +78,10 @@ move_window(lzma_mf *mf)
/// 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)
+fill_window(lzma_coder *coder, const 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.
@@ -93,7 +91,8 @@ fill_window(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *in,
// 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;
+ size_t write_pos = coder->mf.write_pos;
+ lzma_ret ret;
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,
@@ -111,6 +110,12 @@ fill_window(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *in,
coder->mf.write_pos = write_pos;
+ // Silence Valgrind. lzma_memcmplen() can read extra bytes
+ // and Valgrind will give warnings if those bytes are uninitialized
+ // because Valgrind cannot see that the values of the uninitialized
+ // bytes are eventually ignored.
+ memzero(coder->mf.buffer + write_pos, LZMA_MEMCMPLEN_EXTRA);
+
// 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
@@ -134,7 +139,7 @@ fill_window(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *in,
&& 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;
+ const uint32_t pending = coder->mf.pending;
coder->mf.pending = 0;
// Rewind read_pos so that the match finder can hash
@@ -152,16 +157,16 @@ fill_window(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *in,
static lzma_ret
-lz_encode(lzma_coder *coder, lzma_allocator *allocator,
- const uint8_t *LZMA_RESTRICT in, size_t *LZMA_RESTRICT in_pos,
+lz_encode(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size,
- uint8_t *LZMA_RESTRICT out, size_t *LZMA_RESTRICT out_pos,
+ uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size, lzma_action action)
{
+ lzma_coder *coder = coder_ptr;
+
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)
@@ -169,7 +174,7 @@ lz_encode(lzma_coder *coder, lzma_allocator *allocator,
in, in_pos, in_size, action));
// Encode
- ret = coder->lz.code(coder->lz.coder,
+ const lzma_ret 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
@@ -185,17 +190,9 @@ lz_encode(lzma_coder *coder, lzma_allocator *allocator,
static bool
-lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
+lz_encoder_prepare(lzma_mf *mf, const 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.
@@ -221,14 +218,14 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
// to size_t.
// - Memory usage calculation needs something too, e.g. use uint64_t
// for mf->size.
- reserve = lz_options->dict_size / 2;
+ uint32_t 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;
+ const uint32_t 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
@@ -298,11 +295,12 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
// 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;
+ const uint32_t hash_bytes = lz_options->match_finder & 0x0F;
if (hash_bytes > mf->nice_len)
return true;
- is_bt = (lz_options->match_finder & 0x10) != 0;
+ const bool is_bt = (lz_options->match_finder & 0x10) != 0;
+ uint32_t hs;
if (hash_bytes == 2) {
hs = 0xFFFF;
@@ -338,25 +336,22 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
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;
+ const uint32_t old_hash_count = mf->hash_count;
+ const uint32_t old_sons_count = mf->sons_count;
+ mf->hash_count = 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) {
+ if (old_hash_count != mf->hash_count
+ || old_sons_count != mf->sons_count) {
lzma_free(mf->hash, allocator);
mf->hash = NULL;
+
+ lzma_free(mf->son, allocator);
+ mf->son = NULL;
}
// Maximum number of match finder cycles
@@ -373,16 +368,23 @@ lz_encoder_prepare(lzma_mf *mf, lzma_allocator *allocator,
static bool
-lz_encoder_init(lzma_mf *mf, lzma_allocator *allocator,
+lz_encoder_init(lzma_mf *mf, const 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);
+ // lzma_memcmplen() is used for the dictionary buffer
+ // so we need to allocate a few extra bytes to prevent
+ // it from reading past the end of the buffer.
+ mf->buffer = lzma_alloc(mf->size + LZMA_MEMCMPLEN_EXTRA,
+ allocator);
if (mf->buffer == NULL)
return true;
+
+ // Keep Valgrind happy with lzma_memcmplen() and initialize
+ // the extra bytes whose value may get read but which will
+ // effectively get ignored.
+ memzero(mf->buffer + mf->size, LZMA_MEMCMPLEN_EXTRA);
}
// Use cyclic_size as initial mf->offset. This allows
@@ -396,43 +398,48 @@ lz_encoder_init(lzma_mf *mf, lzma_allocator *allocator,
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))
+ if (mf->hash_count > SIZE_MAX / sizeof(uint32_t)
+ || mf->sons_count > SIZE_MAX / sizeof(uint32_t))
return true;
#endif
+ // Allocate and initialize the hash table. Since EMPTY_HASH_VALUE
+ // is zero, we can use lzma_alloc_zero() or memzero() for mf->hash.
+ //
+ // We don't need to initialize mf->son, but not doing that may
+ // make Valgrind complain in normalization (see normalize() in
+ // lz_encoder_mf.c). Skipping the initialization is *very* good
+ // when big dictionary is used but only small amount of data gets
+ // actually compressed: most of the mf->son won't get actually
+ // allocated by the kernel, so we avoid wasting RAM and improve
+ // initialization speed a lot.
if (mf->hash == NULL) {
- mf->hash = lzma_alloc(alloc_count * sizeof(uint32_t),
+ mf->hash = lzma_alloc_zero(mf->hash_count * sizeof(uint32_t),
+ allocator);
+ mf->son = lzma_alloc(mf->sons_count * sizeof(uint32_t),
allocator);
- if (mf->hash == NULL)
- return true;
- }
- mf->son = mf->hash + mf->hash_size_sum;
- mf->cyclic_pos = 0;
+ if (mf->hash == NULL || mf->son == NULL) {
+ lzma_free(mf->hash, allocator);
+ mf->hash = NULL;
+
+ lzma_free(mf->son, allocator);
+ mf->son = NULL;
- // Initialize the hash table. Since EMPTY_HASH_VALUE is zero, we
- // can use memset().
+ return true;
+ }
+ } else {
/*
- for (uint32_t i = 0; i < hash_size_sum; ++i)
- mf->hash[i] = EMPTY_HASH_VALUE;
+ for (uint32_t i = 0; i < mf->hash_count; ++i)
+ mf->hash[i] = EMPTY_HASH_VALUE;
*/
- memzero(mf->hash, (size_t)(mf->hash_size_sum) * sizeof(uint32_t));
+ memzero(mf->hash, mf->hash_count * 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));
+ mf->cyclic_pos = 0;
// Handle preset dictionary.
if (lz_options->preset_dict != NULL
@@ -457,24 +464,32 @@ 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 };
+ lzma_mf mf = {
+ .buffer = NULL,
+ .hash = NULL,
+ .son = NULL,
+ .hash_count = 0,
+ .sons_count = 0,
+ };
// 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);
+ return ((uint64_t)(mf.hash_count) + mf.sons_count) * sizeof(uint32_t)
+ + mf.size + sizeof(lzma_coder);
}
static void
-lz_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+lz_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_coder *coder = coder_ptr;
+
lzma_next_end(&coder->next, allocator);
+ lzma_free(coder->mf.son, allocator);
lzma_free(coder->mf.hash, allocator);
lzma_free(coder->mf.buffer, allocator);
@@ -489,10 +504,12 @@ lz_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-lz_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
+lz_encoder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters_null lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
+ lzma_coder *coder = coder_ptr;
+
if (coder->lz.options_update == NULL)
return LZMA_PROG_ERROR;
@@ -505,58 +522,63 @@ lz_encoder_update(lzma_coder *coder, lzma_allocator *allocator,
extern lzma_ret
-lzma_lz_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_lz_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters,
lzma_ret (*lz_init)(lzma_lz_encoder *lz,
- lzma_allocator *allocator, const void *options,
+ const 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)
+ lzma_coder *coder = next->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
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;
+ coder->lz.coder = NULL;
+ coder->lz.code = NULL;
+ coder->lz.end = NULL;
+
+ // mf.size is initialized to silence Valgrind
+ // when used on optimized binaries (GCC may reorder
+ // code in a way that Valgrind gets unhappy).
+ coder->mf.buffer = NULL;
+ coder->mf.size = 0;
+ coder->mf.hash = NULL;
+ coder->mf.son = NULL;
+ coder->mf.hash_count = 0;
+ coder->mf.sons_count = 0;
+
+ coder->next = LZMA_NEXT_CODER_INIT;
}
// Initialize the LZ-based encoder.
- return_if_error(lz_init(&next->coder->lz, allocator,
+ lzma_lz_options lz_options;
+ return_if_error(lz_init(&coder->lz, allocator,
filters[0].options, &lz_options));
- // Setup the size information into next->coder->mf and deallocate
+ // Setup the size information into coder->mf and deallocate
// old buffers if they have wrong size.
- if (lz_encoder_prepare(&next->coder->mf, allocator, &lz_options))
+ if (lz_encoder_prepare(&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))
+ if (lz_encoder_init(&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);
+ return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder.h b/Utilities/cmliblzma/liblzma/lz/lz_encoder.h
index dcb4b2c5b..426dcd8a3 100644
--- a/Utilities/cmliblzma/liblzma/lz/lz_encoder.h
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder.h
@@ -119,7 +119,7 @@ struct lzma_mf_s {
lzma_action action;
/// Number of elements in hash[]
- uint32_t hash_size_sum;
+ uint32_t hash_count;
/// Number of elements in son[]
uint32_t sons_count;
@@ -191,19 +191,18 @@ typedef struct {
typedef struct {
/// Data specific to the LZ-based encoder
- lzma_coder *coder;
+ void *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);
+ lzma_ret (*code)(void *coder,
+ lzma_mf *restrict mf, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size);
/// Free allocated resources
- void (*end)(lzma_coder *coder, lzma_allocator *allocator);
+ void (*end)(void *coder, const lzma_allocator *allocator);
/// Update the options in the middle of the encoding.
- lzma_ret (*options_update)(lzma_coder *coder,
- const lzma_filter *filter);
+ lzma_ret (*options_update)(void *coder, const lzma_filter *filter);
} lzma_lz_encoder;
@@ -218,7 +217,7 @@ typedef struct {
/// Get pointer to the first byte not ran through the match finder
-static inline uint8_t *
+static inline const uint8_t *
mf_ptr(const lzma_mf *mf)
{
return mf->buffer + mf->read_pos;
@@ -296,10 +295,10 @@ mf_read(lzma_mf *mf, uint8_t *out, size_t *out_pos, size_t out_size,
extern lzma_ret lzma_lz_encoder_init(
- lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters,
lzma_ret (*lz_init)(lzma_lz_encoder *lz,
- lzma_allocator *allocator, const void *options,
+ const lzma_allocator *allocator, const void *options,
lzma_lz_options *lz_options));
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h b/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h
index de17c54fc..342a333d1 100644
--- a/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder_hash.h
@@ -39,22 +39,25 @@
// 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)
+ const uint32_t hash_value = *(const uint16_t *)(cur)
#else
# define hash_2_calc() \
- hash_value = (uint32_t)(cur[0]) | ((uint32_t)(cur[1]) << 8)
+ const uint32_t 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
+ const uint32_t temp = hash_table[cur[0]] ^ cur[1]; \
+ const uint32_t hash_2_value = temp & HASH_2_MASK; \
+ const uint32_t 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) \
+ 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_value = (temp ^ ((uint32_t)(cur[2]) << 8) \
^ (hash_table[cur[3]] << 5)) & mf->hash_mask
diff --git a/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c b/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c
index 50c3459aa..78520779f 100644
--- a/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c
+++ b/Utilities/cmliblzma/liblzma/lz/lz_encoder_mf.c
@@ -13,6 +13,7 @@
#include "lz_encoder.h"
#include "lz_encoder_hash.h"
+#include "memcmplen.h"
/// \brief Find matches starting from the current byte
@@ -32,9 +33,8 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
if (count > 0) {
#ifndef NDEBUG
- uint32_t i;
// Validate the matches.
- for (i = 0; i < count; ++i) {
+ for (uint32_t 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,
@@ -50,9 +50,6 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
// 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
@@ -63,15 +60,13 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
// Pointer to the byte we just ran through
// the match finder.
- p1 = mf_ptr(mf) - 1;
+ const uint8_t *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;
+ const uint8_t *p2 = p1 - matches[count - 1].dist - 1;
- while (len_best < limit
- && p1[len_best] == p2[len_best])
- ++len_best;
+ len_best = lzma_memcmplen(p1, p2, len_best, limit);
}
}
@@ -112,36 +107,35 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
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);
+ const uint32_t 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) {
+ for (uint32_t i = 0; i < mf->hash_count; ++i) {
// If the distance is greater than the dictionary size,
// we can simply mark the hash element as empty.
+ if (mf->hash[i] <= subvalue)
+ mf->hash[i] = EMPTY_HASH_VALUE;
+ else
+ mf->hash[i] -= subvalue;
+ }
+
+ for (uint32_t i = 0; i < mf->sons_count; ++i) {
+ // Do the same for mf->son.
//
- // 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;
+ // NOTE: There may be uninitialized elements in mf->son.
+ // Valgrind may complain that the "if" below depends on
+ // an 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 (mf->son[i] <= subvalue)
+ mf->son[i] = EMPTY_HASH_VALUE;
else
- hash[i] -= subvalue;
+ mf->son[i] -= subvalue;
}
// Update offset to match the new locations.
@@ -204,14 +198,15 @@ move_pending(lzma_mf *mf)
move_pending(mf); \
ret_op; \
} \
- cur = mf_ptr(mf); \
- pos = mf->read_pos + mf->offset
+ const uint8_t *cur = mf_ptr(mf); \
+ const uint32_t 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(is_bt, len_min, return 0); \
+ uint32_t matches_count = 0
/// Header for a loop in a skip function. "continue" tells to skip the rest
@@ -268,19 +263,15 @@ hc_find_func(
while (true) {
const uint32_t delta = pos - cur_match;
- const uint8_t *pb;
if (depth-- == 0 || delta >= cyclic_size)
return matches;
- pb = cur - delta;
+ const uint8_t *const 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;
+ uint32_t len = lzma_memcmplen(pb, cur, 1, len_limit);
if (len_best < len) {
len_best = len;
@@ -313,27 +304,21 @@ do { \
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];
+ const uint32_t delta2 = pos - mf->hash[hash_2_value];
+ const uint32_t 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;
+ uint32_t len_best = 2;
+
if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
- for ( ; len_best != len_limit; ++len_best)
- if (*(cur + len_best - delta2) != cur[len_best])
- break;
+ len_best = lzma_memcmplen(cur - delta2, cur,
+ len_best, len_limit);
matches[0].len = len_best;
matches[0].dist = delta2 - 1;
@@ -353,22 +338,18 @@ 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;
+ const uint8_t *cur = mf_ptr(mf);
+ const uint32_t pos = mf->read_pos + mf->offset;
hash_3_calc();
- cur_match = mf->hash[FIX_3_HASH_SIZE + hash_value];
+ const uint32_t 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;
@@ -384,25 +365,21 @@ lzma_mf_hc3_skip(lzma_mf *mf, uint32_t amount)
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];
+ uint32_t delta2 = pos - mf->hash[hash_2_value];
+ const uint32_t delta3
+ = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value];
+ const uint32_t 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;
+ uint32_t len_best = 1;
+
if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
len_best = 2;
matches[0].len = 2;
@@ -418,9 +395,8 @@ lzma_mf_hc4_find(lzma_mf *mf, lzma_match *matches)
}
if (matches_count != 0) {
- for ( ; len_best != len_limit; ++len_best)
- if (*(cur + len_best - delta2) != cur[len_best])
- break;
+ len_best = lzma_memcmplen(cur - delta2, cur,
+ len_best, len_limit);
matches[matches_count - 1].len = len_best;
@@ -441,22 +417,18 @@ 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;
+ const uint8_t *cur = mf_ptr(mf);
+ const uint32_t pos = mf->read_pos + mf->offset;
hash_4_calc();
- cur_match = mf->hash[FIX_4_HASH_SIZE + hash_value];
+ const uint32_t 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;
@@ -494,10 +466,6 @@ bt_find_func(
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;
@@ -505,17 +473,15 @@ bt_find_func(
return matches;
}
- pair = son + ((cyclic_pos - delta
+ uint32_t *const pair = son + ((cyclic_pos - delta
+ (delta > cyclic_pos ? cyclic_size : 0))
<< 1);
- pb = cur - delta;
- len = my_min(len0, len1);
+ const uint8_t *const pb = cur - delta;
+ uint32_t len = my_min(len0, len1);
if (pb[len] == cur[len]) {
- while (++len != len_limit)
- if (pb[len] != cur[len])
- break;
+ len = lzma_memcmplen(pb, cur, len + 1, len_limit);
if (len_best < len) {
len_best = len;
@@ -564,10 +530,6 @@ bt_skip_func(
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;
@@ -575,16 +537,14 @@ bt_skip_func(
return;
}
- pair = son + ((cyclic_pos - delta
+ uint32_t *pair = son + ((cyclic_pos - delta
+ (delta > cyclic_pos ? cyclic_size : 0))
<< 1);
- pb = cur - delta;
- len = my_min(len0, len1);
+ const uint8_t *pb = cur - delta;
+ uint32_t len = my_min(len0, len1);
if (pb[len] == cur[len]) {
- while (++len != len_limit)
- if (pb[len] != cur[len])
- break;
+ len = lzma_memcmplen(pb, cur, len + 1, len_limit);
if (len == len_limit) {
*ptr1 = pair[0];
@@ -626,17 +586,11 @@ do { \
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];
+ const uint32_t cur_match = mf->hash[hash_value];
mf->hash[hash_value] = pos;
bt_find(1);
@@ -647,16 +601,11 @@ 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];
+ const uint32_t cur_match = mf->hash[hash_value];
mf->hash[hash_value] = pos;
bt_skip();
@@ -670,27 +619,21 @@ lzma_mf_bt2_skip(lzma_mf *mf, uint32_t amount)
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];
+ const uint32_t delta2 = pos - mf->hash[hash_2_value];
+ const uint32_t 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;
+ uint32_t len_best = 2;
+
if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
- for ( ; len_best != len_limit; ++len_best)
- if (*(cur + len_best - delta2) != cur[len_best])
- break;
+ len_best = lzma_memcmplen(
+ cur, cur - delta2, len_best, len_limit);
matches[0].len = len_best;
matches[0].dist = delta2 - 1;
@@ -710,16 +653,12 @@ 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];
+ const uint32_t 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;
@@ -735,25 +674,21 @@ lzma_mf_bt3_skip(lzma_mf *mf, uint32_t amount)
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];
+ uint32_t delta2 = pos - mf->hash[hash_2_value];
+ const uint32_t delta3
+ = pos - mf->hash[FIX_3_HASH_SIZE + hash_3_value];
+ const uint32_t 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;
+ uint32_t len_best = 1;
+
if (delta2 < mf->cyclic_size && *(cur - delta2) == *cur) {
len_best = 2;
matches[0].len = 2;
@@ -769,9 +704,8 @@ lzma_mf_bt4_find(lzma_mf *mf, lzma_match *matches)
}
if (matches_count != 0) {
- for ( ; len_best != len_limit; ++len_best)
- if (*(cur + len_best - delta2) != cur[len_best])
- break;
+ len_best = lzma_memcmplen(
+ cur, cur - delta2, len_best, len_limit);
matches[matches_count - 1].len = len_best;
@@ -792,16 +726,12 @@ 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];
+ const uint32_t 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;
diff --git a/Utilities/cmliblzma/liblzma/lzma/fastpos.h b/Utilities/cmliblzma/liblzma/lzma/fastpos.h
index 5a834d68d..a3feea58d 100644
--- a/Utilities/cmliblzma/liblzma/lzma/fastpos.h
+++ b/Utilities/cmliblzma/liblzma/lzma/fastpos.h
@@ -14,15 +14,15 @@
#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
+// LZMA encodes match distances 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 .xz
// 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
+// dist return
// 0 0
// 1 1
// 2 2
@@ -48,10 +48,10 @@
// 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)
+// get_dist_slot(dist) is the basic version. get_dist_slot_2(dist)
+// assumes that dist >= FULL_DISTANCES, thus the result is at least
+// FULL_DISTANCES_BITS * 2. Using get_dist_slot(dist) instead of
+// get_dist_slot_2(dist) would give the same result, but get_dist_slot_2(dist)
// should be tiny bit faster due to the assumption being made.
//
//
@@ -75,16 +75,15 @@
// 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))
+# define get_dist_slot(dist) \
+ ((dist) <= 4 ? (dist) : get_dist_slot_2(dist))
static inline uint32_t
-get_pos_slot_2(uint32_t pos)
+get_dist_slot_2(uint32_t dist)
{
- const uint32_t i = bsr32(pos);
- return (i + i) + ((pos >> (i - 1)) & 1);
+ const uint32_t i = bsr32(dist);
+ return (i + i) + ((dist >> (i - 1)) & 1);
}
@@ -101,39 +100,39 @@ extern const uint8_t lzma_fastpos[1 << FASTPOS_BITS];
#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)] \
+#define fastpos_result(dist, extra, n) \
+ lzma_fastpos[(dist) >> fastpos_shift(extra, n)] \
+ 2 * fastpos_shift(extra, n)
static inline uint32_t
-get_pos_slot(uint32_t pos)
+get_dist_slot(uint32_t dist)
{
// 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 (dist < fastpos_limit(0, 0))
+ return lzma_fastpos[dist];
- if (pos < fastpos_limit(0, 1))
- return fastpos_result(pos, 0, 1);
+ if (dist < fastpos_limit(0, 1))
+ return fastpos_result(dist, 0, 1);
- return fastpos_result(pos, 0, 2);
+ return fastpos_result(dist, 0, 2);
}
#ifdef FULL_DISTANCES_BITS
static inline uint32_t
-get_pos_slot_2(uint32_t pos)
+get_dist_slot_2(uint32_t dist)
{
- assert(pos >= FULL_DISTANCES);
+ assert(dist >= FULL_DISTANCES);
- if (pos < fastpos_limit(FULL_DISTANCES_BITS - 1, 0))
- return fastpos_result(pos, FULL_DISTANCES_BITS - 1, 0);
+ if (dist < fastpos_limit(FULL_DISTANCES_BITS - 1, 0))
+ return fastpos_result(dist, FULL_DISTANCES_BITS - 1, 0);
- if (pos < fastpos_limit(FULL_DISTANCES_BITS - 1, 1))
- return fastpos_result(pos, FULL_DISTANCES_BITS - 1, 1);
+ if (dist < fastpos_limit(FULL_DISTANCES_BITS - 1, 1))
+ return fastpos_result(dist, FULL_DISTANCES_BITS - 1, 1);
- return fastpos_result(pos, FULL_DISTANCES_BITS - 1, 2);
+ return fastpos_result(dist, FULL_DISTANCES_BITS - 1, 2);
}
#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c
index bd2a73782..878c870ae 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.c
@@ -16,7 +16,7 @@
#include "lzma_decoder.h"
-struct lzma_coder_s {
+typedef struct {
enum sequence {
SEQ_CONTROL,
SEQ_UNCOMPRESSED_1,
@@ -50,14 +50,16 @@ struct lzma_coder_s {
bool need_dictionary_reset;
lzma_options_lzma options;
-};
+} lzma_lzma2_coder;
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,
+lzma2_decode(void *coder_ptr, lzma_dict *restrict dict,
+ const uint8_t *restrict in, size_t *restrict in_pos,
size_t in_size)
{
+ lzma_lzma2_coder *restrict coder = coder_ptr;
+
// 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.
@@ -209,8 +211,10 @@ lzma2_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dict,
static void
-lzma2_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
+lzma2_decoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_lzma2_coder *coder = coder_ptr;
+
assert(coder->lzma.end == NULL);
lzma_free(coder->lzma.coder, allocator);
@@ -221,34 +225,36 @@ lzma2_decoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-lzma2_decoder_init(lzma_lz_decoder *lz, lzma_allocator *allocator,
+lzma2_decoder_init(lzma_lz_decoder *lz, const 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)
+ lzma_lzma2_coder *coder = lz->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_lzma2_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ lz->coder = coder;
lz->code = &lzma2_decode;
lz->end = &lzma2_decoder_end;
- lz->coder->lzma = LZMA_LZ_DECODER_INIT;
+ 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
+ const lzma_options_lzma *options = opt;
+
+ coder->sequence = SEQ_CONTROL;
+ coder->need_properties = true;
+ coder->need_dictionary_reset = options->preset_dict == NULL
|| options->preset_dict_size == 0;
- return lzma_lzma_decoder_create(&lz->coder->lzma,
+ return lzma_lzma_decoder_create(&coder->lzma,
allocator, options, lz_options);
}
extern lzma_ret
-lzma_lzma2_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_lzma2_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
// LZMA2 can only be the last filter in the chain. This is enforced
@@ -263,17 +269,15 @@ lzma_lzma2_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern uint64_t
lzma_lzma2_decoder_memusage(const void *options)
{
- return sizeof(lzma_coder)
+ return sizeof(lzma_lzma2_coder)
+ lzma_lzma_decoder_memusage_nocheck(options);
}
extern lzma_ret
-lzma_lzma2_props_decode(void **options, lzma_allocator *allocator,
+lzma_lzma2_props_decode(void **options, const lzma_allocator *allocator,
const uint8_t *props, size_t props_size)
{
- lzma_options_lzma *opt;
-
if (props_size != 1)
return LZMA_OPTIONS_ERROR;
@@ -285,7 +289,8 @@ lzma_lzma2_props_decode(void **options, lzma_allocator *allocator,
if (props[0] > 40)
return LZMA_OPTIONS_ERROR;
- opt = lzma_alloc(sizeof(lzma_options_lzma), allocator);
+ lzma_options_lzma *opt = lzma_alloc(
+ sizeof(lzma_options_lzma), allocator);
if (opt == NULL)
return LZMA_MEM_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h
index fac4ac487..ef2dcbfa7 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_decoder.h
@@ -17,12 +17,13 @@
#include "common.h"
extern lzma_ret lzma_lzma2_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters);
+ const 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,
+ void **options, const 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
index a3651a7c6..63588ee30 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.c
@@ -17,7 +17,7 @@
#include "lzma2_encoder.h"
-struct lzma_coder_s {
+typedef struct {
enum {
SEQ_INIT,
SEQ_LZMA_ENCODE,
@@ -27,7 +27,7 @@ struct lzma_coder_s {
} sequence;
/// LZMA encoder
- lzma_coder *lzma;
+ void *lzma;
/// LZMA options currently in use.
lzma_options_lzma opt_cur;
@@ -48,20 +48,19 @@ struct lzma_coder_s {
/// Buffer to hold the chunk header and LZMA compressed data
uint8_t buf[LZMA2_HEADER_MAX + LZMA2_CHUNK_MAX];
-};
+} lzma_lzma2_coder;
static void
-lzma2_header_lzma(lzma_coder *coder)
+lzma2_header_lzma(lzma_lzma2_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);
+ size_t pos;
+
if (coder->need_properties) {
pos = 0;
@@ -82,7 +81,7 @@ lzma2_header_lzma(lzma_coder *coder)
coder->buf_pos = pos;
// Uncompressed size
- size = coder->uncompressed_size - 1;
+ size_t size = coder->uncompressed_size - 1;
coder->buf[pos++] += size >> 16;
coder->buf[pos++] = (size >> 8) & 0xFF;
coder->buf[pos++] = size & 0xFF;
@@ -109,7 +108,7 @@ lzma2_header_lzma(lzma_coder *coder)
static void
-lzma2_header_uncompressed(lzma_coder *coder)
+lzma2_header_uncompressed(lzma_lzma2_coder *coder)
{
assert(coder->uncompressed_size > 0);
assert(coder->uncompressed_size <= LZMA2_CHUNK_MAX);
@@ -134,10 +133,12 @@ lzma2_header_uncompressed(lzma_coder *coder)
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,
+lzma2_encode(void *coder_ptr, lzma_mf *restrict mf,
+ uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size)
{
+ lzma_lzma2_coder *restrict coder = coder_ptr;
+
while (*out_pos < out_size)
switch (coder->sequence) {
case SEQ_INIT:
@@ -163,9 +164,6 @@ lzma2_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
// 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
@@ -186,10 +184,10 @@ lzma2_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
// Save the start position so that we can update
// coder->uncompressed_size.
- read_start = mf->read_pos - mf->read_ahead;
+ const uint32_t read_start = mf->read_pos - mf->read_ahead;
// Call the LZMA encoder until the chunk is finished.
- ret = lzma_lzma_encode(coder->lzma, mf,
+ const lzma_ret ret = lzma_lzma_encode(coder->lzma, mf,
coder->buf + LZMA2_HEADER_MAX,
&coder->compressed_size,
LZMA2_CHUNK_MAX, limit);
@@ -266,8 +264,9 @@ lzma2_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
static void
-lzma2_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
+lzma2_encoder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_lzma2_coder *coder = coder_ptr;
lzma_free(coder->lzma, allocator);
lzma_free(coder, allocator);
return;
@@ -275,9 +274,9 @@ lzma2_encoder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-lzma2_encoder_options_update(lzma_coder *coder, const lzma_filter *filter)
+lzma2_encoder_options_update(void *coder_ptr, const lzma_filter *filter)
{
- lzma_options_lzma *opt;
+ lzma_lzma2_coder *coder = coder_ptr;
// 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
@@ -287,7 +286,7 @@ lzma2_encoder_options_update(lzma_coder *coder, const lzma_filter *filter)
// Look if there are new options. At least for now,
// only lc/lp/pb can be changed.
- opt = filter->options;
+ const lzma_options_lzma *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.
@@ -310,36 +309,38 @@ lzma2_encoder_options_update(lzma_coder *coder, const lzma_filter *filter)
static lzma_ret
-lzma2_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
+lzma2_encoder_init(lzma_lz_encoder *lz, const 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)
+ lzma_lzma2_coder *coder = lz->coder;
+ if (coder == NULL) {
+ coder = lzma_alloc(sizeof(lzma_lzma2_coder), allocator);
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ lz->coder = coder;
lz->code = &lzma2_encode;
lz->end = &lzma2_encoder_end;
lz->options_update = &lzma2_encoder_options_update;
- lz->coder->lzma = NULL;
+ coder->lzma = NULL;
}
- lz->coder->opt_cur = *(const lzma_options_lzma *)(options);
+ 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;
+ coder->sequence = SEQ_INIT;
+ coder->need_properties = true;
+ coder->need_state_reset = false;
+ coder->need_dictionary_reset
+ = coder->opt_cur.preset_dict == NULL
+ || 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));
+ return_if_error(lzma_lzma_encoder_create(&coder->lzma, allocator,
+ &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
@@ -355,7 +356,7 @@ lzma2_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
extern lzma_ret
-lzma_lzma2_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_lzma2_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
return lzma_lz_encoder_init(
@@ -370,7 +371,7 @@ lzma_lzma2_encoder_memusage(const void *options)
if (lzma_mem == UINT64_MAX)
return UINT64_MAX;
- return sizeof(lzma_coder) + lzma_mem;
+ return sizeof(lzma_lzma2_coder) + lzma_mem;
}
@@ -393,7 +394,17 @@ lzma_lzma2_props_encode(const void *options, uint8_t *out)
if (d == UINT32_MAX)
out[0] = 40;
else
- out[0] = get_pos_slot(d + 1) - 24;
+ out[0] = get_dist_slot(d + 1) - 24;
return LZMA_OK;
}
+
+
+extern uint64_t
+lzma_lzma2_block_size(const void *options)
+{
+ const lzma_options_lzma *const opt = options;
+
+ // Use at least 1 MiB to keep compression ratio better.
+ return my_max((uint64_t)(opt->dict_size) * 3, UINT64_C(1) << 20);
+}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h
index ca19ef469..515f18393 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma2_encoder.h
@@ -31,11 +31,13 @@
extern lzma_ret lzma_lzma2_encoder_init(
- lzma_next_coder *next, lzma_allocator *allocator,
+ lzma_next_coder *next, const 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);
+extern uint64_t lzma_lzma2_block_size(const void *options);
+
#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_common.h b/Utilities/cmliblzma/liblzma/lzma/lzma_common.h
index 36267dc88..09efd3872 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_common.h
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_common.h
@@ -129,15 +129,12 @@ 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);
+ const uint32_t coders = 1U << (lc + lp);
- for (i = 0; i < coders; ++i)
- for (j = 0; j < LITERAL_CODER_SIZE; ++j)
+ for (uint32_t i = 0; i < coders; ++i)
+ for (uint32_t j = 0; j < LITERAL_CODER_SIZE; ++j)
bit_reset(probs[i][j]);
return;
@@ -174,53 +171,54 @@ literal_init(probability (*probs)[LITERAL_CODER_SIZE],
// Match distance //
////////////////////
-// Different set of probabilities is used for match distances that have very
+// Different sets of probabilities are 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
+#define DIST_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 \
+#define get_dist_state(len) \
+ ((len) < DIST_STATES + MATCH_LEN_MIN \
? (len) - MATCH_LEN_MIN \
- : LEN_TO_POS_STATES - 1)
+ : DIST_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)
+// The highest two bits of a match distance (distance slot) are encoded
+// using six bits. See fastpos.h for more explanation.
+#define DIST_SLOT_BITS 6
+#define DIST_SLOTS (1 << DIST_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
+// the highest two bits (distance slot) are always encoded using six bits,
+// the distances 0-3 don't need any additional bits to encode, since the
+// distance slot itself is the same as the actual distance. DIST_MODEL_START
+// indicates the first distance slot where at least one additional bit is
+// needed.
+#define DIST_MODEL_START 4
// Match distances greater than 127 are encoded in three pieces:
-// - pos slot: the highest two bits
+// - distance 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
+// The distance slot value of 14 is for distances 128-191 (see the table in
// fastpos.h to understand why).
-#define END_POS_MODEL_INDEX 14
+#define DIST_MODEL_END 14
-// Pos slots that indicate a distance <= 127.
-#define FULL_DISTANCES_BITS (END_POS_MODEL_INDEX / 2)
+// Distance slots that indicate a distance <= 127.
+#define FULL_DISTANCES_BITS (DIST_MODEL_END / 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)
+#define ALIGN_SIZE (1 << ALIGN_BITS)
+#define ALIGN_MASK (ALIGN_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
+#define REPS 4
#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
index 3c0f39331..d0f29b763 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.c
@@ -16,6 +16,12 @@
#include "lzma_decoder.h"
#include "range_decoder.h"
+// The macros unroll loops with switch statements.
+// Silence warnings about missing fall-through comments.
+#if TUKLIB_GNUC_REQ(7, 0)
+# pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#endif
+
#ifdef HAVE_SMALL
@@ -114,33 +120,33 @@ do { \
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); \
+ rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW0); \
+ rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW1); \
+ rc_bit_case(ld.low[pos_state][symbol], , , 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, \
+ rc_bit_case(ld.mid[pos_state][symbol], , , \
seq ## _MID0); \
- rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
+ rc_bit_case(ld.mid[pos_state][symbol], , , \
seq ## _MID1); \
- rc_bit_case(ld.mid[pos_state][symbol], 0, 0, \
+ rc_bit_case(ld.mid[pos_state][symbol], , , \
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); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH0); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH1); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH2); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH3); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH4); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH5); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH6); \
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH7); \
target = symbol - LEN_HIGH_SYMBOLS \
+ MATCH_LEN_MIN \
+ LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS; \
@@ -161,7 +167,7 @@ typedef struct {
} lzma_length_decoder;
-struct lzma_coder_s {
+typedef struct {
///////////////////
// Probabilities //
///////////////////
@@ -193,15 +199,15 @@ struct lzma_coder_s {
/// 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 dist_slot[DIST_STATES][DIST_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 pos_special[FULL_DISTANCES - DIST_MODEL_END];
/// 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];
+ probability pos_align[ALIGN_SIZE];
/// Length of a normal match
lzma_length_decoder match_len_decoder;
@@ -245,8 +251,8 @@ struct lzma_coder_s {
SEQ_LITERAL_WRITE,
SEQ_IS_REP,
seq_len(SEQ_MATCH_LEN),
- seq_6(SEQ_POS_SLOT),
- SEQ_POS_MODEL,
+ seq_6(SEQ_DIST_SLOT),
+ SEQ_DIST_MODEL,
SEQ_DIRECT,
seq_4(SEQ_ALIGN),
SEQ_EOPM,
@@ -277,14 +283,27 @@ struct lzma_coder_s {
/// If decoding a literal: match byte.
/// If decoding a match: length of the match.
uint32_t len;
-};
+} lzma_lzma1_decoder;
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)
+lzma_decode(void *coder_ptr, lzma_dict *restrict dictptr,
+ const uint8_t *restrict in,
+ size_t *restrict in_pos, size_t in_size)
{
+ lzma_lzma1_decoder *restrict coder = coder_ptr;
+
+ ////////////////////
+ // Initialization //
+ ////////////////////
+
+ {
+ const lzma_ret ret = rc_read_init(
+ &coder->rc, in, in_pos, in_size);
+ if (ret != LZMA_STREAM_END)
+ return ret;
+ }
+
///////////////
// Variables //
///////////////
@@ -331,16 +350,6 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
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)
@@ -356,21 +365,6 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
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.
@@ -388,21 +382,16 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
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);
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL0);
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL1);
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL2);
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL3);
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL4);
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL5);
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL6);
+ rc_bit_case(probs[symbol], , , 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
@@ -441,6 +430,8 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
} while (symbol < (1 << 8));
#else
// Unroll the loop.
+ uint32_t match_bit;
+ uint32_t subcoder_index;
# define d(seq) \
case seq: \
@@ -474,6 +465,20 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
// Use a lookup table to update to literal state,
// since compared to other state updates, this would
// need two branches.
+ 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
+ };
state = next_state[state];
case SEQ_LITERAL_WRITE:
@@ -509,28 +514,28 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
// Prepare to decode the highest two bits of the
// match distance.
- probs = coder->pos_slot[get_len_to_pos_state(len)];
+ probs = coder->dist_slot[get_dist_state(len)];
symbol = 1;
#ifdef HAVE_SMALL
- case SEQ_POS_SLOT:
+ case SEQ_DIST_SLOT:
do {
- rc_bit(probs[symbol], , , SEQ_POS_SLOT);
- } while (symbol < POS_SLOTS);
+ rc_bit(probs[symbol], , , SEQ_DIST_SLOT);
+ } while (symbol < DIST_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);
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT0);
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT1);
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT2);
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT3);
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT4);
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT5);
#endif
// Get rid of the highest bit that was needed for
// indexing of the probability array.
- symbol -= POS_SLOTS;
+ symbol -= DIST_SLOTS;
assert(symbol <= 63);
- if (symbol < START_POS_MODEL_INDEX) {
+ if (symbol < DIST_MODEL_START) {
// Match distances [0, 3] have only two bits.
rep0 = symbol;
} else {
@@ -540,7 +545,7 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
assert(limit >= 1 && limit <= 30);
rep0 = 2 + (symbol & 1);
- if (symbol < END_POS_MODEL_INDEX) {
+ if (symbol < DIST_MODEL_END) {
// Prepare to decode the low bits for
// a distance of [4, 127].
assert(limit <= 5);
@@ -560,38 +565,38 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
- symbol - 1;
symbol = 1;
offset = 0;
- case SEQ_POS_MODEL:
+ case SEQ_DIST_MODEL:
#ifdef HAVE_SMALL
do {
rc_bit(probs[symbol], ,
rep0 += 1 << offset,
- SEQ_POS_MODEL);
+ SEQ_DIST_MODEL);
} while (++offset < limit);
#else
switch (limit) {
case 5:
assert(offset == 0);
- rc_bit(probs[symbol], 0,
+ rc_bit(probs[symbol], ,
rep0 += 1,
- SEQ_POS_MODEL);
+ SEQ_DIST_MODEL);
++offset;
--limit;
case 4:
- rc_bit(probs[symbol], 0,
+ rc_bit(probs[symbol], ,
rep0 += 1 << offset,
- SEQ_POS_MODEL);
+ SEQ_DIST_MODEL);
++offset;
--limit;
case 3:
- rc_bit(probs[symbol], 0,
+ rc_bit(probs[symbol], ,
rep0 += 1 << offset,
- SEQ_POS_MODEL);
+ SEQ_DIST_MODEL);
++offset;
--limit;
case 2:
- rc_bit(probs[symbol], 0,
+ rc_bit(probs[symbol], ,
rep0 += 1 << offset,
- SEQ_POS_MODEL);
+ SEQ_DIST_MODEL);
++offset;
--limit;
case 1:
@@ -601,9 +606,9 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
// rc_bit_last() here to omit
// the unneeded updating of
// "symbol".
- rc_bit_last(probs[symbol], 0,
+ rc_bit_last(probs[symbol], ,
rep0 += 1 << offset,
- SEQ_POS_MODEL);
+ SEQ_DIST_MODEL);
}
#endif
} else {
@@ -635,19 +640,19 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
} while (++offset < ALIGN_BITS);
#else
case SEQ_ALIGN0:
- rc_bit(coder->pos_align[symbol], 0,
+ rc_bit(coder->pos_align[symbol], ,
rep0 += 1, SEQ_ALIGN0);
case SEQ_ALIGN1:
- rc_bit(coder->pos_align[symbol], 0,
+ rc_bit(coder->pos_align[symbol], ,
rep0 += 2, SEQ_ALIGN1);
case SEQ_ALIGN2:
- rc_bit(coder->pos_align[symbol], 0,
+ rc_bit(coder->pos_align[symbol], ,
rep0 += 4, SEQ_ALIGN2);
case SEQ_ALIGN3:
- // Like in SEQ_POS_MODEL, we don't
+ // Like in SEQ_DIST_MODEL, we don't
// need "symbol" for anything else
// than indexing the probability array.
- rc_bit_last(coder->pos_align[symbol], 0,
+ rc_bit_last(coder->pos_align[symbol], ,
rep0 += 8, SEQ_ALIGN3);
#endif
@@ -732,11 +737,9 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
// 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;
+ const uint32_t distance = rep1;
rep1 = rep0;
rep0 = distance;
@@ -745,23 +748,19 @@ lzma_decode(lzma_coder *LZMA_RESTRICT coder, lzma_dict *LZMA_RESTRICT dictptr,
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;
+ const uint32_t distance = rep2;
rep2 = rep1;
rep1 = rep0;
rep0 = distance;
} else {
- uint32_t distance;
-
rc_update_1(coder->is_rep2[
state]);
- distance = rep3;
+ const uint32_t distance = rep3;
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
@@ -849,26 +848,17 @@ out:
static void
-lzma_decoder_uncompressed(lzma_coder *coder, lzma_vli uncompressed_size)
+lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
{
+ lzma_lzma1_decoder *coder = coder_ptr;
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)
+lzma_decoder_reset(void *coder_ptr, const void *opt)
{
- uint32_t i, j, pos_state;
- uint32_t num_pos_states;
-
+ lzma_lzma1_decoder *coder = coder_ptr;
const lzma_options_lzma *options = opt;
// NOTE: We assume that lc/lp/pb are valid since they were
@@ -895,8 +885,8 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
rc_reset(coder->rc);
// Bit and bittree decoders
- for (i = 0; i < STATES; ++i) {
- for (j = 0; j <= coder->pos_mask; ++j) {
+ for (uint32_t i = 0; i < STATES; ++i) {
+ for (uint32_t j = 0; j <= coder->pos_mask; ++j) {
bit_reset(coder->is_match[i][j]);
bit_reset(coder->is_rep0_long[i][j]);
}
@@ -907,22 +897,22 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
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 (uint32_t i = 0; i < DIST_STATES; ++i)
+ bittree_reset(coder->dist_slot[i], DIST_SLOT_BITS);
- for (i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
+ for (uint32_t i = 0; i < FULL_DISTANCES - DIST_MODEL_END; ++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;
+ const uint32_t 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) {
+ for (uint32_t 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],
@@ -949,13 +939,11 @@ lzma_decoder_reset(lzma_coder *coder, const void *opt)
extern lzma_ret
-lzma_lzma_decoder_create(lzma_lz_decoder *lz, lzma_allocator *allocator,
+lzma_lzma_decoder_create(lzma_lz_decoder *lz, const 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);
+ lz->coder = lzma_alloc(sizeof(lzma_lzma1_decoder), allocator);
if (lz->coder == NULL)
return LZMA_MEM_ERROR;
@@ -966,6 +954,7 @@ lzma_lzma_decoder_create(lzma_lz_decoder *lz, lzma_allocator *allocator,
// All dictionary sizes are OK here. LZ decoder will take care of
// the special cases.
+ const lzma_options_lzma *options = opt;
lz_options->dict_size = options->dict_size;
lz_options->preset_dict = options->preset_dict;
lz_options->preset_dict_size = options->preset_dict_size;
@@ -978,7 +967,7 @@ lzma_lzma_decoder_create(lzma_lz_decoder *lz, lzma_allocator *allocator,
/// 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,
+lzma_decoder_init(lzma_lz_decoder *lz, const lzma_allocator *allocator,
const void *options, lzma_lz_options *lz_options)
{
if (!is_lclppb_valid(options))
@@ -995,7 +984,7 @@ lzma_decoder_init(lzma_lz_decoder *lz, lzma_allocator *allocator,
extern lzma_ret
-lzma_lzma_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_lzma_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
// LZMA can only be the last filter in the chain. This is enforced
@@ -1027,7 +1016,8 @@ 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);
+ return sizeof(lzma_lzma1_decoder)
+ + lzma_lz_decoder_memusage(opt->dict_size);
}
@@ -1042,15 +1032,14 @@ lzma_lzma_decoder_memusage(const void *options)
extern lzma_ret
-lzma_lzma_props_decode(void **options, lzma_allocator *allocator,
+lzma_lzma_props_decode(void **options, const 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);
+ lzma_options_lzma *opt
+ = lzma_alloc(sizeof(lzma_options_lzma), allocator);
if (opt == NULL)
return LZMA_MEM_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h
index a463a76fc..fa8ecb23e 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_decoder.h
@@ -19,12 +19,13 @@
/// Allocates and initializes LZMA decoder
extern lzma_ret lzma_lzma_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters);
+ const 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,
+ void **options, const lzma_allocator *allocator,
const uint8_t *props, size_t props_size);
@@ -40,7 +41,7 @@ extern bool lzma_lzma_lclppb_decode(
/// 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,
+ lzma_lz_decoder *lz, const lzma_allocator *allocator,
const void *opt, lzma_lz_options *lz_options);
/// Gets memory usage without validating lc/lp/pb. This is used by LZMA2
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c
index e8738f411..ba9ce6989 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.c
@@ -28,14 +28,11 @@ literal_matched(lzma_range_encoder *rc, probability *subcoder,
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;
+ const uint32_t match_bit = match_byte & offset;
+ const uint32_t subcoder_index
+ = offset + match_bit + (symbol >> 8);
+ const uint32_t bit = (symbol >> 7) & 1;
rc_bit(rc, &subcoder[subcoder_index], bit);
symbol <<= 1;
@@ -46,7 +43,7 @@ literal_matched(lzma_range_encoder *rc, probability *subcoder,
static inline void
-literal(lzma_coder *coder, lzma_mf *mf, uint32_t position)
+literal(lzma_lzma1_encoder *coder, lzma_mf *mf, uint32_t position)
{
// Locate the literal byte to be encoded and the subcoder.
const uint8_t cur_byte = mf->buffer[
@@ -80,19 +77,16 @@ literal(lzma_coder *coder, lzma_mf *mf, uint32_t position)
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];
+ const uint32_t a0 = rc_bit_0_price(lc->choice);
+ const uint32_t a1 = rc_bit_1_price(lc->choice);
+ const uint32_t b0 = a1 + rc_bit_0_price(lc->choice2);
+ const uint32_t b1 = a1 + rc_bit_1_price(lc->choice2);
+ uint32_t *const prices = lc->prices[pos_state];
+ uint32_t i;
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);
@@ -146,39 +140,36 @@ length(lzma_range_encoder *rc, lzma_length_encoder *lc,
///////////
static inline void
-match(lzma_coder *coder, const uint32_t pos_state,
+match(lzma_lzma1_encoder *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);
+ const uint32_t dist_slot = get_dist_slot(distance);
+ const uint32_t dist_state = get_dist_state(len);
+ rc_bittree(&coder->rc, coder->dist_slot[dist_state],
+ DIST_SLOT_BITS, dist_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 (dist_slot >= DIST_MODEL_START) {
+ const uint32_t footer_bits = (dist_slot >> 1) - 1;
+ const uint32_t base = (2 | (dist_slot & 1)) << footer_bits;
+ const uint32_t dist_reduced = distance - base;
- if (pos_slot < END_POS_MODEL_INDEX) {
- // Careful here: base - pos_slot - 1 can be -1, but
+ if (dist_slot < DIST_MODEL_END) {
+ // Careful here: base - dist_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);
+ coder->dist_special + base - dist_slot - 1,
+ footer_bits, dist_reduced);
} else {
- rc_direct(&coder->rc, pos_reduced >> ALIGN_BITS,
+ rc_direct(&coder->rc, dist_reduced >> ALIGN_BITS,
footer_bits - ALIGN_BITS);
rc_bittree_reverse(
- &coder->rc, coder->pos_align,
- ALIGN_BITS, pos_reduced & ALIGN_MASK);
+ &coder->rc, coder->dist_align,
+ ALIGN_BITS, dist_reduced & ALIGN_MASK);
++coder->align_price_count;
}
}
@@ -196,7 +187,7 @@ match(lzma_coder *coder, const uint32_t pos_state,
////////////////////
static inline void
-rep_match(lzma_coder *coder, const uint32_t pos_state,
+rep_match(lzma_lzma1_encoder *coder, const uint32_t pos_state,
const uint32_t rep, const uint32_t len)
{
if (rep == 0) {
@@ -240,7 +231,7 @@ rep_match(lzma_coder *coder, const uint32_t pos_state,
//////////
static void
-encode_symbol(lzma_coder *coder, lzma_mf *mf,
+encode_symbol(lzma_lzma1_encoder *coder, lzma_mf *mf,
uint32_t back, uint32_t len, uint32_t position)
{
const uint32_t pos_state = position & coder->pos_mask;
@@ -256,7 +247,7 @@ encode_symbol(lzma_coder *coder, lzma_mf *mf,
rc_bit(&coder->rc,
&coder->is_match[coder->state][pos_state], 1);
- if (back < REP_DISTANCES) {
+ if (back < REPS) {
// It's a repeated match i.e. the same distance
// has been used earlier.
rc_bit(&coder->rc, &coder->is_rep[coder->state], 1);
@@ -264,7 +255,7 @@ encode_symbol(lzma_coder *coder, lzma_mf *mf,
} else {
// Normal match
rc_bit(&coder->rc, &coder->is_rep[coder->state], 0);
- match(coder, pos_state, back - REP_DISTANCES, len);
+ match(coder, pos_state, back - REPS, len);
}
}
@@ -274,7 +265,7 @@ encode_symbol(lzma_coder *coder, lzma_mf *mf,
static bool
-encode_init(lzma_coder *coder, lzma_mf *mf)
+encode_init(lzma_lzma1_encoder *coder, lzma_mf *mf)
{
assert(mf_position(mf) == 0);
@@ -302,7 +293,7 @@ encode_init(lzma_coder *coder, lzma_mf *mf)
static void
-encode_eopm(lzma_coder *coder, uint32_t position)
+encode_eopm(lzma_lzma1_encoder *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);
@@ -318,23 +309,18 @@ encode_eopm(lzma_coder *coder, uint32_t position)
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,
+lzma_lzma_encode(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf,
+ uint8_t *restrict out, size_t *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);
+ uint32_t 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
@@ -367,12 +353,14 @@ lzma_lzma_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
// 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)
+ // - [0, REPS): repeated match
+ // - [REPS, UINT32_MAX):
+ // match at (pos - REPS)
// - UINT32_MAX: not a match but a literal
// Value ranges for len:
// - [MATCH_LEN_MIN, MATCH_LEN_MAX]
+ uint32_t len;
+ uint32_t back;
if (coder->fast_mode)
lzma_lzma_optimum_fast(coder, mf, &back, &len);
@@ -414,8 +402,8 @@ lzma_lzma_encode(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
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,
+lzma_encode(void *coder, lzma_mf *restrict mf,
+ uint8_t *restrict out, size_t *restrict out_pos,
size_t out_size)
{
// Plain LZMA has no support for sync-flushing.
@@ -465,12 +453,10 @@ 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) {
+ for (size_t 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);
}
@@ -478,7 +464,7 @@ length_encoder_reset(lzma_length_encoder *lencoder,
bittree_reset(lencoder->high, LEN_HIGH_BITS);
if (!fast_mode)
- for (pos_state = 0; pos_state < num_pos_states;
+ for (uint32_t pos_state = 0; pos_state < num_pos_states;
++pos_state)
length_update_prices(lencoder, pos_state);
@@ -487,10 +473,9 @@ length_encoder_reset(lzma_length_encoder *lencoder,
extern lzma_ret
-lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
+lzma_lzma_encoder_reset(lzma_lzma1_encoder *coder,
+ const lzma_options_lzma *options)
{
- size_t i, j;
-
if (!is_options_valid(options))
return LZMA_OPTIONS_ERROR;
@@ -503,14 +488,14 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
// State
coder->state = STATE_LIT_LIT;
- for (i = 0; i < REP_DISTANCES; ++i)
+ for (size_t i = 0; i < REPS; ++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) {
+ for (size_t i = 0; i < STATES; ++i) {
+ for (size_t j = 0; j <= coder->pos_mask; ++j) {
bit_reset(coder->is_match[i][j]);
bit_reset(coder->is_rep0_long[i][j]);
}
@@ -521,14 +506,14 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
bit_reset(coder->is_rep2[i]);
}
- for (i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
- bit_reset(coder->pos_special[i]);
+ for (size_t i = 0; i < FULL_DISTANCES - DIST_MODEL_END; ++i)
+ bit_reset(coder->dist_special[i]);
// Bit tree encoders
- for (i = 0; i < LEN_TO_POS_STATES; ++i)
- bittree_reset(coder->pos_slot[i], POS_SLOT_BITS);
+ for (size_t i = 0; i < DIST_STATES; ++i)
+ bittree_reset(coder->dist_slot[i], DIST_SLOT_BITS);
- bittree_reset(coder->pos_align, ALIGN_BITS);
+ bittree_reset(coder->dist_align, ALIGN_BITS);
// Length encoders
length_encoder_reset(&coder->match_len_encoder,
@@ -561,20 +546,18 @@ lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
extern lzma_ret
-lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
+lzma_lzma_encoder_create(void **coder_ptr,
+ const 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.
+ // Allocate lzma_lzma1_encoder if it wasn't already allocated.
if (*coder_ptr == NULL) {
- *coder_ptr = lzma_alloc(sizeof(lzma_coder), allocator);
+ *coder_ptr = lzma_alloc(sizeof(lzma_lzma1_encoder), allocator);
if (*coder_ptr == NULL)
return LZMA_MEM_ERROR;
}
- coder = *coder_ptr;
+ lzma_lzma1_encoder *coder = *coder_ptr;
// Set compression mode. We haven't validates the options yet,
// but it's OK here, since nothing bad happens with invalid
@@ -590,6 +573,7 @@ lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
// Set dist_table_size.
// Round the dictionary size up to next 2^n.
+ uint32_t log_size = 0;
while ((UINT32_C(1) << log_size) < options->dict_size)
++log_size;
@@ -622,7 +606,7 @@ lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
static lzma_ret
-lzma_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
+lzma_encoder_init(lzma_lz_encoder *lz, const lzma_allocator *allocator,
const void *options, lzma_lz_options *lz_options)
{
lz->code = &lzma_encode;
@@ -632,7 +616,7 @@ lzma_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
extern lzma_ret
-lzma_lzma_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_lzma_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
return lzma_lz_encoder_init(
@@ -643,19 +627,17 @@ lzma_lzma_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
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;
+ lzma_lz_options lz_options;
set_lz_options(&lz_options, options);
- lz_memusage = lzma_lz_encoder_memusage(&lz_options);
+ const uint64_t lz_memusage = lzma_lz_encoder_memusage(&lz_options);
if (lz_memusage == UINT64_MAX)
return UINT64_MAX;
- return (uint64_t)(sizeof(lzma_coder)) + lz_memusage;
+ return (uint64_t)(sizeof(lzma_lzma1_encoder)) + lz_memusage;
}
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h
index abb8d8b46..6cfdf228b 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder.h
@@ -17,8 +17,12 @@
#include "common.h"
+typedef struct lzma_lzma1_encoder_s lzma_lzma1_encoder;
+
+
extern lzma_ret lzma_lzma_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters);
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters);
extern uint64_t lzma_lzma_encoder_memusage(const void *options);
@@ -35,18 +39,18 @@ extern bool lzma_lzma_lclppb_encode(
/// Initializes raw LZMA encoder; this is used by LZMA2.
extern lzma_ret lzma_lzma_encoder_create(
- lzma_coder **coder_ptr, lzma_allocator *allocator,
+ void **coder_ptr, const 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);
+ lzma_lzma1_encoder *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,
+extern lzma_ret lzma_lzma_encode(lzma_lzma1_encoder *restrict coder,
+ lzma_mf *restrict mf, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size,
uint32_t read_limit);
#endif
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c
index f98312643..6c53d2bd0 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_fast.c
@@ -10,6 +10,7 @@
///////////////////////////////////////////////////////////////////////////////
#include "lzma_encoder_private.h"
+#include "memcmplen.h"
#define change_pair(small_dist, big_dist) \
@@ -17,17 +18,10 @@
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)
+lzma_lzma_optimum_fast(lzma_lzma1_encoder *restrict coder,
+ lzma_mf *restrict mf,
+ uint32_t *restrict back_res, uint32_t *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;
@@ -40,8 +34,8 @@ lzma_lzma_optimum_fast(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT m
matches_count = coder->matches_count;
}
- buf = mf_ptr(mf) - 1;
- buf_avail = my_min(mf_avail(mf) + 1, MATCH_LEN_MAX);
+ const uint8_t *buf = mf_ptr(mf) - 1;
+ const uint32_t 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.
@@ -51,9 +45,10 @@ lzma_lzma_optimum_fast(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT m
}
// Look for repeated matches; scan the previous four match distances
- for (i = 0; i < REP_DISTANCES; ++i) {
- uint32_t len;
+ uint32_t rep_len = 0;
+ uint32_t rep_index = 0;
+ for (uint32_t i = 0; i < REPS; ++i) {
// Pointer to the beginning of the match candidate
const uint8_t *const buf_back = buf - coder->reps[i] - 1;
@@ -64,8 +59,8 @@ lzma_lzma_optimum_fast(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT m
// The first two bytes matched.
// Calculate the length of the match.
- for (len = 2; len < buf_avail
- && buf[len] == buf_back[len]; ++len) ;
+ const uint32_t len = lzma_memcmplen(
+ buf, buf_back, 2, buf_avail);
// If we have found a repeated match that is at least
// nice_len long, return it immediately.
@@ -85,13 +80,13 @@ lzma_lzma_optimum_fast(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT m
// 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;
+ *back_res = coder->matches[matches_count - 1].dist + REPS;
*len_res = len_main;
mf_skip(mf, len_main - 1);
return;
}
+ uint32_t back_main = 0;
if (len_main >= 2) {
back_main = coder->matches[matches_count - 1].dist;
@@ -158,27 +153,17 @@ lzma_lzma_optimum_fast(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT m
// 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) ;
+ const uint32_t limit = my_max(2, len_main - 1);
- if (len >= limit) {
+ for (uint32_t i = 0; i < REPS; ++i) {
+ if (memcmp(buf, buf - coder->reps[i] - 1, limit) == 0) {
*back_res = UINT32_MAX;
*len_res = 1;
return;
}
}
- *back_res = back_main + REP_DISTANCES;
+ *back_res = back_main + REPS;
*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
index d3a63485c..59f77343e 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_normal.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_optimum_normal.c
@@ -11,6 +11,7 @@
#include "lzma_encoder_private.h"
#include "fastpos.h"
+#include "memcmplen.h"
////////////
@@ -18,7 +19,7 @@
////////////
static uint32_t
-get_literal_price(const lzma_coder *const coder, const uint32_t pos,
+get_literal_price(const lzma_lzma1_encoder *const coder, const uint32_t pos,
const uint32_t prev_byte, const bool match_mode,
uint32_t match_byte, uint32_t symbol)
{
@@ -35,15 +36,12 @@ get_literal_price(const lzma_coder *const coder, const uint32_t pos,
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;
+ const uint32_t match_bit = match_byte & offset;
+ const uint32_t subcoder_index
+ = offset + match_bit + (symbol >> 8);
+ const uint32_t bit = (symbol >> 7) & 1;
price += rc_bit_price(subcoder[subcoder_index], bit);
symbol <<= 1;
@@ -67,7 +65,7 @@ get_len_price(const lzma_length_encoder *const lencoder,
static inline uint32_t
-get_short_rep_price(const lzma_coder *const coder,
+get_short_rep_price(const lzma_lzma1_encoder *const coder,
const lzma_lzma_state state, const uint32_t pos_state)
{
return rc_bit_0_price(coder->is_rep0[state])
@@ -76,7 +74,7 @@ get_short_rep_price(const lzma_coder *const coder,
static inline uint32_t
-get_pure_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
+get_pure_rep_price(const lzma_lzma1_encoder *const coder, const uint32_t rep_index,
const lzma_lzma_state state, uint32_t pos_state)
{
uint32_t price;
@@ -101,7 +99,7 @@ get_pure_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
static inline uint32_t
-get_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
+get_rep_price(const lzma_lzma1_encoder *const coder, const uint32_t rep_index,
const uint32_t len, const lzma_lzma_state state,
const uint32_t pos_state)
{
@@ -111,18 +109,18 @@ get_rep_price(const lzma_coder *const coder, const uint32_t rep_index,
static inline uint32_t
-get_pos_len_price(const lzma_coder *const coder, const uint32_t pos,
+get_dist_len_price(const lzma_lzma1_encoder *const coder, const uint32_t dist,
const uint32_t len, const uint32_t pos_state)
{
- const uint32_t len_to_pos_state = get_len_to_pos_state(len);
+ const uint32_t dist_state = get_dist_state(len);
uint32_t price;
- if (pos < FULL_DISTANCES) {
- price = coder->distances_prices[len_to_pos_state][pos];
+ if (dist < FULL_DISTANCES) {
+ price = coder->dist_prices[dist_state][dist];
} 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];
+ const uint32_t dist_slot = get_dist_slot_2(dist);
+ price = coder->dist_slot_prices[dist_state][dist_slot]
+ + coder->align_prices[dist & ALIGN_MASK];
}
price += get_len_price(&coder->match_len_encoder, len, pos_state);
@@ -132,59 +130,53 @@ get_pos_len_price(const lzma_coder *const coder, const uint32_t pos,
static void
-fill_distances_prices(lzma_coder *coder)
+fill_dist_prices(lzma_lzma1_encoder *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) {
+ for (uint32_t dist_state = 0; dist_state < DIST_STATES; ++dist_state) {
- uint32_t *const pos_slot_prices
- = coder->pos_slot_prices[len_to_pos_state];
+ uint32_t *const dist_slot_prices
+ = coder->dist_slot_prices[dist_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);
+ // Price to encode the dist_slot.
+ for (uint32_t dist_slot = 0;
+ dist_slot < coder->dist_table_size; ++dist_slot)
+ dist_slot_prices[dist_slot] = rc_bittree_price(
+ coder->dist_slot[dist_state],
+ DIST_SLOT_BITS, dist_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);
+ for (uint32_t dist_slot = DIST_MODEL_END;
+ dist_slot < coder->dist_table_size;
+ ++dist_slot)
+ dist_slot_prices[dist_slot] += rc_direct_price(
+ ((dist_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
+ // dist_slot, so they are used for coder->dist_prices
// as is.
- for (i = 0; i < START_POS_MODEL_INDEX; ++i)
- coder->distances_prices[len_to_pos_state][i]
- = pos_slot_prices[i];
+ for (uint32_t i = 0; i < DIST_MODEL_START; ++i)
+ coder->dist_prices[dist_state][i]
+ = dist_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;
+ // Distances in the range [4, 127] depend on dist_slot and
+ // dist_special. We do this in a loop separate from the above
+ // loop to avoid redundant calls to get_dist_slot().
+ for (uint32_t i = DIST_MODEL_START; i < FULL_DISTANCES; ++i) {
+ const uint32_t dist_slot = get_dist_slot(i);
+ const uint32_t footer_bits = ((dist_slot >> 1) - 1);
+ const uint32_t base = (2 | (dist_slot & 1)) << footer_bits;
const uint32_t price = rc_bittree_reverse_price(
- coder->pos_special + base - pos_slot - 1,
+ coder->dist_special + base - dist_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];
+ for (uint32_t dist_state = 0; dist_state < DIST_STATES;
+ ++dist_state)
+ coder->dist_prices[dist_state][i]
+ = price + coder->dist_slot_prices[
+ dist_state][dist_slot];
}
coder->match_price_count = 0;
@@ -193,12 +185,11 @@ fill_distances_prices(lzma_coder *coder)
static void
-fill_align_prices(lzma_coder *coder)
+fill_align_prices(lzma_lzma1_encoder *coder)
{
- uint32_t i;
- for (i = 0; i < ALIGN_TABLE_SIZE; ++i)
+ for (uint32_t i = 0; i < ALIGN_SIZE; ++i)
coder->align_prices[i] = rc_bittree_reverse_price(
- coder->pos_align, ALIGN_BITS, i);
+ coder->dist_align, ALIGN_BITS, i);
coder->align_price_count = 0;
return;
@@ -230,18 +221,15 @@ make_short_rep(lzma_optimal *optimal)
static void
-backward(lzma_coder *LZMA_RESTRICT coder, uint32_t *LZMA_RESTRICT len_res,
- uint32_t *LZMA_RESTRICT back_res, uint32_t cur)
+backward(lzma_lzma1_encoder *restrict coder, uint32_t *restrict len_res,
+ uint32_t *restrict back_res, uint32_t cur)
{
+ coder->opts_end_index = 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;
@@ -256,6 +244,9 @@ backward(lzma_coder *LZMA_RESTRICT coder, uint32_t *LZMA_RESTRICT len_res,
}
}
+ const uint32_t pos_prev = pos_mem;
+ const uint32_t back_cur = back_mem;
+
back_mem = coder->opts[pos_prev].back_prev;
pos_mem = coder->opts[pos_prev].pos_prev;
@@ -278,27 +269,10 @@ backward(lzma_coder *LZMA_RESTRICT coder, uint32_t *LZMA_RESTRICT len_res,
//////////
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,
+helper1(lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf,
+ uint32_t *restrict back_res, uint32_t *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;
@@ -312,18 +286,19 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
matches_count = coder->matches_count;
}
- buf_avail = my_min(mf_avail(mf) + 1, MATCH_LEN_MAX);
+ const uint32_t 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;
+ const uint8_t *const buf = mf_ptr(mf) - 1;
- for (i = 0; i < REP_DISTANCES; ++i) {
- uint32_t len_test;
+ uint32_t rep_lens[REPS];
+ uint32_t rep_max_index = 0;
+ for (uint32_t i = 0; i < REPS; ++i) {
const uint8_t *const buf_back = buf - coder->reps[i] - 1;
if (not_equal_16(buf, buf_back)) {
@@ -331,12 +306,9 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
continue;
}
- for (len_test = 2; len_test < buf_avail
- && buf[len_test] == buf_back[len_test];
- ++len_test) ;
+ rep_lens[i] = lzma_memcmplen(buf, buf_back, 2, buf_avail);
- rep_lens[i] = len_test;
- if (len_test > rep_lens[rep_max_index])
+ if (rep_lens[i] > rep_lens[rep_max_index])
rep_max_index = i;
}
@@ -349,15 +321,14 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
if (len_main >= nice_len) {
- *back_res = coder->matches[matches_count - 1].dist
- + REP_DISTANCES;
+ *back_res = coder->matches[matches_count - 1].dist + REPS;
*len_res = len_main;
mf_skip(mf, len_main - 1);
return UINT32_MAX;
}
- current_byte = *buf;
- match_byte = *(buf - coder->reps[0] - 1);
+ const uint8_t current_byte = *buf;
+ const uint8_t match_byte = *(buf - coder->reps[0] - 1);
if (len_main < 2 && current_byte != match_byte
&& rep_lens[rep_max_index] < 2) {
@@ -368,7 +339,7 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
coder->opts[0].state = coder->state;
- pos_state = position & coder->pos_mask;
+ const uint32_t pos_state = position & coder->pos_mask;
coder->opts[1].price = rc_bit_0_price(
coder->is_match[coder->state][pos_state])
@@ -378,9 +349,9 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
make_literal(&coder->opts[1]);
- match_price = rc_bit_1_price(
+ const uint32_t match_price = rc_bit_1_price(
coder->is_match[coder->state][pos_state]);
- rep_match_price = match_price
+ const uint32_t rep_match_price = match_price
+ rc_bit_1_price(coder->is_rep[coder->state]);
if (match_byte == current_byte) {
@@ -394,7 +365,7 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
}
}
- len_end = my_max(len_main, rep_lens[rep_max_index]);
+ const uint32_t len_end = my_max(len_main, rep_lens[rep_max_index]);
if (len_end < 2) {
*back_res = coder->opts[1].back_prev;
@@ -404,23 +375,21 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
coder->opts[1].pos_prev = 0;
- for (i = 0; i < REP_DISTANCES; ++i)
+ for (uint32_t i = 0; i < REPS; ++i)
coder->opts[0].backs[i] = coder->reps[i];
- len = len_end;
+ uint32_t len = len_end;
do {
coder->opts[len].price = RC_INFINITY_PRICE;
} while (--len >= 2);
- for (i = 0; i < REP_DISTANCES; ++i) {
- uint32_t price;
-
+ for (uint32_t i = 0; i < REPS; ++i) {
uint32_t rep_len = rep_lens[i];
if (rep_len < 2)
continue;
- price = rep_match_price + get_pure_rep_price(
+ const uint32_t price = rep_match_price + get_pure_rep_price(
coder, i, coder->state, pos_state);
do {
@@ -439,7 +408,7 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
}
- normal_match_price = match_price
+ const uint32_t normal_match_price = match_price
+ rc_bit_0_price(coder->is_rep[coder->state]);
len = rep_lens[0] >= 2 ? rep_lens[0] + 1 : 2;
@@ -451,14 +420,13 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
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,
+ + get_dist_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].back_prev = dist + REPS;
coder->opts[len].prev_1_is_literal = false;
}
@@ -473,7 +441,7 @@ helper1(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT mf,
static inline uint32_t
-helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
+helper2(lzma_lzma1_encoder *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)
{
@@ -481,19 +449,6 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
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;
@@ -501,7 +456,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
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)
+ if (coder->opts[cur].back_prev_2 < REPS)
update_long_rep(state);
else
update_match(state);
@@ -530,48 +485,49 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
update_long_rep(state);
} else {
pos = coder->opts[cur].back_prev;
- if (pos < REP_DISTANCES)
+ if (pos < REPS)
update_long_rep(state);
else
update_match(state);
}
- if (pos < REP_DISTANCES) {
- uint32_t i;
-
+ if (pos < REPS) {
reps[0] = coder->opts[pos_prev].backs[pos];
+ uint32_t i;
for (i = 1; i <= pos; ++i)
reps[i] = coder->opts[pos_prev].backs[i - 1];
- for (; i < REP_DISTANCES; ++i)
+ for (; i < REPS; ++i)
reps[i] = coder->opts[pos_prev].backs[i];
} else {
- reps[0] = pos - REP_DISTANCES;
+ reps[0] = pos - REPS;
- for (i = 1; i < REP_DISTANCES; ++i)
+ for (uint32_t i = 1; i < REPS; ++i)
reps[i] = coder->opts[pos_prev].backs[i - 1];
}
}
coder->opts[cur].state = state;
- for (i = 0; i < REP_DISTANCES; ++i)
+ for (uint32_t i = 0; i < REPS; ++i)
coder->opts[cur].backs[i] = reps[i];
- cur_price = coder->opts[cur].price;
+ const uint32_t cur_price = coder->opts[cur].price;
- current_byte = *buf;
- match_byte = *(buf - reps[0] - 1);
+ const uint8_t current_byte = *buf;
+ const uint8_t match_byte = *(buf - reps[0] - 1);
- pos_state = position & coder->pos_mask;
+ const uint32_t pos_state = position & coder->pos_mask;
- cur_and_1_price = cur_price
+ const uint32_t 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);
+ bool next_is_literal = false;
+
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;
@@ -579,9 +535,9 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
next_is_literal = true;
}
- match_price = cur_price
+ const uint32_t match_price = cur_price
+ rc_bit_1_price(coder->is_match[state][pos_state]);
- rep_match_price = match_price
+ const uint32_t rep_match_price = match_price
+ rc_bit_1_price(coder->is_rep[state]);
if (match_byte == current_byte
@@ -602,40 +558,31 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
if (buf_avail_full < 2)
return len_end;
- buf_avail = my_min(buf_avail_full, nice_len);
+ const uint32_t 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;
+ const uint32_t len_test = lzma_memcmplen(buf, buf_back, 1, limit) - 1;
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
+ const uint32_t pos_state_next = (position + 1) & coder->pos_mask;
+ const uint32_t 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;
+ const uint32_t 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
+ const uint32_t cur_and_len_price = next_rep_match_price
+ get_rep_price(coder, 0, len_test,
state_2, pos_state_next);
@@ -651,23 +598,20 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
}
- for (rep_index = 0; rep_index < REP_DISTANCES; ++rep_index) {
- uint32_t len_test, len_test_2, len_test_temp;
- uint32_t price, limit;
+ uint32_t start_len = 2; // speed optimization
+ for (uint32_t rep_index = 0; rep_index < REPS; ++rep_index) {
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) ;
+ uint32_t len_test = lzma_memcmplen(buf, buf_back, 2, buf_avail);
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(
+ const uint32_t len_test_temp = len_test;
+ const uint32_t price = rep_match_price + get_pure_rep_price(
coder, rep_index, state, pos_state);
do {
@@ -689,8 +633,8 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
start_len = len_test + 1;
- len_test_2 = len_test + 1;
- limit = my_min(buf_avail_full,
+ 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];
@@ -699,18 +643,12 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
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;
+ uint32_t pos_state_next = (position + len_test) & coder->pos_mask;
- cur_and_len_literal_price = price
+ const uint32_t 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])
@@ -722,17 +660,17 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
pos_state_next = (position + len_test + 1) & coder->pos_mask;
- next_rep_match_price = cur_and_len_literal_price
+ const uint32_t 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;
+ const uint32_t 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
+ const uint32_t cur_and_len_price = next_rep_match_price
+ get_rep_price(coder, 0, len_test_2,
state_2, pos_state_next);
@@ -763,29 +701,27 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
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;
+ uint32_t i = 0;
while (start_len > coder->matches[i].len)
++i;
- for (len_test = start_len; ; ++len_test) {
+ for (uint32_t 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,
+ + get_dist_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;
+ = cur_back + REPS;
coder->opts[cur + len_test].prev_1_is_literal = false;
}
@@ -803,16 +739,12 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
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;
+ uint32_t pos_state_next
+ = (position + len_test) & coder->pos_mask;
- cur_and_len_literal_price = cur_and_len_price
+ const uint32_t 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,
@@ -825,14 +757,14 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
update_literal(state_2);
pos_state_next = (pos_state_next + 1) & coder->pos_mask;
- next_rep_match_price
+ const uint32_t 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;
+ const uint32_t offset = cur + len_test + 1 + len_test_2;
while (len_end < offset)
coder->opts[++len_end].price = RC_INFINITY_PRICE;
@@ -849,7 +781,7 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
coder->opts[offset].prev_2 = true;
coder->opts[offset].pos_prev_2 = cur;
coder->opts[offset].back_prev_2
- = cur_back + REP_DISTANCES;
+ = cur_back + REPS;
}
//}
}
@@ -865,14 +797,11 @@ helper2(lzma_coder *coder, uint32_t *reps, const uint8_t *buf,
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,
+lzma_lzma_optimum_normal(lzma_lzma1_encoder *restrict coder,
+ lzma_mf *restrict mf,
+ uint32_t *restrict back_res, uint32_t *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);
@@ -889,9 +818,9 @@ lzma_lzma_optimum_normal(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT
// 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);
+ fill_dist_prices(coder);
- if (coder->align_price_count >= ALIGN_TABLE_SIZE)
+ if (coder->align_price_count >= ALIGN_SIZE)
fill_align_prices(coder);
}
@@ -899,13 +828,14 @@ lzma_lzma_optimum_normal(lzma_coder *LZMA_RESTRICT coder, lzma_mf *LZMA_RESTRICT
// 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);
+ uint32_t len_end = helper1(coder, mf, back_res, len_res, position);
if (len_end == UINT32_MAX)
return;
-
+ uint32_t reps[REPS];
memcpy(reps, coder->reps, sizeof(reps));
+ uint32_t cur;
for (cur = 1; cur < len_end; ++cur) {
assert(cur < OPTS);
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c
index 9332abfa5..711df0255 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_presets.c
@@ -2,6 +2,7 @@
//
/// \file lzma_encoder_presets.c
/// \brief Encoder presets
+/// \note xz needs this even when only decoding is enabled.
//
// Author: Lasse Collin
//
@@ -16,10 +17,6 @@
extern LZMA_API(lzma_bool)
lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
{
- static const uint8_t dict_pow2[]
- = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
- static const uint8_t depths[] = { 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;
@@ -34,12 +31,15 @@ lzma_lzma_preset(lzma_options_lzma *options, uint32_t preset)
options->lp = LZMA_LP_DEFAULT;
options->pb = LZMA_PB_DEFAULT;
+ static const uint8_t dict_pow2[]
+ = { 18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
options->dict_size = UINT32_C(1) << dict_pow2[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;
+ static const uint8_t depths[] = { 4, 8, 24, 48 };
options->depth = depths[level];
} else {
options->mode = LZMA_MODE_NORMAL;
diff --git a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h
index 04fb29e90..a2da969f4 100644
--- a/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h
+++ b/Utilities/cmliblzma/liblzma/lzma/lzma_encoder_private.h
@@ -64,12 +64,12 @@ typedef struct {
uint32_t pos_prev; // pos_next;
uint32_t back_prev;
- uint32_t backs[REP_DISTANCES];
+ uint32_t backs[REPS];
} lzma_optimal;
-struct lzma_coder_s {
+struct lzma_lzma1_encoder_s {
/// Range encoder
lzma_range_encoder rc;
@@ -77,7 +77,7 @@ struct lzma_coder_s {
lzma_lzma_state state;
/// The four most recent match distances
- uint32_t reps[REP_DISTANCES];
+ uint32_t reps[REPS];
/// Array of match candidates
lzma_match matches[MATCH_LEN_MAX + 1];
@@ -112,9 +112,9 @@ struct lzma_coder_s {
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];
+ probability dist_slot[DIST_STATES][DIST_SLOTS];
+ probability dist_special[FULL_DISTANCES - DIST_MODEL_END];
+ probability dist_align[ALIGN_SIZE];
// These are the same as in lzma_decoder.c except that the encoders
// include also price tables.
@@ -122,12 +122,12 @@ struct lzma_coder_s {
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_slot_prices[DIST_STATES][DIST_SLOTS];
+ uint32_t dist_prices[DIST_STATES][FULL_DISTANCES];
uint32_t dist_table_size;
uint32_t match_price_count;
- uint32_t align_prices[ALIGN_TABLE_SIZE];
+ uint32_t align_prices[ALIGN_SIZE];
uint32_t align_price_count;
// Optimal
@@ -138,11 +138,11 @@ struct lzma_coder_s {
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);
+ lzma_lzma1_encoder *restrict coder, lzma_mf *restrict mf,
+ uint32_t *restrict back_res, uint32_t *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);
+extern void lzma_lzma_optimum_normal(lzma_lzma1_encoder *restrict coder,
+ lzma_mf *restrict mf, uint32_t *restrict back_res,
+ uint32_t *restrict len_res, uint32_t position);
#endif
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/range_common.h b/Utilities/cmliblzma/liblzma/rangecoder/range_common.h
index f15623ea6..2c74dc153 100644
--- a/Utilities/cmliblzma/liblzma/rangecoder/range_common.h
+++ b/Utilities/cmliblzma/liblzma/rangecoder/range_common.h
@@ -40,11 +40,8 @@
// 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)
+ for (uint32_t bt_i = 0; bt_i < (1 << (bit_levels)); ++bt_i) \
+ bit_reset((probs)[bt_i])
//////////////////////
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h b/Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h
index 199e7b5a6..e0b051fac 100644
--- a/Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h
+++ b/Utilities/cmliblzma/liblzma/rangecoder/range_decoder.h
@@ -25,20 +25,26 @@ typedef struct {
/// 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)
+static inline lzma_ret
+rc_read_init(lzma_range_decoder *rc, const uint8_t *restrict in,
+ size_t *restrict in_pos, size_t in_size)
{
while (rc->init_bytes_left > 0) {
if (*in_pos == in_size)
- return false;
+ return LZMA_OK;
+
+ // The first byte is always 0x00. It could have been omitted
+ // in LZMA2 but it wasn't, so one byte is wasted in every
+ // LZMA2 chunk.
+ if (rc->init_bytes_left == 5 && in[*in_pos] != 0x00)
+ return LZMA_DATA_ERROR;
rc->code = (rc->code << 8) | in[*in_pos];
++*in_pos;
--rc->init_bytes_left;
}
- return true;
+ return LZMA_STREAM_END;
}
diff --git a/Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h b/Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h
index e9614f252..1e1c36995 100644
--- a/Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h
+++ b/Utilities/cmliblzma/liblzma/rangecoder/range_encoder.h
@@ -115,8 +115,7 @@ rc_direct(lzma_range_encoder *rc,
static inline void
rc_flush(lzma_range_encoder *rc)
{
- size_t i;
- for (i = 0; i < 5; ++i)
+ for (size_t i = 0; i < 5; ++i)
rc->symbols[rc->count++] = RC_FLUSH;
}
diff --git a/Utilities/cmliblzma/liblzma/simple/arm.c b/Utilities/cmliblzma/liblzma/simple/arm.c
index 8dcba39fd..181d0e3b2 100644
--- a/Utilities/cmliblzma/liblzma/simple/arm.c
+++ b/Utilities/cmliblzma/liblzma/simple/arm.c
@@ -15,19 +15,19 @@
static size_t
-arm_code(lzma_simple *simple lzma_attribute((__unused__)),
+arm_code(void *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;
+ uint32_t dest;
if (is_encoder)
dest = now_pos + (uint32_t)(i) + 8 + src;
else
@@ -45,7 +45,7 @@ arm_code(lzma_simple *simple lzma_attribute((__unused__)),
static lzma_ret
-arm_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+arm_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder)
{
return lzma_simple_coder_init(next, allocator, filters,
@@ -54,7 +54,8 @@ arm_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
-lzma_simple_arm_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_simple_arm_encoder_init(lzma_next_coder *next,
+ const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
return arm_coder_init(next, allocator, filters, true);
@@ -62,7 +63,8 @@ lzma_simple_arm_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
-lzma_simple_arm_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_simple_arm_decoder_init(lzma_next_coder *next,
+ const 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
index 4b890a395..eab4862dd 100644
--- a/Utilities/cmliblzma/liblzma/simple/armthumb.c
+++ b/Utilities/cmliblzma/liblzma/simple/armthumb.c
@@ -15,7 +15,7 @@
static size_t
-armthumb_code(lzma_simple *simple lzma_attribute((__unused__)),
+armthumb_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{
@@ -23,7 +23,6 @@ armthumb_code(lzma_simple *simple lzma_attribute((__unused__)),
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)
@@ -31,6 +30,7 @@ armthumb_code(lzma_simple *simple lzma_attribute((__unused__)),
src <<= 1;
+ uint32_t dest;
if (is_encoder)
dest = now_pos + (uint32_t)(i) + 4 + src;
else
@@ -50,7 +50,7 @@ armthumb_code(lzma_simple *simple lzma_attribute((__unused__)),
static lzma_ret
-armthumb_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+armthumb_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder)
{
return lzma_simple_coder_init(next, allocator, filters,
@@ -60,7 +60,8 @@ armthumb_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters)
{
return armthumb_coder_init(next, allocator, filters, true);
}
@@ -68,7 +69,8 @@ lzma_simple_armthumb_encoder_init(lzma_next_coder *next,
extern lzma_ret
lzma_simple_armthumb_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const 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
index c537caca1..580529e80 100644
--- a/Utilities/cmliblzma/liblzma/simple/ia64.c
+++ b/Utilities/cmliblzma/liblzma/simple/ia64.c
@@ -15,7 +15,7 @@
static size_t
-ia64_code(lzma_simple *simple lzma_attribute((__unused__)),
+ia64_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{
@@ -28,42 +28,36 @@ ia64_code(lzma_simple *simple lzma_attribute((__unused__)),
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) {
+ for (size_t slot = 0; slot < 3; ++slot, bit_pos += 41) {
+ if (((mask >> slot) & 1) == 0)
+ continue;
+
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)
+ for (size_t j = 0; j < 6; ++j)
instruction += (uint64_t)(
buffer[i + j + byte_pos])
<< (8 * j);
- inst_norm = instruction >> bit_res;
+ uint64_t 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;
+ uint32_t dest;
if (is_encoder)
dest = now_pos + (uint32_t)(i) + src;
else
@@ -79,7 +73,7 @@ ia64_code(lzma_simple *simple lzma_attribute((__unused__)),
instruction &= (1 << bit_res) - 1;
instruction |= (inst_norm << bit_res);
- for (j = 0; j < 6; j++)
+ for (size_t j = 0; j < 6; j++)
buffer[i + j + byte_pos] = (uint8_t)(
instruction
>> (8 * j));
@@ -92,7 +86,7 @@ ia64_code(lzma_simple *simple lzma_attribute((__unused__)),
static lzma_ret
-ia64_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+ia64_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder)
{
return lzma_simple_coder_init(next, allocator, filters,
@@ -102,7 +96,8 @@ ia64_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
lzma_simple_ia64_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters)
{
return ia64_coder_init(next, allocator, filters, true);
}
@@ -110,7 +105,8 @@ lzma_simple_ia64_encoder_init(lzma_next_coder *next,
extern lzma_ret
lzma_simple_ia64_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const 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
index 6f8351176..54dfbf102 100644
--- a/Utilities/cmliblzma/liblzma/simple/powerpc.c
+++ b/Utilities/cmliblzma/liblzma/simple/powerpc.c
@@ -15,7 +15,7 @@
static size_t
-powerpc_code(lzma_simple *simple lzma_attribute((__unused__)),
+powerpc_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{
@@ -49,7 +49,7 @@ powerpc_code(lzma_simple *simple lzma_attribute((__unused__)),
static lzma_ret
-powerpc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+powerpc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder)
{
return lzma_simple_coder_init(next, allocator, filters,
@@ -59,7 +59,8 @@ powerpc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters)
{
return powerpc_coder_init(next, allocator, filters, true);
}
@@ -67,7 +68,8 @@ lzma_simple_powerpc_encoder_init(lzma_next_coder *next,
extern lzma_ret
lzma_simple_powerpc_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const 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
index f3bbdd7a7..13ebabc76 100644
--- a/Utilities/cmliblzma/liblzma/simple/simple_coder.c
+++ b/Utilities/cmliblzma/liblzma/simple/simple_coder.c
@@ -18,10 +18,10 @@
/// 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)
+copy_or_code(lzma_simple_coder *coder, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
assert(!coder->end_was_reached);
@@ -55,7 +55,7 @@ copy_or_code(lzma_coder *coder, lzma_allocator *allocator,
static size_t
-call_filter(lzma_coder *coder, uint8_t *buffer, size_t size)
+call_filter(lzma_simple_coder *coder, uint8_t *buffer, size_t size)
{
const size_t filtered = coder->filter(coder->simple,
coder->now_pos, coder->is_encoder,
@@ -66,13 +66,12 @@ call_filter(lzma_coder *coder, uint8_t *buffer, size_t size)
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)
+simple_code(void *coder_ptr, const lzma_allocator *allocator,
+ const uint8_t *restrict in, size_t *restrict in_pos,
+ size_t in_size, uint8_t *restrict out,
+ size_t *restrict out_pos, size_t out_size, lzma_action action)
{
- size_t out_avail;
- size_t buf_avail;
+ lzma_simple_coder *coder = coder_ptr;
// TODO: Add partial support for LZMA_SYNC_FLUSH. We can support it
// in cases when the filter is able to filter everything. With most
@@ -108,13 +107,9 @@ simple_code(lzma_coder *coder, lzma_allocator *allocator,
// 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;
+ const size_t out_avail = out_size - *out_pos;
+ const size_t 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;
@@ -137,10 +132,11 @@ simple_code(lzma_coder *coder, lzma_allocator *allocator,
}
// Filter out[].
- size = *out_pos - out_start;
- filtered = call_filter(coder, out + out_start, size);
+ const size_t size = *out_pos - out_start;
+ const size_t filtered = call_filter(
+ coder, out + out_start, size);
- unfiltered = size - filtered;
+ const size_t unfiltered = size - filtered;
assert(unfiltered <= coder->allocated / 2);
// Now we can update coder->pos and coder->size, because
@@ -204,8 +200,9 @@ simple_code(lzma_coder *coder, lzma_allocator *allocator,
static void
-simple_coder_end(lzma_coder *coder, lzma_allocator *allocator)
+simple_coder_end(void *coder_ptr, const lzma_allocator *allocator)
{
+ lzma_simple_coder *coder = coder_ptr;
lzma_next_end(&coder->next, allocator);
lzma_free(coder->simple, allocator);
lzma_free(coder, allocator);
@@ -214,10 +211,12 @@ simple_coder_end(lzma_coder *coder, lzma_allocator *allocator)
static lzma_ret
-simple_coder_update(lzma_coder *coder, lzma_allocator *allocator,
+simple_coder_update(void *coder_ptr, const lzma_allocator *allocator,
const lzma_filter *filters_null lzma_attribute((__unused__)),
const lzma_filter *reversed_filters)
{
+ lzma_simple_coder *coder = coder_ptr;
+
// No update support, just call the next filter in the chain.
return lzma_next_filter_update(
&coder->next, allocator, reversed_filters + 1);
@@ -225,59 +224,59 @@ simple_coder_update(lzma_coder *coder, lzma_allocator *allocator,
extern lzma_ret
-lzma_simple_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_simple_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters,
- size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
+ size_t (*filter)(void *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) {
+ // Allocate memory for the lzma_simple_coder structure if needed.
+ lzma_simple_coder *coder = next->coder;
+ if (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)
+ coder = lzma_alloc(sizeof(lzma_simple_coder)
+ 2 * unfiltered_max, allocator);
- if (next->coder == NULL)
+ if (coder == NULL)
return LZMA_MEM_ERROR;
+ next->coder = coder;
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;
+ coder->next = LZMA_NEXT_CODER_INIT;
+ coder->filter = filter;
+ 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)
+ coder->simple = lzma_alloc(simple_size, allocator);
+ if (coder->simple == NULL)
return LZMA_MEM_ERROR;
} else {
- next->coder->simple = NULL;
+ 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))
+ coder->now_pos = simple->start_offset;
+ if (coder->now_pos & (alignment - 1))
return LZMA_OPTIONS_ERROR;
} else {
- next->coder->now_pos = 0;
+ 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);
+ coder->is_encoder = is_encoder;
+ coder->end_was_reached = false;
+ coder->pos = 0;
+ coder->filtered = 0;
+ coder->size = 0;
+
+ return lzma_next_filter_init(&coder->next, allocator, filters + 1);
}
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_coder.h b/Utilities/cmliblzma/liblzma/simple/simple_coder.h
index 0952fad33..19c2ee03a 100644
--- a/Utilities/cmliblzma/liblzma/simple/simple_coder.h
+++ b/Utilities/cmliblzma/liblzma/simple/simple_coder.h
@@ -17,44 +17,56 @@
extern lzma_ret lzma_simple_x86_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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);
+ const 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
index 034e158ff..1d864f2bf 100644
--- a/Utilities/cmliblzma/liblzma/simple/simple_decoder.c
+++ b/Utilities/cmliblzma/liblzma/simple/simple_decoder.c
@@ -14,18 +14,17 @@
extern lzma_ret
-lzma_simple_props_decode(void **options, lzma_allocator *allocator,
+lzma_simple_props_decode(void **options, const 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);
+ lzma_options_bcj *opt = lzma_alloc(
+ sizeof(lzma_options_bcj), allocator);
if (opt == NULL)
return LZMA_MEM_ERROR;
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_decoder.h b/Utilities/cmliblzma/liblzma/simple/simple_decoder.h
index b8bf590f7..bed8d37a9 100644
--- a/Utilities/cmliblzma/liblzma/simple/simple_decoder.h
+++ b/Utilities/cmliblzma/liblzma/simple/simple_decoder.h
@@ -16,7 +16,7 @@
#include "simple_coder.h"
extern lzma_ret lzma_simple_props_decode(
- void **options, lzma_allocator *allocator,
+ void **options, const lzma_allocator *allocator,
const uint8_t *props, size_t props_size);
#endif
diff --git a/Utilities/cmliblzma/liblzma/simple/simple_private.h b/Utilities/cmliblzma/liblzma/simple/simple_private.h
index fcf9f7c19..9d2c0fdd7 100644
--- a/Utilities/cmliblzma/liblzma/simple/simple_private.h
+++ b/Utilities/cmliblzma/liblzma/simple/simple_private.h
@@ -16,9 +16,7 @@
#include "simple_coder.h"
-typedef struct lzma_simple_s lzma_simple;
-
-struct lzma_coder_s {
+typedef struct {
/// Next filter in the chain
lzma_next_coder next;
@@ -33,12 +31,12 @@ struct lzma_coder_s {
/// Pointer to filter-specific function, which does
/// the actual filtering.
- size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
+ size_t (*filter)(void *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;
+ void *simple;
/// The lowest 32 bits of the current position in the data. Most
/// filters need this to do conversions between absolute and relative
@@ -62,12 +60,13 @@ struct lzma_coder_s {
/// Temporary buffer
uint8_t buffer[];
-};
+} lzma_simple_coder;
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,
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters,
+ size_t (*filter)(void *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);
diff --git a/Utilities/cmliblzma/liblzma/simple/sparc.c b/Utilities/cmliblzma/liblzma/simple/sparc.c
index 0ddd2ac9d..74b2655f3 100644
--- a/Utilities/cmliblzma/liblzma/simple/sparc.c
+++ b/Utilities/cmliblzma/liblzma/simple/sparc.c
@@ -15,7 +15,7 @@
static size_t
-sparc_code(lzma_simple *simple lzma_attribute((__unused__)),
+sparc_code(void *simple lzma_attribute((__unused__)),
uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{
@@ -26,8 +26,6 @@ sparc_code(lzma_simple *simple lzma_attribute((__unused__)),
|| (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)
@@ -35,6 +33,7 @@ sparc_code(lzma_simple *simple lzma_attribute((__unused__)),
src <<= 2;
+ uint32_t dest;
if (is_encoder)
dest = now_pos + (uint32_t)(i) + src;
else
@@ -58,7 +57,7 @@ sparc_code(lzma_simple *simple lzma_attribute((__unused__)),
static lzma_ret
-sparc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+sparc_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder)
{
return lzma_simple_coder_init(next, allocator, filters,
@@ -68,7 +67,8 @@ sparc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
lzma_simple_sparc_encoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const lzma_allocator *allocator,
+ const lzma_filter_info *filters)
{
return sparc_coder_init(next, allocator, filters, true);
}
@@ -76,7 +76,8 @@ lzma_simple_sparc_encoder_init(lzma_next_coder *next,
extern lzma_ret
lzma_simple_sparc_decoder_init(lzma_next_coder *next,
- lzma_allocator *allocator, const lzma_filter_info *filters)
+ const 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
index 95858e51e..b38cebfd5 100644
--- a/Utilities/cmliblzma/liblzma/simple/x86.c
+++ b/Utilities/cmliblzma/liblzma/simple/x86.c
@@ -17,14 +17,14 @@
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
-struct lzma_simple_s {
+typedef struct {
uint32_t prev_mask;
uint32_t prev_pos;
-};
+} lzma_simple_x86;
static size_t
-x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
+x86_code(void *simple_ptr, uint32_t now_pos, bool is_encoder,
uint8_t *buffer, size_t size)
{
static const bool MASK_TO_ALLOWED_STATUS[8]
@@ -33,39 +33,34 @@ x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
static const uint32_t MASK_TO_BIT_NUMBER[8]
= { 0, 1, 2, 2, 3, 3, 3, 3 };
+ lzma_simple_x86 *simple = simple_ptr;
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;
+ const size_t limit = size - 5;
+ size_t 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)
+ const uint32_t 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) {
+ for (uint32_t i = 0; i < offset; ++i) {
prev_mask &= 0x77;
prev_mask <<= 1;
}
@@ -84,8 +79,6 @@ x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
uint32_t dest;
while (true) {
- uint32_t i;
-
if (is_encoder)
dest = src + (now_pos + (uint32_t)(
buffer_pos) + 5);
@@ -96,14 +89,15 @@ x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
if (prev_mask == 0)
break;
- i = MASK_TO_BIT_NUMBER[prev_mask >> 1];
+ const uint32_t i = MASK_TO_BIT_NUMBER[
+ prev_mask >> 1];
b = (uint8_t)(dest >> (24 - i * 8));
if (!Test86MSByte(b))
break;
- src = dest ^ ((1u << (32 - i * 8)) - 1);
+ src = dest ^ ((1ull << (32 - i * 8)) - 1);
}
buffer[buffer_pos + 4]
@@ -130,15 +124,17 @@ x86_code(lzma_simple *simple, uint32_t now_pos, bool is_encoder,
static lzma_ret
-x86_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
+x86_coder_init(lzma_next_coder *next, const 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);
+ &x86_code, sizeof(lzma_simple_x86), 5, 1, is_encoder);
if (ret == LZMA_OK) {
- next->coder->simple->prev_mask = 0;
- next->coder->simple->prev_pos = (uint32_t)(-5);
+ lzma_simple_coder *coder = next->coder;
+ lzma_simple_x86 *simple = coder->simple;
+ simple->prev_mask = 0;
+ simple->prev_pos = (uint32_t)(-5);
}
return ret;
@@ -146,7 +142,8 @@ x86_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
-lzma_simple_x86_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_simple_x86_encoder_init(lzma_next_coder *next,
+ const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
return x86_coder_init(next, allocator, filters, true);
@@ -154,7 +151,8 @@ lzma_simple_x86_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
extern lzma_ret
-lzma_simple_x86_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
+lzma_simple_x86_decoder_init(lzma_next_coder *next,
+ const lzma_allocator *allocator,
const lzma_filter_info *filters)
{
return x86_coder_init(next, allocator, filters, false);
diff --git a/Utilities/cmlibrhash/CMakeLists.txt b/Utilities/cmlibrhash/CMakeLists.txt
index aa280554c..6067b7dcb 100644
--- a/Utilities/cmlibrhash/CMakeLists.txt
+++ b/Utilities/cmlibrhash/CMakeLists.txt
@@ -2,7 +2,7 @@ project(librhash C)
# Disable warnings to avoid changing 3rd party code.
if(CMAKE_C_COMPILER_ID MATCHES
- "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
diff --git a/Utilities/cmlibrhash/librhash/rhash.c b/Utilities/cmlibrhash/librhash/rhash.c
index ad6249b17..34e1eb305 100644
--- a/Utilities/cmlibrhash/librhash/rhash.c
+++ b/Utilities/cmlibrhash/librhash/rhash.c
@@ -18,6 +18,8 @@
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
+#include "ustd.h" /* Need this first within CMake. */
+
#include <string.h> /* memset() */
#include <stdlib.h> /* free() */
#include <stddef.h> /* ptrdiff_t */
diff --git a/Utilities/cmlibuv/CMakeLists.txt b/Utilities/cmlibuv/CMakeLists.txt
index 4c8e2289d..2e781f155 100644
--- a/Utilities/cmlibuv/CMakeLists.txt
+++ b/Utilities/cmlibuv/CMakeLists.txt
@@ -2,7 +2,7 @@ project(libuv C)
# Disable warnings to avoid changing 3rd party code.
if(CMAKE_C_COMPILER_ID MATCHES
- "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
@@ -14,18 +14,24 @@ set(uv_libraries ${CMAKE_THREAD_LIBS_INIT})
set(uv_includes include src)
set(uv_headers
include/uv.h
- include/uv-errno.h
- include/uv-threadpool.h
- include/uv-version.h
+ include/uv/errno.h
+ include/uv/threadpool.h
+ include/uv/version.h
)
set(uv_sources
src/fs-poll.c
src/heap-inl.h
+ src/idna.c
+ src/idna.h
src/inet.c
src/queue.h
+ src/strscpy.c
+ src/strscpy.h
src/threadpool.c
+ src/timer.c
src/uv-common.c
src/uv-common.h
+ src/uv-data-getter-setters.c
src/version.c
)
if(WIN32)
@@ -44,7 +50,7 @@ if(WIN32)
_WIN32_WINNT=0x0600
)
list(APPEND uv_headers
- include/uv-win.h
+ include/uv/win.h
include/tree.h
)
list(APPEND uv_sources
@@ -66,7 +72,6 @@ if(WIN32)
src/win/poll.c
src/win/process-stdio.c
src/win/process.c
- src/win/req.c
src/win/req-inl.h
src/win/signal.c
src/win/snprintf.c
@@ -74,7 +79,6 @@ if(WIN32)
src/win/stream-inl.h
src/win/tcp.c
src/win/thread.c
- src/win/timer.c
src/win/tty.c
src/win/udp.c
src/win/util.c
@@ -88,7 +92,7 @@ else()
src/unix
)
list(APPEND uv_headers
- include/uv-unix.h
+ include/uv/unix.h
)
list(APPEND uv_sources
src/unix/async.c
@@ -109,7 +113,6 @@ else()
src/unix/stream.c
src/unix/tcp.c
src/unix/thread.c
- src/unix/timer.c
src/unix/tty.c
src/unix/udp.c
)
@@ -120,7 +123,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
perfstat
)
list(APPEND uv_headers
- include/uv-aix.h
+ include/uv/aix.h
)
list(APPEND uv_defines
_ALL_SOURCE
@@ -130,6 +133,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
)
list(APPEND uv_sources
src/unix/aix.c
+ src/unix/aix-common.c
)
endif()
@@ -137,7 +141,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
list(APPEND uv_libraries
)
list(APPEND uv_headers
- include/uv-posix.h
+ include/uv/posix.h
)
list(APPEND uv_defines
)
@@ -156,8 +160,7 @@ endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND uv_headers
- include/uv-darwin.h
- include/pthread-barrier.h
+ include/uv/darwin.h
)
list(APPEND uv_defines
_DARWIN_USE_64_BIT_INODE=1
@@ -170,14 +173,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
src/unix/fsevents.c
src/unix/kqueue.c
src/unix/proctitle.c
- src/unix/pthread-barrier.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND uv_libraries dl rt)
list(APPEND uv_headers
- include/uv-linux.h
+ include/uv/linux.h
)
list(APPEND uv_defines _GNU_SOURCE)
list(APPEND uv_sources
@@ -197,10 +199,28 @@ if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
kvm
)
list(APPEND uv_headers
- include/uv-bsd.h
+ include/uv/bsd.h
)
list(APPEND uv_sources
src/unix/bsd-ifaddrs.c
+ src/unix/bsd-proctitle.c
+ src/unix/freebsd.c
+ src/unix/kqueue.c
+ src/unix/posix-hrtime.c
+ )
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD")
+ list(APPEND uv_libraries
+ freebsd-glue
+ kvm
+ )
+ list(APPEND uv_headers
+ include/uv/bsd.h
+ )
+ list(APPEND uv_sources
+ src/unix/bsd-ifaddrs.c
+ src/unix/bsd-proctitle.c
src/unix/freebsd.c
src/unix/kqueue.c
src/unix/posix-hrtime.c
@@ -212,10 +232,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
kvm
)
list(APPEND uv_headers
- include/uv-bsd.h
+ include/uv/bsd.h
)
list(APPEND uv_sources
src/unix/bsd-ifaddrs.c
+ src/unix/bsd-proctitle.c
src/unix/netbsd.c
src/unix/kqueue.c
src/unix/posix-hrtime.c
@@ -227,10 +248,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
kvm
)
list(APPEND uv_headers
- include/uv-bsd.h
+ include/uv/bsd.h
)
list(APPEND uv_sources
src/unix/bsd-ifaddrs.c
+ src/unix/bsd-proctitle.c
src/unix/openbsd.c
src/unix/kqueue.c
src/unix/posix-hrtime.c
@@ -246,7 +268,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
rt
)
list(APPEND uv_headers
- include/uv-sunos.h
+ include/uv/sunos.h
)
list(APPEND uv_defines
__EXTENSIONS__
diff --git a/Utilities/cmlibuv/LICENSE b/Utilities/cmlibuv/LICENSE
index 41ba44c28..28f17339e 100644
--- a/Utilities/cmlibuv/LICENSE
+++ b/Utilities/cmlibuv/LICENSE
@@ -62,8 +62,8 @@ The externally maintained libraries used by libuv are:
- stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three
clause BSD license.
- - pthread-fixes.h, pthread-fixes.c, copyright Google Inc. and Sony Mobile
- Communications AB. Three clause BSD license.
+ - pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB.
+ Three clause BSD license.
- android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design
Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement
diff --git a/Utilities/cmlibuv/include/uv.h b/Utilities/cmlibuv/include/uv.h
index 38f567644..e6dc7368a 100644
--- a/Utilities/cmlibuv/include/uv.h
+++ b/Utilities/cmlibuv/include/uv.h
@@ -49,21 +49,21 @@ extern "C" {
# define UV_EXTERN /* nothing */
#endif
-#include "uv-errno.h"
-#include "uv-version.h"
+#include "uv/errno.h"
+#include "uv/version.h"
#include <stddef.h>
#include <stdio.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "stdint-msvc2008.h"
+# include "uv/stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
#if defined(_WIN32)
-# include "uv-win.h"
+# include "uv/win.h"
#else
-# include "uv-unix.h"
+# include "uv/unix.h"
#endif
/* Expand this list if necessary. */
@@ -144,6 +144,9 @@ extern "C" {
XX(ENXIO, "no such device or address") \
XX(EMLINK, "too many links") \
XX(EHOSTDOWN, "host is down") \
+ XX(EREMOTEIO, "remote I/O error") \
+ XX(ENOTTY, "inappropriate ioctl for device") \
+ XX(EFTYPE, "inappropriate file type or format") \
#define UV_HANDLE_TYPE_MAP(XX) \
XX(ASYNC, async) \
@@ -235,6 +238,7 @@ typedef struct uv_cpu_info_s uv_cpu_info_t;
typedef struct uv_interface_address_s uv_interface_address_t;
typedef struct uv_dirent_s uv_dirent_t;
typedef struct uv_passwd_s uv_passwd_t;
+typedef struct uv_utsname_s uv_utsname_t;
typedef enum {
UV_LOOP_BLOCK_SIGNAL
@@ -371,7 +375,10 @@ typedef enum {
UV_EXTERN int uv_translate_sys_error(int sys_errno);
UV_EXTERN const char* uv_strerror(int err);
+UV_EXTERN char* uv_strerror_r(int err, char* buf, size_t buflen);
+
UV_EXTERN const char* uv_err_name(int err);
+UV_EXTERN char* uv_err_name_r(int err, char* buf, size_t buflen);
#define UV_REQ_FIELDS \
@@ -380,8 +387,7 @@ UV_EXTERN const char* uv_err_name(int err);
/* read-only */ \
uv_req_type type; \
/* private */ \
- void* active_queue[2]; \
- void* reserved[4]; \
+ void* reserved[6]; \
UV_REQ_PRIVATE_FIELDS \
/* Abstract base class of all requests. */
@@ -427,7 +433,17 @@ struct uv_handle_s {
};
UV_EXTERN size_t uv_handle_size(uv_handle_type type);
+UV_EXTERN uv_handle_type uv_handle_get_type(const uv_handle_t* handle);
+UV_EXTERN const char* uv_handle_type_name(uv_handle_type type);
+UV_EXTERN void* uv_handle_get_data(const uv_handle_t* handle);
+UV_EXTERN uv_loop_t* uv_handle_get_loop(const uv_handle_t* handle);
+UV_EXTERN void uv_handle_set_data(uv_handle_t* handle, void* data);
+
UV_EXTERN size_t uv_req_size(uv_req_type type);
+UV_EXTERN void* uv_req_get_data(const uv_req_t* req);
+UV_EXTERN void uv_req_set_data(uv_req_t* req, void* data);
+UV_EXTERN uv_req_type uv_req_get_type(const uv_req_t* req);
+UV_EXTERN const char* uv_req_type_name(uv_req_type type);
UV_EXTERN int uv_is_active(const uv_handle_t* handle);
@@ -467,6 +483,8 @@ struct uv_stream_s {
UV_STREAM_FIELDS
};
+UV_EXTERN size_t uv_stream_get_write_queue_size(const uv_stream_t* stream);
+
UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
@@ -494,7 +512,7 @@ UV_EXTERN int uv_try_write(uv_stream_t* handle,
struct uv_write_s {
UV_REQ_FIELDS
uv_write_cb cb;
- uv_stream_t* send_handle;
+ uv_stream_t* send_handle; /* TODO: make private and unix-only in v2.x. */
uv_stream_t* handle;
UV_WRITE_PRIVATE_FIELDS
};
@@ -644,6 +662,8 @@ UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb);
UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
+UV_EXTERN size_t uv_udp_get_send_queue_size(const uv_udp_t* handle);
+UV_EXTERN size_t uv_udp_get_send_queue_count(const uv_udp_t* handle);
/*
@@ -712,6 +732,7 @@ UV_EXTERN int uv_pipe_getpeername(const uv_pipe_t* handle,
UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count);
UV_EXTERN int uv_pipe_pending_count(uv_pipe_t* handle);
UV_EXTERN uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle);
+UV_EXTERN int uv_pipe_chmod(uv_pipe_t* handle, int flags);
struct uv_poll_s {
@@ -723,7 +744,8 @@ struct uv_poll_s {
enum uv_poll_event {
UV_READABLE = 1,
UV_WRITABLE = 2,
- UV_DISCONNECT = 4
+ UV_DISCONNECT = 4,
+ UV_PRIORITIZED = 8
};
UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd);
@@ -852,7 +874,13 @@ typedef enum {
* flags may be specified to create a duplex data stream.
*/
UV_READABLE_PIPE = 0x10,
- UV_WRITABLE_PIPE = 0x20
+ UV_WRITABLE_PIPE = 0x20,
+
+ /*
+ * Open the child pipe handle in overlapped mode on Windows.
+ * On Unix it is silently ignored.
+ */
+ UV_OVERLAPPED_PIPE = 0x40
} uv_stdio_flags;
typedef struct uv_stdio_container_s {
@@ -907,6 +935,19 @@ typedef struct uv_process_options_s {
*/
uv_uid_t uid;
uv_gid_t gid;
+ /*
+ Libuv can set the child process' CPU affinity mask. This happens when
+ `cpumask` is non-NULL. It must point to an array of char values
+ of length `cpumask_size`, whose value must be at least that returned by
+ uv_cpumask_size(). Each byte in the mask can be either zero (false)
+ or non-zero (true) to indicate whether the corresponding processor at
+ that index is included.
+
+ If enabled on an unsupported platform, uv_spawn() will fail with
+ UV_ENOTSUP.
+ */
+ char* cpumask;
+ size_t cpumask_size;
} uv_process_options_t;
/*
@@ -940,11 +981,22 @@ enum uv_process_flags {
*/
UV_PROCESS_DETACHED = (1 << 3),
/*
+ * Hide the subprocess window that would normally be created. This option is
+ * only meaningful on Windows systems. On Unix it is silently ignored.
+ */
+ UV_PROCESS_WINDOWS_HIDE = (1 << 4),
+ /*
* Hide the subprocess console window that would normally be created. This
* option is only meaningful on Windows systems. On Unix it is silently
* ignored.
*/
- UV_PROCESS_WINDOWS_HIDE = (1 << 4)
+ UV_PROCESS_WINDOWS_HIDE_CONSOLE = (1 << 5),
+ /*
+ * Hide the subprocess GUI window that would normally be created. This
+ * option is only meaningful on Windows systems. On Unix it is silently
+ * ignored.
+ */
+ UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
};
/*
@@ -962,6 +1014,7 @@ UV_EXTERN int uv_spawn(uv_loop_t* loop,
const uv_process_options_t* options);
UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
UV_EXTERN int uv_kill(int pid, int signum);
+UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t*);
/*
@@ -983,16 +1036,18 @@ UV_EXTERN int uv_queue_work(uv_loop_t* loop,
UV_EXTERN int uv_cancel(uv_req_t* req);
+struct uv_cpu_times_s {
+ uint64_t user;
+ uint64_t nice;
+ uint64_t sys;
+ uint64_t idle;
+ uint64_t irq;
+};
+
struct uv_cpu_info_s {
char* model;
int speed;
- struct uv_cpu_times_s {
- uint64_t user;
- uint64_t nice;
- uint64_t sys;
- uint64_t idle;
- uint64_t irq;
- } cpu_times;
+ struct uv_cpu_times_s cpu_times;
};
struct uv_interface_address_s {
@@ -1017,6 +1072,16 @@ struct uv_passwd_s {
char* homedir;
};
+struct uv_utsname_s {
+ char sysname[256];
+ char release[256];
+ char version[256];
+ char machine[256];
+ /* This struct does not contain the nodename and domainname fields present in
+ the utsname type. domainname is a GNU extension. Both fields are referred
+ to as meaningless in the docs. */
+};
+
typedef enum {
UV_DIRENT_UNKNOWN,
UV_DIRENT_FILE,
@@ -1038,6 +1103,8 @@ UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
UV_EXTERN int uv_set_process_title(const char* title);
UV_EXTERN int uv_resident_set_memory(size_t* rss);
UV_EXTERN int uv_uptime(double* uptime);
+UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
+UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
typedef struct {
long tv_sec;
@@ -1069,9 +1136,22 @@ UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
+UV_EXTERN uv_pid_t uv_os_getpid(void);
+UV_EXTERN uv_pid_t uv_os_getppid(void);
+
+#define UV_PRIORITY_LOW 19
+#define UV_PRIORITY_BELOW_NORMAL 10
+#define UV_PRIORITY_NORMAL 0
+#define UV_PRIORITY_ABOVE_NORMAL -7
+#define UV_PRIORITY_HIGH -14
+#define UV_PRIORITY_HIGHEST -20
+
+UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
+UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
+UV_EXTERN int uv_cpumask_size(void);
UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
int* count);
@@ -1084,6 +1164,8 @@ UV_EXTERN int uv_os_unsetenv(const char* name);
UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
+UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
+
typedef enum {
UV_FS_UNKNOWN = -1,
@@ -1115,7 +1197,9 @@ typedef enum {
UV_FS_READLINK,
UV_FS_CHOWN,
UV_FS_FCHOWN,
- UV_FS_REALPATH
+ UV_FS_REALPATH,
+ UV_FS_COPYFILE,
+ UV_FS_LCHOWN
} uv_fs_type;
/* uv_fs_t is a subclass of uv_req_t. */
@@ -1131,6 +1215,12 @@ struct uv_fs_s {
UV_FS_PRIVATE_FIELDS
};
+UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
+UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
+UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
+UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
+UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
+
UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
UV_EXTERN int uv_fs_close(uv_loop_t* loop,
uv_fs_t* req,
@@ -1160,6 +1250,30 @@ UV_EXTERN int uv_fs_write(uv_loop_t* loop,
unsigned int nbufs,
int64_t offset,
uv_fs_cb cb);
+/*
+ * This flag can be used with uv_fs_copyfile() to return an error if the
+ * destination already exists.
+ */
+#define UV_FS_COPYFILE_EXCL 0x0001
+
+/*
+ * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
+ * If copy-on-write is not supported, a fallback copy mechanism is used.
+ */
+#define UV_FS_COPYFILE_FICLONE 0x0002
+
+/*
+ * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
+ * If copy-on-write is not supported, an error is returned.
+ */
+#define UV_FS_COPYFILE_FICLONE_FORCE 0x0004
+
+UV_EXTERN int uv_fs_copyfile(uv_loop_t* loop,
+ uv_fs_t* req,
+ const char* path,
+ const char* new_path,
+ int flags,
+ uv_fs_cb cb);
UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
uv_fs_t* req,
const char* path,
@@ -1288,6 +1402,12 @@ UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
uv_uid_t uid,
uv_gid_t gid,
uv_fs_cb cb);
+UV_EXTERN int uv_fs_lchown(uv_loop_t* loop,
+ uv_fs_t* req,
+ const char* path,
+ uv_uid_t uid,
+ uv_gid_t gid,
+ uv_fs_cb cb);
enum uv_fs_event {
@@ -1393,6 +1513,21 @@ UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size
UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
+#if defined(IF_NAMESIZE)
+# define UV_IF_NAMESIZE (IF_NAMESIZE + 1)
+#elif defined(IFNAMSIZ)
+# define UV_IF_NAMESIZE (IFNAMSIZ + 1)
+#else
+# define UV_IF_NAMESIZE (16 + 1)
+#endif
+
+UV_EXTERN int uv_if_indextoname(unsigned int ifindex,
+ char* buffer,
+ size_t* size);
+UV_EXTERN int uv_if_indextoiid(unsigned int ifindex,
+ char* buffer,
+ size_t* size);
+
UV_EXTERN int uv_exepath(char* buffer, size_t* size);
UV_EXTERN int uv_cwd(char* buffer, size_t* size);
@@ -1412,6 +1547,7 @@ UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
+UV_EXTERN int uv_mutex_init_recursive(uv_mutex_t* handle);
UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
@@ -1478,12 +1614,17 @@ struct uv_loop_s {
/* Loop reference counting. */
unsigned int active_handles;
void* handle_queue[2];
- void* active_reqs[2];
+ union {
+ void* unused[2];
+ unsigned int count;
+ } active_reqs;
/* Internal flag to signal loop stop. */
unsigned int stop_flag;
UV_LOOP_PRIVATE_FIELDS
};
+UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
+UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
/* Don't export the private CPP symbols. */
#undef UV_HANDLE_TYPE_PRIVATE
@@ -1504,6 +1645,7 @@ struct uv_loop_s {
#undef UV_SIGNAL_PRIVATE_FIELDS
#undef UV_LOOP_PRIVATE_FIELDS
#undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
+#undef UV__ERR
#ifdef __cplusplus
}
diff --git a/Utilities/cmlibuv/src/fs-poll.c b/Utilities/cmlibuv/src/fs-poll.c
index ee73d5a2e..6c82dfc1d 100644
--- a/Utilities/cmlibuv/src/fs-poll.c
+++ b/Utilities/cmlibuv/src/fs-poll.c
@@ -83,7 +83,7 @@ int uv_fs_poll_start(uv_fs_poll_t* handle,
if (err < 0)
goto error;
- ctx->timer_handle.flags |= UV__HANDLE_INTERNAL;
+ ctx->timer_handle.flags |= UV_HANDLE_INTERNAL;
uv__handle_unref(&ctx->timer_handle);
err = uv_fs_stat(loop, &ctx->fs_req, ctx->path, poll_cb);
@@ -248,7 +248,7 @@ static int statbuf_eq(const uv_stat_t* a, const uv_stat_t* b) {
#include "win/handle-inl.h"
void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle) {
- assert(handle->flags & UV__HANDLE_CLOSING);
+ assert(handle->flags & UV_HANDLE_CLOSING);
assert(!(handle->flags & UV_HANDLE_CLOSED));
uv__handle_close(handle);
}
diff --git a/Utilities/cmlibuv/src/inet.c b/Utilities/cmlibuv/src/inet.c
index 7c75e4373..58238dcbb 100644
--- a/Utilities/cmlibuv/src/inet.c
+++ b/Utilities/cmlibuv/src/inet.c
@@ -22,7 +22,7 @@
#include <string.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "stdint-msvc2008.h"
+# include "uv/stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
@@ -59,8 +59,7 @@ static int inet_ntop4(const unsigned char *src, char *dst, size_t size) {
if (l <= 0 || (size_t) l >= size) {
return UV_ENOSPC;
}
- strncpy(dst, tmp, size);
- dst[size - 1] = '\0';
+ uv__strscpy(dst, tmp, size);
return 0;
}
@@ -142,14 +141,8 @@ static int inet_ntop6(const unsigned char *src, char *dst, size_t size) {
if (best.base != -1 && (best.base + best.len) == ARRAY_SIZE(words))
*tp++ = ':';
*tp++ = '\0';
-
- /*
- * Check for overflow, copy, and we're done.
- */
- if ((size_t)(tp - tmp) > size) {
+ if (UV_E2BIG == uv__strscpy(dst, tmp, size))
return UV_ENOSPC;
- }
- strcpy(dst, tmp);
return 0;
}
diff --git a/Utilities/cmlibuv/src/threadpool.c b/Utilities/cmlibuv/src/threadpool.c
index 108934112..4258933c7 100644
--- a/Utilities/cmlibuv/src/threadpool.c
+++ b/Utilities/cmlibuv/src/threadpool.c
@@ -33,13 +33,18 @@ static uv_once_t once = UV_ONCE_INIT;
static uv_cond_t cond;
static uv_mutex_t mutex;
static unsigned int idle_threads;
+static unsigned int slow_io_work_running;
static unsigned int nthreads;
static uv_thread_t* threads;
static uv_thread_t default_threads[4];
static QUEUE exit_message;
static QUEUE wq;
-static volatile int initialized;
+static QUEUE run_slow_work_message;
+static QUEUE slow_io_pending_wq;
+static unsigned int slow_work_thread_threshold(void) {
+ return (nthreads + 1) / 2;
+}
static void uv__cancelled(struct uv__work* w) {
abort();
@@ -52,33 +57,67 @@ static void uv__cancelled(struct uv__work* w) {
static void worker(void* arg) {
struct uv__work* w;
QUEUE* q;
+ int is_slow_work;
- (void) arg;
+ uv_sem_post((uv_sem_t*) arg);
+ arg = NULL;
+ uv_mutex_lock(&mutex);
for (;;) {
- uv_mutex_lock(&mutex);
-
- while (QUEUE_EMPTY(&wq)) {
+ /* `mutex` should always be locked at this point. */
+
+ /* Keep waiting while either no work is present or only slow I/O
+ and we're at the threshold for that. */
+ while (QUEUE_EMPTY(&wq) ||
+ (QUEUE_HEAD(&wq) == &run_slow_work_message &&
+ QUEUE_NEXT(&run_slow_work_message) == &wq &&
+ slow_io_work_running >= slow_work_thread_threshold())) {
idle_threads += 1;
uv_cond_wait(&cond, &mutex);
idle_threads -= 1;
}
q = QUEUE_HEAD(&wq);
-
- if (q == &exit_message)
+ if (q == &exit_message) {
uv_cond_signal(&cond);
- else {
+ uv_mutex_unlock(&mutex);
+ break;
+ }
+
+ QUEUE_REMOVE(q);
+ QUEUE_INIT(q); /* Signal uv_cancel() that the work req is executing. */
+
+ is_slow_work = 0;
+ if (q == &run_slow_work_message) {
+ /* If we're at the slow I/O threshold, re-schedule until after all
+ other work in the queue is done. */
+ if (slow_io_work_running >= slow_work_thread_threshold()) {
+ QUEUE_INSERT_TAIL(&wq, q);
+ continue;
+ }
+
+ /* If we encountered a request to run slow I/O work but there is none
+ to run, that means it's cancelled => Start over. */
+ if (QUEUE_EMPTY(&slow_io_pending_wq))
+ continue;
+
+ is_slow_work = 1;
+ slow_io_work_running++;
+
+ q = QUEUE_HEAD(&slow_io_pending_wq);
QUEUE_REMOVE(q);
- QUEUE_INIT(q); /* Signal uv_cancel() that the work req is
- executing. */
+ QUEUE_INIT(q);
+
+ /* If there is more slow I/O work, schedule it to be run as well. */
+ if (!QUEUE_EMPTY(&slow_io_pending_wq)) {
+ QUEUE_INSERT_TAIL(&wq, &run_slow_work_message);
+ if (idle_threads > 0)
+ uv_cond_signal(&cond);
+ }
}
uv_mutex_unlock(&mutex);
- if (q == &exit_message)
- break;
-
w = QUEUE_DATA(q, struct uv__work, wq);
w->work(w);
@@ -88,12 +127,32 @@ static void worker(void* arg) {
QUEUE_INSERT_TAIL(&w->loop->wq, &w->wq);
uv_async_send(&w->loop->wq_async);
uv_mutex_unlock(&w->loop->wq_mutex);
+
+ /* Lock `mutex` since that is expected at the start of the next
+ * iteration. */
+ uv_mutex_lock(&mutex);
+ if (is_slow_work) {
+ /* `slow_io_work_running` is protected by `mutex`. */
+ slow_io_work_running--;
+ }
}
}
-static void post(QUEUE* q) {
+static void post(QUEUE* q, enum uv__work_kind kind) {
uv_mutex_lock(&mutex);
+ if (kind == UV__WORK_SLOW_IO) {
+ /* Insert into a separate queue. */
+ QUEUE_INSERT_TAIL(&slow_io_pending_wq, q);
+ if (!QUEUE_EMPTY(&run_slow_work_message)) {
+ /* Running slow I/O tasks is already scheduled => Nothing to do here.
+ The worker that runs said other task will schedule this one as well. */
+ uv_mutex_unlock(&mutex);
+ return;
+ }
+ q = &run_slow_work_message;
+ }
+
QUEUE_INSERT_TAIL(&wq, q);
if (idle_threads > 0)
uv_cond_signal(&cond);
@@ -105,10 +164,10 @@ static void post(QUEUE* q) {
UV_DESTRUCTOR(static void cleanup(void)) {
unsigned int i;
- if (initialized == 0)
+ if (nthreads == 0)
return;
- post(&exit_message);
+ post(&exit_message, UV__WORK_CPU);
for (i = 0; i < nthreads; i++)
if (uv_thread_join(threads + i))
@@ -122,7 +181,6 @@ UV_DESTRUCTOR(static void cleanup(void)) {
threads = NULL;
nthreads = 0;
- initialized = 0;
}
#endif
@@ -130,6 +188,7 @@ UV_DESTRUCTOR(static void cleanup(void)) {
static void init_threads(void) {
unsigned int i;
const char* val;
+ uv_sem_t sem;
nthreads = ARRAY_SIZE(default_threads);
val = getenv("UV_THREADPOOL_SIZE");
@@ -156,12 +215,20 @@ static void init_threads(void) {
abort();
QUEUE_INIT(&wq);
+ QUEUE_INIT(&slow_io_pending_wq);
+ QUEUE_INIT(&run_slow_work_message);
+
+ if (uv_sem_init(&sem, 0))
+ abort();
for (i = 0; i < nthreads; i++)
- if (uv_thread_create(threads + i, worker, NULL))
+ if (uv_thread_create(threads + i, worker, &sem))
abort();
- initialized = 1;
+ for (i = 0; i < nthreads; i++)
+ uv_sem_wait(&sem);
+
+ uv_sem_destroy(&sem);
}
@@ -188,13 +255,14 @@ static void init_once(void) {
void uv__work_submit(uv_loop_t* loop,
struct uv__work* w,
+ enum uv__work_kind kind,
void (*work)(struct uv__work* w),
void (*done)(struct uv__work* w, int status)) {
uv_once(&once, init_once);
w->loop = loop;
w->work = work;
w->done = done;
- post(&w->wq);
+ post(&w->wq, kind);
}
@@ -278,7 +346,11 @@ int uv_queue_work(uv_loop_t* loop,
req->loop = loop;
req->work_cb = work_cb;
req->after_work_cb = after_work_cb;
- uv__work_submit(loop, &req->work_req, uv__queue_work, uv__queue_done);
+ uv__work_submit(loop,
+ &req->work_req,
+ UV__WORK_CPU,
+ uv__queue_work,
+ uv__queue_done);
return 0;
}
diff --git a/Utilities/cmlibuv/src/unix/aix.c b/Utilities/cmlibuv/src/unix/aix.c
index 388c9cca9..337e58e0a 100644
--- a/Utilities/cmlibuv/src/unix/aix.c
+++ b/Utilities/cmlibuv/src/unix/aix.c
@@ -1,4 +1,5 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
+ *
* 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
@@ -64,11 +65,18 @@
#define RDWR_BUF_SIZE 4096
#define EQ(a,b) (strcmp(a,b) == 0)
+static uv_mutex_t process_title_mutex;
+static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static void* args_mem = NULL;
static char** process_argv = NULL;
static int process_argc = 0;
static char* process_title_ptr = NULL;
+static void init_process_title_mutex_once(void) {
+ uv_mutex_init(&process_title_mutex);
+}
+
+
int uv__platform_loop_init(uv_loop_t* loop) {
loop->fs_fd = -1;
@@ -111,7 +119,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
pc.fd = fd;
if (pollset_ctl(loop->backend_fd, &pc, 1))
- return -errno;
+ return UV__ERR(errno);
pc.cmd = PS_DELETE;
if (pollset_ctl(loop->backend_fd, &pc, 1))
@@ -316,104 +324,6 @@ update_timeout:
}
-uint64_t uv__hrtime(uv_clocktype_t type) {
- uint64_t G = 1000000000;
- timebasestruct_t t;
- read_wall_time(&t, TIMEBASE_SZ);
- time_base_to_time(&t, TIMEBASE_SZ);
- return (uint64_t) t.tb_high * G + t.tb_low;
-}
-
-
-/*
- * We could use a static buffer for the path manipulations that we need outside
- * of the function, but this function could be called by multiple consumers and
- * we don't want to potentially create a race condition in the use of snprintf.
- * There is no direct way of getting the exe path in AIX - either through /procfs
- * or through some libc APIs. The below approach is to parse the argv[0]'s pattern
- * and use it in conjunction with PATH environment variable to craft one.
- */
-int uv_exepath(char* buffer, size_t* size) {
- int res;
- char args[PATH_MAX];
- char abspath[PATH_MAX];
- size_t abspath_size;
- struct procsinfo pi;
-
- if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
-
- pi.pi_pid = getpid();
- res = getargs(&pi, sizeof(pi), args, sizeof(args));
- if (res < 0)
- return -EINVAL;
-
- /*
- * Possibilities for args:
- * i) an absolute path such as: /home/user/myprojects/nodejs/node
- * ii) a relative path such as: ./node or ../myprojects/nodejs/node
- * iii) a bare filename such as "node", after exporting PATH variable
- * to its location.
- */
-
- /* Case i) and ii) absolute or relative paths */
- if (strchr(args, '/') != NULL) {
- if (realpath(args, abspath) != abspath)
- return -errno;
-
- abspath_size = strlen(abspath);
-
- *size -= 1;
- if (*size > abspath_size)
- *size = abspath_size;
-
- memcpy(buffer, abspath, *size);
- buffer[*size] = '\0';
-
- return 0;
- } else {
- /* Case iii). Search PATH environment variable */
- char trypath[PATH_MAX];
- char *clonedpath = NULL;
- char *token = NULL;
- char *path = getenv("PATH");
-
- if (path == NULL)
- return -EINVAL;
-
- clonedpath = uv__strdup(path);
- if (clonedpath == NULL)
- return -ENOMEM;
-
- token = strtok(clonedpath, ":");
- while (token != NULL) {
- snprintf(trypath, sizeof(trypath) - 1, "%s/%s", token, args);
- if (realpath(trypath, abspath) == abspath) {
- /* Check the match is executable */
- if (access(abspath, X_OK) == 0) {
- abspath_size = strlen(abspath);
-
- *size -= 1;
- if (*size > abspath_size)
- *size = abspath_size;
-
- memcpy(buffer, abspath, *size);
- buffer[*size] = '\0';
-
- uv__free(clonedpath);
- return 0;
- }
- }
- token = strtok(NULL, ":");
- }
- uv__free(clonedpath);
-
- /* Out of tokens (path entries), and no match found */
- return -EINVAL;
- }
-}
-
-
uint64_t uv_get_free_memory(void) {
perfstat_memory_total_t mem_total;
int result = perfstat_memory_total(NULL, &mem_total, sizeof(mem_total), 1);
@@ -448,19 +358,15 @@ void uv_loadavg(double avg[3]) {
#ifdef HAVE_SYS_AHAFS_EVPRODS_H
-static char *uv__rawname(char *cp) {
- static char rawbuf[FILENAME_MAX+1];
- char *dp = rindex(cp, '/');
+static char* uv__rawname(const char* cp, char (*dst)[FILENAME_MAX+1]) {
+ char* dp;
+ dp = rindex(cp, '/');
if (dp == 0)
return 0;
- *dp = 0;
- strcpy(rawbuf, cp);
- *dp = '/';
- strcat(rawbuf, "/r");
- strcat(rawbuf, dp+1);
- return rawbuf;
+ snprintf(*dst, sizeof(*dst), "%.*s/r%s", (int) (dp - cp), cp, dp + 1);
+ return *dst;
}
@@ -489,6 +395,7 @@ static int uv__path_is_a_directory(char* filename) {
* Returns 0 if AHAFS is mounted, or an error code < 0 on failure
*/
static int uv__is_ahafs_mounted(void){
+ char rawbuf[FILENAME_MAX+1];
int rv, i = 2;
struct vmount *p;
int size_multiplier = 10;
@@ -499,22 +406,22 @@ static int uv__is_ahafs_mounted(void){
p = uv__malloc(siz);
if (p == NULL)
- return -errno;
+ return UV__ERR(errno);
/* Retrieve all mounted filesystems */
rv = mntctl(MCTL_QUERY, siz, (char*)p);
if (rv < 0)
- return -errno;
+ return UV__ERR(errno);
if (rv == 0) {
/* buffer was not large enough, reallocate to correct size */
siz = *(int*)p;
uv__free(p);
p = uv__malloc(siz);
if (p == NULL)
- return -errno;
+ return UV__ERR(errno);
rv = mntctl(MCTL_QUERY, siz, (char*)p);
if (rv < 0)
- return -errno;
+ return UV__ERR(errno);
}
/* Look for dev in filesystems mount info */
@@ -522,7 +429,7 @@ static int uv__is_ahafs_mounted(void){
obj = vmt2dataptr(vmt, VMT_OBJECT); /* device */
stub = vmt2dataptr(vmt, VMT_STUB); /* mount point */
- if (EQ(obj, dev) || EQ(uv__rawname(obj), dev) || EQ(stub, dev)) {
+ if (EQ(obj, dev) || EQ(uv__rawname(obj, &rawbuf), dev) || EQ(stub, dev)) {
uv__free(p); /* Found a match */
return 0;
}
@@ -543,7 +450,8 @@ static int uv__makedir_p(const char *dir) {
size_t len;
int err;
- snprintf(tmp, sizeof(tmp),"%s",dir);
+ /* TODO(bnoordhuis) Check uv__strscpy() return value. */
+ uv__strscpy(tmp, dir, sizeof(tmp));
len = strlen(tmp);
if (tmp[len - 1] == '/')
tmp[len - 1] = 0;
@@ -585,7 +493,7 @@ static int uv__make_subdirs_p(const char *filename) {
rc = uv__makedir_p(cmd);
if (rc == -1 && errno != EEXIST){
- return -errno;
+ return UV__ERR(errno);
}
return rc;
@@ -612,7 +520,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) {
sprintf(mon_file, "/aha/fs/modFile.monFactory");
if ((strlen(mon_file) + strlen(filename) + 5) > PATH_MAX)
- return -ENAMETOOLONG;
+ return UV_ENAMETOOLONG;
/* Make the necessary subdirectories for the monitor file */
rc = uv__make_subdirs_p(filename);
@@ -627,7 +535,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) {
/* Open the monitor file, creating it if necessary */
*fd = open(mon_file, O_CREAT|O_RDWR);
if (*fd < 0)
- return -errno;
+ return UV__ERR(errno);
/* Write out the monitoring specifications.
* In this case, we are monitoring for a state change event type
@@ -647,8 +555,8 @@ static int uv__setup_ahafs(const char* filename, int *fd) {
sprintf(mon_file_write_string, "CHANGED=YES;WAIT_TYPE=WAIT_IN_SELECT;INFO_LVL=1");
rc = write(*fd, mon_file_write_string, strlen(mon_file_write_string)+1);
- if (rc < 0)
- return -errno;
+ if (rc < 0 && errno != EBUSY)
+ return UV__ERR(errno);
return 0;
}
@@ -792,9 +700,9 @@ static void uv__ahafs_event(uv_loop_t* loop, uv__io_t* event_watch, unsigned int
else
p++;
}
- strncpy(fname, p, sizeof(fname) - 1);
- /* Just in case */
- fname[sizeof(fname) - 1] = '\0';
+
+ /* TODO(bnoordhuis) Check uv__strscpy() return value. */
+ uv__strscpy(fname, p, sizeof(fname));
handle->cb(handle, fname, events, 0);
}
@@ -806,7 +714,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
return 0;
#else
- return -ENOSYS;
+ return UV_ENOSYS;
#endif
}
@@ -820,12 +728,19 @@ int uv_fs_event_start(uv_fs_event_t* handle,
char cwd[PATH_MAX];
char absolute_path[PATH_MAX];
char readlink_cwd[PATH_MAX];
+ struct timeval zt;
+ fd_set pollfd;
/* Figure out whether filename is absolute or not */
- if (filename[0] == '/') {
+ if (filename[0] == '\0') {
+ /* Missing a pathname */
+ return UV_ENOENT;
+ }
+ else if (filename[0] == '/') {
/* We have absolute pathname */
- snprintf(absolute_path, sizeof(absolute_path), "%s", filename);
+ /* TODO(bnoordhuis) Check uv__strscpy() return value. */
+ uv__strscpy(absolute_path, filename, sizeof(absolute_path));
} else {
/* We have a relative pathname, compose the absolute pathname */
snprintf(cwd, sizeof(cwd), "/proc/%lu/cwd", (unsigned long) getpid());
@@ -855,12 +770,22 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv__io_init(&handle->event_watcher, uv__ahafs_event, fd);
handle->path = uv__strdup(filename);
handle->cb = cb;
+ handle->dir_filename = NULL;
uv__io_start(handle->loop, &handle->event_watcher, POLLIN);
+ /* AHAFS wants someone to poll for it to start mointoring.
+ * so kick-start it so that we don't miss an event in the
+ * eventuality of an event that occurs in the current loop. */
+ do {
+ memset(&zt, 0, sizeof(zt));
+ FD_ZERO(&pollfd);
+ FD_SET(fd, &pollfd);
+ rc = select(fd + 1, &pollfd, NULL, NULL, &zt);
+ } while (rc == -1 && errno == EINTR);
return 0;
#else
- return -ENOSYS;
+ return UV_ENOSYS;
#endif
}
@@ -885,7 +810,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
return 0;
#else
- return -ENOSYS;
+ return UV_ENOSYS;
#endif
}
@@ -950,7 +875,10 @@ int uv_set_process_title(const char* title) {
*/
new_title = uv__strdup(title);
if (new_title == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
+
+ uv_once(&process_title_mutex_once, init_process_title_mutex_once);
+ uv_mutex_lock(&process_title_mutex);
/* If this is the first time this is set,
* don't free and set argv[1] to NULL.
@@ -964,19 +892,30 @@ int uv_set_process_title(const char* title) {
if (process_argc > 1)
process_argv[1] = NULL;
+ uv_mutex_unlock(&process_title_mutex);
+
return 0;
}
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
- len = strlen(process_argv[0]);
if (buffer == NULL || size == 0)
- return -EINVAL;
- else if (size <= len)
- return -ENOBUFS;
+ return UV_EINVAL;
+
+ uv_once(&process_title_mutex_once, init_process_title_mutex_once);
+ uv_mutex_lock(&process_title_mutex);
+
+ len = strlen(process_argv[0]);
+ if (size <= len) {
+ uv_mutex_unlock(&process_title_mutex);
+ return UV_ENOBUFS;
+ }
+
+ memcpy(buffer, process_argv[0], len);
+ buffer[len] = '\0';
- memcpy(buffer, process_argv[0], len + 1);
+ uv_mutex_unlock(&process_title_mutex);
return 0;
}
@@ -998,10 +937,10 @@ int uv_resident_set_memory(size_t* rss) {
fd = open(pp, O_RDONLY);
if (fd == -1)
- return -errno;
+ return UV__ERR(errno);
/* FIXME(bnoordhuis) Handle EINTR. */
- err = -EINVAL;
+ err = UV_EINVAL;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
*rss = (size_t)psinfo.pr_rssize * 1024;
err = 0;
@@ -1017,6 +956,7 @@ int uv_uptime(double* uptime) {
size_t entries = 0;
time_t boot_time;
+ boot_time = 0;
utmpname(UTMP_FILE);
setutent();
@@ -1031,7 +971,7 @@ int uv_uptime(double* uptime) {
endutent();
if (boot_time == 0)
- return -ENOSYS;
+ return UV_ENOSYS;
*uptime = time(NULL) - boot_time;
return 0;
@@ -1047,30 +987,31 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
if (result == -1) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0);
if (result == -1) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
ps_cpus = (perfstat_cpu_t*) uv__malloc(ncpus * sizeof(perfstat_cpu_t));
if (!ps_cpus) {
- return -ENOMEM;
+ return UV_ENOMEM;
}
- strcpy(cpu_id.name, FIRST_CPU);
+ /* TODO(bnoordhuis) Check uv__strscpy() return value. */
+ uv__strscpy(cpu_id.name, FIRST_CPU, sizeof(cpu_id.name));
result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus);
if (result == -1) {
uv__free(ps_cpus);
- return -ENOSYS;
+ return UV_ENOSYS;
}
*cpu_infos = (uv_cpu_info_t*) uv__malloc(ncpus * sizeof(uv_cpu_info_t));
if (!*cpu_infos) {
uv__free(ps_cpus);
- return -ENOMEM;
+ return UV_ENOMEM;
}
*count = ncpus;
@@ -1093,130 +1034,6 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
}
-void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
- int i;
-
- for (i = 0; i < count; ++i) {
- uv__free(cpu_infos[i].model);
- }
-
- uv__free(cpu_infos);
-}
-
-
-int uv_interface_addresses(uv_interface_address_t** addresses,
- int* count) {
- uv_interface_address_t* address;
- int sockfd, size = 1;
- struct ifconf ifc;
- struct ifreq *ifr, *p, flg;
-
- *count = 0;
-
- if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {
- return -errno;
- }
-
- if (ioctl(sockfd, SIOCGSIZIFCONF, &size) == -1) {
- uv__close(sockfd);
- return -errno;
- }
-
- ifc.ifc_req = (struct ifreq*)uv__malloc(size);
- ifc.ifc_len = size;
- if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
- uv__close(sockfd);
- return -errno;
- }
-
-#define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p))
-
- /* Count all up and running ipv4/ipv6 addresses */
- ifr = ifc.ifc_req;
- while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) {
- p = ifr;
- ifr = (struct ifreq*)
- ((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr));
-
- if (!(p->ifr_addr.sa_family == AF_INET6 ||
- p->ifr_addr.sa_family == AF_INET))
- continue;
-
- memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
- if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
- uv__close(sockfd);
- return -errno;
- }
-
- if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
- continue;
-
- (*count)++;
- }
-
- /* Alloc the return interface structs */
- *addresses = (uv_interface_address_t*)
- uv__malloc(*count * sizeof(uv_interface_address_t));
- if (!(*addresses)) {
- uv__close(sockfd);
- return -ENOMEM;
- }
- address = *addresses;
-
- ifr = ifc.ifc_req;
- while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) {
- p = ifr;
- ifr = (struct ifreq*)
- ((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr));
-
- if (!(p->ifr_addr.sa_family == AF_INET6 ||
- p->ifr_addr.sa_family == AF_INET))
- continue;
-
- memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
- if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
- uv__close(sockfd);
- return -ENOSYS;
- }
-
- if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
- continue;
-
- /* All conditions above must match count loop */
-
- address->name = uv__strdup(p->ifr_name);
-
- if (p->ifr_addr.sa_family == AF_INET6) {
- address->address.address6 = *((struct sockaddr_in6*) &p->ifr_addr);
- } else {
- address->address.address4 = *((struct sockaddr_in*) &p->ifr_addr);
- }
-
- /* TODO: Retrieve netmask using SIOCGIFNETMASK ioctl */
-
- address->is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0;
-
- address++;
- }
-
-#undef ADDR_SIZE
-
- uv__close(sockfd);
- return 0;
-}
-
-
-void uv_free_interface_addresses(uv_interface_address_t* addresses,
- int count) {
- int i;
-
- for (i = 0; i < count; ++i) {
- uv__free(addresses[i].name);
- }
-
- uv__free(addresses);
-}
-
void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
struct pollfd* events;
uintptr_t i;
diff --git a/Utilities/cmlibuv/src/unix/android-ifaddrs.c b/Utilities/cmlibuv/src/unix/android-ifaddrs.c
index 30f681b7d..99fb25a43 100644
--- a/Utilities/cmlibuv/src/unix/android-ifaddrs.c
+++ b/Utilities/cmlibuv/src/unix/android-ifaddrs.c
@@ -23,7 +23,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "android-ifaddrs.h"
+#include "uv/android-ifaddrs.h"
#include "uv-common.h"
#include <string.h>
@@ -43,9 +43,10 @@ typedef struct NetlinkList
unsigned int m_size;
} NetlinkList;
-static int netlink_socket(void)
+static int netlink_socket(pid_t *p_pid)
{
struct sockaddr_nl l_addr;
+ socklen_t l_len;
int l_socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if(l_socket < 0)
@@ -61,6 +62,14 @@ static int netlink_socket(void)
return -1;
}
+ l_len = sizeof(l_addr);
+ if(getsockname(l_socket, (struct sockaddr *)&l_addr, &l_len) < 0)
+ {
+ close(l_socket);
+ return -1;
+ }
+ *p_pid = l_addr.nl_pid;
+
return l_socket;
}
@@ -128,7 +137,7 @@ static int netlink_recv(int p_socket, void *p_buffer, size_t p_len)
}
}
-static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_done)
+static struct nlmsghdr *getNetlinkResponse(int p_socket, pid_t p_pid, int *p_size, int *p_done)
{
size_t l_size = 4096;
void *l_buffer = NULL;
@@ -153,11 +162,10 @@ static struct nlmsghdr *getNetlinkResponse(int p_socket, int *p_size, int *p_don
}
if(l_read >= 0)
{
- pid_t l_pid = getpid();
struct nlmsghdr *l_hdr;
for(l_hdr = (struct nlmsghdr *)l_buffer; NLMSG_OK(l_hdr, (unsigned int)l_read); l_hdr = (struct nlmsghdr *)NLMSG_NEXT(l_hdr, l_read))
{
- if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket)
+ if((pid_t)l_hdr->nlmsg_pid != p_pid || (int)l_hdr->nlmsg_seq != p_socket)
{
continue;
}
@@ -207,7 +215,7 @@ static void freeResultList(NetlinkList *p_list)
}
}
-static NetlinkList *getResultList(int p_socket, int p_request)
+static NetlinkList *getResultList(int p_socket, int p_request, pid_t p_pid)
{
int l_size;
int l_done;
@@ -227,7 +235,7 @@ static NetlinkList *getResultList(int p_socket, int p_request)
{
NetlinkList *l_item;
- struct nlmsghdr *l_hdr = getNetlinkResponse(p_socket, &l_size, &l_done);
+ struct nlmsghdr *l_hdr = getNetlinkResponse(p_socket, p_pid, &l_size, &l_done);
/* Error */
if(!l_hdr)
{
@@ -449,7 +457,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
char *l_name;
char *l_addr;
- for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
+ for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
{
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
if(l_info->ifa_family == AF_PACKET)
@@ -471,7 +479,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
l_addrSize += NLMSG_ALIGN(calcAddrLen(l_info->ifa_family, l_rtaDataSize));
break;
case IFA_LABEL:
- l_nameSize += NLMSG_ALIGN(l_rtaSize + 1);
+ l_nameSize += NLMSG_ALIGN(l_rtaDataSize + 1);
break;
default:
break;
@@ -496,7 +504,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
}
l_rtaSize = NLMSG_PAYLOAD(p_hdr, sizeof(struct ifaddrmsg));
- for(l_rta = IFLA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
+ for(l_rta = IFA_RTA(l_info); RTA_OK(l_rta, l_rtaSize); l_rta = RTA_NEXT(l_rta, l_rtaSize))
{
void *l_rtaData = RTA_DATA(l_rta);
size_t l_rtaDataSize = RTA_PAYLOAD(l_rta);
@@ -559,7 +567,7 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
{
unsigned l_maxPrefix = (l_entry->ifa_addr->sa_family == AF_INET ? 32 : 128);
unsigned l_prefix = (l_info->ifa_prefixlen > l_maxPrefix ? l_maxPrefix : l_info->ifa_prefixlen);
- char l_mask[16] = {0};
+ unsigned char l_mask[16] = {0};
unsigned i;
for(i=0; i<(l_prefix/8); ++i)
{
@@ -578,18 +586,17 @@ static int interpretAddr(struct nlmsghdr *p_hdr, struct ifaddrs **p_resultList,
return 0;
}
-static int interpretLinks(int p_socket, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList)
+static int interpretLinks(int p_socket, pid_t p_pid, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList)
{
int l_numLinks = 0;
- pid_t l_pid = getpid();
for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next)
{
unsigned int l_nlsize = p_netlinkList->m_size;
struct nlmsghdr *l_hdr;
for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize))
{
- if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket)
+ if((pid_t)l_hdr->nlmsg_pid != p_pid || (int)l_hdr->nlmsg_seq != p_socket)
{
continue;
}
@@ -612,16 +619,15 @@ static int interpretLinks(int p_socket, NetlinkList *p_netlinkList, struct ifadd
return l_numLinks;
}
-static int interpretAddrs(int p_socket, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList, int p_numLinks)
+static int interpretAddrs(int p_socket, pid_t p_pid, NetlinkList *p_netlinkList, struct ifaddrs **p_resultList, int p_numLinks)
{
- pid_t l_pid = getpid();
for(; p_netlinkList; p_netlinkList = p_netlinkList->m_next)
{
unsigned int l_nlsize = p_netlinkList->m_size;
struct nlmsghdr *l_hdr;
for(l_hdr = p_netlinkList->m_data; NLMSG_OK(l_hdr, l_nlsize); l_hdr = NLMSG_NEXT(l_hdr, l_nlsize))
{
- if((pid_t)l_hdr->nlmsg_pid != l_pid || (int)l_hdr->nlmsg_seq != p_socket)
+ if((pid_t)l_hdr->nlmsg_pid != p_pid || (int)l_hdr->nlmsg_seq != p_socket)
{
continue;
}
@@ -648,6 +654,7 @@ int getifaddrs(struct ifaddrs **ifap)
int l_socket;
int l_result;
int l_numLinks;
+ pid_t l_pid;
NetlinkList *l_linkResults;
NetlinkList *l_addrResults;
@@ -657,20 +664,20 @@ int getifaddrs(struct ifaddrs **ifap)
}
*ifap = NULL;
- l_socket = netlink_socket();
+ l_socket = netlink_socket(&l_pid);
if(l_socket < 0)
{
return -1;
}
- l_linkResults = getResultList(l_socket, RTM_GETLINK);
+ l_linkResults = getResultList(l_socket, RTM_GETLINK, l_pid);
if(!l_linkResults)
{
close(l_socket);
return -1;
}
- l_addrResults = getResultList(l_socket, RTM_GETADDR);
+ l_addrResults = getResultList(l_socket, RTM_GETADDR, l_pid);
if(!l_addrResults)
{
close(l_socket);
@@ -679,8 +686,8 @@ int getifaddrs(struct ifaddrs **ifap)
}
l_result = 0;
- l_numLinks = interpretLinks(l_socket, l_linkResults, ifap);
- if(l_numLinks == -1 || interpretAddrs(l_socket, l_addrResults, ifap, l_numLinks) == -1)
+ l_numLinks = interpretLinks(l_socket, l_pid, l_linkResults, ifap);
+ if(l_numLinks == -1 || interpretAddrs(l_socket, l_pid, l_addrResults, ifap, l_numLinks) == -1)
{
l_result = -1;
}
diff --git a/Utilities/cmlibuv/src/unix/async.c b/Utilities/cmlibuv/src/unix/async.c
index 45c088ea1..0b450ae0d 100644
--- a/Utilities/cmlibuv/src/unix/async.c
+++ b/Utilities/cmlibuv/src/unix/async.c
@@ -166,7 +166,7 @@ static int uv__async_start(uv_loop_t* loop) {
pipefd[0] = err;
pipefd[1] = -1;
}
- else if (err == -ENOSYS) {
+ else if (err == UV_ENOSYS) {
err = uv__make_pipe(pipefd, UV__F_NONBLOCK);
#if defined(__linux__)
/* Save a file descriptor by opening one of the pipe descriptors as
@@ -240,7 +240,7 @@ static int uv__async_eventfd(void) {
return fd;
if (errno != ENOSYS)
- return -errno;
+ return UV__ERR(errno);
no_eventfd2 = 1;
@@ -257,7 +257,7 @@ skip_eventfd2:
}
if (errno != ENOSYS)
- return -errno;
+ return UV__ERR(errno);
no_eventfd = 1;
@@ -265,5 +265,5 @@ skip_eventfd:
#endif
- return -ENOSYS;
+ return UV_ENOSYS;
}
diff --git a/Utilities/cmlibuv/src/unix/atomic-ops.h b/Utilities/cmlibuv/src/unix/atomic-ops.h
index 9dac2557f..be741dcb7 100644
--- a/Utilities/cmlibuv/src/unix/atomic-ops.h
+++ b/Utilities/cmlibuv/src/unix/atomic-ops.h
@@ -20,7 +20,6 @@
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#include <atomic.h>
-#define __sync_val_compare_and_swap(p, o, n) atomic_cas_ptr(p, o, n)
#endif
UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval));
@@ -38,7 +37,7 @@ UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval)) {
: "r" (newval), "0" (oldval)
: "memory");
return out;
-#elif defined(_AIX) && defined(__xlC__)
+#elif defined(_AIX) && (defined(__xlC__) || defined(__ibmxl__))
const int out = (*(volatile int*) ptr);
__compare_and_swap(ptr, &oldval, newval);
return out;
@@ -49,6 +48,8 @@ UV_UNUSED(static int cmpxchgi(int* ptr, int oldval, int newval)) {
return oldval;
else
return op4;
+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+ return atomic_cas_uint(ptr, oldval, newval);
#else
return __sync_val_compare_and_swap(ptr, oldval, newval);
#endif
@@ -62,7 +63,7 @@ UV_UNUSED(static long cmpxchgl(long* ptr, long oldval, long newval)) {
: "r" (newval), "0" (oldval)
: "memory");
return out;
-#elif defined(_AIX) && defined(__xlC__)
+#elif defined(_AIX) && (defined(__xlC__) || defined(__ibmxl__))
const long out = (*(volatile int*) ptr);
# if defined(__64BIT__)
__compare_and_swaplp(ptr, &oldval, newval);
@@ -83,6 +84,8 @@ UV_UNUSED(static long cmpxchgl(long* ptr, long oldval, long newval)) {
return oldval;
else
return op4;
+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+ return atomic_cas_ulong(ptr, oldval, newval);
#else
return __sync_val_compare_and_swap(ptr, oldval, newval);
#endif
diff --git a/Utilities/cmlibuv/src/unix/bsd-ifaddrs.c b/Utilities/cmlibuv/src/unix/bsd-ifaddrs.c
index 414789451..3c2253f0c 100644
--- a/Utilities/cmlibuv/src/unix/bsd-ifaddrs.c
+++ b/Utilities/cmlibuv/src/unix/bsd-ifaddrs.c
@@ -31,11 +31,20 @@
#include <net/if_dl.h>
#endif
-static int uv__ifaddr_exclude(struct ifaddrs *ent) {
+static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
return 1;
if (ent->ifa_addr == NULL)
return 1;
+#if !defined(__CYGWIN__) && !defined(__MSYS__)
+ /*
+ * If `exclude_type` is `UV__EXCLUDE_IFPHYS`, just see whether `sa_family`
+ * equals to `AF_LINK` or not. Otherwise, the result depends on the operation
+ * system with `AF_LINK` or `PF_INET`.
+ */
+ if (exclude_type == UV__EXCLUDE_IFPHYS)
+ return (ent->ifa_addr->sa_family != AF_LINK);
+#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
/*
* On BSD getifaddrs returns information related to the raw underlying
@@ -44,7 +53,8 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent) {
if (ent->ifa_addr->sa_family == AF_LINK)
return 1;
#elif defined(__NetBSD__) || defined(__OpenBSD__)
- if (ent->ifa_addr->sa_family != PF_INET)
+ if (ent->ifa_addr->sa_family != PF_INET &&
+ ent->ifa_addr->sa_family != PF_INET6)
return 1;
#endif
return 0;
@@ -56,29 +66,35 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
uv_interface_address_t* address;
int i;
- if (getifaddrs(&addrs) != 0)
- return -errno;
-
*count = 0;
+ *addresses = NULL;
+
+ if (getifaddrs(&addrs) != 0)
+ return UV__ERR(errno);
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
- if (uv__ifaddr_exclude(ent))
+ if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
continue;
(*count)++;
}
+ if (*count == 0) {
+ freeifaddrs(addrs);
+ return 0;
+ }
+
*addresses = uv__malloc(*count * sizeof(**addresses));
if (*addresses == NULL) {
freeifaddrs(addrs);
- return -ENOMEM;
+ return UV_ENOMEM;
}
address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
- if (uv__ifaddr_exclude(ent))
+ if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
continue;
address->name = uv__strdup(ent->ifa_name);
@@ -102,21 +118,23 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
/* Fill in physical addresses for each interface */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
- if (uv__ifaddr_exclude(ent))
+ if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFPHYS))
continue;
address = *addresses;
for (i = 0; i < *count; i++) {
- if (strcmp(address->name, ent->ifa_name) == 0) {
#if defined(__CYGWIN__) || defined(__MSYS__)
- memset(address->phys_addr, 0, sizeof(address->phys_addr));
+ memset(address->phys_addr, 0, sizeof(address->phys_addr));
#else
+ if (strcmp(address->name, ent->ifa_name) == 0) {
struct sockaddr_dl* sa_addr;
sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
-#endif
+ } else {
+ memset(address->phys_addr, 0, sizeof(address->phys_addr));
}
+#endif
address++;
}
}
diff --git a/Utilities/cmlibuv/src/unix/core.c b/Utilities/cmlibuv/src/unix/core.c
index 30cdaef7b..a8d6adb42 100644
--- a/Utilities/cmlibuv/src/unix/core.c
+++ b/Utilities/cmlibuv/src/unix/core.c
@@ -28,7 +28,6 @@
#include <errno.h>
#include <assert.h>
#include <unistd.h>
-#include <sys/param.h> /* MAXHOSTNAMELEN on Linux and the BSDs */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -41,6 +40,8 @@
#include <sys/uio.h> /* writev */
#include <sys/resource.h> /* getrusage */
#include <pwd.h>
+#include <sched.h>
+#include <sys/utsname.h>
#ifdef __sun
# include <netdb.h> /* MAXHOSTNAMELEN on Solaris */
@@ -59,13 +60,21 @@
#if defined(__DragonFly__) || \
defined(__FreeBSD__) || \
- defined(__FreeBSD_kernel__)
+ defined(__FreeBSD_kernel__) || \
+ defined(__NetBSD__)
# include <sys/sysctl.h>
# include <sys/filio.h>
# include <sys/wait.h>
+# include <sys/param.h>
+# include <sys/cpuset.h>
# define UV__O_CLOEXEC O_CLOEXEC
# if defined(__FreeBSD__) && __FreeBSD__ >= 10
# define uv__accept4 accept4
+# endif
+# if defined(__NetBSD__)
+# define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
+# endif
+# if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
# define UV__SOCK_NONBLOCK SOCK_NONBLOCK
# define UV__SOCK_CLOEXEC SOCK_CLOEXEC
# endif
@@ -82,6 +91,10 @@
#include <sys/ioctl.h>
#endif
+#if !defined(__MVS__)
+#include <sys/param.h> /* MAXHOSTNAMELEN on Linux and the BSDs */
+#endif
+
/* Fallback for the maximum hostname length */
#ifndef MAXHOSTNAMELEN
# define MAXHOSTNAMELEN 256
@@ -107,7 +120,7 @@ uint64_t uv_hrtime(void) {
void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
assert(!uv__is_closing(handle));
- handle->flags |= UV_CLOSING;
+ handle->flags |= UV_HANDLE_CLOSING;
handle->close_cb = close_cb;
switch (handle->type) {
@@ -165,8 +178,8 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
case UV_SIGNAL:
uv__signal_close((uv_signal_t*) handle);
- /* Signal handles may not be closed immediately. The signal code will */
- /* itself close uv__make_close_pending whenever appropriate. */
+ /* Signal handles may not be closed immediately. The signal code will
+ * itself close uv__make_close_pending whenever appropriate. */
return;
default:
@@ -182,14 +195,14 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) {
socklen_t len;
if (handle == NULL || value == NULL)
- return -EINVAL;
+ return UV_EINVAL;
if (handle->type == UV_TCP || handle->type == UV_NAMED_PIPE)
fd = uv__stream_fd((uv_stream_t*) handle);
else if (handle->type == UV_UDP)
fd = ((uv_udp_t *) handle)->io_watcher.fd;
else
- return -ENOTSUP;
+ return UV_ENOTSUP;
len = sizeof(*value);
@@ -199,14 +212,14 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) {
r = setsockopt(fd, SOL_SOCKET, optname, (const void*) value, len);
if (r < 0)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
void uv__make_close_pending(uv_handle_t* handle) {
- assert(handle->flags & UV_CLOSING);
- assert(!(handle->flags & UV_CLOSED));
+ assert(handle->flags & UV_HANDLE_CLOSING);
+ assert(!(handle->flags & UV_HANDLE_CLOSED));
handle->next_closing = handle->loop->closing_handles;
handle->loop->closing_handles = handle;
}
@@ -232,15 +245,17 @@ int uv__getiovmax(void) {
static void uv__finish_close(uv_handle_t* handle) {
- /* Note: while the handle is in the UV_CLOSING state now, it's still possible
- * for it to be active in the sense that uv__is_active() returns true.
+ /* Note: while the handle is in the UV_HANDLE_CLOSING state now, it's still
+ * possible for it to be active in the sense that uv__is_active() returns
+ * true.
+ *
* A good example is when the user calls uv_shutdown(), immediately followed
* by uv_close(). The handle is considered active at this point because the
* completion of the shutdown req is still pending.
*/
- assert(handle->flags & UV_CLOSING);
- assert(!(handle->flags & UV_CLOSED));
- handle->flags |= UV_CLOSED;
+ assert(handle->flags & UV_HANDLE_CLOSING);
+ assert(!(handle->flags & UV_HANDLE_CLOSED));
+ handle->flags |= UV_HANDLE_CLOSED;
switch (handle->type) {
case UV_PREPARE:
@@ -409,12 +424,12 @@ int uv__socket(int domain, int type, int protocol) {
return sockfd;
if (errno != EINVAL)
- return -errno;
+ return UV__ERR(errno);
#endif
sockfd = socket(domain, type, protocol);
if (sockfd == -1)
- return -errno;
+ return UV__ERR(errno);
err = uv__nonblock(sockfd, 1);
if (err == 0)
@@ -459,7 +474,9 @@ int uv__accept(int sockfd) {
assert(sockfd >= 0);
while (1) {
-#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD__ >= 10)
+#if defined(__linux__) || \
+ (defined(__FreeBSD__) && __FreeBSD__ >= 10) || \
+ defined(__NetBSD__)
static int no_accept4;
if (no_accept4)
@@ -476,7 +493,7 @@ int uv__accept(int sockfd) {
continue;
if (errno != ENOSYS)
- return -errno;
+ return UV__ERR(errno);
no_accept4 = 1;
skip:
@@ -486,7 +503,7 @@ skip:
if (peerfd == -1) {
if (errno == EINTR)
continue;
- return -errno;
+ return UV__ERR(errno);
}
err = uv__cloexec(peerfd, 1);
@@ -512,8 +529,8 @@ int uv__close_nocheckstdio(int fd) {
saved_errno = errno;
rc = close(fd);
if (rc == -1) {
- rc = -errno;
- if (rc == -EINTR || rc == -EINPROGRESS)
+ rc = UV__ERR(errno);
+ if (rc == UV_EINTR || rc == UV__ERR(EINPROGRESS))
rc = 0; /* The close is in progress, not an error. */
errno = saved_errno;
}
@@ -525,7 +542,7 @@ int uv__close_nocheckstdio(int fd) {
int uv__close(int fd) {
assert(fd > STDERR_FILENO); /* Catch stdio close bugs. */
#if defined(__MVS__)
- epoll_file_close(fd);
+ SAVE_ERRNO(epoll_file_close(fd));
#endif
return uv__close_nocheckstdio(fd);
}
@@ -539,7 +556,7 @@ int uv__nonblock_ioctl(int fd, int set) {
while (r == -1 && errno == EINTR);
if (r)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -554,7 +571,7 @@ int uv__cloexec_ioctl(int fd, int set) {
while (r == -1 && errno == EINTR);
if (r)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -570,7 +587,7 @@ int uv__nonblock_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR);
if (r == -1)
- return -errno;
+ return UV__ERR(errno);
/* Bail out now if already set/clear. */
if (!!(r & O_NONBLOCK) == !!set)
@@ -586,7 +603,7 @@ int uv__nonblock_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR);
if (r)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -601,7 +618,7 @@ int uv__cloexec_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR);
if (r == -1)
- return -errno;
+ return UV__ERR(errno);
/* Bail out now if already set/clear. */
if (!!(r & FD_CLOEXEC) == !!set)
@@ -617,33 +634,12 @@ int uv__cloexec_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR);
if (r)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
-/* This function is not execve-safe, there is a race window
- * between the call to dup() and fcntl(FD_CLOEXEC).
- */
-int uv__dup(int fd) {
- int err;
-
- fd = dup(fd);
-
- if (fd == -1)
- return -errno;
-
- err = uv__cloexec(fd, 1);
- if (err) {
- uv__close(fd);
- return err;
- }
-
- return fd;
-}
-
-
ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
struct cmsghdr* cmsg;
ssize_t rc;
@@ -656,10 +652,10 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
if (rc != -1)
return rc;
if (errno != EINVAL)
- return -errno;
+ return UV__ERR(errno);
rc = recvmsg(fd, msg, flags);
if (rc == -1)
- return -errno;
+ return UV__ERR(errno);
no_msg_cmsg_cloexec = 1;
} else {
rc = recvmsg(fd, msg, flags);
@@ -668,7 +664,7 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
rc = recvmsg(fd, msg, flags);
#endif
if (rc == -1)
- return -errno;
+ return UV__ERR(errno);
if (msg->msg_controllen == 0)
return rc;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg))
@@ -684,10 +680,10 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
int uv_cwd(char* buffer, size_t* size) {
if (buffer == NULL || size == NULL)
- return -EINVAL;
+ return UV_EINVAL;
if (getcwd(buffer, *size) == NULL)
- return -errno;
+ return UV__ERR(errno);
*size = strlen(buffer);
if (*size > 1 && buffer[*size - 1] == '/') {
@@ -701,7 +697,7 @@ int uv_cwd(char* buffer, size_t* size) {
int uv_chdir(const char* dir) {
if (chdir(dir))
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -738,11 +734,11 @@ int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) {
break;
default:
- return -EINVAL;
+ return UV_EINVAL;
}
if (uv__is_closing(handle) || fd_out == -1)
- return -EBADF;
+ return UV_EBADF;
*fd = fd_out;
return 0;
@@ -835,7 +831,7 @@ void uv__io_init(uv__io_t* w, uv__io_cb cb, int fd) {
void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
- assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP)));
+ assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
assert(0 != events);
assert(w->fd >= 0);
assert(w->fd < INT_MAX);
@@ -863,7 +859,7 @@ void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
- assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP)));
+ assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
assert(0 != events);
if (w->fd == -1)
@@ -895,7 +891,7 @@ void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
void uv__io_close(uv_loop_t* loop, uv__io_t* w) {
- uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP);
+ uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
QUEUE_REMOVE(&w->pending_queue);
/* Remove stale events for this file descriptor */
@@ -910,17 +906,22 @@ void uv__io_feed(uv_loop_t* loop, uv__io_t* w) {
int uv__io_active(const uv__io_t* w, unsigned int events) {
- assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP)));
+ assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
assert(0 != events);
return 0 != (w->pevents & events);
}
+int uv__fd_exists(uv_loop_t* loop, int fd) {
+ return (unsigned) fd < loop->nwatchers && loop->watchers[fd] != NULL;
+}
+
+
int uv_getrusage(uv_rusage_t* rusage) {
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage))
- return -errno;
+ return UV__ERR(errno);
rusage->ru_utime.tv_sec = usage.ru_utime.tv_sec;
rusage->ru_utime.tv_usec = usage.ru_utime.tv_usec;
@@ -962,7 +963,7 @@ int uv__open_cloexec(const char* path, int flags) {
return fd;
if (errno != EINVAL)
- return -errno;
+ return UV__ERR(errno);
/* O_CLOEXEC not supported. */
no_cloexec = 1;
@@ -971,7 +972,7 @@ int uv__open_cloexec(const char* path, int flags) {
fd = open(path, flags);
if (fd == -1)
- return -errno;
+ return UV__ERR(errno);
err = uv__cloexec(fd, 1);
if (err) {
@@ -985,17 +986,17 @@ int uv__open_cloexec(const char* path, int flags) {
int uv__dup2_cloexec(int oldfd, int newfd) {
int r;
-#if defined(__FreeBSD__) && __FreeBSD__ >= 10
+#if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
r = dup3(oldfd, newfd, O_CLOEXEC);
if (r == -1)
- return -errno;
+ return UV__ERR(errno);
return r;
#elif defined(__FreeBSD__) && defined(F_DUP2FD_CLOEXEC)
r = fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd);
if (r != -1)
return r;
if (errno != EINVAL)
- return -errno;
+ return UV__ERR(errno);
/* Fall through. */
#elif defined(__linux__)
static int no_dup3;
@@ -1006,7 +1007,7 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
if (r != -1)
return r;
if (errno != ENOSYS)
- return -errno;
+ return UV__ERR(errno);
/* Fall through. */
no_dup3 = 1;
}
@@ -1022,7 +1023,7 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
#endif
if (r == -1)
- return -errno;
+ return UV__ERR(errno);
err = uv__cloexec(newfd, 1);
if (err) {
@@ -1037,29 +1038,16 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
int uv_os_homedir(char* buffer, size_t* size) {
uv_passwd_t pwd;
- char* buf;
size_t len;
int r;
- if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
-
- /* Check if the HOME environment variable is set first */
- buf = getenv("HOME");
-
- if (buf != NULL) {
- len = strlen(buf);
-
- if (len >= *size) {
- *size = len + 1;
- return -ENOBUFS;
- }
-
- memcpy(buffer, buf, len + 1);
- *size = len;
+ /* Check if the HOME environment variable is set first. The task of
+ performing input validation on buffer and size is taken care of by
+ uv_os_getenv(). */
+ r = uv_os_getenv("HOME", buffer, size);
- return 0;
- }
+ if (r != UV_ENOENT)
+ return r;
/* HOME is not set, so call uv__getpwuid_r() */
r = uv__getpwuid_r(&pwd);
@@ -1073,7 +1061,7 @@ int uv_os_homedir(char* buffer, size_t* size) {
if (len >= *size) {
*size = len + 1;
uv_os_free_passwd(&pwd);
- return -ENOBUFS;
+ return UV_ENOBUFS;
}
memcpy(buffer, pwd.homedir, len + 1);
@@ -1089,7 +1077,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
size_t len;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
#define CHECK_ENV_VAR(name) \
do { \
@@ -1119,7 +1107,7 @@ return_buffer:
if (len >= *size) {
*size = len + 1;
- return -ENOBUFS;
+ return UV_ENOBUFS;
}
/* The returned directory should not have a trailing slash. */
@@ -1151,11 +1139,11 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
getpwuid_r = dlsym(RTLD_DEFAULT, "getpwuid_r");
if (getpwuid_r == NULL)
- return -ENOSYS;
+ return UV_ENOSYS;
#endif
if (pwd == NULL)
- return -EINVAL;
+ return UV_EINVAL;
initsize = sysconf(_SC_GETPW_R_SIZE_MAX);
@@ -1172,7 +1160,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
buf = uv__malloc(bufsize);
if (buf == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
r = getpwuid_r(uid, &pw, buf, bufsize, &result);
@@ -1189,7 +1177,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
if (result == NULL) {
uv__free(buf);
- return -ENOENT;
+ return UV_ENOENT;
}
/* Allocate memory for the username, shell, and home directory */
@@ -1200,7 +1188,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
if (pwd->username == NULL) {
uv__free(buf);
- return -ENOMEM;
+ return UV_ENOMEM;
}
/* Copy the username */
@@ -1256,18 +1244,18 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
size_t len;
if (name == NULL || buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
var = getenv(name);
if (var == NULL)
- return -ENOENT;
+ return UV_ENOENT;
len = strlen(var);
if (len >= *size) {
*size = len + 1;
- return -ENOBUFS;
+ return UV_ENOBUFS;
}
memcpy(buffer, var, len + 1);
@@ -1279,18 +1267,21 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
int uv_os_setenv(const char* name, const char* value) {
if (name == NULL || value == NULL)
- return -EINVAL;
+ return UV_EINVAL;
if (setenv(name, value, 1) != 0)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
int uv_os_unsetenv(const char* name) {
+ if (name == NULL)
+ return UV_EINVAL;
+
if (unsetenv(name) != 0)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -1307,20 +1298,131 @@ int uv_os_gethostname(char* buffer, size_t* size) {
size_t len;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
if (gethostname(buf, sizeof(buf)) != 0)
- return -errno;
+ return UV__ERR(errno);
buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */
len = strlen(buf);
if (len >= *size) {
*size = len + 1;
- return -ENOBUFS;
+ return UV_ENOBUFS;
}
memcpy(buffer, buf, len + 1);
*size = len;
return 0;
}
+
+
+int uv_cpumask_size(void) {
+#if defined(__linux__) || defined(__FreeBSD__)
+ return CPU_SETSIZE;
+#else
+ return UV_ENOTSUP;
+#endif
+}
+
+
+uv_os_fd_t uv_get_osfhandle(int fd) {
+ return fd;
+}
+
+int uv_open_osfhandle(uv_os_fd_t os_fd) {
+ return os_fd;
+}
+
+uv_pid_t uv_os_getpid(void) {
+ return getpid();
+}
+
+
+uv_pid_t uv_os_getppid(void) {
+ return getppid();
+}
+
+
+int uv_os_getpriority(uv_pid_t pid, int* priority) {
+ int r;
+
+ if (priority == NULL)
+ return UV_EINVAL;
+
+ errno = 0;
+ r = getpriority(PRIO_PROCESS, (int) pid);
+
+ if (r == -1 && errno != 0)
+ return UV__ERR(errno);
+
+ *priority = r;
+ return 0;
+}
+
+
+int uv_os_setpriority(uv_pid_t pid, int priority) {
+ if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW)
+ return UV_EINVAL;
+
+ if (setpriority(PRIO_PROCESS, (int) pid, priority) != 0)
+ return UV__ERR(errno);
+
+ return 0;
+}
+
+
+int uv_os_uname(uv_utsname_t* buffer) {
+ struct utsname buf;
+ int r;
+
+ if (buffer == NULL)
+ return UV_EINVAL;
+
+ if (uname(&buf) == -1) {
+ r = UV__ERR(errno);
+ goto error;
+ }
+
+ r = uv__strscpy(buffer->sysname, buf.sysname, sizeof(buffer->sysname));
+ if (r == UV_E2BIG)
+ goto error;
+
+#ifdef _AIX
+ r = snprintf(buffer->release,
+ sizeof(buffer->release),
+ "%s.%s",
+ buf.version,
+ buf.release);
+ if (r >= sizeof(buffer->release)) {
+ r = UV_E2BIG;
+ goto error;
+ }
+#else
+ r = uv__strscpy(buffer->release, buf.release, sizeof(buffer->release));
+ if (r == UV_E2BIG)
+ goto error;
+#endif
+
+ r = uv__strscpy(buffer->version, buf.version, sizeof(buffer->version));
+ if (r == UV_E2BIG)
+ goto error;
+
+#if defined(_AIX) || defined(__PASE__)
+ r = uv__strscpy(buffer->machine, "ppc64", sizeof(buffer->machine));
+#else
+ r = uv__strscpy(buffer->machine, buf.machine, sizeof(buffer->machine));
+#endif
+
+ if (r == UV_E2BIG)
+ goto error;
+
+ return 0;
+
+error:
+ buffer->sysname[0] = '\0';
+ buffer->release[0] = '\0';
+ buffer->version[0] = '\0';
+ buffer->machine[0] = '\0';
+ return r;
+}
diff --git a/Utilities/cmlibuv/src/unix/cygwin.c b/Utilities/cmlibuv/src/unix/cygwin.c
index 5a887dd4c..9da20e203 100644
--- a/Utilities/cmlibuv/src/unix/cygwin.c
+++ b/Utilities/cmlibuv/src/unix/cygwin.c
@@ -29,7 +29,7 @@ int uv_uptime(double* uptime) {
struct sysinfo info;
if (sysinfo(&info) < 0)
- return -errno;
+ return UV__ERR(errno);
*uptime = info.uptime;
return 0;
@@ -38,7 +38,7 @@ int uv_uptime(double* uptime) {
int uv_resident_set_memory(size_t* rss) {
/* FIXME: read /proc/meminfo? */
*rss = 0;
- return UV_ENOSYS;
+ return 0;
}
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
diff --git a/Utilities/cmlibuv/src/unix/darwin-proctitle.c b/Utilities/cmlibuv/src/unix/darwin-proctitle.c
index 114231160..e505bdd23 100644
--- a/Utilities/cmlibuv/src/unix/darwin-proctitle.c
+++ b/Utilities/cmlibuv/src/unix/darwin-proctitle.c
@@ -18,6 +18,9 @@
* IN THE SOFTWARE.
*/
+#include "uv.h"
+#include "internal.h"
+
#include <dlfcn.h>
#include <errno.h>
#include <stdlib.h>
@@ -30,61 +33,56 @@
# include <ApplicationServices/ApplicationServices.h>
#endif
+#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
-static int uv__pthread_setname_np(const char* name) {
- int (*dynamic_pthread_setname_np)(const char* name);
- char namebuf[64]; /* MAXTHREADNAMESIZE */
- int err;
-
- /* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
- *(void **)(&dynamic_pthread_setname_np) =
- dlsym(RTLD_DEFAULT, "pthread_setname_np");
-
- if (dynamic_pthread_setname_np == NULL)
- return -ENOSYS;
-
- strncpy(namebuf, name, sizeof(namebuf) - 1);
- namebuf[sizeof(namebuf) - 1] = '\0';
- err = dynamic_pthread_setname_np(namebuf);
- if (err)
- return -err;
+static int (*dynamic_pthread_setname_np)(const char* name);
+#if !TARGET_OS_IPHONE
+static CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
+ const char*,
+ CFStringEncoding);
+static CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
+static void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
+static void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
+static CFTypeRef (*pLSGetCurrentApplicationASN)(void);
+static OSStatus (*pLSSetApplicationInformationItem)(int,
+ CFTypeRef,
+ CFStringRef,
+ CFStringRef,
+ CFDictionaryRef*);
+static void* application_services_handle;
+static void* core_foundation_handle;
+static CFBundleRef launch_services_bundle;
+static CFStringRef* display_name_key;
+static CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
+static CFBundleRef (*pCFBundleGetMainBundle)(void);
+static CFBundleRef hi_services_bundle;
+static OSStatus (*pSetApplicationIsDaemon)(int);
+static CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef);
+static void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t,
+ void*);
+
+
+UV_DESTRUCTOR(static void uv__set_process_title_platform_fini(void)) {
+ if (core_foundation_handle != NULL) {
+ dlclose(core_foundation_handle);
+ core_foundation_handle = NULL;
+ }
- return 0;
+ if (application_services_handle != NULL) {
+ dlclose(application_services_handle);
+ application_services_handle = NULL;
+ }
}
+#endif /* !TARGET_OS_IPHONE */
+
+void uv__set_process_title_platform_init(void) {
+ /* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
+ *(void **)(&dynamic_pthread_setname_np) =
+ dlsym(RTLD_DEFAULT, "pthread_setname_np");
-int uv__set_process_title(const char* title) {
-#if TARGET_OS_IPHONE
- return uv__pthread_setname_np(title);
-#else
- CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
- const char*,
- CFStringEncoding);
- CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
- void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
- void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
- CFTypeRef (*pLSGetCurrentApplicationASN)(void);
- OSStatus (*pLSSetApplicationInformationItem)(int,
- CFTypeRef,
- CFStringRef,
- CFStringRef,
- CFDictionaryRef*);
- void* application_services_handle;
- void* core_foundation_handle;
- CFBundleRef launch_services_bundle;
- CFStringRef* display_name_key;
- CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
- CFBundleRef (*pCFBundleGetMainBundle)(void);
- CFBundleRef hi_services_bundle;
- OSStatus (*pSetApplicationIsDaemon)(int);
- CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef);
- void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t,
- void*);
- CFTypeRef asn;
- int err;
-
- err = -ENOENT;
+#if !TARGET_OS_IPHONE
application_services_handle = dlopen("/System/Library/Frameworks/"
"ApplicationServices.framework/"
"Versions/A/ApplicationServices",
@@ -113,8 +111,6 @@ int uv__set_process_title(const char* title) {
goto out;
}
-#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
-
launch_services_bundle =
pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices"));
@@ -145,13 +141,14 @@ int uv__set_process_title(const char* title) {
"CFBundleGetInfoDictionary");
*(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle,
"CFBundleGetMainBundle");
+
if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL)
goto out;
/* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */
hi_services_bundle =
pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices"));
- err = -ENOENT;
+
if (hi_services_bundle == NULL)
goto out;
@@ -165,42 +162,37 @@ int uv__set_process_title(const char* title) {
pCFBundleGetFunctionPointerForName(
launch_services_bundle,
S("_LSSetApplicationLaunchServicesServerConnectionStatus"));
+
if (pSetApplicationIsDaemon == NULL ||
pLSApplicationCheckIn == NULL ||
pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) {
goto out;
}
- if (pSetApplicationIsDaemon(1) != noErr)
- goto out;
-
- pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL);
-
- /* Check into process manager?! */
- pLSApplicationCheckIn(-2,
- pCFBundleGetInfoDictionary(pCFBundleGetMainBundle()));
-
- asn = pLSGetCurrentApplicationASN();
-
- err = -EINVAL;
- if (pLSSetApplicationInformationItem(-2, /* Magic value. */
- asn,
- *display_name_key,
- S(title),
- NULL) != noErr) {
- goto out;
- }
-
- uv__pthread_setname_np(title); /* Don't care if it fails. */
- err = 0;
+ return;
out:
- if (core_foundation_handle != NULL)
- dlclose(core_foundation_handle);
+ uv__set_process_title_platform_fini();
+#endif /* !TARGET_OS_IPHONE */
+}
- if (application_services_handle != NULL)
- dlclose(application_services_handle);
- return err;
+void uv__set_process_title(const char* title) {
+#if !TARGET_OS_IPHONE
+ if (core_foundation_handle != NULL && pSetApplicationIsDaemon(1) != noErr) {
+ CFTypeRef asn;
+ pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL);
+ pLSApplicationCheckIn(/* Magic value */ -2,
+ pCFBundleGetInfoDictionary(pCFBundleGetMainBundle()));
+ asn = pLSGetCurrentApplicationASN();
+ pLSSetApplicationInformationItem(/* Magic value */ -2, asn,
+ *display_name_key, S(title), NULL);
+ }
#endif /* !TARGET_OS_IPHONE */
+
+ if (dynamic_pthread_setname_np != NULL) {
+ char namebuf[64]; /* MAXTHREADNAMESIZE */
+ uv__strscpy(namebuf, title, sizeof(namebuf));
+ dynamic_pthread_setname_np(namebuf);
+ }
}
diff --git a/Utilities/cmlibuv/src/unix/darwin.c b/Utilities/cmlibuv/src/unix/darwin.c
index df6dd1c61..31ad8a9e4 100644
--- a/Utilities/cmlibuv/src/unix/darwin.c
+++ b/Utilities/cmlibuv/src/unix/darwin.c
@@ -37,7 +37,7 @@ int uv__platform_loop_init(uv_loop_t* loop) {
loop->cf_state = NULL;
if (uv__kqueue_init(loop))
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -68,18 +68,18 @@ int uv_exepath(char* buffer, size_t* size) {
size_t abspath_size;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
exepath_size = sizeof(exepath);
if (_NSGetExecutablePath(exepath, &exepath_size))
- return -EIO;
+ return UV_EIO;
if (realpath(exepath, abspath) != abspath)
- return -errno;
+ return UV__ERR(errno);
abspath_size = strlen(abspath);
if (abspath_size == 0)
- return -EIO;
+ return UV_EIO;
*size -= 1;
if (*size > abspath_size)
@@ -98,7 +98,7 @@ uint64_t uv_get_free_memory(void) {
if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) {
- return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
+ return UV_EINVAL; /* FIXME(bnoordhuis) Translate error. */
}
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
@@ -111,7 +111,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
return (uint64_t) info;
}
@@ -158,7 +158,7 @@ int uv_uptime(double* uptime) {
static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
now = time(NULL);
*uptime = now - info.tv_sec;
@@ -181,23 +181,23 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(model);
if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) &&
sysctlbyname("hw.model", &model, &size, NULL, 0)) {
- return -errno;
+ return UV__ERR(errno);
}
size = sizeof(cpuspeed);
if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info,
&msg_type) != KERN_SUCCESS) {
- return -EINVAL; /* FIXME(bnoordhuis) Translate error. */
+ return UV_EINVAL; /* FIXME(bnoordhuis) Translate error. */
}
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) {
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
- return -ENOMEM;
+ return UV_ENOMEM;
}
*count = numcpus;
diff --git a/Utilities/cmlibuv/src/unix/freebsd.c b/Utilities/cmlibuv/src/unix/freebsd.c
index e52ae99db..0f729cfd4 100644
--- a/Utilities/cmlibuv/src/unix/freebsd.c
+++ b/Utilities/cmlibuv/src/unix/freebsd.c
@@ -25,7 +25,6 @@
#include <string.h>
#include <errno.h>
-#include <kvm.h>
#include <paths.h>
#include <sys/user.h>
#include <sys/types.h>
@@ -48,8 +47,6 @@
# define CP_INTR 4
#endif
-static char *process_title;
-
int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop);
@@ -66,11 +63,11 @@ int uv_exepath(char* buffer, size_t* size) {
ssize_t abspath_size;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
abspath_size = readlink("/proc/curproc/file", abspath, sizeof(abspath));
if (abspath_size < 0)
- return -errno;
+ return UV__ERR(errno);
assert(abspath_size > 0);
*size -= 1;
@@ -90,7 +87,7 @@ int uv_exepath(char* buffer, size_t* size) {
size_t abspath_size;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
@@ -99,7 +96,7 @@ int uv_exepath(char* buffer, size_t* size) {
abspath_size = sizeof abspath;
if (sysctl(mib, 4, abspath, &abspath_size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
assert(abspath_size > 0);
abspath_size -= 1;
@@ -120,7 +117,7 @@ uint64_t uv_get_free_memory(void) {
size_t size = sizeof(freecount);
if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
@@ -134,7 +131,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
return (uint64_t) info;
}
@@ -153,85 +150,31 @@ void uv_loadavg(double avg[3]) {
}
-char** uv_setup_args(int argc, char** argv) {
- process_title = argc ? uv__strdup(argv[0]) : NULL;
- return argv;
-}
-
-
-int uv_set_process_title(const char* title) {
- int oid[4];
-
- uv__free(process_title);
- process_title = uv__strdup(title);
-
- oid[0] = CTL_KERN;
- oid[1] = KERN_PROC;
- oid[2] = KERN_PROC_ARGS;
- oid[3] = getpid();
-
- sysctl(oid,
- ARRAY_SIZE(oid),
- NULL,
- NULL,
- process_title,
- strlen(process_title) + 1);
-
- return 0;
-}
-
-
-int uv_get_process_title(char* buffer, size_t size) {
- size_t len;
-
- if (buffer == NULL || size == 0)
- return -EINVAL;
-
- if (process_title) {
- len = strlen(process_title) + 1;
-
- if (size < len)
- return -ENOBUFS;
-
- memcpy(buffer, process_title, len);
- } else {
- len = 0;
- }
-
- buffer[len] = '\0';
-
- return 0;
-}
-
-
int uv_resident_set_memory(size_t* rss) {
- kvm_t *kd = NULL;
- struct kinfo_proc *kinfo = NULL;
- pid_t pid;
- int nprocs;
- size_t page_size = getpagesize();
+ struct kinfo_proc kinfo;
+ size_t page_size;
+ size_t kinfo_size;
+ int mib[4];
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = getpid();
- pid = getpid();
+ kinfo_size = sizeof(kinfo);
- kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
- if (kd == NULL) goto error;
+ if (sysctl(mib, 4, &kinfo, &kinfo_size, NULL, 0))
+ return UV__ERR(errno);
- kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs);
- if (kinfo == NULL) goto error;
+ page_size = getpagesize();
#ifdef __DragonFly__
- *rss = kinfo->kp_vm_rssize * page_size;
+ *rss = kinfo.kp_vm_rssize * page_size;
#else
- *rss = kinfo->ki_rssize * page_size;
+ *rss = kinfo.ki_rssize * page_size;
#endif
- kvm_close(kd);
-
return 0;
-
-error:
- if (kd) kvm_close(kd);
- return -EPERM;
}
@@ -240,7 +183,7 @@ int uv_uptime(double* uptime) {
struct timespec sp;
r = clock_gettime(CLOCK_MONOTONIC, &sp);
if (r)
- return -errno;
+ return UV__ERR(errno);
*uptime = sp.tv_sec;
return 0;
@@ -254,6 +197,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv_cpu_info_t* cpu_info;
const char* maxcpus_key;
const char* cptimes_key;
+ const char* model_key;
char model[512];
long* cp_times;
int numcpus;
@@ -272,33 +216,39 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cptimes_key = "kern.cp_times";
#endif
- size = sizeof(model);
- if (sysctlbyname("hw.model", &model, &size, NULL, 0))
+#if defined(__arm__) || defined(__aarch64__)
+ /* The key hw.model and hw.clockrate are not available on FreeBSD ARM. */
+ model_key = "hw.machine";
+ cpuspeed = 0;
+#else
+ model_key = "hw.model";
+
+ size = sizeof(cpuspeed);
+ if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0))
return -errno;
+#endif
+
+ size = sizeof(model);
+ if (sysctlbyname(model_key, &model, &size, NULL, 0))
+ return UV__ERR(errno);
size = sizeof(numcpus);
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos))
- return -ENOMEM;
+ return UV_ENOMEM;
*count = numcpus;
- size = sizeof(cpuspeed);
- if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {
- uv__free(*cpu_infos);
- return -errno;
- }
-
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of
* ncpu.
*/
size = sizeof(maxcpus);
if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) {
uv__free(*cpu_infos);
- return -errno;
+ return UV__ERR(errno);
}
size = maxcpus * CPUSTATES * sizeof(long);
@@ -306,13 +256,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cp_times = uv__malloc(size);
if (cp_times == NULL) {
uv__free(*cpu_infos);
- return -ENOMEM;
+ return UV_ENOMEM;
}
if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) {
uv__free(cp_times);
uv__free(*cpu_infos);
- return -errno;
+ return UV__ERR(errno);
}
for (i = 0; i < numcpus; i++) {
diff --git a/Utilities/cmlibuv/src/unix/fs.c b/Utilities/cmlibuv/src/unix/fs.c
index 8a4ba7a2f..bffc956b5 100644
--- a/Utilities/cmlibuv/src/unix/fs.c
+++ b/Utilities/cmlibuv/src/unix/fs.c
@@ -43,7 +43,6 @@
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
-#include <utime.h>
#include <poll.h>
#if defined(__DragonFly__) || \
@@ -60,17 +59,34 @@
# include <sys/sendfile.h>
#endif
+#if defined(__APPLE__)
+# include <copyfile.h>
+# include <sys/sysctl.h>
+#elif defined(__linux__) && !defined(FICLONE)
+# include <sys/ioctl.h>
+# define FICLONE _IOW(0x94, 9, int)
+#endif
+
+#if defined(_AIX) && !defined(_AIX71)
+# include <utime.h>
+#endif
+
+#if defined(_AIX) && _XOPEN_SOURCE <= 600
+extern char *mkdtemp(char *template); /* See issue #740 on AIX < 7 */
+#endif
+
#define INIT(subtype) \
do { \
- req->type = UV_FS; \
- if (cb != NULL) \
- uv__req_init(loop, req, UV_FS); \
+ if (req == NULL) \
+ return UV_EINVAL; \
+ UV_REQ_INIT(req, UV_FS); \
req->fs_type = UV_FS_ ## subtype; \
req->result = 0; \
req->ptr = NULL; \
req->loop = loop; \
req->path = NULL; \
req->new_path = NULL; \
+ req->bufs = NULL; \
req->cb = cb; \
} \
while (0)
@@ -82,10 +98,8 @@
req->path = path; \
} else { \
req->path = uv__strdup(path); \
- if (req->path == NULL) { \
- uv__req_unregister(loop, req); \
- return -ENOMEM; \
- } \
+ if (req->path == NULL) \
+ return UV_ENOMEM; \
} \
} \
while (0)
@@ -101,10 +115,8 @@
path_len = strlen(path) + 1; \
new_path_len = strlen(new_path) + 1; \
req->path = uv__malloc(path_len + new_path_len); \
- if (req->path == NULL) { \
- uv__req_unregister(loop, req); \
- return -ENOMEM; \
- } \
+ if (req->path == NULL) \
+ return UV_ENOMEM; \
req->new_path = req->path + path_len; \
memcpy((void*) req->path, path, path_len); \
memcpy((void*) req->new_path, new_path, new_path_len); \
@@ -115,7 +127,12 @@
#define POST \
do { \
if (cb != NULL) { \
- uv__work_submit(loop, &req->work_req, uv__fs_work, uv__fs_done); \
+ uv__req_register(loop, req); \
+ uv__work_submit(loop, \
+ &req->work_req, \
+ UV__WORK_FAST_IO, \
+ uv__fs_work, \
+ uv__fs_done); \
return 0; \
} \
else { \
@@ -126,26 +143,33 @@
while (0)
-static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
-#if defined(__linux__) || defined(__sun) || defined(__NetBSD__)
- return fdatasync(req->file);
-#elif defined(__APPLE__)
+static ssize_t uv__fs_fsync(uv_fs_t* req) {
+#if defined(__APPLE__)
/* Apple's fdatasync and fsync explicitly do NOT flush the drive write cache
* to the drive platters. This is in contrast to Linux's fdatasync and fsync
* which do, according to recent man pages. F_FULLFSYNC is Apple's equivalent
- * for flushing buffered data to permanent storage.
+ * for flushing buffered data to permanent storage. If F_FULLFSYNC is not
+ * supported by the file system we should fall back to fsync(). This is the
+ * same approach taken by sqlite.
*/
- return fcntl(req->file, F_FULLFSYNC);
+ int r;
+
+ r = fcntl(req->file, F_FULLFSYNC);
+ if (r != 0)
+ r = fsync(req->file);
+ return r;
#else
return fsync(req->file);
#endif
}
-static ssize_t uv__fs_fsync(uv_fs_t* req) {
-#if defined(__APPLE__)
- /* See the comment in uv__fs_fdatasync. */
- return fcntl(req->file, F_FULLFSYNC);
+static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
+#if defined(__linux__) || defined(__sun) || defined(__NetBSD__)
+ return fdatasync(req->file);
+#elif defined(__APPLE__)
+ /* See the comment in uv__fs_fsync. */
+ return uv__fs_fsync(req);
#else
return fsync(req->file);
#endif
@@ -153,59 +177,17 @@ static ssize_t uv__fs_fsync(uv_fs_t* req) {
static ssize_t uv__fs_futime(uv_fs_t* req) {
-#if defined(__linux__)
+#if defined(__linux__) \
+ || defined(_AIX71)
/* utimesat() has nanosecond resolution but we stick to microseconds
* for the sake of consistency with other platforms.
*/
- static int no_utimesat;
struct timespec ts[2];
- struct timeval tv[2];
- char path[sizeof("/proc/self/fd/") + 3 * sizeof(int)];
- int r;
-
- if (no_utimesat)
- goto skip;
-
ts[0].tv_sec = req->atime;
ts[0].tv_nsec = (uint64_t)(req->atime * 1000000) % 1000000 * 1000;
ts[1].tv_sec = req->mtime;
ts[1].tv_nsec = (uint64_t)(req->mtime * 1000000) % 1000000 * 1000;
-
- r = uv__utimesat(req->file, NULL, ts, 0);
- if (r == 0)
- return r;
-
- if (errno != ENOSYS)
- return r;
-
- no_utimesat = 1;
-
-skip:
-
- tv[0].tv_sec = req->atime;
- tv[0].tv_usec = (uint64_t)(req->atime * 1000000) % 1000000;
- tv[1].tv_sec = req->mtime;
- tv[1].tv_usec = (uint64_t)(req->mtime * 1000000) % 1000000;
- snprintf(path, sizeof(path), "/proc/self/fd/%d", (int) req->file);
-
- r = utimes(path, tv);
- if (r == 0)
- return r;
-
- switch (errno) {
- case ENOENT:
- if (fcntl(req->file, F_GETFL) == -1 && errno == EBADF)
- break;
- /* Fall through. */
-
- case EACCES:
- case ENOTDIR:
- errno = ENOSYS;
- break;
- }
-
- return r;
-
+ return futimens(req->file, ts);
#elif defined(__APPLE__) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
@@ -223,13 +205,6 @@ skip:
# else
return futimes(req->file, tv);
# endif
-#elif defined(_AIX71)
- struct timespec ts[2];
- ts[0].tv_sec = req->atime;
- ts[0].tv_nsec = (uint64_t)(req->atime * 1000000) % 1000000 * 1000;
- ts[1].tv_sec = req->mtime;
- ts[1].tv_nsec = (uint64_t)(req->mtime * 1000000) % 1000000 * 1000;
- return futimens(req->file, ts);
#elif defined(__MVS__)
attrib_t atr;
memset(&atr, 0, sizeof(atr));
@@ -244,7 +219,7 @@ skip:
#endif
}
-#if defined(__sun) && _XOPEN_SOURCE < 600
+#if defined(__sun) && (_XOPEN_SOURCE < 600 || defined(CMAKE_BOOTSTRAP))
static char* uv__mkdtemp(char *template)
{
if (!mktemp(template) || mkdir(template, 0700))
@@ -302,17 +277,13 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
#if defined(__linux__)
static int no_preadv;
#endif
+ unsigned int iovmax;
ssize_t result;
-#if defined(_AIX)
- struct stat buf;
- if(fstat(req->file, &buf))
- return -1;
- if(S_ISDIR(buf.st_mode)) {
- errno = EISDIR;
- return -1;
- }
-#endif /* defined(_AIX) */
+ iovmax = uv__getiovmax();
+ if (req->nbufs > iovmax)
+ req->nbufs = iovmax;
+
if (req->off < 0) {
if (req->nbufs == 1)
result = read(req->file, req->bufs[0].base, req->bufs[0].len);
@@ -331,25 +302,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
if (no_preadv) retry:
# endif
{
- off_t nread;
- size_t index;
-
- nread = 0;
- index = 0;
- result = 1;
- do {
- if (req->bufs[index].len > 0) {
- result = pread(req->file,
- req->bufs[index].base,
- req->bufs[index].len,
- req->off + nread);
- if (result > 0)
- nread += result;
- }
- index++;
- } while (index < req->nbufs && result > 0);
- if (nread > 0)
- result = nread;
+ result = pread(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
}
# if defined(__linux__)
else {
@@ -367,6 +320,13 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
}
done:
+ /* Early cleanup of bufs allocation, since we're done with it. */
+ if (req->bufs != req->bufsml)
+ uv__free(req->bufs);
+
+ req->bufs = NULL;
+ req->nbufs = 0;
+
return result;
}
@@ -413,42 +373,84 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) {
return n;
}
+#if defined(_POSIX_PATH_MAX)
+# define UV__FS_PATH_MAX _POSIX_PATH_MAX
+#elif defined(PATH_MAX)
+# define UV__FS_PATH_MAX PATH_MAX
+#else
+# define UV__FS_PATH_MAX_FALLBACK 8192
+# define UV__FS_PATH_MAX UV__FS_PATH_MAX_FALLBACK
+#endif
static ssize_t uv__fs_pathmax_size(const char* path) {
ssize_t pathmax;
pathmax = pathconf(path, _PC_PATH_MAX);
- if (pathmax == -1) {
-#if defined(PATH_MAX)
- return PATH_MAX;
-#else
-#error "PATH_MAX undefined in the current platform"
-#endif
- }
+ if (pathmax == -1)
+ pathmax = UV__FS_PATH_MAX;
return pathmax;
}
static ssize_t uv__fs_readlink(uv_fs_t* req) {
+ ssize_t maxlen;
ssize_t len;
char* buf;
+ char* newbuf;
- len = uv__fs_pathmax_size(req->path);
- buf = uv__malloc(len + 1);
+#if defined(UV__FS_PATH_MAX_FALLBACK)
+ /* We may not have a real PATH_MAX. Read size of link. */
+ struct stat st;
+ int ret;
+ ret = lstat(req->path, &st);
+ if (ret != 0)
+ return -1;
+ if (!S_ISLNK(st.st_mode)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ maxlen = st.st_size;
+
+ /* According to readlink(2) lstat can report st_size == 0
+ for some symlinks, such as those in /proc or /sys. */
+ if (maxlen == 0)
+ maxlen = uv__fs_pathmax_size(req->path);
+#else
+ maxlen = uv__fs_pathmax_size(req->path);
+#endif
+
+ buf = uv__malloc(maxlen);
if (buf == NULL) {
errno = ENOMEM;
return -1;
}
- len = readlink(req->path, buf, len);
+#if defined(__MVS__)
+ len = os390_readlink(req->path, buf, maxlen);
+#else
+ len = readlink(req->path, buf, maxlen);
+#endif
if (len == -1) {
uv__free(buf);
return -1;
}
+ /* Uncommon case: resize to make room for the trailing nul byte. */
+ if (len == maxlen) {
+ newbuf = uv__realloc(buf, len + 1);
+
+ if (newbuf == NULL) {
+ uv__free(buf);
+ return -1;
+ }
+
+ buf = newbuf;
+ }
+
buf[len] = '\0';
req->ptr = buf;
@@ -456,9 +458,15 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
}
static ssize_t uv__fs_realpath(uv_fs_t* req) {
- ssize_t len;
char* buf;
+#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L
+ buf = realpath(req->path, NULL);
+ if (buf == NULL)
+ return -1;
+#else
+ ssize_t len;
+
len = uv__fs_pathmax_size(req->path);
buf = uv__malloc(len + 1);
@@ -471,6 +479,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) {
uv__free(buf);
return -1;
}
+#endif
req->ptr = buf;
@@ -691,10 +700,48 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) {
static ssize_t uv__fs_utime(uv_fs_t* req) {
+#if defined(__linux__) \
+ || defined(_AIX71) \
+ || defined(__sun)
+ /* utimesat() has nanosecond resolution but we stick to microseconds
+ * for the sake of consistency with other platforms.
+ */
+ struct timespec ts[2];
+ ts[0].tv_sec = req->atime;
+ ts[0].tv_nsec = (uint64_t)(req->atime * 1000000) % 1000000 * 1000;
+ ts[1].tv_sec = req->mtime;
+ ts[1].tv_nsec = (uint64_t)(req->mtime * 1000000) % 1000000 * 1000;
+ return utimensat(AT_FDCWD, req->path, ts, 0);
+#elif defined(__APPLE__) \
+ || defined(__DragonFly__) \
+ || defined(__FreeBSD__) \
+ || defined(__FreeBSD_kernel__) \
+ || defined(__NetBSD__) \
+ || defined(__OpenBSD__)
+ struct timeval tv[2];
+ tv[0].tv_sec = req->atime;
+ tv[0].tv_usec = (uint64_t)(req->atime * 1000000) % 1000000;
+ tv[1].tv_sec = req->mtime;
+ tv[1].tv_usec = (uint64_t)(req->mtime * 1000000) % 1000000;
+ return utimes(req->path, tv);
+#elif defined(_AIX) \
+ && !defined(_AIX71)
struct utimbuf buf;
buf.actime = req->atime;
buf.modtime = req->mtime;
- return utime(req->path, &buf); /* TODO use utimes() where available */
+ return utime(req->path, &buf);
+#elif defined(__MVS__)
+ attrib_t atr;
+ memset(&atr, 0, sizeof(atr));
+ atr.att_mtimechg = 1;
+ atr.att_atimechg = 1;
+ atr.att_mtime = req->mtime;
+ atr.att_atime = req->atime;
+ return __lchattr((char*) req->path, &atr, sizeof(atr));
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
}
@@ -732,25 +779,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
if (no_pwritev) retry:
# endif
{
- off_t written;
- size_t index;
-
- written = 0;
- index = 0;
- r = 0;
- do {
- if (req->bufs[index].len > 0) {
- r = pwrite(req->file,
- req->bufs[index].base,
- req->bufs[index].len,
- req->off + written);
- if (r > 0)
- written += r;
- }
- index++;
- } while (index < req->nbufs && r >= 0);
- if (written > 0)
- r = written;
+ r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
}
# if defined(__linux__)
else {
@@ -776,6 +805,175 @@ done:
return r;
}
+static ssize_t uv__fs_copyfile(uv_fs_t* req) {
+#if defined(__APPLE__) && !TARGET_OS_IPHONE
+ /* On macOS, use the native copyfile(3). */
+ static int can_clone;
+ copyfile_flags_t flags;
+ char buf[64];
+ size_t len;
+ int major;
+
+ flags = COPYFILE_ALL;
+
+ if (req->flags & UV_FS_COPYFILE_EXCL)
+ flags |= COPYFILE_EXCL;
+
+ /* Check OS version. Cloning is only supported on macOS >= 10.12. */
+ if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
+ if (can_clone == 0) {
+ len = sizeof(buf);
+ if (sysctlbyname("kern.osrelease", buf, &len, NULL, 0))
+ return UV__ERR(errno);
+
+ if (1 != sscanf(buf, "%d", &major))
+ abort();
+
+ can_clone = -1 + 2 * (major >= 16); /* macOS >= 10.12 */
+ }
+
+ if (can_clone < 0)
+ return UV_ENOSYS;
+ }
+
+ /* copyfile() simply ignores COPYFILE_CLONE if it's not supported. */
+ if (req->flags & UV_FS_COPYFILE_FICLONE)
+ flags |= 1 << 24; /* COPYFILE_CLONE */
+
+ if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE)
+ flags |= 1 << 25; /* COPYFILE_CLONE_FORCE */
+
+ return copyfile(req->path, req->new_path, NULL, flags);
+#else
+ uv_fs_t fs_req;
+ uv_file srcfd;
+ uv_file dstfd;
+ struct stat statsbuf;
+ int dst_flags;
+ int result;
+ int err;
+ size_t bytes_to_send;
+ int64_t in_offset;
+
+ dstfd = -1;
+ err = 0;
+
+ /* Open the source file. */
+ srcfd = uv_fs_open(NULL, &fs_req, req->path, O_RDONLY, 0, NULL);
+ uv_fs_req_cleanup(&fs_req);
+
+ if (srcfd < 0)
+ return srcfd;
+
+ /* Get the source file's mode. */
+ if (fstat(srcfd, &statsbuf)) {
+ err = UV__ERR(errno);
+ goto out;
+ }
+
+ dst_flags = O_WRONLY | O_CREAT | O_TRUNC;
+
+ if (req->flags & UV_FS_COPYFILE_EXCL)
+ dst_flags |= O_EXCL;
+
+ /* Open the destination file. */
+ dstfd = uv_fs_open(NULL,
+ &fs_req,
+ req->new_path,
+ dst_flags,
+ statsbuf.st_mode,
+ NULL);
+ uv_fs_req_cleanup(&fs_req);
+
+ if (dstfd < 0) {
+ err = dstfd;
+ goto out;
+ }
+
+ if (fchmod(dstfd, statsbuf.st_mode) == -1) {
+ err = UV__ERR(errno);
+ goto out;
+ }
+
+#ifdef FICLONE
+ if (req->flags & UV_FS_COPYFILE_FICLONE ||
+ req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
+ if (ioctl(dstfd, FICLONE, srcfd) == -1) {
+ /* If an error occurred that the sendfile fallback also won't handle, or
+ this is a force clone then exit. Otherwise, fall through to try using
+ sendfile(). */
+ if (errno != ENOTTY && errno != EOPNOTSUPP && errno != EXDEV) {
+ err = UV__ERR(errno);
+ goto out;
+ } else if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
+ err = UV_ENOTSUP;
+ goto out;
+ }
+ } else {
+ goto out;
+ }
+ }
+#else
+ if (req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
+ err = UV_ENOSYS;
+ goto out;
+ }
+#endif
+
+ bytes_to_send = statsbuf.st_size;
+ in_offset = 0;
+ while (bytes_to_send != 0) {
+ err = uv_fs_sendfile(NULL,
+ &fs_req,
+ dstfd,
+ srcfd,
+ in_offset,
+ bytes_to_send,
+ NULL);
+ uv_fs_req_cleanup(&fs_req);
+ if (err < 0)
+ break;
+ bytes_to_send -= fs_req.result;
+ in_offset += fs_req.result;
+ }
+
+out:
+ if (err < 0)
+ result = err;
+ else
+ result = 0;
+
+ /* Close the source file. */
+ err = uv__close_nocheckstdio(srcfd);
+
+ /* Don't overwrite any existing errors. */
+ if (err != 0 && result == 0)
+ result = err;
+
+ /* Close the destination file if it is open. */
+ if (dstfd >= 0) {
+ err = uv__close_nocheckstdio(dstfd);
+
+ /* Don't overwrite any existing errors. */
+ if (err != 0 && result == 0)
+ result = err;
+
+ /* Remove the destination file if something went wrong. */
+ if (result != 0) {
+ uv_fs_unlink(NULL, &fs_req, req->new_path, NULL);
+ /* Ignore the unlink return value, as an error already happened. */
+ uv_fs_req_cleanup(&fs_req);
+ }
+ }
+
+ if (result == 0)
+ return 0;
+
+ errno = UV__ERR(result);
+ return -1;
+#endif
+}
+
static void uv__to_stat(struct stat* src, uv_stat_t* dst) {
dst->st_dev = src->st_dev;
dst->st_mode = src->st_mode;
@@ -888,9 +1086,21 @@ static int uv__fs_fstat(int fd, uv_stat_t *buf) {
return ret;
}
+static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) {
+ size_t offset;
+ /* Figure out which bufs are done */
+ for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset)
+ size -= bufs[offset].len;
+
+ /* Fix a partial read/write */
+ if (size > 0) {
+ bufs[offset].base += size;
+ bufs[offset].len -= size;
+ }
+ return offset;
+}
-typedef ssize_t (*uv__fs_buf_iter_processor)(uv_fs_t* req);
-static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process) {
+static ssize_t uv__fs_write_all(uv_fs_t* req) {
unsigned int iovmax;
unsigned int nbufs;
uv_buf_t* bufs;
@@ -907,7 +1117,10 @@ static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process)
if (req->nbufs > iovmax)
req->nbufs = iovmax;
- result = process(req);
+ do
+ result = uv__fs_write(req);
+ while (result < 0 && errno == EINTR);
+
if (result <= 0) {
if (total == 0)
total = result;
@@ -917,14 +1130,12 @@ static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process)
if (req->off >= 0)
req->off += result;
+ req->nbufs = uv__fs_buf_offset(req->bufs, result);
req->bufs += req->nbufs;
nbufs -= req->nbufs;
total += result;
}
- if (errno == EINTR && total == -1)
- return total;
-
if (bufs != req->bufsml)
uv__free(bufs);
@@ -941,7 +1152,8 @@ static void uv__fs_work(struct uv__work* w) {
ssize_t r;
req = container_of(w, uv_fs_t, work_req);
- retry_on_eintr = !(req->fs_type == UV_FS_CLOSE);
+ retry_on_eintr = !(req->fs_type == UV_FS_CLOSE ||
+ req->fs_type == UV_FS_READ);
do {
errno = 0;
@@ -956,8 +1168,10 @@ static void uv__fs_work(struct uv__work* w) {
X(CHMOD, chmod(req->path, req->mode));
X(CHOWN, chown(req->path, req->uid, req->gid));
X(CLOSE, close(req->file));
+ X(COPYFILE, uv__fs_copyfile(req));
X(FCHMOD, fchmod(req->file, req->mode));
X(FCHOWN, fchown(req->file, req->uid, req->gid));
+ X(LCHOWN, lchown(req->path, req->uid, req->gid));
X(FDATASYNC, uv__fs_fdatasync(req));
X(FSTAT, uv__fs_fstat(req->file, &req->statbuf));
X(FSYNC, uv__fs_fsync(req));
@@ -968,7 +1182,7 @@ static void uv__fs_work(struct uv__work* w) {
X(MKDIR, mkdir(req->path, req->mode));
X(MKDTEMP, uv__fs_mkdtemp(req));
X(OPEN, uv__fs_open(req));
- X(READ, uv__fs_buf_iter(req, uv__fs_read));
+ X(READ, uv__fs_read(req));
X(SCANDIR, uv__fs_scandir(req));
X(READLINK, uv__fs_readlink(req));
X(REALPATH, uv__fs_realpath(req));
@@ -979,14 +1193,14 @@ static void uv__fs_work(struct uv__work* w) {
X(SYMLINK, symlink(req->path, req->new_path));
X(UNLINK, unlink(req->path));
X(UTIME, uv__fs_utime(req));
- X(WRITE, uv__fs_buf_iter(req, uv__fs_write));
+ X(WRITE, uv__fs_write_all(req));
default: abort();
}
#undef X
} while (r == -1 && errno == EINTR && retry_on_eintr);
if (r == -1)
- req->result = -errno;
+ req->result = UV__ERR(errno);
else
req->result = r;
@@ -1004,9 +1218,9 @@ static void uv__fs_done(struct uv__work* w, int status) {
req = container_of(w, uv_fs_t, work_req);
uv__req_unregister(req->loop, req);
- if (status == -ECANCELED) {
+ if (status == UV_ECANCELED) {
assert(req->result == 0);
- req->result = -ECANCELED;
+ req->result = UV_ECANCELED;
}
req->cb(req);
@@ -1084,6 +1298,20 @@ int uv_fs_fchown(uv_loop_t* loop,
}
+int uv_fs_lchown(uv_loop_t* loop,
+ uv_fs_t* req,
+ const char* path,
+ uv_uid_t uid,
+ uv_gid_t gid,
+ uv_fs_cb cb) {
+ INIT(LCHOWN);
+ PATH;
+ req->uid = uid;
+ req->gid = gid;
+ POST;
+}
+
+
int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
INIT(FDATASYNC);
req->file = file;
@@ -1167,11 +1395,8 @@ int uv_fs_mkdtemp(uv_loop_t* loop,
uv_fs_cb cb) {
INIT(MKDTEMP);
req->path = uv__strdup(tpl);
- if (req->path == NULL) {
- if (cb != NULL)
- uv__req_unregister(loop, req);
- return -ENOMEM;
- }
+ if (req->path == NULL)
+ return UV_ENOMEM;
POST;
}
@@ -1196,10 +1421,11 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
unsigned int nbufs,
int64_t off,
uv_fs_cb cb) {
+ INIT(READ);
+
if (bufs == NULL || nbufs == 0)
- return -EINVAL;
+ return UV_EINVAL;
- INIT(READ);
req->file = file;
req->nbufs = nbufs;
@@ -1207,11 +1433,8 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = uv__malloc(nbufs * sizeof(*bufs));
- if (req->bufs == NULL) {
- if (cb != NULL)
- uv__req_unregister(loop, req);
- return -ENOMEM;
- }
+ if (req->bufs == NULL)
+ return UV_ENOMEM;
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
@@ -1334,10 +1557,11 @@ int uv_fs_write(uv_loop_t* loop,
unsigned int nbufs,
int64_t off,
uv_fs_cb cb) {
+ INIT(WRITE);
+
if (bufs == NULL || nbufs == 0)
- return -EINVAL;
+ return UV_EINVAL;
- INIT(WRITE);
req->file = file;
req->nbufs = nbufs;
@@ -1345,11 +1569,8 @@ int uv_fs_write(uv_loop_t* loop,
if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = uv__malloc(nbufs * sizeof(*bufs));
- if (req->bufs == NULL) {
- if (cb != NULL)
- uv__req_unregister(loop, req);
- return -ENOMEM;
- }
+ if (req->bufs == NULL)
+ return UV_ENOMEM;
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
@@ -1359,6 +1580,9 @@ int uv_fs_write(uv_loop_t* loop,
void uv_fs_req_cleanup(uv_fs_t* req) {
+ if (req == NULL)
+ return;
+
/* Only necessary for asychronous requests, i.e., requests with a callback.
* Synchronous ones don't copy their arguments and have req->path and
* req->new_path pointing to user-owned memory. UV_FS_MKDTEMP is the
@@ -1373,7 +1597,31 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL)
uv__fs_scandir_cleanup(req);
+ if (req->bufs != req->bufsml)
+ uv__free(req->bufs);
+ req->bufs = NULL;
+
if (req->ptr != &req->statbuf)
uv__free(req->ptr);
req->ptr = NULL;
}
+
+
+int uv_fs_copyfile(uv_loop_t* loop,
+ uv_fs_t* req,
+ const char* path,
+ const char* new_path,
+ int flags,
+ uv_fs_cb cb) {
+ INIT(COPYFILE);
+
+ if (flags & ~(UV_FS_COPYFILE_EXCL |
+ UV_FS_COPYFILE_FICLONE |
+ UV_FS_COPYFILE_FICLONE_FORCE)) {
+ return UV_EINVAL;
+ }
+
+ PATH2;
+ req->flags = flags;
+ POST;
+}
diff --git a/Utilities/cmlibuv/src/unix/fsevents.c b/Utilities/cmlibuv/src/unix/fsevents.c
index 643e233cf..c430562b3 100644
--- a/Utilities/cmlibuv/src/unix/fsevents.c
+++ b/Utilities/cmlibuv/src/unix/fsevents.c
@@ -230,6 +230,7 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef,
uv_loop_t* loop;
uv__cf_loop_state_t* state;
uv__fsevents_event_t* event;
+ FSEventStreamEventFlags flags;
QUEUE head;
loop = info;
@@ -245,58 +246,77 @@ static void uv__fsevents_event_cb(ConstFSEventStreamRef streamRef,
/* Process and filter out events */
for (i = 0; i < numEvents; i++) {
+ flags = eventFlags[i];
+
/* Ignore system events */
- if (eventFlags[i] & kFSEventsSystem)
+ if (flags & kFSEventsSystem)
continue;
path = paths[i];
len = strlen(path);
+ if (handle->realpath_len == 0)
+ continue; /* This should be unreachable */
+
/* Filter out paths that are outside handle's request */
- if (strncmp(path, handle->realpath, handle->realpath_len) != 0)
+ if (len < handle->realpath_len)
+ continue;
+
+ if (handle->realpath_len != len &&
+ path[handle->realpath_len] != '/')
+ /* Make sure that realpath actually named a directory,
+ * or that we matched the whole string */
+ continue;
+
+ if (memcmp(path, handle->realpath, handle->realpath_len) != 0)
continue;
- if (handle->realpath_len > 1 || *handle->realpath != '/') {
+ if (!(handle->realpath_len == 1 && handle->realpath[0] == '/')) {
+ /* Remove common prefix, unless the watched folder is "/" */
path += handle->realpath_len;
len -= handle->realpath_len;
- /* Skip forward slash */
- if (*path != '\0') {
+ /* Ignore events with path equal to directory itself */
+ if (len <= 1 && (flags & kFSEventStreamEventFlagItemIsDir))
+ continue;
+
+ if (len == 0) {
+ /* Since we're using fsevents to watch the file itself,
+ * realpath == path, and we now need to get the basename of the file back
+ * (for commonality with other codepaths and platforms). */
+ while (len < handle->realpath_len && path[-1] != '/') {
+ path--;
+ len++;
+ }
+ /* Created and Removed seem to be always set, but don't make sense */
+ flags &= ~kFSEventsRenamed;
+ } else {
+ /* Skip forward slash */
path++;
len--;
}
}
-#ifdef MAC_OS_X_VERSION_10_7
- /* Ignore events with path equal to directory itself */
- if (len == 0)
- continue;
-#endif /* MAC_OS_X_VERSION_10_7 */
-
/* Do not emit events from subdirectories (without option set) */
- if ((handle->cf_flags & UV_FS_EVENT_RECURSIVE) == 0 && *path != 0) {
+ if ((handle->cf_flags & UV_FS_EVENT_RECURSIVE) == 0 && *path != '\0') {
pos = strchr(path + 1, '/');
if (pos != NULL)
continue;
}
-#ifndef MAC_OS_X_VERSION_10_7
- path = "";
- len = 0;
-#endif /* MAC_OS_X_VERSION_10_7 */
-
event = uv__malloc(sizeof(*event) + len);
if (event == NULL)
break;
memset(event, 0, sizeof(*event));
memcpy(event->path, path, len + 1);
+ event->events = UV_RENAME;
- if ((eventFlags[i] & kFSEventsModified) != 0 &&
- (eventFlags[i] & kFSEventsRenamed) == 0)
- event->events = UV_CHANGE;
- else
- event->events = UV_RENAME;
+ if (0 == (flags & kFSEventsRenamed)) {
+ if (0 != (flags & kFSEventsModified) ||
+ 0 == (flags & kFSEventStreamEventFlagItemIsDir))
+ event->events = UV_CHANGE;
+ }
QUEUE_INSERT_TAIL(&head, &event->member);
}
@@ -361,7 +381,7 @@ static int uv__fsevents_create_stream(uv_loop_t* loop, CFArrayRef paths) {
if (!pFSEventStreamStart(ref)) {
pFSEventStreamInvalidate(ref);
pFSEventStreamRelease(ref);
- return -EMFILE;
+ return UV_EMFILE;
}
state->fsevent_stream = ref;
@@ -422,7 +442,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle,
uv__fsevents_destroy_stream(handle->loop);
/* Any failure below will be a memory failure */
- err = -ENOMEM;
+ err = UV_ENOMEM;
/* Create list of all watched paths */
uv_mutex_lock(&state->fsevent_mutex);
@@ -456,7 +476,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle,
/* Create new FSEventStream */
cf_paths = pCFArrayCreate(NULL, (const void**) paths, path_count, NULL);
if (cf_paths == NULL) {
- err = -ENOMEM;
+ err = UV_ENOMEM;
goto final;
}
err = uv__fsevents_create_stream(handle->loop, cf_paths);
@@ -510,7 +530,7 @@ static int uv__fsevents_global_init(void) {
* but if it ever becomes one, we can turn the dynamic library handles into
* per-event loop properties and have the dynamic linker keep track for us.
*/
- err = -ENOSYS;
+ err = UV_ENOSYS;
core_foundation_handle = dlopen("/System/Library/Frameworks/"
"CoreFoundation.framework/"
"Versions/A/CoreFoundation",
@@ -525,7 +545,7 @@ static int uv__fsevents_global_init(void) {
if (core_services_handle == NULL)
goto out;
- err = -ENOENT;
+ err = UV_ENOENT;
#define V(handle, symbol) \
do { \
*(void **)(&p ## symbol) = dlsym((handle), #symbol); \
@@ -589,7 +609,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
state = uv__calloc(1, sizeof(*state));
if (state == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
err = uv_mutex_init(&loop->cf_mutex);
if (err)
@@ -618,7 +638,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
ctx.perform = uv__cf_loop_cb;
state->signal_source = pCFRunLoopSourceCreate(NULL, 0, &ctx);
if (state->signal_source == NULL) {
- err = -ENOMEM;
+ err = UV_ENOMEM;
goto fail_signal_source_create;
}
@@ -637,7 +657,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
loop->cf_state = state;
/* uv_thread_t is an alias for pthread_t. */
- err = -pthread_create(&loop->cf_thread, attr, uv__cf_loop_runner, loop);
+ err = UV__ERR(pthread_create(&loop->cf_thread, attr, uv__cf_loop_runner, loop));
if (attr != NULL)
pthread_attr_destroy(attr);
@@ -769,7 +789,7 @@ int uv__cf_loop_signal(uv_loop_t* loop,
item = uv__malloc(sizeof(*item));
if (item == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
item->handle = handle;
item->type = type;
@@ -799,7 +819,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
/* Get absolute path to file */
handle->realpath = realpath(handle->path, NULL);
if (handle->realpath == NULL)
- return -errno;
+ return UV__ERR(errno);
handle->realpath_len = strlen(handle->realpath);
/* Initialize event queue */
@@ -812,13 +832,13 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
*/
handle->cf_cb = uv__malloc(sizeof(*handle->cf_cb));
if (handle->cf_cb == NULL) {
- err = -ENOMEM;
+ err = UV_ENOMEM;
goto fail_cf_cb_malloc;
}
handle->cf_cb->data = handle;
uv_async_init(handle->loop, handle->cf_cb, uv__fsevents_cb);
- handle->cf_cb->flags |= UV__HANDLE_INTERNAL;
+ handle->cf_cb->flags |= UV_HANDLE_INTERNAL;
uv_unref((uv_handle_t*) handle->cf_cb);
err = uv_mutex_init(&handle->cf_mutex);
@@ -863,7 +883,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
uv__cf_loop_state_t* state;
if (handle->cf_cb == NULL)
- return -EINVAL;
+ return UV_EINVAL;
/* Remove handle from the list */
state = handle->loop->cf_state;
@@ -877,7 +897,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
assert(handle != NULL);
err = uv__cf_loop_signal(handle->loop, handle, kUVCFLoopSignalClosing);
if (err)
- return -err;
+ return UV__ERR(err);
/* Wait for deinitialization */
uv_sem_wait(&state->fsevent_sem);
diff --git a/Utilities/cmlibuv/src/unix/getaddrinfo.c b/Utilities/cmlibuv/src/unix/getaddrinfo.c
index 2049aea2f..6d23fbe02 100644
--- a/Utilities/cmlibuv/src/unix/getaddrinfo.c
+++ b/Utilities/cmlibuv/src/unix/getaddrinfo.c
@@ -27,11 +27,13 @@
#include "uv.h"
#include "internal.h"
+#include "idna.h"
#include <errno.h>
#include <stddef.h> /* NULL */
#include <stdlib.h>
#include <string.h>
+#include <net/if.h> /* if_indextoname() */
/* EAI_* constants. */
#include <netdb.h>
@@ -85,7 +87,7 @@ int uv__getaddrinfo_translate_error(int sys_err) {
case EAI_SOCKTYPE: return UV_EAI_SOCKTYPE;
#endif
#if defined(EAI_SYSTEM)
- case EAI_SYSTEM: return -errno;
+ case EAI_SYSTEM: return UV__ERR(errno);
#endif
}
assert(!"unknown EAI_* error code");
@@ -124,7 +126,7 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
req->service = NULL;
req->hostname = NULL;
- if (status == -ECANCELED) {
+ if (status == UV_ECANCELED) {
assert(req->retcode == 0);
req->retcode = UV_EAI_CANCELED;
}
@@ -140,14 +142,33 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* hostname,
const char* service,
const struct addrinfo* hints) {
+ char hostname_ascii[256];
size_t hostname_len;
size_t service_len;
size_t hints_len;
size_t len;
char* buf;
+ long rc;
if (req == NULL || (hostname == NULL && service == NULL))
- return -EINVAL;
+ return UV_EINVAL;
+
+ /* FIXME(bnoordhuis) IDNA does not seem to work z/OS,
+ * probably because it uses EBCDIC rather than ASCII.
+ */
+#ifdef __MVS__
+ (void) &hostname_ascii;
+#else
+ if (hostname != NULL) {
+ rc = uv__idna_toascii(hostname,
+ hostname + strlen(hostname),
+ hostname_ascii,
+ hostname_ascii + sizeof(hostname_ascii));
+ if (rc < 0)
+ return rc;
+ hostname = hostname_ascii;
+ }
+#endif
hostname_len = hostname ? strlen(hostname) + 1 : 0;
service_len = service ? strlen(service) + 1 : 0;
@@ -155,7 +176,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
buf = uv__malloc(hostname_len + service_len + hints_len);
if (buf == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
uv__req_init(loop, req, UV_GETADDRINFO);
req->loop = loop;
@@ -185,6 +206,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (cb) {
uv__work_submit(loop,
&req->work_req,
+ UV__WORK_SLOW_IO,
uv__getaddrinfo_work,
uv__getaddrinfo_done);
return 0;
@@ -200,3 +222,32 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
if (ai)
freeaddrinfo(ai);
}
+
+
+int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
+ char ifname_buf[UV_IF_NAMESIZE];
+ size_t len;
+
+ if (buffer == NULL || size == NULL || *size == 0)
+ return UV_EINVAL;
+
+ if (if_indextoname(ifindex, ifname_buf) == NULL)
+ return UV__ERR(errno);
+
+ len = strnlen(ifname_buf, sizeof(ifname_buf));
+
+ if (*size <= len) {
+ *size = len + 1;
+ return UV_ENOBUFS;
+ }
+
+ memcpy(buffer, ifname_buf, len);
+ buffer[len] = '\0';
+ *size = len;
+
+ return 0;
+}
+
+int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) {
+ return uv_if_indextoname(ifindex, buffer, size);
+}
diff --git a/Utilities/cmlibuv/src/unix/getnameinfo.c b/Utilities/cmlibuv/src/unix/getnameinfo.c
index b2879d69b..b695081b4 100644
--- a/Utilities/cmlibuv/src/unix/getnameinfo.c
+++ b/Utilities/cmlibuv/src/unix/getnameinfo.c
@@ -61,7 +61,7 @@ static void uv__getnameinfo_done(struct uv__work* w, int status) {
uv__req_unregister(req->loop, req);
host = service = NULL;
- if (status == -ECANCELED) {
+ if (status == UV_ECANCELED) {
assert(req->retcode == 0);
req->retcode = UV_EAI_CANCELED;
} else if (req->retcode == 0) {
@@ -109,6 +109,7 @@ int uv_getnameinfo(uv_loop_t* loop,
if (getnameinfo_cb) {
uv__work_submit(loop,
&req->work_req,
+ UV__WORK_SLOW_IO,
uv__getnameinfo_work,
uv__getnameinfo_done);
return 0;
diff --git a/Utilities/cmlibuv/src/unix/internal.h b/Utilities/cmlibuv/src/unix/internal.h
index 2e3afa6c8..48fe6e8b1 100644
--- a/Utilities/cmlibuv/src/unix/internal.h
+++ b/Utilities/cmlibuv/src/unix/internal.h
@@ -29,6 +29,7 @@
#include <string.h> /* strrchr */
#include <fcntl.h> /* O_CLOEXEC, may be */
#include <stdio.h>
+#include <errno.h>
#if defined(__STRICT_ANSI__)
# define inline __inline
@@ -59,7 +60,17 @@
# include <AvailabilityMacros.h>
#endif
-#if defined(__ANDROID__)
+#if defined(CMAKE_BOOTSTRAP)
+# undef pthread_atfork
+# define pthread_atfork(prepare, parent, child) \
+ uv__pthread_atfork(prepare, parent, child)
+int uv__pthread_atfork(void (*prepare)(void), void (*parent)(void),
+ void (*child)(void));
+# undef pthread_sigmask
+# define pthread_sigmask(how, set, oldset) \
+ uv__pthread_sigmask(how, set, oldset)
+int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset);
+#elif defined(__ANDROID__)
int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset);
# ifdef pthread_sigmask
# undef pthread_sigmask
@@ -110,6 +121,12 @@ int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset);
# define UV__POLLRDHUP 0x2000
#endif
+#ifdef POLLPRI
+# define UV__POLLPRI POLLPRI
+#else
+# define UV__POLLPRI 0
+#endif
+
#if !defined(O_CLOEXEC) && defined(__FreeBSD__)
/*
* It may be that we are just missing `__POSIX_VISIBLE >= 200809`.
@@ -120,29 +137,15 @@ int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset);
typedef struct uv__stream_queued_fds_s uv__stream_queued_fds_t;
-/* handle flags */
+/* loop flags */
enum {
- UV_CLOSING = 0x01, /* uv_close() called but not finished. */
- UV_CLOSED = 0x02, /* close(2) finished. */
- UV_STREAM_READING = 0x04, /* uv_read_start() called. */
- UV_STREAM_SHUTTING = 0x08, /* uv_shutdown() called but not complete. */
- UV_STREAM_SHUT = 0x10, /* Write side closed. */
- UV_STREAM_READABLE = 0x20, /* The stream is readable */
- UV_STREAM_WRITABLE = 0x40, /* The stream is writable */
- UV_STREAM_BLOCKING = 0x80, /* Synchronous writes. */
- UV_STREAM_READ_PARTIAL = 0x100, /* read(2) read less than requested. */
- UV_STREAM_READ_EOF = 0x200, /* read(2) read EOF. */
- UV_TCP_NODELAY = 0x400, /* Disable Nagle. */
- UV_TCP_KEEPALIVE = 0x800, /* Turn on keep-alive. */
- UV_TCP_SINGLE_ACCEPT = 0x1000, /* Only accept() when idle. */
- UV_HANDLE_IPV6 = 0x10000, /* Handle is bound to a IPv6 socket. */
- UV_UDP_PROCESSING = 0x20000, /* Handle is running the send callback queue. */
- UV_HANDLE_BOUND = 0x40000 /* Handle is bound to an address and port */
+ UV_LOOP_BLOCK_SIGPROF = 1
};
-/* loop flags */
+/* flags of excluding ifaddr */
enum {
- UV_LOOP_BLOCK_SIGPROF = 1
+ UV__EXCLUDE_IFPHYS,
+ UV__EXCLUDE_IFADDR
};
typedef enum {
@@ -163,7 +166,8 @@ struct uv__stream_queued_fds_s {
defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__) || \
defined(__linux__) || \
- defined(__OpenBSD__)
+ defined(__OpenBSD__) || \
+ defined(__NetBSD__)
#define uv__cloexec uv__cloexec_ioctl
#define uv__nonblock uv__nonblock_ioctl
#else
@@ -171,15 +175,26 @@ struct uv__stream_queued_fds_s {
#define uv__nonblock uv__nonblock_fcntl
#endif
+/* On Linux, uv__nonblock_fcntl() and uv__nonblock_ioctl() do not commute
+ * when O_NDELAY is not equal to O_NONBLOCK. Case in point: linux/sparc32
+ * and linux/sparc64, where O_NDELAY is O_NONBLOCK + another bit.
+ *
+ * Libuv uses uv__nonblock_fcntl() directly sometimes so ensure that it
+ * commutes with uv__nonblock().
+ */
+#if defined(__linux__) && O_NDELAY != O_NONBLOCK
+#undef uv__nonblock
+#define uv__nonblock uv__nonblock_fcntl
+#endif
+
/* core */
int uv__cloexec_ioctl(int fd, int set);
int uv__cloexec_fcntl(int fd, int set);
int uv__nonblock_ioctl(int fd, int set);
int uv__nonblock_fcntl(int fd, int set);
-int uv__close(int fd);
+int uv__close(int fd); /* preserves errno */
int uv__close_nocheckstdio(int fd);
int uv__socket(int domain, int type, int protocol);
-int uv__dup(int fd);
ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags);
void uv__make_close_pending(uv_handle_t* handle);
int uv__getiovmax(void);
@@ -193,6 +208,7 @@ int uv__io_active(const uv__io_t* w, unsigned int events);
int uv__io_check_fd(uv_loop_t* loop, int fd);
void uv__io_poll(uv_loop_t* loop, int timeout); /* in milliseconds or -1 */
int uv__io_fork(uv_loop_t* loop);
+int uv__fd_exists(uv_loop_t* loop, int fd);
/* async */
void uv__async_stop(uv_loop_t* loop);
@@ -225,10 +241,6 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay);
/* pipe */
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
-/* timer */
-void uv__run_timers(uv_loop_t* loop);
-int uv__next_timeout(const uv_loop_t* loop);
-
/* signal */
void uv__signal_close(uv_signal_t* handle);
void uv__signal_global_once_init(void);
@@ -253,7 +265,6 @@ void uv__prepare_close(uv_prepare_t* handle);
void uv__process_close(uv_process_t* handle);
void uv__stream_close(uv_stream_t* handle);
void uv__tcp_close(uv_tcp_t* handle);
-void uv__timer_close(uv_timer_t* handle);
void uv__udp_close(uv_udp_t* handle);
void uv__udp_finish_close(uv_udp_t* handle);
uv_handle_type uv__handle_type(int fd);
@@ -261,7 +272,7 @@ FILE* uv__open_file(const char* path);
int uv__getpwuid_r(uv_passwd_t* pwd);
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
int uv___stream_fd(const uv_stream_t* handle);
#define uv__stream_fd(handle) (uv___stream_fd((const uv_stream_t*) (handle)))
#else
@@ -283,24 +294,6 @@ int uv__fsevents_init(uv_fs_event_t* handle);
int uv__fsevents_close(uv_fs_event_t* handle);
void uv__fsevents_loop_delete(uv_loop_t* loop);
-/* OSX < 10.7 has no file events, polyfill them */
-#ifndef MAC_OS_X_VERSION_10_7
-
-static const int kFSEventStreamCreateFlagFileEvents = 0x00000010;
-static const int kFSEventStreamEventFlagItemCreated = 0x00000100;
-static const int kFSEventStreamEventFlagItemRemoved = 0x00000200;
-static const int kFSEventStreamEventFlagItemInodeMetaMod = 0x00000400;
-static const int kFSEventStreamEventFlagItemRenamed = 0x00000800;
-static const int kFSEventStreamEventFlagItemModified = 0x00001000;
-static const int kFSEventStreamEventFlagItemFinderInfoMod = 0x00002000;
-static const int kFSEventStreamEventFlagItemChangeOwner = 0x00004000;
-static const int kFSEventStreamEventFlagItemXattrMod = 0x00008000;
-static const int kFSEventStreamEventFlagItemIsFile = 0x00010000;
-static const int kFSEventStreamEventFlagItemIsDir = 0x00020000;
-static const int kFSEventStreamEventFlagItemIsSymlink = 0x00040000;
-
-#endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070 */
-
#endif /* defined(__APPLE__) */
UV_UNUSED(static void uv__update_time(uv_loop_t* loop)) {
diff --git a/Utilities/cmlibuv/src/unix/kqueue.c b/Utilities/cmlibuv/src/unix/kqueue.c
index 6bc60bbe4..c24f96e13 100644
--- a/Utilities/cmlibuv/src/unix/kqueue.c
+++ b/Utilities/cmlibuv/src/unix/kqueue.c
@@ -34,13 +34,24 @@
#include <fcntl.h>
#include <time.h>
+/*
+ * Required on
+ * - Until at least FreeBSD 11.0
+ * - Older versions of Mac OS X
+ *
+ * http://www.boost.org/doc/libs/1_61_0/boost/asio/detail/kqueue_reactor.hpp
+ */
+#ifndef EV_OOBAND
+#define EV_OOBAND EV_FLAG1
+#endif
+
static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags);
int uv__kqueue_init(uv_loop_t* loop) {
loop->backend_fd = kqueue();
if (loop->backend_fd == -1)
- return -errno;
+ return UV__ERR(errno);
uv__cloexec(loop->backend_fd, 1);
@@ -48,11 +59,12 @@ int uv__kqueue_init(uv_loop_t* loop) {
}
+#if defined(__APPLE__)
static int uv__has_forked_with_cfrunloop;
+#endif
int uv__io_fork(uv_loop_t* loop) {
int err;
- uv__close(loop->backend_fd);
loop->backend_fd = -1;
err = uv__kqueue_init(loop);
if (err)
@@ -86,7 +98,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
rc = 0;
EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, 0);
if (kevent(loop->backend_fd, &ev, 1, NULL, 0, NULL))
- rc = -errno;
+ rc = UV__ERR(errno);
EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
if (rc == 0)
@@ -166,6 +178,16 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
}
}
+ if ((w->events & UV__POLLPRI) == 0 && (w->pevents & UV__POLLPRI) != 0) {
+ EV_SET(events + nevents, w->fd, EV_OOBAND, EV_ADD, 0, 0, 0);
+
+ if (++nevents == ARRAY_SIZE(events)) {
+ if (kevent(loop->backend_fd, events, nevents, NULL, 0, NULL))
+ abort();
+ nevents = 0;
+ }
+ }
+
w->events = w->pevents;
}
@@ -239,8 +261,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
w = loop->watchers[fd];
if (w == NULL) {
- /* File descriptor that we've stopped watching, disarm it. */
- /* TODO batch up */
+ /* File descriptor that we've stopped watching, disarm it.
+ * TODO: batch up. */
struct kevent events[1];
EV_SET(events + 0, fd, ev->filter, EV_DELETE, 0, 0, 0);
@@ -275,6 +297,20 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
}
}
+ if (ev->filter == EV_OOBAND) {
+ if (w->pevents & UV__POLLPRI) {
+ revents |= UV__POLLPRI;
+ w->rcount = ev->data;
+ } else {
+ /* TODO batch up */
+ struct kevent events[1];
+ EV_SET(events + 0, fd, ev->filter, EV_DELETE, 0, 0, 0);
+ if (kevent(loop->backend_fd, events, 1, NULL, 0, NULL))
+ if (errno != ENOENT)
+ abort();
+ }
+ }
+
if (ev->filter == EVFILT_WRITE) {
if (w->pevents & POLLOUT) {
revents |= POLLOUT;
@@ -416,49 +452,48 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv_fs_event_cb cb,
const char* path,
unsigned int flags) {
-#if defined(__APPLE__)
- struct stat statbuf;
-#endif /* defined(__APPLE__) */
int fd;
if (uv__is_active(handle))
- return -EINVAL;
-
- /* TODO open asynchronously - but how do we report back errors? */
- fd = open(path, O_RDONLY);
- if (fd == -1)
- return -errno;
-
- uv__handle_start(handle);
- uv__io_init(&handle->event_watcher, uv__fs_event, fd);
- handle->path = uv__strdup(path);
- handle->cb = cb;
+ return UV_EINVAL;
#if defined(__APPLE__)
- if (uv__has_forked_with_cfrunloop)
- goto fallback;
-
/* Nullify field to perform checks later */
handle->cf_cb = NULL;
handle->realpath = NULL;
handle->realpath_len = 0;
handle->cf_flags = flags;
- if (fstat(fd, &statbuf))
- goto fallback;
- /* FSEvents works only with directories */
- if (!(statbuf.st_mode & S_IFDIR))
- goto fallback;
-
- /* The fallback fd is no longer needed */
- uv__close(fd);
- handle->event_watcher.fd = -1;
-
- return uv__fsevents_init(handle);
-
-fallback:
+ if (!uv__has_forked_with_cfrunloop) {
+ int r;
+ /* The fallback fd is not used */
+ handle->event_watcher.fd = -1;
+ handle->path = uv__strdup(path);
+ if (handle->path == NULL)
+ return UV_ENOMEM;
+ handle->cb = cb;
+ r = uv__fsevents_init(handle);
+ if (r == 0) {
+ uv__handle_start(handle);
+ } else {
+ uv__free(handle->path);
+ handle->path = NULL;
+ }
+ return r;
+ }
#endif /* defined(__APPLE__) */
+ /* TODO open asynchronously - but how do we report back errors? */
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return UV__ERR(errno);
+
+ handle->path = uv__strdup(path);
+ if (handle->path == NULL)
+ return UV_ENOMEM;
+ handle->cb = cb;
+ uv__handle_start(handle);
+ uv__io_init(&handle->event_watcher, uv__fs_event, fd);
uv__io_start(handle->loop, &handle->event_watcher, POLLIN);
return 0;
@@ -466,29 +501,29 @@ fallback:
int uv_fs_event_stop(uv_fs_event_t* handle) {
+ int r;
+ r = 0;
+
if (!uv__is_active(handle))
return 0;
uv__handle_stop(handle);
#if defined(__APPLE__)
- if (uv__has_forked_with_cfrunloop || uv__fsevents_close(handle))
-#endif /* defined(__APPLE__) */
- {
- uv__io_close(handle->loop, &handle->event_watcher);
- }
-
- uv__free(handle->path);
- handle->path = NULL;
+ if (!uv__has_forked_with_cfrunloop)
+ r = uv__fsevents_close(handle);
+#endif
if (handle->event_watcher.fd != -1) {
- /* When FSEvents is used, we don't use the event_watcher's fd under certain
- * confitions. (see uv_fs_event_start) */
+ uv__io_close(handle->loop, &handle->event_watcher);
uv__close(handle->event_watcher.fd);
handle->event_watcher.fd = -1;
}
- return 0;
+ uv__free(handle->path);
+ handle->path = NULL;
+
+ return r;
}
diff --git a/Utilities/cmlibuv/src/unix/linux-core.c b/Utilities/cmlibuv/src/unix/linux-core.c
index 2866e9385..3341b94e1 100644
--- a/Utilities/cmlibuv/src/unix/linux-core.c
+++ b/Utilities/cmlibuv/src/unix/linux-core.c
@@ -20,7 +20,7 @@
/* We lean on the fact that POLL{IN,OUT,ERR,HUP} correspond with their
* EPOLL* counterparts. We use the POLL* variants in this file because that
- * is what libuv uses elsewhere and it avoids a dependency on <sys/epoll.h>.
+ * is what libuv uses elsewhere.
*/
#include "uv.h"
@@ -34,6 +34,7 @@
#include <errno.h>
#include <net/if.h>
+#include <sys/epoll.h>
#include <sys/param.h>
#include <sys/prctl.h>
#include <sys/sysinfo.h>
@@ -51,7 +52,7 @@
#ifdef HAVE_IFADDRS_H
# if defined(__ANDROID__)
-# include "android-ifaddrs.h"
+# include "uv/android-ifaddrs.h"
# else
# include <ifaddrs.h>
# endif
@@ -84,13 +85,13 @@ static unsigned long read_cpufreq(unsigned int cpunum);
int uv__platform_loop_init(uv_loop_t* loop) {
int fd;
- fd = uv__epoll_create1(UV__EPOLL_CLOEXEC);
+ fd = epoll_create1(EPOLL_CLOEXEC);
/* epoll_create1() can fail either because it's not implemented (old kernel)
* or because it doesn't understand the EPOLL_CLOEXEC flag.
*/
if (fd == -1 && (errno == ENOSYS || errno == EINVAL)) {
- fd = uv__epoll_create(256);
+ fd = epoll_create(256);
if (fd != -1)
uv__cloexec(fd, 1);
@@ -101,7 +102,7 @@ int uv__platform_loop_init(uv_loop_t* loop) {
loop->inotify_watchers = NULL;
if (fd == -1)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -134,20 +135,20 @@ void uv__platform_loop_delete(uv_loop_t* loop) {
void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
- struct uv__epoll_event* events;
- struct uv__epoll_event dummy;
+ struct epoll_event* events;
+ struct epoll_event dummy;
uintptr_t i;
uintptr_t nfds;
assert(loop->watchers != NULL);
- events = (struct uv__epoll_event*) loop->watchers[loop->nwatchers];
+ events = (struct epoll_event*) loop->watchers[loop->nwatchers];
nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1];
if (events != NULL)
/* Invalidate events with same file descriptor */
for (i = 0; i < nfds; i++)
- if ((int) events[i].data == fd)
- events[i].data = -1;
+ if (events[i].data.fd == fd)
+ events[i].data.fd = -1;
/* Remove the file descriptor from the epoll.
* This avoids a problem where the same file description remains open
@@ -160,25 +161,26 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
* has the EPOLLWAKEUP flag set generates spurious audit syslog warnings.
*/
memset(&dummy, 0, sizeof(dummy));
- uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_DEL, fd, &dummy);
+ epoll_ctl(loop->backend_fd, EPOLL_CTL_DEL, fd, &dummy);
}
}
int uv__io_check_fd(uv_loop_t* loop, int fd) {
- struct uv__epoll_event e;
+ struct epoll_event e;
int rc;
+ memset(&e, 0, sizeof(e));
e.events = POLLIN;
- e.data = -1;
+ e.data.fd = -1;
rc = 0;
- if (uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_ADD, fd, &e))
+ if (epoll_ctl(loop->backend_fd, EPOLL_CTL_ADD, fd, &e))
if (errno != EEXIST)
- rc = -errno;
+ rc = UV__ERR(errno);
if (rc == 0)
- if (uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_DEL, fd, &e))
+ if (epoll_ctl(loop->backend_fd, EPOLL_CTL_DEL, fd, &e))
abort();
return rc;
@@ -195,16 +197,14 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* that being the largest value I have seen in the wild (and only once.)
*/
static const int max_safe_timeout = 1789569;
- static int no_epoll_pwait;
- static int no_epoll_wait;
- struct uv__epoll_event events[1024];
- struct uv__epoll_event* pe;
- struct uv__epoll_event e;
+ struct epoll_event events[1024];
+ struct epoll_event* pe;
+ struct epoll_event e;
int real_timeout;
QUEUE* q;
uv__io_t* w;
sigset_t sigset;
- uint64_t sigmask;
+ sigset_t* psigset;
uint64_t base;
int have_signals;
int nevents;
@@ -219,6 +219,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
return;
}
+ memset(&e, 0, sizeof(e));
+
while (!QUEUE_EMPTY(&loop->watcher_queue)) {
q = QUEUE_HEAD(&loop->watcher_queue);
QUEUE_REMOVE(q);
@@ -230,35 +232,35 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
assert(w->fd < (int) loop->nwatchers);
e.events = w->pevents;
- e.data = w->fd;
+ e.data.fd = w->fd;
if (w->events == 0)
- op = UV__EPOLL_CTL_ADD;
+ op = EPOLL_CTL_ADD;
else
- op = UV__EPOLL_CTL_MOD;
+ op = EPOLL_CTL_MOD;
/* XXX Future optimization: do EPOLL_CTL_MOD lazily if we stop watching
* events, skip the syscall and squelch the events after epoll_wait().
*/
- if (uv__epoll_ctl(loop->backend_fd, op, w->fd, &e)) {
+ if (epoll_ctl(loop->backend_fd, op, w->fd, &e)) {
if (errno != EEXIST)
abort();
- assert(op == UV__EPOLL_CTL_ADD);
+ assert(op == EPOLL_CTL_ADD);
/* We've reactivated a file descriptor that's been watched before. */
- if (uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_MOD, w->fd, &e))
+ if (epoll_ctl(loop->backend_fd, EPOLL_CTL_MOD, w->fd, &e))
abort();
}
w->events = w->pevents;
}
- sigmask = 0;
+ psigset = NULL;
if (loop->flags & UV_LOOP_BLOCK_SIGPROF) {
sigemptyset(&sigset);
sigaddset(&sigset, SIGPROF);
- sigmask |= 1 << (SIGPROF - 1);
+ psigset = &sigset;
}
assert(timeout >= -1);
@@ -273,30 +275,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (sizeof(int32_t) == sizeof(long) && timeout >= max_safe_timeout)
timeout = max_safe_timeout;
- if (sigmask != 0 && no_epoll_pwait != 0)
- if (pthread_sigmask(SIG_BLOCK, &sigset, NULL))
- abort();
-
- if (no_epoll_wait != 0 || (sigmask != 0 && no_epoll_pwait == 0)) {
- nfds = uv__epoll_pwait(loop->backend_fd,
- events,
- ARRAY_SIZE(events),
- timeout,
- sigmask);
- if (nfds == -1 && errno == ENOSYS)
- no_epoll_pwait = 1;
- } else {
- nfds = uv__epoll_wait(loop->backend_fd,
- events,
- ARRAY_SIZE(events),
- timeout);
- if (nfds == -1 && errno == ENOSYS)
- no_epoll_wait = 1;
- }
-
- if (sigmask != 0 && no_epoll_pwait != 0)
- if (pthread_sigmask(SIG_UNBLOCK, &sigset, NULL))
- abort();
+ nfds = epoll_pwait(loop->backend_fd,
+ events,
+ ARRAY_SIZE(events),
+ timeout,
+ psigset);
/* Update loop->time unconditionally. It's tempting to skip the update when
* timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
@@ -317,12 +300,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
}
if (nfds == -1) {
- if (errno == ENOSYS) {
- /* epoll_wait() or epoll_pwait() failed, try the other system call. */
- assert(no_epoll_wait == 0 || no_epoll_pwait == 0);
- continue;
- }
-
if (errno != EINTR)
abort();
@@ -344,7 +321,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
loop->watchers[loop->nwatchers + 1] = (void*) (uintptr_t) nfds;
for (i = 0; i < nfds; i++) {
pe = events + i;
- fd = pe->data;
+ fd = pe->data.fd;
/* Skip invalidated events, see uv__platform_invalidate_fd */
if (fd == -1)
@@ -361,7 +338,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* Ignore all errors because we may be racing with another thread
* when the file descriptor is closed.
*/
- uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_DEL, fd, pe);
+ epoll_ctl(loop->backend_fd, EPOLL_CTL_DEL, fd, pe);
continue;
}
@@ -388,7 +365,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* free when we switch over to edge-triggered I/O.
*/
if (pe->events == POLLERR || pe->events == POLLHUP)
- pe->events |= w->pevents & (POLLIN | POLLOUT);
+ pe->events |=
+ w->pevents & (POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
if (pe->events != 0) {
/* Run signal watchers last. This also affects child process watchers
@@ -485,7 +463,7 @@ int uv_resident_set_memory(size_t* rss) {
while (fd == -1 && errno == EINTR);
if (fd == -1)
- return -errno;
+ return UV__ERR(errno);
do
n = read(fd, buf, sizeof(buf) - 1);
@@ -493,7 +471,7 @@ int uv_resident_set_memory(size_t* rss) {
uv__close(fd);
if (n == -1)
- return -errno;
+ return UV__ERR(errno);
buf[n] = '\0';
s = strchr(buf, ' ');
@@ -525,7 +503,7 @@ int uv_resident_set_memory(size_t* rss) {
return 0;
err:
- return -EINVAL;
+ return UV_EINVAL;
}
@@ -547,7 +525,7 @@ int uv_uptime(double* uptime) {
}
if (r)
- return -errno;
+ return UV__ERR(errno);
*uptime = now.tv_sec;
return 0;
@@ -559,7 +537,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) {
char buf[1024];
if (!fgets(buf, sizeof(buf), statfile_fp))
- return -EIO;
+ return UV_EIO;
num = 0;
while (fgets(buf, sizeof(buf), statfile_fp)) {
@@ -569,7 +547,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) {
}
if (num == 0)
- return -EIO;
+ return UV_EIO;
*numcpus = num;
return 0;
@@ -587,13 +565,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
statfile_fp = uv__open_file("/proc/stat");
if (statfile_fp == NULL)
- return -errno;
+ return UV__ERR(errno);
err = uv__cpu_num(statfile_fp, &numcpus);
if (err < 0)
goto out;
- err = -ENOMEM;
+ err = UV_ENOMEM;
ci = uv__calloc(numcpus, sizeof(*ci));
if (ci == NULL)
goto out;
@@ -667,7 +645,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
defined(__x86_64__)
fp = uv__open_file("/proc/cpuinfo");
if (fp == NULL)
- return -errno;
+ return UV__ERR(errno);
while (fgets(buf, sizeof(buf), fp)) {
if (model_idx < numcpus) {
@@ -676,7 +654,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) {
fclose(fp);
- return -ENOMEM;
+ return UV_ENOMEM;
}
ci[model_idx++].model = model;
continue;
@@ -695,7 +673,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) {
fclose(fp);
- return -ENOMEM;
+ return UV_ENOMEM;
}
ci[model_idx++].model = model;
continue;
@@ -725,7 +703,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
while (model_idx < numcpus) {
model = uv__strndup(inferred_model, strlen(inferred_model));
if (model == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
ci[model_idx++].model = model;
}
@@ -837,7 +815,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
uv__free(cpu_infos);
}
-static int uv__ifaddr_exclude(struct ifaddrs *ent) {
+static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
if (!((ent->ifa_flags & IFF_UP) && (ent->ifa_flags & IFF_RUNNING)))
return 1;
if (ent->ifa_addr == NULL)
@@ -847,47 +825,50 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent) {
* devices. We're not interested in this information yet.
*/
if (ent->ifa_addr->sa_family == PF_PACKET)
- return 1;
- return 0;
+ return exclude_type;
+ return !exclude_type;
}
-int uv_interface_addresses(uv_interface_address_t** addresses,
- int* count) {
+int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
#ifndef HAVE_IFADDRS_H
- return -ENOSYS;
+ *count = 0;
+ *addresses = NULL;
+ return UV_ENOSYS;
#else
struct ifaddrs *addrs, *ent;
uv_interface_address_t* address;
int i;
struct sockaddr_ll *sll;
- if (getifaddrs(&addrs))
- return -errno;
-
*count = 0;
*addresses = NULL;
+ if (getifaddrs(&addrs))
+ return UV__ERR(errno);
+
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
- if (uv__ifaddr_exclude(ent))
+ if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
continue;
(*count)++;
}
- if (*count == 0)
+ if (*count == 0) {
+ freeifaddrs(addrs);
return 0;
+ }
*addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) {
freeifaddrs(addrs);
- return -ENOMEM;
+ return UV_ENOMEM;
}
address = *addresses;
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
- if (uv__ifaddr_exclude(ent))
+ if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
continue;
address->name = uv__strdup(ent->ifa_name);
@@ -911,7 +892,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
/* Fill in physical addresses for each interface */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
- if (uv__ifaddr_exclude(ent))
+ if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFPHYS))
continue;
address = *addresses;
@@ -920,6 +901,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
if (strcmp(address->name, ent->ifa_name) == 0) {
sll = (struct sockaddr_ll*)ent->ifa_addr;
memcpy(address->phys_addr, sll->sll_addr, sizeof(address->phys_addr));
+ } else {
+ memset(address->phys_addr, 0, sizeof(address->phys_addr));
}
address++;
}
diff --git a/Utilities/cmlibuv/src/unix/linux-inotify.c b/Utilities/cmlibuv/src/unix/linux-inotify.c
index 5934c5d8c..9b26202fb 100644
--- a/Utilities/cmlibuv/src/unix/linux-inotify.c
+++ b/Utilities/cmlibuv/src/unix/linux-inotify.c
@@ -19,7 +19,7 @@
*/
#include "uv.h"
-#include "tree.h"
+#include "uv/tree.h"
#include "internal.h"
#include <stdint.h>
@@ -73,11 +73,11 @@ static int new_inotify_fd(void) {
return fd;
if (errno != ENOSYS)
- return -errno;
+ return UV__ERR(errno);
fd = uv__inotify_init();
if (fd == -1)
- return -errno;
+ return UV__ERR(errno);
err = uv__cloexec(fd, 1);
if (err == 0)
@@ -278,12 +278,13 @@ int uv_fs_event_start(uv_fs_event_t* handle,
const char* path,
unsigned int flags) {
struct watcher_list* w;
+ size_t len;
int events;
int err;
int wd;
if (uv__is_active(handle))
- return -EINVAL;
+ return UV_EINVAL;
err = init_inotify(handle->loop);
if (err)
@@ -300,18 +301,19 @@ int uv_fs_event_start(uv_fs_event_t* handle,
wd = uv__inotify_add_watch(handle->loop->inotify_fd, path, events);
if (wd == -1)
- return -errno;
+ return UV__ERR(errno);
w = find_watcher(handle->loop, wd);
if (w)
goto no_insert;
- w = uv__malloc(sizeof(*w) + strlen(path) + 1);
+ len = strlen(path) + 1;
+ w = uv__malloc(sizeof(*w) + len);
if (w == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
w->wd = wd;
- w->path = strcpy((char*)(w + 1), path);
+ w->path = memcpy(w + 1, path, len);
QUEUE_INIT(&w->watchers);
w->iterating = 0;
RB_INSERT(watcher_root, CAST(&handle->loop->inotify_watchers), w);
diff --git a/Utilities/cmlibuv/src/unix/linux-syscalls.c b/Utilities/cmlibuv/src/unix/linux-syscalls.c
index 89998ded2..bfd754487 100644
--- a/Utilities/cmlibuv/src/unix/linux-syscalls.c
+++ b/Utilities/cmlibuv/src/unix/linux-syscalls.c
@@ -77,56 +77,6 @@
# endif
#endif /* __NR_eventfd2 */
-#ifndef __NR_epoll_create
-# if defined(__x86_64__)
-# define __NR_epoll_create 213
-# elif defined(__i386__)
-# define __NR_epoll_create 254
-# elif defined(__arm__)
-# define __NR_epoll_create (UV_SYSCALL_BASE + 250)
-# endif
-#endif /* __NR_epoll_create */
-
-#ifndef __NR_epoll_create1
-# if defined(__x86_64__)
-# define __NR_epoll_create1 291
-# elif defined(__i386__)
-# define __NR_epoll_create1 329
-# elif defined(__arm__)
-# define __NR_epoll_create1 (UV_SYSCALL_BASE + 357)
-# endif
-#endif /* __NR_epoll_create1 */
-
-#ifndef __NR_epoll_ctl
-# if defined(__x86_64__)
-# define __NR_epoll_ctl 233 /* used to be 214 */
-# elif defined(__i386__)
-# define __NR_epoll_ctl 255
-# elif defined(__arm__)
-# define __NR_epoll_ctl (UV_SYSCALL_BASE + 251)
-# endif
-#endif /* __NR_epoll_ctl */
-
-#ifndef __NR_epoll_wait
-# if defined(__x86_64__)
-# define __NR_epoll_wait 232 /* used to be 215 */
-# elif defined(__i386__)
-# define __NR_epoll_wait 256
-# elif defined(__arm__)
-# define __NR_epoll_wait (UV_SYSCALL_BASE + 252)
-# endif
-#endif /* __NR_epoll_wait */
-
-#ifndef __NR_epoll_pwait
-# if defined(__x86_64__)
-# define __NR_epoll_pwait 281
-# elif defined(__i386__)
-# define __NR_epoll_pwait 319
-# elif defined(__arm__)
-# define __NR_epoll_pwait (UV_SYSCALL_BASE + 346)
-# endif
-#endif /* __NR_epoll_pwait */
-
#ifndef __NR_inotify_init
# if defined(__x86_64__)
# define __NR_inotify_init 253
@@ -285,76 +235,6 @@ int uv__eventfd2(unsigned int count, int flags) {
}
-int uv__epoll_create(int size) {
-#if defined(__NR_epoll_create)
- return syscall(__NR_epoll_create, size);
-#else
- return errno = ENOSYS, -1;
-#endif
-}
-
-
-int uv__epoll_create1(int flags) {
-#if defined(__NR_epoll_create1)
- return syscall(__NR_epoll_create1, flags);
-#else
- return errno = ENOSYS, -1;
-#endif
-}
-
-
-int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event* events) {
-#if defined(__NR_epoll_ctl)
- return syscall(__NR_epoll_ctl, epfd, op, fd, events);
-#else
- return errno = ENOSYS, -1;
-#endif
-}
-
-
-int uv__epoll_wait(int epfd,
- struct uv__epoll_event* events,
- int nevents,
- int timeout) {
-#if defined(__NR_epoll_wait)
- int result;
- result = syscall(__NR_epoll_wait, epfd, events, nevents, timeout);
-#if MSAN_ACTIVE
- if (result > 0)
- __msan_unpoison(events, sizeof(events[0]) * result);
-#endif
- return result;
-#else
- return errno = ENOSYS, -1;
-#endif
-}
-
-
-int uv__epoll_pwait(int epfd,
- struct uv__epoll_event* events,
- int nevents,
- int timeout,
- uint64_t sigmask) {
-#if defined(__NR_epoll_pwait)
- int result;
- result = syscall(__NR_epoll_pwait,
- epfd,
- events,
- nevents,
- timeout,
- &sigmask,
- sizeof(sigmask));
-#if MSAN_ACTIVE
- if (result > 0)
- __msan_unpoison(events, sizeof(events[0]) * result);
-#endif
- return result;
-#else
- return errno = ENOSYS, -1;
-#endif
-}
-
-
int uv__inotify_init(void) {
#if defined(__NR_inotify_init)
return syscall(__NR_inotify_init);
@@ -431,19 +311,6 @@ int uv__recvmmsg(int fd,
}
-int uv__utimesat(int dirfd,
- const char* path,
- const struct timespec times[2],
- int flags)
-{
-#if defined(__NR_utimensat)
- return syscall(__NR_utimensat, dirfd, path, times, flags);
-#else
- return errno = ENOSYS, -1;
-#endif
-}
-
-
ssize_t uv__preadv(int fd, const struct iovec *iov, int iovcnt, int64_t offset) {
#if defined(__NR_preadv)
return syscall(__NR_preadv, fd, iov, iovcnt, (long)offset, (long)(offset >> 32));
diff --git a/Utilities/cmlibuv/src/unix/linux-syscalls.h b/Utilities/cmlibuv/src/unix/linux-syscalls.h
index 4c095e9b5..3dfd329d6 100644
--- a/Utilities/cmlibuv/src/unix/linux-syscalls.h
+++ b/Utilities/cmlibuv/src/unix/linux-syscalls.h
@@ -66,12 +66,6 @@
# define UV__SOCK_NONBLOCK UV__O_NONBLOCK
#endif
-/* epoll flags */
-#define UV__EPOLL_CLOEXEC UV__O_CLOEXEC
-#define UV__EPOLL_CTL_ADD 1
-#define UV__EPOLL_CTL_DEL 2
-#define UV__EPOLL_CTL_MOD 3
-
/* inotify flags */
#define UV__IN_ACCESS 0x001
#define UV__IN_MODIFY 0x002
@@ -86,18 +80,6 @@
#define UV__IN_DELETE_SELF 0x400
#define UV__IN_MOVE_SELF 0x800
-#if defined(__x86_64__)
-struct uv__epoll_event {
- uint32_t events;
- uint64_t data;
-} __attribute__((packed));
-#else
-struct uv__epoll_event {
- uint32_t events;
- uint64_t data;
-};
-#endif
-
struct uv__inotify_event {
int32_t wd;
uint32_t mask;
@@ -113,18 +95,6 @@ struct uv__mmsghdr {
int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags);
int uv__eventfd(unsigned int count);
-int uv__epoll_create(int size);
-int uv__epoll_create1(int flags);
-int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event *ev);
-int uv__epoll_wait(int epfd,
- struct uv__epoll_event* events,
- int nevents,
- int timeout);
-int uv__epoll_pwait(int epfd,
- struct uv__epoll_event* events,
- int nevents,
- int timeout,
- uint64_t sigmask);
int uv__eventfd2(unsigned int count, int flags);
int uv__inotify_init(void);
int uv__inotify_init1(int flags);
@@ -140,10 +110,6 @@ int uv__sendmmsg(int fd,
struct uv__mmsghdr* mmsg,
unsigned int vlen,
unsigned int flags);
-int uv__utimesat(int dirfd,
- const char* path,
- const struct timespec times[2],
- int flags);
ssize_t uv__preadv(int fd, const struct iovec *iov, int iovcnt, int64_t offset);
ssize_t uv__pwritev(int fd, const struct iovec *iov, int iovcnt, int64_t offset);
int uv__dup3(int oldfd, int newfd, int flags);
diff --git a/Utilities/cmlibuv/src/unix/loop-watcher.c b/Utilities/cmlibuv/src/unix/loop-watcher.c
index 340bb0dfa..b8c1c2a71 100644
--- a/Utilities/cmlibuv/src/unix/loop-watcher.c
+++ b/Utilities/cmlibuv/src/unix/loop-watcher.c
@@ -31,7 +31,7 @@
\
int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
if (uv__is_active(handle)) return 0; \
- if (cb == NULL) return -EINVAL; \
+ if (cb == NULL) return UV_EINVAL; \
QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \
handle->name##_cb = cb; \
uv__handle_start(handle); \
diff --git a/Utilities/cmlibuv/src/unix/loop.c b/Utilities/cmlibuv/src/unix/loop.c
index bcd49242c..c2a03d770 100644
--- a/Utilities/cmlibuv/src/unix/loop.c
+++ b/Utilities/cmlibuv/src/unix/loop.c
@@ -20,7 +20,7 @@
*/
#include "uv.h"
-#include "tree.h"
+#include "uv/tree.h"
#include "internal.h"
#include "heap-inl.h"
#include <stdlib.h>
@@ -31,7 +31,6 @@ int uv_loop_init(uv_loop_t* loop) {
void* saved_data;
int err;
- uv__signal_global_once_init();
saved_data = loop->data;
memset(loop, 0, sizeof(*loop));
@@ -39,13 +38,14 @@ int uv_loop_init(uv_loop_t* loop) {
heap_init((struct heap*) &loop->timer_heap);
QUEUE_INIT(&loop->wq);
- QUEUE_INIT(&loop->active_reqs);
QUEUE_INIT(&loop->idle_handles);
QUEUE_INIT(&loop->async_handles);
QUEUE_INIT(&loop->check_handles);
QUEUE_INIT(&loop->prepare_handles);
QUEUE_INIT(&loop->handle_queue);
+ loop->active_handles = 0;
+ loop->active_reqs.count = 0;
loop->nfds = 0;
loop->watchers = NULL;
loop->nwatchers = 0;
@@ -68,12 +68,13 @@ int uv_loop_init(uv_loop_t* loop) {
if (err)
return err;
+ uv__signal_global_once_init();
err = uv_signal_init(loop, &loop->child_watcher);
if (err)
goto fail_signal_init;
uv__handle_unref(&loop->child_watcher);
- loop->child_watcher.flags |= UV__HANDLE_INTERNAL;
+ loop->child_watcher.flags |= UV_HANDLE_INTERNAL;
QUEUE_INIT(&loop->process_handles);
err = uv_rwlock_init(&loop->cloexec_lock);
@@ -89,7 +90,7 @@ int uv_loop_init(uv_loop_t* loop) {
goto fail_async_init;
uv__handle_unref(&loop->wq_async);
- loop->wq_async.flags |= UV__HANDLE_INTERNAL;
+ loop->wq_async.flags |= UV_HANDLE_INTERNAL;
return 0;
diff --git a/Utilities/cmlibuv/src/unix/netbsd.c b/Utilities/cmlibuv/src/unix/netbsd.c
index 9b5546b7e..a2a4e5215 100644
--- a/Utilities/cmlibuv/src/unix/netbsd.c
+++ b/Utilities/cmlibuv/src/unix/netbsd.c
@@ -40,8 +40,6 @@
#include <unistd.h>
#include <time.h>
-static char *process_title;
-
int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop);
@@ -66,22 +64,33 @@ void uv_loadavg(double avg[3]) {
int uv_exepath(char* buffer, size_t* size) {
+ /* Intermediate buffer, retrieving partial path name does not work
+ * As of NetBSD-8(beta), vnode->path translator does not handle files
+ * with longer names than 31 characters.
+ */
+ char int_buf[PATH_MAX];
+ size_t int_size;
int mib[4];
- size_t cb;
- pid_t mypid;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
- mypid = getpid();
mib[0] = CTL_KERN;
mib[1] = KERN_PROC_ARGS;
- mib[2] = mypid;
- mib[3] = KERN_PROC_ARGV;
+ mib[2] = -1;
+ mib[3] = KERN_PROC_PATHNAME;
+ int_size = ARRAY_SIZE(int_buf);
+
+ if (sysctl(mib, 4, int_buf, &int_size, NULL, 0))
+ return UV__ERR(errno);
+
+ /* Copy string from the intermediate buffer to outer one with appropriate
+ * length.
+ */
+ /* TODO(bnoordhuis) Check uv__strscpy() return value. */
+ uv__strscpy(buffer, int_buf, *size);
- cb = *size;
- if (sysctl(mib, 4, buffer, &cb, NULL, 0))
- return -errno;
+ /* Set new size. */
*size = strlen(buffer);
return 0;
@@ -94,7 +103,7 @@ uint64_t uv_get_free_memory(void) {
int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
@@ -111,51 +120,12 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
return (uint64_t) info;
}
-char** uv_setup_args(int argc, char** argv) {
- process_title = argc ? uv__strdup(argv[0]) : NULL;
- return argv;
-}
-
-
-int uv_set_process_title(const char* title) {
- if (process_title) uv__free(process_title);
-
- process_title = uv__strdup(title);
- setproctitle("%s", title);
-
- return 0;
-}
-
-
-int uv_get_process_title(char* buffer, size_t size) {
- size_t len;
-
- if (buffer == NULL || size == 0)
- return -EINVAL;
-
- if (process_title) {
- len = strlen(process_title) + 1;
-
- if (size < len)
- return -ENOBUFS;
-
- memcpy(buffer, process_title, len);
- } else {
- len = 0;
- }
-
- buffer[len] = '\0';
-
- return 0;
-}
-
-
int uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL;
struct kinfo_proc2 *kinfo = NULL;
@@ -182,7 +152,7 @@ int uv_resident_set_memory(size_t* rss) {
error:
if (kd) kvm_close(kd);
- return -EPERM;
+ return UV_EPERM;
}
@@ -193,7 +163,7 @@ int uv_uptime(double* uptime) {
static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
now = time(NULL);
@@ -217,12 +187,12 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(model);
if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) &&
sysctlbyname("hw.model", &model, &size, NULL, 0)) {
- return -errno;
+ return UV__ERR(errno);
}
size = sizeof(numcpus);
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
*count = numcpus;
/* Only i386 and amd64 have machdep.tsc_freq */
@@ -233,16 +203,16 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = numcpus * CPUSTATES * sizeof(*cp_times);
cp_times = uv__malloc(size);
if (cp_times == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) {
uv__free(cp_times);
uv__free(*cpu_infos);
- return -ENOMEM;
+ return UV_ENOMEM;
}
for (i = 0; i < numcpus; i++) {
diff --git a/Utilities/cmlibuv/src/unix/no-fsevents.c b/Utilities/cmlibuv/src/unix/no-fsevents.c
index 38fb6ab0b..158643af1 100644
--- a/Utilities/cmlibuv/src/unix/no-fsevents.c
+++ b/Utilities/cmlibuv/src/unix/no-fsevents.c
@@ -25,16 +25,16 @@
#include <errno.h>
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb,
const char* filename, unsigned int flags) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
int uv_fs_event_stop(uv_fs_event_t* handle) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
void uv__fs_event_close(uv_fs_event_t* handle) {
diff --git a/Utilities/cmlibuv/src/unix/no-proctitle.c b/Utilities/cmlibuv/src/unix/no-proctitle.c
index a5c19fbff..165740ca3 100644
--- a/Utilities/cmlibuv/src/unix/no-proctitle.c
+++ b/Utilities/cmlibuv/src/unix/no-proctitle.c
@@ -35,7 +35,7 @@ int uv_set_process_title(const char* title) {
int uv_get_process_title(char* buffer, size_t size) {
if (buffer == NULL || size == 0)
- return -EINVAL;
+ return UV_EINVAL;
buffer[0] = '\0';
return 0;
diff --git a/Utilities/cmlibuv/src/unix/openbsd.c b/Utilities/cmlibuv/src/unix/openbsd.c
index 56f0af15c..bffb58bcd 100644
--- a/Utilities/cmlibuv/src/unix/openbsd.c
+++ b/Utilities/cmlibuv/src/unix/openbsd.c
@@ -36,9 +36,6 @@
#include <unistd.h>
-static char *process_title;
-
-
int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop);
}
@@ -71,11 +68,11 @@ int uv_exepath(char* buffer, size_t* size) {
int err;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
mypid = getpid();
for (;;) {
- err = -ENOMEM;
+ err = UV_ENOMEM;
argsbuf_tmp = uv__realloc(argsbuf, argsbuf_size);
if (argsbuf_tmp == NULL)
goto out;
@@ -88,14 +85,14 @@ int uv_exepath(char* buffer, size_t* size) {
break;
}
if (errno != ENOMEM) {
- err = -errno;
+ err = UV__ERR(errno);
goto out;
}
argsbuf_size *= 2U;
}
if (argsbuf[0] == NULL) {
- err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
+ err = UV_EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
goto out;
}
@@ -121,7 +118,7 @@ uint64_t uv_get_free_memory(void) {
int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
}
@@ -133,49 +130,12 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
return (uint64_t) info;
}
-char** uv_setup_args(int argc, char** argv) {
- process_title = argc ? uv__strdup(argv[0]) : NULL;
- return argv;
-}
-
-
-int uv_set_process_title(const char* title) {
- uv__free(process_title);
- process_title = uv__strdup(title);
- setproctitle("%s", title);
- return 0;
-}
-
-
-int uv_get_process_title(char* buffer, size_t size) {
- size_t len;
-
- if (buffer == NULL || size == 0)
- return -EINVAL;
-
- if (process_title) {
- len = strlen(process_title) + 1;
-
- if (size < len)
- return -ENOBUFS;
-
- memcpy(buffer, process_title, len);
- } else {
- len = 0;
- }
-
- buffer[len] = '\0';
-
- return 0;
-}
-
-
int uv_resident_set_memory(size_t* rss) {
struct kinfo_proc kinfo;
size_t page_size = getpagesize();
@@ -190,7 +150,7 @@ int uv_resident_set_memory(size_t* rss) {
mib[5] = 1;
if (sysctl(mib, 6, &kinfo, &size, NULL, 0) < 0)
- return -errno;
+ return UV__ERR(errno);
*rss = kinfo.p_vm_rssize * page_size;
return 0;
@@ -204,7 +164,7 @@ int uv_uptime(double* uptime) {
static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
now = time(NULL);
@@ -226,16 +186,16 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(model);
if (sysctl(which, 2, &model, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
which[1] = HW_NCPU;
size = sizeof(numcpus);
if (sysctl(which, 2, &numcpus, &size, NULL, 0))
- return -errno;
+ return UV__ERR(errno);
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos))
- return -ENOMEM;
+ return UV_ENOMEM;
*count = numcpus;
@@ -243,7 +203,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(cpuspeed);
if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) {
uv__free(*cpu_infos);
- return -errno;
+ return UV__ERR(errno);
}
size = sizeof(info);
@@ -254,7 +214,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(info);
if (sysctl(which, 3, &info, &size, NULL, 0)) {
uv__free(*cpu_infos);
- return -errno;
+ return UV__ERR(errno);
}
cpu_info = &(*cpu_infos)[i];
diff --git a/Utilities/cmlibuv/src/unix/os390-syscalls.c b/Utilities/cmlibuv/src/unix/os390-syscalls.c
index 7edf2358d..1040d6697 100644
--- a/Utilities/cmlibuv/src/unix/os390-syscalls.c
+++ b/Utilities/cmlibuv/src/unix/os390-syscalls.c
@@ -25,6 +25,8 @@
#include <stdlib.h>
#include <assert.h>
#include <search.h>
+#include <termios.h>
+#include <sys/msg.h>
#define CW_CONDVAR 32
@@ -103,10 +105,19 @@ static void maybe_resize(uv__os390_epoll* lst, unsigned int len) {
unsigned int newsize;
unsigned int i;
struct pollfd* newlst;
+ struct pollfd event;
if (len <= lst->size)
return;
+ if (lst->size == 0)
+ event.fd = -1;
+ else {
+ /* Extract the message queue at the end. */
+ event = lst->items[lst->size - 1];
+ lst->items[lst->size - 1].fd = -1;
+ }
+
newsize = next_power_of_two(len);
newlst = uv__realloc(lst->items, newsize * sizeof(lst->items[0]));
@@ -115,32 +126,102 @@ static void maybe_resize(uv__os390_epoll* lst, unsigned int len) {
for (i = lst->size; i < newsize; ++i)
newlst[i].fd = -1;
+ /* Restore the message queue at the end */
+ newlst[newsize - 1] = event;
+
lst->items = newlst;
lst->size = newsize;
}
+static void init_message_queue(uv__os390_epoll* lst) {
+ struct {
+ long int header;
+ char body;
+ } msg;
+
+ /* initialize message queue */
+ lst->msg_queue = msgget(IPC_PRIVATE, 0600 | IPC_CREAT);
+ if (lst->msg_queue == -1)
+ abort();
+
+ /*
+ On z/OS, the message queue will be affiliated with the process only
+ when a send is performed on it. Once this is done, the system
+ can be queried for all message queues belonging to our process id.
+ */
+ msg.header = 1;
+ if (msgsnd(lst->msg_queue, &msg, sizeof(msg.body), 0) != 0)
+ abort();
+
+ /* Clean up the dummy message sent above */
+ if (msgrcv(lst->msg_queue, &msg, sizeof(msg.body), 0, 0) != sizeof(msg.body))
+ abort();
+}
+
+
+static void before_fork(void) {
+ uv_mutex_lock(&global_epoll_lock);
+}
+
+
+static void after_fork(void) {
+ uv_mutex_unlock(&global_epoll_lock);
+}
+
+
+static void child_fork(void) {
+ QUEUE* q;
+ uv_once_t child_once = UV_ONCE_INIT;
+
+ /* reset once */
+ memcpy(&once, &child_once, sizeof(child_once));
+
+ /* reset epoll list */
+ while (!QUEUE_EMPTY(&global_epoll_queue)) {
+ uv__os390_epoll* lst;
+ q = QUEUE_HEAD(&global_epoll_queue);
+ QUEUE_REMOVE(q);
+ lst = QUEUE_DATA(q, uv__os390_epoll, member);
+ uv__free(lst->items);
+ lst->items = NULL;
+ lst->size = 0;
+ }
+
+ uv_mutex_unlock(&global_epoll_lock);
+ uv_mutex_destroy(&global_epoll_lock);
+}
+
+
static void epoll_init(void) {
QUEUE_INIT(&global_epoll_queue);
if (uv_mutex_init(&global_epoll_lock))
abort();
+
+ if (pthread_atfork(&before_fork, &after_fork, &child_fork))
+ abort();
}
uv__os390_epoll* epoll_create1(int flags) {
uv__os390_epoll* lst;
- uv_once(&once, epoll_init);
- uv_mutex_lock(&global_epoll_lock);
lst = uv__malloc(sizeof(*lst));
- if (lst == -1)
- return NULL;
- QUEUE_INSERT_TAIL(&global_epoll_queue, &lst->member);
- uv_mutex_unlock(&global_epoll_lock);
+ if (lst != NULL) {
+ /* initialize list */
+ lst->size = 0;
+ lst->items = NULL;
+ init_message_queue(lst);
+ maybe_resize(lst, 1);
+ lst->items[lst->size - 1].fd = lst->msg_queue;
+ lst->items[lst->size - 1].events = POLLIN;
+ lst->items[lst->size - 1].revents = 0;
+ uv_once(&once, epoll_init);
+ uv_mutex_lock(&global_epoll_lock);
+ QUEUE_INSERT_TAIL(&global_epoll_queue, &lst->member);
+ uv_mutex_unlock(&global_epoll_lock);
+ }
- /* initialize list */
- lst->size = 0;
- lst->items = NULL;
return lst;
}
@@ -149,71 +230,85 @@ int epoll_ctl(uv__os390_epoll* lst,
int op,
int fd,
struct epoll_event *event) {
- if(op == EPOLL_CTL_DEL) {
+ uv_mutex_lock(&global_epoll_lock);
+
+ if (op == EPOLL_CTL_DEL) {
if (fd >= lst->size || lst->items[fd].fd == -1) {
+ uv_mutex_unlock(&global_epoll_lock);
errno = ENOENT;
return -1;
}
lst->items[fd].fd = -1;
- } else if(op == EPOLL_CTL_ADD) {
- maybe_resize(lst, fd + 1);
+ } else if (op == EPOLL_CTL_ADD) {
+
+ /* Resizing to 'fd + 1' would expand the list to contain at least
+ * 'fd'. But we need to guarantee that the last index on the list
+ * is reserved for the message queue. So specify 'fd + 2' instead.
+ */
+ maybe_resize(lst, fd + 2);
if (lst->items[fd].fd != -1) {
+ uv_mutex_unlock(&global_epoll_lock);
errno = EEXIST;
return -1;
}
lst->items[fd].fd = fd;
lst->items[fd].events = event->events;
- } else if(op == EPOLL_CTL_MOD) {
- if (fd >= lst->size || lst->items[fd].fd == -1) {
+ lst->items[fd].revents = 0;
+ } else if (op == EPOLL_CTL_MOD) {
+ if (fd >= lst->size - 1 || lst->items[fd].fd == -1) {
+ uv_mutex_unlock(&global_epoll_lock);
errno = ENOENT;
return -1;
}
lst->items[fd].events = event->events;
+ lst->items[fd].revents = 0;
} else
abort();
+ uv_mutex_unlock(&global_epoll_lock);
return 0;
}
int epoll_wait(uv__os390_epoll* lst, struct epoll_event* events,
int maxevents, int timeout) {
- size_t size;
+ nmsgsfds_t size;
struct pollfd* pfds;
int pollret;
int reventcount;
+ int nevents;
- uv_mutex_lock(&global_epoll_lock);
- uv_mutex_unlock(&global_epoll_lock);
- size = lst->size;
+ _SET_FDS_MSGS(size, 1, lst->size - 1);
pfds = lst->items;
pollret = poll(pfds, size, timeout);
- if(pollret == -1)
+ if (pollret <= 0)
return pollret;
+ pollret = _NFDS(pollret) + _NMSGS(pollret);
+
reventcount = 0;
- for (int i = 0; i < lst->size && i < maxevents; ++i) {
+ nevents = 0;
+ for (int i = 0;
+ i < lst->size && i < maxevents && reventcount < pollret; ++i) {
struct epoll_event ev;
+ struct pollfd* pfd;
- ev.events = 0;
- ev.fd = pfds[i].fd;
- if(!pfds[i].revents)
+ pfd = &pfds[i];
+ if (pfd->fd == -1 || pfd->revents == 0)
continue;
- if(pfds[i].revents & POLLRDNORM)
- ev.events = ev.events | POLLIN;
-
- if(pfds[i].revents & POLLWRNORM)
- ev.events = ev.events | POLLOUT;
+ ev.fd = pfd->fd;
+ ev.events = pfd->revents;
+ if (pfd->revents & POLLIN && pfd->revents & POLLOUT)
+ reventcount += 2;
+ else if (pfd->revents & (POLLIN | POLLOUT))
+ ++reventcount;
- if(pfds[i].revents & POLLHUP)
- ev.events = ev.events | POLLHUP;
-
- pfds[i].revents = 0;
- events[reventcount++] = ev;
+ pfd->revents = 0;
+ events[nevents++] = ev;
}
- return reventcount;
+ return nevents;
}
@@ -235,9 +330,14 @@ int epoll_file_close(int fd) {
}
void epoll_queue_close(uv__os390_epoll* lst) {
+ /* Remove epoll instance from global queue */
uv_mutex_lock(&global_epoll_lock);
QUEUE_REMOVE(&lst->member);
uv_mutex_unlock(&global_epoll_lock);
+
+ /* Free resources */
+ msgctl(lst->msg_queue, IPC_RMID, NULL);
+ lst->msg_queue = -1;
uv__free(lst->items);
lst->items = NULL;
}
@@ -332,3 +432,81 @@ char* mkdtemp(char* path) {
return path;
}
+
+
+ssize_t os390_readlink(const char* path, char* buf, size_t len) {
+ ssize_t rlen;
+ ssize_t vlen;
+ ssize_t plen;
+ char* delimiter;
+ char old_delim;
+ char* tmpbuf;
+ char realpathstr[PATH_MAX + 1];
+
+ tmpbuf = uv__malloc(len + 1);
+ if (tmpbuf == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ rlen = readlink(path, tmpbuf, len);
+ if (rlen < 0) {
+ uv__free(tmpbuf);
+ return rlen;
+ }
+
+ if (rlen < 3 || strncmp("/$", tmpbuf, 2) != 0) {
+ /* Straightforward readlink. */
+ memcpy(buf, tmpbuf, rlen);
+ uv__free(tmpbuf);
+ return rlen;
+ }
+
+ /*
+ * There is a parmlib variable at the beginning
+ * which needs interpretation.
+ */
+ tmpbuf[rlen] = '\0';
+ delimiter = strchr(tmpbuf + 2, '/');
+ if (delimiter == NULL)
+ /* No slash at the end */
+ delimiter = strchr(tmpbuf + 2, '\0');
+
+ /* Read real path of the variable. */
+ old_delim = *delimiter;
+ *delimiter = '\0';
+ if (realpath(tmpbuf, realpathstr) == NULL) {
+ uv__free(tmpbuf);
+ return -1;
+ }
+
+ /* realpathstr is not guaranteed to end with null byte.*/
+ realpathstr[PATH_MAX] = '\0';
+
+ /* Reset the delimiter and fill up the buffer. */
+ *delimiter = old_delim;
+ plen = strlen(delimiter);
+ vlen = strlen(realpathstr);
+ rlen = plen + vlen;
+ if (rlen > len) {
+ uv__free(tmpbuf);
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ memcpy(buf, realpathstr, vlen);
+ memcpy(buf + vlen, delimiter, plen);
+
+ /* Done using temporary buffer. */
+ uv__free(tmpbuf);
+
+ return rlen;
+}
+
+
+size_t strnlen(const char* str, size_t maxlen) {
+ char* p = memchr(str, 0, maxlen);
+ if (p == NULL)
+ return maxlen;
+ else
+ return p - str;
+}
diff --git a/Utilities/cmlibuv/src/unix/os390-syscalls.h b/Utilities/cmlibuv/src/unix/os390-syscalls.h
index 61a7cee83..ea599107b 100644
--- a/Utilities/cmlibuv/src/unix/os390-syscalls.h
+++ b/Utilities/cmlibuv/src/unix/os390-syscalls.h
@@ -36,10 +36,6 @@
#define MAX_ITEMS_PER_EPOLL 1024
#define UV__O_CLOEXEC 0x80000
-#define UV__EPOLL_CLOEXEC UV__O_CLOEXEC
-#define UV__EPOLL_CTL_ADD EPOLL_CTL_ADD
-#define UV__EPOLL_CTL_DEL EPOLL_CTL_DEL
-#define UV__EPOLL_CTL_MOD EPOLL_CTL_MOD
struct epoll_event {
int events;
@@ -50,6 +46,7 @@ typedef struct {
QUEUE member;
struct pollfd* items;
unsigned long size;
+ int msg_queue;
} uv__os390_epoll;
/* epoll api */
@@ -65,5 +62,7 @@ int scandir(const char* maindir, struct dirent*** namelist,
int (*compar)(const struct dirent **,
const struct dirent **));
char *mkdtemp(char* path);
+ssize_t os390_readlink(const char* path, char* buf, size_t len);
+size_t strnlen(const char* str, size_t maxlen);
#endif /* UV_OS390_SYSCALL_H_ */
diff --git a/Utilities/cmlibuv/src/unix/os390.c b/Utilities/cmlibuv/src/unix/os390.c
index 2ba5abf35..dc146e311 100644
--- a/Utilities/cmlibuv/src/unix/os390.c
+++ b/Utilities/cmlibuv/src/unix/os390.c
@@ -25,6 +25,9 @@
#include <utmpx.h>
#include <unistd.h>
#include <sys/ps.h>
+#include <builtins.h>
+#include <termios.h>
+#include <sys/msg.h>
#if defined(__clang__)
#include "csrsic.h"
#else
@@ -32,6 +35,7 @@
#endif
#define CVT_PTR 0x10
+#define PSA_PTR 0x00
#define CSD_OFFSET 0x294
/*
@@ -69,6 +73,18 @@
/* CPC model length from the CSRSI Service. */
#define CPCMODEL_LENGTH 16
+/* Pointer to the home (current) ASCB. */
+#define PSAAOLD 0x224
+
+/* Pointer to rsm address space block extension. */
+#define ASCBRSME 0x16C
+
+/*
+ NUMBER OF FRAMES CURRENTLY IN USE BY THIS ADDRESS SPACE.
+ It does not include 2G frames.
+*/
+#define RAXFMCT 0x2C
+
/* Thread Entry constants */
#define PGTH_CURRENT 1
#define PGTH_LEN 26
@@ -76,6 +92,9 @@
#pragma linkage(BPX4GTH, OS)
#pragma linkage(BPX1GTH, OS)
+/* TOD Clock resolution in nanoseconds */
+#define TOD_RES 4.096
+
typedef unsigned data_area_ptr_assign_type;
typedef union {
@@ -100,10 +119,10 @@ void uv_loadavg(double avg[3]) {
int uv__platform_loop_init(uv_loop_t* loop) {
uv__os390_epoll* ep;
- ep = epoll_create1(UV__EPOLL_CLOEXEC);
+ ep = epoll_create1(0);
loop->ep = ep;
if (ep == NULL)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -118,9 +137,10 @@ void uv__platform_loop_delete(uv_loop_t* loop) {
uint64_t uv__hrtime(uv_clocktype_t type) {
- struct timeval time;
- gettimeofday(&time, NULL);
- return (uint64_t) time.tv_sec * 1e9 + time.tv_usec * 1e3;
+ unsigned long long timestamp;
+ __stckf(&timestamp);
+ /* Convert to nanoseconds */
+ return timestamp / TOD_RES;
}
@@ -209,15 +229,15 @@ static int getexe(const int pid, char* buf, size_t len) {
assert(((Output_buf.Output_data.offsetPath >>24) & 0xFF) == 'A');
/* Get the offset from the lowest 3 bytes */
- Output_path = (char*)(&Output_buf) +
- (Output_buf.Output_data.offsetPath & 0x00FFFFFF);
+ Output_path = (struct Output_path_type*) ((char*) (&Output_buf) +
+ (Output_buf.Output_data.offsetPath & 0x00FFFFFF));
if (Output_path->len >= len) {
errno = ENOBUFS;
return -1;
}
- strncpy(buf, Output_path->path, len);
+ uv__strscpy(buf, Output_path->path, len);
return 0;
}
@@ -239,12 +259,12 @@ int uv_exepath(char* buffer, size_t* size) {
int pid;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
pid = getpid();
res = getexe(pid, args, sizeof(args));
if (res < 0)
- return -EINVAL;
+ return UV_EINVAL;
/*
* Possibilities for args:
@@ -257,7 +277,7 @@ int uv_exepath(char* buffer, size_t* size) {
/* Case i) and ii) absolute or relative paths */
if (strchr(args, '/') != NULL) {
if (realpath(args, abspath) != abspath)
- return -errno;
+ return UV__ERR(errno);
abspath_size = strlen(abspath);
@@ -277,11 +297,11 @@ int uv_exepath(char* buffer, size_t* size) {
char* path = getenv("PATH");
if (path == NULL)
- return -EINVAL;
+ return UV_EINVAL;
clonedpath = uv__strdup(path);
if (clonedpath == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
token = strtok(clonedpath, ":");
while (token != NULL) {
@@ -307,7 +327,7 @@ int uv_exepath(char* buffer, size_t* size) {
uv__free(clonedpath);
/* Out of tokens (path entries), and no match found */
- return -EINVAL;
+ return UV_EINVAL;
}
}
@@ -337,13 +357,15 @@ uint64_t uv_get_total_memory(void) {
int uv_resident_set_memory(size_t* rss) {
- W_PSPROC buf;
+ char* ascb;
+ char* rax;
+ size_t nframes;
- memset(&buf, 0, sizeof(buf));
- if (w_getpsent(0, &buf, sizeof(W_PSPROC)) == -1)
- return -EINVAL;
+ ascb = *(char* __ptr32 *)(PSA_PTR + PSAAOLD);
+ rax = *(char* __ptr32 *)(ascb + ASCBRSME);
+ nframes = *(unsigned int*)(rax + RAXFMCT);
- *rss = buf.ps_size;
+ *rss = nframes * sysconf(_SC_PAGESIZE);
return 0;
}
@@ -364,7 +386,6 @@ int uv_uptime(double* uptime) {
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv_cpu_info_t* cpu_info;
- int result;
int idx;
siv1v2 info;
data_area_ptr cvt = {0};
@@ -384,7 +405,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
*cpu_infos = uv__malloc(*count * sizeof(uv_cpu_info_t));
if (!*cpu_infos)
- return -ENOMEM;
+ return UV_ENOMEM;
cpu_info = *cpu_infos;
idx = 0;
@@ -429,7 +450,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
maxsize = 16384;
if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)))
- return -errno;
+ return UV__ERR(errno);
ifc.__nif6h_version = 1;
ifc.__nif6h_buflen = maxsize;
@@ -437,7 +458,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
if (ioctl(sockfd, SIOCGIFCONF6, &ifc) == -1) {
uv__close(sockfd);
- return -errno;
+ return UV__ERR(errno);
}
@@ -461,7 +482,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
*addresses = uv__malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
uv__close(sockfd);
- return -ENOMEM;
+ return UV_ENOMEM;
}
address = *addresses;
@@ -489,7 +510,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
/* TODO: Retrieve netmask using SIOCGIFNETMASK ioctl */
address->is_internal = flg.__nif6e_flags & _NIF6E_FLAGS_LOOPBACK ? 1 : 0;
-
+ memset(address->phys_addr, 0, sizeof(address->phys_addr));
address++;
}
@@ -508,25 +529,27 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifreq* p;
int count_v6;
+ *count = 0;
+ *addresses = NULL;
+
/* get the ipv6 addresses first */
uv_interface_address_t* addresses_v6;
uv__interface_addresses_v6(&addresses_v6, &count_v6);
/* now get the ipv4 addresses */
- *count = 0;
/* Assume maximum buffer size allowable */
maxsize = 16384;
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (0 > sockfd)
- return -errno;
+ return UV__ERR(errno);
ifc.ifc_req = uv__calloc(1, maxsize);
ifc.ifc_len = maxsize;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
uv__close(sockfd);
- return -errno;
+ return UV__ERR(errno);
}
#define MAX(a,b) (((a)>(b))?(a):(b))
@@ -546,7 +569,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
uv__close(sockfd);
- return -errno;
+ return UV__ERR(errno);
}
if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
@@ -555,13 +578,18 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
+ if (*count == 0) {
+ uv__close(sockfd);
+ return 0;
+ }
+
/* Alloc the return interface structs */
*addresses = uv__malloc((*count + count_v6) *
sizeof(uv_interface_address_t));
if (!(*addresses)) {
uv__close(sockfd);
- return -ENOMEM;
+ return UV_ENOMEM;
}
address = *addresses;
@@ -584,7 +612,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
uv__close(sockfd);
- return -ENOSYS;
+ return UV_ENOSYS;
}
if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
@@ -601,6 +629,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
}
address->is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0;
+ memset(address->phys_addr, 0, sizeof(address->phys_addr));
address++;
}
@@ -639,7 +668,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
/* Remove the file descriptor from the epoll. */
if (loop->ep != NULL)
- epoll_ctl(loop->ep, UV__EPOLL_CTL_DEL, fd, &dummy);
+ epoll_ctl(loop->ep, EPOLL_CTL_DEL, fd, &dummy);
}
@@ -663,11 +692,124 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
return 0;
}
+
+void uv__fs_event_close(uv_fs_event_t* handle) {
+ uv_fs_event_stop(handle);
+}
+
+
+int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
+ uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
+ return 0;
+}
+
+
+int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb,
+ const char* filename, unsigned int flags) {
+ uv__os390_epoll* ep;
+ _RFIS reg_struct;
+ char* path;
+ int rc;
+
+ if (uv__is_active(handle))
+ return UV_EINVAL;
+
+ ep = handle->loop->ep;
+ assert(ep->msg_queue != -1);
+
+ reg_struct.__rfis_cmd = _RFIS_REG;
+ reg_struct.__rfis_qid = ep->msg_queue;
+ reg_struct.__rfis_type = 1;
+ memcpy(reg_struct.__rfis_utok, &handle, sizeof(handle));
+
+ path = uv__strdup(filename);
+ if (path == NULL)
+ return UV_ENOMEM;
+
+ rc = __w_pioctl(path, _IOCC_REGFILEINT, sizeof(reg_struct), &reg_struct);
+ if (rc != 0)
+ return UV__ERR(errno);
+
+ uv__handle_start(handle);
+ handle->path = path;
+ handle->cb = cb;
+ memcpy(handle->rfis_rftok, reg_struct.__rfis_rftok,
+ sizeof(handle->rfis_rftok));
+
+ return 0;
+}
+
+
+int uv_fs_event_stop(uv_fs_event_t* handle) {
+ uv__os390_epoll* ep;
+ _RFIS reg_struct;
+ int rc;
+
+ if (!uv__is_active(handle))
+ return 0;
+
+ ep = handle->loop->ep;
+ assert(ep->msg_queue != -1);
+
+ reg_struct.__rfis_cmd = _RFIS_UNREG;
+ reg_struct.__rfis_qid = ep->msg_queue;
+ reg_struct.__rfis_type = 1;
+ memcpy(reg_struct.__rfis_rftok, handle->rfis_rftok,
+ sizeof(handle->rfis_rftok));
+
+ /*
+ * This call will take "/" as the path argument in case we
+ * don't care to supply the correct path. The system will simply
+ * ignore it.
+ */
+ rc = __w_pioctl("/", _IOCC_REGFILEINT, sizeof(reg_struct), &reg_struct);
+ if (rc != 0 && errno != EALREADY && errno != ENOENT)
+ abort();
+
+ uv__handle_stop(handle);
+
+ return 0;
+}
+
+
+static int os390_message_queue_handler(uv__os390_epoll* ep) {
+ uv_fs_event_t* handle;
+ int msglen;
+ int events;
+ _RFIM msg;
+
+ if (ep->msg_queue == -1)
+ return 0;
+
+ msglen = msgrcv(ep->msg_queue, &msg, sizeof(msg), 0, IPC_NOWAIT);
+
+ if (msglen == -1 && errno == ENOMSG)
+ return 0;
+
+ if (msglen == -1)
+ abort();
+
+ events = 0;
+ if (msg.__rfim_event == _RFIM_ATTR || msg.__rfim_event == _RFIM_WRITE)
+ events = UV_CHANGE;
+ else if (msg.__rfim_event == _RFIM_RENAME)
+ events = UV_RENAME;
+ else
+ /* Some event that we are not interested in. */
+ return 0;
+
+ handle = *(uv_fs_event_t**)(msg.__rfim_utok);
+ handle->cb(handle, uv__basename_r(handle->path), events, 0);
+ return 1;
+}
+
+
void uv__io_poll(uv_loop_t* loop, int timeout) {
static const int max_safe_timeout = 1789569;
struct epoll_event events[1024];
struct epoll_event* pe;
struct epoll_event e;
+ uv__os390_epoll* ep;
int real_timeout;
QUEUE* q;
uv__io_t* w;
@@ -702,9 +844,9 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
e.fd = w->fd;
if (w->events == 0)
- op = UV__EPOLL_CTL_ADD;
+ op = EPOLL_CTL_ADD;
else
- op = UV__EPOLL_CTL_MOD;
+ op = EPOLL_CTL_MOD;
/* XXX Future optimization: do EPOLL_CTL_MOD lazily if we stop watching
* events, skip the syscall and squelch the events after epoll_wait().
@@ -713,10 +855,10 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (errno != EEXIST)
abort();
- assert(op == UV__EPOLL_CTL_ADD);
+ assert(op == EPOLL_CTL_ADD);
/* We've reactivated a file descriptor that's been watched before. */
- if (epoll_ctl(loop->ep, UV__EPOLL_CTL_MOD, w->fd, &e))
+ if (epoll_ctl(loop->ep, EPOLL_CTL_MOD, w->fd, &e))
abort();
}
@@ -745,9 +887,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
SAVE_ERRNO(uv__update_time(loop));
if (nfds == 0) {
assert(timeout != -1);
- timeout = real_timeout - timeout;
- if (timeout > 0)
+
+ if (timeout > 0) {
+ timeout = real_timeout - timeout;
continue;
+ }
return;
}
@@ -779,6 +923,12 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (fd == -1)
continue;
+ ep = loop->ep;
+ if (fd == ep->msg_queue) {
+ os390_message_queue_handler(ep);
+ continue;
+ }
+
assert(fd >= 0);
assert((unsigned) fd < loop->nwatchers);
@@ -790,7 +940,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
* Ignore all errors because we may be racing with another thread
* when the file descriptor is closed.
*/
- epoll_ctl(loop->ep, UV__EPOLL_CTL_DEL, fd, pe);
+ epoll_ctl(loop->ep, EPOLL_CTL_DEL, fd, pe);
continue;
}
@@ -843,7 +993,12 @@ void uv__set_process_title(const char* title) {
}
int uv__io_fork(uv_loop_t* loop) {
- uv__platform_loop_delete(loop);
+ /*
+ Nullify the msg queue but don't close it because
+ it is still being used by the parent.
+ */
+ loop->ep = NULL;
+ uv__platform_loop_delete(loop);
return uv__platform_loop_init(loop);
}
diff --git a/Utilities/cmlibuv/src/unix/pipe.c b/Utilities/cmlibuv/src/unix/pipe.c
index 7ba1bf879..9657bc914 100644
--- a/Utilities/cmlibuv/src/unix/pipe.c
+++ b/Utilities/cmlibuv/src/unix/pipe.c
@@ -48,12 +48,12 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
/* Already bound? */
if (uv__stream_fd(handle) >= 0)
- return -EINVAL;
+ return UV_EINVAL;
/* Make a copy of the file name, it outlives this function's scope. */
pipe_fname = uv__strdup(name);
if (pipe_fname == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
/* We've got a copy, don't touch the original any more. */
name = NULL;
@@ -64,15 +64,14 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
sockfd = err;
memset(&saddr, 0, sizeof saddr);
- strncpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path) - 1);
- saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
+ uv__strscpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
- err = -errno;
+ err = UV__ERR(errno);
/* Convert ENOENT to EACCES for compatibility with Windows. */
- if (err == -ENOENT)
- err = -EACCES;
+ if (err == UV_ENOENT)
+ err = UV_EACCES;
uv__close(sockfd);
goto err_socket;
@@ -92,7 +91,7 @@ err_socket:
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
if (uv__stream_fd(handle) == -1)
- return -EINVAL;
+ return UV_EINVAL;
#if defined(__MVS__)
/* On zOS, backlog=0 has undefined behaviour */
@@ -103,7 +102,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
#endif
if (listen(uv__stream_fd(handle), backlog))
- return -errno;
+ return UV__ERR(errno);
handle->connection_cb = cb;
handle->io_watcher.cb = uv__server_io;
@@ -130,21 +129,38 @@ void uv__pipe_close(uv_pipe_t* handle) {
int uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
+ int flags;
+ int mode;
int err;
+ flags = 0;
+
+ if (uv__fd_exists(handle->loop, fd))
+ return UV_EEXIST;
+
+ do
+ mode = fcntl(fd, F_GETFL);
+ while (mode == -1 && errno == EINTR);
+
+ if (mode == -1)
+ return UV__ERR(errno); /* according to docs, must be EBADF */
err = uv__nonblock(fd, 1);
if (err)
return err;
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
err = uv__stream_try_select((uv_stream_t*) handle, &fd);
if (err)
return err;
#endif /* defined(__APPLE__) */
- return uv__stream_open((uv_stream_t*)handle,
- fd,
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ mode &= O_ACCMODE;
+ if (mode != O_WRONLY)
+ flags |= UV_HANDLE_READABLE;
+ if (mode != O_RDONLY)
+ flags |= UV_HANDLE_WRITABLE;
+
+ return uv__stream_open((uv_stream_t*)handle, fd, flags);
}
@@ -167,8 +183,7 @@ void uv_pipe_connect(uv_connect_t* req,
}
memset(&saddr, 0, sizeof saddr);
- strncpy(saddr.sun_path, name, sizeof(saddr.sun_path) - 1);
- saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
+ uv__strscpy(saddr.sun_path, name, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
do {
@@ -178,14 +193,14 @@ void uv_pipe_connect(uv_connect_t* req,
while (r == -1 && errno == EINTR);
if (r == -1 && errno != EINPROGRESS) {
- err = -errno;
+ err = UV__ERR(errno);
#if defined(__CYGWIN__) || defined(__MSYS__)
/* EBADF is supposed to mean that the socket fd is bad, but
Cygwin reports EBADF instead of ENOTSOCK when the file is
not a socket. We do not expect to see a bad fd here
(e.g. due to new_sock), so translate the error. */
- if (err == -EBADF)
- err = -ENOTSOCK;
+ if (err == UV_EBADF)
+ err = UV_ENOTSOCK;
#endif
goto out;
}
@@ -194,7 +209,7 @@ void uv_pipe_connect(uv_connect_t* req,
if (new_sock) {
err = uv__stream_open((uv_stream_t*)handle,
uv__stream_fd(handle),
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
}
if (err == 0)
@@ -232,7 +247,7 @@ static int uv__pipe_getsockpeername(const uv_pipe_t* handle,
err = func(uv__stream_fd(handle), (struct sockaddr*) &sa, &addrlen);
if (err < 0) {
*size = 0;
- return -errno;
+ return UV__ERR(errno);
}
#if defined(__linux__)
@@ -300,3 +315,61 @@ uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle) {
else
return uv__handle_type(handle->accepted_fd);
}
+
+
+int uv_pipe_chmod(uv_pipe_t* handle, int mode) {
+ unsigned desired_mode;
+ struct stat pipe_stat;
+ char* name_buffer;
+ size_t name_len;
+ int r;
+
+ if (handle == NULL || uv__stream_fd(handle) == -1)
+ return UV_EBADF;
+
+ if (mode != UV_READABLE &&
+ mode != UV_WRITABLE &&
+ mode != (UV_WRITABLE | UV_READABLE))
+ return UV_EINVAL;
+
+ /* Unfortunately fchmod does not work on all platforms, we will use chmod. */
+ name_len = 0;
+ r = uv_pipe_getsockname(handle, NULL, &name_len);
+ if (r != UV_ENOBUFS)
+ return r;
+
+ name_buffer = uv__malloc(name_len);
+ if (name_buffer == NULL)
+ return UV_ENOMEM;
+
+ r = uv_pipe_getsockname(handle, name_buffer, &name_len);
+ if (r != 0) {
+ uv__free(name_buffer);
+ return r;
+ }
+
+ /* stat must be used as fstat has a bug on Darwin */
+ if (stat(name_buffer, &pipe_stat) == -1) {
+ uv__free(name_buffer);
+ return -errno;
+ }
+
+ desired_mode = 0;
+ if (mode & UV_READABLE)
+ desired_mode |= S_IRUSR | S_IRGRP | S_IROTH;
+ if (mode & UV_WRITABLE)
+ desired_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+
+ /* Exit early if pipe already has desired mode. */
+ if ((pipe_stat.st_mode & desired_mode) == desired_mode) {
+ uv__free(name_buffer);
+ return 0;
+ }
+
+ pipe_stat.st_mode |= desired_mode;
+
+ r = chmod(name_buffer, pipe_stat.st_mode);
+ uv__free(name_buffer);
+
+ return r != -1 ? 0 : UV__ERR(errno);
+}
diff --git a/Utilities/cmlibuv/src/unix/poll.c b/Utilities/cmlibuv/src/unix/poll.c
index 370994bd5..3d5022b22 100644
--- a/Utilities/cmlibuv/src/unix/poll.c
+++ b/Utilities/cmlibuv/src/unix/poll.c
@@ -33,16 +33,29 @@ static void uv__poll_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
handle = container_of(w, uv_poll_t, io_watcher);
- if (events & POLLERR) {
- uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP);
+ /*
+ * As documented in the kernel source fs/kernfs/file.c #780
+ * poll will return POLLERR|POLLPRI in case of sysfs
+ * polling. This does not happen in case of out-of-band
+ * TCP messages.
+ *
+ * The above is the case on (at least) FreeBSD and Linux.
+ *
+ * So to properly determine a POLLPRI or a POLLERR we need
+ * to check for both.
+ */
+ if ((events & POLLERR) && !(events & UV__POLLPRI)) {
+ uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
uv__handle_stop(handle);
- handle->poll_cb(handle, -EBADF, 0);
+ handle->poll_cb(handle, UV_EBADF, 0);
return;
}
pevents = 0;
if (events & POLLIN)
pevents |= UV_READABLE;
+ if (events & UV__POLLPRI)
+ pevents |= UV_PRIORITIZED;
if (events & POLLOUT)
pevents |= UV_WRITABLE;
if (events & UV__POLLRDHUP)
@@ -55,6 +68,9 @@ static void uv__poll_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) {
int err;
+ if (uv__fd_exists(loop, fd))
+ return UV_EEXIST;
+
err = uv__io_check_fd(loop, fd);
if (err)
return err;
@@ -63,7 +79,7 @@ int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) {
* Workaround for e.g. kqueue fds not supporting ioctls.
*/
err = uv__nonblock(fd, 1);
- if (err == -ENOTTY)
+ if (err == UV_ENOTTY)
if (uv__nonblock == uv__nonblock_ioctl)
err = uv__nonblock_fcntl(fd, 1);
@@ -86,8 +102,9 @@ int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
static void uv__poll_stop(uv_poll_t* handle) {
uv__io_stop(handle->loop,
&handle->io_watcher,
- POLLIN | POLLOUT | UV__POLLRDHUP);
+ POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
uv__handle_stop(handle);
+ uv__platform_invalidate_fd(handle->loop, handle->io_watcher.fd);
}
@@ -101,7 +118,8 @@ int uv_poll_stop(uv_poll_t* handle) {
int uv_poll_start(uv_poll_t* handle, int pevents, uv_poll_cb poll_cb) {
int events;
- assert((pevents & ~(UV_READABLE | UV_WRITABLE | UV_DISCONNECT)) == 0);
+ assert((pevents & ~(UV_READABLE | UV_WRITABLE | UV_DISCONNECT |
+ UV_PRIORITIZED)) == 0);
assert(!uv__is_closing(handle));
uv__poll_stop(handle);
@@ -112,6 +130,8 @@ int uv_poll_start(uv_poll_t* handle, int pevents, uv_poll_cb poll_cb) {
events = 0;
if (pevents & UV_READABLE)
events |= POLLIN;
+ if (pevents & UV_PRIORITIZED)
+ events |= UV__POLLPRI;
if (pevents & UV_WRITABLE)
events |= POLLOUT;
if (pevents & UV_DISCONNECT)
diff --git a/Utilities/cmlibuv/src/unix/posix-hrtime.c b/Utilities/cmlibuv/src/unix/posix-hrtime.c
index 323dfc203..a2642500e 100644
--- a/Utilities/cmlibuv/src/unix/posix-hrtime.c
+++ b/Utilities/cmlibuv/src/unix/posix-hrtime.c
@@ -22,6 +22,29 @@
#include "uv.h"
#include "internal.h"
+#if defined(__APPLE__)
+/* Special case for CMake bootstrap: no clock_gettime on macOS < 10.12 */
+
+#ifndef CMAKE_BOOTSTRAP
+#error "This code path meant only for use during CMake bootstrap."
+#endif
+
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+
+uint64_t uv__hrtime(uv_clocktype_t type) {
+ static mach_timebase_info_data_t info;
+
+ if ((ACCESS_ONCE(uint32_t, info.numer) == 0 ||
+ ACCESS_ONCE(uint32_t, info.denom) == 0) &&
+ mach_timebase_info(&info) != KERN_SUCCESS)
+ abort();
+
+ return mach_absolute_time() * info.numer / info.denom;
+}
+
+#else
+
#include <stdint.h>
#include <time.h>
@@ -33,3 +56,5 @@ uint64_t uv__hrtime(uv_clocktype_t type) {
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
}
+
+#endif
diff --git a/Utilities/cmlibuv/src/unix/posix-poll.c b/Utilities/cmlibuv/src/unix/posix-poll.c
index 3fba96e1b..f3181f9b7 100644
--- a/Utilities/cmlibuv/src/unix/posix-poll.c
+++ b/Utilities/cmlibuv/src/unix/posix-poll.c
@@ -107,7 +107,7 @@ static void uv__pollfds_add(uv_loop_t* loop, uv__io_t* w) {
static void uv__pollfds_del(uv_loop_t* loop, int fd) {
size_t i;
assert(!loop->poll_fds_iterating);
- for (i = 0; i < loop->poll_fds_used; ++i) {
+ for (i = 0; i < loop->poll_fds_used;) {
if (loop->poll_fds[i].fd == fd) {
/* swap to last position and remove */
--loop->poll_fds_used;
@@ -115,7 +115,17 @@ static void uv__pollfds_del(uv_loop_t* loop, int fd) {
loop->poll_fds[loop->poll_fds_used].fd = -1;
loop->poll_fds[loop->poll_fds_used].events = 0;
loop->poll_fds[loop->poll_fds_used].revents = 0;
- return;
+ /* This method is called with an fd of -1 to purge the invalidated fds,
+ * so we may possibly have multiples to remove.
+ */
+ if (-1 != fd)
+ return;
+ } else {
+ /* We must only increment the loop counter when the fds do not match.
+ * Otherwise, when we are purging an invalidated fd, the value just
+ * swapped here from the previous end of the array will be skipped.
+ */
+ ++i;
}
}
}
@@ -315,10 +325,10 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
while (rv == -1 && (errno == EINTR || errno == EAGAIN));
if (rv == -1)
- return -errno;
+ return UV__ERR(errno);
if (p[0].revents & POLLNVAL)
- return -EINVAL;
+ return UV_EINVAL;
return 0;
}
diff --git a/Utilities/cmlibuv/src/unix/process.c b/Utilities/cmlibuv/src/unix/process.c
index f2fe30521..e9579f5ed 100644
--- a/Utilities/cmlibuv/src/unix/process.c
+++ b/Utilities/cmlibuv/src/unix/process.c
@@ -32,6 +32,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
+#include <sched.h>
#if defined(__APPLE__) && !TARGET_OS_IPHONE
# include <crt_externs.h>
@@ -44,6 +45,16 @@ extern char **environ;
# include <grp.h>
#endif
+#ifndef CMAKE_BOOTSTRAP
+#if defined(__linux__)
+# define uv__cpu_set_t cpu_set_t
+#elif defined(__FreeBSD__)
+# include <sys/param.h>
+# include <sys/cpuset.h>
+# include <pthread_np.h>
+# define uv__cpu_set_t cpuset_t
+#endif
+#endif
static void uv__chld(uv_signal_t* handle, int signum) {
uv_process_t* process;
@@ -126,7 +137,7 @@ int uv__make_socketpair(int fds[2], int flags) {
* Anything else is a genuine error.
*/
if (errno != EINVAL)
- return -errno;
+ return UV__ERR(errno);
no_cloexec = 1;
@@ -134,7 +145,7 @@ skip:
#endif
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
- return -errno;
+ return UV__ERR(errno);
uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1);
@@ -159,7 +170,7 @@ int uv__make_pipe(int fds[2], int flags) {
return 0;
if (errno != ENOSYS)
- return -errno;
+ return UV__ERR(errno);
no_pipe2 = 1;
@@ -167,7 +178,7 @@ skip:
#endif
if (pipe(fds))
- return -errno;
+ return UV__ERR(errno);
uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1);
@@ -198,7 +209,7 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
case UV_CREATE_PIPE:
assert(container->data.stream != NULL);
if (container->data.stream->type != UV_NAMED_PIPE)
- return -EINVAL;
+ return UV_EINVAL;
else
return uv__make_socketpair(fds, 0);
@@ -210,21 +221,20 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
fd = uv__stream_fd(container->data.stream);
if (fd == -1)
- return -EINVAL;
+ return UV_EINVAL;
fds[1] = fd;
return 0;
default:
assert(0 && "Unexpected flags");
- return -EINVAL;
+ return UV_EINVAL;
}
}
static int uv__process_open_stream(uv_stdio_container_t* container,
- int pipefds[2],
- int writable) {
+ int pipefds[2]) {
int flags;
int err;
@@ -238,13 +248,11 @@ static int uv__process_open_stream(uv_stdio_container_t* container,
pipefds[1] = -1;
uv__nonblock(pipefds[0], 1);
- if (container->data.stream->type == UV_NAMED_PIPE &&
- ((uv_pipe_t*)container->data.stream)->ipc)
- flags = UV_STREAM_READABLE | UV_STREAM_WRITABLE;
- else if (writable)
- flags = UV_STREAM_WRITABLE;
- else
- flags = UV_STREAM_READABLE;
+ flags = 0;
+ if (container->flags & UV_WRITABLE_PIPE)
+ flags |= UV_HANDLE_READABLE;
+ if (container->flags & UV_READABLE_PIPE)
+ flags |= UV_HANDLE_WRITABLE;
return uv__stream_open(container->data.stream, pipefds[0], flags);
}
@@ -279,9 +287,20 @@ static void uv__process_child_init(const uv_process_options_t* options,
int stdio_count,
int (*pipes)[2],
int error_fd) {
+ sigset_t set;
int close_fd;
int use_fd;
+ int err;
int fd;
+ int n;
+#ifndef CMAKE_BOOTSTRAP
+#if defined(__linux__) || defined(__FreeBSD__)
+ int r;
+ int i;
+ int cpumask_size;
+ uv__cpu_set_t cpuset;
+#endif
+#endif
if (options->flags & UV_PROCESS_DETACHED)
setsid();
@@ -296,7 +315,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
continue;
pipes[fd][1] = fcntl(use_fd, F_DUPFD, stdio_count);
if (pipes[fd][1] == -1) {
- uv__write_int(error_fd, -errno);
+ uv__write_int(error_fd, UV__ERR(errno));
_exit(127);
}
}
@@ -315,8 +334,8 @@ static void uv__process_child_init(const uv_process_options_t* options,
use_fd = open("/dev/null", fd == 0 ? O_RDONLY : O_RDWR);
close_fd = use_fd;
- if (use_fd == -1) {
- uv__write_int(error_fd, -errno);
+ if (use_fd < 0) {
+ uv__write_int(error_fd, UV__ERR(errno));
_exit(127);
}
}
@@ -328,7 +347,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
fd = dup2(use_fd, fd);
if (fd == -1) {
- uv__write_int(error_fd, -errno);
+ uv__write_int(error_fd, UV__ERR(errno));
_exit(127);
}
@@ -347,7 +366,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
}
if (options->cwd != NULL && chdir(options->cwd)) {
- uv__write_int(error_fd, -errno);
+ uv__write_int(error_fd, UV__ERR(errno));
_exit(127);
}
@@ -363,21 +382,68 @@ static void uv__process_child_init(const uv_process_options_t* options,
}
if ((options->flags & UV_PROCESS_SETGID) && setgid(options->gid)) {
- uv__write_int(error_fd, -errno);
+ uv__write_int(error_fd, UV__ERR(errno));
_exit(127);
}
if ((options->flags & UV_PROCESS_SETUID) && setuid(options->uid)) {
- uv__write_int(error_fd, -errno);
+ uv__write_int(error_fd, UV__ERR(errno));
_exit(127);
}
+#ifndef CMAKE_BOOTSTRAP
+#if defined(__linux__) || defined(__FreeBSD__)
+ if (options->cpumask != NULL) {
+ cpumask_size = uv_cpumask_size();
+ assert(options->cpumask_size >= (size_t)cpumask_size);
+
+ CPU_ZERO(&cpuset);
+ for (i = 0; i < cpumask_size; ++i) {
+ if (options->cpumask[i]) {
+ CPU_SET(i, &cpuset);
+ }
+ }
+
+ r = -pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
+ if (r != 0) {
+ uv__write_int(error_fd, r);
+ _exit(127);
+ }
+ }
+#endif
+#endif
+
if (options->env != NULL) {
environ = options->env;
}
+ /* Reset signal disposition. Use a hard-coded limit because NSIG
+ * is not fixed on Linux: it's either 32, 34 or 64, depending on
+ * whether RT signals are enabled. We are not allowed to touch
+ * RT signal handlers, glibc uses them internally.
+ */
+ for (n = 1; n < 32; n += 1) {
+ if (n == SIGKILL || n == SIGSTOP)
+ continue; /* Can't be changed. */
+
+ if (SIG_ERR != signal(n, SIG_DFL))
+ continue;
+
+ uv__write_int(error_fd, UV__ERR(errno));
+ _exit(127);
+ }
+
+ /* Reset signal mask. */
+ sigemptyset(&set);
+ err = pthread_sigmask(SIG_SETMASK, &set, NULL);
+
+ if (err != 0) {
+ uv__write_int(error_fd, UV__ERR(err));
+ _exit(127);
+ }
+
execvp(options->file, options->args);
- uv__write_int(error_fd, -errno);
+ uv__write_int(error_fd, UV__ERR(errno));
_exit(127);
}
#endif
@@ -388,9 +454,10 @@ int uv_spawn(uv_loop_t* loop,
const uv_process_options_t* options) {
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
/* fork is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED. */
- return -ENOSYS;
+ return UV_ENOSYS;
#else
int signal_pipe[2] = { -1, -1 };
+ int pipes_storage[8][2];
int (*pipes)[2];
int stdio_count;
ssize_t r;
@@ -400,6 +467,20 @@ int uv_spawn(uv_loop_t* loop,
int i;
int status;
+ if (options->cpumask != NULL) {
+#ifndef CMAKE_BOOTSTRAP
+#if defined(__linux__) || defined(__FreeBSD__)
+ if (options->cpumask_size < (size_t)uv_cpumask_size()) {
+ return UV_EINVAL;
+ }
+#else
+ return UV_ENOTSUP;
+#endif
+#else
+ return UV_ENOTSUP;
+#endif
+ }
+
assert(options->file != NULL);
assert(!(options->flags & ~(UV_PROCESS_DETACHED |
UV_PROCESS_SETGID |
@@ -414,8 +495,11 @@ int uv_spawn(uv_loop_t* loop,
if (stdio_count < 3)
stdio_count = 3;
- err = -ENOMEM;
- pipes = uv__malloc(stdio_count * sizeof(*pipes));
+ err = UV_ENOMEM;
+ pipes = pipes_storage;
+ if (stdio_count > (int) ARRAY_SIZE(pipes_storage))
+ pipes = uv__malloc(stdio_count * sizeof(*pipes));
+
if (pipes == NULL)
goto error;
@@ -461,7 +545,7 @@ int uv_spawn(uv_loop_t* loop,
pid = fork();
if (pid == -1) {
- err = -errno;
+ err = UV__ERR(errno);
uv_rwlock_wrunlock(&loop->cloexec_lock);
uv__close(signal_pipe[0]);
uv__close(signal_pipe[1]);
@@ -501,7 +585,7 @@ int uv_spawn(uv_loop_t* loop,
uv__close_nocheckstdio(signal_pipe[0]);
for (i = 0; i < options->stdio_count; i++) {
- err = uv__process_open_stream(options->stdio + i, pipes[i], i == 0);
+ err = uv__process_open_stream(options->stdio + i, pipes[i]);
if (err == 0)
continue;
@@ -520,7 +604,9 @@ int uv_spawn(uv_loop_t* loop,
process->pid = pid;
process->exit_cb = options->exit_cb;
- uv__free(pipes);
+ if (pipes != pipes_storage)
+ uv__free(pipes);
+
return exec_errorno;
error:
@@ -534,7 +620,9 @@ error:
if (pipes[i][1] != -1)
uv__close_nocheckstdio(pipes[i][1]);
}
- uv__free(pipes);
+
+ if (pipes != pipes_storage)
+ uv__free(pipes);
}
return err;
@@ -549,7 +637,7 @@ int uv_process_kill(uv_process_t* process, int signum) {
int uv_kill(int pid, int signum) {
if (kill(pid, signum))
- return -errno;
+ return UV__ERR(errno);
else
return 0;
}
diff --git a/Utilities/cmlibuv/src/unix/procfs-exepath.c b/Utilities/cmlibuv/src/unix/procfs-exepath.c
index 5fdb61155..00dc021f2 100644
--- a/Utilities/cmlibuv/src/unix/procfs-exepath.c
+++ b/Utilities/cmlibuv/src/unix/procfs-exepath.c
@@ -29,14 +29,14 @@ int uv_exepath(char* buffer, size_t* size) {
ssize_t n;
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
n = *size - 1;
if (n > 0)
n = readlink("/proc/self/exe", buffer, n);
if (n == -1)
- return -errno;
+ return UV__ERR(errno);
buffer[n] = '\0';
*size = n;
diff --git a/Utilities/cmlibuv/src/unix/proctitle.c b/Utilities/cmlibuv/src/unix/proctitle.c
index 9160f7eaf..a5ce2030c 100644
--- a/Utilities/cmlibuv/src/unix/proctitle.c
+++ b/Utilities/cmlibuv/src/unix/proctitle.c
@@ -24,8 +24,11 @@
#include <stdlib.h>
#include <string.h>
+extern void uv__set_process_title_platform_init(void);
extern void uv__set_process_title(const char* title);
+static uv_mutex_t process_title_mutex;
+static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static void* args_mem;
static struct {
@@ -34,6 +37,14 @@ static struct {
} process_title;
+static void init_process_title_mutex_once(void) {
+ uv_mutex_init(&process_title_mutex);
+#ifdef __APPLE__
+ uv__set_process_title_platform_init();
+#endif
+}
+
+
char** uv_setup_args(int argc, char** argv) {
char** new_argv;
size_t size;
@@ -81,12 +92,16 @@ char** uv_setup_args(int argc, char** argv) {
int uv_set_process_title(const char* title) {
- if (process_title.len == 0)
- return 0;
+ uv_once(&process_title_mutex_once, init_process_title_mutex_once);
+ uv_mutex_lock(&process_title_mutex);
+
+ if (process_title.len != 0) {
+ /* No need to terminate, byte after is always '\0'. */
+ strncpy(process_title.str, title, process_title.len);
+ uv__set_process_title(title);
+ }
- /* No need to terminate, byte after is always '\0'. */
- strncpy(process_title.str, title, process_title.len);
- uv__set_process_title(title);
+ uv_mutex_unlock(&process_title_mutex);
return 0;
}
@@ -94,13 +109,23 @@ int uv_set_process_title(const char* title) {
int uv_get_process_title(char* buffer, size_t size) {
if (buffer == NULL || size == 0)
- return -EINVAL;
- else if (size <= process_title.len)
- return -ENOBUFS;
+ return UV_EINVAL;
+
+ uv_once(&process_title_mutex_once, init_process_title_mutex_once);
+ uv_mutex_lock(&process_title_mutex);
+
+ if (size <= process_title.len) {
+ uv_mutex_unlock(&process_title_mutex);
+ return UV_ENOBUFS;
+ }
+
+ if (process_title.len != 0)
+ memcpy(buffer, process_title.str, process_title.len + 1);
- memcpy(buffer, process_title.str, process_title.len + 1);
buffer[process_title.len] = '\0';
+ uv_mutex_unlock(&process_title_mutex);
+
return 0;
}
diff --git a/Utilities/cmlibuv/src/unix/signal.c b/Utilities/cmlibuv/src/unix/signal.c
index cb09ead50..01aa55f3f 100644
--- a/Utilities/cmlibuv/src/unix/signal.c
+++ b/Utilities/cmlibuv/src/unix/signal.c
@@ -28,6 +28,9 @@
#include <string.h>
#include <unistd.h>
+#ifndef SA_RESTART
+# define SA_RESTART 0
+#endif
typedef struct {
uv_signal_t* handle;
@@ -51,8 +54,7 @@ static void uv__signal_unregister_handler(int signum);
static uv_once_t uv__signal_global_init_guard = UV_ONCE_INIT;
static struct uv__signal_tree_s uv__signal_tree =
RB_INITIALIZER(uv__signal_tree);
-static int uv__signal_lock_pipefd[2];
-
+static int uv__signal_lock_pipefd[2] = { -1, -1 };
RB_GENERATE_STATIC(uv__signal_tree_s,
uv_signal_s, tree_entry,
@@ -61,7 +63,7 @@ RB_GENERATE_STATIC(uv__signal_tree_s,
static void uv__signal_global_reinit(void);
static void uv__signal_global_init(void) {
- if (!uv__signal_lock_pipefd[0])
+ if (uv__signal_lock_pipefd[0] == -1)
/* pthread_atfork can register before and after handlers, one
* for each child. This only registers one for the child. That
* state is both persistent and cumulative, so if we keep doing
@@ -71,15 +73,11 @@ static void uv__signal_global_init(void) {
if (pthread_atfork(NULL, NULL, &uv__signal_global_reinit))
abort();
- if (uv__make_pipe(uv__signal_lock_pipefd, 0))
- abort();
-
- if (uv__signal_unlock())
- abort();
+ uv__signal_global_reinit();
}
-static void uv__signal_global_reinit(void) {
+UV_DESTRUCTOR(static void uv__signal_global_fini(void)) {
/* We can only use signal-safe functions here.
* That includes read/write and close, fortunately.
* We do all of this directly here instead of resetting
@@ -87,11 +85,26 @@ static void uv__signal_global_reinit(void) {
* uv__signal_global_once_init is only called from uv_loop_init
* and this needs to function in existing loops.
*/
- uv__close(uv__signal_lock_pipefd[0]);
- uv__signal_lock_pipefd[0] = -1;
- uv__close(uv__signal_lock_pipefd[1]);
- uv__signal_lock_pipefd[1] = -1;
- uv__signal_global_init();
+ if (uv__signal_lock_pipefd[0] != -1) {
+ uv__close(uv__signal_lock_pipefd[0]);
+ uv__signal_lock_pipefd[0] = -1;
+ }
+
+ if (uv__signal_lock_pipefd[1] != -1) {
+ uv__close(uv__signal_lock_pipefd[1]);
+ uv__signal_lock_pipefd[1] = -1;
+ }
+}
+
+
+static void uv__signal_global_reinit(void) {
+ uv__signal_global_fini();
+
+ if (uv__make_pipe(uv__signal_lock_pipefd, 0))
+ abort();
+
+ if (uv__signal_unlock())
+ abort();
}
@@ -100,7 +113,6 @@ void uv__signal_global_once_init(void) {
}
-
static int uv__signal_lock(void) {
int r;
char data;
@@ -216,11 +228,13 @@ static int uv__signal_register_handler(int signum, int oneshot) {
if (sigfillset(&sa.sa_mask))
abort();
sa.sa_handler = uv__signal_handler;
- sa.sa_flags = oneshot ? SA_RESETHAND : 0;
+ sa.sa_flags = SA_RESTART;
+ if (oneshot)
+ sa.sa_flags |= SA_RESETHAND;
/* XXX save old action so we can restore it later on? */
if (sigaction(signum, &sa, NULL))
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -357,7 +371,7 @@ static int uv__signal_start(uv_signal_t* handle,
* eventually.
*/
if (signum == 0)
- return -EINVAL;
+ return UV_EINVAL;
/* Short circuit: if the signal watcher is already watching {signum} don't
* go through the process of deregistering and registering the handler.
@@ -382,7 +396,7 @@ static int uv__signal_start(uv_signal_t* handle,
*/
first_handle = uv__signal_first_handle(signum);
if (first_handle == NULL ||
- (!oneshot && (first_handle->flags & UV__SIGNAL_ONE_SHOT))) {
+ (!oneshot && (first_handle->flags & UV_SIGNAL_ONE_SHOT))) {
err = uv__signal_register_handler(signum, oneshot);
if (err) {
/* Registering the signal handler failed. Must be an invalid signal. */
@@ -393,7 +407,7 @@ static int uv__signal_start(uv_signal_t* handle,
handle->signum = signum;
if (oneshot)
- handle->flags |= UV__SIGNAL_ONE_SHOT;
+ handle->flags |= UV_SIGNAL_ONE_SHOT;
RB_INSERT(uv__signal_tree_s, &uv__signal_tree, handle);
@@ -450,20 +464,20 @@ static void uv__signal_event(uv_loop_t* loop,
handle = msg->handle;
if (msg->signum == handle->signum) {
- assert(!(handle->flags & UV_CLOSING));
+ assert(!(handle->flags & UV_HANDLE_CLOSING));
handle->signal_cb(handle, handle->signum);
}
handle->dispatched_signals++;
- if (handle->flags & UV__SIGNAL_ONE_SHOT)
+ if (handle->flags & UV_SIGNAL_ONE_SHOT)
uv__signal_stop(handle);
/* If uv_close was called while there were caught signals that were not
* yet dispatched, the uv__finish_close was deferred. Make close pending
* now if this has happened.
*/
- if ((handle->flags & UV_CLOSING) &&
+ if ((handle->flags & UV_HANDLE_CLOSING) &&
(handle->caught_signals == handle->dispatched_signals)) {
uv__make_close_pending((uv_handle_t*) handle);
}
@@ -491,11 +505,11 @@ static int uv__signal_compare(uv_signal_t* w1, uv_signal_t* w2) {
if (w1->signum < w2->signum) return -1;
if (w1->signum > w2->signum) return 1;
- /* Handlers without UV__SIGNAL_ONE_SHOT set will come first, so if the first
+ /* Handlers without UV_SIGNAL_ONE_SHOT set will come first, so if the first
* handler returned is a one-shot handler, the rest will be too.
*/
- f1 = w1->flags & UV__SIGNAL_ONE_SHOT;
- f2 = w2->flags & UV__SIGNAL_ONE_SHOT;
+ f1 = w1->flags & UV_SIGNAL_ONE_SHOT;
+ f2 = w2->flags & UV_SIGNAL_ONE_SHOT;
if (f1 < f2) return -1;
if (f1 > f2) return 1;
@@ -544,8 +558,8 @@ static void uv__signal_stop(uv_signal_t* handle) {
if (first_handle == NULL) {
uv__signal_unregister_handler(handle->signum);
} else {
- rem_oneshot = handle->flags & UV__SIGNAL_ONE_SHOT;
- first_oneshot = first_handle->flags & UV__SIGNAL_ONE_SHOT;
+ rem_oneshot = handle->flags & UV_SIGNAL_ONE_SHOT;
+ first_oneshot = first_handle->flags & UV_SIGNAL_ONE_SHOT;
if (first_oneshot && !rem_oneshot) {
ret = uv__signal_register_handler(handle->signum, 1);
assert(ret == 0);
diff --git a/Utilities/cmlibuv/src/unix/stream.c b/Utilities/cmlibuv/src/unix/stream.c
index 7b23d16ec..4b9123f1a 100644
--- a/Utilities/cmlibuv/src/unix/stream.c
+++ b/Utilities/cmlibuv/src/unix/stream.c
@@ -58,6 +58,20 @@ struct uv__stream_select_s {
fd_set* swrite;
size_t swrite_sz;
};
+
+/* Due to a possible kernel bug at least in OS X 10.10 "Yosemite",
+ * EPROTOTYPE can be returned while trying to write to a socket that is
+ * shutting down. If we retry the write, we should get the expected EPIPE
+ * instead.
+ */
+# define RETRY_ON_WRITE_ERROR(errno) (errno == EINTR || errno == EPROTOTYPE)
+# define IS_TRANSIENT_WRITE_ERROR(errno, send_handle) \
+ (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || \
+ (errno == EMSGSIZE && send_handle != NULL))
+#else
+# define RETRY_ON_WRITE_ERROR(errno) (errno == EINTR)
+# define IS_TRANSIENT_WRITE_ERROR(errno, send_handle) \
+ (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS)
#endif /* defined(__APPLE__) */
static void uv__stream_connect(uv_stream_t*);
@@ -98,7 +112,7 @@ void uv__stream_init(uv_loop_t* loop,
loop->emfile_fd = err;
}
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
stream->select = NULL;
#endif /* defined(__APPLE_) */
@@ -107,7 +121,7 @@ void uv__stream_init(uv_loop_t* loop,
static void uv__stream_osx_interrupt_select(uv_stream_t* stream) {
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
/* Notify select() thread about state change */
uv__stream_select_t* s;
int r;
@@ -131,7 +145,7 @@ static void uv__stream_osx_interrupt_select(uv_stream_t* stream) {
}
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
static void uv__stream_osx_select(void* arg) {
uv_stream_t* stream;
uv__stream_select_t* s;
@@ -214,7 +228,7 @@ static void uv__stream_osx_select(void* arg) {
uv_sem_wait(&s->async_sem);
/* Should be processed at this stage */
- assert((s->events == 0) || (stream->flags & UV_CLOSING));
+ assert((s->events == 0) || (stream->flags & UV_HANDLE_CLOSING));
}
}
}
@@ -242,7 +256,7 @@ static void uv__stream_osx_select_cb(uv_async_t* handle) {
if ((events & POLLOUT) && uv__io_active(&stream->io_watcher, POLLOUT))
uv__stream_io(stream->loop, &stream->io_watcher, POLLOUT);
- if (stream->flags & UV_CLOSING)
+ if (stream->flags & UV_HANDLE_CLOSING)
return;
/* NOTE: It is important to do it here, otherwise `select()` might be called
@@ -282,7 +296,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
kq = kqueue();
if (kq == -1) {
perror("(libuv) kqueue()");
- return -errno;
+ return UV__ERR(errno);
}
EV_SET(&filter[0], *fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0);
@@ -298,7 +312,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
uv__close(kq);
if (ret == -1)
- return -errno;
+ return UV__ERR(errno);
if (ret == 0 || (events[0].flags & EV_ERROR) == 0 || events[0].data != EINVAL)
return 0;
@@ -310,7 +324,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
* NOTE: do it ahead of malloc below to allocate enough space for fd_sets
*/
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
- return -errno;
+ return UV__ERR(errno);
max_fd = *fd;
if (fds[1] > max_fd)
@@ -321,7 +335,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
s = uv__malloc(sizeof(*s) + sread_sz + swrite_sz);
if (s == NULL) {
- err = -ENOMEM;
+ err = UV_ENOMEM;
goto failed_malloc;
}
@@ -336,7 +350,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
if (err)
goto failed_async_init;
- s->async.flags |= UV__HANDLE_INTERNAL;
+ s->async.flags |= UV_HANDLE_INTERNAL;
uv__handle_unref(&s->async);
err = uv_sem_init(&s->close_sem, 0);
@@ -395,18 +409,20 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
#endif
if (!(stream->io_watcher.fd == -1 || stream->io_watcher.fd == fd))
- return -EBUSY;
+ return UV_EBUSY;
assert(fd >= 0);
stream->flags |= flags;
if (stream->type == UV_TCP) {
- if ((stream->flags & UV_TCP_NODELAY) && uv__tcp_nodelay(fd, 1))
- return -errno;
+ if ((stream->flags & UV_HANDLE_TCP_NODELAY) && uv__tcp_nodelay(fd, 1))
+ return UV__ERR(errno);
/* TODO Use delay the user passed in. */
- if ((stream->flags & UV_TCP_KEEPALIVE) && uv__tcp_keepalive(fd, 1, 60))
- return -errno;
+ if ((stream->flags & UV_HANDLE_TCP_KEEPALIVE) &&
+ uv__tcp_keepalive(fd, 1, 60)) {
+ return UV__ERR(errno);
+ }
}
#if defined(__APPLE__)
@@ -414,7 +430,7 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &enable, sizeof(enable)) &&
errno != ENOTSOCK &&
errno != EINVAL) {
- return -errno;
+ return UV__ERR(errno);
}
#endif
@@ -441,15 +457,15 @@ void uv__stream_flush_write_queue(uv_stream_t* stream, int error) {
void uv__stream_destroy(uv_stream_t* stream) {
assert(!uv__io_active(&stream->io_watcher, POLLIN | POLLOUT));
- assert(stream->flags & UV_CLOSED);
+ assert(stream->flags & UV_HANDLE_CLOSED);
if (stream->connect_req) {
uv__req_unregister(stream->loop, stream->connect_req);
- stream->connect_req->cb(stream->connect_req, -ECANCELED);
+ stream->connect_req->cb(stream->connect_req, UV_ECANCELED);
stream->connect_req = NULL;
}
- uv__stream_flush_write_queue(stream, -ECANCELED);
+ uv__stream_flush_write_queue(stream, UV_ECANCELED);
uv__write_callbacks(stream);
if (stream->shutdown_req) {
@@ -459,7 +475,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
* callee that the handle has been destroyed.
*/
uv__req_unregister(stream->loop, stream->shutdown_req);
- stream->shutdown_req->cb(stream->shutdown_req, -ECANCELED);
+ stream->shutdown_req->cb(stream->shutdown_req, UV_ECANCELED);
stream->shutdown_req = NULL;
}
@@ -483,7 +499,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) {
int emfile_fd;
if (loop->emfile_fd == -1)
- return -EMFILE;
+ return UV_EMFILE;
uv__close(loop->emfile_fd);
loop->emfile_fd = -1;
@@ -492,7 +508,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) {
err = uv__accept(accept_fd);
if (err >= 0)
uv__close(err);
- } while (err >= 0 || err == -EINTR);
+ } while (err >= 0 || err == UV_EINTR);
emfile_fd = uv__open_cloexec("/", O_RDONLY);
if (emfile_fd >= 0)
@@ -514,9 +530,9 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
int err;
stream = container_of(w, uv_stream_t, io_watcher);
- assert(events == POLLIN);
+ assert(events & POLLIN);
assert(stream->accepted_fd == -1);
- assert(!(stream->flags & UV_CLOSING));
+ assert(!(stream->flags & UV_HANDLE_CLOSING));
uv__io_start(stream->loop, &stream->io_watcher, POLLIN);
@@ -533,15 +549,15 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
err = uv__accept(uv__stream_fd(stream));
if (err < 0) {
- if (err == -EAGAIN || err == -EWOULDBLOCK)
+ if (err == UV_EAGAIN || err == UV__ERR(EWOULDBLOCK))
return; /* Not an error. */
- if (err == -ECONNABORTED)
+ if (err == UV_ECONNABORTED)
continue; /* Ignore. Nothing we can do about that. */
- if (err == -EMFILE || err == -ENFILE) {
+ if (err == UV_EMFILE || err == UV_ENFILE) {
err = uv__emfile_trick(loop, uv__stream_fd(stream));
- if (err == -EAGAIN || err == -EWOULDBLOCK)
+ if (err == UV_EAGAIN || err == UV__ERR(EWOULDBLOCK))
break;
}
@@ -559,7 +575,8 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
return;
}
- if (stream->type == UV_TCP && (stream->flags & UV_TCP_SINGLE_ACCEPT)) {
+ if (stream->type == UV_TCP &&
+ (stream->flags & UV_HANDLE_TCP_SINGLE_ACCEPT)) {
/* Give other processes a chance to accept connections. */
struct timespec timeout = { 0, 1 };
nanosleep(&timeout, NULL);
@@ -577,14 +594,14 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) {
assert(server->loop == client->loop);
if (server->accepted_fd == -1)
- return -EAGAIN;
+ return UV_EAGAIN;
switch (client->type) {
case UV_NAMED_PIPE:
case UV_TCP:
err = uv__stream_open(client,
server->accepted_fd,
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
if (err) {
/* TODO handle error */
uv__close(server->accepted_fd);
@@ -601,7 +618,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) {
break;
default:
- return -EINVAL;
+ return UV_EINVAL;
}
client->flags |= UV_HANDLE_BOUND;
@@ -649,7 +666,7 @@ int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) {
break;
default:
- err = -EINVAL;
+ err = UV_EINVAL;
}
if (err == 0)
@@ -668,22 +685,22 @@ static void uv__drain(uv_stream_t* stream) {
uv__stream_osx_interrupt_select(stream);
/* Shutdown? */
- if ((stream->flags & UV_STREAM_SHUTTING) &&
- !(stream->flags & UV_CLOSING) &&
- !(stream->flags & UV_STREAM_SHUT)) {
+ if ((stream->flags & UV_HANDLE_SHUTTING) &&
+ !(stream->flags & UV_HANDLE_CLOSING) &&
+ !(stream->flags & UV_HANDLE_SHUT)) {
assert(stream->shutdown_req);
req = stream->shutdown_req;
stream->shutdown_req = NULL;
- stream->flags &= ~UV_STREAM_SHUTTING;
+ stream->flags &= ~UV_HANDLE_SHUTTING;
uv__req_unregister(stream->loop, req);
err = 0;
if (shutdown(uv__stream_fd(stream), SHUT_WR))
- err = -errno;
+ err = UV__ERR(errno);
if (err == 0)
- stream->flags |= UV_STREAM_SHUT;
+ stream->flags |= UV_HANDLE_SHUT;
if (req->cb != NULL)
req->cb(req, err);
@@ -691,6 +708,14 @@ static void uv__drain(uv_stream_t* stream) {
}
+static ssize_t uv__writev(int fd, struct iovec* vec, size_t n) {
+ if (n == 1)
+ return write(fd, vec->iov_base, vec->iov_len);
+ else
+ return writev(fd, vec, n);
+}
+
+
static size_t uv__write_req_size(uv_write_t* req) {
size_t size;
@@ -703,6 +728,37 @@ static size_t uv__write_req_size(uv_write_t* req) {
}
+/* Returns 1 if all write request data has been written, or 0 if there is still
+ * more data to write.
+ *
+ * Note: the return value only says something about the *current* request.
+ * There may still be other write requests sitting in the queue.
+ */
+static int uv__write_req_update(uv_stream_t* stream,
+ uv_write_t* req,
+ size_t n) {
+ uv_buf_t* buf;
+ size_t len;
+
+ assert(n <= stream->write_queue_size);
+ stream->write_queue_size -= n;
+
+ buf = req->bufs + req->write_index;
+
+ while (n > 0) {
+ len = n < buf->len ? n : buf->len;
+ buf->base += len;
+ buf->len -= len;
+ buf += (buf->len == 0); /* Advance to next buffer if this one is empty. */
+ n -= len;
+ }
+
+ req->write_index = buf - req->bufs;
+
+ return req->write_index == req->nbufs;
+}
+
+
static void uv__write_req_finish(uv_write_t* req) {
uv_stream_t* stream = req->handle;
@@ -750,6 +806,7 @@ static void uv__write(uv_stream_t* stream) {
int iovmax;
int iovcnt;
ssize_t n;
+ int err;
start:
@@ -782,14 +839,21 @@ start:
*/
if (req->send_handle) {
+ int fd_to_send;
struct msghdr msg;
struct cmsghdr *cmsg;
- int fd_to_send = uv__handle_fd((uv_handle_t*) req->send_handle);
union {
char data[64];
struct cmsghdr alias;
} scratch;
+ if (uv__is_closing(req->send_handle)) {
+ err = UV_EBADF;
+ goto error;
+ }
+
+ fd_to_send = uv__handle_fd((uv_handle_t*) req->send_handle);
+
memset(&scratch, 0, sizeof(scratch));
assert(fd_to_send >= 0);
@@ -815,124 +879,64 @@ start:
*pi = fd_to_send;
}
- do {
+ do
n = sendmsg(uv__stream_fd(stream), &msg, 0);
- }
-#if defined(__APPLE__)
- /*
- * Due to a possible kernel bug at least in OS X 10.10 "Yosemite",
- * EPROTOTYPE can be returned while trying to write to a socket that is
- * shutting down. If we retry the write, we should get the expected EPIPE
- * instead.
- */
- while (n == -1 && (errno == EINTR || errno == EPROTOTYPE));
-#else
- while (n == -1 && errno == EINTR);
-#endif
- } else {
- do {
- if (iovcnt == 1) {
- n = write(uv__stream_fd(stream), iov[0].iov_base, iov[0].iov_len);
- } else {
- n = writev(uv__stream_fd(stream), iov, iovcnt);
- }
- }
-#if defined(__APPLE__)
- /*
- * Due to a possible kernel bug at least in OS X 10.10 "Yosemite",
- * EPROTOTYPE can be returned while trying to write to a socket that is
- * shutting down. If we retry the write, we should get the expected EPIPE
- * instead.
- */
- while (n == -1 && (errno == EINTR || errno == EPROTOTYPE));
-#else
- while (n == -1 && errno == EINTR);
-#endif
- }
+ while (n == -1 && RETRY_ON_WRITE_ERROR(errno));
- if (n < 0) {
- if (errno != EAGAIN && errno != EWOULDBLOCK) {
- /* Error */
- req->error = -errno;
- uv__write_req_finish(req);
- uv__io_stop(stream->loop, &stream->io_watcher, POLLOUT);
- if (!uv__io_active(&stream->io_watcher, POLLIN))
- uv__handle_stop(stream);
- uv__stream_osx_interrupt_select(stream);
- return;
- } else if (stream->flags & UV_STREAM_BLOCKING) {
- /* If this is a blocking stream, try again. */
- goto start;
- }
+ /* Ensure the handle isn't sent again in case this is a partial write. */
+ if (n >= 0)
+ req->send_handle = NULL;
} else {
- /* Successful write */
-
- while (n >= 0) {
- uv_buf_t* buf = &(req->bufs[req->write_index]);
- size_t len = buf->len;
-
- assert(req->write_index < req->nbufs);
-
- if ((size_t)n < len) {
- buf->base += n;
- buf->len -= n;
- stream->write_queue_size -= n;
- n = 0;
-
- /* There is more to write. */
- if (stream->flags & UV_STREAM_BLOCKING) {
- /*
- * If we're blocking then we should not be enabling the write
- * watcher - instead we need to try again.
- */
- goto start;
- } else {
- /* Break loop and ensure the watcher is pending. */
- break;
- }
-
- } else {
- /* Finished writing the buf at index req->write_index. */
- req->write_index++;
-
- assert((size_t)n >= len);
- n -= len;
-
- assert(stream->write_queue_size >= len);
- stream->write_queue_size -= len;
+ do
+ n = uv__writev(uv__stream_fd(stream), iov, iovcnt);
+ while (n == -1 && RETRY_ON_WRITE_ERROR(errno));
+ }
- if (req->write_index == req->nbufs) {
- /* Then we're done! */
- assert(n == 0);
- uv__write_req_finish(req);
- /* TODO: start trying to write the next request. */
- return;
- }
- }
- }
+ if (n == -1 && !IS_TRANSIENT_WRITE_ERROR(errno, req->send_handle)) {
+ err = UV__ERR(errno);
+ goto error;
}
- /* Either we've counted n down to zero or we've got EAGAIN. */
- assert(n == 0 || n == -1);
+ if (n > 0 && uv__write_req_update(stream, req, n)) {
+ uv__write_req_finish(req);
+ return; /* TODO(bnoordhuis) Start trying to write the next request. */
+ }
- /* Only non-blocking streams should use the write_watcher. */
- assert(!(stream->flags & UV_STREAM_BLOCKING));
+ /* If this is a blocking stream, try again. */
+ if (stream->flags & UV_HANDLE_BLOCKING_WRITES)
+ goto start;
/* We're not done. */
uv__io_start(stream->loop, &stream->io_watcher, POLLOUT);
/* Notify select() thread about state change */
uv__stream_osx_interrupt_select(stream);
+
+ return;
+
+error:
+ req->error = err;
+ uv__write_req_finish(req);
+ uv__io_stop(stream->loop, &stream->io_watcher, POLLOUT);
+ if (!uv__io_active(&stream->io_watcher, POLLIN))
+ uv__handle_stop(stream);
+ uv__stream_osx_interrupt_select(stream);
}
static void uv__write_callbacks(uv_stream_t* stream) {
uv_write_t* req;
QUEUE* q;
+ QUEUE pq;
+
+ if (QUEUE_EMPTY(&stream->write_completed_queue))
+ return;
+
+ QUEUE_MOVE(&stream->write_completed_queue, &pq);
- while (!QUEUE_EMPTY(&stream->write_completed_queue)) {
+ while (!QUEUE_EMPTY(&pq)) {
/* Pop a req off write_completed_queue. */
- q = QUEUE_HEAD(&stream->write_completed_queue);
+ q = QUEUE_HEAD(&pq);
req = QUEUE_DATA(q, uv_write_t, queue);
QUEUE_REMOVE(q);
uv__req_unregister(stream->loop, req);
@@ -948,8 +952,6 @@ static void uv__write_callbacks(uv_stream_t* stream) {
if (req->cb)
req->cb(req, req->error);
}
-
- assert(QUEUE_EMPTY(&stream->write_completed_queue));
}
@@ -997,13 +999,13 @@ uv_handle_type uv__handle_type(int fd) {
static void uv__stream_eof(uv_stream_t* stream, const uv_buf_t* buf) {
- stream->flags |= UV_STREAM_READ_EOF;
+ stream->flags |= UV_HANDLE_READ_EOF;
uv__io_stop(stream->loop, &stream->io_watcher, POLLIN);
if (!uv__io_active(&stream->io_watcher, POLLOUT))
uv__handle_stop(stream);
uv__stream_osx_interrupt_select(stream);
stream->read_cb(stream, UV_EOF, buf);
- stream->flags &= ~UV_STREAM_READING;
+ stream->flags &= ~UV_HANDLE_READING;
}
@@ -1017,7 +1019,7 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) {
queued_fds = uv__malloc((queue_size - 1) * sizeof(*queued_fds->fds) +
sizeof(*queued_fds));
if (queued_fds == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
queued_fds->size = queue_size;
queued_fds->offset = 0;
stream->queued_fds = queued_fds;
@@ -1034,7 +1036,7 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) {
* NOTE: if it is fatal - sockets will be closed in uv__stream_close
*/
if (queued_fds == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
queued_fds->size = queue_size;
stream->queued_fds = queued_fds;
}
@@ -1103,6 +1105,7 @@ static int uv__stream_recv_cmsg(uv_stream_t* stream, struct msghdr* msg) {
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wgnu-folding-constant"
+# pragma clang diagnostic ignored "-Wvla-extension"
#endif
static void uv__read(uv_stream_t* stream) {
@@ -1114,7 +1117,7 @@ static void uv__read(uv_stream_t* stream) {
int err;
int is_ipc;
- stream->flags &= ~UV_STREAM_READ_PARTIAL;
+ stream->flags &= ~UV_HANDLE_READ_PARTIAL;
/* Prevent loop starvation when the data comes in as fast as (or faster than)
* we can read it. XXX Need to rearm fd if we switch to edge-triggered I/O.
@@ -1123,11 +1126,11 @@ static void uv__read(uv_stream_t* stream) {
is_ipc = stream->type == UV_NAMED_PIPE && ((uv_pipe_t*) stream)->ipc;
- /* XXX: Maybe instead of having UV_STREAM_READING we just test if
+ /* XXX: Maybe instead of having UV_HANDLE_READING we just test if
* tcp->read_cb is NULL or not?
*/
while (stream->read_cb
- && (stream->flags & UV_STREAM_READING)
+ && (stream->flags & UV_HANDLE_READING)
&& (count-- > 0)) {
assert(stream->alloc_cb != NULL);
@@ -1168,7 +1171,7 @@ static void uv__read(uv_stream_t* stream) {
/* Error */
if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* Wait for the next one. */
- if (stream->flags & UV_STREAM_READING) {
+ if (stream->flags & UV_HANDLE_READING) {
uv__io_start(stream->loop, &stream->io_watcher, POLLIN);
uv__stream_osx_interrupt_select(stream);
}
@@ -1180,9 +1183,9 @@ static void uv__read(uv_stream_t* stream) {
#endif
} else {
/* Error. User should call uv_close(). */
- stream->read_cb(stream, -errno, &buf);
- if (stream->flags & UV_STREAM_READING) {
- stream->flags &= ~UV_STREAM_READING;
+ stream->read_cb(stream, UV__ERR(errno), &buf);
+ if (stream->flags & UV_HANDLE_READING) {
+ stream->flags &= ~UV_HANDLE_READING;
uv__io_stop(stream->loop, &stream->io_watcher, POLLIN);
if (!uv__io_active(&stream->io_watcher, POLLOUT))
uv__handle_stop(stream);
@@ -1232,7 +1235,7 @@ static void uv__read(uv_stream_t* stream) {
/* Return if we didn't fill the buffer, there is no more data to read. */
if (nread < buflen) {
- stream->flags |= UV_STREAM_READ_PARTIAL;
+ stream->flags |= UV_HANDLE_READ_PARTIAL;
return;
}
}
@@ -1249,14 +1252,15 @@ static void uv__read(uv_stream_t* stream) {
int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
- assert((stream->type == UV_TCP || stream->type == UV_NAMED_PIPE) &&
- "uv_shutdown (unix) only supports uv_handle_t right now");
+ assert(stream->type == UV_TCP ||
+ stream->type == UV_TTY ||
+ stream->type == UV_NAMED_PIPE);
- if (!(stream->flags & UV_STREAM_WRITABLE) ||
- stream->flags & UV_STREAM_SHUT ||
- stream->flags & UV_STREAM_SHUTTING ||
+ if (!(stream->flags & UV_HANDLE_WRITABLE) ||
+ stream->flags & UV_HANDLE_SHUT ||
+ stream->flags & UV_HANDLE_SHUTTING ||
uv__is_closing(stream)) {
- return -ENOTCONN;
+ return UV_ENOTCONN;
}
assert(uv__stream_fd(stream) >= 0);
@@ -1266,7 +1270,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
req->handle = stream;
req->cb = cb;
stream->shutdown_req = req;
- stream->flags |= UV_STREAM_SHUTTING;
+ stream->flags |= UV_HANDLE_SHUTTING;
uv__io_start(stream->loop, &stream->io_watcher, POLLOUT);
uv__stream_osx_interrupt_select(stream);
@@ -1283,7 +1287,7 @@ static void uv__stream_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
assert(stream->type == UV_TCP ||
stream->type == UV_NAMED_PIPE ||
stream->type == UV_TTY);
- assert(!(stream->flags & UV_CLOSING));
+ assert(!(stream->flags & UV_HANDLE_CLOSING));
if (stream->connect_req) {
uv__stream_connect(stream);
@@ -1292,7 +1296,7 @@ static void uv__stream_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
assert(uv__stream_fd(stream) >= 0);
- /* Ignore POLLHUP here. Even it it's set, there may still be data to read. */
+ /* Ignore POLLHUP here. Even if it's set, there may still be data to read. */
if (events & (POLLIN | POLLERR | POLLHUP))
uv__read(stream);
@@ -1306,9 +1310,9 @@ static void uv__stream_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
* report the EOF yet because there is still data to read.
*/
if ((events & POLLHUP) &&
- (stream->flags & UV_STREAM_READING) &&
- (stream->flags & UV_STREAM_READ_PARTIAL) &&
- !(stream->flags & UV_STREAM_READ_EOF)) {
+ (stream->flags & UV_HANDLE_READING) &&
+ (stream->flags & UV_HANDLE_READ_PARTIAL) &&
+ !(stream->flags & UV_HANDLE_READ_EOF)) {
uv_buf_t buf = { NULL, 0 };
uv__stream_eof(stream, &buf);
}
@@ -1355,10 +1359,10 @@ static void uv__stream_connect(uv_stream_t* stream) {
SO_ERROR,
&error,
&errorsize);
- error = -error;
+ error = UV__ERR(error);
}
- if (error == -EINPROGRESS)
+ if (error == UV__ERR(EINPROGRESS))
return;
stream->connect_req = NULL;
@@ -1375,7 +1379,7 @@ static void uv__stream_connect(uv_stream_t* stream) {
return;
if (error < 0) {
- uv__stream_flush_write_queue(stream, -ECANCELED);
+ uv__stream_flush_write_queue(stream, UV_ECANCELED);
uv__write_callbacks(stream);
}
}
@@ -1396,11 +1400,14 @@ int uv_write2(uv_write_t* req,
"uv_write (unix) does not yet support other types of streams");
if (uv__stream_fd(stream) < 0)
- return -EBADF;
+ return UV_EBADF;
+
+ if (!(stream->flags & UV_HANDLE_WRITABLE))
+ return -EPIPE;
if (send_handle) {
if (stream->type != UV_NAMED_PIPE || !((uv_pipe_t*)stream)->ipc)
- return -EINVAL;
+ return UV_EINVAL;
/* XXX We abuse uv_write2() to send over UDP handles to child processes.
* Don't call uv__stream_fd() on those handles, it's a macro that on OS X
@@ -1409,12 +1416,12 @@ int uv_write2(uv_write_t* req,
* which works but only by accident.
*/
if (uv__handle_fd((uv_handle_t*) send_handle) < 0)
- return -EBADF;
+ return UV_EBADF;
#if defined(__CYGWIN__) || defined(__MSYS__)
/* Cygwin recvmsg always sets msg_controllen to zero, so we cannot send it.
See https://github.com/mirror/newlib-cygwin/blob/86fc4bf0/winsup/cygwin/fhandler_socket.cc#L1736-L1743 */
- return -ENOSYS;
+ return UV_ENOSYS;
#endif
}
@@ -1439,7 +1446,7 @@ int uv_write2(uv_write_t* req,
req->bufs = uv__malloc(nbufs * sizeof(bufs[0]));
if (req->bufs == NULL)
- return -ENOMEM;
+ return UV_ENOMEM;
memcpy(req->bufs, bufs, nbufs * sizeof(bufs[0]));
req->nbufs = nbufs;
@@ -1465,7 +1472,7 @@ int uv_write2(uv_write_t* req,
* if this assert fires then somehow the blocking stream isn't being
* sufficiently flushed in uv__write.
*/
- assert(!(stream->flags & UV_STREAM_BLOCKING));
+ assert(!(stream->flags & UV_HANDLE_BLOCKING_WRITES));
uv__io_start(stream->loop, &stream->io_watcher, POLLOUT);
uv__stream_osx_interrupt_select(stream);
}
@@ -1503,7 +1510,7 @@ int uv_try_write(uv_stream_t* stream,
/* Connecting or already writing some data */
if (stream->connect_req != NULL || stream->write_queue_size != 0)
- return -EAGAIN;
+ return UV_EAGAIN;
has_pollout = uv__io_active(&stream->io_watcher, POLLOUT);
@@ -1534,7 +1541,7 @@ int uv_try_write(uv_stream_t* stream,
}
if (written == 0 && req_size != 0)
- return -EAGAIN;
+ return UV_EAGAIN;
else
return written;
}
@@ -1546,13 +1553,16 @@ int uv_read_start(uv_stream_t* stream,
assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE ||
stream->type == UV_TTY);
- if (stream->flags & UV_CLOSING)
- return -EINVAL;
+ if (stream->flags & UV_HANDLE_CLOSING)
+ return UV_EINVAL;
- /* The UV_STREAM_READING flag is irrelevant of the state of the tcp - it just
+ if (!(stream->flags & UV_HANDLE_READABLE))
+ return -ENOTCONN;
+
+ /* The UV_HANDLE_READING flag is irrelevant of the state of the tcp - it just
* expresses the desired state of the user.
*/
- stream->flags |= UV_STREAM_READING;
+ stream->flags |= UV_HANDLE_READING;
/* TODO: try to do the read inline? */
/* TODO: keep track of tcp state. If we've gotten a EOF then we should
@@ -1573,10 +1583,10 @@ int uv_read_start(uv_stream_t* stream,
int uv_read_stop(uv_stream_t* stream) {
- if (!(stream->flags & UV_STREAM_READING))
+ if (!(stream->flags & UV_HANDLE_READING))
return 0;
- stream->flags &= ~UV_STREAM_READING;
+ stream->flags &= ~UV_HANDLE_READING;
uv__io_stop(stream->loop, &stream->io_watcher, POLLIN);
if (!uv__io_active(&stream->io_watcher, POLLOUT))
uv__handle_stop(stream);
@@ -1589,16 +1599,16 @@ int uv_read_stop(uv_stream_t* stream) {
int uv_is_readable(const uv_stream_t* stream) {
- return !!(stream->flags & UV_STREAM_READABLE);
+ return !!(stream->flags & UV_HANDLE_READABLE);
}
int uv_is_writable(const uv_stream_t* stream) {
- return !!(stream->flags & UV_STREAM_WRITABLE);
+ return !!(stream->flags & UV_HANDLE_WRITABLE);
}
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
int uv___stream_fd(const uv_stream_t* handle) {
const uv__stream_select_t* s;
@@ -1619,7 +1629,7 @@ void uv__stream_close(uv_stream_t* handle) {
unsigned int i;
uv__stream_queued_fds_t* queued_fds;
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP)
/* Terminate select loop first */
if (handle->select != NULL) {
uv__stream_select_t* s;
@@ -1643,6 +1653,7 @@ void uv__stream_close(uv_stream_t* handle) {
uv__io_close(handle->loop, &handle->io_watcher);
uv_read_stop(handle);
uv__handle_stop(handle);
+ handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
if (handle->io_watcher.fd != -1) {
/* Don't close stdio file descriptors. Nothing good comes from it. */
diff --git a/Utilities/cmlibuv/src/unix/sunos.c b/Utilities/cmlibuv/src/unix/sunos.c
index 041f3f336..aac650411 100644
--- a/Utilities/cmlibuv/src/unix/sunos.c
+++ b/Utilities/cmlibuv/src/unix/sunos.c
@@ -77,7 +77,7 @@ int uv__platform_loop_init(uv_loop_t* loop) {
fd = port_create();
if (fd == -1)
- return -errno;
+ return UV__ERR(errno);
err = uv__cloexec(fd, 1);
if (err) {
@@ -136,7 +136,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
int uv__io_check_fd(uv_loop_t* loop, int fd) {
if (port_associate(loop->backend_fd, PORT_SOURCE_FD, fd, POLLIN, 0))
- return -errno;
+ return UV__ERR(errno);
if (port_dissociate(loop->backend_fd, PORT_SOURCE_FD, fd))
abort();
@@ -346,7 +346,7 @@ int uv_exepath(char* buffer, size_t* size) {
char buf[128];
if (buffer == NULL || size == NULL || *size == 0)
- return -EINVAL;
+ return UV_EINVAL;
snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
@@ -355,7 +355,7 @@ int uv_exepath(char* buffer, size_t* size) {
res = readlink(buf, buffer, res);
if (res == -1)
- return -errno;
+ return UV__ERR(errno);
buffer[res] = '\0';
*size = res;
@@ -382,14 +382,14 @@ void uv_loadavg(double avg[3]) {
static int uv__fs_event_rearm(uv_fs_event_t *handle) {
if (handle->fd == -1)
- return -EBADF;
+ return UV_EBADF;
if (port_associate(handle->loop->fs_fd,
PORT_SOURCE_FILE,
(uintptr_t) &handle->fo,
FILE_ATTRIB | FILE_MODIFIED,
handle) == -1) {
- return -errno;
+ return UV__ERR(errno);
}
handle->fd = PORT_LOADED;
@@ -466,13 +466,13 @@ int uv_fs_event_start(uv_fs_event_t* handle,
int err;
if (uv__is_active(handle))
- return -EINVAL;
+ return UV_EINVAL;
first_run = 0;
if (handle->loop->fs_fd == -1) {
portfd = port_create();
if (portfd == -1)
- return -errno;
+ return UV__ERR(errno);
handle->loop->fs_fd = portfd;
first_run = 1;
}
@@ -525,7 +525,7 @@ void uv__fs_event_close(uv_fs_event_t* handle) {
#else /* !defined(PORT_SOURCE_FILE) */
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
@@ -533,12 +533,12 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv_fs_event_cb cb,
const char* filename,
unsigned int flags) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
int uv_fs_event_stop(uv_fs_event_t* handle) {
- return -ENOSYS;
+ return UV_ENOSYS;
}
@@ -556,10 +556,10 @@ int uv_resident_set_memory(size_t* rss) {
fd = open("/proc/self/psinfo", O_RDONLY);
if (fd == -1)
- return -errno;
+ return UV__ERR(errno);
/* FIXME(bnoordhuis) Handle EINTR. */
- err = -EINVAL;
+ err = UV_EINVAL;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
*rss = (size_t)psinfo.pr_rssize * 1024;
err = 0;
@@ -579,7 +579,7 @@ int uv_uptime(double* uptime) {
kc = kstat_open();
if (kc == NULL)
- return -EPERM;
+ return UV_EPERM;
ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc");
if (kstat_read(kc, ksp, NULL) == -1) {
@@ -603,7 +603,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
kc = kstat_open();
if (kc == NULL)
- return -EPERM;
+ return UV_EPERM;
/* Get count of cpus */
lookup_instance = 0;
@@ -614,7 +614,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
*cpu_infos = uv__malloc(lookup_instance * sizeof(**cpu_infos));
if (!(*cpu_infos)) {
kstat_close(kc);
- return -ENOMEM;
+ return UV_ENOMEM;
}
*count = lookup_instance;
@@ -696,7 +696,9 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
#ifdef SUNOS_NO_IFADDRS
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
- return -ENOSYS;
+ *count = 0;
+ *addresses = NULL;
+ return UV_ENOSYS;
}
#else /* SUNOS_NO_IFADDRS */
/*
@@ -709,13 +711,14 @@ static int uv__set_phys_addr(uv_interface_address_t* address,
struct sockaddr_dl* sa_addr;
int sockfd;
- int i;
+ size_t i;
struct arpreq arpreq;
/* This appears to only work as root */
sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
for (i = 0; i < sizeof(address->phys_addr); i++) {
+ /* Check that all bytes of phys_addr are zero. */
if (address->phys_addr[i] != 0)
return 0;
}
@@ -734,11 +737,11 @@ static int uv__set_phys_addr(uv_interface_address_t* address,
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
- return -errno;
+ return UV__ERR(errno);
if (ioctl(sockfd, SIOCGARP, (char*)&arpreq) == -1) {
uv__close(sockfd);
- return -errno;
+ return UV__ERR(errno);
}
memcpy(address->phys_addr, arpreq.arp_ha.sa_data, sizeof(address->phys_addr));
uv__close(sockfd);
@@ -751,7 +754,8 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent) {
return 1;
if (ent->ifa_addr == NULL)
return 1;
- if (ent->ifa_addr->sa_family == PF_PACKET)
+ if (ent->ifa_addr->sa_family != AF_INET &&
+ ent->ifa_addr->sa_family != AF_INET6)
return 1;
return 0;
}
@@ -760,12 +764,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
uv_interface_address_t* address;
struct ifaddrs* addrs;
struct ifaddrs* ent;
- int i;
-
- if (getifaddrs(&addrs))
- return -errno;
*count = 0;
+ *addresses = NULL;
+
+ if (getifaddrs(&addrs))
+ return UV__ERR(errno);
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
@@ -774,10 +778,15 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
+ if (*count == 0) {
+ freeifaddrs(addrs);
+ return 0;
+ }
+
*addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) {
freeifaddrs(addrs);
- return -ENOMEM;
+ return UV_ENOMEM;
}
address = *addresses;
diff --git a/Utilities/cmlibuv/src/unix/tcp.c b/Utilities/cmlibuv/src/unix/tcp.c
index c423dcb15..2982851dc 100644
--- a/Utilities/cmlibuv/src/unix/tcp.c
+++ b/Utilities/cmlibuv/src/unix/tcp.c
@@ -28,15 +28,12 @@
#include <errno.h>
-static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) {
+static int new_socket(uv_tcp_t* handle, int domain, unsigned long flags) {
+ struct sockaddr_storage saddr;
+ socklen_t slen;
int sockfd;
int err;
- if (domain == AF_UNSPEC || uv__stream_fd(handle) != -1) {
- handle->flags |= flags;
- return 0;
- }
-
err = uv__socket(domain, SOCK_STREAM, 0);
if (err < 0)
return err;
@@ -48,20 +45,82 @@ static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) {
return err;
}
+ if (flags & UV_HANDLE_BOUND) {
+ /* Bind this new socket to an arbitrary port */
+ slen = sizeof(saddr);
+ memset(&saddr, 0, sizeof(saddr));
+ if (getsockname(uv__stream_fd(handle), (struct sockaddr*) &saddr, &slen)) {
+ uv__close(sockfd);
+ return UV__ERR(errno);
+ }
+
+ if (bind(uv__stream_fd(handle), (struct sockaddr*) &saddr, slen)) {
+ uv__close(sockfd);
+ return UV__ERR(errno);
+ }
+ }
+
return 0;
}
+static int maybe_new_socket(uv_tcp_t* handle, int domain, unsigned long flags) {
+ struct sockaddr_storage saddr;
+ socklen_t slen;
+
+ if (domain == AF_UNSPEC) {
+ handle->flags |= flags;
+ return 0;
+ }
+
+ if (uv__stream_fd(handle) != -1) {
+
+ if (flags & UV_HANDLE_BOUND) {
+
+ if (handle->flags & UV_HANDLE_BOUND) {
+ /* It is already bound to a port. */
+ handle->flags |= flags;
+ return 0;
+ }
+
+ /* Query to see if tcp socket is bound. */
+ slen = sizeof(saddr);
+ memset(&saddr, 0, sizeof(saddr));
+ if (getsockname(uv__stream_fd(handle), (struct sockaddr*) &saddr, &slen))
+ return UV__ERR(errno);
+
+ if ((saddr.ss_family == AF_INET6 &&
+ ((struct sockaddr_in6*) &saddr)->sin6_port != 0) ||
+ (saddr.ss_family == AF_INET &&
+ ((struct sockaddr_in*) &saddr)->sin_port != 0)) {
+ /* Handle is already bound to a port. */
+ handle->flags |= flags;
+ return 0;
+ }
+
+ /* Bind to arbitrary port */
+ if (bind(uv__stream_fd(handle), (struct sockaddr*) &saddr, slen))
+ return UV__ERR(errno);
+ }
+
+ handle->flags |= flags;
+ return 0;
+ }
+
+ return new_socket(handle, domain, flags);
+}
+
+
int uv_tcp_init_ex(uv_loop_t* loop, uv_tcp_t* tcp, unsigned int flags) {
int domain;
/* Use the lower 8 bits for the domain */
domain = flags & 0xFF;
if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC)
- return -EINVAL;
+ return UV_EINVAL;
if (flags & ~0xFF)
- return -EINVAL;
+ return UV_EINVAL;
uv__stream_init(loop, (uv_stream_t*)tcp, UV_TCP);
@@ -95,18 +154,17 @@ int uv__tcp_bind(uv_tcp_t* tcp,
/* Cannot set IPv6-only mode on non-IPv6 socket. */
if ((flags & UV_TCP_IPV6ONLY) && addr->sa_family != AF_INET6)
- return -EINVAL;
+ return UV_EINVAL;
- err = maybe_new_socket(tcp,
- addr->sa_family,
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ err = maybe_new_socket(tcp, addr->sa_family, 0);
if (err)
return err;
on = 1;
if (setsockopt(tcp->io_watcher.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
- return -errno;
+ return UV__ERR(errno);
+#ifndef __OpenBSD__
#ifdef IPV6_V6ONLY
if (addr->sa_family == AF_INET6) {
on = (flags & UV_TCP_IPV6ONLY) != 0;
@@ -117,22 +175,23 @@ int uv__tcp_bind(uv_tcp_t* tcp,
sizeof on) == -1) {
#if defined(__MVS__)
if (errno == EOPNOTSUPP)
- return -EINVAL;
+ return UV_EINVAL;
#endif
- return -errno;
+ return UV__ERR(errno);
}
}
#endif
+#endif
errno = 0;
if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE) {
if (errno == EAFNOSUPPORT)
/* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
* socket created with AF_INET to an AF_INET6 address or vice versa. */
- return -EINVAL;
- return -errno;
+ return UV_EINVAL;
+ return UV__ERR(errno);
}
- tcp->delayed_error = -errno;
+ tcp->delayed_error = UV__ERR(errno);
tcp->flags |= UV_HANDLE_BOUND;
if (addr->sa_family == AF_INET6)
@@ -153,11 +212,11 @@ int uv__tcp_connect(uv_connect_t* req,
assert(handle->type == UV_TCP);
if (handle->connect_req != NULL)
- return -EALREADY; /* FIXME(bnoordhuis) -EINVAL or maybe -EBUSY. */
+ return UV_EALREADY; /* FIXME(bnoordhuis) UV_EINVAL or maybe UV_EBUSY. */
err = maybe_new_socket(handle,
addr->sa_family,
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
if (err)
return err;
@@ -181,9 +240,9 @@ int uv__tcp_connect(uv_connect_t* req,
* error. Solaris wants to report immediately--other unixes want to
* wait.
*/
- handle->delayed_error = -errno;
+ handle->delayed_error = UV__ERR(errno);
else
- return -errno;
+ return UV__ERR(errno);
}
uv__req_init(handle->loop, req, UV_CONNECT);
@@ -204,13 +263,16 @@ int uv__tcp_connect(uv_connect_t* req,
int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) {
int err;
+ if (uv__fd_exists(handle->loop, sock))
+ return UV_EEXIST;
+
err = uv__nonblock(sock, 1);
if (err)
return err;
return uv__stream_open((uv_stream_t*)handle,
sock,
- UV_STREAM_READABLE | UV_STREAM_WRITABLE);
+ UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
}
@@ -223,13 +285,13 @@ int uv_tcp_getsockname(const uv_tcp_t* handle,
return handle->delayed_error;
if (uv__stream_fd(handle) < 0)
- return -EINVAL; /* FIXME(bnoordhuis) -EBADF */
+ return UV_EINVAL; /* FIXME(bnoordhuis) UV_EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen;
if (getsockname(uv__stream_fd(handle), name, &socklen))
- return -errno;
+ return UV__ERR(errno);
*namelen = (int) socklen;
return 0;
@@ -245,13 +307,13 @@ int uv_tcp_getpeername(const uv_tcp_t* handle,
return handle->delayed_error;
if (uv__stream_fd(handle) < 0)
- return -EINVAL; /* FIXME(bnoordhuis) -EBADF */
+ return UV_EINVAL; /* FIXME(bnoordhuis) UV_EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen;
if (getpeername(uv__stream_fd(handle), name, &socklen))
- return -errno;
+ return UV__ERR(errno);
*namelen = (int) socklen;
return 0;
@@ -260,6 +322,7 @@ int uv_tcp_getpeername(const uv_tcp_t* handle,
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
static int single_accept = -1;
+ unsigned long flags;
int err;
if (tcp->delayed_error)
@@ -271,35 +334,22 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
}
if (single_accept)
- tcp->flags |= UV_TCP_SINGLE_ACCEPT;
-
- err = maybe_new_socket(tcp, AF_INET, UV_STREAM_READABLE);
- if (err)
- return err;
+ tcp->flags |= UV_HANDLE_TCP_SINGLE_ACCEPT;
-#ifdef __MVS__
+ flags = 0;
+#if defined(__MVS__)
/* on zOS the listen call does not bind automatically
if the socket is unbound. Hence the manual binding to
an arbitrary port is required to be done manually
*/
-
- if (!(tcp->flags & UV_HANDLE_BOUND)) {
- struct sockaddr_storage saddr;
- socklen_t slen = sizeof(saddr);
- memset(&saddr, 0, sizeof(saddr));
-
- if (getsockname(tcp->io_watcher.fd, (struct sockaddr*) &saddr, &slen))
- return -errno;
-
- if (bind(tcp->io_watcher.fd, (struct sockaddr*) &saddr, slen))
- return -errno;
-
- tcp->flags |= UV_HANDLE_BOUND;
- }
+ flags |= UV_HANDLE_BOUND;
#endif
+ err = maybe_new_socket(tcp, AF_INET, flags);
+ if (err)
+ return err;
if (listen(tcp->io_watcher.fd, backlog))
- return -errno;
+ return UV__ERR(errno);
tcp->connection_cb = cb;
tcp->flags |= UV_HANDLE_BOUND;
@@ -314,18 +364,18 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
int uv__tcp_nodelay(int fd, int on) {
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)))
- return -errno;
+ return UV__ERR(errno);
return 0;
}
int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
- return -errno;
+ return UV__ERR(errno);
#ifdef TCP_KEEPIDLE
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
- return -errno;
+ return UV__ERR(errno);
#endif
/* Solaris/SmartOS, if you don't support keep-alive,
@@ -334,7 +384,7 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
/* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */
#if defined(TCP_KEEPALIVE) && !defined(__sun)
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
- return -errno;
+ return UV__ERR(errno);
#endif
return 0;
@@ -351,9 +401,9 @@ int uv_tcp_nodelay(uv_tcp_t* handle, int on) {
}
if (on)
- handle->flags |= UV_TCP_NODELAY;
+ handle->flags |= UV_HANDLE_TCP_NODELAY;
else
- handle->flags &= ~UV_TCP_NODELAY;
+ handle->flags &= ~UV_HANDLE_TCP_NODELAY;
return 0;
}
@@ -369,9 +419,9 @@ int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int delay) {
}
if (on)
- handle->flags |= UV_TCP_KEEPALIVE;
+ handle->flags |= UV_HANDLE_TCP_KEEPALIVE;
else
- handle->flags &= ~UV_TCP_KEEPALIVE;
+ handle->flags &= ~UV_HANDLE_TCP_KEEPALIVE;
/* TODO Store delay if uv__stream_fd(handle) == -1 but don't want to enlarge
* uv_tcp_t with an int that's almost never used...
@@ -383,9 +433,9 @@ int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int delay) {
int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) {
if (enable)
- handle->flags &= ~UV_TCP_SINGLE_ACCEPT;
+ handle->flags &= ~UV_HANDLE_TCP_SINGLE_ACCEPT;
else
- handle->flags |= UV_TCP_SINGLE_ACCEPT;
+ handle->flags |= UV_HANDLE_TCP_SINGLE_ACCEPT;
return 0;
}
diff --git a/Utilities/cmlibuv/src/unix/thread.c b/Utilities/cmlibuv/src/unix/thread.c
index a9b5e4c02..29004707a 100644
--- a/Utilities/cmlibuv/src/unix/thread.c
+++ b/Utilities/cmlibuv/src/unix/thread.c
@@ -37,47 +37,185 @@
#include <sys/sem.h>
#endif
+#ifdef __GLIBC__
+#include <gnu/libc-version.h> /* gnu_get_libc_version() */
+#endif
+
#undef NANOSEC
#define NANOSEC ((uint64_t) 1e9)
-
-int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
- int err;
- pthread_attr_t* attr;
-#if defined(__APPLE__)
- pthread_attr_t attr_storage;
- struct rlimit lim;
+#if defined(PTHREAD_BARRIER_SERIAL_THREAD)
+STATIC_ASSERT(sizeof(uv_barrier_t) == sizeof(pthread_barrier_t));
#endif
- /* On OSX threads other than the main thread are created with a reduced stack
- * size by default, adjust it to RLIMIT_STACK.
- */
-#if defined(__APPLE__)
- if (getrlimit(RLIMIT_STACK, &lim))
+/* Note: guard clauses should match uv_barrier_t's in include/uv/uv-unix.h. */
+#if defined(_AIX) || !defined(PTHREAD_BARRIER_SERIAL_THREAD)
+int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
+ struct _uv_barrier* b;
+ int rc;
+
+ if (barrier == NULL || count == 0)
+ return UV_EINVAL;
+
+ b = uv__malloc(sizeof(*b));
+ if (b == NULL)
+ return UV_ENOMEM;
+
+ b->in = 0;
+ b->out = 0;
+ b->threshold = count;
+
+ rc = uv_mutex_init(&b->mutex);
+ if (rc != 0)
+ goto error2;
+
+ rc = uv_cond_init(&b->cond);
+ if (rc != 0)
+ goto error;
+
+ barrier->b = b;
+ return 0;
+
+error:
+ uv_mutex_destroy(&b->mutex);
+error2:
+ uv__free(b);
+ return rc;
+}
+
+
+int uv_barrier_wait(uv_barrier_t* barrier) {
+ struct _uv_barrier* b;
+ int last;
+
+ if (barrier == NULL || barrier->b == NULL)
+ return UV_EINVAL;
+
+ b = barrier->b;
+ uv_mutex_lock(&b->mutex);
+
+ if (++b->in == b->threshold) {
+ b->in = 0;
+ b->out = b->threshold;
+ uv_cond_signal(&b->cond);
+ } else {
+ do
+ uv_cond_wait(&b->cond, &b->mutex);
+ while (b->in != 0);
+ }
+
+ last = (--b->out == 0);
+ if (!last)
+ uv_cond_signal(&b->cond); /* Not needed for last thread. */
+
+ uv_mutex_unlock(&b->mutex);
+ return last;
+}
+
+
+void uv_barrier_destroy(uv_barrier_t* barrier) {
+ struct _uv_barrier* b;
+
+ b = barrier->b;
+ uv_mutex_lock(&b->mutex);
+
+ assert(b->in == 0);
+ assert(b->out == 0);
+
+ if (b->in != 0 || b->out != 0)
+ abort();
+
+ uv_mutex_unlock(&b->mutex);
+ uv_mutex_destroy(&b->mutex);
+ uv_cond_destroy(&b->cond);
+
+ uv__free(barrier->b);
+ barrier->b = NULL;
+}
+
+#else
+
+int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
+ return UV__ERR(pthread_barrier_init(barrier, NULL, count));
+}
+
+
+int uv_barrier_wait(uv_barrier_t* barrier) {
+ int rc;
+
+ rc = pthread_barrier_wait(barrier);
+ if (rc != 0)
+ if (rc != PTHREAD_BARRIER_SERIAL_THREAD)
+ abort();
+
+ return rc == PTHREAD_BARRIER_SERIAL_THREAD;
+}
+
+
+void uv_barrier_destroy(uv_barrier_t* barrier) {
+ if (pthread_barrier_destroy(barrier))
abort();
+}
- attr = &attr_storage;
- if (pthread_attr_init(attr))
+#endif
+
+
+/* On MacOS, threads other than the main thread are created with a reduced
+ * stack size by default. Adjust to RLIMIT_STACK aligned to the page size.
+ *
+ * On Linux, threads created by musl have a much smaller stack than threads
+ * created by glibc (80 vs. 2048 or 4096 kB.) Follow glibc for consistency.
+ */
+static size_t thread_stack_size(void) {
+#if defined(__APPLE__) || defined(__linux__)
+ struct rlimit lim;
+
+ if (getrlimit(RLIMIT_STACK, &lim))
abort();
if (lim.rlim_cur != RLIM_INFINITY) {
/* pthread_attr_setstacksize() expects page-aligned values. */
lim.rlim_cur -= lim.rlim_cur % (rlim_t) getpagesize();
-
if (lim.rlim_cur >= PTHREAD_STACK_MIN)
- if (pthread_attr_setstacksize(attr, lim.rlim_cur))
- abort();
+ return lim.rlim_cur;
}
+#endif
+
+#if !defined(__linux__)
+ return 0;
+#elif defined(__PPC__) || defined(__ppc__) || defined(__powerpc__)
+ return 4 << 20; /* glibc default. */
#else
- attr = NULL;
+ return 2 << 20; /* glibc default. */
#endif
+}
+
+
+int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
+ int err;
+ size_t stack_size;
+ pthread_attr_t* attr;
+ pthread_attr_t attr_storage;
+
+ attr = NULL;
+ stack_size = thread_stack_size();
+
+ if (stack_size > 0) {
+ attr = &attr_storage;
+
+ if (pthread_attr_init(attr))
+ abort();
+
+ if (pthread_attr_setstacksize(attr, stack_size))
+ abort();
+ }
err = pthread_create(tid, attr, (void*(*)(void*)) entry, arg);
if (attr != NULL)
pthread_attr_destroy(attr);
- return -err;
+ return UV__ERR(err);
}
@@ -86,7 +224,7 @@ uv_thread_t uv_thread_self(void) {
}
int uv_thread_join(uv_thread_t *tid) {
- return -pthread_join(*tid, NULL);
+ return UV__ERR(pthread_join(*tid, NULL));
}
@@ -97,7 +235,7 @@ int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) {
int uv_mutex_init(uv_mutex_t* mutex) {
#if defined(NDEBUG) || !defined(PTHREAD_MUTEX_ERRORCHECK)
- return -pthread_mutex_init(mutex, NULL);
+ return UV__ERR(pthread_mutex_init(mutex, NULL));
#else
pthread_mutexattr_t attr;
int err;
@@ -113,11 +251,30 @@ int uv_mutex_init(uv_mutex_t* mutex) {
if (pthread_mutexattr_destroy(&attr))
abort();
- return -err;
+ return UV__ERR(err);
#endif
}
+int uv_mutex_init_recursive(uv_mutex_t* mutex) {
+ pthread_mutexattr_t attr;
+ int err;
+
+ if (pthread_mutexattr_init(&attr))
+ abort();
+
+ if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE))
+ abort();
+
+ err = pthread_mutex_init(mutex, &attr);
+
+ if (pthread_mutexattr_destroy(&attr))
+ abort();
+
+ return UV__ERR(err);
+}
+
+
void uv_mutex_destroy(uv_mutex_t* mutex) {
if (pthread_mutex_destroy(mutex))
abort();
@@ -137,7 +294,7 @@ int uv_mutex_trylock(uv_mutex_t* mutex) {
if (err) {
if (err != EBUSY && err != EAGAIN)
abort();
- return -EBUSY;
+ return UV_EBUSY;
}
return 0;
@@ -151,7 +308,7 @@ void uv_mutex_unlock(uv_mutex_t* mutex) {
int uv_rwlock_init(uv_rwlock_t* rwlock) {
- return -pthread_rwlock_init(rwlock, NULL);
+ return UV__ERR(pthread_rwlock_init(rwlock, NULL));
}
@@ -174,7 +331,7 @@ int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock) {
if (err) {
if (err != EBUSY && err != EAGAIN)
abort();
- return -EBUSY;
+ return UV_EBUSY;
}
return 0;
@@ -200,7 +357,7 @@ int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) {
if (err) {
if (err != EBUSY && err != EAGAIN)
abort();
- return -EBUSY;
+ return UV_EBUSY;
}
return 0;
@@ -227,12 +384,12 @@ int uv_sem_init(uv_sem_t* sem, unsigned int value) {
if (err == KERN_SUCCESS)
return 0;
if (err == KERN_INVALID_ARGUMENT)
- return -EINVAL;
+ return UV_EINVAL;
if (err == KERN_RESOURCE_SHORTAGE)
- return -ENOMEM;
+ return UV_ENOMEM;
abort();
- return -EINVAL; /* Satisfy the compiler. */
+ return UV_EINVAL; /* Satisfy the compiler. */
}
@@ -271,113 +428,151 @@ int uv_sem_trywait(uv_sem_t* sem) {
if (err == KERN_SUCCESS)
return 0;
if (err == KERN_OPERATION_TIMED_OUT)
- return -EAGAIN;
+ return UV_EAGAIN;
abort();
- return -EINVAL; /* Satisfy the compiler. */
+ return UV_EINVAL; /* Satisfy the compiler. */
+}
+
+#else /* !(defined(__APPLE__) && defined(__MACH__)) */
+
+#ifdef __GLIBC__
+
+/* Hack around https://sourceware.org/bugzilla/show_bug.cgi?id=12674
+ * by providing a custom implementation for glibc < 2.21 in terms of other
+ * concurrency primitives.
+ * Refs: https://github.com/nodejs/node/issues/19903 */
+
+/* To preserve ABI compatibility, we treat the uv_sem_t as storage for
+ * a pointer to the actual struct we're using underneath. */
+
+static uv_once_t glibc_version_check_once = UV_ONCE_INIT;
+static int platform_needs_custom_semaphore = 0;
+
+static void glibc_version_check(void) {
+ const char* version = gnu_get_libc_version();
+ platform_needs_custom_semaphore =
+ version[0] == '2' && version[1] == '.' &&
+ atoi(version + 2) < 21;
}
#elif defined(__MVS__)
-int uv_sem_init(uv_sem_t* sem, unsigned int value) {
- uv_sem_t semid;
- struct sembuf buf;
+#define platform_needs_custom_semaphore 1
+
+#else /* !defined(__GLIBC__) && !defined(__MVS__) */
+
+#define platform_needs_custom_semaphore 0
+
+#endif
+
+typedef struct uv_semaphore_s {
+ uv_mutex_t mutex;
+ uv_cond_t cond;
+ unsigned int value;
+} uv_semaphore_t;
+
+#if defined(__GLIBC__) || platform_needs_custom_semaphore
+STATIC_ASSERT(sizeof(uv_sem_t) >= sizeof(uv_semaphore_t*));
+#endif
+
+static int uv__custom_sem_init(uv_sem_t* sem_, unsigned int value) {
int err;
+ uv_semaphore_t* sem;
- buf.sem_num = 0;
- buf.sem_op = value;
- buf.sem_flg = 0;
+ sem = uv__malloc(sizeof(*sem));
+ if (sem == NULL)
+ return UV_ENOMEM;
- semid = semget(IPC_PRIVATE, 1, S_IRUSR | S_IWUSR);
- if (semid == -1)
- return -errno;
+ if ((err = uv_mutex_init(&sem->mutex)) != 0) {
+ uv__free(sem);
+ return err;
+ }
- if (-1 == semop(semid, &buf, 1)) {
- err = errno;
- if (-1 == semctl(*sem, 0, IPC_RMID))
- abort();
- return -err;
+ if ((err = uv_cond_init(&sem->cond)) != 0) {
+ uv_mutex_destroy(&sem->mutex);
+ uv__free(sem);
+ return err;
}
- *sem = semid;
+ sem->value = value;
+ *(uv_semaphore_t**)sem_ = sem;
return 0;
}
-void uv_sem_destroy(uv_sem_t* sem) {
- if (-1 == semctl(*sem, 0, IPC_RMID))
- abort();
+
+static void uv__custom_sem_destroy(uv_sem_t* sem_) {
+ uv_semaphore_t* sem;
+
+ sem = *(uv_semaphore_t**)sem_;
+ uv_cond_destroy(&sem->cond);
+ uv_mutex_destroy(&sem->mutex);
+ uv__free(sem);
}
-void uv_sem_post(uv_sem_t* sem) {
- struct sembuf buf;
- buf.sem_num = 0;
- buf.sem_op = 1;
- buf.sem_flg = 0;
+static void uv__custom_sem_post(uv_sem_t* sem_) {
+ uv_semaphore_t* sem;
- if (-1 == semop(*sem, &buf, 1))
- abort();
+ sem = *(uv_semaphore_t**)sem_;
+ uv_mutex_lock(&sem->mutex);
+ sem->value++;
+ if (sem->value == 1)
+ uv_cond_signal(&sem->cond);
+ uv_mutex_unlock(&sem->mutex);
}
-void uv_sem_wait(uv_sem_t* sem) {
- struct sembuf buf;
- int op_status;
-
- buf.sem_num = 0;
- buf.sem_op = -1;
- buf.sem_flg = 0;
- do
- op_status = semop(*sem, &buf, 1);
- while (op_status == -1 && errno == EINTR);
+static void uv__custom_sem_wait(uv_sem_t* sem_) {
+ uv_semaphore_t* sem;
- if (op_status)
- abort();
+ sem = *(uv_semaphore_t**)sem_;
+ uv_mutex_lock(&sem->mutex);
+ while (sem->value == 0)
+ uv_cond_wait(&sem->cond, &sem->mutex);
+ sem->value--;
+ uv_mutex_unlock(&sem->mutex);
}
-int uv_sem_trywait(uv_sem_t* sem) {
- struct sembuf buf;
- int op_status;
- buf.sem_num = 0;
- buf.sem_op = -1;
- buf.sem_flg = IPC_NOWAIT;
+static int uv__custom_sem_trywait(uv_sem_t* sem_) {
+ uv_semaphore_t* sem;
- do
- op_status = semop(*sem, &buf, 1);
- while (op_status == -1 && errno == EINTR);
+ sem = *(uv_semaphore_t**)sem_;
+ if (uv_mutex_trylock(&sem->mutex) != 0)
+ return UV_EAGAIN;
- if (op_status) {
- if (errno == EAGAIN)
- return -EAGAIN;
- abort();
+ if (sem->value == 0) {
+ uv_mutex_unlock(&sem->mutex);
+ return UV_EAGAIN;
}
+ sem->value--;
+ uv_mutex_unlock(&sem->mutex);
+
return 0;
}
-#else /* !(defined(__APPLE__) && defined(__MACH__)) */
-
-int uv_sem_init(uv_sem_t* sem, unsigned int value) {
+static int uv__sem_init(uv_sem_t* sem, unsigned int value) {
if (sem_init(sem, 0, value))
- return -errno;
+ return UV__ERR(errno);
return 0;
}
-void uv_sem_destroy(uv_sem_t* sem) {
+static void uv__sem_destroy(uv_sem_t* sem) {
if (sem_destroy(sem))
abort();
}
-void uv_sem_post(uv_sem_t* sem) {
+static void uv__sem_post(uv_sem_t* sem) {
if (sem_post(sem))
abort();
}
-void uv_sem_wait(uv_sem_t* sem) {
+static void uv__sem_wait(uv_sem_t* sem) {
int r;
do
@@ -389,7 +584,7 @@ void uv_sem_wait(uv_sem_t* sem) {
}
-int uv_sem_trywait(uv_sem_t* sem) {
+static int uv__sem_trywait(uv_sem_t* sem) {
int r;
do
@@ -398,20 +593,63 @@ int uv_sem_trywait(uv_sem_t* sem) {
if (r) {
if (errno == EAGAIN)
- return -EAGAIN;
+ return UV_EAGAIN;
abort();
}
return 0;
}
+int uv_sem_init(uv_sem_t* sem, unsigned int value) {
+#ifdef __GLIBC__
+ uv_once(&glibc_version_check_once, glibc_version_check);
+#endif
+
+ if (platform_needs_custom_semaphore)
+ return uv__custom_sem_init(sem, value);
+ else
+ return uv__sem_init(sem, value);
+}
+
+
+void uv_sem_destroy(uv_sem_t* sem) {
+ if (platform_needs_custom_semaphore)
+ uv__custom_sem_destroy(sem);
+ else
+ uv__sem_destroy(sem);
+}
+
+
+void uv_sem_post(uv_sem_t* sem) {
+ if (platform_needs_custom_semaphore)
+ uv__custom_sem_post(sem);
+ else
+ uv__sem_post(sem);
+}
+
+
+void uv_sem_wait(uv_sem_t* sem) {
+ if (platform_needs_custom_semaphore)
+ uv__custom_sem_wait(sem);
+ else
+ uv__sem_wait(sem);
+}
+
+
+int uv_sem_trywait(uv_sem_t* sem) {
+ if (platform_needs_custom_semaphore)
+ return uv__custom_sem_trywait(sem);
+ else
+ return uv__sem_trywait(sem);
+}
+
#endif /* defined(__APPLE__) && defined(__MACH__) */
#if defined(__APPLE__) && defined(__MACH__) || defined(__MVS__)
int uv_cond_init(uv_cond_t* cond) {
- return -pthread_cond_init(cond, NULL);
+ return UV__ERR(pthread_cond_init(cond, NULL));
}
#else /* !(defined(__APPLE__) && defined(__MACH__)) */
@@ -422,9 +660,9 @@ int uv_cond_init(uv_cond_t* cond) {
err = pthread_condattr_init(&attr);
if (err)
- return -err;
+ return UV__ERR(err);
-#if !(defined(__ANDROID__) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
+#if !(defined(__ANDROID_API__) && __ANDROID_API__ < 21)
err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (err)
goto error2;
@@ -444,7 +682,7 @@ error:
pthread_cond_destroy(cond);
error2:
pthread_condattr_destroy(&attr);
- return -err;
+ return UV__ERR(err);
}
#endif /* defined(__APPLE__) && defined(__MACH__) */
@@ -502,16 +740,26 @@ void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
int r;
struct timespec ts;
+#if defined(__MVS__)
+ struct timeval tv;
+#endif
#if defined(__APPLE__) && defined(__MACH__)
ts.tv_sec = timeout / NANOSEC;
ts.tv_nsec = timeout % NANOSEC;
r = pthread_cond_timedwait_relative_np(cond, mutex, &ts);
#else
+#if defined(__MVS__)
+ if (gettimeofday(&tv, NULL))
+ abort();
+ timeout += tv.tv_sec * NANOSEC + tv.tv_usec * 1e3;
+#else
timeout += uv__hrtime(UV_CLOCK_PRECISE);
+#endif
ts.tv_sec = timeout / NANOSEC;
ts.tv_nsec = timeout % NANOSEC;
-#if defined(__ANDROID__) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC)
+#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
+
/*
* The bionic pthread implementation doesn't support CLOCK_MONOTONIC,
* but has this alternative function instead.
@@ -519,7 +767,7 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
r = pthread_cond_timedwait_monotonic_np(cond, mutex, &ts);
#else
r = pthread_cond_timedwait(cond, mutex, &ts);
-#endif /* __ANDROID__ */
+#endif /* __ANDROID_API__ */
#endif
@@ -527,34 +775,15 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
return 0;
if (r == ETIMEDOUT)
- return -ETIMEDOUT;
+ return UV_ETIMEDOUT;
abort();
- return -EINVAL; /* Satisfy the compiler. */
-}
-
-
-int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
- return -pthread_barrier_init(barrier, NULL, count);
-}
-
-
-void uv_barrier_destroy(uv_barrier_t* barrier) {
- if (pthread_barrier_destroy(barrier))
- abort();
-}
-
-
-int uv_barrier_wait(uv_barrier_t* barrier) {
- int r = pthread_barrier_wait(barrier);
- if (r && r != PTHREAD_BARRIER_SERIAL_THREAD)
- abort();
- return r == PTHREAD_BARRIER_SERIAL_THREAD;
+ return UV_EINVAL; /* Satisfy the compiler. */
}
int uv_key_create(uv_key_t* key) {
- return -pthread_key_create(key, NULL);
+ return UV__ERR(pthread_key_create(key, NULL));
}
diff --git a/Utilities/cmlibuv/src/unix/tty.c b/Utilities/cmlibuv/src/unix/tty.c
index ae1018fc4..b8bc2838d 100644
--- a/Utilities/cmlibuv/src/unix/tty.c
+++ b/Utilities/cmlibuv/src/unix/tty.c
@@ -48,6 +48,42 @@ static int uv__tty_is_slave(const int fd) {
char dummy[256];
result = ioctl(fd, TIOCPTYGNAME, &dummy) != 0;
+#elif defined(__NetBSD__)
+ /*
+ * NetBSD as an extension returns with ptsname(3) and ptsname_r(3) the slave
+ * device name for both descriptors, the master one and slave one.
+ *
+ * Implement function to compare major device number with pts devices.
+ *
+ * The major numbers are machine-dependent, on NetBSD/amd64 they are
+ * respectively:
+ * - master tty: ptc - major 6
+ * - slave tty: pts - major 5
+ */
+
+ struct stat sb;
+ /* Lookup device's major for the pts driver and cache it. */
+ static devmajor_t pts = NODEVMAJOR;
+
+ if (pts == NODEVMAJOR) {
+ pts = getdevmajor("pts", S_IFCHR);
+ if (pts == NODEVMAJOR)
+ abort();
+ }
+
+ /* Lookup stat structure behind the file descriptor. */
+ if (fstat(fd, &sb) != 0)
+ abort();
+
+ /* Assert character device. */
+ if (!S_ISCHR(sb.st_mode))
+ abort();
+
+ /* Assert valid major. */
+ if (major(sb.st_rdev) == NODEVMAJOR)
+ abort();
+
+ result = (pts == major(sb.st_rdev));
#else
/* Fallback to ptsname
*/
@@ -56,13 +92,15 @@ static int uv__tty_is_slave(const int fd) {
return result;
}
-int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
+int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int unused) {
uv_handle_type type;
int flags = 0;
int newfd = -1;
int r;
int saved_flags;
+ int mode;
char path[256];
+ (void)unused; /* deprecated parameter is no longer needed */
/* File descriptors that refer to files cannot be monitored with epoll.
* That restriction also applies to character devices like /dev/random
@@ -70,7 +108,16 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
*/
type = uv_guess_handle(fd);
if (type == UV_FILE || type == UV_UNKNOWN_HANDLE)
- return -EINVAL;
+ return UV_EINVAL;
+
+ /* Save the fd flags in case we need to restore them due to an error. */
+ do
+ saved_flags = fcntl(fd, F_GETFL);
+ while (saved_flags == -1 && errno == EINTR);
+
+ if (saved_flags == -1)
+ return UV__ERR(errno);
+ mode = saved_flags & O_ACCMODE;
/* Reopen the file descriptor when it refers to a tty. This lets us put the
* tty in non-blocking mode without affecting other processes that share it
@@ -89,21 +136,21 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
* slave device.
*/
if (uv__tty_is_slave(fd) && ttyname_r(fd, path, sizeof(path)) == 0)
- r = uv__open_cloexec(path, O_RDWR);
+ r = uv__open_cloexec(path, mode);
else
r = -1;
if (r < 0) {
/* fallback to using blocking writes */
- if (!readable)
- flags |= UV_STREAM_BLOCKING;
+ if (mode != O_RDONLY)
+ flags |= UV_HANDLE_BLOCKING_WRITES;
goto skip;
}
newfd = r;
r = uv__dup2_cloexec(newfd, fd);
- if (r < 0 && r != -EINVAL) {
+ if (r < 0 && r != UV_EINVAL) {
/* EINVAL means newfd == fd which could conceivably happen if another
* thread called close(fd) between our calls to isatty() and open().
* That's a rather unlikely event but let's handle it anyway.
@@ -115,22 +162,6 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
fd = newfd;
}
-#if defined(__APPLE__)
- /* Save the fd flags in case we need to restore them due to an error. */
- do
- saved_flags = fcntl(fd, F_GETFL);
- while (saved_flags == -1 && errno == EINTR);
-
- if (saved_flags == -1) {
- if (newfd != -1)
- uv__close(newfd);
- return -errno;
- }
-#endif
-
- /* Pacify the compiler. */
- (void) &saved_flags;
-
skip:
uv__stream_init(loop, (uv_stream_t*) tty, UV_TTY);
@@ -138,7 +169,7 @@ skip:
* the handle queue, since it was added by uv__handle_init in uv_stream_init.
*/
- if (!(flags & UV_STREAM_BLOCKING))
+ if (!(flags & UV_HANDLE_BLOCKING_WRITES))
uv__nonblock(fd, 1);
#if defined(__APPLE__)
@@ -155,10 +186,10 @@ skip:
}
#endif
- if (readable)
- flags |= UV_STREAM_READABLE;
- else
- flags |= UV_STREAM_WRITABLE;
+ if (mode != O_WRONLY)
+ flags |= UV_HANDLE_READABLE;
+ if (mode != O_RDONLY)
+ flags |= UV_HANDLE_WRITABLE;
uv__stream_open((uv_stream_t*) tty, fd, flags);
tty->mode = UV_TTY_MODE_NORMAL;
@@ -195,7 +226,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
fd = uv__stream_fd(tty);
if (tty->mode == UV_TTY_MODE_NORMAL && mode != UV_TTY_MODE_NORMAL) {
if (tcgetattr(fd, &tty->orig_termios))
- return -errno;
+ return UV__ERR(errno);
/* This is used for uv_tty_reset_mode() */
uv_spinlock_lock(&termios_spinlock);
@@ -225,7 +256,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
/* Apply changes after draining */
if (tcsetattr(fd, TCSADRAIN, &tmp))
- return -errno;
+ return UV__ERR(errno);
tty->mode = mode;
return 0;
@@ -241,7 +272,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
while (err == -1 && errno == EINTR);
if (err == -1)
- return -errno;
+ return UV__ERR(errno);
*width = ws.ws_col;
*height = ws.ws_row;
@@ -319,12 +350,12 @@ int uv_tty_reset_mode(void) {
saved_errno = errno;
if (!uv_spinlock_trylock(&termios_spinlock))
- return -EBUSY; /* In uv_tty_set_mode(). */
+ return UV_EBUSY; /* In uv_tty_set_mode(). */
err = 0;
if (orig_termios_fd != -1)
if (tcsetattr(orig_termios_fd, TCSANOW, &orig_termios))
- err = -errno;
+ err = UV__ERR(errno);
uv_spinlock_unlock(&termios_spinlock);
errno = saved_errno;
diff --git a/Utilities/cmlibuv/src/unix/udp.c b/Utilities/cmlibuv/src/unix/udp.c
index c556325de..ec337ec8b 100644
--- a/Utilities/cmlibuv/src/unix/udp.c
+++ b/Utilities/cmlibuv/src/unix/udp.c
@@ -72,7 +72,7 @@ void uv__udp_finish_close(uv_udp_t* handle) {
QUEUE_REMOVE(q);
req = QUEUE_DATA(q, uv_udp_send_t, queue);
- req->status = -ECANCELED;
+ req->status = UV_ECANCELED;
QUEUE_INSERT_TAIL(&handle->write_completed_queue, &req->queue);
}
@@ -92,8 +92,8 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
uv_udp_send_t* req;
QUEUE* q;
- assert(!(handle->flags & UV_UDP_PROCESSING));
- handle->flags |= UV_UDP_PROCESSING;
+ assert(!(handle->flags & UV_HANDLE_UDP_PROCESSING));
+ handle->flags |= UV_HANDLE_UDP_PROCESSING;
while (!QUEUE_EMPTY(&handle->write_completed_queue)) {
q = QUEUE_HEAD(&handle->write_completed_queue);
@@ -128,7 +128,7 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
uv__handle_stop(handle);
}
- handle->flags &= ~UV_UDP_PROCESSING;
+ handle->flags &= ~UV_HANDLE_UDP_PROCESSING;
}
@@ -189,7 +189,7 @@ static void uv__udp_recvmsg(uv_udp_t* handle) {
if (errno == EAGAIN || errno == EWOULDBLOCK)
handle->recv_cb(handle, 0, &buf, NULL, 0);
else
- handle->recv_cb(handle, -errno, &buf, NULL, 0);
+ handle->recv_cb(handle, UV__ERR(errno), &buf, NULL, 0);
}
else {
const struct sockaddr *addr;
@@ -237,10 +237,12 @@ static void uv__udp_sendmsg(uv_udp_t* handle) {
size = sendmsg(handle->io_watcher.fd, &h, 0);
} while (size == -1 && errno == EINTR);
- if (size == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
- break;
+ if (size == -1) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS)
+ break;
+ }
- req->status = (size == -1 ? -errno : size);
+ req->status = (size == -1 ? UV__ERR(errno) : size);
/* Sending a datagram is an atomic operation: either all data
* is written or nothing is (and EMSGSIZE is raised). That is
@@ -268,11 +270,11 @@ static int uv__set_reuse(int fd) {
#if defined(SO_REUSEPORT) && !defined(__linux__)
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)))
- return -errno;
+ return UV__ERR(errno);
#else
yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)))
- return -errno;
+ return UV__ERR(errno);
#endif
return 0;
@@ -289,11 +291,11 @@ int uv__udp_bind(uv_udp_t* handle,
/* Check for bad flags. */
if (flags & ~(UV_UDP_IPV6ONLY | UV_UDP_REUSEADDR))
- return -EINVAL;
+ return UV_EINVAL;
/* Cannot set IPv6-only mode on non-IPv6 socket. */
if ((flags & UV_UDP_IPV6ONLY) && addr->sa_family != AF_INET6)
- return -EINVAL;
+ return UV_EINVAL;
fd = handle->io_watcher.fd;
if (fd == -1) {
@@ -314,21 +316,21 @@ int uv__udp_bind(uv_udp_t* handle,
#ifdef IPV6_V6ONLY
yes = 1;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) {
- err = -errno;
+ err = UV__ERR(errno);
return err;
}
#else
- err = -ENOTSUP;
+ err = UV_ENOTSUP;
return err;
#endif
}
if (bind(fd, addr, addrlen)) {
- err = -errno;
+ err = UV__ERR(errno);
if (errno == EAFNOSUPPORT)
/* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
* socket created with AF_INET to an AF_INET6 address or vice versa. */
- err = -EINVAL;
+ err = UV_EINVAL;
return err;
}
@@ -416,7 +418,7 @@ int uv__udp_send(uv_udp_send_t* req,
if (req->bufs == NULL) {
uv__req_unregister(handle->loop, req);
- return -ENOMEM;
+ return UV_ENOMEM;
}
memcpy(req->bufs, bufs, nbufs * sizeof(bufs[0]));
@@ -425,7 +427,7 @@ int uv__udp_send(uv_udp_send_t* req,
QUEUE_INSERT_TAIL(&handle->write_queue, &req->queue);
uv__handle_start(handle);
- if (empty_queue && !(handle->flags & UV_UDP_PROCESSING)) {
+ if (empty_queue && !(handle->flags & UV_HANDLE_UDP_PROCESSING)) {
uv__udp_sendmsg(handle);
/* `uv__udp_sendmsg` may not be able to do non-blocking write straight
@@ -455,7 +457,7 @@ int uv__udp_try_send(uv_udp_t* handle,
/* already sending a message */
if (handle->send_queue_count != 0)
- return -EAGAIN;
+ return UV_EAGAIN;
err = uv__udp_maybe_deferred_bind(handle, addr->sa_family, 0);
if (err)
@@ -472,10 +474,10 @@ int uv__udp_try_send(uv_udp_t* handle,
} while (size == -1 && errno == EINTR);
if (size == -1) {
- if (errno == EAGAIN || errno == EWOULDBLOCK)
- return -EAGAIN;
+ if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS)
+ return UV_EAGAIN;
else
- return -errno;
+ return UV__ERR(errno);
}
return size;
@@ -510,7 +512,7 @@ static int uv__udp_set_membership4(uv_udp_t* handle,
optname = IP_DROP_MEMBERSHIP;
break;
default:
- return -EINVAL;
+ return UV_EINVAL;
}
if (setsockopt(handle->io_watcher.fd,
@@ -520,9 +522,9 @@ static int uv__udp_set_membership4(uv_udp_t* handle,
sizeof(mreq))) {
#if defined(__MVS__)
if (errno == ENXIO)
- return -ENODEV;
+ return UV_ENODEV;
#endif
- return -errno;
+ return UV__ERR(errno);
}
return 0;
@@ -541,7 +543,7 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
if (interface_addr) {
if (uv_ip6_addr(interface_addr, 0, &addr6))
- return -EINVAL;
+ return UV_EINVAL;
mreq.ipv6mr_interface = addr6.sin6_scope_id;
} else {
mreq.ipv6mr_interface = 0;
@@ -557,7 +559,7 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
optname = IPV6_DROP_MEMBERSHIP;
break;
default:
- return -EINVAL;
+ return UV_EINVAL;
}
if (setsockopt(handle->io_watcher.fd,
@@ -567,9 +569,9 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
sizeof(mreq))) {
#if defined(__MVS__)
if (errno == ENXIO)
- return -ENODEV;
+ return UV_ENODEV;
#endif
- return -errno;
+ return UV__ERR(errno);
}
return 0;
@@ -584,10 +586,10 @@ int uv_udp_init_ex(uv_loop_t* loop, uv_udp_t* handle, unsigned int flags) {
/* Use the lower 8 bits for the domain */
domain = flags & 0xFF;
if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC)
- return -EINVAL;
+ return UV_EINVAL;
if (flags & ~0xFF)
- return -EINVAL;
+ return UV_EINVAL;
if (domain != AF_UNSPEC) {
err = uv__socket(domain, SOCK_DGRAM, 0);
@@ -620,7 +622,10 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
/* Check for already active socket. */
if (handle->io_watcher.fd != -1)
- return -EBUSY;
+ return UV_EBUSY;
+
+ if (uv__fd_exists(handle->loop, sock))
+ return UV_EEXIST;
err = uv__nonblock(sock, 1);
if (err)
@@ -654,7 +659,7 @@ int uv_udp_set_membership(uv_udp_t* handle,
return err;
return uv__udp_set_membership6(handle, &addr6, interface_addr, membership);
} else {
- return -EINVAL;
+ return UV_EINVAL;
}
}
@@ -678,7 +683,7 @@ static int uv__setsockopt(uv_udp_t* handle,
val,
size);
if (r)
- return -errno;
+ return UV__ERR(errno);
return 0;
}
@@ -696,7 +701,7 @@ static int uv__setsockopt_maybe_char(uv_udp_t* handle,
#endif
if (val < 0 || val > 255)
- return -EINVAL;
+ return UV_EINVAL;
return uv__setsockopt(handle, option4, option6, &arg, sizeof(arg));
}
@@ -708,7 +713,7 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
SO_BROADCAST,
&on,
sizeof(on))) {
- return -errno;
+ return UV__ERR(errno);
}
return 0;
@@ -717,11 +722,11 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
if (ttl < 1 || ttl > 255)
- return -EINVAL;
+ return UV_EINVAL;
#if defined(__MVS__)
if (!(handle->flags & UV_HANDLE_IPV6))
- return -ENOTSUP; /* zOS does not support setting ttl for IPv4 */
+ return UV_ENOTSUP; /* zOS does not support setting ttl for IPv4 */
#endif
/*
@@ -755,14 +760,16 @@ int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
* IP_MULTICAST_TTL, so hardcode the size of the option in the IPv6 case,
* and use the general uv__setsockopt_maybe_char call otherwise.
*/
-#if defined(__sun) || defined(_AIX) || defined(__MVS__)
+#if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
+ defined(__MVS__)
if (handle->flags & UV_HANDLE_IPV6)
return uv__setsockopt(handle,
IP_MULTICAST_TTL,
IPV6_MULTICAST_HOPS,
&ttl,
sizeof(ttl));
-#endif /* defined(__sun) || defined(_AIX) || defined(__MVS__) */
+#endif /* defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
+ defined(__MVS__) */
return uv__setsockopt_maybe_char(handle,
IP_MULTICAST_TTL,
@@ -778,14 +785,16 @@ int uv_udp_set_multicast_loop(uv_udp_t* handle, int on) {
* IP_MULTICAST_LOOP, so hardcode the size of the option in the IPv6 case,
* and use the general uv__setsockopt_maybe_char call otherwise.
*/
-#if defined(__sun) || defined(_AIX) || defined(__MVS__)
+#if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
+ defined(__MVS__)
if (handle->flags & UV_HANDLE_IPV6)
return uv__setsockopt(handle,
IP_MULTICAST_LOOP,
IPV6_MULTICAST_LOOP,
&on,
sizeof(on));
-#endif /* defined(__sun) || defined(_AIX) || defined(__MVS__) */
+#endif /* defined(__sun) || defined(_AIX) ||defined(__OpenBSD__) ||
+ defined(__MVS__) */
return uv__setsockopt_maybe_char(handle,
IP_MULTICAST_LOOP,
@@ -815,7 +824,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
} else if (uv_ip6_addr(interface_addr, 0, addr6) == 0) {
/* nothing, address was parsed */
} else {
- return -EINVAL;
+ return UV_EINVAL;
}
if (addr_st.ss_family == AF_INET) {
@@ -824,7 +833,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
IP_MULTICAST_IF,
(void*) &addr4->sin_addr,
sizeof(addr4->sin_addr)) == -1) {
- return -errno;
+ return UV__ERR(errno);
}
} else if (addr_st.ss_family == AF_INET6) {
if (setsockopt(handle->io_watcher.fd,
@@ -832,7 +841,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
IPV6_MULTICAST_IF,
&addr6->sin6_scope_id,
sizeof(addr6->sin6_scope_id)) == -1) {
- return -errno;
+ return UV__ERR(errno);
}
} else {
assert(0 && "unexpected address family");
@@ -849,13 +858,13 @@ int uv_udp_getsockname(const uv_udp_t* handle,
socklen_t socklen;
if (handle->io_watcher.fd == -1)
- return -EINVAL; /* FIXME(bnoordhuis) -EBADF */
+ return UV_EINVAL; /* FIXME(bnoordhuis) UV_EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen;
if (getsockname(handle->io_watcher.fd, name, &socklen))
- return -errno;
+ return UV__ERR(errno);
*namelen = (int) socklen;
return 0;
@@ -868,10 +877,10 @@ int uv__udp_recv_start(uv_udp_t* handle,
int err;
if (alloc_cb == NULL || recv_cb == NULL)
- return -EINVAL;
+ return UV_EINVAL;
if (uv__io_active(&handle->io_watcher, POLLIN))
- return -EALREADY; /* FIXME(bnoordhuis) Should be -EBUSY. */
+ return UV_EALREADY; /* FIXME(bnoordhuis) Should be UV_EBUSY. */
err = uv__udp_maybe_deferred_bind(handle, AF_INET, 0);
if (err)
diff --git a/Utilities/cmlibuv/src/uv-common.c b/Utilities/cmlibuv/src/uv-common.c
index bc7d1379d..907ebf2f2 100644
--- a/Utilities/cmlibuv/src/uv-common.c
+++ b/Utilities/cmlibuv/src/uv-common.c
@@ -72,7 +72,9 @@ char* uv__strndup(const char* s, size_t n) {
}
void* uv__malloc(size_t size) {
- return uv__allocator.local_malloc(size);
+ if (size > 0)
+ return uv__allocator.local_malloc(size);
+ return NULL;
}
void uv__free(void* ptr) {
@@ -91,7 +93,10 @@ void* uv__calloc(size_t count, size_t size) {
}
void* uv__realloc(void* ptr, size_t size) {
- return uv__allocator.local_realloc(ptr, size);
+ if (size > 0)
+ return uv__allocator.local_realloc(ptr, size);
+ uv__free(ptr);
+ return NULL;
}
int uv_replace_allocator(uv_malloc_func malloc_func,
@@ -155,6 +160,18 @@ static const char* uv__unknown_err_code(int err) {
return copy != NULL ? copy : "Unknown system error";
}
+#define UV_ERR_NAME_GEN_R(name, _) \
+case UV_## name: \
+ uv__strscpy(buf, #name, buflen); break;
+char* uv_err_name_r(int err, char* buf, size_t buflen) {
+ switch (err) {
+ UV_ERRNO_MAP(UV_ERR_NAME_GEN_R)
+ default: snprintf(buf, buflen, "Unknown system error %d", err);
+ }
+ return buf;
+}
+#undef UV_ERR_NAME_GEN_R
+
#define UV_ERR_NAME_GEN(name, _) case UV_ ## name: return #name;
const char* uv_err_name(int err) {
@@ -166,6 +183,19 @@ const char* uv_err_name(int err) {
#undef UV_ERR_NAME_GEN
+#define UV_STRERROR_GEN_R(name, msg) \
+case UV_ ## name: \
+ snprintf(buf, buflen, "%s", msg); break;
+char* uv_strerror_r(int err, char* buf, size_t buflen) {
+ switch (err) {
+ UV_ERRNO_MAP(UV_STRERROR_GEN_R)
+ default: snprintf(buf, buflen, "Unknown system error %d", err);
+ }
+ return buf;
+}
+#undef UV_STRERROR_GEN_R
+
+
#define UV_STRERROR_GEN(name, msg) case UV_ ## name: return msg;
const char* uv_strerror(int err) {
switch (err) {
@@ -175,6 +205,7 @@ const char* uv_strerror(int err) {
}
#undef UV_STRERROR_GEN
+#if !defined(CMAKE_BOOTSTRAP) || defined(_WIN32)
int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr) {
memset(addr, 0, sizeof(*addr));
@@ -343,6 +374,7 @@ int uv_udp_recv_stop(uv_udp_t* handle) {
return uv__udp_recv_stop(handle);
}
+#endif
void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
QUEUE queue;
@@ -357,7 +389,7 @@ void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
QUEUE_REMOVE(q);
QUEUE_INSERT_TAIL(&loop->handle_queue, q);
- if (h->flags & UV__HANDLE_INTERNAL) continue;
+ if (h->flags & UV_HANDLE_INTERNAL) continue;
walk_cb(h, arg);
}
}
@@ -386,9 +418,9 @@ static void uv__print_handles(uv_loop_t* loop, int only_active, FILE* stream) {
fprintf(stream,
"[%c%c%c] %-8s %p\n",
- "R-"[!(h->flags & UV__HANDLE_REF)],
- "A-"[!(h->flags & UV__HANDLE_ACTIVE)],
- "I-"[!(h->flags & UV__HANDLE_INTERNAL)],
+ "R-"[!(h->flags & UV_HANDLE_REF)],
+ "A-"[!(h->flags & UV_HANDLE_ACTIVE)],
+ "I-"[!(h->flags & UV_HANDLE_INTERNAL)],
type,
(void*)h);
}
@@ -627,12 +659,12 @@ int uv_loop_close(uv_loop_t* loop) {
void* saved_data;
#endif
- if (!QUEUE_EMPTY(&(loop)->active_reqs))
+ if (uv__has_active_reqs(loop))
return UV_EBUSY;
QUEUE_FOREACH(q, &loop->handle_queue) {
h = QUEUE_DATA(q, uv_handle_t, handle_queue);
- if (!(h->flags & UV__HANDLE_INTERNAL))
+ if (!(h->flags & UV_HANDLE_INTERNAL))
return UV_EBUSY;
}
diff --git a/Utilities/cmlibuv/src/uv-common.h b/Utilities/cmlibuv/src/uv-common.h
index 781a8559d..15ac4d02c 100644
--- a/Utilities/cmlibuv/src/uv-common.h
+++ b/Utilities/cmlibuv/src/uv-common.h
@@ -32,14 +32,21 @@
#include <stddef.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "stdint-msvc2008.h"
+# include "uv/stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
#include "uv.h"
-#include "tree.h"
+#include "uv/tree.h"
#include "queue.h"
+#include "strscpy.h"
+
+#if EDOM > 0
+# define UV__ERR(x) (-(x))
+#else
+# define UV__ERR(x) (x)
+#endif
#if !defined(snprintf) && defined(_MSC_VER) && _MSC_VER < 1900
extern int snprintf(char*, size_t, const char*, ...);
@@ -53,22 +60,67 @@ extern int snprintf(char*, size_t, const char*, ...);
#define STATIC_ASSERT(expr) \
void uv__static_assert(int static_assert_failed[1 - 2 * !(expr)])
-#ifndef _WIN32
+/* Handle flags. Some flags are specific to Windows or UNIX. */
enum {
- UV__SIGNAL_ONE_SHOT = 0x80000, /* On signal reception remove sighandler */
- UV__HANDLE_INTERNAL = 0x8000,
- UV__HANDLE_ACTIVE = 0x4000,
- UV__HANDLE_REF = 0x2000,
- UV__HANDLE_CLOSING = 0 /* no-op on unix */
+ /* Used by all handles. */
+ UV_HANDLE_CLOSING = 0x00000001,
+ UV_HANDLE_CLOSED = 0x00000002,
+ UV_HANDLE_ACTIVE = 0x00000004,
+ UV_HANDLE_REF = 0x00000008,
+ UV_HANDLE_INTERNAL = 0x00000010,
+ UV_HANDLE_ENDGAME_QUEUED = 0x00000020,
+
+ /* Used by streams. */
+ UV_HANDLE_LISTENING = 0x00000040,
+ UV_HANDLE_CONNECTION = 0x00000080,
+ UV_HANDLE_SHUTTING = 0x00000100,
+ UV_HANDLE_SHUT = 0x00000200,
+ UV_HANDLE_READ_PARTIAL = 0x00000400,
+ UV_HANDLE_READ_EOF = 0x00000800,
+
+ /* Used by streams and UDP handles. */
+ UV_HANDLE_READING = 0x00001000,
+ UV_HANDLE_BOUND = 0x00002000,
+ UV_HANDLE_READABLE = 0x00004000,
+ UV_HANDLE_WRITABLE = 0x00008000,
+ UV_HANDLE_READ_PENDING = 0x00010000,
+ UV_HANDLE_SYNC_BYPASS_IOCP = 0x00020000,
+ UV_HANDLE_ZERO_READ = 0x00040000,
+ UV_HANDLE_EMULATE_IOCP = 0x00080000,
+ UV_HANDLE_BLOCKING_WRITES = 0x00100000,
+ UV_HANDLE_CANCELLATION_PENDING = 0x00200000,
+
+ /* Used by uv_tcp_t and uv_udp_t handles */
+ UV_HANDLE_IPV6 = 0x00400000,
+
+ /* Only used by uv_tcp_t handles. */
+ UV_HANDLE_TCP_NODELAY = 0x01000000,
+ UV_HANDLE_TCP_KEEPALIVE = 0x02000000,
+ UV_HANDLE_TCP_SINGLE_ACCEPT = 0x04000000,
+ UV_HANDLE_TCP_ACCEPT_STATE_CHANGING = 0x08000000,
+ UV_HANDLE_TCP_SOCKET_CLOSED = 0x10000000,
+ UV_HANDLE_SHARED_TCP_SOCKET = 0x20000000,
+
+ /* Only used by uv_udp_t handles. */
+ UV_HANDLE_UDP_PROCESSING = 0x01000000,
+
+ /* Only used by uv_pipe_t handles. */
+ UV_HANDLE_NON_OVERLAPPED_PIPE = 0x01000000,
+ UV_HANDLE_PIPESERVER = 0x02000000,
+
+ /* Only used by uv_tty_t handles. */
+ UV_HANDLE_TTY_READABLE = 0x01000000,
+ UV_HANDLE_TTY_RAW = 0x02000000,
+ UV_HANDLE_TTY_SAVED_POSITION = 0x04000000,
+ UV_HANDLE_TTY_SAVED_ATTRIBUTES = 0x08000000,
+
+ /* Only used by uv_signal_t handles. */
+ UV_SIGNAL_ONE_SHOT_DISPATCHED = 0x01000000,
+ UV_SIGNAL_ONE_SHOT = 0x02000000,
+
+ /* Only used by uv_poll_t handles. */
+ UV_HANDLE_POLL_SLOW = 0x01000000
};
-#else
-# define UV__SIGNAL_ONE_SHOT_DISPATCHED 0x200
-# define UV__SIGNAL_ONE_SHOT 0x100
-# define UV__HANDLE_INTERNAL 0x80
-# define UV__HANDLE_ACTIVE 0x40
-# define UV__HANDLE_REF 0x20
-# define UV__HANDLE_CLOSING 0x01
-#endif
int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list ap);
@@ -113,8 +165,15 @@ void uv__fs_poll_close(uv_fs_poll_t* handle);
int uv__getaddrinfo_translate_error(int sys_err); /* EAI_* error. */
+enum uv__work_kind {
+ UV__WORK_CPU,
+ UV__WORK_FAST_IO,
+ UV__WORK_SLOW_IO
+};
+
void uv__work_submit(uv_loop_t* loop,
struct uv__work *w,
+ enum uv__work_kind kind,
void (*work)(struct uv__work *w),
void (*done)(struct uv__work *w, int status));
@@ -126,19 +185,23 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value);
void uv__fs_scandir_cleanup(uv_fs_t* req);
+int uv__next_timeout(const uv_loop_t* loop);
+void uv__run_timers(uv_loop_t* loop);
+void uv__timer_close(uv_timer_t* handle);
+
#define uv__has_active_reqs(loop) \
- (QUEUE_EMPTY(&(loop)->active_reqs) == 0)
+ ((loop)->active_reqs.count > 0)
#define uv__req_register(loop, req) \
do { \
- QUEUE_INSERT_TAIL(&(loop)->active_reqs, &(req)->active_queue); \
+ (loop)->active_reqs.count++; \
} \
while (0)
#define uv__req_unregister(loop, req) \
do { \
assert(uv__has_active_reqs(loop)); \
- QUEUE_REMOVE(&(req)->active_queue); \
+ (loop)->active_reqs.count--; \
} \
while (0)
@@ -158,49 +221,47 @@ void uv__fs_scandir_cleanup(uv_fs_t* req);
while (0)
#define uv__is_active(h) \
- (((h)->flags & UV__HANDLE_ACTIVE) != 0)
+ (((h)->flags & UV_HANDLE_ACTIVE) != 0)
#define uv__is_closing(h) \
- (((h)->flags & (UV_CLOSING | UV_CLOSED)) != 0)
+ (((h)->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED)) != 0)
#define uv__handle_start(h) \
do { \
- assert(((h)->flags & UV__HANDLE_CLOSING) == 0); \
- if (((h)->flags & UV__HANDLE_ACTIVE) != 0) break; \
- (h)->flags |= UV__HANDLE_ACTIVE; \
- if (((h)->flags & UV__HANDLE_REF) != 0) uv__active_handle_add(h); \
+ if (((h)->flags & UV_HANDLE_ACTIVE) != 0) break; \
+ (h)->flags |= UV_HANDLE_ACTIVE; \
+ if (((h)->flags & UV_HANDLE_REF) != 0) uv__active_handle_add(h); \
} \
while (0)
#define uv__handle_stop(h) \
do { \
- assert(((h)->flags & UV__HANDLE_CLOSING) == 0); \
- if (((h)->flags & UV__HANDLE_ACTIVE) == 0) break; \
- (h)->flags &= ~UV__HANDLE_ACTIVE; \
- if (((h)->flags & UV__HANDLE_REF) != 0) uv__active_handle_rm(h); \
+ if (((h)->flags & UV_HANDLE_ACTIVE) == 0) break; \
+ (h)->flags &= ~UV_HANDLE_ACTIVE; \
+ if (((h)->flags & UV_HANDLE_REF) != 0) uv__active_handle_rm(h); \
} \
while (0)
#define uv__handle_ref(h) \
do { \
- if (((h)->flags & UV__HANDLE_REF) != 0) break; \
- (h)->flags |= UV__HANDLE_REF; \
- if (((h)->flags & UV__HANDLE_CLOSING) != 0) break; \
- if (((h)->flags & UV__HANDLE_ACTIVE) != 0) uv__active_handle_add(h); \
+ if (((h)->flags & UV_HANDLE_REF) != 0) break; \
+ (h)->flags |= UV_HANDLE_REF; \
+ if (((h)->flags & UV_HANDLE_CLOSING) != 0) break; \
+ if (((h)->flags & UV_HANDLE_ACTIVE) != 0) uv__active_handle_add(h); \
} \
while (0)
#define uv__handle_unref(h) \
do { \
- if (((h)->flags & UV__HANDLE_REF) == 0) break; \
- (h)->flags &= ~UV__HANDLE_REF; \
- if (((h)->flags & UV__HANDLE_CLOSING) != 0) break; \
- if (((h)->flags & UV__HANDLE_ACTIVE) != 0) uv__active_handle_rm(h); \
+ if (((h)->flags & UV_HANDLE_REF) == 0) break; \
+ (h)->flags &= ~UV_HANDLE_REF; \
+ if (((h)->flags & UV_HANDLE_CLOSING) != 0) break; \
+ if (((h)->flags & UV_HANDLE_ACTIVE) != 0) uv__active_handle_rm(h); \
} \
while (0)
#define uv__has_ref(h) \
- (((h)->flags & UV__HANDLE_REF) != 0)
+ (((h)->flags & UV_HANDLE_REF) != 0)
#if defined(_WIN32)
# define uv__handle_platform_init(h) ((h)->u.fd = -1)
@@ -212,7 +273,7 @@ void uv__fs_scandir_cleanup(uv_fs_t* req);
do { \
(h)->loop = (loop_); \
(h)->type = (type_); \
- (h)->flags = UV__HANDLE_REF; /* Ref the loop when active. */ \
+ (h)->flags = UV_HANDLE_REF; /* Ref the loop when active. */ \
QUEUE_INSERT_TAIL(&(loop_)->handle_queue, &(h)->handle_queue); \
uv__handle_platform_init(h); \
} \
diff --git a/Utilities/cmlibuv/src/win/async.c b/Utilities/cmlibuv/src/win/async.c
index 0b636ed1e..d787f6604 100644
--- a/Utilities/cmlibuv/src/win/async.c
+++ b/Utilities/cmlibuv/src/win/async.c
@@ -29,7 +29,7 @@
void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle) {
- if (handle->flags & UV__HANDLE_CLOSING &&
+ if (handle->flags & UV_HANDLE_CLOSING &&
!handle->async_sent) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
uv__handle_close(handle);
@@ -71,9 +71,9 @@ int uv_async_send(uv_async_t* handle) {
return -1;
}
- /* The user should make sure never to call uv_async_send to a closing */
- /* or closed handle. */
- assert(!(handle->flags & UV__HANDLE_CLOSING));
+ /* The user should make sure never to call uv_async_send to a closing or
+ * closed handle. */
+ assert(!(handle->flags & UV_HANDLE_CLOSING));
if (!uv__atomic_exchange_set(&handle->async_sent)) {
POST_COMPLETION_FOR_REQ(loop, &handle->async_req);
@@ -90,7 +90,7 @@ void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle,
handle->async_sent = 0;
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
uv_want_endgame(loop, (uv_handle_t*)handle);
} else if (handle->async_cb != NULL) {
handle->async_cb(handle);
diff --git a/Utilities/cmlibuv/src/win/atomicops-inl.h b/Utilities/cmlibuv/src/win/atomicops-inl.h
index 6d8126f69..52713cf30 100644
--- a/Utilities/cmlibuv/src/win/atomicops-inl.h
+++ b/Utilities/cmlibuv/src/win/atomicops-inl.h
@@ -29,10 +29,10 @@
/* Atomic set operation on char */
#ifdef _MSC_VER /* MSVC */
-/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less */
-/* efficient than InterlockedExchange, but InterlockedExchange8 does not */
-/* exist, and interlocked operations on larger targets might require the */
-/* target to be aligned. */
+/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less
+ * efficient than InterlockedExchange, but InterlockedExchange8 does not exist,
+ * and interlocked operations on larger targets might require the target to be
+ * aligned. */
#pragma intrinsic(_InterlockedOr8)
static char INLINE uv__atomic_exchange_set(char volatile* target) {
diff --git a/Utilities/cmlibuv/src/win/core.c b/Utilities/cmlibuv/src/win/core.c
index 9ed4e824c..58309c696 100644
--- a/Utilities/cmlibuv/src/win/core.c
+++ b/Utilities/cmlibuv/src/win/core.c
@@ -33,6 +33,7 @@
#include "internal.h"
#include "queue.h"
#include "handle-inl.h"
+#include "heap-inl.h"
#include "req-inl.h"
/* uv_once initialization guards */
@@ -221,6 +222,7 @@ static void uv_init(void) {
int uv_loop_init(uv_loop_t* loop) {
+ struct heap* timer_heap;
int err;
/* Initialize libuv itself first */
@@ -239,14 +241,20 @@ int uv_loop_init(uv_loop_t* loop) {
QUEUE_INIT(&loop->wq);
QUEUE_INIT(&loop->handle_queue);
- QUEUE_INIT(&loop->active_reqs);
+ loop->active_reqs.count = 0;
loop->active_handles = 0;
loop->pending_reqs_tail = NULL;
loop->endgame_handles = NULL;
- RB_INIT(&loop->timers);
+ loop->timer_heap = timer_heap = uv__malloc(sizeof(*timer_heap));
+ if (timer_heap == NULL) {
+ err = UV_ENOMEM;
+ goto fail_timers_alloc;
+ }
+
+ heap_init(timer_heap);
loop->check_handles = NULL;
loop->prepare_handles = NULL;
@@ -273,7 +281,7 @@ int uv_loop_init(uv_loop_t* loop) {
goto fail_async_init;
uv__handle_unref(&loop->wq_async);
- loop->wq_async.flags |= UV__HANDLE_INTERNAL;
+ loop->wq_async.flags |= UV_HANDLE_INTERNAL;
err = uv__loops_add(loop);
if (err)
@@ -285,6 +293,10 @@ fail_async_init:
uv_mutex_destroy(&loop->wq_mutex);
fail_mutex_init:
+ uv__free(timer_heap);
+ loop->timer_heap = NULL;
+
+fail_timers_alloc:
CloseHandle(loop->iocp);
loop->iocp = INVALID_HANDLE_VALUE;
@@ -292,6 +304,13 @@ fail_mutex_init:
}
+void uv_update_time(uv_loop_t* loop) {
+ uint64_t new_time = uv__hrtime(1000);
+ assert(new_time >= loop->time);
+ loop->time = new_time;
+}
+
+
void uv__once_init(void) {
uv_once(&uv_init_guard_, uv_init);
}
@@ -320,6 +339,9 @@ void uv__loop_close(uv_loop_t* loop) {
uv_mutex_unlock(&loop->wq_mutex);
uv_mutex_destroy(&loop->wq_mutex);
+ uv__free(loop->timer_heap);
+ loop->timer_heap = NULL;
+
CloseHandle(loop->iocp);
}
@@ -359,7 +381,7 @@ int uv_backend_timeout(const uv_loop_t* loop) {
}
-static void uv_poll(uv_loop_t* loop, DWORD timeout) {
+static void uv__poll_wine(uv_loop_t* loop, DWORD timeout) {
DWORD bytes;
ULONG_PTR key;
OVERLAPPED* overlapped;
@@ -410,7 +432,7 @@ static void uv_poll(uv_loop_t* loop, DWORD timeout) {
}
-static void uv_poll_ex(uv_loop_t* loop, DWORD timeout) {
+static void uv__poll(uv_loop_t* loop, DWORD timeout) {
BOOL success;
uv_req_t* req;
OVERLAPPED_ENTRY overlappeds[128];
@@ -422,12 +444,12 @@ static void uv_poll_ex(uv_loop_t* loop, DWORD timeout) {
timeout_time = loop->time + timeout;
for (repeat = 0; ; repeat++) {
- success = pGetQueuedCompletionStatusEx(loop->iocp,
- overlappeds,
- ARRAY_SIZE(overlappeds),
- &count,
- timeout,
- FALSE);
+ success = GetQueuedCompletionStatusEx(loop->iocp,
+ overlappeds,
+ ARRAY_SIZE(overlappeds),
+ &count,
+ timeout,
+ FALSE);
if (success) {
for (i = 0; i < count; i++) {
@@ -470,8 +492,8 @@ static void uv_poll_ex(uv_loop_t* loop, DWORD timeout) {
static int uv__loop_alive(const uv_loop_t* loop) {
- return loop->active_handles > 0 ||
- !QUEUE_EMPTY(&loop->active_reqs) ||
+ return uv__has_active_handles(loop) ||
+ uv__has_active_reqs(loop) ||
loop->endgame_handles != NULL;
}
@@ -485,12 +507,6 @@ int uv_run(uv_loop_t *loop, uv_run_mode mode) {
DWORD timeout;
int r;
int ran_pending;
- void (*poll)(uv_loop_t* loop, DWORD timeout);
-
- if (pGetQueuedCompletionStatusEx)
- poll = &uv_poll_ex;
- else
- poll = &uv_poll;
r = uv__loop_alive(loop);
if (!r)
@@ -498,7 +514,7 @@ int uv_run(uv_loop_t *loop, uv_run_mode mode) {
while (r != 0 && loop->stop_flag == 0) {
uv_update_time(loop);
- uv_process_timers(loop);
+ uv__run_timers(loop);
ran_pending = uv_process_reqs(loop);
uv_idle_invoke(loop);
@@ -508,7 +524,11 @@ int uv_run(uv_loop_t *loop, uv_run_mode mode) {
if ((mode == UV_RUN_ONCE && !ran_pending) || mode == UV_RUN_DEFAULT)
timeout = uv_backend_timeout(loop);
- (*poll)(loop, timeout);
+ if (pGetQueuedCompletionStatusEx)
+ uv__poll(loop, timeout);
+ else
+ uv__poll_wine(loop, timeout);
+
uv_check_invoke(loop);
uv_process_endgames(loop);
@@ -522,7 +542,7 @@ int uv_run(uv_loop_t *loop, uv_run_mode mode) {
* UV_RUN_NOWAIT makes no guarantees about progress so it's omitted from
* the check.
*/
- uv_process_timers(loop);
+ uv__run_timers(loop);
}
r = uv__loop_alive(loop);
@@ -603,3 +623,7 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) {
return 0;
}
+
+int uv_cpumask_size(void) {
+ return (int)(sizeof(DWORD_PTR) * 8);
+}
diff --git a/Utilities/cmlibuv/src/win/dl.c b/Utilities/cmlibuv/src/win/dl.c
index 39e400ab2..676be4dc7 100644
--- a/Utilities/cmlibuv/src/win/dl.c
+++ b/Utilities/cmlibuv/src/win/dl.c
@@ -22,7 +22,7 @@
#include "uv.h"
#include "internal.h"
-static int uv__dlerror(uv_lib_t* lib, int errorno);
+static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno);
int uv_dlopen(const char* filename, uv_lib_t* lib) {
@@ -37,12 +37,12 @@ int uv_dlopen(const char* filename, uv_lib_t* lib) {
-1,
filename_w,
ARRAY_SIZE(filename_w))) {
- return uv__dlerror(lib, GetLastError());
+ return uv__dlerror(lib, filename, GetLastError());
}
lib->handle = LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (lib->handle == NULL) {
- return uv__dlerror(lib, GetLastError());
+ return uv__dlerror(lib, filename, GetLastError());
}
return 0;
@@ -64,8 +64,9 @@ void uv_dlclose(uv_lib_t* lib) {
int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr) {
- *ptr = (void*) GetProcAddress(lib->handle, name);
- return uv__dlerror(lib, *ptr ? 0 : GetLastError());
+ /* Cast though integer to suppress pedantic warning about forbidden cast. */
+ *ptr = (void*)(uintptr_t) GetProcAddress(lib->handle, name);
+ return uv__dlerror(lib, "", *ptr ? 0 : GetLastError());
}
@@ -75,8 +76,9 @@ const char* uv_dlerror(const uv_lib_t* lib) {
static void uv__format_fallback_error(uv_lib_t* lib, int errorno){
- DWORD_PTR args[1] = { (DWORD_PTR) errorno };
- LPSTR fallback_error = "error: %1!d!";
+ static const CHAR fallback_error[] = "error: %1!d!";
+ DWORD_PTR args[1];
+ args[0] = (DWORD_PTR) errorno;
FormatMessageA(FORMAT_MESSAGE_FROM_STRING |
FORMAT_MESSAGE_ARGUMENT_ARRAY |
@@ -88,31 +90,47 @@ static void uv__format_fallback_error(uv_lib_t* lib, int errorno){
-static int uv__dlerror(uv_lib_t* lib, int errorno) {
+static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno) {
+ DWORD_PTR arg;
DWORD res;
+ char* msg;
if (lib->errmsg) {
- LocalFree((void*)lib->errmsg);
+ LocalFree(lib->errmsg);
lib->errmsg = NULL;
}
- if (errorno) {
+ if (errorno == 0)
+ return 0;
+
+ res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
+ MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
+ (LPSTR) &lib->errmsg, 0, NULL);
+
+ if (!res && (GetLastError() == ERROR_MUI_FILE_NOT_FOUND ||
+ GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND)) {
res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (LPSTR) &lib->errmsg, 0, NULL);
- if (!res && GetLastError() == ERROR_MUI_FILE_NOT_FOUND) {
- res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
- 0, (LPSTR) &lib->errmsg, 0, NULL);
- }
-
- if (!res) {
- uv__format_fallback_error(lib, errorno);
- }
+ 0, (LPSTR) &lib->errmsg, 0, NULL);
+ }
+
+ if (res && errorno == ERROR_BAD_EXE_FORMAT && strstr(lib->errmsg, "%1")) {
+ msg = lib->errmsg;
+ lib->errmsg = NULL;
+ arg = (DWORD_PTR) filename;
+ res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_ARGUMENT_ARRAY |
+ FORMAT_MESSAGE_FROM_STRING,
+ msg,
+ 0, 0, (LPSTR) &lib->errmsg, 0, (va_list*) &arg);
+ LocalFree(msg);
}
- return errorno ? -1 : 0;
+ if (!res)
+ uv__format_fallback_error(lib, errorno);
+
+ return -1;
}
diff --git a/Utilities/cmlibuv/src/win/error.c b/Utilities/cmlibuv/src/win/error.c
index 642d1112e..24924ba81 100644
--- a/Utilities/cmlibuv/src/win/error.c
+++ b/Utilities/cmlibuv/src/win/error.c
@@ -46,8 +46,8 @@ void uv_fatal_error(const int errorno, const char* syscall) {
errmsg = "Unknown error";
}
- /* FormatMessage messages include a newline character already, */
- /* so don't add another. */
+ /* FormatMessage messages include a newline character already, so don't add
+ * another. */
if (syscall) {
fprintf(stderr, "%s: (%d) %s", syscall, errorno, errmsg);
} else {
@@ -58,7 +58,7 @@ void uv_fatal_error(const int errorno, const char* syscall) {
LocalFree(buf);
}
- *((char*)NULL) = 0xff; /* Force debug break */
+ DebugBreak();
abort();
}
diff --git a/Utilities/cmlibuv/src/win/fs-event.c b/Utilities/cmlibuv/src/win/fs-event.c
index 95f843ad0..acf8e1107 100644
--- a/Utilities/cmlibuv/src/win/fs-event.c
+++ b/Utilities/cmlibuv/src/win/fs-event.c
@@ -69,6 +69,7 @@ static void uv_relative_path(const WCHAR* filename,
size_t relpathlen;
size_t filenamelen = wcslen(filename);
size_t dirlen = wcslen(dir);
+ assert(!_wcsnicmp(filename, dir, dirlen));
if (dirlen > 0 && dir[dirlen - 1] == '\\')
dirlen--;
relpathlen = filenamelen - dirlen - 1;
@@ -82,7 +83,7 @@ static void uv_relative_path(const WCHAR* filename,
static int uv_split_path(const WCHAR* filename, WCHAR** dir,
WCHAR** file) {
size_t len, i;
-
+
if (filename == NULL) {
if (dir != NULL)
*dir = NULL;
@@ -151,11 +152,11 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv_fs_event_cb cb,
const char* path,
unsigned int flags) {
- int name_size, is_path_dir;
+ int name_size, is_path_dir, size;
DWORD attr, last_error;
WCHAR* dir = NULL, *dir_to_watch, *pathw = NULL;
WCHAR short_path_buffer[MAX_PATH];
- WCHAR* short_path;
+ WCHAR* short_path, *long_path;
if (uv__is_active(handle))
return UV_EINVAL;
@@ -197,6 +198,30 @@ int uv_fs_event_start(uv_fs_event_t* handle,
if (is_path_dir) {
/* path is a directory, so that's the directory that we will watch. */
+
+ /* Convert to long path. */
+ size = GetLongPathNameW(pathw, NULL, 0);
+
+ if (size) {
+ long_path = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
+ if (!long_path) {
+ uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
+ }
+
+ size = GetLongPathNameW(pathw, long_path, size);
+ if (size) {
+ long_path[size] = '\0';
+ } else {
+ uv__free(long_path);
+ long_path = NULL;
+ }
+
+ if (long_path) {
+ uv__free(pathw);
+ pathw = long_path;
+ }
+ }
+
dir_to_watch = pathw;
} else {
/*
@@ -205,8 +230,11 @@ int uv_fs_event_start(uv_fs_event_t* handle,
*/
/* Convert to short path. */
- short_path = short_path_buffer;
- if (!GetShortPathNameW(pathw, short_path, ARRAY_SIZE(short_path))) {
+ if (GetShortPathNameW(pathw,
+ short_path_buffer,
+ ARRAY_SIZE(short_path_buffer))) {
+ short_path = short_path_buffer;
+ } else {
short_path = NULL;
}
@@ -394,7 +422,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
* - We are not active, just ignore the callback
*/
if (!uv__is_active(handle)) {
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
uv_want_endgame(loop, (uv_handle_t*) handle);
}
return;
@@ -518,7 +546,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
}
offset = file_info->NextEntryOffset;
- } while (offset && !(handle->flags & UV__HANDLE_CLOSING));
+ } while (offset && !(handle->flags & UV_HANDLE_CLOSING));
} else {
handle->cb(handle, NULL, UV_CHANGE, 0);
}
@@ -527,7 +555,7 @@ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
handle->cb(handle, NULL, 0, uv_translate_sys_error(err));
}
- if (!(handle->flags & UV__HANDLE_CLOSING)) {
+ if (!(handle->flags & UV_HANDLE_CLOSING)) {
uv_fs_event_queue_readdirchanges(loop, handle);
} else {
uv_want_endgame(loop, (uv_handle_t*)handle);
@@ -548,7 +576,7 @@ void uv_fs_event_close(uv_loop_t* loop, uv_fs_event_t* handle) {
void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle) {
- if ((handle->flags & UV__HANDLE_CLOSING) && !handle->req_pending) {
+ if ((handle->flags & UV_HANDLE_CLOSING) && !handle->req_pending) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
if (handle->buffer) {
diff --git a/Utilities/cmlibuv/src/win/fs.c b/Utilities/cmlibuv/src/win/fs.c
index 2d72cdc70..65d936bf0 100644
--- a/Utilities/cmlibuv/src/win/fs.c
+++ b/Utilities/cmlibuv/src/win/fs.c
@@ -43,11 +43,30 @@
#define UV_FS_CLEANEDUP 0x0010
-#define QUEUE_FS_TP_JOB(loop, req) \
- do { \
- uv__req_register(loop, req); \
- uv__work_submit((loop), &(req)->work_req, uv__fs_work, uv__fs_done); \
- } while (0)
+#define INIT(subtype) \
+ do { \
+ if (req == NULL) \
+ return UV_EINVAL; \
+ uv_fs_req_init(loop, req, subtype, cb); \
+ } \
+ while (0)
+
+#define POST \
+ do { \
+ if (cb != NULL) { \
+ uv__req_register(loop, req); \
+ uv__work_submit(loop, \
+ &req->work_req, \
+ UV__WORK_FAST_IO, \
+ uv__fs_work, \
+ uv__fs_done); \
+ return 0; \
+ } else { \
+ uv__fs_work(&req->work_req); \
+ return req->result; \
+ } \
+ } \
+ while (0)
#define SET_REQ_RESULT(req, result_value) \
do { \
@@ -77,14 +96,17 @@
return; \
}
+#define MILLIONu (1000U * 1000U)
+#define BILLIONu (1000U * 1000U * 1000U)
+
#define FILETIME_TO_UINT(filetime) \
- (*((uint64_t*) &(filetime)) - 116444736000000000ULL)
+ (*((uint64_t*) &(filetime)) - (uint64_t) 116444736 * BILLIONu)
#define FILETIME_TO_TIME_T(filetime) \
- (FILETIME_TO_UINT(filetime) / 10000000ULL)
+ (FILETIME_TO_UINT(filetime) / (10u * MILLIONu))
#define FILETIME_TO_TIME_NS(filetime, secs) \
- ((FILETIME_TO_UINT(filetime) - (secs * 10000000ULL)) * 100)
+ ((FILETIME_TO_UINT(filetime) - (secs * (uint64_t) 10 * MILLIONu)) * 100U)
#define FILETIME_TO_TIMESPEC(ts, filetime) \
do { \
@@ -94,8 +116,8 @@
#define TIME_T_TO_FILETIME(time, filetime_ptr) \
do { \
- uint64_t bigtime = ((uint64_t) ((time) * 10000000ULL)) + \
- 116444736000000000ULL; \
+ uint64_t bigtime = ((uint64_t) ((time) * (uint64_t) 10 * MILLIONu)) + \
+ (uint64_t) 116444736 * BILLIONu; \
(filetime_ptr)->dwLowDateTime = bigtime & 0xFFFFFFFF; \
(filetime_ptr)->dwHighDateTime = bigtime >> 32; \
} while(0)
@@ -113,6 +135,7 @@ const WCHAR LONG_PATH_PREFIX_LEN = 4;
const WCHAR UNC_PATH_PREFIX[] = L"\\\\?\\UNC\\";
const WCHAR UNC_PATH_PREFIX_LEN = 8;
+static int uv__file_symlink_usermode_flag = SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE;
void uv_fs_init(void) {
_fmode = _O_BINARY;
@@ -220,6 +243,7 @@ INLINE static int fs__capture_path(uv_fs_t* req, const char* path,
INLINE static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req,
uv_fs_type fs_type, const uv_fs_cb cb) {
+ uv__once_init();
UV_REQ_INIT(req, UV_FS);
req->loop = loop;
req->flags = 0;
@@ -309,12 +333,11 @@ INLINE static int fs__readlink_handle(HANDLE handle, char** target_ptr,
reparse_data->SymbolicLinkReparseBuffer.SubstituteNameLength /
sizeof(WCHAR);
- /* Real symlinks can contain pretty much everything, but the only thing */
- /* we really care about is undoing the implicit conversion to an NT */
- /* namespaced path that CreateSymbolicLink will perform on absolute */
- /* paths. If the path is win32-namespaced then the user must have */
- /* explicitly made it so, and we better just return the unmodified */
- /* reparse data. */
+ /* Real symlinks can contain pretty much everything, but the only thing we
+ * really care about is undoing the implicit conversion to an NT namespaced
+ * path that CreateSymbolicLink will perform on absolute paths. If the path
+ * is win32-namespaced then the user must have explicitly made it so, and
+ * we better just return the unmodified reparse data. */
if (w_target_len >= 4 &&
w_target[0] == L'\\' &&
w_target[1] == L'?' &&
@@ -335,8 +358,8 @@ INLINE static int fs__readlink_handle(HANDLE handle, char** target_ptr,
(w_target[5] == L'N' || w_target[5] == L'n') &&
(w_target[6] == L'C' || w_target[6] == L'c') &&
w_target[7] == L'\\') {
- /* \??\UNC\<server>\<share>\ - make sure the final path looks like */
- /* \\<server>\<share>\ */
+ /* \??\UNC\<server>\<share>\ - make sure the final path looks like
+ * \\<server>\<share>\ */
w_target += 6;
w_target[0] = L'\\';
w_target_len -= 6;
@@ -351,11 +374,11 @@ INLINE static int fs__readlink_handle(HANDLE handle, char** target_ptr,
w_target_len = reparse_data->MountPointReparseBuffer.SubstituteNameLength /
sizeof(WCHAR);
- /* Only treat junctions that look like \??\<drive>:\ as symlink. */
- /* Junctions can also be used as mount points, like \??\Volume{<guid>}, */
- /* but that's confusing for programs since they wouldn't be able to */
- /* actually understand such a path when returned by uv_readlink(). */
- /* UNC paths are never valid for junctions so we don't care about them. */
+ /* Only treat junctions that look like \??\<drive>:\ as symlink. Junctions
+ * can also be used as mount points, like \??\Volume{<guid>}, but that's
+ * confusing for programs since they wouldn't be able to actually
+ * understand such a path when returned by uv_readlink(). UNC paths are
+ * never valid for junctions so we don't care about them. */
if (!(w_target_len >= 6 &&
w_target[0] == L'\\' &&
w_target[1] == L'?' &&
@@ -392,27 +415,27 @@ void fs__open(uv_fs_t* req) {
int fd, current_umask;
int flags = req->fs.info.file_flags;
- /* Obtain the active umask. umask() never fails and returns the previous */
- /* umask. */
+ /* Obtain the active umask. umask() never fails and returns the previous
+ * umask. */
current_umask = umask(0);
umask(current_umask);
/* convert flags and mode to CreateFile parameters */
- switch (flags & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
- case _O_RDONLY:
+ switch (flags & (UV_FS_O_RDONLY | UV_FS_O_WRONLY | UV_FS_O_RDWR)) {
+ case UV_FS_O_RDONLY:
access = FILE_GENERIC_READ;
break;
- case _O_WRONLY:
+ case UV_FS_O_WRONLY:
access = FILE_GENERIC_WRITE;
break;
- case _O_RDWR:
+ case UV_FS_O_RDWR:
access = FILE_GENERIC_READ | FILE_GENERIC_WRITE;
break;
default:
goto einval;
}
- if (flags & _O_APPEND) {
+ if (flags & UV_FS_O_APPEND) {
access &= ~FILE_WRITE_DATA;
access |= FILE_APPEND_DATA;
}
@@ -422,26 +445,33 @@ void fs__open(uv_fs_t* req) {
* does. We indiscriminately use all the sharing modes, to match
* UNIX semantics. In particular, this ensures that the file can
* be deleted even whilst it's open, fixing issue #1449.
+ * We still support exclusive sharing mode, since it is necessary
+ * for opening raw block devices, otherwise Windows will prevent
+ * any attempt to write past the master boot record.
*/
- share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+ if (flags & UV_FS_O_EXLOCK) {
+ share = 0;
+ } else {
+ share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+ }
- switch (flags & (_O_CREAT | _O_EXCL | _O_TRUNC)) {
+ switch (flags & (UV_FS_O_CREAT | UV_FS_O_EXCL | UV_FS_O_TRUNC)) {
case 0:
- case _O_EXCL:
+ case UV_FS_O_EXCL:
disposition = OPEN_EXISTING;
break;
- case _O_CREAT:
+ case UV_FS_O_CREAT:
disposition = OPEN_ALWAYS;
break;
- case _O_CREAT | _O_EXCL:
- case _O_CREAT | _O_TRUNC | _O_EXCL:
+ case UV_FS_O_CREAT | UV_FS_O_EXCL:
+ case UV_FS_O_CREAT | UV_FS_O_TRUNC | UV_FS_O_EXCL:
disposition = CREATE_NEW;
break;
- case _O_TRUNC:
- case _O_TRUNC | _O_EXCL:
+ case UV_FS_O_TRUNC:
+ case UV_FS_O_TRUNC | UV_FS_O_EXCL:
disposition = TRUNCATE_EXISTING;
break;
- case _O_CREAT | _O_TRUNC:
+ case UV_FS_O_CREAT | UV_FS_O_TRUNC:
disposition = CREATE_ALWAYS;
break;
default:
@@ -449,34 +479,76 @@ void fs__open(uv_fs_t* req) {
}
attributes |= FILE_ATTRIBUTE_NORMAL;
- if (flags & _O_CREAT) {
+ if (flags & UV_FS_O_CREAT) {
if (!((req->fs.info.mode & ~current_umask) & _S_IWRITE)) {
attributes |= FILE_ATTRIBUTE_READONLY;
}
}
- if (flags & _O_TEMPORARY ) {
+ if (flags & UV_FS_O_TEMPORARY ) {
attributes |= FILE_FLAG_DELETE_ON_CLOSE | FILE_ATTRIBUTE_TEMPORARY;
access |= DELETE;
}
- if (flags & _O_SHORT_LIVED) {
+ if (flags & UV_FS_O_SHORT_LIVED) {
attributes |= FILE_ATTRIBUTE_TEMPORARY;
}
- switch (flags & (_O_SEQUENTIAL | _O_RANDOM)) {
+ switch (flags & (UV_FS_O_SEQUENTIAL | UV_FS_O_RANDOM)) {
case 0:
break;
- case _O_SEQUENTIAL:
+ case UV_FS_O_SEQUENTIAL:
attributes |= FILE_FLAG_SEQUENTIAL_SCAN;
break;
- case _O_RANDOM:
+ case UV_FS_O_RANDOM:
attributes |= FILE_FLAG_RANDOM_ACCESS;
break;
default:
goto einval;
}
+ if (flags & UV_FS_O_DIRECT) {
+ /*
+ * FILE_APPEND_DATA and FILE_FLAG_NO_BUFFERING are mutually exclusive.
+ * Windows returns 87, ERROR_INVALID_PARAMETER if these are combined.
+ *
+ * FILE_APPEND_DATA is included in FILE_GENERIC_WRITE:
+ *
+ * FILE_GENERIC_WRITE = STANDARD_RIGHTS_WRITE |
+ * FILE_WRITE_DATA |
+ * FILE_WRITE_ATTRIBUTES |
+ * FILE_WRITE_EA |
+ * FILE_APPEND_DATA |
+ * SYNCHRONIZE
+ *
+ * Note: Appends are also permitted by FILE_WRITE_DATA.
+ *
+ * In order for direct writes and direct appends to succeed, we therefore
+ * exclude FILE_APPEND_DATA if FILE_WRITE_DATA is specified, and otherwise
+ * fail if the user's sole permission is a direct append, since this
+ * particular combination is invalid.
+ */
+ if (access & FILE_APPEND_DATA) {
+ if (access & FILE_WRITE_DATA) {
+ access &= ~FILE_APPEND_DATA;
+ } else {
+ goto einval;
+ }
+ }
+ attributes |= FILE_FLAG_NO_BUFFERING;
+ }
+
+ switch (flags & (UV_FS_O_DSYNC | UV_FS_O_SYNC)) {
+ case 0:
+ break;
+ case UV_FS_O_DSYNC:
+ case UV_FS_O_SYNC:
+ attributes |= FILE_FLAG_WRITE_THROUGH;
+ break;
+ default:
+ goto einval;
+ }
+
/* Setting this flag makes it possible to open a directory. */
attributes |= FILE_FLAG_BACKUP_SEMANTICS;
@@ -489,10 +561,10 @@ void fs__open(uv_fs_t* req) {
NULL);
if (file == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
- if (error == ERROR_FILE_EXISTS && (flags & _O_CREAT) &&
- !(flags & _O_EXCL)) {
- /* Special case: when ERROR_FILE_EXISTS happens and O_CREAT was */
- /* specified, it means the path referred to a directory. */
+ if (error == ERROR_FILE_EXISTS && (flags & UV_FS_O_CREAT) &&
+ !(flags & UV_FS_O_EXCL)) {
+ /* Special case: when ERROR_FILE_EXISTS happens and UV_FS_O_CREAT was
+ * specified, it means the path referred to a directory. */
SET_REQ_UV_ERROR(req, UV_EISDIR, error);
} else {
SET_REQ_WIN32_ERROR(req, GetLastError());
@@ -556,9 +628,14 @@ void fs__read(uv_fs_t* req) {
DWORD error;
int result;
unsigned int index;
+ LARGE_INTEGER original_position;
+ LARGE_INTEGER zero_offset;
+ int restore_position;
VERIFY_FD(fd, req);
+ zero_offset.QuadPart = 0;
+ restore_position = 0;
handle = uv__get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE) {
@@ -569,6 +646,10 @@ void fs__read(uv_fs_t* req) {
if (offset != -1) {
memset(&overlapped, 0, sizeof overlapped);
overlapped_ptr = &overlapped;
+ if (SetFilePointerEx(handle, zero_offset, &original_position,
+ FILE_CURRENT)) {
+ restore_position = 1;
+ }
} else {
overlapped_ptr = NULL;
}
@@ -593,6 +674,9 @@ void fs__read(uv_fs_t* req) {
++index;
} while (result && index < req->fs.info.nbufs);
+ if (restore_position)
+ SetFilePointerEx(handle, original_position, NULL, FILE_BEGIN);
+
if (result || bytes > 0) {
SET_REQ_RESULT(req, bytes);
} else {
@@ -615,9 +699,14 @@ void fs__write(uv_fs_t* req) {
DWORD bytes;
int result;
unsigned int index;
+ LARGE_INTEGER original_position;
+ LARGE_INTEGER zero_offset;
+ int restore_position;
VERIFY_FD(fd, req);
+ zero_offset.QuadPart = 0;
+ restore_position = 0;
handle = uv__get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE) {
SET_REQ_WIN32_ERROR(req, ERROR_INVALID_HANDLE);
@@ -627,6 +716,10 @@ void fs__write(uv_fs_t* req) {
if (offset != -1) {
memset(&overlapped, 0, sizeof overlapped);
overlapped_ptr = &overlapped;
+ if (SetFilePointerEx(handle, zero_offset, &original_position,
+ FILE_CURRENT)) {
+ restore_position = 1;
+ }
} else {
overlapped_ptr = NULL;
}
@@ -651,6 +744,9 @@ void fs__write(uv_fs_t* req) {
++index;
} while (result && index < req->fs.info.nbufs);
+ if (restore_position)
+ SetFilePointerEx(handle, original_position, NULL, FILE_BEGIN);
+
if (result || bytes > 0) {
SET_REQ_RESULT(req, bytes);
} else {
@@ -693,9 +789,9 @@ void fs__unlink(uv_fs_t* req) {
}
if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- /* Do not allow deletion of directories, unless it is a symlink. When */
- /* the path refers to a non-symlink directory, report EPERM as mandated */
- /* by POSIX.1. */
+ /* Do not allow deletion of directories, unless it is a symlink. When the
+ * path refers to a non-symlink directory, report EPERM as mandated by
+ * POSIX.1. */
/* Check if it is a reparse point. If it's not, it's a normal directory. */
if (!(info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
@@ -704,8 +800,8 @@ void fs__unlink(uv_fs_t* req) {
return;
}
- /* Read the reparse point and check if it is a valid symlink. */
- /* If not, don't unlink. */
+ /* Read the reparse point and check if it is a valid symlink. If not, don't
+ * unlink. */
if (fs__readlink_handle(handle, NULL, NULL) < 0) {
DWORD error = GetLastError();
if (error == ERROR_SYMLINK_NOT_SUPPORTED)
@@ -720,7 +816,8 @@ void fs__unlink(uv_fs_t* req) {
/* Remove read-only attribute */
FILE_BASIC_INFORMATION basic = { 0 };
- basic.FileAttributes = info.dwFileAttributes & ~(FILE_ATTRIBUTE_READONLY);
+ basic.FileAttributes = (info.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY) |
+ FILE_ATTRIBUTE_ARCHIVE;
status = pNtSetInformationFile(handle,
&iosb,
@@ -1029,7 +1126,8 @@ cleanup:
}
-INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf) {
+INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf,
+ int do_lstat) {
FILE_ALL_INFORMATION file_info;
FILE_FS_VOLUME_INFORMATION volume_info;
NTSTATUS nt_status;
@@ -1084,19 +1182,25 @@ INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf) {
*/
statbuf->st_mode = 0;
- if (file_info.BasicInformation.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
+ /*
+ * On Windows, FILE_ATTRIBUTE_REPARSE_POINT is a general purpose mechanism
+ * by which filesystem drivers can intercept and alter file system requests.
+ *
+ * The only reparse points we care about are symlinks and mount points, both
+ * of which are treated as POSIX symlinks. Further, we only care when
+ * invoked via lstat, which seeks information about the link instead of its
+ * target. Otherwise, reparse points must be treated as regular files.
+ */
+ if (do_lstat &&
+ (file_info.BasicInformation.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
/*
- * It is possible for a file to have FILE_ATTRIBUTE_REPARSE_POINT but not have
- * any link data. In that case DeviceIoControl() in fs__readlink_handle() sets
- * the last error to ERROR_NOT_A_REPARSE_POINT. Then the stat result mode
- * calculated below will indicate a normal directory or file, as if
- * FILE_ATTRIBUTE_REPARSE_POINT was not present.
+ * If reading the link fails, the reparse point is not a symlink and needs
+ * to be treated as a regular file. The higher level lstat function will
+ * detect this failure and retry without do_lstat if appropriate.
*/
- if (fs__readlink_handle(handle, NULL, &statbuf->st_size) == 0) {
- statbuf->st_mode |= S_IFLNK;
- } else if (GetLastError() != ERROR_NOT_A_REPARSE_POINT) {
+ if (fs__readlink_handle(handle, NULL, &statbuf->st_size) != 0)
return -1;
- }
+ statbuf->st_mode |= S_IFLNK;
}
if (statbuf->st_mode == 0) {
@@ -1124,7 +1228,7 @@ INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf) {
/* st_blocks contains the on-disk allocation size in 512-byte units. */
statbuf->st_blocks =
- file_info.StandardInformation.AllocationSize.QuadPart >> 9ULL;
+ (uint64_t) file_info.StandardInformation.AllocationSize.QuadPart >> 9;
statbuf->st_nlink = file_info.StandardInformation.NumberOfLinks;
@@ -1139,8 +1243,12 @@ INLINE static int fs__stat_handle(HANDLE handle, uv_stat_t* statbuf) {
*
* Therefore we'll just report a sensible value that's quite commonly okay
* on modern hardware.
+ *
+ * 4096 is the minimum required to be compatible with newer Advanced Format
+ * drives (which have 4096 bytes per physical sector), and to be backwards
+ * compatible with older drives (which have 512 bytes per physical sector).
*/
- statbuf->st_blksize = 2048;
+ statbuf->st_blksize = 4096;
/* Todo: set st_flags to something meaningful. Also provide a wrapper for
* chattr(2).
@@ -1191,9 +1299,11 @@ INLINE static void fs__stat_impl(uv_fs_t* req, int do_lstat) {
return;
}
- if (fs__stat_handle(handle, &req->statbuf) != 0) {
+ if (fs__stat_handle(handle, &req->statbuf, do_lstat) != 0) {
DWORD error = GetLastError();
- if (do_lstat && error == ERROR_SYMLINK_NOT_SUPPORTED) {
+ if (do_lstat &&
+ (error == ERROR_SYMLINK_NOT_SUPPORTED ||
+ error == ERROR_NOT_A_REPARSE_POINT)) {
/* We opened a reparse point but it was not a symlink. Try again. */
fs__stat_impl(req, 0);
@@ -1237,7 +1347,7 @@ static void fs__fstat(uv_fs_t* req) {
return;
}
- if (fs__stat_handle(handle, &req->statbuf) != 0) {
+ if (fs__stat_handle(handle, &req->statbuf, 0) != 0) {
SET_REQ_WIN32_ERROR(req, GetLastError());
return;
}
@@ -1309,6 +1419,28 @@ static void fs__ftruncate(uv_fs_t* req) {
}
+static void fs__copyfile(uv_fs_t* req) {
+ int flags;
+ int overwrite;
+
+ flags = req->fs.info.file_flags;
+
+ if (flags & UV_FS_COPYFILE_FICLONE_FORCE) {
+ SET_REQ_UV_ERROR(req, UV_ENOSYS, ERROR_NOT_SUPPORTED);
+ return;
+ }
+
+ overwrite = flags & UV_FS_COPYFILE_EXCL;
+
+ if (CopyFileW(req->file.pathw, req->fs.info.new_pathw, overwrite) == 0) {
+ SET_REQ_WIN32_ERROR(req, GetLastError());
+ return;
+ }
+
+ SET_REQ_RESULT(req, 0);
+}
+
+
static void fs__sendfile(uv_fs_t* req) {
int fd_in = req->file.fd, fd_out = req->fs.info.fd_out;
size_t length = req->fs.info.bufsml[0].len;
@@ -1390,6 +1522,7 @@ static void fs__chmod(uv_fs_t* req) {
static void fs__fchmod(uv_fs_t* req) {
int fd = req->file.fd;
+ int clear_archive_flag;
HANDLE handle;
NTSTATUS nt_status;
IO_STATUS_BLOCK io_status;
@@ -1397,7 +1530,11 @@ static void fs__fchmod(uv_fs_t* req) {
VERIFY_FD(fd, req);
- handle = uv__get_osfhandle(fd);
+ handle = ReOpenFile(uv__get_osfhandle(fd), FILE_WRITE_ATTRIBUTES, 0, 0);
+ if (handle == INVALID_HANDLE_VALUE) {
+ SET_REQ_WIN32_ERROR(req, GetLastError());
+ return;
+ }
nt_status = pNtQueryInformationFile(handle,
&io_status,
@@ -1407,7 +1544,27 @@ static void fs__fchmod(uv_fs_t* req) {
if (!NT_SUCCESS(nt_status)) {
SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status));
- return;
+ goto fchmod_cleanup;
+ }
+
+ /* Test if the Archive attribute is cleared */
+ if ((file_info.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == 0) {
+ /* Set Archive flag, otherwise setting or clearing the read-only
+ flag will not work */
+ file_info.FileAttributes |= FILE_ATTRIBUTE_ARCHIVE;
+ nt_status = pNtSetInformationFile(handle,
+ &io_status,
+ &file_info,
+ sizeof file_info,
+ FileBasicInformation);
+ if (!NT_SUCCESS(nt_status)) {
+ SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status));
+ goto fchmod_cleanup;
+ }
+ /* Remeber to clear the flag later on */
+ clear_archive_flag = 1;
+ } else {
+ clear_archive_flag = 0;
}
if (req->fs.info.mode & _S_IWRITE) {
@@ -1424,10 +1581,28 @@ static void fs__fchmod(uv_fs_t* req) {
if (!NT_SUCCESS(nt_status)) {
SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status));
- return;
+ goto fchmod_cleanup;
+ }
+
+ if (clear_archive_flag) {
+ file_info.FileAttributes &= ~FILE_ATTRIBUTE_ARCHIVE;
+ if (file_info.FileAttributes == 0) {
+ file_info.FileAttributes = FILE_ATTRIBUTE_NORMAL;
+ }
+ nt_status = pNtSetInformationFile(handle,
+ &io_status,
+ &file_info,
+ sizeof file_info,
+ FileBasicInformation);
+ if (!NT_SUCCESS(nt_status)) {
+ SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status));
+ goto fchmod_cleanup;
+ }
}
SET_REQ_SUCCESS(req);
+fchmod_cleanup:
+ CloseHandle(handle);
}
@@ -1675,25 +1850,42 @@ error:
static void fs__symlink(uv_fs_t* req) {
- WCHAR* pathw = req->file.pathw;
- WCHAR* new_pathw = req->fs.info.new_pathw;
- int flags = req->fs.info.file_flags;
- int result;
+ WCHAR* pathw;
+ WCHAR* new_pathw;
+ int flags;
+ int err;
+ pathw = req->file.pathw;
+ new_pathw = req->fs.info.new_pathw;
- if (flags & UV_FS_SYMLINK_JUNCTION) {
+ if (req->fs.info.file_flags & UV_FS_SYMLINK_JUNCTION) {
fs__create_junction(req, pathw, new_pathw);
- } else if (pCreateSymbolicLinkW) {
- result = pCreateSymbolicLinkW(new_pathw,
- pathw,
- flags & UV_FS_SYMLINK_DIR ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0) ? 0 : -1;
- if (result == -1) {
- SET_REQ_WIN32_ERROR(req, GetLastError());
- } else {
- SET_REQ_RESULT(req, result);
- }
+ return;
+ }
+
+ if (req->fs.info.file_flags & UV_FS_SYMLINK_DIR)
+ flags = SYMBOLIC_LINK_FLAG_DIRECTORY | uv__file_symlink_usermode_flag;
+ else
+ flags = uv__file_symlink_usermode_flag;
+
+ if (CreateSymbolicLinkW(new_pathw, pathw, flags)) {
+ SET_REQ_RESULT(req, 0);
+ return;
+ }
+
+ /* Something went wrong. We will test if it is because of user-mode
+ * symlinks.
+ */
+ err = GetLastError();
+ if (err == ERROR_INVALID_PARAMETER &&
+ flags & SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE) {
+ /* This system does not support user-mode symlinks. We will clear the
+ * unsupported flag and retry.
+ */
+ uv__file_symlink_usermode_flag = 0;
+ fs__symlink(req);
} else {
- SET_REQ_UV_ERROR(req, UV_ENOSYS, ERROR_NOT_SUPPORTED);
+ SET_REQ_WIN32_ERROR(req, err);
}
}
@@ -1727,13 +1919,13 @@ static void fs__readlink(uv_fs_t* req) {
}
-static size_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
+static ssize_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
int r;
DWORD w_realpath_len;
WCHAR* w_realpath_ptr = NULL;
WCHAR* w_realpath_buf;
- w_realpath_len = pGetFinalPathNameByHandleW(handle, NULL, 0, VOLUME_NAME_DOS);
+ w_realpath_len = GetFinalPathNameByHandleW(handle, NULL, 0, VOLUME_NAME_DOS);
if (w_realpath_len == 0) {
return -1;
}
@@ -1745,10 +1937,8 @@ static size_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
}
w_realpath_ptr = w_realpath_buf;
- if (pGetFinalPathNameByHandleW(handle,
- w_realpath_ptr,
- w_realpath_len,
- VOLUME_NAME_DOS) == 0) {
+ if (GetFinalPathNameByHandleW(
+ handle, w_realpath_ptr, w_realpath_len, VOLUME_NAME_DOS) == 0) {
uv__free(w_realpath_buf);
SetLastError(ERROR_INVALID_HANDLE);
return -1;
@@ -1780,11 +1970,6 @@ static size_t fs__realpath_handle(HANDLE handle, char** realpath_ptr) {
static void fs__realpath(uv_fs_t* req) {
HANDLE handle;
- if (!pGetFinalPathNameByHandleW) {
- SET_REQ_UV_ERROR(req, UV_ENOSYS, ERROR_NOT_SUPPORTED);
- return;
- }
-
handle = CreateFileW(req->file.pathw,
0,
0,
@@ -1819,6 +2004,10 @@ static void fs__fchown(uv_fs_t* req) {
}
+static void fs__lchown(uv_fs_t* req) {
+ req->result = 0;
+}
+
static void uv__fs_work(struct uv__work* w) {
uv_fs_t* req;
@@ -1831,6 +2020,7 @@ static void uv__fs_work(struct uv__work* w) {
XX(CLOSE, close)
XX(READ, read)
XX(WRITE, write)
+ XX(COPYFILE, copyfile)
XX(SENDFILE, sendfile)
XX(STAT, stat)
XX(LSTAT, lstat)
@@ -1855,6 +2045,7 @@ static void uv__fs_work(struct uv__work* w) {
XX(REALPATH, realpath)
XX(CHOWN, chown)
XX(FCHOWN, fchown);
+ XX(LCHOWN, lchown);
default:
assert(!"bad uv_fs_type");
}
@@ -1877,6 +2068,9 @@ static void uv__fs_done(struct uv__work* w, int status) {
void uv_fs_req_cleanup(uv_fs_t* req) {
+ if (req == NULL)
+ return;
+
if (req->flags & UV_FS_CLEANEDUP)
return;
@@ -1907,8 +2101,7 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
int mode, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_OPEN, cb);
-
+ INIT(UV_FS_OPEN);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
@@ -1916,28 +2109,14 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
req->fs.info.file_flags = flags;
req->fs.info.mode = mode;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__open(req);
- return req->result;
- }
+ POST;
}
int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_CLOSE, cb);
+ INIT(UV_FS_CLOSE);
req->file.fd = fd;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__close(req);
- return req->result;
- }
+ POST;
}
@@ -1948,11 +2127,11 @@ int uv_fs_read(uv_loop_t* loop,
unsigned int nbufs,
int64_t offset,
uv_fs_cb cb) {
+ INIT(UV_FS_READ);
+
if (bufs == NULL || nbufs == 0)
return UV_EINVAL;
- uv_fs_req_init(loop, req, UV_FS_READ, cb);
-
req->file.fd = fd;
req->fs.info.nbufs = nbufs;
@@ -1966,14 +2145,7 @@ int uv_fs_read(uv_loop_t* loop,
memcpy(req->fs.info.bufs, bufs, nbufs * sizeof(*bufs));
req->fs.info.offset = offset;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__read(req);
- return req->result;
- }
+ POST;
}
@@ -1984,11 +2156,11 @@ int uv_fs_write(uv_loop_t* loop,
unsigned int nbufs,
int64_t offset,
uv_fs_cb cb) {
+ INIT(UV_FS_WRITE);
+
if (bufs == NULL || nbufs == 0)
return UV_EINVAL;
- uv_fs_req_init(loop, req, UV_FS_WRITE, cb);
-
req->file.fd = fd;
req->fs.info.nbufs = nbufs;
@@ -2002,14 +2174,7 @@ int uv_fs_write(uv_loop_t* loop,
memcpy(req->fs.info.bufs, bufs, nbufs * sizeof(*bufs));
req->fs.info.offset = offset;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__write(req);
- return req->result;
- }
+ POST;
}
@@ -2017,20 +2182,13 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_UNLINK, cb);
-
+ INIT(UV_FS_UNLINK);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__unlink(req);
- return req->result;
- }
+ POST;
}
@@ -2038,22 +2196,14 @@ int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_MKDIR, cb);
-
+ INIT(UV_FS_MKDIR);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
req->fs.info.mode = mode;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__mkdir(req);
- return req->result;
- }
+ POST;
}
@@ -2061,39 +2211,25 @@ int uv_fs_mkdtemp(uv_loop_t* loop, uv_fs_t* req, const char* tpl,
uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_MKDTEMP, cb);
-
+ INIT(UV_FS_MKDTEMP);
err = fs__capture_path(req, tpl, NULL, TRUE);
if (err)
return uv_translate_sys_error(err);
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__mkdtemp(req);
- return req->result;
- }
+ POST;
}
int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_RMDIR, cb);
-
+ INIT(UV_FS_RMDIR);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__rmdir(req);
- return req->result;
- }
+ POST;
}
@@ -2101,22 +2237,14 @@ int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_SCANDIR, cb);
-
+ INIT(UV_FS_SCANDIR);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
req->fs.info.file_flags = flags;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__scandir(req);
- return req->result;
- }
+ POST;
}
@@ -2124,20 +2252,13 @@ int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_LINK, cb);
-
+ INIT(UV_FS_LINK);
err = fs__capture_path(req, path, new_path, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__link(req);
- return req->result;
- }
+ POST;
}
@@ -2145,22 +2266,14 @@ int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, int flags, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_SYMLINK, cb);
-
+ INIT(UV_FS_SYMLINK);
err = fs__capture_path(req, path, new_path, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
req->fs.info.file_flags = flags;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__symlink(req);
- return req->result;
- }
+ POST;
}
@@ -2168,20 +2281,13 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_READLINK, cb);
-
+ INIT(UV_FS_READLINK);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__readlink(req);
- return req->result;
- }
+ POST;
}
@@ -2189,24 +2295,18 @@ int uv_fs_realpath(uv_loop_t* loop, uv_fs_t* req, const char* path,
uv_fs_cb cb) {
int err;
- if (!req || !path) {
+ INIT(UV_FS_REALPATH);
+
+ if (!path) {
return UV_EINVAL;
}
- uv_fs_req_init(loop, req, UV_FS_REALPATH, cb);
-
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__realpath(req);
- return req->result;
- }
+ POST;
}
@@ -2214,88 +2314,66 @@ int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid,
uv_gid_t gid, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_CHOWN, cb);
-
+ INIT(UV_FS_CHOWN);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__chown(req);
- return req->result;
- }
+ POST;
}
int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_uid_t uid,
uv_gid_t gid, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_FCHOWN, cb);
+ INIT(UV_FS_FCHOWN);
+ POST;
+}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__fchown(req);
- return req->result;
+
+int uv_fs_lchown(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_uid_t uid,
+ uv_gid_t gid, uv_fs_cb cb) {
+ int err;
+
+ INIT(UV_FS_LCHOWN);
+ err = fs__capture_path(req, path, NULL, cb != NULL);
+ if (err) {
+ return uv_translate_sys_error(err);
}
+ POST;
}
int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_STAT, cb);
-
+ INIT(UV_FS_STAT);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__stat(req);
- return req->result;
- }
+ POST;
}
int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_LSTAT, cb);
-
+ INIT(UV_FS_LSTAT);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__lstat(req);
- return req->result;
- }
+ POST;
}
int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_FSTAT, cb);
+ INIT(UV_FS_FSTAT);
req->file.fd = fd;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__fstat(req);
- return req->result;
- }
+ POST;
}
@@ -2303,85 +2381,73 @@ int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_RENAME, cb);
-
+ INIT(UV_FS_RENAME);
err = fs__capture_path(req, path, new_path, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__rename(req);
- return req->result;
- }
+ POST;
}
int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_FSYNC, cb);
+ INIT(UV_FS_FSYNC);
req->file.fd = fd;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__fsync(req);
- return req->result;
- }
+ POST;
}
int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file fd, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_FDATASYNC, cb);
+ INIT(UV_FS_FDATASYNC);
req->file.fd = fd;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__fdatasync(req);
- return req->result;
- }
+ POST;
}
int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file fd,
int64_t offset, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_FTRUNCATE, cb);
-
+ INIT(UV_FS_FTRUNCATE);
req->file.fd = fd;
req->fs.info.offset = offset;
+ POST;
+}
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__ftruncate(req);
- return req->result;
+
+int uv_fs_copyfile(uv_loop_t* loop,
+ uv_fs_t* req,
+ const char* path,
+ const char* new_path,
+ int flags,
+ uv_fs_cb cb) {
+ int err;
+
+ INIT(UV_FS_COPYFILE);
+
+ if (flags & ~(UV_FS_COPYFILE_EXCL |
+ UV_FS_COPYFILE_FICLONE |
+ UV_FS_COPYFILE_FICLONE_FORCE)) {
+ return UV_EINVAL;
}
-}
+ err = fs__capture_path(req, path, new_path, cb != NULL);
+
+ if (err)
+ return uv_translate_sys_error(err);
+
+ req->fs.info.file_flags = flags;
+ POST;
+}
int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file fd_out,
uv_file fd_in, int64_t in_offset, size_t length, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_SENDFILE, cb);
-
+ INIT(UV_FS_SENDFILE);
req->file.fd = fd_in;
req->fs.info.fd_out = fd_out;
req->fs.info.offset = in_offset;
req->fs.info.bufsml[0].len = length;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__sendfile(req);
- return req->result;
- }
+ POST;
}
@@ -2392,21 +2458,13 @@ int uv_fs_access(uv_loop_t* loop,
uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_ACCESS, cb);
-
+ INIT(UV_FS_ACCESS);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err)
return uv_translate_sys_error(err);
req->fs.info.mode = flags;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- }
-
- fs__access(req);
- return req->result;
+ POST;
}
@@ -2414,39 +2472,23 @@ int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path, int mode,
uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_CHMOD, cb);
-
+ INIT(UV_FS_CHMOD);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
}
req->fs.info.mode = mode;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__chmod(req);
- return req->result;
- }
+ POST;
}
int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file fd, int mode,
uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_FCHMOD, cb);
-
+ INIT(UV_FS_FCHMOD);
req->file.fd = fd;
req->fs.info.mode = mode;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__fchmod(req);
- return req->result;
- }
+ POST;
}
@@ -2454,8 +2496,7 @@ int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
double mtime, uv_fs_cb cb) {
int err;
- uv_fs_req_init(loop, req, UV_FS_UTIME, cb);
-
+ INIT(UV_FS_UTIME);
err = fs__capture_path(req, path, NULL, cb != NULL);
if (err) {
return uv_translate_sys_error(err);
@@ -2463,30 +2504,15 @@ int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
req->fs.time.atime = atime;
req->fs.time.mtime = mtime;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__utime(req);
- return req->result;
- }
+ POST;
}
int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file fd, double atime,
double mtime, uv_fs_cb cb) {
- uv_fs_req_init(loop, req, UV_FS_FUTIME, cb);
-
+ INIT(UV_FS_FUTIME);
req->file.fd = fd;
req->fs.time.atime = atime;
req->fs.time.mtime = mtime;
-
- if (cb) {
- QUEUE_FS_TP_JOB(loop, req);
- return 0;
- } else {
- fs__futime(req);
- return req->result;
- }
+ POST;
}
diff --git a/Utilities/cmlibuv/src/win/getaddrinfo.c b/Utilities/cmlibuv/src/win/getaddrinfo.c
index baab83889..dfab860a7 100644
--- a/Utilities/cmlibuv/src/win/getaddrinfo.c
+++ b/Utilities/cmlibuv/src/win/getaddrinfo.c
@@ -24,10 +24,13 @@
#include "uv.h"
#include "internal.h"
#include "req-inl.h"
+#include "idna.h"
/* EAI_* constants. */
#include <winsock2.h>
+/* Needed for ConvertInterfaceIndexToLuid and ConvertInterfaceLuidToNameA */
+#include <iphlpapi.h>
int uv__getaddrinfo_translate_error(int sys_err) {
switch (sys_err) {
@@ -69,10 +72,13 @@ int uv__getaddrinfo_translate_error(int sys_err) {
#endif
-/* adjust size value to be multiple of 4. Use to keep pointer aligned */
-/* Do we need different versions of this for different architectures? */
+/* Adjust size value to be multiple of 4. Use to keep pointer aligned.
+ * Do we need different versions of this for different architectures? */
#define ALIGNED_SIZE(X) ((((X) + 3) >> 2) << 2)
+#ifndef NDIS_IF_MAX_STRING_SIZE
+#define NDIS_IF_MAX_STRING_SIZE IF_MAX_STRING_SIZE
+#endif
static void uv__getaddrinfo_work(struct uv__work* w) {
uv_getaddrinfo_t* req;
@@ -119,8 +125,7 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
}
if (req->retcode == 0) {
- /* convert addrinfoW to addrinfo */
- /* first calculate required length */
+ /* Convert addrinfoW to addrinfo. First calculate required length. */
addrinfow_ptr = req->addrinfow;
while (addrinfow_ptr != NULL) {
addrinfo_len += addrinfo_struct_len +
@@ -255,11 +260,13 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* node,
const char* service,
const struct addrinfo* hints) {
+ char hostname_ascii[256];
int nodesize = 0;
int servicesize = 0;
int hintssize = 0;
char* alloc_ptr = NULL;
int err;
+ long rc;
if (req == NULL || (node == NULL && service == NULL)) {
return UV_EINVAL;
@@ -273,12 +280,19 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* calculate required memory size for all input values */
if (node != NULL) {
- nodesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, 0, node, -1, NULL, 0) *
- sizeof(WCHAR));
+ rc = uv__idna_toascii(node,
+ node + strlen(node),
+ hostname_ascii,
+ hostname_ascii + sizeof(hostname_ascii));
+ if (rc < 0)
+ return rc;
+ nodesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, 0, hostname_ascii,
+ -1, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) {
err = GetLastError();
goto error;
}
+ node = hostname_ascii;
}
if (service != NULL) {
@@ -308,8 +322,8 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* save alloc_ptr now so we can free if error */
req->alloc = (void*)alloc_ptr;
- /* convert node string to UTF16 into allocated memory and save pointer in */
- /* the request. */
+ /* Convert node string to UTF16 into allocated memory and save pointer in the
+ * request. */
if (node != NULL) {
req->node = (WCHAR*)alloc_ptr;
if (MultiByteToWideChar(CP_UTF8,
@@ -326,8 +340,8 @@ int uv_getaddrinfo(uv_loop_t* loop,
req->node = NULL;
}
- /* convert service string to UTF16 into allocated memory and save pointer */
- /* in the req. */
+ /* Convert service string to UTF16 into allocated memory and save pointer in
+ * the req. */
if (service != NULL) {
req->service = (WCHAR*)alloc_ptr;
if (MultiByteToWideChar(CP_UTF8,
@@ -364,6 +378,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
if (getaddrinfo_cb) {
uv__work_submit(loop,
&req->work_req,
+ UV__WORK_SLOW_IO,
uv__getaddrinfo_work,
uv__getaddrinfo_done);
return 0;
@@ -380,3 +395,69 @@ error:
}
return uv_translate_sys_error(err);
}
+
+int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
+ NET_LUID luid;
+ wchar_t wname[NDIS_IF_MAX_STRING_SIZE + 1]; /* Add one for the NUL. */
+ DWORD bufsize;
+ int r;
+
+ if (buffer == NULL || size == NULL || *size == 0)
+ return UV_EINVAL;
+
+ r = ConvertInterfaceIndexToLuid(ifindex, &luid);
+
+ if (r != 0)
+ return uv_translate_sys_error(r);
+
+ r = ConvertInterfaceLuidToNameW(&luid, wname, ARRAY_SIZE(wname));
+
+ if (r != 0)
+ return uv_translate_sys_error(r);
+
+ /* Check how much space we need */
+ bufsize = WideCharToMultiByte(CP_UTF8, 0, wname, -1, NULL, 0, NULL, NULL);
+
+ if (bufsize == 0) {
+ return uv_translate_sys_error(GetLastError());
+ } else if (bufsize > *size) {
+ *size = bufsize;
+ return UV_ENOBUFS;
+ }
+
+ /* Convert to UTF-8 */
+ bufsize = WideCharToMultiByte(CP_UTF8,
+ 0,
+ wname,
+ -1,
+ buffer,
+ *size,
+ NULL,
+ NULL);
+
+ if (bufsize == 0)
+ return uv_translate_sys_error(GetLastError());
+
+ *size = bufsize - 1;
+ return 0;
+}
+
+int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) {
+ int r;
+
+ if (buffer == NULL || size == NULL || *size == 0)
+ return UV_EINVAL;
+
+ r = snprintf(buffer, *size, "%d", ifindex);
+
+ if (r < 0)
+ return uv_translate_sys_error(r);
+
+ if (r >= (int) *size) {
+ *size = r + 1;
+ return UV_ENOBUFS;
+ }
+
+ *size = r;
+ return 0;
+}
diff --git a/Utilities/cmlibuv/src/win/getnameinfo.c b/Utilities/cmlibuv/src/win/getnameinfo.c
index 9f10cd2a5..b3773380c 100644
--- a/Utilities/cmlibuv/src/win/getnameinfo.c
+++ b/Utilities/cmlibuv/src/win/getnameinfo.c
@@ -42,7 +42,7 @@ static void uv__getnameinfo_work(struct uv__work* w) {
uv_getnameinfo_t* req;
WCHAR host[NI_MAXHOST];
WCHAR service[NI_MAXSERV];
- int ret = 0;
+ int ret;
req = container_of(w, uv_getnameinfo_t, work_req);
if (GetNameInfoW((struct sockaddr*)&req->storage,
@@ -53,27 +53,34 @@ static void uv__getnameinfo_work(struct uv__work* w) {
ARRAY_SIZE(service),
req->flags)) {
ret = WSAGetLastError();
+ req->retcode = uv__getaddrinfo_translate_error(ret);
+ return;
+ }
+
+ ret = WideCharToMultiByte(CP_UTF8,
+ 0,
+ host,
+ -1,
+ req->host,
+ sizeof(req->host),
+ NULL,
+ NULL);
+ if (ret == 0) {
+ req->retcode = uv_translate_sys_error(GetLastError());
+ return;
+ }
+
+ ret = WideCharToMultiByte(CP_UTF8,
+ 0,
+ service,
+ -1,
+ req->service,
+ sizeof(req->service),
+ NULL,
+ NULL);
+ if (ret == 0) {
+ req->retcode = uv_translate_sys_error(GetLastError());
}
- req->retcode = uv__getaddrinfo_translate_error(ret);
-
- /* convert results to UTF-8 */
- WideCharToMultiByte(CP_UTF8,
- 0,
- host,
- -1,
- req->host,
- sizeof(req->host),
- NULL,
- NULL);
-
- WideCharToMultiByte(CP_UTF8,
- 0,
- service,
- -1,
- req->service,
- sizeof(req->service),
- NULL,
- NULL);
}
@@ -138,6 +145,7 @@ int uv_getnameinfo(uv_loop_t* loop,
if (getnameinfo_cb) {
uv__work_submit(loop,
&req->work_req,
+ UV__WORK_SLOW_IO,
uv__getnameinfo_work,
uv__getnameinfo_done);
return 0;
diff --git a/Utilities/cmlibuv/src/win/handle-inl.h b/Utilities/cmlibuv/src/win/handle-inl.h
index 8d0334cc5..82c657d57 100644
--- a/Utilities/cmlibuv/src/win/handle-inl.h
+++ b/Utilities/cmlibuv/src/win/handle-inl.h
@@ -32,7 +32,7 @@
#define DECREASE_ACTIVE_COUNT(loop, handle) \
do { \
if (--(handle)->activecnt == 0 && \
- !((handle)->flags & UV__HANDLE_CLOSING)) { \
+ !((handle)->flags & UV_HANDLE_CLOSING)) { \
uv__handle_stop((handle)); \
} \
assert((handle)->activecnt >= 0); \
@@ -53,7 +53,7 @@
assert(handle->reqs_pending > 0); \
handle->reqs_pending--; \
\
- if (handle->flags & UV__HANDLE_CLOSING && \
+ if (handle->flags & UV_HANDLE_CLOSING && \
handle->reqs_pending == 0) { \
uv_want_endgame(loop, (uv_handle_t*)handle); \
} \
@@ -62,14 +62,14 @@
#define uv__handle_closing(handle) \
do { \
- assert(!((handle)->flags & UV__HANDLE_CLOSING)); \
+ assert(!((handle)->flags & UV_HANDLE_CLOSING)); \
\
- if (!(((handle)->flags & UV__HANDLE_ACTIVE) && \
- ((handle)->flags & UV__HANDLE_REF))) \
+ if (!(((handle)->flags & UV_HANDLE_ACTIVE) && \
+ ((handle)->flags & UV_HANDLE_REF))) \
uv__active_handle_add((uv_handle_t*) (handle)); \
\
- (handle)->flags |= UV__HANDLE_CLOSING; \
- (handle)->flags &= ~UV__HANDLE_ACTIVE; \
+ (handle)->flags |= UV_HANDLE_CLOSING; \
+ (handle)->flags &= ~UV_HANDLE_ACTIVE; \
} while (0)
@@ -126,7 +126,8 @@ INLINE static void uv_process_endgames(uv_loop_t* loop) {
break;
case UV_TIMER:
- uv_timer_endgame(loop, (uv_timer_t*) handle);
+ uv__timer_close((uv_timer_t*) handle);
+ uv__handle_close(handle);
break;
case UV_PREPARE:
@@ -164,10 +165,10 @@ INLINE static void uv_process_endgames(uv_loop_t* loop) {
INLINE static HANDLE uv__get_osfhandle(int fd)
{
- /* _get_osfhandle() raises an assert in debug builds if the FD is invalid. */
- /* But it also correctly checks the FD and returns INVALID_HANDLE_VALUE */
- /* for invalid FDs in release builds (or if you let the assert continue). */
- /* So this wrapper function disables asserts when calling _get_osfhandle. */
+ /* _get_osfhandle() raises an assert in debug builds if the FD is invalid.
+ * But it also correctly checks the FD and returns INVALID_HANDLE_VALUE for
+ * invalid FDs in release builds (or if you let the assert continue). So this
+ * wrapper function disables asserts when calling _get_osfhandle. */
HANDLE handle;
UV_BEGIN_DISABLE_CRT_ASSERT();
diff --git a/Utilities/cmlibuv/src/win/handle.c b/Utilities/cmlibuv/src/win/handle.c
index 72b49d979..9d76c3f54 100644
--- a/Utilities/cmlibuv/src/win/handle.c
+++ b/Utilities/cmlibuv/src/win/handle.c
@@ -59,15 +59,15 @@ uv_handle_type uv_guess_handle(uv_file file) {
int uv_is_active(const uv_handle_t* handle) {
- return (handle->flags & UV__HANDLE_ACTIVE) &&
- !(handle->flags & UV__HANDLE_CLOSING);
+ return (handle->flags & UV_HANDLE_ACTIVE) &&
+ !(handle->flags & UV_HANDLE_CLOSING);
}
void uv_close(uv_handle_t* handle, uv_close_cb cb) {
uv_loop_t* loop = handle->loop;
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
assert(0);
return;
}
@@ -150,5 +150,14 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
int uv_is_closing(const uv_handle_t* handle) {
- return !!(handle->flags & (UV__HANDLE_CLOSING | UV_HANDLE_CLOSED));
+ return !!(handle->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED));
+}
+
+
+uv_os_fd_t uv_get_osfhandle(int fd) {
+ return uv__get_osfhandle(fd);
+}
+
+int uv_open_osfhandle(uv_os_fd_t os_fd) {
+ return _open_osfhandle((intptr_t) os_fd, 0);
}
diff --git a/Utilities/cmlibuv/src/win/internal.h b/Utilities/cmlibuv/src/win/internal.h
index 83601d57a..206ab5f62 100644
--- a/Utilities/cmlibuv/src/win/internal.h
+++ b/Utilities/cmlibuv/src/win/internal.h
@@ -29,7 +29,7 @@
#include "uv.h"
#include "../uv-common.h"
-#include "tree.h"
+#include "uv/tree.h"
#include "winapi.h"
#include "winsock.h"
@@ -62,77 +62,19 @@ extern UV_THREAD_LOCAL int uv__crt_assert_enabled;
#endif
/*
- * Handles
- * (also see handle-inl.h)
- */
-
-/* Used by all handles. */
-#define UV_HANDLE_CLOSED 0x00000002
-#define UV_HANDLE_ENDGAME_QUEUED 0x00000008
-
-/* uv-common.h: #define UV__HANDLE_CLOSING 0x00000001 */
-/* uv-common.h: #define UV__HANDLE_ACTIVE 0x00000040 */
-/* uv-common.h: #define UV__HANDLE_REF 0x00000020 */
-/* uv-common.h: #define UV_HANDLE_INTERNAL 0x00000080 */
-
-/* Used by streams and UDP handles. */
-#define UV_HANDLE_READING 0x00000100
-#define UV_HANDLE_BOUND 0x00000200
-#define UV_HANDLE_LISTENING 0x00000800
-#define UV_HANDLE_CONNECTION 0x00001000
-#define UV_HANDLE_READABLE 0x00008000
-#define UV_HANDLE_WRITABLE 0x00010000
-#define UV_HANDLE_READ_PENDING 0x00020000
-#define UV_HANDLE_SYNC_BYPASS_IOCP 0x00040000
-#define UV_HANDLE_ZERO_READ 0x00080000
-#define UV_HANDLE_EMULATE_IOCP 0x00100000
-#define UV_HANDLE_BLOCKING_WRITES 0x00200000
-#define UV_HANDLE_CANCELLATION_PENDING 0x00400000
-
-/* Used by uv_tcp_t and uv_udp_t handles */
-#define UV_HANDLE_IPV6 0x01000000
-
-/* Only used by uv_tcp_t handles. */
-#define UV_HANDLE_TCP_NODELAY 0x02000000
-#define UV_HANDLE_TCP_KEEPALIVE 0x04000000
-#define UV_HANDLE_TCP_SINGLE_ACCEPT 0x08000000
-#define UV_HANDLE_TCP_ACCEPT_STATE_CHANGING 0x10000000
-#define UV_HANDLE_TCP_SOCKET_CLOSED 0x20000000
-#define UV_HANDLE_SHARED_TCP_SOCKET 0x40000000
-
-/* Only used by uv_pipe_t handles. */
-#define UV_HANDLE_NON_OVERLAPPED_PIPE 0x01000000
-#define UV_HANDLE_PIPESERVER 0x02000000
-#define UV_HANDLE_PIPE_READ_CANCELABLE 0x04000000
-
-/* Only used by uv_tty_t handles. */
-#define UV_HANDLE_TTY_READABLE 0x01000000
-#define UV_HANDLE_TTY_RAW 0x02000000
-#define UV_HANDLE_TTY_SAVED_POSITION 0x04000000
-#define UV_HANDLE_TTY_SAVED_ATTRIBUTES 0x08000000
-
-/* Only used by uv_poll_t handles. */
-#define UV_HANDLE_POLL_SLOW 0x02000000
-
-
-/*
- * Requests: see req-inl.h
- */
-
-
-/*
- * Streams: see stream-inl.h
- */
-
-
-/*
* TCP
*/
+typedef enum {
+ UV__IPC_SOCKET_XFER_NONE = 0,
+ UV__IPC_SOCKET_XFER_TCP_CONNECTION,
+ UV__IPC_SOCKET_XFER_TCP_SERVER
+} uv__ipc_socket_xfer_type_t;
+
typedef struct {
WSAPROTOCOL_INFOW socket_info;
- int delayed_error;
-} uv__ipc_socket_info_ex;
+ uint32_t delayed_error;
+} uv__ipc_socket_xfer_info_t;
int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb);
int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client);
@@ -154,11 +96,13 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
void uv_tcp_close(uv_loop_t* loop, uv_tcp_t* tcp);
void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle);
-int uv_tcp_import(uv_tcp_t* tcp, uv__ipc_socket_info_ex* socket_info_ex,
- int tcp_connection);
-
-int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
- LPWSAPROTOCOL_INFOW protocol_info);
+int uv__tcp_xfer_export(uv_tcp_t* handle,
+ int pid,
+ uv__ipc_socket_xfer_type_t* xfer_type,
+ uv__ipc_socket_xfer_info_t* xfer_info);
+int uv__tcp_xfer_import(uv_tcp_t* tcp,
+ uv__ipc_socket_xfer_type_t xfer_type,
+ uv__ipc_socket_xfer_info_t* xfer_info);
/*
@@ -182,14 +126,14 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client);
int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb,
uv_read_cb read_cb);
-int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
- const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb);
-int uv_pipe_write2(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
- const uv_buf_t bufs[], unsigned int nbufs, uv_stream_t* send_handle,
- uv_write_cb cb);
-void uv__pipe_pause_read(uv_pipe_t* handle);
-void uv__pipe_unpause_read(uv_pipe_t* handle);
-void uv__pipe_stop_read(uv_pipe_t* handle);
+void uv__pipe_read_stop(uv_pipe_t* handle);
+int uv__pipe_write(uv_loop_t* loop,
+ uv_write_t* req,
+ uv_pipe_t* handle,
+ const uv_buf_t bufs[],
+ size_t nbufs,
+ uv_stream_t* send_handle,
+ uv_write_cb cb);
void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_req_t* req);
@@ -225,10 +169,16 @@ void uv_process_tty_read_req(uv_loop_t* loop, uv_tty_t* handle,
uv_req_t* req);
void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
uv_write_t* req);
-/* TODO: remove me */
+/*
+ * uv_process_tty_accept_req() is a stub to keep DELEGATE_STREAM_REQ working
+ * TODO: find a way to remove it
+ */
void uv_process_tty_accept_req(uv_loop_t* loop, uv_tty_t* handle,
uv_req_t* raw_req);
-/* TODO: remove me */
+/*
+ * uv_process_tty_connect_req() is a stub to keep DELEGATE_STREAM_REQ working
+ * TODO: find a way to remove it
+ */
void uv_process_tty_connect_req(uv_loop_t* loop, uv_tty_t* handle,
uv_connect_t* req);
@@ -246,15 +196,6 @@ void uv_poll_endgame(uv_loop_t* loop, uv_poll_t* handle);
/*
- * Timers
- */
-void uv_timer_endgame(uv_loop_t* loop, uv_timer_t* handle);
-
-DWORD uv__next_timeout(const uv_loop_t* loop);
-void uv_process_timers(uv_loop_t* loop);
-
-
-/*
* Loop watchers
*/
void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle);
@@ -330,8 +271,6 @@ void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle);
void uv__util_init(void);
uint64_t uv__hrtime(double scale);
-int uv_parent_pid(void);
-int uv_current_pid(void);
__declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall);
int uv__getpwuid_r(uv_passwd_t* pwd);
int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8);
diff --git a/Utilities/cmlibuv/src/win/loop-watcher.c b/Utilities/cmlibuv/src/win/loop-watcher.c
index 20e4509f8..ad7fbea16 100644
--- a/Utilities/cmlibuv/src/win/loop-watcher.c
+++ b/Utilities/cmlibuv/src/win/loop-watcher.c
@@ -27,7 +27,7 @@
void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
handle->flags |= UV_HANDLE_CLOSED;
uv__handle_close(handle);
diff --git a/Utilities/cmlibuv/src/win/pipe.c b/Utilities/cmlibuv/src/win/pipe.c
index edf300212..277f6497a 100644
--- a/Utilities/cmlibuv/src/win/pipe.c
+++ b/Utilities/cmlibuv/src/win/pipe.c
@@ -21,27 +21,19 @@
#include <assert.h>
#include <io.h>
-#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
-#include "uv.h"
-#include "internal.h"
#include "handle-inl.h"
-#include "stream-inl.h"
+#include "internal.h"
#include "req-inl.h"
+#include "stream-inl.h"
+#include "uv-common.h"
+#include "uv.h"
-typedef struct uv__ipc_queue_item_s uv__ipc_queue_item_t;
-
-struct uv__ipc_queue_item_s {
- /*
- * NOTE: It is important for socket_info_ex to be the first field,
- * because we will we assigning it to the pending_ipc_info.socket_info
- */
- uv__ipc_socket_info_ex socket_info_ex;
- QUEUE member;
- int tcp_connection;
-};
+#include <aclapi.h>
+#include <accctrl.h>
/* A zero-size buffer for use by uv_pipe_read */
static char uv_zero_[] = "";
@@ -49,8 +41,8 @@ static char uv_zero_[] = "";
/* Null uv_buf_t */
static const uv_buf_t uv_null_buf_ = { 0, NULL };
-/* The timeout that the pipe will wait for the remote end to write data */
-/* when the local ends wants to shut it down. */
+/* The timeout that the pipe will wait for the remote end to write data when
+ * the local ends wants to shut it down. */
static const int64_t eof_timeout = 50; /* ms */
static const int default_pending_pipe_instances = 4;
@@ -59,22 +51,44 @@ static const int default_pending_pipe_instances = 4;
static char pipe_prefix[] = "\\\\?\\pipe";
static const int pipe_prefix_len = sizeof(pipe_prefix) - 1;
-/* IPC protocol flags. */
-#define UV_IPC_RAW_DATA 0x0001
-#define UV_IPC_TCP_SERVER 0x0002
-#define UV_IPC_TCP_CONNECTION 0x0004
+/* IPC incoming xfer queue item. */
+typedef struct {
+ uv__ipc_socket_xfer_type_t xfer_type;
+ uv__ipc_socket_xfer_info_t xfer_info;
+ QUEUE member;
+} uv__ipc_xfer_queue_item_t;
+
+/* IPC frame header flags. */
+/* clang-format off */
+enum {
+ UV__IPC_FRAME_HAS_DATA = 0x01,
+ UV__IPC_FRAME_HAS_SOCKET_XFER = 0x02,
+ UV__IPC_FRAME_XFER_IS_TCP_CONNECTION = 0x04,
+ /* These are combinations of the flags above. */
+ UV__IPC_FRAME_XFER_FLAGS = 0x06,
+ UV__IPC_FRAME_VALID_FLAGS = 0x07
+};
+/* clang-format on */
/* IPC frame header. */
typedef struct {
- int flags;
- uint64_t raw_data_length;
-} uv_ipc_frame_header_t;
-
-/* IPC frame, which contains an imported TCP socket stream. */
+ uint32_t flags;
+ uint32_t reserved1; /* Ignored. */
+ uint32_t data_length; /* Must be zero if there is no data. */
+ uint32_t reserved2; /* Must be zero. */
+} uv__ipc_frame_header_t;
+
+/* To implement the IPC protocol correctly, these structures must have exactly
+ * the right size. */
+STATIC_ASSERT(sizeof(uv__ipc_frame_header_t) == 16);
+STATIC_ASSERT(sizeof(uv__ipc_socket_xfer_info_t) == 632);
+
+/* Coalesced write request. */
typedef struct {
- uv_ipc_frame_header_t header;
- uv__ipc_socket_info_ex socket_info_ex;
-} uv_ipc_frame_uv_stream;
+ uv_write_t req; /* Internal heap-allocated write request. */
+ uv_write_t* user_req; /* Pointer to user-specified uv_write_t. */
+} uv__coalesced_write_t;
+
static void eof_timer_init(uv_pipe_t* pipe);
static void eof_timer_start(uv_pipe_t* pipe);
@@ -95,15 +109,12 @@ int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
handle->reqs_pending = 0;
handle->handle = INVALID_HANDLE_VALUE;
handle->name = NULL;
- handle->pipe.conn.ipc_pid = 0;
- handle->pipe.conn.remaining_ipc_rawdata_bytes = 0;
- QUEUE_INIT(&handle->pipe.conn.pending_ipc_info.queue);
- handle->pipe.conn.pending_ipc_info.queue_len = 0;
+ handle->pipe.conn.ipc_remote_pid = 0;
+ handle->pipe.conn.ipc_data_frame.payload_remaining = 0;
+ QUEUE_INIT(&handle->pipe.conn.ipc_xfer_queue);
+ handle->pipe.conn.ipc_xfer_queue_length = 0;
handle->ipc = ipc;
handle->pipe.conn.non_overlapped_writes_tail = NULL;
- handle->pipe.conn.readfile_thread = NULL;
-
- UV_REQ_INIT(&handle->pipe.conn.ipc_header_write_req, UV_UNKNOWN_REQ);
return 0;
}
@@ -114,10 +125,9 @@ static void uv_pipe_connection_init(uv_pipe_t* handle) {
handle->read_req.data = handle;
handle->pipe.conn.eof_timer = NULL;
assert(!(handle->flags & UV_HANDLE_PIPESERVER));
- if (pCancelSynchronousIo &&
- handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) {
- uv_mutex_init(&handle->pipe.conn.readfile_mutex);
- handle->flags |= UV_HANDLE_PIPE_READ_CANCELABLE;
+ if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) {
+ handle->pipe.conn.readfile_thread_handle = NULL;
+ InitializeCriticalSection(&handle->pipe.conn.readfile_thread_lock);
}
}
@@ -202,7 +212,7 @@ int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
uv_unique_pipe_name(ptr, name, nameSize);
pipeHandle = CreateNamedPipeA(name,
- access | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE,
+ access | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE | WRITE_DAC,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 65536, 65536, 0,
NULL);
@@ -344,12 +354,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
NTSTATUS nt_status;
IO_STATUS_BLOCK io_status;
FILE_PIPE_LOCAL_INFORMATION pipe_info;
- uv__ipc_queue_item_t* item;
-
- if (handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE) {
- handle->flags &= ~UV_HANDLE_PIPE_READ_CANCELABLE;
- uv_mutex_destroy(&handle->pipe.conn.readfile_mutex);
- }
+ uv__ipc_xfer_queue_item_t* xfer_queue_item;
if ((handle->flags & UV_HANDLE_CONNECTION) &&
handle->stream.conn.shutdown_req != NULL &&
@@ -359,7 +364,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
/* Clear the shutdown_req field so we don't go here again. */
handle->stream.conn.shutdown_req = NULL;
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
UNREGISTER_HANDLE_REQ(loop, handle, req);
/* Already closing. Cancel the shutdown. */
@@ -420,33 +425,33 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
}
}
- if (handle->flags & UV__HANDLE_CLOSING &&
+ if (handle->flags & UV_HANDLE_CLOSING &&
handle->reqs_pending == 0) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
if (handle->flags & UV_HANDLE_CONNECTION) {
/* Free pending sockets */
- while (!QUEUE_EMPTY(&handle->pipe.conn.pending_ipc_info.queue)) {
+ while (!QUEUE_EMPTY(&handle->pipe.conn.ipc_xfer_queue)) {
QUEUE* q;
SOCKET socket;
- q = QUEUE_HEAD(&handle->pipe.conn.pending_ipc_info.queue);
+ q = QUEUE_HEAD(&handle->pipe.conn.ipc_xfer_queue);
QUEUE_REMOVE(q);
- item = QUEUE_DATA(q, uv__ipc_queue_item_t, member);
+ xfer_queue_item = QUEUE_DATA(q, uv__ipc_xfer_queue_item_t, member);
/* Materialize socket and close it */
socket = WSASocketW(FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO,
- &item->socket_info_ex.socket_info,
+ &xfer_queue_item->xfer_info.socket_info,
0,
WSA_FLAG_OVERLAPPED);
- uv__free(item);
+ uv__free(xfer_queue_item);
if (socket != INVALID_SOCKET)
closesocket(socket);
}
- handle->pipe.conn.pending_ipc_info.queue_len = 0;
+ handle->pipe.conn.ipc_xfer_queue_length = 0;
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
if (handle->read_req.wait_handle != INVALID_HANDLE_VALUE) {
@@ -458,6 +463,9 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
handle->read_req.event_handle = NULL;
}
}
+
+ if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE)
+ DeleteCriticalSection(&handle->pipe.conn.readfile_thread_lock);
}
if (handle->flags & UV_HANDLE_PIPESERVER) {
@@ -534,7 +542,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
*/
handle->pipe.serv.accept_reqs[0].pipeHandle = CreateNamedPipeW(handle->name,
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED |
- FILE_FLAG_FIRST_PIPE_INSTANCE,
+ FILE_FLAG_FIRST_PIPE_INSTANCE | WRITE_DAC,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL);
@@ -592,8 +600,8 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) {
loop = handle->loop;
assert(loop);
- /* We're here because CreateFile on a pipe returned ERROR_PIPE_BUSY. */
- /* We wait for the pipe to become available with WaitNamedPipe. */
+ /* We're here because CreateFile on a pipe returned ERROR_PIPE_BUSY. We wait
+ * for the pipe to become available with WaitNamedPipe. */
while (WaitNamedPipeW(handle->name, 30000)) {
/* The pipe is now available, try to connect. */
pipeHandle = open_named_pipe(handle->name, &duplex_flags);
@@ -703,48 +711,68 @@ error:
}
-void uv__pipe_pause_read(uv_pipe_t* handle) {
- if (handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE) {
- /* Pause the ReadFile task briefly, to work
- around the Windows kernel bug that causes
- any access to a NamedPipe to deadlock if
- any process has called ReadFile */
- HANDLE h;
- uv_mutex_lock(&handle->pipe.conn.readfile_mutex);
- h = handle->pipe.conn.readfile_thread;
- while (h) {
- /* spinlock: we expect this to finish quickly,
- or we are probably about to deadlock anyways
- (in the kernel), so it doesn't matter */
- pCancelSynchronousIo(h);
- SwitchToThread(); /* yield thread control briefly */
- h = handle->pipe.conn.readfile_thread;
- }
- }
-}
+void uv__pipe_interrupt_read(uv_pipe_t* handle) {
+ BOOL r;
+ if (!(handle->flags & UV_HANDLE_READ_PENDING))
+ return; /* No pending reads. */
+ if (handle->flags & UV_HANDLE_CANCELLATION_PENDING)
+ return; /* Already cancelled. */
+ if (handle->handle == INVALID_HANDLE_VALUE)
+ return; /* Pipe handle closed. */
+
+ if (!(handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE)) {
+ /* Cancel asynchronous read. */
+ r = CancelIoEx(handle->handle, &handle->read_req.u.io.overlapped);
+ assert(r || GetLastError() == ERROR_NOT_FOUND);
+
+ } else {
+ /* Cancel synchronous read (which is happening in the thread pool). */
+ HANDLE thread;
+ volatile HANDLE* thread_ptr = &handle->pipe.conn.readfile_thread_handle;
-void uv__pipe_unpause_read(uv_pipe_t* handle) {
- if (handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE) {
- uv_mutex_unlock(&handle->pipe.conn.readfile_mutex);
+ EnterCriticalSection(&handle->pipe.conn.readfile_thread_lock);
+
+ thread = *thread_ptr;
+ if (thread == NULL) {
+ /* The thread pool thread has not yet reached the point of blocking, we
+ * can pre-empt it by setting thread_handle to INVALID_HANDLE_VALUE. */
+ *thread_ptr = INVALID_HANDLE_VALUE;
+
+ } else {
+ /* Spin until the thread has acknowledged (by setting the thread to
+ * INVALID_HANDLE_VALUE) that it is past the point of blocking. */
+ while (thread != INVALID_HANDLE_VALUE) {
+ r = CancelSynchronousIo(thread);
+ assert(r || GetLastError() == ERROR_NOT_FOUND);
+ SwitchToThread(); /* Yield thread. */
+ thread = *thread_ptr;
+ }
+ }
+
+ LeaveCriticalSection(&handle->pipe.conn.readfile_thread_lock);
}
+
+ /* Set flag to indicate that read has been cancelled. */
+ handle->flags |= UV_HANDLE_CANCELLATION_PENDING;
}
-void uv__pipe_stop_read(uv_pipe_t* handle) {
+void uv__pipe_read_stop(uv_pipe_t* handle) {
handle->flags &= ~UV_HANDLE_READING;
- uv__pipe_pause_read((uv_pipe_t*)handle);
- uv__pipe_unpause_read((uv_pipe_t*)handle);
+ DECREASE_ACTIVE_COUNT(handle->loop, handle);
+
+ uv__pipe_interrupt_read(handle);
}
-/* Cleans up uv_pipe_t (server or connection) and all resources associated */
-/* with it. */
+/* Cleans up uv_pipe_t (server or connection) and all resources associated with
+ * it. */
void uv_pipe_cleanup(uv_loop_t* loop, uv_pipe_t* handle) {
int i;
HANDLE pipeHandle;
- uv__pipe_stop_read(handle);
+ uv__pipe_interrupt_read(handle);
if (handle->name) {
uv__free(handle->name);
@@ -803,7 +831,7 @@ static void uv_pipe_queue_accept(uv_loop_t* loop, uv_pipe_t* handle,
assert(req->pipeHandle == INVALID_HANDLE_VALUE);
req->pipeHandle = CreateNamedPipeW(handle->name,
- PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
+ PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | WRITE_DAC,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL);
@@ -844,6 +872,7 @@ static void uv_pipe_queue_accept(uv_loop_t* loop, uv_pipe_t* handle,
return;
}
+ /* Wait for completion via IOCP */
handle->reqs_pending++;
}
@@ -853,23 +882,22 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
uv_pipe_t* pipe_client;
uv_pipe_accept_t* req;
QUEUE* q;
- uv__ipc_queue_item_t* item;
+ uv__ipc_xfer_queue_item_t* item;
int err;
if (server->ipc) {
- if (QUEUE_EMPTY(&server->pipe.conn.pending_ipc_info.queue)) {
+ if (QUEUE_EMPTY(&server->pipe.conn.ipc_xfer_queue)) {
/* No valid pending sockets. */
return WSAEWOULDBLOCK;
}
- q = QUEUE_HEAD(&server->pipe.conn.pending_ipc_info.queue);
+ q = QUEUE_HEAD(&server->pipe.conn.ipc_xfer_queue);
QUEUE_REMOVE(q);
- server->pipe.conn.pending_ipc_info.queue_len--;
- item = QUEUE_DATA(q, uv__ipc_queue_item_t, member);
+ server->pipe.conn.ipc_xfer_queue_length--;
+ item = QUEUE_DATA(q, uv__ipc_xfer_queue_item_t, member);
- err = uv_tcp_import((uv_tcp_t*)client,
- &item->socket_info_ex,
- item->tcp_connection);
+ err = uv__tcp_xfer_import(
+ (uv_tcp_t*) client, item->xfer_type, &item->xfer_info);
if (err != 0)
return err;
@@ -878,8 +906,8 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
} else {
pipe_client = (uv_pipe_t*)client;
- /* Find a connection instance that has been connected, but not yet */
- /* accepted. */
+ /* Find a connection instance that has been connected, but not yet
+ * accepted. */
req = server->pipe.serv.pending_accepts;
if (!req) {
@@ -897,7 +925,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
req->next_pending = NULL;
req->pipeHandle = INVALID_HANDLE_VALUE;
- if (!(server->flags & UV__HANDLE_CLOSING)) {
+ if (!(server->flags & UV_HANDLE_CLOSING)) {
uv_pipe_queue_accept(loop, server, req, FALSE);
}
}
@@ -942,70 +970,75 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
}
-static DWORD WINAPI uv_pipe_zero_readfile_thread_proc(void* parameter) {
- int result;
- DWORD bytes;
- uv_read_t* req = (uv_read_t*) parameter;
+static DWORD WINAPI uv_pipe_zero_readfile_thread_proc(void* arg) {
+ uv_read_t* req = (uv_read_t*) arg;
uv_pipe_t* handle = (uv_pipe_t*) req->data;
uv_loop_t* loop = handle->loop;
- HANDLE hThread = NULL;
+ volatile HANDLE* thread_ptr = &handle->pipe.conn.readfile_thread_handle;
+ CRITICAL_SECTION* lock = &handle->pipe.conn.readfile_thread_lock;
+ HANDLE thread;
+ DWORD bytes;
DWORD err;
- uv_mutex_t *m = &handle->pipe.conn.readfile_mutex;
- assert(req != NULL);
assert(req->type == UV_READ);
assert(handle->type == UV_NAMED_PIPE);
- if (handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE) {
- uv_mutex_lock(m); /* mutex controls *setting* of readfile_thread */
- if (DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
- GetCurrentProcess(), &hThread,
- 0, FALSE, DUPLICATE_SAME_ACCESS)) {
- handle->pipe.conn.readfile_thread = hThread;
- } else {
- hThread = NULL;
- }
- uv_mutex_unlock(m);
- }
-restart_readfile:
- result = ReadFile(handle->handle,
- &uv_zero_,
- 0,
- &bytes,
- NULL);
- if (!result) {
+ err = 0;
+
+ /* Create a handle to the current thread. */
+ if (!DuplicateHandle(GetCurrentProcess(),
+ GetCurrentThread(),
+ GetCurrentProcess(),
+ &thread,
+ 0,
+ FALSE,
+ DUPLICATE_SAME_ACCESS)) {
err = GetLastError();
- if (err == ERROR_OPERATION_ABORTED &&
- handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE) {
- if (handle->flags & UV_HANDLE_READING) {
- /* just a brief break to do something else */
- handle->pipe.conn.readfile_thread = NULL;
- /* resume after it is finished */
- uv_mutex_lock(m);
- handle->pipe.conn.readfile_thread = hThread;
- uv_mutex_unlock(m);
- goto restart_readfile;
- } else {
- result = 1; /* successfully stopped reading */
- }
- }
- }
- if (hThread) {
- assert(hThread == handle->pipe.conn.readfile_thread);
- /* mutex does not control clearing readfile_thread */
- handle->pipe.conn.readfile_thread = NULL;
- uv_mutex_lock(m);
- /* only when we hold the mutex lock is it safe to
- open or close the handle */
- CloseHandle(hThread);
- uv_mutex_unlock(m);
+ goto out1;
}
- if (!result) {
- SET_REQ_ERROR(req, err);
+ /* The lock needs to be held when thread handle is modified. */
+ EnterCriticalSection(lock);
+ if (*thread_ptr == INVALID_HANDLE_VALUE) {
+ /* uv__pipe_interrupt_read() cancelled reading before we got here. */
+ err = ERROR_OPERATION_ABORTED;
+ } else {
+ /* Let main thread know which worker thread is doing the blocking read. */
+ assert(*thread_ptr == NULL);
+ *thread_ptr = thread;
}
+ LeaveCriticalSection(lock);
+ if (err)
+ goto out2;
+
+ /* Block the thread until data is available on the pipe, or the read is
+ * cancelled. */
+ if (!ReadFile(handle->handle, &uv_zero_, 0, &bytes, NULL))
+ err = GetLastError();
+
+ /* Let the main thread know the worker is past the point of blocking. */
+ assert(thread == *thread_ptr);
+ *thread_ptr = INVALID_HANDLE_VALUE;
+
+ /* Briefly acquire the mutex. Since the main thread holds the lock while it
+ * is spinning trying to cancel this thread's I/O, we will block here until
+ * it stops doing that. */
+ EnterCriticalSection(lock);
+ LeaveCriticalSection(lock);
+
+out2:
+ /* Close the handle to the current thread. */
+ CloseHandle(thread);
+
+out1:
+ /* Set request status and post a completion record to the IOCP. */
+ if (err)
+ SET_REQ_ERROR(req, err);
+ else
+ SET_REQ_SUCCESS(req);
POST_COMPLETION_FOR_REQ(loop, req);
+
return 0;
}
@@ -1087,6 +1120,7 @@ static void uv_pipe_queue_read(uv_loop_t* loop, uv_pipe_t* handle) {
req = &handle->read_req;
if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) {
+ handle->pipe.conn.readfile_thread_handle = NULL; /* Reset cancellation. */
if (!QueueUserWorkItem(&uv_pipe_zero_readfile_thread_proc,
req,
WT_EXECUTELONGFUNCTION)) {
@@ -1154,8 +1188,8 @@ int uv_pipe_read_start(uv_pipe_t* handle,
handle->read_cb = read_cb;
handle->alloc_cb = alloc_cb;
- /* If reading was stopped and then started again, there could still be a */
- /* read request pending. */
+ /* If reading was stopped and then started again, there could still be a read
+ * request pending. */
if (!(handle->flags & UV_HANDLE_READ_PENDING))
uv_pipe_queue_read(loop, handle);
@@ -1211,154 +1245,110 @@ static void uv_queue_non_overlapped_write(uv_pipe_t* handle) {
}
-static int uv_pipe_write_impl(uv_loop_t* loop,
- uv_write_t* req,
- uv_pipe_t* handle,
- const uv_buf_t bufs[],
- unsigned int nbufs,
- uv_stream_t* send_handle,
- uv_write_cb cb) {
- int err;
- int result;
- uv_tcp_t* tcp_send_handle;
- uv_write_t* ipc_header_req = NULL;
- uv_ipc_frame_uv_stream ipc_frame;
+static int uv__build_coalesced_write_req(uv_write_t* user_req,
+ const uv_buf_t bufs[],
+ size_t nbufs,
+ uv_write_t** req_out,
+ uv_buf_t* write_buf_out) {
+ /* Pack into a single heap-allocated buffer:
+ * (a) a uv_write_t structure where libuv stores the actual state.
+ * (b) a pointer to the original uv_write_t.
+ * (c) data from all `bufs` entries.
+ */
+ char* heap_buffer;
+ size_t heap_buffer_length, heap_buffer_offset;
+ uv__coalesced_write_t* coalesced_write_req; /* (a) + (b) */
+ char* data_start; /* (c) */
+ size_t data_length;
+ unsigned int i;
+
+ /* Compute combined size of all combined buffers from `bufs`. */
+ data_length = 0;
+ for (i = 0; i < nbufs; i++)
+ data_length += bufs[i].len;
+
+ /* The total combined size of data buffers should not exceed UINT32_MAX,
+ * because WriteFile() won't accept buffers larger than that. */
+ if (data_length > UINT32_MAX)
+ return WSAENOBUFS; /* Maps to UV_ENOBUFS. */
+
+ /* Compute heap buffer size. */
+ heap_buffer_length = sizeof *coalesced_write_req + /* (a) + (b) */
+ data_length; /* (c) */
+
+ /* Allocate buffer. */
+ heap_buffer = uv__malloc(heap_buffer_length);
+ if (heap_buffer == NULL)
+ return ERROR_NOT_ENOUGH_MEMORY; /* Maps to UV_ENOMEM. */
+
+ /* Copy uv_write_t information to the buffer. */
+ coalesced_write_req = (uv__coalesced_write_t*) heap_buffer;
+ coalesced_write_req->req = *user_req; /* copy (a) */
+ coalesced_write_req->req.coalesced = 1;
+ coalesced_write_req->user_req = user_req; /* copy (b) */
+ heap_buffer_offset = sizeof *coalesced_write_req; /* offset (a) + (b) */
+
+ /* Copy data buffers to the heap buffer. */
+ data_start = &heap_buffer[heap_buffer_offset];
+ for (i = 0; i < nbufs; i++) {
+ memcpy(&heap_buffer[heap_buffer_offset],
+ bufs[i].base,
+ bufs[i].len); /* copy (c) */
+ heap_buffer_offset += bufs[i].len; /* offset (c) */
+ }
+ assert(heap_buffer_offset == heap_buffer_length);
+
+ /* Set out arguments and return. */
+ *req_out = &coalesced_write_req->req;
+ *write_buf_out = uv_buf_init(data_start, (unsigned int) data_length);
+ return 0;
+}
- if (nbufs != 1 && (nbufs != 0 || !send_handle)) {
- return ERROR_NOT_SUPPORTED;
- }
- /* Only TCP handles are supported for sharing. */
- if (send_handle && ((send_handle->type != UV_TCP) ||
- (!(send_handle->flags & UV_HANDLE_BOUND) &&
- !(send_handle->flags & UV_HANDLE_CONNECTION)))) {
- return ERROR_NOT_SUPPORTED;
- }
+static int uv__pipe_write_data(uv_loop_t* loop,
+ uv_write_t* req,
+ uv_pipe_t* handle,
+ const uv_buf_t bufs[],
+ size_t nbufs,
+ uv_write_cb cb,
+ int copy_always) {
+ int err;
+ int result;
+ uv_buf_t write_buf;
assert(handle->handle != INVALID_HANDLE_VALUE);
UV_REQ_INIT(req, UV_WRITE);
req->handle = (uv_stream_t*) handle;
+ req->send_handle = NULL;
req->cb = cb;
- req->ipc_header = 0;
+ /* Private fields. */
+ req->coalesced = 0;
req->event_handle = NULL;
req->wait_handle = INVALID_HANDLE_VALUE;
memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped));
-
- if (handle->ipc) {
- assert(!(handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE));
- ipc_frame.header.flags = 0;
-
- /* Use the IPC framing protocol. */
- if (send_handle) {
- tcp_send_handle = (uv_tcp_t*)send_handle;
-
- if (handle->pipe.conn.ipc_pid == 0) {
- handle->pipe.conn.ipc_pid = uv_current_pid();
- }
-
- err = uv_tcp_duplicate_socket(tcp_send_handle, handle->pipe.conn.ipc_pid,
- &ipc_frame.socket_info_ex.socket_info);
- if (err) {
- return err;
- }
-
- ipc_frame.socket_info_ex.delayed_error = tcp_send_handle->delayed_error;
-
- ipc_frame.header.flags |= UV_IPC_TCP_SERVER;
-
- if (tcp_send_handle->flags & UV_HANDLE_CONNECTION) {
- ipc_frame.header.flags |= UV_IPC_TCP_CONNECTION;
- }
- }
-
- if (nbufs == 1) {
- ipc_frame.header.flags |= UV_IPC_RAW_DATA;
- ipc_frame.header.raw_data_length = bufs[0].len;
- }
-
- /*
- * Use the provided req if we're only doing a single write.
- * If we're doing multiple writes, use ipc_header_write_req to do
- * the first write, and then use the provided req for the second write.
- */
- if (!(ipc_frame.header.flags & UV_IPC_RAW_DATA)) {
- ipc_header_req = req;
- } else {
- /*
- * Try to use the preallocated write req if it's available.
- * Otherwise allocate a new one.
- */
- if (handle->pipe.conn.ipc_header_write_req.type != UV_WRITE) {
- ipc_header_req = (uv_write_t*)&handle->pipe.conn.ipc_header_write_req;
- } else {
- ipc_header_req = (uv_write_t*)uv__malloc(sizeof(uv_write_t));
- if (!ipc_header_req) {
- uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
- }
- }
-
- UV_REQ_INIT(ipc_header_req, UV_WRITE);
- ipc_header_req->handle = (uv_stream_t*) handle;
- ipc_header_req->cb = NULL;
- ipc_header_req->ipc_header = 1;
- }
-
- /* Write the header or the whole frame. */
- memset(&ipc_header_req->u.io.overlapped, 0,
- sizeof(ipc_header_req->u.io.overlapped));
-
- /* Using overlapped IO, but wait for completion before returning.
- This write is blocking because ipc_frame is on stack. */
- ipc_header_req->u.io.overlapped.hEvent = CreateEvent(NULL, 1, 0, NULL);
- if (!ipc_header_req->u.io.overlapped.hEvent) {
- uv_fatal_error(GetLastError(), "CreateEvent");
- }
-
- result = WriteFile(handle->handle,
- &ipc_frame,
- ipc_frame.header.flags & UV_IPC_TCP_SERVER ?
- sizeof(ipc_frame) : sizeof(ipc_frame.header),
- NULL,
- &ipc_header_req->u.io.overlapped);
- if (!result && GetLastError() != ERROR_IO_PENDING) {
- err = GetLastError();
- CloseHandle(ipc_header_req->u.io.overlapped.hEvent);
+ req->write_buffer = uv_null_buf_;
+
+ if (nbufs == 0) {
+ /* Write empty buffer. */
+ write_buf = uv_null_buf_;
+ } else if (nbufs == 1 && !copy_always) {
+ /* Write directly from bufs[0]. */
+ write_buf = bufs[0];
+ } else {
+ /* Coalesce all `bufs` into one big buffer. This also creates a new
+ * write-request structure that replaces the old one. */
+ err = uv__build_coalesced_write_req(req, bufs, nbufs, &req, &write_buf);
+ if (err != 0)
return err;
- }
-
- if (!result) {
- /* Request not completed immediately. Wait for it.*/
- if (WaitForSingleObject(ipc_header_req->u.io.overlapped.hEvent, INFINITE) !=
- WAIT_OBJECT_0) {
- err = GetLastError();
- CloseHandle(ipc_header_req->u.io.overlapped.hEvent);
- return err;
- }
- }
- ipc_header_req->u.io.queued_bytes = 0;
- CloseHandle(ipc_header_req->u.io.overlapped.hEvent);
- ipc_header_req->u.io.overlapped.hEvent = NULL;
-
- REGISTER_HANDLE_REQ(loop, handle, ipc_header_req);
- handle->reqs_pending++;
- handle->stream.conn.write_reqs_pending++;
-
- /* If we don't have any raw data to write - we're done. */
- if (!(ipc_frame.header.flags & UV_IPC_RAW_DATA)) {
- return 0;
- }
}
if ((handle->flags &
(UV_HANDLE_BLOCKING_WRITES | UV_HANDLE_NON_OVERLAPPED_PIPE)) ==
(UV_HANDLE_BLOCKING_WRITES | UV_HANDLE_NON_OVERLAPPED_PIPE)) {
DWORD bytes;
- result = WriteFile(handle->handle,
- bufs[0].base,
- bufs[0].len,
- &bytes,
- NULL);
+ result =
+ WriteFile(handle->handle, write_buf.base, write_buf.len, &bytes, NULL);
if (!result) {
err = GetLastError();
@@ -1374,14 +1364,14 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
POST_COMPLETION_FOR_REQ(loop, req);
return 0;
} else if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) {
- req->write_buffer = bufs[0];
+ req->write_buffer = write_buf;
uv_insert_non_overlapped_write_req(handle, req);
if (handle->stream.conn.write_reqs_pending == 0) {
uv_queue_non_overlapped_write(handle);
}
/* Request queued by the kernel. */
- req->u.io.queued_bytes = bufs[0].len;
+ req->u.io.queued_bytes = write_buf.len;
handle->write_queue_size += req->u.io.queued_bytes;
} else if (handle->flags & UV_HANDLE_BLOCKING_WRITES) {
/* Using overlapped IO, but wait for completion before returning */
@@ -1391,8 +1381,8 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
}
result = WriteFile(handle->handle,
- bufs[0].base,
- bufs[0].len,
+ write_buf.base,
+ write_buf.len,
NULL,
&req->u.io.overlapped);
@@ -1407,13 +1397,13 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
req->u.io.queued_bytes = 0;
} else {
/* Request queued by the kernel. */
- req->u.io.queued_bytes = bufs[0].len;
+ req->u.io.queued_bytes = write_buf.len;
handle->write_queue_size += req->u.io.queued_bytes;
if (WaitForSingleObject(req->u.io.overlapped.hEvent, INFINITE) !=
WAIT_OBJECT_0) {
err = GetLastError();
CloseHandle(req->u.io.overlapped.hEvent);
- return uv_translate_sys_error(err);
+ return err;
}
}
CloseHandle(req->u.io.overlapped.hEvent);
@@ -1424,8 +1414,8 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
return 0;
} else {
result = WriteFile(handle->handle,
- bufs[0].base,
- bufs[0].len,
+ write_buf.base,
+ write_buf.len,
NULL,
&req->u.io.overlapped);
@@ -1438,7 +1428,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
req->u.io.queued_bytes = 0;
} else {
/* Request queued by the kernel. */
- req->u.io.queued_bytes = bufs[0].len;
+ req->u.io.queued_bytes = write_buf.len;
handle->write_queue_size += req->u.io.queued_bytes;
}
@@ -1463,35 +1453,143 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
}
-int uv_pipe_write(uv_loop_t* loop,
- uv_write_t* req,
- uv_pipe_t* handle,
- const uv_buf_t bufs[],
- unsigned int nbufs,
- uv_write_cb cb) {
- return uv_pipe_write_impl(loop, req, handle, bufs, nbufs, NULL, cb);
+static DWORD uv__pipe_get_ipc_remote_pid(uv_pipe_t* handle) {
+ DWORD* pid = &handle->pipe.conn.ipc_remote_pid;
+
+ /* If the both ends of the IPC pipe are owned by the same process,
+ * the remote end pid may not yet be set. If so, do it here.
+ * TODO: this is weird; it'd probably better to use a handshake. */
+ if (*pid == 0)
+ *pid = GetCurrentProcessId();
+
+ return *pid;
}
-int uv_pipe_write2(uv_loop_t* loop,
+int uv__pipe_write_ipc(uv_loop_t* loop,
+ uv_write_t* req,
+ uv_pipe_t* handle,
+ const uv_buf_t data_bufs[],
+ size_t data_buf_count,
+ uv_stream_t* send_handle,
+ uv_write_cb cb) {
+ uv_buf_t stack_bufs[6];
+ uv_buf_t* bufs;
+ size_t buf_count, buf_index;
+ uv__ipc_frame_header_t frame_header;
+ uv__ipc_socket_xfer_type_t xfer_type = UV__IPC_SOCKET_XFER_NONE;
+ uv__ipc_socket_xfer_info_t xfer_info;
+ uint64_t data_length;
+ size_t i;
+ int err;
+
+ /* Compute the combined size of data buffers. */
+ data_length = 0;
+ for (i = 0; i < data_buf_count; i++)
+ data_length += data_bufs[i].len;
+ if (data_length > UINT32_MAX)
+ return WSAENOBUFS; /* Maps to UV_ENOBUFS. */
+
+ /* Prepare the frame's socket xfer payload. */
+ if (send_handle != NULL) {
+ uv_tcp_t* send_tcp_handle = (uv_tcp_t*) send_handle;
+
+ /* Verify that `send_handle` it is indeed a tcp handle. */
+ if (send_tcp_handle->type != UV_TCP)
+ return ERROR_NOT_SUPPORTED;
+
+ /* Export the tcp handle. */
+ err = uv__tcp_xfer_export(send_tcp_handle,
+ uv__pipe_get_ipc_remote_pid(handle),
+ &xfer_type,
+ &xfer_info);
+ if (err != 0)
+ return err;
+ }
+
+ /* Compute the number of uv_buf_t's required. */
+ buf_count = 1 + data_buf_count; /* Frame header and data buffers. */
+ if (send_handle != NULL)
+ buf_count += 1; /* One extra for the socket xfer information. */
+
+ /* Use the on-stack buffer array if it is big enough; otherwise allocate
+ * space for it on the heap. */
+ if (buf_count < ARRAY_SIZE(stack_bufs)) {
+ /* Use on-stack buffer array. */
+ bufs = stack_bufs;
+ } else {
+ /* Use heap-allocated buffer array. */
+ bufs = uv__calloc(buf_count, sizeof(uv_buf_t));
+ if (bufs == NULL)
+ return ERROR_NOT_ENOUGH_MEMORY; /* Maps to UV_ENOMEM. */
+ }
+ buf_index = 0;
+
+ /* Initialize frame header and add it to the buffers list. */
+ memset(&frame_header, 0, sizeof frame_header);
+ bufs[buf_index++] = uv_buf_init((char*) &frame_header, sizeof frame_header);
+
+ if (send_handle != NULL) {
+ /* Add frame header flags. */
+ switch (xfer_type) {
+ case UV__IPC_SOCKET_XFER_TCP_CONNECTION:
+ frame_header.flags |= UV__IPC_FRAME_HAS_SOCKET_XFER |
+ UV__IPC_FRAME_XFER_IS_TCP_CONNECTION;
+ break;
+ case UV__IPC_SOCKET_XFER_TCP_SERVER:
+ frame_header.flags |= UV__IPC_FRAME_HAS_SOCKET_XFER;
+ break;
+ default:
+ assert(0); /* Unreachable. */
+ }
+ /* Add xfer info buffer. */
+ bufs[buf_index++] = uv_buf_init((char*) &xfer_info, sizeof xfer_info);
+ }
+
+ if (data_length > 0) {
+ /* Update frame header. */
+ frame_header.flags |= UV__IPC_FRAME_HAS_DATA;
+ frame_header.data_length = (uint32_t) data_length;
+ /* Add data buffers to buffers list. */
+ for (i = 0; i < data_buf_count; i++)
+ bufs[buf_index++] = data_bufs[i];
+ }
+
+ /* Write buffers. We set the `always_copy` flag, so it is not a problem that
+ * some of the written data lives on the stack. */
+ err = uv__pipe_write_data(loop, req, handle, bufs, buf_count, cb, 1);
+
+ /* If we had to heap-allocate the bufs array, free it now. */
+ if (bufs != stack_bufs) {
+ uv__free(bufs);
+ }
+
+ return err;
+}
+
+
+int uv__pipe_write(uv_loop_t* loop,
uv_write_t* req,
uv_pipe_t* handle,
const uv_buf_t bufs[],
- unsigned int nbufs,
+ size_t nbufs,
uv_stream_t* send_handle,
uv_write_cb cb) {
- if (!handle->ipc) {
- return WSAEINVAL;
+ if (handle->ipc) {
+ /* IPC pipe write: use framing protocol. */
+ return uv__pipe_write_ipc(loop, req, handle, bufs, nbufs, send_handle, cb);
+ } else {
+ /* Non-IPC pipe write: put data on the wire directly. */
+ assert(send_handle == NULL);
+ return uv__pipe_write_data(loop, req, handle, bufs, nbufs, cb, 0);
}
-
- return uv_pipe_write_impl(loop, req, handle, bufs, nbufs, send_handle, cb);
}
static void uv_pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle,
uv_buf_t buf) {
- /* If there is an eof timer running, we don't need it any more, */
- /* so discard it. */
+ /* If there is an eof timer running, we don't need it any more, so discard
+ * it. */
eof_timer_destroy(handle);
handle->flags &= ~UV_HANDLE_READABLE;
@@ -1503,8 +1601,8 @@ static void uv_pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle,
static void uv_pipe_read_error(uv_loop_t* loop, uv_pipe_t* handle, int error,
uv_buf_t buf) {
- /* If there is an eof timer running, we don't need it any more, */
- /* so discard it. */
+ /* If there is an eof timer running, we don't need it any more, so discard
+ * it. */
eof_timer_destroy(handle);
uv_read_stop((uv_stream_t*) handle);
@@ -1523,152 +1621,228 @@ static void uv_pipe_read_error_or_eof(uv_loop_t* loop, uv_pipe_t* handle,
}
-void uv__pipe_insert_pending_socket(uv_pipe_t* handle,
- uv__ipc_socket_info_ex* info,
- int tcp_connection) {
- uv__ipc_queue_item_t* item;
+static void uv__pipe_queue_ipc_xfer_info(
+ uv_pipe_t* handle,
+ uv__ipc_socket_xfer_type_t xfer_type,
+ uv__ipc_socket_xfer_info_t* xfer_info) {
+ uv__ipc_xfer_queue_item_t* item;
- item = (uv__ipc_queue_item_t*) uv__malloc(sizeof(*item));
+ item = (uv__ipc_xfer_queue_item_t*) uv__malloc(sizeof(*item));
if (item == NULL)
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
- memcpy(&item->socket_info_ex, info, sizeof(item->socket_info_ex));
- item->tcp_connection = tcp_connection;
- QUEUE_INSERT_TAIL(&handle->pipe.conn.pending_ipc_info.queue, &item->member);
- handle->pipe.conn.pending_ipc_info.queue_len++;
+ item->xfer_type = xfer_type;
+ item->xfer_info = *xfer_info;
+
+ QUEUE_INSERT_TAIL(&handle->pipe.conn.ipc_xfer_queue, &item->member);
+ handle->pipe.conn.ipc_xfer_queue_length++;
}
-void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
- uv_req_t* req) {
- DWORD bytes, avail;
+/* Read an exact number of bytes from a pipe. If an error or end-of-file is
+ * encountered before the requested number of bytes are read, an error is
+ * returned. */
+static int uv__pipe_read_exactly(HANDLE h, void* buffer, DWORD count) {
+ DWORD bytes_read, bytes_read_now;
+
+ bytes_read = 0;
+ while (bytes_read < count) {
+ if (!ReadFile(h,
+ (char*) buffer + bytes_read,
+ count - bytes_read,
+ &bytes_read_now,
+ NULL)) {
+ return GetLastError();
+ }
+
+ bytes_read += bytes_read_now;
+ }
+
+ assert(bytes_read == count);
+ return 0;
+}
+
+
+static DWORD uv__pipe_read_data(uv_loop_t* loop,
+ uv_pipe_t* handle,
+ DWORD suggested_bytes,
+ DWORD max_bytes) {
+ DWORD bytes_read;
uv_buf_t buf;
- uv_ipc_frame_uv_stream ipc_frame;
+ /* Ask the user for a buffer to read data into. */
+ buf = uv_buf_init(NULL, 0);
+ handle->alloc_cb((uv_handle_t*) handle, suggested_bytes, &buf);
+ if (buf.base == NULL || buf.len == 0) {
+ handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
+ return 0; /* Break out of read loop. */
+ }
+
+ /* Ensure we read at most the smaller of:
+ * (a) the length of the user-allocated buffer.
+ * (b) the maximum data length as specified by the `max_bytes` argument.
+ */
+ if (max_bytes > buf.len)
+ max_bytes = buf.len;
+
+ /* Read into the user buffer. */
+ if (!ReadFile(handle->handle, buf.base, max_bytes, &bytes_read, NULL)) {
+ uv_pipe_read_error_or_eof(loop, handle, GetLastError(), buf);
+ return 0; /* Break out of read loop. */
+ }
+
+ /* Call the read callback. */
+ handle->read_cb((uv_stream_t*) handle, bytes_read, &buf);
+
+ return bytes_read;
+}
+
+
+static DWORD uv__pipe_read_ipc(uv_loop_t* loop, uv_pipe_t* handle) {
+ uint32_t* data_remaining = &handle->pipe.conn.ipc_data_frame.payload_remaining;
+ int err;
+
+ if (*data_remaining > 0) {
+ /* Read frame data payload. */
+ DWORD bytes_read =
+ uv__pipe_read_data(loop, handle, *data_remaining, *data_remaining);
+ *data_remaining -= bytes_read;
+ return bytes_read;
+
+ } else {
+ /* Start of a new IPC frame. */
+ uv__ipc_frame_header_t frame_header;
+ uint32_t xfer_flags;
+ uv__ipc_socket_xfer_type_t xfer_type;
+ uv__ipc_socket_xfer_info_t xfer_info;
+
+ /* Read the IPC frame header. */
+ err = uv__pipe_read_exactly(
+ handle->handle, &frame_header, sizeof frame_header);
+ if (err)
+ goto error;
+
+ /* Validate that flags are valid. */
+ if ((frame_header.flags & ~UV__IPC_FRAME_VALID_FLAGS) != 0)
+ goto invalid;
+ /* Validate that reserved2 is zero. */
+ if (frame_header.reserved2 != 0)
+ goto invalid;
+
+ /* Parse xfer flags. */
+ xfer_flags = frame_header.flags & UV__IPC_FRAME_XFER_FLAGS;
+ if (xfer_flags & UV__IPC_FRAME_HAS_SOCKET_XFER) {
+ /* Socket coming -- determine the type. */
+ xfer_type = xfer_flags & UV__IPC_FRAME_XFER_IS_TCP_CONNECTION
+ ? UV__IPC_SOCKET_XFER_TCP_CONNECTION
+ : UV__IPC_SOCKET_XFER_TCP_SERVER;
+ } else if (xfer_flags == 0) {
+ /* No socket. */
+ xfer_type = UV__IPC_SOCKET_XFER_NONE;
+ } else {
+ /* Invalid flags. */
+ goto invalid;
+ }
+
+ /* Parse data frame information. */
+ if (frame_header.flags & UV__IPC_FRAME_HAS_DATA) {
+ *data_remaining = frame_header.data_length;
+ } else if (frame_header.data_length != 0) {
+ /* Data length greater than zero but data flag not set -- invalid. */
+ goto invalid;
+ }
+
+ /* If no socket xfer info follows, return here. Data will be read in a
+ * subsequent invocation of uv__pipe_read_ipc(). */
+ if (xfer_type == UV__IPC_SOCKET_XFER_NONE)
+ return sizeof frame_header; /* Number of bytes read. */
+
+ /* Read transferred socket information. */
+ err = uv__pipe_read_exactly(handle->handle, &xfer_info, sizeof xfer_info);
+ if (err)
+ goto error;
+
+ /* Store the pending socket info. */
+ uv__pipe_queue_ipc_xfer_info(handle, xfer_type, &xfer_info);
+
+ /* Return number of bytes read. */
+ return sizeof frame_header + sizeof xfer_info;
+ }
+
+invalid:
+ /* Invalid frame. */
+ err = WSAECONNABORTED; /* Maps to UV_ECONNABORTED. */
+
+error:
+ uv_pipe_read_error_or_eof(loop, handle, err, uv_null_buf_);
+ return 0; /* Break out of read loop. */
+}
+
+
+void uv_process_pipe_read_req(uv_loop_t* loop,
+ uv_pipe_t* handle,
+ uv_req_t* req) {
assert(handle->type == UV_NAMED_PIPE);
- handle->flags &= ~UV_HANDLE_READ_PENDING;
+ handle->flags &= ~(UV_HANDLE_READ_PENDING | UV_HANDLE_CANCELLATION_PENDING);
+ DECREASE_PENDING_REQ_COUNT(handle);
eof_timer_stop(handle);
- if (!REQ_SUCCESS(req)) {
- /* An error occurred doing the 0-read. */
- if (handle->flags & UV_HANDLE_READING) {
- uv_pipe_read_error_or_eof(loop,
- handle,
- GET_REQ_ERROR(req),
- uv_null_buf_);
- }
- } else {
- /* Do non-blocking reads until the buffer is empty */
- while (handle->flags & UV_HANDLE_READING) {
- if (!PeekNamedPipe(handle->handle,
- NULL,
- 0,
- NULL,
- &avail,
- NULL)) {
- uv_pipe_read_error_or_eof(loop, handle, GetLastError(), uv_null_buf_);
- break;
- }
+ /* At this point, we're done with bookkeeping. If the user has stopped
+ * reading the pipe in the meantime, there is nothing left to do, since there
+ * is no callback that we can call. */
+ if (!(handle->flags & UV_HANDLE_READING))
+ return;
- if (avail == 0) {
- /* There is nothing to read after all. */
- break;
- }
+ if (!REQ_SUCCESS(req)) {
+ /* An error occurred doing the zero-read. */
+ DWORD err = GET_REQ_ERROR(req);
- if (handle->ipc) {
- /* Use the IPC framing protocol to read the incoming data. */
- if (handle->pipe.conn.remaining_ipc_rawdata_bytes == 0) {
- /* We're reading a new frame. First, read the header. */
- assert(avail >= sizeof(ipc_frame.header));
-
- if (!ReadFile(handle->handle,
- &ipc_frame.header,
- sizeof(ipc_frame.header),
- &bytes,
- NULL)) {
- uv_pipe_read_error_or_eof(loop, handle, GetLastError(),
- uv_null_buf_);
- break;
- }
-
- assert(bytes == sizeof(ipc_frame.header));
- assert(ipc_frame.header.flags <= (UV_IPC_TCP_SERVER | UV_IPC_RAW_DATA |
- UV_IPC_TCP_CONNECTION));
-
- if (ipc_frame.header.flags & UV_IPC_TCP_SERVER) {
- assert(avail - sizeof(ipc_frame.header) >=
- sizeof(ipc_frame.socket_info_ex));
-
- /* Read the TCP socket info. */
- if (!ReadFile(handle->handle,
- &ipc_frame.socket_info_ex,
- sizeof(ipc_frame) - sizeof(ipc_frame.header),
- &bytes,
- NULL)) {
- uv_pipe_read_error_or_eof(loop, handle, GetLastError(),
- uv_null_buf_);
- break;
- }
-
- assert(bytes == sizeof(ipc_frame) - sizeof(ipc_frame.header));
-
- /* Store the pending socket info. */
- uv__pipe_insert_pending_socket(
- handle,
- &ipc_frame.socket_info_ex,
- ipc_frame.header.flags & UV_IPC_TCP_CONNECTION);
- }
-
- if (ipc_frame.header.flags & UV_IPC_RAW_DATA) {
- handle->pipe.conn.remaining_ipc_rawdata_bytes =
- ipc_frame.header.raw_data_length;
- continue;
- }
- } else {
- avail = min(avail, (DWORD)handle->pipe.conn.remaining_ipc_rawdata_bytes);
- }
- }
+ /* If the read was cancelled by uv__pipe_interrupt_read(), the request may
+ * indicate an ERROR_OPERATION_ABORTED error. This error isn't relevant to
+ * the user; we'll start a new zero-read at the end of this function. */
+ if (err != ERROR_OPERATION_ABORTED)
+ uv_pipe_read_error_or_eof(loop, handle, err, uv_null_buf_);
- buf = uv_buf_init(NULL, 0);
- handle->alloc_cb((uv_handle_t*) handle, avail, &buf);
- if (buf.base == NULL || buf.len == 0) {
- handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
+ } else {
+ /* The zero-read completed without error, indicating there is data
+ * available in the kernel buffer. */
+ DWORD avail;
+
+ /* Get the number of bytes available. */
+ avail = 0;
+ if (!PeekNamedPipe(handle->handle, NULL, 0, NULL, &avail, NULL))
+ uv_pipe_read_error_or_eof(loop, handle, GetLastError(), uv_null_buf_);
+
+ /* Read until we've either read all the bytes available, or the 'reading'
+ * flag is cleared. */
+ while (avail > 0 && handle->flags & UV_HANDLE_READING) {
+ /* Depending on the type of pipe, read either IPC frames or raw data. */
+ DWORD bytes_read =
+ handle->ipc ? uv__pipe_read_ipc(loop, handle)
+ : uv__pipe_read_data(loop, handle, avail, (DWORD) -1);
+
+ /* If no bytes were read, treat this as an indication that an error
+ * occurred, and break out of the read loop. */
+ if (bytes_read == 0)
break;
- }
- assert(buf.base != NULL);
-
- if (ReadFile(handle->handle,
- buf.base,
- min(buf.len, avail),
- &bytes,
- NULL)) {
- /* Successful read */
- if (handle->ipc) {
- assert(handle->pipe.conn.remaining_ipc_rawdata_bytes >= bytes);
- handle->pipe.conn.remaining_ipc_rawdata_bytes =
- handle->pipe.conn.remaining_ipc_rawdata_bytes - bytes;
- }
- handle->read_cb((uv_stream_t*)handle, bytes, &buf);
- /* Read again only if bytes == buf.len */
- if (bytes <= buf.len) {
- break;
- }
- } else {
- uv_pipe_read_error_or_eof(loop, handle, GetLastError(), buf);
+ /* It is possible that more bytes were read than we thought were
+ * available. To prevent `avail` from underflowing, break out of the loop
+ * if this is the case. */
+ if (bytes_read > avail)
break;
- }
- }
- /* Post another 0-read if still reading and not closing. */
- if ((handle->flags & UV_HANDLE_READING) &&
- !(handle->flags & UV_HANDLE_READ_PENDING)) {
- uv_pipe_queue_read(loop, handle);
+ /* Recompute the number of bytes available. */
+ avail -= bytes_read;
}
}
- DECREASE_PENDING_REQ_COUNT(handle);
+ /* Start another zero-read request if necessary. */
+ if ((handle->flags & UV_HANDLE_READING) &&
+ !(handle->flags & UV_HANDLE_READ_PENDING)) {
+ uv_pipe_queue_read(loop, handle);
+ }
}
@@ -1694,17 +1868,19 @@ void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
}
}
- if (req->ipc_header) {
- if (req == &handle->pipe.conn.ipc_header_write_req) {
- req->type = UV_UNKNOWN_REQ;
- } else {
- uv__free(req);
- }
- } else {
- if (req->cb) {
- err = GET_REQ_ERROR(req);
- req->cb(req, uv_translate_sys_error(err));
- }
+ err = GET_REQ_ERROR(req);
+
+ /* If this was a coalesced write, extract pointer to the user_provided
+ * uv_write_t structure so we can pass the expected pointer to the callback,
+ * then free the heap-allocated write req. */
+ if (req->coalesced) {
+ uv__coalesced_write_t* coalesced_write =
+ container_of(req, uv__coalesced_write_t, req);
+ req = coalesced_write->user_req;
+ uv__free(coalesced_write);
+ }
+ if (req->cb) {
+ req->cb(req, uv_translate_sys_error(err));
}
handle->stream.conn.write_reqs_pending--;
@@ -1730,7 +1906,7 @@ void uv_process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle,
assert(handle->type == UV_NAMED_PIPE);
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
/* The req->pipeHandle should be freed already in uv_pipe_cleanup(). */
assert(req->pipeHandle == INVALID_HANDLE_VALUE);
DECREASE_PENDING_REQ_COUNT(handle);
@@ -1750,7 +1926,7 @@ void uv_process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle,
CloseHandle(req->pipeHandle);
req->pipeHandle = INVALID_HANDLE_VALUE;
}
- if (!(handle->flags & UV__HANDLE_CLOSING)) {
+ if (!(handle->flags & UV_HANDLE_CLOSING)) {
uv_pipe_queue_accept(loop, handle, req, FALSE);
}
}
@@ -1788,19 +1964,19 @@ void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle,
UNREGISTER_HANDLE_REQ(loop, handle, req);
if (handle->flags & UV_HANDLE_READABLE) {
- /* Initialize and optionally start the eof timer. Only do this if the */
- /* pipe is readable and we haven't seen EOF come in ourselves. */
+ /* Initialize and optionally start the eof timer. Only do this if the pipe
+ * is readable and we haven't seen EOF come in ourselves. */
eof_timer_init(handle);
- /* If reading start the timer right now. */
- /* Otherwise uv_pipe_queue_read will start it. */
+ /* If reading start the timer right now. Otherwise uv_pipe_queue_read will
+ * start it. */
if (handle->flags & UV_HANDLE_READ_PENDING) {
eof_timer_start(handle);
}
} else {
- /* This pipe is not readable. We can just close it to let the other end */
- /* know that we're done writing. */
+ /* This pipe is not readable. We can just close it to let the other end
+ * know that we're done writing. */
close_pipe(handle);
}
@@ -1851,17 +2027,16 @@ static void eof_timer_cb(uv_timer_t* timer) {
assert(pipe->type == UV_NAMED_PIPE);
- /* This should always be true, since we start the timer only */
- /* in uv_pipe_queue_read after successfully calling ReadFile, */
- /* or in uv_process_pipe_shutdown_req if a read is pending, */
- /* and we always immediately stop the timer in */
- /* uv_process_pipe_read_req. */
+ /* This should always be true, since we start the timer only in
+ * uv_pipe_queue_read after successfully calling ReadFile, or in
+ * uv_process_pipe_shutdown_req if a read is pending, and we always
+ * immediately stop the timer in uv_process_pipe_read_req. */
assert(pipe->flags & UV_HANDLE_READ_PENDING);
- /* If there are many packets coming off the iocp then the timer callback */
- /* may be called before the read request is coming off the queue. */
- /* Therefore we check here if the read request has completed but will */
- /* be processed later. */
+ /* If there are many packets coming off the iocp then the timer callback may
+ * be called before the read request is coming off the queue. Therefore we
+ * check here if the read request has completed but will be processed later.
+ */
if ((pipe->flags & UV_HANDLE_READ_PENDING) &&
HasOverlappedIoCompleted(&pipe->read_req.u.io.overlapped)) {
return;
@@ -1870,12 +2045,12 @@ static void eof_timer_cb(uv_timer_t* timer) {
/* Force both ends off the pipe. */
close_pipe(pipe);
- /* Stop reading, so the pending read that is going to fail will */
- /* not be reported to the user. */
+ /* Stop reading, so the pending read that is going to fail will not be
+ * reported to the user. */
uv_read_stop((uv_stream_t*) pipe);
- /* Report the eof and update flags. This will get reported even if the */
- /* user stopped reading in the meantime. TODO: is that okay? */
+ /* Report the eof and update flags. This will get reported even if the user
+ * stopped reading in the meantime. TODO: is that okay? */
uv_pipe_read_eof(loop, pipe, uv_null_buf_);
}
@@ -1906,6 +2081,7 @@ int uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
if (os_handle == INVALID_HANDLE_VALUE)
return UV_EBADF;
+ uv__once_init();
/* In order to avoid closing a stdio file descriptor 0-2, duplicate the
* underlying OS handle and forget about the original fd.
* We could also opt to use the original OS handle and just never close it,
@@ -1961,8 +2137,8 @@ int uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
if (pipe->ipc) {
assert(!(pipe->flags & UV_HANDLE_NON_OVERLAPPED_PIPE));
- pipe->pipe.conn.ipc_pid = uv_parent_pid();
- assert(pipe->pipe.conn.ipc_pid != -1);
+ pipe->pipe.conn.ipc_remote_pid = uv_os_getppid();
+ assert(pipe->pipe.conn.ipc_remote_pid != (DWORD) -1);
}
return 0;
}
@@ -1979,6 +2155,7 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
unsigned int name_len;
int err;
+ uv__once_init();
name_info = NULL;
if (handle->handle == INVALID_HANDLE_VALUE) {
@@ -1986,7 +2163,15 @@ static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size)
return UV_EINVAL;
}
- uv__pipe_pause_read((uv_pipe_t*)handle); /* cast away const warning */
+ /* NtQueryInformationFile will block if another thread is performing a
+ * blocking operation on the queried handle. If the pipe handle is
+ * synchronous, there may be a worker thread currently calling ReadFile() on
+ * the pipe handle, which could cause a deadlock. To avoid this, interrupt
+ * the read. */
+ if (handle->flags & UV_HANDLE_CONNECTION &&
+ handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) {
+ uv__pipe_interrupt_read((uv_pipe_t*) handle); /* cast away const warning */
+ }
nt_status = pNtQueryInformationFile(handle->handle,
&io_status,
@@ -2077,7 +2262,6 @@ error:
uv__free(name_info);
cleanup:
- uv__pipe_unpause_read((uv_pipe_t*)handle); /* cast away const warning */
return err;
}
@@ -2085,7 +2269,7 @@ cleanup:
int uv_pipe_pending_count(uv_pipe_t* handle) {
if (!handle->ipc)
return 0;
- return handle->pipe.conn.pending_ipc_info.queue_len;
+ return handle->pipe.conn.ipc_xfer_queue_length;
}
@@ -2118,8 +2302,85 @@ int uv_pipe_getpeername(const uv_pipe_t* handle, char* buffer, size_t* size) {
uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle) {
if (!handle->ipc)
return UV_UNKNOWN_HANDLE;
- if (handle->pipe.conn.pending_ipc_info.queue_len == 0)
+ if (handle->pipe.conn.ipc_xfer_queue_length == 0)
return UV_UNKNOWN_HANDLE;
else
return UV_TCP;
}
+
+int uv_pipe_chmod(uv_pipe_t* handle, int mode) {
+ SID_IDENTIFIER_AUTHORITY sid_world = { SECURITY_WORLD_SID_AUTHORITY };
+ PACL old_dacl, new_dacl;
+ PSECURITY_DESCRIPTOR sd;
+ EXPLICIT_ACCESS ea;
+ PSID everyone;
+ int error;
+
+ if (handle == NULL || handle->handle == INVALID_HANDLE_VALUE)
+ return UV_EBADF;
+
+ if (mode != UV_READABLE &&
+ mode != UV_WRITABLE &&
+ mode != (UV_WRITABLE | UV_READABLE))
+ return UV_EINVAL;
+
+ if (!AllocateAndInitializeSid(&sid_world,
+ 1,
+ SECURITY_WORLD_RID,
+ 0, 0, 0, 0, 0, 0, 0,
+ &everyone)) {
+ error = GetLastError();
+ goto done;
+ }
+
+ if (GetSecurityInfo(handle->handle,
+ SE_KERNEL_OBJECT,
+ DACL_SECURITY_INFORMATION,
+ NULL,
+ NULL,
+ &old_dacl,
+ NULL,
+ &sd)) {
+ error = GetLastError();
+ goto clean_sid;
+ }
+
+ memset(&ea, 0, sizeof(EXPLICIT_ACCESS));
+ if (mode & UV_READABLE)
+ ea.grfAccessPermissions |= GENERIC_READ | FILE_WRITE_ATTRIBUTES;
+ if (mode & UV_WRITABLE)
+ ea.grfAccessPermissions |= GENERIC_WRITE | FILE_READ_ATTRIBUTES;
+ ea.grfAccessPermissions |= SYNCHRONIZE;
+ ea.grfAccessMode = SET_ACCESS;
+ ea.grfInheritance = NO_INHERITANCE;
+ ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
+ ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
+ ea.Trustee.ptstrName = (LPTSTR)everyone;
+
+ if (SetEntriesInAcl(1, &ea, old_dacl, &new_dacl)) {
+ error = GetLastError();
+ goto clean_sd;
+ }
+
+ if (SetSecurityInfo(handle->handle,
+ SE_KERNEL_OBJECT,
+ DACL_SECURITY_INFORMATION,
+ NULL,
+ NULL,
+ new_dacl,
+ NULL)) {
+ error = GetLastError();
+ goto clean_dacl;
+ }
+
+ error = 0;
+
+clean_dacl:
+ LocalFree((HLOCAL) new_dacl);
+clean_sd:
+ LocalFree((HLOCAL) sd);
+clean_sid:
+ FreeSid(everyone);
+done:
+ return uv_translate_sys_error(error);
+}
diff --git a/Utilities/cmlibuv/src/win/poll.c b/Utilities/cmlibuv/src/win/poll.c
index a648ba711..3c6678600 100644
--- a/Utilities/cmlibuv/src/win/poll.c
+++ b/Utilities/cmlibuv/src/win/poll.c
@@ -75,7 +75,7 @@ static AFD_POLL_INFO* uv__get_afd_poll_info_dummy(void) {
static void uv__fast_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
uv_req_t* req;
AFD_POLL_INFO* afd_poll_info;
- DWORD result;
+ int result;
/* Find a yet unsubmitted req to submit. */
if (handle->submitted_events_1 == 0) {
@@ -91,16 +91,16 @@ static void uv__fast_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
handle->mask_events_1 = handle->events;
handle->mask_events_2 = 0;
} else {
- /* Just wait until there's an unsubmitted req. */
- /* This will happen almost immediately as one of the 2 outstanding */
- /* requests is about to return. When this happens, */
- /* uv__fast_poll_process_poll_req will be called, and the pending */
- /* events, if needed, will be processed in a subsequent request. */
+ /* Just wait until there's an unsubmitted req. This will happen almost
+ * immediately as one of the 2 outstanding requests is about to return.
+ * When this happens, uv__fast_poll_process_poll_req will be called, and
+ * the pending events, if needed, will be processed in a subsequent
+ * request. */
return;
}
- /* Setting Exclusive to TRUE makes the other poll request return if there */
- /* is any. */
+ /* Setting Exclusive to TRUE makes the other poll request return if there is
+ * any. */
afd_poll_info->Exclusive = TRUE;
afd_poll_info->NumberOfHandles = 1;
afd_poll_info->Timeout.QuadPart = INT64_MAX;
@@ -136,7 +136,7 @@ static void uv__fast_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
static int uv__fast_poll_cancel_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
AFD_POLL_INFO afd_poll_info;
- DWORD result;
+ int result;
afd_poll_info.Exclusive = TRUE;
afd_poll_info.NumberOfHandles = 1;
@@ -218,7 +218,7 @@ static void uv__fast_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
if ((handle->events & ~(handle->submitted_events_1 |
handle->submitted_events_2)) != 0) {
uv__fast_poll_submit_poll_req(loop, handle);
- } else if ((handle->flags & UV__HANDLE_CLOSING) &&
+ } else if ((handle->flags & UV_HANDLE_CLOSING) &&
handle->submitted_events_1 == 0 &&
handle->submitted_events_2 == 0) {
uv_want_endgame(loop, (uv_handle_t*) handle);
@@ -228,7 +228,7 @@ static void uv__fast_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
static int uv__fast_poll_set(uv_loop_t* loop, uv_poll_t* handle, int events) {
assert(handle->type == UV_POLL);
- assert(!(handle->flags & UV__HANDLE_CLOSING));
+ assert(!(handle->flags & UV_HANDLE_CLOSING));
assert((events & ~(UV_READABLE | UV_WRITABLE | UV_DISCONNECT)) == 0);
handle->events = events;
@@ -257,8 +257,8 @@ static int uv__fast_poll_close(uv_loop_t* loop, uv_poll_t* handle) {
uv_want_endgame(loop, (uv_handle_t*) handle);
return 0;
} else {
- /* Cancel outstanding poll requests by executing another, unique poll */
- /* request that forces the outstanding ones to return. */
+ /* Cancel outstanding poll requests by executing another, unique poll
+ * request that forces the outstanding ones to return. */
return uv__fast_poll_cancel_poll_req(loop, handle);
}
}
@@ -316,9 +316,8 @@ static SOCKET uv__fast_poll_get_peer_socket(uv_loop_t* loop,
return INVALID_SOCKET;
}
- /* If we didn't (try) to create a peer socket yet, try to make one. Don't */
- /* try again if the peer socket creation failed earlier for the same */
- /* protocol. */
+ /* If we didn't (try) to create a peer socket yet, try to make one. Don't try
+ * again if the peer socket creation failed earlier for the same protocol. */
peer_socket = loop->poll_peer_sockets[index];
if (peer_socket == 0) {
peer_socket = uv__fast_poll_create_peer_socket(loop->iocp, protocol_info);
@@ -357,8 +356,8 @@ static DWORD WINAPI uv__slow_poll_thread_proc(void* arg) {
efds.fd_count = 0;
}
- /* Make the select() time out after 3 minutes. If select() hangs because */
- /* the user closed the socket, we will at least not hang indefinitely. */
+ /* Make the select() time out after 3 minutes. If select() hangs because the
+ * user closed the socket, we will at least not hang indefinitely. */
timeout.tv_sec = 3 * 60;
timeout.tv_usec = 0;
@@ -462,7 +461,7 @@ static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
if ((handle->events & ~(handle->submitted_events_1 |
handle->submitted_events_2)) != 0) {
uv__slow_poll_submit_poll_req(loop, handle);
- } else if ((handle->flags & UV__HANDLE_CLOSING) &&
+ } else if ((handle->flags & UV_HANDLE_CLOSING) &&
handle->submitted_events_1 == 0 &&
handle->submitted_events_2 == 0) {
uv_want_endgame(loop, (uv_handle_t*) handle);
@@ -472,7 +471,7 @@ static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
static int uv__slow_poll_set(uv_loop_t* loop, uv_poll_t* handle, int events) {
assert(handle->type == UV_POLL);
- assert(!(handle->flags & UV__HANDLE_CLOSING));
+ assert(!(handle->flags & UV_HANDLE_CLOSING));
assert((events & ~(UV_READABLE | UV_WRITABLE)) == 0);
handle->events = events;
@@ -522,10 +521,10 @@ int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR)
return uv_translate_sys_error(WSAGetLastError());
- /* Try to obtain a base handle for the socket. This increases this chances */
- /* that we find an AFD handle and are able to use the fast poll mechanism. */
- /* This will always fail on windows XP/2k3, since they don't support the */
- /* SIO_BASE_HANDLE ioctl. */
+/* Try to obtain a base handle for the socket. This increases this chances that
+ * we find an AFD handle and are able to use the fast poll mechanism. This will
+ * always fail on windows XP/2k3, since they don't support the. SIO_BASE_HANDLE
+ * ioctl. */
#ifndef NDEBUG
base_socket = INVALID_SOCKET;
#endif
@@ -557,9 +556,9 @@ int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
return uv_translate_sys_error(WSAGetLastError());
}
- /* Get the peer socket that is needed to enable fast poll. If the returned */
- /* value is NULL, the protocol is not implemented by MSAFD and we'll have */
- /* to use slow mode. */
+ /* Get the peer socket that is needed to enable fast poll. If the returned
+ * value is NULL, the protocol is not implemented by MSAFD and we'll have to
+ * use slow mode. */
peer_socket = uv__fast_poll_get_peer_socket(loop, &protocol_info);
if (peer_socket != INVALID_SOCKET) {
@@ -634,7 +633,7 @@ int uv_poll_close(uv_loop_t* loop, uv_poll_t* handle) {
void uv_poll_endgame(uv_loop_t* loop, uv_poll_t* handle) {
- assert(handle->flags & UV__HANDLE_CLOSING);
+ assert(handle->flags & UV_HANDLE_CLOSING);
assert(!(handle->flags & UV_HANDLE_CLOSED));
assert(handle->submitted_events_1 == 0);
diff --git a/Utilities/cmlibuv/src/win/process-stdio.c b/Utilities/cmlibuv/src/win/process-stdio.c
index 032e30935..355d61880 100644
--- a/Utilities/cmlibuv/src/win/process-stdio.c
+++ b/Utilities/cmlibuv/src/win/process-stdio.c
@@ -103,12 +103,12 @@ static int uv__create_stdio_pipe_pair(uv_loop_t* loop,
DWORD client_access = 0;
HANDLE child_pipe = INVALID_HANDLE_VALUE;
int err;
+ int overlap;
if (flags & UV_READABLE_PIPE) {
- /* The server needs inbound access too, otherwise CreateNamedPipe() */
- /* won't give us the FILE_READ_ATTRIBUTES permission. We need that to */
- /* probe the state of the write buffer when we're trying to shutdown */
- /* the pipe. */
+ /* The server needs inbound access too, otherwise CreateNamedPipe() won't
+ * give us the FILE_READ_ATTRIBUTES permission. We need that to probe the
+ * state of the write buffer when we're trying to shutdown the pipe. */
server_access |= PIPE_ACCESS_OUTBOUND | PIPE_ACCESS_INBOUND;
client_access |= GENERIC_READ | FILE_WRITE_ATTRIBUTES;
}
@@ -131,12 +131,13 @@ static int uv__create_stdio_pipe_pair(uv_loop_t* loop,
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
+ overlap = server_pipe->ipc || (flags & UV_OVERLAPPED_PIPE);
child_pipe = CreateFileA(pipe_name,
client_access,
0,
&sa,
OPEN_EXISTING,
- server_pipe->ipc ? FILE_FLAG_OVERLAPPED : 0,
+ overlap ? FILE_FLAG_OVERLAPPED : 0,
NULL);
if (child_pipe == INVALID_HANDLE_VALUE) {
err = GetLastError();
@@ -159,8 +160,8 @@ static int uv__create_stdio_pipe_pair(uv_loop_t* loop,
}
#endif
- /* Do a blocking ConnectNamedPipe. This should not block because we have */
- /* both ends of the pipe created. */
+ /* Do a blocking ConnectNamedPipe. This should not block because we have both
+ * ends of the pipe created. */
if (!ConnectNamedPipe(server_pipe->handle, NULL)) {
if (GetLastError() != ERROR_PIPE_CONNECTED) {
err = GetLastError();
@@ -194,11 +195,11 @@ static int uv__duplicate_handle(uv_loop_t* loop, HANDLE handle, HANDLE* dup) {
HANDLE current_process;
- /* _get_osfhandle will sometimes return -2 in case of an error. This seems */
- /* to happen when fd <= 2 and the process' corresponding stdio handle is */
- /* set to NULL. Unfortunately DuplicateHandle will happily duplicate */
- /* (HANDLE) -2, so this situation goes unnoticed until someone tries to */
- /* use the duplicate. Therefore we filter out known-invalid handles here. */
+ /* _get_osfhandle will sometimes return -2 in case of an error. This seems to
+ * happen when fd <= 2 and the process' corresponding stdio handle is set to
+ * NULL. Unfortunately DuplicateHandle will happily duplicate (HANDLE) -2, so
+ * this situation goes unnoticed until someone tries to use the duplicate.
+ * Therefore we filter out known-invalid handles here. */
if (handle == INVALID_HANDLE_VALUE ||
handle == NULL ||
handle == (HANDLE) -2) {
@@ -284,8 +285,8 @@ int uv__stdio_create(uv_loop_t* loop,
return ERROR_OUTOFMEMORY;
}
- /* Prepopulate the buffer with INVALID_HANDLE_VALUE handles so we can */
- /* clean up on failure. */
+ /* Prepopulate the buffer with INVALID_HANDLE_VALUE handles so we can clean
+ * up on failure. */
CHILD_STDIO_COUNT(buffer) = count;
for (i = 0; i < count; i++) {
CHILD_STDIO_CRT_FLAGS(buffer, i) = 0;
@@ -303,12 +304,12 @@ int uv__stdio_create(uv_loop_t* loop,
switch (fdopt.flags & (UV_IGNORE | UV_CREATE_PIPE | UV_INHERIT_FD |
UV_INHERIT_STREAM)) {
case UV_IGNORE:
- /* Starting a process with no stdin/stout/stderr can confuse it. */
- /* So no matter what the user specified, we make sure the first */
- /* three FDs are always open in their typical modes, e.g. stdin */
- /* be readable and stdout/err should be writable. For FDs > 2, don't */
- /* do anything - all handles in the stdio buffer are initialized with */
- /* INVALID_HANDLE_VALUE, which should be okay. */
+ /* Starting a process with no stdin/stout/stderr can confuse it. So no
+ * matter what the user specified, we make sure the first three FDs are
+ * always open in their typical modes, e. g. stdin be readable and
+ * stdout/err should be writable. For FDs > 2, don't do anything - all
+ * handles in the stdio buffer are initialized with.
+ * INVALID_HANDLE_VALUE, which should be okay. */
if (i <= 2) {
DWORD access = (i == 0) ? FILE_GENERIC_READ :
FILE_GENERIC_WRITE | FILE_READ_ATTRIBUTES;
@@ -323,14 +324,14 @@ int uv__stdio_create(uv_loop_t* loop,
break;
case UV_CREATE_PIPE: {
- /* Create a pair of two connected pipe ends; one end is turned into */
- /* an uv_pipe_t for use by the parent. The other one is given to */
- /* the child. */
+ /* Create a pair of two connected pipe ends; one end is turned into an
+ * uv_pipe_t for use by the parent. The other one is given to the
+ * child. */
uv_pipe_t* parent_pipe = (uv_pipe_t*) fdopt.data.stream;
HANDLE child_pipe = INVALID_HANDLE_VALUE;
- /* Create a new, connected pipe pair. stdio[i].stream should point */
- /* to an uninitialized, but not connected pipe handle. */
+ /* Create a new, connected pipe pair. stdio[i]. stream should point to
+ * an uninitialized, but not connected pipe handle. */
assert(fdopt.data.stream->type == UV_NAMED_PIPE);
assert(!(fdopt.data.stream->flags & UV_HANDLE_CONNECTION));
assert(!(fdopt.data.stream->flags & UV_HANDLE_PIPESERVER));
@@ -354,8 +355,8 @@ int uv__stdio_create(uv_loop_t* loop,
/* Make an inheritable duplicate of the handle. */
err = uv__duplicate_fd(loop, fdopt.data.fd, &child_handle);
if (err) {
- /* If fdopt.data.fd is not valid and fd fd <= 2, then ignore the */
- /* error. */
+ /* If fdopt. data. fd is not valid and fd <= 2, then ignore the
+ * error. */
if (fdopt.data.fd <= 2 && err == ERROR_INVALID_HANDLE) {
CHILD_STDIO_CRT_FLAGS(buffer, i) = 0;
CHILD_STDIO_HANDLE(buffer, i) = INVALID_HANDLE_VALUE;
@@ -418,8 +419,8 @@ int uv__stdio_create(uv_loop_t* loop,
if (stream_handle == NULL ||
stream_handle == INVALID_HANDLE_VALUE) {
- /* The handle is already closed, or not yet created, or the */
- /* stream type is not supported. */
+ /* The handle is already closed, or not yet created, or the stream
+ * type is not supported. */
err = ERROR_NOT_SUPPORTED;
goto error;
}
diff --git a/Utilities/cmlibuv/src/win/process.c b/Utilities/cmlibuv/src/win/process.c
index d14160160..24037b302 100644
--- a/Utilities/cmlibuv/src/win/process.c
+++ b/Utilities/cmlibuv/src/win/process.c
@@ -360,8 +360,8 @@ static WCHAR* search_path(const WCHAR *file,
return NULL;
}
- /* Find the start of the filename so we can split the directory from the */
- /* name. */
+ /* Find the start of the filename so we can split the directory from the
+ * name. */
for (file_name_start = (WCHAR*)file + file_len;
file_name_start > file
&& file_name_start[-1] != L'\\'
@@ -405,8 +405,15 @@ static WCHAR* search_path(const WCHAR *file,
/* Next slice starts just after where the previous one ended */
dir_start = dir_end;
+ /* If path is quoted, find quote end */
+ if (*dir_start == L'"' || *dir_start == L'\'') {
+ dir_end = wcschr(dir_start + 1, *dir_start);
+ if (dir_end == NULL) {
+ dir_end = wcschr(dir_start, L'\0');
+ }
+ }
/* Slice until the next ; or \0 is found */
- dir_end = wcschr(dir_start, L';');
+ dir_end = wcschr(dir_end, L';');
if (dir_end == NULL) {
dir_end = wcschr(dir_start, L'\0');
}
@@ -549,8 +556,8 @@ int make_program_args(char** args, int verbatim_arguments, WCHAR** dst_ptr) {
arg_count++;
}
- /* Adjust for potential quotes. Also assume the worst-case scenario */
- /* that every character needs escaping, so we need twice as much space. */
+ /* Adjust for potential quotes. Also assume the worst-case scenario that
+ * every character needs escaping, so we need twice as much space. */
dst_len = dst_len * 2 + arg_count * 2;
/* Allocate buffer for the final command line. */
@@ -732,7 +739,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
}
}
*ptr_copy = NULL;
- assert(env_len == ptr - dst_copy);
+ assert(env_len == (size_t) (ptr - dst_copy));
/* sort our (UTF-16) copy */
qsort(env_copy, env_block_count-1, sizeof(wchar_t*), qsort_wcscmp);
@@ -792,7 +799,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
var_size = GetEnvironmentVariableW(required_vars[i].wide,
ptr,
(int) (env_len - (ptr - dst)));
- if (var_size != len-1) { /* race condition? */
+ if (var_size != (DWORD) (len - 1)) { /* TODO: handle race condition? */
uv_fatal_error(GetLastError(), "GetEnvironmentVariableW");
}
}
@@ -808,7 +815,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
}
/* Terminate with an extra NULL. */
- assert(env_len == (ptr - dst));
+ assert(env_len == (size_t) (ptr - dst));
*ptr = L'\0';
uv__free(dst_copy);
@@ -824,8 +831,13 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) {
*/
static WCHAR* find_path(WCHAR *env) {
for (; env != NULL && *env != 0; env += wcslen(env) + 1) {
- if (wcsncmp(env, L"PATH=", 5) == 0)
+ if ((env[0] == L'P' || env[0] == L'p') &&
+ (env[1] == L'A' || env[1] == L'a') &&
+ (env[2] == L'T' || env[2] == L't') &&
+ (env[3] == L'H' || env[3] == L'h') &&
+ (env[4] == L'=')) {
return &env[5];
+ }
}
return NULL;
@@ -858,9 +870,9 @@ void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle) {
assert(handle->exit_cb_pending);
handle->exit_cb_pending = 0;
- /* If we're closing, don't call the exit callback. Just schedule a close */
- /* callback now. */
- if (handle->flags & UV__HANDLE_CLOSING) {
+ /* If we're closing, don't call the exit callback. Just schedule a close
+ * callback now. */
+ if (handle->flags & UV_HANDLE_CLOSING) {
uv_want_endgame(loop, (uv_handle_t*) handle);
return;
}
@@ -871,14 +883,14 @@ void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle) {
handle->wait_handle = INVALID_HANDLE_VALUE;
}
- /* Set the handle to inactive: no callbacks will be made after the exit */
- /* callback.*/
+ /* Set the handle to inactive: no callbacks will be made after the exit
+ * callback. */
uv__handle_stop(handle);
if (GetExitCodeProcess(handle->process_handle, &status)) {
exit_code = status;
} else {
- /* Unable to to obtain the exit code. This should never happen. */
+ /* Unable to obtain the exit code. This should never happen. */
exit_code = uv_translate_sys_error(GetLastError());
}
@@ -893,8 +905,8 @@ void uv_process_close(uv_loop_t* loop, uv_process_t* handle) {
uv__handle_closing(handle);
if (handle->wait_handle != INVALID_HANDLE_VALUE) {
- /* This blocks until either the wait was cancelled, or the callback has */
- /* completed. */
+ /* This blocks until either the wait was cancelled, or the callback has
+ * completed. */
BOOL r = UnregisterWaitEx(handle->wait_handle, INVALID_HANDLE_VALUE);
if (!r) {
/* This should never happen, and if it happens, we can't recover... */
@@ -912,7 +924,7 @@ void uv_process_close(uv_loop_t* loop, uv_process_t* handle) {
void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle) {
assert(!handle->exit_cb_pending);
- assert(handle->flags & UV__HANDLE_CLOSING);
+ assert(handle->flags & UV_HANDLE_CLOSING);
assert(!(handle->flags & UV_HANDLE_CLOSED));
/* Clean-up the process handle. */
@@ -947,11 +959,19 @@ int uv_spawn(uv_loop_t* loop,
return UV_EINVAL;
}
+ if (options->cpumask != NULL) {
+ if (options->cpumask_size < (size_t)uv_cpumask_size()) {
+ return UV_EINVAL;
+ }
+ }
+
assert(options->file != NULL);
assert(!(options->flags & ~(UV_PROCESS_DETACHED |
UV_PROCESS_SETGID |
UV_PROCESS_SETUID |
UV_PROCESS_WINDOWS_HIDE |
+ UV_PROCESS_WINDOWS_HIDE_CONSOLE |
+ UV_PROCESS_WINDOWS_HIDE_GUI |
UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)));
err = uv_utf8_to_utf16_alloc(options->file, &application);
@@ -1051,15 +1071,26 @@ int uv_spawn(uv_loop_t* loop,
startup.hStdOutput = uv__stdio_handle(process->child_stdio_buffer, 1);
startup.hStdError = uv__stdio_handle(process->child_stdio_buffer, 2);
- if (options->flags & UV_PROCESS_WINDOWS_HIDE) {
+ process_flags = CREATE_UNICODE_ENVIRONMENT;
+
+ if ((options->flags & UV_PROCESS_WINDOWS_HIDE_CONSOLE) ||
+ (options->flags & UV_PROCESS_WINDOWS_HIDE)) {
+ /* Avoid creating console window if stdio is not inherited. */
+ for (i = 0; i < options->stdio_count; i++) {
+ if (options->stdio[i].flags & UV_INHERIT_FD)
+ break;
+ if (i == options->stdio_count - 1)
+ process_flags |= CREATE_NO_WINDOW;
+ }
+ }
+ if ((options->flags & UV_PROCESS_WINDOWS_HIDE_GUI) ||
+ (options->flags & UV_PROCESS_WINDOWS_HIDE)) {
/* Use SW_HIDE to avoid any potential process window. */
startup.wShowWindow = SW_HIDE;
} else {
startup.wShowWindow = SW_SHOWDEFAULT;
}
- process_flags = CREATE_UNICODE_ENVIRONMENT;
-
if (options->flags & UV_PROCESS_DETACHED) {
/* Note that we're not setting the CREATE_BREAKAWAY_FROM_JOB flag. That
* means that libuv might not let you create a fully daemonized process
@@ -1074,6 +1105,12 @@ int uv_spawn(uv_loop_t* loop,
process_flags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP;
}
+ if (options->cpumask != NULL) {
+ /* Create the child in a suspended state so we have a chance to set
+ its process affinity before it runs. */
+ process_flags |= CREATE_SUSPENDED;
+ }
+
if (!CreateProcessW(application_path,
arguments,
NULL,
@@ -1089,14 +1126,57 @@ int uv_spawn(uv_loop_t* loop,
goto done;
}
- /* Spawn succeeded */
- /* Beyond this point, failure is reported asynchronously. */
+ if (options->cpumask != NULL) {
+ /* The child is currently suspended. Set its process affinity
+ or terminate it if we can't. */
+ int i;
+ int cpumasksize;
+ DWORD_PTR sysmask;
+ DWORD_PTR oldmask;
+ DWORD_PTR newmask;
+
+ cpumasksize = uv_cpumask_size();
+
+ if (!GetProcessAffinityMask(info.hProcess, &oldmask, &sysmask)) {
+ err = GetLastError();
+ TerminateProcess(info.hProcess, 1);
+ goto done;
+ }
+
+ newmask = 0;
+ for (i = 0; i < cpumasksize; i++) {
+ if (options->cpumask[i]) {
+ if (oldmask & (((DWORD_PTR)1) << i)) {
+ newmask |= ((DWORD_PTR)1) << i;
+ } else {
+ err = UV_EINVAL;
+ TerminateProcess(info.hProcess, 1);
+ goto done;
+ }
+ }
+ }
+
+ if (!SetProcessAffinityMask(info.hProcess, newmask)) {
+ err = GetLastError();
+ TerminateProcess(info.hProcess, 1);
+ goto done;
+ }
+
+ /* The process affinity of the child is set. Let it run. */
+ if (ResumeThread(info.hThread) == ((DWORD)-1)) {
+ err = GetLastError();
+ TerminateProcess(info.hProcess, 1);
+ goto done;
+ }
+ }
+
+ /* Spawn succeeded. Beyond this point, failure is reported asynchronously. */
process->process_handle = info.hProcess;
process->pid = info.dwProcessId;
- /* If the process isn't spawned as detached, assign to the global job */
- /* object so windows will kill it when the parent process dies. */
+ /* If the process isn't spawned as detached, assign to the global job object
+ * so windows will kill it when the parent process dies. */
if (!(options->flags & UV_PROCESS_DETACHED)) {
uv_once(&uv_global_job_handle_init_guard_, uv__init_global_job_handle);
@@ -1123,7 +1203,8 @@ int uv_spawn(uv_loop_t* loop,
if (fdopt->flags & UV_CREATE_PIPE &&
fdopt->data.stream->type == UV_NAMED_PIPE &&
((uv_pipe_t*) fdopt->data.stream)->ipc) {
- ((uv_pipe_t*) fdopt->data.stream)->pipe.conn.ipc_pid = info.dwProcessId;
+ ((uv_pipe_t*) fdopt->data.stream)->pipe.conn.ipc_remote_pid =
+ info.dwProcessId;
}
}
@@ -1139,8 +1220,8 @@ int uv_spawn(uv_loop_t* loop,
assert(!err);
- /* Make the handle active. It will remain active until the exit callback */
- /* is made or the handle is closed, whichever happens first. */
+ /* Make the handle active. It will remain active until the exit callback is
+ * made or the handle is closed, whichever happens first. */
uv__handle_start(process);
/* Cleanup, whether we succeeded or failed. */
@@ -1163,20 +1244,24 @@ int uv_spawn(uv_loop_t* loop,
static int uv__kill(HANDLE process_handle, int signum) {
+ if (signum < 0 || signum >= NSIG) {
+ return UV_EINVAL;
+ }
+
switch (signum) {
case SIGTERM:
case SIGKILL:
case SIGINT: {
- /* Unconditionally terminate the process. On Windows, killed processes */
- /* normally return 1. */
+ /* Unconditionally terminate the process. On Windows, killed processes
+ * normally return 1. */
DWORD status;
int err;
if (TerminateProcess(process_handle, 1))
return 0;
- /* If the process already exited before TerminateProcess was called, */
- /* TerminateProcess will fail with ERROR_ACCESS_DENIED. */
+ /* If the process already exited before TerminateProcess was called,.
+ * TerminateProcess will fail with ERROR_ACCESS_DENIED. */
err = GetLastError();
if (err == ERROR_ACCESS_DENIED &&
GetExitCodeProcess(process_handle, &status) &&
@@ -1227,8 +1312,15 @@ int uv_process_kill(uv_process_t* process, int signum) {
int uv_kill(int pid, int signum) {
int err;
- HANDLE process_handle = OpenProcess(PROCESS_TERMINATE |
- PROCESS_QUERY_INFORMATION, FALSE, pid);
+ HANDLE process_handle;
+
+ if (pid == 0) {
+ process_handle = GetCurrentProcess();
+ } else {
+ process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
+ FALSE,
+ pid);
+ }
if (process_handle == NULL) {
err = GetLastError();
diff --git a/Utilities/cmlibuv/src/win/signal.c b/Utilities/cmlibuv/src/win/signal.c
index 7b42dd992..276dc6097 100644
--- a/Utilities/cmlibuv/src/win/signal.c
+++ b/Utilities/cmlibuv/src/win/signal.c
@@ -47,13 +47,13 @@ void uv_signals_init(void) {
static int uv__signal_compare(uv_signal_t* w1, uv_signal_t* w2) {
- /* Compare signums first so all watchers with the same signnum end up */
- /* adjacent. */
+ /* Compare signums first so all watchers with the same signnum end up
+ * adjacent. */
if (w1->signum < w2->signum) return -1;
if (w1->signum > w2->signum) return 1;
- /* Sort by loop pointer, so we can easily look up the first item after */
- /* { .signum = x, .loop = NULL } */
+ /* Sort by loop pointer, so we can easily look up the first item after
+ * { .signum = x, .loop = NULL }. */
if ((uintptr_t) w1->loop < (uintptr_t) w2->loop) return -1;
if ((uintptr_t) w1->loop > (uintptr_t) w2->loop) return 1;
@@ -64,7 +64,7 @@ static int uv__signal_compare(uv_signal_t* w1, uv_signal_t* w2) {
}
-RB_GENERATE_STATIC(uv_signal_tree_s, uv_signal_s, tree_entry, uv__signal_compare);
+RB_GENERATE_STATIC(uv_signal_tree_s, uv_signal_s, tree_entry, uv__signal_compare)
/*
@@ -90,7 +90,7 @@ int uv__signal_dispatch(int signum) {
unsigned long previous = InterlockedExchange(
(volatile LONG*) &handle->pending_signum, signum);
- if (handle->flags & UV__SIGNAL_ONE_SHOT_DISPATCHED)
+ if (handle->flags & UV_SIGNAL_ONE_SHOT_DISPATCHED)
continue;
if (!previous) {
@@ -98,8 +98,8 @@ int uv__signal_dispatch(int signum) {
}
dispatched = 1;
- if (handle->flags & UV__SIGNAL_ONE_SHOT)
- handle->flags |= UV__SIGNAL_ONE_SHOT_DISPATCHED;
+ if (handle->flags & UV_SIGNAL_ONE_SHOT)
+ handle->flags |= UV_SIGNAL_ONE_SHOT_DISPATCHED;
}
LeaveCriticalSection(&uv__signal_lock);
@@ -118,10 +118,10 @@ static BOOL WINAPI uv__signal_control_handler(DWORD type) {
case CTRL_CLOSE_EVENT:
if (uv__signal_dispatch(SIGHUP)) {
- /* Windows will terminate the process after the control handler */
- /* returns. After that it will just terminate our process. Therefore */
- /* block the signal handler so the main loop has some time to pick */
- /* up the signal and do something for a few seconds. */
+ /* Windows will terminate the process after the control handler
+ * returns. After that it will just terminate our process. Therefore
+ * block the signal handler so the main loop has some time to pick up
+ * the signal and do something for a few seconds. */
Sleep(INFINITE);
return TRUE;
}
@@ -129,8 +129,8 @@ static BOOL WINAPI uv__signal_control_handler(DWORD type) {
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
- /* These signals are only sent to services. Services have their own */
- /* notification mechanism, so there's no point in handling these. */
+ /* These signals are only sent to services. Services have their own
+ * notification mechanism, so there's no point in handling these. */
default:
/* We don't handle these. */
@@ -190,13 +190,13 @@ int uv__signal_start(uv_signal_t* handle,
int signum,
int oneshot) {
/* Test for invalid signal values. */
- if (signum != SIGWINCH && (signum <= 0 || signum >= NSIG))
+ if (signum <= 0 || signum >= NSIG)
return UV_EINVAL;
- /* Short circuit: if the signal watcher is already watching {signum} don't */
- /* go through the process of deregistering and registering the handler. */
- /* Additionally, this avoids pending signals getting lost in the (small) */
- /* time frame that handle->signum == 0. */
+ /* Short circuit: if the signal watcher is already watching {signum} don't go
+ * through the process of deregistering and registering the handler.
+ * Additionally, this avoids pending signals getting lost in the (small) time
+ * frame that handle->signum == 0. */
if (signum == handle->signum) {
handle->signal_cb = signal_cb;
return 0;
@@ -213,7 +213,7 @@ int uv__signal_start(uv_signal_t* handle,
handle->signum = signum;
if (oneshot)
- handle->flags |= UV__SIGNAL_ONE_SHOT;
+ handle->flags |= UV_SIGNAL_ONE_SHOT;
RB_INSERT(uv_signal_tree_s, &uv__signal_tree, handle);
@@ -237,16 +237,16 @@ void uv_process_signal_req(uv_loop_t* loop, uv_signal_t* handle,
(volatile LONG*) &handle->pending_signum, 0);
assert(dispatched_signum != 0);
- /* Check if the pending signal equals the signum that we are watching for. */
- /* These can get out of sync when the handler is stopped and restarted */
- /* while the signal_req is pending. */
+ /* Check if the pending signal equals the signum that we are watching for.
+ * These can get out of sync when the handler is stopped and restarted while
+ * the signal_req is pending. */
if (dispatched_signum == handle->signum)
handle->signal_cb(handle, dispatched_signum);
- if (handle->flags & UV__SIGNAL_ONE_SHOT)
+ if (handle->flags & UV_SIGNAL_ONE_SHOT)
uv_signal_stop(handle);
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
/* When it is closing, it must be stopped at this point. */
assert(handle->signum == 0);
uv_want_endgame(loop, (uv_handle_t*) handle);
@@ -265,7 +265,7 @@ void uv_signal_close(uv_loop_t* loop, uv_signal_t* handle) {
void uv_signal_endgame(uv_loop_t* loop, uv_signal_t* handle) {
- assert(handle->flags & UV__HANDLE_CLOSING);
+ assert(handle->flags & UV_HANDLE_CLOSING);
assert(!(handle->flags & UV_HANDLE_CLOSED));
assert(handle->signum == 0);
diff --git a/Utilities/cmlibuv/src/win/stream-inl.h b/Utilities/cmlibuv/src/win/stream-inl.h
index bf12148af..40f5ddd51 100644
--- a/Utilities/cmlibuv/src/win/stream-inl.h
+++ b/Utilities/cmlibuv/src/win/stream-inl.h
@@ -36,19 +36,18 @@ INLINE static void uv_stream_init(uv_loop_t* loop,
uv__handle_init(loop, (uv_handle_t*) handle, type);
handle->write_queue_size = 0;
handle->activecnt = 0;
-}
-
-
-INLINE static void uv_connection_init(uv_stream_t* handle) {
- handle->flags |= UV_HANDLE_CONNECTION;
+ handle->stream.conn.shutdown_req = NULL;
handle->stream.conn.write_reqs_pending = 0;
UV_REQ_INIT(&handle->read_req, UV_READ);
handle->read_req.event_handle = NULL;
handle->read_req.wait_handle = INVALID_HANDLE_VALUE;
handle->read_req.data = handle;
+}
- handle->stream.conn.shutdown_req = NULL;
+
+INLINE static void uv_connection_init(uv_stream_t* handle) {
+ handle->flags |= UV_HANDLE_CONNECTION;
}
diff --git a/Utilities/cmlibuv/src/win/stream.c b/Utilities/cmlibuv/src/win/stream.c
index 13cbfdcb9..7656627e9 100644
--- a/Utilities/cmlibuv/src/win/stream.c
+++ b/Utilities/cmlibuv/src/win/stream.c
@@ -105,12 +105,10 @@ int uv_read_stop(uv_stream_t* handle) {
err = 0;
if (handle->type == UV_TTY) {
err = uv_tty_read_stop((uv_tty_t*) handle);
+ } else if (handle->type == UV_NAMED_PIPE) {
+ uv__pipe_read_stop((uv_pipe_t*) handle);
} else {
- if (handle->type == UV_NAMED_PIPE) {
- uv__pipe_stop_read((uv_pipe_t*) handle);
- } else {
- handle->flags &= ~UV_HANDLE_READING;
- }
+ handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(handle->loop, handle);
}
@@ -136,7 +134,8 @@ int uv_write(uv_write_t* req,
err = uv_tcp_write(loop, req, (uv_tcp_t*) handle, bufs, nbufs, cb);
break;
case UV_NAMED_PIPE:
- err = uv_pipe_write(loop, req, (uv_pipe_t*) handle, bufs, nbufs, cb);
+ err = uv__pipe_write(
+ loop, req, (uv_pipe_t*) handle, bufs, nbufs, NULL, cb);
break;
case UV_TTY:
err = uv_tty_write(loop, req, (uv_tty_t*) handle, bufs, nbufs, cb);
@@ -158,25 +157,18 @@ int uv_write2(uv_write_t* req,
uv_loop_t* loop = handle->loop;
int err;
- if (!(handle->flags & UV_HANDLE_WRITABLE)) {
- return UV_EPIPE;
+ if (send_handle == NULL) {
+ return uv_write(req, handle, bufs, nbufs, cb);
}
- err = ERROR_INVALID_PARAMETER;
- switch (handle->type) {
- case UV_NAMED_PIPE:
- err = uv_pipe_write2(loop,
- req,
- (uv_pipe_t*) handle,
- bufs,
- nbufs,
- send_handle,
- cb);
- break;
- default:
- assert(0);
+ if (handle->type != UV_NAMED_PIPE || !((uv_pipe_t*) handle)->ipc) {
+ return UV_EINVAL;
+ } else if (!(handle->flags & UV_HANDLE_WRITABLE)) {
+ return UV_EPIPE;
}
+ err = uv__pipe_write(
+ loop, req, (uv_pipe_t*) handle, bufs, nbufs, send_handle, cb);
return uv_translate_sys_error(err);
}
@@ -184,7 +176,7 @@ int uv_write2(uv_write_t* req,
int uv_try_write(uv_stream_t* stream,
const uv_buf_t bufs[],
unsigned int nbufs) {
- if (stream->flags & UV__HANDLE_CLOSING)
+ if (stream->flags & UV_HANDLE_CLOSING)
return UV_EBADF;
if (!(stream->flags & UV_HANDLE_WRITABLE))
return UV_EPIPE;
diff --git a/Utilities/cmlibuv/src/win/tcp.c b/Utilities/cmlibuv/src/win/tcp.c
index 972539f4d..3ce5548c0 100644
--- a/Utilities/cmlibuv/src/win/tcp.c
+++ b/Utilities/cmlibuv/src/win/tcp.c
@@ -99,8 +99,8 @@ static int uv_tcp_set_socket(uv_loop_t* loop,
if (!SetHandleInformation((HANDLE) socket, HANDLE_FLAG_INHERIT, 0))
return GetLastError();
- /* Associate it with the I/O completion port. */
- /* Use uv_handle_t pointer as completion key. */
+ /* Associate it with the I/O completion port. Use uv_handle_t pointer as
+ * completion key. */
if (CreateIoCompletionPort((HANDLE)socket,
loop->iocp,
(ULONG_PTR)socket,
@@ -118,15 +118,12 @@ static int uv_tcp_set_socket(uv_loop_t* loop,
non_ifs_lsp = uv_tcp_non_ifs_lsp_ipv4;
}
- if (pSetFileCompletionNotificationModes &&
- !(handle->flags & UV_HANDLE_EMULATE_IOCP) && !non_ifs_lsp) {
- if (pSetFileCompletionNotificationModes((HANDLE) socket,
- FILE_SKIP_SET_EVENT_ON_HANDLE |
- FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) {
- handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
- } else if (GetLastError() != ERROR_INVALID_FUNCTION) {
+ if (!(handle->flags & UV_HANDLE_EMULATE_IOCP) && !non_ifs_lsp) {
+ UCHAR sfcnm_flags =
+ FILE_SKIP_SET_EVENT_ON_HANDLE | FILE_SKIP_COMPLETION_PORT_ON_SUCCESS;
+ if (!SetFileCompletionNotificationModes((HANDLE) socket, sfcnm_flags))
return GetLastError();
- }
+ handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
}
if (handle->flags & UV_HANDLE_TCP_NODELAY) {
@@ -220,7 +217,7 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
UNREGISTER_HANDLE_REQ(loop, handle, handle->stream.conn.shutdown_req);
err = 0;
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
err = ERROR_OPERATION_ABORTED;
} else if (shutdown(handle->socket, SD_SEND) == SOCKET_ERROR) {
err = WSAGetLastError();
@@ -236,7 +233,7 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
return;
}
- if (handle->flags & UV__HANDLE_CLOSING &&
+ if (handle->flags & UV_HANDLE_CLOSING &&
handle->reqs_pending == 0) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
@@ -326,9 +323,9 @@ static int uv_tcp_try_bind(uv_tcp_t* handle,
on = (flags & UV_TCP_IPV6ONLY) != 0;
- /* TODO: how to handle errors? This may fail if there is no ipv4 stack */
- /* available, or when run on XP/2003 which have no support for dualstack */
- /* sockets. For now we're silently ignoring the error. */
+ /* TODO: how to handle errors? This may fail if there is no ipv4 stack
+ * available, or when run on XP/2003 which have no support for dualstack
+ * sockets. For now we're silently ignoring the error. */
setsockopt(handle->socket,
IPPROTO_IPV6,
IPV6_V6ONLY,
@@ -459,8 +456,6 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) {
INFINITE, WT_EXECUTEINWAITTHREAD)) {
SET_REQ_ERROR(req, GetLastError());
uv_insert_pending_req(loop, (uv_req_t*)req);
- handle->reqs_pending++;
- return;
}
} else {
/* Make this req pending reporting an error. */
@@ -628,9 +623,9 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
uv_tcp_queue_accept(handle, req);
}
- /* Initialize other unused requests too, because uv_tcp_endgame */
- /* doesn't know how how many requests were initialized, so it will */
- /* try to clean up {uv_simultaneous_server_accepts} requests. */
+ /* Initialize other unused requests too, because uv_tcp_endgame doesn't
+ * know how many requests were initialized, so it will try to clean up
+ * {uv_simultaneous_server_accepts} requests. */
for (i = simultaneous_accepts; i < uv_simultaneous_server_accepts; i++) {
req = &handle->tcp.serv.accept_reqs[i];
UV_REQ_INIT(req, UV_ACCEPT);
@@ -685,7 +680,7 @@ int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) {
req->next_pending = NULL;
req->accept_socket = INVALID_SOCKET;
- if (!(server->flags & UV__HANDLE_CLOSING)) {
+ if (!(server->flags & UV_HANDLE_CLOSING)) {
/* Check if we're in a middle of changing the number of pending accepts. */
if (!(server->flags & UV_HANDLE_TCP_ACCEPT_STATE_CHANGING)) {
uv_tcp_queue_accept(server, req);
@@ -723,8 +718,8 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb,
handle->alloc_cb = alloc_cb;
INCREASE_ACTIVE_COUNT(loop, handle);
- /* If reading was stopped and then started again, there could still be a */
- /* read request pending. */
+ /* If reading was stopped and then started again, there could still be a read
+ * request pending. */
if (!(handle->flags & UV_HANDLE_READ_PENDING)) {
if (handle->flags & UV_HANDLE_EMULATE_IOCP &&
!handle->read_req.event_handle) {
@@ -747,10 +742,15 @@ static int uv_tcp_try_connect(uv_connect_t* req,
uv_connect_cb cb) {
uv_loop_t* loop = handle->loop;
const struct sockaddr* bind_addr;
+ struct sockaddr_storage converted;
BOOL success;
DWORD bytes;
int err;
+ err = uv__convert_to_localhost_if_unspecified(addr, &converted);
+ if (err)
+ return err;
+
if (handle->delayed_error) {
return handle->delayed_error;
}
@@ -782,12 +782,12 @@ static int uv_tcp_try_connect(uv_connect_t* req,
memset(&req->u.io.overlapped, 0, sizeof(req->u.io.overlapped));
success = handle->tcp.conn.func_connectex(handle->socket,
- addr,
- addrlen,
- NULL,
- 0,
- &bytes,
- &req->u.io.overlapped);
+ (const struct sockaddr*) &converted,
+ addrlen,
+ NULL,
+ 0,
+ &bytes,
+ &req->u.io.overlapped);
if (UV_SUCCEEDED_WITHOUT_IOCP(success)) {
/* Process the req without IOCP. */
@@ -945,6 +945,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_req_t* req) {
DWORD bytes, flags, err;
uv_buf_t buf;
+ int count;
assert(handle->type == UV_TCP);
@@ -962,8 +963,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
err = GET_REQ_SOCK_ERROR(req);
if (err == WSAECONNABORTED) {
- /*
- * Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix.
+ /* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix.
*/
err = WSAECONNRESET;
}
@@ -1000,7 +1000,8 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
}
/* Do nonblocking reads until the buffer is empty */
- while (handle->flags & UV_HANDLE_READING) {
+ count = 32;
+ while ((handle->flags & UV_HANDLE_READING) && (count-- > 0)) {
buf = uv_buf_init(NULL, 0);
handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.base == NULL || buf.len == 0) {
@@ -1043,8 +1044,8 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
DECREASE_ACTIVE_COUNT(loop, handle);
if (err == WSAECONNABORTED) {
- /* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with */
- /* Unix. */
+ /* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with
+ * Unix. */
err = WSAECONNRESET;
}
@@ -1116,10 +1117,9 @@ void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
assert(handle->type == UV_TCP);
- /* If handle->accepted_socket is not a valid socket, then */
- /* uv_queue_accept must have failed. This is a serious error. We stop */
- /* accepting connections and report this error to the connection */
- /* callback. */
+ /* If handle->accepted_socket is not a valid socket, then uv_queue_accept
+ * must have failed. This is a serious error. We stop accepting connections
+ * and report this error to the connection callback. */
if (req->accept_socket == INVALID_SOCKET) {
if (handle->flags & UV_HANDLE_LISTENING) {
handle->flags &= ~UV_HANDLE_LISTENING;
@@ -1144,9 +1144,9 @@ void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
handle->stream.serv.connection_cb((uv_stream_t*)handle, 0);
}
} else {
- /* Error related to accepted socket is ignored because the server */
- /* socket may still be healthy. If the server socket is broken */
- /* uv_queue_accept will detect it. */
+ /* Error related to accepted socket is ignored because the server socket
+ * may still be healthy. If the server socket is broken uv_queue_accept
+ * will detect it. */
closesocket(req->accept_socket);
req->accept_socket = INVALID_SOCKET;
if (handle->flags & UV_HANDLE_LISTENING) {
@@ -1168,11 +1168,14 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
err = 0;
if (REQ_SUCCESS(req)) {
- if (setsockopt(handle->socket,
- SOL_SOCKET,
- SO_UPDATE_CONNECT_CONTEXT,
- NULL,
- 0) == 0) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
+ /* use UV_ECANCELED for consistency with Unix */
+ err = ERROR_OPERATION_ABORTED;
+ } else if (setsockopt(handle->socket,
+ SOL_SOCKET,
+ SO_UPDATE_CONNECT_CONTEXT,
+ NULL,
+ 0) == 0) {
uv_connection_init((uv_stream_t*)handle);
handle->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
loop->active_tcp_streams++;
@@ -1188,40 +1191,76 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
}
-int uv_tcp_import(uv_tcp_t* tcp, uv__ipc_socket_info_ex* socket_info_ex,
- int tcp_connection) {
+int uv__tcp_xfer_export(uv_tcp_t* handle,
+ int target_pid,
+ uv__ipc_socket_xfer_type_t* xfer_type,
+ uv__ipc_socket_xfer_info_t* xfer_info) {
+ if (handle->flags & UV_HANDLE_CONNECTION) {
+ *xfer_type = UV__IPC_SOCKET_XFER_TCP_CONNECTION;
+ } else {
+ *xfer_type = UV__IPC_SOCKET_XFER_TCP_SERVER;
+ /* We're about to share the socket with another process. Because this is a
+ * listening socket, we assume that the other process will be accepting
+ * connections on it. Thus, before sharing the socket with another process,
+ * we call listen here in the parent process. */
+ if (!(handle->flags & UV_HANDLE_LISTENING)) {
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ return ERROR_NOT_SUPPORTED;
+ }
+ if (handle->delayed_error == 0 &&
+ listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
+ handle->delayed_error = WSAGetLastError();
+ }
+ }
+ }
+
+ if (WSADuplicateSocketW(handle->socket, target_pid, &xfer_info->socket_info))
+ return WSAGetLastError();
+ xfer_info->delayed_error = handle->delayed_error;
+
+ /* Mark the local copy of the handle as 'shared' so we behave in a way that's
+ * friendly to the process(es) that we share the socket with. */
+ handle->flags |= UV_HANDLE_SHARED_TCP_SOCKET;
+
+ return 0;
+}
+
+
+int uv__tcp_xfer_import(uv_tcp_t* tcp,
+ uv__ipc_socket_xfer_type_t xfer_type,
+ uv__ipc_socket_xfer_info_t* xfer_info) {
int err;
- SOCKET socket = WSASocketW(FROM_PROTOCOL_INFO,
- FROM_PROTOCOL_INFO,
- FROM_PROTOCOL_INFO,
- &socket_info_ex->socket_info,
- 0,
- WSA_FLAG_OVERLAPPED);
+ SOCKET socket;
+
+ assert(xfer_type == UV__IPC_SOCKET_XFER_TCP_SERVER ||
+ xfer_type == UV__IPC_SOCKET_XFER_TCP_CONNECTION);
+
+ socket = WSASocketW(FROM_PROTOCOL_INFO,
+ FROM_PROTOCOL_INFO,
+ FROM_PROTOCOL_INFO,
+ &xfer_info->socket_info,
+ 0,
+ WSA_FLAG_OVERLAPPED);
if (socket == INVALID_SOCKET) {
return WSAGetLastError();
}
- err = uv_tcp_set_socket(tcp->loop,
- tcp,
- socket,
- socket_info_ex->socket_info.iAddressFamily,
- 1);
+ err = uv_tcp_set_socket(
+ tcp->loop, tcp, socket, xfer_info->socket_info.iAddressFamily, 1);
if (err) {
closesocket(socket);
return err;
}
- if (tcp_connection) {
+ tcp->delayed_error = xfer_info->delayed_error;
+ tcp->flags |= UV_HANDLE_BOUND | UV_HANDLE_SHARED_TCP_SOCKET;
+
+ if (xfer_type == UV__IPC_SOCKET_XFER_TCP_CONNECTION) {
uv_connection_init((uv_stream_t*)tcp);
tcp->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
}
- tcp->flags |= UV_HANDLE_BOUND;
- tcp->flags |= UV_HANDLE_SHARED_TCP_SOCKET;
-
- tcp->delayed_error = socket_info_ex->delayed_error;
-
tcp->loop->active_tcp_streams++;
return 0;
}
@@ -1267,39 +1306,6 @@ int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay) {
}
-int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
- LPWSAPROTOCOL_INFOW protocol_info) {
- if (!(handle->flags & UV_HANDLE_CONNECTION)) {
- /*
- * We're about to share the socket with another process. Because
- * this is a listening socket, we assume that the other process will
- * be accepting connections on it. So, before sharing the socket
- * with another process, we call listen here in the parent process.
- */
-
- if (!(handle->flags & UV_HANDLE_LISTENING)) {
- if (!(handle->flags & UV_HANDLE_BOUND)) {
- return ERROR_INVALID_PARAMETER;
- }
-
- if (!(handle->delayed_error)) {
- if (listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
- handle->delayed_error = WSAGetLastError();
- }
- }
- }
- }
-
- if (WSADuplicateSocketW(handle->socket, pid, protocol_info)) {
- return WSAGetLastError();
- }
-
- handle->flags |= UV_HANDLE_SHARED_TCP_SOCKET;
-
- return 0;
-}
-
-
int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable) {
if (handle->flags & UV_HANDLE_CONNECTION) {
return UV_EINVAL;
@@ -1340,8 +1346,8 @@ static int uv_tcp_try_cancel_io(uv_tcp_t* tcp) {
non_ifs_lsp = (tcp->flags & UV_HANDLE_IPV6) ? uv_tcp_non_ifs_lsp_ipv6 :
uv_tcp_non_ifs_lsp_ipv4;
- /* If there are non-ifs LSPs then try to obtain a base handle for the */
- /* socket. This will always fail on Windows XP/3k. */
+ /* If there are non-ifs LSPs then try to obtain a base handle for the socket.
+ * This will always fail on Windows XP/3k. */
if (non_ifs_lsp) {
DWORD bytes;
if (WSAIoctl(socket,
@@ -1373,38 +1379,37 @@ void uv_tcp_close(uv_loop_t* loop, uv_tcp_t* tcp) {
int close_socket = 1;
if (tcp->flags & UV_HANDLE_READ_PENDING) {
- /* In order for winsock to do a graceful close there must not be any */
- /* any pending reads, or the socket must be shut down for writing */
+ /* In order for winsock to do a graceful close there must not be any any
+ * pending reads, or the socket must be shut down for writing */
if (!(tcp->flags & UV_HANDLE_SHARED_TCP_SOCKET)) {
/* Just do shutdown on non-shared sockets, which ensures graceful close. */
shutdown(tcp->socket, SD_SEND);
} else if (uv_tcp_try_cancel_io(tcp) == 0) {
- /* In case of a shared socket, we try to cancel all outstanding I/O, */
- /* If that works, don't close the socket yet - wait for the read req to */
- /* return and close the socket in uv_tcp_endgame. */
+ /* In case of a shared socket, we try to cancel all outstanding I/O,. If
+ * that works, don't close the socket yet - wait for the read req to
+ * return and close the socket in uv_tcp_endgame. */
close_socket = 0;
} else {
- /* When cancelling isn't possible - which could happen when an LSP is */
- /* present on an old Windows version, we will have to close the socket */
- /* with a read pending. That is not nice because trailing sent bytes */
- /* may not make it to the other side. */
+ /* When cancelling isn't possible - which could happen when an LSP is
+ * present on an old Windows version, we will have to close the socket
+ * with a read pending. That is not nice because trailing sent bytes may
+ * not make it to the other side. */
}
} else if ((tcp->flags & UV_HANDLE_SHARED_TCP_SOCKET) &&
tcp->tcp.serv.accept_reqs != NULL) {
- /* Under normal circumstances closesocket() will ensure that all pending */
- /* accept reqs are canceled. However, when the socket is shared the */
- /* presence of another reference to the socket in another process will */
- /* keep the accept reqs going, so we have to ensure that these are */
- /* canceled. */
+ /* Under normal circumstances closesocket() will ensure that all pending
+ * accept reqs are canceled. However, when the socket is shared the
+ * presence of another reference to the socket in another process will keep
+ * the accept reqs going, so we have to ensure that these are canceled. */
if (uv_tcp_try_cancel_io(tcp) != 0) {
- /* When cancellation is not possible, there is another option: we can */
- /* close the incoming sockets, which will also cancel the accept */
- /* operations. However this is not cool because we might inadvertently */
- /* close a socket that just accepted a new connection, which will */
- /* cause the connection to be aborted. */
+ /* When cancellation is not possible, there is another option: we can
+ * close the incoming sockets, which will also cancel the accept
+ * operations. However this is not cool because we might inadvertently
+ * close a socket that just accepted a new connection, which will cause
+ * the connection to be aborted. */
unsigned int i;
for (i = 0; i < uv_simultaneous_server_accepts; i++) {
uv_tcp_accept_t* req = &tcp->tcp.serv.accept_reqs[i];
@@ -1446,6 +1451,8 @@ int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) {
WSAPROTOCOL_INFOW protocol_info;
int opt_len;
int err;
+ struct sockaddr_storage saddr;
+ int saddr_len;
/* Detect the address family of the socket. */
opt_len = (int) sizeof protocol_info;
@@ -1466,6 +1473,19 @@ int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock) {
return uv_translate_sys_error(err);
}
+ /* Support already active socket. */
+ saddr_len = sizeof(saddr);
+ if (!uv_tcp_getsockname(handle, (struct sockaddr*) &saddr, &saddr_len)) {
+ /* Socket is already bound. */
+ handle->flags |= UV_HANDLE_BOUND;
+ saddr_len = sizeof(saddr);
+ if (!uv_tcp_getpeername(handle, (struct sockaddr*) &saddr, &saddr_len)) {
+ /* Socket is already connected. */
+ uv_connection_init((uv_stream_t*) handle);
+ handle->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
+ }
+ }
+
return 0;
}
diff --git a/Utilities/cmlibuv/src/win/thread.c b/Utilities/cmlibuv/src/win/thread.c
index 91684e938..fd4b7c986 100644
--- a/Utilities/cmlibuv/src/win/thread.c
+++ b/Utilities/cmlibuv/src/win/thread.c
@@ -23,29 +23,15 @@
#include <limits.h>
#include <stdlib.h>
+#if defined(__MINGW64_VERSION_MAJOR)
+/* MemoryBarrier expands to __mm_mfence in some cases (x86+sse2), which may
+ * require this header in some versions of mingw64. */
+#include <intrin.h>
+#endif
+
#include "uv.h"
#include "internal.h"
-
-#define HAVE_CONDVAR_API() (pInitializeConditionVariable != NULL)
-
-static int uv_cond_fallback_init(uv_cond_t* cond);
-static void uv_cond_fallback_destroy(uv_cond_t* cond);
-static void uv_cond_fallback_signal(uv_cond_t* cond);
-static void uv_cond_fallback_broadcast(uv_cond_t* cond);
-static void uv_cond_fallback_wait(uv_cond_t* cond, uv_mutex_t* mutex);
-static int uv_cond_fallback_timedwait(uv_cond_t* cond,
- uv_mutex_t* mutex, uint64_t timeout);
-
-static int uv_cond_condvar_init(uv_cond_t* cond);
-static void uv_cond_condvar_destroy(uv_cond_t* cond);
-static void uv_cond_condvar_signal(uv_cond_t* cond);
-static void uv_cond_condvar_broadcast(uv_cond_t* cond);
-static void uv_cond_condvar_wait(uv_cond_t* cond, uv_mutex_t* mutex);
-static int uv_cond_condvar_timedwait(uv_cond_t* cond,
- uv_mutex_t* mutex, uint64_t timeout);
-
-
static void uv__once_inner(uv_once_t* guard, void (*callback)(void)) {
DWORD result;
HANDLE existing_event, created_event;
@@ -69,8 +55,8 @@ static void uv__once_inner(uv_once_t* guard, void (*callback)(void)) {
guard->ran = 1;
} else {
- /* We lost the race. Destroy the event we created and wait for the */
- /* existing one to become signaled. */
+ /* We lost the race. Destroy the event we created and wait for the existing
+ * one to become signaled. */
CloseHandle(created_event);
result = WaitForSingleObject(existing_event, INFINITE);
assert(result == WAIT_OBJECT_0);
@@ -138,7 +124,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
ctx->arg = arg;
/* Create the thread in suspended state so we have a chance to pass
- * its own creation handle to it */
+ * its own creation handle to it */
thread = (HANDLE) _beginthreadex(NULL,
0,
uv__thread_start,
@@ -182,6 +168,7 @@ int uv_thread_join(uv_thread_t *tid) {
else {
CloseHandle(*tid);
*tid = 0;
+ MemoryBarrier(); /* For feature parity with pthread_join(). */
return 0;
}
}
@@ -198,6 +185,11 @@ int uv_mutex_init(uv_mutex_t* mutex) {
}
+int uv_mutex_init_recursive(uv_mutex_t* mutex) {
+ return uv_mutex_init(mutex);
+}
+
+
void uv_mutex_destroy(uv_mutex_t* mutex) {
DeleteCriticalSection(mutex);
}
@@ -371,220 +363,35 @@ int uv_sem_trywait(uv_sem_t* sem) {
}
-/* This condition variable implementation is based on the SetEvent solution
- * (section 3.2) at http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
- * We could not use the SignalObjectAndWait solution (section 3.4) because
- * it want the 2nd argument (type uv_mutex_t) of uv_cond_wait() and
- * uv_cond_timedwait() to be HANDLEs, but we use CRITICAL_SECTIONs.
- */
-
-static int uv_cond_fallback_init(uv_cond_t* cond) {
- int err;
-
- /* Initialize the count to 0. */
- cond->fallback.waiters_count = 0;
-
- InitializeCriticalSection(&cond->fallback.waiters_count_lock);
-
- /* Create an auto-reset event. */
- cond->fallback.signal_event = CreateEvent(NULL, /* no security */
- FALSE, /* auto-reset event */
- FALSE, /* non-signaled initially */
- NULL); /* unnamed */
- if (!cond->fallback.signal_event) {
- err = GetLastError();
- goto error2;
- }
-
- /* Create a manual-reset event. */
- cond->fallback.broadcast_event = CreateEvent(NULL, /* no security */
- TRUE, /* manual-reset */
- FALSE, /* non-signaled */
- NULL); /* unnamed */
- if (!cond->fallback.broadcast_event) {
- err = GetLastError();
- goto error;
- }
-
- return 0;
-
-error:
- CloseHandle(cond->fallback.signal_event);
-error2:
- DeleteCriticalSection(&cond->fallback.waiters_count_lock);
- return uv_translate_sys_error(err);
-}
-
-
-static int uv_cond_condvar_init(uv_cond_t* cond) {
- pInitializeConditionVariable(&cond->cond_var);
- return 0;
-}
-
-
int uv_cond_init(uv_cond_t* cond) {
- uv__once_init();
-
- if (HAVE_CONDVAR_API())
- return uv_cond_condvar_init(cond);
- else
- return uv_cond_fallback_init(cond);
-}
-
-
-static void uv_cond_fallback_destroy(uv_cond_t* cond) {
- if (!CloseHandle(cond->fallback.broadcast_event))
- abort();
- if (!CloseHandle(cond->fallback.signal_event))
- abort();
- DeleteCriticalSection(&cond->fallback.waiters_count_lock);
-}
-
-
-static void uv_cond_condvar_destroy(uv_cond_t* cond) {
- /* nothing to do */
+ InitializeConditionVariable(&cond->cond_var);
+ return 0;
}
void uv_cond_destroy(uv_cond_t* cond) {
- if (HAVE_CONDVAR_API())
- uv_cond_condvar_destroy(cond);
- else
- uv_cond_fallback_destroy(cond);
-}
-
-
-static void uv_cond_fallback_signal(uv_cond_t* cond) {
- int have_waiters;
-
- /* Avoid race conditions. */
- EnterCriticalSection(&cond->fallback.waiters_count_lock);
- have_waiters = cond->fallback.waiters_count > 0;
- LeaveCriticalSection(&cond->fallback.waiters_count_lock);
-
- if (have_waiters)
- SetEvent(cond->fallback.signal_event);
-}
-
-
-static void uv_cond_condvar_signal(uv_cond_t* cond) {
- pWakeConditionVariable(&cond->cond_var);
+ /* nothing to do */
+ (void) &cond;
}
void uv_cond_signal(uv_cond_t* cond) {
- if (HAVE_CONDVAR_API())
- uv_cond_condvar_signal(cond);
- else
- uv_cond_fallback_signal(cond);
-}
-
-
-static void uv_cond_fallback_broadcast(uv_cond_t* cond) {
- int have_waiters;
-
- /* Avoid race conditions. */
- EnterCriticalSection(&cond->fallback.waiters_count_lock);
- have_waiters = cond->fallback.waiters_count > 0;
- LeaveCriticalSection(&cond->fallback.waiters_count_lock);
-
- if (have_waiters)
- SetEvent(cond->fallback.broadcast_event);
-}
-
-
-static void uv_cond_condvar_broadcast(uv_cond_t* cond) {
- pWakeAllConditionVariable(&cond->cond_var);
+ WakeConditionVariable(&cond->cond_var);
}
void uv_cond_broadcast(uv_cond_t* cond) {
- if (HAVE_CONDVAR_API())
- uv_cond_condvar_broadcast(cond);
- else
- uv_cond_fallback_broadcast(cond);
-}
-
-
-static int uv_cond_wait_helper(uv_cond_t* cond, uv_mutex_t* mutex,
- DWORD dwMilliseconds) {
- DWORD result;
- int last_waiter;
- HANDLE handles[2] = {
- cond->fallback.signal_event,
- cond->fallback.broadcast_event
- };
-
- /* Avoid race conditions. */
- EnterCriticalSection(&cond->fallback.waiters_count_lock);
- cond->fallback.waiters_count++;
- LeaveCriticalSection(&cond->fallback.waiters_count_lock);
-
- /* It's ok to release the <mutex> here since Win32 manual-reset events */
- /* maintain state when used with <SetEvent>. This avoids the "lost wakeup" */
- /* bug. */
- uv_mutex_unlock(mutex);
-
- /* Wait for either event to become signaled due to <uv_cond_signal> being */
- /* called or <uv_cond_broadcast> being called. */
- result = WaitForMultipleObjects(2, handles, FALSE, dwMilliseconds);
-
- EnterCriticalSection(&cond->fallback.waiters_count_lock);
- cond->fallback.waiters_count--;
- last_waiter = result == WAIT_OBJECT_0 + 1
- && cond->fallback.waiters_count == 0;
- LeaveCriticalSection(&cond->fallback.waiters_count_lock);
-
- /* Some thread called <pthread_cond_broadcast>. */
- if (last_waiter) {
- /* We're the last waiter to be notified or to stop waiting, so reset the */
- /* the manual-reset event. */
- ResetEvent(cond->fallback.broadcast_event);
- }
-
- /* Reacquire the <mutex>. */
- uv_mutex_lock(mutex);
-
- if (result == WAIT_OBJECT_0 || result == WAIT_OBJECT_0 + 1)
- return 0;
-
- if (result == WAIT_TIMEOUT)
- return UV_ETIMEDOUT;
-
- abort();
- return -1; /* Satisfy the compiler. */
-}
-
-
-static void uv_cond_fallback_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
- if (uv_cond_wait_helper(cond, mutex, INFINITE))
- abort();
-}
-
-
-static void uv_cond_condvar_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
- if (!pSleepConditionVariableCS(&cond->cond_var, mutex, INFINITE))
- abort();
+ WakeAllConditionVariable(&cond->cond_var);
}
void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
- if (HAVE_CONDVAR_API())
- uv_cond_condvar_wait(cond, mutex);
- else
- uv_cond_fallback_wait(cond, mutex);
-}
-
-
-static int uv_cond_fallback_timedwait(uv_cond_t* cond,
- uv_mutex_t* mutex, uint64_t timeout) {
- return uv_cond_wait_helper(cond, mutex, (DWORD)(timeout / 1e6));
+ if (!SleepConditionVariableCS(&cond->cond_var, mutex, INFINITE))
+ abort();
}
-
-static int uv_cond_condvar_timedwait(uv_cond_t* cond,
- uv_mutex_t* mutex, uint64_t timeout) {
- if (pSleepConditionVariableCS(&cond->cond_var, mutex, (DWORD)(timeout / 1e6)))
+int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
+ if (SleepConditionVariableCS(&cond->cond_var, mutex, (DWORD)(timeout / 1e6)))
return 0;
if (GetLastError() != ERROR_TIMEOUT)
abort();
@@ -592,15 +399,6 @@ static int uv_cond_condvar_timedwait(uv_cond_t* cond,
}
-int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex,
- uint64_t timeout) {
- if (HAVE_CONDVAR_API())
- return uv_cond_condvar_timedwait(cond, mutex, timeout);
- else
- return uv_cond_fallback_timedwait(cond, mutex, timeout);
-}
-
-
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
int err;
diff --git a/Utilities/cmlibuv/src/win/tty.c b/Utilities/cmlibuv/src/win/tty.c
index a6f583956..f38e9a886 100644
--- a/Utilities/cmlibuv/src/win/tty.c
+++ b/Utilities/cmlibuv/src/win/tty.c
@@ -25,7 +25,7 @@
#include <stdlib.h>
#if defined(_MSC_VER) && _MSC_VER < 1600
-# include "stdint-msvc2008.h"
+# include "uv/stdint-msvc2008.h"
#else
# include <stdint.h>
#endif
@@ -112,14 +112,30 @@ static int uv_tty_virtual_offset = -1;
static int uv_tty_virtual_height = -1;
static int uv_tty_virtual_width = -1;
+/* The console window size
+ * We keep this separate from uv_tty_virtual_*. We use those values to only
+ * handle signalling SIGWINCH
+ */
+
+static HANDLE uv__tty_console_handle = INVALID_HANDLE_VALUE;
+static int uv__tty_console_height = -1;
+static int uv__tty_console_width = -1;
+
+static DWORD WINAPI uv__tty_console_resize_message_loop_thread(void* param);
+static void CALLBACK uv__tty_console_resize_event(HWINEVENTHOOK hWinEventHook,
+ DWORD event,
+ HWND hwnd,
+ LONG idObject,
+ LONG idChild,
+ DWORD dwEventThread,
+ DWORD dwmsEventTime);
+
/* We use a semaphore rather than a mutex or critical section because in some
cases (uv__cancel_read_console) we need take the lock in the main thread and
release it in another thread. Using a semaphore ensures that in such
scenario the main thread will still block when trying to acquire the lock. */
static uv_sem_t uv_tty_output_lock;
-static HANDLE uv_tty_output_handle = INVALID_HANDLE_VALUE;
-
static WORD uv_tty_default_text_attributes =
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
@@ -141,13 +157,29 @@ static void uv__determine_vterm_state(HANDLE handle);
void uv_console_init(void) {
if (uv_sem_init(&uv_tty_output_lock, 1))
abort();
+ uv__tty_console_handle = CreateFileW(L"CONOUT$",
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_WRITE,
+ 0,
+ OPEN_EXISTING,
+ 0,
+ 0);
+ if (uv__tty_console_handle != INVALID_HANDLE_VALUE) {
+ QueueUserWorkItem(uv__tty_console_resize_message_loop_thread,
+ NULL,
+ WT_EXECUTELONGFUNCTION);
+ }
}
-int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
+int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int unused) {
+ BOOL readable;
+ DWORD NumberOfEvents;
HANDLE handle;
CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
+ (void)unused;
+ uv__once_init();
handle = (HANDLE) uv__get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE)
return UV_EBADF;
@@ -170,24 +202,20 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd, int readable) {
fd = -1;
}
+ readable = GetNumberOfConsoleInputEvents(handle, &NumberOfEvents);
if (!readable) {
/* Obtain the screen buffer info with the output handle. */
if (!GetConsoleScreenBufferInfo(handle, &screen_buffer_info)) {
return uv_translate_sys_error(GetLastError());
}
- /* Obtain the the tty_output_lock because the virtual window state is */
- /* shared between all uv_tty_t handles. */
+ /* Obtain the tty_output_lock because the virtual window state is shared
+ * between all uv_tty_t handles. */
uv_sem_wait(&uv_tty_output_lock);
if (uv__vterm_state == UV_UNCHECKED)
uv__determine_vterm_state(handle);
- /* Store the global tty output handle. This handle is used by TTY read */
- /* streams to update the virtual window when a CONSOLE_BUFFER_SIZE_EVENT */
- /* is received. */
- uv_tty_output_handle = handle;
-
/* Remember the original console text attributes. */
uv_tty_capture_initial_style(&screen_buffer_info);
@@ -332,6 +360,8 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
}
} else {
was_reading = 0;
+ alloc_cb = NULL;
+ read_cb = NULL;
}
uv_sem_wait(&uv_tty_output_lock);
@@ -358,12 +388,6 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
}
-int uv_is_tty(uv_file file) {
- DWORD result;
- return GetConsoleMode((HANDLE) _get_osfhandle(file), &result) != 0;
-}
-
-
int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
CONSOLE_SCREEN_BUFFER_INFO info;
@@ -460,8 +484,8 @@ static DWORD CALLBACK uv_tty_line_read_thread(void* data) {
bytes = MAX_INPUT_BUFFER_LENGTH;
}
- /* At last, unicode! */
- /* One utf-16 codeunit never takes more than 3 utf-8 codeunits to encode */
+ /* At last, unicode! One utf-16 codeunit never takes more than 3 utf-8
+ * codeunits to encode. */
chars = bytes / 3;
status = InterlockedExchange(&uv__read_console_status, IN_PROGRESS);
@@ -596,10 +620,10 @@ static const char* get_vt100_fn_key(DWORD code, char shift, char ctrl,
}
switch (code) {
- /* These mappings are the same as Cygwin's. Unmodified and alt-modified */
- /* keypad keys comply with linux console, modifiers comply with xterm */
- /* modifier usage. F1..f12 and shift-f1..f10 comply with linux console, */
- /* f6..f12 with and without modifiers comply with rxvt. */
+ /* These mappings are the same as Cygwin's. Unmodified and alt-modified
+ * keypad keys comply with linux console, modifiers comply with xterm
+ * modifier usage. F1. f12 and shift-f1. f10 comply with linux console, f6.
+ * f12 with and without modifiers comply with rxvt. */
VK_CASE(VK_INSERT, "[2~", "[2;2~", "[2;5~", "[2;6~")
VK_CASE(VK_END, "[4~", "[4;2~", "[4;5~", "[4;6~")
VK_CASE(VK_DOWN, "[B", "[1;2B", "[1;5B", "[1;6B")
@@ -682,8 +706,8 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
goto out;
}
- /* Windows sends a lot of events that we're not interested in, so buf */
- /* will be allocated on demand, when there's actually something to emit. */
+ /* Windows sends a lot of events that we're not interested in, so buf will be
+ * allocated on demand, when there's actually something to emit. */
buf = uv_null_buf_;
buf_used = 0;
@@ -704,39 +728,22 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
}
records_left--;
- /* If the window was resized, recompute the virtual window size. This */
- /* will trigger a SIGWINCH signal if the window size changed in an */
- /* way that matters to libuv. */
- if (handle->tty.rd.last_input_record.EventType == WINDOW_BUFFER_SIZE_EVENT) {
- CONSOLE_SCREEN_BUFFER_INFO info;
-
- uv_sem_wait(&uv_tty_output_lock);
-
- if (uv_tty_output_handle != INVALID_HANDLE_VALUE &&
- GetConsoleScreenBufferInfo(uv_tty_output_handle, &info)) {
- uv_tty_update_virtual_window(&info);
- }
-
- uv_sem_post(&uv_tty_output_lock);
-
- continue;
- }
-
- /* Ignore other events that are not key or resize events. */
+ /* Ignore other events that are not key events. */
if (handle->tty.rd.last_input_record.EventType != KEY_EVENT) {
continue;
}
- /* Ignore keyup events, unless the left alt key was held and a valid */
- /* unicode character was emitted. */
- if (!KEV.bKeyDown && !(((KEV.dwControlKeyState & LEFT_ALT_PRESSED) ||
- KEV.wVirtualKeyCode==VK_MENU) && KEV.uChar.UnicodeChar != 0)) {
+ /* Ignore keyup events, unless the left alt key was held and a valid
+ * unicode character was emitted. */
+ if (!KEV.bKeyDown &&
+ KEV.wVirtualKeyCode != VK_MENU &&
+ KEV.uChar.UnicodeChar != 0) {
continue;
}
- /* Ignore keypresses to numpad number keys if the left alt is held */
- /* because the user is composing a character, or windows simulating */
- /* this. */
+ /* Ignore keypresses to numpad number keys if the left alt is held
+ * because the user is composing a character, or windows simulating this.
+ */
if ((KEV.dwControlKeyState & LEFT_ALT_PRESSED) &&
!(KEV.dwControlKeyState & ENHANCED_KEY) &&
(KEV.wVirtualKeyCode == VK_INSERT ||
@@ -773,8 +780,8 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
continue;
}
- /* Prefix with \u033 if alt was held, but alt was not used as part */
- /* a compose sequence. */
+ /* Prefix with \u033 if alt was held, but alt was not used as part a
+ * compose sequence. */
if ((KEV.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
&& !(KEV.dwControlKeyState & (LEFT_CTRL_PRESSED |
RIGHT_CTRL_PRESSED)) && KEV.bKeyDown) {
@@ -787,8 +794,9 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
if (KEV.uChar.UnicodeChar >= 0xDC00 &&
KEV.uChar.UnicodeChar < 0xE000) {
/* UTF-16 surrogate pair */
- WCHAR utf16_buffer[2] = { handle->tty.rd.last_utf16_high_surrogate,
- KEV.uChar.UnicodeChar};
+ WCHAR utf16_buffer[2];
+ utf16_buffer[0] = handle->tty.rd.last_utf16_high_surrogate;
+ utf16_buffer[1] = KEV.uChar.UnicodeChar;
char_len = WideCharToMultiByte(CP_UTF8,
0,
utf16_buffer,
@@ -812,8 +820,8 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle,
/* Whatever happened, the last character wasn't a high surrogate. */
handle->tty.rd.last_utf16_high_surrogate = 0;
- /* If the utf16 character(s) couldn't be converted something must */
- /* be wrong. */
+ /* If the utf16 character(s) couldn't be converted something must be
+ * wrong. */
if (!char_len) {
handle->flags &= ~UV_HANDLE_READING;
DECREASE_ACTIVE_COUNT(loop, handle);
@@ -937,21 +945,15 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GET_REQ_ERROR(req)),
&buf);
- } else {
- /* The read was cancelled, or whatever we don't care */
- handle->read_cb((uv_stream_t*) handle, 0, &buf);
}
-
} else {
- if (!(handle->flags & UV_HANDLE_CANCELLATION_PENDING)) {
- /* Read successful */
- /* TODO: read unicode, convert to utf-8 */
+ if (!(handle->flags & UV_HANDLE_CANCELLATION_PENDING) &&
+ req->u.io.overlapped.InternalHigh != 0) {
+ /* Read successful. TODO: read unicode, convert to utf-8 */
DWORD bytes = req->u.io.overlapped.InternalHigh;
handle->read_cb((uv_stream_t*) handle, bytes, &buf);
- } else {
- handle->flags &= ~UV_HANDLE_CANCELLATION_PENDING;
- handle->read_cb((uv_stream_t*) handle, 0, &buf);
}
+ handle->flags &= ~UV_HANDLE_CANCELLATION_PENDING;
}
/* Wait for more input events. */
@@ -969,9 +971,9 @@ void uv_process_tty_read_req(uv_loop_t* loop, uv_tty_t* handle,
assert(handle->type == UV_TTY);
assert(handle->flags & UV_HANDLE_TTY_READABLE);
- /* If the read_line_buffer member is zero, it must have been an raw read. */
- /* Otherwise it was a line-buffered read. */
- /* FIXME: This is quite obscure. Use a flag or something. */
+ /* If the read_line_buffer member is zero, it must have been an raw read.
+ * Otherwise it was a line-buffered read. FIXME: This is quite obscure. Use a
+ * flag or something. */
if (handle->tty.rd.read_line_buffer.len == 0) {
uv_process_tty_read_raw_req(loop, handle, req);
} else {
@@ -993,14 +995,14 @@ int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb,
handle->read_cb = read_cb;
handle->alloc_cb = alloc_cb;
- /* If reading was stopped and then started again, there could still be a */
- /* read request pending. */
+ /* If reading was stopped and then started again, there could still be a read
+ * request pending. */
if (handle->flags & UV_HANDLE_READ_PENDING) {
return 0;
}
- /* Maybe the user stopped reading half-way while processing key events. */
- /* Short-circuit if this could be the case. */
+ /* Maybe the user stopped reading half-way while processing key events.
+ * Short-circuit if this could be the case. */
if (handle->tty.rd.last_key_len > 0) {
SET_REQ_SUCCESS(&handle->read_req);
uv_insert_pending_req(handle->loop, (uv_req_t*) &handle->read_req);
@@ -1027,9 +1029,10 @@ int uv_tty_read_stop(uv_tty_t* handle) {
return 0;
if (handle->flags & UV_HANDLE_TTY_RAW) {
- /* Cancel raw read */
- /* Write some bullshit event to force the console wait to return. */
+ /* Cancel raw read. Write some bullshit event to force the console wait to
+ * return. */
memset(&record, 0, sizeof record);
+ record.EventType = FOCUS_EVENT;
if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) {
return GetLastError();
}
@@ -1102,9 +1105,6 @@ static int uv__cancel_read_console(uv_tty_t* handle) {
static void uv_tty_update_virtual_window(CONSOLE_SCREEN_BUFFER_INFO* info) {
- int old_virtual_width = uv_tty_virtual_width;
- int old_virtual_height = uv_tty_virtual_height;
-
uv_tty_virtual_width = info->dwSize.X;
uv_tty_virtual_height = info->srWindow.Bottom - info->srWindow.Top + 1;
@@ -1113,8 +1113,8 @@ static void uv_tty_update_virtual_window(CONSOLE_SCREEN_BUFFER_INFO* info) {
uv_tty_virtual_offset = info->dwCursorPosition.Y;
} else if (uv_tty_virtual_offset < info->dwCursorPosition.Y -
uv_tty_virtual_height + 1) {
- /* If suddenly find the cursor outside of the virtual window, it must */
- /* have somehow scrolled. Update the virtual window offset. */
+ /* If suddenly find the cursor outside of the virtual window, it must have
+ * somehow scrolled. Update the virtual window offset. */
uv_tty_virtual_offset = info->dwCursorPosition.Y -
uv_tty_virtual_height + 1;
}
@@ -1124,14 +1124,6 @@ static void uv_tty_update_virtual_window(CONSOLE_SCREEN_BUFFER_INFO* info) {
if (uv_tty_virtual_offset < 0) {
uv_tty_virtual_offset = 0;
}
-
- /* If the virtual window size changed, emit a SIGWINCH signal. Don't emit */
- /* if this was the first time the virtual window size was computed. */
- if (old_virtual_width != -1 && old_virtual_height != -1 &&
- (uv_tty_virtual_width != old_virtual_width ||
- uv_tty_virtual_height != old_virtual_height)) {
- uv__signal_dispatch(SIGWINCH);
- }
}
@@ -1309,8 +1301,8 @@ static int uv_tty_clear(uv_tty_t* handle, int dir, char entire_screen,
x2 = 0;
x2r = 1;
} else {
- /* Clear to end of row. We pretend the console is 65536 characters wide, */
- /* uv_tty_make_real_coord will clip it to the actual console width. */
+ /* Clear to end of row. We pretend the console is 65536 characters wide,
+ * uv_tty_make_real_coord will clip it to the actual console width. */
x2 = 0xffff;
x2r = 0;
}
@@ -1618,8 +1610,8 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
const uv_buf_t bufs[],
unsigned int nbufs,
DWORD* error) {
- /* We can only write 8k characters at a time. Windows can't handle */
- /* much more characters in a single console write anyway. */
+ /* We can only write 8k characters at a time. Windows can't handle much more
+ * characters in a single console write anyway. */
WCHAR utf16_buf[MAX_CONSOLE_CHAR];
WCHAR* utf16_buffer;
DWORD utf16_buf_used = 0;
@@ -1655,9 +1647,8 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
unsigned char previous_eol = handle->tty.wr.previous_eol;
unsigned char ansi_parser_state = handle->tty.wr.ansi_parser_state;
- /* Store the error here. If we encounter an error, stop trying to do i/o */
- /* but keep parsing the buffer so we leave the parser in a consistent */
- /* state. */
+ /* Store the error here. If we encounter an error, stop trying to do i/o but
+ * keep parsing the buffer so we leave the parser in a consistent state. */
*error = ERROR_SUCCESS;
utf16_buffer = utf16_buf;
@@ -1705,9 +1696,9 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
for (j = 0; j < buf.len; j++) {
unsigned char c = buf.base[j];
- /* Run the character through the utf8 decoder We happily accept non */
- /* shortest form encodings and invalid code points - there's no real */
- /* harm that can be done. */
+ /* Run the character through the utf8 decoder We happily accept non
+ * shortest form encodings and invalid code points - there's no real harm
+ * that can be done. */
if (utf8_bytes_left == 0) {
/* Read utf-8 start byte */
DWORD first_zero_bit;
@@ -1747,8 +1738,8 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
/* Start byte where continuation was expected. */
utf8_bytes_left = 0;
utf8_codepoint = UNICODE_REPLACEMENT_CHARACTER;
- /* Patch buf offset so this character will be parsed again as a */
- /* start byte. */
+ /* Patch buf offset so this character will be parsed again as a start
+ * byte. */
j--;
}
@@ -1781,8 +1772,8 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
case '_':
case 'P':
case ']':
- /* Not supported, but we'll have to parse until we see a stop */
- /* code, e.g. ESC \ or BEL. */
+ /* Not supported, but we'll have to parse until we see a stop code,
+ * e. g. ESC \ or BEL. */
ansi_parser_state = ANSI_ST_CONTROL;
continue;
@@ -1864,8 +1855,9 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
continue;
} else {
- /* If ANSI_IN_ARG is not set, add another argument and */
- /* default it to 0. */
+ /* If ANSI_IN_ARG is not set, add another argument and default it
+ * to 0. */
+
/* Check for too many arguments */
if (handle->tty.wr.ansi_csi_argc >= ARRAY_SIZE(handle->tty.wr.ansi_csi_argv)) {
ansi_parser_state |= ANSI_IGNORE;
@@ -1879,9 +1871,9 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
} else if (utf8_codepoint == '?' && !(ansi_parser_state & ANSI_IN_ARG) &&
handle->tty.wr.ansi_csi_argc == 0) {
- /* Ignores '?' if it is the first character after CSI[ */
- /* This is an extension character from the VT100 codeset */
- /* that is supported and used by most ANSI terminals today. */
+ /* Ignores '?' if it is the first character after CSI[. This is an
+ * extension character from the VT100 codeset that is supported and
+ * used by most ANSI terminals today. */
continue;
} else if (utf8_codepoint >= '@' && utf8_codepoint <= '~' &&
@@ -2011,8 +2003,8 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
continue;
} else {
- /* We don't support commands that use private mode characters or */
- /* intermediaries. Ignore the rest of the sequence. */
+ /* We don't support commands that use private mode characters or
+ * intermediaries. Ignore the rest of the sequence. */
ansi_parser_state |= ANSI_IGNORE;
continue;
}
@@ -2025,8 +2017,8 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
}
} else if (ansi_parser_state & ANSI_ST_CONTROL) {
- /* Unsupported control code */
- /* Ignore everything until we see BEL or ESC \ */
+ /* Unsupported control code.
+ * Ignore everything until we see `BEL` or `ESC \`. */
if (ansi_parser_state & ANSI_IN_STRING) {
if (!(ansi_parser_state & ANSI_BACKSLASH_SEEN)) {
if (utf8_codepoint == '"') {
@@ -2060,9 +2052,9 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
abort();
}
- /* We wouldn't mind emitting utf-16 surrogate pairs. Too bad, the */
- /* windows console doesn't really support UTF-16, so just emit the */
- /* replacement character. */
+ /* We wouldn't mind emitting utf-16 surrogate pairs. Too bad, the windows
+ * console doesn't really support UTF-16, so just emit the replacement
+ * character. */
if (utf8_codepoint > 0xffff) {
utf8_codepoint = UNICODE_REPLACEMENT_CHARACTER;
}
@@ -2076,10 +2068,10 @@ static int uv_tty_write_bufs(uv_tty_t* handle,
utf16_buf[utf16_buf_used++] = L'\r';
utf16_buf[utf16_buf_used++] = L'\n';
} else if (utf8_codepoint == 0x0d && previous_eol == 0x0a) {
- /* \n was followed by \r; do not print the \r, since */
- /* the source was either \r\n\r (so the second \r is */
- /* redundant) or was \n\r (so the \n was processed */
- /* by the last case and an \r automatically inserted). */
+ /* \n was followed by \r; do not print the \r, since the source was
+ * either \r\n\r (so the second \r is redundant) or was \n\r (so the
+ * \n was processed by the last case and an \r automatically
+ * inserted). */
} else {
/* \r without \n; print \r as-is. */
ENSURE_BUFFER_SPACE(1);
@@ -2187,14 +2179,14 @@ void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
void uv_tty_close(uv_tty_t* handle) {
assert(handle->u.fd == -1 || handle->u.fd > 2);
+ if (handle->flags & UV_HANDLE_READING)
+ uv_tty_read_stop(handle);
+
if (handle->u.fd == -1)
CloseHandle(handle->handle);
else
close(handle->u.fd);
- if (handle->flags & UV_HANDLE_READING)
- uv_tty_read_stop(handle);
-
handle->u.fd = -1;
handle->handle = INVALID_HANDLE_VALUE;
handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
@@ -2214,7 +2206,7 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle) {
/* TTY shutdown is really just a no-op */
if (handle->stream.conn.shutdown_req->cb) {
- if (handle->flags & UV__HANDLE_CLOSING) {
+ if (handle->flags & UV_HANDLE_CLOSING) {
handle->stream.conn.shutdown_req->cb(handle->stream.conn.shutdown_req, UV_ECANCELED);
} else {
handle->stream.conn.shutdown_req->cb(handle->stream.conn.shutdown_req, 0);
@@ -2227,10 +2219,10 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle) {
return;
}
- if (handle->flags & UV__HANDLE_CLOSING &&
+ if (handle->flags & UV_HANDLE_CLOSING &&
handle->reqs_pending == 0) {
- /* The wait handle used for raw reading should be unregistered when the */
- /* wait callback runs. */
+ /* The wait handle used for raw reading should be unregistered when the
+ * wait callback runs. */
assert(!(handle->flags & UV_HANDLE_TTY_READABLE) ||
handle->tty.rd.read_raw_wait == NULL);
@@ -2240,14 +2232,20 @@ void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle) {
}
-/* TODO: remove me */
+/*
+ * uv_process_tty_accept_req() is a stub to keep DELEGATE_STREAM_REQ working
+ * TODO: find a way to remove it
+ */
void uv_process_tty_accept_req(uv_loop_t* loop, uv_tty_t* handle,
uv_req_t* raw_req) {
abort();
}
-/* TODO: remove me */
+/*
+ * uv_process_tty_connect_req() is a stub to keep DELEGATE_STREAM_REQ working
+ * TODO: find a way to remove it
+ */
void uv_process_tty_connect_req(uv_loop_t* loop, uv_tty_t* handle,
uv_connect_t* req) {
abort();
@@ -2279,3 +2277,55 @@ static void uv__determine_vterm_state(HANDLE handle) {
uv__vterm_state = UV_SUPPORTED;
}
+
+static DWORD WINAPI uv__tty_console_resize_message_loop_thread(void* param) {
+ CONSOLE_SCREEN_BUFFER_INFO sb_info;
+ MSG msg;
+
+ if (!GetConsoleScreenBufferInfo(uv__tty_console_handle, &sb_info))
+ return 0;
+
+ uv__tty_console_width = sb_info.dwSize.X;
+ uv__tty_console_height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1;
+
+ if (pSetWinEventHook == NULL)
+ return 0;
+
+ if (!pSetWinEventHook(EVENT_CONSOLE_LAYOUT,
+ EVENT_CONSOLE_LAYOUT,
+ NULL,
+ uv__tty_console_resize_event,
+ 0,
+ 0,
+ WINEVENT_OUTOFCONTEXT))
+ return 0;
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ return 0;
+}
+
+static void CALLBACK uv__tty_console_resize_event(HWINEVENTHOOK hWinEventHook,
+ DWORD event,
+ HWND hwnd,
+ LONG idObject,
+ LONG idChild,
+ DWORD dwEventThread,
+ DWORD dwmsEventTime) {
+ CONSOLE_SCREEN_BUFFER_INFO sb_info;
+ int width, height;
+
+ if (!GetConsoleScreenBufferInfo(uv__tty_console_handle, &sb_info))
+ return;
+
+ width = sb_info.dwSize.X;
+ height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1;
+
+ if (width != uv__tty_console_width || height != uv__tty_console_height) {
+ uv__tty_console_width = width;
+ uv__tty_console_height = height;
+ uv__signal_dispatch(SIGWINCH);
+ }
+}
diff --git a/Utilities/cmlibuv/src/win/udp.c b/Utilities/cmlibuv/src/win/udp.c
index 2fd15cfa9..37df849f8 100644
--- a/Utilities/cmlibuv/src/win/udp.c
+++ b/Utilities/cmlibuv/src/win/udp.c
@@ -74,8 +74,8 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, SOCKET socket,
return GetLastError();
}
- /* Associate it with the I/O completion port. */
- /* Use uv_handle_t pointer as completion key. */
+ /* Associate it with the I/O completion port. Use uv_handle_t pointer as
+ * completion key. */
if (CreateIoCompletionPort((HANDLE)socket,
loop->iocp,
(ULONG_PTR)socket,
@@ -83,31 +83,28 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, SOCKET socket,
return GetLastError();
}
- if (pSetFileCompletionNotificationModes) {
- /* All known Windows that support SetFileCompletionNotificationModes */
- /* have a bug that makes it impossible to use this function in */
- /* conjunction with datagram sockets. We can work around that but only */
- /* if the user is using the default UDP driver (AFD) and has no other */
- /* LSPs stacked on top. Here we check whether that is the case. */
- opt_len = (int) sizeof info;
- if (getsockopt(socket,
- SOL_SOCKET,
- SO_PROTOCOL_INFOW,
- (char*) &info,
- &opt_len) == SOCKET_ERROR) {
- return GetLastError();
- }
+ /* All known Windows that support SetFileCompletionNotificationModes have a
+ * bug that makes it impossible to use this function in conjunction with
+ * datagram sockets. We can work around that but only if the user is using
+ * the default UDP driver (AFD) and has no other. LSPs stacked on top. Here
+ * we check whether that is the case. */
+ opt_len = (int) sizeof info;
+ if (getsockopt(
+ socket, SOL_SOCKET, SO_PROTOCOL_INFOW, (char*) &info, &opt_len) ==
+ SOCKET_ERROR) {
+ return GetLastError();
+ }
- if (info.ProtocolChain.ChainLen == 1) {
- if (pSetFileCompletionNotificationModes((HANDLE)socket,
- FILE_SKIP_SET_EVENT_ON_HANDLE |
- FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) {
- handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
- handle->func_wsarecv = uv_wsarecv_workaround;
- handle->func_wsarecvfrom = uv_wsarecvfrom_workaround;
- } else if (GetLastError() != ERROR_INVALID_FUNCTION) {
- return GetLastError();
- }
+ if (info.ProtocolChain.ChainLen == 1) {
+ if (SetFileCompletionNotificationModes(
+ (HANDLE) socket,
+ FILE_SKIP_SET_EVENT_ON_HANDLE |
+ FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) {
+ handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
+ handle->func_wsarecv = uv_wsarecv_workaround;
+ handle->func_wsarecvfrom = uv_wsarecvfrom_workaround;
+ } else if (GetLastError() != ERROR_INVALID_FUNCTION) {
+ return GetLastError();
}
}
@@ -191,7 +188,7 @@ void uv_udp_close(uv_loop_t* loop, uv_udp_t* handle) {
void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle) {
- if (handle->flags & UV__HANDLE_CLOSING &&
+ if (handle->flags & UV_HANDLE_CLOSING &&
handle->reqs_pending == 0) {
assert(!(handle->flags & UV_HANDLE_CLOSED));
uv__handle_close(handle);
@@ -245,12 +242,12 @@ static int uv_udp_maybe_bind(uv_udp_t* handle,
handle->flags |= UV_HANDLE_IPV6;
if (addr->sa_family == AF_INET6 && !(flags & UV_UDP_IPV6ONLY)) {
- /* On windows IPV6ONLY is on by default. */
- /* If the user doesn't specify it libuv turns it off. */
+ /* On windows IPV6ONLY is on by default. If the user doesn't specify it
+ * libuv turns it off. */
- /* TODO: how to handle errors? This may fail if there is no ipv4 stack */
- /* available, or when run on XP/2003 which have no support for dualstack */
- /* sockets. For now we're silently ignoring the error. */
+ /* TODO: how to handle errors? This may fail if there is no ipv4 stack
+ * available, or when run on XP/2003 which have no support for dualstack
+ * sockets. For now we're silently ignoring the error. */
setsockopt(handle->socket,
IPPROTO_IPV6,
IPV6_V6ONLY,
@@ -369,7 +366,7 @@ int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
int err;
if (handle->flags & UV_HANDLE_READING) {
- return WSAEALREADY;
+ return UV_EALREADY;
}
err = uv_udp_maybe_bind(handle,
@@ -377,7 +374,7 @@ int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
sizeof(uv_addr_ip4_any_),
0);
if (err)
- return err;
+ return uv_translate_sys_error(err);
handle->flags |= UV_HANDLE_READING;
INCREASE_ACTIVE_COUNT(loop, handle);
@@ -386,8 +383,8 @@ int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
handle->recv_cb = recv_cb;
handle->alloc_cb = alloc_cb;
- /* If reading was stopped and then started again, there could still be a */
- /* recv request pending. */
+ /* If reading was stopped and then started again, there could still be a recv
+ * request pending. */
if (!(handle->flags & UV_HANDLE_READ_PENDING))
uv_udp_queue_recv(loop, handle);
@@ -467,19 +464,19 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,
if (!REQ_SUCCESS(req)) {
DWORD err = GET_REQ_SOCK_ERROR(req);
if (err == WSAEMSGSIZE) {
- /* Not a real error, it just indicates that the received packet */
- /* was bigger than the receive buffer. */
+ /* Not a real error, it just indicates that the received packet was
+ * bigger than the receive buffer. */
} else if (err == WSAECONNRESET || err == WSAENETRESET) {
- /* A previous sendto operation failed; ignore this error. If */
- /* zero-reading we need to call WSARecv/WSARecvFrom _without_ the */
- /* MSG_PEEK flag to clear out the error queue. For nonzero reads, */
- /* immediately queue a new receive. */
+ /* A previous sendto operation failed; ignore this error. If zero-reading
+ * we need to call WSARecv/WSARecvFrom _without_ the. MSG_PEEK flag to
+ * clear out the error queue. For nonzero reads, immediately queue a new
+ * receive. */
if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
goto done;
}
} else {
- /* A real error occurred. Report the error to the user only if we're */
- /* currently reading. */
+ /* A real error occurred. Report the error to the user only if we're
+ * currently reading. */
if (handle->flags & UV_HANDLE_READING) {
uv_udp_recv_stop(handle);
buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
@@ -503,8 +500,8 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle,
struct sockaddr_storage from;
int from_len;
- /* Do a nonblocking receive */
- /* TODO: try to read multiple datagrams at once. FIONREAD maybe? */
+ /* Do a nonblocking receive.
+ * TODO: try to read multiple datagrams at once. FIONREAD maybe? */
buf = uv_buf_init(NULL, 0);
handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.base == NULL || buf.len == 0) {
@@ -741,7 +738,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
return UV_EINVAL;
}
- if (!(handle->flags & UV_HANDLE_BOUND))
+ if (handle->socket == INVALID_SOCKET)
return UV_EBADF;
if (addr_st.ss_family == AF_INET) {
@@ -772,7 +769,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
int uv_udp_set_broadcast(uv_udp_t* handle, int value) {
BOOL optval = (BOOL) value;
- if (!(handle->flags & UV_HANDLE_BOUND))
+ if (handle->socket == INVALID_SOCKET)
return UV_EBADF;
if (setsockopt(handle->socket,
@@ -818,7 +815,7 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
return UV_EINVAL; \
} \
\
- if (!(handle->flags & UV_HANDLE_BOUND)) \
+ if (handle->socket == INVALID_SOCKET) \
return UV_EBADF; \
\
if (!(handle->flags & UV_HANDLE_IPV6)) { \
@@ -897,13 +894,12 @@ int uv__udp_send(uv_udp_send_t* req,
int err;
if (!(handle->flags & UV_HANDLE_BOUND)) {
- if (addrlen == sizeof(uv_addr_ip4_any_)) {
+ if (addrlen == sizeof(uv_addr_ip4_any_))
bind_addr = (const struct sockaddr*) &uv_addr_ip4_any_;
- } else if (addrlen == sizeof(uv_addr_ip6_any_)) {
+ else if (addrlen == sizeof(uv_addr_ip6_any_))
bind_addr = (const struct sockaddr*) &uv_addr_ip6_any_;
- } else {
- abort();
- }
+ else
+ return UV_EINVAL;
err = uv_udp_maybe_bind(handle, bind_addr, addrlen, 0);
if (err)
return uv_translate_sys_error(err);
@@ -922,5 +918,45 @@ int uv__udp_try_send(uv_udp_t* handle,
unsigned int nbufs,
const struct sockaddr* addr,
unsigned int addrlen) {
- return UV_ENOSYS;
+ DWORD bytes;
+ const struct sockaddr* bind_addr;
+ struct sockaddr_storage converted;
+ int err;
+
+ assert(nbufs > 0);
+
+ err = uv__convert_to_localhost_if_unspecified(addr, &converted);
+ if (err)
+ return err;
+
+ /* Already sending a message.*/
+ if (handle->send_queue_count != 0)
+ return UV_EAGAIN;
+
+ if (!(handle->flags & UV_HANDLE_BOUND)) {
+ if (addrlen == sizeof(uv_addr_ip4_any_))
+ bind_addr = (const struct sockaddr*) &uv_addr_ip4_any_;
+ else if (addrlen == sizeof(uv_addr_ip6_any_))
+ bind_addr = (const struct sockaddr*) &uv_addr_ip6_any_;
+ else
+ return UV_EINVAL;
+ err = uv_udp_maybe_bind(handle, bind_addr, addrlen, 0);
+ if (err)
+ return uv_translate_sys_error(err);
+ }
+
+ err = WSASendTo(handle->socket,
+ (WSABUF*)bufs,
+ nbufs,
+ &bytes,
+ 0,
+ (const struct sockaddr*) &converted,
+ addrlen,
+ NULL,
+ NULL);
+
+ if (err)
+ return uv_translate_sys_error(WSAGetLastError());
+
+ return bytes;
}
diff --git a/Utilities/cmlibuv/src/win/util.c b/Utilities/cmlibuv/src/win/util.c
index d2e7f772c..923789129 100644
--- a/Utilities/cmlibuv/src/win/util.c
+++ b/Utilities/cmlibuv/src/win/util.c
@@ -37,7 +37,7 @@
#include <tlhelp32.h>
#include <windows.h>
#include <userenv.h>
-
+#include <math.h>
/*
* Max title length; the only thing MSDN tells us about the maximum length
@@ -74,10 +74,6 @@
static char *process_title;
static CRITICAL_SECTION process_title_lock;
-/* Cached copy of the process id, written once. */
-static DWORD current_pid = 0;
-
-
/* Interval (in seconds) of the high-resolution clock. */
static double hrtime_interval_ = 0;
@@ -149,8 +145,8 @@ int uv_exepath(char* buffer, size_t* size_ptr) {
uv__free(utf16_buffer);
- /* utf8_len *does* include the terminating null at this point, but the */
- /* returned size shouldn't. */
+ /* utf8_len *does* include the terminating null at this point, but the
+ * returned size shouldn't. */
*size_ptr = utf8_len - 1;
return 0;
@@ -173,16 +169,16 @@ int uv_cwd(char* buffer, size_t* size) {
if (utf16_len == 0) {
return uv_translate_sys_error(GetLastError());
} else if (utf16_len > MAX_PATH) {
- /* This should be impossible; however the CRT has a code path to deal */
- /* with this scenario, so I added a check anyway. */
+ /* This should be impossible; however the CRT has a code path to deal with
+ * this scenario, so I added a check anyway. */
return UV_EIO;
}
/* utf16_len contains the length, *not* including the terminating null. */
utf16_buffer[utf16_len] = L'\0';
- /* The returned directory should not have a trailing slash, unless it */
- /* points at a drive root, like c:\. Remove it if needed.*/
+ /* The returned directory should not have a trailing slash, unless it points
+ * at a drive root, like c:\. Remove it if needed. */
if (utf16_buffer[utf16_len - 1] == L'\\' &&
!(utf16_len == 3 && utf16_buffer[1] == L':')) {
utf16_len--;
@@ -239,9 +235,9 @@ int uv_chdir(const char* dir) {
utf16_buffer,
MAX_PATH) == 0) {
DWORD error = GetLastError();
- /* The maximum length of the current working directory is 260 chars, */
- /* including terminating null. If it doesn't fit, the path name must be */
- /* too long. */
+ /* The maximum length of the current working directory is 260 chars,
+ * including terminating null. If it doesn't fit, the path name must be too
+ * long. */
if (error == ERROR_INSUFFICIENT_BUFFER) {
return UV_ENAMETOOLONG;
} else {
@@ -253,9 +249,9 @@ int uv_chdir(const char* dir) {
return uv_translate_sys_error(GetLastError());
}
- /* Windows stores the drive-local path in an "hidden" environment variable, */
- /* which has the form "=C:=C:\Windows". SetCurrentDirectory does not */
- /* update this, so we'll have to do it. */
+ /* Windows stores the drive-local path in an "hidden" environment variable,
+ * which has the form "=C:=C:\Windows". SetCurrentDirectory does not update
+ * this, so we'll have to do it. */
utf16_len = GetCurrentDirectoryW(MAX_PATH, utf16_buffer);
if (utf16_len == 0) {
return uv_translate_sys_error(GetLastError());
@@ -263,8 +259,8 @@ int uv_chdir(const char* dir) {
return UV_EIO;
}
- /* The returned directory should not have a trailing slash, unless it */
- /* points at a drive root, like c:\. Remove it if needed. */
+ /* The returned directory should not have a trailing slash, unless it points
+ * at a drive root, like c:\. Remove it if needed. */
if (utf16_buffer[utf16_len - 1] == L'\\' &&
!(utf16_len == 3 && utf16_buffer[1] == L':')) {
utf16_len--;
@@ -272,8 +268,8 @@ int uv_chdir(const char* dir) {
}
if (utf16_len < 2 || utf16_buffer[1] != L':') {
- /* Doesn't look like a drive letter could be there - probably an UNC */
- /* path. TODO: Need to handle win32 namespaces like \\?\C:\ ? */
+ /* Doesn't look like a drive letter could be there - probably an UNC path.
+ * TODO: Need to handle win32 namespaces like \\?\C:\ ? */
drive_letter = 0;
} else if (utf16_buffer[0] >= L'A' && utf16_buffer[0] <= L'Z') {
drive_letter = utf16_buffer[0];
@@ -331,7 +327,12 @@ uint64_t uv_get_total_memory(void) {
}
-int uv_parent_pid(void) {
+uv_pid_t uv_os_getpid(void) {
+ return GetCurrentProcessId();
+}
+
+
+uv_pid_t uv_os_getppid(void) {
int parent_pid = -1;
HANDLE handle;
PROCESSENTRY32 pe;
@@ -354,14 +355,6 @@ int uv_parent_pid(void) {
}
-int uv_current_pid(void) {
- if (current_pid == 0) {
- current_pid = GetCurrentProcessId();
- }
- return current_pid;
-}
-
-
char** uv_setup_args(int argc, char** argv) {
return argv;
}
@@ -582,8 +575,8 @@ int uv_uptime(double* uptime) {
BYTE* address = (BYTE*) object_type + object_type->DefinitionLength +
counter_definition->CounterOffset;
uint64_t value = *((uint64_t*) address);
- *uptime = (double) (object_type->PerfTime.QuadPart - value) /
- (double) object_type->PerfFreq.QuadPart;
+ *uptime = floor((double) (object_type->PerfTime.QuadPart - value) /
+ (double) object_type->PerfFreq.QuadPart);
uv__free(malloced_buffer);
return 0;
}
@@ -610,7 +603,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION* sppi;
DWORD sppi_size;
SYSTEM_INFO system_info;
- DWORD cpu_count, r, i;
+ DWORD cpu_count, i;
NTSTATUS status;
ULONG result_size;
int err;
@@ -665,34 +658,33 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos_ptr, int* cpu_count_ptr) {
assert(len > 0 && len < ARRAY_SIZE(key_name));
- r = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
- key_name,
- 0,
- KEY_QUERY_VALUE,
- &processor_key);
- if (r != ERROR_SUCCESS) {
- err = GetLastError();
+ err = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+ key_name,
+ 0,
+ KEY_QUERY_VALUE,
+ &processor_key);
+ if (err != ERROR_SUCCESS) {
goto error;
}
- if (RegQueryValueExW(processor_key,
- L"~MHz",
- NULL,
- NULL,
- (BYTE*) &cpu_speed,
- &cpu_speed_size) != ERROR_SUCCESS) {
- err = GetLastError();
+ err = RegQueryValueExW(processor_key,
+ L"~MHz",
+ NULL,
+ NULL,
+ (BYTE*)&cpu_speed,
+ &cpu_speed_size);
+ if (err != ERROR_SUCCESS) {
RegCloseKey(processor_key);
goto error;
}
- if (RegQueryValueExW(processor_key,
- L"ProcessorNameString",
- NULL,
- NULL,
- (BYTE*) &cpu_brand,
- &cpu_brand_size) != ERROR_SUCCESS) {
- err = GetLastError();
+ err = RegQueryValueExW(processor_key,
+ L"ProcessorNameString",
+ NULL,
+ NULL,
+ (BYTE*)&cpu_brand,
+ &cpu_brand_size);
+ if (err != ERROR_SUCCESS) {
RegCloseKey(processor_key);
goto error;
}
@@ -824,6 +816,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
int is_vista_or_greater;
ULONG flags;
+ *addresses_ptr = NULL;
+ *count_ptr = 0;
+
is_vista_or_greater = is_windows_version_or_greater(6, 0, 0, 0);
if (is_vista_or_greater) {
flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
@@ -838,17 +833,17 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
}
- /* Fetch the size of the adapters reported by windows, and then get the */
- /* list itself. */
+ /* Fetch the size of the adapters reported by windows, and then get the list
+ * itself. */
win_address_buf_size = 0;
win_address_buf = NULL;
for (;;) {
ULONG r;
- /* If win_address_buf is 0, then GetAdaptersAddresses will fail with */
- /* ERROR_BUFFER_OVERFLOW, and the required buffer size will be stored in */
- /* win_address_buf_size. */
+ /* If win_address_buf is 0, then GetAdaptersAddresses will fail with.
+ * ERROR_BUFFER_OVERFLOW, and the required buffer size will be stored in
+ * win_address_buf_size. */
r = GetAdaptersAddresses(AF_UNSPEC,
flags,
NULL,
@@ -862,8 +857,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
switch (r) {
case ERROR_BUFFER_OVERFLOW:
- /* This happens when win_address_buf is NULL or too small to hold */
- /* all adapters. */
+ /* This happens when win_address_buf is NULL or too small to hold all
+ * adapters. */
win_address_buf = uv__malloc(win_address_buf_size);
if (win_address_buf == NULL)
return UV_ENOMEM;
@@ -897,15 +892,15 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
return UV_ENOBUFS;
default:
- /* Other (unspecified) errors can happen, but we don't have any */
- /* special meaning for them. */
+ /* Other (unspecified) errors can happen, but we don't have any special
+ * meaning for them. */
assert(r != ERROR_SUCCESS);
return uv_translate_sys_error(r);
}
}
- /* Count the number of enabled interfaces and compute how much space is */
- /* needed to store their info. */
+ /* Count the number of enabled interfaces and compute how much space is
+ * needed to store their info. */
count = 0;
uv_address_buf_size = 0;
@@ -915,9 +910,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
IP_ADAPTER_UNICAST_ADDRESS* unicast_address;
int name_size;
- /* Interfaces that are not 'up' should not be reported. Also skip */
- /* interfaces that have no associated unicast address, as to avoid */
- /* allocating space for the name for this interface. */
+ /* Interfaces that are not 'up' should not be reported. Also skip
+ * interfaces that have no associated unicast address, as to avoid
+ * allocating space for the name for this interface. */
if (adapter->OperStatus != IfOperStatusUp ||
adapter->FirstUnicastAddress == NULL)
continue;
@@ -937,8 +932,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
}
uv_address_buf_size += name_size;
- /* Count the number of addresses associated with this interface, and */
- /* compute the size. */
+ /* Count the number of addresses associated with this interface, and
+ * compute the size. */
for (unicast_address = (IP_ADAPTER_UNICAST_ADDRESS*)
adapter->FirstUnicastAddress;
unicast_address != NULL;
@@ -955,8 +950,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
return UV_ENOMEM;
}
- /* Compute the start of the uv_interface_address_t array, and the place in */
- /* the buffer where the interface names will be stored. */
+ /* Compute the start of the uv_interface_address_t array, and the place in
+ * the buffer where the interface names will be stored. */
uv_address = uv_address_buf;
name_buf = (char*) (uv_address_buf + count);
@@ -1143,53 +1138,17 @@ int uv_getrusage(uv_rusage_t *uv_rusage) {
int uv_os_homedir(char* buffer, size_t* size) {
uv_passwd_t pwd;
- wchar_t path[MAX_PATH];
- DWORD bufsize;
size_t len;
int r;
- if (buffer == NULL || size == NULL || *size == 0)
- return UV_EINVAL;
-
- /* Check if the USERPROFILE environment variable is set first */
- len = GetEnvironmentVariableW(L"USERPROFILE", path, MAX_PATH);
-
- if (len == 0) {
- r = GetLastError();
+ /* Check if the USERPROFILE environment variable is set first. The task of
+ performing input validation on buffer and size is taken care of by
+ uv_os_getenv(). */
+ r = uv_os_getenv("USERPROFILE", buffer, size);
- /* Don't return an error if USERPROFILE was not found */
- if (r != ERROR_ENVVAR_NOT_FOUND)
- return uv_translate_sys_error(r);
- } else if (len > MAX_PATH) {
- /* This should not be possible */
- return UV_EIO;
- } else {
- /* Check how much space we need */
- bufsize = WideCharToMultiByte(CP_UTF8, 0, path, -1, NULL, 0, NULL, NULL);
-
- if (bufsize == 0) {
- return uv_translate_sys_error(GetLastError());
- } else if (bufsize > *size) {
- *size = bufsize;
- return UV_ENOBUFS;
- }
-
- /* Convert to UTF-8 */
- bufsize = WideCharToMultiByte(CP_UTF8,
- 0,
- path,
- -1,
- buffer,
- *size,
- NULL,
- NULL);
-
- if (bufsize == 0)
- return uv_translate_sys_error(GetLastError());
-
- *size = bufsize - 1;
- return 0;
- }
+ /* Don't return an error if USERPROFILE was not found. */
+ if (r != UV_ENOENT)
+ return r;
/* USERPROFILE is not set, so call uv__getpwuid_r() */
r = uv__getpwuid_r(&pwd);
@@ -1231,8 +1190,8 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
return UV_EIO;
}
- /* The returned directory should not have a trailing slash, unless it */
- /* points at a drive root, like c:\. Remove it if needed.*/
+ /* The returned directory should not have a trailing slash, unless it points
+ * at a drive root, like c:\. Remove it if needed. */
if (path[len - 1] == L'\\' &&
!(len == 3 && path[1] == L':')) {
len--;
@@ -1388,7 +1347,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token) == 0)
return uv_translate_sys_error(GetLastError());
- bufsize = sizeof(path);
+ bufsize = ARRAY_SIZE(path);
if (!GetUserProfileDirectoryW(token, path, &bufsize)) {
r = GetLastError();
CloseHandle(token);
@@ -1403,7 +1362,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
CloseHandle(token);
/* Get the username using GetUserNameW() */
- bufsize = sizeof(username);
+ bufsize = ARRAY_SIZE(username);
if (!GetUserNameW(username, &bufsize)) {
r = GetLastError();
@@ -1574,3 +1533,214 @@ int uv_os_gethostname(char* buffer, size_t* size) {
*size = len;
return 0;
}
+
+
+static int uv__get_handle(uv_pid_t pid, int access, HANDLE* handle) {
+ int r;
+
+ if (pid == 0)
+ *handle = GetCurrentProcess();
+ else
+ *handle = OpenProcess(access, FALSE, pid);
+
+ if (*handle == NULL) {
+ r = GetLastError();
+
+ if (r == ERROR_INVALID_PARAMETER)
+ return UV_ESRCH;
+ else
+ return uv_translate_sys_error(r);
+ }
+
+ return 0;
+}
+
+
+int uv_os_getpriority(uv_pid_t pid, int* priority) {
+ HANDLE handle;
+ int r;
+
+ if (priority == NULL)
+ return UV_EINVAL;
+
+ r = uv__get_handle(pid, PROCESS_QUERY_LIMITED_INFORMATION, &handle);
+
+ if (r != 0)
+ return r;
+
+ r = GetPriorityClass(handle);
+
+ if (r == 0) {
+ r = uv_translate_sys_error(GetLastError());
+ } else {
+ /* Map Windows priority classes to Unix nice values. */
+ if (r == REALTIME_PRIORITY_CLASS)
+ *priority = UV_PRIORITY_HIGHEST;
+ else if (r == HIGH_PRIORITY_CLASS)
+ *priority = UV_PRIORITY_HIGH;
+ else if (r == ABOVE_NORMAL_PRIORITY_CLASS)
+ *priority = UV_PRIORITY_ABOVE_NORMAL;
+ else if (r == NORMAL_PRIORITY_CLASS)
+ *priority = UV_PRIORITY_NORMAL;
+ else if (r == BELOW_NORMAL_PRIORITY_CLASS)
+ *priority = UV_PRIORITY_BELOW_NORMAL;
+ else /* IDLE_PRIORITY_CLASS */
+ *priority = UV_PRIORITY_LOW;
+
+ r = 0;
+ }
+
+ CloseHandle(handle);
+ return r;
+}
+
+
+int uv_os_setpriority(uv_pid_t pid, int priority) {
+ HANDLE handle;
+ int priority_class;
+ int r;
+
+ /* Map Unix nice values to Windows priority classes. */
+ if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW)
+ return UV_EINVAL;
+ else if (priority < UV_PRIORITY_HIGH)
+ priority_class = REALTIME_PRIORITY_CLASS;
+ else if (priority < UV_PRIORITY_ABOVE_NORMAL)
+ priority_class = HIGH_PRIORITY_CLASS;
+ else if (priority < UV_PRIORITY_NORMAL)
+ priority_class = ABOVE_NORMAL_PRIORITY_CLASS;
+ else if (priority < UV_PRIORITY_BELOW_NORMAL)
+ priority_class = NORMAL_PRIORITY_CLASS;
+ else if (priority < UV_PRIORITY_LOW)
+ priority_class = BELOW_NORMAL_PRIORITY_CLASS;
+ else
+ priority_class = IDLE_PRIORITY_CLASS;
+
+ r = uv__get_handle(pid, PROCESS_SET_INFORMATION, &handle);
+
+ if (r != 0)
+ return r;
+
+ if (SetPriorityClass(handle, priority_class) == 0)
+ r = uv_translate_sys_error(GetLastError());
+
+ CloseHandle(handle);
+ return r;
+}
+
+
+int uv_os_uname(uv_utsname_t* buffer) {
+ /* Implementation loosely based on
+ https://github.com/gagern/gnulib/blob/master/lib/uname.c */
+ OSVERSIONINFOW os_info;
+ SYSTEM_INFO system_info;
+ int processor_level;
+ int r;
+
+ if (buffer == NULL)
+ return UV_EINVAL;
+
+ uv__once_init();
+ os_info.dwOSVersionInfoSize = sizeof(os_info);
+ os_info.szCSDVersion[0] = L'\0';
+
+ /* Try calling RtlGetVersion(), and fall back to the deprecated GetVersionEx()
+ if RtlGetVersion() is not available. */
+ if (pRtlGetVersion) {
+ pRtlGetVersion(&os_info);
+ } else {
+ /* Silence GetVersionEx() deprecation warning. */
+ #pragma warning(suppress : 4996)
+ if (GetVersionExW(&os_info) == 0) {
+ r = uv_translate_sys_error(GetLastError());
+ goto error;
+ }
+ }
+
+ /* Populate the version field. */
+ if (WideCharToMultiByte(CP_UTF8,
+ 0,
+ os_info.szCSDVersion,
+ -1,
+ buffer->version,
+ sizeof(buffer->version),
+ NULL,
+ NULL) == 0) {
+ r = uv_translate_sys_error(GetLastError());
+ goto error;
+ }
+
+ /* Populate the sysname field. */
+#ifdef __MINGW32__
+ r = snprintf(buffer->sysname,
+ sizeof(buffer->sysname),
+ "MINGW32_NT-%u.%u",
+ (unsigned int) os_info.dwMajorVersion,
+ (unsigned int) os_info.dwMinorVersion);
+ assert(r < sizeof(buffer->sysname));
+#else
+ uv__strscpy(buffer->sysname, "Windows_NT", sizeof(buffer->sysname));
+#endif
+
+ /* Populate the release field. */
+ r = snprintf(buffer->release,
+ sizeof(buffer->release),
+ "%d.%d.%d",
+ (unsigned int) os_info.dwMajorVersion,
+ (unsigned int) os_info.dwMinorVersion,
+ (unsigned int) os_info.dwBuildNumber);
+ assert(r < sizeof(buffer->release));
+
+ /* Populate the machine field. */
+ GetSystemInfo(&system_info);
+
+ switch (system_info.wProcessorArchitecture) {
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ uv__strscpy(buffer->machine, "x86_64", sizeof(buffer->machine));
+ break;
+ case PROCESSOR_ARCHITECTURE_IA64:
+ uv__strscpy(buffer->machine, "ia64", sizeof(buffer->machine));
+ break;
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ uv__strscpy(buffer->machine, "i386", sizeof(buffer->machine));
+
+ if (system_info.wProcessorLevel > 3) {
+ processor_level = system_info.wProcessorLevel < 6 ?
+ system_info.wProcessorLevel : 6;
+ buffer->machine[1] = '0' + processor_level;
+ }
+
+ break;
+ case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64:
+ uv__strscpy(buffer->machine, "i686", sizeof(buffer->machine));
+ break;
+ case PROCESSOR_ARCHITECTURE_MIPS:
+ uv__strscpy(buffer->machine, "mips", sizeof(buffer->machine));
+ break;
+ case PROCESSOR_ARCHITECTURE_ALPHA:
+ case PROCESSOR_ARCHITECTURE_ALPHA64:
+ uv__strscpy(buffer->machine, "alpha", sizeof(buffer->machine));
+ break;
+ case PROCESSOR_ARCHITECTURE_PPC:
+ uv__strscpy(buffer->machine, "powerpc", sizeof(buffer->machine));
+ break;
+ case PROCESSOR_ARCHITECTURE_SHX:
+ uv__strscpy(buffer->machine, "sh", sizeof(buffer->machine));
+ break;
+ case PROCESSOR_ARCHITECTURE_ARM:
+ uv__strscpy(buffer->machine, "arm", sizeof(buffer->machine));
+ break;
+ default:
+ uv__strscpy(buffer->machine, "unknown", sizeof(buffer->machine));
+ break;
+ }
+
+ return 0;
+
+error:
+ buffer->sysname[0] = '\0';
+ buffer->release[0] = '\0';
+ buffer->version[0] = '\0';
+ buffer->machine[0] = '\0';
+ return r;
+}
diff --git a/Utilities/cmlibuv/src/win/winapi.c b/Utilities/cmlibuv/src/win/winapi.c
index aa5d719fb..fbbbceed9 100644
--- a/Utilities/cmlibuv/src/win/winapi.c
+++ b/Utilities/cmlibuv/src/win/winapi.c
@@ -26,6 +26,7 @@
/* Ntdll function pointers */
+sRtlGetVersion pRtlGetVersion;
sRtlNtStatusToDosError pRtlNtStatusToDosError;
sNtDeviceIoControlFile pNtDeviceIoControlFile;
sNtQueryInformationFile pNtQueryInformationFile;
@@ -34,35 +35,30 @@ sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile;
sNtQueryDirectoryFile pNtQueryDirectoryFile;
sNtQuerySystemInformation pNtQuerySystemInformation;
-
/* Kernel32 function pointers */
sGetQueuedCompletionStatusEx pGetQueuedCompletionStatusEx;
-sSetFileCompletionNotificationModes pSetFileCompletionNotificationModes;
-sCreateSymbolicLinkW pCreateSymbolicLinkW;
-sCancelIoEx pCancelIoEx;
-sInitializeConditionVariable pInitializeConditionVariable;
-sSleepConditionVariableCS pSleepConditionVariableCS;
-sSleepConditionVariableSRW pSleepConditionVariableSRW;
-sWakeAllConditionVariable pWakeAllConditionVariable;
-sWakeConditionVariable pWakeConditionVariable;
-sCancelSynchronousIo pCancelSynchronousIo;
-sGetFinalPathNameByHandleW pGetFinalPathNameByHandleW;
-
/* Powrprof.dll function pointer */
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
+/* User32.dll function pointer */
+sSetWinEventHook pSetWinEventHook;
+
void uv_winapi_init(void) {
HMODULE ntdll_module;
- HMODULE kernel32_module;
HMODULE powrprof_module;
+ HMODULE user32_module;
+ HMODULE kernel32_module;
ntdll_module = GetModuleHandleA("ntdll.dll");
if (ntdll_module == NULL) {
uv_fatal_error(GetLastError(), "GetModuleHandleA");
}
+ pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module,
+ "RtlGetVersion");
+
pRtlNtStatusToDosError = (sRtlNtStatusToDosError) GetProcAddress(
ntdll_module,
"RtlNtStatusToDosError");
@@ -119,41 +115,16 @@ void uv_winapi_init(void) {
kernel32_module,
"GetQueuedCompletionStatusEx");
- pSetFileCompletionNotificationModes = (sSetFileCompletionNotificationModes)
- GetProcAddress(kernel32_module, "SetFileCompletionNotificationModes");
-
- pCreateSymbolicLinkW = (sCreateSymbolicLinkW)
- GetProcAddress(kernel32_module, "CreateSymbolicLinkW");
-
- pCancelIoEx = (sCancelIoEx)
- GetProcAddress(kernel32_module, "CancelIoEx");
-
- pInitializeConditionVariable = (sInitializeConditionVariable)
- GetProcAddress(kernel32_module, "InitializeConditionVariable");
-
- pSleepConditionVariableCS = (sSleepConditionVariableCS)
- GetProcAddress(kernel32_module, "SleepConditionVariableCS");
-
- pSleepConditionVariableSRW = (sSleepConditionVariableSRW)
- GetProcAddress(kernel32_module, "SleepConditionVariableSRW");
-
- pWakeAllConditionVariable = (sWakeAllConditionVariable)
- GetProcAddress(kernel32_module, "WakeAllConditionVariable");
-
- pWakeConditionVariable = (sWakeConditionVariable)
- GetProcAddress(kernel32_module, "WakeConditionVariable");
-
- pCancelSynchronousIo = (sCancelSynchronousIo)
- GetProcAddress(kernel32_module, "CancelSynchronousIo");
-
- pGetFinalPathNameByHandleW = (sGetFinalPathNameByHandleW)
- GetProcAddress(kernel32_module, "GetFinalPathNameByHandleW");
-
-
powrprof_module = LoadLibraryA("powrprof.dll");
if (powrprof_module != NULL) {
pPowerRegisterSuspendResumeNotification = (sPowerRegisterSuspendResumeNotification)
GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
}
+ user32_module = LoadLibraryA("user32.dll");
+ if (user32_module != NULL) {
+ pSetWinEventHook = (sSetWinEventHook)
+ GetProcAddress(user32_module, "SetWinEventHook");
+ }
+
}
diff --git a/Utilities/cmlibuv/src/win/winapi.h b/Utilities/cmlibuv/src/win/winapi.h
index 4b0eeca15..1e49b5787 100644
--- a/Utilities/cmlibuv/src/win/winapi.h
+++ b/Utilities/cmlibuv/src/win/winapi.h
@@ -4076,8 +4076,8 @@
# define STATUS_HASH_NOT_PRESENT ((NTSTATUS) 0xC000A101L)
#endif
-/* This is not the NTSTATUS_FROM_WIN32 that the DDK provides, because the */
-/* DDK got it wrong! */
+/* This is not the NTSTATUS_FROM_WIN32 that the DDK provides, because the DDK
+ * got it wrong! */
#ifdef NTSTATUS_FROM_WIN32
# undef NTSTATUS_FROM_WIN32
#endif
@@ -4104,7 +4104,14 @@
# define JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE 0x00002000
#endif
+#ifndef SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
+# define SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE 0x00000002
+#endif
+
/* from winternl.h */
+#if !defined(__UNICODE_STRING_DEFINED) && defined(__MINGW32_)
+#define __UNICODE_STRING_DEFINED
+#endif
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
@@ -4520,6 +4527,9 @@ typedef VOID (NTAPI *PIO_APC_ROUTINE)
PIO_STATUS_BLOCK IoStatusBlock,
ULONG Reserved);
+typedef NTSTATUS (NTAPI *sRtlGetVersion)
+ (PRTL_OSVERSIONINFOW lpVersionInformation);
+
typedef ULONG (NTAPI *sRtlNtStatusToDosError)
(NTSTATUS Status);
@@ -4655,48 +4665,6 @@ typedef BOOL (WINAPI *sGetQueuedCompletionStatusEx)
DWORD dwMilliseconds,
BOOL fAlertable);
-typedef BOOL (WINAPI* sSetFileCompletionNotificationModes)
- (HANDLE FileHandle,
- UCHAR Flags);
-
-typedef BOOLEAN (WINAPI* sCreateSymbolicLinkW)
- (LPCWSTR lpSymlinkFileName,
- LPCWSTR lpTargetFileName,
- DWORD dwFlags);
-
-typedef BOOL (WINAPI* sCancelIoEx)
- (HANDLE hFile,
- LPOVERLAPPED lpOverlapped);
-
-typedef VOID (WINAPI* sInitializeConditionVariable)
- (PCONDITION_VARIABLE ConditionVariable);
-
-typedef BOOL (WINAPI* sSleepConditionVariableCS)
- (PCONDITION_VARIABLE ConditionVariable,
- PCRITICAL_SECTION CriticalSection,
- DWORD dwMilliseconds);
-
-typedef BOOL (WINAPI* sSleepConditionVariableSRW)
- (PCONDITION_VARIABLE ConditionVariable,
- PSRWLOCK SRWLock,
- DWORD dwMilliseconds,
- ULONG Flags);
-
-typedef VOID (WINAPI* sWakeAllConditionVariable)
- (PCONDITION_VARIABLE ConditionVariable);
-
-typedef VOID (WINAPI* sWakeConditionVariable)
- (PCONDITION_VARIABLE ConditionVariable);
-
-typedef BOOL (WINAPI* sCancelSynchronousIo)
- (HANDLE hThread);
-
-typedef DWORD (WINAPI* sGetFinalPathNameByHandleW)
- (HANDLE hFile,
- LPWSTR lpszFilePath,
- DWORD cchFilePath,
- DWORD dwFlags);
-
/* from powerbase.h */
#ifndef DEVICE_NOTIFY_CALLBACK
# define DEVICE_NOTIFY_CALLBACK 2
@@ -4730,8 +4698,28 @@ typedef DWORD (WINAPI *sPowerRegisterSuspendResumeNotification)
HANDLE Recipient,
_PHPOWERNOTIFY RegistrationHandle);
+/* from Winuser.h */
+typedef VOID (CALLBACK* WINEVENTPROC)
+ (HWINEVENTHOOK hWinEventHook,
+ DWORD event,
+ HWND hwnd,
+ LONG idObject,
+ LONG idChild,
+ DWORD idEventThread,
+ DWORD dwmsEventTime);
+
+typedef HWINEVENTHOOK (WINAPI *sSetWinEventHook)
+ (UINT eventMin,
+ UINT eventMax,
+ HMODULE hmodWinEventProc,
+ WINEVENTPROC lpfnWinEventProc,
+ DWORD idProcess,
+ DWORD idThread,
+ UINT dwflags);
+
/* Ntdll function pointers */
+extern sRtlGetVersion pRtlGetVersion;
extern sRtlNtStatusToDosError pRtlNtStatusToDosError;
extern sNtDeviceIoControlFile pNtDeviceIoControlFile;
extern sNtQueryInformationFile pNtQueryInformationFile;
@@ -4740,22 +4728,13 @@ extern sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile;
extern sNtQueryDirectoryFile pNtQueryDirectoryFile;
extern sNtQuerySystemInformation pNtQuerySystemInformation;
-
/* Kernel32 function pointers */
extern sGetQueuedCompletionStatusEx pGetQueuedCompletionStatusEx;
-extern sSetFileCompletionNotificationModes pSetFileCompletionNotificationModes;
-extern sCreateSymbolicLinkW pCreateSymbolicLinkW;
-extern sCancelIoEx pCancelIoEx;
-extern sInitializeConditionVariable pInitializeConditionVariable;
-extern sSleepConditionVariableCS pSleepConditionVariableCS;
-extern sSleepConditionVariableSRW pSleepConditionVariableSRW;
-extern sWakeAllConditionVariable pWakeAllConditionVariable;
-extern sWakeConditionVariable pWakeConditionVariable;
-extern sCancelSynchronousIo pCancelSynchronousIo;
-extern sGetFinalPathNameByHandleW pGetFinalPathNameByHandleW;
-
/* Powrprof.dll function pointer */
extern sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification;
+/* User32.dll function pointer */
+extern sSetWinEventHook pSetWinEventHook;
+
#endif /* UV_WIN_WINAPI_H_ */
diff --git a/Utilities/cmlibuv/src/win/winsock.c b/Utilities/cmlibuv/src/win/winsock.c
index e86d76b13..5e7da2a8f 100644
--- a/Utilities/cmlibuv/src/win/winsock.c
+++ b/Utilities/cmlibuv/src/win/winsock.c
@@ -256,8 +256,8 @@ int uv_ntstatus_to_winsock_error(NTSTATUS status) {
default:
if ((status & (FACILITY_NTWIN32 << 16)) == (FACILITY_NTWIN32 << 16) &&
(status & (ERROR_SEVERITY_ERROR | ERROR_SEVERITY_WARNING))) {
- /* It's a windows error that has been previously mapped to an */
- /* ntstatus code. */
+ /* It's a windows error that has been previously mapped to an ntstatus
+ * code. */
return (DWORD) (status & 0xffff);
} else {
/* The default fallback for unmappable ntstatus codes. */
@@ -519,8 +519,8 @@ int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO* info_in,
sizeof *info_out);
if (overlapped == NULL) {
- /* If this is a blocking operation, wait for the event to become */
- /* signaled, and then grab the real status from the io status block. */
+ /* If this is a blocking operation, wait for the event to become signaled,
+ * and then grab the real status from the io status block. */
if (status == STATUS_PENDING) {
DWORD r = WaitForSingleObject(event, INFINITE);
@@ -559,3 +559,33 @@ int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO* info_in,
return SOCKET_ERROR;
}
}
+
+int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr,
+ struct sockaddr_storage* storage) {
+ struct sockaddr_in* dest4;
+ struct sockaddr_in6* dest6;
+
+ if (addr == NULL)
+ return UV_EINVAL;
+
+ switch (addr->sa_family) {
+ case AF_INET:
+ dest4 = (struct sockaddr_in*) storage;
+ memcpy(dest4, addr, sizeof(*dest4));
+ if (dest4->sin_addr.s_addr == 0)
+ dest4->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ return 0;
+ case AF_INET6:
+ dest6 = (struct sockaddr_in6*) storage;
+ memcpy(dest6, addr, sizeof(*dest6));
+ if (memcmp(&dest6->sin6_addr,
+ &uv_addr_ip6_any_.sin6_addr,
+ sizeof(uv_addr_ip6_any_.sin6_addr)) == 0) {
+ struct in6_addr init_sin6_addr = IN6ADDR_LOOPBACK_INIT;
+ dest6->sin6_addr = init_sin6_addr;
+ }
+ return 0;
+ default:
+ return UV_EINVAL;
+ }
+}
diff --git a/Utilities/cmlibuv/src/win/winsock.h b/Utilities/cmlibuv/src/win/winsock.h
index 3115fe3d2..e8b274e1b 100644
--- a/Utilities/cmlibuv/src/win/winsock.h
+++ b/Utilities/cmlibuv/src/win/winsock.h
@@ -188,4 +188,7 @@ typedef struct _IP_ADAPTER_UNICAST_ADDRESS_LH {
#endif
+int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr,
+ struct sockaddr_storage* storage);
+
#endif /* UV_WIN_WINSOCK_H_ */
diff --git a/Utilities/cmzlib/CMakeLists.txt b/Utilities/cmzlib/CMakeLists.txt
index 0be48f107..888c3ff77 100644
--- a/Utilities/cmzlib/CMakeLists.txt
+++ b/Utilities/cmzlib/CMakeLists.txt
@@ -2,7 +2,7 @@ PROJECT(CMZLIB)
# Disable warnings to avoid changing 3rd party code.
if(CMAKE_C_COMPILER_ID MATCHES
- "^(GNU|Clang|AppleClang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$")
+ "^(GNU|Clang|AppleClang|XLClang|XL|VisualAge|SunPro|HP|Intel)$")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
elseif(CMAKE_C_COMPILER_ID STREQUAL "PathScale")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall")
diff --git a/bootstrap b/bootstrap
index b5effd640..38fa32b5b 100755
--- a/bootstrap
+++ b/bootstrap
@@ -9,26 +9,22 @@ die() {
# Compile flag extraction function.
cmake_extract_standard_flags()
{
- cd "${cmake_source_dir}/Modules/Compiler/"
- for file in ${1:-*}-${2}.cmake; do
- cat "${file}" \
- | sed -n "s/ *set *( *CMAKE_${2}${3}_EXTENSION_COMPILE_OPTION *\"\{0,1\}\([^\")]*\).*/\1/p" \
- | tr ';' ' '
- done
+ sed -n "s/ *set *( *CMAKE_${2}${3}_EXTENSION_COMPILE_OPTION *\"\{0,1\}\([^\")]*\).*/\1/p" \
+ "${cmake_source_dir}/Modules/Compiler/"${1:-*}-${2}.cmake 2>/dev/null | tr ';' ' '
}
# Version number extraction function.
cmake_version_component()
{
- cat "${cmake_source_dir}/Source/CMakeVersion.cmake" | sed -n "
+ sed -n "
/^set(CMake_VERSION_${1}/ {s/set(CMake_VERSION_${1} *\([0-9]*\))/\1/;p;}
-"
+" "${cmake_source_dir}/Source/CMakeVersion.cmake"
}
# Install destination extraction function.
cmake_install_dest_default()
{
- cat "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake" | sed -n '
+ sed -n '
/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT.*) # '"${2}"'$/ {
s/^ *set(CMAKE_'"${1}"'_DIR_DEFAULT *"\([^"]*\)").*$/\1/
s/${CMake_VERSION_MAJOR}/'"${cmake_version_major}"'/
@@ -37,12 +33,12 @@ cmake_install_dest_default()
p
q
}
-'
+' "${cmake_source_dir}/Source/CMakeInstallDestinations.cmake"
}
cmake_toupper()
{
- echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
+ echo "$1" | tr '[:lower:]' '[:upper:]'
}
# Detect system and directory information.
@@ -76,7 +72,7 @@ cmake_init_file=""
cmake_bootstrap_system_libs=""
cmake_bootstrap_qt_gui=""
cmake_bootstrap_qt_qmake=""
-cmake_bootstrap_server=""
+cmake_sphinx_info=""
cmake_sphinx_man=""
cmake_sphinx_html=""
cmake_sphinx_qthelp=""
@@ -133,6 +129,11 @@ fi
# Determine whether this is HP-UX
if echo "${cmake_system}" | grep HP-UX >/dev/null 2>&1; then
+ die 'CMake no longer compiles on HP-UX. See
+
+ https://gitlab.kitware.com/cmake/cmake/issues/17137
+
+Use CMake 3.9 or lower instead.'
cmake_system_hpux=true
else
cmake_system_hpux=false
@@ -224,8 +225,8 @@ cmake_doc_dir_default="`cmake_install_dest_default DOC ${cmake_doc_dir_keyword}`
cmake_man_dir_default="`cmake_install_dest_default MAN ${cmake_man_dir_keyword}`"
cmake_xdgdata_dir_default="`cmake_install_dest_default XDGDATA ${cmake_xdgdata_dir_keyword}`"
-CMAKE_KNOWN_C_COMPILERS="cc gcc xlc icc tcc"
-CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ c++ icc como "
+CMAKE_KNOWN_C_COMPILERS="cc gcc clang xlc icc tcc"
+CMAKE_KNOWN_CXX_COMPILERS="aCC xlC CC g++ clang++ c++ icc como "
CMAKE_KNOWN_MAKE_PROCESSORS="gmake make"
CMAKE_PROBLEMATIC_FILES="\
@@ -259,6 +260,7 @@ CMAKE_CXX_SOURCES="\
cmAddLibraryCommand \
cmAddSubDirectoryCommand \
cmAddTestCommand \
+ cmArgumentParser \
cmBreakCommand \
cmBuildCommand \
cmCMakeMinimumRequired \
@@ -267,7 +269,6 @@ CMAKE_CXX_SOURCES="\
cmCacheManager \
cmCommand \
cmCommandArgumentParserHelper \
- cmCommandArgumentsHelper \
cmCommands \
cmCommonTargetGenerator \
cmComputeComponentGraph \
@@ -301,7 +302,11 @@ CMAKE_CXX_SOURCES="\
cmExprParserHelper \
cmExternalMakefileProjectGenerator \
cmFileCommand \
- cmFileTimeComparison \
+ cmFileCopier \
+ cmFileInstaller \
+ cmFileTime \
+ cmFileTimeCache \
+ cmFileTimes \
cmFindBase \
cmFindCommon \
cmFindFileCommand \
@@ -311,6 +316,7 @@ CMAKE_CXX_SOURCES="\
cmFindProgramCommand \
cmForEachCommand \
cmFunctionCommand \
+ cmFSPermissions \
cmGeneratedFileStream \
cmGeneratorExpression \
cmGeneratorExpressionContext \
@@ -324,6 +330,7 @@ CMAKE_CXX_SOURCES="\
cmGetCMakePropertyCommand \
cmGetDirectoryPropertyCommand \
cmGetFilenameComponentCommand \
+ cmGetPipes \
cmGetPropertyCommand \
cmGetSourceFilePropertyCommand \
cmGetTargetPropertyCommand \
@@ -331,9 +338,11 @@ CMAKE_CXX_SOURCES="\
cmGlobalCommonGenerator \
cmGlobalGenerator \
cmGlobalUnixMakefileGenerator3 \
+ cmGlobVerificationManager \
cmHexFileConverter \
cmIfCommand \
cmIncludeCommand \
+ cmIncludeGuardCommand \
cmIncludeDirectoryCommand \
cmIncludeRegularExpressionCommand \
cmInstallCommand \
@@ -344,11 +353,14 @@ CMAKE_CXX_SOURCES="\
cmInstallFilesGenerator \
cmInstallGenerator \
cmInstallScriptGenerator \
+ cmInstallSubdirectoryGenerator \
cmInstallTargetGenerator \
cmInstallTargetsCommand \
cmInstalledFile \
cmLinkDirectoriesCommand \
+ cmLinkItem \
cmLinkLineComputer \
+ cmLinkLineDeviceComputer \
cmListCommand \
cmListFileCache \
cmLocalCommonGenerator \
@@ -397,12 +409,19 @@ CMAKE_CXX_SOURCES="\
cmState \
cmStateDirectory \
cmStateSnapshot \
+ cmStringReplaceHelper \
cmStringCommand \
cmSubdirCommand \
cmSystemTools \
cmTarget \
+ cmTargetCompileDefinitionsCommand \
+ cmTargetCompileFeaturesCommand \
+ cmTargetCompileOptionsCommand \
+ cmTargetIncludeDirectoriesCommand \
cmTargetLinkLibrariesCommand \
+ cmTargetPropCommandBase \
cmTargetPropertyComputer \
+ cmTargetSourcesCommand \
cmTest \
cmTestGenerator \
cmTimestamp \
@@ -410,12 +429,15 @@ CMAKE_CXX_SOURCES="\
cmTryRunCommand \
cmUnexpectedCommand \
cmUnsetCommand \
+ cmUVHandlePtr \
+ cmUVProcessChain \
cmVersion \
cmWhileCommand \
cmWorkingDirectory \
cmake \
cmakemain \
cmcmd \
+ cm_string_view \
"
if ${cmake_system_mingw}; then
@@ -473,6 +495,61 @@ KWSYS_FILES="\
SystemTools.hxx \
Terminal.h"
+if ${cmake_system_mingw}; then
+ LIBUV_C_SOURCES="\
+ src/fs-poll.c \
+ src/idna.c
+ src/inet.c \
+ src/threadpool.c \
+ src/strscpy.c \
+ src/timer.c \
+ src/uv-common.c \
+ src/win/async.c \
+ src/win/core.c \
+ src/win/detect-wakeup.c \
+ src/win/dl.c \
+ src/win/error.c \
+ src/win/fs-event.c \
+ src/win/fs.c \
+ src/win/getaddrinfo.c \
+ src/win/getnameinfo.c \
+ src/win/handle.c \
+ src/win/loop-watcher.c \
+ src/win/pipe.c \
+ src/win/poll.c \
+ src/win/process-stdio.c \
+ src/win/process.c \
+ src/win/signal.c \
+ src/win/stream.c \
+ src/win/tcp.c \
+ src/win/thread.c \
+ src/win/tty.c \
+ src/win/udp.c \
+ src/win/util.c \
+ src/win/winapi.c \
+ src/win/winsock.c \
+ "
+else
+ LIBUV_C_SOURCES="\
+ src/strscpy.c \
+ src/timer.c \
+ src/uv-common.c \
+ src/unix/cmake-bootstrap.c \
+ src/unix/core.c \
+ src/unix/fs.c \
+ src/unix/loop.c \
+ src/unix/loop-watcher.c \
+ src/unix/no-fsevents.c \
+ src/unix/pipe.c \
+ src/unix/poll.c \
+ src/unix/posix-hrtime.c \
+ src/unix/posix-poll.c \
+ src/unix/process.c \
+ src/unix/signal.c \
+ src/unix/stream.c \
+ "
+fi
+
# Display CMake bootstrap usage
cmake_usage()
{
@@ -503,18 +580,20 @@ Configuration:
--no-system-bzip2 use cmake-provided bzip2 library (default)
--system-liblzma use system-installed liblzma library
--no-system-liblzma use cmake-provided liblzma library (default)
+ --system-zstd use system-installed zstd library
+ --no-system-zstd use cmake-provided zstd library (default)
--system-libarchive use system-installed libarchive library
--no-system-libarchive use cmake-provided libarchive library (default)
--system-librhash use system-installed librhash library
--no-system-librhash use cmake-provided librhash library (default)
+ --system-libuv use system-installed libuv library
+ --no-system-libuv use cmake-provided libuv 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
- --server enable the server mode (default if supported)
- --no-server disable the server mode
-
+ --sphinx-info build Info manual with Sphinx
--sphinx-man build man pages with Sphinx
--sphinx-html build html help with Sphinx
--sphinx-qthelp build qch help with Sphinx
@@ -581,8 +660,7 @@ cmake_replace_string ()
SEARCHFOR="$3"
REPLACEWITH="$4"
if [ -f "${INFILE}" ] || ${cmake_system_openvms}; then
- cat "${INFILE}" |
- sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" > "${OUTFILE}${_tmp}"
+ sed "s/\@${SEARCHFOR}\@/${REPLACEWITH}/g" "${INFILE}" > "${OUTFILE}${_tmp}"
if [ -f "${OUTFILE}${_tmp}" ]; then
if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
#echo "Files are the same"
@@ -604,15 +682,15 @@ cmake_kwsys_config_replace_string ()
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_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g;
- s/@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@/${KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H}/g;
- }" >> "${OUTFILE}${_tmp}"
+ 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_STL_HAS_WSTRING@/${KWSYS_STL_HAS_WSTRING}/g;
+ s/@KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H@/${KWSYS_CXX_HAS_EXT_STDIO_FILEBUF_H}/g;
+ s/@KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP@/${KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP}/g;
+ }" "${INFILE}" >> "${OUTFILE}${_tmp}"
if [ -f "${OUTFILE}${_tmp}" ]; then
if "${_diff}" "${OUTFILE}" "${OUTFILE}${_tmp}" > /dev/null 2> /dev/null ; then
#echo "Files are the same"
@@ -639,6 +717,12 @@ cmake_escape ()
echo $1 | sed "s/ /\\\\ /g"
}
+# Encode object file names.
+cmake_obj ()
+{
+ echo $1 | sed 's/\//-/g' | sed 's/$/\.o/'
+}
+
# Strip prefix from argument
cmake_arg ()
{
@@ -740,17 +824,16 @@ while test $# != 0; do
--init=*) cmake_init_file=`cmake_arg "$1"` ;;
--system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" ;;
--no-system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" ;;
- --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-librhash|--system-zlib|--system-liblzma|--system-libuv|--system-form)
+ --system-bzip2|--system-curl|--system-expat|--system-jsoncpp|--system-libarchive|--system-librhash|--system-zlib|--system-liblzma|--system-zstd|--system-libuv)
lib=`cmake_arg "$1" "--system-"`
cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper $lib`=1" ;;
- --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-librhash|--no-system-zlib|--no-system-liblzma|--no-system-libuv|--no-system-form)
+ --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-jsoncpp|--no-system-libarchive|--no-system-librhash|--no-system-zlib|--no-system-liblzma|--no-system-zstd|--no-system-libuv)
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"` ;;
- --server) cmake_bootstrap_server="1" ;;
- --no-server) cmake_bootstrap_server="0" ;;
+ --sphinx-info) cmake_sphinx_info="1" ;;
--sphinx-man) cmake_sphinx_man="1" ;;
--sphinx-html) cmake_sphinx_html="1" ;;
--sphinx-qthelp) cmake_sphinx_qthelp="1" ;;
@@ -760,6 +843,11 @@ while test $# != 0; do
--version) cmake_version_display ; exit 2 ;;
--verbose) cmake_verbose=TRUE ;;
--enable-ccache) cmake_ccache_enabled=TRUE ;;
+ CC=*) CC=`cmake_arg "$1"` ;;
+ CXX=*) CXX=`cmake_arg "$1"` ;;
+ CFLAGS=*) CFLAGS=`cmake_arg "$1"` ;;
+ CXXFLAGS=*) CXXFLAGS=`cmake_arg "$1"` ;;
+ LDFLAGS=*) LDFLAGS=`cmake_arg "$1"` ;;
--) shift; break ;;
*) die "Unknown option: $1" ;;
esac
@@ -861,16 +949,6 @@ if ${cmake_system_haiku}; then
cmake_ld_flags="${LDFLAGS} -lroot -lbe"
fi
-# Workaround for short jump tables on PA-RISC
-if ${cmake_machine_parisc}; then
- if ${cmake_c_compiler_is_gnu}; then
- cmake_c_flags="${CFLAGS} -mlong-calls"
- fi
- if ${cmake_cxx_compiler_is_gnu}; then
- cmake_cxx_flags="${CXXFLAGS} -mlong-calls"
- fi
-fi
-
#-----------------------------------------------------------------------------
# Detect known toolchains on some platforms.
cmake_toolchains=''
@@ -931,6 +1009,11 @@ if [ -z "${CC}" -a -z "${CXX}" ]; then
cmake_toolchain_detect
fi
+thread_flags=''
+case "${cmake_system}" in
+ *AIX*) thread_flags='-pthread' ;;
+esac
+
#-----------------------------------------------------------------------------
# Test C compiler
cmake_c_compiler=
@@ -951,35 +1034,36 @@ echo '
# error "The CMAKE_C_COMPILER is set to a C++ compiler"
#endif
-#include<stdio.h>
+#if defined(_AIX) && defined(__GNUC__) && !defined(_THREAD_SAFE)
+#error "On AIX with GNU we need the -pthread flag."
+#endif
-#if defined(__CLASSIC_C__)
-int main(argc, argv)
- int argc;
- char* argv[];
-#else
-int main(int argc, char* argv[])
+#if defined(__sun) && __STDC_VERSION__ < 199901L
+#error "On Solaris we need C99."
#endif
+
+#include <stdio.h>
+
+int main(int argc, char* argv[])
{
printf("%d%c", (argv != 0), (char)0x0a);
- return argc-1;
+ 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
for std in 11 99 90; do
- try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" C \"${std}\"`"
- for flag in $try_flags; do
- echo "Checking whether ${cmake_c_compiler} supports ${flag}" >> cmake_bootstrap.log 2>&1
- if cmake_try_run "${cmake_c_compiler}" "${cmake_c_flags} ${flag}" \
- "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
- cmake_c_flags="${cmake_c_flags} ${flag}"
- break 2
- fi
+ std_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" C \"${std}\"`"
+ for compiler in ${cmake_c_compilers}; do
+ for std_flag in '' $std_flags; do
+ for thread_flag in '' $thread_flags; do
+ echo "Checking whether '${compiler} ${cmake_c_flags} ${std_flag} ${thread_flag}' works." >> cmake_bootstrap.log 2>&1
+ if cmake_try_run "${compiler}" "${cmake_c_flags} ${std_flag} ${thread_flag}" \
+ "${TMPFILE}.c" >> cmake_bootstrap.log 2>&1; then
+ cmake_c_compiler="${compiler}"
+ cmake_c_flags="${cmake_c_flags} ${std_flag} ${thread_flag}"
+ break 3
+ fi
+ done
+ done
done
done
rm -f "${TMPFILE}.c"
@@ -1010,59 +1094,59 @@ fi
# Check if C++ compiler works
TMPFILE=`cmake_tmp_file`
echo '
-#if defined(TEST1)
-# include <iostream>
-#else
-# include <iostream.h>
+#include <iostream>
+#include <memory>
+#include <unordered_map>
+
+#if __cplusplus < 201103L
+#error "Compiler is not in a mode aware of C++11."
#endif
-#if __cplusplus >= 201103L && defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140
-#error "SunPro <= 5.13 C++ 11 mode not supported due to bug in move semantics."
+#if defined(_AIX) && defined(__GNUC__) && !defined(_THREAD_SAFE)
+#error "On AIX with GNU we need the -pthread flag."
#endif
-class NeedCXX
+#if defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5140
+#error "SunPro <= 5.13 mode not supported due to bug in move semantics."
+#endif
+
+class Class
{
public:
- NeedCXX() { this->Foo = 1; }
- int GetFoo() { return this->Foo; }
+ int Get() const { return this->Member; }
private:
- int Foo;
+ int Member = 1;
};
int main()
{
- NeedCXX c;
-#ifdef TEST3
- cout << c.GetFoo() << endl;
-#else
- std::cout << c.GetFoo() << std::endl;
-#endif
+ auto const c = std::unique_ptr<Class>(new Class);
+ std::cout << c->Get() << std::endl;
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
-for std in 14 11 98; do
- try_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" CXX \"${std}\"`"
- for flag in $try_flags; do
- echo "Checking for wheter ${cmake_cxx_flags} supports ${flag}" >> cmake_bootstrap.log 2>&1
- if cmake_try_run "${cmake_cxx_compiler}" "${cmake_cxx_flags} ${flag} -DTEST1" \
- "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
- cmake_cxx_flags="${cmake_cxx_flags} ${flag} "
- break 2
- fi
+for std in 17 14 11; do
+ std_flags="`cmake_extract_standard_flags \"${cmake_toolchain}\" CXX \"${std}\"`"
+ for compiler in ${cmake_cxx_compilers}; do
+ for std_flag in '' $std_flags; do
+ for thread_flag in '' $thread_flags; do
+ echo "Checking whether '${compiler} ${cmake_cxx_flags} ${std_flag} ${thread_flag}' works." >> cmake_bootstrap.log 2>&1
+ if cmake_try_run "${compiler}" "${cmake_cxx_flags} ${std_flag} ${thread_flag}" \
+ "${TMPFILE}.cxx" >> cmake_bootstrap.log 2>&1; then
+ cmake_cxx_compiler="${compiler}"
+ cmake_cxx_flags="${cmake_cxx_flags} ${std_flag} ${thread_flag} "
+ break 3
+ fi
+ done
+ done
done
done
rm -f "${TMPFILE}.cxx"
if [ -z "${cmake_cxx_compiler}" ]; then
- cmake_error 7 "Cannot find appropriate C++ compiler on this system.
+cmake_error 7 "Cannot find a C++ compiler that supports both C++11 and the specified C++ flags.
Please specify one using environment variable CXX.
+The C++ flags are \"$cmake_cxx_flags\".
+They can be changed using the environment variable CXXFLAGS.
See cmake_bootstrap.log for compilers attempted."
fi
echo "C++ compiler on this system is: ${cmake_cxx_compiler} ${cmake_cxx_flags}"
@@ -1126,85 +1210,6 @@ if [ "x${cmake_full_make_flags}" != "x${cmake_make_flags}" ]; then
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 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
@@ -1217,6 +1222,7 @@ KWSYS_CXX_HAS_UNSETENV=0
KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=0
KWSYS_CXX_HAS_UTIMENSAT=0
KWSYS_CXX_HAS_UTIMES=0
+KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP=1
if cmake_try_run "${cmake_cxx_compiler}" \
"${cmake_cxx_flags} -DTEST_KWSYS_CXX_HAS_SETENV" \
@@ -1263,6 +1269,12 @@ else
echo "${cmake_cxx_compiler} does not have <ext/stdio_filebuf.h>"
fi
+if [ -n "${cmake_ccache_enabled}" ]; then
+ echo "Building CMake with ccache"
+ cmake_c_compiler="ccache ${cmake_c_compiler}"
+ cmake_cxx_compiler="ccache ${cmake_cxx_compiler}"
+fi
+
# Just to be safe, let us store compiler and flags to the header file
cmake_bootstrap_version='$Revision$'
@@ -1287,6 +1299,8 @@ cmake_compiler_settings_comment="/*
* ${LexerParser_CXX_SOURCES} ${LexerParser_C_SOURCES}
* kwSys Sources:
* ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}
+ * libuv Sources:
+ * ${LIBUV_C_SOURCES}
*/
"
@@ -1309,14 +1323,11 @@ cmake_report cmVersionConfig.h${_tmp} "#define CMake_VERSION_PATCH ${cmake_versi
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_DEFAULT_RECURSION_LIMIT 400"
cmake_report cmConfigure.h${_tmp} "#define CMAKE_BIN_DIR \"/bootstrap-not-insalled\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_DATA_DIR \"/bootstrap-not-insalled\""
cmake_report cmConfigure.h${_tmp} "#define CMAKE_BOOTSTRAP"
-cmake_report cmConfigure.h${_tmp} "#define CM_EQ_DELETE"
cmake_report cmConfigure.h${_tmp} "#define CM_FALLTHROUGH"
-cmake_report cmConfigure.h${_tmp} "#define CM_NULLPTR 0"
-cmake_report cmConfigure.h${_tmp} "#define CM_OVERRIDE"
-cmake_report cmConfigure.h${_tmp} "#define CM_DISABLE_COPY(Class)"
# Regenerate configured headers
for h in Configure VersionConfig; do
@@ -1350,6 +1361,51 @@ objs=""
for a in ${CMAKE_CXX_SOURCES} ${CMAKE_C_SOURCES} ${LexerParser_CXX_SOURCES} ${LexerParser_C_SOURCES} ${KWSYS_CXX_SOURCES} ${KWSYS_C_SOURCES}; do
objs="${objs} ${a}.o"
done
+for a in ${LIBUV_C_SOURCES}; do
+ objs="${objs} uv-`cmake_obj ${a}`"
+done
+
+libs=""
+
+uv_c_flags=""
+if ${cmake_system_mingw}; then
+ uv_c_flags="${uv_c_flags} -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600"
+ libs="${libs} -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv"
+else
+ uv_c_flags="${uv_c_flags} -DCMAKE_BOOTSTRAP"
+ case "${cmake_system}" in
+ *AIX*)
+ uv_c_flags="${uv_c_flags} -D_ALL_SOURCE -D_XOPEN_SOURCE=500 -D_LINUX_SOURCE_COMPAT"
+ libs="${libs} -lperfstat"
+ ;;
+ *Darwin*)
+ uv_c_flags="${uv_c_flags} -D_DARWIN_USE_64_BIT_INODE=1 -D_DARWIN_UNLIMITED_SELECT=1"
+ ;;
+ *Linux*)
+ uv_c_flags="${uv_c_flags} -D_GNU_SOURCE"
+ libs="${libs} -ldl -lrt"
+ ;;
+ *kFreeBSD*)
+ libs="${libs} -lkvm -lfreebsd-glue"
+ ;;
+ *BSD*)
+ libs="${libs} -lkvm"
+ ;;
+ *SunOS*)
+ # Normally libuv uses '-D_XOPEN_SOURCE=500 -std=c90' on Solaris 5.10,
+ # but we do not need to do that because we bootstrap using POSIX APIs.
+ uv_c_flags="${uv_c_flags} -D__EXTENSIONS__ -D_XOPEN_SOURCE=600"
+ libs="${libs} -lkstat -lnsl -lsendfile -lsocket -lrt"
+ ;;
+ esac
+fi
+uv_c_flags="${uv_c_flags} `cmake_escape "-I${cmake_source_dir}/Utilities/cmlibuv/include"`"
+if ${cmake_system_mingw}; then
+ uv_c_flags="${uv_c_flags} `cmake_escape "-I${cmake_source_dir}/Utilities/cmlibuv/src/win"`"
+else
+ uv_c_flags="${uv_c_flags} `cmake_escape "-I${cmake_source_dir}/Utilities/cmlibuv/src/unix"`"
+fi
+uv_c_flags="${uv_c_flags} `cmake_escape "-I${cmake_source_dir}/Utilities/cmlibuv/src"`"
if [ "x${cmake_ansi_cxx_flags}" != "x" ]; then
cmake_cxx_flags="${cmake_ansi_cxx_flags} ${cmake_cxx_flags}"
@@ -1387,7 +1443,7 @@ cmake_cxx_flags="${cmake_cxx_flags} \
-I`cmake_escape \"${cmake_source_dir}/Source/LexerParser\"` \
-I`cmake_escape \"${cmake_source_dir}/Utilities\"`"
echo "cmake: ${objs}" > "${cmake_bootstrap_dir}/Makefile"
-echo " ${cmake_cxx_compiler} ${cmake_ld_flags} ${cmake_cxx_flags} ${objs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
+echo " ${cmake_cxx_compiler} ${cmake_ld_flags} ${cmake_cxx_flags} ${objs} ${libs} -o cmake" >> "${cmake_bootstrap_dir}/Makefile"
for a in ${CMAKE_CXX_SOURCES}; do
src=`cmake_escape "${cmake_source_dir}/Source/${a}.cxx"`
src_flags=`eval echo \\${cmake_cxx_flags_\${a}}`
@@ -1422,6 +1478,11 @@ for a in ${KWSYS_CXX_SOURCES}; do
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
+for a in ${LIBUV_C_SOURCES}; do
+ src=`cmake_escape "${cmake_source_dir}/Utilities/cmlibuv/${a}"`
+ echo "uv-`cmake_obj ${a}` : ${src} ${dep}" >> "${cmake_bootstrap_dir}/Makefile"
+ echo " ${cmake_c_compiler} ${cmake_c_flags} ${uv_c_flags} -c ${src} -o uv-`cmake_obj ${a}`" >> "${cmake_bootstrap_dir}/Makefile"
+done
echo '
rebuild_cache:
cd "${cmake_binary_dir}" && "${cmake_source_dir}/bootstrap"
@@ -1450,9 +1511,9 @@ if [ "x${cmake_bootstrap_qt_qmake}" != "x" ]; then
set (QT_QMAKE_EXECUTABLE "'"${cmake_bootstrap_qt_qmake}"'" CACHE FILEPATH "Location of Qt qmake" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
-if [ "x${cmake_bootstrap_server}" != "x" ]; then
+if [ "x${cmake_sphinx_info}" != "x" ]; then
echo '
-set (CMake_ENABLE_SERVER_MODE '"${cmake_bootstrap_server}"' CACHE BOOL "Enable server mode" FORCE)
+set (SPHINX_INFO "'"${cmake_sphinx_info}"'" CACHE BOOL "Build Info manual with Sphinx" FORCE)
' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake"
fi
if [ "x${cmake_sphinx_man}" != "x" ]; then
@@ -1508,14 +1569,13 @@ cd "${cmake_binary_dir}"
# 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
+export CFLAGS
+export CXXFLAGS
+export LDFLAGS
# Run bootstrap CMake to configure real CMake
cmake_options="-DCMAKE_BOOTSTRAP=1"